From 480b70927069a8fb5e22593eba083505d284a24a Mon Sep 17 00:00:00 2001 From: Stephan Raue Date: Mon, 14 May 2012 16:11:49 +0200 Subject: [PATCH] xbmc-pvr: update internal FFMPEG Signed-off-by: Stephan Raue --- packages/mediacenter/xbmc-pvr/build | 3 + ...vr-11.0.1-901.01-ffmpeg-10.2-28b186f.patch | 483184 +++++++++++++++ ...mes_ended_up_in_internal_lavf_buffer.patch | 35 + ...1.0.1-901.31-ffmpeg_add_xvba_support.patch | 813 + ...o_new_ffmpeg_fix_artifacts_for_h.264.patch | 50 + ....33-ffmpeg_xvba_xvba_vc-1_new_ffmpeg.patch | 64 + ...1.0.1-902.00-xdpau_reset_pvr_changes.patch | 12 +- ...01-xvba_support_vdpau_rework-c633159.patch | 1711 +- 8 files changed, 484603 insertions(+), 1269 deletions(-) create mode 100644 packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.01-ffmpeg-10.2-28b186f.patch create mode 100644 packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.02-ffmpeg_dvd_still_frames_ended_up_in_internal_lavf_buffer.patch create mode 100644 packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.31-ffmpeg_add_xvba_support.patch create mode 100644 packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.32-ffmpeg_xvba_adapt_to_new_ffmpeg_fix_artifacts_for_h.264.patch create mode 100644 packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.33-ffmpeg_xvba_xvba_vc-1_new_ffmpeg.patch diff --git a/packages/mediacenter/xbmc-pvr/build b/packages/mediacenter/xbmc-pvr/build index 4f8722ed55..1cf98f5aec 100755 --- a/packages/mediacenter/xbmc-pvr/build +++ b/packages/mediacenter/xbmc-pvr/build @@ -201,6 +201,9 @@ cd $PKG_BUILD # Clean the generated files find . -depth -type d -name "autom4te.cache" -exec rm -rf {} \; +# hack: make codec_names.sh executable + chmod +x lib/ffmpeg/libavcodec/codec_names.sh + ./configure --host=$TARGET_NAME \ --build=$HOST_NAME \ --with-arch=$TARGET_ARCH \ diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.01-ffmpeg-10.2-28b186f.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.01-ffmpeg-10.2-28b186f.patch new file mode 100644 index 0000000000..09927c0151 --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.01-ffmpeg-10.2-28b186f.patch @@ -0,0 +1,483184 @@ +diff -Naur xbmc-pvr-11.0.1/configure.in xbmc-pvr-11.0.1.patch/configure.in +--- xbmc-pvr-11.0.1/configure.in 2012-03-27 17:55:54.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/configure.in 2012-05-14 14:08:56.008373673 +0200 +@@ -2033,7 +2033,7 @@ + --disable-amd3dnow \ + --disable-armv5te \ + --disable-armv6t2 \ +- --disable-static \ ++ --enable-static \ + `if test "$use_debug" = "no"; then echo --disable-debug; fi` \ + --disable-muxers \ + --enable-muxer=spdif \ +@@ -2047,7 +2047,6 @@ + --disable-ffplay \ + --disable-ffserver \ + --disable-ffmpeg \ +- --enable-shared \ + --disable-doc \ + --disable-decoder=mpeg_xvmc \ + --enable-postproc \ +@@ -2055,6 +2054,7 @@ + --enable-protocol=http \ + --enable-pthreads \ + --enable-runtime-cpudetect \ ++ --disable-openmp \ + --cc="$CC" && + sed -ie "s#YASM=yasm#YASM=${prefix}/bin/yasm#" config.mak && + sed -ie "s#YASMDEP=yasm#YASMDEP=${prefix}/bin/yasm#" config.mak && +diff -Naur xbmc-pvr-11.0.1/lib/DllAvCodec.h xbmc-pvr-11.0.1.patch/lib/DllAvCodec.h +--- xbmc-pvr-11.0.1/lib/DllAvCodec.h 2012-03-27 17:55:40.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllAvCodec.h 2012-05-14 14:08:56.008373673 +0200 +@@ -24,7 +24,7 @@ + #include "config.h" + #endif + #include "DynamicDll.h" +-#include "DllAvCore.h" ++#include "DllAvUtil.h" + #include "utils/log.h" + + extern "C" { +@@ -76,28 +76,6 @@ + #endif + } + +-/* Some convenience macros introduced at this particular revision of libavcodec. +- */ +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,25,0) +-#define CH_LAYOUT_5POINT0_BACK (CH_LAYOUT_SURROUND|CH_BACK_LEFT|CH_BACK_RIGHT) +-#define CH_LAYOUT_5POINT1_BACK (CH_LAYOUT_5POINT0_BACK|CH_LOW_FREQUENCY) +-#undef CH_LAYOUT_7POINT1_WIDE +-#define CH_LAYOUT_7POINT1_WIDE (CH_LAYOUT_5POINT1_BACK|\ +- CH_FRONT_LEFT_OF_CENTER|CH_FRONT_RIGHT_OF_CENTER) +-#endif +- +-#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(52,64,0) +-// API added on: 2010-03-31 +-#define AVMediaType CodecType +-#define AVMEDIA_TYPE_UNKNOWN CODEC_TYPE_UNKNOWN +-#define AVMEDIA_TYPE_VIDEO CODEC_TYPE_VIDEO +-#define AVMEDIA_TYPE_AUDIO CODEC_TYPE_AUDIO +-#define AVMEDIA_TYPE_DATA CODEC_TYPE_DATA +-#define AVMEDIA_TYPE_SUBTITLE CODEC_TYPE_SUBTITLE +-#define AVMEDIA_TYPE_ATTACHMENT CODEC_TYPE_ATTACHMENT +-#define AVMEDIA_TYPE_NB CODEC_TYPE_NB +-#endif +- + #include "threads/SingleLock.h" + + class DllAvCodecInterface +@@ -106,20 +84,20 @@ + virtual ~DllAvCodecInterface() {} + virtual void avcodec_register_all(void)=0; + virtual void avcodec_flush_buffers(AVCodecContext *avctx)=0; +- virtual int avcodec_open_dont_call(AVCodecContext *avctx, AVCodec *codec)=0; ++ virtual int avcodec_open2_dont_call(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options)=0; + virtual AVCodec *avcodec_find_decoder(enum CodecID id)=0; + virtual AVCodec *avcodec_find_encoder(enum CodecID id)=0; + virtual int avcodec_close_dont_call(AVCodecContext *avctx)=0; + virtual AVFrame *avcodec_alloc_frame(void)=0; + virtual int avpicture_fill(AVPicture *picture, uint8_t *ptr, PixelFormat pix_fmt, int width, int height)=0; + virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)=0; +- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt)=0; ++ virtual int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)=0; + virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt)=0; + virtual int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples)=0; + virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height)=0; +- virtual AVCodecContext *avcodec_alloc_context(void)=0; ++ virtual AVCodecContext *avcodec_alloc_context3(AVCodec *codec)=0; + virtual void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)=0; +- virtual void avcodec_get_context_defaults(AVCodecContext *s)=0; ++ virtual void avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec)=0; + virtual AVCodecParserContext *av_parser_init(int codec_id)=0; + virtual int av_parser_parse2(AVCodecParserContext *s,AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, +@@ -137,7 +115,6 @@ + virtual enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt)=0; + virtual int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic)=0; + virtual void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic)=0; +- virtual int avcodec_thread_init(AVCodecContext *s, int thread_count)=0; + virtual AVCodec *av_codec_next(AVCodec *c)=0; + virtual AVAudioConvert *av_audio_convert_alloc(enum AVSampleFormat out_fmt, int out_channels, + enum AVSampleFormat in_fmt , int in_channels, +@@ -151,7 +128,7 @@ + virtual int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name)=0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + + // Use direct layer + class DllAvCodec : public DllDynamic, DllAvCodecInterface +@@ -166,12 +143,12 @@ + ::avcodec_register_all(); + } + virtual void avcodec_flush_buffers(AVCodecContext *avctx) { ::avcodec_flush_buffers(avctx); } +- virtual int avcodec_open(AVCodecContext *avctx, AVCodec *codec) ++ virtual int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) + { + CSingleLock lock(DllAvCodec::m_critSection); +- return ::avcodec_open(avctx, codec); ++ return ::avcodec_open2(avctx, codec, options); + } +- virtual int avcodec_open_dont_call(AVCodecContext *avctx, AVCodec *codec) { *(int *)0x0 = 0; return 0; } ++ virtual int avcodec_open2_dont_call(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) { *(int *)0x0 = 0; return 0; } + virtual int avcodec_close_dont_call(AVCodecContext *avctx) { *(int *)0x0 = 0; return 0; } + virtual AVCodec *avcodec_find_decoder(enum CodecID id) { return ::avcodec_find_decoder(id); } + virtual AVCodec *avcodec_find_encoder(enum CodecID id) { return ::avcodec_find_encoder(id); } +@@ -182,33 +159,21 @@ + } + virtual AVFrame *avcodec_alloc_frame() { return ::avcodec_alloc_frame(); } + virtual int avpicture_fill(AVPicture *picture, uint8_t *ptr, PixelFormat pix_fmt, int width, int height) { return ::avpicture_fill(picture, ptr, pix_fmt, width, height); } +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,23,0) +- // API added on: 2009-04-07 + virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) { return ::avcodec_decode_video2(avctx, picture, got_picture_ptr, avpkt); } +- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt) { return ::avcodec_decode_audio3(avctx, samples, frame_size_ptr, avpkt); } ++ virtual int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt) { return ::avcodec_decode_audio4(avctx, frame, got_frame_ptr, avpkt); } + virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { return ::avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, avpkt); } +-#else +- virtual int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt) { return ::avcodec_decode_video(avctx, picture, got_picture_ptr, avpkt->data, avpkt->size); } +- virtual int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, int *frame_size_ptr, AVPacket *avpkt) { return ::avcodec_decode_audio2(avctx, samples, frame_size_ptr, avpkt->data, avpkt->size); } +- virtual int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, int *got_sub_ptr, AVPacket *avpkt) { return ::avcodec_decode_subtitle(avctx, sub, got_sub_ptr, avpkt->data, avpkt->size); } +-#endif + virtual int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, const short *samples) { return ::avcodec_encode_audio(avctx, buf, buf_size, samples); } + virtual int avpicture_get_size(PixelFormat pix_fmt, int width, int height) { return ::avpicture_get_size(pix_fmt, width, height); } +- virtual AVCodecContext *avcodec_alloc_context() { return ::avcodec_alloc_context(); } ++ virtual AVCodecContext *avcodec_alloc_context3(AVCodec *codec) { return ::avcodec_alloc_context3(codec); } + virtual void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) { ::avcodec_string(buf, buf_size, enc, encode); } +- virtual void avcodec_get_context_defaults(AVCodecContext *s) { ::avcodec_get_context_defaults(s); } ++ virtual void avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec) { ::avcodec_get_context_defaults3(s, codec); } + + virtual AVCodecParserContext *av_parser_init(int codec_id) { return ::av_parser_init(codec_id); } + virtual int av_parser_parse2(AVCodecParserContext *s,AVCodecContext *avctx, uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size, + int64_t pts, int64_t dts, int64_t pos) + { +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,21,0) +- // API added on : 2009-03-05 + return ::av_parser_parse2(s, avctx, poutbuf, poutbuf_size, buf, buf_size, pts, dts, pos); +-#else +- return ::av_parser_parse(s, avctx, poutbuf, poutbuf_size, buf, buf_size, pts, dts); +-#endif + } + virtual void av_parser_close(AVCodecParserContext *s) { ::av_parser_close(s); } + +@@ -225,7 +190,6 @@ + virtual int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic) { return ::avcodec_default_get_buffer(s, pic); } + virtual void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic) { ::avcodec_default_release_buffer(s, pic); } + virtual enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt) { return ::avcodec_default_get_format(s, fmt); } +- virtual int avcodec_thread_init(AVCodecContext *s, int thread_count) { return ::avcodec_thread_init(s, thread_count); } + virtual AVCodec *av_codec_next(AVCodec *c) { return ::av_codec_next(c); } + virtual AVAudioConvert *av_audio_convert_alloc(enum AVSampleFormat out_fmt, int out_channels, + enum AVSampleFormat in_fmt , int in_channels, +@@ -256,12 +220,12 @@ + { + DECLARE_DLL_WRAPPER(DllAvCodec, DLL_PATH_LIBAVCODEC) + DEFINE_FUNC_ALIGNED1(void, __cdecl, avcodec_flush_buffers, AVCodecContext*) +- DEFINE_FUNC_ALIGNED2(int, __cdecl, avcodec_open_dont_call, AVCodecContext*, AVCodec *) ++ DEFINE_FUNC_ALIGNED3(int, __cdecl, avcodec_open2_dont_call, AVCodecContext*, AVCodec *, AVDictionary **) + DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_video2, AVCodecContext*, AVFrame*, int*, AVPacket*) +- DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio3, AVCodecContext*, int16_t*, int*, AVPacket*) ++ DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_audio4, AVCodecContext*, AVFrame*, int*, AVPacket*) + DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_decode_subtitle2, AVCodecContext*, AVSubtitle*, int*, AVPacket*) + DEFINE_FUNC_ALIGNED4(int, __cdecl, avcodec_encode_audio, AVCodecContext*, uint8_t*, int, const short*) +- DEFINE_FUNC_ALIGNED0(AVCodecContext*, __cdecl, avcodec_alloc_context) ++ DEFINE_FUNC_ALIGNED1(AVCodecContext*, __cdecl, avcodec_alloc_context3, AVCodec *) + DEFINE_FUNC_ALIGNED1(AVCodecParserContext*, __cdecl, av_parser_init, int) + DEFINE_FUNC_ALIGNED9(int, __cdecl, av_parser_parse2, AVCodecParserContext*,AVCodecContext*, uint8_t**, int*, const uint8_t*, int, int64_t, int64_t, int64_t) + DEFINE_METHOD1(int, av_dup_packet, (AVPacket *p1)) +@@ -278,7 +242,7 @@ + DEFINE_METHOD5(int, avpicture_fill, (AVPicture *p1, uint8_t *p2, PixelFormat p3, int p4, int p5)) + DEFINE_METHOD3(int, avpicture_get_size, (PixelFormat p1, int p2, int p3)) + DEFINE_METHOD4(void, avcodec_string, (char *p1, int p2, AVCodecContext *p3, int p4)) +- DEFINE_METHOD1(void, avcodec_get_context_defaults, (AVCodecContext *p1)) ++ DEFINE_METHOD2(void, avcodec_get_context_defaults3, (AVCodecContext *p1, AVCodec *p2)) + DEFINE_METHOD1(void, av_parser_close, (AVCodecParserContext *p1)) + DEFINE_METHOD1(void, avpicture_free, (AVPicture *p1)) + DEFINE_METHOD1(AVBitStreamFilterContext*, av_bitstream_filter_init, (const char *p1)) +@@ -290,7 +254,6 @@ + DEFINE_METHOD2(void, avcodec_default_release_buffer, (AVCodecContext *p1, AVFrame *p2)) + DEFINE_METHOD2(enum PixelFormat, avcodec_default_get_format, (struct AVCodecContext *p1, const enum PixelFormat *p2)) + +- DEFINE_METHOD2(int, avcodec_thread_init, (AVCodecContext *p1, int p2)) + DEFINE_METHOD1(AVCodec*, av_codec_next, (AVCodec *p1)) + DEFINE_METHOD6(AVAudioConvert*, av_audio_convert_alloc, (enum AVSampleFormat p1, int p2, + enum AVSampleFormat p3, int p4, +@@ -301,7 +264,7 @@ + const void * const p4[6], const int p5[6], int p6)) + BEGIN_METHOD_RESOLVE() + RESOLVE_METHOD(avcodec_flush_buffers) +- RESOLVE_METHOD_RENAME(avcodec_open,avcodec_open_dont_call) ++ RESOLVE_METHOD_RENAME(avcodec_open2,avcodec_open2_dont_call) + RESOLVE_METHOD_RENAME(avcodec_close,avcodec_close_dont_call) + RESOLVE_METHOD(avcodec_find_decoder) + RESOLVE_METHOD(avcodec_find_encoder) +@@ -309,13 +272,13 @@ + RESOLVE_METHOD_RENAME(avcodec_register_all, avcodec_register_all_dont_call) + RESOLVE_METHOD(avpicture_fill) + RESOLVE_METHOD(avcodec_decode_video2) +- RESOLVE_METHOD(avcodec_decode_audio3) ++ RESOLVE_METHOD(avcodec_decode_audio4) + RESOLVE_METHOD(avcodec_decode_subtitle2) + RESOLVE_METHOD(avcodec_encode_audio) + RESOLVE_METHOD(avpicture_get_size) +- RESOLVE_METHOD(avcodec_alloc_context) ++ RESOLVE_METHOD(avcodec_alloc_context3) + RESOLVE_METHOD(avcodec_string) +- RESOLVE_METHOD(avcodec_get_context_defaults) ++ RESOLVE_METHOD(avcodec_get_context_defaults3) + RESOLVE_METHOD(av_parser_init) + RESOLVE_METHOD(av_parser_parse2) + RESOLVE_METHOD(av_parser_close) +@@ -328,7 +291,6 @@ + RESOLVE_METHOD(avcodec_default_get_buffer) + RESOLVE_METHOD(avcodec_default_release_buffer) + RESOLVE_METHOD(avcodec_default_get_format) +- RESOLVE_METHOD(avcodec_thread_init) + RESOLVE_METHOD(av_codec_next) + RESOLVE_METHOD(av_audio_convert_alloc) + RESOLVE_METHOD(av_audio_convert_free) +@@ -339,15 +301,15 @@ + END_METHOD_RESOLVE() + + /* dependencies of libavcodec */ +- DllAvCore m_dllAvCore; ++ DllAvUtil m_dllAvUtil; + // DllAvUtil loaded implicitely by m_dllAvCore + + public: + static CCriticalSection m_critSection; +- int avcodec_open(AVCodecContext *avctx, AVCodec *codec) ++ int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) + { + CSingleLock lock(DllAvCodec::m_critSection); +- return avcodec_open_dont_call(avctx,codec); ++ return avcodec_open2_dont_call(avctx,codec, options); + } + int avcodec_close(AVCodecContext *avctx) + { +@@ -361,7 +323,7 @@ + } + virtual bool Load() + { +- if (!m_dllAvCore.Load()) ++ if (!m_dllAvUtil.Load()) + return false; + return DllDynamic::Load(); + } +diff -Naur xbmc-pvr-11.0.1/lib/DllAvCore.h xbmc-pvr-11.0.1.patch/lib/DllAvCore.h +--- xbmc-pvr-11.0.1/lib/DllAvCore.h 2012-03-27 17:55:42.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllAvCore.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,182 +0,0 @@ +-#pragma once +-/* +- * Copyright (C) 2005-2010 Team XBMC +- * http://www.xbmc.org +- * +- * This Program 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, or (at your option) +- * any later version. +- * +- * This Program 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 XBMC; see the file COPYING. If not, write to the Free +- * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +- * Boston, MA 02110-1301, USA. +- * http://www.gnu.org/copyleft/gpl.html +- * +- */ +- +-#if (defined HAVE_CONFIG_H) && (!defined WIN32) +- #include "config.h" +-#endif +-#include "DynamicDll.h" +-#include "DllAvUtil.h" +-#include "utils/log.h" +- +-extern "C" { +-#ifdef USE_EXTERNAL_FFMPEG +- #ifdef HAVE_LIBAVUTIL_SAMPLEFMT_H +- // libavcore was merged to libavutil on 2010-02-15 +- #include +- #include +- #endif +- +- #ifdef HAVE_LIBAVCORE_AVCORE_H +- #include +- #endif +- #ifdef HAVE_LIBAVCORE_SAMPLEFMT_H +- #include +- #endif +- +- /* Needed for old FFmpeg versions as used below */ +- #ifdef HAVE_LIBAVCODEC_AVCODEC_H +- #include +- #else +- #include +- #endif +-#else +- #include "libavcore/avcore.h" +- #include "libavcore/samplefmt.h" +-#endif +-} +- +-/* Compatibility for old external FFmpeg versions. */ +- +-#ifdef USE_EXTERNAL_FFMPEG +- +-#ifndef LIBAVCORE_VERSION_INT +-// API added on: 2010-07-21, removed on 2010-02-15 +-#define LIBAVCORE_VERSION_INT 0 +-#endif +- +-#ifndef AV_SAMPLE_FMT_NONE +-// API added on: 2010-11-02 +-#define AVSampleFormat SampleFormat +-#define AV_SAMPLE_FMT_NONE SAMPLE_FMT_NONE +-#define AV_SAMPLE_FMT_U8 SAMPLE_FMT_U8 +-#define AV_SAMPLE_FMT_S16 SAMPLE_FMT_S16 +-#define AV_SAMPLE_FMT_S32 SAMPLE_FMT_S32 +-#define AV_SAMPLE_FMT_FLT SAMPLE_FMT_FLT +-#define AV_SAMPLE_FMT_DBL SAMPLE_FMT_DBL +-#endif +- +-#ifndef AV_CH_FRONT_LEFT +-// API added on: 2010-11-21 +-#define AV_CH_FRONT_LEFT CH_FRONT_LEFT +-#define AV_CH_FRONT_RIGHT CH_FRONT_RIGHT +-#define AV_CH_FRONT_CENTER CH_FRONT_CENTER +-#define AV_CH_LOW_FREQUENCY CH_LOW_FREQUENCY +-#define AV_CH_BACK_LEFT CH_BACK_LEFT +-#define AV_CH_BACK_RIGHT CH_BACK_RIGHT +-#define AV_CH_FRONT_LEFT_OF_CENTER CH_FRONT_LEFT_OF_CENTER +-#define AV_CH_FRONT_RIGHT_OF_CENTER CH_FRONT_RIGHT_OF_CENTER +-#define AV_CH_BACK_CENTER CH_BACK_CENTER +-#define AV_CH_SIDE_LEFT CH_SIDE_LEFT +-#define AV_CH_SIDE_RIGHT CH_SIDE_RIGHT +-#define AV_CH_TOP_CENTER CH_TOP_CENTER +-#define AV_CH_TOP_FRONT_LEFT CH_TOP_FRONT_LEFT +-#define AV_CH_TOP_FRONT_CENTER CH_TOP_FRONT_CENTER +-#define AV_CH_TOP_FRONT_RIGHT CH_TOP_FRONT_RIGHT +-#define AV_CH_TOP_BACK_LEFT CH_TOP_BACK_LEFT +-#define AV_CH_TOP_BACK_CENTER CH_TOP_BACK_CENTER +-#define AV_CH_TOP_BACK_RIGHT CH_TOP_BACK_RIGHT +-#define AV_CH_STEREO_LEFT CH_STEREO_LEFT +-#define AV_CH_STEREO_RIGHT CH_STEREO_RIGHT +- +-#define AV_CH_LAYOUT_NATIVE CH_LAYOUT_NATIVE +- +-#define AV_CH_LAYOUT_MONO CH_LAYOUT_MONO +-#define AV_CH_LAYOUT_STEREO CH_LAYOUT_STEREO +-#define AV_CH_LAYOUT_2_1 CH_LAYOUT_2_1 +-#define AV_CH_LAYOUT_SURROUND CH_LAYOUT_SURROUND +-#define AV_CH_LAYOUT_4POINT0 CH_LAYOUT_4POINT0 +-#define AV_CH_LAYOUT_2_2 CH_LAYOUT_2_2 +-#define AV_CH_LAYOUT_QUAD CH_LAYOUT_QUAD +-#define AV_CH_LAYOUT_5POINT0 CH_LAYOUT_5POINT0 +-#define AV_CH_LAYOUT_5POINT1 CH_LAYOUT_5POINT1 +-#define AV_CH_LAYOUT_5POINT0_BACK CH_LAYOUT_5POINT0_BACK +-#define AV_CH_LAYOUT_5POINT1_BACK CH_LAYOUT_5POINT1_BACK +-#define AV_CH_LAYOUT_7POINT0 CH_LAYOUT_7POINT0 +-#define AV_CH_LAYOUT_7POINT1 CH_LAYOUT_7POINT1 +-#define AV_CH_LAYOUT_7POINT1_WIDE CH_LAYOUT_7POINT1_WIDE +-#define AV_CH_LAYOUT_STEREO_DOWNMIX CH_LAYOUT_STEREO_DOWNMIX +-#endif +- +-#endif // USE_EXTERNAL_FFMPEG +- +-class DllAvCoreInterface +-{ +-public: +- virtual ~DllAvCoreInterface() {} +- virtual int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) = 0; +-}; +- +-#if (defined USE_EXTERNAL_FFMPEG) +- +-// Use direct layer +-class DllAvCore : public DllDynamic, DllAvCoreInterface +-{ +-public: +- virtual ~DllAvCore() {} +-#if LIBAVCORE_VERSION_INT >= AV_VERSION_INT(0,12,0) || LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(50,38,0) +- // API added on: 2010-11-02, moved to libavutil on 2010-02-15 +- virtual int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) { return ::av_get_bits_per_sample_fmt(sample_fmt); } +-#else +- // from avcodec.h +- virtual int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) { return ::av_get_bits_per_sample_format(sample_fmt); } +-#endif +- +- // DLL faking. +- virtual bool ResolveExports() { return true; } +- virtual bool Load() { +-#if LIBAVCORE_VERSION_INT > 0 +- CLog::Log(LOGDEBUG, "DllAvCore: Using libavcore system library"); +-#endif +- return true; +- } +- virtual void Unload() {} +-}; +- +-#else +- +-class DllAvCore : public DllDynamic, DllAvCoreInterface +-{ +- DECLARE_DLL_WRAPPER(DllAvCore, DLL_PATH_LIBAVCORE) +- +- LOAD_SYMBOLS() +- +- DEFINE_METHOD1(int, av_get_bits_per_sample_fmt, (enum AVSampleFormat p1)) +- +- BEGIN_METHOD_RESOLVE() +- RESOLVE_METHOD(av_get_bits_per_sample_fmt) +- END_METHOD_RESOLVE() +- +- /* dependency of libavcore */ +- DllAvUtil m_dllAvUtil; +- +-public: +- virtual bool Load() +- { +- if (!m_dllAvUtil.Load()) +- return false; +- return DllDynamic::Load(); +- } +-}; +- +-#endif +- +diff -Naur xbmc-pvr-11.0.1/lib/DllAvFilter.h xbmc-pvr-11.0.1.patch/lib/DllAvFilter.h +--- xbmc-pvr-11.0.1/lib/DllAvFilter.h 2012-03-27 17:55:42.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllAvFilter.h 2012-05-14 14:08:56.009373693 +0200 +@@ -24,8 +24,8 @@ + #include "config.h" + #endif + #include "DynamicDll.h" +-#include "DllAvCore.h" + #include "DllAvCodec.h" ++#include "DllSwResample.h" + #include "utils/log.h" + + extern "C" { +@@ -43,24 +43,17 @@ + #if (defined USE_EXTERNAL_FFMPEG) + #if (defined HAVE_LIBAVFILTER_AVFILTER_H) + #include ++ #include ++ #include + #elif (defined HAVE_FFMPEG_AVFILTER_H) + #include +- #endif +- /* for av_vsrc_buffer_add_frame */ +- #if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,8,0) +- #include +- #elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,7,0) +- int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, +- AVFrame *frame); +- #elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,3,0) +- int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, +- AVFrame *frame, int64_t pts); +- #else +- int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, +- AVFrame *frame, int64_t pts, AVRational pixel_aspect); ++ #include ++ #include + #endif + #else + #include "libavfilter/avfiltergraph.h" ++ #include "libavfilter/buffersink.h" ++ #include "libavfilter/avcodec.h" + #endif + } + +@@ -82,21 +75,16 @@ + virtual int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx)=0; + virtual int avfilter_poll_frame(AVFilterLink *link)=0; + virtual int avfilter_request_frame(AVFilterLink *link)=0; +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,13,0) + virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags)=0; +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,7,0) +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame)=0; +-#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,3,0) +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts)=0; +-#else +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts, AVRational pixel_aspect)=0; +-#endif + virtual AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h)=0; + virtual void avfilter_unref_buffer(AVFilterBufferRef *ref)=0; + virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad)=0; ++ virtual int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, AVFilterBufferRef **bufref, int flags)=0; ++ virtual AVBufferSinkParams *av_buffersink_params_alloc()=0; ++ virtual int av_buffersink_poll_frame(AVFilterContext *ctx)=0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + // Use direct mapping + class DllAvFilter : public DllDynamic, DllAvFilterInterface + { +@@ -115,12 +103,7 @@ + virtual void avfilter_graph_free(AVFilterGraph **graph) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(1,76,0) + ::avfilter_graph_free(graph); +-#else +- ::avfilter_graph_free(*graph); +- *graph = NULL; +-#endif + } + void avfilter_register_all() + { +@@ -133,56 +116,31 @@ + virtual AVFilterInOut *avfilter_inout_alloc() + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + return ::avfilter_inout_alloc(); +-#else +- return (AVFilterInOut*)::av_mallocz(sizeof(AVFilterInOut)); +-#endif + } + virtual void avfilter_inout_free(AVFilterInOut **inout) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + ::avfilter_inout_free(inout); +-#else +- *inout = NULL; +-#endif + } + virtual int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if ( LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(1,79,0) \ +- && LIBAVFILTER_VERSION_INT < AV_VERSION_INT(2,0,0) ) \ +- ||( LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,16,0)) + return ::avfilter_graph_parse(graph, filters, inputs, outputs, log_ctx); +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) +- return ::avfilter_graph_parse(graph, filters, *inputs, *outputs, log_ctx); +-#else +- return ::avfilter_graph_parse(graph, filters, *inputs, *outputs, (AVClass*)log_ctx); +-#endif + } + virtual int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) + { +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) + return ::avfilter_graph_config(graphctx, log_ctx); +-#else +- return ::avfilter_graph_config(graphctx, (AVClass*)log_ctx); +-#endif + } + virtual int avfilter_poll_frame(AVFilterLink *link) { return ::avfilter_poll_frame(link); } + virtual int avfilter_request_frame(AVFilterLink *link) { return ::avfilter_request_frame(link); } +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,13,0) + virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int flags) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, flags); } +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,7,0) +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame); } +-#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,3,0) +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, pts); } +-#else +- virtual int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, int64_t pts, AVRational pixel_aspect) { return ::av_vsrc_buffer_add_frame(buffer_filter, frame, pts, pixel_aspect); } +-#endif + virtual AVFilterBufferRef *avfilter_get_video_buffer(AVFilterLink *link, int perms, int w, int h) { return ::avfilter_get_video_buffer(link, perms, w, h); } + virtual void avfilter_unref_buffer(AVFilterBufferRef *ref) { ::avfilter_unref_buffer(ref); } + virtual int avfilter_link(AVFilterContext *src, unsigned srcpad, AVFilterContext *dst, unsigned dstpad) { return ::avfilter_link(src, srcpad, dst, dstpad); } ++ virtual int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, AVFilterBufferRef **bufref, int flags) { return ::av_buffersink_get_buffer_ref(buffer_sink, bufref, flags); } ++ virtual AVBufferSinkParams *av_buffersink_params_alloc() { return ::av_buffersink_params_alloc(); } ++ virtual int av_buffersink_poll_frame(AVFilterContext *ctx) { return av_buffersink_poll_frame(ctx); } + // DLL faking. + virtual bool ResolveExports() { return true; } + virtual bool Load() { +@@ -200,45 +158,24 @@ + + DEFINE_METHOD3(int, avfilter_open_dont_call, (AVFilterContext **p1, AVFilter *p2, const char *p3)) + DEFINE_METHOD1(void, avfilter_free_dont_call, (AVFilterContext *p1)) +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(1,76,0) + DEFINE_METHOD1(void, avfilter_graph_free_dont_call, (AVFilterGraph **p1)) +-#else +- DEFINE_METHOD1(void, avfilter_graph_free_dont_call, (AVFilterGraph *p1)) +-#endif + DEFINE_METHOD0(void, avfilter_register_all_dont_call) + DEFINE_METHOD6(int, avfilter_graph_create_filter, (AVFilterContext **p1, AVFilter *p2, const char *p3, const char *p4, void *p5, AVFilterGraph *p6)) + DEFINE_METHOD1(AVFilter*, avfilter_get_by_name, (const char *p1)) + DEFINE_METHOD0(AVFilterGraph*, avfilter_graph_alloc) +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + DEFINE_METHOD0(AVFilterInOut*, avfilter_inout_alloc_dont_call) + DEFINE_METHOD1(void, avfilter_inout_free_dont_call, (AVFilterInOut **p1)) +-#endif +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,16,0) +- DEFINE_METHOD5(int, avfilter_graph_parse_dont_call, (AVFilterGraph *p1, const char *p2, AVFilterInOut **p3, AVFilterInOut **p4, void *p5)) +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) +- DEFINE_METHOD5(int, avfilter_graph_parse_dont_call, (AVFilterGraph *p1, const char *p2, AVFilterInOut *p3, AVFilterInOut *p4, void *p5)) +-#else +- DEFINE_METHOD5(int, avfilter_graph_parse_dont_call, (AVFilterGraph *p1, const char *p2, AVFilterInOut *p3, AVFilterInOut *p4, AVClass *p5)) +-#endif +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) +- DEFINE_METHOD2(int, avfilter_graph_config_dont_call, (AVFilterGraph *p1, void *p2)) +-#else +- DEFINE_METHOD2(int, avfilter_graph_config_dont_call, (AVFilterGraph *p1, AVClass *p2)) +-#endif ++ DEFINE_FUNC_ALIGNED5(int, __cdecl, avfilter_graph_parse_dont_call, AVFilterGraph *, const char *, AVFilterInOut **, AVFilterInOut **, void *) ++ DEFINE_FUNC_ALIGNED2(int, __cdecl, avfilter_graph_config_dont_call, AVFilterGraph *, void *) + DEFINE_FUNC_ALIGNED1(int, __cdecl, avfilter_poll_frame, AVFilterLink *) + DEFINE_FUNC_ALIGNED1(int, __cdecl, avfilter_request_frame, AVFilterLink*) +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,13,0) + DEFINE_METHOD3(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int p3)) +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,7,0) +- DEFINE_METHOD2(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2)) +-#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,3,0) +- DEFINE_METHOD3(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int64_t p3)) +-#else +- DEFINE_METHOD4(int, av_vsrc_buffer_add_frame, (AVFilterContext *p1, AVFrame *p2, int64_t p3, AVRational p4)) +-#endif + DEFINE_METHOD4(AVFilterBufferRef*, avfilter_get_video_buffer, (AVFilterLink *p1, int p2, int p3, int p4)) + DEFINE_METHOD1(void, avfilter_unref_buffer, (AVFilterBufferRef *p1)) + DEFINE_METHOD4(int, avfilter_link, (AVFilterContext *p1, unsigned p2, AVFilterContext *p3, unsigned p4)) ++ DEFINE_FUNC_ALIGNED3(int , __cdecl, av_buffersink_get_buffer_ref, AVFilterContext *, AVFilterBufferRef **, int); ++ DEFINE_FUNC_ALIGNED0(AVBufferSinkParams*, __cdecl, av_buffersink_params_alloc); ++ DEFINE_FUNC_ALIGNED1(int , __cdecl, av_buffersink_poll_frame, AVFilterContext *); + + BEGIN_METHOD_RESOLVE() + RESOLVE_METHOD_RENAME(avfilter_open, avfilter_open_dont_call) +@@ -248,10 +185,8 @@ + RESOLVE_METHOD(avfilter_graph_create_filter) + RESOLVE_METHOD(avfilter_get_by_name) + RESOLVE_METHOD(avfilter_graph_alloc) +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + RESOLVE_METHOD_RENAME(avfilter_inout_alloc, avfilter_inout_alloc_dont_call) + RESOLVE_METHOD_RENAME(avfilter_inout_free, avfilter_inout_free_dont_call) +-#endif + RESOLVE_METHOD_RENAME(avfilter_graph_parse, avfilter_graph_parse_dont_call) + RESOLVE_METHOD_RENAME(avfilter_graph_config, avfilter_graph_config_dont_call) + RESOLVE_METHOD(avfilter_poll_frame) +@@ -260,10 +195,14 @@ + RESOLVE_METHOD(avfilter_get_video_buffer) + RESOLVE_METHOD(avfilter_unref_buffer) + RESOLVE_METHOD(avfilter_link) ++ RESOLVE_METHOD(av_buffersink_get_buffer_ref) ++ RESOLVE_METHOD(av_buffersink_params_alloc) ++ RESOLVE_METHOD(av_buffersink_poll_frame) + END_METHOD_RESOLVE() + + /* dependencies of libavfilter */ + DllAvUtil m_dllAvUtil; ++ DllSwResample m_dllSwResample; + + public: + int avfilter_open(AVFilterContext **filter_ctx, AVFilter *filter, const char *inst_name) +@@ -279,12 +218,7 @@ + void avfilter_graph_free(AVFilterGraph **graph) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(1,76,0) + avfilter_graph_free_dont_call(graph); +-#else +- avfilter_graph_free_dont_call(*graph); +- m_dllAvUtil.av_freep(graph); +-#endif + } + void avfilter_register_all() + { +@@ -294,45 +228,29 @@ + AVFilterInOut* avfilter_inout_alloc() + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + return avfilter_inout_alloc_dont_call(); +-#else +- return (AVFilterInOut*)m_dllAvUtil.av_mallocz(sizeof(AVFilterInOut)); +-#endif + } + int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, AVFilterInOut **inputs, AVFilterInOut **outputs, void *log_ctx) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,16,0) + return avfilter_graph_parse_dont_call(graph, filters, inputs, outputs, log_ctx); +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) +- return avfilter_graph_parse_dont_call(graph, filters, *inputs, *outputs, log_ctx); +-#else +- return avfilter_graph_parse_dont_call(graph, filters, *inputs, *outputs, (AVClass*)log_ctx); +-#endif + } + void avfilter_inout_free(AVFilterInOut **inout) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,17,0) + avfilter_inout_free_dont_call(inout); +-#else +- *inout = NULL; +-#endif + } + int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) + { + CSingleLock lock(DllAvCodec::m_critSection); +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,15,1) + return avfilter_graph_config_dont_call(graphctx, log_ctx); +-#else +- return avfilter_graph_config_dont_call(graphctx, (AVClass*)log_ctx); +-#endif + } + virtual bool Load() + { + if (!m_dllAvUtil.Load()) + return false; ++ if (!m_dllSwResample.Load()) ++ return false; + return DllDynamic::Load(); + } + }; +diff -Naur xbmc-pvr-11.0.1/lib/DllAvFormat.h xbmc-pvr-11.0.1.patch/lib/DllAvFormat.h +--- xbmc-pvr-11.0.1/lib/DllAvFormat.h 2012-03-27 17:55:44.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllAvFormat.h 2012-05-14 14:08:56.010373713 +0200 +@@ -62,57 +62,45 @@ + virtual ~DllAvFormatInterface() {} + virtual void av_register_all_dont_call(void)=0; + virtual AVInputFormat *av_find_input_format(const char *short_name)=0; +- virtual int url_feof(ByteIOContext *s)=0; +- virtual AVMetadataTag *av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags)=0; +- virtual void av_close_input_file(AVFormatContext *s)=0; +- virtual void av_close_input_stream(AVFormatContext *s)=0; ++ virtual int url_feof(AVIOContext *s)=0; ++ virtual void avformat_close_input(AVFormatContext **s)=0; + virtual int av_read_frame(AVFormatContext *s, AVPacket *pkt)=0; + virtual void av_read_frame_flush(AVFormatContext *s)=0; + virtual int av_read_play(AVFormatContext *s)=0; + virtual int av_read_pause(AVFormatContext *s)=0; + virtual int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags)=0; +-#if (!defined USE_EXTERNAL_FFMPEG) +- virtual int av_find_stream_info_dont_call(AVFormatContext *ic)=0; ++#if (!defined USE_EXTERNAL_FFMPEG) && (!defined TARGET_DARWIN) ++ virtual int avformat_find_stream_info_dont_call(AVFormatContext *ic, AVDictionary **options)=0; + #endif +- virtual int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap)=0; +- virtual void url_set_interrupt_cb(URLInterruptCB *interrupt_cb)=0; +- virtual int av_open_input_stream(AVFormatContext **ic_ptr, ByteIOContext *pb, const char *filename, AVInputFormat *fmt, AVFormatParameters *ap)=0; +- virtual int init_put_byte(ByteIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, ++ virtual int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)=0; ++ virtual AVIOContext *avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, + int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), + offset_t (*seek)(void *opaque, offset_t offset, int whence))=0; + virtual AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)=0; + virtual AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max)=0; +- virtual int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)=0; +- virtual void dump_format(AVFormatContext *ic, int index, const char *url, int is_output)=0; +- virtual int url_fdopen(ByteIOContext **s, URLContext *h)=0; +- virtual int url_fopen(ByteIOContext **s, const char *filename, int flags)=0; +- virtual int url_fclose(ByteIOContext *s)=0; +- virtual int url_open_dyn_buf(ByteIOContext **s)=0; +- virtual int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer)=0; +- virtual offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence)=0; +- virtual int get_buffer(ByteIOContext *s, unsigned char *buf, int size)=0; +- virtual int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size)=0; +- virtual void put_byte(ByteIOContext *s, int b)=0; +- virtual void put_buffer(ByteIOContext *s, const unsigned char *buf, int size)=0; +- virtual void put_be24(ByteIOContext *s, unsigned int val)=0; +- virtual void put_be32(ByteIOContext *s, unsigned int val)=0; +- virtual void put_be16(ByteIOContext *s, unsigned int val)=0; ++ virtual int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size)=0; ++ virtual void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output)=0; ++ virtual int avio_open(AVIOContext **s, const char *filename, int flags)=0; ++ virtual int avio_close(AVIOContext *s)=0; ++ virtual int avio_open_dyn_buf(AVIOContext **s)=0; ++ virtual int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer)=0; ++ virtual offset_t avio_seek(AVIOContext *s, offset_t offset, int whence)=0; ++ virtual int avio_read(AVIOContext *s, unsigned char *buf, int size)=0; ++ virtual void avio_w8(AVIOContext *s, int b)=0; ++ virtual void avio_write(AVIOContext *s, const unsigned char *buf, int size)=0; ++ virtual void avio_wb24(AVIOContext *s, unsigned int val)=0; ++ virtual void avio_wb32(AVIOContext *s, unsigned int val)=0; ++ virtual void avio_wb16(AVIOContext *s, unsigned int val)=0; + virtual AVFormatContext *avformat_alloc_context(void)=0; +- virtual AVStream *av_new_stream(AVFormatContext *s, int id)=0; ++ virtual AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c)=0; + virtual AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type)=0; +- virtual int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap)=0; +- virtual ByteIOContext *av_alloc_put_byte(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, +- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), +- int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), +- offset_t (*seek)(void *opaque, offset_t offset, int whence))=0; +- virtual int av_write_header (AVFormatContext *s)=0; ++ virtual int avformat_write_header (AVFormatContext *s, AVDictionary **options)=0; + virtual int av_write_trailer(AVFormatContext *s)=0; + virtual int av_write_frame (AVFormatContext *s, AVPacket *pkt)=0; +- virtual int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags)=0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + + // Use direct mapping + class DllAvFormat : public DllDynamic, DllAvFormatInterface +@@ -126,78 +114,45 @@ + } + virtual void av_register_all_dont_call() { *(int* )0x0 = 0; } + virtual AVInputFormat *av_find_input_format(const char *short_name) { return ::av_find_input_format(short_name); } +- virtual int url_feof(ByteIOContext *s) { return ::url_feof(s); } +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0) +- // API added on: 2009-03-01 +- virtual AVMetadataTag *av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags){ return ::av_metadata_get(m, key, prev, flags); } +-#else +- virtual AVMetadataTag *av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags){ return NULL; } +-#endif +- virtual void av_close_input_file(AVFormatContext *s) { ::av_close_input_file(s); } +- virtual void av_close_input_stream(AVFormatContext *s) { ::av_close_input_stream(s); } ++ virtual int url_feof(AVIOContext *s) { return ::url_feof(s); } ++ virtual void avformat_close_input(AVFormatContext **s) { ::avformat_close_input(s); } + virtual int av_read_frame(AVFormatContext *s, AVPacket *pkt) { return ::av_read_frame(s, pkt); } + virtual void av_read_frame_flush(AVFormatContext *s) { ::av_read_frame_flush(s); } + virtual int av_read_play(AVFormatContext *s) { return ::av_read_play(s); } + virtual int av_read_pause(AVFormatContext *s) { return ::av_read_pause(s); } + virtual int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { return ::av_seek_frame(s, stream_index, timestamp, flags); } +- virtual int av_find_stream_info(AVFormatContext *ic) ++ virtual int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) + { + CSingleLock lock(DllAvCodec::m_critSection); +- return ::av_find_stream_info(ic); ++ return ::avformat_find_stream_info(ic, options); + } +- virtual int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, AVInputFormat *fmt, int buf_size, AVFormatParameters *ap) { return ::av_open_input_file(ic_ptr, filename, fmt, buf_size, ap); } +- virtual void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) { ::url_set_interrupt_cb(interrupt_cb); } +- virtual int av_open_input_stream(AVFormatContext **ic_ptr, ByteIOContext *pb, const char *filename, AVInputFormat *fmt, AVFormatParameters *ap) { return ::av_open_input_stream(ic_ptr, pb, filename, fmt, ap); } +- virtual int init_put_byte(ByteIOContext *s, unsigned char *buffer, int buffer_size, int write_flag, void *opaque, ++ virtual int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options) ++ { return ::avformat_open_input(ps, filename, fmt, options); } ++ virtual AVIOContext *avio_alloc_context(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, + int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), +- offset_t (*seek)(void *opaque, offset_t offset, int whence)) { return ::init_put_byte(s, buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek); } ++ offset_t (*seek)(void *opaque, offset_t offset, int whence)) { return ::avio_alloc_context(buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek); } + virtual AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) {return ::av_probe_input_format(pd, is_opened); } + virtual AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max) {*score_max = 100; return ::av_probe_input_format(pd, is_opened); } // Use av_probe_input_format, this is not exported by ffmpeg's headers +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,98,0) +- // API added on: 2010-02-08 +- virtual int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size) { return ::av_probe_input_buffer(pb, fmt, filename, logctx, offset, max_probe_size); } +-#else +- virtual int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size) { return -1; } +-#endif +- virtual void dump_format(AVFormatContext *ic, int index, const char *url, int is_output) { ::dump_format(ic, index, url, is_output); } +- virtual int url_fdopen(ByteIOContext **s, URLContext *h) { return ::url_fdopen(s, h); } +- virtual int url_fopen(ByteIOContext **s, const char *filename, int flags) { return ::url_fopen(s, filename, flags); } +- virtual int url_fclose(ByteIOContext *s) { return ::url_fclose(s); } +- virtual int url_open_dyn_buf(ByteIOContext **s) { return ::url_open_dyn_buf(s); } +- virtual int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer) { return ::url_close_dyn_buf(s, pbuffer); } +- virtual offset_t url_fseek(ByteIOContext *s, offset_t offset, int whence) { return ::url_fseek(s, offset, whence); } +- virtual int get_buffer(ByteIOContext *s, unsigned char *buf, int size) { return ::get_buffer(s, buf, size); } +- virtual int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size) { return ::get_partial_buffer(s, buf, size); } +- virtual void put_byte(ByteIOContext *s, int b) { ::put_byte(s, b); } +- virtual void put_buffer(ByteIOContext *s, const unsigned char *buf, int size) { ::put_buffer(s, buf, size); } +- virtual void put_be24(ByteIOContext *s, unsigned int val) { ::put_be24(s, val); } +- virtual void put_be32(ByteIOContext *s, unsigned int val) { ::put_be32(s, val); } +- virtual void put_be16(ByteIOContext *s, unsigned int val) { ::put_be16(s, val); } ++ virtual int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, const char *filename, void *logctx, unsigned int offset, unsigned int max_probe_size) { return ::av_probe_input_buffer(pb, fmt, filename, logctx, offset, max_probe_size); } ++ virtual void av_dump_format(AVFormatContext *ic, int index, const char *url, int is_output) { ::av_dump_format(ic, index, url, is_output); } ++ virtual int avio_open(AVIOContext **s, const char *filename, int flags) { return ::avio_open(s, filename, flags); } ++ virtual int avio_close(AVIOContext *s) { return ::avio_close(s); } ++ virtual int avio_open_dyn_buf(AVIOContext **s) { return ::avio_open_dyn_buf(s); } ++ virtual int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) { return ::avio_close_dyn_buf(s, pbuffer); } ++ virtual offset_t avio_seek(AVIOContext *s, offset_t offset, int whence) { return ::avio_seek(s, offset, whence); } ++ virtual int avio_read(AVIOContext *s, unsigned char *buf, int size) { return ::avio_read(s, buf, size); } ++ virtual void avio_w8(AVIOContext *s, int b) { ::avio_w8(s, b); } ++ virtual void avio_write(AVIOContext *s, const unsigned char *buf, int size) { ::avio_write(s, buf, size); } ++ virtual void avio_wb24(AVIOContext *s, unsigned int val) { ::avio_wb24(s, val); } ++ virtual void avio_wb32(AVIOContext *s, unsigned int val) { ::avio_wb32(s, val); } ++ virtual void avio_wb16(AVIOContext *s, unsigned int val) { ::avio_wb16(s, val); } + virtual AVFormatContext *avformat_alloc_context() { return ::avformat_alloc_context(); } +- virtual AVStream *av_new_stream(AVFormatContext *s, int id) { return ::av_new_stream(s, id); } +-#if LIBAVFORMAT_VERSION_INT < (52<<16 | 45<<8) +- virtual AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type) { return ::guess_format(short_name, filename, mime_type); } +-#else ++ virtual AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c) { return ::avformat_new_stream(s, c); } + virtual AVOutputFormat *av_guess_format(const char *short_name, const char *filename, const char *mime_type) { return ::av_guess_format(short_name, filename, mime_type); } +-#endif +- virtual int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) { return ::av_set_parameters(s, ap); } +- virtual ByteIOContext *av_alloc_put_byte(unsigned char *buffer, int buffer_size, int write_flag, void *opaque, +- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), +- int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), +- offset_t (*seek)(void *opaque, offset_t offset, int whence)) { return ::av_alloc_put_byte(buffer, buffer_size, write_flag, opaque, read_packet, write_packet, seek); } +- virtual int av_write_header (AVFormatContext *s) { return ::av_write_header (s); } ++ virtual int avformat_write_header (AVFormatContext *s, AVDictionary **options) { return ::avformat_write_header (s, options); } + virtual int av_write_trailer(AVFormatContext *s) { return ::av_write_trailer(s); } + virtual int av_write_frame (AVFormatContext *s, AVPacket *pkt) { return ::av_write_frame(s, pkt); } +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,43,0) +- // API added on: 2009-12-13 +- virtual int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags) { return ::av_metadata_set2(pm, key, value, flags); } +-#elif LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,31,0) +- // API added on: 2009-03-01 +- virtual int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags) { return ::av_metadata_set(pm, key, value); } +-#else +- virtual int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags) { return -1; } +-#endif + + // DLL faking. + virtual bool ResolveExports() { return true; } +@@ -218,108 +173,78 @@ + + DEFINE_METHOD0(void, av_register_all_dont_call) + DEFINE_METHOD1(AVInputFormat*, av_find_input_format, (const char *p1)) +- DEFINE_METHOD1(int, url_feof, (ByteIOContext *p1)) +- DEFINE_METHOD4(AVMetadataTag*, av_metadata_get, (AVMetadata *p1, const char *p2, const AVMetadataTag *p3, int p4)) +- DEFINE_METHOD1(void, av_close_input_file, (AVFormatContext *p1)) +- DEFINE_METHOD1(void, av_close_input_stream, (AVFormatContext *p1)) ++ DEFINE_METHOD1(int, url_feof, (AVIOContext *p1)) ++ DEFINE_METHOD1(void, avformat_close_input, (AVFormatContext **p1)) + DEFINE_METHOD1(int, av_read_play, (AVFormatContext *p1)) + DEFINE_METHOD1(int, av_read_pause, (AVFormatContext *p1)) + DEFINE_METHOD1(void, av_read_frame_flush, (AVFormatContext *p1)) + DEFINE_FUNC_ALIGNED2(int, __cdecl, av_read_frame, AVFormatContext *, AVPacket *) + DEFINE_FUNC_ALIGNED4(int, __cdecl, av_seek_frame, AVFormatContext*, int, int64_t, int) +- DEFINE_FUNC_ALIGNED1(int, __cdecl, av_find_stream_info_dont_call, AVFormatContext*) +- DEFINE_FUNC_ALIGNED5(int, __cdecl, av_open_input_file, AVFormatContext**, const char *, AVInputFormat *, int, AVFormatParameters *) +- DEFINE_FUNC_ALIGNED5(int,__cdecl, av_open_input_stream, AVFormatContext **, ByteIOContext *, const char *, AVInputFormat *, AVFormatParameters *) ++ DEFINE_FUNC_ALIGNED2(int, __cdecl, avformat_find_stream_info_dont_call, AVFormatContext*, AVDictionary **) ++ DEFINE_FUNC_ALIGNED4(int, __cdecl, avformat_open_input, AVFormatContext **, const char *, AVInputFormat *, AVDictionary **) + DEFINE_FUNC_ALIGNED2(AVInputFormat*, __cdecl, av_probe_input_format, AVProbeData*, int) + DEFINE_FUNC_ALIGNED3(AVInputFormat*, __cdecl, av_probe_input_format2, AVProbeData*, int, int*) +- DEFINE_FUNC_ALIGNED6(int, __cdecl, av_probe_input_buffer, ByteIOContext *, AVInputFormat **, const char *, void *, unsigned int, unsigned int) +- DEFINE_FUNC_ALIGNED3(int, __cdecl, get_buffer, ByteIOContext*, unsigned char *, int) +- DEFINE_FUNC_ALIGNED3(int, __cdecl, get_partial_buffer, ByteIOContext*, unsigned char *, int) +- DEFINE_FUNC_ALIGNED2(void, __cdecl, put_byte, ByteIOContext*, int) +- DEFINE_FUNC_ALIGNED3(void, __cdecl, put_buffer, ByteIOContext*, const unsigned char *, int) +- DEFINE_FUNC_ALIGNED2(void, __cdecl, put_be24, ByteIOContext*, unsigned int) +- DEFINE_FUNC_ALIGNED2(void, __cdecl, put_be32, ByteIOContext*, unsigned int) +- DEFINE_FUNC_ALIGNED2(void, __cdecl, put_be16, ByteIOContext*, unsigned int) +- DEFINE_METHOD1(void, url_set_interrupt_cb, (URLInterruptCB *p1)) +- DEFINE_METHOD8(int, init_put_byte, (ByteIOContext *p1, unsigned char *p2, int p3, int p4, void *p5, ++ DEFINE_FUNC_ALIGNED6(int, __cdecl, av_probe_input_buffer, AVIOContext *, AVInputFormat **, const char *, void *, unsigned int, unsigned int) ++ DEFINE_FUNC_ALIGNED3(int, __cdecl, avio_read, AVIOContext*, unsigned char *, int) ++ DEFINE_FUNC_ALIGNED2(void, __cdecl, avio_w8, AVIOContext*, int) ++ DEFINE_FUNC_ALIGNED3(void, __cdecl, avio_write, AVIOContext*, const unsigned char *, int) ++ DEFINE_FUNC_ALIGNED2(void, __cdecl, avio_wb24, AVIOContext*, unsigned int) ++ DEFINE_FUNC_ALIGNED2(void, __cdecl, avio_wb32, AVIOContext*, unsigned int) ++ DEFINE_FUNC_ALIGNED2(void, __cdecl, avio_wb16, AVIOContext*, unsigned int) ++ DEFINE_METHOD7(AVIOContext *, avio_alloc_context, (unsigned char *p1, int p2, int p3, void *p4, ++ int (*p5)(void *opaque, uint8_t *buf, int buf_size), + int (*p6)(void *opaque, uint8_t *buf, int buf_size), +- int (*p7)(void *opaque, uint8_t *buf, int buf_size), +- offset_t (*p8)(void *opaque, offset_t offset, int whence))) +- DEFINE_METHOD4(void, dump_format, (AVFormatContext *p1, int p2, const char *p3, int p4)) +- DEFINE_METHOD2(int, url_fdopen, (ByteIOContext **p1, URLContext *p2)) +- DEFINE_METHOD3(int, url_fopen, (ByteIOContext **p1, const char *p2, int p3)) +- DEFINE_METHOD1(int, url_fclose, (ByteIOContext *p1)) +- DEFINE_METHOD1(int, url_open_dyn_buf, (ByteIOContext **p1)) +- DEFINE_METHOD2(int, url_close_dyn_buf, (ByteIOContext *p1, uint8_t **p2)) +- DEFINE_METHOD3(offset_t, url_fseek, (ByteIOContext *p1, offset_t p2, int p3)) ++ offset_t (*p7)(void *opaque, offset_t offset, int whence))) ++ DEFINE_METHOD4(void, av_dump_format, (AVFormatContext *p1, int p2, const char *p3, int p4)) ++ DEFINE_METHOD3(int, avio_open, (AVIOContext **p1, const char *p2, int p3)) ++ DEFINE_METHOD1(int, avio_close, (AVIOContext *p1)) ++ DEFINE_METHOD1(int, avio_open_dyn_buf, (AVIOContext **p1)) ++ DEFINE_METHOD2(int, avio_close_dyn_buf, (AVIOContext *p1, uint8_t **p2)) ++ DEFINE_METHOD3(offset_t, avio_seek, (AVIOContext *p1, offset_t p2, int p3)) + DEFINE_METHOD0(AVFormatContext *, avformat_alloc_context) +- DEFINE_METHOD2(AVStream *, av_new_stream, (AVFormatContext *p1, int p2)) +-#if LIBAVFORMAT_VERSION_INT < (52<<16 | 45<<8) +- DEFINE_METHOD3(AVOutputFormat *, guess_format, (const char *p1, const char *p2, const char *p3)) +-#else ++ DEFINE_METHOD2(AVStream *, avformat_new_stream, (AVFormatContext *p1, AVCodec *p2)) + DEFINE_METHOD3(AVOutputFormat *, av_guess_format, (const char *p1, const char *p2, const char *p3)) +-#endif +- DEFINE_METHOD2(int, av_set_parameters, (AVFormatContext *p1, AVFormatParameters *p2)); +- DEFINE_METHOD7(ByteIOContext *, av_alloc_put_byte, (unsigned char *p1, int p2, int p3, void *p4, +- int(*p5)(void *opaque, uint8_t *buf, int buf_size), +- int(*p6)(void *opaque, uint8_t *buf, int buf_size), +- offset_t(*p7)(void *opaque, offset_t offset, int whence))) +- DEFINE_METHOD1(int, av_write_header , (AVFormatContext *p1)) ++ DEFINE_METHOD2(int, avformat_write_header , (AVFormatContext *p1, AVDictionary **p2)) + DEFINE_METHOD1(int, av_write_trailer, (AVFormatContext *p1)) + DEFINE_METHOD2(int, av_write_frame , (AVFormatContext *p1, AVPacket *p2)) +- DEFINE_METHOD4(int, av_metadata_set2, (AVMetadata **p1, const char *p2, const char *p3, int p4)); + BEGIN_METHOD_RESOLVE() + RESOLVE_METHOD_RENAME(av_register_all, av_register_all_dont_call) + RESOLVE_METHOD(av_find_input_format) + RESOLVE_METHOD(url_feof) +- RESOLVE_METHOD(av_metadata_get) +- RESOLVE_METHOD(av_close_input_file) +- RESOLVE_METHOD(av_close_input_stream) ++ RESOLVE_METHOD(avformat_close_input) + RESOLVE_METHOD(av_read_frame) + RESOLVE_METHOD(av_read_play) + RESOLVE_METHOD(av_read_pause) +- RESOLVE_METHOD_RENAME(ff_read_frame_flush, av_read_frame_flush) ++ RESOLVE_METHOD(av_read_frame_flush) + RESOLVE_METHOD(av_seek_frame) +- RESOLVE_METHOD_RENAME(av_find_stream_info, av_find_stream_info_dont_call) +- RESOLVE_METHOD(av_open_input_file) +- RESOLVE_METHOD(url_set_interrupt_cb) +- RESOLVE_METHOD(av_open_input_stream) +- RESOLVE_METHOD(init_put_byte) ++ RESOLVE_METHOD_RENAME(avformat_find_stream_info, avformat_find_stream_info_dont_call) ++ RESOLVE_METHOD(avformat_open_input) ++ RESOLVE_METHOD(avio_alloc_context) + RESOLVE_METHOD(av_probe_input_format) + RESOLVE_METHOD(av_probe_input_format2) + RESOLVE_METHOD(av_probe_input_buffer) +- RESOLVE_METHOD(dump_format) +- RESOLVE_METHOD(url_fdopen) +- RESOLVE_METHOD(url_fopen) +- RESOLVE_METHOD(url_fclose) +- RESOLVE_METHOD(url_open_dyn_buf) +- RESOLVE_METHOD(url_close_dyn_buf) +- RESOLVE_METHOD(url_fseek) +- RESOLVE_METHOD(get_buffer) +- RESOLVE_METHOD(get_partial_buffer) +- RESOLVE_METHOD(put_byte) +- RESOLVE_METHOD(put_buffer) +- RESOLVE_METHOD(put_be24) +- RESOLVE_METHOD(put_be32) +- RESOLVE_METHOD(put_be16) ++ RESOLVE_METHOD(av_dump_format) ++ RESOLVE_METHOD(avio_open) ++ RESOLVE_METHOD(avio_close) ++ RESOLVE_METHOD(avio_open_dyn_buf) ++ RESOLVE_METHOD(avio_close_dyn_buf) ++ RESOLVE_METHOD(avio_seek) ++ RESOLVE_METHOD(avio_read) ++ RESOLVE_METHOD(avio_w8) ++ RESOLVE_METHOD(avio_write) ++ RESOLVE_METHOD(avio_wb24) ++ RESOLVE_METHOD(avio_wb32) ++ RESOLVE_METHOD(avio_wb16) + RESOLVE_METHOD(avformat_alloc_context) +- RESOLVE_METHOD(av_new_stream) +-#if LIBAVFORMAT_VERSION_INT < (52<<16 | 45<<8) +- RESOLVE_METHOD(guess_format) +-#else ++ RESOLVE_METHOD(avformat_new_stream) + RESOLVE_METHOD(av_guess_format) +-#endif +- RESOLVE_METHOD(av_set_parameters) +- RESOLVE_METHOD(av_alloc_put_byte) +- RESOLVE_METHOD(av_write_header) ++ RESOLVE_METHOD(avformat_write_header) + RESOLVE_METHOD(av_write_trailer) + RESOLVE_METHOD(av_write_frame) +- RESOLVE_METHOD(av_metadata_set2) + END_METHOD_RESOLVE() + + /* dependencies of libavformat */ + DllAvCodec m_dllAvCodec; +- // DllAvCore loaded implicitely by m_dllAvCodec + // DllAvUtil loaded implicitely by m_dllAvCodec + + public: +@@ -328,10 +253,10 @@ + CSingleLock lock(DllAvCodec::m_critSection); + av_register_all_dont_call(); + } +- int av_find_stream_info(AVFormatContext *ic) ++ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) + { + CSingleLock lock(DllAvCodec::m_critSection); +- return(av_find_stream_info_dont_call(ic)); ++ return avformat_find_stream_info_dont_call(ic, options); + } + + virtual bool Load() +diff -Naur xbmc-pvr-11.0.1/lib/DllAvUtil.h xbmc-pvr-11.0.1.patch/lib/DllAvUtil.h +--- xbmc-pvr-11.0.1/lib/DllAvUtil.h 2012-03-27 17:55:43.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllAvUtil.h 2012-05-14 14:08:56.010373713 +0200 +@@ -65,6 +65,7 @@ + #include "libavutil/opt.h" + #include "libavutil/mem.h" + #include "libavutil/fifo.h" ++ #include "libavutil/samplefmt.h" + #endif + } + +@@ -89,7 +90,7 @@ + virtual int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)=0; + virtual const AVCRC* av_crc_get_table(AVCRCId crc_id)=0; + virtual uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)=0; +- virtual int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out)=0; ++ virtual int av_opt_set(void *obj, const char *name, const char *val, int search_flags)=0; + virtual AVFifoBuffer *av_fifo_alloc(unsigned int size) = 0; + virtual void av_fifo_free(AVFifoBuffer *f) = 0; + virtual void av_fifo_reset(AVFifoBuffer *f) = 0; +@@ -97,10 +98,13 @@ + virtual int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int)) = 0; + virtual int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)) = 0; + virtual char *av_strdup(const char *s)=0; ++ virtual int av_get_bytes_per_sample(enum AVSampleFormat p1) = 0; ++ virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) = 0; ++ virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags)=0; ++ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) = 0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) +- ++#if defined (USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + // Use direct layer + class DllAvUtilBase : public DllDynamic, DllAvUtilInterface + { +@@ -117,12 +121,7 @@ + virtual int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq) { return ::av_rescale_q(a, bq, cq); } + virtual const AVCRC* av_crc_get_table(AVCRCId crc_id) { return ::av_crc_get_table(crc_id); } + virtual uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length) { return ::av_crc(ctx, crc, buffer, length); } +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,7,0) +- // API added on: 2008-12-16 +- virtual int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out) { return ::av_set_string3(obj, name, val, alloc, o_out); } +-#else +- virtual int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out) { return AVERROR(ENOENT); } +-#endif ++ virtual int av_opt_set(void *obj, const char *name, const char *val, int search_flags) { return ::av_opt_set(obj, name, val, search_flags); } + virtual AVFifoBuffer *av_fifo_alloc(unsigned int size) {return ::av_fifo_alloc(size); } + virtual void av_fifo_free(AVFifoBuffer *f) { ::av_fifo_free(f); } + virtual void av_fifo_reset(AVFifoBuffer *f) { ::av_fifo_reset(f); } +@@ -132,6 +131,12 @@ + virtual int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)) + { return ::av_fifo_generic_write(f, src, size, func); } + virtual char *av_strdup(const char *s) { return ::av_strdup(s); } ++ virtual int av_get_bytes_per_sample(enum AVSampleFormat p1) ++ { return ::av_get_bytes_per_sample(p1); } ++ virtual AVDictionaryEntry *av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags){ return ::av_dict_get(m, key, prev, flags); } ++ virtual int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags) { return ::av_dict_set(pm, key, value, flags); } ++ virtual int av_samples_get_buffer_size (int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align) ++ { return ::av_samples_get_buffer_size(linesize, nb_channels, nb_samples, sample_fmt, align); } + + // DLL faking. + virtual bool ResolveExports() { return true; } +@@ -160,7 +165,7 @@ + DEFINE_METHOD3(int64_t, av_rescale_q, (int64_t p1, AVRational p2, AVRational p3)); + DEFINE_METHOD1(const AVCRC*, av_crc_get_table, (AVCRCId p1)) + DEFINE_METHOD4(uint32_t, av_crc, (const AVCRC *p1, uint32_t p2, const uint8_t *p3, size_t p4)); +- DEFINE_METHOD5(int, av_set_string3, (void *p1, const char *p2, const char *p3, int p4, const AVOption **p5)); ++ DEFINE_METHOD4(int, av_opt_set, (void *p1, const char *p2, const char *p3, int p4)); + DEFINE_METHOD1(AVFifoBuffer*, av_fifo_alloc, (unsigned int p1)) + DEFINE_METHOD1(void, av_fifo_free, (AVFifoBuffer *p1)) + DEFINE_METHOD1(void, av_fifo_reset, (AVFifoBuffer *p1)) +@@ -168,6 +173,10 @@ + DEFINE_METHOD4(int, av_fifo_generic_read, (AVFifoBuffer *p1, void *p2, int p3, void (*p4)(void*, void*, int))) + DEFINE_METHOD4(int, av_fifo_generic_write, (AVFifoBuffer *p1, void *p2, int p3, int (*p4)(void*, void*, int))) + DEFINE_METHOD1(char*, av_strdup, (const char *p1)) ++ DEFINE_METHOD1(int, av_get_bytes_per_sample, (enum AVSampleFormat p1)) ++ DEFINE_METHOD4(AVDictionaryEntry *, av_dict_get, (AVDictionary *p1, const char *p2, const AVDictionaryEntry *p3, int p4)) ++ DEFINE_METHOD4(int, av_dict_set, (AVDictionary **p1, const char *p2, const char *p3, int p4)); ++ DEFINE_METHOD5(int, av_samples_get_buffer_size, (int *p1, int p2, int p3, enum AVSampleFormat p4, int p5)) + + public: + BEGIN_METHOD_RESOLVE() +@@ -181,7 +190,7 @@ + RESOLVE_METHOD(av_rescale_q) + RESOLVE_METHOD(av_crc_get_table) + RESOLVE_METHOD(av_crc) +- RESOLVE_METHOD(av_set_string3) ++ RESOLVE_METHOD(av_opt_set) + RESOLVE_METHOD(av_fifo_alloc) + RESOLVE_METHOD(av_fifo_free) + RESOLVE_METHOD(av_fifo_reset) +@@ -189,6 +198,10 @@ + RESOLVE_METHOD(av_fifo_generic_read) + RESOLVE_METHOD(av_fifo_generic_write) + RESOLVE_METHOD(av_strdup) ++ RESOLVE_METHOD(av_get_bytes_per_sample) ++ RESOLVE_METHOD(av_dict_get) ++ RESOLVE_METHOD(av_dict_set) ++ RESOLVE_METHOD(av_samples_get_buffer_size) + END_METHOD_RESOLVE() + }; + +diff -Naur xbmc-pvr-11.0.1/lib/DllPostProc.h xbmc-pvr-11.0.1.patch/lib/DllPostProc.h +--- xbmc-pvr-11.0.1/lib/DllPostProc.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllPostProc.h 2012-05-14 14:08:56.011373733 +0200 +@@ -87,7 +87,7 @@ + virtual void pp_free_context(pp_context *ppContext)=0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + + // We call directly. + class DllPostProc : public DllDynamic, DllPostProcInterface +diff -Naur xbmc-pvr-11.0.1/lib/DllSwResample.h xbmc-pvr-11.0.1.patch/lib/DllSwResample.h +--- xbmc-pvr-11.0.1/lib/DllSwResample.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/DllSwResample.h 2012-05-14 14:08:56.012373753 +0200 +@@ -0,0 +1,87 @@ ++#pragma once ++/* ++ * Copyright (C) 2005-2010 Team XBMC ++ * http://www.xbmc.org ++ * ++ * This Program 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, or (at your option) ++ * any later version. ++ * ++ * This Program 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 XBMC; see the file COPYING. If not, write to ++ * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. ++ * http://www.gnu.org/copyleft/gpl.html ++ * ++ */ ++ ++#if (defined HAVE_CONFIG_H) && (!defined WIN32) ++ #include "config.h" ++#endif ++#include "DynamicDll.h" ++ ++extern "C" { ++#ifndef HAVE_MMX ++#define HAVE_MMX ++#endif ++#ifndef __STDC_CONSTANT_MACROS ++#define __STDC_CONSTANT_MACROS ++#endif ++#ifndef __GNUC__ ++#pragma warning(disable:4244) ++#endif ++#if (defined USE_EXTERNAL_FFMPEG) ++ #include ++#else ++ #include "libswresample/swresample.h" ++#endif ++} ++ ++ ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) ++ ++// Use direct mapping ++class DllSwResample : public DllDynamic ++{ ++public: ++ virtual ~DllSwResample() {} ++ ++ // DLL faking. ++ virtual bool ResolveExports() { return true; } ++ virtual bool Load() { ++ CLog::Log(LOGDEBUG, "DllAvFormat: Using libswresample system library"); ++ return true; ++ } ++ virtual void Unload() {} ++}; ++ ++#else ++ ++class DllSwResample : public DllDynamic ++{ ++ DECLARE_DLL_WRAPPER(DllSwResample, DLL_PATH_LIBSWRESAMPLE) ++ ++ LOAD_SYMBOLS() ++ ++ BEGIN_METHOD_RESOLVE() ++ END_METHOD_RESOLVE() ++ ++ /* dependencies of libavformat */ ++ DllAvUtil m_dllAvUtil; ++ ++public: ++ ++ virtual bool Load() ++ { ++ if (!m_dllAvUtil.Load()) ++ return false; ++ return DllDynamic::Load(); ++ } ++}; ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/DllSwScale.h xbmc-pvr-11.0.1.patch/lib/DllSwScale.h +--- xbmc-pvr-11.0.1/lib/DllSwScale.h 2012-03-27 17:55:42.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/DllSwScale.h 2012-05-14 14:08:56.012373753 +0200 +@@ -92,7 +92,7 @@ + virtual void sws_freeContext(struct SwsContext *context)=0; + }; + +-#if (defined USE_EXTERNAL_FFMPEG) ++#if (defined USE_EXTERNAL_FFMPEG) || (defined TARGET_DARWIN) + + // We call into this library directly. + class DllSwScale : public DllDynamic, public DllSwScaleInterface +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/build_xbmc_win32.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/build_xbmc_win32.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/build_xbmc_win32.sh 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/build_xbmc_win32.sh 2012-05-14 14:08:53.101315166 +0200 +@@ -51,10 +51,10 @@ + + make $MAKEFLAGS && + cp lib*/*.dll .libs/ && +-cp .libs/avcodec-52.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/avcore-0.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/avformat-52.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/avutil-50.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/avfilter-1.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/postproc-51.dll /xbmc/system/players/dvdplayer/ && +-cp .libs/swscale-0.dll /xbmc/system/players/dvdplayer/ ++cp .libs/avcodec-53.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/avformat-53.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/avutil-51.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/avfilter-2.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/postproc-52.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/swresample-0.dll /xbmc/system/players/dvdplayer/ && ++cp .libs/swscale-2.dll /xbmc/system/players/dvdplayer/ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/Changelog xbmc-pvr-11.0.1.patch/lib/ffmpeg/Changelog +--- xbmc-pvr-11.0.1/lib/ffmpeg/Changelog 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/Changelog 2012-05-14 14:08:53.068314502 +0200 +@@ -1,9 +1,222 @@ + Entries are sorted chronologically from oldest to youngest within each release, + releases are sorted from youngest to oldest. + ++version next: + +-version : ++version 0.10.1 ++- Several security fixes, many bugfixes affecting many formats and ++ codecs, the list below is not complete. ++ ++- swapuv filter ++ ++- Several bugs and crashes have been fixed in the following codecs: AAC, ++ AC-3, ADPCM, AMR (both NB and WB), ATRAC3, CAVC, Cook, camstudio, DCA, ++ DPCM, DSI CIN, DV, EA TGQ, FLAC, fraps, G.722 (both encoder and ++ decoder), H.264, huvffyuv, BB JV decoder, Indeo 3, KGV1, LCL, the ++ libx264 wrapper, MJPEG, mp3on4, Musepack, MPEG1/2, PNG, QDM2, Qt RLE, ++ ROQ, RV10, RV30/RV34/RV40, shorten, smacker, subrip, SVQ3, TIFF, ++ Truemotion2, TTA, VC1, VMware Screen codec, Vorbis, VP5, VP6, WMA, ++ Westwood SNDx, XXAN. ++ ++- This release additionally updates the following codecs to the ++ bytestream2 API, and therefore benefit from additional overflow ++ checks: XXAN, ALG MM, TQG, SMC, Qt SMC, ROQ, PNG ++ ++- Several bugs and crashes have been fixed in the following formats: ++ AIFF, ASF, DV, Matroska, NSV, MOV, MPEG-TS, Smacker, Sony OpenMG, RM, ++ SWF. ++ ++- Libswscale has an potential overflow for large image size fixed. ++ ++- The following APIs have been added: ++ ++ avcodec_is_open() ++ avformat_get_riff_video_tags() ++ avformat_get_riff_audio_tags() ++ ++ Please see the file doc/APIchanges and the Doxygen documentation for ++ further information. ++ ++ ++version 0.10: ++- Fixes: CVE-2011-3929, CVE-2011-3934, CVE-2011-3935, CVE-2011-3936, ++ CVE-2011-3937, CVE-2011-3940, CVE-2011-3941, CVE-2011-3944, ++ CVE-2011-3945, CVE-2011-3946, CVE-2011-3947, CVE-2011-3949, ++ CVE-2011-3950, CVE-2011-3951, CVE-2011-3952 ++- v410 Quicktime Uncompressed 4:4:4 10-bit encoder and decoder ++- SBaGen (SBG) binaural beats script demuxer ++- OpenMG Audio muxer ++- Timecode extraction in DV and MOV ++- thumbnail video filter ++- XML output in ffprobe ++- asplit audio filter ++- tinterlace video filter ++- astreamsync audio filter ++- amerge audio filter ++- ISMV (Smooth Streaming) muxer ++- GSM audio parser ++- SMJPEG muxer ++- XWD encoder and decoder ++- Automatic thread count based on detection number of (available) CPU cores ++- y41p Brooktree Uncompressed 4:1:1 12-bit encoder and decoder ++- ffprobe -show_error option ++- Avid 1:1 10-bit RGB Packer codec ++- v308 Quicktime Uncompressed 4:4:4 encoder and decoder ++- yuv4 libquicktime packed 4:2:0 encoder and decoder ++- ffprobe -show_frames option ++- silencedetect audio filter ++- ffprobe -show_program_version, -show_library_versions, -show_versions options ++- rv34: frame-level multi-threading ++- optimized iMDCT transform on x86 using SSE for for mpegaudiodec ++- Improved PGS subtitle decoder ++- dumpgraph option to lavfi device ++- r210 and r10k encoders ++- ffwavesynth decoder ++- aviocat tool ++- ffeval tool ++ ++ ++version 0.9: ++ ++- openal input device added ++- boxblur filter added ++- BWF muxer ++- Flash Screen Video 2 decoder ++- lavfi input device added ++- added avconv, which is almost the same for now, except ++for a few incompatible changes in the options, which will hopefully make them ++easier to use. The changes are: ++ * The options placement is now strictly enforced! While in theory the ++ options for ffmpeg should be given in [input options] -i INPUT [output ++ options] OUTPUT order, in practice it was possible to give output options ++ before the -i and it mostly worked. Except when it didn't - the behavior was ++ a bit inconsistent. In avconv, it is not possible to mix input and output ++ options. All non-global options are reset after an input or output filename. ++ * All per-file options are now truly per-file - they apply only to the next ++ input or output file and specifying different values for different files ++ will now work properly (notably -ss and -t options). ++ * All per-stream options are now truly per-stream - it is possible to ++ specify which stream(s) should a given option apply to. See the Stream ++ specifiers section in the avconv manual for details. ++ * In ffmpeg some options (like -newvideo/-newaudio/...) are irregular in the ++ sense that they're specified after the output filename instead of before, ++ like all other options. In avconv this irregularity is removed, all options ++ apply to the next input or output file. ++ * -newvideo/-newaudio/-newsubtitle options were removed. Not only were they ++ irregular and highly confusing, they were also redundant. In avconv the -map ++ option will create new streams in the output file and map input streams to ++ them. E.g. avconv -i INPUT -map 0 OUTPUT will create an output stream for ++ each stream in the first input file. ++ * The -map option now has slightly different and more powerful syntax: ++ + Colons (':') are used to separate file index/stream type/stream index ++ instead of dots. Comma (',') is used to separate the sync stream instead ++ of colon.. This is done for consistency with other options. ++ + It's possible to specify stream type. E.g. -map 0:a:2 creates an ++ output stream from the third input audio stream. ++ + Omitting the stream index now maps all the streams of the given type, ++ not just the first. E.g. -map 0:s creates output streams for all the ++ subtitle streams in the first input file. ++ + Since -map can now match multiple streams, negative mappings were ++ introduced. Negative mappings disable some streams from an already ++ defined map. E.g. '-map 0 -map -0:a:1' means 'create output streams for ++ all the stream in the first input file, except for the second audio ++ stream'. ++ * There is a new option -c (or -codec) for choosing the decoder/encoder to ++ use, which allows to precisely specify target stream(s) consistently with ++ other options. E.g. -c:v lib264 sets the codec for all video streams, -c:a:0 ++ libvorbis sets the codec for the first audio stream and -c copy copies all ++ the streams without reencoding. Old -vcodec/-acodec/-scodec options are now ++ aliases to -c:v/a/s ++ * It is now possible to precisely specify which stream should an AVOption ++ apply to. E.g. -b:v:0 2M sets the bitrate for the first video stream, while ++ -b:a 128k sets the bitrate for all audio streams. Note that the old -ab 128k ++ syntax is deprecated and will stop working soon. ++ * -map_chapters now takes only an input file index and applies to the next ++ output file. This is consistent with how all the other options work. ++ * -map_metadata now takes only an input metadata specifier and applies to ++ the next output file. Output metadata specifier is now part of the option ++ name, similarly to the AVOptions/map/codec feature above. ++ * -metadata can now be used to set metadata on streams and chapters, e.g. ++ -metadata:s:1 language=eng sets the language of the first stream to 'eng'. ++ This made -vlang/-alang/-slang options redundant, so they were removed. ++ * -qscale option now uses stream specifiers and applies to all streams, not ++ just video. I.e. plain -qscale number would now apply to all streams. To get ++ the old behavior, use -qscale:v. Also there is now a shortcut -q for -qscale ++ and -aq is now an alias for -q:a. ++ * -vbsf/-absf/-sbsf options were removed and replaced by a -bsf option which ++ uses stream specifiers. Use -bsf:v/a/s instead of the old options. ++ * -itsscale option now uses stream specifiers, so its argument is only the ++ scale parameter. ++ * -intra option was removed, use -g 0 for the same effect. ++ * -psnr option was removed, use -flags +psnr for the same effect. ++ * -vf option is now an alias to the new -filter option, which uses stream specifiers. ++ * -vframes/-aframes/-dframes options are now aliases to the new -frames option. ++ * -vtag/-atag/-stag options are now aliases to the new -tag option. ++- XMV demuxer ++- LOAS demuxer ++- ashowinfo filter added ++- Windows Media Image decoder ++- amovie source added ++- LATM muxer/demuxer ++- Speex encoder via libspeex ++- JSON output in ffprobe ++- WTV muxer ++- Optional C++ Support (needed for libstagefright) ++- H.264 Decoding on Android via Stagefright ++- Prores decoder ++- BIN/XBIN/ADF/IDF text file decoder ++- aconvert audio filter added ++- audio support to lavfi input device added ++- libcdio-paranoia input device for audio CD grabbing ++- Apple ProRes decoder ++- CELT in Ogg demuxing ++- G.723.1 demuxer and decoder ++- libmodplug support (--enable-libmodplug) ++- VC-1 interlaced decoding ++- libutvideo wrapper (--enable-libutvideo) ++- aevalsrc audio source added ++- Ut Video decoder ++- Speex encoding via libspeex ++- 4:2:2 H.264 decoding support ++- 4:2:2 and 4:4:4 H.264 encoding with libx264 ++- Pulseaudio input device ++- Prores encoder ++- Video Decoder Acceleration (VDA) HWAccel module. ++- replacement Indeo 3 decoder ++- new ffmpeg option: -map_channel ++- volume audio filter added ++- earwax audio filter added ++- libv4l2 support (--enable-libv4l2) ++- TLS/SSL and HTTPS protocol support ++- AVOptions API rewritten and documented ++- most of CODEC_FLAG2_*, some CODEC_FLAG_* and many codec-specific fields in ++ AVCodecContext deprecated. Codec private options should be used instead. ++- Properly working defaults in libx264 wrapper, support for native presets. ++- Encrypted OMA files support ++- Discworld II BMV decoding support ++- VBLE Decoder ++- OS X Video Decoder Acceleration (VDA) support ++- compact and csv output in ffprobe ++- pan audio filter ++- IFF Amiga Continuous Bitmap (ACBM) decoder ++- ass filter ++- CRI ADX audio format muxer and demuxer ++- Playstation Portable PMP format demuxer ++- Microsoft Windows ICO demuxer ++- life source ++- PCM format support in OMA demuxer ++- CLJR encoder ++- new option: -report ++- Dxtory capture format decoder ++- cellauto source ++- Simple segmenting muxer ++- Indeo 4 decoder ++- SMJPEG demuxer + ++ ++version 0.8: ++ ++- many many things we forgot because we rather write code than changelogs + - WebM support in Matroska de/muxer + - low overhead Ogg muxing + - MMS-TCP support +@@ -11,6 +224,7 @@ + - Demuxer for On2's IVF format + - Pictor/PC Paint decoder + - HE-AAC v2 decoder ++- HE-AAC v2 encoding with libaacplus + - libfaad2 wrapper removed + - DTS-ES extension (XCh) decoding support + - native VP8 decoder +@@ -22,7 +236,7 @@ + - RTP depacketization of QDM2 + - ANSI/ASCII art playback system + - Lego Mindstorms RSO de/muxer +-- libavcore added ++- libavcore added (and subsequently removed) + - SubRip subtitle file muxer and demuxer + - Chinese AVS encoding via libxavs + - ffprobe -show_packets option added +@@ -52,10 +266,10 @@ + - demuxer for receiving raw rtp:// URLs without an SDP description + - single stream LATM/LOAS decoder + - setpts filter added +-- Win64 support for optimized asm functions ++- Win64 support for optimized x86 assembly functions + - MJPEG/AVI1 to JPEG/JFIF bitstream filter + - ASS subtitle encoder and decoder +-- IEC 61937 encapsulation for E-AC3 and TrueHD (for HDMI passthrough) ++- IEC 61937 encapsulation for E-AC-3, TrueHD, DTS-HD (for HDMI passthrough) + - overlay filter added + - rename aspect filter to setdar, and pixelaspect to setsar + - IEC 61937 demuxer +@@ -69,11 +283,59 @@ + - replace the ocv_smooth filter with a more generic ocv filter + - Windows Televison (WTV) demuxer + - FFmpeg metadata format muxer and demuxer +-- SubRip (srt) subtitle decoder ++- SubRip (srt) subtitle encoder and decoder + - floating-point AC-3 encoder added + - Lagarith decoder + - ffmpeg -copytb option added + - IVF muxer added ++- Wing Commander IV movies decoder added ++- movie source added ++- Bink version 'b' audio and video decoder ++- Bitmap Brothers JV playback system ++- Apple HTTP Live Streaming protocol handler ++- sndio support for playback and record ++- Linux framebuffer input device added ++- Chronomaster DFA decoder ++- DPX image encoder ++- MicroDVD subtitle file muxer and demuxer ++- Playstation Portable PMP format demuxer ++- fieldorder video filter added ++- AAC encoding via libvo-aacenc ++- AMR-WB encoding via libvo-amrwbenc ++- xWMA demuxer ++- Mobotix MxPEG decoder ++- VP8 frame-multithreading ++- NEON optimizations for VP8 ++- Lots of deprecated API cruft removed ++- fft and imdct optimizations for AVX (Sandy Bridge) processors ++- showinfo filter added ++- SMPTE 302M AES3 audio decoder ++- Apple Core Audio Format muxer ++- 9bit and 10bit per sample support in the H.264 decoder ++- 9bit and 10bit FFV1 encoding / decoding ++- split filter added ++- select filter added ++- sdl output device added ++- libmpcodecs video filter support (3 times as many filters than before) ++- mpeg2 aspect ratio dection fixed ++- libxvid aspect pickiness fixed ++- Frame multithreaded decoding ++- E-AC-3 audio encoder ++- ac3enc: add channel coupling support ++- floating-point sample format support to the ac3, eac3, dca, aac, and vorbis decoders. ++- H264/MPEG frame-level multi-threading ++- All av_metadata_* functions renamed to av_dict_* and moved to libavutil ++- 4:4:4 H.264 decoding support ++- 10-bit H.264 optimizations for x86 ++- lut, lutrgb, and lutyuv filters added ++- buffersink libavfilter sink added ++- Bump libswscale for recently reported ABI break ++- New J2K encoder (via OpenJPEG) ++ ++ ++version 0.7: ++ ++- all the changes for 0.8, but keeping API/ABI compatibility with the 0.6 release + + + version 0.6: +@@ -314,6 +576,7 @@ + - Gopher client support + - MXF D-10 muxer + - generic metadata API ++- flash ScreenVideo2 encoder + + + version 0.4.9-pre1: +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils.c 2012-05-14 14:08:53.108315308 +0200 +@@ -33,12 +33,17 @@ + #include "libavfilter/avfilter.h" + #include "libavdevice/avdevice.h" + #include "libswscale/swscale.h" ++#include "libswresample/swresample.h" ++#if CONFIG_POSTPROC + #include "libpostproc/postprocess.h" ++#endif + #include "libavutil/avstring.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/parseutils.h" + #include "libavutil/pixdesc.h" + #include "libavutil/eval.h" +-#include "libavcodec/opt.h" +-#include "libavcore/avcore.h" ++#include "libavutil/dict.h" ++#include "libavutil/opt.h" + #include "cmdutils.h" + #include "version.h" + #if CONFIG_NETWORK +@@ -48,78 +53,91 @@ + #include + #endif + +-const char **opt_names; +-const char **opt_values; +-static int opt_name_count; +-AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; +-AVFormatContext *avformat_opts; + struct SwsContext *sws_opts; ++AVDictionary *format_opts, *codec_opts; ++ ++const int this_year = 2012; + +-static const int this_year = 2011; ++static FILE *report_file; + + void init_opts(void) + { +- int i; +- for (i = 0; i < AVMEDIA_TYPE_NB; i++) +- avcodec_opts[i] = avcodec_alloc_context2(i); +- avformat_opts = avformat_alloc_context(); + #if CONFIG_SWSCALE +- sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL); ++ sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, ++ NULL, NULL, NULL); + #endif + } + + void uninit_opts(void) + { +- int i; +- for (i = 0; i < AVMEDIA_TYPE_NB; i++) +- av_freep(&avcodec_opts[i]); +- av_freep(&avformat_opts->key); +- av_freep(&avformat_opts); + #if CONFIG_SWSCALE +- av_freep(&sws_opts); ++ sws_freeContext(sws_opts); ++ sws_opts = NULL; + #endif ++ av_dict_free(&format_opts); ++ av_dict_free(&codec_opts); + } + +-void log_callback_help(void* ptr, int level, const char* fmt, va_list vl) ++void log_callback_help(void *ptr, int level, const char *fmt, va_list vl) + { + vfprintf(stdout, fmt, vl); + } + +-double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max) ++static void log_callback_report(void *ptr, int level, const char *fmt, va_list vl) ++{ ++ va_list vl2; ++ char line[1024]; ++ static int print_prefix = 1; ++ ++ va_copy(vl2, vl); ++ av_log_default_callback(ptr, level, fmt, vl); ++ av_log_format_line(ptr, level, fmt, vl2, line, sizeof(line), &print_prefix); ++ va_end(vl2); ++ fputs(line, report_file); ++ fflush(report_file); ++} ++ ++double parse_number_or_die(const char *context, const char *numstr, int type, ++ double min, double max) + { + char *tail; + const char *error; + double d = av_strtod(numstr, &tail); + if (*tail) +- error= "Expected number for %s but found: %s\n"; ++ error = "Expected number for %s but found: %s\n"; + else if (d < min || d > max) +- error= "The value for %s was %s which is not within %f - %f\n"; +- else if(type == OPT_INT64 && (int64_t)d != d) +- error= "Expected int64 for %s but found %s\n"; ++ error = "The value for %s was %s which is not within %f - %f\n"; ++ else if (type == OPT_INT64 && (int64_t)d != d) ++ error = "Expected int64 for %s but found %s\n"; ++ else if (type == OPT_INT && (int)d != d) ++ error = "Expected int for %s but found %s\n"; + else + return d; +- fprintf(stderr, error, context, numstr, min, max); +- exit(1); ++ av_log(NULL, AV_LOG_FATAL, error, context, numstr, min, max); ++ exit_program(1); ++ return 0; + } + +-int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration) ++int64_t parse_time_or_die(const char *context, const char *timestr, ++ int is_duration) + { +- int64_t us = parse_date(timestr, is_duration); +- if (us == INT64_MIN) { +- fprintf(stderr, "Invalid %s specification for %s: %s\n", +- is_duration ? "duration" : "date", context, timestr); +- exit(1); ++ int64_t us; ++ if (av_parse_time(&us, timestr, is_duration) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Invalid %s specification for %s: %s\n", ++ is_duration ? "duration" : "date", context, timestr); ++ exit_program(1); + } + return us; + } + +-void show_help_options(const OptionDef *options, const char *msg, int mask, int value) ++void show_help_options(const OptionDef *options, const char *msg, int mask, ++ int value) + { + const OptionDef *po; + int first; + + first = 1; +- for(po = options; po->name != NULL; po++) { ++ for (po = options; po->name != NULL; po++) { + char buf[64]; + if ((po->flags & mask) == value) { + if (first) { +@@ -136,21 +154,171 @@ + } + } + +-static const OptionDef* find_option(const OptionDef *po, const char *name){ ++void show_help_children(const AVClass *class, int flags) ++{ ++ const AVClass *child = NULL; ++ av_opt_show2(&class, NULL, flags, 0); ++ printf("\n"); ++ ++ while (child = av_opt_child_class_next(class, child)) ++ show_help_children(child, flags); ++} ++ ++static const OptionDef *find_option(const OptionDef *po, const char *name) ++{ ++ const char *p = strchr(name, ':'); ++ int len = p ? p - name : strlen(name); ++ + while (po->name != NULL) { +- if (!strcmp(name, po->name)) ++ if (!strncmp(name, po->name, len) && strlen(po->name) == len) + break; + po++; + } + return po; + } + +-void parse_options(int argc, char **argv, const OptionDef *options, +- void (* parse_arg_function)(const char*)) ++#if defined(_WIN32) && !defined(__MINGW32CE__) ++#include ++/* Will be leaked on exit */ ++static char** win32_argv_utf8 = NULL; ++static int win32_argc = 0; ++ ++/** ++ * Prepare command line arguments for executable. ++ * For Windows - perform wide-char to UTF-8 conversion. ++ * Input arguments should be main() function arguments. ++ * @param argc_ptr Arguments number (including executable) ++ * @param argv_ptr Arguments list. ++ */ ++static void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) ++{ ++ char *argstr_flat; ++ wchar_t **argv_w; ++ int i, buffsize = 0, offset = 0; ++ ++ if (win32_argv_utf8) { ++ *argc_ptr = win32_argc; ++ *argv_ptr = win32_argv_utf8; ++ return; ++ } ++ ++ win32_argc = 0; ++ argv_w = CommandLineToArgvW(GetCommandLineW(), &win32_argc); ++ if (win32_argc <= 0 || !argv_w) ++ return; ++ ++ /* determine the UTF-8 buffer size (including NULL-termination symbols) */ ++ for (i = 0; i < win32_argc; i++) ++ buffsize += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, ++ NULL, 0, NULL, NULL); ++ ++ win32_argv_utf8 = av_mallocz(sizeof(char *) * (win32_argc + 1) + buffsize); ++ argstr_flat = (char *)win32_argv_utf8 + sizeof(char *) * (win32_argc + 1); ++ if (win32_argv_utf8 == NULL) { ++ LocalFree(argv_w); ++ return; ++ } ++ ++ for (i = 0; i < win32_argc; i++) { ++ win32_argv_utf8[i] = &argstr_flat[offset]; ++ offset += WideCharToMultiByte(CP_UTF8, 0, argv_w[i], -1, ++ &argstr_flat[offset], ++ buffsize - offset, NULL, NULL); ++ } ++ win32_argv_utf8[i] = NULL; ++ LocalFree(argv_w); ++ ++ *argc_ptr = win32_argc; ++ *argv_ptr = win32_argv_utf8; ++} ++#else ++static inline void prepare_app_arguments(int *argc_ptr, char ***argv_ptr) ++{ ++ /* nothing to do */ ++} ++#endif /* WIN32 && !__MINGW32CE__ */ ++ ++int parse_option(void *optctx, const char *opt, const char *arg, ++ const OptionDef *options) + { +- const char *opt, *arg; +- int optindex, handleoptions=1; + const OptionDef *po; ++ int bool_val = 1; ++ int *dstcount; ++ void *dst; ++ ++ po = find_option(options, opt); ++ if (!po->name && opt[0] == 'n' && opt[1] == 'o') { ++ /* handle 'no' bool option */ ++ po = find_option(options, opt + 2); ++ if (!(po->name && (po->flags & OPT_BOOL))) ++ goto unknown_opt; ++ bool_val = 0; ++ } ++ if (!po->name) ++ po = find_option(options, "default"); ++ if (!po->name) { ++unknown_opt: ++ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); ++ return AVERROR(EINVAL); ++ } ++ if (po->flags & HAS_ARG && !arg) { ++ av_log(NULL, AV_LOG_ERROR, "Missing argument for option '%s'\n", opt); ++ return AVERROR(EINVAL); ++ } ++ ++ /* new-style options contain an offset into optctx, old-style address of ++ * a global var*/ ++ dst = po->flags & (OPT_OFFSET | OPT_SPEC) ? (uint8_t *)optctx + po->u.off ++ : po->u.dst_ptr; ++ ++ if (po->flags & OPT_SPEC) { ++ SpecifierOpt **so = dst; ++ char *p = strchr(opt, ':'); ++ ++ dstcount = (int *)(so + 1); ++ *so = grow_array(*so, sizeof(**so), dstcount, *dstcount + 1); ++ (*so)[*dstcount - 1].specifier = av_strdup(p ? p + 1 : ""); ++ dst = &(*so)[*dstcount - 1].u; ++ } ++ ++ if (po->flags & OPT_STRING) { ++ char *str; ++ str = av_strdup(arg); ++ *(char **)dst = str; ++ } else if (po->flags & OPT_BOOL) { ++ *(int *)dst = bool_val; ++ } else if (po->flags & OPT_INT) { ++ *(int *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); ++ } else if (po->flags & OPT_INT64) { ++ *(int64_t *)dst = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); ++ } else if (po->flags & OPT_TIME) { ++ *(int64_t *)dst = parse_time_or_die(opt, arg, 1); ++ } else if (po->flags & OPT_FLOAT) { ++ *(float *)dst = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); ++ } else if (po->flags & OPT_DOUBLE) { ++ *(double *)dst = parse_number_or_die(opt, arg, OPT_DOUBLE, -INFINITY, INFINITY); ++ } else if (po->u.func_arg) { ++ int ret = po->flags & OPT_FUNC2 ? po->u.func2_arg(optctx, opt, arg) ++ : po->u.func_arg(opt, arg); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Failed to set value '%s' for option '%s'\n", arg, opt); ++ return ret; ++ } ++ } ++ if (po->flags & OPT_EXIT) ++ exit_program(0); ++ return !!(po->flags & HAS_ARG); ++} ++ ++void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, ++ void (*parse_arg_function)(void *, const char*)) ++{ ++ const char *opt; ++ int optindex, handleoptions = 1, ret; ++ ++ /* perform system-dependent conversions for arguments list */ ++ prepare_app_arguments(&argc, &argv); + + /* parse options */ + optindex = 1; +@@ -158,123 +326,134 @@ + opt = argv[optindex++]; + + if (handleoptions && opt[0] == '-' && opt[1] != '\0') { +- int bool_val = 1; + if (opt[1] == '-' && opt[2] == '\0') { + handleoptions = 0; + continue; + } + opt++; +- po= find_option(options, opt); +- if (!po->name && opt[0] == 'n' && opt[1] == 'o') { +- /* handle 'no' bool option */ +- po = find_option(options, opt + 2); +- if (!(po->name && (po->flags & OPT_BOOL))) +- goto unknown_opt; +- bool_val = 0; +- } +- if (!po->name) +- po= find_option(options, "default"); +- if (!po->name) { +-unknown_opt: +- fprintf(stderr, "%s: unrecognized option '%s'\n", argv[0], opt); +- exit(1); +- } +- arg = NULL; +- if (po->flags & HAS_ARG) { +- arg = argv[optindex++]; +- if (!arg) { +- fprintf(stderr, "%s: missing argument for option '%s'\n", argv[0], opt); +- exit(1); +- } +- } +- if (po->flags & OPT_STRING) { +- char *str; +- str = av_strdup(arg); +- *po->u.str_arg = str; +- } else if (po->flags & OPT_BOOL) { +- *po->u.int_arg = bool_val; +- } else if (po->flags & OPT_INT) { +- *po->u.int_arg = parse_number_or_die(opt, arg, OPT_INT64, INT_MIN, INT_MAX); +- } else if (po->flags & OPT_INT64) { +- *po->u.int64_arg = parse_number_or_die(opt, arg, OPT_INT64, INT64_MIN, INT64_MAX); +- } else if (po->flags & OPT_FLOAT) { +- *po->u.float_arg = parse_number_or_die(opt, arg, OPT_FLOAT, -INFINITY, INFINITY); +- } else if (po->flags & OPT_FUNC2) { +- if (po->u.func2_arg(opt, arg) < 0) { +- fprintf(stderr, "%s: failed to set value '%s' for option '%s'\n", argv[0], arg, opt); +- exit(1); +- } +- } else { +- po->u.func_arg(arg); +- } +- if(po->flags & OPT_EXIT) +- exit(0); ++ ++ if ((ret = parse_option(optctx, opt, argv[optindex], options)) < 0) ++ exit_program(1); ++ optindex += ret; + } else { + if (parse_arg_function) +- parse_arg_function(opt); ++ parse_arg_function(optctx, opt); + } + } + } + +-int opt_default(const char *opt, const char *arg){ +- int type; +- int ret= 0; +- const AVOption *o= NULL; +- int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0}; +- +- for(type=0; *avcodec_opts && type= 0; type++){ +- const AVOption *o2 = av_find_opt(avcodec_opts[0], opt, NULL, opt_types[type], opt_types[type]); +- if(o2) +- ret = av_set_string3(avcodec_opts[type], opt, arg, 1, &o); +- } +- if(!o && avformat_opts) +- ret = av_set_string3(avformat_opts, opt, arg, 1, &o); +- if(!o && sws_opts) +- ret = av_set_string3(sws_opts, opt, arg, 1, &o); +- if(!o){ +- if (opt[0] == 'a' && avcodec_opts[AVMEDIA_TYPE_AUDIO]) +- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_AUDIO], opt+1, arg, 1, &o); +- else if(opt[0] == 'v' && avcodec_opts[AVMEDIA_TYPE_VIDEO]) +- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_VIDEO], opt+1, arg, 1, &o); +- else if(opt[0] == 's' && avcodec_opts[AVMEDIA_TYPE_SUBTITLE]) +- ret = av_set_string3(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], opt+1, arg, 1, &o); +- } +- if (o && ret < 0) { +- fprintf(stderr, "Invalid value '%s' for option '%s'\n", arg, opt); +- exit(1); +- } +- if (!o) { +- AVCodec *p = NULL; +- AVOutputFormat *oformat = NULL; +- while ((p=av_codec_next(p))){ +- AVClass *c= p->priv_class; +- if(c && av_find_opt(&c, opt, NULL, 0, 0)) +- break; +- } +- if (!p) { +- while ((oformat = av_oformat_next(oformat))) { +- const AVClass *c = oformat->priv_class; +- if (c && av_find_opt(&c, opt, NULL, 0, 0)) +- break; ++/* ++ * Return index of option opt in argv or 0 if not found. ++ */ ++static int locate_option(int argc, char **argv, const OptionDef *options, ++ const char *optname) ++{ ++ const OptionDef *po; ++ int i; ++ ++ for (i = 1; i < argc; i++) { ++ const char *cur_opt = argv[i]; ++ ++ if (*cur_opt++ != '-') ++ continue; ++ ++ po = find_option(options, cur_opt); ++ if (!po->name && cur_opt[0] == 'n' && cur_opt[1] == 'o') ++ po = find_option(options, cur_opt + 2); ++ ++ if ((!po->name && !strcmp(cur_opt, optname)) || ++ (po->name && !strcmp(optname, po->name))) ++ return i; ++ ++ if (!po || po->flags & HAS_ARG) ++ i++; ++ } ++ return 0; ++} ++ ++static void dump_argument(const char *a) ++{ ++ const unsigned char *p; ++ ++ for (p = a; *p; p++) ++ if (!((*p >= '+' && *p <= ':') || (*p >= '@' && *p <= 'Z') || ++ *p == '_' || (*p >= 'a' && *p <= 'z'))) ++ break; ++ if (!*p) { ++ fputs(a, report_file); ++ return; ++ } ++ fputc('"', report_file); ++ for (p = a; *p; p++) { ++ if (*p == '\\' || *p == '"' || *p == '$' || *p == '`') ++ fprintf(report_file, "\\%c", *p); ++ else if (*p < ' ' || *p > '~') ++ fprintf(report_file, "\\x%02x", *p); ++ else ++ fputc(*p, report_file); ++ } ++ fputc('"', report_file); ++} ++ ++void parse_loglevel(int argc, char **argv, const OptionDef *options) ++{ ++ int idx = locate_option(argc, argv, options, "loglevel"); ++ if (!idx) ++ idx = locate_option(argc, argv, options, "v"); ++ if (idx && argv[idx + 1]) ++ opt_loglevel("loglevel", argv[idx + 1]); ++ idx = locate_option(argc, argv, options, "report"); ++ if (idx || getenv("FFREPORT")) { ++ opt_report("report"); ++ if (report_file) { ++ int i; ++ fprintf(report_file, "Command line:\n"); ++ for (i = 0; i < argc; i++) { ++ dump_argument(argv[i]); ++ fputc(i < argc - 1 ? ' ' : '\n', report_file); + } +- } +- if(!p && !oformat){ +- fprintf(stderr, "Unrecognized option '%s'\n", opt); +- exit(1); ++ fflush(report_file); + } + } ++} + +-// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL)); +- +- //FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this +- opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1)); +- opt_values[opt_name_count]= o ? NULL : arg; +- opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1)); +- opt_names[opt_name_count++]= o ? o->name : opt; ++#define FLAGS(o) ((o)->type == AV_OPT_TYPE_FLAGS) ? AV_DICT_APPEND : 0 ++int opt_default(const char *opt, const char *arg) ++{ ++ const AVOption *oc, *of, *os; ++ char opt_stripped[128]; ++ const char *p; ++ const AVClass *cc = avcodec_get_class(), *fc = avformat_get_class(), *sc; ++ ++ if (!(p = strchr(opt, ':'))) ++ p = opt + strlen(opt); ++ av_strlcpy(opt_stripped, opt, FFMIN(sizeof(opt_stripped), p - opt + 1)); ++ ++ if ((oc = av_opt_find(&cc, opt_stripped, NULL, 0, ++ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ)) || ++ ((opt[0] == 'v' || opt[0] == 'a' || opt[0] == 's') && ++ (oc = av_opt_find(&cc, opt + 1, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ)))) ++ av_dict_set(&codec_opts, opt, arg, FLAGS(oc)); ++ if ((of = av_opt_find(&fc, opt, NULL, 0, ++ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) ++ av_dict_set(&format_opts, opt, arg, FLAGS(of)); ++#if CONFIG_SWSCALE ++ sc = sws_get_class(); ++ if ((os = av_opt_find(&sc, opt, NULL, 0, ++ AV_OPT_SEARCH_CHILDREN | AV_OPT_SEARCH_FAKE_OBJ))) { ++ // XXX we only support sws_flags, not arbitrary sws options ++ int ret = av_opt_set(sws_opts, opt, arg, 0); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Error setting option %s.\n", opt); ++ return ret; ++ } ++ } ++#endif + +- if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug)) +- av_log_set_level(AV_LOG_DEBUG); +- return 0; ++ if (oc || of || os) ++ return 0; ++ av_log(NULL, AV_LOG_ERROR, "Unrecognized option '%s'\n", opt); ++ return AVERROR_OPTION_NOT_FOUND; + } + + int opt_loglevel(const char *opt, const char *arg) +@@ -302,16 +481,68 @@ + + level = strtol(arg, &tail, 10); + if (*tail) { +- fprintf(stderr, "Invalid loglevel \"%s\". " +- "Possible levels are numbers or:\n", arg); ++ av_log(NULL, AV_LOG_FATAL, "Invalid loglevel \"%s\". " ++ "Possible levels are numbers or:\n", arg); + for (i = 0; i < FF_ARRAY_ELEMS(log_levels); i++) +- fprintf(stderr, "\"%s\"\n", log_levels[i].name); +- exit(1); ++ av_log(NULL, AV_LOG_FATAL, "\"%s\"\n", log_levels[i].name); ++ exit_program(1); + } + av_log_set_level(level); + return 0; + } + ++int opt_report(const char *opt) ++{ ++ char filename[64]; ++ time_t now; ++ struct tm *tm; ++ ++ if (report_file) /* already opened */ ++ return 0; ++ time(&now); ++ tm = localtime(&now); ++ snprintf(filename, sizeof(filename), "%s-%04d%02d%02d-%02d%02d%02d.log", ++ program_name, ++ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, ++ tm->tm_hour, tm->tm_min, tm->tm_sec); ++ report_file = fopen(filename, "w"); ++ if (!report_file) { ++ av_log(NULL, AV_LOG_ERROR, "Failed to open report \"%s\": %s\n", ++ filename, strerror(errno)); ++ return AVERROR(errno); ++ } ++ av_log_set_callback(log_callback_report); ++ av_log(NULL, AV_LOG_INFO, ++ "%s started on %04d-%02d-%02d at %02d:%02d:%02d\n" ++ "Report written to \"%s\"\n", ++ program_name, ++ tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, ++ tm->tm_hour, tm->tm_min, tm->tm_sec, ++ filename); ++ av_log_set_level(FFMAX(av_log_get_level(), AV_LOG_VERBOSE)); ++ return 0; ++} ++ ++int opt_max_alloc(const char *opt, const char *arg) ++{ ++ char *tail; ++ size_t max; ++ ++ max = strtol(arg, &tail, 10); ++ if (*tail) { ++ av_log(NULL, AV_LOG_FATAL, "Invalid max_alloc \"%s\".\n", arg); ++ exit_program(1); ++ } ++ av_max_alloc(max); ++ return 0; ++} ++ ++int opt_codec_debug(const char *opt, const char *arg) ++{ ++ av_log_set_level(AV_LOG_DEBUG); ++ return opt_default(opt, arg); ++} ++ + int opt_timelimit(const char *opt, const char *arg) + { + #if HAVE_SETRLIMIT +@@ -320,43 +551,11 @@ + if (setrlimit(RLIMIT_CPU, &rl)) + perror("setrlimit"); + #else +- fprintf(stderr, "Warning: -%s not implemented on this OS\n", opt); ++ av_log(NULL, AV_LOG_WARNING, "-%s not implemented on this OS\n", opt); + #endif + return 0; + } + +-void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec) +-{ +- int i; +- void *priv_ctx=NULL; +- if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){ +- AVCodecContext *avctx= ctx; +- if(codec && codec->priv_class && avctx->priv_data){ +- priv_ctx= avctx->priv_data; +- } +- } else if (!strcmp("AVFormatContext", (*(AVClass**)ctx)->class_name)) { +- AVFormatContext *avctx = ctx; +- if (avctx->oformat && avctx->oformat->priv_class) { +- priv_ctx = avctx->priv_data; +- } +- } +- +- for(i=0; iflags & flags) == flags)) +- av_set_string3(ctx, opt_names[i], str, 1, NULL); +- /* We need to use a differnt system to pass options to the private context because +- it is not known which codec and thus context kind that will be when parsing options +- we thus use opt_values directly instead of opts_ctx */ +- if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){ +- av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL); +- } +- } +-} +- + void print_error(const char *filename, int err) + { + char errbuf[128]; +@@ -364,7 +563,7 @@ + + if (av_strerror(err, errbuf, sizeof(errbuf)) < 0) + errbuf_ptr = strerror(AVUNERROR(err)); +- fprintf(stderr, "%s: %s\n", filename, errbuf_ptr); ++ av_log(NULL, AV_LOG_ERROR, "%s: %s\n", filename, errbuf_ptr); + } + + static int warned_cfg = 0; +@@ -372,63 +571,82 @@ + #define INDENT 1 + #define SHOW_VERSION 2 + #define SHOW_CONFIG 4 ++#define SHOW_COPYRIGHT 8 + +-#define PRINT_LIB_INFO(outstream,libname,LIBNAME,flags) \ ++#define PRINT_LIB_INFO(libname, LIBNAME, flags, level) \ + if (CONFIG_##LIBNAME) { \ + const char *indent = flags & INDENT? " " : ""; \ + if (flags & SHOW_VERSION) { \ + unsigned int version = libname##_version(); \ +- fprintf(outstream, "%slib%-9s %2d.%3d.%2d / %2d.%3d.%2d\n", \ +- indent, #libname, \ +- LIB##LIBNAME##_VERSION_MAJOR, \ +- LIB##LIBNAME##_VERSION_MINOR, \ +- LIB##LIBNAME##_VERSION_MICRO, \ +- version >> 16, version >> 8 & 0xff, version & 0xff); \ ++ av_log(NULL, level, "%slib%-11s %2d.%3d.%3d / %2d.%3d.%3d\n",\ ++ indent, #libname, \ ++ LIB##LIBNAME##_VERSION_MAJOR, \ ++ LIB##LIBNAME##_VERSION_MINOR, \ ++ LIB##LIBNAME##_VERSION_MICRO, \ ++ version >> 16, version >> 8 & 0xff, version & 0xff); \ + } \ + if (flags & SHOW_CONFIG) { \ + const char *cfg = libname##_configuration(); \ + if (strcmp(FFMPEG_CONFIGURATION, cfg)) { \ + if (!warned_cfg) { \ +- fprintf(outstream, \ ++ av_log(NULL, level, \ + "%sWARNING: library configuration mismatch\n", \ + indent); \ + warned_cfg = 1; \ + } \ +- fprintf(stderr, "%s%-11s configuration: %s\n", \ ++ av_log(NULL, level, "%s%-11s configuration: %s\n", \ + indent, #libname, cfg); \ + } \ + } \ + } \ + +-static void print_all_libs_info(FILE* outstream, int flags) ++static void print_all_libs_info(int flags, int level) + { +- PRINT_LIB_INFO(outstream, avutil, AVUTIL, flags); +- PRINT_LIB_INFO(outstream, avcore, AVCORE, flags); +- PRINT_LIB_INFO(outstream, avcodec, AVCODEC, flags); +- PRINT_LIB_INFO(outstream, avformat, AVFORMAT, flags); +- PRINT_LIB_INFO(outstream, avdevice, AVDEVICE, flags); +- PRINT_LIB_INFO(outstream, avfilter, AVFILTER, flags); +- PRINT_LIB_INFO(outstream, swscale, SWSCALE, flags); +- PRINT_LIB_INFO(outstream, postproc, POSTPROC, flags); ++ PRINT_LIB_INFO(avutil, AVUTIL, flags, level); ++ PRINT_LIB_INFO(avcodec, AVCODEC, flags, level); ++ PRINT_LIB_INFO(avformat, AVFORMAT, flags, level); ++ PRINT_LIB_INFO(avdevice, AVDEVICE, flags, level); ++ PRINT_LIB_INFO(avfilter, AVFILTER, flags, level); ++ PRINT_LIB_INFO(swscale, SWSCALE, flags, level); ++ PRINT_LIB_INFO(swresample,SWRESAMPLE, flags, level); ++#if CONFIG_POSTPROC ++ PRINT_LIB_INFO(postproc, POSTPROC, flags, level); ++#endif + } + +-void show_banner(void) ++static void print_program_info(int flags, int level) + { +- fprintf(stderr, "%s version " FFMPEG_VERSION ", Copyright (c) %d-%d the FFmpeg developers\n", +- program_name, program_birth_year, this_year); +- fprintf(stderr, " built on %s %s with %s %s\n", +- __DATE__, __TIME__, CC_TYPE, CC_VERSION); +- fprintf(stderr, " configuration: " FFMPEG_CONFIGURATION "\n"); +- print_all_libs_info(stderr, INDENT|SHOW_CONFIG); +- print_all_libs_info(stderr, INDENT|SHOW_VERSION); ++ const char *indent = flags & INDENT? " " : ""; ++ ++ av_log(NULL, level, "%s version " FFMPEG_VERSION, program_name); ++ if (flags & SHOW_COPYRIGHT) ++ av_log(NULL, level, " Copyright (c) %d-%d the FFmpeg developers", ++ program_birth_year, this_year); ++ av_log(NULL, level, "\n"); ++ av_log(NULL, level, "%sbuilt on %s %s with %s %s\n", ++ indent, __DATE__, __TIME__, CC_TYPE, CC_VERSION); ++ av_log(NULL, level, "%sconfiguration: " FFMPEG_CONFIGURATION "\n", indent); + } + +-void show_version(void) { +- printf("%s " FFMPEG_VERSION "\n", program_name); +- print_all_libs_info(stdout, SHOW_VERSION); ++void show_banner(int argc, char **argv, const OptionDef *options) ++{ ++ int idx = locate_option(argc, argv, options, "version"); ++ if (idx) ++ return; ++ ++ print_program_info (INDENT|SHOW_COPYRIGHT, AV_LOG_INFO); ++ print_all_libs_info(INDENT|SHOW_CONFIG, AV_LOG_INFO); ++ print_all_libs_info(INDENT|SHOW_VERSION, AV_LOG_INFO); ++} ++ ++int opt_version(const char *opt, const char *arg) { ++ av_log_set_callback(log_callback_help); ++ print_program_info (0 , AV_LOG_INFO); ++ print_all_libs_info(SHOW_VERSION, AV_LOG_INFO); ++ return 0; + } + +-void show_license(void) ++int opt_license(const char *opt, const char *arg) + { + printf( + #if CONFIG_NONFREE +@@ -495,154 +713,144 @@ + program_name, program_name, program_name + #endif + ); ++ return 0; + } + +-void list_fmts(void (*get_fmt_string)(char *buf, int buf_size, int fmt), int nb_fmts) +-{ +- int i; +- char fmt_str[128]; +- for (i=-1; i < nb_fmts; i++) { +- get_fmt_string (fmt_str, sizeof(fmt_str), i); +- fprintf(stdout, "%s\n", fmt_str); +- } +-} +- +-void show_formats(void) ++int opt_formats(const char *opt, const char *arg) + { +- AVInputFormat *ifmt=NULL; +- AVOutputFormat *ofmt=NULL; ++ AVInputFormat *ifmt = NULL; ++ AVOutputFormat *ofmt = NULL; + const char *last_name; + +- printf( +- "File formats:\n" +- " D. = Demuxing supported\n" +- " .E = Muxing supported\n" +- " --\n"); +- last_name= "000"; +- for(;;){ +- int decode=0; +- int encode=0; +- const char *name=NULL; +- const char *long_name=NULL; +- +- while((ofmt= av_oformat_next(ofmt))) { +- if((name == NULL || strcmp(ofmt->name, name)<0) && +- strcmp(ofmt->name, last_name)>0){ +- name= ofmt->name; +- long_name= ofmt->long_name; +- encode=1; +- } +- } +- while((ifmt= av_iformat_next(ifmt))) { +- if((name == NULL || strcmp(ifmt->name, name)<0) && +- strcmp(ifmt->name, last_name)>0){ +- name= ifmt->name; +- long_name= ifmt->long_name; +- encode=0; ++ printf("File formats:\n" ++ " D. = Demuxing supported\n" ++ " .E = Muxing supported\n" ++ " --\n"); ++ last_name = "000"; ++ for (;;) { ++ int decode = 0; ++ int encode = 0; ++ const char *name = NULL; ++ const char *long_name = NULL; ++ ++ while ((ofmt = av_oformat_next(ofmt))) { ++ if ((name == NULL || strcmp(ofmt->name, name) < 0) && ++ strcmp(ofmt->name, last_name) > 0) { ++ name = ofmt->name; ++ long_name = ofmt->long_name; ++ encode = 1; ++ } ++ } ++ while ((ifmt = av_iformat_next(ifmt))) { ++ if ((name == NULL || strcmp(ifmt->name, name) < 0) && ++ strcmp(ifmt->name, last_name) > 0) { ++ name = ifmt->name; ++ long_name = ifmt->long_name; ++ encode = 0; + } +- if(name && strcmp(ifmt->name, name)==0) +- decode=1; ++ if (name && strcmp(ifmt->name, name) == 0) ++ decode = 1; + } +- if(name==NULL) ++ if (name == NULL) + break; +- last_name= name; ++ last_name = name; + +- printf( +- " %s%s %-15s %s\n", +- decode ? "D":" ", +- encode ? "E":" ", +- name, ++ printf(" %s%s %-15s %s\n", ++ decode ? "D" : " ", ++ encode ? "E" : " ", ++ name, + long_name ? long_name:" "); + } ++ return 0; + } + +-void show_codecs(void) ++static char get_media_type_char(enum AVMediaType type) + { +- AVCodec *p=NULL, *p2; ++ static const char map[AVMEDIA_TYPE_NB] = { ++ [AVMEDIA_TYPE_VIDEO] = 'V', ++ [AVMEDIA_TYPE_AUDIO] = 'A', ++ [AVMEDIA_TYPE_DATA] = 'D', ++ [AVMEDIA_TYPE_SUBTITLE] = 'S', ++ [AVMEDIA_TYPE_ATTACHMENT] = 'T', ++ }; ++ return type >= 0 && type < AVMEDIA_TYPE_NB && map[type] ? map[type] : '?'; ++} ++ ++int opt_codecs(const char *opt, const char *arg) ++{ ++ AVCodec *p = NULL, *p2; + const char *last_name; +- printf( +- "Codecs:\n" +- " D..... = Decoding supported\n" +- " .E.... = Encoding supported\n" +- " ..V... = Video codec\n" +- " ..A... = Audio codec\n" +- " ..S... = Subtitle codec\n" +- " ...S.. = Supports draw_horiz_band\n" +- " ....D. = Supports direct rendering method 1\n" +- " .....T = Supports weird frame truncation\n" +- " ------\n"); ++ printf("Codecs:\n" ++ " D..... = Decoding supported\n" ++ " .E.... = Encoding supported\n" ++ " ..V... = Video codec\n" ++ " ..A... = Audio codec\n" ++ " ..S... = Subtitle codec\n" ++ " ...S.. = Supports draw_horiz_band\n" ++ " ....D. = Supports direct rendering method 1\n" ++ " .....T = Supports weird frame truncation\n" ++ " ------\n"); + last_name= "000"; +- for(;;){ +- int decode=0; +- int encode=0; +- int cap=0; +- const char *type_str; +- +- p2=NULL; +- while((p= av_codec_next(p))) { +- if((p2==NULL || strcmp(p->name, p2->name)<0) && +- strcmp(p->name, last_name)>0){ +- p2= p; +- decode= encode= cap=0; +- } +- if(p2 && strcmp(p->name, p2->name)==0){ +- if(p->decode) decode=1; +- if(p->encode) encode=1; ++ for (;;) { ++ int decode = 0; ++ int encode = 0; ++ int cap = 0; ++ ++ p2 = NULL; ++ while ((p = av_codec_next(p))) { ++ if ((p2 == NULL || strcmp(p->name, p2->name) < 0) && ++ strcmp(p->name, last_name) > 0) { ++ p2 = p; ++ decode = encode = cap = 0; ++ } ++ if (p2 && strcmp(p->name, p2->name) == 0) { ++ if (p->decode) ++ decode = 1; ++ if (p->encode || p->encode2) ++ encode = 1; + cap |= p->capabilities; + } + } +- if(p2==NULL) ++ if (p2 == NULL) + break; +- last_name= p2->name; ++ last_name = p2->name; + +- switch(p2->type) { +- case AVMEDIA_TYPE_VIDEO: +- type_str = "V"; +- break; +- case AVMEDIA_TYPE_AUDIO: +- type_str = "A"; +- break; +- case AVMEDIA_TYPE_SUBTITLE: +- type_str = "S"; +- break; +- default: +- type_str = "?"; +- break; +- } +- printf( +- " %s%s%s%s%s%s %-15s %s", +- decode ? "D": (/*p2->decoder ? "d":*/" "), +- encode ? "E":" ", +- type_str, +- cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S":" ", +- cap & CODEC_CAP_DR1 ? "D":" ", +- cap & CODEC_CAP_TRUNCATED ? "T":" ", +- p2->name, +- p2->long_name ? p2->long_name : ""); +- /* if(p2->decoder && decode==0) +- printf(" use %s for decoding", p2->decoder->name);*/ ++ printf(" %s%s%c%s%s%s %-15s %s", ++ decode ? "D" : (/* p2->decoder ? "d" : */ " "), ++ encode ? "E" : " ", ++ get_media_type_char(p2->type), ++ cap & CODEC_CAP_DRAW_HORIZ_BAND ? "S" : " ", ++ cap & CODEC_CAP_DR1 ? "D" : " ", ++ cap & CODEC_CAP_TRUNCATED ? "T" : " ", ++ p2->name, ++ p2->long_name ? p2->long_name : ""); ++#if 0 ++ if (p2->decoder && decode == 0) ++ printf(" use %s for decoding", p2->decoder->name); ++#endif + printf("\n"); + } + printf("\n"); +- printf( +-"Note, the names of encoders and decoders do not always match, so there are\n" +-"several cases where the above table shows encoder only or decoder only entries\n" +-"even though both encoding and decoding are supported. For example, the h263\n" +-"decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" +-"worse.\n"); ++ printf("Note, the names of encoders and decoders do not always match, so there are\n" ++ "several cases where the above table shows encoder only or decoder only entries\n" ++ "even though both encoding and decoding are supported. For example, the h263\n" ++ "decoder corresponds to the h263 and h263p encoders, for file formats it is even\n" ++ "worse.\n"); ++ return 0; + } + +-void show_bsfs(void) ++int opt_bsfs(const char *opt, const char *arg) + { +- AVBitStreamFilter *bsf=NULL; ++ AVBitStreamFilter *bsf = NULL; + + printf("Bitstream filters:\n"); +- while((bsf = av_bitstream_filter_next(bsf))) ++ while ((bsf = av_bitstream_filter_next(bsf))) + printf("%s\n", bsf->name); + printf("\n"); ++ return 0; + } + +-void show_protocols(void) ++int opt_protocols(const char *opt, const char *arg) + { + URLProtocol *up=NULL; + +@@ -658,32 +866,53 @@ + up->url_write ? 'O' : '.', + up->url_seek ? 'S' : '.', + up->name); ++ return 0; + } + +-void show_filters(void) ++int opt_filters(const char *opt, const char *arg) + { + AVFilter av_unused(**filter) = NULL; ++ char descr[64], *descr_cur; ++ int i, j; ++ const AVFilterPad *pad; + + printf("Filters:\n"); + #if CONFIG_AVFILTER +- while ((filter = av_filter_next(filter)) && *filter) +- printf("%-16s %s\n", (*filter)->name, (*filter)->description); ++ while ((filter = av_filter_next(filter)) && *filter) { ++ descr_cur = descr; ++ for (i = 0; i < 2; i++) { ++ if (i) { ++ *(descr_cur++) = '-'; ++ *(descr_cur++) = '>'; ++ } ++ pad = i ? (*filter)->outputs : (*filter)->inputs; ++ for (j = 0; pad[j].name; j++) { ++ if (descr_cur >= descr + sizeof(descr) - 4) ++ break; ++ *(descr_cur++) = get_media_type_char(pad[j].type); ++ } ++ if (!j) ++ *(descr_cur++) = '|'; ++ } ++ *descr_cur = 0; ++ printf("%-16s %-10s %s\n", (*filter)->name, descr, (*filter)->description); ++ } + #endif ++ return 0; + } + +-void show_pix_fmts(void) ++int opt_pix_fmts(const char *opt, const char *arg) + { + enum PixelFormat pix_fmt; + +- printf( +- "Pixel formats:\n" +- "I.... = Supported Input format for conversion\n" +- ".O... = Supported Output format for conversion\n" +- "..H.. = Hardware accelerated format\n" +- "...P. = Paletted format\n" +- "....B = Bitstream format\n" +- "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n" +- "-----\n"); ++ printf("Pixel formats:\n" ++ "I.... = Supported Input format for conversion\n" ++ ".O... = Supported Output format for conversion\n" ++ "..H.. = Hardware accelerated format\n" ++ "...P. = Paletted format\n" ++ "....B = Bitstream format\n" ++ "FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL\n" ++ "-----\n"); + + #if !CONFIG_SWSCALE + # define sws_isSupportedInput(x) 0 +@@ -692,6 +921,8 @@ + + for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) { + const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; ++ if(!pix_desc->name) ++ continue; + printf("%c%c%c%c%c %-16s %d %2d\n", + sws_isSupportedInput (pix_fmt) ? 'I' : '.', + sws_isSupportedOutput(pix_fmt) ? 'O' : '.', +@@ -702,6 +933,16 @@ + pix_desc->nb_components, + av_get_bits_per_pixel(pix_desc)); + } ++ return 0; ++} ++ ++int show_sample_fmts(const char *opt, const char *arg) ++{ ++ int i; ++ char fmt_str[128]; ++ for (i = -1; i < AV_SAMPLE_FMT_NB; i++) ++ printf("%s\n", av_get_sample_fmt_string(fmt_str, sizeof(fmt_str), i)); ++ return 0; + } + + int read_yesno(void) +@@ -715,12 +956,14 @@ + return yesno; + } + +-int read_file(const char *filename, char **bufptr, size_t *size) ++int cmdutils_read_file(const char *filename, char **bufptr, size_t *size) + { ++ int ret; + FILE *f = fopen(filename, "rb"); + + if (!f) { +- fprintf(stderr, "Cannot read file '%s': %s\n", filename, strerror(errno)); ++ av_log(NULL, AV_LOG_ERROR, "Cannot read file '%s': %s\n", filename, ++ strerror(errno)); + return AVERROR(errno); + } + fseek(f, 0, SEEK_END); +@@ -728,66 +971,70 @@ + fseek(f, 0, SEEK_SET); + *bufptr = av_malloc(*size + 1); + if (!*bufptr) { +- fprintf(stderr, "Could not allocate file buffer\n"); ++ av_log(NULL, AV_LOG_ERROR, "Could not allocate file buffer\n"); + fclose(f); + return AVERROR(ENOMEM); + } +- fread(*bufptr, 1, *size, f); +- (*bufptr)[*size++] = '\0'; +- +- fclose(f); +- return 0; +-} +- +-void init_pts_correction(PtsCorrectionContext *ctx) +-{ +- ctx->num_faulty_pts = ctx->num_faulty_dts = 0; +- ctx->last_pts = ctx->last_dts = INT64_MIN; +-} +- +-int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t reordered_pts, int64_t dts) +-{ +- int64_t pts = AV_NOPTS_VALUE; +- +- if (dts != AV_NOPTS_VALUE) { +- ctx->num_faulty_dts += dts <= ctx->last_dts; +- ctx->last_dts = dts; +- } +- if (reordered_pts != AV_NOPTS_VALUE) { +- ctx->num_faulty_pts += reordered_pts <= ctx->last_pts; +- ctx->last_pts = reordered_pts; ++ ret = fread(*bufptr, 1, *size, f); ++ if (ret < *size) { ++ av_free(*bufptr); ++ if (ferror(f)) { ++ av_log(NULL, AV_LOG_ERROR, "Error while reading file '%s': %s\n", ++ filename, strerror(errno)); ++ ret = AVERROR(errno); ++ } else ++ ret = AVERROR_EOF; ++ } else { ++ ret = 0; ++ (*bufptr)[*size++] = '\0'; + } +- if ((ctx->num_faulty_pts<=ctx->num_faulty_dts || dts == AV_NOPTS_VALUE) +- && reordered_pts != AV_NOPTS_VALUE) +- pts = reordered_pts; +- else +- pts = dts; + +- return pts; ++ fclose(f); ++ return ret; + } + + FILE *get_preset_file(char *filename, size_t filename_size, +- const char *preset_name, int is_path, const char *codec_name) ++ const char *preset_name, int is_path, ++ const char *codec_name) + { + FILE *f = NULL; + int i; +- const char *base[3]= { getenv("FFMPEG_DATADIR"), +- getenv("HOME"), +- FFMPEG_DATADIR, +- }; ++ const char *base[3] = { getenv("FFMPEG_DATADIR"), ++ getenv("HOME"), ++ FFMPEG_DATADIR, }; + + if (is_path) { + av_strlcpy(filename, preset_name, filename_size); + f = fopen(filename, "r"); + } else { ++#ifdef _WIN32 ++ char datadir[MAX_PATH], *ls; ++ base[2] = NULL; ++ ++ if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1)) ++ { ++ for (ls = datadir; ls < datadir + strlen(datadir); ls++) ++ if (*ls == '\\') *ls = '/'; ++ ++ if (ls = strrchr(datadir, '/')) ++ { ++ *ls = 0; ++ strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir)); ++ base[2] = datadir; ++ } ++ } ++#endif + for (i = 0; i < 3 && !f; i++) { + if (!base[i]) + continue; +- snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name); ++ snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], ++ i != 1 ? "" : "/.ffmpeg", preset_name); + f = fopen(filename, "r"); + if (!f && codec_name) { + snprintf(filename, filename_size, +- "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name); ++ "%s%s/%s-%s.ffpreset", ++ base[i], i != 1 ? "" : "/.ffmpeg", codec_name, ++ preset_name); + f = fopen(filename, "r"); + } + } +@@ -796,65 +1043,150 @@ + return f; + } + +-#if CONFIG_AVFILTER +- +-static int ffsink_init(AVFilterContext *ctx, const char *args, void *opaque) ++int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec) + { +- FFSinkContext *priv = ctx->priv; +- +- if (!opaque) +- return AVERROR(EINVAL); +- *priv = *(FFSinkContext *)opaque; ++ if (*spec <= '9' && *spec >= '0') /* opt:index */ ++ return strtol(spec, NULL, 0) == st->index; ++ else if (*spec == 'v' || *spec == 'a' || *spec == 's' || *spec == 'd' || ++ *spec == 't') { /* opt:[vasdt] */ ++ enum AVMediaType type; ++ ++ switch (*spec++) { ++ case 'v': type = AVMEDIA_TYPE_VIDEO; break; ++ case 'a': type = AVMEDIA_TYPE_AUDIO; break; ++ case 's': type = AVMEDIA_TYPE_SUBTITLE; break; ++ case 'd': type = AVMEDIA_TYPE_DATA; break; ++ case 't': type = AVMEDIA_TYPE_ATTACHMENT; break; ++ default: abort(); // never reached, silence warning ++ } ++ if (type != st->codec->codec_type) ++ return 0; ++ if (*spec++ == ':') { /* possibly followed by :index */ ++ int i, index = strtol(spec, NULL, 0); ++ for (i = 0; i < s->nb_streams; i++) ++ if (s->streams[i]->codec->codec_type == type && index-- == 0) ++ return i == st->index; ++ return 0; ++ } ++ return 1; ++ } else if (*spec == 'p' && *(spec + 1) == ':') { ++ int prog_id, i, j; ++ char *endptr; ++ spec += 2; ++ prog_id = strtol(spec, &endptr, 0); ++ for (i = 0; i < s->nb_programs; i++) { ++ if (s->programs[i]->id != prog_id) ++ continue; + +- return 0; +-} ++ if (*endptr++ == ':') { ++ int stream_idx = strtol(endptr, NULL, 0); ++ return stream_idx >= 0 && ++ stream_idx < s->programs[i]->nb_stream_indexes && ++ st->index == s->programs[i]->stream_index[stream_idx]; ++ } + +-static void null_end_frame(AVFilterLink *inlink) { } ++ for (j = 0; j < s->programs[i]->nb_stream_indexes; j++) ++ if (st->index == s->programs[i]->stream_index[j]) ++ return 1; ++ } ++ return 0; ++ } else if (!*spec) /* empty specifier, matches everything */ ++ return 1; ++ ++ av_log(s, AV_LOG_ERROR, "Invalid stream specifier: %s.\n", spec); ++ return AVERROR(EINVAL); ++} ++ ++AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, ++ AVFormatContext *s, AVStream *st) ++{ ++ AVDictionary *ret = NULL; ++ AVDictionaryEntry *t = NULL; ++ int flags = s->oformat ? AV_OPT_FLAG_ENCODING_PARAM ++ : AV_OPT_FLAG_DECODING_PARAM; ++ char prefix = 0; ++ const AVClass *cc = avcodec_get_class(); ++ ++ if (!codec) ++ return NULL; ++ ++ switch (codec->type) { ++ case AVMEDIA_TYPE_VIDEO: ++ prefix = 'v'; ++ flags |= AV_OPT_FLAG_VIDEO_PARAM; ++ break; ++ case AVMEDIA_TYPE_AUDIO: ++ prefix = 'a'; ++ flags |= AV_OPT_FLAG_AUDIO_PARAM; ++ break; ++ case AVMEDIA_TYPE_SUBTITLE: ++ prefix = 's'; ++ flags |= AV_OPT_FLAG_SUBTITLE_PARAM; ++ break; ++ } ++ ++ while (t = av_dict_get(opts, "", t, AV_DICT_IGNORE_SUFFIX)) { ++ char *p = strchr(t->key, ':'); ++ ++ /* check stream specification in opt name */ ++ if (p) ++ switch (check_stream_specifier(s, st, p + 1)) { ++ case 1: *p = 0; break; ++ case 0: continue; ++ default: return NULL; ++ } + +-static int ffsink_query_formats(AVFilterContext *ctx) +-{ +- FFSinkContext *priv = ctx->priv; +- enum PixelFormat pix_fmts[] = { priv->pix_fmt, PIX_FMT_NONE }; ++ if (av_opt_find(&cc, t->key, NULL, flags, AV_OPT_SEARCH_FAKE_OBJ) || ++ (codec && codec->priv_class && ++ av_opt_find(&codec->priv_class, t->key, NULL, flags, ++ AV_OPT_SEARCH_FAKE_OBJ))) ++ av_dict_set(&ret, t->key, t->value, 0); ++ else if (t->key[0] == prefix && ++ av_opt_find(&cc, t->key + 1, NULL, flags, ++ AV_OPT_SEARCH_FAKE_OBJ)) ++ av_dict_set(&ret, t->key + 1, t->value, 0); + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); +- return 0; ++ if (p) ++ *p = ':'; ++ } ++ return ret; + } + +-AVFilter ffsink = { +- .name = "ffsink", +- .priv_size = sizeof(FFSinkContext), +- .init = ffsink_init, +- +- .query_formats = ffsink_query_formats, +- +- .inputs = (AVFilterPad[]) {{ .name = "default", +- .type = AVMEDIA_TYPE_VIDEO, +- .end_frame = null_end_frame, +- .min_perms = AV_PERM_READ, }, +- { .name = NULL }}, +- .outputs = (AVFilterPad[]) {{ .name = NULL }}, +-}; +- +-int get_filtered_video_frame(AVFilterContext *ctx, AVFrame *frame, +- AVFilterBufferRef **picref_ptr, AVRational *tb) ++AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, ++ AVDictionary *codec_opts) + { +- int ret; +- AVFilterBufferRef *picref; +- +- if ((ret = avfilter_request_frame(ctx->inputs[0])) < 0) +- return ret; +- if (!(picref = ctx->inputs[0]->cur_buf)) +- return AVERROR(ENOENT); +- *picref_ptr = picref; +- ctx->inputs[0]->cur_buf = NULL; +- *tb = ctx->inputs[0]->time_base; +- +- memcpy(frame->data, picref->data, sizeof(frame->data)); +- memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); +- frame->interlaced_frame = picref->video->interlaced; +- frame->top_field_first = picref->video->top_field_first; ++ int i; ++ AVDictionary **opts; + +- return 1; ++ if (!s->nb_streams) ++ return NULL; ++ opts = av_mallocz(s->nb_streams * sizeof(*opts)); ++ if (!opts) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Could not alloc memory for stream options.\n"); ++ return NULL; ++ } ++ for (i = 0; i < s->nb_streams; i++) ++ opts[i] = filter_codec_opts(codec_opts, avcodec_find_decoder(s->streams[i]->codec->codec_id), ++ s, s->streams[i]); ++ return opts; ++} ++ ++void *grow_array(void *array, int elem_size, int *size, int new_size) ++{ ++ if (new_size >= INT_MAX / elem_size) { ++ av_log(NULL, AV_LOG_ERROR, "Array too big.\n"); ++ exit_program(1); ++ } ++ if (*size < new_size) { ++ uint8_t *tmp = av_realloc(array, new_size*elem_size); ++ if (!tmp) { ++ av_log(NULL, AV_LOG_ERROR, "Could not alloc buffer.\n"); ++ exit_program(1); ++ } ++ memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); ++ *size = new_size; ++ return tmp; ++ } ++ return array; + } +- +-#endif /* CONFIG_AVFILTER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils_common_opts.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils_common_opts.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils_common_opts.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils_common_opts.h 2012-05-14 14:08:53.110315348 +0200 +@@ -1,13 +1,18 @@ +- { "L", OPT_EXIT, {(void*)show_license}, "show license" }, +- { "h", OPT_EXIT, {(void*)show_help}, "show help" }, +- { "?", OPT_EXIT, {(void*)show_help}, "show help" }, +- { "help", OPT_EXIT, {(void*)show_help}, "show help" }, +- { "-help", OPT_EXIT, {(void*)show_help}, "show help" }, +- { "version", OPT_EXIT, {(void*)show_version}, "show version" }, +- { "formats" , OPT_EXIT, {(void*)show_formats }, "show available formats" }, +- { "codecs" , OPT_EXIT, {(void*)show_codecs }, "show available codecs" }, +- { "bsfs" , OPT_EXIT, {(void*)show_bsfs }, "show available bit stream filters" }, +- { "protocols", OPT_EXIT, {(void*)show_protocols}, "show available protocols" }, +- { "filters", OPT_EXIT, {(void*)show_filters }, "show available filters" }, +- { "pix_fmts" , OPT_EXIT, {(void*)show_pix_fmts }, "show available pixel formats" }, +- { "loglevel", HAS_ARG | OPT_FUNC2, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, ++ { "L", OPT_EXIT, {(void*)opt_license}, "show license" }, ++ { "h", OPT_EXIT, {(void*)opt_help}, "show help" }, ++ { "?", OPT_EXIT, {(void*)opt_help}, "show help" }, ++ { "help", OPT_EXIT, {(void*)opt_help}, "show help" }, ++ { "-help", OPT_EXIT, {(void*)opt_help}, "show help" }, ++ { "version", OPT_EXIT, {(void*)opt_version}, "show version" }, ++ { "formats" , OPT_EXIT, {(void*)opt_formats }, "show available formats" }, ++ { "codecs" , OPT_EXIT, {(void*)opt_codecs }, "show available codecs" }, ++ { "bsfs" , OPT_EXIT, {(void*)opt_bsfs }, "show available bit stream filters" }, ++ { "protocols", OPT_EXIT, {(void*)opt_protocols}, "show available protocols" }, ++ { "filters", OPT_EXIT, {(void*)opt_filters }, "show available filters" }, ++ { "pix_fmts" , OPT_EXIT, {(void*)opt_pix_fmts }, "show available pixel formats" }, ++ { "sample_fmts", OPT_EXIT, {.func_arg = show_sample_fmts }, "show available audio sample formats" }, ++ { "loglevel", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, ++ { "v", HAS_ARG, {(void*)opt_loglevel}, "set libav* logging level", "loglevel" }, ++ { "debug", HAS_ARG, {(void*)opt_codec_debug}, "set debug flags", "flags" }, ++ { "report", 0, {(void*)opt_report}, "generate a report" }, ++ { "max_alloc", HAS_ARG, {(void*)opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/cmdutils.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/cmdutils.h 2012-05-14 14:08:53.110315348 +0200 +@@ -22,11 +22,17 @@ + #ifndef FFMPEG_CMDUTILS_H + #define FFMPEG_CMDUTILS_H + +-#include ++#include ++ + #include "libavcodec/avcodec.h" ++#include "libavfilter/avfilter.h" + #include "libavformat/avformat.h" + #include "libswscale/swscale.h" + ++#ifdef __MINGW32__ ++#undef main /* We don't want SDL to override our main() */ ++#endif ++ + /** + * program name, defined by the program for show_version(). + */ +@@ -37,10 +43,15 @@ + */ + extern const int program_birth_year; + +-extern const char **opt_names; ++/** ++ * this year, defined by the program for show_banner() ++ */ ++extern const int this_year; ++ + extern AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB]; + extern AVFormatContext *avformat_opts; + extern struct SwsContext *sws_opts; ++extern AVDictionary *format_opts, *codec_opts; + + /** + * Initialize the cmdutils option system, in particular +@@ -55,7 +66,7 @@ + + /** + * Trivial log callback. +- * Only suitable for show_help and similar since it lacks prefix handling. ++ * Only suitable for opt_help and similar since it lacks prefix handling. + */ + void log_callback_help(void* ptr, int level, const char* fmt, va_list vl); + +@@ -70,6 +81,12 @@ + */ + int opt_loglevel(const char *opt, const char *arg); + ++int opt_report(const char *opt); ++ ++int opt_max_alloc(const char *opt, const char *arg); ++ ++int opt_codec_debug(const char *opt, const char *arg); ++ + /** + * Limit the execution time. + */ +@@ -81,14 +98,15 @@ + * parsed or the corresponding value is invalid. + * + * @param context the context of the value to be set (e.g. the +- * corresponding commandline option name) ++ * corresponding command line option name) + * @param numstr the string to be parsed + * @param type the type (OPT_INT64 or OPT_FLOAT) as which the + * string should be parsed + * @param min the minimum valid accepted value + * @param max the maximum valid accepted value + */ +-double parse_number_or_die(const char *context, const char *numstr, int type, double min, double max); ++double parse_number_or_die(const char *context, const char *numstr, int type, ++ double min, double max); + + /** + * Parse a string specifying a time and return its corresponding +@@ -96,7 +114,7 @@ + * the string cannot be correctly parsed. + * + * @param context the context of the value to be set (e.g. the +- * corresponding commandline option name) ++ * corresponding command line option name) + * @param timestr the string to be parsed + * @param is_duration a flag which tells how to interpret timestr, if + * not zero timestr is interpreted as a duration, otherwise as a +@@ -104,7 +122,19 @@ + * + * @see parse_date() + */ +-int64_t parse_time_or_die(const char *context, const char *timestr, int is_duration); ++int64_t parse_time_or_die(const char *context, const char *timestr, ++ int is_duration); ++ ++typedef struct SpecifierOpt { ++ char *specifier; /**< stream/chapter/program/... specifier */ ++ union { ++ uint8_t *str; ++ int i; ++ int64_t i64; ++ float f; ++ double dbl; ++ } u; ++} SpecifierOpt; + + typedef struct { + const char *name; +@@ -119,35 +149,98 @@ + #define OPT_INT 0x0080 + #define OPT_FLOAT 0x0100 + #define OPT_SUBTITLE 0x0200 +-#define OPT_FUNC2 0x0400 +-#define OPT_INT64 0x0800 +-#define OPT_EXIT 0x1000 ++#define OPT_INT64 0x0400 ++#define OPT_EXIT 0x0800 ++#define OPT_DATA 0x1000 ++#define OPT_FUNC2 0x2000 ++#define OPT_OFFSET 0x4000 /* option is specified as an offset in a passed optctx */ ++#define OPT_SPEC 0x8000 /* option is to be stored in an array of SpecifierOpt. ++ Implies OPT_OFFSET. Next element after the offset is ++ an int containing element count in the array. */ ++#define OPT_TIME 0x10000 ++#define OPT_DOUBLE 0x20000 + union { +- void (*func_arg)(const char *); //FIXME passing error code as int return would be nicer then exit() in the func +- int *int_arg; +- char **str_arg; +- float *float_arg; +- int (*func2_arg)(const char *, const char *); +- int64_t *int64_arg; ++ void *dst_ptr; ++ int (*func_arg)(const char *, const char *); ++ int (*func2_arg)(void *, const char *, const char *); ++ size_t off; + } u; + const char *help; + const char *argname; + } OptionDef; + +-void show_help_options(const OptionDef *options, const char *msg, int mask, int value); ++void show_help_options(const OptionDef *options, const char *msg, int mask, ++ int value); ++ ++/** ++ * Show help for all options with given flags in class and all its ++ * children. ++ */ ++void show_help_children(const AVClass *class, int flags); + + /** + * Parse the command line arguments. ++ * ++ * @param optctx an opaque options context + * @param options Array with the definitions required to interpret every + * option of the form: -option_name [argument] + * @param parse_arg_function Name of the function called to process every + * argument without a leading option name flag. NULL if such arguments do + * not have to be processed. + */ +-void parse_options(int argc, char **argv, const OptionDef *options, +- void (* parse_arg_function)(const char*)); ++void parse_options(void *optctx, int argc, char **argv, const OptionDef *options, ++ void (* parse_arg_function)(void *optctx, const char*)); + +-void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec); ++/** ++ * Parse one given option. ++ * ++ * @return on success 1 if arg was consumed, 0 otherwise; negative number on error ++ */ ++int parse_option(void *optctx, const char *opt, const char *arg, ++ const OptionDef *options); ++ ++/** ++ * Find the '-loglevel' option in the command line args and apply it. ++ */ ++void parse_loglevel(int argc, char **argv, const OptionDef *options); ++ ++/** ++ * Check if the given stream matches a stream specifier. ++ * ++ * @param s Corresponding format context. ++ * @param st Stream from s to be checked. ++ * @param spec A stream specifier of the [v|a|s|d]:[\] form. ++ * ++ * @return 1 if the stream matches, 0 if it doesn't, <0 on error ++ */ ++int check_stream_specifier(AVFormatContext *s, AVStream *st, const char *spec); ++ ++/** ++ * Filter out options for given codec. ++ * ++ * Create a new options dictionary containing only the options from ++ * opts which apply to the codec with ID codec_id. ++ * ++ * @param s Corresponding format context. ++ * @param st A stream from s for which the options should be filtered. ++ * @return a pointer to the created dictionary ++ */ ++AVDictionary *filter_codec_opts(AVDictionary *opts, AVCodec *codec, ++ AVFormatContext *s, AVStream *st); ++ ++/** ++ * Setup AVCodecContext options for avformat_find_stream_info(). ++ * ++ * Create an array of dictionaries, one dictionary for each stream ++ * contained in s. ++ * Each dictionary will contain the options from codec_opts which can ++ * be applied to the corresponding stream codec context. ++ * ++ * @return pointer to the created array of dictionaries, NULL if it ++ * cannot be created ++ */ ++AVDictionary **setup_find_stream_info_opts(AVFormatContext *s, ++ AVDictionary *codec_opts); + + /** + * Print an error message to stderr, indicating filename and a human +@@ -160,63 +253,75 @@ + */ + void print_error(const char *filename, int err); + +-void list_fmts(void (*get_fmt_string)(char *buf, int buf_size, int fmt), int nb_fmts); +- + /** + * Print the program banner to stderr. The banner contents depend on the + * current version of the repository and of the libav* libraries used by + * the program. + */ +-void show_banner(void); ++void show_banner(int argc, char **argv, const OptionDef *options); + + /** + * Print the version of the program to stdout. The version message + * depends on the current versions of the repository and of the libav* + * libraries. ++ * This option processing function does not utilize the arguments. + */ +-void show_version(void); ++int opt_version(const char *opt, const char *arg); + + /** + * Print the license of the program to stdout. The license depends on + * the license of the libraries compiled into the program. ++ * This option processing function does not utilize the arguments. + */ +-void show_license(void); ++int opt_license(const char *opt, const char *arg); + + /** + * Print a listing containing all the formats supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_formats(void); ++int opt_formats(const char *opt, const char *arg); + + /** + * Print a listing containing all the codecs supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_codecs(void); ++int opt_codecs(const char *opt, const char *arg); + + /** + * Print a listing containing all the filters supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_filters(void); ++int opt_filters(const char *opt, const char *arg); + + /** + * Print a listing containing all the bit stream filters supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_bsfs(void); ++int opt_bsfs(const char *opt, const char *arg); + + /** + * Print a listing containing all the protocols supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_protocols(void); ++int opt_protocols(const char *opt, const char *arg); + + /** + * Print a listing containing all the pixel formats supported by the + * program. ++ * This option processing function does not utilize the arguments. + */ +-void show_pix_fmts(void); ++int opt_pix_fmts(const char *opt, const char *arg); ++ ++/** ++ * Print a listing containing all the sample formats supported by the ++ * program. ++ */ ++int show_sample_fmts(const char *opt, const char *arg); + + /** + * Return a positive value if a line read from standard input +@@ -233,31 +338,7 @@ + * @return 0 in case of success, a negative value corresponding to an + * AVERROR error code in case of failure. + */ +-int read_file(const char *filename, char **bufptr, size_t *size); +- +-typedef struct { +- int64_t num_faulty_pts; /// Number of incorrect PTS values so far +- int64_t num_faulty_dts; /// Number of incorrect DTS values so far +- int64_t last_pts; /// PTS of the last frame +- int64_t last_dts; /// DTS of the last frame +-} PtsCorrectionContext; +- +-/** +- * Reset the state of the PtsCorrectionContext. +- */ +-void init_pts_correction(PtsCorrectionContext *ctx); +- +-/** +- * Attempt to guess proper monotonic timestamps for decoded video frames +- * which might have incorrect times. Input timestamps may wrap around, in +- * which case the output will as well. +- * +- * @param pts the pts field of the decoded AVPacket, as passed through +- * AVCodecContext.reordered_opaque +- * @param dts the dts field of the decoded AVPacket +- * @return one of the input values, may be AV_NOPTS_VALUE +- */ +-int64_t guess_correct_pts(PtsCorrectionContext *ctx, int64_t pts, int64_t dts); ++int cmdutils_read_file(const char *filename, char **bufptr, size_t *size); + + /** + * Get a file corresponding to a preset file. +@@ -265,7 +346,8 @@ + * If is_path is non-zero, look for the file in the path preset_name. + * Otherwise search for a file named arg.ffpreset in the directories + * $FFMPEG_DATADIR (if set), $HOME/.ffmpeg, and in the datadir defined +- * at configuration time, in that order. If no such file is found and ++ * at configuration time or in a "ffpresets" folder along the executable ++ * on win32, in that order. If no such file is found and + * codec_name is defined, then search for a file named + * codec_name-preset_name.ffpreset in the above-mentioned directories. + * +@@ -279,24 +361,20 @@ + FILE *get_preset_file(char *filename, size_t filename_size, + const char *preset_name, int is_path, const char *codec_name); + +-#if CONFIG_AVFILTER +-#include "libavfilter/avfilter.h" +- +-typedef struct { +- enum PixelFormat pix_fmt; +-} FFSinkContext; +- +-extern AVFilter ffsink; ++/** ++ * Do all the necessary cleanup and abort. ++ * This function is implemented in the avtools, not cmdutils. ++ */ ++void exit_program(int ret); + + /** +- * Extract a frame from sink. ++ * Realloc array to hold new_size elements of elem_size. ++ * Calls exit_program() on failure. + * +- * @return a negative error in case of failure, 1 if one frame has +- * been extracted successfully. ++ * @param elem_size size in bytes of each element ++ * @param size new element count will be written here ++ * @return reallocated array + */ +-int get_filtered_video_frame(AVFilterContext *sink, AVFrame *frame, +- AVFilterBufferRef **picref, AVRational *pts_tb); +- +-#endif /* CONFIG_AVFILTER */ ++void *grow_array(void *array, int elem_size, int *size, int new_size); + +-#endif /* FFMPEG_CMDUTILS_H */ ++#endif /* CMDUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/common.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/common.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/common.mak 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/common.mak 2012-05-14 14:08:53.111315368 +0200 +@@ -6,22 +6,11 @@ + all: all-yes + + ifndef SUBDIR +-vpath %.c $(SRC_DIR) +-vpath %.h $(SRC_DIR) +-vpath %.S $(SRC_DIR) +-vpath %.asm $(SRC_DIR) +-vpath %.v $(SRC_DIR) +- +-ifeq ($(SRC_DIR),$(SRC_PATH_BARE)) +-BUILD_ROOT_REL = . +-else +-BUILD_ROOT_REL = .. +-endif + + ifndef V + Q = @ + ECHO = printf "$(1)\t%s\n" $(2) +-BRIEF = CC AS YASM AR LD HOSTCC STRIP CP ++BRIEF = CC CXX AS YASM AR LD HOSTCC STRIP CP + SILENT = DEPCC YASMDEP RM RANLIB + MSG = $@ + M = @$(call ECHO,$(TAG),$@); +@@ -31,28 +20,42 @@ + $(eval INSTALL = @$(call ECHO,INSTALL,$$(^:$(SRC_DIR)/%=%)); $(INSTALL)) + endif + +-ALLFFLIBS = avcodec avcore avdevice avfilter avformat avutil postproc swscale +- +-IFLAGS := -I$(BUILD_ROOT_REL) -I$(SRC_PATH) +-CPPFLAGS := $(IFLAGS) $(CPPFLAGS) +-CFLAGS += $(ECFLAGS) +-YASMFLAGS += $(IFLAGS) -Pconfig.asm ++ALLFFLIBS = avcodec avdevice avfilter avformat avutil postproc swscale swresample + ++# NASM requires -I path terminated with / ++IFLAGS := -I. -I$(SRC_PATH)/ ++CPPFLAGS := $(IFLAGS) $(CPPFLAGS) ++CFLAGS += $(ECFLAGS) ++CCFLAGS = $(CFLAGS) ++CXXFLAGS := $(CFLAGS) $(CXXFLAGS) ++YASMFLAGS += $(IFLAGS) -I$(SRC_PATH)/libavutil/x86/ -Pconfig.asm + HOSTCFLAGS += $(IFLAGS) ++LDFLAGS := $(ALLFFLIBS:%=-Llib%) $(LDFLAGS) ++ ++define COMPILE ++ $($(1)DEP) ++ $($(1)) $(CPPFLAGS) $($(1)FLAGS) $($(1)_DEPFLAGS) -c $($(1)_O) $< ++endef ++ ++COMPILE_C = $(call COMPILE,CC) ++COMPILE_CXX = $(call COMPILE,CXX) ++COMPILE_S = $(call COMPILE,AS) + + %.o: %.c +- $(CCDEP) +- $(CC) $(CPPFLAGS) $(CFLAGS) $(CC_DEPFLAGS) -c $(CC_O) $< ++ $(COMPILE_C) ++ ++%.o: %.cpp ++ $(COMPILE_CXX) ++ ++%.s: %.c ++ $(CC) $(CPPFLAGS) $(CFLAGS) -S -o $@ $< + + %.o: %.S +- $(ASDEP) +- $(AS) $(CPPFLAGS) $(ASFLAGS) $(AS_DEPFLAGS) -c -o $@ $< ++ $(COMPILE_S) + + %.ho: %.h + $(CC) $(CPPFLAGS) $(CFLAGS) -Wno-unused -c -o $@ -x c $< + +-%$(EXESUF): %.c +- + %.ver: %.v + $(Q)sed 's/$$MAJOR/$($(basename $(@F))_VERSION_MAJOR)/' $^ > $@ + +@@ -62,13 +65,6 @@ + %.h: + @: + +-install: install-libs install-headers +-install-libs: install-libs-yes +- +-uninstall: uninstall-libs uninstall-headers +- +-.PHONY: all depend dep *clean install* uninstall* examples testprogs +- + # Disable suffix rules. Most of the builtin rules are suffix rules, + # so this saves some time on slow systems. + .SUFFIXES: +@@ -79,36 +75,46 @@ + + OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes) + +-CFLAGS += $(CFLAGS-yes) + OBJS += $(OBJS-yes) + FFLIBS := $(FFLIBS-yes) $(FFLIBS) + TESTPROGS += $(TESTPROGS-yes) + +-FFEXTRALIBS := $(addprefix -l,$(addsuffix $(BUILDSUF),$(FFLIBS))) $(EXTRALIBS) +-FFLDFLAGS := $(addprefix -L$(BUILD_ROOT)/lib,$(ALLFFLIBS)) $(LDFLAGS) ++FFEXTRALIBS := $(FFLIBS:%=-l%$(BUILDSUF)) $(EXTRALIBS) + +-EXAMPLES := $(addprefix $(SUBDIR),$(addsuffix -example$(EXESUF),$(EXAMPLES))) +-OBJS := $(addprefix $(SUBDIR),$(sort $(OBJS))) +-TESTOBJS := $(addprefix $(SUBDIR),$(TESTOBJS)) +-TESTPROGS := $(addprefix $(SUBDIR),$(addsuffix -test$(EXESUF),$(TESTPROGS))) +-HOSTOBJS := $(addprefix $(SUBDIR),$(addsuffix .o,$(HOSTPROGS))) +-HOSTPROGS := $(addprefix $(SUBDIR),$(addsuffix $(HOSTEXESUF),$(HOSTPROGS))) ++EXAMPLES := $(EXAMPLES:%=$(SUBDIR)%-example$(EXESUF)) ++OBJS := $(sort $(OBJS:%=$(SUBDIR)%)) ++TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o) ++TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF)) ++HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o) ++HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF)) ++TOOLS += $(TOOLS-yes) ++TOOLOBJS := $(TOOLS:%=tools/%.o) ++TOOLS := $(TOOLS:%=tools/%$(EXESUF)) + +-DEP_LIBS := $(foreach NAME,$(FFLIBS),$(BUILD_ROOT_REL)/lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME)) ++DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME)) + + ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h)) +-SKIPHEADERS += $(addprefix $(ARCH)/,$(ARCH_HEADERS)) +-SKIPHEADERS := $(addprefix $(SUBDIR),$(SKIPHEADERS-) $(SKIPHEADERS)) ++SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-) ++SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%) + checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho)) + ++alltools: $(TOOLS) ++ + $(HOSTOBJS): %.o: %.c + $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $< + + $(HOSTPROGS): %$(HOSTEXESUF): %.o + $(HOSTCC) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS) + +-CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver ++$(OBJS): | $(sort $(dir $(OBJS))) ++$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS))) ++$(TESTOBJS): | $(sort $(dir $(TESTOBJS))) ++$(TOOLOBJS): | tools ++ ++OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS)) ++ ++CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver *.gcno *.gcda + DISTCLEANSUFFIXES = *.pc + LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp + +--include $(wildcard $(OBJS:.o=.d)) ++-include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d)) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/configure xbmc-pvr-11.0.1.patch/lib/ffmpeg/configure +--- xbmc-pvr-11.0.1/lib/ffmpeg/configure 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/configure 2012-05-14 14:08:53.123315609 +0200 +@@ -86,16 +86,16 @@ + --disable-ffserver disable ffserver build + --disable-avdevice disable libavdevice build + --disable-avcodec disable libavcodec build +- --disable-avcore disable libavcore build + --disable-avformat disable libavformat build ++ --disable-swresample disable libswresample build + --disable-swscale disable libswscale build +- --enable-postproc enable GPLed postprocessing support [no] ++ --disable-postproc disable libpostproc build + --disable-avfilter disable video filter support [no] + --disable-pthreads disable pthreads [auto] +- --enable-w32threads use Win32 threads [no] ++ --disable-w32threads disable Win32 threads [auto] ++ --disable-os2threads disable OS/2 threads [auto] + --enable-x11grab enable X11 grabbing [no] + --disable-network disable network support [no] +- --disable-mpegaudio-hp faster (but less accurate) MPEG audio decoding [no] + --enable-gray enable full grayscale support (slower color) + --disable-swscale-alpha disable alpha channel support in swscale + --disable-fastdiv disable table-based division +@@ -108,11 +108,16 @@ + --disable-lpc disable LPC code + --disable-mdct disable MDCT code + --disable-rdft disable RDFT code +- --disable-vaapi disable VAAPI code +- --disable-vdpau disable VDPAU code ++ --enable-vaapi enable VAAPI code [autodetect] ++ --enable-vda enable VDA code [autodetect] ++ --enable-vdpau enable VDPAU code [autodetect] + --disable-dxva2 disable DXVA2 code ++ --disable-vda disable VDA code + --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary) + --enable-hardcoded-tables use hardcoded tables instead of runtime generation ++ --disable-safe-bitstream-reader ++ disable buffer boundary checking in bitreaders ++ (faster, but may crash) + --enable-memalign-hack emulate memalign, interferes with memory debuggers + --disable-everything disable all components listed below + --disable-encoder=NAME disable encoder NAME +@@ -163,22 +168,35 @@ + --enable-avisynth enable reading of AVISynth script files [no] + --enable-bzlib enable bzlib [autodetect] + --enable-frei0r enable frei0r video filtering ++ --enable-gnutls enable gnutls [no] ++ --enable-libaacplus enable AAC+ encoding via libaacplus [no] ++ --enable-libass enable libass subtitles rendering [no] ++ --enable-libcelt enable CELT decoding via libcelt [no] + --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no] + --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no] + --enable-libopencv enable video filtering via libopencv [no] ++ --enable-libcdio enable audio CD grabbing with libcdio + --enable-libdc1394 enable IIDC-1394 grabbing using libdc1394 + and libraw1394 [no] + --enable-libdirac enable Dirac support via libdirac [no] + --enable-libfaac enable FAAC support via libfaac [no] ++ --enable-libfreetype enable libfreetype [no] + --enable-libgsm enable GSM support via libgsm [no] ++ --enable-libmodplug enable ModPlug via libmodplug [no] + --enable-libmp3lame enable MP3 encoding via libmp3lame [no] + --enable-libnut enable NUT (de)muxing via libnut, + native (de)muxer exists [no] +- --enable-libopenjpeg enable JPEG 2000 decoding via OpenJPEG [no] ++ --enable-libopenjpeg enable JPEG 2000 encoding/decoding via OpenJPEG [no] ++ --enable-libpulse enable Pulseaudio input via libpulse [no] + --enable-librtmp enable RTMP[E] support via librtmp [no] + --enable-libschroedinger enable Dirac support via libschroedinger [no] +- --enable-libspeex enable Speex decoding via libspeex [no] ++ --enable-libspeex enable Speex support via libspeex [no] ++ --enable-libstagefright-h264 enable H.264 decoding via libstagefright [no] + --enable-libtheora enable Theora encoding via libtheora [no] ++ --enable-libutvideo enable Ut Video decoding via libutvideo [no] ++ --enable-libv4l2 enable libv4l2/v4l-utils [no] ++ --enable-libvo-aacenc enable AAC encoding via libvo-aacenc [no] ++ --enable-libvo-amrwbenc enable AMR-WB encoding via libvo-amrwbenc [no] + --enable-libvorbis enable Vorbis encoding via libvorbis, + native implementation exists [no] + --enable-libvpx enable VP8 support via libvpx [no] +@@ -186,11 +204,12 @@ + --enable-libxavs enable AVS encoding via xavs [no] + --enable-libxvid enable Xvid encoding via xvidcore, + native MPEG-4/Xvid encoder exists [no] ++ --enable-openal enable OpenAL 1.1 capture support [no] + --enable-mlib enable Sun medialib [no] ++ --enable-openssl enable openssl [no] + --enable-zlib enable zlib [autodetect] + + Advanced options (experts only): +- --source-path=PATH path to source code [$source_path] + --cross-prefix=PREFIX use PREFIX for compilation tools [$cross_prefix] + --enable-cross-compile assume a cross-compiler is used + --sysroot=PATH root of cross-build tree +@@ -198,20 +217,24 @@ + --target-os=OS compiler targets OS [$target_os] + --target-exec=CMD command to run executables on target + --target-path=DIR path to view of build directory on target +- --nm=NM use nm tool ++ --nm=NM use nm tool NM [$nm_default] + --ar=AR use archive tool AR [$ar_default] + --as=AS use assembler AS [$as_default] ++ --yasmexe=EXE use yasm-compatible assembler EXE [$yasmexe_default] + --cc=CC use C compiler CC [$cc_default] +- --ld=LD use linker LD ++ --cxx=CXX use C compiler CXX [$cxx_default] ++ --ld=LD use linker LD [$ld_default] + --host-cc=HOSTCC use host C compiler HOSTCC + --host-cflags=HCFLAGS use HCFLAGS when compiling for host + --host-ldflags=HLDFLAGS use HLDFLAGS when linking for host + --host-libs=HLIBS use libs HLIBS when linking for host + --extra-cflags=ECFLAGS add ECFLAGS to CFLAGS [$CFLAGS] ++ --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS [$CXXFLAGS] + --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS [$LDFLAGS] + --extra-libs=ELIBS add ELIBS [$ELIBS] + --extra-version=STRING version string suffix [] + --build-suffix=SUFFIX library name suffix [] ++ --progs-suffix=SUFFIX program name suffix [] + --arch=ARCH select architecture [$arch] + --cpu=CPU select the minimum required CPU (affects + instruction selection, may crash on older CPUs) +@@ -224,27 +247,36 @@ + --disable-mmx2 disable MMX2 optimizations + --disable-sse disable SSE optimizations + --disable-ssse3 disable SSSE3 optimizations ++ --disable-avx disable AVX optimizations + --disable-armv5te disable armv5te optimizations + --disable-armv6 disable armv6 optimizations + --disable-armv6t2 disable armv6t2 optimizations + --disable-armvfp disable ARM VFP optimizations + --disable-iwmmxt disable iwmmxt optimizations + --disable-mmi disable MMI optimizations +- --disable-neon disable neon optimizations ++ --disable-neon disable NEON optimizations + --disable-vis disable VIS optimizations + --disable-yasm disable use of yasm assembler + --enable-pic build position-independent code + --malloc-prefix=PFX prefix malloc and related names with PFX + --enable-sram allow use of on-chip SRAM + --disable-symver disable symbol versioning ++ --optflags override optimization-related compiler flags ++ --postproc-version=V build libpostproc version V. ++ Where V can be '$ALT_PP_VER_MAJOR.$ALT_PP_VER_MINOR.$ALT_PP_VER_MICRO' or 'current'. [$postproc_version_default] + + Developer options (useful when working on FFmpeg itself): ++ --enable-coverage build with test coverage instrumentation + --disable-debug disable debugging symbols + --enable-debug=LEVEL set the debug level [$debuglevel] + --disable-optimizations disable compiler optimizations + --enable-extra-warnings enable more compiler warnings + --disable-stripping disable stripping of executables and shared libraries +- --samples=PATH location of test samples for FATE ++ --valgrind=VALGRIND run "make fate" tests through valgrind to detect memory ++ leaks and errors, using the specified valgrind binary. ++ Cannot be combined with --target-exec ++ --samples=PATH location of test samples for FATE, if not set use ++ \$FATE_SAMPLES at make invocation time. + + NOTE: Object files are built at the place where configure is launched. + EOF +@@ -279,7 +311,7 @@ + + If you think configure made a mistake, make sure you are using the latest + version from Git. If the latest version fails, report the problem to the +-ffmpeg-user@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net. ++ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net. + EOF + if disabled logging; then + cat < $TMPCPP ++ log_file $TMPCPP ++ check_cmd $cxx $CPPFLAGS $CFLAGS $CXXFLAGS "$@" -c -o $TMPO $TMPCPP ++} ++ + check_cpp(){ + log check_cpp "$@" + cat > $TMPC +@@ -621,13 +678,15 @@ + + check_ld(){ + log check_ld "$@" ++ type=$1 ++ shift 1 + flags='' + libs='' + for f; do + test "${f}" = "${f#-l}" && flags="$flags $f" || libs="$libs $f" + done +- check_cc $($filter_cflags $flags) || return +- check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $extralibs $libs ++ check_$type $($filter_cflags $flags) || return ++ check_cmd $ld $LDFLAGS $flags -o $TMPE $TMPO $libs $extralibs + } + + check_cppflags(){ +@@ -646,9 +705,17 @@ + EOF + } + ++check_cxxflags(){ ++ log check_cxxflags "$@" ++ set -- $($filter_cflags "$@") ++ check_cxx "$@" < + float foo(float f) { return $func(f); } +-int main(void){ return 0; } ++int main(void){ return (int) foo; } + EOF + } + + check_func_headers(){ + log check_func_headers "$@" + headers=$1 +- func=$2 ++ funcs=$2 + shift 2 +- disable $func +- incs="" +- for hdr in $headers; do +- incs="$incs +-#include <$hdr>" +- done +- check_ld "$@" <" ++ done ++ for func in $funcs; do ++ echo "long check_$func(void) { return (long) $func; }" ++ done ++ echo "int main(void) { return 0; }" ++ } | check_ld "cc" "$@" && enable $funcs && enable_safe $headers + } +-EOF ++ ++check_class_headers_cpp(){ ++ log check_class_headers_cpp "$@" ++ headers=$1 ++ classes=$2 ++ shift 2 ++ { ++ for hdr in $headers; do ++ echo "#include <$hdr>" ++ done ++ echo "int main(void) { " ++ i=1 ++ for class in $classes; do ++ echo "$class obj$i;" ++ i=$(expr $i + 1) ++ done ++ echo "return 0; }" ++ } | check_ld "cxx" "$@" && enable $funcs && enable_safe $headers + } + + check_cpp_condition(){ +@@ -735,13 +818,35 @@ + check_lib2(){ + log check_lib2 "$@" + headers="$1" +- func="$2" ++ funcs="$2" ++ shift 2 ++ check_func_headers "$headers" "$funcs" "$@" && add_extralibs "$@" ++} ++ ++check_lib_cpp(){ ++ log check_lib_cpp "$@" ++ headers="$1" ++ classes="$2" + shift 2 +- check_func_headers "$headers" $func "$@" && add_extralibs "$@" ++ check_class_headers_cpp "$headers" "$classes" "$@" && add_extralibs "$@" ++} ++ ++check_pkg_config(){ ++ log check_pkg_config "$@" ++ pkg="$1" ++ headers="$2" ++ funcs="$3" ++ shift 3 ++ $pkg_config --exists $pkg 2>/dev/null || return ++ pkg_cflags=$($pkg_config --cflags $pkg) ++ pkg_libs=$($pkg_config --libs $pkg) ++ check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" && ++ set_safe ${pkg}_cflags $pkg_cflags && ++ set_safe ${pkg}_libs $pkg_libs + } + + check_exec(){ +- check_ld "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; } ++ check_ld "cc" "$@" && { enabled cross_compile || $TMPE >> $logfile 2>&1; } + } + + check_exec_crash(){ +@@ -758,6 +863,9 @@ + static void sighandler(int sig){ + raise(SIGTERM); + } ++int func(void){ ++ $code ++} + int main(void){ + signal(SIGILL, sighandler); + signal(SIGFPE, sighandler); +@@ -765,7 +873,7 @@ + #ifdef SIGBUS + signal(SIGBUS, sighandler); + #endif +- { $code } ++ return func(); + } + EOF + } +@@ -821,6 +929,21 @@ + check_lib2 "$headers" $func "$@" || die "ERROR: $name not found" + } + ++require_cpp(){ ++ name="$1" ++ headers="$2" ++ classes="$3" ++ shift 3 ++ check_lib_cpp "$headers" "$classes" "$@" || die "ERROR: $name not found" ++} ++ ++require_pkg_config(){ ++ pkg="$1" ++ check_pkg_config "$@" || die "ERROR: $pkg not found" ++ add_cflags $(get_safe ${pkg}_cflags) ++ add_extralibs $(get_safe ${pkg}_libs) ++} ++ + check_host_cc(){ + log check_host_cc "$@" + cat > $TMPC +@@ -842,9 +965,9 @@ + } + + cp_if_changed(){ +- cmp -s "$1" "$2" && +- echo "$2 is unchanged" || +- cp -f "$1" "$2" ++ cmp -s "$1" "$2" && echo "$2 is unchanged" && return ++ mkdir -p "$(dirname $2)" ++ cp -f "$1" "$2" + } + + # CONFIG_LIST contains configurable options, while HAVE_LIST is for +@@ -864,48 +987,70 @@ + protocols + " + ++PROGRAM_LIST=" ++ ffplay ++ ffprobe ++ ffserver ++ ffmpeg ++" ++ + CONFIG_LIST=" + $COMPONENT_LIST ++ $PROGRAM_LIST ++ avplay ++ avprobe ++ avserver + aandct ++ ac3dsp + avcodec +- avcore + avdevice + avfilter + avformat + avisynth + bzlib ++ crystalhd + dct + doc + dwt + dxva2 + fastdiv +- ffmpeg +- ffplay +- ffprobe +- ffserver + fft + frei0r ++ gnutls + golomb + gpl + gray ++ h264chroma + h264dsp + h264pred + hardcoded_tables + huffman ++ libaacplus ++ libass ++ libcdio ++ libcelt + libdc1394 + libdirac + libfaac ++ libfreetype + libgsm ++ libmodplug + libmp3lame + libnut + libopencore_amrnb + libopencore_amrwb + libopencv + libopenjpeg ++ libpulse + librtmp + libschroedinger + libspeex ++ libstagefright_h264 + libtheora ++ libutvideo ++ libv4l2 ++ libvo_aacenc ++ libvo_amrwbenc + libvorbis + libvpx + libx264 +@@ -916,21 +1061,28 @@ + mdct + memalign_hack + mlib +- mpegaudio_hp ++ mpegaudiodsp + network + nonfree ++ openal ++ openssl + pic + postproc + rdft + rtpdec + runtime_cpudetect ++ safe_bitstream_reader + shared ++ sinewin + small + sram + static ++ swresample + swscale + swscale_alpha ++ thumb + vaapi ++ vda + vdpau + version3 + x11grab +@@ -940,6 +1092,7 @@ + THREADS_LIST=' + pthreads + w32threads ++ os2threads + ' + + ARCH_LIST=' +@@ -974,6 +1127,7 @@ + armv6 + armv6t2 + armvfp ++ avx + iwmmxt + mmi + mmx +@@ -982,6 +1136,7 @@ + ppc4xx + sse + ssse3 ++ vfpv3 + vis + ' + +@@ -998,18 +1153,19 @@ + alsa_asoundlib_h + altivec_h + arpa_inet_h ++ asm_mod_y ++ asm_types_h + attribute_may_alias + attribute_packed +- bswap ++ cbrtf + closesocket + cmov +- conio_h + dcbzl + dev_bktr_ioctl_bt848_h + dev_bktr_ioctl_meteor_h + dev_ic_bt8xx_h +- dev_video_meteor_ioctl_meteor_h + dev_video_bktr_ioctl_bt848_h ++ dev_video_meteor_ioctl_meteor_h + dlfcn_h + dlopen + dos_paths +@@ -1024,22 +1180,22 @@ + fork + getaddrinfo + gethrtime ++ GetProcessAffinityMask + GetProcessMemoryInfo + GetProcessTimes + getrusage + gnu_as +- struct_rusage_ru_maxrss + ibm_asm + inet_aton + inline_asm + isatty ++ kbhit + ldbrx +- libdc1394_1 +- libdc1394_2 + llrint + llrintf + local_aligned_16 + local_aligned_8 ++ localtime_r + log2 + log2f + loongson +@@ -1048,40 +1204,48 @@ + lzo1x_999_compress + machine_ioctl_bt848_h + machine_ioctl_meteor_h ++ makeinfo + malloc_h + MapViewOfFile + memalign + mkstemp + mmap +- pld ++ PeekNamedPipe ++ poll_h + posix_memalign + round + roundf ++ sched_getaffinity + sdl + sdl_video_size + setmode ++ setrlimit ++ sndio_h + socklen_t + soundcard_h +- poll_h +- setrlimit + strerror_r +- strtok_r ++ strptime + struct_addrinfo + struct_ipv6_mreq ++ struct_rusage_ru_maxrss + struct_sockaddr_in6 + struct_sockaddr_sa_len + struct_sockaddr_storage ++ struct_v4l2_frmivalenum_discrete + symver +- symver_gnu_asm + symver_asm_label ++ symver_gnu_asm ++ sysconf ++ sysctl + sys_mman_h ++ sys_param_h + sys_resource_h + sys_select_h + sys_soundcard_h + sys_videoio_h +- ten_operands + termios_h + threads ++ trunc + truncf + vfp_args + VirtualAlloc +@@ -1103,6 +1267,7 @@ + $CONFIG_LIST + $THREADS_LIST + asm ++ coverage + cross_compile + debug + extra_warnings +@@ -1129,9 +1294,11 @@ + arch + as + build_suffix ++ progs_suffix + cc + cpu + cross_prefix ++ cxx + custom_libname_with_major + dep_cc + extra_version +@@ -1140,22 +1307,28 @@ + host_ldflags + host_libs + host_os ++ install + ld + logfile + malloc_prefix + nm ++ optflags ++ pkg_config + samples +- source_path + strip + sysinclude + sysroot + target_exec + target_os + target_path ++ postproc_version ++ valgrind ++ yasmexe + " + + CMDLINE_APPEND=" + extra_cflags ++ extra_cxxflags + " + + # code dependency declarations +@@ -1168,6 +1341,7 @@ + armvfp_deps="arm" + iwmmxt_deps="arm" + neon_deps="arm" ++vfpv3_deps="armvfp" + + mmi_deps="mips" + +@@ -1183,14 +1357,15 @@ + mmx2_deps="mmx" + sse_deps="mmx" + ssse3_deps="sse" ++avx_deps="ssse3" + + aligned_stack_if_any="ppc x86" + fast_64bit_if_any="alpha ia64 mips64 parisc64 ppc64 sparc64 x86_64" + fast_clz_if_any="alpha armv5te avr32 mips ppc x86" + fast_unaligned_if_any="armv6 ppc x86" + +-need_memalign="altivec neon sse" + inline_asm_deps="!tms470" ++need_memalign="altivec neon sse" + + symver_if_any="symver_asm_label symver_gnu_asm" + +@@ -1198,27 +1373,30 @@ + dct_select="rdft" + mdct_select="fft" + rdft_select="fft" ++mpegaudiodsp_select="dct" + + # decoders / encoders / hardware accelerators +-aac_decoder_select="mdct rdft" +-aac_encoder_select="mdct" ++aac_decoder_select="mdct sinewin" ++aac_encoder_select="mdct sinewin" + aac_latm_decoder_select="aac_decoder aac_latm_parser" +-ac3_decoder_select="mdct ac3_parser" +-ac3_encoder_select="mdct" ++ac3_decoder_select="mdct ac3dsp ac3_parser" ++ac3_encoder_select="mdct ac3dsp" ++ac3_fixed_encoder_select="mdct ac3dsp" + alac_encoder_select="lpc" + amrnb_decoder_select="lsp" + amrwb_decoder_select="lsp" +-atrac1_decoder_select="mdct" ++atrac1_decoder_select="mdct sinewin" + atrac3_decoder_select="mdct" +-binkaudio_dct_decoder_select="mdct rdft dct" +-binkaudio_rdft_decoder_select="mdct rdft" ++binkaudio_dct_decoder_select="mdct rdft dct sinewin" ++binkaudio_rdft_decoder_select="mdct rdft sinewin" + cavs_decoder_select="golomb" +-cook_decoder_select="mdct" ++cook_decoder_select="mdct sinewin" + cscd_decoder_suggest="zlib" + dca_decoder_select="mdct" + dnxhd_encoder_select="aandct" + dxa_decoder_select="zlib" + eac3_decoder_select="ac3_decoder" ++eac3_encoder_select="mdct ac3dsp" + eamad_decoder_select="aandct" + eatgq_decoder_select="aandct" + eatqi_decoder_select="aandct" +@@ -1227,6 +1405,8 @@ + flac_encoder_select="golomb lpc" + flashsv_decoder_select="zlib" + flashsv_encoder_select="zlib" ++flashsv2_encoder_select="zlib" ++flashsv2_decoder_select="zlib" + flv_decoder_select="h263_decoder" + flv_encoder_select="h263_encoder" + fraps_decoder_select="huffman" +@@ -1236,56 +1416,70 @@ + h263_vaapi_hwaccel_select="vaapi h263_decoder" + h263i_decoder_select="h263_decoder" + h263p_encoder_select="h263_encoder" +-h264_decoder_select="golomb h264dsp h264pred" ++h264_crystalhd_decoder_select="crystalhd h264_mp4toannexb_bsf h264_parser" ++h264_decoder_select="golomb h264chroma h264dsp h264pred" + h264_dxva2_hwaccel_deps="dxva2api_h" + h264_dxva2_hwaccel_select="dxva2 h264_decoder" +-h264_vaapi_hwaccel_select="vaapi" ++h264_vaapi_hwaccel_select="vaapi h264_decoder" ++h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" ++h264_vda_hwaccel_select="vda h264_decoder" + h264_vdpau_decoder_select="vdpau h264_decoder" +-imc_decoder_select="fft mdct" ++imc_decoder_select="fft mdct sinewin" + jpegls_decoder_select="golomb" + jpegls_encoder_select="golomb" + ljpeg_encoder_select="aandct" + loco_decoder_select="golomb" + mjpeg_encoder_select="aandct" + mlp_decoder_select="mlp_parser" +-mp1float_decoder_select="dct" +-mp2float_decoder_select="dct" +-mp3adufloat_decoder_select="dct" +-mp3float_decoder_select="dct" +-mp3on4float_decoder_select="dct" +-mpeg1video_encoder_select="aandct" +-mpeg2video_encoder_select="aandct" +-mpeg4_decoder_select="h263_decoder mpeg4video_parser" +-mpeg4_encoder_select="h263_encoder" ++mp1_decoder_select="mpegaudiodsp" ++mp1float_decoder_select="mpegaudiodsp" ++mp2_decoder_select="mpegaudiodsp" ++mp2float_decoder_select="mpegaudiodsp" ++mp3_decoder_select="mpegaudiodsp" ++mp3adu_decoder_select="mpegaudiodsp" ++mp3adufloat_decoder_select="mpegaudiodsp" ++mp3float_decoder_select="mpegaudiodsp" ++mp3on4_decoder_select="mpegaudiodsp" ++mp3on4float_decoder_select="mpegaudiodsp" ++mpc7_decoder_select="mpegaudiodsp" ++mpc8_decoder_select="mpegaudiodsp" + mpeg_vdpau_decoder_select="vdpau mpegvideo_decoder" ++mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" ++mpeg_xvmc_decoder_select="mpegvideo_decoder" + mpeg1_vdpau_decoder_select="vdpau mpeg1video_decoder" ++mpeg1_vdpau_hwaccel_select="vdpau mpeg1video_decoder" ++mpeg1video_encoder_select="aandct" ++mpeg2_crystalhd_decoder_select="crystalhd" + mpeg2_dxva2_hwaccel_deps="dxva2api_h" + mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder" ++mpeg2_vdpau_hwaccel_select="vdpau mpeg2video_decoder" + mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder" ++mpeg2video_encoder_select="aandct" ++mpeg4_crystalhd_decoder_select="crystalhd" ++mpeg4_decoder_select="h263_decoder mpeg4video_parser" ++mpeg4_encoder_select="h263_encoder" + mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" +-mpeg4_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h vdpau_mpeg4_support" + mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder" +-mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" +-mpeg_xvmc_decoder_select="mpegvideo_decoder" ++msmpeg4_crystalhd_decoder_select="crystalhd" + msmpeg4v1_decoder_select="h263_decoder" + msmpeg4v1_encoder_select="h263_encoder" + msmpeg4v2_decoder_select="h263_decoder" + msmpeg4v2_encoder_select="h263_encoder" + msmpeg4v3_decoder_select="h263_decoder" + msmpeg4v3_encoder_select="h263_encoder" +-nellymoser_decoder_select="mdct" +-nellymoser_encoder_select="mdct" ++nellymoser_decoder_select="mdct sinewin" ++nellymoser_encoder_select="mdct sinewin" + png_decoder_select="zlib" + png_encoder_select="zlib" + qcelp_decoder_select="lsp" +-qdm2_decoder_select="mdct rdft" ++qdm2_decoder_select="mdct rdft mpegaudiodsp" + ra_144_encoder_select="lpc" + rv10_decoder_select="h263_decoder" + rv10_encoder_select="h263_encoder" + rv20_decoder_select="h263_decoder" + rv20_encoder_select="h263_encoder" +-rv30_decoder_select="golomb h264pred" +-rv40_decoder_select="golomb h264pred" ++rv30_decoder_select="golomb h264chroma h264pred" ++rv40_decoder_select="golomb h264chroma h264pred" + shorten_decoder_select="golomb" + sipr_decoder_select="lsp" + snow_decoder_select="dwt" +@@ -1294,51 +1488,59 @@ + sonic_encoder_select="golomb" + sonic_ls_encoder_select="golomb" + svq1_encoder_select="aandct" +-svq3_decoder_select="golomb h264dsp h264pred" ++svq3_decoder_select="golomb h264chroma h264dsp h264pred" + svq3_decoder_suggest="zlib" + theora_decoder_select="vp3_decoder" + tiff_decoder_suggest="zlib" + tiff_encoder_suggest="zlib" + truehd_decoder_select="mlp_decoder" + tscc_decoder_select="zlib" +-twinvq_decoder_select="mdct lsp" +-vc1_decoder_select="h263_decoder" +-vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex" ++twinvq_decoder_select="mdct lsp sinewin" ++vc1_crystalhd_decoder_select="crystalhd" ++vc1_decoder_select="h263_decoder h264chroma" ++vc1_dxva2_hwaccel_deps="dxva2api_h" + vc1_dxva2_hwaccel_select="dxva2 vc1_decoder" + vc1_vaapi_hwaccel_select="vaapi vc1_decoder" + vc1_vdpau_decoder_select="vdpau vc1_decoder" ++vc1image_decoder_select="vc1_decoder" + vorbis_decoder_select="mdct" + vorbis_encoder_select="mdct" + vp6_decoder_select="huffman" + vp6a_decoder_select="vp6_decoder" + vp6f_decoder_select="vp6_decoder" + vp8_decoder_select="h264pred" +-wmapro_decoder_select="mdct" +-wmav1_decoder_select="mdct" +-wmav1_encoder_select="mdct" +-wmav2_decoder_select="mdct" +-wmav2_encoder_select="mdct" +-wmavoice_decoder_select="lsp rdft dct mdct" ++wmapro_decoder_select="mdct sinewin" ++wmav1_decoder_select="mdct sinewin" ++wmav1_encoder_select="mdct sinewin" ++wmav2_decoder_select="mdct sinewin" ++wmav2_encoder_select="mdct sinewin" ++wmavoice_decoder_select="lsp rdft dct mdct sinewin" + wmv1_decoder_select="h263_decoder" + wmv1_encoder_select="h263_encoder" + wmv2_decoder_select="h263_decoder" + wmv2_encoder_select="h263_encoder" + wmv3_decoder_select="vc1_decoder" ++wmv3_crystalhd_decoder_select="crystalhd" + wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel" + wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel" + wmv3_vdpau_decoder_select="vc1_vdpau_decoder" ++wmv3image_decoder_select="wmv3_decoder" + zlib_decoder_select="zlib" + zlib_encoder_select="zlib" + zmbv_decoder_select="zlib" + zmbv_encoder_select="zlib" + ++crystalhd_deps="libcrystalhd_libcrystalhd_if_h" + vaapi_deps="va_va_h" ++vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" + vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" + + # parsers +-h264_parser_select="golomb h264dsp h264pred" ++h264_parser_select="golomb h264chroma h264dsp h264pred" + + # external libraries ++libaacplus_encoder_deps="libaacplus" ++libcelt_decoder_deps="libcelt" + libdirac_decoder_deps="libdirac !libschroedinger" + libdirac_encoder_deps="libdirac" + libfaac_encoder_deps="libfaac" +@@ -1346,21 +1548,29 @@ + libgsm_encoder_deps="libgsm" + libgsm_ms_decoder_deps="libgsm" + libgsm_ms_encoder_deps="libgsm" ++libmodplug_demuxer_deps="libmodplug" + libmp3lame_encoder_deps="libmp3lame" + libopencore_amrnb_decoder_deps="libopencore_amrnb" + libopencore_amrnb_encoder_deps="libopencore_amrnb" + libopencore_amrwb_decoder_deps="libopencore_amrwb" + libopenjpeg_decoder_deps="libopenjpeg" ++libopenjpeg_encoder_deps="libopenjpeg" + libschroedinger_decoder_deps="libschroedinger" + libschroedinger_encoder_deps="libschroedinger" + libspeex_decoder_deps="libspeex" ++libspeex_encoder_deps="libspeex" ++libstagefright_h264_decoder_deps="libstagefright_h264" + libtheora_encoder_deps="libtheora" ++libvo_aacenc_encoder_deps="libvo_aacenc" ++libvo_amrwbenc_encoder_deps="libvo_amrwbenc" + libvorbis_encoder_deps="libvorbis" + libvpx_decoder_deps="libvpx" + libvpx_encoder_deps="libvpx" + libx264_encoder_deps="libx264" ++libx264rgb_encoder_deps="libx264" + libxavs_encoder_deps="libxavs" + libxvid_encoder_deps="libxvid" ++libutvideo_decoder_deps="libutvideo gpl" + + # demuxers / muxers + ac3_demuxer_select="ac3_parser" +@@ -1397,11 +1607,22 @@ + alsa_indev_deps="alsa_asoundlib_h snd_pcm_htimestamp" + alsa_outdev_deps="alsa_asoundlib_h" + bktr_indev_deps_any="dev_bktr_ioctl_bt848_h machine_ioctl_bt848_h dev_video_bktr_ioctl_bt848_h dev_ic_bt8xx_h" ++dshow_indev_deps="IBaseFilter" ++dshow_indev_extralibs="-lpsapi -lole32 -lstrmiids -luuid" + dv1394_indev_deps="dv1394 dv_demuxer" +-jack_indev_deps="jack_jack_h" ++fbdev_indev_deps="linux_fb_h" ++jack_indev_deps="jack_jack_h sem_timedwait" ++lavfi_indev_deps="avfilter" ++libcdio_indev_deps="libcdio" + libdc1394_indev_deps="libdc1394" ++libv4l2_indev_deps="libv4l2" ++openal_indev_deps="openal" + oss_indev_deps_any="soundcard_h sys_soundcard_h" + oss_outdev_deps_any="soundcard_h sys_soundcard_h" ++pulse_indev_deps="libpulse" ++sdl_outdev_deps="sdl" ++sndio_indev_deps="sndio_h" ++sndio_outdev_deps="sndio_h" + v4l_indev_deps="linux_videodev_h" + v4l2_indev_deps_any="linux_videodev2_h sys_videoio_h" + vfwcap_indev_deps="capCreateCaptureWindow vfwcap_defines" +@@ -1411,37 +1632,54 @@ + + # protocols + gopher_protocol_deps="network" ++httpproxy_protocol_deps="network" ++httpproxy_protocol_select="tcp_protocol" + http_protocol_deps="network" + http_protocol_select="tcp_protocol" ++https_protocol_select="tls_protocol" + mmsh_protocol_select="http_protocol" + mmst_protocol_deps="network" + rtmp_protocol_select="tcp_protocol" + rtp_protocol_select="udp_protocol" + tcp_protocol_deps="network" ++tls_protocol_deps_any="openssl gnutls" ++tls_protocol_select="tcp_protocol" + udp_protocol_deps="network" + + # filters ++amovie_filter_deps="avcodec avformat" ++ass_filter_deps="libass" + blackframe_filter_deps="gpl" ++boxblur_filter_deps="gpl" + cropdetect_filter_deps="gpl" +-frei0r_filter_deps="frei0r dlopen strtok_r" +-frei0r_src_filter_deps="frei0r dlopen strtok_r" ++delogo_filter_deps="gpl" ++drawtext_filter_deps="libfreetype" ++frei0r_filter_deps="frei0r dlopen" ++frei0r_src_filter_deps="frei0r dlopen" + hqdn3d_filter_deps="gpl" +-scale_filter_deps="swscale" ++movie_filter_deps="avcodec avformat" ++mp_filter_deps="gpl avcodec" ++mptestsrc_filter_deps="gpl" ++negate_filter_deps="lut_filter" + ocv_filter_deps="libopencv" ++pan_filter_deps="swresample" ++scale_filter_deps="swscale" ++tinterlace_filter_deps="gpl" + yadif_filter_deps="gpl" + + # libraries + avdevice_deps="avcodec avformat" + avformat_deps="avcodec" ++postproc_deps="gpl" + + # programs +-ffmpeg_deps="avcodec avformat swscale" +-ffmpeg_select="buffer_filter" + ffplay_deps="avcodec avformat swscale sdl" +-ffplay_select="rdft" ++ffplay_select="buffersink_filter rdft" + ffprobe_deps="avcodec avformat" +-ffserver_deps="avformat ffm_muxer rtp_protocol rtsp_demuxer" ++ffserver_deps="avformat ffm_muxer fork rtp_protocol rtsp_demuxer" + ffserver_extralibs='$ldl' ++ffmpeg_deps="avcodec avformat swscale swresample" ++ffmpeg_select="buffersink_filter" + + doc_deps="texi2html" + +@@ -1455,18 +1693,15 @@ + dep=${v%=*} + tests=${v#*=} + for name in ${tests}; do +- eval ${name}_test_deps="'${dep}$suf1 ${dep}$suf2'" ++ append ${name}_test_deps ${dep}$suf1 ${dep}$suf2 + done + done + } + +-set_ne_test_deps(){ +- eval ${1}_be_test_deps="bigendian" +- eval ${1}_le_test_deps="!bigendian" +-} ++mxf_d10_test_deps="avfilter" ++seek_lavf_mxf_d10_test_deps="mxf_d10_test" + + test_deps _encoder _decoder \ +- adpcm_g726=g726 \ + adpcm_ima_qt \ + adpcm_ima_wav \ + adpcm_ms \ +@@ -1477,11 +1712,12 @@ + asv2 \ + bmp \ + dnxhd="dnxhd_1080i dnxhd_720p dnxhd_720p_rd" \ +- dvvideo="dv dv50" \ ++ dvvideo="dv dv_411 dv50" \ + ffv1 \ + flac \ + flashsv \ + flv \ ++ adpcm_g726=g726 \ + gif \ + h261 \ + h263="h263 h263p" \ +@@ -1490,8 +1726,10 @@ + mjpeg="jpg mjpeg ljpeg" \ + mp2 \ + mpeg1video="mpeg mpeg1b" \ +- mpeg2video="mpeg2 mpeg2thread" \ +- mpeg4="mpeg4 mpeg4adv mpeg4nr mpeg4thread error rc" \ ++ mpeg2video="mpeg2 mpeg2_422 mpeg2_idct_int mpeg2_ilace mpeg2_ivlc_qprd" \ ++ mpeg2video="mpeg2thread mpeg2thread_ilace" \ ++ mpeg4="mpeg4 mpeg4_adap mpeg4_qpel mpeg4_qprd mpeg4adv mpeg4nr" \ ++ mpeg4="mpeg4thread error rc" \ + msmpeg4v3=msmpeg4 \ + msmpeg4v2 \ + pbm=pbmpipe \ +@@ -1527,7 +1765,7 @@ + mmf \ + mov \ + pcm_mulaw=mulaw \ +- mxf \ ++ mxf="mxf mxf_d10" \ + nut \ + ogg \ + rawvideo=pixfmt \ +@@ -1541,15 +1779,6 @@ + ac3_fixed_test_deps="ac3_fixed_encoder ac3_decoder rm_muxer rm_demuxer" + mpg_test_deps="mpeg1system_muxer mpegps_demuxer" + +-set_ne_test_deps pixdesc +-set_ne_test_deps pixfmts_copy +-set_ne_test_deps pixfmts_crop +-set_ne_test_deps pixfmts_hflip +-set_ne_test_deps pixfmts_null +-set_ne_test_deps pixfmts_pad +-set_ne_test_deps pixfmts_scale +-set_ne_test_deps pixfmts_vflip +- + # default parameters + + logfile="config.log" +@@ -1562,21 +1791,25 @@ + libdir_default='${prefix}/lib' + mandir_default='${prefix}/share/man' + shlibdir_default="$libdir_default" ++postproc_version_default="current" + + # toolchain + ar_default="ar" + cc_default="gcc" ++cxx_default="g++" + cc_version=\"unknown\" + host_cc_default="gcc" ++install="install" + ln_s="ln -sf" + nm_default="nm" + objformat="elf" ++pkg_config_default=pkg-config + ranlib="ranlib" + strip_default="strip" +-yasmexe="yasm" +-nogas=":" ++yasmexe_default="yasm" + + nm_opts='-g' ++nogas=":" + + # machine + arch_default=$(uname -m) +@@ -1586,28 +1819,33 @@ + target_os_default=$(tolower $(uname -s)) + host_os=$target_os_default + ++# alternative libpostproc version ++ALT_PP_VER_MAJOR=51 ++ALT_PP_VER_MINOR=2 ++ALT_PP_VER_MICRO=101 ++ALT_PP_VER=$ALT_PP_VER_MAJOR.$ALT_PP_VER_MINOR.$ALT_PP_VER_MICRO ++ + # configurable options ++enable $PROGRAM_LIST ++ + enable avcodec +-enable avcore + enable avdevice + enable avfilter + enable avformat + enable avutil ++enable postproc ++enable stripping ++enable swresample ++enable swscale ++ + enable asm + enable debug + enable doc + enable fastdiv +-enable ffmpeg +-enable ffplay +-enable ffprobe +-enable ffserver +-enable mpegaudio_hp + enable network + enable optimizations +-enable protocols ++enable safe_bitstream_reader + enable static +-enable stripping +-enable swscale + enable swscale_alpha + + # build settings +@@ -1623,10 +1861,14 @@ + SLIBNAME_WITH_VERSION='$(SLIBNAME).$(LIBVERSION)' + SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)' + LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"' ++SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)' ++SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)' + ++AS_O='-o $@' + CC_O='-o $@' ++CXX_O='-o $@' + +-host_cflags='-D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 -O3 -g -Wall' ++host_cflags='-D_ISOC99_SOURCE -O3 -g' + host_libs='-lm' + + target_path='$(CURDIR)' +@@ -1637,13 +1879,10 @@ + DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -MM' + + # find source path +-source_path="$(dirname "$0")" +-enable source_path_used + if test -f configure; then +- source_path="$(pwd)" +- disable source_path_used ++ source_path=. + else +- source_path="$(cd "$source_path"; pwd)" ++ source_path=$(cd $(dirname "$0"); pwd) + echo "$source_path" | grep -q '[[:blank:]]' && + die "Out of tree builds are impossible with whitespace in source path." + test -e "$source_path/config.h" && +@@ -1676,6 +1915,20 @@ + PROTOCOL_LIST=$(find_things protocol PROTOCOL libavformat/allformats.c) + FILTER_LIST=$(find_things filter FILTER libavfilter/allfilters.c) + ++ALL_COMPONENTS=" ++ $BSF_LIST ++ $DECODER_LIST ++ $DEMUXER_LIST ++ $ENCODER_LIST ++ $FILTER_LIST ++ $HWACCEL_LIST ++ $INDEV_LIST ++ $MUXER_LIST ++ $OUTDEV_LIST ++ $PARSER_LIST ++ $PROTOCOL_LIST ++" ++ + find_tests(){ + map "echo ${2}\${v}_test" $(ls "$source_path"/tests/ref/$1 | grep -v '[^-a-z0-9_]') + } +@@ -1686,6 +1939,8 @@ + LAVFI_TESTS=$(find_tests lavfi) + SEEK_TESTS=$(find_tests seek seek_) + ++ALL_TESTS="$ACODEC_TESTS $VCODEC_TESTS $LAVF_TESTS $LAVFI_TESTS $SEEK_TESTS" ++ + pcm_test_deps=$(map 'echo ${v%_*}_decoder $v' $(filter pcm_* $ENCODER_LIST)) + + for n in $COMPONENT_LIST; do +@@ -1694,7 +1949,7 @@ + eval ${n}_if_any="\$$v" + done + +-enable $ARCH_EXT_LIST $ACODEC_TESTS $VCODEC_TESTS $LAVF_TESTS $LAVFI_TESTS $SEEK_TESTS ++enable $ARCH_EXT_LIST $ALL_TESTS + + die_unknown(){ + echo "Unknown option \"$1\"." +@@ -1776,23 +2031,40 @@ + die "Must specify target arch and OS when cross-compiling" + fi + +-set_default arch target_os ++set_default arch target_os postproc_version ++ ++# Check if we should build alternative libpostproc version instead of current ++if test "$postproc_version" = $ALT_PP_VER; then ++ LIBPOSTPROC_VERSION=$ALT_PP_VER ++ LIBPOSTPROC_VERSION_MAJOR=$ALT_PP_VER_MAJOR ++ LIBPOSTPROC_VERSION_MINOR=$ALT_PP_VER_MINOR ++ LIBPOSTPROC_VERSION_MICRO=$ALT_PP_VER_MICRO ++elif test "$postproc_version" != current; then ++ die "Invalid argument to --postproc-version. See --help output." ++fi + + ar_default="${cross_prefix}${ar_default}" + cc_default="${cross_prefix}${cc_default}" ++cxx_default="${cross_prefix}${cxx_default}" + nm_default="${cross_prefix}${nm_default}" ++pkg_config_default="${cross_prefix}${pkg_config_default}" + ranlib="${cross_prefix}${ranlib}" + strip_default="${cross_prefix}${strip_default}" + + sysinclude_default="${sysroot}/usr/include" + +-set_default cc nm strip sysinclude ++set_default cc cxx nm pkg_config strip sysinclude yasmexe + enabled cross_compile || host_cc_default=$cc + set_default host_cc + ++if ! $pkg_config --version >/dev/null 2>&1; then ++ warn "$pkg_config not found, library detection may fail." ++ pkg_config=false ++fi ++ + exesuf() { + case $1 in +- mingw32*|cygwin*|*-dos|freedos|opendos|os/2*) echo .exe ;; ++ mingw32*|cygwin*|*-dos|freedos|opendos|os/2*|symbian) echo .exe ;; + esac + } + +@@ -1822,14 +2094,15 @@ + + trap 'rm -f -- $TMPFILES' EXIT + +-tmpfile TMPC .c +-tmpfile TMPE $EXESUF +-tmpfile TMPH .h +-tmpfile TMPO .o +-tmpfile TMPS .S +-tmpfile TMPV .ver +-tmpfile TMPSH .sh + tmpfile TMPASM .asm ++tmpfile TMPC .c ++tmpfile TMPCPP .cpp ++tmpfile TMPE $EXESUF ++tmpfile TMPH .h ++tmpfile TMPO .o ++tmpfile TMPS .S ++tmpfile TMPSH .sh ++tmpfile TMPV .ver + + unset -f mktemp + +@@ -1848,9 +2121,9 @@ + die "Sanity test failed." + fi + ++filter_asflags=echo + filter_cflags=echo + filter_cppflags=echo +-filter_asflags=echo + + if $cc -v 2>&1 | grep -q '^gcc.*LLVM'; then + cc_type=llvm_gcc +@@ -1864,8 +2137,11 @@ + elif $cc -v 2>&1 | grep -qi ^gcc; then + cc_type=gcc + cc_version=__VERSION__ +- gcc_extra_ver=$(expr "$($cc --version | head -n1)" : '.*\((.*)\)') +- cc_ident="gcc $($cc -dumpversion) $gcc_extra_ver" ++ gcc_version=$($cc --version | head -n1) ++ gcc_basever=$($cc -dumpversion) ++ gcc_pkg_ver=$(expr "$gcc_version" : '[^ ]* \(([^)]*)\)') ++ gcc_ext_ver=$(expr "$gcc_version" : ".*$gcc_pkg_ver $gcc_basever \\(.*\\)") ++ cc_ident=$(cleanws "gcc $gcc_basever $gcc_pkg_ver $gcc_ext_ver") + if ! $cc -dumpversion | grep -q '^2\.'; then + CC_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' + AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' +@@ -1971,6 +2247,7 @@ + cc_ident=$($cc -V 2>&1 | head -n1 | cut -d' ' -f 2-) + DEPEND_CMD='$(DEPCC) $(DEPFLAGS) $< | sed -e "1s,^.*: ,$@: ," -e "\$$!s,\$$, \\\," -e "1!s,^.*: , ," > $(@:.o=.d)' + DEPFLAGS='$(CPPFLAGS) $(CFLAGS) -xM1' ++ add_ldflags -xc99 + speed_cflags='-O5' + size_cflags='-O5 -xspace' + filter_cflags=suncc_flags +@@ -2015,6 +2292,7 @@ + AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' + speed_cflags='-O2' + size_cflags='-Os' ++ filter_cflags='filter_out -Wdisabled-optimization' + elif $cc -v 2>&1 | grep -q Open64; then + cc_type=open64 + cc_version=__OPEN64__ +@@ -2023,6 +2301,7 @@ + AS_DEPFLAGS='-MMD -MF $(@:.o=.d) -MT $@' + speed_cflags='-O2' + size_cflags='-Os' ++ filter_cflags='filter_out -Wdisabled-optimization|-Wtype-limits|-fno-signed-zeros' + fi + + test -n "$cc_type" && enable $cc_type || +@@ -2034,14 +2313,16 @@ + set_default ar as dep_cc ld + + test -n "$CC_DEPFLAGS" || CCDEP=$DEPEND_CMD ++test -n "$CXX_DEPFLAGS" || CXXDEP=$DEPEND_CMD + test -n "$AS_DEPFLAGS" || ASDEP=$DEPEND_CMD + + add_cflags $extra_cflags ++add_cxxflags $extra_cxxflags + add_asflags $extra_cflags + + if test -n "$sysroot"; then + case "$cc_type" in +- gcc|llvm_gcc) ++ gcc|llvm_gcc|clang) + add_cppflags --sysroot="$sysroot" + add_ldflags --sysroot="$sysroot" + ;; +@@ -2049,10 +2330,6 @@ + add_cppflags -I"$sysinclude" + add_ldflags --sysroot="$sysroot" + ;; +- clang) +- add_cppflags -isysroot "$sysroot" +- add_ldflags -isysroot "$sysroot" +- ;; + esac + fi + +@@ -2063,7 +2340,7 @@ + gcc|llvm_gcc) + check_native(){ + $cc $1=native -v -c -o $TMPO $TMPC >$TMPE 2>&1 || return +- sed -n "/$1=/{ ++ sed -n "/cc1.*$1=/{ + s/.*$1=\\([^ ]*\\).*/\\1/ + p + q +@@ -2078,7 +2355,7 @@ + + # Deal with common $arch aliases + case "$arch" in +- arm*) ++ arm*|iPad*) + arch="arm" + ;; + mips|mipsel|IP*) +@@ -2095,13 +2372,9 @@ + arch="parisc" + subarch="parisc64" + ;; +- "Power Macintosh"|ppc|powerpc) ++ "Power Macintosh"|ppc|powerpc|ppc64|powerpc64) + arch="ppc" + ;; +- ppc64|powerpc64) +- arch="ppc" +- subarch="ppc64" +- ;; + s390|s390x) + arch="s390" + ;; +@@ -2112,7 +2385,7 @@ + arch="sparc" + subarch="sparc64" + ;; +- i[3-6]86|i86pc|BePC|x86pc|x86_64|amd64) ++ i[3-6]86|i86pc|BePC|x86pc|x86_64|x86_32|amd64) + arch="x86" + ;; + esac +@@ -2178,7 +2451,7 @@ + disable cmov + ;; + # targets that do support conditional mov (cmov) +- i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64|k8|opteron|athlon-fx|core2|amdfam10|barcelona|atom) ++ i686|pentiumpro|pentium[23]|pentium-m|athlon|athlon-tbird|athlon-4|athlon-[mx]p|athlon64*|k8*|opteron*|athlon-fx|core2|amdfam10|barcelona|atom) + cpuflags="-march=$cpu" + enable cmov + enable fast_cmov +@@ -2215,7 +2488,7 @@ + case $cpu in + cortex-a*) subarch=armv7a ;; + cortex-r*) subarch=armv7r ;; +- cortex-m*) subarch=armv7m ;; ++ cortex-m*) enable thumb; subarch=armv7m ;; + arm11*) subarch=armv6 ;; + arm[79]*e*|arm9[24]6*|arm96*|arm102[26]) subarch=armv5te ;; + armv4*|arm7*|arm9[24]*) subarch=armv4 ;; +@@ -2274,7 +2547,8 @@ + die "C compiler test failed." + fi + +-add_cppflags -D_ISOC99_SOURCE -D_POSIX_C_SOURCE=200112 ++add_cppflags -D_ISOC99_SOURCE ++add_cxxflags -D__STDC_CONSTANT_MACROS + check_cflags -std=c99 + check_cc -D_FILE_OFFSET_BITS=64 < +@@ -2284,6 +2558,7 @@ + EOF + + check_host_cflags -std=c99 ++check_host_cflags -Wall + + case "$arch" in + alpha|ia64|mips|parisc|sparc) +@@ -2298,6 +2573,11 @@ + spic=$shared + fi + ;; ++ ppc) ++ check_cc < mapfile && add_ldflags -Wl,-M,mapfile + nm_opts='-P -g' + ;; + netbsd) + disable symver + oss_indev_extralibs="-lossaudio" + oss_outdev_extralibs="-lossaudio" +- add_cppflags -D_XOPEN_SOURCE=600 + ;; + openbsd) + enable malloc_aligned +@@ -2351,7 +2637,8 @@ + enable malloc_aligned + gas="gas-preprocessor.pl $cc" + enabled ppc && add_asflags -force_cpusubtype_ALL +- SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR) -Wl,-read_only_relocs,suppress' ++ SHFLAGS='-dynamiclib -Wl,-single_module -Wl,-install_name,$(SHLIBDIR)/$(SLIBNAME),-current_version,$(LIBVERSION),-compatibility_version,$(LIBMAJOR)' ++ enabled x86_32 && append SHFLAGS -Wl,-read_only_relocs,suppress + strip="${strip} -x" + add_ldflags -Wl,-dynamic,-search_paths_first + SLIBSUF=".dylib" +@@ -2374,20 +2661,18 @@ + enable malloc_aligned + LIBTARGET=x64 + elif enabled arm; then +- LIBTARGET=arm ++ LIBTARGET=arm-wince + fi + shlibdir_default="$bindir_default" +- disable ffserver + SLIBPREF="" + SLIBSUF=".dll" + SLIBNAME_WITH_VERSION='$(SLIBPREF)$(FULLNAME)-$(LIBVERSION)$(SLIBSUF)' + SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)' +- SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)' +- SLIB_INSTALL_EXTRA_CMD='-install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"; \ +- install -m 644 $(SUBDIR)$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib) "$(SHLIBDIR)/$(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.lib)"; \ +- install -d "$(LIBDIR)"; \ +- install -m 644 $(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) "$(LIBDIR)/lib$(SLIBNAME:$(SLIBSUF)=.dll.a)"' +- SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(SHLIBDIR)/$(SLIBNAME:$(SLIBSUF)=.lib)"' ++ SLIB_EXTRA_CMD='-lib.exe /machine:$(LIBTARGET) /def:$$(@:$(SLIBSUF)=.def) /out:$(SUBDIR)$(SLIBNAME:$(SLIBSUF)=.lib)' ++ SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)' ++ SLIB_INSTALL_LINKS= ++ SLIB_INSTALL_EXTRA_SHLIB='$(SLIBNAME:$(SLIBSUF)=.lib)' ++ SLIB_INSTALL_EXTRA_LIB='lib$(SLIBNAME:$(SLIBSUF)=.dll.a) $(SLIBNAME_WITH_MAJOR:$(SLIBSUF)=.def)' + SHFLAGS='-shared -Wl,--output-def,$$(@:$(SLIBSUF)=.def) -Wl,--out-implib,$(SUBDIR)lib$(SLIBNAME:$(SLIBSUF)=.dll.a) -Wl,--enable-runtime-pseudo-reloc -Wl,--enable-auto-image-base' + objformat="win32" + enable dos_paths +@@ -2395,6 +2680,7 @@ + check_cpp_condition _mingw.h "defined (__MINGW64_VERSION_MAJOR) || (__MINGW32_MAJOR_VERSION > 3) \ + || (__MINGW32_MAJOR_VERSION == 3 && __MINGW32_MINOR_VERSION >= 15)" || + die "ERROR: MinGW runtime version must be >= 3.15." ++ add_cppflags -U__STRICT_ANSI__ + ;; + cygwin*) + target_os=cygwin +@@ -2407,15 +2693,16 @@ + objformat="win32" + enable dos_paths + check_cflags -fno-common ++ add_cppflags -U__STRICT_ANSI__ + ;; + *-dos|freedos|opendos) +- disable ffplay ffserver +- disable $INDEV_LIST $OUTDEV_LIST + network_extralibs="-lsocket" + objformat="coff" + enable dos_paths ++ add_cppflags -U__STRICT_ANSI__ + ;; + linux) ++ add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 + enable dv1394 + ;; + irix*) +@@ -2423,8 +2710,10 @@ + ranlib="echo ignoring ranlib" + ;; + os/2*) +- strip="lxlite" ++ strip="lxlite -CS" + ln_s="cp -f" ++ objformat="aout" ++ add_cppflags -D_GNU_SOURCE + add_ldflags -Zomf -Zbin-files -Zargs-wild -Zmap + SHFLAGS='$(SUBDIR)$(NAME).def -Zdll -Zomf' + FFSERVERLDFLAGS="" +@@ -2441,18 +2730,32 @@ + emxexp -o $(OBJS) >> $(SUBDIR)$(NAME).def' + SLIB_EXTRA_CMD='emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(NAME).def; \ + emximp -o $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib $(SUBDIR)$(NAME).def;' +- SLIB_INSTALL_EXTRA_CMD='install -m 644 $(SUBDIR)$(LIBPREF)$(NAME)_dll.a $(SUBDIR)$(LIBPREF)$(NAME)_dll.lib "$(LIBDIR)"' +- SLIB_UNINSTALL_EXTRA_CMD='rm -f "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.a "$(LIBDIR)"/$(LIBPREF)$(NAME)_dll.lib' ++ SLIB_INSTALL_EXTRA_LIB='$(LIBPREF)$(NAME)_dll.a $(LIBPREF)$(NAME)_dll.lib' + enable dos_paths ++ enable_weak os2threads + ;; + gnu/kfreebsd) ++ add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 -D_BSD_SOURCE + ;; + gnu) ++ add_cppflags -D_POSIX_C_SOURCE=200112 -D_XOPEN_SOURCE=600 + ;; + qnx) + add_cppflags -D_QNX_SOURCE + network_extralibs="-lsocket" + ;; ++ symbian) ++ SLIBSUF=".dll" ++ enable dos_paths ++ add_cflags --include=$sysinclude/gcce/gcce.h -fvisibility=default ++ add_cppflags -D__GCCE__ -D__SYMBIAN32__ -DSYMBIAN_OE_POSIX_SIGNALS ++ add_ldflags -Wl,--target1-abs,--no-undefined \ ++ -Wl,-Ttext,0x80000,-Tdata,0x1000000 -shared \ ++ -Wl,--entry=_E32Startup -Wl,-u,_E32Startup ++ add_extralibs -l:eexe.lib -l:usrt2_2.lib -l:dfpaeabi.dso \ ++ -l:drtaeabi.dso -l:scppnwdl.dso -lsupc++ -lgcc \ ++ -l:libc.dso -l:libm.dso -l:euser.dso -l:libcrt0.lib ++ ;; + none) + ;; + *) +@@ -2477,29 +2780,29 @@ + exit 1; + fi + +-disabled static && LIBNAME="" +- + test -n "$custom_libname_with_major" && SLIBNAME_WITH_MAJOR="$custom_libname_with_major" + + die_license_disabled() { + enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; } + } + ++die_license_disabled gpl libcdio + die_license_disabled gpl libx264 + die_license_disabled gpl libxavs + die_license_disabled gpl libxvid +-die_license_disabled gpl postproc + die_license_disabled gpl x11grab + ++die_license_disabled nonfree libaacplus + die_license_disabled nonfree libfaac ++die_license_disabled nonfree openssl + + die_license_disabled version3 libopencore_amrnb + die_license_disabled version3 libopencore_amrwb ++die_license_disabled version3 libvo_aacenc ++die_license_disabled version3 libvo_amrwbenc + + enabled version3 && { enabled gpl && enable gplv3 || enable lgplv3; } + +-check_deps $ARCH_EXT_LIST +- + disabled optimizations || check_cflags -fomit-frame-pointer + + enable_pic() { +@@ -2547,7 +2850,7 @@ + + elif enabled arm; then + +- check_cflags -marm ++ enabled thumb && check_cflags -mthumb || check_cflags -marm + nogas=die + + if check_cpp_condition stddef.h "defined __ARM_PCS_VFP"; then +@@ -2555,7 +2858,7 @@ + elif ! check_cpp_condition stddef.h "defined __ARM_PCS || defined __SOFTFP__"; then + case "${cross_prefix:-$cc}" in + *hardfloat*) enable vfp_args; fpabi=vfp ;; +- *) check_ld <= 2.0.0" aacplus.h aacplusEncOpen -laacplus ++enabled libass && require_pkg_config libass ass/ass.h ass_library_init ++enabled libcelt && require libcelt celt/celt.h celt_decode -lcelt0 && ++ { check_lib celt/celt.h celt_decoder_create_custom -lcelt0 || ++ die "ERROR: libcelt version must be >= 0.11.0."; } ++enabled libdc1394 && require_pkg_config libdc1394-2 dc1394/dc1394.h dc1394_new ++enabled libdirac && require_pkg_config dirac \ ++ "libdirac_decoder/dirac_parser.h libdirac_encoder/dirac_encoder.h" \ ++ "dirac_decoder_init dirac_encoder_init" + enabled libfaac && require2 libfaac "stdint.h faac.h" faacEncGetVersion -lfaac ++enabled libfreetype && require_pkg_config freetype2 "ft2build.h freetype/freetype.h" FT_Init_FreeType + enabled libgsm && require libgsm gsm/gsm.h gsm_create -lgsm ++enabled libmodplug && require libmodplug libmodplug/modplug.h ModPlug_Load -lmodplug + enabled libmp3lame && require "libmp3lame >= 3.98.3" lame/lame.h lame_set_VBR_quality -lmp3lame + enabled libnut && require libnut libnut.h nut_demuxer_init -lnut + enabled libopencore_amrnb && require libopencore_amrnb opencore-amrnb/interf_dec.h Decoder_Interface_init -lopencore-amrnb + enabled libopencore_amrwb && require libopencore_amrwb opencore-amrwb/dec_if.h D_IF_init -lopencore-amrwb +-enabled libopencv && { check_lib opencv/cv.h cvCreateImageHeader $(pkg-config --libs opencv) || +- die "ERROR: libopencv not found"; } ++enabled libopencv && require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader + enabled libopenjpeg && require libopenjpeg openjpeg.h opj_version -lopenjpeg +-enabled librtmp && { check_lib librtmp/rtmp.h RTMP_Socket $(pkg-config --libs librtmp) || +- die "ERROR: librtmp not found or RTMP_Socket() missing, librtmp version must be >= 2.2.f"; } +-enabled libschroedinger && add_cflags $(pkg-config --cflags schroedinger-1.0) && +- require libschroedinger schroedinger/schro.h schro_init $(pkg-config --libs schroedinger-1.0) ++enabled libpulse && require_pkg_config libpulse-simple pulse/simple.h pa_simple_new ++enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket ++enabled libschroedinger && require_pkg_config schroedinger-1.0 schroedinger/schro.h schro_init + enabled libspeex && require libspeex speex/speex.h speex_decoder_init -lspeex ++enabled libstagefright_h264 && require_cpp libstagefright_h264 "binder/ProcessState.h media/stagefright/MetaData.h ++ media/stagefright/MediaBufferGroup.h media/stagefright/MediaDebug.h media/stagefright/MediaDefs.h ++ media/stagefright/OMXClient.h media/stagefright/OMXCodec.h" android::OMXClient -lstagefright -lmedia -lutils -lbinder + enabled libtheora && require libtheora theora/theoraenc.h th_info_init -ltheoraenc -ltheoradec -logg ++enabled libutvideo && require_cpp utvideo "stdint.h stdlib.h utvideo/utvideo.h utvideo/Codec.h" 'CCodec*' -lutvideo -lstdc++ ++enabled libv4l2 && require_pkg_config libv4l2 libv4l2.h v4l2_ioctl ++enabled libvo_aacenc && require libvo_aacenc vo-aacenc/voAAC.h voGetAACEncAPI -lvo-aacenc ++enabled libvo_amrwbenc && require libvo_amrwbenc vo-amrwbenc/enc_if.h E_IF_init -lvo-amrwbenc + enabled libvorbis && require libvorbis vorbis/vorbisenc.h vorbis_info_init -lvorbisenc -lvorbis -logg + enabled libvpx && { + enabled libvpx_decoder && { check_lib2 "vpx/vpx_decoder.h vpx/vp8dx.h" vpx_codec_dec_init_ver -lvpx || + die "ERROR: libvpx decoder version must be >=0.9.1"; } +- enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" vpx_codec_enc_init_ver -lvpx || +- die "ERROR: libvpx encoder version must be >=0.9.1"; } } ++ enabled libvpx_encoder && { check_lib2 "vpx/vpx_encoder.h vpx/vp8cx.h" "vpx_codec_enc_init_ver VPX_CQ" -lvpx || ++ die "ERROR: libvpx encoder version must be >=0.9.6"; } } + enabled libx264 && require libx264 x264.h x264_encoder_encode -lx264 && +- { check_cpp_condition x264.h "X264_BUILD >= 99" || +- die "ERROR: libx264 version must be >= 0.99."; } ++ { check_cpp_condition x264.h "X264_BUILD >= 118" || ++ die "ERROR: libx264 version must be >= 0.118."; } + enabled libxavs && require libxavs xavs.h xavs_encoder_encode -lxavs + enabled libxvid && require libxvid xvid.h xvid_global -lxvidcore ++enabled openal && { { for al_libs in "${OPENAL_LIBS}" "-lopenal" "-lOpenAL32"; do ++ check_lib 'AL/al.h' alGetError "${al_libs}" && break; done } || ++ die "ERROR: openal not found"; } && ++ { check_cpp_condition "AL/al.h" "defined(AL_VERSION_1_1)" || ++ die "ERROR: openal version must be 1.1 or compatible"; } + enabled mlib && require mediaLib mlib_types.h mlib_VectorSub_S16_U8_Mod -lmlib +- +-# libdc1394 check +-if enabled libdc1394; then +- { check_lib dc1394/dc1394.h dc1394_new -ldc1394 -lraw1394 && +- enable libdc1394_2; } || +- { check_lib libdc1394/dc1394_control.h dc1394_create_handle -ldc1394_control -lraw1394 && +- enable libdc1394_1; } || +- die "ERROR: No version of libdc1394 found " +-fi ++enabled openssl && { check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto || ++ check_lib openssl/ssl.h SSL_library_init -lssl32 -leay32 || ++ check_lib openssl/ssl.h SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 || ++ die "ERROR: openssl not found"; } + + SDL_CONFIG="${cross_prefix}sdl-config" +-if "${SDL_CONFIG}" --version > /dev/null 2>&1; then ++if check_pkg_config sdl SDL_version.h SDL_Linked_Version; then ++ check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags && ++ enable sdl && ++ check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size ++else ++ if "${SDL_CONFIG}" --version > /dev/null 2>&1; then + sdl_cflags=$("${SDL_CONFIG}" --cflags) + sdl_libs=$("${SDL_CONFIG}" --libs) +- check_func_headers SDL.h SDL_Init $sdl_cflags $sdl_libs && ++ check_func_headers SDL_version.h SDL_Linked_Version $sdl_cflags $sdl_libs && + check_cpp_condition SDL.h "(SDL_MAJOR_VERSION<<16 | SDL_MINOR_VERSION<<8 | SDL_PATCHLEVEL) >= 0x010201" $sdl_cflags && + enable sdl && + check_struct SDL.h SDL_VideoInfo current_w $sdl_cflags && enable sdl_video_size ++ fi + fi ++enabled sdl && add_cflags $sdl_cflags && add_extralibs $sdl_libs + + texi2html -version > /dev/null 2>&1 && enable texi2html || disable texi2html ++makeinfo --version > /dev/null 2>&1 && enable makeinfo || disable makeinfo + ++check_header linux/fb.h + check_header linux/videodev.h + check_header linux/videodev2.h ++check_struct linux/videodev2.h "struct v4l2_frmivalenum" discrete ++ + check_header sys/videoio.h + + check_func_headers "windows.h vfw.h" capCreateCaptureWindow "$vfwcap_indev_extralibs" +@@ -2882,6 +3216,8 @@ + # w32api 3.12 had it defined wrong + check_cpp_condition vfw.h "WM_CAP_DRIVER_CONNECT > WM_USER" && enable vfwcap_defines + ++check_type "dshow.h" IBaseFilter ++ + # check for ioctl_meteor.h, ioctl_bt848.h and alternatives + { check_header dev/bktr/ioctl_meteor.h && + check_header dev/bktr/ioctl_bt848.h; } || +@@ -2891,12 +3227,25 @@ + check_header dev/video/bktr/ioctl_bt848.h; } || + check_header dev/ic/bt8xx.h + +-check_header sys/soundcard.h ++check_header sndio.h ++if check_struct sys/soundcard.h audio_buf_info bytes; then ++ enable_safe sys/soundcard.h ++else ++ check_cc -D__BSD_VISIBLE -D__XSI_VISIBLE < ++ audio_buf_info abc; ++EOF ++fi + check_header soundcard.h + + enabled_any alsa_indev alsa_outdev && check_lib2 alsa/asoundlib.h snd_pcm_htimestamp -lasound + +-enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack ++enabled jack_indev && check_lib2 jack/jack.h jack_client_open -ljack && check_func sem_timedwait ++ ++enabled_any sndio_indev sndio_outdev && check_lib2 sndio.h sio_open -lsndio ++ ++enabled libcdio && ++ check_lib2 "cdio/cdda.h cdio/paranoia.h" cdio_cddap_open "-lcdio_paranoia -lcdio_cdda -lcdio" + + enabled x11grab && + check_header X11/Xlib.h && +@@ -2906,6 +3255,13 @@ + check_func XShmCreateImage -lX11 -lXext && + check_func XFixesGetCursorImage -lX11 -lXext -lXfixes + ++if ! disabled vaapi; then ++ check_lib va/va.h vaInitialize -lva && { ++ check_cpp_condition va/va_version.h "VA_CHECK_VERSION(0,32,0)" || ++ warn "Please upgrade to VA-API >= 0.32 if you would like full VA-API support."; ++ } || disable vaapi ++fi ++ + if ! disabled vdpau && enabled vdpau_vdpau_h; then + check_cpp_condition \ + vdpau/vdpau.h "defined VDP_DECODER_PROFILE_MPEG4_PART2_ASP" || +@@ -2914,12 +3270,15 @@ + fi + + enabled debug && add_cflags -g"$debuglevel" && add_asflags -g"$debuglevel" ++enabled coverage && add_cflags "-fprofile-arcs -ftest-coverage" && add_ldflags "-fprofile-arcs -ftest-coverage" ++test -n "$valgrind" && target_exec="$valgrind --error-exitcode=1 --malloc-fill=0x2a --track-origins=yes --leak-check=full --gen-suppressions=all --suppressions=$source_path/tests/fate-valgrind.supp" + + # add some useful compiler flags if supported + check_cflags -Wdeclaration-after-statement + check_cflags -Wall + check_cflags -Wno-parentheses + check_cflags -Wno-switch ++check_cflags -Wno-format-zero-length + check_cflags -Wdisabled-optimization + check_cflags -Wpointer-arith + check_cflags -Wredundant-decls +@@ -2928,14 +3287,14 @@ + check_cflags -Wwrite-strings + check_cflags -Wtype-limits + check_cflags -Wundef +-# some gcc compilers (mingw 4.2.1-sjlj) are b0rk so for now skip this +-# check_cflags -Wmissing-prototypes ++check_cflags -Wmissing-prototypes ++check_cflags -Wno-pointer-to-int-cast ++check_cflags -Wstrict-prototypes + enabled extra_warnings && check_cflags -Winline + + # add some linker flags + check_ldflags -Wl,--warn-common +-check_ldflags -Wl,--as-needed +-check_ldflags '-Wl,-rpath-link,\$(BUILD_ROOT)/libpostproc -Wl,-rpath-link,\$(BUILD_ROOT)/libswscale -Wl,-rpath-link,\$(BUILD_ROOT)/libavfilter -Wl,-rpath-link,\$(BUILD_ROOT)/libavdevice -Wl,-rpath-link,\$(BUILD_ROOT)/libavformat -Wl,-rpath-link,\$(BUILD_ROOT)/libavcodec -Wl,-rpath-link,\$(BUILD_ROOT)/libavcore -Wl,-rpath-link,\$(BUILD_ROOT)/libavutil' ++check_ldflags -Wl,-rpath-link=libpostproc:libswresample:libswscale:libavfilter:libavdevice:libavformat:libavcodec:libavutil + test_ldflags -Wl,-Bsymbolic && append SHFLAGS -Wl,-Bsymbolic + + echo "X{};" > $TMPV +@@ -2951,9 +3310,10 @@ + EOF + fi + +-if enabled small; then ++if [ -n "$optflags" ]; then ++ add_cflags $optflags ++elif enabled small; then + add_cflags $size_cflags +- optimizations="small" + elif enabled optimizations; then + add_cflags $speed_cflags + else +@@ -2961,16 +3321,21 @@ + fi + check_cflags -fno-math-errno + check_cflags -fno-signed-zeros ++check_cc -mno-red-zone <> config.mak + eval echo "${lcname}_VERSION_MAJOR=\$${name}_VERSION_MAJOR" >> config.mak + } + +-get_version LIBSWSCALE libswscale/swscale.h +-get_version LIBPOSTPROC libpostproc/postprocess.h +-get_version LIBAVCODEC libavcodec/avcodec.h +-get_version LIBAVCORE libavcore/avcore.h ++get_version LIBAVCODEC libavcodec/version.h + get_version LIBAVDEVICE libavdevice/avdevice.h ++get_version LIBAVFILTER libavfilter/version.h + get_version LIBAVFORMAT libavformat/version.h + get_version LIBAVUTIL libavutil/avutil.h +-get_version LIBAVFILTER libavfilter/avfilter.h ++get_version LIBPOSTPROC libpostproc/postprocess.h ++get_version LIBSWRESAMPLE libswresample/swresample.h ++get_version LIBSWSCALE libswscale/swscale.h + + cat > $TMPH <>config.mak <> $TMPH <> $TMPH +@@ -3364,6 +3719,7 @@ + libs=$4 + requires=$5 + enabled ${name#lib} || return 0 ++mkdir -p $name + cat < $name/$name.pc + prefix=$prefix + exec_prefix=\${prefix} +@@ -3396,11 +3752,11 @@ + EOF + } + +-pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" +-pkgconfig_generate libavcore "FFmpeg multimedia shared core utilities library" "$LIBAVCORE_VERSION" "" "libavutil = $LIBAVUTIL_VERSION" +-pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavcore = $LIBAVCORE_VERSION" ++pkgconfig_generate libavutil "FFmpeg utility library" "$LIBAVUTIL_VERSION" "$LIBM" ++pkgconfig_generate libavcodec "FFmpeg codec library" "$LIBAVCODEC_VERSION" "$extralibs" "libavutil = $LIBAVUTIL_VERSION" + pkgconfig_generate libavformat "FFmpeg container format library" "$LIBAVFORMAT_VERSION" "$extralibs" "libavcodec = $LIBAVCODEC_VERSION" + pkgconfig_generate libavdevice "FFmpeg device handling library" "$LIBAVDEVICE_VERSION" "$extralibs" "libavformat = $LIBAVFORMAT_VERSION" +-pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" "libavcore = $LIBAVCORE_VERSION" +-pkgconfig_generate libpostproc "FFmpeg post processing library" "$LIBPOSTPROC_VERSION" +-pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "" "libavutil = $LIBAVUTIL_VERSION" ++pkgconfig_generate libavfilter "FFmpeg video filtering library" "$LIBAVFILTER_VERSION" "$extralibs" ++pkgconfig_generate libpostproc "FFmpeg postprocessing library" "$LIBPOSTPROC_VERSION" "" "libavutil = $LIBAVUTIL_VERSION" ++pkgconfig_generate libswscale "FFmpeg image rescaling library" "$LIBSWSCALE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION" ++pkgconfig_generate libswresample "FFmpeg audio rescaling library" "$LIBSWRESAMPLE_VERSION" "$LIBM" "libavutil = $LIBAVUTIL_VERSION" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/APIchanges xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/APIchanges +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/APIchanges 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/APIchanges 2012-05-14 14:08:53.125315649 +0200 +@@ -1,18 +1,558 @@ +-Never assume the API of libav* to be stable unless at least 1 week has passed since +-the last major version increase. ++Never assume the API of libav* to be stable unless at least 1 month has passed ++since the last major version increase. ++ + The last version increases were: +-libavcodec: ? +-libavcore: 2010-07-21 +-libavdevice: ? +-libavfilter: 2009-10-18 +-libavformat: ? +-libpostproc: ? +-libswscale: ? +-libavutil: 2009-03-08 ++libavcodec: 2011-04-18 ++libavdevice: 2011-04-18 ++libavfilter: 2011-04-18 ++libavformat: 2011-04-18 ++libpostproc: 2011-04-18 ++libswscale: 2011-06-20 ++libavutil: 2011-04-18 + + + API changes, most recent first: + ++2012-01-24 - xxxxxxx - lavfi 2.60.100 ++ Add avfilter_graph_dump. ++ ++2012-01-25 - lavf 53.22.0 ++ f1caf01 Allow doing av_write_frame(ctx, NULL) for flushing possible ++ buffered data within a muxer. Added AVFMT_ALLOW_FLUSH for ++ muxers supporting it (av_write_frame makes sure it is called ++ only for muxers with this flag). ++ ++2012-03-04 - xxxxxxx - lavu 51.22.1 - error.h ++ Add AVERROR_UNKNOWN ++ ++2012-02-29 - xxxxxxx - lavf 53.21.0 ++ Add avformat_get_riff_video_tags() and avformat_get_riff_audio_tags(). ++ ++2012-02-29 - xxxxxxx - lavu 51.22.0 - intfloat.h ++ Add a new installed header libavutil/intfloat.h with int/float punning ++ functions. ++ ++2012-02-17 - xxxxxxx - lavc 53.35.0 ++ Add avcodec_is_open() function. ++ ++2012-01-15 - lavc 53.34.0 ++ New audio encoding API: ++ b2c75b6 Add CODEC_CAP_VARIABLE_FRAME_SIZE capability for use by audio ++ encoders. ++ 5ee5fa0 Add avcodec_fill_audio_frame() as a convenience function. ++ b2c75b6 Add avcodec_encode_audio2() and deprecate avcodec_encode_audio(). ++ Add AVCodec.encode2(). ++ ++2012-01-12 - 3167dc9 - lavfi 2.15.0 ++ Add a new installed header -- libavfilter/version.h -- with version macros. ++ ++2011-12-08 - a502939 - lavfi 2.52.0 ++ Add av_buffersink_poll_frame() to buffersink.h. ++ ++2011-12-08 - xxxxxxx - lavu 51.31.0 ++ Add av_log_format_line. ++ ++2011-12-03 - xxxxxxx - lavu 51.30.0 ++ Add AVERROR_BUG. ++ ++2011-xx-xx - xxxxxxx - lavu 51.28.1 ++ Add av_get_alt_sample_fmt() to samplefmt.h. ++ ++2011-11-03 - 96949da - lavu 51.23.0 ++ Add av_strcasecmp() and av_strncasecmp() to avstring.h. ++ ++2011-10-20 - b35e9e1 - lavu 51.22.0 ++ Add av_strtok() to avstring.h. ++ ++2011-01-03 - b73ec05 - lavu 51.21.0 ++ Add av_popcount64 ++ ++2011-12-18 - 8400b12 - lavc 53.28.1 ++ Deprecate AVFrame.age. The field is unused. ++ ++2011-12-12 - 5266045 - lavf 53.17.0 ++ Add avformat_close_input(). ++ Deprecate av_close_input_file() and av_close_input_stream(). ++ ++2011-12-02 - 0eea212 - lavc 53.25.0 ++ Add nb_samples and extended_data fields to AVFrame. ++ Deprecate AVCODEC_MAX_AUDIO_FRAME_SIZE. ++ Deprecate avcodec_decode_audio3() in favor of avcodec_decode_audio4(). ++ avcodec_decode_audio4() writes output samples to an AVFrame, which allows ++ audio decoders to use get_buffer(). ++ ++2011-12-04 - 560f773 - lavc 53.24.0 ++ Change AVFrame.data[4]/base[4]/linesize[4]/error[4] to [8] at next major bump. ++ Change AVPicture.data[4]/linesize[4] to [8] at next major bump. ++ Change AVCodecContext.error[4] to [8] at next major bump. ++ Add AV_NUM_DATA_POINTERS to simplify the bump transition. ++ ++2011-11-23 - bbb46f3 - lavu 51.18.0 ++ Add av_samples_get_buffer_size(), av_samples_fill_arrays(), and ++ av_samples_alloc(), to samplefmt.h. ++ ++2011-11-23 - 8889cc4 - lavu 51.17.0 ++ Add planar sample formats and av_sample_fmt_is_planar() to samplefmt.h. ++ ++2011-11-19 - f3a29b7 - lavc 53.21.0 ++ Move some AVCodecContext fields to a new private struct, AVCodecInternal, ++ which is accessed from a new field, AVCodecContext.internal. ++ - fields moved: ++ AVCodecContext.internal_buffer --> AVCodecInternal.buffer ++ AVCodecContext.internal_buffer_count --> AVCodecInternal.buffer_count ++ AVCodecContext.is_copy --> AVCodecInternal.is_copy ++ ++2011-11-16 - 6270671 - lavu 51.16.0 ++ Add av_timegm() ++ ++2011-11-13 - lavf 53.15.0 ++ New interrupt callback API, allowing per-AVFormatContext/AVIOContext ++ interrupt callbacks. ++ 6aa0b98 Add AVIOInterruptCB struct and the interrupt_callback field to ++ AVFormatContext. ++ 1dee0ac Add avio_open2() with additional parameters. Those are ++ an interrupt callback and an options AVDictionary. ++ This will allow passing AVOptions to protocols after lavf ++ 54.0. ++ ++2011-11-06 - ba04ecf - lavu 51.14.0 ++ Add av_strcasecmp() and av_strncasecmp() to avstring.h. ++ ++2011-11-06 - 07b172f - lavu 51.13.0 ++ Add av_toupper()/av_tolower() ++ ++2011-11-05 - b6d08f4 - lavf 53.13.0 ++ Add avformat_network_init()/avformat_network_uninit() ++ ++2011-10-27 - 512557b - lavc 53.15.0 ++ Remove avcodec_parse_frame. ++ Deprecate AVCodecContext.parse_only and CODEC_CAP_PARSE_ONLY. ++ ++2011-10-19 - 569129a - lavf 53.10.0 ++ Add avformat_new_stream(). Deprecate av_new_stream(). ++ ++2011-10-13 - b631fba - lavf 53.9.0 ++ Add AVFMT_NO_BYTE_SEEK AVInputFormat flag. ++ ++2011-10-12 - lavu 51.12.0 ++ AVOptions API rewrite. ++ ++ - 145f741 FF_OPT_TYPE* renamed to AV_OPT_TYPE_* ++ - new setting/getting functions with slightly different semantics: ++ dac66da av_set_string3 -> av_opt_set ++ av_set_double -> av_opt_set_double ++ av_set_q -> av_opt_set_q ++ av_set_int -> av_opt_set_int ++ ++ 41d9d51 av_get_string -> av_opt_get ++ av_get_double -> av_opt_get_double ++ av_get_q -> av_opt_get_q ++ av_get_int -> av_opt_get_int ++ ++ - 8c5dcaa trivial rename av_next_option -> av_opt_next ++ - 641c7af new functions - av_opt_child_next, av_opt_child_class_next ++ and av_opt_find2() ++ ++2011-09-22 - a70e787 - lavu 51.17.0 ++ Add av_x_if_null(). ++ ++2011-09-18 - 645cebb - lavc 53.16.0 ++ Add showall flag2 ++ ++2011-09-16 - ea8de10 - lavfi 2.42.0 ++ Add avfilter_all_channel_layouts. ++ ++2011-09-16 - 9899037 - lavfi 2.41.0 ++ Rename avfilter_all_* function names to avfilter_make_all_*. ++ ++ In particular, apply the renames: ++ avfilter_all_formats -> avfilter_make_all_formats ++ avfilter_all_channel_layouts -> avfilter_make_all_channel_layouts ++ avfilter_all_packing_formats -> avfilter_make_all_packing_formats ++ ++2011-09-12 - 4381bdd - lavfi 2.40.0 ++ Change AVFilterBufferRefAudioProps.sample_rate type from uint32_t to int. ++ ++2011-09-12 - 2c03174 - lavfi 2.40.0 ++ Simplify signature for avfilter_get_audio_buffer(), make it ++ consistent with avfilter_get_video_buffer(). ++ ++2011-09-06 - 4f7dfe1 - lavfi 2.39.0 ++ Rename libavfilter/vsink_buffer.h to libavfilter/buffersink.h. ++ ++2011-09-06 - c4415f6 - lavfi 2.38.0 ++ Unify video and audio sink API. ++ ++ In particular, add av_buffersink_get_buffer_ref(), deprecate ++ av_vsink_buffer_get_video_buffer_ref() and change the value for the ++ opaque field passed to the abuffersink init function. ++ ++2011-09-04 - 61e2e29 - lavu 51.16.0 ++ Add av_asprintf(). ++ ++2011-08-22 - dacd827 - lavf 53.10.0 ++ Add av_find_program_from_stream(). ++ ++2011-08-20 - 69e2c1a - lavu 51.13.0 ++ Add av_get_media_type_string(). ++ ++2011-09-03 - fb4ca26 - lavc 53.13.0 ++ lavf 53.11.0 ++ lsws 2.1.0 ++ Add {avcodec,avformat,sws}_get_class(). ++ ++2011-08-03 - c11fb82 - lavu 51.15.0 ++ Add AV_OPT_SEARCH_FAKE_OBJ flag for av_opt_find() function. ++ ++2011-08-14 - 323b930 - lavu 51.12.0 ++ Add av_fifo_peek2(), deprecate av_fifo_peek(). ++ ++2011-08-26 - lavu 51.9.0 ++ - add41de..abc78a5 Do not include intfloat_readwrite.h, ++ mathematics.h, rational.h, pixfmt.h, or log.h from avutil.h. ++ ++2011-08-16 - 48f9e45 - lavf 53.8.0 ++ Add avformat_query_codec(). ++ ++2011-08-16 - bca06e7 - lavc 53.11.0 ++ Add avcodec_get_type(). ++ ++2011-08-06 - 2f63440 - lavf 53.7.0 ++ Add error_recognition to AVFormatContext. ++ ++2011-08-02 - 9d39cbf - lavc 53.9.1 ++ Add AV_PKT_FLAG_CORRUPT AVPacket flag. ++ ++2011-07-16 - b57df29 - lavfi 2.27.0 ++ Add audio packing negotiation fields and helper functions. ++ ++ In particular, add AVFilterPacking enum, planar, in_packings and ++ out_packings fields to AVFilterLink, and the functions: ++ avfilter_set_common_packing_formats() ++ avfilter_all_packing_formats() ++ ++2011-07-10 - a67c061 - lavf 53.6.0 ++ Add avformat_find_stream_info(), deprecate av_find_stream_info(). ++ ++2011-07-10 - 0b950fe - lavc 53.8.0 ++ Add avcodec_open2(), deprecate avcodec_open(). ++ ++2011-07-01 - b442ca6 - lavf 53.5.0 - avformat.h ++ Add function av_get_output_timestamp(). ++ ++2011-06-28 - 5129336 - lavu 51.11.0 - avutil.h ++ Define the AV_PICTURE_TYPE_NONE value in AVPictureType enum. ++ ++2011-06-19 - fd2c0a5 - lavfi 2.23.0 - avfilter.h ++ Add layout negotiation fields and helper functions. ++ ++ In particular, add in_chlayouts and out_chlayouts to AVFilterLink, ++ and the functions: ++ avfilter_set_common_sample_formats() ++ avfilter_set_common_channel_layouts() ++ avfilter_all_channel_layouts() ++ ++2011-06-19 - 527ca39 - lavfi 2.22.0 - AVFilterFormats ++ Change type of AVFilterFormats.formats from int * to int64_t *, ++ and update formats handling API accordingly. ++ ++ avfilter_make_format_list() still takes a int32_t array and converts ++ it to int64_t. A new function, avfilter_make_format64_list(), that ++ takes int64_t arrays has been added. ++ ++2011-06-19 - 44f669e - lavfi 2.21.0 - vsink_buffer.h ++ Add video sink buffer and vsink_buffer.h public header. ++ ++2011-06-12 - 9fdf772 - lavfi 2.18.0 - avcodec.h ++ Add avfilter_get_video_buffer_ref_from_frame() function in ++ libavfilter/avcodec.h. ++ ++2011-06-12 - c535494 - lavfi 2.17.0 - avfiltergraph.h ++ Add avfilter_inout_alloc() and avfilter_inout_free() functions. ++ ++2011-06-12 - 6119b23 - lavfi 2.16.0 - avfilter_graph_parse() ++ Change avfilter_graph_parse() signature. ++ ++2011-06-23 - 67e9ae1 - lavu 51.8.0 - attributes.h ++ Add av_printf_format(). ++ ++2011-06-16 - 05e84c9, 25de595 - lavf 53.2.0 - avformat.h ++ Add avformat_open_input and avformat_write_header(). ++ Deprecate av_open_input_stream, av_open_input_file, ++ AVFormatParameters and av_write_header. ++ ++2011-06-16 - 7e83e1c, dc59ec5 - lavu 51.7.0 - opt.h ++ Add av_opt_set_dict() and av_opt_find(). ++ Deprecate av_find_opt(). ++ Add AV_DICT_APPEND flag. ++ ++2011-06-10 - cb7c11c - lavu 51.6.0 - opt.h ++ Add av_opt_flag_is_set(). ++ ++2011-06-10 - c381960 - lavfi 2.15.0 - avfilter_get_audio_buffer_ref_from_arrays ++ Add avfilter_get_audio_buffer_ref_from_arrays() to avfilter.h. ++ ++2011-06-09 - d9f80ea - lavu 51.8.0 - AVMetadata ++ Move AVMetadata from lavf to lavu and rename it to ++ AVDictionary -- new installed header dict.h. ++ All av_metadata_* functions renamed to av_dict_*. ++ ++2011-06-07 - a6703fa - lavu 51.8.0 - av_get_bytes_per_sample() ++ Add av_get_bytes_per_sample() in libavutil/samplefmt.h. ++ Deprecate av_get_bits_per_sample_fmt(). ++ ++2011-06-05 - b39b062 - lavu 51.8.0 - opt.h ++ Add av_opt_free convenience function. ++ ++2011-06-06 - 95a0242 - lavfi 2.14.0 - AVFilterBufferRefAudioProps ++ Remove AVFilterBufferRefAudioProps.size, and use nb_samples in ++ avfilter_get_audio_buffer() and avfilter_default_get_audio_buffer() in ++ place of size. ++ ++2011-06-06 - 0bc2cca - lavu 51.6.0 - av_samples_alloc() ++ Switch nb_channels and nb_samples parameters order in ++ av_samples_alloc(). ++ ++2011-06-06 - e1c7414 - lavu 51.5.0 - av_samples_* ++ Change the data layout created by av_samples_fill_arrays() and ++ av_samples_alloc(). ++ ++2011-06-06 - 27bcf55 - lavfi 2.13.0 - vsrc_buffer.h ++ Make av_vsrc_buffer_add_video_buffer_ref() accepts an additional ++ flags parameter in input. ++ ++2011-06-03 - e977ca2 - lavfi 2.12.0 - avfilter_link_free() ++ Add avfilter_link_free() function. ++ ++2011-06-02 - 5ad38d9 - lavu 51.4.0 - av_force_cpu_flags() ++ Add av_cpu_flags() in libavutil/cpu.h. ++ ++2011-05-28 - e71f260 - lavu 51.3.0 - pixdesc.h ++ Add av_get_pix_fmt_name() in libavutil/pixdesc.h, and deprecate ++ avcodec_get_pix_fmt_name() in libavcodec/avcodec.h in its favor. ++ ++2011-05-25 - 30315a8 - lavf 53.3.0 - avformat.h ++ Add fps_probe_size to AVFormatContext. ++ ++2011-05-22 - 5ecdfd0 - lavf 53.2.0 - avformat.h ++ Introduce avformat_alloc_output_context2() and deprecate ++ avformat_alloc_output_context(). ++ ++2011-05-22 - 83db719 - lavfi 2.10.0 - vsrc_buffer.h ++ Make libavfilter/vsrc_buffer.h public. ++ ++2011-05-19 - c000a9f - lavfi 2.8.0 - avcodec.h ++ Add av_vsrc_buffer_add_frame() to libavfilter/avcodec.h. ++ ++2011-05-14 - 9fdf772 - lavfi 2.6.0 - avcodec.h ++ Add avfilter_get_video_buffer_ref_from_frame() to libavfilter/avcodec.h. ++ ++2011-05-18 - 64150ff - lavc 53.7.0 - AVCodecContext.request_sample_fmt ++ Add request_sample_fmt field to AVCodecContext. ++ ++2011-05-10 - 188dea1 - lavc 53.6.0 - avcodec.h ++ Deprecate AVLPCType and the following fields in ++ AVCodecContext: lpc_coeff_precision, prediction_order_method, ++ min_partition_order, max_partition_order, lpc_type, lpc_passes. ++ Corresponding FLAC encoder options should be used instead. ++ ++2011-05-07 - 9fdf772 - lavfi 2.5.0 - avcodec.h ++ Add libavfilter/avcodec.h header and avfilter_copy_frame_props() ++ function. ++ ++2011-05-07 - 18ded93 - lavc 53.5.0 - AVFrame ++ Add format field to AVFrame. ++ ++2011-05-07 - 22333a6 - lavc 53.4.0 - AVFrame ++ Add width and height fields to AVFrame. ++ ++2011-05-01 - 35fe66a - lavfi 2.4.0 - avfilter.h ++ Rename AVFilterBufferRefVideoProps.pixel_aspect to ++ sample_aspect_ratio. ++ ++2011-05-01 - 77e9dee - lavc 53.3.0 - AVFrame ++ Add a sample_aspect_ratio field to AVFrame. ++ ++2011-05-01 - 1ba5727 - lavc 53.2.0 - AVFrame ++ Add a pkt_pos field to AVFrame. ++ ++2011-04-29 - 35ceaa7 - lavu 51.2.0 - mem.h ++ Add av_dynarray_add function for adding ++ an element to a dynamic array. ++ ++2011-04-26 - bebe72f - lavu 51.1.0 - avutil.h ++ Add AVPictureType enum and av_get_picture_type_char(), deprecate ++ FF_*_TYPE defines and av_get_pict_type_char() defined in ++ libavcodec/avcodec.h. ++ ++2011-04-26 - 10d3940 - lavfi 2.3.0 - avfilter.h ++ Add pict_type and key_frame fields to AVFilterBufferRefVideo. ++ ++2011-04-26 - 7a11c82 - lavfi 2.2.0 - vsrc_buffer ++ Add sample_aspect_ratio fields to vsrc_buffer arguments ++ ++2011-04-21 - 94f7451 - lavc 53.1.0 - avcodec.h ++ Add CODEC_CAP_SLICE_THREADS for codecs supporting sliced threading. ++ ++2011-04-15 - lavc 52.120.0 - avcodec.h ++ AVPacket structure got additional members for passing side information: ++ 4de339e introduce side information for AVPacket ++ 2d8591c make containers pass palette change in AVPacket ++ ++2011-04-12 - lavf 52.107.0 - avio.h ++ Avio cleanup, part II - deprecate the entire URLContext API: ++ 175389c add avio_check as a replacement for url_exist ++ ff1ec0c add avio_pause and avio_seek_time as replacements ++ for _av_url_read_fseek/fpause ++ cdc6a87 deprecate av_protocol_next(), avio_enum_protocols ++ should be used instead. ++ 80c6e23 rename url_set_interrupt_cb->avio_set_interrupt_cb. ++ f87b1b3 rename open flags: URL_* -> AVIO_* ++ f8270bb add avio_enum_protocols. ++ 5593f03 deprecate URLProtocol. ++ c486dad deprecate URLContext. ++ 026e175 deprecate the typedef for URLInterruptCB ++ 8e76a19 deprecate av_register_protocol2. ++ b840484 deprecate URL_PROTOCOL_FLAG_NESTED_SCHEME ++ 1305d93 deprecate av_url_read_seek ++ fa104e1 deprecate av_url_read_pause ++ 727c7aa deprecate url_get_filename(). ++ 5958df3 deprecate url_max_packet_size(). ++ 1869ea0 deprecate url_get_file_handle(). ++ 32a97d4 deprecate url_filesize(). ++ e52a914 deprecate url_close(). ++ 58a48c6 deprecate url_seek(). ++ 925e908 deprecate url_write(). ++ dce3756 deprecate url_read_complete(). ++ bc371ac deprecate url_read(). ++ 0589da0 deprecate url_open(). ++ 62eaaea deprecate url_connect. ++ 5652bb9 deprecate url_alloc. ++ 333e894 deprecate url_open_protocol ++ e230705 deprecate url_poll and URLPollEntry ++ ++2011-04-08 - lavf 52.106.0 - avformat.h ++ Minor avformat.h cleanup: ++ a9bf9d8 deprecate av_guess_image2_codec ++ c3675df rename avf_sdp_create->av_sdp_create ++ ++2011-04-03 - lavf 52.105.0 - avio.h ++ Large-scale renaming/deprecating of AVIOContext-related functions: ++ 724f6a0 deprecate url_fdopen ++ 403ee83 deprecate url_open_dyn_packet_buf ++ 6dc7d80 rename url_close_dyn_buf -> avio_close_dyn_buf ++ b92c545 rename url_open_dyn_buf -> avio_open_dyn_buf ++ 8978fed introduce an AVIOContext.seekable field as a replacement for ++ AVIOContext.is_streamed and url_is_streamed() ++ b64030f deprecate get_checksum() ++ 4c4427a deprecate init_checksum() ++ 4ec153b deprecate udp_set_remote_url/get_local_port ++ 933e90a deprecate av_url_read_fseek/fpause ++ 8d9769a deprecate url_fileno ++ b7f2fdd rename put_flush_packet -> avio_flush ++ 35f1023 deprecate url_close_buf ++ 83fddae deprecate url_open_buf ++ d9d86e0 rename url_fprintf -> avio_printf ++ 59f65d9 deprecate url_setbufsize ++ 3e68b3b deprecate url_ferror ++ e8bb2e2 deprecate url_fget_max_packet_size ++ 76aa876 rename url_fsize -> avio_size ++ e519753 deprecate url_fgetc ++ 655e45e deprecate url_fgets ++ a2704c9 rename url_ftell -> avio_tell ++ e16ead0 deprecate get_strz() in favor of avio_get_str ++ 0300db8,2af07d3 rename url_fskip -> avio_skip ++ 6b4aa5d rename url_fseek -> avio_seek ++ 61840b4 deprecate put_tag ++ 22a3212 rename url_fopen/fclose -> avio_open/close. ++ 0ac8e2b deprecate put_nbyte ++ 77eb550 rename put_byte -> avio_w8 ++ put_[b/l]e -> avio_w[b/l] ++ put_buffer -> avio_write ++ b7effd4 rename get_byte -> avio_r8, ++ get_[b/l]e -> avio_r[b/l] ++ get_buffer -> avio_read ++ b3db9ce deprecate get_partial_buffer ++ 8d9ac96 rename av_alloc_put_byte -> avio_alloc_context ++ ++2011-03-25 - 34b47d7 - lavc 52.115.0 - AVCodecContext.audio_service_type ++ Add audio_service_type field to AVCodecContext. ++ ++2011-03-17 - e309fdc - lavu 50.40.0 - pixfmt.h ++ Add PIX_FMT_BGR48LE and PIX_FMT_BGR48BE pixel formats ++ ++2011-03-02 - 863c471 - lavf 52.103.0 - av_pkt_dump2, av_pkt_dump_log2 ++ Add new functions av_pkt_dump2, av_pkt_dump_log2 that uses the ++ source stream timebase for outputting timestamps. Deprecate ++ av_pkt_dump and av_pkt_dump_log. ++ ++2011-02-20 - e731b8d - lavf 52.102.0 - avio.h ++ * e731b8d - rename init_put_byte() to ffio_init_context(), deprecating the ++ original, and move it to a private header so it is no longer ++ part of our public API. Instead, use av_alloc_put_byte(). ++ * ae628ec - rename ByteIOContext to AVIOContext. ++ ++2011-02-16 - 09d171b - lavf 52.101.0 - avformat.h ++ lavu 52.39.0 - parseutils.h ++ * 610219a - Add av_ prefix to dump_format(). ++ * f6c7375 - Replace parse_date() in lavf with av_parse_time() in lavu. ++ * ab0287f - Move find_info_tag from lavf to lavu and add av_prefix to it. ++ ++2011-02-15 - lavu 52.38.0 - merge libavcore ++ libavcore is merged back completely into libavutil ++ ++2011-02-10 - 55bad0c - lavc 52.113.0 - vbv_delay ++ Add vbv_delay field to AVCodecContext ++ ++2011-02-14 - 24a83bd - lavf 52.100.0 - AV_DISPOSITION_CLEAN_EFFECTS ++ Add AV_DISPOSITION_CLEAN_EFFECTS disposition flag. ++ ++2011-02-14 - 910b5b8 - lavfi 1.76.0 - AVFilterLink sample_aspect_ratio ++ Add sample_aspect_ratio field to AVFilterLink. ++ ++2011-02-10 - 12c14cd - lavf 52.99.0 - AVStream.disposition ++ Add AV_DISPOSITION_HEARING_IMPAIRED and AV_DISPOSITION_VISUAL_IMPAIRED. ++ ++2011-02-09 - 5592734 - lavc 52.112.0 - avcodec_thread_init() ++ Deprecate avcodec_thread_init()/avcodec_thread_free() use; instead ++ set thread_count before calling avcodec_open. ++ ++2011-02-09 - 778b08a - lavc 52.111.0 - threading API ++ Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/ ++ release_buffer()/draw_horiz_band() callbacks for appropriate codecs. ++ Add thread_type and active_thread_type fields to AVCodecContext. ++ ++2011-02-08 - 3940caa - lavf 52.98.0 - av_probe_input_buffer ++ Add av_probe_input_buffer() to avformat.h for probing format from a ++ ByteIOContext. ++ ++2011-02-06 - fe174fc - lavf 52.97.0 - avio.h ++ Add flag for non-blocking protocols: URL_FLAG_NONBLOCK ++ ++2011-02-04 - f124b08 - lavf 52.96.0 - avformat_free_context() ++ Add avformat_free_context() in avformat.h. ++ ++2011-02-03 - f5b82f4 - lavc 52.109.0 - add CODEC_ID_PRORES ++ Add CODEC_ID_PRORES to avcodec.h. ++ ++2011-02-03 - fe9a3fb - lavc 52.109.0 - H.264 profile defines ++ Add defines for H.264 * Constrained Baseline and Intra profiles ++ ++2011-02-02 - lavf 52.95.0 ++ * 50196a9 - add a new installed header version.h. ++ * 4efd5cf, dccbd97, 93b78d1 - add several variants of public ++ avio_{put,get}_str* functions. Deprecate corresponding semi-public ++ {put,get}_str*. ++ ++2011-02-02 - dfd2a00 - lavu 50.37.0 - log.h ++ Make av_dlog public. ++ ++2011-01-31 - 7b3ea55 - lavfi 1.76.0 - vsrc_buffer ++ Add sample_aspect_ratio fields to vsrc_buffer arguments ++ ++2011-01-31 - 910b5b8 - lavfi 1.75.0 - AVFilterLink sample_aspect_ratio ++ Add sample_aspect_ratio field to AVFilterLink. ++ + 2011-01-15 - r26374 - lavfi 1.74.0 - AVFilterBufferRefAudioProps + Rename AVFilterBufferRefAudioProps.samples_nb to nb_samples. + +@@ -385,16 +925,22 @@ + + 2010-05-26 - r23334 - lavc 52.72.0 - CODEC_CAP_EXPERIMENTAL + Add CODEC_CAP_EXPERIMENTAL flag. ++ NOTE: this was backported to 0.6 + + 2010-05-23 - r23255 - lavu 50.16.0 - av_get_random_seed() + Add av_get_random_seed(). + + 2010-05-18 - r23161 - lavf 52.63.0 - AVFMT_FLAG_RTP_HINT + Add AVFMT_FLAG_RTP_HINT as possible value for AVFormatContext.flags. ++ NOTE: this was backported to 0.6 + + 2010-05-09 - r23066 - lavfi 1.20.0 - AVFilterPicRef + Add interlaced and top_field_first fields to AVFilterPicRef. + ++------------------------------8<------------------------------------- ++ 0.6 branch was cut here ++----------------------------->8-------------------------------------- ++ + 2010-05-01 - r23002 - lavf 52.62.0 - probe function + Add av_probe_input_format2 to API, it allows ignoring probe + results below given score and returns the actual probe score. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/avtools-common-opts.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/avtools-common-opts.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/avtools-common-opts.texi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/avtools-common-opts.texi 2012-05-14 14:08:53.130315750 +0200 +@@ -0,0 +1,168 @@ ++All the numerical options, if not specified otherwise, accept in input ++a string representing a number, which may contain one of the ++International System number postfixes, for example 'K', 'M', 'G'. ++If 'i' is appended after the postfix, powers of 2 are used instead of ++powers of 10. The 'B' postfix multiplies the value for 8, and can be ++appended after another postfix or used alone. This allows using for ++example 'KB', 'MiB', 'G' and 'B' as postfix. ++ ++Options which do not take arguments are boolean options, and set the ++corresponding value to true. They can be set to false by prefixing ++with "no" the option name, for example using "-nofoo" in the ++command line will set to false the boolean option with name "foo". ++ ++@anchor{Stream specifiers} ++@section Stream specifiers ++Some options are applied per-stream, e.g. bitrate or codec. Stream specifiers ++are used to precisely specify which stream(s) does a given option belong to. ++ ++A stream specifier is a string generally appended to the option name and ++separated from it by a colon. E.g. @code{-codec:a:1 ac3} option contains ++@code{a:1} stream specifer, which matches the second audio stream. Therefore it ++would select the ac3 codec for the second audio stream. ++ ++A stream specifier can match several stream, the option is then applied to all ++of them. E.g. the stream specifier in @code{-b:a 128k} matches all audio ++streams. ++ ++An empty stream specifier matches all streams, for example @code{-codec copy} ++or @code{-codec: copy} would copy all the streams without reencoding. ++ ++Possible forms of stream specifiers are: ++@table @option ++@item @var{stream_index} ++Matches the stream with this index. E.g. @code{-threads:1 4} would set the ++thread count for the second stream to 4. ++@item @var{stream_type}[:@var{stream_index}] ++@var{stream_type} is one of: 'v' for video, 'a' for audio, 's' for subtitle, ++'d' for data and 't' for attachments. If @var{stream_index} is given, then ++matches stream number @var{stream_index} of this type. Otherwise matches all ++streams of this type. ++@item p:@var{program_id}[:@var{stream_index}] ++If @var{stream_index} is given, then matches stream number @var{stream_index} in ++program with id @var{program_id}. Otherwise matches all streams in this program. ++@end table ++@section Generic options ++ ++These options are shared amongst the av* tools. ++ ++@table @option ++ ++@item -L ++Show license. ++ ++@item -h, -?, -help, --help ++Show help. ++ ++@item -version ++Show version. ++ ++@item -formats ++Show available formats. ++ ++The fields preceding the format names have the following meanings: ++@table @samp ++@item D ++Decoding available ++@item E ++Encoding available ++@end table ++ ++@item -codecs ++Show available codecs. ++ ++The fields preceding the codec names have the following meanings: ++@table @samp ++@item D ++Decoding available ++@item E ++Encoding available ++@item V/A/S ++Video/audio/subtitle codec ++@item S ++Codec supports slices ++@item D ++Codec supports direct rendering ++@item T ++Codec can handle input truncated at random locations instead of only at frame boundaries ++@end table ++ ++@item -bsfs ++Show available bitstream filters. ++ ++@item -protocols ++Show available protocols. ++ ++@item -filters ++Show available libavfilter filters. ++ ++@item -pix_fmts ++Show available pixel formats. ++ ++@item -sample_fmts ++Show available sample formats. ++ ++@item -loglevel @var{loglevel} | -v @var{loglevel} ++Set the logging level used by the library. ++@var{loglevel} is a number or a string containing one of the following values: ++@table @samp ++@item quiet ++@item panic ++@item fatal ++@item error ++@item warning ++@item info ++@item verbose ++@item debug ++@end table ++ ++By default the program logs to stderr, if coloring is supported by the ++terminal, colors are used to mark errors and warnings. Log coloring ++can be disabled setting the environment variable ++@env{AV_LOG_FORCE_NOCOLOR} or @env{NO_COLOR}, or can be forced setting ++the environment variable @env{AV_LOG_FORCE_COLOR}. ++The use of the environment variable @env{NO_COLOR} is deprecated and ++will be dropped in a following FFmpeg version. ++ ++@item -report ++Dump full command line and console output to a file named ++@code{@var{program}-@var{YYYYMMDD}-@var{HHMMSS}.log} in the current ++directory. ++This file can be useful for bug reports. ++It also implies @code{-loglevel verbose}. ++ ++Note: setting the environment variable @code{FFREPORT} to any value has the ++same effect. ++ ++@end table ++ ++@section AVOptions ++ ++These options are provided directly by the libavformat, libavdevice and ++libavcodec libraries. To see the list of available AVOptions, use the ++@option{-help} option. They are separated into two categories: ++@table @option ++@item generic ++These options can be set for any container, codec or device. Generic options ++are listed under AVFormatContext options for containers/devices and under ++AVCodecContext options for codecs. ++@item private ++These options are specific to the given container, device or codec. Private ++options are listed under their corresponding containers/devices/codecs. ++@end table ++ ++For example to write an ID3v2.3 header instead of a default ID3v2.4 to ++an MP3 file, use the @option{id3v2_version} private option of the MP3 ++muxer: ++@example ++ffmpeg -i input.flac -id3v2_version 3 out.mp3 ++@end example ++ ++All codec AVOptions are obviously per-stream, so the chapter on stream ++specifiers applies to them ++ ++Note @option{-nooption} syntax cannot be used for boolean AVOptions, ++use @option{-option 0}/@option{-option 1}. ++ ++Note2 old undocumented way of specifying per-stream AVOptions by prepending ++v/a/s to the options name is now obsolete and will be removed soon. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/avutil.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/avutil.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/avutil.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/avutil.txt 2012-05-14 14:08:53.130315750 +0200 +@@ -19,7 +19,6 @@ + lls.c + mathematics.c greatest common divisor, integer sqrt, integer log2, ... + mem.c memory allocation routines with guaranteed alignment +-softfloat.c + + Headers: + bswap.h big/little/native-endian conversion code +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/bitstream_filters.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/bitstream_filters.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/bitstream_filters.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/bitstream_filters.texi 2012-05-14 14:08:53.131315770 +0200 +@@ -23,6 +23,20 @@ + + @section h264_mp4toannexb + ++Convert an H.264 bitstream from length prefixed mode to start code ++prefixed mode (as defined in the Annex B of the ITU-T H.264 ++specification). ++ ++This is required by some streaming formats, typically the MPEG-2 ++transport stream format ("mpegts"). ++ ++For example to remux an MP4 file containing an H.264 stream to mpegts ++format with @command{ffmpeg}, you can use the command: ++ ++@example ++ffmpeg -i INPUT.mp4 -codec copy -bsf:v h264_mp4toannexb OUTPUT.ts ++@end example ++ + @section imx_dump_header + + @section mjpeg2jpeg +@@ -34,7 +48,7 @@ + e.g. by + + @example +-ffmpeg -i ../some_mjpeg.avi -vcodec copy frames_%d.jpg ++ffmpeg -i ../some_mjpeg.avi -c:v copy frames_%d.jpg + @end example + + Unfortunately, these chunks are incomplete JPEG images, because +@@ -57,9 +71,9 @@ + produce fully qualified JPEG images. + + @example +-ffmpeg -i mjpeg-movie.avi -vcodec copy -vbsf mjpeg2jpeg frame_%d.jpg ++ffmpeg -i mjpeg-movie.avi -c:v copy -vbsf mjpeg2jpeg frame_%d.jpg + exiftran -i -9 frame*.jpg +-ffmpeg -i frame_%d.jpg -vcodec copy rotated.avi ++ffmpeg -i frame_%d.jpg -c:v copy rotated.avi + @end example + + @section mjpega_dump_header +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/build_system.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/build_system.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/build_system.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/build_system.txt 2012-05-14 14:08:53.131315770 +0200 +@@ -1,9 +1,38 @@ + FFmpeg currently uses a custom build system, this text attempts to document + some of its obscure features and options. + +-Options to make: +-make V=1 +- Build target with verbosity 1, instead of 1, 2 can be used too ++Makefile variables: ++ ++V ++ Disable the default terse mode, the full command issued by make and its ++ output will be shown on the screen. ++ ++DESTDIR ++ Destination directory for the install targets, useful to prepare packages ++ or install FFmpeg in cross-environments. ++ ++Makefile targets: ++ ++all ++ Default target, builds all the libraries and the executables. ++ ++fate ++ Run the fate test suite, note you must have installed it ++ ++fate-list ++ Will list all fate/regression test targets ++ ++install ++ Install headers, libraries and programs. ++ ++libavformat/output-example ++ Build the libavformat basic example. ++ ++libavcodec/api-example ++ Build the libavcodec basic example. ++ ++libswscale/swscale-test ++ Build the swscale self-test (useful also as example). + + + Useful standard make commands: +@@ -19,16 +48,3 @@ + continue build in case of errors, this is useful for the regression tests + sometimes but note it will still not run all reg tests. + +- +-Targets to make: +-fate-list +- Will list all fate/regression test targets +- +-fate +- Run the fate test suite, note you must have installed it +- +- +-Setting up local fate: +-use the following command to get the fate test samples +-rsync -aL rsync://rsync.mplayerhq.hu:/samples/fate-suite/ fate/fate-suite +-pass --samples= to configure +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/decoders.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/decoders.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/decoders.texi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/decoders.texi 2012-05-14 14:08:53.132315790 +0200 +@@ -0,0 +1,63 @@ ++@chapter Decoders ++@c man begin DECODERS ++ ++Decoders are configured elements in FFmpeg which allow the decoding of ++multimedia streams. ++ ++When you configure your FFmpeg build, all the supported native decoders ++are enabled by default. Decoders requiring an external library must be enabled ++manually via the corresponding @code{--enable-lib} option. You can list all ++available decoders using the configure option @code{--list-decoders}. ++ ++You can disable all the decoders with the configure option ++@code{--disable-decoders} and selectively enable / disable single decoders ++with the options @code{--enable-decoder=@var{DECODER}} / ++@code{--disable-decoder=@var{DECODER}}. ++ ++The option @code{-codecs} of the ff* tools will display the list of ++enabled decoders. ++ ++@c man end DECODERS ++ ++@chapter Video Decoders ++@c man begin VIDEO DECODERS ++ ++A description of some of the currently available video decoders ++follows. ++ ++@section rawvideo ++ ++Raw video decoder. ++ ++This decoder decodes rawvideo streams. ++ ++@subsection Options ++ ++@table @option ++@item top @var{top_field_first} ++Specify the assumed field type of the input video. ++@table @option ++@item -1 ++the video is assumed to be progressive (default) ++@item 0 ++bottom-field-first is assumed ++@item 1 ++top-field-first is assumed ++@end table ++ ++@end table ++ ++@c man end VIDEO DECODERS ++ ++@chapter Audio Decoders ++@c man begin AUDIO DECODERS ++ ++@section ffwavesynth ++ ++Internal wave synthetizer. ++ ++This decoder generates wave patterns according to predefined sequences. Its ++use is purely internal and the format of the data it accepts is not publicly ++documented. ++ ++@c man end AUDIO DECODERS +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/demuxers.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/demuxers.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/demuxers.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/demuxers.texi 2012-05-14 14:08:53.133315810 +0200 +@@ -49,19 +49,60 @@ + The size, the pixel format, and the format of each image must be the + same for all the files in the sequence. + +-The following example shows how to use @file{ffmpeg} for creating a ++The following example shows how to use @command{ffmpeg} for creating a + video from the images in the file sequence @file{img-001.jpeg}, +-@file{img-002.jpeg}, ..., assuming an input framerate of 10 frames per ++@file{img-002.jpeg}, ..., assuming an input frame rate of 10 frames per + second: + @example +-ffmpeg -r 10 -f image2 -i 'img-%03d.jpeg' out.avi ++ffmpeg -i 'img-%03d.jpeg' -r 10 out.mkv + @end example + + Note that the pattern must not necessarily contain "%d" or + "%0@var{N}d", for example to convert a single image file + @file{img.jpeg} you can employ the command: + @example +-ffmpeg -f image2 -i img.jpeg img.png ++ffmpeg -i img.jpeg img.png + @end example + ++@section applehttp ++ ++Apple HTTP Live Streaming demuxer. ++ ++This demuxer presents all AVStreams from all variant streams. ++The id field is set to the bitrate variant index number. By setting ++the discard flags on AVStreams (by pressing 'a' or 'v' in ffplay), ++the caller can decide which variant streams to actually receive. ++The total bitrate of the variant that the stream belongs to is ++available in a metadata key named "variant_bitrate". ++ ++@section sbg ++ ++SBaGen script demuxer. ++ ++This demuxer reads the script language used by SBaGen ++@url{http://uazu.net/sbagen/} to generate binaural beats sessions. A SBG ++script looks like that: ++@example ++-SE ++a: 300-2.5/3 440+4.5/0 ++b: 300-2.5/0 440+4.5/3 ++off: - ++NOW == a +++0:07:00 == b +++0:14:00 == a +++0:21:00 == b +++0:30:00 off ++@end example ++ ++A SBG script can mix absolute and relative timestamps. If the script uses ++either only absolute timestamps (including the script start time) or only ++relative ones, then its layout is fixed, and the conversion is ++straightforward. On the other hand, if the script mixes both kind of ++timestamps, then the @var{NOW} reference for relative timestamps will be ++taken from the current time of day at the time the script is read, and the ++script layout will be frozen according to that reference. That means that if ++the script is directly played, the actual times will match the absolute ++timestamps up to the sound controller's clock accuracy, but if the user ++somehow pauses the playback or seeks, all times will be shifted accordingly. ++ + @c man end INPUT DEVICES +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/developer.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/developer.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/developer.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/developer.texi 2012-05-14 14:08:53.136315870 +0200 +@@ -34,59 +34,57 @@ + @emph{any patch you make must be published}. The best way to proceed is + to send your patches to the FFmpeg mailing list. + +-@anchor{Coding Rules} +-@section Coding Rules ++@section Contributing + +-FFmpeg is programmed in the ISO C90 language with a few additional +-features from ISO C99, namely: ++There are 3 ways by which code gets into ffmpeg. + @itemize @bullet +-@item +-the @samp{inline} keyword; +-@item +-@samp{//} comments; +-@item +-designated struct initializers (@samp{struct s x = @{ .i = 17 @};}) +-@item +-compound literals (@samp{x = (struct s) @{ 17, 23 @};}) ++@item Submitting Patches to the main developer mailing list ++ see @ref{Submitting patches} for details. ++@item Directly committing changes to the main tree. ++@item Committing changes to a git clone, for example on github.com or ++ gitorious.org. And asking us to merge these changes. + @end itemize + +-These features are supported by all compilers we care about, so we will not +-accept patches to remove their use unless they absolutely do not impair +-clarity and performance. ++Whichever way, changes should be reviewed by the maintainer of the code ++before they are committed. And they should follow the @ref{Coding Rules}. ++The developer making the commit and the author are responsible for their changes ++and should try to fix issues their commit causes. + +-All code must compile with GCC 2.95 and GCC 3.3. Currently, FFmpeg also +-compiles with several other compilers, such as the Compaq ccc compiler +-or Sun Studio 9, and we would like to keep it that way unless it would +-be exceedingly involved. To ensure compatibility, please do not use any +-additional C99 features or GCC extensions. Especially watch out for: ++@anchor{Coding Rules} ++@section Coding Rules ++ ++@subsection Code formatting conventions ++ ++There are the following guidelines regarding the indentation in files: + @itemize @bullet + @item +-mixing statements and declarations; +-@item +-@samp{long long} (use @samp{int64_t} instead); ++Indent size is 4. + @item +-@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar; ++The TAB character is forbidden outside of Makefiles as is any ++form of trailing whitespace. Commits containing either will be ++rejected by the git repository. + @item +-GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}). ++You should try to limit your code lines to 80 characters; however, do so if ++and only if this improves readability. + @end itemize +- +-Indent size is 4. + The presentation is one inspired by 'indent -i4 -kr -nut'. +-The TAB character is forbidden outside of Makefiles as is any +-form of trailing whitespace. Commits containing either will be +-rejected by the Subversion repository. + + The main priority in FFmpeg is simplicity and small code size in order to + minimize the bug count. + +-Comments: Use the JavaDoc/Doxygen +-format (see examples below) so that code documentation ++@subsection Comments ++Use the JavaDoc/Doxygen format (see examples below) so that code documentation + can be generated automatically. All nontrivial functions should have a comment + above them explaining what the function does, even if it is just one sentence. + All structures and their member variables should be documented, too. ++ ++Avoid Qt-style and similar Doxygen syntax with @code{!} in it, i.e. replace ++@code{//!} with @code{///} and similar. Also @@ syntax should be employed ++for markup commands, i.e. use @code{@@param} and not @code{\param}. ++ + @example + /** +- * @@file mpeg.c ++ * @@file + * MPEG codec. + * @@author ... + */ +@@ -114,11 +112,97 @@ + ... + @end example + ++@subsection C language features ++ ++FFmpeg is programmed in the ISO C90 language with a few additional ++features from ISO C99, namely: ++@itemize @bullet ++@item ++the @samp{inline} keyword; ++@item ++@samp{//} comments; ++@item ++designated struct initializers (@samp{struct s x = @{ .i = 17 @};}) ++@item ++compound literals (@samp{x = (struct s) @{ 17, 23 @};}) ++@end itemize ++ ++These features are supported by all compilers we care about, so we will not ++accept patches to remove their use unless they absolutely do not impair ++clarity and performance. ++ ++All code must compile with recent versions of GCC and a number of other ++currently supported compilers. To ensure compatibility, please do not use ++additional C99 features or GCC extensions. Especially watch out for: ++@itemize @bullet ++@item ++mixing statements and declarations; ++@item ++@samp{long long} (use @samp{int64_t} instead); ++@item ++@samp{__attribute__} not protected by @samp{#ifdef __GNUC__} or similar; ++@item ++GCC statement expressions (@samp{(x = (@{ int y = 4; y; @})}). ++@end itemize ++ ++@subsection Naming conventions ++All names are using underscores (_), not CamelCase. For example, @samp{avfilter_get_video_buffer} is ++a valid function name and @samp{AVFilterGetVideo} is not. The exception from this are type names, like ++for example structs and enums; they should always be in the CamelCase ++ ++ ++There are following conventions for naming variables and functions: ++@itemize @bullet ++@item ++For local variables no prefix is required. ++@item ++For variables and functions declared as @code{static} no prefixes are required. ++@item ++For variables and functions used internally by the library, @code{ff_} prefix ++should be used. ++For example, @samp{ff_w64_demuxer}. ++@item ++For variables and functions used internally across multiple libraries, use ++@code{avpriv_}. For example, @samp{avpriv_aac_parse_header}. ++@item ++For exported names, each library has its own prefixes. Just check the existing ++code and name accordingly. ++@end itemize ++ ++@subsection Miscellanous conventions ++@itemize @bullet ++@item + fprintf and printf are forbidden in libavformat and libavcodec, + please use av_log() instead. +- ++@item + Casts should be used only when necessary. Unneeded parentheses + should also be avoided if they don't make the code easier to understand. ++@end itemize ++ ++@subsection Editor configuration ++In order to configure Vim to follow FFmpeg formatting conventions, paste ++the following snippet into your @file{.vimrc}: ++@example ++" indentation rules for FFmpeg: 4 spaces, no tabs ++set expandtab ++set shiftwidth=4 ++set softtabstop=4 ++" allow tabs in Makefiles ++autocmd FileType make set noexpandtab shiftwidth=8 softtabstop=8 ++" Trailing whitespace and tabs are forbidden, so highlight them. ++highlight ForbiddenWhitespace ctermbg=red guibg=red ++match ForbiddenWhitespace /\s\+$\|\t/ ++" Do not highlight spaces at the end of line while typing on that line. ++autocmd InsertEnter * match ForbiddenWhitespace /\t\|\s\+\%#\@@bit_rate = 64000; ++ c->sample_rate = 44100; ++ c->channels = 2; ++ c->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ /* open it */ ++ if (avcodec_open(c, codec) < 0) { ++ fprintf(stderr, "could not open codec\n"); ++ exit(1); ++ } ++ ++ /* the codec gives us the frame size, in samples */ ++ frame_size = c->frame_size; ++ samples = malloc(frame_size * 2 * c->channels); ++ outbuf_size = 10000; ++ outbuf = malloc(outbuf_size); ++ ++ f = fopen(filename, "wb"); ++ if (!f) { ++ fprintf(stderr, "could not open %s\n", filename); ++ exit(1); ++ } ++ ++ /* encode a single tone sound */ ++ t = 0; ++ tincr = 2 * M_PI * 440.0 / c->sample_rate; ++ for(i=0;i<200;i++) { ++ for(j=0;j 0) { ++ int got_frame = 0; ++ ++ if (!decoded_frame) { ++ if (!(decoded_frame = avcodec_alloc_frame())) { ++ fprintf(stderr, "out of memory\n"); ++ exit(1); ++ } ++ } else ++ avcodec_get_frame_defaults(decoded_frame); ++ ++ len = avcodec_decode_audio4(c, decoded_frame, &got_frame, &avpkt); ++ if (len < 0) { ++ fprintf(stderr, "Error while decoding\n"); ++ exit(1); ++ } ++ if (got_frame) { ++ /* if a frame has been decoded, output it */ ++ int data_size = av_samples_get_buffer_size(NULL, c->channels, ++ decoded_frame->nb_samples, ++ c->sample_fmt, 1); ++ fwrite(decoded_frame->data[0], 1, data_size, outfile); ++ } ++ avpkt.size -= len; ++ avpkt.data += len; ++ avpkt.dts = ++ avpkt.pts = AV_NOPTS_VALUE; ++ if (avpkt.size < AUDIO_REFILL_THRESH) { ++ /* Refill the input buffer, to avoid trying to decode ++ * incomplete frames. Instead of this, one could also use ++ * a parser, or use a proper container format through ++ * libavformat. */ ++ memmove(inbuf, avpkt.data, avpkt.size); ++ avpkt.data = inbuf; ++ len = fread(avpkt.data + avpkt.size, 1, ++ AUDIO_INBUF_SIZE - avpkt.size, f); ++ if (len > 0) ++ avpkt.size += len; ++ } ++ } ++ ++ fclose(outfile); ++ fclose(f); ++ ++ avcodec_close(c); ++ av_free(c); ++ av_free(decoded_frame); ++} ++ ++/* ++ * Video encoding example ++ */ ++static void video_encode_example(const char *filename, int codec_id) ++{ ++ AVCodec *codec; ++ AVCodecContext *c= NULL; ++ int i, out_size, size, x, y, outbuf_size; ++ FILE *f; ++ AVFrame *picture; ++ uint8_t *outbuf; ++ ++ printf("Video encoding\n"); ++ ++ /* find the mpeg1 video encoder */ ++ codec = avcodec_find_encoder(codec_id); ++ if (!codec) { ++ fprintf(stderr, "codec not found\n"); ++ exit(1); ++ } ++ ++ c = avcodec_alloc_context3(codec); ++ picture= avcodec_alloc_frame(); ++ ++ /* put sample parameters */ ++ c->bit_rate = 400000; ++ /* resolution must be a multiple of two */ ++ c->width = 352; ++ c->height = 288; ++ /* frames per second */ ++ c->time_base= (AVRational){1,25}; ++ c->gop_size = 10; /* emit one intra frame every ten frames */ ++ c->max_b_frames=1; ++ c->pix_fmt = PIX_FMT_YUV420P; ++ ++ if(codec_id == CODEC_ID_H264) ++ av_opt_set(c->priv_data, "preset", "slow", 0); ++ ++ /* open it */ ++ if (avcodec_open(c, codec) < 0) { ++ fprintf(stderr, "could not open codec\n"); ++ exit(1); ++ } ++ ++ f = fopen(filename, "wb"); ++ if (!f) { ++ fprintf(stderr, "could not open %s\n", filename); ++ exit(1); ++ } ++ ++ /* alloc image and output buffer */ ++ outbuf_size = 100000; ++ outbuf = malloc(outbuf_size); ++ ++ /* the image can be allocated by any means and av_image_alloc() is ++ * just the most convenient way if av_malloc() is to be used */ ++ av_image_alloc(picture->data, picture->linesize, ++ c->width, c->height, c->pix_fmt, 1); ++ ++ /* encode 1 second of video */ ++ for(i=0;i<25;i++) { ++ fflush(stdout); ++ /* prepare a dummy image */ ++ /* Y */ ++ for(y=0;yheight;y++) { ++ for(x=0;xwidth;x++) { ++ picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3; ++ } ++ } ++ ++ /* Cb and Cr */ ++ for(y=0;yheight/2;y++) { ++ for(x=0;xwidth/2;x++) { ++ picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2; ++ picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5; ++ } ++ } ++ ++ /* encode the image */ ++ out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); ++ printf("encoding frame %3d (size=%5d)\n", i, out_size); ++ fwrite(outbuf, 1, out_size, f); ++ } ++ ++ /* get the delayed frames */ ++ for(; out_size; i++) { ++ fflush(stdout); ++ ++ out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); ++ printf("write frame %3d (size=%5d)\n", i, out_size); ++ fwrite(outbuf, 1, out_size, f); ++ } ++ ++ /* add sequence end code to have a real mpeg file */ ++ outbuf[0] = 0x00; ++ outbuf[1] = 0x00; ++ outbuf[2] = 0x01; ++ outbuf[3] = 0xb7; ++ fwrite(outbuf, 1, 4, f); ++ fclose(f); ++ free(outbuf); ++ ++ avcodec_close(c); ++ av_free(c); ++ av_free(picture->data[0]); ++ av_free(picture); ++ printf("\n"); ++} ++ ++/* ++ * Video decoding example ++ */ ++ ++static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, ++ char *filename) ++{ ++ FILE *f; ++ int i; ++ ++ f=fopen(filename,"w"); ++ fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255); ++ for(i=0;icapabilities&CODEC_CAP_TRUNCATED) ++ c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */ ++ ++ /* For some codecs, such as msmpeg4 and mpeg4, width and height ++ MUST be initialized there because this information is not ++ available in the bitstream. */ ++ ++ /* open it */ ++ if (avcodec_open(c, codec) < 0) { ++ fprintf(stderr, "could not open codec\n"); ++ exit(1); ++ } ++ ++ /* the codec gives us the frame size, in samples */ ++ ++ f = fopen(filename, "rb"); ++ if (!f) { ++ fprintf(stderr, "could not open %s\n", filename); ++ exit(1); ++ } ++ ++ frame = 0; ++ for(;;) { ++ avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); ++ if (avpkt.size == 0) ++ break; ++ ++ /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio) ++ and this is the only method to use them because you cannot ++ know the compressed data size before analysing it. ++ ++ BUT some other codecs (msmpeg4, mpeg4) are inherently frame ++ based, so you must call them with all the data for one ++ frame exactly. You must also initialize 'width' and ++ 'height' before initializing them. */ ++ ++ /* NOTE2: some codecs allow the raw parameters (frame size, ++ sample rate) to be changed at any frame. We handle this, so ++ you should also take care of it */ ++ ++ /* here, we use a stream based decoder (mpeg1video), so we ++ feed decoder and see if it could decode a frame */ ++ avpkt.data = inbuf; ++ while (avpkt.size > 0) { ++ len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); ++ if (len < 0) { ++ fprintf(stderr, "Error while decoding frame %d\n", frame); ++ exit(1); ++ } ++ if (got_picture) { ++ printf("saving frame %3d\n", frame); ++ fflush(stdout); ++ ++ /* the picture is allocated by the decoder. no need to ++ free it */ ++ snprintf(buf, sizeof(buf), outfilename, frame); ++ pgm_save(picture->data[0], picture->linesize[0], ++ c->width, c->height, buf); ++ frame++; ++ } ++ avpkt.size -= len; ++ avpkt.data += len; ++ } ++ } ++ ++ /* some codecs, such as MPEG, transmit the I and P frame with a ++ latency of one frame. You must do the following to have a ++ chance to get the last frame of the video */ ++ avpkt.data = NULL; ++ avpkt.size = 0; ++ len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); ++ if (got_picture) { ++ printf("saving last frame %3d\n", frame); ++ fflush(stdout); ++ ++ /* the picture is allocated by the decoder. no need to ++ free it */ ++ snprintf(buf, sizeof(buf), outfilename, frame); ++ pgm_save(picture->data[0], picture->linesize[0], ++ c->width, c->height, buf); ++ frame++; ++ } ++ ++ fclose(f); ++ ++ avcodec_close(c); ++ av_free(c); ++ av_free(picture); ++ printf("\n"); ++} ++ ++int main(int argc, char **argv) ++{ ++ const char *filename; ++ ++ /* must be called before using avcodec lib */ ++ avcodec_init(); ++ ++ /* register all the codecs */ ++ avcodec_register_all(); ++ ++ if (argc <= 1) { ++ audio_encode_example("/tmp/test.mp2"); ++ audio_decode_example("/tmp/test.sw", "/tmp/test.mp2"); ++ ++ video_encode_example("/tmp/test.h264", CODEC_ID_H264); ++ video_encode_example("/tmp/test.mpg", CODEC_ID_MPEG1VIDEO); ++ filename = "/tmp/test.mpg"; ++ } else { ++ filename = argv[1]; ++ } ++ ++ // audio_decode_example("/tmp/test.sw", filename); ++ video_decode_example("/tmp/test%d.pgm", filename); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/filtering.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/filtering.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/filtering.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/filtering.c 2012-05-14 14:08:53.145316052 +0200 +@@ -0,0 +1,229 @@ ++/* ++ * Copyright (c) 2010 Nicolas George ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a copy ++ * of this software and associated documentation files (the "Software"), to deal ++ * in the Software without restriction, including without limitation the rights ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++ * copies of the Software, and to permit persons to whom the Software is ++ * furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ++ * THE SOFTWARE. ++ */ ++ ++/** ++ * @file ++ * API example for decoding and filtering ++ */ ++ ++#define _XOPEN_SOURCE 600 /* for usleep */ ++ ++#include ++#include ++#include ++#include ++ ++const char *filter_descr = "scale=78:24"; ++ ++static AVFormatContext *fmt_ctx; ++static AVCodecContext *dec_ctx; ++AVFilterContext *buffersink_ctx; ++AVFilterContext *buffersrc_ctx; ++AVFilterGraph *filter_graph; ++static int video_stream_index = -1; ++static int64_t last_pts = AV_NOPTS_VALUE; ++ ++static int open_input_file(const char *filename) ++{ ++ int ret, i; ++ AVCodec *dec; ++ ++ if ((ret = avformat_open_input(&fmt_ctx, filename, NULL, NULL)) < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot open input file\n"); ++ return ret; ++ } ++ ++ if ((ret = av_find_stream_info(fmt_ctx)) < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot find stream information\n"); ++ return ret; ++ } ++ ++ /* select the video stream */ ++ ret = av_find_best_stream(fmt_ctx, AVMEDIA_TYPE_VIDEO, -1, -1, &dec, 0); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot find a video stream in the input file\n"); ++ return ret; ++ } ++ video_stream_index = ret; ++ dec_ctx = fmt_ctx->streams[video_stream_index]->codec; ++ ++ /* init the video decoder */ ++ if ((ret = avcodec_open(dec_ctx, dec)) < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot open video decoder\n"); ++ return ret; ++ } ++ ++ return 0; ++} ++ ++static int init_filters(const char *filters_descr) ++{ ++ char args[512]; ++ int ret; ++ AVFilter *buffersrc = avfilter_get_by_name("buffer"); ++ AVFilter *buffersink = avfilter_get_by_name("buffersink"); ++ AVFilterInOut *outputs = avfilter_inout_alloc(); ++ AVFilterInOut *inputs = avfilter_inout_alloc(); ++ enum PixelFormat pix_fmts[] = { PIX_FMT_GRAY8, PIX_FMT_NONE }; ++ filter_graph = avfilter_graph_alloc(); ++ ++ /* buffer video source: the decoded frames from the decoder will be inserted here. */ ++ snprintf(args, sizeof(args), "%d:%d:%d:%d:%d:%d:%d", ++ dec_ctx->width, dec_ctx->height, dec_ctx->pix_fmt, ++ dec_ctx->time_base.num, dec_ctx->time_base.den, ++ dec_ctx->sample_aspect_ratio.num, dec_ctx->sample_aspect_ratio.den); ++ ret = avfilter_graph_create_filter(&buffersrc_ctx, buffersrc, "in", ++ args, NULL, filter_graph); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot create buffer source\n"); ++ return ret; ++ } ++ ++ /* buffer video sink: to terminate the filter chain. */ ++ ret = avfilter_graph_create_filter(&buffersink_ctx, buffersink, "out", ++ NULL, pix_fmts, filter_graph); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Cannot create buffer sink\n"); ++ return ret; ++ } ++ ++ /* Endpoints for the filter graph. */ ++ outputs->name = av_strdup("in"); ++ outputs->filter_ctx = buffersrc_ctx; ++ outputs->pad_idx = 0; ++ outputs->next = NULL; ++ ++ inputs->name = av_strdup("out"); ++ inputs->filter_ctx = buffersink_ctx; ++ inputs->pad_idx = 0; ++ inputs->next = NULL; ++ ++ if ((ret = avfilter_graph_parse(filter_graph, filter_descr, ++ &inputs, &outputs, NULL)) < 0) ++ return ret; ++ ++ if ((ret = avfilter_graph_config(filter_graph, NULL)) < 0) ++ return ret; ++} ++ ++static void display_picref(AVFilterBufferRef *picref, AVRational time_base) ++{ ++ int x, y; ++ uint8_t *p0, *p; ++ int64_t delay; ++ ++ if (picref->pts != AV_NOPTS_VALUE) { ++ if (last_pts != AV_NOPTS_VALUE) { ++ /* sleep roughly the right amount of time; ++ * usleep is in microseconds, just like AV_TIME_BASE. */ ++ delay = av_rescale_q(picref->pts - last_pts, ++ time_base, AV_TIME_BASE_Q); ++ if (delay > 0 && delay < 1000000) ++ usleep(delay); ++ } ++ last_pts = picref->pts; ++ } ++ ++ /* Trivial ASCII grayscale display. */ ++ p0 = picref->data[0]; ++ puts("\033c"); ++ for (y = 0; y < picref->video->h; y++) { ++ p = p0; ++ for (x = 0; x < picref->video->w; x++) ++ putchar(" .-+#"[*(p++) / 52]); ++ putchar('\n'); ++ p0 += picref->linesize[0]; ++ } ++ fflush(stdout); ++} ++ ++int main(int argc, char **argv) ++{ ++ int ret; ++ AVPacket packet; ++ AVFrame frame; ++ int got_frame; ++ ++ if (argc != 2) { ++ fprintf(stderr, "Usage: %s file\n", argv[0]); ++ exit(1); ++ } ++ ++ avcodec_register_all(); ++ av_register_all(); ++ avfilter_register_all(); ++ ++ if ((ret = open_input_file(argv[1])) < 0) ++ goto end; ++ if ((ret = init_filters(filter_descr)) < 0) ++ goto end; ++ ++ /* read all packets */ ++ while (1) { ++ AVFilterBufferRef *picref; ++ if ((ret = av_read_frame(fmt_ctx, &packet)) < 0) ++ break; ++ ++ if (packet.stream_index == video_stream_index) { ++ avcodec_get_frame_defaults(&frame); ++ got_frame = 0; ++ ret = avcodec_decode_video2(dec_ctx, &frame, &got_frame, &packet); ++ av_free_packet(&packet); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Error decoding video\n"); ++ break; ++ } ++ ++ if (got_frame) { ++ if (frame.pts == AV_NOPTS_VALUE) ++ frame.pts = frame.pkt_dts == AV_NOPTS_VALUE ? ++ frame.pkt_dts : frame.pkt_pts; ++ /* push the decoded frame into the filtergraph */ ++ av_vsrc_buffer_add_frame(buffersrc_ctx, &frame); ++ ++ /* pull filtered pictures from the filtergraph */ ++ while (avfilter_poll_frame(buffersink_ctx->inputs[0])) { ++ av_vsink_buffer_get_video_buffer_ref(buffersink_ctx, &picref, 0); ++ if (picref) { ++ display_picref(picref, buffersink_ctx->inputs[0]->time_base); ++ avfilter_unref_buffer(picref); ++ } ++ } ++ } ++ } ++ } ++end: ++ avfilter_graph_free(&filter_graph); ++ if (dec_ctx) ++ avcodec_close(dec_ctx); ++ av_close_input_file(fmt_ctx); ++ ++ if (ret < 0 && ret != AVERROR_EOF) { ++ char buf[1024]; ++ av_strerror(ret, buf, sizeof(buf)); ++ fprintf(stderr, "Error occurred: %s\n", buf); ++ exit(1); ++ } ++ ++ exit(0); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/Makefile 2012-05-14 14:08:53.141315972 +0200 +@@ -0,0 +1,21 @@ ++# use pkg-config for getting CFLAGS abd LDFLAGS ++FFMPEG_LIBS=libavdevice libavformat libavfilter libavcodec libswscale libavutil ++CFLAGS+=$(shell pkg-config --cflags $(FFMPEG_LIBS)) ++LDFLAGS+=$(shell pkg-config --libs $(FFMPEG_LIBS)) ++ ++EXAMPLES=decoding_encoding filtering metadata muxing ++ ++OBJS=$(addsuffix .o,$(EXAMPLES)) ++ ++%: %.o ++ $(CC) $< $(LDFLAGS) -o $@ ++ ++%.o: %.c ++ $(CC) $< $(CFLAGS) -c -o $@ ++ ++.phony: all clean ++ ++all: $(OBJS) $(EXAMPLES) ++ ++clean: ++ rm -rf $(EXAMPLES) $(OBJS) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/metadata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/metadata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/metadata.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/metadata.c 2012-05-14 14:08:53.146316072 +0200 +@@ -0,0 +1,55 @@ ++/* ++ * Copyright (c) 2011 Reinhard Tartler ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a copy ++ * of this software and associated documentation files (the "Software"), to deal ++ * in the Software without restriction, including without limitation the rights ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++ * copies of the Software, and to permit persons to whom the Software is ++ * furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ++ * THE SOFTWARE. ++ */ ++ ++/** ++ * @file ++ * Shows how the metadata API can be used in application programs. ++ */ ++ ++#include ++ ++#include ++#include ++ ++int main (int argc, char **argv) ++{ ++ AVFormatContext *fmt_ctx = NULL; ++ AVDictionaryEntry *tag = NULL; ++ int ret; ++ ++ if (argc != 2) { ++ printf("usage: %s \n" ++ "example program to demonstrate the use of the libavformat metadata API.\n" ++ "\n", argv[0]); ++ return 1; ++ } ++ ++ av_register_all(); ++ if ((ret = avformat_open_input(&fmt_ctx, argv[1], NULL, NULL))) ++ return ret; ++ ++ while ((tag = av_dict_get(fmt_ctx->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) ++ printf("%s=%s\n", tag->key, tag->value); ++ ++ avformat_free_context(fmt_ctx); ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/muxing.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/muxing.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/examples/muxing.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/examples/muxing.c 2012-05-14 14:08:53.147316092 +0200 +@@ -0,0 +1,556 @@ ++/* ++ * Copyright (c) 2003 Fabrice Bellard ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a copy ++ * of this software and associated documentation files (the "Software"), to deal ++ * in the Software without restriction, including without limitation the rights ++ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell ++ * copies of the Software, and to permit persons to whom the Software is ++ * furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, ++ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN ++ * THE SOFTWARE. ++ */ ++ ++/** ++ * @file ++ * libavformat API example. ++ * ++ * Output a media file in any supported libavformat format. ++ * The default codecs are used. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "libavutil/mathematics.h" ++#include "libavformat/avformat.h" ++#include "libswscale/swscale.h" ++ ++#undef exit ++ ++/* 5 seconds stream duration */ ++#define STREAM_DURATION 200.0 ++#define STREAM_FRAME_RATE 25 /* 25 images/s */ ++#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE)) ++#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */ ++ ++static int sws_flags = SWS_BICUBIC; ++ ++/**************************************************************/ ++/* audio output */ ++ ++static float t, tincr, tincr2; ++static int16_t *samples; ++static uint8_t *audio_outbuf; ++static int audio_outbuf_size; ++static int audio_input_frame_size; ++ ++/* ++ * add an audio output stream ++ */ ++static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id) ++{ ++ AVCodecContext *c; ++ AVStream *st; ++ ++ st = avformat_new_stream(oc, NULL); ++ if (!st) { ++ fprintf(stderr, "Could not alloc stream\n"); ++ exit(1); ++ } ++ st->id = 1; ++ ++ c = st->codec; ++ c->codec_id = codec_id; ++ c->codec_type = AVMEDIA_TYPE_AUDIO; ++ ++ /* put sample parameters */ ++ c->sample_fmt = AV_SAMPLE_FMT_S16; ++ c->bit_rate = 64000; ++ c->sample_rate = 44100; ++ c->channels = 2; ++ ++ // some formats want stream headers to be separate ++ if (oc->oformat->flags & AVFMT_GLOBALHEADER) ++ c->flags |= CODEC_FLAG_GLOBAL_HEADER; ++ ++ return st; ++} ++ ++static void open_audio(AVFormatContext *oc, AVStream *st) ++{ ++ AVCodecContext *c; ++ AVCodec *codec; ++ ++ c = st->codec; ++ ++ /* find the audio encoder */ ++ codec = avcodec_find_encoder(c->codec_id); ++ if (!codec) { ++ fprintf(stderr, "codec not found\n"); ++ exit(1); ++ } ++ ++ /* open it */ ++ if (avcodec_open(c, codec) < 0) { ++ fprintf(stderr, "could not open codec\n"); ++ exit(1); ++ } ++ ++ /* init signal generator */ ++ t = 0; ++ tincr = 2 * M_PI * 110.0 / c->sample_rate; ++ /* increment frequency by 110 Hz per second */ ++ tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate; ++ ++ audio_outbuf_size = 10000; ++ audio_outbuf = av_malloc(audio_outbuf_size); ++ ++ /* ugly hack for PCM codecs (will be removed ASAP with new PCM ++ support to compute the input frame size in samples */ ++ if (c->frame_size <= 1) { ++ audio_input_frame_size = audio_outbuf_size / c->channels; ++ switch(st->codec->codec_id) { ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S16BE: ++ case CODEC_ID_PCM_U16LE: ++ case CODEC_ID_PCM_U16BE: ++ audio_input_frame_size >>= 1; ++ break; ++ default: ++ break; ++ } ++ } else { ++ audio_input_frame_size = c->frame_size; ++ } ++ samples = av_malloc(audio_input_frame_size * 2 * c->channels); ++} ++ ++/* prepare a 16 bit dummy audio frame of 'frame_size' samples and ++ 'nb_channels' channels */ ++static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels) ++{ ++ int j, i, v; ++ int16_t *q; ++ ++ q = samples; ++ for (j = 0; j < frame_size; j++) { ++ v = (int)(sin(t) * 10000); ++ for(i = 0; i < nb_channels; i++) ++ *q++ = v; ++ t += tincr; ++ tincr += tincr2; ++ } ++} ++ ++static void write_audio_frame(AVFormatContext *oc, AVStream *st) ++{ ++ AVCodecContext *c; ++ AVPacket pkt; ++ av_init_packet(&pkt); ++ ++ c = st->codec; ++ ++ get_audio_frame(samples, audio_input_frame_size, c->channels); ++ ++ pkt.size = avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples); ++ ++ if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) ++ pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); ++ pkt.flags |= AV_PKT_FLAG_KEY; ++ pkt.stream_index = st->index; ++ pkt.data = audio_outbuf; ++ ++ /* write the compressed frame in the media file */ ++ if (av_interleaved_write_frame(oc, &pkt) != 0) { ++ fprintf(stderr, "Error while writing audio frame\n"); ++ exit(1); ++ } ++} ++ ++static void close_audio(AVFormatContext *oc, AVStream *st) ++{ ++ avcodec_close(st->codec); ++ ++ av_free(samples); ++ av_free(audio_outbuf); ++} ++ ++/**************************************************************/ ++/* video output */ ++ ++static AVFrame *picture, *tmp_picture; ++static uint8_t *video_outbuf; ++static int frame_count, video_outbuf_size; ++ ++/* add a video output stream */ ++static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id) ++{ ++ AVCodecContext *c; ++ AVStream *st; ++ AVCodec *codec; ++ ++ st = avformat_new_stream(oc, NULL); ++ if (!st) { ++ fprintf(stderr, "Could not alloc stream\n"); ++ exit(1); ++ } ++ ++ c = st->codec; ++ ++ /* find the video encoder */ ++ codec = avcodec_find_encoder(codec_id); ++ if (!codec) { ++ fprintf(stderr, "codec not found\n"); ++ exit(1); ++ } ++ avcodec_get_context_defaults3(c, codec); ++ ++ c->codec_id = codec_id; ++ ++ /* put sample parameters */ ++ c->bit_rate = 400000; ++ /* resolution must be a multiple of two */ ++ c->width = 352; ++ c->height = 288; ++ /* time base: this is the fundamental unit of time (in seconds) in terms ++ of which frame timestamps are represented. for fixed-fps content, ++ timebase should be 1/framerate and timestamp increments should be ++ identically 1. */ ++ c->time_base.den = STREAM_FRAME_RATE; ++ c->time_base.num = 1; ++ c->gop_size = 12; /* emit one intra frame every twelve frames at most */ ++ c->pix_fmt = STREAM_PIX_FMT; ++ if (c->codec_id == CODEC_ID_MPEG2VIDEO) { ++ /* just for testing, we also add B frames */ ++ c->max_b_frames = 2; ++ } ++ if (c->codec_id == CODEC_ID_MPEG1VIDEO){ ++ /* Needed to avoid using macroblocks in which some coeffs overflow. ++ This does not happen with normal video, it just happens here as ++ the motion of the chroma plane does not match the luma plane. */ ++ c->mb_decision=2; ++ } ++ // some formats want stream headers to be separate ++ if (oc->oformat->flags & AVFMT_GLOBALHEADER) ++ c->flags |= CODEC_FLAG_GLOBAL_HEADER; ++ ++ return st; ++} ++ ++static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height) ++{ ++ AVFrame *picture; ++ uint8_t *picture_buf; ++ int size; ++ ++ picture = avcodec_alloc_frame(); ++ if (!picture) ++ return NULL; ++ size = avpicture_get_size(pix_fmt, width, height); ++ picture_buf = av_malloc(size); ++ if (!picture_buf) { ++ av_free(picture); ++ return NULL; ++ } ++ avpicture_fill((AVPicture *)picture, picture_buf, ++ pix_fmt, width, height); ++ return picture; ++} ++ ++static void open_video(AVFormatContext *oc, AVStream *st) ++{ ++ AVCodec *codec; ++ AVCodecContext *c; ++ ++ c = st->codec; ++ ++ /* find the video encoder */ ++ codec = avcodec_find_encoder(c->codec_id); ++ if (!codec) { ++ fprintf(stderr, "codec not found\n"); ++ exit(1); ++ } ++ ++ /* open the codec */ ++ if (avcodec_open(c, codec) < 0) { ++ fprintf(stderr, "could not open codec\n"); ++ exit(1); ++ } ++ ++ video_outbuf = NULL; ++ if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { ++ /* allocate output buffer */ ++ /* XXX: API change will be done */ ++ /* buffers passed into lav* can be allocated any way you prefer, ++ as long as they're aligned enough for the architecture, and ++ they're freed appropriately (such as using av_free for buffers ++ allocated with av_malloc) */ ++ video_outbuf_size = 200000; ++ video_outbuf = av_malloc(video_outbuf_size); ++ } ++ ++ /* allocate the encoded raw picture */ ++ picture = alloc_picture(c->pix_fmt, c->width, c->height); ++ if (!picture) { ++ fprintf(stderr, "Could not allocate picture\n"); ++ exit(1); ++ } ++ ++ /* if the output format is not YUV420P, then a temporary YUV420P ++ picture is needed too. It is then converted to the required ++ output format */ ++ tmp_picture = NULL; ++ if (c->pix_fmt != PIX_FMT_YUV420P) { ++ tmp_picture = alloc_picture(PIX_FMT_YUV420P, c->width, c->height); ++ if (!tmp_picture) { ++ fprintf(stderr, "Could not allocate temporary picture\n"); ++ exit(1); ++ } ++ } ++} ++ ++/* prepare a dummy image */ ++static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height) ++{ ++ int x, y, i; ++ ++ i = frame_index; ++ ++ /* Y */ ++ for (y = 0; y < height; y++) { ++ for (x = 0; x < width; x++) { ++ pict->data[0][y * pict->linesize[0] + x] = x + y + i * 3; ++ } ++ } ++ ++ /* Cb and Cr */ ++ for (y = 0; y < height/2; y++) { ++ for (x = 0; x < width/2; x++) { ++ pict->data[1][y * pict->linesize[1] + x] = 128 + y + i * 2; ++ pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5; ++ } ++ } ++} ++ ++static void write_video_frame(AVFormatContext *oc, AVStream *st) ++{ ++ int out_size, ret; ++ AVCodecContext *c; ++ static struct SwsContext *img_convert_ctx; ++ ++ c = st->codec; ++ ++ if (frame_count >= STREAM_NB_FRAMES) { ++ /* no more frame to compress. The codec has a latency of a few ++ frames if using B frames, so we get the last frames by ++ passing the same picture again */ ++ } else { ++ if (c->pix_fmt != PIX_FMT_YUV420P) { ++ /* as we only generate a YUV420P picture, we must convert it ++ to the codec pixel format if needed */ ++ if (img_convert_ctx == NULL) { ++ img_convert_ctx = sws_getContext(c->width, c->height, ++ PIX_FMT_YUV420P, ++ c->width, c->height, ++ c->pix_fmt, ++ sws_flags, NULL, NULL, NULL); ++ if (img_convert_ctx == NULL) { ++ fprintf(stderr, "Cannot initialize the conversion context\n"); ++ exit(1); ++ } ++ } ++ fill_yuv_image(tmp_picture, frame_count, c->width, c->height); ++ sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize, ++ 0, c->height, picture->data, picture->linesize); ++ } else { ++ fill_yuv_image(picture, frame_count, c->width, c->height); ++ } ++ } ++ ++ ++ if (oc->oformat->flags & AVFMT_RAWPICTURE) { ++ /* raw video case. The API will change slightly in the near ++ future for that. */ ++ AVPacket pkt; ++ av_init_packet(&pkt); ++ ++ pkt.flags |= AV_PKT_FLAG_KEY; ++ pkt.stream_index = st->index; ++ pkt.data = (uint8_t *)picture; ++ pkt.size = sizeof(AVPicture); ++ ++ ret = av_interleaved_write_frame(oc, &pkt); ++ } else { ++ /* encode the image */ ++ out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture); ++ /* if zero size, it means the image was buffered */ ++ if (out_size > 0) { ++ AVPacket pkt; ++ av_init_packet(&pkt); ++ ++ if (c->coded_frame->pts != AV_NOPTS_VALUE) ++ pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); ++ if(c->coded_frame->key_frame) ++ pkt.flags |= AV_PKT_FLAG_KEY; ++ pkt.stream_index = st->index; ++ pkt.data = video_outbuf; ++ pkt.size = out_size; ++ ++ /* write the compressed frame in the media file */ ++ ret = av_interleaved_write_frame(oc, &pkt); ++ } else { ++ ret = 0; ++ } ++ } ++ if (ret != 0) { ++ fprintf(stderr, "Error while writing video frame\n"); ++ exit(1); ++ } ++ frame_count++; ++} ++ ++static void close_video(AVFormatContext *oc, AVStream *st) ++{ ++ avcodec_close(st->codec); ++ av_free(picture->data[0]); ++ av_free(picture); ++ if (tmp_picture) { ++ av_free(tmp_picture->data[0]); ++ av_free(tmp_picture); ++ } ++ av_free(video_outbuf); ++} ++ ++/**************************************************************/ ++/* media file output */ ++ ++int main(int argc, char **argv) ++{ ++ const char *filename; ++ AVOutputFormat *fmt; ++ AVFormatContext *oc; ++ AVStream *audio_st, *video_st; ++ double audio_pts, video_pts; ++ int i; ++ ++ /* initialize libavcodec, and register all codecs and formats */ ++ av_register_all(); ++ ++ if (argc != 2) { ++ printf("usage: %s output_file\n" ++ "API example program to output a media file with libavformat.\n" ++ "The output format is automatically guessed according to the file extension.\n" ++ "Raw images can also be output by using '%%d' in the filename\n" ++ "\n", argv[0]); ++ return 1; ++ } ++ ++ filename = argv[1]; ++ ++ /* allocate the output media context */ ++ avformat_alloc_output_context2(&oc, NULL, NULL, filename); ++ if (!oc) { ++ printf("Could not deduce output format from file extension: using MPEG.\n"); ++ avformat_alloc_output_context2(&oc, NULL, "mpeg", filename); ++ } ++ if (!oc) { ++ return 1; ++ } ++ fmt = oc->oformat; ++ ++ /* add the audio and video streams using the default format codecs ++ and initialize the codecs */ ++ video_st = NULL; ++ audio_st = NULL; ++ if (fmt->video_codec != CODEC_ID_NONE) { ++ video_st = add_video_stream(oc, fmt->video_codec); ++ } ++ if (fmt->audio_codec != CODEC_ID_NONE) { ++ audio_st = add_audio_stream(oc, fmt->audio_codec); ++ } ++ ++ av_dump_format(oc, 0, filename, 1); ++ ++ /* now that all the parameters are set, we can open the audio and ++ video codecs and allocate the necessary encode buffers */ ++ if (video_st) ++ open_video(oc, video_st); ++ if (audio_st) ++ open_audio(oc, audio_st); ++ ++ /* open the output file, if needed */ ++ if (!(fmt->flags & AVFMT_NOFILE)) { ++ if (avio_open(&oc->pb, filename, AVIO_FLAG_WRITE) < 0) { ++ fprintf(stderr, "Could not open '%s'\n", filename); ++ return 1; ++ } ++ } ++ ++ /* write the stream header, if any */ ++ av_write_header(oc); ++ picture->pts = 0; ++ for(;;) { ++ /* compute current audio and video time */ ++ if (audio_st) ++ audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den; ++ else ++ audio_pts = 0.0; ++ ++ if (video_st) ++ video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den; ++ else ++ video_pts = 0.0; ++ ++ if ((!audio_st || audio_pts >= STREAM_DURATION) && ++ (!video_st || video_pts >= STREAM_DURATION)) ++ break; ++ ++ /* write interleaved audio and video frames */ ++ if (!video_st || (video_st && audio_st && audio_pts < video_pts)) { ++ write_audio_frame(oc, audio_st); ++ } else { ++ write_video_frame(oc, video_st); ++ picture->pts++; ++ } ++ } ++ ++ /* write the trailer, if any. the trailer must be written ++ * before you close the CodecContexts open when you wrote the ++ * header; otherwise write_trailer may try to use memory that ++ * was freed on av_codec_close() */ ++ av_write_trailer(oc); ++ ++ /* close each codec */ ++ if (video_st) ++ close_video(oc, video_st); ++ if (audio_st) ++ close_audio(oc, audio_st); ++ ++ /* free the streams */ ++ for(i = 0; i < oc->nb_streams; i++) { ++ av_freep(&oc->streams[i]->codec); ++ av_freep(&oc->streams[i]); ++ } ++ ++ if (!(fmt->flags & AVFMT_NOFILE)) { ++ /* close the output file */ ++ avio_close(oc->pb); ++ } ++ ++ /* free the stream */ ++ av_free(oc); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/faq.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/faq.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/faq.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/faq.texi 2012-05-14 14:08:53.149316132 +0200 +@@ -11,22 +11,6 @@ + + @chapter General Questions + +-@section When will the next FFmpeg version be released? / Why are FFmpeg releases so few and far between? +- +-Like most open source projects FFmpeg suffers from a certain lack of +-manpower. For this reason the developers have to prioritize the work +-they do and putting out releases is not at the top of the list, fixing +-bugs and reviewing patches takes precedence. Please don't complain or +-request more timely and/or frequent releases unless you are willing to +-help out creating them. +- +-@section I have a problem with an old version of FFmpeg; where should I report it? +-Nowhere. We do not support old FFmpeg versions in any way, we simply lack +-the time, motivation and manpower to do so. If you have a problem with an +-old version of FFmpeg, upgrade to the latest Subversion snapshot. If you +-still experience the problem, then you can report it according to the +-guidelines in @url{http://ffmpeg.org/bugreports.html}. +- + @section Why doesn't FFmpeg support feature [xyz]? + + Because no one has taken on that task yet. FFmpeg development is +@@ -40,30 +24,6 @@ + Moreover FFmpeg strives to support all codecs natively. + A DLL loader is not conducive to that goal. + +-@section My bug report/mail to ffmpeg-devel/user has not received any replies. +- +-Likely reasons +-@itemize +-@item We are busy and haven't had time yet to read your report or +-investigate the issue. +-@item You didn't follow @url{http://ffmpeg.org/bugreports.html}. +-@item You didn't use Subversion HEAD. +-@item You reported a segmentation fault without gdb output. +-@item You describe a problem but not how to reproduce it. +-@item It's unclear if you use ffmpeg as command line tool or use +-libav* from another application. +-@item You speak about a video having problems on playback but +-not what you use to play it. +-@item We have no faint clue what you are talking about besides +-that it is related to FFmpeg. +-@end itemize +- +-@section Is there a forum for FFmpeg? I do not like mailing lists. +- +-You may view our mailing lists with a more forum-alike look here: +-@url{http://dir.gmane.org/gmane.comp.video.ffmpeg.user}, +-but, if you post, please remember that our mailing list rules still apply there. +- + @section I cannot read this file although this format seems to be supported by ffmpeg. + + Even if ffmpeg can read the container format, it may not support all its +@@ -87,7 +47,7 @@ + .asf only + @item mpeg4 + Only if you have some MPEG-4 codec like ffdshow or Xvid installed. +-@item mpeg1 ++@item mpeg1video + .mpg only + @end table + Note, ASF files often have .wmv or .wma extensions in Windows. It should also +@@ -99,9 +59,9 @@ + @table @option + @item adpcm_ima_wav + @item adpcm_ms +-@item pcm ++@item pcm_s16le + always +-@item mp3 ++@item libmp3lame + If some MP3 codec like LAME is installed. + @end table + +@@ -123,7 +83,8 @@ + + @section ffmpeg does not work; what is wrong? + +-Try a @code{make distclean} in the ffmpeg source directory before the build. If this does not help see ++Try a @code{make distclean} in the ffmpeg source directory before the build. ++If this does not help see + (@url{http://ffmpeg.org/bugreports.html}). + + @section How do I encode single pictures into movies? +@@ -147,7 +108,7 @@ + @file{img001.jpg}, @file{img002.jpg} and so on. + + @example +- x=1; for i in *jpg; do counter=$(printf %03d $x); ln "$i" /tmp/img"$counter".jpg; x=$(($x+1)); done ++ x=1; for i in *jpg; do counter=$(printf %03d $x); ln -s "$i" /tmp/img"$counter".jpg; x=$(($x+1)); done + @end example + + If you want to sequence them by oldest modified first, substitute +@@ -174,15 +135,15 @@ + + Instead of relying on file format self-recognition, you may also use + @table @option +-@item -vcodec ppm +-@item -vcodec png +-@item -vcodec mjpeg ++@item -c:v ppm ++@item -c:v png ++@item -c:v mjpeg + @end table + to force the encoding. + + Applying that to the previous example: + @example +- ffmpeg -i movie.mpg -f image2 -vcodec mjpeg menu%d.jpg ++ ffmpeg -i movie.mpg -f image2 -c:v mjpeg menu%d.jpg + @end example + + Beware that there is no "jpeg" codec. Use "mjpeg" instead. +@@ -201,59 +162,21 @@ + + Try '-f image2 test%d.jpg'. + +-@section Why can I not change the framerate? ++@section Why can I not change the frame rate? + +-Some codecs, like MPEG-1/2, only allow a small number of fixed framerates. +-Choose a different codec with the -vcodec command line option. ++Some codecs, like MPEG-1/2, only allow a small number of fixed frame rates. ++Choose a different codec with the -c:v command line option. + + @section How do I encode Xvid or DivX video with ffmpeg? + + Both Xvid and DivX (version 4+) are implementations of the ISO MPEG-4 + standard (note that there are many other coding formats that use this +-same standard). Thus, use '-vcodec mpeg4' to encode in these formats. The ++same standard). Thus, use '-c:v mpeg4' to encode in these formats. The + default fourcc stored in an MPEG-4-coded file will be 'FMP4'. If you want + a different fourcc, use the '-vtag' option. E.g., '-vtag xvid' will + force the fourcc 'xvid' to be stored as the video fourcc rather than the + default. + +-@section How do I encode videos which play on the iPod? +- +-@table @option +-@item needed stuff +--acodec libfaac -vcodec mpeg4 width<=320 height<=240 +-@item working stuff +-mv4, title +-@item non-working stuff +-B-frames +-@item example command line +-ffmpeg -i input -acodec libfaac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +mv4 -trellis 2 -aic 2 -cmp 2 -subcmp 2 -s 320x180 -metadata title=X output.mp4 +-@end table +- +-@section How do I encode videos which play on the PSP? +- +-@table @option +-@item needed stuff +--acodec libfaac -vcodec mpeg4 width*height<=76800 width%16=0 height%16=0 -ar 24000 -r 30000/1001 or 15000/1001 -f psp +-@item working stuff +-mv4, title +-@item non-working stuff +-B-frames +-@item example command line +-ffmpeg -i input -acodec libfaac -ab 128kb -vcodec mpeg4 -b 1200kb -ar 24000 -mbd 2 -flags +mv4 -trellis 2 -aic 2 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -metadata title=X -f psp output.mp4 +-@item needed stuff for H.264 +--acodec libfaac -vcodec libx264 width*height<=76800 width%16=0? height%16=0? -ar 48000 -coder 1 -r 30000/1001 or 15000/1001 -f psp +-@item working stuff for H.264 +-title, loop filter +-@item non-working stuff for H.264 +-CAVLC +-@item example command line +-ffmpeg -i input -acodec libfaac -ab 128kb -vcodec libx264 -b 1200kb -ar 48000 -mbd 2 -coder 1 -cmp 2 -subcmp 2 -s 368x192 -r 30000/1001 -metadata title=X -f psp -flags loop -trellis 2 -partitions parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 output.mp4 +-@item higher resolution for newer PSP firmwares, width<=480, height<=272 +--vcodec libx264 -level 21 -coder 1 -f psp +-@item example command line +-ffmpeg -i input -acodec libfaac -ab 128kb -ac 2 -ar 48000 -vcodec libx264 -level 21 -b 640kb -coder 1 -f psp -flags +loop -trellis 2 -partitions +parti4x4+parti8x8+partp4x4+partp8x8+partb8x8 -g 250 -s 480x272 output.mp4 +-@end table +- + @section Which are good parameters for encoding high quality MPEG-4? + + '-mbd rd -flags +mv4+aic -trellis 2 -cmp 2 -subcmp 2 -g 300 -pass 1/2', +@@ -280,12 +203,13 @@ + @example + DirectShowSource("C:\path to your file\yourfile.asf") + @end example +-... and then feed that text file to FFmpeg: ++... and then feed that text file to ffmpeg: + @example + ffmpeg -i input.avs + @end example + +-For ANY other help on Avisynth, please visit @url{http://www.avisynth.org/}. ++For ANY other help on Avisynth, please visit the ++@uref{http://www.avisynth.org/, Avisynth homepage}. + + @section How can I join video files? + +@@ -298,13 +222,13 @@ + format of choice. + + @example +-ffmpeg -i input1.avi -sameq intermediate1.mpg +-ffmpeg -i input2.avi -sameq intermediate2.mpg ++ffmpeg -i input1.avi -same_quant intermediate1.mpg ++ffmpeg -i input2.avi -same_quant intermediate2.mpg + cat intermediate1.mpg intermediate2.mpg > intermediate_all.mpg +-ffmpeg -i intermediate_all.mpg -sameq output.avi ++ffmpeg -i intermediate_all.mpg -same_quant output.avi + @end example + +-Notice that you should either use @code{-sameq} or set a reasonably high ++Notice that you should either use @code{-same_quant} or set a reasonably high + bitrate for your intermediate and output files, if you want to preserve + video quality. + +@@ -314,10 +238,10 @@ + @example + mkfifo intermediate1.mpg + mkfifo intermediate2.mpg +-ffmpeg -i input1.avi -sameq -y intermediate1.mpg < /dev/null & +-ffmpeg -i input2.avi -sameq -y intermediate2.mpg < /dev/null & ++ffmpeg -i input1.avi -same_quant -y intermediate1.mpg < /dev/null & ++ffmpeg -i input2.avi -same_quant -y intermediate2.mpg < /dev/null & + cat intermediate1.mpg intermediate2.mpg |\ +-ffmpeg -f mpeg -i - -sameq -vcodec mpeg4 -acodec libmp3lame output.avi ++ffmpeg -f mpeg -i - -same_quant -c:v mpeg4 -acodec libmp3lame output.avi + @end example + + Similarly, the yuv4mpegpipe format, and the raw video, raw audio codecs also +@@ -344,27 +268,47 @@ + cat temp1.v temp2.v > all.v & + ffmpeg -f u16le -acodec pcm_s16le -ac 2 -ar 44100 -i all.a \ + -f yuv4mpegpipe -i all.v \ +- -sameq -y output.flv ++ -same_quant -y output.flv + rm temp[12].[av] all.[av] + @end example + +-@section FFmpeg does not adhere to the -maxrate setting, some frames are bigger than maxrate/fps. ++@section -profile option fails when encoding H.264 video with AAC audio ++ ++@command{ffmpeg} prints an error like ++ ++@example ++Undefined constant or missing '(' in 'baseline' ++Unable to parse option value "baseline" ++Error setting option profile to value baseline. ++@end example ++ ++Short answer: write @option{-profile:v} instead of @option{-profile}. + +-Read the MPEG spec about video buffer verifier. ++Long answer: this happens because the @option{-profile} option can apply to both ++video and audio. Specifically the AAC encoder also defines some profiles, none ++of which are named @var{baseline}. + +-@section I want CBR, but no matter what I do frame sizes differ. ++The solution is to apply the @option{-profile} option to the video stream only ++by using @url{http://ffmpeg.org/ffmpeg.html#Stream-specifiers-1, Stream specifiers}. ++Appending @code{:v} to it will do exactly that. + +-You do not understand what CBR is, please read the MPEG spec. +-Read about video buffer verifier and constant bitrate. +-The one sentence summary is that there is a buffer and the input rate is +-constant, the output can vary as needed. ++@section Using @option{-f lavfi}, audio becomes mono for no apparent reason. + +-@section How do I check if a stream is CBR? ++Use @option{-dumpgraph -} to find out exactly where the channel layout is ++lost. + +-To quote the MPEG-2 spec: +-"There is no way to tell that a bitstream is constant bitrate without +-examining all of the vbv_delay values and making complicated computations." ++Most likely, it is through @code{auto-inserted aconvert}. Try to understand ++why the converting filter was needed at that place. + ++Just before the output is a likely place, as @option{-f lavfi} currently ++only support packed S16. ++ ++Then insert the correct @code{aconvert} explicitly in the filter graph, ++specifying the exact format. ++ ++@example ++aconvert=s16:stereo:packed ++@end example + + @chapter Development + +@@ -412,34 +356,26 @@ + + No. These tools are too bloated and they complicate the build. + +-@section Why not rewrite ffmpeg in object-oriented C++? ++@section Why not rewrite FFmpeg in object-oriented C++? + + FFmpeg is already organized in a highly modular manner and does not need to + be rewritten in a formal object language. Further, many of the developers + favor straight C; it works for them. For more arguments on this matter, +-read "Programming Religion" at (@url{http://www.tux.org/lkml/#s15}). ++read @uref{http://www.tux.org/lkml/#s15, "Programming Religion"}. + + @section Why are the ffmpeg programs devoid of debugging symbols? + + The build process creates ffmpeg_g, ffplay_g, etc. which contain full debug + information. Those binaries are stripped to create ffmpeg, ffplay, etc. If +-you need the debug information, used the *_g versions. ++you need the debug information, use the *_g versions. + + @section I do not like the LGPL, can I contribute code under the GPL instead? + + Yes, as long as the code is optional and can easily and cleanly be placed +-under #if CONFIG_GPL without breaking anything. So for example a new codec ++under #if CONFIG_GPL without breaking anything. So, for example, a new codec + or filter would be OK under GPL while a bug fix to LGPL code would not. + +-@section I want to compile xyz.c alone but my compiler produced many errors. +- +-Common code is in its own files in libav* and is used by the individual +-codecs. They will not work without the common parts, you have to compile +-the whole libav*. If you wish, disable some parts with configure switches. +-You can also try to hack it and remove more, but if you had problems fixing +-the compilation failure then you are probably not qualified for this. +- +-@section I'm using libavcodec from within my C++ application but the linker complains about missing symbols which seem to be available. ++@section I'm using FFmpeg from within my C++ application but the linker complains about missing symbols which seem to be available. + + FFmpeg is a pure C project, so to use the libraries within your C++ application + you need to explicitly state that you are using a C library. You can do this by +@@ -447,19 +383,16 @@ + + See @url{http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html#faq-32.3} + ++@section I'm using libavutil from within my C++ application but the compiler complains about 'UINT64_C' was not declared in this scope ++ ++FFmpeg is a pure C project using C99 math features, in order to enable C++ ++to use them you have to append -D__STDC_CONSTANT_MACROS to your CXXFLAGS ++ + @section I have a file in memory / a API different from *open/*read/ libc how do I use it with libavformat? + + You have to implement a URLProtocol, see @file{libavformat/file.c} in + FFmpeg and @file{libmpdemux/demux_lavf.c} in MPlayer sources. + +-@section I get "No compatible shell script interpreter found." in MSys. +- +-The standard MSys bash (2.04) is broken. You need to install 2.05 or later. +- +-@section I get "./configure: line : pr: command not found" in MSys. +- +-The standard MSys install doesn't come with pr. You need to get it from the coreutils package. +- + @section Where can I find libav* headers for Pascal/Delphi? + + see @url{http://www.iversenit.dk/dev/ffmpeg-headers/} +@@ -474,12 +407,24 @@ + other. You have to @emph{demux} RTP before feeding the payload to libavcodec. + In this specific case please look at RFC 4629 to see how it should be done. + +-@section AVStream.r_frame_rate is wrong, it is much larger than the framerate. ++@section AVStream.r_frame_rate is wrong, it is much larger than the frame rate. + +-r_frame_rate is NOT the average framerate, it is the smallest framerate ++r_frame_rate is NOT the average frame rate, it is the smallest frame rate + that can accurately represent all timestamps. So no, it is not + wrong if it is larger than the average! + For example, if you have mixed 25 and 30 fps content, then r_frame_rate + will be 150. + ++@section Why is @code{make fate} not running all tests? ++ ++Make sure you have the fate-suite samples and the @code{SAMPLES} Make variable ++or @code{FATE_SAMPLES} environment variable or the @code{--samples} ++@command{configure} option is set to the right path. ++ ++@section Why is @code{make fate} not finding the samples? ++ ++Do you happen to have a @code{~} character in the samples path to indicate a ++home directory? The value is used in ways where the shell cannot expand it, ++causing FATE to not find files. Just replace @code{~} by the full path. ++ + @bye +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/fate.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/fate.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/fate.texi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/fate.texi 2012-05-14 14:08:53.150316152 +0200 +@@ -0,0 +1,174 @@ ++\input texinfo @c -*- texinfo -*- ++ ++@settitle FATE Automated Testing Environment ++@titlepage ++@center @titlefont{FATE Automated Testing Environment} ++@end titlepage ++ ++@node Top ++@top ++ ++@contents ++ ++@chapter Introduction ++ ++ FATE is an extended regression suite on the client-side and a means ++for results aggregation and presentation on the server-side. ++ ++ The first part of this document explains how you can use FATE from ++your FFmpeg source directory to test your ffmpeg binary. The second ++part describes how you can run FATE to submit the results to FFmpeg's ++FATE server. ++ ++ In any way you can have a look at the publicly viewable FATE results ++by visiting this website: ++ ++ @url{http://fate.ffmpeg.org/} ++ ++ This is especially recommended for all people contributing source ++code to FFmpeg, as it can be seen if some test on some platform broke ++with there recent contribution. This usually happens on the platforms ++the developers could not test on. ++ ++ The second part of this document describes how you can run FATE to ++submit your results to FFmpeg's FATE server. If you want to submit your ++results be sure to check that your combination of CPU, OS and compiler ++is not already listed on the above mentioned website. ++ ++ In the third part you can find a comprehensive listing of FATE makefile ++targets and variables. ++ ++ ++@chapter Using FATE from your FFmpeg source directory ++ ++ If you want to run FATE on your machine you need to have the samples ++in place. You can get the samples via the build target fate-rsync. ++Use this command from the top-level source directory: ++ ++@example ++make fate-rsync SAMPLES=fate-suite/ ++make fate SAMPLES=fate-suite/ ++@end example ++ ++ The above commands set the samples location by passing a makefile ++variable via command line. It is also possible to set the samples ++location at source configuration time by invoking configure with ++`--samples='. Afterwards you can ++invoke the makefile targets without setting the SAMPLES makefile ++variable. This is illustrated by the following commands: ++ ++@example ++./configure --samples=fate-suite/ ++make fate-rsync ++make fate ++@end example ++ ++ Yet another way to tell FATE about the location of the sample ++directory is by making sure the environment variable FATE_SAMPLES ++contains the path to your samples directory. This can be achieved ++by e.g. putting that variable in your shell profile or by setting ++it in your interactive session. ++ ++@example ++FATE_SAMPLES=fate-suite/ make fate ++@end example ++ ++@float NOTE ++Do not put a '~' character in the samples path to indicate a home ++directory. Because of shell nuances, this will cause FATE to fail. ++@end float ++ ++ ++@chapter Submitting the results to the FFmpeg result aggregation server ++ ++ To submit your results to the server you should run fate through the ++shell script tests/fate.sh from the FFmpeg sources. This script needs ++to be invoked with a configuration file as its first argument. ++ ++@example ++tests/fate.sh /path/to/fate_config ++@end example ++ ++ A configuration file template with comments describing the individual ++configuration variables can be found at @file{tests/fate_config.sh.template}. ++ ++@ifhtml ++ The mentioned configuration template is also available here: ++@verbatiminclude ../tests/fate_config.sh.template ++@end ifhtml ++ ++ Create a configuration that suits your needs, based on the configuration ++template. The `slot' configuration variable can be any string that is not ++yet used, but it is suggested that you name it adhering to the following ++pattern ---. The configuration file ++itself will be sourced in a shell script, therefore all shell features may ++be used. This enables you to setup the environment as you need it for your ++build. ++ ++ For your first test runs the `fate_recv' variable should be empty or ++commented out. This will run everything as normal except that it will omit ++the submission of the results to the server. The following files should be ++present in $workdir as specified in the configuration file: ++ ++@itemize ++ @item configure.log ++ @item compile.log ++ @item test.log ++ @item report ++ @item version ++@end itemize ++ ++ When you have everything working properly you can create an SSH key and ++send its public part to the FATE server administrator. ++ ++ Configure your SSH client to use public key authentication with that key ++when connecting to the FATE server. Also do not forget to check the identity ++of the server and to accept its host key. This can usually be achieved by ++running your SSH client manually and killing it after you accepted the key. ++The FATE server's fingerprint is: ++ ++ b1:31:c8:79:3f:04:1d:f8:f2:23:26:5a:fd:55:fa:92 ++ ++ The only thing left is to automate the execution of the fate.sh script and ++the synchronisation of the samples directory. ++ ++ ++@chapter FATE makefile targets and variables ++ ++@section Makefile targets ++ ++@table @option ++@item fate-rsync ++ Download/synchronize sample files to the configured samples directory. ++ ++@item fate-list ++ Will list all fate/regression test targets. ++ ++@item fate ++ Run the FATE test suite (requires the fate-suite dataset). ++@end table ++ ++@section Makefile variables ++ ++@table @option ++@item V ++ Verbosity level, can be set to 0, 1 or 2. ++ @itemize ++ @item 0: show just the test arguments ++ @item 1: show just the command used in the test ++ @item 2: show everything ++ @end itemize ++ ++@item SAMPLES ++ Specify or override the path to the FATE samples at make time, it has a ++ meaning only while running the regression tests. ++ ++@item THREADS ++ Specify how many threads to use while running regression tests, it is ++ quite useful to detect thread-related regressions. ++@end table ++ ++Example: ++@example ++make V=1 SAMPLES=/var/fate/samples THREADS=2 fate ++@end example +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffmpeg.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffmpeg.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffmpeg.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffmpeg.texi 2012-05-14 14:08:53.154316232 +0200 +@@ -1,8 +1,8 @@ + \input texinfo @c -*- texinfo -*- + +-@settitle FFmpeg Documentation ++@settitle ffmpeg Documentation + @titlepage +-@center @titlefont{FFmpeg Documentation} ++@center @titlefont{ffmpeg Documentation} + @end titlepage + + @top +@@ -15,34 +15,50 @@ + + @example + @c man begin SYNOPSIS +-ffmpeg [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}... ++ffmpeg [global options] [[infile options][@option{-i} @var{infile}]]... @{[outfile options] @var{outfile}@}... + @c man end + @end example + + @chapter Description + @c man begin DESCRIPTION + +-FFmpeg is a very fast video and audio converter. It can also grab from +-a live audio/video source. +- +-The command line interface is designed to be intuitive, in the sense +-that FFmpeg tries to figure out all parameters that can possibly be +-derived automatically. You usually only have to specify the target +-bitrate you want. +- +-FFmpeg can also convert from any sample rate to any other, and resize +-video on the fly with a high quality polyphase filter. ++ffmpeg is a very fast video and audio converter that can also grab from ++a live audio/video source. It can also convert between arbitrary sample ++rates and resize video on the fly with a high quality polyphase filter. ++ ++ffmpeg reads from an arbitrary number of input "files" (which can be regular ++files, pipes, network streams, grabbing devices, etc.), specified by the ++@code{-i} option, and writes to an arbitrary number of output "files", which are ++specified by a plain output filename. Anything found on the command line which ++cannot be interpreted as an option is considered to be an output filename. ++ ++Each input or output file can in principle contain any number of streams of ++different types (video/audio/subtitle/attachment/data). Allowed number and/or ++types of streams can be limited by the container format. Selecting, which ++streams from which inputs go into output, is done either automatically or with ++the @code{-map} option (see the Stream selection chapter). ++ ++To refer to input files in options, you must use their indices (0-based). E.g. ++the first input file is @code{0}, the second is @code{1} etc. Similarly, streams ++within a file are referred to by their indices. E.g. @code{2:3} refers to the ++fourth stream in the third input file. See also the Stream specifiers chapter. + + As a general rule, options are applied to the next specified + file. Therefore, order is important, and you can have the same + option on the command line multiple times. Each occurrence is + then applied to the next input or output file. ++Exceptions from this rule are the global options (e.g. verbosity level), ++which should be specified first. ++ ++Do not mix input and output files -- first specify all input files, then all ++output files. Also do not mix options which belong to different files. All ++options apply ONLY to the next input or output file and are reset between files. + + @itemize + @item + To set the video bitrate of the output file to 64kbit/s: + @example +-ffmpeg -i input.avi -b 64k output.avi ++ffmpeg -i input.avi -b:v 64k output.avi + @end example + + @item +@@ -61,51 +77,90 @@ + + The format option may be needed for raw input files. + +-By default, FFmpeg tries to convert as losslessly as possible: It +-uses the same audio and video parameters for the outputs as the one +-specified for the inputs. +- + @c man end DESCRIPTION + ++@chapter Stream selection ++@c man begin STREAM SELECTION ++ ++By default ffmpeg includes only one stream of each type (video, audio, subtitle) ++present in the input files and adds them to each output file. It picks the ++"best" of each based upon the following criteria; for video it is the stream ++with the highest resolution, for audio the stream with the most channels, for ++subtitle it's the first subtitle stream. In the case where several streams of ++the same type rate equally, the lowest numbered stream is chosen. ++ ++You can disable some of those defaults by using @code{-vn/-an/-sn} options. For ++full manual control, use the @code{-map} option, which disables the defaults just ++described. ++ ++@c man end STREAM SELECTION ++ + @chapter Options + @c man begin OPTIONS + +-@include fftools-common-opts.texi ++@include avtools-common-opts.texi + + @section Main options + + @table @option + +-@item -f @var{fmt} +-Force format. ++@item -f @var{fmt} (@emph{input/output}) ++Force input or output file format. The format is normally auto detected for input ++files and guessed from file extension for output files, so this option is not ++needed in most cases. + +-@item -i @var{filename} ++@item -i @var{filename} (@emph{input}) + input file name + +-@item -y +-Overwrite output files. ++@item -y (@emph{global}) ++Overwrite output files without asking. ++ ++@item -n (@emph{global}) ++Do not overwrite output files but exit if file exists. + +-@item -t @var{duration} +-Restrict the transcoded/captured video sequence +-to the duration specified in seconds. +-@code{hh:mm:ss[.xxx]} syntax is also supported. ++@item -c[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream}) ++@itemx -codec[:@var{stream_specifier}] @var{codec} (@emph{input/output,per-stream}) ++Select an encoder (when used before an output file) or a decoder (when used ++before an input file) for one or more streams. @var{codec} is the name of a ++decoder/encoder or a special value @code{copy} (output only) to indicate that ++the stream is not to be re-encoded. + +-@item -fs @var{limit_size} ++For example ++@example ++ffmpeg -i INPUT -map 0 -c:v libx264 -c:a copy OUTPUT ++@end example ++encodes all video streams with libx264 and copies all audio streams. ++ ++For each stream, the last matching @code{c} option is applied, so ++@example ++ffmpeg -i INPUT -map 0 -c copy -c:v:1 libx264 -c:a:137 libvorbis OUTPUT ++@end example ++will copy all the streams except the second video, which will be encoded with ++libx264, and the 138th audio, which will be encoded with libvorbis. ++ ++@item -t @var{duration} (@emph{output}) ++Stop writing the output after its duration reaches @var{duration}. ++@var{duration} may be a number in seconds, or in @code{hh:mm:ss[.xxx]} form. ++ ++@item -fs @var{limit_size} (@emph{output}) + Set the file size limit. + +-@item -ss @var{position} +-Seek to given time position in seconds. +-@code{hh:mm:ss[.xxx]} syntax is also supported. ++@item -ss @var{position} (@emph{input/output}) ++When used as an input option (before @code{-i}), seeks in this input file to ++@var{position}. When used as an output option (before an output filename), ++decodes but discards input until the timestamps reach @var{position}. This is ++slower, but more accurate. ++ ++@var{position} may be either in seconds or in @code{hh:mm:ss[.xxx]} form. + +-@item -itsoffset @var{offset} ++@item -itsoffset @var{offset} (@emph{input}) + Set the input time offset in seconds. + @code{[-]hh:mm:ss[.xxx]} syntax is also supported. +-This option affects all the input files that follow it. + The offset is added to the timestamps of the input files. + Specifying a positive offset means that the corresponding +-streams are delayed by 'offset' seconds. ++streams are delayed by @var{offset} seconds. + +-@item -timestamp @var{time} ++@item -timestamp @var{time} (@emph{output}) + Set the recording timestamp in the container. + The syntax for @var{time} is: + @example +@@ -117,21 +172,31 @@ + If the year-month-day part is not specified it takes the current + year-month-day. + +-@item -metadata @var{key}=@var{value} ++@item -metadata[:metadata_specifier] @var{key}=@var{value} (@emph{output,per-metadata}) + Set a metadata key/value pair. + ++An optional @var{metadata_specifier} may be given to set metadata ++on streams or chapters. See @code{-map_metadata} documentation for ++details. ++ ++This option overrides metadata set with @code{-map_metadata}. It is ++also possible to delete metadata by using an empty value. ++ + For example, for setting the title in the output file: + @example + ffmpeg -i in.avi -metadata title="my title" out.flv + @end example + +-@item -v @var{number} +-Set the logging verbosity level. ++To set the language of the first audio stream: ++@example ++ffmpeg -i INPUT -metadata:s:a:1 language=eng OUTPUT ++@end example + +-@item -target @var{type} +-Specify target file type ("vcd", "svcd", "dvd", "dv", "dv50", "pal-vcd", +-"ntsc-svcd", ... ). All the format options (bitrate, codecs, +-buffer sizes) are then set automatically. You can just type: ++@item -target @var{type} (@emph{output}) ++Specify target file type (@code{vcd}, @code{svcd}, @code{dvd}, @code{dv}, ++@code{dv50}). @var{type} may be prefixed with @code{pal-}, @code{ntsc-} or ++@code{film-} to use the corresponding standard. All the format options ++(bitrate, codecs, buffer sizes) are then set automatically. You can just type: + + @example + ffmpeg -i myfile.avi -target vcd /tmp/vcd.mpg +@@ -144,31 +209,71 @@ + ffmpeg -i myfile.avi -target vcd -bf 2 /tmp/vcd.mpg + @end example + +-@item -dframes @var{number} +-Set the number of data frames to record. ++@item -dframes @var{number} (@emph{output}) ++Set the number of data frames to record. This is an alias for @code{-frames:d}. + +-@item -scodec @var{codec} +-Force subtitle codec ('copy' to copy stream). ++@item -frames[:@var{stream_specifier}] @var{framecount} (@emph{output,per-stream}) ++Stop writing to the stream after @var{framecount} frames. + +-@item -newsubtitle +-Add a new subtitle stream to the current output stream. ++@item -q[:@var{stream_specifier}] @var{q} (@emph{output,per-stream}) ++@itemx -qscale[:@var{stream_specifier}] @var{q} (@emph{output,per-stream}) ++Use fixed quality scale (VBR). The meaning of @var{q} is ++codec-dependent. + +-@item -slang @var{code} +-Set the ISO 639 language code (3 letters) of the current subtitle stream. ++@item -filter[:@var{stream_specifier}] @var{filter_graph} (@emph{output,per-stream}) ++@var{filter_graph} is a description of the filter graph to apply to ++the stream. Use @code{-filters} to show all the available filters ++(including also sources and sinks). ++@item -pre[:@var{stream_specifier}] @var{preset_name} (@emph{output,per-stream}) ++Specify the preset for matching stream(s). ++ ++@item -stats (@emph{global}) ++Print encoding progress/statistics. On by default. ++ ++@item -attach @var{filename} (@emph{output}) ++Add an attachment to the output file. This is supported by a few formats ++like Matroska for e.g. fonts used in rendering subtitles. Attachments ++are implemented as a specific type of stream, so this option will add ++a new stream to the file. It is then possible to use per-stream options ++on this stream in the usual way. Attachment streams created with this ++option will be created after all the other streams (i.e. those created ++with @code{-map} or automatic mappings). ++ ++Note that for Matroska you also have to set the mimetype metadata tag: ++@example ++ffmpeg -i INPUT -attach DejaVuSans.ttf -metadata:s:2 mimetype=application/x-truetype-font out.mkv ++@end example ++(assuming that the attachment stream will be third in the output file). ++ ++@item -dump_attachment[:@var{stream_specifier}] @var{filename} (@emph{input,per-stream}) ++Extract the matching attachment stream into a file named @var{filename}. If ++@var{filename} is empty, then the value of the @code{filename} metadata tag ++will be used. ++ ++E.g. to extract the first attachment to a file named 'out.ttf': ++@example ++ffmpeg -dump_attachment:t:0 out.ttf INPUT ++@end example ++To extract all attachments to files determined by the @code{filename} tag: ++@example ++ffmpeg -dump_attachment:t "" INPUT ++@end example ++ ++Technical note -- attachments are implemented as codec extradata, so this ++option can actually be used to extract extradata from any stream, not just ++attachments. + + @end table + + @section Video Options + + @table @option +-@item -b @var{bitrate} +-Set the video bitrate in bit/s (default = 200 kb/s). +-@item -vframes @var{number} +-Set the number of video frames to record. +-@item -r @var{fps} ++@item -vframes @var{number} (@emph{output}) ++Set the number of video frames to record. This is an alias for @code{-frames:v}. ++@item -r[:@var{stream_specifier}] @var{fps} (@emph{input/output,per-stream}) + Set frame rate (Hz value, fraction or abbreviation), (default = 25). +-@item -s @var{size} +-Set frame size. The format is @samp{wxh} (ffserver default = 160x128, ffmpeg default = same as source). ++@item -s[:@var{stream_specifier}] @var{size} (@emph{input/output,per-stream}) ++Set frame size. The format is @samp{wxh} (default - same as source). + The following abbreviations are recognized: + @table @samp + @item sqcif +@@ -231,8 +336,14 @@ + 1920x1080 + @end table + +-@item -aspect @var{aspect} +-Set aspect ratio (4:3, 16:9 or 1.3333, 1.7777). ++@item -aspect[:@var{stream_specifier}] @var{aspect} (@emph{output,per-stream}) ++Set the video display aspect ratio specified by @var{aspect}. ++ ++@var{aspect} can be a floating point number string, or a string of the ++form @var{num}:@var{den}, where @var{num} and @var{den} are the ++numerator and denominator of the aspect ratio. For example "4:3", ++"16:9", "1.3333", and "1.7777" are valid argument values. ++ + @item -croptop @var{size} + @item -cropbottom @var{size} + @item -cropleft @var{size} +@@ -247,7 +358,8 @@ + @item -padcolor @var{hex_color} + All the pad options have been removed. Use -vf + pad=width:height:x:y:color instead. +-@item -vn ++ ++@item -vn (@emph{output}) + Disable video recording. + @item -bt @var{tolerance} + Set video bitrate tolerance (in bits, default 4000k). +@@ -263,16 +375,18 @@ + Set min video bitrate (in bit/s). + Most useful in setting up a CBR encode: + @example +-ffmpeg -i myfile.avi -b 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v ++ffmpeg -i myfile.avi -b:v 4000k -minrate 4000k -maxrate 4000k -bufsize 1835k out.m2v + @end example + It is of little use elsewise. + @item -bufsize @var{size} + Set video buffer verifier buffer size (in bits). +-@item -vcodec @var{codec} +-Force video codec to @var{codec}. Use the @code{copy} special value to +-tell that the raw codec data must be copied as is. +-@item -sameq +-Use same video quality as source (implies VBR). ++@item -vcodec @var{codec} (@emph{output}) ++Set the video codec. This is an alias for @code{-codec:v}. ++@item -same_quant ++Use same quantizer as source (implies VBR). ++ ++Note that this is NOT SAME QUALITY. Do not use this option unless you know you ++need it. + + @item -pass @var{n} + Select the pass number (1 or 2). It is used to do two-pass +@@ -283,46 +397,41 @@ + On pass 1, you may just deactivate audio and set output to null, + examples for Windows and Unix: + @example +-ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y NUL +-ffmpeg -i foo.mov -vcodec libxvid -pass 1 -an -f rawvideo -y /dev/null ++ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y NUL ++ffmpeg -i foo.mov -c:v libxvid -pass 1 -an -f rawvideo -y /dev/null + @end example + +-@item -passlogfile @var{prefix} ++@item -passlogfile @var{prefix} (@emph{global}) + Set two-pass log file name prefix to @var{prefix}, the default file name + prefix is ``ffmpeg2pass''. The complete file name will be + @file{PREFIX-N.log}, where N is a number specific to the output +-stream. +- +-@item -newvideo +-Add a new video stream to the current output stream. ++stream + + @item -vlang @var{code} + Set the ISO 639 language code (3 letters) of the current video stream. + +-@item -vf @var{filter_graph} ++@item -vf @var{filter_graph} (@emph{output}) + @var{filter_graph} is a description of the filter graph to apply to + the input video. + Use the option "-filters" to show all the available filters (including +-also sources and sinks). ++also sources and sinks). This is an alias for @code{-filter:v}. + + @end table + + @section Advanced Video Options + + @table @option +-@item -pix_fmt @var{format} +-Set pixel format. Use 'list' as parameter to show all the supported ++@item -pix_fmt[:@var{stream_specifier}] @var{format} (@emph{input/output,per-stream}) ++Set pixel format. Use @code{-pix_fmts} to show all the supported + pixel formats. +-@item -sws_flags @var{flags} ++@item -sws_flags @var{flags} (@emph{input/output}) + Set SwScaler flags. + @item -g @var{gop_size} + Set the group of pictures size. + @item -intra +-Use only intra frames. ++deprecated, use -g 1 + @item -vdt @var{n} + Discard threshold. +-@item -qscale @var{q} +-Use fixed video quantizer scale (VBR). + @item -qmin @var{q} + minimum video quantizer scale (VBR) + @item -qmax @var{q} +@@ -394,8 +503,11 @@ + @item avgTex + @end table + +-@item -rc_override @var{override} +-rate control override for specific intervals ++@item -rc_override[:@var{stream_specifier}] @var{override} (@emph{output,per-stream}) ++Rate control override for specific intervals, formatted as "int,int,int" ++list separated with slashes. Two first values are the beginning and ++end frame numbers, last one is quantizer to use if positive, or quality ++factor if negative. + @item -me_method @var{method} + Set motion estimation method to @var{method}. + Available methods are (from lowest to best quality): +@@ -486,7 +598,7 @@ + macroblock decision + @table @samp + @item 0 +-FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in FFmpeg). ++FF_MB_DECISION_SIMPLE: Use mb_cmp (cannot change it yet in ffmpeg). + @item 1 + FF_MB_DECISION_BITS: Choose the one which needs the fewest bits. + @item 2 +@@ -520,123 +632,231 @@ + Dump video coding statistics to @file{vstats_HHMMSS.log}. + @item -vstats_file @var{file} + Dump video coding statistics to @var{file}. +-@item -top @var{n} ++@item -top[:@var{stream_specifier}] @var{n} (@emph{output,per-stream}) + top=1/bottom=0/auto=-1 field first + @item -dc @var{precision} + Intra_dc_precision. +-@item -vtag @var{fourcc/tag} +-Force video tag/fourcc. +-@item -qphist +-Show QP histogram. ++@item -vtag @var{fourcc/tag} (@emph{output}) ++Force video tag/fourcc. This is an alias for @code{-tag:v}. ++@item -qphist (@emph{global}) ++Show QP histogram + @item -vbsf @var{bitstream_filter} +-Bitstream filters available are "dump_extra", "remove_extra", "noise", "h264_mp4toannexb", "imxdump", "mjpegadump", "mjpeg2jpeg". +-@example +-ffmpeg -i h264.mp4 -vcodec copy -vbsf h264_mp4toannexb -an out.h264 +-@end example +-@item -force_key_frames @var{time}[,@var{time}...] ++Deprecated see -bsf ++@item -force_key_frames[:@var{stream_specifier}] @var{time}[,@var{time}...] (@emph{output,per-stream}) + Force key frames at the specified timestamps, more precisely at the first + frames after each specified time. + This option can be useful to ensure that a seek point is present at a + chapter mark or any other designated place in the output file. + The timestamps must be specified in ascending order. ++ ++@item -copyinkf[:@var{stream_specifier}] (@emph{output,per-stream}) ++When doing stream copy, copy also non-key frames found at the ++beginning. + @end table + + @section Audio Options + + @table @option +-@item -aframes @var{number} +-Set the number of audio frames to record. +-@item -ar @var{freq} +-Set the audio sampling frequency. For input streams it is set by +-default to 44100 Hz, for output streams it is set by default to the +-frequency of the input stream. If the input file has audio streams +-with different frequencies, the behaviour is undefined. +-@item -ab @var{bitrate} +-Set the audio bitrate in bit/s (default = 64k). +-@item -aq @var{q} +-Set the audio quality (codec-specific, VBR). +-@item -ac @var{channels} +-Set the number of audio channels. For input streams it is set by +-default to 1, for output streams it is set by default to the same +-number of audio channels in input. If the input file has audio streams +-with different channel count, the behaviour is undefined. +-@item -an ++@item -aframes @var{number} (@emph{output}) ++Set the number of audio frames to record. This is an alias for @code{-frames:a}. ++@item -ar[:@var{stream_specifier}] @var{freq} (@emph{input/output,per-stream}) ++Set the audio sampling frequency. For output streams it is set by ++default to the frequency of the corresponding input stream. For input ++streams this option only makes sense for audio grabbing devices and raw ++demuxers and is mapped to the corresponding demuxer options. ++@item -aq @var{q} (@emph{output}) ++Set the audio quality (codec-specific, VBR). This is an alias for -q:a. ++@item -ac[:@var{stream_specifier}] @var{channels} (@emph{input/output,per-stream}) ++Set the number of audio channels. For output streams it is set by ++default to the number of input audio channels. For input streams ++this option only makes sense for audio grabbing devices and raw demuxers ++and is mapped to the corresponding demuxer options. ++@item -an (@emph{output}) + Disable audio recording. +-@item -acodec @var{codec} +-Force audio codec to @var{codec}. Use the @code{copy} special value to +-specify that the raw codec data must be copied as is. +-@item -newaudio +-Add a new audio track to the output file. If you want to specify parameters, +-do so before @code{-newaudio} (@code{-acodec}, @code{-ab}, etc..). +- +-Mapping will be done automatically, if the number of output streams is equal to +-the number of input streams, else it will pick the first one that matches. You +-can override the mapping using @code{-map} as usual. +- +-Example: +-@example +-ffmpeg -i file.mpg -vcodec copy -acodec ac3 -ab 384k test.mpg -acodec mp2 -ab 192k -newaudio +-@end example +-@item -alang @var{code} +-Set the ISO 639 language code (3 letters) of the current audio stream. ++@item -acodec @var{codec} (@emph{input/output}) ++Set the audio codec. This is an alias for @code{-codec:a}. ++@item -sample_fmt[:@var{stream_specifier}] @var{sample_fmt} (@emph{output,per-stream}) ++Set the audio sample format. Use @code{-sample_fmts} to get a list ++of supported sample formats. + @end table + + @section Advanced Audio options: + + @table @option +-@item -atag @var{fourcc/tag} +-Force audio tag/fourcc. ++@item -atag @var{fourcc/tag} (@emph{output}) ++Force audio tag/fourcc. This is an alias for @code{-tag:a}. ++@item -audio_service_type @var{type} ++Set the type of service that the audio stream contains. ++@table @option ++@item ma ++Main Audio Service (default) ++@item ef ++Effects ++@item vi ++Visually Impaired ++@item hi ++Hearing Impaired ++@item di ++Dialogue ++@item co ++Commentary ++@item em ++Emergency ++@item vo ++Voice Over ++@item ka ++Karaoke ++@end table + @item -absf @var{bitstream_filter} +-Bitstream filters available are "dump_extra", "remove_extra", "noise", "mp3comp", "mp3decomp". ++Deprecated, see -bsf + @end table + + @section Subtitle options: + + @table @option +-@item -scodec @var{codec} +-Force subtitle codec ('copy' to copy stream). +-@item -newsubtitle +-Add a new subtitle stream to the current output stream. + @item -slang @var{code} + Set the ISO 639 language code (3 letters) of the current subtitle stream. +-@item -sn ++@item -scodec @var{codec} (@emph{input/output}) ++Set the subtitle codec. This is an alias for @code{-codec:s}. ++@item -sn (@emph{output}) + Disable subtitle recording. + @item -sbsf @var{bitstream_filter} +-Bitstream filters available are "mov2textsub", "text2movsub". +-@example +-ffmpeg -i file.mov -an -vn -sbsf mov2textsub -scodec copy -f rawvideo sub.txt +-@end example ++Deprecated, see -bsf + @end table + + @section Audio/Video grab options + + @table @option +-@item -vc @var{channel} +-Set video grab channel (DV1394 only). +-@item -tvstd @var{standard} +-Set television standard (NTSC, PAL (SECAM)). +-@item -isync ++@item -isync (@emph{global}) + Synchronize read on input. + @end table + + @section Advanced options + + @table @option +-@item -map @var{input_stream_id}[:@var{sync_stream_id}] +-Set stream mapping from input streams to output streams. +-Just enumerate the input streams in the order you want them in the output. +-@var{sync_stream_id} if specified sets the input stream to sync +-against. +-@item -map_meta_data @var{outfile}[,@var{metadata}]:@var{infile}[,@var{metadata}] +-Set meta data information of @var{outfile} from @var{infile}. Note that those +-are file indices (zero-based), not filenames. +-Optional @var{metadata} parameters specify, which metadata to copy - (g)lobal +-(i.e. metadata that applies to the whole file), per-(s)tream, per-(c)hapter or +-per-(p)rogram. All metadata specifiers other than global must be followed by the +-stream/chapter/program number. If metadata specifier is omitted, it defaults to +-global. ++@item -map [-]@var{input_file_id}[:@var{stream_specifier}][,@var{sync_file_id}[:@var{stream_specifier}]] (@emph{output}) ++ ++Designate one or more input streams as a source for the output file. Each input ++stream is identified by the input file index @var{input_file_id} and ++the input stream index @var{input_stream_id} within the input ++file. Both indices start at 0. If specified, ++@var{sync_file_id}:@var{stream_specifier} sets which input stream ++is used as a presentation sync reference. ++ ++The first @code{-map} option on the command line specifies the ++source for output stream 0, the second @code{-map} option specifies ++the source for output stream 1, etc. ++ ++A @code{-} character before the stream identifier creates a "negative" mapping. ++It disables matching streams from already created mappings. ++ ++For example, to map ALL streams from the first input file to output ++@example ++ffmpeg -i INPUT -map 0 output ++@end example ++ ++For example, if you have two audio streams in the first input file, ++these streams are identified by "0:0" and "0:1". You can use ++@code{-map} to select which streams to place in an output file. For ++example: ++@example ++ffmpeg -i INPUT -map 0:1 out.wav ++@end example ++will map the input stream in @file{INPUT} identified by "0:1" to ++the (single) output stream in @file{out.wav}. ++ ++For example, to select the stream with index 2 from input file ++@file{a.mov} (specified by the identifier "0:2"), and stream with ++index 6 from input @file{b.mov} (specified by the identifier "1:6"), ++and copy them to the output file @file{out.mov}: ++@example ++ffmpeg -i a.mov -i b.mov -c copy -map 0:2 -map 1:6 out.mov ++@end example ++ ++To select all video and the third audio stream from an input file: ++@example ++ffmpeg -i INPUT -map 0:v -map 0:a:2 OUTPUT ++@end example ++ ++To map all the streams except the second audio, use negative mappings ++@example ++ffmpeg -i INPUT -map 0 -map -0:a:1 OUTPUT ++@end example ++ ++Note that using this option disables the default mappings for this output file. ++ ++@item -map_channel [@var{input_file_id}.@var{stream_specifier}.@var{channel_id}|-1][:@var{output_file_id}.@var{stream_specifier}] ++Map an audio channel from a given input to an output. If ++@var{output_file_id}.@var{stream_specifier} are not set, the audio channel will ++be mapped on all the audio streams. ++ ++Using "-1" instead of ++@var{input_file_id}.@var{stream_specifier}.@var{channel_id} will map a muted ++channel. ++ ++For example, assuming @var{INPUT} is a stereo audio file, you can switch the ++two audio channels with the following command: ++@example ++ffmpeg -i INPUT -map_channel 0.0.1 -map_channel 0.0.0 OUTPUT ++@end example ++ ++If you want to mute the first channel and keep the second: ++@example ++ffmpeg -i INPUT -map_channel -1 -map_channel 0.0.1 OUTPUT ++@end example ++ ++The order of the "-map_channel" option specifies the order of the channels in ++the output stream. The output channel layout is guessed from the number of ++channels mapped (mono if one "-map_channel", stereo if two, etc.). Using "-ac" ++in combination of "-map_channel" makes the channel gain levels to be updated if ++channel layouts don't match (for instance two "-map_channel" options and "-ac ++6"). ++ ++You can also extract each channel of an @var{INPUT} to specific outputs; the ++following command extract each channel of the audio stream (file 0, stream 0) ++to the respective @var{OUTPUT_CH0} and @var{OUTPUT_CH1}: ++@example ++ffmpeg -i INPUT -map_channel 0.0.0 OUTPUT_CH0 -map_channel 0.0.1 OUTPUT_CH1 ++@end example ++ ++The following example split the channels of a stereo input into streams: ++ ++@example ++ffmpeg -i stereo.wav -map 0:0 -map 0:0 -map_channel 0.0.0:0.0 -map_channel 0.0.1:0.1 -y out.ogg ++@end example ++ ++Note that currently each output stream can only contain channels from a single ++input stream; you can't for example use "-map_channel" to pick multiple input ++audio channels contained in different streams (from the same or different files) ++and merge them into a single output stream. It is therefore not currently ++possible, for example, to turn two separate mono streams into a single stereo ++stream. However spliting a stereo stream into two single channel mono streams ++is possible. ++ ++@item -map_metadata[:@var{metadata_spec_out}] @var{infile}[:@var{metadata_spec_in}] (@emph{output,per-metadata}) ++Set metadata information of the next output file from @var{infile}. Note that ++those are file indices (zero-based), not filenames. ++Optional @var{metadata_spec_in/out} parameters specify, which metadata to copy. ++A metadata specifier can have the following forms: ++@table @option ++@item @var{g} ++global metadata, i.e. metadata that applies to the whole file ++ ++@item @var{s}[:@var{stream_spec}] ++per-stream metadata. @var{stream_spec} is a stream specifier as described ++in the @ref{Stream specifiers} chapter. In an input metadata specifier, the first ++matching stream is copied from. In an output metadata specifier, all matching ++streams are copied to. ++ ++@item @var{c}:@var{chapter_index} ++per-chapter metadata. @var{chapter_index} is the zero-based chapter index. ++ ++@item @var{p}:@var{program_index} ++per-program metadata. @var{program_index} is the zero-based program index. ++@end table ++If metadata specifier is omitted, it defaults to global. + +-By default, global metadata is copied from the first input file to all output files, ++By default, global metadata is copied from the first input file, + per-stream and per-chapter metadata is copied along with streams/chapters. These + default mappings are disabled by creating any mapping of the relevant type. A negative + file index can be used to create a dummy mapping that just disables automatic copying. +@@ -644,50 +864,92 @@ + For example to copy metadata from the first stream of the input file to global metadata + of the output file: + @example +-ffmpeg -i in.ogg -map_meta_data 0:0,s0 out.mp3 ++ffmpeg -i in.ogg -map_metadata 0:s:0 out.mp3 + @end example +-@item -map_chapters @var{outfile}:@var{infile} +-Copy chapters from @var{infile} to @var{outfile}. If no chapter mapping is specified, +-then chapters are copied from the first input file with at least one chapter to all +-output files. Use a negative file index to disable any chapter copying. +-@item -debug ++ ++To do the reverse, i.e. copy global metadata to all audio streams: ++@example ++ffmpeg -i in.mkv -map_metadata:s:a 0:g out.mkv ++@end example ++Note that simple @code{0} would work as well in this example, since global ++metadata is assumed by default. ++ ++@item -map_chapters @var{input_file_index} (@emph{output}) ++Copy chapters from input file with index @var{input_file_index} to the next ++output file. If no chapter mapping is specified, then chapters are copied from ++the first input file with at least one chapter. Use a negative file index to ++disable any chapter copying. ++@item -debug @var{category} + Print specific debug info. +-@item -benchmark ++@var{category} is a number or a string containing one of the following values: ++@table @samp ++@item bitstream ++@item buffers ++picture buffer allocations ++@item bugs ++@item dct_coeff ++@item er ++error recognition ++@item mb_type ++macroblock (MB) type ++@item mmco ++memory management control operations (H.264) ++@item mv ++motion vector ++@item pict ++picture info ++@item pts ++@item qp ++per-block quantization parameter (QP) ++@item rc ++rate control ++@item skip ++@item startcode ++@item thread_ops ++threading operations ++@item vis_mb_type ++visualize block types ++@item vis_qp ++visualize quantization parameter (QP), lower QP are tinted greener ++@end table ++@item -benchmark (@emph{global}) + Show benchmarking information at the end of an encode. + Shows CPU time used and maximum memory consumption. + Maximum memory consumption is not supported on all systems, + it will usually display as 0 if not supported. +-@item -dump +-Dump each input packet. +-@item -hex ++@item -timelimit @var{duration} (@emph{global}) ++Exit after ffmpeg has been running for @var{duration} seconds. ++@item -dump (@emph{global}) ++Dump each input packet to stderr. ++@item -hex (@emph{global}) + When dumping packets, also dump the payload. +-@item -bitexact +-Only use bit exact algorithms (for codec testing). + @item -ps @var{size} + Set RTP payload size in bytes. +-@item -re ++@item -re (@emph{input}) + Read input at native frame rate. Mainly used to simulate a grab device. + @item -loop_input + Loop over the input stream. Currently it works only for image + streams. This option is used for automatic FFserver testing. ++This option is deprecated, use -loop 1. + @item -loop_output @var{number_of_times} + Repeatedly loop output for formats that support looping such as animated GIF + (0 will loop the output infinitely). ++This option is deprecated, use -loop. + @item -threads @var{count} + Thread count. + @item -vsync @var{parameter} + Video sync method. + + @table @option +-@item 0 ++@item 0, passthrough + Each frame is passed with its timestamp from the demuxer to the muxer. +-@item 1 ++@item 1, cfr + Frames will be duplicated and dropped to achieve exactly the requested + constant framerate. +-@item 2 ++@item 2, vfr + Frames are passed through with their timestamp or dropped so as to + prevent 2 frames from having the same timestamp. +-@item -1 ++@item -1, auto + Chooses between 1 and 2 depending on muxer capabilities. This is the + default method. + @end table +@@ -709,11 +971,11 @@ + Finish encoding when the shortest input stream ends. + @item -dts_delta_threshold + Timestamp discontinuity delta threshold. +-@item -muxdelay @var{seconds} ++@item -muxdelay @var{seconds} (@emph{input}) + Set the maximum demux-decode delay. +-@item -muxpreload @var{seconds} ++@item -muxpreload @var{seconds} (@emph{input}) + Set the initial demux-decode delay. +-@item -streamid @var{output-stream-index}:@var{new-value} ++@item -streamid @var{output-stream-index}:@var{new-value} (@emph{output}) + Assign a new stream-id value to an output stream. This option should be + specified prior to the output filename to which it applies. + For the situation where multiple output files exist, a streamid +@@ -724,15 +986,35 @@ + @example + ffmpeg -i infile -streamid 0:33 -streamid 1:36 out.ts + @end example ++ ++@item -bsf[:@var{stream_specifier}] @var{bitstream_filters} (@emph{output,per-stream}) ++Set bitstream filters for matching streams. @var{bistream_filters} is ++a comma-separated list of bitstream filters. Use the @code{-bsfs} option ++to get the list of bitstream filters. ++@example ++ffmpeg -i h264.mp4 -c:v copy -vbsf h264_mp4toannexb -an out.h264 ++@end example ++@example ++ffmpeg -i file.mov -an -vn -sbsf mov2textsub -c:s copy -f rawvideo sub.txt ++@end example ++ ++@item -tag[:@var{stream_specifier}] @var{codec_tag} (@emph{per-stream}) ++Force a tag/fourcc for matching streams. ++ ++@item -timecode @var{hh}:@var{mm}:@var{ss}SEP@var{ff} ++Specify Timecode for writing. @var{SEP} is ':' for non drop timecode and ';' ++(or '.') for drop. ++@example ++ffmpeg -i input.mpg -timecode 01:02:03.04 -r 30000/1001 -s ntsc output.mpg ++@end example + @end table + + @section Preset files +- + A preset file contains a sequence of @var{option}=@var{value} pairs, + one for each line, specifying a sequence of options which would be + awkward to specify on the command line. Lines starting with the hash + ('#') character are ignored and are used to provide comments. Check +-the @file{ffpresets} directory in the FFmpeg source tree for examples. ++the @file{presets} directory in the FFmpeg source tree for examples. + + Preset files are specified with the @code{vpre}, @code{apre}, + @code{spre}, and @code{fpre} options. The @code{fpre} option takes the +@@ -749,6 +1031,7 @@ + First ffmpeg searches for a file named @var{arg}.ffpreset in the + directories @file{$FFMPEG_DATADIR} (if set), and @file{$HOME/.ffmpeg}, and in + the datadir defined at configuration time (usually @file{PREFIX/share/ffmpeg}) ++or in a @file{ffpresets} folder along the executable on win32, + in that order. For example, if the argument is @code{libx264-max}, it will + search for the file @file{libx264-max.ffpreset}. + +@@ -758,7 +1041,7 @@ + the preset file options will be applied. For example, if you select + the video codec with @code{-vcodec libx264} and use @code{-vpre max}, + then it will search for the file @file{libx264-max.ffpreset}. +-@c man end ++@c man end OPTIONS + + @chapter Tips + @c man begin TIPS +@@ -771,7 +1054,7 @@ + frames. An example is: + + @example +-ffmpeg -g 3 -r 3 -t 10 -b 50k -s qcif -f rv10 /tmp/b.rm ++ffmpeg -g 3 -r 3 -t 10 -b:v 50k -s qcif -f rv10 /tmp/b.rm + @end example + + @item +@@ -798,35 +1081,50 @@ + '-qscale n' when 'n' is between 1 (excellent quality) and 31 (worst + quality). + +-@item +-When converting video files, you can use the '-sameq' option which +-uses the same quality factor in the encoder as in the decoder. +-It allows almost lossless encoding. +- + @end itemize + @c man end TIPS + + @chapter Examples + @c man begin EXAMPLES + ++@section Preset files ++ ++A preset file contains a sequence of @var{option=value} pairs, one for ++each line, specifying a sequence of options which can be specified also on ++the command line. Lines starting with the hash ('#') character are ignored and ++are used to provide comments. Empty lines are also ignored. Check the ++@file{presets} directory in the FFmpeg source tree for examples. ++ ++Preset files are specified with the @code{pre} option, this option takes a ++preset name as input. FFmpeg searches for a file named @var{preset_name}.avpreset in ++the directories @file{$AVCONV_DATADIR} (if set), and @file{$HOME/.ffmpeg}, and in ++the data directory defined at configuration time (usually @file{$PREFIX/share/ffmpeg}) ++in that order. For example, if the argument is @code{libx264-max}, it will ++search for the file @file{libx264-max.avpreset}. ++ + @section Video and Audio grabbing + +-FFmpeg can grab video and audio from devices given that you specify the input +-format and device. ++If you specify the input format and device then ffmpeg can grab video ++and audio directly. + + @example + ffmpeg -f oss -i /dev/dsp -f video4linux2 -i /dev/video0 /tmp/out.mpg + @end example + ++Or with an ALSA audio source (mono input, card id 1) instead of OSS: ++@example ++ffmpeg -f alsa -ac 1 -i hw:1 -f video4linux2 -i /dev/video0 /tmp/out.mpg ++@end example ++ + Note that you must activate the right video source and channel before +-launching FFmpeg with any TV viewer such as xawtv +-(@url{http://linux.bytesex.org/xawtv/}) by Gerd Knorr. You also ++launching ffmpeg with any TV viewer such as ++@uref{http://linux.bytesex.org/xawtv/, xawtv} by Gerd Knorr. You also + have to set the audio recording levels correctly with a + standard mixer. + + @section X11 grabbing + +-FFmpeg can grab the X11 display. ++Grab the X11 display with ffmpeg via + + @example + ffmpeg -f x11grab -s cif -r 25 -i :0.0 /tmp/out.mpg +@@ -844,7 +1142,7 @@ + + @section Video and Audio file format conversion + +-FFmpeg can use any supported file format and protocol as input: ++Any supported file format and protocol can serve as input to ffmpeg: + + Examples: + @itemize +@@ -864,7 +1162,7 @@ + The Y files use twice the resolution of the U and V files. They are + raw files, without header. They can be generated by all decent video + decoders. You must specify the size of the image with the @option{-s} option +-if FFmpeg cannot guess it. ++if ffmpeg cannot guess it. + + @item + You can input from a raw YUV420P file: +@@ -908,7 +1206,7 @@ + mapping from input stream to output streams: + + @example +-ffmpeg -i /tmp/a.wav -ab 64k /tmp/a.mp2 -ab 128k /tmp/b.mp2 -map 0:0 -map 0:0 ++ffmpeg -i /tmp/a.wav -map 0:a -b:a 64k /tmp/a.mp2 -map 0:a -b:a 128k /tmp/b.mp2 + @end example + + Converts a.wav to a.mp2 at 64 kbits and to b.mp2 at 128 kbits. '-map +@@ -919,7 +1217,7 @@ + You can transcode decrypted VOBs: + + @example +-ffmpeg -i snatch_1.vob -f avi -vcodec mpeg4 -b 800k -g 300 -bf 2 -acodec libmp3lame -ab 128k snatch.avi ++ffmpeg -i snatch_1.vob -f avi -c:v mpeg4 -b:v 800k -g 300 -bf 2 -c:a libmp3lame -b:a 128k snatch.avi + @end example + + This is a typical DVD ripping example; the input is a VOB file, the +@@ -963,21 +1261,18 @@ + You can put many streams of the same type in the output: + + @example +-ffmpeg -i test1.avi -i test2.avi -vcodec copy -acodec copy -vcodec copy -acodec copy test12.avi -newvideo -newaudio ++ffmpeg -i test1.avi -i test2.avi -map 0.3 -map 0.2 -map 0.1 -map 0.0 -c copy test12.nut + @end example + +-In addition to the first video and audio streams, the resulting +-output file @file{test12.avi} will contain the second video +-and the second audio stream found in the input streams list. +- +-The @code{-newvideo}, @code{-newaudio} and @code{-newsubtitle} +-options have to be specified immediately after the name of the output +-file to which you want to add them. ++The resulting output file @file{test12.avi} will contain first four streams from ++the input file in reverse order. + + @end itemize + @c man end EXAMPLES + + @include eval.texi ++@include decoders.texi ++@include encoders.texi + @include demuxers.texi + @include muxers.texi + @include indevs.texi +@@ -990,14 +1285,14 @@ + @ignore + + @setfilename ffmpeg +-@settitle FFmpeg video converter ++@settitle ffmpeg video converter + + @c man begin SEEALSO + ffplay(1), ffprobe(1), ffserver(1) and the FFmpeg HTML documentation + @c man end + + @c man begin AUTHORS +-The FFmpeg developers ++See git history + @c man end + + @end ignore +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffmpeg.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffmpeg.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffmpeg.txt 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffmpeg.txt 2012-05-14 14:08:53.155316253 +0200 +@@ -0,0 +1,47 @@ ++ : ++ ffmpeg.c : libav* ++ ======== : ====== ++ : ++ : ++ --------------------------------:---> AVStream... ++ InputStream input_streams[] / : ++ / : ++ InputFile input_files[] +==========================+ / ^ : ++ ------> 0 | : st ---:-----------:--/ : : ++ ^ +------+-----------+-----+ / +--------------------------+ : : ++ : | :ist_index--:-----:---------/ 1 | : st : | : : ++ : +------+-----------+-----+ +==========================+ : : ++ nb_input_files : | :ist_index--:-----:------------------> 2 | : st : | : : ++ : +------+-----------+-----+ +--------------------------+ : nb_input_streams : ++ : | :ist_index : | 3 | ... | : : ++ v +------+-----------+-----+ +--------------------------+ : : ++ --> 4 | | : : ++ | +--------------------------+ : : ++ | 5 | | : : ++ | +==========================+ v : ++ | : ++ | : ++ | : ++ | : ++ --------- --------------------------------:---> AVStream... ++ \ / : ++ OutputStream output_streams[] / : ++ \ / : ++ +======\======================/======+ ^ : ++ ------> 0 | : source_index : st-:--- | : : ++ OuputFile output_files[] / +------------------------------------+ : : ++ / 1 | : : : | : : ++ ^ +------+------------+-----+ / +------------------------------------+ : : ++ : | : ost_index -:-----:------/ 2 | : : : | : : ++ nb_output_files : +------+------------+-----+ +====================================+ : : ++ : | : ost_index -:-----|-----------------> 3 | : : : | : : ++ : +------+------------+-----+ +------------------------------------+ : nb_output_streams : ++ : | : : | 4 | | : : ++ : +------+------------+-----+ +------------------------------------+ : : ++ : | : : | 5 | | : : ++ v +------+------------+-----+ +------------------------------------+ : : ++ 6 | | : : ++ +------------------------------------+ : : ++ 7 | | : : ++ +====================================+ v : ++ : +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffplay.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffplay.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffplay.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffplay.texi 2012-05-14 14:08:53.159316334 +0200 +@@ -1,8 +1,8 @@ + \input texinfo @c -*- texinfo -*- + +-@settitle FFplay Documentation ++@settitle ffplay Documentation + @titlepage +-@center @titlefont{FFplay Documentation} ++@center @titlefont{ffplay Documentation} + @end titlepage + + @top +@@ -13,7 +13,7 @@ + + @example + @c man begin SYNOPSIS +-ffplay [options] @file{input_file} ++ffplay [options] [@file{input_file}] + @c man end + @end example + +@@ -28,7 +28,7 @@ + @chapter Options + @c man begin OPTIONS + +-@include fftools-common-opts.texi ++@include avtools-common-opts.texi + + @section Main options + +@@ -38,8 +38,9 @@ + @item -y @var{height} + Force displayed height. + @item -s @var{size} +-Set frame size (WxH or abbreviation), needed for videos which don't +-contain a header with the frame size like raw YUV. ++Set frame size (WxH or abbreviation), needed for videos which do ++not contain a header with the frame size like raw YUV. This option ++has been deprecated in favor of private options, try -video_size. + @item -an + Disable audio. + @item -vn +@@ -58,27 +59,44 @@ + Set window title (default is the input filename). + @item -loop @var{number} + Loops movie playback times. 0 means forever. ++@item -showmode @var{mode} ++Set the show mode to use. ++Available values for @var{mode} are: ++@table @samp ++@item 0, video ++show video ++@item 1, waves ++show audio waves ++@item 2, rdft ++show audio frequency band using RDFT ((Inverse) Real Discrete Fourier Transform) ++@end table ++ ++Default value is "video", if video is not present or cannot be played ++"rdft" is automatically selected. ++ ++You can interactively cycle through the available show modes by ++pressing the key @key{w}. ++ + @item -vf @var{filter_graph} + @var{filter_graph} is a description of the filter graph to apply to + the input video. + Use the option "-filters" to show all the available filters (including + also sources and sinks). + ++@item -i @var{input_file} ++Read @var{input_file}. + @end table + + @section Advanced options + @table @option + @item -pix_fmt @var{format} + Set pixel format. ++This option has been deprecated in favor of private options, try -pixel_format. + @item -stats + Show the stream duration, the codec parameters, the current position in + the stream and the audio/video synchronisation drift. +-@item -debug +-Print specific debug info. + @item -bug + Work around bugs. +-@item -vismv +-Visualize motion vectors. + @item -fast + Non-spec-compliant optimizations. + @item -genpts +@@ -116,6 +134,8 @@ + Exit if any key is pressed. + @item -exitonmousedown + Exit if any mouse button is pressed. ++@item -codec:@var{stream_type} ++Force a specific decoder implementation + @end table + + @section While playing +@@ -148,6 +168,9 @@ + @item down/up + Seek backward/forward 1 minute. + ++@item page down/page up ++Seek backward/forward 10 minutes. ++ + @item mouse click + Seek to percentage in file corresponding to fraction of width. + +@@ -156,6 +179,7 @@ + @c man end + + @include eval.texi ++@include decoders.texi + @include demuxers.texi + @include muxers.texi + @include indevs.texi +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffprobe.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffprobe.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffprobe.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffprobe.texi 2012-05-14 14:08:53.161316374 +0200 +@@ -1,8 +1,8 @@ + \input texinfo @c -*- texinfo -*- + +-@settitle FFprobe Documentation ++@settitle ffprobe Documentation + @titlepage +-@center @titlefont{FFprobe Documentation} ++@center @titlefont{ffprobe Documentation} + @end titlepage + + @top +@@ -22,7 +22,7 @@ + @chapter Description + @c man begin DESCRIPTION + +-FFprobe gathers information from multimedia streams and prints it in ++ffprobe gathers information from multimedia streams and prints it in + human- and machine-readable fashion. + + For example it can be used to check the format of the container used +@@ -33,7 +33,7 @@ + probe the file content. If the file cannot be opened or recognized as + a multimedia file, a positive exit code is returned. + +-FFprobe may be employed both as a standalone application or in ++ffprobe may be employed both as a standalone application or in + combination with a textual filter, which may perform more + sophisticated processing, e.g. statistical processing or plotting. + +@@ -41,26 +41,19 @@ + for specifying which information to display, and for setting how + ffprobe will show it. + +-FFprobe output is designed to be easily parsable by a textual filter, +-and consists of one or more sections of the form: +-@example +-[SECTION] +-key1=val1 +-... +-keyN=valN +-[/SECTION] +-@end example ++ffprobe output is designed to be easily parsable by a textual filter, ++and consists of one or more sections of a form defined by the selected ++writer, which is specified by the @option{print_format} option. + + Metadata tags stored in the container or in the streams are recognized +-and printed in the corresponding "FORMAT" or "STREAM" section, and +-are prefixed by the string "TAG:". ++and printed in the corresponding "FORMAT" or "STREAM" section. + + @c man end + + @chapter Options + @c man begin OPTIONS + +-@include fftools-common-opts.texi ++@include avtools-common-opts.texi + + @section Main options + +@@ -87,6 +80,25 @@ + Prettify the format of the displayed values, it corresponds to the + options "-unit -prefix -byte_binary_prefix -sexagesimal". + ++@item -print_format @var{writer_name}[=@var{writer_options}] ++Set the output printing format. ++ ++@var{writer_name} specifies the name of the writer, and ++@var{writer_options} specifies the options to be passed to the writer. ++ ++For example for printing the output in JSON format, specify: ++@example ++-print_format json ++@end example ++ ++For more details on the available output printing formats, see the ++Writers section below. ++ ++@item -show_error ++Show information about the error found when trying to probe the input. ++ ++The error information is printed within a section with name "ERROR". ++ + @item -show_format + Show information about the container format of the input multimedia + stream. +@@ -101,6 +113,13 @@ + The information for each single packet is printed within a dedicated + section with name "PACKET". + ++@item -show_frames ++Show information about each frame contained in the input multimedia ++stream. ++ ++The information for each single frame is printed within a dedicated ++section with name "FRAME". ++ + @item -show_streams + Show information about each media stream contained in the input + multimedia stream. +@@ -108,18 +127,199 @@ + Each media stream information is printed within a dedicated section + with name "STREAM". + ++@item -show_private_data, -private ++Show private data, that is data depending on the format of the ++particular shown element. ++This option is enabled by default, but you may need to disable it ++for specific uses, for example when creating XSD-compliant XML output. ++ ++@item -show_program_version ++Show information related to program version. ++ ++Version information is printed within a section with name ++"PROGRAM_VERSION". ++ ++@item -show_library_versions ++Show information related to library versions. ++ ++Version information for each library is printed within a section with ++name "LIBRARY_VERSION". ++ ++@item -show_versions ++Show information related to program and library versions. This is the ++equivalent of setting both @option{-show_program_version} and ++@option{-show_library_versions} options. ++ ++@item -i @var{input_file} ++Read @var{input_file}. ++ + @end table + @c man end + ++@chapter Writers ++@c man begin WRITERS ++ ++A writer defines the output format adopted by @command{ffprobe}, and will be ++used for printing all the parts of the output. ++ ++A writer may accept one or more arguments, which specify the options to ++adopt. ++ ++A description of the currently available writers follows. ++ ++@section default ++Default format. ++ ++Print each section in the form: ++@example ++[SECTION] ++key1=val1 ++... ++keyN=valN ++[/SECTION] ++@end example ++ ++Metadata tags are printed as a line in the corresponding FORMAT or ++STREAM section, and are prefixed by the string "TAG:". ++ ++@section compact ++Compact format. ++ ++Each section is printed on a single line. ++If no option is specifid, the output has the form: ++@example ++section|key1=val1| ... |keyN=valN ++@end example ++ ++Metadata tags are printed in the corresponding "format" or "stream" ++section. A metadata tag key, if printed, is prefixed by the string ++"tag:". ++ ++This writer accepts options as a list of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item item_sep, s ++Specify the character to use for separating fields in the output line. ++It must be a single printable character, it is "|" by default. ++ ++@item nokey, nk ++If set to 1 specify not to print the key of each field. Its default ++value is 0. ++ ++@item escape, e ++Set the escape mode to use, default to "c". ++ ++It can assume one of the following values: ++@table @option ++@item c ++Perform C-like escaping. Strings containing a newline ('\n') or ++carriage return ('\r'), the escaping character ('\') or the item ++separator character @var{SEP} are escaped using C-like fashioned ++escaping, so that a newline is converted to the sequence "\n", a ++carriage return to "\r", '\' to "\\" and the separator @var{SEP} is ++converted to "\@var{SEP}". ++ ++@item csv ++Perform CSV-like escaping, as described in RFC4180. Strings ++containing a newline ('\n'), a carriage return ('\r'), a double quote ++('"'), or @var{SEP} are enclosed in double-quotes. ++ ++@item none ++Perform no escaping. ++@end table ++ ++@end table ++ ++@section csv ++CSV format. ++ ++This writer is equivalent to ++@code{compact=item_sep=,:nokey=1:escape=csv}. ++ ++@section json ++JSON based format. ++ ++Each section is printed using JSON notation. ++ ++This writer accepts options as a list of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item compact, c ++If set to 1 enable compact output, that is each section will be ++printed on a single line. Default value is 0. ++@end table ++ ++For more information about JSON, see @url{http://www.json.org/}. ++ ++@section xml ++XML based format. ++ ++The XML output is described in the XML schema description file ++@file{ffprobe.xsd} installed in the FFmpeg datadir. ++ ++Note that the output issued will be compliant to the ++@file{ffprobe.xsd} schema only when no special global output options ++(@option{unit}, @option{prefix}, @option{byte_binary_prefix}, ++@option{sexagesimal} etc.) are specified. ++ ++This writer accepts options as a list of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item fully_qualified, q ++If set to 1 specify if the output should be fully qualified. Default ++value is 0. ++This is required for generating an XML file which can be validated ++through an XSD file. ++ ++@item xsd_compliant, x ++If set to 1 perform more checks for ensuring that the output is XSD ++compliant. Default value is 0. ++This option automatically sets @option{fully_qualified} to 1. ++@end table ++ ++For more information about the XML format, see ++@url{http://www.w3.org/XML/}. ++ ++@chapter Timecode ++ ++@command{ffprobe} supports Timecode extraction: ++ ++@itemize ++ ++@item MPEG1/2 timecode is extracted from the GOP, and is available in the video ++stream details (@option{-show_streams}, see @var{timecode}). ++ ++@item MOV timecode is extracted from tmcd track, so is available in the tmcd ++stream metadata (@option{-show_streams}, see @var{TAG:timecode}). ++ ++@item DV and GXF timecodes are available in format metadata ++(@option{-show_format}, see @var{TAG:timecode}). ++ ++@end itemize ++ ++@c man end WRITERS ++ ++@include decoders.texi + @include demuxers.texi +-@include muxers.texi + @include protocols.texi + @include indevs.texi + + @ignore + + @setfilename ffprobe +-@settitle FFprobe media prober ++@settitle ffprobe media prober + + @c man begin SEEALSO + ffmpeg(1), ffplay(1), ffserver(1) and the FFmpeg HTML documentation +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffprobe.xsd xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffprobe.xsd +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffprobe.xsd 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffprobe.xsd 2012-05-14 14:08:53.162316394 +0200 +@@ -0,0 +1,164 @@ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffserver.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffserver.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/ffserver.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/ffserver.texi 2012-05-14 14:08:53.162316394 +0200 +@@ -1,8 +1,8 @@ + \input texinfo @c -*- texinfo -*- + +-@settitle FFserver Documentation ++@settitle ffserver Documentation + @titlepage +-@center @titlefont{FFserver Documentation} ++@center @titlefont{ffserver Documentation} + @end titlepage + + @top +@@ -22,24 +22,25 @@ + @chapter Description + @c man begin DESCRIPTION + +-FFserver is a streaming server for both audio and video. It supports ++ffserver is a streaming server for both audio and video. It supports ++ + several live feeds, streaming from files and time shifting on live feeds + (you can seek to positions in the past on each live feed, provided you + specify a big enough feed storage in ffserver.conf). + +-FFserver runs in daemon mode by default; that is, it puts itself in ++ffserver runs in daemon mode by default; that is, it puts itself in + the background and detaches from its TTY, unless it is launched in + debug mode or a NoDaemon option is specified in the configuration + file. + + This documentation covers only the streaming aspects of ffserver / + ffmpeg. All questions about parameters for ffmpeg, codec questions, +-etc. are not covered here. Read @file{ffmpeg-doc.html} for more ++etc. are not covered here. Read @file{ffmpeg.html} for more + information. + + @section How does it work? + +-FFserver receives prerecorded files or FFM streams from some ffmpeg ++ffserver receives prerecorded files or FFM streams from some ffmpeg + instance as input, then streams them over RTP/RTSP/HTTP. + + An ffserver instance will listen on some port as specified in the +@@ -57,7 +58,7 @@ + + @section Status stream + +-FFserver supports an HTTP interface which exposes the current status ++ffserver supports an HTTP interface which exposes the current status + of the server. + + Simply point your browser to the address of the special status stream +@@ -110,8 +111,8 @@ + is some file which you can decode with ffmpeg: + + @example +-./ffserver -f doc/ffserver.conf & +-./ffmpeg -i INPUTFILE http://localhost:8090/feed1.ffm ++ffserver -f doc/ffserver.conf & ++ffmpeg -i INPUTFILE http://localhost:8090/feed1.ffm + @end example + + At this point you should be able to go to your Windows machine and fire up +@@ -146,7 +147,7 @@ + If you are one of these people, then export 'AUDIO_FLIP_LEFT=1' before + starting ffmpeg. + +-@subsection The audio and video loose sync after a while. ++@subsection The audio and video lose sync after a while. + + Yes, they do. + +@@ -240,7 +241,7 @@ + @chapter Options + @c man begin OPTIONS + +-@include fftools-common-opts.texi ++@include avtools-common-opts.texi + + @section Main options + +@@ -249,8 +250,8 @@ + Use @file{configfile} instead of @file{/etc/ffserver.conf}. + @item -n + Enable no-launch mode. This option disables all the Launch directives +-within the various sections. FFserver will not launch any +-ffmpeg instance, so you will have to launch them manually. ++within the various sections. Since ffserver will not launch ++any ffmpeg instances, you will have to launch them manually. + @item -d + Enable debug mode. This option increases log verbosity, directs log + messages to stdout and causes ffserver to run in the foreground +@@ -261,11 +262,11 @@ + @ignore + + @setfilename ffserver +-@settitle FFserver video server ++@settitle ffserver video server + + @c man begin SEEALSO + +-ffmpeg(1), ffplay(1), ffprobe(1), the @file{ffmpeg/doc/ffserver.conf} ++ffmpeg(1), ffplay(1), ffprobe(1), the @file{ffserver.conf} + example and the FFmpeg HTML documentation + @c man end + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/fftools-common-opts.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/fftools-common-opts.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/fftools-common-opts.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/fftools-common-opts.texi 1970-01-01 01:00:00.000000000 +0100 +@@ -1,93 +0,0 @@ +-All the numerical options, if not specified otherwise, accept in input +-a string representing a number, which may contain one of the +-International System number postfixes, for example 'K', 'M', 'G'. +-If 'i' is appended after the postfix, powers of 2 are used instead of +-powers of 10. The 'B' postfix multiplies the value for 8, and can be +-appended after another postfix or used alone. This allows using for +-example 'KB', 'MiB', 'G' and 'B' as postfix. +- +-Options which do not take arguments are boolean options, and set the +-corresponding value to true. They can be set to false by prefixing +-with "no" the option name, for example using "-nofoo" in the +-commandline will set to false the boolean option with name "foo". +- +-@section Generic options +- +-These options are shared amongst the ff* tools. +- +-@table @option +- +-@item -L +-Show license. +- +-@item -h, -?, -help, --help +-Show help. +- +-@item -version +-Show version. +- +-@item -formats +-Show available formats. +- +-The fields preceding the format names have the following meanings: +-@table @samp +-@item D +-Decoding available +-@item E +-Encoding available +-@end table +- +-@item -codecs +-Show available codecs. +- +-The fields preceding the codec names have the following meanings: +-@table @samp +-@item D +-Decoding available +-@item E +-Encoding available +-@item V/A/S +-Video/audio/subtitle codec +-@item S +-Codec supports slices +-@item D +-Codec supports direct rendering +-@item T +-Codec can handle input truncated at random locations instead of only at frame boundaries +-@end table +- +-@item -bsfs +-Show available bitstream filters. +- +-@item -protocols +-Show available protocols. +- +-@item -filters +-Show available libavfilter filters. +- +-@item -pix_fmts +-Show available pixel formats. +- +-@item -loglevel @var{loglevel} +-Set the logging level used by the library. +-@var{loglevel} is a number or a string containing one of the following values: +-@table @samp +-@item quiet +-@item panic +-@item fatal +-@item error +-@item warning +-@item info +-@item verbose +-@item debug +-@end table +- +-By default the program logs to stderr, if coloring is supported by the +-terminal, colors are used to mark errors and warnings. Log coloring +-can be disabled setting the environment variable +-@env{FFMPEG_FORCE_NOCOLOR} or @env{NO_COLOR}, or can be forced setting +-the environment variable @env{FFMPEG_FORCE_COLOR}. +-The use of the environment variable @env{NO_COLOR} is deprecated and +-will be dropped in a following FFmpeg version. +- +-@end table +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/filters.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/filters.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/filters.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/filters.texi 2012-05-14 14:08:53.170316555 +0200 +@@ -17,9 +17,9 @@ + @section Filtergraph syntax + + A filtergraph can be represented using a textual representation, which +-is recognized by the @code{-vf} and @code{-af} options of the ff* +-tools, and by the @code{av_parse_graph()} function defined in +-@file{libavfilter/avfiltergraph}. ++is recognized by the @code{-vf} option of the ff* ++tools, and by the @code{avfilter_graph_parse()} function defined in ++@file{libavfilter/avfiltergraph.h}. + + A filterchain consists of a sequence of connected filters, each one + connected to the previous one in the sequence. A filterchain is +@@ -93,16 +93,396 @@ + @c man begin AUDIO FILTERS + + When you configure your FFmpeg build, you can disable any of the +-existing filters using --disable-filters. ++existing filters using @code{--disable-filters}. + The configure output will show the audio filters included in your + build. + + Below is a description of the currently available audio filters. + ++@section aconvert ++ ++Convert the input audio format to the specified formats. ++ ++The filter accepts a string of the form: ++"@var{sample_format}:@var{channel_layout}:@var{packing_format}". ++ ++@var{sample_format} specifies the sample format, and can be a string or ++the corresponding numeric value defined in @file{libavutil/samplefmt.h}. ++ ++@var{channel_layout} specifies the channel layout, and can be a string ++or the corresponding number value defined in @file{libavutil/audioconvert.h}. ++ ++@var{packing_format} specifies the type of packing in output, can be one ++of "planar" or "packed", or the corresponding numeric values "0" or "1". ++ ++The special parameter "auto", signifies that the filter will ++automatically select the output format depending on the output filter. ++ ++Some examples follow. ++ ++@itemize ++@item ++Convert input to unsigned 8-bit, stereo, packed: ++@example ++aconvert=u8:stereo:packed ++@end example ++ ++@item ++Convert input to unsigned 8-bit, automatically select out channel layout ++and packing format: ++@example ++aconvert=u8:auto:auto ++@end example ++@end itemize ++ ++@section aformat ++ ++Convert the input audio to one of the specified formats. The framework will ++negotiate the most appropriate format to minimize conversions. ++ ++The filter accepts three lists of formats, separated by ":", in the form: ++"@var{sample_formats}:@var{channel_layouts}:@var{packing_formats}". ++ ++Elements in each list are separated by "," which has to be escaped in the ++filtergraph specification. ++ ++The special parameter "all", in place of a list of elements, signifies all ++supported formats. ++ ++Some examples follow: ++@example ++aformat=u8\\,s16:mono:packed ++ ++aformat=s16:mono\\,stereo:all ++@end example ++ ++@section amerge ++ ++Merge two audio streams into a single multi-channel stream. ++ ++This filter does not need any argument. ++ ++If the channel layouts of the inputs are disjoint, and therefore compatible, ++the channel layout of the output will be set accordingly and the channels ++will be reordered as necessary. If the channel layouts of the inputs are not ++disjoint, the output will have all the channels of the first input then all ++the channels of the second input, in that order, and the channel layout of ++the output will be the default value corresponding to the total number of ++channels. ++ ++For example, if the first input is in 2.1 (FL+FR+LF) and the second input ++is FC+BL+BR, then the output will be in 5.1, with the channels in the ++following order: a1, a2, b1, a3, b2, b3 (a1 is the first channel of the ++first input, b1 is the first channel of the second input). ++ ++On the other hand, if both input are in stereo, the output channels will be ++in the default order: a1, a2, b1, b2, and the channel layout will be ++arbitrarily set to 4.0, which may or may not be the expected value. ++ ++Both inputs must have the same sample rate, format and packing. ++ ++If inputs do not have the same duration, the output will stop with the ++shortest. ++ ++Example: merge two mono files into a stereo stream: ++@example ++amovie=left.wav [l] ; amovie=right.mp3 [r] ; [l] [r] amerge ++@end example ++ + @section anull + + Pass the audio source unchanged to the output. + ++@section aresample ++ ++Resample the input audio to the specified sample rate. ++ ++The filter accepts exactly one parameter, the output sample rate. If not ++specified then the filter will automatically convert between its input ++and output sample rates. ++ ++For example, to resample the input audio to 44100Hz: ++@example ++aresample=44100 ++@end example ++ ++@section ashowinfo ++ ++Show a line containing various information for each input audio frame. ++The input audio is not modified. ++ ++The shown line contains a sequence of key/value pairs of the form ++@var{key}:@var{value}. ++ ++A description of each shown parameter follows: ++ ++@table @option ++@item n ++sequential number of the input frame, starting from 0 ++ ++@item pts ++presentation TimeStamp of the input frame, expressed as a number of ++time base units. The time base unit depends on the filter input pad, and ++is usually 1/@var{sample_rate}. ++ ++@item pts_time ++presentation TimeStamp of the input frame, expressed as a number of ++seconds ++ ++@item pos ++position of the frame in the input stream, -1 if this information in ++unavailable and/or meaningless (for example in case of synthetic audio) ++ ++@item fmt ++sample format name ++ ++@item chlayout ++channel layout description ++ ++@item nb_samples ++number of samples (per each channel) contained in the filtered frame ++ ++@item rate ++sample rate for the audio frame ++ ++@item planar ++if the packing format is planar, 0 if packed ++ ++@item checksum ++Adler-32 checksum (printed in hexadecimal) of all the planes of the input frame ++ ++@item plane_checksum ++Adler-32 checksum (printed in hexadecimal) for each input frame plane, ++expressed in the form "[@var{c0} @var{c1} @var{c2} @var{c3} @var{c4} @var{c5} ++@var{c6} @var{c7}]" ++@end table ++ ++@section asplit ++ ++Pass on the input audio to two outputs. Both outputs are identical to ++the input audio. ++ ++For example: ++@example ++[in] asplit[out0], showaudio[out1] ++@end example ++ ++will create two separate outputs from the same input, one cropped and ++one padded. ++ ++@section astreamsync ++ ++Forward two audio streams and control the order the buffers are forwarded. ++ ++The argument to the filter is an expression deciding which stream should be ++forwarded next: if the result is negative, the first stream is forwarded; if ++the result is positive or zero, the second stream is forwarded. It can use ++the following variables: ++ ++@table @var ++@item b1 b2 ++number of buffers forwarded so far on each stream ++@item s1 s2 ++number of samples forwarded so far on each stream ++@item t1 t2 ++current timestamp of each stream ++@end table ++ ++The default value is @code{t1-t2}, which means to always forward the stream ++that has a smaller timestamp. ++ ++Example: stress-test @code{amerge} by randomly sending buffers on the wrong ++input, while avoiding too much of a desynchronization: ++@example ++amovie=file.ogg [a] ; amovie=file.mp3 [b] ; ++[a] [b] astreamsync=(2*random(1))-1+tanh(5*(t1-t2)) [a2] [b2] ; ++[a2] [b2] amerge ++@end example ++ ++@section earwax ++ ++Make audio easier to listen to on headphones. ++ ++This filter adds `cues' to 44.1kHz stereo (i.e. audio CD format) audio ++so that when listened to on headphones the stereo image is moved from ++inside your head (standard for headphones) to outside and in front of ++the listener (standard for speakers). ++ ++Ported from SoX. ++ ++@section pan ++ ++Mix channels with specific gain levels. The filter accepts the output ++channel layout followed by a set of channels definitions. ++ ++This filter is also designed to remap efficiently the channels of an audio ++stream. ++ ++The filter accepts parameters of the form: ++"@var{l}:@var{outdef}:@var{outdef}:..." ++ ++@table @option ++@item l ++output channel layout or number of channels ++ ++@item outdef ++output channel specification, of the form: ++"@var{out_name}=[@var{gain}*]@var{in_name}[+[@var{gain}*]@var{in_name}...]" ++ ++@item out_name ++output channel to define, either a channel name (FL, FR, etc.) or a channel ++number (c0, c1, etc.) ++ ++@item gain ++multiplicative coefficient for the channel, 1 leaving the volume unchanged ++ ++@item in_name ++input channel to use, see out_name for details; it is not possible to mix ++named and numbered input channels ++@end table ++ ++If the `=' in a channel specification is replaced by `<', then the gains for ++that specification will be renormalized so that the total is 1, thus ++avoiding clipping noise. ++ ++@subsection Mixing examples ++ ++For example, if you want to down-mix from stereo to mono, but with a bigger ++factor for the left channel: ++@example ++pan=1:c0=0.9*c0+0.1*c1 ++@end example ++ ++A customized down-mix to stereo that works automatically for 3-, 4-, 5- and ++7-channels surround: ++@example ++pan=stereo: FL < FL + 0.5*FC + 0.6*BL + 0.6*SL : FR < FR + 0.5*FC + 0.6*BR + 0.6*SR ++@end example ++ ++Note that @command{ffmpeg} integrates a default down-mix (and up-mix) system ++that should be preferred (see "-ac" option) unless you have very specific ++needs. ++ ++@subsection Remapping examples ++ ++The channel remapping will be effective if, and only if: ++ ++@itemize ++@item gain coefficients are zeroes or ones, ++@item only one input per channel output, ++@item the number of output channels is supported by libswresample (16 at the ++ moment) ++@c if SWR_CH_MAX changes, fix the line above. ++@end itemize ++ ++If all these conditions are satisfied, the filter will notify the user ("Pure ++channel mapping detected"), and use an optimized and lossless method to do the ++remapping. ++ ++For example, if you have a 5.1 source and want a stereo audio stream by ++dropping the extra channels: ++@example ++pan="stereo: c0=FL : c1=FR" ++@end example ++ ++Given the same source, you can also switch front left and front right channels ++and keep the input channel layout: ++@example ++pan="5.1: c0=c1 : c1=c0 : c2=c2 : c3=c3 : c4=c4 : c5=c5" ++@end example ++ ++If the input is a stereo audio stream, you can mute the front left channel (and ++still keep the stereo channel layout) with: ++@example ++pan="stereo:c1=c1" ++@end example ++ ++Still with a stereo audio stream input, you can copy the right channel in both ++front left and right: ++@example ++pan="stereo: c0=FR : c1=FR" ++@end example ++ ++@section silencedetect ++ ++Detect silence in an audio stream. ++ ++This filter logs a message when it detects that the input audio volume is less ++or equal to a noise tolerance value for a duration greater or equal to the ++minimum detected noise duration. ++ ++The printed times and duration are expressed in seconds. ++ ++@table @option ++@item duration, d ++Set silence duration until notification (default is 2 seconds). ++ ++@item noise, n ++Set noise tolerance. Can be specified in dB (in case "dB" is appended to the ++specified value) or amplitude ratio. Default is -60dB, or 0.001. ++@end table ++ ++Detect 5 seconds of silence with -50dB noise tolerance: ++@example ++silencedetect=n=-50dB:d=5 ++@end example ++ ++Complete example with @command{ffmpeg} to detect silence with 0.0001 noise ++tolerance in @file{silence.mp3}: ++@example ++ffmpeg -f lavfi -i amovie=silence.mp3,silencedetect=noise=0.0001 -f null - ++@end example ++ ++@section volume ++ ++Adjust the input audio volume. ++ ++The filter accepts exactly one parameter @var{vol}, which expresses ++how the audio volume will be increased or decreased. ++ ++Output values are clipped to the maximum value. ++ ++If @var{vol} is expressed as a decimal number, the output audio ++volume is given by the relation: ++@example ++@var{output_volume} = @var{vol} * @var{input_volume} ++@end example ++ ++If @var{vol} is expressed as a decimal number followed by the string ++"dB", the value represents the requested change in decibels of the ++input audio power, and the output audio volume is given by the ++relation: ++@example ++@var{output_volume} = 10^(@var{vol}/20) * @var{input_volume} ++@end example ++ ++Otherwise @var{vol} is considered an expression and its evaluated ++value is used for computing the output audio volume according to the ++first relation. ++ ++Default value for @var{vol} is 1.0. ++ ++@subsection Examples ++ ++@itemize ++@item ++Half the input audio volume: ++@example ++volume=0.5 ++@end example ++ ++The above example is equivalent to: ++@example ++volume=1/2 ++@end example ++ ++@item ++Decrease input audio power by 12 decibels: ++@example ++volume=-12dB ++@end example ++@end itemize ++ + @c man end AUDIO FILTERS + + @chapter Audio Sources +@@ -110,31 +490,212 @@ + + Below is a description of the currently available audio sources. + ++@section abuffer ++ ++Buffer audio frames, and make them available to the filter chain. ++ ++This source is mainly intended for a programmatic use, in particular ++through the interface defined in @file{libavfilter/asrc_abuffer.h}. ++ ++It accepts the following mandatory parameters: ++@var{sample_rate}:@var{sample_fmt}:@var{channel_layout}:@var{packing} ++ ++@table @option ++ ++@item sample_rate ++The sample rate of the incoming audio buffers. ++ ++@item sample_fmt ++The sample format of the incoming audio buffers. ++Either a sample format name or its corresponging integer representation from ++the enum AVSampleFormat in @file{libavutil/samplefmt.h} ++ ++@item channel_layout ++The channel layout of the incoming audio buffers. ++Either a channel layout name from channel_layout_map in ++@file{libavutil/audioconvert.c} or its corresponding integer representation ++from the AV_CH_LAYOUT_* macros in @file{libavutil/audioconvert.h} ++ ++@item packing ++Either "packed" or "planar", or their integer representation: 0 or 1 ++respectively. ++ ++@end table ++ ++For example: ++@example ++abuffer=44100:s16:stereo:planar ++@end example ++ ++will instruct the source to accept planar 16bit signed stereo at 44100Hz. ++Since the sample format with name "s16" corresponds to the number ++1 and the "stereo" channel layout corresponds to the value 3, this is ++equivalent to: ++@example ++abuffer=44100:1:3:1 ++@end example ++ ++@section aevalsrc ++ ++Generate an audio signal specified by an expression. ++ ++This source accepts in input one or more expressions (one for each ++channel), which are evaluated and used to generate a corresponding ++audio signal. ++ ++It accepts the syntax: @var{exprs}[::@var{options}]. ++@var{exprs} is a list of expressions separated by ":", one for each ++separate channel. The output channel layout depends on the number of ++provided expressions, up to 8 channels are supported. ++ ++@var{options} is an optional sequence of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item duration, d ++Set the minimum duration of the sourced audio. See the function ++@code{av_parse_time()} for the accepted format. ++Note that the resulting duration may be greater than the specified ++duration, as the generated audio is always cut at the end of a ++complete frame. ++ ++If not specified, or the expressed duration is negative, the audio is ++supposed to be generated forever. ++ ++@item nb_samples, n ++Set the number of samples per channel per each output frame, ++default to 1024. ++ ++@item sample_rate, s ++Specify the sample rate, default to 44100. ++@end table ++ ++Each expression in @var{exprs} can contain the following constants: ++ ++@table @option ++@item n ++number of the evaluated sample, starting from 0 ++ ++@item t ++time of the evaluated sample expressed in seconds, starting from 0 ++ ++@item s ++sample rate ++ ++@end table ++ ++@subsection Examples ++ ++@itemize ++ ++@item ++Generate silence: ++@example ++aevalsrc=0 ++@end example ++ ++@item ++ ++Generate a sin signal with frequency of 440 Hz, set sample rate to ++8000 Hz: ++@example ++aevalsrc="sin(440*2*PI*t)::s=8000" ++@end example ++ ++@item ++Generate white noise: ++@example ++aevalsrc="-2+random(0)" ++@end example ++ ++@item ++Generate an amplitude modulated signal: ++@example ++aevalsrc="sin(10*2*PI*t)*sin(880*2*PI*t)" ++@end example ++ ++@item ++Generate 2.5 Hz binaural beats on a 360 Hz carrier: ++@example ++aevalsrc="0.1*sin(2*PI*(360-2.5/2)*t) : 0.1*sin(2*PI*(360+2.5/2)*t)" ++@end example ++ ++@end itemize ++ ++@section amovie ++ ++Read an audio stream from a movie container. ++ ++It accepts the syntax: @var{movie_name}[:@var{options}] where ++@var{movie_name} is the name of the resource to read (not necessarily ++a file but also a device or a stream accessed through some protocol), ++and @var{options} is an optional sequence of @var{key}=@var{value} ++pairs, separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item format_name, f ++Specify the format assumed for the movie to read, and can be either ++the name of a container or an input device. If not specified the ++format is guessed from @var{movie_name} or by probing. ++ ++@item seek_point, sp ++Specify the seek point in seconds, the frames will be output ++starting from this seek point, the parameter is evaluated with ++@code{av_strtod} so the numerical value may be suffixed by an IS ++postfix. Default value is "0". ++ ++@item stream_index, si ++Specify the index of the audio stream to read. If the value is -1, ++the best suited audio stream will be automatically selected. Default ++value is "-1". ++ ++@end table ++ + @section anullsrc + +-Null audio source, never return audio frames. It is mainly useful as a +-template and to be employed in analysis / debugging tools. ++Null audio source, return unprocessed audio frames. It is mainly useful ++as a template and to be employed in analysis / debugging tools, or as ++the source for filters which ignore the input data (for example the sox ++synth filter). + +-It accepts as optional parameter a string of the form +-@var{sample_rate}:@var{channel_layout}. ++It accepts an optional sequence of @var{key}=@var{value} pairs, ++separated by ":". + +-@var{sample_rate} specify the sample rate, and defaults to 44100. ++The description of the accepted options follows. ++ ++@table @option + +-@var{channel_layout} specify the channel layout, and can be either an +-integer or a string representing a channel layout. The default value +-of @var{channel_layout} is 3, which corresponds to CH_LAYOUT_STEREO. ++@item sample_rate, s ++Specify the sample rate, and defaults to 44100. ++ ++@item channel_layout, cl ++ ++Specify the channel layout, and can be either an integer or a string ++representing a channel layout. The default value of @var{channel_layout} ++is "stereo". + + Check the channel_layout_map definition in + @file{libavcodec/audioconvert.c} for the mapping between strings and + channel layout values. + ++@item nb_samples, n ++Set the number of samples per requested frames. ++ ++@end table ++ + Follow some examples: + @example +-# set the sample rate to 48000 Hz and the channel layout to CH_LAYOUT_MONO. +-anullsrc=48000:4 ++# set the sample rate to 48000 Hz and the channel layout to AV_CH_LAYOUT_MONO. ++anullsrc=r=48000:cl=4 + + # same as +-anullsrc=48000:mono ++anullsrc=r=48000:cl=mono + @end example + + @c man end AUDIO SOURCES +@@ -144,6 +705,17 @@ + + Below is a description of the currently available audio sinks. + ++@section abuffersink ++ ++Buffer audio frames, and make them available to the end of filter chain. ++ ++This sink is mainly intended for programmatic use, in particular ++through the interface defined in @file{libavfilter/buffersink.h}. ++ ++It requires a pointer to an AVABufferSinkContext structure, which ++defines the incoming buffers' formats, to be passed as the opaque ++parameter to @code{avfilter_init_filter} for initialization. ++ + @section anullsink + + Null audio sink, do absolutely nothing with the input audio. It is +@@ -156,12 +728,28 @@ + @c man begin VIDEO FILTERS + + When you configure your FFmpeg build, you can disable any of the +-existing filters using --disable-filters. ++existing filters using @code{--disable-filters}. + The configure output will show the video filters included in your + build. + + Below is a description of the currently available video filters. + ++@section ass ++ ++Draw ASS (Advanced Substation Alpha) subtitles on top of input video ++using the libass library. ++ ++To enable compilation of this filter you need to configure FFmpeg with ++@code{--enable-libass}. ++ ++This filter accepts in input the name of the ass file to render. ++ ++For example, to render the file @file{sub.ass} on top of the input ++video, use the command: ++@example ++ass=sub.ass ++@end example ++ + @section blackframe + + Detect frames that are (almost) completely black. Can be useful to +@@ -183,6 +771,66 @@ + @var{threshold} is the threshold below which a pixel value is + considered black, and defaults to 32. + ++@section boxblur ++ ++Apply boxblur algorithm to the input video. ++ ++This filter accepts the parameters: ++@var{luma_radius}:@var{luma_power}:@var{chroma_radius}:@var{chroma_power}:@var{alpha_radius}:@var{alpha_power} ++ ++Chroma and alpha parameters are optional, if not specified they default ++to the corresponding values set for @var{luma_radius} and ++@var{luma_power}. ++ ++@var{luma_radius}, @var{chroma_radius}, and @var{alpha_radius} represent ++the radius in pixels of the box used for blurring the corresponding ++input plane. They are expressions, and can contain the following ++constants: ++@table @option ++@item w, h ++the input width and height in pixels ++ ++@item cw, ch ++the input chroma image width and height in pixels ++ ++@item hsub, vsub ++horizontal and vertical chroma subsample values. For example for the ++pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. ++@end table ++ ++The radius must be a non-negative number, and must not be greater than ++the value of the expression @code{min(w,h)/2} for the luma and alpha planes, ++and of @code{min(cw,ch)/2} for the chroma planes. ++ ++@var{luma_power}, @var{chroma_power}, and @var{alpha_power} represent ++how many times the boxblur filter is applied to the corresponding ++plane. ++ ++Some examples follow: ++ ++@itemize ++ ++@item ++Apply a boxblur filter with luma, chroma, and alpha radius ++set to 2: ++@example ++boxblur=2:1 ++@end example ++ ++@item ++Set luma radius to 2, alpha and chroma radius to 0 ++@example ++boxblur=2:1:0:0:0:0 ++@end example ++ ++@item ++Set luma and chroma radius to a fraction of the video dimension ++@example ++boxblur=min(h\,w)/10:1:min(cw\,ch)/10:1 ++@end example ++ ++@end itemize ++ + @section copy + + Copy the input source unchanged to the output. Mainly useful for +@@ -195,26 +843,35 @@ + The parameters are expressions containing the following constants: + + @table @option +-@item E, PI, PHI +-the corresponding mathematical approximated values for e +-(euler number), pi (greek PI), PHI (golden ratio) +- + @item x, y + the computed values for @var{x} and @var{y}. They are evaluated for + each new frame. + + @item in_w, in_h +-the input width and heigth ++the input width and height + + @item iw, ih + same as @var{in_w} and @var{in_h} + + @item out_w, out_h +-the output (cropped) width and heigth ++the output (cropped) width and height + + @item ow, oh + same as @var{out_w} and @var{out_h} + ++@item a ++same as @var{iw} / @var{ih} ++ ++@item sar ++input sample aspect ratio ++ ++@item dar ++input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar} ++ ++@item hsub, vsub ++horizontal and vertical chroma subsample values. For example for the ++pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. ++ + @item n + the number of input frame, starting from 0 + +@@ -258,99 +915,544 @@ + # crop the central input area with size 2/3 of the input video + "crop=2/3*in_w:2/3*in_h" + +-# crop the input video central square +-crop=in_h ++# crop the input video central square ++crop=in_h ++ ++# delimit the rectangle with the top-left corner placed at position ++# 100:100 and the right-bottom corner corresponding to the right-bottom ++# corner of the input image. ++crop=in_w-100:in_h-100:100:100 ++ ++# crop 10 pixels from the left and right borders, and 20 pixels from ++# the top and bottom borders ++"crop=in_w-2*10:in_h-2*20" ++ ++# keep only the bottom right quarter of the input image ++"crop=in_w/2:in_h/2:in_w/2:in_h/2" ++ ++# crop height for getting Greek harmony ++"crop=in_w:1/PHI*in_w" ++ ++# trembling effect ++"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(n/10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(n/7)" ++ ++# erratic camera effect depending on timestamp ++"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(t*10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(t*13)" ++ ++# set x depending on the value of y ++"crop=in_w/2:in_h/2:y:10+10*sin(n/10)" ++@end example ++ ++@section cropdetect ++ ++Auto-detect crop size. ++ ++Calculate necessary cropping parameters and prints the recommended ++parameters through the logging system. The detected dimensions ++correspond to the non-black area of the input video. ++ ++It accepts the syntax: ++@example ++cropdetect[=@var{limit}[:@var{round}[:@var{reset}]]] ++@end example ++ ++@table @option ++ ++@item limit ++Threshold, which can be optionally specified from nothing (0) to ++everything (255), defaults to 24. ++ ++@item round ++Value which the width/height should be divisible by, defaults to ++16. The offset is automatically adjusted to center the video. Use 2 to ++get only even dimensions (needed for 4:2:2 video). 16 is best when ++encoding to most video codecs. ++ ++@item reset ++Counter that determines after how many frames cropdetect will reset ++the previously detected largest video area and start over to detect ++the current optimal crop area. Defaults to 0. ++ ++This can be useful when channel logos distort the video area. 0 ++indicates never reset and return the largest area encountered during ++playback. ++@end table ++ ++@section delogo ++ ++Suppress a TV station logo by a simple interpolation of the surrounding ++pixels. Just set a rectangle covering the logo and watch it disappear ++(and sometimes something even uglier appear - your mileage may vary). ++ ++The filter accepts parameters as a string of the form ++"@var{x}:@var{y}:@var{w}:@var{h}:@var{band}", or as a list of ++@var{key}=@var{value} pairs, separated by ":". ++ ++The description of the accepted parameters follows. ++ ++@table @option ++ ++@item x, y ++Specify the top left corner coordinates of the logo. They must be ++specified. ++ ++@item w, h ++Specify the width and height of the logo to clear. They must be ++specified. ++ ++@item band, t ++Specify the thickness of the fuzzy edge of the rectangle (added to ++@var{w} and @var{h}). The default value is 4. ++ ++@item show ++When set to 1, a green rectangle is drawn on the screen to simplify ++finding the right @var{x}, @var{y}, @var{w}, @var{h} parameters, and ++@var{band} is set to 4. The default value is 0. ++ ++@end table ++ ++Some examples follow. ++ ++@itemize ++ ++@item ++Set a rectangle covering the area with top left corner coordinates 0,0 ++and size 100x77, setting a band of size 10: ++@example ++delogo=0:0:100:77:10 ++@end example ++ ++@item ++As the previous example, but use named options: ++@example ++delogo=x=0:y=0:w=100:h=77:band=10 ++@end example ++ ++@end itemize ++ ++@section deshake ++ ++Attempt to fix small changes in horizontal and/or vertical shift. This ++filter helps remove camera shake from hand-holding a camera, bumping a ++tripod, moving on a vehicle, etc. ++ ++The filter accepts parameters as a string of the form ++"@var{x}:@var{y}:@var{w}:@var{h}:@var{rx}:@var{ry}:@var{edge}:@var{blocksize}:@var{contrast}:@var{search}:@var{filename}" ++ ++A description of the accepted parameters follows. ++ ++@table @option ++ ++@item x, y, w, h ++Specify a rectangular area where to limit the search for motion ++vectors. ++If desired the search for motion vectors can be limited to a ++rectangular area of the frame defined by its top left corner, width ++and height. These parameters have the same meaning as the drawbox ++filter which can be used to visualise the position of the bounding ++box. ++ ++This is useful when simultaneous movement of subjects within the frame ++might be confused for camera motion by the motion vector search. ++ ++If any or all of @var{x}, @var{y}, @var{w} and @var{h} are set to -1 ++then the full frame is used. This allows later options to be set ++without specifying the bounding box for the motion vector search. ++ ++Default - search the whole frame. ++ ++@item rx, ry ++Specify the maximum extent of movement in x and y directions in the ++range 0-64 pixels. Default 16. ++ ++@item edge ++Specify how to generate pixels to fill blanks at the edge of the ++frame. An integer from 0 to 3 as follows: ++@table @option ++@item 0 ++Fill zeroes at blank locations ++@item 1 ++Original image at blank locations ++@item 2 ++Extruded edge value at blank locations ++@item 3 ++Mirrored edge at blank locations ++@end table ++ ++The default setting is mirror edge at blank locations. ++ ++@item blocksize ++Specify the blocksize to use for motion search. Range 4-128 pixels, ++default 8. ++ ++@item contrast ++Specify the contrast threshold for blocks. Only blocks with more than ++the specified contrast (difference between darkest and lightest ++pixels) will be considered. Range 1-255, default 125. ++ ++@item search ++Specify the search strategy 0 = exhaustive search, 1 = less exhaustive ++search. Default - exhaustive search. ++ ++@item filename ++If set then a detailed log of the motion search is written to the ++specified file. ++ ++@end table ++ ++@section drawbox ++ ++Draw a colored box on the input image. ++ ++It accepts the syntax: ++@example ++drawbox=@var{x}:@var{y}:@var{width}:@var{height}:@var{color} ++@end example ++ ++@table @option ++ ++@item x, y ++Specify the top left corner coordinates of the box. Default to 0. ++ ++@item width, height ++Specify the width and height of the box, if 0 they are interpreted as ++the input width and height. Default to 0. ++ ++@item color ++Specify the color of the box to write, it can be the name of a color ++(case insensitive match) or a 0xRRGGBB[AA] sequence. ++@end table ++ ++Follow some examples: ++@example ++# draw a black box around the edge of the input image ++drawbox ++ ++# draw a box with color red and an opacity of 50% ++drawbox=10:20:200:60:red@@0.5" ++@end example ++ ++@section drawtext ++ ++Draw text string or text from specified file on top of video using the ++libfreetype library. ++ ++To enable compilation of this filter you need to configure FFmpeg with ++@code{--enable-libfreetype}. ++ ++The filter also recognizes strftime() sequences in the provided text ++and expands them accordingly. Check the documentation of strftime(). ++ ++The filter accepts parameters as a list of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted parameters follows. ++ ++@table @option ++ ++@item fontfile ++The font file to be used for drawing text. Path must be included. ++This parameter is mandatory. ++ ++@item text ++The text string to be drawn. The text must be a sequence of UTF-8 ++encoded characters. ++This parameter is mandatory if no file is specified with the parameter ++@var{textfile}. ++ ++@item textfile ++A text file containing text to be drawn. The text must be a sequence ++of UTF-8 encoded characters. ++ ++This parameter is mandatory if no text string is specified with the ++parameter @var{text}. ++ ++If both text and textfile are specified, an error is thrown. ++ ++@item x, y ++The expressions which specify the offsets where text will be drawn ++within the video frame. They are relative to the top/left border of the ++output image. ++ ++The default value of @var{x} and @var{y} is "0". ++ ++See below for the list of accepted constants. ++ ++@item fontsize ++The font size to be used for drawing text. ++The default value of @var{fontsize} is 16. ++ ++@item fontcolor ++The color to be used for drawing fonts. ++Either a string (e.g. "red") or in 0xRRGGBB[AA] format ++(e.g. "0xff000033"), possibly followed by an alpha specifier. ++The default value of @var{fontcolor} is "black". ++ ++@item boxcolor ++The color to be used for drawing box around text. ++Either a string (e.g. "yellow") or in 0xRRGGBB[AA] format ++(e.g. "0xff00ff"), possibly followed by an alpha specifier. ++The default value of @var{boxcolor} is "white". ++ ++@item box ++Used to draw a box around text using background color. ++Value should be either 1 (enable) or 0 (disable). ++The default value of @var{box} is 0. ++ ++@item shadowx, shadowy ++The x and y offsets for the text shadow position with respect to the ++position of the text. They can be either positive or negative ++values. Default value for both is "0". ++ ++@item shadowcolor ++The color to be used for drawing a shadow behind the drawn text. It ++can be a color name (e.g. "yellow") or a string in the 0xRRGGBB[AA] ++form (e.g. "0xff00ff"), possibly followed by an alpha specifier. ++The default value of @var{shadowcolor} is "black". ++ ++@item ft_load_flags ++Flags to be used for loading the fonts. ++ ++The flags map the corresponding flags supported by libfreetype, and are ++a combination of the following values: ++@table @var ++@item default ++@item no_scale ++@item no_hinting ++@item render ++@item no_bitmap ++@item vertical_layout ++@item force_autohint ++@item crop_bitmap ++@item pedantic ++@item ignore_global_advance_width ++@item no_recurse ++@item ignore_transform ++@item monochrome ++@item linear_design ++@item no_autohint ++@item end table ++@end table ++ ++Default value is "render". ++ ++For more information consult the documentation for the FT_LOAD_* ++libfreetype flags. ++ ++@item tabsize ++The size in number of spaces to use for rendering the tab. ++Default value is 4. ++@end table ++ ++The parameters for @var{x} and @var{y} are expressions containing the ++following constants: ++ ++@table @option ++@item W, H ++the input width and height ++ ++@item tw, text_w ++the width of the rendered text ++ ++@item th, text_h ++the height of the rendered text ++ ++@item lh, line_h ++the height of each text line ++ ++@item sar ++input sample aspect ratio ++ ++@item dar ++input display aspect ratio, it is the same as (@var{w} / @var{h}) * @var{sar} ++ ++@item hsub, vsub ++horizontal and vertical chroma subsample values. For example for the ++pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. ++ ++@item max_glyph_w ++maximum glyph width, that is the maximum width for all the glyphs ++contained in the rendered text ++ ++@item max_glyph_h ++maximum glyph height, that is the maximum height for all the glyphs ++contained in the rendered text, it is equivalent to @var{ascent} - ++@var{descent}. ++ ++@item max_glyph_a, ascent ++ ++the maximum distance from the baseline to the highest/upper grid ++coordinate used to place a glyph outline point, for all the rendered ++glyphs. ++It is a positive value, due to the grid's orientation with the Y axis ++upwards. ++ ++@item max_glyph_d, descent ++the maximum distance from the baseline to the lowest grid coordinate ++used to place a glyph outline point, for all the rendered glyphs. ++This is a negative value, due to the grid's orientation, with the Y axis ++upwards. ++ ++@item n ++the number of input frame, starting from 0 ++ ++@item t ++timestamp expressed in seconds, NAN if the input timestamp is unknown ++ ++@item timecode ++initial timecode representation in "hh:mm:ss[:;.]ff" format. It can be used ++with or without text parameter. @var{rate} option must be specified. ++Note that timecode options are @emph{not} effective if FFmpeg is build with ++@code{--disable-avcodec}. ++ ++@item r, rate ++frame rate (timecode only) ++@end table ++ ++Some examples follow. ++ ++@itemize ++ ++@item ++Draw "Test Text" with font FreeSerif, using the default values for the ++optional parameters. ++ ++@example ++drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='Test Text'" ++@end example ++ ++@item ++Draw 'Test Text' with font FreeSerif of size 24 at position x=100 ++and y=50 (counting from the top-left corner of the screen), text is ++yellow with a red box around it. Both the text and the box have an ++opacity of 20%. ++ ++@example ++drawtext="fontfile=/usr/share/fonts/truetype/freefont/FreeSerif.ttf: text='Test Text':\ ++ x=100: y=50: fontsize=24: fontcolor=yellow@@0.2: box=1: boxcolor=red@@0.2" ++@end example ++ ++Note that the double quotes are not necessary if spaces are not used ++within the parameter list. ++ ++@item ++Show the text at the center of the video frame: ++@example ++drawtext=fontsize=30:fontfile=FreeSerif.ttf:text='hello world':x=(w-text_w)/2:y=(h-text_h-line_h)/2" ++@end example ++ ++@item ++Show a text line sliding from right to left in the last row of the video ++frame. The file @file{LONG_LINE} is assumed to contain a single line ++with no newlines. ++@example ++drawtext=fontsize=15:fontfile=FreeSerif.ttf:text=LONG_LINE:y=h-line_h:x=-50*t ++@end example + +-# delimit the rectangle with the top-left corner placed at position +-# 100:100 and the right-bottom corner corresponding to the right-bottom +-# corner of the input image. +-crop=in_w-100:in_h-100:100:100 ++@item ++Show the content of file @file{CREDITS} off the bottom of the frame and scroll up. ++@example ++drawtext=fontsize=20:fontfile=FreeSerif.ttf:textfile=CREDITS:y=h-20*t" ++@end example + +-# crop 10 pixels from the left and right borders, and 20 pixels from +-# the top and bottom borders +-"crop=in_w-2*10:in_h-2*20" ++@item ++Draw a single green letter "g", at the center of the input video. ++The glyph baseline is placed at half screen height. ++@example ++drawtext=fontsize=60:fontfile=FreeSerif.ttf:fontcolor=green:text=g:x=(w-max_glyph_w)/2:y=h/2-ascent ++@end example + +-# keep only the bottom right quarter of the input image +-"crop=in_w/2:in_h/2:in_w/2:in_h/2" ++@end itemize + +-# crop height for getting Greek harmony +-"crop=in_w:1/PHI*in_w" ++For more information about libfreetype, check: ++@url{http://www.freetype.org/}. + +-# trembling effect +-"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(n/10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(n/7)" ++@section fade + +-# erratic camera effect depending on timestamp +-"crop=in_w/2:in_h/2:(in_w-out_w)/2+((in_w-out_w)/2)*sin(t*10):(in_h-out_h)/2 +((in_h-out_h)/2)*sin(t*13)" ++Apply fade-in/out effect to input video. + +-# set x depending on the value of y +-"crop=in_w/2:in_h/2:y:10+10*sin(n/10)" +-@end example ++It accepts the parameters: ++@var{type}:@var{start_frame}:@var{nb_frames}[:@var{options}] + +-@section cropdetect ++@var{type} specifies if the effect type, can be either "in" for ++fade-in, or "out" for a fade-out effect. + +-Auto-detect crop size. ++@var{start_frame} specifies the number of the start frame for starting ++to apply the fade effect. + +-Calculate necessary cropping parameters and prints the recommended +-parameters through the logging system. The detected dimensions +-correspond to the non-black area of the input video. ++@var{nb_frames} specifies the number of frames for which the fade ++effect has to last. At the end of the fade-in effect the output video ++will have the same intensity as the input video, at the end of the ++fade-out transition the output video will be completely black. + +-It accepts the syntax: +-@example +-cropdetect[=@var{limit}[:@var{round}[:@var{reset}]]] +-@end example ++@var{options} is an optional sequence of @var{key}=@var{value} pairs, ++separated by ":". The description of the accepted options follows. + + @table @option + +-@item limit +-Threshold, which can be optionally specified from nothing (0) to +-everything (255), defaults to 24. ++@item type, t ++See @var{type}. + +-@item round +-Value which the width/height should be divisible by, defaults to +-16. The offset is automatically adjusted to center the video. Use 2 to +-get only even dimensions (needed for 4:2:2 video). 16 is best when +-encoding to most video codecs. ++@item start_frame, s ++See @var{start_frame}. + +-@item reset +-Counter that determines after how many frames cropdetect will reset +-the previously detected largest video area and start over to detect +-the current optimal crop area. Defaults to 0. ++@item nb_frames, n ++See @var{nb_frames}. + +-This can be useful when channel logos distort the video area. 0 +-indicates never reset and return the largest area encountered during +-playback. ++@item alpha ++If set to 1, fade only alpha channel, if one exists on the input. ++Default value is 0. + @end table + +-@section drawbox ++A few usage examples follow, usable too as test scenarios. ++@example ++# fade in first 30 frames of video ++fade=in:0:30 + +-Draw a colored box on the input image. ++# fade out last 45 frames of a 200-frame video ++fade=out:155:45 + +-It accepts the syntax: +-@example +-drawbox=@var{x}:@var{y}:@var{width}:@var{height}:@var{color} ++# fade in first 25 frames and fade out last 25 frames of a 1000-frame video ++fade=in:0:25, fade=out:975:25 ++ ++# make first 5 frames black, then fade in from frame 5-24 ++fade=in:5:20 ++ ++# fade in alpha over first 25 frames of video ++fade=in:0:25:alpha=1 + @end example + +-@table @option ++@section fieldorder + +-@item x, y +-Specify the top left corner coordinates of the box. Default to 0. ++Transform the field order of the input video. + +-@item width, height +-Specify the width and height of the box, if 0 they are interpreted as +-the input width and height. Default to 0. ++It accepts one parameter which specifies the required field order that ++the input interlaced video will be transformed to. The parameter can ++assume one of the following values: + +-@item color +-Specify the color of the box to write, it can be the name of a color +-(case insensitive match) or a 0xRRGGBB[AA] sequence. ++@table @option ++@item 0 or bff ++output bottom field first ++@item 1 or tff ++output top field first + @end table + +-Follow some examples: +-@example +-# draw a black box around the edge of the input image +-drawbox ++Default value is "tff". + +-# draw a box with color red and an opacity of 50% +-drawbox=10:20:200:60:red@@0.5" ++Transformation is achieved by shifting the picture content up or down ++by one line, and filling the remaining line with appropriate picture content. ++This method is consistent with most broadcast field order converters. ++ ++If the input video is not flagged as being interlaced, or it is already ++flagged as being of the required output field order then this filter does ++not alter the incoming video. ++ ++This filter is very useful when converting to or from PAL DV material, ++which is bottom field first. ++ ++For example: ++@example ++ffmpeg -i in.vob -vf "fieldorder=bff" out.dv + @end example + + @section fifo +@@ -386,7 +1488,7 @@ + Apply a frei0r effect to the input video. + + To enable compilation of this filter you need to install the frei0r +-header and configure FFmpeg with --enable-frei0r. ++header and configure FFmpeg with @code{--enable-frei0r}. + + The filter supports the syntax: + @example +@@ -434,10 +1536,14 @@ + @section gradfun + + Fix the banding artifacts that are sometimes introduced into nearly flat +-regions by truncation to 8bit colordepth. ++regions by truncation to 8bit color depth. + Interpolate the gradients that should go where the bands are, and + dither them. + ++This filter is designed for playback only. Do not use it prior to ++lossy compression, because compression tends to lose the dither and ++bring back the bands. ++ + The filter takes two optional parameters, separated by ':': + @var{strength}:@var{radius} + +@@ -464,8 +1570,7 @@ + + Flip the input video horizontally. + +-For example to horizontally flip the video in input with +-@file{ffmpeg}: ++For example to horizontally flip the input video with @command{ffmpeg}: + @example + ffmpeg -i in.avi -vf "hflip" out.avi + @end example +@@ -497,6 +1602,224 @@ + @var{luma_tmp}*@var{chroma_spatial}/@var{luma_spatial} + @end table + ++@section lut, lutrgb, lutyuv ++ ++Compute a look-up table for binding each pixel component input value ++to an output value, and apply it to input video. ++ ++@var{lutyuv} applies a lookup table to a YUV input video, @var{lutrgb} ++to an RGB input video. ++ ++These filters accept in input a ":"-separated list of options, which ++specify the expressions used for computing the lookup table for the ++corresponding pixel component values. ++ ++The @var{lut} filter requires either YUV or RGB pixel formats in ++input, and accepts the options: ++@table @option ++@item c0 ++first pixel component ++@item c1 ++second pixel component ++@item c2 ++third pixel component ++@item c3 ++fourth pixel component, corresponds to the alpha component ++@end table ++ ++The exact component associated to each option depends on the format in ++input. ++ ++The @var{lutrgb} filter requires RGB pixel formats in input, and ++accepts the options: ++@table @option ++@item r ++red component ++@item g ++green component ++@item b ++blue component ++@item a ++alpha component ++@end table ++ ++The @var{lutyuv} filter requires YUV pixel formats in input, and ++accepts the options: ++@table @option ++@item y ++Y/luminance component ++@item u ++U/Cb component ++@item v ++V/Cr component ++@item a ++alpha component ++@end table ++ ++The expressions can contain the following constants and functions: ++ ++@table @option ++@item w, h ++the input width and height ++ ++@item val ++input value for the pixel component ++ ++@item clipval ++the input value clipped in the @var{minval}-@var{maxval} range ++ ++@item maxval ++maximum value for the pixel component ++ ++@item minval ++minimum value for the pixel component ++ ++@item negval ++the negated value for the pixel component value clipped in the ++@var{minval}-@var{maxval} range , it corresponds to the expression ++"maxval-clipval+minval" ++ ++@item clip(val) ++the computed value in @var{val} clipped in the ++@var{minval}-@var{maxval} range ++ ++@item gammaval(gamma) ++the computed gamma correction value of the pixel component value ++clipped in the @var{minval}-@var{maxval} range, corresponds to the ++expression ++"pow((clipval-minval)/(maxval-minval)\,@var{gamma})*(maxval-minval)+minval" ++ ++@end table ++ ++All expressions default to "val". ++ ++Some examples follow: ++@example ++# negate input video ++lutrgb="r=maxval+minval-val:g=maxval+minval-val:b=maxval+minval-val" ++lutyuv="y=maxval+minval-val:u=maxval+minval-val:v=maxval+minval-val" ++ ++# the above is the same as ++lutrgb="r=negval:g=negval:b=negval" ++lutyuv="y=negval:u=negval:v=negval" ++ ++# negate luminance ++lutyuv=y=negval ++ ++# remove chroma components, turns the video into a graytone image ++lutyuv="u=128:v=128" ++ ++# apply a luma burning effect ++lutyuv="y=2*val" ++ ++# remove green and blue components ++lutrgb="g=0:b=0" ++ ++# set a constant alpha channel value on input ++format=rgba,lutrgb=a="maxval-minval/2" ++ ++# correct luminance gamma by a 0.5 factor ++lutyuv=y=gammaval(0.5) ++@end example ++ ++@section mp ++ ++Apply an MPlayer filter to the input video. ++ ++This filter provides a wrapper around most of the filters of ++MPlayer/MEncoder. ++ ++This wrapper is considered experimental. Some of the wrapped filters ++may not work properly and we may drop support for them, as they will ++be implemented natively into FFmpeg. Thus you should avoid ++depending on them when writing portable scripts. ++ ++The filters accepts the parameters: ++@var{filter_name}[:=]@var{filter_params} ++ ++@var{filter_name} is the name of a supported MPlayer filter, ++@var{filter_params} is a string containing the parameters accepted by ++the named filter. ++ ++The list of the currently supported filters follows: ++@table @var ++@item 2xsai ++@item decimate ++@item denoise3d ++@item detc ++@item dint ++@item divtc ++@item down3dright ++@item dsize ++@item eq2 ++@item eq ++@item field ++@item fil ++@item fixpts ++@item framestep ++@item fspp ++@item geq ++@item harddup ++@item hqdn3d ++@item hue ++@item il ++@item ilpack ++@item ivtc ++@item kerndeint ++@item mcdeint ++@item mirror ++@item noise ++@item ow ++@item palette ++@item perspective ++@item phase ++@item pp7 ++@item pullup ++@item qp ++@item rectangle ++@item remove-logo ++@item rotate ++@item sab ++@item screenshot ++@item smartblur ++@item softpulldown ++@item softskip ++@item spp ++@item swapuv ++@item telecine ++@item tile ++@item tinterlace ++@item unsharp ++@item uspp ++@item yuvcsp ++@item yvu9 ++@end table ++ ++The parameter syntax and behavior for the listed filters are the same ++of the corresponding MPlayer filters. For detailed instructions check ++the "VIDEO FILTERS" section in the MPlayer manual. ++ ++Some examples follow: ++@example ++# remove a logo by interpolating the surrounding pixels ++mp=delogo=200:200:80:20:1 ++ ++# adjust gamma, brightness, contrast ++mp=eq2=1.0:2:0.5 ++ ++# tweak hue and saturation ++mp=hue=100:-10 ++@end example ++ ++See also mplayer(1), @url{http://www.mplayerhq.hu/}. ++ ++@section negate ++ ++Negate input video. ++ ++This filter accepts an integer in input, if non-zero it negates the ++alpha component (if available). The default value in input is 0. ++ + @section noformat + + Force libavfilter not to use any of the specified pixel formats for the +@@ -524,7 +1847,7 @@ + Apply video transform using libopencv. + + To enable this filter install libopencv library and headers and +-configure FFmpeg with --enable-libopencv. ++configure FFmpeg with @code{--enable-libopencv}. + + The filter takes the parameters: @var{filter_name}@{:=@}@var{filter_params}. + +@@ -534,7 +1857,7 @@ + filter. If not specified the default values are assumed. + + Refer to the official libopencv documentation for more precise +-informations: ++information: + @url{http://opencv.willowgarage.com/documentation/c/image_filtering.html} + + Follows the list of supported libopencv filters. +@@ -550,7 +1873,7 @@ + @var{struct_el} represents a structuring element, and has the syntax: + @var{cols}x@var{rows}+@var{anchor_x}x@var{anchor_y}/@var{shape} + +-@var{cols} and @var{rows} represent the number of colums and rows of ++@var{cols} and @var{rows} represent the number of columns and rows of + the structuring element, @var{anchor_x} and @var{anchor_y} the anchor + point, and @var{shape} the shape for the structuring element, and + can be one of the values "rect", "cross", "ellipse", "custom". +@@ -592,8 +1915,7 @@ + This filter corresponds to the libopencv function @code{cvErode}. + + The filter accepts the parameters: @var{struct_el}:@var{nb_iterations}, +-with the same meaning and use of those of the dilate filter +-(@pxref{dilate}). ++with the same syntax and semantics as the @ref{dilate} filter. + + @subsection smooth + +@@ -617,6 +1939,7 @@ + These parameters correspond to the parameters assigned to the + libopencv function @code{cvSmooth}. + ++@anchor{overlay} + @section overlay + + Overlay one video on top of another. +@@ -624,10 +1947,10 @@ + It takes two inputs and one output, the first input is the "main" + video on which the second input is overlayed. + +-It accepts the parameters: @var{x}:@var{y}. ++It accepts the parameters: @var{x}:@var{y}[:@var{options}]. + + @var{x} is the x coordinate of the overlayed video on the main video, +-@var{y} is the y coordinate. The parameters are expressions containing ++@var{y} is the y coordinate. @var{x} and @var{y} are expressions containing + the following parameters: + + @table @option +@@ -644,6 +1967,17 @@ + same as @var{overlay_w} and @var{overlay_h} + @end table + ++@var{options} is an optional list of @var{key}=@var{value} pairs, ++separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++@item rgb ++If set to 1, force the filter to accept inputs in the RGB ++color space. Default value is 0. ++@end table ++ + Be aware that frames are taken from each input video in timestamp + order, hence, if their initial timestamps differ, it is a a good idea + to pass the two inputs through a @var{setpts=PTS-STARTPTS} filter to +@@ -657,104 +1991,367 @@ + overlay=main_w-overlay_w-10:main_h-overlay_h-10 + + # insert a transparent PNG logo in the bottom left corner of the input +-movie=0:png:logo.png [logo]; ++movie=logo.png [logo]; + [in][logo] overlay=10:main_h-overlay_h-10 [out] + + # insert 2 different transparent PNG logos (second logo on bottom + # right corner): +-movie=0:png:logo1.png [logo1]; +-movie=0:png:logo2.png [logo2]; ++movie=logo1.png [logo1]; ++movie=logo2.png [logo2]; + [in][logo1] overlay=10:H-h-10 [in+logo1]; + [in+logo1][logo2] overlay=W-w-10:H-h-10 [out] + +-# add a transparent color layer on top of the main video, +-# WxH specifies the size of the main input to the overlay filter +-color=red@.3:WxH [over]; [in][over] overlay [out] ++# add a transparent color layer on top of the main video, ++# WxH specifies the size of the main input to the overlay filter ++color=red@.3:WxH [over]; [in][over] overlay [out] ++@end example ++ ++You can chain together more overlays but the efficiency of such ++approach is yet to be tested. ++ ++@section pad ++ ++Add paddings to the input image, and places the original input at the ++given coordinates @var{x}, @var{y}. ++ ++It accepts the following parameters: ++@var{width}:@var{height}:@var{x}:@var{y}:@var{color}. ++ ++The parameters @var{width}, @var{height}, @var{x}, and @var{y} are ++expressions containing the following constants: ++ ++@table @option ++@item in_w, in_h ++the input video width and height ++ ++@item iw, ih ++same as @var{in_w} and @var{in_h} ++ ++@item out_w, out_h ++the output width and height, that is the size of the padded area as ++specified by the @var{width} and @var{height} expressions ++ ++@item ow, oh ++same as @var{out_w} and @var{out_h} ++ ++@item x, y ++x and y offsets as specified by the @var{x} and @var{y} ++expressions, or NAN if not yet specified ++ ++@item a ++same as @var{iw} / @var{ih} ++ ++@item sar ++input sample aspect ratio ++ ++@item dar ++input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar} ++ ++@item hsub, vsub ++horizontal and vertical chroma subsample values. For example for the ++pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. ++@end table ++ ++Follows the description of the accepted parameters. ++ ++@table @option ++@item width, height ++ ++Specify the size of the output image with the paddings added. If the ++value for @var{width} or @var{height} is 0, the corresponding input size ++is used for the output. ++ ++The @var{width} expression can reference the value set by the ++@var{height} expression, and vice versa. ++ ++The default value of @var{width} and @var{height} is 0. ++ ++@item x, y ++ ++Specify the offsets where to place the input image in the padded area ++with respect to the top/left border of the output image. ++ ++The @var{x} expression can reference the value set by the @var{y} ++expression, and vice versa. ++ ++The default value of @var{x} and @var{y} is 0. ++ ++@item color ++ ++Specify the color of the padded area, it can be the name of a color ++(case insensitive match) or a 0xRRGGBB[AA] sequence. ++ ++The default value of @var{color} is "black". ++ ++@end table ++ ++Some examples follow: ++ ++@example ++# Add paddings with color "violet" to the input video. Output video ++# size is 640x480, the top-left corner of the input video is placed at ++# column 0, row 40. ++pad=640:480:0:40:violet ++ ++# pad the input to get an output with dimensions increased bt 3/2, ++# and put the input video at the center of the padded area ++pad="3/2*iw:3/2*ih:(ow-iw)/2:(oh-ih)/2" ++ ++# pad the input to get a squared output with size equal to the maximum ++# value between the input width and height, and put the input video at ++# the center of the padded area ++pad="max(iw\,ih):ow:(ow-iw)/2:(oh-ih)/2" ++ ++# pad the input to get a final w/h ratio of 16:9 ++pad="ih*16/9:ih:(ow-iw)/2:(oh-ih)/2" ++ ++# for anamorphic video, in order to set the output display aspect ratio, ++# it is necessary to use sar in the expression, according to the relation: ++# (ih * X / ih) * sar = output_dar ++# X = output_dar / sar ++pad="ih*16/9/sar:ih:(ow-iw)/2:(oh-ih)/2" ++ ++# double output size and put the input video in the bottom-right ++# corner of the output padded area ++pad="2*iw:2*ih:ow-iw:oh-ih" ++@end example ++ ++@section pixdesctest ++ ++Pixel format descriptor test filter, mainly useful for internal ++testing. The output video should be equal to the input video. ++ ++For example: ++@example ++format=monow, pixdesctest ++@end example ++ ++can be used to test the monowhite pixel format descriptor definition. ++ ++@section scale ++ ++Scale the input video to @var{width}:@var{height}[:@var{interl}=@{1|-1@}] and/or convert the image format. ++ ++The parameters @var{width} and @var{height} are expressions containing ++the following constants: ++ ++@table @option ++@item in_w, in_h ++the input width and height ++ ++@item iw, ih ++same as @var{in_w} and @var{in_h} ++ ++@item out_w, out_h ++the output (cropped) width and height ++ ++@item ow, oh ++same as @var{out_w} and @var{out_h} ++ ++@item a ++same as @var{iw} / @var{ih} ++ ++@item sar ++input sample aspect ratio ++ ++@item dar ++input display aspect ratio, it is the same as (@var{iw} / @var{ih}) * @var{sar} ++ ++@item hsub, vsub ++horizontal and vertical chroma subsample values. For example for the ++pixel format "yuv422p" @var{hsub} is 2 and @var{vsub} is 1. ++@end table ++ ++If the input image format is different from the format requested by ++the next filter, the scale filter will convert the input to the ++requested format. ++ ++If the value for @var{width} or @var{height} is 0, the respective input ++size is used for the output. ++ ++If the value for @var{width} or @var{height} is -1, the scale filter will ++use, for the respective output size, a value that maintains the aspect ++ratio of the input image. ++ ++The default value of @var{width} and @var{height} is 0. ++ ++Valid values for the optional parameter @var{interl} are: ++ ++@table @option ++@item 1 ++force interlaced aware scaling ++ ++@item -1 ++select interlaced aware scaling depending on whether the source frames ++are flagged as interlaced or not ++@end table ++ ++Some examples follow: ++@example ++# scale the input video to a size of 200x100. ++scale=200:100 ++ ++# scale the input to 2x ++scale=2*iw:2*ih ++# the above is the same as ++scale=2*in_w:2*in_h ++ ++# scale the input to half size ++scale=iw/2:ih/2 ++ ++# increase the width, and set the height to the same size ++scale=3/2*iw:ow ++ ++# seek for Greek harmony ++scale=iw:1/PHI*iw ++scale=ih*PHI:ih ++ ++# increase the height, and set the width to 3/2 of the height ++scale=3/2*oh:3/5*ih ++ ++# increase the size, but make the size a multiple of the chroma ++scale="trunc(3/2*iw/hsub)*hsub:trunc(3/2*ih/vsub)*vsub" ++ ++# increase the width to a maximum of 500 pixels, keep the same input aspect ratio ++scale='min(500\, iw*3/2):-1' + @end example + +-You can chain togheter more overlays but the efficiency of such +-approach is yet to be tested. ++@section select ++Select frames to pass in output. + +-@section pad ++It accepts in input an expression, which is evaluated for each input ++frame. If the expression is evaluated to a non-zero value, the frame ++is selected and passed to the output, otherwise it is discarded. + +-Add paddings to the input image, and places the original input at the +-given coordinates @var{x}, @var{y}. ++The expression can contain the following constants: + +-It accepts the following parameters: +-@var{width}:@var{height}:@var{x}:@var{y}:@var{color}. ++@table @option ++@item n ++the sequential number of the filtered frame, starting from 0 + +-Follows the description of the accepted parameters. ++@item selected_n ++the sequential number of the selected frame, starting from 0 + +-@table @option +-@item width, height ++@item prev_selected_n ++the sequential number of the last selected frame, NAN if undefined + +-Specify the size of the output image with the paddings added. If the +-value for @var{width} or @var{height} is 0, the corresponding input size +-is used for the output. ++@item TB ++timebase of the input timestamps + +-The default value of @var{width} and @var{height} is 0. ++@item pts ++the PTS (Presentation TimeStamp) of the filtered video frame, ++expressed in @var{TB} units, NAN if undefined + +-@item x, y ++@item t ++the PTS (Presentation TimeStamp) of the filtered video frame, ++expressed in seconds, NAN if undefined + +-Specify the offsets where to place the input image in the padded area +-with respect to the top/left border of the output image. ++@item prev_pts ++the PTS of the previously filtered video frame, NAN if undefined + +-The default value of @var{x} and @var{y} is 0. ++@item prev_selected_pts ++the PTS of the last previously filtered video frame, NAN if undefined + +-@item color ++@item prev_selected_t ++the PTS of the last previously selected video frame, NAN if undefined + +-Specify the color of the padded area, it can be the name of a color +-(case insensitive match) or a 0xRRGGBB[AA] sequence. ++@item start_pts ++the PTS of the first video frame in the video, NAN if undefined + +-The default value of @var{color} is "black". ++@item start_t ++the time of the first video frame in the video, NAN if undefined + ++@item pict_type ++the type of the filtered frame, can assume one of the following ++values: ++@table @option ++@item I ++@item P ++@item B ++@item S ++@item SI ++@item SP ++@item BI + @end table + +-For example: ++@item interlace_type ++the frame interlace type, can assume one of the following values: ++@table @option ++@item PROGRESSIVE ++the frame is progressive (not interlaced) ++@item TOPFIRST ++the frame is top-field-first ++@item BOTTOMFIRST ++the frame is bottom-field-first ++@end table + +-@example +-# Add paddings with color "violet" to the input video. Output video +-# size is 640x480, the top-left corner of the input video is placed at +-# row 0, column 40. +-pad=640:480:0:40:violet +-@end example ++@item key ++1 if the filtered frame is a key-frame, 0 otherwise + +-@section pixdesctest ++@item pos ++the position in the file of the filtered frame, -1 if the information ++is not available (e.g. for synthetic video) ++@end table + +-Pixel format descriptor test filter, mainly useful for internal +-testing. The output video should be equal to the input video. ++The default value of the select expression is "1". ++ ++Some examples follow: + +-For example: + @example +-format=monow, pixdesctest +-@end example ++# select all frames in input ++select + +-can be used to test the monowhite pixel format descriptor definition. ++# the above is the same as: ++select=1 + +-@section scale ++# skip all frames: ++select=0 + +-Scale the input video to @var{width}:@var{height} and/or convert the image format. ++# select only I-frames ++select='eq(pict_type\,I)' + +-For example the command: ++# select one frame every 100 ++select='not(mod(n\,100))' + +-@example +-./ffmpeg -i in.avi -vf "scale=200:100" out.avi ++# select only frames contained in the 10-20 time interval ++select='gte(t\,10)*lte(t\,20)' ++ ++# select only I frames contained in the 10-20 time interval ++select='gte(t\,10)*lte(t\,20)*eq(pict_type\,I)' ++ ++# select frames with a minimum distance of 10 seconds ++select='isnan(prev_selected_t)+gte(t-prev_selected_t\,10)' + @end example + +-will scale the input video to a size of 200x100. ++@anchor{setdar} ++@section setdar + +-If the input image format is different from the format requested by +-the next filter, the scale filter will convert the input to the +-requested format. ++Set the Display Aspect Ratio for the filter output video. + +-If the value for @var{width} or @var{height} is 0, the respective input +-size is used for the output. ++This is done by changing the specified Sample (aka Pixel) Aspect ++Ratio, according to the following equation: ++@math{DAR = HORIZONTAL_RESOLUTION / VERTICAL_RESOLUTION * SAR} + +-If the value for @var{width} or @var{height} is -1, the scale filter will +-use, for the respective output size, a value that maintains the aspect +-ratio of the input image. ++Keep in mind that this filter does not modify the pixel dimensions of ++the video frame. Also the display aspect ratio set by this filter may ++be changed by later filters in the filterchain, e.g. in case of ++scaling or if another "setdar" or a "setsar" filter is applied. + +-The default value of @var{width} and @var{height} is 0. ++The filter accepts a parameter string which represents the wanted ++display aspect ratio. ++The parameter can be a floating point number string, or an expression ++of the form @var{num}:@var{den}, where @var{num} and @var{den} are the ++numerator and denominator of the aspect ratio. ++If the parameter is not specified, it is assumed the value "0:1". ++ ++For example to change the display aspect ratio to 16:9, specify: ++@example ++setdar=16:9 ++# the above is equivalent to ++setdar=1.77777 ++@end example ++ ++See also the @ref{setsar} filter documentation. + + @section setpts + +@@ -767,15 +2364,6 @@ + @item PTS + the presentation timestamp in input + +-@item PI +-Greek PI +- +-@item PHI +-golden ratio +- +-@item E +-Euler number +- + @item N + the count of the input frame, starting from 0. + +@@ -816,13 +2404,39 @@ + setpts='1/(25*TB) * (N + 0.05 * sin(N*2*PI/25))' + @end example + ++@anchor{setsar} ++@section setsar ++ ++Set the Sample (aka Pixel) Aspect Ratio for the filter output video. ++ ++Note that as a consequence of the application of this filter, the ++output display aspect ratio will change according to the following ++equation: ++@math{DAR = HORIZONTAL_RESOLUTION / VERTICAL_RESOLUTION * SAR} ++ ++Keep in mind that the sample aspect ratio set by this filter may be ++changed by later filters in the filterchain, e.g. if another "setsar" ++or a "setdar" filter is applied. ++ ++The filter accepts a parameter string which represents the wanted ++sample aspect ratio. ++The parameter can be a floating point number string, or an expression ++of the form @var{num}:@var{den}, where @var{num} and @var{den} are the ++numerator and denominator of the aspect ratio. ++If the parameter is not specified, it is assumed the value "0:1". ++ ++For example to change the sample aspect ratio to 10:11, specify: ++@example ++setsar=10:11 ++@end example ++ + @section settb + + Set the timebase to use for the output frames timestamps. + It is mainly useful for testing timebase configuration. + + It accepts in input an arithmetic expression representing a rational. +-The expression can contain the constants "PI", "E", "PHI", "AVTB" (the ++The expression can contain the constants "AVTB" (the + default timebase), and "intb" (the input timebase). + + The default value for the input is "intb". +@@ -846,13 +2460,72 @@ + settb=AVTB + @end example + ++@section showinfo ++ ++Show a line containing various information for each input video frame. ++The input video is not modified. ++ ++The shown line contains a sequence of key/value pairs of the form ++@var{key}:@var{value}. ++ ++A description of each shown parameter follows: ++ ++@table @option ++@item n ++sequential number of the input frame, starting from 0 ++ ++@item pts ++Presentation TimeStamp of the input frame, expressed as a number of ++time base units. The time base unit depends on the filter input pad. ++ ++@item pts_time ++Presentation TimeStamp of the input frame, expressed as a number of ++seconds ++ ++@item pos ++position of the frame in the input stream, -1 if this information in ++unavailable and/or meaningless (for example in case of synthetic video) ++ ++@item fmt ++pixel format name ++ ++@item sar ++sample aspect ratio of the input frame, expressed in the form ++@var{num}/@var{den} ++ ++@item s ++size of the input frame, expressed in the form ++@var{width}x@var{height} ++ ++@item i ++interlaced mode ("P" for "progressive", "T" for top field first, "B" ++for bottom field first) ++ ++@item iskey ++1 if the frame is a key frame, 0 otherwise ++ ++@item type ++picture type of the input frame ("I" for an I-frame, "P" for a ++P-frame, "B" for a B-frame, "?" for unknown type). ++Check also the documentation of the @code{AVPictureType} enum and of ++the @code{av_get_picture_type_char} function defined in ++@file{libavutil/avutil.h}. ++ ++@item checksum ++Adler-32 checksum (printed in hexadecimal) of all the planes of the input frame ++ ++@item plane_checksum ++Adler-32 checksum (printed in hexadecimal) of each plane of the input frame, ++expressed in the form "[@var{c0} @var{c1} @var{c2} @var{c3}]" ++@end table ++ + @section slicify + + Pass the images of input video on to next video filter as multiple + slices. + + @example +-./ffmpeg -i in.avi -vf "slicify=32" out.avi ++ffmpeg -i in.avi -vf "slicify=32" out.avi + @end example + + The filter accepts the slice height as parameter. If the parameter is +@@ -861,6 +2534,82 @@ + Adding this in the beginning of filter chains should make filtering + faster due to better use of the memory cache. + ++@section split ++ ++Pass on the input video to two outputs. Both outputs are identical to ++the input video. ++ ++For example: ++@example ++[in] split [splitout1][splitout2]; ++[splitout1] crop=100:100:0:0 [cropout]; ++[splitout2] pad=200:200:100:100 [padout]; ++@end example ++ ++will create two separate outputs from the same input, one cropped and ++one padded. ++ ++@section swapuv ++Swap U & V plane. ++ ++@section thumbnail ++Select the most representative frame in a given sequence of consecutive frames. ++ ++It accepts as argument the frames batch size to analyze (default @var{N}=100); ++in a set of @var{N} frames, the filter will pick one of them, and then handle ++the next batch of @var{N} frames until the end. ++ ++Since the filter keeps track of the whole frames sequence, a bigger @var{N} ++value will result in a higher memory usage, so a high value is not recommended. ++ ++The following example extract one picture each 50 frames: ++@example ++thumbnail=50 ++@end example ++ ++Complete example of a thumbnail creation with @command{ffmpeg}: ++@example ++ffmpeg -i in.avi -vf thumbnail,scale=300:200 -frames:v 1 out.png ++@end example ++ ++@section tinterlace ++ ++Perform various types of temporal field interlacing. ++ ++Frames are counted starting from 1, so the first input frame is ++considered odd. ++ ++This filter accepts a single parameter specifying the mode. Available ++modes are: ++ ++@table @samp ++@item 0 ++Move odd frames into the upper field, even into the lower field, ++generating a double height frame at half framerate. ++ ++@item 1 ++Only output even frames, odd frames are dropped, generating a frame with ++unchanged height at half framerate. ++ ++@item 2 ++Only output odd frames, even frames are dropped, generating a frame with ++unchanged height at half framerate. ++ ++@item 3 ++Expand each frame to full height, but pad alternate lines with black, ++generating a frame with double height at the same input framerate. ++ ++@item 4 ++Interleave the upper field from odd frames with the lower field from ++even frames, generating a frame with unchanged height at half framerate. ++ ++@item 5 ++Interleave the lower field from odd frames with the upper field from ++even frames, generating a frame with unchanged height at half framerate. ++@end table ++ ++Default mode is 0. ++ + @section transpose + + Transpose rows with columns in the input video and optionally flip it. +@@ -911,7 +2660,7 @@ + + Negative values for the amount will blur the input video, while positive + values will sharpen. All parameters are optional and default to the +-equivalent of the string '5:5:1.0:0:0:0.0'. ++equivalent of the string '5:5:1.0:5:5:0.0'. + + @table @option + +@@ -929,13 +2678,13 @@ + + @item chroma_msize_x + Set the chroma matrix horizontal size. It can be an integer between 3 +-and 13, default value is 0. ++and 13, default value is 5. + + @item chroma_msize_y + Set the chroma matrix vertical size. It can be an integer between 3 +-and 13, default value is 0. ++and 13, default value is 5. + +-@item luma_amount ++@item chroma_amount + Set the chroma effect strength. It can be a float number between -2.0 + and 5.0, default value is 0.0. + +@@ -949,7 +2698,7 @@ + unsharp=7:7:-2:7:7:-2 + + # Use the default values with @command{ffmpeg} +-./ffmpeg -i in.avi -vf "unsharp" out.mp4 ++ffmpeg -i in.avi -vf "unsharp" out.mp4 + @end example + + @section vflip +@@ -957,7 +2706,7 @@ + Flip the input video vertically. + + @example +-./ffmpeg -i in.avi -vf "vflip" out.avi ++ffmpeg -i in.avi -vf "vflip" out.avi + @end example + + @section yadif +@@ -965,7 +2714,7 @@ + Deinterlace the input video ("yadif" means "yet another deinterlacing + filter"). + +-It accepts the optional parameters: @var{mode}:@var{parity}. ++It accepts the optional parameters: @var{mode}:@var{parity}:@var{auto}. + + @var{mode} specifies the interlacing mode to adopt, accepts one of the + following values: +@@ -988,9 +2737,9 @@ + + @table @option + @item 0 +-assume bottom field first +-@item 1 + assume top field first ++@item 1 ++assume bottom field first + @item -1 + enable automatic detection + @end table +@@ -999,6 +2748,18 @@ + If interlacing is unknown or decoder does not export this information, + top field first will be assumed. + ++@var{auto} specifies if deinterlacer should trust the interlaced flag ++and only deinterlace frames marked as interlaced ++ ++@table @option ++@item 0 ++deinterlace all frames ++@item 1 ++only deinterlace frames marked as interlaced ++@end table ++ ++Default value is 0. ++ + @c man end VIDEO FILTERS + + @chapter Video Sources +@@ -1014,9 +2775,10 @@ + through the interface defined in @file{libavfilter/vsrc_buffer.h}. + + It accepts the following parameters: +-@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den} ++@var{width}:@var{height}:@var{pix_fmt_string}:@var{timebase_num}:@var{timebase_den}:@var{sample_aspect_ratio_num}:@var{sample_aspect_ratio.den}:@var{scale_params} + +-All the parameters need to be explicitely defined. ++All the parameters but @var{scale_params} need to be explicitly ++defined. + + Follows the list of the accepted parameters. + +@@ -1033,22 +2795,147 @@ + @item timebase_num, timebase_den + Specify numerator and denomitor of the timebase assumed by the + timestamps of the buffered frames. ++ ++@item sample_aspect_ratio.num, sample_aspect_ratio.den ++Specify numerator and denominator of the sample aspect ratio assumed ++by the video frames. ++ ++@item scale_params ++Specify the optional parameters to be used for the scale filter which ++is automatically inserted when an input change is detected in the ++input size or format. + @end table + + For example: + @example +-buffer=320:240:yuv410p:1:24 ++buffer=320:240:yuv410p:1:24:1:1 + @end example + + will instruct the source to accept video frames with size 320x240 and +-with format "yuv410p" and assuming 1/24 as the timestamps timebase. ++with format "yuv410p", assuming 1/24 as the timestamps timebase and ++square pixels (1:1 sample aspect ratio). + Since the pixel format with name "yuv410p" corresponds to the number 6 + (check the enum PixelFormat definition in @file{libavutil/pixfmt.h}), + this example corresponds to: + @example +-buffer=320:240:6:1:24 ++buffer=320:240:6:1:24:1:1 ++@end example ++ ++@section cellauto ++ ++Create a pattern generated by an elementary cellular automaton. ++ ++The initial state of the cellular automaton can be defined through the ++@option{filename}, and @option{pattern} options. If such options are ++not specified an initial state is created randomly. ++ ++At each new frame a new row in the video is filled with the result of ++the cellular automaton next generation. The behavior when the whole ++frame is filled is defined by the @option{scroll} option. ++ ++This source accepts a list of options in the form of ++@var{key}=@var{value} pairs separated by ":". A description of the ++accepted options follows. ++ ++@table @option ++@item filename, f ++Read the initial cellular automaton state, i.e. the starting row, from ++the specified file. ++In the file, each non-whitespace character is considered an alive ++cell, a newline will terminate the row, and further characters in the ++file will be ignored. ++ ++@item pattern, p ++Read the initial cellular automaton state, i.e. the starting row, from ++the specified string. ++ ++Each non-whitespace character in the string is considered an alive ++cell, a newline will terminate the row, and further characters in the ++string will be ignored. ++ ++@item rate, r ++Set the video rate, that is the number of frames generated per second. ++Default is 25. ++ ++@item random_fill_ratio, ratio ++Set the random fill ratio for the initial cellular automaton row. It ++is a floating point number value ranging from 0 to 1, defaults to ++1/PHI. ++ ++This option is ignored when a file or a pattern is specified. ++ ++@item random_seed, seed ++Set the seed for filling randomly the initial row, must be an integer ++included between 0 and UINT32_MAX. If not specified, or if explicitly ++set to -1, the filter will try to use a good random seed on a best ++effort basis. ++ ++@item rule ++Set the cellular automaton rule, it is a number ranging from 0 to 255. ++Default value is 110. ++ ++@item size, s ++Set the size of the output video. ++ ++If @option{filename} or @option{pattern} is specified, the size is set ++by default to the width of the specified initial state row, and the ++height is set to @var{width} * PHI. ++ ++If @option{size} is set, it must contain the width of the specified ++pattern string, and the specified pattern will be centered in the ++larger row. ++ ++If a filename or a pattern string is not specified, the size value ++defaults to "320x518" (used for a randomly generated initial state). ++ ++@item scroll ++If set to 1, scroll the output upward when all the rows in the output ++have been already filled. If set to 0, the new generated row will be ++written over the top row just after the bottom row is filled. ++Defaults to 1. ++ ++@item start_full, full ++If set to 1, completely fill the output with generated rows before ++outputting the first frame. ++This is the default behavior, for disabling set the value to 0. ++ ++@item stitch ++If set to 1, stitch the left and right row edges together. ++This is the default behavior, for disabling set the value to 0. ++@end table ++ ++@subsection Examples ++ ++@itemize ++@item ++Read the initial state from @file{pattern}, and specify an output of ++size 200x400. ++@example ++cellauto=f=pattern:s=200x400 ++@end example ++ ++@item ++Generate a random initial row with a width of 200 cells, with a fill ++ratio of 2/3: ++@example ++cellauto=ratio=2/3:s=200x200 + @end example + ++@item ++Create a pattern generated by rule 18 starting by a single alive cell ++centered on an initial row with width 100: ++@example ++cellauto=p=@@:s=100x400:full=0:rule=18 ++@end example ++ ++@item ++Specify a more elaborated initial pattern: ++@example ++cellauto=p='@@@@ @@ @@@@':s=100x400:full=0:rule=18 ++@end example ++ ++@end itemize ++ + @section color + + Provide an uniformly colored input. +@@ -1067,7 +2954,7 @@ + + @item frame_size + Specify the size of the sourced video, it may be a string of the form +-@var{width}x@var{heigth}, or the name of a size abbreviation. The ++@var{width}x@var{height}, or the name of a size abbreviation. The + default value is "320x240". + + @item frame_rate +@@ -1088,28 +2975,124 @@ + "color=red@@0.2:qcif:10 [color]; [in][color] overlay [out]" + @end example + +-@section nullsrc ++@section movie ++ ++Read a video stream from a movie container. ++ ++It accepts the syntax: @var{movie_name}[:@var{options}] where ++@var{movie_name} is the name of the resource to read (not necessarily ++a file but also a device or a stream accessed through some protocol), ++and @var{options} is an optional sequence of @var{key}=@var{value} ++pairs, separated by ":". ++ ++The description of the accepted options follows. ++ ++@table @option ++ ++@item format_name, f ++Specifies the format assumed for the movie to read, and can be either ++the name of a container or an input device. If not specified the ++format is guessed from @var{movie_name} or by probing. ++ ++@item seek_point, sp ++Specifies the seek point in seconds, the frames will be output ++starting from this seek point, the parameter is evaluated with ++@code{av_strtod} so the numerical value may be suffixed by an IS ++postfix. Default value is "0". ++ ++@item stream_index, si ++Specifies the index of the video stream to read. If the value is -1, ++the best suited video stream will be automatically selected. Default ++value is "-1". ++ ++@end table ++ ++This filter allows to overlay a second video on top of main input of ++a filtergraph as shown in this graph: ++@example ++input -----------> deltapts0 --> overlay --> output ++ ^ ++ | ++movie --> scale--> deltapts1 -------+ ++@end example ++ ++Some examples follow: ++@example ++# skip 3.2 seconds from the start of the avi file in.avi, and overlay it ++# on top of the input labelled as "in". ++movie=in.avi:seek_point=3.2, scale=180:-1, setpts=PTS-STARTPTS [movie]; ++[in] setpts=PTS-STARTPTS, [movie] overlay=16:16 [out] ++ ++# read from a video4linux2 device, and overlay it on top of the input ++# labelled as "in" ++movie=/dev/video0:f=video4linux2, scale=180:-1, setpts=PTS-STARTPTS [movie]; ++[in] setpts=PTS-STARTPTS, [movie] overlay=16:16 [out] ++ ++@end example ++ ++@section mptestsrc ++ ++Generate various test patterns, as generated by the MPlayer test filter. ++ ++The size of the generated video is fixed, and is 256x256. ++This source is useful in particular for testing encoding features. ++ ++This source accepts an optional sequence of @var{key}=@var{value} pairs, ++separated by ":". The description of the accepted options follows. ++ ++@table @option ++ ++@item rate, r ++Specify the frame rate of the sourced video, as the number of frames ++generated per second. It has to be a string in the format ++@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float ++number or a valid video frame rate abbreviation. The default value is ++"25". ++ ++@item duration, d ++Set the video duration of the sourced video. The accepted syntax is: ++@example ++[-]HH[:MM[:SS[.m...]]] ++[-]S+[.m...] ++@end example ++See also the function @code{av_parse_time()}. ++ ++If not specified, or the expressed duration is negative, the video is ++supposed to be generated forever. + +-Null video source, never return images. It is mainly useful as a +-template and to be employed in analysis / debugging tools. ++@item test, t + +-It accepts as optional parameter a string of the form +-@var{width}:@var{height}:@var{timebase}. ++Set the number or the name of the test to perform. Supported tests are: ++@table @option ++@item dc_luma ++@item dc_chroma ++@item freq_luma ++@item freq_chroma ++@item amp_luma ++@item amp_chroma ++@item cbp ++@item mv ++@item ring1 ++@item ring2 ++@item all ++@end table ++ ++Default value is "all", which will cycle through the list of all tests. ++@end table + +-@var{width} and @var{height} specify the size of the configured +-source. The default values of @var{width} and @var{height} are +-respectively 352 and 288 (corresponding to the CIF size format). ++For example the following: ++@example ++testsrc=t=dc_luma ++@end example + +-@var{timebase} specifies an arithmetic expression representing a +-timebase. The expression can contain the constants "PI", "E", "PHI", +-"AVTB" (the default timebase), and defaults to the value "AVTB". ++will generate a "dc_luma" test pattern. + + @section frei0r_src + + Provide a frei0r source. + + To enable compilation of this filter you need to install the frei0r +-header and configure FFmpeg with --enable-frei0r. ++header and configure FFmpeg with @code{--enable-frei0r}. + + The source supports the syntax: + @example +@@ -1122,16 +3105,211 @@ + the form @var{num}/@var{den} or a frame rate abbreviation. + @var{src_name} is the name to the frei0r source to load. For more + information regarding frei0r and how to set the parameters read the +-section "frei0r" (@pxref{frei0r}) in the description of the video +-filters. ++section @ref{frei0r} in the description of the video filters. + + Some examples follow: + @example +-# generate a frei0r partik0l source with size 200x200 and framerate 10 ++# generate a frei0r partik0l source with size 200x200 and frame rate 10 + # which is overlayed on the overlay filter main input + frei0r_src=200x200:10:partik0l=1234 [overlay]; [in][overlay] overlay + @end example + ++@section life ++ ++Generate a life pattern. ++ ++This source is based on a generalization of John Conway's life game. ++ ++The sourced input represents a life grid, each pixel represents a cell ++which can be in one of two possible states, alive or dead. Every cell ++interacts with its eight neighbours, which are the cells that are ++horizontally, vertically, or diagonally adjacent. ++ ++At each interaction the grid evolves according to the adopted rule, ++which specifies the number of neighbor alive cells which will make a ++cell stay alive or born. The @option{rule} option allows to specify ++the rule to adopt. ++ ++This source accepts a list of options in the form of ++@var{key}=@var{value} pairs separated by ":". A description of the ++accepted options follows. ++ ++@table @option ++@item filename, f ++Set the file from which to read the initial grid state. In the file, ++each non-whitespace character is considered an alive cell, and newline ++is used to delimit the end of each row. ++ ++If this option is not specified, the initial grid is generated ++randomly. ++ ++@item rate, r ++Set the video rate, that is the number of frames generated per second. ++Default is 25. ++ ++@item random_fill_ratio, ratio ++Set the random fill ratio for the initial random grid. It is a ++floating point number value ranging from 0 to 1, defaults to 1/PHI. ++It is ignored when a file is specified. ++ ++@item random_seed, seed ++Set the seed for filling the initial random grid, must be an integer ++included between 0 and UINT32_MAX. If not specified, or if explicitly ++set to -1, the filter will try to use a good random seed on a best ++effort basis. ++ ++@item rule ++Set the life rule. ++ ++A rule can be specified with a code of the kind "S@var{NS}/B@var{NB}", ++where @var{NS} and @var{NB} are sequences of numbers in the range 0-8, ++@var{NS} specifies the number of alive neighbor cells which make a ++live cell stay alive, and @var{NB} the number of alive neighbor cells ++which make a dead cell to become alive (i.e. to "born"). ++"s" and "b" can be used in place of "S" and "B", respectively. ++ ++Alternatively a rule can be specified by an 18-bits integer. The 9 ++high order bits are used to encode the next cell state if it is alive ++for each number of neighbor alive cells, the low order bits specify ++the rule for "borning" new cells. Higher order bits encode for an ++higher number of neighbor cells. ++For example the number 6153 = @code{(12<<9)+9} specifies a stay alive ++rule of 12 and a born rule of 9, which corresponds to "S23/B03". ++ ++Default value is "S23/B3", which is the original Conway's game of life ++rule, and will keep a cell alive if it has 2 or 3 neighbor alive ++cells, and will born a new cell if there are three alive cells around ++a dead cell. ++ ++@item size, s ++Set the size of the output video. ++ ++If @option{filename} is specified, the size is set by default to the ++same size of the input file. If @option{size} is set, it must contain ++the size specified in the input file, and the initial grid defined in ++that file is centered in the larger resulting area. ++ ++If a filename is not specified, the size value defaults to "320x240" ++(used for a randomly generated initial grid). ++ ++@item stitch ++If set to 1, stitch the left and right grid edges together, and the ++top and bottom edges also. Defaults to 1. ++ ++@item mold ++Set cell mold speed. If set, a dead cell will go from @option{death_color} to ++@option{mold_color} with a step of @option{mold}. @option{mold} can have a ++value from 0 to 255. ++ ++@item life_color ++Set the color of living (or new born) cells. ++ ++@item death_color ++Set the color of dead cells. If @option{mold} is set, this is the first color ++used to represent a dead cell. ++ ++@item mold_color ++Set mold color, for definitely dead and moldy cells. ++@end table ++ ++@subsection Examples ++ ++@itemize ++@item ++Read a grid from @file{pattern}, and center it on a grid of size ++300x300 pixels: ++@example ++life=f=pattern:s=300x300 ++@end example ++ ++@item ++Generate a random grid of size 200x200, with a fill ratio of 2/3: ++@example ++life=ratio=2/3:s=200x200 ++@end example ++ ++@item ++Specify a custom rule for evolving a randomly generated grid: ++@example ++life=rule=S14/B34 ++@end example ++ ++@item ++Full example with slow death effect (mold) using @command{ffplay}: ++@example ++ffplay -f lavfi life=s=300x200:mold=10:r=60:ratio=0.1:death_color=#C83232:life_color=#00ff00,scale=1200:800:flags=16 ++@end example ++@end itemize ++ ++@section nullsrc, rgbtestsrc, testsrc ++ ++The @code{nullsrc} source returns unprocessed video frames. It is ++mainly useful to be employed in analysis / debugging tools, or as the ++source for filters which ignore the input data. ++ ++The @code{rgbtestsrc} source generates an RGB test pattern useful for ++detecting RGB vs BGR issues. You should see a red, green and blue ++stripe from top to bottom. ++ ++The @code{testsrc} source generates a test video pattern, showing a ++color pattern, a scrolling gradient and a timestamp. This is mainly ++intended for testing purposes. ++ ++These sources accept an optional sequence of @var{key}=@var{value} pairs, ++separated by ":". The description of the accepted options follows. ++ ++@table @option ++ ++@item size, s ++Specify the size of the sourced video, it may be a string of the form ++@var{width}x@var{height}, or the name of a size abbreviation. The ++default value is "320x240". ++ ++@item rate, r ++Specify the frame rate of the sourced video, as the number of frames ++generated per second. It has to be a string in the format ++@var{frame_rate_num}/@var{frame_rate_den}, an integer number, a float ++number or a valid video frame rate abbreviation. The default value is ++"25". ++ ++@item sar ++Set the sample aspect ratio of the sourced video. ++ ++@item duration, d ++Set the video duration of the sourced video. The accepted syntax is: ++@example ++[-]HH[:MM[:SS[.m...]]] ++[-]S+[.m...] ++@end example ++See also the function @code{av_parse_time()}. ++ ++If not specified, or the expressed duration is negative, the video is ++supposed to be generated forever. ++ ++@item decimals, n ++Set the number of decimals to show in the timestamp, only used in the ++@code{testsrc} source. ++ ++The displayed timestamp value will correspond to the original ++timestamp value multiplied by the power of 10 of the specified ++value. Default value is 0. ++@end table ++ ++For example the following: ++@example ++testsrc=duration=5.3:size=qcif:rate=10 ++@end example ++ ++will generate a video with a duration of 5.3 seconds, with size ++176x144 and a frame rate of 10 frames per second. ++ ++If the input content is to be ignored, @code{nullsrc} can be used. The ++following command generates noise in the luminance plane by employing ++the @code{mp=geq} filter: ++@example ++nullsrc=s=256x256, mp=geq=random(1)*255:128:128 ++@end example ++ + @c man end VIDEO SOURCES + + @chapter Video Sinks +@@ -1139,6 +3317,19 @@ + + Below is a description of the currently available video sinks. + ++@section buffersink ++ ++Buffer video frames, and make them available to the end of the filter ++graph. ++ ++This sink is mainly intended for a programmatic use, in particular ++through the interface defined in @file{libavfilter/buffersink.h}. ++ ++It does not require a string parameter in input, but you need to ++specify a pointer to a list of supported pixel formats terminated by ++-1 in the opaque parameter provided to @code{avfilter_init_filter} ++when initializing this sink. ++ + @section nullsink + + Null video sink, do absolutely nothing with the input video. It is +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/general.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/general.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/general.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/general.texi 2012-05-14 14:08:53.177316695 +0200 +@@ -9,29 +9,92 @@ + + @contents + +-@chapter external libraries ++@chapter External libraries + + FFmpeg can be hooked up with a number of external libraries to add support + for more formats. None of them are used by default, their use has to be + explicitly requested by passing the appropriate flags to @file{./configure}. + +-@section OpenCORE AMR ++@section OpenJPEG ++ ++FFmpeg can use the OpenJPEG libraries for encoding/decoding J2K videos. Go to ++@url{http://www.openjpeg.org/} to get the libraries and follow the installation ++instructions. To enable using OpenJPEG in FFmpeg, pass @code{--enable-libopenjpeg} to ++@file{./configure}. + +-FFmpeg can make use of the OpenCORE libraries for AMR-NB +-decoding/encoding and AMR-WB decoding. + +-Go to @url{http://sourceforge.net/projects/opencore-amr/} and follow the instructions for +-installing the libraries. Then pass @code{--enable-libopencore-amrnb} and/or +-@code{--enable-libopencore-amrwb} to configure to enable the libraries. ++@section OpenCORE and VisualOn libraries + +-Note that OpenCORE is under the Apache License 2.0 (see +-@url{http://www.apache.org/licenses/LICENSE-2.0} for details), which is ++Spun off Google Android sources, OpenCore and VisualOn libraries provide ++encoders for a number of audio codecs. ++ ++@float NOTE ++OpenCORE and VisualOn libraries are under the Apache License 2.0 ++(see @url{http://www.apache.org/licenses/LICENSE-2.0} for details), which is + incompatible with the LGPL version 2.1 and GPL version 2. You have to + upgrade FFmpeg's license to LGPL version 3 (or if you have enabled + GPL components, GPL version 3) to use it. ++@end float ++ ++@subsection OpenCORE AMR ++ ++FFmpeg can make use of the OpenCORE libraries for AMR-NB ++decoding/encoding and AMR-WB decoding. ++ ++Go to @url{http://sourceforge.net/projects/opencore-amr/} and follow the ++instructions for installing the libraries. ++Then pass @code{--enable-libopencore-amrnb} and/or ++@code{--enable-libopencore-amrwb} to configure to enable them. ++ ++@subsection VisualOn AAC encoder library ++ ++FFmpeg can make use of the VisualOn AACenc library for AAC encoding. ++ ++Go to @url{http://sourceforge.net/projects/opencore-amr/} and follow the ++instructions for installing the library. ++Then pass @code{--enable-libvo-aacenc} to configure to enable it. ++ ++@subsection VisualOn AMR-WB encoder library ++ ++FFmpeg can make use of the VisualOn AMR-WBenc library for AMR-WB encoding. ++ ++Go to @url{http://sourceforge.net/projects/opencore-amr/} and follow the ++instructions for installing the library. ++Then pass @code{--enable-libvo-amrwbenc} to configure to enable it. ++ ++@section LAME ++ ++FFmpeg can make use of the LAME library for MP3 encoding. ++ ++Go to @url{http://lame.sourceforge.net/} and follow the ++instructions for installing the library. ++Then pass @code{--enable-libmp3lame} to configure to enable it. + ++@section libvpx + +-@chapter Supported File Formats and Codecs ++FFmpeg can make use of the libvpx library for VP8 encoding. ++ ++Go to @url{http://www.webmproject.org/} and follow the instructions for ++installing the library. Then pass @code{--enable-libvpx} to configure to ++enable it. ++ ++@section x264 ++ ++FFmpeg can make use of the x264 library for H.264 encoding. ++ ++Go to @url{http://www.videolan.org/developers/x264.html} and follow the ++instructions for installing the library. Then pass @code{--enable-libx264} to ++configure to enable it. ++ ++@float NOTE ++x264 is under the GNU Public License Version 2 or later ++(see @url{http://www.gnu.org/licenses/old-licenses/gpl-2.0.html} for ++details), you must upgrade FFmpeg's license to GPL in order to use it. ++@end float ++ ++ ++ ++@chapter Supported File Formats, Codecs or Features + + You can use the @code{-formats} and @code{-codecs} options to have an exhaustive list. + +@@ -45,12 +108,15 @@ + @item 4xm @tab @tab X + @tab 4X Technologies format, used in some games. + @item 8088flex TMV @tab @tab X ++@item ACT Voice @tab @tab X ++ @tab contains G.729 audio + @item Adobe Filmstrip @tab X @tab X + @item Audio IFF (AIFF) @tab X @tab X + @item American Laser Games MM @tab @tab X + @tab Multimedia format used in games like Mad Dog McCree. + @item 3GPP AMR @tab X @tab X + @item Apple HTTP Live Streaming @tab @tab X ++@item Artworx Data Format @tab @tab X + @item ASF @tab X @tab X + @item AVI @tab X @tab X + @item AVISynth @tab @tab X +@@ -60,17 +126,24 @@ + @tab Audio and video format used in some games by Beam Software. + @item Bethesda Softworks VID @tab @tab X + @tab Used in some games from Bethesda Softworks. ++@item Binary text @tab @tab X + @item Bink @tab @tab X + @tab Multimedia format used by many games. ++@item Bitmap Brothers JV @tab @tab X ++ @tab Used in Z and Z95 games. + @item Brute Force & Ignorance @tab @tab X + @tab Used in the game Flash Traffic: City of Angels. ++@item BWF @tab X @tab X ++@item CRI ADX @tab X @tab X ++ @tab Audio-only format used in console video games. ++@item Discworld II BMV @tab @tab X + @item Interplay C93 @tab @tab X + @tab Used in the game Cyberia from Interplay. + @item Delphine Software International CIN @tab @tab X + @tab Multimedia format used by Delphine Software games. + @item CD+G @tab @tab X + @tab Video format used by CD+G karaoke disks +-@item Core Audio Format @tab @tab X ++@item Core Audio Format @tab X @tab X + @tab Apple Core Audio Format + @item CRC testing format @tab X @tab + @item Creative Voice @tab X @tab X +@@ -79,6 +152,8 @@ + @tab Audio format used in some games by CRYO Interactive Entertainment. + @item D-Cinema audio @tab X @tab X + @item Deluxe Paint Animation @tab @tab X ++@item DFA @tab @tab X ++ @tab This format is used in Chronomaster game + @item DV video @tab X @tab X + @item DXA @tab @tab X + @tab This format is used in the non-Windows version of the Feeble Files +@@ -92,18 +167,24 @@ + @tab Only embedded audio is decoded. + @item FLI/FLC/FLX animation @tab @tab X + @tab .fli/.flc files +-@item Flash Video (FLV) @tab @tab X ++@item Flash Video (FLV) @tab X @tab X + @tab Macromedia Flash video files + @item framecrc testing format @tab X @tab + @item FunCom ISS @tab @tab X + @tab Audio format used in various games from FunCom like The Longest Journey. ++@item G.723.1 @tab X @tab X ++@item G.729 BIT @tab X @tab X ++@item G.729 raw @tab @tab X + @item GIF Animation @tab X @tab + @item GXF @tab X @tab X + @tab General eXchange Format SMPTE 360M, used by Thomson Grass Valley + playout servers. ++@item iCEDraw File @tab @tab X ++@item ICO @tab @tab X ++ @tab Microsoft Windows ICO + @item id Quake II CIN video @tab @tab X + @item id RoQ @tab X @tab X +- @tab Used in Quake III, Jedi Knight 2, other computer games. ++ @tab Used in Quake III, Jedi Knight 2 and other computer games. + @item IEC61937 encapsulation @tab X @tab X + @item IFF @tab @tab X + @tab Interchange File Format +@@ -113,8 +194,11 @@ + @tab A format generated by IndigoVision 8000 video server. + @item IVF (On2) @tab X @tab X + @tab A format used by libvpx ++@item LATM @tab X @tab X + @item LMLM4 @tab @tab X + @tab Used by Linux Media Labs MPEG-4 PCI boards ++@item LOAS @tab @tab X ++ @tab contains LATM multiplexed AAC audio + @item LXF @tab @tab X + @tab VR native stream format, used by Leitch/Harris' video servers. + @item Matroska @tab X @tab X +@@ -158,6 +242,7 @@ + @item NUT @tab X @tab X + @tab NUT Open Container Format + @item Ogg @tab X @tab X ++@item Playstation Portable PMP @tab @tab X + @item TechnoTrend PVA @tab @tab X + @tab Used by TechnoTrend DVB PCI boards. + @item QCP @tab @tab X +@@ -222,6 +307,7 @@ + @item RTP @tab X @tab X + @item RTSP @tab X @tab X + @item SAP @tab X @tab X ++@item SBG @tab @tab X + @item SDP @tab @tab X + @item Sega FILM/CPK @tab @tab X + @tab Used in many Sega Saturn console games. +@@ -231,7 +317,9 @@ + @tab Used in Sierra CD-ROM games. + @item Smacker @tab @tab X + @tab Multimedia format used by many games. +-@item Sony OpenMG (OMA) @tab @tab X ++@item SMJPEG @tab X @tab X ++ @tab Used in certain Loki game ports. ++@item Sony OpenMG (OMA) @tab X @tab X + @tab Audio format used in Sony Sonic Stage and Sony Vegas. + @item Sony PlayStation STR @tab @tab X + @item Sony Wave64 (W64) @tab @tab X +@@ -247,13 +335,18 @@ + @item WAV @tab X @tab X + @item WavPack @tab @tab X + @item WebM @tab X @tab X +-@item Windows Televison (WTV) @tab @tab X ++@item Windows Televison (WTV) @tab X @tab X + @item Wing Commander III movie @tab @tab X + @tab Multimedia format used in Origin's Wing Commander III computer game. + @item Westwood Studios audio @tab @tab X + @tab Multimedia format used in Westwood Studios games. + @item Westwood Studios VQA @tab @tab X + @tab Multimedia format used in Westwood Studios games. ++@item XMV @tab @tab X ++ @tab Microsoft video container used in Xbox games. ++@item xWMA @tab @tab X ++ @tab Microsoft audio container used by XAudio 2. ++@item eXtended BINary text (XBIN) @tab @tab X + @item YUV4MPEG pipe @tab X @tab X + @item Psygnosis YOP @tab @tab X + @end multitable +@@ -273,12 +366,11 @@ + @tab Only uncompressed GIFs are generated. + @item BMP @tab X @tab X + @tab Microsoft BMP image +-@item DPX @tab @tab X ++@item DPX @tab X @tab X + @tab Digital Picture Exchange + @item JPEG @tab X @tab X + @tab Progressive JPEG is not supported. +-@item JPEG 2000 @tab @tab E +- @tab decoding supported through external library libopenjpeg ++@item JPEG 2000 @tab X @tab X + @item JPEG-LS @tab X @tab X + @item LJPEG @tab X @tab + @tab Lossless JPEG +@@ -295,7 +387,6 @@ + @item PIC @tab @tab X + @tab Pictor/PC Paint + @item PNG @tab X @tab X +- @tab 2/4 bpp not supported yet + @item PPM @tab X @tab X + @tab Portable PixelMap image + @item PTX @tab @tab X +@@ -308,6 +399,8 @@ + @tab YUV, JPEG and some extension is not supported yet. + @item Truevision Targa @tab X @tab X + @tab Targa (.TGA) image format ++@item XWD @tab X @tab X ++ @tab X Window Dump image format + @end multitable + + @code{X} means that encoding (resp. decoding) is supported. +@@ -327,10 +420,11 @@ + @tab Creates video suitable to be played on a commodore 64 (multicolor mode). + @item American Laser Games MM @tab @tab X + @tab Used in games like Mad Dog McCree. +-@item AMV Video @tab @tab X ++@item AMV Video @tab X @tab X + @tab Used in Chinese MP3 players. + @item ANSI/ASCII art @tab @tab X + @item Apple MJPEG-B @tab @tab X ++@item Apple ProRes @tab X @tab X + @item Apple QuickDraw @tab @tab X + @tab fourcc: qdrw + @item Asus v1 @tab X @tab X +@@ -346,13 +440,16 @@ + @item Autodesk Animator Flic video @tab @tab X + @item Autodesk RLE @tab @tab X + @tab fourcc: AASC ++@item Avid 1:1 10-bit RGB Packer @tab X @tab X ++ @tab fourcc: AVrp + @item AVS (Audio Video Standard) video @tab @tab X + @tab Video encoding used by the Creature Shock game. + @item Beam Software VB @tab @tab X + @item Bethesda VID video @tab @tab X + @tab Used in some games from Bethesda Softworks. + @item Bink Video @tab @tab X +- @tab Support for version 'b' is missing. ++@item Bitmap Brothers JV video @tab @tab X ++@item y41p Brooktree uncompressed 4:1:1 12-bit @tab X @tab X + @item Brute Force & Ignorance @tab @tab X + @tab Used in the game Flash Traffic: City of Angels. + @item C93 video @tab @tab X +@@ -365,11 +462,14 @@ + @tab AVS1-P2, JiZhun profile, encoding through external library libxavs + @item Delphine Software International CIN video @tab @tab X + @tab Codec used in Delphine Software International games. ++@item Discworld II BMV Video @tab @tab X + @item Cinepak @tab @tab X +-@item Cirrus Logic AccuPak @tab @tab X ++@item Cirrus Logic AccuPak @tab X @tab X + @tab fourcc: CLJR + @item Creative YUV (CYUV) @tab @tab X +-@item Dirac @tab E @tab E ++@item DFA @tab @tab X ++ @tab Codec used in Chronomaster game. ++@item Dirac @tab E @tab X + @tab supported through external libdirac/libschroedinger libraries + @item Deluxe Paint Animation @tab @tab X + @item DNxHD @tab X @tab X +@@ -379,6 +479,7 @@ + @item Duck TrueMotion 2.0 @tab @tab X + @tab fourcc: TM20 + @item DV (Digital Video) @tab X @tab X ++@item Dxtory capture format @tab @tab X + @item Feeble Files/ScummVM DXA @tab @tab X + @tab Codec originally used in Feeble Files game. + @item Electronic Arts CMV video @tab @tab X +@@ -388,10 +489,12 @@ + @item Electronic Arts TGQ video @tab @tab X + @item Electronic Arts TQI video @tab @tab X + @item Escape 124 @tab @tab X ++@item Escape 130 @tab @tab X + @item FFmpeg video codec #1 @tab X @tab X + @tab experimental lossless codec (fourcc: FFV1) + @item Flash Screen Video v1 @tab X @tab X + @tab fourcc: FSV1 ++@item Flash Screen Video v2 @tab X @tab X + @item Flash Video (FLV) @tab X @tab X + @tab Sorenson H.263 used in Flash + @item Fraps @tab @tab X +@@ -410,17 +513,19 @@ + @item id RoQ video @tab X @tab X + @tab Used in Quake III, Jedi Knight 2, other computer games. + @item IFF ILBM @tab @tab X +- @tab IFF interlaved bitmap ++ @tab IFF interleaved bitmap + @item IFF ByteRun1 @tab @tab X + @tab IFF run length encoded bitmap + @item Intel H.263 @tab @tab X + @item Intel Indeo 2 @tab @tab X + @item Intel Indeo 3 @tab @tab X ++@item Intel Indeo 4 @tab @tab X + @item Intel Indeo 5 @tab @tab X + @item Interplay C93 @tab @tab X + @tab Used in the game Cyberia from Interplay. + @item Interplay MVE video @tab @tab X + @tab Used in Interplay .MVE files. ++@item J2K @tab X @tab X + @item Karl Morton's video codec @tab @tab X + @tab Codec used in Worms games. + @item Kega Game Video (KGV1) @tab @tab X +@@ -437,13 +542,14 @@ + @item Miro VideoXL @tab @tab X + @tab fourcc: VIXL + @item MJPEG (Motion JPEG) @tab X @tab X ++@item Mobotix MxPEG video @tab @tab X + @item Motion Pixels video @tab @tab X + @item MPEG-1 video @tab X @tab X + @item MPEG-1/2 video XvMC (X-Video Motion Compensation) @tab @tab X + @item MPEG-1/2 video (VDPAU acceleration) @tab @tab X + @item MPEG-2 video @tab X @tab X + @item MPEG-4 part 2 @tab X @tab X +- @ libxvidcore can be used alternatively for encoding. ++ @tab libxvidcore can be used alternatively for encoding. + @item MPEG-4 part 2 Microsoft variant version 1 @tab @tab X + @item MPEG-4 part 2 Microsoft variant version 2 @tab X @tab X + @item MPEG-4 part 2 Microsoft variant version 3 @tab X @tab X +@@ -460,6 +566,8 @@ + @tab fourcc: VP80, encoding supported through external library libvpx + @item planar RGB @tab @tab X + @tab fourcc: 8BPS ++@item Prores @tab @tab X ++ @tab fourcc: apch,apcn,apcs,apco + @item Q-team QPEG @tab @tab X + @tab fourccs: QPEG, Q1.0, Q1.1 + @item QuickTime 8BPS video @tab @tab X +@@ -469,8 +577,8 @@ + @tab fourcc: 'smc ' + @item QuickTime video (RPZA) @tab @tab X + @tab fourcc: rpza +-@item R10K AJA Kona 10-bit RGB Codec @tab @tab X +-@item R210 Quicktime Uncompressed RGB 10-bit @tab @tab X ++@item R10K AJA Kona 10-bit RGB Codec @tab X @tab X ++@item R210 Quicktime Uncompressed RGB 10-bit @tab X @tab X + @item Raw Video @tab X @tab X + @item RealVideo 1.0 @tab X @tab X + @item RealVideo 2.0 @tab X @tab X +@@ -501,20 +609,29 @@ + @tab encoding supported through external library libtheora + @item Tiertex Limited SEQ video @tab @tab X + @tab Codec used in DOS CD-ROM FlashBack game. +-@item V210 Quicktime Uncompressed 4:2:2 10-bit @tab X @tab X ++@item Ut Video @tab @tab X ++@item v210 QuickTime uncompressed 4:2:2 10-bit @tab X @tab X ++@item v308 QuickTime uncompressed 4:4:4 @tab X @tab X ++@item v410 QuickTime uncompressed 4:4:4 10-bit @tab X @tab X ++@item VBLE Lossless Codec @tab @tab X + @item VMware Screen Codec / VMware Video @tab @tab X + @tab Codec used in videos captured by VMware. + @item Westwood Studios VQA (Vector Quantized Animation) video @tab @tab X ++@item Windows Media Image @tab @tab X + @item Windows Media Video 7 @tab X @tab X + @item Windows Media Video 8 @tab X @tab X + @item Windows Media Video 9 @tab @tab X + @tab not completely working + @item Wing Commander III / Xan @tab @tab X + @tab Used in Wing Commander III .MVE files. ++@item Wing Commander IV / Xan @tab @tab X ++ @tab Used in Wing Commander IV. + @item Winnov WNV1 @tab @tab X + @item WMV7 @tab X @tab X + @item YAMAHA SMAF @tab X @tab X + @item Psygnosis YOP Video @tab @tab X ++@item yuv4 @tab X @tab X ++ @tab libquicktime uncompressed packed 4:2:0 + @item ZLIB @tab X @tab X + @tab part of LCL, encoder experimental + @item Zip Motion Blocks Video @tab X @tab X +@@ -530,8 +647,10 @@ + @multitable @columnfractions .4 .1 .1 .4 + @item Name @tab Encoding @tab Decoding @tab Comments + @item 8SVX audio @tab @tab X ++@item AAC+ @tab E @tab X ++ @tab encoding supported through external library libaacplus + @item AAC @tab E @tab X +- @tab encoding supported through external library libfaac ++ @tab encoding supported through external library libfaac and libvo-aacenc + @item AC-3 @tab IX @tab X + @item ADPCM 4X Movie @tab @tab X + @item ADPCM CDROM XA @tab @tab X +@@ -579,20 +698,24 @@ + @item ADPCM Yamaha @tab X @tab X + @item AMR-NB @tab E @tab X + @tab encoding supported through external library libopencore-amrnb +-@item AMR-WB @tab @tab X ++@item AMR-WB @tab E @tab X ++ @tab encoding supported through external library libvo-amrwbenc + @item Apple lossless audio @tab X @tab X + @tab QuickTime fourcc 'alac' + @item Atrac 1 @tab @tab X + @item Atrac 3 @tab @tab X + @item Bink Audio @tab @tab X + @tab Used in Bink and Smacker files in many games. ++@item CELT @tab @tab E ++ @tab decoding supported through external library libcelt + @item Delphine Software International CIN audio @tab @tab X + @tab Codec used in Delphine Software International games. ++@item Discworld II BMV Audio @tab @tab X + @item COOK @tab @tab X + @tab All versions except 5.1 are supported. +-@item DCA (DTS Coherent Acoustics) @tab @tab X ++@item DCA (DTS Coherent Acoustics) @tab X @tab X + @item DPCM id RoQ @tab X @tab X +- @tab Used in Quake III, Jedi Knight 2, other computer games. ++ @tab Used in Quake III, Jedi Knight 2 and other computer games. + @item DPCM Interplay @tab @tab X + @tab Used in various Interplay computer games. + @item DPCM Sierra Online @tab @tab X +@@ -602,8 +725,10 @@ + @tab Used in Origin's Wing Commander IV AVI files. + @item DSP Group TrueSpeech @tab @tab X + @item DV audio @tab @tab X +-@item Enhanced AC-3 @tab @tab X ++@item Enhanced AC-3 @tab X @tab X + @item FLAC (Free Lossless Audio Codec) @tab X @tab IX ++@item G.723.1 @tab X @tab X ++@item G.729 @tab @tab X + @item GSM @tab E @tab X + @tab encoding supported through external library libgsm + @item GSM Microsoft variant @tab E @tab X +@@ -646,7 +771,7 @@ + @item PCM unsigned 24-bit little-endian @tab X @tab X + @item PCM unsigned 32-bit big-endian @tab X @tab X + @item PCM unsigned 32-bit little-endian @tab X @tab X +-@item PCM Zork @tab X @tab X ++@item PCM Zork @tab @tab X + @item QCELP / PureVoice @tab @tab X + @item QDesign Music Codec 2 @tab @tab X + @tab There are still some distortions. +@@ -661,11 +786,12 @@ + @item Sierra VMD audio @tab @tab X + @tab Used in Sierra VMD files. + @item Smacker audio @tab @tab X ++@item SMPTE 302M AES3 audio @tab @tab X + @item Sonic @tab X @tab X + @tab experimental codec + @item Sonic lossless @tab X @tab X + @tab experimental codec +-@item Speex @tab @tab E ++@item Speex @tab E @tab E + @tab supported through external library libspeex + @item True Audio (TTA) @tab @tab X + @item TrueHD @tab @tab X +@@ -695,8 +821,9 @@ + @item SSA/ASS @tab X @tab X @tab X @tab X + @item DVB @tab X @tab X @tab X @tab X + @item DVD @tab X @tab X @tab X @tab X ++@item MicroDVD @tab X @tab X @tab @tab + @item PGS @tab @tab @tab @tab X +-@item SubRip (SRT) @tab X @tab X @tab @tab X ++@item SubRip (SRT) @tab X @tab X @tab X @tab X + @item XSUB @tab @tab @tab X @tab X + @end multitable + +@@ -706,6 +833,7 @@ + + @multitable @columnfractions .4 .1 + @item Name @tab Support ++@item Apple HTTP Live Streaming @tab X + @item file @tab X + @item Gopher @tab X + @item HTTP @tab X +@@ -729,6 +857,7 @@ + @item JACK @tab X @tab + @item LIBDC1394 @tab X @tab + @item OSS @tab X @tab X ++@item Pulseaudio @tab X @tab + @item Video4Linux @tab X @tab + @item Video4Linux2 @tab X @tab + @item VfW capture @tab X @tab +@@ -737,360 +866,15 @@ + + @code{X} means that input/output is supported. + ++@section Timecode + +-@chapter Platform Specific information +- +-@section DOS +- +-Using a cross-compiler is preferred for various reasons. +- +-@subsection DJGPP +- +-FFmpeg cannot be compiled because of broken system headers, add +-@code{--extra-cflags=-U__STRICT_ANSI__} to the configure options as a +-workaround. +- +-@section OS/2 +- +-For information about compiling FFmpeg on OS/2 see +-@url{http://www.edm2.com/index.php/FFmpeg}. +- +-@section Unix-like +- +-Some parts of FFmpeg cannot be built with version 2.15 of the GNU +-assembler which is still provided by a few AMD64 distributions. To +-make sure your compiler really uses the required version of gas +-after a binutils upgrade, run: +- +-@example +-$(gcc -print-prog-name=as) --version +-@end example +- +-If not, then you should install a different compiler that has no +-hard-coded path to gas. In the worst case pass @code{--disable-asm} +-to configure. +- +-@subsection BSD +- +-BSD make will not build FFmpeg, you need to install and use GNU Make +-(@file{gmake}). +- +-@subsubsection FreeBSD +- +-FreeBSD will not compile out-of-the-box due to broken system headers. +-Passing @code{--extra-cflags=-D__BSD_VISIBLE} to configure will work +-around the problem. This may have unexpected sideeffects, so use it at +-your own risk. If you care about FreeBSD, please make an attempt at +-getting the system headers fixed. +- +-@subsection (Open)Solaris +- +-GNU Make is required to build FFmpeg, so you have to invoke (@file{gmake}), +-standard Solaris Make will not work. When building with a non-c99 front-end +-(gcc, generic suncc) add either @code{--extra-libs=/usr/lib/values-xpg6.o} +-or @code{--extra-libs=/usr/lib/64/values-xpg6.o} to the configure options +-since the libc is not c99-compliant by default. The probes performed by +-configure may raise an exception leading to the death of configure itself +-due to a bug in the system shell. Simply invoke a different shell such as +-bash directly to work around this: +- +-@example +-bash ./configure +-@end example +- +-@subsection Darwin (MacOS X, iPhone) +- +-MacOS X on PowerPC or ARM (iPhone) requires a preprocessor from +-@url{http://github.com/yuvi/gas-preprocessor} to build the optimized +-assembler functions. Just download the Perl script and put it somewhere +-in your PATH, FFmpeg's configure will pick it up automatically. +- +-@section Windows +- +-To get help and instructions for building FFmpeg under Windows, check out +-the FFmpeg Windows Help Forum at +-@url{http://ffmpeg.arrozcru.org/}. +- +-@subsection Native Windows compilation +- +-FFmpeg can be built to run natively on Windows using the MinGW tools. Install +-the latest versions of MSYS and MinGW from @url{http://www.mingw.org/}. +-You can find detailed installation +-instructions in the download section and the FAQ. +- +-FFmpeg does not build out-of-the-box with the packages the automated MinGW +-installer provides. It also requires coreutils to be installed and many other +-packages updated to the latest version. The minimum version for some packages +-are listed below: +- +-@itemize +-@item bash 3.1 +-@item msys-make 3.81-2 (note: not mingw32-make) +-@item w32api 3.13 +-@item mingw-runtime 3.15 +-@end itemize +- +-FFmpeg automatically passes @code{-fno-common} to the compiler to work around +-a GCC bug (see @url{http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216}). +- +-Within the MSYS shell, configure and make with: +- +-@example +-./configure --enable-memalign-hack +-make +-make install +-@end example +- +-This will install @file{ffmpeg.exe} along with many other development files +-to @file{/usr/local}. You may specify another install path using the +-@code{--prefix} option in @file{configure}. +- +-Notes: +- +-@itemize +- +-@item Building natively using MSYS can be sped up by disabling implicit rules +-in the Makefile by calling @code{make -r} instead of plain @code{make}. This +-speed up is close to non-existent for normal one-off builds and is only +-noticeable when running make for a second time (for example in +-@code{make install}). +- +-@item In order to compile FFplay, you must have the MinGW development library +-of SDL. Get it from @url{http://www.libsdl.org}. +-Edit the @file{bin/sdl-config} script so that it points to the correct prefix +-where SDL was installed. Verify that @file{sdl-config} can be launched from +-the MSYS command line. +- +-@item By using @code{./configure --enable-shared} when configuring FFmpeg, +-you can build libavutil, libavcodec and libavformat as DLLs. +- +-@end itemize +- +-@subsection Microsoft Visual C++ compatibility +- +-As stated in the FAQ, FFmpeg will not compile under MSVC++. However, if you +-want to use the libav* libraries in your own applications, you can still +-compile those applications using MSVC++. But the libav* libraries you link +-to @emph{must} be built with MinGW. However, you will not be able to debug +-inside the libav* libraries, since MSVC++ does not recognize the debug +-symbols generated by GCC. +-We strongly recommend you to move over from MSVC++ to MinGW tools. +- +-This description of how to use the FFmpeg libraries with MSVC++ is based on +-Microsoft Visual C++ 2005 Express Edition. If you have a different version, +-you might have to modify the procedures slightly. +- +-@subsubsection Using static libraries +- +-Assuming you have just built and installed FFmpeg in @file{/usr/local}. +- +-@enumerate +- +-@item Create a new console application ("File / New / Project") and then +-select "Win32 Console Application". On the appropriate page of the +-Application Wizard, uncheck the "Precompiled headers" option. +- +-@item Write the source code for your application, or, for testing, just +-copy the code from an existing sample application into the source file +-that MSVC++ has already created for you. For example, you can copy +-@file{libavformat/output-example.c} from the FFmpeg distribution. +- +-@item Open the "Project / Properties" dialog box. In the "Configuration" +-combo box, select "All Configurations" so that the changes you make will +-affect both debug and release builds. In the tree view on the left hand +-side, select "C/C++ / General", then edit the "Additional Include +-Directories" setting to contain the path where the FFmpeg includes were +-installed (i.e. @file{c:\msys\1.0\local\include}). +-Do not add MinGW's include directory here, or the include files will +-conflict with MSVC's. +- +-@item Still in the "Project / Properties" dialog box, select +-"Linker / General" from the tree view and edit the +-"Additional Library Directories" setting to contain the @file{lib} +-directory where FFmpeg was installed (i.e. @file{c:\msys\1.0\local\lib}), +-the directory where MinGW libs are installed (i.e. @file{c:\mingw\lib}), +-and the directory where MinGW's GCC libs are installed +-(i.e. @file{C:\mingw\lib\gcc\mingw32\4.2.1-sjlj}). Then select +-"Linker / Input" from the tree view, and add the files @file{libavformat.a}, +-@file{libavcodec.a}, @file{libavutil.a}, @file{libmingwex.a}, +-@file{libgcc.a}, and any other libraries you used (i.e. @file{libz.a}) +-to the end of "Additional Dependencies". +- +-@item Now, select "C/C++ / Code Generation" from the tree view. Select +-"Debug" in the "Configuration" combo box. Make sure that "Runtime +-Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in +-the "Configuration" combo box and make sure that "Runtime Library" is +-set to "Multi-threaded DLL". +- +-@item Click "OK" to close the "Project / Properties" dialog box. +- +-@item MSVC++ lacks some C99 header files that are fundamental for FFmpeg. +-Get msinttypes from @url{http://code.google.com/p/msinttypes/downloads/list} +-and install it in MSVC++'s include directory +-(i.e. @file{C:\Program Files\Microsoft Visual Studio 8\VC\include}). +- +-@item MSVC++ also does not understand the @code{inline} keyword used by +-FFmpeg, so you must add this line before @code{#include}ing libav*: +-@example +-#define inline _inline +-@end example +- +-@item Build your application, everything should work. +- +-@end enumerate +- +-@subsubsection Using shared libraries +- +-This is how to create DLL and LIB files that are compatible with MSVC++: +- +-@enumerate +- +-@item Add a call to @file{vcvars32.bat} (which sets up the environment +-variables for the Visual C++ tools) as the first line of @file{msys.bat}. +-The standard location for @file{vcvars32.bat} is +-@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}, +-and the standard location for @file{msys.bat} is @file{C:\msys\1.0\msys.bat}. +-If this corresponds to your setup, add the following line as the first line +-of @file{msys.bat}: +- +-@example +-call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" +-@end example +- +-Alternatively, you may start the @file{Visual Studio 2005 Command Prompt}, +-and run @file{c:\msys\1.0\msys.bat} from there. +- +-@item Within the MSYS shell, run @code{lib.exe}. If you get a help message +-from @file{Microsoft (R) Library Manager}, this means your environment +-variables are set up correctly, the @file{Microsoft (R) Library Manager} +-is on the path and will be used by FFmpeg to create +-MSVC++-compatible import libraries. +- +-@item Build FFmpeg with +- +-@example +-./configure --enable-shared --enable-memalign-hack +-make +-make install +-@end example +- +-Your install path (@file{/usr/local/} by default) should now have the +-necessary DLL and LIB files under the @file{bin} directory. +- +-@end enumerate +- +-To use those files with MSVC++, do the same as you would do with +-the static libraries, as described above. But in Step 4, +-you should only need to add the directory where the LIB files are installed +-(i.e. @file{c:\msys\usr\local\bin}). This is not a typo, the LIB files are +-installed in the @file{bin} directory. And instead of adding the static +-libraries (@file{libxxx.a} files) you should add the MSVC import libraries +-(@file{avcodec.lib}, @file{avformat.lib}, @file{avcore.lib}, and +-@file{avutil.lib}). Note that you should not use the GCC import +-libraries (@file{libxxx.dll.a} files), as these will give you undefined +-reference errors. There should be no need for @file{libmingwex.a}, +-@file{libgcc.a}, and @file{wsock32.lib}, nor any other external library +-statically linked into the DLLs. The @file{bin} directory contains a bunch +-of DLL files, but the ones that are actually used to run your application +-are the ones with a major version number in their filenames +-(i.e. @file{avcodec-51.dll}). +- +-FFmpeg headers do not declare global data for Windows DLLs through the usual +-dllexport/dllimport interface. Such data will be exported properly while +-building, but to use them in your MSVC++ code you will have to edit the +-appropriate headers and mark the data as dllimport. For example, in +-libavutil/pixdesc.h you should have: +-@example +-extern __declspec(dllimport) const AVPixFmtDescriptor av_pix_fmt_descriptors[]; +-@end example +- +-@subsection Cross compilation for Windows with Linux +- +-You must use the MinGW cross compilation tools available at +-@url{http://www.mingw.org/}. +- +-Then configure FFmpeg with the following options: +-@example +-./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc- +-@end example +-(you can change the cross-prefix according to the prefix chosen for the +-MinGW tools). +- +-Then you can easily test FFmpeg with Wine +-(@url{http://www.winehq.com/}). +- +-@subsection Compilation under Cygwin +- +-Please use Cygwin 1.7.x as the obsolete 1.5.x Cygwin versions lack +-llrint() in its C library. +- +-Install your Cygwin with all the "Base" packages, plus the +-following "Devel" ones: +-@example +-binutils, gcc4-core, make, subversion, mingw-runtime, texi2html +-@end example +- +-And the following "Utils" one: +-@example +-diffutils +-@end example +- +-Then run +- +-@example +-./configure --enable-static --disable-shared +-@end example +- +-to make a static build. +- +-The current @code{gcc4-core} package is buggy and needs this flag to build +-shared libraries: +- +-@example +-./configure --enable-shared --disable-static --extra-cflags=-fno-reorder-functions +-@end example +- +-If you want to build FFmpeg with additional libraries, download Cygwin +-"Devel" packages for Ogg and Vorbis from any Cygwin packages repository: +-@example +-libogg-devel, libvorbis-devel +-@end example +- +-These library packages are only available from Cygwin Ports +-(@url{http://sourceware.org/cygwinports/}) : +- +-@example +-yasm, libSDL-devel, libdirac-devel, libfaac-devel, libgsm-devel, +-libmp3lame-devel, libschroedinger1.0-devel, speex-devel, libtheora-devel, +-libxvidcore-devel +-@end example +- +-The recommendation for libnut and x264 is to build them from source by +-yourself, as they evolve too quickly for Cygwin Ports to be up to date. +- +-Cygwin 1.7.x has IPv6 support. You can add IPv6 to Cygwin 1.5.x by means +-of the @code{libgetaddrinfo-devel} package, available at Cygwin Ports. +- +-@subsection Crosscompilation for Windows under Cygwin +- +-With Cygwin you can create Windows binaries that do not need the cygwin1.dll. +- +-Just install your Cygwin as explained before, plus these additional +-"Devel" packages: +-@example +-gcc-mingw-core, mingw-runtime, mingw-zlib +-@end example +- +-and add some special flags to your configure invocation. +- +-For a static build run +-@example +-./configure --target-os=mingw32 --enable-memalign-hack --enable-static --disable-shared --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin +-@end example +- +-and for a build with shared libraries +-@example +-./configure --target-os=mingw32 --enable-memalign-hack --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin +-@end example ++@multitable @columnfractions .4 .1 .1 ++@item Codec/format @tab Read @tab Write ++@item DV @tab X @tab X ++@item GXF @tab X @tab X ++@item MOV @tab X @tab ++@item MPEG1/2 @tab X @tab X ++@item MXF @tab @tab X ++@end multitable + + @bye +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/git-howto.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/git-howto.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/git-howto.texi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/git-howto.texi 2012-05-14 14:08:53.178316716 +0200 +@@ -0,0 +1,344 @@ ++\input texinfo @c -*- texinfo -*- ++ ++@settitle Using git to develop FFmpeg ++ ++@titlepage ++@center @titlefont{Using git to develop FFmpeg} ++@end titlepage ++ ++@top ++ ++@contents ++ ++@chapter Introduction ++ ++This document aims in giving some quick references on a set of useful git ++commands. You should always use the extensive and detailed documentation ++provided directly by git: ++ ++@example ++git --help ++man git ++@end example ++ ++shows you the available subcommands, ++ ++@example ++git --help ++man git- ++@end example ++ ++shows information about the subcommand . ++ ++Additional information could be found on the ++@url{http://gitref.org, Git Reference} website ++ ++For more information about the Git project, visit the ++ ++@url{http://git-scm.com/, Git website} ++ ++Consult these resources whenever you have problems, they are quite exhaustive. ++ ++What follows now is a basic introduction to Git and some FFmpeg-specific ++guidelines to ease the contribution to the project ++ ++@chapter Basics Usage ++ ++@section Get GIT ++ ++You can get git from @url{http://git-scm.com/} ++Most distribution and operating system provide a package for it. ++ ++ ++@section Cloning the source tree ++ ++@example ++git clone git://source.ffmpeg.org/ffmpeg ++@end example ++ ++This will put the FFmpeg sources into the directory @var{}. ++ ++@example ++git clone git@@source.ffmpeg.org:ffmpeg ++@end example ++ ++This will put the FFmpeg sources into the directory @var{} and let ++you push back your changes to the remote repository. ++ ++ ++@section Updating the source tree to the latest revision ++ ++@example ++git pull (--rebase) ++@end example ++ ++pulls in the latest changes from the tracked branch. The tracked branch ++can be remote. By default the master branch tracks the branch master in ++the remote origin. ++ ++@float IMPORTANT ++@command{--rebase} (see below) is recommended. ++@end float ++ ++@section Rebasing your local branches ++ ++@example ++git pull --rebase ++@end example ++ ++fetches the changes from the main repository and replays your local commits ++over it. This is required to keep all your local changes at the top of ++FFmpeg's master tree. The master tree will reject pushes with merge commits. ++ ++ ++@section Adding/removing files/directories ++ ++@example ++git add [-A] ++git rm [-r] ++@end example ++ ++GIT needs to get notified of all changes you make to your working ++directory that makes files appear or disappear. ++Line moves across files are automatically tracked. ++ ++ ++@section Showing modifications ++ ++@example ++git diff ++@end example ++ ++will show all local modifications in your working directory as unified diff. ++ ++ ++@section Inspecting the changelog ++ ++@example ++git log ++@end example ++ ++You may also use the graphical tools like gitview or gitk or the web ++interface available at http://source.ffmpeg.org/ ++ ++@section Checking source tree status ++ ++@example ++git status ++@end example ++ ++detects all the changes you made and lists what actions will be taken in case ++of a commit (additions, modifications, deletions, etc.). ++ ++ ++@section Committing ++ ++@example ++git diff --check ++@end example ++ ++to double check your changes before committing them to avoid trouble later ++on. All experienced developers do this on each and every commit, no matter ++how small. ++Every one of them has been saved from looking like a fool by this many times. ++It's very easy for stray debug output or cosmetic modifications to slip in, ++please avoid problems through this extra level of scrutiny. ++ ++For cosmetics-only commits you should get (almost) empty output from ++ ++@example ++git diff -w -b ++@end example ++ ++Also check the output of ++ ++@example ++git status ++@end example ++ ++to make sure you don't have untracked files or deletions. ++ ++@example ++git add [-i|-p|-A] ++@end example ++ ++Make sure you have told git your name and email address ++ ++@example ++git config --global user.name "My Name" ++git config --global user.email my@@email.invalid ++@end example ++ ++Use @var{--global} to set the global configuration for all your git checkouts. ++ ++Git will select the changes to the files for commit. Optionally you can use ++the interactive or the patch mode to select hunk by hunk what should be ++added to the commit. ++ ++ ++@example ++git commit ++@end example ++ ++Git will commit the selected changes to your current local branch. ++ ++You will be prompted for a log message in an editor, which is either ++set in your personal configuration file through ++ ++@example ++git config --global core.editor ++@end example ++ ++or set by one of the following environment variables: ++@var{GIT_EDITOR}, @var{VISUAL} or @var{EDITOR}. ++ ++Log messages should be concise but descriptive. Explain why you made a change, ++what you did will be obvious from the changes themselves most of the time. ++Saying just "bug fix" or "10l" is bad. Remember that people of varying skill ++levels look at and educate themselves while reading through your code. Don't ++include filenames in log messages, Git provides that information. ++ ++Possibly make the commit message have a terse, descriptive first line, an ++empty line and then a full description. The first line will be used to name ++the patch by git format-patch. ++ ++@section Preparing a patchset ++ ++@example ++git format-patch [-o directory] ++@end example ++ ++will generate a set of patches for each commit between @var{} and ++current @var{HEAD}. E.g. ++ ++@example ++git format-patch origin/master ++@end example ++ ++will generate patches for all commits on current branch which are not ++present in upstream. ++A useful shortcut is also ++ ++@example ++git format-patch -n ++@end example ++ ++which will generate patches from last @var{n} commits. ++By default the patches are created in the current directory. ++ ++@section Sending patches for review ++ ++@example ++git send-email ++@end example ++ ++will send the patches created by @command{git format-patch} or directly ++generates them. All the email fields can be configured in the global/local ++configuration or overridden by command line. ++Note that this tool must often be installed separately (e.g. @var{git-email} ++package on Debian-based distros). ++ ++ ++@section Renaming/moving/copying files or contents of files ++ ++Git automatically tracks such changes, making those normal commits. ++ ++@example ++mv/cp path/file otherpath/otherfile ++git add [-A] . ++git commit ++@end example ++ ++ ++@chapter FFmpeg specific ++ ++@section Reverting broken commits ++ ++@example ++git reset ++@end example ++ ++@command{git reset} will uncommit the changes till @var{} rewriting ++the current branch history. ++ ++@example ++git commit --amend ++@end example ++ ++allows to amend the last commit details quickly. ++ ++@example ++git rebase -i origin/master ++@end example ++ ++will replay local commits over the main repository allowing to edit, merge ++or remove some of them in the process. ++ ++@float NOTE ++@command{git reset}, @command{git commit --amend} and @command{git rebase} ++rewrite history, so you should use them ONLY on your local or topic branches. ++The main repository will reject those changes. ++@end float ++ ++@example ++git revert ++@end example ++ ++@command{git revert} will generate a revert commit. This will not make the ++faulty commit disappear from the history. ++ ++@section Pushing changes to remote trees ++ ++@example ++git push ++@end example ++ ++Will push the changes to the default remote (@var{origin}). ++Git will prevent you from pushing changes if the local and remote trees are ++out of sync. Refer to and to sync the local tree. ++ ++@example ++git remote add ++@end example ++ ++Will add additional remote with a name reference, it is useful if you want ++to push your local branch for review on a remote host. ++ ++@example ++git push ++@end example ++ ++Will push the changes to the @var{} repository. ++Omitting @var{} makes @command{git push} update all the remote ++branches matching the local ones. ++ ++@section Finding a specific svn revision ++ ++Since version 1.7.1 git supports @var{:/foo} syntax for specifying commits ++based on a regular expression. see man gitrevisions ++ ++@example ++git show :/'as revision 23456' ++@end example ++ ++will show the svn changeset @var{r23456}. With older git versions searching in ++the @command{git log} output is the easiest option (especially if a pager with ++search capabilities is used). ++This commit can be checked out with ++ ++@example ++git checkout -b svn_23456 :/'as revision 23456' ++@end example ++ ++or for git < 1.7.1 with ++ ++@example ++git checkout -b svn_23456 $SHA1 ++@end example ++ ++where @var{$SHA1} is the commit hash from the @command{git log} output. ++ ++@chapter Server Issues ++ ++Contact the project admins @email{root@@ffmpeg.org} if you have technical ++problems with the GIT server. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/git-howto.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/git-howto.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/git-howto.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/git-howto.txt 2012-05-14 14:08:53.179316736 +0200 +@@ -39,16 +39,17 @@ + + 0. Get GIT: + ++ Most distributions have a git package, if not + You can get git from http://git-scm.com/ + + + 1. Cloning the source tree: + +- git clone git://git.ffmpeg.org/ffmpeg.git ++ git clone git://source.ffmpeg.org/ffmpeg + + This will put the FFmpeg sources into the directory . + +- git clone git@git.ffmpeg.org:ffmpeg.git ++ git clone git@source.ffmpeg.org:ffmpeg + + This will put the FFmpeg sources into the directory and let + you push back your changes to the remote repository. +@@ -97,7 +98,7 @@ + git log + + You may also use the graphical tools like gitview or gitk or the web +- interface available at http://git.ffmpeg.org/ ++ interface available at http://source.ffmpeg.org + + 6. Checking source tree status: + +@@ -120,7 +121,7 @@ + + For cosmetics-only commits you should get (almost) empty output from + +- git diff -wb ++ git diff -w -b + + Also check the output of + +@@ -205,8 +206,19 @@ + + git format-patch [-o directory] + +- will generate a set of patches out of the current branch starting from +- commit. By default the patches are created in the current directory. ++ will generate a set of patches for each commit between and ++ current HEAD. E.g. ++ ++ git format-patch origin/master ++ ++ will generate patches for all commits on current branch which are not ++ present in upstream. ++ A useful shortcut is also ++ ++ git format-patch -n ++ ++ which will generate patches from last n commits. ++ By default the patches are created in the current directory. + + 11. Sending patches for review + +@@ -215,6 +227,8 @@ + will send the patches created by git format-patch or directly generates + them. All the email fields can be configured in the global/local + configuration or overridden by command line. ++ Note that this tool must often be installed separately (e.g. git-email ++ package on Debian-based distros). + + 12. Pushing changes to remote trees + +@@ -255,5 +269,5 @@ + where $SHA1 is the commit SHA1 from the 'git log' output. + + +-Contact the project admins if you have technical ++Contact the project admins if you have technical + problems with the GIT server. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/indevs.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/indevs.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/indevs.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/indevs.texi 2012-05-14 14:08:53.181316776 +0200 +@@ -42,7 +42,7 @@ + To see the list of cards currently recognized by your system check the + files @file{/proc/asound/cards} and @file{/proc/asound/devices}. + +-For example to capture with @file{ffmpeg} from an ALSA device with ++For example to capture with @command{ffmpeg} from an ALSA device with + card id 0, you may run the command: + @example + ffmpeg -f alsa -i hw:0 alsaout.wav +@@ -55,10 +55,130 @@ + + BSD video input device. + ++@section dshow ++ ++Windows DirectShow input device. ++ ++DirectShow support is enabled when FFmpeg is built with mingw-w64. ++Currently only audio and video devices are supported. ++ ++Multiple devices may be opened as separate inputs, but they may also be ++opened on the same input, which should improve synchronism between them. ++ ++The input name should be in the format: ++ ++@example ++@var{TYPE}=@var{NAME}[:@var{TYPE}=@var{NAME}] ++@end example ++ ++where @var{TYPE} can be either @var{audio} or @var{video}, ++and @var{NAME} is the device's name. ++ ++@subsection Options ++ ++If no options are specified, the device's defaults are used. ++If the device does not support the requested options, it will ++fail to open. ++ ++@table @option ++ ++@item video_size ++Set the video size in the captured video. ++ ++@item framerate ++Set the framerate in the captured video. ++ ++@item sample_rate ++Set the sample rate (in Hz) of the captured audio. ++ ++@item sample_size ++Set the sample size (in bits) of the captured audio. ++ ++@item channels ++Set the number of channels in the captured audio. ++ ++@item list_devices ++If set to @option{true}, print a list of devices and exit. ++ ++@item list_options ++If set to @option{true}, print a list of selected device's options ++and exit. ++ ++@item video_device_number ++Set video device number for devices with same name (starts at 0, ++defaults to 0). ++ ++@item audio_device_number ++Set audio device number for devices with same name (starts at 0, ++defaults to 0). ++ ++@end table ++ ++@subsection Examples ++ ++@itemize ++ ++@item ++Print the list of DirectShow supported devices and exit: ++@example ++$ ffmpeg -list_devices true -f dshow -i dummy ++@end example ++ ++@item ++Open video device @var{Camera}: ++@example ++$ ffmpeg -f dshow -i video="Camera" ++@end example ++ ++@item ++Open second video device with name @var{Camera}: ++@example ++$ ffmpeg -f dshow -video_device_number 1 -i video="Camera" ++@end example ++ ++@item ++Open video device @var{Camera} and audio device @var{Microphone}: ++@example ++$ ffmpeg -f dshow -i video="Camera":audio="Microphone" ++@end example ++ ++@item ++Print the list of supported options in selected device and exit: ++@example ++$ ffmpeg -list_options true -f dshow -i video="Camera" ++@end example ++ ++@end itemize ++ + @section dv1394 + + Linux DV 1394 input device. + ++@section fbdev ++ ++Linux framebuffer input device. ++ ++The Linux framebuffer is a graphic hardware-independent abstraction ++layer to show graphics on a computer monitor, typically on the ++console. It is accessed through a file device node, usually ++@file{/dev/fb0}. ++ ++For more detailed information read the file ++Documentation/fb/framebuffer.txt included in the Linux source tree. ++ ++To record from the framebuffer device @file{/dev/fb0} with ++@command{ffmpeg}: ++@example ++ffmpeg -f fbdev -r 10 -i /dev/fb0 out.avi ++@end example ++ ++You can take a single screenshot image with the command: ++@example ++ffmpeg -f fbdev -frames:v 1 -r 1 -i /dev/fb0 screenshot.jpeg ++@end example ++ ++See also @url{http://linux-fbdev.sourceforge.net/}, and fbset(1). ++ + @section jack + + JACK input device. +@@ -76,15 +196,15 @@ + Once you have created one or more JACK readable clients, you need to + connect them to one or more JACK writable clients. + +-To connect or disconnect JACK clients you can use the +-@file{jack_connect} and @file{jack_disconnect} programs, or do it +-through a graphical interface, for example with @file{qjackctl}. ++To connect or disconnect JACK clients you can use the @command{jack_connect} ++and @command{jack_disconnect} programs, or do it through a graphical interface, ++for example with @command{qjackctl}. + + To list the JACK clients and their properties you can invoke the command +-@file{jack_lsp}. ++@command{jack_lsp}. + + Follows an example which shows how to capture a JACK readable client +-with @file{ffmpeg}. ++with @command{ffmpeg}. + @example + # Create a JACK writable client with name "ffmpeg". + $ ffmpeg -f jack -i ffmpeg -y out.wav +@@ -108,10 +228,165 @@ + For more information read: + @url{http://jackaudio.org/} + ++@section lavfi ++ ++Libavfilter input virtual device. ++ ++This input device reads data from the open output pads of a libavfilter ++filtergraph. ++ ++For each filtergraph open output, the input device will create a ++corresponding stream which is mapped to the generated output. Currently ++only video data is supported. The filtergraph is specified through the ++option @option{graph}. ++ ++@subsection Options ++ ++@table @option ++ ++@item graph ++Specify the filtergraph to use as input. Each video open output must be ++labelled by a unique string of the form "out@var{N}", where @var{N} is a ++number starting from 0 corresponding to the mapped input stream ++generated by the device. ++The first unlabelled output is automatically assigned to the "out0" ++label, but all the others need to be specified explicitly. ++ ++If not specified defaults to the filename specified for the input ++device. ++@end table ++ ++@subsection Examples ++ ++@itemize ++@item ++Create a color video stream and play it back with @command{ffplay}: ++@example ++ffplay -f lavfi -graph "color=pink [out0]" dummy ++@end example ++ ++@item ++As the previous example, but use filename for specifying the graph ++description, and omit the "out0" label: ++@example ++ffplay -f lavfi color=pink ++@end example ++ ++@item ++Create three different video test filtered sources and play them: ++@example ++ffplay -f lavfi -graph "testsrc [out0]; testsrc,hflip [out1]; testsrc,negate [out2]" test3 ++@end example ++ ++@item ++Read an audio stream from a file using the amovie source and play it ++back with @command{ffplay}: ++@example ++ffplay -f lavfi "amovie=test.wav" ++@end example ++ ++@item ++Read an audio stream and a video stream and play it back with ++@command{ffplay}: ++@example ++ffplay -f lavfi "movie=test.avi[out0];amovie=test.wav[out1]" ++@end example ++ ++@end itemize ++ + @section libdc1394 + + IIDC1394 input device, based on libdc1394 and libraw1394. + ++@section openal ++ ++The OpenAL input device provides audio capture on all systems with a ++working OpenAL 1.1 implementation. ++ ++To enable this input device during configuration, you need OpenAL ++headers and libraries installed on your system, and need to configure ++FFmpeg with @code{--enable-openal}. ++ ++OpenAL headers and libraries should be provided as part of your OpenAL ++implementation, or as an additional download (an SDK). Depending on your ++installation you may need to specify additional flags via the ++@code{--extra-cflags} and @code{--extra-ldflags} for allowing the build ++system to locate the OpenAL headers and libraries. ++ ++An incomplete list of OpenAL implementations follows: ++ ++@table @strong ++@item Creative ++The official Windows implementation, providing hardware acceleration ++with supported devices and software fallback. ++See @url{http://openal.org/}. ++@item OpenAL Soft ++Portable, open source (LGPL) software implementation. Includes ++backends for the most common sound APIs on the Windows, Linux, ++Solaris, and BSD operating systems. ++See @url{http://kcat.strangesoft.net/openal.html}. ++@item Apple ++OpenAL is part of Core Audio, the official Mac OS X Audio interface. ++See @url{http://developer.apple.com/technologies/mac/audio-and-video.html} ++@end table ++ ++This device allows to capture from an audio input device handled ++through OpenAL. ++ ++You need to specify the name of the device to capture in the provided ++filename. If the empty string is provided, the device will ++automatically select the default device. You can get the list of the ++supported devices by using the option @var{list_devices}. ++ ++@subsection Options ++ ++@table @option ++ ++@item channels ++Set the number of channels in the captured audio. Only the values ++@option{1} (monaural) and @option{2} (stereo) are currently supported. ++Defaults to @option{2}. ++ ++@item sample_size ++Set the sample size (in bits) of the captured audio. Only the values ++@option{8} and @option{16} are currently supported. Defaults to ++@option{16}. ++ ++@item sample_rate ++Set the sample rate (in Hz) of the captured audio. ++Defaults to @option{44.1k}. ++ ++@item list_devices ++If set to @option{true}, print a list of devices and exit. ++Defaults to @option{false}. ++ ++@end table ++ ++@subsection Examples ++ ++Print the list of OpenAL supported devices and exit: ++@example ++$ ffmpeg -list_devices true -f openal -i dummy out.ogg ++@end example ++ ++Capture from the OpenAL device @file{DR-BT101 via PulseAudio}: ++@example ++$ ffmpeg -f openal -i 'DR-BT101 via PulseAudio' out.ogg ++@end example ++ ++Capture from the default device (note the empty string '' as filename): ++@example ++$ ffmpeg -f openal -i '' out.ogg ++@end example ++ ++Capture from two devices simultaneously, writing to two different files, ++within the same @command{ffmpeg} command: ++@example ++$ ffmpeg -f openal -i 'DR-BT101 via PulseAudio' out1.ogg -f openal -i 'ALSA Default' out2.ogg ++@end example ++Note: not all OpenAL implementations support multiple simultaneous capture - ++try the latest OpenAL Soft if the above does not work. ++ + @section oss + + Open Sound System input device. +@@ -120,7 +395,7 @@ + representing the OSS input device, and is usually set to + @file{/dev/dsp}. + +-For example to grab from @file{/dev/dsp} using @file{ffmpeg} use the ++For example to grab from @file{/dev/dsp} using @command{ffmpeg} use the + command: + @example + ffmpeg -f oss -i /dev/dsp /tmp/oss.wav +@@ -129,6 +404,106 @@ + For more information about OSS see: + @url{http://manuals.opensound.com/usersguide/dsp.html} + ++@section pulse ++ ++pulseaudio input device. ++ ++To enable this input device during configuration you need libpulse-simple ++installed in your system. ++ ++The filename to provide to the input device is a source device or the ++string "default" ++ ++To list the pulse source devices and their properties you can invoke ++the command @command{pactl list sources}. ++ ++@example ++ffmpeg -f pulse -i default /tmp/pulse.wav ++@end example ++ ++@subsection @var{server} AVOption ++ ++The syntax is: ++@example ++-server @var{server name} ++@end example ++ ++Connects to a specific server. ++ ++@subsection @var{name} AVOption ++ ++The syntax is: ++@example ++-name @var{application name} ++@end example ++ ++Specify the application name pulse will use when showing active clients, ++by default it is the LIBAVFORMAT_IDENT string ++ ++@subsection @var{stream_name} AVOption ++ ++The syntax is: ++@example ++-stream_name @var{stream name} ++@end example ++ ++Specify the stream name pulse will use when showing active streams, ++by default it is "record" ++ ++@subsection @var{sample_rate} AVOption ++ ++The syntax is: ++@example ++-sample_rate @var{samplerate} ++@end example ++ ++Specify the samplerate in Hz, by default 48kHz is used. ++ ++@subsection @var{channels} AVOption ++ ++The syntax is: ++@example ++-channels @var{N} ++@end example ++ ++Specify the channels in use, by default 2 (stereo) is set. ++ ++@subsection @var{frame_size} AVOption ++ ++The syntax is: ++@example ++-frame_size @var{bytes} ++@end example ++ ++Specify the number of byte per frame, by default it is set to 1024. ++ ++@subsection @var{fragment_size} AVOption ++ ++The syntax is: ++@example ++-fragment_size @var{bytes} ++@end example ++ ++Specify the minimal buffering fragment in pulseaudio, it will affect the ++audio latency. By default it is unset. ++ ++@section sndio ++ ++sndio input device. ++ ++To enable this input device during configuration you need libsndio ++installed on your system. ++ ++The filename to provide to the input device is the device node ++representing the sndio input device, and is usually set to ++@file{/dev/audio0}. ++ ++For example to grab from @file{/dev/audio0} using @command{ffmpeg} use the ++command: ++@example ++ffmpeg -f sndio -i /dev/audio0 /tmp/oss.wav ++@end example ++ + @section video4linux and video4linux2 + + Video4Linux and Video4Linux2 input video devices. +@@ -141,17 +516,20 @@ + + Video4Linux and Video4Linux2 devices only support a limited set of + @var{width}x@var{height} sizes and framerates. You can check which are +-supported for example with the command @file{dov4l} for Video4Linux +-devices and the command @file{v4l-info} for Video4Linux2 devices. ++supported for example with the command @command{dov4l} for Video4Linux ++devices and using @command{-list_formats all} for Video4Linux2 devices. + + If the size for the device is set to 0x0, the input device will +-try to autodetect the size to use. ++try to auto-detect the size to use. + Only for the video4linux2 device, if the frame rate is set to 0/0 the + input device will use the frame rate value already set in the driver. + + Video4Linux support is deprecated since Linux 2.6.30, and will be + dropped in later versions. + ++Note that if FFmpeg is build with v4l-utils support ("--enable-libv4l2" ++option), it will always be used. ++ + Follow some usage examples of the video4linux devices with the ff* + tools. + @example +@@ -159,15 +537,18 @@ + # to the default of 25/1. + ffplay -s 320x240 -f video4linux /dev/video0 + +-# Grab and show the input of a video4linux2 device, autoadjust size. ++# Grab and show the input of a video4linux2 device, auto-adjust size. + ffplay -f video4linux2 /dev/video0 + +-# Grab and record the input of a video4linux2 device, autoadjust size, ++# Grab and record the input of a video4linux2 device, auto-adjust size, + # frame rate value defaults to 0/0 so it is read from the video4linux2 + # driver. + ffmpeg -f video4linux2 -i /dev/video0 out.mpeg + @end example + ++"v4l" and "v4l2" can be used as aliases for the respective "video4linux" and ++"video4linux2". ++ + @section vfwcap + + VfW (Video for Windows) capture input device. +@@ -189,7 +570,7 @@ + + @var{hostname}:@var{display_number}.@var{screen_number} specifies the + X11 display name of the screen to grab from. @var{hostname} can be +-ommitted, and defaults to "localhost". The environment variable ++omitted, and defaults to "localhost". The environment variable + @env{DISPLAY} contains the default display name. + + @var{x_offset} and @var{y_offset} specify the offsets of the grabbed +@@ -198,15 +579,54 @@ + + Check the X11 documentation (e.g. man X) for more detailed information. + +-Use the @file{dpyinfo} program for getting basic information about the ++Use the @command{dpyinfo} program for getting basic information about the + properties of your X11 display (e.g. grep for "name" or "dimensions"). + +-For example to grab from @file{:0.0} using @file{ffmpeg}: ++For example to grab from @file{:0.0} using @command{ffmpeg}: + @example + ffmpeg -f x11grab -r 25 -s cif -i :0.0 out.mpg + + # Grab at position 10,20. +-ffmpeg -f x11grab -25 -s cif -i :0.0+10,20 out.mpg ++ffmpeg -f x11grab -r 25 -s cif -i :0.0+10,20 out.mpg ++@end example ++ ++@subsection @var{follow_mouse} AVOption ++ ++The syntax is: ++@example ++-follow_mouse centered|@var{PIXELS} ++@end example ++ ++When it is specified with "centered", the grabbing region follows the mouse ++pointer and keeps the pointer at the center of region; otherwise, the region ++follows only when the mouse pointer reaches within @var{PIXELS} (greater than ++zero) to the edge of region. ++ ++For example: ++@example ++ffmpeg -f x11grab -follow_mouse centered -r 25 -s cif -i :0.0 out.mpg ++ ++# Follows only when the mouse pointer reaches within 100 pixels to edge ++ffmpeg -f x11grab -follow_mouse 100 -r 25 -s cif -i :0.0 out.mpg ++@end example ++ ++@subsection @var{show_region} AVOption ++ ++The syntax is: ++@example ++-show_region 1 ++@end example ++ ++If @var{show_region} AVOption is specified with @var{1}, then the grabbing ++region will be indicated on screen. With this option, it's easy to know what is ++being grabbed if only a portion of the screen is grabbed. ++ ++For example: ++@example ++ffmpeg -f x11grab -show_region 1 -r 25 -s cif -i :0.0+10,20 out.mpg ++ ++# With follow_mouse ++ffmpeg -f x11grab -follow_mouse centered -show_region 1 -r 25 -s cif -i :0.0 out.mpg + @end example + + @c man end INPUT DEVICES +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/issue_tracker.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/issue_tracker.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/issue_tracker.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/issue_tracker.txt 2012-05-14 14:08:53.182316796 +0200 +@@ -5,49 +5,42 @@ + + Overview: + --------- +-FFmpeg uses Roundup for tracking issues, new issues and changes to +-existing issues can be done through a web interface and through email. ++ ++FFmpeg uses Trac for tracking issues, new issues and changes to ++existing issues can be done through a web interface. ++ ++Issues can be different kinds of things we want to keep track of ++but that do not belong into the source tree itself. This includes ++bug reports, patches, feature requests and license violations. We ++might add more items to this list in the future, so feel free to ++propose a new `type of issue' on the ffmpeg-devel mailing list if ++you feel it is worth tracking. ++ + It is possible to subscribe to individual issues by adding yourself to the +-nosy list or to subscribe to the ffmpeg-issues mailing list which receives +-a mail for every change to every issue. Replies to such mails will also +-be properly added to the respective issue. ++Cc list or to subscribe to the ffmpeg-trac mailing list which receives ++a mail for every change to every issue. + (the above does all work already after light testing) +-The subscription URL for the ffmpeg-issues list is: +-http://live.polito/mailman/listinfo/ffmpeg-issues +-The URL of the webinterface of the tracker is: +-http(s)://roundup.ffmpeg/roundup/ffmpeg/ +-Note the URLs in this document are obfuscated, you must append the top level +-domain for non-profit organizations to the tracker, and of Italy to the +-mailing list. +- +-Email Interface: +----------------- +-There is a mailing list to which all new issues and changes to existing issues +-are sent. You can subscribe through +-http://live.polito/mailman/listinfo/ffmpeg-issues +-Replies to messages there will have their text added to the specific issues. +-Attachments will be added as if they had been uploaded via the web interface. +-You can change the status, substatus, topic, ... by changing the subject in +-your reply like: +-Re: [issue94] register_avcodec and allcodecs.h [type=patch;status=open;substatus=approved] +-Roundup will then change things as you requested and remove the [...] from +-the subject before forwarding the mail to the mailing list. + +- +-NOTE: issue = (bug report || patch || feature request) ++The subscription URL for the ffmpeg-trac list is: ++http(s)://ffmpeg.org/mailman/listinfo/ffmpeg-trac ++The URL of the webinterface of the tracker is: ++http(s)://ffmpeg.org/trac/ffmpeg + + Type: + ----- +-bug ++bug / defect + An error, flaw, mistake, failure, or fault in FFmpeg or libav* that + prevents it from behaving as intended. + +-feature request ++feature request / enhancement + Request of support for encoding or decoding of a new codec, container + or variant. + Request of support for more, less or plain different output or behavior + where the current implementation cannot be considered wrong. + ++license violation ++ ticket to keep track of (L)GPL violations of ffmpeg by others ++ + patch + A patch as generated by diff which conforms to the patch submission and + development policy. +@@ -68,6 +61,8 @@ + the separation to normal is somewhat fuzzy. + For feature requests this priority would be used for things many people + want. ++ Regressions also should be marked as important, regressions are bugs that ++ don't exist in a past revision or another branch. + + normal + +@@ -97,6 +92,17 @@ + final state + + ++Analyzed flag: ++-------------- ++Bugs which have been analyzed and where it is understood what causes them ++and which exact chain of events triggers them. This analysis should be ++available as a message in the bug report. ++Note, do not change the status to analyzed without also providing a clear ++and understandable analysis. ++This state implicates that the bug either has been reproduced or that ++reproduction is not needed as the bug is already understood. ++ ++ + Type/Status/Substatus: + ---------- + */new/new +@@ -124,24 +130,6 @@ + Issues for which some information has been requested by the developers, + but which has not been provided by anyone within reasonable time. + +-bug/open/reproduced +- Bugs which have been reproduced. +- +-bug/open/analyzed +- Bugs which have been analyzed and where it is understood what causes them +- and which exact chain of events triggers them. This analysis should be +- available as a message in the bug report. +- Note, do not change the status to analyzed without also providing a clear +- and understandable analysis. +- This state implicates that the bug either has been reproduced or that +- reproduction is not needed as the bug is already understood. +- +-bug/open/needs_more_info +- Bug reports which are incomplete and or where more information is needed +- from the submitter or another person who can provide it. +- This state implicates that the bug has not been analyzed or reproduced. +- Note, the idea behind needs_more_info is to offload work from the +- developers to the users whenever possible. + + bug/closed/fixed + Bugs which have to the best of our knowledge been fixed. +@@ -175,10 +163,6 @@ + patch/closed/rejected + Patches which have been rejected. + +-feature_request/open/needs_more_info +- Feature requests where it is not clear what exactly is wanted +- (these also could be closed as invalid ...). +- + feature_request/closed/implemented + Feature requests which have been implemented. + +@@ -190,12 +174,10 @@ + above without asking on ffmpeg-dev first! + + Note2, if you provide the requested info do not forget to remove the +-needs_more_info substate. ++needs_more_info substatus. + +-Topic: +------- +-A topic is a tag you should add to your issue in order to make grouping them +-easier. ++Component: ++---------- + + avcodec + issues in libavcodec/* +@@ -215,6 +197,9 @@ + ffplay + issues in or related to ffplay.c + ++ffprobe ++ issues in or related to ffprobe.c ++ + ffserver + issues in or related to ffserver.c + +@@ -222,7 +207,7 @@ + issues in or related to configure/Makefile + + regression +- bugs which were working in a past revision ++ bugs which were not present in a past revision + +-roundup ++trac + issues related to our issue tracker +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/libavfilter.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/libavfilter.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/libavfilter.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/libavfilter.texi 2012-05-14 14:08:53.183316816 +0200 +@@ -14,20 +14,8 @@ + Libavfilter is the filtering API of FFmpeg. It is the substitute of the + now deprecated 'vhooks' and started as a Google Summer of Code project. + +-Integrating libavfilter into the main FFmpeg repository is a work in +-progress. If you wish to try the unfinished development code of +-libavfilter then check it out from the libavfilter repository into +-some directory of your choice by: +- +-@example +- svn checkout svn://svn.ffmpeg.org/soc/libavfilter +-@end example +- +-And then read the README file in the top directory to learn how to +-integrate it into ffmpeg and ffplay. +- +-But note that there may still be serious bugs in the code and its API +-and ABI should not be considered stable yet! ++Audio filtering integration into the main FFmpeg repository is a work in ++progress, so audio API and ABI should not be considered stable yet. + + @chapter Tutorial + +@@ -48,21 +36,20 @@ + overlaying it on top. You can use the following command to achieve this: + + @example +-./ffmpeg -i in.avi -s 240x320 -vf "[in] split [T1], fifo, [T2] overlay= 0:240 [out]; [T1] fifo, crop=0:0:-1:240, vflip [T2] ++ffmpeg -i input -vf "[in] split [T1], fifo, [T2] overlay=0:H/2 [out]; [T1] fifo, crop=iw:ih/2:0:ih/2, vflip [T2]" output + @end example + +-where input_video.avi has a vertical resolution of 480 pixels. The +-result will be that in output the top half of the video is mirrored ++The result will be that in output the top half of the video is mirrored + onto the bottom half. + + Video filters are loaded using the @var{-vf} option passed to +-ffmpeg or to ffplay. Filters in the same linear chain are separated by +-commas. In our example, @var{split, fifo, overlay} are in one linear +-chain, and @var{fifo, crop, vflip} are in another. The points where +-the linear chains join are labeled by names enclosed in square +-brackets. In our example, that is @var{[T1]} and @var{[T2]}. The magic +-labels @var{[in]} and @var{[out]} are the points where video is input +-and output. ++@command{ffmpeg} or to @command{ffplay}. Filters in the same linear ++chain are separated by commas. In our example, @var{split, fifo, ++overlay} are in one linear chain, and @var{fifo, crop, vflip} are in ++another. The points where the linear chains join are labeled by names ++enclosed in square brackets. In our example, that is @var{[T1]} and ++@var{[T2]}. The magic labels @var{[in]} and @var{[out]} are the points ++where video is input and output. + + Some filters take in input a list of parameters: they are specified + after the filter name and an equal sign, and are separated each other +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/Makefile 2012-05-14 14:08:53.128315709 +0200 +@@ -0,0 +1,64 @@ ++MANPAGES = $(PROGS-yes:%=doc/%.1) ++PODPAGES = $(PROGS-yes:%=doc/%.pod) ++HTMLPAGES = $(PROGS-yes:%=doc/%.html) \ ++ doc/developer.html \ ++ doc/faq.html \ ++ doc/fate.html \ ++ doc/general.html \ ++ doc/git-howto.html \ ++ doc/libavfilter.html \ ++ doc/platform.html \ ++ ++TXTPAGES = doc/fate.txt \ ++ ++ ++DOCS = $(HTMLPAGES) $(MANPAGES) $(PODPAGES) ++ifdef HAVE_MAKEINFO ++DOCS += $(TXTPAGES) ++endif ++ ++all-$(CONFIG_DOC): documentation ++ ++documentation: $(DOCS) ++ ++TEXIDEP = awk '/^@(verbatim)?include/ { printf "$@: $(@D)/%s\n", $$2 }' <$< >$(@:%=%.d) ++ ++doc/%.txt: TAG = TXT ++doc/%.txt: doc/%.texi ++ $(Q)$(TEXIDEP) ++ $(M)makeinfo --force --no-headers -o $@ $< 2>/dev/null ++ ++doc/%.html: TAG = HTML ++doc/%.html: doc/%.texi $(SRC_PATH)/doc/t2h.init ++ $(Q)$(TEXIDEP) ++ $(M)texi2html -monolithic --init-file $(SRC_PATH)/doc/t2h.init --output $@ $< ++ ++doc/%.pod: TAG = POD ++doc/%.pod: doc/%.texi ++ $(Q)$(TEXIDEP) ++ $(M)$(SRC_PATH)/doc/texi2pod.pl $< $@ ++ ++doc/%.1: TAG = MAN ++doc/%.1: doc/%.pod ++ $(M)pod2man --section=1 --center=" " --release=" " $< > $@ ++ ++$(DOCS): | doc ++OBJDIRS += doc ++ ++install-progs-$(CONFIG_DOC): install-man ++ ++install-man: $(MANPAGES) ++ $(Q)mkdir -p "$(MANDIR)/man1" ++ $(INSTALL) -m 644 $(MANPAGES) "$(MANDIR)/man1" ++ ++uninstall: uninstall-man ++ ++uninstall-man: ++ $(RM) $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES)) ++ ++clean:: ++ $(RM) $(TXTPAGES) doc/*.html doc/*.pod doc/*.1 $(CLEANSUFFIXES:%=doc/%) ++ ++-include $(wildcard $(DOCS:%=%.d)) ++ ++.PHONY: documentation +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/multithreading.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/multithreading.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/multithreading.txt 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/multithreading.txt 2012-05-14 14:08:53.183316816 +0200 +@@ -0,0 +1,65 @@ ++FFmpeg multithreading methods ++============================================== ++ ++FFmpeg provides two methods for multithreading codecs. ++ ++Slice threading decodes multiple parts of a frame at the same time, using ++AVCodecContext execute() and execute2(). ++ ++Frame threading decodes multiple frames at the same time. ++It accepts N future frames and delays decoded pictures by N-1 frames. ++The later frames are decoded in separate threads while the user is ++displaying the current one. ++ ++Restrictions on clients ++============================================== ++ ++Slice threading - ++* The client's draw_horiz_band() must be thread-safe according to the comment ++ in avcodec.h. ++ ++Frame threading - ++* Restrictions with slice threading also apply. ++* For best performance, the client should set thread_safe_callbacks if it ++ provides a thread-safe get_buffer() callback. ++* There is one frame of delay added for every thread beyond the first one. ++ Clients must be able to handle this; the pkt_dts and pkt_pts fields in ++ AVFrame will work as usual. ++ ++Restrictions on codec implementations ++============================================== ++ ++Slice threading - ++ None except that there must be something worth executing in parallel. ++ ++Frame threading - ++* Codecs can only accept entire pictures per packet. ++* Codecs similar to ffv1, whose streams don't reset across frames, ++ will not work because their bitstreams cannot be decoded in parallel. ++ ++* The contents of buffers must not be read before ff_thread_await_progress() ++ has been called on them. reget_buffer() and buffer age optimizations no longer work. ++* The contents of buffers must not be written to after ff_thread_report_progress() ++ has been called on them. This includes draw_edges(). ++ ++Porting codecs to frame threading ++============================================== ++ ++Find all context variables that are needed by the next frame. Move all ++code changing them, as well as code calling get_buffer(), up to before ++the decode process starts. Call ff_thread_finish_setup() afterwards. If ++some code can't be moved, have update_thread_context() run it in the next ++thread. ++ ++If the codec allocates writable tables in its init(), add an init_thread_copy() ++which re-allocates them for other threads. ++ ++Add CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little ++speed gain at this point but it should work. ++ ++Call ff_thread_report_progress() after some part of the current picture has decoded. ++A good place to put this is where draw_horiz_band() is called - add this if it isn't ++called anywhere, as it's useful too and the implementation is trivial when you're ++doing this. Note that draw_edges() needs to be called before reporting progress. ++ ++Before accessing a reference frame or its MVs, call ff_thread_await_progress(). +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/muxers.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/muxers.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/muxers.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/muxers.texi 2012-05-14 14:08:53.184316836 +0200 +@@ -18,16 +18,90 @@ + + A description of some of the currently available muxers follows. + ++@anchor{crc} ++@section crc ++ ++CRC (Cyclic Redundancy Check) testing format. ++ ++This muxer computes and prints the Adler-32 CRC of all the input audio ++and video frames. By default audio frames are converted to signed ++16-bit raw audio and video frames to raw video before computing the ++CRC. ++ ++The output of the muxer consists of a single line of the form: ++CRC=0x@var{CRC}, where @var{CRC} is a hexadecimal number 0-padded to ++8 digits containing the CRC for all the decoded input frames. ++ ++For example to compute the CRC of the input, and store it in the file ++@file{out.crc}: ++@example ++ffmpeg -i INPUT -f crc out.crc ++@end example ++ ++You can print the CRC to stdout with the command: ++@example ++ffmpeg -i INPUT -f crc - ++@end example ++ ++You can select the output format of each frame with @command{ffmpeg} by ++specifying the audio and video codec and format. For example to ++compute the CRC of the input audio converted to PCM unsigned 8-bit ++and the input video converted to MPEG-2 video, use the command: ++@example ++ffmpeg -i INPUT -c:a pcm_u8 -c:v mpeg2video -f crc - ++@end example ++ ++See also the @ref{framecrc} muxer. ++ ++@anchor{framecrc} ++@section framecrc ++ ++Per-frame CRC (Cyclic Redundancy Check) testing format. ++ ++This muxer computes and prints the Adler-32 CRC for each decoded audio ++and video frame. By default audio frames are converted to signed ++16-bit raw audio and video frames to raw video before computing the ++CRC. ++ ++The output of the muxer consists of a line for each audio and video ++frame of the form: @var{stream_index}, @var{frame_dts}, ++@var{frame_size}, 0x@var{CRC}, where @var{CRC} is a hexadecimal ++number 0-padded to 8 digits containing the CRC of the decoded frame. ++ ++For example to compute the CRC of each decoded frame in the input, and ++store it in the file @file{out.crc}: ++@example ++ffmpeg -i INPUT -f framecrc out.crc ++@end example ++ ++You can print the CRC of each decoded frame to stdout with the command: ++@example ++ffmpeg -i INPUT -f framecrc - ++@end example ++ ++You can select the output format of each frame with @command{ffmpeg} by ++specifying the audio and video codec and format. For example, to ++compute the CRC of each decoded input audio frame converted to PCM ++unsigned 8-bit and of each decoded input video frame converted to ++MPEG-2 video, use the command: ++@example ++ffmpeg -i INPUT -c:a pcm_u8 -c:v mpeg2video -f framecrc - ++@end example ++ ++See also the @ref{crc} muxer. ++ ++@anchor{image2} + @section image2 + + Image file muxer. + +-This muxer writes video frames to multiple image files specified by a +-pattern. ++The image file muxer writes video frames to image files. + +-The pattern may contain the string "%d" or "%0@var{N}d", which ++The output filenames are specified by a pattern, which can be used to ++produce sequentially numbered series of files. ++The pattern may contain the string "%d" or "%0@var{N}d", this string + specifies the position of the characters representing a numbering in +-the filenames. If the form "%d0@var{N}d" is used, the string ++the filenames. If the form "%0@var{N}d" is used, the string + representing the number in each filename is 0-padded to @var{N} + digits. The literal character '%' can be specified in the pattern with + the string "%%". +@@ -46,28 +120,46 @@ + form @file{img%-1.jpg}, @file{img%-2.jpg}, ..., @file{img%-10.jpg}, + etc. + +-The following example shows how to use @file{ffmpeg} for creating a ++The following example shows how to use @command{ffmpeg} for creating a + sequence of files @file{img-001.jpeg}, @file{img-002.jpeg}, ..., + taking one image every second from the input video: + @example +-ffmpeg -i in.avi -r 1 -f image2 'img-%03d.jpeg' ++ffmpeg -i in.avi -vsync 1 -r 1 -f image2 'img-%03d.jpeg' + @end example + +-Note that with @file{ffmpeg}, if the format is not specified with the ++Note that with @command{ffmpeg}, if the format is not specified with the + @code{-f} option and the output filename specifies an image file + format, the image2 muxer is automatically selected, so the previous + command can be written as: + @example +-ffmpeg -i in.avi -r 1 'img-%03d.jpeg' ++ffmpeg -i in.avi -vsync 1 -r 1 'img-%03d.jpeg' + @end example + + Note also that the pattern must not necessarily contain "%d" or + "%0@var{N}d", for example to create a single image file + @file{img.jpeg} from the input video you can employ the command: + @example +-ffmpeg -i in.avi -f image2 -vframes 1 img.jpeg ++ffmpeg -i in.avi -f image2 -frames:v 1 img.jpeg + @end example + ++The image muxer supports the .Y.U.V image file format. This format is ++special in that that each image frame consists of three files, for ++each of the YUV420P components. To read or write this image file format, ++specify the name of the '.Y' file. The muxer will automatically open the ++'.U' and '.V' files as required. ++ ++@section mov ++ ++MOV / MP4 muxer ++ ++The muxer options are: ++ ++@table @option ++@item -moov_size @var{bytes} ++Reserves space for the moov atom at the beginning of the file instead of placing the ++moov atom at the end. If the space reserved is insufficient, muxing will fail. ++@end table ++ + @section mpegts + + MPEG transport stream muxer. +@@ -98,7 +190,7 @@ + @code{service_name} is "Service01". + + @example +-ffmpeg -i file.mpg -acodec copy -vcodec copy \ ++ffmpeg -i file.mpg -c copy \ + -mpegts_original_network_id 0x1122 \ + -mpegts_transport_stream_id 0x3344 \ + -mpegts_service_id 0x5566 \ +@@ -109,4 +201,120 @@ + -y out.ts + @end example + ++@section null ++ ++Null muxer. ++ ++This muxer does not generate any output file, it is mainly useful for ++testing or benchmarking purposes. ++ ++For example to benchmark decoding with @command{ffmpeg} you can use the ++command: ++@example ++ffmpeg -benchmark -i INPUT -f null out.null ++@end example ++ ++Note that the above command does not read or write the @file{out.null} ++file, but specifying the output file is required by the @command{ffmpeg} ++syntax. ++ ++Alternatively you can write the command as: ++@example ++ffmpeg -benchmark -i INPUT -f null - ++@end example ++ ++@section matroska ++ ++Matroska container muxer. ++ ++This muxer implements the matroska and webm container specs. ++ ++The recognized metadata settings in this muxer are: ++ ++@table @option ++ ++@item title=@var{title name} ++Name provided to a single track ++@end table ++ ++@table @option ++ ++@item language=@var{language name} ++Specifies the language of the track in the Matroska languages form ++@end table ++ ++@table @option ++ ++@item stereo_mode=@var{mode} ++Stereo 3D video layout of two views in a single video track ++@table @option ++@item mono ++video is not stereo ++@item left_right ++Both views are arranged side by side, Left-eye view is on the left ++@item bottom_top ++Both views are arranged in top-bottom orientation, Left-eye view is at bottom ++@item top_bottom ++Both views are arranged in top-bottom orientation, Left-eye view is on top ++@item checkerboard_rl ++Each view is arranged in a checkerboard interleaved pattern, Left-eye view being first ++@item checkerboard_lr ++Each view is arranged in a checkerboard interleaved pattern, Right-eye view being first ++@item row_interleaved_rl ++Each view is constituted by a row based interleaving, Right-eye view is first row ++@item row_interleaved_lr ++Each view is constituted by a row based interleaving, Left-eye view is first row ++@item col_interleaved_rl ++Both views are arranged in a column based interleaving manner, Right-eye view is first column ++@item col_interleaved_lr ++Both views are arranged in a column based interleaving manner, Left-eye view is first column ++@item anaglyph_cyan_red ++All frames are in anaglyph format viewable through red-cyan filters ++@item right_left ++Both views are arranged side by side, Right-eye view is on the left ++@item anaglyph_green_magenta ++All frames are in anaglyph format viewable through green-magenta filters ++@item block_lr ++Both eyes laced in one Block, Left-eye view is first ++@item block_rl ++Both eyes laced in one Block, Right-eye view is first ++@end table ++@end table ++ ++For example a 3D WebM clip can be created using the following command line: ++@example ++ffmpeg -i sample_left_right_clip.mpg -an -c:v libvpx -metadata stereo_mode=left_right -y stereo_clip.webm ++@end example ++ ++@section segment ++ ++Basic stream segmenter. ++ ++The segmenter muxer outputs streams to a number of separate files of nearly ++fixed duration. Output filename pattern can be set in a fashion similar to ++@ref{image2}. ++ ++Every segment starts with a video keyframe, if a video stream is present. ++The segment muxer works best with a single constant frame rate video. ++ ++Optionally it can generate a flat list of the created segments, one segment ++per line. ++ ++@table @option ++@item segment_format @var{format} ++Override the inner container format, by default it is guessed by the filename ++extension. ++@item segment_time @var{t} ++Set segment duration to @var{t} seconds. ++@item segment_list @var{name} ++Generate also a listfile named @var{name}. ++@item segment_list_size @var{size} ++Overwrite the listfile once it reaches @var{size} entries. ++@end table ++ ++@example ++ffmpeg -i in.mkv -c copy -map 0 -f segment -list out.list out%03d.nut ++@end example ++ ++ + @c man end MUXERS +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/optimization.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/optimization.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/optimization.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/optimization.txt 2012-05-14 14:08:53.188316917 +0200 +@@ -17,15 +17,15 @@ + As many functions tend to be a bit difficult to understand because + of optimizations, it can be hard to optimize them further, or write + architecture-specific versions. It is recommended to look at older +-revisions of the interesting files (for a web frontend try ViewVC at +-http://svn.ffmpeg.org/ffmpeg/trunk/). ++revisions of the interesting files (web frontends for the various FFmpeg ++branches are listed at http://ffmpeg.org/download.html). + Alternatively, look into the other architecture-specific versions in + the x86/, ppc/, alpha/ subdirectories. Even if you don't exactly + comprehend the instructions, it could help understanding the functions + and how they can be optimized. + + NOTE: If you still don't understand some function, ask at our mailing list!!! +-(http://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-devel) ++(http://lists.ffmpeg.org/mailman/listinfo/ffmpeg-devel) + + + When is an optimization justified? +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/outdevs.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/outdevs.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/outdevs.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/outdevs.texi 2012-05-14 14:08:53.189316937 +0200 +@@ -26,4 +26,48 @@ + + OSS (Open Sound System) output device. + ++@section sdl ++ ++SDL (Simple DirectMedia Layer) output device. ++ ++This output devices allows to show a video stream in an SDL ++window. Only one SDL window is allowed per application, so you can ++have only one instance of this output device in an application. ++ ++To enable this output device you need libsdl installed on your system ++when configuring your build. ++ ++For more information about SDL, check: ++@url{http://www.libsdl.org/} ++ ++@subsection Options ++ ++@table @option ++ ++@item window_title ++Set the SDL window title, if not specified default to the filename ++specified for the output device. ++ ++@item icon_title ++Set the name of the iconified SDL window, if not specified it is set ++to the same value of @var{window_title}. ++ ++@item window_size ++Set the SDL window size, can be a string of the form ++@var{width}x@var{height} or a video size abbreviation. ++If not specified it defaults to the size of the input video. ++@end table ++ ++@subsection Examples ++ ++The following command shows the @command{ffmpeg} output is an ++SDL window, forcing its size to the qcif format: ++@example ++ffmpeg -i INPUT -vcodec rawvideo -pix_fmt yuv420p -window_size qcif -f sdl "SDL output" ++@end example ++ ++@section sndio ++ ++sndio audio output device. ++ + @c man end OUTPUT DEVICES +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/platform.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/platform.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/platform.texi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/platform.texi 2012-05-14 14:08:53.191316977 +0200 +@@ -0,0 +1,390 @@ ++\input texinfo @c -*- texinfo -*- ++ ++@settitle Platform Specific information ++@titlepage ++@center @titlefont{Platform Specific information} ++@end titlepage ++ ++@top ++ ++@contents ++ ++@chapter Unix-like ++ ++Some parts of FFmpeg cannot be built with version 2.15 of the GNU ++assembler which is still provided by a few AMD64 distributions. To ++make sure your compiler really uses the required version of gas ++after a binutils upgrade, run: ++ ++@example ++$(gcc -print-prog-name=as) --version ++@end example ++ ++If not, then you should install a different compiler that has no ++hard-coded path to gas. In the worst case pass @code{--disable-asm} ++to configure. ++ ++@section BSD ++ ++BSD make will not build FFmpeg, you need to install and use GNU Make ++(@file{gmake}). ++ ++@section (Open)Solaris ++ ++GNU Make is required to build FFmpeg, so you have to invoke (@file{gmake}), ++standard Solaris Make will not work. When building with a non-c99 front-end ++(gcc, generic suncc) add either @code{--extra-libs=/usr/lib/values-xpg6.o} ++or @code{--extra-libs=/usr/lib/64/values-xpg6.o} to the configure options ++since the libc is not c99-compliant by default. The probes performed by ++configure may raise an exception leading to the death of configure itself ++due to a bug in the system shell. Simply invoke a different shell such as ++bash directly to work around this: ++ ++@example ++bash ./configure ++@end example ++ ++@anchor{Darwin} ++@section Darwin (Mac OS X, iPhone) ++ ++The toolchain provided with Xcode is sufficient to build the basic ++unacelerated code. ++ ++Mac OS X on PowerPC or ARM (iPhone) requires a preprocessor from ++@url{http://github.com/yuvi/gas-preprocessor} to build the optimized ++assembler functions. Just download the Perl script and put it somewhere ++in your PATH, FFmpeg's configure will pick it up automatically. ++ ++Mac OS X on amd64 and x86 requires @command{yasm} to build most of the ++optimized assembler functions. @uref{http://www.finkproject.org/, Fink}, ++@uref{http://www.gentoo.org/proj/en/gentoo-alt/prefix/bootstrap-macos.xml, Gentoo Prefix}, ++@uref{http://mxcl.github.com/homebrew/, Homebrew} ++or @uref{http://www.macports.org, MacPorts} can easily provide it. ++ ++ ++@chapter DOS ++ ++Using a cross-compiler is preferred for various reasons. ++@url{http://www.delorie.com/howto/djgpp/linux-x-djgpp.html} ++ ++ ++@chapter OS/2 ++ ++For information about compiling FFmpeg on OS/2 see ++@url{http://www.edm2.com/index.php/FFmpeg}. ++ ++ ++@chapter Windows ++ ++To get help and instructions for building FFmpeg under Windows, check out ++the FFmpeg Windows Help Forum at ++@url{http://ffmpeg.arrozcru.org/}. ++ ++@section Native Windows compilation ++ ++FFmpeg can be built to run natively on Windows using the MinGW tools. Install ++the latest versions of MSYS and MinGW from @url{http://www.mingw.org/}. ++You can find detailed installation instructions in the download ++section and the FAQ. ++ ++FFmpeg does not build out-of-the-box with the packages the automated MinGW ++installer provides. It also requires coreutils to be installed and many other ++packages updated to the latest version. The minimum version for some packages ++are listed below: ++ ++@itemize ++@item bash 3.1 ++@item msys-make 3.81-2 (note: not mingw32-make) ++@item w32api 3.13 ++@item mingw-runtime 3.15 ++@end itemize ++ ++FFmpeg automatically passes @code{-fno-common} to the compiler to work around ++a GCC bug (see @url{http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37216}). ++ ++Notes: ++ ++@itemize ++ ++@item Building natively using MSYS can be sped up by disabling implicit rules ++in the Makefile by calling @code{make -r} instead of plain @code{make}. This ++speed up is close to non-existent for normal one-off builds and is only ++noticeable when running make for a second time (for example in ++@code{make install}). ++ ++@item In order to compile FFplay, you must have the MinGW development library ++of @uref{http://www.libsdl.org/, SDL}. ++Edit the @file{bin/sdl-config} script so that it points to the correct prefix ++where SDL was installed. Verify that @file{sdl-config} can be launched from ++the MSYS command line. ++ ++@item By using @code{./configure --enable-shared} when configuring FFmpeg, ++you can build the FFmpeg libraries (e.g. libavutil, libavcodec, ++libavformat) as DLLs. ++ ++@end itemize ++ ++@section Microsoft Visual C++ compatibility ++ ++As stated in the FAQ, FFmpeg will not compile under MSVC++. However, if you ++want to use the libav* libraries in your own applications, you can still ++compile those applications using MSVC++. But the libav* libraries you link ++to @emph{must} be built with MinGW. However, you will not be able to debug ++inside the libav* libraries, since MSVC++ does not recognize the debug ++symbols generated by GCC. ++We strongly recommend you to move over from MSVC++ to MinGW tools. ++ ++This description of how to use the FFmpeg libraries with MSVC++ is based on ++Microsoft Visual C++ 2005 Express Edition. If you have a different version, ++you might have to modify the procedures slightly. ++ ++@subsection Using static libraries ++ ++Assuming you have just built and installed FFmpeg in @file{/usr/local}. ++ ++@enumerate ++ ++@item Create a new console application ("File / New / Project") and then ++select "Win32 Console Application". On the appropriate page of the ++Application Wizard, uncheck the "Precompiled headers" option. ++ ++@item Write the source code for your application, or, for testing, just ++copy the code from an existing sample application into the source file ++that MSVC++ has already created for you. For example, you can copy ++@file{libavformat/output-example.c} from the FFmpeg distribution. ++ ++@item Open the "Project / Properties" dialog box. In the "Configuration" ++combo box, select "All Configurations" so that the changes you make will ++affect both debug and release builds. In the tree view on the left hand ++side, select "C/C++ / General", then edit the "Additional Include ++Directories" setting to contain the path where the FFmpeg includes were ++installed (i.e. @file{c:\msys\1.0\local\include}). ++Do not add MinGW's include directory here, or the include files will ++conflict with MSVC's. ++ ++@item Still in the "Project / Properties" dialog box, select ++"Linker / General" from the tree view and edit the ++"Additional Library Directories" setting to contain the @file{lib} ++directory where FFmpeg was installed (i.e. @file{c:\msys\1.0\local\lib}), ++the directory where MinGW libs are installed (i.e. @file{c:\mingw\lib}), ++and the directory where MinGW's GCC libs are installed ++(i.e. @file{C:\mingw\lib\gcc\mingw32\4.2.1-sjlj}). Then select ++"Linker / Input" from the tree view, and add the files @file{libavformat.a}, ++@file{libavcodec.a}, @file{libavutil.a}, @file{libmingwex.a}, ++@file{libgcc.a}, and any other libraries you used (i.e. @file{libz.a}) ++to the end of "Additional Dependencies". ++ ++@item Now, select "C/C++ / Code Generation" from the tree view. Select ++"Debug" in the "Configuration" combo box. Make sure that "Runtime ++Library" is set to "Multi-threaded Debug DLL". Then, select "Release" in ++the "Configuration" combo box and make sure that "Runtime Library" is ++set to "Multi-threaded DLL". ++ ++@item Click "OK" to close the "Project / Properties" dialog box. ++ ++@item MSVC++ lacks some C99 header files that are fundamental for FFmpeg. ++Get msinttypes from @url{http://code.google.com/p/msinttypes/downloads/list} ++and install it in MSVC++'s include directory ++(i.e. @file{C:\Program Files\Microsoft Visual Studio 8\VC\include}). ++ ++@item MSVC++ also does not understand the @code{inline} keyword used by ++FFmpeg, so you must add this line before @code{#include}ing libav*: ++@example ++#define inline _inline ++@end example ++ ++@item Build your application, everything should work. ++ ++@end enumerate ++ ++@subsection Using shared libraries ++ ++This is how to create DLL and LIB files that are compatible with MSVC++: ++ ++@enumerate ++ ++@item Add a call to @file{vcvars32.bat} (which sets up the environment ++variables for the Visual C++ tools) as the first line of @file{msys.bat}. ++The standard location for @file{vcvars32.bat} is ++@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}, ++and the standard location for @file{msys.bat} is @file{C:\msys\1.0\msys.bat}. ++If this corresponds to your setup, add the following line as the first line ++of @file{msys.bat}: ++ ++@example ++call "C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat" ++@end example ++ ++Alternatively, you may start the @file{Visual Studio 2005 Command Prompt}, ++and run @file{c:\msys\1.0\msys.bat} from there. ++ ++@item Within the MSYS shell, run @code{lib.exe}. If you get a help message ++from @file{Microsoft (R) Library Manager}, this means your environment ++variables are set up correctly, the @file{Microsoft (R) Library Manager} ++is on the path and will be used by FFmpeg to create ++MSVC++-compatible import libraries. ++ ++@item Build FFmpeg with ++ ++@example ++./configure --enable-shared ++make ++make install ++@end example ++ ++Your install path (@file{/usr/local/} by default) should now have the ++necessary DLL and LIB files under the @file{bin} directory. ++ ++@end enumerate ++ ++Alternatively, build the libraries with a cross compiler, according to ++the instructions below in @ref{Cross compilation for Windows with Linux}. ++ ++To use those files with MSVC++, do the same as you would do with ++the static libraries, as described above. But in Step 4, ++you should only need to add the directory where the LIB files are installed ++(i.e. @file{c:\msys\usr\local\bin}). This is not a typo, the LIB files are ++installed in the @file{bin} directory. And instead of adding the static ++libraries (@file{libxxx.a} files) you should add the MSVC import libraries ++(@file{avcodec.lib}, @file{avformat.lib}, and ++@file{avutil.lib}). Note that you should not use the GCC import ++libraries (@file{libxxx.dll.a} files), as these will give you undefined ++reference errors. There should be no need for @file{libmingwex.a}, ++@file{libgcc.a}, and @file{wsock32.lib}, nor any other external library ++statically linked into the DLLs. ++ ++FFmpeg headers do not declare global data for Windows DLLs through the usual ++dllexport/dllimport interface. Such data will be exported properly while ++building, but to use them in your MSVC++ code you will have to edit the ++appropriate headers and mark the data as dllimport. For example, in ++libavutil/pixdesc.h you should have: ++@example ++extern __declspec(dllimport) const AVPixFmtDescriptor av_pix_fmt_descriptors[]; ++@end example ++ ++Note that using import libraries created by dlltool requires ++the linker optimization option to be set to ++"References: Keep Unreferenced Data (@code{/OPT:NOREF})", otherwise ++the resulting binaries will fail during runtime. This isn't ++required when using import libraries generated by lib.exe. ++This issue is reported upstream at ++@url{http://sourceware.org/bugzilla/show_bug.cgi?id=12633}. ++ ++To create import libraries that work with the @code{/OPT:REF} option ++(which is enabled by default in Release mode), follow these steps: ++ ++@enumerate ++ ++@item Open @file{Visual Studio 2005 Command Prompt}. ++ ++Alternatively, in a normal command line prompt, call @file{vcvars32.bat} ++which sets up the environment variables for the Visual C++ tools ++(the standard location for this file is ++@file{C:\Program Files\Microsoft Visual Studio 8\VC\bin\vcvars32.bat}). ++ ++@item Enter the @file{bin} directory where the created LIB and DLL files ++are stored. ++ ++@item Generate new import libraries with @file{lib.exe}: ++ ++@example ++lib /machine:i386 /def:..\lib\avcodec-53.def /out:avcodec.lib ++lib /machine:i386 /def:..\lib\avdevice-53.def /out:avdevice.lib ++lib /machine:i386 /def:..\lib\avfilter-2.def /out:avfilter.lib ++lib /machine:i386 /def:..\lib\avformat-53.def /out:avformat.lib ++lib /machine:i386 /def:..\lib\avutil-51.def /out:avutil.lib ++lib /machine:i386 /def:..\lib\swscale-2.def /out:swscale.lib ++@end example ++ ++@end enumerate ++ ++@anchor{Cross compilation for Windows with Linux} ++@section Cross compilation for Windows with Linux ++ ++You must use the MinGW cross compilation tools available at ++@url{http://www.mingw.org/}. ++ ++Then configure FFmpeg with the following options: ++@example ++./configure --target-os=mingw32 --cross-prefix=i386-mingw32msvc- ++@end example ++(you can change the cross-prefix according to the prefix chosen for the ++MinGW tools). ++ ++Then you can easily test FFmpeg with @uref{http://www.winehq.com/, Wine}. ++ ++@section Compilation under Cygwin ++ ++Please use Cygwin 1.7.x as the obsolete 1.5.x Cygwin versions lack ++llrint() in its C library. ++ ++Install your Cygwin with all the "Base" packages, plus the ++following "Devel" ones: ++@example ++binutils, gcc4-core, make, git, mingw-runtime, texi2html ++@end example ++ ++And the following "Utils" one: ++@example ++diffutils ++@end example ++ ++Then run ++ ++@example ++./configure ++@end example ++ ++to make a static build. ++ ++The current @code{gcc4-core} package is buggy and needs this flag to build ++shared libraries: ++ ++@example ++./configure --enable-shared --disable-static --extra-cflags=-fno-reorder-functions ++@end example ++ ++If you want to build FFmpeg with additional libraries, download Cygwin ++"Devel" packages for Ogg and Vorbis from any Cygwin packages repository: ++@example ++libogg-devel, libvorbis-devel ++@end example ++ ++These library packages are only available from ++@uref{http://sourceware.org/cygwinports/, Cygwin Ports}: ++ ++@example ++yasm, libSDL-devel, libdirac-devel, libfaac-devel, libaacplus-devel, libgsm-devel, ++libmp3lame-devel, libschroedinger1.0-devel, speex-devel, libtheora-devel, ++libxvidcore-devel ++@end example ++ ++The recommendation for libnut and x264 is to build them from source by ++yourself, as they evolve too quickly for Cygwin Ports to be up to date. ++ ++Cygwin 1.7.x has IPv6 support. You can add IPv6 to Cygwin 1.5.x by means ++of the @code{libgetaddrinfo-devel} package, available at Cygwin Ports. ++ ++@section Crosscompilation for Windows under Cygwin ++ ++With Cygwin you can create Windows binaries that do not need the cygwin1.dll. ++ ++Just install your Cygwin as explained before, plus these additional ++"Devel" packages: ++@example ++gcc-mingw-core, mingw-runtime, mingw-zlib ++@end example ++ ++and add some special flags to your configure invocation. ++ ++For a static build run ++@example ++./configure --target-os=mingw32 --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin ++@end example ++ ++and for a build with shared libraries ++@example ++./configure --target-os=mingw32 --enable-shared --disable-static --extra-cflags=-mno-cygwin --extra-libs=-mno-cygwin ++@end example ++ ++@bye +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/protocols.texi xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/protocols.texi +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/protocols.texi 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/protocols.texi 2012-05-14 14:08:53.192316997 +0200 +@@ -19,6 +19,22 @@ + + A description of the currently available protocols follows. + ++@section applehttp ++ ++Read Apple HTTP Live Streaming compliant segmented stream as ++a uniform one. The M3U8 playlists describing the segments can be ++remote HTTP resources or local files, accessed using the standard ++file protocol. ++HTTP is default, specific protocol can be declared by specifying ++"+@var{proto}" after the applehttp URI scheme name, where @var{proto} ++is either "file" or "http". ++ ++@example ++applehttp://host/path/to/remote/resource.m3u8 ++applehttp+http://host/path/to/remote/resource.m3u8 ++applehttp+file://path/to/local/resource.m3u8 ++@end example ++ + @section concat + + Physical concatenation protocol. +@@ -36,7 +52,7 @@ + protocol. + + For example to read a sequence of files @file{split1.mpeg}, +-@file{split2.mpeg}, @file{split3.mpeg} with @file{ffplay} use the ++@file{split2.mpeg}, @file{split3.mpeg} with @command{ffplay} use the + command: + @example + ffplay concat:split1.mpeg\|split2.mpeg\|split3.mpeg +@@ -51,7 +67,7 @@ + + Allow to read from or read to a file. + +-For example to read from a file @file{input.mpeg} with @file{ffmpeg} ++For example to read from a file @file{input.mpeg} with @command{ffmpeg} + use the command: + @example + ffmpeg -i file:input.mpeg output.mpeg +@@ -118,14 +134,14 @@ + is not specified, by default the stdout file descriptor will be used + for writing, stdin for reading. + +-For example to read from stdin with @file{ffmpeg}: ++For example to read from stdin with @command{ffmpeg}: + @example + cat test.wav | ffmpeg -i pipe:0 + # ...this is the same as... + cat test.wav | ffmpeg -i pipe: + @end example + +-For writing to stdout with @file{ffmpeg}: ++For writing to stdout with @command{ffmpeg}: + @example + ffmpeg -i test.wav -f avi pipe:1 | cat > test.avi + # ...this is the same as... +@@ -139,8 +155,8 @@ + + Real-Time Messaging Protocol. + +-The Real-Time Messaging Protocol (RTMP) is used for streaming multime†+-dia content across a TCP/IP network. ++The Real-Time Messaging Protocol (RTMP) is used for streaming multimedia ++content across a TCP/IP network. + + The required syntax is: + @example +@@ -167,7 +183,7 @@ + + @end table + +-For example to read with @file{ffplay} a multimedia resource named ++For example to read with @command{ffplay} a multimedia resource named + "sample" from the application "vod" from an RTMP server "myserver": + @example + ffplay rtmp://myserver/vod/sample +@@ -179,7 +195,7 @@ + librtmp. + + Requires the presence of the librtmp headers and library during +-configuration. You need to explicitely configure the build with ++configuration. You need to explicitly configure the build with + "--enable-librtmp". If enabled this will replace the native RTMP + protocol. + +@@ -203,12 +219,12 @@ + See the librtmp manual page (man 3 librtmp) for more information. + + For example, to stream a file in real-time to an RTMP server using +-@file{ffmpeg}: ++@command{ffmpeg}: + @example + ffmpeg -re -i myfile -f flv rtmp://myserver/live/mystream + @end example + +-To play the same stream using @file{ffplay}: ++To play the same stream using @command{ffplay}: + @example + ffplay "rtmp://myserver/live/mystream live=1" + @end example +@@ -226,16 +242,19 @@ + + The muxer can be used to send a stream using RTSP ANNOUNCE to a server + supporting it (currently Darwin Streaming Server and Mischa Spiegelmock's +-RTSP server, @url{http://github.com/revmischa/rtsp-server}). ++@uref{http://github.com/revmischa/rtsp-server, RTSP server}). + + The required syntax for a RTSP url is: + @example +-rtsp://@var{hostname}[:@var{port}]/@var{path}[?@var{options}] ++rtsp://@var{hostname}[:@var{port}]/@var{path} + @end example + +-@var{options} is a @code{&}-separated list. The following options ++The following options (set on the @command{ffmpeg}/@command{ffplay} command ++line, or set in code via @code{AVOption}s or in @code{avformat_open_input}), + are supported: + ++Flags for @code{rtsp_transport}: ++ + @table @option + + @item udp +@@ -245,27 +264,31 @@ + Use TCP (interleaving within the RTSP control channel) as lower + transport protocol. + +-@item multicast ++@item udp_multicast + Use UDP multicast as lower transport protocol. + + @item http + Use HTTP tunneling as lower transport protocol, which is useful for + passing proxies. +- +-@item filter_src +-Accept packets only from negotiated peer address and port. + @end table + + Multiple lower transport protocols may be specified, in that case they are + tried one at a time (if the setup of one fails, the next one is tried). + For the muxer, only the @code{tcp} and @code{udp} options are supported. + ++Flags for @code{rtsp_flags}: ++ ++@table @option ++@item filter_src ++Accept packets only from negotiated peer address and port. ++@end table ++ + When receiving data over UDP, the demuxer tries to reorder received packets + (since they may arrive out of order, or packets may get lost totally). In + order for this to be enabled, a maximum delay must be specified in the + @code{max_delay} field of AVFormatContext. + +-When watching multi-bitrate Real-RTSP streams with @file{ffplay}, the ++When watching multi-bitrate Real-RTSP streams with @command{ffplay}, the + streams to display can be chosen with @code{-vst} @var{n} and + @code{-ast} @var{n} for video and audio respectively, and can be switched + on the fly by pressing @code{v} and @code{a}. +@@ -275,13 +298,13 @@ + To watch a stream over UDP, with a max reordering delay of 0.5 seconds: + + @example +-ffplay -max_delay 500000 rtsp://server/video.mp4?udp ++ffplay -max_delay 500000 -rtsp_transport udp rtsp://server/video.mp4 + @end example + + To watch a stream tunneled over HTTP: + + @example +-ffplay rtsp://server/video.mp4?http ++ffplay -rtsp_transport http rtsp://server/video.mp4 + @end example + + To send a stream in realtime to a RTSP server, for others to watch: +@@ -342,13 +365,13 @@ + ffmpeg -re -i @var{input} -f sap sap://224.0.0.255?same_port=1 + @end example + +-Similarly, for watching in ffplay: ++Similarly, for watching in @command{ffplay}: + + @example + ffmpeg -re -i @var{input} -f sap sap://224.0.0.255 + @end example + +-And for watching in ffplay, over IPv6: ++And for watching in @command{ffplay}, over IPv6: + + @example + ffmpeg -re -i @var{input} -f sap sap://[ff0e::1:2:3:4] +@@ -386,6 +409,23 @@ + + Trasmission Control Protocol. + ++The required syntax for a TCP url is: ++@example ++tcp://@var{hostname}:@var{port}[?@var{options}] ++@end example ++ ++@table @option ++ ++@item listen ++Listen for an incoming connection ++ ++@example ++ffmpeg -i @var{input} -f @var{format} tcp://@var{hostname}:@var{port}?listen ++ffplay tcp://@var{hostname}:@var{port} ++@end example ++ ++@end table ++ + @section udp + + User Datagram Protocol. +@@ -406,6 +446,11 @@ + @item localport=@var{port} + override the local UDP port to bind with + ++@item localaddr=@var{addr} ++Choose the local IP address. This is useful e.g. if sending multicast ++and the host has multiple interfaces, where the user can choose ++which interface to send on by specifying the IP address of that interface. ++ + @item pkt_size=@var{size} + set the size in bytes of UDP packets + +@@ -417,9 +462,9 @@ + + @item connect=@var{1|0} + Initialize the UDP socket with @code{connect()}. In this case, the +-destination address can't be changed with udp_set_remote_url later. ++destination address can't be changed with ff_udp_set_remote_url later. + If the destination address isn't known at the start, this option can +-be specified in udp_set_remote_url, too. ++be specified in ff_udp_set_remote_url, too. + This allows finding out the source address for the packets with getsockname, + and makes writes return with AVERROR(ECONNREFUSED) if "destination + unreachable" is received. +@@ -427,7 +472,7 @@ + the specified peer address/port. + @end table + +-Some usage examples of the udp protocol with @file{ffmpeg} follow. ++Some usage examples of the udp protocol with @command{ffmpeg} follow. + + To stream over UDP to a remote endpoint: + @example +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/RELEASE_NOTES xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/RELEASE_NOTES +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/RELEASE_NOTES 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/RELEASE_NOTES 2012-05-14 14:08:53.128315709 +0200 +@@ -0,0 +1,49 @@ ++Release Notes ++============= ++ ++* 0.10 "Freedom" January, 2012 ++ ++ ++General notes ++------------- ++This release is binary compatible with 0.8 and 0.9. ++ ++See the Changelog file for a list of significant changes. Note, there ++are many more new features and bugfixes than whats listed there. ++ ++Bugreports against FFmpeg git master or the most recent FFmpeg release are ++accepted. If you are experiencing issues with any formally released version of ++FFmpeg, please try git master to check if the issue still exists. If it does, ++make your report against the development code following the usual bug reporting ++guidelines. ++ ++ ++API changes ++----------- ++ ++A number of additional APIs have been introduced and some existing ++functions have been deprecated and are scheduled for removal in the next ++release. Significant API changes include: ++ ++* new audio decoding API which decodes from an AVPacket to an AVFrame and ++is able to use AVCodecContext.get_buffer() in the similar way as video decoding. ++ ++* new audio encoding API which encodes from an AVFrame to an AVPacket, thus ++allowing it to properly output timing information and side data. ++ ++Please see the git history and the file doc/APIchanges for details. ++ ++ ++Other notable changes ++--------------------- ++ ++Libavcodec and libavformat built as shared libraries now hide non-public ++symbols. This will break applications using those symbols. Possible solutions ++are, in order of preference: ++1) Try finding a way of accomplishing the same with public API. ++2) If there is no corresponding public API, but you think there should be, ++post a request on the developer mailing list or IRC channel. ++3) Finally if your program needs access to FFmpeg / libavcodec / libavformat ++internals for some special reason then the best solution is to link statically. ++ ++Please see the Changelog file and git history for a more detailed list of changes. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/soc.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/soc.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/soc.txt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/soc.txt 2012-05-14 14:08:53.193317017 +0200 +@@ -9,16 +9,16 @@ + The Goal: + Our goal in respect to soc is and must be of course exactly one thing and + that is to improve FFmpeg, to reach this goal, code must +-* conform to the svn policy and patch submission guidelines ++* conform to the development policy and patch submission guidelines + * must improve FFmpeg somehow (faster, smaller, "better", + more codecs supported, fewer bugs, cleaner, ...) + + for mentors and other developers to help students to reach that goal it is + essential that changes to their codebase are publicly visible, clean and + easy reviewable that again leads us to: +-* use of a revision control system like svn ++* use of a revision control system like git + * separation of cosmetic from non-cosmetic changes (this is almost entirely +- ignored by mentors and students in soc 2006 which might lead to a suprise ++ ignored by mentors and students in soc 2006 which might lead to a surprise + when the code will be reviewed at the end before a possible inclusion in + FFmpeg, individual changes were generally not reviewable due to cosmetics). + * frequent commits, so that comments can be provided early +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/swresample.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/swresample.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/swresample.txt 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/swresample.txt 2012-05-14 14:08:53.193317017 +0200 +@@ -0,0 +1,46 @@ ++ The official guide to swresample for confused developers. ++ ========================================================= ++ ++Current (simplified) Architecture: ++--------------------------------- ++ Input ++ v ++ __________________/|\___________ ++ / | \ ++ / input sample format convert v ++ / | ___________/ ++ | |/ ++ | v ++ | ___________/|\___________ _____________ ++ | / | \ | | ++ | Rematrix | resample <---->| Buffers | ++ | \___________ | ___________/ |_____________| ++ v \|/ ++Special Converter v ++ v ___________/|\___________ _____________ ++ | / | \ | | ++ | Rematrix | resample <---->| Buffers | ++ | \___________ | ___________/ |_____________| ++ | \|/ ++ | v ++ | |\___________ ++ \ | \ ++ \ output sample format convert v ++ \_________________ | ___________/ ++ \|/ ++ v ++ Output ++ ++Planar/Packed convertion is done when needed during sample format convertion ++Every step can be skiped without memcpy when its not needed. ++Either Resampling and Rematrixing can be performed first depending on which ++way its faster. ++The Buffers are needed for resampling due to resamplng being a process that ++requires future and past data, it thus also introduces inevitably a delay when ++used. ++Internally 32bit float and 16bit int is supported currently, other formats can ++easily be added ++Externally all sample formats in packed and planar configuration are supported ++Its also trivial to add special converters for common cases ++If only sample format and or packed/planar convertion is needed it ++is performed from input to output directly in a single pass with no intermediates. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/t2h.init xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/t2h.init +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/t2h.init 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/t2h.init 2012-05-14 14:08:53.194317038 +0200 +@@ -1,15 +1,161 @@ + # no horiz rules between sections +-$end_section = \&FFMPEG_end_section; +-sub FFMPEG_end_section($$) ++$end_section = \&FFmpeg_end_section; ++sub FFmpeg_end_section($$) + { + } + +-$print_page_foot = \&FFMPEG_print_page_foot; +-sub FFMPEG_print_page_foot($$) ++$EXTRA_HEAD = ++' ++ ++'; ++ ++$CSS_LINES = < ++ ++ ++EOT ++ ++my $FFMPEG_NAVBAR = $ENV{"FFMPEG_NAVBAR"} || ''; ++ ++$AFTER_BODY_OPEN = ++'
' . ++"\n$FFMPEG_NAVBAR\n" . ++'
'; ++ ++$PRE_BODY_CLOSE = '
'; ++ ++$SMALL_RULE = ''; ++$BODYTEXT = ''; ++ ++$print_page_foot = \&FFmpeg_print_page_foot; ++sub FFmpeg_print_page_foot($$) + { + my $fh = shift; +- print $fh "$SMALL_RULE\n"; ++ print $fh '\n"; ++} ++ ++$float = \&FFmpeg_float; ++ ++sub FFmpeg_float($$$$) ++{ ++ my $text = shift; ++ my $float = shift; ++ my $caption = shift; ++ my $shortcaption = shift; ++ ++ my $label = ''; ++ if (exists($float->{'id'})) ++ { ++ $label = &$anchor($float->{'id'}); ++ } ++ my $class = ''; ++ my $subject = ''; ++ ++ if ($caption =~ /NOTE/) ++ { ++ $class = "note"; ++ } ++ elsif ($caption =~ /IMPORTANT/) ++ { ++ $class = "important"; ++ } ++ ++ return '
' . "$label\n" . $text . '
'; ++} ++ ++$print_page_head = \&FFmpeg_print_page_head; ++sub FFmpeg_print_page_head($$) ++{ ++ my $fh = shift; ++ my $longtitle = "$Texi2HTML::THISDOC{'title_no_texi'}"; ++ $longtitle .= ": $Texi2HTML::NO_TEXI{'This'}" if exists $Texi2HTML::NO_TEXI{'This'}; ++ my $description = $DOCUMENT_DESCRIPTION; ++ $description = $longtitle if (!defined($description)); ++ $description = "" if ++ ($description ne ''); ++ $description = $Texi2HTML::THISDOC{'documentdescription'} if (defined($Texi2HTML::THISDOC{'documentdescription'})); ++ my $encoding = ''; ++ $encoding = "" if (defined($ENCODING) and ($ENCODING ne '')); ++ $longtitle =~ s/Documentation.*//g; ++ $longtitle = "FFmpeg documentation : " . $longtitle; ++ ++ print $fh < ++$Texi2HTML::THISDOC{'copying'} ++ ++ ++$longtitle ++ ++$description ++ ++ ++ ++ ++$encoding ++$CSS_LINES ++$EXTRA_HEAD ++ ++ ++ ++$AFTER_BODY_OPEN ++EOT + } + + # no navigation elements +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/texi2pod.pl xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/texi2pod.pl +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/texi2pod.pl 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/texi2pod.pl 2012-05-14 14:08:53.195317059 +0200 +@@ -231,10 +231,12 @@ + + # Single line command handlers. + +- /^\@(?:section|unnumbered|unnumberedsec|center)\s+(.+)$/ ++ /^\@(?:section|unnumbered|unnumberedsec|center|heading)\s+(.+)$/ + and $_ = "\n=head2 $1\n"; +- /^\@subsection\s+(.+)$/ ++ /^\@(?:subsection|subheading)\s+(.+)$/ + and $_ = "\n=head3 $1\n"; ++ /^\@(?:subsubsection|subsubheading)\s+(.+)$/ ++ and $_ = "\n=head4 $1\n"; + + # Block command handlers: + /^\@itemize\s*(\@[a-z]+|\*|-)?/ and do { +@@ -350,6 +352,7 @@ + s/\(?\@xref\{(?:[^\}]*)\}(?:[^.<]|(?:<[^<>]*>))*\.\)?//g; + s/\s+\(\@pxref\{(?:[^\}]*)\}\)//g; + s/;\s+\@pxref\{(?:[^\}]*)\}//g; ++ s/\@ref\{([^\}]*)\}/$1/g; + s/\@noindent\s*//g; + s/\@refill//g; + s/\@gol//g; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/doc/TODO xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/TODO +--- xbmc-pvr-11.0.1/lib/ffmpeg/doc/TODO 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/doc/TODO 1970-01-01 01:00:00.000000000 +0100 +@@ -1,82 +0,0 @@ +-ffmpeg TODO list: +----------------- +- +-Fabrice's TODO list: (unordered) +-------------------- +-Short term: +- +-- use AVFMTCTX_DISCARD_PKT in ffplay so that DV has a chance to work +-- add RTSP regression test (both client and server) +-- make ffserver allocate AVFormatContext +-- clean up (incompatible change, for 0.5.0): +- * AVStream -> AVComponent +- * AVFormatContext -> AVInputStream/AVOutputStream +- * suppress rate_emu from AVCodecContext +-- add new float/integer audio filterting and conversion : suppress +- CODEC_ID_PCM_xxc and use CODEC_ID_RAWAUDIO. +-- fix telecine and frame rate conversion +- +-Long term (ask me if you want to help): +- +-- commit new imgconvert API and new PIX_FMT_xxx alpha formats +-- commit new LGPL'ed float and integer-only AC3 decoder +-- add WMA integer-only decoder +-- add new MPEG4-AAC audio decoder (both integer-only and float version) +- +-Michael's TODO list: (unordered) (if anyone wanna help with sth, just ask) +-------------------- +-- optimize H264 CABAC +-- more optimizations +-- simper rate control +- +-Philip'a TODO list: (alphabetically ordered) (please help) +------------------- +-- Add a multi-ffm filetype so that feeds can be recorded into multiple files rather +- than one big file. +-- Authenticated users support -- where the authentication is in the URL +-- Change ASF files so that the embedded timestamp in the frames is right rather +- than being an offset from the start of the stream +-- Make ffm files more resilient to changes in the codec structures so that you +- can play old ffm files. +- +-Baptiste's TODO list: +------------------ +-- mov edit list support (AVEditList) +-- YUV 10 bit per component support "2vuy" +-- mxf muxer +-- mpeg2 non linear quantizer +- +-unassigned TODO: (unordered) +---------------- +-- use AVFrame for audio codecs too +-- rework aviobuf.c buffering strategy and fix url_fskip +-- generate optimal huffman tables for mjpeg encoding +-- fix ffserver regression tests +-- support xvids motion estimation +-- support x264s motion estimation +-- support x264s rate control +-- SNOW: non translational motion compensation +-- SNOW: more optimal quantization +-- SNOW: 4x4 block support +-- SNOW: 1/8 pel motion compensation support +-- SNOW: iterative motion estimation based on subsampled images +-- SNOW: try B frames and MCTF and see how their PSNR/bitrate/complexity behaves +-- SNOW: try to use the wavelet transformed MC-ed reference frame as context for the entropy coder +-- SNOW: think about/analyize how to make snow use multiple cpus/threads +-- SNOW: finish spec +-- FLAC: lossy encoding (viterbi and naive scalar quantization) +-- libavfilter +-- JPEG2000 decoder & encoder +-- MPEG4 GMC encoding support +-- macroblock based pixel format (better cache locality, somewhat complex, one paper claimed it faster for high res) +-- regression tests for codecs which do not have an encoder (I+P-frame bitstream in svn) +-- add support for using mplayers video filters to ffmpeg +-- H264 encoder +-- per MB ratecontrol (so VCD and such do work better) +-- write a script which iteratively changes all functions between always_inline and noinline and benchmarks the result to find the best set of inlined functions +-- convert all the non SIMD asm into small asm vs. C testcases and submit them to the gcc devels so they can improve gcc +-- generic audio mixing API +-- extract PES packetizer from PS muxer and use it for new TS muxer +-- implement automatic AVBistreamFilter activation +-- make cabac encoder use bytestream (see http://trac.videolan.org/x264/changeset/?format=diff&new=651) +-- merge imdct and windowing, the current code does considerable amounts of redundant work +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/Doxyfile xbmc-pvr-11.0.1.patch/lib/ffmpeg/Doxyfile +--- xbmc-pvr-11.0.1/lib/ffmpeg/Doxyfile 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/Doxyfile 2012-05-14 14:08:53.089314924 +0200 +@@ -1,4 +1,4 @@ +-# Doxyfile 1.5.6 ++# Doxyfile 1.7.1 + + # This file describes the settings to be used by the documentation system + # doxygen (www.doxygen.org) for a project +@@ -31,7 +31,13 @@ + # This could be handy for archiving the generated documentation or + # if some version control system is used. + +-PROJECT_NUMBER = ++PROJECT_NUMBER = 0.10.2 ++ ++# With the PROJECT_LOGO tag one can specify an logo or icon that is included ++# in the documentation. The maximum height of the logo should not exceed 55 ++# pixels and the maximum width should not exceed 200 pixels. Doxygen will ++# copy the logo to the output directory. ++PROJECT_LOGO = + + # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) + # base path where the generated documentation will be put. +@@ -54,11 +60,11 @@ + # information to generate all constant output in the proper language. + # The default language is English, other supported languages are: + # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +-# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, +-# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), +-# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, +-# Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, Swedish, +-# and Ukrainian. ++# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, ++# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English ++# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, ++# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, ++# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + + OUTPUT_LANGUAGE = English + +@@ -155,13 +161,6 @@ + + MULTILINE_CPP_IS_BRIEF = NO + +-# If the DETAILS_AT_TOP tag is set to YES then Doxygen +-# will output the detailed description near the top, like JavaDoc. +-# If set to NO, the detailed description appears after the member +-# documentation. +- +-DETAILS_AT_TOP = NO +- + # If the INHERIT_DOCS tag is set to YES (the default) then an undocumented + # member inherits the documentation from any documented member that it + # re-implements. +@@ -214,6 +213,18 @@ + + OPTIMIZE_OUTPUT_VHDL = NO + ++# Doxygen selects the parser to use depending on the extension of the files it ++# parses. With this tag you can assign which parser to use for a given extension. ++# Doxygen has a built-in mapping, but you can override or extend it using this ++# tag. The format is ext=language, where ext is a file extension, and language ++# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C, ++# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make ++# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C ++# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions ++# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen. ++ ++EXTENSION_MAPPING = ++ + # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want + # to include (a tag file for) the STL sources as input, then you should + # set this tag to YES in order to let doxygen match functions declarations and +@@ -268,6 +279,22 @@ + + TYPEDEF_HIDES_STRUCT = NO + ++# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to ++# determine which symbols to keep in memory and which to flush to disk. ++# When the cache is full, less often used symbols will be written to disk. ++# For small to medium size projects (<1000 input files) the default value is ++# probably good enough. For larger projects a too small cache size can cause ++# doxygen to be busy swapping symbols to and from disk most of the time ++# causing a significant performance penality. ++# If the system has enough physical memory increasing the cache will improve the ++# performance by keeping more symbols in memory. Note that the value works on ++# a logarithmic scale so increasing the size by one will rougly double the ++# memory usage. The cache size is given by this formula: ++# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, ++# corresponding to a cache size of 2^16 = 65536 symbols ++ ++SYMBOL_CACHE_SIZE = 0 ++ + #--------------------------------------------------------------------------- + # Build related configuration options + #--------------------------------------------------------------------------- +@@ -366,6 +393,12 @@ + + SHOW_INCLUDE_FILES = YES + ++# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen ++# will list include files with double quotes in the documentation ++# rather than with sharp brackets. ++ ++FORCE_LOCAL_INCLUDES = NO ++ + # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] + # is inserted in the documentation for inline members. + +@@ -385,6 +418,16 @@ + + SORT_BRIEF_DOCS = NO + ++# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen ++# will sort the (brief and detailed) documentation of class members so that ++# constructors and destructors are listed first. If set to NO (the default) ++# the constructors will appear in the respective orders defined by ++# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. ++# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO ++# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. ++ ++SORT_MEMBERS_CTORS_1ST = NO ++ + # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the + # hierarchy of group names into alphabetical order. If set to NO (the default) + # the group names will appear in their defined order. +@@ -459,7 +502,8 @@ + SHOW_FILES = YES + + # Set the SHOW_NAMESPACES tag to NO to disable the generation of the +-# Namespaces page. This will remove the Namespaces entry from the Quick Index ++# Namespaces page. ++# This will remove the Namespaces entry from the Quick Index + # and from the Folder Tree View (if specified). The default is YES. + + SHOW_NAMESPACES = YES +@@ -474,6 +518,15 @@ + + FILE_VERSION_FILTER = + ++# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed ++# by doxygen. The layout file controls the global structure of the generated ++# output files in an output format independent way. The create the layout file ++# that represents doxygen's defaults, run doxygen with the -l option. ++# You can optionally specify a file name after the option, if omitted ++# DoxygenLayout.xml will be used as the name of the layout file. ++ ++LAYOUT_FILE = ++ + #--------------------------------------------------------------------------- + # configuration options related to warning and progress messages + #--------------------------------------------------------------------------- +@@ -577,7 +630,8 @@ + # against the file with absolute path, so to exclude all test directories + # for example use the pattern */test/* + +-EXCLUDE_PATTERNS = *.svn *.git *.d ++EXCLUDE_PATTERNS = *.git \ ++ *.d + + # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names + # (namespaces, classes, functions, etc.) that should be excluded from the +@@ -591,14 +645,15 @@ + # directories that contain example code fragments that are included (see + # the \include command). + +-EXAMPLE_PATH = ++EXAMPLE_PATH = libavcodec/ \ ++ libavformat/ + + # If the value of the EXAMPLE_PATH tag contains directories, you can use the + # EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp + # and *.h) to filter out the source-files in the directories. If left + # blank all files are included. + +-EXAMPLE_PATTERNS = ++EXAMPLE_PATTERNS = *-example.c + + # If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be + # searched for input files to be used with the \include or \dontinclude +@@ -618,14 +673,17 @@ + # by executing (via popen()) the command , where + # is the value of the INPUT_FILTER tag, and is the name of an + # input file. Doxygen will then use the output that the filter program writes +-# to standard output. If FILTER_PATTERNS is specified, this tag will be ++# to standard output. ++# If FILTER_PATTERNS is specified, this tag will be + # ignored. + + INPUT_FILTER = + + # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +-# basis. Doxygen will compare the file name with each pattern and apply the +-# filter if there is a match. The filters are a list of the form: ++# basis. ++# Doxygen will compare the file name with each pattern and apply the ++# filter if there is a match. ++# The filters are a list of the form: + # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further + # info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER + # is applied to all files. +@@ -675,7 +733,8 @@ + # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) + # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from + # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +-# link to the source code. Otherwise they will link to the documentstion. ++# link to the source code. ++# Otherwise they will link to the documentation. + + REFERENCES_LINK_SOURCE = YES + +@@ -707,7 +766,7 @@ + # the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns + # in which this list will be split (can be a number in the range [1..20]) + +-COLS_IN_ALPHA_INDEX = 5 ++COLS_IN_ALPHA_INDEX = 2 + + # In case all classes in a project start with a common prefix, all + # classes will be put under the same header in the alphabetical index. +@@ -741,13 +800,13 @@ + # each generated HTML page. If it is left blank doxygen will generate a + # standard header. + +-HTML_HEADER = ++HTML_HEADER = doc/doxy/header.html + + # The HTML_FOOTER tag can be used to specify a personal HTML footer for + # each generated HTML page. If it is left blank doxygen will generate a + # standard footer. + +-HTML_FOOTER = ++HTML_FOOTER = doc/doxy/footer.html + + # The HTML_STYLESHEET tag can be used to specify a user-defined cascading + # style sheet that is used by each HTML page. It can be used to +@@ -756,7 +815,38 @@ + # the style sheet file to the HTML output directory, so don't put your own + # stylesheet in the HTML output directory as well, or it will be erased! + +-HTML_STYLESHEET = ++HTML_STYLESHEET = doc/doxy/doxy_stylesheet.css ++ ++# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. ++# Doxygen will adjust the colors in the stylesheet and background images ++# according to this color. Hue is specified as an angle on a colorwheel, ++# see http://en.wikipedia.org/wiki/Hue for more information. ++# For instance the value 0 represents red, 60 is yellow, 120 is green, ++# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. ++# The allowed range is 0 to 359. ++ ++HTML_COLORSTYLE_HUE = 120 ++ ++# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of ++# the colors in the HTML output. For a value of 0 the output will use ++# grayscales only. A value of 255 will produce the most vivid colors. ++ ++HTML_COLORSTYLE_SAT = 100 ++ ++# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to ++# the luminance component of the colors in the HTML output. Values below ++# 100 gradually make the output lighter, whereas values above 100 make ++# the output darker. The value divided by 100 is the actual gamma applied, ++# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, ++# and 100 does not change the gamma. ++ ++HTML_COLORSTYLE_GAMMA = 80 ++ ++# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML ++# page will contain the date and time when the page was generated. Setting ++# this to NO can help when comparing the output of multiple runs. ++ ++HTML_TIMESTAMP = YES + + # If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, + # files or namespaces will be aligned in HTML using tables. If set to +@@ -764,21 +854,24 @@ + + HTML_ALIGN_MEMBERS = YES + +-# If the GENERATE_HTMLHELP tag is set to YES, additional index files +-# will be generated that can be used as input for tools like the +-# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +-# of the generated HTML documentation. ++# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML ++# documentation will contain sections that can be hidden and shown after the ++# page has loaded. For this to work a browser that supports ++# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox ++# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +-GENERATE_HTMLHELP = NO ++HTML_DYNAMIC_SECTIONS = NO + + # If the GENERATE_DOCSET tag is set to YES, additional index files + # will be generated that can be used as input for Apple's Xcode 3 +-# integrated development environment, introduced with OSX 10.5 (Leopard). ++# integrated development environment, introduced with OS X 10.5 (Leopard). + # To create a documentation set, doxygen will generate a Makefile in the + # HTML output directory. Running make will produce the docset in that + # directory and running "make install" will install the docset in + # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find + # it at startup. ++# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html ++# for more information. + + GENERATE_DOCSET = NO + +@@ -796,13 +889,22 @@ + + DOCSET_BUNDLE_ID = org.doxygen.Project + +-# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +-# documentation will contain sections that can be hidden and shown after the +-# page has loaded. For this to work a browser that supports +-# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +-# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). ++# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify ++# the documentation publisher. This should be a reverse domain-name style ++# string, e.g. com.mycompany.MyDocSet.documentation. + +-HTML_DYNAMIC_SECTIONS = NO ++DOCSET_PUBLISHER_ID = org.doxygen.Publisher ++ ++# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. ++ ++DOCSET_PUBLISHER_NAME = Publisher ++ ++# If the GENERATE_HTMLHELP tag is set to YES, additional index files ++# will be generated that can be used as input for tools like the ++# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) ++# of the generated HTML documentation. ++ ++GENERATE_HTMLHELP = NO + + # If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can + # be used to specify the file name of the resulting .chm file. You +@@ -841,6 +943,76 @@ + + TOC_EXPAND = NO + ++# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and ++# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated ++# that can be used as input for Qt's qhelpgenerator to generate a ++# Qt Compressed Help (.qch) of the generated HTML documentation. ++ ++GENERATE_QHP = NO ++ ++# If the QHG_LOCATION tag is specified, the QCH_FILE tag can ++# be used to specify the file name of the resulting .qch file. ++# The path specified is relative to the HTML output folder. ++ ++QCH_FILE = ++ ++# The QHP_NAMESPACE tag specifies the namespace to use when generating ++# Qt Help Project output. For more information please see ++# http://doc.trolltech.com/qthelpproject.html#namespace ++ ++QHP_NAMESPACE = org.doxygen.Project ++ ++# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating ++# Qt Help Project output. For more information please see ++# http://doc.trolltech.com/qthelpproject.html#virtual-folders ++ ++QHP_VIRTUAL_FOLDER = doc ++ ++# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to ++# add. For more information please see ++# http://doc.trolltech.com/qthelpproject.html#custom-filters ++ ++QHP_CUST_FILTER_NAME = ++ ++# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the ++# custom filter to add. For more information please see ++# ++# Qt Help Project / Custom Filters. ++ ++QHP_CUST_FILTER_ATTRS = ++ ++# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this ++# project's ++# filter section matches. ++# ++# Qt Help Project / Filter Attributes. ++ ++QHP_SECT_FILTER_ATTRS = ++ ++# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can ++# be used to specify the location of Qt's qhelpgenerator. ++# If non-empty doxygen will try to run qhelpgenerator on the generated ++# .qhp file. ++ ++QHG_LOCATION = ++ ++# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files ++# will be generated, which together with the HTML files, form an Eclipse help ++# plugin. To install this plugin and make it available under the help contents ++# menu in Eclipse, the contents of the directory containing the HTML and XML ++# files needs to be copied into the plugins directory of eclipse. The name of ++# the directory within the plugins directory should be the same as ++# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before ++# the help appears. ++ ++GENERATE_ECLIPSEHELP = NO ++ ++# A unique identifier for the eclipse help plugin. When installing the plugin ++# the directory name containing the HTML and XML files should also have ++# this name. ++ ++ECLIPSE_DOC_ID = org.doxygen.Project ++ + # The DISABLE_INDEX tag can be used to turn on/off the condensed index at + # top of each HTML page. The value NO (the default) enables the index and + # the value YES disables it. +@@ -854,27 +1026,30 @@ + + # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index + # structure should be generated to display hierarchical information. +-# If the tag value is set to FRAME, a side panel will be generated ++# If the tag value is set to YES, a side panel will be generated + # containing a tree-like index structure (just like the one that + # is generated for HTML Help). For this to work a browser that supports +-# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +-# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +-# probably better off using the HTML help feature. Other possible values +-# for this tag are: HIERARCHIES, which will generate the Groups, Directories, +-# and Class Hiererachy pages using a tree view instead of an ordered list; +-# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which +-# disables this behavior completely. For backwards compatibility with previous +-# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE +-# respectively. ++# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). ++# Windows users are probably better off using the HTML help feature. + + GENERATE_TREEVIEW = NO + ++# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, ++# and Class Hierarchy pages using a tree view instead of an ordered list. ++ ++USE_INLINE_TREES = NO ++ + # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be + # used to set the initial width (in pixels) of the frame in which the tree + # is shown. + + TREEVIEW_WIDTH = 250 + ++# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open ++# links to external symbols imported via tag files in a separate window. ++ ++EXT_LINKS_IN_WINDOW = NO ++ + # Use this tag to change the font size of Latex formulas included + # as images in the HTML documentation. The default is 10. Note that + # when you change the font size after a successful doxygen run you need +@@ -883,6 +1058,34 @@ + + FORMULA_FONTSIZE = 10 + ++# Use the FORMULA_TRANPARENT tag to determine whether or not the images ++# generated for formulas are transparent PNGs. Transparent PNGs are ++# not supported properly for IE 6.0, but are supported on all modern browsers. ++# Note that when changing this option you need to delete any form_*.png files ++# in the HTML output before the changes have effect. ++ ++FORMULA_TRANSPARENT = YES ++ ++# When the SEARCHENGINE tag is enabled doxygen will generate a search box ++# for the HTML output. The underlying search engine uses javascript ++# and DHTML and should work on any modern browser. Note that when using ++# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets ++# (GENERATE_DOCSET) there is already a search function so this one should ++# typically be disabled. For large projects the javascript based search engine ++# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. ++ ++SEARCHENGINE = NO ++ ++# When the SERVER_BASED_SEARCH tag is enabled the search engine will be ++# implemented using a PHP enabled web server instead of at the web client ++# using Javascript. Doxygen will generate the search PHP script and index ++# file to put on the web server. The advantage of the server ++# based approach is that it scales better to large projects and allows ++# full text search. The disadvances is that it is more difficult to setup ++# and does not have live searching capabilities. ++ ++SERVER_BASED_SEARCH = NO ++ + #--------------------------------------------------------------------------- + # configuration options related to the LaTeX output + #--------------------------------------------------------------------------- +@@ -900,6 +1103,9 @@ + + # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be + # invoked. If left blank `latex' will be used as the default command name. ++# Note that when enabling USE_PDFLATEX this option is only used for ++# generating bitmaps for formulas in the HTML output, but not in the ++# Makefile that is written to the output directory. + + LATEX_CMD_NAME = latex + +@@ -959,6 +1165,13 @@ + + LATEX_HIDE_INDICES = NO + ++# If LATEX_SOURCE_CODE is set to YES then doxygen will include ++# source code with syntax highlighting in the LaTeX output. ++# Note that which sources are shown also depends on other settings ++# such as SOURCE_BROWSER. ++ ++LATEX_SOURCE_CODE = NO ++ + #--------------------------------------------------------------------------- + # configuration options related to the RTF output + #--------------------------------------------------------------------------- +@@ -1095,8 +1308,10 @@ + PERLMOD_LATEX = NO + + # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +-# nicely formatted so it can be parsed by a human reader. This is useful +-# if you want to understand what is going on. On the other hand, if this ++# nicely formatted so it can be parsed by a human reader. ++# This is useful ++# if you want to understand what is going on. ++# On the other hand, if this + # tag is set to NO the size of the Perl module output will be much smaller + # and Perl will parse it just the same. + +@@ -1158,16 +1373,23 @@ + # undefined via #undef or recursively expanded use the := operator + # instead of the = operator. + +-PREDEFINED = __attribute__(x)="" "RENAME(x)=x ## _TMPL" "DEF(x)=x ## _TMPL" \ +- HAVE_AV_CONFIG_H HAVE_MMX HAVE_MMX2 HAVE_AMD3DNOW \ ++PREDEFINED = "__attribute__(x)=" \ ++ "RENAME(x)=x ## _TMPL" \ ++ "DEF(x)=x ## _TMPL" \ ++ HAVE_AV_CONFIG_H \ ++ HAVE_MMX \ ++ HAVE_MMX2 \ ++ HAVE_AMD3DNOW \ ++ "DECLARE_ALIGNED(a,t,n)=t n" \ ++ "offsetof(x,y)=0x42" + + # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then + # this tag can be used to specify a list of macro names that should be expanded. + # The macro definition that is found in the sources will be used. + # Use the PREDEFINED tag if you want to use a different macro definition. + +-#EXPAND_AS_DEFINED = FF_COMMON_FRAME +-EXPAND_AS_DEFINED = declare_idct(idct, table, idct_row_head, idct_row, idct_row_tail, idct_row_mid) ++EXPAND_AS_DEFINED = declare_idct \ ++ READ_PAR_DATA \ + + # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then + # doxygen's preprocessor will remove all function-like macros that are alone +@@ -1185,9 +1407,11 @@ + # Optionally an initial location of the external documentation + # can be added for each tagfile. The format of a tag file without + # this location is as follows: +-# TAGFILES = file1 file2 ... ++# ++# TAGFILES = file1 file2 ... + # Adding location for the tag files is done as follows: +-# TAGFILES = file1=loc1 "file2 = loc2" ... ++# ++# TAGFILES = file1=loc1 "file2 = loc2" ... + # where "loc1" and "loc2" can be relative or absolute paths or + # URLs. If a location is present for each tag, the installdox tool + # does not have to be run to correct the links. +@@ -1255,6 +1479,14 @@ + + HAVE_DOT = NO + ++# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is ++# allowed to run in parallel. When set to 0 (the default) doxygen will ++# base this on the number of processors available in the system. You can set it ++# explicitly to a value larger than 0 to get control over the balance ++# between CPU load and processing speed. ++ ++DOT_NUM_THREADS = 0 ++ + # By default doxygen will write a font called FreeSans.ttf to the output + # directory and reference it in all dot files that doxygen generates. This + # font does not include all possible unicode characters however, so when you need +@@ -1266,6 +1498,11 @@ + + DOT_FONTNAME = FreeSans + ++# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. ++# The default size is 10pt. ++ ++DOT_FONTSIZE = 10 ++ + # By default doxygen will tell dot to use the output directory to look for the + # FreeSans.ttf font (which doxygen will put there itself). If you specify a + # different font using DOT_FONTNAME you can set the path where dot +@@ -1383,10 +1620,10 @@ + MAX_DOT_GRAPH_DEPTH = 0 + + # Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +-# background. This is enabled by default, which results in a transparent +-# background. Warning: Depending on the platform used, enabling this option +-# may lead to badly anti-aliased labels on the edges of a graph (i.e. they +-# become hard to read). ++# background. This is disabled by default, because dot on Windows does not ++# seem to support this out of the box. Warning: Depending on the platform used, ++# enabling this option may lead to badly anti-aliased labels on the edges of ++# a graph (i.e. they become hard to read). + + DOT_TRANSPARENT = YES + +@@ -1408,12 +1645,3 @@ + # the various graphs. + + DOT_CLEANUP = YES +- +-#--------------------------------------------------------------------------- +-# Configuration::additions related to the search engine +-#--------------------------------------------------------------------------- +- +-# The SEARCHENGINE tag specifies whether or not a search engine should be +-# used. If set to NO the values of all tags below this one will be ignored. +- +-SEARCHENGINE = NO +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/ffmpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/ffmpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/ffmpeg.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/ffmpeg.c 2012-05-14 14:08:53.218317521 +0200 +@@ -1,5 +1,4 @@ + /* +- * FFmpeg main + * Copyright (c) 2000-2003 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -19,8 +18,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/* needed for usleep() */ +-#define _XOPEN_SOURCE 600 ++/** ++ * @file ++ * multimedia converter based on the FFmpeg libraries ++ */ + + #include "config.h" + #include +@@ -34,22 +35,31 @@ + #include "libavformat/avformat.h" + #include "libavdevice/avdevice.h" + #include "libswscale/swscale.h" +-#include "libavcodec/opt.h" ++#include "libavutil/opt.h" + #include "libavcodec/audioconvert.h" +-#include "libavcore/audioconvert.h" +-#include "libavcore/parseutils.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/samplefmt.h" + #include "libavutil/colorspace.h" + #include "libavutil/fifo.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "libavutil/pixdesc.h" + #include "libavutil/avstring.h" + #include "libavutil/libm.h" ++#include "libavutil/imgutils.h" + #include "libavformat/os_support.h" ++#include "libswresample/swresample.h" ++ ++#include "libavformat/ffm.h" // not public API + + #if CONFIG_AVFILTER ++# include "libavfilter/avcodec.h" + # include "libavfilter/avfilter.h" + # include "libavfilter/avfiltergraph.h" ++# include "libavfilter/buffersink.h" ++# include "libavfilter/buffersrc.h" + # include "libavfilter/vsrc_buffer.h" + #endif + +@@ -74,7 +84,7 @@ + #include + #include + #include +-#elif HAVE_CONIO_H ++#elif HAVE_KBHIT + #include + #endif + #include +@@ -83,210 +93,170 @@ + + #include "libavutil/avassert.h" + +-const char program_name[] = "FFmpeg"; ++#define VSYNC_AUTO -1 ++#define VSYNC_PASSTHROUGH 0 ++#define VSYNC_CFR 1 ++#define VSYNC_VFR 2 ++ ++const char program_name[] = "ffmpeg"; + const int program_birth_year = 2000; + + /* select an input stream for an output stream */ +-typedef struct AVStreamMap { ++typedef struct StreamMap { ++ int disabled; /** 1 is this mapping is disabled by a negative map */ + int file_index; + int stream_index; + int sync_file_index; + int sync_stream_index; +-} AVStreamMap; ++} StreamMap; ++ ++typedef struct { ++ int file_idx, stream_idx, channel_idx; // input ++ int ofile_idx, ostream_idx; // output ++} AudioChannelMap; + + /** + * select an input file for an output file + */ +-typedef struct AVMetaDataMap { +- int file; //< file index +- char type; //< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram +- int index; //< stream/chapter/program number +-} AVMetaDataMap; +- +-typedef struct AVChapterMap { +- int in_file; +- int out_file; +-} AVChapterMap; ++typedef struct MetadataMap { ++ int file; ///< file index ++ char type; ///< type of metadata to copy -- (g)lobal, (s)tream, (c)hapter or (p)rogram ++ int index; ///< stream/chapter/program number ++} MetadataMap; + + static const OptionDef options[]; + +-#define MAX_FILES 100 +-#if !FF_API_MAX_STREAMS + #define MAX_STREAMS 1024 /* arbitrary sanity check value */ +-#endif + +-static const char *last_asked_format = NULL; +-static AVFormatContext *input_files[MAX_FILES]; +-static int64_t input_files_ts_offset[MAX_FILES]; +-static double *input_files_ts_scale[MAX_FILES] = {NULL}; +-static AVCodec **input_codecs = NULL; +-static int nb_input_files = 0; +-static int nb_input_codecs = 0; +-static int nb_input_files_ts_scale[MAX_FILES] = {0}; +- +-static AVFormatContext *output_files[MAX_FILES]; +-static AVCodec **output_codecs = NULL; +-static int nb_output_files = 0; +-static int nb_output_codecs = 0; +- +-static AVStreamMap *stream_maps = NULL; +-static int nb_stream_maps; +- +-/* first item specifies output metadata, second is input */ +-static AVMetaDataMap (*meta_data_maps)[2] = NULL; +-static int nb_meta_data_maps; +-static int metadata_global_autocopy = 1; +-static int metadata_streams_autocopy = 1; +-static int metadata_chapters_autocopy = 1; +- +-static AVChapterMap *chapter_maps = NULL; +-static int nb_chapter_maps; +- +-/* indexed by output file stream index */ +-static int *streamid_map = NULL; +-static int nb_streamid_map = 0; +- +-static int frame_width = 0; +-static int frame_height = 0; +-static float frame_aspect_ratio = 0; +-static enum PixelFormat frame_pix_fmt = PIX_FMT_NONE; +-static enum AVSampleFormat audio_sample_fmt = AV_SAMPLE_FMT_NONE; +-static int max_frames[4] = {INT_MAX, INT_MAX, INT_MAX, INT_MAX}; +-static AVRational frame_rate; +-static float video_qscale = 0; +-static uint16_t *intra_matrix = NULL; +-static uint16_t *inter_matrix = NULL; +-static const char *video_rc_override_string=NULL; +-static int video_disable = 0; ++static int frame_bits_per_raw_sample = 0; + static int video_discard = 0; +-static char *video_codec_name = NULL; +-static unsigned int video_codec_tag = 0; +-static char *video_language = NULL; +-static int same_quality = 0; ++static int same_quant = 0; + static int do_deinterlace = 0; +-static int top_field_first = -1; +-static int me_threshold = 0; + static int intra_dc_precision = 8; + static int loop_input = 0; + static int loop_output = AVFMT_NOOUTPUTLOOP; + static int qp_hist = 0; +-#if CONFIG_AVFILTER +-static char *vfilters = NULL; +-static AVFilterGraph *graph = NULL; +-#endif +- + static int intra_only = 0; +-static int audio_sample_rate = 44100; +-static int64_t channel_layout = 0; +-#define QSCALE_NONE -99999 +-static float audio_qscale = QSCALE_NONE; +-static int audio_disable = 0; +-static int audio_channels = 1; +-static char *audio_codec_name = NULL; +-static unsigned int audio_codec_tag = 0; +-static char *audio_language = NULL; +- +-static int subtitle_disable = 0; +-static char *subtitle_codec_name = NULL; +-static char *subtitle_language = NULL; +-static unsigned int subtitle_codec_tag = 0; +- +-static float mux_preload= 0.5; +-static float mux_max_delay= 0.7; +- +-static int64_t recording_time = INT64_MAX; +-static int64_t start_time = 0; +-static int64_t recording_timestamp = 0; +-static int64_t input_ts_offset = 0; ++static const char *video_codec_name = NULL; ++static const char *audio_codec_name = NULL; ++static const char *subtitle_codec_name = NULL; ++ + static int file_overwrite = 0; +-static AVMetadata *metadata; ++static int no_file_overwrite = 0; + static int do_benchmark = 0; + static int do_hex_dump = 0; + static int do_pkt_dump = 0; + static int do_psnr = 0; + static int do_pass = 0; +-static char *pass_logfilename_prefix = NULL; +-static int audio_stream_copy = 0; +-static int video_stream_copy = 0; +-static int subtitle_stream_copy = 0; +-static int video_sync_method= -1; +-static int audio_sync_method= 0; +-static float audio_drift_threshold= 0.1; +-static int copy_ts= 0; +-static int copy_tb; ++static const char *pass_logfilename_prefix; ++static int video_sync_method = VSYNC_AUTO; ++static int audio_sync_method = 0; ++static float audio_drift_threshold = 0.1; ++static int copy_ts = 0; ++static int copy_tb = -1; + static int opt_shortest = 0; +-static int video_global_header = 0; + static char *vstats_filename; + static FILE *vstats_file; +-static int opt_programid = 0; +-static int copy_initial_nonkeyframes = 0; +- +-static int rate_emu = 0; +- +-static int video_channel = 0; +-static char *video_standard; + + static int audio_volume = 256; + + static int exit_on_error = 0; + static int using_stdin = 0; +-static int verbose = 1; +-static int thread_count= 1; +-static int q_pressed = 0; ++static int run_as_daemon = 0; ++static volatile int received_nb_signals = 0; + static int64_t video_size = 0; + static int64_t audio_size = 0; + static int64_t extra_size = 0; + static int nb_frames_dup = 0; + static int nb_frames_drop = 0; + static int input_sync; +-static uint64_t limit_filesize = 0; +-static int force_fps = 0; +-static char *forced_key_frames = NULL; + + static float dts_delta_threshold = 10; + +-static unsigned int sws_flags = SWS_BICUBIC; +- +-static int64_t timer_start; ++static int print_stats = 1; + + static uint8_t *audio_buf; +-static uint8_t *audio_out; +-static unsigned int allocated_audio_out_size, allocated_audio_buf_size; +- +-static short *samples; ++static unsigned int allocated_audio_buf_size; + +-static AVBitStreamFilterContext *video_bitstream_filters=NULL; +-static AVBitStreamFilterContext *audio_bitstream_filters=NULL; +-static AVBitStreamFilterContext *subtitle_bitstream_filters=NULL; ++static uint8_t *input_tmp= NULL; + + #define DEFAULT_PASS_LOGFILENAME_PREFIX "ffmpeg2pass" + +-struct AVInputStream; ++typedef struct FrameBuffer { ++ uint8_t *base[4]; ++ uint8_t *data[4]; ++ int linesize[4]; ++ ++ int h, w; ++ enum PixelFormat pix_fmt; ++ ++ int refcount; ++ struct InputStream *ist; ++ struct FrameBuffer *next; ++} FrameBuffer; ++ ++typedef struct InputStream { ++ int file_index; ++ AVStream *st; ++ int discard; /* true if stream data should be discarded */ ++ int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ ++ AVCodec *dec; ++ AVFrame *decoded_frame; ++ AVFrame *filtered_frame; ++ ++ int64_t start; /* time when read started */ ++ int64_t next_pts; /* synthetic pts for cases where pkt.pts ++ is not defined */ ++ int64_t pts; /* current pts */ ++ double ts_scale; ++ int is_start; /* is 1 at the start and after a discontinuity */ ++ int showed_multi_packet_warning; ++ AVDictionary *opts; ++ ++ /* a pool of free buffers for decoded data */ ++ FrameBuffer *buffer_pool; ++ int dr1; ++} InputStream; ++ ++typedef struct InputFile { ++ AVFormatContext *ctx; ++ int eof_reached; /* true if eof reached */ ++ int ist_index; /* index of first stream in input_streams */ ++ int buffer_size; /* current total buffer size */ ++ int64_t ts_offset; ++ int nb_streams; /* number of stream that ffmpeg is aware of; may be different ++ from ctx.nb_streams if new streams appear during av_read_frame() */ ++ int rate_emu; ++} InputFile; + +-typedef struct AVOutputStream { ++typedef struct OutputStream { + int file_index; /* file index */ + int index; /* stream index in the output file */ +- int source_index; /* AVInputStream index */ ++ int source_index; /* InputStream index */ + AVStream *st; /* stream in the output file */ + int encoding_needed; /* true if encoding needed for this stream */ + int frame_number; + /* input pts and corresponding output pts + for A/V sync */ +- //double sync_ipts; /* dts from the AVPacket of the demuxer in second units */ +- struct AVInputStream *sync_ist; /* input stream to sync against */ +- int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ //FIXME look at frame_number ++ struct InputStream *sync_ist; /* input stream to sync against */ ++ int64_t sync_opts; /* output frame counter, could be changed to some true timestamp */ // FIXME look at frame_number + AVBitStreamFilterContext *bitstream_filters; ++ AVCodec *enc; ++ int64_t max_frames; ++ AVFrame *output_frame; ++ + /* video only */ + int video_resample; +- AVFrame pict_tmp; /* temporary image for resampling */ ++ AVFrame resample_frame; /* temporary frame for image resampling */ + struct SwsContext *img_resample_ctx; /* for image resampling */ + int resample_height; + int resample_width; + int resample_pix_fmt; ++ AVRational frame_rate; ++ int force_fps; ++ int top_field_first; + +- /* full frame size of first frame */ +- int original_height; +- int original_width; ++ float frame_aspect_ratio; + + /* forced key frames */ + int64_t *forced_kf_pts; +@@ -295,102 +265,404 @@ + + /* audio only */ + int audio_resample; +- ReSampleContext *resample; /* for audio resampling */ ++ int audio_channels_map[SWR_CH_MAX]; ///< list of the channels id to pick from the source stream ++ int audio_channels_mapped; ///< number of channels in audio_channels_map + int resample_sample_fmt; + int resample_channels; + int resample_sample_rate; +- int reformat_pair; +- AVAudioConvert *reformat_ctx; ++ float rematrix_volume; + AVFifoBuffer *fifo; /* for compression: one audio fifo per codec */ + FILE *logfile; +-} AVOutputStream; +- +-static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL }; +-static int nb_output_streams_for_file[MAX_FILES] = { 0 }; + +-typedef struct AVInputStream { +- int file_index; +- int index; +- AVStream *st; +- int discard; /* true if stream data should be discarded */ +- int decoding_needed; /* true if the packets must be decoded in 'raw_fifo' */ +- int64_t sample_index; /* current sample */ ++ struct SwrContext *swr; + +- int64_t start; /* time when read started */ +- int64_t next_pts; /* synthetic pts for cases where pkt.pts +- is not defined */ +- int64_t pts; /* current pts */ +- PtsCorrectionContext pts_ctx; +- int is_start; /* is 1 at the start and after a discontinuity */ +- int showed_multi_packet_warning; +- int is_past_recording_time; + #if CONFIG_AVFILTER + AVFilterContext *output_video_filter; + AVFilterContext *input_video_filter; +- AVFrame *filter_frame; +- int has_filter_frame; + AVFilterBufferRef *picref; ++ char *avfilter; ++ AVFilterGraph *graph; + #endif +-} AVInputStream; + +-typedef struct AVInputFile { +- int eof_reached; /* true if eof reached */ +- int ist_index; /* index of first stream in ist_table */ +- int buffer_size; /* current total buffer size */ +- int nb_streams; /* nb streams we are aware of */ +-} AVInputFile; ++ int64_t sws_flags; ++ AVDictionary *opts; ++ int is_past_recording_time; ++ int stream_copy; ++ const char *attachment_filename; ++ int copy_initial_nonkeyframes; ++} OutputStream; ++ + + #if HAVE_TERMIOS_H + + /* init terminal so that we can grab keys */ + static struct termios oldtty; ++static int restore_tty; ++#endif ++ ++typedef struct OutputFile { ++ AVFormatContext *ctx; ++ AVDictionary *opts; ++ int ost_index; /* index of the first stream in output_streams */ ++ int64_t recording_time; /* desired length of the resulting file in microseconds */ ++ int64_t start_time; /* start time in microseconds */ ++ uint64_t limit_filesize; ++} OutputFile; ++ ++static InputStream *input_streams = NULL; ++static int nb_input_streams = 0; ++static InputFile *input_files = NULL; ++static int nb_input_files = 0; ++ ++static OutputStream *output_streams = NULL; ++static int nb_output_streams = 0; ++static OutputFile *output_files = NULL; ++static int nb_output_files = 0; ++ ++typedef struct OptionsContext { ++ /* input/output options */ ++ int64_t start_time; ++ const char *format; ++ ++ SpecifierOpt *codec_names; ++ int nb_codec_names; ++ SpecifierOpt *audio_channels; ++ int nb_audio_channels; ++ SpecifierOpt *audio_sample_rate; ++ int nb_audio_sample_rate; ++ SpecifierOpt *rematrix_volume; ++ int nb_rematrix_volume; ++ SpecifierOpt *frame_rates; ++ int nb_frame_rates; ++ SpecifierOpt *frame_sizes; ++ int nb_frame_sizes; ++ SpecifierOpt *frame_pix_fmts; ++ int nb_frame_pix_fmts; ++ ++ /* input options */ ++ int64_t input_ts_offset; ++ int rate_emu; ++ ++ SpecifierOpt *ts_scale; ++ int nb_ts_scale; ++ SpecifierOpt *dump_attachment; ++ int nb_dump_attachment; ++ ++ /* output options */ ++ StreamMap *stream_maps; ++ int nb_stream_maps; ++ AudioChannelMap *audio_channel_maps; ///< one info entry per -map_channel ++ int nb_audio_channel_maps; ///< number of (valid) -map_channel settings ++ /* first item specifies output metadata, second is input */ ++ MetadataMap (*meta_data_maps)[2]; ++ int nb_meta_data_maps; ++ int metadata_global_manual; ++ int metadata_streams_manual; ++ int metadata_chapters_manual; ++ const char **attachments; ++ int nb_attachments; ++ ++ int chapters_input_file; ++ ++ int64_t recording_time; ++ uint64_t limit_filesize; ++ float mux_preload; ++ float mux_max_delay; ++ ++ int video_disable; ++ int audio_disable; ++ int subtitle_disable; ++ int data_disable; ++ ++ /* indexed by output file stream index */ ++ int *streamid_map; ++ int nb_streamid_map; ++ ++ SpecifierOpt *metadata; ++ int nb_metadata; ++ SpecifierOpt *max_frames; ++ int nb_max_frames; ++ SpecifierOpt *bitstream_filters; ++ int nb_bitstream_filters; ++ SpecifierOpt *codec_tags; ++ int nb_codec_tags; ++ SpecifierOpt *sample_fmts; ++ int nb_sample_fmts; ++ SpecifierOpt *qscale; ++ int nb_qscale; ++ SpecifierOpt *forced_key_frames; ++ int nb_forced_key_frames; ++ SpecifierOpt *force_fps; ++ int nb_force_fps; ++ SpecifierOpt *frame_aspect_ratios; ++ int nb_frame_aspect_ratios; ++ SpecifierOpt *rc_overrides; ++ int nb_rc_overrides; ++ SpecifierOpt *intra_matrices; ++ int nb_intra_matrices; ++ SpecifierOpt *inter_matrices; ++ int nb_inter_matrices; ++ SpecifierOpt *top_field_first; ++ int nb_top_field_first; ++ SpecifierOpt *metadata_map; ++ int nb_metadata_map; ++ SpecifierOpt *presets; ++ int nb_presets; ++ SpecifierOpt *copy_initial_nonkeyframes; ++ int nb_copy_initial_nonkeyframes; ++#if CONFIG_AVFILTER ++ SpecifierOpt *filters; ++ int nb_filters; + #endif ++} OptionsContext; ++ ++#define MATCH_PER_STREAM_OPT(name, type, outvar, fmtctx, st)\ ++{\ ++ int i, ret;\ ++ for (i = 0; i < o->nb_ ## name; i++) {\ ++ char *spec = o->name[i].specifier;\ ++ if ((ret = check_stream_specifier(fmtctx, st, spec)) > 0)\ ++ outvar = o->name[i].u.type;\ ++ else if (ret < 0)\ ++ exit_program(1);\ ++ }\ ++} ++ ++static void reset_options(OptionsContext *o, int is_input) ++{ ++ const OptionDef *po = options; ++ OptionsContext bak= *o; ++ ++ /* all OPT_SPEC and OPT_STRING can be freed in generic way */ ++ while (po->name) { ++ void *dst = (uint8_t*)o + po->u.off; ++ ++ if (po->flags & OPT_SPEC) { ++ SpecifierOpt **so = dst; ++ int i, *count = (int*)(so + 1); ++ for (i = 0; i < *count; i++) { ++ av_freep(&(*so)[i].specifier); ++ if (po->flags & OPT_STRING) ++ av_freep(&(*so)[i].u.str); ++ } ++ av_freep(so); ++ *count = 0; ++ } else if (po->flags & OPT_OFFSET && po->flags & OPT_STRING) ++ av_freep(dst); ++ po++; ++ } ++ ++ av_freep(&o->stream_maps); ++ av_freep(&o->audio_channel_maps); ++ av_freep(&o->meta_data_maps); ++ av_freep(&o->streamid_map); ++ ++ memset(o, 0, sizeof(*o)); ++ ++ if(is_input) o->recording_time = bak.recording_time; ++ else o->recording_time = INT64_MAX; ++ o->mux_max_delay = 0.7; ++ o->limit_filesize = UINT64_MAX; ++ o->chapters_input_file = INT_MAX; ++ ++ uninit_opts(); ++ init_opts(); ++} ++ ++static int alloc_buffer(AVCodecContext *s, InputStream *ist, FrameBuffer **pbuf) ++{ ++ FrameBuffer *buf = av_mallocz(sizeof(*buf)); ++ int ret, i; ++ const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1; ++ int h_chroma_shift, v_chroma_shift; ++ int edge = 32; // XXX should be avcodec_get_edge_width(), but that fails on svq1 ++ int w = s->width, h = s->height; ++ ++ if (!buf) ++ return AVERROR(ENOMEM); ++ ++ if (!(s->flags & CODEC_FLAG_EMU_EDGE)) { ++ w += 2*edge; ++ h += 2*edge; ++ } ++ ++ avcodec_align_dimensions(s, &w, &h); ++ if ((ret = av_image_alloc(buf->base, buf->linesize, w, h, ++ s->pix_fmt, 32)) < 0) { ++ av_freep(&buf); ++ return ret; ++ } ++ /* XXX this shouldn't be needed, but some tests break without this line ++ * those decoders are buggy and need to be fixed. ++ * the following tests fail: ++ * bethsoft-vid, cdgraphics, ansi, aasc, fraps-v1, qtrle-1bit ++ */ ++ memset(buf->base[0], 128, ret); ++ ++ avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); ++ for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { ++ const int h_shift = i==0 ? 0 : h_chroma_shift; ++ const int v_shift = i==0 ? 0 : v_chroma_shift; ++ if (s->flags & CODEC_FLAG_EMU_EDGE) ++ buf->data[i] = buf->base[i]; ++ else ++ buf->data[i] = buf->base[i] + ++ FFALIGN((buf->linesize[i]*edge >> v_shift) + ++ (pixel_size*edge >> h_shift), 32); ++ } ++ buf->w = s->width; ++ buf->h = s->height; ++ buf->pix_fmt = s->pix_fmt; ++ buf->ist = ist; ++ ++ *pbuf = buf; ++ return 0; ++} ++ ++static void free_buffer_pool(InputStream *ist) ++{ ++ FrameBuffer *buf = ist->buffer_pool; ++ while (buf) { ++ ist->buffer_pool = buf->next; ++ av_freep(&buf->base[0]); ++ av_free(buf); ++ buf = ist->buffer_pool; ++ } ++} ++ ++static void unref_buffer(InputStream *ist, FrameBuffer *buf) ++{ ++ av_assert0(buf->refcount); ++ buf->refcount--; ++ if (!buf->refcount) { ++ buf->next = ist->buffer_pool; ++ ist->buffer_pool = buf; ++ } ++} ++ ++static int codec_get_buffer(AVCodecContext *s, AVFrame *frame) ++{ ++ InputStream *ist = s->opaque; ++ FrameBuffer *buf; ++ int ret, i; ++ ++ if(av_image_check_size(s->width, s->height, 0, s)) ++ return -1; ++ ++ if (!ist->buffer_pool && (ret = alloc_buffer(s, ist, &ist->buffer_pool)) < 0) ++ return ret; ++ ++ buf = ist->buffer_pool; ++ ist->buffer_pool = buf->next; ++ buf->next = NULL; ++ if (buf->w != s->width || buf->h != s->height || buf->pix_fmt != s->pix_fmt) { ++ av_freep(&buf->base[0]); ++ av_free(buf); ++ ist->dr1 = 0; ++ if ((ret = alloc_buffer(s, ist, &buf)) < 0) ++ return ret; ++ } ++ buf->refcount++; ++ ++ frame->opaque = buf; ++ frame->type = FF_BUFFER_TYPE_USER; ++ frame->extended_data = frame->data; ++ frame->pkt_pts = s->pkt ? s->pkt->pts : AV_NOPTS_VALUE; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(buf->data); i++) { ++ frame->base[i] = buf->base[i]; // XXX h264.c uses base though it shouldn't ++ frame->data[i] = buf->data[i]; ++ frame->linesize[i] = buf->linesize[i]; ++ } ++ ++ return 0; ++} ++ ++static void codec_release_buffer(AVCodecContext *s, AVFrame *frame) ++{ ++ InputStream *ist = s->opaque; ++ FrameBuffer *buf = frame->opaque; ++ int i; ++ ++ if(frame->type!=FF_BUFFER_TYPE_USER) ++ return avcodec_default_release_buffer(s, frame); ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(frame->data); i++) ++ frame->data[i] = NULL; ++ ++ unref_buffer(ist, buf); ++} ++ ++static void filter_release_buffer(AVFilterBuffer *fb) ++{ ++ FrameBuffer *buf = fb->priv; ++ av_free(fb); ++ unref_buffer(buf->ist, buf); ++} + + #if CONFIG_AVFILTER + +-static int configure_filters(AVInputStream *ist, AVOutputStream *ost) ++static int configure_video_filters(InputStream *ist, OutputStream *ost) + { + AVFilterContext *last_filter, *filter; + /** filter graph containing all filters including input & output */ + AVCodecContext *codec = ost->st->codec; + AVCodecContext *icodec = ist->st->codec; +- FFSinkContext ffsink_ctx = { .pix_fmt = codec->pix_fmt }; ++ enum PixelFormat pix_fmts[] = { codec->pix_fmt, PIX_FMT_NONE }; ++ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc(); ++ AVRational sample_aspect_ratio; + char args[255]; + int ret; + +- graph = avfilter_graph_alloc(); ++ ost->graph = avfilter_graph_alloc(); + +- snprintf(args, 255, "%d:%d:%d:%d:%d", ist->st->codec->width, +- ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE); +- ret = avfilter_graph_create_filter(&ist->input_video_filter, avfilter_get_by_name("buffer"), +- "src", args, NULL, graph); ++ if (ist->st->sample_aspect_ratio.num) { ++ sample_aspect_ratio = ist->st->sample_aspect_ratio; ++ } else ++ sample_aspect_ratio = ist->st->codec->sample_aspect_ratio; ++ ++ snprintf(args, 255, "%d:%d:%d:%d:%d:%d:%d", ist->st->codec->width, ++ ist->st->codec->height, ist->st->codec->pix_fmt, 1, AV_TIME_BASE, ++ sample_aspect_ratio.num, sample_aspect_ratio.den); ++ ++ ret = avfilter_graph_create_filter(&ost->input_video_filter, avfilter_get_by_name("buffer"), ++ "src", args, NULL, ost->graph); + if (ret < 0) + return ret; +- ret = avfilter_graph_create_filter(&ist->output_video_filter, &ffsink, +- "out", NULL, &ffsink_ctx, graph); ++ ++#if FF_API_OLD_VSINK_API ++ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"), ++ "out", NULL, pix_fmts, ost->graph); ++#else ++ buffersink_params->pixel_fmts = pix_fmts; ++ ret = avfilter_graph_create_filter(&ost->output_video_filter, avfilter_get_by_name("buffersink"), ++ "out", NULL, buffersink_params, ost->graph); ++#endif ++ av_freep(&buffersink_params); ++ + if (ret < 0) + return ret; +- last_filter = ist->input_video_filter; ++ last_filter = ost->input_video_filter; + +- if (codec->width != icodec->width || codec->height != icodec->height) { ++ if (codec->width != icodec->width || codec->height != icodec->height) { + snprintf(args, 255, "%d:%d:flags=0x%X", + codec->width, + codec->height, +- (int)av_get_int(sws_opts, "sws_flags", NULL)); ++ (unsigned)ost->sws_flags); + if ((ret = avfilter_graph_create_filter(&filter, avfilter_get_by_name("scale"), +- NULL, args, NULL, graph)) < 0) ++ NULL, args, NULL, ost->graph)) < 0) + return ret; + if ((ret = avfilter_link(last_filter, 0, filter, 0)) < 0) + return ret; + last_filter = filter; + } + +- snprintf(args, sizeof(args), "flags=0x%X", (int)av_get_int(sws_opts, "sws_flags", NULL)); +- graph->scale_sws_opts = av_strdup(args); ++ snprintf(args, sizeof(args), "flags=0x%X", (unsigned)ost->sws_flags); ++ ost->graph->scale_sws_opts = av_strdup(args); + +- if (vfilters) { +- AVFilterInOut *outputs = av_malloc(sizeof(AVFilterInOut)); +- AVFilterInOut *inputs = av_malloc(sizeof(AVFilterInOut)); ++ if (ost->avfilter) { ++ AVFilterInOut *outputs = avfilter_inout_alloc(); ++ AVFilterInOut *inputs = avfilter_inout_alloc(); + + outputs->name = av_strdup("in"); + outputs->filter_ctx = last_filter; +@@ -398,23 +670,27 @@ + outputs->next = NULL; + + inputs->name = av_strdup("out"); +- inputs->filter_ctx = ist->output_video_filter; ++ inputs->filter_ctx = ost->output_video_filter; + inputs->pad_idx = 0; + inputs->next = NULL; + +- if ((ret = avfilter_graph_parse(graph, vfilters, inputs, outputs, NULL)) < 0) ++ if ((ret = avfilter_graph_parse(ost->graph, ost->avfilter, &inputs, &outputs, NULL)) < 0) + return ret; +- av_freep(&vfilters); ++ av_freep(&ost->avfilter); + } else { +- if ((ret = avfilter_link(last_filter, 0, ist->output_video_filter, 0)) < 0) ++ if ((ret = avfilter_link(last_filter, 0, ost->output_video_filter, 0)) < 0) + return ret; + } + +- if ((ret = avfilter_graph_config(graph, NULL)) < 0) ++ if ((ret = avfilter_graph_config(ost->graph, NULL)) < 0) + return ret; + +- codec->width = ist->output_video_filter->inputs[0]->w; +- codec->height = ist->output_video_filter->inputs[0]->h; ++ codec->width = ost->output_video_filter->inputs[0]->w; ++ codec->height = ost->output_video_filter->inputs[0]->h; ++ codec->sample_aspect_ratio = ost->st->sample_aspect_ratio = ++ ost->frame_aspect_ratio ? // overridden by the -aspect cli option ++ av_d2q(ost->frame_aspect_ratio * codec->height/codec->width, 255) : ++ ost->output_video_filter->inputs[0]->sample_aspect_ratio; + + return 0; + } +@@ -422,28 +698,33 @@ + + static void term_exit(void) + { +- av_log(NULL, AV_LOG_QUIET, ""); ++ av_log(NULL, AV_LOG_QUIET, "%s", ""); + #if HAVE_TERMIOS_H +- tcsetattr (0, TCSANOW, &oldtty); ++ if(restore_tty) ++ tcsetattr (0, TCSANOW, &oldtty); + #endif + } + + static volatile int received_sigterm = 0; + +-static void +-sigterm_handler(int sig) ++static void sigterm_handler(int sig) + { + received_sigterm = sig; ++ received_nb_signals++; + term_exit(); ++ if(received_nb_signals > 3) ++ exit(123); + } + + static void term_init(void) + { + #if HAVE_TERMIOS_H ++ if(!run_as_daemon){ + struct termios tty; + +- tcgetattr (0, &tty); ++ if (tcgetattr (0, &tty) == 0) { + oldtty = tty; ++ restore_tty = 1; + atexit(term_exit); + + tty.c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP +@@ -456,10 +737,13 @@ + tty.c_cc[VTIME] = 0; + + tcsetattr (0, TCSANOW, &tty); ++ } + signal(SIGQUIT, sigterm_handler); /* Quit (POSIX). */ ++ } + #endif ++ avformat_network_deinit(); + +- signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ ++ signal(SIGINT , sigterm_handler); /* Interrupt (ANSI). */ + signal(SIGTERM, sigterm_handler); /* Termination (ANSI). */ + #ifdef SIGXCPU + signal(SIGXCPU, sigterm_handler); +@@ -469,9 +753,9 @@ + /* read a key without blocking */ + static int read_key(void) + { ++ unsigned char ch; + #if HAVE_TERMIOS_H + int n = 1; +- unsigned char ch; + struct timeval tv; + fd_set rfds; + +@@ -487,120 +771,151 @@ + + return n; + } +-#elif HAVE_CONIO_H ++#elif HAVE_KBHIT ++# if HAVE_PEEKNAMEDPIPE ++ static int is_pipe; ++ static HANDLE input_handle; ++ DWORD dw, nchars; ++ if(!input_handle){ ++ input_handle = GetStdHandle(STD_INPUT_HANDLE); ++ is_pipe = !GetConsoleMode(input_handle, &dw); ++ } ++ ++ if (stdin->_cnt > 0) { ++ read(0, &ch, 1); ++ return ch; ++ } ++ if (is_pipe) { ++ /* When running under a GUI, you will end here. */ ++ if (!PeekNamedPipe(input_handle, NULL, 0, NULL, &nchars, NULL)) ++ return -1; ++ //Read it ++ if(nchars != 0) { ++ read(0, &ch, 1); ++ return ch; ++ }else{ ++ return -1; ++ } ++ } ++# endif + if(kbhit()) + return(getch()); + #endif + return -1; + } + +-static int decode_interrupt_cb(void) ++static int decode_interrupt_cb(void *ctx) + { +- return q_pressed || (q_pressed = read_key() == 'q'); ++ return received_nb_signals > 1; + } + +-static int ffmpeg_exit(int ret) ++static const AVIOInterruptCB int_cb = { decode_interrupt_cb, NULL }; ++ ++void av_noreturn exit_program(int ret) + { + int i; + + /* close files */ +- for(i=0;ioformat->flags & AVFMT_NOFILE) && s->pb) +- url_fclose(s->pb); +- for(j=0;jnb_streams;j++) { +- av_metadata_free(&s->streams[j]->metadata); +- av_free(s->streams[j]->codec); +- av_free(s->streams[j]->info); +- av_free(s->streams[j]); +- } +- for(j=0;jnb_programs;j++) { +- av_metadata_free(&s->programs[j]->metadata); +- } +- for(j=0;jnb_chapters;j++) { +- av_metadata_free(&s->chapters[j]->metadata); +- } +- av_metadata_free(&s->metadata); +- av_free(s); +- av_free(output_streams_for_file[i]); +- } +- for(i=0;ipb); ++ avformat_free_context(s); ++ av_dict_free(&output_files[i].opts); ++ } ++ for (i = 0; i < nb_output_streams; i++) { ++ AVBitStreamFilterContext *bsfc = output_streams[i].bitstream_filters; ++ while (bsfc) { ++ AVBitStreamFilterContext *next = bsfc->next; ++ av_bitstream_filter_close(bsfc); ++ bsfc = next; ++ } ++ output_streams[i].bitstream_filters = NULL; ++ ++ if (output_streams[i].output_frame) { ++ AVFrame *frame = output_streams[i].output_frame; ++ if (frame->extended_data != frame->data) ++ av_freep(&frame->extended_data); ++ av_freep(&frame); ++ } ++ } ++ for (i = 0; i < nb_input_files; i++) { ++ avformat_close_input(&input_files[i].ctx); ++ } ++ for (i = 0; i < nb_input_streams; i++) { ++ av_freep(&input_streams[i].decoded_frame); ++ av_freep(&input_streams[i].filtered_frame); ++ av_dict_free(&input_streams[i].opts); ++ free_buffer_pool(&input_streams[i]); + } + +- av_free(intra_matrix); +- av_free(inter_matrix); +- + if (vstats_file) + fclose(vstats_file); + av_free(vstats_filename); + +- av_free(opt_names); +- av_free(streamid_map); +- av_free(input_codecs); +- av_free(output_codecs); +- av_free(stream_maps); +- av_free(meta_data_maps); +- +- av_free(video_codec_name); +- av_free(audio_codec_name); +- av_free(subtitle_codec_name); +- +- av_free(video_standard); ++ av_freep(&input_streams); ++ av_freep(&input_files); ++ av_freep(&output_streams); ++ av_freep(&output_files); + + uninit_opts(); + av_free(audio_buf); +- av_free(audio_out); +- allocated_audio_buf_size= allocated_audio_out_size= 0; +- av_free(samples); ++ allocated_audio_buf_size = 0; + + #if CONFIG_AVFILTER + avfilter_uninit(); + #endif ++ avformat_network_deinit(); ++ ++ av_freep(&input_tmp); + + if (received_sigterm) { +- fprintf(stderr, +- "Received signal %d: terminating.\n", +- (int) received_sigterm); ++ av_log(NULL, AV_LOG_INFO, "Received signal %d: terminating.\n", ++ (int) received_sigterm); + exit (255); + } + + exit(ret); /* not all OS-es handle main() return value */ +- return ret; + } + +-/* similar to ff_dynarray_add() and av_fast_realloc() */ +-static void *grow_array(void *array, int elem_size, int *size, int new_size) ++static void assert_avoptions(AVDictionary *m) ++{ ++ AVDictionaryEntry *t; ++ if ((t = av_dict_get(m, "", NULL, AV_DICT_IGNORE_SUFFIX))) { ++ av_log(NULL, AV_LOG_FATAL, "Option %s not found.\n", t->key); ++ exit_program(1); ++ } ++} ++ ++static void assert_codec_experimental(AVCodecContext *c, int encoder) + { +- if (new_size >= INT_MAX / elem_size) { +- fprintf(stderr, "Array too big.\n"); +- ffmpeg_exit(1); +- } +- if (*size < new_size) { +- uint8_t *tmp = av_realloc(array, new_size*elem_size); +- if (!tmp) { +- fprintf(stderr, "Could not alloc buffer.\n"); +- ffmpeg_exit(1); +- } +- memset(tmp + *size*elem_size, 0, (new_size-*size) * elem_size); +- *size = new_size; +- return tmp; ++ const char *codec_string = encoder ? "encoder" : "decoder"; ++ AVCodec *codec; ++ if (c->codec->capabilities & CODEC_CAP_EXPERIMENTAL && ++ c->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { ++ av_log(NULL, AV_LOG_FATAL, "%s '%s' is experimental and might produce bad " ++ "results.\nAdd '-strict experimental' if you want to use it.\n", ++ codec_string, c->codec->name); ++ codec = encoder ? avcodec_find_encoder(c->codec->id) : avcodec_find_decoder(c->codec->id); ++ if (!(codec->capabilities & CODEC_CAP_EXPERIMENTAL)) ++ av_log(NULL, AV_LOG_FATAL, "Or use the non experimental %s '%s'.\n", ++ codec_string, codec->name); ++ exit_program(1); + } +- return array; + } + + static void choose_sample_fmt(AVStream *st, AVCodec *codec) + { +- if(codec && codec->sample_fmts){ +- const enum AVSampleFormat *p= codec->sample_fmts; +- for(; *p!=-1; p++){ +- if(*p == st->codec->sample_fmt) ++ if (codec && codec->sample_fmts) { ++ const enum AVSampleFormat *p = codec->sample_fmts; ++ for (; *p != -1; p++) { ++ if (*p == st->codec->sample_fmt) + break; + } + if (*p == -1) { ++ if((codec->capabilities & CODEC_CAP_LOSSLESS) && av_get_sample_fmt_name(st->codec->sample_fmt) > av_get_sample_fmt_name(codec->sample_fmts[0])) ++ av_log(NULL, AV_LOG_ERROR, "Conversion will not be lossless.\n"); ++ if(av_get_sample_fmt_name(st->codec->sample_fmt)) + av_log(NULL, AV_LOG_WARNING, + "Incompatible sample format '%s' for codec '%s', auto-selecting format '%s'\n", + av_get_sample_fmt_name(st->codec->sample_fmt), +@@ -613,410 +928,357 @@ + + static void choose_sample_rate(AVStream *st, AVCodec *codec) + { +- if(codec && codec->supported_samplerates){ +- const int *p= codec->supported_samplerates; +- int best=0; +- int best_dist=INT_MAX; +- for(; *p; p++){ +- int dist= abs(st->codec->sample_rate - *p); +- if(dist < best_dist){ +- best_dist= dist; +- best= *p; ++ if (codec && codec->supported_samplerates) { ++ const int *p = codec->supported_samplerates; ++ int best = 0; ++ int best_dist = INT_MAX; ++ for (; *p; p++) { ++ int dist = abs(st->codec->sample_rate - *p); ++ if (dist < best_dist) { ++ best_dist = dist; ++ best = *p; + } + } +- if(best_dist){ ++ if (best_dist) { + av_log(st->codec, AV_LOG_WARNING, "Requested sampling rate unsupported using closest supported (%d)\n", best); + } +- st->codec->sample_rate= best; ++ st->codec->sample_rate = best; + } + } + + static void choose_pixel_fmt(AVStream *st, AVCodec *codec) + { +- if(codec && codec->pix_fmts){ +- const enum PixelFormat *p= codec->pix_fmts; +- if(st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL){ +- if(st->codec->codec_id==CODEC_ID_MJPEG){ +- p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}; +- }else if(st->codec->codec_id==CODEC_ID_LJPEG){ +- p= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_BGRA, PIX_FMT_NONE}; ++ if (codec && codec->pix_fmts) { ++ const enum PixelFormat *p = codec->pix_fmts; ++ int has_alpha= av_pix_fmt_descriptors[st->codec->pix_fmt].nb_components % 2 == 0; ++ enum PixelFormat best= PIX_FMT_NONE; ++ if (st->codec->strict_std_compliance <= FF_COMPLIANCE_UNOFFICIAL) { ++ if (st->codec->codec_id == CODEC_ID_MJPEG) { ++ p = (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE }; ++ } else if (st->codec->codec_id == CODEC_ID_LJPEG) { ++ p = (const enum PixelFormat[]) { PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUV420P, ++ PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_BGRA, PIX_FMT_NONE }; + } + } +- for(; *p!=-1; p++){ +- if(*p == st->codec->pix_fmt) ++ for (; *p != PIX_FMT_NONE; p++) { ++ best= avcodec_find_best_pix_fmt2(best, *p, st->codec->pix_fmt, has_alpha, NULL); ++ if (*p == st->codec->pix_fmt) + break; + } +- if(*p == -1) +- st->codec->pix_fmt = codec->pix_fmts[0]; ++ if (*p == PIX_FMT_NONE) { ++ if (st->codec->pix_fmt != PIX_FMT_NONE) ++ av_log(NULL, AV_LOG_WARNING, ++ "Incompatible pixel format '%s' for codec '%s', auto-selecting format '%s'\n", ++ av_pix_fmt_descriptors[st->codec->pix_fmt].name, ++ codec->name, ++ av_pix_fmt_descriptors[best].name); ++ st->codec->pix_fmt = best; ++ } + } + } + +-static AVOutputStream *new_output_stream(AVFormatContext *oc, int file_idx) ++static double get_sync_ipts(const OutputStream *ost) + { +- int idx = oc->nb_streams - 1; +- AVOutputStream *ost; +- +- output_streams_for_file[file_idx] = +- grow_array(output_streams_for_file[file_idx], +- sizeof(*output_streams_for_file[file_idx]), +- &nb_output_streams_for_file[file_idx], +- oc->nb_streams); +- ost = output_streams_for_file[file_idx][idx] = +- av_mallocz(sizeof(AVOutputStream)); +- if (!ost) { +- fprintf(stderr, "Could not alloc output stream\n"); +- ffmpeg_exit(1); +- } +- ost->file_index = file_idx; +- ost->index = idx; +- return ost; ++ const InputStream *ist = ost->sync_ist; ++ OutputFile *of = &output_files[ost->file_index]; ++ return (double)(ist->pts - of->start_time) / AV_TIME_BASE; + } + +-static int read_ffserver_streams(AVFormatContext *s, const char *filename) ++static void write_frame(AVFormatContext *s, AVPacket *pkt, OutputStream *ost) + { +- int i, err; +- AVFormatContext *ic; +- int nopts = 0; +- +- err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL); +- if (err < 0) +- return err; +- /* copy stream format */ +- s->nb_streams = 0; +- for(i=0;inb_streams;i++) { +- AVStream *st; +- AVCodec *codec; +- +- s->nb_streams++; ++ AVBitStreamFilterContext *bsfc = ost->bitstream_filters; ++ AVCodecContext *avctx = ost->st->codec; ++ int ret; + +- // FIXME: a more elegant solution is needed +- st = av_mallocz(sizeof(AVStream)); +- memcpy(st, ic->streams[i], sizeof(AVStream)); +- st->codec = avcodec_alloc_context(); +- if (!st->codec) { +- print_error(filename, AVERROR(ENOMEM)); +- ffmpeg_exit(1); +- } +- avcodec_copy_context(st->codec, ic->streams[i]->codec); +- s->streams[i] = st; ++ /* ++ * Audio encoders may split the packets -- #frames in != #packets out. ++ * But there is no reordering, so we can limit the number of output packets ++ * by simply dropping them here. ++ * Counting encoded video frames needs to be done separately because of ++ * reordering, see do_video_out() ++ */ ++ if (!(avctx->codec_type == AVMEDIA_TYPE_VIDEO && avctx->codec)) { ++ if (ost->frame_number >= ost->max_frames) ++ return; ++ ost->frame_number++; ++ } + +- codec = avcodec_find_encoder(st->codec->codec_id); +- if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- if (audio_stream_copy) { +- st->stream_copy = 1; +- } else +- choose_sample_fmt(st, codec); +- } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- if (video_stream_copy) { +- st->stream_copy = 1; +- } else +- choose_pixel_fmt(st, codec); ++ while (bsfc) { ++ AVPacket new_pkt = *pkt; ++ int a = av_bitstream_filter_filter(bsfc, avctx, NULL, ++ &new_pkt.data, &new_pkt.size, ++ pkt->data, pkt->size, ++ pkt->flags & AV_PKT_FLAG_KEY); ++ if (a > 0) { ++ av_free_packet(pkt); ++ new_pkt.destruct = av_destruct_packet; ++ } else if (a < 0) { ++ av_log(NULL, AV_LOG_ERROR, "Failed to open bitstream filter %s for stream %d with codec %s", ++ bsfc->filter->name, pkt->stream_index, ++ avctx->codec ? avctx->codec->name : "copy"); ++ print_error("", a); ++ if (exit_on_error) ++ exit_program(1); + } ++ *pkt = new_pkt; + +- if(!st->codec->thread_count) +- st->codec->thread_count = 1; +- if(st->codec->thread_count>1) +- avcodec_thread_init(st->codec, st->codec->thread_count); +- +- if(st->codec->flags & CODEC_FLAG_BITEXACT) +- nopts = 1; +- +- new_output_stream(s, nb_output_files); ++ bsfc = bsfc->next; + } + +- if (!nopts) +- s->timestamp = av_gettime(); +- +- av_close_input_file(ic); +- return 0; ++ ret = av_interleaved_write_frame(s, pkt); ++ if (ret < 0) { ++ print_error("av_interleaved_write_frame()", ret); ++ exit_program(1); ++ } + } + +-static double +-get_sync_ipts(const AVOutputStream *ost) ++static void generate_silence(uint8_t* buf, enum AVSampleFormat sample_fmt, size_t size) + { +- const AVInputStream *ist = ost->sync_ist; +- return (double)(ist->pts - start_time)/AV_TIME_BASE; ++ int fill_char = 0x00; ++ if (sample_fmt == AV_SAMPLE_FMT_U8) ++ fill_char = 0x80; ++ memset(buf, fill_char, size); + } + +-static void write_frame(AVFormatContext *s, AVPacket *pkt, AVCodecContext *avctx, AVBitStreamFilterContext *bsfc){ +- int ret; ++static int encode_audio_frame(AVFormatContext *s, OutputStream *ost, ++ const uint8_t *buf, int buf_size) ++{ ++ AVCodecContext *enc = ost->st->codec; ++ AVFrame *frame = NULL; ++ AVPacket pkt; ++ int ret, got_packet; + +- while(bsfc){ +- AVPacket new_pkt= *pkt; +- int a= av_bitstream_filter_filter(bsfc, avctx, NULL, +- &new_pkt.data, &new_pkt.size, +- pkt->data, pkt->size, +- pkt->flags & AV_PKT_FLAG_KEY); +- if(a>0){ +- av_free_packet(pkt); +- new_pkt.destruct= av_destruct_packet; +- } else if(a<0){ +- fprintf(stderr, "%s failed for stream %d, codec %s", +- bsfc->filter->name, pkt->stream_index, +- avctx->codec ? avctx->codec->name : "copy"); +- print_error("", a); +- if (exit_on_error) +- ffmpeg_exit(1); ++ av_init_packet(&pkt); ++ pkt.data = NULL; ++ pkt.size = 0; ++ ++ if (buf) { ++ if (!ost->output_frame) { ++ ost->output_frame = avcodec_alloc_frame(); ++ if (!ost->output_frame) { ++ av_log(NULL, AV_LOG_FATAL, "out-of-memory in encode_audio_frame()\n"); ++ exit_program(1); ++ } + } +- *pkt= new_pkt; ++ frame = ost->output_frame; ++ if (frame->extended_data != frame->data) ++ av_freep(&frame->extended_data); ++ avcodec_get_frame_defaults(frame); + +- bsfc= bsfc->next; ++ frame->nb_samples = buf_size / ++ (enc->channels * av_get_bytes_per_sample(enc->sample_fmt)); ++ if ((ret = avcodec_fill_audio_frame(frame, enc->channels, enc->sample_fmt, ++ buf, buf_size, 1)) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); ++ exit_program(1); ++ } + } + +- ret= av_interleaved_write_frame(s, pkt); +- if(ret < 0){ +- print_error("av_interleaved_write_frame()", ret); +- ffmpeg_exit(1); ++ got_packet = 0; ++ if (avcodec_encode_audio2(enc, &pkt, frame, &got_packet) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Audio encoding failed\n"); ++ exit_program(1); + } +-} + +-#define MAX_AUDIO_PACKET_SIZE (128 * 1024) ++ ret = pkt.size; ++ ++ if (got_packet) { ++ pkt.stream_index = ost->index; ++ if (pkt.pts != AV_NOPTS_VALUE) ++ pkt.pts = av_rescale_q(pkt.pts, enc->time_base, ost->st->time_base); ++ if (pkt.duration > 0) ++ pkt.duration = av_rescale_q(pkt.duration, enc->time_base, ost->st->time_base); ++ ++ write_frame(s, &pkt, ost); ++ ++ audio_size += pkt.size; ++ ++ av_free_packet(&pkt); ++ } ++ ++ if (frame) ++ ost->sync_opts += frame->nb_samples; ++ ++ return ret; ++} + +-static void do_audio_out(AVFormatContext *s, +- AVOutputStream *ost, +- AVInputStream *ist, +- unsigned char *buf, int size) ++static void do_audio_out(AVFormatContext *s, OutputStream *ost, ++ InputStream *ist, AVFrame *decoded_frame) + { + uint8_t *buftmp; +- int64_t audio_out_size, audio_buf_size; +- int64_t allocated_for_size= size; ++ int64_t audio_buf_size, size_out; + +- int size_out, frame_bytes, ret, resample_changed; +- AVCodecContext *enc= ost->st->codec; +- AVCodecContext *dec= ist->st->codec; +- int osize= av_get_bits_per_sample_fmt(enc->sample_fmt)/8; +- int isize= av_get_bits_per_sample_fmt(dec->sample_fmt)/8; +- const int coded_bps = av_get_bits_per_sample(enc->codec->id); ++ int frame_bytes, resample_changed; ++ AVCodecContext *enc = ost->st->codec; ++ AVCodecContext *dec = ist->st->codec; ++ int osize = av_get_bytes_per_sample(enc->sample_fmt); ++ int isize = av_get_bytes_per_sample(dec->sample_fmt); ++ uint8_t *buf = decoded_frame->data[0]; ++ int size = decoded_frame->nb_samples * dec->channels * isize; ++ int64_t allocated_for_size = size; + + need_realloc: +- audio_buf_size= (allocated_for_size + isize*dec->channels - 1) / (isize*dec->channels); +- audio_buf_size= (audio_buf_size*enc->sample_rate + dec->sample_rate) / dec->sample_rate; +- audio_buf_size= audio_buf_size*2 + 10000; //safety factors for the deprecated resampling API +- audio_buf_size= FFMAX(audio_buf_size, enc->frame_size); +- audio_buf_size*= osize*enc->channels; +- +- audio_out_size= FFMAX(audio_buf_size, enc->frame_size * osize * enc->channels); +- if(coded_bps > 8*osize) +- audio_out_size= audio_out_size * coded_bps / (8*osize); +- audio_out_size += FF_MIN_BUFFER_SIZE; +- +- if(audio_out_size > INT_MAX || audio_buf_size > INT_MAX){ +- fprintf(stderr, "Buffer sizes too large\n"); +- ffmpeg_exit(1); ++ audio_buf_size = (allocated_for_size + isize * dec->channels - 1) / (isize * dec->channels); ++ audio_buf_size = (audio_buf_size * enc->sample_rate + dec->sample_rate) / dec->sample_rate; ++ audio_buf_size = audio_buf_size * 2 + 10000; // safety factors for the deprecated resampling API ++ audio_buf_size = FFMAX(audio_buf_size, enc->frame_size); ++ audio_buf_size *= osize * enc->channels; ++ ++ if (audio_buf_size > INT_MAX) { ++ av_log(NULL, AV_LOG_FATAL, "Buffer sizes too large\n"); ++ exit_program(1); + } + + av_fast_malloc(&audio_buf, &allocated_audio_buf_size, audio_buf_size); +- av_fast_malloc(&audio_out, &allocated_audio_out_size, audio_out_size); +- if (!audio_buf || !audio_out){ +- fprintf(stderr, "Out of memory in do_audio_out\n"); +- ffmpeg_exit(1); ++ if (!audio_buf) { ++ av_log(NULL, AV_LOG_FATAL, "Out of memory in do_audio_out\n"); ++ exit_program(1); + } + +- if (enc->channels != dec->channels) ++ if (enc->channels != dec->channels ++ || enc->sample_fmt != dec->sample_fmt ++ || enc->sample_rate!= dec->sample_rate ++ ) + ost->audio_resample = 1; + + resample_changed = ost->resample_sample_fmt != dec->sample_fmt || + ost->resample_channels != dec->channels || + ost->resample_sample_rate != dec->sample_rate; + +- if ((ost->audio_resample && !ost->resample) || resample_changed) { ++ if ((ost->audio_resample && !ost->swr) || resample_changed || ost->audio_channels_mapped) { + if (resample_changed) { +- av_log(NULL, AV_LOG_INFO, "Input stream #%d.%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n", +- ist->file_index, ist->index, ++ av_log(NULL, AV_LOG_INFO, "Input stream #%d:%d frame changed from rate:%d fmt:%s ch:%d to rate:%d fmt:%s ch:%d\n", ++ ist->file_index, ist->st->index, + ost->resample_sample_rate, av_get_sample_fmt_name(ost->resample_sample_fmt), ost->resample_channels, + dec->sample_rate, av_get_sample_fmt_name(dec->sample_fmt), dec->channels); + ost->resample_sample_fmt = dec->sample_fmt; + ost->resample_channels = dec->channels; + ost->resample_sample_rate = dec->sample_rate; +- if (ost->resample) +- audio_resample_close(ost->resample); ++ swr_free(&ost->swr); + } + /* if audio_sync_method is >1 the resampler is needed for audio drift compensation */ +- if (audio_sync_method <= 1 && ++ if (audio_sync_method <= 1 && !ost->audio_channels_mapped && + ost->resample_sample_fmt == enc->sample_fmt && + ost->resample_channels == enc->channels && + ost->resample_sample_rate == enc->sample_rate) { +- ost->resample = NULL; ++ //ost->swr = NULL; + ost->audio_resample = 0; + } else { +- if (dec->sample_fmt != AV_SAMPLE_FMT_S16) +- fprintf(stderr, "Warning, using s16 intermediate sample format for resampling\n"); +- ost->resample = av_audio_resample_init(enc->channels, dec->channels, +- enc->sample_rate, dec->sample_rate, +- enc->sample_fmt, dec->sample_fmt, +- 16, 10, 0, 0.8); +- if (!ost->resample) { +- fprintf(stderr, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", ++ ost->swr = swr_alloc_set_opts(ost->swr, ++ enc->channel_layout, enc->sample_fmt, enc->sample_rate, ++ dec->channel_layout, dec->sample_fmt, dec->sample_rate, ++ 0, NULL); ++ if (ost->audio_channels_mapped) ++ swr_set_channel_mapping(ost->swr, ost->audio_channels_map); ++ av_opt_set_double(ost->swr, "rmvol", ost->rematrix_volume, 0); ++ if (ost->audio_channels_mapped) { ++ av_opt_set_int(ost->swr, "icl", av_get_default_channel_layout(ost->audio_channels_mapped), 0); ++ av_opt_set_int(ost->swr, "uch", ost->audio_channels_mapped, 0); ++ } ++ if (av_opt_set_int(ost->swr, "ich", dec->channels, 0) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Unsupported number of input channels\n"); ++ exit_program(1); ++ } ++ if (av_opt_set_int(ost->swr, "och", enc->channels, 0) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Unsupported number of output channels\n"); ++ exit_program(1); ++ } ++ if(audio_sync_method>1) av_opt_set_int(ost->swr, "flags", SWR_FLAG_RESAMPLE, 0); ++ if(ost->swr && swr_init(ost->swr) < 0){ ++ av_log(NULL, AV_LOG_FATAL, "swr_init() failed\n"); ++ swr_free(&ost->swr); ++ } ++ ++ if (!ost->swr) { ++ av_log(NULL, AV_LOG_FATAL, "Can not resample %d channels @ %d Hz to %d channels @ %d Hz\n", + dec->channels, dec->sample_rate, + enc->channels, enc->sample_rate); +- ffmpeg_exit(1); ++ exit_program(1); + } + } + } + +-#define MAKE_SFMT_PAIR(a,b) ((a)+AV_SAMPLE_FMT_NB*(b)) +- if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt && +- MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt)!=ost->reformat_pair) { +- if (ost->reformat_ctx) +- av_audio_convert_free(ost->reformat_ctx); +- ost->reformat_ctx = av_audio_convert_alloc(enc->sample_fmt, 1, +- dec->sample_fmt, 1, NULL, 0); +- if (!ost->reformat_ctx) { +- fprintf(stderr, "Cannot convert %s sample format to %s sample format\n", +- av_get_sample_fmt_name(dec->sample_fmt), +- av_get_sample_fmt_name(enc->sample_fmt)); +- ffmpeg_exit(1); +- } +- ost->reformat_pair=MAKE_SFMT_PAIR(enc->sample_fmt,dec->sample_fmt); +- } +- +- if(audio_sync_method){ +- double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts +- - av_fifo_size(ost->fifo)/(enc->channels * 2); +- double idelta= delta*dec->sample_rate / enc->sample_rate; +- int byte_delta= ((int)idelta)*2*dec->channels; +- +- //FIXME resample delay +- if(fabs(delta) > 50){ +- if(ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate){ +- if(byte_delta < 0){ +- byte_delta= FFMAX(byte_delta, -size); ++ av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt); ++ ++ if (audio_sync_method) { ++ double delta = get_sync_ipts(ost) * enc->sample_rate - ost->sync_opts - ++ av_fifo_size(ost->fifo) / (enc->channels * osize); ++ int idelta = delta * dec->sample_rate / enc->sample_rate; ++ int byte_delta = idelta * isize * dec->channels; ++ ++ // FIXME resample delay ++ if (fabs(delta) > 50) { ++ if (ist->is_start || fabs(delta) > audio_drift_threshold*enc->sample_rate) { ++ if (byte_delta < 0) { ++ byte_delta = FFMAX(byte_delta, -size); + size += byte_delta; + buf -= byte_delta; +- if(verbose > 2) +- fprintf(stderr, "discarding %d audio samples\n", (int)-delta); +- if(!size) ++ av_log(NULL, AV_LOG_VERBOSE, "discarding %d audio samples\n", ++ -byte_delta / (isize * dec->channels)); ++ if (!size) + return; +- ist->is_start=0; +- }else{ +- static uint8_t *input_tmp= NULL; +- input_tmp= av_realloc(input_tmp, byte_delta + size); ++ ist->is_start = 0; ++ } else { ++ input_tmp = av_realloc(input_tmp, byte_delta + size); + +- if(byte_delta > allocated_for_size - size){ +- allocated_for_size= byte_delta + (int64_t)size; ++ if (byte_delta > allocated_for_size - size) { ++ allocated_for_size = byte_delta + (int64_t)size; + goto need_realloc; + } +- ist->is_start=0; ++ ist->is_start = 0; + +- memset(input_tmp, 0, byte_delta); ++ generate_silence(input_tmp, dec->sample_fmt, byte_delta); + memcpy(input_tmp + byte_delta, buf, size); +- buf= input_tmp; ++ buf = input_tmp; + size += byte_delta; +- if(verbose > 2) +- fprintf(stderr, "adding %d audio samples of silence\n", (int)delta); ++ av_log(NULL, AV_LOG_VERBOSE, "adding %d audio samples of silence\n", idelta); + } +- }else if(audio_sync_method>1){ +- int comp= av_clip(delta, -audio_sync_method, audio_sync_method); ++ } else if (audio_sync_method > 1) { ++ int comp = av_clip(delta, -audio_sync_method, audio_sync_method); + av_assert0(ost->audio_resample); +- if(verbose > 2) +- fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate); ++ av_log(NULL, AV_LOG_VERBOSE, "compensating audio timestamp drift:%f compensation:%d in:%d\n", ++ delta, comp, enc->sample_rate); + // fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2)); +- av_resample_compensate(*(struct AVResampleContext**)ost->resample, comp, enc->sample_rate); ++ swr_set_compensation(ost->swr, comp, enc->sample_rate); + } + } +- }else +- ost->sync_opts= lrintf(get_sync_ipts(ost) * enc->sample_rate) +- - av_fifo_size(ost->fifo)/(enc->channels * 2); //FIXME wrong ++ } else ++ ost->sync_opts = lrintf(get_sync_ipts(ost) * enc->sample_rate) - ++ av_fifo_size(ost->fifo) / (enc->channels * osize); // FIXME wrong + + if (ost->audio_resample) { + buftmp = audio_buf; +- size_out = audio_resample(ost->resample, +- (short *)buftmp, (short *)buf, +- size / (dec->channels * isize)); ++ size_out = swr_convert(ost->swr, ( uint8_t*[]){buftmp}, audio_buf_size / (enc->channels * osize), ++ (const uint8_t*[]){buf }, size / (dec->channels * isize)); + size_out = size_out * enc->channels * osize; + } else { + buftmp = buf; + size_out = size; + } + +- if (!ost->audio_resample && dec->sample_fmt!=enc->sample_fmt) { +- const void *ibuf[6]= {buftmp}; +- void *obuf[6]= {audio_buf}; +- int istride[6]= {isize}; +- int ostride[6]= {osize}; +- int len= size_out/istride[0]; +- if (av_audio_convert(ost->reformat_ctx, obuf, ostride, ibuf, istride, len)<0) { +- printf("av_audio_convert() failed\n"); +- if (exit_on_error) +- ffmpeg_exit(1); +- return; +- } +- buftmp = audio_buf; +- size_out = len*osize; +- } ++ av_assert0(ost->audio_resample || dec->sample_fmt==enc->sample_fmt); + + /* now encode as many frames as possible */ +- if (enc->frame_size > 1) { ++ if (!(enc->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) { + /* output resampled raw samples */ + if (av_fifo_realloc2(ost->fifo, av_fifo_size(ost->fifo) + size_out) < 0) { +- fprintf(stderr, "av_fifo_realloc2() failed\n"); +- ffmpeg_exit(1); ++ av_log(NULL, AV_LOG_FATAL, "av_fifo_realloc2() failed\n"); ++ exit_program(1); + } + av_fifo_generic_write(ost->fifo, buftmp, size_out, NULL); + + frame_bytes = enc->frame_size * osize * enc->channels; + + while (av_fifo_size(ost->fifo) >= frame_bytes) { +- AVPacket pkt; +- av_init_packet(&pkt); +- + av_fifo_generic_read(ost->fifo, audio_buf, frame_bytes, NULL); +- +- //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() +- +- ret = avcodec_encode_audio(enc, audio_out, audio_out_size, +- (short *)audio_buf); +- if (ret < 0) { +- fprintf(stderr, "Audio encoding failed\n"); +- ffmpeg_exit(1); +- } +- audio_size += ret; +- pkt.stream_index= ost->index; +- pkt.data= audio_out; +- pkt.size= ret; +- if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); +- pkt.flags |= AV_PKT_FLAG_KEY; +- write_frame(s, &pkt, enc, ost->bitstream_filters); +- +- ost->sync_opts += enc->frame_size; ++ encode_audio_frame(s, ost, audio_buf, frame_bytes); + } + } else { +- AVPacket pkt; +- av_init_packet(&pkt); +- +- ost->sync_opts += size_out / (osize * enc->channels); +- +- /* output a pcm frame */ +- /* determine the size of the coded buffer */ +- size_out /= osize; +- if (coded_bps) +- size_out = size_out*coded_bps/8; +- +- if(size_out > audio_out_size){ +- fprintf(stderr, "Internal error, buffer size too small\n"); +- ffmpeg_exit(1); +- } +- +- //FIXME pass ost->sync_opts as AVFrame.pts in avcodec_encode_audio() +- ret = avcodec_encode_audio(enc, audio_out, size_out, +- (short *)buftmp); +- if (ret < 0) { +- fprintf(stderr, "Audio encoding failed\n"); +- ffmpeg_exit(1); +- } +- audio_size += ret; +- pkt.stream_index= ost->index; +- pkt.data= audio_out; +- pkt.size= ret; +- if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); +- pkt.flags |= AV_PKT_FLAG_KEY; +- write_frame(s, &pkt, enc, ost->bitstream_filters); ++ encode_audio_frame(s, ost, buftmp, size_out); + } + } + +-static void pre_process_video_frame(AVInputStream *ist, AVPicture *picture, void **bufp) ++static void pre_process_video_frame(InputStream *ist, AVPicture *picture, void **bufp) + { + AVCodecContext *dec; + AVPicture *picture2; +@@ -1031,17 +1293,17 @@ + + /* create temporary picture */ + size = avpicture_get_size(dec->pix_fmt, dec->width, dec->height); +- buf = av_malloc(size); ++ buf = av_malloc(size); + if (!buf) + return; + + picture2 = &picture_tmp; + avpicture_fill(picture2, buf, dec->pix_fmt, dec->width, dec->height); + +- if(avpicture_deinterlace(picture2, picture, ++ if (avpicture_deinterlace(picture2, picture, + dec->pix_fmt, dec->width, dec->height) < 0) { + /* if error, do not deinterlace */ +- fprintf(stderr, "Deinterlacing failed\n"); ++ av_log(NULL, AV_LOG_WARNING, "Deinterlacing failed\n"); + av_free(buf); + buf = NULL; + picture2 = picture; +@@ -1055,12 +1317,9 @@ + *bufp = buf; + } + +-/* we begin to correct av delay at this threshold */ +-#define AV_DELAY_MAX 0.100 +- + static void do_subtitle_out(AVFormatContext *s, +- AVOutputStream *ost, +- AVInputStream *ist, ++ OutputStream *ost, ++ InputStream *ist, + AVSubtitle *sub, + int64_t pts) + { +@@ -1071,9 +1330,9 @@ + AVPacket pkt; + + if (pts == AV_NOPTS_VALUE) { +- fprintf(stderr, "Subtitle packets must have a pts\n"); ++ av_log(NULL, AV_LOG_ERROR, "Subtitle packets must have a pts\n"); + if (exit_on_error) +- ffmpeg_exit(1); ++ exit_program(1); + return; + } + +@@ -1091,24 +1350,24 @@ + else + nb = 1; + +- for(i = 0; i < nb; i++) { ++ for (i = 0; i < nb; i++) { + sub->pts = av_rescale_q(pts, ist->st->time_base, AV_TIME_BASE_Q); + // start_display_time is required to be 0 +- sub->pts += av_rescale_q(sub->start_display_time, (AVRational){1, 1000}, AV_TIME_BASE_Q); +- sub->end_display_time -= sub->start_display_time; ++ sub->pts += av_rescale_q(sub->start_display_time, (AVRational){ 1, 1000 }, AV_TIME_BASE_Q); ++ sub->end_display_time -= sub->start_display_time; + sub->start_display_time = 0; + subtitle_out_size = avcodec_encode_subtitle(enc, subtitle_out, + subtitle_out_max_size, sub); + if (subtitle_out_size < 0) { +- fprintf(stderr, "Subtitle encoding failed\n"); +- ffmpeg_exit(1); ++ av_log(NULL, AV_LOG_FATAL, "Subtitle encoding failed\n"); ++ exit_program(1); + } + + av_init_packet(&pkt); + pkt.stream_index = ost->index; + pkt.data = subtitle_out; + pkt.size = subtitle_out_size; +- pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base); ++ pkt.pts = av_rescale_q(sub->pts, AV_TIME_BASE_Q, ost->st->time_base); + if (enc->codec_id == CODEC_ID_DVB_SUBTITLE) { + /* XXX: the pts correction is handled here. Maybe handling + it in the codec would be better */ +@@ -1117,26 +1376,94 @@ + else + pkt.pts += 90 * sub->end_display_time; + } +- write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); ++ write_frame(s, &pkt, ost); ++ } ++} ++ ++static int bit_buffer_size = 1024 * 256; ++static uint8_t *bit_buffer = NULL; ++ ++static void do_video_resample(OutputStream *ost, ++ InputStream *ist, ++ AVFrame *in_picture, ++ AVFrame **out_picture) ++{ ++#if CONFIG_AVFILTER ++ *out_picture = in_picture; ++#else ++ AVCodecContext *dec = ist->st->codec; ++ AVCodecContext *enc = ost->st->codec; ++ int resample_changed = ost->resample_width != in_picture->width || ++ ost->resample_height != in_picture->height || ++ ost->resample_pix_fmt != in_picture->format; ++ ++ *out_picture = in_picture; ++ if (resample_changed) { ++ av_log(NULL, AV_LOG_INFO, ++ "Input stream #%d:%d frame changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s / frm size:%dx%d fmt:%s\n", ++ ist->file_index, ist->st->index, ++ ost->resample_width, ost->resample_height, av_get_pix_fmt_name(ost->resample_pix_fmt), ++ dec->width , dec->height , av_get_pix_fmt_name(dec->pix_fmt), ++ in_picture->width, in_picture->height, av_get_pix_fmt_name(in_picture->format)); ++ ost->resample_width = in_picture->width; ++ ost->resample_height = in_picture->height; ++ ost->resample_pix_fmt = in_picture->format; ++ } ++ ++ ost->video_resample = in_picture->width != enc->width || ++ in_picture->height != enc->height || ++ in_picture->format != enc->pix_fmt; ++ ++ if (ost->video_resample) { ++ *out_picture = &ost->resample_frame; ++ if (!ost->img_resample_ctx || resample_changed) { ++ /* initialize the destination picture */ ++ if (!ost->resample_frame.data[0]) { ++ avcodec_get_frame_defaults(&ost->resample_frame); ++ if (avpicture_alloc((AVPicture *)&ost->resample_frame, enc->pix_fmt, ++ enc->width, enc->height)) { ++ av_log(NULL, AV_LOG_FATAL, "Cannot allocate temp picture, check pix fmt\n"); ++ exit_program(1); ++ } ++ } ++ /* initialize a new scaler context */ ++ sws_freeContext(ost->img_resample_ctx); ++ ost->img_resample_ctx = sws_getContext(in_picture->width, in_picture->height, in_picture->format, ++ enc->width, enc->height, enc->pix_fmt, ++ ost->sws_flags, NULL, NULL, NULL); ++ if (ost->img_resample_ctx == NULL) { ++ av_log(NULL, AV_LOG_FATAL, "Cannot get resampling context\n"); ++ exit_program(1); ++ } ++ } ++ sws_scale(ost->img_resample_ctx, in_picture->data, in_picture->linesize, ++ 0, ost->resample_height, (*out_picture)->data, (*out_picture)->linesize); + } ++#endif + } + +-static int bit_buffer_size= 1024*256; +-static uint8_t *bit_buffer= NULL; + + static void do_video_out(AVFormatContext *s, +- AVOutputStream *ost, +- AVInputStream *ist, ++ OutputStream *ost, ++ InputStream *ist, + AVFrame *in_picture, +- int *frame_size) ++ int *frame_size, float quality) + { +- int nb_frames, i, ret; +- AVFrame *final_picture, *formatted_picture, *resampling_dst, *padding_src; +- AVCodecContext *enc, *dec; ++ int nb_frames, i, ret, format_video_sync; ++ AVFrame *final_picture; ++ AVCodecContext *enc; + double sync_ipts; ++ double duration = 0; + + enc = ost->st->codec; +- dec = ist->st->codec; ++ ++ if (ist->st->start_time != AV_NOPTS_VALUE && ist->st->first_dts != AV_NOPTS_VALUE) { ++ duration = FFMAX(av_q2d(ist->st->time_base), av_q2d(ist->st->codec->time_base)); ++ if(ist->st->avg_frame_rate.num) ++ duration= FFMAX(duration, 1/av_q2d(ist->st->avg_frame_rate)); ++ ++ duration /= av_q2d(enc->time_base); ++ } + + sync_ipts = get_sync_ipts(ost) / av_q2d(enc->time_base); + +@@ -1145,149 +1472,110 @@ + + *frame_size = 0; + +- if(video_sync_method){ +- double vdelta = sync_ipts - ost->sync_opts; +- //FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c ++ format_video_sync = video_sync_method; ++ if (format_video_sync == VSYNC_AUTO) ++ format_video_sync = (s->oformat->flags & AVFMT_VARIABLE_FPS) ? ((s->oformat->flags & AVFMT_NOTIMESTAMPS) ? VSYNC_PASSTHROUGH : VSYNC_VFR) : 1; ++ ++ if (format_video_sync != VSYNC_PASSTHROUGH) { ++ double vdelta = sync_ipts - ost->sync_opts + duration; ++ // FIXME set to 0.5 after we fix some dts/pts bugs like in avidec.c + if (vdelta < -1.1) + nb_frames = 0; +- else if (video_sync_method == 2 || (video_sync_method<0 && (s->oformat->flags & AVFMT_VARIABLE_FPS))){ +- if(vdelta<=-0.6){ +- nb_frames=0; +- }else if(vdelta>0.6) +- ost->sync_opts= lrintf(sync_ipts); +- }else if (vdelta > 1.1) ++ else if (format_video_sync == VSYNC_VFR) { ++ if (vdelta <= -0.6) { ++ nb_frames = 0; ++ } else if (vdelta > 0.6) ++ ost->sync_opts = lrintf(sync_ipts); ++ } else if (vdelta > 1.1) + nb_frames = lrintf(vdelta); + //fprintf(stderr, "vdelta:%f, ost->sync_opts:%"PRId64", ost->sync_ipts:%f nb_frames:%d\n", vdelta, ost->sync_opts, get_sync_ipts(ost), nb_frames); +- if (nb_frames == 0){ ++ if (nb_frames == 0) { + ++nb_frames_drop; +- if (verbose>2) +- fprintf(stderr, "*** drop!\n"); +- }else if (nb_frames > 1) { ++ av_log(NULL, AV_LOG_VERBOSE, "*** drop!\n"); ++ } else if (nb_frames > 1) { + nb_frames_dup += nb_frames - 1; +- if (verbose>2) +- fprintf(stderr, "*** %d dup!\n", nb_frames-1); ++ av_log(NULL, AV_LOG_VERBOSE, "*** %d dup!\n", nb_frames - 1); + } +- }else +- ost->sync_opts= lrintf(sync_ipts); ++ } else ++ ost->sync_opts = lrintf(sync_ipts); + +- nb_frames= FFMIN(nb_frames, max_frames[AVMEDIA_TYPE_VIDEO] - ost->frame_number); ++ nb_frames = FFMIN(nb_frames, ost->max_frames - ost->frame_number); + if (nb_frames <= 0) + return; + +- formatted_picture = in_picture; +- final_picture = formatted_picture; +- padding_src = formatted_picture; +- resampling_dst = &ost->pict_tmp; +- +- if ( ost->resample_height != ist->st->codec->height +- || ost->resample_width != ist->st->codec->width +- || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) { +- +- fprintf(stderr,"Input Stream #%d.%d frame size changed to %dx%d, %s\n", ist->file_index, ist->index, ist->st->codec->width, ist->st->codec->height,avcodec_get_pix_fmt_name(ist->st->codec->pix_fmt)); +- if(!ost->video_resample) +- ffmpeg_exit(1); +- } +- +-#if !CONFIG_AVFILTER +- if (ost->video_resample) { +- padding_src = NULL; +- final_picture = &ost->pict_tmp; +- if( ost->resample_height != ist->st->codec->height +- || ost->resample_width != ist->st->codec->width +- || (ost->resample_pix_fmt!= ist->st->codec->pix_fmt) ) { +- +- /* initialize a new scaler context */ +- sws_freeContext(ost->img_resample_ctx); +- sws_flags = av_get_int(sws_opts, "sws_flags", NULL); +- ost->img_resample_ctx = sws_getContext( +- ist->st->codec->width, +- ist->st->codec->height, +- ist->st->codec->pix_fmt, +- ost->st->codec->width, +- ost->st->codec->height, +- ost->st->codec->pix_fmt, +- sws_flags, NULL, NULL, NULL); +- if (ost->img_resample_ctx == NULL) { +- fprintf(stderr, "Cannot get resampling context\n"); +- ffmpeg_exit(1); +- } +- } +- sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize, +- 0, ost->resample_height, resampling_dst->data, resampling_dst->linesize); +- } +-#endif ++ do_video_resample(ost, ist, in_picture, &final_picture); + + /* duplicates frame if needed */ +- for(i=0;iindex; ++ pkt.stream_index = ost->index; + +- if (s->oformat->flags & AVFMT_RAWPICTURE) { ++ if (s->oformat->flags & AVFMT_RAWPICTURE && ++ enc->codec->id == CODEC_ID_RAWVIDEO) { + /* raw pictures are written as AVPicture structure to +- avoid any copies. We support temorarily the older ++ avoid any copies. We support temporarily the older + method. */ +- AVFrame* old_frame = enc->coded_frame; +- enc->coded_frame = dec->coded_frame; //FIXME/XXX remove this hack +- pkt.data= (uint8_t *)final_picture; +- pkt.size= sizeof(AVPicture); +- pkt.pts= av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base); ++ enc->coded_frame->interlaced_frame = in_picture->interlaced_frame; ++ enc->coded_frame->top_field_first = in_picture->top_field_first; ++ pkt.data = (uint8_t *)final_picture; ++ pkt.size = sizeof(AVPicture); ++ pkt.pts = av_rescale_q(ost->sync_opts, enc->time_base, ost->st->time_base); + pkt.flags |= AV_PKT_FLAG_KEY; + +- write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); +- enc->coded_frame = old_frame; ++ write_frame(s, &pkt, ost); + } else { + AVFrame big_picture; + +- big_picture= *final_picture; ++ big_picture = *final_picture; + /* better than nothing: use input picture interlaced + settings */ + big_picture.interlaced_frame = in_picture->interlaced_frame; +- if(avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)){ +- if(top_field_first == -1) ++ if (ost->st->codec->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME)) { ++ if (ost->top_field_first == -1) + big_picture.top_field_first = in_picture->top_field_first; + else +- big_picture.top_field_first = top_field_first; ++ big_picture.top_field_first = !!ost->top_field_first; + } + +- /* handles sameq here. This is not correct because it may ++ /* handles same_quant here. This is not correct because it may + not be a global option */ +- big_picture.quality = same_quality ? ist->st->quality : ost->st->quality; +- if(!me_threshold) ++ big_picture.quality = quality; ++ if (!enc->me_threshold) + big_picture.pict_type = 0; + // big_picture.pts = AV_NOPTS_VALUE; +- big_picture.pts= ost->sync_opts; ++ big_picture.pts = ost->sync_opts; + // big_picture.pts= av_rescale(ost->sync_opts, AV_TIME_BASE*(int64_t)enc->time_base.num, enc->time_base.den); +-//av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts); ++// av_log(NULL, AV_LOG_DEBUG, "%"PRId64" -> encoder\n", ost->sync_opts); + if (ost->forced_kf_index < ost->forced_kf_count && + big_picture.pts >= ost->forced_kf_pts[ost->forced_kf_index]) { +- big_picture.pict_type = FF_I_TYPE; ++ big_picture.pict_type = AV_PICTURE_TYPE_I; + ost->forced_kf_index++; + } + ret = avcodec_encode_video(enc, + bit_buffer, bit_buffer_size, + &big_picture); + if (ret < 0) { +- fprintf(stderr, "Video encoding failed\n"); +- ffmpeg_exit(1); ++ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); ++ exit_program(1); + } + +- if(ret>0){ +- pkt.data= bit_buffer; +- pkt.size= ret; +- if(enc->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); ++ if (ret > 0) { ++ pkt.data = bit_buffer; ++ pkt.size = ret; ++ if (enc->coded_frame->pts != AV_NOPTS_VALUE) ++ pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); + /*av_log(NULL, AV_LOG_DEBUG, "encoder -> %"PRId64"/%"PRId64"\n", + pkt.pts != AV_NOPTS_VALUE ? av_rescale(pkt.pts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1, + pkt.dts != AV_NOPTS_VALUE ? av_rescale(pkt.dts, enc->time_base.den, AV_TIME_BASE*(int64_t)enc->time_base.num) : -1);*/ + +- if(enc->coded_frame->key_frame) ++ if (enc->coded_frame->key_frame) + pkt.flags |= AV_PKT_FLAG_KEY; +- write_frame(s, &pkt, ost->st->codec, ost->bitstream_filters); ++ write_frame(s, &pkt, ost); + *frame_size = ret; + video_size += ret; +- //fprintf(stderr,"\nFrame: %3d size: %5d type: %d", +- // enc->frame_number-1, ret, enc->pict_type); ++ // fprintf(stderr,"\nFrame: %3d size: %5d type: %d", ++ // enc->frame_number-1, ret, enc->pict_type); + /* if two pass, output log */ + if (ost->logfile && enc->stats_out) { + fprintf(ost->logfile, "%s", enc->stats_out); +@@ -1295,15 +1583,21 @@ + } + } + ost->sync_opts++; ++ /* ++ * For video, number of frames in == number of packets out. ++ * But there may be reordering, so we can't throw away frames on encoder ++ * flush, we need to limit them here, before they go into encoder. ++ */ + ost->frame_number++; + } + } + +-static double psnr(double d){ +- return -10.0*log(d)/log(10.0); ++static double psnr(double d) ++{ ++ return -10.0 * log(d) / log(10.0); + } + +-static void do_video_stats(AVFormatContext *os, AVOutputStream *ost, ++static void do_video_stats(AVFormatContext *os, OutputStream *ost, + int frame_size) + { + AVCodecContext *enc; +@@ -1315,16 +1609,16 @@ + vstats_file = fopen(vstats_filename, "w"); + if (!vstats_file) { + perror("fopen"); +- ffmpeg_exit(1); ++ exit_program(1); + } + } + + enc = ost->st->codec; + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { + frame_number = ost->frame_number; +- fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality/(float)FF_QP2LAMBDA); ++ fprintf(vstats_file, "frame= %5d q= %2.1f ", frame_number, enc->coded_frame->quality / (float)FF_QP2LAMBDA); + if (enc->flags&CODEC_FLAG_PSNR) +- fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0]/(enc->width*enc->height*255.0*255.0))); ++ fprintf(vstats_file, "PSNR= %6.2f ", psnr(enc->coded_frame->error[0] / (enc->width * enc->height * 255.0 * 255.0))); + + fprintf(vstats_file,"f_size= %6d ", frame_size); + /* compute pts value */ +@@ -1332,32 +1626,34 @@ + if (ti1 < 0.01) + ti1 = 0.01; + +- bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; ++ bitrate = (frame_size * 8) / av_q2d(enc->time_base) / 1000.0; + avg_bitrate = (double)(video_size * 8) / ti1 / 1000.0; + fprintf(vstats_file, "s_size= %8.0fkB time= %0.3f br= %7.1fkbits/s avg_br= %7.1fkbits/s ", +- (double)video_size / 1024, ti1, bitrate, avg_bitrate); +- fprintf(vstats_file,"type= %c\n", av_get_pict_type_char(enc->coded_frame->pict_type)); ++ (double)video_size / 1024, ti1, bitrate, avg_bitrate); ++ fprintf(vstats_file, "type= %c\n", av_get_picture_type_char(enc->coded_frame->pict_type)); + } + } + +-static void print_report(AVFormatContext **output_files, +- AVOutputStream **ost_table, int nb_ostreams, +- int is_last_report) ++static void print_report(OutputFile *output_files, ++ OutputStream *ost_table, int nb_ostreams, ++ int is_last_report, int64_t timer_start, int64_t cur_time) + { + char buf[1024]; +- AVOutputStream *ost; ++ OutputStream *ost; + AVFormatContext *oc; + int64_t total_size; + AVCodecContext *enc; + int frame_number, vid, i; +- double bitrate, ti1, pts; ++ double bitrate; ++ int64_t pts = INT64_MAX; + static int64_t last_time = -1; + static int qp_histogram[52]; ++ int hours, mins, secs, us; ++ ++ if (!print_stats && !is_last_report) ++ return; + + if (!is_last_report) { +- int64_t cur_time; +- /* display the report every 0.5 seconds */ +- cur_time = av_gettime(); + if (last_time == -1) { + last_time = cur_time; + return; +@@ -1368,953 +1664,1024 @@ + } + + +- oc = output_files[0]; ++ oc = output_files[0].ctx; + +- total_size = url_fsize(oc->pb); +- if(total_size<0) // FIXME improve url_fsize() so it works with non seekable output too +- total_size= url_ftell(oc->pb); ++ total_size = avio_size(oc->pb); ++ if (total_size < 0) { // FIXME improve avio_size() so it works with non seekable output too ++ total_size = avio_tell(oc->pb); ++ if (total_size < 0) ++ total_size = 0; ++ } + + buf[0] = '\0'; +- ti1 = 1e10; + vid = 0; +- for(i=0;ist->codec; ++ if (!ost->stream_copy && enc->coded_frame) ++ q = enc->coded_frame->quality / (float)FF_QP2LAMBDA; + if (vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", +- !ost->st->stream_copy ? +- enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "q=%2.1f ", q); + } + if (!vid && enc->codec_type == AVMEDIA_TYPE_VIDEO) { +- float t = (av_gettime()-timer_start) / 1000000.0; ++ float t = (cur_time-timer_start) / 1000000.0; + + frame_number = ost->frame_number; + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "frame=%5d fps=%3d q=%3.1f ", +- frame_number, (t>1)?(int)(frame_number/t+0.5) : 0, +- !ost->st->stream_copy ? +- enc->coded_frame->quality/(float)FF_QP2LAMBDA : -1); +- if(is_last_report) ++ frame_number, (t > 1) ? (int)(frame_number / t + 0.5) : 0, q); ++ if (is_last_report) + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "L"); +- if(qp_hist){ ++ if (qp_hist) { + int j; +- int qp= lrintf(enc->coded_frame->quality/(float)FF_QP2LAMBDA); +- if(qp>=0 && qp= 0 && qp < FF_ARRAY_ELEMS(qp_histogram)) + qp_histogram[qp]++; +- for(j=0; j<32; j++) +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j]+1)/log(2))); ++ for (j = 0; j < 32; j++) ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%X", (int)lrintf(log(qp_histogram[j] + 1) / log(2))); + } +- if (enc->flags&CODEC_FLAG_PSNR){ ++ if (enc->flags&CODEC_FLAG_PSNR) { + int j; +- double error, error_sum=0; +- double scale, scale_sum=0; +- char type[3]= {'Y','U','V'}; ++ double error, error_sum = 0; ++ double scale, scale_sum = 0; ++ char type[3] = { 'Y','U','V' }; + snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "PSNR="); +- for(j=0; j<3; j++){ +- if(is_last_report){ +- error= enc->error[j]; +- scale= enc->width*enc->height*255.0*255.0*frame_number; +- }else{ +- error= enc->coded_frame->error[j]; +- scale= enc->width*enc->height*255.0*255.0; ++ for (j = 0; j < 3; j++) { ++ if (is_last_report) { ++ error = enc->error[j]; ++ scale = enc->width * enc->height * 255.0 * 255.0 * frame_number; ++ } else { ++ error = enc->coded_frame->error[j]; ++ scale = enc->width * enc->height * 255.0 * 255.0; + } +- if(j) scale/=4; ++ if (j) ++ scale /= 4; + error_sum += error; + scale_sum += scale; +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error/scale)); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%c:%2.2f ", type[j], psnr(error / scale)); + } +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum/scale_sum)); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "*:%2.2f ", psnr(error_sum / scale_sum)); + } + vid = 1; + } + /* compute min output value */ +- pts = (double)ost->st->pts.val * av_q2d(ost->st->time_base); +- if ((pts < ti1) && (pts > 0)) +- ti1 = pts; ++ pts = FFMIN(pts, av_rescale_q(ost->st->pts.val, ++ ost->st->time_base, AV_TIME_BASE_Q)); + } +- if (ti1 < 0.01) +- ti1 = 0.01; + +- if (verbose || is_last_report) { +- bitrate = (double)(total_size * 8) / ti1 / 1000.0; ++ secs = pts / AV_TIME_BASE; ++ us = pts % AV_TIME_BASE; ++ mins = secs / 60; ++ secs %= 60; ++ hours = mins / 60; ++ mins %= 60; + +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), +- "size=%8.0fkB time=%0.2f bitrate=%6.1fkbits/s", +- (double)total_size / 1024, ti1, bitrate); ++ bitrate = pts ? total_size * 8 / (pts / 1000.0) : 0; + +- if (nb_frames_dup || nb_frames_drop) +- snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", +- nb_frames_dup, nb_frames_drop); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ++ "size=%8.0fkB time=", total_size / 1024.0); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ++ "%02d:%02d:%02d.%02d ", hours, mins, secs, ++ (100 * us) / AV_TIME_BASE); ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ++ "bitrate=%6.1fkbits/s", bitrate); + +- if (verbose >= 0) +- fprintf(stderr, "%s \r", buf); ++ if (nb_frames_dup || nb_frames_drop) ++ snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " dup=%d drop=%d", ++ nb_frames_dup, nb_frames_drop); + +- fflush(stderr); +- } ++ av_log(NULL, AV_LOG_INFO, "%s \r", buf); + +- if (is_last_report && verbose >= 0){ ++ fflush(stderr); ++ ++ if (is_last_report) { + int64_t raw= audio_size + video_size + extra_size; +- fprintf(stderr, "\n"); +- fprintf(stderr, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n", +- video_size/1024.0, +- audio_size/1024.0, +- extra_size/1024.0, +- 100.0*(total_size - raw)/raw ++ av_log(NULL, AV_LOG_INFO, "\n"); ++ av_log(NULL, AV_LOG_INFO, "video:%1.0fkB audio:%1.0fkB global headers:%1.0fkB muxing overhead %f%%\n", ++ video_size / 1024.0, ++ audio_size / 1024.0, ++ extra_size / 1024.0, ++ 100.0 * (total_size - raw) / raw + ); ++ if(video_size + audio_size + extra_size == 0){ ++ av_log(NULL, AV_LOG_WARNING, "Output file is empty, nothing was encoded (check -ss / -t / -frames parameters if used)\n"); ++ } + } + } + +-/* pkt = NULL means EOF (needed to flush decoder buffers) */ +-static int output_packet(AVInputStream *ist, int ist_index, +- AVOutputStream **ost_table, int nb_ostreams, +- const AVPacket *pkt) ++static void flush_encoders(OutputStream *ost_table, int nb_ostreams) + { +- AVFormatContext *os; +- AVOutputStream *ost; +- int ret, i; +- int got_picture; +- AVFrame picture; +- void *buffer_to_free; +- static unsigned int samples_size= 0; +- AVSubtitle subtitle, *subtitle_to_free; +- int64_t pkt_pts = AV_NOPTS_VALUE; +-#if CONFIG_AVFILTER +- int frame_available; +-#endif ++ int i, ret; + +- AVPacket avpkt; +- int bps = av_get_bits_per_sample_fmt(ist->st->codec->sample_fmt)>>3; ++ for (i = 0; i < nb_ostreams; i++) { ++ OutputStream *ost = &ost_table[i]; ++ AVCodecContext *enc = ost->st->codec; ++ AVFormatContext *os = output_files[ost->file_index].ctx; ++ int stop_encoding = 0; + +- if(ist->next_pts == AV_NOPTS_VALUE) +- ist->next_pts= ist->pts; +- +- if (pkt == NULL) { +- /* EOF handling */ +- av_init_packet(&avpkt); +- avpkt.data = NULL; +- avpkt.size = 0; +- goto handle_eof; +- } else { +- avpkt = *pkt; +- } +- +- if(pkt->dts != AV_NOPTS_VALUE) +- ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); +- if(pkt->pts != AV_NOPTS_VALUE) +- pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q); ++ if (!ost->encoding_needed) ++ continue; + +- //while we have more to decode or while the decoder did output something on EOF +- while (avpkt.size > 0 || (!pkt && ist->next_pts != ist->pts)) { +- uint8_t *data_buf, *decoded_data_buf; +- int data_size, decoded_data_size; +- handle_eof: +- ist->pts= ist->next_pts; ++ if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <= 1) ++ continue; ++ if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE) && enc->codec->id == CODEC_ID_RAWVIDEO) ++ continue; + +- if(avpkt.size && avpkt.size != pkt->size && +- ((!ist->showed_multi_packet_warning && verbose>0) || verbose>1)){ +- fprintf(stderr, "Multiple frames in a packet from stream %d\n", pkt->stream_index); +- ist->showed_multi_packet_warning=1; +- } ++ for (;;) { ++ AVPacket pkt; ++ int fifo_bytes; ++ av_init_packet(&pkt); ++ pkt.data = NULL; ++ pkt.size = 0; + +- /* decode the packet if needed */ +- decoded_data_buf = NULL; /* fail safe */ +- decoded_data_size= 0; +- data_buf = avpkt.data; +- data_size = avpkt.size; +- subtitle_to_free = NULL; +- if (ist->decoding_needed) { +- switch(ist->st->codec->codec_type) { +- case AVMEDIA_TYPE_AUDIO:{ +- if(pkt && samples_size < FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE)) { +- samples_size = FFMAX(pkt->size*sizeof(*samples), AVCODEC_MAX_AUDIO_FRAME_SIZE); +- av_free(samples); +- samples= av_malloc(samples_size); +- } +- decoded_data_size= samples_size; +- /* XXX: could avoid copy if PCM 16 bits with same +- endianness as CPU */ +- ret = avcodec_decode_audio3(ist->st->codec, samples, &decoded_data_size, +- &avpkt); +- if (ret < 0) +- goto fail_decode; +- avpkt.data += ret; +- avpkt.size -= ret; +- data_size = ret; +- /* Some bug in mpeg audio decoder gives */ +- /* decoded_data_size < 0, it seems they are overflows */ +- if (decoded_data_size <= 0) { +- /* no audio frame */ +- continue; +- } +- decoded_data_buf = (uint8_t *)samples; +- ist->next_pts += ((int64_t)AV_TIME_BASE/bps * decoded_data_size) / +- (ist->st->codec->sample_rate * ist->st->codec->channels); +- break;} +- case AVMEDIA_TYPE_VIDEO: +- decoded_data_size = (ist->st->codec->width * ist->st->codec->height * 3) / 2; +- /* XXX: allocate picture correctly */ +- avcodec_get_frame_defaults(&picture); +- ist->st->codec->reordered_opaque = pkt_pts; +- pkt_pts = AV_NOPTS_VALUE; +- +- ret = avcodec_decode_video2(ist->st->codec, +- &picture, &got_picture, &avpkt); +- ist->st->quality= picture.quality; +- if (ret < 0) +- goto fail_decode; +- if (!got_picture) { +- /* no picture yet */ +- goto discard_packet; ++ switch (ost->st->codec->codec_type) { ++ case AVMEDIA_TYPE_AUDIO: ++ fifo_bytes = av_fifo_size(ost->fifo); ++ if (fifo_bytes > 0) { ++ /* encode any samples remaining in fifo */ ++ int frame_bytes = fifo_bytes; ++ ++ av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL); ++ ++ /* pad last frame with silence if needed */ ++ if (!(enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME)) { ++ frame_bytes = enc->frame_size * enc->channels * ++ av_get_bytes_per_sample(enc->sample_fmt); ++ if (allocated_audio_buf_size < frame_bytes) ++ exit_program(1); ++ generate_silence(audio_buf+fifo_bytes, enc->sample_fmt, frame_bytes - fifo_bytes); + } +- ist->next_pts = ist->pts = guess_correct_pts(&ist->pts_ctx, picture.reordered_opaque, ist->pts); +- if (ist->st->codec->time_base.num != 0) { +- int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; +- ist->next_pts += ((int64_t)AV_TIME_BASE * +- ist->st->codec->time_base.num * ticks) / +- ist->st->codec->time_base.den; ++ encode_audio_frame(os, ost, audio_buf, frame_bytes); ++ } else { ++ /* flush encoder with NULL frames until it is done ++ returning packets */ ++ if (encode_audio_frame(os, ost, NULL, 0) == 0) { ++ stop_encoding = 1; ++ break; + } +- avpkt.size = 0; +- break; +- case AVMEDIA_TYPE_SUBTITLE: +- ret = avcodec_decode_subtitle2(ist->st->codec, +- &subtitle, &got_picture, &avpkt); +- if (ret < 0) +- goto fail_decode; +- if (!got_picture) { +- goto discard_packet; + } +- subtitle_to_free = &subtitle; +- avpkt.size = 0; +- break; +- default: +- goto fail_decode; +- } +- } else { +- switch(ist->st->codec->codec_type) { +- case AVMEDIA_TYPE_AUDIO: +- ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / +- ist->st->codec->sample_rate; + break; + case AVMEDIA_TYPE_VIDEO: +- if (ist->st->codec->time_base.num != 0) { +- int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; +- ist->next_pts += ((int64_t)AV_TIME_BASE * +- ist->st->codec->time_base.num * ticks) / +- ist->st->codec->time_base.den; ++ ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); ++ if (ret < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Video encoding failed\n"); ++ exit_program(1); + } ++ video_size += ret; ++ if (enc->coded_frame && enc->coded_frame->key_frame) ++ pkt.flags |= AV_PKT_FLAG_KEY; ++ if (ost->logfile && enc->stats_out) { ++ fprintf(ost->logfile, "%s", enc->stats_out); ++ } ++ if (ret <= 0) { ++ stop_encoding = 1; ++ break; ++ } ++ pkt.stream_index = ost->index; ++ pkt.data = bit_buffer; ++ pkt.size = ret; ++ if (enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) ++ pkt.pts = av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); ++ write_frame(os, &pkt, ost); + break; ++ default: ++ stop_encoding = 1; + } +- ret = avpkt.size; +- avpkt.size = 0; ++ if (stop_encoding) ++ break; + } ++ } ++} + +- buffer_to_free = NULL; +- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- pre_process_video_frame(ist, (AVPicture *)&picture, +- &buffer_to_free); +- } ++/* ++ * Check whether a packet from ist should be written into ost at this time ++ */ ++static int check_output_constraints(InputStream *ist, OutputStream *ost) ++{ ++ OutputFile *of = &output_files[ost->file_index]; ++ int ist_index = ist - input_streams; + +-#if CONFIG_AVFILTER +- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->input_video_filter) { +- AVRational sar; +- if (ist->st->sample_aspect_ratio.num) sar = ist->st->sample_aspect_ratio; +- else sar = ist->st->codec->sample_aspect_ratio; +- // add it to be filtered +- av_vsrc_buffer_add_frame(ist->input_video_filter, &picture, +- ist->pts, +- sar); +- } +-#endif ++ if (ost->source_index != ist_index) ++ return 0; + +- // preprocess audio (volume) +- if (ist->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- if (audio_volume != 256) { +- short *volp; +- volp = samples; +- for(i=0;i<(decoded_data_size / sizeof(short));i++) { +- int v = ((*volp) * audio_volume + 128) >> 8; +- if (v < -32768) v = -32768; +- if (v > 32767) v = 32767; +- *volp++ = v; +- } ++ if (of->start_time && ist->pts < of->start_time) ++ return 0; ++ ++ if (of->recording_time != INT64_MAX && ++ av_compare_ts(ist->pts, AV_TIME_BASE_Q, of->recording_time + of->start_time, ++ (AVRational){ 1, 1000000 }) >= 0) { ++ ost->is_past_recording_time = 1; ++ return 0; ++ } ++ ++ return 1; ++} ++ ++static void do_streamcopy(InputStream *ist, OutputStream *ost, const AVPacket *pkt) ++{ ++ OutputFile *of = &output_files[ost->file_index]; ++ int64_t ost_tb_start_time = av_rescale_q(of->start_time, AV_TIME_BASE_Q, ost->st->time_base); ++ AVPicture pict; ++ AVPacket opkt; ++ ++ av_init_packet(&opkt); ++ ++ if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && ++ !ost->copy_initial_nonkeyframes) ++ return; ++ ++ /* force the input stream PTS */ ++ if (ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) ++ audio_size += pkt->size; ++ else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ video_size += pkt->size; ++ ost->sync_opts++; ++ } ++ ++ opkt.stream_index = ost->index; ++ if (pkt->pts != AV_NOPTS_VALUE) ++ opkt.pts = av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time; ++ else ++ opkt.pts = AV_NOPTS_VALUE; ++ ++ if (pkt->dts == AV_NOPTS_VALUE) ++ opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base); ++ else ++ opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base); ++ opkt.dts -= ost_tb_start_time; ++ ++ opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base); ++ opkt.flags = pkt->flags; ++ ++ // FIXME remove the following 2 lines they shall be replaced by the bitstream filters ++ if ( ost->st->codec->codec_id != CODEC_ID_H264 ++ && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO ++ && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO ++ ) { ++ if (av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, pkt->data, pkt->size, pkt->flags & AV_PKT_FLAG_KEY)) ++ opkt.destruct = av_destruct_packet; ++ } else { ++ opkt.data = pkt->data; ++ opkt.size = pkt->size; ++ } ++ if (of->ctx->oformat->flags & AVFMT_RAWPICTURE) { ++ /* store AVPicture in AVPacket, as expected by the output format */ ++ avpicture_fill(&pict, opkt.data, ost->st->codec->pix_fmt, ost->st->codec->width, ost->st->codec->height); ++ opkt.data = (uint8_t *)&pict; ++ opkt.size = sizeof(AVPicture); ++ opkt.flags |= AV_PKT_FLAG_KEY; ++ } ++ ++ write_frame(of->ctx, &opkt, ost); ++ ost->st->codec->frame_number++; ++ av_free_packet(&opkt); ++} ++ ++static void rate_emu_sleep(InputStream *ist) ++{ ++ if (input_files[ist->file_index].rate_emu) { ++ int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE); ++ int64_t now = av_gettime() - ist->start; ++ if (pts > now) ++ usleep(pts - now); ++ } ++} ++ ++static int transcode_audio(InputStream *ist, AVPacket *pkt, int *got_output) ++{ ++ AVFrame *decoded_frame; ++ AVCodecContext *avctx = ist->st->codec; ++ int bps = av_get_bytes_per_sample(ist->st->codec->sample_fmt); ++ int i, ret; ++ ++ if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame())) ++ return AVERROR(ENOMEM); ++ else ++ avcodec_get_frame_defaults(ist->decoded_frame); ++ decoded_frame = ist->decoded_frame; ++ ++ ret = avcodec_decode_audio4(avctx, decoded_frame, got_output, pkt); ++ if (ret < 0) { ++ return ret; ++ } ++ ++ if (!*got_output) { ++ /* no audio frame */ ++ return ret; ++ } ++ ++ /* if the decoder provides a pts, use it instead of the last packet pts. ++ the decoder could be delaying output by a packet or more. */ ++ if (decoded_frame->pts != AV_NOPTS_VALUE) ++ ist->next_pts = decoded_frame->pts; ++ ++ /* increment next_pts to use for the case where the input stream does not ++ have timestamps or there are multiple frames in the packet */ ++ ist->next_pts += ((int64_t)AV_TIME_BASE * decoded_frame->nb_samples) / ++ avctx->sample_rate; ++ ++ // preprocess audio (volume) ++ if (audio_volume != 256) { ++ int decoded_data_size = decoded_frame->nb_samples * avctx->channels * bps; ++ void *samples = decoded_frame->data[0]; ++ switch (avctx->sample_fmt) { ++ case AV_SAMPLE_FMT_U8: ++ { ++ uint8_t *volp = samples; ++ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) { ++ int v = (((*volp - 128) * audio_volume + 128) >> 8) + 128; ++ *volp++ = av_clip_uint8(v); + } ++ break; + } +- +- /* frame rate emulation */ +- if (rate_emu) { +- int64_t pts = av_rescale(ist->pts, 1000000, AV_TIME_BASE); +- int64_t now = av_gettime() - ist->start; +- if (pts > now) +- usleep(pts - now); ++ case AV_SAMPLE_FMT_S16: ++ { ++ int16_t *volp = samples; ++ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) { ++ int v = ((*volp) * audio_volume + 128) >> 8; ++ *volp++ = av_clip_int16(v); ++ } ++ break; + } +-#if CONFIG_AVFILTER +- frame_available = ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || +- !ist->output_video_filter || avfilter_poll_frame(ist->output_video_filter->inputs[0]); +-#endif +- /* if output time reached then transcode raw format, +- encode packets and output them */ +- if (start_time == 0 || ist->pts >= start_time) +-#if CONFIG_AVFILTER +- while (frame_available) { +- AVRational ist_pts_tb; +- if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ist->output_video_filter) +- get_filtered_video_frame(ist->output_video_filter, &picture, &ist->picref, &ist_pts_tb); +- if (ist->picref) +- ist->pts = av_rescale_q(ist->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); +-#endif +- for(i=0;i> 8); ++ *volp++ = av_clipl_int32(v); ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_FLT: ++ { ++ float *volp = samples; ++ float scale = audio_volume / 256.f; ++ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) { ++ *volp++ *= scale; ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_DBL: ++ { ++ double *volp = samples; ++ double scale = audio_volume / 256.; ++ for (i = 0; i < (decoded_data_size / sizeof(*volp)); i++) { ++ *volp++ *= scale; ++ } ++ break; ++ } ++ default: ++ av_log(NULL, AV_LOG_FATAL, ++ "Audio volume adjustment on sample format %s is not supported.\n", ++ av_get_sample_fmt_name(ist->st->codec->sample_fmt)); ++ exit_program(1); ++ } ++ } ++ ++ rate_emu_sleep(ist); + +- ost = ost_table[i]; +- if (ost->source_index == ist_index) { +- os = output_files[ost->file_index]; +- +- /* set the input output pts pairs */ +- //ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE; +- +- if (ost->encoding_needed) { +- av_assert0(ist->decoding_needed); +- switch(ost->st->codec->codec_type) { +- case AVMEDIA_TYPE_AUDIO: +- do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size); +- break; +- case AVMEDIA_TYPE_VIDEO: ++ for (i = 0; i < nb_output_streams; i++) { ++ OutputStream *ost = &output_streams[i]; ++ ++ if (!check_output_constraints(ist, ost) || !ost->encoding_needed) ++ continue; ++ do_audio_out(output_files[ost->file_index].ctx, ost, ist, decoded_frame); ++ } ++ ++ return ret; ++} ++ ++static int transcode_video(InputStream *ist, AVPacket *pkt, int *got_output, int64_t *pkt_pts, int64_t *pkt_dts) ++{ ++ AVFrame *decoded_frame, *filtered_frame = NULL; ++ void *buffer_to_free = NULL; ++ int i, ret = 0; ++ float quality = 0; + #if CONFIG_AVFILTER +- if (ist->picref->video) +- ost->st->codec->sample_aspect_ratio = ist->picref->video->pixel_aspect; ++ int frame_available = 1; + #endif +- do_video_out(os, ost, ist, &picture, &frame_size); +- if (vstats_filename && frame_size) +- do_video_stats(os, ost, frame_size); +- break; +- case AVMEDIA_TYPE_SUBTITLE: +- do_subtitle_out(os, ost, ist, &subtitle, +- pkt->pts); +- break; +- default: +- abort(); +- } +- } else { +- AVFrame avframe; //FIXME/XXX remove this +- AVPacket opkt; +- int64_t ost_tb_start_time= av_rescale_q(start_time, AV_TIME_BASE_Q, ost->st->time_base); +- +- av_init_packet(&opkt); +- +- if ((!ost->frame_number && !(pkt->flags & AV_PKT_FLAG_KEY)) && !copy_initial_nonkeyframes) +- continue; +- +- /* no reencoding needed : output the packet directly */ +- /* force the input stream PTS */ +- +- avcodec_get_frame_defaults(&avframe); +- ost->st->codec->coded_frame= &avframe; +- avframe.key_frame = pkt->flags & AV_PKT_FLAG_KEY; +- +- if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO) +- audio_size += data_size; +- else if (ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- video_size += data_size; +- ost->sync_opts++; +- } ++ int duration=0; ++ int64_t *best_effort_timestamp; ++ AVRational *frame_sample_aspect; + +- opkt.stream_index= ost->index; +- if(pkt->pts != AV_NOPTS_VALUE) +- opkt.pts= av_rescale_q(pkt->pts, ist->st->time_base, ost->st->time_base) - ost_tb_start_time; +- else +- opkt.pts= AV_NOPTS_VALUE; +- +- if (pkt->dts == AV_NOPTS_VALUE) +- opkt.dts = av_rescale_q(ist->pts, AV_TIME_BASE_Q, ost->st->time_base); +- else +- opkt.dts = av_rescale_q(pkt->dts, ist->st->time_base, ost->st->time_base); +- opkt.dts -= ost_tb_start_time; +- +- opkt.duration = av_rescale_q(pkt->duration, ist->st->time_base, ost->st->time_base); +- opkt.flags= pkt->flags; +- +- //FIXME remove the following 2 lines they shall be replaced by the bitstream filters +- if( ost->st->codec->codec_id != CODEC_ID_H264 +- && ost->st->codec->codec_id != CODEC_ID_MPEG1VIDEO +- && ost->st->codec->codec_id != CODEC_ID_MPEG2VIDEO +- ) { +- if(av_parser_change(ist->st->parser, ost->st->codec, &opkt.data, &opkt.size, data_buf, data_size, pkt->flags & AV_PKT_FLAG_KEY)) +- opkt.destruct= av_destruct_packet; +- } else { +- opkt.data = data_buf; +- opkt.size = data_size; +- } ++ if (!ist->decoded_frame && !(ist->decoded_frame = avcodec_alloc_frame())) ++ return AVERROR(ENOMEM); ++ else ++ avcodec_get_frame_defaults(ist->decoded_frame); ++ decoded_frame = ist->decoded_frame; ++ pkt->pts = *pkt_pts; ++ pkt->dts = *pkt_dts; ++ *pkt_pts = AV_NOPTS_VALUE; ++ ++ if (pkt->duration) { ++ duration = av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); ++ } else if(ist->st->codec->time_base.num != 0) { ++ int ticks= ist->st->parser ? ist->st->parser->repeat_pict+1 : ist->st->codec->ticks_per_frame; ++ duration = ((int64_t)AV_TIME_BASE * ++ ist->st->codec->time_base.num * ticks) / ++ ist->st->codec->time_base.den; ++ } + +- write_frame(os, &opkt, ost->st->codec, ost->bitstream_filters); +- ost->st->codec->frame_number++; +- ost->frame_number++; +- av_free_packet(&opkt); +- } +- } +- } ++ if(*pkt_dts != AV_NOPTS_VALUE && duration) { ++ *pkt_dts += duration; ++ }else ++ *pkt_dts = AV_NOPTS_VALUE; ++ ++ ret = avcodec_decode_video2(ist->st->codec, ++ decoded_frame, got_output, pkt); ++ if (ret < 0) ++ return ret; ++ ++ quality = same_quant ? decoded_frame->quality : 0; ++ if (!*got_output) { ++ /* no picture yet */ ++ return ret; ++ } ++ ++ best_effort_timestamp= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "best_effort_timestamp"); ++ if(*best_effort_timestamp != AV_NOPTS_VALUE) ++ ist->next_pts = ist->pts = *best_effort_timestamp; ++ ++ ist->next_pts += duration; ++ pkt->size = 0; ++ ++ pre_process_video_frame(ist, (AVPicture *)decoded_frame, &buffer_to_free); + + #if CONFIG_AVFILTER +- frame_available = (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && +- ist->output_video_filter && avfilter_poll_frame(ist->output_video_filter->inputs[0]); +- if(ist->picref) +- avfilter_unref_buffer(ist->picref); +- } +-#endif +- av_free(buffer_to_free); +- /* XXX: allocate the subtitles in the codec ? */ +- if (subtitle_to_free) { +- avsubtitle_free(subtitle_to_free); +- subtitle_to_free = NULL; ++ frame_sample_aspect= av_opt_ptr(avcodec_get_frame_class(), decoded_frame, "sample_aspect_ratio"); ++ for(i=0;iencoding_needed){ ++ if (!frame_sample_aspect->num) ++ *frame_sample_aspect = ist->st->sample_aspect_ratio; ++ decoded_frame->pts = ist->pts; ++ if (ist->dr1 && decoded_frame->type==FF_BUFFER_TYPE_USER) { ++ FrameBuffer *buf = decoded_frame->opaque; ++ AVFilterBufferRef *fb = avfilter_get_video_buffer_ref_from_arrays( ++ decoded_frame->data, decoded_frame->linesize, ++ AV_PERM_READ | AV_PERM_PRESERVE, ++ ist->st->codec->width, ist->st->codec->height, ++ ist->st->codec->pix_fmt); ++ ++ avfilter_copy_frame_props(fb, decoded_frame); ++ fb->pts = ist->pts; ++ fb->buf->priv = buf; ++ fb->buf->free = filter_release_buffer; ++ ++ buf->refcount++; ++ av_buffersrc_buffer(ost->input_video_filter, fb); ++ } else ++ if((av_vsrc_buffer_add_frame(ost->input_video_filter, decoded_frame, AV_VSRC_BUF_FLAG_OVERWRITE)) < 0){ ++ av_log(0, AV_LOG_FATAL, "Failed to inject frame into filter network\n"); ++ exit_program(1); ++ } + } + } +- discard_packet: +- if (pkt == NULL) { +- /* EOF handling */ ++#endif + +- for(i=0;isource_index == ist_index) { +- AVCodecContext *enc= ost->st->codec; +- os = output_files[ost->file_index]; +- +- if(ost->st->codec->codec_type == AVMEDIA_TYPE_AUDIO && enc->frame_size <=1) +- continue; +- if(ost->st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (os->oformat->flags & AVFMT_RAWPICTURE)) +- continue; +- +- if (ost->encoding_needed) { +- for(;;) { +- AVPacket pkt; +- int fifo_bytes; +- av_init_packet(&pkt); +- pkt.stream_index= ost->index; +- +- switch(ost->st->codec->codec_type) { +- case AVMEDIA_TYPE_AUDIO: +- fifo_bytes = av_fifo_size(ost->fifo); +- ret = 0; +- /* encode any samples remaining in fifo */ +- if (fifo_bytes > 0) { +- int osize = av_get_bits_per_sample_fmt(enc->sample_fmt) >> 3; +- int fs_tmp = enc->frame_size; +- +- av_fifo_generic_read(ost->fifo, audio_buf, fifo_bytes, NULL); +- if (enc->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { +- enc->frame_size = fifo_bytes / (osize * enc->channels); +- } else { /* pad */ +- int frame_bytes = enc->frame_size*osize*enc->channels; +- if (allocated_audio_buf_size < frame_bytes) +- ffmpeg_exit(1); +- memset(audio_buf+fifo_bytes, 0, frame_bytes - fifo_bytes); +- } +- +- ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, (short *)audio_buf); +- pkt.duration = av_rescale((int64_t)enc->frame_size*ost->st->time_base.den, +- ost->st->time_base.num, enc->sample_rate); +- enc->frame_size = fs_tmp; +- } +- if(ret <= 0) { +- ret = avcodec_encode_audio(enc, bit_buffer, bit_buffer_size, NULL); +- } +- if (ret < 0) { +- fprintf(stderr, "Audio encoding failed\n"); +- ffmpeg_exit(1); +- } +- audio_size += ret; +- pkt.flags |= AV_PKT_FLAG_KEY; +- break; +- case AVMEDIA_TYPE_VIDEO: +- ret = avcodec_encode_video(enc, bit_buffer, bit_buffer_size, NULL); +- if (ret < 0) { +- fprintf(stderr, "Video encoding failed\n"); +- ffmpeg_exit(1); +- } +- video_size += ret; +- if(enc->coded_frame && enc->coded_frame->key_frame) +- pkt.flags |= AV_PKT_FLAG_KEY; +- if (ost->logfile && enc->stats_out) { +- fprintf(ost->logfile, "%s", enc->stats_out); +- } +- break; +- default: +- ret=-1; +- } ++ rate_emu_sleep(ist); + +- if(ret<=0) +- break; +- pkt.data= bit_buffer; +- pkt.size= ret; +- if(enc->coded_frame && enc->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(enc->coded_frame->pts, enc->time_base, ost->st->time_base); +- write_frame(os, &pkt, ost->st->codec, ost->bitstream_filters); +- } ++ for (i = 0; i < nb_output_streams; i++) { ++ OutputStream *ost = &output_streams[i]; ++ int frame_size; ++ ++ if (!check_output_constraints(ist, ost) || !ost->encoding_needed) ++ continue; ++ ++#if CONFIG_AVFILTER ++ if (ost->input_video_filter) { ++ frame_available = av_buffersink_poll_frame(ost->output_video_filter); ++ } ++ while (frame_available) { ++ if (ost->output_video_filter) { ++ AVRational ist_pts_tb = ost->output_video_filter->inputs[0]->time_base; ++ if (av_buffersink_get_buffer_ref(ost->output_video_filter, &ost->picref, 0) < 0){ ++ av_log(0, AV_LOG_WARNING, "AV Filter told us it has a frame available but failed to output one\n"); ++ goto cont; ++ } ++ if (!ist->filtered_frame && !(ist->filtered_frame = avcodec_alloc_frame())) { ++ av_free(buffer_to_free); ++ return AVERROR(ENOMEM); ++ } else ++ avcodec_get_frame_defaults(ist->filtered_frame); ++ filtered_frame = ist->filtered_frame; ++ *filtered_frame= *decoded_frame; //for me_threshold ++ if (ost->picref) { ++ avfilter_fill_frame_from_video_buffer_ref(filtered_frame, ost->picref); ++ ist->pts = av_rescale_q(ost->picref->pts, ist_pts_tb, AV_TIME_BASE_Q); + } + } ++ if (ost->picref->video && !ost->frame_aspect_ratio) ++ ost->st->codec->sample_aspect_ratio = ost->picref->video->sample_aspect_ratio; ++#else ++ filtered_frame = decoded_frame; ++#endif ++ ++ do_video_out(output_files[ost->file_index].ctx, ost, ist, filtered_frame, &frame_size, ++ same_quant ? quality : ost->st->codec->global_quality); ++ if (vstats_filename && frame_size) ++ do_video_stats(output_files[ost->file_index].ctx, ost, frame_size); ++#if CONFIG_AVFILTER ++ cont: ++ frame_available = ost->output_video_filter && av_buffersink_poll_frame(ost->output_video_filter); ++ avfilter_unref_buffer(ost->picref); + } ++#endif + } + +- return 0; +- fail_decode: +- return -1; ++ av_free(buffer_to_free); ++ return ret; + } + +-static void print_sdp(AVFormatContext **avc, int n) ++static int transcode_subtitles(InputStream *ist, AVPacket *pkt, int *got_output) + { +- char sdp[2048]; ++ AVSubtitle subtitle; ++ int i, ret = avcodec_decode_subtitle2(ist->st->codec, ++ &subtitle, got_output, pkt); ++ if (ret < 0) ++ return ret; ++ if (!*got_output) ++ return ret; + +- avf_sdp_create(avc, n, sdp, sizeof(sdp)); +- printf("SDP:\n%s\n", sdp); +- fflush(stdout); ++ rate_emu_sleep(ist); ++ ++ for (i = 0; i < nb_output_streams; i++) { ++ OutputStream *ost = &output_streams[i]; ++ ++ if (!check_output_constraints(ist, ost) || !ost->encoding_needed) ++ continue; ++ ++ do_subtitle_out(output_files[ost->file_index].ctx, ost, ist, &subtitle, pkt->pts); ++ } ++ ++ avsubtitle_free(&subtitle); ++ return ret; + } + +-static int copy_chapters(int infile, int outfile) ++/* pkt = NULL means EOF (needed to flush decoder buffers) */ ++static int output_packet(InputStream *ist, ++ OutputStream *ost_table, int nb_ostreams, ++ const AVPacket *pkt) + { +- AVFormatContext *is = input_files[infile]; +- AVFormatContext *os = output_files[outfile]; +- int i; ++ int ret = 0, i; ++ int got_output; ++ int64_t pkt_dts = AV_NOPTS_VALUE; ++ int64_t pkt_pts = AV_NOPTS_VALUE; + +- for (i = 0; i < is->nb_chapters; i++) { +- AVChapter *in_ch = is->chapters[i], *out_ch; +- int64_t ts_off = av_rescale_q(start_time - input_files_ts_offset[infile], +- AV_TIME_BASE_Q, in_ch->time_base); +- int64_t rt = (recording_time == INT64_MAX) ? INT64_MAX : +- av_rescale_q(recording_time, AV_TIME_BASE_Q, in_ch->time_base); ++ AVPacket avpkt; + ++ if (ist->next_pts == AV_NOPTS_VALUE) ++ ist->next_pts = ist->pts; + +- if (in_ch->end < ts_off) +- continue; +- if (rt != INT64_MAX && in_ch->start > rt + ts_off) +- break; ++ if (pkt == NULL) { ++ /* EOF handling */ ++ av_init_packet(&avpkt); ++ avpkt.data = NULL; ++ avpkt.size = 0; ++ goto handle_eof; ++ } else { ++ avpkt = *pkt; ++ } + +- out_ch = av_mallocz(sizeof(AVChapter)); +- if (!out_ch) +- return AVERROR(ENOMEM); ++ if (pkt->dts != AV_NOPTS_VALUE) { ++ if (ist->st->codec->codec_type != AVMEDIA_TYPE_VIDEO || !ist->decoding_needed) ++ ist->next_pts = ist->pts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); ++ pkt_dts = av_rescale_q(pkt->dts, ist->st->time_base, AV_TIME_BASE_Q); ++ } ++ if(pkt->pts != AV_NOPTS_VALUE) ++ pkt_pts = av_rescale_q(pkt->pts, ist->st->time_base, AV_TIME_BASE_Q); + +- out_ch->id = in_ch->id; +- out_ch->time_base = in_ch->time_base; +- out_ch->start = FFMAX(0, in_ch->start - ts_off); +- out_ch->end = FFMIN(rt, in_ch->end - ts_off); ++ // while we have more to decode or while the decoder did output something on EOF ++ while (ist->decoding_needed && (avpkt.size > 0 || (!pkt && got_output))) { ++ handle_eof: + +- if (metadata_chapters_autocopy) +- av_metadata_copy(&out_ch->metadata, in_ch->metadata, 0); ++ ist->pts = ist->next_pts; + +- os->nb_chapters++; +- os->chapters = av_realloc(os->chapters, sizeof(AVChapter)*os->nb_chapters); +- if (!os->chapters) +- return AVERROR(ENOMEM); +- os->chapters[os->nb_chapters - 1] = out_ch; +- } +- return 0; +-} ++ if (avpkt.size && avpkt.size != pkt->size) { ++ av_log(NULL, ist->showed_multi_packet_warning ? AV_LOG_VERBOSE : AV_LOG_WARNING, ++ "Multiple frames in a packet from stream %d\n", pkt->stream_index); ++ ist->showed_multi_packet_warning = 1; ++ } + +-static void parse_forced_key_frames(char *kf, AVOutputStream *ost, +- AVCodecContext *avctx) +-{ +- char *p; +- int n = 1, i; +- int64_t t; ++ switch (ist->st->codec->codec_type) { ++ case AVMEDIA_TYPE_AUDIO: ++ ret = transcode_audio (ist, &avpkt, &got_output); ++ break; ++ case AVMEDIA_TYPE_VIDEO: ++ ret = transcode_video (ist, &avpkt, &got_output, &pkt_pts, &pkt_dts); ++ break; ++ case AVMEDIA_TYPE_SUBTITLE: ++ ret = transcode_subtitles(ist, &avpkt, &got_output); ++ break; ++ default: ++ return -1; ++ } + +- for (p = kf; *p; p++) +- if (*p == ',') +- n++; +- ost->forced_kf_count = n; +- ost->forced_kf_pts = av_malloc(sizeof(*ost->forced_kf_pts) * n); +- if (!ost->forced_kf_pts) { +- av_log(NULL, AV_LOG_FATAL, "Could not allocate forced key frames array.\n"); +- ffmpeg_exit(1); +- } +- for (i = 0; i < n; i++) { +- p = i ? strchr(p, ',') + 1 : kf; +- t = parse_time_or_die("force_key_frames", p, 1); +- ost->forced_kf_pts[i] = av_rescale_q(t, AV_TIME_BASE_Q, avctx->time_base); ++ if (ret < 0) ++ return ret; ++ ++ avpkt.dts= ++ avpkt.pts= AV_NOPTS_VALUE; ++ ++ // touch data and size only if not EOF ++ if (pkt) { ++ if(ist->st->codec->codec_type != AVMEDIA_TYPE_AUDIO) ++ ret = avpkt.size; ++ avpkt.data += ret; ++ avpkt.size -= ret; ++ } ++ if (!got_output) { ++ continue; ++ } + } +-} + +-/* +- * The following code is the main loop of the file converter +- */ +-static int transcode(AVFormatContext **output_files, +- int nb_output_files, +- AVFormatContext **input_files, +- int nb_input_files, +- AVStreamMap *stream_maps, int nb_stream_maps) +-{ +- int ret = 0, i, j, k, n, nb_istreams = 0, nb_ostreams = 0; +- AVFormatContext *is, *os; +- AVCodecContext *codec, *icodec; +- AVOutputStream *ost, **ost_table = NULL; +- AVInputStream *ist, **ist_table = NULL; +- AVInputFile *file_table; +- char error[1024]; +- int key; +- int want_sdp = 1; +- uint8_t no_packet[MAX_FILES]={0}; +- int no_packet_count=0; ++ /* handle stream copy */ ++ if (!ist->decoding_needed) { ++ rate_emu_sleep(ist); ++ ist->pts = ist->next_pts; ++ switch (ist->st->codec->codec_type) { ++ case AVMEDIA_TYPE_AUDIO: ++ ist->next_pts += ((int64_t)AV_TIME_BASE * ist->st->codec->frame_size) / ++ ist->st->codec->sample_rate; ++ break; ++ case AVMEDIA_TYPE_VIDEO: ++ if (pkt->duration) { ++ ist->next_pts += av_rescale_q(pkt->duration, ist->st->time_base, AV_TIME_BASE_Q); ++ } else if(ist->st->codec->time_base.num != 0) { ++ int ticks= ist->st->parser ? ist->st->parser->repeat_pict + 1 : ist->st->codec->ticks_per_frame; ++ ist->next_pts += ((int64_t)AV_TIME_BASE * ++ ist->st->codec->time_base.num * ticks) / ++ ist->st->codec->time_base.den; ++ } ++ break; ++ } ++ } ++ for (i = 0; pkt && i < nb_ostreams; i++) { ++ OutputStream *ost = &ost_table[i]; + +- file_table= av_mallocz(nb_input_files * sizeof(AVInputFile)); +- if (!file_table) +- goto fail; ++ if (!check_output_constraints(ist, ost) || ost->encoding_needed) ++ continue; + +- /* input stream init */ +- j = 0; +- for(i=0;inb_streams; +- j += is->nb_streams; ++ do_streamcopy(ist, ost, pkt); + } +- nb_istreams = j; + +- ist_table = av_mallocz(nb_istreams * sizeof(AVInputStream *)); +- if (!ist_table) +- goto fail; ++ return 0; ++} + +- for(i=0;inb_streams;k++) { +- ist = ist_table[j++]; +- ist->st = is->streams[k]; +- ist->file_index = i; +- ist->index = k; +- ist->discard = 1; /* the stream is discarded by default +- (changed later) */ ++static void print_sdp(OutputFile *output_files, int n) ++{ ++ char sdp[2048]; ++ int i; ++ AVFormatContext **avc = av_malloc(sizeof(*avc) * n); + +- if (rate_emu) { +- ist->start = av_gettime(); +- } +- } +- } ++ if (!avc) ++ exit_program(1); ++ for (i = 0; i < n; i++) ++ avc[i] = output_files[i].ctx; + +- /* output stream init */ +- nb_ostreams = 0; +- for(i=0;inb_streams && !(os->oformat->flags & AVFMT_NOSTREAMS)) { +- dump_format(output_files[i], i, output_files[i]->filename, 1); +- fprintf(stderr, "Output file #%d does not contain any stream\n", i); +- ret = AVERROR(EINVAL); +- goto fail; ++ av_sdp_create(avc, n, sdp, sizeof(sdp)); ++ printf("SDP:\n%s\n", sdp); ++ fflush(stdout); ++ av_freep(&avc); ++} ++ ++static int init_input_stream(int ist_index, OutputStream *output_streams, int nb_output_streams, ++ char *error, int error_len) ++{ ++ InputStream *ist = &input_streams[ist_index]; ++ if (ist->decoding_needed) { ++ AVCodec *codec = ist->dec; ++ if (!codec) { ++ snprintf(error, error_len, "Decoder (codec %s) not found for input stream #%d:%d", ++ avcodec_get_name(ist->st->codec->codec_id), ist->file_index, ist->st->index); ++ return AVERROR(EINVAL); + } +- nb_ostreams += os->nb_streams; +- } +- if (nb_stream_maps > 0 && nb_stream_maps != nb_ostreams) { +- fprintf(stderr, "Number of stream maps must match number of output streams\n"); +- ret = AVERROR(EINVAL); +- goto fail; +- } + +- /* Sanity check the mapping args -- do the input files & streams exist? */ +- for(i=0;i nb_input_files - 1 || +- si < 0 || si > file_table[fi].nb_streams - 1) { +- fprintf(stderr,"Could not find input stream #%d.%d\n", fi, si); +- ret = AVERROR(EINVAL); +- goto fail; ++ ist->dr1 = codec->capabilities & CODEC_CAP_DR1; ++ if (codec->type == AVMEDIA_TYPE_VIDEO && ist->dr1) { ++ ist->st->codec->get_buffer = codec_get_buffer; ++ ist->st->codec->release_buffer = codec_release_buffer; ++ ist->st->codec->opaque = ist; + } +- fi = stream_maps[i].sync_file_index; +- si = stream_maps[i].sync_stream_index; +- if (fi < 0 || fi > nb_input_files - 1 || +- si < 0 || si > file_table[fi].nb_streams - 1) { +- fprintf(stderr,"Could not find sync stream #%d.%d\n", fi, si); +- ret = AVERROR(EINVAL); +- goto fail; ++ ++ if (!av_dict_get(ist->opts, "threads", NULL, 0)) ++ av_dict_set(&ist->opts, "threads", "auto", 0); ++ if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) { ++ snprintf(error, error_len, "Error while opening decoder for input stream #%d:%d", ++ ist->file_index, ist->st->index); ++ return AVERROR(EINVAL); + } ++ assert_codec_experimental(ist->st->codec, 0); ++ assert_avoptions(ist->opts); + } + +- ost_table = av_mallocz(sizeof(AVOutputStream *) * nb_ostreams); +- if (!ost_table) +- goto fail; +- n = 0; +- for(k=0;knb_streams;i++,n++) { +- int found; +- ost = ost_table[n] = output_streams_for_file[k][i]; +- ost->st = os->streams[i]; +- if (nb_stream_maps > 0) { +- ost->source_index = file_table[stream_maps[n].file_index].ist_index + +- stream_maps[n].stream_index; +- +- /* Sanity check that the stream types match */ +- if (ist_table[ost->source_index]->st->codec->codec_type != ost->st->codec->codec_type) { +- int i= ost->file_index; +- dump_format(output_files[i], i, output_files[i]->filename, 1); +- fprintf(stderr, "Codec type mismatch for mapping #%d.%d -> #%d.%d\n", +- stream_maps[n].file_index, stream_maps[n].stream_index, +- ost->file_index, ost->index); +- ffmpeg_exit(1); +- } ++ ist->pts = ist->st->avg_frame_rate.num ? - ist->st->codec->has_b_frames * AV_TIME_BASE / av_q2d(ist->st->avg_frame_rate) : 0; ++ ist->next_pts = AV_NOPTS_VALUE; ++ ist->is_start = 1; + +- } else { +- int best_nb_frames=-1; +- /* get corresponding input stream index : we select the first one with the right type */ +- found = 0; +- for(j=0;jfile_index ]; +- skip=1; +- for(pi=0; pinb_programs; pi++){ +- AVProgram *p= f->programs[pi]; +- if(p->id == opt_programid) +- for(si=0; sinb_stream_indexes; si++){ +- if(f->streams[ p->stream_index[si] ] == ist->st) +- skip=0; +- } +- } +- } +- if (ist->discard && ist->st->discard != AVDISCARD_ALL && !skip && +- ist->st->codec->codec_type == ost->st->codec->codec_type) { +- if(best_nb_frames < ist->st->codec_info_nb_frames){ +- best_nb_frames= ist->st->codec_info_nb_frames; +- ost->source_index = j; +- found = 1; +- } +- } +- } ++ return 0; ++} + +- if (!found) { +- if(! opt_programid) { +- /* try again and reuse existing stream */ +- for(j=0;jst->codec->codec_type == ost->st->codec->codec_type +- && ist->st->discard != AVDISCARD_ALL) { +- ost->source_index = j; +- found = 1; +- } +- } +- } +- if (!found) { +- int i= ost->file_index; +- dump_format(output_files[i], i, output_files[i]->filename, 1); +- fprintf(stderr, "Could not find input stream matching output stream #%d.%d\n", +- ost->file_index, ost->index); +- ffmpeg_exit(1); +- } +- } +- } +- ist = ist_table[ost->source_index]; +- ist->discard = 0; +- ost->sync_ist = (nb_stream_maps > 0) ? +- ist_table[file_table[stream_maps[n].sync_file_index].ist_index + +- stream_maps[n].sync_stream_index] : ist; ++static int transcode_init(OutputFile *output_files, int nb_output_files, ++ InputFile *input_files, int nb_input_files) ++{ ++ int ret = 0, i, j, k; ++ AVFormatContext *oc; ++ AVCodecContext *codec, *icodec; ++ OutputStream *ost; ++ InputStream *ist; ++ char error[1024]; ++ int want_sdp = 1; ++ ++ /* init framerate emulation */ ++ for (i = 0; i < nb_input_files; i++) { ++ InputFile *ifile = &input_files[i]; ++ if (ifile->rate_emu) ++ for (j = 0; j < ifile->nb_streams; j++) ++ input_streams[j + ifile->ist_index].start = av_gettime(); ++ } ++ ++ /* output stream init */ ++ for (i = 0; i < nb_output_files; i++) { ++ oc = output_files[i].ctx; ++ if (!oc->nb_streams && !(oc->oformat->flags & AVFMT_NOSTREAMS)) { ++ av_dump_format(oc, i, oc->filename, 1); ++ av_log(NULL, AV_LOG_ERROR, "Output file #%d does not contain any stream\n", i); ++ return AVERROR(EINVAL); + } + } + + /* for each output stream, we compute the right encoding parameters */ +- for(i=0;ifile_index]; +- ist = ist_table[ost->source_index]; ++ for (i = 0; i < nb_output_streams; i++) { ++ ost = &output_streams[i]; ++ oc = output_files[ost->file_index].ctx; ++ ist = &input_streams[ost->source_index]; + +- codec = ost->st->codec; +- icodec = ist->st->codec; ++ if (ost->attachment_filename) ++ continue; + +- if (metadata_streams_autocopy) +- av_metadata_copy(&ost->st->metadata, ist->st->metadata, +- AV_METADATA_DONT_OVERWRITE); ++ codec = ost->st->codec; ++ icodec = ist->st->codec; + +- ost->st->disposition = ist->st->disposition; +- codec->bits_per_raw_sample= icodec->bits_per_raw_sample; ++ ost->st->disposition = ist->st->disposition; ++ codec->bits_per_raw_sample = icodec->bits_per_raw_sample; + codec->chroma_sample_location = icodec->chroma_sample_location; + +- if (ost->st->stream_copy) { ++ if (ost->stream_copy) { + uint64_t extra_size = (uint64_t)icodec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE; + +- if (extra_size > INT_MAX) +- goto fail; ++ if (extra_size > INT_MAX) { ++ return AVERROR(EINVAL); ++ } + + /* if stream_copy is selected, no need to decode or encode */ +- codec->codec_id = icodec->codec_id; ++ codec->codec_id = icodec->codec_id; + codec->codec_type = icodec->codec_type; + +- if(!codec->codec_tag){ +- if( !os->oformat->codec_tag +- || av_codec_get_id (os->oformat->codec_tag, icodec->codec_tag) == codec->codec_id +- || av_codec_get_tag(os->oformat->codec_tag, icodec->codec_id) <= 0) ++ if (!codec->codec_tag) { ++ if (!oc->oformat->codec_tag || ++ av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == codec->codec_id || ++ av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) + codec->codec_tag = icodec->codec_tag; + } + +- codec->bit_rate = icodec->bit_rate; ++ codec->bit_rate = icodec->bit_rate; + codec->rc_max_rate = icodec->rc_max_rate; + codec->rc_buffer_size = icodec->rc_buffer_size; +- codec->extradata= av_mallocz(extra_size); +- if (!codec->extradata) +- goto fail; ++ codec->field_order = icodec->field_order; ++ codec->extradata = av_mallocz(extra_size); ++ if (!codec->extradata) { ++ return AVERROR(ENOMEM); ++ } + memcpy(codec->extradata, icodec->extradata, icodec->extradata_size); + codec->extradata_size= icodec->extradata_size; +- if(!copy_tb && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) && av_q2d(ist->st->time_base) < 1.0/500){ +- codec->time_base = icodec->time_base; +- codec->time_base.num *= icodec->ticks_per_frame; +- av_reduce(&codec->time_base.num, &codec->time_base.den, +- codec->time_base.num, codec->time_base.den, INT_MAX); +- }else +- codec->time_base = ist->st->time_base; +- switch(codec->codec_type) { ++ ++ codec->time_base = ist->st->time_base; ++ if(!strcmp(oc->oformat->name, "avi")) { ++ if ( copy_tb<0 && av_q2d(icodec->time_base)*icodec->ticks_per_frame > 2*av_q2d(ist->st->time_base) ++ && av_q2d(ist->st->time_base) < 1.0/500 ++ || copy_tb==0){ ++ codec->time_base = icodec->time_base; ++ codec->time_base.num *= icodec->ticks_per_frame; ++ codec->time_base.den *= 2; ++ } ++ } else if(!(oc->oformat->flags & AVFMT_VARIABLE_FPS) ++ && strcmp(oc->oformat->name, "mov") && strcmp(oc->oformat->name, "mp4") && strcmp(oc->oformat->name, "3gp") ++ && strcmp(oc->oformat->name, "3g2") && strcmp(oc->oformat->name, "psp") && strcmp(oc->oformat->name, "ipod") ++ ) { ++ if( copy_tb<0 && av_q2d(icodec->time_base)*icodec->ticks_per_frame > av_q2d(ist->st->time_base) ++ && av_q2d(ist->st->time_base) < 1.0/500 ++ || copy_tb==0){ ++ codec->time_base = icodec->time_base; ++ codec->time_base.num *= icodec->ticks_per_frame; ++ } ++ } ++ av_reduce(&codec->time_base.num, &codec->time_base.den, ++ codec->time_base.num, codec->time_base.den, INT_MAX); ++ ++ switch (codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: +- if(audio_volume != 256) { +- fprintf(stderr,"-acodec copy and -vol are incompatible (frames are not decoded)\n"); +- ffmpeg_exit(1); ++ if (audio_volume != 256) { ++ av_log(NULL, AV_LOG_FATAL, "-acodec copy and -vol are incompatible (frames are not decoded)\n"); ++ exit_program(1); + } +- codec->channel_layout = icodec->channel_layout; +- codec->sample_rate = icodec->sample_rate; +- codec->channels = icodec->channels; +- codec->frame_size = icodec->frame_size; +- codec->block_align= icodec->block_align; +- if(codec->block_align == 1 && codec->codec_id == CODEC_ID_MP3) +- codec->block_align= 0; +- if(codec->codec_id == CODEC_ID_AC3) +- codec->block_align= 0; ++ codec->channel_layout = icodec->channel_layout; ++ codec->sample_rate = icodec->sample_rate; ++ codec->channels = icodec->channels; ++ codec->frame_size = icodec->frame_size; ++ codec->audio_service_type = icodec->audio_service_type; ++ codec->block_align = icodec->block_align; + break; + case AVMEDIA_TYPE_VIDEO: +- codec->pix_fmt = icodec->pix_fmt; +- codec->width = icodec->width; +- codec->height = icodec->height; +- codec->has_b_frames = icodec->has_b_frames; ++ codec->pix_fmt = icodec->pix_fmt; ++ codec->width = icodec->width; ++ codec->height = icodec->height; ++ codec->has_b_frames = icodec->has_b_frames; ++ if (!codec->sample_aspect_ratio.num) { ++ codec->sample_aspect_ratio = ++ ost->st->sample_aspect_ratio = ++ ist->st->sample_aspect_ratio.num ? ist->st->sample_aspect_ratio : ++ ist->st->codec->sample_aspect_ratio.num ? ++ ist->st->codec->sample_aspect_ratio : (AVRational){0, 1}; ++ } ++ ost->st->avg_frame_rate = ist->st->avg_frame_rate; + break; + case AVMEDIA_TYPE_SUBTITLE: +- codec->width = icodec->width; ++ codec->width = icodec->width; + codec->height = icodec->height; + break; ++ case AVMEDIA_TYPE_DATA: ++ case AVMEDIA_TYPE_ATTACHMENT: ++ break; + default: + abort(); + } + } else { +- switch(codec->codec_type) { ++ if (!ost->enc) ++ ost->enc = avcodec_find_encoder(ost->st->codec->codec_id); ++ ++ ist->decoding_needed = 1; ++ ost->encoding_needed = 1; ++ ++ switch (codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: +- ost->fifo= av_fifo_alloc(1024); +- if(!ost->fifo) +- goto fail; +- ost->reformat_pair = MAKE_SFMT_PAIR(AV_SAMPLE_FMT_NONE,AV_SAMPLE_FMT_NONE); +- ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; +- icodec->request_channels = codec->channels; +- ist->decoding_needed = 1; +- ost->encoding_needed = 1; ++ ost->fifo = av_fifo_alloc(1024); ++ if (!ost->fifo) { ++ return AVERROR(ENOMEM); ++ } ++ if (!codec->sample_rate) ++ codec->sample_rate = icodec->sample_rate; ++ choose_sample_rate(ost->st, ost->enc); ++ codec->time_base = (AVRational){ 1, codec->sample_rate }; ++ ++ if (codec->sample_fmt == AV_SAMPLE_FMT_NONE) ++ codec->sample_fmt = icodec->sample_fmt; ++ choose_sample_fmt(ost->st, ost->enc); ++ ++ if (ost->audio_channels_mapped) { ++ /* the requested output channel is set to the number of ++ * -map_channel only if no -ac are specified */ ++ if (!codec->channels) { ++ codec->channels = ost->audio_channels_mapped; ++ codec->channel_layout = av_get_default_channel_layout(codec->channels); ++ if (!codec->channel_layout) { ++ av_log(NULL, AV_LOG_FATAL, "Unable to find an appropriate channel layout for requested number of channel\n"); ++ exit_program(1); ++ } ++ } ++ /* fill unused channel mapping with -1 (which means a muted ++ * channel in case the number of output channels is bigger ++ * than the number of mapped channel) */ ++ for (j = ost->audio_channels_mapped; j < FF_ARRAY_ELEMS(ost->audio_channels_map); j++) ++ ost->audio_channels_map[j] = -1; ++ } else if (!codec->channels) { ++ codec->channels = icodec->channels; ++ codec->channel_layout = icodec->channel_layout; ++ } ++ if (av_get_channel_layout_nb_channels(codec->channel_layout) != codec->channels) ++ codec->channel_layout = 0; ++ ++ ost->audio_resample = codec->sample_rate != icodec->sample_rate || audio_sync_method > 1; ++ ost->audio_resample |= codec->sample_fmt != icodec->sample_fmt ++ || codec->channel_layout != icodec->channel_layout; ++ icodec->request_channels = codec->channels; + ost->resample_sample_fmt = icodec->sample_fmt; + ost->resample_sample_rate = icodec->sample_rate; + ost->resample_channels = icodec->channels; + break; + case AVMEDIA_TYPE_VIDEO: ++ if (codec->pix_fmt == PIX_FMT_NONE) ++ codec->pix_fmt = icodec->pix_fmt; ++ choose_pixel_fmt(ost->st, ost->enc); ++ + if (ost->st->codec->pix_fmt == PIX_FMT_NONE) { +- fprintf(stderr, "Video pixel format is unknown, stream cannot be encoded\n"); +- ffmpeg_exit(1); ++ av_log(NULL, AV_LOG_FATAL, "Video pixel format is unknown, stream cannot be encoded\n"); ++ exit_program(1); ++ } ++ ++ if (!codec->width || !codec->height) { ++ codec->width = icodec->width; ++ codec->height = icodec->height; + } +- ost->video_resample = (codec->width != icodec->width || +- codec->height != icodec->height || +- (codec->pix_fmt != icodec->pix_fmt)); ++ ++ ost->video_resample = codec->width != icodec->width || ++ codec->height != icodec->height || ++ codec->pix_fmt != icodec->pix_fmt; + if (ost->video_resample) { +-#if !CONFIG_AVFILTER +- avcodec_get_frame_defaults(&ost->pict_tmp); +- if(avpicture_alloc((AVPicture*)&ost->pict_tmp, codec->pix_fmt, +- codec->width, codec->height)) { +- fprintf(stderr, "Cannot allocate temp picture, check pix fmt\n"); +- ffmpeg_exit(1); +- } +- sws_flags = av_get_int(sws_opts, "sws_flags", NULL); +- ost->img_resample_ctx = sws_getContext( +- icodec->width, +- icodec->height, +- icodec->pix_fmt, +- codec->width, +- codec->height, +- codec->pix_fmt, +- sws_flags, NULL, NULL, NULL); +- if (ost->img_resample_ctx == NULL) { +- fprintf(stderr, "Cannot get resampling context\n"); +- ffmpeg_exit(1); +- } ++ codec->bits_per_raw_sample = frame_bits_per_raw_sample; ++ } + +- ost->original_height = icodec->height; +- ost->original_width = icodec->width; +-#endif +- codec->bits_per_raw_sample= 0; ++ ost->resample_height = icodec->height; ++ ost->resample_width = icodec->width; ++ ost->resample_pix_fmt = icodec->pix_fmt; ++ ++ if (!ost->frame_rate.num) ++ ost->frame_rate = ist->st->r_frame_rate.num ? ist->st->r_frame_rate : (AVRational) { 25, 1 }; ++ if (ost->enc && ost->enc->supported_framerates && !ost->force_fps) { ++ int idx = av_find_nearest_q_idx(ost->frame_rate, ost->enc->supported_framerates); ++ ost->frame_rate = ost->enc->supported_framerates[idx]; ++ } ++ codec->time_base = (AVRational){ost->frame_rate.den, ost->frame_rate.num}; ++ if ( av_q2d(codec->time_base) < 0.001 && video_sync_method ++ && (video_sync_method==1 || (video_sync_method<0 && !(oc->oformat->flags & AVFMT_VARIABLE_FPS)))){ ++ av_log(oc, AV_LOG_WARNING, "Frame rate very high for a muxer not effciciently supporting it.\n" ++ "Please consider specifiying a lower framerate, a different muxer or -vsync 2\n"); + } +- ost->resample_height = icodec->height; +- ost->resample_width = icodec->width; +- ost->resample_pix_fmt= icodec->pix_fmt; +- ost->encoding_needed = 1; +- ist->decoding_needed = 1; ++ for (j = 0; j < ost->forced_kf_count; j++) ++ ost->forced_kf_pts[j] = av_rescale_q(ost->forced_kf_pts[j], ++ AV_TIME_BASE_Q, ++ codec->time_base); + + #if CONFIG_AVFILTER +- if (configure_filters(ist, ost)) { +- fprintf(stderr, "Error opening filters!\n"); ++ if (configure_video_filters(ist, ost)) { ++ av_log(NULL, AV_LOG_FATAL, "Error opening filters!\n"); + exit(1); + } + #endif + break; + case AVMEDIA_TYPE_SUBTITLE: +- ost->encoding_needed = 1; +- ist->decoding_needed = 1; + break; + default: + abort(); + break; + } + /* two pass mode */ +- if (ost->encoding_needed && +- (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2))) { ++ if (codec->flags & (CODEC_FLAG_PASS1 | CODEC_FLAG_PASS2)) { + char logfilename[1024]; + FILE *f; + + snprintf(logfilename, sizeof(logfilename), "%s-%d.log", + pass_logfilename_prefix ? pass_logfilename_prefix : DEFAULT_PASS_LOGFILENAME_PREFIX, + i); +- if (codec->flags & CODEC_FLAG_PASS1) { +- f = fopen(logfilename, "wb"); +- if (!f) { +- fprintf(stderr, "Cannot write log file '%s' for pass-1 encoding: %s\n", logfilename, strerror(errno)); +- ffmpeg_exit(1); +- } +- ost->logfile = f; ++ if (!strcmp(ost->enc->name, "libx264")) { ++ av_dict_set(&ost->opts, "stats", logfilename, AV_DICT_DONT_OVERWRITE); + } else { +- char *logbuffer; +- size_t logbuffer_size; +- if (read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { +- fprintf(stderr, "Error reading log file '%s' for pass-2 encoding\n", logfilename); +- ffmpeg_exit(1); ++ if (codec->flags & CODEC_FLAG_PASS2) { ++ char *logbuffer; ++ size_t logbuffer_size; ++ if (cmdutils_read_file(logfilename, &logbuffer, &logbuffer_size) < 0) { ++ av_log(NULL, AV_LOG_FATAL, "Error reading log file '%s' for pass-2 encoding\n", ++ logfilename); ++ exit_program(1); ++ } ++ codec->stats_in = logbuffer; ++ } ++ if (codec->flags & CODEC_FLAG_PASS1) { ++ f = fopen(logfilename, "wb"); ++ if (!f) { ++ av_log(NULL, AV_LOG_FATAL, "Cannot write log file '%s' for pass-1 encoding: %s\n", ++ logfilename, strerror(errno)); ++ exit_program(1); ++ } ++ ost->logfile = f; + } +- codec->stats_in = logbuffer; + } + } + } +- if(codec->codec_type == AVMEDIA_TYPE_VIDEO){ +- int size= codec->width * codec->height; +- bit_buffer_size= FFMAX(bit_buffer_size, 6*size + 200); ++ if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ /* maximum video buffer size is 8-bytes per pixel, plus DPX header size (1664)*/ ++ int size = codec->width * codec->height; ++ bit_buffer_size = FFMAX(bit_buffer_size, 9*size + 10000); + } + } + + if (!bit_buffer) + bit_buffer = av_malloc(bit_buffer_size); + if (!bit_buffer) { +- fprintf(stderr, "Cannot allocate %d bytes output buffer\n", +- bit_buffer_size); +- ret = AVERROR(ENOMEM); +- goto fail; ++ av_log(NULL, AV_LOG_ERROR, "Cannot allocate %d bytes output buffer\n", ++ bit_buffer_size); ++ return AVERROR(ENOMEM); + } + + /* open each encoder */ +- for(i=0;iencoding_needed) { +- AVCodec *codec = i < nb_output_codecs ? output_codecs[i] : NULL; +- AVCodecContext *dec = ist_table[ost->source_index]->st->codec; +- if (!codec) +- codec = avcodec_find_encoder(ost->st->codec->codec_id); ++ AVCodec *codec = ost->enc; ++ AVCodecContext *dec = input_streams[ost->source_index].st->codec; + if (!codec) { +- snprintf(error, sizeof(error), "Encoder (codec id %d) not found for output stream #%d.%d", +- ost->st->codec->codec_id, ost->file_index, ost->index); ++ snprintf(error, sizeof(error), "Encoder (codec %s) not found for output stream #%d:%d", ++ avcodec_get_name(ost->st->codec->codec_id), ost->file_index, ost->index); + ret = AVERROR(EINVAL); + goto dump_format; + } +@@ -2327,149 +2694,58 @@ + memcpy(ost->st->codec->subtitle_header, dec->subtitle_header, dec->subtitle_header_size); + ost->st->codec->subtitle_header_size = dec->subtitle_header_size; + } +- if (avcodec_open(ost->st->codec, codec) < 0) { +- snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate, width or height", ++ if (!av_dict_get(ost->opts, "threads", NULL, 0)) ++ av_dict_set(&ost->opts, "threads", "auto", 0); ++ if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) { ++ snprintf(error, sizeof(error), "Error while opening encoder for output stream #%d:%d - maybe incorrect parameters such as bit_rate, rate, width or height", + ost->file_index, ost->index); + ret = AVERROR(EINVAL); + goto dump_format; + } ++ assert_codec_experimental(ost->st->codec, 1); ++ assert_avoptions(ost->opts); ++ if (ost->st->codec->bit_rate && ost->st->codec->bit_rate < 1000) ++ av_log(NULL, AV_LOG_WARNING, "The bitrate parameter is set too low." ++ " It takes bits/s as argument, not kbits/s\n"); + extra_size += ost->st->codec->extradata_size; +- } +- } +- +- /* open each decoder */ +- for(i=0;idecoding_needed) { +- AVCodec *codec = i < nb_input_codecs ? input_codecs[i] : NULL; +- if (!codec) +- codec = avcodec_find_decoder(ist->st->codec->codec_id); +- if (!codec) { +- snprintf(error, sizeof(error), "Decoder (codec id %d) not found for input stream #%d.%d", +- ist->st->codec->codec_id, ist->file_index, ist->index); +- ret = AVERROR(EINVAL); +- goto dump_format; +- } +- if (avcodec_open(ist->st->codec, codec) < 0) { +- snprintf(error, sizeof(error), "Error while opening decoder for input stream #%d.%d", +- ist->file_index, ist->index); +- ret = AVERROR(EINVAL); +- goto dump_format; +- } +- //if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) +- // ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD; +- } +- } +- +- /* init pts */ +- for(i=0;ist; +- ist->pts = st->avg_frame_rate.num ? - st->codec->has_b_frames*AV_TIME_BASE / av_q2d(st->avg_frame_rate) : 0; +- ist->next_pts = AV_NOPTS_VALUE; +- init_pts_correction(&ist->pts_ctx); +- ist->is_start = 1; +- } +- +- /* set meta data information from input file if required */ +- for (i=0;i= (nb_elems)) {\ +- snprintf(error, sizeof(error), "Invalid %s index %d while processing metadata maps\n",\ +- (desc), (index));\ +- ret = AVERROR(EINVAL);\ +- goto dump_format;\ +- } + +- int out_file_index = meta_data_maps[i][0].file; +- int in_file_index = meta_data_maps[i][1].file; +- if (in_file_index < 0 || out_file_index < 0) +- continue; +- METADATA_CHECK_INDEX(out_file_index, nb_output_files, "output file") +- METADATA_CHECK_INDEX(in_file_index, nb_input_files, "input file") +- +- files[0] = output_files[out_file_index]; +- files[1] = input_files[in_file_index]; +- +- for (j = 0; j < 2; j++) { +- AVMetaDataMap *map = &meta_data_maps[i][j]; +- +- switch (map->type) { +- case 'g': +- meta[j] = &files[j]->metadata; +- break; +- case 's': +- METADATA_CHECK_INDEX(map->index, files[j]->nb_streams, "stream") +- meta[j] = &files[j]->streams[map->index]->metadata; +- break; +- case 'c': +- METADATA_CHECK_INDEX(map->index, files[j]->nb_chapters, "chapter") +- meta[j] = &files[j]->chapters[map->index]->metadata; +- break; +- case 'p': +- METADATA_CHECK_INDEX(map->index, files[j]->nb_programs, "program") +- meta[j] = &files[j]->programs[map->index]->metadata; +- break; +- } ++ if (ost->st->codec->me_threshold) ++ input_streams[ost->source_index].st->codec->debug |= FF_DEBUG_MV; + } +- +- av_metadata_copy(meta[0], *meta[1], AV_METADATA_DONT_OVERWRITE); +- } +- +- /* copy global metadata by default */ +- if (metadata_global_autocopy) { +- +- for (i = 0; i < nb_output_files; i++) +- av_metadata_copy(&output_files[i]->metadata, input_files[0]->metadata, +- AV_METADATA_DONT_OVERWRITE); + } + +- /* copy chapters according to chapter maps */ +- for (i = 0; i < nb_chapter_maps; i++) { +- int infile = chapter_maps[i].in_file; +- int outfile = chapter_maps[i].out_file; +- +- if (infile < 0 || outfile < 0) +- continue; +- if (infile >= nb_input_files) { +- snprintf(error, sizeof(error), "Invalid input file index %d in chapter mapping.\n", infile); +- ret = AVERROR(EINVAL); +- goto dump_format; +- } +- if (outfile >= nb_output_files) { +- snprintf(error, sizeof(error), "Invalid output file index %d in chapter mapping.\n",outfile); +- ret = AVERROR(EINVAL); ++ /* init input streams */ ++ for (i = 0; i < nb_input_streams; i++) ++ if ((ret = init_input_stream(i, output_streams, nb_output_streams, error, sizeof(error))) < 0) + goto dump_format; +- } +- copy_chapters(infile, outfile); +- } + +- /* copy chapters from the first input file that has them*/ +- if (!nb_chapter_maps) +- for (i = 0; i < nb_input_files; i++) { +- if (!input_files[i]->nb_chapters) +- continue; +- +- for (j = 0; j < nb_output_files; j++) +- if ((ret = copy_chapters(i, j)) < 0) +- goto dump_format; +- break; ++ /* discard unused programs */ ++ for (i = 0; i < nb_input_files; i++) { ++ InputFile *ifile = &input_files[i]; ++ for (j = 0; j < ifile->ctx->nb_programs; j++) { ++ AVProgram *p = ifile->ctx->programs[j]; ++ int discard = AVDISCARD_ALL; ++ ++ for (k = 0; k < p->nb_stream_indexes; k++) ++ if (!input_streams[ifile->ist_index + p->stream_index[k]].discard) { ++ discard = AVDISCARD_DEFAULT; ++ break; ++ } ++ p->discard = discard; + } ++ } + + /* open files and write file headers */ +- for(i=0;iinterrupt_callback = int_cb; ++ if (avformat_write_header(oc, &output_files[i].opts) < 0) { + snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); + ret = AVERROR(EINVAL); + goto dump_format; + } +- if (strcmp(output_files[i]->oformat->name, "rtp")) { ++// assert_avoptions(output_files[i].opts); ++ if (strcmp(oc->oformat->name, "rtp")) { + want_sdp = 0; + } + } +@@ -2477,252 +2753,369 @@ + dump_format: + /* dump the file output parameters - cannot be done before in case + of stream copy */ +- for(i=0;ifilename, 1); ++ for (i = 0; i < nb_output_files; i++) { ++ av_dump_format(output_files[i].ctx, i, output_files[i].ctx->filename, 1); + } + + /* dump the stream mapping */ +- if (verbose >= 0) { +- fprintf(stderr, "Stream mapping:\n"); +- for(i=0;i #%d.%d", +- ist_table[ost->source_index]->file_index, +- ist_table[ost->source_index]->index, +- ost->file_index, +- ost->index); +- if (ost->sync_ist != ist_table[ost->source_index]) +- fprintf(stderr, " [sync #%d.%d]", +- ost->sync_ist->file_index, +- ost->sync_ist->index); +- fprintf(stderr, "\n"); ++ av_log(NULL, AV_LOG_INFO, "Stream mapping:\n"); ++ for (i = 0; i < nb_output_streams; i++) { ++ ost = &output_streams[i]; ++ ++ if (ost->attachment_filename) { ++ /* an attached file */ ++ av_log(NULL, AV_LOG_INFO, " File %s -> Stream #%d:%d\n", ++ ost->attachment_filename, ost->file_index, ost->index); ++ continue; + } ++ av_log(NULL, AV_LOG_INFO, " Stream #%d:%d -> #%d:%d", ++ input_streams[ost->source_index].file_index, ++ input_streams[ost->source_index].st->index, ++ ost->file_index, ++ ost->index); ++ if (ost->audio_channels_mapped) { ++ av_log(NULL, AV_LOG_INFO, " [ch:"); ++ for (j = 0; j < ost->audio_channels_mapped; j++) ++ if (ost->audio_channels_map[j] == -1) ++ av_log(NULL, AV_LOG_INFO, " M"); ++ else ++ av_log(NULL, AV_LOG_INFO, " %d", ost->audio_channels_map[j]); ++ av_log(NULL, AV_LOG_INFO, "]"); ++ } ++ if (ost->sync_ist != &input_streams[ost->source_index]) ++ av_log(NULL, AV_LOG_INFO, " [sync #%d:%d]", ++ ost->sync_ist->file_index, ++ ost->sync_ist->st->index); ++ if (ost->stream_copy) ++ av_log(NULL, AV_LOG_INFO, " (copy)"); ++ else ++ av_log(NULL, AV_LOG_INFO, " (%s -> %s)", input_streams[ost->source_index].dec ? ++ input_streams[ost->source_index].dec->name : "?", ++ ost->enc ? ost->enc->name : "?"); ++ av_log(NULL, AV_LOG_INFO, "\n"); + } + + if (ret) { +- fprintf(stderr, "%s\n", error); +- goto fail; ++ av_log(NULL, AV_LOG_ERROR, "%s\n", error); ++ return ret; + } + + if (want_sdp) { + print_sdp(output_files, nb_output_files); + } + +- if (!using_stdin && verbose >= 0) { +- fprintf(stderr, "Press [q] to stop encoding\n"); +- url_set_interrupt_cb(decode_interrupt_cb); ++ return 0; ++} ++ ++/* ++ * The following code is the main loop of the file converter ++ */ ++static int transcode(OutputFile *output_files, int nb_output_files, ++ InputFile *input_files, int nb_input_files) ++{ ++ int ret, i; ++ AVFormatContext *is, *os; ++ OutputStream *ost; ++ InputStream *ist; ++ uint8_t *no_packet; ++ int no_packet_count = 0; ++ int64_t timer_start; ++ int key; ++ ++ if (!(no_packet = av_mallocz(nb_input_files))) ++ exit_program(1); ++ ++ ret = transcode_init(output_files, nb_output_files, input_files, nb_input_files); ++ if (ret < 0) ++ goto fail; ++ ++ if (!using_stdin) { ++ av_log(NULL, AV_LOG_INFO, "Press [q] to stop, [?] for help\n"); + } +- term_init(); + + timer_start = av_gettime(); + +- for(; received_sigterm == 0;) { ++ for (; received_sigterm == 0;) { + int file_index, ist_index; + AVPacket pkt; +- double ipts_min; ++ int64_t ipts_min; + double opts_min; ++ int64_t cur_time= av_gettime(); + +- redo: +- ipts_min= 1e100; +- opts_min= 1e100; ++ ipts_min = INT64_MAX; ++ opts_min = 1e100; + /* if 'q' pressed, exits */ + if (!using_stdin) { +- if (q_pressed) ++ static int64_t last_time; ++ if (received_nb_signals) + break; + /* read_key() returns 0 on EOF */ +- key = read_key(); ++ if(cur_time - last_time >= 100000 && !run_as_daemon){ ++ key = read_key(); ++ last_time = cur_time; ++ }else ++ key = -1; + if (key == 'q') + break; ++ if (key == '+') av_log_set_level(av_log_get_level()+10); ++ if (key == '-') av_log_set_level(av_log_get_level()-10); ++ if (key == 's') qp_hist ^= 1; ++ if (key == 'h'){ ++ if (do_hex_dump){ ++ do_hex_dump = do_pkt_dump = 0; ++ } else if(do_pkt_dump){ ++ do_hex_dump = 1; ++ } else ++ do_pkt_dump = 1; ++ av_log_set_level(AV_LOG_DEBUG); ++ } ++#if CONFIG_AVFILTER ++ if (key == 'c' || key == 'C'){ ++ char buf[4096], target[64], command[256], arg[256] = {0}; ++ double time; ++ int k, n = 0; ++ fprintf(stderr, "\nEnter command:
")) { ++ } else if (!av_strcasecmp(cmd, "
")) { + if (!stream) { + ERROR("No corresponding for \n"); + } else { +@@ -4584,7 +4557,7 @@ + } + stream = NULL; + } +- } else if (!strcasecmp(cmd, "stream_type = STREAM_TYPE_REDIRECT; + } +- } else if (!strcasecmp(cmd, "URL")) { ++ } else if (!av_strcasecmp(cmd, "URL")) { + if (redirect) + get_arg(redirect->feed_filename, sizeof(redirect->feed_filename), &p); +- } else if (!strcasecmp(cmd, "")) { ++ } else if (!av_strcasecmp(cmd, "")) { + if (!redirect) { + ERROR("No corresponding for \n"); + } else { +@@ -4612,7 +4585,7 @@ + } + redirect = NULL; + } +- } else if (!strcasecmp(cmd, "LoadModule")) { ++ } else if (!av_strcasecmp(cmd, "LoadModule")) { + get_arg(arg, sizeof(arg), &p); + #if HAVE_DLOPEN + load_module(arg); +@@ -4664,12 +4637,13 @@ + logfilename[0] = '-'; + } + +-static void show_help(void) ++static int opt_help(const char *opt, const char *arg) + { + printf("usage: ffserver [options]\n" + "Hyper fast multi format Audio/Video streaming server\n"); + printf("\n"); + show_help_options(options, "Main options:\n", 0, 0); ++ return 0; + } + + static const OptionDef options[] = { +@@ -4684,15 +4658,17 @@ + { + struct sigaction sigact; + ++ parse_loglevel(argc, argv, options); + av_register_all(); ++ avformat_network_init(); + +- show_banner(); ++ show_banner(argc, argv, options); + + my_program_name = argv[0]; + my_program_dir = getcwd(0, 0); + ffserver_daemon = 1; + +- parse_options(argc, argv, options, NULL); ++ parse_options(NULL, argc, argv, options, NULL); + + unsetenv("http_proxy"); /* Kill the http_proxy */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/ffserver.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/ffserver.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/ffserver.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/ffserver.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,28 +0,0 @@ +-/* +- * Multiple format streaming server +- * copyright (c) 2002 Fabrice Bellard +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +-#ifndef FFMPEG_FFSERVER_H +-#define FFMPEG_FFSERVER_H +- +-/* interface between ffserver and modules */ +- +-void ffserver_module_init(void); +- +-#endif /* FFMPEG_FFSERVER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/.gitignore xbmc-pvr-11.0.1.patch/lib/ffmpeg/.gitignore +--- xbmc-pvr-11.0.1/lib/ffmpeg/.gitignore 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/.gitignore 2012-05-14 14:08:53.067314482 +0200 +@@ -7,15 +7,25 @@ + *-example + *-test + *_g ++*.def ++*.dll ++*.lib ++*.exp + config.* + doc/*.1 + doc/*.html + doc/*.pod ++doc/fate.txt + doxy + ffmpeg + ffplay + ffprobe + ffserver ++avconv ++libavcodec/*_tablegen ++libavcodec/*_tables.c ++libavcodec/*_tables.h ++libavcodec/codec_names.h + libavcodec/libavcodec* + libavcore/libavcore* + libavdevice/libavdevice* +@@ -24,27 +34,23 @@ + libavutil/avconfig.h + libavutil/libavutil* + libpostproc/libpostproc* ++libswresample/libswresample* + libswscale/libswscale* + tests/audiogen + tests/base64 + tests/data + tests/rotozoom +-tests/seek_test + tests/tiny_psnr + tests/videogen + tests/vsynth1 + tests/vsynth2 ++tools/aviocat + tools/cws2fws + tools/graph2dot ++tools/ismindex + tools/lavfi-showfiltfmts + tools/pktdumper + tools/probetest + tools/qt-faststart + tools/trasher +-tools/trasher*.d + version.h +- +-# ignore Windows build files +-*.def +-*.dll +-*.lib +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/INSTALL xbmc-pvr-11.0.1.patch/lib/ffmpeg/INSTALL +--- xbmc-pvr-11.0.1/lib/ffmpeg/INSTALL 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/INSTALL 2012-05-14 14:08:53.097315086 +0200 +@@ -9,3 +9,7 @@ + 2) Then type 'make' to build FFmpeg. GNU Make 3.81 or later is required. + + 3) Type 'make install' to install all binaries and libraries you built. ++ ++NOTICE ++ ++ - Non system dependencies (e.g. libx264, libvpx) are disabled by default. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/4xm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/4xm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/4xm.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/4xm.c 2012-05-14 14:08:53.270318568 +0200 +@@ -132,8 +132,8 @@ + AVFrame current_picture, last_picture; + GetBitContext pre_gb; ///< ac/dc prefix + GetBitContext gb; +- const uint8_t *bytestream; +- const uint16_t *wordstream; ++ GetByteContext g; ++ GetByteContext g2; + int mv[256]; + VLC pre_vlc; + int last_dc; +@@ -277,7 +277,7 @@ + } + #endif + +-static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, int dc){ ++static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w, int h, int stride, int scale, unsigned dc){ + int i; + dc*= 0x10001; + +@@ -328,7 +328,11 @@ + assert(code>=0 && code<=6); + + if(code == 0){ +- src += f->mv[ *f->bytestream++ ]; ++ if (f->g.buffer_end - f->g.buffer < 1){ ++ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); ++ return; ++ } ++ src += f->mv[ *f->g.buffer++ ]; + if(start > src || src > end){ + av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); + return; +@@ -345,21 +349,37 @@ + }else if(code == 3 && f->version<2){ + mcdc(dst, src, log2w, h, stride, 1, 0); + }else if(code == 4){ +- src += f->mv[ *f->bytestream++ ]; ++ if (f->g.buffer_end - f->g.buffer < 1){ ++ av_log(f->avctx, AV_LOG_ERROR, "bytestream overread\n"); ++ return; ++ } ++ src += f->mv[ *f->g.buffer++ ]; + if(start > src || src > end){ + av_log(f->avctx, AV_LOG_ERROR, "mv out of pic\n"); + return; + } +- mcdc(dst, src, log2w, h, stride, 1, av_le2ne16(*f->wordstream++)); ++ if (f->g2.buffer_end - f->g2.buffer < 1){ ++ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); ++ return; ++ } ++ mcdc(dst, src, log2w, h, stride, 1, bytestream2_get_le16(&f->g2)); + }else if(code == 5){ +- mcdc(dst, src, log2w, h, stride, 0, av_le2ne16(*f->wordstream++)); ++ if (f->g2.buffer_end - f->g2.buffer < 1){ ++ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); ++ return; ++ } ++ mcdc(dst, src, log2w, h, stride, 0, bytestream2_get_le16(&f->g2)); + }else if(code == 6){ ++ if (f->g2.buffer_end - f->g2.buffer < 2){ ++ av_log(f->avctx, AV_LOG_ERROR, "wordstream overread\n"); ++ return; ++ } + if(log2w){ +- dst[0] = av_le2ne16(*f->wordstream++); +- dst[1] = av_le2ne16(*f->wordstream++); ++ dst[0] = bytestream2_get_le16(&f->g2); ++ dst[1] = bytestream2_get_le16(&f->g2); + }else{ +- dst[0 ] = av_le2ne16(*f->wordstream++); +- dst[stride] = av_le2ne16(*f->wordstream++); ++ dst[0 ] = bytestream2_get_le16(&f->g2); ++ dst[stride] = bytestream2_get_le16(&f->g2); + } + } + } +@@ -371,10 +391,12 @@ + uint16_t *src= (uint16_t*)f->last_picture.data[0]; + uint16_t *dst= (uint16_t*)f->current_picture.data[0]; + const int stride= f->current_picture.linesize[0]>>1; +- unsigned int bitstream_size, bytestream_size, wordstream_size, extra; ++ unsigned int bitstream_size, bytestream_size, wordstream_size, extra, bytestream_offset, wordstream_offset; + + if(f->version>1){ + extra=20; ++ if (length < extra) ++ return -1; + bitstream_size= AV_RL32(buf+8); + wordstream_size= AV_RL32(buf+12); + bytestream_size= AV_RL32(buf+16); +@@ -385,11 +407,10 @@ + bytestream_size= FFMAX(length - bitstream_size - wordstream_size, 0); + } + +- if(bitstream_size+ bytestream_size+ wordstream_size + extra != length +- || bitstream_size > (1<<26) +- || bytestream_size > (1<<26) +- || wordstream_size > (1<<26) +- ){ ++ if (bitstream_size > length || ++ bytestream_size > length - bitstream_size || ++ wordstream_size > length - bytestream_size - bitstream_size || ++ extra > length - bytestream_size - bitstream_size - wordstream_size){ + av_log(f->avctx, AV_LOG_ERROR, "lengths %d %d %d %d\n", bitstream_size, bytestream_size, wordstream_size, + bitstream_size+ bytestream_size+ wordstream_size - length); + return -1; +@@ -399,10 +420,13 @@ + if (!f->bitstream_buffer) + return AVERROR(ENOMEM); + f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra), bitstream_size/4); ++ memset((uint8_t*)f->bitstream_buffer + bitstream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&f->gb, f->bitstream_buffer, 8*bitstream_size); + +- f->wordstream= (const uint16_t*)(buf + extra + bitstream_size); +- f->bytestream= buf + extra + bitstream_size + wordstream_size; ++ wordstream_offset = extra + bitstream_size; ++ bytestream_offset = extra + bitstream_size + wordstream_size; ++ bytestream2_init(&f->g2, buf + wordstream_offset, length - wordstream_offset); ++ bytestream2_init(&f->g, buf + bytestream_offset, length - bytestream_offset); + + init_mv(f); + +@@ -414,15 +438,6 @@ + dst += 8*stride; + } + +- if( bitstream_size != (get_bits_count(&f->gb)+31)/32*4 +- || (((const char*)f->wordstream - (const char*)buf + 2)&~2) != extra + bitstream_size + wordstream_size +- || (((const char*)f->bytestream - (const char*)buf + 3)&~3) != extra + bitstream_size + wordstream_size + bytestream_size) +- av_log(f->avctx, AV_LOG_ERROR, " %d %td %td bytes left\n", +- bitstream_size - (get_bits_count(&f->gb)+31)/32*4, +- -(((const char*)f->bytestream - (const char*)buf + 3)&~3) + (extra + bitstream_size + wordstream_size + bytestream_size), +- -(((const char*)f->wordstream - (const char*)buf + 2)&~2) + (extra + bitstream_size + wordstream_size) +- ); +- + return 0; + } + +@@ -433,6 +448,11 @@ + static int decode_i_block(FourXContext *f, DCTELEM *block){ + int code, i, j, level, val; + ++ if(get_bits_left(&f->gb) < 2){ ++ av_log(f->avctx, AV_LOG_ERROR, "%d bits left before decode_i_block()\n", get_bits_left(&f->gb)); ++ return -1; ++ } ++ + /* DC coef */ + val = get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3); + if (val>>4){ +@@ -531,7 +551,7 @@ + return 0; + } + +-static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf){ ++static const uint8_t *read_huffman_tables(FourXContext *f, const uint8_t * const buf, int buf_size){ + int frequency[512]; + uint8_t flag[512]; + int up[512]; +@@ -539,6 +559,7 @@ + int bits_tab[257]; + int start, end; + const uint8_t *ptr= buf; ++ const uint8_t *ptr_end = buf + buf_size; + int j; + + memset(frequency, 0, sizeof(frequency)); +@@ -549,6 +570,8 @@ + for(;;){ + int i; + ++ if (start <= end && ptr_end - ptr < end - start + 1 + 1) ++ return NULL; + for(i=start; i<=end; i++){ + frequency[i]= *ptr++; + } +@@ -601,9 +624,10 @@ + len_tab[j]= len; + } + +- init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, +- len_tab , 1, 1, +- bits_tab, 4, 4, 0); ++ if (init_vlc(&f->pre_vlc, ACDC_VLC_BITS, 257, ++ len_tab , 1, 1, ++ bits_tab, 4, 4, 0)) ++ return NULL; + + return ptr; + } +@@ -619,16 +643,27 @@ + int x, y, x2, y2; + const int width= f->avctx->width; + const int height= f->avctx->height; ++ const int mbs = (FFALIGN(width, 16) >> 4) * (FFALIGN(height, 16) >> 4); + uint16_t *dst= (uint16_t*)f->current_picture.data[0]; + const int stride= f->current_picture.linesize[0]>>1; ++ const uint8_t *buf_end = buf + length; ++ GetByteContext g3; ++ ++ if(length < mbs * 8) { ++ av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ bytestream2_init(&g3, buf, length); + + for(y=0; y>2) + 8*(y2>>2); +@@ -645,7 +680,7 @@ + } + dst+=16; + } +- dst += 16*stride - width; ++ dst += 16 * stride - x; + } + + return 0; +@@ -655,21 +690,27 @@ + int x, y; + const int width= f->avctx->width; + const int height= f->avctx->height; +- uint16_t *dst= (uint16_t*)f->current_picture.data[0]; +- const int stride= f->current_picture.linesize[0]>>1; + const unsigned int bitstream_size= AV_RL32(buf); +- const int token_count av_unused = AV_RL32(buf + bitstream_size + 8); +- unsigned int prestream_size= 4*AV_RL32(buf + bitstream_size + 4); +- const uint8_t *prestream= buf + bitstream_size + 12; +- +- if(prestream_size + bitstream_size + 12 != length +- || bitstream_size > (1<<26) +- || prestream_size > (1<<26)){ ++ unsigned int prestream_size; ++ const uint8_t *prestream; ++ ++ if (bitstream_size > (1<<26) || length < bitstream_size + 12) { ++ av_log(f->avctx, AV_LOG_ERROR, "packet size too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ prestream_size = 4 * AV_RL32(buf + bitstream_size + 4); ++ prestream = buf + bitstream_size + 12; ++ ++ if (prestream_size > (1<<26) || ++ prestream_size != length - (bitstream_size + 12)){ + av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d %d\n", prestream_size, bitstream_size, length); + return -1; + } + +- prestream= read_huffman_tables(f, prestream); ++ prestream= read_huffman_tables(f, prestream, buf + length - prestream); ++ if (!prestream) ++ return -1; + + init_get_bits(&f->gb, buf + 4, 8*bitstream_size); + +@@ -679,6 +720,7 @@ + if (!f->bitstream_buffer) + return AVERROR(ENOMEM); + f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream, prestream_size/4); ++ memset((uint8_t*)f->bitstream_buffer + prestream_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&f->pre_gb, f->bitstream_buffer, 8*prestream_size); + + f->last_dc= 0*128*8*8; +@@ -690,7 +732,6 @@ + + idct_put(f, x, y); + } +- dst += 16*stride; + } + + if(get_vlc2(&f->pre_gb, f->pre_vlc.table, ACDC_VLC_BITS, 3) != 256) +@@ -710,6 +751,8 @@ + AVFrame *p, temp; + int i, frame_4cc, frame_size; + ++ if (buf_size < 12) ++ return AVERROR_INVALIDDATA; + frame_4cc= AV_RL32(buf); + if(buf_size != AV_RL32(buf+4)+8 || buf_size < 20){ + av_log(f->avctx, AV_LOG_ERROR, "size mismatch %d %d\n", buf_size, AV_RL32(buf+4)); +@@ -722,6 +765,11 @@ + const int whole_size= AV_RL32(buf+16); + CFrameBuffer *cfrm; + ++ if (data_size < 0 || whole_size < 0){ ++ av_log(f->avctx, AV_LOG_ERROR, "sizes invalid\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ + for(i=0; icfrm[i].id && f->cfrm[i].id < avctx->frame_number) + av_log(f->avctx, AV_LOG_ERROR, "lost c frame %d\n", f->cfrm[i].id); +@@ -738,6 +786,8 @@ + } + cfrm= &f->cfrm[i]; + ++ if (data_size > UINT_MAX - cfrm->size - FF_INPUT_BUFFER_PADDING_SIZE) ++ return AVERROR_INVALIDDATA; + cfrm->data= av_fast_realloc(cfrm->data, &cfrm->allocated_size, cfrm->size + data_size + FF_INPUT_BUFFER_PADDING_SIZE); + if(!cfrm->data){ //explicit check needed as memcpy below might not catch a NULL + av_log(f->avctx, AV_LOG_ERROR, "realloc falure"); +@@ -773,42 +823,45 @@ + + avctx->flags |= CODEC_FLAG_EMU_EDGE; // alternatively we would have to use our own buffer management + +- if(p->data[0]) +- avctx->release_buffer(avctx, p); +- +- p->reference= 1; +- if(avctx->get_buffer(avctx, p) < 0){ +- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ p->reference= 3; ++ if (avctx->reget_buffer(avctx, p) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + + if(frame_4cc == AV_RL32("ifr2")){ +- p->pict_type= FF_I_TYPE; +- if(decode_i2_frame(f, buf-4, frame_size) < 0) ++ p->pict_type= AV_PICTURE_TYPE_I; ++ if(decode_i2_frame(f, buf-4, frame_size + 4) < 0) { ++ av_log(f->avctx, AV_LOG_ERROR, "decode i2 frame failed\n"); + return -1; ++ } + }else if(frame_4cc == AV_RL32("ifrm")){ +- p->pict_type= FF_I_TYPE; +- if(decode_i_frame(f, buf, frame_size) < 0) ++ p->pict_type= AV_PICTURE_TYPE_I; ++ if(decode_i_frame(f, buf, frame_size) < 0){ ++ av_log(f->avctx, AV_LOG_ERROR, "decode i frame failed\n"); + return -1; ++ } + }else if(frame_4cc == AV_RL32("pfrm") || frame_4cc == AV_RL32("pfr2")){ + if(!f->last_picture.data[0]){ +- f->last_picture.reference= 1; ++ f->last_picture.reference= 3; + if(avctx->get_buffer(avctx, &f->last_picture) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + } + +- p->pict_type= FF_P_TYPE; +- if(decode_p_frame(f, buf, frame_size) < 0) ++ p->pict_type= AV_PICTURE_TYPE_P; ++ if(decode_p_frame(f, buf, frame_size) < 0){ ++ av_log(f->avctx, AV_LOG_ERROR, "decode p frame failed\n"); + return -1; ++ } + }else if(frame_4cc == AV_RL32("snd_")){ + av_log(avctx, AV_LOG_ERROR, "ignoring snd_ chunk length:%d\n", buf_size); + }else{ + av_log(avctx, AV_LOG_ERROR, "ignoring unknown chunk length:%d\n", buf_size); + } + +- p->key_frame= p->pict_type == FF_I_TYPE; ++ p->key_frame= p->pict_type == AV_PICTURE_TYPE_I; + + *picture= *p; + *data_size = sizeof(AVPicture); +@@ -834,7 +887,13 @@ + av_log(avctx, AV_LOG_ERROR, "extradata wrong or missing\n"); + return 1; + } ++ if((avctx->width % 16) || (avctx->height % 16)) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported width/height\n"); ++ return AVERROR_INVALIDDATA; ++ } + ++ avcodec_get_frame_defaults(&f->current_picture); ++ avcodec_get_frame_defaults(&f->last_picture); + f->version= AV_RL32(avctx->extradata)>>16; + common_init(avctx); + init_vlcs(f); +@@ -866,15 +925,14 @@ + } + + AVCodec ff_fourxm_decoder = { +- "4xm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_4XM, +- sizeof(FourXContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "4xm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_4XM, ++ .priv_data_size = sizeof(FourXContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("4X Movie"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/8bps.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/8bps.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/8bps.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/8bps.c 2012-05-14 14:08:53.271318588 +0200 +@@ -27,7 +27,7 @@ + * + * Supports: PAL8 (RGB 8bpp, paletted) + * : BGR24 (RGB 24bpp) (can also output it as RGB32) +- * : RGB32 (RGB 32bpp, 4th plane is probably alpha and it's ignored) ++ * : RGB32 (RGB 32bpp, 4th plane is alpha) + * + */ + +@@ -50,6 +50,8 @@ + + unsigned char planes; + unsigned char planemap[4]; ++ ++ uint32_t pal[256]; + } EightBpsContext; + + +@@ -69,7 +71,6 @@ + unsigned int dlen, p, row; + const unsigned char *lp, *dp; + unsigned char count; +- unsigned int px_inc; + unsigned int planes = c->planes; + unsigned char *planemap = c->planemap; + +@@ -86,12 +87,6 @@ + /* Set data pointer after line lengths */ + dp = encoded + planes * (height << 1); + +- /* Ignore alpha plane, don't know what to do with it */ +- if (planes == 4) +- planes--; +- +- px_inc = planes + (avctx->pix_fmt == PIX_FMT_RGB32); +- + for (p = 0; p < planes; p++) { + /* Lines length pointer for this plane */ + lp = encoded + p * (height << 1); +@@ -107,20 +102,20 @@ + if ((count = *dp++) <= 127) { + count++; + dlen -= count + 1; +- if (pixptr + count * px_inc > pixptr_end) ++ if (pixptr + count * planes > pixptr_end) + break; + if(dp + count > buf+buf_size) return -1; + while(count--) { + *pixptr = *dp++; +- pixptr += px_inc; ++ pixptr += planes; + } + } else { + count = 257 - count; +- if (pixptr + count * px_inc > pixptr_end) ++ if (pixptr + count * planes > pixptr_end) + break; + while(count--) { + *pixptr = *dp; +- pixptr += px_inc; ++ pixptr += planes; + } + dp++; + dlen -= 2; +@@ -129,13 +124,16 @@ + } + } + +- if (avctx->palctrl) { +- memcpy (c->pic.data[1], avctx->palctrl->palette, AVPALETTE_SIZE); +- if (avctx->palctrl->palette_changed) { ++ if (avctx->bits_per_coded_sample <= 8) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, ++ AV_PKT_DATA_PALETTE, ++ NULL); ++ if (pal) { + c->pic.palette_has_changed = 1; +- avctx->palctrl->palette_changed = 0; +- } else +- c->pic.palette_has_changed = 0; ++ memcpy(c->pal, pal, AVPALETTE_SIZE); ++ } ++ ++ memcpy (c->pic.data[1], c->pal, AVPALETTE_SIZE); + } + + *data_size = sizeof(AVFrame); +@@ -157,6 +155,7 @@ + + c->avctx = avctx; + ++ avcodec_get_frame_defaults(&c->pic); + c->pic.data[0] = NULL; + + switch (avctx->bits_per_coded_sample) { +@@ -164,10 +163,6 @@ + avctx->pix_fmt = PIX_FMT_PAL8; + c->planes = 1; + c->planemap[0] = 0; // 1st plane is palette indexes +- if (avctx->palctrl == NULL) { +- av_log(avctx, AV_LOG_ERROR, "Error: PAL8 format but no palette from demuxer.\n"); +- return -1; +- } + break; + case 24: + avctx->pix_fmt = avctx->get_format(avctx, pixfmt_rgb24); +@@ -183,12 +178,12 @@ + c->planemap[0] = 1; // 1st plane is red + c->planemap[1] = 2; // 2nd plane is green + c->planemap[2] = 3; // 3rd plane is blue +- c->planemap[3] = 0; // 4th plane is alpha??? ++ c->planemap[3] = 0; // 4th plane is alpha + #else + c->planemap[0] = 2; // 1st plane is red + c->planemap[1] = 1; // 2nd plane is green + c->planemap[2] = 0; // 3rd plane is blue +- c->planemap[3] = 3; // 4th plane is alpha??? ++ c->planemap[3] = 3; // 4th plane is alpha + #endif + break; + default: +@@ -220,14 +215,13 @@ + + + AVCodec ff_eightbps_decoder = { +- "8bps", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_8BPS, +- sizeof(EightBpsContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, +- .long_name = NULL_IF_CONFIG_SMALL("QuickTime 8BPS video"), ++ .name = "8bps", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_8BPS, ++ .priv_data_size = sizeof(EightBpsContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("QuickTime 8BPS video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/8svx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/8svx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/8svx.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/8svx.c 2012-05-14 14:08:53.272318608 +0200 +@@ -1,6 +1,6 @@ + /* +- * 8SVX audio decoder + * Copyright (C) 2008 Jaikrishnan Menon ++ * Copyright (C) 2011 Stefano Sabatini + * + * This file is part of FFmpeg. + * +@@ -23,72 +23,188 @@ + * @file + * 8svx audio decoder + * @author Jaikrishnan Menon ++ * + * supports: fibonacci delta encoding + * : exponential encoding ++ * ++ * For more information about the 8SVX format: ++ * http://netghost.narod.ru/gff/vendspec/iff/iff.txt ++ * http://sox.sourceforge.net/AudioFormats-11.html ++ * http://aminet.net/package/mus/misc/wavepak ++ * http://amigan.1emu.net/reg/8SVX.txt ++ * ++ * Samples can be found here: ++ * http://aminet.net/mods/smpl/ + */ + + #include "avcodec.h" + + /** decoder context */ + typedef struct EightSvxContext { +- int16_t fib_acc; +- const int16_t *table; ++ AVFrame frame; ++ const int8_t *table; ++ ++ /* buffer used to store the whole audio decoded/interleaved chunk, ++ * which is sent with the first packet */ ++ uint8_t *samples; ++ size_t samples_size; ++ int samples_idx; + } EightSvxContext; + +-static const int16_t fibonacci[16] = { -34<<8, -21<<8, -13<<8, -8<<8, -5<<8, -3<<8, -2<<8, -1<<8, +- 0, 1<<8, 2<<8, 3<<8, 5<<8, 8<<8, 13<<8, 21<<8 }; +-static const int16_t exponential[16] = { -128<<8, -64<<8, -32<<8, -16<<8, -8<<8, -4<<8, -2<<8, -1<<8, +- 0, 1<<8, 2<<8, 4<<8, 8<<8, 16<<8, 32<<8, 64<<8 }; ++static const int8_t fibonacci[16] = { -34, -21, -13, -8, -5, -3, -2, -1, 0, 1, 2, 3, 5, 8, 13, 21 }; ++static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0, 1, 2, 4, 8, 16, 32, 64 }; + +-/** decode a frame */ +-static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, +- AVPacket *avpkt) ++#define MAX_FRAME_SIZE 2048 ++ ++/** ++ * Interleave samples in buffer containing all left channel samples ++ * at the beginning, and right channel samples at the end. ++ * Each sample is assumed to be in signed 8-bit format. ++ * ++ * @param size the size in bytes of the dst and src buffer ++ */ ++static void interleave_stereo(uint8_t *dst, const uint8_t *src, int size) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- EightSvxContext *esc = avctx->priv_data; +- int16_t *out_data = data; +- int consumed = buf_size; +- const uint8_t *buf_end = buf + buf_size; ++ uint8_t *dst_end = dst + size; ++ size = size>>1; + +- if((*data_size >> 2) < buf_size) +- return -1; ++ while (dst < dst_end) { ++ *dst++ = *src; ++ *dst++ = *(src+size); ++ src++; ++ } ++} + +- if(avctx->frame_number == 0) { +- esc->fib_acc = buf[1] << 8; +- buf_size -= 2; +- buf += 2; ++/** ++ * Delta decode the compressed values in src, and put the resulting ++ * decoded n samples in dst. ++ * ++ * @param val starting value assumed by the delta sequence ++ * @param table delta sequence table ++ * @return size in bytes of the decoded data, must be src_size*2 ++ */ ++static int delta_decode(int8_t *dst, const uint8_t *src, int src_size, ++ int8_t val, const int8_t *table) ++{ ++ int n = src_size; ++ int8_t *dst0 = dst; ++ ++ while (n--) { ++ uint8_t d = *src++; ++ val = av_clip(val + table[d & 0x0f], -127, 128); ++ *dst++ = val; ++ val = av_clip(val + table[d >> 4] , -127, 128); ++ *dst++ = val; + } + +- *data_size = buf_size << 2; ++ return dst-dst0; ++} ++ ++/** decode a frame */ ++static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ EightSvxContext *esc = avctx->priv_data; ++ int n, out_data_size, ret; ++ uint8_t *src, *dst; ++ ++ /* decode and interleave the first packet */ ++ if (!esc->samples && avpkt) { ++ uint8_t *deinterleaved_samples, *p = NULL; ++ ++ esc->samples_size = avctx->codec->id == CODEC_ID_8SVX_RAW || avctx->codec->id ==CODEC_ID_PCM_S8_PLANAR? ++ avpkt->size : avctx->channels + (avpkt->size-avctx->channels) * 2; ++ if (!(esc->samples = av_malloc(esc->samples_size))) ++ return AVERROR(ENOMEM); ++ ++ /* decompress */ ++ if (avctx->codec->id == CODEC_ID_8SVX_FIB || avctx->codec->id == CODEC_ID_8SVX_EXP) { ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int n = esc->samples_size; ++ ++ if (buf_size < 2) { ++ av_log(avctx, AV_LOG_ERROR, "packet size is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ if (!(deinterleaved_samples = av_mallocz(n))) ++ return AVERROR(ENOMEM); ++ p = deinterleaved_samples; ++ ++ /* the uncompressed starting value is contained in the first byte */ ++ if (avctx->channels == 2) { ++ delta_decode(deinterleaved_samples , buf+1, buf_size/2-1, buf[0], esc->table); ++ buf += buf_size/2; ++ delta_decode(deinterleaved_samples+n/2-1, buf+1, buf_size/2-1, buf[0], esc->table); ++ } else ++ delta_decode(deinterleaved_samples , buf+1, buf_size-1 , buf[0], esc->table); ++ } else { ++ deinterleaved_samples = avpkt->data; ++ } ++ ++ if (avctx->channels == 2) ++ interleave_stereo(esc->samples, deinterleaved_samples, esc->samples_size); ++ else ++ memcpy(esc->samples, deinterleaved_samples, esc->samples_size); ++ av_freep(&p); ++ } + +- while(buf < buf_end) { +- uint8_t d = *buf++; +- esc->fib_acc += esc->table[d & 0x0f]; +- *out_data++ = esc->fib_acc; +- esc->fib_acc += esc->table[d >> 4]; +- *out_data++ = esc->fib_acc; ++ /* get output buffer */ ++ esc->frame.nb_samples = (FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx) +avctx->channels-1) / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } + +- return consumed; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = esc->frame; ++ ++ dst = esc->frame.data[0]; ++ src = esc->samples + esc->samples_idx; ++ out_data_size = esc->frame.nb_samples * avctx->channels; ++ for (n = out_data_size; n > 0; n--) ++ *dst++ = *src++ + 128; ++ esc->samples_idx += out_data_size; ++ ++ return avctx->codec->id == CODEC_ID_8SVX_FIB || avctx->codec->id == CODEC_ID_8SVX_EXP ? ++ (avctx->frame_number == 0)*2 + out_data_size / 2 : ++ out_data_size; + } + +-/** initialize 8svx decoder */ + static av_cold int eightsvx_decode_init(AVCodecContext *avctx) + { + EightSvxContext *esc = avctx->priv_data; + +- switch(avctx->codec->id) { +- case CODEC_ID_8SVX_FIB: +- esc->table = fibonacci; +- break; +- case CODEC_ID_8SVX_EXP: +- esc->table = exponential; +- break; +- default: +- return -1; ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ switch (avctx->codec->id) { ++ case CODEC_ID_8SVX_FIB: esc->table = fibonacci; break; ++ case CODEC_ID_8SVX_EXP: esc->table = exponential; break; ++ case CODEC_ID_PCM_S8_PLANAR: ++ case CODEC_ID_8SVX_RAW: esc->table = NULL; break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Invalid codec id %d.\n", avctx->codec->id); ++ return AVERROR_INVALIDDATA; + } +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ avctx->sample_fmt = AV_SAMPLE_FMT_U8; ++ ++ avcodec_get_frame_defaults(&esc->frame); ++ avctx->coded_frame = &esc->frame; ++ ++ return 0; ++} ++ ++static av_cold int eightsvx_decode_close(AVCodecContext *avctx) ++{ ++ EightSvxContext *esc = avctx->priv_data; ++ ++ av_freep(&esc->samples); ++ esc->samples_size = 0; ++ esc->samples_idx = 0; ++ + return 0; + } + +@@ -99,6 +215,8 @@ + .priv_data_size = sizeof (EightSvxContext), + .init = eightsvx_decode_init, + .decode = eightsvx_decode_frame, ++ .close = eightsvx_decode_close, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("8SVX fibonacci"), + }; + +@@ -109,5 +227,19 @@ + .priv_data_size = sizeof (EightSvxContext), + .init = eightsvx_decode_init, + .decode = eightsvx_decode_frame, ++ .close = eightsvx_decode_close, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("8SVX exponential"), + }; ++ ++AVCodec ff_pcm_s8_planar_decoder = { ++ .name = "pcm_s8_planar", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_PCM_S8_PLANAR, ++ .priv_data_size = sizeof(EightSvxContext), ++ .init = eightsvx_decode_init, ++ .close = eightsvx_decode_close, ++ .decode = eightsvx_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/a64multienc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/a64multienc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/a64multienc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/a64multienc.c 2012-05-14 14:08:53.277318708 +0200 +@@ -216,7 +216,7 @@ + + avcodec_get_frame_defaults(&c->picture); + avctx->coded_frame = &c->picture; +- avctx->coded_frame->pict_type = FF_I_TYPE; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; + if (!avctx->codec_tag) + avctx->codec_tag = AV_RL32("a64m"); +@@ -252,7 +252,6 @@ + int b_width; + + int req_size; +- int num_frames = c->mc_lifetime; + + int *charmap = c->mc_charmap; + uint8_t *colram = c->mc_colram; +@@ -280,7 +279,6 @@ + if (!c->mc_lifetime) return 0; + /* no more frames in queue, prepare to flush remaining frames */ + if (!c->mc_frame_counter) { +- num_frames = c->mc_lifetime; + c->mc_lifetime = 0; + } + /* still frames in queue so limit lifetime to remaining frames */ +@@ -290,7 +288,7 @@ + /* fill up mc_meta_charset with data until lifetime exceeds */ + if (c->mc_frame_counter < c->mc_lifetime) { + *p = *pict; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + to_meta_with_crop(avctx, p, meta + 32000 * c->mc_frame_counter); + c->mc_frame_counter++; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_ac3_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_ac3_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_ac3_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_ac3_parser.c 2012-05-14 14:08:53.279318748 +0200 +@@ -94,6 +94,7 @@ + avctx->channel_layout = s->channel_layout; + } + avctx->frame_size = s->samples; ++ avctx->audio_service_type = s->service_type; + } + + avctx->bit_rate = s->bit_rate; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_ac3_parser.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_ac3_parser.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_ac3_parser.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_ac3_parser.h 2012-05-14 14:08:53.282318809 +0200 +@@ -48,7 +48,8 @@ + int sample_rate; + int bit_rate; + int samples; +- int64_t channel_layout; ++ uint64_t channel_layout; ++ int service_type; + + int remaining_size; + uint64_t state; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacadtsdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacadtsdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacadtsdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacadtsdec.c 2012-05-14 14:08:53.285318869 +0200 +@@ -26,7 +26,7 @@ + #include "get_bits.h" + #include "mpeg4audio.h" + +-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) ++int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr) + { + int size, rdb, ch, sr; + int aot, crc_abs; +@@ -39,7 +39,7 @@ + crc_abs = get_bits1(gbc); /* protection_absent */ + aot = get_bits(gbc, 2); /* profile_objecttype */ + sr = get_bits(gbc, 4); /* sample_frequency_index */ +- if(!ff_mpeg4audio_sample_rates[sr]) ++ if(!avpriv_mpeg4audio_sample_rates[sr]) + return AAC_AC3_PARSE_ERROR_SAMPLE_RATE; + skip_bits1(gbc); /* private_bit */ + ch = get_bits(gbc, 3); /* channel_configuration */ +@@ -62,7 +62,7 @@ + hdr->crc_absent = crc_abs; + hdr->num_aac_frames = rdb + 1; + hdr->sampling_index = sr; +- hdr->sample_rate = ff_mpeg4audio_sample_rates[sr]; ++ hdr->sample_rate = avpriv_mpeg4audio_sample_rates[sr]; + hdr->samples = (rdb + 1) * 1024; + hdr->bit_rate = size * 8 * hdr->sample_rate / hdr->samples; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacadtsdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacadtsdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacadtsdec.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacadtsdec.h 2012-05-14 14:08:53.286318889 +0200 +@@ -49,6 +49,6 @@ + * -2 if the version element is invalid, -3 if the sample rate + * element is invalid, or -4 if the bit rate element is invalid. + */ +-int ff_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr); ++int avpriv_aac_parse_header(GetBitContext *gbc, AACADTSHeaderInfo *hdr); + + #endif /* AVCODEC_AACADTSDEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_adtstoasc_bsf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_adtstoasc_bsf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_adtstoasc_bsf.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_adtstoasc_bsf.c 2012-05-14 14:08:53.283318829 +0200 +@@ -55,7 +55,7 @@ + if (show_bits(&gb, 12) != 0xfff) + return 0; + +- if (ff_aac_parse_header(&gb, &hdr) < 0) { ++ if (avpriv_aac_parse_header(&gb, &hdr) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error parsing ADTS frame header!\n"); + return -1; + } +@@ -72,13 +72,13 @@ + int pce_size = 0; + uint8_t pce_data[MAX_PCE_SIZE]; + if (!hdr.chan_config) { +- init_get_bits(&gb, buf, buf_size); ++ init_get_bits(&gb, buf, buf_size * 8); + if (get_bits(&gb, 3) != 5) { + av_log_missing_feature(avctx, "PCE based channel configuration, where the PCE is not the first syntax element is", 0); + return -1; + } + init_put_bits(&pb, pce_data, MAX_PCE_SIZE); +- pce_size = ff_copy_pce_data(&pb, &gb)/8; ++ pce_size = avpriv_copy_pce_data(&pb, &gb)/8; + flush_put_bits(&pb); + buf_size -= get_bits_count(&gb)/8; + buf += get_bits_count(&gb)/8; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aaccoder.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aaccoder.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aaccoder.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aaccoder.c 2012-05-14 14:08:53.288318929 +0200 +@@ -30,7 +30,10 @@ + * add sane pulse detection + ***********************************/ + ++#include "libavutil/libm.h" // brought forward to work around cygwin header breakage ++ + #include ++#include "libavutil/mathematics.h" + #include "avcodec.h" + #include "put_bits.h" + #include "aac.h" +@@ -107,14 +110,15 @@ + int *bits, int BT_ZERO, int BT_UNSIGNED, + int BT_PAIR, int BT_ESC) + { +- const float IQ = ff_aac_pow2sf_tab[200 + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; +- const float Q = ff_aac_pow2sf_tab[200 - scale_idx + SCALE_ONE_POS - SCALE_DIV_512]; ++ const int q_idx = POW_SF2_ZERO - scale_idx + SCALE_ONE_POS - SCALE_DIV_512; ++ const float Q = ff_aac_pow2sf_tab [q_idx]; ++ const float Q34 = ff_aac_pow34sf_tab[q_idx]; ++ const float IQ = ff_aac_pow2sf_tab [POW_SF2_ZERO + scale_idx - SCALE_ONE_POS + SCALE_DIV_512]; + const float CLIPPED_ESCAPE = 165140.0f*IQ; +- int i, j, k; ++ int i, j; + float cost = 0; + const int dim = BT_PAIR ? 2 : 4; + int resbits = 0; +- const float Q34 = sqrtf(Q * sqrtf(Q)); + const int range = aac_cb_range[cb]; + const int maxval = aac_cb_maxval[cb]; + int off; +@@ -146,34 +150,34 @@ + curidx *= range; + curidx += quants[j] + off; + } +- curbits = ff_aac_spectral_bits[cb-1][curidx]; +- vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; +- if (BT_UNSIGNED) { +- for (k = 0; k < dim; k++) { +- float t = fabsf(in[i+k]); +- float di; +- if (BT_ESC && vec[k] == 64.0f) { //FIXME: slow +- if (t >= CLIPPED_ESCAPE) { +- di = t - CLIPPED_ESCAPE; +- curbits += 21; +- } else { +- int c = av_clip(quant(t, Q), 0, 8191); +- di = t - c*cbrtf(c)*IQ; +- curbits += av_log2(c)*2 - 4 + 1; +- } ++ curbits = ff_aac_spectral_bits[cb-1][curidx]; ++ vec = &ff_aac_codebook_vectors[cb-1][curidx*dim]; ++ if (BT_UNSIGNED) { ++ for (j = 0; j < dim; j++) { ++ float t = fabsf(in[i+j]); ++ float di; ++ if (BT_ESC && vec[j] == 64.0f) { //FIXME: slow ++ if (t >= CLIPPED_ESCAPE) { ++ di = t - CLIPPED_ESCAPE; ++ curbits += 21; + } else { +- di = t - vec[k]*IQ; ++ int c = av_clip(quant(t, Q), 0, 8191); ++ di = t - c*cbrtf(c)*IQ; ++ curbits += av_log2(c)*2 - 4 + 1; + } +- if (vec[k] != 0.0f) +- curbits++; +- rd += di*di; +- } +- } else { +- for (k = 0; k < dim; k++) { +- float di = in[i+k] - vec[k]*IQ; +- rd += di*di; ++ } else { ++ di = t - vec[j]*IQ; + } ++ if (vec[j] != 0.0f) ++ curbits++; ++ rd += di*di; ++ } ++ } else { ++ for (j = 0; j < dim; j++) { ++ float di = in[i+j] - vec[j]*IQ; ++ rd += di*di; + } ++ } + cost += rd * lambda + curbits; + resbits += curbits; + if (cost >= uplim) +@@ -279,7 +283,7 @@ + } + + static int find_min_book(float maxval, int sf) { +- float Q = ff_aac_pow2sf_tab[200 - sf + SCALE_ONE_POS - SCALE_DIV_512]; ++ float Q = ff_aac_pow2sf_tab[POW_SF2_ZERO - sf + SCALE_ONE_POS - SCALE_DIV_512]; + float Q34 = sqrtf(Q * sqrtf(Q)); + int qmaxval, cb; + qmaxval = maxval * Q34 + 0.4054f; +@@ -309,7 +313,7 @@ + int win, int group_len, const float lambda) + { + BandCodingPath path[120][12]; +- int w, swb, cb, start, start2, size; ++ int w, swb, cb, start, size; + int i, j; + const int max_sfb = sce->ics.max_sfb; + const int run_bits = sce->ics.num_windows == 1 ? 5 : 3; +@@ -327,7 +331,6 @@ + path[0][cb].run = 0; + } + for (swb = 0; swb < max_sfb; swb++) { +- start2 = start; + size = sce->ics.swb_sizes[swb]; + if (sce->zeroes[win*16 + swb]) { + for (cb = 0; cb < 12; cb++) { +@@ -344,7 +347,7 @@ + float cost_stay_here, cost_get_here; + float rd = 0.0f; + for (w = 0; w < group_len; w++) { +- FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(win+w)*16+swb]; ++ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(win+w)*16+swb]; + rd += quantize_band_cost(s, sce->coeffs + start + w*128, + s->scoefs + start + w*128, size, + sce->sf_idx[(win+w)*16+swb], cb, +@@ -411,14 +414,14 @@ + int win, int group_len, const float lambda) + { + BandCodingPath path[120][12]; +- int w, swb, cb, start, start2, size; ++ int w, swb, cb, start, size; + int i, j; + const int max_sfb = sce->ics.max_sfb; + const int run_bits = sce->ics.num_windows == 1 ? 5 : 3; + const int run_esc = (1 << run_bits) - 1; + int idx, ppos, count; + int stackrun[120], stackcb[120], stack_len; +- float next_minrd = INFINITY; ++ float next_minbits = INFINITY; + int next_mincb = 0; + + abs_pow34_v(s->scoefs, sce->coeffs, 1024); +@@ -429,19 +432,34 @@ + path[0][cb].run = 0; + } + for (swb = 0; swb < max_sfb; swb++) { +- start2 = start; + size = sce->ics.swb_sizes[swb]; + if (sce->zeroes[win*16 + swb]) { +- for (cb = 0; cb < 12; cb++) { +- path[swb+1][cb].prev_idx = cb; +- path[swb+1][cb].cost = path[swb][cb].cost; +- path[swb+1][cb].run = path[swb][cb].run + 1; ++ float cost_stay_here = path[swb][0].cost; ++ float cost_get_here = next_minbits + run_bits + 4; ++ if ( run_value_bits[sce->ics.num_windows == 8][path[swb][0].run] ++ != run_value_bits[sce->ics.num_windows == 8][path[swb][0].run+1]) ++ cost_stay_here += run_bits; ++ if (cost_get_here < cost_stay_here) { ++ path[swb+1][0].prev_idx = next_mincb; ++ path[swb+1][0].cost = cost_get_here; ++ path[swb+1][0].run = 1; ++ } else { ++ path[swb+1][0].prev_idx = 0; ++ path[swb+1][0].cost = cost_stay_here; ++ path[swb+1][0].run = path[swb][0].run + 1; ++ } ++ next_minbits = path[swb+1][0].cost; ++ next_mincb = 0; ++ for (cb = 1; cb < 12; cb++) { ++ path[swb+1][cb].cost = 61450; ++ path[swb+1][cb].prev_idx = -1; ++ path[swb+1][cb].run = 0; + } + } else { +- float minrd = next_minrd; ++ float minbits = next_minbits; + int mincb = next_mincb; + int startcb = sce->band_type[win*16+swb]; +- next_minrd = INFINITY; ++ next_minbits = INFINITY; + next_mincb = 0; + for (cb = 0; cb < startcb; cb++) { + path[swb+1][cb].cost = 61450; +@@ -450,15 +468,15 @@ + } + for (cb = startcb; cb < 12; cb++) { + float cost_stay_here, cost_get_here; +- float rd = 0.0f; ++ float bits = 0.0f; + for (w = 0; w < group_len; w++) { +- rd += quantize_band_cost(s, sce->coeffs + start + w*128, +- s->scoefs + start + w*128, size, +- sce->sf_idx[(win+w)*16+swb], cb, +- 0, INFINITY, NULL); ++ bits += quantize_band_cost(s, sce->coeffs + start + w*128, ++ s->scoefs + start + w*128, size, ++ sce->sf_idx[(win+w)*16+swb], cb, ++ 0, INFINITY, NULL); + } +- cost_stay_here = path[swb][cb].cost + rd; +- cost_get_here = minrd + rd + run_bits + 4; ++ cost_stay_here = path[swb][cb].cost + bits; ++ cost_get_here = minbits + bits + run_bits + 4; + if ( run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run] + != run_value_bits[sce->ics.num_windows == 8][path[swb][cb].run+1]) + cost_stay_here += run_bits; +@@ -471,8 +489,8 @@ + path[swb+1][cb].cost = cost_stay_here; + path[swb+1][cb].run = path[swb][cb].run + 1; + } +- if (path[swb+1][cb].cost < next_minrd) { +- next_minrd = path[swb+1][cb].cost; ++ if (path[swb+1][cb].cost < next_minbits) { ++ next_minbits = path[swb+1][cb].cost; + next_mincb = cb; + } + } +@@ -575,7 +593,7 @@ + int qnrg = av_clip_uint8(log2f(sqrtf(qnrgf/qcnt))*4 - 31 + SCALE_ONE_POS - SCALE_DIV_512); + q1 = qnrg + 30; + q0 = qnrg - 30; +- //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); ++ //av_log(NULL, AV_LOG_ERROR, "q0 %d, q1 %d\n", q0, q1); + if (q0 < q0low) { + q1 += q0low - q0; + q0 = q0low; +@@ -609,7 +627,7 @@ + qmin = INT_MAX; + qmax = 0.0f; + for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { +- FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; ++ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; + if (band->energy <= band->threshold || band->threshold == 0.0f) { + sce->zeroes[(w+w2)*16+g] = 1; + continue; +@@ -638,7 +656,7 @@ + float dist = 0; + int cb = find_min_book(maxval, sce->sf_idx[w*16+g]); + for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { +- FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; ++ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; + dist += quantize_band_cost(s, coefs + w2*128, s->scoefs + start + w2*128, sce->ics.swb_sizes[g], + q + q0, cb, lambda / band->threshold, INFINITY, NULL); + } +@@ -711,7 +729,7 @@ + int nz = 0; + float uplim = 0.0f; + for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { +- FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; ++ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; + uplim += band->threshold; + if (band->energy <= band->threshold || band->threshold == 0.0f) { + sce->zeroes[(w+w2)*16+g] = 1; +@@ -723,7 +741,7 @@ + sce->zeroes[w*16+g] = !nz; + if (nz) + minthr = FFMIN(minthr, uplim); +- allz = FFMAX(allz, nz); ++ allz |= nz; + } + } + for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { +@@ -817,7 +835,7 @@ + int prevsc = sce->sf_idx[w*16+g]; + if (dists[w*16+g] > uplims[w*16+g] && sce->sf_idx[w*16+g] > 60) { + if (find_min_book(maxvals[w*16+g], sce->sf_idx[w*16+g]-1)) +- sce->sf_idx[w*16+g]--; ++ sce->sf_idx[w*16+g]--; + else //Try to make sure there is some energy in every band + sce->sf_idx[w*16+g]-=2; + } +@@ -954,7 +972,7 @@ + dist -= b; + } + dist *= 1.0f / 512.0f / lambda; +- quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[200 - scf + SCALE_ONE_POS - SCALE_DIV_512]); ++ quant_max = quant(maxq[w*16+g], ff_aac_pow2sf_tab[POW_SF2_ZERO - scf + SCALE_ONE_POS - SCALE_DIV_512]); + if (quant_max >= 8191) { // too much, return to the previous quantizer + sce->sf_idx[w*16+g] = prev_scf; + break; +@@ -1004,15 +1022,14 @@ + SingleChannelElement *sce, + const float lambda) + { +- int start = 0, i, w, w2, g; ++ int i, w, w2, g; + int minq = 255; + + memset(sce->sf_idx, 0, sizeof(sce->sf_idx)); + for (w = 0; w < sce->ics.num_windows; w += sce->ics.group_len[w]) { +- start = w*128; + for (g = 0; g < sce->ics.num_swb; g++) { + for (w2 = 0; w2 < sce->ics.group_len[w]; w2++) { +- FFPsyBand *band = &s->psy.psy_bands[s->cur_channel*PSY_MAX_BANDS+(w+w2)*16+g]; ++ FFPsyBand *band = &s->psy.ch[s->cur_channel].psy_bands[(w+w2)*16+g]; + if (band->energy <= band->threshold) { + sce->sf_idx[(w+w2)*16+g] = 218; + sce->zeroes[(w+w2)*16+g] = 1; +@@ -1050,14 +1067,14 @@ + if (!cpe->ch[0].zeroes[w*16+g] && !cpe->ch[1].zeroes[w*16+g]) { + float dist1 = 0.0f, dist2 = 0.0f; + for (w2 = 0; w2 < sce0->ics.group_len[w]; w2++) { +- FFPsyBand *band0 = &s->psy.psy_bands[(s->cur_channel+0)*PSY_MAX_BANDS+(w+w2)*16+g]; +- FFPsyBand *band1 = &s->psy.psy_bands[(s->cur_channel+1)*PSY_MAX_BANDS+(w+w2)*16+g]; ++ FFPsyBand *band0 = &s->psy.ch[s->cur_channel+0].psy_bands[(w+w2)*16+g]; ++ FFPsyBand *band1 = &s->psy.ch[s->cur_channel+1].psy_bands[(w+w2)*16+g]; + float minthr = FFMIN(band0->threshold, band1->threshold); + float maxthr = FFMAX(band0->threshold, band1->threshold); + for (i = 0; i < sce0->ics.swb_sizes[g]; i++) { + M[i] = (sce0->coeffs[start+w2*128+i] + + sce1->coeffs[start+w2*128+i]) * 0.5; +- S[i] = sce0->coeffs[start+w2*128+i] ++ S[i] = M[i] + - sce1->coeffs[start+w2*128+i]; + } + abs_pow34_v(L34, sce0->coeffs+start+w2*128, sce0->ics.swb_sizes[g]); +@@ -1096,7 +1113,7 @@ + } + } + +-AACCoefficientsEncoder ff_aac_coders[] = { ++AACCoefficientsEncoder ff_aac_coders[AAC_CODER_NB] = { + { + search_for_quantizers_faac, + encode_window_bands_info, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacdec.c 2012-05-14 14:08:53.295319070 +0200 +@@ -42,7 +42,7 @@ + * Y filterbank - standard + * N (code in SoC repo) filterbank - Scalable Sample Rate + * Y Temporal Noise Shaping +- * N (code in SoC repo) Long Term Prediction ++ * Y Long Term Prediction + * Y intensity stereo + * Y channel coupling + * Y frequency domain prediction +@@ -87,6 +87,8 @@ + #include "fft.h" + #include "fmtconvert.h" + #include "lpc.h" ++#include "kbdwin.h" ++#include "sinewin.h" + + #include "aac.h" + #include "aactab.h" +@@ -96,6 +98,7 @@ + #include "aacsbr.h" + #include "mpeg4audio.h" + #include "aacadtsdec.h" ++#include "libavutil/intfloat.h" + + #include + #include +@@ -106,11 +109,6 @@ + # include "arm/aac.h" + #endif + +-union float754 { +- float f; +- uint32_t i; +-}; +- + static VLC vlc_scalefactors; + static VLC vlc_spectral[11]; + +@@ -165,6 +163,19 @@ + } + } + ++static int count_channels(enum ChannelPosition che_pos[4][MAX_ELEM_ID]) ++{ ++ int i, type, sum = 0; ++ for (i = 0; i < MAX_ELEM_ID; i++) { ++ for (type = 0; type < 4; type++) { ++ sum += (1 + (type == TYPE_CPE)) * ++ (che_pos[type][i] != AAC_CHANNEL_OFF && ++ che_pos[type][i] != AAC_CHANNEL_CC); ++ } ++ } ++ return sum; ++} ++ + /** + * Check for the channel element in the current channel position configuration. + * If it exists, make sure the appropriate element is allocated and map the +@@ -178,14 +189,15 @@ + * @return Returns error status. 0 - OK, !0 - error + */ + static av_cold int che_configure(AACContext *ac, +- enum ChannelPosition che_pos[4][MAX_ELEM_ID], +- int type, int id, +- int *channels) ++ enum ChannelPosition che_pos[4][MAX_ELEM_ID], ++ int type, int id, int *channels) + { + if (che_pos[type][id]) { +- if (!ac->che[type][id] && !(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) +- return AVERROR(ENOMEM); +- ff_aac_sbr_ctx_init(&ac->che[type][id]->sbr); ++ if (!ac->che[type][id]) { ++ if (!(ac->che[type][id] = av_mallocz(sizeof(ChannelElement)))) ++ return AVERROR(ENOMEM); ++ ff_aac_sbr_ctx_init(ac, &ac->che[type][id]->sbr); ++ } + if (type != TYPE_CCE) { + ac->output_data[(*channels)++] = ac->che[type][id]->ch[0].ret; + if (type == TYPE_CPE || +@@ -210,9 +222,9 @@ + * @return Returns error status. 0 - OK, !0 - error + */ + static av_cold int output_configure(AACContext *ac, +- enum ChannelPosition che_pos[4][MAX_ELEM_ID], +- enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], +- int channel_config, enum OCStatus oc_type) ++ enum ChannelPosition che_pos[4][MAX_ELEM_ID], ++ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], ++ int channel_config, enum OCStatus oc_type) + { + AVCodecContext *avctx = ac->avctx; + int i, type, channels = 0, ret; +@@ -229,7 +241,7 @@ + return ret; + } + +- memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); ++ memset(ac->tag_che_map, 0, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); + + avctx->channel_layout = aac_channel_layout[channel_config - 1]; + } else { +@@ -250,8 +262,6 @@ + } + + memcpy(ac->tag_che_map, ac->che, 4 * MAX_ELEM_ID * sizeof(ac->che[0][0])); +- +- avctx->channel_layout = 0; + } + + avctx->channels = channels; +@@ -261,6 +271,23 @@ + return 0; + } + ++static void flush(AVCodecContext *avctx) ++{ ++ AACContext *ac= avctx->priv_data; ++ int type, i, j; ++ ++ for (type = 3; type >= 0; type--) { ++ for (i = 0; i < MAX_ELEM_ID; i++) { ++ ChannelElement *che = ac->che[type][i]; ++ if (che) { ++ for (j = 0; j <= 1; j++) { ++ memset(che->ch[j].saved, 0, sizeof(che->ch[j].saved)); ++ } ++ } ++ } ++ } ++} ++ + /** + * Decode an array of 4 bit element IDs, optionally interleaved with a stereo/mono switching bit. + * +@@ -314,6 +341,10 @@ + if (get_bits1(gb)) + skip_bits(gb, 3); // mixdown_coeff_index and pseudo_surround + ++ if (get_bits_left(gb) < 4 * (num_front + num_side + num_back + num_lfe + num_assoc_data + num_cc)) { ++ av_log(avctx, AV_LOG_ERROR, overread_err); ++ return -1; ++ } + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_FRONT, gb, num_front); + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_SIDE, gb, num_side ); + decode_channel_map(new_che_pos[TYPE_CPE], new_che_pos[TYPE_SCE], AAC_CHANNEL_BACK, gb, num_back ); +@@ -344,8 +375,8 @@ + * @return Returns error status. 0 - OK, !0 - error + */ + static av_cold int set_default_channel_config(AVCodecContext *avctx, +- enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], +- int channel_config) ++ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID], ++ int channel_config) + { + if (channel_config < 1 || channel_config > 7) { + av_log(avctx, AV_LOG_ERROR, "invalid default channel configuration (%d)\n", +@@ -419,6 +450,12 @@ + if ((ret = set_default_channel_config(avctx, new_che_pos, channel_config))) + return ret; + } ++ ++ if (count_channels(new_che_pos) > 1) { ++ m4ac->ps = 0; ++ } else if (m4ac->sbr == 1 && m4ac->ps == -1) ++ m4ac->ps = 1; ++ + if (ac && (ret = output_configure(ac, ac->che_pos, new_che_pos, channel_config, OC_GLOBAL_HDR))) + return ret; + +@@ -449,35 +486,41 @@ + * @param ac pointer to AACContext, may be null + * @param avctx pointer to AVCCodecContext, used for logging + * @param m4ac pointer to MPEG4AudioConfig, used for parsing +- * @param data pointer to AVCodecContext extradata +- * @param data_size size of AVCCodecContext extradata ++ * @param data pointer to buffer holding an audio specific config ++ * @param bit_size size of audio specific config or data in bits ++ * @param sync_extension look for an appended sync extension + * + * @return Returns error status or number of consumed bits. <0 - error + */ + static int decode_audio_specific_config(AACContext *ac, + AVCodecContext *avctx, + MPEG4AudioConfig *m4ac, +- const uint8_t *data, int data_size) ++ const uint8_t *data, int bit_size, ++ int sync_extension) + { + GetBitContext gb; + int i; + +- init_get_bits(&gb, data, data_size * 8); ++ av_dlog(avctx, "extradata size %d\n", avctx->extradata_size); ++ for (i = 0; i < avctx->extradata_size; i++) ++ av_dlog(avctx, "%02x ", avctx->extradata[i]); ++ av_dlog(avctx, "\n"); ++ ++ init_get_bits(&gb, data, bit_size); + +- if ((i = ff_mpeg4audio_get_config(m4ac, data, data_size)) < 0) ++ if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, sync_extension)) < 0) + return -1; + if (m4ac->sampling_index > 12) { + av_log(avctx, AV_LOG_ERROR, "invalid sampling rate index %d\n", m4ac->sampling_index); + return -1; + } +- if (m4ac->sbr == 1 && m4ac->ps == -1) +- m4ac->ps = 1; + + skip_bits_long(&gb, i); + + switch (m4ac->object_type) { + case AOT_AAC_MAIN: + case AOT_AAC_LC: ++ case AOT_AAC_LTP: + if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config)) + return -1; + break; +@@ -487,6 +530,10 @@ + return -1; + } + ++ av_dlog(avctx, "AOT %d chan config %d sampling index %d (%d) SBR %d PS %d\n", ++ m4ac->object_type, m4ac->chan_config, m4ac->sampling_index, ++ m4ac->sample_rate, m4ac->sbr, m4ac->ps); ++ + return get_bits_count(&gb); + } + +@@ -519,6 +566,22 @@ + reset_predict_state(&ps[i]); + } + ++static int sample_rate_idx (int rate) ++{ ++ if (92017 <= rate) return 0; ++ else if (75132 <= rate) return 1; ++ else if (55426 <= rate) return 2; ++ else if (46009 <= rate) return 3; ++ else if (37566 <= rate) return 4; ++ else if (27713 <= rate) return 5; ++ else if (23004 <= rate) return 6; ++ else if (18783 <= rate) return 7; ++ else if (13856 <= rate) return 8; ++ else if (11502 <= rate) return 9; ++ else if (9391 <= rate) return 10; ++ else return 11; ++} ++ + static void reset_predictor_group(PredictorState *ps, int group_num) + { + int i; +@@ -535,6 +598,7 @@ + static av_cold int aac_decode_init(AVCodecContext *avctx) + { + AACContext *ac = avctx->priv_data; ++ float output_scale_factor; + + ac->avctx = avctx; + ac->m4ac.sample_rate = avctx->sample_rate; +@@ -542,11 +606,42 @@ + if (avctx->extradata_size > 0) { + if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, + avctx->extradata, +- avctx->extradata_size) < 0) ++ avctx->extradata_size*8, 1) < 0) + return -1; ++ } else { ++ int sr, i; ++ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; ++ ++ sr = sample_rate_idx(avctx->sample_rate); ++ ac->m4ac.sampling_index = sr; ++ ac->m4ac.channels = avctx->channels; ++ ac->m4ac.sbr = -1; ++ ac->m4ac.ps = -1; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(ff_mpeg4audio_channels); i++) ++ if (ff_mpeg4audio_channels[i] == avctx->channels) ++ break; ++ if (i == FF_ARRAY_ELEMS(ff_mpeg4audio_channels)) { ++ i = 0; ++ } ++ ac->m4ac.chan_config = i; ++ ++ if (ac->m4ac.chan_config) { ++ int ret = set_default_channel_config(avctx, new_che_pos, ac->m4ac.chan_config); ++ if (!ret) ++ output_configure(ac, ac->che_pos, new_che_pos, ac->m4ac.chan_config, OC_GLOBAL_HDR); ++ else if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; ++ } + } + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ output_scale_factor = 1.0 / 32768.0; ++ } else { ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ output_scale_factor = 1.0; ++ } + + AAC_INIT_VLC_STATIC( 0, 304); + AAC_INIT_VLC_STATIC( 1, 270); +@@ -567,12 +662,6 @@ + + ac->random_state = 0x1f2e3d4c; + +- // -1024 - Compensate wrong IMDCT method. +- // 60 - Required to scale values to the correct range [-32768,32767] +- // for float to int16 conversion. (1 << (60 / 4)) == 32768 +- ac->sf_scale = 1. / -1024.; +- ac->sf_offset = 60; +- + ff_aac_tableinit(); + + INIT_VLC_STATIC(&vlc_scalefactors,7,FF_ARRAY_ELEMS(ff_aac_scalefactor_code), +@@ -580,8 +669,9 @@ + ff_aac_scalefactor_code, sizeof(ff_aac_scalefactor_code[0]), sizeof(ff_aac_scalefactor_code[0]), + 352); + +- ff_mdct_init(&ac->mdct, 11, 1, 1.0); +- ff_mdct_init(&ac->mdct_small, 8, 1, 1.0); ++ ff_mdct_init(&ac->mdct, 11, 1, output_scale_factor/1024.0); ++ ff_mdct_init(&ac->mdct_small, 8, 1, output_scale_factor/128.0); ++ ff_mdct_init(&ac->mdct_ltp, 11, 0, -2.0/output_scale_factor); + // window initialization + ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); + ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); +@@ -590,6 +680,9 @@ + + cbrt_tableinit(); + ++ avcodec_get_frame_defaults(&ac->frame); ++ avctx->coded_frame = &ac->frame; ++ + return 0; + } + +@@ -631,17 +724,28 @@ + } + + /** ++ * Decode Long Term Prediction data; reference: table 4.xx. ++ */ ++static void decode_ltp(AACContext *ac, LongTermPrediction *ltp, ++ GetBitContext *gb, uint8_t max_sfb) ++{ ++ int sfb; ++ ++ ltp->lag = get_bits(gb, 11); ++ ltp->coef = ltp_coef[get_bits(gb, 3)]; ++ for (sfb = 0; sfb < FFMIN(max_sfb, MAX_LTP_LONG_SFB); sfb++) ++ ltp->used[sfb] = get_bits1(gb); ++} ++ ++/** + * Decode Individual Channel Stream info; reference: table 4.6. +- * +- * @param common_window Channels have independent [0], or shared [1], Individual Channel Stream information. + */ + static int decode_ics_info(AACContext *ac, IndividualChannelStream *ics, +- GetBitContext *gb, int common_window) ++ GetBitContext *gb) + { + if (get_bits1(gb)) { + av_log(ac->avctx, AV_LOG_ERROR, "Reserved bit set.\n"); +- memset(ics, 0, sizeof(IndividualChannelStream)); +- return -1; ++ return AVERROR_INVALIDDATA; + } + ics->window_sequence[1] = ics->window_sequence[0]; + ics->window_sequence[0] = get_bits(gb, 2); +@@ -676,17 +780,14 @@ + if (ics->predictor_present) { + if (ac->m4ac.object_type == AOT_AAC_MAIN) { + if (decode_prediction(ac, ics, gb)) { +- memset(ics, 0, sizeof(IndividualChannelStream)); +- return -1; ++ return AVERROR_INVALIDDATA; + } + } else if (ac->m4ac.object_type == AOT_AAC_LC) { + av_log(ac->avctx, AV_LOG_ERROR, "Prediction is not allowed in AAC-LC.\n"); +- memset(ics, 0, sizeof(IndividualChannelStream)); +- return -1; ++ return AVERROR_INVALIDDATA; + } else { +- av_log_missing_feature(ac->avctx, "Predictor bit set but LTP is", 1); +- memset(ics, 0, sizeof(IndividualChannelStream)); +- return -1; ++ if ((ics->ltp.present = get_bits(gb, 1))) ++ decode_ltp(ac, &ics->ltp, gb, ics->max_sfb); + } + } + } +@@ -695,8 +796,7 @@ + av_log(ac->avctx, AV_LOG_ERROR, + "Number of scalefactor bands in group (%d) exceeds limit (%d).\n", + ics->max_sfb, ics->num_swb); +- memset(ics, 0, sizeof(IndividualChannelStream)); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + return 0; +@@ -726,19 +826,20 @@ + av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); + return -1; + } +- while ((sect_len_incr = get_bits(gb, bits)) == (1 << bits) - 1) ++ do { ++ sect_len_incr = get_bits(gb, bits); + sect_end += sect_len_incr; +- sect_end += sect_len_incr; +- if (get_bits_left(gb) < 0) { +- av_log(ac->avctx, AV_LOG_ERROR, overread_err); +- return -1; +- } +- if (sect_end > ics->max_sfb) { +- av_log(ac->avctx, AV_LOG_ERROR, +- "Number of bands (%d) exceeds limit (%d).\n", +- sect_end, ics->max_sfb); +- return -1; +- } ++ if (get_bits_left(gb) < 0) { ++ av_log(ac->avctx, AV_LOG_ERROR, overread_err); ++ return -1; ++ } ++ if (sect_end > ics->max_sfb) { ++ av_log(ac->avctx, AV_LOG_ERROR, ++ "Number of bands (%d) exceeds limit (%d).\n", ++ sect_end, ics->max_sfb); ++ return -1; ++ } ++ } while (sect_len_incr == (1 << bits) - 1); + for (; k < sect_end; k++) { + band_type [idx] = sect_band_type; + band_type_run_end[idx++] = sect_end; +@@ -764,9 +865,9 @@ + enum BandType band_type[120], + int band_type_run_end[120]) + { +- const int sf_offset = ac->sf_offset + (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE ? 12 : 0); + int g, i, idx = 0; +- int offset[3] = { global_gain, global_gain - 90, 100 }; ++ int offset[3] = { global_gain, global_gain - 90, 0 }; ++ int clipped_offset; + int noise_flag = 1; + static const char *sf_str[3] = { "Global gain", "Noise gain", "Intensity stereo position" }; + for (g = 0; g < ics->num_window_groups; g++) { +@@ -778,12 +879,14 @@ + } else if ((band_type[idx] == INTENSITY_BT) || (band_type[idx] == INTENSITY_BT2)) { + for (; i < run_end; i++, idx++) { + offset[2] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; +- if (offset[2] > 255U) { +- av_log(ac->avctx, AV_LOG_ERROR, +- "%s (%d) out of range.\n", sf_str[2], offset[2]); +- return -1; ++ clipped_offset = av_clip(offset[2], -155, 100); ++ if (offset[2] != clipped_offset) { ++ av_log_ask_for_sample(ac->avctx, "Intensity stereo " ++ "position clipped (%d -> %d).\nIf you heard an " ++ "audible artifact, there may be a bug in the " ++ "decoder. ", offset[2], clipped_offset); + } +- sf[idx] = ff_aac_pow2sf_tab[-offset[2] + 300]; ++ sf[idx] = ff_aac_pow2sf_tab[-clipped_offset + POW_SF2_ZERO]; + } + } else if (band_type[idx] == NOISE_BT) { + for (; i < run_end; i++, idx++) { +@@ -791,12 +894,14 @@ + offset[1] += get_bits(gb, 9) - 256; + else + offset[1] += get_vlc2(gb, vlc_scalefactors.table, 7, 3) - 60; +- if (offset[1] > 255U) { +- av_log(ac->avctx, AV_LOG_ERROR, +- "%s (%d) out of range.\n", sf_str[1], offset[1]); +- return -1; ++ clipped_offset = av_clip(offset[1], -100, 155); ++ if (offset[1] != clipped_offset) { ++ av_log_ask_for_sample(ac->avctx, "Noise gain clipped " ++ "(%d -> %d).\nIf you heard an audible " ++ "artifact, there may be a bug in the decoder. ", ++ offset[1], clipped_offset); + } +- sf[idx] = -ff_aac_pow2sf_tab[offset[1] + sf_offset + 100]; ++ sf[idx] = -ff_aac_pow2sf_tab[clipped_offset + POW_SF2_ZERO]; + } + } else { + for (; i < run_end; i++, idx++) { +@@ -806,7 +911,7 @@ + "%s (%d) out of range.\n", sf_str[0], offset[0]); + return -1; + } +- sf[idx] = -ff_aac_pow2sf_tab[ offset[0] + sf_offset]; ++ sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; + } + } + } +@@ -926,7 +1031,7 @@ + static inline float *VMUL2S(float *dst, const float *v, unsigned idx, + unsigned sign, const float *scale) + { +- union float754 s0, s1; ++ union av_intfloat32 s0, s1; + + s0.f = s1.f = *scale; + s0.i ^= sign >> 1 << 31; +@@ -944,22 +1049,22 @@ + unsigned sign, const float *scale) + { + unsigned nz = idx >> 12; +- union float754 s = { .f = *scale }; +- union float754 t; ++ union av_intfloat32 s = { .f = *scale }; ++ union av_intfloat32 t; + +- t.i = s.i ^ (sign & 1<<31); ++ t.i = s.i ^ (sign & 1U<<31); + *dst++ = v[idx & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; +- t.i = s.i ^ (sign & 1<<31); ++ t.i = s.i ^ (sign & 1U<<31); + *dst++ = v[idx>>2 & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; +- t.i = s.i ^ (sign & 1<<31); ++ t.i = s.i ^ (sign & 1U<<31); + *dst++ = v[idx>>4 & 3] * t.f; + + sign <<= nz & 1; nz >>= 1; +- t.i = s.i ^ (sign & 1<<31); ++ t.i = s.i ^ (sign & 1U<<31); + *dst++ = v[idx>>6 & 3] * t.f; + + return dst; +@@ -1058,7 +1163,7 @@ + GET_VLC(code, re, gb, vlc_tab, 8, 2); + cb_idx = cb_vector_idx[code]; + nnz = cb_idx >> 8 & 15; +- bits = SHOW_UBITS(re, gb, nnz) << (32-nnz); ++ bits = nnz ? GET_CACHE(re, gb) : 0; + LAST_SKIP_BITS(re, gb, nnz); + cf = VMUL4S(cf, vq, cb_idx, bits, sf + idx); + } while (len -= 4); +@@ -1098,7 +1203,7 @@ + GET_VLC(code, re, gb, vlc_tab, 8, 2); + cb_idx = cb_vector_idx[code]; + nnz = cb_idx >> 8 & 15; +- sign = SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12); ++ sign = nnz ? SHOW_UBITS(re, gb, nnz) << (cb_idx >> 12) : 0; + LAST_SKIP_BITS(re, gb, nnz); + cf = VMUL2S(cf, vq, cb_idx, sign, sf + idx); + } while (len -= 2); +@@ -1152,11 +1257,11 @@ + b += 4; + n = (1 << b) + SHOW_UBITS(re, gb, b); + LAST_SKIP_BITS(re, gb, b); +- *icf++ = cbrt_tab[n] | (bits & 1<<31); ++ *icf++ = cbrt_tab[n] | (bits & 1U<<31); + bits <<= 1; + } else { + unsigned v = ((const uint32_t*)vq)[cb_idx & 15]; +- *icf++ = (bits & 1<<31) | v; ++ *icf++ = (bits & 1U<<31) | v; + bits <<= !!v; + } + cb_idx >>= 4; +@@ -1194,7 +1299,7 @@ + + static av_always_inline float flt16_round(float pf) + { +- union float754 tmp; ++ union av_intfloat32 tmp; + tmp.f = pf; + tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U; + return tmp.f; +@@ -1202,7 +1307,7 @@ + + static av_always_inline float flt16_even(float pf) + { +- union float754 tmp; ++ union av_intfloat32 tmp; + tmp.f = pf; + tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U >> 16)) & 0xFFFF0000U; + return tmp.f; +@@ -1210,15 +1315,14 @@ + + static av_always_inline float flt16_trunc(float pf) + { +- union float754 pun; ++ union av_intfloat32 pun; + pun.f = pf; + pun.i &= 0xFFFF0000U; + return pun.f; + } + + static av_always_inline void predict(PredictorState *ps, float *coef, +- float sf_scale, float inv_sf_scale, +- int output_enable) ++ int output_enable) + { + const float a = 0.953125; // 61.0 / 64 + const float alpha = 0.90625; // 29.0 / 32 +@@ -1234,9 +1338,9 @@ + + pv = flt16_round(k1 * r0 + k2 * r1); + if (output_enable) +- *coef += pv * sf_scale; ++ *coef += pv; + +- e0 = *coef * inv_sf_scale; ++ e0 = *coef; + e1 = e0 - k1 * r0; + + ps->cor1 = flt16_trunc(alpha * cor1 + r1 * e1); +@@ -1254,7 +1358,6 @@ + static void apply_prediction(AACContext *ac, SingleChannelElement *sce) + { + int sfb, k; +- float sf_scale = ac->sf_scale, inv_sf_scale = 1 / ac->sf_scale; + + if (!sce->ics.predictor_initialized) { + reset_all_predictors(sce->predictor_state); +@@ -1265,7 +1368,6 @@ + for (sfb = 0; sfb < ff_aac_pred_sfb_max[ac->m4ac.sampling_index]; sfb++) { + for (k = sce->ics.swb_offset[sfb]; k < sce->ics.swb_offset[sfb + 1]; k++) { + predict(&sce->predictor_state[k], &sce->coeffs[k], +- sf_scale, inv_sf_scale, + sce->ics.predictor_present && sce->ics.prediction_used[sfb]); + } + } +@@ -1300,8 +1402,8 @@ + global_gain = get_bits(gb, 8); + + if (!common_window && !scale_flag) { +- if (decode_ics_info(ac, ics, gb, 0) < 0) +- return -1; ++ if (decode_ics_info(ac, ics, gb) < 0) ++ return AVERROR_INVALIDDATA; + } + + if (decode_band_types(ac, sce->band_type, sce->band_type_run_end, gb, ics) < 0) +@@ -1371,13 +1473,13 @@ + * [1] mask is decoded from bitstream; [2] mask is all 1s; + * [3] reserved for scalable AAC + */ +-static void apply_intensity_stereo(ChannelElement *cpe, int ms_present) ++static void apply_intensity_stereo(AACContext *ac, ChannelElement *cpe, int ms_present) + { + const IndividualChannelStream *ics = &cpe->ch[1].ics; + SingleChannelElement *sce1 = &cpe->ch[1]; + float *coef0 = cpe->ch[0].coeffs, *coef1 = cpe->ch[1].coeffs; + const uint16_t *offsets = ics->swb_offset; +- int g, group, i, k, idx = 0; ++ int g, group, i, idx = 0; + int c; + float scale; + for (g = 0; g < ics->num_window_groups; g++) { +@@ -1390,8 +1492,10 @@ + c *= 1 - 2 * cpe->ms_mask[idx]; + scale = c * sce1->sf[idx]; + for (group = 0; group < ics->group_len[g]; group++) +- for (k = offsets[i]; k < offsets[i + 1]; k++) +- coef1[group * 128 + k] = scale * coef0[group * 128 + k]; ++ ac->dsp.vector_fmul_scalar(coef1 + group * 128 + offsets[i], ++ coef0 + group * 128 + offsets[i], ++ scale, ++ offsets[i + 1] - offsets[i]); + } + } else { + int bt_run_end = sce1->band_type_run_end[idx]; +@@ -1415,11 +1519,14 @@ + + common_window = get_bits1(gb); + if (common_window) { +- if (decode_ics_info(ac, &cpe->ch[0].ics, gb, 1)) +- return -1; ++ if (decode_ics_info(ac, &cpe->ch[0].ics, gb)) ++ return AVERROR_INVALIDDATA; + i = cpe->ch[1].ics.use_kb_window[0]; + cpe->ch[1].ics = cpe->ch[0].ics; + cpe->ch[1].ics.use_kb_window[1] = i; ++ if (cpe->ch[1].ics.predictor_present && (ac->m4ac.object_type != AOT_AAC_MAIN)) ++ if ((cpe->ch[1].ics.ltp.present = get_bits(gb, 1))) ++ decode_ltp(ac, &cpe->ch[1].ics.ltp, gb, cpe->ch[1].ics.max_sfb); + ms_present = get_bits(gb, 2); + if (ms_present == 3) { + av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); +@@ -1441,7 +1548,7 @@ + } + } + +- apply_intensity_stereo(cpe, ms_present); ++ apply_intensity_stereo(ac, cpe, ms_present); + return 0; + } + +@@ -1659,6 +1766,7 @@ + int w, filt, m, i; + int bottom, top, order, start, end, size, inc; + float lpc[TNS_MAX_ORDER]; ++ float tmp[TNS_MAX_ORDER]; + + for (w = 0; w < ics->num_windows; w++) { + bottom = ics->num_swb; +@@ -1684,15 +1792,120 @@ + } + start += w * 128; + +- // ar filter +- for (m = 0; m < size; m++, start += inc) +- for (i = 1; i <= FFMIN(m, order); i++) +- coef[start] -= coef[start - i * inc] * lpc[i - 1]; ++ if (decode) { ++ // ar filter ++ for (m = 0; m < size; m++, start += inc) ++ for (i = 1; i <= FFMIN(m, order); i++) ++ coef[start] -= coef[start - i * inc] * lpc[i - 1]; ++ } else { ++ // ma filter ++ for (m = 0; m < size; m++, start += inc) { ++ tmp[0] = coef[start]; ++ for (i = 1; i <= FFMIN(m, order); i++) ++ coef[start] += tmp[i] * lpc[i - 1]; ++ for (i = order; i > 0; i--) ++ tmp[i] = tmp[i - 1]; ++ } ++ } + } + } + } + + /** ++ * Apply windowing and MDCT to obtain the spectral ++ * coefficient from the predicted sample by LTP. ++ */ ++static void windowing_and_mdct_ltp(AACContext *ac, float *out, ++ float *in, IndividualChannelStream *ics) ++{ ++ const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; ++ const float *lwindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *swindow_prev = ics->use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; ++ ++ if (ics->window_sequence[0] != LONG_STOP_SEQUENCE) { ++ ac->dsp.vector_fmul(in, in, lwindow_prev, 1024); ++ } else { ++ memset(in, 0, 448 * sizeof(float)); ++ ac->dsp.vector_fmul(in + 448, in + 448, swindow_prev, 128); ++ } ++ if (ics->window_sequence[0] != LONG_START_SEQUENCE) { ++ ac->dsp.vector_fmul_reverse(in + 1024, in + 1024, lwindow, 1024); ++ } else { ++ ac->dsp.vector_fmul_reverse(in + 1024 + 448, in + 1024 + 448, swindow, 128); ++ memset(in + 1024 + 576, 0, 448 * sizeof(float)); ++ } ++ ac->mdct_ltp.mdct_calc(&ac->mdct_ltp, out, in); ++} ++ ++/** ++ * Apply the long term prediction ++ */ ++static void apply_ltp(AACContext *ac, SingleChannelElement *sce) ++{ ++ const LongTermPrediction *ltp = &sce->ics.ltp; ++ const uint16_t *offsets = sce->ics.swb_offset; ++ int i, sfb; ++ ++ if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { ++ float *predTime = sce->ret; ++ float *predFreq = ac->buf_mdct; ++ int16_t num_samples = 2048; ++ ++ if (ltp->lag < 1024) ++ num_samples = ltp->lag + 1024; ++ for (i = 0; i < num_samples; i++) ++ predTime[i] = sce->ltp_state[i + 2048 - ltp->lag] * ltp->coef; ++ memset(&predTime[i], 0, (2048 - i) * sizeof(float)); ++ ++ windowing_and_mdct_ltp(ac, predFreq, predTime, &sce->ics); ++ ++ if (sce->tns.present) ++ apply_tns(predFreq, &sce->tns, &sce->ics, 0); ++ ++ for (sfb = 0; sfb < FFMIN(sce->ics.max_sfb, MAX_LTP_LONG_SFB); sfb++) ++ if (ltp->used[sfb]) ++ for (i = offsets[sfb]; i < offsets[sfb + 1]; i++) ++ sce->coeffs[i] += predFreq[i]; ++ } ++} ++ ++/** ++ * Update the LTP buffer for next frame ++ */ ++static void update_ltp(AACContext *ac, SingleChannelElement *sce) ++{ ++ IndividualChannelStream *ics = &sce->ics; ++ float *saved = sce->saved; ++ float *saved_ltp = sce->coeffs; ++ const float *lwindow = ics->use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *swindow = ics->use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; ++ int i; ++ ++ if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { ++ memcpy(saved_ltp, saved, 512 * sizeof(float)); ++ memset(saved_ltp + 576, 0, 448 * sizeof(float)); ++ ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); ++ for (i = 0; i < 64; i++) ++ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; ++ } else if (ics->window_sequence[0] == LONG_START_SEQUENCE) { ++ memcpy(saved_ltp, ac->buf_mdct + 512, 448 * sizeof(float)); ++ memset(saved_ltp + 576, 0, 448 * sizeof(float)); ++ ac->dsp.vector_fmul_reverse(saved_ltp + 448, ac->buf_mdct + 960, &swindow[64], 64); ++ for (i = 0; i < 64; i++) ++ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * swindow[63 - i]; ++ } else { // LONG_STOP or ONLY_LONG ++ ac->dsp.vector_fmul_reverse(saved_ltp, ac->buf_mdct + 512, &lwindow[512], 512); ++ for (i = 0; i < 512; i++) ++ saved_ltp[i + 512] = ac->buf_mdct[1023 - i] * lwindow[511 - i]; ++ } ++ ++ memcpy(sce->ltp_state, sce->ltp_state+1024, 1024 * sizeof(*sce->ltp_state)); ++ memcpy(sce->ltp_state+1024, sce->ret, 1024 * sizeof(*sce->ltp_state)); ++ memcpy(sce->ltp_state+2048, saved_ltp, 1024 * sizeof(*sce->ltp_state)); ++} ++ ++/** + * Conduct IMDCT and windowing. + */ + static void imdct_and_windowing(AACContext *ac, SingleChannelElement *sce) +@@ -1711,9 +1924,9 @@ + // imdct + if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { + for (i = 0; i < 1024; i += 128) +- ff_imdct_half(&ac->mdct_small, buf + i, in + i); ++ ac->mdct_small.imdct_half(&ac->mdct_small, buf + i, in + i); + } else +- ff_imdct_half(&ac->mdct, buf, in); ++ ac->mdct.imdct_half(&ac->mdct, buf, in); + + /* window overlapping + * NOTE: To simplify the overlapping code, all 'meaningless' short to long +@@ -1857,6 +2070,14 @@ + if (che) { + if (type <= TYPE_CPE) + apply_channel_coupling(ac, che, type, i, BEFORE_TNS, apply_dependent_coupling); ++ if (ac->m4ac.object_type == AOT_AAC_LTP) { ++ if (che->ch[0].ics.predictor_present) { ++ if (che->ch[0].ics.ltp.present) ++ apply_ltp(ac, &che->ch[0]); ++ if (che->ch[1].ics.ltp.present && type == TYPE_CPE) ++ apply_ltp(ac, &che->ch[1]); ++ } ++ } + if (che->ch[0].tns.present) + apply_tns(che->ch[0].coeffs, &che->ch[0].tns, &che->ch[0].ics, 1); + if (che->ch[1].tns.present) +@@ -1865,8 +2086,12 @@ + apply_channel_coupling(ac, che, type, i, BETWEEN_TNS_AND_IMDCT, apply_dependent_coupling); + if (type != TYPE_CCE || che->coup.coupling_point == AFTER_IMDCT) { + imdct_and_windowing(ac, &che->ch[0]); ++ if (ac->m4ac.object_type == AOT_AAC_LTP) ++ update_ltp(ac, &che->ch[0]); + if (type == TYPE_CPE) { + imdct_and_windowing(ac, &che->ch[1]); ++ if (ac->m4ac.object_type == AOT_AAC_LTP) ++ update_ltp(ac, &che->ch[1]); + } + if (ac->m4ac.sbr > 0) { + ff_sbr_apply(ac, &che->sbr, type, che->ch[0].ret, che->ch[1].ret); +@@ -1884,47 +2109,50 @@ + int size; + AACADTSHeaderInfo hdr_info; + +- size = ff_aac_parse_header(gb, &hdr_info); ++ size = avpriv_aac_parse_header(gb, &hdr_info); + if (size > 0) { +- if (ac->output_configured != OC_LOCKED && hdr_info.chan_config) { ++ if (hdr_info.chan_config) { + enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]; + memset(new_che_pos, 0, 4 * MAX_ELEM_ID * sizeof(new_che_pos[0][0])); + ac->m4ac.chan_config = hdr_info.chan_config; + if (set_default_channel_config(ac->avctx, new_che_pos, hdr_info.chan_config)) + return -7; +- if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, OC_TRIAL_FRAME)) ++ if (output_configure(ac, ac->che_pos, new_che_pos, hdr_info.chan_config, ++ FFMAX(ac->output_configured, OC_TRIAL_FRAME))) + return -7; + } else if (ac->output_configured != OC_LOCKED) { ++ ac->m4ac.chan_config = 0; + ac->output_configured = OC_NONE; + } + if (ac->output_configured != OC_LOCKED) { + ac->m4ac.sbr = -1; + ac->m4ac.ps = -1; ++ ac->m4ac.sample_rate = hdr_info.sample_rate; ++ ac->m4ac.sampling_index = hdr_info.sampling_index; ++ ac->m4ac.object_type = hdr_info.object_type; + } +- ac->m4ac.sample_rate = hdr_info.sample_rate; +- ac->m4ac.sampling_index = hdr_info.sampling_index; +- ac->m4ac.object_type = hdr_info.object_type; + if (!ac->avctx->sample_rate) + ac->avctx->sample_rate = hdr_info.sample_rate; +- if (hdr_info.num_aac_frames == 1) { +- if (!hdr_info.crc_absent) +- skip_bits(gb, 16); +- } else { ++ if (!ac->warned_num_aac_frames && hdr_info.num_aac_frames != 1) { ++ // This is 2 for "VLB " audio in NSV files. ++ // See samples/nsv/vlb_audio. + av_log_missing_feature(ac->avctx, "More than one AAC RDB per ADTS frame is", 0); +- return -1; ++ ac->warned_num_aac_frames = 1; + } ++ if (!hdr_info.crc_absent) ++ skip_bits(gb, 16); + } + return size; + } + + static int aac_decode_frame_int(AVCodecContext *avctx, void *data, +- int *data_size, GetBitContext *gb) ++ int *got_frame_ptr, GetBitContext *gb) + { + AACContext *ac = avctx->priv_data; + ChannelElement *che = NULL, *che_prev = NULL; + enum RawDataBlockType elem_type, elem_type_prev = TYPE_END; +- int err, elem_id, data_size_tmp; +- int samples = 0, multiplier; ++ int err, elem_id; ++ int samples = 0, multiplier, audio_found = 0; + + if (show_bits(gb, 12) == 0xfff) { + if (parse_adts_frame_header(ac, gb) < 0) { +@@ -1943,6 +2171,15 @@ + elem_id = get_bits(gb, 4); + + if (elem_type < TYPE_DSE) { ++ if (!ac->tags_mapped && elem_type == TYPE_CPE && ac->m4ac.chan_config==1) { ++ enum ChannelPosition new_che_pos[4][MAX_ELEM_ID]= {0}; ++ ac->m4ac.chan_config=2; ++ ++ if (set_default_channel_config(ac->avctx, new_che_pos, 2)<0) ++ return -1; ++ if (output_configure(ac, ac->che_pos, new_che_pos, 2, OC_TRIAL_FRAME)<0) ++ return -1; ++ } + if (!(che=get_che(ac, elem_type, elem_id))) { + av_log(ac->avctx, AV_LOG_ERROR, "channel element %d.%d is not allocated\n", + elem_type, elem_id); +@@ -1955,10 +2192,12 @@ + + case TYPE_SCE: + err = decode_ics(ac, &che->ch[0], gb, 0, 0); ++ audio_found = 1; + break; + + case TYPE_CPE: + err = decode_cpe(ac, gb, che); ++ audio_found = 1; + break; + + case TYPE_CCE: +@@ -1967,6 +2206,7 @@ + + case TYPE_LFE: + err = decode_ics(ac, &che->ch[0], gb, 0, 0); ++ audio_found = 1; + break; + + case TYPE_DSE: +@@ -1979,10 +2219,11 @@ + if ((err = decode_pce(avctx, &ac->m4ac, new_che_pos, gb))) + break; + if (ac->output_configured > OC_TRIAL_PCE) +- av_log(avctx, AV_LOG_ERROR, +- "Not evaluating a further program_config_element as this construct is dubious at best.\n"); +- else +- err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE); ++ av_log(avctx, AV_LOG_INFO, ++ "Evaluating a further program_config_element.\n"); ++ err = output_configure(ac, ac->che_pos, new_che_pos, 0, OC_TRIAL_PCE); ++ if (!err) ++ ac->m4ac.chan_config = 0; + break; + } + +@@ -2024,37 +2265,65 @@ + avctx->frame_size = samples; + } + +- data_size_tmp = samples * avctx->channels * sizeof(int16_t); +- if (*data_size < data_size_tmp) { +- av_log(avctx, AV_LOG_ERROR, +- "Output buffer too small (%d) or trying to output too many samples (%d) for this frame.\n", +- *data_size, data_size_tmp); +- return -1; +- } +- *data_size = data_size_tmp; ++ if (samples) { ++ /* get output buffer */ ++ ac->frame.nb_samples = samples; ++ if ((err = avctx->get_buffer(avctx, &ac->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return err; ++ } ++ ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) ++ ac->fmt_conv.float_interleave((float *)ac->frame.data[0], ++ (const float **)ac->output_data, ++ samples, avctx->channels); ++ else ++ ac->fmt_conv.float_to_int16_interleave((int16_t *)ac->frame.data[0], ++ (const float **)ac->output_data, ++ samples, avctx->channels); + +- if (samples) +- ac->fmt_conv.float_to_int16_interleave(data, (const float **)ac->output_data, samples, avctx->channels); ++ *(AVFrame *)data = ac->frame; ++ } ++ *got_frame_ptr = !!samples; + +- if (ac->output_configured) ++ if (ac->output_configured && audio_found) + ac->output_configured = OC_LOCKED; + + return 0; + } + + static int aac_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { ++ AACContext *ac = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + GetBitContext gb; + int buf_consumed; + int buf_offset; + int err; ++ int new_extradata_size; ++ const uint8_t *new_extradata = av_packet_get_side_data(avpkt, ++ AV_PKT_DATA_NEW_EXTRADATA, ++ &new_extradata_size); ++ ++ if (new_extradata) { ++ av_free(avctx->extradata); ++ avctx->extradata = av_mallocz(new_extradata_size + ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!avctx->extradata) ++ return AVERROR(ENOMEM); ++ avctx->extradata_size = new_extradata_size; ++ memcpy(avctx->extradata, new_extradata, new_extradata_size); ++ if (decode_audio_specific_config(ac, ac->avctx, &ac->m4ac, ++ avctx->extradata, ++ avctx->extradata_size*8, 1) < 0) ++ return AVERROR_INVALIDDATA; ++ } + + init_get_bits(&gb, buf, buf_size * 8); + +- if ((err = aac_decode_frame_int(avctx, data, data_size, &gb)) < 0) ++ if ((err = aac_decode_frame_int(avctx, data, got_frame_ptr, &gb)) < 0) + return err; + + buf_consumed = (get_bits_count(&gb) + 7) >> 3; +@@ -2080,6 +2349,7 @@ + + ff_mdct_end(&ac->mdct); + ff_mdct_end(&ac->mdct_small); ++ ff_mdct_end(&ac->mdct_ltp); + return 0; + } + +@@ -2104,29 +2374,44 @@ + } + + static int latm_decode_audio_specific_config(struct LATMContext *latmctx, +- GetBitContext *gb) ++ GetBitContext *gb, int asclen) + { +- AVCodecContext *avctx = latmctx->aac_ctx.avctx; +- MPEG4AudioConfig m4ac; +- int config_start_bit = get_bits_count(gb); +- int bits_consumed, esize; ++ AACContext *ac = &latmctx->aac_ctx; ++ AVCodecContext *avctx = ac->avctx; ++ MPEG4AudioConfig m4ac = {0}; ++ int config_start_bit = get_bits_count(gb); ++ int sync_extension = 0; ++ int bits_consumed, esize; ++ ++ if (asclen) { ++ sync_extension = 1; ++ asclen = FFMIN(asclen, get_bits_left(gb)); ++ } else ++ asclen = get_bits_left(gb); + + if (config_start_bit % 8) { + av_log_missing_feature(latmctx->aac_ctx.avctx, "audio specific " + "config not byte aligned.\n", 1); + return AVERROR_INVALIDDATA; +- } else { +- bits_consumed = +- decode_audio_specific_config(NULL, avctx, &m4ac, ++ } ++ if (asclen <= 0) ++ return AVERROR_INVALIDDATA; ++ bits_consumed = decode_audio_specific_config(NULL, avctx, &m4ac, + gb->buffer + (config_start_bit / 8), +- get_bits_left(gb) / 8); ++ asclen, sync_extension); + +- if (bits_consumed < 0) +- return AVERROR_INVALIDDATA; ++ if (bits_consumed < 0) ++ return AVERROR_INVALIDDATA; ++ ++ if (ac->m4ac.sample_rate != m4ac.sample_rate || ++ ac->m4ac.chan_config != m4ac.chan_config) { ++ ++ av_log(avctx, AV_LOG_INFO, "audio config changed\n"); ++ latmctx->initialized = 0; + + esize = (bits_consumed+7) / 8; + +- if (avctx->extradata_size <= esize) { ++ if (avctx->extradata_size < esize) { + av_free(avctx->extradata); + avctx->extradata = av_malloc(esize + FF_INPUT_BUFFER_PADDING_SIZE); + if (!avctx->extradata) +@@ -2136,9 +2421,8 @@ + avctx->extradata_size = esize; + memcpy(avctx->extradata, gb->buffer + (config_start_bit/8), esize); + memset(avctx->extradata+esize, 0, FF_INPUT_BUFFER_PADDING_SIZE); +- +- skip_bits_long(gb, bits_consumed); + } ++ skip_bits_long(gb, bits_consumed); + + return bits_consumed; + } +@@ -2177,11 +2461,11 @@ + + // for all but first stream: use_same_config = get_bits(gb, 1); + if (!audio_mux_version) { +- if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0) ++ if ((ret = latm_decode_audio_specific_config(latmctx, gb, 0)) < 0) + return ret; + } else { + int ascLen = latm_get_value(gb); +- if ((ret = latm_decode_audio_specific_config(latmctx, gb)) < 0) ++ if ((ret = latm_decode_audio_specific_config(latmctx, gb, ascLen)) < 0) + return ret; + ascLen -= ret; + skip_bits_long(gb, ascLen); +@@ -2275,16 +2559,13 @@ + } + + +-static int latm_decode_frame(AVCodecContext *avctx, void *out, int *out_size, +- AVPacket *avpkt) ++static int latm_decode_frame(AVCodecContext *avctx, void *out, ++ int *got_frame_ptr, AVPacket *avpkt) + { + struct LATMContext *latmctx = avctx->priv_data; + int muxlength, err; + GetBitContext gb; + +- if (avpkt->size == 0) +- return 0; +- + init_get_bits(&gb, avpkt->data, avpkt->size * 8); + + // check for LOAS sync word +@@ -2301,10 +2582,12 @@ + + if (!latmctx->initialized) { + if (!avctx->extradata) { +- *out_size = 0; ++ *got_frame_ptr = 0; + return avpkt->size; + } else { +- if ((err = aac_decode_init(avctx)) < 0) ++ if ((err = decode_audio_specific_config( ++ &latmctx->aac_ctx, avctx, &latmctx->aac_ctx.m4ac, ++ avctx->extradata, avctx->extradata_size*8, 1)) < 0) + return err; + latmctx->initialized = 1; + } +@@ -2317,7 +2600,7 @@ + return AVERROR_INVALIDDATA; + } + +- if ((err = aac_decode_frame_int(avctx, out, out_size, &gb)) < 0) ++ if ((err = aac_decode_frame_int(avctx, out, got_frame_ptr, &gb)) < 0) + return err; + + return muxlength; +@@ -2326,33 +2609,28 @@ + av_cold static int latm_decode_init(AVCodecContext *avctx) + { + struct LATMContext *latmctx = avctx->priv_data; +- int ret; +- +- ret = aac_decode_init(avctx); ++ int ret = aac_decode_init(avctx); + +- if (avctx->extradata_size > 0) { ++ if (avctx->extradata_size > 0) + latmctx->initialized = !ret; +- } else { +- latmctx->initialized = 0; +- } + + return ret; + } + + + AVCodec ff_aac_decoder = { +- "aac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AAC, +- sizeof(AACContext), +- aac_decode_init, +- NULL, +- aac_decode_close, +- aac_decode_frame, ++ .name = "aac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AAC, ++ .priv_data_size = sizeof(AACContext), ++ .init = aac_decode_init, ++ .close = aac_decode_close, ++ .decode = aac_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), + .sample_fmts = (const enum AVSampleFormat[]) { +- AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE ++ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE + }, ++ .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, + .channel_layouts = aac_channel_layout, + }; + +@@ -2363,7 +2641,7 @@ + */ + AVCodec ff_aac_latm_decoder = { + .name = "aac_latm", +- .type = CODEC_TYPE_AUDIO, ++ .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_AAC_LATM, + .priv_data_size = sizeof(struct LATMContext), + .init = latm_decode_init, +@@ -2371,7 +2649,9 @@ + .decode = latm_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("AAC LATM (Advanced Audio Codec LATM syntax)"), + .sample_fmts = (const enum AVSampleFormat[]) { +- AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE ++ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE + }, ++ .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, + .channel_layouts = aac_channel_layout, ++ .flush = flush, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacdectab.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacdectab.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacdectab.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacdectab.h 2012-05-14 14:08:53.296319090 +0200 +@@ -30,11 +30,19 @@ + #ifndef AVCODEC_AACDECTAB_H + #define AVCODEC_AACDECTAB_H + +-#include "libavcore/audioconvert.h" ++#include "libavutil/audioconvert.h" + #include "aac.h" + + #include + ++/* @name ltp_coef ++ * Table of the LTP coefficients ++ */ ++static const float ltp_coef[8] = { ++ 0.570829, 0.696616, 0.813004, 0.911304, ++ 0.984900, 1.067894, 1.194601, 1.369533, ++}; ++ + /* @name tns_tmp2_map + * Tables of the tmp2[] arrays of LPC coefficients used for TNS. + * The suffix _M_N[] indicate the values of coef_compress and coef_res +@@ -82,7 +90,7 @@ + { { TYPE_CPE, 0 }, { TYPE_SCE, 0 }, { TYPE_LFE, 0 }, { TYPE_CPE, 2 }, { TYPE_CPE, 1 }, }, + }; + +-static const int64_t aac_channel_layout[8] = { ++static const uint64_t aac_channel_layout[8] = { + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_SURROUND, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacenc.c 2012-05-14 14:08:53.298319131 +0200 +@@ -30,10 +30,13 @@ + * add temporal noise shaping + ***********************************/ + ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "put_bits.h" + #include "dsputil.h" + #include "mpeg4audio.h" ++#include "kbdwin.h" ++#include "sinewin.h" + + #include "aac.h" + #include "aactab.h" +@@ -43,6 +46,14 @@ + + #define AAC_MAX_CHANNELS 6 + ++#define ERROR_IF(cond, ...) \ ++ if (cond) { \ ++ av_log(avctx, AV_LOG_ERROR, __VA_ARGS__); \ ++ return AVERROR(EINVAL); \ ++ } ++ ++float ff_aac_pow34sf_tab[428]; ++ + static const uint8_t swb_size_1024_96[] = { + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, + 12, 12, 12, 12, 12, 16, 16, 24, 28, 36, 44, +@@ -133,6 +144,18 @@ + }; + + /** ++ * Table to remap channels from Libav's default order to AAC order. ++ */ ++static const uint8_t aac_chan_maps[AAC_MAX_CHANNELS][AAC_MAX_CHANNELS] = { ++ { 0 }, ++ { 0, 1 }, ++ { 2, 0, 1 }, ++ { 2, 0, 1, 3 }, ++ { 2, 0, 1, 3, 4 }, ++ { 2, 0, 1, 4, 5, 3 }, ++}; ++ ++/** + * Make AAC audio config object. + * @see 1.6.2.1 "Syntax - AudioSpecificConfig" + */ +@@ -144,7 +167,7 @@ + init_put_bits(&pb, avctx->extradata, avctx->extradata_size*8); + put_bits(&pb, 5, 2); //object type - AAC-LC + put_bits(&pb, 4, s->samplerate_index); //sample rate index +- put_bits(&pb, 4, avctx->channels); ++ put_bits(&pb, 4, s->channels); + //GASpecificConfig + put_bits(&pb, 1, 0); //frame length - 1024 samples + put_bits(&pb, 1, 0); //does not depend on core coder +@@ -157,112 +180,80 @@ + flush_put_bits(&pb); + } + +-static av_cold int aac_encode_init(AVCodecContext *avctx) +-{ +- AACEncContext *s = avctx->priv_data; +- int i; +- const uint8_t *sizes[2]; +- int lengths[2]; ++#define WINDOW_FUNC(type) \ ++static void apply_ ##type ##_window(DSPContext *dsp, SingleChannelElement *sce, const float *audio) + +- avctx->frame_size = 1024; ++WINDOW_FUNC(only_long) ++{ ++ const float *lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ float *out = sce->ret; + +- for (i = 0; i < 16; i++) +- if (avctx->sample_rate == ff_mpeg4audio_sample_rates[i]) +- break; +- if (i == 16) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", avctx->sample_rate); +- return -1; +- } +- if (avctx->channels > AAC_MAX_CHANNELS) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", avctx->channels); +- return -1; +- } +- if (avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported profile %d\n", avctx->profile); +- return -1; +- } +- if (1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * avctx->channels) { +- av_log(avctx, AV_LOG_ERROR, "Too many bits per frame requested\n"); +- return -1; +- } +- s->samplerate_index = i; ++ dsp->vector_fmul (out, audio, lwindow, 1024); ++ dsp->vector_fmul_reverse(out + 1024, audio + 1024, pwindow, 1024); ++} + +- dsputil_init(&s->dsp, avctx); +- ff_mdct_init(&s->mdct1024, 11, 0, 1.0); +- ff_mdct_init(&s->mdct128, 8, 0, 1.0); +- // window init +- ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); +- ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); +- ff_init_ff_sine_windows(10); +- ff_init_ff_sine_windows(7); ++WINDOW_FUNC(long_start) ++{ ++ const float *lwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; ++ float *out = sce->ret; + +- s->samples = av_malloc(2 * 1024 * avctx->channels * sizeof(s->samples[0])); +- s->cpe = av_mallocz(sizeof(ChannelElement) * aac_chan_configs[avctx->channels-1][0]); +- avctx->extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE); +- avctx->extradata_size = 5; +- put_audio_specific_config(avctx); ++ dsp->vector_fmul(out, audio, lwindow, 1024); ++ memcpy(out + 1024, audio + 1024, sizeof(out[0]) * 448); ++ dsp->vector_fmul_reverse(out + 1024 + 448, audio + 1024 + 448, swindow, 128); ++ memset(out + 1024 + 576, 0, sizeof(out[0]) * 448); ++} + +- sizes[0] = swb_size_1024[i]; +- sizes[1] = swb_size_128[i]; +- lengths[0] = ff_aac_num_swb_1024[i]; +- lengths[1] = ff_aac_num_swb_128[i]; +- ff_psy_init(&s->psy, avctx, 2, sizes, lengths); +- s->psypp = ff_psy_preprocess_init(avctx); +- s->coder = &ff_aac_coders[2]; ++WINDOW_FUNC(long_stop) ++{ ++ const float *lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; ++ const float *swindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; ++ float *out = sce->ret; + +- s->lambda = avctx->global_quality ? avctx->global_quality : 120; ++ memset(out, 0, sizeof(out[0]) * 448); ++ dsp->vector_fmul(out + 448, audio + 448, swindow, 128); ++ memcpy(out + 576, audio + 576, sizeof(out[0]) * 448); ++ dsp->vector_fmul_reverse(out + 1024, audio + 1024, lwindow, 1024); ++} + +- ff_aac_tableinit(); ++WINDOW_FUNC(eight_short) ++{ ++ const float *swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; ++ const float *pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; ++ const float *in = audio + 448; ++ float *out = sce->ret; + +- return 0; ++ for (int w = 0; w < 8; w++) { ++ dsp->vector_fmul (out, in, w ? pwindow : swindow, 128); ++ out += 128; ++ in += 128; ++ dsp->vector_fmul_reverse(out, in, swindow, 128); ++ out += 128; ++ } + } + +-static void apply_window_and_mdct(AVCodecContext *avctx, AACEncContext *s, +- SingleChannelElement *sce, short *audio) ++static void (*const apply_window[4])(DSPContext *dsp, SingleChannelElement *sce, const float *audio) = { ++ [ONLY_LONG_SEQUENCE] = apply_only_long_window, ++ [LONG_START_SEQUENCE] = apply_long_start_window, ++ [EIGHT_SHORT_SEQUENCE] = apply_eight_short_window, ++ [LONG_STOP_SEQUENCE] = apply_long_stop_window ++}; ++ ++static void apply_window_and_mdct(AACEncContext *s, SingleChannelElement *sce, ++ float *audio) + { +- int i, k; +- const int chans = avctx->channels; +- const float * lwindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_long_1024 : ff_sine_1024; +- const float * swindow = sce->ics.use_kb_window[0] ? ff_aac_kbd_short_128 : ff_sine_128; +- const float * pwindow = sce->ics.use_kb_window[1] ? ff_aac_kbd_short_128 : ff_sine_128; +- +- if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) { +- memcpy(s->output, sce->saved, sizeof(float)*1024); +- if (sce->ics.window_sequence[0] == LONG_STOP_SEQUENCE) { +- memset(s->output, 0, sizeof(s->output[0]) * 448); +- for (i = 448; i < 576; i++) +- s->output[i] = sce->saved[i] * pwindow[i - 448]; +- for (i = 576; i < 704; i++) +- s->output[i] = sce->saved[i]; +- } +- if (sce->ics.window_sequence[0] != LONG_START_SEQUENCE) { +- for (i = 0; i < 1024; i++) { +- s->output[i+1024] = audio[i * chans] * lwindow[1024 - i - 1]; +- sce->saved[i] = audio[i * chans] * lwindow[i]; +- } +- } else { +- for (i = 0; i < 448; i++) +- s->output[i+1024] = audio[i * chans]; +- for (; i < 576; i++) +- s->output[i+1024] = audio[i * chans] * swindow[576 - i - 1]; +- memset(s->output+1024+576, 0, sizeof(s->output[0]) * 448); +- for (i = 0; i < 1024; i++) +- sce->saved[i] = audio[i * chans]; +- } +- ff_mdct_calc(&s->mdct1024, sce->coeffs, s->output); +- } else { +- for (k = 0; k < 1024; k += 128) { +- for (i = 448 + k; i < 448 + k + 256; i++) +- s->output[i - 448 - k] = (i < 1024) +- ? sce->saved[i] +- : audio[(i-1024)*chans]; +- s->dsp.vector_fmul (s->output, s->output, k ? swindow : pwindow, 128); +- s->dsp.vector_fmul_reverse(s->output+128, s->output+128, swindow, 128); +- ff_mdct_calc(&s->mdct128, sce->coeffs + k, s->output); +- } +- for (i = 0; i < 1024; i++) +- sce->saved[i] = audio[i * chans]; +- } ++ int i; ++ float *output = sce->ret; ++ ++ apply_window[sce->ics.window_sequence[0]](&s->dsp, sce, audio); ++ ++ if (sce->ics.window_sequence[0] != EIGHT_SHORT_SEQUENCE) ++ s->mdct1024.mdct_calc(&s->mdct1024, sce->coeffs, output); ++ else ++ for (i = 0; i < 1024; i += 128) ++ s->mdct128.mdct_calc(&s->mdct128, sce->coeffs + i, output + i*2); ++ memcpy(audio, audio + 1024, sizeof(audio[0]) * 1024); + } + + /** +@@ -359,7 +350,7 @@ + if (msc == 0 || ics0->max_sfb == 0) + cpe->ms_mode = 0; + else +- cpe->ms_mode = msc < ics0->max_sfb ? 1 : 2; ++ cpe->ms_mode = msc < ics0->max_sfb * ics0->num_windows ? 1 : 2; + } + } + +@@ -471,84 +462,103 @@ + put_bits(&s->pb, 3, TYPE_FIL); + put_bits(&s->pb, 4, FFMIN(namelen, 15)); + if (namelen >= 15) +- put_bits(&s->pb, 8, namelen - 16); ++ put_bits(&s->pb, 8, namelen - 14); + put_bits(&s->pb, 4, 0); //extension type - filler +- padbits = 8 - (put_bits_count(&s->pb) & 7); +- align_put_bits(&s->pb); ++ padbits = -put_bits_count(&s->pb) & 7; ++ avpriv_align_put_bits(&s->pb); + for (i = 0; i < namelen - 2; i++) + put_bits(&s->pb, 8, name[i]); + put_bits(&s->pb, 12 - padbits, 0); + } + ++/* ++ * Deinterleave input samples. ++ * Channels are reordered from Libav's default order to AAC order. ++ */ ++static void deinterleave_input_samples(AACEncContext *s, ++ const float *samples) ++{ ++ int ch, i; ++ const int sinc = s->channels; ++ const uint8_t *channel_map = aac_chan_maps[sinc - 1]; ++ ++ /* deinterleave and remap input samples */ ++ for (ch = 0; ch < sinc; ch++) { ++ const float *sptr = samples + channel_map[ch]; ++ ++ /* copy last 1024 samples of previous frame to the start of the current frame */ ++ memcpy(&s->planar_samples[ch][1024], &s->planar_samples[ch][2048], 1024 * sizeof(s->planar_samples[0][0])); ++ ++ /* deinterleave */ ++ for (i = 2048; i < 3072; i++) { ++ s->planar_samples[ch][i] = *sptr; ++ sptr += sinc; ++ } ++ } ++} ++ + static int aac_encode_frame(AVCodecContext *avctx, + uint8_t *frame, int buf_size, void *data) + { + AACEncContext *s = avctx->priv_data; +- int16_t *samples = s->samples, *samples2, *la; ++ float **samples = s->planar_samples, *samples2, *la, *overlap; + ChannelElement *cpe; +- int i, j, chans, tag, start_ch; +- const uint8_t *chan_map = aac_chan_configs[avctx->channels-1]; ++ int i, ch, w, g, chans, tag, start_ch; + int chan_el_counter[4]; + FFPsyWindowInfo windows[AAC_MAX_CHANNELS]; + + if (s->last_frame) + return 0; ++ + if (data) { +- if (!s->psypp) { +- memcpy(s->samples + 1024 * avctx->channels, data, +- 1024 * avctx->channels * sizeof(s->samples[0])); +- } else { +- start_ch = 0; +- samples2 = s->samples + 1024 * avctx->channels; +- for (i = 0; i < chan_map[0]; i++) { +- tag = chan_map[i+1]; +- chans = tag == TYPE_CPE ? 2 : 1; +- ff_psy_preprocess(s->psypp, (uint16_t*)data + start_ch, +- samples2 + start_ch, start_ch, chans); +- start_ch += chans; +- } +- } ++ deinterleave_input_samples(s, data); ++ if (s->psypp) ++ ff_psy_preprocess(s->psypp, s->planar_samples, s->channels); + } +- if (!avctx->frame_number) { +- memcpy(s->samples, s->samples + 1024 * avctx->channels, +- 1024 * avctx->channels * sizeof(s->samples[0])); ++ ++ if (!avctx->frame_number) + return 0; +- } + + start_ch = 0; +- for (i = 0; i < chan_map[0]; i++) { ++ for (i = 0; i < s->chan_map[0]; i++) { + FFPsyWindowInfo* wi = windows + start_ch; +- tag = chan_map[i+1]; ++ tag = s->chan_map[i+1]; + chans = tag == TYPE_CPE ? 2 : 1; + cpe = &s->cpe[i]; +- for (j = 0; j < chans; j++) { +- IndividualChannelStream *ics = &cpe->ch[j].ics; +- int k; +- int cur_channel = start_ch + j; +- samples2 = samples + cur_channel; +- la = samples2 + (448+64) * avctx->channels; ++ for (ch = 0; ch < chans; ch++) { ++ IndividualChannelStream *ics = &cpe->ch[ch].ics; ++ int cur_channel = start_ch + ch; ++ overlap = &samples[cur_channel][0]; ++ samples2 = overlap + 1024; ++ la = samples2 + (448+64); + if (!data) + la = NULL; + if (tag == TYPE_LFE) { +- wi[j].window_type[0] = ONLY_LONG_SEQUENCE; +- wi[j].window_shape = 0; +- wi[j].num_windows = 1; +- wi[j].grouping[0] = 1; ++ wi[ch].window_type[0] = ONLY_LONG_SEQUENCE; ++ wi[ch].window_shape = 0; ++ wi[ch].num_windows = 1; ++ wi[ch].grouping[0] = 1; ++ ++ /* Only the lowest 12 coefficients are used in a LFE channel. ++ * The expression below results in only the bottom 8 coefficients ++ * being used for 11.025kHz to 16kHz sample rates. ++ */ ++ ics->num_swb = s->samplerate_index >= 8 ? 1 : 3; + } else { +- wi[j] = ff_psy_suggest_window(&s->psy, samples2, la, cur_channel, ++ wi[ch] = s->psy.model->window(&s->psy, samples2, la, cur_channel, + ics->window_sequence[0]); + } + ics->window_sequence[1] = ics->window_sequence[0]; +- ics->window_sequence[0] = wi[j].window_type[0]; ++ ics->window_sequence[0] = wi[ch].window_type[0]; + ics->use_kb_window[1] = ics->use_kb_window[0]; +- ics->use_kb_window[0] = wi[j].window_shape; +- ics->num_windows = wi[j].num_windows; ++ ics->use_kb_window[0] = wi[ch].window_shape; ++ ics->num_windows = wi[ch].num_windows; + ics->swb_sizes = s->psy.bands [ics->num_windows == 8]; +- ics->num_swb = tag == TYPE_LFE ? 12 : s->psy.num_bands[ics->num_windows == 8]; +- for (k = 0; k < ics->num_windows; k++) +- ics->group_len[k] = wi[j].grouping[k]; ++ ics->num_swb = tag == TYPE_LFE ? ics->num_swb : s->psy.num_bands[ics->num_windows == 8]; ++ for (w = 0; w < ics->num_windows; w++) ++ ics->group_len[w] = wi[ch].grouping[w]; + +- apply_window_and_mdct(avctx, s, &cpe->ch[j], samples2); ++ apply_window_and_mdct(s, &cpe->ch[ch], overlap); + } + start_ch += chans; + } +@@ -559,17 +569,20 @@ + put_bitstream_info(avctx, s, LIBAVCODEC_IDENT); + start_ch = 0; + memset(chan_el_counter, 0, sizeof(chan_el_counter)); +- for (i = 0; i < chan_map[0]; i++) { ++ for (i = 0; i < s->chan_map[0]; i++) { + FFPsyWindowInfo* wi = windows + start_ch; +- tag = chan_map[i+1]; ++ const float *coeffs[2]; ++ tag = s->chan_map[i+1]; + chans = tag == TYPE_CPE ? 2 : 1; + cpe = &s->cpe[i]; + put_bits(&s->pb, 3, tag); + put_bits(&s->pb, 4, chan_el_counter[tag]++); +- for (j = 0; j < chans; j++) { +- s->cur_channel = start_ch + j; +- ff_psy_set_band_info(&s->psy, s->cur_channel, cpe->ch[j].coeffs, &wi[j]); +- s->coder->search_for_quantizers(avctx, s, &cpe->ch[j], s->lambda); ++ for (ch = 0; ch < chans; ch++) ++ coeffs[ch] = cpe->ch[ch].coeffs; ++ s->psy.model->analyze(&s->psy, start_ch, coeffs, wi); ++ for (ch = 0; ch < chans; ch++) { ++ s->cur_channel = start_ch * 2 + ch; ++ s->coder->search_for_quantizers(avctx, s, &cpe->ch[ch], s->lambda); + } + cpe->common_window = 0; + if (chans > 1 +@@ -577,16 +590,24 @@ + && wi[0].window_shape == wi[1].window_shape) { + + cpe->common_window = 1; +- for (j = 0; j < wi[0].num_windows; j++) { +- if (wi[0].grouping[j] != wi[1].grouping[j]) { ++ for (w = 0; w < wi[0].num_windows; w++) { ++ if (wi[0].grouping[w] != wi[1].grouping[w]) { + cpe->common_window = 0; + break; + } + } + } +- s->cur_channel = start_ch; +- if (cpe->common_window && s->coder->search_for_ms) +- s->coder->search_for_ms(s, cpe, s->lambda); ++ s->cur_channel = start_ch * 2; ++ if (s->options.stereo_mode && cpe->common_window) { ++ if (s->options.stereo_mode > 0) { ++ IndividualChannelStream *ics = &cpe->ch[0].ics; ++ for (w = 0; w < ics->num_windows; w += ics->group_len[w]) ++ for (g = 0; g < ics->num_swb; g++) ++ cpe->ms_mask[w*16+g] = 1; ++ } else if (s->coder->search_for_ms) { ++ s->coder->search_for_ms(s, cpe, s->lambda); ++ } ++ } + adjust_frame_information(s, cpe, chans); + if (chans == 2) { + put_bits(&s->pb, 1, cpe->common_window); +@@ -595,16 +616,18 @@ + encode_ms_info(&s->pb, cpe); + } + } +- for (j = 0; j < chans; j++) { +- s->cur_channel = start_ch + j; +- encode_individual_channel(avctx, s, &cpe->ch[j], cpe->common_window); ++ for (ch = 0; ch < chans; ch++) { ++ s->cur_channel = start_ch + ch; ++ encode_individual_channel(avctx, s, &cpe->ch[ch], cpe->common_window); + } + start_ch += chans; + } + + frame_bits = put_bits_count(&s->pb); +- if (frame_bits <= 6144 * avctx->channels - 3) ++ if (frame_bits <= 6144 * s->channels - 3) { ++ s->psy.bitres.bits = frame_bits / s->channels; + break; ++ } + + s->lambda *= avctx->bit_rate * 1024.0f / avctx->sample_rate / frame_bits; + +@@ -623,8 +646,7 @@ + + if (!data) + s->last_frame = 1; +- memcpy(s->samples, s->samples + 1024 * avctx->channels, +- 1024 * avctx->channels * sizeof(s->samples[0])); ++ + return put_bits_count(&s->pb)>>3; + } + +@@ -635,27 +657,142 @@ + ff_mdct_end(&s->mdct1024); + ff_mdct_end(&s->mdct128); + ff_psy_end(&s->psy); +- ff_psy_preprocess_end(s->psypp); +- av_freep(&s->samples); ++ if (s->psypp) ++ ff_psy_preprocess_end(s->psypp); ++ av_freep(&s->buffer.samples); + av_freep(&s->cpe); + return 0; + } + ++static av_cold int dsp_init(AVCodecContext *avctx, AACEncContext *s) ++{ ++ int ret = 0; ++ ++ dsputil_init(&s->dsp, avctx); ++ ++ // window init ++ ff_kbd_window_init(ff_aac_kbd_long_1024, 4.0, 1024); ++ ff_kbd_window_init(ff_aac_kbd_short_128, 6.0, 128); ++ ff_init_ff_sine_windows(10); ++ ff_init_ff_sine_windows(7); ++ ++ if (ret = ff_mdct_init(&s->mdct1024, 11, 0, 32768.0)) ++ return ret; ++ if (ret = ff_mdct_init(&s->mdct128, 8, 0, 32768.0)) ++ return ret; ++ ++ return 0; ++} ++ ++static av_cold int alloc_buffers(AVCodecContext *avctx, AACEncContext *s) ++{ ++ FF_ALLOCZ_OR_GOTO(avctx, s->buffer.samples, 3 * 1024 * s->channels * sizeof(s->buffer.samples[0]), alloc_fail); ++ FF_ALLOCZ_OR_GOTO(avctx, s->cpe, sizeof(ChannelElement) * s->chan_map[0], alloc_fail); ++ FF_ALLOCZ_OR_GOTO(avctx, avctx->extradata, 5 + FF_INPUT_BUFFER_PADDING_SIZE, alloc_fail); ++ ++ for(int ch = 0; ch < s->channels; ch++) ++ s->planar_samples[ch] = s->buffer.samples + 3 * 1024 * ch; ++ ++ return 0; ++alloc_fail: ++ return AVERROR(ENOMEM); ++} ++ ++static av_cold int aac_encode_init(AVCodecContext *avctx) ++{ ++ AACEncContext *s = avctx->priv_data; ++ int i, ret = 0; ++ const uint8_t *sizes[2]; ++ uint8_t grouping[AAC_MAX_CHANNELS]; ++ int lengths[2]; ++ ++ avctx->frame_size = 1024; ++ ++ for (i = 0; i < 16; i++) ++ if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[i]) ++ break; ++ ++ s->channels = avctx->channels; ++ ++ ERROR_IF(i == 16, ++ "Unsupported sample rate %d\n", avctx->sample_rate); ++ ERROR_IF(s->channels > AAC_MAX_CHANNELS, ++ "Unsupported number of channels: %d\n", s->channels); ++ ERROR_IF(avctx->profile != FF_PROFILE_UNKNOWN && avctx->profile != FF_PROFILE_AAC_LOW, ++ "Unsupported profile %d\n", avctx->profile); ++ ERROR_IF(1024.0 * avctx->bit_rate / avctx->sample_rate > 6144 * s->channels, ++ "Too many bits per frame requested\n"); ++ ++ s->samplerate_index = i; ++ ++ s->chan_map = aac_chan_configs[s->channels-1]; ++ ++ if (ret = dsp_init(avctx, s)) ++ goto fail; ++ ++ if (ret = alloc_buffers(avctx, s)) ++ goto fail; ++ ++ avctx->extradata_size = 5; ++ put_audio_specific_config(avctx); ++ ++ sizes[0] = swb_size_1024[i]; ++ sizes[1] = swb_size_128[i]; ++ lengths[0] = ff_aac_num_swb_1024[i]; ++ lengths[1] = ff_aac_num_swb_128[i]; ++ for (i = 0; i < s->chan_map[0]; i++) ++ grouping[i] = s->chan_map[i + 1] == TYPE_CPE; ++ if (ret = ff_psy_init(&s->psy, avctx, 2, sizes, lengths, s->chan_map[0], grouping)) ++ goto fail; ++ s->psypp = ff_psy_preprocess_init(avctx); ++ s->coder = &ff_aac_coders[s->options.aac_coder]; ++ ++ s->lambda = avctx->global_quality ? avctx->global_quality : 120; ++ ++ ff_aac_tableinit(); ++ ++ for (i = 0; i < 428; i++) ++ ff_aac_pow34sf_tab[i] = sqrt(ff_aac_pow2sf_tab[i] * sqrt(ff_aac_pow2sf_tab[i])); ++ ++ return 0; ++fail: ++ aac_encode_end(avctx); ++ return ret; ++} ++ ++#define AACENC_FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM ++static const AVOption aacenc_options[] = { ++ {"stereo_mode", "Stereo coding method", offsetof(AACEncContext, options.stereo_mode), AV_OPT_TYPE_INT, {.dbl = 0}, -1, 1, AACENC_FLAGS, "stereo_mode"}, ++ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = -1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"}, ++ {"ms_off", "Disable Mid/Side coding", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"}, ++ {"ms_force", "Force Mid/Side for the whole frame if possible", 0, AV_OPT_TYPE_CONST, {.dbl = 1 }, INT_MIN, INT_MAX, AACENC_FLAGS, "stereo_mode"}, ++ {"aac_coder", "", offsetof(AACEncContext, options.aac_coder), AV_OPT_TYPE_INT, {.dbl = 2}, 0, AAC_CODER_NB-1, AACENC_FLAGS}, ++ {NULL} ++}; ++ ++static const AVClass aacenc_class = { ++ "AAC encoder", ++ av_default_item_name, ++ aacenc_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ + static const AVProfile profiles[] = { + { FF_PROFILE_AAC_LOW, "Low" }, + { FF_PROFILE_UNKNOWN }, + }; + + AVCodec ff_aac_encoder = { +- "aac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AAC, +- sizeof(AACEncContext), +- aac_encode_init, +- aac_encode_frame, +- aac_encode_end, ++ .name = "aac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AAC, ++ .priv_data_size = sizeof(AACEncContext), ++ .init = aac_encode_init, ++ .encode = aac_encode_frame, ++ .close = aac_encode_end, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), ++ .priv_class = &aacenc_class, + .profiles = profiles, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacenc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacenc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacenc.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacenc.h 2012-05-14 14:08:53.302319211 +0200 +@@ -30,6 +30,13 @@ + + #include "psymodel.h" + ++#define AAC_CODER_NB 4 ++ ++typedef struct AACEncOptions { ++ int stereo_mode; ++ int aac_coder; ++} AACEncOptions; ++ + struct AACEncContext; + + typedef struct AACCoefficientsEncoder { +@@ -48,14 +55,17 @@ + * AAC encoder context + */ + typedef struct AACEncContext { ++ AVClass *av_class; ++ AACEncOptions options; ///< encoding options + PutBitContext pb; + FFTContext mdct1024; ///< long (1024 samples) frame transform context + FFTContext mdct128; ///< short (128 samples) frame transform context + DSPContext dsp; +- DECLARE_ALIGNED(16, FFTSample, output)[2048]; ///< temporary buffer for MDCT input coefficients +- int16_t* samples; ///< saved preprocessed input ++ float *planar_samples[6]; ///< saved preprocessed input + + int samplerate_index; ///< MPEG-4 samplerate index ++ int channels; ///< channel count ++ const uint8_t *chan_map; ///< channel configuration map + + ChannelElement *cpe; ///< channel elements + FFPsyContext psy; +@@ -65,7 +75,13 @@ + int last_frame; + float lambda; + DECLARE_ALIGNED(16, int, qcoefs)[96]; ///< quantized coefficients +- DECLARE_ALIGNED(16, float, scoefs)[1024]; ///< scaled coefficients ++ DECLARE_ALIGNED(32, float, scoefs)[1024]; ///< scaled coefficients ++ ++ struct { ++ float *samples; ++ } buffer; + } AACEncContext; + ++extern float ff_aac_pow34sf_tab[428]; ++ + #endif /* AVCODEC_AACENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac.h 2012-05-14 14:08:53.278318728 +0200 +@@ -43,6 +43,7 @@ + #define MAX_ELEM_ID 16 + + #define TNS_MAX_ORDER 20 ++#define MAX_LTP_LONG_SFB 40 + + enum RawDataBlockType { + TYPE_SCE, +@@ -83,6 +84,7 @@ + #define IS_CODEBOOK_UNSIGNED(x) ((x - 1) & 10) + + enum ChannelPosition { ++ AAC_CHANNEL_OFF = 0, + AAC_CHANNEL_FRONT = 1, + AAC_CHANNEL_SIDE = 2, + AAC_CHANNEL_BACK = 3, +@@ -103,11 +105,11 @@ + * Output configuration status + */ + enum OCStatus { +- OC_NONE, //< Output unconfigured +- OC_TRIAL_PCE, //< Output configuration under trial specified by an inband PCE +- OC_TRIAL_FRAME, //< Output configuration under trial specified by a frame header +- OC_GLOBAL_HDR, //< Output configuration set in a global header but not yet locked +- OC_LOCKED, //< Output configuration locked in place ++ OC_NONE, ///< Output unconfigured ++ OC_TRIAL_PCE, ///< Output configuration under trial specified by an inband PCE ++ OC_TRIAL_FRAME, ///< Output configuration under trial specified by a frame header ++ OC_GLOBAL_HDR, ///< Output configuration set in a global header but not yet locked ++ OC_LOCKED, ///< Output configuration locked in place + }; + + /** +@@ -129,6 +131,17 @@ + #define SCALE_MAX_POS 255 ///< scalefactor index maximum value + #define SCALE_MAX_DIFF 60 ///< maximum scalefactor difference allowed by standard + #define SCALE_DIFF_ZERO 60 ///< codebook index corresponding to zero scalefactor indices difference ++#define POW_SF2_ZERO 200 ///< ff_aac_pow2sf_tab index corresponding to pow(2, 0); ++ ++/** ++ * Long Term Prediction ++ */ ++typedef struct { ++ int8_t present; ++ int16_t lag; ++ float coef; ++ int8_t used[MAX_LTP_LONG_SFB]; ++} LongTermPrediction; + + /** + * Individual Channel Stream +@@ -139,6 +152,7 @@ + uint8_t use_kb_window[2]; ///< If set, use Kaiser-Bessel window, otherwise use a sinus window. + int num_window_groups; + uint8_t group_len[8]; ++ LongTermPrediction ltp; + const uint16_t *swb_offset; ///< table of offsets to the lowest spectral coefficient of a scalefactor band, sfb, for a particular window + const uint8_t *swb_sizes; ///< table of scalefactor band sizes for a particular window + int num_swb; ///< number of scalefactor window bands +@@ -206,14 +220,15 @@ + IndividualChannelStream ics; + TemporalNoiseShaping tns; + Pulse pulse; +- enum BandType band_type[128]; ///< band types +- int band_type_run_end[120]; ///< band type run end points +- float sf[120]; ///< scalefactors +- int sf_idx[128]; ///< scalefactor indices (used by encoder) +- uint8_t zeroes[128]; ///< band is not coded (used by encoder) +- DECLARE_ALIGNED(16, float, coeffs)[1024]; ///< coefficients for IMDCT +- DECLARE_ALIGNED(16, float, saved)[1024]; ///< overlap +- DECLARE_ALIGNED(16, float, ret)[2048]; ///< PCM output ++ enum BandType band_type[128]; ///< band types ++ int band_type_run_end[120]; ///< band type run end points ++ float sf[120]; ///< scalefactors ++ int sf_idx[128]; ///< scalefactor indices (used by encoder) ++ uint8_t zeroes[128]; ///< band is not coded (used by encoder) ++ DECLARE_ALIGNED(32, float, coeffs)[1024]; ///< coefficients for IMDCT ++ DECLARE_ALIGNED(32, float, saved)[1024]; ///< overlap ++ DECLARE_ALIGNED(32, float, ret)[2048]; ///< PCM output ++ DECLARE_ALIGNED(16, float, ltp_state)[3072]; ///< time signal for LTP + PredictorState predictor_state[MAX_PREDICTORS]; + } SingleChannelElement; + +@@ -237,6 +252,7 @@ + */ + typedef struct { + AVCodecContext *avctx; ++ AVFrame frame; + + MPEG4AudioConfig m4ac; + +@@ -244,7 +260,7 @@ + DynamicRangeControl che_drc; + + /** +- * @defgroup elements Channel element related data. ++ * @name Channel element related data + * @{ + */ + enum ChannelPosition che_pos[4][MAX_ELEM_ID]; /**< channel element channel mapping with the +@@ -256,35 +272,36 @@ + /** @} */ + + /** +- * @defgroup temporary aligned temporary buffers (We do not want to have these on the stack.) ++ * @name temporary aligned temporary buffers ++ * (We do not want to have these on the stack.) + * @{ + */ +- DECLARE_ALIGNED(16, float, buf_mdct)[1024]; ++ DECLARE_ALIGNED(32, float, buf_mdct)[1024]; + /** @} */ + + /** +- * @defgroup tables Computed / set up during initialization. ++ * @name Computed / set up during initialization + * @{ + */ + FFTContext mdct; + FFTContext mdct_small; ++ FFTContext mdct_ltp; + DSPContext dsp; + FmtConvertContext fmt_conv; + int random_state; + /** @} */ + + /** +- * @defgroup output Members used for output interleaving. ++ * @name Members used for output interleaving + * @{ + */ + float *output_data[MAX_CHANNELS]; ///< Points to each element's 'ret' buffer (PCM output). +- float sf_scale; ///< Pre-scale for correct IMDCT and dsp.float_to_int16. +- int sf_offset; ///< offset into pow2sf_tab as appropriate for dsp.float_to_int16 + /** @} */ + +- DECLARE_ALIGNED(16, float, temp)[128]; ++ DECLARE_ALIGNED(32, float, temp)[128]; + + enum OCStatus output_configured; ++ int warned_num_aac_frames; + } AACContext; + + #endif /* AVCODEC_AAC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_parser.c 2012-05-14 14:08:53.283318829 +0200 +@@ -40,7 +40,7 @@ + tmp.u64 = av_be2ne64(state); + init_get_bits(&bits, tmp.u8+8-AAC_ADTS_HEADER_SIZE, AAC_ADTS_HEADER_SIZE * 8); + +- if ((size = ff_aac_parse_header(&bits, &hdr)) < 0) ++ if ((size = avpriv_aac_parse_header(&bits, &hdr)) < 0) + return 0; + *need_next_header = 0; + *new_frame_start = 1; +@@ -61,9 +61,9 @@ + + + AVCodecParser ff_aac_parser = { +- { CODEC_ID_AAC }, +- sizeof(AACAC3ParseContext), +- aac_parse_init, +- ff_aac_ac3_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_AAC }, ++ .priv_data_size = sizeof(AACAC3ParseContext), ++ .parser_init = aac_parse_init, ++ .parser_parse = ff_aac_ac3_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacps.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacps.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacps.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacps.c 2012-05-14 14:08:53.304319251 +0200 +@@ -28,9 +28,9 @@ + #include "aacps_tablegen.h" + #include "aacpsdata.c" + +-#define PS_BASELINE 0 //< Operate in Baseline PS mode +- //< Baseline implies 10 or 20 stereo bands, +- //< mixing mode A, and no ipd/opd ++#define PS_BASELINE 0 ///< Operate in Baseline PS mode ++ ///< Baseline implies 10 or 20 stereo bands, ++ ///< mixing mode A, and no ipd/opd + + #define numQMFSlots 32 //numTimeSlots * RATE + +@@ -69,19 +69,19 @@ + + static VLC vlc_ps[10]; + +-/** +- * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ +- * Inter-channel Phase Difference/Overall Phase Difference parameters from the +- * bitstream. +- * +- * @param avctx contains the current codec context +- * @param gb pointer to the input bitstream +- * @param ps pointer to the Parametric Stereo context +- * @param par pointer to the parameter to be read +- * @param e envelope to decode +- * @param dt 1: time delta-coded, 0: frequency delta-coded +- */ + #define READ_PAR_DATA(PAR, OFFSET, MASK, ERR_CONDITION) \ ++/** \ ++ * Read Inter-channel Intensity Difference/Inter-Channel Coherence/ \ ++ * Inter-channel Phase Difference/Overall Phase Difference parameters from the \ ++ * bitstream. \ ++ * \ ++ * @param avctx contains the current codec context \ ++ * @param gb pointer to the input bitstream \ ++ * @param ps pointer to the Parametric Stereo context \ ++ * @param PAR pointer to the parameter to be read \ ++ * @param e envelope to decode \ ++ * @param dt 1: time delta-coded, 0: frequency delta-coded \ ++ */ \ + static int read_ ## PAR ## _data(AVCodecContext *avctx, GetBitContext *gb, PSContext *ps, \ + int8_t (*PAR)[PS_MAX_NR_IIDICC], int table_idx, int e, int dt) \ + { \ +@@ -223,7 +223,7 @@ + cnt -= 2 + ps_read_extension_data(gb, ps, ps_extension_id); + } + if (cnt < 0) { +- av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d", cnt); ++ av_log(avctx, AV_LOG_ERROR, "ps extension overflow %d\n", cnt); + goto err; + } + skip_bits(gb, cnt); +@@ -654,7 +654,7 @@ + const int8_t *k_to_i = is34 ? k_to_i_34 : k_to_i_20; + const float peak_decay_factor = 0.76592833836465f; + const float transient_impact = 1.5f; +- const float a_smooth = 0.25f; //< Smoothing coefficient ++ const float a_smooth = 0.25f; ///< Smoothing coefficient + int i, k, m, n; + int n0 = 0, nL = 32; + static const int link_delay[] = { 3, 4, 5 }; +@@ -813,14 +813,17 @@ + const float (*H_LUT)[8][4] = (PS_BASELINE || ps->icc_mode < 3) ? HA : HB; + + //Remapping +- memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0])); +- memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0])); +- memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0])); +- memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0])); +- memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0])); +- memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0])); +- memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0])); +- memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0])); ++ if (ps->num_env_old) { ++ memcpy(H11[0][0], H11[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[0][0][0])); ++ memcpy(H11[1][0], H11[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H11[1][0][0])); ++ memcpy(H12[0][0], H12[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[0][0][0])); ++ memcpy(H12[1][0], H12[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H12[1][0][0])); ++ memcpy(H21[0][0], H21[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[0][0][0])); ++ memcpy(H21[1][0], H21[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H21[1][0][0])); ++ memcpy(H22[0][0], H22[0][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[0][0][0])); ++ memcpy(H22[1][0], H22[1][ps->num_env_old], PS_MAX_NR_IIDICC*sizeof(H22[1][0][0])); ++ } ++ + if (is34) { + remap34(&iid_mapped, ps->iid_par, ps->nr_iid_par, ps->num_env, 1); + remap34(&icc_mapped, ps->icc_par, ps->nr_icc_par, ps->num_env, 1); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacps.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacps.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacps.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacps.h 2012-05-14 14:08:53.305319272 +0200 +@@ -52,11 +52,11 @@ + int num_env; + int enable_ipdopd; + int border_position[PS_MAX_NUM_ENV+1]; +- int8_t iid_par[PS_MAX_NUM_ENV][PS_MAX_NR_IIDICC]; // 22kbps/channel (20dB/Bark) */ ++#define PSY_3GPP_EN_SPREAD_HI_L1 2.0f ++/* spreading factor for low-to-hi energy spreading, long block, <= 22kbps/channel (15dB/Bark) */ ++#define PSY_3GPP_EN_SPREAD_HI_L2 1.5f ++/* spreading factor for low-to-hi energy spreading, short block (15 dB/Bark) */ ++#define PSY_3GPP_EN_SPREAD_HI_S 1.5f ++/* spreading factor for hi-to-low energy spreading, long block (30dB/Bark) */ ++#define PSY_3GPP_EN_SPREAD_LOW_L 3.0f ++/* spreading factor for hi-to-low energy spreading, short block (20dB/Bark) */ ++#define PSY_3GPP_EN_SPREAD_LOW_S 2.0f + + #define PSY_3GPP_RPEMIN 0.01f + #define PSY_3GPP_RPELEV 2.0f + ++#define PSY_3GPP_C1 3.0f /* log2(8) */ ++#define PSY_3GPP_C2 1.3219281f /* log2(2.5) */ ++#define PSY_3GPP_C3 0.55935729f /* 1 - C2 / C1 */ ++ ++#define PSY_SNR_1DB 7.9432821e-1f /* -1dB */ ++#define PSY_SNR_25DB 3.1622776e-3f /* -25dB */ ++ ++#define PSY_3GPP_SAVE_SLOPE_L -0.46666667f ++#define PSY_3GPP_SAVE_SLOPE_S -0.36363637f ++#define PSY_3GPP_SAVE_ADD_L -0.84285712f ++#define PSY_3GPP_SAVE_ADD_S -0.75f ++#define PSY_3GPP_SPEND_SLOPE_L 0.66666669f ++#define PSY_3GPP_SPEND_SLOPE_S 0.81818181f ++#define PSY_3GPP_SPEND_ADD_L -0.35f ++#define PSY_3GPP_SPEND_ADD_S -0.26111111f ++#define PSY_3GPP_CLIP_LO_L 0.2f ++#define PSY_3GPP_CLIP_LO_S 0.2f ++#define PSY_3GPP_CLIP_HI_L 0.95f ++#define PSY_3GPP_CLIP_HI_S 0.75f ++ ++#define PSY_3GPP_AH_THR_LONG 0.5f ++#define PSY_3GPP_AH_THR_SHORT 0.63f ++ ++enum { ++ PSY_3GPP_AH_NONE, ++ PSY_3GPP_AH_INACTIVE, ++ PSY_3GPP_AH_ACTIVE ++}; ++ ++#define PSY_3GPP_BITS_TO_PE(bits) ((bits) * 1.18f) ++ + /* LAME psy model constants */ + #define PSY_LAME_FIR_LEN 21 ///< LAME psy model FIR order + #define AAC_BLOCK_SIZE_LONG 1024 ///< long block size +@@ -60,11 +100,15 @@ + * information for single band used by 3GPP TS26.403-inspired psychoacoustic model + */ + typedef struct AacPsyBand{ +- float energy; ///< band energy +- float ffac; ///< form factor +- float thr; ///< energy threshold +- float min_snr; ///< minimal SNR +- float thr_quiet; ///< threshold in quiet ++ float energy; ///< band energy ++ float thr; ///< energy threshold ++ float thr_quiet; ///< threshold in quiet ++ float nz_lines; ///< number of non-zero spectral lines ++ float active_lines; ///< number of active spectral lines ++ float pe; ///< perceptual entropy ++ float pe_const; ///< constant part of the PE calculation ++ float norm_fac; ///< normalization factor for linearization ++ int avoid_holes; ///< hole avoidance flag + }AacPsyBand; + + /** +@@ -88,17 +132,27 @@ + * psychoacoustic model frame type-dependent coefficients + */ + typedef struct AacPsyCoeffs{ +- float ath [64]; ///< absolute threshold of hearing per bands +- float barks [64]; ///< Bark value for each spectral band in long frame +- float spread_low[64]; ///< spreading factor for low-to-high threshold spreading in long frame +- float spread_hi [64]; ///< spreading factor for high-to-low threshold spreading in long frame ++ float ath; ///< absolute threshold of hearing per bands ++ float barks; ///< Bark value for each spectral band in long frame ++ float spread_low[2]; ///< spreading factor for low-to-high threshold spreading in long frame ++ float spread_hi [2]; ///< spreading factor for high-to-low threshold spreading in long frame ++ float min_snr; ///< minimal SNR + }AacPsyCoeffs; + + /** + * 3GPP TS26.403-inspired psychoacoustic model specific data + */ + typedef struct AacPsyContext{ +- AacPsyCoeffs psy_coef[2]; ++ int chan_bitrate; ///< bitrate per channel ++ int frame_bits; ///< average bits per frame ++ int fill_level; ///< bit reservoir fill level ++ struct { ++ float min; ///< minimum allowed PE for bit factor calculation ++ float max; ///< maximum allowed PE for bit factor calculation ++ float previous; ///< allowed PE of the previous frame ++ float correction; ///< PE correction factor ++ } pe; ++ AacPsyCoeffs psy_coef[2][64]; + AacPsyChannel *ch; + }AacPsyContext; + +@@ -162,7 +216,7 @@ + }; + + /** +- * calculates the attack threshold for ABR from the above table for the LAME psy model ++ * Calculate the ABR attack threshold from the above LAME psymodel table. + */ + static float lame_calc_attack_threshold(int bitrate) + { +@@ -236,34 +290,59 @@ + AacPsyContext *pctx; + float bark; + int i, j, g, start; +- float prev, minscale, minath; ++ float prev, minscale, minath, minsnr, pe_min; ++ const int chan_bitrate = ctx->avctx->bit_rate / ctx->avctx->channels; ++ const int bandwidth = ctx->avctx->cutoff ? ctx->avctx->cutoff : ctx->avctx->sample_rate / 2; ++ const float num_bark = calc_bark((float)bandwidth); + + ctx->model_priv_data = av_mallocz(sizeof(AacPsyContext)); + pctx = (AacPsyContext*) ctx->model_priv_data; + ++ pctx->chan_bitrate = chan_bitrate; ++ pctx->frame_bits = chan_bitrate * AAC_BLOCK_SIZE_LONG / ctx->avctx->sample_rate; ++ pctx->pe.min = 8.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f); ++ pctx->pe.max = 12.0f * AAC_BLOCK_SIZE_LONG * bandwidth / (ctx->avctx->sample_rate * 2.0f); ++ ctx->bitres.size = 6144 - pctx->frame_bits; ++ ctx->bitres.size -= ctx->bitres.size % 8; ++ pctx->fill_level = ctx->bitres.size; + minath = ath(3410, ATH_ADD); + for (j = 0; j < 2; j++) { +- AacPsyCoeffs *coeffs = &pctx->psy_coef[j]; ++ AacPsyCoeffs *coeffs = pctx->psy_coef[j]; ++ const uint8_t *band_sizes = ctx->bands[j]; + float line_to_frequency = ctx->avctx->sample_rate / (j ? 256.f : 2048.0f); ++ float avg_chan_bits = chan_bitrate / ctx->avctx->sample_rate * (j ? 128.0f : 1024.0f); ++ /* reference encoder uses 2.4% here instead of 60% like the spec says */ ++ float bark_pe = 0.024f * PSY_3GPP_BITS_TO_PE(avg_chan_bits) / num_bark; ++ float en_spread_low = j ? PSY_3GPP_EN_SPREAD_LOW_S : PSY_3GPP_EN_SPREAD_LOW_L; ++ /* High energy spreading for long blocks <= 22kbps/channel and short blocks are the same. */ ++ float en_spread_hi = (j || (chan_bitrate <= 22.0f)) ? PSY_3GPP_EN_SPREAD_HI_S : PSY_3GPP_EN_SPREAD_HI_L1; ++ + i = 0; + prev = 0.0; + for (g = 0; g < ctx->num_bands[j]; g++) { +- i += ctx->bands[j][g]; ++ i += band_sizes[g]; + bark = calc_bark((i-1) * line_to_frequency); +- coeffs->barks[g] = (bark + prev) / 2.0; ++ coeffs[g].barks = (bark + prev) / 2.0; + prev = bark; + } + for (g = 0; g < ctx->num_bands[j] - 1; g++) { +- coeffs->spread_low[g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_LOW); +- coeffs->spread_hi [g] = pow(10.0, -(coeffs->barks[g+1] - coeffs->barks[g]) * PSY_3GPP_SPREAD_HI); ++ AacPsyCoeffs *coeff = &coeffs[g]; ++ float bark_width = coeffs[g+1].barks - coeffs->barks; ++ coeff->spread_low[0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_LOW); ++ coeff->spread_hi [0] = pow(10.0, -bark_width * PSY_3GPP_THR_SPREAD_HI); ++ coeff->spread_low[1] = pow(10.0, -bark_width * en_spread_low); ++ coeff->spread_hi [1] = pow(10.0, -bark_width * en_spread_hi); ++ pe_min = bark_pe * bark_width; ++ minsnr = pow(2.0f, pe_min / band_sizes[g]) - 1.5f; ++ coeff->min_snr = av_clipf(1.0f / minsnr, PSY_SNR_25DB, PSY_SNR_1DB); + } + start = 0; + for (g = 0; g < ctx->num_bands[j]; g++) { + minscale = ath(start * line_to_frequency, ATH_ADD); +- for (i = 1; i < ctx->bands[j][g]; i++) ++ for (i = 1; i < band_sizes[g]; i++) + minscale = FFMIN(minscale, ath((start + i) * line_to_frequency, ATH_ADD)); +- coeffs->ath[g] = minscale - minath; +- start += ctx->bands[j][g]; ++ coeffs[g].ath = minscale - minath; ++ start += band_sizes[g]; + } + } + +@@ -298,9 +377,10 @@ + * Tell encoder which window types to use. + * @see 3GPP TS26.403 5.4.1 "Blockswitching" + */ +-static FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx, +- const int16_t *audio, const int16_t *la, +- int channel, int prev_type) ++static av_unused FFPsyWindowInfo psy_3gpp_window(FFPsyContext *ctx, ++ const int16_t *audio, ++ const int16_t *la, ++ int channel, int prev_type) + { + int i, j; + int br = ctx->avctx->bit_rate / ctx->avctx->channels; +@@ -320,7 +400,7 @@ + int stay_short = 0; + for (i = 0; i < 8; i++) { + for (j = 0; j < 128; j++) { +- v = iir_filter(la[(i*128+j)*ctx->avctx->channels], pch->iir_state); ++ v = iir_filter(la[i*128+j], pch->iir_state); + sum += v*v; + } + s[i] = sum; +@@ -383,52 +463,294 @@ + return wi; + } + ++/* 5.6.1.2 "Calculation of Bit Demand" */ ++static int calc_bit_demand(AacPsyContext *ctx, float pe, int bits, int size, ++ int short_window) ++{ ++ const float bitsave_slope = short_window ? PSY_3GPP_SAVE_SLOPE_S : PSY_3GPP_SAVE_SLOPE_L; ++ const float bitsave_add = short_window ? PSY_3GPP_SAVE_ADD_S : PSY_3GPP_SAVE_ADD_L; ++ const float bitspend_slope = short_window ? PSY_3GPP_SPEND_SLOPE_S : PSY_3GPP_SPEND_SLOPE_L; ++ const float bitspend_add = short_window ? PSY_3GPP_SPEND_ADD_S : PSY_3GPP_SPEND_ADD_L; ++ const float clip_low = short_window ? PSY_3GPP_CLIP_LO_S : PSY_3GPP_CLIP_LO_L; ++ const float clip_high = short_window ? PSY_3GPP_CLIP_HI_S : PSY_3GPP_CLIP_HI_L; ++ float clipped_pe, bit_save, bit_spend, bit_factor, fill_level; ++ ++ ctx->fill_level += ctx->frame_bits - bits; ++ ctx->fill_level = av_clip(ctx->fill_level, 0, size); ++ fill_level = av_clipf((float)ctx->fill_level / size, clip_low, clip_high); ++ clipped_pe = av_clipf(pe, ctx->pe.min, ctx->pe.max); ++ bit_save = (fill_level + bitsave_add) * bitsave_slope; ++ assert(bit_save <= 0.3f && bit_save >= -0.05000001f); ++ bit_spend = (fill_level + bitspend_add) * bitspend_slope; ++ assert(bit_spend <= 0.5f && bit_spend >= -0.1f); ++ /* The bit factor graph in the spec is obviously incorrect. ++ * bit_spend + ((bit_spend - bit_spend))... ++ * The reference encoder subtracts everything from 1, but also seems incorrect. ++ * 1 - bit_save + ((bit_spend + bit_save))... ++ * Hopefully below is correct. ++ */ ++ bit_factor = 1.0f - bit_save + ((bit_spend - bit_save) / (ctx->pe.max - ctx->pe.min)) * (clipped_pe - ctx->pe.min); ++ /* NOTE: The reference encoder attempts to center pe max/min around the current pe. */ ++ ctx->pe.max = FFMAX(pe, ctx->pe.max); ++ ctx->pe.min = FFMIN(pe, ctx->pe.min); ++ ++ return FFMIN(ctx->frame_bits * bit_factor, ctx->frame_bits + size - bits); ++} ++ ++static float calc_pe_3gpp(AacPsyBand *band) ++{ ++ float pe, a; ++ ++ band->pe = 0.0f; ++ band->pe_const = 0.0f; ++ band->active_lines = 0.0f; ++ if (band->energy > band->thr) { ++ a = log2f(band->energy); ++ pe = a - log2f(band->thr); ++ band->active_lines = band->nz_lines; ++ if (pe < PSY_3GPP_C1) { ++ pe = pe * PSY_3GPP_C3 + PSY_3GPP_C2; ++ a = a * PSY_3GPP_C3 + PSY_3GPP_C2; ++ band->active_lines *= PSY_3GPP_C3; ++ } ++ band->pe = pe * band->nz_lines; ++ band->pe_const = a * band->nz_lines; ++ } ++ ++ return band->pe; ++} ++ ++static float calc_reduction_3gpp(float a, float desired_pe, float pe, ++ float active_lines) ++{ ++ float thr_avg, reduction; ++ ++ thr_avg = powf(2.0f, (a - pe) / (4.0f * active_lines)); ++ reduction = powf(2.0f, (a - desired_pe) / (4.0f * active_lines)) - thr_avg; ++ ++ return FFMAX(reduction, 0.0f); ++} ++ ++static float calc_reduced_thr_3gpp(AacPsyBand *band, float min_snr, ++ float reduction) ++{ ++ float thr = band->thr; ++ ++ if (band->energy > thr) { ++ thr = powf(thr, 0.25f) + reduction; ++ thr = powf(thr, 4.0f); ++ ++ /* This deviates from the 3GPP spec to match the reference encoder. ++ * It performs min(thr_reduced, max(thr, energy/min_snr)) only for bands ++ * that have hole avoidance on (active or inactive). It always reduces the ++ * threshold of bands with hole avoidance off. ++ */ ++ if (thr > band->energy * min_snr && band->avoid_holes != PSY_3GPP_AH_NONE) { ++ thr = FFMAX(band->thr, band->energy * min_snr); ++ band->avoid_holes = PSY_3GPP_AH_ACTIVE; ++ } ++ } ++ ++ return thr; ++} ++ + /** + * Calculate band thresholds as suggested in 3GPP TS26.403 + */ +-static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, +- const float *coefs, const FFPsyWindowInfo *wi) ++static void psy_3gpp_analyze_channel(FFPsyContext *ctx, int channel, ++ const float *coefs, const FFPsyWindowInfo *wi) + { + AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; + AacPsyChannel *pch = &pctx->ch[channel]; + int start = 0; + int i, w, g; +- const int num_bands = ctx->num_bands[wi->num_windows == 8]; +- const uint8_t* band_sizes = ctx->bands[wi->num_windows == 8]; +- AacPsyCoeffs *coeffs = &pctx->psy_coef[wi->num_windows == 8]; ++ float desired_bits, desired_pe, delta_pe, reduction, spread_en[128] = {0}; ++ float a = 0.0f, active_lines = 0.0f, norm_fac = 0.0f; ++ float pe = pctx->chan_bitrate > 32000 ? 0.0f : FFMAX(50.0f, 100.0f - pctx->chan_bitrate * 100.0f / 32000.0f); ++ const int num_bands = ctx->num_bands[wi->num_windows == 8]; ++ const uint8_t *band_sizes = ctx->bands[wi->num_windows == 8]; ++ AacPsyCoeffs *coeffs = pctx->psy_coef[wi->num_windows == 8]; ++ const float avoid_hole_thr = wi->num_windows == 8 ? PSY_3GPP_AH_THR_SHORT : PSY_3GPP_AH_THR_LONG; + + //calculate energies, initial thresholds and related values - 5.4.2 "Threshold Calculation" + for (w = 0; w < wi->num_windows*16; w += 16) { + for (g = 0; g < num_bands; g++) { + AacPsyBand *band = &pch->band[w+g]; ++ ++ float form_factor = 0.0f; + band->energy = 0.0f; +- for (i = 0; i < band_sizes[g]; i++) ++ for (i = 0; i < band_sizes[g]; i++) { + band->energy += coefs[start+i] * coefs[start+i]; +- band->thr = band->energy * 0.001258925f; +- start += band_sizes[g]; ++ form_factor += sqrtf(fabs(coefs[start+i])); ++ } ++ band->thr = band->energy * 0.001258925f; ++ band->nz_lines = form_factor / powf(band->energy / band_sizes[g], 0.25f); + +- ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].energy = band->energy; ++ start += band_sizes[g]; + } + } +- //modify thresholds - spread, threshold in quiet - 5.4.3 "Spreaded Energy Calculation" ++ //modify thresholds and energies - spread, threshold in quiet, pre-echo control + for (w = 0; w < wi->num_windows*16; w += 16) { +- AacPsyBand *band = &pch->band[w]; +- for (g = 1; g < num_bands; g++) +- band[g].thr = FFMAX(band[g].thr, band[g-1].thr * coeffs->spread_hi [g]); +- for (g = num_bands - 2; g >= 0; g--) +- band[g].thr = FFMAX(band[g].thr, band[g+1].thr * coeffs->spread_low[g]); ++ AacPsyBand *bands = &pch->band[w]; ++ ++ //5.4.2.3 "Spreading" & 5.4.3 "Spreaded Energy Calculation" ++ spread_en[0] = bands[0].energy; ++ for (g = 1; g < num_bands; g++) { ++ bands[g].thr = FFMAX(bands[g].thr, bands[g-1].thr * coeffs[g].spread_hi[0]); ++ spread_en[w+g] = FFMAX(bands[g].energy, spread_en[w+g-1] * coeffs[g].spread_hi[1]); ++ } ++ for (g = num_bands - 2; g >= 0; g--) { ++ bands[g].thr = FFMAX(bands[g].thr, bands[g+1].thr * coeffs[g].spread_low[0]); ++ spread_en[w+g] = FFMAX(spread_en[w+g], spread_en[w+g+1] * coeffs[g].spread_low[1]); ++ } ++ //5.4.2.4 "Threshold in quiet" + for (g = 0; g < num_bands; g++) { +- band[g].thr_quiet = band[g].thr = FFMAX(band[g].thr, coeffs->ath[g]); ++ AacPsyBand *band = &bands[g]; ++ ++ band->thr_quiet = band->thr = FFMAX(band->thr, coeffs[g].ath); ++ //5.4.2.5 "Pre-echo control" + if (!(wi->window_type[0] == LONG_STOP_SEQUENCE || (wi->window_type[1] == LONG_START_SEQUENCE && !w))) +- band[g].thr = FFMAX(PSY_3GPP_RPEMIN*band[g].thr, FFMIN(band[g].thr, +- PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet)); ++ band->thr = FFMAX(PSY_3GPP_RPEMIN*band->thr, FFMIN(band->thr, ++ PSY_3GPP_RPELEV*pch->prev_band[w+g].thr_quiet)); + +- ctx->psy_bands[channel*PSY_MAX_BANDS+w+g].threshold = band[g].thr; ++ /* 5.6.1.3.1 "Prepatory steps of the perceptual entropy calculation" */ ++ pe += calc_pe_3gpp(band); ++ a += band->pe_const; ++ active_lines += band->active_lines; ++ ++ /* 5.6.1.3.3 "Selection of the bands for avoidance of holes" */ ++ if (spread_en[w+g] * avoid_hole_thr > band->energy || coeffs[g].min_snr > 1.0f) ++ band->avoid_holes = PSY_3GPP_AH_NONE; ++ else ++ band->avoid_holes = PSY_3GPP_AH_INACTIVE; + } + } ++ ++ /* 5.6.1.3.2 "Calculation of the desired perceptual entropy" */ ++ ctx->ch[channel].entropy = pe; ++ desired_bits = calc_bit_demand(pctx, pe, ctx->bitres.bits, ctx->bitres.size, wi->num_windows == 8); ++ desired_pe = PSY_3GPP_BITS_TO_PE(desired_bits); ++ /* NOTE: PE correction is kept simple. During initial testing it had very ++ * little effect on the final bitrate. Probably a good idea to come ++ * back and do more testing later. ++ */ ++ if (ctx->bitres.bits > 0) ++ desired_pe *= av_clipf(pctx->pe.previous / PSY_3GPP_BITS_TO_PE(ctx->bitres.bits), ++ 0.85f, 1.15f); ++ pctx->pe.previous = PSY_3GPP_BITS_TO_PE(desired_bits); ++ ++ if (desired_pe < pe) { ++ /* 5.6.1.3.4 "First Estimation of the reduction value" */ ++ for (w = 0; w < wi->num_windows*16; w += 16) { ++ reduction = calc_reduction_3gpp(a, desired_pe, pe, active_lines); ++ pe = 0.0f; ++ a = 0.0f; ++ active_lines = 0.0f; ++ for (g = 0; g < num_bands; g++) { ++ AacPsyBand *band = &pch->band[w+g]; ++ ++ band->thr = calc_reduced_thr_3gpp(band, coeffs[g].min_snr, reduction); ++ /* recalculate PE */ ++ pe += calc_pe_3gpp(band); ++ a += band->pe_const; ++ active_lines += band->active_lines; ++ } ++ } ++ ++ /* 5.6.1.3.5 "Second Estimation of the reduction value" */ ++ for (i = 0; i < 2; i++) { ++ float pe_no_ah = 0.0f, desired_pe_no_ah; ++ active_lines = a = 0.0f; ++ for (w = 0; w < wi->num_windows*16; w += 16) { ++ for (g = 0; g < num_bands; g++) { ++ AacPsyBand *band = &pch->band[w+g]; ++ ++ if (band->avoid_holes != PSY_3GPP_AH_ACTIVE) { ++ pe_no_ah += band->pe; ++ a += band->pe_const; ++ active_lines += band->active_lines; ++ } ++ } ++ } ++ desired_pe_no_ah = FFMAX(desired_pe - (pe - pe_no_ah), 0.0f); ++ if (active_lines > 0.0f) ++ reduction += calc_reduction_3gpp(a, desired_pe_no_ah, pe_no_ah, active_lines); ++ ++ pe = 0.0f; ++ for (w = 0; w < wi->num_windows*16; w += 16) { ++ for (g = 0; g < num_bands; g++) { ++ AacPsyBand *band = &pch->band[w+g]; ++ ++ if (active_lines > 0.0f) ++ band->thr = calc_reduced_thr_3gpp(band, coeffs[g].min_snr, reduction); ++ pe += calc_pe_3gpp(band); ++ band->norm_fac = band->active_lines / band->thr; ++ norm_fac += band->norm_fac; ++ } ++ } ++ delta_pe = desired_pe - pe; ++ if (fabs(delta_pe) > 0.05f * desired_pe) ++ break; ++ } ++ ++ if (pe < 1.15f * desired_pe) { ++ /* 6.6.1.3.6 "Final threshold modification by linearization" */ ++ norm_fac = 1.0f / norm_fac; ++ for (w = 0; w < wi->num_windows*16; w += 16) { ++ for (g = 0; g < num_bands; g++) { ++ AacPsyBand *band = &pch->band[w+g]; ++ ++ if (band->active_lines > 0.5f) { ++ float delta_sfb_pe = band->norm_fac * norm_fac * delta_pe; ++ float thr = band->thr; ++ ++ thr *= powf(2.0f, delta_sfb_pe / band->active_lines); ++ if (thr > coeffs[g].min_snr * band->energy && band->avoid_holes == PSY_3GPP_AH_INACTIVE) ++ thr = FFMAX(band->thr, coeffs[g].min_snr * band->energy); ++ band->thr = thr; ++ } ++ } ++ } ++ } else { ++ /* 5.6.1.3.7 "Further perceptual entropy reduction" */ ++ g = num_bands; ++ while (pe > desired_pe && g--) { ++ for (w = 0; w < wi->num_windows*16; w+= 16) { ++ AacPsyBand *band = &pch->band[w+g]; ++ if (band->avoid_holes != PSY_3GPP_AH_NONE && coeffs[g].min_snr < PSY_SNR_1DB) { ++ coeffs[g].min_snr = PSY_SNR_1DB; ++ band->thr = band->energy * PSY_SNR_1DB; ++ pe += band->active_lines * 1.5f - band->pe; ++ } ++ } ++ } ++ /* TODO: allow more holes (unused without mid/side) */ ++ } ++ } ++ ++ for (w = 0; w < wi->num_windows*16; w += 16) { ++ for (g = 0; g < num_bands; g++) { ++ AacPsyBand *band = &pch->band[w+g]; ++ FFPsyBand *psy_band = &ctx->ch[channel].psy_bands[w+g]; ++ ++ psy_band->threshold = band->thr; ++ psy_band->energy = band->energy; ++ } ++ } ++ + memcpy(pch->prev_band, pch->band, sizeof(pch->band)); + } + ++static void psy_3gpp_analyze(FFPsyContext *ctx, int channel, ++ const float **coeffs, const FFPsyWindowInfo *wi) ++{ ++ int ch; ++ FFPsyChannelGroup *group = ff_psy_find_group(ctx, channel); ++ ++ for (ch = 0; ch < group->num_ch; ch++) ++ psy_3gpp_analyze_channel(ctx, channel + ch, coeffs[ch], &wi[ch]); ++} ++ + static av_cold void psy_3gpp_end(FFPsyContext *apc) + { + AacPsyContext *pctx = (AacPsyContext*) apc->model_priv_data; +@@ -454,9 +776,8 @@ + ctx->next_window_seq = blocktype; + } + +-static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, +- const int16_t *audio, const int16_t *la, +- int channel, int prev_type) ++static FFPsyWindowInfo psy_lame_window(FFPsyContext *ctx, const float *audio, ++ const float *la, int channel, int prev_type) + { + AacPsyContext *pctx = (AacPsyContext*) ctx->model_priv_data; + AacPsyChannel *pch = &pctx->ch[channel]; +@@ -473,20 +794,20 @@ + float attack_intensity[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; + float energy_subshort[(AAC_NUM_BLOCKS_SHORT + 1) * PSY_LAME_NUM_SUBBLOCKS]; + float energy_short[AAC_NUM_BLOCKS_SHORT + 1] = { 0 }; +- int chans = ctx->avctx->channels; +- const int16_t *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN) * chans; ++ const float *firbuf = la + (AAC_BLOCK_SIZE_SHORT/4 - PSY_LAME_FIR_LEN); + int j, att_sum = 0; + + /* LAME comment: apply high pass filter of fs/4 */ + for (i = 0; i < AAC_BLOCK_SIZE_LONG; i++) { + float sum1, sum2; +- sum1 = firbuf[(i + ((PSY_LAME_FIR_LEN - 1) / 2)) * chans]; ++ sum1 = firbuf[i + (PSY_LAME_FIR_LEN - 1) / 2]; + sum2 = 0.0; + for (j = 0; j < ((PSY_LAME_FIR_LEN - 1) / 2) - 1; j += 2) { +- sum1 += psy_fir_coeffs[j] * (firbuf[(i + j) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j) * chans]); +- sum2 += psy_fir_coeffs[j + 1] * (firbuf[(i + j + 1) * chans] + firbuf[(i + PSY_LAME_FIR_LEN - j - 1) * chans]); ++ sum1 += psy_fir_coeffs[j] * (firbuf[i + j] + firbuf[i + PSY_LAME_FIR_LEN - j]); ++ sum2 += psy_fir_coeffs[j + 1] * (firbuf[i + j + 1] + firbuf[i + PSY_LAME_FIR_LEN - j - 1]); + } +- hpfsmpl[i] = sum1 + sum2; ++ /* NOTE: The LAME psymodel expects it's input in the range -32768 to 32768. Tuning this for normalized floats would be difficult. */ ++ hpfsmpl[i] = (sum1 + sum2) * 32768.0f; + } + + /* Calculate the energies of each sub-shortblock */ +@@ -501,16 +822,15 @@ + float const *const pfe = pf + AAC_BLOCK_SIZE_LONG / (AAC_NUM_BLOCKS_SHORT * PSY_LAME_NUM_SUBBLOCKS); + float p = 1.0f; + for (; pf < pfe; pf++) +- if (p < fabsf(*pf)) +- p = fabsf(*pf); ++ p = FFMAX(p, fabsf(*pf)); + pch->prev_energy_subshort[i] = energy_subshort[i + PSY_LAME_NUM_SUBBLOCKS] = p; + energy_short[1 + i / PSY_LAME_NUM_SUBBLOCKS] += p; +- /* FIXME: The indexes below are [i + 3 - 2] in the LAME source. +- * Obviously the 3 and 2 have some significance, or this would be just [i + 1] +- * (which is what we use here). What the 3 stands for is ambigious, as it is both +- * number of short blocks, and the number of sub-short blocks. +- * It seems that LAME is comparing each sub-block to sub-block + 1 in the +- * previous block. ++ /* NOTE: The indexes below are [i + 3 - 2] in the LAME source. ++ * Obviously the 3 and 2 have some significance, or this would be just [i + 1] ++ * (which is what we use here). What the 3 stands for is ambiguous, as it is both ++ * number of short blocks, and the number of sub-short blocks. ++ * It seems that LAME is comparing each sub-block to sub-block + 1 in the ++ * previous block. + */ + if (p > energy_subshort[i + 1]) + p = p / energy_subshort[i + 1]; +@@ -553,22 +873,9 @@ + if (pch->prev_attack == 3 || att_sum) { + uselongblock = 0; + +- if (attacks[1] && attacks[0]) +- attacks[1] = 0; +- if (attacks[2] && attacks[1]) +- attacks[2] = 0; +- if (attacks[3] && attacks[2]) +- attacks[3] = 0; +- if (attacks[4] && attacks[3]) +- attacks[4] = 0; +- if (attacks[5] && attacks[4]) +- attacks[5] = 0; +- if (attacks[6] && attacks[5]) +- attacks[6] = 0; +- if (attacks[7] && attacks[6]) +- attacks[7] = 0; +- if (attacks[8] && attacks[7]) +- attacks[8] = 0; ++ for (i = 1; i < AAC_NUM_BLOCKS_SHORT + 1; i++) ++ if (attacks[i] && attacks[i-1]) ++ attacks[i] = 0; + } + } else { + /* We have no lookahead info, so just use same type as the previous sequence. */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacsbr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacsbr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacsbr.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacsbr.c 2012-05-14 14:08:53.311319393 +0200 +@@ -32,9 +32,12 @@ + #include "aacsbrdata.h" + #include "fft.h" + #include "aacps.h" ++#include "libavutil/libm.h" ++#include "libavutil/avassert.h" + + #include + #include ++#include + + #define ENVELOPE_ADJUSTMENT_OFFSET 2 + #define NOISE_FLOOR_OFFSET 6.0f +@@ -125,14 +128,21 @@ + ff_ps_init(); + } + +-av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr) ++av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr) + { ++ float mdct_scale; ++ if(sbr->mdct.mdct_bits) ++ return; + sbr->kx[0] = sbr->kx[1] = 32; //Typo in spec, kx' inits to 32 + sbr->data[0].e_a[1] = sbr->data[1].e_a[1] = -1; + sbr->data[0].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); + sbr->data[1].synthesis_filterbank_samples_offset = SBR_SYNTHESIS_BUF_SIZE - (1280 - 128); +- ff_mdct_init(&sbr->mdct, 7, 1, 1.0/64); +- ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0); ++ /* SBR requires samples to be scaled to +/-32768.0 to work correctly. ++ * mdct scale factors are adjusted to scale up from +/-1.0 at analysis ++ * and scale back down at synthesis. */ ++ mdct_scale = ac->avctx->sample_fmt == AV_SAMPLE_FMT_FLT ? 32768.0f : 1.0f; ++ ff_mdct_init(&sbr->mdct, 7, 1, 1.0 / (64 * mdct_scale)); ++ ff_mdct_init(&sbr->mdct_ana, 7, 1, -2.0 * mdct_scale); + ff_ps_ctx_init(&sbr->ps); + } + +@@ -1134,16 +1144,12 @@ + * @param W array of complex-valued samples split into subbands + */ + static void sbr_qmf_analysis(DSPContext *dsp, FFTContext *mdct, const float *in, float *x, +- float z[320], float W[2][32][32][2], +- float scale) ++ float z[320], float W[2][32][32][2]) + { + int i, k; + memcpy(W[0], W[1], sizeof(W[0])); + memcpy(x , x+1024, (320-32)*sizeof(x[0])); +- if (scale != 1.0f) +- dsp->vector_fmul_scalar(x+288, in, scale, 1024); +- else +- memcpy(x+288, in, 1024*sizeof(*x)); ++ memcpy(x+288, in, 1024*sizeof(x[0])); + for (i = 0; i < 32; i++) { // numTimeSlots*RATE = 16*2 as 960 sample frames + // are not supported + dsp->vector_fmul_reverse(z, sbr_qmf_window_ds, x, 320); +@@ -1159,7 +1165,7 @@ + } + z[64+63] = z[32]; + +- ff_imdct_half(mdct, z, z+64); ++ mdct->imdct_half(mdct, z, z+64); + for (k = 0; k < 32; k++) { + W[1][i][k][0] = -z[63-k]; + W[1][i][k][1] = z[k]; +@@ -1179,14 +1185,15 @@ + { + int i, n; + const float *sbr_qmf_window = div ? sbr_qmf_window_ds : sbr_qmf_window_us; ++ const int step = 128 >> div; + float *v; + for (i = 0; i < 32; i++) { +- if (*v_off == 0) { ++ if (*v_off < step) { + int saved_samples = (1280 - 128) >> div; + memcpy(&v0[SBR_SYNTHESIS_BUF_SIZE - saved_samples], v0, saved_samples * sizeof(float)); +- *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - (128 >> div); ++ *v_off = SBR_SYNTHESIS_BUF_SIZE - saved_samples - step; + } else { +- *v_off -= 128 >> div; ++ *v_off -= step; + } + v = v0 + *v_off; + if (div) { +@@ -1194,7 +1201,7 @@ + X[0][i][ n] = -X[0][i][n]; + X[0][i][32+n] = X[1][i][31-n]; + } +- ff_imdct_half(mdct, mdct_buf[0], X[0][i]); ++ mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); + for (n = 0; n < 32; n++) { + v[ n] = mdct_buf[0][63 - 2*n]; + v[63 - n] = -mdct_buf[0][62 - 2*n]; +@@ -1203,8 +1210,8 @@ + for (n = 1; n < 64; n+=2) { + X[1][i][n] = -X[1][i][n]; + } +- ff_imdct_half(mdct, mdct_buf[0], X[0][i]); +- ff_imdct_half(mdct, mdct_buf[1], X[1][i]); ++ mdct->imdct_half(mdct, mdct_buf[0], X[0][i]); ++ mdct->imdct_half(mdct, mdct_buf[1], X[1][i]); + for (n = 0; n < 64; n++) { + v[ n] = -mdct_buf[0][63 - n] + mdct_buf[1][ n ]; + v[127 - n] = mdct_buf[0][63 - n] + mdct_buf[1][ n ]; +@@ -1454,6 +1461,7 @@ + uint16_t *table = ch_data->bs_freq_res[e + 1] ? sbr->f_tablehigh : sbr->f_tablelow; + int k; + ++ av_assert0(sbr->kx[1] <= table[0]); + for (i = 0; i < ilim; i++) + for (m = table[i]; m < table[i + 1]; m++) + sbr->e_origmapped[e][m - sbr->kx[1]] = ch_data->env_facs[e+1][i]; +@@ -1722,7 +1730,7 @@ + /* decode channel */ + sbr_qmf_analysis(&ac->dsp, &sbr->mdct_ana, ch ? R : L, sbr->data[ch].analysis_filterbank_samples, + (float*)sbr->qmf_filter_scratch, +- sbr->data[ch].W, 1/(-1024 * ac->sf_scale)); ++ sbr->data[ch].W); + sbr_lf_gen(ac, sbr, sbr->X_low, sbr->data[ch].W); + if (sbr->start) { + sbr_hf_inverse_filter(sbr->alpha0, sbr->alpha1, sbr->X_low, sbr->k[0]); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacsbr.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacsbr.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aacsbr.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aacsbr.h 2012-05-14 14:08:53.311319393 +0200 +@@ -36,7 +36,7 @@ + /** Initialize SBR. */ + av_cold void ff_aac_sbr_init(void); + /** Initialize one SBR context. */ +-av_cold void ff_aac_sbr_ctx_init(SpectralBandReplication *sbr); ++av_cold void ff_aac_sbr_ctx_init(AACContext *ac, SpectralBandReplication *sbr); + /** Close one SBR context. */ + av_cold void ff_aac_sbr_ctx_close(SpectralBandReplication *sbr); + /** Decode one SBR element. */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_tablegen_decl.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_tablegen_decl.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_tablegen_decl.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_tablegen_decl.h 2012-05-14 14:08:53.285318869 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef AAC_TABLEGEN_DECL_H +-#define AAC_TABLEGEN_DECL_H ++#ifndef AVCODEC_AAC_TABLEGEN_DECL_H ++#define AVCODEC_AAC_TABLEGEN_DECL_H + + #if CONFIG_HARDCODED_TABLES + #define ff_aac_tableinit() +@@ -31,4 +31,4 @@ + extern float ff_aac_pow2sf_tab[428]; + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* AAC_TABLEGEN_DECL_H */ ++#endif /* AVCODEC_AAC_TABLEGEN_DECL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aac_tablegen.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aac_tablegen.h 2012-05-14 14:08:53.284318849 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef AAC_TABLEGEN_H +-#define AAC_TABLEGEN_H ++#ifndef AVCODEC_AAC_TABLEGEN_H ++#define AVCODEC_AAC_TABLEGEN_H + + #include "aac_tablegen_decl.h" + +@@ -29,14 +29,15 @@ + #include "libavcodec/aac_tables.h" + #else + #include "libavutil/mathematics.h" ++#include "aac.h" + float ff_aac_pow2sf_tab[428]; + + void ff_aac_tableinit(void) + { + int i; + for (i = 0; i < 428; i++) +- ff_aac_pow2sf_tab[i] = pow(2, (i - 200) / 4.); ++ ff_aac_pow2sf_tab[i] = pow(2, (i - POW_SF2_ZERO) / 4.); + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* AAC_TABLEGEN_H */ ++#endif /* AVCODEC_AAC_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aasc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aasc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aasc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aasc.c 2012-05-14 14:08:53.312319413 +0200 +@@ -50,8 +50,8 @@ + AascContext *s = avctx->priv_data; + + s->avctx = avctx; +- + avctx->pix_fmt = PIX_FMT_BGR24; ++ avcodec_get_frame_defaults(&s->frame); + + return 0; + } +@@ -65,7 +65,7 @@ + AascContext *s = avctx->priv_data; + int compr, i, stride; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -79,8 +79,13 @@ + case 0: + stride = (avctx->width * 3 + 3) & ~3; + for(i = avctx->height - 1; i >= 0; i--){ ++ if(avctx->width*3 > buf_size){ ++ av_log(avctx, AV_LOG_ERROR, "Next line is beyond buffer bounds\n"); ++ break; ++ } + memcpy(s->frame.data[0] + i*s->frame.linesize[0], buf, avctx->width*3); + buf += stride; ++ buf_size -= stride; + } + break; + case 1: +@@ -110,14 +115,13 @@ + } + + AVCodec ff_aasc_decoder = { +- "aasc", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_AASC, +- sizeof(AascContext), +- aasc_decode_init, +- NULL, +- aasc_decode_end, +- aasc_decode_frame, +- CODEC_CAP_DR1, ++ .name = "aasc", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AASC, ++ .priv_data_size = sizeof(AascContext), ++ .init = aasc_decode_init, ++ .close = aasc_decode_end, ++ .decode = aasc_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Autodesk RLE"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3.c 2012-05-14 14:08:53.315319473 +0200 +@@ -31,7 +31,7 @@ + /** + * Starting frequency coefficient bin for each critical band. + */ +-static const uint8_t band_start_tab[AC3_CRITICAL_BANDS+1] = { ++const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, + 20, 21, 22, 23, 24, 25, 26, 27, 28, 31, +@@ -44,7 +44,7 @@ + /** + * Map each frequency coefficient bin to the critical band that contains it. + */ +-static const uint8_t bin_to_band_tab[253] = { ++const uint8_t ff_ac3_bin_to_band_tab[253] = { + 0, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +@@ -70,7 +70,7 @@ + }; + + #else /* CONFIG_HARDCODED_TABLES */ +-static uint8_t bin_to_band_tab[253]; ++uint8_t ff_ac3_bin_to_band_tab[253]; + #endif + + static inline int calc_lowcomp1(int a, int b0, int b1, int c) +@@ -106,10 +106,10 @@ + + /* PSD integration */ + bin = start; +- band = bin_to_band_tab[start]; ++ band = ff_ac3_bin_to_band_tab[start]; + do { + int v = psd[bin++]; +- int band_end = FFMIN(band_start_tab[band+1], end); ++ int band_end = FFMIN(ff_ac3_band_start_tab[band+1], end); + for (; bin < band_end; bin++) { + int max = FFMAX(v, psd[bin]); + /* logadd */ +@@ -117,7 +117,7 @@ + v = max + ff_ac3_log_add_tab[adr]; + } + band_psd[band++] = v; +- } while (end > band_start_tab[band]); ++ } while (end > ff_ac3_band_start_tab[band]); + } + + int ff_ac3_bit_alloc_calc_mask(AC3BitAllocParameters *s, int16_t *band_psd, +@@ -132,8 +132,8 @@ + int lowcomp, fastleak, slowleak; + + /* excitation function */ +- band_start = bin_to_band_tab[start]; +- band_end = bin_to_band_tab[end-1] + 1; ++ band_start = ff_ac3_bin_to_band_tab[start]; ++ band_end = ff_ac3_bin_to_band_tab[end-1] + 1; + + if (band_start == 0) { + lowcomp = 0; +@@ -192,9 +192,9 @@ + + if (dba_mode == DBA_REUSE || dba_mode == DBA_NEW) { + int i, seg, delta; +- if (dba_nsegs >= 8) ++ if (dba_nsegs > 8) + return -1; +- band = 0; ++ band = band_start; + for (seg = 0; seg < dba_nsegs; seg++) { + band += dba_offsets[seg]; + if (band >= AC3_CRITICAL_BANDS || dba_lengths[seg] > AC3_CRITICAL_BANDS-band) +@@ -212,30 +212,6 @@ + return 0; + } + +-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, +- int snr_offset, int floor, +- const uint8_t *bap_tab, uint8_t *bap) +-{ +- int bin, band; +- +- /* special case, if snr offset is -960, set all bap's to zero */ +- if (snr_offset == -960) { +- memset(bap, 0, AC3_MAX_COEFS); +- return; +- } +- +- bin = start; +- band = bin_to_band_tab[start]; +- do { +- int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; +- int band_end = FFMIN(band_start_tab[band+1], end); +- for (; bin < band_end; bin++) { +- int address = av_clip((psd[bin] - m) >> 5, 0, 63); +- bap[bin] = bap_tab[address]; +- } +- } while (end > band_start_tab[band++]); +-} +- + /** + * Initialize some tables. + * note: This function must remain thread safe because it is called by the +@@ -244,12 +220,12 @@ + av_cold void ff_ac3_common_init(void) + { + #if !CONFIG_HARDCODED_TABLES +- /* compute bin_to_band_tab from band_start_tab */ ++ /* compute ff_ac3_bin_to_band_tab from ff_ac3_band_start_tab */ + int bin = 0, band; + for (band = 0; band < AC3_CRITICAL_BANDS; band++) { +- int band_end = band_start_tab[band+1]; ++ int band_end = ff_ac3_band_start_tab[band+1]; + while (bin < band_end) +- bin_to_band_tab[bin++] = band; ++ ff_ac3_bin_to_band_tab[bin++] = band; + } + #endif /* !CONFIG_HARDCODED_TABLES */ + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec.c 2012-05-14 14:08:53.323319635 +0200 +@@ -30,14 +30,13 @@ + #include + + #include "libavutil/crc.h" ++#include "libavutil/opt.h" + #include "internal.h" + #include "aac_ac3_parser.h" + #include "ac3_parser.h" + #include "ac3dec.h" + #include "ac3dec_data.h" +- +-/** Large enough for maximum possible frame size when the specification limit is ignored */ +-#define AC3_FRAME_BUFFER_SIZE 32768 ++#include "kbdwin.h" + + /** + * table for ungrouping 3 values in 7 bits. +@@ -45,7 +44,6 @@ + */ + static uint8_t ungroup_3_in_7_bits_tab[128][3]; + +- + /** tables for ungrouping mantissas */ + static int b1_mantissas[32][3]; + static int b2_mantissas[128][3]; +@@ -66,16 +64,6 @@ + static float dynamic_range_tab[256]; + + /** Adjustments in dB gain */ +-#define LEVEL_PLUS_3DB 1.4142135623730950 +-#define LEVEL_PLUS_1POINT5DB 1.1892071150027209 +-#define LEVEL_MINUS_1POINT5DB 0.8408964152537145 +-#define LEVEL_MINUS_3DB 0.7071067811865476 +-#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 +-#define LEVEL_MINUS_6DB 0.5000000000000000 +-#define LEVEL_MINUS_9DB 0.3535533905932738 +-#define LEVEL_ZERO 0.0000000000000000 +-#define LEVEL_ONE 1.0000000000000000 +- + static const float gain_levels[9] = { + LEVEL_PLUS_3DB, + LEVEL_PLUS_1POINT5DB, +@@ -89,18 +77,6 @@ + }; + + /** +- * Table for center mix levels +- * reference: Section 5.4.2.4 cmixlev +- */ +-static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; +- +-/** +- * Table for surround mix levels +- * reference: Section 5.4.2.5 surmixlev +- */ +-static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; +- +-/** + * Table for default stereo downmixing coefficients + * reference: Section 7.8.2 Downmixing Into Two Channels + */ +@@ -135,7 +111,7 @@ + + /* generate table for ungrouping 3 values in 7 bits + reference: Section 7.1.3 Exponent Decoding */ +- for(i=0; i<128; i++) { ++ for (i = 0; i < 128; i++) { + ungroup_3_in_7_bits_tab[i][0] = i / 25; + ungroup_3_in_7_bits_tab[i][1] = (i % 25) / 5; + ungroup_3_in_7_bits_tab[i][2] = (i % 25) % 5; +@@ -143,13 +119,13 @@ + + /* generate grouped mantissa tables + reference: Section 7.3.5 Ungrouping of Mantissas */ +- for(i=0; i<32; i++) { ++ for (i = 0; i < 32; i++) { + /* bap=1 mantissas */ + b1_mantissas[i][0] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][0], 3); + b1_mantissas[i][1] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][1], 3); + b1_mantissas[i][2] = symmetric_dequant(ff_ac3_ungroup_3_in_5_bits_tab[i][2], 3); + } +- for(i=0; i<128; i++) { ++ for (i = 0; i < 128; i++) { + /* bap=2 mantissas */ + b2_mantissas[i][0] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][0], 5); + b2_mantissas[i][1] = symmetric_dequant(ungroup_3_in_7_bits_tab[i][1], 5); +@@ -161,24 +137,23 @@ + } + /* generate ungrouped mantissa tables + reference: Tables 7.21 and 7.23 */ +- for(i=0; i<7; i++) { ++ for (i = 0; i < 7; i++) { + /* bap=3 mantissas */ + b3_mantissas[i] = symmetric_dequant(i, 7); + } +- for(i=0; i<15; i++) { ++ for (i = 0; i < 15; i++) { + /* bap=5 mantissas */ + b5_mantissas[i] = symmetric_dequant(i, 15); + } + + /* generate dynamic range table + reference: Section 7.7.1 Dynamic Range Control */ +- for(i=0; i<256; i++) { ++ for (i = 0; i < 256; i++) { + int v = (i >> 5) - ((i >> 7) << 3) - 5; + dynamic_range_tab[i] = powf(2.0f, v) * ((i & 0x1F) | 0x20); + } + } + +- + /** + * AVCodec initialization + */ +@@ -187,17 +162,29 @@ + AC3DecodeContext *s = avctx->priv_data; + s->avctx = avctx; + ++#if FF_API_DRC_SCALE ++ if (avctx->drc_scale) ++ s->drc_scale = avctx->drc_scale; ++#endif ++ + ff_ac3_common_init(); + ac3_tables_init(); + ff_mdct_init(&s->imdct_256, 8, 1, 1.0); + ff_mdct_init(&s->imdct_512, 9, 1, 1.0); + ff_kbd_window_init(s->window, 5.0, 256); + dsputil_init(&s->dsp, avctx); ++ ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); + ff_fmt_convert_init(&s->fmt_conv, avctx); + av_lfg_init(&s->dith_state, 0); + + /* set scale value for float to int16 conversion */ +- s->mul_bias = 32767.0f; ++ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { ++ s->mul_bias = 1.0f; ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ } else { ++ s->mul_bias = 32767.0f; ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ } + + /* allow downmixing to stereo or mono */ + if (avctx->channels > 0 && avctx->request_channels > 0 && +@@ -207,14 +194,9 @@ + } + s->downmixed = 1; + +- /* allocate context input buffer */ +- if (avctx->error_recognition >= FF_ER_CAREFUL) { +- s->input_buffer = av_mallocz(AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!s->input_buffer) +- return AVERROR(ENOMEM); +- } ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; + return 0; + } + +@@ -229,7 +211,7 @@ + int i; + + /* read the rest of the bsi. read twice for dual mono mode. */ +- i = !(s->channel_mode); ++ i = !s->channel_mode; + do { + skip_bits(gbc, 5); // skip dialog normalization + if (get_bits1(gbc)) +@@ -254,7 +236,7 @@ + i = get_bits(gbc, 6); + do { + skip_bits(gbc, 8); +- } while(i--); ++ } while (i--); + } + + return 0; +@@ -268,12 +250,13 @@ + AC3HeaderInfo hdr; + int err; + +- err = ff_ac3_parse_header(&s->gbc, &hdr); +- if(err) ++ err = avpriv_ac3_parse_header(&s->gbc, &hdr); ++ if (err) + return err; + + /* get decoding parameters from header info */ + s->bit_alloc_params.sr_code = hdr.sr_code; ++ s->bitstream_mode = hdr.bitstream_mode; + s->channel_mode = hdr.channel_mode; + s->channel_layout = hdr.channel_layout; + s->lfe_on = hdr.lfe_on; +@@ -290,9 +273,9 @@ + s->frame_type = hdr.frame_type; + s->substreamid = hdr.substreamid; + +- if(s->lfe_on) { +- s->start_freq[s->lfe_ch] = 0; +- s->end_freq[s->lfe_ch] = 7; ++ if (s->lfe_on) { ++ s->start_freq[s->lfe_ch] = 0; ++ s->end_freq[s->lfe_ch] = 7; + s->num_exp_groups[s->lfe_ch] = 2; + s->channel_in_cpl[s->lfe_ch] = 0; + } +@@ -325,42 +308,43 @@ + static void set_downmix_coeffs(AC3DecodeContext *s) + { + int i; +- float cmix = gain_levels[center_levels[s->center_mix_level]]; +- float smix = gain_levels[surround_levels[s->surround_mix_level]]; ++ float cmix = gain_levels[s-> center_mix_level]; ++ float smix = gain_levels[s->surround_mix_level]; + float norm0, norm1; + +- for(i=0; ifbw_channels; i++) { ++ for (i = 0; i < s->fbw_channels; i++) { + s->downmix_coeffs[i][0] = gain_levels[ac3_default_coeffs[s->channel_mode][i][0]]; + s->downmix_coeffs[i][1] = gain_levels[ac3_default_coeffs[s->channel_mode][i][1]]; + } +- if(s->channel_mode > 1 && s->channel_mode & 1) { ++ if (s->channel_mode > 1 && s->channel_mode & 1) { + s->downmix_coeffs[1][0] = s->downmix_coeffs[1][1] = cmix; + } +- if(s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { ++ if (s->channel_mode == AC3_CHMODE_2F1R || s->channel_mode == AC3_CHMODE_3F1R) { + int nf = s->channel_mode - 2; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf][1] = smix * LEVEL_MINUS_3DB; + } +- if(s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { ++ if (s->channel_mode == AC3_CHMODE_2F2R || s->channel_mode == AC3_CHMODE_3F2R) { + int nf = s->channel_mode - 4; + s->downmix_coeffs[nf][0] = s->downmix_coeffs[nf+1][1] = smix; + } + + /* renormalize */ + norm0 = norm1 = 0.0; +- for(i=0; ifbw_channels; i++) { ++ for (i = 0; i < s->fbw_channels; i++) { + norm0 += s->downmix_coeffs[i][0]; + norm1 += s->downmix_coeffs[i][1]; + } + norm0 = 1.0f / norm0; + norm1 = 1.0f / norm1; +- for(i=0; ifbw_channels; i++) { ++ for (i = 0; i < s->fbw_channels; i++) { + s->downmix_coeffs[i][0] *= norm0; + s->downmix_coeffs[i][1] *= norm1; + } + +- if(s->output_mode == AC3_CHMODE_MONO) { +- for(i=0; ifbw_channels; i++) +- s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; ++ if (s->output_mode == AC3_CHMODE_MONO) { ++ for (i = 0; i < s->fbw_channels; i++) ++ s->downmix_coeffs[i][0] = (s->downmix_coeffs[i][0] + ++ s->downmix_coeffs[i][1]) * LEVEL_MINUS_3DB; + } + } + +@@ -377,7 +361,7 @@ + + /* unpack groups */ + group_size = exp_strategy + (exp_strategy == EXP_D45); +- for(grp=0,i=0; grp 24U) + return -1; + switch (group_size) { +- case 4: dexps[j++] = prevexp; +- dexps[j++] = prevexp; +- case 2: dexps[j++] = prevexp; +- case 1: dexps[j++] = prevexp; ++ case 4: dexps[j++] = prevexp; ++ dexps[j++] = prevexp; ++ case 2: dexps[j++] = prevexp; ++ case 1: dexps[j++] = prevexp; + } + } + return 0; +@@ -417,7 +401,8 @@ + if (s->channel_in_cpl[ch]) { + int cpl_coord = s->cpl_coords[ch][band] << 5; + for (bin = band_start; bin < band_end; bin++) { +- s->fixed_coeffs[ch][bin] = MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); ++ s->fixed_coeffs[ch][bin] = ++ MULH(s->fixed_coeffs[CPL_CH][bin] << 4, cpl_coord); + } + if (ch == 2 && s->phase_flags[band]) { + for (bin = band_start; bin < band_end; bin++) +@@ -448,73 +433,70 @@ + static void ac3_decode_transform_coeffs_ch(AC3DecodeContext *s, int ch_index, mant_groups *m) + { + int start_freq = s->start_freq[ch_index]; +- int end_freq = s->end_freq[ch_index]; +- uint8_t *baps = s->bap[ch_index]; +- int8_t *exps = s->dexps[ch_index]; +- int *coeffs = s->fixed_coeffs[ch_index]; +- int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; ++ int end_freq = s->end_freq[ch_index]; ++ uint8_t *baps = s->bap[ch_index]; ++ int8_t *exps = s->dexps[ch_index]; ++ int *coeffs = s->fixed_coeffs[ch_index]; ++ int dither = (ch_index == CPL_CH) || s->dither_flag[ch_index]; + GetBitContext *gbc = &s->gbc; + int freq; + +- for(freq = start_freq; freq < end_freq; freq++){ ++ for (freq = start_freq; freq < end_freq; freq++) { + int bap = baps[freq]; + int mantissa; +- switch(bap){ +- case 0: +- if (dither) +- mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; +- else +- mantissa = 0; +- break; +- case 1: +- if(m->b1){ +- m->b1--; +- mantissa = m->b1_mant[m->b1]; +- } +- else{ +- int bits = get_bits(gbc, 5); +- mantissa = b1_mantissas[bits][0]; +- m->b1_mant[1] = b1_mantissas[bits][1]; +- m->b1_mant[0] = b1_mantissas[bits][2]; +- m->b1 = 2; +- } +- break; +- case 2: +- if(m->b2){ +- m->b2--; +- mantissa = m->b2_mant[m->b2]; +- } +- else{ +- int bits = get_bits(gbc, 7); +- mantissa = b2_mantissas[bits][0]; +- m->b2_mant[1] = b2_mantissas[bits][1]; +- m->b2_mant[0] = b2_mantissas[bits][2]; +- m->b2 = 2; +- } +- break; +- case 3: +- mantissa = b3_mantissas[get_bits(gbc, 3)]; +- break; +- case 4: +- if(m->b4){ +- m->b4 = 0; +- mantissa = m->b4_mant; +- } +- else{ +- int bits = get_bits(gbc, 7); +- mantissa = b4_mantissas[bits][0]; +- m->b4_mant = b4_mantissas[bits][1]; +- m->b4 = 1; +- } +- break; +- case 5: +- mantissa = b5_mantissas[get_bits(gbc, 4)]; +- break; +- default: /* 6 to 15 */ +- mantissa = get_bits(gbc, quantization_tab[bap]); +- /* Shift mantissa and sign-extend it. */ +- mantissa = (mantissa << (32-quantization_tab[bap]))>>8; +- break; ++ switch (bap) { ++ case 0: ++ if (dither) ++ mantissa = (av_lfg_get(&s->dith_state) & 0x7FFFFF) - 0x400000; ++ else ++ mantissa = 0; ++ break; ++ case 1: ++ if (m->b1) { ++ m->b1--; ++ mantissa = m->b1_mant[m->b1]; ++ } else { ++ int bits = get_bits(gbc, 5); ++ mantissa = b1_mantissas[bits][0]; ++ m->b1_mant[1] = b1_mantissas[bits][1]; ++ m->b1_mant[0] = b1_mantissas[bits][2]; ++ m->b1 = 2; ++ } ++ break; ++ case 2: ++ if (m->b2) { ++ m->b2--; ++ mantissa = m->b2_mant[m->b2]; ++ } else { ++ int bits = get_bits(gbc, 7); ++ mantissa = b2_mantissas[bits][0]; ++ m->b2_mant[1] = b2_mantissas[bits][1]; ++ m->b2_mant[0] = b2_mantissas[bits][2]; ++ m->b2 = 2; ++ } ++ break; ++ case 3: ++ mantissa = b3_mantissas[get_bits(gbc, 3)]; ++ break; ++ case 4: ++ if (m->b4) { ++ m->b4 = 0; ++ mantissa = m->b4_mant; ++ } else { ++ int bits = get_bits(gbc, 7); ++ mantissa = b4_mantissas[bits][0]; ++ m->b4_mant = b4_mantissas[bits][1]; ++ m->b4 = 1; ++ } ++ break; ++ case 5: ++ mantissa = b5_mantissas[get_bits(gbc, 4)]; ++ break; ++ default: /* 6 to 15 */ ++ /* Shift mantissa and sign-extend it. */ ++ mantissa = get_sbits(gbc, quantization_tab[bap]); ++ mantissa <<= 24 - quantization_tab[bap]; ++ break; + } + coeffs[freq] = mantissa >> exps[freq]; + } +@@ -528,10 +510,10 @@ + static void remove_dithering(AC3DecodeContext *s) { + int ch, i; + +- for(ch=1; ch<=s->fbw_channels; ch++) { +- if(!s->dither_flag[ch] && s->channel_in_cpl[ch]) { +- for(i = s->start_freq[CPL_CH]; iend_freq[CPL_CH]; i++) { +- if(!s->bap[CPL_CH][i]) ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (!s->dither_flag[ch] && s->channel_in_cpl[ch]) { ++ for (i = s->start_freq[CPL_CH]; i < s->end_freq[CPL_CH]; i++) { ++ if (!s->bap[CPL_CH][i]) + s->fixed_coeffs[ch][i] = 0; + } + } +@@ -539,7 +521,7 @@ + } + + static void decode_transform_coeffs_ch(AC3DecodeContext *s, int blk, int ch, +- mant_groups *m) ++ mant_groups *m) + { + if (!s->channel_uses_aht[ch]) { + ac3_decode_transform_coeffs_ch(s, ch, m); +@@ -583,7 +565,7 @@ + } + do + s->fixed_coeffs[ch][end] = 0; +- while(++end < 256); ++ while (++end < 256); + } + + /* zero the dithered coefficients for appropriate channels */ +@@ -601,10 +583,10 @@ + + end = FFMIN(s->end_freq[1], s->end_freq[2]); + +- for(bnd=0; bndnum_rematrixing_bands; bnd++) { +- if(s->rematrixing_flags[bnd]) { +- bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd+1]); +- for(i=ff_ac3_rematrix_band_tab[bnd]; inum_rematrixing_bands; bnd++) { ++ if (s->rematrixing_flags[bnd]) { ++ bndend = FFMIN(end, ff_ac3_rematrix_band_tab[bnd + 1]); ++ for (i = ff_ac3_rematrix_band_tab[bnd]; i < bndend; i++) { + int tmp0 = s->fixed_coeffs[1][i]; + s->fixed_coeffs[1][i] += s->fixed_coeffs[2][i]; + s->fixed_coeffs[2][i] = tmp0 - s->fixed_coeffs[2][i]; +@@ -622,21 +604,23 @@ + { + int ch; + +- for (ch=1; ch<=channels; ch++) { ++ for (ch = 1; ch <= channels; ch++) { + if (s->block_switch[ch]) { + int i; +- float *x = s->tmp_output+128; +- for(i=0; i<128; i++) +- x[i] = s->transform_coeffs[ch][2*i]; +- ff_imdct_half(&s->imdct_256, s->tmp_output, x); +- s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, 128); +- for(i=0; i<128; i++) +- x[i] = s->transform_coeffs[ch][2*i+1]; +- ff_imdct_half(&s->imdct_256, s->delay[ch-1], x); ++ float *x = s->tmp_output + 128; ++ for (i = 0; i < 128; i++) ++ x[i] = s->transform_coeffs[ch][2 * i]; ++ s->imdct_256.imdct_half(&s->imdct_256, s->tmp_output, x); ++ s->dsp.vector_fmul_window(s->output[ch - 1], s->delay[ch - 1], ++ s->tmp_output, s->window, 128); ++ for (i = 0; i < 128; i++) ++ x[i] = s->transform_coeffs[ch][2 * i + 1]; ++ s->imdct_256.imdct_half(&s->imdct_256, s->delay[ch - 1], x); + } else { +- ff_imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); +- s->dsp.vector_fmul_window(s->output[ch-1], s->delay[ch-1], s->tmp_output, s->window, 128); +- memcpy(s->delay[ch-1], s->tmp_output+128, 128*sizeof(float)); ++ s->imdct_512.imdct_half(&s->imdct_512, s->tmp_output, s->transform_coeffs[ch]); ++ s->dsp.vector_fmul_window(s->output[ch - 1], s->delay[ch - 1], ++ s->tmp_output, s->window, 128); ++ memcpy(s->delay[ch - 1], s->tmp_output + 128, 128 * sizeof(float)); + } + } + } +@@ -644,24 +628,25 @@ + /** + * Downmix the output to mono or stereo. + */ +-void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], int out_ch, int in_ch, int len) ++void ff_ac3_downmix_c(float (*samples)[256], float (*matrix)[2], ++ int out_ch, int in_ch, int len) + { + int i, j; + float v0, v1; +- if(out_ch == 2) { +- for(i=0; idelay[0]); +- switch(s->channel_mode) { +- case AC3_CHMODE_DUALMONO: +- case AC3_CHMODE_STEREO: +- /* upmix mono to stereo */ +- memcpy(s->delay[1], s->delay[0], channel_data_size); +- break; +- case AC3_CHMODE_2F2R: +- memset(s->delay[3], 0, channel_data_size); +- case AC3_CHMODE_2F1R: +- memset(s->delay[2], 0, channel_data_size); +- break; +- case AC3_CHMODE_3F2R: +- memset(s->delay[4], 0, channel_data_size); +- case AC3_CHMODE_3F1R: +- memset(s->delay[3], 0, channel_data_size); +- case AC3_CHMODE_3F: +- memcpy(s->delay[2], s->delay[1], channel_data_size); +- memset(s->delay[1], 0, channel_data_size); +- break; ++ switch (s->channel_mode) { ++ case AC3_CHMODE_DUALMONO: ++ case AC3_CHMODE_STEREO: ++ /* upmix mono to stereo */ ++ memcpy(s->delay[1], s->delay[0], channel_data_size); ++ break; ++ case AC3_CHMODE_2F2R: ++ memset(s->delay[3], 0, channel_data_size); ++ case AC3_CHMODE_2F1R: ++ memset(s->delay[2], 0, channel_data_size); ++ break; ++ case AC3_CHMODE_3F2R: ++ memset(s->delay[4], 0, channel_data_size); ++ case AC3_CHMODE_3F1R: ++ memset(s->delay[3], 0, channel_data_size); ++ case AC3_CHMODE_3F: ++ memcpy(s->delay[2], s->delay[1], channel_data_size); ++ memset(s->delay[1], 0, channel_data_size); ++ break; + } + } + +@@ -745,7 +730,7 @@ + bnd_sz[0] = ecpl ? 6 : 12; + for (bnd = 0, subbnd = 1; subbnd < n_subbands; subbnd++) { + int subbnd_size = (ecpl && subbnd < 4) ? 6 : 12; +- if (band_struct[subbnd-1]) { ++ if (band_struct[subbnd - 1]) { + n_bands--; + bnd_sz[bnd] += subbnd_size; + } else { +@@ -782,7 +767,7 @@ + if (s->block_switch_syntax) { + for (ch = 1; ch <= fbw_channels; ch++) { + s->block_switch[ch] = get_bits1(gbc); +- if(ch > 1 && s->block_switch[ch] != s->block_switch[1]) ++ if (ch > 1 && s->block_switch[ch] != s->block_switch[1]) + different_transforms = 1; + } + } +@@ -795,15 +780,15 @@ + } + + /* dynamic range */ +- i = !(s->channel_mode); ++ i = !s->channel_mode; + do { +- if(get_bits1(gbc)) { +- s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)]-1.0) * +- s->avctx->drc_scale)+1.0; +- } else if(blk == 0) { ++ if (get_bits1(gbc)) { ++ s->dynamic_range[i] = ((dynamic_range_tab[get_bits(gbc, 8)] - 1.0) * ++ s->drc_scale) + 1.0; ++ } else if (blk == 0) { + s->dynamic_range[i] = 1.0f; + } +- } while(i--); ++ } while (i--); + + /* spectral extension strategy */ + if (s->eac3 && (!blk || get_bits1(gbc))) { +@@ -884,7 +869,8 @@ + bandsize = s->spx_band_sizes[bnd]; + nratio = ((float)((bin + (bandsize >> 1))) / s->spx_dst_end_freq) - spx_blend; + nratio = av_clipf(nratio, 0.0f, 1.0f); +- nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) to give unity variance ++ nblend = sqrtf(3.0f * nratio); // noise is scaled by sqrt(3) ++ // to give unity variance + sblend = sqrtf(1.0f - nratio); + bin += bandsize; + +@@ -894,7 +880,7 @@ + if (spx_coord_exp == 15) spx_coord_mant <<= 1; + else spx_coord_mant += 4; + spx_coord_mant <<= (25 - spx_coord_exp - master_spx_coord); +- spx_coord = spx_coord_mant * (1.0f/(1<<23)); ++ spx_coord = spx_coord_mant * (1.0f / (1 << 23)); + + /* multiply noise and signal blending factors by spx coordinate */ + s->spx_noise_blend [ch][bnd] = nblend * spx_coord; +@@ -967,8 +953,9 @@ + s->phase_flags_in_use = 0; + } + } else if (!s->eac3) { +- if(!blk) { +- av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must be present in block 0\n"); ++ if (!blk) { ++ av_log(s->avctx, AV_LOG_ERROR, "new coupling strategy must " ++ "be present in block 0\n"); + return -1; + } else { + s->cpl_in_use[blk] = s->cpl_in_use[blk-1]; +@@ -997,7 +984,8 @@ + s->cpl_coords[ch][bnd] >>= (cpl_coord_exp + master_cpl_coord); + } + } else if (!blk) { +- av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must be present in block 0\n"); ++ av_log(s->avctx, AV_LOG_ERROR, "new coupling coordinates must " ++ "be present in block 0\n"); + return -1; + } + } else { +@@ -1022,10 +1010,11 @@ + } else if (s->spx_in_use && s->spx_src_start_freq <= 61) { + s->num_rematrixing_bands--; + } +- for(bnd=0; bndnum_rematrixing_bands; bnd++) ++ for (bnd = 0; bnd < s->num_rematrixing_bands; bnd++) + s->rematrixing_flags[bnd] = get_bits1(gbc); + } else if (!blk) { +- av_log(s->avctx, AV_LOG_WARNING, "Warning: new rematrixing strategy not present in block 0\n"); ++ av_log(s->avctx, AV_LOG_WARNING, "Warning: " ++ "new rematrixing strategy not present in block 0\n"); + s->num_rematrixing_bands = 0; + } + } +@@ -1034,7 +1023,7 @@ + for (ch = !cpl_in_use; ch <= s->channels; ch++) { + if (!s->eac3) + s->exp_strategy[blk][ch] = get_bits(gbc, 2 - (ch == s->lfe_ch)); +- if(s->exp_strategy[blk][ch] != EXP_REUSE) ++ if (s->exp_strategy[blk][ch] != EXP_REUSE) + bit_alloc_stages[ch] = 3; + } + +@@ -1057,8 +1046,8 @@ + s->end_freq[ch] = bandwidth_code * 3 + 73; + } + group_size = 3 << (s->exp_strategy[blk][ch] - 1); +- s->num_exp_groups[ch] = (s->end_freq[ch]+group_size-4) / group_size; +- if(blk > 0 && s->end_freq[ch] != prev) ++ s->num_exp_groups[ch] = (s->end_freq[ch] + group_size-4) / group_size; ++ if (blk > 0 && s->end_freq[ch] != prev) + memset(bit_alloc_stages, 3, AC3_MAX_CHANNELS); + } + } +@@ -1077,7 +1066,7 @@ + av_log(s->avctx, AV_LOG_ERROR, "exponent out-of-range\n"); + return -1; + } +- if(ch != CPL_CH && ch != s->lfe_ch) ++ if (ch != CPL_CH && ch != s->lfe_ch) + skip_bits(gbc, 2); /* skip gainrng */ + } + } +@@ -1090,17 +1079,18 @@ + s->bit_alloc_params.slow_gain = ff_ac3_slow_gain_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.db_per_bit = ff_ac3_db_per_bit_tab[get_bits(gbc, 2)]; + s->bit_alloc_params.floor = ff_ac3_floor_tab[get_bits(gbc, 3)]; +- for(ch=!cpl_in_use; ch<=s->channels; ch++) ++ for (ch = !cpl_in_use; ch <= s->channels; ch++) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } else if (!blk) { +- av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must be present in block 0\n"); ++ av_log(s->avctx, AV_LOG_ERROR, "new bit allocation info must " ++ "be present in block 0\n"); + return -1; + } + } + + /* signal-to-noise ratio offsets and fast gains (signal-to-mask ratios) */ +- if(!s->eac3 || !blk){ +- if(s->snr_offset_strategy && get_bits1(gbc)) { ++ if (!s->eac3 || !blk) { ++ if (s->snr_offset_strategy && get_bits1(gbc)) { + int snr = 0; + int csnr; + csnr = (get_bits(gbc, 6) - 15) << 4; +@@ -1109,7 +1099,7 @@ + if (ch == i || s->snr_offset_strategy == 2) + snr = (csnr + get_bits(gbc, 4)) << 2; + /* run at least last bit allocation stage if snr offset changes */ +- if(blk && s->snr_offset[ch] != snr) { ++ if (blk && s->snr_offset[ch] != snr) { + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 1); + } + s->snr_offset[ch] = snr; +@@ -1119,7 +1109,7 @@ + int prev = s->fast_gain[ch]; + s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; + /* run last 2 bit allocation stages if fast gain changes */ +- if(blk && prev != s->fast_gain[ch]) ++ if (blk && prev != s->fast_gain[ch]) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } +@@ -1135,7 +1125,7 @@ + int prev = s->fast_gain[ch]; + s->fast_gain[ch] = ff_ac3_fast_gain_tab[get_bits(gbc, 3)]; + /* run last 2 bit allocation stages if fast gain changes */ +- if(blk && prev != s->fast_gain[ch]) ++ if (blk && prev != s->fast_gain[ch]) + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } else if (s->eac3 && !blk) { +@@ -1155,14 +1145,15 @@ + int sl = get_bits(gbc, 3); + /* run last 2 bit allocation stages for coupling channel if + coupling leak changes */ +- if(blk && (fl != s->bit_alloc_params.cpl_fast_leak || +- sl != s->bit_alloc_params.cpl_slow_leak)) { ++ if (blk && (fl != s->bit_alloc_params.cpl_fast_leak || ++ sl != s->bit_alloc_params.cpl_slow_leak)) { + bit_alloc_stages[CPL_CH] = FFMAX(bit_alloc_stages[CPL_CH], 2); + } + s->bit_alloc_params.cpl_fast_leak = fl; + s->bit_alloc_params.cpl_slow_leak = sl; + } else if (!s->eac3 && !blk) { +- av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must be present in block 0\n"); ++ av_log(s->avctx, AV_LOG_ERROR, "new coupling leak info must " ++ "be present in block 0\n"); + return -1; + } + s->first_cpl_leak = 0; +@@ -1182,48 +1173,48 @@ + /* channel delta offset, len and bit allocation */ + for (ch = !cpl_in_use; ch <= fbw_channels; ch++) { + if (s->dba_mode[ch] == DBA_NEW) { +- s->dba_nsegs[ch] = get_bits(gbc, 3); +- for (seg = 0; seg <= s->dba_nsegs[ch]; seg++) { ++ s->dba_nsegs[ch] = get_bits(gbc, 3) + 1; ++ for (seg = 0; seg < s->dba_nsegs[ch]; seg++) { + s->dba_offsets[ch][seg] = get_bits(gbc, 5); + s->dba_lengths[ch][seg] = get_bits(gbc, 4); +- s->dba_values[ch][seg] = get_bits(gbc, 3); ++ s->dba_values[ch][seg] = get_bits(gbc, 3); + } + /* run last 2 bit allocation stages if new dba values */ + bit_alloc_stages[ch] = FFMAX(bit_alloc_stages[ch], 2); + } + } +- } else if(blk == 0) { +- for(ch=0; ch<=s->channels; ch++) { ++ } else if (blk == 0) { ++ for (ch = 0; ch <= s->channels; ch++) { + s->dba_mode[ch] = DBA_NONE; + } + } + + /* Bit allocation */ +- for(ch=!cpl_in_use; ch<=s->channels; ch++) { +- if(bit_alloc_stages[ch] > 2) { ++ for (ch = !cpl_in_use; ch <= s->channels; ch++) { ++ if (bit_alloc_stages[ch] > 2) { + /* Exponent mapping into PSD and PSD integration */ + ff_ac3_bit_alloc_calc_psd(s->dexps[ch], + s->start_freq[ch], s->end_freq[ch], + s->psd[ch], s->band_psd[ch]); + } +- if(bit_alloc_stages[ch] > 1) { ++ if (bit_alloc_stages[ch] > 1) { + /* Compute excitation function, Compute masking curve, and + Apply delta bit allocation */ + if (ff_ac3_bit_alloc_calc_mask(&s->bit_alloc_params, s->band_psd[ch], +- s->start_freq[ch], s->end_freq[ch], +- s->fast_gain[ch], (ch == s->lfe_ch), +- s->dba_mode[ch], s->dba_nsegs[ch], ++ s->start_freq[ch], s->end_freq[ch], ++ s->fast_gain[ch], (ch == s->lfe_ch), ++ s->dba_mode[ch], s->dba_nsegs[ch], + s->dba_offsets[ch], s->dba_lengths[ch], +- s->dba_values[ch], s->mask[ch])) { ++ s->dba_values[ch], s->mask[ch])) { + av_log(s->avctx, AV_LOG_ERROR, "error in bit allocation\n"); + return -1; + } + } +- if(bit_alloc_stages[ch] > 0) { ++ if (bit_alloc_stages[ch] > 0) { + /* Compute bit allocation */ + const uint8_t *bap_tab = s->channel_uses_aht[ch] ? + ff_eac3_hebap_tab : ff_ac3_bap_tab; +- ff_ac3_bit_alloc_calc_bap(s->mask[ch], s->psd[ch], ++ s->ac3dsp.bit_alloc_calc_bap(s->mask[ch], s->psd[ch], + s->start_freq[ch], s->end_freq[ch], + s->snr_offset[ch], + s->bit_alloc_params.floor, +@@ -1234,7 +1225,7 @@ + /* unused dummy data */ + if (s->skip_syntax && get_bits1(gbc)) { + int skipl = get_bits(gbc, 9); +- while(skipl--) ++ while (skipl--) + skip_bits(gbc, 8); + } + +@@ -1245,18 +1236,19 @@ + /* TODO: generate enhanced coupling coordinates and uncouple */ + + /* recover coefficients if rematrixing is in use */ +- if(s->channel_mode == AC3_CHMODE_STEREO) ++ if (s->channel_mode == AC3_CHMODE_STEREO) + do_rematrixing(s); + + /* apply scaling to coefficients (headroom, dynrng) */ +- for(ch=1; ch<=s->channels; ch++) { ++ for (ch = 1; ch <= s->channels; ch++) { + float gain = s->mul_bias / 4194304.0f; +- if(s->channel_mode == AC3_CHMODE_DUALMONO) { +- gain *= s->dynamic_range[2-ch]; ++ if (s->channel_mode == AC3_CHMODE_DUALMONO) { ++ gain *= s->dynamic_range[2 - ch]; + } else { + gain *= s->dynamic_range[0]; + } +- s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], s->fixed_coeffs[ch], gain, 256); ++ s->fmt_conv.int32_to_float_fmul_scalar(s->transform_coeffs[ch], ++ s->fixed_coeffs[ch], gain, 256); + } + + /* apply spectral extension to high frequency bins */ +@@ -1270,27 +1262,30 @@ + downmix_output = s->channels != s->out_channels && + !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels); +- if(different_transforms) { ++ if (different_transforms) { + /* the delay samples have already been downmixed, so we upmix the delay + samples in order to reconstruct all channels before downmixing. */ +- if(s->downmixed) { ++ if (s->downmixed) { + s->downmixed = 0; + ac3_upmix_delay(s); + } + + do_imdct(s, s->channels); + +- if(downmix_output) { +- s->dsp.ac3_downmix(s->output, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); ++ if (downmix_output) { ++ s->dsp.ac3_downmix(s->output, s->downmix_coeffs, ++ s->out_channels, s->fbw_channels, 256); + } + } else { +- if(downmix_output) { +- s->dsp.ac3_downmix(s->transform_coeffs+1, s->downmix_coeffs, s->out_channels, s->fbw_channels, 256); ++ if (downmix_output) { ++ s->dsp.ac3_downmix(s->transform_coeffs + 1, s->downmix_coeffs, ++ s->out_channels, s->fbw_channels, 256); + } + +- if(downmix_output && !s->downmixed) { ++ if (downmix_output && !s->downmixed) { + s->downmixed = 1; +- s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, s->fbw_channels, 128); ++ s->dsp.ac3_downmix(s->delay, s->downmix_coeffs, s->out_channels, ++ s->fbw_channels, 128); + } + + do_imdct(s, s->out_channels); +@@ -1302,67 +1297,72 @@ + /** + * Decode a single AC-3 frame. + */ +-static int ac3_decode_frame(AVCodecContext * avctx, void *data, int *data_size, +- AVPacket *avpkt) ++static int ac3_decode_frame(AVCodecContext * avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AC3DecodeContext *s = avctx->priv_data; +- int16_t *out_samples = (int16_t *)data; +- int blk, ch, err; ++ float *out_samples_flt; ++ int16_t *out_samples_s16; ++ int blk, ch, err, ret; + const uint8_t *channel_map; + const float *output[AC3_MAX_CHANNELS]; + +- /* initialize the GetBitContext with the start of valid AC-3 Frame */ +- if (s->input_buffer) { +- /* copy input buffer to decoder context to avoid reading past the end +- of the buffer, which can be caused by a damaged input stream. */ ++ /* copy input buffer to decoder context to avoid reading past the end ++ of the buffer, which can be caused by a damaged input stream. */ ++ if (buf_size >= 2 && AV_RB16(buf) == 0x770B) { ++ // seems to be byte-swapped AC-3 ++ int cnt = FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE) >> 1; ++ s->dsp.bswap16_buf((uint16_t *)s->input_buffer, (const uint16_t *)buf, cnt); ++ } else + memcpy(s->input_buffer, buf, FFMIN(buf_size, AC3_FRAME_BUFFER_SIZE)); +- init_get_bits(&s->gbc, s->input_buffer, buf_size * 8); +- } else { +- init_get_bits(&s->gbc, buf, buf_size * 8); +- } ++ buf = s->input_buffer; ++ /* initialize the GetBitContext with the start of valid AC-3 Frame */ ++ init_get_bits(&s->gbc, buf, buf_size * 8); + + /* parse the syncinfo */ +- *data_size = 0; + err = parse_frame_header(s); + + if (err) { +- switch(err) { +- case AAC_AC3_PARSE_ERROR_SYNC: +- av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); +- return -1; +- case AAC_AC3_PARSE_ERROR_BSID: +- av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); +- break; +- case AAC_AC3_PARSE_ERROR_SAMPLE_RATE: +- av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); +- break; +- case AAC_AC3_PARSE_ERROR_FRAME_SIZE: +- av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); +- break; +- case AAC_AC3_PARSE_ERROR_FRAME_TYPE: +- /* skip frame if CRC is ok. otherwise use error concealment. */ +- /* TODO: add support for substreams and dependent frames */ +- if(s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { +- av_log(avctx, AV_LOG_ERROR, "unsupported frame type : skipping frame\n"); +- return s->frame_size; +- } else { +- av_log(avctx, AV_LOG_ERROR, "invalid frame type\n"); +- } +- break; +- default: +- av_log(avctx, AV_LOG_ERROR, "invalid header\n"); +- break; ++ switch (err) { ++ case AAC_AC3_PARSE_ERROR_SYNC: ++ av_log(avctx, AV_LOG_ERROR, "frame sync error\n"); ++ return -1; ++ case AAC_AC3_PARSE_ERROR_BSID: ++ av_log(avctx, AV_LOG_ERROR, "invalid bitstream id\n"); ++ break; ++ case AAC_AC3_PARSE_ERROR_SAMPLE_RATE: ++ av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); ++ break; ++ case AAC_AC3_PARSE_ERROR_FRAME_SIZE: ++ av_log(avctx, AV_LOG_ERROR, "invalid frame size\n"); ++ break; ++ case AAC_AC3_PARSE_ERROR_FRAME_TYPE: ++ /* skip frame if CRC is ok. otherwise use error concealment. */ ++ /* TODO: add support for substreams and dependent frames */ ++ if (s->frame_type == EAC3_FRAME_TYPE_DEPENDENT || s->substreamid) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported frame type : " ++ "skipping frame\n"); ++ *got_frame_ptr = 0; ++ return s->frame_size; ++ } else { ++ av_log(avctx, AV_LOG_ERROR, "invalid frame type\n"); ++ } ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "invalid header\n"); ++ break; + } + } else { + /* check that reported frame size fits in input buffer */ + if (s->frame_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); + err = AAC_AC3_PARSE_ERROR_FRAME_SIZE; +- } else if (avctx->error_recognition >= FF_ER_CAREFUL) { ++ } else if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) { + /* check for crc mismatch */ +- if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], s->frame_size-2)) { ++ if (av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, &buf[2], ++ s->frame_size - 2)) { + av_log(avctx, AV_LOG_ERROR, "frame CRC mismatch\n"); + err = AAC_AC3_PARSE_ERROR_CRC; + } +@@ -1372,32 +1372,49 @@ + /* if frame is ok, set audio parameters */ + if (!err) { + avctx->sample_rate = s->sample_rate; +- avctx->bit_rate = s->bit_rate; ++ avctx->bit_rate = s->bit_rate; + + /* channel config */ + s->out_channels = s->channels; +- s->output_mode = s->channel_mode; +- if(s->lfe_on) ++ s->output_mode = s->channel_mode; ++ if (s->lfe_on) + s->output_mode |= AC3_OUTPUT_LFEON; + if (avctx->request_channels > 0 && avctx->request_channels <= 2 && + avctx->request_channels < s->channels) { + s->out_channels = avctx->request_channels; + s->output_mode = avctx->request_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; +- s->channel_layout = ff_ac3_channel_layout_tab[s->output_mode]; ++ s->channel_layout = avpriv_ac3_channel_layout_tab[s->output_mode]; + } +- avctx->channels = s->out_channels; ++ avctx->channels = s->out_channels; + avctx->channel_layout = s->channel_layout; + ++ s->loro_center_mix_level = gain_levels[s-> center_mix_level]; ++ s->loro_surround_mix_level = gain_levels[s->surround_mix_level]; ++ s->ltrt_center_mix_level = LEVEL_MINUS_3DB; ++ s->ltrt_surround_mix_level = LEVEL_MINUS_3DB; + /* set downmixing coefficients if needed */ +- if(s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && ++ if (s->channels != s->out_channels && !((s->output_mode & AC3_OUTPUT_LFEON) && + s->fbw_channels == s->out_channels)) { + set_downmix_coeffs(s); + } + } else if (!s->out_channels) { + s->out_channels = avctx->channels; +- if(s->out_channels < s->channels) ++ if (s->out_channels < s->channels) + s->output_mode = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO; + } ++ /* set audio service type based on bitstream mode for AC-3 */ ++ avctx->audio_service_type = s->bitstream_mode; ++ if (s->bitstream_mode == 0x7 && s->channels > 1) ++ avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; ++ ++ /* get output buffer */ ++ s->frame.nb_samples = s->num_blocks * 256; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out_samples_flt = (float *)s->frame.data[0]; ++ out_samples_s16 = (int16_t *)s->frame.data[0]; + + /* decode the audio blocks */ + channel_map = ff_ac3_dec_channel_map[s->output_mode & ~AC3_OUTPUT_LFEON][s->lfe_on]; +@@ -1408,10 +1425,20 @@ + av_log(avctx, AV_LOG_ERROR, "error decoding the audio block\n"); + err = 1; + } +- s->fmt_conv.float_to_int16_interleave(out_samples, output, 256, s->out_channels); +- out_samples += 256 * s->out_channels; ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { ++ s->fmt_conv.float_interleave(out_samples_flt, output, 256, ++ s->out_channels); ++ out_samples_flt += 256 * s->out_channels; ++ } else { ++ s->fmt_conv.float_to_int16_interleave(out_samples_s16, output, 256, ++ s->out_channels); ++ out_samples_s16 += 256 * s->out_channels; ++ } + } +- *data_size = s->num_blocks * 256 * avctx->channels * sizeof (int16_t); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return FFMIN(buf_size, s->frame_size); + } + +@@ -1424,31 +1451,67 @@ + ff_mdct_end(&s->imdct_512); + ff_mdct_end(&s->imdct_256); + +- av_freep(&s->input_buffer); +- + return 0; + } + ++#define OFFSET(x) offsetof(AC3DecodeContext, x) ++#define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM) ++static const AVOption options[] = { ++ { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {1.0}, 0.0, 1.0, PAR }, ++ ++{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, 2, 0, "dmix_mode"}, ++{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, ++{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, ++{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, ++{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0}, ++ ++ { NULL}, ++}; ++ ++static const AVClass ac3_decoder_class = { ++ .class_name = "AC3 decoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_ac3_decoder = { +- .name = "ac3", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_AC3, ++ .name = "ac3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AC3, + .priv_data_size = sizeof (AC3DecodeContext), +- .init = ac3_decode_init, +- .close = ac3_decode_end, +- .decode = ac3_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), ++ .init = ac3_decode_init, ++ .close = ac3_decode_end, ++ .decode = ac3_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, ++ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, ++ .priv_class = &ac3_decoder_class, + }; + + #if CONFIG_EAC3_DECODER ++static const AVClass eac3_decoder_class = { ++ .class_name = "E-AC3 decoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_eac3_decoder = { +- .name = "eac3", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_EAC3, ++ .name = "eac3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_EAC3, + .priv_data_size = sizeof (AC3DecodeContext), +- .init = ac3_decode_init, +- .close = ac3_decode_end, +- .decode = ac3_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), ++ .init = ac3_decode_init, ++ .close = ac3_decode_end, ++ .decode = ac3_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"), ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, ++ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, ++ .priv_class = &eac3_decoder_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec_data.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec_data.c 2012-05-14 14:08:53.325319675 +0200 +@@ -54,12 +54,6 @@ + }; + + /** +- * Table E2.16 Default Coupling Banding Structure +- */ +-const uint8_t ff_eac3_default_cpl_band_struct[18] = +-{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 }; +- +-/** + * Table E2.15 Default Spectral Extension Banding Structure + */ + const uint8_t ff_eac3_default_spx_band_struct[17] = +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec_data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec_data.h 2012-05-14 14:08:53.326319695 +0200 +@@ -27,7 +27,6 @@ + extern const uint8_t ff_ac3_ungroup_3_in_5_bits_tab[32][3]; + + extern const uint8_t ff_eac3_hebap_tab[64]; +-extern const uint8_t ff_eac3_default_cpl_band_struct[18]; + extern const uint8_t ff_eac3_default_spx_band_struct[17]; + + #endif /* AVCODEC_AC3DEC_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dec.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dec.h 2012-05-14 14:08:53.325319675 +0200 +@@ -52,26 +52,26 @@ + + #include "libavutil/lfg.h" + #include "ac3.h" ++#include "ac3dsp.h" + #include "get_bits.h" + #include "dsputil.h" + #include "fft.h" + #include "fmtconvert.h" + +-/* override ac3.h to include coupling channel */ +-#undef AC3_MAX_CHANNELS +-#define AC3_MAX_CHANNELS 7 +-#define CPL_CH 0 +- + #define AC3_OUTPUT_LFEON 8 + + #define SPX_MAX_BANDS 17 + ++/** Large enough for maximum possible frame size when the specification limit is ignored */ ++#define AC3_FRAME_BUFFER_SIZE 32768 ++ + typedef struct { ++ AVClass *class; ///< class for AVOptions + AVCodecContext *avctx; ///< parent context ++ AVFrame frame; ///< AVFrame for decoded output + GetBitContext gbc; ///< bitstream reader +- uint8_t *input_buffer; ///< temp buffer to prevent overread + +-///@defgroup bsi bit stream information ++///@name Bit stream information + ///@{ + int frame_type; ///< frame type (strmtyp) + int substreamid; ///< substream identification +@@ -79,6 +79,7 @@ + int bit_rate; ///< stream bit rate, in bits-per-second + int sample_rate; ///< sample frequency, in Hz + int num_blocks; ///< number of audio blocks ++ int bitstream_mode; ///< bitstream mode (bsmod) + int channel_mode; ///< channel mode (acmod) + int channel_layout; ///< channel layout + int lfe_on; ///< lfe channel in use +@@ -88,7 +89,13 @@ + int eac3; ///< indicates if current frame is E-AC-3 + ///@} + +-///@defgroup audfrm frame syntax parameters ++ int preferred_stereo_downmix; ++ float ltrt_center_mix_level; ++ float ltrt_surround_mix_level; ++ float loro_center_mix_level; ++ float loro_surround_mix_level; ++ ++///@name Frame syntax parameters + int snr_offset_strategy; ///< SNR offset strategy (snroffststr) + int block_switch_syntax; ///< block switch syntax enabled (blkswe) + int dither_flag_syntax; ///< dither flag syntax enabled (dithflage) +@@ -98,20 +105,20 @@ + int skip_syntax; ///< skip field syntax enabled (skipflde) + ///@} + +-///@defgroup cpl standard coupling ++///@name Standard coupling + int cpl_in_use[AC3_MAX_BLOCKS]; ///< coupling in use (cplinu) + int cpl_strategy_exists[AC3_MAX_BLOCKS];///< coupling strategy exists (cplstre) + int channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl) + int phase_flags_in_use; ///< phase flags in use (phsflginu) +- int phase_flags[18]; ///< phase flags (phsflg) ++ int phase_flags[AC3_MAX_CPL_BANDS]; ///< phase flags (phsflg) + int num_cpl_bands; ///< number of coupling bands (ncplbnd) +- uint8_t cpl_band_sizes[18]; ///< number of coeffs in each coupling band ++ uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]; ///< number of coeffs in each coupling band + int firstchincpl; ///< first channel in coupling + int first_cpl_coords[AC3_MAX_CHANNELS]; ///< first coupling coordinates states (firstcplcos) +- int cpl_coords[AC3_MAX_CHANNELS][18]; ///< coupling coordinates (cplco) ++ int cpl_coords[AC3_MAX_CHANNELS][AC3_MAX_CPL_BANDS]; ///< coupling coordinates (cplco) + ///@} + +-///@defgroup spx spectral extension ++///@name Spectral extension + ///@{ + int spx_in_use; ///< spectral extension in use (spxinu) + uint8_t channel_uses_spx[AC3_MAX_CHANNELS]; ///< channel uses spectral extension (chinspx) +@@ -127,12 +134,12 @@ + float spx_signal_blend[AC3_MAX_CHANNELS][SPX_MAX_BANDS];///< spx signal blending factor (sblendfact) + ///@} + +-///@defgroup aht adaptive hybrid transform ++///@name Adaptive hybrid transform + int channel_uses_aht[AC3_MAX_CHANNELS]; ///< channel AHT in use (chahtinu) + int pre_mantissa[AC3_MAX_CHANNELS][AC3_MAX_COEFS][AC3_MAX_BLOCKS]; ///< pre-IDCT mantissas + ///@} + +-///@defgroup channel channel ++///@name Channel + int fbw_channels; ///< number of full-bandwidth channels + int channels; ///< number of total channels + int lfe_ch; ///< index of LFE channel +@@ -142,27 +149,28 @@ + int out_channels; ///< number of output channels + ///@} + +-///@defgroup dynrng dynamic range ++///@name Dynamic range + float dynamic_range[2]; ///< dynamic range ++ float drc_scale; ///< percentage of dynamic range compression to be applied + ///@} + +-///@defgroup bandwidth bandwidth ++///@name Bandwidth + int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin (strtmant) + int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) + ///@} + +-///@defgroup rematrixing rematrixing ++///@name Rematrixing + int num_rematrixing_bands; ///< number of rematrixing bands (nrematbnd) + int rematrixing_flags[4]; ///< rematrixing flags (rematflg) + ///@} + +-///@defgroup exponents exponents ++///@name Exponents + int num_exp_groups[AC3_MAX_CHANNELS]; ///< Number of exponent groups (nexpgrp) + int8_t dexps[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< decoded exponents + int exp_strategy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS]; ///< exponent strategies (expstr) + ///@} + +-///@defgroup bitalloc bit allocation ++///@name Bit allocation + AC3BitAllocParameters bit_alloc_params; ///< bit allocation parameters + int first_cpl_leak; ///< first coupling leak state (firstcplleak) + int snr_offset[AC3_MAX_CHANNELS]; ///< signal-to-noise ratio offsets (snroffst) +@@ -178,30 +186,32 @@ + uint8_t dba_values[AC3_MAX_CHANNELS][8]; ///< delta values for each segment + ///@} + +-///@defgroup dithering zero-mantissa dithering ++///@name Zero-mantissa dithering + int dither_flag[AC3_MAX_CHANNELS]; ///< dither flags (dithflg) + AVLFG dith_state; ///< for dither generation + ///@} + +-///@defgroup imdct IMDCT ++///@name IMDCT + int block_switch[AC3_MAX_CHANNELS]; ///< block switch flags (blksw) + FFTContext imdct_512; ///< for 512 sample IMDCT + FFTContext imdct_256; ///< for 256 sample IMDCT + ///@} + +-///@defgroup opt optimization ++///@name Optimization + DSPContext dsp; ///< for optimization ++ AC3DSPContext ac3dsp; + FmtConvertContext fmt_conv; ///< optimized conversion functions + float mul_bias; ///< scaling for float_to_int16 conversion + ///@} + +-///@defgroup arrays aligned arrays +- DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///> fixed-point transform coefficients +- DECLARE_ALIGNED(16, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients +- DECLARE_ALIGNED(16, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block +- DECLARE_ALIGNED(16, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients +- DECLARE_ALIGNED(16, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing +- DECLARE_ALIGNED(16, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing ++///@name Aligned arrays ++ DECLARE_ALIGNED(16, int, fixed_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< fixed-point transform coefficients ++ DECLARE_ALIGNED(32, float, transform_coeffs)[AC3_MAX_CHANNELS][AC3_MAX_COEFS]; ///< transform coefficients ++ DECLARE_ALIGNED(32, float, delay)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< delay - added to the next block ++ DECLARE_ALIGNED(32, float, window)[AC3_BLOCK_SIZE]; ///< window coefficients ++ DECLARE_ALIGNED(32, float, tmp_output)[AC3_BLOCK_SIZE]; ///< temporary storage for output before windowing ++ DECLARE_ALIGNED(32, float, output)[AC3_MAX_CHANNELS][AC3_BLOCK_SIZE]; ///< output after imdct transform and windowing ++ DECLARE_ALIGNED(32, uint8_t, input_buffer)[AC3_FRAME_BUFFER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; ///< temp buffer to prevent overread + ///@} + } AC3DecodeContext; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dsp.c 2012-05-14 14:08:53.327319715 +0200 +@@ -0,0 +1,235 @@ ++/* ++ * AC-3 DSP utils ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/avassert.h" ++#include "avcodec.h" ++#include "ac3.h" ++#include "ac3dsp.h" ++#include "mathops.h" ++ ++static void ac3_exponent_min_c(uint8_t *exp, int num_reuse_blocks, int nb_coefs) ++{ ++ int blk, i; ++ ++ if (!num_reuse_blocks) ++ return; ++ ++ for (i = 0; i < nb_coefs; i++) { ++ uint8_t min_exp = *exp; ++ uint8_t *exp1 = exp + 256; ++ for (blk = 0; blk < num_reuse_blocks; blk++) { ++ uint8_t next_exp = *exp1; ++ if (next_exp < min_exp) ++ min_exp = next_exp; ++ exp1 += 256; ++ } ++ *exp++ = min_exp; ++ } ++} ++ ++static int ac3_max_msb_abs_int16_c(const int16_t *src, int len) ++{ ++ int i, v = 0; ++ for (i = 0; i < len; i++) ++ v |= abs(src[i]); ++ return v; ++} ++ ++static void ac3_lshift_int16_c(int16_t *src, unsigned int len, ++ unsigned int shift) ++{ ++ uint32_t *src32 = (uint32_t *)src; ++ const uint32_t mask = ~(((1 << shift) - 1) << 16); ++ int i; ++ len >>= 1; ++ for (i = 0; i < len; i += 8) { ++ src32[i ] = (src32[i ] << shift) & mask; ++ src32[i+1] = (src32[i+1] << shift) & mask; ++ src32[i+2] = (src32[i+2] << shift) & mask; ++ src32[i+3] = (src32[i+3] << shift) & mask; ++ src32[i+4] = (src32[i+4] << shift) & mask; ++ src32[i+5] = (src32[i+5] << shift) & mask; ++ src32[i+6] = (src32[i+6] << shift) & mask; ++ src32[i+7] = (src32[i+7] << shift) & mask; ++ } ++} ++ ++static void ac3_rshift_int32_c(int32_t *src, unsigned int len, ++ unsigned int shift) ++{ ++ do { ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ *src++ >>= shift; ++ len -= 8; ++ } while (len > 0); ++} ++ ++static void float_to_fixed24_c(int32_t *dst, const float *src, unsigned int len) ++{ ++ const float scale = 1 << 24; ++ do { ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ *dst++ = lrintf(*src++ * scale); ++ len -= 8; ++ } while (len > 0); ++} ++ ++static void ac3_bit_alloc_calc_bap_c(int16_t *mask, int16_t *psd, ++ int start, int end, ++ int snr_offset, int floor, ++ const uint8_t *bap_tab, uint8_t *bap) ++{ ++ int bin, band, band_end; ++ ++ /* special case, if snr offset is -960, set all bap's to zero */ ++ if (snr_offset == -960) { ++ memset(bap, 0, AC3_MAX_COEFS); ++ return; ++ } ++ ++ bin = start; ++ band = ff_ac3_bin_to_band_tab[start]; ++ do { ++ int m = (FFMAX(mask[band] - snr_offset - floor, 0) & 0x1FE0) + floor; ++ band_end = ff_ac3_band_start_tab[++band]; ++ band_end = FFMIN(band_end, end); ++ ++ for (; bin < band_end; bin++) { ++ int address = av_clip((psd[bin] - m) >> 5, 0, 63); ++ bap[bin] = bap_tab[address]; ++ } ++ } while (end > band_end); ++} ++ ++static void ac3_update_bap_counts_c(uint16_t mant_cnt[16], uint8_t *bap, ++ int len) ++{ ++ while (len-- > 0) ++ mant_cnt[bap[len]]++; ++} ++ ++DECLARE_ALIGNED(16, const uint16_t, ff_ac3_bap_bits)[16] = { ++ 0, 0, 0, 3, 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 16 ++}; ++ ++static int ac3_compute_mantissa_size_c(uint16_t mant_cnt[6][16]) ++{ ++ int blk, bap; ++ int bits = 0; ++ ++ for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ // bap=1 : 3 mantissas in 5 bits ++ bits += (mant_cnt[blk][1] / 3) * 5; ++ // bap=2 : 3 mantissas in 7 bits ++ // bap=4 : 2 mantissas in 7 bits ++ bits += ((mant_cnt[blk][2] / 3) + (mant_cnt[blk][4] >> 1)) * 7; ++ // bap=3 : 1 mantissa in 3 bits ++ bits += mant_cnt[blk][3] * 3; ++ // bap=5 to 15 : get bits per mantissa from table ++ for (bap = 5; bap < 16; bap++) ++ bits += mant_cnt[blk][bap] * ff_ac3_bap_bits[bap]; ++ } ++ return bits; ++} ++ ++static void ac3_extract_exponents_c(uint8_t *exp, int32_t *coef, int nb_coefs) ++{ ++ int i; ++ ++ for (i = 0; i < nb_coefs; i++) { ++ int v = abs(coef[i]); ++ exp[i] = v ? 23 - av_log2(v) : 24; ++ } ++} ++ ++static void ac3_sum_square_butterfly_int32_c(int64_t sum[4], ++ const int32_t *coef0, ++ const int32_t *coef1, ++ int len) ++{ ++ int i; ++ ++ sum[0] = sum[1] = sum[2] = sum[3] = 0; ++ ++ for (i = 0; i < len; i++) { ++ int lt = coef0[i]; ++ int rt = coef1[i]; ++ int md = lt + rt; ++ int sd = lt - rt; ++ MAC64(sum[0], lt, lt); ++ MAC64(sum[1], rt, rt); ++ MAC64(sum[2], md, md); ++ MAC64(sum[3], sd, sd); ++ } ++} ++ ++static void ac3_sum_square_butterfly_float_c(float sum[4], ++ const float *coef0, ++ const float *coef1, ++ int len) ++{ ++ int i; ++ ++ sum[0] = sum[1] = sum[2] = sum[3] = 0; ++ ++ for (i = 0; i < len; i++) { ++ float lt = coef0[i]; ++ float rt = coef1[i]; ++ float md = lt + rt; ++ float sd = lt - rt; ++ sum[0] += lt * lt; ++ sum[1] += rt * rt; ++ sum[2] += md * md; ++ sum[3] += sd * sd; ++ } ++} ++ ++av_cold void ff_ac3dsp_init(AC3DSPContext *c, int bit_exact) ++{ ++ c->ac3_exponent_min = ac3_exponent_min_c; ++ c->ac3_max_msb_abs_int16 = ac3_max_msb_abs_int16_c; ++ c->ac3_lshift_int16 = ac3_lshift_int16_c; ++ c->ac3_rshift_int32 = ac3_rshift_int32_c; ++ c->float_to_fixed24 = float_to_fixed24_c; ++ c->bit_alloc_calc_bap = ac3_bit_alloc_calc_bap_c; ++ c->update_bap_counts = ac3_update_bap_counts_c; ++ c->compute_mantissa_size = ac3_compute_mantissa_size_c; ++ c->extract_exponents = ac3_extract_exponents_c; ++ c->sum_square_butterfly_int32 = ac3_sum_square_butterfly_int32_c; ++ c->sum_square_butterfly_float = ac3_sum_square_butterfly_float_c; ++ ++ if (ARCH_ARM) ++ ff_ac3dsp_init_arm(c, bit_exact); ++ if (HAVE_MMX) ++ ff_ac3dsp_init_x86(c, bit_exact); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3dsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3dsp.h 2012-05-14 14:08:53.328319735 +0200 +@@ -0,0 +1,140 @@ ++/* ++ * AC-3 DSP utils ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_AC3DSP_H ++#define AVCODEC_AC3DSP_H ++ ++#include ++ ++/** ++ * Number of mantissa bits written for each bap value. ++ * bap values with fractional bits are set to 0 and are calculated separately. ++ */ ++extern const uint16_t ff_ac3_bap_bits[16]; ++ ++typedef struct AC3DSPContext { ++ /** ++ * Set each encoded exponent in a block to the minimum of itself and the ++ * exponents in the same frequency bin of up to 5 following blocks. ++ * @param exp pointer to the start of the current block of exponents. ++ * constraints: align 16 ++ * @param num_reuse_blocks number of blocks that will reuse exponents from the current block. ++ * constraints: range 0 to 5 ++ * @param nb_coefs number of frequency coefficients. ++ */ ++ void (*ac3_exponent_min)(uint8_t *exp, int num_reuse_blocks, int nb_coefs); ++ ++ /** ++ * Calculate the maximum MSB of the absolute value of each element in an ++ * array of int16_t. ++ * @param src input array ++ * constraints: align 16. values must be in range [-32767,32767] ++ * @param len number of values in the array ++ * constraints: multiple of 16 greater than 0 ++ * @return a value with the same MSB as max(abs(src[])) ++ */ ++ int (*ac3_max_msb_abs_int16)(const int16_t *src, int len); ++ ++ /** ++ * Left-shift each value in an array of int16_t by a specified amount. ++ * @param src input array ++ * constraints: align 16 ++ * @param len number of values in the array ++ * constraints: multiple of 32 greater than 0 ++ * @param shift left shift amount ++ * constraints: range [0,15] ++ */ ++ void (*ac3_lshift_int16)(int16_t *src, unsigned int len, unsigned int shift); ++ ++ /** ++ * Right-shift each value in an array of int32_t by a specified amount. ++ * @param src input array ++ * constraints: align 16 ++ * @param len number of values in the array ++ * constraints: multiple of 16 greater than 0 ++ * @param shift right shift amount ++ * constraints: range [0,31] ++ */ ++ void (*ac3_rshift_int32)(int32_t *src, unsigned int len, unsigned int shift); ++ ++ /** ++ * Convert an array of float in range [-1.0,1.0] to int32_t with range ++ * [-(1<<24),(1<<24)] ++ * ++ * @param dst destination array of int32_t. ++ * constraints: 16-byte aligned ++ * @param src source array of float. ++ * constraints: 16-byte aligned ++ * @param len number of elements to convert. ++ * constraints: multiple of 32 greater than zero ++ */ ++ void (*float_to_fixed24)(int32_t *dst, const float *src, unsigned int len); ++ ++ /** ++ * Calculate bit allocation pointers. ++ * The SNR is the difference between the masking curve and the signal. AC-3 ++ * uses this value for each frequency bin to allocate bits. The snroffset ++ * parameter is a global adjustment to the SNR for all bins. ++ * ++ * @param[in] mask masking curve ++ * @param[in] psd signal power for each frequency bin ++ * @param[in] start starting bin location ++ * @param[in] end ending bin location ++ * @param[in] snr_offset SNR adjustment ++ * @param[in] floor noise floor ++ * @param[in] bap_tab look-up table for bit allocation pointers ++ * @param[out] bap bit allocation pointers ++ */ ++ void (*bit_alloc_calc_bap)(int16_t *mask, int16_t *psd, int start, int end, ++ int snr_offset, int floor, ++ const uint8_t *bap_tab, uint8_t *bap); ++ ++ /** ++ * Update bap counts using the supplied array of bap. ++ * ++ * @param[out] mant_cnt bap counts for 1 block ++ * @param[in] bap array of bap, pointing to start coef bin ++ * @param[in] len number of elements to process ++ */ ++ void (*update_bap_counts)(uint16_t mant_cnt[16], uint8_t *bap, int len); ++ ++ /** ++ * Calculate the number of bits needed to encode a set of mantissas. ++ * ++ * @param[in] mant_cnt bap counts for all blocks ++ * @return mantissa bit count ++ */ ++ int (*compute_mantissa_size)(uint16_t mant_cnt[6][16]); ++ ++ void (*extract_exponents)(uint8_t *exp, int32_t *coef, int nb_coefs); ++ ++ void (*sum_square_butterfly_int32)(int64_t sum[4], const int32_t *coef0, ++ const int32_t *coef1, int len); ++ ++ void (*sum_square_butterfly_float)(float sum[4], const float *coef0, ++ const float *coef1, int len); ++} AC3DSPContext; ++ ++void ff_ac3dsp_init (AC3DSPContext *c, int bit_exact); ++void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact); ++void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact); ++ ++#endif /* AVCODEC_AC3DSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc.c 2012-05-14 14:08:53.337319916 +0200 +@@ -26,160 +26,58 @@ + * The simplest AC-3 encoder. + */ + +-//#define DEBUG ++//#define ASSERT_LEVEL 2 + +-#include "libavcore/audioconvert.h" ++#include ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/avassert.h" ++#include "libavutil/avstring.h" + #include "libavutil/crc.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "put_bits.h" + #include "dsputil.h" ++#include "ac3dsp.h" + #include "ac3.h" + #include "audioconvert.h" ++#include "fft.h" ++#include "ac3enc.h" ++#include "eac3enc.h" + +- +-#ifndef CONFIG_AC3ENC_FLOAT +-#define CONFIG_AC3ENC_FLOAT 0 +-#endif +- +- +-/** Maximum number of exponent groups. +1 for separate DC exponent. */ +-#define AC3_MAX_EXP_GROUPS 85 +- +-/* stereo rematrixing algorithms */ +-#define AC3_REMATRIXING_IS_STATIC 0x1 +-#define AC3_REMATRIXING_SUMS 0 +-#define AC3_REMATRIXING_NONE 1 +-#define AC3_REMATRIXING_ALWAYS 3 +- +-/** Scale a float value by 2^bits and convert to an integer. */ +-#define SCALE_FLOAT(a, bits) lrintf((a) * (float)(1 << (bits))) +- +- +-#if CONFIG_AC3ENC_FLOAT +-#include "ac3enc_float.h" +-#else +-#include "ac3enc_fixed.h" +-#endif +- +- +-/** +- * Data for a single audio block. +- */ +-typedef struct AC3Block { +- uint8_t **bap; ///< bit allocation pointers (bap) +- CoefType **mdct_coef; ///< MDCT coefficients +- int32_t **fixed_coef; ///< fixed-point MDCT coefficients +- uint8_t **exp; ///< original exponents +- uint8_t **grouped_exp; ///< grouped exponents +- int16_t **psd; ///< psd per frequency bin +- int16_t **band_psd; ///< psd per critical band +- int16_t **mask; ///< masking curve +- uint16_t **qmant; ///< quantized mantissas +- int8_t exp_shift[AC3_MAX_CHANNELS]; ///< exponent shift values +- uint8_t new_rematrixing_strategy; ///< send new rematrixing flags in this block +- uint8_t rematrixing_flags[4]; ///< rematrixing flags +-} AC3Block; +- +-/** +- * AC-3 encoder private context. +- */ +-typedef struct AC3EncodeContext { +- PutBitContext pb; ///< bitstream writer context +- DSPContext dsp; +- AC3MDCTContext mdct; ///< MDCT context +- +- AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info +- +- int bitstream_id; ///< bitstream id (bsid) +- int bitstream_mode; ///< bitstream mode (bsmod) +- +- int bit_rate; ///< target bit rate, in bits-per-second +- int sample_rate; ///< sampling frequency, in Hz +- +- int frame_size_min; ///< minimum frame size in case rounding is necessary +- int frame_size; ///< current frame size in bytes +- int frame_size_code; ///< frame size code (frmsizecod) +- uint16_t crc_inv[2]; +- int bits_written; ///< bit count (used to avg. bitrate) +- int samples_written; ///< sample count (used to avg. bitrate) +- +- int fbw_channels; ///< number of full-bandwidth channels (nfchans) +- int channels; ///< total number of channels (nchans) +- int lfe_on; ///< indicates if there is an LFE channel (lfeon) +- int lfe_channel; ///< channel index of the LFE channel +- int channel_mode; ///< channel mode (acmod) +- const uint8_t *channel_map; ///< channel map used to reorder channels +- +- int cutoff; ///< user-specified cutoff frequency, in Hz +- int bandwidth_code[AC3_MAX_CHANNELS]; ///< bandwidth code (0 to 60) (chbwcod) +- int nb_coefs[AC3_MAX_CHANNELS]; +- +- int rematrixing; ///< determines how rematrixing strategy is calculated +- +- /* bitrate allocation control */ +- int slow_gain_code; ///< slow gain code (sgaincod) +- int slow_decay_code; ///< slow decay code (sdcycod) +- int fast_decay_code; ///< fast decay code (fdcycod) +- int db_per_bit_code; ///< dB/bit code (dbpbcod) +- int floor_code; ///< floor code (floorcod) +- AC3BitAllocParameters bit_alloc; ///< bit allocation parameters +- int coarse_snr_offset; ///< coarse SNR offsets (csnroffst) +- int fast_gain_code[AC3_MAX_CHANNELS]; ///< fast gain codes (signal-to-mask ratio) (fgaincod) +- int fine_snr_offset[AC3_MAX_CHANNELS]; ///< fine SNR offsets (fsnroffst) +- int frame_bits_fixed; ///< number of non-coefficient bits for fixed parameters +- int frame_bits; ///< all frame bits except exponents and mantissas +- int exponent_bits; ///< number of bits used for exponents +- +- /* mantissa encoding */ ++typedef struct AC3Mant { ++ int16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4 + int mant1_cnt, mant2_cnt, mant4_cnt; ///< mantissa counts for bap=1,2,4 +- uint16_t *qmant1_ptr, *qmant2_ptr, *qmant4_ptr; ///< mantissa pointers for bap=1,2,4 +- +- SampleType **planar_samples; +- uint8_t *bap_buffer; +- uint8_t *bap1_buffer; +- CoefType *mdct_coef_buffer; +- int32_t *fixed_coef_buffer; +- uint8_t *exp_buffer; +- uint8_t *grouped_exp_buffer; +- int16_t *psd_buffer; +- int16_t *band_psd_buffer; +- int16_t *mask_buffer; +- uint16_t *qmant_buffer; +- +- uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies +- +- DECLARE_ALIGNED(16, SampleType, windowed_samples)[AC3_WINDOW_SIZE]; +-} AC3EncodeContext; ++} AC3Mant; + ++#define CMIXLEV_NUM_OPTIONS 3 ++static const float cmixlev_options[CMIXLEV_NUM_OPTIONS] = { ++ LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, LEVEL_MINUS_6DB ++}; + +-/* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */ +- +-static av_cold void mdct_end(AC3MDCTContext *mdct); +- +-static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, +- int nbits); +- +-static void mdct512(AC3MDCTContext *mdct, CoefType *out, SampleType *in); +- +-static void apply_window(DSPContext *dsp, SampleType *output, const SampleType *input, +- const SampleType *window, int n); +- +-static int normalize_samples(AC3EncodeContext *s); ++#define SURMIXLEV_NUM_OPTIONS 3 ++static const float surmixlev_options[SURMIXLEV_NUM_OPTIONS] = { ++ LEVEL_MINUS_3DB, LEVEL_MINUS_6DB, LEVEL_ZERO ++}; + +-static void scale_coefficients(AC3EncodeContext *s); ++#define EXTMIXLEV_NUM_OPTIONS 8 ++static const float extmixlev_options[EXTMIXLEV_NUM_OPTIONS] = { ++ LEVEL_PLUS_3DB, LEVEL_PLUS_1POINT5DB, LEVEL_ONE, LEVEL_MINUS_4POINT5DB, ++ LEVEL_MINUS_3DB, LEVEL_MINUS_4POINT5DB, LEVEL_MINUS_6DB, LEVEL_ZERO ++}; + + + /** + * LUT for number of exponent groups. +- * exponent_group_tab[exponent strategy-1][number of coefficients] ++ * exponent_group_tab[coupling][exponent strategy-1][number of coefficients] + */ +-static uint8_t exponent_group_tab[3][256]; ++static uint8_t exponent_group_tab[2][3][256]; + + + /** + * List of supported channel layouts. + */ +-static const int64_t ac3_channel_layouts[] = { ++const uint64_t ff_ac3_channel_layouts[19] = { + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_2_1, +@@ -203,10 +101,85 @@ + + + /** ++ * LUT to select the bandwidth code based on the bit rate, sample rate, and ++ * number of full-bandwidth channels. ++ * bandwidth_tab[fbw_channels-1][sample rate code][bit rate code] ++ */ ++static const uint8_t ac3_bandwidth_tab[5][3][19] = { ++// 32 40 48 56 64 80 96 112 128 160 192 224 256 320 384 448 512 576 640 ++ ++ { { 0, 0, 0, 12, 16, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48 }, ++ { 0, 0, 0, 16, 20, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56, 56 }, ++ { 0, 0, 0, 32, 40, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } }, ++ ++ { { 0, 0, 0, 0, 0, 0, 0, 20, 24, 32, 48, 48, 48, 48, 48, 48, 48, 48, 48 }, ++ { 0, 0, 0, 0, 0, 0, 4, 24, 28, 36, 56, 56, 56, 56, 56, 56, 56, 56, 56 }, ++ { 0, 0, 0, 0, 0, 0, 20, 44, 52, 60, 60, 60, 60, 60, 60, 60, 60, 60, 60 } }, ++ ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 24, 32, 40, 48, 48, 48, 48, 48, 48 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 4, 20, 28, 36, 44, 56, 56, 56, 56, 56, 56 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 20, 40, 48, 60, 60, 60, 60, 60, 60, 60, 60 } }, ++ ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 32, 48, 48, 48, 48, 48, 48 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 28, 36, 56, 56, 56, 56, 56, 56 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, 48, 60, 60, 60, 60, 60, 60, 60 } }, ++ ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8, 20, 32, 40, 48, 48, 48, 48 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 12, 24, 36, 44, 56, 56, 56, 56 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, 44, 60, 60, 60, 60, 60, 60 } } ++}; ++ ++ ++/** ++ * LUT to select the coupling start band based on the bit rate, sample rate, and ++ * number of full-bandwidth channels. -1 = coupling off ++ * ac3_coupling_start_tab[channel_mode-2][sample rate code][bit rate code] ++ * ++ * TODO: more testing for optimal parameters. ++ * multi-channel tests at 44.1kHz and 32kHz. ++ */ ++static const int8_t ac3_coupling_start_tab[6][3][19] = { ++// 32 40 48 56 64 80 96 112 128 160 192 224 256 320 384 448 512 576 640 ++ ++ // 2/0 ++ { { 0, 0, 0, 0, 0, 0, 0, 1, 1, 7, 8, 11, 12, -1, -1, -1, -1, -1, -1 }, ++ { 0, 0, 0, 0, 0, 0, 1, 3, 5, 7, 10, 12, 13, -1, -1, -1, -1, -1, -1 }, ++ { 0, 0, 0, 0, 1, 2, 2, 9, 13, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++ ++ // 3/0 ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 }, ++ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++ ++ // 2/1 - untested ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 6, 9, 11, 12, 13, -1, -1, -1, -1 }, ++ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++ ++ // 3/1 ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 }, ++ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++ ++ // 2/2 - untested ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 10, 11, 11, 12, 12, 14, -1 }, ++ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++ ++ // 3/2 ++ { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 6, 8, 11, 12, 12, -1, -1 }, ++ { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 } }, ++}; ++ ++ ++/** + * Adjust the frame size to make the average bit rate match the target bit rate. +- * This is only needed for 11025, 22050, and 44100 sample rates. ++ * This is only needed for 11025, 22050, and 44100 sample rates or any E-AC-3. ++ * ++ * @param s AC-3 encoder private context + */ +-static void adjust_frame_size(AC3EncodeContext *s) ++void ff_ac3_adjust_frame_size(AC3EncodeContext *s) + { + while (s->bits_written >= s->bit_rate && s->samples_written >= s->sample_rate) { + s->bits_written -= s->bit_rate; +@@ -215,164 +188,110 @@ + s->frame_size = s->frame_size_min + + 2 * (s->bits_written * s->sample_rate < s->samples_written * s->bit_rate); + s->bits_written += s->frame_size * 8; +- s->samples_written += AC3_FRAME_SIZE; +-} +- +- +-/** +- * Deinterleave input samples. +- * Channels are reordered from FFmpeg's default order to AC-3 order. +- */ +-static void deinterleave_input_samples(AC3EncodeContext *s, +- const SampleType *samples) +-{ +- int ch, i; +- +- /* deinterleave and remap input samples */ +- for (ch = 0; ch < s->channels; ch++) { +- const SampleType *sptr; +- int sinc; +- +- /* copy last 256 samples of previous frame to the start of the current frame */ +- memcpy(&s->planar_samples[ch][0], &s->planar_samples[ch][AC3_FRAME_SIZE], +- AC3_BLOCK_SIZE * sizeof(s->planar_samples[0][0])); +- +- /* deinterleave */ +- sinc = s->channels; +- sptr = samples + s->channel_map[ch]; +- for (i = AC3_BLOCK_SIZE; i < AC3_FRAME_SIZE+AC3_BLOCK_SIZE; i++) { +- s->planar_samples[ch][i] = *sptr; +- sptr += sinc; +- } +- } ++ s->samples_written += AC3_BLOCK_SIZE * s->num_blocks; + } + + + /** +- * Apply the MDCT to input samples to generate frequency coefficients. +- * This applies the KBD window and normalizes the input to reduce precision +- * loss due to fixed-point calculations. ++ * Set the initial coupling strategy parameters prior to coupling analysis. ++ * ++ * @param s AC-3 encoder private context + */ +-static void apply_mdct(AC3EncodeContext *s) ++void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s) + { + int blk, ch; ++ int got_cpl_snr; ++ int num_cpl_blocks; + +- for (ch = 0; ch < s->channels; ch++) { +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- AC3Block *block = &s->blocks[blk]; +- const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE]; +- +- apply_window(&s->dsp, s->windowed_samples, input_samples, s->mdct.window, AC3_WINDOW_SIZE); +- +- block->exp_shift[ch] = normalize_samples(s); +- +- mdct512(&s->mdct, block->mdct_coef[ch], s->windowed_samples); +- } ++ /* set coupling use flags for each block/channel */ ++ /* TODO: turn coupling on/off and adjust start band based on bit usage */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ block->channel_in_cpl[ch] = s->cpl_on; + } +-} +- + +-/** +- * Initialize stereo rematrixing. +- * If the strategy does not change for each frame, set the rematrixing flags. +- */ +-static void rematrixing_init(AC3EncodeContext *s) +-{ +- if (s->channel_mode == AC3_CHMODE_STEREO) +- s->rematrixing = AC3_REMATRIXING_SUMS; +- else +- s->rematrixing = AC3_REMATRIXING_NONE; +- /* NOTE: AC3_REMATRIXING_ALWAYS might be used in +- the future in conjunction with channel coupling. */ ++ /* enable coupling for each block if at least 2 channels have coupling ++ enabled for that block */ ++ got_cpl_snr = 0; ++ num_cpl_blocks = 0; ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ block->num_cpl_channels = 0; ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ block->num_cpl_channels += block->channel_in_cpl[ch]; ++ block->cpl_in_use = block->num_cpl_channels > 1; ++ num_cpl_blocks += block->cpl_in_use; ++ if (!block->cpl_in_use) { ++ block->num_cpl_channels = 0; ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ block->channel_in_cpl[ch] = 0; ++ } ++ ++ block->new_cpl_strategy = !blk; ++ if (blk) { ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (block->channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]) { ++ block->new_cpl_strategy = 1; ++ break; ++ } ++ } ++ } ++ block->new_cpl_leak = block->new_cpl_strategy; + +- if (s->rematrixing & AC3_REMATRIXING_IS_STATIC) { +- int flag = (s->rematrixing == AC3_REMATRIXING_ALWAYS); +- s->blocks[0].new_rematrixing_strategy = 1; +- memset(s->blocks[0].rematrixing_flags, flag, +- sizeof(s->blocks[0].rematrixing_flags)); ++ if (!blk || (block->cpl_in_use && !got_cpl_snr)) { ++ block->new_snr_offsets = 1; ++ if (block->cpl_in_use) ++ got_cpl_snr = 1; ++ } else { ++ block->new_snr_offsets = 0; ++ } + } +-} +- +- +-/** +- * Determine rematrixing flags for each block and band. +- */ +-static void compute_rematrixing_strategy(AC3EncodeContext *s) +-{ +- int nb_coefs; +- int blk, bnd, i; +- AC3Block *block, *block0; +- +- if (s->rematrixing & AC3_REMATRIXING_IS_STATIC) +- return; +- +- nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]); ++ if (!num_cpl_blocks) ++ s->cpl_on = 0; + +- s->blocks[0].new_rematrixing_strategy = 1; +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- block = &s->blocks[blk]; +- for (bnd = 0; bnd < 4; bnd++) { +- /* calculate calculate sum of squared coeffs for one band in one block */ +- int start = ff_ac3_rematrix_band_tab[bnd]; +- int end = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]); +- CoefSumType sum[4] = {0,}; +- for (i = start; i < end; i++) { +- CoefType lt = block->mdct_coef[0][i]; +- CoefType rt = block->mdct_coef[1][i]; +- CoefType md = lt + rt; +- CoefType sd = lt - rt; +- sum[0] += lt * lt; +- sum[1] += rt * rt; +- sum[2] += md * md; +- sum[3] += sd * sd; +- } +- +- /* compare sums to determine if rematrixing will be used for this band */ +- if (FFMIN(sum[2], sum[3]) < FFMIN(sum[0], sum[1])) +- block->rematrixing_flags[bnd] = 1; ++ /* set bandwidth for each channel */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (block->channel_in_cpl[ch]) ++ block->end_freq[ch] = s->start_freq[CPL_CH]; + else +- block->rematrixing_flags[bnd] = 0; +- +- /* determine if new rematrixing flags will be sent */ +- if (blk && +- !block->new_rematrixing_strategy && +- block->rematrixing_flags[bnd] != block0->rematrixing_flags[bnd]) { +- block->new_rematrixing_strategy = 1; +- } ++ block->end_freq[ch] = s->bandwidth_code * 3 + 73; + } +- block0 = block; + } + } + + + /** + * Apply stereo rematrixing to coefficients based on rematrixing flags. ++ * ++ * @param s AC-3 encoder private context + */ +-static void apply_rematrixing(AC3EncodeContext *s) ++void ff_ac3_apply_rematrixing(AC3EncodeContext *s) + { + int nb_coefs; + int blk, bnd, i; + int start, end; + uint8_t *flags; + +- if (s->rematrixing == AC3_REMATRIXING_NONE) ++ if (!s->rematrixing_enabled) + return; + +- nb_coefs = FFMIN(s->nb_coefs[0], s->nb_coefs[1]); +- +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; + if (block->new_rematrixing_strategy) + flags = block->rematrixing_flags; +- for (bnd = 0; bnd < 4; bnd++) { ++ nb_coefs = FFMIN(block->end_freq[1], block->end_freq[2]); ++ for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) { + if (flags[bnd]) { + start = ff_ac3_rematrix_band_tab[bnd]; + end = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]); + for (i = start; i < end; i++) { +- int32_t lt = block->fixed_coef[0][i]; +- int32_t rt = block->fixed_coef[1][i]; +- block->fixed_coef[0][i] = (lt + rt) >> 1; +- block->fixed_coef[1][i] = (lt - rt) >> 1; ++ int32_t lt = block->fixed_coef[1][i]; ++ int32_t rt = block->fixed_coef[2][i]; ++ block->fixed_coef[1][i] = (lt + rt) >> 1; ++ block->fixed_coef[2][i] = (lt - rt) >> 1; + } + } + } +@@ -380,53 +299,38 @@ + } + + +-/** ++/* + * Initialize exponent tables. + */ + static av_cold void exponent_init(AC3EncodeContext *s) + { +- int i; +- for (i = 73; i < 256; i++) { +- exponent_group_tab[0][i] = (i - 1) / 3; +- exponent_group_tab[1][i] = (i + 2) / 6; +- exponent_group_tab[2][i] = (i + 8) / 12; ++ int expstr, i, grpsize; ++ ++ for (expstr = EXP_D15-1; expstr <= EXP_D45-1; expstr++) { ++ grpsize = 3 << expstr; ++ for (i = 12; i < 256; i++) { ++ exponent_group_tab[0][expstr][i] = (i + grpsize - 4) / grpsize; ++ exponent_group_tab[1][expstr][i] = (i ) / grpsize; ++ } + } + /* LFE */ +- exponent_group_tab[0][7] = 2; ++ exponent_group_tab[0][0][7] = 2; ++ ++ if (CONFIG_EAC3_ENCODER && s->eac3) ++ ff_eac3_exponent_init(); + } + + +-/** ++/* + * Extract exponents from the MDCT coefficients. +- * This takes into account the normalization that was done to the input samples +- * by adjusting the exponents by the exponent shift values. + */ + static void extract_exponents(AC3EncodeContext *s) + { +- int blk, ch, i; ++ int ch = !s->cpl_on; ++ int chan_size = AC3_MAX_COEFS * s->num_blocks * (s->channels - ch + 1); ++ AC3Block *block = &s->blocks[0]; + +- for (ch = 0; ch < s->channels; ch++) { +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- AC3Block *block = &s->blocks[blk]; +- uint8_t *exp = block->exp[ch]; +- int32_t *coef = block->fixed_coef[ch]; +- int exp_shift = block->exp_shift[ch]; +- for (i = 0; i < AC3_MAX_COEFS; i++) { +- int e; +- int v = abs(coef[i]); +- if (v == 0) +- e = 24; +- else { +- e = 23 - av_log2(v) + exp_shift; +- if (e >= 24) { +- e = 24; +- coef[i] = 0; +- } +- } +- exp[i] = e; +- } +- } +- } ++ s->ac3dsp.extract_exponents(block->exp[ch], block->fixed_coef[ch], chan_size); + } + + +@@ -436,115 +340,106 @@ + */ + #define EXP_DIFF_THRESHOLD 500 + +- + /** +- * Calculate exponent strategies for all blocks in a single channel. ++ * Table used to select exponent strategy based on exponent reuse block interval. + */ +-static void compute_exp_strategy_ch(AC3EncodeContext *s, uint8_t *exp_strategy, +- uint8_t *exp) +-{ +- int blk, blk1; +- int exp_diff; +- +- /* estimate if the exponent variation & decide if they should be +- reused in the next frame */ +- exp_strategy[0] = EXP_NEW; +- exp += AC3_MAX_COEFS; +- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) { +- exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16); +- if (exp_diff > EXP_DIFF_THRESHOLD) +- exp_strategy[blk] = EXP_NEW; +- else +- exp_strategy[blk] = EXP_REUSE; +- exp += AC3_MAX_COEFS; +- } +- emms_c(); +- +- /* now select the encoding strategy type : if exponents are often +- recoded, we use a coarse encoding */ +- blk = 0; +- while (blk < AC3_MAX_BLOCKS) { +- blk1 = blk + 1; +- while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) +- blk1++; +- switch (blk1 - blk) { +- case 1: exp_strategy[blk] = EXP_D45; break; +- case 2: +- case 3: exp_strategy[blk] = EXP_D25; break; +- default: exp_strategy[blk] = EXP_D15; break; +- } +- blk = blk1; +- } +-} +- ++static const uint8_t exp_strategy_reuse_tab[4][6] = { ++ { EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15 }, ++ { EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15, EXP_D15 }, ++ { EXP_D25, EXP_D25, EXP_D15, EXP_D15, EXP_D15, EXP_D15 }, ++ { EXP_D45, EXP_D25, EXP_D25, EXP_D15, EXP_D15, EXP_D15 } ++}; + +-/** ++/* + * Calculate exponent strategies for all channels. + * Array arrangement is reversed to simplify the per-channel calculation. + */ + static void compute_exp_strategy(AC3EncodeContext *s) + { +- int ch, blk; ++ int ch, blk, blk1; ++ ++ for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) { ++ uint8_t *exp_strategy = s->exp_strategy[ch]; ++ uint8_t *exp = s->blocks[0].exp[ch]; ++ int exp_diff; ++ ++ /* estimate if the exponent variation & decide if they should be ++ reused in the next frame */ ++ exp_strategy[0] = EXP_NEW; ++ exp += AC3_MAX_COEFS; ++ for (blk = 1; blk < s->num_blocks; blk++, exp += AC3_MAX_COEFS) { ++ if (ch == CPL_CH) { ++ if (!s->blocks[blk-1].cpl_in_use) { ++ exp_strategy[blk] = EXP_NEW; ++ continue; ++ } else if (!s->blocks[blk].cpl_in_use) { ++ exp_strategy[blk] = EXP_REUSE; ++ continue; ++ } ++ } else if (s->blocks[blk].channel_in_cpl[ch] != s->blocks[blk-1].channel_in_cpl[ch]) { ++ exp_strategy[blk] = EXP_NEW; ++ continue; ++ } ++ exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16); ++ exp_strategy[blk] = EXP_REUSE; ++ if (ch == CPL_CH && exp_diff > (EXP_DIFF_THRESHOLD * (s->blocks[blk].end_freq[ch] - s->start_freq[ch]) / AC3_MAX_COEFS)) ++ exp_strategy[blk] = EXP_NEW; ++ else if (ch > CPL_CH && exp_diff > EXP_DIFF_THRESHOLD) ++ exp_strategy[blk] = EXP_NEW; ++ } + +- for (ch = 0; ch < s->fbw_channels; ch++) { +- compute_exp_strategy_ch(s, s->exp_strategy[ch], s->blocks[0].exp[ch]); ++ /* now select the encoding strategy type : if exponents are often ++ recoded, we use a coarse encoding */ ++ blk = 0; ++ while (blk < s->num_blocks) { ++ blk1 = blk + 1; ++ while (blk1 < s->num_blocks && exp_strategy[blk1] == EXP_REUSE) ++ blk1++; ++ exp_strategy[blk] = exp_strategy_reuse_tab[s->num_blks_code][blk1-blk-1]; ++ blk = blk1; ++ } + } + if (s->lfe_on) { + ch = s->lfe_channel; + s->exp_strategy[ch][0] = EXP_D15; +- for (blk = 1; blk < AC3_MAX_BLOCKS; blk++) ++ for (blk = 1; blk < s->num_blocks; blk++) + s->exp_strategy[ch][blk] = EXP_REUSE; + } +-} +- + +-/** +- * Set each encoded exponent in a block to the minimum of itself and the +- * exponents in the same frequency bin of up to 5 following blocks. +- */ +-static void exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs) +-{ +- int blk, i; +- +- if (!num_reuse_blocks) +- return; +- +- for (i = 0; i < nb_coefs; i++) { +- uint8_t min_exp = *exp; +- uint8_t *exp1 = exp + AC3_MAX_COEFS; +- for (blk = 0; blk < num_reuse_blocks; blk++) { +- uint8_t next_exp = *exp1; +- if (next_exp < min_exp) +- min_exp = next_exp; +- exp1 += AC3_MAX_COEFS; +- } +- *exp++ = min_exp; +- } ++ /* for E-AC-3, determine frame exponent strategy */ ++ if (CONFIG_EAC3_ENCODER && s->eac3) ++ ff_eac3_get_frame_exp_strategy(s); + } + + + /** + * Update the exponents so that they are the ones the decoder will decode. ++ * ++ * @param[in,out] exp array of exponents for 1 block in 1 channel ++ * @param nb_exps number of exponents in active bandwidth ++ * @param exp_strategy exponent strategy for the block ++ * @param cpl indicates if the block is in the coupling channel + */ +-static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy) ++static void encode_exponents_blk_ch(uint8_t *exp, int nb_exps, int exp_strategy, ++ int cpl) + { + int nb_groups, i, k; + +- nb_groups = exponent_group_tab[exp_strategy-1][nb_exps] * 3; ++ nb_groups = exponent_group_tab[cpl][exp_strategy-1][nb_exps] * 3; + + /* for each group, compute the minimum exponent */ + switch(exp_strategy) { + case EXP_D25: +- for (i = 1, k = 1; i <= nb_groups; i++) { ++ for (i = 1, k = 1-cpl; i <= nb_groups; i++) { + uint8_t exp_min = exp[k]; + if (exp[k+1] < exp_min) + exp_min = exp[k+1]; +- exp[i] = exp_min; ++ exp[i-cpl] = exp_min; + k += 2; + } + break; + case EXP_D45: +- for (i = 1, k = 1; i <= nb_groups; i++) { ++ for (i = 1, k = 1-cpl; i <= nb_groups; i++) { + uint8_t exp_min = exp[k]; + if (exp[k+1] < exp_min) + exp_min = exp[k+1]; +@@ -552,14 +447,14 @@ + exp_min = exp[k+2]; + if (exp[k+3] < exp_min) + exp_min = exp[k+3]; +- exp[i] = exp_min; ++ exp[i-cpl] = exp_min; + k += 4; + } + break; + } + + /* constraint for DC exponent */ +- if (exp[0] > 15) ++ if (!cpl && exp[0] > 15) + exp[0] = 15; + + /* decrease the delta between each groups to within 2 so that they can be +@@ -570,18 +465,21 @@ + while (--i >= 0) + exp[i] = FFMIN(exp[i], exp[i+1] + 2); + ++ if (cpl) ++ exp[-1] = exp[0] & ~1; ++ + /* now we have the exponent values the decoder will see */ + switch (exp_strategy) { + case EXP_D25: +- for (i = nb_groups, k = nb_groups * 2; i > 0; i--) { +- uint8_t exp1 = exp[i]; ++ for (i = nb_groups, k = (nb_groups * 2)-cpl; i > 0; i--) { ++ uint8_t exp1 = exp[i-cpl]; + exp[k--] = exp1; + exp[k--] = exp1; + } + break; + case EXP_D45: +- for (i = nb_groups, k = nb_groups * 4; i > 0; i--) { +- exp[k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i]; ++ for (i = nb_groups, k = (nb_groups * 4)-cpl; i > 0; i--) { ++ exp[k] = exp[k-1] = exp[k-2] = exp[k-3] = exp[i-cpl]; + k -= 4; + } + break; +@@ -589,7 +487,7 @@ + } + + +-/** ++/* + * Encode exponents from original extracted form to what the decoder will see. + * This copies and groups exponents based on exponent strategy and reduces + * deltas between adjacent exponent groups so that they can be differentially +@@ -597,40 +495,76 @@ + */ + static void encode_exponents(AC3EncodeContext *s) + { +- int blk, blk1, ch; +- uint8_t *exp, *exp1, *exp_strategy; ++ int blk, blk1, ch, cpl; ++ uint8_t *exp, *exp_strategy; + int nb_coefs, num_reuse_blocks; + +- for (ch = 0; ch < s->channels; ch++) { +- exp = s->blocks[0].exp[ch]; ++ for (ch = !s->cpl_on; ch <= s->channels; ch++) { ++ exp = s->blocks[0].exp[ch] + s->start_freq[ch]; + exp_strategy = s->exp_strategy[ch]; +- nb_coefs = s->nb_coefs[ch]; + ++ cpl = (ch == CPL_CH); + blk = 0; +- while (blk < AC3_MAX_BLOCKS) { ++ while (blk < s->num_blocks) { ++ AC3Block *block = &s->blocks[blk]; ++ if (cpl && !block->cpl_in_use) { ++ exp += AC3_MAX_COEFS; ++ blk++; ++ continue; ++ } ++ nb_coefs = block->end_freq[ch] - s->start_freq[ch]; + blk1 = blk + 1; + +- /* count the number of EXP_REUSE blocks after the current block */ +- while (blk1 < AC3_MAX_BLOCKS && exp_strategy[blk1] == EXP_REUSE) ++ /* count the number of EXP_REUSE blocks after the current block ++ and set exponent reference block numbers */ ++ s->exp_ref_block[ch][blk] = blk; ++ while (blk1 < s->num_blocks && exp_strategy[blk1] == EXP_REUSE) { ++ s->exp_ref_block[ch][blk1] = blk; + blk1++; ++ } + num_reuse_blocks = blk1 - blk - 1; + + /* for the EXP_REUSE case we select the min of the exponents */ +- exponent_min(exp, num_reuse_blocks, nb_coefs); ++ s->ac3dsp.ac3_exponent_min(exp-s->start_freq[ch], num_reuse_blocks, ++ AC3_MAX_COEFS); + +- encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk]); ++ encode_exponents_blk_ch(exp, nb_coefs, exp_strategy[blk], cpl); + +- /* copy encoded exponents for reuse case */ +- exp1 = exp + AC3_MAX_COEFS; +- while (blk < blk1-1) { +- memcpy(exp1, exp, nb_coefs * sizeof(*exp)); +- exp1 += AC3_MAX_COEFS; +- blk++; +- } ++ exp += AC3_MAX_COEFS * (num_reuse_blocks + 1); + blk = blk1; +- exp = exp1; + } + } ++ ++ /* reference block numbers have been changed, so reset ref_bap_set */ ++ s->ref_bap_set = 0; ++} ++ ++ ++/* ++ * Count exponent bits based on bandwidth, coupling, and exponent strategies. ++ */ ++static int count_exponent_bits(AC3EncodeContext *s) ++{ ++ int blk, ch; ++ int nb_groups, bit_count; ++ ++ bit_count = 0; ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { ++ int exp_strategy = s->exp_strategy[ch][blk]; ++ int cpl = (ch == CPL_CH); ++ int nb_coefs = block->end_freq[ch] - s->start_freq[ch]; ++ ++ if (exp_strategy == EXP_REUSE) ++ continue; ++ ++ nb_groups = exponent_group_tab[cpl][exp_strategy-1][nb_coefs]; ++ bit_count += 4 + (nb_groups * 7); ++ } ++ } ++ ++ return bit_count; + } + + +@@ -638,26 +572,27 @@ + * Group exponents. + * 3 delta-encoded exponents are in each 7-bit group. The number of groups + * varies depending on exponent strategy and bandwidth. ++ * ++ * @param s AC-3 encoder private context + */ +-static void group_exponents(AC3EncodeContext *s) ++void ff_ac3_group_exponents(AC3EncodeContext *s) + { +- int blk, ch, i; +- int group_size, nb_groups, bit_count; ++ int blk, ch, i, cpl; ++ int group_size, nb_groups; + uint8_t *p; + int delta0, delta1, delta2; + int exp0, exp1; + +- bit_count = 0; +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- for (ch = 0; ch < s->channels; ch++) { ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + int exp_strategy = s->exp_strategy[ch][blk]; + if (exp_strategy == EXP_REUSE) + continue; ++ cpl = (ch == CPL_CH); + group_size = exp_strategy + (exp_strategy == EXP_D45); +- nb_groups = exponent_group_tab[exp_strategy-1][s->nb_coefs[ch]]; +- bit_count += 4 + (nb_groups * 7); +- p = block->exp[ch]; ++ nb_groups = exponent_group_tab[cpl][exp_strategy-1][block->end_freq[ch]-s->start_freq[ch]]; ++ p = block->exp[ch] + s->start_freq[ch] - cpl; + + /* DC exponent */ + exp1 = *p++; +@@ -670,23 +605,24 @@ + exp1 = p[0]; + p += group_size; + delta0 = exp1 - exp0 + 2; ++ av_assert2(delta0 >= 0 && delta0 <= 4); + + exp0 = exp1; + exp1 = p[0]; + p += group_size; + delta1 = exp1 - exp0 + 2; ++ av_assert2(delta1 >= 0 && delta1 <= 4); + + exp0 = exp1; + exp1 = p[0]; + p += group_size; + delta2 = exp1 - exp0 + 2; ++ av_assert2(delta2 >= 0 && delta2 <= 4); + + block->grouped_exp[ch][i] = ((delta0 * 5 + delta1) * 5) + delta2; + } + } + } +- +- s->exponent_bits = bit_count; + } + + +@@ -694,8 +630,10 @@ + * Calculate final exponents from the supplied MDCT coefficients and exponent shift. + * Extract exponents from MDCT coefficients, calculate exponent strategies, + * and encode final exponents. ++ * ++ * @param s AC-3 encoder private context + */ +-static void process_exponents(AC3EncodeContext *s) ++void ff_ac3_process_exponents(AC3EncodeContext *s) + { + extract_exponents(s); + +@@ -703,11 +641,11 @@ + + encode_exponents(s); + +- group_exponents(s); ++ emms_c(); + } + + +-/** ++/* + * Count frame bits that are based solely on fixed parameters. + * This only has to be run once when the encoder is initialized. + */ +@@ -719,49 +657,101 @@ + + /* assumptions: + * no dynamic range codes +- * no channel coupling + * bit allocation parameters do not change between blocks +- * SNR offsets do not change between blocks + * no delta bit allocation + * no skipped data + * no auxilliary data ++ * no E-AC-3 metadata + */ + +- /* header size */ +- frame_bits = 65; +- frame_bits += frame_bits_inc[s->channel_mode]; ++ /* header */ ++ frame_bits = 16; /* sync info */ ++ if (s->eac3) { ++ /* bitstream info header */ ++ frame_bits += 35; ++ frame_bits += 1 + 1; ++ if (s->num_blocks != 0x6) ++ frame_bits++; ++ frame_bits++; ++ /* audio frame header */ ++ if (s->num_blocks == 6) ++ frame_bits += 2; ++ frame_bits += 10; ++ /* exponent strategy */ ++ if (s->use_frame_exp_strategy) ++ frame_bits += 5 * s->fbw_channels; ++ else ++ frame_bits += s->num_blocks * 2 * s->fbw_channels; ++ if (s->lfe_on) ++ frame_bits += s->num_blocks; ++ /* converter exponent strategy */ ++ if (s->num_blks_code != 0x3) ++ frame_bits++; ++ else ++ frame_bits += s->fbw_channels * 5; ++ /* snr offsets */ ++ frame_bits += 10; ++ /* block start info */ ++ if (s->num_blocks != 1) ++ frame_bits++; ++ } else { ++ frame_bits += 49; ++ frame_bits += frame_bits_inc[s->channel_mode]; ++ } + + /* audio blocks */ +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- frame_bits += s->fbw_channels * 2 + 2; /* blksw * c, dithflag * c, dynrnge, cplstre */ +- if (s->channel_mode == AC3_CHMODE_STEREO) { +- frame_bits++; /* rematstr */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ if (!s->eac3) { ++ /* block switch flags */ ++ frame_bits += s->fbw_channels; ++ ++ /* dither flags */ ++ frame_bits += s->fbw_channels; + } +- frame_bits += 2 * s->fbw_channels; /* chexpstr[2] * c */ +- if (s->lfe_on) +- frame_bits++; /* lfeexpstr */ +- frame_bits++; /* baie */ +- frame_bits++; /* snr */ +- frame_bits += 2; /* delta / skip */ +- } +- frame_bits++; /* cplinu for block 0 */ +- /* bit alloc info */ +- /* sdcycod[2], fdcycod[2], sgaincod[2], dbpbcod[2], floorcod[3] */ +- /* csnroffset[6] */ +- /* (fsnoffset[4] + fgaincod[4]) * c */ +- frame_bits += 2*4 + 3 + 6 + s->channels * (4 + 3); + +- /* auxdatae, crcrsv */ +- frame_bits += 2; ++ /* dynamic range */ ++ frame_bits++; ++ ++ /* spectral extension */ ++ if (s->eac3) ++ frame_bits++; ++ ++ if (!s->eac3) { ++ /* exponent strategy */ ++ frame_bits += 2 * s->fbw_channels; ++ if (s->lfe_on) ++ frame_bits++; ++ ++ /* bit allocation params */ ++ frame_bits++; ++ if (!blk) ++ frame_bits += 2 + 2 + 2 + 2 + 3; ++ } ++ ++ /* converter snr offset */ ++ if (s->eac3) ++ frame_bits++; ++ ++ if (!s->eac3) { ++ /* delta bit allocation */ ++ frame_bits++; ++ ++ /* skipped data */ ++ frame_bits++; ++ } ++ } ++ ++ /* auxiliary data */ ++ frame_bits++; + + /* CRC */ +- frame_bits += 16; ++ frame_bits += 1 + 16; + + s->frame_bits_fixed = frame_bits; + } + + +-/** ++/* + * Initialize bit allocation. + * Set default parameter codes and calculate parameter values. + */ +@@ -773,9 +763,9 @@ + s->slow_decay_code = 2; + s->fast_decay_code = 1; + s->slow_gain_code = 1; +- s->db_per_bit_code = 3; +- s->floor_code = 4; +- for (ch = 0; ch < s->channels; ch++) ++ s->db_per_bit_code = s->eac3 ? 2 : 3; ++ s->floor_code = 7; ++ for (ch = 0; ch <= s->channels; ch++) + s->fast_gain_code[ch] = 4; + + /* initial snr offset */ +@@ -789,79 +779,161 @@ + s->bit_alloc.slow_gain = ff_ac3_slow_gain_tab[s->slow_gain_code]; + s->bit_alloc.db_per_bit = ff_ac3_db_per_bit_tab[s->db_per_bit_code]; + s->bit_alloc.floor = ff_ac3_floor_tab[s->floor_code]; ++ s->bit_alloc.cpl_fast_leak = 0; ++ s->bit_alloc.cpl_slow_leak = 0; + + count_frame_bits_fixed(s); + } + + +-/** ++/* + * Count the bits used to encode the frame, minus exponents and mantissas. + * Bits based on fixed parameters have already been counted, so now we just + * have to add the bits based on parameters that change during encoding. + */ + static void count_frame_bits(AC3EncodeContext *s) + { ++ AC3EncOptions *opt = &s->options; + int blk, ch; + int frame_bits = 0; + +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- /* stereo rematrixing */ +- if (s->channel_mode == AC3_CHMODE_STEREO && +- s->blocks[blk].new_rematrixing_strategy) { +- frame_bits += 4; ++ /* header */ ++ if (s->eac3) { ++ if (opt->eac3_mixing_metadata) { ++ if (s->channel_mode > AC3_CHMODE_STEREO) ++ frame_bits += 2; ++ if (s->has_center) ++ frame_bits += 6; ++ if (s->has_surround) ++ frame_bits += 6; ++ frame_bits += s->lfe_on; ++ frame_bits += 1 + 1 + 2; ++ if (s->channel_mode < AC3_CHMODE_STEREO) ++ frame_bits++; ++ frame_bits++; ++ } ++ if (opt->eac3_info_metadata) { ++ frame_bits += 3 + 1 + 1; ++ if (s->channel_mode == AC3_CHMODE_STEREO) ++ frame_bits += 2 + 2; ++ if (s->channel_mode >= AC3_CHMODE_2F2R) ++ frame_bits += 2; ++ frame_bits++; ++ if (opt->audio_production_info) ++ frame_bits += 5 + 2 + 1; ++ frame_bits++; ++ } ++ /* coupling */ ++ if (s->channel_mode > AC3_CHMODE_MONO) { ++ frame_bits++; ++ for (blk = 1; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ frame_bits++; ++ if (block->new_cpl_strategy) ++ frame_bits++; ++ } + } +- +- for (ch = 0; ch < s->fbw_channels; ch++) { +- if (s->exp_strategy[ch][blk] != EXP_REUSE) +- frame_bits += 6 + 2; /* chbwcod[6], gainrng[2] */ ++ /* coupling exponent strategy */ ++ if (s->cpl_on) { ++ if (s->use_frame_exp_strategy) { ++ frame_bits += 5 * s->cpl_on; ++ } else { ++ for (blk = 0; blk < s->num_blocks; blk++) ++ frame_bits += 2 * s->blocks[blk].cpl_in_use; ++ } ++ } ++ } else { ++ if (opt->audio_production_info) ++ frame_bits += 7; ++ if (s->bitstream_id == 6) { ++ if (opt->extended_bsi_1) ++ frame_bits += 14; ++ if (opt->extended_bsi_2) ++ frame_bits += 14; + } + } +- s->frame_bits = s->frame_bits_fixed + frame_bits; +-} + ++ /* audio blocks */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; + +-/** +- * Calculate the number of bits needed to encode a set of mantissas. +- */ +-static int compute_mantissa_size(int mant_cnt[5], uint8_t *bap, int nb_coefs) +-{ +- int bits, b, i; ++ /* coupling strategy */ ++ if (!s->eac3) ++ frame_bits++; ++ if (block->new_cpl_strategy) { ++ if (!s->eac3) ++ frame_bits++; ++ if (block->cpl_in_use) { ++ if (s->eac3) ++ frame_bits++; ++ if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) ++ frame_bits += s->fbw_channels; ++ if (s->channel_mode == AC3_CHMODE_STEREO) ++ frame_bits++; ++ frame_bits += 4 + 4; ++ if (s->eac3) ++ frame_bits++; ++ else ++ frame_bits += s->num_cpl_subbands - 1; ++ } ++ } + +- bits = 0; +- for (i = 0; i < nb_coefs; i++) { +- b = bap[i]; +- if (b <= 4) { +- // bap=1 to bap=4 will be counted in compute_mantissa_size_final +- mant_cnt[b]++; +- } else if (b <= 13) { +- // bap=5 to bap=13 use (bap-1) bits +- bits += b - 1; +- } else { +- // bap=14 uses 14 bits and bap=15 uses 16 bits +- bits += (b == 14) ? 14 : 16; ++ /* coupling coordinates */ ++ if (block->cpl_in_use) { ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (block->channel_in_cpl[ch]) { ++ if (!s->eac3 || block->new_cpl_coords[ch] != 2) ++ frame_bits++; ++ if (block->new_cpl_coords[ch]) { ++ frame_bits += 2; ++ frame_bits += (4 + 4) * s->num_cpl_bands; ++ } ++ } ++ } + } +- } +- return bits; +-} + ++ /* stereo rematrixing */ ++ if (s->channel_mode == AC3_CHMODE_STEREO) { ++ if (!s->eac3 || blk > 0) ++ frame_bits++; ++ if (s->blocks[blk].new_rematrixing_strategy) ++ frame_bits += block->num_rematrixing_bands; ++ } + +-/** +- * Finalize the mantissa bit count by adding in the grouped mantissas. +- */ +-static int compute_mantissa_size_final(int mant_cnt[5]) +-{ +- // bap=1 : 3 mantissas in 5 bits +- int bits = (mant_cnt[1] / 3) * 5; +- // bap=2 : 3 mantissas in 7 bits +- // bap=4 : 2 mantissas in 7 bits +- bits += ((mant_cnt[2] / 3) + (mant_cnt[4] >> 1)) * 7; +- // bap=3 : each mantissa is 3 bits +- bits += mant_cnt[3] * 3; +- return bits; ++ /* bandwidth codes & gain range */ ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (s->exp_strategy[ch][blk] != EXP_REUSE) { ++ if (!block->channel_in_cpl[ch]) ++ frame_bits += 6; ++ frame_bits += 2; ++ } ++ } ++ ++ /* coupling exponent strategy */ ++ if (!s->eac3 && block->cpl_in_use) ++ frame_bits += 2; ++ ++ /* snr offsets and fast gain codes */ ++ if (!s->eac3) { ++ frame_bits++; ++ if (block->new_snr_offsets) ++ frame_bits += 6 + (s->channels + block->cpl_in_use) * (4 + 3); ++ } ++ ++ /* coupling leak info */ ++ if (block->cpl_in_use) { ++ if (!s->eac3 || block->new_cpl_leak != 2) ++ frame_bits++; ++ if (block->new_cpl_leak) ++ frame_bits += 3 + 3; ++ } ++ } ++ ++ s->frame_bits = s->frame_bits_fixed + frame_bits; + } + + +-/** ++/* + * Calculate masking curve based on the final exponents. + * Also calculate the power spectral densities to use in future calculations. + */ +@@ -869,18 +941,18 @@ + { + int blk, ch; + +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- for (ch = 0; ch < s->channels; ch++) { ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + /* We only need psd and mask for calculating bap. + Since we currently do not calculate bap when exponent + strategy is EXP_REUSE we do not need to calculate psd or mask. */ + if (s->exp_strategy[ch][blk] != EXP_REUSE) { +- ff_ac3_bit_alloc_calc_psd(block->exp[ch], 0, +- s->nb_coefs[ch], +- block->psd[ch], block->band_psd[ch]); ++ ff_ac3_bit_alloc_calc_psd(block->exp[ch], s->start_freq[ch], ++ block->end_freq[ch], block->psd[ch], ++ block->band_psd[ch]); + ff_ac3_bit_alloc_calc_mask(&s->bit_alloc, block->band_psd[ch], +- 0, s->nb_coefs[ch], ++ s->start_freq[ch], block->end_freq[ch], + ff_ac3_fast_gain_tab[s->fast_gain_code[ch]], + ch == s->lfe_channel, + DBA_NONE, 0, NULL, NULL, NULL, +@@ -891,70 +963,131 @@ + } + + +-/** ++/* + * Ensure that bap for each block and channel point to the current bap_buffer. + * They may have been switched during the bit allocation search. + */ + static void reset_block_bap(AC3EncodeContext *s) + { + int blk, ch; +- if (s->blocks[0].bap[0] == s->bap_buffer) ++ uint8_t *ref_bap; ++ ++ if (s->ref_bap[0][0] == s->bap_buffer && s->ref_bap_set) + return; ++ ++ ref_bap = s->bap_buffer; ++ for (ch = 0; ch <= s->channels; ch++) { ++ for (blk = 0; blk < s->num_blocks; blk++) ++ s->ref_bap[ch][blk] = ref_bap + AC3_MAX_COEFS * s->exp_ref_block[ch][blk]; ++ ref_bap += AC3_MAX_COEFS * s->num_blocks; ++ } ++ s->ref_bap_set = 1; ++} ++ ++ ++/** ++ * Initialize mantissa counts. ++ * These are set so that they are padded to the next whole group size when bits ++ * are counted in compute_mantissa_size. ++ * ++ * @param[in,out] mant_cnt running counts for each bap value for each block ++ */ ++static void count_mantissa_bits_init(uint16_t mant_cnt[AC3_MAX_BLOCKS][16]) ++{ ++ int blk; ++ + for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { +- for (ch = 0; ch < s->channels; ch++) { +- s->blocks[blk].bap[ch] = &s->bap_buffer[AC3_MAX_COEFS * (blk * s->channels + ch)]; +- } ++ memset(mant_cnt[blk], 0, sizeof(mant_cnt[blk])); ++ mant_cnt[blk][1] = mant_cnt[blk][2] = 2; ++ mant_cnt[blk][4] = 1; + } + } + + + /** ++ * Update mantissa bit counts for all blocks in 1 channel in a given bandwidth ++ * range. ++ * ++ * @param s AC-3 encoder private context ++ * @param ch channel index ++ * @param[in,out] mant_cnt running counts for each bap value for each block ++ * @param start starting coefficient bin ++ * @param end ending coefficient bin ++ */ ++static void count_mantissa_bits_update_ch(AC3EncodeContext *s, int ch, ++ uint16_t mant_cnt[AC3_MAX_BLOCKS][16], ++ int start, int end) ++{ ++ int blk; ++ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ if (ch == CPL_CH && !block->cpl_in_use) ++ continue; ++ s->ac3dsp.update_bap_counts(mant_cnt[blk], ++ s->ref_bap[ch][blk] + start, ++ FFMIN(end, block->end_freq[ch]) - start); ++ } ++} ++ ++ ++/* ++ * Count the number of mantissa bits in the frame based on the bap values. ++ */ ++static int count_mantissa_bits(AC3EncodeContext *s) ++{ ++ int ch, max_end_freq; ++ LOCAL_ALIGNED_16(uint16_t, mant_cnt, [AC3_MAX_BLOCKS], [16]); ++ ++ count_mantissa_bits_init(mant_cnt); ++ ++ max_end_freq = s->bandwidth_code * 3 + 73; ++ for (ch = !s->cpl_enabled; ch <= s->channels; ch++) ++ count_mantissa_bits_update_ch(s, ch, mant_cnt, s->start_freq[ch], ++ max_end_freq); ++ ++ return s->ac3dsp.compute_mantissa_size(mant_cnt); ++} ++ ++ ++/** + * Run the bit allocation with a given SNR offset. + * This calculates the bit allocation pointers that will be used to determine + * the quantization of each mantissa. ++ * ++ * @param s AC-3 encoder private context ++ * @param snr_offset SNR offset, 0 to 1023 + * @return the number of bits needed for mantissas if the given SNR offset is + * is used. + */ + static int bit_alloc(AC3EncodeContext *s, int snr_offset) + { + int blk, ch; +- int mantissa_bits; +- int mant_cnt[5]; + + snr_offset = (snr_offset - 240) << 2; + + reset_block_bap(s); +- mantissa_bits = 0; +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- // initialize grouped mantissa counts. these are set so that they are +- // padded to the next whole group size when bits are counted in +- // compute_mantissa_size_final +- mant_cnt[0] = mant_cnt[3] = 0; +- mant_cnt[1] = mant_cnt[2] = 2; +- mant_cnt[4] = 1; +- for (ch = 0; ch < s->channels; ch++) { ++ ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + /* Currently the only bit allocation parameters which vary across + blocks within a frame are the exponent values. We can take + advantage of that by reusing the bit allocation pointers + whenever we reuse exponents. */ +- if (s->exp_strategy[ch][blk] == EXP_REUSE) { +- memcpy(block->bap[ch], s->blocks[blk-1].bap[ch], AC3_MAX_COEFS); +- } else { +- ff_ac3_bit_alloc_calc_bap(block->mask[ch], block->psd[ch], 0, +- s->nb_coefs[ch], snr_offset, +- s->bit_alloc.floor, ff_ac3_bap_tab, +- block->bap[ch]); ++ if (s->exp_strategy[ch][blk] != EXP_REUSE) { ++ s->ac3dsp.bit_alloc_calc_bap(block->mask[ch], block->psd[ch], ++ s->start_freq[ch], block->end_freq[ch], ++ snr_offset, s->bit_alloc.floor, ++ ff_ac3_bap_tab, s->ref_bap[ch][blk]); + } +- mantissa_bits += compute_mantissa_size(mant_cnt, block->bap[ch], s->nb_coefs[ch]); + } +- mantissa_bits += compute_mantissa_size_final(mant_cnt); + } +- return mantissa_bits; ++ return count_mantissa_bits(s); + } + + +-/** ++/* + * Constant bitrate bit allocation search. + * Find the largest SNR offset that will allow data to fit in the frame. + */ +@@ -965,12 +1098,14 @@ + int snr_offset, snr_incr; + + bits_left = 8 * s->frame_size - (s->frame_bits + s->exponent_bits); ++ if (bits_left < 0) ++ return AVERROR(EINVAL); + + snr_offset = s->coarse_snr_offset << 4; + + /* if previous frame SNR offset was 1023, check if current frame can also + use SNR offset of 1023. if so, skip the search. */ +- if ((snr_offset | s->fine_snr_offset[0]) == 1023) { ++ if ((snr_offset | s->fine_snr_offset[1]) == 1023) { + if (bit_alloc(s, 1023) <= bits_left) + return 0; + } +@@ -994,178 +1129,92 @@ + reset_block_bap(s); + + s->coarse_snr_offset = snr_offset >> 4; +- for (ch = 0; ch < s->channels; ch++) ++ for (ch = !s->cpl_on; ch <= s->channels; ch++) + s->fine_snr_offset[ch] = snr_offset & 0xF; + + return 0; + } + + +-/** +- * Downgrade exponent strategies to reduce the bits used by the exponents. +- * This is a fallback for when bit allocation fails with the normal exponent +- * strategies. Each time this function is run it only downgrades the +- * strategy in 1 channel of 1 block. +- * @return non-zero if downgrade was unsuccessful +- */ +-static int downgrade_exponents(AC3EncodeContext *s) +-{ +- int ch, blk; +- +- for (ch = 0; ch < s->fbw_channels; ch++) { +- for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) { +- if (s->exp_strategy[ch][blk] == EXP_D15) { +- s->exp_strategy[ch][blk] = EXP_D25; +- return 0; +- } +- } +- } +- for (ch = 0; ch < s->fbw_channels; ch++) { +- for (blk = AC3_MAX_BLOCKS-1; blk >= 0; blk--) { +- if (s->exp_strategy[ch][blk] == EXP_D25) { +- s->exp_strategy[ch][blk] = EXP_D45; +- return 0; +- } +- } +- } +- for (ch = 0; ch < s->fbw_channels; ch++) { +- /* block 0 cannot reuse exponents, so only downgrade D45 to REUSE if +- the block number > 0 */ +- for (blk = AC3_MAX_BLOCKS-1; blk > 0; blk--) { +- if (s->exp_strategy[ch][blk] > EXP_REUSE) { +- s->exp_strategy[ch][blk] = EXP_REUSE; +- return 0; +- } +- } +- } +- return -1; +-} +- +- +-/** +- * Reduce the bandwidth to reduce the number of bits used for a given SNR offset. +- * This is a second fallback for when bit allocation still fails after exponents +- * have been downgraded. +- * @return non-zero if bandwidth reduction was unsuccessful +- */ +-static int reduce_bandwidth(AC3EncodeContext *s, int min_bw_code) +-{ +- int ch; +- +- if (s->bandwidth_code[0] > min_bw_code) { +- for (ch = 0; ch < s->fbw_channels; ch++) { +- s->bandwidth_code[ch]--; +- s->nb_coefs[ch] = s->bandwidth_code[ch] * 3 + 73; +- } +- return 0; +- } +- return -1; +-} +- +- +-/** ++/* + * Perform bit allocation search. + * Finds the SNR offset value that maximizes quality and fits in the specified + * frame size. Output is the SNR offset and a set of bit allocation pointers + * used to quantize the mantissas. + */ +-static int compute_bit_allocation(AC3EncodeContext *s) ++int ff_ac3_compute_bit_allocation(AC3EncodeContext *s) + { +- int ret; +- + count_frame_bits(s); + +- bit_alloc_masking(s); +- +- ret = cbr_bit_allocation(s); +- while (ret) { +- /* fallback 1: downgrade exponents */ +- if (!downgrade_exponents(s)) { +- extract_exponents(s); +- encode_exponents(s); +- group_exponents(s); +- ret = compute_bit_allocation(s); +- continue; +- } +- +- /* fallback 2: reduce bandwidth */ +- /* only do this if the user has not specified a specific cutoff +- frequency */ +- if (!s->cutoff && !reduce_bandwidth(s, 0)) { +- process_exponents(s); +- ret = compute_bit_allocation(s); +- continue; +- } ++ s->exponent_bits = count_exponent_bits(s); + +- /* fallbacks were not enough... */ +- break; +- } ++ bit_alloc_masking(s); + +- return ret; ++ return cbr_bit_allocation(s); + } + + + /** + * Symmetric quantization on 'levels' levels. ++ * ++ * @param c unquantized coefficient ++ * @param e exponent ++ * @param levels number of quantization levels ++ * @return quantized coefficient + */ + static inline int sym_quant(int c, int e, int levels) + { +- int v; +- +- if (c >= 0) { +- v = (levels * (c << e)) >> 24; +- v = (v + 1) >> 1; +- v = (levels >> 1) + v; +- } else { +- v = (levels * ((-c) << e)) >> 24; +- v = (v + 1) >> 1; +- v = (levels >> 1) - v; +- } +- assert(v >= 0 && v < levels); ++ int v = (((levels * c) >> (24 - e)) + levels) >> 1; ++ av_assert2(v >= 0 && v < levels); + return v; + } + + + /** + * Asymmetric quantization on 2^qbits levels. ++ * ++ * @param c unquantized coefficient ++ * @param e exponent ++ * @param qbits number of quantization bits ++ * @return quantized coefficient + */ + static inline int asym_quant(int c, int e, int qbits) + { +- int lshift, m, v; ++ int m; + +- lshift = e + qbits - 24; +- if (lshift >= 0) +- v = c << lshift; +- else +- v = c >> (-lshift); +- /* rounding */ +- v = (v + 1) >> 1; ++ c = (((c << e) >> (24 - qbits)) + 1) >> 1; + m = (1 << (qbits-1)); +- if (v >= m) +- v = m - 1; +- assert(v >= -m); +- return v & ((1 << qbits)-1); ++ if (c >= m) ++ c = m - 1; ++ av_assert2(c >= -m); ++ return c; + } + + + /** + * Quantize a set of mantissas for a single channel in a single block. +- */ +-static void quantize_mantissas_blk_ch(AC3EncodeContext *s, int32_t *fixed_coef, +- int8_t exp_shift, uint8_t *exp, +- uint8_t *bap, uint16_t *qmant, int n) ++ * ++ * @param s Mantissa count context ++ * @param fixed_coef unquantized fixed-point coefficients ++ * @param exp exponents ++ * @param bap bit allocation pointer indices ++ * @param[out] qmant quantized coefficients ++ * @param start_freq starting coefficient bin ++ * @param end_freq ending coefficient bin ++ */ ++static void quantize_mantissas_blk_ch(AC3Mant *s, int32_t *fixed_coef, ++ uint8_t *exp, uint8_t *bap, ++ int16_t *qmant, int start_freq, ++ int end_freq) + { + int i; + +- for (i = 0; i < n; i++) { +- int v; ++ for (i = start_freq; i < end_freq; i++) { + int c = fixed_coef[i]; +- int e = exp[i] - exp_shift; +- int b = bap[i]; +- switch (b) { +- case 0: +- v = 0; +- break; ++ int e = exp[i]; ++ int v = bap[i]; ++ if (v) ++ switch (v) { + case 1: + v = sym_quant(c, e, 3); + switch (s->mant1_cnt) { +@@ -1234,7 +1283,7 @@ + v = asym_quant(c, e, 16); + break; + default: +- v = asym_quant(c, e, b - 1); ++ v = asym_quant(c, e, v - 1); + break; + } + qmant[i] = v; +@@ -1244,31 +1293,42 @@ + + /** + * Quantize mantissas using coefficients, exponents, and bit allocation pointers. ++ * ++ * @param s AC-3 encoder private context + */ +-static void quantize_mantissas(AC3EncodeContext *s) ++void ff_ac3_quantize_mantissas(AC3EncodeContext *s) + { +- int blk, ch; +- ++ int blk, ch, ch0=0, got_cpl; + +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- s->mant1_cnt = s->mant2_cnt = s->mant4_cnt = 0; +- s->qmant1_ptr = s->qmant2_ptr = s->qmant4_ptr = NULL; ++ AC3Mant m = { 0 }; + +- for (ch = 0; ch < s->channels; ch++) { +- quantize_mantissas_blk_ch(s, block->fixed_coef[ch], block->exp_shift[ch], +- block->exp[ch], block->bap[ch], +- block->qmant[ch], s->nb_coefs[ch]); ++ got_cpl = !block->cpl_in_use; ++ for (ch = 1; ch <= s->channels; ch++) { ++ if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) { ++ ch0 = ch - 1; ++ ch = CPL_CH; ++ got_cpl = 1; ++ } ++ quantize_mantissas_blk_ch(&m, block->fixed_coef[ch], ++ s->blocks[s->exp_ref_block[ch][blk]].exp[ch], ++ s->ref_bap[ch][blk], block->qmant[ch], ++ s->start_freq[ch], block->end_freq[ch]); ++ if (ch == CPL_CH) ++ ch = ch0; + } + } + } + + +-/** ++/* + * Write the AC-3 frame header to the output bitstream. + */ +-static void output_frame_header(AC3EncodeContext *s) ++static void ac3_output_frame_header(AC3EncodeContext *s) + { ++ AC3EncOptions *opt = &s->options; ++ + put_bits(&s->pb, 16, 0x0b77); /* frame header */ + put_bits(&s->pb, 16, 0); /* crc1: will be filled later */ + put_bits(&s->pb, 2, s->bit_alloc.sr_code); +@@ -1277,134 +1337,236 @@ + put_bits(&s->pb, 3, s->bitstream_mode); + put_bits(&s->pb, 3, s->channel_mode); + if ((s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO) +- put_bits(&s->pb, 2, 1); /* XXX -4.5 dB */ ++ put_bits(&s->pb, 2, s->center_mix_level); + if (s->channel_mode & 0x04) +- put_bits(&s->pb, 2, 1); /* XXX -6 dB */ ++ put_bits(&s->pb, 2, s->surround_mix_level); + if (s->channel_mode == AC3_CHMODE_STEREO) +- put_bits(&s->pb, 2, 0); /* surround not indicated */ ++ put_bits(&s->pb, 2, opt->dolby_surround_mode); + put_bits(&s->pb, 1, s->lfe_on); /* LFE */ +- put_bits(&s->pb, 5, 31); /* dialog norm: -31 db */ ++ put_bits(&s->pb, 5, -opt->dialogue_level); + put_bits(&s->pb, 1, 0); /* no compression control word */ + put_bits(&s->pb, 1, 0); /* no lang code */ +- put_bits(&s->pb, 1, 0); /* no audio production info */ +- put_bits(&s->pb, 1, 0); /* no copyright */ +- put_bits(&s->pb, 1, 1); /* original bitstream */ ++ put_bits(&s->pb, 1, opt->audio_production_info); ++ if (opt->audio_production_info) { ++ put_bits(&s->pb, 5, opt->mixing_level - 80); ++ put_bits(&s->pb, 2, opt->room_type); ++ } ++ put_bits(&s->pb, 1, opt->copyright); ++ put_bits(&s->pb, 1, opt->original); ++ if (s->bitstream_id == 6) { ++ /* alternate bit stream syntax */ ++ put_bits(&s->pb, 1, opt->extended_bsi_1); ++ if (opt->extended_bsi_1) { ++ put_bits(&s->pb, 2, opt->preferred_stereo_downmix); ++ put_bits(&s->pb, 3, s->ltrt_center_mix_level); ++ put_bits(&s->pb, 3, s->ltrt_surround_mix_level); ++ put_bits(&s->pb, 3, s->loro_center_mix_level); ++ put_bits(&s->pb, 3, s->loro_surround_mix_level); ++ } ++ put_bits(&s->pb, 1, opt->extended_bsi_2); ++ if (opt->extended_bsi_2) { ++ put_bits(&s->pb, 2, opt->dolby_surround_ex_mode); ++ put_bits(&s->pb, 2, opt->dolby_headphone_mode); ++ put_bits(&s->pb, 1, opt->ad_converter_type); ++ put_bits(&s->pb, 9, 0); /* xbsi2 and encinfo : reserved */ ++ } ++ } else { + put_bits(&s->pb, 1, 0); /* no time code 1 */ + put_bits(&s->pb, 1, 0); /* no time code 2 */ ++ } + put_bits(&s->pb, 1, 0); /* no additional bit stream info */ + } + + +-/** ++/* + * Write one audio block to the output bitstream. + */ + static void output_audio_block(AC3EncodeContext *s, int blk) + { +- int ch, i, baie, rbnd; ++ int ch, i, baie, bnd, got_cpl; ++ int av_uninit(ch0); + AC3Block *block = &s->blocks[blk]; + + /* block switching */ +- for (ch = 0; ch < s->fbw_channels; ch++) +- put_bits(&s->pb, 1, 0); ++ if (!s->eac3) { ++ for (ch = 0; ch < s->fbw_channels; ch++) ++ put_bits(&s->pb, 1, 0); ++ } + + /* dither flags */ +- for (ch = 0; ch < s->fbw_channels; ch++) +- put_bits(&s->pb, 1, 1); ++ if (!s->eac3) { ++ for (ch = 0; ch < s->fbw_channels; ch++) ++ put_bits(&s->pb, 1, 1); ++ } + + /* dynamic range codes */ + put_bits(&s->pb, 1, 0); + ++ /* spectral extension */ ++ if (s->eac3) ++ put_bits(&s->pb, 1, 0); ++ + /* channel coupling */ +- if (!blk) { +- put_bits(&s->pb, 1, 1); /* coupling strategy present */ +- put_bits(&s->pb, 1, 0); /* no coupling strategy */ +- } else { +- put_bits(&s->pb, 1, 0); /* no new coupling strategy */ ++ if (!s->eac3) ++ put_bits(&s->pb, 1, block->new_cpl_strategy); ++ if (block->new_cpl_strategy) { ++ if (!s->eac3) ++ put_bits(&s->pb, 1, block->cpl_in_use); ++ if (block->cpl_in_use) { ++ int start_sub, end_sub; ++ if (s->eac3) ++ put_bits(&s->pb, 1, 0); /* enhanced coupling */ ++ if (!s->eac3 || s->channel_mode != AC3_CHMODE_STEREO) { ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ put_bits(&s->pb, 1, block->channel_in_cpl[ch]); ++ } ++ if (s->channel_mode == AC3_CHMODE_STEREO) ++ put_bits(&s->pb, 1, 0); /* phase flags in use */ ++ start_sub = (s->start_freq[CPL_CH] - 37) / 12; ++ end_sub = (s->cpl_end_freq - 37) / 12; ++ put_bits(&s->pb, 4, start_sub); ++ put_bits(&s->pb, 4, end_sub - 3); ++ /* coupling band structure */ ++ if (s->eac3) { ++ put_bits(&s->pb, 1, 0); /* use default */ ++ } else { ++ for (bnd = start_sub+1; bnd < end_sub; bnd++) ++ put_bits(&s->pb, 1, ff_eac3_default_cpl_band_struct[bnd]); ++ } ++ } ++ } ++ ++ /* coupling coordinates */ ++ if (block->cpl_in_use) { ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (block->channel_in_cpl[ch]) { ++ if (!s->eac3 || block->new_cpl_coords[ch] != 2) ++ put_bits(&s->pb, 1, block->new_cpl_coords[ch]); ++ if (block->new_cpl_coords[ch]) { ++ put_bits(&s->pb, 2, block->cpl_master_exp[ch]); ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ put_bits(&s->pb, 4, block->cpl_coord_exp [ch][bnd]); ++ put_bits(&s->pb, 4, block->cpl_coord_mant[ch][bnd]); ++ } ++ } ++ } ++ } + } + + /* stereo rematrixing */ + if (s->channel_mode == AC3_CHMODE_STEREO) { +- put_bits(&s->pb, 1, block->new_rematrixing_strategy); ++ if (!s->eac3 || blk > 0) ++ put_bits(&s->pb, 1, block->new_rematrixing_strategy); + if (block->new_rematrixing_strategy) { + /* rematrixing flags */ +- for (rbnd = 0; rbnd < 4; rbnd++) +- put_bits(&s->pb, 1, block->rematrixing_flags[rbnd]); ++ for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) ++ put_bits(&s->pb, 1, block->rematrixing_flags[bnd]); + } + } + + /* exponent strategy */ +- for (ch = 0; ch < s->fbw_channels; ch++) +- put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); +- if (s->lfe_on) +- put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); ++ if (!s->eac3) { ++ for (ch = !block->cpl_in_use; ch <= s->fbw_channels; ch++) ++ put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); ++ if (s->lfe_on) ++ put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); ++ } + + /* bandwidth */ +- for (ch = 0; ch < s->fbw_channels; ch++) { +- if (s->exp_strategy[ch][blk] != EXP_REUSE) +- put_bits(&s->pb, 6, s->bandwidth_code[ch]); ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (s->exp_strategy[ch][blk] != EXP_REUSE && !block->channel_in_cpl[ch]) ++ put_bits(&s->pb, 6, s->bandwidth_code); + } + + /* exponents */ +- for (ch = 0; ch < s->channels; ch++) { ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { + int nb_groups; ++ int cpl = (ch == CPL_CH); + + if (s->exp_strategy[ch][blk] == EXP_REUSE) + continue; + + /* DC exponent */ +- put_bits(&s->pb, 4, block->grouped_exp[ch][0]); ++ put_bits(&s->pb, 4, block->grouped_exp[ch][0] >> cpl); + + /* exponent groups */ +- nb_groups = exponent_group_tab[s->exp_strategy[ch][blk]-1][s->nb_coefs[ch]]; ++ nb_groups = exponent_group_tab[cpl][s->exp_strategy[ch][blk]-1][block->end_freq[ch]-s->start_freq[ch]]; + for (i = 1; i <= nb_groups; i++) + put_bits(&s->pb, 7, block->grouped_exp[ch][i]); + + /* gain range info */ +- if (ch != s->lfe_channel) ++ if (ch != s->lfe_channel && !cpl) + put_bits(&s->pb, 2, 0); + } + + /* bit allocation info */ +- baie = (blk == 0); +- put_bits(&s->pb, 1, baie); +- if (baie) { +- put_bits(&s->pb, 2, s->slow_decay_code); +- put_bits(&s->pb, 2, s->fast_decay_code); +- put_bits(&s->pb, 2, s->slow_gain_code); +- put_bits(&s->pb, 2, s->db_per_bit_code); +- put_bits(&s->pb, 3, s->floor_code); ++ if (!s->eac3) { ++ baie = (blk == 0); ++ put_bits(&s->pb, 1, baie); ++ if (baie) { ++ put_bits(&s->pb, 2, s->slow_decay_code); ++ put_bits(&s->pb, 2, s->fast_decay_code); ++ put_bits(&s->pb, 2, s->slow_gain_code); ++ put_bits(&s->pb, 2, s->db_per_bit_code); ++ put_bits(&s->pb, 3, s->floor_code); ++ } + } + + /* snr offset */ +- put_bits(&s->pb, 1, baie); +- if (baie) { +- put_bits(&s->pb, 6, s->coarse_snr_offset); +- for (ch = 0; ch < s->channels; ch++) { +- put_bits(&s->pb, 4, s->fine_snr_offset[ch]); +- put_bits(&s->pb, 3, s->fast_gain_code[ch]); ++ if (!s->eac3) { ++ put_bits(&s->pb, 1, block->new_snr_offsets); ++ if (block->new_snr_offsets) { ++ put_bits(&s->pb, 6, s->coarse_snr_offset); ++ for (ch = !block->cpl_in_use; ch <= s->channels; ch++) { ++ put_bits(&s->pb, 4, s->fine_snr_offset[ch]); ++ put_bits(&s->pb, 3, s->fast_gain_code[ch]); ++ } ++ } ++ } else { ++ put_bits(&s->pb, 1, 0); /* no converter snr offset */ ++ } ++ ++ /* coupling leak */ ++ if (block->cpl_in_use) { ++ if (!s->eac3 || block->new_cpl_leak != 2) ++ put_bits(&s->pb, 1, block->new_cpl_leak); ++ if (block->new_cpl_leak) { ++ put_bits(&s->pb, 3, s->bit_alloc.cpl_fast_leak); ++ put_bits(&s->pb, 3, s->bit_alloc.cpl_slow_leak); + } + } + +- put_bits(&s->pb, 1, 0); /* no delta bit allocation */ +- put_bits(&s->pb, 1, 0); /* no data to skip */ ++ if (!s->eac3) { ++ put_bits(&s->pb, 1, 0); /* no delta bit allocation */ ++ put_bits(&s->pb, 1, 0); /* no data to skip */ ++ } + + /* mantissas */ +- for (ch = 0; ch < s->channels; ch++) { ++ got_cpl = !block->cpl_in_use; ++ for (ch = 1; ch <= s->channels; ch++) { + int b, q; +- for (i = 0; i < s->nb_coefs[ch]; i++) { ++ ++ if (!got_cpl && ch > 1 && block->channel_in_cpl[ch-1]) { ++ ch0 = ch - 1; ++ ch = CPL_CH; ++ got_cpl = 1; ++ } ++ for (i = s->start_freq[ch]; i < block->end_freq[ch]; i++) { + q = block->qmant[ch][i]; +- b = block->bap[ch][i]; ++ b = s->ref_bap[ch][blk][i]; + switch (b) { +- case 0: break; +- case 1: if (q != 128) put_bits(&s->pb, 5, q); break; +- case 2: if (q != 128) put_bits(&s->pb, 7, q); break; +- case 3: put_bits(&s->pb, 3, q); break; +- case 4: if (q != 128) put_bits(&s->pb, 7, q); break; +- case 14: put_bits(&s->pb, 14, q); break; +- case 15: put_bits(&s->pb, 16, q); break; +- default: put_bits(&s->pb, b-1, q); break; ++ case 0: break; ++ case 1: if (q != 128) put_bits (&s->pb, 5, q); break; ++ case 2: if (q != 128) put_bits (&s->pb, 7, q); break; ++ case 3: put_sbits(&s->pb, 3, q); break; ++ case 4: if (q != 128) put_bits (&s->pb, 7, q); break; ++ case 14: put_sbits(&s->pb, 14, q); break; ++ case 15: put_sbits(&s->pb, 16, q); break; ++ default: put_sbits(&s->pb, b-1, q); break; + } + } ++ if (ch == CPL_CH) ++ ch = ch0; + } + } + +@@ -1444,7 +1606,7 @@ + } + + +-/** ++/* + * Fill the end of the frame with 0's and compute the two CRCs. + */ + static void output_frame_end(AC3EncodeContext *s) +@@ -1456,13 +1618,18 @@ + frame_size_58 = ((s->frame_size >> 2) + (s->frame_size >> 4)) << 1; + + /* pad the remainder of the frame with zeros */ ++ av_assert2(s->frame_size * 8 - put_bits_count(&s->pb) >= 18); + flush_put_bits(&s->pb); + frame = s->pb.buf; + pad_bytes = s->frame_size - (put_bits_ptr(&s->pb) - frame) - 2; +- assert(pad_bytes >= 0); ++ av_assert2(pad_bytes >= 0); + if (pad_bytes > 0) + memset(put_bits_ptr(&s->pb), 0, pad_bytes); + ++ if (s->eac3) { ++ /* compute crc2 */ ++ crc2_partial = av_crc(crc_ctx, 0, frame + 2, s->frame_size - 5); ++ } else { + /* compute crc1 */ + /* this is not so easy because it is at the beginning of the data... */ + crc1 = av_bswap16(av_crc(crc_ctx, 0, frame + 4, frame_size_58 - 4)); +@@ -1473,6 +1640,7 @@ + /* compute crc2 */ + crc2_partial = av_crc(crc_ctx, 0, frame + frame_size_58, + s->frame_size - frame_size_58 - 3); ++ } + crc2 = av_crc(crc_ctx, crc2_partial, frame + s->frame_size - 3, 1); + /* ensure crc2 does not match sync word by flipping crcrsv bit if needed */ + if (crc2 == 0x770B) { +@@ -1486,69 +1654,372 @@ + + /** + * Write the frame to the output bitstream. ++ * ++ * @param s AC-3 encoder private context ++ * @param frame output data buffer + */ +-static void output_frame(AC3EncodeContext *s, unsigned char *frame) ++void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame) + { + int blk; + + init_put_bits(&s->pb, frame, AC3_MAX_CODED_FRAME_SIZE); + +- output_frame_header(s); ++ s->output_frame_header(s); + +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) ++ for (blk = 0; blk < s->num_blocks; blk++) + output_audio_block(s, blk); + + output_frame_end(s); + } + + +-/** +- * Encode a single AC-3 frame. +- */ +-static int ac3_encode_frame(AVCodecContext *avctx, unsigned char *frame, +- int buf_size, void *data) ++static void dprint_options(AC3EncodeContext *s) + { +- AC3EncodeContext *s = avctx->priv_data; +- const SampleType *samples = data; +- int ret; ++#ifdef DEBUG ++ AVCodecContext *avctx = s->avctx; ++ AC3EncOptions *opt = &s->options; ++ char strbuf[32]; ++ ++ switch (s->bitstream_id) { ++ case 6: av_strlcpy(strbuf, "AC-3 (alt syntax)", 32); break; ++ case 8: av_strlcpy(strbuf, "AC-3 (standard)", 32); break; ++ case 9: av_strlcpy(strbuf, "AC-3 (dnet half-rate)", 32); break; ++ case 10: av_strlcpy(strbuf, "AC-3 (dnet quater-rate)", 32); break; ++ case 16: av_strlcpy(strbuf, "E-AC-3 (enhanced)", 32); break; ++ default: snprintf(strbuf, 32, "ERROR"); ++ } ++ av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id); ++ av_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt)); ++ av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout); ++ av_dlog(avctx, "channel_layout: %s\n", strbuf); ++ av_dlog(avctx, "sample_rate: %d\n", s->sample_rate); ++ av_dlog(avctx, "bit_rate: %d\n", s->bit_rate); ++ av_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code); ++ if (s->cutoff) ++ av_dlog(avctx, "cutoff: %d\n", s->cutoff); ++ ++ av_dlog(avctx, "per_frame_metadata: %s\n", ++ opt->allow_per_frame_metadata?"on":"off"); ++ if (s->has_center) ++ av_dlog(avctx, "center_mixlev: %0.3f (%d)\n", opt->center_mix_level, ++ s->center_mix_level); ++ else ++ av_dlog(avctx, "center_mixlev: {not written}\n"); ++ if (s->has_surround) ++ av_dlog(avctx, "surround_mixlev: %0.3f (%d)\n", opt->surround_mix_level, ++ s->surround_mix_level); ++ else ++ av_dlog(avctx, "surround_mixlev: {not written}\n"); ++ if (opt->audio_production_info) { ++ av_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level); ++ switch (opt->room_type) { ++ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break; ++ case AC3ENC_OPT_LARGE_ROOM: av_strlcpy(strbuf, "large", 32); break; ++ case AC3ENC_OPT_SMALL_ROOM: av_strlcpy(strbuf, "small", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type); ++ } ++ av_dlog(avctx, "room_type: %s\n", strbuf); ++ } else { ++ av_dlog(avctx, "mixing_level: {not written}\n"); ++ av_dlog(avctx, "room_type: {not written}\n"); ++ } ++ av_dlog(avctx, "copyright: %s\n", opt->copyright?"on":"off"); ++ av_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level); ++ if (s->channel_mode == AC3_CHMODE_STEREO) { ++ switch (opt->dolby_surround_mode) { ++ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break; ++ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break; ++ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode); ++ } ++ av_dlog(avctx, "dsur_mode: %s\n", strbuf); ++ } else { ++ av_dlog(avctx, "dsur_mode: {not written}\n"); ++ } ++ av_dlog(avctx, "original: %s\n", opt->original?"on":"off"); + +- if (s->bit_alloc.sr_code == 1) +- adjust_frame_size(s); ++ if (s->bitstream_id == 6) { ++ if (opt->extended_bsi_1) { ++ switch (opt->preferred_stereo_downmix) { ++ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break; ++ case AC3ENC_OPT_DOWNMIX_LTRT: av_strlcpy(strbuf, "ltrt", 32); break; ++ case AC3ENC_OPT_DOWNMIX_LORO: av_strlcpy(strbuf, "loro", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->preferred_stereo_downmix); ++ } ++ av_dlog(avctx, "dmix_mode: %s\n", strbuf); ++ av_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n", ++ opt->ltrt_center_mix_level, s->ltrt_center_mix_level); ++ av_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n", ++ opt->ltrt_surround_mix_level, s->ltrt_surround_mix_level); ++ av_dlog(avctx, "loro_cmixlev: %0.3f (%d)\n", ++ opt->loro_center_mix_level, s->loro_center_mix_level); ++ av_dlog(avctx, "loro_surmixlev: %0.3f (%d)\n", ++ opt->loro_surround_mix_level, s->loro_surround_mix_level); ++ } else { ++ av_dlog(avctx, "extended bitstream info 1: {not written}\n"); ++ } ++ if (opt->extended_bsi_2) { ++ switch (opt->dolby_surround_ex_mode) { ++ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break; ++ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break; ++ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_ex_mode); ++ } ++ av_dlog(avctx, "dsurex_mode: %s\n", strbuf); ++ switch (opt->dolby_headphone_mode) { ++ case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break; ++ case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break; ++ case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_headphone_mode); ++ } ++ av_dlog(avctx, "dheadphone_mode: %s\n", strbuf); + +- deinterleave_input_samples(s, samples); ++ switch (opt->ad_converter_type) { ++ case AC3ENC_OPT_ADCONV_STANDARD: av_strlcpy(strbuf, "standard", 32); break; ++ case AC3ENC_OPT_ADCONV_HDCD: av_strlcpy(strbuf, "hdcd", 32); break; ++ default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type); ++ } ++ av_dlog(avctx, "ad_conv_type: %s\n", strbuf); ++ } else { ++ av_dlog(avctx, "extended bitstream info 2: {not written}\n"); ++ } ++ } ++#endif ++} + +- apply_mdct(s); + +- compute_rematrixing_strategy(s); ++#define FLT_OPTION_THRESHOLD 0.01 ++ ++static int validate_float_option(float v, const float *v_list, int v_list_size) ++{ ++ int i; + +- scale_coefficients(s); ++ for (i = 0; i < v_list_size; i++) { ++ if (v < (v_list[i] + FLT_OPTION_THRESHOLD) && ++ v > (v_list[i] - FLT_OPTION_THRESHOLD)) ++ break; ++ } ++ if (i == v_list_size) ++ return -1; + +- apply_rematrixing(s); ++ return i; ++} + +- process_exponents(s); + +- ret = compute_bit_allocation(s); +- if (ret) { +- av_log(avctx, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); +- return ret; ++static void validate_mix_level(void *log_ctx, const char *opt_name, ++ float *opt_param, const float *list, ++ int list_size, int default_value, int min_value, ++ int *ctx_param) ++{ ++ int mixlev = validate_float_option(*opt_param, list, list_size); ++ if (mixlev < min_value) { ++ mixlev = default_value; ++ if (*opt_param >= 0.0) { ++ av_log(log_ctx, AV_LOG_WARNING, "requested %s is not valid. using " ++ "default value: %0.3f\n", opt_name, list[mixlev]); ++ } + } ++ *opt_param = list[mixlev]; ++ *ctx_param = mixlev; ++} + +- quantize_mantissas(s); + +- output_frame(s, frame); ++/** ++ * Validate metadata options as set by AVOption system. ++ * These values can optionally be changed per-frame. ++ * ++ * @param s AC-3 encoder private context ++ */ ++int ff_ac3_validate_metadata(AC3EncodeContext *s) ++{ ++ AVCodecContext *avctx = s->avctx; ++ AC3EncOptions *opt = &s->options; ++ ++ opt->audio_production_info = 0; ++ opt->extended_bsi_1 = 0; ++ opt->extended_bsi_2 = 0; ++ opt->eac3_mixing_metadata = 0; ++ opt->eac3_info_metadata = 0; ++ ++ /* determine mixing metadata / xbsi1 use */ ++ if (s->channel_mode > AC3_CHMODE_STEREO && opt->preferred_stereo_downmix != AC3ENC_OPT_NONE) { ++ opt->extended_bsi_1 = 1; ++ opt->eac3_mixing_metadata = 1; ++ } ++ if (s->has_center && ++ (opt->ltrt_center_mix_level >= 0 || opt->loro_center_mix_level >= 0)) { ++ opt->extended_bsi_1 = 1; ++ opt->eac3_mixing_metadata = 1; ++ } ++ if (s->has_surround && ++ (opt->ltrt_surround_mix_level >= 0 || opt->loro_surround_mix_level >= 0)) { ++ opt->extended_bsi_1 = 1; ++ opt->eac3_mixing_metadata = 1; ++ } + +- return s->frame_size; ++ if (s->eac3) { ++ /* determine info metadata use */ ++ if (avctx->audio_service_type != AV_AUDIO_SERVICE_TYPE_MAIN) ++ opt->eac3_info_metadata = 1; ++ if (opt->copyright != AC3ENC_OPT_NONE || opt->original != AC3ENC_OPT_NONE) ++ opt->eac3_info_metadata = 1; ++ if (s->channel_mode == AC3_CHMODE_STEREO && ++ (opt->dolby_headphone_mode != AC3ENC_OPT_NONE || opt->dolby_surround_mode != AC3ENC_OPT_NONE)) ++ opt->eac3_info_metadata = 1; ++ if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode != AC3ENC_OPT_NONE) ++ opt->eac3_info_metadata = 1; ++ if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != AC3ENC_OPT_NONE || ++ opt->ad_converter_type != AC3ENC_OPT_NONE) { ++ opt->audio_production_info = 1; ++ opt->eac3_info_metadata = 1; ++ } ++ } else { ++ /* determine audio production info use */ ++ if (opt->mixing_level != AC3ENC_OPT_NONE || opt->room_type != AC3ENC_OPT_NONE) ++ opt->audio_production_info = 1; ++ ++ /* determine xbsi2 use */ ++ if (s->channel_mode >= AC3_CHMODE_2F2R && opt->dolby_surround_ex_mode != AC3ENC_OPT_NONE) ++ opt->extended_bsi_2 = 1; ++ if (s->channel_mode == AC3_CHMODE_STEREO && opt->dolby_headphone_mode != AC3ENC_OPT_NONE) ++ opt->extended_bsi_2 = 1; ++ if (opt->ad_converter_type != AC3ENC_OPT_NONE) ++ opt->extended_bsi_2 = 1; ++ } ++ ++ /* validate AC-3 mixing levels */ ++ if (!s->eac3) { ++ if (s->has_center) { ++ validate_mix_level(avctx, "center_mix_level", &opt->center_mix_level, ++ cmixlev_options, CMIXLEV_NUM_OPTIONS, 1, 0, ++ &s->center_mix_level); ++ } ++ if (s->has_surround) { ++ validate_mix_level(avctx, "surround_mix_level", &opt->surround_mix_level, ++ surmixlev_options, SURMIXLEV_NUM_OPTIONS, 1, 0, ++ &s->surround_mix_level); ++ } ++ } ++ ++ /* validate extended bsi 1 / mixing metadata */ ++ if (opt->extended_bsi_1 || opt->eac3_mixing_metadata) { ++ /* default preferred stereo downmix */ ++ if (opt->preferred_stereo_downmix == AC3ENC_OPT_NONE) ++ opt->preferred_stereo_downmix = AC3ENC_OPT_NOT_INDICATED; ++ if (!s->eac3 || s->has_center) { ++ /* validate Lt/Rt center mix level */ ++ validate_mix_level(avctx, "ltrt_center_mix_level", ++ &opt->ltrt_center_mix_level, extmixlev_options, ++ EXTMIXLEV_NUM_OPTIONS, 5, 0, ++ &s->ltrt_center_mix_level); ++ /* validate Lo/Ro center mix level */ ++ validate_mix_level(avctx, "loro_center_mix_level", ++ &opt->loro_center_mix_level, extmixlev_options, ++ EXTMIXLEV_NUM_OPTIONS, 5, 0, ++ &s->loro_center_mix_level); ++ } ++ if (!s->eac3 || s->has_surround) { ++ /* validate Lt/Rt surround mix level */ ++ validate_mix_level(avctx, "ltrt_surround_mix_level", ++ &opt->ltrt_surround_mix_level, extmixlev_options, ++ EXTMIXLEV_NUM_OPTIONS, 6, 3, ++ &s->ltrt_surround_mix_level); ++ /* validate Lo/Ro surround mix level */ ++ validate_mix_level(avctx, "loro_surround_mix_level", ++ &opt->loro_surround_mix_level, extmixlev_options, ++ EXTMIXLEV_NUM_OPTIONS, 6, 3, ++ &s->loro_surround_mix_level); ++ } ++ } ++ ++ /* validate audio service type / channels combination */ ++ if ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_KARAOKE && ++ avctx->channels == 1) || ++ ((avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_COMMENTARY || ++ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_EMERGENCY || ++ avctx->audio_service_type == AV_AUDIO_SERVICE_TYPE_VOICE_OVER) ++ && avctx->channels > 1)) { ++ av_log(avctx, AV_LOG_ERROR, "invalid audio service type for the " ++ "specified number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ /* validate extended bsi 2 / info metadata */ ++ if (opt->extended_bsi_2 || opt->eac3_info_metadata) { ++ /* default dolby headphone mode */ ++ if (opt->dolby_headphone_mode == AC3ENC_OPT_NONE) ++ opt->dolby_headphone_mode = AC3ENC_OPT_NOT_INDICATED; ++ /* default dolby surround ex mode */ ++ if (opt->dolby_surround_ex_mode == AC3ENC_OPT_NONE) ++ opt->dolby_surround_ex_mode = AC3ENC_OPT_NOT_INDICATED; ++ /* default A/D converter type */ ++ if (opt->ad_converter_type == AC3ENC_OPT_NONE) ++ opt->ad_converter_type = AC3ENC_OPT_ADCONV_STANDARD; ++ } ++ ++ /* copyright & original defaults */ ++ if (!s->eac3 || opt->eac3_info_metadata) { ++ /* default copyright */ ++ if (opt->copyright == AC3ENC_OPT_NONE) ++ opt->copyright = AC3ENC_OPT_OFF; ++ /* default original */ ++ if (opt->original == AC3ENC_OPT_NONE) ++ opt->original = AC3ENC_OPT_ON; ++ } ++ ++ /* dolby surround mode default */ ++ if (!s->eac3 || opt->eac3_info_metadata) { ++ if (opt->dolby_surround_mode == AC3ENC_OPT_NONE) ++ opt->dolby_surround_mode = AC3ENC_OPT_NOT_INDICATED; ++ } ++ ++ /* validate audio production info */ ++ if (opt->audio_production_info) { ++ if (opt->mixing_level == AC3ENC_OPT_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "mixing_level must be set if " ++ "room_type is set\n"); ++ return AVERROR(EINVAL); ++ } ++ if (opt->mixing_level < 80) { ++ av_log(avctx, AV_LOG_ERROR, "invalid mixing level. must be between " ++ "80dB and 111dB\n"); ++ return AVERROR(EINVAL); ++ } ++ /* default room type */ ++ if (opt->room_type == AC3ENC_OPT_NONE) ++ opt->room_type = AC3ENC_OPT_NOT_INDICATED; ++ } ++ ++ /* set bitstream id for alternate bitstream syntax */ ++ if (!s->eac3 && (opt->extended_bsi_1 || opt->extended_bsi_2)) { ++ if (s->bitstream_id > 8 && s->bitstream_id < 11) { ++ static int warn_once = 1; ++ if (warn_once) { ++ av_log(avctx, AV_LOG_WARNING, "alternate bitstream syntax is " ++ "not compatible with reduced samplerates. writing of " ++ "extended bitstream information will be disabled.\n"); ++ warn_once = 0; ++ } ++ } else { ++ s->bitstream_id = 6; ++ } ++ } ++ ++ return 0; + } + + + /** + * Finalize encoding and free any memory allocated by the encoder. ++ * ++ * @param avctx Codec context + */ +-static av_cold int ac3_encode_close(AVCodecContext *avctx) ++av_cold int ff_ac3_encode_close(AVCodecContext *avctx) + { + int blk, ch; + AC3EncodeContext *s = avctx->priv_data; + ++ av_freep(&s->windowed_samples); + for (ch = 0; ch < s->channels; ch++) + av_freep(&s->planar_samples[ch]); + av_freep(&s->planar_samples); +@@ -1562,9 +2033,10 @@ + av_freep(&s->band_psd_buffer); + av_freep(&s->mask_buffer); + av_freep(&s->qmant_buffer); +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ av_freep(&s->cpl_coord_exp_buffer); ++ av_freep(&s->cpl_coord_mant_buffer); ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- av_freep(&block->bap); + av_freep(&block->mdct_coef); + av_freep(&block->fixed_coef); + av_freep(&block->exp); +@@ -1573,37 +2045,37 @@ + av_freep(&block->band_psd); + av_freep(&block->mask); + av_freep(&block->qmant); ++ av_freep(&block->cpl_coord_exp); ++ av_freep(&block->cpl_coord_mant); + } + +- mdct_end(&s->mdct); ++ s->mdct_end(s); + + av_freep(&avctx->coded_frame); + return 0; + } + + +-/** ++/* + * Set channel information during initialization. + */ + static av_cold int set_channel_info(AC3EncodeContext *s, int channels, +- int64_t *channel_layout) ++ uint64_t *channel_layout) + { + int ch_layout; + + if (channels < 1 || channels > AC3_MAX_CHANNELS) + return AVERROR(EINVAL); +- if ((uint64_t)*channel_layout > 0x7FF) ++ if (*channel_layout > 0x7FF) + return AVERROR(EINVAL); + ch_layout = *channel_layout; + if (!ch_layout) + ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL); +- if (av_get_channel_layout_nb_channels(ch_layout) != channels) +- return AVERROR(EINVAL); + + s->lfe_on = !!(ch_layout & AV_CH_LOW_FREQUENCY); + s->channels = channels; + s->fbw_channels = channels - s->lfe_on; +- s->lfe_channel = s->lfe_on ? s->fbw_channels : -1; ++ s->lfe_channel = s->lfe_on ? s->fbw_channels + 1 : -1; + if (s->lfe_on) + ch_layout -= AV_CH_LOW_FREQUENCY; + +@@ -1620,6 +2092,8 @@ + default: + return AVERROR(EINVAL); + } ++ s->has_center = (s->channel_mode & 0x01) && s->channel_mode != AC3_CHMODE_MONO; ++ s->has_surround = s->channel_mode & 0x04; + + s->channel_map = ff_ac3_enc_channel_map[s->channel_mode][s->lfe_on]; + *channel_layout = ch_layout; +@@ -1630,9 +2104,10 @@ + } + + +-static av_cold int validate_options(AVCodecContext *avctx, AC3EncodeContext *s) ++static av_cold int validate_options(AC3EncodeContext *s) + { +- int i, ret; ++ AVCodecContext *avctx = s->avctx; ++ int i, ret, max_sr; + + /* validate channel layout */ + if (!avctx->channel_layout) { +@@ -1647,29 +2122,86 @@ + } + + /* validate sample rate */ +- for (i = 0; i < 9; i++) { +- if ((ff_ac3_sample_rate_tab[i / 3] >> (i % 3)) == avctx->sample_rate) ++ /* note: max_sr could be changed from 2 to 5 for E-AC-3 once we find a ++ decoder that supports half sample rate so we can validate that ++ the generated files are correct. */ ++ max_sr = s->eac3 ? 2 : 8; ++ for (i = 0; i <= max_sr; i++) { ++ if ((ff_ac3_sample_rate_tab[i % 3] >> (i / 3)) == avctx->sample_rate) + break; + } +- if (i == 9) { ++ if (i > max_sr) { + av_log(avctx, AV_LOG_ERROR, "invalid sample rate\n"); + return AVERROR(EINVAL); + } + s->sample_rate = avctx->sample_rate; +- s->bit_alloc.sr_shift = i % 3; +- s->bit_alloc.sr_code = i / 3; ++ s->bit_alloc.sr_shift = i / 3; ++ s->bit_alloc.sr_code = i % 3; ++ s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift; + + /* validate bit rate */ +- for (i = 0; i < 19; i++) { +- if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) +- break; +- } +- if (i == 19) { +- av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n"); +- return AVERROR(EINVAL); ++ if (s->eac3) { ++ int max_br, min_br, wpf, min_br_dist, min_br_code; ++ int num_blks_code, num_blocks, frame_samples; ++ ++ /* calculate min/max bitrate */ ++ /* TODO: More testing with 3 and 2 blocks. All E-AC-3 samples I've ++ found use either 6 blocks or 1 block, even though 2 or 3 blocks ++ would work as far as the bit rate is concerned. */ ++ for (num_blks_code = 3; num_blks_code >= 0; num_blks_code--) { ++ num_blocks = ((int[]){ 1, 2, 3, 6 })[num_blks_code]; ++ frame_samples = AC3_BLOCK_SIZE * num_blocks; ++ max_br = 2048 * s->sample_rate / frame_samples * 16; ++ min_br = ((s->sample_rate + (frame_samples-1)) / frame_samples) * 16; ++ if (avctx->bit_rate <= max_br) ++ break; ++ } ++ if (avctx->bit_rate < min_br || avctx->bit_rate > max_br) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bit rate. must be %d to %d " ++ "for this sample rate\n", min_br, max_br); ++ return AVERROR(EINVAL); ++ } ++ s->num_blks_code = num_blks_code; ++ s->num_blocks = num_blocks; ++ ++ /* calculate words-per-frame for the selected bitrate */ ++ wpf = (avctx->bit_rate / 16) * frame_samples / s->sample_rate; ++ av_assert1(wpf > 0 && wpf <= 2048); ++ ++ /* find the closest AC-3 bitrate code to the selected bitrate. ++ this is needed for lookup tables for bandwidth and coupling ++ parameter selection */ ++ min_br_code = -1; ++ min_br_dist = INT_MAX; ++ for (i = 0; i < 19; i++) { ++ int br_dist = abs(ff_ac3_bitrate_tab[i] * 1000 - avctx->bit_rate); ++ if (br_dist < min_br_dist) { ++ min_br_dist = br_dist; ++ min_br_code = i; ++ } ++ } ++ ++ /* make sure the minimum frame size is below the average frame size */ ++ s->frame_size_code = min_br_code << 1; ++ while (wpf > 1 && wpf * s->sample_rate / AC3_FRAME_SIZE * 16 > avctx->bit_rate) ++ wpf--; ++ s->frame_size_min = 2 * wpf; ++ } else { ++ for (i = 0; i < 19; i++) { ++ if ((ff_ac3_bitrate_tab[i] >> s->bit_alloc.sr_shift)*1000 == avctx->bit_rate) ++ break; ++ } ++ if (i == 19) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bit rate\n"); ++ return AVERROR(EINVAL); ++ } ++ s->frame_size_code = i << 1; ++ s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; ++ s->num_blks_code = 0x3; ++ s->num_blocks = 6; + } +- s->bit_rate = avctx->bit_rate; +- s->frame_size_code = i << 1; ++ s->bit_rate = avctx->bit_rate; ++ s->frame_size = s->frame_size_min; + + /* validate cutoff */ + if (avctx->cutoff < 0) { +@@ -1680,121 +2212,188 @@ + if (s->cutoff > (s->sample_rate >> 1)) + s->cutoff = s->sample_rate >> 1; + ++ ret = ff_ac3_validate_metadata(s); ++ if (ret) ++ return ret; ++ ++ s->rematrixing_enabled = s->options.stereo_rematrixing && ++ (s->channel_mode == AC3_CHMODE_STEREO); ++ ++ s->cpl_enabled = s->options.channel_coupling && ++ s->channel_mode >= AC3_CHMODE_STEREO; ++ + return 0; + } + + +-/** ++/* + * Set bandwidth for all channels. + * The user can optionally supply a cutoff frequency. Otherwise an appropriate + * default value will be used. + */ + static av_cold void set_bandwidth(AC3EncodeContext *s) + { +- int ch, bw_code; ++ int blk, ch; ++ int av_uninit(cpl_start); + + if (s->cutoff) { + /* calculate bandwidth based on user-specified cutoff frequency */ + int fbw_coeffs; + fbw_coeffs = s->cutoff * 2 * AC3_MAX_COEFS / s->sample_rate; +- bw_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); ++ s->bandwidth_code = av_clip((fbw_coeffs - 73) / 3, 0, 60); + } else { + /* use default bandwidth setting */ +- /* XXX: should compute the bandwidth according to the frame +- size, so that we avoid annoying high frequency artifacts */ +- bw_code = 50; ++ s->bandwidth_code = ac3_bandwidth_tab[s->fbw_channels-1][s->bit_alloc.sr_code][s->frame_size_code/2]; + } + + /* set number of coefficients for each channel */ +- for (ch = 0; ch < s->fbw_channels; ch++) { +- s->bandwidth_code[ch] = bw_code; +- s->nb_coefs[ch] = bw_code * 3 + 73; ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ s->start_freq[ch] = 0; ++ for (blk = 0; blk < s->num_blocks; blk++) ++ s->blocks[blk].end_freq[ch] = s->bandwidth_code * 3 + 73; ++ } ++ /* LFE channel always has 7 coefs */ ++ if (s->lfe_on) { ++ s->start_freq[s->lfe_channel] = 0; ++ for (blk = 0; blk < s->num_blocks; blk++) ++ s->blocks[blk].end_freq[ch] = 7; ++ } ++ ++ /* initialize coupling strategy */ ++ if (s->cpl_enabled) { ++ if (s->options.cpl_start != AC3ENC_OPT_AUTO) { ++ cpl_start = s->options.cpl_start; ++ } else { ++ cpl_start = ac3_coupling_start_tab[s->channel_mode-2][s->bit_alloc.sr_code][s->frame_size_code/2]; ++ if (cpl_start < 0) { ++ if (s->options.channel_coupling == AC3ENC_OPT_AUTO) ++ s->cpl_enabled = 0; ++ else ++ cpl_start = 15; ++ } ++ } ++ } ++ if (s->cpl_enabled) { ++ int i, cpl_start_band, cpl_end_band; ++ uint8_t *cpl_band_sizes = s->cpl_band_sizes; ++ ++ cpl_end_band = s->bandwidth_code / 4 + 3; ++ cpl_start_band = av_clip(cpl_start, 0, FFMIN(cpl_end_band-1, 15)); ++ ++ s->num_cpl_subbands = cpl_end_band - cpl_start_band; ++ ++ s->num_cpl_bands = 1; ++ *cpl_band_sizes = 12; ++ for (i = cpl_start_band + 1; i < cpl_end_band; i++) { ++ if (ff_eac3_default_cpl_band_struct[i]) { ++ *cpl_band_sizes += 12; ++ } else { ++ s->num_cpl_bands++; ++ cpl_band_sizes++; ++ *cpl_band_sizes = 12; ++ } ++ } ++ ++ s->start_freq[CPL_CH] = cpl_start_band * 12 + 37; ++ s->cpl_end_freq = cpl_end_band * 12 + 37; ++ for (blk = 0; blk < s->num_blocks; blk++) ++ s->blocks[blk].end_freq[CPL_CH] = s->cpl_end_freq; + } +- if (s->lfe_on) +- s->nb_coefs[s->lfe_channel] = 7; /* LFE channel always has 7 coefs */ + } + + +-static av_cold int allocate_buffers(AVCodecContext *avctx) ++static av_cold int allocate_buffers(AC3EncodeContext *s) + { ++ AVCodecContext *avctx = s->avctx; + int blk, ch; +- AC3EncodeContext *s = avctx->priv_data; +- +- FF_ALLOC_OR_GOTO(avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), +- alloc_fail); +- for (ch = 0; ch < s->channels; ch++) { +- FF_ALLOCZ_OR_GOTO(avctx, s->planar_samples[ch], +- (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), +- alloc_fail); ++ int channels = s->channels + 1; /* includes coupling channel */ ++ int channel_blocks = channels * s->num_blocks; ++ int total_coefs = AC3_MAX_COEFS * channel_blocks; ++ ++ if (s->allocate_sample_buffers(s)) ++ goto alloc_fail; ++ ++ FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, total_coefs * ++ sizeof(*s->bap_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, total_coefs * ++ sizeof(*s->bap1_buffer), alloc_fail); ++ FF_ALLOCZ_OR_GOTO(avctx, s->mdct_coef_buffer, total_coefs * ++ sizeof(*s->mdct_coef_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->exp_buffer, total_coefs * ++ sizeof(*s->exp_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->grouped_exp_buffer, channel_blocks * 128 * ++ sizeof(*s->grouped_exp_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->psd_buffer, total_coefs * ++ sizeof(*s->psd_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->band_psd_buffer, channel_blocks * 64 * ++ sizeof(*s->band_psd_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->mask_buffer, channel_blocks * 64 * ++ sizeof(*s->mask_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->qmant_buffer, total_coefs * ++ sizeof(*s->qmant_buffer), alloc_fail); ++ if (s->cpl_enabled) { ++ FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_exp_buffer, channel_blocks * 16 * ++ sizeof(*s->cpl_coord_exp_buffer), alloc_fail); ++ FF_ALLOC_OR_GOTO(avctx, s->cpl_coord_mant_buffer, channel_blocks * 16 * ++ sizeof(*s->cpl_coord_mant_buffer), alloc_fail); + } +- FF_ALLOC_OR_GOTO(avctx, s->bap_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->bap_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->bap1_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->bap1_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->mdct_coef_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->mdct_coef_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->exp_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->exp_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->grouped_exp_buffer, AC3_MAX_BLOCKS * s->channels * +- 128 * sizeof(*s->grouped_exp_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->psd_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->psd_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->band_psd_buffer, AC3_MAX_BLOCKS * s->channels * +- 64 * sizeof(*s->band_psd_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->mask_buffer, AC3_MAX_BLOCKS * s->channels * +- 64 * sizeof(*s->mask_buffer), alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, s->qmant_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->qmant_buffer), alloc_fail); +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- FF_ALLOC_OR_GOTO(avctx, block->bap, s->channels * sizeof(*block->bap), +- alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->mdct_coef, s->channels * sizeof(*block->mdct_coef), ++ FF_ALLOCZ_OR_GOTO(avctx, block->mdct_coef, channels * sizeof(*block->mdct_coef), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->exp, s->channels * sizeof(*block->exp), ++ FF_ALLOCZ_OR_GOTO(avctx, block->exp, channels * sizeof(*block->exp), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->grouped_exp, s->channels * sizeof(*block->grouped_exp), ++ FF_ALLOCZ_OR_GOTO(avctx, block->grouped_exp, channels * sizeof(*block->grouped_exp), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->psd, s->channels * sizeof(*block->psd), ++ FF_ALLOCZ_OR_GOTO(avctx, block->psd, channels * sizeof(*block->psd), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->band_psd, s->channels * sizeof(*block->band_psd), ++ FF_ALLOCZ_OR_GOTO(avctx, block->band_psd, channels * sizeof(*block->band_psd), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->mask, s->channels * sizeof(*block->mask), ++ FF_ALLOCZ_OR_GOTO(avctx, block->mask, channels * sizeof(*block->mask), + alloc_fail); +- FF_ALLOCZ_OR_GOTO(avctx, block->qmant, s->channels * sizeof(*block->qmant), ++ FF_ALLOCZ_OR_GOTO(avctx, block->qmant, channels * sizeof(*block->qmant), + alloc_fail); ++ if (s->cpl_enabled) { ++ FF_ALLOCZ_OR_GOTO(avctx, block->cpl_coord_exp, channels * sizeof(*block->cpl_coord_exp), ++ alloc_fail); ++ FF_ALLOCZ_OR_GOTO(avctx, block->cpl_coord_mant, channels * sizeof(*block->cpl_coord_mant), ++ alloc_fail); ++ } + +- for (ch = 0; ch < s->channels; ch++) { ++ for (ch = 0; ch < channels; ch++) { + /* arrangement: block, channel, coeff */ +- block->bap[ch] = &s->bap_buffer [AC3_MAX_COEFS * (blk * s->channels + ch)]; +- block->mdct_coef[ch] = &s->mdct_coef_buffer [AC3_MAX_COEFS * (blk * s->channels + ch)]; +- block->grouped_exp[ch] = &s->grouped_exp_buffer[128 * (blk * s->channels + ch)]; +- block->psd[ch] = &s->psd_buffer [AC3_MAX_COEFS * (blk * s->channels + ch)]; +- block->band_psd[ch] = &s->band_psd_buffer [64 * (blk * s->channels + ch)]; +- block->mask[ch] = &s->mask_buffer [64 * (blk * s->channels + ch)]; +- block->qmant[ch] = &s->qmant_buffer [AC3_MAX_COEFS * (blk * s->channels + ch)]; ++ block->grouped_exp[ch] = &s->grouped_exp_buffer[128 * (blk * channels + ch)]; ++ block->psd[ch] = &s->psd_buffer [AC3_MAX_COEFS * (blk * channels + ch)]; ++ block->band_psd[ch] = &s->band_psd_buffer [64 * (blk * channels + ch)]; ++ block->mask[ch] = &s->mask_buffer [64 * (blk * channels + ch)]; ++ block->qmant[ch] = &s->qmant_buffer [AC3_MAX_COEFS * (blk * channels + ch)]; ++ if (s->cpl_enabled) { ++ block->cpl_coord_exp[ch] = &s->cpl_coord_exp_buffer [16 * (blk * channels + ch)]; ++ block->cpl_coord_mant[ch] = &s->cpl_coord_mant_buffer[16 * (blk * channels + ch)]; ++ } + + /* arrangement: channel, block, coeff */ +- block->exp[ch] = &s->exp_buffer [AC3_MAX_COEFS * (AC3_MAX_BLOCKS * ch + blk)]; ++ block->exp[ch] = &s->exp_buffer [AC3_MAX_COEFS * (s->num_blocks * ch + blk)]; ++ block->mdct_coef[ch] = &s->mdct_coef_buffer [AC3_MAX_COEFS * (s->num_blocks * ch + blk)]; + } + } + +- if (CONFIG_AC3ENC_FLOAT) { +- FF_ALLOC_OR_GOTO(avctx, s->fixed_coef_buffer, AC3_MAX_BLOCKS * s->channels * +- AC3_MAX_COEFS * sizeof(*s->fixed_coef_buffer), alloc_fail); +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ if (!s->fixed_point) { ++ FF_ALLOCZ_OR_GOTO(avctx, s->fixed_coef_buffer, total_coefs * ++ sizeof(*s->fixed_coef_buffer), alloc_fail); ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, s->channels * ++ FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, channels * + sizeof(*block->fixed_coef), alloc_fail); +- for (ch = 0; ch < s->channels; ch++) +- block->fixed_coef[ch] = &s->fixed_coef_buffer[AC3_MAX_COEFS * (blk * s->channels + ch)]; ++ for (ch = 0; ch < channels; ch++) ++ block->fixed_coef[ch] = &s->fixed_coef_buffer[AC3_MAX_COEFS * (s->num_blocks * ch + blk)]; + } + } else { +- for (blk = 0; blk < AC3_MAX_BLOCKS; blk++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { + AC3Block *block = &s->blocks[blk]; +- FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, s->channels * ++ FF_ALLOCZ_OR_GOTO(avctx, block->fixed_coef, channels * + sizeof(*block->fixed_coef), alloc_fail); +- for (ch = 0; ch < s->channels; ch++) ++ for (ch = 0; ch < channels; ch++) + block->fixed_coef[ch] = (int32_t *)block->mdct_coef[ch]; + } + } +@@ -1805,29 +2404,29 @@ + } + + +-/** +- * Initialize the encoder. +- */ +-static av_cold int ac3_encode_init(AVCodecContext *avctx) ++av_cold int ff_ac3_encode_init(AVCodecContext *avctx) + { + AC3EncodeContext *s = avctx->priv_data; + int ret, frame_size_58; + +- avctx->frame_size = AC3_FRAME_SIZE; ++ s->avctx = avctx; ++ ++ s->eac3 = avctx->codec_id == CODEC_ID_EAC3; + + ff_ac3_common_init(); + +- ret = validate_options(avctx, s); ++ ret = validate_options(s); + if (ret) + return ret; + +- s->bitstream_id = 8 + s->bit_alloc.sr_shift; +- s->bitstream_mode = 0; /* complete main audio service */ ++ avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks; ++ ++ s->bitstream_mode = avctx->audio_service_type; ++ if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE) ++ s->bitstream_mode = 0x7; + +- s->frame_size_min = 2 * ff_ac3_frame_size_tab[s->frame_size_code][s->bit_alloc.sr_code]; + s->bits_written = 0; + s->samples_written = 0; +- s->frame_size = s->frame_size_min; + + /* calculate crc_inv for both possible frame sizes */ + frame_size_58 = (( s->frame_size >> 2) + ( s->frame_size >> 4)) << 1; +@@ -1837,28 +2436,44 @@ + s->crc_inv[1] = pow_poly((CRC16_POLY >> 1), (8 * frame_size_58) - 16, CRC16_POLY); + } + +- set_bandwidth(s); ++ /* set function pointers */ ++ if (CONFIG_AC3_FIXED_ENCODER && s->fixed_point) { ++ s->mdct_end = ff_ac3_fixed_mdct_end; ++ s->mdct_init = ff_ac3_fixed_mdct_init; ++ s->allocate_sample_buffers = ff_ac3_fixed_allocate_sample_buffers; ++ } else if (CONFIG_AC3_ENCODER || CONFIG_EAC3_ENCODER) { ++ s->mdct_end = ff_ac3_float_mdct_end; ++ s->mdct_init = ff_ac3_float_mdct_init; ++ s->allocate_sample_buffers = ff_ac3_float_allocate_sample_buffers; ++ } ++ if (CONFIG_EAC3_ENCODER && s->eac3) ++ s->output_frame_header = ff_eac3_output_frame_header; ++ else ++ s->output_frame_header = ac3_output_frame_header; + +- rematrixing_init(s); ++ set_bandwidth(s); + + exponent_init(s); + + bit_alloc_init(s); + +- ret = mdct_init(avctx, &s->mdct, 9); ++ ret = s->mdct_init(s); + if (ret) + goto init_fail; + +- ret = allocate_buffers(avctx); ++ ret = allocate_buffers(s); + if (ret) + goto init_fail; + + avctx->coded_frame= avcodec_alloc_frame(); + + dsputil_init(&s->dsp, avctx); ++ ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT); ++ ++ dprint_options(s); + + return 0; + init_fail: +- ac3_encode_close(avctx); ++ ff_ac3_encode_close(avctx); + return ret; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_fixed.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_fixed.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_fixed.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_fixed.c 2012-05-14 14:08:53.340319976 +0200 +@@ -26,415 +26,135 @@ + * fixed-point AC-3 encoder. + */ + ++#define CONFIG_FFT_FLOAT 0 + #undef CONFIG_AC3ENC_FLOAT +-#include "ac3enc.c" ++#include "ac3enc.h" ++#include "eac3enc.h" + ++#define AC3ENC_TYPE AC3ENC_TYPE_AC3_FIXED ++#include "ac3enc_opts_template.c" ++static const AVClass ac3enc_class = { "Fixed-Point AC-3 Encoder", av_default_item_name, ++ ac3fixed_options, LIBAVUTIL_VERSION_INT }; + +-/** Scale a float value by 2^15, convert to an integer, and clip to range -32767..32767. */ +-#define FIX15(a) av_clip(SCALE_FLOAT(a, 15), -32767, 32767) ++#include "ac3enc_template.c" + + + /** + * Finalize MDCT and free allocated memory. ++ * ++ * @param s AC-3 encoder private context + */ +-static av_cold void mdct_end(AC3MDCTContext *mdct) +-{ +- mdct->nbits = 0; +- av_freep(&mdct->costab); +- av_freep(&mdct->sintab); +- av_freep(&mdct->xcos1); +- av_freep(&mdct->xsin1); +- av_freep(&mdct->rot_tmp); +- av_freep(&mdct->cplx_tmp); +-} +- +- +-/** +- * Initialize FFT tables. +- * @param ln log2(FFT size) +- */ +-static av_cold int fft_init(AVCodecContext *avctx, AC3MDCTContext *mdct, int ln) ++av_cold void AC3_NAME(mdct_end)(AC3EncodeContext *s) + { +- int i, n, n2; +- float alpha; +- +- n = 1 << ln; +- n2 = n >> 1; +- +- FF_ALLOC_OR_GOTO(avctx, mdct->costab, n2 * sizeof(*mdct->costab), fft_alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, mdct->sintab, n2 * sizeof(*mdct->sintab), fft_alloc_fail); +- +- for (i = 0; i < n2; i++) { +- alpha = 2.0 * M_PI * i / n; +- mdct->costab[i] = FIX15(cos(alpha)); +- mdct->sintab[i] = FIX15(sin(alpha)); +- } +- +- return 0; +-fft_alloc_fail: +- mdct_end(mdct); +- return AVERROR(ENOMEM); ++ ff_mdct_end(&s->mdct); + } + + + /** + * Initialize MDCT tables. +- * @param nbits log2(MDCT size) +- */ +-static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, +- int nbits) +-{ +- int i, n, n4, ret; +- +- n = 1 << nbits; +- n4 = n >> 2; +- +- mdct->nbits = nbits; +- +- ret = fft_init(avctx, mdct, nbits - 2); +- if (ret) +- return ret; +- +- mdct->window = ff_ac3_window; +- +- FF_ALLOC_OR_GOTO(avctx, mdct->xcos1, n4 * sizeof(*mdct->xcos1), mdct_alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, mdct->xsin1, n4 * sizeof(*mdct->xsin1), mdct_alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, mdct->rot_tmp, n * sizeof(*mdct->rot_tmp), mdct_alloc_fail); +- FF_ALLOC_OR_GOTO(avctx, mdct->cplx_tmp, n4 * sizeof(*mdct->cplx_tmp), mdct_alloc_fail); +- +- for (i = 0; i < n4; i++) { +- float alpha = 2.0 * M_PI * (i + 1.0 / 8.0) / n; +- mdct->xcos1[i] = FIX15(-cos(alpha)); +- mdct->xsin1[i] = FIX15(-sin(alpha)); +- } +- +- return 0; +-mdct_alloc_fail: +- mdct_end(mdct); +- return AVERROR(ENOMEM); +-} +- +- +-/** Butterfly op */ +-#define BF(pre, pim, qre, qim, pre1, pim1, qre1, qim1) \ +-{ \ +- int ax, ay, bx, by; \ +- bx = pre1; \ +- by = pim1; \ +- ax = qre1; \ +- ay = qim1; \ +- pre = (bx + ax) >> 1; \ +- pim = (by + ay) >> 1; \ +- qre = (bx - ax) >> 1; \ +- qim = (by - ay) >> 1; \ +-} +- +- +-/** Complex multiply */ +-#define CMUL(pre, pim, are, aim, bre, bim) \ +-{ \ +- pre = (MUL16(are, bre) - MUL16(aim, bim)) >> 15; \ +- pim = (MUL16(are, bim) + MUL16(bre, aim)) >> 15; \ +-} +- +- +-/** +- * Calculate a 2^n point complex FFT on 2^ln points. +- * @param z complex input/output samples +- * @param ln log2(FFT size) ++ * ++ * @param s AC-3 encoder private context ++ * @return 0 on success, negative error code on failure + */ +-static void fft(AC3MDCTContext *mdct, IComplex *z, int ln) ++av_cold int AC3_NAME(mdct_init)(AC3EncodeContext *s) + { +- int j, l, np, np2; +- int nblocks, nloops; +- register IComplex *p,*q; +- int tmp_re, tmp_im; +- +- np = 1 << ln; +- +- /* reverse */ +- for (j = 0; j < np; j++) { +- int k = av_reverse[j] >> (8 - ln); +- if (k < j) +- FFSWAP(IComplex, z[k], z[j]); +- } +- +- /* pass 0 */ +- +- p = &z[0]; +- j = np >> 1; +- do { +- BF(p[0].re, p[0].im, p[1].re, p[1].im, +- p[0].re, p[0].im, p[1].re, p[1].im); +- p += 2; +- } while (--j); +- +- /* pass 1 */ +- +- p = &z[0]; +- j = np >> 2; +- do { +- BF(p[0].re, p[0].im, p[2].re, p[2].im, +- p[0].re, p[0].im, p[2].re, p[2].im); +- BF(p[1].re, p[1].im, p[3].re, p[3].im, +- p[1].re, p[1].im, p[3].im, -p[3].re); +- p+=4; +- } while (--j); +- +- /* pass 2 .. ln-1 */ +- +- nblocks = np >> 3; +- nloops = 1 << 2; +- np2 = np >> 1; +- do { +- p = z; +- q = z + nloops; +- for (j = 0; j < nblocks; j++) { +- BF(p->re, p->im, q->re, q->im, +- p->re, p->im, q->re, q->im); +- p++; +- q++; +- for(l = nblocks; l < np2; l += nblocks) { +- CMUL(tmp_re, tmp_im, mdct->costab[l], -mdct->sintab[l], q->re, q->im); +- BF(p->re, p->im, q->re, q->im, +- p->re, p->im, tmp_re, tmp_im); +- p++; +- q++; +- } +- p += nloops; +- q += nloops; +- } +- nblocks = nblocks >> 1; +- nloops = nloops << 1; +- } while (nblocks); ++ int ret = ff_mdct_init(&s->mdct, 9, 0, -1.0); ++ s->mdct_window = ff_ac3_window; ++ return ret; + } + + +-/** +- * Calculate a 512-point MDCT +- * @param out 256 output frequency coefficients +- * @param in 512 windowed input audio samples +- */ +-static void mdct512(AC3MDCTContext *mdct, int32_t *out, int16_t *in) +-{ +- int i, re, im, n, n2, n4; +- int16_t *rot = mdct->rot_tmp; +- IComplex *x = mdct->cplx_tmp; +- +- n = 1 << mdct->nbits; +- n2 = n >> 1; +- n4 = n >> 2; +- +- /* shift to simplify computations */ +- for (i = 0; i > 1; +- im = -((int)rot[n2+2*i] - (int)rot[n2-1-2*i]) >> 1; +- CMUL(x[i].re, x[i].im, re, im, -mdct->xcos1[i], mdct->xsin1[i]); +- } +- +- fft(mdct, x, mdct->nbits - 2); +- +- /* post rotation */ +- for (i = 0; i < n4; i++) { +- re = x[i].re; +- im = x[i].im; +- CMUL(out[n2-1-2*i], out[2*i], re, im, mdct->xsin1[i], mdct->xcos1[i]); +- } +-} +- +- +-/** ++/* + * Apply KBD window to input samples prior to MDCT. + */ + static void apply_window(DSPContext *dsp, int16_t *output, const int16_t *input, +- const int16_t *window, int n) ++ const int16_t *window, unsigned int len) + { +- int i; +- int n2 = n >> 1; +- +- for (i = 0; i < n2; i++) { +- output[i] = MUL16(input[i], window[i]) >> 15; +- output[n-i-1] = MUL16(input[n-i-1], window[i]) >> 15; +- } ++ dsp->apply_window_int16(output, input, window, len); + } + + +-/** +- * Calculate the log2() of the maximum absolute value in an array. +- * @param tab input array +- * @param n number of values in the array +- * @return log2(max(abs(tab[]))) ++/* ++ * Normalize the input samples to use the maximum available precision. ++ * This assumes signed 16-bit input samples. + */ +-static int log2_tab(int16_t *tab, int n) ++static int normalize_samples(AC3EncodeContext *s) + { +- int i, v; +- +- v = 0; +- for (i = 0; i < n; i++) +- v |= abs(tab[i]); +- +- return av_log2(v); ++ int v = s->ac3dsp.ac3_max_msb_abs_int16(s->windowed_samples, AC3_WINDOW_SIZE); ++ v = 14 - av_log2(v); ++ if (v > 0) ++ s->ac3dsp.ac3_lshift_int16(s->windowed_samples, AC3_WINDOW_SIZE, v); ++ /* +6 to right-shift from 31-bit to 25-bit */ ++ return v + 6; + } + + +-/** +- * Left-shift each value in an array by a specified amount. +- * @param tab input array +- * @param n number of values in the array +- * @param lshift left shift amount. a negative value means right shift. ++/* ++ * Scale MDCT coefficients to 25-bit signed fixed-point. + */ +-static void lshift_tab(int16_t *tab, int n, int lshift) ++static void scale_coefficients(AC3EncodeContext *s) + { +- int i; ++ int blk, ch; + +- if (lshift > 0) { +- for (i = 0; i < n; i++) +- tab[i] <<= lshift; +- } else if (lshift < 0) { +- lshift = -lshift; +- for (i = 0; i < n; i++) +- tab[i] >>= lshift; ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ for (ch = 1; ch <= s->channels; ch++) { ++ s->ac3dsp.ac3_rshift_int32(block->mdct_coef[ch], AC3_MAX_COEFS, ++ block->coeff_shift[ch]); ++ } + } + } + +- +-/** +- * Normalize the input samples to use the maximum available precision. +- * This assumes signed 16-bit input samples. Exponents are reduced by 9 to +- * match the 24-bit internal precision for MDCT coefficients. +- * +- * @return exponent shift +- */ +-static int normalize_samples(AC3EncodeContext *s) ++static void sum_square_butterfly(AC3EncodeContext *s, int64_t sum[4], ++ const int32_t *coef0, const int32_t *coef1, ++ int len) + { +- int v = 14 - log2_tab(s->windowed_samples, AC3_WINDOW_SIZE); +- v = FFMAX(0, v); +- lshift_tab(s->windowed_samples, AC3_WINDOW_SIZE, v); +- return v - 9; ++ s->ac3dsp.sum_square_butterfly_int32(sum, coef0, coef1, len); + } + +- +-/** +- * Scale MDCT coefficients from float to fixed-point. ++/* ++ * Clip MDCT coefficients to allowable range. + */ +-static void scale_coefficients(AC3EncodeContext *s) ++static void clip_coefficients(DSPContext *dsp, int32_t *coef, unsigned int len) + { +- /* scaling/conversion is obviously not needed for the fixed-point encoder +- since the coefficients are already fixed-point. */ +- return; ++ dsp->vector_clip_int32(coef, coef, COEF_MIN, COEF_MAX, len); + } + + +-#ifdef TEST +-/*************************************************************************/ +-/* TEST */ +- +-#include "libavutil/lfg.h" +- +-#define MDCT_NBITS 9 +-#define MDCT_SAMPLES (1 << MDCT_NBITS) +-#define FN (MDCT_SAMPLES/4) +- +- +-static void fft_test(AC3MDCTContext *mdct, AVLFG *lfg) +-{ +- IComplex in[FN], in1[FN]; +- int k, n, i; +- float sum_re, sum_im, a; +- +- for (i = 0; i < FN; i++) { +- in[i].re = av_lfg_get(lfg) % 65535 - 32767; +- in[i].im = av_lfg_get(lfg) % 65535 - 32767; +- in1[i] = in[i]; +- } +- fft(mdct, in, 7); +- +- /* do it by hand */ +- for (k = 0; k < FN; k++) { +- sum_re = 0; +- sum_im = 0; +- for (n = 0; n < FN; n++) { +- a = -2 * M_PI * (n * k) / FN; +- sum_re += in1[n].re * cos(a) - in1[n].im * sin(a); +- sum_im += in1[n].re * sin(a) + in1[n].im * cos(a); +- } +- av_log(NULL, AV_LOG_DEBUG, "%3d: %6d,%6d %6.0f,%6.0f\n", +- k, in[k].re, in[k].im, sum_re / FN, sum_im / FN); +- } +-} +- +- +-static void mdct_test(AC3MDCTContext *mdct, AVLFG *lfg) ++/* ++ * Calculate a single coupling coordinate. ++ */ ++static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) + { +- int16_t input[MDCT_SAMPLES]; +- int32_t output[AC3_MAX_COEFS]; +- float input1[MDCT_SAMPLES]; +- float output1[AC3_MAX_COEFS]; +- float s, a, err, e, emax; +- int i, k, n; +- +- for (i = 0; i < MDCT_SAMPLES; i++) { +- input[i] = (av_lfg_get(lfg) % 65535 - 32767) * 9 / 10; +- input1[i] = input[i]; +- } +- +- mdct512(mdct, output, input); +- +- /* do it by hand */ +- for (k = 0; k < AC3_MAX_COEFS; k++) { +- s = 0; +- for (n = 0; n < MDCT_SAMPLES; n++) { +- a = (2*M_PI*(2*n+1+MDCT_SAMPLES/2)*(2*k+1) / (4 * MDCT_SAMPLES)); +- s += input1[n] * cos(a); +- } +- output1[k] = -2 * s / MDCT_SAMPLES; ++ if (energy_cpl <= COEF_MAX) { ++ return 1048576; ++ } else { ++ uint64_t coord = energy_ch / (energy_cpl >> 24); ++ uint32_t coord32 = FFMIN(coord, 1073741824); ++ coord32 = ff_sqrt(coord32) << 9; ++ return FFMIN(coord32, COEF_MAX); + } +- +- err = 0; +- emax = 0; +- for (i = 0; i < AC3_MAX_COEFS; i++) { +- av_log(NULL, AV_LOG_DEBUG, "%3d: %7d %7.0f\n", i, output[i], output1[i]); +- e = output[i] - output1[i]; +- if (e > emax) +- emax = e; +- err += e * e; +- } +- av_log(NULL, AV_LOG_DEBUG, "err2=%f emax=%f\n", err / AC3_MAX_COEFS, emax); + } + + +-int main(void) ++static av_cold int ac3_fixed_encode_init(AVCodecContext *avctx) + { +- AVLFG lfg; +- AC3MDCTContext mdct; +- +- mdct.avctx = NULL; +- av_log_set_level(AV_LOG_DEBUG); +- mdct_init(&mdct, 9); +- +- fft_test(&mdct, &lfg); +- mdct_test(&mdct, &lfg); +- +- return 0; ++ AC3EncodeContext *s = avctx->priv_data; ++ s->fixed_point = 1; ++ return ff_ac3_encode_init(avctx); + } +-#endif /* TEST */ + + + AVCodec ff_ac3_fixed_encoder = { +- "ac3_fixed", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AC3, +- sizeof(AC3EncodeContext), +- ac3_encode_init, +- ac3_encode_frame, +- ac3_encode_close, +- NULL, ++ .name = "ac3_fixed", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AC3, ++ .priv_data_size = sizeof(AC3EncodeContext), ++ .init = ac3_fixed_encode_init, ++ .encode = ff_ac3_fixed_encode_frame, ++ .close = ff_ac3_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), +- .channel_layouts = ac3_channel_layouts, ++ .priv_class = &ac3enc_class, ++ .channel_layouts = ff_ac3_channel_layouts, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_fixed.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_fixed.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_fixed.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_fixed.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,59 +0,0 @@ +-/* +- * The simplest AC-3 encoder +- * Copyright (c) 2000 Fabrice Bellard +- * Copyright (c) 2006-2010 Justin Ruggles +- * Copyright (c) 2006-2010 Prakash Punnoor +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * fixed-point AC-3 encoder header. +- */ +- +-#ifndef AVCODEC_AC3ENC_FIXED_H +-#define AVCODEC_AC3ENC_FIXED_H +- +-#include +- +- +-typedef int16_t SampleType; +-typedef int32_t CoefType; +-typedef int64_t CoefSumType; +- +- +-/** +- * Compex number. +- * Used in fixed-point MDCT calculation. +- */ +-typedef struct IComplex { +- int16_t re,im; +-} IComplex; +- +-typedef struct AC3MDCTContext { +- const int16_t *window; ///< MDCT window function +- int nbits; ///< log2(transform size) +- int16_t *costab; ///< FFT cos table +- int16_t *sintab; ///< FFT sin table +- int16_t *xcos1; ///< MDCT cos table +- int16_t *xsin1; ///< MDCT sin table +- int16_t *rot_tmp; ///< temp buffer for pre-rotated samples +- IComplex *cplx_tmp; ///< temp buffer for complex pre-rotated samples +-} AC3MDCTContext; +- +-#endif /* AVCODEC_AC3ENC_FIXED_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_float.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_float.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_float.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_float.c 2012-05-14 14:08:53.341319996 +0200 +@@ -27,98 +27,133 @@ + */ + + #define CONFIG_AC3ENC_FLOAT 1 +-#include "ac3enc.c" ++#include "ac3enc.h" ++#include "eac3enc.h" ++#include "kbdwin.h" ++ ++ ++#if CONFIG_AC3_ENCODER ++#define AC3ENC_TYPE AC3ENC_TYPE_AC3 ++#include "ac3enc_opts_template.c" ++static const AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name, ++ ac3_options, LIBAVUTIL_VERSION_INT }; ++#endif ++ ++#include "ac3enc_template.c" + + + /** + * Finalize MDCT and free allocated memory. ++ * ++ * @param s AC-3 encoder private context + */ +-static av_cold void mdct_end(AC3MDCTContext *mdct) ++av_cold void ff_ac3_float_mdct_end(AC3EncodeContext *s) + { +- ff_mdct_end(&mdct->fft); +- av_freep(&mdct->window); ++ ff_mdct_end(&s->mdct); ++ av_freep(&s->mdct_window); + } + + + /** + * Initialize MDCT tables. +- * @param nbits log2(MDCT size) ++ * ++ * @param s AC-3 encoder private context ++ * @return 0 on success, negative error code on failure + */ +-static av_cold int mdct_init(AVCodecContext *avctx, AC3MDCTContext *mdct, +- int nbits) ++av_cold int ff_ac3_float_mdct_init(AC3EncodeContext *s) + { + float *window; + int i, n, n2; + +- n = 1 << nbits; ++ n = 1 << 9; + n2 = n >> 1; + + window = av_malloc(n * sizeof(*window)); + if (!window) { +- av_log(avctx, AV_LOG_ERROR, "Cannot allocate memory.\n"); ++ av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n"); + return AVERROR(ENOMEM); + } + ff_kbd_window_init(window, 5.0, n2); + for (i = 0; i < n2; i++) + window[n-1-i] = window[i]; +- mdct->window = window; +- +- return ff_mdct_init(&mdct->fft, nbits, 0, -2.0 / n); +-} +- ++ s->mdct_window = window; + +-/** +- * Calculate a 512-point MDCT +- * @param out 256 output frequency coefficients +- * @param in 512 windowed input audio samples +- */ +-static void mdct512(AC3MDCTContext *mdct, float *out, float *in) +-{ +- ff_mdct_calc(&mdct->fft, out, in); ++ return ff_mdct_init(&s->mdct, 9, 0, -2.0 / n); + } + + +-/** ++/* + * Apply KBD window to input samples prior to MDCT. + */ + static void apply_window(DSPContext *dsp, float *output, const float *input, +- const float *window, int n) ++ const float *window, unsigned int len) + { +- dsp->vector_fmul(output, input, window, n); ++ dsp->vector_fmul(output, input, window, len); + } + + +-/** +- * Normalize the input samples to use the maximum available precision. ++/* ++ * Normalize the input samples. ++ * Not needed for the floating-point encoder. + */ + static int normalize_samples(AC3EncodeContext *s) + { +- /* Normalization is not needed for floating-point samples, so just return 0 */ + return 0; + } + + +-/** ++/* + * Scale MDCT coefficients from float to 24-bit fixed-point. + */ + static void scale_coefficients(AC3EncodeContext *s) + { +- int i; +- for (i = 0; i < AC3_MAX_COEFS * AC3_MAX_BLOCKS * s->channels; i++) +- s->fixed_coef_buffer[i] = SCALE_FLOAT(s->mdct_coef_buffer[i], 24); ++ int chan_size = AC3_MAX_COEFS * s->num_blocks; ++ int cpl = s->cpl_on; ++ s->ac3dsp.float_to_fixed24(s->fixed_coef_buffer + (chan_size * !cpl), ++ s->mdct_coef_buffer + (chan_size * !cpl), ++ chan_size * (s->channels + cpl)); ++} ++ ++static void sum_square_butterfly(AC3EncodeContext *s, float sum[4], ++ const float *coef0, const float *coef1, ++ int len) ++{ ++ s->ac3dsp.sum_square_butterfly_float(sum, coef0, coef1, len); ++} ++ ++/* ++ * Clip MDCT coefficients to allowable range. ++ */ ++static void clip_coefficients(DSPContext *dsp, float *coef, unsigned int len) ++{ ++ dsp->vector_clipf(coef, coef, COEF_MIN, COEF_MAX, len); ++} ++ ++ ++/* ++ * Calculate a single coupling coordinate. ++ */ ++static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl) ++{ ++ float coord = 0.125; ++ if (energy_cpl > 0) ++ coord *= sqrtf(energy_ch / energy_cpl); ++ return FFMIN(coord, COEF_MAX); + } + + ++#if CONFIG_AC3_ENCODER + AVCodec ff_ac3_encoder = { +- "ac3", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AC3, +- sizeof(AC3EncodeContext), +- ac3_encode_init, +- ac3_encode_frame, +- ac3_encode_close, +- NULL, ++ .name = "ac3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AC3, ++ .priv_data_size = sizeof(AC3EncodeContext), ++ .init = ff_ac3_encode_init, ++ .encode = ff_ac3_float_encode_frame, ++ .close = ff_ac3_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"), +- .channel_layouts = ac3_channel_layouts, ++ .priv_class = &ac3enc_class, ++ .channel_layouts = ff_ac3_channel_layouts, + }; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_float.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_float.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_float.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_float.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,45 +0,0 @@ +-/* +- * The simplest AC-3 encoder +- * Copyright (c) 2000 Fabrice Bellard +- * Copyright (c) 2006-2010 Justin Ruggles +- * Copyright (c) 2006-2010 Prakash Punnoor +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * floating-point AC-3 encoder header. +- */ +- +-#ifndef AVCODEC_AC3ENC_FLOAT_H +-#define AVCODEC_AC3ENC_FLOAT_H +- +-#include "fft.h" +- +- +-typedef float SampleType; +-typedef float CoefType; +-typedef float CoefSumType; +- +- +-typedef struct AC3MDCTContext { +- const float *window; ///< MDCT window function +- FFTContext fft; ///< FFT context for MDCT calculation +-} AC3MDCTContext; +- +-#endif /* AVCODEC_AC3ENC_FLOAT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc.h 2012-05-14 14:08:53.339319956 +0200 +@@ -0,0 +1,305 @@ ++/* ++ * AC-3 encoder & E-AC-3 encoder common header ++ * Copyright (c) 2000 Fabrice Bellard ++ * Copyright (c) 2006-2010 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * AC-3 encoder & E-AC-3 encoder common header ++ */ ++ ++#ifndef AVCODEC_AC3ENC_H ++#define AVCODEC_AC3ENC_H ++ ++#include ++#include "ac3.h" ++#include "ac3dsp.h" ++#include "avcodec.h" ++#include "dsputil.h" ++#include "put_bits.h" ++#include "fft.h" ++ ++#ifndef CONFIG_AC3ENC_FLOAT ++#define CONFIG_AC3ENC_FLOAT 0 ++#endif ++ ++#define OFFSET(param) offsetof(AC3EncodeContext, options.param) ++#define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM) ++ ++#define AC3ENC_TYPE_AC3_FIXED 0 ++#define AC3ENC_TYPE_AC3 1 ++#define AC3ENC_TYPE_EAC3 2 ++ ++#if CONFIG_AC3ENC_FLOAT ++#define AC3_NAME(x) ff_ac3_float_ ## x ++#define MAC_COEF(d,a,b) ((d)+=(a)*(b)) ++#define COEF_MIN (-16777215.0/16777216.0) ++#define COEF_MAX ( 16777215.0/16777216.0) ++#define NEW_CPL_COORD_THRESHOLD 0.03 ++typedef float SampleType; ++typedef float CoefType; ++typedef float CoefSumType; ++#else ++#define AC3_NAME(x) ff_ac3_fixed_ ## x ++#define MAC_COEF(d,a,b) MAC64(d,a,b) ++#define COEF_MIN -16777215 ++#define COEF_MAX 16777215 ++#define NEW_CPL_COORD_THRESHOLD 503317 ++typedef int16_t SampleType; ++typedef int32_t CoefType; ++typedef int64_t CoefSumType; ++#endif ++ ++/* common option values */ ++#define AC3ENC_OPT_NONE -1 ++#define AC3ENC_OPT_AUTO -1 ++#define AC3ENC_OPT_OFF 0 ++#define AC3ENC_OPT_ON 1 ++#define AC3ENC_OPT_NOT_INDICATED 0 ++#define AC3ENC_OPT_MODE_ON 2 ++#define AC3ENC_OPT_MODE_OFF 1 ++ ++/* specific option values */ ++#define AC3ENC_OPT_LARGE_ROOM 1 ++#define AC3ENC_OPT_SMALL_ROOM 2 ++#define AC3ENC_OPT_DOWNMIX_LTRT 1 ++#define AC3ENC_OPT_DOWNMIX_LORO 2 ++#define AC3ENC_OPT_ADCONV_STANDARD 0 ++#define AC3ENC_OPT_ADCONV_HDCD 1 ++ ++ ++/** ++ * Encoding Options used by AVOption. ++ */ ++typedef struct AC3EncOptions { ++ /* AC-3 metadata options*/ ++ int dialogue_level; ++ int bitstream_mode; ++ float center_mix_level; ++ float surround_mix_level; ++ int dolby_surround_mode; ++ int audio_production_info; ++ int mixing_level; ++ int room_type; ++ int copyright; ++ int original; ++ int extended_bsi_1; ++ int preferred_stereo_downmix; ++ float ltrt_center_mix_level; ++ float ltrt_surround_mix_level; ++ float loro_center_mix_level; ++ float loro_surround_mix_level; ++ int extended_bsi_2; ++ int dolby_surround_ex_mode; ++ int dolby_headphone_mode; ++ int ad_converter_type; ++ int eac3_mixing_metadata; ++ int eac3_info_metadata; ++ ++ /* other encoding options */ ++ int allow_per_frame_metadata; ++ int stereo_rematrixing; ++ int channel_coupling; ++ int cpl_start; ++} AC3EncOptions; ++ ++/** ++ * Data for a single audio block. ++ */ ++typedef struct AC3Block { ++ CoefType **mdct_coef; ///< MDCT coefficients ++ int32_t **fixed_coef; ///< fixed-point MDCT coefficients ++ uint8_t **exp; ///< original exponents ++ uint8_t **grouped_exp; ///< grouped exponents ++ int16_t **psd; ///< psd per frequency bin ++ int16_t **band_psd; ///< psd per critical band ++ int16_t **mask; ///< masking curve ++ uint16_t **qmant; ///< quantized mantissas ++ uint8_t **cpl_coord_exp; ///< coupling coord exponents (cplcoexp) ++ uint8_t **cpl_coord_mant; ///< coupling coord mantissas (cplcomant) ++ uint8_t coeff_shift[AC3_MAX_CHANNELS]; ///< fixed-point coefficient shift values ++ uint8_t new_rematrixing_strategy; ///< send new rematrixing flags in this block ++ int num_rematrixing_bands; ///< number of rematrixing bands ++ uint8_t rematrixing_flags[4]; ///< rematrixing flags ++ int new_cpl_strategy; ///< send new coupling strategy ++ int cpl_in_use; ///< coupling in use for this block (cplinu) ++ uint8_t channel_in_cpl[AC3_MAX_CHANNELS]; ///< channel in coupling (chincpl) ++ int num_cpl_channels; ///< number of channels in coupling ++ uint8_t new_cpl_coords[AC3_MAX_CHANNELS]; ///< send new coupling coordinates (cplcoe) ++ uint8_t cpl_master_exp[AC3_MAX_CHANNELS]; ///< coupling coord master exponents (mstrcplco) ++ int new_snr_offsets; ///< send new SNR offsets ++ int new_cpl_leak; ///< send new coupling leak info ++ int end_freq[AC3_MAX_CHANNELS]; ///< end frequency bin (endmant) ++} AC3Block; ++ ++/** ++ * AC-3 encoder private context. ++ */ ++typedef struct AC3EncodeContext { ++ AVClass *av_class; ///< AVClass used for AVOption ++ AC3EncOptions options; ///< encoding options ++ AVCodecContext *avctx; ///< parent AVCodecContext ++ PutBitContext pb; ///< bitstream writer context ++ DSPContext dsp; ++ AC3DSPContext ac3dsp; ///< AC-3 optimized functions ++ FFTContext mdct; ///< FFT context for MDCT calculation ++ const SampleType *mdct_window; ///< MDCT window function array ++ ++ AC3Block blocks[AC3_MAX_BLOCKS]; ///< per-block info ++ ++ int fixed_point; ///< indicates if fixed-point encoder is being used ++ int eac3; ///< indicates if this is E-AC-3 vs. AC-3 ++ int bitstream_id; ///< bitstream id (bsid) ++ int bitstream_mode; ///< bitstream mode (bsmod) ++ ++ int bit_rate; ///< target bit rate, in bits-per-second ++ int sample_rate; ///< sampling frequency, in Hz ++ ++ int num_blks_code; ///< number of blocks code (numblkscod) ++ int num_blocks; ///< number of blocks per frame ++ int frame_size_min; ///< minimum frame size in case rounding is necessary ++ int frame_size; ///< current frame size in bytes ++ int frame_size_code; ///< frame size code (frmsizecod) ++ uint16_t crc_inv[2]; ++ int64_t bits_written; ///< bit count (used to avg. bitrate) ++ int64_t samples_written; ///< sample count (used to avg. bitrate) ++ ++ int fbw_channels; ///< number of full-bandwidth channels (nfchans) ++ int channels; ///< total number of channels (nchans) ++ int lfe_on; ///< indicates if there is an LFE channel (lfeon) ++ int lfe_channel; ///< channel index of the LFE channel ++ int has_center; ///< indicates if there is a center channel ++ int has_surround; ///< indicates if there are one or more surround channels ++ int channel_mode; ///< channel mode (acmod) ++ const uint8_t *channel_map; ///< channel map used to reorder channels ++ ++ int center_mix_level; ///< center mix level code ++ int surround_mix_level; ///< surround mix level code ++ int ltrt_center_mix_level; ///< Lt/Rt center mix level code ++ int ltrt_surround_mix_level; ///< Lt/Rt surround mix level code ++ int loro_center_mix_level; ///< Lo/Ro center mix level code ++ int loro_surround_mix_level; ///< Lo/Ro surround mix level code ++ ++ int cutoff; ///< user-specified cutoff frequency, in Hz ++ int bandwidth_code; ///< bandwidth code (0 to 60) (chbwcod) ++ int start_freq[AC3_MAX_CHANNELS]; ///< start frequency bin (strtmant) ++ int cpl_end_freq; ///< coupling channel end frequency bin ++ ++ int cpl_on; ///< coupling turned on for this frame ++ int cpl_enabled; ///< coupling enabled for all frames ++ int num_cpl_subbands; ///< number of coupling subbands (ncplsubnd) ++ int num_cpl_bands; ///< number of coupling bands (ncplbnd) ++ uint8_t cpl_band_sizes[AC3_MAX_CPL_BANDS]; ///< number of coeffs in each coupling band ++ ++ int rematrixing_enabled; ///< stereo rematrixing enabled ++ ++ /* bitrate allocation control */ ++ int slow_gain_code; ///< slow gain code (sgaincod) ++ int slow_decay_code; ///< slow decay code (sdcycod) ++ int fast_decay_code; ///< fast decay code (fdcycod) ++ int db_per_bit_code; ///< dB/bit code (dbpbcod) ++ int floor_code; ///< floor code (floorcod) ++ AC3BitAllocParameters bit_alloc; ///< bit allocation parameters ++ int coarse_snr_offset; ///< coarse SNR offsets (csnroffst) ++ int fast_gain_code[AC3_MAX_CHANNELS]; ///< fast gain codes (signal-to-mask ratio) (fgaincod) ++ int fine_snr_offset[AC3_MAX_CHANNELS]; ///< fine SNR offsets (fsnroffst) ++ int frame_bits_fixed; ///< number of non-coefficient bits for fixed parameters ++ int frame_bits; ///< all frame bits except exponents and mantissas ++ int exponent_bits; ///< number of bits used for exponents ++ ++ SampleType *windowed_samples; ++ SampleType **planar_samples; ++ uint8_t *bap_buffer; ++ uint8_t *bap1_buffer; ++ CoefType *mdct_coef_buffer; ++ int32_t *fixed_coef_buffer; ++ uint8_t *exp_buffer; ++ uint8_t *grouped_exp_buffer; ++ int16_t *psd_buffer; ++ int16_t *band_psd_buffer; ++ int16_t *mask_buffer; ++ int16_t *qmant_buffer; ++ uint8_t *cpl_coord_exp_buffer; ++ uint8_t *cpl_coord_mant_buffer; ++ ++ uint8_t exp_strategy[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< exponent strategies ++ uint8_t frame_exp_strategy[AC3_MAX_CHANNELS]; ///< frame exp strategy index ++ int use_frame_exp_strategy; ///< indicates use of frame exp strategy ++ uint8_t exp_ref_block[AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< reference blocks for EXP_REUSE ++ uint8_t *ref_bap [AC3_MAX_CHANNELS][AC3_MAX_BLOCKS]; ///< bit allocation pointers (bap) ++ int ref_bap_set; ///< indicates if ref_bap pointers have been set ++ ++ /* fixed vs. float function pointers */ ++ void (*mdct_end)(struct AC3EncodeContext *s); ++ int (*mdct_init)(struct AC3EncodeContext *s); ++ ++ /* fixed vs. float templated function pointers */ ++ int (*allocate_sample_buffers)(struct AC3EncodeContext *s); ++ ++ /* AC-3 vs. E-AC-3 function pointers */ ++ void (*output_frame_header)(struct AC3EncodeContext *s); ++} AC3EncodeContext; ++ ++ ++extern const uint64_t ff_ac3_channel_layouts[19]; ++ ++int ff_ac3_encode_init(AVCodecContext *avctx); ++ ++int ff_ac3_encode_close(AVCodecContext *avctx); ++ ++int ff_ac3_validate_metadata(AC3EncodeContext *s); ++ ++void ff_ac3_adjust_frame_size(AC3EncodeContext *s); ++ ++void ff_ac3_compute_coupling_strategy(AC3EncodeContext *s); ++ ++void ff_ac3_apply_rematrixing(AC3EncodeContext *s); ++ ++void ff_ac3_process_exponents(AC3EncodeContext *s); ++ ++int ff_ac3_compute_bit_allocation(AC3EncodeContext *s); ++ ++void ff_ac3_group_exponents(AC3EncodeContext *s); ++ ++void ff_ac3_quantize_mantissas(AC3EncodeContext *s); ++ ++void ff_ac3_output_frame(AC3EncodeContext *s, unsigned char *frame); ++ ++ ++/* prototypes for functions in ac3enc_fixed.c and ac3enc_float.c */ ++ ++void ff_ac3_fixed_mdct_end(AC3EncodeContext *s); ++void ff_ac3_float_mdct_end(AC3EncodeContext *s); ++ ++int ff_ac3_fixed_mdct_init(AC3EncodeContext *s); ++int ff_ac3_float_mdct_init(AC3EncodeContext *s); ++ ++ ++/* prototypes for functions in ac3enc_template.c */ ++ ++int ff_ac3_fixed_allocate_sample_buffers(AC3EncodeContext *s); ++int ff_ac3_float_allocate_sample_buffers(AC3EncodeContext *s); ++ ++int ff_ac3_fixed_encode_frame(AVCodecContext *avctx, unsigned char *frame, ++ int buf_size, void *data); ++int ff_ac3_float_encode_frame(AVCodecContext *avctx, unsigned char *frame, ++ int buf_size, void *data); ++ ++#endif /* AVCODEC_AC3ENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_opts_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_opts_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_opts_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_opts_template.c 2012-05-14 14:08:53.343320036 +0200 +@@ -0,0 +1,80 @@ ++/* ++ * AC-3 encoder options ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/opt.h" ++#include "ac3.h" ++ ++#if AC3ENC_TYPE == AC3ENC_TYPE_AC3_FIXED ++static const AVOption ac3fixed_options[] = { ++#elif AC3ENC_TYPE == AC3ENC_TYPE_AC3 ++static const AVOption ac3_options[] = { ++#else /* AC3ENC_TYPE_EAC3 */ ++static const AVOption eac3_options[] = { ++#endif ++/* Metadata Options */ ++{"per_frame_metadata", "Allow Changing Metadata Per-Frame", OFFSET(allow_per_frame_metadata), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, 1, AC3ENC_PARAM}, ++#if AC3ENC_TYPE != AC3ENC_TYPE_EAC3 ++/* AC-3 downmix levels */ ++{"center_mixlev", "Center Mix Level", OFFSET(center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_4POINT5DB }, 0.0, 1.0, AC3ENC_PARAM}, ++{"surround_mixlev", "Surround Mix Level", OFFSET(surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = LEVEL_MINUS_6DB }, 0.0, 1.0, AC3ENC_PARAM}, ++#endif ++/* audio production information */ ++{"mixing_level", "Mixing Level", OFFSET(mixing_level), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 111, AC3ENC_PARAM}, ++{"room_type", "Room Type", OFFSET(room_type), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_SMALL_ROOM, AC3ENC_PARAM, "room_type"}, ++ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, ++ {"large", "Large Room", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_LARGE_ROOM }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, ++ {"small", "Small Room", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_SMALL_ROOM }, INT_MIN, INT_MAX, AC3ENC_PARAM, "room_type"}, ++/* other metadata options */ ++{"copyright", "Copyright Bit", OFFSET(copyright), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 1, AC3ENC_PARAM}, ++{"dialnorm", "Dialogue Level (dB)", OFFSET(dialogue_level), AV_OPT_TYPE_INT, {.dbl = -31 }, -31, -1, AC3ENC_PARAM}, ++{"dsur_mode", "Dolby Surround Mode", OFFSET(dolby_surround_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_ON, AC3ENC_PARAM, "dsur_mode"}, ++ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, ++ {"on", "Dolby Surround Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, ++ {"off", "Not Dolby Surround Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsur_mode"}, ++{"original", "Original Bit Stream", OFFSET(original), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, 1, AC3ENC_PARAM}, ++/* extended bitstream information */ ++{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_DOWNMIX_LORO, AC3ENC_PARAM, "dmix_mode"}, ++ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, ++ {"ltrt", "Lt/Rt Downmix Preferred", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_DOWNMIX_LTRT }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, ++ {"loro", "Lo/Ro Downmix Preferred", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_DOWNMIX_LORO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dmix_mode"}, ++{"ltrt_cmixlev", "Lt/Rt Center Mix Level", OFFSET(ltrt_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, ++{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, ++{"loro_cmixlev", "Lo/Ro Center Mix Level", OFFSET(loro_center_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, ++{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, AC3ENC_PARAM}, ++{"dsurex_mode", "Dolby Surround EX Mode", OFFSET(dolby_surround_ex_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_ON, AC3ENC_PARAM, "dsurex_mode"}, ++ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, ++ {"on", "Dolby Surround EX Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, ++ {"off", "Not Dolby Surround EX Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dsurex_mode"}, ++{"dheadphone_mode", "Dolby Headphone Mode", OFFSET(dolby_headphone_mode), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_MODE_ON, AC3ENC_PARAM, "dheadphone_mode"}, ++ {"notindicated", "Not Indicated (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_NOT_INDICATED }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, ++ {"on", "Dolby Headphone Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_ON }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, ++ {"off", "Not Dolby Headphone Encoded", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_MODE_OFF }, INT_MIN, INT_MAX, AC3ENC_PARAM, "dheadphone_mode"}, ++{"ad_conv_type", "A/D Converter Type", OFFSET(ad_converter_type), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_NONE }, AC3ENC_OPT_NONE, AC3ENC_OPT_ADCONV_HDCD, AC3ENC_PARAM, "ad_conv_type"}, ++ {"standard", "Standard (default)", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_ADCONV_STANDARD }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, ++ {"hdcd", "HDCD", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_ADCONV_HDCD }, INT_MIN, INT_MAX, AC3ENC_PARAM, "ad_conv_type"}, ++/* Other Encoding Options */ ++{"stereo_rematrixing", "Stereo Rematrixing", OFFSET(stereo_rematrixing), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_ON }, AC3ENC_OPT_OFF, AC3ENC_OPT_ON, AC3ENC_PARAM}, ++{"channel_coupling", "Channel Coupling", OFFSET(channel_coupling), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, AC3ENC_OPT_ON, AC3ENC_PARAM, "channel_coupling"}, ++ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "channel_coupling"}, ++{"cpl_start_band", "Coupling Start Band", OFFSET(cpl_start), AV_OPT_TYPE_INT, {.dbl = AC3ENC_OPT_AUTO }, AC3ENC_OPT_AUTO, 15, AC3ENC_PARAM, "cpl_start_band"}, ++ {"auto", "Selected by the Encoder", 0, AV_OPT_TYPE_CONST, {.dbl = AC3ENC_OPT_AUTO }, INT_MIN, INT_MAX, AC3ENC_PARAM, "cpl_start_band"}, ++{NULL} ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3enc_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3enc_template.c 2012-05-14 14:08:53.344320057 +0200 +@@ -0,0 +1,443 @@ ++/* ++ * AC-3 encoder float/fixed template ++ * Copyright (c) 2000 Fabrice Bellard ++ * Copyright (c) 2006-2011 Justin Ruggles ++ * Copyright (c) 2006-2010 Prakash Punnoor ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * AC-3 encoder float/fixed template ++ */ ++ ++#include ++ ++ ++/* prototypes for static functions in ac3enc_fixed.c and ac3enc_float.c */ ++ ++static void scale_coefficients(AC3EncodeContext *s); ++ ++static void apply_window(DSPContext *dsp, SampleType *output, ++ const SampleType *input, const SampleType *window, ++ unsigned int len); ++ ++static int normalize_samples(AC3EncodeContext *s); ++ ++static void clip_coefficients(DSPContext *dsp, CoefType *coef, unsigned int len); ++ ++static CoefType calc_cpl_coord(CoefSumType energy_ch, CoefSumType energy_cpl); ++ ++static void sum_square_butterfly(AC3EncodeContext *s, CoefSumType sum[4], ++ const CoefType *coef0, const CoefType *coef1, ++ int len); ++ ++int AC3_NAME(allocate_sample_buffers)(AC3EncodeContext *s) ++{ ++ int ch; ++ ++ FF_ALLOC_OR_GOTO(s->avctx, s->windowed_samples, AC3_WINDOW_SIZE * ++ sizeof(*s->windowed_samples), alloc_fail); ++ FF_ALLOC_OR_GOTO(s->avctx, s->planar_samples, s->channels * sizeof(*s->planar_samples), ++ alloc_fail); ++ for (ch = 0; ch < s->channels; ch++) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->planar_samples[ch], ++ (AC3_FRAME_SIZE+AC3_BLOCK_SIZE) * sizeof(**s->planar_samples), ++ alloc_fail); ++ } ++ ++ return 0; ++alloc_fail: ++ return AVERROR(ENOMEM); ++} ++ ++ ++/* ++ * Deinterleave input samples. ++ * Channels are reordered from FFmpeg's default order to AC-3 order. ++ */ ++static void deinterleave_input_samples(AC3EncodeContext *s, ++ const SampleType *samples) ++{ ++ int ch, i; ++ ++ /* deinterleave and remap input samples */ ++ for (ch = 0; ch < s->channels; ch++) { ++ const SampleType *sptr; ++ int sinc; ++ ++ /* copy last 256 samples of previous frame to the start of the current frame */ ++ memcpy(&s->planar_samples[ch][0], &s->planar_samples[ch][AC3_BLOCK_SIZE * s->num_blocks], ++ AC3_BLOCK_SIZE * sizeof(s->planar_samples[0][0])); ++ ++ /* deinterleave */ ++ sinc = s->channels; ++ sptr = samples + s->channel_map[ch]; ++ for (i = AC3_BLOCK_SIZE; i < AC3_BLOCK_SIZE * (s->num_blocks + 1); i++) { ++ s->planar_samples[ch][i] = *sptr; ++ sptr += sinc; ++ } ++ } ++} ++ ++ ++/* ++ * Apply the MDCT to input samples to generate frequency coefficients. ++ * This applies the KBD window and normalizes the input to reduce precision ++ * loss due to fixed-point calculations. ++ */ ++static void apply_mdct(AC3EncodeContext *s) ++{ ++ int blk, ch; ++ ++ for (ch = 0; ch < s->channels; ch++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE]; ++ ++ apply_window(&s->dsp, s->windowed_samples, input_samples, ++ s->mdct_window, AC3_WINDOW_SIZE); ++ ++ if (s->fixed_point) ++ block->coeff_shift[ch+1] = normalize_samples(s); ++ ++ s->mdct.mdct_calcw(&s->mdct, block->mdct_coef[ch+1], ++ s->windowed_samples); ++ } ++ } ++} ++ ++ ++/* ++ * Calculate coupling channel and coupling coordinates. ++ */ ++static void apply_channel_coupling(AC3EncodeContext *s) ++{ ++ LOCAL_ALIGNED_16(CoefType, cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); ++#if CONFIG_AC3ENC_FLOAT ++ LOCAL_ALIGNED_16(int32_t, fixed_cpl_coords, [AC3_MAX_BLOCKS], [AC3_MAX_CHANNELS][16]); ++#else ++ int32_t (*fixed_cpl_coords)[AC3_MAX_CHANNELS][16] = cpl_coords; ++#endif ++ int blk, ch, bnd, i, j; ++ CoefSumType energy[AC3_MAX_BLOCKS][AC3_MAX_CHANNELS][16] = {{{0}}}; ++ int cpl_start, num_cpl_coefs; ++ ++ memset(cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); ++#if CONFIG_AC3ENC_FLOAT ++ memset(fixed_cpl_coords, 0, AC3_MAX_BLOCKS * sizeof(*cpl_coords)); ++#endif ++ ++ /* align start to 16-byte boundary. align length to multiple of 32. ++ note: coupling start bin % 4 will always be 1 */ ++ cpl_start = s->start_freq[CPL_CH] - 1; ++ num_cpl_coefs = FFALIGN(s->num_cpl_subbands * 12 + 1, 32); ++ cpl_start = FFMIN(256, cpl_start + num_cpl_coefs) - num_cpl_coefs; ++ ++ /* calculate coupling channel from fbw channels */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ CoefType *cpl_coef = &block->mdct_coef[CPL_CH][cpl_start]; ++ if (!block->cpl_in_use) ++ continue; ++ memset(cpl_coef, 0, num_cpl_coefs * sizeof(*cpl_coef)); ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ CoefType *ch_coef = &block->mdct_coef[ch][cpl_start]; ++ if (!block->channel_in_cpl[ch]) ++ continue; ++ for (i = 0; i < num_cpl_coefs; i++) ++ cpl_coef[i] += ch_coef[i]; ++ } ++ ++ /* coefficients must be clipped in order to be encoded */ ++ clip_coefficients(&s->dsp, cpl_coef, num_cpl_coefs); ++ } ++ ++ /* calculate energy in each band in coupling channel and each fbw channel */ ++ /* TODO: possibly use SIMD to speed up energy calculation */ ++ bnd = 0; ++ i = s->start_freq[CPL_CH]; ++ while (i < s->cpl_end_freq) { ++ int band_size = s->cpl_band_sizes[bnd]; ++ for (ch = CPL_CH; ch <= s->fbw_channels; ch++) { ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ if (!block->cpl_in_use || (ch > CPL_CH && !block->channel_in_cpl[ch])) ++ continue; ++ for (j = 0; j < band_size; j++) { ++ CoefType v = block->mdct_coef[ch][i+j]; ++ MAC_COEF(energy[blk][ch][bnd], v, v); ++ } ++ } ++ } ++ i += band_size; ++ bnd++; ++ } ++ ++ /* calculate coupling coordinates for all blocks for all channels */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ if (!block->cpl_in_use) ++ continue; ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (!block->channel_in_cpl[ch]) ++ continue; ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy[blk][ch][bnd], ++ energy[blk][CPL_CH][bnd]); ++ } ++ } ++ } ++ ++ /* determine which blocks to send new coupling coordinates for */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ AC3Block *block0 = blk ? &s->blocks[blk-1] : NULL; ++ ++ memset(block->new_cpl_coords, 0, sizeof(block->new_cpl_coords)); ++ ++ if (block->cpl_in_use) { ++ /* send new coordinates if this is the first block, if previous ++ * block did not use coupling but this block does, the channels ++ * using coupling has changed from the previous block, or the ++ * coordinate difference from the last block for any channel is ++ * greater than a threshold value. */ ++ if (blk == 0 || !block0->cpl_in_use) { ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ block->new_cpl_coords[ch] = 1; ++ } else { ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (!block->channel_in_cpl[ch]) ++ continue; ++ if (!block0->channel_in_cpl[ch]) { ++ block->new_cpl_coords[ch] = 1; ++ } else { ++ CoefSumType coord_diff = 0; ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ coord_diff += FFABS(cpl_coords[blk-1][ch][bnd] - ++ cpl_coords[blk ][ch][bnd]); ++ } ++ coord_diff /= s->num_cpl_bands; ++ if (coord_diff > NEW_CPL_COORD_THRESHOLD) ++ block->new_cpl_coords[ch] = 1; ++ } ++ } ++ } ++ } ++ } ++ ++ /* calculate final coupling coordinates, taking into account reusing of ++ coordinates in successive blocks */ ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ blk = 0; ++ while (blk < s->num_blocks) { ++ int av_uninit(blk1); ++ AC3Block *block = &s->blocks[blk]; ++ ++ if (!block->cpl_in_use) { ++ blk++; ++ continue; ++ } ++ ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ CoefSumType energy_ch, energy_cpl; ++ if (!block->channel_in_cpl[ch]) ++ continue; ++ energy_cpl = energy[blk][CPL_CH][bnd]; ++ energy_ch = energy[blk][ch][bnd]; ++ blk1 = blk+1; ++ while (!s->blocks[blk1].new_cpl_coords[ch] && blk1 < s->num_blocks) { ++ if (s->blocks[blk1].cpl_in_use) { ++ energy_cpl += energy[blk1][CPL_CH][bnd]; ++ energy_ch += energy[blk1][ch][bnd]; ++ } ++ blk1++; ++ } ++ cpl_coords[blk][ch][bnd] = calc_cpl_coord(energy_ch, energy_cpl); ++ } ++ blk = blk1; ++ } ++ } ++ ++ /* calculate exponents/mantissas for coupling coordinates */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ if (!block->cpl_in_use) ++ continue; ++ ++#if CONFIG_AC3ENC_FLOAT ++ s->ac3dsp.float_to_fixed24(fixed_cpl_coords[blk][1], ++ cpl_coords[blk][1], ++ s->fbw_channels * 16); ++#endif ++ s->ac3dsp.extract_exponents(block->cpl_coord_exp[1], ++ fixed_cpl_coords[blk][1], ++ s->fbw_channels * 16); ++ ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ int bnd, min_exp, max_exp, master_exp; ++ ++ if (!block->new_cpl_coords[ch]) ++ continue; ++ ++ /* determine master exponent */ ++ min_exp = max_exp = block->cpl_coord_exp[ch][0]; ++ for (bnd = 1; bnd < s->num_cpl_bands; bnd++) { ++ int exp = block->cpl_coord_exp[ch][bnd]; ++ min_exp = FFMIN(exp, min_exp); ++ max_exp = FFMAX(exp, max_exp); ++ } ++ master_exp = ((max_exp - 15) + 2) / 3; ++ master_exp = FFMAX(master_exp, 0); ++ while (min_exp < master_exp * 3) ++ master_exp--; ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ block->cpl_coord_exp[ch][bnd] = av_clip(block->cpl_coord_exp[ch][bnd] - ++ master_exp * 3, 0, 15); ++ } ++ block->cpl_master_exp[ch] = master_exp; ++ ++ /* quantize mantissas */ ++ for (bnd = 0; bnd < s->num_cpl_bands; bnd++) { ++ int cpl_exp = block->cpl_coord_exp[ch][bnd]; ++ int cpl_mant = (fixed_cpl_coords[blk][ch][bnd] << (5 + cpl_exp + master_exp * 3)) >> 24; ++ if (cpl_exp == 15) ++ cpl_mant >>= 1; ++ else ++ cpl_mant -= 16; ++ ++ block->cpl_coord_mant[ch][bnd] = cpl_mant; ++ } ++ } ++ } ++ ++ if (CONFIG_EAC3_ENCODER && s->eac3) ++ ff_eac3_set_cpl_states(s); ++} ++ ++ ++/* ++ * Determine rematrixing flags for each block and band. ++ */ ++static void compute_rematrixing_strategy(AC3EncodeContext *s) ++{ ++ int nb_coefs; ++ int blk, bnd; ++ AC3Block *block, *av_uninit(block0); ++ ++ if (s->channel_mode != AC3_CHMODE_STEREO) ++ return; ++ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ block = &s->blocks[blk]; ++ block->new_rematrixing_strategy = !blk; ++ ++ block->num_rematrixing_bands = 4; ++ if (block->cpl_in_use) { ++ block->num_rematrixing_bands -= (s->start_freq[CPL_CH] <= 61); ++ block->num_rematrixing_bands -= (s->start_freq[CPL_CH] == 37); ++ if (blk && block->num_rematrixing_bands != block0->num_rematrixing_bands) ++ block->new_rematrixing_strategy = 1; ++ } ++ nb_coefs = FFMIN(block->end_freq[1], block->end_freq[2]); ++ ++ if (!s->rematrixing_enabled) { ++ block0 = block; ++ continue; ++ } ++ ++ for (bnd = 0; bnd < block->num_rematrixing_bands; bnd++) { ++ /* calculate calculate sum of squared coeffs for one band in one block */ ++ int start = ff_ac3_rematrix_band_tab[bnd]; ++ int end = FFMIN(nb_coefs, ff_ac3_rematrix_band_tab[bnd+1]); ++ CoefSumType sum[4]; ++ sum_square_butterfly(s, sum, block->mdct_coef[1] + start, ++ block->mdct_coef[2] + start, end - start); ++ ++ /* compare sums to determine if rematrixing will be used for this band */ ++ if (FFMIN(sum[2], sum[3]) < FFMIN(sum[0], sum[1])) ++ block->rematrixing_flags[bnd] = 1; ++ else ++ block->rematrixing_flags[bnd] = 0; ++ ++ /* determine if new rematrixing flags will be sent */ ++ if (blk && ++ block->rematrixing_flags[bnd] != block0->rematrixing_flags[bnd]) { ++ block->new_rematrixing_strategy = 1; ++ } ++ } ++ block0 = block; ++ } ++} ++ ++ ++int AC3_NAME(encode_frame)(AVCodecContext *avctx, unsigned char *frame, ++ int buf_size, void *data) ++{ ++ AC3EncodeContext *s = avctx->priv_data; ++ const SampleType *samples = data; ++ int ret; ++ ++ if (s->options.allow_per_frame_metadata) { ++ ret = ff_ac3_validate_metadata(s); ++ if (ret) ++ return ret; ++ } ++ ++ if (s->bit_alloc.sr_code == 1 || s->eac3) ++ ff_ac3_adjust_frame_size(s); ++ ++ deinterleave_input_samples(s, samples); ++ ++ apply_mdct(s); ++ ++ if (s->fixed_point) ++ scale_coefficients(s); ++ ++ clip_coefficients(&s->dsp, s->blocks[0].mdct_coef[1], ++ AC3_MAX_COEFS * s->num_blocks * s->channels); ++ ++ s->cpl_on = s->cpl_enabled; ++ ff_ac3_compute_coupling_strategy(s); ++ ++ if (s->cpl_on) ++ apply_channel_coupling(s); ++ ++ compute_rematrixing_strategy(s); ++ ++ if (!s->fixed_point) ++ scale_coefficients(s); ++ ++ ff_ac3_apply_rematrixing(s); ++ ++ ff_ac3_process_exponents(s); ++ ++ ret = ff_ac3_compute_bit_allocation(s); ++ if (ret) { ++ av_log(avctx, AV_LOG_ERROR, "Bit allocation failed. Try increasing the bitrate.\n"); ++ return ret; ++ } ++ ++ ff_ac3_group_exponents(s); ++ ++ ff_ac3_quantize_mantissas(s); ++ ++ ff_ac3_output_frame(s, frame); ++ ++ return s->frame_size; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3.h 2012-05-14 14:08:53.317319513 +0200 +@@ -28,7 +28,8 @@ + #define AVCODEC_AC3_H + + #define AC3_MAX_CODED_FRAME_SIZE 3840 /* in bytes */ +-#define AC3_MAX_CHANNELS 6 /* including LFE channel */ ++#define AC3_MAX_CHANNELS 7 /**< maximum number of channels, including coupling channel */ ++#define CPL_CH 0 /**< coupling channel index */ + + #define AC3_MAX_COEFS 256 + #define AC3_BLOCK_SIZE 256 +@@ -36,7 +37,10 @@ + #define AC3_FRAME_SIZE (AC3_MAX_BLOCKS * 256) + #define AC3_WINDOW_SIZE (AC3_BLOCK_SIZE * 2) + #define AC3_CRITICAL_BANDS 50 ++#define AC3_MAX_CPL_BANDS 18 + ++#include "libavutil/opt.h" ++#include "avcodec.h" + #include "ac3tab.h" + + /* exponent encoding strategy */ +@@ -47,6 +51,17 @@ + #define EXP_D25 2 + #define EXP_D45 3 + ++/* pre-defined gain values */ ++#define LEVEL_PLUS_3DB 1.4142135623730950 ++#define LEVEL_PLUS_1POINT5DB 1.1892071150027209 ++#define LEVEL_MINUS_1POINT5DB 0.8408964152537145 ++#define LEVEL_MINUS_3DB 0.7071067811865476 ++#define LEVEL_MINUS_4POINT5DB 0.5946035575013605 ++#define LEVEL_MINUS_6DB 0.5000000000000000 ++#define LEVEL_MINUS_9DB 0.3535533905932738 ++#define LEVEL_ZERO 0.0000000000000000 ++#define LEVEL_ONE 1.0000000000000000 ++ + /** Delta bit allocation strategy */ + typedef enum { + DBA_REUSE = 0, +@@ -79,13 +94,14 @@ + * Coded AC-3 header values up to the lfeon element, plus derived values. + */ + typedef struct { +- /** @defgroup coded Coded elements ++ /** @name Coded elements + * @{ + */ + uint16_t sync_word; + uint16_t crc1; + uint8_t sr_code; + uint8_t bitstream_id; ++ uint8_t bitstream_mode; + uint8_t channel_mode; + uint8_t lfe_on; + uint8_t frame_type; +@@ -96,7 +112,7 @@ + int num_blocks; ///< number of audio blocks + /** @} */ + +- /** @defgroup derived Derived values ++ /** @name Derived values + * @{ + */ + uint8_t sr_shift; +@@ -104,7 +120,7 @@ + uint32_t bit_rate; + uint8_t channels; + uint16_t frame_size; +- int64_t channel_layout; ++ uint64_t channel_layout; + /** @} */ + } AC3HeaderInfo; + +@@ -162,23 +178,4 @@ + uint8_t *dba_lengths, uint8_t *dba_values, + int16_t *mask); + +-/** +- * Calculate bit allocation pointers. +- * The SNR is the difference between the masking curve and the signal. AC-3 +- * uses this value for each frequency bin to allocate bits. The snroffset +- * parameter is a global adjustment to the SNR for all bins. +- * +- * @param[in] mask masking curve +- * @param[in] psd signal power for each frequency bin +- * @param[in] start starting bin location +- * @param[in] end ending bin location +- * @param[in] snr_offset SNR adjustment +- * @param[in] floor noise floor +- * @param[in] bap_tab look-up table for bit allocation pointers +- * @param[out] bap bit allocation pointers +- */ +-void ff_ac3_bit_alloc_calc_bap(int16_t *mask, int16_t *psd, int start, int end, +- int snr_offset, int floor, +- const uint8_t *bap_tab, uint8_t *bap); +- + #endif /* AVCODEC_AC3_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3_parser.c 2012-05-14 14:08:53.318319533 +0200 +@@ -24,6 +24,7 @@ + #include "ac3_parser.h" + #include "aac_ac3_parser.h" + #include "get_bits.h" ++#include "libavutil/audioconvert.h" + + + #define AC3_HEADER_SIZE 7 +@@ -33,8 +34,20 @@ + 1, 2, 3, 6 + }; + ++/** ++ * Table for center mix levels ++ * reference: Section 5.4.2.4 cmixlev ++ */ ++static const uint8_t center_levels[4] = { 4, 5, 6, 5 }; ++ ++/** ++ * Table for surround mix levels ++ * reference: Section 5.4.2.5 surmixlev ++ */ ++static const uint8_t surround_levels[4] = { 4, 6, 7, 6 }; + +-int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) ++ ++int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr) + { + int frame_size_code; + +@@ -52,8 +65,8 @@ + hdr->num_blocks = 6; + + /* set default mix levels */ +- hdr->center_mix_level = 1; // -4.5dB +- hdr->surround_mix_level = 1; // -6.0dB ++ hdr->center_mix_level = 5; // -4.5dB ++ hdr->surround_mix_level = 6; // -6.0dB + + if(hdr->bitstream_id <= 10) { + /* Normal AC-3 */ +@@ -68,16 +81,16 @@ + + skip_bits(gbc, 5); // skip bsid, already got it + +- skip_bits(gbc, 3); // skip bitstream mode ++ hdr->bitstream_mode = get_bits(gbc, 3); + hdr->channel_mode = get_bits(gbc, 3); + + if(hdr->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 2); // skip dsurmod + } else { + if((hdr->channel_mode & 1) && hdr->channel_mode != AC3_CHMODE_MONO) +- hdr->center_mix_level = get_bits(gbc, 2); ++ hdr-> center_mix_level = center_levels[get_bits(gbc, 2)]; + if(hdr->channel_mode & 4) +- hdr->surround_mix_level = get_bits(gbc, 2); ++ hdr->surround_mix_level = surround_levels[get_bits(gbc, 2)]; + } + hdr->lfe_on = get_bits1(gbc); + +@@ -121,9 +134,9 @@ + (hdr->num_blocks * 256.0)); + hdr->channels = ff_ac3_channels_tab[hdr->channel_mode] + hdr->lfe_on; + } +- hdr->channel_layout = ff_ac3_channel_layout_tab[hdr->channel_mode]; ++ hdr->channel_layout = avpriv_ac3_channel_layout_tab[hdr->channel_mode]; + if (hdr->lfe_on) +- hdr->channel_layout |= CH_LOW_FREQUENCY; ++ hdr->channel_layout |= AV_CH_LOW_FREQUENCY; + + return 0; + } +@@ -140,7 +153,7 @@ + GetBitContext gbc; + + init_get_bits(&gbc, tmp.u8+8-AC3_HEADER_SIZE, 54); +- err = ff_ac3_parse_header(&gbc, &hdr); ++ err = avpriv_ac3_parse_header(&gbc, &hdr); + + if(err < 0) + return 0; +@@ -150,6 +163,9 @@ + hdr_info->channels = hdr.channels; + hdr_info->channel_layout = hdr.channel_layout; + hdr_info->samples = hdr.num_blocks * 256; ++ hdr_info->service_type = hdr.bitstream_mode; ++ if (hdr.bitstream_mode == 0x7 && hdr.channels > 1) ++ hdr_info->service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; + if(hdr.bitstream_id>10) + hdr_info->codec_id = CODEC_ID_EAC3; + else if (hdr_info->codec_id == CODEC_ID_NONE) +@@ -170,9 +186,9 @@ + + + AVCodecParser ff_ac3_parser = { +- { CODEC_ID_AC3, CODEC_ID_EAC3 }, +- sizeof(AACAC3ParseContext), +- ac3_parse_init, +- ff_aac_ac3_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_AC3, CODEC_ID_EAC3 }, ++ .priv_data_size = sizeof(AACAC3ParseContext), ++ .parser_init = ac3_parse_init, ++ .parser_parse = ff_aac_ac3_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3_parser.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3_parser.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3_parser.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3_parser.h 2012-05-14 14:08:53.318319533 +0200 +@@ -36,6 +36,6 @@ + * -2 if the bsid (version) element is invalid, -3 if the fscod (sample rate) + * element is invalid, or -4 if the frmsizecod (bit rate) element is invalid. + */ +-int ff_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); ++int avpriv_ac3_parse_header(GetBitContext *gbc, AC3HeaderInfo *hdr); + + #endif /* AVCODEC_AC3_PARSER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3tab.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3tab.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3tab.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3tab.c 2012-05-14 14:08:53.345320077 +0200 +@@ -24,7 +24,7 @@ + * tables taken directly from the AC-3 spec. + */ + +-#include "libavcore/audioconvert.h" ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "ac3tab.h" + +@@ -84,7 +84,7 @@ + /** + * Map audio coding mode (acmod) to channel layout mask. + */ +-const uint16_t ff_ac3_channel_layout_tab[8] = { ++const uint16_t avpriv_ac3_channel_layout_tab[8] = { + AV_CH_LAYOUT_STEREO, + AV_CH_LAYOUT_MONO, + AV_CH_LAYOUT_STEREO, +@@ -138,10 +138,17 @@ + */ + const uint8_t ff_ac3_rematrix_band_tab[5] = { 13, 25, 37, 61, 253 }; + ++/** ++ * Table E2.16 Default Coupling Banding Structure ++ */ ++const uint8_t ff_eac3_default_cpl_band_struct[18] = { ++ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1 ++}; ++ + /* AC-3 MDCT window */ + + /* MDCT window */ +-const int16_t ff_ac3_window[AC3_WINDOW_SIZE/2] = { ++DECLARE_ALIGNED(16, const int16_t, ff_ac3_window)[AC3_WINDOW_SIZE/2] = { + 4, 7, 12, 16, 21, 28, 34, 42, + 51, 61, 72, 84, 97, 111, 127, 145, + 164, 184, 207, 231, 257, 285, 315, 347, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3tab.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3tab.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ac3tab.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ac3tab.h 2012-05-14 14:08:53.346320097 +0200 +@@ -25,14 +25,21 @@ + #include "libavutil/common.h" + #include "ac3.h" + ++#if CONFIG_HARDCODED_TABLES ++# define HCONST const ++#else ++# define HCONST ++#endif ++ + extern const uint16_t ff_ac3_frame_size_tab[38][3]; + extern const uint8_t ff_ac3_channels_tab[8]; +-extern const uint16_t ff_ac3_channel_layout_tab[8]; ++extern const uint16_t avpriv_ac3_channel_layout_tab[8]; + extern const uint8_t ff_ac3_enc_channel_map[8][2][6]; + extern const uint8_t ff_ac3_dec_channel_map[8][2][6]; + extern const uint16_t ff_ac3_sample_rate_tab[3]; + extern const uint16_t ff_ac3_bitrate_tab[19]; + extern const uint8_t ff_ac3_rematrix_band_tab[5]; ++extern const uint8_t ff_eac3_default_cpl_band_struct[18]; + extern const int16_t ff_ac3_window[AC3_WINDOW_SIZE/2]; + extern const uint8_t ff_ac3_log_add_tab[260]; + extern const uint16_t ff_ac3_hearing_threshold_tab[AC3_CRITICAL_BANDS][3]; +@@ -44,6 +51,8 @@ + extern const int16_t ff_ac3_floor_tab[8]; + extern const uint16_t ff_ac3_fast_gain_tab[8]; + extern const uint16_t ff_eac3_default_chmap[8]; ++extern const uint8_t ff_ac3_band_start_tab[AC3_CRITICAL_BANDS+1]; ++extern HCONST uint8_t ff_ac3_bin_to_band_tab[253]; + + /** Custom channel map locations bitmask + * Other channels described in documentation: +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_filters.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_filters.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_filters.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_filters.h 2012-05-14 14:08:53.347320117 +0200 +@@ -76,7 +76,7 @@ + * + * The filter has a cut-off frequency of 1/80 of the sampling freq + * +- * @note Two items before the top of the out buffer must contain two items from the ++ * @note Two items before the top of the in buffer must contain two items from the + * tail of the previous subframe. + * + * @remark It is safe to pass the same array in in and out parameters. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_pitch_delay.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_pitch_delay.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_pitch_delay.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_pitch_delay.c 2012-05-14 14:08:53.347320117 +0200 +@@ -20,6 +20,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "avcodec.h" + #include "dsputil.h" + #include "acelp_pitch_delay.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_pitch_delay.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_pitch_delay.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_pitch_delay.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_pitch_delay.h 2012-05-14 14:08:53.348320137 +0200 +@@ -30,11 +30,11 @@ + #define PITCH_DELAY_MAX 143 + + /** +- * \brief Decode pitch delay of the first subframe encoded by 8 bits with 1/3 ++ * @brief Decode pitch delay of the first subframe encoded by 8 bits with 1/3 + * resolution. +- * \param ac_index adaptive codebook index (8 bits) ++ * @param ac_index adaptive codebook index (8 bits) + * +- * \return pitch delay in 1/3 units ++ * @return pitch delay in 1/3 units + * + * Pitch delay is coded: + * with 1/3 resolution, 19 < pitch_delay < 85 +@@ -43,18 +43,18 @@ + int ff_acelp_decode_8bit_to_1st_delay3(int ac_index); + + /** +- * \brief Decode pitch delay of the second subframe encoded by 5 or 6 bits ++ * @brief Decode pitch delay of the second subframe encoded by 5 or 6 bits + * with 1/3 precision. +- * \param ac_index adaptive codebook index (5 or 6 bits) +- * \param pitch_delay_min lower bound (integer) of pitch delay interval ++ * @param ac_index adaptive codebook index (5 or 6 bits) ++ * @param pitch_delay_min lower bound (integer) of pitch delay interval + * for second subframe + * +- * \return pitch delay in 1/3 units ++ * @return pitch delay in 1/3 units + * + * Pitch delay is coded: + * with 1/3 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5 + * +- * \remark The routine is used in G.729 @@8k, AMR @@10.2k, AMR @@7.95k, ++ * @remark The routine is used in G.729 @@8k, AMR @@10.2k, AMR @@7.95k, + * AMR @@7.4k for the second subframe. + */ + int ff_acelp_decode_5_6_bit_to_2nd_delay3( +@@ -62,19 +62,19 @@ + int pitch_delay_min); + + /** +- * \brief Decode pitch delay with 1/3 precision. +- * \param ac_index adaptive codebook index (4 bits) +- * \param pitch_delay_min lower bound (integer) of pitch delay interval for ++ * @brief Decode pitch delay with 1/3 precision. ++ * @param ac_index adaptive codebook index (4 bits) ++ * @param pitch_delay_min lower bound (integer) of pitch delay interval for + * second subframe + * +- * \return pitch delay in 1/3 units ++ * @return pitch delay in 1/3 units + * + * Pitch delay is coded: + * integers only, -6 < pitch_delay - int(prev_pitch_delay) <= -2 + * with 1/3 resolution, -2 < pitch_delay - int(prev_pitch_delay) < 1 + * integers only, 1 <= pitch_delay - int(prev_pitch_delay) < 5 + * +- * \remark The routine is used in G.729 @@6.4k, AMR @@6.7k, AMR @@5.9k, ++ * @remark The routine is used in G.729 @@6.4k, AMR @@6.7k, AMR @@5.9k, + * AMR @@5.15k, AMR @@4.75k for the second subframe. + */ + int ff_acelp_decode_4bit_to_2nd_delay3( +@@ -82,44 +82,44 @@ + int pitch_delay_min); + + /** +- * \brief Decode pitch delay of the first subframe encoded by 9 bits ++ * @brief Decode pitch delay of the first subframe encoded by 9 bits + * with 1/6 precision. +- * \param ac_index adaptive codebook index (9 bits) ++ * @param ac_index adaptive codebook index (9 bits) + * +- * \return pitch delay in 1/6 units ++ * @return pitch delay in 1/6 units + * + * Pitch delay is coded: + * with 1/6 resolution, 17 < pitch_delay < 95 + * integers only, 95 <= pitch_delay <= 143 + * +- * \remark The routine is used in AMR @@12.2k for the first and third subframes. ++ * @remark The routine is used in AMR @@12.2k for the first and third subframes. + */ + int ff_acelp_decode_9bit_to_1st_delay6(int ac_index); + + /** +- * \brief Decode pitch delay of the second subframe encoded by 6 bits ++ * @brief Decode pitch delay of the second subframe encoded by 6 bits + * with 1/6 precision. +- * \param ac_index adaptive codebook index (6 bits) +- * \param pitch_delay_min lower bound (integer) of pitch delay interval for ++ * @param ac_index adaptive codebook index (6 bits) ++ * @param pitch_delay_min lower bound (integer) of pitch delay interval for + * second subframe + * +- * \return pitch delay in 1/6 units ++ * @return pitch delay in 1/6 units + * + * Pitch delay is coded: + * with 1/6 resolution, -6 < pitch_delay - int(prev_pitch_delay) < 5 + * +- * \remark The routine is used in AMR @@12.2k for the second and fourth subframes. ++ * @remark The routine is used in AMR @@12.2k for the second and fourth subframes. + */ + int ff_acelp_decode_6bit_to_2nd_delay6( + int ac_index, + int pitch_delay_min); + + /** +- * \brief Update past quantized energies +- * \param[in,out] quant_energy past quantized energies (5.10) +- * \param gain_corr_factor gain correction factor +- * \param log2_ma_pred_order log2() of MA prediction order +- * \param erasure frame erasure flag ++ * @brief Update past quantized energies ++ * @param[in,out] quant_energy past quantized energies (5.10) ++ * @param gain_corr_factor gain correction factor ++ * @param log2_ma_pred_order log2() of MA prediction order ++ * @param erasure frame erasure flag + * + * If frame erasure flag is not equal to zero, memory is updated with + * averaged energy, attenuated by 4dB: +@@ -128,7 +128,7 @@ + * In normal mode memory is updated with + * Er - Ep = 20 * log10(gain_corr_factor) + * +- * \remark The routine is used in G.729 and AMR (all modes). ++ * @remark The routine is used in G.729 and AMR (all modes). + */ + void ff_acelp_update_past_gain( + int16_t* quant_energy, +@@ -137,16 +137,16 @@ + int erasure); + + /** +- * \brief Decode the adaptive codebook gain and add ++ * @brief Decode the adaptive codebook gain and add + * correction (4.1.5 and 3.9.1 of G.729). +- * \param dsp initialized dsputil context +- * \param gain_corr_factor gain correction factor (2.13) +- * \param fc_v fixed-codebook vector (2.13) +- * \param mr_energy mean innovation energy and fixed-point correction (7.13) +- * \param[in,out] quant_energy past quantized energies (5.10) +- * \param subframe_size length of subframe ++ * @param dsp initialized dsputil context ++ * @param gain_corr_factor gain correction factor (2.13) ++ * @param fc_v fixed-codebook vector (2.13) ++ * @param mr_energy mean innovation energy and fixed-point correction (7.13) ++ * @param[in,out] quant_energy past quantized energies (5.10) ++ * @param subframe_size length of subframe + * +- * \return quantized fixed-codebook gain (14.1) ++ * @return quantized fixed-codebook gain (14.1) + * + * The routine implements equations 69, 66 and 71 of the G.729 specification (3.9.1) + * +@@ -205,7 +205,7 @@ + * + * mr_energy = Em + 10log(N) + 10log(2^26) + * +- * \remark The routine is used in G.729 and AMR (all modes). ++ * @remark The routine is used in G.729 and AMR (all modes). + */ + int16_t ff_acelp_decode_gain_code( + DSPContext *dsp, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_vectors.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_vectors.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/acelp_vectors.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/acelp_vectors.c 2012-05-14 14:08:53.349320157 +0200 +@@ -93,16 +93,6 @@ + 78, 79, + }; + +-#if 0 +-static uint8_t gray_decode[32] = +-{ +- 0, 1, 3, 2, 7, 6, 4, 5, +- 15, 14, 12, 13, 8, 9, 11, 10, +- 31, 30, 28, 29, 24, 25, 27, 26, +- 16, 17, 19, 18, 23, 22, 20, 21 +-}; +-#endif +- + const float ff_pow_0_7[10] = { + 0.700000, 0.490000, 0.343000, 0.240100, 0.168070, + 0.117649, 0.082354, 0.057648, 0.040354, 0.028248 +@@ -247,11 +237,12 @@ + int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1); + float y = in->y[i] * scale; + +- do { +- out[x] += y; +- y *= in->pitch_fac; +- x += in->pitch_lag; +- } while (x < size && repeats); ++ if (in->pitch_lag > 0) ++ do { ++ out[x] += y; ++ y *= in->pitch_fac; ++ x += in->pitch_lag; ++ } while (x < size && repeats); + } + } + +@@ -262,9 +253,10 @@ + for (i=0; i < in->n; i++) { + int x = in->x[i], repeats = !((in->no_repeat_mask >> i) & 1); + +- do { +- out[x] = 0.0; +- x += in->pitch_lag; +- } while (x < size && repeats); ++ if (in->pitch_lag > 0) ++ do { ++ out[x] = 0.0; ++ x += in->pitch_lag; ++ } while (x < size && repeats); + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm.c 2012-05-14 14:08:53.356320299 +0200 +@@ -1,5 +1,4 @@ + /* +- * ADPCM codecs + * Copyright (c) 2001-2003 The ffmpeg Project + * + * This file is part of FFmpeg. +@@ -22,10 +21,12 @@ + #include "get_bits.h" + #include "put_bits.h" + #include "bytestream.h" ++#include "adpcm.h" ++#include "adpcm_data.h" + + /** + * @file +- * ADPCM codecs. ++ * ADPCM decoders + * First version by Francois Revol (revol@free.fr) + * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) + * by Mike Melanson (melanson@pcisys.net) +@@ -41,73 +42,35 @@ + * Features and limitations: + * + * Reference documents: +- * http://www.pcisys.net/~melanson/codecs/simpleaudio.html +- * http://www.geocities.com/SiliconValley/8682/aud3.txt +- * http://openquicktime.sourceforge.net/plugins.htm +- * XAnim sources (xa_codec.c) http://www.rasnaimaging.com/people/lapus/download.html +- * http://www.cs.ucla.edu/~leec/mediabench/applications.html +- * SoX source code http://home.sprynet.com/~cbagwell/sox.html ++ * http://wiki.multimedia.cx/index.php?title=Category:ADPCM_Audio_Codecs ++ * http://www.pcisys.net/~melanson/codecs/simpleaudio.html [dead] ++ * http://www.geocities.com/SiliconValley/8682/aud3.txt [dead] ++ * http://openquicktime.sourceforge.net/ ++ * XAnim sources (xa_codec.c) http://xanim.polter.net/ ++ * http://www.cs.ucla.edu/~leec/mediabench/applications.html [dead] ++ * SoX source code http://sox.sourceforge.net/ + * + * CD-ROM XA: +- * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html +- * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html ++ * http://ku-www.ss.titech.ac.jp/~yatsushi/xaadpcm.html [dead] ++ * vagpack & depack http://homepages.compuserve.de/bITmASTER32/psx-index.html [dead] + * readstr http://www.geocities.co.jp/Playtown/2004/ + */ + +-#define BLKSIZE 1024 +- +-/* step_table[] and index_table[] are from the ADPCM reference source */ +-/* This is the index table: */ +-static const int index_table[16] = { +- -1, -1, -1, -1, 2, 4, 6, 8, +- -1, -1, -1, -1, 2, 4, 6, 8, +-}; +- +-/** +- * This is the step table. Note that many programs use slight deviations from +- * this table, but such deviations are negligible: +- */ +-static const int step_table[89] = { +- 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, +- 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, +- 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, +- 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, +- 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, +- 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, +- 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, +- 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, +- 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 +-}; +- +-/* These are for MS-ADPCM */ +-/* AdaptationTable[], AdaptCoeff1[], and AdaptCoeff2[] are from libsndfile */ +-static const int AdaptationTable[] = { +- 230, 230, 230, 230, 307, 409, 512, 614, +- 768, 614, 512, 409, 307, 230, 230, 230 +-}; +- +-/** Divided by 4 to fit in 8-bit integers */ +-static const uint8_t AdaptCoeff1[] = { +- 64, 128, 0, 48, 60, 115, 98 +-}; +- +-/** Divided by 4 to fit in 8-bit integers */ +-static const int8_t AdaptCoeff2[] = { +- 0, -64, 0, 16, 0, -52, -58 +-}; +- + /* These are for CD-ROM XA ADPCM */ + static const int xa_adpcm_table[5][2] = { +- { 0, 0 }, +- { 60, 0 }, +- { 115, -52 }, +- { 98, -55 }, +- { 122, -60 } ++ { 0, 0 }, ++ { 60, 0 }, ++ { 115, -52 }, ++ { 98, -55 }, ++ { 122, -60 } + }; + + static const int ea_adpcm_table[] = { +- 0, 240, 460, 392, 0, 0, -208, -220, 0, 1, +- 3, 4, 7, 8, 10, 11, 0, -1, -3, -4 ++ 0, 240, 460, 392, ++ 0, 0, -208, -220, ++ 0, 1, 3, 4, ++ 7, 8, 10, 11, ++ 0, -1, -3, -4 + }; + + // padded to zero where table size is less then 16 +@@ -118,643 +81,34 @@ + /*5*/ { -1, -1, -1, -1, -1, -1, -1, -1, 1, 2, 4, 6, 8, 10, 13, 16 } + }; + +-static const int yamaha_indexscale[] = { +- 230, 230, 230, 230, 307, 409, 512, 614, +- 230, 230, 230, 230, 307, 409, 512, 614 +-}; +- +-static const int yamaha_difflookup[] = { +- 1, 3, 5, 7, 9, 11, 13, 15, +- -1, -3, -5, -7, -9, -11, -13, -15 +-}; +- + /* end of tables */ + +-typedef struct ADPCMChannelStatus { +- int predictor; +- short int step_index; +- int step; +- /* for encoding */ +- int prev_sample; +- +- /* MS version */ +- short sample1; +- short sample2; +- int coeff1; +- int coeff2; +- int idelta; +-} ADPCMChannelStatus; +- +-typedef struct TrellisPath { +- int nibble; +- int prev; +-} TrellisPath; +- +-typedef struct TrellisNode { +- uint32_t ssd; +- int path; +- int sample1; +- int sample2; +- int step; +-} TrellisNode; +- +-typedef struct ADPCMContext { ++typedef struct ADPCMDecodeContext { ++ AVFrame frame; + ADPCMChannelStatus status[6]; +- TrellisPath *paths; +- TrellisNode *node_buf; +- TrellisNode **nodep_buf; +- uint8_t *trellis_hash; +-} ADPCMContext; +- +-#define FREEZE_INTERVAL 128 +- +-/* XXX: implement encoding */ +- +-#if CONFIG_ENCODERS +-static av_cold int adpcm_encode_init(AVCodecContext *avctx) +-{ +- ADPCMContext *s = avctx->priv_data; +- uint8_t *extradata; +- int i; +- if (avctx->channels > 2) +- return -1; /* only stereo or mono =) */ +- +- if(avctx->trellis && (unsigned)avctx->trellis > 16U){ +- av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n"); +- return -1; +- } +- +- if (avctx->trellis) { +- int frontier = 1 << avctx->trellis; +- int max_paths = frontier * FREEZE_INTERVAL; +- FF_ALLOC_OR_GOTO(avctx, s->paths, max_paths * sizeof(*s->paths), error); +- FF_ALLOC_OR_GOTO(avctx, s->node_buf, 2 * frontier * sizeof(*s->node_buf), error); +- FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, 2 * frontier * sizeof(*s->nodep_buf), error); +- FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, 65536 * sizeof(*s->trellis_hash), error); +- } +- +- switch(avctx->codec->id) { +- case CODEC_ID_ADPCM_IMA_WAV: +- avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / (4 * avctx->channels) + 1; /* each 16 bits sample gives one nibble */ +- /* and we have 4 bytes per channel overhead */ +- avctx->block_align = BLKSIZE; +- /* seems frame_size isn't taken into account... have to buffer the samples :-( */ +- break; +- case CODEC_ID_ADPCM_IMA_QT: +- avctx->frame_size = 64; +- avctx->block_align = 34 * avctx->channels; +- break; +- case CODEC_ID_ADPCM_MS: +- avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; /* each 16 bits sample gives one nibble */ +- /* and we have 7 bytes per channel overhead */ +- avctx->block_align = BLKSIZE; +- avctx->extradata_size = 32; +- extradata = avctx->extradata = av_malloc(avctx->extradata_size); +- if (!extradata) +- return AVERROR(ENOMEM); +- bytestream_put_le16(&extradata, avctx->frame_size); +- bytestream_put_le16(&extradata, 7); /* wNumCoef */ +- for (i = 0; i < 7; i++) { +- bytestream_put_le16(&extradata, AdaptCoeff1[i] * 4); +- bytestream_put_le16(&extradata, AdaptCoeff2[i] * 4); +- } +- break; +- case CODEC_ID_ADPCM_YAMAHA: +- avctx->frame_size = BLKSIZE * avctx->channels; +- avctx->block_align = BLKSIZE; +- break; +- case CODEC_ID_ADPCM_SWF: +- if (avctx->sample_rate != 11025 && +- avctx->sample_rate != 22050 && +- avctx->sample_rate != 44100) { +- av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, 22050 or 44100\n"); +- goto error; +- } +- avctx->frame_size = 512 * (avctx->sample_rate / 11025); +- break; +- default: +- goto error; +- } +- +- avctx->coded_frame= avcodec_alloc_frame(); +- avctx->coded_frame->key_frame= 1; +- +- return 0; +-error: +- av_freep(&s->paths); +- av_freep(&s->node_buf); +- av_freep(&s->nodep_buf); +- av_freep(&s->trellis_hash); +- return -1; +-} +- +-static av_cold int adpcm_encode_close(AVCodecContext *avctx) +-{ +- ADPCMContext *s = avctx->priv_data; +- av_freep(&avctx->coded_frame); +- av_freep(&s->paths); +- av_freep(&s->node_buf); +- av_freep(&s->nodep_buf); +- av_freep(&s->trellis_hash); +- +- return 0; +-} +- +- +-static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, short sample) +-{ +- int delta = sample - c->prev_sample; +- int nibble = FFMIN(7, abs(delta)*4/step_table[c->step_index]) + (delta<0)*8; +- c->prev_sample += ((step_table[c->step_index] * yamaha_difflookup[nibble]) / 8); +- c->prev_sample = av_clip_int16(c->prev_sample); +- c->step_index = av_clip(c->step_index + index_table[nibble], 0, 88); +- return nibble; +-} +- +-static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, short sample) +-{ +- int predictor, nibble, bias; +- +- predictor = (((c->sample1) * (c->coeff1)) + ((c->sample2) * (c->coeff2))) / 64; +- +- nibble= sample - predictor; +- if(nibble>=0) bias= c->idelta/2; +- else bias=-c->idelta/2; +- +- nibble= (nibble + bias) / c->idelta; +- nibble= av_clip(nibble, -8, 7)&0x0F; +- +- predictor += (signed)((nibble & 0x08)?(nibble - 0x10):(nibble)) * c->idelta; +- +- c->sample2 = c->sample1; +- c->sample1 = av_clip_int16(predictor); +- +- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8; +- if (c->idelta < 16) c->idelta = 16; +- +- return nibble; +-} +- +-static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, short sample) +-{ +- int nibble, delta; +- +- if(!c->step) { +- c->predictor = 0; +- c->step = 127; +- } +- +- delta = sample - c->predictor; +- +- nibble = FFMIN(7, abs(delta)*4/c->step) + (delta<0)*8; +- +- c->predictor += ((c->step * yamaha_difflookup[nibble]) / 8); +- c->predictor = av_clip_int16(c->predictor); +- c->step = (c->step * yamaha_indexscale[nibble]) >> 8; +- c->step = av_clip(c->step, 127, 24567); +- +- return nibble; +-} +- +-static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, +- uint8_t *dst, ADPCMChannelStatus *c, int n) +-{ +- //FIXME 6% faster if frontier is a compile-time constant +- ADPCMContext *s = avctx->priv_data; +- const int frontier = 1 << avctx->trellis; +- const int stride = avctx->channels; +- const int version = avctx->codec->id; +- TrellisPath *paths = s->paths, *p; +- TrellisNode *node_buf = s->node_buf; +- TrellisNode **nodep_buf = s->nodep_buf; +- TrellisNode **nodes = nodep_buf; // nodes[] is always sorted by .ssd +- TrellisNode **nodes_next = nodep_buf + frontier; +- int pathn = 0, froze = -1, i, j, k, generation = 0; +- uint8_t *hash = s->trellis_hash; +- memset(hash, 0xff, 65536 * sizeof(*hash)); +- +- memset(nodep_buf, 0, 2 * frontier * sizeof(*nodep_buf)); +- nodes[0] = node_buf + frontier; +- nodes[0]->ssd = 0; +- nodes[0]->path = 0; +- nodes[0]->step = c->step_index; +- nodes[0]->sample1 = c->sample1; +- nodes[0]->sample2 = c->sample2; +- if((version == CODEC_ID_ADPCM_IMA_WAV) || (version == CODEC_ID_ADPCM_IMA_QT) || (version == CODEC_ID_ADPCM_SWF)) +- nodes[0]->sample1 = c->prev_sample; +- if(version == CODEC_ID_ADPCM_MS) +- nodes[0]->step = c->idelta; +- if(version == CODEC_ID_ADPCM_YAMAHA) { +- if(c->step == 0) { +- nodes[0]->step = 127; +- nodes[0]->sample1 = 0; +- } else { +- nodes[0]->step = c->step; +- nodes[0]->sample1 = c->predictor; +- } +- } +- +- for(i=0; istep; +- int nidx; +- if(version == CODEC_ID_ADPCM_MS) { +- const int predictor = ((nodes[j]->sample1 * c->coeff1) + (nodes[j]->sample2 * c->coeff2)) / 64; +- const int div = (sample - predictor) / step; +- const int nmin = av_clip(div-range, -8, 6); +- const int nmax = av_clip(div+range, -7, 7); +- for(nidx=nmin; nidx<=nmax; nidx++) { +- const int nibble = nidx & 0xf; +- int dec_sample = predictor + nidx * step; +-#define STORE_NODE(NAME, STEP_INDEX)\ +- int d;\ +- uint32_t ssd;\ +- int pos;\ +- TrellisNode *u;\ +- uint8_t *h;\ +- dec_sample = av_clip_int16(dec_sample);\ +- d = sample - dec_sample;\ +- ssd = nodes[j]->ssd + d*d;\ +- /* Check for wraparound, skip such samples completely. \ +- * Note, changing ssd to a 64 bit variable would be \ +- * simpler, avoiding this check, but it's slower on \ +- * x86 32 bit at the moment. */\ +- if (ssd < nodes[j]->ssd)\ +- goto next_##NAME;\ +- /* Collapse any two states with the same previous sample value. \ +- * One could also distinguish states by step and by 2nd to last +- * sample, but the effects of that are negligible. +- * Since nodes in the previous generation are iterated +- * through a heap, they're roughly ordered from better to +- * worse, but not strictly ordered. Therefore, an earlier +- * node with the same sample value is better in most cases +- * (and thus the current is skipped), but not strictly +- * in all cases. Only skipping samples where ssd >= +- * ssd of the earlier node with the same sample gives +- * slightly worse quality, though, for some reason. */ \ +- h = &hash[(uint16_t) dec_sample];\ +- if (*h == generation)\ +- goto next_##NAME;\ +- if (heap_pos < frontier) {\ +- pos = heap_pos++;\ +- } else {\ +- /* Try to replace one of the leaf nodes with the new \ +- * one, but try a different slot each time. */\ +- pos = (frontier >> 1) + (heap_pos & ((frontier >> 1) - 1));\ +- if (ssd > nodes_next[pos]->ssd)\ +- goto next_##NAME;\ +- heap_pos++;\ +- }\ +- *h = generation;\ +- u = nodes_next[pos];\ +- if(!u) {\ +- assert(pathn < FREEZE_INTERVAL<trellis);\ +- u = t++;\ +- nodes_next[pos] = u;\ +- u->path = pathn++;\ +- }\ +- u->ssd = ssd;\ +- u->step = STEP_INDEX;\ +- u->sample2 = nodes[j]->sample1;\ +- u->sample1 = dec_sample;\ +- paths[u->path].nibble = nibble;\ +- paths[u->path].prev = nodes[j]->path;\ +- /* Sift the newly inserted node up in the heap to \ +- * restore the heap property. */\ +- while (pos > 0) {\ +- int parent = (pos - 1) >> 1;\ +- if (nodes_next[parent]->ssd <= ssd)\ +- break;\ +- FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\ +- pos = parent;\ +- }\ +- next_##NAME:; +- STORE_NODE(ms, FFMAX(16, (AdaptationTable[nibble] * step) >> 8)); +- } +- } else if((version == CODEC_ID_ADPCM_IMA_WAV)|| (version == CODEC_ID_ADPCM_IMA_QT)|| (version == CODEC_ID_ADPCM_SWF)) { +-#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ +- const int predictor = nodes[j]->sample1;\ +- const int div = (sample - predictor) * 4 / STEP_TABLE;\ +- int nmin = av_clip(div-range, -7, 6);\ +- int nmax = av_clip(div+range, -6, 7);\ +- if(nmin<=0) nmin--; /* distinguish -0 from +0 */\ +- if(nmax<0) nmax--;\ +- for(nidx=nmin; nidx<=nmax; nidx++) {\ +- const int nibble = nidx<0 ? 7-nidx : nidx;\ +- int dec_sample = predictor + (STEP_TABLE * yamaha_difflookup[nibble]) / 8;\ +- STORE_NODE(NAME, STEP_INDEX);\ +- } +- LOOP_NODES(ima, step_table[step], av_clip(step + index_table[nibble], 0, 88)); +- } else { //CODEC_ID_ADPCM_YAMAHA +- LOOP_NODES(yamaha, step, av_clip((step * yamaha_indexscale[nibble]) >> 8, 127, 24567)); +-#undef LOOP_NODES +-#undef STORE_NODE +- } +- } +- +- u = nodes; +- nodes = nodes_next; +- nodes_next = u; +- +- generation++; +- if (generation == 255) { +- memset(hash, 0xff, 65536 * sizeof(*hash)); +- generation = 0; +- } +- +- // prevent overflow +- if(nodes[0]->ssd > (1<<28)) { +- for(j=1; jssd -= nodes[0]->ssd; +- nodes[0]->ssd = 0; +- } +- +- // merge old paths to save memory +- if(i == froze + FREEZE_INTERVAL) { +- p = &paths[nodes[0]->path]; +- for(k=i; k>froze; k--) { +- dst[k] = p->nibble; +- p = &paths[p->prev]; +- } +- froze = i; +- pathn = 0; +- // other nodes might use paths that don't coincide with the frozen one. +- // checking which nodes do so is too slow, so just kill them all. +- // this also slightly improves quality, but I don't know why. +- memset(nodes+1, 0, (frontier-1)*sizeof(TrellisNode*)); +- } +- } +- +- p = &paths[nodes[0]->path]; +- for(i=n-1; i>froze; i--) { +- dst[i] = p->nibble; +- p = &paths[p->prev]; +- } +- +- c->predictor = nodes[0]->sample1; +- c->sample1 = nodes[0]->sample1; +- c->sample2 = nodes[0]->sample2; +- c->step_index = nodes[0]->step; +- c->step = nodes[0]->step; +- c->idelta = nodes[0]->step; +-} +- +-static int adpcm_encode_frame(AVCodecContext *avctx, +- unsigned char *frame, int buf_size, void *data) +-{ +- int n, i, st; +- short *samples; +- unsigned char *dst; +- ADPCMContext *c = avctx->priv_data; +- uint8_t *buf; +- +- dst = frame; +- samples = (short *)data; +- st= avctx->channels == 2; +-/* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ +- +- switch(avctx->codec->id) { +- case CODEC_ID_ADPCM_IMA_WAV: +- n = avctx->frame_size / 8; +- c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ +-/* c->status[0].step_index = 0; *//* XXX: not sure how to init the state machine */ +- bytestream_put_le16(&dst, c->status[0].prev_sample); +- *dst++ = (unsigned char)c->status[0].step_index; +- *dst++ = 0; /* unknown */ +- samples++; +- if (avctx->channels == 2) { +- c->status[1].prev_sample = (signed short)samples[0]; +-/* c->status[1].step_index = 0; */ +- bytestream_put_le16(&dst, c->status[1].prev_sample); +- *dst++ = (unsigned char)c->status[1].step_index; +- *dst++ = 0; +- samples++; +- } +- +- /* stereo: 4 bytes (8 samples) for left, 4 bytes for right, 4 bytes left, ... */ +- if(avctx->trellis > 0) { +- FF_ALLOC_OR_GOTO(avctx, buf, 2*n*8, error); +- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n*8); +- if(avctx->channels == 2) +- adpcm_compress_trellis(avctx, samples+1, buf + n*8, &c->status[1], n*8); +- for(i=0; ichannels == 2) { +- uint8_t *buf1 = buf + n*8; +- *dst++ = buf1[8*i+0] | (buf1[8*i+1] << 4); +- *dst++ = buf1[8*i+2] | (buf1[8*i+3] << 4); +- *dst++ = buf1[8*i+4] | (buf1[8*i+5] << 4); +- *dst++ = buf1[8*i+6] | (buf1[8*i+7] << 4); +- } +- } +- av_free(buf); +- } else +- for (; n>0; n--) { +- *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]); +- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]); +- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]); +- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]); +- *dst |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4; +- dst++; +- /* right channel */ +- if (avctx->channels == 2) { +- *dst = adpcm_ima_compress_sample(&c->status[1], samples[1]); +- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[3]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[1], samples[5]); +- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[7]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[1], samples[9]); +- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4; +- dst++; +- *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]); +- *dst |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4; +- dst++; +- } +- samples += 8 * avctx->channels; +- } +- break; +- case CODEC_ID_ADPCM_IMA_QT: +- { +- int ch, i; +- PutBitContext pb; +- init_put_bits(&pb, dst, buf_size*8); +- +- for(ch=0; chchannels; ch++){ +- put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7); +- put_bits(&pb, 7, c->status[ch].step_index); +- if(avctx->trellis > 0) { +- uint8_t buf[64]; +- adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64); +- for(i=0; i<64; i++) +- put_bits(&pb, 4, buf[i^1]); +- c->status[ch].prev_sample = c->status[ch].predictor & ~0x7F; +- } else { +- for (i=0; i<64; i+=2){ +- int t1, t2; +- t1 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+0)+ch]); +- t2 = adpcm_ima_compress_sample(&c->status[ch], samples[avctx->channels*(i+1)+ch]); +- put_bits(&pb, 4, t2); +- put_bits(&pb, 4, t1); +- } +- c->status[ch].prev_sample &= ~0x7F; +- } +- } +- +- flush_put_bits(&pb); +- dst += put_bits_count(&pb)>>3; +- break; +- } +- case CODEC_ID_ADPCM_SWF: +- { +- int i; +- PutBitContext pb; +- init_put_bits(&pb, dst, buf_size*8); +- +- n = avctx->frame_size-1; +- +- //Store AdpcmCodeSize +- put_bits(&pb, 2, 2); //Set 4bits flash adpcm format +- +- //Init the encoder state +- for(i=0; ichannels; i++){ +- c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); // clip step so it fits 6 bits +- put_sbits(&pb, 16, samples[i]); +- put_bits(&pb, 6, c->status[i].step_index); +- c->status[i].prev_sample = (signed short)samples[i]; +- } +- +- if(avctx->trellis > 0) { +- FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error); +- adpcm_compress_trellis(avctx, samples+2, buf, &c->status[0], n); +- if (avctx->channels == 2) +- adpcm_compress_trellis(avctx, samples+3, buf+n, &c->status[1], n); +- for(i=0; ichannels == 2) +- put_bits(&pb, 4, buf[n+i]); +- } +- av_free(buf); +- } else { +- for (i=1; iframe_size; i++) { +- put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels*i])); +- if (avctx->channels == 2) +- put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], samples[2*i+1])); +- } +- } +- flush_put_bits(&pb); +- dst += put_bits_count(&pb)>>3; +- break; +- } +- case CODEC_ID_ADPCM_MS: +- for(i=0; ichannels; i++){ +- int predictor=0; +- +- *dst++ = predictor; +- c->status[i].coeff1 = AdaptCoeff1[predictor]; +- c->status[i].coeff2 = AdaptCoeff2[predictor]; +- } +- for(i=0; ichannels; i++){ +- if (c->status[i].idelta < 16) +- c->status[i].idelta = 16; +- +- bytestream_put_le16(&dst, c->status[i].idelta); +- } +- for(i=0; ichannels; i++){ +- c->status[i].sample2= *samples++; +- } +- for(i=0; ichannels; i++){ +- c->status[i].sample1= *samples++; +- +- bytestream_put_le16(&dst, c->status[i].sample1); +- } +- for(i=0; ichannels; i++) +- bytestream_put_le16(&dst, c->status[i].sample2); +- +- if(avctx->trellis > 0) { +- int n = avctx->block_align - 7*avctx->channels; +- FF_ALLOC_OR_GOTO(avctx, buf, 2*n, error); +- if(avctx->channels == 1) { +- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); +- for(i=0; istatus[0], n); +- adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n); +- for(i=0; ichannels; iblock_align; i++) { +- int nibble; +- nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++)<<4; +- nibble|= adpcm_ms_compress_sample(&c->status[st], *samples++); +- *dst++ = nibble; +- } +- break; +- case CODEC_ID_ADPCM_YAMAHA: +- n = avctx->frame_size / 2; +- if(avctx->trellis > 0) { +- FF_ALLOC_OR_GOTO(avctx, buf, 2*n*2, error); +- n *= 2; +- if(avctx->channels == 1) { +- adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); +- for(i=0; istatus[0], n); +- adpcm_compress_trellis(avctx, samples+1, buf+n, &c->status[1], n); +- for(i=0; ichannels; n>0; n--) { +- int nibble; +- nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++); +- nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4; +- *dst++ = nibble; +- } +- break; +- default: +- error: +- return -1; +- } +- return dst - frame; +-} +-#endif //CONFIG_ENCODERS ++ int vqa_version; /**< VQA version. Used for ADPCM_IMA_WS */ ++} ADPCMDecodeContext; + + static av_cold int adpcm_decode_init(AVCodecContext * avctx) + { +- ADPCMContext *c = avctx->priv_data; ++ ADPCMDecodeContext *c = avctx->priv_data; ++ unsigned int min_channels = 1; + unsigned int max_channels = 2; + + switch(avctx->codec->id) { ++ case CODEC_ID_ADPCM_EA: ++ min_channels = 2; ++ break; + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: ++ case CODEC_ID_ADPCM_EA_XAS: + max_channels = 6; + break; + } +- if(avctx->channels > max_channels){ +- return -1; ++ if (avctx->channels < min_channels || avctx->channels > max_channels) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); ++ return AVERROR(EINVAL); + } + + switch(avctx->codec->id) { +@@ -767,16 +121,24 @@ + return -1; + } + break; +- case CODEC_ID_ADPCM_IMA_WS: +- if (avctx->extradata && avctx->extradata_size == 2 * 4) { ++ case CODEC_ID_ADPCM_IMA_APC: ++ if (avctx->extradata && avctx->extradata_size >= 8) { + c->status[0].predictor = AV_RL32(avctx->extradata); + c->status[1].predictor = AV_RL32(avctx->extradata + 4); + } + break; ++ case CODEC_ID_ADPCM_IMA_WS: ++ if (avctx->extradata && avctx->extradata_size >= 42) ++ c->vqa_version = AV_RL16(avctx->extradata); ++ break; + default: + break; + } + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ + return 0; + } + +@@ -786,8 +148,8 @@ + int predictor; + int sign, delta, diff, step; + +- step = step_table[c->step_index]; +- step_index = c->step_index + index_table[(unsigned)nibble]; ++ step = ff_adpcm_step_table[c->step_index]; ++ step_index = c->step_index + ff_adpcm_index_table[(unsigned)nibble]; + if (step_index < 0) step_index = 0; + else if (step_index > 88) step_index = 88; + +@@ -807,6 +169,32 @@ + return (short)c->predictor; + } + ++static inline int adpcm_ima_qt_expand_nibble(ADPCMChannelStatus *c, int nibble, int shift) ++{ ++ int step_index; ++ int predictor; ++ int diff, step; ++ ++ step = ff_adpcm_step_table[c->step_index]; ++ step_index = c->step_index + ff_adpcm_index_table[nibble]; ++ step_index = av_clip(step_index, 0, 88); ++ ++ diff = step >> 3; ++ if (nibble & 4) diff += step; ++ if (nibble & 2) diff += step >> 1; ++ if (nibble & 1) diff += step >> 2; ++ ++ if (nibble & 8) ++ predictor = c->predictor - diff; ++ else ++ predictor = c->predictor + diff; ++ ++ c->predictor = av_clip_int16(predictor); ++ c->step_index = step_index; ++ ++ return c->predictor; ++} ++ + static inline short adpcm_ms_expand_nibble(ADPCMChannelStatus *c, char nibble) + { + int predictor; +@@ -816,7 +204,7 @@ + + c->sample2 = c->sample1; + c->sample1 = av_clip_int16(predictor); +- c->idelta = (AdaptationTable[(int)nibble] * c->idelta) >> 8; ++ c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8; + if (c->idelta < 16) c->idelta = 16; + + return c->sample1; +@@ -837,7 +225,7 @@ + c->predictor = ((c->predictor * 254) >> 8) + (sign ? -diff : diff); + c->predictor = av_clip_int16(c->predictor); + /* calculate new step and clamp it to range 511..32767 */ +- new_step = (AdaptationTable[nibble & 7] * c->step) >> 8; ++ new_step = (ff_adpcm_AdaptationTable[nibble & 7] * c->step) >> 8; + c->step = av_clip(new_step, 511, 32767); + + return (short)c->predictor; +@@ -870,15 +258,16 @@ + c->step = 127; + } + +- c->predictor += (c->step * yamaha_difflookup[nibble]) / 8; ++ c->predictor += (c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8; + c->predictor = av_clip_int16(c->predictor); +- c->step = (c->step * yamaha_indexscale[nibble]) >> 8; ++ c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8; + c->step = av_clip(c->step, 127, 24567); + return c->predictor; + } + +-static void xa_decode(short *out, const unsigned char *in, +- ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc) ++static int xa_decode(AVCodecContext *avctx, ++ short *out, const unsigned char *in, ++ ADPCMChannelStatus *left, ADPCMChannelStatus *right, int inc) + { + int i, j; + int shift,filter,f0,f1; +@@ -889,6 +278,12 @@ + + shift = 12 - (in[4+i*2] & 15); + filter = in[4+i*2] >> 4; ++ if (filter > 4) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid XA-ADPCM filter %d (max. allowed is 4)\n", ++ filter); ++ return AVERROR_INVALIDDATA; ++ } + f0 = xa_adpcm_table[filter][0]; + f1 = xa_adpcm_table[filter][1]; + +@@ -916,7 +311,12 @@ + + shift = 12 - (in[5+i*2] & 15); + filter = in[5+i*2] >> 4; +- ++ if (filter > 4) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid XA-ADPCM filter %d (max. allowed is 4)\n", ++ filter); ++ return AVERROR_INVALIDDATA; ++ } + f0 = xa_adpcm_table[filter][0]; + f1 = xa_adpcm_table[filter][1]; + +@@ -940,8 +340,181 @@ + left->sample2 = s_2; + } + } ++ ++ return 0; + } + ++/** ++ * Get the number of samples that will be decoded from the packet. ++ * In one case, this is actually the maximum number of samples possible to ++ * decode with the given buf_size. ++ * ++ * @param[out] coded_samples set to the number of samples as coded in the ++ * packet, or 0 if the codec does not encode the ++ * number of samples in each frame. ++ */ ++static int get_nb_samples(AVCodecContext *avctx, const uint8_t *buf, ++ int buf_size, int *coded_samples) ++{ ++ ADPCMDecodeContext *s = avctx->priv_data; ++ int nb_samples = 0; ++ int ch = avctx->channels; ++ int has_coded_samples = 0; ++ int header_size; ++ ++ *coded_samples = 0; ++ ++ if(ch <= 0) ++ return 0; ++ ++ switch (avctx->codec->id) { ++ /* constant, only check buf_size */ ++ case CODEC_ID_ADPCM_EA_XAS: ++ if (buf_size < 76 * ch) ++ return 0; ++ nb_samples = 128; ++ break; ++ case CODEC_ID_ADPCM_IMA_QT: ++ if (buf_size < 34 * ch) ++ return 0; ++ nb_samples = 64; ++ break; ++ /* simple 4-bit adpcm */ ++ case CODEC_ID_ADPCM_CT: ++ case CODEC_ID_ADPCM_IMA_APC: ++ case CODEC_ID_ADPCM_IMA_EA_SEAD: ++ case CODEC_ID_ADPCM_IMA_WS: ++ case CODEC_ID_ADPCM_YAMAHA: ++ nb_samples = buf_size * 2 / ch; ++ break; ++ } ++ if (nb_samples) ++ return nb_samples; ++ ++ /* simple 4-bit adpcm, with header */ ++ header_size = 0; ++ switch (avctx->codec->id) { ++ case CODEC_ID_ADPCM_4XM: ++ case CODEC_ID_ADPCM_IMA_ISS: header_size = 4 * ch; break; ++ case CODEC_ID_ADPCM_IMA_AMV: header_size = 8; break; ++ case CODEC_ID_ADPCM_IMA_SMJPEG: header_size = 4; break; ++ } ++ if (header_size > 0) ++ return (buf_size - header_size) * 2 / ch; ++ ++ /* more complex formats */ ++ switch (avctx->codec->id) { ++ case CODEC_ID_ADPCM_EA: ++ has_coded_samples = 1; ++ if (buf_size < 4) ++ return 0; ++ *coded_samples = AV_RL32(buf); ++ *coded_samples -= *coded_samples % 28; ++ nb_samples = (buf_size - 12) / 30 * 28; ++ break; ++ case CODEC_ID_ADPCM_IMA_EA_EACS: ++ has_coded_samples = 1; ++ if (buf_size < 4) ++ return 0; ++ *coded_samples = AV_RL32(buf); ++ nb_samples = (buf_size - (4 + 8 * ch)) * 2 / ch; ++ break; ++ case CODEC_ID_ADPCM_EA_MAXIS_XA: ++ nb_samples = ((buf_size - ch) / (2 * ch)) * 2 * ch; ++ break; ++ case CODEC_ID_ADPCM_EA_R1: ++ case CODEC_ID_ADPCM_EA_R2: ++ case CODEC_ID_ADPCM_EA_R3: ++ /* maximum number of samples */ ++ /* has internal offsets and a per-frame switch to signal raw 16-bit */ ++ has_coded_samples = 1; ++ if (buf_size < 4) ++ return 0; ++ switch (avctx->codec->id) { ++ case CODEC_ID_ADPCM_EA_R1: ++ header_size = 4 + 9 * ch; ++ *coded_samples = AV_RL32(buf); ++ break; ++ case CODEC_ID_ADPCM_EA_R2: ++ header_size = 4 + 5 * ch; ++ *coded_samples = AV_RL32(buf); ++ break; ++ case CODEC_ID_ADPCM_EA_R3: ++ header_size = 4 + 5 * ch; ++ *coded_samples = AV_RB32(buf); ++ break; ++ } ++ *coded_samples -= *coded_samples % 28; ++ nb_samples = (buf_size - header_size) * 2 / ch; ++ nb_samples -= nb_samples % 28; ++ break; ++ case CODEC_ID_ADPCM_IMA_DK3: ++ if (avctx->block_align > 0) ++ buf_size = FFMIN(buf_size, avctx->block_align); ++ nb_samples = ((buf_size - 16) * 8 / 3) / ch; ++ break; ++ case CODEC_ID_ADPCM_IMA_DK4: ++ nb_samples = 1 + (buf_size - 4 * ch) * 2 / ch; ++ break; ++ case CODEC_ID_ADPCM_IMA_WAV: ++ if (avctx->block_align > 0) ++ buf_size = FFMIN(buf_size, avctx->block_align); ++ nb_samples = 1 + (buf_size - 4 * ch) / (4 * ch) * 8; ++ break; ++ case CODEC_ID_ADPCM_MS: ++ if (avctx->block_align > 0) ++ buf_size = FFMIN(buf_size, avctx->block_align); ++ nb_samples = 2 + (buf_size - 7 * ch) * 2 / ch; ++ break; ++ case CODEC_ID_ADPCM_SBPRO_2: ++ case CODEC_ID_ADPCM_SBPRO_3: ++ case CODEC_ID_ADPCM_SBPRO_4: ++ { ++ int samples_per_byte; ++ switch (avctx->codec->id) { ++ case CODEC_ID_ADPCM_SBPRO_2: samples_per_byte = 4; break; ++ case CODEC_ID_ADPCM_SBPRO_3: samples_per_byte = 3; break; ++ case CODEC_ID_ADPCM_SBPRO_4: samples_per_byte = 2; break; ++ } ++ if (!s->status[0].step_index) { ++ nb_samples++; ++ buf_size -= ch; ++ } ++ nb_samples += buf_size * samples_per_byte / ch; ++ break; ++ } ++ case CODEC_ID_ADPCM_SWF: ++ { ++ int buf_bits = buf_size * 8 - 2; ++ int nbits = (buf[0] >> 6) + 2; ++ int block_hdr_size = 22 * ch; ++ int block_size = block_hdr_size + nbits * ch * 4095; ++ int nblocks = buf_bits / block_size; ++ int bits_left = buf_bits - nblocks * block_size; ++ nb_samples = nblocks * 4096; ++ if (bits_left >= block_hdr_size) ++ nb_samples += 1 + (bits_left - block_hdr_size) / (nbits * ch); ++ break; ++ } ++ case CODEC_ID_ADPCM_THP: ++ has_coded_samples = 1; ++ if (buf_size < 8) ++ return 0; ++ *coded_samples = AV_RB32(&buf[4]); ++ *coded_samples -= *coded_samples % 14; ++ nb_samples = (buf_size - 80) / (8 * ch) * 14; ++ break; ++ case CODEC_ID_ADPCM_XA: ++ nb_samples = (buf_size / 128) * 224 / ch; ++ break; ++ } ++ ++ /* validate coded sample count */ ++ if (has_coded_samples && (*coded_samples <= 0 || *coded_samples > nb_samples)) ++ return AVERROR_INVALIDDATA; ++ ++ return nb_samples; ++} + + /* DK3 ADPCM support macro */ + #define DK3_GET_NEXT_NIBBLE() \ +@@ -952,105 +525,104 @@ + } \ + else \ + { \ ++ if (end_of_packet) \ ++ break; \ + last_byte = *src++; \ +- if (src >= buf + buf_size) break; \ ++ if (src >= buf + buf_size) \ ++ end_of_packet = 1; \ + nibble = last_byte & 0x0F; \ + decode_top_nibble_next = 1; \ + } + +-static int adpcm_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int adpcm_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- ADPCMContext *c = avctx->priv_data; ++ ADPCMDecodeContext *c = avctx->priv_data; + ADPCMChannelStatus *cs; + int n, m, channel, i; +- int block_predictor[2]; + short *samples; +- short *samples_end; + const uint8_t *src; + int st; /* stereo */ +- +- /* DK3 ADPCM accounting variables */ +- unsigned char last_byte = 0; +- unsigned char nibble; +- int decode_top_nibble_next = 0; +- int diff_channel; +- +- /* EA ADPCM state variables */ +- uint32_t samples_in_chunk; +- int32_t previous_left_sample, previous_right_sample; +- int32_t current_left_sample, current_right_sample; +- int32_t next_left_sample, next_right_sample; +- int32_t coeff1l, coeff2l, coeff1r, coeff2r; +- uint8_t shift_left, shift_right; + int count1, count2; +- int coeff[2][2], shift[2];//used in EA MAXIS ADPCM ++ int nb_samples, coded_samples, ret; + +- if (!buf_size) +- return 0; ++ nb_samples = get_nb_samples(avctx, buf, buf_size, &coded_samples); ++ if (nb_samples <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of samples in packet\n"); ++ return AVERROR_INVALIDDATA; ++ } + +- //should protect all 4bit ADPCM variants +- //8 is needed for CODEC_ID_ADPCM_IMA_WAV with 2 channels +- // +- if(*data_size/4 < buf_size + 8) +- return -1; ++ /* get output buffer */ ++ c->frame.nb_samples = nb_samples; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (short *)c->frame.data[0]; ++ ++ /* use coded_samples when applicable */ ++ /* it is always <= nb_samples, so the output buffer will be large enough */ ++ if (coded_samples) { ++ if (coded_samples != nb_samples) ++ av_log(avctx, AV_LOG_WARNING, "mismatch in coded sample count\n"); ++ c->frame.nb_samples = nb_samples = coded_samples; ++ } + +- samples = data; +- samples_end= samples + *data_size/2; +- *data_size= 0; + src = buf; + + st = avctx->channels == 2 ? 1 : 0; + + switch(avctx->codec->id) { + case CODEC_ID_ADPCM_IMA_QT: +- n = buf_size - 2*avctx->channels; ++ /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples). ++ Channel data is interleaved per-chunk. */ + for (channel = 0; channel < avctx->channels; channel++) { ++ int16_t predictor; ++ int step_index; + cs = &(c->status[channel]); + /* (pppppp) (piiiiiii) */ + + /* Bits 15-7 are the _top_ 9 bits of the 16-bit initial predictor value */ +- cs->predictor = (*src++) << 8; +- cs->predictor |= (*src & 0x80); +- cs->predictor &= 0xFF80; +- +- /* sign extension */ +- if(cs->predictor & 0x8000) +- cs->predictor -= 0x10000; +- +- cs->predictor = av_clip_int16(cs->predictor); +- +- cs->step_index = (*src++) & 0x7F; ++ predictor = AV_RB16(src); ++ step_index = predictor & 0x7F; ++ predictor &= 0xFF80; ++ ++ src += 2; ++ ++ if (cs->step_index == step_index) { ++ int diff = (int)predictor - cs->predictor; ++ if (diff < 0) ++ diff = - diff; ++ if (diff > 0x7f) ++ goto update; ++ } else { ++ update: ++ cs->step_index = step_index; ++ cs->predictor = predictor; ++ } + + if (cs->step_index > 88){ + av_log(avctx, AV_LOG_ERROR, "ERROR: step_index = %i\n", cs->step_index); + cs->step_index = 88; + } + +- cs->step = step_table[cs->step_index]; +- +- samples = (short*)data + channel; ++ samples = (short *)c->frame.data[0] + channel; + +- for(m=32; n>0 && m>0; n--, m--) { /* in QuickTime, IMA is encoded by chuncks of 34 bytes (=64 samples) */ +- *samples = adpcm_ima_expand_nibble(cs, src[0] & 0x0F, 3); ++ for (m = 0; m < 32; m++) { ++ *samples = adpcm_ima_qt_expand_nibble(cs, src[0] & 0x0F, 3); + samples += avctx->channels; +- *samples = adpcm_ima_expand_nibble(cs, src[0] >> 4 , 3); ++ *samples = adpcm_ima_qt_expand_nibble(cs, src[0] >> 4 , 3); + samples += avctx->channels; + src ++; + } + } +- if (st) +- samples--; + break; + case CODEC_ID_ADPCM_IMA_WAV: + if (avctx->block_align != 0 && buf_size > avctx->block_align) + buf_size = avctx->block_align; + +-// samples_per_block= (block_align-4*chanels)*8 / (bits_per_sample * chanels) + 1; +- + for(i=0; ichannels; i++){ + cs = &(c->status[i]); + cs->predictor = *samples++ = (int16_t)bytestream_get_le16(&src); +@@ -1063,61 +635,61 @@ + if (*src++) av_log(avctx, AV_LOG_ERROR, "unused byte should be null but is %d!!\n", src[-1]); /* unused */ + } + +- while(src < buf + buf_size){ +- for(m=0; m<4; m++){ +- for(i=0; i<=st; i++) +- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] & 0x0F, 3); +- for(i=0; i<=st; i++) +- *samples++ = adpcm_ima_expand_nibble(&c->status[i], src[4*i] >> 4 , 3); +- src++; ++ for (n = (nb_samples - 1) / 8; n > 0; n--) { ++ for (i = 0; i < avctx->channels; i++) { ++ cs = &c->status[i]; ++ for (m = 0; m < 4; m++) { ++ uint8_t v = *src++; ++ *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 3); ++ samples += avctx->channels; ++ *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 3); ++ samples += avctx->channels; ++ } ++ samples -= 8 * avctx->channels - 1; + } +- src += 4*st; ++ samples += 7 * avctx->channels; + } + break; + case CODEC_ID_ADPCM_4XM: +- cs = &(c->status[0]); +- c->status[0].predictor= (int16_t)bytestream_get_le16(&src); +- if(st){ +- c->status[1].predictor= (int16_t)bytestream_get_le16(&src); +- } +- c->status[0].step_index= (int16_t)bytestream_get_le16(&src); +- if(st){ +- c->status[1].step_index= (int16_t)bytestream_get_le16(&src); +- } +- if (cs->step_index < 0) cs->step_index = 0; +- if (cs->step_index > 88) cs->step_index = 88; +- +- m= (buf_size - (src - buf))>>st; +- for(i=0; istatus[0], src[i] & 0x0F, 4); +- if (st) +- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] & 0x0F, 4); +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[i] >> 4, 4); +- if (st) +- *samples++ = adpcm_ima_expand_nibble(&c->status[1], src[i+m] >> 4, 4); +- } ++ for (i = 0; i < avctx->channels; i++) ++ c->status[i].predictor= (int16_t)bytestream_get_le16(&src); + +- src += m<channels; i++) { ++ c->status[i].step_index= (int16_t)bytestream_get_le16(&src); ++ c->status[i].step_index = av_clip(c->status[i].step_index, 0, 88); ++ } + ++ for (i = 0; i < avctx->channels; i++) { ++ samples = (short *)c->frame.data[0] + i; ++ cs = &c->status[i]; ++ for (n = nb_samples >> 1; n > 0; n--, src++) { ++ uint8_t v = *src; ++ *samples = adpcm_ima_expand_nibble(cs, v & 0x0F, 4); ++ samples += avctx->channels; ++ *samples = adpcm_ima_expand_nibble(cs, v >> 4 , 4); ++ samples += avctx->channels; ++ } ++ } + break; + case CODEC_ID_ADPCM_MS: ++ { ++ int block_predictor; ++ + if (avctx->block_align != 0 && buf_size > avctx->block_align) + buf_size = avctx->block_align; +- n = buf_size - 7 * avctx->channels; +- if (n < 0) +- return -1; +- block_predictor[0] = av_clip(*src++, 0, 6); +- block_predictor[1] = 0; +- if (st) +- block_predictor[1] = av_clip(*src++, 0, 6); ++ ++ block_predictor = av_clip(*src++, 0, 6); ++ c->status[0].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor]; ++ c->status[0].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor]; ++ if (st) { ++ block_predictor = av_clip(*src++, 0, 6); ++ c->status[1].coeff1 = ff_adpcm_AdaptCoeff1[block_predictor]; ++ c->status[1].coeff2 = ff_adpcm_AdaptCoeff2[block_predictor]; ++ } + c->status[0].idelta = (int16_t)bytestream_get_le16(&src); + if (st){ + c->status[1].idelta = (int16_t)bytestream_get_le16(&src); + } +- c->status[0].coeff1 = AdaptCoeff1[block_predictor[0]]; +- c->status[0].coeff2 = AdaptCoeff2[block_predictor[0]]; +- c->status[1].coeff1 = AdaptCoeff1[block_predictor[1]]; +- c->status[1].coeff2 = AdaptCoeff2[block_predictor[1]]; + + c->status[0].sample1 = bytestream_get_le16(&src); + if (st) c->status[1].sample1 = bytestream_get_le16(&src); +@@ -1128,55 +700,44 @@ + if (st) *samples++ = c->status[1].sample2; + *samples++ = c->status[0].sample1; + if (st) *samples++ = c->status[1].sample1; +- for(;n>0;n--) { ++ for(n = (nb_samples - 2) >> (1 - st); n > 0; n--, src++) { + *samples++ = adpcm_ms_expand_nibble(&c->status[0 ], src[0] >> 4 ); + *samples++ = adpcm_ms_expand_nibble(&c->status[st], src[0] & 0x0F); +- src ++; + } + break; ++ } + case CODEC_ID_ADPCM_IMA_DK4: + if (avctx->block_align != 0 && buf_size > avctx->block_align) + buf_size = avctx->block_align; + +- c->status[0].predictor = (int16_t)bytestream_get_le16(&src); +- c->status[0].step_index = *src++; +- src++; +- *samples++ = c->status[0].predictor; +- if (st) { +- c->status[1].predictor = (int16_t)bytestream_get_le16(&src); +- c->status[1].step_index = *src++; ++ for (channel = 0; channel < avctx->channels; channel++) { ++ cs = &c->status[channel]; ++ cs->predictor = (int16_t)bytestream_get_le16(&src); ++ cs->step_index = av_clip(*src++, 0, 88); + src++; +- *samples++ = c->status[1].predictor; ++ *samples++ = cs->predictor; + } +- while (src < buf + buf_size) { +- +- /* take care of the top nibble (always left or mono channel) */ +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] >> 4, 3); +- +- /* take care of the bottom nibble, which is right sample for +- * stereo, or another mono sample */ +- if (st) +- *samples++ = adpcm_ima_expand_nibble(&c->status[1], +- src[0] & 0x0F, 3); +- else +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] & 0x0F, 3); +- +- src++; ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { ++ uint8_t v = *src; ++ *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v >> 4 , 3); ++ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3); + } + break; + case CODEC_ID_ADPCM_IMA_DK3: ++ { ++ unsigned char last_byte = 0; ++ unsigned char nibble; ++ int decode_top_nibble_next = 0; ++ int end_of_packet = 0; ++ int diff_channel; ++ + if (avctx->block_align != 0 && buf_size > avctx->block_align) + buf_size = avctx->block_align; + +- if(buf_size + 16 > (samples_end - samples)*3/8) +- return -1; +- + c->status[0].predictor = (int16_t)AV_RL16(src + 10); + c->status[1].predictor = (int16_t)AV_RL16(src + 12); +- c->status[0].step_index = src[14]; +- c->status[1].step_index = src[15]; ++ c->status[0].step_index = av_clip(src[14], 0, 88); ++ c->status[1].step_index = av_clip(src[15], 0, 88); + /* sign extend the predictors */ + src += 16; + diff_channel = c->status[1].predictor; +@@ -1211,111 +772,125 @@ + *samples++ = c->status[0].predictor - c->status[1].predictor; + } + break; ++ } + case CODEC_ID_ADPCM_IMA_ISS: +- c->status[0].predictor = (int16_t)AV_RL16(src + 0); +- c->status[0].step_index = src[2]; +- src += 4; +- if(st) { +- c->status[1].predictor = (int16_t)AV_RL16(src + 0); +- c->status[1].step_index = src[2]; +- src += 4; ++ for (channel = 0; channel < avctx->channels; channel++) { ++ cs = &c->status[channel]; ++ cs->predictor = (int16_t)bytestream_get_le16(&src); ++ cs->step_index = av_clip(*src++, 0, 88); ++ src++; + } + +- while (src < buf + buf_size) { +- ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { ++ uint8_t v1, v2; ++ uint8_t v = *src; ++ /* nibbles are swapped for mono */ + if (st) { +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] >> 4 , 3); +- *samples++ = adpcm_ima_expand_nibble(&c->status[1], +- src[0] & 0x0F, 3); ++ v1 = v >> 4; ++ v2 = v & 0x0F; + } else { +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] & 0x0F, 3); +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] >> 4 , 3); ++ v2 = v >> 4; ++ v1 = v & 0x0F; + } +- +- src++; ++ *samples++ = adpcm_ima_expand_nibble(&c->status[0 ], v1, 3); ++ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v2, 3); + } + break; +- case CODEC_ID_ADPCM_IMA_WS: +- /* no per-block initialization; just start decoding the data */ ++ case CODEC_ID_ADPCM_IMA_APC: + while (src < buf + buf_size) { +- +- if (st) { +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] >> 4 , 3); +- *samples++ = adpcm_ima_expand_nibble(&c->status[1], +- src[0] & 0x0F, 3); ++ uint8_t v = *src++; ++ *samples++ = adpcm_ima_expand_nibble(&c->status[0], v >> 4 , 3); ++ *samples++ = adpcm_ima_expand_nibble(&c->status[st], v & 0x0F, 3); ++ } ++ break; ++ case CODEC_ID_ADPCM_IMA_WS: ++ for (channel = 0; channel < avctx->channels; channel++) { ++ const uint8_t *src0; ++ int src_stride; ++ int16_t *smp = samples + channel; ++ ++ if (c->vqa_version == 3) { ++ src0 = src + channel * buf_size / 2; ++ src_stride = 1; + } else { +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] >> 4 , 3); +- *samples++ = adpcm_ima_expand_nibble(&c->status[0], +- src[0] & 0x0F, 3); ++ src0 = src + channel; ++ src_stride = avctx->channels; ++ } ++ for (n = nb_samples / 2; n > 0; n--) { ++ uint8_t v = *src0; ++ src0 += src_stride; ++ *smp = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3); ++ smp += avctx->channels; ++ *smp = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3); ++ smp += avctx->channels; + } +- +- src++; + } ++ src = buf + buf_size; + break; + case CODEC_ID_ADPCM_XA: + while (buf_size >= 128) { +- xa_decode(samples, src, &c->status[0], &c->status[1], +- avctx->channels); ++ if ((ret = xa_decode(avctx, samples, src, &c->status[0], ++ &c->status[1], avctx->channels)) < 0) ++ return ret; + src += 128; + samples += 28 * 8; + buf_size -= 128; + } + break; + case CODEC_ID_ADPCM_IMA_EA_EACS: +- samples_in_chunk = bytestream_get_le32(&src) >> (1-st); +- +- if (samples_in_chunk > buf_size-4-(8<status[i].step_index = bytestream_get_le32(&src); ++ c->status[i].step_index = av_clip(bytestream_get_le32(&src), 0, 88); + for (i=0; i<=st; i++) + c->status[i].predictor = bytestream_get_le32(&src); + +- for (; samples_in_chunk; samples_in_chunk--, src++) { ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], *src>>4, 3); + *samples++ = adpcm_ima_expand_nibble(&c->status[st], *src&0x0F, 3); + } + break; + case CODEC_ID_ADPCM_IMA_EA_SEAD: +- for (; src < buf+buf_size; src++) { ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { + *samples++ = adpcm_ima_expand_nibble(&c->status[0], src[0] >> 4, 6); + *samples++ = adpcm_ima_expand_nibble(&c->status[st],src[0]&0x0F, 6); + } + break; + case CODEC_ID_ADPCM_EA: +- if (buf_size < 4 || AV_RL32(src) >= ((buf_size - 12) * 2)) { +- src += buf_size; +- break; +- } +- samples_in_chunk = AV_RL32(src); +- src += 4; ++ { ++ int32_t previous_left_sample, previous_right_sample; ++ int32_t current_left_sample, current_right_sample; ++ int32_t next_left_sample, next_right_sample; ++ int32_t coeff1l, coeff2l, coeff1r, coeff2r; ++ uint8_t shift_left, shift_right; ++ ++ /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces, ++ each coding 28 stereo samples. */ ++ ++ if(avctx->channels != 2) ++ return AVERROR_INVALIDDATA; ++ ++ src += 4; // skip sample count (already read) ++ + current_left_sample = (int16_t)bytestream_get_le16(&src); + previous_left_sample = (int16_t)bytestream_get_le16(&src); + current_right_sample = (int16_t)bytestream_get_le16(&src); + previous_right_sample = (int16_t)bytestream_get_le16(&src); + +- for (count1 = 0; count1 < samples_in_chunk/28;count1++) { ++ for (count1 = 0; count1 < nb_samples / 28; count1++) { + coeff1l = ea_adpcm_table[ *src >> 4 ]; + coeff2l = ea_adpcm_table[(*src >> 4 ) + 4]; + coeff1r = ea_adpcm_table[*src & 0x0F]; + coeff2r = ea_adpcm_table[(*src & 0x0F) + 4]; + src++; + +- shift_left = (*src >> 4 ) + 8; +- shift_right = (*src & 0x0F) + 8; ++ shift_left = 20 - (*src >> 4); ++ shift_right = 20 - (*src & 0x0F); + src++; + + for (count2 = 0; count2 < 28; count2++) { +- next_left_sample = (int32_t)((*src & 0xF0) << 24) >> shift_left; +- next_right_sample = (int32_t)((*src & 0x0F) << 28) >> shift_right; ++ next_left_sample = sign_extend(*src >> 4, 4) << shift_left; ++ next_right_sample = sign_extend(*src, 4) << shift_right; + src++; + + next_left_sample = (next_left_sample + +@@ -1338,17 +913,21 @@ + src += 2; // Skip terminating 0x0000 + + break; ++ } + case CODEC_ID_ADPCM_EA_MAXIS_XA: ++ { ++ int coeff[2][2], shift[2]; ++ + for(channel = 0; channel < avctx->channels; channel++) { + for (i=0; i<2; i++) + coeff[channel][i] = ea_adpcm_table[(*src >> 4) + 4*i]; +- shift[channel] = (*src & 0x0F) + 8; ++ shift[channel] = 20 - (*src & 0x0F); + src++; + } +- for (count1 = 0; count1 < (buf_size - avctx->channels) / avctx->channels; count1++) { ++ for (count1 = 0; count1 < nb_samples / 2; count1++) { + for(i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */ + for(channel = 0; channel < avctx->channels; channel++) { +- int32_t sample = (int32_t)(((*(src+channel) >> i) & 0x0F) << 0x1C) >> shift[channel]; ++ int32_t sample = sign_extend(src[channel] >> i, 4) << shift[channel]; + sample = (sample + + c->status[channel].sample1 * coeff[channel][0] + + c->status[channel].sample2 * coeff[channel][1] + 0x80) >> 8; +@@ -1359,7 +938,10 @@ + } + src+=avctx->channels; + } ++ /* consume whole packet */ ++ src = buf + buf_size; + break; ++ } + case CODEC_ID_ADPCM_EA_R1: + case CODEC_ID_ADPCM_EA_R2: + case CODEC_ID_ADPCM_EA_R3: { +@@ -1375,14 +957,9 @@ + uint16_t *samplesC; + const uint8_t *srcC; + const uint8_t *src_end = buf + buf_size; ++ int count = 0; + +- samples_in_chunk = (big_endian ? bytestream_get_be32(&src) +- : bytestream_get_le32(&src)) / 28; +- if (samples_in_chunk > UINT32_MAX/(28*avctx->channels) || +- 28*samples_in_chunk*avctx->channels > samples_end-samples) { +- src += buf_size - 4; +- break; +- } ++ src += 4; // skip sample count (already read) + + for (channel=0; channelchannels; channel++) { + int32_t offset = (big_endian ? bytestream_get_be32(&src) +@@ -1401,7 +978,7 @@ + previous_sample = c->status[channel].prev_sample; + } + +- for (count1=0; count1 src_end - 30*2) break; +@@ -1415,14 +992,14 @@ + } else { + coeff1 = ea_adpcm_table[ *srcC>>4 ]; + coeff2 = ea_adpcm_table[(*srcC>>4) + 4]; +- shift = (*srcC++ & 0x0F) + 8; ++ shift = 20 - (*srcC++ & 0x0F); + + if (srcC > src_end - 14) break; + for (count2=0; count2<28; count2++) { + if (count2 & 1) +- next_sample = (int32_t)((*srcC++ & 0x0F) << 28) >> shift; ++ next_sample = sign_extend(*srcC++, 4) << shift; + else +- next_sample = (int32_t)((*srcC & 0xF0) << 24) >> shift; ++ next_sample = sign_extend(*srcC >> 4, 4) << shift; + + next_sample += (current_sample * coeff1) + + (previous_sample * coeff2); +@@ -1435,6 +1012,12 @@ + } + } + } ++ if (!count) { ++ count = count1; ++ } else if (count != count1) { ++ av_log(avctx, AV_LOG_WARNING, "per-channel sample count mismatch\n"); ++ count = FFMAX(count, count1); ++ } + + if (avctx->codec->id != CODEC_ID_ADPCM_EA_R1) { + c->status[channel].predictor = current_sample; +@@ -1442,23 +1025,18 @@ + } + } + +- src = src + buf_size - (4 + 4*avctx->channels); +- samples += 28 * samples_in_chunk * avctx->channels; ++ c->frame.nb_samples = count * 28; ++ src = src_end; + break; + } + case CODEC_ID_ADPCM_EA_XAS: +- if (samples_end-samples < 32*4*avctx->channels +- || buf_size < (4+15)*4*avctx->channels) { +- src += buf_size; +- break; +- } + for (channel=0; channelchannels; channel++) { + int coeff[2][4], shift[4]; + short *s2, *s = &samples[channel]; + for (n=0; n<4; n++, s+=32*avctx->channels) { + for (i=0; i<2; i++) + coeff[i][n] = ea_adpcm_table[(src[0]&0x0F)+4*i]; +- shift[n] = (src[2]&0x0F) + 8; ++ shift[n] = 20 - (src[2] & 0x0F); + for (s2=s, i=0; i<2; i++, src+=2, s2+=avctx->channels) + s2[0] = (src[0]&0xF0) + (src[1]<<8); + } +@@ -1467,7 +1045,7 @@ + s = &samples[m*avctx->channels + channel]; + for (n=0; n<4; n++, src++, s+=32*avctx->channels) { + for (s2=s, i=0; i<8; i+=4, s2+=avctx->channels) { +- int level = (int32_t)((*src & (0xF0>>i)) << (24+i)) >> shift[n]; ++ int level = sign_extend(*src >> (4 - i), 4) << shift[n]; + int pred = s2[-1*avctx->channels] * coeff[0][n] + + s2[-2*avctx->channels] * coeff[1][n]; + s2[0] = av_clip_int16((level + pred + 0x80) >> 8); +@@ -1475,17 +1053,20 @@ + } + } + } +- samples += 32*4*avctx->channels; + break; + case CODEC_ID_ADPCM_IMA_AMV: + case CODEC_ID_ADPCM_IMA_SMJPEG: +- c->status[0].predictor = (int16_t)bytestream_get_le16(&src); +- c->status[0].step_index = bytestream_get_le16(&src); +- +- if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) +- src+=4; ++ if (avctx->codec->id == CODEC_ID_ADPCM_IMA_AMV) { ++ c->status[0].predictor = sign_extend(bytestream_get_le16(&src), 16); ++ c->status[0].step_index = av_clip(bytestream_get_le16(&src), 0, 88); ++ src += 4; ++ } else { ++ c->status[0].predictor = sign_extend(bytestream_get_be16(&src), 16); ++ c->status[0].step_index = av_clip(bytestream_get_byte(&src), 0, 88); ++ src += 1; ++ } + +- while (src < buf + buf_size) { ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { + char hi, lo; + lo = *src & 0x0F; + hi = *src >> 4; +@@ -1497,23 +1078,13 @@ + lo, 3); + *samples++ = adpcm_ima_expand_nibble(&c->status[0], + hi, 3); +- src++; + } + break; + case CODEC_ID_ADPCM_CT: +- while (src < buf + buf_size) { +- if (st) { +- *samples++ = adpcm_ct_expand_nibble(&c->status[0], +- src[0] >> 4); +- *samples++ = adpcm_ct_expand_nibble(&c->status[1], +- src[0] & 0x0F); +- } else { +- *samples++ = adpcm_ct_expand_nibble(&c->status[0], +- src[0] >> 4); +- *samples++ = adpcm_ct_expand_nibble(&c->status[0], +- src[0] & 0x0F); +- } +- src++; ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { ++ uint8_t v = *src; ++ *samples++ = adpcm_ct_expand_nibble(&c->status[0 ], v >> 4 ); ++ *samples++ = adpcm_ct_expand_nibble(&c->status[st], v & 0x0F); + } + break; + case CODEC_ID_ADPCM_SBPRO_4: +@@ -1525,27 +1096,26 @@ + if (st) + *samples++ = 128 * (*src++ - 0x80); + c->status[0].step_index = 1; ++ nb_samples--; + } + if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_4) { +- while (src < buf + buf_size) { ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { + *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], + src[0] >> 4, 4, 0); + *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], + src[0] & 0x0F, 4, 0); +- src++; + } + } else if (avctx->codec->id == CODEC_ID_ADPCM_SBPRO_3) { +- while (src < buf + buf_size && samples + 2 < samples_end) { ++ for (n = nb_samples / 3; n > 0; n--, src++) { + *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], + src[0] >> 5 , 3, 0); + *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], + (src[0] >> 2) & 0x07, 3, 0); + *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], + src[0] & 0x03, 2, 0); +- src++; + } + } else { +- while (src < buf + buf_size && samples + 3 < samples_end) { ++ for (n = nb_samples >> (2 - st); n > 0; n--, src++) { + *samples++ = adpcm_sbpro_expand_nibble(&c->status[0], + src[0] >> 6 , 2, 2); + *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], +@@ -1554,7 +1124,6 @@ + (src[0] >> 2) & 0x03, 2, 2); + *samples++ = adpcm_sbpro_expand_nibble(&c->status[st], + src[0] & 0x03, 2, 2); +- src++; + } + } + break; +@@ -1586,7 +1155,7 @@ + for (i = 0; i < avctx->channels; i++) { + // similar to IMA adpcm + int delta = get_bits(&gb, nb_bits); +- int step = step_table[c->status[i].step_index]; ++ int step = ff_adpcm_step_table[c->status[i].step_index]; + long vpdiff = 0; // vpdiff = (delta+0.5)*step/4 + int k = k0; + +@@ -1609,10 +1178,6 @@ + c->status[i].predictor = av_clip_int16(c->status[i].predictor); + + *samples++ = c->status[i].predictor; +- if (samples >= samples_end) { +- av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); +- return -1; +- } + } + } + } +@@ -1620,35 +1185,20 @@ + break; + } + case CODEC_ID_ADPCM_YAMAHA: +- while (src < buf + buf_size) { +- if (st) { +- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], +- src[0] & 0x0F); +- *samples++ = adpcm_yamaha_expand_nibble(&c->status[1], +- src[0] >> 4 ); +- } else { +- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], +- src[0] & 0x0F); +- *samples++ = adpcm_yamaha_expand_nibble(&c->status[0], +- src[0] >> 4 ); +- } +- src++; ++ for (n = nb_samples >> (1 - st); n > 0; n--, src++) { ++ uint8_t v = *src; ++ *samples++ = adpcm_yamaha_expand_nibble(&c->status[0 ], v & 0x0F); ++ *samples++ = adpcm_yamaha_expand_nibble(&c->status[st], v >> 4 ); + } + break; + case CODEC_ID_ADPCM_THP: + { + int table[2][16]; +- unsigned int samplecnt; + int prev[2][2]; + int ch; + +- if (buf_size < 80) { +- av_log(avctx, AV_LOG_ERROR, "frame too small\n"); +- return -1; +- } +- +- src+=4; +- samplecnt = bytestream_get_be32(&src); ++ src += 4; // skip channel size ++ src += 4; // skip number of samples (already read) + + for (i = 0; i < 32; i++) + table[0][i] = (int16_t)bytestream_get_be16(&src); +@@ -1657,29 +1207,24 @@ + for (i = 0; i < 4; i++) + prev[0][i] = (int16_t)bytestream_get_be16(&src); + +- if (samplecnt >= (samples_end - samples) / (st + 1)) { +- av_log(avctx, AV_LOG_ERROR, "allocated output buffer is too small\n"); +- return -1; +- } +- + for (ch = 0; ch <= st; ch++) { +- samples = (unsigned short *) data + ch; ++ samples = (short *)c->frame.data[0] + ch; + + /* Read in every sample for this channel. */ +- for (i = 0; i < samplecnt / 14; i++) { ++ for (i = 0; i < nb_samples / 14; i++) { + int index = (*src >> 4) & 7; +- unsigned int exp = 28 - (*src++ & 15); ++ unsigned int exp = *src++ & 15; + int factor1 = table[ch][index * 2]; + int factor2 = table[ch][index * 2 + 1]; + + /* Decode 14 samples. */ + for (n = 0; n < 14; n++) { + int32_t sampledat; +- if(n&1) sampledat= *src++ <<28; +- else sampledat= (*src&0xF0)<<24; ++ if(n&1) sampledat = sign_extend(*src++, 4); ++ else sampledat = sign_extend(*src >> 4, 4); + + sampledat = ((prev[ch][0]*factor1 +- + prev[ch][1]*factor2) >> 11) + (sampledat>>exp); ++ + prev[ch][1]*factor2) >> 11) + (sampledat << exp); + *samples = av_clip_int16(sampledat); + prev[ch][1] = prev[ch][0]; + prev[ch][0] = *samples++; +@@ -1690,59 +1235,31 @@ + } + } + } +- +- /* In the previous loop, in case stereo is used, samples is +- increased exactly one time too often. */ +- samples -= st; + break; + } + + default: + return -1; + } +- *data_size = (uint8_t *)samples - (uint8_t *)data; +- return src - buf; +-} + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; + ++ return src - buf; ++} + +-#if CONFIG_ENCODERS +-#define ADPCM_ENCODER(id,name,long_name_) \ +-AVCodec ff_ ## name ## _encoder = { \ +- #name, \ +- AVMEDIA_TYPE_AUDIO, \ +- id, \ +- sizeof(ADPCMContext), \ +- adpcm_encode_init, \ +- adpcm_encode_frame, \ +- adpcm_encode_close, \ +- NULL, \ +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, \ +- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ +-}; +-#else +-#define ADPCM_ENCODER(id,name,long_name_) +-#endif +- +-#if CONFIG_DECODERS +-#define ADPCM_DECODER(id,name,long_name_) \ +-AVCodec ff_ ## name ## _decoder = { \ +- #name, \ +- AVMEDIA_TYPE_AUDIO, \ +- id, \ +- sizeof(ADPCMContext), \ +- adpcm_decode_init, \ +- NULL, \ +- NULL, \ +- adpcm_decode_frame, \ +- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ +-}; +-#else +-#define ADPCM_DECODER(id,name,long_name_) +-#endif + +-#define ADPCM_CODEC(id,name,long_name_) \ +- ADPCM_ENCODER(id,name,long_name_) ADPCM_DECODER(id,name,long_name_) ++#define ADPCM_DECODER(id_, name_, long_name_) \ ++AVCodec ff_ ## name_ ## _decoder = { \ ++ .name = #name_, \ ++ .type = AVMEDIA_TYPE_AUDIO, \ ++ .id = id_, \ ++ .priv_data_size = sizeof(ADPCMDecodeContext), \ ++ .init = adpcm_decode_init, \ ++ .decode = adpcm_decode_frame, \ ++ .capabilities = CODEC_CAP_DR1, \ ++ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ ++} + + /* Note: Do not forget to add new entries to the Makefile as well. */ + ADPCM_DECODER(CODEC_ID_ADPCM_4XM, adpcm_4xm, "ADPCM 4X Movie"); +@@ -1754,20 +1271,21 @@ + ADPCM_DECODER(CODEC_ID_ADPCM_EA_R3, adpcm_ea_r3, "ADPCM Electronic Arts R3"); + ADPCM_DECODER(CODEC_ID_ADPCM_EA_XAS, adpcm_ea_xas, "ADPCM Electronic Arts XAS"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, "ADPCM IMA AMV"); ++ADPCM_DECODER(CODEC_ID_ADPCM_IMA_APC, adpcm_ima_apc, "ADPCM IMA CRYO APC"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK3, adpcm_ima_dk3, "ADPCM IMA Duck DK3"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_DK4, adpcm_ima_dk4, "ADPCM IMA Duck DK4"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs, "ADPCM IMA Electronic Arts EACS"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_EA_SEAD, adpcm_ima_ea_sead, "ADPCM IMA Electronic Arts SEAD"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_ISS, adpcm_ima_iss, "ADPCM IMA Funcom ISS"); +-ADPCM_CODEC (CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime"); ++ADPCM_DECODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_SMJPEG, adpcm_ima_smjpeg, "ADPCM IMA Loki SDL MJPEG"); +-ADPCM_CODEC (CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV"); ++ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV"); + ADPCM_DECODER(CODEC_ID_ADPCM_IMA_WS, adpcm_ima_ws, "ADPCM IMA Westwood"); +-ADPCM_CODEC (CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft"); ++ADPCM_DECODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft"); + ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_2, adpcm_sbpro_2, "ADPCM Sound Blaster Pro 2-bit"); + ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_3, adpcm_sbpro_3, "ADPCM Sound Blaster Pro 2.6-bit"); + ADPCM_DECODER(CODEC_ID_ADPCM_SBPRO_4, adpcm_sbpro_4, "ADPCM Sound Blaster Pro 4-bit"); +-ADPCM_CODEC (CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash"); ++ADPCM_DECODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash"); + ADPCM_DECODER(CODEC_ID_ADPCM_THP, adpcm_thp, "ADPCM Nintendo Gamecube THP"); + ADPCM_DECODER(CODEC_ID_ADPCM_XA, adpcm_xa, "ADPCM CDROM XA"); +-ADPCM_CODEC (CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha"); ++ADPCM_DECODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha"); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm_data.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm_data.c 2012-05-14 14:08:53.357320319 +0200 +@@ -0,0 +1,78 @@ ++/* ++ * Copyright (c) 2001-2003 The ffmpeg Project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * ADPCM tables ++ */ ++ ++#include ++ ++/* ff_adpcm_step_table[] and ff_adpcm_index_table[] are from the ADPCM ++ reference source */ ++/* This is the index table: */ ++const int8_t ff_adpcm_index_table[16] = { ++ -1, -1, -1, -1, 2, 4, 6, 8, ++ -1, -1, -1, -1, 2, 4, 6, 8, ++}; ++ ++/** ++ * This is the step table. Note that many programs use slight deviations from ++ * this table, but such deviations are negligible: ++ */ ++const int16_t ff_adpcm_step_table[89] = { ++ 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, ++ 19, 21, 23, 25, 28, 31, 34, 37, 41, 45, ++ 50, 55, 60, 66, 73, 80, 88, 97, 107, 118, ++ 130, 143, 157, 173, 190, 209, 230, 253, 279, 307, ++ 337, 371, 408, 449, 494, 544, 598, 658, 724, 796, ++ 876, 963, 1060, 1166, 1282, 1411, 1552, 1707, 1878, 2066, ++ 2272, 2499, 2749, 3024, 3327, 3660, 4026, 4428, 4871, 5358, ++ 5894, 6484, 7132, 7845, 8630, 9493, 10442, 11487, 12635, 13899, ++ 15289, 16818, 18500, 20350, 22385, 24623, 27086, 29794, 32767 ++}; ++ ++/* These are for MS-ADPCM */ ++/* ff_adpcm_AdaptationTable[], ff_adpcm_AdaptCoeff1[], and ++ ff_adpcm_AdaptCoeff2[] are from libsndfile */ ++const int16_t ff_adpcm_AdaptationTable[] = { ++ 230, 230, 230, 230, 307, 409, 512, 614, ++ 768, 614, 512, 409, 307, 230, 230, 230 ++}; ++ ++/** Divided by 4 to fit in 8-bit integers */ ++const uint8_t ff_adpcm_AdaptCoeff1[] = { ++ 64, 128, 0, 48, 60, 115, 98 ++}; ++ ++/** Divided by 4 to fit in 8-bit integers */ ++const int8_t ff_adpcm_AdaptCoeff2[] = { ++ 0, -64, 0, 16, 0, -52, -58 ++}; ++ ++const int16_t ff_adpcm_yamaha_indexscale[] = { ++ 230, 230, 230, 230, 307, 409, 512, 614, ++ 230, 230, 230, 230, 307, 409, 512, 614 ++}; ++ ++const int8_t ff_adpcm_yamaha_difflookup[] = { ++ 1, 3, 5, 7, 9, 11, 13, 15, ++ -1, -3, -5, -7, -9, -11, -13, -15 ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm_data.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm_data.h 2012-05-14 14:08:53.357320319 +0200 +@@ -0,0 +1,39 @@ ++/* ++ * Copyright (c) 2001-2003 The ffmpeg Project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * ADPCM tables ++ */ ++ ++#ifndef AVCODEC_ADPCM_DATA_H ++#define AVCODEC_ADPCM_DATA_H ++ ++#include ++ ++extern const int8_t ff_adpcm_index_table[16]; ++extern const int16_t ff_adpcm_step_table[89]; ++extern const int16_t ff_adpcm_AdaptationTable[]; ++extern const uint8_t ff_adpcm_AdaptCoeff1[]; ++extern const int8_t ff_adpcm_AdaptCoeff2[]; ++extern const int16_t ff_adpcm_yamaha_indexscale[]; ++extern const int8_t ff_adpcm_yamaha_difflookup[]; ++ ++#endif /* AVCODEC_ADPCM_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcmenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcmenc.c 2012-05-14 14:08:53.360320379 +0200 +@@ -0,0 +1,720 @@ ++/* ++ * Copyright (c) 2001-2003 The ffmpeg Project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "get_bits.h" ++#include "put_bits.h" ++#include "bytestream.h" ++#include "adpcm.h" ++#include "adpcm_data.h" ++ ++/** ++ * @file ++ * ADPCM encoders ++ * First version by Francois Revol (revol@free.fr) ++ * Fringe ADPCM codecs (e.g., DK3, DK4, Westwood) ++ * by Mike Melanson (melanson@pcisys.net) ++ * ++ * See ADPCM decoder reference documents for codec information. ++ */ ++ ++typedef struct TrellisPath { ++ int nibble; ++ int prev; ++} TrellisPath; ++ ++typedef struct TrellisNode { ++ uint32_t ssd; ++ int path; ++ int sample1; ++ int sample2; ++ int step; ++} TrellisNode; ++ ++typedef struct ADPCMEncodeContext { ++ ADPCMChannelStatus status[6]; ++ TrellisPath *paths; ++ TrellisNode *node_buf; ++ TrellisNode **nodep_buf; ++ uint8_t *trellis_hash; ++} ADPCMEncodeContext; ++ ++#define FREEZE_INTERVAL 128 ++ ++static av_cold int adpcm_encode_init(AVCodecContext *avctx) ++{ ++ ADPCMEncodeContext *s = avctx->priv_data; ++ uint8_t *extradata; ++ int i; ++ if (avctx->channels > 2) ++ return -1; /* only stereo or mono =) */ ++ ++ if (avctx->trellis && (unsigned)avctx->trellis > 16U) { ++ av_log(avctx, AV_LOG_ERROR, "invalid trellis size\n"); ++ return -1; ++ } ++ ++ if (avctx->trellis) { ++ int frontier = 1 << avctx->trellis; ++ int max_paths = frontier * FREEZE_INTERVAL; ++ FF_ALLOC_OR_GOTO(avctx, s->paths, ++ max_paths * sizeof(*s->paths), error); ++ FF_ALLOC_OR_GOTO(avctx, s->node_buf, ++ 2 * frontier * sizeof(*s->node_buf), error); ++ FF_ALLOC_OR_GOTO(avctx, s->nodep_buf, ++ 2 * frontier * sizeof(*s->nodep_buf), error); ++ FF_ALLOC_OR_GOTO(avctx, s->trellis_hash, ++ 65536 * sizeof(*s->trellis_hash), error); ++ } ++ ++ avctx->bits_per_coded_sample = av_get_bits_per_sample(avctx->codec->id); ++ ++ switch (avctx->codec->id) { ++ case CODEC_ID_ADPCM_IMA_WAV: ++ /* each 16 bits sample gives one nibble ++ and we have 4 bytes per channel overhead */ ++ avctx->frame_size = (BLKSIZE - 4 * avctx->channels) * 8 / ++ (4 * avctx->channels) + 1; ++ /* seems frame_size isn't taken into account... ++ have to buffer the samples :-( */ ++ avctx->block_align = BLKSIZE; ++ avctx->bits_per_coded_sample = 4; ++ break; ++ case CODEC_ID_ADPCM_IMA_QT: ++ avctx->frame_size = 64; ++ avctx->block_align = 34 * avctx->channels; ++ break; ++ case CODEC_ID_ADPCM_MS: ++ /* each 16 bits sample gives one nibble ++ and we have 7 bytes per channel overhead */ ++ avctx->frame_size = (BLKSIZE - 7 * avctx->channels) * 2 / avctx->channels + 2; ++ avctx->block_align = BLKSIZE; ++ avctx->bits_per_coded_sample = 4; ++ avctx->extradata_size = 32; ++ extradata = avctx->extradata = av_malloc(avctx->extradata_size); ++ if (!extradata) ++ return AVERROR(ENOMEM); ++ bytestream_put_le16(&extradata, avctx->frame_size); ++ bytestream_put_le16(&extradata, 7); /* wNumCoef */ ++ for (i = 0; i < 7; i++) { ++ bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff1[i] * 4); ++ bytestream_put_le16(&extradata, ff_adpcm_AdaptCoeff2[i] * 4); ++ } ++ break; ++ case CODEC_ID_ADPCM_YAMAHA: ++ avctx->frame_size = BLKSIZE * avctx->channels; ++ avctx->block_align = BLKSIZE; ++ break; ++ case CODEC_ID_ADPCM_SWF: ++ if (avctx->sample_rate != 11025 && ++ avctx->sample_rate != 22050 && ++ avctx->sample_rate != 44100) { ++ av_log(avctx, AV_LOG_ERROR, "Sample rate must be 11025, " ++ "22050 or 44100\n"); ++ goto error; ++ } ++ avctx->frame_size = 512 * (avctx->sample_rate / 11025); ++ break; ++ default: ++ goto error; ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ avctx->coded_frame->key_frame= 1; ++ ++ return 0; ++error: ++ av_freep(&s->paths); ++ av_freep(&s->node_buf); ++ av_freep(&s->nodep_buf); ++ av_freep(&s->trellis_hash); ++ return -1; ++} ++ ++static av_cold int adpcm_encode_close(AVCodecContext *avctx) ++{ ++ ADPCMEncodeContext *s = avctx->priv_data; ++ av_freep(&avctx->coded_frame); ++ av_freep(&s->paths); ++ av_freep(&s->node_buf); ++ av_freep(&s->nodep_buf); ++ av_freep(&s->trellis_hash); ++ ++ return 0; ++} ++ ++ ++static inline unsigned char adpcm_ima_compress_sample(ADPCMChannelStatus *c, ++ short sample) ++{ ++ int delta = sample - c->prev_sample; ++ int nibble = FFMIN(7, abs(delta) * 4 / ++ ff_adpcm_step_table[c->step_index]) + (delta < 0) * 8; ++ c->prev_sample += ((ff_adpcm_step_table[c->step_index] * ++ ff_adpcm_yamaha_difflookup[nibble]) / 8); ++ c->prev_sample = av_clip_int16(c->prev_sample); ++ c->step_index = av_clip(c->step_index + ff_adpcm_index_table[nibble], 0, 88); ++ return nibble; ++} ++ ++static inline unsigned char adpcm_ima_qt_compress_sample(ADPCMChannelStatus *c, ++ short sample) ++{ ++ int delta = sample - c->prev_sample; ++ int diff, step = ff_adpcm_step_table[c->step_index]; ++ int nibble = 8*(delta < 0); ++ ++ delta= abs(delta); ++ diff = delta + (step >> 3); ++ ++ if (delta >= step) { ++ nibble |= 4; ++ delta -= step; ++ } ++ step >>= 1; ++ if (delta >= step) { ++ nibble |= 2; ++ delta -= step; ++ } ++ step >>= 1; ++ if (delta >= step) { ++ nibble |= 1; ++ delta -= step; ++ } ++ diff -= delta; ++ ++ if (nibble & 8) ++ c->prev_sample -= diff; ++ else ++ c->prev_sample += diff; ++ ++ c->prev_sample = av_clip_int16(c->prev_sample); ++ c->step_index = av_clip(c->step_index + ff_adpcm_index_table[nibble], 0, 88); ++ ++ return nibble; ++} ++ ++static inline unsigned char adpcm_ms_compress_sample(ADPCMChannelStatus *c, ++ short sample) ++{ ++ int predictor, nibble, bias; ++ ++ predictor = (((c->sample1) * (c->coeff1)) + ++ (( c->sample2) * (c->coeff2))) / 64; ++ ++ nibble = sample - predictor; ++ if (nibble >= 0) ++ bias = c->idelta / 2; ++ else ++ bias = -c->idelta / 2; ++ ++ nibble = (nibble + bias) / c->idelta; ++ nibble = av_clip(nibble, -8, 7) & 0x0F; ++ ++ predictor += (signed)((nibble & 0x08) ? (nibble - 0x10) : nibble) * c->idelta; ++ ++ c->sample2 = c->sample1; ++ c->sample1 = av_clip_int16(predictor); ++ ++ c->idelta = (ff_adpcm_AdaptationTable[(int)nibble] * c->idelta) >> 8; ++ if (c->idelta < 16) ++ c->idelta = 16; ++ ++ return nibble; ++} ++ ++static inline unsigned char adpcm_yamaha_compress_sample(ADPCMChannelStatus *c, ++ short sample) ++{ ++ int nibble, delta; ++ ++ if (!c->step) { ++ c->predictor = 0; ++ c->step = 127; ++ } ++ ++ delta = sample - c->predictor; ++ ++ nibble = FFMIN(7, abs(delta) * 4 / c->step) + (delta < 0) * 8; ++ ++ c->predictor += ((c->step * ff_adpcm_yamaha_difflookup[nibble]) / 8); ++ c->predictor = av_clip_int16(c->predictor); ++ c->step = (c->step * ff_adpcm_yamaha_indexscale[nibble]) >> 8; ++ c->step = av_clip(c->step, 127, 24567); ++ ++ return nibble; ++} ++ ++static void adpcm_compress_trellis(AVCodecContext *avctx, const short *samples, ++ uint8_t *dst, ADPCMChannelStatus *c, int n) ++{ ++ //FIXME 6% faster if frontier is a compile-time constant ++ ADPCMEncodeContext *s = avctx->priv_data; ++ const int frontier = 1 << avctx->trellis; ++ const int stride = avctx->channels; ++ const int version = avctx->codec->id; ++ TrellisPath *paths = s->paths, *p; ++ TrellisNode *node_buf = s->node_buf; ++ TrellisNode **nodep_buf = s->nodep_buf; ++ TrellisNode **nodes = nodep_buf; // nodes[] is always sorted by .ssd ++ TrellisNode **nodes_next = nodep_buf + frontier; ++ int pathn = 0, froze = -1, i, j, k, generation = 0; ++ uint8_t *hash = s->trellis_hash; ++ memset(hash, 0xff, 65536 * sizeof(*hash)); ++ ++ memset(nodep_buf, 0, 2 * frontier * sizeof(*nodep_buf)); ++ nodes[0] = node_buf + frontier; ++ nodes[0]->ssd = 0; ++ nodes[0]->path = 0; ++ nodes[0]->step = c->step_index; ++ nodes[0]->sample1 = c->sample1; ++ nodes[0]->sample2 = c->sample2; ++ if (version == CODEC_ID_ADPCM_IMA_WAV || ++ version == CODEC_ID_ADPCM_IMA_QT || ++ version == CODEC_ID_ADPCM_SWF) ++ nodes[0]->sample1 = c->prev_sample; ++ if (version == CODEC_ID_ADPCM_MS) ++ nodes[0]->step = c->idelta; ++ if (version == CODEC_ID_ADPCM_YAMAHA) { ++ if (c->step == 0) { ++ nodes[0]->step = 127; ++ nodes[0]->sample1 = 0; ++ } else { ++ nodes[0]->step = c->step; ++ nodes[0]->sample1 = c->predictor; ++ } ++ } ++ ++ for (i = 0; i < n; i++) { ++ TrellisNode *t = node_buf + frontier*(i&1); ++ TrellisNode **u; ++ int sample = samples[i * stride]; ++ int heap_pos = 0; ++ memset(nodes_next, 0, frontier * sizeof(TrellisNode*)); ++ for (j = 0; j < frontier && nodes[j]; j++) { ++ // higher j have higher ssd already, so they're likely ++ // to yield a suboptimal next sample too ++ const int range = (j < frontier / 2) ? 1 : 0; ++ const int step = nodes[j]->step; ++ int nidx; ++ if (version == CODEC_ID_ADPCM_MS) { ++ const int predictor = ((nodes[j]->sample1 * c->coeff1) + ++ (nodes[j]->sample2 * c->coeff2)) / 64; ++ const int div = (sample - predictor) / step; ++ const int nmin = av_clip(div-range, -8, 6); ++ const int nmax = av_clip(div+range, -7, 7); ++ for (nidx = nmin; nidx <= nmax; nidx++) { ++ const int nibble = nidx & 0xf; ++ int dec_sample = predictor + nidx * step; ++#define STORE_NODE(NAME, STEP_INDEX)\ ++ int d;\ ++ uint32_t ssd;\ ++ int pos;\ ++ TrellisNode *u;\ ++ uint8_t *h;\ ++ dec_sample = av_clip_int16(dec_sample);\ ++ d = sample - dec_sample;\ ++ ssd = nodes[j]->ssd + d*d;\ ++ /* Check for wraparound, skip such samples completely. \ ++ * Note, changing ssd to a 64 bit variable would be \ ++ * simpler, avoiding this check, but it's slower on \ ++ * x86 32 bit at the moment. */\ ++ if (ssd < nodes[j]->ssd)\ ++ goto next_##NAME;\ ++ /* Collapse any two states with the same previous sample value. \ ++ * One could also distinguish states by step and by 2nd to last ++ * sample, but the effects of that are negligible. ++ * Since nodes in the previous generation are iterated ++ * through a heap, they're roughly ordered from better to ++ * worse, but not strictly ordered. Therefore, an earlier ++ * node with the same sample value is better in most cases ++ * (and thus the current is skipped), but not strictly ++ * in all cases. Only skipping samples where ssd >= ++ * ssd of the earlier node with the same sample gives ++ * slightly worse quality, though, for some reason. */ \ ++ h = &hash[(uint16_t) dec_sample];\ ++ if (*h == generation)\ ++ goto next_##NAME;\ ++ if (heap_pos < frontier) {\ ++ pos = heap_pos++;\ ++ } else {\ ++ /* Try to replace one of the leaf nodes with the new \ ++ * one, but try a different slot each time. */\ ++ pos = (frontier >> 1) +\ ++ (heap_pos & ((frontier >> 1) - 1));\ ++ if (ssd > nodes_next[pos]->ssd)\ ++ goto next_##NAME;\ ++ heap_pos++;\ ++ }\ ++ *h = generation;\ ++ u = nodes_next[pos];\ ++ if (!u) {\ ++ assert(pathn < FREEZE_INTERVAL << avctx->trellis);\ ++ u = t++;\ ++ nodes_next[pos] = u;\ ++ u->path = pathn++;\ ++ }\ ++ u->ssd = ssd;\ ++ u->step = STEP_INDEX;\ ++ u->sample2 = nodes[j]->sample1;\ ++ u->sample1 = dec_sample;\ ++ paths[u->path].nibble = nibble;\ ++ paths[u->path].prev = nodes[j]->path;\ ++ /* Sift the newly inserted node up in the heap to \ ++ * restore the heap property. */\ ++ while (pos > 0) {\ ++ int parent = (pos - 1) >> 1;\ ++ if (nodes_next[parent]->ssd <= ssd)\ ++ break;\ ++ FFSWAP(TrellisNode*, nodes_next[parent], nodes_next[pos]);\ ++ pos = parent;\ ++ }\ ++ next_##NAME:; ++ STORE_NODE(ms, FFMAX(16, ++ (ff_adpcm_AdaptationTable[nibble] * step) >> 8)); ++ } ++ } else if (version == CODEC_ID_ADPCM_IMA_WAV || ++ version == CODEC_ID_ADPCM_IMA_QT || ++ version == CODEC_ID_ADPCM_SWF) { ++#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)\ ++ const int predictor = nodes[j]->sample1;\ ++ const int div = (sample - predictor) * 4 / STEP_TABLE;\ ++ int nmin = av_clip(div - range, -7, 6);\ ++ int nmax = av_clip(div + range, -6, 7);\ ++ if (nmin <= 0)\ ++ nmin--; /* distinguish -0 from +0 */\ ++ if (nmax < 0)\ ++ nmax--;\ ++ for (nidx = nmin; nidx <= nmax; nidx++) {\ ++ const int nibble = nidx < 0 ? 7 - nidx : nidx;\ ++ int dec_sample = predictor +\ ++ (STEP_TABLE *\ ++ ff_adpcm_yamaha_difflookup[nibble]) / 8;\ ++ STORE_NODE(NAME, STEP_INDEX);\ ++ } ++ LOOP_NODES(ima, ff_adpcm_step_table[step], ++ av_clip(step + ff_adpcm_index_table[nibble], 0, 88)); ++ } else { //CODEC_ID_ADPCM_YAMAHA ++ LOOP_NODES(yamaha, step, ++ av_clip((step * ff_adpcm_yamaha_indexscale[nibble]) >> 8, ++ 127, 24567)); ++#undef LOOP_NODES ++#undef STORE_NODE ++ } ++ } ++ ++ u = nodes; ++ nodes = nodes_next; ++ nodes_next = u; ++ ++ generation++; ++ if (generation == 255) { ++ memset(hash, 0xff, 65536 * sizeof(*hash)); ++ generation = 0; ++ } ++ ++ // prevent overflow ++ if (nodes[0]->ssd > (1 << 28)) { ++ for (j = 1; j < frontier && nodes[j]; j++) ++ nodes[j]->ssd -= nodes[0]->ssd; ++ nodes[0]->ssd = 0; ++ } ++ ++ // merge old paths to save memory ++ if (i == froze + FREEZE_INTERVAL) { ++ p = &paths[nodes[0]->path]; ++ for (k = i; k > froze; k--) { ++ dst[k] = p->nibble; ++ p = &paths[p->prev]; ++ } ++ froze = i; ++ pathn = 0; ++ // other nodes might use paths that don't coincide with the frozen one. ++ // checking which nodes do so is too slow, so just kill them all. ++ // this also slightly improves quality, but I don't know why. ++ memset(nodes + 1, 0, (frontier - 1) * sizeof(TrellisNode*)); ++ } ++ } ++ ++ p = &paths[nodes[0]->path]; ++ for (i = n - 1; i > froze; i--) { ++ dst[i] = p->nibble; ++ p = &paths[p->prev]; ++ } ++ ++ c->predictor = nodes[0]->sample1; ++ c->sample1 = nodes[0]->sample1; ++ c->sample2 = nodes[0]->sample2; ++ c->step_index = nodes[0]->step; ++ c->step = nodes[0]->step; ++ c->idelta = nodes[0]->step; ++} ++ ++static int adpcm_encode_frame(AVCodecContext *avctx, ++ unsigned char *frame, int buf_size, void *data) ++{ ++ int n, i, st; ++ short *samples; ++ unsigned char *dst; ++ ADPCMEncodeContext *c = avctx->priv_data; ++ uint8_t *buf; ++ ++ dst = frame; ++ samples = (short *)data; ++ st = avctx->channels == 2; ++ /* n = (BLKSIZE - 4 * avctx->channels) / (2 * 8 * avctx->channels); */ ++ ++ switch(avctx->codec->id) { ++ case CODEC_ID_ADPCM_IMA_WAV: ++ n = avctx->frame_size / 8; ++ c->status[0].prev_sample = (signed short)samples[0]; /* XXX */ ++ /* c->status[0].step_index = 0; ++ XXX: not sure how to init the state machine */ ++ bytestream_put_le16(&dst, c->status[0].prev_sample); ++ *dst++ = (unsigned char)c->status[0].step_index; ++ *dst++ = 0; /* unknown */ ++ samples++; ++ if (avctx->channels == 2) { ++ c->status[1].prev_sample = (signed short)samples[0]; ++ /* c->status[1].step_index = 0; */ ++ bytestream_put_le16(&dst, c->status[1].prev_sample); ++ *dst++ = (unsigned char)c->status[1].step_index; ++ *dst++ = 0; ++ samples++; ++ } ++ ++ /* stereo: 4 bytes (8 samples) for left, ++ 4 bytes for right, 4 bytes left, ... */ ++ if (avctx->trellis > 0) { ++ FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 8, error); ++ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n * 8); ++ if (avctx->channels == 2) ++ adpcm_compress_trellis(avctx, samples + 1, buf + n * 8, ++ &c->status[1], n * 8); ++ for (i = 0; i < n; i++) { ++ *dst++ = buf[8 * i + 0] | (buf[8 * i + 1] << 4); ++ *dst++ = buf[8 * i + 2] | (buf[8 * i + 3] << 4); ++ *dst++ = buf[8 * i + 4] | (buf[8 * i + 5] << 4); ++ *dst++ = buf[8 * i + 6] | (buf[8 * i + 7] << 4); ++ if (avctx->channels == 2) { ++ uint8_t *buf1 = buf + n * 8; ++ *dst++ = buf1[8 * i + 0] | (buf1[8 * i + 1] << 4); ++ *dst++ = buf1[8 * i + 2] | (buf1[8 * i + 3] << 4); ++ *dst++ = buf1[8 * i + 4] | (buf1[8 * i + 5] << 4); ++ *dst++ = buf1[8 * i + 6] | (buf1[8 * i + 7] << 4); ++ } ++ } ++ av_free(buf); ++ } else { ++ for (; n > 0; n--) { ++ *dst = adpcm_ima_compress_sample(&c->status[0], samples[0]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels ]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 2]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 3]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 4]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 5]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 6]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[0], samples[avctx->channels * 7]) << 4; ++ /* right channel */ ++ if (avctx->channels == 2) { ++ *dst = adpcm_ima_compress_sample(&c->status[1], samples[1 ]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[3 ]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[1], samples[5 ]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[7 ]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[1], samples[9 ]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[11]) << 4; ++ *dst = adpcm_ima_compress_sample(&c->status[1], samples[13]); ++ *dst++ |= adpcm_ima_compress_sample(&c->status[1], samples[15]) << 4; ++ } ++ samples += 8 * avctx->channels; ++ } ++ } ++ break; ++ case CODEC_ID_ADPCM_IMA_QT: ++ { ++ int ch, i; ++ PutBitContext pb; ++ init_put_bits(&pb, dst, buf_size * 8); ++ ++ for (ch = 0; ch < avctx->channels; ch++) { ++ put_bits(&pb, 9, (c->status[ch].prev_sample + 0x10000) >> 7); ++ put_bits(&pb, 7, c->status[ch].step_index); ++ if (avctx->trellis > 0) { ++ uint8_t buf[64]; ++ adpcm_compress_trellis(avctx, samples+ch, buf, &c->status[ch], 64); ++ for (i = 0; i < 64; i++) ++ put_bits(&pb, 4, buf[i ^ 1]); ++ } else { ++ for (i = 0; i < 64; i += 2) { ++ int t1, t2; ++ t1 = adpcm_ima_qt_compress_sample(&c->status[ch], ++ samples[avctx->channels * (i + 0) + ch]); ++ t2 = adpcm_ima_qt_compress_sample(&c->status[ch], ++ samples[avctx->channels * (i + 1) + ch]); ++ put_bits(&pb, 4, t2); ++ put_bits(&pb, 4, t1); ++ } ++ } ++ } ++ ++ flush_put_bits(&pb); ++ dst += put_bits_count(&pb) >> 3; ++ break; ++ } ++ case CODEC_ID_ADPCM_SWF: ++ { ++ int i; ++ PutBitContext pb; ++ init_put_bits(&pb, dst, buf_size * 8); ++ ++ n = avctx->frame_size - 1; ++ ++ // store AdpcmCodeSize ++ put_bits(&pb, 2, 2); // set 4-bit flash adpcm format ++ ++ // init the encoder state ++ for (i = 0; i < avctx->channels; i++) { ++ // clip step so it fits 6 bits ++ c->status[i].step_index = av_clip(c->status[i].step_index, 0, 63); ++ put_sbits(&pb, 16, samples[i]); ++ put_bits(&pb, 6, c->status[i].step_index); ++ c->status[i].prev_sample = (signed short)samples[i]; ++ } ++ ++ if (avctx->trellis > 0) { ++ FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error); ++ adpcm_compress_trellis(avctx, samples + 2, buf, &c->status[0], n); ++ if (avctx->channels == 2) ++ adpcm_compress_trellis(avctx, samples + 3, buf + n, ++ &c->status[1], n); ++ for (i = 0; i < n; i++) { ++ put_bits(&pb, 4, buf[i]); ++ if (avctx->channels == 2) ++ put_bits(&pb, 4, buf[n + i]); ++ } ++ av_free(buf); ++ } else { ++ for (i = 1; i < avctx->frame_size; i++) { ++ put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0], ++ samples[avctx->channels * i])); ++ if (avctx->channels == 2) ++ put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1], ++ samples[2 * i + 1])); ++ } ++ } ++ flush_put_bits(&pb); ++ dst += put_bits_count(&pb) >> 3; ++ break; ++ } ++ case CODEC_ID_ADPCM_MS: ++ for (i = 0; i < avctx->channels; i++) { ++ int predictor = 0; ++ *dst++ = predictor; ++ c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor]; ++ c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor]; ++ } ++ for (i = 0; i < avctx->channels; i++) { ++ if (c->status[i].idelta < 16) ++ c->status[i].idelta = 16; ++ bytestream_put_le16(&dst, c->status[i].idelta); ++ } ++ for (i = 0; i < avctx->channels; i++) ++ c->status[i].sample2= *samples++; ++ for (i = 0; i < avctx->channels; i++) { ++ c->status[i].sample1 = *samples++; ++ bytestream_put_le16(&dst, c->status[i].sample1); ++ } ++ for (i = 0; i < avctx->channels; i++) ++ bytestream_put_le16(&dst, c->status[i].sample2); ++ ++ if (avctx->trellis > 0) { ++ int n = avctx->block_align - 7 * avctx->channels; ++ FF_ALLOC_OR_GOTO(avctx, buf, 2 * n, error); ++ if (avctx->channels == 1) { ++ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); ++ for (i = 0; i < n; i += 2) ++ *dst++ = (buf[i] << 4) | buf[i + 1]; ++ } else { ++ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); ++ adpcm_compress_trellis(avctx, samples + 1, buf + n, &c->status[1], n); ++ for (i = 0; i < n; i++) ++ *dst++ = (buf[i] << 4) | buf[n + i]; ++ } ++ av_free(buf); ++ } else { ++ for (i = 7 * avctx->channels; i < avctx->block_align; i++) { ++ int nibble; ++ nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4; ++ nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++); ++ *dst++ = nibble; ++ } ++ } ++ break; ++ case CODEC_ID_ADPCM_YAMAHA: ++ n = avctx->frame_size / 2; ++ if (avctx->trellis > 0) { ++ FF_ALLOC_OR_GOTO(avctx, buf, 2 * n * 2, error); ++ n *= 2; ++ if (avctx->channels == 1) { ++ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); ++ for (i = 0; i < n; i += 2) ++ *dst++ = buf[i] | (buf[i + 1] << 4); ++ } else { ++ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n); ++ adpcm_compress_trellis(avctx, samples + 1, buf + n, &c->status[1], n); ++ for (i = 0; i < n; i++) ++ *dst++ = buf[i] | (buf[n + i] << 4); ++ } ++ av_free(buf); ++ } else ++ for (n *= avctx->channels; n > 0; n--) { ++ int nibble; ++ nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++); ++ nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4; ++ *dst++ = nibble; ++ } ++ break; ++ default: ++ error: ++ return -1; ++ } ++ return dst - frame; ++} ++ ++ ++#define ADPCM_ENCODER(id_, name_, long_name_) \ ++AVCodec ff_ ## name_ ## _encoder = { \ ++ .name = #name_, \ ++ .type = AVMEDIA_TYPE_AUDIO, \ ++ .id = id_, \ ++ .priv_data_size = sizeof(ADPCMEncodeContext), \ ++ .init = adpcm_encode_init, \ ++ .encode = adpcm_encode_frame, \ ++ .close = adpcm_encode_close, \ ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, \ ++ AV_SAMPLE_FMT_NONE}, \ ++ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ ++} ++ ++ADPCM_ENCODER(CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, "ADPCM IMA QuickTime"); ++ADPCM_ENCODER(CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, "ADPCM IMA WAV"); ++ADPCM_ENCODER(CODEC_ID_ADPCM_MS, adpcm_ms, "ADPCM Microsoft"); ++ADPCM_ENCODER(CODEC_ID_ADPCM_SWF, adpcm_swf, "ADPCM Shockwave Flash"); ++ADPCM_ENCODER(CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, "ADPCM Yamaha"); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adpcm.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adpcm.h 2012-05-14 14:08:53.356320299 +0200 +@@ -0,0 +1,46 @@ ++/* ++ * Copyright (c) 2001-2003 The ffmpeg Project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * ADPCM encoder/decoder common header. ++ */ ++ ++#ifndef AVCODEC_ADPCM_H ++#define AVCODEC_ADPCM_H ++ ++#define BLKSIZE 1024 ++ ++typedef struct ADPCMChannelStatus { ++ int predictor; ++ short int step_index; ++ int step; ++ /* for encoding */ ++ int prev_sample; ++ ++ /* MS version */ ++ short sample1; ++ short sample2; ++ int coeff1; ++ int coeff2; ++ int idelta; ++} ADPCMChannelStatus; ++ ++#endif /* AVCODEC_ADPCM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx.c 2012-05-14 14:08:53.360320379 +0200 +@@ -0,0 +1,81 @@ ++/* ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" ++#include "adx.h" ++ ++void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff) ++{ ++ double a, b, c; ++ ++ a = M_SQRT2 - cos(2.0 * M_PI * cutoff / sample_rate); ++ b = M_SQRT2 - 1.0; ++ c = (a - sqrt((a + b) * (a - b))) / b; ++ ++ coeff[0] = lrintf(c * 2.0 * (1 << bits)); ++ coeff[1] = lrintf(-(c * c) * (1 << bits)); ++} ++ ++int avpriv_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, ++ int bufsize, int *header_size, int *coeff) ++{ ++ int offset, cutoff; ++ ++ if (bufsize < 24) ++ return AVERROR_INVALIDDATA; ++ ++ if (AV_RB16(buf) != 0x8000) ++ return AVERROR_INVALIDDATA; ++ offset = AV_RB16(buf + 2) + 4; ++ ++ /* if copyright string is within the provided data, validate it */ ++ if (bufsize >= offset && memcmp(buf + offset - 6, "(c)CRI", 6)) ++ return AVERROR_INVALIDDATA; ++ ++ /* check for encoding=3 block_size=18, sample_size=4 */ ++ if (buf[4] != 3 || buf[5] != 18 || buf[6] != 4) { ++ av_log_ask_for_sample(avctx, "unsupported ADX format\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ /* channels */ ++ avctx->channels = buf[7]; ++ if (avctx->channels <= 0 || avctx->channels > 2) ++ return AVERROR_INVALIDDATA; ++ ++ /* sample rate */ ++ avctx->sample_rate = AV_RB32(buf + 8); ++ if (avctx->sample_rate < 1 || ++ avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8)) ++ return AVERROR_INVALIDDATA; ++ ++ /* bit rate */ ++ avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES; ++ ++ /* LPC coefficients */ ++ if (coeff) { ++ cutoff = AV_RB16(buf + 16); ++ ff_adx_calculate_coeffs(cutoff, avctx->sample_rate, COEFF_BITS, coeff); ++ } ++ ++ *header_size = offset; ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adxdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adxdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adxdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adxdec.c 2012-05-14 14:08:53.363320439 +0200 +@@ -22,6 +22,7 @@ + #include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "adx.h" ++#include "get_bits.h" + + /** + * @file +@@ -34,147 +35,151 @@ + + static av_cold int adx_decode_init(AVCodecContext *avctx) + { ++ ADXContext *c = avctx->priv_data; ++ int ret, header_size; ++ ++ if (avctx->extradata_size >= 24) { ++ if ((ret = avpriv_adx_decode_header(avctx, avctx->extradata, ++ avctx->extradata_size, &header_size, ++ c->coeff)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ c->channels = avctx->channels; ++ c->header_parsed = 1; ++ } ++ + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ + return 0; + } + +-/* 18 bytes <-> 32 samples */ +- +-static void adx_decode(short *out,const unsigned char *in,PREV *prev) ++/** ++ * Decode 32 samples from 18 bytes. ++ * ++ * A 16-bit scalar value is applied to 32 residuals, which then have a ++ * 2nd-order LPC filter applied to it to form the output signal for a single ++ * channel. ++ */ ++static int adx_decode(ADXContext *c, int16_t *out, const uint8_t *in, int ch) + { ++ ADXChannelState *prev = &c->prev[ch]; ++ GetBitContext gb; + int scale = AV_RB16(in); + int i; +- int s0,s1,s2,d; ++ int s0, s1, s2, d; + +-// printf("%x ",scale); ++ /* check if this is an EOF packet */ ++ if (scale & 0x8000) ++ return -1; + +- in+=2; ++ init_get_bits(&gb, in + 2, (BLOCK_SIZE - 2) * 8); + s1 = prev->s1; + s2 = prev->s2; +- for(i=0;i<16;i++) { +- d = in[i]; +- // d>>=4; if (d&8) d-=16; +- d = ((signed char)d >> 4); +- s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; ++ for (i = 0; i < BLOCK_SAMPLES; i++) { ++ d = get_sbits(&gb, 4); ++ s0 = ((d << COEFF_BITS) * scale + c->coeff[0] * s1 + c->coeff[1] * s2) >> COEFF_BITS; + s2 = s1; + s1 = av_clip_int16(s0); +- *out++=s1; +- +- d = in[i]; +- //d&=15; if (d&8) d-=16; +- d = ((signed char)(d<<4) >> 4); +- s0 = (BASEVOL*d*scale + SCALE1*s1 - SCALE2*s2)>>14; +- s2 = s1; +- s1 = av_clip_int16(s0); +- *out++=s1; ++ *out = s1; ++ out += c->channels; + } + prev->s1 = s1; + prev->s2 = s2; + ++ return 0; + } + +-static void adx_decode_stereo(short *out,const unsigned char *in,PREV *prev) ++static int adx_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- short tmp[32*2]; +- int i; +- +- adx_decode(tmp ,in ,prev); +- adx_decode(tmp+32,in+18,prev+1); +- for(i=0;i<32;i++) { +- out[i*2] = tmp[i]; +- out[i*2+1] = tmp[i+32]; ++ int buf_size = avpkt->size; ++ ADXContext *c = avctx->priv_data; ++ int16_t *samples; ++ const uint8_t *buf = avpkt->data; ++ int num_blocks, ch, ret; ++ ++ if (c->eof) { ++ *got_frame_ptr = 0; ++ return buf_size; ++ } ++ ++ if (!c->header_parsed && buf_size >= 2 && AV_RB16(buf) == 0x8000) { ++ int header_size; ++ if ((ret = avpriv_adx_decode_header(avctx, buf, buf_size, &header_size, ++ c->coeff)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ c->channels = avctx->channels; ++ c->header_parsed = 1; ++ if (buf_size < header_size) ++ return AVERROR_INVALIDDATA; ++ buf += header_size; ++ buf_size -= header_size; ++ } ++ if (!c->header_parsed) ++ return AVERROR_INVALIDDATA; ++ ++ /* calculate number of blocks in the packet */ ++ num_blocks = buf_size / (BLOCK_SIZE * c->channels); ++ ++ /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF ++ packet */ ++ if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) { ++ if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) { ++ c->eof = 1; ++ *got_frame_ptr = 0; ++ return avpkt->size; ++ } ++ return AVERROR_INVALIDDATA; + } +-} + +-/* return data offset or 0 */ +-static int adx_decode_header(AVCodecContext *avctx,const unsigned char *buf,size_t bufsize) +-{ +- int offset; +- +- if (buf[0]!=0x80) return 0; +- offset = (AV_RB32(buf)^0x80000000)+4; +- if (bufsizeframe.nb_samples = num_blocks * BLOCK_SAMPLES; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)c->frame.data[0]; ++ ++ while (num_blocks--) { ++ for (ch = 0; ch < c->channels; ch++) { ++ if (adx_decode(c, samples + ch, buf, ch)) { ++ c->eof = 1; ++ buf = avpkt->data + avpkt->size; ++ break; ++ } ++ buf_size -= BLOCK_SIZE; ++ buf += BLOCK_SIZE; ++ } ++ samples += BLOCK_SAMPLES * c->channels; ++ } + +- avctx->channels = buf[7]; +- avctx->sample_rate = AV_RB32(buf+8); +- avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; + +- return offset; ++ return buf - avpkt->data; + } + +-static int adx_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static void adx_decode_flush(AVCodecContext *avctx) + { +- const uint8_t *buf0 = avpkt->data; +- int buf_size = avpkt->size; + ADXContext *c = avctx->priv_data; +- short *samples = data; +- const uint8_t *buf = buf0; +- int rest = buf_size; +- +- if (!c->header_parsed) { +- int hdrsize = adx_decode_header(avctx,buf,rest); +- if (hdrsize==0) return -1; +- c->header_parsed = 1; +- buf += hdrsize; +- rest -= hdrsize; +- } +- +- /* 18 bytes of data are expanded into 32*2 bytes of audio, +- so guard against buffer overflows */ +- if(rest/18 > *data_size/64) +- rest = (*data_size/64) * 18; +- +- if (c->in_temp) { +- int copysize = 18*avctx->channels - c->in_temp; +- memcpy(c->dec_temp+c->in_temp,buf,copysize); +- rest -= copysize; +- buf += copysize; +- if (avctx->channels==1) { +- adx_decode(samples,c->dec_temp,c->prev); +- samples += 32; +- } else { +- adx_decode_stereo(samples,c->dec_temp,c->prev); +- samples += 32*2; +- } +- } +- // +- if (avctx->channels==1) { +- while(rest>=18) { +- adx_decode(samples,buf,c->prev); +- rest-=18; +- buf+=18; +- samples+=32; +- } +- } else { +- while(rest>=18*2) { +- adx_decode_stereo(samples,buf,c->prev); +- rest-=18*2; +- buf+=18*2; +- samples+=32*2; +- } +- } +- // +- c->in_temp = rest; +- if (rest) { +- memcpy(c->dec_temp,buf,rest); +- buf+=rest; +- } +- *data_size = (uint8_t*)samples - (uint8_t*)data; +-// printf("%d:%d ",buf-buf0,*data_size); fflush(stdout); +- return buf-buf0; ++ memset(c->prev, 0, sizeof(c->prev)); ++ c->eof = 0; + } + + AVCodec ff_adpcm_adx_decoder = { +- "adpcm_adx", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ADPCM_ADX, +- sizeof(ADXContext), +- adx_decode_init, +- NULL, +- NULL, +- adx_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"), ++ .name = "adpcm_adx", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_ADX, ++ .priv_data_size = sizeof(ADXContext), ++ .init = adx_decode_init, ++ .decode = adx_decode_frame, ++ .flush = adx_decode_flush, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"), + }; +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adxenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adxenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adxenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adxenc.c 2012-05-14 14:08:53.364320459 +0200 +@@ -19,9 +19,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "adx.h" ++#include "bytestream.h" ++#include "put_bits.h" + + /** + * @file +@@ -32,98 +33,97 @@ + * adx2wav & wav2adx http://www.geocities.co.jp/Playtown/2004/ + */ + +-/* 18 bytes <-> 32 samples */ +- +-static void adx_encode(unsigned char *adx,const short *wav,PREV *prev) ++static void adx_encode(ADXContext *c, uint8_t *adx, const int16_t *wav, ++ ADXChannelState *prev, int channels) + { ++ PutBitContext pb; + int scale; +- int i; +- int s0,s1,s2,d; +- int max=0; +- int min=0; +- int data[32]; ++ int i, j; ++ int s0, s1, s2, d; ++ int max = 0; ++ int min = 0; ++ int data[BLOCK_SAMPLES]; + + s1 = prev->s1; + s2 = prev->s2; +- for(i=0;i<32;i++) { ++ for (i = 0, j = 0; j < 32; i += channels, j++) { + s0 = wav[i]; +- d = ((s0<<14) - SCALE1*s1 + SCALE2*s2)/BASEVOL; +- data[i]=d; +- if (maxd) min=d; ++ d = ((s0 << COEFF_BITS) - c->coeff[0] * s1 - c->coeff[1] * s2) >> COEFF_BITS; ++ data[j] = d; ++ if (max < d) ++ max = d; ++ if (min > d) ++ min = d; + s2 = s1; + s1 = s0; + } + prev->s1 = s1; + prev->s2 = s2; + +- /* -8..+7 */ +- +- if (max==0 && min==0) { +- memset(adx,0,18); ++ if (max == 0 && min == 0) { ++ memset(adx, 0, BLOCK_SIZE); + return; + } + +- if (max/7>-min/8) scale = max/7; +- else scale = -min/8; ++ if (max / 7 > -min / 8) ++ scale = max / 7; ++ else ++ scale = -min / 8; + +- if (scale==0) scale=1; ++ if (scale == 0) ++ scale = 1; + + AV_WB16(adx, scale); + +- for(i=0;i<16;i++) { +- adx[i+2] = ((data[i*2]/scale)<<4) | ((data[i*2+1]/scale)&0xf); +- } ++ init_put_bits(&pb, adx + 2, 16); ++ for (i = 0; i < BLOCK_SAMPLES; i++) ++ put_sbits(&pb, 4, av_clip(data[i] / scale, -8, 7)); ++ flush_put_bits(&pb); + } + +-static int adx_encode_header(AVCodecContext *avctx,unsigned char *buf,size_t bufsize) ++#define HEADER_SIZE 36 ++ ++static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize) + { +-#if 0 +- struct { +- uint32_t offset; /* 0x80000000 + sample start - 4 */ +- unsigned char unknown1[3]; /* 03 12 04 */ +- unsigned char channel; /* 1 or 2 */ +- uint32_t freq; +- uint32_t size; +- uint32_t unknown2; /* 01 f4 03 00 */ +- uint32_t unknown3; /* 00 00 00 00 */ +- uint32_t unknown4; /* 00 00 00 00 */ +- +- /* if loop +- unknown3 00 15 00 01 +- unknown4 00 00 00 01 +- long loop_start_sample; +- long loop_start_byte; +- long loop_end_sample; +- long loop_end_byte; +- long +- */ +- } adxhdr; /* big endian */ +- /* offset-6 "(c)CRI" */ +-#endif +- AV_WB32(buf+0x00,0x80000000|0x20); +- AV_WB32(buf+0x04,0x03120400|avctx->channels); +- AV_WB32(buf+0x08,avctx->sample_rate); +- AV_WB32(buf+0x0c,0); /* FIXME: set after */ +- AV_WB32(buf+0x10,0x01040300); +- AV_WB32(buf+0x14,0x00000000); +- AV_WB32(buf+0x18,0x00000000); +- memcpy(buf+0x1c,"\0\0(c)CRI",8); +- return 0x20+4; ++ ADXContext *c = avctx->priv_data; ++ ++ if (bufsize < HEADER_SIZE) ++ return AVERROR(EINVAL); ++ ++ bytestream_put_be16(&buf, 0x8000); /* header signature */ ++ bytestream_put_be16(&buf, HEADER_SIZE - 4); /* copyright offset */ ++ bytestream_put_byte(&buf, 3); /* encoding */ ++ bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */ ++ bytestream_put_byte(&buf, 4); /* sample size */ ++ bytestream_put_byte(&buf, avctx->channels); /* channels */ ++ bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */ ++ bytestream_put_be32(&buf, 0); /* total sample count */ ++ bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */ ++ bytestream_put_byte(&buf, 3); /* version */ ++ bytestream_put_byte(&buf, 0); /* flags */ ++ bytestream_put_be32(&buf, 0); /* unknown */ ++ bytestream_put_be32(&buf, 0); /* loop enabled */ ++ bytestream_put_be16(&buf, 0); /* padding */ ++ bytestream_put_buffer(&buf, "(c)CRI", 6); /* copyright signature */ ++ ++ return HEADER_SIZE; + } + + static av_cold int adx_encode_init(AVCodecContext *avctx) + { +- if (avctx->channels > 2) +- return -1; /* only stereo or mono =) */ +- avctx->frame_size = 32; ++ ADXContext *c = avctx->priv_data; + +- avctx->coded_frame= avcodec_alloc_frame(); +- avctx->coded_frame->key_frame= 1; ++ if (avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ avctx->frame_size = BLOCK_SAMPLES; + +-// avctx->bit_rate = avctx->sample_rate*avctx->channels*18*8/32; ++ avctx->coded_frame = avcodec_alloc_frame(); + +- av_log(avctx, AV_LOG_DEBUG, "adx encode init\n"); ++ /* the cutoff can be adjusted, but this seems to work pretty well */ ++ c->cutoff = 500; ++ ff_adx_calculate_coeffs(c->cutoff, avctx->sample_rate, COEFF_BITS, c->coeff); + + return 0; + } +@@ -131,67 +131,48 @@ + static av_cold int adx_encode_close(AVCodecContext *avctx) + { + av_freep(&avctx->coded_frame); +- + return 0; + } + +-static int adx_encode_frame(AVCodecContext *avctx, +- uint8_t *frame, int buf_size, void *data) ++static int adx_encode_frame(AVCodecContext *avctx, uint8_t *frame, ++ int buf_size, void *data) + { +- ADXContext *c = avctx->priv_data; +- const short *samples = data; +- unsigned char *dst = frame; +- int rest = avctx->frame_size; +- +-/* +- input data size = +- ffmpeg.c: do_audio_out() +- frame_bytes = enc->frame_size * 2 * enc->channels; +-*/ ++ ADXContext *c = avctx->priv_data; ++ const int16_t *samples = data; ++ uint8_t *dst = frame; ++ int ch; + +-// printf("sz=%d ",buf_size); fflush(stdout); + if (!c->header_parsed) { +- int hdrsize = adx_encode_header(avctx,dst,buf_size); +- dst+=hdrsize; ++ int hdrsize; ++ if ((hdrsize = adx_encode_header(avctx, dst, buf_size)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ dst += hdrsize; ++ buf_size -= hdrsize; + c->header_parsed = 1; + } ++ if (buf_size < BLOCK_SIZE * avctx->channels) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer is too small\n"); ++ return AVERROR(EINVAL); ++ } + +- if (avctx->channels==1) { +- while(rest>=32) { +- adx_encode(dst,samples,c->prev); +- dst+=18; +- samples+=32; +- rest-=32; +- } +- } else { +- while(rest>=32*2) { +- short tmpbuf[32*2]; +- int i; +- +- for(i=0;i<32;i++) { +- tmpbuf[i] = samples[i*2]; +- tmpbuf[i+32] = samples[i*2+1]; +- } +- +- adx_encode(dst,tmpbuf,c->prev); +- adx_encode(dst+18,tmpbuf+32,c->prev+1); +- dst+=18*2; +- samples+=32*2; +- rest-=32*2; +- } ++ for (ch = 0; ch < avctx->channels; ch++) { ++ adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels); ++ dst += BLOCK_SIZE; + } +- return dst-frame; ++ return dst - frame; + } + + AVCodec ff_adpcm_adx_encoder = { +- "adpcm_adx", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ADPCM_ADX, +- sizeof(ADXContext), +- adx_encode_init, +- adx_encode_frame, +- adx_encode_close, +- NULL, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"), ++ .name = "adpcm_adx", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_ADX, ++ .priv_data_size = sizeof(ADXContext), ++ .init = adx_encode_init, ++ .encode = adx_encode_frame, ++ .close = adx_encode_close, ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("SEGA CRI ADX ADPCM"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx.h 2012-05-14 14:08:53.361320399 +0200 +@@ -31,19 +31,51 @@ + #ifndef AVCODEC_ADX_H + #define AVCODEC_ADX_H + ++#include ++ ++#include "avcodec.h" ++ + typedef struct { + int s1,s2; +-} PREV; ++} ADXChannelState; + + typedef struct { +- PREV prev[2]; ++ AVFrame frame; ++ int channels; ++ ADXChannelState prev[2]; + int header_parsed; +- unsigned char dec_temp[18*2]; +- int in_temp; ++ int eof; ++ int cutoff; ++ int coeff[2]; + } ADXContext; + +-#define BASEVOL 0x4000 +-#define SCALE1 0x7298 +-#define SCALE2 0x3350 ++#define COEFF_BITS 12 ++ ++#define BLOCK_SIZE 18 ++#define BLOCK_SAMPLES 32 ++ ++/** ++ * Calculate LPC coefficients based on cutoff frequency and sample rate. ++ * ++ * @param cutoff cutoff frequency ++ * @param sample_rate sample rate ++ * @param bits number of bits used to quantize coefficients ++ * @param[out] coeff 2 quantized LPC coefficients ++ */ ++void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff); ++ ++/** ++ * Decode ADX stream header. ++ * Sets avctx->channels and avctx->sample_rate. ++ * ++ * @param avctx codec context ++ * @param buf header data ++ * @param bufsize data size, should be at least 24 bytes ++ * @param[out] header_size size of ADX header ++ * @param[out] coeff 2 LPC coefficients, can be NULL ++ * @return data offset or negative error code if header is invalid ++ */ ++int avpriv_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, ++ int bufsize, int *header_size, int *coeff); + + #endif /* AVCODEC_ADX_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/adx_parser.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/adx_parser.c 2012-05-14 14:08:53.362320419 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * ADX audio parser ++ * ++ * Splits packets into individual blocks. ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "parser.h" ++#include "adx.h" ++ ++typedef struct ADXParseContext { ++ ParseContext pc; ++ int header_size; ++ int block_size; ++ int remaining; ++} ADXParseContext; ++ ++static int adx_parse(AVCodecParserContext *s1, ++ AVCodecContext *avctx, ++ const uint8_t **poutbuf, int *poutbuf_size, ++ const uint8_t *buf, int buf_size) ++{ ++ ADXParseContext *s = s1->priv_data; ++ ParseContext *pc = &s->pc; ++ int next = END_NOT_FOUND; ++ int i; ++ uint64_t state = pc->state64; ++ ++ if (!s->header_size) { ++ for (i = 0; i < buf_size; i++) { ++ state = (state << 8) | buf[i]; ++ /* check for fixed fields in ADX header for possible match */ ++ if ((state & 0xFFFF0000FFFFFF00) == 0x8000000003120400ULL) { ++ int channels = state & 0xFF; ++ int header_size = ((state >> 32) & 0xFFFF) + 4; ++ if (channels > 0 && header_size >= 8) { ++ s->header_size = header_size; ++ s->block_size = BLOCK_SIZE * channels; ++ s->remaining = i - 7 + s->header_size + s->block_size; ++ break; ++ } ++ } ++ } ++ pc->state64 = state; ++ } ++ ++ if (s->header_size) { ++ if (!s->remaining) ++ s->remaining = s->block_size; ++ if (s->remaining <= buf_size) { ++ next = s->remaining; ++ s->remaining = 0; ++ } else ++ s->remaining -= buf_size; ++ } ++ ++ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) { ++ *poutbuf = NULL; ++ *poutbuf_size = 0; ++ return buf_size; ++ } ++ *poutbuf = buf; ++ *poutbuf_size = buf_size; ++ return next; ++} ++ ++AVCodecParser ff_adx_parser = { ++ .codec_ids = { CODEC_ID_ADPCM_ADX }, ++ .priv_data_size = sizeof(ADXParseContext), ++ .parser_parse = adx_parse, ++ .parser_close = ff_parse_close, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alac.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alac.c 2012-05-14 14:08:53.367320519 +0200 +@@ -23,31 +23,25 @@ + * @file + * ALAC (Apple Lossless Audio Codec) decoder + * @author 2005 David Hammerton ++ * @see http://crazney.net/programs/itunes/alac.html + * +- * For more information on the ALAC format, visit: +- * http://crazney.net/programs/itunes/alac.html +- * +- * Note: This decoder expects a 36- (0x24-)byte QuickTime atom to be ++ * Note: This decoder expects a 36-byte QuickTime atom to be + * passed through the extradata[_size] fields. This atom is tacked onto + * the end of an 'alac' stsd atom and has the following format: +- * bytes 0-3 atom size (0x24), big-endian +- * bytes 4-7 atom type ('alac', not the 'alac' tag from start of stsd) +- * bytes 8-35 data bytes needed by decoder + * +- * Extradata: +- * 32bit size +- * 32bit tag (=alac) +- * 32bit zero? +- * 32bit max sample per frame +- * 8bit ?? (zero?) ++ * 32bit atom size ++ * 32bit tag ("alac") ++ * 32bit tag version (0) ++ * 32bit samples per frame (used when not set explicitly in the frames) ++ * 8bit compatible version (0) + * 8bit sample size +- * 8bit history mult +- * 8bit initial history +- * 8bit kmodifier +- * 8bit channels? +- * 16bit ?? +- * 32bit max coded frame size +- * 32bit bitrate? ++ * 8bit history mult (40) ++ * 8bit initial history (14) ++ * 8bit kmodifier (10) ++ * 8bit channels ++ * 16bit maxRun (255) ++ * 32bit max coded frame size (0 means unknown) ++ * 32bit average bitrate (0 means unknown) + * 32bit samplerate + */ + +@@ -64,17 +58,17 @@ + typedef struct { + + AVCodecContext *avctx; ++ AVFrame frame; + GetBitContext gb; + + int numchannels; +- int bytespersample; + + /* buffers */ + int32_t *predicterror_buffer[MAX_CHANNELS]; + + int32_t *outputsamples_buffer[MAX_CHANNELS]; + +- int32_t *wasted_bits_buffer[MAX_CHANNELS]; ++ int32_t *extra_bits_buffer[MAX_CHANNELS]; + + /* stuff from setinfo */ + uint32_t setinfo_max_samples_per_frame; /* 0x1000 = 4096 */ /* max samples per frame? */ +@@ -84,58 +78,9 @@ + uint8_t setinfo_rice_kmodifier; /* 0x0e */ + /* end setinfo stuff */ + +- int wasted_bits; ++ int extra_bits; /**< number of extra bits beyond 16-bit */ + } ALACContext; + +-static void allocate_buffers(ALACContext *alac) +-{ +- int chan; +- for (chan = 0; chan < MAX_CHANNELS; chan++) { +- alac->predicterror_buffer[chan] = +- av_malloc(alac->setinfo_max_samples_per_frame * 4); +- +- alac->outputsamples_buffer[chan] = +- av_malloc(alac->setinfo_max_samples_per_frame * 4); +- +- alac->wasted_bits_buffer[chan] = av_malloc(alac->setinfo_max_samples_per_frame * 4); +- } +-} +- +-static int alac_set_info(ALACContext *alac) +-{ +- const unsigned char *ptr = alac->avctx->extradata; +- +- ptr += 4; /* size */ +- ptr += 4; /* alac */ +- ptr += 4; /* 0 ? */ +- +- if(AV_RB32(ptr) >= UINT_MAX/4){ +- av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n"); +- return -1; +- } +- +- /* buffer size / 2 ? */ +- alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr); +- ptr++; /* ??? */ +- alac->setinfo_sample_size = *ptr++; +- if (alac->setinfo_sample_size > 32) { +- av_log(alac->avctx, AV_LOG_ERROR, "setinfo_sample_size too large\n"); +- return -1; +- } +- alac->setinfo_rice_historymult = *ptr++; +- alac->setinfo_rice_initialhistory = *ptr++; +- alac->setinfo_rice_kmodifier = *ptr++; +- ptr++; /* channels? */ +- bytestream_get_be16(&ptr); /* ??? */ +- bytestream_get_be32(&ptr); /* max coded frame size */ +- bytestream_get_be32(&ptr); /* bitrate ? */ +- bytestream_get_be32(&ptr); /* samplerate */ +- +- allocate_buffers(alac); +- +- return 0; +-} +- + static inline int decode_scalar(GetBitContext *gb, int k, int limit, int readsamplesize){ + /* read x - number of 1s before 0 represent the rice */ + int x = get_unary_0_9(gb); +@@ -163,7 +108,7 @@ + return x; + } + +-static void bastardized_rice_decompress(ALACContext *alac, ++static int bastardized_rice_decompress(ALACContext *alac, + int32_t *output_buffer, + int output_size, + int readsamplesize, /* arg_10 */ +@@ -185,6 +130,9 @@ + /* standard rice encoding */ + int k; /* size of extra bits */ + ++ if(get_bits_left(&alac->gb) <= 0) ++ return -1; ++ + /* read k, that is bits as is */ + k = av_log2((history >> 9) + 3); + x= decode_scalar(&alac->gb, k, rice_kmodifier, readsamplesize); +@@ -230,6 +178,7 @@ + history = 0; + } + } ++ return 0; + } + + static inline int sign_only(int v) +@@ -286,20 +235,9 @@ + buffer_out[i+1] = val; + } + +-#if 0 + /* 4 and 8 are very common cases (the only ones i've seen). these + * should be unrolled and optimized + */ +- if (predictor_coef_num == 4) { +- /* FIXME: optimized general case */ +- return; +- } +- +- if (predictor_coef_table == 8) { +- /* FIXME: optimized general case */ +- return; +- } +-#endif + + /* general case */ + if (predictor_coef_num > 0) { +@@ -360,99 +298,72 @@ + } + } + +-static void reconstruct_stereo_16(int32_t *buffer[MAX_CHANNELS], +- int16_t *buffer_out, +- int numchannels, int numsamples, +- uint8_t interlacing_shift, +- uint8_t interlacing_leftweight) ++static void decorrelate_stereo(int32_t *buffer[MAX_CHANNELS], ++ int numsamples, uint8_t interlacing_shift, ++ uint8_t interlacing_leftweight) + { + int i; +- if (numsamples <= 0) +- return; +- +- /* weighted interlacing */ +- if (interlacing_leftweight) { +- for (i = 0; i < numsamples; i++) { +- int32_t a, b; + +- a = buffer[0][i]; +- b = buffer[1][i]; ++ for (i = 0; i < numsamples; i++) { ++ int32_t a, b; + +- a -= (b * interlacing_leftweight) >> interlacing_shift; +- b += a; ++ a = buffer[0][i]; ++ b = buffer[1][i]; + +- buffer_out[i*numchannels] = b; +- buffer_out[i*numchannels + 1] = a; +- } ++ a -= (b * interlacing_leftweight) >> interlacing_shift; ++ b += a; + +- return; ++ buffer[0][i] = b; ++ buffer[1][i] = a; + } ++} + +- /* otherwise basic interlacing took place */ +- for (i = 0; i < numsamples; i++) { +- int16_t left, right; +- +- left = buffer[0][i]; +- right = buffer[1][i]; ++static void append_extra_bits(int32_t *buffer[MAX_CHANNELS], ++ int32_t *extra_bits_buffer[MAX_CHANNELS], ++ int extra_bits, int numchannels, int numsamples) ++{ ++ int i, ch; + +- buffer_out[i*numchannels] = left; +- buffer_out[i*numchannels + 1] = right; +- } ++ for (ch = 0; ch < numchannels; ch++) ++ for (i = 0; i < numsamples; i++) ++ buffer[ch][i] = (buffer[ch][i] << extra_bits) | extra_bits_buffer[ch][i]; + } + +-static void decorrelate_stereo_24(int32_t *buffer[MAX_CHANNELS], +- int32_t *buffer_out, +- int32_t *wasted_bits_buffer[MAX_CHANNELS], +- int wasted_bits, +- int numchannels, int numsamples, +- uint8_t interlacing_shift, +- uint8_t interlacing_leftweight) ++static void interleave_stereo_16(int32_t *buffer[MAX_CHANNELS], ++ int16_t *buffer_out, int numsamples) + { + int i; + +- if (numsamples <= 0) +- return; +- +- /* weighted interlacing */ +- if (interlacing_leftweight) { +- for (i = 0; i < numsamples; i++) { +- int32_t a, b; +- +- a = buffer[0][i]; +- b = buffer[1][i]; +- +- a -= (b * interlacing_leftweight) >> interlacing_shift; +- b += a; +- +- if (wasted_bits) { +- b = (b << wasted_bits) | wasted_bits_buffer[0][i]; +- a = (a << wasted_bits) | wasted_bits_buffer[1][i]; +- } ++ for (i = 0; i < numsamples; i++) { ++ *buffer_out++ = buffer[0][i]; ++ *buffer_out++ = buffer[1][i]; ++ } ++} + +- buffer_out[i * numchannels] = b << 8; +- buffer_out[i * numchannels + 1] = a << 8; +- } +- } else { +- for (i = 0; i < numsamples; i++) { +- int32_t left, right; ++static void interleave_stereo_24(int32_t *buffer[MAX_CHANNELS], ++ int32_t *buffer_out, int numsamples) ++{ ++ int i; + +- left = buffer[0][i]; +- right = buffer[1][i]; ++ for (i = 0; i < numsamples; i++) { ++ *buffer_out++ = buffer[0][i] << 8; ++ *buffer_out++ = buffer[1][i] << 8; ++ } ++} + +- if (wasted_bits) { +- left = (left << wasted_bits) | wasted_bits_buffer[0][i]; +- right = (right << wasted_bits) | wasted_bits_buffer[1][i]; +- } ++static void interleave_stereo_32(int32_t *buffer[MAX_CHANNELS], ++ int32_t *buffer_out, int numsamples) ++{ ++ int i; + +- buffer_out[i * numchannels] = left << 8; +- buffer_out[i * numchannels + 1] = right << 8; +- } ++ for (i = 0; i < numsamples; i++) { ++ *buffer_out++ = buffer[0][i]; ++ *buffer_out++ = buffer[1][i]; + } + } + +-static int alac_decode_frame(AVCodecContext *avctx, +- void *outbuffer, int *outputsize, +- AVPacket *avpkt) ++static int alac_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *inbuffer = avpkt->data; + int input_buffer_size = avpkt->size; +@@ -465,18 +376,14 @@ + int isnotcompressed; + uint8_t interlacing_shift; + uint8_t interlacing_leftweight; +- +- /* short-circuit null buffers */ +- if (!inbuffer || !input_buffer_size) +- return -1; ++ int i, ch, ret; + + init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8); + + channels = get_bits(&alac->gb, 3) + 1; +- if (channels > MAX_CHANNELS) { +- av_log(avctx, AV_LOG_ERROR, "channels > %d not supported\n", +- MAX_CHANNELS); +- return -1; ++ if (channels != avctx->channels) { ++ av_log(avctx, AV_LOG_ERROR, "frame header channel count mismatch\n"); ++ return AVERROR_INVALIDDATA; + } + + /* 2^result = something to do with output waiting. +@@ -489,7 +396,7 @@ + /* the output sample size is stored soon */ + hassize = get_bits1(&alac->gb); + +- alac->wasted_bits = get_bits(&alac->gb, 2) << 3; ++ alac->extra_bits = get_bits(&alac->gb, 2) << 3; + + /* whether the frame is compressed */ + isnotcompressed = get_bits1(&alac->gb); +@@ -504,25 +411,18 @@ + } else + outputsamples = alac->setinfo_max_samples_per_frame; + +- switch (alac->setinfo_sample_size) { +- case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- alac->bytespersample = channels << 1; +- break; +- case 24: avctx->sample_fmt = AV_SAMPLE_FMT_S32; +- alac->bytespersample = channels << 2; +- break; +- default: av_log(avctx, AV_LOG_ERROR, "Sample depth %d is not supported.\n", +- alac->setinfo_sample_size); +- return -1; ++ /* get output buffer */ ++ if (outputsamples > INT32_MAX) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", outputsamples); ++ return AVERROR_INVALIDDATA; ++ } ++ alac->frame.nb_samples = outputsamples; ++ if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } + +- if(outputsamples > *outputsize / alac->bytespersample){ +- av_log(avctx, AV_LOG_ERROR, "sample buffer too small\n"); +- return -1; +- } +- +- *outputsize = outputsamples * alac->bytespersample; +- readsamplesize = alac->setinfo_sample_size - (alac->wasted_bits) + channels - 1; ++ readsamplesize = alac->setinfo_sample_size - alac->extra_bits + channels - 1; + if (readsamplesize > MIN_CACHE_BITS) { + av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", readsamplesize); + return -1; +@@ -535,118 +435,123 @@ + int prediction_type[MAX_CHANNELS]; + int prediction_quantitization[MAX_CHANNELS]; + int ricemodifier[MAX_CHANNELS]; +- int i, chan; + + interlacing_shift = get_bits(&alac->gb, 8); + interlacing_leftweight = get_bits(&alac->gb, 8); + +- for (chan = 0; chan < channels; chan++) { +- prediction_type[chan] = get_bits(&alac->gb, 4); +- prediction_quantitization[chan] = get_bits(&alac->gb, 4); ++ for (ch = 0; ch < channels; ch++) { ++ prediction_type[ch] = get_bits(&alac->gb, 4); ++ prediction_quantitization[ch] = get_bits(&alac->gb, 4); + +- ricemodifier[chan] = get_bits(&alac->gb, 3); +- predictor_coef_num[chan] = get_bits(&alac->gb, 5); ++ ricemodifier[ch] = get_bits(&alac->gb, 3); ++ predictor_coef_num[ch] = get_bits(&alac->gb, 5); + + /* read the predictor table */ +- for (i = 0; i < predictor_coef_num[chan]; i++) +- predictor_coef_table[chan][i] = (int16_t)get_bits(&alac->gb, 16); ++ for (i = 0; i < predictor_coef_num[ch]; i++) ++ predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16); + } + +- if (alac->wasted_bits) { +- int i, ch; ++ if (alac->extra_bits) { + for (i = 0; i < outputsamples; i++) { ++ if(get_bits_left(&alac->gb) <= 0) ++ return -1; + for (ch = 0; ch < channels; ch++) +- alac->wasted_bits_buffer[ch][i] = get_bits(&alac->gb, alac->wasted_bits); ++ alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, alac->extra_bits); + } + } +- for (chan = 0; chan < channels; chan++) { +- bastardized_rice_decompress(alac, +- alac->predicterror_buffer[chan], ++ for (ch = 0; ch < channels; ch++) { ++ int ret = bastardized_rice_decompress(alac, ++ alac->predicterror_buffer[ch], + outputsamples, + readsamplesize, + alac->setinfo_rice_initialhistory, + alac->setinfo_rice_kmodifier, +- ricemodifier[chan] * alac->setinfo_rice_historymult / 4, ++ ricemodifier[ch] * alac->setinfo_rice_historymult / 4, + (1 << alac->setinfo_rice_kmodifier) - 1); ++ if(ret<0) ++ return ret; + +- if (prediction_type[chan] == 0) { +- /* adaptive fir */ +- predictor_decompress_fir_adapt(alac->predicterror_buffer[chan], +- alac->outputsamples_buffer[chan], +- outputsamples, +- readsamplesize, +- predictor_coef_table[chan], +- predictor_coef_num[chan], +- prediction_quantitization[chan]); +- } else { +- av_log(avctx, AV_LOG_ERROR, "FIXME: unhandled prediction type: %i\n", prediction_type[chan]); +- /* I think the only other prediction type (or perhaps this is +- * just a boolean?) runs adaptive fir twice.. like: +- * predictor_decompress_fir_adapt(predictor_error, tempout, ...) +- * predictor_decompress_fir_adapt(predictor_error, outputsamples ...) +- * little strange.. ++ /* adaptive FIR filter */ ++ if (prediction_type[ch] == 15) { ++ /* Prediction type 15 runs the adaptive FIR twice. ++ * The first pass uses the special-case coef_num = 31, while ++ * the second pass uses the coefs from the bitstream. ++ * ++ * However, this prediction type is not currently used by the ++ * reference encoder. + */ ++ predictor_decompress_fir_adapt(alac->predicterror_buffer[ch], ++ alac->predicterror_buffer[ch], ++ outputsamples, readsamplesize, ++ NULL, 31, 0); ++ } else if (prediction_type[ch] > 0) { ++ av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n", ++ prediction_type[ch]); + } ++ predictor_decompress_fir_adapt(alac->predicterror_buffer[ch], ++ alac->outputsamples_buffer[ch], ++ outputsamples, readsamplesize, ++ predictor_coef_table[ch], ++ predictor_coef_num[ch], ++ prediction_quantitization[ch]); + } + } else { + /* not compressed, easy case */ +- int i, chan; +- if (alac->setinfo_sample_size <= 16) { +- for (i = 0; i < outputsamples; i++) +- for (chan = 0; chan < channels; chan++) { +- int32_t audiobits; +- +- audiobits = get_sbits_long(&alac->gb, alac->setinfo_sample_size); +- +- alac->outputsamples_buffer[chan][i] = audiobits; +- } +- } else { +- for (i = 0; i < outputsamples; i++) { +- for (chan = 0; chan < channels; chan++) { +- alac->outputsamples_buffer[chan][i] = get_bits(&alac->gb, +- alac->setinfo_sample_size); +- alac->outputsamples_buffer[chan][i] = sign_extend(alac->outputsamples_buffer[chan][i], +- alac->setinfo_sample_size); +- } ++ for (i = 0; i < outputsamples; i++) { ++ if(get_bits_left(&alac->gb) <= 0) ++ return -1; ++ for (ch = 0; ch < channels; ch++) { ++ alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb, ++ alac->setinfo_sample_size); + } + } +- alac->wasted_bits = 0; ++ alac->extra_bits = 0; + interlacing_shift = 0; + interlacing_leftweight = 0; + } + if (get_bits(&alac->gb, 3) != 7) + av_log(avctx, AV_LOG_ERROR, "Error : Wrong End Of Frame\n"); + ++ if (channels == 2 && interlacing_leftweight) { ++ decorrelate_stereo(alac->outputsamples_buffer, outputsamples, ++ interlacing_shift, interlacing_leftweight); ++ } ++ ++ if (alac->extra_bits) { ++ append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer, ++ alac->extra_bits, alac->numchannels, outputsamples); ++ } ++ + switch(alac->setinfo_sample_size) { + case 16: + if (channels == 2) { +- reconstruct_stereo_16(alac->outputsamples_buffer, +- (int16_t*)outbuffer, +- alac->numchannels, +- outputsamples, +- interlacing_shift, +- interlacing_leftweight); ++ interleave_stereo_16(alac->outputsamples_buffer, ++ (int16_t *)alac->frame.data[0], outputsamples); + } else { +- int i; ++ int16_t *outbuffer = (int16_t *)alac->frame.data[0]; + for (i = 0; i < outputsamples; i++) { +- ((int16_t*)outbuffer)[i] = alac->outputsamples_buffer[0][i]; ++ outbuffer[i] = alac->outputsamples_buffer[0][i]; + } + } + break; + case 24: + if (channels == 2) { +- decorrelate_stereo_24(alac->outputsamples_buffer, +- outbuffer, +- alac->wasted_bits_buffer, +- alac->wasted_bits, +- alac->numchannels, +- outputsamples, +- interlacing_shift, +- interlacing_leftweight); ++ interleave_stereo_24(alac->outputsamples_buffer, ++ (int32_t *)alac->frame.data[0], outputsamples); ++ } else { ++ int32_t *outbuffer = (int32_t *)alac->frame.data[0]; ++ for (i = 0; i < outputsamples; i++) ++ outbuffer[i] = alac->outputsamples_buffer[0][i] << 8; ++ } ++ break; ++ case 32: ++ if (channels == 2) { ++ interleave_stereo_32(alac->outputsamples_buffer, ++ (int32_t *)alac->frame.data[0], outputsamples); + } else { +- int i; ++ int32_t *outbuffer = (int32_t *)alac->frame.data[0]; + for (i = 0; i < outputsamples; i++) +- ((int32_t *)outbuffer)[i] = alac->outputsamples_buffer[0][i] << 8; ++ outbuffer[i] = alac->outputsamples_buffer[0][i]; + } + break; + } +@@ -654,14 +559,81 @@ + if (input_buffer_size * 8 - get_bits_count(&alac->gb) > 8) + av_log(avctx, AV_LOG_ERROR, "Error : %d bits left\n", input_buffer_size * 8 - get_bits_count(&alac->gb)); + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = alac->frame; ++ + return input_buffer_size; + } + ++static av_cold int alac_decode_close(AVCodecContext *avctx) ++{ ++ ALACContext *alac = avctx->priv_data; ++ ++ int ch; ++ for (ch = 0; ch < alac->numchannels; ch++) { ++ av_freep(&alac->predicterror_buffer[ch]); ++ av_freep(&alac->outputsamples_buffer[ch]); ++ av_freep(&alac->extra_bits_buffer[ch]); ++ } ++ ++ return 0; ++} ++ ++static int allocate_buffers(ALACContext *alac) ++{ ++ int ch; ++ for (ch = 0; ch < alac->numchannels; ch++) { ++ int buf_size = alac->setinfo_max_samples_per_frame * sizeof(int32_t); ++ ++ FF_ALLOC_OR_GOTO(alac->avctx, alac->predicterror_buffer[ch], ++ buf_size, buf_alloc_fail); ++ ++ FF_ALLOC_OR_GOTO(alac->avctx, alac->outputsamples_buffer[ch], ++ buf_size, buf_alloc_fail); ++ ++ FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch], ++ buf_size, buf_alloc_fail); ++ } ++ return 0; ++buf_alloc_fail: ++ alac_decode_close(alac->avctx); ++ return AVERROR(ENOMEM); ++} ++ ++static int alac_set_info(ALACContext *alac) ++{ ++ const unsigned char *ptr = alac->avctx->extradata; ++ ++ ptr += 4; /* size */ ++ ptr += 4; /* alac */ ++ ptr += 4; /* version */ ++ ++ if(AV_RB32(ptr) >= UINT_MAX/4){ ++ av_log(alac->avctx, AV_LOG_ERROR, "setinfo_max_samples_per_frame too large\n"); ++ return -1; ++ } ++ ++ /* buffer size / 2 ? */ ++ alac->setinfo_max_samples_per_frame = bytestream_get_be32(&ptr); ++ ptr++; /* compatible version */ ++ alac->setinfo_sample_size = *ptr++; ++ alac->setinfo_rice_historymult = *ptr++; ++ alac->setinfo_rice_initialhistory = *ptr++; ++ alac->setinfo_rice_kmodifier = *ptr++; ++ alac->numchannels = *ptr++; ++ bytestream_get_be16(&ptr); /* maxRun */ ++ bytestream_get_be32(&ptr); /* max coded frame size */ ++ bytestream_get_be32(&ptr); /* average bitrate */ ++ bytestream_get_be32(&ptr); /* samplerate */ ++ ++ return 0; ++} ++ + static av_cold int alac_decode_init(AVCodecContext * avctx) + { ++ int ret; + ALACContext *alac = avctx->priv_data; + alac->avctx = avctx; +- alac->numchannels = alac->avctx->channels; + + /* initialize from the extradata */ + if (alac->avctx->extradata_size != ALAC_EXTRADATA_SIZE) { +@@ -674,31 +646,51 @@ + return -1; + } + +- return 0; +-} ++ switch (alac->setinfo_sample_size) { ++ case 16: avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ break; ++ case 32: ++ case 24: avctx->sample_fmt = AV_SAMPLE_FMT_S32; ++ break; ++ default: av_log_ask_for_sample(avctx, "Sample depth %d is not supported.\n", ++ alac->setinfo_sample_size); ++ return AVERROR_PATCHWELCOME; ++ } + +-static av_cold int alac_decode_close(AVCodecContext *avctx) +-{ +- ALACContext *alac = avctx->priv_data; ++ if (alac->numchannels < 1) { ++ av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n"); ++ alac->numchannels = avctx->channels; ++ } else { ++ if (alac->numchannels > MAX_CHANNELS) ++ alac->numchannels = avctx->channels; ++ else ++ avctx->channels = alac->numchannels; ++ } ++ if (avctx->channels > MAX_CHANNELS) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported channel count: %d\n", ++ avctx->channels); ++ return AVERROR_PATCHWELCOME; ++ } + +- int chan; +- for (chan = 0; chan < MAX_CHANNELS; chan++) { +- av_freep(&alac->predicterror_buffer[chan]); +- av_freep(&alac->outputsamples_buffer[chan]); +- av_freep(&alac->wasted_bits_buffer[chan]); ++ if ((ret = allocate_buffers(alac)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n"); ++ return ret; + } + ++ avcodec_get_frame_defaults(&alac->frame); ++ avctx->coded_frame = &alac->frame; ++ + return 0; + } + + AVCodec ff_alac_decoder = { +- "alac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ALAC, +- sizeof(ALACContext), +- alac_decode_init, +- NULL, +- alac_decode_close, +- alac_decode_frame, ++ .name = "alac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ALAC, ++ .priv_data_size = sizeof(ALACContext), ++ .init = alac_decode_init, ++ .close = alac_decode_close, ++ .decode = alac_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alacenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alacenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alacenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alacenc.c 2012-05-14 14:08:53.369320560 +0200 +@@ -75,20 +75,22 @@ + } AlacEncodeContext; + + +-static void init_sample_buffers(AlacEncodeContext *s, const int16_t *input_samples) ++static void init_sample_buffers(AlacEncodeContext *s, ++ const int16_t *input_samples) + { + int ch, i; + +- for(ch=0;chavctx->channels;ch++) { ++ for (ch = 0; ch < s->avctx->channels; ch++) { + const int16_t *sptr = input_samples + ch; +- for(i=0;iavctx->frame_size;i++) { ++ for (i = 0; i < s->avctx->frame_size; i++) { + s->sample_buf[ch][i] = *sptr; + sptr += s->avctx->channels; + } + } + } + +-static void encode_scalar(AlacEncodeContext *s, int x, int k, int write_sample_size) ++static void encode_scalar(AlacEncodeContext *s, int x, ++ int k, int write_sample_size) + { + int divisor, q, r; + +@@ -97,17 +99,17 @@ + q = x / divisor; + r = x % divisor; + +- if(q > 8) { ++ if (q > 8) { + // write escape code and sample value directly + put_bits(&s->pbctx, 9, ALAC_ESCAPE_CODE); + put_bits(&s->pbctx, write_sample_size, x); + } else { +- if(q) ++ if (q) + put_bits(&s->pbctx, q, (1<pbctx, 1, 0); + +- if(k != 1) { +- if(r > 0) ++ if (k != 1) { ++ if (r > 0) + put_bits(&s->pbctx, k, r+1); + else + put_bits(&s->pbctx, k-1, 0); +@@ -146,7 +148,7 @@ + s->min_prediction_order, + s->max_prediction_order, + ALAC_MAX_LPC_PRECISION, coefs, shift, +- AV_LPC_TYPE_LEVINSON, 0, ++ FF_LPC_TYPE_LEVINSON, 0, + ORDER_METHOD_EST, ALAC_MAX_LPC_SHIFT, 1); + + s->lpc[ch].lpc_order = opt_order; +@@ -164,7 +166,7 @@ + + /* calculate sum of 2nd order residual for each channel */ + sum[0] = sum[1] = sum[2] = sum[3] = 0; +- for(i=2; i> 1); +@@ -181,8 +183,8 @@ + + /* return mode with lowest score */ + best = 0; +- for(i=1; i<4; i++) { +- if(score[i] < score[best]) { ++ for (i = 1; i < 4; i++) { ++ if (score[i] < score[best]) { + best = i; + } + } +@@ -205,7 +207,7 @@ + break; + + case ALAC_CHMODE_LEFT_SIDE: +- for(i=0; iinterlacing_leftweight = 1; +@@ -213,7 +215,7 @@ + break; + + case ALAC_CHMODE_RIGHT_SIDE: +- for(i=0; i> 31); +@@ -223,7 +225,7 @@ + break; + + default: +- for(i=0; i> 1; + right[i] = tmp - right[i]; +@@ -239,10 +241,10 @@ + int i; + AlacLPCContext lpc = s->lpc[ch]; + +- if(lpc.lpc_order == 31) { ++ if (lpc.lpc_order == 31) { + s->predictor_buf[0] = s->sample_buf[ch][0]; + +- for(i=1; iavctx->frame_size; i++) ++ for (i = 1; i < s->avctx->frame_size; i++) + s->predictor_buf[i] = s->sample_buf[ch][i] - s->sample_buf[ch][i-1]; + + return; +@@ -250,17 +252,17 @@ + + // generalised linear predictor + +- if(lpc.lpc_order > 0) { ++ if (lpc.lpc_order > 0) { + int32_t *samples = s->sample_buf[ch]; + int32_t *residual = s->predictor_buf; + + // generate warm-up samples + residual[0] = samples[0]; +- for(i=1;i<=lpc.lpc_order;i++) ++ for (i = 1; i <= lpc.lpc_order; i++) + residual[i] = samples[i] - samples[i-1]; + + // perform lpc on remaining samples +- for(i = lpc.lpc_order + 1; i < s->avctx->frame_size; i++) { ++ for (i = lpc.lpc_order + 1; i < s->avctx->frame_size; i++) { + int sum = 1 << (lpc.lpc_quant - 1), res_val, j; + + for (j = 0; j < lpc.lpc_order; j++) { +@@ -303,7 +305,7 @@ + int sign_modifier = 0, i, k; + int32_t *samples = s->predictor_buf; + +- for(i=0;i < s->avctx->frame_size;) { ++ for (i = 0; i < s->avctx->frame_size;) { + int x; + + k = av_log2((history >> 9) + 3); +@@ -320,15 +322,15 @@ + - ((history * s->rc.history_mult) >> 9); + + sign_modifier = 0; +- if(x > 0xFFFF) ++ if (x > 0xFFFF) + history = 0xFFFF; + +- if((history < 128) && (i < s->avctx->frame_size)) { ++ if (history < 128 && i < s->avctx->frame_size) { + unsigned int block_size = 0; + + k = 7 - av_log2(history) + ((history + 16) >> 6); + +- while((*samples == 0) && (i < s->avctx->frame_size)) { ++ while (*samples == 0 && i < s->avctx->frame_size) { + samples++; + i++; + block_size++; +@@ -346,31 +348,40 @@ + static void write_compressed_frame(AlacEncodeContext *s) + { + int i, j; ++ int prediction_type = 0; + +- if(s->avctx->channels == 2) ++ if (s->avctx->channels == 2) + alac_stereo_decorrelation(s); + put_bits(&s->pbctx, 8, s->interlacing_shift); + put_bits(&s->pbctx, 8, s->interlacing_leftweight); + +- for(i=0;iavctx->channels;i++) { ++ for (i = 0; i < s->avctx->channels; i++) { + + calc_predictor_params(s, i); + +- put_bits(&s->pbctx, 4, 0); // prediction type : currently only type 0 has been RE'd ++ put_bits(&s->pbctx, 4, prediction_type); + put_bits(&s->pbctx, 4, s->lpc[i].lpc_quant); + + put_bits(&s->pbctx, 3, s->rc.rice_modifier); + put_bits(&s->pbctx, 5, s->lpc[i].lpc_order); + // predictor coeff. table +- for(j=0;jlpc[i].lpc_order;j++) { ++ for (j = 0; j < s->lpc[i].lpc_order; j++) { + put_sbits(&s->pbctx, 16, s->lpc[i].lpc_coeff[j]); + } + } + + // apply lpc and entropy coding to audio samples + +- for(i=0;iavctx->channels;i++) { ++ for (i = 0; i < s->avctx->channels; i++) { + alac_linear_predictor(s, i); ++ ++ // TODO: determine when this will actually help. for now it's not used. ++ if (prediction_type == 15) { ++ // 2nd pass 1st order filter ++ for (j = s->avctx->frame_size - 1; j > 0; j--) ++ s->predictor_buf[j] -= s->predictor_buf[j - 1]; ++ } ++ + alac_entropy_coder(s); + } + } +@@ -384,13 +395,21 @@ + avctx->frame_size = DEFAULT_FRAME_SIZE; + avctx->bits_per_coded_sample = DEFAULT_SAMPLE_SIZE; + +- if(avctx->sample_fmt != AV_SAMPLE_FMT_S16) { ++ if (avctx->sample_fmt != AV_SAMPLE_FMT_S16) { + av_log(avctx, AV_LOG_ERROR, "only pcm_s16 input samples are supported\n"); + return -1; + } + ++ /* TODO: Correctly implement multi-channel ALAC. ++ It is similar to multi-channel AAC, in that it has a series of ++ single-channel (SCE), channel-pair (CPE), and LFE elements. */ ++ if (avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "only mono or stereo input is currently supported\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ + // Set default compression level +- if(avctx->compression_level == FF_COMPRESSION_DEFAULT) ++ if (avctx->compression_level == FF_COMPRESSION_DEFAULT) + s->compression_level = 2; + else + s->compression_level = av_clip(avctx->compression_level, 0, 2); +@@ -411,21 +430,23 @@ + AV_WB8 (alac_extradata+17, avctx->bits_per_coded_sample); + AV_WB8 (alac_extradata+21, avctx->channels); + AV_WB32(alac_extradata+24, s->max_coded_frame_size); +- AV_WB32(alac_extradata+28, avctx->sample_rate*avctx->channels*avctx->bits_per_coded_sample); // average bitrate ++ AV_WB32(alac_extradata+28, ++ avctx->sample_rate * avctx->channels * avctx->bits_per_coded_sample); // average bitrate + AV_WB32(alac_extradata+32, avctx->sample_rate); + + // Set relevant extradata fields +- if(s->compression_level > 0) { ++ if (s->compression_level > 0) { + AV_WB8(alac_extradata+18, s->rc.history_mult); + AV_WB8(alac_extradata+19, s->rc.initial_history); + AV_WB8(alac_extradata+20, s->rc.k_modifier); + } + + s->min_prediction_order = DEFAULT_MIN_PRED_ORDER; +- if(avctx->min_prediction_order >= 0) { +- if(avctx->min_prediction_order < MIN_LPC_ORDER || ++ if (avctx->min_prediction_order >= 0) { ++ if (avctx->min_prediction_order < MIN_LPC_ORDER || + avctx->min_prediction_order > ALAC_MAX_LPC_ORDER) { +- av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", avctx->min_prediction_order); ++ av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", ++ avctx->min_prediction_order); + return -1; + } + +@@ -433,18 +454,20 @@ + } + + s->max_prediction_order = DEFAULT_MAX_PRED_ORDER; +- if(avctx->max_prediction_order >= 0) { +- if(avctx->max_prediction_order < MIN_LPC_ORDER || +- avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) { +- av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", avctx->max_prediction_order); ++ if (avctx->max_prediction_order >= 0) { ++ if (avctx->max_prediction_order < MIN_LPC_ORDER || ++ avctx->max_prediction_order > ALAC_MAX_LPC_ORDER) { ++ av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", ++ avctx->max_prediction_order); + return -1; + } + + s->max_prediction_order = avctx->max_prediction_order; + } + +- if(s->max_prediction_order < s->min_prediction_order) { +- av_log(avctx, AV_LOG_ERROR, "invalid prediction orders: min=%d max=%d\n", ++ if (s->max_prediction_order < s->min_prediction_order) { ++ av_log(avctx, AV_LOG_ERROR, ++ "invalid prediction orders: min=%d max=%d\n", + s->min_prediction_order, s->max_prediction_order); + return -1; + } +@@ -457,7 +480,7 @@ + + s->avctx = avctx; + ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size, s->max_prediction_order, +- AV_LPC_TYPE_LEVINSON); ++ FF_LPC_TYPE_LEVINSON); + + return ret; + } +@@ -469,12 +492,12 @@ + PutBitContext *pb = &s->pbctx; + int i, out_bytes, verbatim_flag = 0; + +- if(avctx->frame_size > DEFAULT_FRAME_SIZE) { ++ if (avctx->frame_size > DEFAULT_FRAME_SIZE) { + av_log(avctx, AV_LOG_ERROR, "input frame size exceeded\n"); + return -1; + } + +- if(buf_size < 2*s->max_coded_frame_size) { ++ if (buf_size < 2 * s->max_coded_frame_size) { + av_log(avctx, AV_LOG_ERROR, "buffer size is too small\n"); + return -1; + } +@@ -482,11 +505,11 @@ + verbatim: + init_put_bits(pb, frame, buf_size); + +- if((s->compression_level == 0) || verbatim_flag) { ++ if (s->compression_level == 0 || verbatim_flag) { + // Verbatim mode + const int16_t *samples = data; + write_frame_header(s, 1); +- for(i=0; iframe_size*avctx->channels; i++) { ++ for (i = 0; i < avctx->frame_size * avctx->channels; i++) { + put_sbits(pb, 16, *samples++); + } + } else { +@@ -499,9 +522,9 @@ + flush_put_bits(pb); + out_bytes = put_bits_count(pb) >> 3; + +- if(out_bytes > s->max_coded_frame_size) { ++ if (out_bytes > s->max_coded_frame_size) { + /* frame too large. use verbatim mode */ +- if(verbatim_flag || (s->compression_level == 0)) { ++ if (verbatim_flag || s->compression_level == 0) { + /* still too large. must be an error. */ + av_log(avctx, AV_LOG_ERROR, "error encoding frame\n"); + return -1; +@@ -524,14 +547,15 @@ + } + + AVCodec ff_alac_encoder = { +- "alac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ALAC, +- sizeof(AlacEncodeContext), +- alac_encode_init, +- alac_encode_frame, +- alac_encode_close, ++ .name = "alac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ALAC, ++ .priv_data_size = sizeof(AlacEncodeContext), ++ .init = alac_encode_init, ++ .encode = alac_encode_frame, ++ .close = alac_encode_close, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME, +- .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE}, ++ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c 2012-05-14 14:08:53.370320581 +0200 +@@ -57,8 +57,11 @@ + REGISTER_HWACCEL (H263_VAAPI, h263_vaapi); + REGISTER_HWACCEL (H264_DXVA2, h264_dxva2); + REGISTER_HWACCEL (H264_VAAPI, h264_vaapi); ++ REGISTER_HWACCEL (H264_VDA, h264_vda); ++ REGISTER_HWACCEL (MPEG1_VDPAU, mpeg1_vdpau); + REGISTER_HWACCEL (MPEG2_DXVA2, mpeg2_dxva2); + REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi); ++ REGISTER_HWACCEL (MPEG2_VDPAU, mpeg2_vdpau); + REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi); + REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2); + REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi); +@@ -69,30 +72,35 @@ + REGISTER_ENCODER (A64MULTI, a64multi); + REGISTER_ENCODER (A64MULTI5, a64multi5); + REGISTER_DECODER (AASC, aasc); +- REGISTER_DECODER (AMV, amv); ++ REGISTER_ENCDEC (AMV, amv); + REGISTER_DECODER (ANM, anm); + REGISTER_DECODER (ANSI, ansi); + REGISTER_ENCDEC (ASV1, asv1); + REGISTER_ENCDEC (ASV2, asv2); + REGISTER_DECODER (AURA, aura); + REGISTER_DECODER (AURA2, aura2); ++ REGISTER_ENCDEC (AVRP, avrp); + REGISTER_DECODER (AVS, avs); + REGISTER_DECODER (BETHSOFTVID, bethsoftvid); + REGISTER_DECODER (BFI, bfi); + REGISTER_DECODER (BINK, bink); + REGISTER_ENCDEC (BMP, bmp); ++ REGISTER_DECODER (BMV_VIDEO, bmv_video); + REGISTER_DECODER (C93, c93); + REGISTER_DECODER (CAVS, cavs); + REGISTER_DECODER (CDGRAPHICS, cdgraphics); + REGISTER_DECODER (CINEPAK, cinepak); +- REGISTER_DECODER (CLJR, cljr); ++ REGISTER_ENCDEC (CLJR, cljr); + REGISTER_DECODER (CSCD, cscd); + REGISTER_DECODER (CYUV, cyuv); ++ REGISTER_DECODER (DFA, dfa); ++ REGISTER_DECODER (DIRAC, dirac); + REGISTER_ENCDEC (DNXHD, dnxhd); +- REGISTER_DECODER (DPX, dpx); ++ REGISTER_ENCDEC (DPX, dpx); + REGISTER_DECODER (DSICINVIDEO, dsicinvideo); + REGISTER_ENCDEC (DVVIDEO, dvvideo); + REGISTER_DECODER (DXA, dxa); ++ REGISTER_DECODER (DXTORY, dxtory); + REGISTER_DECODER (EACMV, eacmv); + REGISTER_DECODER (EAMAD, eamad); + REGISTER_DECODER (EATGQ, eatgq); +@@ -102,9 +110,11 @@ + REGISTER_DECODER (EIGHTSVX_EXP, eightsvx_exp); + REGISTER_DECODER (EIGHTSVX_FIB, eightsvx_fib); + REGISTER_DECODER (ESCAPE124, escape124); ++ REGISTER_DECODER (ESCAPE130, escape130); + REGISTER_ENCDEC (FFV1, ffv1); + REGISTER_ENCDEC (FFVHUFF, ffvhuff); + REGISTER_ENCDEC (FLASHSV, flashsv); ++ REGISTER_ENCDEC (FLASHSV2, flashsv2); + REGISTER_DECODER (FLIC, flic); + REGISTER_ENCDEC (FLV, flv); + REGISTER_DECODER (FOURXM, fourxm); +@@ -116,6 +126,7 @@ + REGISTER_DECODER (H263I, h263i); + REGISTER_ENCODER (H263P, h263p); + REGISTER_DECODER (H264, h264); ++ REGISTER_DECODER (H264_CRYSTALHD, h264_crystalhd); + REGISTER_DECODER (H264_VDPAU, h264_vdpau); + REGISTER_ENCDEC (HUFFYUV, huffyuv); + REGISTER_DECODER (IDCIN, idcin); +@@ -123,9 +134,12 @@ + REGISTER_DECODER (IFF_ILBM, iff_ilbm); + REGISTER_DECODER (INDEO2, indeo2); + REGISTER_DECODER (INDEO3, indeo3); ++ REGISTER_DECODER (INDEO4, indeo4); + REGISTER_DECODER (INDEO5, indeo5); + REGISTER_DECODER (INTERPLAY_VIDEO, interplay_video); ++ REGISTER_ENCDEC (JPEG2000, jpeg2000); + REGISTER_ENCDEC (JPEGLS, jpegls); ++ REGISTER_DECODER (JV, jv); + REGISTER_DECODER (KGV1, kgv1); + REGISTER_DECODER (KMVC, kmvc); + REGISTER_DECODER (LAGARITH, lagarith); +@@ -141,16 +155,20 @@ + REGISTER_ENCDEC (MPEG1VIDEO, mpeg1video); + REGISTER_ENCDEC (MPEG2VIDEO, mpeg2video); + REGISTER_ENCDEC (MPEG4, mpeg4); ++ REGISTER_DECODER (MPEG4_CRYSTALHD, mpeg4_crystalhd); + REGISTER_DECODER (MPEG4_VDPAU, mpeg4_vdpau); + REGISTER_DECODER (MPEGVIDEO, mpegvideo); + REGISTER_DECODER (MPEG_VDPAU, mpeg_vdpau); + REGISTER_DECODER (MPEG1_VDPAU, mpeg1_vdpau); +- REGISTER_ENCDEC (MSMPEG4V1, msmpeg4v1); ++ REGISTER_DECODER (MPEG2_CRYSTALHD, mpeg2_crystalhd); ++ REGISTER_DECODER (MSMPEG4_CRYSTALHD, msmpeg4_crystalhd); ++ REGISTER_DECODER (MSMPEG4V1, msmpeg4v1); + REGISTER_ENCDEC (MSMPEG4V2, msmpeg4v2); + REGISTER_ENCDEC (MSMPEG4V3, msmpeg4v3); + REGISTER_DECODER (MSRLE, msrle); +- REGISTER_DECODER (MSVIDEO1, msvideo1); ++ REGISTER_ENCDEC (MSVIDEO1, msvideo1); + REGISTER_DECODER (MSZH, mszh); ++ REGISTER_DECODER (MXPEG, mxpeg); + REGISTER_DECODER (NUV, nuv); + REGISTER_ENCDEC (PAM, pam); + REGISTER_ENCDEC (PBM, pbm); +@@ -160,12 +178,14 @@ + REGISTER_DECODER (PICTOR, pictor); + REGISTER_ENCDEC (PNG, png); + REGISTER_ENCDEC (PPM, ppm); ++ REGISTER_ENCDEC (PRORES, prores); ++ REGISTER_DECODER (PRORES_LGPL, prores_lgpl); + REGISTER_DECODER (PTX, ptx); + REGISTER_DECODER (QDRAW, qdraw); + REGISTER_DECODER (QPEG, qpeg); + REGISTER_ENCDEC (QTRLE, qtrle); +- REGISTER_DECODER (R10K, r10k); +- REGISTER_DECODER (R210, r210); ++ REGISTER_ENCDEC (R10K, r10k); ++ REGISTER_ENCDEC (R210, r210); + REGISTER_ENCDEC (RAWVIDEO, rawvideo); + REGISTER_DECODER (RL2, rl2); + REGISTER_ENCDEC (ROQ, roq); +@@ -174,6 +194,7 @@ + REGISTER_ENCDEC (RV20, rv20); + REGISTER_DECODER (RV30, rv30); + REGISTER_DECODER (RV40, rv40); ++ REGISTER_DECODER (S302M, s302m); + REGISTER_ENCDEC (SGI, sgi); + REGISTER_DECODER (SMACKER, smacker); + REGISTER_DECODER (SMC, smc); +@@ -193,11 +214,17 @@ + REGISTER_DECODER (TSCC, tscc); + REGISTER_DECODER (TXD, txd); + REGISTER_DECODER (ULTI, ulti); ++ REGISTER_DECODER (UTVIDEO, utvideo); + REGISTER_ENCDEC (V210, v210); + REGISTER_DECODER (V210X, v210x); ++ REGISTER_ENCDEC (V308, v308); ++ REGISTER_ENCDEC (V410, v410); + REGISTER_DECODER (VB, vb); ++ REGISTER_DECODER (VBLE, vble); + REGISTER_DECODER (VC1, vc1); ++ REGISTER_DECODER (VC1_CRYSTALHD, vc1_crystalhd); + REGISTER_DECODER (VC1_VDPAU, vc1_vdpau); ++ REGISTER_DECODER (VC1IMAGE, vc1image); + REGISTER_DECODER (VCR1, vcr1); + REGISTER_DECODER (VMDVIDEO, vmdvideo); + REGISTER_DECODER (VMNC, vmnc); +@@ -211,11 +238,17 @@ + REGISTER_ENCDEC (WMV1, wmv1); + REGISTER_ENCDEC (WMV2, wmv2); + REGISTER_DECODER (WMV3, wmv3); ++ REGISTER_DECODER (WMV3_CRYSTALHD, wmv3_crystalhd); + REGISTER_DECODER (WMV3_VDPAU, wmv3_vdpau); ++ REGISTER_DECODER (WMV3IMAGE, wmv3image); + REGISTER_DECODER (WNV1, wnv1); + REGISTER_DECODER (XAN_WC3, xan_wc3); ++ REGISTER_DECODER (XAN_WC4, xan_wc4); + REGISTER_DECODER (XL, xl); ++ REGISTER_ENCDEC (XWD, xwd); ++ REGISTER_ENCDEC (Y41P, y41p); + REGISTER_DECODER (YOP, yop); ++ REGISTER_ENCDEC (YUV4, yuv4); + REGISTER_ENCDEC (ZLIB, zlib); + REGISTER_ENCDEC (ZMBV, zmbv); + +@@ -233,11 +266,15 @@ + REGISTER_DECODER (ATRAC3, atrac3); + REGISTER_DECODER (BINKAUDIO_DCT, binkaudio_dct); + REGISTER_DECODER (BINKAUDIO_RDFT, binkaudio_rdft); ++ REGISTER_DECODER (BMV_AUDIO, bmv_audio); + REGISTER_DECODER (COOK, cook); +- REGISTER_DECODER (DCA, dca); ++ REGISTER_ENCDEC (DCA, dca); + REGISTER_DECODER (DSICINAUDIO, dsicinaudio); +- REGISTER_DECODER (EAC3, eac3); ++ REGISTER_ENCDEC (EAC3, eac3); ++ REGISTER_DECODER (FFWAVESYNTH, ffwavesynth); + REGISTER_ENCDEC (FLAC, flac); ++ REGISTER_ENCDEC (G723_1, g723_1); ++ REGISTER_DECODER (G729, g729); + REGISTER_DECODER (GSM, gsm); + REGISTER_DECODER (GSM_MS, gsm_ms); + REGISTER_DECODER (IMC, imc); +@@ -273,6 +310,7 @@ + REGISTER_DECODER (VMDAUDIO, vmdaudio); + REGISTER_ENCDEC (VORBIS, vorbis); + REGISTER_DECODER (WAVPACK, wavpack); ++ REGISTER_DECODER (WMALOSSLESS, wmalossless); + REGISTER_DECODER (WMAPRO, wmapro); + REGISTER_ENCDEC (WMAV1, wmav1); + REGISTER_ENCDEC (WMAV2, wmav2); +@@ -290,6 +328,7 @@ + REGISTER_DECODER (PCM_LXF, pcm_lxf); + REGISTER_ENCDEC (PCM_MULAW, pcm_mulaw); + REGISTER_ENCDEC (PCM_S8, pcm_s8); ++ REGISTER_DECODER (PCM_S8_PLANAR, pcm_s8_planar); + REGISTER_ENCDEC (PCM_S16BE, pcm_s16be); + REGISTER_ENCDEC (PCM_S16LE, pcm_s16le); + REGISTER_DECODER (PCM_S16LE_PLANAR, pcm_s16le_planar); +@@ -305,7 +344,7 @@ + REGISTER_ENCDEC (PCM_U24LE, pcm_u24le); + REGISTER_ENCDEC (PCM_U32BE, pcm_u32be); + REGISTER_ENCDEC (PCM_U32LE, pcm_u32le); +- REGISTER_ENCDEC (PCM_ZORK , pcm_zork); ++ REGISTER_DECODER (PCM_ZORK , pcm_zork); + + /* DPCM codecs */ + REGISTER_DECODER (INTERPLAY_DPCM, interplay_dpcm); +@@ -326,6 +365,7 @@ + REGISTER_ENCDEC (ADPCM_G722, adpcm_g722); + REGISTER_ENCDEC (ADPCM_G726, adpcm_g726); + REGISTER_DECODER (ADPCM_IMA_AMV, adpcm_ima_amv); ++ REGISTER_DECODER (ADPCM_IMA_APC, adpcm_ima_apc); + REGISTER_DECODER (ADPCM_IMA_DK3, adpcm_ima_dk3); + REGISTER_DECODER (ADPCM_IMA_DK4, adpcm_ima_dk4); + REGISTER_DECODER (ADPCM_IMA_EA_EACS, adpcm_ima_ea_eacs); +@@ -349,10 +389,12 @@ + REGISTER_ENCDEC (DVBSUB, dvbsub); + REGISTER_ENCDEC (DVDSUB, dvdsub); + REGISTER_DECODER (PGSSUB, pgssub); +- REGISTER_DECODER (SRT, srt); ++ REGISTER_ENCDEC (SRT, srt); + REGISTER_ENCDEC (XSUB, xsub); + + /* external libraries */ ++ REGISTER_ENCODER (LIBAACPLUS, libaacplus); ++ REGISTER_DECODER (LIBCELT, libcelt); + REGISTER_ENCDEC (LIBDIRAC, libdirac); + REGISTER_ENCODER (LIBFAAC, libfaac); + REGISTER_ENCDEC (LIBGSM, libgsm); +@@ -360,20 +402,31 @@ + REGISTER_ENCODER (LIBMP3LAME, libmp3lame); + REGISTER_ENCDEC (LIBOPENCORE_AMRNB, libopencore_amrnb); + REGISTER_DECODER (LIBOPENCORE_AMRWB, libopencore_amrwb); +- REGISTER_DECODER (LIBOPENJPEG, libopenjpeg); ++ REGISTER_ENCDEC (LIBOPENJPEG, libopenjpeg); + REGISTER_ENCDEC (LIBSCHROEDINGER, libschroedinger); +- REGISTER_DECODER (LIBSPEEX, libspeex); ++ REGISTER_ENCDEC (LIBSPEEX, libspeex); ++ REGISTER_DECODER (LIBSTAGEFRIGHT_H264, libstagefright_h264); + REGISTER_ENCODER (LIBTHEORA, libtheora); ++ REGISTER_DECODER (LIBUTVIDEO, libutvideo); ++ REGISTER_ENCODER (LIBVO_AACENC, libvo_aacenc); ++ REGISTER_ENCODER (LIBVO_AMRWBENC, libvo_amrwbenc); + REGISTER_ENCODER (LIBVORBIS, libvorbis); + REGISTER_ENCDEC (LIBVPX, libvpx); + REGISTER_ENCODER (LIBX264, libx264); ++ REGISTER_ENCODER (LIBX264RGB, libx264rgb); + REGISTER_ENCODER (LIBXAVS, libxavs); + REGISTER_ENCODER (LIBXVID, libxvid); + ++ /* text */ ++ REGISTER_DECODER (BINTEXT, bintext); ++ REGISTER_DECODER (XBIN, xbin); ++ REGISTER_DECODER (IDF, idf); ++ + /* parsers */ + REGISTER_PARSER (AAC, aac); + REGISTER_PARSER (AAC_LATM, aac_latm); + REGISTER_PARSER (AC3, ac3); ++ REGISTER_PARSER (ADX, adx); + REGISTER_PARSER (CAVSVIDEO, cavsvideo); + REGISTER_PARSER (DCA, dca); + REGISTER_PARSER (DIRAC, dirac); +@@ -381,6 +434,7 @@ + REGISTER_PARSER (DVBSUB, dvbsub); + REGISTER_PARSER (DVDSUB, dvdsub); + REGISTER_PARSER (FLAC, flac); ++ REGISTER_PARSER (GSM, gsm); + REGISTER_PARSER (H261, h261); + REGISTER_PARSER (H263, h263); + REGISTER_PARSER (H264, h264); +@@ -390,6 +444,8 @@ + REGISTER_PARSER (MPEGAUDIO, mpegaudio); + REGISTER_PARSER (MPEGVIDEO, mpegvideo); + REGISTER_PARSER (PNM, pnm); ++ REGISTER_PARSER (RV30, rv30); ++ REGISTER_PARSER (RV40, rv40); + REGISTER_PARSER (VC1, vc1); + REGISTER_PARSER (VP3, vp3); + REGISTER_PARSER (VP8, vp8); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alpha/dsputil_alpha.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alpha/dsputil_alpha.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alpha/dsputil_alpha.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alpha/dsputil_alpha.c 2012-05-14 14:08:53.371320601 +0200 +@@ -270,6 +270,9 @@ + + void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx) + { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = put_pixels16_axp_asm; + c->put_pixels_tab[0][1] = put_pixels16_x2_axp; + c->put_pixels_tab[0][2] = put_pixels16_y2_axp; +@@ -311,13 +314,15 @@ + c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels_xy2_axp; + + c->clear_blocks = clear_blocks_axp; ++ } + + /* amask clears all bits that correspond to present features. */ + if (amask(AMASK_MVI) == 0) { + c->put_pixels_clamped = put_pixels_clamped_mvi_asm; + c->add_pixels_clamped = add_pixels_clamped_mvi_asm; + +- c->get_pixels = get_pixels_mvi; ++ if (!high_bit_depth) ++ c->get_pixels = get_pixels_mvi; + c->diff_pixels = diff_pixels_mvi; + c->sad[0] = pix_abs16x16_mvi_asm; + c->sad[1] = pix_abs8x8_mvi; +@@ -331,7 +336,7 @@ + put_pixels_clamped_axp_p = c->put_pixels_clamped; + add_pixels_clamped_axp_p = c->add_pixels_clamped; + +- if (!avctx->lowres && ++ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 && + (avctx->idct_algo == FF_IDCT_AUTO || + avctx->idct_algo == FF_IDCT_SIMPLEALPHA)) { + c->idct_put = ff_simple_idct_put_axp; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alpha/simple_idct_alpha.c 2012-05-14 14:08:53.372320621 +0200 +@@ -33,20 +33,20 @@ + // cos(i * M_PI / 16) * sqrt(2) * (1 << 14) + // W4 is actually exactly 16384, but using 16383 works around + // accumulating rounding errors for some encoders +-#define W1 ((int_fast32_t) 22725) +-#define W2 ((int_fast32_t) 21407) +-#define W3 ((int_fast32_t) 19266) +-#define W4 ((int_fast32_t) 16383) +-#define W5 ((int_fast32_t) 12873) +-#define W6 ((int_fast32_t) 8867) +-#define W7 ((int_fast32_t) 4520) ++#define W1 22725 ++#define W2 21407 ++#define W3 19266 ++#define W4 16383 ++#define W5 12873 ++#define W6 8867 ++#define W7 4520 + #define ROW_SHIFT 11 + #define COL_SHIFT 20 + + /* 0: all entries 0, 1: only first entry nonzero, 2: otherwise */ + static inline int idct_row(DCTELEM *row) + { +- int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3, t; ++ int a0, a1, a2, a3, b0, b1, b2, b3, t; + uint64_t l, r, t2; + l = ldq(row); + r = ldq(row + 4); +@@ -154,7 +154,7 @@ + + static inline void idct_col(DCTELEM *col) + { +- int_fast32_t a0, a1, a2, a3, b0, b1, b2, b3; ++ int a0, a1, a2, a3, b0, b1, b2, b3; + + col[0] += (1 << (COL_SHIFT - 1)) / W4; + +@@ -235,7 +235,7 @@ + uint64_t l, r; + + for (i = 0; i < 8; ++i) { +- int_fast32_t a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4; ++ int a0 = col[i] + (1 << (COL_SHIFT - 1)) / W4; + + a0 *= W4; + col[i] = a0 >> COL_SHIFT; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alsdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alsdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/alsdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/alsdec.c 2012-05-14 14:08:53.374320661 +0200 +@@ -36,7 +36,7 @@ + #include "bytestream.h" + #include "bgmc.h" + #include "dsputil.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/samplefmt.h" + #include "libavutil/crc.h" + + #include +@@ -191,6 +191,7 @@ + + typedef struct { + AVCodecContext *avctx; ++ AVFrame frame; + ALSSpecificConfig sconf; + GetBitContext gb; + DSPContext dsp; +@@ -289,8 +290,8 @@ + + init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); + +- config_offset = ff_mpeg4audio_get_config(&m4ac, avctx->extradata, +- avctx->extradata_size); ++ config_offset = avpriv_mpeg4audio_get_config(&m4ac, avctx->extradata, ++ avctx->extradata_size * 8, 1); + + if (config_offset < 0) + return -1; +@@ -393,7 +394,7 @@ + if (get_bits_left(&gb) < 32) + return -1; + +- if (avctx->error_recognition >= FF_ER_CAREFUL) { ++ if (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL)) { + ctx->crc_table = av_crc_get_table(AV_CRC_32_IEEE_LE); + ctx->crc = 0xFFFFFFFF; + ctx->crc_org = ~get_bits_long(&gb, 32); +@@ -1011,7 +1012,7 @@ + unsigned int count = 0; + + while (b < b_max) +- count += div_blocks[b]; ++ count += div_blocks[b++]; + + if (count) + memset(buf, 0, sizeof(*buf) * count); +@@ -1415,15 +1416,14 @@ + + /** Decode an ALS frame. + */ +-static int decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, ++static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, + AVPacket *avpkt) + { + ALSDecContext *ctx = avctx->priv_data; + ALSSpecificConfig *sconf = &ctx->sconf; + const uint8_t *buffer = avpkt->data; + int buffer_size = avpkt->size; +- int invalid_frame, size; ++ int invalid_frame, ret; + unsigned int c, sample, ra_frame, bytes_read, shift; + + init_get_bits(&ctx->gb, buffer, buffer_size * 8); +@@ -1442,27 +1442,23 @@ + ctx->cur_frame_length = sconf->frame_length; + + // decode the frame data +- if ((invalid_frame = read_frame_data(ctx, ra_frame) < 0)) ++ if ((invalid_frame = read_frame_data(ctx, ra_frame)) < 0) + av_log(ctx->avctx, AV_LOG_WARNING, + "Reading frame data failed. Skipping RA unit.\n"); + + ctx->frame_id++; + +- // check for size of decoded data +- size = ctx->cur_frame_length * avctx->channels * +- (av_get_bits_per_sample_fmt(avctx->sample_fmt) >> 3); +- +- if (size > *data_size) { +- av_log(avctx, AV_LOG_ERROR, "Decoded data exceeds buffer size.\n"); +- return -1; ++ /* get output buffer */ ++ ctx->frame.nb_samples = ctx->cur_frame_length; ++ if ((ret = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } + +- *data_size = size; +- + // transform decoded frame into output format + #define INTERLEAVE_OUTPUT(bps) \ + { \ +- int##bps##_t *dest = (int##bps##_t*) data; \ ++ int##bps##_t *dest = (int##bps##_t*)ctx->frame.data[0]; \ + shift = bps - ctx->avctx->bits_per_raw_sample; \ + for (sample = 0; sample < ctx->cur_frame_length; sample++) \ + for (c = 0; c < avctx->channels; c++) \ +@@ -1476,11 +1472,11 @@ + } + + // update CRC +- if (sconf->crc_enabled && avctx->error_recognition >= FF_ER_CAREFUL) { ++ if (sconf->crc_enabled && (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) { + int swap = HAVE_BIGENDIAN != sconf->msb_first; + + if (ctx->avctx->bits_per_raw_sample == 24) { +- int32_t *src = data; ++ int32_t *src = (int32_t *)ctx->frame.data[0]; + + for (sample = 0; + sample < ctx->cur_frame_length * avctx->channels; +@@ -1501,22 +1497,25 @@ + + if (swap) { + if (ctx->avctx->bits_per_raw_sample <= 16) { +- int16_t *src = (int16_t*) data; ++ int16_t *src = (int16_t*) ctx->frame.data[0]; + int16_t *dest = (int16_t*) ctx->crc_buffer; + for (sample = 0; + sample < ctx->cur_frame_length * avctx->channels; + sample++) + *dest++ = av_bswap16(src[sample]); + } else { +- ctx->dsp.bswap_buf((uint32_t*)ctx->crc_buffer, data, ++ ctx->dsp.bswap_buf((uint32_t*)ctx->crc_buffer, ++ (uint32_t *)ctx->frame.data[0], + ctx->cur_frame_length * avctx->channels); + } + crc_source = ctx->crc_buffer; + } else { +- crc_source = data; ++ crc_source = ctx->frame.data[0]; + } + +- ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source, size); ++ ctx->crc = av_crc(ctx->crc_table, ctx->crc, crc_source, ++ ctx->cur_frame_length * avctx->channels * ++ av_get_bytes_per_sample(avctx->sample_fmt)); + } + + +@@ -1527,6 +1526,9 @@ + } + } + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ctx->frame; ++ + + bytes_read = invalid_frame ? buffer_size : + (get_bits_count(&ctx->gb) + 7) >> 3; +@@ -1710,11 +1712,11 @@ + + // allocate crc buffer + if (HAVE_BIGENDIAN != sconf->msb_first && sconf->crc_enabled && +- avctx->error_recognition >= FF_ER_CAREFUL) { ++ (avctx->err_recognition & (AV_EF_CRCCHECK|AV_EF_CAREFUL))) { + ctx->crc_buffer = av_malloc(sizeof(*ctx->crc_buffer) * + ctx->cur_frame_length * + avctx->channels * +- (av_get_bits_per_sample_fmt(avctx->sample_fmt) >> 3)); ++ av_get_bytes_per_sample(avctx->sample_fmt)); + if (!ctx->crc_buffer) { + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + decode_end(avctx); +@@ -1724,6 +1726,9 @@ + + dsputil_init(&ctx->dsp, avctx); + ++ avcodec_get_frame_defaults(&ctx->frame); ++ avctx->coded_frame = &ctx->frame; ++ + return 0; + } + +@@ -1739,16 +1744,15 @@ + + + AVCodec ff_als_decoder = { +- "als", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP4ALS, +- sizeof(ALSDecContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, ++ .name = "als", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP4ALS, ++ .priv_data_size = sizeof(ALSDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, + .flush = flush, +- .capabilities = CODEC_CAP_SUBFRAMES, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Audio Lossless Coding (ALS)"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrnbdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrnbdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrnbdata.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrnbdata.h 2012-05-14 14:08:53.377320721 +0200 +@@ -1655,10 +1655,10 @@ + 0.016998, 0.023804, -0.041779, 0.025696, 0.019989, + }; + +-static const float *ir_filters_lookup[2] = { ++static const float * const ir_filters_lookup[2] = { + ir_filter_strong, ir_filter_medium + }; +-static const float *ir_filters_lookup_MODE_7k95[2] = { ++static const float * const ir_filters_lookup_MODE_7k95[2] = { + ir_filter_strong_MODE_7k95, ir_filter_medium + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrnbdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrnbdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrnbdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrnbdec.c 2012-05-14 14:08:53.378320741 +0200 +@@ -95,6 +95,7 @@ + #define AMR_AGC_ALPHA 0.9 + + typedef struct AMRContext { ++ AVFrame avframe; ///< AVFrame for decoded samples + AMRNBFrame frame; ///< decoded AMR parameters (lsf coefficients, codebook indexes, etc) + uint8_t bad_frame_indicator; ///< bad frame ? 1 : 0 + enum Mode cur_frame_mode; +@@ -167,6 +168,9 @@ + for (i = 0; i < 4; i++) + p->prediction_error[i] = MIN_ENERGY; + ++ avcodec_get_frame_defaults(&p->avframe); ++ avctx->coded_frame = &p->avframe; ++ + return 0; + } + +@@ -196,6 +200,10 @@ + p->bad_frame_indicator = !get_bits1(&gb); // quality bit + skip_bits(&gb, 2); // two padding bits + ++ if (mode >= N_MODES || buf_size < frame_sizes_nb[mode] + 1) { ++ return NO_DATA; ++ } ++ + if (mode < MODE_DTX) + ff_amr_bit_reorder((uint16_t *) &p->frame, sizeof(AMRNBFrame), buf + 1, + amr_unpacking_bitmaps_per_mode[mode]); +@@ -204,7 +212,7 @@ + } + + +-/// @defgroup amr_lpc_decoding AMR pitch LPC coefficient decoding functions ++/// @name AMR pitch LPC coefficient decoding functions + /// @{ + + /** +@@ -255,7 +263,7 @@ + } + + if (update) +- memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(float)); ++ memcpy(p->prev_lsf_r, lsf_r, LP_FILTER_ORDER * sizeof(*lsf_r)); + + for (i = 0; i < LP_FILTER_ORDER; i++) + lsf_q[i] = lsf_r[i] * (LSF_R_FAC / 8000.0) + lsf_no_r[i] * (1.0 / 8000.0); +@@ -341,7 +349,7 @@ + /// @} + + +-/// @defgroup amr_pitch_vector_decoding AMR pitch vector decoding functions ++/// @name AMR pitch vector decoding functions + /// @{ + + /** +@@ -403,7 +411,7 @@ + /// @} + + +-/// @defgroup amr_algebraic_code_book AMR algebraic code book (fixed) vector decoding functions ++/// @name AMR algebraic code book (fixed) vector decoding functions + /// @{ + + /** +@@ -547,7 +555,7 @@ + /// @} + + +-/// @defgroup amr_gain_decoding AMR gain decoding functions ++/// @name AMR gain decoding functions + /// @{ + + /** +@@ -633,7 +641,7 @@ + /// @} + + +-/// @defgroup amr_pre_processing AMR pre-processing functions ++/// @name AMR preprocessing functions + /// @{ + + /** +@@ -649,7 +657,7 @@ + static void apply_ir_filter(float *out, const AMRFixed *in, + const float *filter) + { +- float filter1[AMR_SUBFRAME_SIZE], //!< filters at pitch lag*1 and *2 ++ float filter1[AMR_SUBFRAME_SIZE], ///< filters at pitch lag*1 and *2 + filter2[AMR_SUBFRAME_SIZE]; + int lag = in->pitch_lag; + float fac = in->pitch_fac; +@@ -751,7 +759,7 @@ + /// @} + + +-/// @defgroup amr_synthesis AMR synthesis functions ++/// @name AMR synthesis functions + /// @{ + + /** +@@ -812,7 +820,7 @@ + /// @} + + +-/// @defgroup amr_update AMR update functions ++/// @name AMR update functions + /// @{ + + /** +@@ -837,7 +845,7 @@ + /// @} + + +-/// @defgroup amr_postproc AMR Post processing functions ++/// @name AMR Postprocessing functions + /// @{ + + /** +@@ -919,24 +927,37 @@ + + /// @} + +-static int amrnb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, +- AVPacket *avpkt) ++static int amrnb_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + + AMRContext *p = avctx->priv_data; // pointer to private data + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- float *buf_out = data; // pointer to the output data buffer +- int i, subframe; ++ float *buf_out; // pointer to the output data buffer ++ int i, subframe, ret; + float fixed_gain_factor; + AMRFixed fixed_sparse = {0}; // fixed vector up to anti-sparseness processing + float spare_vector[AMR_SUBFRAME_SIZE]; // extra stack space to hold result from anti-sparseness processing + float synth_fixed_gain; // the fixed gain that synthesis should use + const float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use + ++ /* get output buffer */ ++ p->avframe.nb_samples = AMR_BLOCK_SIZE; ++ if ((ret = avctx->get_buffer(avctx, &p->avframe)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ buf_out = (float *)p->avframe.data[0]; ++ + p->cur_frame_mode = unpack_bitstream(p, buf, buf_size); ++ if (p->cur_frame_mode == NO_DATA) { ++ av_log(avctx, AV_LOG_ERROR, "Corrupt bitstream\n"); ++ return AVERROR_INVALIDDATA; ++ } + if (p->cur_frame_mode == MODE_DTX) { +- av_log_missing_feature(avctx, "dtx mode", 1); ++ av_log_missing_feature(avctx, "dtx mode", 0); ++ av_log(avctx, AV_LOG_INFO, "Note: libopencore_amrnb supports dtx\n"); + return -1; + } + +@@ -965,6 +986,10 @@ + + pitch_sharpening(p, subframe, p->cur_frame_mode, &fixed_sparse); + ++ if (fixed_sparse.pitch_lag == 0) { ++ av_log(avctx, AV_LOG_ERROR, "The file is corrupted, pitch_lag = 0 is not allowed\n"); ++ return AVERROR_INVALIDDATA; ++ } + ff_set_fixed_vector(p->fixed_vector, &fixed_sparse, 1.0, + AMR_SUBFRAME_SIZE); + +@@ -1028,8 +1053,8 @@ + ff_weighted_vector_sumf(p->lsf_avg, p->lsf_avg, p->lsf_q[3], + 0.84, 0.16, LP_FILTER_ORDER); + +- /* report how many samples we got */ +- *data_size = AMR_BLOCK_SIZE * sizeof(float); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = p->avframe; + + /* return the amount of bytes consumed if everything was OK */ + return frame_sizes_nb[p->cur_frame_mode] + 1; // +7 for rounding and +8 for TOC +@@ -1043,6 +1068,7 @@ + .priv_data_size = sizeof(AMRContext), + .init = amrnb_decode_init, + .decode = amrnb_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate NarrowBand"), +- .sample_fmts = (enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrwbdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrwbdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrwbdata.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrwbdata.h 2012-05-14 14:08:53.380320781 +0200 +@@ -1805,7 +1805,7 @@ + -7.501221e-02, 2.920532e-02, 1.660156e-02, 7.751465e-02 + }; + +-static const float *ir_filters_lookup[2] = { ++static const float * const ir_filters_lookup[2] = { + ir_filter_str, ir_filter_mid + }; + +@@ -1887,4 +1887,4 @@ + 40 /// SID/comfort noise frame + }; + +-#endif ++#endif /* AVCODEC_AMRWBDATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrwbdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrwbdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/amrwbdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/amrwbdec.c 2012-05-14 14:08:53.383320841 +0200 +@@ -41,6 +41,7 @@ + #include "amrwbdata.h" + + typedef struct { ++ AVFrame avframe; ///< AVFrame for decoded samples + AMRWBFrame frame; ///< AMRWB parameters decoded from bitstream + enum Mode fr_cur_mode; ///< mode index of current frame + uint8_t fr_quality; ///< frame quality index (FQI) +@@ -89,7 +90,7 @@ + AMRWBContext *ctx = avctx->priv_data; + int i; + +- avctx->sample_fmt = SAMPLE_FMT_FLT; ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + + av_lfg_init(&ctx->prng, 1); + +@@ -102,12 +103,15 @@ + for (i = 0; i < 4; i++) + ctx->prediction_error[i] = MIN_ENERGY; + ++ avcodec_get_frame_defaults(&ctx->avframe); ++ avctx->coded_frame = &ctx->avframe; ++ + return 0; + } + + /** + * Decode the frame header in the "MIME/storage" format. This format +- * is simpler and does not carry the auxiliary information of the frame ++ * is simpler and does not carry the auxiliary frame information. + * + * @param[in] ctx The Context + * @param[in] buf Pointer to the input buffer +@@ -129,7 +133,7 @@ + } + + /** +- * Decodes quantized ISF vectors using 36-bit indexes (6K60 mode only) ++ * Decode quantized ISF vectors using 36-bit indexes (6K60 mode only). + * + * @param[in] ind Array of 5 indexes + * @param[out] isf_q Buffer for isf_q[LP_ORDER] +@@ -156,7 +160,7 @@ + } + + /** +- * Decodes quantized ISF vectors using 46-bit indexes (except 6K60 mode) ++ * Decode quantized ISF vectors using 46-bit indexes (except 6K60 mode). + * + * @param[in] ind Array of 7 indexes + * @param[out] isf_q Buffer for isf_q[LP_ORDER] +@@ -189,8 +193,8 @@ + } + + /** +- * Apply mean and past ISF values using the prediction factor +- * Updates past ISF vector ++ * Apply mean and past ISF values using the prediction factor. ++ * Updates past ISF vector. + * + * @param[in,out] isf_q Current quantized ISF + * @param[in,out] isf_past Past quantized ISF +@@ -211,7 +215,7 @@ + + /** + * Interpolate the fourth ISP vector from current and past frames +- * to obtain a ISP vector for each subframe ++ * to obtain an ISP vector for each subframe. + * + * @param[in,out] isp_q ISPs for each subframe + * @param[in] isp4_past Past ISP for subframe 4 +@@ -228,9 +232,9 @@ + } + + /** +- * Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes) +- * Calculate integer lag and fractional lag always using 1/4 resolution +- * In 1st and 3rd subframes the index is relative to last subframe integer lag ++ * Decode an adaptive codebook index into pitch lag (except 6k60, 8k85 modes). ++ * Calculate integer lag and fractional lag always using 1/4 resolution. ++ * In 1st and 3rd subframes the index is relative to last subframe integer lag. + * + * @param[out] lag_int Decoded integer pitch lag + * @param[out] lag_frac Decoded fractional pitch lag +@@ -267,9 +271,9 @@ + } + + /** +- * Decode a adaptive codebook index into pitch lag for 8k85 and 6k60 modes +- * Description is analogous to decode_pitch_lag_high, but in 6k60 relative +- * index is used for all subframes except the first ++ * Decode an adaptive codebook index into pitch lag for 8k85 and 6k60 modes. ++ * The description is analogous to decode_pitch_lag_high, but in 6k60 the ++ * relative index is used for all subframes except the first. + */ + static void decode_pitch_lag_low(int *lag_int, int *lag_frac, int pitch_index, + uint8_t *base_lag_int, int subframe, enum Mode mode) +@@ -294,7 +298,7 @@ + + /** + * Find the pitch vector by interpolating the past excitation at the +- * pitch delay, which is obtained in this function ++ * pitch delay, which is obtained in this function. + * + * @param[in,out] ctx The context + * @param[in] amr_subframe Current subframe data +@@ -347,10 +351,10 @@ + /** + * The next six functions decode_[i]p_track decode exactly i pulses + * positions and amplitudes (-1 or 1) in a subframe track using +- * an encoded pulse indexing (TS 26.190 section 5.8.2) ++ * an encoded pulse indexing (TS 26.190 section 5.8.2). + * + * The results are given in out[], in which a negative number means +- * amplitude -1 and vice versa (i.e., ampl(x) = x / abs(x) ) ++ * amplitude -1 and vice versa (i.e., ampl(x) = x / abs(x) ). + * + * @param[out] out Output buffer (writes i elements) + * @param[in] code Pulse index (no. of bits varies, see below) +@@ -466,7 +470,7 @@ + + /** + * Decode the algebraic codebook index to pulse positions and signs, +- * then construct the algebraic codebook vector ++ * then construct the algebraic codebook vector. + * + * @param[out] fixed_vector Buffer for the fixed codebook excitation + * @param[in] pulse_hi MSBs part of the pulse index array (higher modes only) +@@ -537,7 +541,7 @@ + } + + /** +- * Decode pitch gain and fixed gain correction factor ++ * Decode pitch gain and fixed gain correction factor. + * + * @param[in] vq_gain Vector-quantized index for gains + * @param[in] mode Mode of the current frame +@@ -555,7 +559,7 @@ + } + + /** +- * Apply pitch sharpening filters to the fixed codebook vector ++ * Apply pitch sharpening filters to the fixed codebook vector. + * + * @param[in] ctx The context + * @param[in,out] fixed_vector Fixed codebook excitation +@@ -576,7 +580,7 @@ + } + + /** +- * Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced) ++ * Calculate the voicing factor (-1.0 = unvoiced to 1.0 = voiced). + * + * @param[in] p_vector, f_vector Pitch and fixed excitation vectors + * @param[in] p_gain, f_gain Pitch and fixed gains +@@ -595,8 +599,8 @@ + } + + /** +- * Reduce fixed vector sparseness by smoothing with one of three IR filters +- * Also known as "adaptive phase dispersion" ++ * Reduce fixed vector sparseness by smoothing with one of three IR filters, ++ * also known as "adaptive phase dispersion". + * + * @param[in] ctx The context + * @param[in,out] fixed_vector Unfiltered fixed vector +@@ -666,7 +670,7 @@ + + /** + * Calculate a stability factor {teta} based on distance between +- * current and past isf. A value of 1 shows maximum signal stability ++ * current and past isf. A value of 1 shows maximum signal stability. + */ + static float stability_factor(const float *isf, const float *isf_past) + { +@@ -683,7 +687,7 @@ + + /** + * Apply a non-linear fixed gain smoothing in order to reduce +- * fluctuation in the energy of excitation ++ * fluctuation in the energy of excitation. + * + * @param[in] fixed_gain Unsmoothed fixed gain + * @param[in,out] prev_tr_gain Previous threshold gain (updated) +@@ -714,7 +718,7 @@ + } + + /** +- * Filter the fixed_vector to emphasize the higher frequencies ++ * Filter the fixed_vector to emphasize the higher frequencies. + * + * @param[in,out] fixed_vector Fixed codebook vector + * @param[in] voice_fac Frame voicing factor +@@ -738,7 +742,7 @@ + } + + /** +- * Conduct 16th order linear predictive coding synthesis from excitation ++ * Conduct 16th order linear predictive coding synthesis from excitation. + * + * @param[in] ctx Pointer to the AMRWBContext + * @param[in] lpc Pointer to the LPC coefficients +@@ -798,7 +802,7 @@ + + /** + * Upsample a signal by 5/4 ratio (from 12.8kHz to 16kHz) using +- * a FIR interpolation filter. Uses past data from before *in address ++ * a FIR interpolation filter. Uses past data from before *in address. + * + * @param[out] out Buffer for interpolated signal + * @param[in] in Current signal data (length 0.8*o_size) +@@ -828,7 +832,7 @@ + + /** + * Calculate the high-band gain based on encoded index (23k85 mode) or +- * on the low-band speech signal and the Voice Activity Detection flag ++ * on the low-band speech signal and the Voice Activity Detection flag. + * + * @param[in] ctx The context + * @param[in] synth LB speech synthesis at 12.8k +@@ -853,7 +857,7 @@ + + /** + * Generate the high-band excitation with the same energy from the lower +- * one and scaled by the given gain ++ * one and scaled by the given gain. + * + * @param[in] ctx The context + * @param[out] hb_exc Buffer for the excitation +@@ -876,7 +880,7 @@ + } + + /** +- * Calculate the auto-correlation for the ISF difference vector ++ * Calculate the auto-correlation for the ISF difference vector. + */ + static float auto_correlation(float *diff_isf, float mean, int lag) + { +@@ -892,12 +896,12 @@ + + /** + * Extrapolate a ISF vector to the 16kHz range (20th order LP) +- * used at mode 6k60 LP filter for the high frequency band ++ * used at mode 6k60 LP filter for the high frequency band. + * +- * @param[out] out Buffer for extrapolated isf +- * @param[in] isf Input isf vector ++ * @param[out] isf Buffer for extrapolated isf; contains LP_ORDER ++ * values on input + */ +-static void extrapolate_isf(float out[LP_ORDER_16k], float isf[LP_ORDER]) ++static void extrapolate_isf(float isf[LP_ORDER_16k]) + { + float diff_isf[LP_ORDER - 2], diff_mean; + float *diff_hi = diff_isf - LP_ORDER + 1; // diff array for extrapolated indexes +@@ -905,8 +909,7 @@ + float est, scale; + int i, i_max_corr; + +- memcpy(out, isf, (LP_ORDER - 1) * sizeof(float)); +- out[LP_ORDER_16k - 1] = isf[LP_ORDER - 1]; ++ isf[LP_ORDER_16k - 1] = isf[LP_ORDER - 1]; + + /* Calculate the difference vector */ + for (i = 0; i < LP_ORDER - 2; i++) +@@ -927,16 +930,16 @@ + i_max_corr++; + + for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) +- out[i] = isf[i - 1] + isf[i - 1 - i_max_corr] ++ isf[i] = isf[i - 1] + isf[i - 1 - i_max_corr] + - isf[i - 2 - i_max_corr]; + + /* Calculate an estimate for ISF(18) and scale ISF based on the error */ +- est = 7965 + (out[2] - out[3] - out[4]) / 6.0; +- scale = 0.5 * (FFMIN(est, 7600) - out[LP_ORDER - 2]) / +- (out[LP_ORDER_16k - 2] - out[LP_ORDER - 2]); ++ est = 7965 + (isf[2] - isf[3] - isf[4]) / 6.0; ++ scale = 0.5 * (FFMIN(est, 7600) - isf[LP_ORDER - 2]) / ++ (isf[LP_ORDER_16k - 2] - isf[LP_ORDER - 2]); + + for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) +- diff_hi[i] = scale * (out[i] - out[i - 1]); ++ diff_hi[i] = scale * (isf[i] - isf[i - 1]); + + /* Stability insurance */ + for (i = LP_ORDER; i < LP_ORDER_16k - 1; i++) +@@ -948,11 +951,11 @@ + } + + for (i = LP_ORDER - 1; i < LP_ORDER_16k - 1; i++) +- out[i] = out[i - 1] + diff_hi[i] * (1.0f / (1 << 15)); ++ isf[i] = isf[i - 1] + diff_hi[i] * (1.0f / (1 << 15)); + + /* Scale the ISF vector for 16000 Hz */ + for (i = 0; i < LP_ORDER_16k - 1; i++) +- out[i] *= 0.8; ++ isf[i] *= 0.8; + } + + /** +@@ -977,7 +980,7 @@ + + /** + * Conduct 20th order linear predictive coding synthesis for the high +- * frequency band excitation at 16kHz ++ * frequency band excitation at 16kHz. + * + * @param[in] ctx The context + * @param[in] subframe Current subframe index (0 to 3) +@@ -999,7 +1002,7 @@ + ff_weighted_vector_sumf(e_isf, isf_past, isf, isfp_inter[subframe], + 1.0 - isfp_inter[subframe], LP_ORDER); + +- extrapolate_isf(e_isf, e_isf); ++ extrapolate_isf(e_isf); + + e_isf[LP_ORDER_16k - 1] *= 2.0; + ff_acelp_lsf2lspd(e_isp, e_isf, LP_ORDER_16k); +@@ -1015,8 +1018,8 @@ + } + + /** +- * Apply to high-band samples a 15th order filter +- * The filter characteristic depends on the given coefficients ++ * Apply a 15th order filter to high-band samples. ++ * The filter characteristic depends on the given coefficients. + * + * @param[out] out Buffer for filtered output + * @param[in] fir_coef Filter coefficients +@@ -1044,7 +1047,7 @@ + } + + /** +- * Update context state before the next subframe ++ * Update context state before the next subframe. + */ + static void update_sub_state(AMRWBContext *ctx) + { +@@ -1062,15 +1065,15 @@ + LP_ORDER_16k * sizeof(float)); + } + +-static int amrwb_decode_frame(AVCodecContext *avctx, void *data, int *data_size, +- AVPacket *avpkt) ++static int amrwb_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + AMRWBContext *ctx = avctx->priv_data; + AMRWBFrame *cf = &ctx->frame; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + int expected_fr_size, header_size; +- float *buf_out = data; ++ float *buf_out; + float spare_vector[AMRWB_SFR_SIZE]; // extra stack space to hold result from anti-sparseness processing + float fixed_gain_factor; // fixed gain correction factor (gamma) + float *synth_fixed_vector; // pointer to the fixed vector that synthesis should use +@@ -1080,26 +1083,38 @@ + float hb_exc[AMRWB_SFR_SIZE_16k]; // excitation for the high frequency band + float hb_samples[AMRWB_SFR_SIZE_16k]; // filtered high-band samples from synthesis + float hb_gain; +- int sub, i; ++ int sub, i, ret; ++ ++ /* get output buffer */ ++ ctx->avframe.nb_samples = 4 * AMRWB_SFR_SIZE_16k; ++ if ((ret = avctx->get_buffer(avctx, &ctx->avframe)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ buf_out = (float *)ctx->avframe.data[0]; + + header_size = decode_mime_header(ctx, buf); ++ if (ctx->fr_cur_mode > MODE_SID) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid mode %d\n", ctx->fr_cur_mode); ++ return AVERROR_INVALIDDATA; ++ } + expected_fr_size = ((cf_sizes_wb[ctx->fr_cur_mode] + 7) >> 3) + 1; + + if (buf_size < expected_fr_size) { + av_log(avctx, AV_LOG_ERROR, + "Frame too small (%d bytes). Truncated file?\n", buf_size); +- *data_size = 0; +- return buf_size; ++ *got_frame_ptr = 0; ++ return AVERROR_INVALIDDATA; + } + + if (!ctx->fr_quality || ctx->fr_cur_mode > MODE_SID) + av_log(avctx, AV_LOG_ERROR, "Encountered a bad or corrupted frame\n"); + +- if (ctx->fr_cur_mode == MODE_SID) /* Comfort noise frame */ ++ if (ctx->fr_cur_mode == MODE_SID) { /* Comfort noise frame */ + av_log_missing_feature(avctx, "SID mode", 1); +- +- if (ctx->fr_cur_mode >= MODE_SID) + return -1; ++ } + + ff_amr_bit_reorder((uint16_t *) &ctx->frame, sizeof(AMRWBFrame), + buf + header_size, amr_bit_orderings_by_mode[ctx->fr_cur_mode]); +@@ -1219,19 +1234,20 @@ + memcpy(ctx->isp_sub4_past, ctx->isp[3], LP_ORDER * sizeof(ctx->isp[3][0])); + memcpy(ctx->isf_past_final, ctx->isf_cur, LP_ORDER * sizeof(float)); + +- /* report how many samples we got */ +- *data_size = 4 * AMRWB_SFR_SIZE_16k * sizeof(float); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ctx->avframe; + + return expected_fr_size; + } + + AVCodec ff_amrwb_decoder = { + .name = "amrwb", +- .type = CODEC_TYPE_AUDIO, ++ .type = AVMEDIA_TYPE_AUDIO, + .id = CODEC_ID_AMR_WB, + .priv_data_size = sizeof(AMRWBContext), + .init = amrwb_decode_init, + .decode = amrwb_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Adaptive Multi-Rate WideBand"), +- .sample_fmts = (enum AVSampleFormat[]){SAMPLE_FMT_FLT,SAMPLE_FMT_NONE}, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/anm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/anm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/anm.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/anm.c 2012-05-14 14:08:53.383320841 +0200 +@@ -29,6 +29,7 @@ + + typedef struct AnmContext { + AVFrame frame; ++ int palette[AVPALETTE_COUNT]; + int x; ///< x coordinate position + } AnmContext; + +@@ -43,15 +44,12 @@ + if (avctx->extradata_size != 16*8 + 4*256) + return -1; + +- s->frame.reference = 1; +- if (avctx->get_buffer(avctx, &s->frame) < 0) { +- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; +- } ++ avcodec_get_frame_defaults(&s->frame); ++ s->frame.reference = 3; + + buf = avctx->extradata + 16*8; + for (i = 0; i < 256; i++) +- ((uint32_t*)s->frame.data[1])[i] = bytestream_get_le32(&buf); ++ s->palette[i] = bytestream_get_le32(&buf); + + return 0; + } +@@ -81,6 +79,8 @@ + int striplen = FFMIN(count, remaining); + if (buf) { + striplen = FFMIN(striplen, buf_end - *buf); ++ if (*buf >= buf_end) ++ goto exhausted; + memcpy(*dst, *buf, striplen); + *buf += striplen; + } else if (pixel >= 0) +@@ -170,6 +170,8 @@ + } + } while (buf + 1 < buf_end); + ++ memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); ++ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + return buf_size; +@@ -184,14 +186,13 @@ + } + + AVCodec ff_anm_decoder = { +- "anm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ANM, +- sizeof(AnmContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "anm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ANM, ++ .priv_data_size = sizeof(AnmContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ansi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ansi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ansi.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ansi.c 2012-05-14 14:08:53.384320862 +0200 +@@ -81,6 +81,7 @@ + s->fg = DEFAULT_FG_COLOR; + s->bg = DEFAULT_BG_COLOR; + ++ avcodec_get_frame_defaults(&s->frame); + if (!avctx->width || !avctx->height) + avcodec_set_dimensions(avctx, 80<<3, 25<<4); + +@@ -153,7 +154,7 @@ + + /** + * Execute ANSI escape code +- * @param <0 error ++ * @return 0 on success, negative on error + */ + static int execute_code(AVCodecContext * avctx, int c) + { +@@ -226,7 +227,7 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + s->frame.palette_has_changed = 1; + memcpy(s->frame.data[1], ff_cga_palette, 16 * 4); + erase_screen(avctx); +@@ -323,7 +324,7 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + s->frame.palette_has_changed = 1; + memcpy(s->frame.data[1], ff_cga_palette, 16 * 4); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/apedec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/apedec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/apedec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/apedec.c 2012-05-14 14:08:53.387320922 +0200 +@@ -20,11 +20,13 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "dsputil.h" + #include "get_bits.h" + #include "bytestream.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/avassert.h" + + /** + * @file +@@ -127,6 +129,7 @@ + /** Decoder context */ + typedef struct APEContext { + AVCodecContext *avctx; ++ AVFrame frame; + DSPContext dsp; + int channels; + int samples; ///< samples left to decode in current frame +@@ -138,8 +141,6 @@ + + uint32_t CRC; ///< frame CRC + int frameflags; ///< frame flags +- int currentframeblocks; ///< samples (per channel) in current frame +- int blocksdecoded; ///< count of decoded samples in current frame + APEPredictor predictor; ///< predictor used for final reconstruction + + int32_t decoded0[BLOCKS_PER_LOOP]; ///< decoded data for the first channel +@@ -155,29 +156,40 @@ + uint8_t *data; ///< current frame data + uint8_t *data_end; ///< frame data end + const uint8_t *ptr; ///< current position in frame data +- const uint8_t *last_ptr; ///< position where last 4608-sample block ended + + int error; + } APEContext; + + // TODO: dsputilize + +-static av_cold int ape_decode_init(AVCodecContext * avctx) ++static av_cold int ape_decode_close(AVCodecContext *avctx) ++{ ++ APEContext *s = avctx->priv_data; ++ int i; ++ ++ for (i = 0; i < APE_FILTER_LEVELS; i++) ++ av_freep(&s->filterbuf[i]); ++ ++ av_freep(&s->data); ++ return 0; ++} ++ ++static av_cold int ape_decode_init(AVCodecContext *avctx) + { + APEContext *s = avctx->priv_data; + int i; + + if (avctx->extradata_size != 6) { + av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n"); +- return -1; ++ return AVERROR(EINVAL); + } + if (avctx->bits_per_coded_sample != 16) { + av_log(avctx, AV_LOG_ERROR, "Only 16-bit samples are supported\n"); +- return -1; ++ return AVERROR(EINVAL); + } + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Only mono and stereo is supported\n"); +- return -1; ++ return AVERROR(EINVAL); + } + s->avctx = avctx; + s->channels = avctx->channels; +@@ -185,38 +197,37 @@ + s->compression_level = AV_RL16(avctx->extradata + 2); + s->flags = AV_RL16(avctx->extradata + 4); + +- av_log(avctx, AV_LOG_DEBUG, "Compression Level: %d - Flags: %d\n", s->compression_level, s->flags); ++ av_log(avctx, AV_LOG_DEBUG, "Compression Level: %d - Flags: %d\n", ++ s->compression_level, s->flags); + if (s->compression_level % 1000 || s->compression_level > COMPRESSION_LEVEL_INSANE) { +- av_log(avctx, AV_LOG_ERROR, "Incorrect compression level %d\n", s->compression_level); +- return -1; ++ av_log(avctx, AV_LOG_ERROR, "Incorrect compression level %d\n", ++ s->compression_level); ++ return AVERROR_INVALIDDATA; + } + s->fset = s->compression_level / 1000 - 1; + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[s->fset][i]) + break; +- s->filterbuf[i] = av_malloc((ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4); ++ FF_ALLOC_OR_GOTO(avctx, s->filterbuf[i], ++ (ape_filter_orders[s->fset][i] * 3 + HISTORY_SIZE) * 4, ++ filter_alloc_fail); + } + + dsputil_init(&s->dsp, avctx); + avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; +- return 0; +-} +- +-static av_cold int ape_decode_close(AVCodecContext * avctx) +-{ +- APEContext *s = avctx->priv_data; +- int i; ++ avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + +- for (i = 0; i < APE_FILTER_LEVELS; i++) +- av_freep(&s->filterbuf[i]); ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; + +- av_freep(&s->data); + return 0; ++filter_alloc_fail: ++ ape_decode_close(avctx); ++ return AVERROR(ENOMEM); + } + + /** +- * @defgroup rangecoder APE range decoder ++ * @name APE range decoding functions + * @{ + */ + +@@ -227,7 +238,7 @@ + #define BOTTOM_VALUE (TOP_VALUE >> 8) + + /** Start the decoder */ +-static inline void range_start_decoding(APEContext * ctx) ++static inline void range_start_decoding(APEContext *ctx) + { + ctx->rc.buffer = bytestream_get_byte(&ctx->ptr); + ctx->rc.low = ctx->rc.buffer >> (8 - EXTRA_BITS); +@@ -235,13 +246,16 @@ + } + + /** Perform normalization */ +-static inline void range_dec_normalize(APEContext * ctx) ++static inline void range_dec_normalize(APEContext *ctx) + { + while (ctx->rc.range <= BOTTOM_VALUE) { + ctx->rc.buffer <<= 8; +- if(ctx->ptr < ctx->data_end) ++ if(ctx->ptr < ctx->data_end) { + ctx->rc.buffer += *ctx->ptr; +- ctx->ptr++; ++ ctx->ptr++; ++ } else { ++ ctx->error = 1; ++ } + ctx->rc.low = (ctx->rc.low << 8) | ((ctx->rc.buffer >> 1) & 0xFF); + ctx->rc.range <<= 8; + } +@@ -253,7 +267,7 @@ + * @param tot_f is the total frequency or (code_value)1<rc.help = ctx->rc.range / tot_f; +@@ -265,7 +279,7 @@ + * @param ctx decoder context + * @param shift number of bits to decode + */ +-static inline int range_decode_culshift(APEContext * ctx, int shift) ++static inline int range_decode_culshift(APEContext *ctx, int shift) + { + range_dec_normalize(ctx); + ctx->rc.help = ctx->rc.range >> shift; +@@ -279,14 +293,14 @@ + * @param sy_f the interval length (frequency of the symbol) + * @param lt_f the lower end (frequency sum of < symbols) + */ +-static inline void range_decode_update(APEContext * ctx, int sy_f, int lt_f) ++static inline void range_decode_update(APEContext *ctx, int sy_f, int lt_f) + { + ctx->rc.low -= ctx->rc.help * lt_f; + ctx->rc.range = ctx->rc.help * sy_f; + } + + /** Decode n bits (n <= 16) without modelling */ +-static inline int range_decode_bits(APEContext * ctx, int n) ++static inline int range_decode_bits(APEContext *ctx, int n) + { + int sym = range_decode_culshift(ctx, n); + range_decode_update(ctx, 1, sym); +@@ -338,7 +352,7 @@ + * @param counts probability range start position + * @param counts_diff probability range widths + */ +-static inline int range_get_symbol(APEContext * ctx, ++static inline int range_get_symbol(APEContext *ctx, + const uint16_t counts[], + const uint16_t counts_diff[]) + { +@@ -373,7 +387,7 @@ + rice->k++; + } + +-static inline int ape_decode_value(APEContext * ctx, APERice *rice) ++static inline int ape_decode_value(APEContext *ctx, APERice *rice) + { + int x, overflow; + +@@ -440,13 +454,11 @@ + return -(x >> 1); + } + +-static void entropy_decode(APEContext * ctx, int blockstodecode, int stereo) ++static void entropy_decode(APEContext *ctx, int blockstodecode, int stereo) + { + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + +- ctx->blocksdecoded = blockstodecode; +- + if (ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + /* We are pure silence, just memset the output buffer. */ + memset(decoded0, 0, blockstodecode * sizeof(int32_t)); +@@ -458,14 +470,13 @@ + *decoded1++ = ape_decode_value(ctx, &ctx->riceX); + } + } +- +- if (ctx->blocksdecoded == ctx->currentframeblocks) +- range_dec_normalize(ctx); /* normalize to use up all bytes */ + } + +-static void init_entropy_decoder(APEContext * ctx) ++static int init_entropy_decoder(APEContext *ctx) + { + /* Read the CRC */ ++ if (ctx->data_end - ctx->ptr < 6) ++ return AVERROR_INVALIDDATA; + ctx->CRC = bytestream_get_be32(&ctx->ptr); + + /* Read the frame flags if they exist */ +@@ -473,12 +484,11 @@ + if ((ctx->fileversion > 3820) && (ctx->CRC & 0x80000000)) { + ctx->CRC &= ~0x80000000; + ++ if (ctx->data_end - ctx->ptr < 6) ++ return AVERROR_INVALIDDATA; + ctx->frameflags = bytestream_get_be32(&ctx->ptr); + } + +- /* Keep a count of the blocks decoded in this frame */ +- ctx->blocksdecoded = 0; +- + /* Initialize the rice structs */ + ctx->riceX.k = 10; + ctx->riceX.ksum = (1 << ctx->riceX.k) * 16; +@@ -489,13 +499,15 @@ + ctx->ptr++; + + range_start_decoding(ctx); ++ ++ return 0; + } + + static const int32_t initial_coeffs[4] = { + 360, 317, -109, 98 + }; + +-static void init_predictor_decoder(APEContext * ctx) ++static void init_predictor_decoder(APEContext *ctx) + { + APEPredictor *p = &ctx->predictor; + +@@ -518,7 +530,10 @@ + return (x < 0) - (x > 0); + } + +-static av_always_inline int predictor_update_filter(APEPredictor *p, const int decoded, const int filter, const int delayA, const int delayB, const int adaptA, const int adaptB) ++static av_always_inline int predictor_update_filter(APEPredictor *p, ++ const int decoded, const int filter, ++ const int delayA, const int delayB, ++ const int adaptA, const int adaptB) + { + int32_t predictionA, predictionB, sign; + +@@ -562,7 +577,7 @@ + return p->filterA[filter]; + } + +-static void predictor_decode_stereo(APEContext * ctx, int count) ++static void predictor_decode_stereo(APEContext *ctx, int count) + { + APEPredictor *p = &ctx->predictor; + int32_t *decoded0 = ctx->decoded0; +@@ -570,9 +585,11 @@ + + while (count--) { + /* Predictor Y */ +- *decoded0 = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, YADAPTCOEFFSA, YADAPTCOEFFSB); ++ *decoded0 = predictor_update_filter(p, *decoded0, 0, YDELAYA, YDELAYB, ++ YADAPTCOEFFSA, YADAPTCOEFFSB); + decoded0++; +- *decoded1 = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, XADAPTCOEFFSA, XADAPTCOEFFSB); ++ *decoded1 = predictor_update_filter(p, *decoded1, 1, XDELAYA, XDELAYB, ++ XADAPTCOEFFSA, XADAPTCOEFFSB); + decoded1++; + + /* Combined */ +@@ -586,7 +603,7 @@ + } + } + +-static void predictor_decode_mono(APEContext * ctx, int count) ++static void predictor_decode_mono(APEContext *ctx, int count) + { + APEPredictor *p = &ctx->predictor; + int32_t *decoded0 = ctx->decoded0; +@@ -631,7 +648,7 @@ + p->lastA[0] = currentA; + } + +-static void do_init_filter(APEFilter *f, int16_t * buf, int order) ++static void do_init_filter(APEFilter *f, int16_t *buf, int order) + { + f->coeffs = buf; + f->historybuffer = buf + order; +@@ -643,20 +660,23 @@ + f->avg = 0; + } + +-static void init_filter(APEContext * ctx, APEFilter *f, int16_t * buf, int order) ++static void init_filter(APEContext *ctx, APEFilter *f, int16_t *buf, int order) + { + do_init_filter(&f[0], buf, order); + do_init_filter(&f[1], buf + order * 3 + HISTORY_SIZE, order); + } + +-static void do_apply_filter(APEContext * ctx, int version, APEFilter *f, int32_t *data, int count, int order, int fracbits) ++static void do_apply_filter(APEContext *ctx, int version, APEFilter *f, ++ int32_t *data, int count, int order, int fracbits) + { + int res; + int absres; + + while (count--) { + /* round fixedpoint scalar product */ +- res = ctx->dsp.scalarproduct_and_madd_int16(f->coeffs, f->delay - order, f->adaptcoeffs - order, order, APESIGN(*data)); ++ res = ctx->dsp.scalarproduct_and_madd_int16(f->coeffs, f->delay - order, ++ f->adaptcoeffs - order, ++ order, APESIGN(*data)); + res = (res + (1 << (fracbits - 1))) >> fracbits; + res += *data; + *data++ = res; +@@ -675,7 +695,8 @@ + /* Update the adaption coefficients */ + absres = FFABS(res); + if (absres) +- *f->adaptcoeffs = ((res & (1<<31)) - (1<<30)) >> (25 + (absres <= f->avg*3) + (absres <= f->avg*4/3)); ++ *f->adaptcoeffs = ((res & (-1<<31)) ^ (-1<<30)) >> ++ (25 + (absres <= f->avg*3) + (absres <= f->avg*4/3)); + else + *f->adaptcoeffs = 0; + +@@ -698,8 +719,8 @@ + } + } + +-static void apply_filter(APEContext * ctx, APEFilter *f, +- int32_t * data0, int32_t * data1, ++static void apply_filter(APEContext *ctx, APEFilter *f, ++ int32_t *data0, int32_t *data1, + int count, int order, int fracbits) + { + do_apply_filter(ctx, ctx->fileversion, &f[0], data0, count, order, fracbits); +@@ -707,34 +728,38 @@ + do_apply_filter(ctx, ctx->fileversion, &f[1], data1, count, order, fracbits); + } + +-static void ape_apply_filters(APEContext * ctx, int32_t * decoded0, +- int32_t * decoded1, int count) ++static void ape_apply_filters(APEContext *ctx, int32_t *decoded0, ++ int32_t *decoded1, int count) + { + int i; + + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[ctx->fset][i]) + break; +- apply_filter(ctx, ctx->filters[i], decoded0, decoded1, count, ape_filter_orders[ctx->fset][i], ape_filter_fracbits[ctx->fset][i]); ++ apply_filter(ctx, ctx->filters[i], decoded0, decoded1, count, ++ ape_filter_orders[ctx->fset][i], ++ ape_filter_fracbits[ctx->fset][i]); + } + } + +-static void init_frame_decoder(APEContext * ctx) ++static int init_frame_decoder(APEContext *ctx) + { +- int i; +- init_entropy_decoder(ctx); ++ int i, ret; ++ if ((ret = init_entropy_decoder(ctx)) < 0) ++ return ret; + init_predictor_decoder(ctx); + + for (i = 0; i < APE_FILTER_LEVELS; i++) { + if (!ape_filter_orders[ctx->fset][i]) + break; +- init_filter(ctx, ctx->filters[i], ctx->filterbuf[i], ape_filter_orders[ctx->fset][i]); ++ init_filter(ctx, ctx->filters[i], ctx->filterbuf[i], ++ ape_filter_orders[ctx->fset][i]); + } ++ return 0; + } + +-static void ape_unpack_mono(APEContext * ctx, int count) ++static void ape_unpack_mono(APEContext *ctx, int count) + { +- int32_t left; + int32_t *decoded0 = ctx->decoded0; + int32_t *decoded1 = ctx->decoded1; + +@@ -753,14 +778,11 @@ + + /* Pseudo-stereo - just copy left channel to right channel */ + if (ctx->channels == 2) { +- while (count--) { +- left = *decoded0; +- *(decoded1++) = *(decoded0++) = left; +- } ++ memcpy(decoded1, decoded0, count * sizeof(*decoded1)); + } + } + +-static void ape_unpack_stereo(APEContext * ctx, int count) ++static void ape_unpack_stereo(APEContext *ctx, int count) + { + int32_t left, right; + int32_t *decoded0 = ctx->decoded0; +@@ -788,66 +810,87 @@ + } + } + +-static int ape_decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int ape_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + APEContext *s = avctx->priv_data; +- int16_t *samples = data; +- int nblocks; +- int i, n; ++ int16_t *samples; ++ int i, ret; + int blockstodecode; +- int bytes_used; ++ int bytes_used = 0; + +- if (buf_size == 0 && !s->samples) { +- *data_size = 0; +- return 0; +- } +- +- /* should not happen but who knows */ +- if (BLOCKS_PER_LOOP * 2 * avctx->channels > *data_size) { +- av_log (avctx, AV_LOG_ERROR, "Packet size is too big to be handled in lavc! (max is %d where you have %d)\n", *data_size, s->samples * 2 * avctx->channels); +- return -1; +- } ++ /* this should never be negative, but bad things will happen if it is, so ++ check it just to make sure. */ ++ av_assert0(s->samples >= 0); + + if(!s->samples){ +- s->data = av_realloc(s->data, (buf_size + 3) & ~3); ++ uint32_t nblocks, offset; ++ void *tmp_data; ++ ++ if (!buf_size) { ++ *got_frame_ptr = 0; ++ return 0; ++ } ++ if (buf_size < 8) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ tmp_data = av_realloc(s->data, FFALIGN(buf_size, 4)); ++ if (!tmp_data) ++ return AVERROR(ENOMEM); ++ s->data = tmp_data; + s->dsp.bswap_buf((uint32_t*)s->data, (const uint32_t*)buf, buf_size >> 2); +- s->ptr = s->last_ptr = s->data; ++ s->ptr = s->data; + s->data_end = s->data + buf_size; + +- nblocks = s->samples = bytestream_get_be32(&s->ptr); +- n = bytestream_get_be32(&s->ptr); +- if(n < 0 || n > 3){ ++ nblocks = bytestream_get_be32(&s->ptr); ++ offset = bytestream_get_be32(&s->ptr); ++ if (offset > 3) { + av_log(avctx, AV_LOG_ERROR, "Incorrect offset passed\n"); + s->data = NULL; +- return -1; ++ return AVERROR_INVALIDDATA; ++ } ++ if (s->data_end - s->ptr < offset) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; + } +- s->ptr += n; ++ s->ptr += offset; + +- s->currentframeblocks = nblocks; +- buf += 4; +- if (s->samples <= 0) { +- *data_size = 0; +- return buf_size; ++ if (!nblocks || nblocks > INT_MAX) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid sample count: %u.\n", nblocks); ++ return AVERROR_INVALIDDATA; + } ++ s->samples = nblocks; + + memset(s->decoded0, 0, sizeof(s->decoded0)); + memset(s->decoded1, 0, sizeof(s->decoded1)); + + /* Initialize the frame decoder */ +- init_frame_decoder(s); ++ if (init_frame_decoder(s) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Error reading frame header\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ bytes_used = buf_size; + } + + if (!s->data) { +- *data_size = 0; ++ *got_frame_ptr = 0; + return buf_size; + } + +- nblocks = s->samples; +- blockstodecode = FFMIN(BLOCKS_PER_LOOP, nblocks); ++ blockstodecode = FFMIN(BLOCKS_PER_LOOP, s->samples); ++ ++ /* get output buffer */ ++ s->frame.nb_samples = blockstodecode; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)s->frame.data[0]; + + s->error=0; + +@@ -857,10 +900,10 @@ + ape_unpack_stereo(s, blockstodecode); + emms_c(); + +- if(s->error || s->ptr > s->data_end){ ++ if (s->error) { + s->samples=0; + av_log(avctx, AV_LOG_ERROR, "Error decoding frame\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + for (i = 0; i < blockstodecode; i++) { +@@ -871,9 +914,9 @@ + + s->samples -= blockstodecode; + +- *data_size = blockstodecode * 2 * s->channels; +- bytes_used = s->samples ? s->ptr - s->last_ptr : buf_size; +- s->last_ptr = s->ptr; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return bytes_used; + } + +@@ -884,15 +927,14 @@ + } + + AVCodec ff_ape_decoder = { +- "ape", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_APE, +- sizeof(APEContext), +- ape_decode_init, +- NULL, +- ape_decode_close, +- ape_decode_frame, +- .capabilities = CODEC_CAP_SUBFRAMES, ++ .name = "ape", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_APE, ++ .priv_data_size = sizeof(APEContext), ++ .init = ape_decode_init, ++ .close = ape_decode_close, ++ .decode = ape_decode_frame, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY | CODEC_CAP_DR1, + .flush = ape_flush, + .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/api-example.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/api-example.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/api-example.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/api-example.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,467 +0,0 @@ +-/* +- * copyright (c) 2001 Fabrice Bellard +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * avcodec API use example. +- * +- * Note that this library only handles codecs (mpeg, mpeg4, etc...), +- * not file formats (avi, vob, etc...). See library 'libavformat' for the +- * format handling +- */ +- +-#include +-#include +-#include +- +-#ifdef HAVE_AV_CONFIG_H +-#undef HAVE_AV_CONFIG_H +-#endif +- +-#include "libavcodec/avcodec.h" +-#include "libavutil/mathematics.h" +- +-#define INBUF_SIZE 4096 +-#define AUDIO_INBUF_SIZE 20480 +-#define AUDIO_REFILL_THRESH 4096 +- +-/* +- * Audio encoding example +- */ +-static void audio_encode_example(const char *filename) +-{ +- AVCodec *codec; +- AVCodecContext *c= NULL; +- int frame_size, i, j, out_size, outbuf_size; +- FILE *f; +- short *samples; +- float t, tincr; +- uint8_t *outbuf; +- +- printf("Audio encoding\n"); +- +- /* find the MP2 encoder */ +- codec = avcodec_find_encoder(CODEC_ID_MP2); +- if (!codec) { +- fprintf(stderr, "codec not found\n"); +- exit(1); +- } +- +- c= avcodec_alloc_context(); +- +- /* put sample parameters */ +- c->bit_rate = 64000; +- c->sample_rate = 44100; +- c->channels = 2; +- +- /* open it */ +- if (avcodec_open(c, codec) < 0) { +- fprintf(stderr, "could not open codec\n"); +- exit(1); +- } +- +- /* the codec gives us the frame size, in samples */ +- frame_size = c->frame_size; +- samples = malloc(frame_size * 2 * c->channels); +- outbuf_size = 10000; +- outbuf = malloc(outbuf_size); +- +- f = fopen(filename, "wb"); +- if (!f) { +- fprintf(stderr, "could not open %s\n", filename); +- exit(1); +- } +- +- /* encode a single tone sound */ +- t = 0; +- tincr = 2 * M_PI * 440.0 / c->sample_rate; +- for(i=0;i<200;i++) { +- for(j=0;j 0) { +- out_size = AVCODEC_MAX_AUDIO_FRAME_SIZE; +- len = avcodec_decode_audio3(c, (short *)outbuf, &out_size, &avpkt); +- if (len < 0) { +- fprintf(stderr, "Error while decoding\n"); +- exit(1); +- } +- if (out_size > 0) { +- /* if a frame has been decoded, output it */ +- fwrite(outbuf, 1, out_size, outfile); +- } +- avpkt.size -= len; +- avpkt.data += len; +- if (avpkt.size < AUDIO_REFILL_THRESH) { +- /* Refill the input buffer, to avoid trying to decode +- * incomplete frames. Instead of this, one could also use +- * a parser, or use a proper container format through +- * libavformat. */ +- memmove(inbuf, avpkt.data, avpkt.size); +- avpkt.data = inbuf; +- len = fread(avpkt.data + avpkt.size, 1, +- AUDIO_INBUF_SIZE - avpkt.size, f); +- if (len > 0) +- avpkt.size += len; +- } +- } +- +- fclose(outfile); +- fclose(f); +- free(outbuf); +- +- avcodec_close(c); +- av_free(c); +-} +- +-/* +- * Video encoding example +- */ +-static void video_encode_example(const char *filename) +-{ +- AVCodec *codec; +- AVCodecContext *c= NULL; +- int i, out_size, size, x, y, outbuf_size; +- FILE *f; +- AVFrame *picture; +- uint8_t *outbuf, *picture_buf; +- +- printf("Video encoding\n"); +- +- /* find the mpeg1 video encoder */ +- codec = avcodec_find_encoder(CODEC_ID_MPEG1VIDEO); +- if (!codec) { +- fprintf(stderr, "codec not found\n"); +- exit(1); +- } +- +- c= avcodec_alloc_context(); +- picture= avcodec_alloc_frame(); +- +- /* put sample parameters */ +- c->bit_rate = 400000; +- /* resolution must be a multiple of two */ +- c->width = 352; +- c->height = 288; +- /* frames per second */ +- c->time_base= (AVRational){1,25}; +- c->gop_size = 10; /* emit one intra frame every ten frames */ +- c->max_b_frames=1; +- c->pix_fmt = PIX_FMT_YUV420P; +- +- /* open it */ +- if (avcodec_open(c, codec) < 0) { +- fprintf(stderr, "could not open codec\n"); +- exit(1); +- } +- +- f = fopen(filename, "wb"); +- if (!f) { +- fprintf(stderr, "could not open %s\n", filename); +- exit(1); +- } +- +- /* alloc image and output buffer */ +- outbuf_size = 100000; +- outbuf = malloc(outbuf_size); +- size = c->width * c->height; +- picture_buf = malloc((size * 3) / 2); /* size for YUV 420 */ +- +- picture->data[0] = picture_buf; +- picture->data[1] = picture->data[0] + size; +- picture->data[2] = picture->data[1] + size / 4; +- picture->linesize[0] = c->width; +- picture->linesize[1] = c->width / 2; +- picture->linesize[2] = c->width / 2; +- +- /* encode 1 second of video */ +- for(i=0;i<25;i++) { +- fflush(stdout); +- /* prepare a dummy image */ +- /* Y */ +- for(y=0;yheight;y++) { +- for(x=0;xwidth;x++) { +- picture->data[0][y * picture->linesize[0] + x] = x + y + i * 3; +- } +- } +- +- /* Cb and Cr */ +- for(y=0;yheight/2;y++) { +- for(x=0;xwidth/2;x++) { +- picture->data[1][y * picture->linesize[1] + x] = 128 + y + i * 2; +- picture->data[2][y * picture->linesize[2] + x] = 64 + x + i * 5; +- } +- } +- +- /* encode the image */ +- out_size = avcodec_encode_video(c, outbuf, outbuf_size, picture); +- printf("encoding frame %3d (size=%5d)\n", i, out_size); +- fwrite(outbuf, 1, out_size, f); +- } +- +- /* get the delayed frames */ +- for(; out_size; i++) { +- fflush(stdout); +- +- out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); +- printf("write frame %3d (size=%5d)\n", i, out_size); +- fwrite(outbuf, 1, out_size, f); +- } +- +- /* add sequence end code to have a real mpeg file */ +- outbuf[0] = 0x00; +- outbuf[1] = 0x00; +- outbuf[2] = 0x01; +- outbuf[3] = 0xb7; +- fwrite(outbuf, 1, 4, f); +- fclose(f); +- free(picture_buf); +- free(outbuf); +- +- avcodec_close(c); +- av_free(c); +- av_free(picture); +- printf("\n"); +-} +- +-/* +- * Video decoding example +- */ +- +-static void pgm_save(unsigned char *buf, int wrap, int xsize, int ysize, +- char *filename) +-{ +- FILE *f; +- int i; +- +- f=fopen(filename,"w"); +- fprintf(f,"P5\n%d %d\n%d\n",xsize,ysize,255); +- for(i=0;icapabilities&CODEC_CAP_TRUNCATED) +- c->flags|= CODEC_FLAG_TRUNCATED; /* we do not send complete frames */ +- +- /* For some codecs, such as msmpeg4 and mpeg4, width and height +- MUST be initialized there because this information is not +- available in the bitstream. */ +- +- /* open it */ +- if (avcodec_open(c, codec) < 0) { +- fprintf(stderr, "could not open codec\n"); +- exit(1); +- } +- +- /* the codec gives us the frame size, in samples */ +- +- f = fopen(filename, "rb"); +- if (!f) { +- fprintf(stderr, "could not open %s\n", filename); +- exit(1); +- } +- +- frame = 0; +- for(;;) { +- avpkt.size = fread(inbuf, 1, INBUF_SIZE, f); +- if (avpkt.size == 0) +- break; +- +- /* NOTE1: some codecs are stream based (mpegvideo, mpegaudio) +- and this is the only method to use them because you cannot +- know the compressed data size before analysing it. +- +- BUT some other codecs (msmpeg4, mpeg4) are inherently frame +- based, so you must call them with all the data for one +- frame exactly. You must also initialize 'width' and +- 'height' before initializing them. */ +- +- /* NOTE2: some codecs allow the raw parameters (frame size, +- sample rate) to be changed at any frame. We handle this, so +- you should also take care of it */ +- +- /* here, we use a stream based decoder (mpeg1video), so we +- feed decoder and see if it could decode a frame */ +- avpkt.data = inbuf; +- while (avpkt.size > 0) { +- len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); +- if (len < 0) { +- fprintf(stderr, "Error while decoding frame %d\n", frame); +- exit(1); +- } +- if (got_picture) { +- printf("saving frame %3d\n", frame); +- fflush(stdout); +- +- /* the picture is allocated by the decoder. no need to +- free it */ +- snprintf(buf, sizeof(buf), outfilename, frame); +- pgm_save(picture->data[0], picture->linesize[0], +- c->width, c->height, buf); +- frame++; +- } +- avpkt.size -= len; +- avpkt.data += len; +- } +- } +- +- /* some codecs, such as MPEG, transmit the I and P frame with a +- latency of one frame. You must do the following to have a +- chance to get the last frame of the video */ +- avpkt.data = NULL; +- avpkt.size = 0; +- len = avcodec_decode_video2(c, picture, &got_picture, &avpkt); +- if (got_picture) { +- printf("saving last frame %3d\n", frame); +- fflush(stdout); +- +- /* the picture is allocated by the decoder. no need to +- free it */ +- snprintf(buf, sizeof(buf), outfilename, frame); +- pgm_save(picture->data[0], picture->linesize[0], +- c->width, c->height, buf); +- frame++; +- } +- +- fclose(f); +- +- avcodec_close(c); +- av_free(c); +- av_free(picture); +- printf("\n"); +-} +- +-int main(int argc, char **argv) +-{ +- const char *filename; +- +- /* must be called before using avcodec lib */ +- avcodec_init(); +- +- /* register all the codecs */ +- avcodec_register_all(); +- +- if (argc <= 1) { +- audio_encode_example("/tmp/test.mp2"); +- audio_decode_example("/tmp/test.sw", "/tmp/test.mp2"); +- +- video_encode_example("/tmp/test.mpg"); +- filename = "/tmp/test.mpg"; +- } else { +- filename = argv[1]; +- } +- +- // audio_decode_example("/tmp/test.sw", filename); +- video_decode_example("/tmp/test%d.pgm", filename); +- +- return 0; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/aac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/aac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/aac.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/aac.h 2012-05-14 14:08:53.391321002 +0200 +@@ -30,17 +30,17 @@ + const float *scale) + { + unsigned v0, v1; +- __asm__ volatile ("ubfx %0, %4, #0, #4 \n\t" +- "ubfx %1, %4, #4, #4 \n\t" +- "ldr %0, [%3, %0, lsl #2] \n\t" +- "ldr %1, [%3, %1, lsl #2] \n\t" +- "vld1.32 {d1[]}, [%5,:32] \n\t" +- "vmov d0, %0, %1 \n\t" +- "vmul.f32 d0, d0, d1 \n\t" +- "vst1.32 {d0}, [%2,:64]! \n\t" +- : "=&r"(v0), "=&r"(v1), "+r"(dst) +- : "r"(v), "r"(idx), "r"(scale) +- : "d0", "d1"); ++ __asm__ ("ubfx %0, %6, #0, #4 \n\t" ++ "ubfx %1, %6, #4, #4 \n\t" ++ "ldr %0, [%5, %0, lsl #2] \n\t" ++ "ldr %1, [%5, %1, lsl #2] \n\t" ++ "vld1.32 {d1[]}, [%7,:32] \n\t" ++ "vmov d0, %0, %1 \n\t" ++ "vmul.f32 d0, d0, d1 \n\t" ++ "vst1.32 {d0}, [%2,:64]! \n\t" ++ : "=&r"(v0), "=&r"(v1), "+r"(dst), "=m"(dst[0]), "=m"(dst[1]) ++ : "r"(v), "r"(idx), "r"(scale) ++ : "d0", "d1"); + return dst; + } + +@@ -49,22 +49,23 @@ + const float *scale) + { + unsigned v0, v1, v2, v3; +- __asm__ volatile ("ubfx %0, %6, #0, #2 \n\t" +- "ubfx %1, %6, #2, #2 \n\t" +- "ldr %0, [%5, %0, lsl #2] \n\t" +- "ubfx %2, %6, #4, #2 \n\t" +- "ldr %1, [%5, %1, lsl #2] \n\t" +- "ubfx %3, %6, #6, #2 \n\t" +- "ldr %2, [%5, %2, lsl #2] \n\t" +- "vmov d0, %0, %1 \n\t" +- "ldr %3, [%5, %3, lsl #2] \n\t" +- "vld1.32 {d2[],d3[]},[%7,:32] \n\t" +- "vmov d1, %2, %3 \n\t" +- "vmul.f32 q0, q0, q1 \n\t" +- "vst1.32 {q0}, [%4,:128]! \n\t" +- : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst) +- : "r"(v), "r"(idx), "r"(scale) +- : "d0", "d1", "d2", "d3"); ++ __asm__ ("ubfx %0, %10, #0, #2 \n\t" ++ "ubfx %1, %10, #2, #2 \n\t" ++ "ldr %0, [%9, %0, lsl #2] \n\t" ++ "ubfx %2, %10, #4, #2 \n\t" ++ "ldr %1, [%9, %1, lsl #2] \n\t" ++ "ubfx %3, %10, #6, #2 \n\t" ++ "ldr %2, [%9, %2, lsl #2] \n\t" ++ "vmov d0, %0, %1 \n\t" ++ "ldr %3, [%9, %3, lsl #2] \n\t" ++ "vld1.32 {d2[],d3[]},[%11,:32] \n\t" ++ "vmov d1, %2, %3 \n\t" ++ "vmul.f32 q0, q0, q1 \n\t" ++ "vst1.32 {q0}, [%4,:128]! \n\t" ++ : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), ++ "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3]) ++ : "r"(v), "r"(idx), "r"(scale) ++ : "d0", "d1", "d2", "d3"); + return dst; + } + +@@ -73,22 +74,23 @@ + unsigned sign, const float *scale) + { + unsigned v0, v1, v2, v3; +- __asm__ volatile ("ubfx %0, %6, #0, #4 \n\t" +- "ubfx %1, %6, #4, #4 \n\t" +- "ldr %0, [%5, %0, lsl #2] \n\t" +- "lsl %2, %8, #30 \n\t" +- "ldr %1, [%5, %1, lsl #2] \n\t" +- "lsl %3, %8, #31 \n\t" +- "vmov d0, %0, %1 \n\t" +- "bic %2, %2, #1<<30 \n\t" +- "vld1.32 {d1[]}, [%7,:32] \n\t" +- "vmov d2, %2, %3 \n\t" +- "veor d0, d0, d2 \n\t" +- "vmul.f32 d0, d0, d1 \n\t" +- "vst1.32 {d0}, [%4,:64]! \n\t" +- : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst) +- : "r"(v), "r"(idx), "r"(scale), "r"(sign) +- : "d0", "d1", "d2"); ++ __asm__ ("ubfx %0, %8, #0, #4 \n\t" ++ "ubfx %1, %8, #4, #4 \n\t" ++ "ldr %0, [%7, %0, lsl #2] \n\t" ++ "lsl %2, %10, #30 \n\t" ++ "ldr %1, [%7, %1, lsl #2] \n\t" ++ "lsl %3, %10, #31 \n\t" ++ "vmov d0, %0, %1 \n\t" ++ "bic %2, %2, #1<<30 \n\t" ++ "vld1.32 {d1[]}, [%9,:32] \n\t" ++ "vmov d2, %2, %3 \n\t" ++ "veor d0, d0, d2 \n\t" ++ "vmul.f32 d0, d0, d1 \n\t" ++ "vst1.32 {d0}, [%4,:64]! \n\t" ++ : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), ++ "=m"(dst[0]), "=m"(dst[1]) ++ : "r"(v), "r"(idx), "r"(scale), "r"(sign) ++ : "d0", "d1", "d2"); + return dst; + } + +@@ -97,38 +99,42 @@ + unsigned sign, const float *scale) + { + unsigned v0, v1, v2, v3, nz; +- __asm__ volatile ("vld1.32 {d2[],d3[]},[%9,:32] \n\t" +- "ubfx %0, %8, #0, #2 \n\t" +- "ubfx %1, %8, #2, #2 \n\t" +- "ldr %0, [%7, %0, lsl #2] \n\t" +- "ubfx %2, %8, #4, #2 \n\t" +- "ldr %1, [%7, %1, lsl #2] \n\t" +- "ubfx %3, %8, #6, #2 \n\t" +- "ldr %2, [%7, %2, lsl #2] \n\t" +- "vmov d0, %0, %1 \n\t" +- "ldr %3, [%7, %3, lsl #2] \n\t" +- "lsr %6, %8, #12 \n\t" +- "rbit %6, %6 \n\t" +- "vmov d1, %2, %3 \n\t" +- "lsls %6, %6, #1 \n\t" +- "and %0, %5, #1<<31 \n\t" +- "lslcs %5, %5, #1 \n\t" +- "lsls %6, %6, #1 \n\t" +- "and %1, %5, #1<<31 \n\t" +- "lslcs %5, %5, #1 \n\t" +- "lsls %6, %6, #1 \n\t" +- "and %2, %5, #1<<31 \n\t" +- "lslcs %5, %5, #1 \n\t" +- "vmov d4, %0, %1 \n\t" +- "and %3, %5, #1<<31 \n\t" +- "vmov d5, %2, %3 \n\t" +- "veor q0, q0, q2 \n\t" +- "vmul.f32 q0, q0, q1 \n\t" +- "vst1.32 {q0}, [%4,:128]! \n\t" +- : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), +- "+r"(sign), "=r"(nz) +- : "r"(v), "r"(idx), "r"(scale) +- : "d0", "d1", "d2", "d3", "d4", "d5"); ++ __asm__ ("vld1.32 {d2[],d3[]},[%13,:32] \n\t" ++ "ubfx %0, %12, #0, #2 \n\t" ++ "ubfx %1, %12, #2, #2 \n\t" ++ "ldr %0, [%11,%0, lsl #2] \n\t" ++ "ubfx %2, %12, #4, #2 \n\t" ++ "ldr %1, [%11,%1, lsl #2] \n\t" ++ "ubfx %3, %12, #6, #2 \n\t" ++ "ldr %2, [%11,%2, lsl #2] \n\t" ++ "vmov d0, %0, %1 \n\t" ++ "ldr %3, [%11,%3, lsl #2] \n\t" ++ "lsr %6, %12, #12 \n\t" ++ "rbit %6, %6 \n\t" ++ "vmov d1, %2, %3 \n\t" ++ "lsls %6, %6, #1 \n\t" ++ "and %0, %5, #1<<31 \n\t" ++ "it cs \n\t" ++ "lslcs %5, %5, #1 \n\t" ++ "lsls %6, %6, #1 \n\t" ++ "and %1, %5, #1<<31 \n\t" ++ "it cs \n\t" ++ "lslcs %5, %5, #1 \n\t" ++ "lsls %6, %6, #1 \n\t" ++ "and %2, %5, #1<<31 \n\t" ++ "it cs \n\t" ++ "lslcs %5, %5, #1 \n\t" ++ "vmov d4, %0, %1 \n\t" ++ "and %3, %5, #1<<31 \n\t" ++ "vmov d5, %2, %3 \n\t" ++ "veor q0, q0, q2 \n\t" ++ "vmul.f32 q0, q0, q1 \n\t" ++ "vst1.32 {q0}, [%4,:128]! \n\t" ++ : "=&r"(v0), "=&r"(v1), "=&r"(v2), "=&r"(v3), "+r"(dst), ++ "+r"(sign), "=r"(nz), ++ "=m"(dst[0]), "=m"(dst[1]), "=m"(dst[2]), "=m"(dst[3]) ++ : "r"(v), "r"(idx), "r"(scale) ++ : "cc", "d0", "d1", "d2", "d3", "d4", "d5"); + return dst; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_arm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_arm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_arm.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_arm.S 2012-05-14 14:08:53.394321063 +0200 +@@ -0,0 +1,36 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++function ff_ac3_update_bap_counts_arm, export=1 ++ push {lr} ++ ldrb lr, [r1], #1 ++1: ++ lsl r3, lr, #1 ++ ldrh r12, [r0, r3] ++ subs r2, r2, #1 ++ it gt ++ ldrbgt lr, [r1], #1 ++ add r12, r12, #1 ++ strh r12, [r0, r3] ++ bgt 1b ++ pop {pc} ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_armv6.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_armv6.S 2012-05-14 14:08:53.395321083 +0200 +@@ -0,0 +1,85 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++function ff_ac3_bit_alloc_calc_bap_armv6, export=1 ++ ldr r12, [sp] ++ cmp r12, #-960 ++ beq 4f ++ push {r4-r11,lr} ++ add r5, sp, #40 ++ movrel r4, X(ff_ac3_bin_to_band_tab) ++ movrel lr, X(ff_ac3_band_start_tab) ++ ldm r5, {r5-r7} ++ ldrb r4, [r4, r2] ++ add r1, r1, r2, lsl #1 @ psd + start ++ add r0, r0, r4, lsl #1 @ mask + band ++ add r4, lr, r4 ++ add r7, r7, r2 @ bap + start ++ ldrb r10, [r4], #1 ++1: ++ ldrsh r9, [r0], #2 @ mask[band] ++ mov r8, #0xff0 ++ sub r9, r9, r12 @ - snr_offset ++ mov r11, r10 ++ ldrb r10, [r4], #1 @ band_start_tab[band++] ++ subs r9, r9, r5 @ - floor ++ it lt ++ movlt r9, #0 ++ cmp r10, r3 @ - end ++ and r9, r9, r8, lsl #1 @ & 0x1fe0 ++ ite gt ++ subgt r8, r3, r11 ++ suble r8, r10, r11 ++ add r9, r9, r5 @ + floor => m ++ tst r8, #1 ++ add r2, r7, r8 ++ bne 3f ++ b 5f ++2: ++ ldrsh r8, [r1], #2 ++ ldrsh lr, [r1], #2 ++ sub r8, r8, r9 ++ sub lr, lr, r9 ++ usat r8, #6, r8, asr #5 @ address ++ usat lr, #6, lr, asr #5 ++ ldrb r8, [r6, r8] @ bap_tab[address] ++ ldrb lr, [r6, lr] ++ strb r8, [r7], #1 @ bap[bin] ++ strb lr, [r7], #1 ++5: cmp r7, r2 ++ blo 2b ++ cmp r3, r11 ++ bgt 1b ++ pop {r4-r11,pc} ++3: ++ ldrsh r8, [r1], #2 @ psd[bin] ++ sub r8, r8, r9 @ - m ++ usat r8, #6, r8, asr #5 @ address ++ ldrb r8, [r6, r8] @ bap_tab[address] ++ strb r8, [r7], #1 @ bap[bin] ++ b 5b ++4: ++ ldr r0, [sp, #12] ++ mov r1, #0 ++ mov r2, #256 ++ b X(memset) ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_init_arm.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_init_arm.c 2012-05-14 14:08:53.395321083 +0200 +@@ -0,0 +1,66 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "libavutil/attributes.h" ++#include "libavcodec/ac3dsp.h" ++#include "config.h" ++ ++void ff_ac3_exponent_min_neon(uint8_t *exp, int num_reuse_blocks, int nb_coefs); ++int ff_ac3_max_msb_abs_int16_neon(const int16_t *src, int len); ++void ff_ac3_lshift_int16_neon(int16_t *src, unsigned len, unsigned shift); ++void ff_ac3_rshift_int32_neon(int32_t *src, unsigned len, unsigned shift); ++void ff_float_to_fixed24_neon(int32_t *dst, const float *src, unsigned int len); ++void ff_ac3_extract_exponents_neon(uint8_t *exp, int32_t *coef, int nb_coefs); ++void ff_ac3_sum_square_butterfly_int32_neon(int64_t sum[4], ++ const int32_t *coef0, ++ const int32_t *coef1, ++ int len); ++void ff_ac3_sum_square_butterfly_float_neon(float sum[4], ++ const float *coef0, ++ const float *coef1, ++ int len); ++ ++void ff_ac3_bit_alloc_calc_bap_armv6(int16_t *mask, int16_t *psd, ++ int start, int end, ++ int snr_offset, int floor, ++ const uint8_t *bap_tab, uint8_t *bap); ++ ++void ff_ac3_update_bap_counts_arm(uint16_t mant_cnt[16], uint8_t *bap, int len); ++ ++av_cold void ff_ac3dsp_init_arm(AC3DSPContext *c, int bit_exact) ++{ ++ c->update_bap_counts = ff_ac3_update_bap_counts_arm; ++ ++ if (HAVE_ARMV6) { ++ c->bit_alloc_calc_bap = ff_ac3_bit_alloc_calc_bap_armv6; ++ } ++ ++ if (HAVE_NEON) { ++ c->ac3_exponent_min = ff_ac3_exponent_min_neon; ++ c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_neon; ++ c->ac3_lshift_int16 = ff_ac3_lshift_int16_neon; ++ c->ac3_rshift_int32 = ff_ac3_rshift_int32_neon; ++ c->float_to_fixed24 = ff_float_to_fixed24_neon; ++ c->extract_exponents = ff_ac3_extract_exponents_neon; ++ c->sum_square_butterfly_int32 = ff_ac3_sum_square_butterfly_int32_neon; ++ c->sum_square_butterfly_float = ff_ac3_sum_square_butterfly_float_neon; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/ac3dsp_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/ac3dsp_neon.S 2012-05-14 14:08:53.396321103 +0200 +@@ -0,0 +1,154 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++function ff_ac3_max_msb_abs_int16_neon, export=1 ++ vmov.i16 q0, #0 ++ vmov.i16 q2, #0 ++1: vld1.16 {q1}, [r0,:128]! ++ vabs.s16 q1, q1 ++ vld1.16 {q3}, [r0,:128]! ++ vabs.s16 q3, q3 ++ vorr q0, q0, q1 ++ vorr q2, q2, q3 ++ subs r1, r1, #16 ++ bgt 1b ++ vorr q0, q0, q2 ++ vorr d0, d0, d1 ++ vpmax.u16 d0, d0, d0 ++ vpmax.u16 d0, d0, d0 ++ vmov.u16 r0, d0[0] ++ bx lr ++endfunc ++ ++function ff_ac3_exponent_min_neon, export=1 ++ cmp r1, #0 ++ it eq ++ bxeq lr ++ push {lr} ++ mov r12, #256 ++1: ++ vld1.8 {q0}, [r0,:128] ++ mov lr, r1 ++ add r3, r0, #256 ++2: vld1.8 {q1}, [r3,:128], r12 ++ subs lr, lr, #1 ++ vmin.u8 q0, q0, q1 ++ bgt 2b ++ subs r2, r2, #16 ++ vst1.8 {q0}, [r0,:128]! ++ bgt 1b ++ pop {pc} ++endfunc ++ ++function ff_ac3_lshift_int16_neon, export=1 ++ vdup.16 q0, r2 ++1: vld1.16 {q1}, [r0,:128] ++ vshl.s16 q1, q1, q0 ++ vst1.16 {q1}, [r0,:128]! ++ subs r1, r1, #8 ++ bgt 1b ++ bx lr ++endfunc ++ ++function ff_ac3_rshift_int32_neon, export=1 ++ rsb r2, r2, #0 ++ vdup.32 q0, r2 ++1: vld1.32 {q1}, [r0,:128] ++ vshl.s32 q1, q1, q0 ++ vst1.32 {q1}, [r0,:128]! ++ subs r1, r1, #4 ++ bgt 1b ++ bx lr ++endfunc ++ ++function ff_float_to_fixed24_neon, export=1 ++1: vld1.32 {q0-q1}, [r1,:128]! ++ vcvt.s32.f32 q0, q0, #24 ++ vld1.32 {q2-q3}, [r1,:128]! ++ vcvt.s32.f32 q1, q1, #24 ++ vcvt.s32.f32 q2, q2, #24 ++ vst1.32 {q0-q1}, [r0,:128]! ++ vcvt.s32.f32 q3, q3, #24 ++ vst1.32 {q2-q3}, [r0,:128]! ++ subs r2, r2, #16 ++ bgt 1b ++ bx lr ++endfunc ++ ++function ff_ac3_extract_exponents_neon, export=1 ++ vmov.i32 q15, #8 ++1: ++ vld1.32 {q0}, [r1,:128]! ++ vabs.s32 q1, q0 ++ vclz.i32 q3, q1 ++ vsub.i32 q3, q3, q15 ++ vmovn.i32 d6, q3 ++ vmovn.i16 d6, q3 ++ vst1.32 {d6[0]}, [r0,:32]! ++ subs r2, r2, #4 ++ bgt 1b ++ bx lr ++endfunc ++ ++function ff_ac3_sum_square_butterfly_int32_neon, export=1 ++ vmov.i64 q0, #0 ++ vmov.i64 q1, #0 ++ vmov.i64 q2, #0 ++ vmov.i64 q3, #0 ++1: ++ vld1.32 {d16}, [r1]! ++ vld1.32 {d17}, [r2]! ++ vadd.s32 d18, d16, d17 ++ vsub.s32 d19, d16, d17 ++ vmlal.s32 q0, d16, d16 ++ vmlal.s32 q1, d17, d17 ++ vmlal.s32 q2, d18, d18 ++ vmlal.s32 q3, d19, d19 ++ subs r3, r3, #2 ++ bgt 1b ++ vadd.s64 d0, d0, d1 ++ vadd.s64 d1, d2, d3 ++ vadd.s64 d2, d4, d5 ++ vadd.s64 d3, d6, d7 ++ vst1.64 {q0-q1}, [r0] ++ bx lr ++endfunc ++ ++function ff_ac3_sum_square_butterfly_float_neon, export=1 ++ vmov.f32 q0, #0.0 ++ vmov.f32 q1, #0.0 ++1: ++ vld1.32 {d16}, [r1]! ++ vld1.32 {d17}, [r2]! ++ vadd.f32 d18, d16, d17 ++ vsub.f32 d19, d16, d17 ++ vmla.f32 d0, d16, d16 ++ vmla.f32 d1, d17, d17 ++ vmla.f32 d2, d18, d18 ++ vmla.f32 d3, d19, d19 ++ subs r3, r3, #2 ++ bgt 1b ++ vpadd.f32 d0, d0, d1 ++ vpadd.f32 d1, d2, d3 ++ vst1.32 {q0}, [r0] ++ bx lr ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/asm-offsets.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/asm-offsets.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/asm-offsets.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/asm-offsets.h 2012-05-14 14:08:53.397321123 +0200 +@@ -29,11 +29,11 @@ + #endif + + /* MpegEncContext */ +-#define Y_DC_SCALE 0xb4 +-#define C_DC_SCALE 0xb8 +-#define AC_PRED 0xbc +-#define BLOCK_LAST_INDEX 0xc0 +-#define H263_AIC 0xf0 +-#define INTER_SCANTAB_RASTER_END 0x138 ++#define Y_DC_SCALE 0xa8 ++#define C_DC_SCALE 0xac ++#define AC_PRED 0xb0 ++#define BLOCK_LAST_INDEX 0xb4 ++#define H263_AIC 0xe4 ++#define INTER_SCANTAB_RASTER_END 0x12c + +-#endif ++#endif /* AVCODEC_ARM_ASM_OFFSETS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/asm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/asm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/asm.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/asm.S 2012-05-14 14:08:53.397321123 +0200 +@@ -26,6 +26,33 @@ + # define ELF @ + #endif + ++#if CONFIG_THUMB ++# define A @ ++# define T ++#else ++# define A ++# define T @ ++#endif ++ ++#if HAVE_NEON ++ .arch armv7-a ++#elif HAVE_ARMV6T2 ++ .arch armv6t2 ++#elif HAVE_ARMV6 ++ .arch armv6 ++#elif HAVE_ARMV5TE ++ .arch armv5te ++#endif ++ ++#if HAVE_NEON ++ .fpu neon ++#elif HAVE_ARMVFP ++ .fpu vfp ++#endif ++ ++ .syntax unified ++T .thumb ++ + .macro require8 val=1 + ELF .eabi_attribute 24, \val + .endm +@@ -41,6 +68,7 @@ + .purgem endfunc + .endm + .text ++ .align 2 + .if \export + .global EXTERN_ASM\name + EXTERN_ASM\name: +@@ -80,6 +108,108 @@ + #endif + .endm + ++.macro ldr_pre rt, rn, rm:vararg ++A ldr \rt, [\rn, \rm]! ++T add \rn, \rn, \rm ++T ldr \rt, [\rn] ++.endm ++ ++.macro ldr_dpre rt, rn, rm:vararg ++A ldr \rt, [\rn, -\rm]! ++T sub \rn, \rn, \rm ++T ldr \rt, [\rn] ++.endm ++ ++.macro ldr_dpren rt, rn, rm:vararg ++A ldr \rt, [\rn, -\rm] ++T sub \rt, \rn, \rm ++T ldr \rt, [\rt] ++.endm ++ ++.macro ldr_post rt, rn, rm:vararg ++A ldr \rt, [\rn], \rm ++T ldr \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro ldrd_reg rt, rt2, rn, rm ++A ldrd \rt, \rt2, [\rn, \rm] ++T add \rt, \rn, \rm ++T ldrd \rt, \rt2, [\rt] ++.endm ++ ++.macro ldrd_post rt, rt2, rn, rm ++A ldrd \rt, \rt2, [\rn], \rm ++T ldrd \rt, \rt2, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro ldrh_pre rt, rn, rm ++A ldrh \rt, [\rn, \rm]! ++T add \rn, \rn, \rm ++T ldrh \rt, [\rn] ++.endm ++ ++.macro ldrh_dpre rt, rn, rm ++A ldrh \rt, [\rn, -\rm]! ++T sub \rn, \rn, \rm ++T ldrh \rt, [\rn] ++.endm ++ ++.macro ldrh_post rt, rn, rm ++A ldrh \rt, [\rn], \rm ++T ldrh \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro ldrb_post rt, rn, rm ++A ldrb \rt, [\rn], \rm ++T ldrb \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro str_post rt, rn, rm:vararg ++A str \rt, [\rn], \rm ++T str \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro strb_post rt, rn, rm:vararg ++A strb \rt, [\rn], \rm ++T strb \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro strd_post rt, rt2, rn, rm ++A strd \rt, \rt2, [\rn], \rm ++T strd \rt, \rt2, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro strh_pre rt, rn, rm ++A strh \rt, [\rn, \rm]! ++T add \rn, \rn, \rm ++T strh \rt, [\rn] ++.endm ++ ++.macro strh_dpre rt, rn, rm ++A strh \rt, [\rn, -\rm]! ++T sub \rn, \rn, \rm ++T strh \rt, [\rn] ++.endm ++ ++.macro strh_post rt, rn, rm ++A strh \rt, [\rn], \rm ++T strh \rt, [\rn] ++T add \rn, \rn, \rm ++.endm ++ ++.macro strh_dpost rt, rn, rm ++A strh \rt, [\rn], -\rm ++T strh \rt, [\rn] ++T sub \rn, \rn, \rm ++.endm ++ + #if HAVE_VFP_ARGS + .eabi_attribute 28, 1 + # define VFP +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dcadsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dcadsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dcadsp_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dcadsp_neon.S 2012-05-14 14:08:53.402321224 +0200 +@@ -27,6 +27,7 @@ + add r5, r2, #256*4-16 @ cf1 + sub r1, r1, #12 + cmp r3, #32 ++ ite eq + moveq r6, #256/32 + movne r6, #256/64 + NOVFP vldr s0, [sp, #16] @ scale +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dca.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dca.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dca.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dca.h 2012-05-14 14:08:53.399321163 +0200 +@@ -0,0 +1,104 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_ARM_DCA_H ++#define AVCODEC_ARM_DCA_H ++ ++#include ++#include "config.h" ++#include "libavutil/intmath.h" ++ ++#if HAVE_ARMV6 && HAVE_INLINE_ASM && AV_GCC_VERSION_AT_LEAST(4,4) ++ ++#define decode_blockcodes decode_blockcodes ++static inline int decode_blockcodes(int code1, int code2, int levels, ++ int *values) ++{ ++ int v0, v1, v2, v3, v4, v5; ++ ++ __asm__ ("smmul %8, %14, %18 \n" ++ "smmul %11, %15, %18 \n" ++ "smlabb %14, %8, %17, %14 \n" ++ "smlabb %15, %11, %17, %15 \n" ++ "smmul %9, %8, %18 \n" ++ "smmul %12, %11, %18 \n" ++ "sub %14, %14, %16, lsr #1 \n" ++ "sub %15, %15, %16, lsr #1 \n" ++ "smlabb %8, %9, %17, %8 \n" ++ "smlabb %11, %12, %17, %11 \n" ++ "smmul %10, %9, %18 \n" ++ "smmul %13, %12, %18 \n" ++ "str %14, %0 \n" ++ "str %15, %4 \n" ++ "sub %8, %8, %16, lsr #1 \n" ++ "sub %11, %11, %16, lsr #1 \n" ++ "smlabb %9, %10, %17, %9 \n" ++ "smlabb %12, %13, %17, %12 \n" ++ "smmul %14, %10, %18 \n" ++ "smmul %15, %13, %18 \n" ++ "str %8, %1 \n" ++ "str %11, %5 \n" ++ "sub %9, %9, %16, lsr #1 \n" ++ "sub %12, %12, %16, lsr #1 \n" ++ "smlabb %10, %14, %17, %10 \n" ++ "smlabb %13, %15, %17, %13 \n" ++ "str %9, %2 \n" ++ "str %12, %6 \n" ++ "sub %10, %10, %16, lsr #1 \n" ++ "sub %13, %13, %16, lsr #1 \n" ++ "str %10, %3 \n" ++ "str %13, %7 \n" ++ : "=m"(values[0]), "=m"(values[1]), ++ "=m"(values[2]), "=m"(values[3]), ++ "=m"(values[4]), "=m"(values[5]), ++ "=m"(values[6]), "=m"(values[7]), ++ "=&r"(v0), "=&r"(v1), "=&r"(v2), ++ "=&r"(v3), "=&r"(v4), "=&r"(v5), ++ "+&r"(code1), "+&r"(code2) ++ : "r"(levels - 1), "r"(-levels), "r"(ff_inverse[levels])); ++ ++ return code1 | code2; ++} ++ ++#endif ++ ++#if HAVE_NEON && HAVE_INLINE_ASM && HAVE_ASM_MOD_Y ++ ++#define int8x8_fmul_int32 int8x8_fmul_int32 ++static inline void int8x8_fmul_int32(float *dst, const int8_t *src, int scale) ++{ ++ __asm__ ("vcvt.f32.s32 %2, %2, #4 \n" ++ "vld1.8 {d0}, [%1,:64] \n" ++ "vmovl.s8 q0, d0 \n" ++ "vmovl.s16 q1, d1 \n" ++ "vmovl.s16 q0, d0 \n" ++ "vcvt.f32.s32 q0, q0 \n" ++ "vcvt.f32.s32 q1, q1 \n" ++ "vmul.f32 q0, q0, %y2 \n" ++ "vmul.f32 q1, q1, %y2 \n" ++ "vst1.32 {q0-q1}, [%m0,:128] \n" ++ : "=Um"(*(float (*)[8])dst) ++ : "r"(src), "x"(scale) ++ : "d0", "d1", "d2", "d3"); ++} ++ ++#endif ++ ++#endif /* AVCODEC_ARM_DCA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_arm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_arm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_arm.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_arm.h 2012-05-14 14:08:53.404321264 +0200 +@@ -30,4 +30,4 @@ + void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx); + void ff_dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx); + +-#endif ++#endif /* AVCODEC_ARM_DSPUTIL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_arm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_arm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_arm.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_arm.S 2012-05-14 14:08:53.403321244 +0200 +@@ -24,11 +24,6 @@ + + preserve8 + +-#if !HAVE_PLD +-.macro pld reg +-.endm +-#endif +- + #if HAVE_ARMV5TE + function ff_prefetch_arm, export=1 + subs r2, r2, #1 +@@ -37,6 +32,8 @@ + bne ff_prefetch_arm + bx lr + endfunc ++#else ++#define pld @ + #endif + + .macro ALIGN_QWORD_D shift, Rd0, Rd1, Rd2, Rd3, Rn0, Rn1, Rn2, Rn3, Rn4 +@@ -554,10 +551,12 @@ + and r9, r5, r14 + and r10, r6, r14 + and r11, r7, r14 ++ it eq + andeq r14, r14, r14, \rnd #1 + add r8, r8, r10 + add r9, r9, r11 + ldr r12, =0xfcfcfcfc >> 2 ++ itt eq + addeq r8, r8, r14 + addeq r9, r9, r14 + and r4, r12, r4, lsr #2 +@@ -638,8 +637,10 @@ + mvn r5, r5 + mvn r7, r7 + tst r6, #0x100 ++ it ne + movne r6, r5, lsr #24 + tst r8, #0x100 ++ it ne + movne r8, r7, lsr #24 + mov r9, r6 + ldrsh r5, [r0, #4] /* moved form [A] */ +@@ -654,8 +655,10 @@ + mvn r5, r5 + mvn r7, r7 + tst r6, #0x100 ++ it ne + movne r6, r5, lsr #24 + tst r8, #0x100 ++ it ne + movne r8, r7, lsr #24 + orr r9, r9, r6, lsl #16 + ldr r4, [r1, #4] /* moved form [B] */ +@@ -676,8 +679,10 @@ + mvn r5, r5 + mvn r7, r7 + tst r6, #0x100 ++ it ne + movne r6, r5, lsr #24 + tst r8, #0x100 ++ it ne + movne r8, r7, lsr #24 + mov r9, r6 + ldrsh r5, [r0, #12] /* moved from [D] */ +@@ -692,8 +697,10 @@ + mvn r5, r5 + mvn r7, r7 + tst r6, #0x100 ++ it ne + movne r6, r5, lsr #24 + tst r8, #0x100 ++ it ne + movne r8, r7, lsr #24 + orr r9, r9, r6, lsl #16 + add r0, r0, #16 /* moved from [E] */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_armv6.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_armv6.S 2012-05-14 14:08:53.405321284 +0200 +@@ -22,8 +22,6 @@ + + preserve8 + +- .text +- + .macro call_2x_pixels type, subp + function ff_\type\()_pixels16\subp\()_armv6, export=1 + push {r0-r3, lr} +@@ -47,16 +45,16 @@ + ldr r5, [r1, #4] + ldr r6, [r1, #8] + ldr r7, [r1, #12] +- ldr r4, [r1], r2 ++ ldr_post r4, r1, r2 + strd r6, r7, [r0, #8] + ldr r9, [r1, #4] +- strd r4, r5, [r0], r2 ++ strd_post r4, r5, r0, r2 + ldr r10, [r1, #8] + ldr r11, [r1, #12] +- ldr r8, [r1], r2 ++ ldr_post r8, r1, r2 + strd r10, r11, [r0, #8] + subs r3, r3, #2 +- strd r8, r9, [r0], r2 ++ strd_post r8, r9, r0, r2 + bne 1b + + pop {r4-r11} +@@ -67,12 +65,12 @@ + push {r4-r7} + 1: + ldr r5, [r1, #4] +- ldr r4, [r1], r2 ++ ldr_post r4, r1, r2 + ldr r7, [r1, #4] +- strd r4, r5, [r0], r2 +- ldr r6, [r1], r2 ++ strd_post r4, r5, r0, r2 ++ ldr_post r6, r1, r2 + subs r3, r3, #2 +- strd r6, r7, [r0], r2 ++ strd_post r6, r7, r0, r2 + bne 1b + + pop {r4-r7} +@@ -90,7 +88,7 @@ + ldr r5, [r1, #4] + ldr r7, [r1, #5] + lsr r6, r4, #8 +- ldr r8, [r1, r2]! ++ ldr_pre r8, r1, r2 + orr r6, r6, r5, lsl #24 + ldr r9, [r1, #4] + ldr r11, [r1, #5] +@@ -112,9 +110,9 @@ + uhadd8 r9, r9, r11 + and r6, r6, r12 + uadd8 r8, r8, r14 +- strd r4, r5, [r0], r2 ++ strd_post r4, r5, r0, r2 + uadd8 r9, r9, r6 +- strd r8, r9, [r0], r2 ++ strd_post r8, r9, r0, r2 + bne 1b + + pop {r4-r11, pc} +@@ -127,7 +125,7 @@ + orr r12, r12, r12, lsl #16 + ldr r4, [r1] + ldr r5, [r1, #4] +- ldr r6, [r1, r2]! ++ ldr_pre r6, r1, r2 + ldr r7, [r1, #4] + 1: + subs r3, r3, #2 +@@ -136,7 +134,7 @@ + uhadd8 r9, r5, r7 + eor r11, r5, r7 + and r10, r10, r12 +- ldr r4, [r1, r2]! ++ ldr_pre r4, r1, r2 + uadd8 r8, r8, r10 + and r11, r11, r12 + uadd8 r9, r9, r11 +@@ -148,11 +146,11 @@ + eor r7, r5, r7 + uadd8 r10, r10, r6 + and r7, r7, r12 +- ldr r6, [r1, r2]! ++ ldr_pre r6, r1, r2 + uadd8 r11, r11, r7 +- strd r8, r9, [r0], r2 ++ strd_post r8, r9, r0, r2 + ldr r7, [r1, #4] +- strd r10, r11, [r0], r2 ++ strd_post r10, r11, r0, r2 + bne 1b + + pop {r4-r11} +@@ -166,7 +164,7 @@ + ldr r4, [r1] + ldr r5, [r1, #4] + ldr r7, [r1, #5] +- ldr r8, [r1, r2]! ++ ldr_pre r8, r1, r2 + ldr r9, [r1, #4] + ldr r14, [r1, #5] + add r1, r1, r2 +@@ -191,16 +189,16 @@ + push {r4-r9, lr} + ldr r4, [r1] + ldr r5, [r1, #4] +- ldr r6, [r1, r2]! ++ ldr_pre r6, r1, r2 + ldr r7, [r1, #4] + 1: + subs r3, r3, #2 + uhadd8 r8, r4, r6 +- ldr r4, [r1, r2]! ++ ldr_pre r4, r1, r2 + uhadd8 r9, r5, r7 + ldr r5, [r1, #4] + uhadd8 r12, r4, r6 +- ldr r6, [r1, r2]! ++ ldr_pre r6, r1, r2 + uhadd8 r14, r5, r7 + ldr r7, [r1, #4] + stm r0, {r8,r9} +@@ -220,44 +218,44 @@ + orr lr, lr, lr, lsl #16 + ldrd r4, r5, [r0] + ldr r10, [r1, #4] +- ldr r9, [r1], r2 ++ ldr_post r9, r1, r2 + subs r3, r3, #2 + 1: + pld [r1, r2] + eor r8, r4, r9 + uhadd8 r4, r4, r9 + eor r12, r5, r10 +- ldrd r6, r7, [r0, r2] ++ ldrd_reg r6, r7, r0, r2 + uhadd8 r5, r5, r10 + and r8, r8, lr + ldr r10, [r1, #4] + and r12, r12, lr + uadd8 r4, r4, r8 +- ldr r9, [r1], r2 ++ ldr_post r9, r1, r2 + eor r8, r6, r9 + uadd8 r5, r5, r12 + pld [r1, r2, lsl #1] + eor r12, r7, r10 + uhadd8 r6, r6, r9 +- strd r4, r5, [r0], r2 ++ strd_post r4, r5, r0, r2 + uhadd8 r7, r7, r10 + beq 2f + and r8, r8, lr +- ldrd r4, r5, [r0, r2] ++ ldrd_reg r4, r5, r0, r2 + uadd8 r6, r6, r8 + ldr r10, [r1, #4] + and r12, r12, lr + subs r3, r3, #2 + uadd8 r7, r7, r12 +- ldr r9, [r1], r2 +- strd r6, r7, [r0], r2 ++ ldr_post r9, r1, r2 ++ strd_post r6, r7, r0, r2 + b 1b + 2: + and r8, r8, lr + and r12, r12, lr + uadd8 r6, r6, r8 + uadd8 r7, r7, r12 +- strd r6, r7, [r0], r2 ++ strd_post r6, r7, r0, r2 + + pop {r4-r10, pc} + endfunc +@@ -284,7 +282,7 @@ + orr r6, r8, r5, lsl #8 + orr r7, r4, lr, lsl #8 + subs r3, r3, #1 +- strd r6, r7, [r1], r2 ++ strd_post r6, r7, r1, r2 + bgt 1b + pop {r4-r8,pc} + endfunc +@@ -294,7 +292,7 @@ + push {r4-r8, lr} + mov lr, #8 + 1: +- ldrd r4, r5, [r1], r2 ++ ldrd_post r4, r5, r1, r2 + subs lr, lr, #1 + uxtb16 r6, r4 + uxtb16 r4, r4, ror #8 +@@ -317,8 +315,8 @@ + push {r4-r9, lr} + mov lr, #8 + 1: +- ldrd r4, r5, [r1], r3 +- ldrd r6, r7, [r2], r3 ++ ldrd_post r4, r5, r1, r3 ++ ldrd_post r6, r7, r2, r3 + uxtb16 r8, r4 + uxtb16 r4, r4, ror #8 + uxtb16 r9, r6 +@@ -492,19 +490,19 @@ + push {r4-r9, lr} + mov r0, #0 + mov lr, #0 +- ldrd r4, r5, [r1], r3 ++ ldrd_post r4, r5, r1, r3 + 1: + subs r12, r12, #2 + ldr r7, [r2, #4] +- ldr r6, [r2], r3 +- ldrd r8, r9, [r1], r3 ++ ldr_post r6, r2, r3 ++ ldrd_post r8, r9, r1, r3 + usada8 r0, r4, r6, r0 + pld [r2, r3] + usada8 lr, r5, r7, lr + ldr r7, [r2, #4] +- ldr r6, [r2], r3 ++ ldr_post r6, r2, r3 + beq 2f +- ldrd r4, r5, [r1], r3 ++ ldrd_post r4, r5, r1, r3 + usada8 r0, r8, r6, r0 + pld [r2, r3] + usada8 lr, r9, r7, lr +@@ -613,7 +611,7 @@ + ldr r7, [r0, #12] + usada8 r2, r6, lr, r2 + beq 2f +- ldr r4, [r0, r1]! ++ ldr_pre r4, r0, r1 + usada8 r3, r7, lr, r3 + bgt 1b + 2: +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_arm.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_arm.c 2012-05-14 14:08:53.406321304 +0200 +@@ -75,10 +75,12 @@ + + void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx) + { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ + ff_put_pixels_clamped = c->put_pixels_clamped; + ff_add_pixels_clamped = c->add_pixels_clamped; + +- if (!avctx->lowres) { ++ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8) { + if(avctx->idct_algo == FF_IDCT_AUTO || + avctx->idct_algo == FF_IDCT_ARM){ + c->idct_put = j_rev_dct_arm_put; +@@ -95,6 +97,7 @@ + + c->add_pixels_clamped = ff_add_pixels_clamped_arm; + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = ff_put_pixels16_arm; + c->put_pixels_tab[0][1] = ff_put_pixels16_x2_arm; + c->put_pixels_tab[0][2] = ff_put_pixels16_y2_arm; +@@ -112,6 +115,7 @@ + c->put_no_rnd_pixels_tab[1][1] = ff_put_no_rnd_pixels8_x2_arm; + c->put_no_rnd_pixels_tab[1][2] = ff_put_no_rnd_pixels8_y2_arm; + c->put_no_rnd_pixels_tab[1][3] = ff_put_no_rnd_pixels8_xy2_arm; ++ } + + if (HAVE_ARMV5TE) ff_dsputil_init_armv5te(c, avctx); + if (HAVE_ARMV6) ff_dsputil_init_armv6(c, avctx); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_armv5te.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_armv5te.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_armv5te.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_armv5te.c 2012-05-14 14:08:53.406321304 +0200 +@@ -29,8 +29,9 @@ + + void av_cold ff_dsputil_init_armv5te(DSPContext* c, AVCodecContext *avctx) + { +- if (!avctx->lowres && (avctx->idct_algo == FF_IDCT_AUTO || +- avctx->idct_algo == FF_IDCT_SIMPLEARMV5TE)) { ++ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 && ++ (avctx->idct_algo == FF_IDCT_AUTO || ++ avctx->idct_algo == FF_IDCT_SIMPLEARMV5TE)) { + c->idct_put = ff_simple_idct_put_armv5te; + c->idct_add = ff_simple_idct_add_armv5te; + c->idct = ff_simple_idct_armv5te; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_armv6.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_armv6.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_armv6.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_armv6.c 2012-05-14 14:08:53.407321324 +0200 +@@ -72,14 +72,18 @@ + + void av_cold ff_dsputil_init_armv6(DSPContext* c, AVCodecContext *avctx) + { +- if (!avctx->lowres && (avctx->idct_algo == FF_IDCT_AUTO || +- avctx->idct_algo == FF_IDCT_SIMPLEARMV6)) { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ ++ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8 && ++ (avctx->idct_algo == FF_IDCT_AUTO || ++ avctx->idct_algo == FF_IDCT_SIMPLEARMV6)) { + c->idct_put = ff_simple_idct_put_armv6; + c->idct_add = ff_simple_idct_add_armv6; + c->idct = ff_simple_idct_armv6; + c->idct_permutation_type = FF_LIBMPEG2_IDCT_PERM; + } + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = ff_put_pixels16_armv6; + c->put_pixels_tab[0][1] = ff_put_pixels16_x2_armv6; + c->put_pixels_tab[0][2] = ff_put_pixels16_y2_armv6; +@@ -100,9 +104,11 @@ + + c->avg_pixels_tab[0][0] = ff_avg_pixels16_armv6; + c->avg_pixels_tab[1][0] = ff_avg_pixels8_armv6; ++ } + ++ if (!high_bit_depth) ++ c->get_pixels = ff_get_pixels_armv6; + c->add_pixels_clamped = ff_add_pixels_clamped_armv6; +- c->get_pixels = ff_get_pixels_armv6; + c->diff_pixels = ff_diff_pixels_armv6; + + c->pix_abs[0][0] = ff_pix_abs16_armv6; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_neon.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_neon.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_neon.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_neon.c 2012-05-14 14:08:53.409321366 +0200 +@@ -53,7 +53,19 @@ + void ff_put_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); + + void ff_avg_pixels16_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_x2_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_y2_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_xy2_neon(uint8_t *, const uint8_t *, int, int); + void ff_avg_pixels8_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_x2_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_y2_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_xy2_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); ++void ff_avg_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int); + + void ff_add_pixels_clamped_neon(const DCTELEM *, uint8_t *, int); + void ff_put_pixels_clamped_neon(const DCTELEM *, uint8_t *, int); +@@ -143,14 +155,8 @@ + const float *src1, const float *win, int len); + void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul, + int len); +-void ff_vector_fmul_sv_scalar_2_neon(float *dst, const float *src, +- const float **vp, float mul, int len); +-void ff_vector_fmul_sv_scalar_4_neon(float *dst, const float *src, +- const float **vp, float mul, int len); +-void ff_sv_fmul_scalar_2_neon(float *dst, const float **vp, float mul, +- int len); +-void ff_sv_fmul_scalar_4_neon(float *dst, const float **vp, float mul, +- int len); ++void ff_vector_fmac_scalar_neon(float *dst, const float *src, float mul, ++ int len); + void ff_butterflies_float_neon(float *v1, float *v2, int len); + float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len); + void ff_vector_fmul_reverse_neon(float *dst, const float *src0, +@@ -160,6 +166,8 @@ + + void ff_vector_clipf_neon(float *dst, const float *src, float min, float max, + int len); ++void ff_vector_clip_int32_neon(int32_t *dst, const int32_t *src, int32_t min, ++ int32_t max, unsigned int len); + + void ff_vorbis_inverse_coupling_neon(float *mag, float *ang, int blocksize); + +@@ -168,9 +176,14 @@ + int32_t ff_scalarproduct_and_madd_int16_neon(int16_t *v1, const int16_t *v2, + const int16_t *v3, int len, int mul); + ++void ff_apply_window_int16_neon(int16_t *dst, const int16_t *src, ++ const int16_t *window, unsigned n); ++ + void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx) + { +- if (!avctx->lowres) { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ ++ if (!avctx->lowres && avctx->bits_per_raw_sample <= 8) { + if (avctx->idct_algo == FF_IDCT_AUTO || + avctx->idct_algo == FF_IDCT_SIMPLENEON) { + c->idct_put = ff_simple_idct_put_neon; +@@ -187,35 +200,52 @@ + } + } + +- c->clear_block = ff_clear_block_neon; +- c->clear_blocks = ff_clear_blocks_neon; +- +- c->put_pixels_tab[0][0] = ff_put_pixels16_neon; +- c->put_pixels_tab[0][1] = ff_put_pixels16_x2_neon; +- c->put_pixels_tab[0][2] = ff_put_pixels16_y2_neon; +- c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_neon; +- c->put_pixels_tab[1][0] = ff_put_pixels8_neon; +- c->put_pixels_tab[1][1] = ff_put_pixels8_x2_neon; +- c->put_pixels_tab[1][2] = ff_put_pixels8_y2_neon; +- c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_neon; +- +- c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_neon; +- c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_neon; +- c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_neon; +- c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_neon; +- c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_neon; +- c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_neon; +- c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_neon; +- c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_neon; +- +- c->avg_pixels_tab[0][0] = ff_avg_pixels16_neon; +- c->avg_pixels_tab[1][0] = ff_avg_pixels8_neon; ++ if (!high_bit_depth) { ++ c->clear_block = ff_clear_block_neon; ++ c->clear_blocks = ff_clear_blocks_neon; ++ ++ c->put_pixels_tab[0][0] = ff_put_pixels16_neon; ++ c->put_pixels_tab[0][1] = ff_put_pixels16_x2_neon; ++ c->put_pixels_tab[0][2] = ff_put_pixels16_y2_neon; ++ c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_neon; ++ c->put_pixels_tab[1][0] = ff_put_pixels8_neon; ++ c->put_pixels_tab[1][1] = ff_put_pixels8_x2_neon; ++ c->put_pixels_tab[1][2] = ff_put_pixels8_y2_neon; ++ c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_neon; ++ ++ c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_neon; ++ c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_neon; ++ c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_neon; ++ c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_neon; ++ c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_neon; ++ c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_neon; ++ c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_neon; ++ c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_neon; ++ ++ c->avg_pixels_tab[0][0] = ff_avg_pixels16_neon; ++ c->avg_pixels_tab[0][1] = ff_avg_pixels16_x2_neon; ++ c->avg_pixels_tab[0][2] = ff_avg_pixels16_y2_neon; ++ c->avg_pixels_tab[0][3] = ff_avg_pixels16_xy2_neon; ++ c->avg_pixels_tab[1][0] = ff_avg_pixels8_neon; ++ c->avg_pixels_tab[1][1] = ff_avg_pixels8_x2_neon; ++ c->avg_pixels_tab[1][2] = ff_avg_pixels8_y2_neon; ++ c->avg_pixels_tab[1][3] = ff_avg_pixels8_xy2_neon; ++ ++ c->avg_no_rnd_pixels_tab[0][0] = ff_avg_pixels16_neon; ++ c->avg_no_rnd_pixels_tab[0][1] = ff_avg_pixels16_x2_no_rnd_neon; ++ c->avg_no_rnd_pixels_tab[0][2] = ff_avg_pixels16_y2_no_rnd_neon; ++ c->avg_no_rnd_pixels_tab[0][3] = ff_avg_pixels16_xy2_no_rnd_neon; ++ c->avg_no_rnd_pixels_tab[1][0] = ff_avg_pixels8_neon; ++ c->avg_no_rnd_pixels_tab[1][1] = ff_avg_pixels8_x2_no_rnd_neon; ++ c->avg_no_rnd_pixels_tab[1][2] = ff_avg_pixels8_y2_no_rnd_neon; ++ c->avg_no_rnd_pixels_tab[1][3] = ff_avg_pixels8_xy2_no_rnd_neon; ++ } + + c->add_pixels_clamped = ff_add_pixels_clamped_neon; + c->put_pixels_clamped = ff_put_pixels_clamped_neon; + c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_neon; + +- if (CONFIG_H264_DECODER) { ++ if (CONFIG_H264_DECODER && !high_bit_depth) { + c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_neon; + c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_neon; + c->put_h264_chroma_pixels_tab[2] = ff_put_h264_chroma_mc2_neon; +@@ -302,21 +332,19 @@ + c->vector_fmul = ff_vector_fmul_neon; + c->vector_fmul_window = ff_vector_fmul_window_neon; + c->vector_fmul_scalar = ff_vector_fmul_scalar_neon; ++ c->vector_fmac_scalar = ff_vector_fmac_scalar_neon; + c->butterflies_float = ff_butterflies_float_neon; + c->scalarproduct_float = ff_scalarproduct_float_neon; + c->vector_fmul_reverse = ff_vector_fmul_reverse_neon; + c->vector_fmul_add = ff_vector_fmul_add_neon; + c->vector_clipf = ff_vector_clipf_neon; +- +- c->vector_fmul_sv_scalar[0] = ff_vector_fmul_sv_scalar_2_neon; +- c->vector_fmul_sv_scalar[1] = ff_vector_fmul_sv_scalar_4_neon; +- +- c->sv_fmul_scalar[0] = ff_sv_fmul_scalar_2_neon; +- c->sv_fmul_scalar[1] = ff_sv_fmul_scalar_4_neon; ++ c->vector_clip_int32 = ff_vector_clip_int32_neon; + + if (CONFIG_VORBIS_DECODER) + c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_neon; + + c->scalarproduct_int16 = ff_scalarproduct_int16_neon; + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_neon; ++ ++ c->apply_window_int16 = ff_apply_window_int16_neon; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_vfp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_vfp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_init_vfp.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_init_vfp.c 2012-05-14 14:08:53.409321366 +0200 +@@ -28,6 +28,7 @@ + + void ff_dsputil_init_vfp(DSPContext* c, AVCodecContext *avctx) + { +- c->vector_fmul = ff_vector_fmul_vfp; ++ if (!HAVE_VFPV3) ++ c->vector_fmul = ff_vector_fmul_vfp; + c->vector_fmul_reverse = ff_vector_fmul_reverse_vfp; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_iwmmxt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_iwmmxt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_iwmmxt.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_iwmmxt.c 2012-05-14 14:08:53.410321386 +0200 +@@ -155,6 +155,7 @@ + void ff_dsputil_init_iwmmxt(DSPContext* c, AVCodecContext *avctx) + { + int mm_flags = AV_CPU_FLAG_IWMMXT; /* multimedia extension flags */ ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; + + if (avctx->dsp_mask) { + if (avctx->dsp_mask & AV_CPU_FLAG_FORCE) +@@ -167,6 +168,7 @@ + + c->add_pixels_clamped = add_pixels_clamped_iwmmxt; + ++ if (!high_bit_depth) { + c->clear_blocks = clear_blocks_iwmmxt; + + c->put_pixels_tab[0][0] = put_pixels16_iwmmxt; +@@ -204,4 +206,5 @@ + c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x2_iwmmxt; + c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y2_iwmmxt; + c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy2_iwmmxt; ++ } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_neon.S 2012-05-14 14:08:53.412321426 +0200 +@@ -23,7 +23,6 @@ + #include "asm.S" + + preserve8 +- .text + + function ff_clear_block_neon, export=1 + vmov.i16 q0, #0 +@@ -41,75 +40,89 @@ + bx lr + endfunc + +- .macro pixels16 avg=0 +-.if \avg +- mov ip, r0 +-.endif +-1: vld1.64 {d0, d1}, [r1], r2 +- vld1.64 {d2, d3}, [r1], r2 +- vld1.64 {d4, d5}, [r1], r2 ++.macro pixels16 rnd=1, avg=0 ++ .if \avg ++ mov r12, r0 ++ .endif ++1: vld1.64 {q0}, [r1], r2 ++ vld1.64 {q1}, [r1], r2 ++ vld1.64 {q2}, [r1], r2 + pld [r1, r2, lsl #2] +- vld1.64 {d6, d7}, [r1], r2 ++ vld1.64 {q3}, [r1], r2 + pld [r1] + pld [r1, r2] + pld [r1, r2, lsl #1] +-.if \avg +- vld1.64 {d16,d17}, [ip,:128], r2 ++ .if \avg ++ vld1.64 {q8}, [r12,:128], r2 + vrhadd.u8 q0, q0, q8 +- vld1.64 {d18,d19}, [ip,:128], r2 ++ vld1.64 {q9}, [r12,:128], r2 + vrhadd.u8 q1, q1, q9 +- vld1.64 {d20,d21}, [ip,:128], r2 ++ vld1.64 {q10}, [r12,:128], r2 + vrhadd.u8 q2, q2, q10 +- vld1.64 {d22,d23}, [ip,:128], r2 ++ vld1.64 {q11}, [r12,:128], r2 + vrhadd.u8 q3, q3, q11 +-.endif ++ .endif + subs r3, r3, #4 +- vst1.64 {d0, d1}, [r0,:128], r2 +- vst1.64 {d2, d3}, [r0,:128], r2 +- vst1.64 {d4, d5}, [r0,:128], r2 +- vst1.64 {d6, d7}, [r0,:128], r2 ++ vst1.64 {q0}, [r0,:128], r2 ++ vst1.64 {q1}, [r0,:128], r2 ++ vst1.64 {q2}, [r0,:128], r2 ++ vst1.64 {q3}, [r0,:128], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels16_x2 vhadd=vrhadd.u8 +-1: vld1.64 {d0-d2}, [r1], r2 +- vld1.64 {d4-d6}, [r1], r2 ++.macro pixels16_x2 rnd=1, avg=0 ++1: vld1.64 {d0-d2}, [r1], r2 ++ vld1.64 {d4-d6}, [r1], r2 + pld [r1] + pld [r1, r2] + subs r3, r3, #2 + vext.8 q1, q0, q1, #1 +- \vhadd q0, q0, q1 ++ avg q0, q0, q1 + vext.8 q3, q2, q3, #1 +- \vhadd q2, q2, q3 +- vst1.64 {d0, d1}, [r0,:128], r2 +- vst1.64 {d4, d5}, [r0,:128], r2 ++ avg q2, q2, q3 ++ .if \avg ++ vld1.8 {q1}, [r0,:128], r2 ++ vld1.8 {q3}, [r0,:128] ++ vrhadd.u8 q0, q0, q1 ++ vrhadd.u8 q2, q2, q3 ++ sub r0, r0, r2 ++ .endif ++ vst1.64 {q0}, [r0,:128], r2 ++ vst1.64 {q2}, [r0,:128], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels16_y2 vhadd=vrhadd.u8 +- vld1.64 {d0, d1}, [r1], r2 +- vld1.64 {d2, d3}, [r1], r2 ++.macro pixels16_y2 rnd=1, avg=0 ++ vld1.64 {q0}, [r1], r2 ++ vld1.64 {q1}, [r1], r2 + 1: subs r3, r3, #2 +- \vhadd q2, q0, q1 +- vld1.64 {d0, d1}, [r1], r2 +- \vhadd q3, q0, q1 +- vld1.64 {d2, d3}, [r1], r2 ++ avg q2, q0, q1 ++ vld1.64 {q0}, [r1], r2 ++ avg q3, q0, q1 ++ vld1.64 {q1}, [r1], r2 + pld [r1] + pld [r1, r2] +- vst1.64 {d4, d5}, [r0,:128], r2 +- vst1.64 {d6, d7}, [r0,:128], r2 ++ .if \avg ++ vld1.8 {q8}, [r0,:128], r2 ++ vld1.8 {q9}, [r0,:128] ++ vrhadd.u8 q2, q2, q8 ++ vrhadd.u8 q3, q3, q9 ++ sub r0, r0, r2 ++ .endif ++ vst1.64 {q2}, [r0,:128], r2 ++ vst1.64 {q3}, [r0,:128], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels16_xy2 vshrn=vrshrn.u16 no_rnd=0 +- vld1.64 {d0-d2}, [r1], r2 +- vld1.64 {d4-d6}, [r1], r2 +-.if \no_rnd ++.macro pixels16_xy2 rnd=1, avg=0 ++ vld1.64 {d0-d2}, [r1], r2 ++ vld1.64 {d4-d6}, [r1], r2 ++ .ifeq \rnd + vmov.i16 q13, #1 +-.endif ++ .endif + pld [r1] + pld [r1, r2] + vext.8 q1, q0, q1, #1 +@@ -119,109 +132,129 @@ + vaddl.u8 q9, d4, d6 + vaddl.u8 q11, d5, d7 + 1: subs r3, r3, #2 +- vld1.64 {d0-d2}, [r1], r2 ++ vld1.64 {d0-d2}, [r1], r2 + vadd.u16 q12, q8, q9 + pld [r1] +-.if \no_rnd ++ .ifeq \rnd + vadd.u16 q12, q12, q13 +-.endif ++ .endif + vext.8 q15, q0, q1, #1 + vadd.u16 q1 , q10, q11 +- \vshrn d28, q12, #2 +-.if \no_rnd ++ shrn d28, q12, #2 ++ .ifeq \rnd + vadd.u16 q1, q1, q13 +-.endif +- \vshrn d29, q1, #2 ++ .endif ++ shrn d29, q1, #2 ++ .if \avg ++ vld1.8 {q8}, [r0,:128] ++ vrhadd.u8 q14, q14, q8 ++ .endif + vaddl.u8 q8, d0, d30 +- vld1.64 {d2-d4}, [r1], r2 ++ vld1.64 {d2-d4}, [r1], r2 + vaddl.u8 q10, d1, d31 +- vst1.64 {d28,d29}, [r0,:128], r2 ++ vst1.64 {q14}, [r0,:128], r2 + vadd.u16 q12, q8, q9 + pld [r1, r2] +-.if \no_rnd ++ .ifeq \rnd + vadd.u16 q12, q12, q13 +-.endif ++ .endif + vext.8 q2, q1, q2, #1 + vadd.u16 q0, q10, q11 +- \vshrn d30, q12, #2 +-.if \no_rnd ++ shrn d30, q12, #2 ++ .ifeq \rnd + vadd.u16 q0, q0, q13 +-.endif +- \vshrn d31, q0, #2 ++ .endif ++ shrn d31, q0, #2 ++ .if \avg ++ vld1.8 {q9}, [r0,:128] ++ vrhadd.u8 q15, q15, q9 ++ .endif + vaddl.u8 q9, d2, d4 + vaddl.u8 q11, d3, d5 +- vst1.64 {d30,d31}, [r0,:128], r2 ++ vst1.64 {q15}, [r0,:128], r2 + bgt 1b + bx lr +- .endm ++.endm + +- .macro pixels8 avg=0 +-1: vld1.64 {d0}, [r1], r2 +- vld1.64 {d1}, [r1], r2 +- vld1.64 {d2}, [r1], r2 ++.macro pixels8 rnd=1, avg=0 ++1: vld1.64 {d0}, [r1], r2 ++ vld1.64 {d1}, [r1], r2 ++ vld1.64 {d2}, [r1], r2 + pld [r1, r2, lsl #2] +- vld1.64 {d3}, [r1], r2 ++ vld1.64 {d3}, [r1], r2 + pld [r1] + pld [r1, r2] + pld [r1, r2, lsl #1] +-.if \avg +- vld1.64 {d4}, [r0,:64], r2 ++ .if \avg ++ vld1.64 {d4}, [r0,:64], r2 + vrhadd.u8 d0, d0, d4 +- vld1.64 {d5}, [r0,:64], r2 ++ vld1.64 {d5}, [r0,:64], r2 + vrhadd.u8 d1, d1, d5 +- vld1.64 {d6}, [r0,:64], r2 ++ vld1.64 {d6}, [r0,:64], r2 + vrhadd.u8 d2, d2, d6 +- vld1.64 {d7}, [r0,:64], r2 ++ vld1.64 {d7}, [r0,:64], r2 + vrhadd.u8 d3, d3, d7 + sub r0, r0, r2, lsl #2 +-.endif ++ .endif + subs r3, r3, #4 +- vst1.64 {d0}, [r0,:64], r2 +- vst1.64 {d1}, [r0,:64], r2 +- vst1.64 {d2}, [r0,:64], r2 +- vst1.64 {d3}, [r0,:64], r2 ++ vst1.64 {d0}, [r0,:64], r2 ++ vst1.64 {d1}, [r0,:64], r2 ++ vst1.64 {d2}, [r0,:64], r2 ++ vst1.64 {d3}, [r0,:64], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels8_x2 vhadd=vrhadd.u8 +-1: vld1.64 {d0, d1}, [r1], r2 ++.macro pixels8_x2 rnd=1, avg=0 ++1: vld1.64 {q0}, [r1], r2 + vext.8 d1, d0, d1, #1 +- vld1.64 {d2, d3}, [r1], r2 ++ vld1.64 {q1}, [r1], r2 + vext.8 d3, d2, d3, #1 + pld [r1] + pld [r1, r2] + subs r3, r3, #2 + vswp d1, d2 +- \vhadd q0, q0, q1 +- vst1.64 {d0}, [r0,:64], r2 +- vst1.64 {d1}, [r0,:64], r2 ++ avg q0, q0, q1 ++ .if \avg ++ vld1.8 {d4}, [r0,:64], r2 ++ vld1.8 {d5}, [r0,:64] ++ vrhadd.u8 q0, q0, q2 ++ sub r0, r0, r2 ++ .endif ++ vst1.64 {d0}, [r0,:64], r2 ++ vst1.64 {d1}, [r0,:64], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels8_y2 vhadd=vrhadd.u8 +- vld1.64 {d0}, [r1], r2 +- vld1.64 {d1}, [r1], r2 ++.macro pixels8_y2 rnd=1, avg=0 ++ vld1.64 {d0}, [r1], r2 ++ vld1.64 {d1}, [r1], r2 + 1: subs r3, r3, #2 +- \vhadd d4, d0, d1 +- vld1.64 {d0}, [r1], r2 +- \vhadd d5, d0, d1 +- vld1.64 {d1}, [r1], r2 ++ avg d4, d0, d1 ++ vld1.64 {d0}, [r1], r2 ++ avg d5, d0, d1 ++ vld1.64 {d1}, [r1], r2 + pld [r1] + pld [r1, r2] +- vst1.64 {d4}, [r0,:64], r2 +- vst1.64 {d5}, [r0,:64], r2 ++ .if \avg ++ vld1.8 {d2}, [r0,:64], r2 ++ vld1.8 {d3}, [r0,:64] ++ vrhadd.u8 q2, q2, q1 ++ sub r0, r0, r2 ++ .endif ++ vst1.64 {d4}, [r0,:64], r2 ++ vst1.64 {d5}, [r0,:64], r2 + bne 1b + bx lr +- .endm ++.endm + +- .macro pixels8_xy2 vshrn=vrshrn.u16 no_rnd=0 +- vld1.64 {d0, d1}, [r1], r2 +- vld1.64 {d2, d3}, [r1], r2 +-.if \no_rnd ++.macro pixels8_xy2 rnd=1, avg=0 ++ vld1.64 {q0}, [r1], r2 ++ vld1.64 {q1}, [r1], r2 ++ .ifeq \rnd + vmov.i16 q11, #1 +-.endif ++ .endif + pld [r1] + pld [r1, r2] + vext.8 d4, d0, d1, #1 +@@ -229,70 +262,101 @@ + vaddl.u8 q8, d0, d4 + vaddl.u8 q9, d2, d6 + 1: subs r3, r3, #2 +- vld1.64 {d0, d1}, [r1], r2 ++ vld1.64 {q0}, [r1], r2 + pld [r1] + vadd.u16 q10, q8, q9 + vext.8 d4, d0, d1, #1 +-.if \no_rnd ++ .ifeq \rnd + vadd.u16 q10, q10, q11 +-.endif ++ .endif + vaddl.u8 q8, d0, d4 +- \vshrn d5, q10, #2 +- vld1.64 {d2, d3}, [r1], r2 ++ shrn d5, q10, #2 ++ vld1.64 {q1}, [r1], r2 + vadd.u16 q10, q8, q9 + pld [r1, r2] +-.if \no_rnd ++ .if \avg ++ vld1.8 {d7}, [r0,:64] ++ vrhadd.u8 d5, d5, d7 ++ .endif ++ .ifeq \rnd + vadd.u16 q10, q10, q11 +-.endif +- vst1.64 {d5}, [r0,:64], r2 +- \vshrn d7, q10, #2 ++ .endif ++ vst1.64 {d5}, [r0,:64], r2 ++ shrn d7, q10, #2 ++ .if \avg ++ vld1.8 {d5}, [r0,:64] ++ vrhadd.u8 d7, d7, d5 ++ .endif + vext.8 d6, d2, d3, #1 + vaddl.u8 q9, d2, d6 +- vst1.64 {d7}, [r0,:64], r2 ++ vst1.64 {d7}, [r0,:64], r2 + bgt 1b + bx lr +- .endm ++.endm + +- .macro pixfunc pfx name suf rnd_op args:vararg ++.macro pixfunc pfx, name, suf, rnd=1, avg=0 ++ .if \rnd ++ .macro avg rd, rn, rm ++ vrhadd.u8 \rd, \rn, \rm ++ .endm ++ .macro shrn rd, rn, rm ++ vrshrn.u16 \rd, \rn, \rm ++ .endm ++ .else ++ .macro avg rd, rn, rm ++ vhadd.u8 \rd, \rn, \rm ++ .endm ++ .macro shrn rd, rn, rm ++ vshrn.u16 \rd, \rn, \rm ++ .endm ++ .endif + function ff_\pfx\name\suf\()_neon, export=1 +- \name \rnd_op \args ++ \name \rnd, \avg + endfunc +- .endm +- +- .macro pixfunc2 pfx name args:vararg +- pixfunc \pfx \name +- pixfunc \pfx \name \args +- .endm ++ .purgem avg ++ .purgem shrn ++.endm ++ ++.macro pixfunc2 pfx, name, avg=0 ++ pixfunc \pfx, \name, rnd=1, avg=\avg ++ pixfunc \pfx, \name, _no_rnd, rnd=0, avg=\avg ++.endm + + function ff_put_h264_qpel16_mc00_neon, export=1 + mov r3, #16 + endfunc + +- pixfunc put_ pixels16 +- pixfunc2 put_ pixels16_x2, _no_rnd, vhadd.u8 +- pixfunc2 put_ pixels16_y2, _no_rnd, vhadd.u8 +- pixfunc2 put_ pixels16_xy2, _no_rnd, vshrn.u16, 1 ++ pixfunc put_, pixels16, avg=0 ++ pixfunc2 put_, pixels16_x2, avg=0 ++ pixfunc2 put_, pixels16_y2, avg=0 ++ pixfunc2 put_, pixels16_xy2, avg=0 + + function ff_avg_h264_qpel16_mc00_neon, export=1 + mov r3, #16 + endfunc + +- pixfunc avg_ pixels16,, 1 ++ pixfunc avg_, pixels16, avg=1 ++ pixfunc2 avg_, pixels16_x2, avg=1 ++ pixfunc2 avg_, pixels16_y2, avg=1 ++ pixfunc2 avg_, pixels16_xy2, avg=1 + + function ff_put_h264_qpel8_mc00_neon, export=1 + mov r3, #8 + endfunc + +- pixfunc put_ pixels8 +- pixfunc2 put_ pixels8_x2, _no_rnd, vhadd.u8 +- pixfunc2 put_ pixels8_y2, _no_rnd, vhadd.u8 +- pixfunc2 put_ pixels8_xy2, _no_rnd, vshrn.u16, 1 ++ pixfunc put_, pixels8, avg=0 ++ pixfunc2 put_, pixels8_x2, avg=0 ++ pixfunc2 put_, pixels8_y2, avg=0 ++ pixfunc2 put_, pixels8_xy2, avg=0 + + function ff_avg_h264_qpel8_mc00_neon, export=1 + mov r3, #8 + endfunc + +- pixfunc avg_ pixels8,, 1 ++ pixfunc avg_, pixels8, avg=1 ++ pixfunc2 avg_, pixels8_x2, avg=1 ++ pixfunc2 avg_, pixels8_y2, avg=1 ++ pixfunc2 avg_, pixels8_xy2, avg=1 + + function ff_put_pixels_clamped_neon, export=1 + vld1.64 {d16-d19}, [r0,:128]! +@@ -531,6 +595,7 @@ + + 2: vst1.32 {d2-d3}, [r3, :128]! + vst1.32 {d0-d1}, [r12,:128]! ++ it lt + bxlt lr + + 3: vld1.32 {d2-d3}, [r1,:128] +@@ -575,6 +640,7 @@ + 2: vst1.32 {q2},[r0,:128]! + vst1.32 {q3},[r0,:128]! + ands len, len, #15 ++ it eq + bxeq lr + 3: vld1.32 {q0},[r1,:128]! + vmul.f32 q0, q0, q8 +@@ -585,105 +651,50 @@ + .unreq len + endfunc + +-function ff_vector_fmul_sv_scalar_2_neon, export=1 +-VFP vdup.32 d16, d0[0] +-NOVFP vdup.32 d16, r3 +-NOVFP ldr r3, [sp] +- vld1.32 {d0},[r1,:64]! +- vld1.32 {d1},[r1,:64]! +-1: subs r3, r3, #4 +- vmul.f32 d4, d0, d16 +- vmul.f32 d5, d1, d16 +- ldr r12, [r2], #4 +- vld1.32 {d2},[r12,:64] +- ldr r12, [r2], #4 +- vld1.32 {d3},[r12,:64] +- vmul.f32 d4, d4, d2 +- vmul.f32 d5, d5, d3 +- beq 2f +- vld1.32 {d0},[r1,:64]! +- vld1.32 {d1},[r1,:64]! +- vst1.32 {d4},[r0,:64]! +- vst1.32 {d5},[r0,:64]! +- b 1b +-2: vst1.32 {d4},[r0,:64]! +- vst1.32 {d5},[r0,:64]! +- bx lr +-endfunc +- +-function ff_vector_fmul_sv_scalar_4_neon, export=1 +-VFP vdup.32 q10, d0[0] +-NOVFP vdup.32 q10, r3 +-NOVFP ldr r3, [sp] +- push {lr} +- bics lr, r3, #7 +- beq 3f +- vld1.32 {q0},[r1,:128]! +- vld1.32 {q2},[r1,:128]! +-1: ldr r12, [r2], #4 +- vld1.32 {q1},[r12,:128] +- ldr r12, [r2], #4 +- vld1.32 {q3},[r12,:128] +- vmul.f32 q8, q0, q10 +- vmul.f32 q8, q8, q1 +- vmul.f32 q9, q2, q10 +- vmul.f32 q9, q9, q3 +- subs lr, lr, #8 +- beq 2f +- vld1.32 {q0},[r1,:128]! +- vld1.32 {q2},[r1,:128]! +- vst1.32 {q8},[r0,:128]! +- vst1.32 {q9},[r0,:128]! +- b 1b +-2: vst1.32 {q8},[r0,:128]! +- vst1.32 {q9},[r0,:128]! +- ands r3, r3, #7 +- popeq {pc} +-3: vld1.32 {q0},[r1,:128]! +- ldr r12, [r2], #4 +- vld1.32 {q1},[r12,:128] +- vmul.f32 q0, q0, q10 +- vmul.f32 q0, q0, q1 +- vst1.32 {q0},[r0,:128]! +- subs r3, r3, #4 +- bgt 3b +- pop {pc} +-endfunc +- +-function ff_sv_fmul_scalar_2_neon, export=1 ++function ff_vector_fmac_scalar_neon, export=1 + VFP len .req r2 ++VFP acc .req r3 + NOVFP len .req r3 +-VFP vdup.32 q8, d0[0] +-NOVFP vdup.32 q8, r2 +- ldr r12, [r1], #4 +- vld1.32 {d0},[r12,:64] +- ldr r12, [r1], #4 +- vld1.32 {d1},[r12,:64] +-1: vmul.f32 q1, q0, q8 +- subs len, len, #4 ++NOVFP acc .req r2 ++VFP vdup.32 q15, d0[0] ++NOVFP vdup.32 q15, r2 ++ bics r12, len, #15 ++ mov acc, r0 ++ beq 3f ++ vld1.32 {q0}, [r1,:128]! ++ vld1.32 {q8}, [acc,:128]! ++ vld1.32 {q1}, [r1,:128]! ++ vld1.32 {q9}, [acc,:128]! ++1: vmla.f32 q8, q0, q15 ++ vld1.32 {q2}, [r1,:128]! ++ vld1.32 {q10}, [acc,:128]! ++ vmla.f32 q9, q1, q15 ++ vld1.32 {q3}, [r1,:128]! ++ vld1.32 {q11}, [acc,:128]! ++ vmla.f32 q10, q2, q15 ++ vst1.32 {q8}, [r0,:128]! ++ vmla.f32 q11, q3, q15 ++ vst1.32 {q9}, [r0,:128]! ++ subs r12, r12, #16 + beq 2f +- ldr r12, [r1], #4 +- vld1.32 {d0},[r12,:64] +- ldr r12, [r1], #4 +- vld1.32 {d1},[r12,:64] +- vst1.32 {q1},[r0,:128]! ++ vld1.32 {q0}, [r1,:128]! ++ vld1.32 {q8}, [acc,:128]! ++ vst1.32 {q10}, [r0,:128]! ++ vld1.32 {q1}, [r1,:128]! ++ vld1.32 {q9}, [acc,:128]! ++ vst1.32 {q11}, [r0,:128]! + b 1b +-2: vst1.32 {q1},[r0,:128]! +- bx lr +- .unreq len +-endfunc +- +-function ff_sv_fmul_scalar_4_neon, export=1 +-VFP len .req r2 +-NOVFP len .req r3 +-VFP vdup.32 q8, d0[0] +-NOVFP vdup.32 q8, r2 +-1: ldr r12, [r1], #4 +- vld1.32 {q0},[r12,:128] +- vmul.f32 q0, q0, q8 +- vst1.32 {q0},[r0,:128]! ++2: vst1.32 {q10}, [r0,:128]! ++ vst1.32 {q11}, [r0,:128]! ++ ands len, len, #15 ++ it eq ++ bxeq lr ++3: vld1.32 {q0}, [r1,:128]! ++ vld1.32 {q8}, [acc,:128]! ++ vmla.f32 q8, q0, q15 ++ vst1.32 {q8}, [r0,:128]! + subs len, len, #4 +- bgt 1b ++ bgt 3b + bx lr + .unreq len + endfunc +@@ -789,3 +800,42 @@ + vst1.f32 {q9},[r0,:128]! + bx lr + endfunc ++ ++function ff_apply_window_int16_neon, export=1 ++ push {r4,lr} ++ add r4, r1, r3, lsl #1 ++ add lr, r0, r3, lsl #1 ++ sub r4, r4, #16 ++ sub lr, lr, #16 ++ mov r12, #-16 ++1: ++ vld1.16 {q0}, [r1,:128]! ++ vld1.16 {q2}, [r2,:128]! ++ vld1.16 {q1}, [r4,:128], r12 ++ vrev64.16 q3, q2 ++ vqrdmulh.s16 q0, q0, q2 ++ vqrdmulh.s16 d2, d2, d7 ++ vqrdmulh.s16 d3, d3, d6 ++ vst1.16 {q0}, [r0,:128]! ++ vst1.16 {q1}, [lr,:128], r12 ++ subs r3, r3, #16 ++ bgt 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_vector_clip_int32_neon, export=1 ++ vdup.32 q0, r2 ++ vdup.32 q1, r3 ++ ldr r2, [sp] ++1: ++ vld1.32 {q2-q3}, [r1,:128]! ++ vmin.s32 q2, q2, q1 ++ vmin.s32 q3, q3, q1 ++ vmax.s32 q2, q2, q0 ++ vmax.s32 q3, q3, q0 ++ vst1.32 {q2-q3}, [r0,:128]! ++ subs r2, r2, #8 ++ bgt 1b ++ bx lr ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_vfp.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_vfp.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/dsputil_vfp.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/dsputil_vfp.S 2012-05-14 14:08:53.413321446 +0200 +@@ -21,7 +21,6 @@ + #include "config.h" + #include "asm.S" + +- .syntax unified + /* + * VFP is a floating point coprocessor used in some ARM cores. VFP11 has 1 cycle + * throughput for almost all the instructions (except for double precision +@@ -56,18 +55,23 @@ + 1: + subs r3, r3, #16 + vmul.f32 s12, s4, s12 ++ itttt ge + vldmiage r1!, {s16-s19} + vldmiage r2!, {s24-s27} + vldmiage r1!, {s20-s23} + vldmiage r2!, {s28-s31} ++ it ge + vmulge.f32 s24, s16, s24 + vstmia r0!, {s8-s11} + vstmia r0!, {s12-s15} ++ it ge + vmulge.f32 s28, s20, s28 ++ itttt gt + vldmiagt r1!, {s0-s3} + vldmiagt r2!, {s8-s11} + vldmiagt r1!, {s4-s7} + vldmiagt r2!, {s12-s15} ++ ittt ge + vmulge.f32 s8, s0, s8 + vstmiage r0!, {s24-s27} + vstmiage r0!, {s28-s31} +@@ -98,33 +102,49 @@ + vmul.f32 s11, s0, s11 + 1: + subs r3, r3, #16 ++ it ge + vldmdbge r2!, {s16-s19} + vmul.f32 s12, s7, s12 ++ it ge + vldmiage r1!, {s24-s27} + vmul.f32 s13, s6, s13 ++ it ge + vldmdbge r2!, {s20-s23} + vmul.f32 s14, s5, s14 ++ it ge + vldmiage r1!, {s28-s31} + vmul.f32 s15, s4, s15 ++ it ge + vmulge.f32 s24, s19, s24 ++ it gt + vldmdbgt r2!, {s0-s3} ++ it ge + vmulge.f32 s25, s18, s25 + vstmia r0!, {s8-s13} ++ it ge + vmulge.f32 s26, s17, s26 ++ it gt + vldmiagt r1!, {s8-s11} ++ itt ge + vmulge.f32 s27, s16, s27 + vmulge.f32 s28, s23, s28 ++ it gt + vldmdbgt r2!, {s4-s7} ++ it ge + vmulge.f32 s29, s22, s29 + vstmia r0!, {s14-s15} ++ ittt ge + vmulge.f32 s30, s21, s30 + vmulge.f32 s31, s20, s31 + vmulge.f32 s8, s3, s8 ++ it gt + vldmiagt r1!, {s12-s15} ++ itttt ge + vmulge.f32 s9, s2, s9 + vmulge.f32 s10, s1, s10 + vstmiage r0!, {s24-s27} + vmulge.f32 s11, s0, s11 ++ it ge + vstmiage r0!, {s28-s31} + bgt 1b + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_fixed_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_fixed_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_fixed_init_arm.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_fixed_init_arm.c 2012-05-14 14:08:53.414321466 +0200 +@@ -0,0 +1,42 @@ ++/* ++ * Copyright (c) 2009 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFMpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FFT_FLOAT 0 ++#include "libavcodec/fft.h" ++ ++void ff_fft_fixed_calc_neon(FFTContext *s, FFTComplex *z); ++void ff_mdct_fixed_calc_neon(FFTContext *s, FFTSample *o, const FFTSample *i); ++void ff_mdct_fixed_calcw_neon(FFTContext *s, FFTDouble *o, const FFTSample *i); ++ ++av_cold void ff_fft_fixed_init_arm(FFTContext *s) ++{ ++ if (HAVE_NEON) { ++ s->fft_permutation = FF_FFT_PERM_SWAP_LSBS; ++ s->fft_calc = ff_fft_fixed_calc_neon; ++ ++#if CONFIG_MDCT ++ if (!s->inverse && s->mdct_bits >= 5) { ++ s->mdct_permutation = FF_MDCT_PERM_INTERLEAVE; ++ s->mdct_calc = ff_mdct_fixed_calc_neon; ++ s->mdct_calcw = ff_mdct_fixed_calcw_neon; ++ } ++#endif ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_fixed_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_fixed_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_fixed_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_fixed_neon.S 2012-05-14 14:08:53.415321486 +0200 +@@ -0,0 +1,261 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++.macro bflies d0, d1, r0, r1 ++ vrev64.32 \r0, \d1 @ t5, t6, t1, t2 ++ vhsub.s16 \r1, \d1, \r0 @ t1-t5, t2-t6, t5-t1, t6-t2 ++ vhadd.s16 \r0, \d1, \r0 @ t1+t5, t2+t6, t5+t1, t6+t2 ++ vext.16 \r1, \r1, \r1, #1 @ t2-t6, t5-t1, t6-t2, t1-t5 ++ vtrn.32 \r0, \r1 @ t1+t5, t2+t6, t2-t6, t5-t1 ++ @ t5, t6, t4, t3 ++ vhsub.s16 \d1, \d0, \r0 ++ vhadd.s16 \d0, \d0, \r0 ++.endm ++ ++.macro transform01 q0, q1, d3, c0, c1, r0, w0, w1 ++ vrev32.16 \r0, \d3 ++ vmull.s16 \w0, \d3, \c0 ++ vmlal.s16 \w0, \r0, \c1 ++ vshrn.s32 \d3, \w0, #15 ++ bflies \q0, \q1, \w0, \w1 ++.endm ++ ++.macro transform2 d0, d1, d2, d3, q0, q1, c0, c1, c2, c3, \ ++ r0, r1, w0, w1 ++ vrev32.16 \r0, \d1 ++ vrev32.16 \r1, \d3 ++ vmull.s16 \w0, \d1, \c0 ++ vmlal.s16 \w0, \r0, \c1 ++ vmull.s16 \w1, \d3, \c2 ++ vmlal.s16 \w1, \r1, \c3 ++ vshrn.s32 \d1, \w0, #15 ++ vshrn.s32 \d3, \w1, #15 ++ bflies \q0, \q1, \w0, \w1 ++.endm ++ ++.macro fft4 d0, d1, r0, r1 ++ vhsub.s16 \r0, \d0, \d1 @ t3, t4, t8, t7 ++ vhsub.s16 \r1, \d1, \d0 ++ vhadd.s16 \d0, \d0, \d1 @ t1, t2, t6, t5 ++ vmov.i64 \d1, #0xffff00000000 ++ vbit \r0, \r1, \d1 ++ vrev64.16 \r1, \r0 @ t7, t8, t4, t3 ++ vtrn.32 \r0, \r1 @ t3, t4, t7, t8 ++ vtrn.32 \d0, \r0 @ t1, t2, t3, t4, t6, t5, t8, t7 ++ vhsub.s16 \d1, \d0, \r0 @ r2, i2, r3, i1 ++ vhadd.s16 \d0, \d0, \r0 @ r0, i0, r1, i3 ++.endm ++ ++.macro fft8 d0, d1, d2, d3, q0, q1, c0, c1, r0, r1, w0, w1 ++ fft4 \d0, \d1, \r0, \r1 ++ vtrn.32 \d0, \d1 @ z0, z2, z1, z3 ++ vhadd.s16 \r0, \d2, \d3 @ t1, t2, t3, t4 ++ vhsub.s16 \d3, \d2, \d3 @ z5, z7 ++ vmov \d2, \r0 ++ transform01 \q0, \q1, \d3, \c0, \c1, \r0, \w0, \w1 ++.endm ++ ++function fft4_neon ++ vld1.16 {d0-d1}, [r0] ++ fft4 d0, d1, d2, d3 ++ vst1.16 {d0-d1}, [r0] ++ bx lr ++endfunc ++ ++function fft8_neon ++ vld1.16 {d0-d3}, [r0,:128] ++ movrel r1, coefs ++ vld1.16 {d30}, [r1,:64] ++ vdup.16 d31, d30[0] ++ fft8 d0, d1, d2, d3, q0, q1, d31, d30, d20, d21, q8, q9 ++ vtrn.32 d0, d1 ++ vtrn.32 d2, d3 ++ vst1.16 {d0-d3}, [r0,:128] ++ bx lr ++endfunc ++ ++function fft16_neon ++ vld1.16 {d0-d3}, [r0,:128]! ++ vld1.16 {d4-d7}, [r0,:128] ++ movrel r1, coefs ++ sub r0, r0, #32 ++ vld1.16 {d28-d31},[r1,:128] ++ vdup.16 d31, d28[0] ++ fft8 d0, d1, d2, d3, q0, q1, d31, d28, d20, d21, q8, q9 ++ vswp d5, d6 ++ fft4 q2, q3, q8, q9 ++ vswp d5, d6 ++ vtrn.32 q0, q1 @ z0, z4, z2, z6, z1, z5, z3, z7 ++ vtrn.32 q2, q3 @ z8, z12,z10,z14,z9, z13,z11,z15 ++ vswp d1, d2 ++ vdup.16 d31, d28[0] ++ transform01 q0, q2, d5, d31, d28, d20, q8, q9 ++ vdup.16 d26, d29[0] ++ vdup.16 d27, d30[0] ++ transform2 d2, d6, d3, d7, q1, q3, d26, d30, d27, d29, \ ++ d20, d21, q8, q9 ++ vtrn.32 q0, q1 ++ vtrn.32 q2, q3 ++ vst1.16 {d0-d3}, [r0,:128]! ++ vst1.16 {d4-d7}, [r0,:128] ++ bx lr ++endfunc ++ ++function fft_pass_neon ++ push {r4,lr} ++ movrel lr, coefs+24 ++ vld1.16 {d30}, [lr,:64] ++ lsl r12, r2, #3 ++ vmov d31, d30 ++ add r3, r1, r2, lsl #2 ++ mov lr, #-8 ++ sub r3, r3, #2 ++ mov r4, r0 ++ vld1.16 {d27[]}, [r3,:16] ++ sub r3, r3, #6 ++ vld1.16 {q0}, [r4,:128], r12 ++ vld1.16 {q1}, [r4,:128], r12 ++ vld1.16 {q2}, [r4,:128], r12 ++ vld1.16 {q3}, [r4,:128], r12 ++ vld1.16 {d28}, [r1,:64]! ++ vld1.16 {d29}, [r3,:64], lr ++ vswp d1, d2 ++ vswp d5, d6 ++ vtrn.32 d0, d1 ++ vtrn.32 d4, d5 ++ vdup.16 d25, d28[1] ++ vmul.s16 d27, d27, d31 ++ transform01 q0, q2, d5, d25, d27, d20, q8, q9 ++ b 2f ++1: ++ mov r4, r0 ++ vdup.16 d26, d29[0] ++ vld1.16 {q0}, [r4,:128], r12 ++ vld1.16 {q1}, [r4,:128], r12 ++ vld1.16 {q2}, [r4,:128], r12 ++ vld1.16 {q3}, [r4,:128], r12 ++ vld1.16 {d28}, [r1,:64]! ++ vld1.16 {d29}, [r3,:64], lr ++ vswp d1, d2 ++ vswp d5, d6 ++ vtrn.32 d0, d1 ++ vtrn.32 d4, d5 ++ vdup.16 d24, d28[0] ++ vdup.16 d25, d28[1] ++ vdup.16 d27, d29[3] ++ vmul.s16 q13, q13, q15 ++ transform2 d0, d4, d1, d5, q0, q2, d24, d26, d25, d27, \ ++ d16, d17, q9, q10 ++2: ++ vtrn.32 d2, d3 ++ vtrn.32 d6, d7 ++ vdup.16 d24, d28[2] ++ vdup.16 d26, d29[2] ++ vdup.16 d25, d28[3] ++ vdup.16 d27, d29[1] ++ vmul.s16 q13, q13, q15 ++ transform2 d2, d6, d3, d7, q1, q3, d24, d26, d25, d27, \ ++ d16, d17, q9, q10 ++ vtrn.32 d0, d1 ++ vtrn.32 d2, d3 ++ vtrn.32 d4, d5 ++ vtrn.32 d6, d7 ++ vswp d1, d2 ++ vswp d5, d6 ++ mov r4, r0 ++ vst1.16 {q0}, [r4,:128], r12 ++ vst1.16 {q1}, [r4,:128], r12 ++ vst1.16 {q2}, [r4,:128], r12 ++ vst1.16 {q3}, [r4,:128], r12 ++ add r0, r0, #16 ++ subs r2, r2, #2 ++ bgt 1b ++ pop {r4,pc} ++endfunc ++ ++#define F_SQRT1_2 23170 ++#define F_COS_16_1 30274 ++#define F_COS_16_3 12540 ++ ++const coefs, align=4 ++ .short F_SQRT1_2, -F_SQRT1_2, -F_SQRT1_2, F_SQRT1_2 ++ .short F_COS_16_1,-F_COS_16_1,-F_COS_16_1, F_COS_16_1 ++ .short F_COS_16_3,-F_COS_16_3,-F_COS_16_3, F_COS_16_3 ++ .short 1, -1, -1, 1 ++endconst ++ ++.macro def_fft n, n2, n4 ++function fft\n\()_neon ++ push {r4, lr} ++ mov r4, r0 ++ bl fft\n2\()_neon ++ add r0, r4, #\n4*2*4 ++ bl fft\n4\()_neon ++ add r0, r4, #\n4*3*4 ++ bl fft\n4\()_neon ++ mov r0, r4 ++ pop {r4, lr} ++ movrel r1, X(ff_cos_\n\()_fixed) ++ mov r2, #\n4/2 ++ b fft_pass_neon ++endfunc ++.endm ++ ++ def_fft 32, 16, 8 ++ def_fft 64, 32, 16 ++ def_fft 128, 64, 32 ++ def_fft 256, 128, 64 ++ def_fft 512, 256, 128 ++ def_fft 1024, 512, 256 ++ def_fft 2048, 1024, 512 ++ def_fft 4096, 2048, 1024 ++ def_fft 8192, 4096, 2048 ++ def_fft 16384, 8192, 4096 ++ def_fft 32768, 16384, 8192 ++ def_fft 65536, 32768, 16384 ++ ++function ff_fft_fixed_calc_neon, export=1 ++ ldr r2, [r0] ++ sub r2, r2, #2 ++ movrel r3, fft_fixed_tab_neon ++ ldr r3, [r3, r2, lsl #2] ++ mov r0, r1 ++ bx r3 ++endfunc ++ ++const fft_fixed_tab_neon ++ .word fft4_neon ++ .word fft8_neon ++ .word fft16_neon ++ .word fft32_neon ++ .word fft64_neon ++ .word fft128_neon ++ .word fft256_neon ++ .word fft512_neon ++ .word fft1024_neon ++ .word fft2048_neon ++ .word fft4096_neon ++ .word fft8192_neon ++ .word fft16384_neon ++ .word fft32768_neon ++ .word fft65536_neon ++endconst +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_init_arm.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_init_arm.c 2012-05-14 14:08:53.418321546 +0200 +@@ -19,6 +19,7 @@ + */ + + #include "libavcodec/fft.h" ++#include "libavcodec/rdft.h" + #include "libavcodec/synth_filter.h" + + void ff_fft_permute_neon(FFTContext *s, FFTComplex *z); +@@ -41,10 +42,12 @@ + if (HAVE_NEON) { + s->fft_permute = ff_fft_permute_neon; + s->fft_calc = ff_fft_calc_neon; ++#if CONFIG_MDCT + s->imdct_calc = ff_imdct_calc_neon; + s->imdct_half = ff_imdct_half_neon; + s->mdct_calc = ff_mdct_calc_neon; +- s->permutation = FF_MDCT_PERM_INTERLEAVE; ++ s->mdct_permutation = FF_MDCT_PERM_INTERLEAVE; ++#endif + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fft_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fft_neon.S 2012-05-14 14:08:53.420321586 +0200 +@@ -28,7 +28,6 @@ + + #define M_SQRT1_2 0.70710678118654752440 + +- .text + + function fft4_neon + vld1.32 {d0-d3}, [r0,:128] +@@ -101,12 +100,8 @@ + bx lr + endfunc + +- .align 4 +-pmmp: .float +1.0, -1.0, -1.0, +1.0 +-mppm: .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +- + function fft16_neon +- adr r1, mppm ++ movrel r1, mppm + vld1.32 {d16-d19}, [r0,:128]! @ q8{r0,i0,r1,i1} q9{r2,i2,r3,i3} + pld [r0, #32] + vld1.32 {d2-d3}, [r1,:128] +@@ -148,16 +143,12 @@ + vswp d29, d30 @ q14{r12,i12,i14,r15} q15{r13,i13,i15,r14} + vadd.f32 q0, q12, q13 @ {t1,t2,t5,t6} + vadd.f32 q1, q14, q15 @ {t1a,t2a,t5a,t6a} +- ldr r2, _neon_label +- ldr r3, L$diff1 +- add r2, r3 +-local_label1: +- ldr r2, [pc, r2] ++ movrel r2, X(ff_cos_16) + vsub.f32 q13, q12, q13 @ {t3,t4,t7,t8} + vrev64.32 d1, d1 + vsub.f32 q15, q14, q15 @ {t3a,t4a,t7a,t8a} + vrev64.32 d3, d3 +- adr r3, pmmp ++ movrel r3, pmmp + vswp d1, d26 @ q0{t1,t2,t3,t4} q13{t6,t5,t7,t8} + vswp d3, d30 @ q1{t1a,t2a,t3a,t4a} q15{t6a,t5a,t7a,t8a} + vadd.f32 q12, q0, q13 @ {r8,i8,r9,i9} +@@ -222,7 +213,7 @@ + add r2, r2, r0 @ &z[o2] + add r3, r3, r0 @ &z[o3] + vld1.32 {d20-d21},[r2,:128] @ {z[o2],z[o2+1]} +- adr r12, pmmp ++ movrel r12, pmmp + vld1.32 {d22-d23},[r3,:128] @ {z[o3],z[o3+1]} + add r5, r5, r1 @ wim + vld1.32 {d6-d7}, [r12,:128] @ pmmp +@@ -287,11 +278,6 @@ + pop {r4-r6,pc} + endfunc + +-.set L$offs16, 0 +-.macro setTabOffs n, n2 +-.set L$offs\n, L$offs\n2 + 4 +-.endm +- + .macro def_fft n, n2, n4 + .align 6 + function fft\n\()_neon +@@ -304,15 +290,10 @@ + bl fft\n4\()_neon + mov r0, r4 + pop {r4, lr} +- ldr r1, _neon_label +- add r1, #L$diff\n +-local_label\n: +- ldr r1, [pc, r1] ++ movrel r1, X(ff_cos_\n) + mov r2, #\n4/2 + b fft_pass_neon + endfunc +-setTabOffs \n, \n2 +-.set L$diff\n, _neon_label - local_label\n + L$offs\n - 8 + .endm + + def_fft 32, 16, 8 +@@ -328,14 +309,10 @@ + def_fft 32768, 16384, 8192 + def_fft 65536, 32768, 16384 + +-.set L$diffTab, fft_tab_neon_offs - local_label_tab - 8 + function ff_fft_calc_neon, export=1 + ldr r2, [r0] + sub r2, r2, #2 +- ldr r3, fft_tab_neon_offs +- add r3, #L$diffTab +-local_label_tab: +- add r3, pc ++ movrel r3, fft_tab_neon + ldr r3, [r3, r2, lsl #2] + mov r0, r1 + bx r3 +@@ -371,22 +348,7 @@ + pop {r4,pc} + endfunc + +- +-.global _neon_label +-_neon_label: +-.word _neon_cos_tab - . +- +-L$diff1: +-.word _neon_label - local_label1 - 8 +- +-fft_tab_neon_offs: +-.word _fft_tab_neon - . +- +- +-.section .rodata +- +- .align 4 +-_fft_tab_neon: ++const fft_tab_neon + .word fft4_neon + .word fft8_neon + .word fft16_neon +@@ -402,20 +364,12 @@ + .word fft16384_neon + .word fft32768_neon + .word fft65536_neon +-ELF .size _fft_tab_neon, . - _fft_tab_neon +- +- .align 4 +-_neon_cos_tab: +- .word X(ff_cos_16) +- .word X(ff_cos_32) +- .word X(ff_cos_64) +- .word X(ff_cos_128) +- .word X(ff_cos_256) +- .word X(ff_cos_512) +- .word X(ff_cos_1024) +- .word X(ff_cos_2048) +- .word X(ff_cos_4096) +- .word X(ff_cos_8192) +- .word X(ff_cos_16384) +- .word X(ff_cos_32768) +- .word X(ff_cos_65536) ++endconst ++ ++const pmmp, align=4 ++ .float +1.0, -1.0, -1.0, +1.0 ++endconst ++ ++const mppm, align=4 ++ .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 ++endconst +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fmtconvert_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fmtconvert_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fmtconvert_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fmtconvert_neon.S 2012-05-14 14:08:53.420321586 +0200 +@@ -23,7 +23,6 @@ + #include "asm.S" + + preserve8 +- .text + + function ff_float_to_int16_neon, export=1 + subs r2, r2, #8 +@@ -71,6 +70,7 @@ + + function ff_float_to_int16_interleave_neon, export=1 + cmp r3, #2 ++ itt lt + ldrlt r1, [r1] + blt ff_float_to_int16_neon + bne 4f +@@ -196,6 +196,7 @@ + vst1.64 {d3}, [r8], ip + vst1.64 {d7}, [r8], ip + subs r3, r3, #4 ++ it eq + popeq {r4-r8,pc} + cmp r3, #4 + add r0, r0, #8 +@@ -305,6 +306,7 @@ + vst1.32 {d23[1]}, [r8], ip + 8: subs r3, r3, #2 + add r0, r0, #4 ++ it eq + popeq {r4-r8,pc} + + @ 1 channel +@@ -354,6 +356,7 @@ + vst1.16 {d2[3]}, [r5,:16], ip + vst1.16 {d3[1]}, [r5,:16], ip + vst1.16 {d3[3]}, [r5,:16], ip ++ it eq + popeq {r4-r8,pc} + vld1.64 {d0-d1}, [r4,:128]! + vcvt.s32.f32 q0, q0, #16 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fmtconvert_vfp.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fmtconvert_vfp.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/fmtconvert_vfp.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/fmtconvert_vfp.S 2012-05-14 14:08:53.421321606 +0200 +@@ -21,8 +21,6 @@ + #include "config.h" + #include "asm.S" + +- .syntax unified +- + /** + * ARM VFP optimized float to int16 conversion. + * Assume that len is a positive number and is multiple of 8, destination +@@ -48,6 +46,7 @@ + vmov r5, r6, s2, s3 + vmov r7, r8, s4, s5 + vmov ip, lr, s6, s7 ++ it gt + vldmiagt r1!, {s16-s23} + ssat r4, #16, r4 + ssat r3, #16, r3 +@@ -55,10 +54,12 @@ + ssat r5, #16, r5 + pkhbt r3, r3, r4, lsl #16 + pkhbt r4, r5, r6, lsl #16 ++ itttt gt + vcvtgt.s32.f32 s0, s16 + vcvtgt.s32.f32 s1, s17 + vcvtgt.s32.f32 s2, s18 + vcvtgt.s32.f32 s3, s19 ++ itttt gt + vcvtgt.s32.f32 s4, s20 + vcvtgt.s32.f32 s5, s21 + vcvtgt.s32.f32 s6, s22 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264cmc_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264cmc_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264cmc_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264cmc_neon.S 2012-05-14 14:08:53.422321626 +0200 +@@ -0,0 +1,430 @@ ++/* ++ * Copyright (c) 2008 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++/* chroma_mc8(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */ ++.macro h264_chroma_mc8 type, codec=h264 ++function ff_\type\()_\codec\()_chroma_mc8_neon, export=1 ++ push {r4-r7, lr} ++ ldrd r4, [sp, #20] ++ .ifc \type,avg ++ mov lr, r0 ++ .endif ++ pld [r1] ++ pld [r1, r2] ++ ++ .ifc \codec,rv40 ++ movrel r6, rv40bias ++ lsr r7, r5, #1 ++ add r6, r6, r7, lsl #3 ++ lsr r7, r4, #1 ++ add r6, r6, r7, lsl #1 ++ vld1.16 {d22[],d23[]}, [r6,:16] ++ .endif ++ ++A muls r7, r4, r5 ++T mul r7, r4, r5 ++T cmp r7, #0 ++ rsb r6, r7, r5, lsl #3 ++ rsb r12, r7, r4, lsl #3 ++ sub r4, r7, r4, lsl #3 ++ sub r4, r4, r5, lsl #3 ++ add r4, r4, #64 ++ ++ beq 2f ++ ++ add r5, r1, r2 ++ ++ vdup.8 d0, r4 ++ lsl r4, r2, #1 ++ vdup.8 d1, r12 ++ vld1.8 {d4, d5}, [r1], r4 ++ vdup.8 d2, r6 ++ vld1.8 {d6, d7}, [r5], r4 ++ vdup.8 d3, r7 ++ ++ vext.8 d5, d4, d5, #1 ++ vext.8 d7, d6, d7, #1 ++ ++1: pld [r5] ++ vmull.u8 q8, d4, d0 ++ vmlal.u8 q8, d5, d1 ++ vld1.8 {d4, d5}, [r1], r4 ++ vmlal.u8 q8, d6, d2 ++ vext.8 d5, d4, d5, #1 ++ vmlal.u8 q8, d7, d3 ++ vmull.u8 q9, d6, d0 ++ subs r3, r3, #2 ++ vmlal.u8 q9, d7, d1 ++ vmlal.u8 q9, d4, d2 ++ vmlal.u8 q9, d5, d3 ++ vld1.8 {d6, d7}, [r5], r4 ++ pld [r1] ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ vrshrn.u16 d17, q9, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vadd.u16 q9, q9, q11 ++ vshrn.u16 d16, q8, #6 ++ vshrn.u16 d17, q9, #6 ++ .endif ++ .ifc \type,avg ++ vld1.8 {d20}, [lr,:64], r2 ++ vld1.8 {d21}, [lr,:64], r2 ++ vrhadd.u8 q8, q8, q10 ++ .endif ++ vext.8 d7, d6, d7, #1 ++ vst1.8 {d16}, [r0,:64], r2 ++ vst1.8 {d17}, [r0,:64], r2 ++ bgt 1b ++ ++ pop {r4-r7, pc} ++ ++2: tst r6, r6 ++ add r12, r12, r6 ++ vdup.8 d0, r4 ++ vdup.8 d1, r12 ++ ++ beq 4f ++ ++ add r5, r1, r2 ++ lsl r4, r2, #1 ++ vld1.8 {d4}, [r1], r4 ++ vld1.8 {d6}, [r5], r4 ++ ++3: pld [r5] ++ vmull.u8 q8, d4, d0 ++ vmlal.u8 q8, d6, d1 ++ vld1.8 {d4}, [r1], r4 ++ vmull.u8 q9, d6, d0 ++ vmlal.u8 q9, d4, d1 ++ vld1.8 {d6}, [r5], r4 ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ vrshrn.u16 d17, q9, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vadd.u16 q9, q9, q11 ++ vshrn.u16 d16, q8, #6 ++ vshrn.u16 d17, q9, #6 ++ .endif ++ .ifc \type,avg ++ vld1.8 {d20}, [lr,:64], r2 ++ vld1.8 {d21}, [lr,:64], r2 ++ vrhadd.u8 q8, q8, q10 ++ .endif ++ subs r3, r3, #2 ++ pld [r1] ++ vst1.8 {d16}, [r0,:64], r2 ++ vst1.8 {d17}, [r0,:64], r2 ++ bgt 3b ++ ++ pop {r4-r7, pc} ++ ++4: vld1.8 {d4, d5}, [r1], r2 ++ vld1.8 {d6, d7}, [r1], r2 ++ vext.8 d5, d4, d5, #1 ++ vext.8 d7, d6, d7, #1 ++ ++5: pld [r1] ++ subs r3, r3, #2 ++ vmull.u8 q8, d4, d0 ++ vmlal.u8 q8, d5, d1 ++ vld1.8 {d4, d5}, [r1], r2 ++ vmull.u8 q9, d6, d0 ++ vmlal.u8 q9, d7, d1 ++ pld [r1] ++ vext.8 d5, d4, d5, #1 ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ vrshrn.u16 d17, q9, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vadd.u16 q9, q9, q11 ++ vshrn.u16 d16, q8, #6 ++ vshrn.u16 d17, q9, #6 ++ .endif ++ .ifc \type,avg ++ vld1.8 {d20}, [lr,:64], r2 ++ vld1.8 {d21}, [lr,:64], r2 ++ vrhadd.u8 q8, q8, q10 ++ .endif ++ vld1.8 {d6, d7}, [r1], r2 ++ vext.8 d7, d6, d7, #1 ++ vst1.8 {d16}, [r0,:64], r2 ++ vst1.8 {d17}, [r0,:64], r2 ++ bgt 5b ++ ++ pop {r4-r7, pc} ++endfunc ++.endm ++ ++/* chroma_mc4(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */ ++.macro h264_chroma_mc4 type, codec=h264 ++function ff_\type\()_\codec\()_chroma_mc4_neon, export=1 ++ push {r4-r7, lr} ++ ldrd r4, [sp, #20] ++ .ifc \type,avg ++ mov lr, r0 ++ .endif ++ pld [r1] ++ pld [r1, r2] ++ ++ .ifc \codec,rv40 ++ movrel r6, rv40bias ++ lsr r7, r5, #1 ++ add r6, r6, r7, lsl #3 ++ lsr r7, r4, #1 ++ add r6, r6, r7, lsl #1 ++ vld1.16 {d22[],d23[]}, [r6,:16] ++ .endif ++ ++A muls r7, r4, r5 ++T mul r7, r4, r5 ++T cmp r7, #0 ++ rsb r6, r7, r5, lsl #3 ++ rsb r12, r7, r4, lsl #3 ++ sub r4, r7, r4, lsl #3 ++ sub r4, r4, r5, lsl #3 ++ add r4, r4, #64 ++ ++ beq 2f ++ ++ add r5, r1, r2 ++ ++ vdup.8 d0, r4 ++ lsl r4, r2, #1 ++ vdup.8 d1, r12 ++ vld1.8 {d4}, [r1], r4 ++ vdup.8 d2, r6 ++ vld1.8 {d6}, [r5], r4 ++ vdup.8 d3, r7 ++ ++ vext.8 d5, d4, d5, #1 ++ vext.8 d7, d6, d7, #1 ++ vtrn.32 d4, d5 ++ vtrn.32 d6, d7 ++ ++ vtrn.32 d0, d1 ++ vtrn.32 d2, d3 ++ ++1: pld [r5] ++ vmull.u8 q8, d4, d0 ++ vmlal.u8 q8, d6, d2 ++ vld1.8 {d4}, [r1], r4 ++ vext.8 d5, d4, d5, #1 ++ vtrn.32 d4, d5 ++ vmull.u8 q9, d6, d0 ++ vmlal.u8 q9, d4, d2 ++ vld1.8 {d6}, [r5], r4 ++ vadd.i16 d16, d16, d17 ++ vadd.i16 d17, d18, d19 ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vshrn.u16 d16, q8, #6 ++ .endif ++ subs r3, r3, #2 ++ pld [r1] ++ .ifc \type,avg ++ vld1.32 {d20[0]}, [lr,:32], r2 ++ vld1.32 {d20[1]}, [lr,:32], r2 ++ vrhadd.u8 d16, d16, d20 ++ .endif ++ vext.8 d7, d6, d7, #1 ++ vtrn.32 d6, d7 ++ vst1.32 {d16[0]}, [r0,:32], r2 ++ vst1.32 {d16[1]}, [r0,:32], r2 ++ bgt 1b ++ ++ pop {r4-r7, pc} ++ ++2: tst r6, r6 ++ add r12, r12, r6 ++ vdup.8 d0, r4 ++ vdup.8 d1, r12 ++ vtrn.32 d0, d1 ++ ++ beq 4f ++ ++ vext.32 d1, d0, d1, #1 ++ add r5, r1, r2 ++ lsl r4, r2, #1 ++ vld1.32 {d4[0]}, [r1], r4 ++ vld1.32 {d4[1]}, [r5], r4 ++ ++3: pld [r5] ++ vmull.u8 q8, d4, d0 ++ vld1.32 {d4[0]}, [r1], r4 ++ vmull.u8 q9, d4, d1 ++ vld1.32 {d4[1]}, [r5], r4 ++ vadd.i16 d16, d16, d17 ++ vadd.i16 d17, d18, d19 ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vshrn.u16 d16, q8, #6 ++ .endif ++ .ifc \type,avg ++ vld1.32 {d20[0]}, [lr,:32], r2 ++ vld1.32 {d20[1]}, [lr,:32], r2 ++ vrhadd.u8 d16, d16, d20 ++ .endif ++ subs r3, r3, #2 ++ pld [r1] ++ vst1.32 {d16[0]}, [r0,:32], r2 ++ vst1.32 {d16[1]}, [r0,:32], r2 ++ bgt 3b ++ ++ pop {r4-r7, pc} ++ ++4: vld1.8 {d4}, [r1], r2 ++ vld1.8 {d6}, [r1], r2 ++ vext.8 d5, d4, d5, #1 ++ vext.8 d7, d6, d7, #1 ++ vtrn.32 d4, d5 ++ vtrn.32 d6, d7 ++ ++5: vmull.u8 q8, d4, d0 ++ vmull.u8 q9, d6, d0 ++ subs r3, r3, #2 ++ vld1.8 {d4}, [r1], r2 ++ vext.8 d5, d4, d5, #1 ++ vtrn.32 d4, d5 ++ vadd.i16 d16, d16, d17 ++ vadd.i16 d17, d18, d19 ++ pld [r1] ++ .ifc \codec,h264 ++ vrshrn.u16 d16, q8, #6 ++ .else ++ vadd.u16 q8, q8, q11 ++ vshrn.u16 d16, q8, #6 ++ .endif ++ .ifc \type,avg ++ vld1.32 {d20[0]}, [lr,:32], r2 ++ vld1.32 {d20[1]}, [lr,:32], r2 ++ vrhadd.u8 d16, d16, d20 ++ .endif ++ vld1.8 {d6}, [r1], r2 ++ vext.8 d7, d6, d7, #1 ++ vtrn.32 d6, d7 ++ pld [r1] ++ vst1.32 {d16[0]}, [r0,:32], r2 ++ vst1.32 {d16[1]}, [r0,:32], r2 ++ bgt 5b ++ ++ pop {r4-r7, pc} ++endfunc ++.endm ++ ++.macro h264_chroma_mc2 type ++function ff_\type\()_h264_chroma_mc2_neon, export=1 ++ push {r4-r6, lr} ++ ldr r4, [sp, #16] ++ ldr lr, [sp, #20] ++ pld [r1] ++ pld [r1, r2] ++ orrs r5, r4, lr ++ beq 2f ++ ++ mul r5, r4, lr ++ rsb r6, r5, lr, lsl #3 ++ rsb r12, r5, r4, lsl #3 ++ sub r4, r5, r4, lsl #3 ++ sub r4, r4, lr, lsl #3 ++ add r4, r4, #64 ++ vdup.8 d0, r4 ++ vdup.8 d2, r12 ++ vdup.8 d1, r6 ++ vdup.8 d3, r5 ++ vtrn.16 q0, q1 ++1: ++ vld1.32 {d4[0]}, [r1], r2 ++ vld1.32 {d4[1]}, [r1], r2 ++ vrev64.32 d5, d4 ++ vld1.32 {d5[1]}, [r1] ++ vext.8 q3, q2, q2, #1 ++ vtrn.16 q2, q3 ++ vmull.u8 q8, d4, d0 ++ vmlal.u8 q8, d5, d1 ++ .ifc \type,avg ++ vld1.16 {d18[0]}, [r0,:16], r2 ++ vld1.16 {d18[1]}, [r0,:16] ++ sub r0, r0, r2 ++ .endif ++ vtrn.32 d16, d17 ++ vadd.i16 d16, d16, d17 ++ vrshrn.u16 d16, q8, #6 ++ .ifc \type,avg ++ vrhadd.u8 d16, d16, d18 ++ .endif ++ vst1.16 {d16[0]}, [r0,:16], r2 ++ vst1.16 {d16[1]}, [r0,:16], r2 ++ subs r3, r3, #2 ++ bgt 1b ++ pop {r4-r6, pc} ++2: ++ .ifc \type,put ++ ldrh_post r5, r1, r2 ++ strh_post r5, r0, r2 ++ ldrh_post r6, r1, r2 ++ strh_post r6, r0, r2 ++ .else ++ vld1.16 {d16[0]}, [r1], r2 ++ vld1.16 {d16[1]}, [r1], r2 ++ vld1.16 {d18[0]}, [r0,:16], r2 ++ vld1.16 {d18[1]}, [r0,:16] ++ sub r0, r0, r2 ++ vrhadd.u8 d16, d16, d18 ++ vst1.16 {d16[0]}, [r0,:16], r2 ++ vst1.16 {d16[1]}, [r0,:16], r2 ++ .endif ++ subs r3, r3, #2 ++ bgt 2b ++ pop {r4-r6, pc} ++endfunc ++.endm ++ ++#if CONFIG_H264_DECODER ++ h264_chroma_mc8 put ++ h264_chroma_mc8 avg ++ h264_chroma_mc4 put ++ h264_chroma_mc4 avg ++ h264_chroma_mc2 put ++ h264_chroma_mc2 avg ++#endif ++ ++#if CONFIG_RV40_DECODER ++const rv40bias ++ .short 0, 16, 32, 16 ++ .short 32, 28, 32, 28 ++ .short 0, 32, 16, 32 ++ .short 32, 28, 32, 28 ++endconst ++ ++ h264_chroma_mc8 put, rv40 ++ h264_chroma_mc8 avg, rv40 ++ h264_chroma_mc4 put, rv40 ++ h264_chroma_mc4 avg, rv40 ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264dsp_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264dsp_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264dsp_init_arm.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264dsp_init_arm.c 2012-05-14 14:08:53.423321646 +0200 +@@ -32,47 +32,22 @@ + void ff_h264_h_loop_filter_chroma_neon(uint8_t *pix, int stride, int alpha, + int beta, int8_t *tc0); + +-void ff_weight_h264_pixels_16x16_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_16x8_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_8x16_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_8x8_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_8x4_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_4x8_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_4x4_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +-void ff_weight_h264_pixels_4x2_neon(uint8_t *ds, int stride, int log2_den, +- int weight, int offset); +- +-void ff_biweight_h264_pixels_16x16_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_16x8_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_8x16_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_8x8_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_8x4_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_4x8_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_4x4_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); +-void ff_biweight_h264_pixels_4x2_neon(uint8_t *dst, uint8_t *src, int stride, +- int log2_den, int weightd, int weights, +- int offset); ++void ff_weight_h264_pixels_16_neon(uint8_t *dst, int stride, int height, ++ int log2_den, int weight, int offset); ++void ff_weight_h264_pixels_8_neon(uint8_t *dst, int stride, int height, ++ int log2_den, int weight, int offset); ++void ff_weight_h264_pixels_4_neon(uint8_t *dst, int stride, int height, ++ int log2_den, int weight, int offset); ++ ++void ff_biweight_h264_pixels_16_neon(uint8_t *dst, uint8_t *src, int stride, ++ int height, int log2_den, int weightd, ++ int weights, int offset); ++void ff_biweight_h264_pixels_8_neon(uint8_t *dst, uint8_t *src, int stride, ++ int height, int log2_den, int weightd, ++ int weights, int offset); ++void ff_biweight_h264_pixels_4_neon(uint8_t *dst, uint8_t *src, int stride, ++ int height, int log2_den, int weightd, ++ int weights, int offset); + + void ff_h264_idct_add_neon(uint8_t *dst, DCTELEM *block, int stride); + void ff_h264_idct_dc_add_neon(uint8_t *dst, DCTELEM *block, int stride); +@@ -92,42 +67,37 @@ + DCTELEM *block, int stride, + const uint8_t nnzc[6*8]); + +-static void ff_h264dsp_init_neon(H264DSPContext *c) ++static void ff_h264dsp_init_neon(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) + { ++ if (bit_depth == 8) { + c->h264_v_loop_filter_luma = ff_h264_v_loop_filter_luma_neon; + c->h264_h_loop_filter_luma = ff_h264_h_loop_filter_luma_neon; ++ if(chroma_format_idc == 1){ + c->h264_v_loop_filter_chroma = ff_h264_v_loop_filter_chroma_neon; + c->h264_h_loop_filter_chroma = ff_h264_h_loop_filter_chroma_neon; ++ } + +- c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16x16_neon; +- c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_16x8_neon; +- c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_8x16_neon; +- c->weight_h264_pixels_tab[3] = ff_weight_h264_pixels_8x8_neon; +- c->weight_h264_pixels_tab[4] = ff_weight_h264_pixels_8x4_neon; +- c->weight_h264_pixels_tab[5] = ff_weight_h264_pixels_4x8_neon; +- c->weight_h264_pixels_tab[6] = ff_weight_h264_pixels_4x4_neon; +- c->weight_h264_pixels_tab[7] = ff_weight_h264_pixels_4x2_neon; +- +- c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16x16_neon; +- c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_16x8_neon; +- c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_8x16_neon; +- c->biweight_h264_pixels_tab[3] = ff_biweight_h264_pixels_8x8_neon; +- c->biweight_h264_pixels_tab[4] = ff_biweight_h264_pixels_8x4_neon; +- c->biweight_h264_pixels_tab[5] = ff_biweight_h264_pixels_4x8_neon; +- c->biweight_h264_pixels_tab[6] = ff_biweight_h264_pixels_4x4_neon; +- c->biweight_h264_pixels_tab[7] = ff_biweight_h264_pixels_4x2_neon; ++ c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16_neon; ++ c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_8_neon; ++ c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_4_neon; ++ ++ c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16_neon; ++ c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_8_neon; ++ c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_4_neon; + + c->h264_idct_add = ff_h264_idct_add_neon; + c->h264_idct_dc_add = ff_h264_idct_dc_add_neon; + c->h264_idct_add16 = ff_h264_idct_add16_neon; + c->h264_idct_add16intra = ff_h264_idct_add16intra_neon; +- c->h264_idct_add8 = ff_h264_idct_add8_neon; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_neon; + c->h264_idct8_add = ff_h264_idct8_add_neon; + c->h264_idct8_dc_add = ff_h264_idct8_dc_add_neon; + c->h264_idct8_add4 = ff_h264_idct8_add4_neon; ++ } + } + +-void ff_h264dsp_init_arm(H264DSPContext *c) ++void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) + { +- if (HAVE_NEON) ff_h264dsp_init_neon(c); ++ if (HAVE_NEON) ff_h264dsp_init_neon(c, bit_depth, chroma_format_idc); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264dsp_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264dsp_neon.S 2012-05-14 14:08:53.429321768 +0200 +@@ -19,414 +19,26 @@ + */ + + #include "asm.S" +- +- .macro transpose_8x8 r0 r1 r2 r3 r4 r5 r6 r7 +- vtrn.32 \r0, \r4 +- vtrn.32 \r1, \r5 +- vtrn.32 \r2, \r6 +- vtrn.32 \r3, \r7 +- vtrn.16 \r0, \r2 +- vtrn.16 \r1, \r3 +- vtrn.16 \r4, \r6 +- vtrn.16 \r5, \r7 +- vtrn.8 \r0, \r1 +- vtrn.8 \r2, \r3 +- vtrn.8 \r4, \r5 +- vtrn.8 \r6, \r7 +- .endm +- +- .macro transpose_4x4 r0 r1 r2 r3 +- vtrn.16 \r0, \r2 +- vtrn.16 \r1, \r3 +- vtrn.8 \r0, \r1 +- vtrn.8 \r2, \r3 +- .endm +- +- .macro swap4 r0 r1 r2 r3 r4 r5 r6 r7 +- vswp \r0, \r4 +- vswp \r1, \r5 +- vswp \r2, \r6 +- vswp \r3, \r7 +- .endm +- +- .macro transpose16_4x4 r0 r1 r2 r3 r4 r5 r6 r7 +- vtrn.32 \r0, \r2 +- vtrn.32 \r1, \r3 +- vtrn.32 \r4, \r6 +- vtrn.32 \r5, \r7 +- vtrn.16 \r0, \r1 +- vtrn.16 \r2, \r3 +- vtrn.16 \r4, \r5 +- vtrn.16 \r6, \r7 +- .endm +- +-/* chroma_mc8(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */ +- .macro h264_chroma_mc8 type +-function ff_\type\()_h264_chroma_mc8_neon, export=1 +- push {r4-r7, lr} +- ldrd r4, [sp, #20] +-.ifc \type,avg +- mov lr, r0 +-.endif +- pld [r1] +- pld [r1, r2] +- +- muls r7, r4, r5 +- rsb r6, r7, r5, lsl #3 +- rsb ip, r7, r4, lsl #3 +- sub r4, r7, r4, lsl #3 +- sub r4, r4, r5, lsl #3 +- add r4, r4, #64 +- +- beq 2f +- +- add r5, r1, r2 +- +- vdup.8 d0, r4 +- lsl r4, r2, #1 +- vdup.8 d1, ip +- vld1.64 {d4, d5}, [r1], r4 +- vdup.8 d2, r6 +- vld1.64 {d6, d7}, [r5], r4 +- vdup.8 d3, r7 +- +- vext.8 d5, d4, d5, #1 +- vext.8 d7, d6, d7, #1 +- +-1: pld [r5] +- vmull.u8 q8, d4, d0 +- vmlal.u8 q8, d5, d1 +- vld1.64 {d4, d5}, [r1], r4 +- vmlal.u8 q8, d6, d2 +- vext.8 d5, d4, d5, #1 +- vmlal.u8 q8, d7, d3 +- vmull.u8 q9, d6, d0 +- subs r3, r3, #2 +- vmlal.u8 q9, d7, d1 +- vmlal.u8 q9, d4, d2 +- vmlal.u8 q9, d5, d3 +- vrshrn.u16 d16, q8, #6 +- vld1.64 {d6, d7}, [r5], r4 +- pld [r1] +- vrshrn.u16 d17, q9, #6 +-.ifc \type,avg +- vld1.64 {d20}, [lr,:64], r2 +- vld1.64 {d21}, [lr,:64], r2 +- vrhadd.u8 q8, q8, q10 +-.endif +- vext.8 d7, d6, d7, #1 +- vst1.64 {d16}, [r0,:64], r2 +- vst1.64 {d17}, [r0,:64], r2 +- bgt 1b +- +- pop {r4-r7, pc} +- +-2: tst r6, r6 +- add ip, ip, r6 +- vdup.8 d0, r4 +- vdup.8 d1, ip +- +- beq 4f +- +- add r5, r1, r2 +- lsl r4, r2, #1 +- vld1.64 {d4}, [r1], r4 +- vld1.64 {d6}, [r5], r4 +- +-3: pld [r5] +- vmull.u8 q8, d4, d0 +- vmlal.u8 q8, d6, d1 +- vld1.64 {d4}, [r1], r4 +- vmull.u8 q9, d6, d0 +- vmlal.u8 q9, d4, d1 +- vld1.64 {d6}, [r5], r4 +- vrshrn.u16 d16, q8, #6 +- vrshrn.u16 d17, q9, #6 +-.ifc \type,avg +- vld1.64 {d20}, [lr,:64], r2 +- vld1.64 {d21}, [lr,:64], r2 +- vrhadd.u8 q8, q8, q10 +-.endif +- subs r3, r3, #2 +- pld [r1] +- vst1.64 {d16}, [r0,:64], r2 +- vst1.64 {d17}, [r0,:64], r2 +- bgt 3b +- +- pop {r4-r7, pc} +- +-4: vld1.64 {d4, d5}, [r1], r2 +- vld1.64 {d6, d7}, [r1], r2 +- vext.8 d5, d4, d5, #1 +- vext.8 d7, d6, d7, #1 +- +-5: pld [r1] +- subs r3, r3, #2 +- vmull.u8 q8, d4, d0 +- vmlal.u8 q8, d5, d1 +- vld1.64 {d4, d5}, [r1], r2 +- vmull.u8 q9, d6, d0 +- vmlal.u8 q9, d7, d1 +- pld [r1] +- vext.8 d5, d4, d5, #1 +- vrshrn.u16 d16, q8, #6 +- vrshrn.u16 d17, q9, #6 +-.ifc \type,avg +- vld1.64 {d20}, [lr,:64], r2 +- vld1.64 {d21}, [lr,:64], r2 +- vrhadd.u8 q8, q8, q10 +-.endif +- vld1.64 {d6, d7}, [r1], r2 +- vext.8 d7, d6, d7, #1 +- vst1.64 {d16}, [r0,:64], r2 +- vst1.64 {d17}, [r0,:64], r2 +- bgt 5b +- +- pop {r4-r7, pc} +-endfunc +- .endm +- +-/* chroma_mc4(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y) */ +- .macro h264_chroma_mc4 type +-function ff_\type\()_h264_chroma_mc4_neon, export=1 +- push {r4-r7, lr} +- ldrd r4, [sp, #20] +-.ifc \type,avg +- mov lr, r0 +-.endif +- pld [r1] +- pld [r1, r2] +- +- muls r7, r4, r5 +- rsb r6, r7, r5, lsl #3 +- rsb ip, r7, r4, lsl #3 +- sub r4, r7, r4, lsl #3 +- sub r4, r4, r5, lsl #3 +- add r4, r4, #64 +- +- beq 2f +- +- add r5, r1, r2 +- +- vdup.8 d0, r4 +- lsl r4, r2, #1 +- vdup.8 d1, ip +- vld1.64 {d4}, [r1], r4 +- vdup.8 d2, r6 +- vld1.64 {d6}, [r5], r4 +- vdup.8 d3, r7 +- +- vext.8 d5, d4, d5, #1 +- vext.8 d7, d6, d7, #1 +- vtrn.32 d4, d5 +- vtrn.32 d6, d7 +- +- vtrn.32 d0, d1 +- vtrn.32 d2, d3 +- +-1: pld [r5] +- vmull.u8 q8, d4, d0 +- vmlal.u8 q8, d6, d2 +- vld1.64 {d4}, [r1], r4 +- vext.8 d5, d4, d5, #1 +- vtrn.32 d4, d5 +- vmull.u8 q9, d6, d0 +- vmlal.u8 q9, d4, d2 +- vld1.64 {d6}, [r5], r4 +- vadd.i16 d16, d16, d17 +- vadd.i16 d17, d18, d19 +- vrshrn.u16 d16, q8, #6 +- subs r3, r3, #2 +- pld [r1] +-.ifc \type,avg +- vld1.32 {d20[0]}, [lr,:32], r2 +- vld1.32 {d20[1]}, [lr,:32], r2 +- vrhadd.u8 d16, d16, d20 +-.endif +- vext.8 d7, d6, d7, #1 +- vtrn.32 d6, d7 +- vst1.32 {d16[0]}, [r0,:32], r2 +- vst1.32 {d16[1]}, [r0,:32], r2 +- bgt 1b +- +- pop {r4-r7, pc} +- +-2: tst r6, r6 +- add ip, ip, r6 +- vdup.8 d0, r4 +- vdup.8 d1, ip +- vtrn.32 d0, d1 +- +- beq 4f +- +- vext.32 d1, d0, d1, #1 +- add r5, r1, r2 +- lsl r4, r2, #1 +- vld1.32 {d4[0]}, [r1], r4 +- vld1.32 {d4[1]}, [r5], r4 +- +-3: pld [r5] +- vmull.u8 q8, d4, d0 +- vld1.32 {d4[0]}, [r1], r4 +- vmull.u8 q9, d4, d1 +- vld1.32 {d4[1]}, [r5], r4 +- vadd.i16 d16, d16, d17 +- vadd.i16 d17, d18, d19 +- vrshrn.u16 d16, q8, #6 +-.ifc \type,avg +- vld1.32 {d20[0]}, [lr,:32], r2 +- vld1.32 {d20[1]}, [lr,:32], r2 +- vrhadd.u8 d16, d16, d20 +-.endif +- subs r3, r3, #2 +- pld [r1] +- vst1.32 {d16[0]}, [r0,:32], r2 +- vst1.32 {d16[1]}, [r0,:32], r2 +- bgt 3b +- +- pop {r4-r7, pc} +- +-4: vld1.64 {d4}, [r1], r2 +- vld1.64 {d6}, [r1], r2 +- vext.8 d5, d4, d5, #1 +- vext.8 d7, d6, d7, #1 +- vtrn.32 d4, d5 +- vtrn.32 d6, d7 +- +-5: vmull.u8 q8, d4, d0 +- vmull.u8 q9, d6, d0 +- subs r3, r3, #2 +- vld1.64 {d4}, [r1], r2 +- vext.8 d5, d4, d5, #1 +- vtrn.32 d4, d5 +- vadd.i16 d16, d16, d17 +- vadd.i16 d17, d18, d19 +- pld [r1] +- vrshrn.u16 d16, q8, #6 +-.ifc \type,avg +- vld1.32 {d20[0]}, [lr,:32], r2 +- vld1.32 {d20[1]}, [lr,:32], r2 +- vrhadd.u8 d16, d16, d20 +-.endif +- vld1.64 {d6}, [r1], r2 +- vext.8 d7, d6, d7, #1 +- vtrn.32 d6, d7 +- pld [r1] +- vst1.32 {d16[0]}, [r0,:32], r2 +- vst1.32 {d16[1]}, [r0,:32], r2 +- bgt 5b +- +- pop {r4-r7, pc} +-endfunc +- .endm +- +- .macro h264_chroma_mc2 type +-function ff_\type\()_h264_chroma_mc2_neon, export=1 +- push {r4-r6, lr} +- ldr r4, [sp, #16] +- ldr lr, [sp, #20] +- pld [r1] +- pld [r1, r2] +- orrs r5, r4, lr +- beq 2f +- +- mul r5, r4, lr +- rsb r6, r5, lr, lsl #3 +- rsb r12, r5, r4, lsl #3 +- sub r4, r5, r4, lsl #3 +- sub r4, r4, lr, lsl #3 +- add r4, r4, #64 +- vdup.8 d0, r4 +- vdup.8 d2, r12 +- vdup.8 d1, r6 +- vdup.8 d3, r5 +- vtrn.16 q0, q1 +-1: +- vld1.32 {d4[0]}, [r1], r2 +- vld1.32 {d4[1]}, [r1], r2 +- vrev64.32 d5, d4 +- vld1.32 {d5[1]}, [r1] +- vext.8 q3, q2, q2, #1 +- vtrn.16 q2, q3 +- vmull.u8 q8, d4, d0 +- vmlal.u8 q8, d5, d1 +-.ifc \type,avg +- vld1.16 {d18[0]}, [r0,:16], r2 +- vld1.16 {d18[1]}, [r0,:16] +- sub r0, r0, r2 +-.endif +- vtrn.32 d16, d17 +- vadd.i16 d16, d16, d17 +- vrshrn.u16 d16, q8, #6 +-.ifc \type,avg +- vrhadd.u8 d16, d16, d18 +-.endif +- vst1.16 {d16[0]}, [r0,:16], r2 +- vst1.16 {d16[1]}, [r0,:16], r2 +- subs r3, r3, #2 +- bgt 1b +- pop {r4-r6, pc} +-2: +-.ifc \type,put +- ldrh r5, [r1], r2 +- strh r5, [r0], r2 +- ldrh r6, [r1], r2 +- strh r6, [r0], r2 +-.else +- vld1.16 {d16[0]}, [r1], r2 +- vld1.16 {d16[1]}, [r1], r2 +- vld1.16 {d18[0]}, [r0,:16], r2 +- vld1.16 {d18[1]}, [r0,:16] +- sub r0, r0, r2 +- vrhadd.u8 d16, d16, d18 +- vst1.16 {d16[0]}, [r0,:16], r2 +- vst1.16 {d16[1]}, [r0,:16], r2 +-.endif +- subs r3, r3, #2 +- bgt 2b +- pop {r4-r6, pc} +-endfunc +-.endm +- +- .text +- .align +- +- h264_chroma_mc8 put +- h264_chroma_mc8 avg +- h264_chroma_mc4 put +- h264_chroma_mc4 avg +- h264_chroma_mc2 put +- h264_chroma_mc2 avg ++#include "neon.S" + + /* H.264 loop filter */ + +- .macro h264_loop_filter_start +- ldr ip, [sp] ++.macro h264_loop_filter_start ++ ldr r12, [sp] + tst r2, r2 +- ldr ip, [ip] ++ ldr r12, [r12] ++ it ne + tstne r3, r3 +- vmov.32 d24[0], ip +- and ip, ip, ip, lsl #16 ++ vmov.32 d24[0], r12 ++ and r12, r12, r12, lsl #16 ++ it eq + bxeq lr +- ands ip, ip, ip, lsl #8 ++ ands r12, r12, r12, lsl #8 ++ it lt + bxlt lr +- .endm +- +- .macro align_push_regs +- and ip, sp, #15 +- add ip, ip, #32 +- sub sp, sp, ip +- vst1.64 {d12-d15}, [sp,:128] +- sub sp, sp, #32 +- vst1.64 {d8-d11}, [sp,:128] +- .endm +- +- .macro align_pop_regs +- vld1.64 {d8-d11}, [sp,:128]! +- vld1.64 {d12-d15}, [sp,:128], ip +- .endm ++.endm + +- .macro h264_loop_filter_luma ++.macro h264_loop_filter_luma + vdup.8 q11, r2 @ alpha + vmovl.u8 q12, d24 + vabd.u8 q6, q8, q0 @ abs(p0 - q0) +@@ -492,31 +104,31 @@ + vqmovun.s16 d17, q6 + vqmovun.s16 d0, q11 + vqmovun.s16 d1, q12 +- .endm ++.endm + + function ff_h264_v_loop_filter_luma_neon, export=1 + h264_loop_filter_start + +- vld1.64 {d0, d1}, [r0,:128], r1 +- vld1.64 {d2, d3}, [r0,:128], r1 +- vld1.64 {d4, d5}, [r0,:128], r1 ++ vld1.8 {d0, d1}, [r0,:128], r1 ++ vld1.8 {d2, d3}, [r0,:128], r1 ++ vld1.8 {d4, d5}, [r0,:128], r1 + sub r0, r0, r1, lsl #2 + sub r0, r0, r1, lsl #1 +- vld1.64 {d20,d21}, [r0,:128], r1 +- vld1.64 {d18,d19}, [r0,:128], r1 +- vld1.64 {d16,d17}, [r0,:128], r1 ++ vld1.8 {d20,d21}, [r0,:128], r1 ++ vld1.8 {d18,d19}, [r0,:128], r1 ++ vld1.8 {d16,d17}, [r0,:128], r1 + +- align_push_regs ++ vpush {d8-d15} + + h264_loop_filter_luma + + sub r0, r0, r1, lsl #1 +- vst1.64 {d8, d9}, [r0,:128], r1 +- vst1.64 {d16,d17}, [r0,:128], r1 +- vst1.64 {d0, d1}, [r0,:128], r1 +- vst1.64 {d10,d11}, [r0,:128] ++ vst1.8 {d8, d9}, [r0,:128], r1 ++ vst1.8 {d16,d17}, [r0,:128], r1 ++ vst1.8 {d0, d1}, [r0,:128], r1 ++ vst1.8 {d10,d11}, [r0,:128] + +- align_pop_regs ++ vpop {d8-d15} + bx lr + endfunc + +@@ -524,26 +136,26 @@ + h264_loop_filter_start + + sub r0, r0, #4 +- vld1.64 {d6}, [r0], r1 +- vld1.64 {d20}, [r0], r1 +- vld1.64 {d18}, [r0], r1 +- vld1.64 {d16}, [r0], r1 +- vld1.64 {d0}, [r0], r1 +- vld1.64 {d2}, [r0], r1 +- vld1.64 {d4}, [r0], r1 +- vld1.64 {d26}, [r0], r1 +- vld1.64 {d7}, [r0], r1 +- vld1.64 {d21}, [r0], r1 +- vld1.64 {d19}, [r0], r1 +- vld1.64 {d17}, [r0], r1 +- vld1.64 {d1}, [r0], r1 +- vld1.64 {d3}, [r0], r1 +- vld1.64 {d5}, [r0], r1 +- vld1.64 {d27}, [r0], r1 ++ vld1.8 {d6}, [r0], r1 ++ vld1.8 {d20}, [r0], r1 ++ vld1.8 {d18}, [r0], r1 ++ vld1.8 {d16}, [r0], r1 ++ vld1.8 {d0}, [r0], r1 ++ vld1.8 {d2}, [r0], r1 ++ vld1.8 {d4}, [r0], r1 ++ vld1.8 {d26}, [r0], r1 ++ vld1.8 {d7}, [r0], r1 ++ vld1.8 {d21}, [r0], r1 ++ vld1.8 {d19}, [r0], r1 ++ vld1.8 {d17}, [r0], r1 ++ vld1.8 {d1}, [r0], r1 ++ vld1.8 {d3}, [r0], r1 ++ vld1.8 {d5}, [r0], r1 ++ vld1.8 {d27}, [r0], r1 + + transpose_8x8 q3, q10, q9, q8, q0, q1, q2, q13 + +- align_push_regs ++ vpush {d8-d15} + + h264_loop_filter_luma + +@@ -568,11 +180,11 @@ + vst1.32 {d1[1]}, [r0], r1 + vst1.32 {d11[1]}, [r0], r1 + +- align_pop_regs ++ vpop {d8-d15} + bx lr + endfunc + +- .macro h264_loop_filter_chroma ++.macro h264_loop_filter_chroma + vdup.8 d22, r2 @ alpha + vmovl.u8 q12, d24 + vabd.u8 d26, d16, d0 @ abs(p0 - q0) +@@ -601,22 +213,22 @@ + vsubw.s8 q11, q11, d4 + vqmovun.s16 d16, q14 + vqmovun.s16 d0, q11 +- .endm ++.endm + + function ff_h264_v_loop_filter_chroma_neon, export=1 + h264_loop_filter_start + + sub r0, r0, r1, lsl #1 +- vld1.64 {d18}, [r0,:64], r1 +- vld1.64 {d16}, [r0,:64], r1 +- vld1.64 {d0}, [r0,:64], r1 +- vld1.64 {d2}, [r0,:64] ++ vld1.8 {d18}, [r0,:64], r1 ++ vld1.8 {d16}, [r0,:64], r1 ++ vld1.8 {d0}, [r0,:64], r1 ++ vld1.8 {d2}, [r0,:64] + + h264_loop_filter_chroma + + sub r0, r0, r1, lsl #1 +- vst1.64 {d16}, [r0,:64], r1 +- vst1.64 {d0}, [r0,:64], r1 ++ vst1.8 {d16}, [r0,:64], r1 ++ vst1.8 {d0}, [r0,:64], r1 + + bx lr + endfunc +@@ -661,20 +273,20 @@ + + /* H.264 qpel MC */ + +- .macro lowpass_const r ++.macro lowpass_const r + movw \r, #5 + movt \r, #20 + vmov.32 d6[0], \r +- .endm ++.endm + +- .macro lowpass_8 r0, r1, r2, r3, d0, d1, narrow=1 +-.if \narrow ++.macro lowpass_8 r0, r1, r2, r3, d0, d1, narrow=1 ++ .if \narrow + t0 .req q0 + t1 .req q8 +-.else ++ .else + t0 .req \d0 + t1 .req \d1 +-.endif ++ .endif + vext.8 d2, \r0, \r1, #2 + vext.8 d3, \r0, \r1, #3 + vaddl.u8 q1, d2, d3 +@@ -695,20 +307,20 @@ + vaddl.u8 t1, \r2, d31 + vmla.i16 t1, q9, d6[1] + vmls.i16 t1, q10, d6[0] +-.if \narrow ++ .if \narrow + vqrshrun.s16 \d0, t0, #5 + vqrshrun.s16 \d1, t1, #5 +-.endif ++ .endif + .unreq t0 + .unreq t1 +- .endm ++.endm + +- .macro lowpass_8_1 r0, r1, d0, narrow=1 +-.if \narrow ++.macro lowpass_8_1 r0, r1, d0, narrow=1 ++ .if \narrow + t0 .req q0 +-.else ++ .else + t0 .req \d0 +-.endif ++ .endif + vext.8 d2, \r0, \r1, #2 + vext.8 d3, \r0, \r1, #3 + vaddl.u8 q1, d2, d3 +@@ -719,13 +331,13 @@ + vaddl.u8 t0, \r0, d30 + vmla.i16 t0, q1, d6[1] + vmls.i16 t0, q2, d6[0] +-.if \narrow ++ .if \narrow + vqrshrun.s16 \d0, t0, #5 +-.endif ++ .endif + .unreq t0 +- .endm ++.endm + +- .macro lowpass_8.16 r0, r1, l0, h0, l1, h1, d ++.macro lowpass_8.16 r0, r1, l0, h0, l1, h1, d + vext.16 q1, \r0, \r1, #2 + vext.16 q0, \r0, \r1, #3 + vaddl.s16 q9, d2, d0 +@@ -760,59 +372,59 @@ + vrshrn.s32 d19, q1, #10 + + vqmovun.s16 \d, q9 +- .endm ++.endm + + function put_h264_qpel16_h_lowpass_neon_packed + mov r4, lr +- mov ip, #16 ++ mov r12, #16 + mov r3, #8 + bl put_h264_qpel8_h_lowpass_neon + sub r1, r1, r2, lsl #4 + add r1, r1, #8 +- mov ip, #16 ++ mov r12, #16 + mov lr, r4 + b put_h264_qpel8_h_lowpass_neon + endfunc + +- .macro h264_qpel_h_lowpass type ++.macro h264_qpel_h_lowpass type + function \type\()_h264_qpel16_h_lowpass_neon + push {lr} +- mov ip, #16 ++ mov r12, #16 + bl \type\()_h264_qpel8_h_lowpass_neon + sub r0, r0, r3, lsl #4 + sub r1, r1, r2, lsl #4 + add r0, r0, #8 + add r1, r1, #8 +- mov ip, #16 ++ mov r12, #16 + pop {lr} + endfunc + + function \type\()_h264_qpel8_h_lowpass_neon +-1: vld1.64 {d0, d1}, [r1], r2 +- vld1.64 {d16,d17}, [r1], r2 +- subs ip, ip, #2 ++1: vld1.8 {d0, d1}, [r1], r2 ++ vld1.8 {d16,d17}, [r1], r2 ++ subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, d0, d16 +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d2}, [r0,:64], r3 + vrhadd.u8 d0, d0, d2 + vld1.8 {d3}, [r0,:64] + vrhadd.u8 d16, d16, d3 + sub r0, r0, r3 +-.endif +- vst1.64 {d0}, [r0,:64], r3 +- vst1.64 {d16}, [r0,:64], r3 ++ .endif ++ vst1.8 {d0}, [r0,:64], r3 ++ vst1.8 {d16}, [r0,:64], r3 + bne 1b + bx lr + endfunc +- .endm ++.endm + + h264_qpel_h_lowpass put + h264_qpel_h_lowpass avg + +- .macro h264_qpel_h_lowpass_l2 type ++.macro h264_qpel_h_lowpass_l2 type + function \type\()_h264_qpel16_h_lowpass_l2_neon + push {lr} +- mov ip, #16 ++ mov r12, #16 + bl \type\()_h264_qpel8_h_lowpass_l2_neon + sub r0, r0, r2, lsl #4 + sub r1, r1, r2, lsl #4 +@@ -820,31 +432,31 @@ + add r0, r0, #8 + add r1, r1, #8 + add r3, r3, #8 +- mov ip, #16 ++ mov r12, #16 + pop {lr} + endfunc + + function \type\()_h264_qpel8_h_lowpass_l2_neon +-1: vld1.64 {d0, d1}, [r1], r2 +- vld1.64 {d16,d17}, [r1], r2 +- vld1.64 {d28}, [r3], r2 +- vld1.64 {d29}, [r3], r2 +- subs ip, ip, #2 ++1: vld1.8 {d0, d1}, [r1], r2 ++ vld1.8 {d16,d17}, [r1], r2 ++ vld1.8 {d28}, [r3], r2 ++ vld1.8 {d29}, [r3], r2 ++ subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, d0, d1 + vrhadd.u8 q0, q0, q14 +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d2}, [r0,:64], r2 + vrhadd.u8 d0, d0, d2 + vld1.8 {d3}, [r0,:64] + vrhadd.u8 d1, d1, d3 + sub r0, r0, r2 +-.endif +- vst1.64 {d0}, [r0,:64], r2 +- vst1.64 {d1}, [r0,:64], r2 ++ .endif ++ vst1.8 {d0}, [r0,:64], r2 ++ vst1.8 {d1}, [r0,:64], r2 + bne 1b + bx lr + endfunc +- .endm ++.endm + + h264_qpel_h_lowpass_l2 put + h264_qpel_h_lowpass_l2 avg +@@ -864,7 +476,7 @@ + b put_h264_qpel8_v_lowpass_neon + endfunc + +- .macro h264_qpel_v_lowpass type ++.macro h264_qpel_v_lowpass type + function \type\()_h264_qpel16_v_lowpass_neon + mov r4, lr + bl \type\()_h264_qpel8_v_lowpass_neon +@@ -881,19 +493,19 @@ + endfunc + + function \type\()_h264_qpel8_v_lowpass_neon +- vld1.64 {d8}, [r1], r3 +- vld1.64 {d10}, [r1], r3 +- vld1.64 {d12}, [r1], r3 +- vld1.64 {d14}, [r1], r3 +- vld1.64 {d22}, [r1], r3 +- vld1.64 {d24}, [r1], r3 +- vld1.64 {d26}, [r1], r3 +- vld1.64 {d28}, [r1], r3 +- vld1.64 {d9}, [r1], r3 +- vld1.64 {d11}, [r1], r3 +- vld1.64 {d13}, [r1], r3 +- vld1.64 {d15}, [r1], r3 +- vld1.64 {d23}, [r1] ++ vld1.8 {d8}, [r1], r3 ++ vld1.8 {d10}, [r1], r3 ++ vld1.8 {d12}, [r1], r3 ++ vld1.8 {d14}, [r1], r3 ++ vld1.8 {d22}, [r1], r3 ++ vld1.8 {d24}, [r1], r3 ++ vld1.8 {d26}, [r1], r3 ++ vld1.8 {d28}, [r1], r3 ++ vld1.8 {d9}, [r1], r3 ++ vld1.8 {d11}, [r1], r3 ++ vld1.8 {d13}, [r1], r3 ++ vld1.8 {d15}, [r1], r3 ++ vld1.8 {d23}, [r1] + + transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 + lowpass_8 d8, d9, d10, d11, d8, d10 +@@ -902,7 +514,7 @@ + lowpass_8 d26, d27, d28, d29, d26, d28 + transpose_8x8 d8, d10, d12, d14, d22, d24, d26, d28 + +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d9}, [r0,:64], r2 + vrhadd.u8 d8, d8, d9 + vld1.8 {d11}, [r0,:64], r2 +@@ -920,34 +532,34 @@ + vld1.8 {d29}, [r0,:64], r2 + vrhadd.u8 d28, d28, d29 + sub r0, r0, r2, lsl #3 +-.endif ++ .endif + +- vst1.64 {d8}, [r0,:64], r2 +- vst1.64 {d10}, [r0,:64], r2 +- vst1.64 {d12}, [r0,:64], r2 +- vst1.64 {d14}, [r0,:64], r2 +- vst1.64 {d22}, [r0,:64], r2 +- vst1.64 {d24}, [r0,:64], r2 +- vst1.64 {d26}, [r0,:64], r2 +- vst1.64 {d28}, [r0,:64], r2 ++ vst1.8 {d8}, [r0,:64], r2 ++ vst1.8 {d10}, [r0,:64], r2 ++ vst1.8 {d12}, [r0,:64], r2 ++ vst1.8 {d14}, [r0,:64], r2 ++ vst1.8 {d22}, [r0,:64], r2 ++ vst1.8 {d24}, [r0,:64], r2 ++ vst1.8 {d26}, [r0,:64], r2 ++ vst1.8 {d28}, [r0,:64], r2 + + bx lr + endfunc +- .endm ++.endm + + h264_qpel_v_lowpass put + h264_qpel_v_lowpass avg + +- .macro h264_qpel_v_lowpass_l2 type ++.macro h264_qpel_v_lowpass_l2 type + function \type\()_h264_qpel16_v_lowpass_l2_neon + mov r4, lr + bl \type\()_h264_qpel8_v_lowpass_l2_neon + sub r1, r1, r3, lsl #2 + bl \type\()_h264_qpel8_v_lowpass_l2_neon + sub r0, r0, r3, lsl #4 +- sub ip, ip, r2, lsl #4 ++ sub r12, r12, r2, lsl #4 + add r0, r0, #8 +- add ip, ip, #8 ++ add r12, r12, #8 + sub r1, r1, r3, lsl #4 + sub r1, r1, r3, lsl #2 + add r1, r1, #8 +@@ -957,19 +569,19 @@ + endfunc + + function \type\()_h264_qpel8_v_lowpass_l2_neon +- vld1.64 {d8}, [r1], r3 +- vld1.64 {d10}, [r1], r3 +- vld1.64 {d12}, [r1], r3 +- vld1.64 {d14}, [r1], r3 +- vld1.64 {d22}, [r1], r3 +- vld1.64 {d24}, [r1], r3 +- vld1.64 {d26}, [r1], r3 +- vld1.64 {d28}, [r1], r3 +- vld1.64 {d9}, [r1], r3 +- vld1.64 {d11}, [r1], r3 +- vld1.64 {d13}, [r1], r3 +- vld1.64 {d15}, [r1], r3 +- vld1.64 {d23}, [r1] ++ vld1.8 {d8}, [r1], r3 ++ vld1.8 {d10}, [r1], r3 ++ vld1.8 {d12}, [r1], r3 ++ vld1.8 {d14}, [r1], r3 ++ vld1.8 {d22}, [r1], r3 ++ vld1.8 {d24}, [r1], r3 ++ vld1.8 {d26}, [r1], r3 ++ vld1.8 {d28}, [r1], r3 ++ vld1.8 {d9}, [r1], r3 ++ vld1.8 {d11}, [r1], r3 ++ vld1.8 {d13}, [r1], r3 ++ vld1.8 {d15}, [r1], r3 ++ vld1.8 {d23}, [r1] + + transpose_8x8 q4, q5, q6, q7, q11, q12, q13, q14 + lowpass_8 d8, d9, d10, d11, d8, d9 +@@ -978,20 +590,20 @@ + lowpass_8 d26, d27, d28, d29, d26, d27 + transpose_8x8 d8, d9, d12, d13, d22, d23, d26, d27 + +- vld1.64 {d0}, [ip], r2 +- vld1.64 {d1}, [ip], r2 +- vld1.64 {d2}, [ip], r2 +- vld1.64 {d3}, [ip], r2 +- vld1.64 {d4}, [ip], r2 ++ vld1.8 {d0}, [r12], r2 ++ vld1.8 {d1}, [r12], r2 ++ vld1.8 {d2}, [r12], r2 ++ vld1.8 {d3}, [r12], r2 ++ vld1.8 {d4}, [r12], r2 + vrhadd.u8 q0, q0, q4 +- vld1.64 {d5}, [ip], r2 ++ vld1.8 {d5}, [r12], r2 + vrhadd.u8 q1, q1, q6 +- vld1.64 {d10}, [ip], r2 ++ vld1.8 {d10}, [r12], r2 + vrhadd.u8 q2, q2, q11 +- vld1.64 {d11}, [ip], r2 ++ vld1.8 {d11}, [r12], r2 + vrhadd.u8 q5, q5, q13 + +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d0, d0, d16 + vld1.8 {d17}, [r0,:64], r3 +@@ -1009,51 +621,51 @@ + vld1.8 {d17}, [r0,:64], r3 + vrhadd.u8 d11, d11, d17 + sub r0, r0, r3, lsl #3 +-.endif ++ .endif + +- vst1.64 {d0}, [r0,:64], r3 +- vst1.64 {d1}, [r0,:64], r3 +- vst1.64 {d2}, [r0,:64], r3 +- vst1.64 {d3}, [r0,:64], r3 +- vst1.64 {d4}, [r0,:64], r3 +- vst1.64 {d5}, [r0,:64], r3 +- vst1.64 {d10}, [r0,:64], r3 +- vst1.64 {d11}, [r0,:64], r3 ++ vst1.8 {d0}, [r0,:64], r3 ++ vst1.8 {d1}, [r0,:64], r3 ++ vst1.8 {d2}, [r0,:64], r3 ++ vst1.8 {d3}, [r0,:64], r3 ++ vst1.8 {d4}, [r0,:64], r3 ++ vst1.8 {d5}, [r0,:64], r3 ++ vst1.8 {d10}, [r0,:64], r3 ++ vst1.8 {d11}, [r0,:64], r3 + + bx lr + endfunc +- .endm ++.endm + + h264_qpel_v_lowpass_l2 put + h264_qpel_v_lowpass_l2 avg + + function put_h264_qpel8_hv_lowpass_neon_top +- lowpass_const ip +- mov ip, #12 +-1: vld1.64 {d0, d1}, [r1], r3 +- vld1.64 {d16,d17}, [r1], r3 +- subs ip, ip, #2 ++ lowpass_const r12 ++ mov r12, #12 ++1: vld1.8 {d0, d1}, [r1], r3 ++ vld1.8 {d16,d17}, [r1], r3 ++ subs r12, r12, #2 + lowpass_8 d0, d1, d16, d17, q11, q12, narrow=0 +- vst1.64 {d22-d25}, [r4,:128]! ++ vst1.8 {d22-d25}, [r4,:128]! + bne 1b + +- vld1.64 {d0, d1}, [r1] ++ vld1.8 {d0, d1}, [r1] + lowpass_8_1 d0, d1, q12, narrow=0 + +- mov ip, #-16 +- add r4, r4, ip +- vld1.64 {d30,d31}, [r4,:128], ip +- vld1.64 {d20,d21}, [r4,:128], ip +- vld1.64 {d18,d19}, [r4,:128], ip +- vld1.64 {d16,d17}, [r4,:128], ip +- vld1.64 {d14,d15}, [r4,:128], ip +- vld1.64 {d12,d13}, [r4,:128], ip +- vld1.64 {d10,d11}, [r4,:128], ip +- vld1.64 {d8, d9}, [r4,:128], ip +- vld1.64 {d6, d7}, [r4,:128], ip +- vld1.64 {d4, d5}, [r4,:128], ip +- vld1.64 {d2, d3}, [r4,:128], ip +- vld1.64 {d0, d1}, [r4,:128] ++ mov r12, #-16 ++ add r4, r4, r12 ++ vld1.8 {d30,d31}, [r4,:128], r12 ++ vld1.8 {d20,d21}, [r4,:128], r12 ++ vld1.8 {d18,d19}, [r4,:128], r12 ++ vld1.8 {d16,d17}, [r4,:128], r12 ++ vld1.8 {d14,d15}, [r4,:128], r12 ++ vld1.8 {d12,d13}, [r4,:128], r12 ++ vld1.8 {d10,d11}, [r4,:128], r12 ++ vld1.8 {d8, d9}, [r4,:128], r12 ++ vld1.8 {d6, d7}, [r4,:128], r12 ++ vld1.8 {d4, d5}, [r4,:128], r12 ++ vld1.8 {d2, d3}, [r4,:128], r12 ++ vld1.8 {d0, d1}, [r4,:128] + + swap4 d1, d3, d5, d7, d8, d10, d12, d14 + transpose16_4x4 q0, q1, q2, q3, q4, q5, q6, q7 +@@ -1061,31 +673,31 @@ + swap4 d17, d19, d21, d31, d24, d26, d28, d22 + transpose16_4x4 q8, q9, q10, q15, q12, q13, q14, q11 + +- vst1.64 {d30,d31}, [r4,:128]! +- vst1.64 {d6, d7}, [r4,:128]! +- vst1.64 {d20,d21}, [r4,:128]! +- vst1.64 {d4, d5}, [r4,:128]! +- vst1.64 {d18,d19}, [r4,:128]! +- vst1.64 {d2, d3}, [r4,:128]! +- vst1.64 {d16,d17}, [r4,:128]! +- vst1.64 {d0, d1}, [r4,:128] ++ vst1.8 {d30,d31}, [r4,:128]! ++ vst1.8 {d6, d7}, [r4,:128]! ++ vst1.8 {d20,d21}, [r4,:128]! ++ vst1.8 {d4, d5}, [r4,:128]! ++ vst1.8 {d18,d19}, [r4,:128]! ++ vst1.8 {d2, d3}, [r4,:128]! ++ vst1.8 {d16,d17}, [r4,:128]! ++ vst1.8 {d0, d1}, [r4,:128] + + lowpass_8.16 q4, q12, d8, d9, d24, d25, d8 + lowpass_8.16 q5, q13, d10, d11, d26, d27, d9 + lowpass_8.16 q6, q14, d12, d13, d28, d29, d10 + lowpass_8.16 q7, q11, d14, d15, d22, d23, d11 + +- vld1.64 {d16,d17}, [r4,:128], ip +- vld1.64 {d30,d31}, [r4,:128], ip ++ vld1.8 {d16,d17}, [r4,:128], r12 ++ vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d12 +- vld1.64 {d16,d17}, [r4,:128], ip +- vld1.64 {d30,d31}, [r4,:128], ip ++ vld1.8 {d16,d17}, [r4,:128], r12 ++ vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d13 +- vld1.64 {d16,d17}, [r4,:128], ip +- vld1.64 {d30,d31}, [r4,:128], ip ++ vld1.8 {d16,d17}, [r4,:128], r12 ++ vld1.8 {d30,d31}, [r4,:128], r12 + lowpass_8.16 q8, q15, d16, d17, d30, d31, d14 +- vld1.64 {d16,d17}, [r4,:128], ip +- vld1.64 {d30,d31}, [r4,:128] ++ vld1.8 {d16,d17}, [r4,:128], r12 ++ vld1.8 {d30,d31}, [r4,:128] + lowpass_8.16 q8, q15, d16, d17, d30, d31, d15 + + transpose_8x8 d12, d13, d14, d15, d8, d9, d10, d11 +@@ -1093,11 +705,11 @@ + bx lr + endfunc + +- .macro h264_qpel8_hv_lowpass type ++.macro h264_qpel8_hv_lowpass type + function \type\()_h264_qpel8_hv_lowpass_neon + mov r10, lr + bl put_h264_qpel8_hv_lowpass_neon_top +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d0}, [r0,:64], r2 + vrhadd.u8 d12, d12, d0 + vld1.8 {d1}, [r0,:64], r2 +@@ -1115,38 +727,39 @@ + vld1.8 {d7}, [r0,:64], r2 + vrhadd.u8 d11, d11, d7 + sub r0, r0, r2, lsl #3 +-.endif +- vst1.64 {d12}, [r0,:64], r2 +- vst1.64 {d13}, [r0,:64], r2 +- vst1.64 {d14}, [r0,:64], r2 +- vst1.64 {d15}, [r0,:64], r2 +- vst1.64 {d8}, [r0,:64], r2 +- vst1.64 {d9}, [r0,:64], r2 +- vst1.64 {d10}, [r0,:64], r2 +- vst1.64 {d11}, [r0,:64], r2 ++ .endif ++ ++ vst1.8 {d12}, [r0,:64], r2 ++ vst1.8 {d13}, [r0,:64], r2 ++ vst1.8 {d14}, [r0,:64], r2 ++ vst1.8 {d15}, [r0,:64], r2 ++ vst1.8 {d8}, [r0,:64], r2 ++ vst1.8 {d9}, [r0,:64], r2 ++ vst1.8 {d10}, [r0,:64], r2 ++ vst1.8 {d11}, [r0,:64], r2 + + mov lr, r10 + bx lr + endfunc +- .endm ++.endm + + h264_qpel8_hv_lowpass put + h264_qpel8_hv_lowpass avg + +- .macro h264_qpel8_hv_lowpass_l2 type ++.macro h264_qpel8_hv_lowpass_l2 type + function \type\()_h264_qpel8_hv_lowpass_l2_neon + mov r10, lr + bl put_h264_qpel8_hv_lowpass_neon_top + +- vld1.64 {d0, d1}, [r2,:128]! +- vld1.64 {d2, d3}, [r2,:128]! ++ vld1.8 {d0, d1}, [r2,:128]! ++ vld1.8 {d2, d3}, [r2,:128]! + vrhadd.u8 q0, q0, q6 +- vld1.64 {d4, d5}, [r2,:128]! ++ vld1.8 {d4, d5}, [r2,:128]! + vrhadd.u8 q1, q1, q7 +- vld1.64 {d6, d7}, [r2,:128]! ++ vld1.8 {d6, d7}, [r2,:128]! + vrhadd.u8 q2, q2, q4 + vrhadd.u8 q3, q3, q5 +-.ifc \type,avg ++ .ifc \type,avg + vld1.8 {d16}, [r0,:64], r3 + vrhadd.u8 d0, d0, d16 + vld1.8 {d17}, [r0,:64], r3 +@@ -1164,25 +777,25 @@ + vld1.8 {d23}, [r0,:64], r3 + vrhadd.u8 d7, d7, d23 + sub r0, r0, r3, lsl #3 +-.endif +- vst1.64 {d0}, [r0,:64], r3 +- vst1.64 {d1}, [r0,:64], r3 +- vst1.64 {d2}, [r0,:64], r3 +- vst1.64 {d3}, [r0,:64], r3 +- vst1.64 {d4}, [r0,:64], r3 +- vst1.64 {d5}, [r0,:64], r3 +- vst1.64 {d6}, [r0,:64], r3 +- vst1.64 {d7}, [r0,:64], r3 ++ .endif ++ vst1.8 {d0}, [r0,:64], r3 ++ vst1.8 {d1}, [r0,:64], r3 ++ vst1.8 {d2}, [r0,:64], r3 ++ vst1.8 {d3}, [r0,:64], r3 ++ vst1.8 {d4}, [r0,:64], r3 ++ vst1.8 {d5}, [r0,:64], r3 ++ vst1.8 {d6}, [r0,:64], r3 ++ vst1.8 {d7}, [r0,:64], r3 + + mov lr, r10 + bx lr + endfunc +- .endm ++.endm + + h264_qpel8_hv_lowpass_l2 put + h264_qpel8_hv_lowpass_l2 avg + +- .macro h264_qpel16_hv type ++.macro h264_qpel16_hv type + function \type\()_h264_qpel16_hv_lowpass_neon + mov r9, lr + bl \type\()_h264_qpel8_hv_lowpass_neon +@@ -1215,17 +828,17 @@ + mov lr, r9 + b \type\()_h264_qpel8_hv_lowpass_l2_neon + endfunc +- .endm ++.endm + + h264_qpel16_hv put + h264_qpel16_hv avg + +- .macro h264_qpel8 type ++.macro h264_qpel8 type + function ff_\type\()_h264_qpel8_mc10_neon, export=1 + lowpass_const r3 + mov r3, r1 + sub r1, r1, #2 +- mov ip, #8 ++ mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_l2_neon + endfunc + +@@ -1233,7 +846,7 @@ + lowpass_const r3 + sub r1, r1, #2 + mov r3, r2 +- mov ip, #8 ++ mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_neon + endfunc + +@@ -1241,13 +854,13 @@ + lowpass_const r3 + add r3, r1, #1 + sub r1, r1, #2 +- mov ip, #8 ++ mov r12, #8 + b \type\()_h264_qpel8_h_lowpass_l2_neon + endfunc + + function ff_\type\()_h264_qpel8_mc01_neon, export=1 + push {lr} +- mov ip, r1 ++ mov r12, r1 + \type\()_h264_qpel8_mc01: + lowpass_const r3 + mov r3, r2 +@@ -1263,22 +876,24 @@ + \type\()_h264_qpel8_mc11: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #64 + mov r0, sp + sub r1, r1, #2 + mov r3, #8 +- mov ip, #8 ++ mov r12, #8 + vpush {d8-d15} + bl put_h264_qpel8_h_lowpass_neon +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + mov r3, r2 +- add ip, sp, #64 ++ add r12, sp, #64 + sub r1, r1, r2, lsl #1 + mov r2, #8 + bl \type\()_h264_qpel8_v_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r11, pc} + endfunc + +@@ -1287,23 +902,25 @@ + \type\()_h264_qpel8_mc21: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #(8*8+16*12) + sub r1, r1, #2 + mov r3, #8 + mov r0, sp +- mov ip, #8 ++ mov r12, #8 + vpush {d8-d15} + bl put_h264_qpel8_h_lowpass_neon + mov r4, r0 +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + sub r2, r4, #64 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r4, r10, r11, pc} + endfunc + +@@ -1330,7 +947,9 @@ + \type\()_h264_qpel8_mc12: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #(8*8+16*12) + sub r1, r1, r2, lsl #1 + mov r3, r2 +@@ -1339,20 +958,22 @@ + vpush {d8-d15} + bl put_h264_qpel8_v_lowpass_neon + mov r4, r0 +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + sub r1, r1, r3, lsl #1 + sub r1, r1, #2 + sub r2, r4, #64 + bl \type\()_h264_qpel8_hv_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r4, r10, r11, pc} + endfunc + + function ff_\type\()_h264_qpel8_mc22_neon, export=1 + push {r4, r10, r11, lr} + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r4, r11, #15 ++T mov sp, r4 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 +@@ -1373,7 +994,7 @@ + + function ff_\type\()_h264_qpel8_mc03_neon, export=1 + push {lr} +- add ip, r1, r2 ++ add r12, r1, r2 + b \type\()_h264_qpel8_mc01 + endfunc + +@@ -1396,12 +1017,12 @@ + sub r1, r1, #1 + b \type\()_h264_qpel8_mc11 + endfunc +- .endm ++.endm + + h264_qpel8 put + h264_qpel8 avg + +- .macro h264_qpel16 type ++.macro h264_qpel16 type + function ff_\type\()_h264_qpel16_mc10_neon, export=1 + lowpass_const r3 + mov r3, r1 +@@ -1425,7 +1046,7 @@ + + function ff_\type\()_h264_qpel16_mc01_neon, export=1 + push {r4, lr} +- mov ip, r1 ++ mov r12, r1 + \type\()_h264_qpel16_mc01: + lowpass_const r3 + mov r3, r2 +@@ -1441,21 +1062,23 @@ + \type\()_h264_qpel16_mc11: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #256 + mov r0, sp + sub r1, r1, #2 + mov r3, #16 + vpush {d8-d15} + bl put_h264_qpel16_h_lowpass_neon +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + mov r3, r2 +- add ip, sp, #64 ++ add r12, sp, #64 + sub r1, r1, r2, lsl #1 + mov r2, #16 + bl \type\()_h264_qpel16_v_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r4, r11, pc} + endfunc + +@@ -1464,20 +1087,22 @@ + \type\()_h264_qpel16_mc21: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #(16*16+16*12) + sub r1, r1, #2 + mov r0, sp + vpush {d8-d15} + bl put_h264_qpel16_h_lowpass_neon_packed + mov r4, r0 +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 + bl \type\()_h264_qpel16_hv_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r4-r5, r9-r11, pc} + endfunc + +@@ -1504,7 +1129,9 @@ + \type\()_h264_qpel16_mc12: + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r0, r11, #15 ++T mov sp, r0 + sub sp, sp, #(16*16+16*12) + sub r1, r1, r2, lsl #1 + mov r0, sp +@@ -1512,13 +1139,13 @@ + vpush {d8-d15} + bl put_h264_qpel16_v_lowpass_neon_packed + mov r4, r0 +- ldrd r0, [r11] ++ ldrd r0, [r11], #8 + sub r1, r1, r3, lsl #1 + sub r1, r1, #2 + mov r2, r3 + bl \type\()_h264_qpel16_hv_lowpass_l2_neon + vpop {d8-d15} +- add sp, r11, #8 ++ mov sp, r11 + pop {r4-r5, r9-r11, pc} + endfunc + +@@ -1526,7 +1153,9 @@ + push {r4, r9-r11, lr} + lowpass_const r3 + mov r11, sp +- bic sp, sp, #15 ++A bic sp, sp, #15 ++T bic r4, r11, #15 ++T mov sp, r4 + sub r1, r1, r2, lsl #1 + sub r1, r1, #2 + mov r3, r2 +@@ -1547,7 +1176,7 @@ + + function ff_\type\()_h264_qpel16_mc03_neon, export=1 + push {r4, lr} +- add ip, r1, r2 ++ add r12, r1, r2 + b \type\()_h264_qpel16_mc01 + endfunc + +@@ -1570,19 +1199,19 @@ + sub r1, r1, #1 + b \type\()_h264_qpel16_mc11 + endfunc +- .endm ++.endm + + h264_qpel16 put + h264_qpel16 avg + + @ Biweighted prediction + +- .macro biweight_16 macs, macd ++.macro biweight_16 macs, macd + vdup.8 d0, r4 + vdup.8 d1, r5 + vmov q2, q8 + vmov q3, q8 +-1: subs ip, ip, #2 ++1: subs r3, r3, #2 + vld1.8 {d20-d21},[r0,:128], r2 + \macd q2, d0, d20 + pld [r0] +@@ -1615,14 +1244,14 @@ + vst1.8 {d24-d25},[r6,:128], r2 + bne 1b + pop {r4-r6, pc} +- .endm ++.endm + +- .macro biweight_8 macs, macd ++.macro biweight_8 macs, macd + vdup.8 d0, r4 + vdup.8 d1, r5 + vmov q1, q8 + vmov q10, q8 +-1: subs ip, ip, #2 ++1: subs r3, r3, #2 + vld1.8 {d4},[r0,:64], r2 + \macd q1, d0, d4 + pld [r0] +@@ -1645,14 +1274,14 @@ + vst1.8 {d4},[r6,:64], r2 + bne 1b + pop {r4-r6, pc} +- .endm ++.endm + +- .macro biweight_4 macs, macd ++.macro biweight_4 macs, macd + vdup.8 d0, r4 + vdup.8 d1, r5 + vmov q1, q8 + vmov q10, q8 +-1: subs ip, ip, #4 ++1: subs r3, r3, #4 + vld1.32 {d4[0]},[r0,:32], r2 + vld1.32 {d4[1]},[r0,:32], r2 + \macd q1, d0, d4 +@@ -1687,19 +1316,20 @@ + vst1.32 {d2[0]},[r6,:32], r2 + vst1.32 {d2[1]},[r6,:32], r2 + pop {r4-r6, pc} +- .endm ++.endm + +- .macro biweight_func w +-function biweight_h264_pixels_\w\()_neon ++.macro biweight_func w ++function ff_biweight_h264_pixels_\w\()_neon, export=1 + push {r4-r6, lr} +- add r4, sp, #16 ++ ldr r12, [sp, #16] ++ add r4, sp, #20 + ldm r4, {r4-r6} + lsr lr, r4, #31 + add r6, r6, #1 + eors lr, lr, r5, lsr #30 + orr r6, r6, #1 +- vdup.16 q9, r3 +- lsl r6, r6, r3 ++ vdup.16 q9, r12 ++ lsl r6, r6, r12 + vmvn q9, q9 + vdup.16 q8, r6 + mov r6, r0 +@@ -1718,36 +1348,17 @@ + 40: rsb r5, r5, #0 + biweight_\w vmlsl.u8, vmlal.u8 + endfunc +- .endm +- +- .macro biweight_entry w, h, b=1 +-function ff_biweight_h264_pixels_\w\()x\h\()_neon, export=1 +- mov ip, #\h +-.if \b +- b biweight_h264_pixels_\w\()_neon +-.endif +-endfunc +- .endm ++.endm + +- biweight_entry 16, 8 +- biweight_entry 16, 16, b=0 + biweight_func 16 +- +- biweight_entry 8, 16 +- biweight_entry 8, 4 +- biweight_entry 8, 8, b=0 + biweight_func 8 +- +- biweight_entry 4, 8 +- biweight_entry 4, 2 +- biweight_entry 4, 4, b=0 + biweight_func 4 + + @ Weighted prediction + +- .macro weight_16 add +- vdup.8 d0, r3 +-1: subs ip, ip, #2 ++.macro weight_16 add ++ vdup.8 d0, r12 ++1: subs r2, r2, #2 + vld1.8 {d20-d21},[r0,:128], r1 + vmull.u8 q2, d0, d20 + pld [r0] +@@ -1772,11 +1383,11 @@ + vst1.8 {d24-d25},[r4,:128], r1 + bne 1b + pop {r4, pc} +- .endm ++.endm + +- .macro weight_8 add +- vdup.8 d0, r3 +-1: subs ip, ip, #2 ++.macro weight_8 add ++ vdup.8 d0, r12 ++1: subs r2, r2, #2 + vld1.8 {d4},[r0,:64], r1 + vmull.u8 q1, d0, d4 + pld [r0] +@@ -1793,13 +1404,13 @@ + vst1.8 {d4},[r4,:64], r1 + bne 1b + pop {r4, pc} +- .endm ++.endm + +- .macro weight_4 add +- vdup.8 d0, r3 ++.macro weight_4 add ++ vdup.8 d0, r12 + vmov q1, q8 + vmov q10, q8 +-1: subs ip, ip, #4 ++1: subs r2, r2, #4 + vld1.32 {d4[0]},[r0,:32], r1 + vld1.32 {d4[1]},[r0,:32], r1 + vmull.u8 q1, d0, d4 +@@ -1829,53 +1440,35 @@ + vst1.32 {d2[0]},[r4,:32], r1 + vst1.32 {d2[1]},[r4,:32], r1 + pop {r4, pc} +- .endm ++.endm + +- .macro weight_func w +-function weight_h264_pixels_\w\()_neon ++.macro weight_func w ++function ff_weight_h264_pixels_\w\()_neon, export=1 + push {r4, lr} +- ldr r4, [sp, #8] +- cmp r2, #1 +- lsl r4, r4, r2 ++ ldr r12, [sp, #8] ++ ldr r4, [sp, #12] ++ cmp r3, #1 ++ lsl r4, r4, r3 + vdup.16 q8, r4 + mov r4, r0 + ble 20f +- rsb lr, r2, #1 ++ rsb lr, r3, #1 + vdup.16 q9, lr +- cmp r3, #0 ++ cmp r12, #0 + blt 10f + weight_\w vhadd.s16 +-10: rsb r3, r3, #0 ++10: rsb r12, r12, #0 + weight_\w vhsub.s16 +-20: rsb lr, r2, #0 ++20: rsb lr, r3, #0 + vdup.16 q9, lr +- cmp r3, #0 ++ cmp r12, #0 + blt 10f + weight_\w vadd.s16 +-10: rsb r3, r3, #0 ++10: rsb r12, r12, #0 + weight_\w vsub.s16 + endfunc +- .endm +- +- .macro weight_entry w, h, b=1 +-function ff_weight_h264_pixels_\w\()x\h\()_neon, export=1 +- mov ip, #\h +-.if \b +- b weight_h264_pixels_\w\()_neon +-.endif +-endfunc +- .endm ++.endm + +- weight_entry 16, 8 +- weight_entry 16, 16, b=0 + weight_func 16 +- +- weight_entry 8, 16 +- weight_entry 8, 4 +- weight_entry 8, 8, b=0 + weight_func 8 +- +- weight_entry 4, 8 +- weight_entry 4, 2 +- weight_entry 4, 4, b=0 + weight_func 4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264idct_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264idct_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264idct_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264idct_neon.S 2012-05-14 14:08:53.434321868 +0200 +@@ -21,7 +21,6 @@ + #include "asm.S" + + preserve8 +- .text + + function ff_h264_idct_add_neon, export=1 + vld1.64 {d0-d3}, [r1,:128] +@@ -97,7 +96,7 @@ + mov r1, r2 + mov r2, r3 + ldr r6, [sp, #24] +- adr r7, scan8 ++ movrel r7, scan8 + mov ip, #16 + 1: ldrb r8, [r7], #1 + ldr r0, [r5], #4 +@@ -106,10 +105,12 @@ + blt 2f + ldrsh lr, [r1] + add r0, r0, r4 ++ it ne + movne lr, #0 + cmp lr, #0 +- adrne lr, ff_h264_idct_dc_add_neon +- adreq lr, ff_h264_idct_add_neon ++ ite ne ++ adrne lr, ff_h264_idct_dc_add_neon + CONFIG_THUMB ++ adreq lr, ff_h264_idct_add_neon + CONFIG_THUMB + blx lr + 2: subs ip, ip, #1 + add r1, r1, #32 +@@ -117,16 +118,6 @@ + pop {r4-r8,pc} + endfunc + +- .align +-scan8: .byte 4+1*8, 5+1*8, 4+2*8, 5+2*8 +- .byte 6+1*8, 7+1*8, 6+2*8, 7+2*8 +- .byte 4+3*8, 5+3*8, 4+4*8, 5+4*8 +- .byte 6+3*8, 7+3*8, 6+4*8, 7+4*8 +- .byte 1+1*8, 2+1*8 +- .byte 1+2*8, 2+2*8 +- .byte 1+4*8, 2+4*8 +- .byte 1+5*8, 2+5*8 +- + function ff_h264_idct_add16intra_neon, export=1 + push {r4-r8,lr} + mov r4, r0 +@@ -134,7 +125,7 @@ + mov r1, r2 + mov r2, r3 + ldr r6, [sp, #24] +- adr r7, scan8 ++ movrel r7, scan8 + mov ip, #16 + 1: ldrb r8, [r7], #1 + ldr r0, [r5], #4 +@@ -142,8 +133,9 @@ + add r0, r0, r4 + cmp r8, #0 + ldrsh r8, [r1] +- adrne lr, ff_h264_idct_add_neon +- adreq lr, ff_h264_idct_dc_add_neon ++ iteet ne ++ adrne lr, ff_h264_idct_add_neon + CONFIG_THUMB ++ adreq lr, ff_h264_idct_dc_add_neon + CONFIG_THUMB + cmpeq r8, #0 + blxne lr + subs ip, ip, #1 +@@ -158,24 +150,29 @@ + add r5, r1, #16*4 + add r1, r2, #16*32 + mov r2, r3 ++ mov r3, r1 + ldr r6, [sp, #32] +- adr r7, scan8+16 +- mov ip, #7 +-1: ldrb r8, [r7], #1 +- ldr r0, [r5], #4 ++ movrel r7, scan8+16 ++ mov r12, #0 ++1: ldrb r8, [r7, r12] ++ ldr r0, [r5, r12, lsl #2] + ldrb r8, [r6, r8] +- tst ip, #4 +- addne r0, r0, r4 +- addeq r0, r0, r9 ++ add r0, r0, r4 ++ add r1, r3, r12, lsl #5 + cmp r8, #0 + ldrsh r8, [r1] +- adrne lr, ff_h264_idct_add_neon +- adreq lr, ff_h264_idct_dc_add_neon ++ iteet ne ++ adrne lr, ff_h264_idct_add_neon + CONFIG_THUMB ++ adreq lr, ff_h264_idct_dc_add_neon + CONFIG_THUMB + cmpeq r8, #0 + blxne lr +- subs ip, ip, #1 +- add r1, r1, #32 +- bge 1b ++ add r12, r12, #1 ++ cmp r12, #4 ++ itt eq ++ moveq r12, #16 ++ moveq r4, r9 ++ cmp r12, #20 ++ blt 1b + pop {r4-r10,pc} + endfunc + +@@ -363,7 +360,7 @@ + mov r1, r2 + mov r2, r3 + ldr r6, [sp, #24] +- adr r7, scan8 ++ movrel r7, scan8 + mov r12, #16 + 1: ldrb r8, [r7], #4 + ldr r0, [r5], #16 +@@ -372,13 +369,30 @@ + blt 2f + ldrsh lr, [r1] + add r0, r0, r4 ++ it ne + movne lr, #0 + cmp lr, #0 +- adrne lr, ff_h264_idct8_dc_add_neon +- adreq lr, ff_h264_idct8_add_neon ++ ite ne ++ adrne lr, ff_h264_idct8_dc_add_neon + CONFIG_THUMB ++ adreq lr, ff_h264_idct8_add_neon + CONFIG_THUMB + blx lr + 2: subs r12, r12, #4 + add r1, r1, #128 + bne 1b + pop {r4-r8,pc} + endfunc ++ ++const scan8 ++ .byte 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 ++ .byte 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8 ++ .byte 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8 ++ .byte 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8 ++ .byte 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8 ++ .byte 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8 ++ .byte 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8 ++ .byte 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8 ++ .byte 4+11*8, 5+11*8, 4+12*8, 5+12*8 ++ .byte 6+11*8, 7+11*8, 6+12*8, 7+12*8 ++ .byte 4+13*8, 5+13*8, 4+14*8, 5+14*8 ++ .byte 6+13*8, 7+13*8, 6+14*8, 7+14*8 ++endconst +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264pred_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264pred_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264pred_init_arm.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264pred_init_arm.c 2012-05-14 14:08:53.434321868 +0200 +@@ -42,8 +42,13 @@ + void ff_pred8x8_l00_dc_neon(uint8_t *src, int stride); + void ff_pred8x8_0l0_dc_neon(uint8_t *src, int stride); + +-static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id) ++static void ff_h264_pred_init_neon(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc) + { ++ const int high_depth = bit_depth > 8; ++ ++ if (high_depth) ++ return; ++ if(chroma_format_idc == 1){ + h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vert_neon; + h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_hor_neon; + if (codec_id != CODEC_ID_VP8) +@@ -58,6 +63,7 @@ + h->pred8x8[ALZHEIMER_DC_L00_PRED8x8] = ff_pred8x8_l00_dc_neon; + h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8] = ff_pred8x8_0l0_dc_neon; + } ++ } + + h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_neon; + h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vert_neon; +@@ -69,7 +75,7 @@ + h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_neon; + } + +-void ff_h264_pred_init_arm(H264PredContext *h, int codec_id) ++void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, int bit_depth, const int chroma_format_idc) + { +- if (HAVE_NEON) ff_h264_pred_init_neon(h, codec_id); ++ if (HAVE_NEON) ff_h264_pred_init_neon(h, codec_id, bit_depth, chroma_format_idc); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264pred_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264pred_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/h264pred_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/h264pred_neon.S 2012-05-14 14:08:53.435321888 +0200 +@@ -123,7 +123,7 @@ + vaddl.u8 q8, d2, d3 + vsubl.u8 q2, d2, d0 + vsubl.u8 q3, d3, d1 +- adr r3, p16weight ++ movrel r3, p16weight + vld1.8 {q0}, [r3,:128] + vmul.s16 q2, q2, q0 + vmul.s16 q3, q3, q0 +@@ -166,11 +166,9 @@ + bx lr + endfunc + +- .align 4 +-p16weight: ++const p16weight, align=4 + .short 1,2,3,4,5,6,7,8 +- +- .text ++endconst + + function ff_pred8x8_hor_neon, export=1 + sub r2, r0, #1 +@@ -206,7 +204,7 @@ + vrev32.8 d0, d0 + vtrn.32 d2, d3 + vsubl.u8 q2, d2, d0 +- adr r3, p16weight ++ movrel r3, p16weight + vld1.16 {q0}, [r3,:128] + vmul.s16 d4, d4, d0 + vmul.s16 d5, d5, d0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/int_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/int_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/int_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/int_neon.S 2012-05-14 14:08:53.436321908 +0200 +@@ -23,7 +23,6 @@ + + preserve8 + .fpu neon +- .text + + function ff_scalarproduct_int16_neon, export=1 + vmov.i16 q0, #0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/jrevdct_arm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/jrevdct_arm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/jrevdct_arm.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/jrevdct_arm.S 2012-05-14 14:08:53.437321928 +0200 +@@ -54,18 +54,13 @@ + #define FIX_M_1_961570560_ID 40 + #define FIX_M_2_562915447_ID 44 + #define FIX_0xFFFF_ID 48 +- .text +- .align + + function ff_j_rev_dct_arm, export=1 +- stmdb sp!, { r4 - r12, lr } @ all callee saved regs +- +- sub sp, sp, #4 @ reserve some space on the stack +- str r0, [ sp ] @ save the DCT pointer to the stack ++ push {r0, r4 - r11, lr} + + mov lr, r0 @ lr = pointer to the current row + mov r12, #8 @ r12 = row-counter +- adr r11, const_array @ r11 = base pointer to the constants array ++ movrel r11, const_array @ r11 = base pointer to the constants array + row_loop: + ldrsh r0, [lr, # 0] @ r0 = 'd0' + ldrsh r2, [lr, # 2] @ r2 = 'd2' +@@ -102,7 +97,7 @@ + add r4, r6, r3, lsl #13 @ r4 = tmp11 + rsb r3, r6, r3, lsl #13 @ r3 = tmp12 + +- stmdb sp!, { r0, r2, r3, r4 } @ save on the stack tmp10, tmp13, tmp12, tmp11 ++ push {r0, r2, r3, r4} @ save on the stack tmp10, tmp13, tmp12, tmp11 + + ldrsh r3, [lr, #10] @ r3 = 'd3' + ldrsh r5, [lr, #12] @ r5 = 'd5' +@@ -136,8 +131,8 @@ + add r3, r3, r4 @ r3 = tmp2 + add r1, r1, r6 @ r1 = tmp3 + +- ldmia sp!, { r0, r2, r4, r6 } @ r0 = tmp10 / r2 = tmp13 / r4 = tmp12 / r6 = tmp11 +- @ r1 = tmp3 / r3 = tmp2 / r5 = tmp1 / r7 = tmp0 ++ pop {r0, r2, r4, r6} @ r0 = tmp10 / r2 = tmp13 / r4 = tmp12 / r6 = tmp11 ++ @ r1 = tmp3 / r3 = tmp2 / r5 = tmp1 / r7 = tmp0 + + @ Compute DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS) + add r8, r0, r1 +@@ -211,7 +206,7 @@ + + start_column_loop: + @ Start of column loop +- ldr lr, [ sp ] ++ pop {lr} + mov r12, #8 + column_loop: + ldrsh r0, [lr, #( 0*8)] @ r0 = 'd0' +@@ -245,7 +240,7 @@ + orrs r10, r9, r10 + beq empty_odd_column + +- stmdb sp!, { r0, r2, r4, r6 } @ save on the stack tmp10, tmp13, tmp12, tmp11 ++ push {r0, r2, r4, r6} @ save on the stack tmp10, tmp13, tmp12, tmp11 + + add r0, r3, r5 @ r0 = 'z2' + add r2, r1, r7 @ r2 = 'z1' +@@ -275,8 +270,8 @@ + add r3, r3, r4 @ r3 = tmp2 + add r1, r1, r6 @ r1 = tmp3 + +- ldmia sp!, { r0, r2, r4, r6 } @ r0 = tmp10 / r2 = tmp13 / r4 = tmp11 / r6 = tmp12 +- @ r1 = tmp3 / r3 = tmp2 / r5 = tmp1 / r7 = tmp0 ++ pop {r0, r2, r4, r6} @ r0 = tmp10 / r2 = tmp13 / r4 = tmp11 / r6 = tmp12 ++ @ r1 = tmp3 / r3 = tmp2 / r5 = tmp1 / r7 = tmp0 + + @ Compute DESCALE(tmp10 + tmp3, CONST_BITS+PASS1_BITS+3) + add r8, r0, r1 +@@ -368,11 +363,10 @@ + + the_end: + @ The end.... +- add sp, sp, #4 +- ldmia sp!, { r4 - r12, pc } @ restore callee saved regs and return ++ pop {r4 - r11, pc} ++endfunc + +-const_array: +- .align ++const const_array + .word FIX_0_298631336 + .word FIX_0_541196100 + .word FIX_0_765366865 +@@ -386,3 +380,4 @@ + .word FIX_M_1_961570560 + .word FIX_M_2_562915447 + .word FIX_0xFFFF ++endconst +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/Makefile 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/Makefile 2012-05-14 14:08:53.389320962 +0200 +@@ -1,7 +1,18 @@ ++OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_init_arm.o \ ++ arm/ac3dsp_arm.o ++ + OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_init_arm.o \ + ++ARMV6-OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_armv6.o ++ ++OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_init_arm.o ++ARMV6-OBJS-$(CONFIG_MPEGAUDIODSP) += arm/mpegaudiodsp_fixed_armv6.o ++ + OBJS-$(CONFIG_VP5_DECODER) += arm/vp56dsp_init_arm.o + OBJS-$(CONFIG_VP6_DECODER) += arm/vp56dsp_init_arm.o ++OBJS-$(CONFIG_VP8_DECODER) += arm/vp8dsp_init_arm.o ++ARMV6-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8_armv6.o \ ++ arm/vp8dsp_armv6.o + + OBJS-$(CONFIG_H264DSP) += arm/h264dsp_init_arm.o + OBJS-$(CONFIG_H264PRED) += arm/h264pred_init_arm.o +@@ -9,6 +20,7 @@ + OBJS += arm/dsputil_init_arm.o \ + arm/dsputil_arm.o \ + arm/fft_init_arm.o \ ++ arm/fft_fixed_init_arm.o \ + arm/fmtconvert_init_arm.o \ + arm/jrevdct_arm.o \ + arm/mpegvideo_arm.o \ +@@ -22,6 +34,7 @@ + OBJS-$(HAVE_ARMV6) += arm/dsputil_init_armv6.o \ + arm/dsputil_armv6.o \ + arm/simple_idct_armv6.o \ ++ $(ARMV6-OBJS-yes) + + VFP-OBJS-$(HAVE_ARMV6) += arm/fmtconvert_vfp.o \ + +@@ -33,19 +46,33 @@ + arm/mpegvideo_iwmmxt.o \ + + NEON-OBJS-$(CONFIG_FFT) += arm/fft_neon.o \ ++ arm/fft_fixed_neon.o \ + + NEON-OBJS-$(CONFIG_MDCT) += arm/mdct_neon.o \ ++ arm/mdct_fixed_neon.o \ + + NEON-OBJS-$(CONFIG_RDFT) += arm/rdft_neon.o \ + + NEON-OBJS-$(CONFIG_H264DSP) += arm/h264dsp_neon.o \ + arm/h264idct_neon.o \ ++ arm/h264cmc_neon.o \ + + NEON-OBJS-$(CONFIG_H264PRED) += arm/h264pred_neon.o \ + ++NEON-OBJS-$(CONFIG_AC3DSP) += arm/ac3dsp_neon.o ++ + NEON-OBJS-$(CONFIG_DCA_DECODER) += arm/dcadsp_neon.o \ + arm/synth_filter_neon.o \ + ++NEON-OBJS-$(CONFIG_RV30_DECODER) += arm/rv34dsp_init_neon.o \ ++ arm/rv34dsp_neon.o \ ++ ++NEON-OBJS-$(CONFIG_RV40_DECODER) += arm/rv34dsp_init_neon.o \ ++ arm/rv34dsp_neon.o \ ++ arm/rv40dsp_init_neon.o \ ++ arm/rv40dsp_neon.o \ ++ arm/h264cmc_neon.o \ ++ + NEON-OBJS-$(CONFIG_VP3_DECODER) += arm/vp3dsp_neon.o + + NEON-OBJS-$(CONFIG_VP5_DECODER) += arm/vp56dsp_neon.o \ +@@ -54,6 +81,8 @@ + NEON-OBJS-$(CONFIG_VP6_DECODER) += arm/vp56dsp_neon.o \ + arm/vp3dsp_neon.o \ + ++NEON-OBJS-$(CONFIG_VP8_DECODER) += arm/vp8dsp_neon.o ++ + OBJS-$(HAVE_NEON) += arm/dsputil_init_neon.o \ + arm/dsputil_neon.o \ + arm/fmtconvert_neon.o \ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mathops.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mathops.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mathops.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mathops.h 2012-05-14 14:08:53.437321928 +0200 +@@ -28,52 +28,16 @@ + + #if HAVE_INLINE_ASM + +-# define MULL MULL +-static inline av_const int MULL(int a, int b, unsigned shift) +-{ +- int lo, hi; +- __asm__("smull %0, %1, %2, %3 \n\t" +- "mov %0, %0, lsr %4 \n\t" +- "add %1, %0, %1, lsl %5 \n\t" +- : "=&r"(lo), "=&r"(hi) +- : "r"(b), "r"(a), "ir"(shift), "ir"(32-shift)); +- return hi; +-} +- +-#define MULH MULH + #if HAVE_ARMV6 ++#define MULH MULH + static inline av_const int MULH(int a, int b) + { + int r; + __asm__ ("smmul %0, %1, %2" : "=r"(r) : "r"(a), "r"(b)); + return r; + } +-#else +-static inline av_const int MULH(int a, int b) +-{ +- int lo, hi; +- __asm__ ("smull %0, %1, %2, %3" : "=&r"(lo), "=&r"(hi) : "r"(b), "r"(a)); +- return hi; +-} + #endif + +-static inline av_const int64_t MUL64(int a, int b) +-{ +- union { uint64_t x; unsigned hl[2]; } x; +- __asm__ ("smull %0, %1, %2, %3" +- : "=r"(x.hl[0]), "=r"(x.hl[1]) : "r"(a), "r"(b)); +- return x.x; +-} +-#define MUL64 MUL64 +- +-static inline av_const int64_t MAC64(int64_t d, int a, int b) +-{ +- union { uint64_t x; unsigned hl[2]; } x = { d }; +- __asm__ ("smlal %0, %1, %2, %3" +- : "+r"(x.hl[0]), "+r"(x.hl[1]) : "r"(a), "r"(b)); +- return x.x; +-} +-#define MAC64(d, a, b) ((d) = MAC64(d, a, b)) + #define MLS64(d, a, b) MAC64(d, -(a), b) + + #if HAVE_ARMV5TE +@@ -97,17 +61,21 @@ + static inline av_const int mid_pred(int a, int b, int c) + { + int m; +- __asm__ volatile ( ++ __asm__ ( + "mov %0, %2 \n\t" + "cmp %1, %2 \n\t" ++ "itt gt \n\t" + "movgt %0, %1 \n\t" + "movgt %1, %2 \n\t" + "cmp %1, %3 \n\t" ++ "it le \n\t" + "movle %1, %3 \n\t" + "cmp %0, %1 \n\t" ++ "it gt \n\t" + "movgt %0, %1 \n\t" + : "=&r"(m), "+r"(a) +- : "r"(b), "r"(c)); ++ : "r"(b), "r"(c) ++ : "cc"); + return m; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mdct_fixed_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mdct_fixed_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mdct_fixed_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mdct_fixed_neon.S 2012-05-14 14:08:53.438321948 +0200 +@@ -0,0 +1,195 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++ preserve8 ++ ++.macro prerot dst, rt ++ lsr r3, r6, #2 @ n4 ++ add \rt, r4, r6, lsr #1 @ revtab + n4 ++ add r9, r3, r3, lsl #1 @ n3 ++ add r8, r7, r6 @ tcos + n4 ++ add r3, r2, r6, lsr #1 @ in + n4 ++ add r9, r2, r9, lsl #1 @ in + n3 ++ sub r8, r8, #16 ++ sub r10, r3, #16 ++ sub r11, r9, #16 ++ mov r12, #-16 ++1: ++ vld2.16 {d0,d1}, [r9, :128]! ++ vld2.16 {d2,d3}, [r11,:128], r12 ++ vld2.16 {d4,d5}, [r3, :128]! ++ vld2.16 {d6,d7}, [r10,:128], r12 ++ vld2.16 {d16,d17},[r7, :128]! @ cos, sin ++ vld2.16 {d18,d19},[r8, :128], r12 ++ vrev64.16 q1, q1 ++ vrev64.16 q3, q3 ++ vrev64.16 q9, q9 ++ vneg.s16 d0, d0 ++ vneg.s16 d2, d2 ++ vneg.s16 d16, d16 ++ vneg.s16 d18, d18 ++ vhsub.s16 d0, d0, d3 @ re ++ vhsub.s16 d4, d7, d4 @ im ++ vhsub.s16 d6, d6, d5 ++ vhsub.s16 d2, d2, d1 ++ vmull.s16 q10, d0, d16 ++ vmlsl.s16 q10, d4, d17 ++ vmull.s16 q11, d0, d17 ++ vmlal.s16 q11, d4, d16 ++ vmull.s16 q12, d6, d18 ++ vmlsl.s16 q12, d2, d19 ++ vmull.s16 q13, d6, d19 ++ vmlal.s16 q13, d2, d18 ++ vshrn.s32 d0, q10, #15 ++ vshrn.s32 d1, q11, #15 ++ vshrn.s32 d2, q12, #15 ++ vshrn.s32 d3, q13, #15 ++ vzip.16 d0, d1 ++ vzip.16 d2, d3 ++ ldrh lr, [r4], #2 ++ ldrh r2, [\rt, #-2]! ++ add lr, \dst, lr, lsl #2 ++ add r2, \dst, r2, lsl #2 ++ vst1.32 {d0[0]}, [lr,:32] ++ vst1.32 {d2[0]}, [r2,:32] ++ ldrh lr, [r4], #2 ++ ldrh r2, [\rt, #-2]! ++ add lr, \dst, lr, lsl #2 ++ add r2, \dst, r2, lsl #2 ++ vst1.32 {d0[1]}, [lr,:32] ++ vst1.32 {d2[1]}, [r2,:32] ++ ldrh lr, [r4], #2 ++ ldrh r2, [\rt, #-2]! ++ add lr, \dst, lr, lsl #2 ++ add r2, \dst, r2, lsl #2 ++ vst1.32 {d1[0]}, [lr,:32] ++ vst1.32 {d3[0]}, [r2,:32] ++ ldrh lr, [r4], #2 ++ ldrh r2, [\rt, #-2]! ++ add lr, \dst, lr, lsl #2 ++ add r2, \dst, r2, lsl #2 ++ vst1.32 {d1[1]}, [lr,:32] ++ vst1.32 {d3[1]}, [r2,:32] ++ subs r6, r6, #32 ++ bgt 1b ++.endm ++ ++function ff_mdct_fixed_calc_neon, export=1 ++ push {r1,r4-r11,lr} ++ ++ ldr r4, [r0, #8] @ revtab ++ ldr r6, [r0, #16] @ mdct_size; n ++ ldr r7, [r0, #24] @ tcos ++ ++ prerot r1, r5 ++ ++ mov r4, r0 ++ bl X(ff_fft_fixed_calc_neon) ++ ++ pop {r5} ++ mov r12, #-16 ++ ldr r6, [r4, #16] @ mdct_size; n ++ ldr r7, [r4, #24] @ tcos ++ add r5, r5, r6, lsr #1 ++ add r7, r7, r6, lsr #1 ++ sub r1, r5, #16 ++ sub r2, r7, #16 ++1: ++ vld2.16 {d4,d5}, [r7,:128]! ++ vld2.16 {d6,d7}, [r2,:128], r12 ++ vld2.16 {d0,d1}, [r5,:128] ++ vld2.16 {d2,d3}, [r1,:128] ++ vrev64.16 q3, q3 ++ vrev64.16 q1, q1 ++ vneg.s16 q3, q3 ++ vneg.s16 q2, q2 ++ vmull.s16 q11, d2, d6 ++ vmlal.s16 q11, d3, d7 ++ vmull.s16 q8, d0, d5 ++ vmlsl.s16 q8, d1, d4 ++ vmull.s16 q9, d0, d4 ++ vmlal.s16 q9, d1, d5 ++ vmull.s16 q10, d2, d7 ++ vmlsl.s16 q10, d3, d6 ++ vshrn.s32 d0, q11, #15 ++ vshrn.s32 d1, q8, #15 ++ vshrn.s32 d2, q9, #15 ++ vshrn.s32 d3, q10, #15 ++ vrev64.16 q0, q0 ++ vst2.16 {d2,d3}, [r5,:128]! ++ vst2.16 {d0,d1}, [r1,:128], r12 ++ subs r6, r6, #32 ++ bgt 1b ++ ++ pop {r4-r11,pc} ++endfunc ++ ++function ff_mdct_fixed_calcw_neon, export=1 ++ push {r1,r4-r11,lr} ++ ++ ldrd r4, r5, [r0, #8] @ revtab, tmp_buf ++ ldr r6, [r0, #16] @ mdct_size; n ++ ldr r7, [r0, #24] @ tcos ++ ++ prerot r5, r1 ++ ++ mov r4, r0 ++ mov r1, r5 ++ bl X(ff_fft_fixed_calc_neon) ++ ++ pop {r7} ++ mov r12, #-16 ++ ldr r6, [r4, #16] @ mdct_size; n ++ ldr r9, [r4, #24] @ tcos ++ add r5, r5, r6, lsr #1 ++ add r7, r7, r6 ++ add r9, r9, r6, lsr #1 ++ sub r3, r5, #16 ++ sub r1, r7, #16 ++ sub r2, r9, #16 ++1: ++ vld2.16 {d4,d5}, [r9,:128]! ++ vld2.16 {d6,d7}, [r2,:128], r12 ++ vld2.16 {d0,d1}, [r5,:128]! ++ vld2.16 {d2,d3}, [r3,:128], r12 ++ vrev64.16 q3, q3 ++ vrev64.16 q1, q1 ++ vneg.s16 q3, q3 ++ vneg.s16 q2, q2 ++ vmull.s16 q8, d2, d6 ++ vmlal.s16 q8, d3, d7 ++ vmull.s16 q9, d0, d5 ++ vmlsl.s16 q9, d1, d4 ++ vmull.s16 q10, d0, d4 ++ vmlal.s16 q10, d1, d5 ++ vmull.s16 q11, d2, d7 ++ vmlsl.s16 q11, d3, d6 ++ vrev64.32 q8, q8 ++ vrev64.32 q9, q9 ++ vst2.32 {q10,q11},[r7,:128]! ++ vst2.32 {d16,d18},[r1,:128], r12 ++ vst2.32 {d17,d19},[r1,:128], r12 ++ subs r6, r6, #32 ++ bgt 1b ++ ++ pop {r4-r11,pc} ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mdct_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mdct_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mdct_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mdct_neon.S 2012-05-14 14:08:53.439321969 +0200 +@@ -23,8 +23,6 @@ + + preserve8 + +- .text +- + #define ff_fft_calc_neon X(ff_fft_calc_neon) + + function ff_imdct_half_neon, export=1 +@@ -191,7 +189,9 @@ + vadd.f32 d17, d17, d3 @ in2u+in1d -I + 1: + vmul.f32 d7, d0, d21 @ I*s +- ldr r10, [r3, lr, lsr #1] ++A ldr r10, [r3, lr, lsr #1] ++T lsr r10, lr, #1 ++T ldr r10, [r3, r10] + vmul.f32 d6, d1, d20 @ -R*c + ldr r6, [r3, #4]! + vmul.f32 d4, d1, d21 @ -R*s +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_fixed_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_fixed_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_fixed_armv6.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_fixed_armv6.S 2012-05-14 14:08:53.440321989 +0200 +@@ -0,0 +1,143 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++.macro skip args:vararg ++.endm ++ ++.macro sum8 lo, hi, w, p, t1, t2, t3, t4, rsb=skip, offs=0 ++ ldr \t1, [\w, #4*\offs] ++ ldr \t2, [\p, #4]! ++ \rsb \t1, \t1, #0 ++ .irpc i, 135 ++ ldr \t3, [\w, #4*64*\i+4*\offs] ++ ldr \t4, [\p, #4*64*\i] ++ smlal \lo, \hi, \t1, \t2 ++ \rsb \t3, \t3, #0 ++ ldr \t1, [\w, #4*64*(\i+1)+4*\offs] ++ ldr \t2, [\p, #4*64*(\i+1)] ++ smlal \lo, \hi, \t3, \t4 ++ \rsb \t1, \t1, #0 ++ .endr ++ ldr \t3, [\w, #4*64*7+4*\offs] ++ ldr \t4, [\p, #4*64*7] ++ smlal \lo, \hi, \t1, \t2 ++ \rsb \t3, \t3, #0 ++ smlal \lo, \hi, \t3, \t4 ++.endm ++ ++.macro round rd, lo, hi ++ lsr \rd, \lo, #24 ++ bic \lo, \lo, #0xff000000 ++ orr \rd, \rd, \hi, lsl #8 ++ mov \hi, #0 ++ ssat \rd, #16, \rd ++.endm ++ ++function ff_mpadsp_apply_window_fixed_armv6, export=1 ++ push {r2,r4-r11,lr} ++ ++ add r4, r0, #4*512 @ synth_buf + 512 ++ .rept 4 ++ ldm r0!, {r5-r12} ++ stm r4!, {r5-r12} ++ .endr ++ ++ ldr r4, [sp, #40] @ incr ++ sub r0, r0, #4*17 @ synth_buf + 16 ++ ldr r8, [r2] @ sum:low ++ add r2, r0, #4*32 @ synth_buf + 48 ++ rsb r5, r4, r4, lsl #5 @ 31 * incr ++ lsl r4, r4, #1 ++ asr r9, r8, #31 @ sum:high ++ add r5, r3, r5, lsl #1 @ samples2 ++ add r6, r1, #4*32 @ w2 ++ str r4, [sp, #40] ++ ++ sum8 r8, r9, r1, r0, r10, r11, r12, lr ++ sum8 r8, r9, r1, r2, r10, r11, r12, lr, rsb, 32 ++ round r10, r8, r9 ++ strh_post r10, r3, r4 ++ ++ mov lr, #15 ++1: ++ ldr r12, [r0, #4]! ++ ldr r11, [r6, #-4]! ++ ldr r10, [r1, #4]! ++ .irpc i, 0246 ++ .if \i ++ ldr r11, [r6, #4*64*\i] ++ ldr r10, [r1, #4*64*\i] ++ .endif ++ rsb r11, r11, #0 ++ smlal r8, r9, r10, r12 ++ ldr r10, [r0, #4*64*(\i+1)] ++ .ifeq \i ++ smull r4, r7, r11, r12 ++ .else ++ smlal r4, r7, r11, r12 ++ .endif ++ ldr r11, [r6, #4*64*(\i+1)] ++ ldr r12, [r1, #4*64*(\i+1)] ++ rsb r11, r11, #0 ++ smlal r8, r9, r12, r10 ++ .iflt \i-6 ++ ldr r12, [r0, #4*64*(\i+2)] ++ .else ++ ldr r12, [r2, #-4]! ++ .endif ++ smlal r4, r7, r11, r10 ++ .endr ++ .irpc i, 0246 ++ ldr r10, [r1, #4*64*\i+4*32] ++ rsb r12, r12, #0 ++ ldr r11, [r6, #4*64*\i+4*32] ++ smlal r8, r9, r10, r12 ++ ldr r10, [r2, #4*64*(\i+1)] ++ smlal r4, r7, r11, r12 ++ ldr r12, [r1, #4*64*(\i+1)+4*32] ++ rsb r10, r10, #0 ++ ldr r11, [r6, #4*64*(\i+1)+4*32] ++ smlal r8, r9, r12, r10 ++ .iflt \i-6 ++ ldr r12, [r2, #4*64*(\i+2)] ++ .else ++ ldr r12, [sp, #40] ++ .endif ++ smlal r4, r7, r11, r10 ++ .endr ++ round r10, r8, r9 ++ adds r8, r8, r4 ++ adc r9, r9, r7 ++ strh_post r10, r3, r12 ++ round r11, r8, r9 ++ subs lr, lr, #1 ++ strh_dpost r11, r5, r12 ++ bgt 1b ++ ++ sum8 r8, r9, r1, r0, r10, r11, r12, lr, rsb, 33 ++ pop {r4} ++ round r10, r8, r9 ++ str r8, [r4] ++ strh r10, [r3] ++ ++ pop {r4-r11,pc} ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegaudiodsp_init_arm.c 2012-05-14 14:08:53.441322009 +0200 +@@ -0,0 +1,33 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "libavcodec/mpegaudiodsp.h" ++#include "config.h" ++ ++void ff_mpadsp_apply_window_fixed_armv6(int32_t *synth_buf, int32_t *window, ++ int *dither, int16_t *out, int incr); ++ ++void ff_mpadsp_init_arm(MPADSPContext *s) ++{ ++ if (HAVE_ARMV6) { ++ s->apply_window_fixed = ff_mpadsp_apply_window_fixed_armv6; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_arm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_arm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_arm.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_arm.h 2012-05-14 14:08:53.441322009 +0200 +@@ -24,4 +24,4 @@ + void MPV_common_init_iwmmxt(MpegEncContext *s); + void MPV_common_init_armv5te(MpegEncContext *s); + +-#endif ++#endif /* AVCODEC_ARM_MPEGVIDEO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_armv5te_s.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_armv5te_s.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_armv5te_s.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_armv5te_s.S 2012-05-14 14:08:53.442322029 +0200 +@@ -35,6 +35,27 @@ + * + * Inner loop should take 6 cycles per element on arm926ej-s (Nokia 770) + */ ++ ++.macro dequant_t dst, src, mul, add, tmp ++ rsbs \tmp, ip, \src, asr #16 ++ it gt ++ addgt \tmp, \add, #0 ++ it lt ++ rsblt \tmp, \add, #0 ++ it ne ++ smlatbne \dst, \src, \mul, \tmp ++.endm ++ ++.macro dequant_b dst, src, mul, add, tmp ++ rsbs \tmp, ip, \src, lsl #16 ++ it gt ++ addgt \tmp, \add, #0 ++ it lt ++ rsblt \tmp, \add, #0 ++ it ne ++ smlabbne \dst, \src, \mul, \tmp ++.endm ++ + function ff_dct_unquantize_h263_armv5te, export=1 + push {r4-r9,lr} + mov ip, #0 +@@ -44,50 +65,20 @@ + 1: + ldrd r6, [r0, #8] + +- rsbs r9, ip, r4, asr #16 +- addgt r9, r2, #0 +- rsblt r9, r2, #0 +- smlatbne r9, r4, r1, r9 +- +- rsbs lr, ip, r5, asr #16 +- addgt lr, r2, #0 +- rsblt lr, r2, #0 +- smlatbne lr, r5, r1, lr +- +- rsbs r8, ip, r4, asl #16 +- addgt r8, r2, #0 +- rsblt r8, r2, #0 +- smlabbne r4, r4, r1, r8 +- +- rsbs r8, ip, r5, asl #16 +- addgt r8, r2, #0 +- rsblt r8, r2, #0 +- smlabbne r5, r5, r1, r8 ++ dequant_t r9, r4, r1, r2, r9 ++ dequant_t lr, r5, r1, r2, lr ++ dequant_b r4, r4, r1, r2, r8 ++ dequant_b r5, r5, r1, r2, r8 + + strh r4, [r0], #2 + strh r9, [r0], #2 + strh r5, [r0], #2 + strh lr, [r0], #2 + +- rsbs r9, ip, r6, asr #16 +- addgt r9, r2, #0 +- rsblt r9, r2, #0 +- smlatbne r9, r6, r1, r9 +- +- rsbs lr, ip, r7, asr #16 +- addgt lr, r2, #0 +- rsblt lr, r2, #0 +- smlatbne lr, r7, r1, lr +- +- rsbs r8, ip, r6, asl #16 +- addgt r8, r2, #0 +- rsblt r8, r2, #0 +- smlabbne r6, r6, r1, r8 +- +- rsbs r8, ip, r7, asl #16 +- addgt r8, r2, #0 +- rsblt r8, r2, #0 +- smlabbne r7, r7, r1, r8 ++ dequant_t r9, r6, r1, r2, r9 ++ dequant_t lr, r7, r1, r2, lr ++ dequant_b r6, r6, r1, r2, r8 ++ dequant_b r7, r7, r1, r2, r8 + + strh r6, [r0], #2 + strh r9, [r0], #2 +@@ -95,21 +86,27 @@ + strh lr, [r0], #2 + + subs r3, r3, #8 +- ldrgtd r4, [r0, #0] /* load data early to avoid load/use pipeline stall */ ++ it gt ++ ldrdgt r4, [r0, #0] /* load data early to avoid load/use pipeline stall */ + bgt 1b + + adds r3, r3, #2 ++ it le + pople {r4-r9,pc} + 2: + ldrsh r9, [r0, #0] + ldrsh lr, [r0, #2] + mov r8, r2 + cmp r9, #0 ++ it lt + rsblt r8, r2, #0 ++ it ne + smlabbne r9, r9, r1, r8 + mov r8, r2 + cmp lr, #0 ++ it lt + rsblt r8, r2, #0 ++ it ne + smlabbne lr, lr, r1, r8 + strh r9, [r0], #2 + strh lr, [r0], #2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_iwmmxt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_iwmmxt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_iwmmxt.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_iwmmxt.c 2012-05-14 14:08:53.443322049 +0200 +@@ -93,29 +93,9 @@ + block_orig[0] = level; + } + +-#if 0 +-static void dct_unquantize_h263_inter_iwmmxt(MpegEncContext *s, +- DCTELEM *block, int n, int qscale) +-{ +- int nCoeffs; +- +- assert(s->block_last_index[n]>=0); +- +- if(s->ac_pred) +- nCoeffs=63; +- else +- nCoeffs= s->inter_scantable.raster_end[ s->block_last_index[n] ]; +- +- ippiQuantInvInter_Compact_H263_16s_I(block, nCoeffs+1, qscale); +-} +-#endif +- + void MPV_common_init_iwmmxt(MpegEncContext *s) + { + if (!(mm_flags & AV_CPU_FLAG_IWMMXT)) return; + + s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_iwmmxt; +-#if 0 +- s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_iwmmxt; +-#endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/mpegvideo_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/mpegvideo_neon.S 2012-05-14 14:08:53.443322049 +0200 +@@ -57,6 +57,7 @@ + subs r3, r3, #16 + vst1.16 {q0}, [r1,:128]! + vst1.16 {q8}, [r1,:128]! ++ it le + bxle lr + cmp r3, #8 + bgt 1b +@@ -78,6 +79,7 @@ + ldr r6, [r0, #AC_PRED] + add lr, r0, #INTER_SCANTAB_RASTER_END + cmp r6, #0 ++ it ne + movne r12, #63 + bne 1f + ldr r12, [r12, r2, lsl #2] +@@ -86,9 +88,11 @@ + ldrsh r4, [r1] + cmp r5, #0 + mov r5, r1 ++ it ne + movne r2, #0 + bne 2f + cmp r2, #4 ++ it ge + addge r0, r0, #4 + sub r2, r3, #1 + ldr r6, [r0, #Y_DC_SCALE] +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/neon.S 2012-05-14 14:08:53.444322069 +0200 +@@ -0,0 +1,59 @@ ++/* ++ * Copyright (c) 2008 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++.macro transpose_8x8 r0, r1, r2, r3, r4, r5, r6, r7 ++ vtrn.32 \r0, \r4 ++ vtrn.32 \r1, \r5 ++ vtrn.32 \r2, \r6 ++ vtrn.32 \r3, \r7 ++ vtrn.16 \r0, \r2 ++ vtrn.16 \r1, \r3 ++ vtrn.16 \r4, \r6 ++ vtrn.16 \r5, \r7 ++ vtrn.8 \r0, \r1 ++ vtrn.8 \r2, \r3 ++ vtrn.8 \r4, \r5 ++ vtrn.8 \r6, \r7 ++.endm ++ ++.macro transpose_4x4 r0, r1, r2, r3 ++ vtrn.16 \r0, \r2 ++ vtrn.16 \r1, \r3 ++ vtrn.8 \r0, \r1 ++ vtrn.8 \r2, \r3 ++.endm ++ ++.macro swap4 r0, r1, r2, r3, r4, r5, r6, r7 ++ vswp \r0, \r4 ++ vswp \r1, \r5 ++ vswp \r2, \r6 ++ vswp \r3, \r7 ++.endm ++ ++.macro transpose16_4x4 r0, r1, r2, r3, r4, r5, r6, r7 ++ vtrn.32 \r0, \r2 ++ vtrn.32 \r1, \r3 ++ vtrn.32 \r4, \r6 ++ vtrn.32 \r5, \r7 ++ vtrn.16 \r0, \r1 ++ vtrn.16 \r2, \r3 ++ vtrn.16 \r4, \r5 ++ vtrn.16 \r6, \r7 ++.endm +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rdft_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rdft_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rdft_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rdft_neon.S 2012-05-14 14:08:53.444322069 +0200 +@@ -137,6 +137,7 @@ + vst1.32 {d22}, [r5,:64] + + cmp r6, #0 ++ it eq + popeq {r4-r8,pc} + + vmul.f32 d22, d22, d18 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv34dsp_init_neon.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv34dsp_init_neon.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv34dsp_init_neon.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv34dsp_init_neon.c 2012-05-14 14:08:53.445322089 +0200 +@@ -0,0 +1,40 @@ ++/* ++ * Copyright (c) 2011 Janne Grunau ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "libavcodec/avcodec.h" ++#include "libavcodec/rv34dsp.h" ++ ++void ff_rv34_inv_transform_noround_neon(DCTELEM *block); ++ ++void ff_rv34_inv_transform_noround_dc_neon(DCTELEM *block); ++ ++void ff_rv34_idct_add_neon(uint8_t *dst, int stride, DCTELEM *block); ++void ff_rv34_idct_dc_add_neon(uint8_t *dst, int stride, int dc); ++ ++void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) ++{ ++ c->rv34_inv_transform = ff_rv34_inv_transform_noround_neon; ++ c->rv34_inv_transform_dc = ff_rv34_inv_transform_noround_dc_neon; ++ ++ c->rv34_idct_add = ff_rv34_idct_add_neon; ++ c->rv34_idct_dc_add = ff_rv34_idct_dc_add_neon; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv34dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv34dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv34dsp_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv34dsp_neon.S 2012-05-14 14:08:53.446322109 +0200 +@@ -0,0 +1,156 @@ ++/* ++ * Copyright (c) 2011 Janne Grunau ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++#include "neon.S" ++ ++.macro rv34_inv_transform r0 ++ vld1.16 {q14-q15}, [\r0,:128] ++ vmov.s16 d0, #13 ++ vshll.s16 q12, d29, #3 ++ vshll.s16 q13, d29, #4 ++ vshll.s16 q9, d31, #3 ++ vshll.s16 q1, d31, #4 ++ vmull.s16 q10, d28, d0 ++ vmlal.s16 q10, d30, d0 ++ vmull.s16 q11, d28, d0 ++ vmlsl.s16 q11, d30, d0 ++ vsubw.s16 q12, q12, d29 @ z2 = block[i+4*1]*7 ++ vaddw.s16 q13, q13, d29 @ z3 = block[i+4*1]*17 ++ vsubw.s16 q9, q9, d31 ++ vaddw.s16 q1, q1, d31 ++ vadd.s32 q13, q13, q9 @ z3 = 17*block[i+4*1] + 7*block[i+4*3] ++ vsub.s32 q12, q12, q1 @ z2 = 7*block[i+4*1] - 17*block[i+4*3] ++ vadd.s32 q1, q10, q13 @ z0 + z3 ++ vadd.s32 q2, q11, q12 @ z1 + z2 ++ vsub.s32 q8, q10, q13 @ z0 - z3 ++ vsub.s32 q3, q11, q12 @ z1 - z2 ++ vtrn.32 q1, q2 ++ vtrn.32 q3, q8 ++ vswp d3, d6 ++ vswp d5, d16 ++ vmov.s32 d0, #13 ++ vadd.s32 q10, q1, q3 ++ vsub.s32 q11, q1, q3 ++ vshl.s32 q12, q2, #3 ++ vshl.s32 q9, q2, #4 ++ vmul.s32 q13, q11, d0[0] ++ vshl.s32 q11, q8, #4 ++ vadd.s32 q9, q9, q2 ++ vshl.s32 q15, q8, #3 ++ vsub.s32 q12, q12, q2 ++ vadd.s32 q11, q11, q8 ++ vmul.s32 q14, q10, d0[0] ++ vsub.s32 q8, q15, q8 ++ vsub.s32 q12, q12, q11 ++ vadd.s32 q9, q9, q8 ++ vadd.s32 q2, q13, q12 @ z1 + z2 ++ vadd.s32 q1, q14, q9 @ z0 + z3 ++ vsub.s32 q3, q13, q12 @ z1 - z2 ++ vsub.s32 q15, q14, q9 @ z0 - z3 ++.endm ++ ++/* void rv34_idct_add_c(uint8_t *dst, int stride, DCTELEM *block) */ ++function ff_rv34_idct_add_neon, export=1 ++ mov r3, r0 ++ rv34_inv_transform r2 ++ vmov.i16 q12, #0 ++ vrshrn.s32 d16, q1, #10 @ (z0 + z3) >> 10 ++ vrshrn.s32 d17, q2, #10 @ (z1 + z2) >> 10 ++ vrshrn.s32 d18, q3, #10 @ (z1 - z2) >> 10 ++ vrshrn.s32 d19, q15, #10 @ (z0 - z3) >> 10 ++ vld1.32 {d28[]}, [r0,:32], r1 ++ vld1.32 {d29[]}, [r0,:32], r1 ++ vtrn.32 q8, q9 ++ vld1.32 {d28[1]}, [r0,:32], r1 ++ vld1.32 {d29[1]}, [r0,:32], r1 ++ vst1.16 {q12}, [r2,:128]! @ memset(block, 0, 16) ++ vst1.16 {q12}, [r2,:128] @ memset(block+16, 0, 16) ++ vtrn.16 d16, d17 ++ vtrn.32 d28, d29 ++ vtrn.16 d18, d19 ++ vaddw.u8 q0, q8, d28 ++ vaddw.u8 q1, q9, d29 ++ vqmovun.s16 d28, q0 ++ vqmovun.s16 d29, q1 ++ vst1.32 {d28[0]}, [r3,:32], r1 ++ vst1.32 {d28[1]}, [r3,:32], r1 ++ vst1.32 {d29[0]}, [r3,:32], r1 ++ vst1.32 {d29[1]}, [r3,:32], r1 ++ bx lr ++endfunc ++ ++/* void rv34_inv_transform_noround_neon(DCTELEM *block); */ ++function ff_rv34_inv_transform_noround_neon, export=1 ++ rv34_inv_transform r0 ++ vshl.s32 q11, q2, #1 ++ vshl.s32 q10, q1, #1 ++ vshl.s32 q12, q3, #1 ++ vshl.s32 q13, q15, #1 ++ vadd.s32 q11, q11, q2 ++ vadd.s32 q10, q10, q1 ++ vadd.s32 q12, q12, q3 ++ vadd.s32 q13, q13, q15 ++ vshrn.s32 d0, q10, #11 @ (z0 + z3)*3 >> 11 ++ vshrn.s32 d1, q11, #11 @ (z1 + z2)*3 >> 11 ++ vshrn.s32 d2, q12, #11 @ (z1 - z2)*3 >> 11 ++ vshrn.s32 d3, q13, #11 @ (z0 - z3)*3 >> 11 ++ vst4.16 {d0[0], d1[0], d2[0], d3[0]}, [r0,:64]! ++ vst4.16 {d0[1], d1[1], d2[1], d3[1]}, [r0,:64]! ++ vst4.16 {d0[2], d1[2], d2[2], d3[2]}, [r0,:64]! ++ vst4.16 {d0[3], d1[3], d2[3], d3[3]}, [r0,:64]! ++ bx lr ++endfunc ++ ++/* void ff_rv34_idct_dc_add_neon(uint8_t *dst, int stride, int dc) */ ++function ff_rv34_idct_dc_add_neon, export=1 ++ mov r3, r0 ++ vld1.32 {d28[]}, [r0,:32], r1 ++ vld1.32 {d29[]}, [r0,:32], r1 ++ vdup.16 d0, r2 ++ vmov.s16 d1, #169 ++ vld1.32 {d28[1]}, [r0,:32], r1 ++ vmull.s16 q1, d0, d1 @ dc * 13 * 13 ++ vld1.32 {d29[1]}, [r0,:32], r1 ++ vrshrn.s32 d0, q1, #10 @ (dc * 13 * 13 + 0x200) >> 10 ++ vmov d1, d0 ++ vaddw.u8 q2, q0, d28 ++ vaddw.u8 q3, q0, d29 ++ vqmovun.s16 d28, q2 ++ vqmovun.s16 d29, q3 ++ vst1.32 {d28[0]}, [r3,:32], r1 ++ vst1.32 {d29[0]}, [r3,:32], r1 ++ vst1.32 {d28[1]}, [r3,:32], r1 ++ vst1.32 {d29[1]}, [r3,:32], r1 ++ bx lr ++endfunc ++ ++/* void rv34_inv_transform_dc_noround_c(DCTELEM *block) */ ++function ff_rv34_inv_transform_noround_dc_neon, export=1 ++ vld1.16 {d28[]}, [r0,:16] @ block[0] ++ vmov.i16 d4, #251 ++ vorr.s16 d4, #256 @ 13^2 * 3 ++ vmull.s16 q3, d28, d4 ++ vshrn.s32 d0, q3, #11 ++ vmov.i16 d1, d0 ++ vst1.64 {q0}, [r0,:128]! ++ vst1.64 {q0}, [r0,:128]! ++ bx lr ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv40dsp_init_neon.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv40dsp_init_neon.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv40dsp_init_neon.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv40dsp_init_neon.c 2012-05-14 14:08:53.446322109 +0200 +@@ -0,0 +1,138 @@ ++/* ++ * Copyright (c) 2011 Janne Grunau ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "libavcodec/avcodec.h" ++#include "libavcodec/rv34dsp.h" ++ ++#define DECL_QPEL3(type, w, pos) \ ++ void ff_##type##_rv40_qpel##w##_mc##pos##_neon(uint8_t *dst, uint8_t *src,\ ++ int stride) ++#define DECL_QPEL2(w, pos) \ ++ DECL_QPEL3(put, w, pos); \ ++ DECL_QPEL3(avg, w, pos) ++ ++#define DECL_QPEL_XY(x, y) \ ++ DECL_QPEL2(16, x ## y); \ ++ DECL_QPEL2(8, x ## y) ++ ++#define DECL_QPEL_Y(y) \ ++ DECL_QPEL_XY(0, y); \ ++ DECL_QPEL_XY(1, y); \ ++ DECL_QPEL_XY(2, y); \ ++ DECL_QPEL_XY(3, y); \ ++ ++DECL_QPEL_Y(0); ++DECL_QPEL_Y(1); ++DECL_QPEL_Y(2); ++DECL_QPEL_Y(3); ++ ++void ff_put_rv40_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); ++void ff_put_rv40_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); ++ ++void ff_avg_rv40_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int); ++void ff_avg_rv40_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int); ++ ++void ff_rv40_weight_func_16_neon(uint8_t *, uint8_t *, uint8_t *, int, int, int); ++void ff_rv40_weight_func_8_neon(uint8_t *, uint8_t *, uint8_t *, int, int, int); ++ ++int ff_rv40_h_loop_filter_strength_neon(uint8_t *src, int stride, ++ int beta, int beta2, int edge, ++ int *p1, int *q1); ++int ff_rv40_v_loop_filter_strength_neon(uint8_t *src, int stride, ++ int beta, int beta2, int edge, ++ int *p1, int *q1); ++ ++void ff_rv40_h_weak_loop_filter_neon(uint8_t *src, int stride, int filter_p1, ++ int filter_q1, int alpha, int beta, ++ int lim_p0q0, int lim_q1, int lim_p1); ++void ff_rv40_v_weak_loop_filter_neon(uint8_t *src, int stride, int filter_p1, ++ int filter_q1, int alpha, int beta, ++ int lim_p0q0, int lim_q1, int lim_p1); ++ ++void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext* dsp) ++{ ++ c->put_pixels_tab[0][ 1] = ff_put_rv40_qpel16_mc10_neon; ++ c->put_pixels_tab[0][ 3] = ff_put_rv40_qpel16_mc30_neon; ++ c->put_pixels_tab[0][ 4] = ff_put_rv40_qpel16_mc01_neon; ++ c->put_pixels_tab[0][ 5] = ff_put_rv40_qpel16_mc11_neon; ++ c->put_pixels_tab[0][ 6] = ff_put_rv40_qpel16_mc21_neon; ++ c->put_pixels_tab[0][ 7] = ff_put_rv40_qpel16_mc31_neon; ++ c->put_pixels_tab[0][ 9] = ff_put_rv40_qpel16_mc12_neon; ++ c->put_pixels_tab[0][10] = ff_put_rv40_qpel16_mc22_neon; ++ c->put_pixels_tab[0][11] = ff_put_rv40_qpel16_mc32_neon; ++ c->put_pixels_tab[0][12] = ff_put_rv40_qpel16_mc03_neon; ++ c->put_pixels_tab[0][13] = ff_put_rv40_qpel16_mc13_neon; ++ c->put_pixels_tab[0][14] = ff_put_rv40_qpel16_mc23_neon; ++ c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_neon; ++ c->avg_pixels_tab[0][ 1] = ff_avg_rv40_qpel16_mc10_neon; ++ c->avg_pixels_tab[0][ 3] = ff_avg_rv40_qpel16_mc30_neon; ++ c->avg_pixels_tab[0][ 4] = ff_avg_rv40_qpel16_mc01_neon; ++ c->avg_pixels_tab[0][ 5] = ff_avg_rv40_qpel16_mc11_neon; ++ c->avg_pixels_tab[0][ 6] = ff_avg_rv40_qpel16_mc21_neon; ++ c->avg_pixels_tab[0][ 7] = ff_avg_rv40_qpel16_mc31_neon; ++ c->avg_pixels_tab[0][ 9] = ff_avg_rv40_qpel16_mc12_neon; ++ c->avg_pixels_tab[0][10] = ff_avg_rv40_qpel16_mc22_neon; ++ c->avg_pixels_tab[0][11] = ff_avg_rv40_qpel16_mc32_neon; ++ c->avg_pixels_tab[0][12] = ff_avg_rv40_qpel16_mc03_neon; ++ c->avg_pixels_tab[0][13] = ff_avg_rv40_qpel16_mc13_neon; ++ c->avg_pixels_tab[0][14] = ff_avg_rv40_qpel16_mc23_neon; ++ c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_neon; ++ c->put_pixels_tab[1][ 1] = ff_put_rv40_qpel8_mc10_neon; ++ c->put_pixels_tab[1][ 3] = ff_put_rv40_qpel8_mc30_neon; ++ c->put_pixels_tab[1][ 4] = ff_put_rv40_qpel8_mc01_neon; ++ c->put_pixels_tab[1][ 5] = ff_put_rv40_qpel8_mc11_neon; ++ c->put_pixels_tab[1][ 6] = ff_put_rv40_qpel8_mc21_neon; ++ c->put_pixels_tab[1][ 7] = ff_put_rv40_qpel8_mc31_neon; ++ c->put_pixels_tab[1][ 9] = ff_put_rv40_qpel8_mc12_neon; ++ c->put_pixels_tab[1][10] = ff_put_rv40_qpel8_mc22_neon; ++ c->put_pixels_tab[1][11] = ff_put_rv40_qpel8_mc32_neon; ++ c->put_pixels_tab[1][12] = ff_put_rv40_qpel8_mc03_neon; ++ c->put_pixels_tab[1][13] = ff_put_rv40_qpel8_mc13_neon; ++ c->put_pixels_tab[1][14] = ff_put_rv40_qpel8_mc23_neon; ++ c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_neon; ++ c->avg_pixels_tab[1][ 1] = ff_avg_rv40_qpel8_mc10_neon; ++ c->avg_pixels_tab[1][ 3] = ff_avg_rv40_qpel8_mc30_neon; ++ c->avg_pixels_tab[1][ 4] = ff_avg_rv40_qpel8_mc01_neon; ++ c->avg_pixels_tab[1][ 5] = ff_avg_rv40_qpel8_mc11_neon; ++ c->avg_pixels_tab[1][ 6] = ff_avg_rv40_qpel8_mc21_neon; ++ c->avg_pixels_tab[1][ 7] = ff_avg_rv40_qpel8_mc31_neon; ++ c->avg_pixels_tab[1][ 9] = ff_avg_rv40_qpel8_mc12_neon; ++ c->avg_pixels_tab[1][10] = ff_avg_rv40_qpel8_mc22_neon; ++ c->avg_pixels_tab[1][11] = ff_avg_rv40_qpel8_mc32_neon; ++ c->avg_pixels_tab[1][12] = ff_avg_rv40_qpel8_mc03_neon; ++ c->avg_pixels_tab[1][13] = ff_avg_rv40_qpel8_mc13_neon; ++ c->avg_pixels_tab[1][14] = ff_avg_rv40_qpel8_mc23_neon; ++ c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_neon; ++ ++ c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_neon; ++ c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_neon; ++ c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_neon; ++ c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_neon; ++ ++ c->rv40_weight_pixels_tab[0] = ff_rv40_weight_func_16_neon; ++ c->rv40_weight_pixels_tab[1] = ff_rv40_weight_func_8_neon; ++ ++ c->rv40_loop_filter_strength[0] = ff_rv40_h_loop_filter_strength_neon; ++ c->rv40_loop_filter_strength[1] = ff_rv40_v_loop_filter_strength_neon; ++ c->rv40_weak_loop_filter[0] = ff_rv40_h_weak_loop_filter_neon; ++ c->rv40_weak_loop_filter[1] = ff_rv40_v_weak_loop_filter_neon; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv40dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv40dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/rv40dsp_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/rv40dsp_neon.S 2012-05-14 14:08:53.449322170 +0200 +@@ -0,0 +1,920 @@ ++/* ++ * Copyright (c) 2011 Janne Grunau ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++#include "neon.S" ++ ++.macro qpel_lowpass r0, r1, rc1, rc2, shift ++ vext.8 d25, \r0, \r1, #1 @ src[-1] ++ vext.8 d26, \r0, \r1, #4 @ src[ 2] ++ vext.8 d24, \r0, \r1, #5 @ src[ 3] ++ vaddl.u8 q9, d25, d26 ++ vaddl.u8 q8, \r0, d24 ++ vext.8 d27, \r0, \r1, #2 @ src[ 0] ++ vshl.s16 q12, q9, #2 ++ vsub.s16 q8, q8, q9 ++ vext.8 d28, \r0, \r1, #3 @ src[ 1] ++ vsub.s16 q8, q8, q12 ++ vmlal.u8 q8, d27, \rc1 ++ vmlal.u8 q8, d28, \rc2 ++ vqrshrun.s16 \r0, q8, #\shift ++.endm ++ ++.macro qpel_lowpass_x2 r0, r1, r2, r3, rc1, rc2, shift ++ vext.8 d25, \r0, \r1, #1 @ src[-1] ++ vext.8 d26, \r0, \r1, #4 @ src[ 2] ++ vext.8 d24, \r0, \r1, #5 @ src[ 3] ++ vaddl.u8 q9, d25, d26 ++ vaddl.u8 q8, \r0, d24 ++ vext.8 d29, \r0, \r1, #2 @ src[ 0] ++ vext.8 d28, \r0, \r1, #3 @ src[ 1] ++ vshl.s16 q10, q9, #2 ++ vext.8 \r1, \r2, \r3, #1 @ src[-1] ++ vsub.s16 q8, q8, q9 ++ vext.8 d22, \r2, \r3, #4 @ src[ 2] ++ vext.8 \r0, \r2, \r3, #5 @ src[ 3] ++ vaddl.u8 q13, \r1, d22 ++ vaddl.u8 q12, \r2, \r0 ++ vsub.s16 q8, q8, q10 ++ vshl.s16 q9, q13, #2 ++ vsub.s16 q12, q12, q13 ++ vmlal.u8 q8, d29, \rc1 ++ vmlal.u8 q8, d28, \rc2 ++ vsub.s16 q12, q12, q9 ++ vext.8 d26, \r2, \r3, #2 @ src[ 0] ++ vext.8 d27, \r2, \r3, #3 @ src[ 1] ++ vmlal.u8 q12, d26, \rc1 ++ vmlal.u8 q12, d27, \rc2 ++ vqrshrun.s16 \r0, q8, #\shift ++ vqrshrun.s16 \r2, q12, #\shift ++.endm ++ ++.macro rv40_qpel8_h shift ++function put_rv40_qpel8_h_lp_packed_s\shift\()_neon ++1: ++ vld1.8 {q2}, [r1], r2 ++ vld1.8 {q3}, [r1], r2 ++ qpel_lowpass_x2 d4, d5, d6, d7, d0, d1, \shift ++ vst1.8 {d4}, [r12,:64]! ++ vst1.8 {d6}, [r12,:64]! ++ subs r3, r3, #2 ++ bgt 1b ++ vld1.8 {q2}, [r1] ++ qpel_lowpass d4, d5, d0, d1, \shift ++ vst1.8 {d4}, [r12,:64]! ++ bx lr ++endfunc ++.endm ++ ++.macro rv40_qpel8_v shift, type ++function \type\()_rv40_qpel8_v_lp_packed_s\shift\()_neon ++ vld1.64 {d2}, [r1,:64]! ++ vld1.64 {d3}, [r1,:64]! ++ vld1.64 {d4}, [r1,:64]! ++ vld1.64 {d5}, [r1,:64]! ++ vld1.64 {d6}, [r1,:64]! ++ vld1.64 {d7}, [r1,:64]! ++ vld1.64 {d8}, [r1,:64]! ++ vld1.64 {d9}, [r1,:64]! ++ vld1.64 {d10}, [r1,:64]! ++ vld1.64 {d11}, [r1,:64]! ++ vld1.64 {d12}, [r1,:64]! ++ vld1.64 {d13}, [r1,:64]! ++ vld1.64 {d14}, [r1,:64]! ++ transpose_8x8 d2, d3, d4, d5, d6, d7, d8, d9 ++ transpose_8x8 d10, d11, d12, d13, d14, d15, d30, d31 ++ qpel_lowpass_x2 d2, d10, d3, d11, d0, d1, \shift ++ qpel_lowpass_x2 d4, d12, d5, d13, d0, d1, \shift ++ qpel_lowpass_x2 d6, d14, d7, d15, d0, d1, \shift ++ qpel_lowpass_x2 d8, d30, d9, d31, d0, d1, \shift ++ transpose_8x8 d2, d3, d4, d5, d6, d7, d8, d9 ++ .ifc \type,avg ++ vld1.64 d12, [r0,:64], r2 ++ vld1.64 d13, [r0,:64], r2 ++ vld1.64 d14, [r0,:64], r2 ++ vld1.64 d15, [r0,:64], r2 ++ vld1.64 d16, [r0,:64], r2 ++ vld1.64 d17, [r0,:64], r2 ++ vld1.64 d18, [r0,:64], r2 ++ vld1.64 d19, [r0,:64], r2 ++ sub r0, r0, r2, lsl #3 ++ vrhadd.u8 q1, q1, q6 ++ vrhadd.u8 q2, q2, q7 ++ vrhadd.u8 q3, q3, q8 ++ vrhadd.u8 q4, q4, q9 ++ .endif ++ vst1.64 d2, [r0,:64], r2 ++ vst1.64 d3, [r0,:64], r2 ++ vst1.64 d4, [r0,:64], r2 ++ vst1.64 d5, [r0,:64], r2 ++ vst1.64 d6, [r0,:64], r2 ++ vst1.64 d7, [r0,:64], r2 ++ vst1.64 d8, [r0,:64], r2 ++ vst1.64 d9, [r0,:64], r2 ++ bx lr ++endfunc ++.endm ++ ++ rv40_qpel8_h 5 ++ rv40_qpel8_h 6 ++ ++.macro rv40_qpel type ++function \type\()_rv40_qpel8_h_lowpass_neon ++ .ifc \type,avg ++ mov r12, r0 ++ .endif ++1: ++ vld1.8 {q2}, [r1], r2 ++ vld1.8 {q3}, [r1], r2 ++ qpel_lowpass_x2 d4, d5, d6, d7, d0, d1, 6 ++ .ifc \type,avg ++ vld1.8 {d3}, [r12,:64], r2 ++ vld1.8 {d16}, [r12,:64], r2 ++ vrhadd.u8 d4, d4, d3 ++ vrhadd.u8 d6, d6, d16 ++ .endif ++ vst1.8 {d4}, [r0,:64], r2 ++ vst1.8 {d6}, [r0,:64], r2 ++ subs r3, r3, #2 ++ bgt 1b ++ bx lr ++endfunc ++ ++function \type\()_rv40_qpel8_v_lowpass_neon ++ vld1.64 {d2}, [r1], r2 ++ vld1.64 {d3}, [r1], r2 ++ vld1.64 {d4}, [r1], r2 ++ vld1.64 {d5}, [r1], r2 ++ vld1.64 {d6}, [r1], r2 ++ vld1.64 {d7}, [r1], r2 ++ vld1.64 {d8}, [r1], r2 ++ vld1.64 {d9}, [r1], r2 ++ vld1.64 {d10}, [r1], r2 ++ vld1.64 {d11}, [r1], r2 ++ vld1.64 {d12}, [r1], r2 ++ vld1.64 {d13}, [r1], r2 ++ vld1.64 {d14}, [r1] ++ transpose_8x8 d2, d3, d4, d5, d6, d7, d8, d9 ++ transpose_8x8 d10, d11, d12, d13, d14, d15, d30, d31 ++ qpel_lowpass_x2 d2, d10, d3, d11, d0, d1, 6 ++ qpel_lowpass_x2 d4, d12, d5, d13, d0, d1, 6 ++ qpel_lowpass_x2 d6, d14, d7, d15, d0, d1, 6 ++ qpel_lowpass_x2 d8, d30, d9, d31, d0, d1, 6 ++ transpose_8x8 d2, d3, d4, d5, d6, d7, d8, d9 ++ .ifc \type,avg ++ vld1.64 d12, [r0,:64], r2 ++ vld1.64 d13, [r0,:64], r2 ++ vld1.64 d14, [r0,:64], r2 ++ vld1.64 d15, [r0,:64], r2 ++ vld1.64 d16, [r0,:64], r2 ++ vld1.64 d17, [r0,:64], r2 ++ vld1.64 d18, [r0,:64], r2 ++ vld1.64 d19, [r0,:64], r2 ++ sub r0, r0, r2, lsl #3 ++ vrhadd.u8 q1, q1, q6 ++ vrhadd.u8 q2, q2, q7 ++ vrhadd.u8 q3, q3, q8 ++ vrhadd.u8 q4, q4, q9 ++ .endif ++ vst1.64 d2, [r0,:64], r2 ++ vst1.64 d3, [r0,:64], r2 ++ vst1.64 d4, [r0,:64], r2 ++ vst1.64 d5, [r0,:64], r2 ++ vst1.64 d6, [r0,:64], r2 ++ vst1.64 d7, [r0,:64], r2 ++ vst1.64 d8, [r0,:64], r2 ++ vst1.64 d9, [r0,:64], r2 ++ bx lr ++endfunc ++ ++ rv40_qpel8_v 5, \type ++ rv40_qpel8_v 6, \type ++ ++function ff_\type\()_rv40_qpel8_mc10_neon, export=1 ++ sub r1, r1, #2 ++ mov r3, #8 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ b \type\()_rv40_qpel8_h_lowpass_neon ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc30_neon, export=1 ++ sub r1, r1, #2 ++ mov r3, #8 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ b \type\()_rv40_qpel8_h_lowpass_neon ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc01_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub r1, r1, r2, lsl #1 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc11_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc21_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vmov.i8 d0, #52 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc31_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vswp d0, d1 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc12_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vmov.i8 d0, #20 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc22_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc32_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vmov.i8 d1, #20 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc03_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub r1, r1, r2, lsl #1 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc33_neon, export=1 ++ mov r3, #8 ++ b X(ff_\type\()_pixels8_xy2_neon) ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc13_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vswp d0, d1 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel8_mc23_neon, export=1 ++ push {r4, lr} ++ vpush {d8-d15} ++ sub sp, sp, #14*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ mov r3, #12 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ vmov.i8 d1, #52 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #14*8 ++ vpop {d8-d15} ++ pop {r4, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc10_neon, export=1 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++.L\type\()_rv40_qpel16_h: ++ push {r1, lr} ++ sub r1, r1, #2 ++ mov r3, #16 ++ bl \type\()_rv40_qpel8_h_lowpass_neon ++ pop {r1, lr} ++ sub r0, r0, r2, lsl #4 ++ add r0, r0, #8 ++ add r1, r1, #6 ++ mov r3, #16 ++ b \type\()_rv40_qpel8_h_lowpass_neon ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc30_neon, export=1 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ b .L\type\()_rv40_qpel16_h ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc01_neon, export=1 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++.L\type\()_rv40_qpel16_v: ++ sub r1, r1, r2, lsl #1 ++ push {r1, lr} ++ vpush {d8-d15} ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ sub r1, r1, r2, lsl #2 ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ ldr r1, [sp, #64] ++ sub r0, r0, r2, lsl #4 ++ add r0, r0, #8 ++ add r1, r1, #8 ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ sub r1, r1, r2, lsl #2 ++ bl \type\()_rv40_qpel8_v_lowpass_neon ++ vpop {d8-d15} ++ pop {r1, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc11_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++.L\type\()_rv40_qpel16_v_s6: ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ sub r1, r1, #40 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ sub r0, r0, r2, lsl #4 ++ add r0, r0, #8 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ sub r1, r1, #40 ++ bl \type\()_rv40_qpel8_v_lp_packed_s6_neon ++ add sp, sp, #44*8 ++ vpop {d8-d15} ++ pop {r1, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc21_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ vmov.i8 d0, #52 ++ b .L\type\()_rv40_qpel16_v_s6 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc31_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ vswp d0, d1 ++ b .L\type\()_rv40_qpel16_v_s6 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc12_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ vmov.i8 d0, #20 ++.L\type\()_rv40_qpel16_v_s5: ++ add r1, sp, #7 ++ bic r1, r1, #7 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ sub r1, r1, #40 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ sub r0, r0, r2, lsl #4 ++ add r0, r0, #8 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ sub r1, r1, #40 ++ bl \type\()_rv40_qpel8_v_lp_packed_s5_neon ++ add sp, sp, #44*8 ++ vpop {d8-d15} ++ pop {r1, pc} ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc22_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ b .L\type\()_rv40_qpel16_v_s5 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc32_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ vmov.i8 d1, #20 ++ b .L\type\()_rv40_qpel16_v_s5 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc03_neon, export=1 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #52 ++ b .L\type\()_rv40_qpel16_v ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc13_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #52 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s6_neon ++ vswp d0, d1 ++ b .L\type\()_rv40_qpel16_v_s6 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc23_neon, export=1 ++ sub r1, r1, r2, lsl #1 ++ sub r1, r1, #2 ++ push {r1, lr} ++ vpush {d8-d15} ++ sub sp, sp, #44*8 ++ add r12, sp, #7 ++ bic r12, r12, #7 ++ mov r3, #20 ++ vmov.i8 d0, #20 ++ vmov.i8 d1, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ ldr r1, [sp, #416] ++ add r1, r1, #8 ++ mov r3, #20 ++ bl put_rv40_qpel8_h_lp_packed_s5_neon ++ vmov.i8 d1, #52 ++ b .L\type\()_rv40_qpel16_v_s6 ++endfunc ++ ++function ff_\type\()_rv40_qpel16_mc33_neon, export=1 ++ mov r3, #16 ++ b X(ff_\type\()_pixels16_xy2_neon) ++endfunc ++.endm ++ ++ rv40_qpel put ++ rv40_qpel avg ++ ++.macro rv40_weight ++ vmovl.u8 q8, d2 ++ vmovl.u8 q9, d3 ++ vmovl.u8 q10, d4 ++ vmovl.u8 q11, d5 ++ vmull.u16 q2, d16, d0[2] ++ vmull.u16 q3, d17, d0[2] ++ vmull.u16 q8, d18, d0[2] ++ vmull.u16 q9, d19, d0[2] ++ vmull.u16 q12, d20, d0[0] ++ vmull.u16 q13, d21, d0[0] ++ vmull.u16 q14, d22, d0[0] ++ vmull.u16 q15, d23, d0[0] ++ vshrn.i32 d4, q2, #9 ++ vshrn.i32 d5, q3, #9 ++ vshrn.i32 d6, q8, #9 ++ vshrn.i32 d7, q9, #9 ++ vshrn.i32 d16, q12, #9 ++ vshrn.i32 d17, q13, #9 ++ vshrn.i32 d18, q14, #9 ++ vshrn.i32 d19, q15, #9 ++ vadd.u16 q2, q2, q8 ++ vadd.u16 q3, q3, q9 ++ vrshrn.i16 d2, q2, #5 ++ vrshrn.i16 d3, q3, #5 ++.endm ++ ++/* void ff_rv40_weight_func_16_neon(uint8_t *dst, uint8_t *src1, uint8_t *src2, ++ int w1, int w2, int stride) */ ++function ff_rv40_weight_func_16_neon, export=1 ++ ldr r12, [sp] ++ vmov d0, r3, r12 ++ ldr r12, [sp, #4] ++ mov r3, #16 ++1: ++ vld1.8 {q1}, [r1,:128], r12 ++ vld1.8 {q2}, [r2,:128], r12 ++ rv40_weight ++ vst1.8 {q1}, [r0,:128], r12 ++ subs r3, r3, #1 ++ bne 1b ++ bx lr ++endfunc ++ ++/* void ff_rv40_weight_func_8_neon(uint8_t *dst, uint8_t *src1, uint8_t *src2, ++ int w1, int w2, int stride) */ ++function ff_rv40_weight_func_8_neon, export=1 ++ ldr r12, [sp] ++ vmov d0, r3, r12 ++ ldr r12, [sp, #4] ++ mov r3, #8 ++1: ++ vld1.8 {d2}, [r1,:64], r12 ++ vld1.8 {d3}, [r1,:64], r12 ++ vld1.8 {d4}, [r2,:64], r12 ++ vld1.8 {d5}, [r2,:64], r12 ++ rv40_weight ++ vst1.8 {d2}, [r0,:64], r12 ++ vst1.8 {d3}, [r0,:64], r12 ++ subs r3, r3, #2 ++ bne 1b ++ bx lr ++endfunc ++ ++function ff_rv40_h_loop_filter_strength_neon, export=1 ++ pkhbt r2, r3, r2, lsl #18 ++ ++ ldr r3, [r0] ++ ldr_dpre r12, r0, r1 ++ teq r3, r12 ++ beq 1f ++ ++ sub r0, r0, r1, lsl #1 ++ ++ vld1.32 {d4[]}, [r0,:32], r1 @ -3 ++ vld1.32 {d0[]}, [r0,:32], r1 @ -2 ++ vld1.32 {d4[1]}, [r0,:32], r1 @ -1 ++ vld1.32 {d5[]}, [r0,:32], r1 @ 0 ++ vld1.32 {d1[]}, [r0,:32], r1 @ 1 ++ vld1.32 {d5[0]}, [r0,:32], r1 @ 2 ++ ++ vpaddl.u8 q8, q0 @ -2, -2, -2, -2, 1, 1, 1, 1 ++ vpaddl.u8 q9, q2 @ -3, -3, -1, -1, 2, 2, 0, 0 ++ vdup.32 d30, r2 @ beta2, beta << 2 ++ vpadd.u16 d16, d16, d17 @ -2, -2, 1, 1 ++ vpadd.u16 d18, d18, d19 @ -3, -1, 2, 0 ++ vabd.u16 d16, d18, d16 ++ vclt.u16 d16, d16, d30 ++ ++ ldrd r2, r3, [sp, #4] ++ vmovl.u16 q12, d16 ++ vtrn.16 d16, d17 ++ vshr.u32 q12, q12, #15 ++ ldr r0, [sp] ++ vst1.32 {d24[1]}, [r2,:32] ++ vst1.32 {d25[1]}, [r3,:32] ++ ++ cmp r0, #0 ++ it eq ++ bxeq lr ++ ++ vand d18, d16, d17 ++ vtrn.32 d18, d19 ++ vand d18, d18, d19 ++ vmov.u16 r0, d18[0] ++ bx lr ++1: ++ ldrd r2, r3, [sp, #4] ++ mov r0, #0 ++ str r0, [r2] ++ str r0, [r3] ++ bx lr ++endfunc ++ ++function ff_rv40_v_loop_filter_strength_neon, export=1 ++ sub r0, r0, #3 ++ pkhbt r2, r3, r2, lsl #18 ++ ++ vld1.8 {d0}, [r0], r1 ++ vld1.8 {d1}, [r0], r1 ++ vld1.8 {d2}, [r0], r1 ++ vld1.8 {d3}, [r0], r1 ++ ++ vaddl.u8 q0, d0, d1 ++ vaddl.u8 q1, d2, d3 ++ vdup.32 q15, r2 ++ vadd.u16 q0, q0, q1 @ -3, -2, -1, 0, 1, 2 ++ vext.16 q1, q0, q0, #1 @ -2, -1, 0, 1, 2 ++ vabd.u16 q0, q1, q0 ++ vclt.u16 q0, q0, q15 ++ ++ ldrd r2, r3, [sp, #4] ++ vmovl.u16 q1, d0 ++ vext.16 d1, d0, d1, #3 ++ vshr.u32 q1, q1, #15 ++ ldr r0, [sp] ++ vst1.32 {d2[1]}, [r2,:32] ++ vst1.32 {d3[1]}, [r3,:32] ++ ++ cmp r0, #0 ++ it eq ++ bxeq lr ++ ++ vand d0, d0, d1 ++ vtrn.16 d0, d1 ++ vand d0, d0, d1 ++ vmov.u16 r0, d0[0] ++ bx lr ++endfunc ++ ++.macro rv40_weak_loop_filter ++ vdup.16 d30, r2 @ filter_p1 ++ vdup.16 d31, r3 @ filter_q1 ++ ldrd r2, r3, [sp] ++ vdup.16 d28, r2 @ alpha ++ vdup.16 d29, r3 @ beta ++ ldr r12, [sp, #8] ++ vdup.16 d25, r12 @ lim_p0q0 ++ ldrd r2, r3, [sp, #12] ++ vsubl.u8 q9, d5, d4 @ x, t ++ vabdl.u8 q8, d5, d4 @ x, abs(t) ++ vneg.s16 q15, q15 ++ vceq.i16 d16, d19, #0 @ !t ++ vshl.s16 d19, d19, #2 @ t << 2 ++ vmul.u16 d18, d17, d28 @ alpha * abs(t) ++ vand d24, d30, d31 @ filter_p1 & filter_q1 ++ vsubl.u8 q1, d0, d4 @ p1p2, p1p0 ++ vsubl.u8 q3, d1, d5 @ q1q2, q1q0 ++ vmov.i16 d22, #3 ++ vshr.u16 d18, d18, #7 ++ vadd.i16 d22, d22, d24 @ 3 - (filter_p1 & filter_q1) ++ vsubl.u8 q10, d0, d1 @ src[-2] - src[1] ++ vcle.u16 d18, d18, d22 ++ vand d20, d20, d24 ++ vneg.s16 d23, d25 @ -lim_p0q0 ++ vadd.s16 d19, d19, d20 ++ vbic d16, d18, d16 @ t && u <= 3 - (fp1 & fq1) ++ vtrn.32 d4, d5 @ -3, 2, -1, 0 ++ vrshr.s16 d19, d19, #3 ++ vmov d28, d29 @ beta ++ vswp d3, d6 @ q1q2, p1p0 ++ vmin.s16 d19, d19, d25 ++ vand d30, d30, d16 ++ vand d31, d31, d16 ++ vadd.s16 q10, q1, q3 @ p1p2 + p1p0, q1q2 + q1q0 ++ vmax.s16 d19, d19, d23 @ diff ++ vabs.s16 q1, q1 @ abs(p1p2), abs(q1q2) ++ vand d18, d19, d16 @ diff ++ vcle.u16 q1, q1, q14 ++ vneg.s16 d19, d18 @ -diff ++ vdup.16 d26, r3 @ lim_p1 ++ vaddw.u8 q2, q9, d5 @ src[-1]+diff, src[0]-diff ++ vhsub.s16 q11, q10, q9 ++ vand q1, q1, q15 ++ vqmovun.s16 d4, q2 @ -1, 0 ++ vand q9, q11, q1 ++ vdup.16 d27, r2 @ lim_q1 ++ vneg.s16 q9, q9 ++ vneg.s16 q14, q13 ++ vmin.s16 q9, q9, q13 ++ vtrn.32 d0, d1 @ -2, 1, -2, 1 ++ vmax.s16 q9, q9, q14 ++ vaddw.u8 q3, q9, d0 ++ vqmovun.s16 d5, q3 @ -2, 1 ++.endm ++ ++function ff_rv40_h_weak_loop_filter_neon, export=1 ++ sub r0, r0, r1, lsl #1 ++ sub r0, r0, r1 ++ ++ vld1.32 {d4[]}, [r0,:32], r1 ++ vld1.32 {d0[]}, [r0,:32], r1 ++ vld1.32 {d4[1]}, [r0,:32], r1 ++ vld1.32 {d5[]}, [r0,:32], r1 ++ vld1.32 {d1[]}, [r0,:32], r1 ++ vld1.32 {d5[0]}, [r0,:32] ++ ++ sub r0, r0, r1, lsl #2 ++ ++ rv40_weak_loop_filter ++ ++ vst1.32 {d5[0]}, [r0,:32], r1 ++ vst1.32 {d4[0]}, [r0,:32], r1 ++ vst1.32 {d4[1]}, [r0,:32], r1 ++ vst1.32 {d5[1]}, [r0,:32], r1 ++ ++ bx lr ++endfunc ++ ++function ff_rv40_v_weak_loop_filter_neon, export=1 ++ sub r12, r0, #3 ++ sub r0, r0, #2 ++ ++ vld1.8 {d4}, [r12], r1 ++ vld1.8 {d5}, [r12], r1 ++ vld1.8 {d2}, [r12], r1 ++ vld1.8 {d3}, [r12], r1 ++ ++ vtrn.16 q2, q1 ++ vtrn.8 d4, d5 ++ vtrn.8 d2, d3 ++ ++ vrev64.32 d5, d5 ++ vtrn.32 q2, q1 ++ vdup.32 d0, d3[0] ++ vdup.32 d1, d2[0] ++ ++ rv40_weak_loop_filter ++ ++ vtrn.32 q2, q3 ++ vswp d4, d5 ++ ++ vst4.8 {d4[0],d5[0],d6[0],d7[0]}, [r0], r1 ++ vst4.8 {d4[1],d5[1],d6[1],d7[1]}, [r0], r1 ++ vst4.8 {d4[2],d5[2],d6[2],d7[2]}, [r0], r1 ++ vst4.8 {d4[3],d5[3],d6[3],d7[3]}, [r0], r1 ++ ++ bx lr ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_arm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_arm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_arm.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_arm.S 2012-05-14 14:08:53.454322270 +0200 +@@ -1,5 +1,4 @@ + /* +- * simple_idct_arm.S + * Copyright (C) 2002 Frederic 'dilb' Boulay + * + * Author: Frederic Boulay +@@ -54,8 +53,6 @@ + #define COL_SHIFTED_1 524288 /* 1<< (COL_SHIFT-1) */ + + +- .text +- + function ff_simple_idct_arm, export=1 + @@ void simple_idct_arm(int16_t *block) + @@ save stack for reg needed (take all of them), +@@ -121,11 +118,13 @@ + ldr r11, [r12, #offW7] @ R11=W7 + mul r5, r10, r7 @ R5=W5*ROWr16[1]=b2 (ROWr16[1] must be the second arg, to have the possibility to save 1 cycle) + mul r7, r11, r7 @ R7=W7*ROWr16[1]=b3 (ROWr16[1] must be the second arg, to have the possibility to save 1 cycle) +- teq r2, #0 @ if null avoid muls +- mlane r0, r9, r2, r0 @ R0+=W3*ROWr16[3]=b0 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) ++ teq r2, #0 @ if null avoid muls ++ itttt ne ++ mlane r0, r9, r2, r0 @ R0+=W3*ROWr16[3]=b0 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + rsbne r2, r2, #0 @ R2=-ROWr16[3] + mlane r1, r11, r2, r1 @ R1-=W7*ROWr16[3]=b1 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + mlane r5, r8, r2, r5 @ R5-=W1*ROWr16[3]=b2 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) ++ it ne + mlane r7, r10, r2, r7 @ R7-=W5*ROWr16[3]=b3 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + + @@ at this point, R0=b0, R1=b1, R2 (free), R3=ROWr32[2], R4=ROWr32[3], +@@ -148,19 +147,23 @@ + @@ MAC16(b3, -W1, row[7]); + @@ MAC16(b1, -W5, row[7]); + mov r3, r3, asr #16 @ R3=ROWr16[5] +- teq r3, #0 @ if null avoid muls ++ teq r3, #0 @ if null avoid muls ++ it ne + mlane r0, r10, r3, r0 @ R0+=W5*ROWr16[5]=b0 + mov r4, r4, asr #16 @ R4=ROWr16[7] ++ itttt ne + mlane r5, r11, r3, r5 @ R5+=W7*ROWr16[5]=b2 + mlane r7, r9, r3, r7 @ R7+=W3*ROWr16[5]=b3 + rsbne r3, r3, #0 @ R3=-ROWr16[5] + mlane r1, r8, r3, r1 @ R7-=W1*ROWr16[5]=b1 + @@ R3 is free now +- teq r4, #0 @ if null avoid muls ++ teq r4, #0 @ if null avoid muls ++ itttt ne + mlane r0, r11, r4, r0 @ R0+=W7*ROWr16[7]=b0 + mlane r5, r9, r4, r5 @ R5+=W3*ROWr16[7]=b2 + rsbne r4, r4, #0 @ R4=-ROWr16[7] + mlane r7, r8, r4, r7 @ R7-=W1*ROWr16[7]=b3 ++ it ne + mlane r1, r10, r4, r1 @ R1-=W5*ROWr16[7]=b1 + @@ R4 is free now + __end_b_evaluation: +@@ -204,16 +207,19 @@ + @@ a2 -= W4*row[4] + @@ a3 += W4*row[4] + ldrsh r11, [r14, #8] @ R11=ROWr16[4] +- teq r11, #0 @ if null avoid muls ++ teq r11, #0 @ if null avoid muls ++ it ne + mulne r11, r9, r11 @ R11=W4*ROWr16[4] + @@ R9 is free now + ldrsh r9, [r14, #12] @ R9=ROWr16[6] ++ itttt ne + addne r6, r6, r11 @ R6+=W4*ROWr16[4] (a0) + subne r2, r2, r11 @ R2-=W4*ROWr16[4] (a1) + subne r3, r3, r11 @ R3-=W4*ROWr16[4] (a2) + addne r4, r4, r11 @ R4+=W4*ROWr16[4] (a3) + @@ W6 alone is no more useful, save W2*ROWr16[6] in it instead +- teq r9, #0 @ if null avoid muls ++ teq r9, #0 @ if null avoid muls ++ itttt ne + mulne r11, r10, r9 @ R11=W6*ROWr16[6] + addne r6, r6, r11 @ R6+=W6*ROWr16[6] (a0) + mulne r10, r8, r9 @ R10=W2*ROWr16[6] +@@ -222,6 +228,7 @@ + @@ a1 -= W2*row[6]; + @@ a2 += W2*row[6]; + subne r4, r4, r11 @ R4-=W6*ROWr16[6] (a3) ++ itt ne + subne r2, r2, r10 @ R2-=W2*ROWr16[6] (a1) + addne r3, r3, r10 @ R3+=W2*ROWr16[6] (a2) + +@@ -323,10 +330,12 @@ + ldrsh r2, [r14, #48] + mul r7, r11, r7 @ R7=W7*ROWr16[1]=b3 (ROWr16[1] must be the second arg, to have the possibility to save 1 cycle) + teq r2, #0 @ if 0, then avoid muls ++ itttt ne + mlane r0, r9, r2, r0 @ R0+=W3*ROWr16[3]=b0 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + rsbne r2, r2, #0 @ R2=-ROWr16[3] + mlane r1, r11, r2, r1 @ R1-=W7*ROWr16[3]=b1 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + mlane r5, r8, r2, r5 @ R5-=W1*ROWr16[3]=b2 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) ++ it ne + mlane r7, r10, r2, r7 @ R7-=W5*ROWr16[3]=b3 (ROWr16[3] must be the second arg, to have the possibility to save 1 cycle) + + @@ at this point, R0=b0, R1=b1, R2 (free), R3 (free), R4 (free), +@@ -342,18 +351,22 @@ + @@ MAC16(b1, -W5, col[7x8]); + ldrsh r3, [r14, #80] @ R3=COLr16[5x8] + teq r3, #0 @ if 0 then avoid muls ++ itttt ne + mlane r0, r10, r3, r0 @ R0+=W5*ROWr16[5x8]=b0 + mlane r5, r11, r3, r5 @ R5+=W7*ROWr16[5x8]=b2 + mlane r7, r9, r3, r7 @ R7+=W3*ROWr16[5x8]=b3 + rsbne r3, r3, #0 @ R3=-ROWr16[5x8] + ldrsh r4, [r14, #112] @ R4=COLr16[7x8] ++ it ne + mlane r1, r8, r3, r1 @ R7-=W1*ROWr16[5x8]=b1 + @@ R3 is free now + teq r4, #0 @ if 0 then avoid muls ++ itttt ne + mlane r0, r11, r4, r0 @ R0+=W7*ROWr16[7x8]=b0 + mlane r5, r9, r4, r5 @ R5+=W3*ROWr16[7x8]=b2 + rsbne r4, r4, #0 @ R4=-ROWr16[7x8] + mlane r7, r8, r4, r7 @ R7-=W1*ROWr16[7x8]=b3 ++ it ne + mlane r1, r10, r4, r1 @ R1-=W5*ROWr16[7x8]=b1 + @@ R4 is free now + __end_b_evaluation2: +@@ -390,15 +403,18 @@ + @@ a3 += W4*row[4] + ldrsh r11, [r14, #64] @ R11=ROWr16[4] + teq r11, #0 @ if null avoid muls ++ itttt ne + mulne r11, r9, r11 @ R11=W4*ROWr16[4] + @@ R9 is free now + addne r6, r6, r11 @ R6+=W4*ROWr16[4] (a0) + subne r2, r2, r11 @ R2-=W4*ROWr16[4] (a1) + subne r3, r3, r11 @ R3-=W4*ROWr16[4] (a2) + ldrsh r9, [r14, #96] @ R9=ROWr16[6] ++ it ne + addne r4, r4, r11 @ R4+=W4*ROWr16[4] (a3) + @@ W6 alone is no more useful, save W2*ROWr16[6] in it instead + teq r9, #0 @ if null avoid muls ++ itttt ne + mulne r11, r10, r9 @ R11=W6*ROWr16[6] + addne r6, r6, r11 @ R6+=W6*ROWr16[6] (a0) + mulne r10, r8, r9 @ R10=W2*ROWr16[6] +@@ -407,6 +423,7 @@ + @@ a1 -= W2*row[6]; + @@ a2 += W2*row[6]; + subne r4, r4, r11 @ R4-=W6*ROWr16[6] (a3) ++ itt ne + subne r2, r2, r10 @ R2-=W2*ROWr16[6] (a1) + addne r3, r3, r10 @ R3+=W2*ROWr16[6] (a2) + __end_a_evaluation2: +@@ -474,8 +491,8 @@ + bal __end_a_evaluation + + +-__constant_ptr__: @@ see #defines at the beginning of the source code for values. + .align ++__constant_ptr__: @@ see #defines at the beginning of the source code for values. + .word W1 + .word W2 + .word W3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_armv5te.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_armv5te.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_armv5te.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_armv5te.S 2012-05-14 14:08:53.455322291 +0200 +@@ -49,6 +49,7 @@ + ldrd v1, [a1, #8] + ldrd a3, [a1] /* a3 = row[1:0], a4 = row[3:2] */ + orrs v1, v1, v2 ++ itt eq + cmpeq v1, a4 + cmpeq v1, a3, lsr #16 + beq row_dc_only +@@ -269,6 +270,7 @@ + ldmfd sp!, {a3, a4} + adds a2, a3, v1 + mov a2, a2, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + add ip, a4, v2 + mov ip, ip, asr #20 +@@ -276,6 +278,7 @@ + str a2, [a1] + subs a3, a3, v1 + mov a2, a3, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + sub a4, a4, v2 + mov a4, a4, asr #20 +@@ -285,6 +288,7 @@ + + subs a2, a3, v3 + mov a2, a2, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + sub ip, a4, v4 + mov ip, ip, asr #20 +@@ -292,6 +296,7 @@ + str a2, [a1, #(16*1)] + adds a3, a3, v3 + mov a2, a3, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + add a4, a4, v4 + mov a4, a4, asr #20 +@@ -301,6 +306,7 @@ + + adds a2, a3, v5 + mov a2, a2, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + add ip, a4, v6 + mov ip, ip, asr #20 +@@ -308,6 +314,7 @@ + str a2, [a1, #(16*2)] + subs a3, a3, v5 + mov a2, a3, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + sub a4, a4, v6 + mov a4, a4, asr #20 +@@ -317,6 +324,7 @@ + + adds a2, a3, v7 + mov a2, a2, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + add ip, a4, fp + mov ip, ip, asr #20 +@@ -324,6 +332,7 @@ + str a2, [a1, #(16*3)] + subs a3, a3, v7 + mov a2, a3, lsr #20 ++ it mi + orrmi a2, a2, #0xf000 + sub a4, a4, fp + mov a4, a4, asr #20 +@@ -333,6 +342,24 @@ + ldr pc, [sp], #4 + endfunc + ++.macro clip dst, src:vararg ++ movs \dst, \src ++ it mi ++ movmi \dst, #0 ++ cmp \dst, #255 ++ it gt ++ movgt \dst, #255 ++.endm ++ ++.macro aclip dst, src:vararg ++ adds \dst, \src ++ it mi ++ movmi \dst, #0 ++ cmp \dst, #255 ++ it gt ++ movgt \dst, #255 ++.endm ++ + function idct_col_put_armv5te + str lr, [sp, #-4]! + +@@ -341,111 +368,63 @@ + ldmfd sp!, {a3, a4} + ldr lr, [sp, #32] + add a2, a3, v1 +- movs a2, a2, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a2, asr #20 + add ip, a4, v2 +- movs ip, ip, asr #20 +- movmi ip, #0 +- cmp ip, #255 +- movgt ip, #255 ++ clip ip, ip, asr #20 + orr a2, a2, ip, lsl #8 + sub a3, a3, v1 +- movs a3, a3, asr #20 +- movmi a3, #0 +- cmp a3, #255 +- movgt a3, #255 ++ clip a3, a3, asr #20 + sub a4, a4, v2 +- movs a4, a4, asr #20 +- movmi a4, #0 +- cmp a4, #255 ++ clip a4, a4, asr #20 + ldr v1, [sp, #28] +- movgt a4, #255 + strh a2, [v1] + add a2, v1, #2 + str a2, [sp, #28] + orr a2, a3, a4, lsl #8 + rsb v2, lr, lr, lsl #3 + ldmfd sp!, {a3, a4} +- strh a2, [v2, v1]! ++ strh_pre a2, v2, v1 + + sub a2, a3, v3 +- movs a2, a2, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a2, asr #20 + sub ip, a4, v4 +- movs ip, ip, asr #20 +- movmi ip, #0 +- cmp ip, #255 +- movgt ip, #255 ++ clip ip, ip, asr #20 + orr a2, a2, ip, lsl #8 +- strh a2, [v1, lr]! ++ strh_pre a2, v1, lr + add a3, a3, v3 +- movs a2, a3, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a3, asr #20 + add a4, a4, v4 +- movs a4, a4, asr #20 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ clip a4, a4, asr #20 + orr a2, a2, a4, lsl #8 + ldmfd sp!, {a3, a4} +- strh a2, [v2, -lr]! ++ strh_dpre a2, v2, lr + + add a2, a3, v5 +- movs a2, a2, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a2, asr #20 + add ip, a4, v6 +- movs ip, ip, asr #20 +- movmi ip, #0 +- cmp ip, #255 +- movgt ip, #255 ++ clip ip, ip, asr #20 + orr a2, a2, ip, lsl #8 +- strh a2, [v1, lr]! ++ strh_pre a2, v1, lr + sub a3, a3, v5 +- movs a2, a3, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a3, asr #20 + sub a4, a4, v6 +- movs a4, a4, asr #20 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ clip a4, a4, asr #20 + orr a2, a2, a4, lsl #8 + ldmfd sp!, {a3, a4} +- strh a2, [v2, -lr]! ++ strh_dpre a2, v2, lr + + add a2, a3, v7 +- movs a2, a2, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a2, asr #20 + add ip, a4, fp +- movs ip, ip, asr #20 +- movmi ip, #0 +- cmp ip, #255 +- movgt ip, #255 ++ clip ip, ip, asr #20 + orr a2, a2, ip, lsl #8 + strh a2, [v1, lr] + sub a3, a3, v7 +- movs a2, a3, asr #20 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ clip a2, a3, asr #20 + sub a4, a4, fp +- movs a4, a4, asr #20 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ clip a4, a4, asr #20 + orr a2, a2, a4, lsl #8 +- strh a2, [v2, -lr] ++ strh_dpre a2, v2, lr + + ldr pc, [sp], #4 + endfunc +@@ -460,140 +439,84 @@ + ldmfd sp!, {a3, a4} + ldrh ip, [lr] + add a2, a3, v1 +- mov a2, a2, asr #20 + sub a3, a3, v1 + and v1, ip, #255 +- adds a2, a2, v1 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ aclip a2, v1, a2, asr #20 + add v1, a4, v2 + mov v1, v1, asr #20 +- adds v1, v1, ip, lsr #8 +- movmi v1, #0 +- cmp v1, #255 +- movgt v1, #255 ++ aclip v1, v1, ip, lsr #8 + orr a2, a2, v1, lsl #8 + ldr v1, [sp, #32] + sub a4, a4, v2 + rsb v2, v1, v1, lsl #3 +- ldrh ip, [v2, lr]! ++ ldrh_pre ip, v2, lr + strh a2, [lr] +- mov a3, a3, asr #20 + and a2, ip, #255 +- adds a3, a3, a2 +- movmi a3, #0 +- cmp a3, #255 +- movgt a3, #255 ++ aclip a3, a2, a3, asr #20 + mov a4, a4, asr #20 +- adds a4, a4, ip, lsr #8 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ aclip a4, a4, ip, lsr #8 + add a2, lr, #2 + str a2, [sp, #28] + orr a2, a3, a4, lsl #8 + strh a2, [v2] + + ldmfd sp!, {a3, a4} +- ldrh ip, [lr, v1]! ++ ldrh_pre ip, lr, v1 + sub a2, a3, v3 +- mov a2, a2, asr #20 + add a3, a3, v3 + and v3, ip, #255 +- adds a2, a2, v3 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ aclip a2, v3, a2, asr #20 + sub v3, a4, v4 + mov v3, v3, asr #20 +- adds v3, v3, ip, lsr #8 +- movmi v3, #0 +- cmp v3, #255 +- movgt v3, #255 ++ aclip v3, v3, ip, lsr #8 + orr a2, a2, v3, lsl #8 + add a4, a4, v4 +- ldrh ip, [v2, -v1]! ++ ldrh_dpre ip, v2, v1 + strh a2, [lr] +- mov a3, a3, asr #20 + and a2, ip, #255 +- adds a3, a3, a2 +- movmi a3, #0 +- cmp a3, #255 +- movgt a3, #255 ++ aclip a3, a2, a3, asr #20 + mov a4, a4, asr #20 +- adds a4, a4, ip, lsr #8 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ aclip a4, a4, ip, lsr #8 + orr a2, a3, a4, lsl #8 + strh a2, [v2] + + ldmfd sp!, {a3, a4} +- ldrh ip, [lr, v1]! ++ ldrh_pre ip, lr, v1 + add a2, a3, v5 +- mov a2, a2, asr #20 + sub a3, a3, v5 + and v3, ip, #255 +- adds a2, a2, v3 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ aclip a2, v3, a2, asr #20 + add v3, a4, v6 + mov v3, v3, asr #20 +- adds v3, v3, ip, lsr #8 +- movmi v3, #0 +- cmp v3, #255 +- movgt v3, #255 ++ aclip v3, v3, ip, lsr #8 + orr a2, a2, v3, lsl #8 + sub a4, a4, v6 +- ldrh ip, [v2, -v1]! ++ ldrh_dpre ip, v2, v1 + strh a2, [lr] +- mov a3, a3, asr #20 + and a2, ip, #255 +- adds a3, a3, a2 +- movmi a3, #0 +- cmp a3, #255 +- movgt a3, #255 ++ aclip a3, a2, a3, asr #20 + mov a4, a4, asr #20 +- adds a4, a4, ip, lsr #8 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ aclip a4, a4, ip, lsr #8 + orr a2, a3, a4, lsl #8 + strh a2, [v2] + + ldmfd sp!, {a3, a4} +- ldrh ip, [lr, v1]! ++ ldrh_pre ip, lr, v1 + add a2, a3, v7 +- mov a2, a2, asr #20 + sub a3, a3, v7 + and v3, ip, #255 +- adds a2, a2, v3 +- movmi a2, #0 +- cmp a2, #255 +- movgt a2, #255 ++ aclip a2, v3, a2, asr #20 + add v3, a4, fp + mov v3, v3, asr #20 +- adds v3, v3, ip, lsr #8 +- movmi v3, #0 +- cmp v3, #255 +- movgt v3, #255 ++ aclip v3, v3, ip, lsr #8 + orr a2, a2, v3, lsl #8 + sub a4, a4, fp +- ldrh ip, [v2, -v1]! ++ ldrh_dpre ip, v2, v1 + strh a2, [lr] +- mov a3, a3, asr #20 + and a2, ip, #255 +- adds a3, a3, a2 +- movmi a3, #0 +- cmp a3, #255 +- movgt a3, #255 ++ aclip a3, a2, a3, asr #20 + mov a4, a4, asr #20 +- adds a4, a4, ip, lsr #8 +- movmi a4, #0 +- cmp a4, #255 +- movgt a4, #255 ++ aclip a4, a4, ip, lsr #8 + orr a2, a3, a4, lsl #8 + strh a2, [v2] + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_armv6.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_armv6.S 2012-05-14 14:08:53.456322311 +0200 +@@ -200,6 +200,7 @@ + ldr r3, [r0, #8] /* r3 = row[3,1] */ + ldr r2, [r0] /* r2 = row[2,0] */ + orrs lr, lr, ip ++ itt eq + cmpeq lr, r3 + cmpeq lr, r2, lsr #16 + beq 1f +@@ -282,14 +283,14 @@ + pop {r1, r2} + idct_finish_shift_sat COL_SHIFT + +- strb r4, [r1], r2 +- strb r5, [r1], r2 +- strb r6, [r1], r2 +- strb r7, [r1], r2 +- strb r11,[r1], r2 +- strb r10,[r1], r2 +- strb r9, [r1], r2 +- strb r8, [r1], r2 ++ strb_post r4, r1, r2 ++ strb_post r5, r1, r2 ++ strb_post r6, r1, r2 ++ strb_post r7, r1, r2 ++ strb_post r11,r1, r2 ++ strb_post r10,r1, r2 ++ strb_post r9, r1, r2 ++ strb_post r8, r1, r2 + + sub r1, r1, r2, lsl #3 + +@@ -318,16 +319,16 @@ + add ip, r3, ip, asr #COL_SHIFT + usat ip, #8, ip + add r4, r7, r4, asr #COL_SHIFT +- strb ip, [r1], r2 ++ strb_post ip, r1, r2 + ldrb ip, [r1, r2] + usat r4, #8, r4 + ldrb r11,[r1, r2, lsl #2] + add r5, ip, r5, asr #COL_SHIFT + usat r5, #8, r5 +- strb r4, [r1], r2 ++ strb_post r4, r1, r2 + ldrb r3, [r1, r2] + ldrb ip, [r1, r2, lsl #2] +- strb r5, [r1], r2 ++ strb_post r5, r1, r2 + ldrb r7, [r1, r2] + ldrb r4, [r1, r2, lsl #2] + add r6, r3, r6, asr #COL_SHIFT +@@ -340,11 +341,11 @@ + usat r8, #8, r8 + add lr, r4, lr, asr #COL_SHIFT + usat lr, #8, lr +- strb r6, [r1], r2 +- strb r10,[r1], r2 +- strb r9, [r1], r2 +- strb r8, [r1], r2 +- strb lr, [r1], r2 ++ strb_post r6, r1, r2 ++ strb_post r10,r1, r2 ++ strb_post r9, r1, r2 ++ strb_post r8, r1, r2 ++ strb_post lr, r1, r2 + + sub r1, r1, r2, lsl #3 + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S 2012-05-14 14:08:53.457322331 +0200 +@@ -71,7 +71,7 @@ + add r3, r0, r1, lsl #2 + pld [r0, r1] + pld [r0, r1, lsl #1] +- pld [r3, -r1] ++A pld [r3, -r1] + pld [r3] + pld [r3, r1] + add r3, r3, r1, lsl #1 +@@ -164,6 +164,7 @@ + orrs r4, r4, r5 + + idct_col4_top ++ it eq + addeq r2, r2, #16 + beq 1f + +@@ -176,6 +177,7 @@ + + 1: orrs r6, r6, r7 + ldrd r4, [r2, #16] ++ it eq + addeq r2, r2, #16 + beq 2f + +@@ -187,6 +189,7 @@ + + 2: orrs r4, r4, r5 + ldrd r4, [r2, #16] ++ it eq + addeq r2, r2, #16 + beq 3f + +@@ -199,6 +202,7 @@ + vadd.i32 q13, q13, q8 + + 3: orrs r4, r4, r5 ++ it eq + addeq r2, r2, #16 + beq 4f + +@@ -239,16 +243,16 @@ + bx lr + endfunc + +- .align 4 +-idct_coeff_neon: ++const idct_coeff_neon, align=4 + .short W1, W2, W3, W4, W5, W6, W7, W4c ++endconst + + .macro idct_start data + push {r4-r7, lr} + pld [\data] + pld [\data, #64] + vpush {d8-d15} +- adr r3, idct_coeff_neon ++ movrel r3, idct_coeff_neon + vld1.64 {d0,d1}, [r3,:128] + .endm + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/synth_filter_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/synth_filter_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/synth_filter_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/synth_filter_neon.S 2012-05-14 14:08:53.461322411 +0200 +@@ -100,9 +100,11 @@ + vst1.32 {q9}, [r2,:128] + + subs r1, r1, #1 ++ it eq + popeq {r4-r11,pc} + + cmp r4, #0 ++ itt eq + subeq r8, r8, #512*4 + subeq r9, r9, #512*4 + sub r5, r5, #512*4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S 2012-05-14 14:08:53.462322431 +0200 +@@ -20,8 +20,9 @@ + + #include "asm.S" + +-.text +-.align 4 ++const vp3_idct_constants, align=4 ++.short 64277, 60547, 54491, 46341, 36410, 25080, 12785 ++endconst + + #define xC1S7 d0[0] + #define xC2S6 d0[1] +@@ -104,14 +105,10 @@ + bx lr + endfunc + +-.align 4 +-vp3_idct_constants: +-.short 64277, 60547, 54491, 46341, 36410, 25080, 12785 +-.align 4 + + function vp3_idct_start_neon + vpush {d8-d15} +- adr r3, vp3_idct_constants ++ movrel r3, vp3_idct_constants + vld1.64 {d0-d1}, [r3,:128] + vld1.64 {d16-d19}, [r2,:128]! + vld1.64 {d20-d23}, [r2,:128]! +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp56_arith.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp56_arith.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp56_arith.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp56_arith.h 2012-05-14 14:08:53.463322451 +0200 +@@ -0,0 +1,113 @@ ++/* ++ * Copyright (C) 2010 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_ARM_VP56_ARITH_H ++#define AVCODEC_ARM_VP56_ARITH_H ++ ++#if CONFIG_THUMB ++# define A(x) ++# define T(x) x ++#else ++# define A(x) x ++# define T(x) ++#endif ++ ++#if HAVE_ARMV6 && HAVE_INLINE_ASM ++ ++#define vp56_rac_get_prob vp56_rac_get_prob_armv6 ++static inline int vp56_rac_get_prob_armv6(VP56RangeCoder *c, int pr) ++{ ++ unsigned shift = ff_vp56_norm_shift[c->high]; ++ unsigned code_word = c->code_word << shift; ++ unsigned high = c->high << shift; ++ unsigned bit; ++ ++ __asm__ ("adds %3, %3, %0 \n" ++ "itt cs \n" ++ "cmpcs %7, %4 \n" ++ A("ldrcsh %2, [%4], #2 \n") ++ T("ldrhcs %2, [%4], #2 \n") ++ "rsb %0, %6, #256 \n" ++ "smlabb %0, %5, %6, %0 \n" ++ T("itttt cs \n") ++ "rev16cs %2, %2 \n" ++ T("lslcs %2, %2, %3 \n") ++ T("orrcs %1, %1, %2 \n") ++ A("orrcs %1, %1, %2, lsl %3 \n") ++ "subcs %3, %3, #16 \n" ++ "lsr %0, %0, #8 \n" ++ "cmp %1, %0, lsl #16 \n" ++ "ittte ge \n" ++ "subge %1, %1, %0, lsl #16 \n" ++ "subge %0, %5, %0 \n" ++ "movge %2, #1 \n" ++ "movlt %2, #0 \n" ++ : "=&r"(c->high), "=&r"(c->code_word), "=&r"(bit), ++ "+&r"(c->bits), "+&r"(c->buffer) ++ : "r"(high), "r"(pr), "r"(c->end - 1), ++ "0"(shift), "1"(code_word) ++ : "cc"); ++ ++ return bit; ++} ++ ++#define vp56_rac_get_prob_branchy vp56_rac_get_prob_branchy_armv6 ++static inline int vp56_rac_get_prob_branchy_armv6(VP56RangeCoder *c, int pr) ++{ ++ unsigned shift = ff_vp56_norm_shift[c->high]; ++ unsigned code_word = c->code_word << shift; ++ unsigned high = c->high << shift; ++ unsigned low; ++ unsigned tmp; ++ ++ __asm__ ("adds %3, %3, %0 \n" ++ "itt cs \n" ++ "cmpcs %7, %4 \n" ++ A("ldrcsh %2, [%4], #2 \n") ++ T("ldrhcs %2, [%4], #2 \n") ++ "rsb %0, %6, #256 \n" ++ "smlabb %0, %5, %6, %0 \n" ++ T("itttt cs \n") ++ "rev16cs %2, %2 \n" ++ T("lslcs %2, %2, %3 \n") ++ T("orrcs %1, %1, %2 \n") ++ A("orrcs %1, %1, %2, lsl %3 \n") ++ "subcs %3, %3, #16 \n" ++ "lsr %0, %0, #8 \n" ++ "lsl %2, %0, #16 \n" ++ : "=&r"(low), "+&r"(code_word), "=&r"(tmp), ++ "+&r"(c->bits), "+&r"(c->buffer) ++ : "r"(high), "r"(pr), "r"(c->end - 1), "0"(shift) ++ : "cc"); ++ ++ if (code_word >= tmp) { ++ c->high = high - low; ++ c->code_word = code_word - tmp; ++ return 1; ++ } ++ ++ c->high = low; ++ c->code_word = code_word; ++ return 0; ++} ++ ++#endif ++ ++#endif /* AVCODEC_ARM_VP56_ARITH_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8_armv6.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8_armv6.S 2012-05-14 14:08:53.464322472 +0200 +@@ -0,0 +1,248 @@ ++/** ++ * Copyright (C) 2010 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++ ++.macro rac_get_prob h, bs, buf, cw, pr, t0, t1 ++ adds \bs, \bs, \t0 ++ lsl \cw, \cw, \t0 ++ lsl \t0, \h, \t0 ++ rsb \h, \pr, #256 ++ it cs ++ ldrhcs \t1, [\buf], #2 ++ smlabb \h, \t0, \pr, \h ++T itttt cs ++ rev16cs \t1, \t1 ++A orrcs \cw, \cw, \t1, lsl \bs ++T lslcs \t1, \t1, \bs ++T orrcs \cw, \cw, \t1 ++ subcs \bs, \bs, #16 ++ lsr \h, \h, #8 ++ cmp \cw, \h, lsl #16 ++ itt ge ++ subge \cw, \cw, \h, lsl #16 ++ subge \h, \t0, \h ++.endm ++ ++.macro rac_get_128 h, bs, buf, cw, t0, t1 ++ adds \bs, \bs, \t0 ++ lsl \cw, \cw, \t0 ++ lsl \t0, \h, \t0 ++ it cs ++ ldrhcs \t1, [\buf], #2 ++ mov \h, #128 ++ it cs ++ rev16cs \t1, \t1 ++ add \h, \h, \t0, lsl #7 ++A orrcs \cw, \cw, \t1, lsl \bs ++T ittt cs ++T lslcs \t1, \t1, \bs ++T orrcs \cw, \cw, \t1 ++ subcs \bs, \bs, #16 ++ lsr \h, \h, #8 ++ cmp \cw, \h, lsl #16 ++ itt ge ++ subge \cw, \cw, \h, lsl #16 ++ subge \h, \t0, \h ++.endm ++ ++function ff_decode_block_coeffs_armv6, export=1 ++ push {r0,r1,r4-r11,lr} ++ movrel lr, X(ff_vp56_norm_shift) ++ ldrd r4, r5, [sp, #44] @ token_prob, qmul ++ cmp r3, #0 ++ ldr r11, [r5] ++ ldm r0, {r5-r7} @ high, bits, buf ++ it ne ++ pkhtbne r11, r11, r11, asr #16 ++ ldr r8, [r0, #16] @ code_word ++0: ++ ldrb r9, [lr, r5] ++ add r3, r3, #1 ++ ldrb r0, [r4, #1] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ blt 2f ++ ++ ldrb r9, [lr, r5] ++ ldrb r0, [r4, #2] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ ldrb r9, [lr, r5] ++ bge 3f ++ ++ add r4, r3, r3, lsl #5 ++ sxth r12, r11 ++ add r4, r2, r4 ++ adds r6, r6, r9 ++ add r4, r4, #11 ++ lsl r8, r8, r9 ++ it cs ++ ldrhcs r10, [r7], #2 ++ lsl r9, r5, r9 ++ mov r5, #128 ++ it cs ++ rev16cs r10, r10 ++ add r5, r5, r9, lsl #7 ++T ittt cs ++T lslcs r10, r10, r6 ++T orrcs r8, r8, r10 ++A orrcs r8, r8, r10, lsl r6 ++ subcs r6, r6, #16 ++ lsr r5, r5, #8 ++ cmp r8, r5, lsl #16 ++ movrel r10, zigzag_scan-1 ++ itt ge ++ subge r8, r8, r5, lsl #16 ++ subge r5, r9, r5 ++ ldrb r10, [r10, r3] ++ it ge ++ rsbge r12, r12, #0 ++ cmp r3, #16 ++ strh r12, [r1, r10] ++ bge 6f ++5: ++ ldrb r9, [lr, r5] ++ ldrb r0, [r4] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ pkhtb r11, r11, r11, asr #16 ++ bge 0b ++ ++6: ++ ldr r0, [sp] ++ ldr r9, [r0, #12] ++ cmp r7, r9 ++ it hi ++ movhi r7, r9 ++ stm r0, {r5-r7} @ high, bits, buf ++ str r8, [r0, #16] @ code_word ++ ++ add sp, sp, #8 ++ mov r0, r3 ++ pop {r4-r11,pc} ++2: ++ add r4, r3, r3, lsl #5 ++ cmp r3, #16 ++ add r4, r2, r4 ++ pkhtb r11, r11, r11, asr #16 ++ bne 0b ++ b 6b ++3: ++ ldrb r0, [r4, #3] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ ldrb r9, [lr, r5] ++ bge 1f ++ ++ mov r12, #2 ++ ldrb r0, [r4, #4] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r12, #1 ++ ldrb r9, [lr, r5] ++ blt 4f ++ ldrb r0, [r4, #5] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r12, #1 ++ ldrb r9, [lr, r5] ++ b 4f ++1: ++ ldrb r0, [r4, #6] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ ldrb r9, [lr, r5] ++ bge 3f ++ ++ ldrb r0, [r4, #7] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ ldrb r9, [lr, r5] ++ bge 2f ++ ++ mov r12, #5 ++ mov r0, #159 ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r12, r12, #1 ++ ldrb r9, [lr, r5] ++ b 4f ++2: ++ mov r12, #7 ++ mov r0, #165 ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r12, r12, #2 ++ ldrb r9, [lr, r5] ++ mov r0, #145 ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r12, r12, #1 ++ ldrb r9, [lr, r5] ++ b 4f ++3: ++ ldrb r0, [r4, #8] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ it ge ++ addge r4, r4, #1 ++ ldrb r9, [lr, r5] ++ ite ge ++ movge r12, #2 ++ movlt r12, #0 ++ ldrb r0, [r4, #9] ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ mov r9, #8 ++ it ge ++ addge r12, r12, #1 ++ movrel r4, X(ff_vp8_dct_cat_prob) ++ lsl r9, r9, r12 ++ ldr r4, [r4, r12, lsl #2] ++ add r12, r9, #3 ++ mov r1, #0 ++ ldrb r0, [r4], #1 ++1: ++ ldrb r9, [lr, r5] ++ lsl r1, r1, #1 ++ rac_get_prob r5, r6, r7, r8, r0, r9, r10 ++ ldrb r0, [r4], #1 ++ it ge ++ addge r1, r1, #1 ++ cmp r0, #0 ++ bne 1b ++ ldrb r9, [lr, r5] ++ add r12, r12, r1 ++ ldr r1, [sp, #4] ++4: ++ add r4, r3, r3, lsl #5 ++ add r4, r2, r4 ++ add r4, r4, #22 ++ rac_get_128 r5, r6, r7, r8, r9, r10 ++ it ge ++ rsbge r12, r12, #0 ++ smulbb r12, r12, r11 ++ movrel r9, zigzag_scan-1 ++ ldrb r9, [r9, r3] ++ cmp r3, #16 ++ strh r12, [r1, r9] ++ bge 6b ++ b 5b ++endfunc ++ ++const zigzag_scan ++ .byte 0, 2, 8, 16 ++ .byte 10, 4, 6, 12 ++ .byte 18, 24, 26, 20 ++ .byte 14, 22, 28, 30 ++endconst +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_armv6.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_armv6.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_armv6.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_armv6.S 2012-05-14 14:08:53.471322613 +0200 +@@ -0,0 +1,2328 @@ ++/** ++ * VP8 ARMv6 optimisations ++ * ++ * Copyright (c) 2011 The WebM project authors. All Rights Reserved. ++ * Copyright (c) 2010 Rob Clark ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ * ++ * This code was partially ported from libvpx, which uses this license: ++ * ++ * Use of this source code is governed by a BSD-style license ++ * that can be found in the LICENSE file in the root of the source ++ * tree. An additional intellectual property rights grant can be found ++ * in the file PATENTS. All contributing project authors may ++ * be found in the AUTHORS file in the root of the source tree. ++ * ++ * (Note that the "LICENSE", "AUTHORS" and "PATENTS" files can be ++ * found in the libvpx source tree.) ++ */ ++ ++#include "asm.S" ++ ++@ idct ++ ++@ void vp8_luma_dc_wht(DCTELEM block[4][4][16], DCTELEM dc[16]) ++function ff_vp8_luma_dc_wht_armv6, export=1 ++ push {r4 - r10, lr} ++ ++ @ load dc[] and zero memory ++ mov r12, #0 ++ ldr r2, [r1] @ dc0[0,1] ++ ldr r3, [r1, #4] @ dc0[2,3] ++ ldr r4, [r1, #8] @ dc1[0,1] ++ ldr r5, [r1, #12] @ dc1[2,3] ++ ldr r6, [r1, #16] @ dc2[0,1] ++ ldr r7, [r1, #20] @ dc2[2,3] ++ ldr r8, [r1, #24] @ dc3[0,1] ++ ldr r9, [r1, #28] @ dc3[2,3] ++ str r12,[r1] ++ str r12,[r1, #4] ++ str r12,[r1, #8] ++ str r12,[r1, #12] ++ str r12,[r1, #16] ++ str r12,[r1, #20] ++ str r12,[r1, #24] ++ str r12,[r1, #28] ++ ++ @ loop1 ++ uadd16 r12, r2, r8 @ t0[0,1] ++ uadd16 r14, r3, r9 @ t0[2,3] ++ usub16 r2, r2, r8 @ t3[0,1] ++ usub16 r3, r3, r9 @ t3[2,3] ++ uadd16 r8, r4, r6 @ t1[0,1] ++ uadd16 r9, r5, r7 @ t1[2,3] ++ usub16 r4, r4, r6 @ t2[0,1] ++ usub16 r5, r5, r7 @ t2[2,3] ++ ++ uadd16 r6, r12, r8 @ dc0[0,1] ++ uadd16 r7, r14, r9 @ dc0[2,3] ++ usub16 r12, r12, r8 @ dc2[0,1] ++ usub16 r14, r14, r9 @ dc2[2,3] ++ uadd16 r8, r2, r4 @ dc1[0,1] ++ uadd16 r9, r3, r5 @ dc1[2,3] ++ usub16 r2, r2, r4 @ dc3[0,1] ++ usub16 r3, r3, r5 @ dc3[2,3] ++ ++ mov r1, #3 ++ orr r1, r1, #0x30000 @ 3 | 3 (round) ++ ++ @ "transpose" ++ pkhbt r4, r6, r8, lsl #16 @ dc{0,1}[0] ++ pkhtb r6, r8, r6, asr #16 @ dc{0,1}[1] ++ pkhbt r5, r12, r2, lsl #16 @ dc{2,3}[0] ++ pkhtb r12, r2, r12, asr #16 @ dc{2,3}[1] ++ pkhbt r8, r7, r9, lsl #16 @ dc{0,1}[2] ++ uadd16 r4, r4, r1 ++ uadd16 r5, r5, r1 ++ pkhtb r7, r9, r7, asr #16 @ dc{0,1}[3] ++ pkhbt r2, r14, r3, lsl #16 @ dc{2,3}[2] ++ pkhtb r14, r3, r14, asr #16 @ dc{2,3}[3] ++ ++ @ loop2 ++ uadd16 r9, r4, r7 @ t0[0,1] ++ uadd16 r3, r5, r14 @ t0[2,3] ++ usub16 r4, r4, r7 @ t3[0,1] ++ usub16 r5, r5, r14 @ t3[2,3] ++ uadd16 r7, r6, r8 @ t1[0,1] ++ uadd16 r14, r12, r2 @ t1[2,3] ++ usub16 r6, r6, r8 @ t2[0,1] ++ usub16 r12, r12, r2 @ t2[2,3] ++ ++ uadd16 r8, r9, r7 @ block[0,1][0] ++ uadd16 r2, r3, r14 @ block[2,3][0] ++ usub16 r9, r9, r7 @ block[0,1][2] ++ usub16 r3, r3, r14 @ block[2,3][2] ++ uadd16 r7, r4, r6 @ block[0,1][1] ++ uadd16 r14, r5, r12 @ block[2,3][1] ++ usub16 r4, r4, r6 @ block[0,1][3] ++ usub16 r5, r5, r12 @ block[2,3][3] ++ ++ @ store ++ mov r6, r8, asr #19 @ block[1][0] ++ mov r12, r7, asr #19 @ block[1][1] ++ mov r1, r9, asr #19 @ block[1][2] ++ mov r10, r4, asr #19 @ block[1][3] ++ sxth r8, r8 ++ sxth r7, r7 ++ sxth r9, r9 ++ sxth r4, r4 ++ asr r8, #3 @ block[0][0] ++ asr r7, #3 @ block[0][1] ++ asr r9, #3 @ block[0][2] ++ asr r4, #3 @ block[0][3] ++ ++ strh r8, [r0], #32 ++ strh r7, [r0], #32 ++ strh r9, [r0], #32 ++ strh r4, [r0], #32 ++ strh r6, [r0], #32 ++ strh r12,[r0], #32 ++ strh r1, [r0], #32 ++ strh r10,[r0], #32 ++ ++ mov r6, r2, asr #19 @ block[3][0] ++ mov r12, r14, asr #19 @ block[3][1] ++ mov r1, r3, asr #19 @ block[3][2] ++ mov r10, r5, asr #19 @ block[3][3] ++ sxth r2, r2 ++ sxth r14, r14 ++ sxth r3, r3 ++ sxth r5, r5 ++ asr r2, #3 @ block[2][0] ++ asr r14, #3 @ block[2][1] ++ asr r3, #3 @ block[2][2] ++ asr r5, #3 @ block[2][3] ++ ++ strh r2, [r0], #32 ++ strh r14,[r0], #32 ++ strh r3, [r0], #32 ++ strh r5, [r0], #32 ++ strh r6, [r0], #32 ++ strh r12,[r0], #32 ++ strh r1, [r0], #32 ++ strh r10,[r0], #32 ++ ++ pop {r4 - r10, pc} ++endfunc ++ ++@ void vp8_luma_dc_wht_dc(DCTELEM block[4][4][16], DCTELEM dc[16]) ++function ff_vp8_luma_dc_wht_dc_armv6, export=1 ++ ldrsh r2, [r1] ++ mov r3, #0 ++ add r2, r2, #3 ++ strh r3, [r1] ++ asr r2, r2, #3 ++ .rept 16 ++ strh r2, [r0], #32 ++ .endr ++ bx lr ++endfunc ++ ++@ void vp8_idct_add(uint8_t *dst, DCTELEM block[16], int stride) ++function ff_vp8_idct_add_armv6, export=1 ++ push {r4 - r11, lr} ++ sub sp, sp, #32 ++ ++ mov r3, #0x00004E00 @ cos ++ orr r3, r3, #0x0000007B @ cospi8sqrt2minus1 = 20091 ++ mov r4, #0x00008A00 @ sin ++ orr r4, r4, #0x0000008C @ sinpi8sqrt2 = 35468 ++ mov r5, #0x2 @ i=2 ++1: ++ ldr r6, [r1, #8] @ i5 | i4 = block1[1] | block1[0] ++ ldr r12,[r1, #24] @ i13 | i12 = block3[1] | block3[0] ++ ldr r14,[r1, #16] @ i9 | i8 = block2[1] | block2[0] ++ ++ smulwt r9, r3, r6 @ (ip[5] * cospi8sqrt2minus1) >> 16 ++ smulwb r7, r3, r6 @ (ip[4] * cospi8sqrt2minus1) >> 16 ++ smulwt r10, r4, r6 @ (ip[5] * sinpi8sqrt2) >> 16 ++ smulwb r8, r4, r6 @ (ip[4] * sinpi8sqrt2) >> 16 ++ pkhbt r7, r7, r9, lsl #16 @ 5c | 4c ++ smulwt r11, r3, r12 @ (ip[13] * cospi8sqrt2minus1) >> 16 ++ pkhbt r8, r8, r10, lsl #16 @ 5s | 4s = t2 first half ++ uadd16 r6, r6, r7 @ 5c+5 | 4c+4 = t3 first half ++ smulwt r7, r4, r12 @ (ip[13] * sinpi8sqrt2) >> 16 ++ smulwb r9, r3, r12 @ (ip[12] * cospi8sqrt2minus1) >> 16 ++ smulwb r10, r4, r12 @ (ip[12] * sinpi8sqrt2) >> 16 ++ ++ subs r5, r5, #1 @ i-- ++ pkhbt r9, r9, r11, lsl #16 @ 13c | 12c ++ ldr r11,[r1] @ i1 | i0 ++ pkhbt r10, r10, r7, lsl #16 @ 13s | 12s = t3 second half ++ uadd16 r7, r12, r9 @ 13c+13 | 12c+12 = t2 second half ++ usub16 r7, r8, r7 @ c = t2 ++ uadd16 r6, r6, r10 @ d = t3 ++ uadd16 r10, r11, r14 @ a = t0 ++ usub16 r8, r11, r14 @ b = t1 ++ uadd16 r9, r10, r6 @ a+d = tmp{0,1}[0] ++ usub16 r10, r10, r6 @ a-d = tmp{0,1}[3] ++ uadd16 r6, r8, r7 @ b+c = tmp{0,1}[1] ++ usub16 r7, r8, r7 @ b-c = tmp{0,1}[2] ++ mov r8, #0 ++ str r6, [sp, #8] @ o5 | o4 ++ str r7, [sp, #16] @ o9 | o8 ++ str r10,[sp, #24] @ o13 | o12 ++ str r9, [sp], #4 @ o1 | o0 ++ str r8, [r1, #24] ++ str r8, [r1, #16] ++ str r8, [r1, #8] ++ str r8, [r1], #4 ++ bne 1b ++ ++ mov r5, #0x2 @ i=2 ++ sub sp, sp, #8 ++2: ++ ldr r6, [sp, #8] @ i5 | i4 = tmp{0,1}[1] ++ ldr r14,[sp, #4] @ i3 | i2 = tmp{2,3}[0] ++ ldr r12,[sp, #12] @ i7 | i6 = tmp{2,3}[1] ++ ldr r1, [sp], #16 @ i1 | i0 = tmp{0,1}[0] ++ smulwt r9, r3, r6 @ (ip[5] * cospi8sqrt2minus1) >> 16 ++ smulwt r7, r3, r1 @ (ip[1] * cospi8sqrt2minus1) >> 16 ++ smulwt r10, r4, r6 @ (ip[5] * sinpi8sqrt2) >> 16 ++ smulwt r8, r4, r1 @ (ip[1] * sinpi8sqrt2) >> 16 ++ pkhbt r11, r1, r6, lsl #16 @ i4 | i0 = t0/t1 first half ++ pkhbt r7, r7, r9, lsl #16 @ 5c | 1c ++ pkhbt r8, r8, r10, lsl #16 @ 5s | 1s = temp1 = t2 first half ++ pkhtb r1, r6, r1, asr #16 @ i5 | i1 ++ uadd16 r1, r7, r1 @ 5c+5 | 1c+1 = temp2 (d) = t3 first half ++ pkhbt r9, r14, r12, lsl #16 @ i6 | i2 = t0/t1 second half ++ uadd16 r10, r11, r9 @ a = t0 ++ usub16 r9, r11, r9 @ b = t1 ++ pkhtb r6, r12, r14, asr #16 @ i7 | i3 ++ subs r5, r5, #0x1 @ i-- ++ smulwt r7, r3, r6 @ (ip[7] * cospi8sqrt2minus1) >> 16 ++ smulwt r11, r4, r6 @ (ip[7] * sinpi8sqrt2) >> 16 ++ smulwb r12, r3, r6 @ (ip[3] * cospi8sqrt2minus1) >> 16 ++ smulwb r14, r4, r6 @ (ip[3] * sinpi8sqrt2) >> 16 ++ ++ pkhbt r7, r12, r7, lsl #16 @ 7c | 3c ++ pkhbt r11, r14, r11, lsl #16 @ 7s | 3s = temp1 (d) = t3 second half ++ mov r14, #0x4 @ set up 4's ++ orr r14, r14, #0x40000 @ 4|4 ++ uadd16 r6, r7, r6 @ 7c+7 | 3c+3 = temp2 (c) = t2 second half ++ usub16 r12, r8, r6 @ c (o5 | o1) = t2 ++ uadd16 r6, r11, r1 @ d (o7 | o3) = t3 ++ uadd16 r10, r10, r14 @ t0 + 4 ++ uadd16 r9, r9, r14 @ t1 + 4 ++ uadd16 r7, r10, r6 @ a+d = dst{0,1}[0] ++ usub16 r6, r10, r6 @ a-d = dst{0,1}[3] ++ uadd16 r10, r9, r12 @ b+c = dst{0,1}[1] ++ usub16 r1, r9, r12 @ b-c = dst{0,1}[2] ++ ++ mov r9, r6, asr #3 @ o[1][3] ++ mov r12, r1, asr #3 @ o[1][2] ++ pkhtb r8, r12, r7, asr #19 @ o[1][0,2] ++ pkhtb r11, r9, r10, asr #19 @ o[1][1,3] ++ ldr r12,[r0] ++ ldr r9, [r0, r2] ++ sxth r7, r7 ++ sxth r6, r6 ++ sxth r10, r10 ++ sxth r1, r1 ++ asr r7, #3 @ o[0][0] ++ asr r10, #3 @ o[0][1] ++ pkhbt r7, r7, r1, lsl #13 @ o[0][0,2] ++ pkhbt r10, r10, r6, lsl #13 @ o[0][1,3] ++ ++ uxtab16 r7, r7, r12 ++ uxtab16 r10, r10, r12, ror #8 ++ uxtab16 r8, r8, r9 ++ uxtab16 r11, r11, r9, ror #8 ++ usat16 r7, #8, r7 ++ usat16 r10, #8, r10 ++ usat16 r8, #8, r8 ++ usat16 r11, #8, r11 ++ orr r7, r7, r10, lsl #8 ++ orr r8, r8, r11, lsl #8 ++ str r8, [r0, r2] ++ str_post r7, r0, r2, lsl #1 ++ ++ bne 2b ++ ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void vp8_idct_dc_add(uint8_t *dst, DCTELEM block[16], int stride) ++function ff_vp8_idct_dc_add_armv6, export=1 ++ push {r4 - r5, lr} ++ ldrsh r3, [r1] ++ mov r4, #0 ++ add r3, r3, #4 ++ asr r3, #3 ++ strh r4, [r1], #32 ++ ldr r4, [r0, r2] ++ ldr_post r5, r0, r2, lsl #1 ++ pkhbt r3, r3, r3, lsl #16 ++ ++ uxtab16 lr, r3, r5 @ a1+2 | a1+0 ++ uxtab16 r5, r3, r5, ror #8 @ a1+3 | a1+1 ++ uxtab16 r12, r3, r4 ++ uxtab16 r4, r3, r4, ror #8 ++ usat16 lr, #8, lr ++ usat16 r5, #8, r5 ++ usat16 r12, #8, r12 ++ usat16 r4, #8, r4 ++ orr lr, lr, r5, lsl #8 ++ orr r12, r12, r4, lsl #8 ++ ldr r5, [r0] ++ ldr r4, [r0, r2] ++ sub r0, r0, r2, lsl #1 ++ str r12,[r0, r2] ++ str_post lr, r0, r2, lsl #1 ++ ++ uxtab16 lr, r3, r5 ++ uxtab16 r5, r3, r5, ror #8 ++ uxtab16 r12, r3, r4 ++ uxtab16 r4, r3, r4, ror #8 ++ usat16 lr, #8, lr ++ usat16 r5, #8, r5 ++ usat16 r12, #8, r12 ++ usat16 r4, #8, r4 ++ orr lr, lr, r5, lsl #8 ++ orr r12, r12, r4, lsl #8 ++ ++ str r12,[r0, r2] ++ str_post lr, r0, r2, lsl #1 ++ ++ pop {r4 - r5, pc} ++endfunc ++ ++@ void vp8_idct_dc_add4uv(uint8_t *dst, DCTELEM block[4][16], int stride) ++function ff_vp8_idct_dc_add4uv_armv6, export=1 ++ push {lr} ++ ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, r2, lsl #2 ++ add r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, r2, lsl #2 ++ add r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ ++ pop {pc} ++endfunc ++ ++@ void vp8_idct_dc_add4y(uint8_t *dst, DCTELEM block[4][16], int stride) ++function ff_vp8_idct_dc_add4y_armv6, export=1 ++ push {lr} ++ ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, r2, lsl #2 ++ add r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, r2, lsl #2 ++ add r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ sub r0, r0, r2, lsl #2 ++ add r0, r0, #4 ++ bl ff_vp8_idct_dc_add_armv6 ++ ++ pop {pc} ++endfunc ++ ++@ loopfilter ++ ++@ void vp8_v_loop_filter16_simple(uint8_t *dst, int stride, int flim) ++function ff_vp8_v_loop_filter16_simple_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ ldr_dpren r3, r0, r1, lsl #1 @ p1 ++ ldr_dpren r4, r0, r1 @ p0 ++ ldr r5, [r0] @ q0 ++ ldr r6, [r0, r1] @ q1 ++ orr r2, r2, r2, lsl #16 ++ mov r9, #4 @ count ++ mov lr, #0 @ need 0 in a couple places ++ orr r12, r2, r2, lsl #8 @ splat int -> byte ++ ldr r2, c0x80808080 ++ ++1: ++ @ vp8_simple_filter_mask() ++ uqsub8 r7, r3, r6 @ p1 - q1 ++ uqsub8 r8, r6, r3 @ q1 - p1 ++ uqsub8 r10, r4, r5 @ p0 - q0 ++ uqsub8 r11, r5, r4 @ q0 - p0 ++ orr r8, r8, r7 @ abs(p1 - q1) ++ orr r10, r10, r11 @ abs(p0 - q0) ++ uqadd8 r10, r10, r10 @ abs(p0 - q0) * 2 ++ uhadd8 r8, r8, lr @ abs(p1 - q2) >> 1 ++ uqadd8 r10, r10, r8 @ abs(p0 - q0)*2 + abs(p1 - q1)/2 ++ mvn r8, #0 ++ usub8 r10, r12, r10 @ compare to flimit. usub8 sets GE flags ++ sel r10, r8, lr @ filter mask: F or 0 ++ cmp r10, #0 ++ beq 2f @ skip filtering if all masks are 0x00 ++ ++ @ vp8_simple_filter() ++ eor r3, r3, r2 @ p1 offset to convert to a signed value ++ eor r6, r6, r2 @ q1 offset to convert to a signed value ++ eor r4, r4, r2 @ p0 offset to convert to a signed value ++ eor r5, r5, r2 @ q0 offset to convert to a signed value ++ ++ qsub8 r3, r3, r6 @ vp8_filter = p1 - q1 ++ qsub8 r6, r5, r4 @ q0 - p0 ++ qadd8 r3, r3, r6 @ += q0 - p0 ++ ldr r7, c0x04040404 ++ qadd8 r3, r3, r6 @ += q0 - p0 ++ ldr r8, c0x03030303 ++ qadd8 r3, r3, r6 @ vp8_filter = p1-q1 + 3*(q0-p0)) ++ @STALL ++ and r3, r3, r10 @ vp8_filter &= mask ++ ++ qadd8 r7, r3, r7 @ Filter1 = vp8_filter + 4 ++ qadd8 r8, r3, r8 @ Filter2 = vp8_filter + 3 ++ ++ shadd8 r7, r7, lr ++ shadd8 r8, r8, lr ++ shadd8 r7, r7, lr ++ shadd8 r8, r8, lr ++ shadd8 r7, r7, lr @ Filter1 >>= 3 ++ shadd8 r8, r8, lr @ Filter2 >>= 3 ++ ++ qsub8 r5, r5, r7 @ u = q0 - Filter1 ++ qadd8 r4, r4, r8 @ u = p0 + Filter2 ++ eor r5, r5, r2 @ *oq0 = u^0x80 ++ eor r4, r4, r2 @ *op0 = u^0x80 ++T sub r7, r0, r1 ++ str r5, [r0] @ store oq0 result ++A str r4, [r0, -r1] @ store op0 result ++T str r4, [r7] ++ ++2: ++ subs r9, r9, #1 @ counter-- ++ add r0, r0, #4 @ next row ++T itttt ne ++A ldrne r3, [r0, -r1, lsl #1] @ p1 ++T subne r3, r0, r1, lsl #1 ++T ldrne r3, [r3] @ p1 ++A ldrne r4, [r0, -r1] @ p0 ++T subne r4, r0, r1 ++T ldrne r4, [r4] @ p0 ++T itt ne ++ ldrne r5, [r0] @ q0 ++ ldrne r6, [r0, r1] @ q1 ++ ++ bne 1b ++ ++ pop {r4 - r11, pc} ++endfunc ++ ++c0x01010101: .long 0x01010101 ++c0x03030303: .long 0x03030303 ++c0x04040404: .long 0x04040404 ++c0x7F7F7F7F: .long 0x7F7F7F7F ++c0x80808080: .long 0x80808080 ++ ++@ void vp8_v_loop_filter16_inner(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh) ++@ and ++@ void vp8_v_loop_filter8uv_inner(uint8_t *dstU, uint8_t *dstV, int stride, ++@ int fE, int fI, int hev_thresh) ++@ call: ++@ void vp8_v_loop_filter_inner(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh, int count) ++function ff_vp8_v_loop_filter_inner_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ldr r5, [sp, #40] @ counter ++ ldr r6, [sp, #36] @ load thresh address ++ sub sp, sp, #16 @ create temp buffer ++ ++ ldr r10,[r0, r1] @ p2 ++ ldr_post r9, r0, r1, lsl #1 @ p3 ++ ldr r12,[r0, r1] @ p0 ++ ldr_post r11, r0, r1, lsl #1 @ p1 ++ ++ orr r2, r2, r2, lsl #16 ++ orr r3, r3, r3, lsl #16 ++ orr r6, r6, r6, lsl #16 ++ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte ++ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte ++ orr r3, r6, r6, lsl #8 @ thresh splat int -> byte ++ ++1: ++ @ vp8_filter_mask() function ++ @ calculate breakout conditions ++ uqsub8 r6, r9, r10 @ p3 - p2 ++ uqsub8 r7, r10, r9 @ p2 - p3 ++ uqsub8 r8, r10, r11 @ p2 - p1 ++ uqsub8 r10, r11, r10 @ p1 - p2 ++ ++ orr r6, r6, r7 @ abs (p3-p2) ++ orr r8, r8, r10 @ abs (p2-p1) ++ uqsub8 lr, r6, r2 @ compare to limit. lr: vp8_filter_mask ++ uqsub8 r8, r8, r2 @ compare to limit ++ uqsub8 r6, r11, r12 @ p1 - p0 ++ orr lr, lr, r8 ++ uqsub8 r7, r12, r11 @ p0 - p1 ++ ldr r10,[r0, r1] @ q1 ++ ldr_post r9, r0, r1, lsl #1 @ q0 ++ orr r6, r6, r7 @ abs (p1-p0) ++ uqsub8 r7, r6, r2 @ compare to limit ++ uqsub8 r8, r6, r3 @ compare to thresh -- save r8 for later ++ orr lr, lr, r7 ++ ++ uqsub8 r6, r11, r10 @ p1 - q1 ++ uqsub8 r7, r10, r11 @ q1 - p1 ++ uqsub8 r11, r12, r9 @ p0 - q0 ++ uqsub8 r12, r9, r12 @ q0 - p0 ++ orr r6, r6, r7 @ abs (p1-q1) ++ ldr r7, c0x7F7F7F7F ++ orr r12, r11, r12 @ abs (p0-q0) ++ ldr_post r11, r0, r1 @ q2 ++ uqadd8 r12, r12, r12 @ abs (p0-q0) * 2 ++ and r6, r7, r6, lsr #1 @ abs (p1-q1) / 2 ++ uqsub8 r7, r9, r10 @ q0 - q1 ++ uqadd8 r12, r12, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2 ++ uqsub8 r6, r10, r9 @ q1 - q0 ++ uqsub8 r12, r12, r4 @ compare to flimit ++ uqsub8 r9, r11, r10 @ q2 - q1 ++ ++ orr lr, lr, r12 ++ ++ ldr_post r12, r0, r1 @ q3 ++ uqsub8 r10, r10, r11 @ q1 - q2 ++ orr r6, r7, r6 @ abs (q1-q0) ++ orr r10, r9, r10 @ abs (q2-q1) ++ uqsub8 r7, r6, r2 @ compare to limit ++ uqsub8 r10, r10, r2 @ compare to limit ++ uqsub8 r6, r6, r3 @ compare to thresh -- save r6 for later ++ orr lr, lr, r7 ++ orr lr, lr, r10 ++ ++ uqsub8 r10, r12, r11 @ q3 - q2 ++ uqsub8 r9, r11, r12 @ q2 - q3 ++ ++ mvn r11, #0 @ r11 == -1 ++ ++ orr r10, r10, r9 @ abs (q3-q2) ++ uqsub8 r10, r10, r2 @ compare to limit ++ ++ mov r12, #0 ++ orr lr, lr, r10 ++ sub r0, r0, r1, lsl #2 ++ ++ usub8 lr, r12, lr @ use usub8 instead of ssub8 ++ sel lr, r11, r12 @ filter mask: lr ++ ++ cmp lr, #0 ++ beq 2f @ skip filtering ++ ++ sub r0, r0, r1, lsl #1 @ move r0 pointer down by 6 lines ++ ++ @vp8_hevmask() function ++ @calculate high edge variance ++ orr r10, r6, r8 @ calculate vp8_hevmask ++ ++ usub8 r10, r12, r10 @ use usub8 instead of ssub8 ++ sel r6, r12, r11 @ obtain vp8_hevmask: r6 ++ ++ @vp8_filter() function ++ ldr r8, [r0, r1] @ p0 ++ ldr_post r7, r0, r1, lsl #1 @ p1 ++ ldr r12, c0x80808080 ++ ldr r10,[r0, r1] @ q1 ++ ldr_post r9, r0, r1, lsl #1 @ q0 ++ ++ eor r7, r7, r12 @ p1 offset to convert to a signed value ++ eor r8, r8, r12 @ p0 offset to convert to a signed value ++ eor r9, r9, r12 @ q0 offset to convert to a signed value ++ eor r10, r10, r12 @ q1 offset to convert to a signed value ++ ++ str r9, [sp] @ store qs0 temporarily ++ str r8, [sp, #4] @ store ps0 temporarily ++ str r10,[sp, #8] @ store qs1 temporarily ++ str r7, [sp, #12] @ store ps1 temporarily ++ ++ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1) ++ qsub8 r8, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) ++ ++ and r7, r7, r6 @ vp8_filter (r7) &= hev ++ ++ qadd8 r7, r7, r8 ++ ldr r9, c0x03030303 @ r9 = 3 --modified for vp8 ++ ++ qadd8 r7, r7, r8 ++ ldr r10, c0x04040404 ++ ++ qadd8 r7, r7, r8 ++ and r7, r7, lr @ vp8_filter &= mask@ ++ ++ qadd8 r8, r7, r9 @ Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3) ++ qadd8 r7, r7, r10 @ vp8_filter = vp8_signed_char_clamp(vp8_filter+4) ++ ++ mov r9, #0 ++ shadd8 r8, r8, r9 @ Filter2 >>= 3 ++ shadd8 r7, r7, r9 @ vp8_filter >>= 3 ++ shadd8 r8, r8, r9 ++ shadd8 r7, r7, r9 ++ shadd8 lr, r8, r9 @ lr: Filter2 ++ shadd8 r7, r7, r9 @ r7: filter ++ ++ @calculate output ++ ++ ldr r8, [sp] @ load qs0 ++ ldr r9, [sp, #4] @ load ps0 ++ ++ ldr r10, c0x01010101 ++ ++ qsub8 r8, r8, r7 @ u = vp8_signed_char_clamp(qs0 - vp8_filter) ++ qadd8 r9, r9, lr @ u = vp8_signed_char_clamp(ps0 + Filter2) ++ ++ mov lr, #0 ++ sadd8 r7, r7, r10 @ vp8_filter += 1 ++ shadd8 r7, r7, lr @ vp8_filter >>= 1 ++ ++ ldr r11,[sp, #12] @ load ps1 ++ ldr r10,[sp, #8] @ load qs1 ++ ++ bic r7, r7, r6 @ vp8_filter &= ~hev ++ sub r0, r0, r1, lsl #2 ++ ++ qadd8 r11, r11, r7 @ u = vp8_signed_char_clamp(ps1 + vp8_filter) ++ qsub8 r10, r10, r7 @ u = vp8_signed_char_clamp(qs1 - vp8_filter) ++ ++ eor r11, r11, r12 @ *op1 = u^0x80 ++ eor r9, r9, r12 @ *op0 = u^0x80 ++ eor r8, r8, r12 @ *oq0 = u^0x80 ++ eor r10, r10, r12 @ *oq1 = u^0x80 ++ str r9, [r0, r1] @ store op0 result ++ str_post r11, r0, r1, lsl #1 @ store op1 ++ str r10,[r0, r1] @ store oq1 ++ str_post r8, r0, r1, lsl #1 @ store oq0 result ++ ++ sub r0, r0, r1, lsl #1 ++ ++2: ++ add r0, r0, #4 ++ sub r0, r0, r1, lsl #2 ++ ++ subs r5, r5, #1 ++T ittt ne ++ ldrne r10,[r0, r1] @ p2 ++A ldrne r9, [r0], r1, lsl #1 @ p3 ++T ldrne r9, [r0] @ p3 ++T addne r0, r0, r1, lsl #1 ++T ittt ne ++ ldrne r12,[r0, r1] @ p0 ++A ldrne r11,[r0], r1, lsl #1 @ p1 ++T ldrne r11,[r0] @ p3 ++T addne r0, r0, r1, lsl #1 ++ ++ bne 1b ++ ++ add sp, sp, #16 ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void vp8_v_loop_filter16(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh) ++@ and ++@ void vp8_v_loop_filter8uv(uint8_t *dstU, uint8_t *dstV, int stride, ++@ int fE, int fI, int hev_thresh) ++@ call: ++@ void vp8_v_loop_filter(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh, int count) ++function ff_vp8_v_loop_filter_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ldr r5, [sp, #40] @ counter ++ ldr r6, [sp, #36] @ load thresh address ++ sub sp, sp, #16 @ create temp buffer ++ ++ ldr r10,[r0, r1] @ p2 ++ ldr_post r9, r0, r1, lsl #1 @ p3 ++ ldr r12,[r0, r1] @ p0 ++ ldr_post r11, r0, r1, lsl #1 @ p1 ++ ++ orr r2, r2, r2, lsl #16 ++ orr r3, r3, r3, lsl #16 ++ orr r6, r6, r6, lsl #16 ++ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte ++ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte ++ orr r3, r6, r6, lsl #8 @ thresh splat int -> byte ++ ++1: ++ @ vp8_filter_mask() function ++ @ calculate breakout conditions ++ uqsub8 r6, r9, r10 @ p3 - p2 ++ uqsub8 r7, r10, r9 @ p2 - p3 ++ uqsub8 r8, r10, r11 @ p2 - p1 ++ uqsub8 r10, r11, r10 @ p1 - p2 ++ ++ orr r6, r6, r7 @ abs (p3-p2) ++ orr r8, r8, r10 @ abs (p2-p1) ++ uqsub8 lr, r6, r2 @ compare to limit. lr: vp8_filter_mask ++ uqsub8 r8, r8, r2 @ compare to limit ++ ++ uqsub8 r6, r11, r12 @ p1 - p0 ++ orr lr, lr, r8 ++ uqsub8 r7, r12, r11 @ p0 - p1 ++ ldr r10,[r0, r1] @ q1 ++ ldr_post r9, r0, r1, lsl #1 @ q0 ++ orr r6, r6, r7 @ abs (p1-p0) ++ uqsub8 r7, r6, r2 @ compare to limit ++ uqsub8 r8, r6, r3 @ compare to thresh -- save r8 for later ++ orr lr, lr, r7 ++ ++ uqsub8 r6, r11, r10 @ p1 - q1 ++ uqsub8 r7, r10, r11 @ q1 - p1 ++ uqsub8 r11, r12, r9 @ p0 - q0 ++ uqsub8 r12, r9, r12 @ q0 - p0 ++ orr r6, r6, r7 @ abs (p1-q1) ++ ldr r7, c0x7F7F7F7F ++ orr r12, r11, r12 @ abs (p0-q0) ++ ldr_post r11, r0, r1 @ q2 ++ uqadd8 r12, r12, r12 @ abs (p0-q0) * 2 ++ and r6, r7, r6, lsr #1 @ abs (p1-q1) / 2 ++ uqsub8 r7, r9, r10 @ q0 - q1 ++ uqadd8 r12, r12, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2 ++ uqsub8 r6, r10, r9 @ q1 - q0 ++ uqsub8 r12, r12, r4 @ compare to flimit ++ uqsub8 r9, r11, r10 @ q2 - q1 ++ ++ orr lr, lr, r12 ++ ++ ldr_post r12, r0, r1 @ q3 ++ ++ uqsub8 r10, r10, r11 @ q1 - q2 ++ orr r6, r7, r6 @ abs (q1-q0) ++ orr r10, r9, r10 @ abs (q2-q1) ++ uqsub8 r7, r6, r2 @ compare to limit ++ uqsub8 r10, r10, r2 @ compare to limit ++ uqsub8 r6, r6, r3 @ compare to thresh -- save r6 for later ++ orr lr, lr, r7 ++ orr lr, lr, r10 ++ ++ uqsub8 r10, r12, r11 @ q3 - q2 ++ uqsub8 r9, r11, r12 @ q2 - q3 ++ ++ mvn r11, #0 @ r11 == -1 ++ ++ orr r10, r10, r9 @ abs (q3-q2) ++ uqsub8 r10, r10, r2 @ compare to limit ++ ++ mov r12, #0 ++ ++ orr lr, lr, r10 ++ ++ usub8 lr, r12, lr @ use usub8 instead of ssub8 ++ sel lr, r11, r12 @ filter mask: lr ++ ++ cmp lr, #0 ++ beq 2f @ skip filtering ++ ++ @vp8_hevmask() function ++ @calculate high edge variance ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 6 lines ++ sub r0, r0, r1, lsl #1 ++ ++ orr r10, r6, r8 ++ ++ usub8 r10, r12, r10 ++ sel r6, r12, r11 @ hev mask: r6 ++ ++ @vp8_mbfilter() function ++ @p2, q2 are only needed at the end. Do not need to load them in now. ++ ldr r8, [r0, r1] @ p0 ++ ldr_post r7, r0, r1, lsl #1 @ p1 ++ ldr r12, c0x80808080 ++ ldr_post r9, r0, r1 @ q0 ++ ldr r10,[r0] @ q1 ++ ++ eor r7, r7, r12 @ ps1 ++ eor r8, r8, r12 @ ps0 ++ eor r9, r9, r12 @ qs0 ++ eor r10, r10, r12 @ qs1 ++ ++ qsub8 r12, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) ++ str r7, [sp, #12] @ store ps1 temporarily ++ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1) ++ str r10,[sp, #8] @ store qs1 temporarily ++ qadd8 r7, r7, r12 ++ str r9, [sp] @ store qs0 temporarily ++ qadd8 r7, r7, r12 ++ str r8, [sp, #4] @ store ps0 temporarily ++ qadd8 r7, r7, r12 @ vp8_filter: r7 ++ ++ ldr r10, c0x03030303 @ r10 = 3 --modified for vp8 ++ ldr r9, c0x04040404 ++ ++ and r7, r7, lr @ vp8_filter &= mask (lr is free) ++ ++ mov r12, r7 @ Filter2: r12 ++ and r12, r12, r6 @ Filter2 &= hev ++ ++ @save bottom 3 bits so that we round one side +4 and the other +3 ++ qadd8 r8, r12, r9 @ Filter1 (r8) = vp8_signed_char_clamp(Filter2+4) ++ qadd8 r12, r12, r10 @ Filter2 (r12) = vp8_signed_char_clamp(Filter2+3) ++ ++ mov r10, #0 ++ shadd8 r8, r8, r10 @ Filter1 >>= 3 ++ shadd8 r12, r12, r10 @ Filter2 >>= 3 ++ shadd8 r8, r8, r10 ++ shadd8 r12, r12, r10 ++ shadd8 r8, r8, r10 @ r8: Filter1 ++ shadd8 r12, r12, r10 @ r12: Filter2 ++ ++ ldr r9, [sp] @ load qs0 ++ ldr r11,[sp, #4] @ load ps0 ++ ++ qsub8 r9, r9, r8 @ qs0 = vp8_signed_char_clamp(qs0 - Filter1) ++ qadd8 r11, r11, r12 @ ps0 = vp8_signed_char_clamp(ps0 + Filter2) ++ ++ bic r12, r7, r6 @ vp8_filter &= ~hev ( r6 is free) ++ ++ @roughly 3/7th difference across boundary ++ mov lr, #0x1b @ 27 ++ mov r7, #0x3f @ 63 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r7, r10, lr, r7 ++ smultb r10, r10, lr ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ add r10, r10, #63 ++ ssat r7, #8, r7, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ ldr lr, c0x80808080 ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r7, r10, lsl #16 ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ sub r0, r0, r1 ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7) ++ ++ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs0 - u) ++ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps0 + u) ++ eor r8, r8, lr @ *oq0 = s^0x80 ++ str r8, [r0] @ store *oq0 ++ sub r0, r0, r1 ++ eor r10, r10, lr @ *op0 = s^0x80 ++ str r10,[r0] @ store *op0 ++ ++ @roughly 2/7th difference across boundary ++ mov lr, #0x12 @ 18 ++ mov r7, #0x3f @ 63 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r9, r10, lr, r7 ++ smlatb r10, r10, lr, r7 ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ ssat r9, #8, r9, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ ldr lr, c0x80808080 ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r9, r10, lsl #16 ++ ++ ldr r9, [sp, #8] @ load qs1 ++ ldr r11, [sp, #12] @ load ps1 ++ ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ sub r0, r0, r1 ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7) ++ ++ qadd8 r11, r11, r10 @ s = vp8_signed_char_clamp(ps1 + u) ++ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs1 - u) ++ eor r11, r11, lr @ *op1 = s^0x80 ++ str_post r11, r0, r1 @ store *op1 ++ eor r8, r8, lr @ *oq1 = s^0x80 ++ add r0, r0, r1, lsl #1 ++ ++ mov r7, #0x3f @ 63 ++ ++ str_post r8, r0, r1 @ store *oq1 ++ ++ @roughly 1/7th difference across boundary ++ mov lr, #0x9 @ 9 ++ ldr r9, [r0] @ load q2 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r12, r10, lr, r7 ++ smlatb r10, r10, lr, r7 ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ ssat r12, #8, r12, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ sub r0, r0, r1, lsl #2 ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r12, r10, lsl #16 ++ ++ sub r0, r0, r1 ++ ldr lr, c0x80808080 ++ ++ ldr r11, [r0] @ load p2 ++ ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ eor r9, r9, lr ++ eor r11, r11, lr ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7) ++ ++ qadd8 r8, r11, r10 @ s = vp8_signed_char_clamp(ps2 + u) ++ qsub8 r10, r9, r10 @ s = vp8_signed_char_clamp(qs2 - u) ++ eor r8, r8, lr @ *op2 = s^0x80 ++ str_post r8, r0, r1, lsl #2 @ store *op2 ++ add r0, r0, r1 ++ eor r10, r10, lr @ *oq2 = s^0x80 ++ str_post r10, r0, r1, lsl #1 @ store *oq2 ++ ++2: ++ add r0, r0, #4 ++ sub r0, r0, r1, lsl #3 ++ subs r5, r5, #1 ++ ++T ittt ne ++ ldrne r10,[r0, r1] @ p2 ++A ldrne r9, [r0], r1, lsl #1 @ p3 ++T ldrne r9, [r0] @ p3 ++T addne r0, r0, r1, lsl #1 ++T ittt ne ++ ldrne r12,[r0, r1] @ p0 ++A ldrne r11,[r0], r1, lsl #1 @ p1 ++T ldrne r11,[r0] @ p3 ++T addne r0, r0, r1, lsl #1 ++ ++ bne 1b ++ ++ add sp, sp, #16 ++ pop {r4 - r11, pc} ++endfunc ++ ++.macro TRANSPOSE_MATRIX i0, i1, i2, i3, o3, o2, o1, o0 ++ @ input: $0, $1, $2, $3 ++ @ output: $4, $5, $6, $7 ++ @ i0: 03 02 01 00 ++ @ i1: 13 12 11 10 ++ @ i2: 23 22 21 20 ++ @ i3: 33 32 31 30 ++ @ o3 o2 o1 o0 ++ ++ uxtb16 \o1, \i1 @ xx 12 xx 10 ++ uxtb16 \o0, \i0 @ xx 02 xx 00 ++ uxtb16 \o3, \i3 @ xx 32 xx 30 ++ uxtb16 \o2, \i2 @ xx 22 xx 20 ++ orr \o1, \o0, \o1, lsl #8 @ 12 02 10 00 ++ orr \o3, \o2, \o3, lsl #8 @ 32 22 30 20 ++ ++ uxtb16 \i1, \i1, ror #8 @ xx 13 xx 11 ++ uxtb16 \i3, \i3, ror #8 @ xx 33 xx 31 ++ uxtb16 \i0, \i0, ror #8 @ xx 03 xx 01 ++ uxtb16 \i2, \i2, ror #8 @ xx 23 xx 21 ++ orr \i0, \i0, \i1, lsl #8 @ 13 03 11 01 ++ orr \i2, \i2, \i3, lsl #8 @ 33 23 31 21 ++ ++ pkhtb \o2, \o3, \o1, asr #16 @ 32 22 12 02 -- p1 ++ pkhbt \o0, \o1, \o3, lsl #16 @ 30 20 10 00 -- p3 ++ ++ pkhtb \o3, \i2, \i0, asr #16 @ 33 23 13 03 -- p0 ++ pkhbt \o1, \i0, \i2, lsl #16 @ 31 21 11 01 -- p2 ++.endm ++ ++@ void vp8_h_loop_filter16_simple(uint8_t *dst, int stride, int flim) ++function ff_vp8_h_loop_filter16_simple_armv6, export=1 ++ push {r4 - r11, lr} ++ orr r12, r2, r2, lsl #16 ++ ldr r2, c0x80808080 ++ orr r12, r12, r12, lsl #8 ++ ++ @ load soure data to r7, r8, r9, r10 ++ sub r0, r0, #2 ++ ldr r8, [r0, r1] ++ ldr_post r7, r0, r1, lsl #1 ++ ldr r10,[r0, r1] ++ ldr_post r9, r0, r1, lsl #1 ++ add r0, r0, #2 ++ ++ mov r11, #4 @ count (r11) for 4-in-parallel ++1: ++ @transpose r7, r8, r9, r10 to r3, r4, r5, r6 ++ TRANSPOSE_MATRIX r7, r8, r9, r10, r6, r5, r4, r3 ++ ++ @ vp8_simple_filter_mask() function ++ uqsub8 r7, r3, r6 @ p1 - q1 ++ uqsub8 r8, r6, r3 @ q1 - p1 ++ uqsub8 r9, r4, r5 @ p0 - q0 ++ uqsub8 r10, r5, r4 @ q0 - p0 ++ orr r7, r7, r8 @ abs(p1 - q1) ++ orr r9, r9, r10 @ abs(p0 - q0) ++ mov r8, #0 ++ uqadd8 r9, r9, r9 @ abs(p0 - q0) * 2 ++ uhadd8 r7, r7, r8 @ abs(p1 - q1) / 2 ++ uqadd8 r7, r7, r9 @ abs(p0 - q0)*2 + abs(p1 - q1)/2 ++ mvn r10, #0 @ r10 == -1 ++ ++ usub8 r7, r12, r7 @ compare to flimit ++ sel lr, r10, r8 @ filter mask ++ ++ cmp lr, #0 ++ beq 2f @ skip filtering ++ ++ @vp8_simple_filter() function ++ eor r3, r3, r2 @ p1 offset to convert to a signed value ++ eor r6, r6, r2 @ q1 offset to convert to a signed value ++ eor r4, r4, r2 @ p0 offset to convert to a signed value ++ eor r5, r5, r2 @ q0 offset to convert to a signed value ++ ++ qsub8 r3, r3, r6 @ vp8_filter = p1 - q1 ++ qsub8 r6, r5, r4 @ q0 - p0 ++ ++ qadd8 r3, r3, r6 @ vp8_filter += q0 - p0 ++ ldr r9, c0x03030303 @ r9 = 3 ++ ++ qadd8 r3, r3, r6 @ vp8_filter += q0 - p0 ++ ldr r7, c0x04040404 ++ ++ qadd8 r3, r3, r6 @ vp8_filter = p1-q1 + 3*(q0-p0)) ++ @STALL ++ and r3, r3, lr @ vp8_filter &= mask ++ ++ qadd8 r9, r3, r9 @ Filter2 = vp8_filter + 3 ++ qadd8 r3, r3, r7 @ Filter1 = vp8_filter + 4 ++ ++ shadd8 r9, r9, r8 ++ shadd8 r3, r3, r8 ++ shadd8 r9, r9, r8 ++ shadd8 r3, r3, r8 ++ shadd8 r9, r9, r8 @ Filter2 >>= 3 ++ shadd8 r3, r3, r8 @ Filter1 >>= 3 ++ ++ @calculate output ++ sub r0, r0, r1, lsl #2 ++ ++ qadd8 r4, r4, r9 @ u = p0 + Filter2 ++ qsub8 r5, r5, r3 @ u = q0 - Filter1 ++ eor r4, r4, r2 @ *op0 = u^0x80 ++ eor r5, r5, r2 @ *oq0 = u^0x80 ++ ++ strb r4, [r0, #-1] @ store the result ++ mov r4, r4, lsr #8 ++ strb_post r5, r0, r1 ++ mov r5, r5, lsr #8 ++ ++ strb r4, [r0, #-1] ++ mov r4, r4, lsr #8 ++ strb_post r5, r0, r1 ++ mov r5, r5, lsr #8 ++ ++ strb r4, [r0, #-1] ++ mov r4, r4, lsr #8 ++ strb_post r5, r0, r1 ++ mov r5, r5, lsr #8 ++ ++ strb r4, [r0, #-1] ++ strb_post r5, r0, r1 ++ ++2: ++ subs r11, r11, #1 ++ ++ @ load soure data to r7, r8, r9, r10 ++ sub r0, r0, #2 ++T ittt ne ++ ldrne r8, [r0, r1] ++A ldrne r7, [r0], r1, lsl #1 ++T ldrne r7, [r0] ++T addne r0, r0, r1, lsl #1 ++T ittt ne ++ ldrne r10,[r0, r1] ++A ldrne r9, [r0], r1, lsl #1 ++T ldrne r9, [r0] ++T addne r0, r0, r1, lsl #1 ++ add r0, r0, #2 ++ ++ bne 1b ++ ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void vp8_h_loop_filter16_inner(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh) ++@ and ++@ void vp8_h_loop_filter8uv_inner(uint8_t *dstU, uint8_t *dstV, int stride, ++@ int fE, int fI, int hev_thresh) ++@ call: ++@ void vp8_h_loop_filter_inner(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh, int count) ++function ff_vp8_h_loop_filter_inner_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ sub r0, r0, #4 @ move r0 pointer down by 4 ++ ldr r5, [sp, #40] @ counter ++ ldr r9, [sp, #36] @ load thresh address ++ sub sp, sp, #16 @ create temp buffer ++ ++ ldr r7, [r0, r1] @ transpose will make it into p3-p0 ++ ldr_post r6, r0, r1, lsl #1 @ load source data ++ ldr lr, [r0, r1] ++ ldr_post r8, r0, r1, lsl #1 ++ ++ orr r2, r2, r2, lsl #16 ++ orr r3, r3, r3, lsl #16 ++ orr r9, r9, r9, lsl #16 ++ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte ++ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte ++ orr r3, r9, r9, lsl #8 @ thresh splat int -> byte ++ ++1: ++ @ vp8_filter_mask() function ++ @ calculate breakout conditions ++ @ transpose the source data for 4-in-parallel operation ++ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9 ++ ++ uqsub8 r7, r9, r10 @ p3 - p2 ++ uqsub8 r8, r10, r9 @ p2 - p3 ++ uqsub8 r9, r10, r11 @ p2 - p1 ++ uqsub8 r10, r11, r10 @ p1 - p2 ++ orr r7, r7, r8 @ abs (p3-p2) ++ orr r10, r9, r10 @ abs (p2-p1) ++ uqsub8 lr, r7, r2 @ compare to limit. lr: vp8_filter_mask ++ uqsub8 r10, r10, r2 @ compare to limit ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ orr lr, lr, r10 ++ ++ uqsub8 r6, r11, r12 @ p1 - p0 ++ uqsub8 r7, r12, r11 @ p0 - p1 ++ add r0, r0, #4 @ move r0 pointer up by 4 ++ orr r6, r6, r7 @ abs (p1-p0) ++ str r11,[sp, #12] @ save p1 ++ uqsub8 r10, r6, r2 @ compare to limit ++ uqsub8 r11, r6, r3 @ compare to thresh ++ orr lr, lr, r10 ++ ++ @ transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now ++ @ transpose the source data for 4-in-parallel operation ++ str r11,[sp] @ push r11 to stack ++ ldr r7, [r0, r1] ++ ldr_post r6, r0, r1, lsl #1 @ load source data ++ str r12,[sp, #4] @ save current reg before load q0 - q3 data ++ str lr, [sp, #8] ++ ldr lr, [r0, r1] ++ ldr_post r8, r0, r1, lsl #1 ++ ++ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9 ++ ++ ldr lr, [sp, #8] @ load back (f)limit accumulator ++ ++ uqsub8 r6, r12, r11 @ q3 - q2 ++ uqsub8 r7, r11, r12 @ q2 - q3 ++ uqsub8 r12, r11, r10 @ q2 - q1 ++ uqsub8 r11, r10, r11 @ q1 - q2 ++ orr r6, r6, r7 @ abs (q3-q2) ++ orr r7, r12, r11 @ abs (q2-q1) ++ uqsub8 r6, r6, r2 @ compare to limit ++ uqsub8 r7, r7, r2 @ compare to limit ++ ldr r11,[sp, #4] @ load back p0 ++ ldr r12,[sp, #12] @ load back p1 ++ orr lr, lr, r6 ++ orr lr, lr, r7 ++ ++ uqsub8 r6, r11, r9 @ p0 - q0 ++ uqsub8 r7, r9, r11 @ q0 - p0 ++ uqsub8 r8, r12, r10 @ p1 - q1 ++ uqsub8 r11, r10, r12 @ q1 - p1 ++ orr r6, r6, r7 @ abs (p0-q0) ++ ldr r7, c0x7F7F7F7F ++ orr r8, r8, r11 @ abs (p1-q1) ++ uqadd8 r6, r6, r6 @ abs (p0-q0) * 2 ++ and r8, r7, r8, lsr #1 @ abs (p1-q1) / 2 ++ uqsub8 r11, r10, r9 @ q1 - q0 ++ uqadd8 r6, r8, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2 ++ uqsub8 r12, r9, r10 @ q0 - q1 ++ uqsub8 r6, r6, r4 @ compare to flimit ++ ++ orr r9, r11, r12 @ abs (q1-q0) ++ uqsub8 r8, r9, r2 @ compare to limit ++ uqsub8 r10, r9, r3 @ compare to thresh ++ orr lr, lr, r6 ++ orr lr, lr, r8 ++ ++ mvn r11, #0 @ r11 == -1 ++ mov r12, #0 ++ ++ usub8 lr, r12, lr ++ ldr r9, [sp] @ load the compared result ++ sel lr, r11, r12 @ filter mask: lr ++ ++ cmp lr, #0 ++ beq 2f @ skip filtering ++ ++ @vp8_hevmask() function ++ @calculate high edge variance ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ orr r9, r9, r10 ++ ++ ldrh r7, [r0, #-2] ++ ldrh_post r8, r0, r1 ++ ++ usub8 r9, r12, r9 ++ sel r6, r12, r11 @ hev mask: r6 ++ ++ @vp8_filter() function ++ @ load soure data to r6, r11, r12, lr ++ ldrh r9, [r0, #-2] ++ ldrh_post r10, r0, r1 ++ ++ pkhbt r12, r7, r8, lsl #16 ++ ++ ldrh r7, [r0, #-2] ++ ldrh_post r8, r0, r1 ++ ++ pkhbt r11, r9, r10, lsl #16 ++ ++ ldrh r9, [r0, #-2] ++ ldrh_post r10, r0, r1 ++ ++ @ Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first ++ str r6, [sp] ++ str lr, [sp, #4] ++ ++ pkhbt r6, r7, r8, lsl #16 ++ pkhbt lr, r9, r10, lsl #16 ++ ++ @transpose r12, r11, r6, lr to r7, r8, r9, r10 ++ TRANSPOSE_MATRIX r12, r11, r6, lr, r10, r9, r8, r7 ++ ++ @load back hev_mask r6 and filter_mask lr ++ ldr r12, c0x80808080 ++ ldr r6, [sp] ++ ldr lr, [sp, #4] ++ ++ eor r7, r7, r12 @ p1 offset to convert to a signed value ++ eor r8, r8, r12 @ p0 offset to convert to a signed value ++ eor r9, r9, r12 @ q0 offset to convert to a signed value ++ eor r10, r10, r12 @ q1 offset to convert to a signed value ++ ++ str r9, [sp] @ store qs0 temporarily ++ str r8, [sp, #4] @ store ps0 temporarily ++ str r10,[sp, #8] @ store qs1 temporarily ++ str r7, [sp, #12] @ store ps1 temporarily ++ ++ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1) ++ qsub8 r8, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) ++ ++ and r7, r7, r6 @ vp8_filter (r7) &= hev (r7 : filter) ++ ++ qadd8 r7, r7, r8 ++ ldr r9, c0x03030303 @ r9 = 3 --modified for vp8 ++ ++ qadd8 r7, r7, r8 ++ ldr r10, c0x04040404 ++ ++ qadd8 r7, r7, r8 ++ ++ and r7, r7, lr @ vp8_filter &= mask ++ ++ qadd8 r8, r7, r9 @ Filter2 (r8) = vp8_signed_char_clamp(vp8_filter+3) ++ qadd8 r7, r7, r10 @ vp8_filter = vp8_signed_char_clamp(vp8_filter+4) ++ ++ mov r9, #0 ++ shadd8 r8, r8, r9 @ Filter2 >>= 3 ++ shadd8 r7, r7, r9 @ vp8_filter >>= 3 ++ shadd8 r8, r8, r9 ++ shadd8 r7, r7, r9 ++ shadd8 lr, r8, r9 @ lr: filter2 ++ shadd8 r7, r7, r9 @ r7: filter ++ ++ @calculate output ++ ldr r8, [sp] @ load qs0 ++ ldr r9, [sp, #4] @ load ps0 ++ ++ ldr r10, c0x01010101 ++ ++ qsub8 r8, r8, r7 @ u = vp8_signed_char_clamp(qs0 - vp8_filter) ++ qadd8 r9, r9, lr @ u = vp8_signed_char_clamp(ps0 + Filter2) ++ ++ eor r8, r8, r12 ++ eor r9, r9, r12 ++ ++ mov lr, #0 ++ ++ sadd8 r7, r7, r10 ++ shadd8 r7, r7, lr ++ ++ ldr r10,[sp, #8] @ load qs1 ++ ldr r11,[sp, #12] @ load ps1 ++ ++ bic r7, r7, r6 @ r7: vp8_filter ++ ++ qsub8 r10, r10, r7 @ u = vp8_signed_char_clamp(qs1 - vp8_filter) ++ qadd8 r11, r11, r7 @ u = vp8_signed_char_clamp(ps1 + vp8_filter) ++ eor r10, r10, r12 ++ eor r11, r11, r12 ++ ++ sub r0, r0, r1, lsl #2 ++ ++ @we can use TRANSPOSE_MATRIX macro to transpose output - input: q1, q0, p0, p1 ++ TRANSPOSE_MATRIX r11, r9, r8, r10, lr, r12, r7, r6 ++ ++ strh r6, [r0, #-2] @ store the result ++ mov r6, r6, lsr #16 ++ strh_post r6, r0, r1 ++ ++ strh r7, [r0, #-2] ++ mov r7, r7, lsr #16 ++ strh_post r7, r0, r1 ++ ++ strh r12, [r0, #-2] ++ mov r12, r12, lsr #16 ++ strh_post r12, r0, r1 ++ ++ strh lr, [r0, #-2] ++ mov lr, lr, lsr #16 ++ strh_post lr, r0, r1 ++ ++2: ++ sub r0, r0, #4 ++ subs r5, r5, #1 ++ ++T ittt ne ++ ldrne r7, [r0, r1] ++A ldrne r6, [r0], r1, lsl #1 @ load source data ++T ldrne r6, [r0] @ load source data ++T addne r0, r0, r1, lsl #1 ++T ittt ne ++ ldrne lr, [r0, r1] ++A ldrne r8, [r0], r1, lsl #1 ++T ldrne r8, [r0] ++T addne r0, r0, r1, lsl #1 ++ ++ bne 1b ++ ++ add sp, sp, #16 ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void vp8_h_loop_filter16(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh) ++@ and ++@ void vp8_h_loop_filter8uv(uint8_t *dstU, uint8_t *dstV, int stride, ++@ int fE, int fI, int hev_thresh) ++@ call: ++@ void vp8_h_loop_filter(uint8_t *dst, int stride, ++@ int fE, int fI, int hev_thresh, int count) ++function ff_vp8_h_loop_filter_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ sub r0, r0, #4 @ move r0 pointer down by 4 ++ ldr r5, [sp, #40] @ counter ++ ldr r9, [sp, #36] @ load thresh address ++ sub sp, sp, #16 @ create temp buffer ++ ++ ldr r7, [r0, r1] @ transpose will make it into p3-p0 ++ ldr_post r6, r0, r1, lsl #1 @ load source data ++ ldr lr, [r0, r1] ++ ldr_post r8, r0, r1, lsl #1 ++ ++ orr r2, r2, r2, lsl #16 ++ orr r3, r3, r3, lsl #16 ++ orr r9, r9, r9, lsl #16 ++ orr r4, r2, r2, lsl #8 @ flimE splat int -> byte ++ orr r2, r3, r3, lsl #8 @ flimI splat int -> byte ++ orr r3, r9, r9, lsl #8 @ thresh splat int -> byte ++ ++1: ++ @ vp8_filter_mask() function ++ @ calculate breakout conditions ++ @ transpose the source data for 4-in-parallel operation ++ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9 ++ ++ uqsub8 r7, r9, r10 @ p3 - p2 ++ uqsub8 r8, r10, r9 @ p2 - p3 ++ uqsub8 r9, r10, r11 @ p2 - p1 ++ uqsub8 r10, r11, r10 @ p1 - p2 ++ orr r7, r7, r8 @ abs (p3-p2) ++ orr r10, r9, r10 @ abs (p2-p1) ++ uqsub8 lr, r7, r2 @ compare to limit. lr: vp8_filter_mask ++ uqsub8 r10, r10, r2 @ compare to limit ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ orr lr, lr, r10 ++ ++ uqsub8 r6, r11, r12 @ p1 - p0 ++ uqsub8 r7, r12, r11 @ p0 - p1 ++ add r0, r0, #4 @ move r0 pointer up by 4 ++ orr r6, r6, r7 @ abs (p1-p0) ++ str r11,[sp, #12] @ save p1 ++ uqsub8 r10, r6, r2 @ compare to limit ++ uqsub8 r11, r6, r3 @ compare to thresh ++ orr lr, lr, r10 ++ ++ @ transpose uses 8 regs(r6 - r12 and lr). Need to save reg value now ++ @ transpose the source data for 4-in-parallel operation ++ str r11,[sp] @ push r11 to stack ++ ldr r7, [r0, r1] ++ ldr_post r6, r0, r1, lsl #1 @ load source data ++ str r12,[sp, #4] @ save current reg before load q0 - q3 data ++ str lr, [sp, #8] ++ ldr lr, [r0, r1] ++ ldr_post r8, r0, r1, lsl #1 ++ ++ TRANSPOSE_MATRIX r6, r7, r8, lr, r12, r11, r10, r9 ++ ++ ldr lr, [sp, #8] @ load back (f)limit accumulator ++ ++ uqsub8 r6, r12, r11 @ q3 - q2 ++ uqsub8 r7, r11, r12 @ q2 - q3 ++ uqsub8 r12, r11, r10 @ q2 - q1 ++ uqsub8 r11, r10, r11 @ q1 - q2 ++ orr r6, r6, r7 @ abs (q3-q2) ++ orr r7, r12, r11 @ abs (q2-q1) ++ uqsub8 r6, r6, r2 @ compare to limit ++ uqsub8 r7, r7, r2 @ compare to limit ++ ldr r11,[sp, #4] @ load back p0 ++ ldr r12,[sp, #12] @ load back p1 ++ orr lr, lr, r6 ++ orr lr, lr, r7 ++ ++ uqsub8 r6, r11, r9 @ p0 - q0 ++ uqsub8 r7, r9, r11 @ q0 - p0 ++ uqsub8 r8, r12, r10 @ p1 - q1 ++ uqsub8 r11, r10, r12 @ q1 - p1 ++ orr r6, r6, r7 @ abs (p0-q0) ++ ldr r7, c0x7F7F7F7F ++ orr r8, r8, r11 @ abs (p1-q1) ++ uqadd8 r6, r6, r6 @ abs (p0-q0) * 2 ++ and r8, r7, r8, lsr #1 @ abs (p1-q1) / 2 ++ uqsub8 r11, r10, r9 @ q1 - q0 ++ uqadd8 r6, r8, r6 @ abs (p0-q0)*2 + abs (p1-q1)/2 ++ uqsub8 r12, r9, r10 @ q0 - q1 ++ uqsub8 r6, r6, r4 @ compare to flimit ++ ++ orr r9, r11, r12 @ abs (q1-q0) ++ uqsub8 r8, r9, r2 @ compare to limit ++ uqsub8 r10, r9, r3 @ compare to thresh ++ orr lr, lr, r6 ++ orr lr, lr, r8 ++ ++ mvn r11, #0 @ r11 == -1 ++ mov r12, #0 ++ ++ usub8 lr, r12, lr ++ ldr r9, [sp] @ load the compared result ++ sel lr, r11, r12 @ filter mask: lr ++ ++ cmp lr, #0 ++ beq 2f @ skip filtering ++ ++ ++ @vp8_hevmask() function ++ @calculate high edge variance ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ orr r9, r9, r10 ++ ++ ldrh r7, [r0, #-2] ++ ldrh_post r8, r0, r1 ++ ++ usub8 r9, r12, r9 ++ sel r6, r12, r11 @ hev mask: r6 ++ ++ ++ @ vp8_mbfilter() function ++ @ p2, q2 are only needed at the end. do not need to load them in now. ++ @ Transpose needs 8 regs(r6 - r12, and lr). Save r6 and lr first ++ @ load soure data to r6, r11, r12, lr ++ ldrh r9, [r0, #-2] ++ ldrh_post r10, r0, r1 ++ ++ pkhbt r12, r7, r8, lsl #16 ++ ++ ldrh r7, [r0, #-2] ++ ldrh_post r8, r0, r1 ++ ++ pkhbt r11, r9, r10, lsl #16 ++ ++ ldrh r9, [r0, #-2] ++ ldrh_post r10, r0, r1 ++ ++ str r6, [sp] @ save r6 ++ str lr, [sp, #4] @ save lr ++ ++ pkhbt r6, r7, r8, lsl #16 ++ pkhbt lr, r9, r10, lsl #16 ++ ++ @transpose r12, r11, r6, lr to p1, p0, q0, q1 ++ TRANSPOSE_MATRIX r12, r11, r6, lr, r10, r9, r8, r7 ++ ++ @load back hev_mask r6 and filter_mask lr ++ ldr r12, c0x80808080 ++ ldr r6, [sp] ++ ldr lr, [sp, #4] ++ ++ eor r7, r7, r12 @ ps1 ++ eor r8, r8, r12 @ ps0 ++ eor r9, r9, r12 @ qs0 ++ eor r10, r10, r12 @ qs1 ++ ++ qsub8 r12, r9, r8 @ vp8_signed_char_clamp(vp8_filter + 3 * ( qs0 - ps0)) ++ str r7, [sp, #12] @ store ps1 temporarily ++ qsub8 r7, r7, r10 @ vp8_signed_char_clamp(ps1-qs1) ++ str r10,[sp, #8] @ store qs1 temporarily ++ qadd8 r7, r7, r12 ++ str r9, [sp] @ store qs0 temporarily ++ qadd8 r7, r7, r12 ++ str r8, [sp, #4] @ store ps0 temporarily ++ qadd8 r7, r7, r12 @ vp8_filter: r7 ++ ++ ldr r10, c0x03030303 @ r10 = 3 --modified for vp8 ++ ldr r9, c0x04040404 ++ ++ and r7, r7, lr @ vp8_filter &= mask (lr is free) ++ ++ mov r12, r7 @ Filter2: r12 ++ and r12, r12, r6 @ Filter2 &= hev ++ ++ @save bottom 3 bits so that we round one side +4 and the other +3 ++ qadd8 r8, r12, r9 @ Filter1 (r8) = vp8_signed_char_clamp(Filter2+4) ++ qadd8 r12, r12, r10 @ Filter2 (r12) = vp8_signed_char_clamp(Filter2+3) ++ ++ mov r10, #0 ++ shadd8 r8, r8, r10 @ Filter1 >>= 3 ++ shadd8 r12, r12, r10 @ Filter2 >>= 3 ++ shadd8 r8, r8, r10 ++ shadd8 r12, r12, r10 ++ shadd8 r8, r8, r10 @ r8: Filter1 ++ shadd8 r12, r12, r10 @ r12: Filter2 ++ ++ ldr r9, [sp] @ load qs0 ++ ldr r11,[sp, #4] @ load ps0 ++ ++ qsub8 r9, r9, r8 @ qs0 = vp8_signed_char_clamp(qs0 - Filter1) ++ qadd8 r11, r11, r12 @ ps0 = vp8_signed_char_clamp(ps0 + Filter2) ++ ++ bic r12, r7, r6 @vp8_filter &= ~hev ( r6 is free) ++ ++ @roughly 3/7th difference across boundary ++ mov lr, #0x1b @ 27 ++ mov r7, #0x3f @ 63 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r7, r10, lr, r7 ++ smultb r10, r10, lr ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ add r10, r10, #63 ++ ssat r7, #8, r7, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ ldr lr, c0x80808080 ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r7, r10, lsl #16 ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 27)>>7) ++ ++ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs0 - u) ++ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps0 + u) ++ eor r8, r8, lr @ *oq0 = s^0x80 ++ eor r10, r10, lr @ *op0 = s^0x80 ++ ++ strb r10,[r0, #-1] @ store op0 result ++ strb_post r8, r0, r1 @ store oq0 result ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ strb r10,[r0, #-1] ++ strb_post r8, r0, r1 ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ strb r10,[r0, #-1] ++ strb_post r8, r0, r1 ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ strb r10,[r0, #-1] ++ strb_post r8, r0, r1 ++ ++ @roughly 2/7th difference across boundary ++ mov lr, #0x12 @ 18 ++ mov r7, #0x3f @ 63 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r9, r10, lr, r7 ++ smlatb r10, r10, lr, r7 ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ ssat r9, #8, r9, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ sub r0, r0, r1, lsl #2 @ move r0 pointer down by 4 lines ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r9, r10, lsl #16 ++ ++ ldr r9, [sp, #8] @ load qs1 ++ ldr r11,[sp, #12] @ load ps1 ++ ldr lr, c0x80808080 ++ ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ add r0, r0, #2 ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 18)>>7) ++ ++ qsub8 r8, r9, r10 @ s = vp8_signed_char_clamp(qs1 - u) ++ qadd8 r10, r11, r10 @ s = vp8_signed_char_clamp(ps1 + u) ++ eor r8, r8, lr @ *oq1 = s^0x80 ++ eor r10, r10, lr @ *op1 = s^0x80 ++ ++ ldrb r11,[r0, #-5] @ load p2 for 1/7th difference across boundary ++ strb r10,[r0, #-4] @ store op1 ++ strb r8, [r0, #-1] @ store oq1 ++ ldrb_post r9, r0, r1 @ load q2 for 1/7th difference across boundary ++ ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ ++ ldrb r6, [r0, #-5] ++ strb r10,[r0, #-4] ++ strb r8, [r0, #-1] ++ ldrb_post r7, r0, r1 ++ ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ orr r11, r11, r6, lsl #8 ++ orr r9, r9, r7, lsl #8 ++ ++ ldrb r6, [r0, #-5] ++ strb r10,[r0, #-4] ++ strb r8, [r0, #-1] ++ ldrb_post r7, r0, r1 ++ ++ mov r10, r10, lsr #8 ++ mov r8, r8, lsr #8 ++ orr r11, r11, r6, lsl #16 ++ orr r9, r9, r7, lsl #16 ++ ++ ldrb r6, [r0, #-5] ++ strb r10,[r0, #-4] ++ strb r8, [r0, #-1] ++ ldrb_post r7, r0, r1 ++ orr r11, r11, r6, lsl #24 ++ orr r9, r9, r7, lsl #24 ++ ++ @roughly 1/7th difference across boundary ++ eor r9, r9, lr ++ eor r11, r11, lr ++ ++ mov lr, #0x9 @ 9 ++ mov r7, #0x3f @ 63 ++ ++ sxtb16 r6, r12 ++ sxtb16 r10, r12, ror #8 ++ smlabb r8, r6, lr, r7 ++ smlatb r6, r6, lr, r7 ++ smlabb r12, r10, lr, r7 ++ smlatb r10, r10, lr, r7 ++ ssat r8, #8, r8, asr #7 ++ ssat r6, #8, r6, asr #7 ++ ssat r12, #8, r12, asr #7 ++ ssat r10, #8, r10, asr #7 ++ ++ sub r0, r0, r1, lsl #2 ++ ++ pkhbt r6, r8, r6, lsl #16 ++ pkhbt r10, r12, r10, lsl #16 ++ ++ uxtb16 r6, r6 ++ uxtb16 r10, r10 ++ ++ ldr lr, c0x80808080 ++ ++ orr r10, r6, r10, lsl #8 @ u = vp8_signed_char_clamp((63 + Filter2 * 9)>>7) ++ ++ qadd8 r8, r11, r10 @ s = vp8_signed_char_clamp(ps2 + u) ++ qsub8 r10, r9, r10 @ s = vp8_signed_char_clamp(qs2 - u) ++ eor r8, r8, lr @ *op2 = s^0x80 ++ eor r10, r10, lr @ *oq2 = s^0x80 ++ ++ strb r8, [r0, #-5] @ store *op2 ++ strb_post r10, r0, r1 @ store *oq2 ++ mov r8, r8, lsr #8 ++ mov r10, r10, lsr #8 ++ strb r8, [r0, #-5] ++ strb_post r10, r0, r1 ++ mov r8, r8, lsr #8 ++ mov r10, r10, lsr #8 ++ strb r8, [r0, #-5] ++ strb_post r10, r0, r1 ++ mov r8, r8, lsr #8 ++ mov r10, r10, lsr #8 ++ strb r8, [r0, #-5] ++ strb_post r10, r0, r1 ++ ++ @adjust r0 pointer for next loop ++ sub r0, r0, #2 ++ ++2: ++ sub r0, r0, #4 ++ subs r5, r5, #1 ++ ++T ittt ne ++ ldrne r7, [r0, r1] ++A ldrne r6, [r0], r1, lsl #1 @ load source data ++T ldrne r6, [r0] ++T addne r0, r0, r1, lsl #1 ++T ittt ne ++ ldrne lr, [r0, r1] ++A ldrne r8, [r0], r1, lsl #1 ++T ldrne r8, [r0] ++T addne r0, r0, r1, lsl #1 ++ ++ bne 1b ++ ++ add sp, sp, #16 ++ pop {r4 - r11, pc} ++endfunc ++ ++@ MC ++ ++@ void put_vp8_pixels16(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int h, int mx, int my) ++function ff_put_vp8_pixels16_armv6, export=1 ++ push {r4 - r11} ++ ldr r12,[sp, #32] @ h ++1: ++ subs r12, r12, #2 ++ ldr r5, [r2, #4] ++ ldr r6, [r2, #8] ++ ldr r7, [r2, #12] ++ ldr_post r4, r2, r3 ++ ldr r9, [r2, #4] ++ ldr r10,[r2, #8] ++ ldr r11,[r2, #12] ++ ldr_post r8, r2, r3 ++ strd r6, r7, [r0, #8] ++ strd_post r4, r5, r0, r1 ++ strd r10, r11,[r0, #8] ++ strd_post r8, r9, r0, r1 ++ bgt 1b ++ pop {r4 - r11} ++ bx lr ++endfunc ++ ++@ void put_vp8_pixels8(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int h, int mx, int my) ++function ff_put_vp8_pixels8_armv6, export=1 ++ push {r4 - r11} ++ ldr r12,[sp, #32] @ h ++1: ++ subs r12, r12, #4 ++ ldr r5, [r2, #4] ++ ldr_post r4, r2, r3 ++ ldr r7, [r2, #4] ++ ldr_post r6, r2, r3 ++ ldr r9, [r2, #4] ++ ldr_post r8, r2, r3 ++ ldr r11,[r2, #4] ++ ldr_post r10, r2, r3 ++ strd_post r4, r5, r0, r1 ++ strd_post r6, r7, r0, r1 ++ strd_post r8, r9, r0, r1 ++ strd_post r10, r11, r0, r1 ++ bgt 1b ++ pop {r4 - r11} ++ bx lr ++endfunc ++ ++@ void put_vp8_pixels4(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int h, int mx, int my) ++function ff_put_vp8_pixels4_armv6, export=1 ++ ldr r12, [sp, #0] @ h ++ push {r4 - r6, lr} ++1: ++ subs r12, r12, #4 ++ ldr r5, [r2, r3] ++ ldr_post r4, r2, r3, lsl #1 ++ ldr lr, [r2, r3] ++ ldr_post r6, r2, r3, lsl #1 ++ str r5, [r0, r1] ++ str_post r4, r0, r1, lsl #1 ++ str lr, [r0, r1] ++ str_post r6, r0, r1, lsl #1 ++ bgt 1b ++ pop {r4 - r6, pc} ++endfunc ++ ++@ note: worst case sum of all 6-tap filter values * 255 is 0x7f80 so 16 bit ++@ arithmatic can be used to apply filters ++const sixtap_filters_13245600, align=4 ++ .short 2, 108, -11, 36, -8, 1, 0, 0 ++ .short 3, 77, -16, 77, -16, 3, 0, 0 ++ .short 1, 36, -8, 108, -11, 2, 0, 0 ++endconst ++const fourtap_filters_1324, align=4 ++ .short -6, 12, 123, -1 ++ .short -9, 50, 93, -6 ++ .short -6, 93, 50, -9 ++ .short -1, 123, 12, -6 ++endconst ++ ++@ void put_vp8_epel_h6(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int mx) ++function ff_put_vp8_epel_h6_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ sub r2, r2, #2 ++ movrel lr, sixtap_filters_13245600 - 16 ++ ldr r12,[sp, #44] @ vp8_filter index ++ ldr r4, [sp, #36] @ width ++ add lr, lr, r12, lsl #3 ++ sub r3, r3, r4 @ src_stride - block_width ++ sub r1, r1, r4 @ dst_stride - block_width ++ lsr r4, #2 ++ ++ str r4, [sp, #36] @ "4-in-parallel" loop counter @40 ++ str r3, [sp, #44] @ src_stride - block_width @48 ++ push {r1} @ dst_stride - block_width @0 ++ @ height @44 ++ ++ ldr r1, [lr], #4 @ coefficients ++ ldr r3, [lr], #4 ++ ldr lr, [lr] ++1: ++ @ 3 loads, 10 shuffles and then mul/acc/add/shr ++ @ o0: i0/i1/i2/i3/i4/i5 -> i0/i2 (ld1) | i1/i3 (ld1) | i4/i5 (ld2) ++ @ o1: i1/i2/i3/i4/i5/i6 -> i1/i3 (ld1) | i2/i4 (ld2) | i5/i6 (ld2/3) ++ @ o2: i2/i3/i4/i5/i6/i7 -> i2/i4 (ld2) | i3/i5 (ld2) | i6/i7 (ld3) ++ @ o3: i3/i4/i5/i6/i7/i8 -> i3/i5 (ld2) | i4/i6 (ld2/3) | i7/i8 (ld3) ++ ldr r7, [r2, #5] @ ld3 -> src[5-8] ++ ldr r6, [r2, #2] @ ld2 -> src[2-5] ++ ldr r5, [r2], #4 @ ld1 -> src[0-3] ++ ++ pkhtb r7, r7, r7, asr #8 @ src[8,7,7,6] ++ uxtb16 r9, r6, ror #8 @ src[5] | src[3] ++ uxtb16 r6, r6 @ src[4] | src[2] ++ uxtb16 r8, r5, ror #8 @ src[3] | src[1] ++ uxtb16 r11, r7, ror #8 @ src[8] | src[7] ++ uxtb16 r7, r7 @ src[7] | src[6] ++ pkhtb r10, r9, r6, asr #16 @ src[5] | src[4] ++ uxtb16 r5, r5 @ src[2] | src[0] ++ ++ smuad r11, r11, lr @ filter[3][2] -> r11 ++ subs r4, r4, #1 ++ pkhbt r12, r10, r7, lsl #16 @ src[6] | src[4] ++ smuad r7, r7, lr @ filter[2][2] -> r7 ++ smuad r5, r5, r1 @ filter[0][0] -> r5 ++ smlad r11, r9, r1, r11 @ filter[3][0] -> r11 ++ smlad r7, r9, r3, r7 @ filter[2][1] -> r7 ++ smuad r9, r8, r1 @ filter[1][0] -> r9 ++ smlad r5, r8, r3, r5 @ filter[0][1] -> r5 ++ pkhtb r8, r12, r10, asr #16 @ src[6] | src[5] ++ smlad r11, r12, r3, r11 @ filter[3][1] -> r11 ++ smlad r9, r6, r3, r9 @ filter[1][1] -> r9 ++ smlad r5, r10, lr, r5 @ filter[0][2] -> r5 ++ smlad r7, r6, r1, r7 @ filter[2][0] -> r7 ++ smlad r9, r8, lr, r9 @ filter[1][2] -> r9 ++ ++ add r5, r5, #0x40 @ round_shift_and_clamp[0] ++ add r9, r9, #0x40 @ round_shift_and_clamp[1] ++ add r7, r7, #0x40 @ round_shift_and_clamp[2] ++ add r11, r11, #0x40 @ round_shift_and_clamp[3] ++ ++ usat r5, #8, r5, asr #7 ++ usat r9, #8, r9, asr #7 ++ usat r7, #8, r7, asr #7 ++ usat r11, #8, r11, asr #7 ++ ++ strb r5, [r0], #1 @ store res[0] ++ strb r9, [r0], #1 @ store res[1] ++ strb r7, [r0], #1 @ store res[2] ++ strb r11,[r0], #1 @ store res[3] ++ ++ bne 1b ++ ++ ldr r12,[sp, #44] @ height = outer-loop counter ++ subs r12, r12, #1 ++T itttt ne ++ ldrne r4, [sp, #40] @ 4-in-parallel loop counter ++ ldrne r5, [sp, #48] ++ ldrne r6, [sp] ++ strne r12,[sp, #44] ++ add r2, r2, r5 @ move to next input/output lines ++ add r0, r0, r6 ++ ++ bne 1b ++ ++ add sp, sp, #4 @ restore stack after push{r1} above ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void put_vp8_epel_v6(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int my) ++function ff_put_vp8_epel_v6_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ movrel lr, sixtap_filters_13245600 - 16 ++ ldr r12,[sp, #44] @ vp8_filter index ++ ldr r4, [sp, #36] @ width ++ add lr, lr, r12, lsl #3 ++ sub r1, r1, r4 @ dst_stride - block_width ++ lsr r4, #2 ++ ++ str r4, [sp, #36] @ "4-in-parallel" loop counter @40 ++ str r3, [sp, #44] @ src_stride - block_width @48 ++ push {r1} @ dst_stride - block_width @0 ++ @ height @44 ++1: ++ add r1, r3, r3, lsl #1 @ stride * 3 ++ ldr_dpren r5, r2, r3 @ src[0,1,2,3 + stride * 1] ++ ldr r6, [r2, r3] @ src[0,1,2,3 + stride * 3] ++ ldr r7, [r2, r3, lsl #1] @ src[0,1,2,3 + stride * 4] ++ ldr r8, [r2, r1] @ src[0,1,2,3 + stride * 5] ++ ++ @ byte -> word and "transpose" ++ uxtb16 r9, r5, ror #8 @ src[3 + stride*1] | src[1 + stride*1] ++ uxtb16 r10, r6, ror #8 @ src[3 + stride*3] | src[1 + stride*3] ++ uxtb16 r11, r7, ror #8 @ src[3 + stride*4] | src[1 + stride*4] ++ uxtb16 r12, r8, ror #8 @ src[3 + stride*5] | src[1 + stride*5] ++ uxtb16 r5, r5 @ src[2 + stride*1] | src[0 + stride*1] ++ uxtb16 r6, r6 @ src[2 + stride*3] | src[0 + stride*3] ++ uxtb16 r7, r7 @ src[2 + stride*4] | src[0 + stride*4] ++ uxtb16 r8, r8 @ src[2 + stride*5] | src[0 + stride*5] ++ pkhbt r1, r9, r10, lsl #16 @ src[1 + stride*3] | src[1 + stride*1] ++ pkhtb r9, r10, r9, asr #16 @ src[3 + stride*3] | src[3 + stride*1] ++ pkhbt r10, r11, r12, lsl #16 @ src[1 + stride*5] | src[1 + stride*4] ++ pkhtb r11, r12, r11, asr #16 @ src[3 + stride*5] | src[3 + stride*4] ++ pkhbt r12, r5, r6, lsl #16 @ src[0 + stride*3] | src[0 + stride*1] ++ pkhtb r5, r6, r5, asr #16 @ src[2 + stride*3] | src[2 + stride*1] ++ pkhbt r6, r7, r8, lsl #16 @ src[0 + stride*5] | src[0 + stride*4] ++ pkhtb r7, r8, r7, asr #16 @ src[2 + stride*5] | src[2 + stride*4] ++ ++ ldr r8, [lr, #4] @ stall - if only I had more registers... ++ smuad r12, r12, r8 @ filter[0][1] ++ smuad r1, r1, r8 @ filter[1][1] ++ smuad r5, r5, r8 @ filter[2][1] ++ smuad r9, r9, r8 @ filter[3][1] ++ ldr r8, [lr, #8] @ stall - if only I had more registers... ++ smlad r12, r6, r8, r12 @ filter[0][2] ++ smlad r1, r10, r8, r1 @ filter[1][2] ++ ldr_dpren r6, r2, r3, lsl #1 @ src[0,1,2,3 + stride * 0] ++ ldr r10,[r2], #4 @ src[0,1,2,3 + stride * 2] ++ smlad r5, r7, r8, r5 @ filter[2][2] ++ smlad r9, r11, r8, r9 @ filter[3][2] ++ ++ uxtb16 r7, r6, ror #8 @ src[3 + stride*0] | src[1 + stride*0] ++ uxtb16 r11, r10, ror #8 @ src[3 + stride*2] | src[1 + stride*2] ++ uxtb16 r6, r6 @ src[2 + stride*0] | src[0 + stride*0] ++ uxtb16 r10, r10 @ src[2 + stride*2] | src[0 + stride*2] ++ ++ pkhbt r8, r7, r11, lsl #16 @ src[1 + stride*2] | src[1 + stride*0] ++ pkhtb r7, r11, r7, asr #16 @ src[3 + stride*2] | src[3 + stride*0] ++ pkhbt r11, r6, r10, lsl #16 @ src[0 + stride*2] | src[0 + stride*0] ++ pkhtb r6, r10, r6, asr #16 @ src[2 + stride*2] | src[2 + stride*0] ++ ++ ldr r10,[lr] @ stall - if only I had more registers... ++ subs r4, r4, #1 @ counter-- ++ smlad r12, r11, r10, r12 @ filter[0][0] ++ smlad r1, r8, r10, r1 @ filter[1][0] ++ smlad r5, r6, r10, r5 @ filter[2][0] ++ smlad r9, r7, r10, r9 @ filter[3][0] ++ ++ add r12, r12, #0x40 @ round_shift_and_clamp[0] ++ add r1, r1, #0x40 @ round_shift_and_clamp[1] ++ add r5, r5, #0x40 @ round_shift_and_clamp[2] ++ add r9, r9, #0x40 @ round_shift_and_clamp[3] ++ ++ usat r12, #8, r12, asr #7 ++ usat r1, #8, r1, asr #7 ++ usat r5, #8, r5, asr #7 ++ usat r9, #8, r9, asr #7 ++ ++ strb r12,[r0], #1 @ store res[0] ++ strb r1, [r0], #1 @ store res[1] ++ strb r5, [r0], #1 @ store res[2] ++ strb r9, [r0], #1 @ store res[3] ++ ++ bne 1b ++ ++ ldr r12,[sp, #44] @ height = outer-loop counter ++ subs r12, r12, #1 ++T itttt ne ++ ldrne r4, [sp, #40] @ 4-in-parallel loop counter ++ ldrne r6, [sp, #0] ++ subne r2, r2, r4, lsl #2 ++ strne r12,[sp, #44] ++ add r0, r0, r6 ++ add r2, r2, r3 @ move to next input/output lines ++ ++ bne 1b ++ ++ add sp, sp, #4 @ restore stack after push{r1} above ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void put_vp8_epel_h4(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int mx) ++function ff_put_vp8_epel_h4_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ subs r2, r2, #1 ++ movrel lr, fourtap_filters_1324 - 4 ++ ldr r4, [sp, #36] @ width ++ ldr r12,[sp, #44] @ vp8_filter index ++ add lr, lr, r12, lsl #2 ++ sub r3, r3, r4 @ src_stride - block_width ++ sub r1, r1, r4 @ dst_stride - block_width ++ ldr r5, [lr] ++ ldr r6, [lr, #4] ++ asr r4, #2 ++ ++ ldr lr, [sp, #40] @ height = outer-loop counter ++ str r4, [sp, #36] @ "4-in-parallel" inner loop counter ++1: ++ @ 3 loads, 5 uxtb16s and then mul/acc/add/shr ++ @ o0: i0/i1/i2/i3 -> i0/i2(ld1) + i1/i3(ld1) ++ @ o1: i1/i2/i3/i4 -> i1/i3(ld1) + i2/i4(ld2) ++ @ o2: i2/i3/i4/i5 -> i2/i4(ld2) + i3/i5(ld2) ++ @ o3: i3/i4/i5/i6 -> i3/i5(ld2) + i4/i6(ld3) ++ ldr r9, [r2, #3] @ load source data ++ ldr r8, [r2, #2] ++ ldr r7, [r2], #4 ++ ++ uxtb16 r9, r9, ror #8 @ src[6] | src[4] ++ uxtb16 r10, r8, ror #8 @ src[5] | src[3] ++ uxtb16 r8, r8 @ src[4] | src[2] ++ uxtb16 r11, r7, ror #8 @ src[3] | src[1] ++ uxtb16 r7, r7 @ src[2] | src[0] ++ ++ smuad r9, r9, r6 @ filter[3][1] -> r9 ++ smuad r12, r10, r6 @ filter[2][1] -> r12 ++ smuad r7, r7, r5 @ filter[0][0] -> r7 ++ smlad r9, r10, r5, r9 @ filter[3][0] -> r9 ++ smuad r10, r11, r5 @ filter[1][0] -> r10 ++ smlad r12, r8, r5, r12 @ filter[2][0] -> r12 ++ smlad r7, r11, r6, r7 @ filter[0][1] -> r7 ++ smlad r10, r8, r6, r10 @ filter[1][1] -> r10 ++ ++ subs r4, r4, #1 @ counter-- ++ ++ add r7, r7, #0x40 @ round_shift_and_clamp[0] ++ add r10, r10, #0x40 @ round_shift_and_clamp[1] ++ add r12, r12, #0x40 @ round_shift_and_clamp[2] ++ add r9, r9, #0x40 @ round_shift_and_clamp[3] ++ ++ usat r7, #8, r7, asr #7 ++ usat r10, #8, r10, asr #7 ++ usat r12, #8, r12, asr #7 ++ usat r9, #8, r9, asr #7 ++ ++ strb r7, [r0], #1 @ store res[0] ++ strb r10,[r0], #1 @ store res[1] ++ strb r12,[r0], #1 @ store res[2] ++ strb r9, [r0], #1 @ store res[3] ++ ++ bne 1b ++ ++ subs lr, lr, #1 ++T it ne ++ ldrne r4, [sp, #36] @ 4-in-parallel loop counter ++ add r2, r2, r3 @ move to next input/output lines ++ add r0, r0, r1 ++ ++ bne 1b ++ ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void put_vp8_epel_v4(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int my) ++function ff_put_vp8_epel_v4_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ movrel lr, fourtap_filters_1324 - 4 ++ ldr r12,[sp, #44] @ vp8_filter index ++ ldr r4, [sp, #36] @ width ++ add lr, lr, r12, lsl #2 ++ sub r1, r1, r4 @ dst_stride - block_width ++ asr r4, #2 ++ ldr r5, [lr] ++ ldr r6, [lr, #4] ++ ++ str r4, [sp, #36] @ "4-in-parallel" loop counter @40 ++ str r3, [sp, #44] @ src_stride @48 ++ push {r1} @ dst_stride - block_width @36 ++ @ height @44 ++1: ++ ldr lr, [r2, r3, lsl #1] @ load source pixels ++ ldr r12,[r2, r3] ++ ldr_dpren r7, r2, r3 ++ ldr r11,[r2], #4 ++ ++ @ byte -> word and "transpose" ++ uxtb16 r8, lr, ror #8 @ src[3 + stride*3] | src[1 + stride*3] ++ uxtb16 r9, r12, ror #8 @ src[3 + stride*2] | src[1 + stride*2] ++ uxtb16 r3, r7, ror #8 @ src[3 + stride*0] | src[1 + stride*0] ++ uxtb16 r1, r11, ror #8 @ src[3 + stride*1] | src[1 + stride*1] ++ uxtb16 lr, lr @ src[2 + stride*3] | src[0 + stride*3] ++ uxtb16 r12, r12 @ src[2 + stride*2] | src[0 + stride*2] ++ uxtb16 r7, r7 @ src[2 + stride*0] | src[0 + stride*0] ++ uxtb16 r11, r11 @ src[2 + stride*1] | src[0 + stride*1] ++ pkhbt r10, r1, r8, lsl #16 @ src[1 + stride*3] | src[1 + stride*1] ++ pkhtb r1, r8, r1, asr #16 @ src[3 + stride*3] | src[3 + stride*1] ++ pkhbt r8, r3, r9, lsl #16 @ src[1 + stride*2] | src[1 + stride*0] ++ pkhtb r3, r9, r3, asr #16 @ src[3 + stride*2] | src[3 + stride*0] ++ pkhbt r9, r11, lr, lsl #16 @ src[0 + stride*3] | src[0 + stride*1] ++ pkhtb r11, lr, r11, asr #16 @ src[2 + stride*3] | src[2 + stride*1] ++ pkhbt lr, r7, r12, lsl #16 @ src[0 + stride*2] | src[0 + stride*0] ++ pkhtb r7, r12, r7, asr #16 @ src[2 + stride*2] | src[2 + stride*0] ++ ++ smuad r9, r9, r6 @ filter[0][1] ++ smuad r10, r10, r6 @ filter[1][1] ++ smuad r11, r11, r6 @ filter[2][1] ++ smuad r1, r1, r6 @ filter[3][1] ++ smlad r9, lr, r5, r9 @ filter[0][0] ++ smlad r10, r8, r5, r10 @ filter[1][0] ++ smlad r11, r7, r5, r11 @ filter[2][0] ++ smlad r1, r3, r5, r1 @ filter[3][0] ++ ++ subs r4, r4, #1 @ counter-- ++ ldr r3, [sp, #48] @ FIXME prevent clobber of r3 above? ++ ++ add r9, r9, #0x40 @ round_shift_and_clamp[0] ++ add r10, r10, #0x40 @ round_shift_and_clamp[1] ++ add r11, r11, #0x40 @ round_shift_and_clamp[2] ++ add r1, r1, #0x40 @ round_shift_and_clamp[3] ++ ++ usat r9, #8, r9, asr #7 ++ usat r10, #8, r10, asr #7 ++ usat r11, #8, r11, asr #7 ++ usat r1, #8, r1, asr #7 ++ ++ strb r9, [r0], #1 @ store result ++ strb r10,[r0], #1 ++ strb r11,[r0], #1 ++ strb r1, [r0], #1 ++ ++ bne 1b ++ ++ ldr r12,[sp, #44] @ height = outer-loop counter ++ subs r12, r12, #1 ++T ittt ne ++ ldrne r4, [sp, #40] @ 4-in-parallel loop counter ++ ldrne r9, [sp, #0] ++ strne r12,[sp, #44] ++ sub r2, r2, r4, lsl #2 ++ add r0, r0, r9 ++ add r2, r2, r3 @ move to next input/output lines ++ ++ bne 1b ++ ++ add sp, sp, #4 @ restore stack after push{r1} above ++ pop {r4 - r11, pc} ++endfunc ++ ++@ void put_vp8_bilin_h(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int mx) ++function ff_put_vp8_bilin_h_armv6, export=1 ++ push {r4 - r9, lr} ++ ++ ldr r8, [sp, #36] @ vp8_filter index ++ ldr r12,[sp, #32] @ height = outer-loop counter ++ ldr r4, [sp, #28] @ width ++ lsl r5, r8, #16 @ mx << 16 ++ sub r3, r3, r4 @ src_stride - block_width ++ sub r1, r1, r4 @ dst_stride - block_width ++ asr r4, #2 ++ sub r5, r5, r8 @ (mx << 16) | (-mx) ++ str r4, [sp, #28] @ "4-in-parallel" loop counter ++ add r5, r5, #8 @ (8 - mx) | (mx << 16) = filter coefficients ++1: ++ ldrb r6, [r2], #1 @ load source data ++ ldrb r7, [r2], #1 ++ ldrb r8, [r2], #1 ++ ldrb r9, [r2], #1 ++ ldrb lr, [r2] ++ ++ pkhbt r6, r6, r7, lsl #16 @ src[1] | src[0] ++ pkhbt r7, r7, r8, lsl #16 @ src[2] | src[1] ++ pkhbt r8, r8, r9, lsl #16 @ src[3] | src[2] ++ pkhbt r9, r9, lr, lsl #16 @ src[4] | src[3] ++ ++ smuad r6, r6, r5 @ apply the filter ++ smuad r7, r7, r5 ++ smuad r8, r8, r5 ++ smuad r9, r9, r5 ++ ++ subs r4, r4, #1 @ counter-- ++ ++ add r6, r6, #0x4 @ round_shift_and_clamp ++ add r7, r7, #0x4 ++ add r8, r8, #0x4 ++ add r9, r9, #0x4 ++ ++ asr r6, #3 ++ asr r7, #3 ++ pkhbt r6, r6, r8, lsl #13 ++ pkhbt r7, r7, r9, lsl #13 ++ orr r6, r6, r7, lsl #8 ++ str r6, [r0], #4 @ store result ++ ++ bne 1b ++ ++ ldr r4, [sp, #28] @ 4-in-parallel loop counter ++ subs r12, r12, #1 ++ ++ add r2, r2, r3 @ move to next input/output lines ++ add r0, r0, r1 ++ ++ bne 1b ++ ++ pop {r4 - r9, pc} ++endfunc ++ ++@ void put_vp8_bilin_v(uint8_t *dst, int dststride, uint8_t *src, ++@ int srcstride, int w, int h, int my) ++function ff_put_vp8_bilin_v_armv6, export=1 ++ push {r4 - r11, lr} ++ ++ ldr r11,[sp, #44] @ vp8_filter index ++ ldr r4, [sp, #36] @ width ++ mov r5, r11, lsl #16 @ mx << 16 ++ ldr r12,[sp, #40] @ height = outer-loop counter ++ sub r1, r1, r4 ++ sub r5, r5, r11 @ (mx << 16) | (-mx) ++ asr r4, #2 ++ add r5, r5, #8 @ (8 - mx) | (mx << 16) = filter coefficients ++ str r4, [sp, #36] @ "4-in-parallel" loop counter ++1: ++ ldrb r10,[r2, r3] @ load the data ++ ldrb r6, [r2], #1 ++ ldrb r11,[r2, r3] ++ ldrb r7, [r2], #1 ++ ldrb lr, [r2, r3] ++ ldrb r8, [r2], #1 ++ ldrb r9, [r2, r3] ++ pkhbt r6, r6, r10, lsl #16 ++ ldrb r10,[r2], #1 ++ pkhbt r7, r7, r11, lsl #16 ++ pkhbt r8, r8, lr, lsl #16 ++ pkhbt r9, r10, r9, lsl #16 ++ ++ smuad r6, r6, r5 @ apply the filter ++ smuad r7, r7, r5 ++ smuad r8, r8, r5 ++ smuad r9, r9, r5 ++ ++ subs r4, r4, #1 @ counter-- ++ ++ add r6, r6, #0x4 @ round_shift_and_clamp ++ add r7, r7, #0x4 ++ add r8, r8, #0x4 ++ add r9, r9, #0x4 ++ ++ asr r6, #3 ++ asr r7, #3 ++ pkhbt r6, r6, r8, lsl #13 ++ pkhbt r7, r7, r9, lsl #13 ++ orr r6, r6, r7, lsl #8 ++ str r6, [r0], #4 @ store result ++ ++ bne 1b ++ ++ ldr r4, [sp, #36] @ 4-in-parallel loop counter ++ subs r12, r12, #1 ++ ++ add r2, r2, r3 @ move to next input/output lines ++ add r0, r0, r1 ++ sub r2, r2, r4, lsl #2 ++ ++ bne 1b ++ pop {r4 - r11, pc} ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_init_arm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_init_arm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_init_arm.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_init_arm.c 2012-05-14 14:08:53.476322713 +0200 +@@ -0,0 +1,309 @@ ++/** ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "libavcodec/vp8dsp.h" ++ ++void ff_vp8_luma_dc_wht_dc_armv6(DCTELEM block[4][4][16], DCTELEM dc[16]); ++ ++#define idct_funcs(opt) \ ++void ff_vp8_luma_dc_wht_ ## opt(DCTELEM block[4][4][16], DCTELEM dc[16]); \ ++void ff_vp8_idct_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \ ++void ff_vp8_idct_dc_add_ ## opt(uint8_t *dst, DCTELEM block[16], int stride); \ ++void ff_vp8_idct_dc_add4y_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride); \ ++void ff_vp8_idct_dc_add4uv_ ## opt(uint8_t *dst, DCTELEM block[4][16], int stride) ++ ++idct_funcs(neon); ++idct_funcs(armv6); ++ ++void ff_vp8_v_loop_filter16_neon(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++void ff_vp8_h_loop_filter16_neon(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++void ff_vp8_v_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++void ff_vp8_h_loop_filter8uv_neon(uint8_t *dstU, uint8_t *dstV, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++ ++void ff_vp8_v_loop_filter16_inner_neon(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++void ff_vp8_h_loop_filter16_inner_neon(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh); ++void ff_vp8_v_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV, ++ int stride, int flim_E, int flim_I, ++ int hev_thresh); ++void ff_vp8_h_loop_filter8uv_inner_neon(uint8_t *dstU, uint8_t *dstV, ++ int stride, int flim_E, int flim_I, ++ int hev_thresh); ++ ++void ff_vp8_v_loop_filter_inner_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, ++ int hev_thresh, int count); ++void ff_vp8_h_loop_filter_inner_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, ++ int hev_thresh, int count); ++void ff_vp8_v_loop_filter_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, ++ int hev_thresh, int count); ++void ff_vp8_h_loop_filter_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, ++ int hev_thresh, int count); ++ ++static void ff_vp8_v_loop_filter16_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_v_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4); ++} ++ ++static void ff_vp8_h_loop_filter16_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_h_loop_filter_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4); ++} ++ ++static void ff_vp8_v_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_v_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2); ++ ff_vp8_v_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2); ++} ++ ++static void ff_vp8_h_loop_filter8uv_armv6(uint8_t *dstU, uint8_t *dstV, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_h_loop_filter_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2); ++ ff_vp8_h_loop_filter_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2); ++} ++ ++static void ff_vp8_v_loop_filter16_inner_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_v_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4); ++} ++ ++static void ff_vp8_h_loop_filter16_inner_armv6(uint8_t *dst, int stride, ++ int flim_E, int flim_I, int hev_thresh) ++{ ++ ff_vp8_h_loop_filter_inner_armv6(dst, stride, flim_E, flim_I, hev_thresh, 4); ++} ++ ++static void ff_vp8_v_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV, ++ int stride, int flim_E, int flim_I, ++ int hev_thresh) ++{ ++ ff_vp8_v_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2); ++ ff_vp8_v_loop_filter_inner_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2); ++} ++ ++static void ff_vp8_h_loop_filter8uv_inner_armv6(uint8_t *dstU, uint8_t *dstV, ++ int stride, int flim_E, int flim_I, ++ int hev_thresh) ++{ ++ ff_vp8_h_loop_filter_inner_armv6(dstU, stride, flim_E, flim_I, hev_thresh, 2); ++ ff_vp8_h_loop_filter_inner_armv6(dstV, stride, flim_E, flim_I, hev_thresh, 2); ++} ++ ++#define simple_lf_funcs(opt) \ ++void ff_vp8_v_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim); \ ++void ff_vp8_h_loop_filter16_simple_ ## opt(uint8_t *dst, int stride, int flim) ++ ++simple_lf_funcs(neon); ++simple_lf_funcs(armv6); ++ ++#define VP8_MC_OPT(n, opt) \ ++ void ff_put_vp8_##n##_##opt(uint8_t *dst, int dststride, \ ++ uint8_t *src, int srcstride, \ ++ int h, int x, int y) ++ ++#define VP8_MC(n) \ ++ VP8_MC_OPT(n, neon) ++ ++#define VP8_EPEL(w) \ ++ VP8_MC(epel ## w ## _h4); \ ++ VP8_MC(epel ## w ## _h6); \ ++ VP8_MC(epel ## w ## _h4v4); \ ++ VP8_MC(epel ## w ## _h6v4); \ ++ VP8_MC(epel ## w ## _v4); \ ++ VP8_MC(epel ## w ## _v6); \ ++ VP8_MC(epel ## w ## _h4v6); \ ++ VP8_MC(epel ## w ## _h6v6) ++ ++VP8_EPEL(16); ++VP8_MC(pixels16); ++VP8_MC_OPT(pixels16, armv6); ++VP8_EPEL(8); ++VP8_MC(pixels8); ++VP8_MC_OPT(pixels8, armv6); ++VP8_EPEL(4); ++VP8_MC_OPT(pixels4, armv6); ++ ++VP8_MC(bilin16_h); ++VP8_MC(bilin16_v); ++VP8_MC(bilin16_hv); ++VP8_MC(bilin8_h); ++VP8_MC(bilin8_v); ++VP8_MC(bilin8_hv); ++VP8_MC(bilin4_h); ++VP8_MC(bilin4_v); ++VP8_MC(bilin4_hv); ++ ++#define VP8_V6_MC(n) \ ++void ff_put_vp8_##n##_armv6(uint8_t *dst, int dststride, uint8_t *src, \ ++ int srcstride, int w, int h, int mxy) ++ ++VP8_V6_MC(epel_v6); ++VP8_V6_MC(epel_h6); ++VP8_V6_MC(epel_v4); ++VP8_V6_MC(epel_h4); ++VP8_V6_MC(bilin_v); ++VP8_V6_MC(bilin_h); ++ ++#define VP8_EPEL_HV(SIZE, TAPNUMX, TAPNUMY, NAME, HNAME, VNAME, MAXHEIGHT) \ ++static void ff_put_vp8_##NAME##SIZE##_##HNAME##VNAME##_armv6( \ ++ uint8_t *dst, int dststride, uint8_t *src, \ ++ int srcstride, int h, int mx, int my) \ ++{ \ ++ DECLARE_ALIGNED(4, uint8_t, tmp)[SIZE * (MAXHEIGHT + TAPNUMY - 1)]; \ ++ uint8_t *tmpptr = tmp + SIZE * (TAPNUMY / 2 - 1); \ ++ src -= srcstride * (TAPNUMY / 2 - 1); \ ++ ff_put_vp8_ ## NAME ## _ ## HNAME ## _armv6(tmp, SIZE, src, srcstride, \ ++ SIZE, h + TAPNUMY - 1, mx); \ ++ ff_put_vp8_ ## NAME ## _ ## VNAME ## _armv6(dst, dststride, tmpptr, SIZE, \ ++ SIZE, h, my); \ ++} ++ ++VP8_EPEL_HV(16, 6, 6, epel, h6, v6, 16); ++VP8_EPEL_HV(16, 2, 2, bilin, h, v, 16); ++VP8_EPEL_HV(8, 6, 6, epel, h6, v6, 16); ++VP8_EPEL_HV(8, 4, 6, epel, h4, v6, 16); ++VP8_EPEL_HV(8, 6, 4, epel, h6, v4, 16); ++VP8_EPEL_HV(8, 4, 4, epel, h4, v4, 16); ++VP8_EPEL_HV(8, 2, 2, bilin, h, v, 16); ++VP8_EPEL_HV(4, 6, 6, epel, h6, v6, 8); ++VP8_EPEL_HV(4, 4, 6, epel, h4, v6, 8); ++VP8_EPEL_HV(4, 6, 4, epel, h6, v4, 8); ++VP8_EPEL_HV(4, 4, 4, epel, h4, v4, 8); ++VP8_EPEL_HV(4, 2, 2, bilin, h, v, 8); ++ ++extern void put_vp8_epel4_v6_c(uint8_t *dst, int d, uint8_t *src, int s, int h, int mx, int my); ++#undef printf ++#define VP8_EPEL_H_OR_V(SIZE, NAME, HV) \ ++static void ff_put_vp8_##NAME##SIZE##_##HV##_armv6( \ ++ uint8_t *dst, int dststride, uint8_t *src, \ ++ int srcstride, int h, int mx, int my) \ ++{ \ ++ ff_put_vp8_## NAME ## _ ## HV ## _armv6(dst, dststride, src, srcstride, \ ++ SIZE, h, mx | my); \ ++} ++ ++VP8_EPEL_H_OR_V(4, epel, h6); ++VP8_EPEL_H_OR_V(4, epel, h4); ++VP8_EPEL_H_OR_V(4, epel, v6); ++VP8_EPEL_H_OR_V(4, epel, v4); ++VP8_EPEL_H_OR_V(4, bilin, v); ++VP8_EPEL_H_OR_V(4, bilin, h); ++VP8_EPEL_H_OR_V(8, epel, h6); ++VP8_EPEL_H_OR_V(8, epel, h4); ++VP8_EPEL_H_OR_V(8, epel, v6); ++VP8_EPEL_H_OR_V(8, epel, v4); ++VP8_EPEL_H_OR_V(8, bilin, v); ++VP8_EPEL_H_OR_V(8, bilin, h); ++VP8_EPEL_H_OR_V(16, epel, h6); ++VP8_EPEL_H_OR_V(16, epel, v6); ++VP8_EPEL_H_OR_V(16, bilin, v); ++VP8_EPEL_H_OR_V(16, bilin, h); ++ ++av_cold void ff_vp8dsp_init_arm(VP8DSPContext *dsp) ++{ ++#define set_func_ptrs(opt) \ ++ dsp->vp8_luma_dc_wht = ff_vp8_luma_dc_wht_##opt; \ ++ dsp->vp8_luma_dc_wht_dc = ff_vp8_luma_dc_wht_dc_armv6; \ ++ \ ++ dsp->vp8_idct_add = ff_vp8_idct_add_##opt; \ ++ dsp->vp8_idct_dc_add = ff_vp8_idct_dc_add_##opt; \ ++ dsp->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_##opt; \ ++ dsp->vp8_idct_dc_add4uv = ff_vp8_idct_dc_add4uv_##opt; \ ++ \ ++ dsp->vp8_v_loop_filter16y = ff_vp8_v_loop_filter16_##opt; \ ++ dsp->vp8_h_loop_filter16y = ff_vp8_h_loop_filter16_##opt; \ ++ dsp->vp8_v_loop_filter8uv = ff_vp8_v_loop_filter8uv_##opt; \ ++ dsp->vp8_h_loop_filter8uv = ff_vp8_h_loop_filter8uv_##opt; \ ++ \ ++ dsp->vp8_v_loop_filter16y_inner = ff_vp8_v_loop_filter16_inner_##opt; \ ++ dsp->vp8_h_loop_filter16y_inner = ff_vp8_h_loop_filter16_inner_##opt; \ ++ dsp->vp8_v_loop_filter8uv_inner = ff_vp8_v_loop_filter8uv_inner_##opt; \ ++ dsp->vp8_h_loop_filter8uv_inner = ff_vp8_h_loop_filter8uv_inner_##opt; \ ++ \ ++ dsp->vp8_v_loop_filter_simple = ff_vp8_v_loop_filter16_simple_##opt; \ ++ dsp->vp8_h_loop_filter_simple = ff_vp8_h_loop_filter16_simple_##opt; \ ++ \ ++ dsp->put_vp8_epel_pixels_tab[0][0][0] = ff_put_vp8_pixels16_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[0][0][2] = ff_put_vp8_epel16_h6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[0][2][0] = ff_put_vp8_epel16_v6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[0][2][2] = ff_put_vp8_epel16_h6v6_##opt; \ ++ \ ++ dsp->put_vp8_epel_pixels_tab[1][0][0] = ff_put_vp8_pixels8_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][0][1] = ff_put_vp8_epel8_h4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][0][2] = ff_put_vp8_epel8_h6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][1][0] = ff_put_vp8_epel8_v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][1][1] = ff_put_vp8_epel8_h4v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][1][2] = ff_put_vp8_epel8_h6v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][2][0] = ff_put_vp8_epel8_v6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][2][1] = ff_put_vp8_epel8_h4v6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[1][2][2] = ff_put_vp8_epel8_h6v6_##opt; \ ++ \ ++ dsp->put_vp8_epel_pixels_tab[2][0][0] = ff_put_vp8_pixels4_armv6; \ ++ dsp->put_vp8_epel_pixels_tab[2][0][1] = ff_put_vp8_epel4_h4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][0][2] = ff_put_vp8_epel4_h6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][1][0] = ff_put_vp8_epel4_v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][1][1] = ff_put_vp8_epel4_h4v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][1][2] = ff_put_vp8_epel4_h6v4_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][2][0] = ff_put_vp8_epel4_v6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][2][1] = ff_put_vp8_epel4_h4v6_##opt; \ ++ dsp->put_vp8_epel_pixels_tab[2][2][2] = ff_put_vp8_epel4_h6v6_##opt; \ ++ \ ++ dsp->put_vp8_bilinear_pixels_tab[0][0][0] = ff_put_vp8_pixels16_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[0][0][2] = ff_put_vp8_bilin16_h_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[0][2][0] = ff_put_vp8_bilin16_v_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[0][2][2] = ff_put_vp8_bilin16_hv_##opt; \ ++ \ ++ dsp->put_vp8_bilinear_pixels_tab[1][0][0] = ff_put_vp8_pixels8_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][0][1] = ff_put_vp8_bilin8_h_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][0][2] = ff_put_vp8_bilin8_h_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][1][0] = ff_put_vp8_bilin8_v_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][1][1] = ff_put_vp8_bilin8_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][1][2] = ff_put_vp8_bilin8_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][2][0] = ff_put_vp8_bilin8_v_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][2][1] = ff_put_vp8_bilin8_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[1][2][2] = ff_put_vp8_bilin8_hv_##opt; \ ++ \ ++ dsp->put_vp8_bilinear_pixels_tab[2][0][0] = ff_put_vp8_pixels4_armv6; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][0][1] = ff_put_vp8_bilin4_h_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][0][2] = ff_put_vp8_bilin4_h_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][1][0] = ff_put_vp8_bilin4_v_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][1][1] = ff_put_vp8_bilin4_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][1][2] = ff_put_vp8_bilin4_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][2][0] = ff_put_vp8_bilin4_v_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][2][1] = ff_put_vp8_bilin4_hv_##opt; \ ++ dsp->put_vp8_bilinear_pixels_tab[2][2][2] = ff_put_vp8_bilin4_hv_##opt ++ if (HAVE_NEON) { ++ set_func_ptrs(neon); ++ } else if (HAVE_ARMV6) { ++ set_func_ptrs(armv6); ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_neon.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_neon.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8dsp_neon.S 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8dsp_neon.S 2012-05-14 14:08:53.481322815 +0200 +@@ -0,0 +1,1867 @@ ++/** ++ * VP8 NEON optimisations ++ * ++ * Copyright (c) 2010 Rob Clark ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "asm.S" ++#include "neon.S" ++ ++function ff_vp8_luma_dc_wht_neon, export=1 ++ vld1.16 {q0-q1}, [r1,:128] ++ vmov.i16 q15, #0 ++ ++ vadd.i16 d4, d0, d3 ++ vadd.i16 d6, d1, d2 ++ vst1.16 {q15}, [r1,:128]! ++ vsub.i16 d7, d1, d2 ++ vsub.i16 d5, d0, d3 ++ vst1.16 {q15}, [r1,:128] ++ vadd.i16 q0, q2, q3 ++ vsub.i16 q1, q2, q3 ++ ++ vmov.i16 q8, #3 ++ ++ vtrn.32 d0, d2 ++ vtrn.32 d1, d3 ++ vtrn.16 d0, d1 ++ vtrn.16 d2, d3 ++ ++ vadd.i16 d0, d0, d16 ++ ++ vadd.i16 d4, d0, d3 ++ vadd.i16 d6, d1, d2 ++ vsub.i16 d7, d1, d2 ++ vsub.i16 d5, d0, d3 ++ vadd.i16 q0, q2, q3 ++ vsub.i16 q1, q2, q3 ++ ++ vshr.s16 q0, q0, #3 ++ vshr.s16 q1, q1, #3 ++ ++ mov r3, #32 ++ vst1.16 {d0[0]}, [r0,:16], r3 ++ vst1.16 {d1[0]}, [r0,:16], r3 ++ vst1.16 {d2[0]}, [r0,:16], r3 ++ vst1.16 {d3[0]}, [r0,:16], r3 ++ vst1.16 {d0[1]}, [r0,:16], r3 ++ vst1.16 {d1[1]}, [r0,:16], r3 ++ vst1.16 {d2[1]}, [r0,:16], r3 ++ vst1.16 {d3[1]}, [r0,:16], r3 ++ vst1.16 {d0[2]}, [r0,:16], r3 ++ vst1.16 {d1[2]}, [r0,:16], r3 ++ vst1.16 {d2[2]}, [r0,:16], r3 ++ vst1.16 {d3[2]}, [r0,:16], r3 ++ vst1.16 {d0[3]}, [r0,:16], r3 ++ vst1.16 {d1[3]}, [r0,:16], r3 ++ vst1.16 {d2[3]}, [r0,:16], r3 ++ vst1.16 {d3[3]}, [r0,:16], r3 ++ ++ bx lr ++endfunc ++ ++function ff_vp8_idct_add_neon, export=1 ++ vld1.16 {q0-q1}, [r1,:128] ++ movw r3, #20091 ++ movt r3, #35468/2 ++ vdup.32 d4, r3 ++ ++ vmull.s16 q12, d1, d4[0] ++ vmull.s16 q13, d3, d4[0] ++ vqdmulh.s16 d20, d1, d4[1] ++ vqdmulh.s16 d23, d3, d4[1] ++ vshrn.s32 d21, q12, #16 ++ vshrn.s32 d22, q13, #16 ++ vadd.s16 d21, d21, d1 ++ vadd.s16 d22, d22, d3 ++ ++ vadd.s16 d16, d0, d2 ++ vsub.s16 d17, d0, d2 ++ vadd.s16 d18, d21, d23 ++ vsub.s16 d19, d20, d22 ++ vadd.s16 q0, q8, q9 ++ vsub.s16 q1, q8, q9 ++ ++ vtrn.32 d0, d3 ++ vtrn.32 d1, d2 ++ vtrn.16 d0, d1 ++ vtrn.16 d3, d2 ++ ++ vmov.i16 q15, #0 ++ vmull.s16 q12, d1, d4[0] ++ vst1.16 {q15}, [r1,:128]! ++ vmull.s16 q13, d2, d4[0] ++ vst1.16 {q15}, [r1,:128] ++ vqdmulh.s16 d21, d1, d4[1] ++ vqdmulh.s16 d23, d2, d4[1] ++ vshrn.s32 d20, q12, #16 ++ vshrn.s32 d22, q13, #16 ++ vadd.i16 d20, d20, d1 ++ vadd.i16 d22, d22, d2 ++ ++ vadd.i16 d16, d0, d3 ++ vsub.i16 d17, d0, d3 ++ vadd.i16 d18, d20, d23 ++ vld1.32 {d20[]}, [r0,:32], r2 ++ vsub.i16 d19, d21, d22 ++ vld1.32 {d22[]}, [r0,:32], r2 ++ vadd.s16 q0, q8, q9 ++ vld1.32 {d23[]}, [r0,:32], r2 ++ vsub.s16 q1, q8, q9 ++ vld1.32 {d21[]}, [r0,:32], r2 ++ vrshr.s16 q0, q0, #3 ++ vtrn.32 q10, q11 ++ vrshr.s16 q1, q1, #3 ++ ++ sub r0, r0, r2, lsl #2 ++ ++ vtrn.32 d0, d3 ++ vtrn.32 d1, d2 ++ vtrn.16 d0, d1 ++ vtrn.16 d3, d2 ++ ++ vaddw.u8 q0, q0, d20 ++ vaddw.u8 q1, q1, d21 ++ vqmovun.s16 d0, q0 ++ vqmovun.s16 d1, q1 ++ ++ vst1.32 {d0[0]}, [r0,:32], r2 ++ vst1.32 {d0[1]}, [r0,:32], r2 ++ vst1.32 {d1[1]}, [r0,:32], r2 ++ vst1.32 {d1[0]}, [r0,:32], r2 ++ ++ bx lr ++endfunc ++ ++function ff_vp8_idct_dc_add_neon, export=1 ++ mov r3, #0 ++ ldrsh r12, [r1] ++ strh r3, [r1] ++ vdup.16 q1, r12 ++ vrshr.s16 q1, q1, #3 ++ vld1.32 {d0[]}, [r0,:32], r2 ++ vld1.32 {d1[]}, [r0,:32], r2 ++ vld1.32 {d0[1]}, [r0,:32], r2 ++ vld1.32 {d1[1]}, [r0,:32], r2 ++ vaddw.u8 q2, q1, d0 ++ vaddw.u8 q3, q1, d1 ++ sub r0, r0, r2, lsl #2 ++ vqmovun.s16 d0, q2 ++ vqmovun.s16 d1, q3 ++ vst1.32 {d0[0]}, [r0,:32], r2 ++ vst1.32 {d1[0]}, [r0,:32], r2 ++ vst1.32 {d0[1]}, [r0,:32], r2 ++ vst1.32 {d1[1]}, [r0,:32], r2 ++ bx lr ++endfunc ++ ++function ff_vp8_idct_dc_add4uv_neon, export=1 ++ vmov.i16 d0, #0 ++ mov r3, #32 ++ vld1.16 {d16[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d17[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d18[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d19[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ mov r3, r0 ++ vrshr.s16 q8, q8, #3 @ dc >>= 3 ++ vld1.8 {d0}, [r0,:64], r2 ++ vrshr.s16 q9, q9, #3 ++ vld1.8 {d1}, [r0,:64], r2 ++ vaddw.u8 q10, q8, d0 ++ vld1.8 {d2}, [r0,:64], r2 ++ vaddw.u8 q0, q8, d1 ++ vld1.8 {d3}, [r0,:64], r2 ++ vaddw.u8 q11, q8, d2 ++ vld1.8 {d4}, [r0,:64], r2 ++ vaddw.u8 q1, q8, d3 ++ vld1.8 {d5}, [r0,:64], r2 ++ vaddw.u8 q12, q9, d4 ++ vld1.8 {d6}, [r0,:64], r2 ++ vaddw.u8 q2, q9, d5 ++ vld1.8 {d7}, [r0,:64], r2 ++ vaddw.u8 q13, q9, d6 ++ vqmovun.s16 d20, q10 ++ vaddw.u8 q3, q9, d7 ++ vqmovun.s16 d21, q0 ++ vqmovun.s16 d22, q11 ++ vst1.8 {d20}, [r3,:64], r2 ++ vqmovun.s16 d23, q1 ++ vst1.8 {d21}, [r3,:64], r2 ++ vqmovun.s16 d24, q12 ++ vst1.8 {d22}, [r3,:64], r2 ++ vqmovun.s16 d25, q2 ++ vst1.8 {d23}, [r3,:64], r2 ++ vqmovun.s16 d26, q13 ++ vst1.8 {d24}, [r3,:64], r2 ++ vqmovun.s16 d27, q3 ++ vst1.8 {d25}, [r3,:64], r2 ++ vst1.8 {d26}, [r3,:64], r2 ++ vst1.8 {d27}, [r3,:64], r2 ++ ++ bx lr ++endfunc ++ ++function ff_vp8_idct_dc_add4y_neon, export=1 ++ vmov.i16 d0, #0 ++ mov r3, #32 ++ vld1.16 {d16[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d17[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d18[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vld1.16 {d19[]}, [r1,:16] ++ vst1.16 {d0[0]}, [r1,:16], r3 ++ vrshr.s16 q8, q8, #3 @ dc >>= 3 ++ vld1.8 {q0}, [r0,:128], r2 ++ vrshr.s16 q9, q9, #3 ++ vld1.8 {q1}, [r0,:128], r2 ++ vaddw.u8 q10, q8, d0 ++ vld1.8 {q2}, [r0,:128], r2 ++ vaddw.u8 q0, q9, d1 ++ vld1.8 {q3}, [r0,:128], r2 ++ vaddw.u8 q11, q8, d2 ++ vaddw.u8 q1, q9, d3 ++ vaddw.u8 q12, q8, d4 ++ vaddw.u8 q2, q9, d5 ++ vaddw.u8 q13, q8, d6 ++ vaddw.u8 q3, q9, d7 ++ sub r0, r0, r2, lsl #2 ++ vqmovun.s16 d20, q10 ++ vqmovun.s16 d21, q0 ++ vqmovun.s16 d22, q11 ++ vqmovun.s16 d23, q1 ++ vqmovun.s16 d24, q12 ++ vst1.8 {q10}, [r0,:128], r2 ++ vqmovun.s16 d25, q2 ++ vst1.8 {q11}, [r0,:128], r2 ++ vqmovun.s16 d26, q13 ++ vst1.8 {q12}, [r0,:128], r2 ++ vqmovun.s16 d27, q3 ++ vst1.8 {q13}, [r0,:128], r2 ++ ++ bx lr ++endfunc ++ ++@ Register layout: ++@ P3..Q3 -> q0..q7 ++@ flim_E -> q14 ++@ flim_I -> q15 ++@ hev_thresh -> r12 ++@ ++.macro vp8_loop_filter, inner=0, simple=0 ++ .if \simple ++ vabd.u8 q9, q3, q4 @ abs(P0-Q0) ++ vabd.u8 q15, q2, q5 @ abs(P1-Q1) ++ vqadd.u8 q9, q9, q9 @ abs(P0-Q0) * 2 ++ vshr.u8 q10, q15, #1 @ abs(P1-Q1) / 2 ++ vqadd.u8 q11, q9, q10 @ (abs(P0-Q0)*2) + (abs(P1-Q1)/2) ++ vmov.i8 q13, #0x80 ++ vcle.u8 q8, q11, q14 @ (abs(P0-Q0)*2) + (abs(P1-Q1)/2) <= flim ++ .else ++ @ calculate hev and normal_limit: ++ vabd.u8 q12, q2, q3 @ abs(P1-P0) ++ vabd.u8 q13, q5, q4 @ abs(Q1-Q0) ++ vabd.u8 q10, q0, q1 @ abs(P3-P2) ++ vabd.u8 q11, q1, q2 @ abs(P2-P1) ++ vcle.u8 q8, q12, q15 @ abs(P1-P0) <= flim_I ++ vcle.u8 q9, q13, q15 @ abs(Q1-Q0) <= flim_I ++ vcle.u8 q10, q10, q15 @ abs(P3-P2) <= flim_I ++ vcle.u8 q11, q11, q15 @ abs(P2-P1) <= flim_I ++ vand q8, q8, q9 ++ vabd.u8 q9, q7, q6 @ abs(Q3-Q2) ++ vand q8, q8, q11 ++ vabd.u8 q11, q6, q5 @ abs(Q2-Q1) ++ vand q8, q8, q10 ++ vcle.u8 q10, q9, q15 @ abs(Q3-Q2) <= flim_I ++ vcle.u8 q11, q11, q15 @ abs(Q2-Q1) <= flim_I ++ vabd.u8 q9, q3, q4 @ abs(P0-Q0) ++ vabd.u8 q15, q2, q5 @ abs(P1-Q1) ++ vand q8, q8, q10 ++ vqadd.u8 q9, q9, q9 @ abs(P0-Q0) * 2 ++ vand q8, q8, q11 ++ vshr.u8 q10, q15, #1 @ abs(P1-Q1) / 2 ++ vdup.8 q15, r12 @ hev_thresh ++ vqadd.u8 q11, q9, q10 @ (abs(P0-Q0)*2) + (abs(P1-Q1)/2) ++ vcgt.u8 q12, q12, q15 @ abs(P1-P0) > hev_thresh ++ vcle.u8 q11, q11, q14 @ (abs(P0-Q0)*2) + (abs(P1-Q1)/2) <= flim_E ++ vcgt.u8 q14, q13, q15 @ abs(Q1-Q0) > hev_thresh ++ vand q8, q8, q11 ++ vmov.i8 q13, #0x80 ++ vorr q9, q12, q14 ++ .endif ++ ++ @ at this point: ++ @ q8: normal_limit ++ @ q9: hev ++ ++ @ convert to signed value: ++ veor q3, q3, q13 @ PS0 = P0 ^ 0x80 ++ veor q4, q4, q13 @ QS0 = Q0 ^ 0x80 ++ ++ vmov.i16 q12, #3 ++ vsubl.s8 q10, d8, d6 @ QS0 - PS0 ++ vsubl.s8 q11, d9, d7 @ (widened to 16bit) ++ veor q2, q2, q13 @ PS1 = P1 ^ 0x80 ++ veor q5, q5, q13 @ QS1 = Q1 ^ 0x80 ++ vmul.i16 q10, q10, q12 @ w = 3 * (QS0 - PS0) ++ vmul.i16 q11, q11, q12 ++ ++ vqsub.s8 q12, q2, q5 @ clamp(PS1-QS1) ++ vmov.i8 q14, #4 ++ vmov.i8 q15, #3 ++ .if \inner ++ vand q12, q12, q9 @ if(hev) w += clamp(PS1-QS1) ++ .endif ++ vaddw.s8 q10, q10, d24 @ w += clamp(PS1-QS1) ++ vaddw.s8 q11, q11, d25 ++ vqmovn.s16 d20, q10 @ narrow result back into q10 ++ vqmovn.s16 d21, q11 ++ .if !\inner && !\simple ++ veor q1, q1, q13 @ PS2 = P2 ^ 0x80 ++ veor q6, q6, q13 @ QS2 = Q2 ^ 0x80 ++ .endif ++ vand q10, q10, q8 @ w &= normal_limit ++ ++ @ registers used at this point.. ++ @ q0 -> P3 (don't corrupt) ++ @ q1-q6 -> PS2-QS2 ++ @ q7 -> Q3 (don't corrupt) ++ @ q9 -> hev ++ @ q10 -> w ++ @ q13 -> #0x80 ++ @ q14 -> #4 ++ @ q15 -> #3 ++ @ q8, q11, q12 -> unused ++ ++ @ filter_common: is4tap==1 ++ @ c1 = clamp(w + 4) >> 3; ++ @ c2 = clamp(w + 3) >> 3; ++ @ Q0 = s2u(QS0 - c1); ++ @ P0 = s2u(PS0 + c2); ++ ++ .if \simple ++ vqadd.s8 q11, q10, q14 @ c1 = clamp((w&hev)+4) ++ vqadd.s8 q12, q10, q15 @ c2 = clamp((w&hev)+3) ++ vshr.s8 q11, q11, #3 @ c1 >>= 3 ++ vshr.s8 q12, q12, #3 @ c2 >>= 3 ++ vqsub.s8 q4, q4, q11 @ QS0 = clamp(QS0-c1) ++ vqadd.s8 q3, q3, q12 @ PS0 = clamp(PS0+c2) ++ veor q4, q4, q13 @ Q0 = QS0 ^ 0x80 ++ veor q3, q3, q13 @ P0 = PS0 ^ 0x80 ++ veor q5, q5, q13 @ Q1 = QS1 ^ 0x80 ++ veor q2, q2, q13 @ P1 = PS1 ^ 0x80 ++ .elseif \inner ++ @ the !is4tap case of filter_common, only used for inner blocks ++ @ c3 = ((c1&~hev) + 1) >> 1; ++ @ Q1 = s2u(QS1 - c3); ++ @ P1 = s2u(PS1 + c3); ++ vqadd.s8 q11, q10, q14 @ c1 = clamp((w&hev)+4) ++ vqadd.s8 q12, q10, q15 @ c2 = clamp((w&hev)+3) ++ vshr.s8 q11, q11, #3 @ c1 >>= 3 ++ vshr.s8 q12, q12, #3 @ c2 >>= 3 ++ vqsub.s8 q4, q4, q11 @ QS0 = clamp(QS0-c1) ++ vqadd.s8 q3, q3, q12 @ PS0 = clamp(PS0+c2) ++ vbic q11, q11, q9 @ c1 & ~hev ++ veor q4, q4, q13 @ Q0 = QS0 ^ 0x80 ++ vrshr.s8 q11, q11, #1 @ c3 >>= 1 ++ veor q3, q3, q13 @ P0 = PS0 ^ 0x80 ++ vqsub.s8 q5, q5, q11 @ QS1 = clamp(QS1-c3) ++ vqadd.s8 q2, q2, q11 @ PS1 = clamp(PS1+c3) ++ veor q5, q5, q13 @ Q1 = QS1 ^ 0x80 ++ veor q2, q2, q13 @ P1 = PS1 ^ 0x80 ++ .else ++ vand q12, q10, q9 @ w & hev ++ vqadd.s8 q11, q12, q14 @ c1 = clamp((w&hev)+4) ++ vqadd.s8 q12, q12, q15 @ c2 = clamp((w&hev)+3) ++ vshr.s8 q11, q11, #3 @ c1 >>= 3 ++ vshr.s8 q12, q12, #3 @ c2 >>= 3 ++ vbic q10, q10, q9 @ w &= ~hev ++ vqsub.s8 q4, q4, q11 @ QS0 = clamp(QS0-c1) ++ vqadd.s8 q3, q3, q12 @ PS0 = clamp(PS0+c2) ++ ++ @ filter_mbedge: ++ @ a = clamp((27*w + 63) >> 7); ++ @ Q0 = s2u(QS0 - a); ++ @ P0 = s2u(PS0 + a); ++ @ a = clamp((18*w + 63) >> 7); ++ @ Q1 = s2u(QS1 - a); ++ @ P1 = s2u(PS1 + a); ++ @ a = clamp((9*w + 63) >> 7); ++ @ Q2 = s2u(QS2 - a); ++ @ P2 = s2u(PS2 + a); ++ vmov.i16 q9, #63 ++ vshll.s8 q14, d20, #3 ++ vshll.s8 q15, d21, #3 ++ vaddw.s8 q14, q14, d20 ++ vaddw.s8 q15, q15, d21 ++ vadd.s16 q8, q9, q14 ++ vadd.s16 q9, q9, q15 @ 9*w + 63 ++ vadd.s16 q11, q8, q14 ++ vadd.s16 q12, q9, q15 @ 18*w + 63 ++ vadd.s16 q14, q11, q14 ++ vadd.s16 q15, q12, q15 @ 27*w + 63 ++ vqshrn.s16 d16, q8, #7 ++ vqshrn.s16 d17, q9, #7 @ clamp(( 9*w + 63)>>7) ++ vqshrn.s16 d22, q11, #7 ++ vqshrn.s16 d23, q12, #7 @ clamp((18*w + 63)>>7) ++ vqshrn.s16 d28, q14, #7 ++ vqshrn.s16 d29, q15, #7 @ clamp((27*w + 63)>>7) ++ vqadd.s8 q1, q1, q8 @ PS2 = clamp(PS2+a) ++ vqsub.s8 q6, q6, q8 @ QS2 = clamp(QS2-a) ++ vqadd.s8 q2, q2, q11 @ PS1 = clamp(PS1+a) ++ vqsub.s8 q5, q5, q11 @ QS1 = clamp(QS1-a) ++ vqadd.s8 q3, q3, q14 @ PS0 = clamp(PS0+a) ++ vqsub.s8 q4, q4, q14 @ QS0 = clamp(QS0-a) ++ veor q3, q3, q13 @ P0 = PS0 ^ 0x80 ++ veor q4, q4, q13 @ Q0 = QS0 ^ 0x80 ++ veor q2, q2, q13 @ P1 = PS1 ^ 0x80 ++ veor q5, q5, q13 @ Q1 = QS1 ^ 0x80 ++ veor q1, q1, q13 @ P2 = PS2 ^ 0x80 ++ veor q6, q6, q13 @ Q2 = QS2 ^ 0x80 ++ .endif ++.endm ++ ++.macro vp8_v_loop_filter16 name, inner=0, simple=0 ++function ff_vp8_v_loop_filter16\name\()_neon, export=1 ++ vpush {q4-q7} ++ sub r0, r0, r1, lsl #1+!\simple ++ ++ @ Load pixels: ++ .if !\simple ++ ldr r12, [sp, #64] @ hev_thresh ++ vld1.8 {q0}, [r0,:128], r1 @ P3 ++ vld1.8 {q1}, [r0,:128], r1 @ P2 ++ .endif ++ vld1.8 {q2}, [r0,:128], r1 @ P1 ++ vld1.8 {q3}, [r0,:128], r1 @ P0 ++ vld1.8 {q4}, [r0,:128], r1 @ Q0 ++ vld1.8 {q5}, [r0,:128], r1 @ Q1 ++ .if !\simple ++ vld1.8 {q6}, [r0,:128], r1 @ Q2 ++ vld1.8 {q7}, [r0,:128] @ Q3 ++ vdup.8 q15, r3 @ flim_I ++ .endif ++ vdup.8 q14, r2 @ flim_E ++ ++ vp8_loop_filter inner=\inner, simple=\simple ++ ++ @ back up to P2: dst -= stride * 6 ++ sub r0, r0, r1, lsl #2 ++ .if !\simple ++ sub r0, r0, r1, lsl #1 ++ ++ @ Store pixels: ++ vst1.8 {q1}, [r0,:128], r1 @ P2 ++ .endif ++ vst1.8 {q2}, [r0,:128], r1 @ P1 ++ vst1.8 {q3}, [r0,:128], r1 @ P0 ++ vst1.8 {q4}, [r0,:128], r1 @ Q0 ++ vst1.8 {q5}, [r0,:128], r1 @ Q1 ++ .if !\simple ++ vst1.8 {q6}, [r0,:128] @ Q2 ++ .endif ++ ++ vpop {q4-q7} ++ bx lr ++endfunc ++.endm ++ ++vp8_v_loop_filter16 ++vp8_v_loop_filter16 _inner, inner=1 ++vp8_v_loop_filter16 _simple, simple=1 ++ ++.macro vp8_v_loop_filter8uv name, inner=0 ++function ff_vp8_v_loop_filter8uv\name\()_neon, export=1 ++ vpush {q4-q7} ++ sub r0, r0, r2, lsl #2 ++ sub r1, r1, r2, lsl #2 ++ ldr r12, [sp, #64] @ flim_I ++ ++ @ Load pixels: ++ vld1.8 {d0}, [r0,:64], r2 @ P3 ++ vld1.8 {d1}, [r1,:64], r2 @ P3 ++ vld1.8 {d2}, [r0,:64], r2 @ P2 ++ vld1.8 {d3}, [r1,:64], r2 @ P2 ++ vld1.8 {d4}, [r0,:64], r2 @ P1 ++ vld1.8 {d5}, [r1,:64], r2 @ P1 ++ vld1.8 {d6}, [r0,:64], r2 @ P0 ++ vld1.8 {d7}, [r1,:64], r2 @ P0 ++ vld1.8 {d8}, [r0,:64], r2 @ Q0 ++ vld1.8 {d9}, [r1,:64], r2 @ Q0 ++ vld1.8 {d10}, [r0,:64], r2 @ Q1 ++ vld1.8 {d11}, [r1,:64], r2 @ Q1 ++ vld1.8 {d12}, [r0,:64], r2 @ Q2 ++ vld1.8 {d13}, [r1,:64], r2 @ Q2 ++ vld1.8 {d14}, [r0,:64] @ Q3 ++ vld1.8 {d15}, [r1,:64] @ Q3 ++ ++ vdup.8 q14, r3 @ flim_E ++ vdup.8 q15, r12 @ flim_I ++ ldr r12, [sp, #68] @ hev_thresh ++ ++ vp8_loop_filter inner=\inner ++ ++ @ back up to P2: u,v -= stride * 6 ++ sub r0, r0, r2, lsl #2 ++ sub r1, r1, r2, lsl #2 ++ sub r0, r0, r2, lsl #1 ++ sub r1, r1, r2, lsl #1 ++ ++ @ Store pixels: ++ vst1.8 {d2}, [r0,:64], r2 @ P2 ++ vst1.8 {d3}, [r1,:64], r2 @ P2 ++ vst1.8 {d4}, [r0,:64], r2 @ P1 ++ vst1.8 {d5}, [r1,:64], r2 @ P1 ++ vst1.8 {d6}, [r0,:64], r2 @ P0 ++ vst1.8 {d7}, [r1,:64], r2 @ P0 ++ vst1.8 {d8}, [r0,:64], r2 @ Q0 ++ vst1.8 {d9}, [r1,:64], r2 @ Q0 ++ vst1.8 {d10}, [r0,:64], r2 @ Q1 ++ vst1.8 {d11}, [r1,:64], r2 @ Q1 ++ vst1.8 {d12}, [r0,:64] @ Q2 ++ vst1.8 {d13}, [r1,:64] @ Q2 ++ ++ vpop {q4-q7} ++ bx lr ++endfunc ++.endm ++ ++vp8_v_loop_filter8uv ++vp8_v_loop_filter8uv _inner, inner=1 ++ ++.macro vp8_h_loop_filter16 name, inner=0, simple=0 ++function ff_vp8_h_loop_filter16\name\()_neon, export=1 ++ vpush {q4-q7} ++ sub r0, r0, #4 ++ .if !\simple ++ ldr r12, [sp, #64] @ hev_thresh ++ .endif ++ ++ @ Load pixels: ++ vld1.8 {d0}, [r0], r1 @ load first 8-line src data ++ vld1.8 {d2}, [r0], r1 ++ vld1.8 {d4}, [r0], r1 ++ vld1.8 {d6}, [r0], r1 ++ vld1.8 {d8}, [r0], r1 ++ vld1.8 {d10}, [r0], r1 ++ vld1.8 {d12}, [r0], r1 ++ vld1.8 {d14}, [r0], r1 ++ vld1.8 {d1}, [r0], r1 @ load second 8-line src data ++ vld1.8 {d3}, [r0], r1 ++ vld1.8 {d5}, [r0], r1 ++ vld1.8 {d7}, [r0], r1 ++ vld1.8 {d9}, [r0], r1 ++ vld1.8 {d11}, [r0], r1 ++ vld1.8 {d13}, [r0], r1 ++ vld1.8 {d15}, [r0], r1 ++ ++ transpose_8x8 q0, q1, q2, q3, q4, q5, q6, q7 ++ ++ vdup.8 q14, r2 @ flim_E ++ .if !\simple ++ vdup.8 q15, r3 @ flim_I ++ .endif ++ ++ vp8_loop_filter inner=\inner, simple=\simple ++ ++ sub r0, r0, r1, lsl #4 @ backup 16 rows ++ ++ transpose_8x8 q0, q1, q2, q3, q4, q5, q6, q7 ++ ++ @ Store pixels: ++ vst1.8 {d0}, [r0], r1 ++ vst1.8 {d2}, [r0], r1 ++ vst1.8 {d4}, [r0], r1 ++ vst1.8 {d6}, [r0], r1 ++ vst1.8 {d8}, [r0], r1 ++ vst1.8 {d10}, [r0], r1 ++ vst1.8 {d12}, [r0], r1 ++ vst1.8 {d14}, [r0], r1 ++ vst1.8 {d1}, [r0], r1 ++ vst1.8 {d3}, [r0], r1 ++ vst1.8 {d5}, [r0], r1 ++ vst1.8 {d7}, [r0], r1 ++ vst1.8 {d9}, [r0], r1 ++ vst1.8 {d11}, [r0], r1 ++ vst1.8 {d13}, [r0], r1 ++ vst1.8 {d15}, [r0] ++ ++ vpop {q4-q7} ++ bx lr ++endfunc ++.endm ++ ++vp8_h_loop_filter16 ++vp8_h_loop_filter16 _inner, inner=1 ++vp8_h_loop_filter16 _simple, simple=1 ++ ++.macro vp8_h_loop_filter8uv name, inner=0 ++function ff_vp8_h_loop_filter8uv\name\()_neon, export=1 ++ vpush {q4-q7} ++ sub r0, r0, #4 ++ sub r1, r1, #4 ++ ldr r12, [sp, #64] @ flim_I ++ ++ @ Load pixels: ++ vld1.8 {d0}, [r0], r2 @ load u ++ vld1.8 {d1}, [r1], r2 @ load v ++ vld1.8 {d2}, [r0], r2 ++ vld1.8 {d3}, [r1], r2 ++ vld1.8 {d4}, [r0], r2 ++ vld1.8 {d5}, [r1], r2 ++ vld1.8 {d6}, [r0], r2 ++ vld1.8 {d7}, [r1], r2 ++ vld1.8 {d8}, [r0], r2 ++ vld1.8 {d9}, [r1], r2 ++ vld1.8 {d10}, [r0], r2 ++ vld1.8 {d11}, [r1], r2 ++ vld1.8 {d12}, [r0], r2 ++ vld1.8 {d13}, [r1], r2 ++ vld1.8 {d14}, [r0], r2 ++ vld1.8 {d15}, [r1], r2 ++ ++ transpose_8x8 q0, q1, q2, q3, q4, q5, q6, q7 ++ ++ vdup.8 q14, r3 @ flim_E ++ vdup.8 q15, r12 @ flim_I ++ ldr r12, [sp, #68] @ hev_thresh ++ ++ vp8_loop_filter inner=\inner ++ ++ sub r0, r0, r2, lsl #3 @ backup u 8 rows ++ sub r1, r1, r2, lsl #3 @ backup v 8 rows ++ ++ transpose_8x8 q0, q1, q2, q3, q4, q5, q6, q7 ++ ++ @ Store pixels: ++ vst1.8 {d0}, [r0], r2 ++ vst1.8 {d1}, [r1], r2 ++ vst1.8 {d2}, [r0], r2 ++ vst1.8 {d3}, [r1], r2 ++ vst1.8 {d4}, [r0], r2 ++ vst1.8 {d5}, [r1], r2 ++ vst1.8 {d6}, [r0], r2 ++ vst1.8 {d7}, [r1], r2 ++ vst1.8 {d8}, [r0], r2 ++ vst1.8 {d9}, [r1], r2 ++ vst1.8 {d10}, [r0], r2 ++ vst1.8 {d11}, [r1], r2 ++ vst1.8 {d12}, [r0], r2 ++ vst1.8 {d13}, [r1], r2 ++ vst1.8 {d14}, [r0] ++ vst1.8 {d15}, [r1] ++ ++ vpop {q4-q7} ++ bx lr ++endfunc ++.endm ++ ++vp8_h_loop_filter8uv ++vp8_h_loop_filter8uv _inner, inner=1 ++ ++function ff_put_vp8_pixels16_neon, export=1 ++ ldr r12, [sp, #0] @ h ++1: ++ subs r12, r12, #4 ++ vld1.8 {q0}, [r2], r3 ++ vld1.8 {q1}, [r2], r3 ++ vld1.8 {q2}, [r2], r3 ++ vld1.8 {q3}, [r2], r3 ++ vst1.8 {q0}, [r0,:128], r1 ++ vst1.8 {q1}, [r0,:128], r1 ++ vst1.8 {q2}, [r0,:128], r1 ++ vst1.8 {q3}, [r0,:128], r1 ++ bgt 1b ++ bx lr ++endfunc ++ ++function ff_put_vp8_pixels8_neon, export=1 ++ ldr r12, [sp, #0] @ h ++1: ++ subs r12, r12, #4 ++ vld1.8 {d0}, [r2], r3 ++ vld1.8 {d1}, [r2], r3 ++ vld1.8 {d2}, [r2], r3 ++ vld1.8 {d3}, [r2], r3 ++ vst1.8 {d0}, [r0,:64], r1 ++ vst1.8 {d1}, [r0,:64], r1 ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ bgt 1b ++ bx lr ++endfunc ++ ++/* 4/6-tap 8th-pel MC */ ++ ++.macro vp8_epel8_h6 d, a, b ++ vext.8 d27, \a, \b, #1 ++ vmovl.u8 q8, \a ++ vext.8 d28, \a, \b, #2 ++ vmovl.u8 q9, d27 ++ vext.8 d29, \a, \b, #3 ++ vmovl.u8 q10, d28 ++ vext.8 d30, \a, \b, #4 ++ vmovl.u8 q11, d29 ++ vext.8 d31, \a, \b, #5 ++ vmovl.u8 q12, d30 ++ vmul.u16 q10, q10, d0[2] ++ vmovl.u8 q13, d31 ++ vmul.u16 q11, q11, d0[3] ++ vmls.u16 q10, q9, d0[1] ++ vmls.u16 q11, q12, d1[0] ++ vmla.u16 q10, q8, d0[0] ++ vmla.u16 q11, q13, d1[1] ++ vqadd.s16 q11, q10, q11 ++ vqrshrun.s16 \d, q11, #7 ++.endm ++ ++.macro vp8_epel16_h6 d0, d1, s0, s1, s2, q0, q1 ++ vext.8 q14, \q0, \q1, #3 ++ vext.8 q15, \q0, \q1, #4 ++ vmovl.u8 q11, d28 ++ vmovl.u8 q14, d29 ++ vext.8 q3, \q0, \q1, #2 ++ vmovl.u8 q12, d30 ++ vmovl.u8 q15, d31 ++ vext.8 q8, \q0, \q1, #1 ++ vmovl.u8 q10, d6 ++ vmovl.u8 q3, d7 ++ vext.8 q2, \q0, \q1, #5 ++ vmovl.u8 q13, d4 ++ vmovl.u8 q2, d5 ++ vmovl.u8 q9, d16 ++ vmovl.u8 q8, d17 ++ vmul.u16 q11, q11, d0[3] ++ vmul.u16 q10, q10, d0[2] ++ vmul.u16 q3, q3, d0[2] ++ vmul.u16 q14, q14, d0[3] ++ vmls.u16 q11, q12, d1[0] ++ vmovl.u8 q12, \s0 ++ vmovl.u8 q1, \s1 ++ vmls.u16 q10, q9, d0[1] ++ vmls.u16 q3, q8, d0[1] ++ vmls.u16 q14, q15, d1[0] ++ vmla.u16 q10, q12, d0[0] ++ vmla.u16 q11, q13, d1[1] ++ vmla.u16 q3, q1, d0[0] ++ vmla.u16 q14, q2, d1[1] ++ vqadd.s16 q11, q10, q11 ++ vqadd.s16 q14, q3, q14 ++ vqrshrun.s16 \d0, q11, #7 ++ vqrshrun.s16 \d1, q14, #7 ++.endm ++ ++.macro vp8_epel8_v6 d0, s0, s1, s2, s3, s4, s5 ++ vmovl.u8 q10, \s2 ++ vmovl.u8 q11, \s3 ++ vmovl.u8 q9, \s1 ++ vmovl.u8 q12, \s4 ++ vmovl.u8 q8, \s0 ++ vmovl.u8 q13, \s5 ++ vmul.u16 q10, q10, d0[2] ++ vmul.u16 q11, q11, d0[3] ++ vmls.u16 q10, q9, d0[1] ++ vmls.u16 q11, q12, d1[0] ++ vmla.u16 q10, q8, d0[0] ++ vmla.u16 q11, q13, d1[1] ++ vqadd.s16 q11, q10, q11 ++ vqrshrun.s16 \d0, q11, #7 ++.endm ++ ++.macro vp8_epel8_v6_y2 d0, d1, s0, s1, s2, s3, s4, s5, s6 ++ vmovl.u8 q10, \s0 ++ vmovl.u8 q11, \s3 ++ vmovl.u8 q14, \s6 ++ vmovl.u8 q9, \s1 ++ vmovl.u8 q12, \s4 ++ vmovl.u8 q8, \s2 ++ vmovl.u8 q13, \s5 ++ vmul.u16 q10, q10, d0[0] ++ vmul.u16 q15, q11, d0[3] ++ vmul.u16 q11, q11, d0[2] ++ vmul.u16 q14, q14, d1[1] ++ vmls.u16 q10, q9, d0[1] ++ vmls.u16 q15, q12, d1[0] ++ vmls.u16 q11, q8, d0[1] ++ vmls.u16 q14, q13, d1[0] ++ vmla.u16 q10, q8, d0[2] ++ vmla.u16 q15, q13, d1[1] ++ vmla.u16 q11, q9, d0[0] ++ vmla.u16 q14, q12, d0[3] ++ vqadd.s16 q15, q10, q15 ++ vqadd.s16 q14, q11, q14 ++ vqrshrun.s16 \d0, q15, #7 ++ vqrshrun.s16 \d1, q14, #7 ++.endm ++ ++.macro vp8_epel8_h4 d, a, b ++ vext.8 d28, \a, \b, #1 ++ vmovl.u8 q9, \a ++ vext.8 d29, \a, \b, #2 ++ vmovl.u8 q10, d28 ++ vext.8 d30, \a, \b, #3 ++ vmovl.u8 q11, d29 ++ vmovl.u8 q12, d30 ++ vmul.u16 q10, q10, d0[2] ++ vmul.u16 q11, q11, d0[3] ++ vmls.u16 q10, q9, d0[1] ++ vmls.u16 q11, q12, d1[0] ++ vqadd.s16 q11, q10, q11 ++ vqrshrun.s16 \d, q11, #7 ++.endm ++ ++.macro vp8_epel8_v4_y2 d0, d1, s0, s1, s2, s3, s4 ++ vmovl.u8 q9, \s0 ++ vmovl.u8 q10, \s1 ++ vmovl.u8 q11, \s2 ++ vmovl.u8 q12, \s3 ++ vmovl.u8 q13, \s4 ++ vmul.u16 q8, q10, d0[2] ++ vmul.u16 q14, q11, d0[3] ++ vmul.u16 q11, q11, d0[2] ++ vmul.u16 q15, q12, d0[3] ++ vmls.u16 q8, q9, d0[1] ++ vmls.u16 q14, q12, d1[0] ++ vmls.u16 q11, q10, d0[1] ++ vmls.u16 q15, q13, d1[0] ++ vqadd.s16 q8, q8, q14 ++ vqadd.s16 q11, q11, q15 ++ vqrshrun.s16 \d0, q8, #7 ++ vqrshrun.s16 \d1, q11, #7 ++.endm ++ ++function ff_put_vp8_epel16_v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ push {r4,lr} ++ vpush {d8-d15} ++ ++ ldr r4, [sp, #80] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #72] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2-d3}, [r2], r3 ++ vld1.8 {d4-d5}, [r2], r3 ++ vld1.8 {d6-d7}, [r2], r3 ++ vld1.8 {d8-d9}, [r2], r3 ++ vld1.8 {d10-d11},[r2], r3 ++ vld1.8 {d12-d13},[r2], r3 ++ vld1.8 {d14-d15},[r2] ++ sub r2, r2, r3, lsl #2 ++ ++ vp8_epel8_v6_y2 d2, d4, d2, d4, d6, d8, d10, d12, d14 ++ vp8_epel8_v6_y2 d3, d5, d3, d5, d7, d9, d11, d13, d15 ++ ++ vst1.8 {d2-d3}, [r0,:128], r1 ++ vst1.8 {d4-d5}, [r0,:128], r1 ++ subs r12, r12, #2 ++ bne 1b ++ ++ vpop {d8-d15} ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel16_h6_neon, export=1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2-d4}, [r2], r3 ++ ++ vp8_epel16_h6 d2, d3, d2, d3, d4, q1, q2 ++ ++ vst1.8 {d2-d3}, [r0,:128], r1 ++ subs r12, r12, #1 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel16_h6v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ vpush {d8-d9} ++ ++ @ first pass (horizontal): ++ ldr r4, [sp, #28] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #24] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #336+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #5 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2,d3,d4}, [r2], r3 ++ ++ vp8_epel16_h6 d2, d3, d2, d3, d4, q1, q2 ++ ++ vst1.8 {d2-d3}, [lr,:128]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ @ second pass (vertical): ++ ldr r4, [sp, #336+16+32] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #336+16+24] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d5}, [lr,:128]! ++ vld1.8 {d6-d9}, [lr,:128]! ++ vld1.8 {d28-d31},[lr,:128] ++ sub lr, lr, #48 ++ ++ vp8_epel8_v6 d2, d2, d4, d6, d8, d28, d30 ++ vp8_epel8_v6 d3, d3, d5, d7, d9, d29, d31 ++ ++ vst1.8 {d2-d3}, [r0,:128], r1 ++ subs r12, r12, #1 ++ bne 2b ++ ++ add sp, sp, #336+16 ++ vpop {d8-d9} ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2}, [r2], r3 ++ vld1.8 {d3}, [r2], r3 ++ vld1.8 {d4}, [r2], r3 ++ vld1.8 {d5}, [r2], r3 ++ vld1.8 {d6}, [r2], r3 ++ vld1.8 {d7}, [r2], r3 ++ vld1.8 {d28}, [r2] ++ ++ sub r2, r2, r3, lsl #2 ++ ++ vp8_epel8_v6_y2 d2, d3, d2, d3, d4, d5, d6, d7, d28 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h6_neon, export=1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h6 d2, d2, d3 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ subs r12, r12, #1 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h6v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ @ first pass (horizontal): ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #168+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #5 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h6 d2, d2, d3 ++ ++ vst1.8 {d2}, [lr,:64]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ @ second pass (vertical): ++ ldr r4, [sp, #168+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #168+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d5}, [lr,:128]! ++ vld1.8 {d6-d7}, [lr,:128]! ++ vld1.8 {d30}, [lr,:64] ++ sub lr, lr, #32 ++ ++ vp8_epel8_v6_y2 d2, d3, d2, d3, d4, d5, d6, d7, d30 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 2b ++ ++ add sp, sp, #168+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_v4_neon, export=1 ++ sub r2, r2, r3 ++ push {r4,lr} ++ ++ ldr r4, [sp, #16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2}, [r2], r3 ++ vld1.8 {d3}, [r2], r3 ++ vld1.8 {d4}, [r2], r3 ++ vld1.8 {d5}, [r2], r3 ++ vld1.8 {d6}, [r2] ++ sub r2, r2, r3, lsl #1 ++ ++ vp8_epel8_v4_y2 d2, d3, d2, d3, d4, d5, d6 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h4_neon, export=1 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h4 d2, d2, d3 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ subs r12, r12, #1 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h4v4_neon, export=1 ++ sub r2, r2, r3 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ @ first pass (horizontal): ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #168+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #3 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h4 d2, d2, d3 ++ ++ vst1.8 {d2}, [lr,:64]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ @ second pass (vertical): ++ ldr r4, [sp, #168+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #168+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d5}, [lr,:128]! ++ vld1.8 {d6}, [lr,:64] ++ sub lr, lr, #16 ++ ++ vp8_epel8_v4_y2 d2, d3, d2, d3, d4, d5, d6 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 2b ++ ++ add sp, sp, #168+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h6v4_neon, export=1 ++ sub r2, r2, r3 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ @ first pass (horizontal): ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #168+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #3 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h6 d2, d2, d3 ++ ++ vst1.8 {d2}, [lr,:64]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ @ second pass (vertical): ++ ldr r4, [sp, #168+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #168+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d5}, [lr,:128]! ++ vld1.8 {d6}, [lr,:64] ++ sub lr, lr, #16 ++ ++ vp8_epel8_v4_y2 d2, d3, d2, d3, d4, d5, d6 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 2b ++ ++ add sp, sp, #168+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel8_h4v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ @ first pass (horizontal): ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #168+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #5 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2,d3}, [r2], r3 ++ ++ vp8_epel8_h4 d2, d2, d3 ++ ++ vst1.8 {d2}, [lr,:64]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ @ second pass (vertical): ++ ldr r4, [sp, #168+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #168+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d5}, [lr,:128]! ++ vld1.8 {d6-d7}, [lr,:128]! ++ vld1.8 {d30}, [lr,:64] ++ sub lr, lr, #32 ++ ++ vp8_epel8_v6_y2 d2, d3, d2, d3, d4, d5, d6, d7, d30 ++ ++ vst1.8 {d2}, [r0,:64], r1 ++ vst1.8 {d3}, [r0,:64], r1 ++ subs r12, r12, #2 ++ bne 2b ++ ++ add sp, sp, #168+16 ++ pop {r4,pc} ++endfunc ++ ++.ltorg ++ ++function ff_put_vp8_epel4_v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.32 {d2[]}, [r2], r3 ++ vld1.32 {d3[]}, [r2], r3 ++ vld1.32 {d4[]}, [r2], r3 ++ vld1.32 {d5[]}, [r2], r3 ++ vld1.32 {d6[]}, [r2], r3 ++ vld1.32 {d7[]}, [r2], r3 ++ vld1.32 {d28[]}, [r2] ++ sub r2, r2, r3, lsl #2 ++ vld1.32 {d2[1]}, [r2], r3 ++ vld1.32 {d3[1]}, [r2], r3 ++ vld1.32 {d4[1]}, [r2], r3 ++ vld1.32 {d5[1]}, [r2], r3 ++ vld1.32 {d6[1]}, [r2], r3 ++ vld1.32 {d7[1]}, [r2], r3 ++ vld1.32 {d28[1]}, [r2] ++ sub r2, r2, r3, lsl #2 ++ ++ vp8_epel8_v6_y2 d2, d3, d2, d3, d4, d5, d6, d7, d28 ++ ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h6_neon, export=1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {q1}, [r2], r3 ++ vp8_epel8_h6 d2, d2, d3 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ subs r12, r12, #1 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h6v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #52+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #5 ++ bic lr, lr, #15 ++1: ++ vld1.8 {q1}, [r2], r3 ++ vp8_epel8_h6 d2, d2, d3 ++ vst1.32 {d2[0]}, [lr,:32]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ ldr r4, [sp, #52+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #52+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d3}, [lr,:128]! ++ vld1.8 {d6}, [lr,:64]! ++ vld1.32 {d28[]}, [lr,:32] ++ sub lr, lr, #16 ++ vld1.8 {d4-d5}, [lr]! ++ vld1.8 {d7}, [lr,:64]! ++ vld1.32 {d28[1]}, [lr,:32] ++ sub lr, lr, #16 ++ vtrn.32 q1, q2 ++ vtrn.32 d6, d7 ++ vp8_epel8_v6_y2 d2, d3, d2, d4, d3, d5, d6, d7, d28 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 2b ++ ++ add sp, sp, #52+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h4v6_neon, export=1 ++ sub r2, r2, r3, lsl #1 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #52+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #5 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2}, [r2], r3 ++ vp8_epel8_h4 d2, d2, d2 ++ vst1.32 {d2[0]}, [lr,:32]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ ldr r4, [sp, #52+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #52+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d3}, [lr,:128]! ++ vld1.8 {d6}, [lr,:64]! ++ vld1.32 {d28[]}, [lr,:32] ++ sub lr, lr, #16 ++ vld1.8 {d4-d5}, [lr]! ++ vld1.8 {d7}, [lr,:64]! ++ vld1.32 {d28[1]}, [lr,:32] ++ sub lr, lr, #16 ++ vtrn.32 q1, q2 ++ vtrn.32 d6, d7 ++ vp8_epel8_v6_y2 d2, d3, d2, d4, d3, d5, d6, d7, d28 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 2b ++ ++ add sp, sp, #52+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h6v4_neon, export=1 ++ sub r2, r2, r3 ++ sub r2, r2, #2 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #44+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #3 ++ bic lr, lr, #15 ++1: ++ vld1.8 {q1}, [r2], r3 ++ vp8_epel8_h6 d2, d2, d3 ++ vst1.32 {d2[0]}, [lr,:32]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ ldr r4, [sp, #44+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #44+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d3}, [lr,:128]! ++ vld1.32 {d6[]}, [lr,:32] ++ sub lr, lr, #8 ++ vld1.8 {d4-d5}, [lr]! ++ vld1.32 {d6[1]}, [lr,:32] ++ sub lr, lr, #8 ++ vtrn.32 q1, q2 ++ vp8_epel8_v4_y2 d2, d3, d2, d4, d3, d5, d6 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 2b ++ ++ add sp, sp, #44+16 ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h4_neon, export=1 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.8 {d2}, [r2], r3 ++ vp8_epel8_h4 d2, d2, d2 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ subs r12, r12, #1 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_v4_neon, export=1 ++ sub r2, r2, r3 ++ push {r4,lr} ++ ++ ldr r4, [sp, #16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ vld1.16 {q0}, [r4,:128] ++1: ++ vld1.32 {d2[]}, [r2], r3 ++ vld1.32 {d3[]}, [r2], r3 ++ vld1.32 {d4[]}, [r2], r3 ++ vld1.32 {d5[]}, [r2], r3 ++ vld1.32 {d6[]}, [r2] ++ sub r2, r2, r3, lsl #1 ++ vld1.32 {d2[1]}, [r2], r3 ++ vld1.32 {d3[1]}, [r2], r3 ++ vld1.32 {d4[1]}, [r2], r3 ++ vld1.32 {d5[1]}, [r2], r3 ++ vld1.32 {d6[1]}, [r2] ++ sub r2, r2, r3, lsl #1 ++ ++ vp8_epel8_v4_y2 d2, d3, d2, d3, d4, d5, d6 ++ ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 1b ++ ++ pop {r4,pc} ++endfunc ++ ++function ff_put_vp8_epel4_h4v4_neon, export=1 ++ sub r2, r2, r3 ++ sub r2, r2, #1 ++ push {r4,lr} ++ ++ ldr r4, [sp, #12] @ mx ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #8] @ h ++ add r4, lr, r4, lsl #4 ++ sub sp, sp, #44+16 ++ vld1.16 {q0}, [r4,:128] ++ add lr, sp, #15 ++ add r12, r12, #3 ++ bic lr, lr, #15 ++1: ++ vld1.8 {d2}, [r2], r3 ++ vp8_epel8_h4 d2, d2, d3 ++ vst1.32 {d2[0]}, [lr,:32]! ++ subs r12, r12, #1 ++ bne 1b ++ ++ ldr r4, [sp, #44+16+16] @ my ++ movrel lr, subpel_filters-16 ++ ldr r12, [sp, #44+16+8] @ h ++ add r4, lr, r4, lsl #4 ++ add lr, sp, #15 ++ vld1.16 {q0}, [r4,:128] ++ bic lr, lr, #15 ++2: ++ vld1.8 {d2-d3}, [lr,:128]! ++ vld1.32 {d6[]}, [lr,:32] ++ sub lr, lr, #8 ++ vld1.8 {d4-d5}, [lr]! ++ vld1.32 {d6[1]}, [lr,:32] ++ sub lr, lr, #8 ++ vtrn.32 q1, q2 ++ vp8_epel8_v4_y2 d2, d3, d2, d4, d3, d5, d6 ++ vst1.32 {d2[0]}, [r0,:32], r1 ++ vst1.32 {d3[0]}, [r0,:32], r1 ++ vst1.32 {d2[1]}, [r0,:32], r1 ++ vst1.32 {d3[1]}, [r0,:32], r1 ++ subs r12, r12, #4 ++ bne 2b ++ ++ add sp, sp, #44+16 ++ pop {r4,pc} ++endfunc ++ ++@ note: worst case sum of all 6-tap filter values * 255 is 0x7f80 so 16 bit ++@ arithmatic can be used to apply filters ++const subpel_filters, align=4 ++ .short 0, 6, 123, 12, 1, 0, 0, 0 ++ .short 2, 11, 108, 36, 8, 1, 0, 0 ++ .short 0, 9, 93, 50, 6, 0, 0, 0 ++ .short 3, 16, 77, 77, 16, 3, 0, 0 ++ .short 0, 6, 50, 93, 9, 0, 0, 0 ++ .short 1, 8, 36, 108, 11, 2, 0, 0 ++ .short 0, 1, 12, 123, 6, 0, 0, 0 ++endconst ++ ++/* Bilinear MC */ ++ ++function ff_put_vp8_bilin16_h_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++1: ++ subs r12, r12, #2 ++ vld1.8 {d2-d4}, [r2], r1 ++ vext.8 q2, q1, q2, #1 ++ vmull.u8 q8, d2, d1 ++ vmlal.u8 q8, d4, d0 ++ vld1.8 {d18-d20},[r2], r1 ++ vmull.u8 q3, d3, d1 ++ vmlal.u8 q3, d5, d0 ++ vext.8 q10, q9, q10, #1 ++ vmull.u8 q11, d18, d1 ++ vmlal.u8 q11, d20, d0 ++ vmull.u8 q12, d19, d1 ++ vmlal.u8 q12, d21, d0 ++ vrshrn.u16 d4, q8, #3 ++ vrshrn.u16 d5, q3, #3 ++ vrshrn.u16 d6, q11, #3 ++ vrshrn.u16 d7, q12, #3 ++ vst1.8 {q2}, [r0,:128], r1 ++ vst1.8 {q3}, [r0,:128], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin16_v_neon, export=1 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++ vld1.8 {q1}, [r2], r1 ++1: ++ subs r12, r12, #2 ++ vld1.8 {q2}, [r2], r1 ++ vmull.u8 q3, d2, d1 ++ vmlal.u8 q3, d4, d0 ++ vmull.u8 q8, d3, d1 ++ vmlal.u8 q8, d5, d0 ++ vld1.8 {q1}, [r2], r1 ++ vmull.u8 q9, d4, d1 ++ vmlal.u8 q9, d2, d0 ++ vmull.u8 q10, d5, d1 ++ vmlal.u8 q10, d3, d0 ++ vrshrn.u16 d4, q3, #3 ++ vrshrn.u16 d5, q8, #3 ++ vrshrn.u16 d6, q9, #3 ++ vrshrn.u16 d7, q10, #3 ++ vst1.8 {q2}, [r0,:128], r1 ++ vst1.8 {q3}, [r0,:128], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin16_hv_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d2, r3 ++ vdup.8 d3, r12 ++ ldr r12, [sp] @ h ++ ++ vld1.8 {d4-d6}, [r2], r1 ++ vext.8 q3, q2, q3, #1 ++ vmull.u8 q8, d4, d1 ++ vmlal.u8 q8, d6, d0 ++ vmull.u8 q9, d5, d1 ++ vmlal.u8 q9, d7, d0 ++ vrshrn.u16 d4, q8, #3 ++ vrshrn.u16 d5, q9, #3 ++1: ++ subs r12, r12, #2 ++ vld1.8 {d18-d20},[r2], r1 ++ vext.8 q10, q9, q10, #1 ++ vmull.u8 q11, d18, d1 ++ vmlal.u8 q11, d20, d0 ++ vld1.8 {d26-d28},[r2], r1 ++ vmull.u8 q12, d19, d1 ++ vmlal.u8 q12, d21, d0 ++ vext.8 q14, q13, q14, #1 ++ vmull.u8 q8, d26, d1 ++ vmlal.u8 q8, d28, d0 ++ vmull.u8 q9, d27, d1 ++ vmlal.u8 q9, d29, d0 ++ vrshrn.u16 d6, q11, #3 ++ vrshrn.u16 d7, q12, #3 ++ vmull.u8 q12, d4, d3 ++ vmlal.u8 q12, d6, d2 ++ vmull.u8 q15, d5, d3 ++ vmlal.u8 q15, d7, d2 ++ vrshrn.u16 d4, q8, #3 ++ vrshrn.u16 d5, q9, #3 ++ vmull.u8 q10, d6, d3 ++ vmlal.u8 q10, d4, d2 ++ vmull.u8 q11, d7, d3 ++ vmlal.u8 q11, d5, d2 ++ vrshrn.u16 d24, q12, #3 ++ vrshrn.u16 d25, q15, #3 ++ vst1.8 {q12}, [r0,:128], r1 ++ vrshrn.u16 d20, q10, #3 ++ vrshrn.u16 d21, q11, #3 ++ vst1.8 {q10}, [r0,:128], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin8_h_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++1: ++ subs r12, r12, #2 ++ vld1.8 {q1}, [r2], r1 ++ vext.8 d3, d2, d3, #1 ++ vmull.u8 q2, d2, d1 ++ vmlal.u8 q2, d3, d0 ++ vld1.8 {q3}, [r2], r1 ++ vext.8 d7, d6, d7, #1 ++ vmull.u8 q8, d6, d1 ++ vmlal.u8 q8, d7, d0 ++ vrshrn.u16 d4, q2, #3 ++ vrshrn.u16 d16, q8, #3 ++ vst1.8 {d4}, [r0,:64], r1 ++ vst1.8 {d16}, [r0,:64], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin8_v_neon, export=1 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++ vld1.8 {d2}, [r2], r1 ++1: ++ subs r12, r12, #2 ++ vld1.8 {d3}, [r2], r1 ++ vmull.u8 q2, d2, d1 ++ vmlal.u8 q2, d3, d0 ++ vld1.8 {d2}, [r2], r1 ++ vmull.u8 q3, d3, d1 ++ vmlal.u8 q3, d2, d0 ++ vrshrn.u16 d4, q2, #3 ++ vrshrn.u16 d6, q3, #3 ++ vst1.8 {d4}, [r0,:64], r1 ++ vst1.8 {d6}, [r0,:64], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin8_hv_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d2, r3 ++ vdup.8 d3, r12 ++ ldr r12, [sp] @ h ++ ++ vld1.8 {q2}, [r2], r1 ++ vext.8 d5, d4, d5, #1 ++ vmull.u8 q9, d4, d1 ++ vmlal.u8 q9, d5, d0 ++ vrshrn.u16 d22, q9, #3 ++1: ++ subs r12, r12, #2 ++ vld1.8 {q3}, [r2], r1 ++ vext.8 d7, d6, d7, #1 ++ vmull.u8 q8, d6, d1 ++ vmlal.u8 q8, d7, d0 ++ vld1.8 {q2}, [r2], r1 ++ vext.8 d5, d4, d5, #1 ++ vmull.u8 q9, d4, d1 ++ vmlal.u8 q9, d5, d0 ++ vrshrn.u16 d16, q8, #3 ++ vmull.u8 q10, d22, d3 ++ vmlal.u8 q10, d16, d2 ++ vrshrn.u16 d22, q9, #3 ++ vmull.u8 q12, d16, d3 ++ vmlal.u8 q12, d22, d2 ++ vrshrn.u16 d20, q10, #3 ++ vst1.8 {d20}, [r0,:64], r1 ++ vrshrn.u16 d23, q12, #3 ++ vst1.8 {d23}, [r0,:64], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin4_h_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++1: ++ subs r12, r12, #2 ++ vld1.8 {d2}, [r2], r1 ++ vext.8 d3, d2, d3, #1 ++ vld1.8 {d6}, [r2], r1 ++ vext.8 d7, d6, d7, #1 ++ vtrn.32 q1, q3 ++ vmull.u8 q2, d2, d1 ++ vmlal.u8 q2, d3, d0 ++ vrshrn.u16 d4, q2, #3 ++ vst1.32 {d4[0]}, [r0,:32], r1 ++ vst1.32 {d4[1]}, [r0,:32], r1 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin4_v_neon, export=1 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r12, [sp] @ h ++ vld1.32 {d2[]}, [r2], r1 ++1: ++ vld1.32 {d3[]}, [r2] ++ vld1.32 {d2[1]}, [r2], r1 ++ vld1.32 {d3[1]}, [r2], r1 ++ vmull.u8 q2, d2, d1 ++ vmlal.u8 q2, d3, d0 ++ vtrn.32 d3, d2 ++ vrshrn.u16 d4, q2, #3 ++ vst1.32 {d4[0]}, [r0,:32], r1 ++ vst1.32 {d4[1]}, [r0,:32], r1 ++ subs r12, r12, #2 ++ bgt 1b ++ ++ bx lr ++endfunc ++ ++function ff_put_vp8_bilin4_hv_neon, export=1 ++ ldr r3, [sp, #4] @ mx ++ rsb r12, r3, #8 ++ vdup.8 d0, r3 ++ vdup.8 d1, r12 ++ ldr r3, [sp, #8] @ my ++ rsb r12, r3, #8 ++ vdup.8 d2, r3 ++ vdup.8 d3, r12 ++ ldr r12, [sp] @ h ++ ++ vld1.8 {d4}, [r2], r1 ++ vext.8 d5, d4, d4, #1 ++ vmull.u8 q9, d4, d1 ++ vmlal.u8 q9, d5, d0 ++ vrshrn.u16 d22, q9, #3 ++1: ++ subs r12, r12, #2 ++ vld1.8 {d6}, [r2], r1 ++ vext.8 d7, d6, d6, #1 ++ vld1.8 {d4}, [r2], r1 ++ vext.8 d5, d4, d4, #1 ++ vtrn.32 q3, q2 ++ vmull.u8 q8, d6, d1 ++ vmlal.u8 q8, d7, d0 ++ vrshrn.u16 d16, q8, #3 ++ vmull.u8 q10, d16, d2 ++ vtrn.32 d22, d16 ++ vmlal.u8 q10, d22, d3 ++ vrev64.32 d22, d16 ++ vrshrn.u16 d20, q10, #3 ++ vst1.32 {d20[0]}, [r0,:32], r1 ++ vst1.32 {d20[1]}, [r0,:32], r1 ++ bgt 1b ++ ++ bx lr ++endfunc +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/arm/vp8.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/arm/vp8.h 2012-05-14 14:08:53.463322451 +0200 +@@ -0,0 +1,29 @@ ++/** ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_ARM_VP8_H ++#define AVCODEC_ARM_VP8_H ++ ++#if HAVE_ARMV6 ++#define decode_block_coeffs_internal ff_decode_block_coeffs_armv6 ++int ff_decode_block_coeffs_armv6(VP56RangeCoder *rc, DCTELEM block[16], ++ uint8_t probs[8][3][NUM_DCT_TOKENS-1], ++ int i, uint8_t *token_prob, int16_t qmul[2]); ++#endif ++ ++#endif /* AVCODEC_ARM_VP8_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass.c 2012-05-14 14:08:53.485322895 +0200 +@@ -21,27 +21,13 @@ + + #include "avcodec.h" + #include "ass.h" ++#include "libavutil/avstring.h" + +-/** +- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. +- * +- * @param avctx pointer to the AVCodecContext +- * @param font name of the default font face to use +- * @param font_size default font size to use +- * @param color default text color to use (ABGR) +- * @param back_color default background color to use (ABGR) +- * @param bold 1 for bold text, 0 for normal text +- * @param italic 1 for italic text, 0 for normal text +- * @param underline 1 for underline text, 0 for normal text +- * @param alignment position of the text (left, center, top...), defined after +- * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top) +- * @return >= 0 on success otherwise an error code <0 +- */ +-static int ff_ass_subtitle_header(AVCodecContext *avctx, +- const char *font, int font_size, +- int color, int back_color, +- int bold, int italic, int underline, +- int alignment) ++int ff_ass_subtitle_header(AVCodecContext *avctx, ++ const char *font, int font_size, ++ int color, int back_color, ++ int bold, int italic, int underline, ++ int alignment) + { + char header[512]; + +@@ -77,11 +63,6 @@ + ASS_DEFAULT_ALIGNMENT); + } + +-void ff_ass_init(AVSubtitle *sub) +-{ +- memset(sub, 0, sizeof(*sub)); +-} +- + static int ts_to_string(char *str, int strlen, int ts) + { + int h, m, s; +@@ -117,8 +98,7 @@ + rects[sub->num_rects]->type = SUBTITLE_ASS; + rects[sub->num_rects]->ass = av_malloc(len + dlen + 1); + strcpy (rects[sub->num_rects]->ass , header); +- strncpy(rects[sub->num_rects]->ass + len, dialog, dlen); +- rects[sub->num_rects]->ass[len+dlen] = 0; ++ av_strlcpy(rects[sub->num_rects]->ass + len, dialog, dlen + 1); + sub->num_rects++; + return dlen; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/assdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/assdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/assdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/assdec.c 2012-05-14 14:08:53.489322975 +0200 +@@ -21,6 +21,7 @@ + + #include "avcodec.h" + #include "ass.h" ++#include "ass_split.h" + + static av_cold int ass_decode_init(AVCodecContext *avctx) + { +@@ -29,6 +30,7 @@ + return AVERROR(ENOMEM); + memcpy(avctx->subtitle_header, avctx->extradata, avctx->extradata_size); + avctx->subtitle_header_size = avctx->extradata_size; ++ avctx->priv_data = ff_ass_split(avctx->extradata); + return 0; + } + +@@ -38,10 +40,10 @@ + const char *ptr = avpkt->data; + int len, size = avpkt->size; + +- ff_ass_init(data); +- + while (size > 0) { +- len = ff_ass_add_rect(data, ptr, 0, 0/* FIXME: duration */, 1); ++ ASSDialog *dialog = ff_ass_split_dialog(avctx->priv_data, ptr, 0, NULL); ++ int duration = dialog->end - dialog->start; ++ len = ff_ass_add_rect(data, ptr, 0, duration, 1); + if (len < 0) + return len; + ptr += len; +@@ -52,6 +54,13 @@ + return avpkt->size; + } + ++static int ass_decode_close(AVCodecContext *avctx) ++{ ++ ff_ass_split_free(avctx->priv_data); ++ avctx->priv_data = NULL; ++ return 0; ++} ++ + AVCodec ff_ass_decoder = { + .name = "ass", + .long_name = NULL_IF_CONFIG_SMALL("Advanced SubStation Alpha subtitle"), +@@ -59,4 +68,5 @@ + .id = CODEC_ID_SSA, + .init = ass_decode_init, + .decode = ass_decode_frame, ++ .close = ass_decode_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass.h 2012-05-14 14:08:53.486322915 +0200 +@@ -25,8 +25,7 @@ + #include "avcodec.h" + + /** +- * Default values for ASS style. +- * @defgroup ass_default ++ * @name Default values for ASS style + * @{ + */ + #define ASS_DEFAULT_FONT "Arial" +@@ -40,20 +39,34 @@ + /** @} */ + + /** +- * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS +- * with default style. ++ * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS. + * + * @param avctx pointer to the AVCodecContext ++ * @param font name of the default font face to use ++ * @param font_size default font size to use ++ * @param color default text color to use (ABGR) ++ * @param back_color default background color to use (ABGR) ++ * @param bold 1 for bold text, 0 for normal text ++ * @param italic 1 for italic text, 0 for normal text ++ * @param underline 1 for underline text, 0 for normal text ++ * @param alignment position of the text (left, center, top...), defined after ++ * the layout of the numpad (1-3 sub, 4-6 mid, 7-9 top) + * @return >= 0 on success otherwise an error code <0 + */ +-int ff_ass_subtitle_header_default(AVCodecContext *avctx); ++int ff_ass_subtitle_header(AVCodecContext *avctx, ++ const char *font, int font_size, ++ int color, int back_color, ++ int bold, int italic, int underline, ++ int alignment); + + /** +- * Initialize an AVSubtitle structure for use with ff_ass_add_rect(). ++ * Generate a suitable AVCodecContext.subtitle_header for SUBTITLE_ASS ++ * with default style. + * +- * @param sub pointer to the AVSubtitle ++ * @param avctx pointer to the AVCodecContext ++ * @return >= 0 on success otherwise an error code <0 + */ +-void ff_ass_init(AVSubtitle *sub); ++int ff_ass_subtitle_header_default(AVCodecContext *avctx); + + /** + * Add an ASS dialog line to an AVSubtitle as a new AVSubtitleRect. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass_split.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass_split.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass_split.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass_split.c 2012-05-14 14:08:53.487322935 +0200 +@@ -0,0 +1,468 @@ ++/* ++ * SSA/ASS spliting functions ++ * Copyright (c) 2010 Aurelien Jacobs ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "ass_split.h" ++ ++typedef enum { ++ ASS_STR, ++ ASS_INT, ++ ASS_FLT, ++ ASS_COLOR, ++ ASS_TIMESTAMP, ++ ASS_ALGN, ++} ASSFieldType; ++ ++typedef struct { ++ const char *name; ++ int type; ++ int offset; ++} ASSFields; ++ ++typedef struct { ++ const char *section; ++ const char *format_header; ++ const char *fields_header; ++ int size; ++ int offset; ++ int offset_count; ++ ASSFields fields[10]; ++} ASSSection; ++ ++static const ASSSection ass_sections[] = { ++ { .section = "Script Info", ++ .offset = offsetof(ASS, script_info), ++ .fields = {{"ScriptType", ASS_STR, offsetof(ASSScriptInfo, script_type)}, ++ {"Collisions", ASS_STR, offsetof(ASSScriptInfo, collisions) }, ++ {"PlayResX", ASS_INT, offsetof(ASSScriptInfo, play_res_x) }, ++ {"PlayResY", ASS_INT, offsetof(ASSScriptInfo, play_res_y) }, ++ {"Timer", ASS_FLT, offsetof(ASSScriptInfo, timer) }, ++ {0}, ++ } ++ }, ++ { .section = "V4+ Styles", ++ .format_header = "Format", ++ .fields_header = "Style", ++ .size = sizeof(ASSStyle), ++ .offset = offsetof(ASS, styles), ++ .offset_count = offsetof(ASS, styles_count), ++ .fields = {{"Name", ASS_STR, offsetof(ASSStyle, name) }, ++ {"Fontname", ASS_STR, offsetof(ASSStyle, font_name) }, ++ {"Fontsize", ASS_INT, offsetof(ASSStyle, font_size) }, ++ {"PrimaryColour",ASS_COLOR,offsetof(ASSStyle, primary_color)}, ++ {"BackColour", ASS_COLOR,offsetof(ASSStyle, back_color) }, ++ {"Bold", ASS_INT, offsetof(ASSStyle, bold) }, ++ {"Italic", ASS_INT, offsetof(ASSStyle, italic) }, ++ {"Underline", ASS_INT, offsetof(ASSStyle, underline) }, ++ {"Alignment", ASS_INT, offsetof(ASSStyle, alignment) }, ++ {0}, ++ } ++ }, ++ { .section = "V4 Styles", ++ .format_header = "Format", ++ .fields_header = "Style", ++ .size = sizeof(ASSStyle), ++ .offset = offsetof(ASS, styles), ++ .offset_count = offsetof(ASS, styles_count), ++ .fields = {{"Name", ASS_STR, offsetof(ASSStyle, name) }, ++ {"Fontname", ASS_STR, offsetof(ASSStyle, font_name) }, ++ {"Fontsize", ASS_INT, offsetof(ASSStyle, font_size) }, ++ {"PrimaryColour",ASS_COLOR,offsetof(ASSStyle, primary_color)}, ++ {"BackColour", ASS_COLOR,offsetof(ASSStyle, back_color) }, ++ {"Bold", ASS_INT, offsetof(ASSStyle, bold) }, ++ {"Italic", ASS_INT, offsetof(ASSStyle, italic) }, ++ {"Alignment", ASS_ALGN, offsetof(ASSStyle, alignment) }, ++ {0}, ++ } ++ }, ++ { .section = "Events", ++ .format_header = "Format", ++ .fields_header = "Dialogue", ++ .size = sizeof(ASSDialog), ++ .offset = offsetof(ASS, dialogs), ++ .offset_count = offsetof(ASS, dialogs_count), ++ .fields = {{"Layer", ASS_INT, offsetof(ASSDialog, layer) }, ++ {"Start", ASS_TIMESTAMP, offsetof(ASSDialog, start) }, ++ {"End", ASS_TIMESTAMP, offsetof(ASSDialog, end) }, ++ {"Style", ASS_STR, offsetof(ASSDialog, style) }, ++ {"Text", ASS_STR, offsetof(ASSDialog, text) }, ++ {0}, ++ } ++ }, ++}; ++ ++ ++typedef int (*ASSConvertFunc)(void *dest, const char *buf, int len); ++ ++static int convert_str(void *dest, const char *buf, int len) ++{ ++ char *str = av_malloc(len + 1); ++ if (str) { ++ memcpy(str, buf, len); ++ str[len] = 0; ++ if (*(void **)dest) ++ av_free(*(void **)dest); ++ *(char **)dest = str; ++ } ++ return !str; ++} ++static int convert_int(void *dest, const char *buf, int len) ++{ ++ return sscanf(buf, "%d", (int *)dest) == 1; ++} ++static int convert_flt(void *dest, const char *buf, int len) ++{ ++ return sscanf(buf, "%f", (float *)dest) == 1; ++} ++static int convert_color(void *dest, const char *buf, int len) ++{ ++ return sscanf(buf, "&H%8x", (int *)dest) == 1 || ++ sscanf(buf, "%d", (int *)dest) == 1; ++} ++static int convert_timestamp(void *dest, const char *buf, int len) ++{ ++ int c, h, m, s, cs; ++ if ((c = sscanf(buf, "%d:%02d:%02d.%02d", &h, &m, &s, &cs)) == 4) ++ *(int *)dest = 360000*h + 6000*m + 100*s + cs; ++ return c == 4; ++} ++static int convert_alignment(void *dest, const char *buf, int len) ++{ ++ int a; ++ if (sscanf(buf, "%d", &a) == 1) { ++ /* convert V4 Style alignment to V4+ Style */ ++ *(int *)dest = a + ((a&4) >> 1) - 5*!!(a&8); ++ return 1; ++ } ++ return 0; ++} ++ ++static const ASSConvertFunc convert_func[] = { ++ [ASS_STR] = convert_str, ++ [ASS_INT] = convert_int, ++ [ASS_FLT] = convert_flt, ++ [ASS_COLOR] = convert_color, ++ [ASS_TIMESTAMP] = convert_timestamp, ++ [ASS_ALGN] = convert_alignment, ++}; ++ ++ ++struct ASSSplitContext { ++ ASS ass; ++ int current_section; ++ int field_number[FF_ARRAY_ELEMS(ass_sections)]; ++ int *field_order[FF_ARRAY_ELEMS(ass_sections)]; ++}; ++ ++ ++static uint8_t *realloc_section_array(ASSSplitContext *ctx) ++{ ++ const ASSSection *section = &ass_sections[ctx->current_section]; ++ int *count = (int *)((uint8_t *)&ctx->ass + section->offset_count); ++ void **section_ptr = (void **)((uint8_t *)&ctx->ass + section->offset); ++ uint8_t *tmp = av_realloc(*section_ptr, (*count+1)*section->size); ++ if (!tmp) ++ return NULL; ++ *section_ptr = tmp; ++ tmp += *count * section->size; ++ memset(tmp, 0, section->size); ++ (*count)++; ++ return tmp; ++} ++ ++static inline int is_eol(char buf) ++{ ++ return buf == '\r' || buf == '\n' || buf == 0; ++} ++ ++static inline const char *skip_space(const char *buf) ++{ ++ while (*buf == ' ') ++ buf++; ++ return buf; ++} ++ ++static const char *ass_split_section(ASSSplitContext *ctx, const char *buf) ++{ ++ const ASSSection *section = &ass_sections[ctx->current_section]; ++ int *number = &ctx->field_number[ctx->current_section]; ++ int *order = ctx->field_order[ctx->current_section]; ++ int *tmp, i, len; ++ ++ while (buf && *buf) { ++ if (buf[0] == '[') { ++ ctx->current_section = -1; ++ break; ++ } ++ if (buf[0] == ';' || (buf[0] == '!' && buf[1] == ':')) { ++ /* skip comments */ ++ } else if (section->format_header && !order) { ++ len = strlen(section->format_header); ++ if (strncmp(buf, section->format_header, len) || buf[len] != ':') ++ return NULL; ++ buf += len + 1; ++ while (!is_eol(*buf)) { ++ buf = skip_space(buf); ++ len = strcspn(buf, ", \r\n"); ++ if (!(tmp = av_realloc(order, (*number + 1) * sizeof(*order)))) ++ return NULL; ++ order = tmp; ++ order[*number] = -1; ++ for (i=0; section->fields[i].name; i++) ++ if (!strncmp(buf, section->fields[i].name, len)) { ++ order[*number] = i; ++ break; ++ } ++ (*number)++; ++ buf = skip_space(buf + len + 1); ++ } ++ ctx->field_order[ctx->current_section] = order; ++ } else if (section->fields_header) { ++ len = strlen(section->fields_header); ++ if (!strncmp(buf, section->fields_header, len) && buf[len] == ':') { ++ uint8_t *ptr, *struct_ptr = realloc_section_array(ctx); ++ if (!struct_ptr) return NULL; ++ buf += len + 1; ++ for (i=0; !is_eol(*buf) && i < *number; i++) { ++ int last = i == *number - 1; ++ buf = skip_space(buf); ++ len = strcspn(buf, last ? "\r\n" : ",\r\n"); ++ if (order[i] >= 0) { ++ ASSFieldType type = section->fields[order[i]].type; ++ ptr = struct_ptr + section->fields[order[i]].offset; ++ convert_func[type](ptr, buf, len); ++ } ++ buf = skip_space(buf + len + !last); ++ } ++ } ++ } else { ++ len = strcspn(buf, ":\r\n"); ++ if (buf[len] == ':') { ++ for (i=0; section->fields[i].name; i++) ++ if (!strncmp(buf, section->fields[i].name, len)) { ++ ASSFieldType type = section->fields[i].type; ++ uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset; ++ ptr += section->fields[i].offset; ++ buf = skip_space(buf + len + 1); ++ convert_func[type](ptr, buf, strcspn(buf, "\r\n")); ++ break; ++ } ++ } ++ } ++ buf += strcspn(buf, "\n") + 1; ++ } ++ return buf; ++} ++ ++static int ass_split(ASSSplitContext *ctx, const char *buf) ++{ ++ char c, section[16]; ++ int i; ++ ++ if (ctx->current_section >= 0) ++ buf = ass_split_section(ctx, buf); ++ ++ while (buf && *buf) { ++ if (sscanf(buf, "[%15[0-9A-Za-z+ ]]%c", section, &c) == 2) { ++ buf += strcspn(buf, "\n") + 1; ++ for (i=0; icurrent_section = i; ++ buf = ass_split_section(ctx, buf); ++ } ++ } else ++ buf += strcspn(buf, "\n") + 1; ++ } ++ return buf ? 0 : AVERROR_INVALIDDATA; ++} ++ ++ASSSplitContext *ff_ass_split(const char *buf) ++{ ++ ASSSplitContext *ctx = av_mallocz(sizeof(*ctx)); ++ ctx->current_section = -1; ++ if (ass_split(ctx, buf) < 0) { ++ ff_ass_split_free(ctx); ++ return NULL; ++ } ++ return ctx; ++} ++ ++static void free_section(ASSSplitContext *ctx, const ASSSection *section) ++{ ++ uint8_t *ptr = (uint8_t *)&ctx->ass + section->offset; ++ int i, j, *count, c = 1; ++ ++ if (section->format_header) { ++ ptr = *(void **)ptr; ++ count = (int *)((uint8_t *)&ctx->ass + section->offset_count); ++ } else ++ count = &c; ++ ++ if (ptr) ++ for (i=0; i<*count; i++, ptr += section->size) ++ for (j=0; section->fields[j].name; j++) { ++ const ASSFields *field = §ion->fields[j]; ++ if (field->type == ASS_STR) ++ av_freep(ptr + field->offset); ++ } ++ *count = 0; ++ ++ if (section->format_header) ++ av_freep((uint8_t *)&ctx->ass + section->offset); ++} ++ ++ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, ++ int cache, int *number) ++{ ++ ASSDialog *dialog = NULL; ++ int i, count; ++ if (!cache) ++ for (i=0; iass.dialogs_count; ++ if (ass_split(ctx, buf) == 0) ++ dialog = ctx->ass.dialogs + count; ++ if (number) ++ *number = ctx->ass.dialogs_count - count; ++ return dialog; ++} ++ ++void ff_ass_split_free(ASSSplitContext *ctx) ++{ ++ if (ctx) { ++ int i; ++ for (i=0; itext && ++ (sscanf(buf, "\\%1[nN]", new_line) == 1 || ++ !strncmp(buf, "{\\", 2))) { ++ callbacks->text(priv, text, text_len); ++ text = NULL; ++ } ++ if (sscanf(buf, "\\%1[nN]", new_line) == 1) { ++ if (callbacks->new_line) ++ callbacks->new_line(priv, new_line[0] == 'N'); ++ buf += 2; ++ } else if (!strncmp(buf, "{\\", 2)) { ++ buf++; ++ while (*buf == '\\') { ++ char style[2], c[2], sep[2], c_num[2] = "0", tmp[128] = {0}; ++ unsigned int color = 0xFFFFFFFF; ++ int len, size = -1, an = -1, alpha = -1; ++ int x1, y1, x2, y2, t1 = -1, t2 = -1; ++ if (sscanf(buf, "\\%1[bisu]%1[01\\}]%n", style, c, &len) > 1) { ++ int close = c[0] == '0' ? 1 : c[0] == '1' ? 0 : -1; ++ len += close != -1; ++ if (callbacks->style) ++ callbacks->style(priv, style[0], close); ++ } else if (sscanf(buf, "\\c%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\c&H%X&%1[\\}]%n", &color, sep, &len) > 1 || ++ sscanf(buf, "\\%1[1234]c%1[\\}]%n", c_num, sep, &len) > 1 || ++ sscanf(buf, "\\%1[1234]c&H%X&%1[\\}]%n", c_num, &color, sep, &len) > 2) { ++ if (callbacks->color) ++ callbacks->color(priv, color, c_num[0] - '0'); ++ } else if (sscanf(buf, "\\alpha%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\alpha&H%2X&%1[\\}]%n", &alpha, sep, &len) > 1 || ++ sscanf(buf, "\\%1[1234]a%1[\\}]%n", c_num, sep, &len) > 1 || ++ sscanf(buf, "\\%1[1234]a&H%2X&%1[\\}]%n", c_num, &alpha, sep, &len) > 2) { ++ if (callbacks->alpha) ++ callbacks->alpha(priv, alpha, c_num[0] - '0'); ++ } else if (sscanf(buf, "\\fn%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\fn%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) { ++ if (callbacks->font_name) ++ callbacks->font_name(priv, tmp[0] ? tmp : NULL); ++ } else if (sscanf(buf, "\\fs%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\fs%u%1[\\}]%n", &size, sep, &len) > 1) { ++ if (callbacks->font_size) ++ callbacks->font_size(priv, size); ++ } else if (sscanf(buf, "\\a%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\a%2u%1[\\}]%n", &an, sep, &len) > 1 || ++ sscanf(buf, "\\an%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\an%1u%1[\\}]%n", &an, sep, &len) > 1) { ++ if (an != -1 && buf[2] != 'n') ++ an = (an&3) + (an&4 ? 6 : an&8 ? 3 : 0); ++ if (callbacks->alignment) ++ callbacks->alignment(priv, an); ++ } else if (sscanf(buf, "\\r%1[\\}]%n", sep, &len) > 0 || ++ sscanf(buf, "\\r%127[^\\}]%1[\\}]%n", tmp, sep, &len) > 1) { ++ if (callbacks->cancel_overrides) ++ callbacks->cancel_overrides(priv, tmp); ++ } else if (sscanf(buf, "\\move(%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, sep, &len) > 4 || ++ sscanf(buf, "\\move(%d,%d,%d,%d,%d,%d)%1[\\}]%n", &x1, &y1, &x2, &y2, &t1, &t2, sep, &len) > 6) { ++ if (callbacks->move) ++ callbacks->move(priv, x1, y1, x2, y2, t1, t2); ++ } else if (sscanf(buf, "\\pos(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) { ++ if (callbacks->move) ++ callbacks->move(priv, x1, y1, x1, y1, -1, -1); ++ } else if (sscanf(buf, "\\org(%d,%d)%1[\\}]%n", &x1, &y1, sep, &len) > 2) { ++ if (callbacks->origin) ++ callbacks->origin(priv, x1, y1); ++ } else { ++ len = strcspn(buf+1, "\\}") + 2; /* skip unknown code */ ++ } ++ buf += len - 1; ++ } ++ if (*buf++ != '}') ++ return AVERROR_INVALIDDATA; ++ } else { ++ if (!text) { ++ text = buf; ++ text_len = 1; ++ } else ++ text_len++; ++ buf++; ++ } ++ } ++ if (text && callbacks->text) ++ callbacks->text(priv, text, text_len); ++ if (callbacks->end) ++ callbacks->end(priv); ++ return 0; ++} ++ ++ASSStyle *ass_style_get(ASSSplitContext *ctx, const char *style) ++{ ++ ASS *ass = &ctx->ass; ++ int i; ++ ++ if (!style || !*style) ++ style = "Default"; ++ for (i=0; istyles_count; i++) ++ if (!strcmp(ass->styles[i].name, style)) ++ return ass->styles + i; ++ return NULL; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass_split.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass_split.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ass_split.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ass_split.h 2012-05-14 14:08:53.488322955 +0200 +@@ -0,0 +1,172 @@ ++/* ++ * SSA/ASS spliting functions ++ * Copyright (c) 2010 Aurelien Jacobs ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_ASS_SPLIT_H ++#define AVCODEC_ASS_SPLIT_H ++ ++/** ++ * fields extracted from the [Script Info] section ++ */ ++typedef struct { ++ char *script_type; /**< SSA script format version (eg. v4.00) */ ++ char *collisions; /**< how subtitles are moved to prevent collisions */ ++ int play_res_x; /**< video width that ASS coords are referring to */ ++ int play_res_y; /**< video height that ASS coords are referring to */ ++ float timer; /**< time multiplier to apply to SSA clock (in %) */ ++} ASSScriptInfo; ++ ++/** ++ * fields extracted from the [V4(+) Styles] section ++ */ ++typedef struct { ++ char *name; /**< name of the tyle (case sensitive) */ ++ char *font_name; /**< font face (case sensitive) */ ++ int font_size; /**< font height */ ++ int primary_color; /**< color that a subtitle will normally appear in */ ++ int back_color; /**< color of the subtitle outline or shadow */ ++ int bold; /**< whether text is bold (1) or not (0) */ ++ int italic; /**< whether text is italic (1) or not (0) */ ++ int underline; /**< whether text is underlined (1) or not (0) */ ++ int alignment; /**< position of the text (left, center, top...), ++ defined after the layout of the numpad ++ (1-3 sub, 4-6 mid, 7-9 top) */ ++} ASSStyle; ++ ++/** ++ * fields extracted from the [Events] section ++ */ ++typedef struct { ++ int layer; /**< higher numbered layers are drawn over lower numbered */ ++ int start; /**< start time of the dialog in centiseconds */ ++ int end; /**< end time of the dialog in centiseconds */ ++ char *style; /**< name of the ASSStyle to use with this dialog */ ++ char *text; /**< actual text which will be displayed as a subtitle, ++ can include style override control codes (see ++ ff_ass_split_override_codes()) */ ++} ASSDialog; ++ ++/** ++ * structure containing the whole split ASS data ++ */ ++typedef struct { ++ ASSScriptInfo script_info; /**< general information about the SSA script*/ ++ ASSStyle *styles; /**< array of split out styles */ ++ int styles_count; /**< number of ASSStyle in the styles array */ ++ ASSDialog *dialogs; /**< array of split out dialogs */ ++ int dialogs_count; /**< number of ASSDialog in the dialogs array*/ ++} ASS; ++ ++/** ++ * This struct can be casted to ASS to access to the split data. ++ */ ++typedef struct ASSSplitContext ASSSplitContext; ++ ++/** ++ * Split a full ASS file or a ASS header from a string buffer and store ++ * the split structure in a newly allocated context. ++ * ++ * @param buf String containing the ASS formated data. ++ * @return Newly allocated struct containing split data. ++ */ ++ASSSplitContext *ff_ass_split(const char *buf); ++ ++/** ++ * Split one or several ASS "Dialogue" lines from a string buffer and store ++ * them in a already initialized context. ++ * ++ * @param ctx Context previously initialized by ff_ass_split(). ++ * @param buf String containing the ASS "Dialogue" lines. ++ * @param cache Set to 1 to keep all the previously split ASSDialog in ++ * the context, or set to 0 to free all the previously split ++ * ASSDialog. ++ * @param number If not NULL, the pointed integer will be set to the number ++ * of split ASSDialog. ++ * @return Pointer to the first split ASSDialog. ++ */ ++ASSDialog *ff_ass_split_dialog(ASSSplitContext *ctx, const char *buf, ++ int cache, int *number); ++ ++/** ++ * Free all the memory allocated for an ASSSplitContext. ++ * ++ * @param ctx Context previously initialized by ff_ass_split(). ++ */ ++void ff_ass_split_free(ASSSplitContext *ctx); ++ ++ ++/** ++ * Set of callback functions corresponding to each override codes that can ++ * be encountered in a "Dialogue" Text field. ++ */ ++typedef struct { ++ /** ++ * @defgroup ass_styles ASS styles ++ * @{ ++ */ ++ void (*text)(void *priv, const char *text, int len); ++ void (*new_line)(void *priv, int forced); ++ void (*style)(void *priv, char style, int close); ++ void (*color)(void *priv, unsigned int color, unsigned int color_id); ++ void (*alpha)(void *priv, int alpha, int alpha_id); ++ void (*font_name)(void *priv, const char *name); ++ void (*font_size)(void *priv, int size); ++ void (*alignment)(void *priv, int alignment); ++ void (*cancel_overrides)(void *priv, const char *style); ++ /** @} */ ++ ++ /** ++ * @defgroup ass_functions ASS functions ++ * @{ ++ */ ++ void (*move)(void *priv, int x1, int y1, int x2, int y2, int t1, int t2); ++ void (*origin)(void *priv, int x, int y); ++ /** @} */ ++ ++ /** ++ * @defgroup ass_end end of Dialogue Event ++ * @{ ++ */ ++ void (*end)(void *priv); ++ /** @} */ ++} ASSCodesCallbacks; ++ ++/** ++ * Split override codes out of a ASS "Dialogue" Text field. ++ * ++ * @param callbacks Set of callback functions called for each override code ++ * encountered. ++ * @param priv Opaque pointer passed to the callback functions. ++ * @param buf The ASS "Dialogue" Text field to split. ++ * @return >= 0 on success otherwise an error code <0 ++ */ ++int ff_ass_split_override_codes(const ASSCodesCallbacks *callbacks, void *priv, ++ const char *buf); ++ ++/** ++ * Find an ASSStyle structure by its name. ++ * ++ * @param ctx Context previously initialized by ff_ass_split(). ++ * @param style name of the style to search for. ++ * @return the ASSStyle corresponding to style, or NULL if style can't be found ++ */ ++ASSStyle *ass_style_get(ASSSplitContext *ctx, const char *style); ++ ++#endif /* AVCODEC_ASS_SPLIT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/asv1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/asv1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/asv1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/asv1.c 2012-05-14 14:08:53.490322995 +0200 +@@ -405,10 +405,10 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + +- av_fast_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ av_fast_padded_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size); + if (!a->bitstream_buffer) + return AVERROR(ENOMEM); + +@@ -450,17 +450,6 @@ + idct_put(a, mb_x, mb_y); + } + } +-#if 0 +-int i; +-printf("%d %d\n", 8*buf_size, get_bits_count(&a->gb)); +-for(i=get_bits_count(&a->gb); i<8*buf_size; i++){ +- printf("%d", get_bits1(&a->gb)); +-} +- +-for(i=0; iavctx->extradata_size; i++){ +- printf("%c\n", ((uint8_t*)s->avctx->extradata)[i]); +-} +-#endif + + *picture= *(AVFrame*)&a->picture; + *data_size = sizeof(AVPicture); +@@ -481,7 +470,7 @@ + init_put_bits(&a->pb, buf, buf_size); + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + for(mb_y=0; mb_ymb_height2; mb_y++){ +@@ -508,7 +497,7 @@ + } + emms_c(); + +- align_put_bits(&a->pb); ++ avpriv_align_put_bits(&a->pb); + while(put_bits_count(&a->pb)&31) + put_bits(&a->pb, 8, 0); + +@@ -614,39 +603,37 @@ + } + + AVCodec ff_asv1_decoder = { +- "asv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ASV1, +- sizeof(ASV1Context), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "asv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ASV1, ++ .priv_data_size = sizeof(ASV1Context), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("ASUS V1"), + }; + + AVCodec ff_asv2_decoder = { +- "asv2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ASV2, +- sizeof(ASV1Context), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "asv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ASV2, ++ .priv_data_size = sizeof(ASV1Context), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("ASUS V2"), + }; + + #if CONFIG_ASV1_ENCODER + AVCodec ff_asv1_encoder = { +- "asv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ASV1, +- sizeof(ASV1Context), +- encode_init, +- encode_frame, ++ .name = "asv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ASV1, ++ .priv_data_size = sizeof(ASV1Context), ++ .init = encode_init, ++ .encode = encode_frame, + //encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("ASUS V1"), +@@ -655,12 +642,12 @@ + + #if CONFIG_ASV2_ENCODER + AVCodec ff_asv2_encoder = { +- "asv2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ASV2, +- sizeof(ASV1Context), +- encode_init, +- encode_frame, ++ .name = "asv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ASV2, ++ .priv_data_size = sizeof(ASV1Context), ++ .init = encode_init, ++ .encode = encode_frame, + //encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("ASUS V2"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/atrac1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/atrac1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/atrac1.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/atrac1.c 2012-05-14 14:08:53.495323096 +0200 +@@ -36,6 +36,8 @@ + #include "get_bits.h" + #include "dsputil.h" + #include "fft.h" ++#include "fmtconvert.h" ++#include "sinewin.h" + + #include "atrac.h" + #include "atrac1data.h" +@@ -59,28 +61,30 @@ + int log2_block_count[AT1_QMF_BANDS]; ///< log2 number of blocks in a band + int num_bfus; ///< number of Block Floating Units + float* spectrum[2]; +- DECLARE_ALIGNED(16, float, spec1)[AT1_SU_SAMPLES]; ///< mdct buffer +- DECLARE_ALIGNED(16, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer +- DECLARE_ALIGNED(16, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter +- DECLARE_ALIGNED(16, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter +- DECLARE_ALIGNED(16, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter ++ DECLARE_ALIGNED(32, float, spec1)[AT1_SU_SAMPLES]; ///< mdct buffer ++ DECLARE_ALIGNED(32, float, spec2)[AT1_SU_SAMPLES]; ///< mdct buffer ++ DECLARE_ALIGNED(32, float, fst_qmf_delay)[46]; ///< delay line for the 1st stacked QMF filter ++ DECLARE_ALIGNED(32, float, snd_qmf_delay)[46]; ///< delay line for the 2nd stacked QMF filter ++ DECLARE_ALIGNED(32, float, last_qmf_delay)[256+23]; ///< delay line for the last stacked QMF filter + } AT1SUCtx; + + /** + * The atrac1 context, holds all needed parameters for decoding + */ + typedef struct { ++ AVFrame frame; + AT1SUCtx SUs[AT1_MAX_CHANNELS]; ///< channel sound unit +- DECLARE_ALIGNED(16, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer ++ DECLARE_ALIGNED(32, float, spec)[AT1_SU_SAMPLES]; ///< the mdct spectrum buffer + +- DECLARE_ALIGNED(16, float, low)[256]; +- DECLARE_ALIGNED(16, float, mid)[256]; +- DECLARE_ALIGNED(16, float, high)[512]; ++ DECLARE_ALIGNED(32, float, low)[256]; ++ DECLARE_ALIGNED(32, float, mid)[256]; ++ DECLARE_ALIGNED(32, float, high)[512]; + float* bands[3]; +- DECLARE_ALIGNED(16, float, out_samples)[AT1_MAX_CHANNELS][AT1_SU_SAMPLES]; ++ float *out_samples[AT1_MAX_CHANNELS]; + FFTContext mdct_ctx[3]; + int channels; + DSPContext dsp; ++ FmtConvertContext fmt_conv; + } AT1Ctx; + + /** size of the transform in samples in the long mode for each QMF band */ +@@ -99,7 +103,7 @@ + for (i = 0; i < transf_size / 2; i++) + FFSWAP(float, spec[i], spec[transf_size - 1 - i]); + } +- ff_imdct_half(mdct_context, out, spec); ++ mdct_context->imdct_half(mdct_context, out, spec); + } + + +@@ -128,7 +132,7 @@ + nbits = mdct_long_nbits[band_num] - log2_block_count; + + if (nbits != 5 && nbits != 7 && nbits != 8) +- return -1; ++ return AVERROR_INVALIDDATA; + } else { + block_size = 32; + nbits = 5; +@@ -172,14 +176,14 @@ + /* low and mid band */ + log2_block_count_tmp = get_bits(gb, 2); + if (log2_block_count_tmp & 1) +- return -1; ++ return AVERROR_INVALIDDATA; + log2_block_cnt[i] = 2 - log2_block_count_tmp; + } + + /* high band */ + log2_block_count_tmp = get_bits(gb, 2); + if (log2_block_count_tmp != 0 && log2_block_count_tmp != 3) +- return -1; ++ return AVERROR_INVALIDDATA; + log2_block_cnt[IDX_HIGH_BAND] = 3 - log2_block_count_tmp; + + skip_bits(gb, 2); +@@ -228,7 +232,7 @@ + + /* check for bitstream overflow */ + if (bits_used > AT1_SU_MAX_BITS) +- return -1; ++ return AVERROR_INVALIDDATA; + + /* get the position of the 1st spec according to the block size mode */ + pos = su->log2_block_count[band_num] ? bfu_start_short[bfu_num] : bfu_start_long[bfu_num]; +@@ -270,21 +274,29 @@ + + + static int atrac1_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + AT1Ctx *q = avctx->priv_data; +- int ch, ret, i; ++ int ch, ret; + GetBitContext gb; +- float* samples = data; ++ float *samples; + + + if (buf_size < 212 * q->channels) { +- av_log(q,AV_LOG_ERROR,"Not enought data to decode!\n"); +- return -1; ++ av_log(avctx, AV_LOG_ERROR, "Not enough data to decode!\n"); ++ return AVERROR_INVALIDDATA; + } + ++ /* get output buffer */ ++ q->frame.nb_samples = AT1_SU_SAMPLES; ++ if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (float *)q->frame.data[0]; ++ + for (ch = 0; ch < q->channels; ch++) { + AT1SUCtx* su = &q->SUs[ch]; + +@@ -302,44 +314,74 @@ + ret = at1_imdct_block(su, q); + if (ret < 0) + return ret; +- at1_subband_synthesis(q, su, q->out_samples[ch]); ++ at1_subband_synthesis(q, su, q->channels == 1 ? samples : q->out_samples[ch]); + } + +- /* interleave; FIXME, should create/use a DSP function */ +- if (q->channels == 1) { +- /* mono */ +- memcpy(samples, q->out_samples[0], AT1_SU_SAMPLES * 4); +- } else { +- /* stereo */ +- for (i = 0; i < AT1_SU_SAMPLES; i++) { +- samples[i * 2] = q->out_samples[0][i]; +- samples[i * 2 + 1] = q->out_samples[1][i]; +- } ++ /* interleave */ ++ if (q->channels == 2) { ++ q->fmt_conv.float_interleave(samples, (const float **)q->out_samples, ++ AT1_SU_SAMPLES, 2); + } + +- *data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = q->frame; ++ + return avctx->block_align; + } + + ++static av_cold int atrac1_decode_end(AVCodecContext * avctx) ++{ ++ AT1Ctx *q = avctx->priv_data; ++ ++ av_freep(&q->out_samples[0]); ++ ++ ff_mdct_end(&q->mdct_ctx[0]); ++ ff_mdct_end(&q->mdct_ctx[1]); ++ ff_mdct_end(&q->mdct_ctx[2]); ++ ++ return 0; ++} ++ ++ + static av_cold int atrac1_decode_init(AVCodecContext *avctx) + { + AT1Ctx *q = avctx->priv_data; ++ int ret; + + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + ++ if (avctx->channels < 1 || avctx->channels > AT1_MAX_CHANNELS) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %d\n", ++ avctx->channels); ++ return AVERROR(EINVAL); ++ } + q->channels = avctx->channels; + ++ if (avctx->channels == 2) { ++ q->out_samples[0] = av_malloc(2 * AT1_SU_SAMPLES * sizeof(*q->out_samples[0])); ++ q->out_samples[1] = q->out_samples[0] + AT1_SU_SAMPLES; ++ if (!q->out_samples[0]) { ++ av_freep(&q->out_samples[0]); ++ return AVERROR(ENOMEM); ++ } ++ } ++ + /* Init the mdct transforms */ +- ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15)); +- ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15)); +- ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1 << 15)); ++ if ((ret = ff_mdct_init(&q->mdct_ctx[0], 6, 1, -1.0/ (1 << 15))) || ++ (ret = ff_mdct_init(&q->mdct_ctx[1], 8, 1, -1.0/ (1 << 15))) || ++ (ret = ff_mdct_init(&q->mdct_ctx[2], 9, 1, -1.0/ (1 << 15)))) { ++ av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n"); ++ atrac1_decode_end(avctx); ++ return ret; ++ } + + ff_init_ff_sine_windows(5); + + atrac_generate_tables(); + + dsputil_init(&q->dsp, avctx); ++ ff_fmt_convert_init(&q->fmt_conv, avctx); + + q->bands[0] = q->low; + q->bands[1] = q->mid; +@@ -351,16 +393,9 @@ + q->SUs[1].spectrum[0] = q->SUs[1].spec1; + q->SUs[1].spectrum[1] = q->SUs[1].spec2; + +- return 0; +-} +- +- +-static av_cold int atrac1_decode_end(AVCodecContext * avctx) { +- AT1Ctx *q = avctx->priv_data; ++ avcodec_get_frame_defaults(&q->frame); ++ avctx->coded_frame = &q->frame; + +- ff_mdct_end(&q->mdct_ctx[0]); +- ff_mdct_end(&q->mdct_ctx[1]); +- ff_mdct_end(&q->mdct_ctx[2]); + return 0; + } + +@@ -373,5 +408,6 @@ + .init = atrac1_decode_init, + .close = atrac1_decode_end, + .decode = atrac1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Atrac 1 (Adaptive TRansform Acoustic Coding)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/atrac3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/atrac3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/atrac3.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/atrac3.c 2012-05-14 14:08:53.497323136 +0200 +@@ -41,6 +41,7 @@ + #include "dsputil.h" + #include "bytestream.h" + #include "fft.h" ++#include "fmtconvert.h" + + #include "atrac.h" + #include "atrac3data.h" +@@ -48,6 +49,8 @@ + #define JOINT_STEREO 0x12 + #define STEREO 0x2 + ++#define SAMPLES_PER_FRAME 1024 ++#define MDCT_SIZE 512 + + /* These structures are needed to store the parsed gain control data. */ + typedef struct { +@@ -70,12 +73,12 @@ + int bandsCoded; + int numComponents; + tonal_component components[64]; +- float prevFrame[1024]; ++ float prevFrame[SAMPLES_PER_FRAME]; + int gcBlkSwitch; + gain_block gainBlock[2]; + +- DECLARE_ALIGNED(16, float, spectrum)[1024]; +- DECLARE_ALIGNED(16, float, IMDCT_buf)[1024]; ++ DECLARE_ALIGNED(32, float, spectrum)[SAMPLES_PER_FRAME]; ++ DECLARE_ALIGNED(32, float, IMDCT_buf)[SAMPLES_PER_FRAME]; + + float delayBuf1[46]; ///mdct_ctx,pOutput,pInput); ++ q->mdct_ctx.imdct_calc(&q->mdct_ctx,pOutput,pInput); + + /* Perform windowing on the output. */ +- dsp.vector_fmul(pOutput, pOutput, mdct_window, 512); ++ dsp.vector_fmul(pOutput, pOutput, mdct_window, MDCT_SIZE); + + } + +@@ -186,13 +191,13 @@ + obuf[i] = c ^ buf[i]; + + if (off) +- av_log(NULL,AV_LOG_DEBUG,"Offset of %d not handled, post sample on ffmpeg-dev.\n",off); ++ av_log_ask_for_sample(NULL, "Offset of %d not handled.\n", off); + + return off; + } + + +-static av_cold void init_atrac3_transforms(ATRAC3Context *q) { ++static av_cold int init_atrac3_transforms(ATRAC3Context *q, int is_float) { + float enc_window[256]; + int i; + +@@ -208,7 +213,7 @@ + } + + /* Initialize the MDCT transform. */ +- ff_mdct_init(&q->mdct_ctx, 9, 1, 1.0); ++ return ff_mdct_init(&q->mdct_ctx, 9, 1, is_float ? 1.0 / 32768 : 1.0); + } + + /** +@@ -221,6 +226,8 @@ + + av_free(q->pUnits); + av_free(q->decoded_bytes_buffer); ++ av_freep(&q->outSamples[0]); ++ + ff_mdct_end(&q->mdct_ctx); + + return 0; +@@ -340,7 +347,7 @@ + + /* Clear the subbands that were not coded. */ + first = subbandTab[cnt]; +- memset(pOut+first, 0, (1024 - first) * sizeof(float)); ++ memset(pOut+first, 0, (SAMPLES_PER_FRAME - first) * sizeof(float)); + return numSubbands; + } + +@@ -370,7 +377,7 @@ + + coding_mode_selector = get_bits(gb,2); + if (coding_mode_selector == 2) +- return -1; ++ return AVERROR_INVALIDDATA; + + coding_mode = coding_mode_selector & 1; + +@@ -382,7 +389,7 @@ + + quant_step_index = get_bits(gb,3); + if (quant_step_index <= 1) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (coding_mode_selector == 3) + coding_mode = get_bits1(gb); +@@ -395,8 +402,10 @@ + + for (k=0; k= 64) ++ return AVERROR_INVALIDDATA; + pComponent[component_count].pos = j * 64 + (get_bits(gb,6)); +- max_coded_values = 1024 - pComponent[component_count].pos; ++ max_coded_values = SAMPLES_PER_FRAME - pComponent[component_count].pos; + coded_values = coded_values_per_component + 1; + coded_values = FFMIN(max_coded_values,coded_values); + +@@ -445,7 +454,7 @@ + pLevel[cf]= get_bits(gb,4); + pLoc [cf]= get_bits(gb,5); + if(cf && pLoc[cf] <= pLoc[cf-1]) +- return -1; ++ return AVERROR_INVALIDDATA; + } + } + +@@ -662,12 +671,12 @@ + if (codingMode == JOINT_STEREO && channelNum == 1) { + if (get_bits(gb,2) != 3) { + av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + } else { + if (get_bits(gb,6) != 0x28) { + av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + } + +@@ -701,9 +710,10 @@ + memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); + + /* gain compensation and overlapping */ +- gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), +- &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]), +- &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band])); ++ gainCompensateAndOverlap(pSnd->IMDCT_buf, &pSnd->prevFrame[band * 256], ++ &pOut[band * 256], ++ &pSnd->gainBlock[1 - pSnd->gcBlkSwitch].gBlock[band], ++ &pSnd->gainBlock[ pSnd->gcBlkSwitch].gBlock[band]); + } + + /* Swap the gain control buffers for the next frame. */ +@@ -719,7 +729,8 @@ + * @param databuf the input data + */ + +-static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf) ++static int decodeFrame(ATRAC3Context *q, const uint8_t* databuf, ++ float **out_samples) + { + int result, i; + float *p1, *p2, *p3, *p4; +@@ -731,9 +742,9 @@ + /* decode Sound Unit 1 */ + init_get_bits(&q->gb,databuf,q->bits_per_frame); + +- result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, q->outSamples, 0, JOINT_STEREO); ++ result = decodeChannelSoundUnit(q,&q->gb, q->pUnits, out_samples[0], 0, JOINT_STEREO); + if (result != 0) +- return (result); ++ return result; + + /* Framedata of the su2 in the joint-stereo mode is encoded in + * reverse byte order so we need to swap it first. */ +@@ -753,7 +764,7 @@ + ptr1 = q->decoded_bytes_buffer; + for (i = 4; *ptr1 == 0xF8; i++, ptr1++) { + if (i >= q->bytes_per_frame) +- return -1; ++ return AVERROR_INVALIDDATA; + } + + +@@ -772,14 +783,14 @@ + } + + /* Decode Sound Unit 2. */ +- result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], &q->outSamples[1024], 1, JOINT_STEREO); ++ result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[1], out_samples[1], 1, JOINT_STEREO); + if (result != 0) +- return (result); ++ return result; + + /* Reconstruct the channel coefficients. */ +- reverseMatrixing(q->outSamples, &q->outSamples[1024], q->matrix_coeff_index_prev, q->matrix_coeff_index_now); ++ reverseMatrixing(out_samples[0], out_samples[1], q->matrix_coeff_index_prev, q->matrix_coeff_index_now); + +- channelWeighting(q->outSamples, &q->outSamples[1024], q->weighting_delay); ++ channelWeighting(out_samples[0], out_samples[1], q->weighting_delay); + + } else { + /* normal stereo mode or mono */ +@@ -787,24 +798,25 @@ + for (i=0 ; ichannels ; i++) { + + /* Set the bitstream reader at the start of a channel sound unit. */ +- init_get_bits(&q->gb, databuf+((i*q->bytes_per_frame)/q->channels), (q->bits_per_frame)/q->channels); ++ init_get_bits(&q->gb, ++ databuf + i * q->bytes_per_frame / q->channels, ++ q->bits_per_frame / q->channels); + +- result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], &q->outSamples[i*1024], i, q->codingMode); ++ result = decodeChannelSoundUnit(q,&q->gb, &q->pUnits[i], out_samples[i], i, q->codingMode); + if (result != 0) +- return (result); ++ return result; + } + } + + /* Apply the iQMF synthesis filter. */ +- p1= q->outSamples; + for (i=0 ; ichannels ; i++) { ++ p1 = out_samples[i]; + p2= p1+256; + p3= p2+256; + p4= p3+256; + atrac_iqmf (p1, p2, 256, p1, q->pUnits[i].delayBuf1, q->tempBuf); + atrac_iqmf (p4, p3, 256, p3, q->pUnits[i].delayBuf2, q->tempBuf); + atrac_iqmf (p1, p3, 512, p1, q->pUnits[i].delayBuf3, q->tempBuf); +- p1 +=1024; + } + + return 0; +@@ -817,22 +829,31 @@ + * @param avctx pointer to the AVCodecContext + */ + +-static int atrac3_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) { ++static int atrac3_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + ATRAC3Context *q = avctx->priv_data; +- int result = 0, i; ++ int result; + const uint8_t* databuf; +- int16_t* samples = data; ++ float *samples_flt; ++ int16_t *samples_s16; + + if (buf_size < avctx->block_align) { + av_log(avctx, AV_LOG_ERROR, + "Frame too small (%d bytes). Truncated file?\n", buf_size); +- *data_size = 0; +- return buf_size; ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* get output buffer */ ++ q->frame.nb_samples = SAMPLES_PER_FRAME; ++ if ((result = avctx->get_buffer(avctx, &q->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return result; + } ++ samples_flt = (float *)q->frame.data[0]; ++ samples_s16 = (int16_t *)q->frame.data[0]; + + /* Check if we need to descramble and what buffer to pass on. */ + if (q->scrambled_stream) { +@@ -842,27 +863,30 @@ + databuf = buf; + } + +- result = decodeFrame(q, databuf); ++ if (q->channels == 1 && avctx->sample_fmt == AV_SAMPLE_FMT_FLT) ++ result = decodeFrame(q, databuf, &samples_flt); ++ else ++ result = decodeFrame(q, databuf, q->outSamples); + + if (result != 0) { + av_log(NULL,AV_LOG_ERROR,"Frame decoding error!\n"); +- return -1; ++ return result; + } + +- if (q->channels == 1) { +- /* mono */ +- for (i = 0; i<1024; i++) +- samples[i] = av_clip_int16(round(q->outSamples[i])); +- *data_size = 1024 * sizeof(int16_t); +- } else { +- /* stereo */ +- for (i = 0; i < 1024; i++) { +- samples[i*2] = av_clip_int16(round(q->outSamples[i])); +- samples[i*2+1] = av_clip_int16(round(q->outSamples[1024+i])); +- } +- *data_size = 2048 * sizeof(int16_t); ++ /* interleave */ ++ if (q->channels == 2 && avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { ++ q->fmt_conv.float_interleave(samples_flt, ++ (const float **)q->outSamples, ++ SAMPLES_PER_FRAME, 2); ++ } else if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) { ++ q->fmt_conv.float_to_int16_interleave(samples_s16, ++ (const float **)q->outSamples, ++ SAMPLES_PER_FRAME, q->channels); + } + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = q->frame; ++ + return avctx->block_align; + } + +@@ -875,7 +899,7 @@ + + static av_cold int atrac3_decode_init(AVCodecContext *avctx) + { +- int i; ++ int i, ret; + const uint8_t *edata_ptr = avctx->extradata; + ATRAC3Context *q = avctx->priv_data; + static VLC_TYPE atrac3_vlc_table[4096][2]; +@@ -899,7 +923,7 @@ + av_log(avctx,AV_LOG_DEBUG,"[12-13] %d\n",bytestream_get_le16(&edata_ptr)); //Unknown always 0 + + /* setup */ +- q->samples_per_frame = 1024 * q->channels; ++ q->samples_per_frame = SAMPLES_PER_FRAME * q->channels; + q->atrac3version = 4; + q->delay = 0x88E; + if (q->codingMode) +@@ -912,7 +936,7 @@ + if ((q->bytes_per_frame == 96*q->channels*q->frame_factor) || (q->bytes_per_frame == 152*q->channels*q->frame_factor) || (q->bytes_per_frame == 192*q->channels*q->frame_factor)) { + } else { + av_log(avctx,AV_LOG_ERROR,"Unknown frame/channel/frame_factor configuration %d/%d/%d\n", q->bytes_per_frame, q->channels, q->frame_factor); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + } else if (avctx->extradata_size == 10) { +@@ -932,17 +956,17 @@ + + if (q->atrac3version != 4) { + av_log(avctx,AV_LOG_ERROR,"Version %d != 4.\n",q->atrac3version); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (q->samples_per_frame != 1024 && q->samples_per_frame != 2048) { ++ if (q->samples_per_frame != SAMPLES_PER_FRAME && q->samples_per_frame != SAMPLES_PER_FRAME*2) { + av_log(avctx,AV_LOG_ERROR,"Unknown amount of samples per frame %d.\n",q->samples_per_frame); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (q->delay != 0x88E) { + av_log(avctx,AV_LOG_ERROR,"Unknown amount of delay %x != 0x88E.\n",q->delay); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (q->codingMode == STEREO) { +@@ -951,17 +975,17 @@ + av_log(avctx,AV_LOG_DEBUG,"Joint stereo detected.\n"); + } else { + av_log(avctx,AV_LOG_ERROR,"Unknown channel coding mode %x!\n",q->codingMode); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (avctx->channels <= 0 || avctx->channels > 2 /*|| ((avctx->channels * 1024) != q->samples_per_frame)*/) { + av_log(avctx,AV_LOG_ERROR,"Channel configuration error!\n"); +- return -1; ++ return AVERROR(EINVAL); + } + + + if(avctx->block_align >= UINT_MAX/2) +- return -1; ++ return AVERROR(EINVAL); + + /* Pad the data buffer with FF_INPUT_BUFFER_PADDING_SIZE, + * this is for the bitstream reader. */ +@@ -981,7 +1005,16 @@ + vlcs_initialized = 1; + } + +- init_atrac3_transforms(q); ++ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ else ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ if ((ret = init_atrac3_transforms(q, avctx->sample_fmt == AV_SAMPLE_FMT_FLT))) { ++ av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n"); ++ av_freep(&q->decoded_bytes_buffer); ++ return ret; ++ } + + atrac_generate_tables(); + +@@ -1007,14 +1040,26 @@ + } + + dsputil_init(&dsp, avctx); ++ ff_fmt_convert_init(&q->fmt_conv, avctx); + + q->pUnits = av_mallocz(sizeof(channel_unit)*q->channels); + if (!q->pUnits) { +- av_free(q->decoded_bytes_buffer); ++ atrac3_decode_close(avctx); + return AVERROR(ENOMEM); + } + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ if (avctx->channels > 1 || avctx->sample_fmt == AV_SAMPLE_FMT_S16) { ++ q->outSamples[0] = av_mallocz(SAMPLES_PER_FRAME * avctx->channels * sizeof(*q->outSamples[0])); ++ q->outSamples[1] = q->outSamples[0] + SAMPLES_PER_FRAME; ++ if (!q->outSamples[0]) { ++ atrac3_decode_close(avctx); ++ return AVERROR(ENOMEM); ++ } ++ } ++ ++ avcodec_get_frame_defaults(&q->frame); ++ avctx->coded_frame = &q->frame; ++ + return 0; + } + +@@ -1028,5 +1073,6 @@ + .init = atrac3_decode_init, + .close = atrac3_decode_close, + .decode = atrac3_decode_frame, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Atrac 3 (Adaptive TRansform Acoustic Coding 3)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/audioconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/audioconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/audioconvert.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/audioconvert.c 2012-05-14 14:08:53.498323156 +0200 +@@ -27,7 +27,7 @@ + + #include "libavutil/avstring.h" + #include "libavutil/libm.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/samplefmt.h" + #include "avcodec.h" + #include "audioconvert.h" + +@@ -48,7 +48,7 @@ + } + #endif + +-int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name) ++uint64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name) + { + switch(nb_channels) { + case 1: return AV_CH_LAYOUT_MONO; +@@ -145,8 +145,8 @@ + else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80) + else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi>>16) + else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi) +- else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) +- else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1<<31))) ++ else CONV(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) ++ else CONV(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) + else CONV(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) + else CONV(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) + else CONV(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/audioconvert.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/audioconvert.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/audioconvert.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/audioconvert.h 2012-05-14 14:08:53.499323176 +0200 +@@ -31,6 +31,7 @@ + + #include "libavutil/cpu.h" + #include "avcodec.h" ++#include "libavutil/audioconvert.h" + + #if FF_API_OLD_SAMPLE_FMT + /** +@@ -79,7 +80,7 @@ + * @param fmt_name Format name, or NULL if unknown + * @return Channel layout mask + */ +-int64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name); ++uint64_t avcodec_guess_channel_layout(int nb_channels, enum CodecID codec_id, const char *fmt_name); + + struct AVAudioConvert; + typedef struct AVAudioConvert AVAudioConvert; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aura.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aura.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/aura.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/aura.c 2012-05-14 14:08:53.499323176 +0200 +@@ -39,6 +39,7 @@ + if (avctx->width & 0x3) + return -1; + avctx->pix_fmt = PIX_FMT_YUV422P; ++ avcodec_get_frame_defaults(&s->frame); + + return 0; + } +@@ -123,16 +124,14 @@ + } + + AVCodec ff_aura2_decoder = { +- "aura2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_AURA2, +- sizeof(AuraDecodeContext), +- aura_decode_init, +- NULL, +- aura_decode_end, +- aura_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "aura2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AURA2, ++ .priv_data_size = sizeof(AuraDecodeContext), ++ .init = aura_decode_init, ++ .close = aura_decode_end, ++ .decode = aura_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Auravision Aura 2"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avcodec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avcodec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avcodec.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avcodec.h 2012-05-14 14:08:53.513323458 +0200 +@@ -27,67 +27,46 @@ + */ + + #include +-#include "libavcore/samplefmt.h" ++#include "libavutil/samplefmt.h" + #include "libavutil/avutil.h" + #include "libavutil/cpu.h" +- +-#define LIBAVCODEC_VERSION_MAJOR 52 +-#define LIBAVCODEC_VERSION_MINOR 108 +-#define LIBAVCODEC_VERSION_MICRO 0 +- +-#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ +- LIBAVCODEC_VERSION_MINOR, \ +- LIBAVCODEC_VERSION_MICRO) +-#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \ +- LIBAVCODEC_VERSION_MINOR, \ +- LIBAVCODEC_VERSION_MICRO) +-#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT +- +-#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) +- +-/** +- * Those FF_API_* defines are not part of public API. +- * They may change, break or disappear at any time. ++#include "libavutil/dict.h" ++#include "libavutil/log.h" ++#include "libavutil/pixfmt.h" ++#include "libavutil/rational.h" ++ ++#include "libavcodec/version.h" ++/** ++ * @defgroup libavc Encoding/Decoding Library ++ * @{ ++ * ++ * @defgroup lavc_decoding Decoding ++ * @{ ++ * @} ++ * ++ * @defgroup lavc_encoding Encoding ++ * @{ ++ * @} ++ * ++ * @defgroup lavc_codec Codecs ++ * @{ ++ * @defgroup lavc_codec_native Native Codecs ++ * @{ ++ * @} ++ * @defgroup lavc_codec_wrappers External library wrappers ++ * @{ ++ * @} ++ * @defgroup lavc_codec_hwaccel Hardware Accelerators bridge ++ * @{ ++ * @} ++ * @} ++ * @defgroup lavc_internal Internal ++ * @{ ++ * @} ++ * @} ++ * + */ +-#ifndef FF_API_PALETTE_CONTROL +-#define FF_API_PALETTE_CONTROL (LIBAVCODEC_VERSION_MAJOR < 54) +-#endif +-#ifndef FF_API_MM_FLAGS +-#define FF_API_MM_FLAGS (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_OPT_SHOW +-#define FF_API_OPT_SHOW (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_AUDIO_OLD +-#define FF_API_AUDIO_OLD (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_VIDEO_OLD +-#define FF_API_VIDEO_OLD (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_SUBTITLE_OLD +-#define FF_API_SUBTITLE_OLD (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_USE_LPC +-#define FF_API_USE_LPC (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_SET_STRING_OLD +-#define FF_API_SET_STRING_OLD (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_INOFFICIAL +-#define FF_API_INOFFICIAL (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_OLD_SAMPLE_FMT +-#define FF_API_OLD_SAMPLE_FMT (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif +-#ifndef FF_API_OLD_AUDIOCONVERT +-#define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 53) +-#endif + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-# define FF_INTERNALC_MEM_TYPE unsigned int +-#else +-# define FF_INTERNALC_MEM_TYPE size_t +-#endif + + /** + * Identify the syntax and semantics of the bitstream. +@@ -99,7 +78,8 @@ + * + * If you add a codec ID to this list, add it so that + * 1. no value of a existing codec ID changes (that would break ABI), +- * 2. it is as close as possible to similar codecs. ++ * 2. Give it a value which when taken as ASCII is recognized uniquely by a human as this specific codec. ++ * This ensures that 2 forks can independantly add CodecIDs without producing conflicts. + */ + enum CodecID { + CODEC_ID_NONE, +@@ -167,9 +147,6 @@ + CODEC_ID_QDRAW, + CODEC_ID_VIXL, + CODEC_ID_QPEG, +-#if LIBAVCODEC_VERSION_MAJOR < 53 +- CODEC_ID_XVID, +-#endif + CODEC_ID_PNG, + CODEC_ID_PPM, + CODEC_ID_PBM, +@@ -207,7 +184,9 @@ + CODEC_ID_TIERTEXSEQVIDEO, + CODEC_ID_TIFF, + CODEC_ID_GIF, ++#if LIBAVCODEC_VERSION_MAJOR == 53 + CODEC_ID_FFH264, ++#endif + CODEC_ID_DXA, + CODEC_ID_DNXHD, + CODEC_ID_THP, +@@ -225,8 +204,10 @@ + CODEC_ID_INDEO5, + CODEC_ID_MIMIC, + CODEC_ID_RL2, ++#if LIBAVCODEC_VERSION_MAJOR == 53 + CODEC_ID_8SVX_EXP, + CODEC_ID_8SVX_FIB, ++#endif + CODEC_ID_ESCAPE124, + CODEC_ID_DIRAC, + CODEC_ID_BFI, +@@ -260,9 +241,33 @@ + CODEC_ID_R10K, + CODEC_ID_MXPEG, + CODEC_ID_LAGARITH, ++ CODEC_ID_PRORES, ++ CODEC_ID_JV, ++ CODEC_ID_DFA, ++ CODEC_ID_WMV3IMAGE, ++ CODEC_ID_VC1IMAGE, ++#if LIBAVCODEC_VERSION_MAJOR == 53 ++ CODEC_ID_G723_1_DEPRECATED, ++ CODEC_ID_G729_DEPRECATED, ++#endif ++ CODEC_ID_UTVIDEO_DEPRECATED, ++ CODEC_ID_BMV_VIDEO, ++ CODEC_ID_VBLE, ++ CODEC_ID_DXTORY, ++ CODEC_ID_V410, ++ CODEC_ID_XWD, ++ CODEC_ID_Y41P = MKBETAG('Y','4','1','P'), ++ CODEC_ID_UTVIDEO = 0x800, ++ CODEC_ID_ESCAPE130 = MKBETAG('E','1','3','0'), ++ CODEC_ID_AVRP = MKBETAG('A','V','R','P'), ++ ++ CODEC_ID_G2M = MKBETAG( 0 ,'G','2','M'), ++ CODEC_ID_V308 = MKBETAG('V','3','0','8'), ++ CODEC_ID_YUV4 = MKBETAG('Y','U','V','4'), + + /* various PCM "codecs" */ +- CODEC_ID_PCM_S16LE= 0x10000, ++ CODEC_ID_FIRST_AUDIO = 0x10000, ///< A dummy id pointing at the start of audio codecs ++ CODEC_ID_PCM_S16LE = 0x10000, + CODEC_ID_PCM_S16BE, + CODEC_ID_PCM_U16LE, + CODEC_ID_PCM_U16BE, +@@ -288,9 +293,11 @@ + CODEC_ID_PCM_F64LE, + CODEC_ID_PCM_BLURAY, + CODEC_ID_PCM_LXF, ++ CODEC_ID_S302M, ++ CODEC_ID_PCM_S8_PLANAR, + + /* various ADPCM codecs */ +- CODEC_ID_ADPCM_IMA_QT= 0x11000, ++ CODEC_ID_ADPCM_IMA_QT = 0x11000, + CODEC_ID_ADPCM_IMA_WAV, + CODEC_ID_ADPCM_IMA_DK3, + CODEC_ID_ADPCM_IMA_DK4, +@@ -319,23 +326,24 @@ + CODEC_ID_ADPCM_EA_MAXIS_XA, + CODEC_ID_ADPCM_IMA_ISS, + CODEC_ID_ADPCM_G722, ++ CODEC_ID_ADPCM_IMA_APC, + + /* AMR */ +- CODEC_ID_AMR_NB= 0x12000, ++ CODEC_ID_AMR_NB = 0x12000, + CODEC_ID_AMR_WB, + + /* RealAudio codecs*/ +- CODEC_ID_RA_144= 0x13000, ++ CODEC_ID_RA_144 = 0x13000, + CODEC_ID_RA_288, + + /* various DPCM codecs */ +- CODEC_ID_ROQ_DPCM= 0x14000, ++ CODEC_ID_ROQ_DPCM = 0x14000, + CODEC_ID_INTERPLAY_DPCM, + CODEC_ID_XAN_DPCM, + CODEC_ID_SOL_DPCM, + + /* audio codecs */ +- CODEC_ID_MP2= 0x15000, ++ CODEC_ID_MP2 = 0x15000, + CODEC_ID_MP3, ///< preferred ID for decoding MPEG audio layer 1, 2 or 3 + CODEC_ID_AAC, + CODEC_ID_AC3, +@@ -347,8 +355,10 @@ + CODEC_ID_MACE3, + CODEC_ID_MACE6, + CODEC_ID_VMDAUDIO, ++#if LIBAVCODEC_VERSION_MAJOR == 53 + CODEC_ID_SONIC, + CODEC_ID_SONIC_LS, ++#endif + CODEC_ID_FLAC, + CODEC_ID_MP3ADU, + CODEC_ID_MP3ON4, +@@ -388,9 +398,23 @@ + CODEC_ID_BINKAUDIO_RDFT, + CODEC_ID_BINKAUDIO_DCT, + CODEC_ID_AAC_LATM, ++ CODEC_ID_QDMC, ++ CODEC_ID_CELT, ++#if LIBAVCODEC_VERSION_MAJOR > 53 ++ CODEC_ID_G723_1_DEPRECATED, ++ CODEC_ID_G729_DEPRECATED, ++ CODEC_ID_8SVX_EXP, ++ CODEC_ID_8SVX_FIB, ++#endif ++ CODEC_ID_BMV_AUDIO, ++ CODEC_ID_G729 = 0x15800, ++ CODEC_ID_G723_1= 0x15801, ++ CODEC_ID_FFWAVESYNTH = MKBETAG('F','F','W','S'), ++ CODEC_ID_8SVX_RAW = MKBETAG('8','S','V','X'), + + /* subtitle codecs */ +- CODEC_ID_DVD_SUBTITLE= 0x17000, ++ CODEC_ID_FIRST_SUBTITLE = 0x17000, ///< A dummy ID pointing at the start of subtitle codecs. ++ CODEC_ID_DVD_SUBTITLE = 0x17000, + CODEC_ID_DVB_SUBTITLE, + CODEC_ID_TEXT, ///< raw UTF-8 text + CODEC_ID_XSUB, +@@ -399,33 +423,28 @@ + CODEC_ID_HDMV_PGS_SUBTITLE, + CODEC_ID_DVB_TELETEXT, + CODEC_ID_SRT, ++ CODEC_ID_MICRODVD = MKBETAG('m','D','V','D'), + + /* data codecs */ + CODEC_ID_VBI_DATA= 0x17500, + CODEC_ID_VBI_TELETEXT, + + /* other specific kind of codecs (generally used for attachments) */ +- CODEC_ID_TTF= 0x18000, ++ CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs. ++ CODEC_ID_TTF = 0x18000, ++ CODEC_ID_BINTEXT = MKBETAG('B','T','X','T'), ++ CODEC_ID_XBIN = MKBETAG('X','B','I','N'), ++ CODEC_ID_IDF = MKBETAG( 0 ,'I','D','F'), + +- CODEC_ID_PROBE= 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it ++ CODEC_ID_PROBE = 0x19000, ///< codec_id is not known (like CODEC_ID_NONE) but lavf should attempt to identify it + +- CODEC_ID_MPEG2TS= 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS ++ CODEC_ID_MPEG2TS = 0x20000, /**< _FAKE_ codec to indicate a raw MPEG-2 TS + * stream (only used by libavformat) */ +- CODEC_ID_FFMETADATA=0x21000, ///< Dummy codec for streams containing only metadata information. ++ CODEC_ID_MPEG4SYSTEMS = 0x20001, /**< _FAKE_ codec to indicate a MPEG-4 Systems ++ * stream (only used by libavformat) */ ++ CODEC_ID_FFMETADATA = 0x21000, ///< Dummy codec for streams containing only metadata information. + }; + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-#define CodecType AVMediaType +- +-#define CODEC_TYPE_UNKNOWN AVMEDIA_TYPE_UNKNOWN +-#define CODEC_TYPE_VIDEO AVMEDIA_TYPE_VIDEO +-#define CODEC_TYPE_AUDIO AVMEDIA_TYPE_AUDIO +-#define CODEC_TYPE_DATA AVMEDIA_TYPE_DATA +-#define CODEC_TYPE_SUBTITLE AVMEDIA_TYPE_SUBTITLE +-#define CODEC_TYPE_ATTACHMENT AVMEDIA_TYPE_ATTACHMENT +-#define CODEC_TYPE_NB AVMEDIA_TYPE_NB +-#endif +- + #if FF_API_OLD_SAMPLE_FMT + #define SampleFormat AVSampleFormat + +@@ -439,7 +458,7 @@ + #endif + + #if FF_API_OLD_AUDIOCONVERT +-#include "libavcore/audioconvert.h" ++#include "libavutil/audioconvert.h" + + /* Audio channel masks */ + #define CH_FRONT_LEFT AV_CH_FRONT_LEFT +@@ -486,8 +505,10 @@ + #define CH_LAYOUT_STEREO_DOWNMIX AV_CH_LAYOUT_STEREO_DOWNMIX + #endif + ++#if FF_API_OLD_DECODE_AUDIO + /* in bytes */ + #define AVCODEC_MAX_AUDIO_FRAME_SIZE 192000 // 1 second of 48khz 32bit audio ++#endif + + /** + * Required number of additionally allocated bytes at the end of the input bitstream for decoding. +@@ -496,7 +517,7 @@ + * Note: If the first 23 bits of the additional bytes are not 0, then damaged + * MPEG bitstreams could cause overread and segfault. + */ +-#define FF_INPUT_BUFFER_PADDING_SIZE 8 ++#define FF_INPUT_BUFFER_PADDING_SIZE 16 + + /** + * minimum encoding buffer size +@@ -548,6 +569,7 @@ + AVCOL_TRC_UNSPECIFIED=2, + AVCOL_TRC_GAMMA22 =4, ///< also ITU-R BT470M / ITU-R BT1700 625 PAL & SECAM + AVCOL_TRC_GAMMA28 =5, ///< also ITU-R BT470BG ++ AVCOL_TRC_SMPTE240M =7, + AVCOL_TRC_NB , ///< Not part of ABI + }; + +@@ -559,6 +581,7 @@ + AVCOL_SPC_BT470BG =5, ///< also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 + AVCOL_SPC_SMPTE170M =6, ///< also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above + AVCOL_SPC_SMPTE240M =7, ++ AVCOL_SPC_YCGCO =8, + AVCOL_SPC_NB , ///< Not part of ABI + }; + +@@ -585,6 +608,7 @@ + AVCHROMA_LOC_NB , ///< Not part of ABI + }; + ++#if FF_API_FLAC_GLOBAL_OPTS + /** + * LPC analysis type + */ +@@ -596,6 +620,20 @@ + AV_LPC_TYPE_CHOLESKY = 3, ///< Cholesky factorization + AV_LPC_TYPE_NB , ///< Not part of ABI + }; ++#endif ++ ++enum AVAudioServiceType { ++ AV_AUDIO_SERVICE_TYPE_MAIN = 0, ++ AV_AUDIO_SERVICE_TYPE_EFFECTS = 1, ++ AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED = 2, ++ AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED = 3, ++ AV_AUDIO_SERVICE_TYPE_DIALOGUE = 4, ++ AV_AUDIO_SERVICE_TYPE_COMMENTARY = 5, ++ AV_AUDIO_SERVICE_TYPE_EMERGENCY = 6, ++ AV_AUDIO_SERVICE_TYPE_VOICE_OVER = 7, ++ AV_AUDIO_SERVICE_TYPE_KARAOKE = 8, ++ AV_AUDIO_SERVICE_TYPE_NB , ///< Not part of ABI ++}; + + typedef struct RcOverride{ + int start_frame; +@@ -616,7 +654,6 @@ + #define CODEC_FLAG_QPEL 0x0010 ///< Use qpel MC. + #define CODEC_FLAG_GMC 0x0020 ///< Use GMC. + #define CODEC_FLAG_MV0 0x0040 ///< Always try a MB with MV=<0,0>. +-#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning. + /** + * The parent program guarantees that the input for B-frames containing + * streams is not written to for at least s->max_b_frames+1 frames, if +@@ -625,7 +662,6 @@ + #define CODEC_FLAG_INPUT_PRESERVED 0x0100 + #define CODEC_FLAG_PASS1 0x0200 ///< Use internal 2pass ratecontrol in first pass mode. + #define CODEC_FLAG_PASS2 0x0400 ///< Use internal 2pass ratecontrol in second pass mode. +-#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). + #define CODEC_FLAG_GRAY 0x2000 ///< Only decode/encode grayscale. + #define CODEC_FLAG_EMU_EDGE 0x4000 ///< Don't draw edges. + #define CODEC_FLAG_PSNR 0x8000 ///< error[?] variables will be set during encoding. +@@ -634,25 +670,43 @@ + #define CODEC_FLAG_NORMALIZE_AQP 0x00020000 ///< Normalize adaptive quantization. + #define CODEC_FLAG_INTERLACED_DCT 0x00040000 ///< Use interlaced DCT. + #define CODEC_FLAG_LOW_DELAY 0x00080000 ///< Force low delay. +-#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan. + #define CODEC_FLAG_GLOBAL_HEADER 0x00400000 ///< Place global headers in extradata instead of every keyframe. + #define CODEC_FLAG_BITEXACT 0x00800000 ///< Use only bitexact stuff (except (I)DCT). + /* Fx : Flag for h263+ extra options */ + #define CODEC_FLAG_AC_PRED 0x01000000 ///< H.263 advanced intra coding / MPEG-4 AC prediction +-#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector + #define CODEC_FLAG_CBP_RD 0x04000000 ///< Use rate distortion optimization for cbp. + #define CODEC_FLAG_QP_RD 0x08000000 ///< Use rate distortion optimization for qp selectioon. +-#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC +-#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC + #define CODEC_FLAG_LOOP_FILTER 0x00000800 ///< loop filter +-#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 + #define CODEC_FLAG_INTERLACED_ME 0x20000000 ///< interlaced motion estimation +-#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data. + #define CODEC_FLAG_CLOSED_GOP 0x80000000 + #define CODEC_FLAG2_FAST 0x00000001 ///< Allow non spec compliant speedup tricks. + #define CODEC_FLAG2_STRICT_GOP 0x00000002 ///< Strictly enforce GOP size. + #define CODEC_FLAG2_NO_OUTPUT 0x00000004 ///< Skip bitstream encoding. + #define CODEC_FLAG2_LOCAL_HEADER 0x00000008 ///< Place global headers at every keyframe instead of in extradata. ++#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping ++#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries. ++#define CODEC_FLAG2_SHOW_ALL 0x00400000 ///< Show all frames before the first keyframe ++/** ++ * @defgroup deprecated_flags Deprecated codec flags ++ * Use corresponding private codec options instead. ++ * @{ ++ */ ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++#define CODEC_FLAG_OBMC 0x00000001 ///< OBMC ++#define CODEC_FLAG_H263P_AIV 0x00000008 ///< H.263 alternative inter VLC ++#define CODEC_FLAG_PART 0x0080 ///< Use data partitioning. ++#define CODEC_FLAG_ALT_SCAN 0x00100000 ///< Use alternate scan. ++#define CODEC_FLAG_H263P_UMV 0x02000000 ///< unlimited motion vector ++#define CODEC_FLAG_H263P_SLICE_STRUCT 0x10000000 ++#define CODEC_FLAG_SVCD_SCAN_OFFSET 0x40000000 ///< Will reserve space for SVCD scan offset user data. ++#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table. ++#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. ++#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer. ++#endif ++#if FF_API_MJPEG_GLOBAL_OPTS ++#define CODEC_FLAG_EXTERN_HUFF 0x1000 ///< Use external Huffman table (for MJPEG). ++#endif ++#if FF_API_X264_GLOBAL_OPTS + #define CODEC_FLAG2_BPYRAMID 0x00000010 ///< H.264 allow B-frames to be used as references. + #define CODEC_FLAG2_WPRED 0x00000020 ///< H.264 weighted biprediction for B-frames + #define CODEC_FLAG2_MIXED_REFS 0x00000040 ///< H.264 one reference per partition, as opposed to one reference per macroblock +@@ -660,17 +714,20 @@ + #define CODEC_FLAG2_FASTPSKIP 0x00000100 ///< H.264 fast pskip + #define CODEC_FLAG2_AUD 0x00000200 ///< H.264 access unit delimiters + #define CODEC_FLAG2_BRDO 0x00000400 ///< B-frame rate-distortion optimization +-#define CODEC_FLAG2_INTRA_VLC 0x00000800 ///< Use MPEG-2 intra VLC table. +-#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). +-#define CODEC_FLAG2_DROP_FRAME_TIMECODE 0x00002000 ///< timecode is in drop frame format. +-#define CODEC_FLAG2_SKIP_RD 0x00004000 ///< RD optimal MB level residual skipping +-#define CODEC_FLAG2_CHUNKS 0x00008000 ///< Input bitstream might be truncated at a packet boundaries instead of only at frame boundaries. +-#define CODEC_FLAG2_NON_LINEAR_QUANT 0x00010000 ///< Use MPEG-2 nonlinear quantizer. +-#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible + #define CODEC_FLAG2_MBTREE 0x00040000 ///< Use macroblock tree ratecontrol (x264 only) + #define CODEC_FLAG2_PSY 0x00080000 ///< Use psycho visual optimizations. + #define CODEC_FLAG2_SSIM 0x00100000 ///< Compute SSIM during encoding, error[] values are undefined. + #define CODEC_FLAG2_INTRA_REFRESH 0x00200000 ///< Use periodic insertion of intra blocks instead of keyframes. ++#endif ++#if FF_API_SNOW_GLOBAL_OPTS ++#define CODEC_FLAG2_MEMC_ONLY 0x00001000 ///< Only do ME/MC (I frames -> ref, P frame -> ME+MC). ++#endif ++#if FF_API_LAME_GLOBAL_OPTS ++#define CODEC_FLAG2_BIT_RESERVOIR 0x00020000 ///< Use a bit reservoir when encoding if possible ++#endif ++/** ++ * @} ++ */ + + /* Unsupported options : + * Syntax Arithmetic coding (SAC) +@@ -686,14 +743,35 @@ + * assume the buffer was allocated by avcodec_default_get_buffer. + */ + #define CODEC_CAP_DR1 0x0002 ++#if FF_API_PARSE_FRAME + /* If 'parse_only' field is true, then avcodec_parse_frame() can be used. */ + #define CODEC_CAP_PARSE_ONLY 0x0004 ++#endif + #define CODEC_CAP_TRUNCATED 0x0008 + /* Codec can export data for HW decoding (XvMC). */ + #define CODEC_CAP_HWACCEL 0x0010 + /** +- * Codec has a nonzero delay and needs to be fed with NULL at the end to get the delayed data. +- * If this is not set, the codec is guaranteed to never be fed with NULL data. ++ * Encoder or decoder requires flushing with NULL input at the end in order to ++ * give the complete and correct output. ++ * ++ * NOTE: If this flag is not set, the codec is guaranteed to never be fed with ++ * with NULL data. The user can still send NULL data to the public encode ++ * or decode function, but libavcodec will not pass it along to the codec ++ * unless this flag is set. ++ * ++ * Decoders: ++ * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL, ++ * avpkt->size=0 at the end to get the delayed data until the decoder no longer ++ * returns frames. ++ * ++ * Encoders: ++ * The encoder needs to be fed with NULL data at the end of encoding until the ++ * encoder no longer returns data. ++ * ++ * NOTE: For encoders implementing the AVCodec.encode2() function, setting this ++ * flag also means that the encoder must set the pts and duration for ++ * each output packet. If this flag is not set, the pts and duration will ++ * be determined by libavcodec from the input frame. + */ + #define CODEC_CAP_DELAY 0x0020 + /** +@@ -726,11 +804,37 @@ + * Codec should fill in channel configuration and samplerate instead of container + */ + #define CODEC_CAP_CHANNEL_CONF 0x0400 ++ + /** + * Codec is able to deal with negative linesizes + */ + #define CODEC_CAP_NEG_LINESIZES 0x0800 + ++/** ++ * Codec supports frame-level multithreading. ++ */ ++#define CODEC_CAP_FRAME_THREADS 0x1000 ++/** ++ * Codec supports slice-based (or partition-based) multithreading. ++ */ ++#define CODEC_CAP_SLICE_THREADS 0x2000 ++/** ++ * Codec supports changed parameters at any point. ++ */ ++#define CODEC_CAP_PARAM_CHANGE 0x4000 ++/** ++ * Codec supports avctx->thread_count == 0 (auto). ++ */ ++#define CODEC_CAP_AUTO_THREADS 0x8000 ++/** ++ * Audio encoder supports receiving a different number of samples in each call. ++ */ ++#define CODEC_CAP_VARIABLE_FRAME_SIZE 0x10000 ++/** ++ * Codec is lossless. ++ */ ++#define CODEC_CAP_LOSSLESS 0x80000000 ++ + //The following defines may change, don't expect compatibility if you use them. + #define MB_TYPE_INTRA4x4 0x0001 + #define MB_TYPE_INTRA16x16 0x0002 //FIXME H.264-specific +@@ -784,253 +888,6 @@ + int16_t position[3][2]; + }AVPanScan; + +-#define FF_COMMON_FRAME \ +- /**\ +- * pointer to the picture planes.\ +- * This might be different from the first allocated byte\ +- * - encoding: \ +- * - decoding: \ +- */\ +- uint8_t *data[4];\ +- int linesize[4];\ +- /**\ +- * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer.\ +- * This isn't used by libavcodec unless the default get/release_buffer() is used.\ +- * - encoding: \ +- * - decoding: \ +- */\ +- uint8_t *base[4];\ +- /**\ +- * 1 -> keyframe, 0-> not\ +- * - encoding: Set by libavcodec.\ +- * - decoding: Set by libavcodec.\ +- */\ +- int key_frame;\ +-\ +- /**\ +- * Picture type of the frame, see ?_TYPE below.\ +- * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ +- * - decoding: Set by libavcodec.\ +- */\ +- int pict_type;\ +-\ +- /**\ +- * presentation timestamp in time_base units (time when frame should be shown to user)\ +- * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed.\ +- * - encoding: MUST be set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- int64_t pts;\ +-\ +- /**\ +- * picture number in bitstream order\ +- * - encoding: set by\ +- * - decoding: Set by libavcodec.\ +- */\ +- int coded_picture_number;\ +- /**\ +- * picture number in display order\ +- * - encoding: set by\ +- * - decoding: Set by libavcodec.\ +- */\ +- int display_picture_number;\ +-\ +- /**\ +- * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) \ +- * - encoding: Set by libavcodec. for coded_picture (and set by user for input).\ +- * - decoding: Set by libavcodec.\ +- */\ +- int quality; \ +-\ +- /**\ +- * buffer age (1->was last buffer and dint change, 2->..., ...).\ +- * Set to INT_MAX if the buffer has not been used yet.\ +- * - encoding: unused\ +- * - decoding: MUST be set by get_buffer().\ +- */\ +- int age;\ +-\ +- /**\ +- * is this picture used as reference\ +- * The values for this are the same as the MpegEncContext.picture_structure\ +- * variable, that is 1->top field, 2->bottom field, 3->frame/both fields.\ +- * Set to 4 for delayed, non-reference frames.\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec. (before get_buffer() call)).\ +- */\ +- int reference;\ +-\ +- /**\ +- * QP table\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- int8_t *qscale_table;\ +- /**\ +- * QP store stride\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- int qstride;\ +-\ +- /**\ +- * mbskip_table[mb]>=1 if MB didn't change\ +- * stride= mb_width = (width+15)>>4\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- uint8_t *mbskip_table;\ +-\ +- /**\ +- * motion vector table\ +- * @code\ +- * example:\ +- * int mv_sample_log2= 4 - motion_subsample_log2;\ +- * int mb_width= (width+15)>>4;\ +- * int mv_stride= (mb_width << mv_sample_log2) + 1;\ +- * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y];\ +- * @endcode\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- int16_t (*motion_val[2])[2];\ +-\ +- /**\ +- * macroblock type table\ +- * mb_type_base + mb_width + 2\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- uint32_t *mb_type;\ +-\ +- /**\ +- * log2 of the size of the block which a single vector in motion_val represents: \ +- * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2)\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- uint8_t motion_subsample_log2;\ +-\ +- /**\ +- * for some private data of the user\ +- * - encoding: unused\ +- * - decoding: Set by user.\ +- */\ +- void *opaque;\ +-\ +- /**\ +- * error\ +- * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR.\ +- * - decoding: unused\ +- */\ +- uint64_t error[4];\ +-\ +- /**\ +- * type of the buffer (to keep track of who has to deallocate data[*])\ +- * - encoding: Set by the one who allocates it.\ +- * - decoding: Set by the one who allocates it.\ +- * Note: User allocated (direct rendering) & internal buffers cannot coexist currently.\ +- */\ +- int type;\ +- \ +- /**\ +- * When decoding, this signals how much the picture must be delayed.\ +- * extra_delay = repeat_pict / (2*fps)\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- int repeat_pict;\ +- \ +- /**\ +- * \ +- */\ +- int qscale_type;\ +- \ +- /**\ +- * The content of the picture is interlaced.\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec. (default 0)\ +- */\ +- int interlaced_frame;\ +- \ +- /**\ +- * If the content is interlaced, is top field displayed first.\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- int top_field_first;\ +- \ +- /**\ +- * Pan scan.\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- AVPanScan *pan_scan;\ +- \ +- /**\ +- * Tell user application that palette has changed from previous frame.\ +- * - encoding: ??? (no palette-enabled encoder yet)\ +- * - decoding: Set by libavcodec. (default 0).\ +- */\ +- int palette_has_changed;\ +- \ +- /**\ +- * codec suggestion on buffer type if != 0\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec. (before get_buffer() call)).\ +- */\ +- int buffer_hints;\ +-\ +- /**\ +- * DCT coefficients\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec.\ +- */\ +- short *dct_coeff;\ +-\ +- /**\ +- * motion reference frame index\ +- * the order in which these are stored can depend on the codec.\ +- * - encoding: Set by user.\ +- * - decoding: Set by libavcodec.\ +- */\ +- int8_t *ref_index[2];\ +-\ +- /**\ +- * reordered opaque 64bit (generally an integer or a double precision float\ +- * PTS but can be anything). \ +- * The user sets AVCodecContext.reordered_opaque to represent the input at\ +- * that time,\ +- * the decoder reorders values as needed and sets AVFrame.reordered_opaque\ +- * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque \ +- * @deprecated in favor of pkt_pts\ +- * - encoding: unused\ +- * - decoding: Read by user.\ +- */\ +- int64_t reordered_opaque;\ +-\ +- /**\ +- * hardware accelerator private data (FFmpeg allocated)\ +- * - encoding: unused\ +- * - decoding: Set by libavcodec\ +- */\ +- void *hwaccel_picture_private;\ +-\ +- /**\ +- * reordered pts from the last AVPacket that has been input into the decoder\ +- * - encoding: unused\ +- * - decoding: Read by user.\ +- */\ +- int64_t pkt_pts;\ +-\ +- /**\ +- * dts from the last AVPacket that has been input into the decoder\ +- * - encoding: unused\ +- * - decoding: Read by user.\ +- */\ +- int64_t pkt_dts;\ +- +- + #define FF_QSCALE_TYPE_MPEG1 0 + #define FF_QSCALE_TYPE_MPEG2 1 + #define FF_QSCALE_TYPE_H264 2 +@@ -1041,20 +898,28 @@ + #define FF_BUFFER_TYPE_SHARED 4 ///< Buffer from somewhere else; don't deallocate image (data/base), all other tables are not shared. + #define FF_BUFFER_TYPE_COPY 8 ///< Just a (modified) copy of some other buffer, don't deallocate anything. + +- +-#define FF_I_TYPE 1 ///< Intra +-#define FF_P_TYPE 2 ///< Predicted +-#define FF_B_TYPE 3 ///< Bi-dir predicted +-#define FF_S_TYPE 4 ///< S(GMC)-VOP MPEG4 +-#define FF_SI_TYPE 5 ///< Switching Intra +-#define FF_SP_TYPE 6 ///< Switching Predicted +-#define FF_BI_TYPE 7 ++#if FF_API_OLD_FF_PICT_TYPES ++/* DEPRECATED, directly use the AV_PICTURE_TYPE_* enum values */ ++#define FF_I_TYPE AV_PICTURE_TYPE_I ///< Intra ++#define FF_P_TYPE AV_PICTURE_TYPE_P ///< Predicted ++#define FF_B_TYPE AV_PICTURE_TYPE_B ///< Bi-dir predicted ++#define FF_S_TYPE AV_PICTURE_TYPE_S ///< S(GMC)-VOP MPEG4 ++#define FF_SI_TYPE AV_PICTURE_TYPE_SI ///< Switching Intra ++#define FF_SP_TYPE AV_PICTURE_TYPE_SP ///< Switching Predicted ++#define FF_BI_TYPE AV_PICTURE_TYPE_BI ++#endif + + #define FF_BUFFER_HINTS_VALID 0x01 // Buffer hints value is meaningful (if 0 ignore). + #define FF_BUFFER_HINTS_READABLE 0x02 // Codec will read from buffer. + #define FF_BUFFER_HINTS_PRESERVE 0x04 // User must not alter buffer content. + #define FF_BUFFER_HINTS_REUSABLE 0x08 // Codec will reuse the buffer (update). + ++enum AVPacketSideDataType { ++ AV_PKT_DATA_PALETTE, ++ AV_PKT_DATA_NEW_EXTRADATA, ++ AV_PKT_DATA_PARAM_CHANGE, ++}; ++ + typedef struct AVPacket { + /** + * Presentation timestamp in AVStream->time_base units; the time at which +@@ -1075,8 +940,22 @@ + uint8_t *data; + int size; + int stream_index; ++ /** ++ * A combination of AV_PKT_FLAG values ++ */ + int flags; + /** ++ * Additional packet data that can be provided by the container. ++ * Packet can contain several types of side information. ++ */ ++ struct { ++ uint8_t *data; ++ int size; ++ enum AVPacketSideDataType type; ++ } *side_data; ++ int side_data_elems; ++ ++ /** + * Duration of this packet in AVStream->time_base units, 0 if unknown. + * Equals next_pts - this_pts in presentation order. + */ +@@ -1104,35 +983,409 @@ + */ + int64_t convergence_duration; + } AVPacket; +-#define AV_PKT_FLAG_KEY 0x0001 +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-#define PKT_FLAG_KEY AV_PKT_FLAG_KEY +-#endif ++#define AV_PKT_FLAG_KEY 0x0001 ///< The packet contains a keyframe ++#define AV_PKT_FLAG_CORRUPT 0x0002 ///< The packet content is corrupted ++ ++/** ++ * An AV_PKT_DATA_PARAM_CHANGE side data packet is laid out as follows: ++ * u32le param_flags ++ * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) ++ * s32le channel_count ++ * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) ++ * u64le channel_layout ++ * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) ++ * s32le sample_rate ++ * if (param_flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) ++ * s32le width ++ * s32le height ++ */ ++ ++enum AVSideDataParamChangeFlags { ++ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT = 0x0001, ++ AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT = 0x0002, ++ AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE = 0x0004, ++ AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS = 0x0008, ++}; + + /** + * Audio Video Frame. +- * New fields can be added to the end of FF_COMMON_FRAME with minor version +- * bumps. +- * Removal, reordering and changes to existing fields require a major +- * version bump. No fields should be added into AVFrame before or after +- * FF_COMMON_FRAME! +- * sizeof(AVFrame) must not be used outside libav*. ++ * New fields can be added to the end of AVFRAME with minor version ++ * bumps. Similarly fields that are marked as to be only accessed by ++ * av_opt_ptr() can be reordered. This allows 2 forks to add fields ++ * without breaking compatibility with each other. ++ * Removal, reordering and changes in the remaining cases require ++ * a major version bump. ++ * sizeof(AVFrame) must not be used outside libavcodec. + */ + typedef struct AVFrame { +- FF_COMMON_FRAME ++#if FF_API_DATA_POINTERS ++#define AV_NUM_DATA_POINTERS 4 ++#else ++#define AV_NUM_DATA_POINTERS 8 ++#endif ++ /** ++ * pointer to the picture/channel planes. ++ * This might be different from the first allocated byte ++ * - encoding: Set by user ++ * - decoding: set by AVCodecContext.get_buffer() ++ */ ++ uint8_t *data[AV_NUM_DATA_POINTERS]; ++ ++ /** ++ * Size, in bytes, of the data for each picture/channel plane. ++ * ++ * For audio, only linesize[0] may be set. For planar audio, each channel ++ * plane must be the same size. ++ * ++ * - encoding: Set by user (video only) ++ * - decoding: set by AVCodecContext.get_buffer() ++ */ ++ int linesize[AV_NUM_DATA_POINTERS]; ++ ++ /** ++ * pointer to the first allocated byte of the picture. Can be used in get_buffer/release_buffer. ++ * This isn't used by libavcodec unless the default get/release_buffer() is used. ++ * - encoding: ++ * - decoding: ++ */ ++ uint8_t *base[AV_NUM_DATA_POINTERS]; ++ /** ++ * 1 -> keyframe, 0-> not ++ * - encoding: Set by libavcodec. ++ * - decoding: Set by libavcodec. ++ */ ++ int key_frame; ++ ++ /** ++ * Picture type of the frame, see ?_TYPE below. ++ * - encoding: Set by libavcodec. for coded_picture (and set by user for input). ++ * - decoding: Set by libavcodec. ++ */ ++ enum AVPictureType pict_type; ++ ++ /** ++ * presentation timestamp in time_base units (time when frame should be shown to user) ++ * If AV_NOPTS_VALUE then frame_rate = 1/time_base will be assumed. ++ * - encoding: MUST be set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ int64_t pts; ++ ++ /** ++ * picture number in bitstream order ++ * - encoding: set by ++ * - decoding: Set by libavcodec. ++ */ ++ int coded_picture_number; ++ /** ++ * picture number in display order ++ * - encoding: set by ++ * - decoding: Set by libavcodec. ++ */ ++ int display_picture_number; ++ ++ /** ++ * quality (between 1 (good) and FF_LAMBDA_MAX (bad)) ++ * - encoding: Set by libavcodec. for coded_picture (and set by user for input). ++ * - decoding: Set by libavcodec. ++ */ ++ int quality; ++ ++#if FF_API_AVFRAME_AGE ++ /** ++ * @deprecated unused ++ */ ++ attribute_deprecated int age; ++#endif ++ ++ /** ++ * is this picture used as reference ++ * The values for this are the same as the MpegEncContext.picture_structure ++ * variable, that is 1->top field, 2->bottom field, 3->frame/both fields. ++ * Set to 4 for delayed, non-reference frames. ++ * - encoding: unused ++ * - decoding: Set by libavcodec. (before get_buffer() call)). ++ */ ++ int reference; ++ ++ /** ++ * QP table ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ int8_t *qscale_table; ++ /** ++ * QP store stride ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ int qstride; ++ ++ /** ++ * mbskip_table[mb]>=1 if MB didn't change ++ * stride= mb_width = (width+15)>>4 ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ uint8_t *mbskip_table; ++ ++ /** ++ * motion vector table ++ * @code ++ * example: ++ * int mv_sample_log2= 4 - motion_subsample_log2; ++ * int mb_width= (width+15)>>4; ++ * int mv_stride= (mb_width << mv_sample_log2) + 1; ++ * motion_val[direction][x + y*mv_stride][0->mv_x, 1->mv_y]; ++ * @endcode ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ int16_t (*motion_val[2])[2]; ++ ++ /** ++ * macroblock type table ++ * mb_type_base + mb_width + 2 ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ uint32_t *mb_type; ++ ++ /** ++ * log2 of the size of the block which a single vector in motion_val represents: ++ * (4->16x16, 3->8x8, 2-> 4x4, 1-> 2x2) ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ uint8_t motion_subsample_log2; ++ ++ /** ++ * for some private data of the user ++ * - encoding: unused ++ * - decoding: Set by user. ++ */ ++ void *opaque; ++ ++ /** ++ * error ++ * - encoding: Set by libavcodec. if flags&CODEC_FLAG_PSNR. ++ * - decoding: unused ++ */ ++ uint64_t error[AV_NUM_DATA_POINTERS]; ++ ++ /** ++ * type of the buffer (to keep track of who has to deallocate data[*]) ++ * - encoding: Set by the one who allocates it. ++ * - decoding: Set by the one who allocates it. ++ * Note: User allocated (direct rendering) & internal buffers cannot coexist currently. ++ */ ++ int type; ++ ++ /** ++ * When decoding, this signals how much the picture must be delayed. ++ * extra_delay = repeat_pict / (2*fps) ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ int repeat_pict; ++ ++ /** ++ * ++ */ ++ int qscale_type; ++ ++ /** ++ * The content of the picture is interlaced. ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. (default 0) ++ */ ++ int interlaced_frame; ++ ++ /** ++ * If the content is interlaced, is top field displayed first. ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ int top_field_first; ++ ++ /** ++ * Pan scan. ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ AVPanScan *pan_scan; ++ ++ /** ++ * Tell user application that palette has changed from previous frame. ++ * - encoding: ??? (no palette-enabled encoder yet) ++ * - decoding: Set by libavcodec. (default 0). ++ */ ++ int palette_has_changed; ++ ++ /** ++ * codec suggestion on buffer type if != 0 ++ * - encoding: unused ++ * - decoding: Set by libavcodec. (before get_buffer() call)). ++ */ ++ int buffer_hints; ++ ++ /** ++ * DCT coefficients ++ * - encoding: unused ++ * - decoding: Set by libavcodec. ++ */ ++ short *dct_coeff; ++ ++ /** ++ * motion reference frame index ++ * the order in which these are stored can depend on the codec. ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ int8_t *ref_index[2]; ++ ++ /** ++ * reordered opaque 64bit (generally an integer or a double precision float ++ * PTS but can be anything). ++ * The user sets AVCodecContext.reordered_opaque to represent the input at ++ * that time, ++ * the decoder reorders values as needed and sets AVFrame.reordered_opaque ++ * to exactly one of the values provided by the user through AVCodecContext.reordered_opaque ++ * @deprecated in favor of pkt_pts ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int64_t reordered_opaque; ++ ++ /** ++ * hardware accelerator private data (FFmpeg-allocated) ++ * - encoding: unused ++ * - decoding: Set by libavcodec ++ */ ++ void *hwaccel_picture_private; ++ ++ /** ++ * reordered pts from the last AVPacket that has been input into the decoder ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int64_t pkt_pts; ++ ++ /** ++ * dts from the last AVPacket that has been input into the decoder ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int64_t pkt_dts; ++ ++ /** ++ * the AVCodecContext which ff_thread_get_buffer() was last called on ++ * - encoding: Set by libavcodec. ++ * - decoding: Set by libavcodec. ++ */ ++ struct AVCodecContext *owner; ++ ++ /** ++ * used by multithreading to store frame-specific info ++ * - encoding: Set by libavcodec. ++ * - decoding: Set by libavcodec. ++ */ ++ void *thread_opaque; ++ ++ /** ++ * number of audio samples (per channel) described by this frame ++ * - encoding: unused ++ * - decoding: Set by libavcodec ++ */ ++ int nb_samples; ++ ++ /** ++ * pointers to the data planes/channels. ++ * ++ * For video, this should simply point to data[]. ++ * ++ * For planar audio, each channel has a separate data pointer, and ++ * linesize[0] contains the size of each channel buffer. ++ * For packed audio, there is just one data pointer, and linesize[0] ++ * contains the total size of the buffer for all channels. ++ * ++ * Note: Both data and extended_data will always be set by get_buffer(), ++ * but for planar audio with more channels that can fit in data, ++ * extended_data must be used by the decoder in order to access all ++ * channels. ++ * ++ * encoding: unused ++ * decoding: set by AVCodecContext.get_buffer() ++ */ ++ uint8_t **extended_data; ++ ++ /** ++ * sample aspect ratio for the video frame, 0/1 if unknown\unspecified ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ AVRational sample_aspect_ratio; ++ ++ /** ++ * width and height of the video frame ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int width, height; ++ ++ /** ++ * format of the frame, -1 if unknown or unset ++ * Values correspond to enum PixelFormat for video frames, ++ * enum AVSampleFormat for audio) ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int format; ++ ++ /** ++ * frame timestamp estimated using various heuristics, in stream time base ++ * Code outside libavcodec should access this field using: ++ * av_opt_ptr(avcodec_get_frame_class(), frame, "best_effort_timestamp"); ++ * - encoding: unused ++ * - decoding: set by libavcodec, read by user. ++ */ ++ int64_t best_effort_timestamp; ++ ++ /** ++ * reordered pos from the last AVPacket that has been input into the decoder ++ * Code outside libavcodec should access this field using: ++ * av_opt_ptr(avcodec_get_frame_class(), frame, "pkt_pos"); ++ * - encoding: unused ++ * - decoding: Read by user. ++ */ ++ int64_t pkt_pos; ++ + } AVFrame; + ++struct AVCodecInternal; ++ ++enum AVFieldOrder { ++ AV_FIELD_UNKNOWN, ++ AV_FIELD_PROGRESSIVE, ++ AV_FIELD_TT, //< Top coded_first, top displayed first ++ AV_FIELD_BB, //< Bottom coded first, bottom displayed first ++ AV_FIELD_TB, //< Top coded first, bottom displayed first ++ AV_FIELD_BT, //< Bottom coded first, top displayed first ++}; ++ + /** + * main external API structure. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. ++ * Please use AVOptions (av_opt* / av_set/get*()) to access these fields from user ++ * applications. + * sizeof(AVCodecContext) must not be used outside libav*. + */ + typedef struct AVCodecContext { + /** + * information on struct for av_log +- * - set by avcodec_alloc_context ++ * - set by avcodec_alloc_context3 + */ + const AVClass *av_class; + /** +@@ -1161,7 +1414,7 @@ + * Some codecs need additional format info. It is stored here. + * If any muxer uses this then ALL demuxers/parsers AND encoders for the + * specific codec MUST set it correctly otherwise stream copy breaks. +- * In general use of this field by muxers is not recommanded. ++ * In general use of this field by muxers is not recommended. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. (FIXME: Is this OK?) + */ +@@ -1229,18 +1482,14 @@ + enum PixelFormat pix_fmt; + + /** +- * Frame rate emulation. If not zero, the lower layer (i.e. format handler) +- * has to read frames at native frame rate. +- * - encoding: Set by user. +- * - decoding: unused +- */ +- int rate_emu; +- +- /** + * If non NULL, 'draw_horiz_band' is called by the libavcodec + * decoder to draw a horizontal band. It improves cache usage. Not + * all codecs can do that. You must check the codec capabilities + * beforehand. ++ * When multithreading is used, it may be called from multiple threads ++ * at the same time; threads might draw different parts of the same AVFrame, ++ * or multiple AVFrames, and there is no guarantee that slices will be drawn ++ * in order. + * The function is also used by hardware acceleration APIs. + * It is called at least once during frame decoding to pass + * the data needed for hardware render. +@@ -1256,7 +1505,7 @@ + * @param offset offset into the AVFrame.data from which the slice should be read + */ + void (*draw_horiz_band)(struct AVCodecContext *s, +- const AVFrame *src, int offset[4], ++ const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], + int y, int type, int height); + + /* audio only */ +@@ -1276,15 +1525,14 @@ + */ + int frame_size; + int frame_number; ///< audio or video frame number +-#if LIBAVCODEC_VERSION_MAJOR < 53 +- int real_pict_num; ///< Returns the real picture number of previous encoded frame. +-#endif + + /** +- * Number of frames the decoded output will be delayed relative to +- * the encoded input. ++ * Encoding: Number of frames delay there will be from the encoder input to ++ * the decoder output. (we assume the decoder matches the spec) ++ * Decoding: Number of frames delay in addition to what a standard decoder ++ * as specified in the spec would produce. + * - encoding: Set by libavcodec. +- * - decoding: unused ++ * - decoding: Set by libavcodec. + */ + int delay; + +@@ -1336,14 +1584,6 @@ + + int b_frame_strategy; + +- /** +- * hurry up amount +- * - encoding: unused +- * - decoding: Set by user. 1-> Skip B-frames, 2-> Skip IDCT/dequant too, 5-> Skip everything except header +- * @deprecated Deprecated in favor of skip_idct and skip_frame. +- */ +- int hurry_up; +- + struct AVCodec *codec; + + void *priv_data; +@@ -1398,7 +1638,7 @@ + * A demuxer should set this to what is stored in the field used to identify the codec. + * If there are multiple such fields in a container then the demuxer should choose the one + * which maximizes the information about the used codec. +- * If the codec tag field in a container is larger then 32 bits then the demuxer should ++ * If the codec tag field in a container is larger than 32 bits then the demuxer should + * remap the longer ID to 32 bits with a table or other structure. Alternatively a new + * extra_codec_tag + size could be added but for this a clear advantage must be demonstrated + * first. +@@ -1461,9 +1701,6 @@ + #define FF_COMPLIANCE_VERY_STRICT 2 ///< Strictly conform to an older more strict version of the spec or reference software. + #define FF_COMPLIANCE_STRICT 1 ///< Strictly conform to all the things in the spec no matter what consequences. + #define FF_COMPLIANCE_NORMAL 0 +-#if FF_API_INOFFICIAL +-#define FF_COMPLIANCE_INOFFICIAL -1 ///< Allow inofficial extensions (deprecated - use FF_COMPLIANCE_UNOFFICIAL instead). +-#endif + #define FF_COMPLIANCE_UNOFFICIAL -1 ///< Allow unofficial extensions + #define FF_COMPLIANCE_EXPERIMENTAL -2 ///< Allow nonstandardized experimental things. + +@@ -1474,26 +1711,73 @@ + */ + float b_quant_offset; + ++#if FF_API_ER + /** +- * Error recognization; higher values will detect more errors but may ++ * Error recognition; higher values will detect more errors but may + * misdetect some more or less valid parts as errors. + * - encoding: unused + * - decoding: Set by user. + */ +- int error_recognition; ++ attribute_deprecated int error_recognition; + #define FF_ER_CAREFUL 1 + #define FF_ER_COMPLIANT 2 + #define FF_ER_AGGRESSIVE 3 + #define FF_ER_VERY_AGGRESSIVE 4 ++#define FF_ER_EXPLODE 5 ++#endif /* FF_API_ER */ + + /** + * Called at the beginning of each frame to get a buffer for it. +- * If pic.reference is set then the frame will be read later by libavcodec. +- * avcodec_align_dimensions2() should be used to find the required width and +- * height, as they normally need to be rounded up to the next multiple of 16. ++ * ++ * The function will set AVFrame.data[], AVFrame.linesize[]. ++ * AVFrame.extended_data[] must also be set, but it should be the same as ++ * AVFrame.data[] except for planar audio with more channels than can fit ++ * in AVFrame.data[]. In that case, AVFrame.data[] shall still contain as ++ * many data pointers as it can hold. ++ * + * if CODEC_CAP_DR1 is not set then get_buffer() must call + * avcodec_default_get_buffer() instead of providing buffers allocated by + * some other means. ++ * ++ * AVFrame.data[] should be 32- or 16-byte-aligned unless the CPU doesn't ++ * need it. avcodec_default_get_buffer() aligns the output buffer properly, ++ * but if get_buffer() is overridden then alignment considerations should ++ * be taken into account. ++ * ++ * @see avcodec_default_get_buffer() ++ * ++ * Video: ++ * ++ * If pic.reference is set then the frame will be read later by libavcodec. ++ * avcodec_align_dimensions2() should be used to find the required width and ++ * height, as they normally need to be rounded up to the next multiple of 16. ++ * ++ * If frame multithreading is used and thread_safe_callbacks is set, ++ * it may be called from a different thread, but not from more than one at ++ * once. Does not need to be reentrant. ++ * ++ * @see release_buffer(), reget_buffer() ++ * @see avcodec_align_dimensions2() ++ * ++ * Audio: ++ * ++ * Decoders request a buffer of a particular size by setting ++ * AVFrame.nb_samples prior to calling get_buffer(). The decoder may, ++ * however, utilize only part of the buffer by setting AVFrame.nb_samples ++ * to a smaller value in the output frame. ++ * ++ * Decoders cannot use the buffer after returning from ++ * avcodec_decode_audio4(), so they will not call release_buffer(), as it ++ * is assumed to be released immediately upon return. ++ * ++ * As a convenience, av_samples_get_buffer_size() and ++ * av_samples_fill_arrays() in libavutil may be used by custom get_buffer() ++ * functions to find the required data size and to fill data pointers and ++ * linesize. In AVFrame.linesize, only linesize[0] may be set for audio ++ * since all planes must be the same size. ++ * ++ * @see av_samples_get_buffer_size(), av_samples_fill_arrays() ++ * + * - encoding: unused + * - decoding: Set by libavcodec, user can override. + */ +@@ -1503,6 +1787,8 @@ + * Called to release buffers which were allocated with get_buffer. + * A released buffer can be reused in get_buffer(). + * pic.data[*] must be set to NULL. ++ * May be called from a different thread if frame multithreading is used, ++ * but not by more than one thread at once, so does not need to be reentrant. + * - encoding: unused + * - decoding: Set by libavcodec, user can override. + */ +@@ -1522,9 +1808,15 @@ + */ + int block_align; + +- int parse_only; /* - decoding only: If true, only parsing is done +- (function avcodec_parse_frame()). The frame +- data is returned. Only MPEG codecs support this now. */ ++#if FF_API_PARSE_FRAME ++ /** ++ * If true, only parsing is done. The frame data is returned. ++ * Only MPEG audio decoders support this now. ++ * - encoding: unused ++ * - decoding: Set by user ++ */ ++ attribute_deprecated int parse_only; ++#endif + + /** + * 0-> h263 quant 1-> mpeg quant +@@ -1732,25 +2024,6 @@ + */ + unsigned dsp_mask; + +-#if FF_API_MM_FLAGS +-#define FF_MM_FORCE AV_CPU_FLAG_FORCE +-#define FF_MM_MMX AV_CPU_FLAG_MMX +-#define FF_MM_3DNOW AV_CPU_FLAG_3DNOW +-#define FF_MM_MMXEXT AV_CPU_FLAG_MMX2 +-#define FF_MM_MMX2 AV_CPU_FLAG_MMX2 +-#define FF_MM_SSE AV_CPU_FLAG_SSE +-#define FF_MM_SSE2 AV_CPU_FLAG_SSE2 +-#define FF_MM_SSE2SLOW AV_CPU_FLAG_SSE2SLOW +-#define FF_MM_3DNOWEXT AV_CPU_FLAG_3DNOWEXT +-#define FF_MM_SSE3 AV_CPU_FLAG_SSE3 +-#define FF_MM_SSE3SLOW AV_CPU_FLAG_SSE3SLOW +-#define FF_MM_SSSE3 AV_CPU_FLAG_SSSE3 +-#define FF_MM_SSE4 AV_CPU_FLAG_SSE4 +-#define FF_MM_SSE42 AV_CPU_FLAG_SSE42 +-#define FF_MM_IWMMXT AV_CPU_FLAG_IWMMXT +-#define FF_MM_ALTIVEC AV_CPU_FLAG_ALTIVEC +-#endif +- + /** + * bits per sample/pixel from the demuxer (needed for huffyuv). + * - encoding: Set by libavcodec. +@@ -1806,6 +2079,7 @@ + #define FF_DEBUG_VIS_QP 0x00002000 + #define FF_DEBUG_VIS_MB_TYPE 0x00004000 + #define FF_DEBUG_BUFFERS 0x00008000 ++#define FF_DEBUG_THREADS 0x00010000 + + /** + * debug +@@ -1822,21 +2096,7 @@ + * - encoding: Set by libavcodec if flags&CODEC_FLAG_PSNR. + * - decoding: unused + */ +- uint64_t error[4]; +- +- /** +- * minimum MB quantizer +- * - encoding: unused +- * - decoding: unused +- */ +- int mb_qmin; +- +- /** +- * maximum MB quantizer +- * - encoding: unused +- * - decoding: unused +- */ +- int mb_qmax; ++ uint64_t error[AV_NUM_DATA_POINTERS]; + + /** + * motion estimation comparison function +@@ -1981,17 +2241,21 @@ + */ + int color_table_id; + ++#if FF_API_INTERNAL_CONTEXT + /** + * internal_buffer count + * Don't touch, used by libavcodec default_get_buffer(). ++ * @deprecated this field was moved to an internal context + */ +- int internal_buffer_count; ++ attribute_deprecated int internal_buffer_count; + + /** + * internal_buffers + * Don't touch, used by libavcodec default_get_buffer(). ++ * @deprecated this field was moved to an internal context + */ +- void *internal_buffer; ++ attribute_deprecated void *internal_buffer; ++#endif + + /** + * Global quality for codecs which cannot change it per frame. +@@ -2157,16 +2421,19 @@ + */ + int error_rate; + ++#if FF_API_ANTIALIAS_ALGO + /** + * MP3 antialias algorithm, see FF_AA_* below. + * - encoding: unused + * - decoding: Set by user. + */ +- int antialias_algo; ++ attribute_deprecated int antialias_algo; + #define FF_AA_AUTO 0 + #define FF_AA_FASTINT 1 //not implemented yet + #define FF_AA_INT 2 + #define FF_AA_FLOAT 3 ++#endif ++ + /** + * quantizer noise shaping + * - encoding: Set by user. +@@ -2252,6 +2519,7 @@ + */ + int profile; + #define FF_PROFILE_UNKNOWN -99 ++#define FF_PROFILE_RESERVED -100 + + #define FF_PROFILE_AAC_MAIN 0 + #define FF_PROFILE_AAC_LOW 1 +@@ -2264,6 +2532,13 @@ + #define FF_PROFILE_DTS_HD_HRA 50 + #define FF_PROFILE_DTS_HD_MA 60 + ++#define FF_PROFILE_MPEG2_422 0 ++#define FF_PROFILE_MPEG2_HIGH 1 ++#define FF_PROFILE_MPEG2_SS 2 ++#define FF_PROFILE_MPEG2_SNR_SCALABLE 3 ++#define FF_PROFILE_MPEG2_MAIN 4 ++#define FF_PROFILE_MPEG2_SIMPLE 5 ++ + #define FF_PROFILE_H264_CONSTRAINED (1<<9) // 8+1; constraint_set1_flag + #define FF_PROFILE_H264_INTRA (1<<11) // 8+3; constraint_set3_flag + +@@ -2276,10 +2551,33 @@ + #define FF_PROFILE_H264_HIGH_10_INTRA (110|FF_PROFILE_H264_INTRA) + #define FF_PROFILE_H264_HIGH_422 122 + #define FF_PROFILE_H264_HIGH_422_INTRA (122|FF_PROFILE_H264_INTRA) ++#define FF_PROFILE_H264_HIGH_444 144 + #define FF_PROFILE_H264_HIGH_444_PREDICTIVE 244 + #define FF_PROFILE_H264_HIGH_444_INTRA (244|FF_PROFILE_H264_INTRA) + #define FF_PROFILE_H264_CAVLC_444 44 + ++#define FF_PROFILE_VC1_SIMPLE 0 ++#define FF_PROFILE_VC1_MAIN 1 ++#define FF_PROFILE_VC1_COMPLEX 2 ++#define FF_PROFILE_VC1_ADVANCED 3 ++ ++#define FF_PROFILE_MPEG4_SIMPLE 0 ++#define FF_PROFILE_MPEG4_SIMPLE_SCALABLE 1 ++#define FF_PROFILE_MPEG4_CORE 2 ++#define FF_PROFILE_MPEG4_MAIN 3 ++#define FF_PROFILE_MPEG4_N_BIT 4 ++#define FF_PROFILE_MPEG4_SCALABLE_TEXTURE 5 ++#define FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION 6 ++#define FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE 7 ++#define FF_PROFILE_MPEG4_HYBRID 8 ++#define FF_PROFILE_MPEG4_ADVANCED_REAL_TIME 9 ++#define FF_PROFILE_MPEG4_CORE_SCALABLE 10 ++#define FF_PROFILE_MPEG4_ADVANCED_CODING 11 ++#define FF_PROFILE_MPEG4_ADVANCED_CORE 12 ++#define FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE 13 ++#define FF_PROFILE_MPEG4_SIMPLE_STUDIO 14 ++#define FF_PROFILE_MPEG4_ADVANCED_SIMPLE 15 ++ + /** + * level + * - encoding: Set by user. +@@ -2296,8 +2594,7 @@ + int lowres; + + /** +- * Bitstream width / height, may be different from width/height if lowres +- * or other things are used. ++ * Bitstream width / height, may be different from width/height if lowres enabled. + * - encoding: unused + * - decoding: Set by user before init if known. Codec should override / dynamically change if needed. + */ +@@ -2395,19 +2692,23 @@ + */ + int brd_scale; + ++#if FF_API_X264_GLOBAL_OPTS + /** + * constant rate factor - quality-based VBR - values ~correspond to qps + * - encoding: Set by user. + * - decoding: unused ++ * @deprecated use 'crf' libx264 private option + */ +- float crf; ++ attribute_deprecated float crf; + + /** + * constant quantization parameter rate control method + * - encoding: Set by user. + * - decoding: unused ++ * @deprecated use 'cqp' libx264 private option + */ +- int cqp; ++ attribute_deprecated int cqp; ++#endif + + /** + * minimum GOP size +@@ -2430,12 +2731,14 @@ + */ + int chromaoffset; + ++#if FF_API_X264_GLOBAL_OPTS + /** +- * Influences how often B-frames are used. ++ * Influence how often B-frames are used. + * - encoding: Set by user. + * - decoding: unused + */ +- int bframebias; ++ attribute_deprecated int bframebias; ++#endif + + /** + * trellis RD quantization +@@ -2444,12 +2747,13 @@ + */ + int trellis; + ++#if FF_API_X264_GLOBAL_OPTS + /** + * Reduce fluctuations in qp (before curve compression). + * - encoding: Set by user. + * - decoding: unused + */ +- float complexityblur; ++ attribute_deprecated float complexityblur; + + /** + * in-loop deblocking filter alphac0 parameter +@@ -2457,7 +2761,7 @@ + * - encoding: Set by user. + * - decoding: unused + */ +- int deblockalpha; ++ attribute_deprecated int deblockalpha; + + /** + * in-loop deblocking filter beta parameter +@@ -2465,14 +2769,14 @@ + * - encoding: Set by user. + * - decoding: unused + */ +- int deblockbeta; ++ attribute_deprecated int deblockbeta; + + /** + * macroblock subpartition sizes to consider - p8x8, p4x4, b8x8, i8x8, i4x4 + * - encoding: Set by user. + * - decoding: unused + */ +- int partitions; ++ attribute_deprecated int partitions; + #define X264_PART_I4X4 0x001 /* Analyze i4x4 */ + #define X264_PART_I8X8 0x002 /* Analyze i8x8 (requires 8x8 transform) */ + #define X264_PART_P8X8 0x010 /* Analyze p16x8, p8x16 and p8x8 */ +@@ -2484,7 +2788,8 @@ + * - encoding: Set by user. + * - decoding: unused + */ +- int directpred; ++ attribute_deprecated int directpred; ++#endif + + /** + * Audio cutoff bandwidth (0 means "automatic") +@@ -2509,7 +2814,7 @@ + int mv0_threshold; + + /** +- * Adjusts sensitivity of b_frame_strategy 1. ++ * Adjust sensitivity of b_frame_strategy 1. + * - encoding: Set by user. + * - decoding: unused + */ +@@ -2522,62 +2827,63 @@ + int compression_level; + #define FF_COMPRESSION_DEFAULT -1 + +-#if FF_API_USE_LPC + /** +- * Sets whether to use LPC mode - used by FLAC encoder. + * - encoding: Set by user. + * - decoding: unused +- * @deprecated Deprecated in favor of lpc_type and lpc_passes. + */ +- int use_lpc; +-#endif ++ int min_prediction_order; + + /** +- * LPC coefficient precision - used by FLAC encoder + * - encoding: Set by user. + * - decoding: unused + */ +- int lpc_coeff_precision; ++ int max_prediction_order; + ++#if FF_API_FLAC_GLOBAL_OPTS + /** +- * - encoding: Set by user. +- * - decoding: unused ++ * @name FLAC options ++ * @deprecated Use FLAC encoder private options instead. ++ * @{ + */ +- int min_prediction_order; + + /** ++ * LPC coefficient precision - used by FLAC encoder + * - encoding: Set by user. + * - decoding: unused + */ +- int max_prediction_order; ++ attribute_deprecated int lpc_coeff_precision; + + /** + * search method for selecting prediction order + * - encoding: Set by user. + * - decoding: unused + */ +- int prediction_order_method; ++ attribute_deprecated int prediction_order_method; + + /** + * - encoding: Set by user. + * - decoding: unused + */ +- int min_partition_order; ++ attribute_deprecated int min_partition_order; + + /** + * - encoding: Set by user. + * - decoding: unused + */ +- int max_partition_order; ++ attribute_deprecated int max_partition_order; ++ /** ++ * @} ++ */ ++#endif + + /** +- * GOP timecode frame start number, in non drop frame format +- * - encoding: Set by user. +- * - decoding: unused ++ * GOP timecode frame start number ++ * - encoding: Set by user, in non drop frame format ++ * - decoding: Set by libavcodec (timecode in the 25 bits format, -1 if unset) + */ + int64_t timecode_frame_start; + +-#if LIBAVCODEC_VERSION_MAJOR < 53 ++#if FF_API_REQUEST_CHANNELS + /** + * Decoder should decode to this many channels if it can (0 for default) + * - encoding: unused +@@ -2587,13 +2893,16 @@ + int request_channels; + #endif + ++#if FF_API_DRC_SCALE + /** + * Percentage of dynamic range compression to be applied by the decoder. + * The default value is 1.0, corresponding to full compression. + * - encoding: unused + * - decoding: Set by user. ++ * @deprecated use AC3 decoder private option instead. + */ +- float drc_scale; ++ attribute_deprecated float drc_scale; ++#endif + + /** + * opaque 64bit number (generally a PTS) that will be reordered and +@@ -2606,7 +2915,6 @@ + + /** + * Bits per sample/pixel of internal libavcodec pixel/sample format. +- * This field is applicable only when sample_fmt is AV_SAMPLE_FMT_S32. + * - encoding: set by user. + * - decoding: set by libavcodec. + */ +@@ -2615,16 +2923,16 @@ + /** + * Audio channel layout. + * - encoding: set by user. +- * - decoding: set by libavcodec. ++ * - decoding: set by user, may be overwritten by libavcodec. + */ +- int64_t channel_layout; ++ uint64_t channel_layout; + + /** + * Request decoder to use this channel layout if it can (0 for default) + * - encoding: unused + * - decoding: Set by user. + */ +- int64_t request_channel_layout; ++ uint64_t request_channel_layout; + + /** + * Ratecontrol attempt to use, at maximum, of what can be used without an underflow. +@@ -2723,6 +3031,7 @@ + */ + int (*execute2)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count); + ++#if FF_API_X264_GLOBAL_OPTS + /** + * explicit P-frame weighted prediction analysis method + * 0: off +@@ -2731,7 +3040,7 @@ + * - encoding: Set by user. + * - decoding: unused + */ +- int weighted_p_pred; ++ attribute_deprecated int weighted_p_pred; + + /** + * AQ mode +@@ -2741,7 +3050,7 @@ + * - encoding: Set by user + * - decoding: unused + */ +- int aq_mode; ++ attribute_deprecated int aq_mode; + + /** + * AQ strength +@@ -2749,7 +3058,7 @@ + * - encoding: Set by user + * - decoding: unused + */ +- float aq_strength; ++ attribute_deprecated float aq_strength; + + /** + * PSY RD +@@ -2757,7 +3066,7 @@ + * - encoding: Set by user + * - decoding: unused + */ +- float psy_rd; ++ attribute_deprecated float psy_rd; + + /** + * PSY trellis +@@ -2765,7 +3074,7 @@ + * - encoding: Set by user + * - decoding: unused + */ +- float psy_trellis; ++ attribute_deprecated float psy_trellis; + + /** + * RC lookahead +@@ -2773,7 +3082,7 @@ + * - encoding: Set by user + * - decoding: unused + */ +- int rc_lookahead; ++ attribute_deprecated int rc_lookahead; + + /** + * Constant rate factor maximum +@@ -2782,23 +3091,26 @@ + * - encoding: Set by user. + * - decoding: unused + */ +- float crf_max; ++ attribute_deprecated float crf_max; ++#endif + + int log_level_offset; + ++#if FF_API_FLAC_GLOBAL_OPTS + /** +- * Determines which LPC analysis algorithm to use. ++ * Determine which LPC analysis algorithm to use. + * - encoding: Set by user + * - decoding: unused + */ +- enum AVLPCType lpc_type; ++ attribute_deprecated enum AVLPCType lpc_type; + + /** + * Number of passes to use for Cholesky factorization during LPC analysis + * - encoding: Set by user + * - decoding: unused + */ +- int lpc_passes; ++ attribute_deprecated int lpc_passes; ++#endif + + /** + * Number of slices. +@@ -2814,8 +3126,8 @@ + * For SUBTITLE_ASS subtitle type, it should contain the whole ASS + * [Script Info] and [V4+ Styles] section, plus the [Events] line and + * the Format line following. It shouldn't include any Dialogue line. +- * - encoding: Set/allocated/freed by user (before avcodec_open()) +- * - decoding: Set/allocated/freed by libavcodec (by avcodec_open()) ++ * - encoding: Set/allocated/freed by user (before avcodec_open2()) ++ * - decoding: Set/allocated/freed by libavcodec (by avcodec_open2()) + */ + uint8_t *subtitle_header; + int subtitle_header_size; +@@ -2828,6 +3140,111 @@ + * - encoding: unused + */ + AVPacket *pkt; ++ ++#if FF_API_INTERNAL_CONTEXT ++ /** ++ * Whether this is a copy of the context which had init() called on it. ++ * This is used by multithreading - shared tables and picture pointers ++ * should be freed from the original context only. ++ * - encoding: Set by libavcodec. ++ * - decoding: Set by libavcodec. ++ * ++ * @deprecated this field has been moved to an internal context ++ */ ++ attribute_deprecated int is_copy; ++#endif ++ ++ /** ++ * Which multithreading methods to use. ++ * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread, ++ * so clients which cannot provide future frames should not use it. ++ * ++ * - encoding: Set by user, otherwise the default is used. ++ * - decoding: Set by user, otherwise the default is used. ++ */ ++ int thread_type; ++#define FF_THREAD_FRAME 1 ///< Decode more than one frame at once ++#define FF_THREAD_SLICE 2 ///< Decode more than one part of a single frame at once ++ ++ /** ++ * Which multithreading methods are in use by the codec. ++ * - encoding: Set by libavcodec. ++ * - decoding: Set by libavcodec. ++ */ ++ int active_thread_type; ++ ++ /** ++ * Set by the client if its custom get_buffer() callback can be called ++ * from another thread, which allows faster multithreaded decoding. ++ * draw_horiz_band() will be called from other threads regardless of this setting. ++ * Ignored if the default get_buffer() is used. ++ * - encoding: Set by user. ++ * - decoding: Set by user. ++ */ ++ int thread_safe_callbacks; ++ ++ /** ++ * VBV delay coded in the last frame (in periods of a 27 MHz clock). ++ * Used for compliant TS muxing. ++ * - encoding: Set by libavcodec. ++ * - decoding: unused. ++ */ ++ uint64_t vbv_delay; ++ ++ /** ++ * Type of service that the audio stream conveys. ++ * - encoding: Set by user. ++ * - decoding: Set by libavcodec. ++ */ ++ enum AVAudioServiceType audio_service_type; ++ ++ /** ++ * desired sample format ++ * - encoding: Not used. ++ * - decoding: Set by user. ++ * Decoder will decode to this format if it can. ++ */ ++ enum AVSampleFormat request_sample_fmt; ++ ++ /** ++ * Error recognition; may misdetect some more or less valid parts as errors. ++ * - encoding: unused ++ * - decoding: Set by user. ++ */ ++ int err_recognition; ++#define AV_EF_CRCCHECK (1<<0) ++#define AV_EF_BITSTREAM (1<<1) ++#define AV_EF_BUFFER (1<<2) ++#define AV_EF_EXPLODE (1<<3) ++ ++#define AV_EF_CAREFUL (1<<16) ++#define AV_EF_COMPLIANT (1<<17) ++#define AV_EF_AGGRESSIVE (1<<18) ++ ++ /** ++ * Private context used for internal data. ++ * ++ * Unlike priv_data, this is not codec-specific. It is used in general ++ * libavcodec functions. ++ */ ++ struct AVCodecInternal *internal; ++ ++ /** Field order ++ * - encoding: set by libavcodec ++ * - decoding: Set by libavcodec ++ */ ++ enum AVFieldOrder field_order; ++ ++ /** ++ * Current statistics for PTS correction. ++ * - decoding: maintained and used by libavcodec, not intended to be used by user apps ++ * - encoding: unused ++ */ ++ int64_t pts_correction_num_faulty_pts; /// Number of incorrect PTS values so far ++ int64_t pts_correction_num_faulty_dts; /// Number of incorrect DTS values so far ++ int64_t pts_correction_last_pts; /// PTS of the last frame ++ int64_t pts_correction_last_dts; /// DTS of the last frame ++ + } AVCodecContext; + + /** +@@ -2838,6 +3255,8 @@ + const char *name; ///< short name for the profile + } AVProfile; + ++typedef struct AVCodecDefault AVCodecDefault; ++ + /** + * AVCodec. + */ +@@ -2876,10 +3295,53 @@ + const char *long_name; + const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0 + const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 +- const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 ++ const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 + uint8_t max_lowres; ///< maximum value for lowres supported by the decoder +- AVClass *priv_class; ///< AVClass for the private context ++ const AVClass *priv_class; ///< AVClass for the private context + const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} ++ ++ /** ++ * @name Frame-level threading support functions ++ * @{ ++ */ ++ /** ++ * If defined, called on thread contexts when they are created. ++ * If the codec allocates writable tables in init(), re-allocate them here. ++ * priv_data will be set to a copy of the original. ++ */ ++ int (*init_thread_copy)(AVCodecContext *); ++ /** ++ * Copy necessary context variables from a previous thread context to the current one. ++ * If not defined, the next thread will start automatically; otherwise, the codec ++ * must call ff_thread_finish_setup(). ++ * ++ * dst and src will (rarely) point to the same context, in which case memcpy should be skipped. ++ */ ++ int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src); ++ /** @} */ ++ ++ /** ++ * Private codec-specific defaults. ++ */ ++ const AVCodecDefault *defaults; ++ ++ /** ++ * Initialize codec static data, called from avcodec_register(). ++ */ ++ void (*init_static_data)(struct AVCodec *codec); ++ ++ /** ++ * Encode data to an AVPacket. ++ * ++ * @param avctx codec context ++ * @param avpkt output AVPacket (may contain a user-provided buffer) ++ * @param[in] frame AVFrame containing the raw data to be encoded ++ * @param[out] got_packet_ptr encoder sets to 0 or 1 to indicate that a ++ * non-empty packet was returned in avpkt. ++ * @return 0 on success, negative error code on failure ++ */ ++ int (*encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, ++ int *got_packet_ptr); + } AVCodec; + + /** +@@ -2977,10 +3439,12 @@ + * the last component is alpha + */ + typedef struct AVPicture { +- uint8_t *data[4]; +- int linesize[4]; ///< number of bytes per line ++ uint8_t *data[AV_NUM_DATA_POINTERS]; ++ int linesize[AV_NUM_DATA_POINTERS]; ///< number of bytes per line + } AVPicture; + ++#define AVPALETTE_SIZE 1024 ++#define AVPALETTE_COUNT 256 + #if FF_API_PALETTE_CONTROL + /** + * AVPaletteControl +@@ -2990,8 +3454,6 @@ + * @deprecated Use AVPacket to send palette changes instead. + * This is totally broken. + */ +-#define AVPALETTE_SIZE 1024 +-#define AVPALETTE_COUNT 256 + typedef struct AVPaletteControl { + + /* Demuxer sets this to 1 to indicate the palette has changed; +@@ -3116,6 +3578,33 @@ + */ + void av_free_packet(AVPacket *pkt); + ++/** ++ * Allocate new information of a packet. ++ * ++ * @param pkt packet ++ * @param type side information type ++ * @param size side information size ++ * @return pointer to fresh allocated data or NULL otherwise ++ */ ++uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ++ int size); ++ ++/** ++ * Get side information from packet. ++ * ++ * @param pkt packet ++ * @param type desired side information type ++ * @param size pointer for side information size to store (optional) ++ * @return pointer to data if present or NULL otherwise ++ */ ++uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ++ int *size); ++ ++int av_packet_merge_side_data(AVPacket *pkt); ++ ++int av_packet_split_side_data(AVPacket *pkt); ++ ++ + /* resample.c */ + + struct ReSampleContext; +@@ -3123,15 +3612,8 @@ + + typedef struct ReSampleContext ReSampleContext; + +-#if FF_API_AUDIO_OLD +-/** +- * @deprecated Use av_audio_resample_init() instead. +- */ +-attribute_deprecated ReSampleContext *audio_resample_init(int output_channels, int input_channels, +- int output_rate, int input_rate); +-#endif + /** +- * Initialize audio resampling context ++ * Initialize audio resampling context. + * + * @param output_channels number of output channels + * @param input_channels number of input channels +@@ -3139,12 +3621,12 @@ + * @param input_rate input sample rate + * @param sample_fmt_out requested output sample format + * @param sample_fmt_in input sample format +- * @param filter_length length of each FIR filter in the filterbank relative to the cutoff freq ++ * @param filter_length length of each FIR filter in the filterbank relative to the cutoff frequency + * @param log2_phase_count log2 of the number of entries in the polyphase filterbank +- * @param linear If 1 then the used FIR filter will be linearly interpolated ++ * @param linear if 1 then the used FIR filter will be linearly interpolated + between the 2 closest, if 0 the closest will be used + * @param cutoff cutoff frequency, 1.0 corresponds to half the output sampling rate +- * @return allocated ReSampleContext, NULL if error occured ++ * @return allocated ReSampleContext, NULL if error occurred + */ + ReSampleContext *av_audio_resample_init(int output_channels, int input_channels, + int output_rate, int input_rate, +@@ -3154,6 +3636,13 @@ + int linear, double cutoff); + + int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples); ++ ++/** ++ * Free resample context. ++ * ++ * @param s a non-NULL pointer to a resample context previously ++ * created with av_audio_resample_init() ++ */ + void audio_resample_close(ReSampleContext *s); + + +@@ -3196,7 +3685,9 @@ + void av_resample_close(struct AVResampleContext *c); + + /** +- * Allocate memory for a picture. Call avpicture_free to free it. ++ * Allocate memory for a picture. Call avpicture_free() to free it. ++ * ++ * @see avpicture_fill() + * + * @param picture the picture to be filled in + * @param pix_fmt the format of the picture +@@ -3208,6 +3699,8 @@ + + /** + * Free a picture previously allocated by avpicture_alloc(). ++ * The data buffer used by the AVPicture is freed, but the AVPicture structure ++ * itself is not. + * + * @param picture the AVPicture to be freed + */ +@@ -3223,6 +3716,9 @@ + * will be stored in the lines_sizes array. + * Call with ptr == NULL to get the required size for the ptr buffer. + * ++ * To allocate the buffer and fill in the AVPicture fields in one call, ++ * use avpicture_alloc(). ++ * + * @param picture AVPicture whose fields are to be filled in + * @param ptr Buffer which will contain or contains the actual image data + * @param pix_fmt The format in which the picture data is stored. +@@ -3232,6 +3728,22 @@ + */ + int avpicture_fill(AVPicture *picture, uint8_t *ptr, + enum PixelFormat pix_fmt, int width, int height); ++ ++/** ++ * Copy pixel data from an AVPicture into a buffer. ++ * The data is stored compactly, without any gaps for alignment or padding ++ * which may be applied by avpicture_fill(). ++ * ++ * @see avpicture_get_size() ++ * ++ * @param[in] src AVPicture containing image data ++ * @param[in] pix_fmt The format in which the picture data is stored. ++ * @param[in] width the width of the image in pixels. ++ * @param[in] height the height of the image in pixels. ++ * @param[out] dest A buffer into which picture data will be copied. ++ * @param[in] dest_size The size of 'dest'. ++ * @return The number of bytes written to dest, or a negative value (error code) on error. ++ */ + int avpicture_layout(const AVPicture* src, enum PixelFormat pix_fmt, int width, int height, + unsigned char *dest, int dest_size); + +@@ -3239,8 +3751,8 @@ + * Calculate the size in bytes that a picture of the given width and height + * would occupy if stored in the given picture format. + * Note that this returns the size of a compact representation as generated +- * by avpicture_layout, which can be smaller than the size required for e.g. +- * avpicture_fill. ++ * by avpicture_layout(), which can be smaller than the size required for e.g. ++ * avpicture_fill(). + * + * @param pix_fmt the given picture format + * @param width the width of the image +@@ -3249,26 +3761,26 @@ + */ + int avpicture_get_size(enum PixelFormat pix_fmt, int width, int height); + void avcodec_get_chroma_sub_sample(enum PixelFormat pix_fmt, int *h_shift, int *v_shift); +-const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); +-void avcodec_set_dimensions(AVCodecContext *s, int width, int height); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 + /** +- * Return the pixel format corresponding to the name name. +- * +- * If there is no pixel format with name name, then look for a +- * pixel format with the name corresponding to the native endian +- * format of name. +- * For example in a little-endian system, first look for "gray16", +- * then for "gray16le". +- * +- * Finally if no pixel format has been found, return PIX_FMT_NONE. ++ * Get the name of a codec. ++ * @return a static string identifying the codec; never NULL ++ */ ++const char *avcodec_get_name(enum CodecID id); ++ ++#if FF_API_GET_PIX_FMT_NAME ++/** ++ * Return the short name for a pixel format. + * +- * @deprecated Deprecated in favor of av_get_pix_fmt(). ++ * \see av_get_pix_fmt(), av_get_pix_fmt_string(). ++ * @deprecated Deprecated in favor of av_get_pix_fmt_name(). + */ +-attribute_deprecated enum PixelFormat avcodec_get_pix_fmt(const char* name); ++attribute_deprecated ++const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt); + #endif + ++void avcodec_set_dimensions(AVCodecContext *s, int width, int height); ++ + /** + * Return a value representing the fourCC code associated to the + * pixel format pix_fmt, or 0 if no associated fourCC code can be +@@ -3307,7 +3819,8 @@ + * @param[in] dst_pix_fmt destination pixel format + * @param[in] src_pix_fmt source pixel format + * @param[in] has_alpha Whether the source pixel format alpha channel is used. +- * @return Combination of flags informing you what kind of losses will occur. ++ * @return Combination of flags informing you what kind of losses will occur ++ * (maximum loss for an invalid dst_pix_fmt). + */ + int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt, + int has_alpha); +@@ -3322,9 +3835,11 @@ + * The pixel formats from which it chooses one, are determined by the + * pix_fmt_mask parameter. + * ++ * Note, only the first 64 pixel formats will fit in pix_fmt_mask. ++ * + * @code + * src_pix_fmt = PIX_FMT_YUV420P; +- * pix_fmt_mask = (1 << PIX_FMT_YUV422P) || (1 << PIX_FMT_RGB24); ++ * pix_fmt_mask = (1 << PIX_FMT_YUV422P) | (1 << PIX_FMT_RGB24); + * dst_pix_fmt = avcodec_find_best_pix_fmt(pix_fmt_mask, src_pix_fmt, alpha, &loss); + * @endcode + * +@@ -3337,14 +3852,40 @@ + enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, + int has_alpha, int *loss_ptr); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 + /** +- * @deprecated Use av_get_pix_fmt_string() instead. ++ * Find the best pixel format to convert to given a certain source pixel ++ * format and a selection of two destination pixel formats. When converting from ++ * one pixel format to another, information loss may occur. For example, when converting ++ * from RGB24 to GRAY, the color information will be lost. Similarly, other losses occur when ++ * converting from some formats to other formats. avcodec_find_best_pix_fmt2() selects which of ++ * the given pixel formats should be used to suffer the least amount of loss. ++ * ++ * If one of the destination formats is PIX_FMT_NONE the other pixel format (if valid) will be ++ * returned. ++ * ++ * @code ++ * src_pix_fmt = PIX_FMT_YUV420P; ++ * dst_pix_fmt1= PIX_FMT_RGB24; ++ * dst_pix_fmt2= PIX_FMT_GRAY8; ++ * dst_pix_fmt3= PIX_FMT_RGB8; ++ * loss= FF_LOSS_CHROMA; // don't care about chroma loss, so chroma loss will be ignored. ++ * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt1, dst_pix_fmt2, src_pix_fmt, alpha, &loss); ++ * dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, dst_pix_fmt3, src_pix_fmt, alpha, &loss); ++ * @endcode ++ * ++ * @param[in] dst_pix_fmt1 One of the two destination pixel formats to choose from ++ * @param[in] dst_pix_fmt2 The other of the two destination pixel formats to choose from ++ * @param[in] src_pix_fmt Source pixel format ++ * @param[in] has_alpha Whether the source pixel format alpha channel is used. ++ * @param[in, out] loss_ptr Combination of loss flags. In: selects which of the losses to ignore, i.e. ++ * NULL or value of zero means we care about all losses. Out: the loss ++ * that occurs when converting from src to selected dst pixel format. ++ * @return The best pixel format to convert to or -1 if none was found. + */ +-attribute_deprecated +-void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt); +-#endif ++enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2, ++ enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr); + ++#if FF_API_GET_ALPHA_INFO + #define FF_ALPHA_TRANSP 0x0001 /* image has some totally transparent pixels */ + #define FF_ALPHA_SEMI_TRANSP 0x0002 /* image has some transparent pixels */ + +@@ -3352,8 +3893,10 @@ + * Tell if an image really has transparent alpha values. + * @return ored mask of FF_ALPHA_xxx constants + */ ++attribute_deprecated + int img_get_alpha_info(const AVPicture *src, + enum PixelFormat pix_fmt, int width, int height); ++#endif + + /* deinterlace a picture */ + /* deinterlace - if not supported return -1 */ +@@ -3384,25 +3927,22 @@ + */ + const char *avcodec_license(void); + ++#if FF_API_AVCODEC_INIT + /** +- * Initialize libavcodec. +- * +- * @warning This function must be called before any other libavcodec +- * function. ++ * @deprecated this function is called automatically from avcodec_register() ++ * and avcodec_register_all(), there is no need to call it manually + */ ++attribute_deprecated + void avcodec_init(void); +- +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-/** +- * @deprecated Deprecated in favor of avcodec_register(). +- */ +-attribute_deprecated void register_avcodec(AVCodec *codec); + #endif + + /** + * Register the codec codec and initialize libavcodec. + * +- * @see avcodec_init() ++ * @warning either this function or avcodec_register_all() must be called ++ * before any other libavcodec functions. ++ * ++ * @see avcodec_register_all() + */ + void avcodec_register(AVCodec *codec); + +@@ -3448,46 +3988,74 @@ + */ + const char *av_get_profile_name(const AVCodec *codec, int profile); + ++#if FF_API_ALLOC_CONTEXT + /** + * Set the fields of the given AVCodecContext to default values. + * + * @param s The AVCodecContext of which the fields should be set to default values. ++ * @deprecated use avcodec_get_context_defaults3 + */ ++attribute_deprecated + void avcodec_get_context_defaults(AVCodecContext *s); + + /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! + * we WILL change its arguments and name a few times! */ ++attribute_deprecated + void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType); ++#endif + +-/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! +- * we WILL change its arguments and name a few times! */ ++/** ++ * Set the fields of the given AVCodecContext to default values corresponding ++ * to the given codec (defaults may be codec-dependent). ++ * ++ * Do not call this function if a non-NULL codec has been passed ++ * to avcodec_alloc_context3() that allocated this AVCodecContext. ++ * If codec is non-NULL, it is illegal to call avcodec_open2() with a ++ * different codec on this AVCodecContext. ++ */ + int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec); + ++#if FF_API_ALLOC_CONTEXT + /** + * Allocate an AVCodecContext and set its fields to default values. The + * resulting struct can be deallocated by simply calling av_free(). + * + * @return An AVCodecContext filled with default values or NULL on failure. + * @see avcodec_get_context_defaults ++ * ++ * @deprecated use avcodec_alloc_context3() + */ ++attribute_deprecated + AVCodecContext *avcodec_alloc_context(void); + + /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! + * we WILL change its arguments and name a few times! */ ++attribute_deprecated + AVCodecContext *avcodec_alloc_context2(enum AVMediaType); ++#endif + +-/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API! +- * we WILL change its arguments and name a few times! */ ++/** ++ * Allocate an AVCodecContext and set its fields to default values. The ++ * resulting struct can be deallocated by calling avcodec_close() on it followed ++ * by av_free(). ++ * ++ * @param codec if non-NULL, allocate private data and initialize defaults ++ * for the given codec. It is illegal to then call avcodec_open2() ++ * with a different codec. ++ * ++ * @return An AVCodecContext filled with default values or NULL on failure. ++ * @see avcodec_get_context_defaults ++ */ + AVCodecContext *avcodec_alloc_context3(AVCodec *codec); + + /** + * Copy the settings of the source AVCodecContext into the destination + * AVCodecContext. The resulting destination codec context will be +- * unopened, i.e. you are required to call avcodec_open() before you ++ * unopened, i.e. you are required to call avcodec_open2() before you + * can use this AVCodecContext to decode/encode video/audio data. + * + * @param dest target codec context, should be initialized with +- * avcodec_alloc_context(), but otherwise uninitialized ++ * avcodec_alloc_context3(), but otherwise uninitialized + * @param src source codec context + * @return AVERROR() on error (e.g. memory allocation error), 0 on success + */ +@@ -3541,24 +4109,23 @@ + * according to avcodec_get_edge_width() before. + */ + void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, +- int linesize_align[4]); ++ int linesize_align[AV_NUM_DATA_POINTERS]); ++ ++enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 ++#if FF_API_THREAD_INIT + /** +- * @deprecated Deprecated in favor of av_check_image_size(). ++ * @deprecated Set s->thread_count before calling avcodec_open2() instead of calling this. + */ + attribute_deprecated +-int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h); ++int avcodec_thread_init(AVCodecContext *s, int thread_count); + #endif + +-enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); +- +-int avcodec_thread_init(AVCodecContext *s, int thread_count); +-void avcodec_thread_free(AVCodecContext *s); + int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); + int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); + //FIXME func typedef + ++#if FF_API_AVCODEC_OPEN + /** + * Initialize the AVCodecContext to use the given AVCodec. Prior to using this + * function the context has to be allocated. +@@ -3575,7 +4142,7 @@ + * if (!codec) + * exit(1); + * +- * context = avcodec_alloc_context(); ++ * context = avcodec_alloc_context3(codec); + * + * if (avcodec_open(context, codec) < 0) + * exit(1); +@@ -3584,30 +4151,58 @@ + * @param avctx The context which will be set up to use the given codec. + * @param codec The codec to use within the context. + * @return zero on success, a negative value on error +- * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder ++ * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close ++ * ++ * @deprecated use avcodec_open2 + */ ++attribute_deprecated + int avcodec_open(AVCodecContext *avctx, AVCodec *codec); ++#endif + +-#if FF_API_AUDIO_OLD + /** +- * Decode an audio frame from buf into samples. +- * Wrapper function which calls avcodec_decode_audio3. ++ * Initialize the AVCodecContext to use the given AVCodec. Prior to using this ++ * function the context has to be allocated with avcodec_alloc_context3(). + * +- * @deprecated Use avcodec_decode_audio3 instead. +- * @param avctx the codec context +- * @param[out] samples the output buffer +- * @param[in,out] frame_size_ptr the output buffer size in bytes +- * @param[in] buf the input buffer +- * @param[in] buf_size the input buffer size in bytes +- * @return On error a negative value is returned, otherwise the number of bytes +- * used or zero if no frame could be decompressed. ++ * The functions avcodec_find_decoder_by_name(), avcodec_find_encoder_by_name(), ++ * avcodec_find_decoder() and avcodec_find_encoder() provide an easy way for ++ * retrieving a codec. ++ * ++ * @warning This function is not thread safe! ++ * ++ * @code ++ * avcodec_register_all(); ++ * av_dict_set(&opts, "b", "2.5M", 0); ++ * codec = avcodec_find_decoder(CODEC_ID_H264); ++ * if (!codec) ++ * exit(1); ++ * ++ * context = avcodec_alloc_context3(codec); ++ * ++ * if (avcodec_open2(context, codec, opts) < 0) ++ * exit(1); ++ * @endcode ++ * ++ * @param avctx The context to initialize. ++ * @param codec The codec to open this context for. If a non-NULL codec has been ++ * previously passed to avcodec_alloc_context3() or ++ * avcodec_get_context_defaults3() for this context, then this ++ * parameter MUST be either NULL or equal to the previously passed ++ * codec. ++ * @param options A dictionary filled with AVCodecContext and codec-private options. ++ * On return this object will be filled with options that were not found. ++ * ++ * @return zero on success, a negative value on error ++ * @see avcodec_alloc_context3(), avcodec_find_decoder(), avcodec_find_encoder(), ++ * av_dict_set(), av_opt_find(). + */ +-attribute_deprecated int avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, +- int *frame_size_ptr, +- const uint8_t *buf, int buf_size); +-#endif ++int avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options); + ++#if FF_API_OLD_DECODE_AUDIO + /** ++ * Wrapper function which calls avcodec_decode_audio4. ++ * ++ * @deprecated Use avcodec_decode_audio4 instead. ++ * + * Decode the audio frame of size avpkt->size from avpkt->data into samples. + * Some decoders may support multiple frames in a single AVPacket, such + * decoders would then just decode the first frame. In this case, +@@ -3627,6 +4222,11 @@ + * @warning The end of the input buffer avpkt->data should be set to 0 to ensure that + * no overreading happens for damaged MPEG streams. + * ++ * @warning You must not provide a custom get_buffer() when using ++ * avcodec_decode_audio3(). Doing so will override it with ++ * avcodec_default_get_buffer. Use avcodec_decode_audio4() instead, ++ * which does allow the application to provide a custom get_buffer(). ++ * + * @note You might have to align the input buffer avpkt->data and output buffer + * samples. The alignment requirements depend on the CPU: On some CPUs it isn't + * necessary at all, on others it won't work at all if not aligned and on others +@@ -3636,8 +4236,14 @@ + * samples should be 16 byte aligned unless the CPU doesn't need it + * (AltiVec and SSE do). + * ++ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay ++ * between input and output, these need to be fed with avpkt->data=NULL, ++ * avpkt->size=0 at the end to return the remaining frames. ++ * + * @param avctx the codec context + * @param[out] samples the output buffer, sample type in avctx->sample_fmt ++ * If the sample format is planar, each channel plane will ++ * be the same size, with no padding between channels. + * @param[in,out] frame_size_ptr the output buffer size in bytes + * @param[in] avpkt The input AVPacket containing the input buffer. + * You can create such packet with av_init_packet() and by then setting +@@ -3646,28 +4252,46 @@ + * @return On error a negative value is returned, otherwise the number of bytes + * used or zero if no frame data was decompressed (used) from the input AVPacket. + */ +-int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, ++attribute_deprecated int avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, + int *frame_size_ptr, + AVPacket *avpkt); ++#endif + +-#if FF_API_VIDEO_OLD + /** +- * Decode a video frame from buf into picture. +- * Wrapper function which calls avcodec_decode_video2. ++ * Decode the audio frame of size avpkt->size from avpkt->data into frame. + * +- * @deprecated Use avcodec_decode_video2 instead. +- * @param avctx the codec context +- * @param[out] picture The AVFrame in which the decoded video frame will be stored. +- * @param[in] buf the input buffer +- * @param[in] buf_size the size of the input buffer in bytes +- * @param[in,out] got_picture_ptr Zero if no frame could be decompressed, otherwise, it is nonzero. +- * @return On error a negative value is returned, otherwise the number of bytes +- * used or zero if no frame could be decompressed. ++ * Some decoders may support multiple frames in a single AVPacket. Such ++ * decoders would then just decode the first frame. In this case, ++ * avcodec_decode_audio4 has to be called again with an AVPacket containing ++ * the remaining data in order to decode the second frame, etc... ++ * Even if no frames are returned, the packet needs to be fed to the decoder ++ * with remaining data until it is completely consumed or an error occurs. ++ * ++ * @warning The input buffer, avpkt->data must be FF_INPUT_BUFFER_PADDING_SIZE ++ * larger than the actual read bytes because some optimized bitstream ++ * readers read 32 or 64 bits at once and could read over the end. ++ * ++ * @note You might have to align the input buffer. The alignment requirements ++ * depend on the CPU and the decoder. ++ * ++ * @param avctx the codec context ++ * @param[out] frame The AVFrame in which to store decoded audio samples. ++ * Decoders request a buffer of a particular size by setting ++ * AVFrame.nb_samples prior to calling get_buffer(). The ++ * decoder may, however, only utilize part of the buffer by ++ * setting AVFrame.nb_samples to a smaller value in the ++ * output frame. ++ * @param[out] got_frame_ptr Zero if no frame could be decoded, otherwise it is ++ * non-zero. ++ * @param[in] avpkt The input AVPacket containing the input buffer. ++ * At least avpkt->data and avpkt->size should be set. Some ++ * decoders might also require additional fields to be set. ++ * @return A negative error code is returned if an error occurred during ++ * decoding, otherwise the number of bytes consumed from the input ++ * AVPacket is returned. + */ +-attribute_deprecated int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, +- int *got_picture_ptr, +- const uint8_t *buf, int buf_size); +-#endif ++int avcodec_decode_audio4(AVCodecContext *avctx, AVFrame *frame, ++ int *got_frame_ptr, AVPacket *avpkt); + + /** + * Decode the video frame of size avpkt->size from avpkt->data into picture. +@@ -3688,8 +4312,9 @@ + * + * In practice, avpkt->data should have 4 byte alignment at minimum. + * +- * @note Some codecs have a delay between input and output, these need to be +- * fed with avpkt->data=NULL, avpkt->size=0 at the end to return the remaining frames. ++ * @note Codecs which have the CODEC_CAP_DELAY capability set have a delay ++ * between input and output, these need to be fed with avpkt->data=NULL, ++ * avpkt->size=0 at the end to return the remaining frames. + * + * @param avctx the codec context + * @param[out] picture The AVFrame in which the decoded video frame will be stored. +@@ -3711,16 +4336,7 @@ + */ + int avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, + int *got_picture_ptr, +- AVPacket *avpkt); +- +-#if FF_API_SUBTITLE_OLD +-/* Decode a subtitle message. Return -1 if error, otherwise return the +- * number of bytes used. If no subtitle could be decompressed, +- * got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ +-attribute_deprecated int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, +- int *got_sub_ptr, +- const uint8_t *buf, int buf_size); +-#endif ++ const AVPacket *avpkt); + + /** + * Decode a subtitle message. +@@ -3743,23 +4359,22 @@ + AVPacket *avpkt); + + /** +- * Frees all allocated data in the given subtitle struct. ++ * Free all allocated data in the given subtitle struct. + * + * @param sub AVSubtitle to free. + */ + void avsubtitle_free(AVSubtitle *sub); + +-int avcodec_parse_frame(AVCodecContext *avctx, uint8_t **pdata, +- int *data_size_ptr, +- uint8_t *buf, int buf_size); +- ++#if FF_API_OLD_ENCODE_AUDIO + /** + * Encode an audio frame from samples into buf. + * ++ * @deprecated Use avcodec_encode_audio2 instead. ++ * + * @note The output buffer should be at least FF_MIN_BUFFER_SIZE bytes large. +- * However, for PCM audio the user will know how much space is needed +- * because it depends on the value passed in buf_size as described +- * below. In that case a lower value can be used. ++ * However, for codecs with avctx->frame_size equal to 0 (e.g. PCM) the user ++ * will know how much space is needed because it depends on the value passed ++ * in buf_size as described below. In that case a lower value can be used. + * + * @param avctx the codec context + * @param[out] buf the output buffer +@@ -3767,13 +4382,79 @@ + * @param[in] samples the input buffer containing the samples + * The number of samples read from this buffer is frame_size*channels, + * both of which are defined in avctx. +- * For PCM audio the number of samples read from samples is equal to +- * buf_size * input_sample_size / output_sample_size. ++ * For codecs which have avctx->frame_size equal to 0 (e.g. PCM) the number of ++ * samples read from samples is equal to: ++ * buf_size * 8 / (avctx->channels * av_get_bits_per_sample(avctx->codec_id)) ++ * This also implies that av_get_bits_per_sample() must not return 0 for these ++ * codecs. + * @return On error a negative value is returned, on success zero or the number + * of bytes used to encode the data read from the input buffer. + */ +-int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, +- const short *samples); ++int attribute_deprecated avcodec_encode_audio(AVCodecContext *avctx, ++ uint8_t *buf, int buf_size, ++ const short *samples); ++#endif ++ ++/** ++ * Encode a frame of audio. ++ * ++ * Takes input samples from frame and writes the next output packet, if ++ * available, to avpkt. The output packet does not necessarily contain data for ++ * the most recent frame, as encoders can delay, split, and combine input frames ++ * internally as needed. ++ * ++ * @param avctx codec context ++ * @param avpkt output AVPacket. ++ * The user can supply an output buffer by setting ++ * avpkt->data and avpkt->size prior to calling the ++ * function, but if the size of the user-provided data is not ++ * large enough, encoding will fail. All other AVPacket fields ++ * will be reset by the encoder using av_init_packet(). If ++ * avpkt->data is NULL, the encoder will allocate it. ++ * The encoder will set avpkt->size to the size of the ++ * output packet. ++ * @param[in] frame AVFrame containing the raw audio data to be encoded. ++ * May be NULL when flushing an encoder that has the ++ * CODEC_CAP_DELAY capability set. ++ * There are 2 codec capabilities that affect the allowed ++ * values of frame->nb_samples. ++ * If CODEC_CAP_SMALL_LAST_FRAME is set, then only the final ++ * frame may be smaller than avctx->frame_size, and all other ++ * frames must be equal to avctx->frame_size. ++ * If CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame ++ * can have any number of samples. ++ * If neither is set, frame->nb_samples must be equal to ++ * avctx->frame_size for all frames. ++ * @param[out] got_packet_ptr This field is set to 1 by libavcodec if the ++ * output packet is non-empty, and to 0 if it is ++ * empty. If the function returns an error, the ++ * packet can be assumed to be invalid, and the ++ * value of got_packet_ptr is undefined and should ++ * not be used. ++ * @return 0 on success, negative error code on failure ++ */ ++int avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, ++ const AVFrame *frame, int *got_packet_ptr); ++ ++/** ++ * Fill audio frame data and linesize. ++ * AVFrame extended_data channel pointers are allocated if necessary for ++ * planar audio. ++ * ++ * @param frame the AVFrame ++ * frame->nb_samples must be set prior to calling the ++ * function. This function fills in frame->data, ++ * frame->extended_data, frame->linesize[0]. ++ * @param nb_channels channel count ++ * @param sample_fmt sample format ++ * @param buf buffer to use for frame data ++ * @param buf_size size of buffer ++ * @param align plane size sample alignment ++ * @return 0 on success, negative error code on failure ++ */ ++int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, ++ enum AVSampleFormat sample_fmt, const uint8_t *buf, ++ int buf_size, int align); + + /** + * Encode a video frame from pict into buf. +@@ -3792,6 +4473,15 @@ + int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, + const AVSubtitle *sub); + ++/** ++ * Close a given AVCodecContext and free all the data associated with it ++ * (but not the AVCodecContext itself). ++ * ++ * Calling this function on an AVCodecContext that hasn't been opened will free ++ * the codec-specific data allocated in avcodec_alloc_context3() / ++ * avcodec_get_context_defaults3() with a non-NULL codec. Subsequent calls will ++ * do nothing. ++ */ + int avcodec_close(AVCodecContext *avctx); + + /** +@@ -3815,13 +4505,17 @@ + + /* misc useful functions */ + ++#if FF_API_OLD_FF_PICT_TYPES + /** + * Return a single letter to describe the given picture type pict_type. + * + * @param[in] pict_type the picture type + * @return A single character representing the picture type. ++ * @deprecated Use av_get_picture_type_char() instead. + */ ++attribute_deprecated + char av_get_pict_type_char(int pict_type); ++#endif + + /** + * Return codec bits per sample. +@@ -3833,7 +4527,7 @@ + + #if FF_API_OLD_SAMPLE_FMT + /** +- * @deprecated Use av_get_bits_per_sample_fmt() instead. ++ * @deprecated Use av_get_bytes_per_sample() instead. + */ + attribute_deprecated + int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt); +@@ -3882,10 +4576,10 @@ + int64_t offset; ///< byte offset from starting packet start + int64_t cur_frame_end[AV_PARSER_PTS_NB]; + +- /*! ++ /** + * Set by parser to 1 for key frames and 0 for non-key frames. + * It is initialized to -1, so if the parser doesn't set this flag, +- * old-style fallback using FF_I_TYPE picture type as key frames ++ * old-style fallback using AV_PICTURE_TYPE_I picture type as key frames + * will be used. + */ + int key_frame; +@@ -3986,15 +4680,6 @@ + void av_register_codec_parser(AVCodecParser *parser); + AVCodecParserContext *av_parser_init(int codec_id); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-attribute_deprecated +-int av_parser_parse(AVCodecParserContext *s, +- AVCodecContext *avctx, +- uint8_t **poutbuf, int *poutbuf_size, +- const uint8_t *buf, int buf_size, +- int64_t pts, int64_t dts); +-#endif +- + /** + * Parse a packet. + * +@@ -4073,7 +4758,7 @@ + * + * @see av_realloc + */ +-void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size); ++void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size); + + /** + * Allocate a buffer, reusing the given one if large enough. +@@ -4087,17 +4772,16 @@ + * @param min_size minimum size of *ptr buffer after returning, *ptr will be NULL and + * *size 0 if an error occurred. + */ +-void av_fast_malloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size); ++void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 + /** +- * @deprecated Deprecated in favor of av_image_copy(). ++ * Same behaviour av_fast_malloc but the buffer has additional ++ * FF_INPUT_PADDING_SIZE at the end which will will always be 0. ++ * ++ * In addition the whole buffer will initially and after resizes ++ * be 0-initialized so that no uninitialized data will ever appear. + */ +-attribute_deprecated +-void av_picture_data_copy(uint8_t *dst_data[4], int dst_linesize[4], +- uint8_t *src_data[4], int src_linesize[4], +- enum PixelFormat pix_fmt, int width, int height); +-#endif ++void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size); + + /** + * Copy image src to dst. Wraps av_picture_data_copy() above. +@@ -4126,24 +4810,8 @@ + */ + unsigned int av_xiphlacing(unsigned char *s, unsigned int v); + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-/** +- * Parse str and put in width_ptr and height_ptr the detected values. +- * +- * @deprecated Deprecated in favor of av_parse_video_size(). +- */ +-attribute_deprecated int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str); +- +-/** +- * Parse str and store the detected values in *frame_rate. +- * +- * @deprecated Deprecated in favor of av_parse_video_rate(). +- */ +-attribute_deprecated int av_parse_video_frame_rate(AVRational *frame_rate, const char *str); +-#endif +- + /** +- * Logs a generic warning message about a missing feature. This function is ++ * Log a generic warning message about a missing feature. This function is + * intended to be used internally by FFmpeg (libavcodec, libavformat, etc.) + * only, and would normally not be used by applications. + * @param[in] avc a pointer to an arbitrary struct of which the first field is +@@ -4164,7 +4832,7 @@ + * a pointer to an AVClass struct + * @param[in] msg string containing an optional message, or NULL if no message + */ +-void av_log_ask_for_sample(void *avc, const char *msg); ++void av_log_ask_for_sample(void *avc, const char *msg, ...) av_printf_format(2, 3); + + /** + * Register the hardware accelerator hwaccel. +@@ -4204,4 +4872,31 @@ + */ + int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)); + ++/** ++ * Get the type of the given codec. ++ */ ++enum AVMediaType avcodec_get_type(enum CodecID codec_id); ++ ++/** ++ * Get the AVClass for AVCodecContext. It can be used in combination with ++ * AV_OPT_SEARCH_FAKE_OBJ for examining options. ++ * ++ * @see av_opt_find(). ++ */ ++const AVClass *avcodec_get_class(void); ++ ++/** ++ * Get the AVClass for AVFrame. It can be used in combination with ++ * AV_OPT_SEARCH_FAKE_OBJ for examining options. ++ * ++ * @see av_opt_find(). ++ */ ++const AVClass *avcodec_get_frame_class(void); ++ ++/** ++ * @return a positive value if s is open (i.e. avcodec_open2() was called on it ++ * with no corresponding avcodec_close()), 0 otherwise. ++ */ ++int avcodec_is_open(AVCodecContext *s); ++ + #endif /* AVCODEC_AVCODEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avfft.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avfft.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avfft.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avfft.c 2012-05-14 14:08:53.518323558 +0200 +@@ -19,6 +19,8 @@ + #include "libavutil/mem.h" + #include "avfft.h" + #include "fft.h" ++#include "rdft.h" ++#include "dct.h" + + /* FFT */ + +@@ -101,7 +103,7 @@ + + void av_rdft_calc(RDFTContext *s, FFTSample *data) + { +- ff_rdft_calc(s, data); ++ s->rdft_calc(s, data); + } + + void av_rdft_end(RDFTContext *s) +@@ -128,7 +130,7 @@ + + void av_dct_calc(DCTContext *s, FFTSample *data) + { +- ff_dct_calc(s, data); ++ s->dct_calc(s, data); + } + + void av_dct_end(DCTContext *s) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avpacket.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avpacket.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avpacket.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avpacket.c 2012-05-14 14:08:53.519323579 +0200 +@@ -20,18 +20,32 @@ + */ + + #include "avcodec.h" ++#include "internal.h" + #include "libavutil/avassert.h" +- ++#include "bytestream.h" + + void av_destruct_packet_nofree(AVPacket *pkt) + { + pkt->data = NULL; pkt->size = 0; ++ pkt->side_data = NULL; ++ pkt->side_data_elems = 0; ++} ++ ++void ff_packet_free_side_data(AVPacket *pkt) ++{ ++ int i; ++ for (i = 0; i < pkt->side_data_elems; i++) ++ av_free(pkt->side_data[i].data); ++ av_freep(&pkt->side_data); ++ pkt->side_data_elems = 0; + } + + void av_destruct_packet(AVPacket *pkt) + { + av_free(pkt->data); + pkt->data = NULL; pkt->size = 0; ++ ++ ff_packet_free_side_data(pkt); + } + + void av_init_packet(AVPacket *pkt) +@@ -44,6 +58,8 @@ + pkt->flags = 0; + pkt->stream_index = 0; + pkt->destruct= NULL; ++ pkt->side_data = NULL; ++ pkt->side_data_elems = 0; + } + + int av_new_packet(AVPacket *pkt, int size) +@@ -89,23 +105,52 @@ + return 0; + } + ++#define DUP_DATA(dst, src, size, padding) \ ++ do { \ ++ void *data; \ ++ if (padding) { \ ++ if ((unsigned)(size) > (unsigned)(size) + FF_INPUT_BUFFER_PADDING_SIZE) \ ++ goto failed_alloc; \ ++ data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); \ ++ } else { \ ++ data = av_malloc(size); \ ++ } \ ++ if (!data) \ ++ goto failed_alloc; \ ++ memcpy(data, src, size); \ ++ if (padding) \ ++ memset((uint8_t*)data + size, 0, FF_INPUT_BUFFER_PADDING_SIZE); \ ++ dst = data; \ ++ } while(0) ++ + int av_dup_packet(AVPacket *pkt) + { ++ AVPacket tmp_pkt; ++ + if (((pkt->destruct == av_destruct_packet_nofree) || (pkt->destruct == NULL)) && pkt->data) { +- uint8_t *data; +- /* We duplicate the packet and don't forget to add the padding again. */ +- if((unsigned)pkt->size > (unsigned)pkt->size + FF_INPUT_BUFFER_PADDING_SIZE) +- return AVERROR(ENOMEM); +- data = av_malloc(pkt->size + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!data) { +- return AVERROR(ENOMEM); +- } +- memcpy(data, pkt->data, pkt->size); +- memset(data + pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); +- pkt->data = data; ++ tmp_pkt = *pkt; ++ ++ pkt->data = NULL; ++ pkt->side_data = NULL; ++ DUP_DATA(pkt->data, tmp_pkt.data, pkt->size, 1); + pkt->destruct = av_destruct_packet; ++ ++ if (pkt->side_data_elems) { ++ int i; ++ ++ DUP_DATA(pkt->side_data, tmp_pkt.side_data, ++ pkt->side_data_elems * sizeof(*pkt->side_data), 0); ++ memset(pkt->side_data, 0, pkt->side_data_elems * sizeof(*pkt->side_data)); ++ for (i = 0; i < pkt->side_data_elems; i++) { ++ DUP_DATA(pkt->side_data[i].data, tmp_pkt.side_data[i].data, ++ pkt->side_data[i].size, 1); ++ } ++ } + } + return 0; ++failed_alloc: ++ av_destruct_packet(pkt); ++ return AVERROR(ENOMEM); + } + + void av_free_packet(AVPacket *pkt) +@@ -113,5 +158,124 @@ + if (pkt) { + if (pkt->destruct) pkt->destruct(pkt); + pkt->data = NULL; pkt->size = 0; ++ pkt->side_data = NULL; ++ pkt->side_data_elems = 0; + } + } ++ ++uint8_t* av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ++ int size) ++{ ++ int elems = pkt->side_data_elems; ++ ++ if ((unsigned)elems + 1 > INT_MAX / sizeof(*pkt->side_data)) ++ return NULL; ++ if ((unsigned)size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) ++ return NULL; ++ ++ pkt->side_data = av_realloc(pkt->side_data, (elems + 1) * sizeof(*pkt->side_data)); ++ if (!pkt->side_data) ++ return NULL; ++ ++ pkt->side_data[elems].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!pkt->side_data[elems].data) ++ return NULL; ++ pkt->side_data[elems].size = size; ++ pkt->side_data[elems].type = type; ++ pkt->side_data_elems++; ++ ++ return pkt->side_data[elems].data; ++} ++ ++uint8_t* av_packet_get_side_data(AVPacket *pkt, enum AVPacketSideDataType type, ++ int *size) ++{ ++ int i; ++ ++ for (i = 0; i < pkt->side_data_elems; i++) { ++ if (pkt->side_data[i].type == type) { ++ if (size) ++ *size = pkt->side_data[i].size; ++ return pkt->side_data[i].data; ++ } ++ } ++ return NULL; ++} ++ ++#define FF_MERGE_MARKER 0x8c4d9d108e25e9feULL ++ ++int av_packet_merge_side_data(AVPacket *pkt){ ++ if(pkt->side_data_elems){ ++ int i; ++ uint8_t *p; ++ uint64_t size= pkt->size + 8LL + FF_INPUT_BUFFER_PADDING_SIZE; ++ AVPacket old= *pkt; ++ for (i=0; i INT_MAX) ++ return AVERROR(EINVAL); ++ p = av_malloc(size); ++ if (!p) ++ return AVERROR(ENOMEM); ++ pkt->data = p; ++ pkt->destruct = av_destruct_packet; ++ pkt->size = size - FF_INPUT_BUFFER_PADDING_SIZE; ++ bytestream_put_buffer(&p, old.data, old.size); ++ for (i=old.side_data_elems-1; i>=0; i--) { ++ bytestream_put_buffer(&p, old.side_data[i].data, old.side_data[i].size); ++ bytestream_put_be32(&p, old.side_data[i].size); ++ *p++ = old.side_data[i].type | ((i==old.side_data_elems-1)*128); ++ } ++ bytestream_put_be64(&p, FF_MERGE_MARKER); ++ av_assert0(p-pkt->data == pkt->size); ++ memset(p, 0, FF_INPUT_BUFFER_PADDING_SIZE); ++ av_free_packet(&old); ++ pkt->side_data_elems = 0; ++ pkt->side_data = NULL; ++ return 1; ++ } ++ return 0; ++} ++ ++int av_packet_split_side_data(AVPacket *pkt){ ++ if (!pkt->side_data_elems && pkt->size >12 && AV_RB64(pkt->data + pkt->size - 8) == FF_MERGE_MARKER){ ++ int i; ++ unsigned int size; ++ uint8_t *p; ++ ++ p = pkt->data + pkt->size - 8 - 5; ++ for (i=1; ; i++){ ++ size = AV_RB32(p); ++ if (size>INT_MAX || p - pkt->data <= size) ++ return 0; ++ if (p[4]&128) ++ break; ++ p-= size+5; ++ } ++ ++ pkt->side_data = av_malloc(i * sizeof(*pkt->side_data)); ++ if (!pkt->side_data) ++ return AVERROR(ENOMEM); ++ ++ p= pkt->data + pkt->size - 8 - 5; ++ for (i=0; ; i++){ ++ size= AV_RB32(p); ++ av_assert0(size<=INT_MAX && p - pkt->data > size); ++ pkt->side_data[i].data = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); ++ pkt->side_data[i].size = size; ++ pkt->side_data[i].type = p[4]&127; ++ if (!pkt->side_data[i].data) ++ return AVERROR(ENOMEM); ++ memcpy(pkt->side_data[i].data, p-size, size); ++ pkt->size -= size + 5; ++ if(p[4]&128) ++ break; ++ p-= size+5; ++ } ++ pkt->size -= 8; ++ pkt->side_data_elems = i+1; ++ return 1; ++ } ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/avs.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/avs.c 2012-05-14 14:08:53.520323600 +0200 +@@ -47,6 +47,7 @@ + void *data, int *data_size, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + int buf_size = avpkt->size; + AvsContext *const avs = avctx->priv_data; + AVFrame *picture = data; +@@ -62,13 +63,15 @@ + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } +- p->reference = 1; +- p->pict_type = FF_P_TYPE; ++ p->reference = 3; ++ p->pict_type = AV_PICTURE_TYPE_P; + p->key_frame = 0; + + out = avs->picture.data[0]; + stride = avs->picture.linesize[0]; + ++ if (buf_end - buf < 4) ++ return AVERROR_INVALIDDATA; + sub_type = buf[0]; + type = buf[1]; + buf += 4; +@@ -79,9 +82,13 @@ + + first = AV_RL16(buf); + last = first + AV_RL16(buf + 2); ++ if (first >= 256 || last > 256 || buf_end - buf < 4 + 4 + 3 * (last - first)) ++ return AVERROR_INVALIDDATA; + buf += 4; +- for (i=first; i> 6) & 0x30303; ++ } + + sub_type = buf[0]; + type = buf[1]; +@@ -93,7 +100,7 @@ + + switch (sub_type) { + case AVS_I_FRAME: +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + case AVS_P_FRAME_3X3: + vect_w = 3; +@@ -114,16 +121,22 @@ + return -1; + } + ++ if (buf_end - buf < 256 * vect_w * vect_h) ++ return AVERROR_INVALIDDATA; + table = buf + (256 * vect_w * vect_h); + if (sub_type != AVS_I_FRAME) { + int map_size = ((318 / vect_w + 7) / 8) * (198 / vect_h); +- init_get_bits(&change_map, table, map_size); ++ if (buf_end - table < map_size) ++ return AVERROR_INVALIDDATA; ++ init_get_bits(&change_map, table, map_size * 8); + table += map_size; + } + + for (y=0; y<198; y+=vect_h) { + for (x=0; x<318; x+=vect_w) { + if (sub_type == AVS_I_FRAME || get_bits1(&change_map)) { ++ if (buf_end - table < 1) ++ return AVERROR_INVALIDDATA; + vect = &buf[*table++ * (vect_w * vect_h)]; + for (j=0; jpriv_data; + avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&avs->picture); + return 0; + } + ++static av_cold int avs_decode_end(AVCodecContext *avctx) ++{ ++ AvsContext *s = avctx->priv_data; ++ if (s->picture.data[0]) ++ avctx->release_buffer(avctx, &s->picture); ++ return 0; ++} ++ ++ + AVCodec ff_avs_decoder = { +- "avs", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_AVS, +- sizeof(AvsContext), +- avs_decode_init, +- NULL, +- NULL, +- avs_decode_frame, +- CODEC_CAP_DR1, ++ .name = "avs", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AVS, ++ .priv_data_size = sizeof(AvsContext), ++ .init = avs_decode_init, ++ .decode = avs_decode_frame, ++ .close = avs_decode_end, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("AVS (Audio Video Standard) video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bethsoftvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bethsoftvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bethsoftvideo.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bethsoftvideo.c 2012-05-14 14:08:53.521323620 +0200 +@@ -23,8 +23,8 @@ + * @file + * @brief Bethesda Softworks VID Video Decoder + * @author Nicholas Tung [ntung (at. ntung com] (2007-03) +- * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID +- * @sa http://www.svatopluk.com/andux/docs/dfvid.html ++ * @see http://wiki.multimedia.cx/index.php?title=Bethsoft_VID ++ * @see http://www.svatopluk.com/andux/docs/dfvid.html + */ + + #include "libavutil/common.h" +@@ -34,34 +34,40 @@ + + typedef struct BethsoftvidContext { + AVFrame frame; ++ GetByteContext g; + } BethsoftvidContext; + + static av_cold int bethsoftvid_decode_init(AVCodecContext *avctx) + { + BethsoftvidContext *vid = avctx->priv_data; +- vid->frame.reference = 1; ++ avcodec_get_frame_defaults(&vid->frame); ++ vid->frame.reference = 3; + vid->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; + } + +-static void set_palette(AVFrame * frame, const uint8_t * palette_buffer) ++static int set_palette(BethsoftvidContext *ctx) + { +- uint32_t * palette = (uint32_t *)frame->data[1]; ++ uint32_t *palette = (uint32_t *)ctx->frame.data[1]; + int a; ++ ++ if (bytestream2_get_bytes_left(&ctx->g) < 256*3) ++ return AVERROR_INVALIDDATA; ++ + for(a = 0; a < 256; a++){ +- palette[a] = AV_RB24(&palette_buffer[a * 3]) * 4; ++ palette[a] = 0xFFU << 24 | bytestream2_get_be24u(&ctx->g) * 4; ++ palette[a] |= palette[a] >> 6 & 0x30303; + } +- frame->palette_has_changed = 1; ++ ctx->frame.palette_has_changed = 1; ++ return 256*3; + } + + static int bethsoftvid_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; + BethsoftvidContext * vid = avctx->priv_data; + char block_type; + uint8_t * dst; +@@ -75,30 +81,32 @@ + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } ++ ++ bytestream2_init(&vid->g, avpkt->data, avpkt->size); + dst = vid->frame.data[0]; + frame_end = vid->frame.data[0] + vid->frame.linesize[0] * avctx->height; + +- switch(block_type = *buf++){ +- case PALETTE_BLOCK: +- set_palette(&vid->frame, buf); +- return 0; ++ switch(block_type = bytestream2_get_byte(&vid->g)){ ++ case PALETTE_BLOCK: { ++ return set_palette(vid); ++ } + case VIDEO_YOFF_P_FRAME: +- yoffset = bytestream_get_le16(&buf); ++ yoffset = bytestream2_get_le16(&vid->g); + if(yoffset >= avctx->height) + return -1; + dst += vid->frame.linesize[0] * yoffset; + } + + // main code +- while((code = *buf++)){ ++ while((code = bytestream2_get_byte(&vid->g))){ + int length = code & 0x7f; + + // copy any bytes starting at the current position, and ending at the frame width + while(length > remaining){ + if(code < 0x80) +- bytestream_get_buffer(&buf, dst, remaining); ++ bytestream2_get_buffer(&vid->g, dst, remaining); + else if(block_type == VIDEO_I_FRAME) +- memset(dst, buf[0], remaining); ++ memset(dst, bytestream2_peek_byte(&vid->g), remaining); + length -= remaining; // decrement the number of bytes to be copied + dst += remaining + wrap_to_next_line; // skip over extra bytes at end of frame + remaining = avctx->width; +@@ -108,9 +116,9 @@ + + // copy any remaining bytes after / if line overflows + if(code < 0x80) +- bytestream_get_buffer(&buf, dst, length); ++ bytestream2_get_buffer(&vid->g, dst, length); + else if(block_type == VIDEO_I_FRAME) +- memset(dst, *buf++, length); ++ memset(dst, bytestream2_get_byte(&vid->g), length); + remaining -= length; + dst += length; + } +@@ -119,7 +127,7 @@ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = vid->frame; + +- return buf_size; ++ return avpkt->size; + } + + static av_cold int bethsoftvid_decode_end(AVCodecContext *avctx) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfi.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfi.c 2012-05-14 14:08:53.522323640 +0200 +@@ -23,7 +23,7 @@ + * @file + * @brief Brute Force & Ignorance (.bfi) video decoder + * @author Sisir Koppaka ( sisir.koppaka at gmail dot com ) +- * @sa http://wiki.multimedia.cx/index.php?title=BFI ++ * @see http://wiki.multimedia.cx/index.php?title=BFI + */ + + #include "libavutil/common.h" +@@ -34,20 +34,22 @@ + AVCodecContext *avctx; + AVFrame frame; + uint8_t *dst; ++ uint32_t pal[256]; + } BFIContext; + +-static av_cold int bfi_decode_init(AVCodecContext * avctx) ++static av_cold int bfi_decode_init(AVCodecContext *avctx) + { + BFIContext *bfi = avctx->priv_data; + avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&bfi->frame); + bfi->dst = av_mallocz(avctx->width * avctx->height); + return 0; + } + +-static int bfi_decode_frame(AVCodecContext * avctx, void *data, ++static int bfi_decode_frame(AVCodecContext *avctx, void *data, + int *data_size, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data, *buf_end = avpkt->data + avpkt->size; ++ GetByteContext g; + int buf_size = avpkt->size; + BFIContext *bfi = avctx->priv_data; + uint8_t *dst = bfi->dst; +@@ -59,78 +61,84 @@ + if (bfi->frame.data[0]) + avctx->release_buffer(avctx, &bfi->frame); + +- bfi->frame.reference = 1; ++ bfi->frame.reference = 3; + + if (avctx->get_buffer(avctx, &bfi->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + ++ bytestream2_init(&g, avpkt->data, buf_size); ++ + /* Set frame parameters and palette, if necessary */ + if (!avctx->frame_number) { +- bfi->frame.pict_type = FF_I_TYPE; ++ bfi->frame.pict_type = AV_PICTURE_TYPE_I; + bfi->frame.key_frame = 1; + /* Setting the palette */ +- if(avctx->extradata_size>768) { ++ if (avctx->extradata_size > 768) { + av_log(NULL, AV_LOG_ERROR, "Palette is too large.\n"); + return -1; + } +- pal = (uint32_t *) bfi->frame.data[1]; ++ pal = (uint32_t *)bfi->frame.data[1]; + for (i = 0; i < avctx->extradata_size / 3; i++) { + int shift = 16; +- *pal = 0; ++ *pal = 0xFF << 24; + for (j = 0; j < 3; j++, shift -= 8) + *pal += + ((avctx->extradata[i * 3 + j] << 2) | + (avctx->extradata[i * 3 + j] >> 4)) << shift; + pal++; + } ++ memcpy(bfi->pal, bfi->frame.data[1], sizeof(bfi->pal)); + bfi->frame.palette_has_changed = 1; + } else { +- bfi->frame.pict_type = FF_P_TYPE; ++ bfi->frame.pict_type = AV_PICTURE_TYPE_P; + bfi->frame.key_frame = 0; ++ bfi->frame.palette_has_changed = 0; ++ memcpy(bfi->frame.data[1], bfi->pal, sizeof(bfi->pal)); + } + +- buf += 4; //Unpacked size, not required. ++ bytestream2_skip(&g, 4); // Unpacked size, not required. + + while (dst != frame_end) { +- static const uint8_t lentab[4]={0,2,0,1}; +- unsigned int byte = *buf++, av_uninit(offset); +- unsigned int code = byte >> 6; ++ static const uint8_t lentab[4] = { 0, 2, 0, 1 }; ++ unsigned int byte = bytestream2_get_byte(&g), av_uninit(offset); ++ unsigned int code = byte >> 6; + unsigned int length = byte & ~0xC0; + +- if (buf >= buf_end) { +- av_log(avctx, AV_LOG_ERROR, "Input resolution larger than actual frame.\n"); ++ if (!bytestream2_get_bytes_left(&g)) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Input resolution larger than actual frame.\n"); + return -1; + } + + /* Get length and offset(if required) */ + if (length == 0) { + if (code == 1) { +- length = bytestream_get_byte(&buf); +- offset = bytestream_get_le16(&buf); ++ length = bytestream2_get_byte(&g); ++ offset = bytestream2_get_le16(&g); + } else { +- length = bytestream_get_le16(&buf); ++ length = bytestream2_get_le16(&g); + if (code == 2 && length == 0) + break; + } + } else { + if (code == 1) +- offset = bytestream_get_byte(&buf); ++ offset = bytestream2_get_byte(&g); + } + + /* Do boundary check */ +- if (dst + (length< frame_end) ++ if (dst + (length << lentab[code]) > frame_end) + break; + + switch (code) { + + case 0: //Normal Chain +- if (length >= buf_end - buf) { ++ if (length >= bytestream2_get_bytes_left(&g)) { + av_log(avctx, AV_LOG_ERROR, "Frame larger than buffer.\n"); + return -1; + } +- bytestream_get_buffer(&buf, dst, length); ++ bytestream2_get_buffer(&g, dst, length); + dst += length; + break; + +@@ -148,8 +156,8 @@ + break; + + case 3: //Fill Chain +- colour1 = bytestream_get_byte(&buf); +- colour2 = bytestream_get_byte(&buf); ++ colour1 = bytestream2_get_byte(&g); ++ colour2 = bytestream2_get_byte(&g); + while (length--) { + *dst++ = colour1; + *dst++ = colour2; +@@ -167,7 +175,7 @@ + dst += bfi->frame.linesize[0]; + } + *data_size = sizeof(AVFrame); +- *(AVFrame *) data = bfi->frame; ++ *(AVFrame *)data = bfi->frame; + return buf_size; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/dsputil_bfin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/dsputil_bfin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/dsputil_bfin.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/dsputil_bfin.c 2012-05-14 14:08:53.523323660 +0200 +@@ -197,11 +197,14 @@ + + void dsputil_init_bfin( DSPContext* c, AVCodecContext *avctx ) + { +- c->get_pixels = ff_bfin_get_pixels; ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ + c->diff_pixels = ff_bfin_diff_pixels; + c->put_pixels_clamped = ff_bfin_put_pixels_clamped; + c->add_pixels_clamped = ff_bfin_add_pixels_clamped; + ++ if (!high_bit_depth) ++ c->get_pixels = ff_bfin_get_pixels; + c->clear_blocks = bfin_clear_blocks; + c->pix_sum = ff_bfin_pix_sum; + c->pix_norm1 = ff_bfin_pix_norm1; +@@ -228,6 +231,7 @@ + c->sse[1] = ff_bfin_sse8; + c->sse[2] = ff_bfin_sse4; + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = bfin_put_pixels16; + c->put_pixels_tab[0][1] = bfin_put_pixels16_x2; + c->put_pixels_tab[0][2] = bfin_put_pixels16_y2; +@@ -247,20 +251,23 @@ + c->put_no_rnd_pixels_tab[0][1] = bfin_put_pixels16_x2_nornd; + c->put_no_rnd_pixels_tab[0][2] = bfin_put_pixels16_y2_nornd; + /* c->put_no_rnd_pixels_tab[0][3] = ff_bfin_put_pixels16_xy2_nornd; */ ++ } + +- if (avctx->dct_algo == FF_DCT_AUTO) +- c->fdct = ff_bfin_fdct; +- +- if (avctx->idct_algo==FF_IDCT_VP3) { +- c->idct_permutation_type = FF_NO_IDCT_PERM; +- c->idct = ff_bfin_vp3_idct; +- c->idct_add = ff_bfin_vp3_idct_add; +- c->idct_put = ff_bfin_vp3_idct_put; +- } else if (avctx->idct_algo == FF_IDCT_AUTO) { +- c->idct_permutation_type = FF_NO_IDCT_PERM; +- c->idct = ff_bfin_idct; +- c->idct_add = bfin_idct_add; +- c->idct_put = bfin_idct_put; ++ if (avctx->bits_per_raw_sample <= 8) { ++ if (avctx->dct_algo == FF_DCT_AUTO) ++ c->fdct = ff_bfin_fdct; ++ ++ if (avctx->idct_algo == FF_IDCT_VP3) { ++ c->idct_permutation_type = FF_NO_IDCT_PERM; ++ c->idct = ff_bfin_vp3_idct; ++ c->idct_add = ff_bfin_vp3_idct_add; ++ c->idct_put = ff_bfin_vp3_idct_put; ++ } else if (avctx->idct_algo == FF_IDCT_AUTO) { ++ c->idct_permutation_type = FF_NO_IDCT_PERM; ++ c->idct = ff_bfin_idct; ++ c->idct_add = bfin_idct_add; ++ c->idct_put = bfin_idct_put; ++ } + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/mathops.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/mathops.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/mathops.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/mathops.h 2012-05-14 14:08:53.524323680 +0200 +@@ -24,7 +24,6 @@ + + #include "config.h" + +-#if CONFIG_MPEGAUDIO_HP + #define MULH(X,Y) ({ int xxo; \ + __asm__ ( \ + "a1 = %2.L * %1.L (FU);\n\t" \ +@@ -34,15 +33,6 @@ + "a1 = a1 >>> 16;\n\t" \ + "%0 = (a0 += a1);\n\t" \ + : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; }) +-#else +-#define MULH(X,Y) ({ int xxo; \ +- __asm__ ( \ +- "a1 = %2.H * %1.L (IS,M);\n\t" \ +- "a0 = %1.H * %2.H, a1+= %1.H * %2.L (IS,M);\n\t"\ +- "a1 = a1 >>> 16;\n\t" \ +- "%0 = (a0 += a1);\n\t" \ +- : "=d" (xxo) : "d" (X), "d" (Y) : "A0","A1"); xxo; }) +-#endif + + /* signed 16x16 -> 32 multiply */ + #define MUL16(a, b) ({ int xxo; \ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bfin/mpegvideo_bfin.c 2012-05-14 14:08:53.524323680 +0200 +@@ -61,8 +61,13 @@ + dc = block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; +- bias = s->q_intra_matrix16[qscale][1]; +- qmat = s->q_intra_matrix16[qscale][0]; ++ if(n<4){ ++ bias = s->q_intra_matrix16[qscale][1]; ++ qmat = s->q_intra_matrix16[qscale][0]; ++ }else{ ++ bias = s->q_chroma_intra_matrix16[qscale][1]; ++ qmat = s->q_chroma_intra_matrix16[qscale][0]; ++ } + + } else { + start_i = 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bgmc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bgmc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bgmc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bgmc.c 2012-05-14 14:08:53.525323700 +0200 +@@ -474,7 +474,8 @@ + av_log(avctx, AV_LOG_ERROR, "Allocating buffer memory failed.\n"); + return AVERROR(ENOMEM); + } else { +- // initialize lut_status buffer to a value never used to compare against ++ // initialize lut_status buffer to a value never used to compare ++ // against + memset(*cf_lut_status, -1, sizeof(*cf_lut_status) * LUT_BUFF); + } + +@@ -494,7 +495,7 @@ + /** Initialize decoding and reads the first value + */ + void ff_bgmc_decode_init(GetBitContext *gb, +- unsigned int *h, unsigned int *l, unsigned int *v) ++ unsigned int *h, unsigned int *l, unsigned int *v) + { + *h = TOP_VALUE; + *l = 0; +@@ -513,9 +514,9 @@ + /** Read and decode a block Gilbert-Moore coded symbol + */ + void ff_bgmc_decode(GetBitContext *gb, unsigned int num, int32_t *dst, +- int delta, unsigned int sx, +- unsigned int *h, unsigned int *l, unsigned int *v, +- uint8_t *cf_lut, int *cf_lut_status) ++ int delta, unsigned int sx, ++ unsigned int *h, unsigned int *l, unsigned int *v, ++ uint8_t *cf_lut, int *cf_lut_status) + { + unsigned int i; + uint8_t *lut = bgmc_lut_getp(cf_lut, cf_lut_status, delta); +@@ -567,4 +568,3 @@ + *l = low; + *v = value; + } +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkaudio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkaudio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkaudio.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkaudio.c 2012-05-14 14:08:53.530323800 +0200 +@@ -1,6 +1,6 @@ + /* + * Bink Audio decoder +- * Copyright (c) 2007-2010 Peter Ross (pross@xvid.org) ++ * Copyright (c) 2007-2011 Peter Ross (pross@xvid.org) + * Copyright (c) 2009 Daniel Verkamp (daniel@drv.nu) + * + * This file is part of FFmpeg. +@@ -29,22 +29,27 @@ + */ + + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "dsputil.h" +-#include "fft.h" ++#include "dct.h" ++#include "rdft.h" + #include "fmtconvert.h" ++#include "libavutil/intfloat.h" + + extern const uint16_t ff_wma_critical_freqs[25]; + ++static float quant_table[96]; ++ + #define MAX_CHANNELS 2 + #define BINK_BLOCK_MAX_SIZE (MAX_CHANNELS << 11) + + typedef struct { +- AVCodecContext *avctx; ++ AVFrame frame; + GetBitContext gb; + DSPContext dsp; + FmtConvertContext fmt_conv; ++ int version_b; ///< Bink version 'b' + int first; + int channels; + int frame_len; ///< transform size (samples) +@@ -53,9 +58,12 @@ + int num_bands; + unsigned int *bands; + float root; +- DECLARE_ALIGNED(16, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE]; +- DECLARE_ALIGNED(16, short, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block ++ DECLARE_ALIGNED(32, FFTSample, coeffs)[BINK_BLOCK_MAX_SIZE]; ++ DECLARE_ALIGNED(16, int16_t, previous)[BINK_BLOCK_MAX_SIZE / 16]; ///< coeffs from previous audio block ++ DECLARE_ALIGNED(16, int16_t, current)[BINK_BLOCK_MAX_SIZE / 16]; + float *coeffs_ptr[MAX_CHANNELS]; ///< pointers to the coeffs arrays for float_to_int16_interleave ++ float *prev_ptr[MAX_CHANNELS]; ///< pointers to the overlap points in the coeffs array ++ uint8_t *packet_buffer; + union { + RDFTContext rdft; + DCTContext dct; +@@ -71,7 +79,6 @@ + int i; + int frame_len_bits; + +- s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + ff_fmt_convert_init(&s->fmt_conv, avctx); + +@@ -83,28 +90,33 @@ + } else { + frame_len_bits = 11; + } +- s->frame_len = 1 << frame_len_bits; + +- if (s->channels > MAX_CHANNELS) { +- av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); ++ if (avctx->channels > MAX_CHANNELS) { ++ av_log(avctx, AV_LOG_ERROR, "too many channels: %d\n", avctx->channels); + return -1; + } + ++ s->version_b = avctx->extradata && avctx->extradata[3] == 'b'; ++ + if (avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) { + // audio is already interleaved for the RDFT format variant + sample_rate *= avctx->channels; +- s->frame_len *= avctx->channels; + s->channels = 1; +- if (avctx->channels == 2) +- frame_len_bits++; ++ if (!s->version_b) ++ frame_len_bits += av_log2(avctx->channels); + } else { + s->channels = avctx->channels; + } + ++ s->frame_len = 1 << frame_len_bits; + s->overlap_len = s->frame_len / 16; + s->block_size = (s->frame_len - s->overlap_len) * s->channels; + sample_rate_half = (sample_rate + 1) / 2; + s->root = 2.0 / sqrt(s->frame_len); ++ for (i = 0; i < 96; i++) { ++ /* constant is result of 0.066399999/log10(M_E) */ ++ quant_table[i] = expf(i * 0.15289164787221953823f) * s->root; ++ } + + /* calculate number of bands */ + for (s->num_bands = 1; s->num_bands < 25; s->num_bands++) +@@ -116,16 +128,18 @@ + return AVERROR(ENOMEM); + + /* populate bands data */ +- s->bands[0] = 1; ++ s->bands[0] = 2; + for (i = 1; i < s->num_bands; i++) +- s->bands[i] = ff_wma_critical_freqs[i - 1] * (s->frame_len / 2) / sample_rate_half; +- s->bands[s->num_bands] = s->frame_len / 2; ++ s->bands[i] = (ff_wma_critical_freqs[i - 1] * s->frame_len / sample_rate_half) & ~1; ++ s->bands[s->num_bands] = s->frame_len; + + s->first = 1; + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + +- for (i = 0; i < s->channels; i++) ++ for (i = 0; i < s->channels; i++) { + s->coeffs_ptr[i] = s->coeffs + i * s->frame_len; ++ s->prev_ptr[i] = s->coeffs_ptr[i] + s->frame_len - s->overlap_len; ++ } + + if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) + ff_rdft_init(&s->trans.rdft, frame_len_bits, DFT_C2R); +@@ -134,6 +148,9 @@ + else + return -1; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -150,11 +167,18 @@ + 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64 + }; + ++#define GET_BITS_SAFE(out, nbits) do { \ ++ if (get_bits_left(gb) < nbits) \ ++ return AVERROR_INVALIDDATA; \ ++ out = get_bits(gb, nbits); \ ++} while (0) ++ + /** + * Decode Bink Audio block + * @param[out] out Output buffer (must contain s->block_size elements) ++ * @return 0 on success, negative error code on failure + */ +-static void decode_block(BinkAudioContext *s, short *out, int use_dct) ++static int decode_block(BinkAudioContext *s, int16_t *out, int use_dct) + { + int ch, i, j, k; + float q, quant[25]; +@@ -166,45 +190,61 @@ + + for (ch = 0; ch < s->channels; ch++) { + FFTSample *coeffs = s->coeffs_ptr[ch]; +- q = 0.0f; +- coeffs[0] = get_float(gb) * s->root; +- coeffs[1] = get_float(gb) * s->root; ++ if (s->version_b) { ++ if (get_bits_left(gb) < 64) ++ return AVERROR_INVALIDDATA; ++ coeffs[0] = av_int2float(get_bits_long(gb, 32)) * s->root; ++ coeffs[1] = av_int2float(get_bits_long(gb, 32)) * s->root; ++ } else { ++ if (get_bits_left(gb) < 58) ++ return AVERROR_INVALIDDATA; ++ coeffs[0] = get_float(gb) * s->root; ++ coeffs[1] = get_float(gb) * s->root; ++ } + ++ if (get_bits_left(gb) < s->num_bands * 8) ++ return AVERROR_INVALIDDATA; + for (i = 0; i < s->num_bands; i++) { +- /* constant is result of 0.066399999/log10(M_E) */ + int value = get_bits(gb, 8); +- quant[i] = expf(FFMIN(value, 95) * 0.15289164787221953823f) * s->root; ++ quant[i] = quant_table[FFMIN(value, 95)]; + } + +- // find band (k) +- for (k = 0; s->bands[k] < 1; k++) { +- q = quant[k]; +- } ++ k = 0; ++ q = quant[0]; + + // parse coefficients + i = 2; + while (i < s->frame_len) { +- if (get_bits1(gb)) { +- j = i + rle_length_tab[get_bits(gb, 4)] * 8; ++ if (s->version_b) { ++ j = i + 16; + } else { +- j = i + 8; ++ int v; ++ GET_BITS_SAFE(v, 1); ++ if (v) { ++ GET_BITS_SAFE(v, 4); ++ j = i + rle_length_tab[v] * 8; ++ } else { ++ j = i + 8; ++ } + } + + j = FFMIN(j, s->frame_len); + +- width = get_bits(gb, 4); ++ GET_BITS_SAFE(width, 4); + if (width == 0) { + memset(coeffs + i, 0, (j - i) * sizeof(*coeffs)); + i = j; +- while (s->bands[k] * 2 < i) ++ while (s->bands[k] < i) + q = quant[k++]; + } else { + while (i < j) { +- if (s->bands[k] * 2 == i) ++ if (s->bands[k] == i) + q = quant[k++]; +- coeff = get_bits(gb, width); ++ GET_BITS_SAFE(coeff, width); + if (coeff) { +- if (get_bits1(gb)) ++ int v; ++ GET_BITS_SAFE(v, 1); ++ if (v) + coeffs[i] = -q * coeff; + else + coeffs[i] = q * coeff; +@@ -218,15 +258,19 @@ + + if (CONFIG_BINKAUDIO_DCT_DECODER && use_dct) { + coeffs[0] /= 0.5; +- ff_dct_calc (&s->trans.dct, coeffs); ++ s->trans.dct.dct_calc(&s->trans.dct, coeffs); + s->dsp.vector_fmul_scalar(coeffs, coeffs, s->frame_len / 2, s->frame_len); + } + else if (CONFIG_BINKAUDIO_RDFT_DECODER) +- ff_rdft_calc(&s->trans.rdft, coeffs); ++ s->trans.rdft.rdft_calc(&s->trans.rdft, coeffs); + } + ++ s->fmt_conv.float_to_int16_interleave(s->current, ++ (const float **)s->prev_ptr, ++ s->overlap_len, s->channels); + s->fmt_conv.float_to_int16_interleave(out, (const float **)s->coeffs_ptr, +- s->frame_len, s->channels); ++ s->frame_len - s->overlap_len, ++ s->channels); + + if (!s->first) { + int count = s->overlap_len * s->channels; +@@ -236,20 +280,24 @@ + } + } + +- memcpy(s->previous, out + s->block_size, +- s->overlap_len * s->channels * sizeof(*out)); ++ memcpy(s->previous, s->current, ++ s->overlap_len * s->channels * sizeof(*s->previous)); + + s->first = 0; ++ ++ return 0; + } + + static av_cold int decode_end(AVCodecContext *avctx) + { + BinkAudioContext * s = avctx->priv_data; + av_freep(&s->bands); ++ av_freep(&s->packet_buffer); + if (CONFIG_BINKAUDIO_RDFT_DECODER && avctx->codec->id == CODEC_ID_BINKAUDIO_RDFT) + ff_rdft_end(&s->trans.rdft); + else if (CONFIG_BINKAUDIO_DCT_DECODER) + ff_dct_end(&s->trans.dct); ++ + return 0; + } + +@@ -259,52 +307,77 @@ + if (n) skip_bits(s, n); + } + +-static int decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + BinkAudioContext *s = avctx->priv_data; +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- short *samples = data; +- short *samples_end = (short*)((uint8_t*)data + *data_size); +- int reported_size; ++ int16_t *samples; + GetBitContext *gb = &s->gb; ++ int ret, consumed = 0; + +- init_get_bits(gb, buf, buf_size * 8); ++ if (!get_bits_left(gb)) { ++ uint8_t *buf; ++ /* handle end-of-stream */ ++ if (!avpkt->size) { ++ *got_frame_ptr = 0; ++ return 0; ++ } ++ if (avpkt->size < 4) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ buf = av_realloc(s->packet_buffer, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!buf) ++ return AVERROR(ENOMEM); ++ s->packet_buffer = buf; ++ memcpy(s->packet_buffer, avpkt->data, avpkt->size); ++ init_get_bits(gb, s->packet_buffer, avpkt->size * 8); ++ consumed = avpkt->size; + +- reported_size = get_bits_long(gb, 32); +- while (get_bits_count(gb) / 8 < buf_size && +- samples + s->block_size <= samples_end) { +- decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT); +- samples += s->block_size; +- get_bits_align32(gb); ++ /* skip reported size */ ++ skip_bits_long(gb, 32); + } + +- *data_size = FFMIN(reported_size, (uint8_t*)samples - (uint8_t*)data); +- return buf_size; ++ /* get output buffer */ ++ s->frame.nb_samples = s->block_size / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)s->frame.data[0]; ++ ++ if (decode_block(s, samples, avctx->codec->id == CODEC_ID_BINKAUDIO_DCT)) { ++ av_log(avctx, AV_LOG_ERROR, "Incomplete packet\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ get_bits_align32(gb); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return consumed; + } + + AVCodec ff_binkaudio_rdft_decoder = { +- "binkaudio_rdft", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_BINKAUDIO_RDFT, +- sizeof(BinkAudioContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, ++ .name = "binkaudio_rdft", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_BINKAUDIO_RDFT, ++ .priv_data_size = sizeof(BinkAudioContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (RDFT)") + }; + + AVCodec ff_binkaudio_dct_decoder = { +- "binkaudio_dct", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_BINKAUDIO_DCT, +- sizeof(BinkAudioContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, ++ .name = "binkaudio_dct", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_BINKAUDIO_DCT, ++ .priv_data_size = sizeof(BinkAudioContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Bink Audio (DCT)") + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bink.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bink.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bink.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bink.c 2012-05-14 14:08:53.528323760 +0200 +@@ -1,6 +1,7 @@ + /* + * Bink video decoder + * Copyright (c) 2009 Konstantin Shishkov ++ * Copyright (C) 2011 Peter Ross + * + * This file is part of FFmpeg. + * +@@ -19,13 +20,14 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "dsputil.h" + #include "binkdata.h" ++#include "binkdsp.h" + #include "mathops.h" + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + #define BINK_FLAG_ALPHA 0x00100000 +@@ -34,6 +36,35 @@ + static VLC bink_trees[16]; + + /** ++ * IDs for different data types used in old version of Bink video codec ++ */ ++enum OldSources { ++ BINKB_SRC_BLOCK_TYPES = 0, ///< 8x8 block types ++ BINKB_SRC_COLORS, ///< pixel values used for different block types ++ BINKB_SRC_PATTERN, ///< 8-bit values for 2-colour pattern fill ++ BINKB_SRC_X_OFF, ///< X components of motion value ++ BINKB_SRC_Y_OFF, ///< Y components of motion value ++ BINKB_SRC_INTRA_DC, ///< DC values for intrablocks with DCT ++ BINKB_SRC_INTER_DC, ///< DC values for interblocks with DCT ++ BINKB_SRC_INTRA_Q, ///< quantizer values for intrablocks with DCT ++ BINKB_SRC_INTER_Q, ///< quantizer values for interblocks with DCT ++ BINKB_SRC_INTER_COEFS, ///< number of coefficients for residue blocks ++ ++ BINKB_NB_SRC ++}; ++ ++static const int binkb_bundle_sizes[BINKB_NB_SRC] = { ++ 4, 8, 8, 5, 5, 11, 11, 4, 4, 7 ++}; ++ ++static const int binkb_bundle_signed[BINKB_NB_SRC] = { ++ 0, 0, 0, 1, 1, 0, 1, 0, 0, 0 ++}; ++ ++static int32_t binkb_intra_quant[16][64]; ++static int32_t binkb_inter_quant[16][64]; ++ ++/** + * IDs for different data types used in Bink video codec + */ + enum Sources { +@@ -79,13 +110,13 @@ + typedef struct BinkContext { + AVCodecContext *avctx; + DSPContext dsp; ++ BinkDSPContext bdsp; + AVFrame pic, last; + int version; ///< internal Bink file version + int has_alpha; + int swap_planes; +- ScanTable scantable; ///< permutated scantable for DCT coeffs decoding + +- Bundle bundle[BINK_NB_SRC]; ///< bundles for decoding all data types ++ Bundle bundle[BINKB_NB_SRC]; ///< bundles for decoding all data types + Tree col_high[16]; ///< trees for decoding high nibble in "colours" data type + int col_lastval; ///< value of last decoded high nibble in "colours" data type + } BinkContext; +@@ -145,7 +176,7 @@ + bh = (c->avctx->height + 7) >> 3; + blocks = bw * bh; + +- for (i = 0; i < BINK_NB_SRC; i++) { ++ for (i = 0; i < BINKB_NB_SRC; i++) { + c->bundle[i].data = av_malloc(blocks * 64); + c->bundle[i].data_end = c->bundle[i].data + blocks * 64; + } +@@ -159,7 +190,7 @@ + static av_cold void free_bundles(BinkContext *c) + { + int i; +- for (i = 0; i < BINK_NB_SRC; i++) ++ for (i = 0; i < BINKB_NB_SRC; i++) + av_freep(&c->bundle[i].data); + } + +@@ -216,7 +247,7 @@ + tree->syms[i] = get_bits(gb, 4); + tmp1[tree->syms[i]] = 1; + } +- for (i = 0; i < 16; i++) ++ for (i = 0; i < 16 && len < 16 - 1; i++) + if (!tmp1[i]) + tree->syms[++len] = i; + } else { +@@ -313,14 +344,14 @@ + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { +- do { ++ while (b->cur_dec < dec_end) { + v = GET_HUFF(gb, b->tree); + if (v) { + sign = -get_bits1(gb); + v = (v ^ sign) - sign; + } + *b->cur_dec++ = v; +- } while (b->cur_dec < dec_end); ++ } + } + return 0; + } +@@ -344,7 +375,7 @@ + memset(b->cur_dec, v, t); + b->cur_dec += t; + } else { +- do { ++ while (b->cur_dec < dec_end) { + v = GET_HUFF(gb, b->tree); + if (v < 12) { + last = v; +@@ -352,10 +383,12 @@ + } else { + int run = bink_rlelens[v - 12]; + ++ if (dec_end - b->cur_dec < run) ++ return -1; + memset(b->cur_dec, last, run); + b->cur_dec += run; + } +- } while (b->cur_dec < dec_end); ++ } + } + return 0; + } +@@ -425,7 +458,8 @@ + int start_bits, int has_sign) + { + int i, j, len, len2, bsize, sign, v, v2; +- int16_t *dst = (int16_t*)b->cur_dec; ++ int16_t *dst = (int16_t*)b->cur_dec; ++ int16_t *dst_end = (int16_t*)b->data_end; + + CHECK_READ_VAL(gb, b, len); + v = get_bits(gb, start_bits - has_sign); +@@ -433,10 +467,14 @@ + sign = -get_bits1(gb); + v = (v ^ sign) - sign; + } ++ if (dst_end - dst < 1) ++ return -1; + *dst++ = v; + len--; + for (i = 0; i < len; i += 8) { + len2 = FFMIN(len - i, 8); ++ if (dst_end - dst < len2) ++ return -1; + bsize = get_bits(gb, 4); + if (bsize) { + for (j = 0; j < len2; j++) { +@@ -470,7 +508,7 @@ + */ + static inline int get_value(BinkContext *c, int bundle) + { +- int16_t ret; ++ int ret; + + if (bundle < BINK_SRC_X_OFF || bundle == BINK_SRC_RUN) + return *c->bundle[bundle].cur_ptr++; +@@ -481,26 +519,88 @@ + return ret; + } + ++static void binkb_init_bundle(BinkContext *c, int bundle_num) ++{ ++ c->bundle[bundle_num].cur_dec = ++ c->bundle[bundle_num].cur_ptr = c->bundle[bundle_num].data; ++ c->bundle[bundle_num].len = 13; ++} ++ ++static void binkb_init_bundles(BinkContext *c) ++{ ++ int i; ++ for (i = 0; i < BINKB_NB_SRC; i++) ++ binkb_init_bundle(c, i); ++} ++ ++static int binkb_read_bundle(BinkContext *c, GetBitContext *gb, int bundle_num) ++{ ++ const int bits = binkb_bundle_sizes[bundle_num]; ++ const int mask = 1 << (bits - 1); ++ const int issigned = binkb_bundle_signed[bundle_num]; ++ Bundle *b = &c->bundle[bundle_num]; ++ int i, len; ++ ++ CHECK_READ_VAL(gb, b, len); ++ if (b->data_end - b->cur_dec < len * (1 + (bits > 8))) ++ return -1; ++ if (bits <= 8) { ++ if (!issigned) { ++ for (i = 0; i < len; i++) ++ *b->cur_dec++ = get_bits(gb, bits); ++ } else { ++ for (i = 0; i < len; i++) ++ *b->cur_dec++ = get_bits(gb, bits) - mask; ++ } ++ } else { ++ int16_t *dst = (int16_t*)b->cur_dec; ++ ++ if (!issigned) { ++ for (i = 0; i < len; i++) ++ *dst++ = get_bits(gb, bits); ++ } else { ++ for (i = 0; i < len; i++) ++ *dst++ = get_bits(gb, bits) - mask; ++ } ++ b->cur_dec = (uint8_t*)dst; ++ } ++ return 0; ++} ++ ++static inline int binkb_get_value(BinkContext *c, int bundle_num) ++{ ++ int16_t ret; ++ const int bits = binkb_bundle_sizes[bundle_num]; ++ ++ if (bits <= 8) { ++ int val = *c->bundle[bundle_num].cur_ptr++; ++ return binkb_bundle_signed[bundle_num] ? (int8_t)val : val; ++ } ++ ret = *(int16_t*)c->bundle[bundle_num].cur_ptr; ++ c->bundle[bundle_num].cur_ptr += 2; ++ return ret; ++} ++ + /** + * Read 8x8 block of DCT coefficients. + * + * @param gb context for reading bits + * @param block place for storing coefficients + * @param scan scan order table +- * @param is_intra tells what set of quantizer matrices to use ++ * @param quant_matrices quantization matrices + * @return 0 for success, negative value in other cases + */ +-static int read_dct_coeffs(GetBitContext *gb, DCTELEM block[64], const uint8_t *scan, +- int is_intra) ++static int read_dct_coeffs(GetBitContext *gb, int32_t block[64], const uint8_t *scan, ++ const int32_t quant_matrices[16][64], int q) + { + int coef_list[128]; + int mode_list[128]; +- int i, t, mask, bits, ccoef, mode, sign; ++ int i, t, bits, ccoef, mode, sign; + int list_start = 64, list_end = 64, list_pos; + int coef_count = 0; + int coef_idx[64]; + int quant_idx; +- const uint32_t *quant; ++ const int32_t *quant; + + coef_list[list_end] = 4; mode_list[list_end++] = 0; + coef_list[list_end] = 24; mode_list[list_end++] = 0; +@@ -509,8 +609,7 @@ + coef_list[list_end] = 2; mode_list[list_end++] = 3; + coef_list[list_end] = 3; mode_list[list_end++] = 3; + +- bits = get_bits(gb, 4) - 1; +- for (mask = 1 << bits; bits >= 0; mask >>= 1, bits--) { ++ for (bits = get_bits(gb, 4) - 1; bits >= 0; bits--) { + list_pos = list_start; + while (list_pos < list_end) { + if (!(mode_list[list_pos] | coef_list[list_pos]) || !get_bits1(gb)) { +@@ -533,11 +632,10 @@ + coef_list[--list_start] = ccoef; + mode_list[ list_start] = 3; + } else { +- int t; + if (!bits) { + t = 1 - (get_bits1(gb) << 1); + } else { +- t = get_bits(gb, bits) | mask; ++ t = get_bits(gb, bits) | 1 << bits; + sign = -get_bits1(gb); + t = (t ^ sign) - sign; + } +@@ -558,7 +656,7 @@ + if (!bits) { + t = 1 - (get_bits1(gb) << 1); + } else { +- t = get_bits(gb, bits) | mask; ++ t = get_bits(gb, bits) | 1 << bits; + sign = -get_bits1(gb); + t = (t ^ sign) - sign; + } +@@ -571,9 +669,14 @@ + } + } + +- quant_idx = get_bits(gb, 4); +- quant = is_intra ? bink_intra_quant[quant_idx] +- : bink_inter_quant[quant_idx]; ++ if (q == -1) { ++ quant_idx = get_bits(gb, 4); ++ } else { ++ quant_idx = q; ++ } ++ ++ quant = quant_matrices[quant_idx]; ++ + block[0] = (block[0] * quant[0]) >> 11; + for (i = 0; i < coef_count; i++) { + int idx = coef_idx[i]; +@@ -673,6 +776,165 @@ + return 0; + } + ++/** ++ * Copy 8x8 block from source to destination, where src and dst may be overlapped ++ */ ++static inline void put_pixels8x8_overlapped(uint8_t *dst, uint8_t *src, int stride) ++{ ++ uint8_t tmp[64]; ++ int i; ++ for (i = 0; i < 8; i++) ++ memcpy(tmp + i*8, src + i*stride, 8); ++ for (i = 0; i < 8; i++) ++ memcpy(dst + i*stride, tmp + i*8, 8); ++} ++ ++static int binkb_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, ++ int is_key, int is_chroma) ++{ ++ int blk; ++ int i, j, bx, by; ++ uint8_t *dst, *ref, *ref_start, *ref_end; ++ int v, col[2]; ++ const uint8_t *scan; ++ int xoff, yoff; ++ LOCAL_ALIGNED_16(DCTELEM, block, [64]); ++ LOCAL_ALIGNED_16(int32_t, dctblock, [64]); ++ int coordmap[64]; ++ int ybias = is_key ? -15 : 0; ++ int qp; ++ ++ const int stride = c->pic.linesize[plane_idx]; ++ int bw = is_chroma ? (c->avctx->width + 15) >> 4 : (c->avctx->width + 7) >> 3; ++ int bh = is_chroma ? (c->avctx->height + 15) >> 4 : (c->avctx->height + 7) >> 3; ++ ++ binkb_init_bundles(c); ++ ref_start = c->pic.data[plane_idx]; ++ ref_end = c->pic.data[plane_idx] + (bh * c->pic.linesize[plane_idx] + bw) * 8; ++ ++ for (i = 0; i < 64; i++) ++ coordmap[i] = (i & 7) + (i >> 3) * stride; ++ ++ for (by = 0; by < bh; by++) { ++ for (i = 0; i < BINKB_NB_SRC; i++) { ++ if (binkb_read_bundle(c, gb, i) < 0) ++ return -1; ++ } ++ ++ dst = c->pic.data[plane_idx] + 8*by*stride; ++ for (bx = 0; bx < bw; bx++, dst += 8) { ++ blk = binkb_get_value(c, BINKB_SRC_BLOCK_TYPES); ++ switch (blk) { ++ case 0: ++ break; ++ case 1: ++ scan = bink_patterns[get_bits(gb, 4)]; ++ i = 0; ++ do { ++ int mode, run; ++ ++ mode = get_bits1(gb); ++ run = get_bits(gb, binkb_runbits[i]) + 1; ++ ++ i += run; ++ if (i > 64) { ++ av_log(c->avctx, AV_LOG_ERROR, "Run went out of bounds\n"); ++ return -1; ++ } ++ if (mode) { ++ v = binkb_get_value(c, BINKB_SRC_COLORS); ++ for (j = 0; j < run; j++) ++ dst[coordmap[*scan++]] = v; ++ } else { ++ for (j = 0; j < run; j++) ++ dst[coordmap[*scan++]] = binkb_get_value(c, BINKB_SRC_COLORS); ++ } ++ } while (i < 63); ++ if (i == 63) ++ dst[coordmap[*scan++]] = binkb_get_value(c, BINKB_SRC_COLORS); ++ break; ++ case 2: ++ memset(dctblock, 0, sizeof(*dctblock) * 64); ++ dctblock[0] = binkb_get_value(c, BINKB_SRC_INTRA_DC); ++ qp = binkb_get_value(c, BINKB_SRC_INTRA_Q); ++ read_dct_coeffs(gb, dctblock, bink_scan, binkb_intra_quant, qp); ++ c->bdsp.idct_put(dst, stride, dctblock); ++ break; ++ case 3: ++ xoff = binkb_get_value(c, BINKB_SRC_X_OFF); ++ yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias; ++ ref = dst + xoff + yoff * stride; ++ if (ref < ref_start || ref + 8*stride > ref_end) { ++ av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n"); ++ } else if (ref + 8*stride < dst || ref >= dst + 8*stride) { ++ c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); ++ } else { ++ put_pixels8x8_overlapped(dst, ref, stride); ++ } ++ c->dsp.clear_block(block); ++ v = binkb_get_value(c, BINKB_SRC_INTER_COEFS); ++ read_residue(gb, block, v); ++ c->dsp.add_pixels8(dst, block, stride); ++ break; ++ case 4: ++ xoff = binkb_get_value(c, BINKB_SRC_X_OFF); ++ yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias; ++ ref = dst + xoff + yoff * stride; ++ if (ref < ref_start || ref + 8 * stride > ref_end) { ++ av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n"); ++ } else if (ref + 8*stride < dst || ref >= dst + 8*stride) { ++ c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); ++ } else { ++ put_pixels8x8_overlapped(dst, ref, stride); ++ } ++ memset(dctblock, 0, sizeof(*dctblock) * 64); ++ dctblock[0] = binkb_get_value(c, BINKB_SRC_INTER_DC); ++ qp = binkb_get_value(c, BINKB_SRC_INTER_Q); ++ read_dct_coeffs(gb, dctblock, bink_scan, binkb_inter_quant, qp); ++ c->bdsp.idct_add(dst, stride, dctblock); ++ break; ++ case 5: ++ v = binkb_get_value(c, BINKB_SRC_COLORS); ++ c->dsp.fill_block_tab[1](dst, v, stride, 8); ++ break; ++ case 6: ++ for (i = 0; i < 2; i++) ++ col[i] = binkb_get_value(c, BINKB_SRC_COLORS); ++ for (i = 0; i < 8; i++) { ++ v = binkb_get_value(c, BINKB_SRC_PATTERN); ++ for (j = 0; j < 8; j++, v >>= 1) ++ dst[i*stride + j] = col[v & 1]; ++ } ++ break; ++ case 7: ++ xoff = binkb_get_value(c, BINKB_SRC_X_OFF); ++ yoff = binkb_get_value(c, BINKB_SRC_Y_OFF) + ybias; ++ ref = dst + xoff + yoff * stride; ++ if (ref < ref_start || ref + 8 * stride > ref_end) { ++ av_log(c->avctx, AV_LOG_WARNING, "Reference block is out of bounds\n"); ++ } else if (ref + 8*stride < dst || ref >= dst + 8*stride) { ++ c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); ++ } else { ++ put_pixels8x8_overlapped(dst, ref, stride); ++ } ++ break; ++ case 8: ++ for (i = 0; i < 8; i++) ++ memcpy(dst + i*stride, c->bundle[BINKB_SRC_COLORS].cur_ptr + i*8, 8); ++ c->bundle[BINKB_SRC_COLORS].cur_ptr += 64; ++ break; ++ default: ++ av_log(c->avctx, AV_LOG_ERROR, "Unknown block type %d\n", blk); ++ return -1; ++ } ++ } ++ } ++ if (get_bits_count(gb) & 0x1F) //next plane data starts at 32-bit boundary ++ skip_bits_long(gb, 32 - (get_bits_count(gb) & 0x1F)); ++ ++ return 0; ++} ++ + static int bink_decode_plane(BinkContext *c, GetBitContext *gb, int plane_idx, + int is_chroma) + { +@@ -684,6 +946,7 @@ + int xoff, yoff; + LOCAL_ALIGNED_16(DCTELEM, block, [64]); + LOCAL_ALIGNED_16(uint8_t, ublock, [64]); ++ LOCAL_ALIGNED_16(int32_t, dctblock, [64]); + int coordmap[64]; + + const int stride = c->pic.linesize[plane_idx]; +@@ -695,8 +958,9 @@ + for (i = 0; i < BINK_NB_SRC; i++) + read_bundle(gb, c, i); + +- ref_start = c->last.data[plane_idx]; +- ref_end = c->last.data[plane_idx] ++ ref_start = c->last.data[plane_idx] ? c->last.data[plane_idx] ++ : c->pic.data[plane_idx]; ++ ref_end = ref_start + + (bw - 1 + c->last.linesize[plane_idx] * (bh - 1)) * 8; + + for (i = 0; i < 64; i++) +@@ -725,7 +989,8 @@ + if (by == bh) + break; + dst = c->pic.data[plane_idx] + 8*by*stride; +- prev = c->last.data[plane_idx] + 8*by*stride; ++ prev = (c->last.data[plane_idx] ? c->last.data[plane_idx] ++ : c->pic.data[plane_idx]) + 8*by*stride; + for (bx = 0; bx < bw; bx++, dst += 8, prev += 8) { + blk = get_value(c, BINK_SRC_BLOCK_TYPES); + // 16x16 block type on odd line means part of the already decoded block, so skip it +@@ -766,11 +1031,10 @@ + ublock[*scan++] = get_value(c, BINK_SRC_COLORS); + break; + case INTRA_BLOCK: +- c->dsp.clear_block(block); +- block[0] = get_value(c, BINK_SRC_INTRA_DC); +- read_dct_coeffs(gb, block, c->scantable.permutated, 1); +- c->dsp.idct(block); +- c->dsp.put_pixels_nonclamped(block, ublock, 8); ++ memset(dctblock, 0, sizeof(*dctblock) * 64); ++ dctblock[0] = get_value(c, BINK_SRC_INTRA_DC); ++ read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1); ++ c->bdsp.idct_put(ublock, 8, dctblock); + break; + case FILL_BLOCK: + v = get_value(c, BINK_SRC_COLORS); +@@ -795,7 +1059,7 @@ + return -1; + } + if (blk != FILL_BLOCK) +- c->dsp.scale_block(ublock, dst, stride); ++ c->bdsp.scale_block(ublock, dst, stride); + bx++; + dst += 8; + prev += 8; +@@ -850,10 +1114,10 @@ + c->dsp.add_pixels8(dst, block, stride); + break; + case INTRA_BLOCK: +- c->dsp.clear_block(block); +- block[0] = get_value(c, BINK_SRC_INTRA_DC); +- read_dct_coeffs(gb, block, c->scantable.permutated, 1); +- c->dsp.idct_put(dst, stride, block); ++ memset(dctblock, 0, sizeof(*dctblock) * 64); ++ dctblock[0] = get_value(c, BINK_SRC_INTRA_DC); ++ read_dct_coeffs(gb, dctblock, bink_scan, bink_intra_quant, -1); ++ c->bdsp.idct_put(dst, stride, dctblock); + break; + case FILL_BLOCK: + v = get_value(c, BINK_SRC_COLORS); +@@ -864,10 +1128,10 @@ + yoff = get_value(c, BINK_SRC_Y_OFF); + ref = prev + xoff + yoff * stride; + c->dsp.put_pixels_tab[1][0](dst, ref, stride, 8); +- c->dsp.clear_block(block); +- block[0] = get_value(c, BINK_SRC_INTER_DC); +- read_dct_coeffs(gb, block, c->scantable.permutated, 0); +- c->dsp.idct_add(dst, stride, block); ++ memset(dctblock, 0, sizeof(*dctblock) * 64); ++ dctblock[0] = get_value(c, BINK_SRC_INTER_DC); ++ read_dct_coeffs(gb, dctblock, bink_scan, bink_inter_quant, -1); ++ c->bdsp.idct_add(dst, stride, dctblock); + break; + case PATTERN_BLOCK: + for (i = 0; i < 2; i++) +@@ -902,12 +1166,19 @@ + int plane, plane_idx; + int bits_count = pkt->size << 3; + +- if(c->pic.data[0]) +- avctx->release_buffer(avctx, &c->pic); ++ if (c->version > 'b') { ++ if(c->pic.data[0]) ++ avctx->release_buffer(avctx, &c->pic); + +- if(avctx->get_buffer(avctx, &c->pic) < 0){ +- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; ++ if(avctx->get_buffer(avctx, &c->pic) < 0){ ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ } else { ++ if(avctx->reget_buffer(avctx, &c->pic) < 0){ ++ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); ++ return -1; ++ } + } + + init_get_bits(&gb, pkt->data, bits_count); +@@ -923,8 +1194,13 @@ + for (plane = 0; plane < 3; plane++) { + plane_idx = (!plane || !c->swap_planes) ? plane : (plane ^ 3); + +- if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) +- return -1; ++ if (c->version > 'b') { ++ if (bink_decode_plane(c, &gb, plane_idx, !!plane) < 0) ++ return -1; ++ } else { ++ if (binkb_decode_plane(c, &gb, plane_idx, !pkt->pts, !!plane) < 0) ++ return -1; ++ } + if (get_bits_count(&gb) >= bits_count) + break; + } +@@ -933,24 +1209,67 @@ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; + +- FFSWAP(AVFrame, c->pic, c->last); ++ if (c->version > 'b') ++ FFSWAP(AVFrame, c->pic, c->last); + + /* always report that the buffer was completely consumed */ + return pkt->size; + } + ++/** ++ * Caclulate quantization tables for version b ++ */ ++static av_cold void binkb_calc_quant(void) ++{ ++ uint8_t inv_bink_scan[64]; ++ double s[64]; ++ int i, j; ++ ++ for (j = 0; j < 8; j++) { ++ for (i = 0; i < 8; i++) { ++ if (j && j != 4) ++ if (i && i != 4) ++ s[j*8 + i] = cos(j * M_PI/16.0) * cos(i * M_PI/16.0) * 2.0; ++ else ++ s[j*8 + i] = cos(j * M_PI/16.0) * sqrt(2.0); ++ else ++ if (i && i != 4) ++ s[j*8 + i] = cos(i * M_PI/16.0) * sqrt(2.0); ++ else ++ s[j*8 + i] = 1.0; ++ } ++ } ++ ++ for (i = 0; i < 64; i++) ++ inv_bink_scan[bink_scan[i]] = i; ++ ++ for (j = 0; j < 16; j++) { ++ for (i = 0; i < 64; i++) { ++ int k = inv_bink_scan[i]; ++ if (s[i] == 1.0) { ++ binkb_intra_quant[j][k] = (1L << 12) * binkb_intra_seed[i] * ++ binkb_num[j]/binkb_den[j]; ++ binkb_inter_quant[j][k] = (1L << 12) * binkb_inter_seed[i] * ++ binkb_num[j]/binkb_den[j]; ++ } else { ++ binkb_intra_quant[j][k] = (1L << 12) * binkb_intra_seed[i] * s[i] * ++ binkb_num[j]/(double)binkb_den[j]; ++ binkb_inter_quant[j][k] = (1L << 12) * binkb_inter_seed[i] * s[i] * ++ binkb_num[j]/(double)binkb_den[j]; ++ } ++ } ++ } ++} ++ + static av_cold int decode_init(AVCodecContext *avctx) + { + BinkContext * const c = avctx->priv_data; + static VLC_TYPE table[16 * 128][2]; ++ static int binkb_initialised = 0; + int i; + int flags; + + c->version = avctx->codec_tag >> 24; +- if (c->version < 'c') { +- av_log(avctx, AV_LOG_ERROR, "Too old version '%c'\n", c->version); +- return -1; +- } + if (avctx->extradata_size < 4) { + av_log(avctx, AV_LOG_ERROR, "Extradata missing or too short\n"); + return -1; +@@ -980,10 +1299,17 @@ + + avctx->idct_algo = FF_IDCT_BINK; + dsputil_init(&c->dsp, avctx); +- ff_init_scantable(c->dsp.idct_permutation, &c->scantable, bink_scan); ++ ff_binkdsp_init(&c->bdsp); + + init_bundles(c); + ++ if (c->version == 'b') { ++ if (!binkb_initialised) { ++ binkb_calc_quant(); ++ binkb_initialised = 1; ++ } ++ } ++ + return 0; + } + +@@ -1001,13 +1327,12 @@ + } + + AVCodec ff_bink_decoder = { +- "binkvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_BINKVIDEO, +- sizeof(BinkContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, ++ .name = "binkvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_BINKVIDEO, ++ .priv_data_size = sizeof(BinkContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Bink video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdata.h 2012-05-14 14:08:53.531323820 +0200 +@@ -285,7 +285,7 @@ + } + }; + +-static const uint32_t bink_intra_quant[16][64] = { ++static const int32_t bink_intra_quant[16][64] = { + { + 0x010000, 0x016315, 0x01E83D, 0x02A535, 0x014E7B, 0x016577, 0x02F1E6, 0x02724C, + 0x010000, 0x00EEDA, 0x024102, 0x017F9B, 0x00BE80, 0x00611E, 0x01083C, 0x00A552, +@@ -448,7 +448,7 @@ + }, + }; + +-static const uint32_t bink_inter_quant[16][64] = { ++static const int32_t bink_inter_quant[16][64] = { + { + 0x010000, 0x017946, 0x01A5A9, 0x0248DC, 0x016363, 0x0152A7, 0x0243EC, 0x0209EA, + 0x012000, 0x00E248, 0x01BBDA, 0x015CBC, 0x00A486, 0x0053E0, 0x00F036, 0x008095, +@@ -611,4 +611,45 @@ + }, + }; + ++static const uint8_t binkb_runbits[64] = { ++ 6, 6, 6, 6, 6, 6, 6, 6, ++ 6, 6, 6, 6, 6, 6, 6, 6, ++ 6, 6, 6, 6, 6, 6, 6, 6, ++ 6, 6, 6, 6, 6, 6, 6, 6, ++ 5, 5, 5, 5, 5, 5, 5, 5, ++ 5, 5, 5, 5, 5, 5, 5, 5, ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 3, 3, 3, 3, 2, 2, 1, 0, ++}; ++ ++static const uint8_t binkb_intra_seed[64] = { ++ 16, 16, 16, 19, 16, 19, 22, 22, ++ 22, 22, 26, 24, 26, 22, 22, 27, ++ 27, 27, 26, 26, 26, 29, 29, 29, ++ 27, 27, 27, 26, 34, 34, 34, 29, ++ 29, 29, 27, 27, 37, 34, 34, 32, ++ 32, 29, 29, 38, 37, 35, 35, 34, ++ 35, 40, 40, 40, 38, 38, 48, 48, ++ 46, 46, 58, 56, 56, 69, 69, 83, ++}; ++ ++static const uint8_t binkb_inter_seed[64] = { ++ 16, 17, 17, 18, 18, 18, 19, 19, ++ 19, 19, 20, 20, 20, 20, 20, 21, ++ 21, 21, 21, 21, 21, 22, 22, 22, ++ 22, 22, 22, 22, 23, 23, 23, 23, ++ 23, 23, 23, 23, 24, 24, 24, 25, ++ 24, 24, 24, 25, 26, 26, 26, 26, ++ 25, 27, 27, 27, 27, 27, 28, 28, ++ 28, 28, 30, 30, 30, 31, 31, 33, ++}; ++ ++static const uint8_t binkb_num[16] = { ++ 1, 4, 5, 2, 7, 8, 3, 7, 4, 9, 5, 6, 7, 8, 9, 10 ++}; ++ ++static const uint8_t binkb_den[16] = { ++ 1, 3, 3, 1, 3, 3, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1 ++}; ++ + #endif /* AVCODEC_BINKDATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdsp.c 2012-05-14 14:08:53.532323840 +0200 +@@ -0,0 +1,136 @@ ++/* ++ * Bink DSP routines ++ * Copyright (c) 2009 Kostya Shishkov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Bink DSP routines ++ */ ++ ++#include "dsputil.h" ++#include "binkdsp.h" ++ ++#define A1 2896 /* (1/sqrt(2))<<12 */ ++#define A2 2217 ++#define A3 3784 ++#define A4 -5352 ++ ++#define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ ++ const int a0 = (src)[s0] + (src)[s4]; \ ++ const int a1 = (src)[s0] - (src)[s4]; \ ++ const int a2 = (src)[s2] + (src)[s6]; \ ++ const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ ++ const int a4 = (src)[s5] + (src)[s3]; \ ++ const int a5 = (src)[s5] - (src)[s3]; \ ++ const int a6 = (src)[s1] + (src)[s7]; \ ++ const int a7 = (src)[s1] - (src)[s7]; \ ++ const int b0 = a4 + a6; \ ++ const int b1 = (A3*(a5 + a7)) >> 11; \ ++ const int b2 = ((A4*a5) >> 11) - b0 + b1; \ ++ const int b3 = (A1*(a6 - a4) >> 11) - b2; \ ++ const int b4 = ((A2*a7) >> 11) + b3 - b1; \ ++ (dest)[d0] = munge(a0+a2 +b0); \ ++ (dest)[d1] = munge(a1+a3-a2+b2); \ ++ (dest)[d2] = munge(a1-a3+a2+b3); \ ++ (dest)[d3] = munge(a0-a2 -b4); \ ++ (dest)[d4] = munge(a0-a2 +b4); \ ++ (dest)[d5] = munge(a1-a3+a2-b3); \ ++ (dest)[d6] = munge(a1+a3-a2-b2); \ ++ (dest)[d7] = munge(a0+a2 -b0); \ ++} ++/* end IDCT_TRANSFORM macro */ ++ ++#define MUNGE_NONE(x) (x) ++#define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) ++ ++#define MUNGE_ROW(x) (((x) + 0x7F)>>8) ++#define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src) ++ ++static inline void bink_idct_col(int *dest, const int32_t *src) ++{ ++ if ((src[8]|src[16]|src[24]|src[32]|src[40]|src[48]|src[56])==0) { ++ dest[0] = ++ dest[8] = ++ dest[16] = ++ dest[24] = ++ dest[32] = ++ dest[40] = ++ dest[48] = ++ dest[56] = src[0]; ++ } else { ++ IDCT_COL(dest, src); ++ } ++} ++ ++static void bink_idct_c(int32_t *block) ++{ ++ int i; ++ int temp[64]; ++ ++ for (i = 0; i < 8; i++) ++ bink_idct_col(&temp[i], &block[i]); ++ for (i = 0; i < 8; i++) { ++ IDCT_ROW( (&block[8*i]), (&temp[8*i]) ); ++ } ++} ++ ++static void bink_idct_add_c(uint8_t *dest, int linesize, int32_t *block) ++{ ++ int i, j; ++ ++ bink_idct_c(block); ++ for (i = 0; i < 8; i++, dest += linesize, block += 8) ++ for (j = 0; j < 8; j++) ++ dest[j] += block[j]; ++} ++ ++static void bink_idct_put_c(uint8_t *dest, int linesize, int32_t *block) ++{ ++ int i; ++ int temp[64]; ++ for (i = 0; i < 8; i++) ++ bink_idct_col(&temp[i], &block[i]); ++ for (i = 0; i < 8; i++) { ++ IDCT_ROW( (&dest[i*linesize]), (&temp[8*i]) ); ++ } ++} ++ ++static void scale_block_c(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize) ++{ ++ int i, j; ++ uint16_t *dst1 = (uint16_t *) dst; ++ uint16_t *dst2 = (uint16_t *)(dst + linesize); ++ ++ for (j = 0; j < 8; j++) { ++ for (i = 0; i < 8; i++) { ++ dst1[i] = dst2[i] = src[i] * 0x0101; ++ } ++ src += 8; ++ dst1 += linesize; ++ dst2 += linesize; ++ } ++} ++ ++void ff_binkdsp_init(BinkDSPContext *c) ++{ ++ c->idct_add = bink_idct_add_c; ++ c->idct_put = bink_idct_put_c; ++ c->scale_block = scale_block_c; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkdsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkdsp.h 2012-05-14 14:08:53.532323840 +0200 +@@ -0,0 +1,40 @@ ++/* ++ * Bink DSP routines ++ * Copyright (c) 2009 Kostya Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Bink DSP routines ++ */ ++ ++#ifndef AVCODEC_BINKDSP_H ++#define AVCODEC_BINKDSP_H ++ ++#include "dsputil.h" ++ ++typedef struct BinkDSPContext { ++ void (*idct_put)(uint8_t *dest/*align 8*/, int line_size, int32_t *block/*align 16*/); ++ void (*idct_add)(uint8_t *dest/*align 8*/, int line_size, int32_t *block/*align 16*/); ++ void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize); ++} BinkDSPContext; ++ ++void ff_binkdsp_init(BinkDSPContext *c); ++ ++#endif /* AVCODEC_BINKDSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkidct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkidct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/binkidct.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/binkidct.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,112 +0,0 @@ +-/* +- * Bink IDCT algorithm +- * Copyright (c) 2009 Kostya Shishkov +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * Bink IDCT algorithm +- */ +- +-#include "dsputil.h" +- +-#define A1 2896 /* (1/sqrt(2))<<12 */ +-#define A2 2217 +-#define A3 3784 +-#define A4 -5352 +- +-#define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ +- const int a0 = (src)[s0] + (src)[s4]; \ +- const int a1 = (src)[s0] - (src)[s4]; \ +- const int a2 = (src)[s2] + (src)[s6]; \ +- const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ +- const int a4 = (src)[s5] + (src)[s3]; \ +- const int a5 = (src)[s5] - (src)[s3]; \ +- const int a6 = (src)[s1] + (src)[s7]; \ +- const int a7 = (src)[s1] - (src)[s7]; \ +- const int b0 = a4 + a6; \ +- const int b1 = (A3*(a5 + a7)) >> 11; \ +- const int b2 = ((A4*a5) >> 11) - b0 + b1; \ +- const int b3 = (A1*(a6 - a4) >> 11) - b2; \ +- const int b4 = ((A2*a7) >> 11) + b3 - b1; \ +- (dest)[d0] = munge(a0+a2 +b0); \ +- (dest)[d1] = munge(a1+a3-a2+b2); \ +- (dest)[d2] = munge(a1-a3+a2+b3); \ +- (dest)[d3] = munge(a0-a2 -b4); \ +- (dest)[d4] = munge(a0-a2 +b4); \ +- (dest)[d5] = munge(a1-a3+a2-b3); \ +- (dest)[d6] = munge(a1+a3-a2-b2); \ +- (dest)[d7] = munge(a0+a2 -b0); \ +-} +-/* end IDCT_TRANSFORM macro */ +- +-#define MUNGE_NONE(x) (x) +-#define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) +- +-#define MUNGE_ROW(x) (((x) + 0x7F)>>8) +-#define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src) +- +-static inline void bink_idct_col(DCTELEM *dest, const DCTELEM *src) +-{ +- if ((src[8]|src[16]|src[24]|src[32]|src[40]|src[48]|src[56])==0) { +- dest[0] = +- dest[8] = +- dest[16] = +- dest[24] = +- dest[32] = +- dest[40] = +- dest[48] = +- dest[56] = src[0]; +- } else { +- IDCT_COL(dest, src); +- } +-} +- +-void ff_bink_idct_c(DCTELEM *block) +-{ +- int i; +- DCTELEM temp[64]; +- +- for (i = 0; i < 8; i++) +- bink_idct_col(&temp[i], &block[i]); +- for (i = 0; i < 8; i++) { +- IDCT_ROW( (&block[8*i]), (&temp[8*i]) ); +- } +-} +- +-void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block) +-{ +- int i, j; +- +- ff_bink_idct_c(block); +- for (i = 0; i < 8; i++, dest += linesize, block += 8) +- for (j = 0; j < 8; j++) +- dest[j] += block[j]; +-} +- +-void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block) +-{ +- int i; +- DCTELEM temp[64]; +- for (i = 0; i < 8; i++) +- bink_idct_col(&temp[i], &block[i]); +- for (i = 0; i < 8; i++) { +- IDCT_ROW( (&dest[i*linesize]), (&temp[8*i]) ); +- } +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bintext.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bintext.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bintext.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bintext.c 2012-05-14 14:08:53.534323880 +0200 +@@ -0,0 +1,247 @@ ++/* ++ * Binary text decoder ++ * eXtended BINary text (XBIN) decoder ++ * iCEDraw File decoder ++ * Copyright (c) 2010 Peter Ross (pross@xvid.org) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Binary text decoder ++ * eXtended BINary text (XBIN) decoder ++ * iCEDraw File decoder ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++#include "cga_data.h" ++#include "bintext.h" ++ ++typedef struct XbinContext { ++ AVFrame frame; ++ int palette[16]; ++ int flags; ++ int font_height; ++ const uint8_t *font; ++ int x, y; ++} XbinContext; ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ XbinContext *s = avctx->priv_data; ++ uint8_t *p; ++ int i; ++ ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ p = avctx->extradata; ++ if (p) { ++ s->font_height = p[0]; ++ s->flags = p[1]; ++ p += 2; ++ } else { ++ s->font_height = 8; ++ s->flags = 0; ++ } ++ ++ if ((s->flags & BINTEXT_PALETTE)) { ++ for (i = 0; i < 16; i++) { ++ s->palette[i] = 0xFF000000 | (AV_RB24(p) << 2) | ((AV_RB24(p) >> 4) & 0x30303); ++ p += 3; ++ } ++ } else { ++ for (i = 0; i < 16; i++) ++ s->palette[i] = 0xFF000000 | ff_cga_palette[i]; ++ } ++ ++ if ((s->flags & BINTEXT_FONT)) { ++ s->font = p; ++ } else { ++ switch(s->font_height) { ++ default: ++ av_log(avctx, AV_LOG_WARNING, "font height %i not supported\n", s->font_height); ++ s->font_height = 8; ++ case 8: ++ s->font = ff_cga_font; ++ break; ++ case 16: ++ s->font = ff_vga16_font; ++ break; ++ } ++ } ++ ++ return 0; ++} ++ ++#define DEFAULT_BG_COLOR 0 ++static void hscroll(AVCodecContext *avctx) ++{ ++ XbinContext *s = avctx->priv_data; ++ if (s->y < avctx->height - s->font_height) { ++ s->y += s->font_height; ++ } else { ++ memmove(s->frame.data[0], s->frame.data[0] + s->font_height*s->frame.linesize[0], ++ (avctx->height - s->font_height)*s->frame.linesize[0]); ++ memset(s->frame.data[0] + (avctx->height - s->font_height)*s->frame.linesize[0], ++ DEFAULT_BG_COLOR, s->font_height * s->frame.linesize[0]); ++ } ++} ++ ++#define FONT_WIDTH 8 ++ ++/** ++ * Draw character to screen ++ */ ++static void draw_char(AVCodecContext *avctx, int c, int a) ++{ ++ XbinContext *s = avctx->priv_data; ++ if (s->y > avctx->height - s->font_height) ++ return; ++ ff_draw_pc_font(s->frame.data[0] + s->y * s->frame.linesize[0] + s->x, ++ s->frame.linesize[0], s->font, s->font_height, c, ++ a & 0x0F, a >> 4); ++ s->x += FONT_WIDTH; ++ if (s->x > avctx->width - FONT_WIDTH) { ++ s->x = 0; ++ s->y += s->font_height; ++ } ++} ++ ++static int decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ XbinContext *s = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ const uint8_t *buf_end = buf+buf_size; ++ ++ s->x = s->y = 0; ++ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | ++ FF_BUFFER_HINTS_PRESERVE | ++ FF_BUFFER_HINTS_REUSABLE; ++ if (avctx->reget_buffer(avctx, &s->frame)) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ s->frame.pict_type = AV_PICTURE_TYPE_I; ++ s->frame.palette_has_changed = 1; ++ memcpy(s->frame.data[1], s->palette, 16 * 4); ++ ++ if (avctx->codec_id == CODEC_ID_XBIN) { ++ while (buf + 2 < buf_end) { ++ int i,c,a; ++ int type = *buf >> 6; ++ int count = (*buf & 0x3F) + 1; ++ buf++; ++ switch (type) { ++ case 0: //no compression ++ for (i = 0; i < count && buf + 1 < buf_end; i++) { ++ draw_char(avctx, buf[0], buf[1]); ++ buf += 2; ++ } ++ break; ++ case 1: //character compression ++ c = *buf++; ++ for (i = 0; i < count && buf < buf_end; i++) ++ draw_char(avctx, c, *buf++); ++ break; ++ case 2: //attribute compression ++ a = *buf++; ++ for (i = 0; i < count && buf < buf_end; i++) ++ draw_char(avctx, *buf++, a); ++ break; ++ case 3: //character/attribute compression ++ c = *buf++; ++ a = *buf++; ++ for (i = 0; i < count && buf < buf_end; i++) ++ draw_char(avctx, c, a); ++ break; ++ } ++ } ++ } else if (avctx->codec_id == CODEC_ID_IDF) { ++ while (buf + 2 < buf_end) { ++ if (AV_RL16(buf) == 1) { ++ int i; ++ if (buf + 6 > buf_end) ++ break; ++ for (i = 0; i < buf[2]; i++) ++ draw_char(avctx, buf[4], buf[5]); ++ buf += 6; ++ } else { ++ draw_char(avctx, buf[0], buf[1]); ++ buf += 2; ++ } ++ } ++ } else { ++ while (buf + 1 < buf_end) { ++ draw_char(avctx, buf[0], buf[1]); ++ buf += 2; ++ } ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = s->frame; ++ return buf_size; ++} ++ ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ XbinContext *s = avctx->priv_data; ++ ++ if (s->frame.data[0]) ++ avctx->release_buffer(avctx, &s->frame); ++ ++ return 0; ++} ++ ++AVCodec ff_bintext_decoder = { ++ .name = "bintext", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_BINTEXT, ++ .priv_data_size = sizeof(XbinContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Binary text"), ++}; ++ ++AVCodec ff_xbin_decoder = { ++ .name = "xbin", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_XBIN, ++ .priv_data_size = sizeof(XbinContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text"), ++}; ++ ++AVCodec ff_idf_decoder = { ++ .name = "idf", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_IDF, ++ .priv_data_size = sizeof(XbinContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("iCEDraw text"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bintext.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bintext.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bintext.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bintext.h 2012-05-14 14:08:53.534323880 +0200 +@@ -0,0 +1,37 @@ ++/* ++ * Binary text decoder ++ * Copyright (c) 2010 Peter Ross (pross@xvid.org) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Binary text decoder ++ */ ++ ++#ifndef AVCODEC_BINTEXT_H ++#define AVCODEC_BINTEXT_H ++ ++/* flag values passed between avformat and avcodec; ++ * while these are identical to the XBIN flags, they are are also used ++ * for the BINTEXT and IDF decoders. ++ */ ++#define BINTEXT_PALETTE 0x1 ++#define BINTEXT_FONT 0x2 ++ ++#endif /* AVCODEC_BINTEXT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bit_depth_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bit_depth_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bit_depth_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bit_depth_template.c 2012-05-14 14:08:53.535323901 +0200 +@@ -0,0 +1,91 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dsputil.h" ++ ++#ifndef BIT_DEPTH ++#define BIT_DEPTH 8 ++#endif ++ ++#ifdef AVCODEC_H264_HIGH_DEPTH_H ++# undef pixel ++# undef pixel2 ++# undef pixel4 ++# undef dctcoef ++# undef INIT_CLIP ++# undef no_rnd_avg_pixel4 ++# undef rnd_avg_pixel4 ++# undef AV_RN2P ++# undef AV_RN4P ++# undef AV_RN4PA ++# undef AV_WN2P ++# undef AV_WN4P ++# undef AV_WN4PA ++# undef CLIP ++# undef FUNC ++# undef FUNCC ++# undef av_clip_pixel ++# undef PIXEL_SPLAT_X4 ++#else ++# define AVCODEC_H264_HIGH_DEPTH_H ++#endif ++ ++#if BIT_DEPTH > 8 ++# define pixel uint16_t ++# define pixel2 uint32_t ++# define pixel4 uint64_t ++# define dctcoef int32_t ++ ++# define INIT_CLIP ++# define no_rnd_avg_pixel4 no_rnd_avg64 ++# define rnd_avg_pixel4 rnd_avg64 ++# define AV_RN2P AV_RN32 ++# define AV_RN4P AV_RN64 ++# define AV_RN4PA AV_RN64A ++# define AV_WN2P AV_WN32 ++# define AV_WN4P AV_WN64 ++# define AV_WN4PA AV_WN64A ++# define PIXEL_SPLAT_X4(x) ((x)*0x0001000100010001ULL) ++ ++# define av_clip_pixel(a) av_clip_uintp2(a, BIT_DEPTH) ++# define CLIP(a) av_clip_uintp2(a, BIT_DEPTH) ++#else ++# define pixel uint8_t ++# define pixel2 uint16_t ++# define pixel4 uint32_t ++# define dctcoef int16_t ++ ++# define INIT_CLIP uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; ++# define no_rnd_avg_pixel4 no_rnd_avg32 ++# define rnd_avg_pixel4 rnd_avg32 ++# define AV_RN2P AV_RN16 ++# define AV_RN4P AV_RN32 ++# define AV_RN4PA AV_RN32A ++# define AV_WN2P AV_WN16 ++# define AV_WN4P AV_WN32 ++# define AV_WN4PA AV_WN32A ++# define PIXEL_SPLAT_X4(x) ((x)*0x01010101U) ++ ++# define av_clip_pixel(a) av_clip_uint8(a) ++# define CLIP(a) cm[a] ++#endif ++ ++#define FUNC3(a, b, c) a ## _ ## b ## c ++#define FUNC2(a, b, c) FUNC3(a, b, c) ++#define FUNC(a) FUNC2(a, BIT_DEPTH,) ++#define FUNCC(a) FUNC2(a, BIT_DEPTH, _c) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bitstream.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bitstream.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bitstream.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bitstream.c 2012-05-14 14:08:53.536323922 +0200 +@@ -32,20 +32,18 @@ + #include "get_bits.h" + #include "put_bits.h" + +-const uint8_t ff_log2_run[32]={ ++const uint8_t ff_log2_run[41]={ + 0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 5, 5, 6, 6, 7, 7, +- 8, 9,10,11,12,13,14,15 ++ 8, 9,10,11,12,13,14,15, ++16,17,18,19,20,21,22,23, ++24, + }; + +-void align_put_bits(PutBitContext *s) ++void avpriv_align_put_bits(PutBitContext *s) + { +-#ifdef ALT_BITSTREAM_WRITER +- put_bits(s,( - s->index) & 7,0); +-#else + put_bits(s,s->bit_left & 7,0); +-#endif + } + + void ff_put_string(PutBitContext *pb, const char *string, int terminate_string) +@@ -58,7 +56,7 @@ + put_bits(pb, 8, 0); + } + +-void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length) ++void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length) + { + int words= length>>4; + int bits= length&15; +@@ -81,8 +79,6 @@ + + /* VLC decoding */ + +-//#define DEBUG_VLC +- + #define GET_DATA(v, table, i, wrap, size) \ + {\ + const uint8_t *ptr = (const uint8_t *)table + i * wrap;\ +@@ -107,10 +103,10 @@ + vlc->table_size += size; + if (vlc->table_size > vlc->table_allocated) { + if(use_static) +- abort(); //cant do anything, init_vlc() is used with too little memory ++ abort(); // cannot do anything, init_vlc() is used with too little memory + vlc->table_allocated += (1 << vlc->bits); +- vlc->table = av_realloc(vlc->table, +- sizeof(VLC_TYPE) * 2 * vlc->table_allocated); ++ vlc->table = av_realloc_f(vlc->table, ++ vlc->table_allocated, sizeof(VLC_TYPE) * 2); + if (!vlc->table) + return -1; + } +@@ -118,10 +114,10 @@ + } + + static av_always_inline uint32_t bitswap_32(uint32_t x) { +- return av_reverse[x&0xFF]<<24 +- | av_reverse[(x>>8)&0xFF]<<16 +- | av_reverse[(x>>16)&0xFF]<<8 +- | av_reverse[x>>24]; ++ return (uint32_t)av_reverse[x&0xFF]<<24 ++ | (uint32_t)av_reverse[(x>>8)&0xFF]<<16 ++ | (uint32_t)av_reverse[(x>>16)&0xFF]<<8 ++ | (uint32_t)av_reverse[x>>24]; + } + + typedef struct { +@@ -162,10 +158,7 @@ + + table_size = 1 << table_nb_bits; + table_index = alloc_table(vlc, table_size, flags & INIT_VLC_USE_NEW_STATIC); +-#ifdef DEBUG_VLC +- av_log(NULL,AV_LOG_DEBUG,"new table index=%d size=%d\n", +- table_index, table_size); +-#endif ++ av_dlog(NULL, "new table index=%d size=%d\n", table_index, table_size); + if (table_index < 0) + return -1; + table = &vlc->table[table_index]; +@@ -180,9 +173,7 @@ + n = codes[i].bits; + code = codes[i].code; + symbol = codes[i].symbol; +-#if defined(DEBUG_VLC) && 0 +- av_log(NULL,AV_LOG_DEBUG,"i=%d n=%d code=0x%x\n", i, n, code); +-#endif ++ av_dlog(NULL, "i=%d n=%d code=0x%x\n", i, n, code); + if (n <= table_nb_bits) { + /* no need to add another table */ + j = code >> (32 - table_nb_bits); +@@ -193,10 +184,7 @@ + inc = 1 << n; + } + for (k = 0; k < nb; k++) { +-#ifdef DEBUG_VLC +- av_log(NULL, AV_LOG_DEBUG, "%4x: code=%d n=%d\n", +- j, i, n); +-#endif ++ av_dlog(NULL, "%4x: code=%d n=%d\n", j, i, n); + if (table[j][1] /*bits*/ != 0) { + av_log(NULL, AV_LOG_ERROR, "incorrect codes\n"); + return -1; +@@ -226,10 +214,8 @@ + subtable_bits = FFMIN(subtable_bits, table_nb_bits); + j = (flags & INIT_VLC_LE) ? bitswap_32(code_prefix) >> (32 - table_nb_bits) : code_prefix; + table[j][1] = -subtable_bits; +-#ifdef DEBUG_VLC +- av_log(NULL,AV_LOG_DEBUG,"%4x: n=%d (subtable)\n", +- j, codes[i].bits + table_nb_bits); +-#endif ++ av_dlog(NULL, "%4x: n=%d (subtable)\n", ++ j, codes[i].bits + table_nb_bits); + index = build_table(vlc, subtable_bits, k-i, codes+i, flags); + if (index < 0) + return -1; +@@ -291,9 +277,7 @@ + vlc->table_size = 0; + } + +-#ifdef DEBUG_VLC +- av_log(NULL,AV_LOG_DEBUG,"build table nb_codes=%d\n", nb_codes); +-#endif ++ av_dlog(NULL, "build table nb_codes=%d\n", nb_codes); + + buf = av_malloc((nb_codes+1)*sizeof(VLCcode)); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmp.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmp.c 2012-05-14 14:08:53.537323942 +0200 +@@ -49,6 +49,7 @@ + unsigned int ihsize; + int i, j, n, linesize; + uint32_t rgb[3]; ++ uint32_t alpha = 0; + uint8_t *ptr; + int dsize; + const uint8_t *buf0 = buf; +@@ -92,7 +93,8 @@ + } + + switch(ihsize){ +- case 40: // windib v3 ++ case 40: // windib ++ case 56: // windib v3 + case 64: // OS/2 v2 + case 108: // windib v4 + case 124: // windib v5 +@@ -115,7 +117,7 @@ + + depth = bytestream_get_le16(&buf); + +- if(ihsize == 40) ++ if(ihsize == 40 || ihsize == 64 || ihsize == 56) + comp = bytestream_get_le32(&buf); + else + comp = BMP_RGB; +@@ -130,6 +132,8 @@ + rgb[0] = bytestream_get_le32(&buf); + rgb[1] = bytestream_get_le32(&buf); + rgb[2] = bytestream_get_le32(&buf); ++ if (ihsize >= 108) ++ alpha = bytestream_get_le32(&buf); + } + + avctx->width = width; +@@ -140,21 +144,21 @@ + switch(depth){ + case 32: + if(comp == BMP_BITFIELDS){ +- rgb[0] = (rgb[0] >> 15) & 3; +- rgb[1] = (rgb[1] >> 15) & 3; +- rgb[2] = (rgb[2] >> 15) & 3; +- +- if(rgb[0] + rgb[1] + rgb[2] != 3 || +- rgb[0] == rgb[1] || rgb[0] == rgb[2] || rgb[1] == rgb[2]){ +- break; ++ if (rgb[0] == 0xFF000000 && rgb[1] == 0x00FF0000 && rgb[2] == 0x0000FF00) ++ avctx->pix_fmt = alpha ? PIX_FMT_ABGR : PIX_FMT_0BGR; ++ else if (rgb[0] == 0x00FF0000 && rgb[1] == 0x0000FF00 && rgb[2] == 0x000000FF) ++ avctx->pix_fmt = alpha ? PIX_FMT_BGRA : PIX_FMT_BGR0; ++ else if (rgb[0] == 0x0000FF00 && rgb[1] == 0x00FF0000 && rgb[2] == 0xFF000000) ++ avctx->pix_fmt = alpha ? PIX_FMT_ARGB : PIX_FMT_0RGB; ++ else if (rgb[0] == 0x000000FF && rgb[1] == 0x0000FF00 && rgb[2] == 0x00FF0000) ++ avctx->pix_fmt = alpha ? PIX_FMT_RGBA : PIX_FMT_RGB0; ++ else { ++ av_log(avctx, AV_LOG_ERROR, "Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]); ++ return AVERROR(EINVAL); + } + } else { +- rgb[0] = 2; +- rgb[1] = 1; +- rgb[2] = 0; ++ avctx->pix_fmt = PIX_FMT_BGRA; + } +- +- avctx->pix_fmt = PIX_FMT_BGR24; + break; + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; +@@ -162,8 +166,18 @@ + case 16: + if(comp == BMP_RGB) + avctx->pix_fmt = PIX_FMT_RGB555; +- if(comp == BMP_BITFIELDS) +- avctx->pix_fmt = rgb[1] == 0x07E0 ? PIX_FMT_RGB565 : PIX_FMT_RGB555; ++ else if (comp == BMP_BITFIELDS) { ++ if (rgb[0] == 0xF800 && rgb[1] == 0x07E0 && rgb[2] == 0x001F) ++ avctx->pix_fmt = PIX_FMT_RGB565; ++ else if (rgb[0] == 0x7C00 && rgb[1] == 0x03E0 && rgb[2] == 0x001F) ++ avctx->pix_fmt = PIX_FMT_RGB555; ++ else if (rgb[0] == 0x0F00 && rgb[1] == 0x00F0 && rgb[2] == 0x000F) ++ avctx->pix_fmt = PIX_FMT_RGB444; ++ else { ++ av_log(avctx, AV_LOG_ERROR, "Unknown bitfields %0X %0X %0X\n", rgb[0], rgb[1], rgb[2]); ++ return AVERROR(EINVAL); ++ } ++ } + break; + case 8: + if(hsize - ihsize - 14 > 0) +@@ -171,17 +185,15 @@ + else + avctx->pix_fmt = PIX_FMT_GRAY8; + break; ++ case 1: + case 4: + if(hsize - ihsize - 14 > 0){ + avctx->pix_fmt = PIX_FMT_PAL8; + }else{ +- av_log(avctx, AV_LOG_ERROR, "Unknown palette for 16-colour BMP\n"); ++ av_log(avctx, AV_LOG_ERROR, "Unknown palette for %d-colour BMP\n", 1<pix_fmt = PIX_FMT_MONOBLACK; +- break; + default: + av_log(avctx, AV_LOG_ERROR, "depth %d not supported\n", depth); + return -1; +@@ -200,14 +212,14 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + + buf = buf0 + hsize; + dsize = buf_size - hsize; + + /* Line size in file multiple of 4 */ +- n = ((avctx->width * depth) / 8 + 3) & ~3; ++ n = ((avctx->width * depth + 31) / 8) & ~3; + + if(n * avctx->height > dsize && comp != BMP_RLE4 && comp != BMP_RLE8){ + av_log(avctx, AV_LOG_ERROR, "not enough data (%d < %d)\n", +@@ -245,10 +257,10 @@ + buf = buf0 + 14 + ihsize; //palette location + if((hsize-ihsize-14) < (colors << 2)){ // OS/2 bitmap, 3 bytes per palette entry + for(i = 0; i < colors; i++) +- ((uint32_t*)p->data[1])[i] = bytestream_get_le24(&buf); ++ ((uint32_t*)p->data[1])[i] = (0xff<<24) | bytestream_get_le24(&buf); + }else{ + for(i = 0; i < colors; i++) +- ((uint32_t*)p->data[1])[i] = bytestream_get_le32(&buf); ++ ((uint32_t*)p->data[1])[i] = 0xFFU << 24 | bytestream_get_le32(&buf); + } + buf = buf0 + hsize; + } +@@ -265,8 +277,25 @@ + }else{ + switch(depth){ + case 1: ++ for (i = 0; i < avctx->height; i++) { ++ int j; ++ for (j = 0; j < n; j++) { ++ ptr[j*8+0] = buf[j] >> 7; ++ ptr[j*8+1] = (buf[j] >> 6) & 1; ++ ptr[j*8+2] = (buf[j] >> 5) & 1; ++ ptr[j*8+3] = (buf[j] >> 4) & 1; ++ ptr[j*8+4] = (buf[j] >> 3) & 1; ++ ptr[j*8+5] = (buf[j] >> 2) & 1; ++ ptr[j*8+6] = (buf[j] >> 1) & 1; ++ ptr[j*8+7] = buf[j] & 1; ++ } ++ buf += n; ++ ptr += linesize; ++ } ++ break; + case 8: + case 24: ++ case 32: + for(i = 0; i < avctx->height; i++){ + memcpy(ptr, buf, n); + buf += n; +@@ -296,23 +325,6 @@ + ptr += linesize; + } + break; +- case 32: +- for(i = 0; i < avctx->height; i++){ +- const uint8_t *src = buf; +- uint8_t *dst = ptr; +- +- for(j = 0; j < avctx->width; j++){ +- dst[0] = src[rgb[2]]; +- dst[1] = src[rgb[1]]; +- dst[2] = src[rgb[0]]; +- dst += 3; +- src += 4; +- } +- +- buf += n; +- ptr += linesize; +- } +- break; + default: + av_log(avctx, AV_LOG_ERROR, "BMP decoder is broken\n"); + return -1; +@@ -336,14 +348,13 @@ + } + + AVCodec ff_bmp_decoder = { +- "bmp", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_BMP, +- sizeof(BMPContext), +- bmp_decode_init, +- NULL, +- bmp_decode_end, +- bmp_decode_frame, +- CODEC_CAP_DR1, ++ .name = "bmp", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_BMP, ++ .priv_data_size = sizeof(BMPContext), ++ .init = bmp_decode_init, ++ .close = bmp_decode_end, ++ .decode = bmp_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("BMP image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmpenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmpenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmpenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmpenc.c 2012-05-14 14:08:53.538323962 +0200 +@@ -20,13 +20,15 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/internal.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + #include "bmp.h" ++#include + + static const uint32_t monoblack_pal[] = { 0x000000, 0xFFFFFF }; + static const uint32_t rgb565_masks[] = { 0xF800, 0x07E0, 0x001F }; ++static const uint32_t rgb444_masks[] = { 0x0F00, 0x00F0, 0x000F }; + + static av_cold int bmp_encode_init(AVCodecContext *avctx){ + BMPContext *s = avctx->priv_data; +@@ -35,13 +37,15 @@ + avctx->coded_frame = (AVFrame*)&s->picture; + + switch (avctx->pix_fmt) { ++ case PIX_FMT_BGRA: ++ avctx->bits_per_coded_sample = 32; ++ break; + case PIX_FMT_BGR24: + avctx->bits_per_coded_sample = 24; + break; + case PIX_FMT_RGB555: +- avctx->bits_per_coded_sample = 16; +- break; + case PIX_FMT_RGB565: ++ case PIX_FMT_RGB444: + avctx->bits_per_coded_sample = 16; + break; + case PIX_FMT_RGB8: +@@ -69,14 +73,20 @@ + AVFrame * const p= (AVFrame*)&s->picture; + int n_bytes_image, n_bytes_per_row, n_bytes, i, n, hsize; + const uint32_t *pal = NULL; ++ uint32_t palette256[256]; + int pad_bytes_per_row, pal_entries = 0, compression = BMP_RGB; + int bit_count = avctx->bits_per_coded_sample; + uint8_t *ptr; + unsigned char* buf0 = buf; + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + switch (avctx->pix_fmt) { ++ case PIX_FMT_RGB444: ++ compression = BMP_BITFIELDS; ++ pal = rgb444_masks; // abuse pal to hold color masks ++ pal_entries = 3; ++ break; + case PIX_FMT_RGB565: + compression = BMP_BITFIELDS; + pal = rgb565_masks; // abuse pal to hold color masks +@@ -87,7 +97,10 @@ + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_GRAY8: +- ff_set_systematic_pal2((uint32_t*)p->data[1], avctx->pix_fmt); ++ assert(bit_count == 8); ++ ff_set_systematic_pal2(palette256, avctx->pix_fmt); ++ pal = palette256; ++ break; + case PIX_FMT_PAL8: + pal = (uint32_t *)p->data[1]; + break; +@@ -150,16 +163,15 @@ + } + + AVCodec ff_bmp_encoder = { +- "bmp", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_BMP, +- sizeof(BMPContext), +- bmp_encode_init, +- bmp_encode_frame, +- NULL, //encode_end, ++ .name = "bmp", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_BMP, ++ .priv_data_size = sizeof(BMPContext), ++ .init = bmp_encode_init, ++ .encode = bmp_encode_frame, + .pix_fmts = (const enum PixelFormat[]){ +- PIX_FMT_BGR24, +- PIX_FMT_RGB555, PIX_FMT_RGB565, ++ PIX_FMT_BGRA, PIX_FMT_BGR24, ++ PIX_FMT_RGB565, PIX_FMT_RGB555, PIX_FMT_RGB444, + PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, + PIX_FMT_MONOBLACK, + PIX_FMT_NONE}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bmv.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bmv.c 2012-05-14 14:08:53.539323982 +0200 +@@ -0,0 +1,376 @@ ++/* ++ * Discworld II BMV video and audio decoder ++ * Copyright (c) 2011 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "bytestream.h" ++ ++enum BMVFlags{ ++ BMV_NOP = 0, ++ BMV_END, ++ BMV_DELTA, ++ BMV_INTRA, ++ ++ BMV_SCROLL = 0x04, ++ BMV_PALETTE = 0x08, ++ BMV_COMMAND = 0x10, ++ BMV_AUDIO = 0x20, ++ BMV_EXT = 0x40, ++ BMV_PRINT = 0x80 ++}; ++ ++#define SCREEN_WIDE 640 ++#define SCREEN_HIGH 429 ++ ++typedef struct BMVDecContext { ++ AVCodecContext *avctx; ++ AVFrame pic; ++ ++ uint8_t *frame, frame_base[SCREEN_WIDE * (SCREEN_HIGH + 1)]; ++ uint32_t pal[256]; ++ const uint8_t *stream; ++} BMVDecContext; ++ ++#define NEXT_BYTE(v) v = forward ? v + 1 : v - 1; ++ ++static int decode_bmv_frame(const uint8_t *source, int src_len, uint8_t *frame, int frame_off) ++{ ++ int val, saved_val = 0; ++ int tmplen = src_len; ++ const uint8_t *src, *source_end = source + src_len; ++ uint8_t *frame_end = frame + SCREEN_WIDE * SCREEN_HIGH; ++ uint8_t *dst, *dst_end; ++ int len, mask; ++ int forward = (frame_off <= -SCREEN_WIDE) || (frame_off >= 0); ++ int read_two_nibbles, flag; ++ int advance_mode; ++ int mode = 0; ++ int i; ++ ++ if (src_len <= 0) ++ return -1; ++ ++ if (forward) { ++ src = source; ++ dst = frame; ++ dst_end = frame_end; ++ } else { ++ src = source + src_len - 1; ++ dst = frame_end - 1; ++ dst_end = frame - 1; ++ } ++ for (;;) { ++ int shift = 0; ++ flag = 0; ++ ++ /* The mode/len decoding is a bit strange: ++ * values are coded as variable-length codes with nibble units, ++ * code end is signalled by two top bits in the nibble being nonzero. ++ * And since data is bytepacked and we read two nibbles at a time, ++ * we may get a nibble belonging to the next code. ++ * Hence this convoluted loop. ++ */ ++ if (!mode || (tmplen == 4)) { ++ if (src < source || src >= source_end) ++ return -1; ++ val = *src; ++ read_two_nibbles = 1; ++ } else { ++ val = saved_val; ++ read_two_nibbles = 0; ++ } ++ if (!(val & 0xC)) { ++ for (;;) { ++ if (!read_two_nibbles) { ++ if (src < source || src >= source_end) ++ return -1; ++ shift += 2; ++ val |= *src << shift; ++ if (*src & 0xC) ++ break; ++ } ++ // two upper bits of the nibble is zero, ++ // so shift top nibble value down into their place ++ read_two_nibbles = 0; ++ shift += 2; ++ mask = (1 << shift) - 1; ++ val = ((val >> 2) & ~mask) | (val & mask); ++ NEXT_BYTE(src); ++ if ((val & (0xC << shift))) { ++ flag = 1; ++ break; ++ } ++ } ++ } else if (mode) { ++ flag = tmplen != 4; ++ } ++ if (flag) { ++ tmplen = 4; ++ } else { ++ saved_val = val >> (4 + shift); ++ tmplen = 0; ++ val &= (1 << (shift + 4)) - 1; ++ NEXT_BYTE(src); ++ } ++ advance_mode = val & 1; ++ len = (val >> 1) - 1; ++ mode += 1 + advance_mode; ++ if (mode >= 4) ++ mode -= 3; ++ if (FFABS(dst_end - dst) < len) ++ return -1; ++ switch (mode) { ++ case 1: ++ if (forward) { ++ if (dst - frame + SCREEN_WIDE < frame_off || ++ frame_end - dst < frame_off + len) ++ return -1; ++ for (i = 0; i < len; i++) ++ dst[i] = dst[frame_off + i]; ++ dst += len; ++ } else { ++ dst -= len; ++ if (dst - frame + SCREEN_WIDE < frame_off || ++ frame_end - dst < frame_off + len) ++ return -1; ++ for (i = len - 1; i >= 0; i--) ++ dst[i] = dst[frame_off + i]; ++ } ++ break; ++ case 2: ++ if (forward) { ++ if (source + src_len - src < len) ++ return -1; ++ memcpy(dst, src, len); ++ dst += len; ++ src += len; ++ } else { ++ if (src - source < len) ++ return -1; ++ dst -= len; ++ src -= len; ++ memcpy(dst, src, len); ++ } ++ break; ++ case 3: ++ val = forward ? dst[-1] : dst[1]; ++ if (forward) { ++ memset(dst, val, len); ++ dst += len; ++ } else { ++ dst -= len; ++ memset(dst, val, len); ++ } ++ break; ++ default: ++ break; ++ } ++ if (dst == dst_end) ++ return 0; ++ } ++ return 0; ++} ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt) ++{ ++ BMVDecContext * const c = avctx->priv_data; ++ int type, scr_off; ++ int i; ++ uint8_t *srcptr, *outptr; ++ ++ c->stream = pkt->data; ++ type = bytestream_get_byte(&c->stream); ++ if (type & BMV_AUDIO) { ++ int blobs = bytestream_get_byte(&c->stream); ++ if (pkt->size < blobs * 65 + 2) { ++ av_log(avctx, AV_LOG_ERROR, "Audio data doesn't fit in frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ c->stream += blobs * 65; ++ } ++ if (type & BMV_COMMAND) { ++ int command_size = (type & BMV_PRINT) ? 8 : 10; ++ if (c->stream - pkt->data + command_size > pkt->size) { ++ av_log(avctx, AV_LOG_ERROR, "Command data doesn't fit in frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ c->stream += command_size; ++ } ++ if (type & BMV_PALETTE) { ++ if (c->stream - pkt->data > pkt->size - 768) { ++ av_log(avctx, AV_LOG_ERROR, "Palette data doesn't fit in frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ for (i = 0; i < 256; i++) ++ c->pal[i] = 0xFF << 24 | bytestream_get_be24(&c->stream); ++ } ++ if (type & BMV_SCROLL) { ++ if (c->stream - pkt->data > pkt->size - 2) { ++ av_log(avctx, AV_LOG_ERROR, "Screen offset data doesn't fit in frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ scr_off = (int16_t)bytestream_get_le16(&c->stream); ++ } else if ((type & BMV_INTRA) == BMV_INTRA) { ++ scr_off = -640; ++ } else { ++ scr_off = 0; ++ } ++ ++ if (decode_bmv_frame(c->stream, pkt->size - (c->stream - pkt->data), c->frame, scr_off)) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding frame data\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); ++ c->pic.palette_has_changed = type & BMV_PALETTE; ++ ++ outptr = c->pic.data[0]; ++ srcptr = c->frame; ++ ++ for (i = 0; i < avctx->height; i++) { ++ memcpy(outptr, srcptr, avctx->width); ++ srcptr += avctx->width; ++ outptr += c->pic.linesize[0]; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = c->pic; ++ ++ /* always report that the buffer was completely consumed */ ++ return pkt->size; ++} ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ BMVDecContext * const c = avctx->priv_data; ++ ++ c->avctx = avctx; ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ ++ c->pic.reference = 1; ++ if (avctx->get_buffer(avctx, &c->pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ ++ c->frame = c->frame_base + 640; ++ ++ return 0; ++} ++ ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ BMVDecContext *c = avctx->priv_data; ++ ++ if (c->pic.data[0]) ++ avctx->release_buffer(avctx, &c->pic); ++ ++ return 0; ++} ++ ++typedef struct BMVAudioDecContext { ++ AVFrame frame; ++} BMVAudioDecContext; ++ ++static const int bmv_aud_mults[16] = { ++ 16512, 8256, 4128, 2064, 1032, 516, 258, 192, 129, 88, 64, 56, 48, 40, 36, 32 ++}; ++ ++static av_cold int bmv_aud_decode_init(AVCodecContext *avctx) ++{ ++ BMVAudioDecContext *c = avctx->priv_data; ++ ++ if (avctx->channels != 2) { ++ av_log(avctx, AV_LOG_INFO, "invalid number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ ++ return 0; ++} ++ ++static int bmv_aud_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ BMVAudioDecContext *c = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int blocks = 0, total_blocks, i; ++ int ret; ++ int16_t *output_samples; ++ int scale[2]; ++ ++ total_blocks = *buf++; ++ if (buf_size < total_blocks * 65 + 1) { ++ av_log(avctx, AV_LOG_ERROR, "expected %d bytes, got %d\n", ++ total_blocks * 65 + 1, buf_size); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* get output buffer */ ++ c->frame.nb_samples = total_blocks * 32; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ output_samples = (int16_t *)c->frame.data[0]; ++ ++ for (blocks = 0; blocks < total_blocks; blocks++) { ++ uint8_t code = *buf++; ++ code = (code >> 1) | (code << 7); ++ scale[0] = bmv_aud_mults[code & 0xF]; ++ scale[1] = bmv_aud_mults[code >> 4]; ++ for (i = 0; i < 32; i++) { ++ *output_samples++ = av_clip_int16((scale[0] * (int8_t)*buf++) >> 5); ++ *output_samples++ = av_clip_int16((scale[1] * (int8_t)*buf++) >> 5); ++ } ++ } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; ++ ++ return buf_size; ++} ++ ++AVCodec ff_bmv_video_decoder = { ++ .name = "bmv_video", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_BMV_VIDEO, ++ .priv_data_size = sizeof(BMVDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV video"), ++}; ++ ++AVCodec ff_bmv_audio_decoder = { ++ .name = "bmv_audio", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_BMV_AUDIO, ++ .priv_data_size = sizeof(BMVAudioDecContext), ++ .init = bmv_aud_decode_init, ++ .decode = bmv_aud_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV audio"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bytestream.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bytestream.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/bytestream.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/bytestream.h 2012-05-14 14:08:53.540324002 +0200 +@@ -26,6 +26,10 @@ + #include "libavutil/common.h" + #include "libavutil/intreadwrite.h" + ++typedef struct { ++ const uint8_t *buffer, *buffer_end, *buffer_start; ++} GetByteContext; ++ + #define DEF_T(type, name, bytes, read, write) \ + static av_always_inline type bytestream_get_ ## name(const uint8_t **b){\ + (*b) += bytes;\ +@@ -34,6 +38,22 @@ + static av_always_inline void bytestream_put_ ##name(uint8_t **b, const type value){\ + write(*b, value);\ + (*b) += bytes;\ ++}\ ++static av_always_inline type bytestream2_get_ ## name ## u(GetByteContext *g)\ ++{\ ++ return bytestream_get_ ## name(&g->buffer);\ ++}\ ++static av_always_inline type bytestream2_get_ ## name(GetByteContext *g)\ ++{\ ++ if (g->buffer_end - g->buffer < bytes)\ ++ return 0;\ ++ return bytestream2_get_ ## name ## u(g);\ ++}\ ++static av_always_inline type bytestream2_peek_ ## name(GetByteContext *g)\ ++{\ ++ if (g->buffer_end - g->buffer < bytes)\ ++ return 0;\ ++ return read(g->buffer);\ + } + + #define DEF(name, bytes, read, write) \ +@@ -55,6 +75,99 @@ + #undef DEF64 + #undef DEF_T + ++#if HAVE_BIGENDIAN ++# define bytestream2_get_ne16 bytestream2_get_be16 ++# define bytestream2_get_ne24 bytestream2_get_be24 ++# define bytestream2_get_ne32 bytestream2_get_be32 ++# define bytestream2_get_ne64 bytestream2_get_be64 ++# define bytestream2_get_ne16u bytestream2_get_be16u ++# define bytestream2_get_ne24u bytestream2_get_be24u ++# define bytestream2_get_ne32u bytestream2_get_be32u ++# define bytestream2_get_ne64u bytestream2_get_be64u ++# define bytestream2_put_ne16 bytestream2_put_be16 ++# define bytestream2_put_ne24 bytestream2_put_be24 ++# define bytestream2_put_ne32 bytestream2_put_be32 ++# define bytestream2_put_ne64 bytestream2_put_be64 ++# define bytestream2_peek_ne16 bytestream2_peek_be16 ++# define bytestream2_peek_ne24 bytestream2_peek_be24 ++# define bytestream2_peek_ne32 bytestream2_peek_be32 ++# define bytestream2_peek_ne64 bytestream2_peek_be64 ++#else ++# define bytestream2_get_ne16 bytestream2_get_le16 ++# define bytestream2_get_ne24 bytestream2_get_le24 ++# define bytestream2_get_ne32 bytestream2_get_le32 ++# define bytestream2_get_ne64 bytestream2_get_le64 ++# define bytestream2_get_ne16u bytestream2_get_le16u ++# define bytestream2_get_ne24u bytestream2_get_le24u ++# define bytestream2_get_ne32u bytestream2_get_le32u ++# define bytestream2_get_ne64u bytestream2_get_le64u ++# define bytestream2_put_ne16 bytestream2_put_le16 ++# define bytestream2_put_ne24 bytestream2_put_le24 ++# define bytestream2_put_ne32 bytestream2_put_le32 ++# define bytestream2_put_ne64 bytestream2_put_le64 ++# define bytestream2_peek_ne16 bytestream2_peek_le16 ++# define bytestream2_peek_ne24 bytestream2_peek_le24 ++# define bytestream2_peek_ne32 bytestream2_peek_le32 ++# define bytestream2_peek_ne64 bytestream2_peek_le64 ++#endif ++ ++static av_always_inline void bytestream2_init(GetByteContext *g, ++ const uint8_t *buf, int buf_size) ++{ ++ g->buffer = buf; ++ g->buffer_start = buf; ++ g->buffer_end = buf + buf_size; ++} ++ ++static av_always_inline unsigned int bytestream2_get_bytes_left(GetByteContext *g) ++{ ++ return g->buffer_end - g->buffer; ++} ++ ++static av_always_inline void bytestream2_skip(GetByteContext *g, ++ unsigned int size) ++{ ++ g->buffer += FFMIN(g->buffer_end - g->buffer, size); ++} ++ ++static av_always_inline int bytestream2_tell(GetByteContext *g) ++{ ++ return (int)(g->buffer - g->buffer_start); ++} ++ ++static av_always_inline int bytestream2_seek(GetByteContext *g, int offset, ++ int whence) ++{ ++ switch (whence) { ++ case SEEK_CUR: ++ offset = av_clip(offset, -(g->buffer - g->buffer_start), ++ g->buffer_end - g->buffer); ++ g->buffer += offset; ++ break; ++ case SEEK_END: ++ offset = av_clip(offset, -(g->buffer_end - g->buffer_start), 0); ++ g->buffer = g->buffer_end + offset; ++ break; ++ case SEEK_SET: ++ offset = av_clip(offset, 0, g->buffer_end - g->buffer_start); ++ g->buffer = g->buffer_start + offset; ++ break; ++ default: ++ return AVERROR(EINVAL); ++ } ++ return bytestream2_tell(g); ++} ++ ++static av_always_inline unsigned int bytestream2_get_buffer(GetByteContext *g, ++ uint8_t *dst, ++ unsigned int size) ++{ ++ int size2 = FFMIN(g->buffer_end - g->buffer, size); ++ memcpy(dst, g->buffer, size2); ++ g->buffer += size2; ++ return size2; ++} ++ + static av_always_inline unsigned int bytestream_get_buffer(const uint8_t **b, uint8_t *dst, unsigned int size) + { + memcpy(dst, *b, size); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/c93.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/c93.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/c93.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/c93.c 2012-05-14 14:08:53.541324022 +0200 +@@ -47,6 +47,10 @@ + + static av_cold int decode_init(AVCodecContext *avctx) + { ++ C93DecoderContext * const c93 = avctx->priv_data; ++ ++ avcodec_get_frame_defaults(&c93->pictures[0]); ++ avcodec_get_frame_defaults(&c93->pictures[1]); + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; + } +@@ -126,7 +130,7 @@ + + c93->currentpic ^= 1; + +- newpic->reference = 1; ++ newpic->reference = 3; + newpic->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; + if (avctx->reget_buffer(avctx, newpic)) { +@@ -137,10 +141,10 @@ + stride = newpic->linesize[0]; + + if (buf[0] & C93_FIRST_FRAME) { +- newpic->pict_type = FF_I_TYPE; ++ newpic->pict_type = AV_PICTURE_TYPE_I; + newpic->key_frame = 1; + } else { +- newpic->pict_type = FF_P_TYPE; ++ newpic->pict_type = AV_PICTURE_TYPE_P; + newpic->key_frame = 0; + } + +@@ -148,7 +152,7 @@ + uint32_t *palette = (uint32_t *) newpic->data[1]; + const uint8_t *palbuf = buf + buf_size - 768 - 1; + for (i = 0; i < 256; i++) { +- palette[i] = bytestream_get_be24(&palbuf); ++ palette[i] = 0xFF << 24 | bytestream_get_be24(&palbuf); + } + } else { + if (oldpic->data[1]) +@@ -243,14 +247,13 @@ + } + + AVCodec ff_c93_decoder = { +- "c93", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_C93, +- sizeof(C93DecoderContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "c93", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_C93, ++ .priv_data_size = sizeof(C93DecoderContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Interplay C93"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cabac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cabac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cabac.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cabac.c 2012-05-14 14:08:53.542324042 +0200 +@@ -29,6 +29,7 @@ + #include "libavutil/common.h" + #include "get_bits.h" + #include "cabac.h" ++#include "cabac_functions.h" + + static const uint8_t lps_range[64][4]= { + {128,176,208,240}, {128,167,197,227}, {128,158,187,216}, {123,150,178,205}, +@@ -52,7 +53,7 @@ + uint8_t ff_h264_mlps_state[4*64]; + uint8_t ff_h264_lps_range[4*2*64]; + uint8_t ff_h264_lps_state[2*64]; +-uint8_t ff_h264_mps_state[2*64]; ++static uint8_t h264_mps_state[2 * 64]; + + static const uint8_t mps_state[64]= { + 1, 2, 3, 4, 5, 6, 7, 8, +@@ -75,18 +76,7 @@ + 33,33,34,34,35,35,35,36, + 36,36,37,37,37,38,38,63, + }; +-#if 0 +-const uint8_t ff_h264_norm_shift_old[128]= { +- 7,6,5,5,4,4,4,4,3,3,3,3,3,3,3,3, +- 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, +- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +- 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, +- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, +-}; +-#endif ++ + const uint8_t ff_h264_norm_shift[512]= { + 9,8,7,7,6,6,6,6,5,5,5,5,5,5,5,5, + 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, +@@ -120,10 +110,6 @@ + c->low= 0; + c->range= 0x1FE; + c->outstanding_count= 0; +-#ifdef STRICT_LIMITS +- c->sym_count =0; +-#endif +- + c->pb.bit_left++; //avoids firstBitFlag + } + +@@ -156,24 +142,20 @@ + } + + ff_h264_mlps_state[128+2*i+0]= +- ff_h264_mps_state[2*i+0]= 2*mps_state[i]+0; ++ h264_mps_state[2 * i + 0] = 2 * mps_state[i] + 0; + ff_h264_mlps_state[128+2*i+1]= +- ff_h264_mps_state[2*i+1]= 2*mps_state[i]+1; ++ h264_mps_state[2 * i + 1] = 2 * mps_state[i] + 1; + + if( i ){ +-#ifdef BRANCHLESS_CABAC_DECODER ++ ff_h264_lps_state[2*i+0]= + ff_h264_mlps_state[128-2*i-1]= 2*lps_state[i]+0; ++ ff_h264_lps_state[2*i+1]= + ff_h264_mlps_state[128-2*i-2]= 2*lps_state[i]+1; + }else{ ++ ff_h264_lps_state[2*i+0]= + ff_h264_mlps_state[128-2*i-1]= 1; ++ ff_h264_lps_state[2*i+1]= + ff_h264_mlps_state[128-2*i-2]= 0; +-#else +- ff_h264_lps_state[2*i+0]= 2*lps_state[i]+0; +- ff_h264_lps_state[2*i+1]= 2*lps_state[i]+1; +- }else{ +- ff_h264_lps_state[2*i+0]= 1; +- ff_h264_lps_state[2*i+1]= 0; +-#endif + } + } + } +@@ -185,6 +167,92 @@ + #include "avcodec.h" + #include "cabac.h" + ++static inline void put_cabac_bit(CABACContext *c, int b){ ++ put_bits(&c->pb, 1, b); ++ for(;c->outstanding_count; c->outstanding_count--){ ++ put_bits(&c->pb, 1, 1-b); ++ } ++} ++ ++static inline void renorm_cabac_encoder(CABACContext *c){ ++ while(c->range < 0x100){ ++ //FIXME optimize ++ if(c->low<0x100){ ++ put_cabac_bit(c, 0); ++ }else if(c->low<0x200){ ++ c->outstanding_count++; ++ c->low -= 0x100; ++ }else{ ++ put_cabac_bit(c, 1); ++ c->low -= 0x200; ++ } ++ ++ c->range+= c->range; ++ c->low += c->low; ++ } ++} ++ ++static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ ++ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; ++ ++ if(bit == ((*state)&1)){ ++ c->range -= RangeLPS; ++ *state = h264_mps_state[*state]; ++ }else{ ++ c->low += c->range - RangeLPS; ++ c->range = RangeLPS; ++ *state= ff_h264_lps_state[*state]; ++ } ++ ++ renorm_cabac_encoder(c); ++} ++ ++/** ++ * @param bit 0 -> write zero bit, !=0 write one bit ++ */ ++static void put_cabac_bypass(CABACContext *c, int bit){ ++ c->low += c->low; ++ ++ if(bit){ ++ c->low += c->range; ++ } ++//FIXME optimize ++ if(c->low<0x200){ ++ put_cabac_bit(c, 0); ++ }else if(c->low<0x400){ ++ c->outstanding_count++; ++ c->low -= 0x200; ++ }else{ ++ put_cabac_bit(c, 1); ++ c->low -= 0x400; ++ } ++} ++ ++/** ++ * ++ * @return the number of bytes written ++ */ ++static int put_cabac_terminate(CABACContext *c, int bit){ ++ c->range -= 2; ++ ++ if(!bit){ ++ renorm_cabac_encoder(c); ++ }else{ ++ c->low += c->range; ++ c->range= 2; ++ ++ renorm_cabac_encoder(c); ++ ++ assert(c->low <= 0x1FF); ++ put_cabac_bit(c, c->low>>9); ++ put_bits(&c->pb, 2, ((c->low>>7)&3)|1); ++ ++ flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong ++ } ++ ++ return (put_bits_count(&c->pb)+7)>>3; ++} ++ + int main(void){ + CABACContext c; + uint8_t b[9*SIZE]; +@@ -198,7 +266,8 @@ + ff_init_cabac_states(&c); + + for(i=0; i>8)&1; + } + + for(i=0; i ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Context Adaptive Binary Arithmetic Coder inline functions ++ */ ++ ++#ifndef AVCODEC_CABAC_FUNCTIONS_H ++#define AVCODEC_CABAC_FUNCTIONS_H ++ ++#include ++ ++#include "cabac.h" ++#include "config.h" ++ ++#if ARCH_X86 ++# include "x86/cabac.h" ++#endif ++ ++extern const uint8_t ff_h264_norm_shift[512]; ++extern uint8_t ff_h264_mlps_state[4*64]; ++extern uint8_t ff_h264_lps_range[4*2*64]; ///< rangeTabLPS ++ ++static void refill(CABACContext *c){ ++#if CABAC_BITS == 16 ++ c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); ++#else ++ c->low+= c->bytestream[0]<<1; ++#endif ++ c->low -= CABAC_MASK; ++ c->bytestream+= CABAC_BITS/8; ++} ++ ++static inline void renorm_cabac_decoder_once(CABACContext *c){ ++ int shift= (uint32_t)(c->range - 0x100)>>31; ++ c->range<<= shift; ++ c->low <<= shift; ++ if(!(c->low & CABAC_MASK)) ++ refill(c); ++} ++ ++#ifndef get_cabac_inline ++static void refill2(CABACContext *c){ ++ int i, x; ++ ++ x= c->low ^ (c->low-1); ++ i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)]; ++ ++ x= -CABAC_MASK; ++ ++#if CABAC_BITS == 16 ++ x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); ++#else ++ x+= c->bytestream[0]<<1; ++#endif ++ ++ c->low += x<bytestream+= CABAC_BITS/8; ++} ++ ++static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ ++ int s = *state; ++ int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s]; ++ int bit, lps_mask; ++ ++ c->range -= RangeLPS; ++ lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31; ++ ++ c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask; ++ c->range += (RangeLPS - c->range) & lps_mask; ++ ++ s^=lps_mask; ++ *state= (ff_h264_mlps_state+128)[s]; ++ bit= s&1; ++ ++ lps_mask= ff_h264_norm_shift[c->range]; ++ c->range<<= lps_mask; ++ c->low <<= lps_mask; ++ if(!(c->low & CABAC_MASK)) ++ refill2(c); ++ return bit; ++} ++#endif ++ ++static int av_noinline av_unused get_cabac_noinline(CABACContext *c, uint8_t * const state){ ++ return get_cabac_inline(c,state); ++} ++ ++static int av_unused get_cabac(CABACContext *c, uint8_t * const state){ ++ return get_cabac_inline(c,state); ++} ++ ++static int av_unused get_cabac_bypass(CABACContext *c){ ++ int range; ++ c->low += c->low; ++ ++ if(!(c->low & CABAC_MASK)) ++ refill(c); ++ ++ range= c->range<<(CABAC_BITS+1); ++ if(c->low < range){ ++ return 0; ++ }else{ ++ c->low -= range; ++ return 1; ++ } ++} ++ ++ ++#ifndef get_cabac_bypass_sign ++static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ ++ int range, mask; ++ c->low += c->low; ++ ++ if(!(c->low & CABAC_MASK)) ++ refill(c); ++ ++ range= c->range<<(CABAC_BITS+1); ++ c->low -= range; ++ mask= c->low >> 31; ++ range &= mask; ++ c->low += range; ++ return (val^mask)-mask; ++} ++#endif ++ ++/** ++ * ++ * @return the number of bytes read or 0 if no end ++ */ ++static int av_unused get_cabac_terminate(CABACContext *c){ ++ c->range -= 2; ++ if(c->low < c->range<<(CABAC_BITS+1)){ ++ renorm_cabac_decoder_once(c); ++ return 0; ++ }else{ ++ return c->bytestream - c->bytestream_start; ++ } ++} ++ ++#endif /* AVCODEC_CABAC_FUNCTIONS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cabac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cabac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cabac.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cabac.h 2012-05-14 14:08:53.544324082 +0200 +@@ -27,732 +27,25 @@ + #ifndef AVCODEC_CABAC_H + #define AVCODEC_CABAC_H + +-#include "put_bits.h" ++#include + +-//#undef NDEBUG +-#include +-#include "libavutil/x86_cpu.h" ++#include "put_bits.h" + + #define CABAC_BITS 16 + #define CABAC_MASK ((1<pb, 1, b); +- for(;c->outstanding_count; c->outstanding_count--){ +- put_bits(&c->pb, 1, 1-b); +- } +-} +- +-static inline void renorm_cabac_encoder(CABACContext *c){ +- while(c->range < 0x100){ +- //FIXME optimize +- if(c->low<0x100){ +- put_cabac_bit(c, 0); +- }else if(c->low<0x200){ +- c->outstanding_count++; +- c->low -= 0x100; +- }else{ +- put_cabac_bit(c, 1); +- c->low -= 0x200; +- } +- +- c->range+= c->range; +- c->low += c->low; +- } +-} +- +-#ifdef TEST +-static void put_cabac(CABACContext *c, uint8_t * const state, int bit){ +- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + *state]; +- +- if(bit == ((*state)&1)){ +- c->range -= RangeLPS; +- *state= ff_h264_mps_state[*state]; +- }else{ +- c->low += c->range - RangeLPS; +- c->range = RangeLPS; +- *state= ff_h264_lps_state[*state]; +- } +- +- renorm_cabac_encoder(c); +- +-#ifdef STRICT_LIMITS +- c->symCount++; +-#endif +-} +- +-static void put_cabac_static(CABACContext *c, int RangeLPS, int bit){ +- assert(c->range > RangeLPS); +- +- if(!bit){ +- c->range -= RangeLPS; +- }else{ +- c->low += c->range - RangeLPS; +- c->range = RangeLPS; +- } +- +- renorm_cabac_encoder(c); +- +-#ifdef STRICT_LIMITS +- c->symCount++; +-#endif +-} +- +-/** +- * @param bit 0 -> write zero bit, !=0 write one bit +- */ +-static void put_cabac_bypass(CABACContext *c, int bit){ +- c->low += c->low; +- +- if(bit){ +- c->low += c->range; +- } +-//FIXME optimize +- if(c->low<0x200){ +- put_cabac_bit(c, 0); +- }else if(c->low<0x400){ +- c->outstanding_count++; +- c->low -= 0x200; +- }else{ +- put_cabac_bit(c, 1); +- c->low -= 0x400; +- } +- +-#ifdef STRICT_LIMITS +- c->symCount++; +-#endif +-} +- +-/** +- * +- * @return the number of bytes written +- */ +-static int put_cabac_terminate(CABACContext *c, int bit){ +- c->range -= 2; +- +- if(!bit){ +- renorm_cabac_encoder(c); +- }else{ +- c->low += c->range; +- c->range= 2; +- +- renorm_cabac_encoder(c); +- +- assert(c->low <= 0x1FF); +- put_cabac_bit(c, c->low>>9); +- put_bits(&c->pb, 2, ((c->low>>7)&3)|1); +- +- flush_put_bits(&c->pb); //FIXME FIXME FIXME XXX wrong +- } +- +-#ifdef STRICT_LIMITS +- c->symCount++; +-#endif +- +- return (put_bits_count(&c->pb)+7)>>3; +-} +- +-/** +- * put (truncated) unary binarization. +- */ +-static void put_cabac_u(CABACContext *c, uint8_t * state, int v, int max, int max_index, int truncated){ +- int i; +- +- assert(v <= max); +- +-#if 1 +- for(i=0; i= m){ //FIXME optimize +- put_cabac_bypass(c, 1); +- v-= m; +- m+= m; +- } +- put_cabac_bypass(c, 0); +- while(m>>=1){ +- put_cabac_bypass(c, v&m); +- } +- } +- +- if(is_signed) +- put_cabac_bypass(c, sign); +- } +-} +-#endif /* TEST */ +- +-static void refill(CABACContext *c){ +-#if CABAC_BITS == 16 +- c->low+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); +-#else +- c->low+= c->bytestream[0]<<1; +-#endif +- c->low -= CABAC_MASK; +- c->bytestream+= CABAC_BITS/8; +-} +- +-#if ! ( ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) ) +-static void refill2(CABACContext *c){ +- int i, x; +- +- x= c->low ^ (c->low-1); +- i= 7 - ff_h264_norm_shift[x>>(CABAC_BITS-1)]; +- +- x= -CABAC_MASK; +- +-#if CABAC_BITS == 16 +- x+= (c->bytestream[0]<<9) + (c->bytestream[1]<<1); +-#else +- x+= c->bytestream[0]<<1; +-#endif +- +- c->low += x<bytestream+= CABAC_BITS/8; +-} +-#endif +- +-static inline void renorm_cabac_decoder(CABACContext *c){ +- while(c->range < 0x100){ +- c->range+= c->range; +- c->low+= c->low; +- if(!(c->low & CABAC_MASK)) +- refill(c); +- } +-} +- +-static inline void renorm_cabac_decoder_once(CABACContext *c){ +-#ifdef ARCH_X86_DISABLED +- int temp; +-#if 0 +- //P3:683 athlon:475 +- __asm__( +- "lea -0x100(%0), %2 \n\t" +- "shr $31, %2 \n\t" //FIXME 31->63 for x86-64 +- "shl %%cl, %0 \n\t" +- "shl %%cl, %1 \n\t" +- : "+r"(c->range), "+r"(c->low), "+c"(temp) +- ); +-#elif 0 +- //P3:680 athlon:474 +- __asm__( +- "cmp $0x100, %0 \n\t" +- "setb %%cl \n\t" //FIXME 31->63 for x86-64 +- "shl %%cl, %0 \n\t" +- "shl %%cl, %1 \n\t" +- : "+r"(c->range), "+r"(c->low), "+c"(temp) +- ); +-#elif 1 +- int temp2; +- //P3:665 athlon:517 +- __asm__( +- "lea -0x100(%0), %%eax \n\t" +- "cltd \n\t" +- "mov %0, %%eax \n\t" +- "and %%edx, %0 \n\t" +- "and %1, %%edx \n\t" +- "add %%eax, %0 \n\t" +- "add %%edx, %1 \n\t" +- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) +- ); +-#elif 0 +- int temp2; +- //P3:673 athlon:509 +- __asm__( +- "cmp $0x100, %0 \n\t" +- "sbb %%edx, %%edx \n\t" +- "mov %0, %%eax \n\t" +- "and %%edx, %0 \n\t" +- "and %1, %%edx \n\t" +- "add %%eax, %0 \n\t" +- "add %%edx, %1 \n\t" +- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) +- ); +-#else +- int temp2; +- //P3:677 athlon:511 +- __asm__( +- "cmp $0x100, %0 \n\t" +- "lea (%0, %0), %%eax \n\t" +- "lea (%1, %1), %%edx \n\t" +- "cmovb %%eax, %0 \n\t" +- "cmovb %%edx, %1 \n\t" +- : "+r"(c->range), "+r"(c->low), "+a"(temp), "+d"(temp2) +- ); +-#endif +-#else +- //P3:675 athlon:476 +- int shift= (uint32_t)(c->range - 0x100)>>31; +- c->range<<= shift; +- c->low <<= shift; +-#endif +- if(!(c->low & CABAC_MASK)) +- refill(c); +-} +- +-static av_always_inline int get_cabac_inline(CABACContext *c, uint8_t * const state){ +- //FIXME gcc generates duplicate load/stores for c->low and c->range +-#define LOW "0" +-#define RANGE "4" +-#if ARCH_X86_64 +-#define BYTESTART "16" +-#define BYTE "24" +-#define BYTEEND "32" +-#else +-#define BYTESTART "12" +-#define BYTE "16" +-#define BYTEEND "20" +-#endif +-#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) +- int bit; +- +-#ifndef BRANCHLESS_CABAC_DECODER +- __asm__ volatile( +- "movzbl (%1), %0 \n\t" +- "movl "RANGE "(%2), %%ebx \n\t" +- "movl "RANGE "(%2), %%edx \n\t" +- "andl $0xC0, %%ebx \n\t" +- "movzbl "MANGLE(ff_h264_lps_range)"(%0, %%ebx, 2), %%esi\n\t" +- "movl "LOW "(%2), %%ebx \n\t" +-//eax:state ebx:low, edx:range, esi:RangeLPS +- "subl %%esi, %%edx \n\t" +- "movl %%edx, %%ecx \n\t" +- "shll $17, %%ecx \n\t" +- "cmpl %%ecx, %%ebx \n\t" +- " ja 1f \n\t" +- +-#if 1 +- //athlon:4067 P3:4110 +- "lea -0x100(%%edx), %%ecx \n\t" +- "shr $31, %%ecx \n\t" +- "shl %%cl, %%edx \n\t" +- "shl %%cl, %%ebx \n\t" +-#else +- //athlon:4057 P3:4130 +- "cmp $0x100, %%edx \n\t" //FIXME avoidable +- "setb %%cl \n\t" +- "shl %%cl, %%edx \n\t" +- "shl %%cl, %%ebx \n\t" +-#endif +- "movzbl "MANGLE(ff_h264_mps_state)"(%0), %%ecx \n\t" +- "movb %%cl, (%1) \n\t" +-//eax:state ebx:low, edx:range, esi:RangeLPS +- "test %%bx, %%bx \n\t" +- " jnz 2f \n\t" +- "mov "BYTE "(%2), %%"REG_S" \n\t" +- "subl $0xFFFF, %%ebx \n\t" +- "movzwl (%%"REG_S"), %%ecx \n\t" +- "bswap %%ecx \n\t" +- "shrl $15, %%ecx \n\t" +- "add $2, %%"REG_S" \n\t" +- "addl %%ecx, %%ebx \n\t" +- "mov %%"REG_S", "BYTE "(%2) \n\t" +- "jmp 2f \n\t" +- "1: \n\t" +-//eax:state ebx:low, edx:range, esi:RangeLPS +- "subl %%ecx, %%ebx \n\t" +- "movl %%esi, %%edx \n\t" +- "movzbl " MANGLE(ff_h264_norm_shift) "(%%esi), %%ecx \n\t" +- "shll %%cl, %%ebx \n\t" +- "shll %%cl, %%edx \n\t" +- "movzbl "MANGLE(ff_h264_lps_state)"(%0), %%ecx \n\t" +- "movb %%cl, (%1) \n\t" +- "add $1, %0 \n\t" +- "test %%bx, %%bx \n\t" +- " jnz 2f \n\t" +- +- "mov "BYTE "(%2), %%"REG_c" \n\t" +- "movzwl (%%"REG_c"), %%esi \n\t" +- "bswap %%esi \n\t" +- "shrl $15, %%esi \n\t" +- "subl $0xFFFF, %%esi \n\t" +- "add $2, %%"REG_c" \n\t" +- "mov %%"REG_c", "BYTE "(%2) \n\t" +- +- "leal -1(%%ebx), %%ecx \n\t" +- "xorl %%ebx, %%ecx \n\t" +- "shrl $15, %%ecx \n\t" +- "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t" +- "neg %%ecx \n\t" +- "add $7, %%ecx \n\t" +- +- "shll %%cl , %%esi \n\t" +- "addl %%esi, %%ebx \n\t" +- "2: \n\t" +- "movl %%edx, "RANGE "(%2) \n\t" +- "movl %%ebx, "LOW "(%2) \n\t" +- :"=&a"(bit) //FIXME this is fragile gcc either runs out of registers or miscompiles it (for example if "+a"(bit) or "+m"(*state) is used +- :"r"(state), "r"(c) +- : "%"REG_c, "%ebx", "%edx", "%"REG_S, "memory" +- ); +- bit&=1; +-#else /* BRANCHLESS_CABAC_DECODER */ +- +- +-#if HAVE_FAST_CMOV +-#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\ +- "mov "tmp" , %%ecx \n\t"\ +- "shl $17 , "tmp" \n\t"\ +- "cmp "low" , "tmp" \n\t"\ +- "cmova %%ecx , "range" \n\t"\ +- "sbb %%ecx , %%ecx \n\t"\ +- "and %%ecx , "tmp" \n\t"\ +- "sub "tmp" , "low" \n\t"\ +- "xor %%ecx , "ret" \n\t" +-#else /* HAVE_FAST_CMOV */ +-#define BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\ +- "mov "tmp" , %%ecx \n\t"\ +- "shl $17 , "tmp" \n\t"\ +- "sub "low" , "tmp" \n\t"\ +- "sar $31 , "tmp" \n\t" /*lps_mask*/\ +- "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\ +- "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\ +- "add %%ecx , "range" \n\t" /*new range*/\ +- "shl $17 , %%ecx \n\t"\ +- "and "tmp" , %%ecx \n\t"\ +- "sub %%ecx , "low" \n\t"\ +- "xor "tmp" , "ret" \n\t" +-#endif /* HAVE_FAST_CMOV */ +- +- +-#define BRANCHLESS_GET_CABAC(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\ +- "movzbl "statep" , "ret" \n\t"\ +- "mov "range" , "tmp" \n\t"\ +- "and $0xC0 , "range" \n\t"\ +- "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\ +- "sub "range" , "tmp" \n\t"\ +- BRANCHLESS_GET_CABAC_UPDATE(ret, cabac, statep, low, lowword, range, tmp, tmpbyte)\ +- "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\ +- "shl %%cl , "range" \n\t"\ +- "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\ +- "mov "tmpbyte" , "statep" \n\t"\ +- "shl %%cl , "low" \n\t"\ +- "test "lowword" , "lowword" \n\t"\ +- " jnz 1f \n\t"\ +- "mov "BYTE"("cabac"), %%"REG_c" \n\t"\ +- "movzwl (%%"REG_c") , "tmp" \n\t"\ +- "bswap "tmp" \n\t"\ +- "shr $15 , "tmp" \n\t"\ +- "sub $0xFFFF , "tmp" \n\t"\ +- "add $2 , %%"REG_c" \n\t"\ +- "mov %%"REG_c" , "BYTE "("cabac") \n\t"\ +- "lea -1("low") , %%ecx \n\t"\ +- "xor "low" , %%ecx \n\t"\ +- "shr $15 , %%ecx \n\t"\ +- "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\ +- "neg %%ecx \n\t"\ +- "add $7 , %%ecx \n\t"\ +- "shl %%cl , "tmp" \n\t"\ +- "add "tmp" , "low" \n\t"\ +- "1: \n\t" +- +- __asm__ volatile( +- "movl "RANGE "(%2), %%esi \n\t" +- "movl "LOW "(%2), %%ebx \n\t" +- BRANCHLESS_GET_CABAC("%0", "%2", "(%1)", "%%ebx", "%%bx", "%%esi", "%%edx", "%%dl") +- "movl %%esi, "RANGE "(%2) \n\t" +- "movl %%ebx, "LOW "(%2) \n\t" +- +- :"=&a"(bit) +- :"r"(state), "r"(c) +- : "%"REG_c, "%ebx", "%edx", "%esi", "memory" +- ); +- bit&=1; +-#endif /* BRANCHLESS_CABAC_DECODER */ +-#else /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */ +- int s = *state; +- int RangeLPS= ff_h264_lps_range[2*(c->range&0xC0) + s]; +- int bit, lps_mask av_unused; +- +- c->range -= RangeLPS; +-#ifndef BRANCHLESS_CABAC_DECODER +- if(c->low < (c->range<<(CABAC_BITS+1))){ +- bit= s&1; +- *state= ff_h264_mps_state[s]; +- renorm_cabac_decoder_once(c); +- }else{ +- bit= ff_h264_norm_shift[RangeLPS]; +- c->low -= (c->range<<(CABAC_BITS+1)); +- *state= ff_h264_lps_state[s]; +- c->range = RangeLPS<low <<= bit; +- bit= (s&1)^1; +- +- if(!(c->low & CABAC_MASK)){ +- refill2(c); +- } +- } +-#else /* BRANCHLESS_CABAC_DECODER */ +- lps_mask= ((c->range<<(CABAC_BITS+1)) - c->low)>>31; +- +- c->low -= (c->range<<(CABAC_BITS+1)) & lps_mask; +- c->range += (RangeLPS - c->range) & lps_mask; +- +- s^=lps_mask; +- *state= (ff_h264_mlps_state+128)[s]; +- bit= s&1; +- +- lps_mask= ff_h264_norm_shift[c->range]; +- c->range<<= lps_mask; +- c->low <<= lps_mask; +- if(!(c->low & CABAC_MASK)) +- refill2(c); +-#endif /* BRANCHLESS_CABAC_DECODER */ +-#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) */ +- return bit; +-} +- +-static int av_noinline av_unused get_cabac_noinline(CABACContext *c, uint8_t * const state){ +- return get_cabac_inline(c,state); +-} +- +-static int av_unused get_cabac(CABACContext *c, uint8_t * const state){ +- return get_cabac_inline(c,state); +-} +- +-static int av_unused get_cabac_bypass(CABACContext *c){ +-#if 0 //not faster +- int bit; +- __asm__ volatile( +- "movl "RANGE "(%1), %%ebx \n\t" +- "movl "LOW "(%1), %%eax \n\t" +- "shl $17, %%ebx \n\t" +- "add %%eax, %%eax \n\t" +- "sub %%ebx, %%eax \n\t" +- "cltd \n\t" +- "and %%edx, %%ebx \n\t" +- "add %%ebx, %%eax \n\t" +- "test %%ax, %%ax \n\t" +- " jnz 1f \n\t" +- "movl "BYTE "(%1), %%"REG_b" \n\t" +- "subl $0xFFFF, %%eax \n\t" +- "movzwl (%%"REG_b"), %%ecx \n\t" +- "bswap %%ecx \n\t" +- "shrl $15, %%ecx \n\t" +- "addl $2, %%"REG_b" \n\t" +- "addl %%ecx, %%eax \n\t" +- "movl %%"REG_b", "BYTE "(%1) \n\t" +- "1: \n\t" +- "movl %%eax, "LOW "(%1) \n\t" +- +- :"=&d"(bit) +- :"r"(c) +- : "%eax", "%"REG_b, "%ecx", "memory" +- ); +- return bit+1; +-#else +- int range; +- c->low += c->low; +- +- if(!(c->low & CABAC_MASK)) +- refill(c); +- +- range= c->range<<(CABAC_BITS+1); +- if(c->low < range){ +- return 0; +- }else{ +- c->low -= range; +- return 1; +- } +-#endif +-} +- +- +-static av_always_inline int get_cabac_bypass_sign(CABACContext *c, int val){ +-#if ARCH_X86 && HAVE_EBX_AVAILABLE +- __asm__ volatile( +- "movl "RANGE "(%1), %%ebx \n\t" +- "movl "LOW "(%1), %%eax \n\t" +- "shl $17, %%ebx \n\t" +- "add %%eax, %%eax \n\t" +- "sub %%ebx, %%eax \n\t" +- "cltd \n\t" +- "and %%edx, %%ebx \n\t" +- "add %%ebx, %%eax \n\t" +- "xor %%edx, %%ecx \n\t" +- "sub %%edx, %%ecx \n\t" +- "test %%ax, %%ax \n\t" +- " jnz 1f \n\t" +- "mov "BYTE "(%1), %%"REG_b" \n\t" +- "subl $0xFFFF, %%eax \n\t" +- "movzwl (%%"REG_b"), %%edx \n\t" +- "bswap %%edx \n\t" +- "shrl $15, %%edx \n\t" +- "add $2, %%"REG_b" \n\t" +- "addl %%edx, %%eax \n\t" +- "mov %%"REG_b", "BYTE "(%1) \n\t" +- "1: \n\t" +- "movl %%eax, "LOW "(%1) \n\t" +- +- :"+c"(val) +- :"r"(c) +- : "%eax", "%"REG_b, "%edx", "memory" +- ); +- return val; +-#else +- int range, mask; +- c->low += c->low; +- +- if(!(c->low & CABAC_MASK)) +- refill(c); +- +- range= c->range<<(CABAC_BITS+1); +- c->low -= range; +- mask= c->low >> 31; +- range &= mask; +- c->low += range; +- return (val^mask)-mask; +-#endif +-} +- +-/** +- * +- * @return the number of bytes read or 0 if no end +- */ +-static int av_unused get_cabac_terminate(CABACContext *c){ +- c->range -= 2; +- if(c->low < c->range<<(CABAC_BITS+1)){ +- renorm_cabac_decoder_once(c); +- return 0; +- }else{ +- return c->bytestream - c->bytestream_start; +- } +-} +- +-#if 0 +-/** +- * Get (truncated) unary binarization. +- */ +-static int get_cabac_u(CABACContext *c, uint8_t * state, int max, int max_index, int truncated){ +- int i; +- +- for(i=0; i>=1){ +- v+= v + get_cabac_bypass(c); +- } +- i += v; +- +- if(is_signed && get_cabac_bypass(c)){ +- return -i; +- }else +- return i; +-} +-#endif /* 0 */ +- + #endif /* AVCODEC_CABAC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs.c 2012-05-14 14:08:53.546324122 +0200 +@@ -333,9 +333,9 @@ + const int mx= mv->x + src_x_offset*8; + const int my= mv->y + src_y_offset*8; + const int luma_xy= (mx&3) + ((my&3)<<2); +- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->l_stride; +- uint8_t * src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->c_stride; +- uint8_t * src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->c_stride; ++ uint8_t * src_y = pic->f.data[0] + (mx >> 2) + (my >> 2) * h->l_stride; ++ uint8_t * src_cb = pic->f.data[1] + (mx >> 3) + (my >> 3) * h->c_stride; ++ uint8_t * src_cr = pic->f.data[2] + (mx >> 3) + (my >> 3) * h->c_stride; + int extra_width= 0; //(s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; + int extra_height= extra_width; + int emu=0; +@@ -344,7 +344,7 @@ + const int pic_width = 16*h->mb_width; + const int pic_height = 16*h->mb_height; + +- if(!pic->data[0]) ++ if(!pic->f.data[0]) + return; + if(mx&7) extra_width -= 3; + if(my&7) extra_height -= 3; +@@ -602,9 +602,9 @@ + h->mbx = 0; + h->mby++; + /* re-calculate sample pointers */ +- h->cy = h->picture.data[0] + h->mby*16*h->l_stride; +- h->cu = h->picture.data[1] + h->mby*8*h->c_stride; +- h->cv = h->picture.data[2] + h->mby*8*h->c_stride; ++ h->cy = h->picture.f.data[0] + h->mby * 16 * h->l_stride; ++ h->cu = h->picture.f.data[1] + h->mby * 8 * h->c_stride; ++ h->cv = h->picture.f.data[2] + h->mby * 8 * h->c_stride; + if(h->mby == h->mb_height) { //frame end + return 0; + } +@@ -629,11 +629,11 @@ + h->mv[MV_FWD_X0] = ff_cavs_dir_mv; + set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); + h->pred_mode_Y[3] = h->pred_mode_Y[6] = NOT_AVAIL; +- h->cy = h->picture.data[0]; +- h->cu = h->picture.data[1]; +- h->cv = h->picture.data[2]; +- h->l_stride = h->picture.linesize[0]; +- h->c_stride = h->picture.linesize[1]; ++ h->cy = h->picture.f.data[0]; ++ h->cu = h->picture.f.data[1]; ++ h->cv = h->picture.f.data[2]; ++ h->l_stride = h->picture.f.linesize[0]; ++ h->c_stride = h->picture.f.linesize[1]; + h->luma_scan[2] = 8*h->l_stride; + h->luma_scan[3] = 8*h->l_stride+8; + h->mbx = h->mby = h->mbidx = 0; +@@ -658,8 +658,8 @@ + h->top_mv[1] = av_malloc((h->mb_width*2+1)*sizeof(cavs_vector)); + h->top_pred_Y = av_malloc( h->mb_width*2*sizeof(*h->top_pred_Y)); + h->top_border_y = av_malloc((h->mb_width+1)*16); +- h->top_border_u = av_malloc((h->mb_width)*10); +- h->top_border_v = av_malloc((h->mb_width)*10); ++ h->top_border_u = av_malloc( h->mb_width * 10); ++ h->top_border_v = av_malloc( h->mb_width * 10); + + /* alloc space for co-located MVs and types */ + h->col_mv = av_malloc( h->mb_width*h->mb_height*4*sizeof(cavs_vector)); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdata.h 2012-05-14 14:08:53.548324162 +0200 +@@ -497,9 +497,9 @@ + 5, 5, 5, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9 + }; + +-const int_fast8_t ff_left_modifier_l[8] = { 0,-1, 6,-1,-1, 7, 6, 7}; +-const int_fast8_t ff_top_modifier_l[8] = {-1, 1, 5,-1,-1, 5, 7, 7}; +-const int_fast8_t ff_left_modifier_c[7] = { 5,-1, 2,-1, 6, 5, 6}; +-const int_fast8_t ff_top_modifier_c[7] = { 4, 1,-1,-1, 4, 6, 6}; ++const int8_t ff_left_modifier_l[8] = { 0, -1, 6, -1, -1, 7, 6, 7 }; ++const int8_t ff_top_modifier_l[8] = { -1, 1, 5, -1, -1, 5, 7, 7 }; ++const int8_t ff_left_modifier_c[7] = { 5, -1, 2, -1, 6, 5, 6 }; ++const int8_t ff_top_modifier_c[7] = { 4, 1, -1, -1, 4, 6, 6 }; + + #endif /* AVCODEC_CAVSDATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdec.c 2012-05-14 14:08:53.550324203 +0200 +@@ -115,7 +115,8 @@ + static int decode_residual_block(AVSContext *h, GetBitContext *gb, + const struct dec_2dvlc *r, int esc_golomb_order, + int qp, uint8_t *dst, int stride) { +- int i, level_code, esc_code, level, run, mask; ++ int i, esc_code, level, mask; ++ unsigned int level_code, run; + DCTELEM level_buf[65]; + uint8_t run_buf[65]; + DCTELEM *block = h->block; +@@ -124,6 +125,8 @@ + level_code = get_ue_code(gb,r->golomb_order); + if(level_code >= ESCAPE_CODE) { + run = ((level_code - ESCAPE_CODE) >> 1) + 1; ++ if(run > 64) ++ return -1; + esc_code = get_ue_code(gb,esc_golomb_order); + level = esc_code + (run > r->max_run ? 1 : r->level_add[run]); + while(level > r->inc_limit) +@@ -163,7 +166,7 @@ + + /* get coded block pattern */ + int cbp= get_ue_golomb(&h->s.gb); +- if(cbp > 63){ ++ if(cbp > 63U){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal inter cbp\n"); + return -1; + } +@@ -189,7 +192,8 @@ + + static int decode_mb_i(AVSContext *h, int cbp_code) { + GetBitContext *gb = &h->s.gb; +- int block, pred_mode_uv; ++ unsigned pred_mode_uv; ++ int block; + uint8_t top[18]; + uint8_t *left = NULL; + uint8_t *d; +@@ -220,9 +224,9 @@ + ff_cavs_modify_mb_i(h, &pred_mode_uv); + + /* get coded block pattern */ +- if(h->pic_type == FF_I_TYPE) ++ if(h->pic_type == AV_PICTURE_TYPE_I) + cbp_code = get_ue_golomb(gb); +- if(cbp_code > 63){ ++ if(cbp_code > 63U){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal intra cbp\n"); + return -1; + } +@@ -424,7 +428,7 @@ + h->qp = get_bits(gb,6); + } + /* inter frame or second slice can have weighting params */ +- if((h->pic_type != FF_I_TYPE) || (!h->pic_structure && h->mby >= h->mb_width/2)) ++ if((h->pic_type != AV_PICTURE_TYPE_I) || (!h->pic_structure && h->mby >= h->mb_width/2)) + if(get_bits1(gb)) { //slice_weighting_flag + av_log(h->s.avctx, AV_LOG_ERROR, + "weighted prediction not yet supported\n"); +@@ -445,6 +449,8 @@ + if((show_bits_long(gb,24+align) & 0xFFFFFF) == 0x000001) { + skip_bits_long(gb,24+align); + h->stc = get_bits(gb,8); ++ if (h->stc >= h->mb_height) ++ return 0; + decode_slice_header(h,gb); + return 1; + } +@@ -470,22 +476,22 @@ + } + skip_bits(&s->gb,16);//bbv_dwlay + if(h->stc == PIC_PB_START_CODE) { +- h->pic_type = get_bits(&s->gb,2) + FF_I_TYPE; +- if(h->pic_type > FF_B_TYPE) { ++ h->pic_type = get_bits(&s->gb,2) + AV_PICTURE_TYPE_I; ++ if(h->pic_type > AV_PICTURE_TYPE_B) { + av_log(s->avctx, AV_LOG_ERROR, "illegal picture type\n"); + return -1; + } + /* make sure we have the reference frames we need */ +- if(!h->DPB[0].data[0] || +- (!h->DPB[1].data[0] && h->pic_type == FF_B_TYPE)) ++ if(!h->DPB[0].f.data[0] || ++ (!h->DPB[1].f.data[0] && h->pic_type == AV_PICTURE_TYPE_B)) + return -1; + } else { +- h->pic_type = FF_I_TYPE; ++ h->pic_type = AV_PICTURE_TYPE_I; + if(get_bits1(&s->gb)) + skip_bits(&s->gb,24);//time_code + /* old sample clips were all progressive and no low_delay, + bump stream revision if detected otherwise */ +- if((s->low_delay) || !(show_bits(&s->gb,9) & 1)) ++ if (s->low_delay || !(show_bits(&s->gb,9) & 1)) + h->stream_revision = 1; + /* similarly test top_field_first and repeat_first_field */ + else if(show_bits(&s->gb,11) & 3) +@@ -494,7 +500,7 @@ + skip_bits(&s->gb,1); //marker_bit + } + /* release last B frame */ +- if(h->picture.data[0]) ++ if(h->picture.f.data[0]) + s->avctx->release_buffer(s->avctx, (AVFrame *)&h->picture); + + s->avctx->get_buffer(s->avctx, (AVFrame *)&h->picture); +@@ -502,7 +508,7 @@ + h->picture.poc = get_bits(&s->gb,8)*2; + + /* get temporal distances and MV scaling factors */ +- if(h->pic_type != FF_B_TYPE) { ++ if(h->pic_type != AV_PICTURE_TYPE_B) { + h->dist[0] = (h->picture.poc - h->DPB[0].poc + 512) % 512; + } else { + h->dist[0] = (h->DPB[0].poc - h->picture.poc + 512) % 512; +@@ -510,7 +516,7 @@ + h->dist[1] = (h->picture.poc - h->DPB[1].poc + 512) % 512; + h->scale_den[0] = h->dist[0] ? 512/h->dist[0] : 0; + h->scale_den[1] = h->dist[1] ? 512/h->dist[1] : 0; +- if(h->pic_type == FF_B_TYPE) { ++ if(h->pic_type == AV_PICTURE_TYPE_B) { + h->sym_factor = h->dist[0]*h->scale_den[1]; + } else { + h->direct_den[0] = h->dist[0] ? 16384/h->dist[0] : 0; +@@ -529,12 +535,12 @@ + skip_bits1(&s->gb); //repeat_first_field + h->qp_fixed = get_bits1(&s->gb); + h->qp = get_bits(&s->gb,6); +- if(h->pic_type == FF_I_TYPE) { ++ if(h->pic_type == AV_PICTURE_TYPE_I) { + if(!h->progressive && !h->pic_structure) + skip_bits1(&s->gb);//what is this? + skip_bits(&s->gb,4); //reserved bits + } else { +- if(!(h->pic_type == FF_B_TYPE && h->pic_structure == 1)) ++ if(!(h->pic_type == AV_PICTURE_TYPE_B && h->pic_structure == 1)) + h->ref_flag = get_bits1(&s->gb); + skip_bits(&s->gb,4); //reserved bits + h->skip_mode_flag = get_bits1(&s->gb); +@@ -546,12 +552,12 @@ + } else { + h->alpha_offset = h->beta_offset = 0; + } +- if(h->pic_type == FF_I_TYPE) { ++ if(h->pic_type == AV_PICTURE_TYPE_I) { + do { + check_for_slice(h); + decode_mb_i(h, 0); + } while(ff_cavs_next_mb(h)); +- } else if(h->pic_type == FF_P_TYPE) { ++ } else if(h->pic_type == AV_PICTURE_TYPE_P) { + do { + if(check_for_slice(h)) + skip_count = -1; +@@ -567,7 +573,7 @@ + decode_mb_p(h,mb_type); + } + } while(ff_cavs_next_mb(h)); +- } else { /* FF_B_TYPE */ ++ } else { /* AV_PICTURE_TYPE_B */ + do { + if(check_for_slice(h)) + skip_count = -1; +@@ -584,8 +590,8 @@ + } + } while(ff_cavs_next_mb(h)); + } +- if(h->pic_type != FF_B_TYPE) { +- if(h->DPB[1].data[0]) ++ if(h->pic_type != AV_PICTURE_TYPE_B) { ++ if(h->DPB[1].f.data[0]) + s->avctx->release_buffer(s->avctx, (AVFrame *)&h->DPB[1]); + h->DPB[1] = h->DPB[0]; + h->DPB[0] = h->picture; +@@ -619,8 +625,8 @@ + s->low_delay = get_bits1(&s->gb); + h->mb_width = (s->width + 15) >> 4; + h->mb_height = (s->height + 15) >> 4; +- h->s.avctx->time_base.den = ff_frame_rate_tab[frame_rate_code].num; +- h->s.avctx->time_base.num = ff_frame_rate_tab[frame_rate_code].den; ++ h->s.avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_code].num; ++ h->s.avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_code].den; + h->s.avctx->width = s->width; + h->s.avctx->height = s->height; + if(!h->top_qp) +@@ -648,9 +654,10 @@ + s->avctx = avctx; + + if (buf_size == 0) { +- if(!s->low_delay && h->DPB[0].data[0]) { ++ if (!s->low_delay && h->DPB[0].f.data[0]) { + *data_size = sizeof(AVPicture); +- *picture = *(AVFrame *) &h->DPB[0]; ++ *picture = h->DPB[0].f; ++ memset(&h->DPB[0], 0, sizeof(h->DPB[0])); + } + return 0; + } +@@ -658,8 +665,8 @@ + buf_ptr = buf; + buf_end = buf + buf_size; + for(;;) { +- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &stc); +- if(stc & 0xFFFFFE00) ++ buf_ptr = avpriv_mpv_find_start_code(buf_ptr,buf_end, &stc); ++ if((stc & 0xFFFFFE00) || buf_ptr == buf_end) + return FFMAX(0, buf_ptr - buf - s->parse_context.last_index); + input_size = (buf_end - buf_ptr)*8; + switch(stc) { +@@ -669,9 +676,9 @@ + break; + case PIC_I_START_CODE: + if(!h->got_keyframe) { +- if(h->DPB[0].data[0]) ++ if(h->DPB[0].f.data[0]) + avctx->release_buffer(avctx, (AVFrame *)&h->DPB[0]); +- if(h->DPB[1].data[0]) ++ if(h->DPB[1].f.data[0]) + avctx->release_buffer(avctx, (AVFrame *)&h->DPB[1]); + h->got_keyframe = 1; + } +@@ -684,8 +691,8 @@ + if(decode_pic(h)) + break; + *data_size = sizeof(AVPicture); +- if(h->pic_type != FF_B_TYPE) { +- if(h->DPB[1].data[0]) { ++ if(h->pic_type != AV_PICTURE_TYPE_B) { ++ if(h->DPB[1].f.data[0]) { + *picture = *(AVFrame *) &h->DPB[1]; + } else { + *data_size = 0; +@@ -710,15 +717,14 @@ + } + + AVCodec ff_cavs_decoder = { +- "cavs", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CAVS, +- sizeof(AVSContext), +- ff_cavs_init, +- NULL, +- ff_cavs_end, +- cavs_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .name = "cavs", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CAVS, ++ .priv_data_size = sizeof(AVSContext), ++ .init = ff_cavs_init, ++ .close = ff_cavs_end, ++ .decode = cavs_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, + .flush= cavs_flush, + .long_name= NULL_IF_CONFIG_SMALL("Chinese AVS video (AVS1-P2, JiZhun profile)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavsdsp.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavsdsp.h 2012-05-14 14:08:53.551324223 +0200 +@@ -38,4 +38,4 @@ + void ff_cavsdsp_init(CAVSDSPContext* c, AVCodecContext *avctx); + void ff_cavsdsp_init_mmx(CAVSDSPContext* c, AVCodecContext *avctx); + +-#endif ++#endif /* AVCODEC_CAVSDSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs.h 2012-05-14 14:08:53.547324142 +0200 +@@ -233,15 +233,16 @@ + extern const uint8_t ff_cavs_chroma_qp[64]; + extern const uint8_t ff_cavs_scan3x3[4]; + extern const uint8_t ff_cavs_partition_flags[30]; +-extern const int_fast8_t ff_left_modifier_l[8]; +-extern const int_fast8_t ff_top_modifier_l[8]; +-extern const int_fast8_t ff_left_modifier_c[7]; +-extern const int_fast8_t ff_top_modifier_c[7]; ++extern const int8_t ff_left_modifier_l[8]; ++extern const int8_t ff_top_modifier_l[8]; ++extern const int8_t ff_left_modifier_c[7]; ++extern const int8_t ff_top_modifier_c[7]; + extern const cavs_vector ff_cavs_intra_mv; + extern const cavs_vector ff_cavs_un_mv; + extern const cavs_vector ff_cavs_dir_mv; + +-static inline void modify_pred(const int_fast8_t *mod_table, int *mode) { ++static inline void modify_pred(const int8_t *mod_table, int *mode) ++{ + *mode = mod_table[*mode]; + if(*mode < 0) { + av_log(NULL, AV_LOG_ERROR, "Illegal intra prediction mode\n"); +@@ -278,7 +279,7 @@ + set_mvs(&h->mv[MV_FWD_X0], BLK_16X16); + h->mv[MV_BWD_X0] = ff_cavs_intra_mv; + set_mvs(&h->mv[MV_BWD_X0], BLK_16X16); +- if(h->pic_type != FF_B_TYPE) ++ if(h->pic_type != AV_PICTURE_TYPE_B) + h->col_type_base[h->mbidx] = I_8X8; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cavs_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cavs_parser.c 2012-05-14 14:08:53.547324142 +0200 +@@ -30,7 +30,7 @@ + + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ + static int cavs_find_frame_end(ParseContext *pc, const uint8_t *buf, +@@ -98,10 +98,9 @@ + } + + AVCodecParser ff_cavsvideo_parser = { +- { CODEC_ID_CAVS }, +- sizeof(ParseContext1), +- NULL, +- cavsvideo_parse, +- ff_parse1_close, +- ff_mpeg4video_split, ++ .codec_ids = { CODEC_ID_CAVS }, ++ .priv_data_size = sizeof(ParseContext1), ++ .parser_parse = cavsvideo_parse, ++ .parser_close = ff_parse1_close, ++ .split = ff_mpeg4video_split, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cbrt_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cbrt_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cbrt_tablegen.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cbrt_tablegen.h 2012-05-14 14:08:53.551324223 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef CBRT_TABLEGEN_H +-#define CBRT_TABLEGEN_H ++#ifndef AVCODEC_CBRT_TABLEGEN_H ++#define AVCODEC_CBRT_TABLEGEN_H + + #include + #include +@@ -48,4 +48,4 @@ + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* CBRT_TABLEGEN_H */ ++#endif /* AVCODEC_CBRT_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cdgraphics.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cdgraphics.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cdgraphics.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cdgraphics.c 2012-05-14 14:08:53.552324243 +0200 +@@ -26,8 +26,8 @@ + * @file + * @brief CD Graphics Video Decoder + * @author Michael Tison +- * @sa http://wiki.multimedia.cx/index.php?title=CD_Graphics +- * @sa http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg ++ * @see http://wiki.multimedia.cx/index.php?title=CD_Graphics ++ * @see http://www.ccs.neu.edu/home/bchafy/cdb/info/cdg + */ + + /// default screen sizes +@@ -126,7 +126,7 @@ + r = ((color >> 8) & 0x000F) * 17; + g = ((color >> 4) & 0x000F) * 17; + b = ((color ) & 0x000F) * 17; +- palette[i + array_offset] = r << 16 | g << 8 | b; ++ palette[i + array_offset] = 0xFF << 24 | r << 16 | g << 8 | b; + } + cc->frame.palette_has_changed = 1; + } +@@ -368,15 +368,13 @@ + } + + AVCodec ff_cdgraphics_decoder = { +- "cdgraphics", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CDGRAPHICS, +- sizeof(CDGraphicsContext), +- cdg_decode_init, +- NULL, +- cdg_decode_end, +- cdg_decode_frame, +- CODEC_CAP_DR1, +- .max_lowres = 5, ++ .name = "cdgraphics", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CDGRAPHICS, ++ .priv_data_size = sizeof(CDGraphicsContext), ++ .init = cdg_decode_init, ++ .close = cdg_decode_end, ++ .decode = cdg_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("CD Graphics video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_filters.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_filters.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_filters.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_filters.c 2012-05-14 14:08:53.553324263 +0200 +@@ -58,7 +58,7 @@ + int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, + const int16_t *in, int buffer_length, + int filter_length, int stop_on_overflow, +- int rounder) ++ int shift, int rounder) + { + int i,n; + +@@ -67,7 +67,7 @@ + for (i = 1; i <= filter_length; i++) + sum -= filter_coeffs[i-1] * out[n-i]; + +- sum = (sum >> 12) + in[n]; ++ sum = ((sum >> 12) + in[n]) >> shift; + + if (sum + 0x8000 > 0xFFFFU) { + if (stop_on_overflow) +@@ -109,7 +109,7 @@ + old_out2 = out[-2]; + old_out3 = out[-1]; + for (n = 0; n <= buffer_length - 4; n+=4) { +- float tmp0,tmp1,tmp2,tmp3; ++ float tmp0,tmp1,tmp2; + float val; + + out0 = in[0]; +@@ -160,7 +160,6 @@ + tmp0 = out0; + tmp1 = out1; + tmp2 = out2; +- tmp3 = out3; + + out3 -= a * tmp2; + out2 -= a * tmp1; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_filters.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_filters.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_filters.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_filters.h 2012-05-14 14:08:53.554324283 +0200 +@@ -34,7 +34,7 @@ + * + * fc_out[n] = sum(i,0,len-1){ fc_in[i] * filter[(len + n - i)%len] } + * +- * \note fc_in and fc_out should not overlap! ++ * @note fc_in and fc_out should not overlap! + */ + void ff_celp_convolve_circ(int16_t *fc_out, const int16_t *fc_in, + const int16_t *filter, int len); +@@ -63,6 +63,7 @@ + * @param filter_length filter length (10 for 10th order LP filter) + * @param stop_on_overflow 1 - return immediately if overflow occurs + * 0 - ignore overflows ++ * @param shift the result is shifted right by this value + * @param rounder the amount to add for rounding (usually 0x800 or 0xfff) + * + * @return 1 if overflow occurred, 0 - otherwise +@@ -75,7 +76,7 @@ + int ff_celp_lp_synthesis_filter(int16_t *out, const int16_t *filter_coeffs, + const int16_t *in, int buffer_length, + int filter_length, int stop_on_overflow, +- int rounder); ++ int shift, int rounder); + + /** + * LP synthesis filter. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_math.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_math.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_math.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_math.c 2012-05-14 14:08:53.554324283 +0200 +@@ -25,6 +25,7 @@ + #include + + #include "avcodec.h" ++#include "mathops.h" + #include "celp_math.h" + + #ifdef G729_BITEXACT +@@ -196,6 +197,17 @@ + return (power_int << 15) + value; + } + ++int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length) ++{ ++ int i; ++ int64_t sum = 0; ++ ++ for (i = 0; i < length; i++) ++ sum += MUL16(a[i], b[i]); ++ ++ return sum; ++} ++ + float ff_dot_productf(const float* a, const float* b, int length) + { + float sum = 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_math.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_math.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/celp_math.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/celp_math.h 2012-05-14 14:08:53.555324303 +0200 +@@ -64,7 +64,17 @@ + } + + /** +- * returns the dot product. ++ * returns the dot product of 2 int16_t vectors. ++ * @param a input data array ++ * @param b input data array ++ * @param length number of elements ++ * ++ * @return dot product = sum of elementwise products ++ */ ++int64_t ff_dot_product(const int16_t *a, const int16_t *b, int length); ++ ++/** ++ * Return the dot product. + * @param a input data array + * @param b input data array + * @param length number of elements +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cga_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cga_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cga_data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cga_data.c 2012-05-14 14:08:53.556324323 +0200 +@@ -417,19 +417,19 @@ + }; + + const uint32_t ff_cga_palette[16] = { +- 0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAA5500, 0xAAAAAA, +- 0x555555, 0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF, ++ 0xFF000000, 0xFF0000AA, 0xFF00AA00, 0xFF00AAAA, 0xFFAA0000, 0xFFAA00AA, 0xFFAA5500, 0xFFAAAAAA, ++ 0xFF555555, 0xFF5555FF, 0xFF55FF55, 0xFF55FFFF, 0xFFFF5555, 0xFFFF55FF, 0xFFFFFF55, 0xFFFFFFFF, + }; + + const uint32_t ff_ega_palette[64] = { +- 0x000000, 0x0000AA, 0x00AA00, 0x00AAAA, 0xAA0000, 0xAA00AA, 0xAAAA00, 0xAAAAAA, +- 0x000055, 0x0000FF, 0x00AA55, 0x00AAFF, 0xAA0055, 0xAA00FF, 0xAAAA55, 0xAAAAFF, +- 0x005500, 0x0055AA, 0x00FF00, 0x00FFAA, 0xAA5500, 0xAA55AA, 0xAAFF00, 0xAAFFAA, +- 0x005555, 0x0055FF, 0x00FF55, 0x00FFFF, 0xAA5555, 0xAA55FF, 0xAAFF55, 0xAAFFFF, +- 0x550000, 0x5500AA, 0x55AA00, 0x55AAAA, 0xFF0000, 0xFF00AA, 0xFFAA00, 0xFFAAAA, +- 0x550055, 0x5500FF, 0x55AA55, 0x55AAFF, 0xFF0055, 0xFF00FF, 0xFFAA55, 0xFFAAFF, +- 0x555500, 0x5555AA, 0x55FF00, 0x55FFAA, 0xFF5500, 0xFF55AA, 0xFFFF00, 0xFFFFAA, +- 0x555555, 0x5555FF, 0x55FF55, 0x55FFFF, 0xFF5555, 0xFF55FF, 0xFFFF55, 0xFFFFFF ++ 0xFF000000, 0xFF0000AA, 0xFF00AA00, 0xFF00AAAA, 0xFFAA0000, 0xFFAA00AA, 0xFFAAAA00, 0xFFAAAAAA, ++ 0xFF000055, 0xFF0000FF, 0xFF00AA55, 0xFF00AAFF, 0xFFAA0055, 0xFFAA00FF, 0xFFAAAA55, 0xFFAAAAFF, ++ 0xFF005500, 0xFF0055AA, 0xFF00FF00, 0xFF00FFAA, 0xFFAA5500, 0xFFAA55AA, 0xFFAAFF00, 0xFFAAFFAA, ++ 0xFF005555, 0xFF0055FF, 0xFF00FF55, 0xFF00FFFF, 0xFFAA5555, 0xFFAA55FF, 0xFFAAFF55, 0xFFAAFFFF, ++ 0xFF550000, 0xFF5500AA, 0xFF55AA00, 0xFF55AAAA, 0xFFFF0000, 0xFFFF00AA, 0xFFFFAA00, 0xFFFFAAAA, ++ 0xFF550055, 0xFF5500FF, 0xFF55AA55, 0xFF55AAFF, 0xFFFF0055, 0xFFFF00FF, 0xFFFFAA55, 0xFFFFAAFF, ++ 0xFF555500, 0xFF5555AA, 0xFF55FF00, 0xFF55FFAA, 0xFFFF5500, 0xFFFF55AA, 0xFFFFFF00, 0xFFFFFFAA, ++ 0xFF555555, 0xFF5555FF, 0xFF55FF55, 0xFF55FFFF, 0xFFFF5555, 0xFFFF55FF, 0xFFFFFF55, 0xFFFFFFFF + }; + + void ff_draw_pc_font(uint8_t *dst, int linesize, const uint8_t *font, int font_height, int ch, int fg, int bg) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cga_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cga_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cga_data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cga_data.h 2012-05-14 14:08:53.556324323 +0200 +@@ -45,4 +45,4 @@ + */ + void ff_draw_pc_font(uint8_t *dst, int linesize, const uint8_t *font, int font_height, int ch, int fg, int bg); + +-#endif ++#endif /* AVCODEC_CGA_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cinepak.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cinepak.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cinepak.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cinepak.c 2012-05-14 14:08:53.558324364 +0200 +@@ -22,10 +22,11 @@ + /** + * @file + * Cinepak video decoder +- * by Ewald Snel +- * For more information on the Cinepak algorithm, visit: ++ * @author Ewald Snel ++ * ++ * @see For more information on the Cinepak algorithm, visit: + * http://www.csse.monash.edu.au/~timf/ +- * For more information on the quirky data inside Sega FILM/CPK files, visit: ++ * @see For more information on the quirky data inside Sega FILM/CPK files, visit: + * http://wiki.multimedia.cx/index.php?title=Sega_FILM + */ + +@@ -67,6 +68,7 @@ + + int sega_film_skip_bytes; + ++ uint32_t pal[256]; + } CinepakContext; + + static void cinepak_decode_codebook (cvid_codebook *codebook, +@@ -146,7 +148,7 @@ + for (x=strip->x1; x < strip->x2; x+=4) { + if ((chunk_id & 0x01) && !(mask >>= 1)) { + if ((data + 4) > eod) +- return -1; ++ return AVERROR_INVALIDDATA; + + flag = AV_RB32 (data); + data += 4; +@@ -156,7 +158,7 @@ + if (!(chunk_id & 0x01) || (flag & mask)) { + if (!(chunk_id & 0x02) && !(mask >>= 1)) { + if ((data + 4) > eod) +- return -1; ++ return AVERROR_INVALIDDATA; + + flag = AV_RB32 (data); + data += 4; +@@ -165,7 +167,7 @@ + + if ((chunk_id & 0x02) || (~flag & mask)) { + if (data >= eod) +- return -1; ++ return AVERROR_INVALIDDATA; + + codebook = &strip->v1_codebook[*data++]; + s->frame.data[0][iy[0] + 0] = codebook->y0; +@@ -206,7 +208,7 @@ + + } else if (flag & mask) { + if ((data + 4) > eod) +- return -1; ++ return AVERROR_INVALIDDATA; + + codebook = &strip->v4_codebook[*data++]; + s->frame.data[0][iy[0] + 0] = codebook->y0; +@@ -268,16 +270,16 @@ + int chunk_id, chunk_size; + + /* coordinate sanity checks */ +- if (strip->x1 >= s->width || strip->x2 > s->width || +- strip->y1 >= s->height || strip->y2 > s->height || ++ if (strip->x2 > s->width || ++ strip->y2 > s->height || + strip->x1 >= strip->x2 || strip->y1 >= strip->y2) +- return -1; ++ return AVERROR_INVALIDDATA; + + while ((data + 4) <= eod) { + chunk_id = data[0]; + chunk_size = AV_RB24 (&data[1]) - 4; + if(chunk_size < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + data += 4; + chunk_size = ((data + chunk_size) > eod) ? (eod - data) : chunk_size; +@@ -310,7 +312,7 @@ + data += chunk_size; + } + +- return -1; ++ return AVERROR_INVALIDDATA; + } + + static int cinepak_decode (CinepakContext *s) +@@ -321,21 +323,27 @@ + int encoded_buf_size; + + if (s->size < 10) +- return -1; ++ return AVERROR_INVALIDDATA; + + frame_flags = s->data[0]; + num_strips = AV_RB16 (&s->data[8]); +- encoded_buf_size = ((s->data[1] << 16) | AV_RB16 (&s->data[2])); ++ encoded_buf_size = AV_RB24(&s->data[1]); + + /* if this is the first frame, check for deviant Sega FILM data */ + if (s->sega_film_skip_bytes == -1) { +- if (encoded_buf_size != s->size) { ++ if (!encoded_buf_size) { ++ av_log_ask_for_sample(s->avctx, "encoded_buf_size is 0"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (encoded_buf_size != s->size && (s->size % encoded_buf_size) != 0) { + /* If the encoded frame size differs from the frame size as indicated + * by the container file, this data likely comes from a Sega FILM/CPK file. + * If the frame header is followed by the bytes FE 00 00 06 00 00 then + * this is probably one of the two known files that have 6 extra bytes +- * after the frame header. Else, assume 2 extra bytes. */ +- if ((s->data[10] == 0xFE) && ++ * after the frame header. Else, assume 2 extra bytes. The container ++ * size also cannot be a multiple of the encoded size. */ ++ if (s->size >= 16 && ++ (s->data[10] == 0xFE) && + (s->data[11] == 0x00) && + (s->data[12] == 0x00) && + (s->data[13] == 0x06) && +@@ -350,12 +358,13 @@ + + s->data += 10 + s->sega_film_skip_bytes; + +- if (num_strips > MAX_STRIPS) +- num_strips = MAX_STRIPS; ++ num_strips = FFMIN(num_strips, MAX_STRIPS); ++ ++ s->frame.key_frame = 0; + + for (i=0; i < num_strips; i++) { + if ((s->data + 12) > eod) +- return -1; ++ return AVERROR_INVALIDDATA; + + s->strips[i].id = s->data[0]; + s->strips[i].y1 = y0; +@@ -363,7 +372,12 @@ + s->strips[i].y2 = y0 + AV_RB16 (&s->data[8]); + s->strips[i].x2 = s->avctx->width; + ++ if (s->strips[i].id == 0x10) ++ s->frame.key_frame = 1; ++ + strip_size = AV_RB24 (&s->data[1]) - 12; ++ if (strip_size < 0) ++ return AVERROR_INVALIDDATA; + s->data += 12; + strip_size = ((s->data + strip_size) > eod) ? (eod - s->data) : strip_size; + +@@ -395,7 +409,7 @@ + s->sega_film_skip_bytes = -1; /* uninitialized state */ + + // check for paletted data +- if ((avctx->palctrl == NULL) || (avctx->bits_per_coded_sample == 40)) { ++ if (avctx->bits_per_coded_sample != 8) { + s->palette_video = 0; + avctx->pix_fmt = PIX_FMT_YUV420P; + } else { +@@ -403,6 +417,7 @@ + avctx->pix_fmt = PIX_FMT_PAL8; + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -413,31 +428,33 @@ + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ int ret = 0, buf_size = avpkt->size; + CinepakContext *s = avctx->priv_data; + + s->data = buf; + s->size = buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE; +- if (avctx->reget_buffer(avctx, &s->frame)) { ++ if ((ret = avctx->reget_buffer(avctx, &s->frame))) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +- return -1; ++ return ret; + } + +- cinepak_decode(s); +- + if (s->palette_video) { +- memcpy (s->frame.data[1], avctx->palctrl->palette, AVPALETTE_SIZE); +- if (avctx->palctrl->palette_changed) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ if (pal) { + s->frame.palette_has_changed = 1; +- avctx->palctrl->palette_changed = 0; +- } else +- s->frame.palette_has_changed = 0; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); ++ } + } + ++ cinepak_decode(s); ++ ++ if (s->palette_video) ++ memcpy (s->frame.data[1], s->pal, AVPALETTE_SIZE); ++ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + +@@ -456,14 +473,13 @@ + } + + AVCodec ff_cinepak_decoder = { +- "cinepak", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CINEPAK, +- sizeof(CinepakContext), +- cinepak_decode_init, +- NULL, +- cinepak_decode_end, +- cinepak_decode_frame, +- CODEC_CAP_DR1, ++ .name = "cinepak", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CINEPAK, ++ .priv_data_size = sizeof(CinepakContext), ++ .init = cinepak_decode_init, ++ .close = cinepak_decode_end, ++ .decode = cinepak_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Cinepak"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cljr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cljr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cljr.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cljr.c 2012-05-14 14:08:53.559324384 +0200 +@@ -25,143 +25,181 @@ + */ + + #include "avcodec.h" +-#include "dsputil.h" ++#include "libavutil/opt.h" + #include "get_bits.h" ++#include "put_bits.h" + +-/* Disable the encoder. */ +-#undef CONFIG_CLJR_ENCODER +-#define CONFIG_CLJR_ENCODER 0 +- +-typedef struct CLJRContext{ +- AVCodecContext *avctx; +- AVFrame picture; +- int delta[16]; +- int offset[4]; +- GetBitContext gb; ++typedef struct CLJRContext { ++ AVClass *avclass; ++ AVFrame picture; ++ int dither_type; + } CLJRContext; + ++static av_cold int common_init(AVCodecContext *avctx) ++{ ++ CLJRContext * const a = avctx->priv_data; ++ ++ avcodec_get_frame_defaults(&a->picture); ++ avctx->coded_frame = &a->picture; ++ ++ return 0; ++} ++ ++#if CONFIG_CLJR_DECODER + static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ int buf_size = avpkt->size; + CLJRContext * const a = avctx->priv_data; ++ GetBitContext gb; + AVFrame *picture = data; +- AVFrame * const p= (AVFrame*)&a->picture; ++ AVFrame * const p = &a->picture; + int x, y; + +- if(p->data[0]) ++ if (p->data[0]) + avctx->release_buffer(avctx, p); + +- if(buf_size/avctx->height < avctx->width) { +- av_log(avctx, AV_LOG_ERROR, "Resolution larger than buffer size. Invalid header?\n"); +- return -1; ++ if (avctx->height <= 0 || avctx->width <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid width or height\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (buf_size / avctx->height < avctx->width) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Resolution larger than buffer size. Invalid header?\n"); ++ return AVERROR_INVALIDDATA; + } + +- p->reference= 0; +- if(avctx->get_buffer(avctx, p) < 0){ ++ p->reference = 0; ++ if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; +- p->key_frame= 1; ++ p->pict_type = AV_PICTURE_TYPE_I; ++ p->key_frame = 1; + +- init_get_bits(&a->gb, buf, buf_size); ++ init_get_bits(&gb, buf, buf_size * 8); + +- for(y=0; yheight; y++){ +- uint8_t *luma= &a->picture.data[0][ y*a->picture.linesize[0] ]; +- uint8_t *cb= &a->picture.data[1][ y*a->picture.linesize[1] ]; +- uint8_t *cr= &a->picture.data[2][ y*a->picture.linesize[2] ]; +- for(x=0; xwidth; x+=4){ +- luma[3] = get_bits(&a->gb, 5) << 3; +- luma[2] = get_bits(&a->gb, 5) << 3; +- luma[1] = get_bits(&a->gb, 5) << 3; +- luma[0] = get_bits(&a->gb, 5) << 3; +- luma+= 4; +- *(cb++) = get_bits(&a->gb, 6) << 2; +- *(cr++) = get_bits(&a->gb, 6) << 2; ++ for (y = 0; y < avctx->height; y++) { ++ uint8_t *luma = &a->picture.data[0][y * a->picture.linesize[0]]; ++ uint8_t *cb = &a->picture.data[1][y * a->picture.linesize[1]]; ++ uint8_t *cr = &a->picture.data[2][y * a->picture.linesize[2]]; ++ for (x = 0; x < avctx->width; x += 4) { ++ luma[3] = (get_bits(&gb, 5)*33) >> 2; ++ luma[2] = (get_bits(&gb, 5)*33) >> 2; ++ luma[1] = (get_bits(&gb, 5)*33) >> 2; ++ luma[0] = (get_bits(&gb, 5)*33) >> 2; ++ luma += 4; ++ *(cb++) = get_bits(&gb, 6) << 2; ++ *(cr++) = get_bits(&gb, 6) << 2; + } + } + +- *picture= *(AVFrame*)&a->picture; ++ *picture = a->picture; + *data_size = sizeof(AVPicture); + +- emms_c(); +- + return buf_size; + } + +-#if CONFIG_CLJR_ENCODER +-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ +- CLJRContext * const a = avctx->priv_data; +- AVFrame *pict = data; +- AVFrame * const p= (AVFrame*)&a->picture; +- int size; +- +- *p = *pict; +- p->pict_type= FF_I_TYPE; +- p->key_frame= 1; +- +- emms_c(); +- +- align_put_bits(&a->pb); +- while(get_bit_count(&a->pb)&31) +- put_bits(&a->pb, 8, 0); +- +- size= get_bit_count(&a->pb)/32; +- +- return size*4; +-} +-#endif +- +-static av_cold void common_init(AVCodecContext *avctx){ +- CLJRContext * const a = avctx->priv_data; +- +- avctx->coded_frame= (AVFrame*)&a->picture; +- a->avctx= avctx; ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV411P; ++ return common_init(avctx); + } + +-static av_cold int decode_init(AVCodecContext *avctx){ +- +- common_init(avctx); +- +- avctx->pix_fmt= PIX_FMT_YUV411P; ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ CLJRContext *a = avctx->priv_data; + ++ if (a->picture.data[0]) ++ avctx->release_buffer(avctx, &a->picture); + return 0; + } + ++AVCodec ff_cljr_decoder = { ++ .name = "cljr", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CLJR, ++ .priv_data_size = sizeof(CLJRContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), ++}; ++#endif ++ + #if CONFIG_CLJR_ENCODER +-static av_cold int encode_init(AVCodecContext *avctx){ ++static int encode_frame(AVCodecContext *avctx, unsigned char *buf, ++ int buf_size, void *data) ++{ ++ CLJRContext *a = avctx->priv_data; ++ PutBitContext pb; ++ AVFrame *p = data; ++ int x, y; ++ uint32_t dither= avctx->frame_number; ++ static const uint32_t ordered_dither[2][2] = ++ { ++ { 0x10400000, 0x104F0000 }, ++ { 0xCB2A0000, 0xCB250000 }, ++ }; ++ ++ p->pict_type = AV_PICTURE_TYPE_I; ++ p->key_frame = 1; ++ ++ init_put_bits(&pb, buf, buf_size / 8); ++ ++ for (y = 0; y < avctx->height; y++) { ++ uint8_t *luma = &p->data[0][y * p->linesize[0]]; ++ uint8_t *cb = &p->data[1][y * p->linesize[1]]; ++ uint8_t *cr = &p->data[2][y * p->linesize[2]]; ++ for (x = 0; x < avctx->width; x += 4) { ++ switch (a->dither_type) { ++ case 0: dither = 0x492A0000; break; ++ case 1: dither = dither * 1664525 + 1013904223; break; ++ case 2: dither = ordered_dither[ y&1 ][ (x>>2)&1 ];break; ++ } ++ put_bits(&pb, 5, (249*(luma[3] + (dither>>29) )) >> 11); ++ put_bits(&pb, 5, (249*(luma[2] + ((dither>>26)&7))) >> 11); ++ put_bits(&pb, 5, (249*(luma[1] + ((dither>>23)&7))) >> 11); ++ put_bits(&pb, 5, (249*(luma[0] + ((dither>>20)&7))) >> 11); ++ luma += 4; ++ put_bits(&pb, 6, (253*(*(cb++) + ((dither>>18)&3))) >> 10); ++ put_bits(&pb, 6, (253*(*(cr++) + ((dither>>16)&3))) >> 10); ++ } ++ } + +- common_init(avctx); ++ flush_put_bits(&pb); + +- return 0; ++ return put_bits_count(&pb) / 8; + } +-#endif + +-AVCodec ff_cljr_decoder = { +- "cljr", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CLJR, +- sizeof(CLJRContext), +- decode_init, +- NULL, +- NULL, +- decode_frame, +- CODEC_CAP_DR1, +- .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), ++#define OFFSET(x) offsetof(CLJRContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "dither_type", "Dither type", OFFSET(dither_type), AV_OPT_TYPE_INT, { .dbl=1 }, 0, 2, VE}, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "cljr encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, + }; + +-#if CONFIG_CLJR_ENCODER + AVCodec ff_cljr_encoder = { +- "cljr", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CLJR, +- sizeof(CLJRContext), +- encode_init, +- encode_frame, +- //encode_end, +- .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), ++ .name = "cljr", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CLJR, ++ .priv_data_size = sizeof(CLJRContext), ++ .init = common_init, ++ .encode = encode_frame, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, ++ PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Cirrus Logic AccuPak"), ++ .priv_class = &class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/codec_names.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/codec_names.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/codec_names.sh 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/codec_names.sh 2012-05-14 14:08:53.559324384 +0200 +@@ -0,0 +1,84 @@ ++#!/bin/sh ++ ++# Copyright (c) 2011 Nicolas George ++# ++# This file is part of FFmpeg. ++# ++# FFmpeg is free software; you can redistribute it and/or ++# modify it under the terms of the GNU Lesser General Public ++# License as published by the Free Software Foundation; either ++# version 2.1 of the License, or (at your option) any later version. ++# ++# FFmpeg 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 ++# Lesser General Public License for more details. ++# ++# You should have received a copy of the GNU Lesser General Public ++# License along with FFmpeg; if not, write to the Free Software Foundation, ++# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ ++set -e ++ ++config="$1" ++out="$2" ++test -n "$out" ++ ++outval="" ++ ++add_line () { ++ outval="$outval$* ++" ++} ++ ++parse_config_h () { ++ while read define var value; do ++ case "$define $var $value" in ++ "#define CONFIG_"*_*" 1") eval "$var=1";; ++ esac ++ done ++} ++ ++define_codecid () { ++ id="$1" ++ n=${1#CODEC_ID_} ++ add_line "case ${id}:" ++ eval "c=\${CONFIG_${n}_DECODER}:\${CONFIG_${n}_ENCODER}" ++ case "$c" in ++ 1:*) s="decoder";; ++ *:1) s="encoder";; ++ *) s="";; ++ esac ++ case "$s" in ++ "") add_line " return \"$n\";" ;; ++ *) ++ add_line " { extern AVCodec ff_${n}_${s};" ++ add_line " return ff_${n}_${s}.name; }" ++ ;; ++ esac ++} ++ ++parse_enum_codecid () { ++ while read line; do ++ case "$line" in ++ "};") break;; ++ *CODEC_ID_FIRST*=*) ;; ++ CODEC_ID_*) define_codecid ${line%%[=,]*};; ++ esac ++ done ++} ++ ++parse_avcodec_h () { ++ while read line; do ++ case "$line" in ++ "enum CodecID {") parse_enum_codecid; break;; ++ esac ++ done ++} ++ ++parse_config_h < "$config" ++parse_avcodec_h # use stdin ++sed -e '/case.*:/!y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/' \ ++ -e 's/extern avcodec /extern AVCodec /' > "$out" < +-#include +-#include +- + #include "libavutil/lfg.h" +-#include "libavutil/random_seed.h" + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" + #include "bytestream.h" + #include "fft.h" ++#include "libavutil/audioconvert.h" ++#include "sinewin.h" + + #include "cookdata.h" + +@@ -60,11 +57,10 @@ + #define MONO 0x1000001 + #define STEREO 0x1000002 + #define JOINT_STEREO 0x1000003 +-#define MC_COOK 0x2000000 //multichannel Cook, not supported ++#define MC_COOK 0x2000000 // multichannel Cook, not supported + + #define SUBBAND_SIZE 20 + #define MAX_SUBPACKETS 5 +-//#define COOKDEBUG + + typedef struct { + int *now; +@@ -106,26 +102,27 @@ + * The following 5 functions provide the lowlevel arithmetic on + * the internal audio buffers. + */ +- void (* scalar_dequant)(struct cook *q, int index, int quant_index, +- int* subband_coef_index, int* subband_coef_sign, +- float* mlt_p); +- +- void (* decouple) (struct cook *q, +- COOKSubpacket *p, +- int subband, +- float f1, float f2, +- float *decode_buffer, +- float *mlt_buffer1, float *mlt_buffer2); ++ void (*scalar_dequant)(struct cook *q, int index, int quant_index, ++ int *subband_coef_index, int *subband_coef_sign, ++ float *mlt_p); ++ ++ void (*decouple)(struct cook *q, ++ COOKSubpacket *p, ++ int subband, ++ float f1, float f2, ++ float *decode_buffer, ++ float *mlt_buffer1, float *mlt_buffer2); + +- void (* imlt_window) (struct cook *q, float *buffer1, +- cook_gains *gains_ptr, float *previous_buffer); ++ void (*imlt_window)(struct cook *q, float *buffer1, ++ cook_gains *gains_ptr, float *previous_buffer); + +- void (* interpolate) (struct cook *q, float* buffer, +- int gain_index, int gain_index_next); ++ void (*interpolate)(struct cook *q, float *buffer, ++ int gain_index, int gain_index_next); + +- void (* saturate_output) (struct cook *q, int chan, int16_t *out); ++ void (*saturate_output)(struct cook *q, int chan, float *out); + + AVCodecContext* avctx; ++ AVFrame frame; + GetBitContext gb; + /* stream data */ + int nb_channels; +@@ -135,6 +132,7 @@ + int samples_per_channel; + /* states */ + AVLFG random_state; ++ int discarded_packets; + + /* transform data */ + FFTContext mdct_ctx; +@@ -142,7 +140,7 @@ + + /* VLC data */ + VLC envelope_quant_index[13]; +- VLC sqvh[7]; //scalar quantization ++ VLC sqvh[7]; // scalar quantization + + /* generatable tables and related variables */ + int gain_size_factor; +@@ -151,7 +149,7 @@ + /* data buffers */ + + uint8_t* decoded_bytes_buffer; +- DECLARE_ALIGNED(16, float,mono_mdct_output)[2048]; ++ DECLARE_ALIGNED(32, float, mono_mdct_output)[2048]; + float decode_buffer_1[1024]; + float decode_buffer_2[1024]; + float decode_buffer_0[1060]; /* static allocation for joint decode */ +@@ -164,127 +162,99 @@ + static float pow2tab[127]; + static float rootpow2tab[127]; + +-/* debug functions */ +- +-#ifdef COOKDEBUG +-static void dump_float_table(float* table, int size, int delimiter) { +- int i=0; +- av_log(NULL,AV_LOG_ERROR,"\n[%d]: ",i); +- for (i=0 ; igain_size_factor = q->samples_per_channel/8; +- for (i=0 ; i<23 ; i++) { +- q->gain_table[i] = pow(pow2tab[i+52] , +- (1.0/(double)q->gain_size_factor)); +- } ++ q->gain_size_factor = q->samples_per_channel / 8; ++ for (i = 0; i < 23; i++) ++ q->gain_table[i] = pow(pow2tab[i + 52], ++ (1.0 / (double) q->gain_size_factor)); + } + + +-static av_cold int init_cook_vlc_tables(COOKContext *q) { ++static av_cold int init_cook_vlc_tables(COOKContext *q) ++{ + int i, result; + + result = 0; +- for (i=0 ; i<13 ; i++) { +- result |= init_vlc (&q->envelope_quant_index[i], 9, 24, +- envelope_quant_index_huffbits[i], 1, 1, +- envelope_quant_index_huffcodes[i], 2, 2, 0); ++ for (i = 0; i < 13; i++) { ++ result |= init_vlc(&q->envelope_quant_index[i], 9, 24, ++ envelope_quant_index_huffbits[i], 1, 1, ++ envelope_quant_index_huffcodes[i], 2, 2, 0); + } +- av_log(q->avctx,AV_LOG_DEBUG,"sqvh VLC init\n"); +- for (i=0 ; i<7 ; i++) { +- result |= init_vlc (&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], +- cvh_huffbits[i], 1, 1, +- cvh_huffcodes[i], 2, 2, 0); ++ av_log(q->avctx, AV_LOG_DEBUG, "sqvh VLC init\n"); ++ for (i = 0; i < 7; i++) { ++ result |= init_vlc(&q->sqvh[i], vhvlcsize_tab[i], vhsize_tab[i], ++ cvh_huffbits[i], 1, 1, ++ cvh_huffcodes[i], 2, 2, 0); + } + +- for(i=0;inum_subpackets;i++){ +- if (q->subpacket[i].joint_stereo==1){ +- result |= init_vlc (&q->subpacket[i].ccpl, 6, (1<subpacket[i].js_vlc_bits)-1, +- ccpl_huffbits[q->subpacket[i].js_vlc_bits-2], 1, 1, +- ccpl_huffcodes[q->subpacket[i].js_vlc_bits-2], 2, 2, 0); +- av_log(q->avctx,AV_LOG_DEBUG,"subpacket %i Joint-stereo VLC used.\n",i); ++ for (i = 0; i < q->num_subpackets; i++) { ++ if (q->subpacket[i].joint_stereo == 1) { ++ result |= init_vlc(&q->subpacket[i].ccpl, 6, (1 << q->subpacket[i].js_vlc_bits) - 1, ++ ccpl_huffbits[q->subpacket[i].js_vlc_bits - 2], 1, 1, ++ ccpl_huffcodes[q->subpacket[i].js_vlc_bits - 2], 2, 2, 0); ++ av_log(q->avctx, AV_LOG_DEBUG, "subpacket %i Joint-stereo VLC used.\n", i); + } + } + +- av_log(q->avctx,AV_LOG_DEBUG,"VLC tables initialized.\n"); ++ av_log(q->avctx, AV_LOG_DEBUG, "VLC tables initialized.\n"); + return result; + } + +-static av_cold int init_cook_mlt(COOKContext *q) { +- int j; ++static av_cold int init_cook_mlt(COOKContext *q) ++{ ++ int j, ret; + int mlt_size = q->samples_per_channel; + +- if ((q->mlt_window = av_malloc(sizeof(float)*mlt_size)) == 0) +- return -1; ++ if ((q->mlt_window = av_malloc(mlt_size * sizeof(*q->mlt_window))) == 0) ++ return AVERROR(ENOMEM); + + /* Initialize the MLT window: simple sine window. */ + ff_sine_window_init(q->mlt_window, mlt_size); +- for(j=0 ; jmlt_window[j] *= sqrt(2.0 / q->samples_per_channel); + + /* Initialize the MDCT. */ +- if (ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size)+1, 1, 1.0)) { +- av_free(q->mlt_window); +- return -1; ++ if ((ret = ff_mdct_init(&q->mdct_ctx, av_log2(mlt_size) + 1, 1, 1.0 / 32768.0))) { ++ av_free(q->mlt_window); ++ return ret; + } +- av_log(q->avctx,AV_LOG_DEBUG,"MDCT initialized, order = %d.\n", +- av_log2(mlt_size)+1); ++ av_log(q->avctx, AV_LOG_DEBUG, "MDCT initialized, order = %d.\n", ++ av_log2(mlt_size) + 1); + + return 0; + } + +-static const float *maybe_reformat_buffer32 (COOKContext *q, const float *ptr, int n) ++static const float *maybe_reformat_buffer32(COOKContext *q, const float *ptr, int n) + { + if (1) + return ptr; + } + +-static av_cold void init_cplscales_table (COOKContext *q) { ++static av_cold void init_cplscales_table(COOKContext *q) ++{ + int i; +- for (i=0;i<5;i++) +- q->cplscales[i] = maybe_reformat_buffer32 (q, cplscales[i], (1<<(i+2))-1); ++ for (i = 0; i < 5; i++) ++ q->cplscales[i] = maybe_reformat_buffer32(q, cplscales[i], (1 << (i + 2)) - 1); + } + + /*************** init functions end ***********/ + +-#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes)+3) % 4) ++#define DECODE_BYTES_PAD1(bytes) (3 - ((bytes) + 3) % 4) + #define DECODE_BYTES_PAD2(bytes) ((bytes) % 4 + DECODE_BYTES_PAD1(2 * (bytes))) + + /** +@@ -307,23 +277,27 @@ + * @param out pointer to byte array of outdata + * @param bytes number of bytes + */ +- +-static inline int decode_bytes(const uint8_t* inbuffer, uint8_t* out, int bytes){ ++static inline int decode_bytes(const uint8_t *inbuffer, uint8_t *out, int bytes) ++{ ++ static const uint32_t tab[4] = { ++ AV_BE2NE32C(0x37c511f2), AV_BE2NE32C(0xf237c511), ++ AV_BE2NE32C(0x11f237c5), AV_BE2NE32C(0xc511f237), ++ }; + int i, off; + uint32_t c; +- const uint32_t* buf; +- uint32_t* obuf = (uint32_t*) out; ++ const uint32_t *buf; ++ uint32_t *obuf = (uint32_t *) out; + /* FIXME: 64 bit platforms would be able to do 64 bits at a time. + * I'm too lazy though, should be something like +- * for(i=0 ; i> (off*8)) | (0x37c511f2 << (32-(off*8)))); ++ off = (intptr_t) inbuffer & 3; ++ buf = (const uint32_t *) (inbuffer - off); ++ c = tab[off]; + bytes += 3 + off; +- for (i = 0; i < bytes/4; i++) ++ for (i = 0; i < bytes / 4; i++) + obuf[i] = c ^ buf[i]; + + return off; +@@ -332,12 +306,11 @@ + /** + * Cook uninit + */ +- + static av_cold int cook_decode_close(AVCodecContext *avctx) + { + int i; + COOKContext *q = avctx->priv_data; +- av_log(avctx,AV_LOG_DEBUG, "Deallocating memory.\n"); ++ av_log(avctx, AV_LOG_DEBUG, "Deallocating memory.\n"); + + /* Free allocated memory buffers. */ + av_free(q->mlt_window); +@@ -347,17 +320,14 @@ + ff_mdct_end(&q->mdct_ctx); + + /* Free the VLC tables. */ +- for (i=0 ; i<13 ; i++) { ++ for (i = 0; i < 13; i++) + free_vlc(&q->envelope_quant_index[i]); +- } +- for (i=0 ; i<7 ; i++) { ++ for (i = 0; i < 7; i++) + free_vlc(&q->sqvh[i]); +- } +- for (i=0 ; inum_subpackets ; i++) { ++ for (i = 0; i < q->num_subpackets; i++) + free_vlc(&q->subpacket[i].ccpl); +- } + +- av_log(avctx,AV_LOG_DEBUG,"Memory deallocated.\n"); ++ av_log(avctx, AV_LOG_DEBUG, "Memory deallocated.\n"); + + return 0; + } +@@ -366,24 +336,28 @@ + * Fill the gain array for the timedomain quantization. + * + * @param gb pointer to the GetBitContext +- * @param gaininfo[9] array of gain indexes ++ * @param gaininfo array[9] of gain indexes + */ +- + static void decode_gain_info(GetBitContext *gb, int *gaininfo) + { + int i, n; + +- while (get_bits1(gb)) {} +- n = get_bits_count(gb) - 1; //amount of elements*2 to update ++ while (get_bits1(gb)) { ++ /* NOTHING */ ++ } ++ ++ n = get_bits_count(gb) - 1; // amount of elements*2 to update + + i = 0; + while (n--) { + int index = get_bits(gb, 3); + int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1; + +- while (i <= index) gaininfo[i++] = gain; ++ while (i <= index) ++ gaininfo[i++] = gain; + } +- while (i <= 8) gaininfo[i++] = 0; ++ while (i <= 8) ++ gaininfo[i++] = 0; + } + + /** +@@ -392,26 +366,37 @@ + * @param q pointer to the COOKContext + * @param quant_index_table pointer to the array + */ ++static int decode_envelope(COOKContext *q, COOKSubpacket *p, ++ int *quant_index_table) ++{ ++ int i, j, vlc_index; + +-static void decode_envelope(COOKContext *q, COOKSubpacket *p, int* quant_index_table) { +- int i,j, vlc_index; +- +- quant_index_table[0]= get_bits(&q->gb,6) - 6; //This is used later in categorize ++ quant_index_table[0] = get_bits(&q->gb, 6) - 6; // This is used later in categorize + +- for (i=1 ; i < p->total_subbands ; i++){ +- vlc_index=i; ++ for (i = 1; i < p->total_subbands; i++) { ++ vlc_index = i; + if (i >= p->js_subband_start * 2) { +- vlc_index-=p->js_subband_start; ++ vlc_index -= p->js_subband_start; + } else { +- vlc_index/=2; +- if(vlc_index < 1) vlc_index = 1; ++ vlc_index /= 2; ++ if (vlc_index < 1) ++ vlc_index = 1; ++ } ++ if (vlc_index > 13) ++ vlc_index = 13; // the VLC tables >13 are identical to No. 13 ++ ++ j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index - 1].table, ++ q->envelope_quant_index[vlc_index - 1].bits, 2); ++ quant_index_table[i] = quant_index_table[i - 1] + j - 12; // differential encoding ++ if (quant_index_table[i] > 63 || quant_index_table[i] < -63) { ++ av_log(q->avctx, AV_LOG_ERROR, ++ "Invalid quantizer %d at position %d, outside [-63, 63] range\n", ++ quant_index_table[i], i); ++ return AVERROR_INVALIDDATA; + } +- if (vlc_index>13) vlc_index = 13; //the VLC tables >13 are identical to No. 13 +- +- j = get_vlc2(&q->gb, q->envelope_quant_index[vlc_index-1].table, +- q->envelope_quant_index[vlc_index-1].bits,2); +- quant_index_table[i] = quant_index_table[i-1] + j - 12; //differential encoding + } ++ ++ return 0; + } + + /** +@@ -422,48 +407,47 @@ + * @param category pointer to the category array + * @param category_index pointer to the category_index array + */ +- +-static void categorize(COOKContext *q, COOKSubpacket *p, int* quant_index_table, +- int* category, int* category_index){ ++static void categorize(COOKContext *q, COOKSubpacket *p, int *quant_index_table, ++ int *category, int *category_index) ++{ + int exp_idx, bias, tmpbias1, tmpbias2, bits_left, num_bits, index, v, i, j; + int exp_index2[102]; + int exp_index1[102]; + +- int tmp_categorize_array[128*2]; +- int tmp_categorize_array1_idx=p->numvector_size; +- int tmp_categorize_array2_idx=p->numvector_size; ++ int tmp_categorize_array[128 * 2]; ++ int tmp_categorize_array1_idx = p->numvector_size; ++ int tmp_categorize_array2_idx = p->numvector_size; + +- bits_left = p->bits_per_subpacket - get_bits_count(&q->gb); ++ bits_left = p->bits_per_subpacket - get_bits_count(&q->gb); + +- if(bits_left > q->samples_per_channel) { ++ if (bits_left > q->samples_per_channel) { + bits_left = q->samples_per_channel + +- ((bits_left - q->samples_per_channel)*5)/8; ++ ((bits_left - q->samples_per_channel) * 5) / 8; + //av_log(q->avctx, AV_LOG_ERROR, "bits_left = %d\n",bits_left); + } + +- memset(&exp_index1,0,102*sizeof(int)); +- memset(&exp_index2,0,102*sizeof(int)); +- memset(&tmp_categorize_array,0,128*2*sizeof(int)); ++ memset(&exp_index1, 0, sizeof(exp_index1)); ++ memset(&exp_index2, 0, sizeof(exp_index2)); ++ memset(&tmp_categorize_array, 0, sizeof(tmp_categorize_array)); + +- bias=-32; ++ bias = -32; + + /* Estimate bias. */ +- for (i=32 ; i>0 ; i=i/2){ ++ for (i = 32; i > 0; i = i / 2) { + num_bits = 0; +- index = 0; +- for (j=p->total_subbands ; j>0 ; j--){ ++ index = 0; ++ for (j = p->total_subbands; j > 0; j--) { + exp_idx = av_clip((i - quant_index_table[index] + bias) / 2, 0, 7); + index++; +- num_bits+=expbits_tab[exp_idx]; +- } +- if(num_bits >= bits_left - 32){ +- bias+=i; ++ num_bits += expbits_tab[exp_idx]; + } ++ if (num_bits >= bits_left - 32) ++ bias += i; + } + + /* Calculate total number of bits. */ +- num_bits=0; +- for (i=0 ; itotal_subbands ; i++) { ++ num_bits = 0; ++ for (i = 0; i < p->total_subbands; i++) { + exp_idx = av_clip((bias - quant_index_table[i]) / 2, 0, 7); + num_bits += expbits_tab[exp_idx]; + exp_index1[i] = exp_idx; +@@ -471,50 +455,51 @@ + } + tmpbias1 = tmpbias2 = num_bits; + +- for (j = 1 ; j < p->numvector_size ; j++) { +- if (tmpbias1 + tmpbias2 > 2*bits_left) { /* ---> */ ++ for (j = 1; j < p->numvector_size; j++) { ++ if (tmpbias1 + tmpbias2 > 2 * bits_left) { /* ---> */ + int max = -999999; +- index=-1; +- for (i=0 ; itotal_subbands ; i++){ ++ index = -1; ++ for (i = 0; i < p->total_subbands; i++) { + if (exp_index1[i] < 7) { +- v = (-2*exp_index1[i]) - quant_index_table[i] + bias; +- if ( v >= max) { +- max = v; ++ v = (-2 * exp_index1[i]) - quant_index_table[i] + bias; ++ if (v >= max) { ++ max = v; + index = i; + } + } + } +- if(index==-1)break; ++ if (index == -1) ++ break; + tmp_categorize_array[tmp_categorize_array1_idx++] = index; + tmpbias1 -= expbits_tab[exp_index1[index]] - +- expbits_tab[exp_index1[index]+1]; ++ expbits_tab[exp_index1[index] + 1]; + ++exp_index1[index]; + } else { /* <--- */ + int min = 999999; +- index=-1; +- for (i=0 ; itotal_subbands ; i++){ +- if(exp_index2[i] > 0){ +- v = (-2*exp_index2[i])-quant_index_table[i]+bias; +- if ( v < min) { +- min = v; ++ index = -1; ++ for (i = 0; i < p->total_subbands; i++) { ++ if (exp_index2[i] > 0) { ++ v = (-2 * exp_index2[i]) - quant_index_table[i] + bias; ++ if (v < min) { ++ min = v; + index = i; + } + } + } +- if(index == -1)break; ++ if (index == -1) ++ break; + tmp_categorize_array[--tmp_categorize_array2_idx] = index; + tmpbias2 -= expbits_tab[exp_index2[index]] - +- expbits_tab[exp_index2[index]-1]; ++ expbits_tab[exp_index2[index] - 1]; + --exp_index2[index]; + } + } + +- for(i=0 ; itotal_subbands ; i++) ++ for (i = 0; i < p->total_subbands; i++) + category[i] = exp_index2[i]; + +- for(i=0 ; inumvector_size-1 ; i++) ++ for (i = 0; i < p->numvector_size - 1; i++) + category_index[i] = tmp_categorize_array[tmp_categorize_array2_idx++]; +- + } + + +@@ -525,12 +510,15 @@ + * @param category pointer to the category array + * @param category_index pointer to the category_index array + */ +- +-static inline void expand_category(COOKContext *q, int* category, +- int* category_index){ ++static inline void expand_category(COOKContext *q, int *category, ++ int *category_index) ++{ + int i; +- for(i=0 ; inum_vectors ; i++){ +- ++category[category_index[i]]; ++ for (i = 0; i < q->num_vectors; i++) ++ { ++ int idx = category_index[i]; ++ if (++category[idx] >= FF_ARRAY_ELEMS(dither_tab)) ++ --category[idx]; + } + } + +@@ -544,23 +532,25 @@ + * @param subband_coef_sign signs of coefficients + * @param mlt_p pointer into the mlt buffer + */ +- + static void scalar_dequant_float(COOKContext *q, int index, int quant_index, +- int* subband_coef_index, int* subband_coef_sign, +- float* mlt_p){ ++ int *subband_coef_index, int *subband_coef_sign, ++ float *mlt_p) ++{ + int i; + float f1; + +- for(i=0 ; irandom_state) < 0x80000000) f1 = -f1; ++ if (av_lfg_get(&q->random_state) < 0x80000000) ++ f1 = -f1; + } +- mlt_p[i] = f1 * rootpow2tab[quant_index+63]; ++ mlt_p[i] = f1 * rootpow2tab[quant_index + 63]; + } + } + /** +@@ -571,35 +561,35 @@ + * @param subband_coef_index array of indexes to quant_centroid_tab + * @param subband_coef_sign signs of coefficients + */ +- +-static int unpack_SQVH(COOKContext *q, COOKSubpacket *p, int category, int* subband_coef_index, +- int* subband_coef_sign) { +- int i,j; +- int vlc, vd ,tmp, result; ++static int unpack_SQVH(COOKContext *q, COOKSubpacket *p, int category, ++ int *subband_coef_index, int *subband_coef_sign) ++{ ++ int i, j; ++ int vlc, vd, tmp, result; + + vd = vd_tab[category]; + result = 0; +- for(i=0 ; igb, q->sqvh[category].table, q->sqvh[category].bits, 3); +- if (p->bits_per_subpacket < get_bits_count(&q->gb)){ ++ if (p->bits_per_subpacket < get_bits_count(&q->gb)) { + vlc = 0; + result = 1; + } +- for(j=vd-1 ; j>=0 ; j--){ +- tmp = (vlc * invradix_tab[category])/0x100000; +- subband_coef_index[vd*i+j] = vlc - tmp * (kmax_tab[category]+1); ++ for (j = vd - 1; j >= 0; j--) { ++ tmp = (vlc * invradix_tab[category]) / 0x100000; ++ subband_coef_index[vd * i + j] = vlc - tmp * (kmax_tab[category] + 1); + vlc = tmp; + } +- for(j=0 ; jgb) < p->bits_per_subpacket){ +- subband_coef_sign[i*vd+j] = get_bits1(&q->gb); ++ for (j = 0; j < vd; j++) { ++ if (subband_coef_index[i * vd + j]) { ++ if (get_bits_count(&q->gb) < p->bits_per_subpacket) { ++ subband_coef_sign[i * vd + j] = get_bits1(&q->gb); + } else { +- result=1; +- subband_coef_sign[i*vd+j]=0; ++ result = 1; ++ subband_coef_sign[i * vd + j] = 0; + } + } else { +- subband_coef_sign[i*vd+j]=0; ++ subband_coef_sign[i * vd + j] = 0; + } + } + } +@@ -615,10 +605,9 @@ + * @param quant_index_table pointer to the array + * @param mlt_buffer pointer to mlt coefficients + */ +- +- +-static void decode_vectors(COOKContext* q, COOKSubpacket* p, int* category, +- int *quant_index_table, float* mlt_buffer){ ++static void decode_vectors(COOKContext *q, COOKSubpacket *p, int *category, ++ int *quant_index_table, float *mlt_buffer) ++{ + /* A zero in this table means that the subband coefficient is + random noise coded. */ + int subband_coef_index[SUBBAND_SIZE]; +@@ -626,28 +615,29 @@ + positive multiplicator. */ + int subband_coef_sign[SUBBAND_SIZE]; + int band, j; +- int index=0; ++ int index = 0; + +- for(band=0 ; bandtotal_subbands ; band++){ ++ for (band = 0; band < p->total_subbands; band++) { + index = category[band]; +- if(category[band] < 7){ +- if(unpack_SQVH(q, p, category[band], subband_coef_index, subband_coef_sign)){ +- index=7; +- for(j=0 ; jtotal_subbands ; j++) category[band+j]=7; ++ if (category[band] < 7) { ++ if (unpack_SQVH(q, p, category[band], subband_coef_index, subband_coef_sign)) { ++ index = 7; ++ for (j = 0; j < p->total_subbands; j++) ++ category[band + j] = 7; + } + } +- if(index>=7) { ++ if (index >= 7) { + memset(subband_coef_index, 0, sizeof(subband_coef_index)); +- memset(subband_coef_sign, 0, sizeof(subband_coef_sign)); ++ memset(subband_coef_sign, 0, sizeof(subband_coef_sign)); + } + q->scalar_dequant(q, index, quant_index_table[band], + subband_coef_index, subband_coef_sign, + &mlt_buffer[band * SUBBAND_SIZE]); + } + +- if(p->total_subbands*SUBBAND_SIZE >= q->samples_per_channel){ ++ /* FIXME: should this be removed, or moved into loop above? */ ++ if (p->total_subbands * SUBBAND_SIZE >= q->samples_per_channel) + return; +- } /* FIXME: should this be removed, or moved into loop above? */ + } + + +@@ -657,21 +647,24 @@ + * @param q pointer to the COOKContext + * @param mlt_buffer pointer to mlt coefficients + */ +- +-static void mono_decode(COOKContext *q, COOKSubpacket *p, float* mlt_buffer) { +- ++static int mono_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer) ++{ + int category_index[128]; + int quant_index_table[102]; + int category[128]; ++ int res; + +- memset(&category, 0, 128*sizeof(int)); +- memset(&category_index, 0, 128*sizeof(int)); ++ memset(&category, 0, sizeof(category)); ++ memset(&category_index, 0, sizeof(category_index)); + +- decode_envelope(q, p, quant_index_table); +- q->num_vectors = get_bits(&q->gb,p->log2_numvector_size); ++ if ((res = decode_envelope(q, p, quant_index_table)) < 0) ++ return res; ++ q->num_vectors = get_bits(&q->gb, p->log2_numvector_size); + categorize(q, p, quant_index_table, category, category_index); + expand_category(q, category, category_index); + decode_vectors(q, p, category, quant_index_table, mlt_buffer); ++ ++ return 0; + } + + +@@ -683,25 +676,22 @@ + * @param gain_index index for the block multiplier + * @param gain_index_next index for the next block multiplier + */ +- +-static void interpolate_float(COOKContext *q, float* buffer, +- int gain_index, int gain_index_next){ ++static void interpolate_float(COOKContext *q, float *buffer, ++ int gain_index, int gain_index_next) ++{ + int i; + float fc1, fc2; +- fc1 = pow2tab[gain_index+63]; ++ fc1 = pow2tab[gain_index + 63]; + +- if(gain_index == gain_index_next){ //static gain +- for(i=0 ; igain_size_factor ; i++){ +- buffer[i]*=fc1; ++ if (gain_index == gain_index_next) { // static gain ++ for (i = 0; i < q->gain_size_factor; i++) ++ buffer[i] *= fc1; ++ } else { // smooth gain ++ fc2 = q->gain_table[11 + (gain_index_next - gain_index)]; ++ for (i = 0; i < q->gain_size_factor; i++) { ++ buffer[i] *= fc1; ++ fc1 *= fc2; + } +- return; +- } else { //smooth gain +- fc2 = q->gain_table[11 + (gain_index_next-gain_index)]; +- for(i=0 ; igain_size_factor ; i++){ +- buffer[i]*=fc1; +- fc1*=fc2; +- } +- return; + } + } + +@@ -713,9 +703,8 @@ + * @param gains_ptr current and previous gains + * @param previous_buffer pointer to the previous buffer to be used for overlapping + */ +- +-static void imlt_window_float (COOKContext *q, float *inbuffer, +- cook_gains *gains_ptr, float *previous_buffer) ++static void imlt_window_float(COOKContext *q, float *inbuffer, ++ cook_gains *gains_ptr, float *previous_buffer) + { + const float fc = pow2tab[gains_ptr->previous[0] + 63]; + int i; +@@ -726,10 +715,9 @@ + */ + + /* Apply window and overlap */ +- for(i = 0; i < q->samples_per_channel; i++){ ++ for (i = 0; i < q->samples_per_channel; i++) + inbuffer[i] = inbuffer[i] * fc * q->mlt_window[i] - +- previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i]; +- } ++ previous_buffer[i] * q->mlt_window[q->samples_per_channel - 1 - i]; + } + + /** +@@ -743,28 +731,27 @@ + * @param gains_ptr current and previous gains + * @param previous_buffer pointer to the previous buffer to be used for overlapping + */ +- + static void imlt_gain(COOKContext *q, float *inbuffer, +- cook_gains *gains_ptr, float* previous_buffer) ++ cook_gains *gains_ptr, float *previous_buffer) + { + float *buffer0 = q->mono_mdct_output; + float *buffer1 = q->mono_mdct_output + q->samples_per_channel; + int i; + + /* Inverse modified discrete cosine transform */ +- ff_imdct_calc(&q->mdct_ctx, q->mono_mdct_output, inbuffer); ++ q->mdct_ctx.imdct_calc(&q->mdct_ctx, q->mono_mdct_output, inbuffer); + +- q->imlt_window (q, buffer1, gains_ptr, previous_buffer); ++ q->imlt_window(q, buffer1, gains_ptr, previous_buffer); + + /* Apply gain profile */ +- for (i = 0; i < 8; i++) { ++ for (i = 0; i < 8; i++) + if (gains_ptr->now[i] || gains_ptr->now[i + 1]) + q->interpolate(q, &buffer1[q->gain_size_factor * i], + gains_ptr->now[i], gains_ptr->now[i + 1]); +- } + + /* Save away the current to be previous block. */ +- memcpy(previous_buffer, buffer0, sizeof(float)*q->samples_per_channel); ++ memcpy(previous_buffer, buffer0, ++ q->samples_per_channel * sizeof(*previous_buffer)); + } + + +@@ -775,27 +762,23 @@ + * @param decouple_tab decoupling array + * + */ ++static void decouple_info(COOKContext *q, COOKSubpacket *p, int *decouple_tab) ++{ ++ int i; ++ int vlc = get_bits1(&q->gb); ++ int start = cplband[p->js_subband_start]; ++ int end = cplband[p->subbands - 1]; ++ int length = end - start + 1; + +-static void decouple_info(COOKContext *q, COOKSubpacket *p, int* decouple_tab){ +- int length, i; +- +- if(get_bits1(&q->gb)) { +- if(cplband[p->js_subband_start] > cplband[p->subbands-1]) return; +- +- length = cplband[p->subbands-1] - cplband[p->js_subband_start] + 1; +- for (i=0 ; ijs_subband_start] + i] = get_vlc2(&q->gb, p->ccpl.table, p->ccpl.bits, 2); +- } ++ if (start > end) + return; +- } + +- if(cplband[p->js_subband_start] > cplband[p->subbands-1]) return; +- +- length = cplband[p->subbands-1] - cplband[p->js_subband_start] + 1; +- for (i=0 ; ijs_subband_start] + i] = get_bits(&q->gb, p->js_vlc_bits); +- } +- return; ++ if (vlc) ++ for (i = 0; i < length; i++) ++ decouple_tab[start + i] = get_vlc2(&q->gb, p->ccpl.table, p->ccpl.bits, 2); ++ else ++ for (i = 0; i < length; i++) ++ decouple_tab[start + i] = get_bits(&q->gb, p->js_vlc_bits); + } + + /* +@@ -809,18 +792,18 @@ + * @param mlt_buffer1 pointer to left channel mlt coefficients + * @param mlt_buffer2 pointer to right channel mlt coefficients + */ +-static void decouple_float (COOKContext *q, +- COOKSubpacket *p, +- int subband, +- float f1, float f2, +- float *decode_buffer, +- float *mlt_buffer1, float *mlt_buffer2) ++static void decouple_float(COOKContext *q, ++ COOKSubpacket *p, ++ int subband, ++ float f1, float f2, ++ float *decode_buffer, ++ float *mlt_buffer1, float *mlt_buffer2) + { + int j, tmp_idx; +- for (j=0 ; jjs_subband_start + subband)*SUBBAND_SIZE)+j; +- mlt_buffer1[SUBBAND_SIZE*subband + j] = f1 * decode_buffer[tmp_idx]; +- mlt_buffer2[SUBBAND_SIZE*subband + j] = f2 * decode_buffer[tmp_idx]; ++ for (j = 0; j < SUBBAND_SIZE; j++) { ++ tmp_idx = ((p->js_subband_start + subband) * SUBBAND_SIZE) + j; ++ mlt_buffer1[SUBBAND_SIZE * subband + j] = f1 * decode_buffer[tmp_idx]; ++ mlt_buffer2[SUBBAND_SIZE * subband + j] = f2 * decode_buffer[tmp_idx]; + } + } + +@@ -831,45 +814,48 @@ + * @param mlt_buffer1 pointer to left channel mlt coefficients + * @param mlt_buffer2 pointer to right channel mlt coefficients + */ +- +-static void joint_decode(COOKContext *q, COOKSubpacket *p, float* mlt_buffer1, +- float* mlt_buffer2) { +- int i,j; ++static int joint_decode(COOKContext *q, COOKSubpacket *p, float *mlt_buffer1, ++ float *mlt_buffer2) ++{ ++ int i, j, res; + int decouple_tab[SUBBAND_SIZE]; + float *decode_buffer = q->decode_buffer_0; + int idx, cpl_tmp; +- float f1,f2; +- const float* cplscale; ++ float f1, f2; ++ const float *cplscale; + + memset(decouple_tab, 0, sizeof(decouple_tab)); +- memset(decode_buffer, 0, sizeof(decode_buffer)); ++ memset(decode_buffer, 0, sizeof(q->decode_buffer_0)); + + /* Make sure the buffers are zeroed out. */ +- memset(mlt_buffer1,0, 1024*sizeof(float)); +- memset(mlt_buffer2,0, 1024*sizeof(float)); ++ memset(mlt_buffer1, 0, 1024 * sizeof(*mlt_buffer1)); ++ memset(mlt_buffer2, 0, 1024 * sizeof(*mlt_buffer2)); + decouple_info(q, p, decouple_tab); +- mono_decode(q, p, decode_buffer); ++ if ((res = mono_decode(q, p, decode_buffer)) < 0) ++ return res; + + /* The two channels are stored interleaved in decode_buffer. */ +- for (i=0 ; ijs_subband_start ; i++) { +- for (j=0 ; jjs_subband_start; i++) { ++ for (j = 0; j < SUBBAND_SIZE; j++) { ++ mlt_buffer1[i * 20 + j] = decode_buffer[i * 40 + j]; ++ mlt_buffer2[i * 20 + j] = decode_buffer[i * 40 + 20 + j]; + } + } + + /* When we reach js_subband_start (the higher frequencies) + the coefficients are stored in a coupling scheme. */ + idx = (1 << p->js_vlc_bits) - 1; +- for (i=p->js_subband_start ; isubbands ; i++) { ++ for (i = p->js_subband_start; i < p->subbands; i++) { + cpl_tmp = cplband[i]; +- idx -=decouple_tab[cpl_tmp]; +- cplscale = q->cplscales[p->js_vlc_bits-2]; //choose decoupler table +- f1 = cplscale[decouple_tab[cpl_tmp]]; +- f2 = cplscale[idx-1]; +- q->decouple (q, p, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); ++ idx -= decouple_tab[cpl_tmp]; ++ cplscale = q->cplscales[p->js_vlc_bits - 2]; // choose decoupler table ++ f1 = cplscale[decouple_tab[cpl_tmp] + 1]; ++ f2 = cplscale[idx]; ++ q->decouple(q, p, i, f1, f2, decode_buffer, mlt_buffer1, mlt_buffer2); + idx = (1 << p->js_vlc_bits) - 1; + } ++ ++ return 0; + } + + /** +@@ -880,15 +866,14 @@ + * @param inbuffer pointer to raw stream data + * @param gains_ptr array of current/prev gain pointers + */ +- +-static inline void +-decode_bytes_and_gain(COOKContext *q, COOKSubpacket *p, const uint8_t *inbuffer, +- cook_gains *gains_ptr) ++static inline void decode_bytes_and_gain(COOKContext *q, COOKSubpacket *p, ++ const uint8_t *inbuffer, ++ cook_gains *gains_ptr) + { + int offset; + + offset = decode_bytes(inbuffer, q->decoded_bytes_buffer, +- p->bits_per_subpacket/8); ++ p->bits_per_subpacket / 8); + init_get_bits(&q->gb, q->decoded_bytes_buffer + offset, + p->bits_per_subpacket); + decode_gain_info(&q->gb, gains_ptr->now); +@@ -897,23 +882,19 @@ + FFSWAP(int *, gains_ptr->now, gains_ptr->previous); + } + +- /** +- * Saturate the output signal to signed 16bit integers. ++/** ++ * Saturate the output signal and interleave. + * + * @param q pointer to the COOKContext + * @param chan channel to saturate + * @param out pointer to the output vector + */ +-static void +-saturate_output_float (COOKContext *q, int chan, int16_t *out) ++static void saturate_output_float(COOKContext *q, int chan, float *out) + { + int j; + float *output = q->mono_mdct_output + q->samples_per_channel; +- /* Clip and convert floats to 16 bits. +- */ + for (j = 0; j < q->samples_per_channel; j++) { +- out[chan + q->nb_channels * j] = +- av_clip_int16(lrintf(output[j])); ++ out[chan + q->nb_channels * j] = av_clipf(output[j], -1.0, 1.0); + } + } + +@@ -929,14 +910,13 @@ + * @param out pointer to the output buffer + * @param chan 0: left or single channel, 1: right channel + */ +- +-static inline void +-mlt_compensate_output(COOKContext *q, float *decode_buffer, +- cook_gains *gains_ptr, float *previous_buffer, +- int16_t *out, int chan) ++static inline void mlt_compensate_output(COOKContext *q, float *decode_buffer, ++ cook_gains *gains_ptr, float *previous_buffer, ++ float *out, int chan) + { + imlt_gain(q, decode_buffer, gains_ptr, previous_buffer); +- q->saturate_output (q, chan, out); ++ if (out) ++ q->saturate_output(q, chan, out); + } + + +@@ -948,40 +928,44 @@ + * @param inbuffer pointer to the inbuffer + * @param outbuffer pointer to the outbuffer + */ +-static void decode_subpacket(COOKContext *q, COOKSubpacket* p, const uint8_t *inbuffer, int16_t *outbuffer) { ++static int decode_subpacket(COOKContext *q, COOKSubpacket *p, ++ const uint8_t *inbuffer, float *outbuffer) ++{ + int sub_packet_size = p->size; ++ int res; + /* packet dump */ +-// for (i=0 ; iavctx, AV_LOG_ERROR, "%02x", inbuffer[i]); +-// } +-// av_log(q->avctx, AV_LOG_ERROR, "\n"); +- memset(q->decode_buffer_1,0,sizeof(q->decode_buffer_1)); ++ // for (i = 0; i < sub_packet_size ; i++) ++ // av_log(q->avctx, AV_LOG_ERROR, "%02x", inbuffer[i]); ++ // av_log(q->avctx, AV_LOG_ERROR, "\n"); ++ memset(q->decode_buffer_1, 0, sizeof(q->decode_buffer_1)); + decode_bytes_and_gain(q, p, inbuffer, &p->gains1); + + if (p->joint_stereo) { +- joint_decode(q, p, q->decode_buffer_1, q->decode_buffer_2); ++ if ((res = joint_decode(q, p, q->decode_buffer_1, q->decode_buffer_2)) < 0) ++ return res; + } else { +- mono_decode(q, p, q->decode_buffer_1); ++ if ((res = mono_decode(q, p, q->decode_buffer_1)) < 0) ++ return res; + + if (p->num_channels == 2) { +- decode_bytes_and_gain(q, p, inbuffer + sub_packet_size/2, &p->gains2); +- mono_decode(q, p, q->decode_buffer_2); ++ decode_bytes_and_gain(q, p, inbuffer + sub_packet_size / 2, &p->gains2); ++ if ((res = mono_decode(q, p, q->decode_buffer_2)) < 0) ++ return res; + } + } + + mlt_compensate_output(q, q->decode_buffer_1, &p->gains1, + p->mono_previous_buffer1, outbuffer, p->ch_idx); + +- if (p->num_channels == 2) { +- if (p->joint_stereo) { ++ if (p->num_channels == 2) ++ if (p->joint_stereo) + mlt_compensate_output(q, q->decode_buffer_2, &p->gains1, + p->mono_previous_buffer2, outbuffer, p->ch_idx + 1); +- } else { ++ else + mlt_compensate_output(q, q->decode_buffer_2, &p->gains2, + p->mono_previous_buffer2, outbuffer, p->ch_idx + 1); +- } +- } + ++ return 0; + } + + +@@ -990,84 +974,106 @@ + * + * @param avctx pointer to the AVCodecContext + */ +- +-static int cook_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) { ++static int cook_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + COOKContext *q = avctx->priv_data; +- int i; ++ float *samples = NULL; ++ int i, ret; + int offset = 0; + int chidx = 0; + + if (buf_size < avctx->block_align) + return buf_size; + ++ /* get output buffer */ ++ if (q->discarded_packets >= 2) { ++ q->frame.nb_samples = q->samples_per_channel; ++ if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (float *) q->frame.data[0]; ++ } ++ + /* estimate subpacket sizes */ + q->subpacket[0].size = avctx->block_align; + +- for(i=1;inum_subpackets;i++){ ++ for (i = 1; i < q->num_subpackets; i++) { + q->subpacket[i].size = 2 * buf[avctx->block_align - q->num_subpackets + i]; + q->subpacket[0].size -= q->subpacket[i].size + 1; + if (q->subpacket[0].size < 0) { +- av_log(avctx,AV_LOG_DEBUG,"frame subpacket size total > avctx->block_align!\n"); +- return -1; ++ av_log(avctx, AV_LOG_DEBUG, ++ "frame subpacket size total > avctx->block_align!\n"); ++ return AVERROR_INVALIDDATA; + } + } + + /* decode supbackets */ +- *data_size = 0; +- for(i=0;inum_subpackets;i++){ +- q->subpacket[i].bits_per_subpacket = (q->subpacket[i].size*8)>>q->subpacket[i].bits_per_subpdiv; ++ for (i = 0; i < q->num_subpackets; i++) { ++ q->subpacket[i].bits_per_subpacket = (q->subpacket[i].size * 8) >> ++ q->subpacket[i].bits_per_subpdiv; + q->subpacket[i].ch_idx = chidx; +- av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] size %i js %i %i block_align %i\n",i,q->subpacket[i].size,q->subpacket[i].joint_stereo,offset,avctx->block_align); +- decode_subpacket(q, &q->subpacket[i], buf + offset, (int16_t*)data); ++ av_log(avctx, AV_LOG_DEBUG, ++ "subpacket[%i] size %i js %i %i block_align %i\n", ++ i, q->subpacket[i].size, q->subpacket[i].joint_stereo, offset, ++ avctx->block_align); ++ ++ if ((ret = decode_subpacket(q, &q->subpacket[i], buf + offset, samples)) < 0) ++ return ret; + offset += q->subpacket[i].size; + chidx += q->subpacket[i].num_channels; +- av_log(avctx,AV_LOG_DEBUG,"subpacket[%i] %i %i\n",i,q->subpacket[i].size * 8,get_bits_count(&q->gb)); ++ av_log(avctx, AV_LOG_DEBUG, "subpacket[%i] %i %i\n", ++ i, q->subpacket[i].size * 8, get_bits_count(&q->gb)); + } +- *data_size = sizeof(int16_t) * q->nb_channels * q->samples_per_channel; + + /* Discard the first two frames: no valid audio. */ +- if (avctx->frame_number < 2) *data_size = 0; ++ if (q->discarded_packets < 2) { ++ q->discarded_packets++; ++ *got_frame_ptr = 0; ++ return avctx->block_align; ++ } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *) data = q->frame; + + return avctx->block_align; + } + +-#ifdef COOKDEBUG ++#ifdef DEBUG + static void dump_cook_context(COOKContext *q) + { + //int i=0; +-#define PRINT(a,b) av_log(q->avctx,AV_LOG_ERROR," %s = %d\n", a, b); +- av_log(q->avctx,AV_LOG_ERROR,"COOKextradata\n"); +- av_log(q->avctx,AV_LOG_ERROR,"cookversion=%x\n",q->subpacket[0].cookversion); ++#define PRINT(a, b) av_log(q->avctx, AV_LOG_ERROR, " %s = %d\n", a, b); ++ av_log(q->avctx, AV_LOG_ERROR, "COOKextradata\n"); ++ av_log(q->avctx, AV_LOG_ERROR, "cookversion=%x\n", q->subpacket[0].cookversion); + if (q->subpacket[0].cookversion > STEREO) { +- PRINT("js_subband_start",q->subpacket[0].js_subband_start); +- PRINT("js_vlc_bits",q->subpacket[0].js_vlc_bits); ++ PRINT("js_subband_start", q->subpacket[0].js_subband_start); ++ PRINT("js_vlc_bits", q->subpacket[0].js_vlc_bits); + } +- av_log(q->avctx,AV_LOG_ERROR,"COOKContext\n"); +- PRINT("nb_channels",q->nb_channels); +- PRINT("bit_rate",q->bit_rate); +- PRINT("sample_rate",q->sample_rate); +- PRINT("samples_per_channel",q->subpacket[0].samples_per_channel); +- PRINT("samples_per_frame",q->subpacket[0].samples_per_frame); +- PRINT("subbands",q->subpacket[0].subbands); +- PRINT("random_state",q->random_state); +- PRINT("js_subband_start",q->subpacket[0].js_subband_start); +- PRINT("log2_numvector_size",q->subpacket[0].log2_numvector_size); +- PRINT("numvector_size",q->subpacket[0].numvector_size); +- PRINT("total_subbands",q->subpacket[0].total_subbands); ++ av_log(q->avctx, AV_LOG_ERROR, "COOKContext\n"); ++ PRINT("nb_channels", q->nb_channels); ++ PRINT("bit_rate", q->bit_rate); ++ PRINT("sample_rate", q->sample_rate); ++ PRINT("samples_per_channel", q->subpacket[0].samples_per_channel); ++ PRINT("samples_per_frame", q->subpacket[0].samples_per_frame); ++ PRINT("subbands", q->subpacket[0].subbands); ++ PRINT("js_subband_start", q->subpacket[0].js_subband_start); ++ PRINT("log2_numvector_size", q->subpacket[0].log2_numvector_size); ++ PRINT("numvector_size", q->subpacket[0].numvector_size); ++ PRINT("total_subbands", q->subpacket[0].total_subbands); + } + #endif + +-static av_cold int cook_count_channels(unsigned int mask){ ++static av_cold int cook_count_channels(unsigned int mask) ++{ + int i; + int channels = 0; +- for(i = 0;i<32;i++){ +- if(mask & (1<priv_data; +@@ -1085,34 +1090,39 @@ + int extradata_size = avctx->extradata_size; + int s = 0; + unsigned int channel_mask = 0; ++ int ret; + q->avctx = avctx; + + /* Take care of the codec specific extradata. */ + if (extradata_size <= 0) { +- av_log(avctx,AV_LOG_ERROR,"Necessary extradata missing!\n"); +- return -1; ++ av_log(avctx, AV_LOG_ERROR, "Necessary extradata missing!\n"); ++ return AVERROR_INVALIDDATA; + } +- av_log(avctx,AV_LOG_DEBUG,"codecdata_length=%d\n",avctx->extradata_size); ++ av_log(avctx, AV_LOG_DEBUG, "codecdata_length=%d\n", avctx->extradata_size); + + /* Take data from the AVCodecContext (RM container). */ + q->sample_rate = avctx->sample_rate; + q->nb_channels = avctx->channels; + q->bit_rate = avctx->bit_rate; ++ if (!q->nb_channels) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); ++ return AVERROR_INVALIDDATA; ++ } + + /* Initialize RNG. */ + av_lfg_init(&q->random_state, 0); + +- while(edata_ptr < edata_ptr_end){ ++ while (edata_ptr < edata_ptr_end) { + /* 8 for mono, 16 for stereo, ? for multichannel + Swap to right endianness so we don't need to care later on. */ +- if (extradata_size >= 8){ ++ if (extradata_size >= 8) { + q->subpacket[s].cookversion = bytestream_get_be32(&edata_ptr); +- q->subpacket[s].samples_per_frame = bytestream_get_be16(&edata_ptr); ++ q->subpacket[s].samples_per_frame = bytestream_get_be16(&edata_ptr); + q->subpacket[s].subbands = bytestream_get_be16(&edata_ptr); + extradata_size -= 8; + } +- if (avctx->extradata_size >= 8){ +- bytestream_get_be32(&edata_ptr); //Unknown unused ++ if (extradata_size >= 8) { ++ bytestream_get_be32(&edata_ptr); // Unknown unused + q->subpacket[s].js_subband_start = bytestream_get_be16(&edata_ptr); + q->subpacket[s].js_vlc_bits = bytestream_get_be16(&edata_ptr); + extradata_size -= 8; +@@ -1129,71 +1139,73 @@ + + /* Initialize version-dependent variables */ + +- av_log(avctx,AV_LOG_DEBUG,"subpacket[%i].cookversion=%x\n",s,q->subpacket[s].cookversion); ++ av_log(avctx, AV_LOG_DEBUG, "subpacket[%i].cookversion=%x\n", s, ++ q->subpacket[s].cookversion); + q->subpacket[s].joint_stereo = 0; + switch (q->subpacket[s].cookversion) { +- case MONO: +- if (q->nb_channels != 1) { +- av_log(avctx,AV_LOG_ERROR,"Container channels != 1, report sample!\n"); +- return -1; +- } +- av_log(avctx,AV_LOG_DEBUG,"MONO\n"); +- break; +- case STEREO: +- if (q->nb_channels != 1) { +- q->subpacket[s].bits_per_subpdiv = 1; +- q->subpacket[s].num_channels = 2; +- } +- av_log(avctx,AV_LOG_DEBUG,"STEREO\n"); +- break; +- case JOINT_STEREO: +- if (q->nb_channels != 2) { +- av_log(avctx,AV_LOG_ERROR,"Container channels != 2, report sample!\n"); +- return -1; +- } +- av_log(avctx,AV_LOG_DEBUG,"JOINT_STEREO\n"); +- if (avctx->extradata_size >= 16){ +- q->subpacket[s].total_subbands = q->subpacket[s].subbands + q->subpacket[s].js_subband_start; +- q->subpacket[s].joint_stereo = 1; +- q->subpacket[s].num_channels = 2; +- } ++ case MONO: ++ if (q->nb_channels != 1) { ++ av_log_ask_for_sample(avctx, "Container channels != 1.\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ av_log(avctx, AV_LOG_DEBUG, "MONO\n"); ++ break; ++ case STEREO: ++ if (q->nb_channels != 1) { ++ q->subpacket[s].bits_per_subpdiv = 1; ++ q->subpacket[s].num_channels = 2; ++ } ++ av_log(avctx, AV_LOG_DEBUG, "STEREO\n"); ++ break; ++ case JOINT_STEREO: ++ if (q->nb_channels != 2) { ++ av_log_ask_for_sample(avctx, "Container channels != 2.\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ av_log(avctx, AV_LOG_DEBUG, "JOINT_STEREO\n"); ++ if (avctx->extradata_size >= 16) { ++ q->subpacket[s].total_subbands = q->subpacket[s].subbands + ++ q->subpacket[s].js_subband_start; ++ q->subpacket[s].joint_stereo = 1; ++ q->subpacket[s].num_channels = 2; ++ } ++ if (q->subpacket[s].samples_per_channel > 256) { ++ q->subpacket[s].log2_numvector_size = 6; ++ } ++ if (q->subpacket[s].samples_per_channel > 512) { ++ q->subpacket[s].log2_numvector_size = 7; ++ } ++ break; ++ case MC_COOK: ++ av_log(avctx, AV_LOG_DEBUG, "MULTI_CHANNEL\n"); ++ if (extradata_size >= 4) ++ channel_mask |= q->subpacket[s].channel_mask = bytestream_get_be32(&edata_ptr); ++ ++ if (cook_count_channels(q->subpacket[s].channel_mask) > 1) { ++ q->subpacket[s].total_subbands = q->subpacket[s].subbands + ++ q->subpacket[s].js_subband_start; ++ q->subpacket[s].joint_stereo = 1; ++ q->subpacket[s].num_channels = 2; ++ q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame >> 1; ++ + if (q->subpacket[s].samples_per_channel > 256) { +- q->subpacket[s].log2_numvector_size = 6; ++ q->subpacket[s].log2_numvector_size = 6; + } + if (q->subpacket[s].samples_per_channel > 512) { +- q->subpacket[s].log2_numvector_size = 7; ++ q->subpacket[s].log2_numvector_size = 7; + } +- break; +- case MC_COOK: +- av_log(avctx,AV_LOG_DEBUG,"MULTI_CHANNEL\n"); +- if(extradata_size >= 4) +- channel_mask |= q->subpacket[s].channel_mask = bytestream_get_be32(&edata_ptr); +- +- if(cook_count_channels(q->subpacket[s].channel_mask) > 1){ +- q->subpacket[s].total_subbands = q->subpacket[s].subbands + q->subpacket[s].js_subband_start; +- q->subpacket[s].joint_stereo = 1; +- q->subpacket[s].num_channels = 2; +- q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame >> 1; +- +- if (q->subpacket[s].samples_per_channel > 256) { +- q->subpacket[s].log2_numvector_size = 6; +- } +- if (q->subpacket[s].samples_per_channel > 512) { +- q->subpacket[s].log2_numvector_size = 7; +- } +- }else +- q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame; ++ } else ++ q->subpacket[s].samples_per_channel = q->subpacket[s].samples_per_frame; + +- break; +- default: +- av_log(avctx,AV_LOG_ERROR,"Unknown Cook version, report sample!\n"); +- return -1; +- break; ++ break; ++ default: ++ av_log_ask_for_sample(avctx, "Unknown Cook version.\n"); ++ return AVERROR_PATCHWELCOME; + } + +- if(s > 1 && q->subpacket[s].samples_per_channel != q->samples_per_channel) { +- av_log(avctx,AV_LOG_ERROR,"different number of samples per channel!\n"); +- return -1; ++ if (s > 1 && q->subpacket[s].samples_per_channel != q->samples_per_channel) { ++ av_log(avctx, AV_LOG_ERROR, "different number of samples per channel!\n"); ++ return AVERROR_INVALIDDATA; + } else + q->samples_per_channel = q->subpacket[0].samples_per_channel; + +@@ -1203,18 +1215,20 @@ + + /* Try to catch some obviously faulty streams, othervise it might be exploitable */ + if (q->subpacket[s].total_subbands > 53) { +- av_log(avctx,AV_LOG_ERROR,"total_subbands > 53, report sample!\n"); +- return -1; ++ av_log_ask_for_sample(avctx, "total_subbands > 53\n"); ++ return AVERROR_PATCHWELCOME; + } + +- if ((q->subpacket[s].js_vlc_bits > 6) || (q->subpacket[s].js_vlc_bits < 0)) { +- av_log(avctx,AV_LOG_ERROR,"js_vlc_bits = %d, only >= 0 and <= 6 allowed!\n",q->subpacket[s].js_vlc_bits); +- return -1; ++ if ((q->subpacket[s].js_vlc_bits > 6) || ++ (q->subpacket[s].js_vlc_bits < 2 * q->subpacket[s].joint_stereo)) { ++ av_log(avctx, AV_LOG_ERROR, "js_vlc_bits = %d, only >= %d and <= 6 allowed!\n", ++ q->subpacket[s].js_vlc_bits, 2 * q->subpacket[s].joint_stereo); ++ return AVERROR_INVALIDDATA; + } + + if (q->subpacket[s].subbands > 50) { +- av_log(avctx,AV_LOG_ERROR,"subbands > 50, report sample!\n"); +- return -1; ++ av_log_ask_for_sample(avctx, "subbands > 50\n"); ++ return AVERROR_PATCHWELCOME; + } + q->subpacket[s].gains1.now = q->subpacket[s].gain_1; + q->subpacket[s].gains1.previous = q->subpacket[s].gain_2; +@@ -1224,8 +1238,8 @@ + q->num_subpackets++; + s++; + if (s > MAX_SUBPACKETS) { +- av_log(avctx,AV_LOG_ERROR,"Too many subpackets > 5, report file!\n"); +- return -1; ++ av_log_ask_for_sample(avctx, "Too many subpackets > 5\n"); ++ return AVERROR_PATCHWELCOME; + } + } + /* Generate tables */ +@@ -1233,26 +1247,26 @@ + init_gain_table(q); + init_cplscales_table(q); + +- if (init_cook_vlc_tables(q) != 0) +- return -1; ++ if ((ret = init_cook_vlc_tables(q))) ++ return ret; + + +- if(avctx->block_align >= UINT_MAX/2) +- return -1; ++ if (avctx->block_align >= UINT_MAX / 2) ++ return AVERROR(EINVAL); + + /* Pad the databuffer with: + DECODE_BYTES_PAD1 or DECODE_BYTES_PAD2 for decode_bytes(), + FF_INPUT_BUFFER_PADDING_SIZE, for the bitstreamreader. */ +- q->decoded_bytes_buffer = +- av_mallocz(avctx->block_align +- + DECODE_BYTES_PAD1(avctx->block_align) +- + FF_INPUT_BUFFER_PADDING_SIZE); ++ q->decoded_bytes_buffer = ++ av_mallocz(avctx->block_align ++ + DECODE_BYTES_PAD1(avctx->block_align) ++ + FF_INPUT_BUFFER_PADDING_SIZE); + if (q->decoded_bytes_buffer == NULL) +- return -1; ++ return AVERROR(ENOMEM); + + /* Initialize transform. */ +- if ( init_cook_mlt(q) != 0 ) +- return -1; ++ if ((ret = init_cook_mlt(q))) ++ return ret; + + /* Initialize COOK signal arithmetic handling */ + if (1) { +@@ -1264,33 +1278,38 @@ + } + + /* Try to catch some obviously faulty streams, othervise it might be exploitable */ +- if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) || (q->samples_per_channel == 1024)) { ++ if ((q->samples_per_channel == 256) || (q->samples_per_channel == 512) ++ || (q->samples_per_channel == 1024)) { + } else { +- av_log(avctx,AV_LOG_ERROR,"unknown amount of samples_per_channel = %d, report sample!\n",q->samples_per_channel); +- return -1; ++ av_log_ask_for_sample(avctx, ++ "unknown amount of samples_per_channel = %d\n", ++ q->samples_per_channel); ++ return AVERROR_PATCHWELCOME; + } + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + if (channel_mask) + avctx->channel_layout = channel_mask; + else +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + +-#ifdef COOKDEBUG ++ avcodec_get_frame_defaults(&q->frame); ++ avctx->coded_frame = &q->frame; ++ ++#ifdef DEBUG + dump_cook_context(q); + #endif + return 0; + } + +- +-AVCodec ff_cook_decoder = +-{ +- .name = "cook", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_COOK, ++AVCodec ff_cook_decoder = { ++ .name = "cook", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_COOK, + .priv_data_size = sizeof(COOKContext), +- .init = cook_decode_init, +- .close = cook_decode_close, +- .decode = cook_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("COOK"), ++ .init = cook_decode_init, ++ .close = cook_decode_close, ++ .decode = cook_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("COOK"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cookdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cookdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cookdata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cookdata.h 2012-05-14 14:08:53.566324524 +0200 +@@ -36,8 +36,8 @@ + 52,47,43,37,29,22,16,0, + }; + +-static const float dither_tab[8] = { +- 0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107, ++static const float dither_tab[9] = { ++ 0.0, 0.0, 0.0, 0.0, 0.0, 0.176777, 0.25, 0.707107, 1.0 + }; + + static const float quant_centroid_tab[7][14] = { +@@ -510,23 +510,37 @@ + 19, + }; + +-static const float cplscale2[3] = { ++// The 1 and 0 at the beginning/end are to prevent overflows with ++// bitstream-read indexes. E.g. if n_bits=5, we can access any ++// index from [1, (1< ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++ ++#ifndef M_PI ++#define M_PI 3.14159265358979323846 ++#endif ++#define BITS 16 ++#define FLOATFMT "%.18e" ++#define FIXEDFMT "%6d" ++ ++static int clip_f15(int v) ++{ ++ return v < -32767 ? -32767 : ++ v > 32767 ? 32767 : ++ v; ++} ++ ++static void printval(double val, int fixed) ++{ ++ if (fixed) ++ printf(" "FIXEDFMT",", clip_f15(lrint(val * (double)(1<<15)))); ++ else ++ printf(" "FLOATFMT",", val); ++ ++} ++ ++int main(int argc, char *argv[]) ++{ ++ int i, j; ++ int do_sin = argc > 1 && !strcmp(argv[1], "sin"); ++ int fixed = argc > 1 && strstr(argv[1], "fixed"); ++ double (*func)(double) = do_sin ? sin : cos; ++ ++ printf("/* This file was automatically generated. */\n"); ++ printf("#define CONFIG_FFT_FLOAT %d\n", !fixed); ++ printf("#include \"libavcodec/%s\"\n", do_sin ? "rdft.h" : "fft.h"); ++ for (i = 4; i <= BITS; i++) { ++ int m = 1 << i; ++ double freq = 2*M_PI/m; ++ printf("%s(%i) = {\n ", do_sin ? "SINTABLE" : "COSTABLE", m); ++ for (j = 0; j < m/2 - 1; j++) { ++ int idx = j > m/4 ? m/2 - j : j; ++ if (do_sin && j >= m/4) ++ idx = m/4 - j; ++ printval(func(idx*freq), fixed); ++ if ((j & 3) == 3) ++ printf("\n "); ++ } ++ printval(func(do_sin ? -(m/4 - 1)*freq : freq), fixed); ++ printf("\n};\n"); ++ } ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/costablegen.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/costablegen.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/costablegen.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/costablegen.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,56 +0,0 @@ +-/* +- * Generate a header file for hardcoded ff_cos_* tables +- * +- * Copyright (c) 2009 Reimar Döffinger +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +-#include +-#include +- +-#ifndef M_PI +-#define M_PI 3.14159265358979323846 +-#endif +-#define BITS 16 +-#define FLOATFMT "%.18e" +- +-int main(int argc, char *argv[]) +-{ +- int i, j; +- int do_sin = argc == 2 && !strcmp(argv[1], "sin"); +- double (*func)(double) = do_sin ? sin : cos; +- +- printf("/* This file was generated by libavcodec/costablegen */\n"); +- printf("#include \"libavcodec/fft.h\"\n"); +- for (i = 4; i <= BITS; i++) { +- int m = 1 << i; +- double freq = 2*M_PI/m; +- printf("%s(%i) = {\n ", do_sin ? "SINTABLE" : "COSTABLE", m); +- for (j = 0; j < m/2 - 1; j++) { +- int idx = j > m/4 ? m/2 - j : j; +- if (do_sin && j >= m/4) +- idx = m/4 - j; +- printf(" "FLOATFMT",", func(idx*freq)); +- if ((j & 3) == 3) +- printf("\n "); +- } +- printf(" "FLOATFMT"\n};\n", func(do_sin ? -(m/4 - 1)*freq : freq)); +- } +- return 0; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/crystalhd.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/crystalhd.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/crystalhd.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/crystalhd.c 2012-05-14 14:08:53.570324606 +0200 +@@ -0,0 +1,1167 @@ ++/* ++ * - CrystalHD decoder module - ++ * ++ * Copyright(C) 2010,2011 Philip Langdale ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/* ++ * - Principles of Operation - ++ * ++ * The CrystalHD decoder operates at the bitstream level - which is an even ++ * higher level than the decoding hardware you typically see in modern GPUs. ++ * This means it has a very simple interface, in principle. You feed demuxed ++ * packets in one end and get decoded picture (fields/frames) out the other. ++ * ++ * Of course, nothing is ever that simple. Due, at the very least, to b-frame ++ * dependencies in the supported formats, the hardware has a delay between ++ * when a packet goes in, and when a picture comes out. Furthermore, this delay ++ * is not just a function of time, but also one of the dependency on additional ++ * frames being fed into the decoder to satisfy the b-frame dependencies. ++ * ++ * As such, a pipeline will build up that is roughly equivalent to the required ++ * DPB for the file being played. If that was all it took, things would still ++ * be simple - so, of course, it isn't. ++ * ++ * The hardware has a way of indicating that a picture is ready to be copied out, ++ * but this is unreliable - and sometimes the attempt will still fail so, based ++ * on testing, the code will wait until 3 pictures are ready before starting ++ * to copy out - and this has the effect of extending the pipeline. ++ * ++ * Finally, while it is tempting to say that once the decoder starts outputing ++ * frames, the software should never fail to return a frame from a decode(), ++ * this is a hard assertion to make, because the stream may switch between ++ * differently encoded content (number of b-frames, interlacing, etc) which ++ * might require a longer pipeline than before. If that happened, you could ++ * deadlock trying to retrieve a frame that can't be decoded without feeding ++ * in additional packets. ++ * ++ * As such, the code will return in the event that a picture cannot be copied ++ * out, leading to an increase in the length of the pipeline. This in turn, ++ * means we have to be sensitive to the time it takes to decode a picture; ++ * We do not want to give up just because the hardware needed a little more ++ * time to prepare the picture! For this reason, there are delays included ++ * in the decode() path that ensure that, under normal conditions, the hardware ++ * will only fail to return a frame if it really needs additional packets to ++ * complete the decoding. ++ * ++ * Finally, to be explicit, we do not want the pipeline to grow without bound ++ * for two reasons: 1) The hardware can only buffer a finite number of packets, ++ * and 2) The client application may not be able to cope with arbitrarily long ++ * delays in the video path relative to the audio path. For example. MPlayer ++ * can only handle a 20 picture delay (although this is arbitrary, and needs ++ * to be extended to fully support the CrystalHD where the delay could be up ++ * to 32 pictures - consider PAFF H.264 content with 16 b-frames). ++ */ ++ ++/***************************************************************************** ++ * Includes ++ ****************************************************************************/ ++ ++#define _XOPEN_SOURCE 600 ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++ ++#include "avcodec.h" ++#include "h264.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/opt.h" ++ ++/** Timeout parameter passed to DtsProcOutput() in us */ ++#define OUTPUT_PROC_TIMEOUT 50 ++/** Step between fake timestamps passed to hardware in units of 100ns */ ++#define TIMESTAMP_UNIT 100000 ++/** Initial value in us of the wait in decode() */ ++#define BASE_WAIT 10000 ++/** Increment in us to adjust wait in decode() */ ++#define WAIT_UNIT 1000 ++ ++ ++/***************************************************************************** ++ * Module private data ++ ****************************************************************************/ ++ ++typedef enum { ++ RET_ERROR = -1, ++ RET_OK = 0, ++ RET_COPY_AGAIN = 1, ++ RET_SKIP_NEXT_COPY = 2, ++ RET_COPY_NEXT_FIELD = 3, ++} CopyRet; ++ ++typedef struct OpaqueList { ++ struct OpaqueList *next; ++ uint64_t fake_timestamp; ++ uint64_t reordered_opaque; ++ uint8_t pic_type; ++} OpaqueList; ++ ++typedef struct { ++ AVClass *av_class; ++ AVCodecContext *avctx; ++ AVFrame pic; ++ HANDLE dev; ++ ++ uint8_t *orig_extradata; ++ uint32_t orig_extradata_size; ++ ++ AVBitStreamFilterContext *bsfc; ++ AVCodecParserContext *parser; ++ ++ uint8_t is_70012; ++ uint8_t *sps_pps_buf; ++ uint32_t sps_pps_size; ++ uint8_t is_nal; ++ uint8_t output_ready; ++ uint8_t need_second_field; ++ uint8_t skip_next_output; ++ uint64_t decode_wait; ++ ++ uint64_t last_picture; ++ ++ OpaqueList *head; ++ OpaqueList *tail; ++ ++ /* Options */ ++ uint32_t sWidth; ++ uint8_t bframe_bug; ++} CHDContext; ++ ++static const AVOption options[] = { ++ { "crystalhd_downscale_width", ++ "Turn on downscaling to the specified width", ++ offsetof(CHDContext, sWidth), ++ AV_OPT_TYPE_INT, 0, 0, UINT32_MAX, ++ AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, }, ++ { NULL, }, ++}; ++ ++ ++/***************************************************************************** ++ * Helper functions ++ ****************************************************************************/ ++ ++static inline BC_MEDIA_SUBTYPE id2subtype(CHDContext *priv, enum CodecID id) ++{ ++ switch (id) { ++ case CODEC_ID_MPEG4: ++ return BC_MSUBTYPE_DIVX; ++ case CODEC_ID_MSMPEG4V3: ++ return BC_MSUBTYPE_DIVX311; ++ case CODEC_ID_MPEG2VIDEO: ++ return BC_MSUBTYPE_MPEG2VIDEO; ++ case CODEC_ID_VC1: ++ return BC_MSUBTYPE_VC1; ++ case CODEC_ID_WMV3: ++ return BC_MSUBTYPE_WMV3; ++ case CODEC_ID_H264: ++ return priv->is_nal ? BC_MSUBTYPE_AVC1 : BC_MSUBTYPE_H264; ++ default: ++ return BC_MSUBTYPE_INVALID; ++ } ++} ++ ++static inline void print_frame_info(CHDContext *priv, BC_DTS_PROC_OUT *output) ++{ ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffSz: %u\n", output->YbuffSz); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tYBuffDoneSz: %u\n", ++ output->YBuffDoneSz); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tUVBuffDoneSz: %u\n", ++ output->UVBuffDoneSz); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tTimestamp: %"PRIu64"\n", ++ output->PicInfo.timeStamp); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tPicture Number: %u\n", ++ output->PicInfo.picture_number); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tWidth: %u\n", ++ output->PicInfo.width); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tHeight: %u\n", ++ output->PicInfo.height); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tChroma: 0x%03x\n", ++ output->PicInfo.chroma_format); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tPulldown: %u\n", ++ output->PicInfo.pulldown); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFlags: 0x%08x\n", ++ output->PicInfo.flags); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrame Rate/Res: %u\n", ++ output->PicInfo.frame_rate); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tAspect Ratio: %u\n", ++ output->PicInfo.aspect_ratio); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tColor Primaries: %u\n", ++ output->PicInfo.colour_primaries); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tMetaData: %u\n", ++ output->PicInfo.picture_meta_payload); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tSession Number: %u\n", ++ output->PicInfo.sess_num); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tycom: %u\n", ++ output->PicInfo.ycom); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tCustom Aspect: %u\n", ++ output->PicInfo.custom_aspect_ratio_width_height); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tFrames to Drop: %u\n", ++ output->PicInfo.n_drop); ++ av_log(priv->avctx, AV_LOG_VERBOSE, "\tH264 Valid Fields: 0x%08x\n", ++ output->PicInfo.other.h264.valid); ++} ++ ++ ++/***************************************************************************** ++ * OpaqueList functions ++ ****************************************************************************/ ++ ++static uint64_t opaque_list_push(CHDContext *priv, uint64_t reordered_opaque, ++ uint8_t pic_type) ++{ ++ OpaqueList *newNode = av_mallocz(sizeof (OpaqueList)); ++ if (!newNode) { ++ av_log(priv->avctx, AV_LOG_ERROR, ++ "Unable to allocate new node in OpaqueList.\n"); ++ return 0; ++ } ++ if (!priv->head) { ++ newNode->fake_timestamp = TIMESTAMP_UNIT; ++ priv->head = newNode; ++ } else { ++ newNode->fake_timestamp = priv->tail->fake_timestamp + TIMESTAMP_UNIT; ++ priv->tail->next = newNode; ++ } ++ priv->tail = newNode; ++ newNode->reordered_opaque = reordered_opaque; ++ newNode->pic_type = pic_type; ++ ++ return newNode->fake_timestamp; ++} ++ ++/* ++ * The OpaqueList is built in decode order, while elements will be removed ++ * in presentation order. If frames are reordered, this means we must be ++ * able to remove elements that are not the first element. ++ * ++ * Returned node must be freed by caller. ++ */ ++static OpaqueList *opaque_list_pop(CHDContext *priv, uint64_t fake_timestamp) ++{ ++ OpaqueList *node = priv->head; ++ ++ if (!priv->head) { ++ av_log(priv->avctx, AV_LOG_ERROR, ++ "CrystalHD: Attempted to query non-existent timestamps.\n"); ++ return NULL; ++ } ++ ++ /* ++ * The first element is special-cased because we have to manipulate ++ * the head pointer rather than the previous element in the list. ++ */ ++ if (priv->head->fake_timestamp == fake_timestamp) { ++ priv->head = node->next; ++ ++ if (!priv->head->next) ++ priv->tail = priv->head; ++ ++ node->next = NULL; ++ return node; ++ } ++ ++ /* ++ * The list is processed at arm's length so that we have the ++ * previous element available to rewrite its next pointer. ++ */ ++ while (node->next) { ++ OpaqueList *current = node->next; ++ if (current->fake_timestamp == fake_timestamp) { ++ node->next = current->next; ++ ++ if (!node->next) ++ priv->tail = node; ++ ++ current->next = NULL; ++ return current; ++ } else { ++ node = current; ++ } ++ } ++ ++ av_log(priv->avctx, AV_LOG_VERBOSE, ++ "CrystalHD: Couldn't match fake_timestamp.\n"); ++ return NULL; ++} ++ ++ ++/***************************************************************************** ++ * Video decoder API function definitions ++ ****************************************************************************/ ++ ++static void flush(AVCodecContext *avctx) ++{ ++ CHDContext *priv = avctx->priv_data; ++ ++ avctx->has_b_frames = 0; ++ priv->last_picture = -1; ++ priv->output_ready = 0; ++ priv->need_second_field = 0; ++ priv->skip_next_output = 0; ++ priv->decode_wait = BASE_WAIT; ++ ++ if (priv->pic.data[0]) ++ avctx->release_buffer(avctx, &priv->pic); ++ ++ /* Flush mode 4 flushes all software and hardware buffers. */ ++ DtsFlushInput(priv->dev, 4); ++} ++ ++ ++static av_cold int uninit(AVCodecContext *avctx) ++{ ++ CHDContext *priv = avctx->priv_data; ++ HANDLE device; ++ ++ device = priv->dev; ++ DtsStopDecoder(device); ++ DtsCloseDecoder(device); ++ DtsDeviceClose(device); ++ ++ /* ++ * Restore original extradata, so that if the decoder is ++ * reinitialised, the bitstream detection and filtering ++ * will work as expected. ++ */ ++ if (priv->orig_extradata) { ++ av_free(avctx->extradata); ++ avctx->extradata = priv->orig_extradata; ++ avctx->extradata_size = priv->orig_extradata_size; ++ priv->orig_extradata = NULL; ++ priv->orig_extradata_size = 0; ++ } ++ ++ av_parser_close(priv->parser); ++ if (priv->bsfc) { ++ av_bitstream_filter_close(priv->bsfc); ++ } ++ ++ av_free(priv->sps_pps_buf); ++ ++ if (priv->pic.data[0]) ++ avctx->release_buffer(avctx, &priv->pic); ++ ++ if (priv->head) { ++ OpaqueList *node = priv->head; ++ while (node) { ++ OpaqueList *next = node->next; ++ av_free(node); ++ node = next; ++ } ++ } ++ ++ return 0; ++} ++ ++ ++static av_cold int init(AVCodecContext *avctx) ++{ ++ CHDContext* priv; ++ BC_STATUS ret; ++ BC_INFO_CRYSTAL version; ++ BC_INPUT_FORMAT format = { ++ .FGTEnable = FALSE, ++ .Progressive = TRUE, ++ .OptFlags = 0x80000000 | vdecFrameRate59_94 | 0x40, ++ .width = avctx->width, ++ .height = avctx->height, ++ }; ++ ++ BC_MEDIA_SUBTYPE subtype; ++ ++ uint32_t mode = DTS_PLAYBACK_MODE | ++ DTS_LOAD_FILE_PLAY_FW | ++ DTS_SKIP_TX_CHK_CPB | ++ DTS_PLAYBACK_DROP_RPT_MODE | ++ DTS_SINGLE_THREADED_MODE | ++ DTS_DFLT_RESOLUTION(vdecRESOLUTION_1080p23_976); ++ ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD Init for %s\n", ++ avctx->codec->name); ++ ++ avctx->pix_fmt = PIX_FMT_YUYV422; ++ ++ /* Initialize the library */ ++ priv = avctx->priv_data; ++ priv->avctx = avctx; ++ priv->is_nal = avctx->extradata_size > 0 && *(avctx->extradata) == 1; ++ priv->last_picture = -1; ++ priv->decode_wait = BASE_WAIT; ++ ++ subtype = id2subtype(priv, avctx->codec->id); ++ switch (subtype) { ++ case BC_MSUBTYPE_AVC1: ++ { ++ uint8_t *dummy_p; ++ int dummy_int; ++ ++ /* Back up the extradata so it can be restored at close time. */ ++ priv->orig_extradata = av_malloc(avctx->extradata_size); ++ if (!priv->orig_extradata) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Failed to allocate copy of extradata\n"); ++ return AVERROR(ENOMEM); ++ } ++ priv->orig_extradata_size = avctx->extradata_size; ++ memcpy(priv->orig_extradata, avctx->extradata, avctx->extradata_size); ++ ++ priv->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); ++ if (!priv->bsfc) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Cannot open the h264_mp4toannexb BSF!\n"); ++ return AVERROR_BSF_NOT_FOUND; ++ } ++ av_bitstream_filter_filter(priv->bsfc, avctx, NULL, &dummy_p, ++ &dummy_int, NULL, 0, 0); ++ } ++ subtype = BC_MSUBTYPE_H264; ++ // Fall-through ++ case BC_MSUBTYPE_H264: ++ format.startCodeSz = 4; ++ // Fall-through ++ case BC_MSUBTYPE_VC1: ++ case BC_MSUBTYPE_WVC1: ++ case BC_MSUBTYPE_WMV3: ++ case BC_MSUBTYPE_WMVA: ++ case BC_MSUBTYPE_MPEG2VIDEO: ++ case BC_MSUBTYPE_DIVX: ++ case BC_MSUBTYPE_DIVX311: ++ format.pMetaData = avctx->extradata; ++ format.metaDataSz = avctx->extradata_size; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: Unknown codec name\n"); ++ return AVERROR(EINVAL); ++ } ++ format.mSubtype = subtype; ++ ++ if (priv->sWidth) { ++ format.bEnableScaling = 1; ++ format.ScalingParams.sWidth = priv->sWidth; ++ } ++ ++ /* Get a decoder instance */ ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: starting up\n"); ++ // Initialize the Link and Decoder devices ++ ret = DtsDeviceOpen(&priv->dev, mode); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: DtsDeviceOpen failed\n"); ++ goto fail; ++ } ++ ++ ret = DtsCrystalHDVersion(priv->dev, &version); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_VERBOSE, ++ "CrystalHD: DtsCrystalHDVersion failed\n"); ++ goto fail; ++ } ++ priv->is_70012 = version.device == 0; ++ ++ if (priv->is_70012 && ++ (subtype == BC_MSUBTYPE_DIVX || subtype == BC_MSUBTYPE_DIVX311)) { ++ av_log(avctx, AV_LOG_VERBOSE, ++ "CrystalHD: BCM70012 doesn't support MPEG4-ASP/DivX/Xvid\n"); ++ goto fail; ++ } ++ ++ ret = DtsSetInputFormat(priv->dev, &format); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: SetInputFormat failed\n"); ++ goto fail; ++ } ++ ++ ret = DtsOpenDecoder(priv->dev, BC_STREAM_TYPE_ES); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsOpenDecoder failed\n"); ++ goto fail; ++ } ++ ++ ret = DtsSetColorSpace(priv->dev, OUTPUT_MODE422_YUY2); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsSetColorSpace failed\n"); ++ goto fail; ++ } ++ ret = DtsStartDecoder(priv->dev); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartDecoder failed\n"); ++ goto fail; ++ } ++ ret = DtsStartCapture(priv->dev); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: DtsStartCapture failed\n"); ++ goto fail; ++ } ++ ++ if (avctx->codec->id == CODEC_ID_H264) { ++ priv->parser = av_parser_init(avctx->codec->id); ++ if (!priv->parser) ++ av_log(avctx, AV_LOG_WARNING, ++ "Cannot open the h.264 parser! Interlaced h.264 content " ++ "will not be detected reliably.\n"); ++ priv->parser->flags = PARSER_FLAG_COMPLETE_FRAMES; ++ } ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Init complete.\n"); ++ ++ return 0; ++ ++ fail: ++ uninit(avctx); ++ return -1; ++} ++ ++ ++static inline CopyRet copy_frame(AVCodecContext *avctx, ++ BC_DTS_PROC_OUT *output, ++ void *data, int *data_size) ++{ ++ BC_STATUS ret; ++ BC_DTS_STATUS decoder_status = { 0, }; ++ uint8_t trust_interlaced; ++ uint8_t interlaced; ++ ++ CHDContext *priv = avctx->priv_data; ++ int64_t pkt_pts = AV_NOPTS_VALUE; ++ uint8_t pic_type = 0; ++ ++ uint8_t bottom_field = (output->PicInfo.flags & VDEC_FLAG_BOTTOMFIELD) == ++ VDEC_FLAG_BOTTOMFIELD; ++ uint8_t bottom_first = !!(output->PicInfo.flags & VDEC_FLAG_BOTTOM_FIRST); ++ ++ int width = output->PicInfo.width; ++ int height = output->PicInfo.height; ++ int bwidth; ++ uint8_t *src = output->Ybuff; ++ int sStride; ++ uint8_t *dst; ++ int dStride; ++ ++ if (output->PicInfo.timeStamp != 0) { ++ OpaqueList *node = opaque_list_pop(priv, output->PicInfo.timeStamp); ++ if (node) { ++ pkt_pts = node->reordered_opaque; ++ pic_type = node->pic_type; ++ av_free(node); ++ } else { ++ /* ++ * We will encounter a situation where a timestamp cannot be ++ * popped if a second field is being returned. In this case, ++ * each field has the same timestamp and the first one will ++ * cause it to be popped. To keep subsequent calculations ++ * simple, pic_type should be set a FIELD value - doesn't ++ * matter which, but I chose BOTTOM. ++ */ ++ pic_type = PICT_BOTTOM_FIELD; ++ } ++ av_log(avctx, AV_LOG_VERBOSE, "output \"pts\": %"PRIu64"\n", ++ output->PicInfo.timeStamp); ++ av_log(avctx, AV_LOG_VERBOSE, "output picture type %d\n", ++ pic_type); ++ } ++ ++ ret = DtsGetDriverStatus(priv->dev, &decoder_status); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, ++ "CrystalHD: GetDriverStatus failed: %u\n", ret); ++ return RET_ERROR; ++ } ++ ++ /* ++ * For most content, we can trust the interlaced flag returned ++ * by the hardware, but sometimes we can't. These are the ++ * conditions under which we can trust the flag: ++ * ++ * 1) It's not h.264 content ++ * 2) The UNKNOWN_SRC flag is not set ++ * 3) We know we're expecting a second field ++ * 4) The hardware reports this picture and the next picture ++ * have the same picture number. ++ * ++ * Note that there can still be interlaced content that will ++ * fail this check, if the hardware hasn't decoded the next ++ * picture or if there is a corruption in the stream. (In either ++ * case a 0 will be returned for the next picture number) ++ */ ++ trust_interlaced = avctx->codec->id != CODEC_ID_H264 || ++ !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) || ++ priv->need_second_field || ++ (decoder_status.picNumFlags & ~0x40000000) == ++ output->PicInfo.picture_number; ++ ++ /* ++ * If we got a false negative for trust_interlaced on the first field, ++ * we will realise our mistake here when we see that the picture number is that ++ * of the previous picture. We cannot recover the frame and should discard the ++ * second field to keep the correct number of output frames. ++ */ ++ if (output->PicInfo.picture_number == priv->last_picture && !priv->need_second_field) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Incorrectly guessed progressive frame. Discarding second field\n"); ++ /* Returning without providing a picture. */ ++ return RET_OK; ++ } ++ ++ interlaced = (output->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) && ++ trust_interlaced; ++ ++ if (!trust_interlaced && (decoder_status.picNumFlags & ~0x40000000) == 0) { ++ av_log(avctx, AV_LOG_VERBOSE, ++ "Next picture number unknown. Assuming progressive frame.\n"); ++ } ++ ++ av_log(avctx, AV_LOG_VERBOSE, "Interlaced state: %d | trust_interlaced %d\n", ++ interlaced, trust_interlaced); ++ ++ if (priv->pic.data[0] && !priv->need_second_field) ++ avctx->release_buffer(avctx, &priv->pic); ++ ++ priv->need_second_field = interlaced && !priv->need_second_field; ++ ++ priv->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | ++ FF_BUFFER_HINTS_REUSABLE; ++ if (!priv->pic.data[0]) { ++ if (avctx->get_buffer(avctx, &priv->pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return RET_ERROR; ++ } ++ } ++ ++ bwidth = av_image_get_linesize(avctx->pix_fmt, width, 0); ++ if (priv->is_70012) { ++ int pStride; ++ ++ if (width <= 720) ++ pStride = 720; ++ else if (width <= 1280) ++ pStride = 1280; ++ else if (width <= 1080) ++ pStride = 1080; ++ sStride = av_image_get_linesize(avctx->pix_fmt, pStride, 0); ++ } else { ++ sStride = bwidth; ++ } ++ ++ dStride = priv->pic.linesize[0]; ++ dst = priv->pic.data[0]; ++ ++ av_log(priv->avctx, AV_LOG_VERBOSE, "CrystalHD: Copying out frame\n"); ++ ++ if (interlaced) { ++ int dY = 0; ++ int sY = 0; ++ ++ height /= 2; ++ if (bottom_field) { ++ av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: bottom field\n"); ++ dY = 1; ++ } else { ++ av_log(priv->avctx, AV_LOG_VERBOSE, "Interlaced: top field\n"); ++ dY = 0; ++ } ++ ++ for (sY = 0; sY < height; dY++, sY++) { ++ memcpy(&(dst[dY * dStride]), &(src[sY * sStride]), bwidth); ++ dY++; ++ } ++ } else { ++ av_image_copy_plane(dst, dStride, src, sStride, bwidth, height); ++ } ++ ++ priv->pic.interlaced_frame = interlaced; ++ if (interlaced) ++ priv->pic.top_field_first = !bottom_first; ++ ++ priv->pic.pkt_pts = pkt_pts; ++ ++ if (!priv->need_second_field) { ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = priv->pic; ++ } ++ ++ /* ++ * Two types of PAFF content have been observed. One form causes the ++ * hardware to return a field pair and the other individual fields, ++ * even though the input is always individual fields. We must skip ++ * copying on the next decode() call to maintain pipeline length in ++ * the first case. ++ */ ++ if (!interlaced && (output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) && ++ (pic_type == PICT_TOP_FIELD || pic_type == PICT_BOTTOM_FIELD)) { ++ av_log(priv->avctx, AV_LOG_VERBOSE, "Fieldpair from two packets.\n"); ++ return RET_SKIP_NEXT_COPY; ++ } ++ ++ /* ++ * Testing has shown that in all cases where we don't want to return the ++ * full frame immediately, VDEC_FLAG_UNKNOWN_SRC is set. ++ */ ++ return priv->need_second_field && ++ !(output->PicInfo.flags & VDEC_FLAG_UNKNOWN_SRC) ? ++ RET_COPY_NEXT_FIELD : RET_OK; ++} ++ ++ ++static inline CopyRet receive_frame(AVCodecContext *avctx, ++ void *data, int *data_size) ++{ ++ BC_STATUS ret; ++ BC_DTS_PROC_OUT output = { ++ .PicInfo.width = avctx->width, ++ .PicInfo.height = avctx->height, ++ }; ++ CHDContext *priv = avctx->priv_data; ++ HANDLE dev = priv->dev; ++ ++ *data_size = 0; ++ ++ // Request decoded data from the driver ++ ret = DtsProcOutputNoCopy(dev, OUTPUT_PROC_TIMEOUT, &output); ++ if (ret == BC_STS_FMT_CHANGE) { ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Initial format change\n"); ++ avctx->width = output.PicInfo.width; ++ avctx->height = output.PicInfo.height; ++ return RET_COPY_AGAIN; ++ } else if (ret == BC_STS_SUCCESS) { ++ int copy_ret = -1; ++ if (output.PoutFlags & BC_POUT_FLAGS_PIB_VALID) { ++ if (priv->last_picture == -1) { ++ /* ++ * Init to one less, so that the incrementing code doesn't ++ * need to be special-cased. ++ */ ++ priv->last_picture = output.PicInfo.picture_number - 1; ++ } ++ ++ if (avctx->codec->id == CODEC_ID_MPEG4 && ++ output.PicInfo.timeStamp == 0 && priv->bframe_bug) { ++ av_log(avctx, AV_LOG_VERBOSE, ++ "CrystalHD: Not returning packed frame twice.\n"); ++ priv->last_picture++; ++ DtsReleaseOutputBuffs(dev, NULL, FALSE); ++ return RET_COPY_AGAIN; ++ } ++ ++ print_frame_info(priv, &output); ++ ++ if (priv->last_picture + 1 < output.PicInfo.picture_number) { ++ av_log(avctx, AV_LOG_WARNING, ++ "CrystalHD: Picture Number discontinuity\n"); ++ /* ++ * Have we lost frames? If so, we need to shrink the ++ * pipeline length appropriately. ++ * ++ * XXX: I have no idea what the semantics of this situation ++ * are so I don't even know if we've lost frames or which ++ * ones. ++ * ++ * In any case, only warn the first time. ++ */ ++ priv->last_picture = output.PicInfo.picture_number - 1; ++ } ++ ++ copy_ret = copy_frame(avctx, &output, data, data_size); ++ if (*data_size > 0) { ++ avctx->has_b_frames--; ++ priv->last_picture++; ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Pipeline length: %u\n", ++ avctx->has_b_frames); ++ } ++ } else { ++ /* ++ * An invalid frame has been consumed. ++ */ ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput succeeded with " ++ "invalid PIB\n"); ++ avctx->has_b_frames--; ++ copy_ret = RET_OK; ++ } ++ DtsReleaseOutputBuffs(dev, NULL, FALSE); ++ ++ return copy_ret; ++ } else if (ret == BC_STS_BUSY) { ++ return RET_COPY_AGAIN; ++ } else { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: ProcOutput failed %d\n", ret); ++ return RET_ERROR; ++ } ++} ++ ++ ++static int decode(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) ++{ ++ BC_STATUS ret; ++ BC_DTS_STATUS decoder_status = { 0, }; ++ CopyRet rec_ret; ++ CHDContext *priv = avctx->priv_data; ++ HANDLE dev = priv->dev; ++ uint8_t *in_data = avpkt->data; ++ int len = avpkt->size; ++ int free_data = 0; ++ uint8_t pic_type = 0; ++ ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: decode_frame\n"); ++ ++ if (avpkt->size == 7 && !priv->bframe_bug) { ++ /* ++ * The use of a drop frame triggers the bug ++ */ ++ av_log(avctx, AV_LOG_INFO, ++ "CrystalHD: Enabling work-around for packed b-frame bug\n"); ++ priv->bframe_bug = 1; ++ } else if (avpkt->size == 8 && priv->bframe_bug) { ++ /* ++ * Delay frames don't trigger the bug ++ */ ++ av_log(avctx, AV_LOG_INFO, ++ "CrystalHD: Disabling work-around for packed b-frame bug\n"); ++ priv->bframe_bug = 0; ++ } ++ ++ if (len) { ++ int32_t tx_free = (int32_t)DtsTxFreeSize(dev); ++ ++ if (priv->parser) { ++ int ret = 0; ++ ++ if (priv->bsfc) { ++ ret = av_bitstream_filter_filter(priv->bsfc, avctx, NULL, ++ &in_data, &len, ++ avpkt->data, len, 0); ++ } ++ free_data = ret > 0; ++ ++ if (ret >= 0) { ++ uint8_t *pout; ++ int psize; ++ int index; ++ H264Context *h = priv->parser->priv_data; ++ ++ index = av_parser_parse2(priv->parser, avctx, &pout, &psize, ++ in_data, len, avctx->pkt->pts, ++ avctx->pkt->dts, 0); ++ if (index < 0) { ++ av_log(avctx, AV_LOG_WARNING, ++ "CrystalHD: Failed to parse h.264 packet to " ++ "detect interlacing.\n"); ++ } else if (index != len) { ++ av_log(avctx, AV_LOG_WARNING, ++ "CrystalHD: Failed to parse h.264 packet " ++ "completely. Interlaced frames may be " ++ "incorrectly detected\n."); ++ } else { ++ av_log(avctx, AV_LOG_VERBOSE, ++ "CrystalHD: parser picture type %d\n", ++ h->s.picture_structure); ++ pic_type = h->s.picture_structure; ++ } ++ } else { ++ av_log(avctx, AV_LOG_WARNING, ++ "CrystalHD: mp4toannexb filter failed to filter " ++ "packet. Interlaced frames may be incorrectly " ++ "detected.\n"); ++ } ++ } ++ ++ if (len < tx_free - 1024) { ++ /* ++ * Despite being notionally opaque, either libcrystalhd or ++ * the hardware itself will mangle pts values that are too ++ * small or too large. The docs claim it should be in units ++ * of 100ns. Given that we're nominally dealing with a black ++ * box on both sides, any transform we do has no guarantee of ++ * avoiding mangling so we need to build a mapping to values ++ * we know will not be mangled. ++ */ ++ uint64_t pts = opaque_list_push(priv, avctx->pkt->pts, pic_type); ++ if (!pts) { ++ if (free_data) { ++ av_freep(&in_data); ++ } ++ return AVERROR(ENOMEM); ++ } ++ av_log(priv->avctx, AV_LOG_VERBOSE, ++ "input \"pts\": %"PRIu64"\n", pts); ++ ret = DtsProcInput(dev, in_data, len, pts, 0); ++ if (free_data) { ++ av_freep(&in_data); ++ } ++ if (ret == BC_STS_BUSY) { ++ av_log(avctx, AV_LOG_WARNING, ++ "CrystalHD: ProcInput returned busy\n"); ++ usleep(BASE_WAIT); ++ return AVERROR(EBUSY); ++ } else if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, ++ "CrystalHD: ProcInput failed: %u\n", ret); ++ return -1; ++ } ++ avctx->has_b_frames++; ++ } else { ++ av_log(avctx, AV_LOG_WARNING, "CrystalHD: Input buffer full\n"); ++ len = 0; // We didn't consume any bytes. ++ } ++ } else { ++ av_log(avctx, AV_LOG_INFO, "CrystalHD: No more input data\n"); ++ } ++ ++ if (priv->skip_next_output) { ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Skipping next output.\n"); ++ priv->skip_next_output = 0; ++ avctx->has_b_frames--; ++ return len; ++ } ++ ++ ret = DtsGetDriverStatus(dev, &decoder_status); ++ if (ret != BC_STS_SUCCESS) { ++ av_log(avctx, AV_LOG_ERROR, "CrystalHD: GetDriverStatus failed\n"); ++ return -1; ++ } ++ ++ /* ++ * No frames ready. Don't try to extract. ++ * ++ * Empirical testing shows that ReadyListCount can be a damn lie, ++ * and ProcOut still fails when count > 0. The same testing showed ++ * that two more iterations were needed before ProcOutput would ++ * succeed. ++ */ ++ if (priv->output_ready < 2) { ++ if (decoder_status.ReadyListCount != 0) ++ priv->output_ready++; ++ usleep(BASE_WAIT); ++ av_log(avctx, AV_LOG_INFO, "CrystalHD: Filling pipeline.\n"); ++ return len; ++ } else if (decoder_status.ReadyListCount == 0) { ++ /* ++ * After the pipeline is established, if we encounter a lack of frames ++ * that probably means we're not giving the hardware enough time to ++ * decode them, so start increasing the wait time at the end of a ++ * decode call. ++ */ ++ usleep(BASE_WAIT); ++ priv->decode_wait += WAIT_UNIT; ++ av_log(avctx, AV_LOG_INFO, "CrystalHD: No frames ready. Returning\n"); ++ return len; ++ } ++ ++ do { ++ rec_ret = receive_frame(avctx, data, data_size); ++ if (rec_ret == RET_OK && *data_size == 0) { ++ /* ++ * This case is for when the encoded fields are stored ++ * separately and we get a separate avpkt for each one. To keep ++ * the pipeline stable, we should return nothing and wait for ++ * the next time round to grab the second field. ++ * H.264 PAFF is an example of this. ++ */ ++ av_log(avctx, AV_LOG_VERBOSE, "Returning after first field.\n"); ++ avctx->has_b_frames--; ++ } else if (rec_ret == RET_COPY_NEXT_FIELD) { ++ /* ++ * This case is for when the encoded fields are stored in a ++ * single avpkt but the hardware returns then separately. Unless ++ * we grab the second field before returning, we'll slip another ++ * frame in the pipeline and if that happens a lot, we're sunk. ++ * So we have to get that second field now. ++ * Interlaced mpeg2 and vc1 are examples of this. ++ */ ++ av_log(avctx, AV_LOG_VERBOSE, "Trying to get second field.\n"); ++ while (1) { ++ usleep(priv->decode_wait); ++ ret = DtsGetDriverStatus(dev, &decoder_status); ++ if (ret == BC_STS_SUCCESS && ++ decoder_status.ReadyListCount > 0) { ++ rec_ret = receive_frame(avctx, data, data_size); ++ if ((rec_ret == RET_OK && *data_size > 0) || ++ rec_ret == RET_ERROR) ++ break; ++ } ++ } ++ av_log(avctx, AV_LOG_VERBOSE, "CrystalHD: Got second field.\n"); ++ } else if (rec_ret == RET_SKIP_NEXT_COPY) { ++ /* ++ * Two input packets got turned into a field pair. Gawd. ++ */ ++ av_log(avctx, AV_LOG_VERBOSE, ++ "Don't output on next decode call.\n"); ++ priv->skip_next_output = 1; ++ } ++ /* ++ * If rec_ret == RET_COPY_AGAIN, that means that either we just handled ++ * a FMT_CHANGE event and need to go around again for the actual frame, ++ * we got a busy status and need to try again, or we're dealing with ++ * packed b-frames, where the hardware strangely returns the packed ++ * p-frame twice. We choose to keep the second copy as it carries the ++ * valid pts. ++ */ ++ } while (rec_ret == RET_COPY_AGAIN); ++ usleep(priv->decode_wait); ++ return len; ++} ++ ++ ++#if CONFIG_H264_CRYSTALHD_DECODER ++static AVClass h264_class = { ++ "h264_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_h264_crystalhd_decoder = { ++ .name = "h264_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &h264_class, ++}; ++#endif ++ ++#if CONFIG_MPEG2_CRYSTALHD_DECODER ++static AVClass mpeg2_class = { ++ "mpeg2_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_mpeg2_crystalhd_decoder = { ++ .name = "mpeg2_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 Video (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &mpeg2_class, ++}; ++#endif ++ ++#if CONFIG_MPEG4_CRYSTALHD_DECODER ++static AVClass mpeg4_class = { ++ "mpeg4_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_mpeg4_crystalhd_decoder = { ++ .name = "mpeg4_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG4, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &mpeg4_class, ++}; ++#endif ++ ++#if CONFIG_MSMPEG4_CRYSTALHD_DECODER ++static AVClass msmpeg4_class = { ++ "msmpeg4_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_msmpeg4_crystalhd_decoder = { ++ .name = "msmpeg4_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V3, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-4 Part 2 Microsoft variant version 3 (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &msmpeg4_class, ++}; ++#endif ++ ++#if CONFIG_VC1_CRYSTALHD_DECODER ++static AVClass vc1_class = { ++ "vc1_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_vc1_crystalhd_decoder = { ++ .name = "vc1_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VC1, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &vc1_class, ++}; ++#endif ++ ++#if CONFIG_WMV3_CRYSTALHD_DECODER ++static AVClass wmv3_class = { ++ "wmv3_crystalhd", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_wmv3_crystalhd_decoder = { ++ .name = "wmv3_crystalhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV3, ++ .priv_data_size = sizeof(CHDContext), ++ .init = init, ++ .close = uninit, ++ .decode = decode, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 (CrystalHD acceleration)"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUYV422, PIX_FMT_NONE}, ++ .priv_class = &wmv3_class, ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cscd.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cscd.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cscd.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cscd.c 2012-05-14 14:08:53.571324626 +0200 +@@ -149,7 +149,7 @@ + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); +- c->pic.reference = 1; ++ c->pic.reference = 3; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->get_buffer(avctx, &c->pic) < 0) { +@@ -183,7 +183,7 @@ + + // flip upside down, add difference frame + if (buf[0] & 1) { // keyframe +- c->pic.pict_type = FF_I_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_I; + c->pic.key_frame = 1; + switch (c->bpp) { + case 16: +@@ -197,7 +197,7 @@ + c->linelen, c->height); + } + } else { +- c->pic.pict_type = FF_P_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_P; + c->pic.key_frame = 0; + switch (c->bpp) { + case 16: +@@ -228,9 +228,10 @@ + av_log(avctx, AV_LOG_ERROR, + "CamStudio codec error: invalid depth %i bpp\n", + avctx->bits_per_coded_sample); +- return 1; ++ return AVERROR_INVALIDDATA; + } + c->bpp = avctx->bits_per_coded_sample; ++ avcodec_get_frame_defaults(&c->pic); + c->pic.data[0] = NULL; + c->linelen = avctx->width * avctx->bits_per_coded_sample / 8; + c->height = avctx->height; +@@ -241,7 +242,7 @@ + c->decomp_buf = av_malloc(c->decomp_size + AV_LZO_OUTPUT_PADDING); + if (!c->decomp_buf) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); +- return 1; ++ return AVERROR(ENOMEM); + } + return 0; + } +@@ -255,15 +256,14 @@ + } + + AVCodec ff_cscd_decoder = { +- "camstudio", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CSCD, +- sizeof(CamStudioContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "camstudio", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CSCD, ++ .priv_data_size = sizeof(CamStudioContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("CamStudio"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cyuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cyuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/cyuv.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/cyuv.c 2012-05-14 14:08:53.571324626 +0200 +@@ -53,6 +53,7 @@ + return -1; + s->height = avctx->height; + avctx->pix_fmt = PIX_FMT_YUV411P; ++ avcodec_get_frame_defaults(&s->frame); + + return 0; + } +@@ -179,32 +180,28 @@ + + #if CONFIG_AURA_DECODER + AVCodec ff_aura_decoder = { +- "aura", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_AURA, +- sizeof(CyuvDecodeContext), +- cyuv_decode_init, +- NULL, +- cyuv_decode_end, +- cyuv_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "aura", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AURA, ++ .priv_data_size = sizeof(CyuvDecodeContext), ++ .init = cyuv_decode_init, ++ .close = cyuv_decode_end, ++ .decode = cyuv_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Auravision AURA"), + }; + #endif + + #if CONFIG_CYUV_DECODER + AVCodec ff_cyuv_decoder = { +- "cyuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CYUV, +- sizeof(CyuvDecodeContext), +- cyuv_decode_init, +- NULL, +- cyuv_decode_end, +- cyuv_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "cyuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CYUV, ++ .priv_data_size = sizeof(CyuvDecodeContext), ++ .init = cyuv_decode_init, ++ .close = cyuv_decode_end, ++ .decode = cyuv_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Creative YUV (CYUV)"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dca.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dca.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dca.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dca.c 2012-05-14 14:08:53.577324746 +0200 +@@ -29,7 +29,8 @@ + #include "libavutil/common.h" + #include "libavutil/intmath.h" + #include "libavutil/intreadwrite.h" +-#include "libavcore/audioconvert.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "dsputil.h" + #include "fft.h" +@@ -42,15 +43,19 @@ + #include "dcadsp.h" + #include "fmtconvert.h" + ++#if ARCH_ARM ++# include "arm/dca.h" ++#endif ++ + //#define TRACE + +-#define DCA_PRIM_CHANNELS_MAX (7) +-#define DCA_SUBBANDS (32) +-#define DCA_ABITS_MAX (32) /* Should be 28 */ +-#define DCA_SUBSUBFRAMES_MAX (4) +-#define DCA_SUBFRAMES_MAX (16) +-#define DCA_BLOCKS_MAX (16) +-#define DCA_LFE_MAX (3) ++#define DCA_PRIM_CHANNELS_MAX (7) ++#define DCA_SUBBANDS (32) ++#define DCA_ABITS_MAX (32) /* Should be 28 */ ++#define DCA_SUBSUBFRAMES_MAX (4) ++#define DCA_SUBFRAMES_MAX (16) ++#define DCA_BLOCKS_MAX (16) ++#define DCA_LFE_MAX (3) + + enum DCAMode { + DCA_MONO = 0, +@@ -99,6 +104,21 @@ + DCA_EXT_EXSS_XLL = 0x200, ///< lossless extension in ExSS + }; + ++/* -1 are reserved or unknown */ ++static const int dca_ext_audio_descr_mask[] = { ++ DCA_EXT_XCH, ++ -1, ++ DCA_EXT_X96, ++ DCA_EXT_XCH | DCA_EXT_X96, ++ -1, ++ -1, ++ DCA_EXT_XXCH, ++ -1, ++}; ++ ++/* extensions that reside in core substream */ ++#define DCA_CORE_EXTS (DCA_EXT_XCH | DCA_EXT_XXCH | DCA_EXT_X96) ++ + /* Tables for mapping dts channel configurations to libavcodec multichannel api. + * Some compromises have been made for special configurations. Most configurations + * are never used so complete accuracy is not needed. +@@ -106,30 +126,47 @@ + * L = left, R = right, C = center, S = surround, F = front, R = rear, T = total, OV = overhead. + * S -> side, when both rear and back are configured move one of them to the side channel + * OV -> center back +- * All 2 channel configurations -> CH_LAYOUT_STEREO ++ * All 2 channel configurations -> AV_CH_LAYOUT_STEREO + */ +- +-static const int64_t dca_core_channel_layout[] = { +- AV_CH_FRONT_CENTER, ///< 1, A +- AV_CH_LAYOUT_STEREO, ///< 2, A + B (dual mono) +- AV_CH_LAYOUT_STEREO, ///< 2, L + R (stereo) +- AV_CH_LAYOUT_STEREO, ///< 2, (L+R) + (L-R) (sum-difference) +- AV_CH_LAYOUT_STEREO, ///< 2, LT +RT (left and right total) +- AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER, ///< 3, C+L+R +- AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER, ///< 3, L+R+S +- AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER|CH_BACK_CENTER, ///< 4, C + L + R+ S +- AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ///< 4, L + R +SL+ SR +- AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ///< 5, C + L + R+ SL+SR +- AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, ///< 6, CL + CR + L + R + SL + SR +- AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER, ///< 6, C + L + R+ LR + RR + OV +- AV_CH_FRONT_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_BACK_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ///< 6, CF+ CR+LF+ RF+LR + RR +- AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR +- AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2+ SR1 + SR2 +- AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER|AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_BACK_CENTER|AV_CH_SIDE_RIGHT, ///< 8, CL + C+ CR + L + R + SL + S+ SR ++static const uint64_t dca_core_channel_layout[] = { ++ AV_CH_FRONT_CENTER, ///< 1, A ++ AV_CH_LAYOUT_STEREO, ///< 2, A + B (dual mono) ++ AV_CH_LAYOUT_STEREO, ///< 2, L + R (stereo) ++ AV_CH_LAYOUT_STEREO, ///< 2, (L + R) + (L - R) (sum-difference) ++ AV_CH_LAYOUT_STEREO, ///< 2, LT + RT (left and right total) ++ AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER, ///< 3, C + L + R ++ AV_CH_LAYOUT_STEREO | AV_CH_BACK_CENTER, ///< 3, L + R + S ++ AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_BACK_CENTER, ///< 4, C + L + R + S ++ AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT, ///< 4, L + R + SL + SR ++ ++ AV_CH_LAYOUT_STEREO | AV_CH_FRONT_CENTER | AV_CH_SIDE_LEFT | ++ AV_CH_SIDE_RIGHT, ///< 5, C + L + R + SL + SR ++ ++ AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT | ++ AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER, ///< 6, CL + CR + L + R + SL + SR ++ ++ AV_CH_LAYOUT_STEREO | AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT | ++ AV_CH_FRONT_CENTER | AV_CH_BACK_CENTER, ///< 6, C + L + R + LR + RR + OV ++ ++ AV_CH_FRONT_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER | ++ AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_BACK_CENTER | ++ AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT, ///< 6, CF + CR + LF + RF + LR + RR ++ ++ AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_CENTER | ++ AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO | ++ AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT, ///< 7, CL + C + CR + L + R + SL + SR ++ ++ AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER | ++ AV_CH_LAYOUT_STEREO | AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT | ++ AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT, ///< 8, CL + CR + L + R + SL1 + SL2 + SR1 + SR2 ++ ++ AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_CENTER | ++ AV_CH_FRONT_RIGHT_OF_CENTER | AV_CH_LAYOUT_STEREO | ++ AV_CH_SIDE_LEFT | AV_CH_BACK_CENTER | AV_CH_SIDE_RIGHT, ///< 8, CL + C + CR + L + R + SL + S + SR + }; + + static const int8_t dca_lfe_index[] = { +- 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 ++ 1, 2, 2, 2, 2, 3, 2, 3, 2, 3, 2, 3, 1, 3, 2, 3 + }; + + static const int8_t dca_channel_reorder_lfe[][9] = { +@@ -208,19 +245,19 @@ + { 3, 2, 4, 0, 1, 5, 8, 7, 6}, + }; + +-#define DCA_DOLBY 101 /* FIXME */ ++#define DCA_DOLBY 101 /* FIXME */ + +-#define DCA_CHANNEL_BITS 6 +-#define DCA_CHANNEL_MASK 0x3F ++#define DCA_CHANNEL_BITS 6 ++#define DCA_CHANNEL_MASK 0x3F + +-#define DCA_LFE 0x80 ++#define DCA_LFE 0x80 + +-#define HEADER_SIZE 14 ++#define HEADER_SIZE 14 + +-#define DCA_MAX_FRAME_SIZE 16384 +-#define DCA_MAX_EXSS_HEADER_SIZE 4096 ++#define DCA_MAX_FRAME_SIZE 16384 ++#define DCA_MAX_EXSS_HEADER_SIZE 4096 + +-#define DCA_BUFFER_PADDING_SIZE 1024 ++#define DCA_BUFFER_PADDING_SIZE 1024 + + /** Bit allocation */ + typedef struct { +@@ -235,13 +272,16 @@ + static BitAlloc dca_scalefactor; ///< scalefactor VLCs + static BitAlloc dca_smpl_bitalloc[11]; ///< samples VLCs + +-static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, int idx) ++static av_always_inline int get_bitalloc(GetBitContext *gb, BitAlloc *ba, ++ int idx) + { +- return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ba->offset; ++ return get_vlc2(gb, ba->vlc[idx].table, ba->vlc[idx].bits, ba->wrap) + ++ ba->offset; + } + + typedef struct { + AVCodecContext *avctx; ++ AVFrame frame; + /* Frame header */ + int frame_type; ///< type of the current frame + int samples_deficit; ///< deficit sample count +@@ -274,7 +314,6 @@ + + /* Primary audio coding header */ + int subframes; ///< number of subframes +- int is_channels_set; ///< check for if the channel number is already set + int total_channels; ///< number of channels including extensions + int prim_channels; ///< number of primary audio channels + int subband_activity[DCA_PRIM_CHANNELS_MAX]; ///< subband activity count +@@ -287,8 +326,8 @@ + float scalefactor_adj[DCA_PRIM_CHANNELS_MAX][DCA_ABITS_MAX]; ///< scale factor adjustment + + /* Primary audio coding side information */ +- int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes +- int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count ++ int subsubframes[DCA_SUBFRAMES_MAX]; ///< number of subsubframes ++ int partial_samples[DCA_SUBFRAMES_MAX]; ///< partial subsubframe samples count + int prediction_mode[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction mode (ADPCM used or not) + int prediction_vq[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< prediction VQ coefs + int bitalloc[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS]; ///< bit allocation index +@@ -305,36 +344,34 @@ + int lfe_scale_factor; + + /* Subband samples history (for ADPCM) */ +- float subband_samples_hist[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; +- DECLARE_ALIGNED(16, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512]; +- DECLARE_ALIGNED(16, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32]; ++ DECLARE_ALIGNED(16, float, subband_samples_hist)[DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][4]; ++ DECLARE_ALIGNED(32, float, subband_fir_hist)[DCA_PRIM_CHANNELS_MAX][512]; ++ DECLARE_ALIGNED(32, float, subband_fir_noidea)[DCA_PRIM_CHANNELS_MAX][32]; + int hist_index[DCA_PRIM_CHANNELS_MAX]; +- DECLARE_ALIGNED(16, float, raXin)[32]; ++ DECLARE_ALIGNED(32, float, raXin)[32]; + + int output; ///< type of output + float scale_bias; ///< output scale + +- DECLARE_ALIGNED(16, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; +- DECLARE_ALIGNED(16, float, samples)[(DCA_PRIM_CHANNELS_MAX+1)*256]; +- const float *samples_chanptr[DCA_PRIM_CHANNELS_MAX+1]; ++ DECLARE_ALIGNED(32, float, subband_samples)[DCA_BLOCKS_MAX][DCA_PRIM_CHANNELS_MAX][DCA_SUBBANDS][8]; ++ DECLARE_ALIGNED(32, float, samples)[(DCA_PRIM_CHANNELS_MAX + 1) * 256]; ++ const float *samples_chanptr[DCA_PRIM_CHANNELS_MAX + 1]; + + uint8_t dca_buffer[DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE + DCA_BUFFER_PADDING_SIZE]; + int dca_buffer_size; ///< how much data is in the dca_buffer + +- const int8_t* channel_order_tab; ///< channel reordering table, lfe and non lfe ++ const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe + GetBitContext gb; + /* Current position in DCA frame */ + int current_subframe; + int current_subsubframe; + ++ int core_ext_mask; ///< present extensions in the core substream ++ + /* XCh extension information */ +- int xch_present; ++ int xch_present; ///< XCh extension present and valid + int xch_base_channel; ///< index of first (only) channel containing XCH data + +- /* Other detected extensions in the core substream */ +- int xxch_present; +- int x96_present; +- + /* ExSS header parser */ + int static_fields; ///< static fields present + int mix_metadata; ///< mixing metadata present +@@ -398,13 +435,15 @@ + } + + for (i = 0; i < 10; i++) +- for (j = 0; j < 7; j++){ +- if (!bitalloc_codes[i][j]) break; +- dca_smpl_bitalloc[i+1].offset = bitalloc_offsets[i]; +- dca_smpl_bitalloc[i+1].wrap = 1 + (j > 4); +- dca_smpl_bitalloc[i+1].vlc[j].table = &dca_table[dca_vlc_offs[c]]; +- dca_smpl_bitalloc[i+1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c]; +- init_vlc(&dca_smpl_bitalloc[i+1].vlc[j], bitalloc_maxbits[i][j], ++ for (j = 0; j < 7; j++) { ++ if (!bitalloc_codes[i][j]) ++ break; ++ dca_smpl_bitalloc[i + 1].offset = bitalloc_offsets[i]; ++ dca_smpl_bitalloc[i + 1].wrap = 1 + (j > 4); ++ dca_smpl_bitalloc[i + 1].vlc[j].table = &dca_table[dca_vlc_offs[c]]; ++ dca_smpl_bitalloc[i + 1].vlc[j].table_allocated = dca_vlc_offs[c + 1] - dca_vlc_offs[c]; ++ ++ init_vlc(&dca_smpl_bitalloc[i + 1].vlc[j], bitalloc_maxbits[i][j], + bitalloc_sizes[i], + bitalloc_bits[i][j], 1, 1, + bitalloc_codes[i][j], 2, 2, INIT_VLC_USE_NEW_STATIC); +@@ -415,19 +454,19 @@ + + static inline void get_array(GetBitContext *gb, int *dst, int len, int bits) + { +- while(len--) ++ while (len--) + *dst++ = get_bits(gb, bits); + } + +-static int dca_parse_audio_coding_header(DCAContext * s, int base_channel) ++static int dca_parse_audio_coding_header(DCAContext *s, int base_channel) + { + int i, j; + static const float adj_table[4] = { 1.0, 1.1250, 1.2500, 1.4375 }; + static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; +- static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; ++ static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; + +- s->total_channels = get_bits(&s->gb, 3) + 1 + base_channel; +- s->prim_channels = s->total_channels; ++ s->total_channels = get_bits(&s->gb, 3) + 1 + base_channel; ++ s->prim_channels = s->total_channels; + + if (s->prim_channels > DCA_PRIM_CHANNELS_MAX) + s->prim_channels = DCA_PRIM_CHANNELS_MAX; +@@ -470,23 +509,28 @@ + get_bits(&s->gb, 16); + } + +- s->current_subframe = 0; ++ s->current_subframe = 0; + s->current_subsubframe = 0; + + #ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "subframes: %i\n", s->subframes); + av_log(s->avctx, AV_LOG_DEBUG, "prim channels: %i\n", s->prim_channels); +- for (i = base_channel; i < s->prim_channels; i++){ +- av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", s->subband_activity[i]); +- av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", s->vq_start_subband[i]); +- av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", s->joint_intensity[i]); +- av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", s->transient_huffman[i]); +- av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", s->scalefactor_huffman[i]); +- av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", s->bitalloc_huffman[i]); ++ for (i = base_channel; i < s->prim_channels; i++) { ++ av_log(s->avctx, AV_LOG_DEBUG, "subband activity: %i\n", ++ s->subband_activity[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "vq start subband: %i\n", ++ s->vq_start_subband[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "joint intensity: %i\n", ++ s->joint_intensity[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "transient mode codebook: %i\n", ++ s->transient_huffman[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "scale factor codebook: %i\n", ++ s->scalefactor_huffman[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "bit allocation quantizer: %i\n", ++ s->bitalloc_huffman[i]); + av_log(s->avctx, AV_LOG_DEBUG, "quant index huff:"); + for (j = 0; j < 11; j++) +- av_log(s->avctx, AV_LOG_DEBUG, " %i", +- s->quant_index_huffman[i][j]); ++ av_log(s->avctx, AV_LOG_DEBUG, " %i", s->quant_index_huffman[i][j]); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + av_log(s->avctx, AV_LOG_DEBUG, "scalefac adj:"); + for (j = 0; j < 11; j++) +@@ -495,15 +539,15 @@ + } + #endif + +- return 0; ++ return 0; + } + +-static int dca_parse_frame_header(DCAContext * s) ++static int dca_parse_frame_header(DCAContext *s) + { + init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); + + /* Sync code */ +- get_bits(&s->gb, 32); ++ skip_bits_long(&s->gb, 32); + + /* Frame header */ + s->frame_type = get_bits(&s->gb, 1); +@@ -512,15 +556,15 @@ + s->sample_blocks = get_bits(&s->gb, 7) + 1; + s->frame_size = get_bits(&s->gb, 14) + 1; + if (s->frame_size < 95) +- return -1; ++ return AVERROR_INVALIDDATA; + s->amode = get_bits(&s->gb, 6); + s->sample_rate = dca_sample_rates[get_bits(&s->gb, 4)]; + if (!s->sample_rate) +- return -1; ++ return AVERROR_INVALIDDATA; + s->bit_rate_index = get_bits(&s->gb, 5); + s->bit_rate = dca_bit_rates[s->bit_rate_index]; + if (!s->bit_rate) +- return -1; ++ return AVERROR_INVALIDDATA; + + s->downmix = get_bits(&s->gb, 1); + s->dynrange = get_bits(&s->gb, 1); +@@ -547,7 +591,8 @@ + + /* FIXME: channels mixing levels */ + s->output = s->amode; +- if (s->lfe) s->output |= DCA_LFE; ++ if (s->lfe) ++ s->output |= DCA_LFE; + + #ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "frame type: %i\n", s->frame_type); +@@ -594,26 +639,33 @@ + } + + +-static inline int get_scale(GetBitContext *gb, int level, int value) ++static inline int get_scale(GetBitContext *gb, int level, int value, int log2range) + { +- if (level < 5) { +- /* huffman encoded */ +- value += get_bitalloc(gb, &dca_scalefactor, level); +- } else if (level < 8) +- value = get_bits(gb, level + 1); +- return value; ++ if (level < 5) { ++ /* huffman encoded */ ++ value += get_bitalloc(gb, &dca_scalefactor, level); ++ value = av_clip(value, 0, (1 << log2range) - 1); ++ } else if (level < 8) { ++ if (level + 1 > log2range) { ++ skip_bits(gb, level + 1 - log2range); ++ value = get_bits(gb, log2range); ++ } else { ++ value = get_bits(gb, level + 1); ++ } ++ } ++ return value; + } + +-static int dca_subframe_header(DCAContext * s, int base_channel, int block_index) ++static int dca_subframe_header(DCAContext *s, int base_channel, int block_index) + { + /* Primary audio coding side information */ + int j, k; + + if (get_bits_left(&s->gb) < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (!base_channel) { +- s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1; ++ s->subsubframes[s->current_subframe] = get_bits(&s->gb, 2) + 1; + s->partial_samples[s->current_subframe] = get_bits(&s->gb, 3); + } + +@@ -642,16 +694,16 @@ + else if (s->bitalloc_huffman[j] == 7) { + av_log(s->avctx, AV_LOG_ERROR, + "Invalid bit allocation index\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } else { + s->bitalloc[j][k] = + get_bitalloc(&s->gb, &dca_bitalloc_index, s->bitalloc_huffman[j]); + } + + if (s->bitalloc[j][k] > 26) { +-// av_log(s->avctx,AV_LOG_DEBUG,"bitalloc index [%i][%i] too big (%i)\n", +-// j, k, s->bitalloc[j][k]); +- return -1; ++ // av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index [%i][%i] too big (%i)\n", ++ // j, k, s->bitalloc[j][k]); ++ return AVERROR_INVALIDDATA; + } + } + } +@@ -669,31 +721,35 @@ + } + + if (get_bits_left(&s->gb) < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + for (j = base_channel; j < s->prim_channels; j++) { + const uint32_t *scale_table; +- int scale_sum; ++ int scale_sum, log_size; + +- memset(s->scale_factor[j], 0, s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); ++ memset(s->scale_factor[j], 0, ++ s->subband_activity[j] * sizeof(s->scale_factor[0][0][0]) * 2); + +- if (s->scalefactor_huffman[j] == 6) ++ if (s->scalefactor_huffman[j] == 6) { + scale_table = scale_factor_quant7; +- else ++ log_size = 7; ++ } else { + scale_table = scale_factor_quant6; ++ log_size = 6; ++ } + + /* When huffman coded, only the difference is encoded */ + scale_sum = 0; + + for (k = 0; k < s->subband_activity[j]; k++) { + if (k >= s->vq_start_subband[j] || s->bitalloc[j][k] > 0) { +- scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); ++ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size); + s->scale_factor[j][k][0] = scale_table[scale_sum]; + } + + if (k < s->vq_start_subband[j] && s->transition_mode[j][k]) { + /* Get second scale factor */ +- scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum); ++ scale_sum = get_scale(&s->gb, s->scalefactor_huffman[j], scale_sum, log_size); + s->scale_factor[j][k][1] = scale_table[scale_sum]; + } + } +@@ -707,7 +763,7 @@ + } + + if (get_bits_left(&s->gb) < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + /* Scale factors for joint subband coding */ + for (j = base_channel; j < s->prim_channels; j++) { +@@ -722,8 +778,7 @@ + * (is this valid as well for joint scales ???) */ + + for (k = s->subband_activity[j]; k < s->subband_activity[source_channel]; k++) { +- scale = get_scale(&s->gb, s->joint_huff[j], 0); +- scale += 64; /* bias */ ++ scale = get_scale(&s->gb, s->joint_huff[j], 64 /* bias */, 7); + s->joint_scale_factor[j][k] = scale; /*joint_scale_table[scale]; */ + } + +@@ -744,6 +799,11 @@ + } + } else { + int am = s->amode & DCA_CHANNEL_MASK; ++ if (am >= FF_ARRAY_ELEMS(dca_default_coeffs)) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Invalid channel mode %d\n", am); ++ return AVERROR_INVALIDDATA; ++ } + for (j = base_channel; j < s->prim_channels; j++) { + s->downmix_coef[j][0] = dca_default_coeffs[am][j][0]; + s->downmix_coef[j][1] = dca_default_coeffs[am][j][1]; +@@ -783,7 +843,8 @@ + } + + /* Scale factor index */ +- s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 8)]; ++ skip_bits(&s->gb, 1); ++ s->lfe_scale_factor = scale_factor_quant7[get_bits(&s->gb, 7)]; + + /* Quantization step size * scale factor */ + lfe_scale = 0.035 * s->lfe_scale_factor; +@@ -793,9 +854,11 @@ + } + + #ifdef TRACE +- av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", s->subsubframes[s->current_subframe]); ++ av_log(s->avctx, AV_LOG_DEBUG, "subsubframes: %i\n", ++ s->subsubframes[s->current_subframe]); + av_log(s->avctx, AV_LOG_DEBUG, "partial samples: %i\n", + s->partial_samples[s->current_subframe]); ++ + for (j = base_channel; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "prediction mode:"); + for (k = 0; k < s->subband_activity[j]; k++) +@@ -804,12 +867,12 @@ + } + for (j = base_channel; j < s->prim_channels; j++) { + for (k = 0; k < s->subband_activity[j]; k++) +- av_log(s->avctx, AV_LOG_DEBUG, +- "prediction coefs: %f, %f, %f, %f\n", +- (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, +- (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, +- (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, +- (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); ++ av_log(s->avctx, AV_LOG_DEBUG, ++ "prediction coefs: %f, %f, %f, %f\n", ++ (float) adpcm_vb[s->prediction_vq[j][k]][0] / 8192, ++ (float) adpcm_vb[s->prediction_vq[j][k]][1] / 8192, ++ (float) adpcm_vb[s->prediction_vq[j][k]][2] / 8192, ++ (float) adpcm_vb[s->prediction_vq[j][k]][3] / 8192); + } + for (j = base_channel; j < s->prim_channels; j++) { + av_log(s->avctx, AV_LOG_DEBUG, "bitalloc index: "); +@@ -845,8 +908,10 @@ + if (!base_channel && s->prim_channels > 2 && s->downmix) { + av_log(s->avctx, AV_LOG_DEBUG, "Downmix coeffs:\n"); + for (j = 0; j < s->prim_channels; j++) { +- av_log(s->avctx, AV_LOG_DEBUG, "Channel 0,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][0]]); +- av_log(s->avctx, AV_LOG_DEBUG, "Channel 1,%d = %f\n", j, dca_downmix_coeffs[s->downmix_coef[j][1]]); ++ av_log(s->avctx, AV_LOG_DEBUG, "Channel 0, %d = %f\n", j, ++ dca_downmix_coeffs[s->downmix_coef[j][0]]); ++ av_log(s->avctx, AV_LOG_DEBUG, "Channel 1, %d = %f\n", j, ++ dca_downmix_coeffs[s->downmix_coef[j][1]]); + } + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } +@@ -867,7 +932,7 @@ + return 0; + } + +-static void qmf_32_subbands(DCAContext * s, int chans, ++static void qmf_32_subbands(DCAContext *s, int chans, + float samples_in[32][8], float *samples_out, + float scale) + { +@@ -877,7 +942,7 @@ + int sb_act = s->subband_activity[chans]; + int subindex; + +- scale *= sqrt(1/8.0); ++ scale *= sqrt(1 / 8.0); + + /* Select filter */ + if (!s->multirate_inter) /* Non-perfect reconstruction */ +@@ -885,22 +950,24 @@ + else /* Perfect reconstruction */ + prCoeff = fir_32bands_perfect; + ++ for (i = sb_act; i < 32; i++) ++ s->raXin[i] = 0.0; ++ + /* Reconstructed channel sample index */ + for (subindex = 0; subindex < 8; subindex++) { + /* Load in one sample from each subband and clear inactive subbands */ +- for (i = 0; i < sb_act; i++){ +- uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ ((i-1)&2)<<30; ++ for (i = 0; i < sb_act; i++) { ++ unsigned sign = (i - 1) & 2; ++ uint32_t v = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30; + AV_WN32A(&s->raXin[i], v); + } +- for (; i < 32; i++) +- s->raXin[i] = 0.0; + + s->synth.synth_filter_float(&s->imdct, +- s->subband_fir_hist[chans], &s->hist_index[chans], +- s->subband_fir_noidea[chans], prCoeff, +- samples_out, s->raXin, scale); +- samples_out+= 32; +- ++ s->subband_fir_hist[chans], ++ &s->hist_index[chans], ++ s->subband_fir_noidea[chans], prCoeff, ++ samples_out, s->raXin, scale); ++ samples_out += 32; + } + } + +@@ -930,45 +997,44 @@ + } + /* Interpolation */ + for (deciindex = 0; deciindex < num_deci_sample; deciindex++) { +- s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, +- scale); ++ s->dcadsp.lfe_fir(samples_out, samples_in, prCoeff, decifactor, scale); + samples_in++; + samples_out += 2 * decifactor; + } + } + + /* downmixing routines */ +-#define MIX_REAR1(samples, si1, rs, coef) \ +- samples[i] += samples[si1] * coef[rs][0]; \ +- samples[i+256] += samples[si1] * coef[rs][1]; +- +-#define MIX_REAR2(samples, si1, si2, rs, coef) \ +- samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs+1][0]; \ +- samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs+1][1]; +- +-#define MIX_FRONT3(samples, coef) \ +- t = samples[i+c]; \ +- u = samples[i+l]; \ +- v = samples[i+r]; \ ++#define MIX_REAR1(samples, si1, rs, coef) \ ++ samples[i] += samples[si1] * coef[rs][0]; \ ++ samples[i+256] += samples[si1] * coef[rs][1]; ++ ++#define MIX_REAR2(samples, si1, si2, rs, coef) \ ++ samples[i] += samples[si1] * coef[rs][0] + samples[si2] * coef[rs + 1][0]; \ ++ samples[i+256] += samples[si1] * coef[rs][1] + samples[si2] * coef[rs + 1][1]; ++ ++#define MIX_FRONT3(samples, coef) \ ++ t = samples[i + c]; \ ++ u = samples[i + l]; \ ++ v = samples[i + r]; \ + samples[i] = t * coef[0][0] + u * coef[1][0] + v * coef[2][0]; \ + samples[i+256] = t * coef[0][1] + u * coef[1][1] + v * coef[2][1]; + +-#define DOWNMIX_TO_STEREO(op1, op2) \ +- for (i = 0; i < 256; i++){ \ +- op1 \ +- op2 \ ++#define DOWNMIX_TO_STEREO(op1, op2) \ ++ for (i = 0; i < 256; i++) { \ ++ op1 \ ++ op2 \ + } + + static void dca_downmix(float *samples, int srcfmt, + int downmix_coef[DCA_PRIM_CHANNELS_MAX][2], + const int8_t *channel_mapping) + { +- int c,l,r,sl,sr,s; ++ int c, l, r, sl, sr, s; + int i; + float t, u, v; + float coef[DCA_PRIM_CHANNELS_MAX][2]; + +- for (i=0; icurrent_subsubframe; +@@ -1066,7 +1145,7 @@ + + for (k = base_channel; k < s->prim_channels; k++) { + if (get_bits_left(&s->gb) < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + for (l = 0; l < s->vq_start_subband[k]; l++) { + int m; +@@ -1086,39 +1165,45 @@ + /* + * Extract bits from the bit stream + */ +- if (!abits){ ++ if (!abits) { + memset(subband_samples[k][l], 0, 8 * sizeof(subband_samples[0][0][0])); + } else { + /* Deal with transients */ + int sfi = s->transition_mode[k][l] && subsubframe >= s->transition_mode[k][l]; +- float rscale = quant_step_size * s->scale_factor[k][l][sfi] * s->scalefactor_adj[k][sel]; ++ float rscale = quant_step_size * s->scale_factor[k][l][sfi] * ++ s->scalefactor_adj[k][sel]; + +- if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table){ +- if (abits <= 7){ ++ if (abits >= 11 || !dca_smpl_bitalloc[abits].vlc[sel].table) { ++ if (abits <= 7) { + /* Block code */ +- int block_code1, block_code2, size, levels; ++ int block_code1, block_code2, size, levels, err; + +- size = abits_sizes[abits-1]; +- levels = abits_levels[abits-1]; ++ size = abits_sizes[abits - 1]; ++ levels = abits_levels[abits - 1]; + + block_code1 = get_bits(&s->gb, size); +- /* FIXME Should test return value */ +- decode_blockcode(block_code1, levels, block); + block_code2 = get_bits(&s->gb, size); +- decode_blockcode(block_code2, levels, &block[4]); +- }else{ ++ err = decode_blockcodes(block_code1, block_code2, ++ levels, block); ++ if (err) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "ERROR: block code look-up failed\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } else { + /* no coding */ + for (m = 0; m < 8; m++) + block[m] = get_sbits(&s->gb, abits - 3); + } +- }else{ ++ } else { + /* Huffman coded */ + for (m = 0; m < 8; m++) +- block[m] = get_bitalloc(&s->gb, &dca_smpl_bitalloc[abits], sel); ++ block[m] = get_bitalloc(&s->gb, ++ &dca_smpl_bitalloc[abits], sel); + } + + s->fmt_conv.int32_to_float_fmul_scalar(subband_samples[k][l], +- block, rscale, 8); ++ block, rscale, 8); + } + + /* +@@ -1135,8 +1220,7 @@ + else if (s->predictor_history) + subband_samples[k][l][m] += + (adpcm_vb[s->prediction_vq[k][l]][n - 1] * +- s->subband_samples_hist[k][l][m - n + +- 4] / 8192); ++ s->subband_samples_hist[k][l][m - n + 4] / 8192); + } + } + } +@@ -1147,19 +1231,17 @@ + for (l = s->vq_start_subband[k]; l < s->subband_activity[k]; l++) { + /* 1 vector -> 32 samples but we only need the 8 samples + * for this subsubframe. */ +- int m; ++ int hfvq = s->high_freq_vq[k][l]; + + if (!s->debug_flag & 0x01) { +- av_log(s->avctx, AV_LOG_DEBUG, "Stream with high frequencies VQ coding\n"); ++ av_log(s->avctx, AV_LOG_DEBUG, ++ "Stream with high frequencies VQ coding\n"); + s->debug_flag |= 0x01; + } + +- for (m = 0; m < 8; m++) { +- subband_samples[k][l][m] = +- high_freq_vq[s->high_freq_vq[k][l]][subsubframe * 8 + +- m] +- * (float) s->scale_factor[k][l][0] / 16.0; +- } ++ int8x8_fmul_int32(subband_samples[k][l], ++ &high_freq_vq[hfvq][subsubframe * 8], ++ s->scale_factor[k][l][0]); + } + } + +@@ -1177,23 +1259,25 @@ + /* Backup predictor history for adpcm */ + for (k = base_channel; k < s->prim_channels; k++) + for (l = 0; l < s->vq_start_subband[k]; l++) +- memcpy(s->subband_samples_hist[k][l], &subband_samples[k][l][4], +- 4 * sizeof(subband_samples[0][0][0])); ++ memcpy(s->subband_samples_hist[k][l], ++ &subband_samples[k][l][4], ++ 4 * sizeof(subband_samples[0][0][0])); + + return 0; + } + +-static int dca_filter_channels(DCAContext * s, int block_index) ++static int dca_filter_channels(DCAContext *s, int block_index) + { + float (*subband_samples)[DCA_SUBBANDS][8] = s->subband_samples[block_index]; + int k; + + /* 32 subbands QMF */ + for (k = 0; k < s->prim_channels; k++) { +-/* static float pcm_to_double[8] = +- {32768.0, 32768.0, 524288.0, 524288.0, 0, 8388608.0, 8388608.0};*/ +- qmf_32_subbands(s, k, subband_samples[k], &s->samples[256 * s->channel_order_tab[k]], +- M_SQRT1_2*s->scale_bias /*pcm_to_double[s->source_pcm_res] */ ); ++/* static float pcm_to_double[8] = { 32768.0, 32768.0, 524288.0, 524288.0, ++ 0, 8388608.0, 8388608.0 };*/ ++ qmf_32_subbands(s, k, subband_samples[k], ++ &s->samples[256 * s->channel_order_tab[k]], ++ M_SQRT1_2 * s->scale_bias /* pcm_to_double[s->source_pcm_res] */); + } + + /* Down mixing */ +@@ -1206,7 +1290,7 @@ + lfe_interpolation_fir(s, s->lfe, 2 * s->lfe, + s->lfe_data + 2 * s->lfe * (block_index + 4), + &s->samples[256 * dca_lfe_index[s->amode]], +- (1.0/256.0)*s->scale_bias); ++ (1.0 / 256.0) * s->scale_bias); + /* Outputs 20bits pcm samples */ + } + +@@ -1214,7 +1298,7 @@ + } + + +-static int dca_subframe_footer(DCAContext * s, int base_channel) ++static int dca_subframe_footer(DCAContext *s, int base_channel) + { + int aux_data_count = 0, i; + +@@ -1225,7 +1309,7 @@ + /* presumably optional information only appears in the core? */ + if (!base_channel) { + if (s->timestamp) +- get_bits(&s->gb, 32); ++ skip_bits_long(&s->gb, 32); + + if (s->aux_data) + aux_data_count = get_bits(&s->gb, 6); +@@ -1246,14 +1330,15 @@ + * @param s pointer to the DCAContext + */ + +-static int dca_decode_block(DCAContext * s, int base_channel, int block_index) ++static int dca_decode_block(DCAContext *s, int base_channel, int block_index) + { ++ int ret; + + /* Sanity check */ + if (s->current_subframe >= s->subframes) { + av_log(s->avctx, AV_LOG_DEBUG, "check failed: %i>%i", + s->current_subframe, s->subframes); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (!s->current_subsubframe) { +@@ -1261,16 +1346,16 @@ + av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_header\n"); + #endif + /* Read subframe header */ +- if (dca_subframe_header(s, base_channel, block_index)) +- return -1; ++ if ((ret = dca_subframe_header(s, base_channel, block_index))) ++ return ret; + } + + /* Read subsubframe */ + #ifdef TRACE + av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subsubframe\n"); + #endif +- if (dca_subsubframe(s, base_channel, block_index)) +- return -1; ++ if ((ret = dca_subsubframe(s, base_channel, block_index))) ++ return ret; + + /* Update state */ + s->current_subsubframe++; +@@ -1283,8 +1368,8 @@ + av_log(s->avctx, AV_LOG_DEBUG, "DSYNC dca_subframe_footer\n"); + #endif + /* Read subframe footer */ +- if (dca_subframe_footer(s, base_channel)) +- return -1; ++ if ((ret = dca_subframe_footer(s, base_channel))) ++ return ret; + } + + return 0; +@@ -1293,8 +1378,8 @@ + /** + * Convert bitstream to one representation based on sync marker + */ +-static int dca_convert_bitstream(const uint8_t * src, int src_size, uint8_t * dst, +- int max_size) ++static int dca_convert_bitstream(const uint8_t *src, int src_size, uint8_t *dst, ++ int max_size) + { + uint32_t mrk; + int i, tmp; +@@ -1302,8 +1387,8 @@ + uint16_t *sdst = (uint16_t *) dst; + PutBitContext pb; + +- if ((unsigned)src_size > (unsigned)max_size) { +-// av_log(NULL, AV_LOG_ERROR, "Input frame size larger then DCA_MAX_FRAME_SIZE!\n"); ++ if ((unsigned) src_size > (unsigned) max_size) { ++// av_log(NULL, AV_LOG_ERROR, "Input frame size larger than DCA_MAX_FRAME_SIZE!\n"); + // return -1; + src_size = max_size; + } +@@ -1327,7 +1412,7 @@ + flush_put_bits(&pb); + return (put_bits_count(&pb) + 7) >> 3; + default: +- return -1; ++ return AVERROR_INVALIDDATA; + } + } + +@@ -1337,18 +1422,16 @@ + static int dca_exss_mask2count(int mask) + { + /* count bits that mean speaker pairs twice */ +- return av_popcount(mask) +- + av_popcount(mask & ( +- DCA_EXSS_CENTER_LEFT_RIGHT +- | DCA_EXSS_FRONT_LEFT_RIGHT +- | DCA_EXSS_FRONT_HIGH_LEFT_RIGHT +- | DCA_EXSS_WIDE_LEFT_RIGHT +- | DCA_EXSS_SIDE_LEFT_RIGHT +- | DCA_EXSS_SIDE_HIGH_LEFT_RIGHT +- | DCA_EXSS_SIDE_REAR_LEFT_RIGHT +- | DCA_EXSS_REAR_LEFT_RIGHT +- | DCA_EXSS_REAR_HIGH_LEFT_RIGHT +- )); ++ return av_popcount(mask) + ++ av_popcount(mask & (DCA_EXSS_CENTER_LEFT_RIGHT | ++ DCA_EXSS_FRONT_LEFT_RIGHT | ++ DCA_EXSS_FRONT_HIGH_LEFT_RIGHT | ++ DCA_EXSS_WIDE_LEFT_RIGHT | ++ DCA_EXSS_SIDE_LEFT_RIGHT | ++ DCA_EXSS_SIDE_HIGH_LEFT_RIGHT | ++ DCA_EXSS_SIDE_REAR_LEFT_RIGHT | ++ DCA_EXSS_REAR_LEFT_RIGHT | ++ DCA_EXSS_REAR_HIGH_LEFT_RIGHT)); + } + + /** +@@ -1372,11 +1455,11 @@ + { + int header_pos = get_bits_count(&s->gb); + int header_size; +- int channels; ++ int channels = 0; + int embedded_stereo = 0; +- int embedded_6ch = 0; ++ int embedded_6ch = 0; + int drc_code_present; +- int extensions_mask; ++ int av_uninit(extensions_mask); + int i, j; + + if (get_bits_left(&s->gb) < 16) +@@ -1508,12 +1591,10 @@ + + if (!(extensions_mask & DCA_EXT_CORE)) + av_log(s->avctx, AV_LOG_WARNING, "DTS core detection mismatch.\n"); +- if (!!(extensions_mask & DCA_EXT_XCH) != s->xch_present) +- av_log(s->avctx, AV_LOG_WARNING, "DTS XCh detection mismatch.\n"); +- if (!!(extensions_mask & DCA_EXT_XXCH) != s->xxch_present) +- av_log(s->avctx, AV_LOG_WARNING, "DTS XXCh detection mismatch.\n"); +- if (!!(extensions_mask & DCA_EXT_X96) != s->x96_present) +- av_log(s->avctx, AV_LOG_WARNING, "DTS X96 detection mismatch.\n"); ++ if ((extensions_mask & DCA_CORE_EXTS) != s->core_ext_mask) ++ av_log(s->avctx, AV_LOG_WARNING, ++ "DTS extensions detection mismatch (%d, %d)\n", ++ extensions_mask & DCA_CORE_EXTS, s->core_ext_mask); + + return 0; + } +@@ -1525,8 +1606,6 @@ + { + int ss_index; + int blownup; +- int header_size; +- int hd_size; + int num_audiop = 1; + int num_assets = 1; + int active_ss_mask[8]; +@@ -1539,8 +1618,8 @@ + ss_index = get_bits(&s->gb, 2); + + blownup = get_bits1(&s->gb); +- header_size = get_bits(&s->gb, 8 + 4 * blownup) + 1; +- hd_size = get_bits_long(&s->gb, 16 + 4 * blownup) + 1; ++ skip_bits(&s->gb, 8 + 4 * blownup); // header_size ++ skip_bits(&s->gb, 16 + 4 * blownup); // hd_size + + s->static_fields = get_bits1(&s->gb); + if (s->static_fields) { +@@ -1580,18 +1659,18 @@ + int mix_out_mask_size; + + skip_bits(&s->gb, 2); // adjustment level +- mix_out_mask_size = (get_bits(&s->gb, 2) + 1) << 2; +- s->num_mix_configs = get_bits(&s->gb, 2) + 1; ++ mix_out_mask_size = (get_bits(&s->gb, 2) + 1) << 2; ++ s->num_mix_configs = get_bits(&s->gb, 2) + 1; + + for (i = 0; i < s->num_mix_configs; i++) { +- int mix_out_mask = get_bits(&s->gb, mix_out_mask_size); ++ int mix_out_mask = get_bits(&s->gb, mix_out_mask_size); + s->mix_config_num_ch[i] = dca_exss_mask2count(mix_out_mask); + } + } + } + + for (i = 0; i < num_assets; i++) +- skip_bits_long(&s->gb, 16 + 4 * blownup); // asset size ++ skip_bits_long(&s->gb, 16 + 4 * blownup); // asset size + + for (i = 0; i < num_assets; i++) { + if (dca_exss_parse_asset_header(s)) +@@ -1606,133 +1685,156 @@ + * Main frame decoding function + * FIXME add arguments + */ +-static int dca_decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int dca_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + + int lfe_samples; + int num_core_channels = 0; +- int i; +- int16_t *samples = data; ++ int i, ret; ++ float *samples_flt; ++ int16_t *samples_s16; + DCAContext *s = avctx->priv_data; + int channels; + int core_ss_end; + + + s->xch_present = 0; +- s->x96_present = 0; +- s->xxch_present = 0; + + s->dca_buffer_size = dca_convert_bitstream(buf, buf_size, s->dca_buffer, + DCA_MAX_FRAME_SIZE + DCA_MAX_EXSS_HEADER_SIZE); +- if (s->dca_buffer_size == -1) { ++ if (s->dca_buffer_size == AVERROR_INVALIDDATA) { + av_log(avctx, AV_LOG_ERROR, "Not a valid DCA frame\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + init_get_bits(&s->gb, s->dca_buffer, s->dca_buffer_size * 8); +- if (dca_parse_frame_header(s) < 0) { ++ if ((ret = dca_parse_frame_header(s)) < 0) { + //seems like the frame is corrupt, try with the next one +- *data_size=0; +- return buf_size; ++ return ret; + } + //set AVCodec values with parsed data + avctx->sample_rate = s->sample_rate; +- avctx->bit_rate = s->bit_rate; +- avctx->frame_size = s->sample_blocks * 32; ++ avctx->bit_rate = s->bit_rate; ++ avctx->frame_size = s->sample_blocks * 32; + + s->profile = FF_PROFILE_DTS; + + for (i = 0; i < (s->sample_blocks / 8); i++) { +- dca_decode_block(s, 0, i); ++ if ((ret = dca_decode_block(s, 0, i))) { ++ av_log(avctx, AV_LOG_ERROR, "error decoding block\n"); ++ return ret; ++ } + } + + /* record number of core channels incase less than max channels are requested */ + num_core_channels = s->prim_channels; + +- /* extensions start at 32-bit boundaries into bitstream */ +- skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); ++ if (s->ext_coding) ++ s->core_ext_mask = dca_ext_audio_descr_mask[s->ext_descr]; ++ else ++ s->core_ext_mask = 0; + + core_ss_end = FFMIN(s->frame_size, s->dca_buffer_size) * 8; + +- while(core_ss_end - get_bits_count(&s->gb) >= 32) { +- uint32_t bits = get_bits_long(&s->gb, 32); ++ /* only scan for extensions if ext_descr was unknown or indicated a ++ * supported XCh extension */ ++ if (s->core_ext_mask < 0 || s->core_ext_mask & DCA_EXT_XCH) { ++ ++ /* if ext_descr was unknown, clear s->core_ext_mask so that the ++ * extensions scan can fill it up */ ++ s->core_ext_mask = FFMAX(s->core_ext_mask, 0); + +- switch(bits) { +- case 0x5a5a5a5a: { +- int ext_amode, xch_fsize; +- +- s->xch_base_channel = s->prim_channels; +- +- /* validate sync word using XCHFSIZE field */ +- xch_fsize = show_bits(&s->gb, 10); +- if((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) && +- (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1)) +- continue; ++ /* extensions start at 32-bit boundaries into bitstream */ ++ skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); + +- /* skip length-to-end-of-frame field for the moment */ +- skip_bits(&s->gb, 10); ++ while (core_ss_end - get_bits_count(&s->gb) >= 32) { ++ uint32_t bits = get_bits_long(&s->gb, 32); + +- s->profile = FFMAX(s->profile, FF_PROFILE_DTS_ES); ++ switch (bits) { ++ case 0x5a5a5a5a: { ++ int ext_amode, xch_fsize; ++ ++ s->xch_base_channel = s->prim_channels; ++ ++ /* validate sync word using XCHFSIZE field */ ++ xch_fsize = show_bits(&s->gb, 10); ++ if ((s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize) && ++ (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + xch_fsize + 1)) ++ continue; ++ ++ /* skip length-to-end-of-frame field for the moment */ ++ skip_bits(&s->gb, 10); ++ ++ s->core_ext_mask |= DCA_EXT_XCH; ++ ++ /* extension amode(number of channels in extension) should be 1 */ ++ /* AFAIK XCh is not used for more channels */ ++ if ((ext_amode = get_bits(&s->gb, 4)) != 1) { ++ av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not" ++ " supported!\n", ext_amode); ++ continue; ++ } + +- /* extension amode should == 1, number of channels in extension */ +- /* AFAIK XCh is not used for more channels */ +- if ((ext_amode = get_bits(&s->gb, 4)) != 1) { +- av_log(avctx, AV_LOG_ERROR, "XCh extension amode %d not" +- " supported!\n",ext_amode); +- continue; +- } ++ /* much like core primary audio coding header */ ++ dca_parse_audio_coding_header(s, s->xch_base_channel); + +- /* much like core primary audio coding header */ +- dca_parse_audio_coding_header(s, s->xch_base_channel); ++ for (i = 0; i < (s->sample_blocks / 8); i++) ++ if ((ret = dca_decode_block(s, s->xch_base_channel, i))) { ++ av_log(avctx, AV_LOG_ERROR, "error decoding XCh extension\n"); ++ continue; ++ } + +- for (i = 0; i < (s->sample_blocks / 8); i++) { +- dca_decode_block(s, s->xch_base_channel, i); ++ s->xch_present = 1; ++ break; + } ++ case 0x47004a03: ++ /* XXCh: extended channels */ ++ /* usually found either in core or HD part in DTS-HD HRA streams, ++ * but not in DTS-ES which contains XCh extensions instead */ ++ s->core_ext_mask |= DCA_EXT_XXCH; ++ break; + +- s->xch_present = 1; +- break; +- } +- case 0x47004a03: +- /* XXCh: extended channels */ +- /* usually found either in core or HD part in DTS-HD HRA streams, +- * but not in DTS-ES which contains XCh extensions instead */ +- s->xxch_present = 1; +- s->profile = FFMAX(s->profile, FF_PROFILE_DTS_ES); +- break; ++ case 0x1d95f262: { ++ int fsize96 = show_bits(&s->gb, 12) + 1; ++ if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96) ++ continue; + +- case 0x1d95f262: { +- int fsize96 = show_bits(&s->gb, 12) + 1; +- if (s->frame_size != (get_bits_count(&s->gb) >> 3) - 4 + fsize96) +- continue; ++ av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n", ++ get_bits_count(&s->gb)); ++ skip_bits(&s->gb, 12); ++ av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96); ++ av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4)); + +- av_log(avctx, AV_LOG_DEBUG, "X96 extension found at %d bits\n", get_bits_count(&s->gb)); +- skip_bits(&s->gb, 12); +- av_log(avctx, AV_LOG_DEBUG, "FSIZE96 = %d bytes\n", fsize96); +- av_log(avctx, AV_LOG_DEBUG, "REVNO = %d\n", get_bits(&s->gb, 4)); ++ s->core_ext_mask |= DCA_EXT_X96; ++ break; ++ } ++ } + +- s->x96_present = 1; +- s->profile = FFMAX(s->profile, FF_PROFILE_DTS_96_24); +- break; +- } ++ skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); + } +- +- skip_bits_long(&s->gb, (-get_bits_count(&s->gb)) & 31); ++ } else { ++ /* no supported extensions, skip the rest of the core substream */ ++ skip_bits_long(&s->gb, core_ss_end - get_bits_count(&s->gb)); + } + ++ if (s->core_ext_mask & DCA_EXT_X96) ++ s->profile = FF_PROFILE_DTS_96_24; ++ else if (s->core_ext_mask & (DCA_EXT_XCH | DCA_EXT_XXCH)) ++ s->profile = FF_PROFILE_DTS_ES; ++ + /* check for ExSS (HD part) */ +- if (s->dca_buffer_size - s->frame_size > 32 +- && get_bits_long(&s->gb, 32) == DCA_HD_MARKER) ++ if (s->dca_buffer_size - s->frame_size > 32 && ++ get_bits_long(&s->gb, 32) == DCA_HD_MARKER) + dca_exss_parse_header(s); + + avctx->profile = s->profile; + + channels = s->prim_channels + !!s->lfe; + +- if (s->amode<16) { ++ if (s->amode < 16) { + avctx->channel_layout = dca_core_channel_layout[s->amode]; + + if (s->xch_present && (!avctx->request_channels || +@@ -1756,37 +1858,36 @@ + + if (channels > !!s->lfe && + s->channel_order_tab[channels - 1 - !!s->lfe] < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (avctx->request_channels == 2 && s->prim_channels > 2) { + channels = 2; + s->output = DCA_STEREO; + avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } ++ else if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) { ++ static const int8_t dca_channel_order_native[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; ++ s->channel_order_tab = dca_channel_order_native; ++ } + } else { +- av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n",s->amode); +- return -1; ++ av_log(avctx, AV_LOG_ERROR, "Non standard configuration %d !\n", s->amode); ++ return AVERROR_INVALIDDATA; + } + +- +- /* There is nothing that prevents a dts frame to change channel configuration +- but FFmpeg doesn't support that so only set the channels if it is previously +- unset. Ideally during the first probe for channels the crc should be checked +- and only set avctx->channels when the crc is ok. Right now the decoder could +- set the channels based on a broken first frame.*/ +- if (s->is_channels_set == 0) { +- s->is_channels_set = 1; +- avctx->channels = channels; +- } + if (avctx->channels != channels) { +- av_log(avctx, AV_LOG_ERROR, "DCA decoder does not support number of " +- "channels changing in stream. Skipping frame.\n"); +- return -1; ++ if (avctx->channels) ++ av_log(avctx, AV_LOG_INFO, "Number of channels changed in DCA decoder (%d -> %d)\n", avctx->channels, channels); ++ avctx->channels = channels; + } + +- if (*data_size < (s->sample_blocks / 8) * 256 * sizeof(int16_t) * channels) +- return -1; +- *data_size = 256 / 8 * s->sample_blocks * sizeof(int16_t) * channels; ++ /* get output buffer */ ++ s->frame.nb_samples = 256 * (s->sample_blocks / 8); ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples_flt = (float *) s->frame.data[0]; ++ samples_s16 = (int16_t *) s->frame.data[0]; + + /* filter to get final output */ + for (i = 0; i < (s->sample_blocks / 8); i++) { +@@ -1794,26 +1895,33 @@ + + /* If this was marked as a DTS-ES stream we need to subtract back- */ + /* channel from SL & SR to remove matrixed back-channel signal */ +- if((s->source_pcm_res & 1) && s->xch_present) { +- float* back_chan = s->samples + s->channel_order_tab[s->xch_base_channel] * 256; +- float* lt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 2] * 256; +- float* rt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 1] * 256; +- int j; +- for(j = 0; j < 256; ++j) { +- lt_chan[j] -= back_chan[j] * M_SQRT1_2; +- rt_chan[j] -= back_chan[j] * M_SQRT1_2; +- } ++ if ((s->source_pcm_res & 1) && s->xch_present) { ++ float *back_chan = s->samples + s->channel_order_tab[s->xch_base_channel] * 256; ++ float *lt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 2] * 256; ++ float *rt_chan = s->samples + s->channel_order_tab[s->xch_base_channel - 1] * 256; ++ s->dsp.vector_fmac_scalar(lt_chan, back_chan, -M_SQRT1_2, 256); ++ s->dsp.vector_fmac_scalar(rt_chan, back_chan, -M_SQRT1_2, 256); + } + +- s->fmt_conv.float_to_int16_interleave(samples, s->samples_chanptr, 256, channels); +- samples += 256 * channels; ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { ++ s->fmt_conv.float_interleave(samples_flt, s->samples_chanptr, 256, ++ channels); ++ samples_flt += 256 * channels; ++ } else { ++ s->fmt_conv.float_to_int16_interleave(samples_s16, ++ s->samples_chanptr, 256, ++ channels); ++ samples_s16 += 256 * channels; ++ } + } + + /* update lfe history */ + lfe_samples = 2 * s->lfe * (s->sample_blocks / 8); +- for (i = 0; i < 2 * s->lfe * 4; i++) { ++ for (i = 0; i < 2 * s->lfe * 4; i++) + s->lfe_data[i] = s->lfe_data[i + lfe_samples]; +- } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *) data = s->frame; + + return buf_size; + } +@@ -1826,7 +1934,7 @@ + * @param avctx pointer to the AVCodecContext + */ + +-static av_cold int dca_decode_init(AVCodecContext * avctx) ++static av_cold int dca_decode_init(AVCodecContext *avctx) + { + DCAContext *s = avctx->priv_data; + int i; +@@ -1840,11 +1948,16 @@ + ff_dcadsp_init(&s->dcadsp); + ff_fmt_convert_init(&s->fmt_conv, avctx); + +- for (i = 0; i < DCA_PRIM_CHANNELS_MAX+1; i++) ++ for (i = 0; i < DCA_PRIM_CHANNELS_MAX + 1; i++) + s->samples_chanptr[i] = s->samples + i * 256; +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; + +- s->scale_bias = 1.0; ++ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ s->scale_bias = 1.0 / 32768.0; ++ } else { ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ s->scale_bias = 1.0; ++ } + + /* allow downmixing to stereo */ + if (avctx->channels > 0 && avctx->request_channels < avctx->channels && +@@ -1852,10 +1965,13 @@ + avctx->channels = avctx->request_channels; + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +-static av_cold int dca_decode_end(AVCodecContext * avctx) ++static av_cold int dca_decode_end(AVCodecContext *avctx) + { + DCAContext *s = avctx->priv_data; + ff_mdct_end(&s->imdct); +@@ -1872,14 +1988,17 @@ + }; + + AVCodec ff_dca_decoder = { +- .name = "dca", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_DTS, +- .priv_data_size = sizeof(DCAContext), +- .init = dca_decode_init, +- .decode = dca_decode_frame, +- .close = dca_decode_end, +- .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"), +- .capabilities = CODEC_CAP_CHANNEL_CONF, +- .profiles = NULL_IF_CONFIG_SMALL(profiles), ++ .name = "dca", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_DTS, ++ .priv_data_size = sizeof(DCAContext), ++ .init = dca_decode_init, ++ .decode = dca_decode_frame, ++ .close = dca_decode_end, ++ .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"), ++ .capabilities = CODEC_CAP_CHANNEL_CONF | CODEC_CAP_DR1, ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, ++ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, ++ .profiles = NULL_IF_CONFIG_SMALL(profiles), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcadata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcadata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcadata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcadata.h 2012-05-14 14:08:53.584324888 +0200 +@@ -4224,7 +4224,7 @@ + + /* Vector quantization tables */ + +-static const int8_t high_freq_vq[1024][32] = ++DECLARE_ALIGNED(8, static const int8_t, high_freq_vq)[1024][32] = + { + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, +@@ -7528,7 +7528,7 @@ + 0.001412537544623, 0.001000000000000, 0.000501187233627, 0.000251188643151, 0.000000000000000, + }; + +-static const uint8_t dca_default_coeffs[16][5][2] = { ++static const uint8_t dca_default_coeffs[10][5][2] = { + { { 13, 13 }, }, + { { 0, 64 }, { 64, 0 }, }, + { { 0, 64 }, { 64, 0 }, }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcaenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcaenc.c 2012-05-14 14:08:53.586324928 +0200 +@@ -0,0 +1,587 @@ ++/* ++ * DCA encoder ++ * Copyright (C) 2008 Alexander E. Patrakov ++ * 2010 Benjamin Larsson ++ * 2011 Xiang Wang ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/common.h" ++#include "libavutil/avassert.h" ++#include "libavutil/audioconvert.h" ++#include "avcodec.h" ++#include "get_bits.h" ++#include "put_bits.h" ++#include "dcaenc.h" ++#include "dcadata.h" ++ ++#undef NDEBUG ++ ++#define MAX_CHANNELS 6 ++#define DCA_SUBBANDS_32 32 ++#define DCA_MAX_FRAME_SIZE 16383 ++#define DCA_HEADER_SIZE 13 ++ ++#define DCA_SUBBANDS 32 ///< Subband activity count ++#define QUANTIZER_BITS 16 ++#define SUBFRAMES 1 ++#define SUBSUBFRAMES 4 ++#define PCM_SAMPLES (SUBFRAMES*SUBSUBFRAMES*8) ++#define LFE_BITS 8 ++#define LFE_INTERPOLATION 64 ++#define LFE_PRESENT 2 ++#define LFE_MISSING 0 ++ ++static const int8_t dca_lfe_index[] = { ++ 1,2,2,2,2,3,2,3,2,3,2,3,1,3,2,3 ++}; ++ ++static const int8_t dca_channel_reorder_lfe[][9] = { ++ { 0, -1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 1, 2, 0, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, 2, -1, -1, -1, -1, -1 }, ++ { 1, 2, 0, -1, 3, -1, -1, -1, -1 }, ++ { 0, 1, -1, 2, 3, -1, -1, -1, -1 }, ++ { 1, 2, 0, -1, 3, 4, -1, -1, -1 }, ++ { 2, 3, -1, 0, 1, 4, 5, -1, -1 }, ++ { 1, 2, 0, -1, 3, 4, 5, -1, -1 }, ++ { 0, -1, 4, 5, 2, 3, 1, -1, -1 }, ++ { 3, 4, 1, -1, 0, 2, 5, 6, -1 }, ++ { 2, 3, -1, 5, 7, 0, 1, 4, 6 }, ++ { 3, 4, 1, -1, 0, 2, 5, 7, 6 }, ++}; ++ ++static const int8_t dca_channel_reorder_nolfe[][9] = { ++ { 0, -1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, -1, -1, -1, -1, -1, -1, -1 }, ++ { 1, 2, 0, -1, -1, -1, -1, -1, -1 }, ++ { 0, 1, 2, -1, -1, -1, -1, -1, -1 }, ++ { 1, 2, 0, 3, -1, -1, -1, -1, -1 }, ++ { 0, 1, 2, 3, -1, -1, -1, -1, -1 }, ++ { 1, 2, 0, 3, 4, -1, -1, -1, -1 }, ++ { 2, 3, 0, 1, 4, 5, -1, -1, -1 }, ++ { 1, 2, 0, 3, 4, 5, -1, -1, -1 }, ++ { 0, 4, 5, 2, 3, 1, -1, -1, -1 }, ++ { 3, 4, 1, 0, 2, 5, 6, -1, -1 }, ++ { 2, 3, 5, 7, 0, 1, 4, 6, -1 }, ++ { 3, 4, 1, 0, 2, 5, 7, 6, -1 }, ++}; ++ ++typedef struct { ++ PutBitContext pb; ++ int32_t history[MAX_CHANNELS][512]; /* This is a circular buffer */ ++ int start[MAX_CHANNELS]; ++ int frame_size; ++ int prim_channels; ++ int lfe_channel; ++ int sample_rate_code; ++ int scale_factor[MAX_CHANNELS][DCA_SUBBANDS_32]; ++ int lfe_scale_factor; ++ int lfe_data[SUBFRAMES*SUBSUBFRAMES*4]; ++ ++ int a_mode; ///< audio channels arrangement ++ int num_channel; ++ int lfe_state; ++ int lfe_offset; ++ const int8_t *channel_order_tab; ///< channel reordering table, lfe and non lfe ++ ++ int32_t pcm[FFMAX(LFE_INTERPOLATION, DCA_SUBBANDS_32)]; ++ int32_t subband[PCM_SAMPLES][MAX_CHANNELS][DCA_SUBBANDS_32]; /* [sample][channel][subband] */ ++} DCAContext; ++ ++static int32_t cos_table[128]; ++ ++static inline int32_t mul32(int32_t a, int32_t b) ++{ ++ int64_t r = (int64_t) a * b; ++ /* round the result before truncating - improves accuracy */ ++ return (r + 0x80000000) >> 32; ++} ++ ++/* Integer version of the cosine modulated Pseudo QMF */ ++ ++static void qmf_init(void) ++{ ++ int i; ++ int32_t c[17], s[17]; ++ s[0] = 0; /* sin(index * PI / 64) * 0x7fffffff */ ++ c[0] = 0x7fffffff; /* cos(index * PI / 64) * 0x7fffffff */ ++ ++ for (i = 1; i <= 16; i++) { ++ s[i] = 2 * (mul32(c[i - 1], 105372028) + mul32(s[i - 1], 2144896908)); ++ c[i] = 2 * (mul32(c[i - 1], 2144896908) - mul32(s[i - 1], 105372028)); ++ } ++ ++ for (i = 0; i < 16; i++) { ++ cos_table[i ] = c[i] >> 3; /* avoid output overflow */ ++ cos_table[i + 16] = s[16 - i] >> 3; ++ cos_table[i + 32] = -s[i] >> 3; ++ cos_table[i + 48] = -c[16 - i] >> 3; ++ cos_table[i + 64] = -c[i] >> 3; ++ cos_table[i + 80] = -s[16 - i] >> 3; ++ cos_table[i + 96] = s[i] >> 3; ++ cos_table[i + 112] = c[16 - i] >> 3; ++ } ++} ++ ++static int32_t band_delta_factor(int band, int sample_num) ++{ ++ int index = band * (2 * sample_num + 1); ++ if (band == 0) ++ return 0x07ffffff; ++ else ++ return cos_table[index & 127]; ++} ++ ++static void add_new_samples(DCAContext *c, const int32_t *in, ++ int count, int channel) ++{ ++ int i; ++ ++ /* Place new samples into the history buffer */ ++ for (i = 0; i < count; i++) { ++ c->history[channel][c->start[channel] + i] = in[i]; ++ av_assert0(c->start[channel] + i < 512); ++ } ++ c->start[channel] += count; ++ if (c->start[channel] == 512) ++ c->start[channel] = 0; ++ av_assert0(c->start[channel] < 512); ++} ++ ++static void qmf_decompose(DCAContext *c, int32_t in[32], int32_t out[32], ++ int channel) ++{ ++ int band, i, j, k; ++ int32_t resp; ++ int32_t accum[DCA_SUBBANDS_32] = {0}; ++ ++ add_new_samples(c, in, DCA_SUBBANDS_32, channel); ++ ++ /* Calculate the dot product of the signal with the (possibly inverted) ++ reference decoder's response to this vector: ++ (0.0, 0.0, ..., 0.0, -1.0, 1.0, 0.0, ..., 0.0) ++ so that -1.0 cancels 1.0 from the previous step */ ++ ++ for (k = 48, j = 0, i = c->start[channel]; i < 512; k++, j++, i++) ++ accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]); ++ for (i = 0; i < c->start[channel]; k++, j++, i++) ++ accum[(k & 32) ? (31 - (k & 31)) : (k & 31)] += mul32(c->history[channel][i], UnQMF[j]); ++ ++ resp = 0; ++ /* TODO: implement FFT instead of this naive calculation */ ++ for (band = 0; band < DCA_SUBBANDS_32; band++) { ++ for (j = 0; j < 32; j++) ++ resp += mul32(accum[j], band_delta_factor(band, j)); ++ ++ out[band] = (band & 2) ? (-resp) : resp; ++ } ++} ++ ++static int32_t lfe_fir_64i[512]; ++static int lfe_downsample(DCAContext *c, int32_t in[LFE_INTERPOLATION]) ++{ ++ int i, j; ++ int channel = c->prim_channels; ++ int32_t accum = 0; ++ ++ add_new_samples(c, in, LFE_INTERPOLATION, channel); ++ for (i = c->start[channel], j = 0; i < 512; i++, j++) ++ accum += mul32(c->history[channel][i], lfe_fir_64i[j]); ++ for (i = 0; i < c->start[channel]; i++, j++) ++ accum += mul32(c->history[channel][i], lfe_fir_64i[j]); ++ return accum; ++} ++ ++static void init_lfe_fir(void) ++{ ++ static int initialized = 0; ++ int i; ++ if (initialized) ++ return; ++ ++ for (i = 0; i < 512; i++) ++ lfe_fir_64i[i] = lfe_fir_64[i] * (1 << 25); //float -> int32_t ++ initialized = 1; ++} ++ ++static void put_frame_header(DCAContext *c) ++{ ++ /* SYNC */ ++ put_bits(&c->pb, 16, 0x7ffe); ++ put_bits(&c->pb, 16, 0x8001); ++ ++ /* Frame type: normal */ ++ put_bits(&c->pb, 1, 1); ++ ++ /* Deficit sample count: none */ ++ put_bits(&c->pb, 5, 31); ++ ++ /* CRC is not present */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Number of PCM sample blocks */ ++ put_bits(&c->pb, 7, PCM_SAMPLES-1); ++ ++ /* Primary frame byte size */ ++ put_bits(&c->pb, 14, c->frame_size-1); ++ ++ /* Audio channel arrangement: L + R (stereo) */ ++ put_bits(&c->pb, 6, c->num_channel); ++ ++ /* Core audio sampling frequency */ ++ put_bits(&c->pb, 4, c->sample_rate_code); ++ ++ /* Transmission bit rate: 1411.2 kbps */ ++ put_bits(&c->pb, 5, 0x16); /* FIXME: magic number */ ++ ++ /* Embedded down mix: disabled */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Embedded dynamic range flag: not present */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Embedded time stamp flag: not present */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Auxiliary data flag: not present */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* HDCD source: no */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Extension audio ID: N/A */ ++ put_bits(&c->pb, 3, 0); ++ ++ /* Extended audio data: not present */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Audio sync word insertion flag: after each sub-frame */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Low frequency effects flag: not present or interpolation factor=64 */ ++ put_bits(&c->pb, 2, c->lfe_state); ++ ++ /* Predictor history switch flag: on */ ++ put_bits(&c->pb, 1, 1); ++ ++ /* No CRC */ ++ /* Multirate interpolator switch: non-perfect reconstruction */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Encoder software revision: 7 */ ++ put_bits(&c->pb, 4, 7); ++ ++ /* Copy history: 0 */ ++ put_bits(&c->pb, 2, 0); ++ ++ /* Source PCM resolution: 16 bits, not DTS ES */ ++ put_bits(&c->pb, 3, 0); ++ ++ /* Front sum/difference coding: no */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Surrounds sum/difference coding: no */ ++ put_bits(&c->pb, 1, 0); ++ ++ /* Dialog normalization: 0 dB */ ++ put_bits(&c->pb, 4, 0); ++} ++ ++static void put_primary_audio_header(DCAContext *c) ++{ ++ static const int bitlen[11] = { 0, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3 }; ++ static const int thr[11] = { 0, 1, 3, 3, 3, 3, 7, 7, 7, 7, 7 }; ++ ++ int ch, i; ++ /* Number of subframes */ ++ put_bits(&c->pb, 4, SUBFRAMES - 1); ++ ++ /* Number of primary audio channels */ ++ put_bits(&c->pb, 3, c->prim_channels - 1); ++ ++ /* Subband activity count */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 5, DCA_SUBBANDS - 2); ++ ++ /* High frequency VQ start subband */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 5, DCA_SUBBANDS - 1); ++ ++ /* Joint intensity coding index: 0, 0 */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 3, 0); ++ ++ /* Transient mode codebook: A4, A4 (arbitrary) */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 2, 0); ++ ++ /* Scale factor code book: 7 bit linear, 7-bit sqrt table (for each channel) */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 3, 6); ++ ++ /* Bit allocation quantizer select: linear 5-bit */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, 3, 6); ++ ++ /* Quantization index codebook select: dummy data ++ to avoid transmission of scale factor adjustment */ ++ ++ for (i = 1; i < 11; i++) ++ for (ch = 0; ch < c->prim_channels; ch++) ++ put_bits(&c->pb, bitlen[i], thr[i]); ++ ++ /* Scale factor adjustment index: not transmitted */ ++} ++ ++/** ++ * 8-23 bits quantization ++ * @param sample ++ * @param bits ++ */ ++static inline uint32_t quantize(int32_t sample, int bits) ++{ ++ av_assert0(sample < 1 << (bits - 1)); ++ av_assert0(sample >= -(1 << (bits - 1))); ++ return sample & ((1 << bits) - 1); ++} ++ ++static inline int find_scale_factor7(int64_t max_value, int bits) ++{ ++ int i = 0, j = 128, q; ++ max_value = ((max_value << 15) / lossy_quant[bits + 3]) >> (bits - 1); ++ while (i < j) { ++ q = (i + j) >> 1; ++ if (max_value < scale_factor_quant7[q]) ++ j = q; ++ else ++ i = q + 1; ++ } ++ av_assert1(i < 128); ++ return i; ++} ++ ++static inline void put_sample7(DCAContext *c, int64_t sample, int bits, ++ int scale_factor) ++{ ++ sample = (sample << 15) / ((int64_t) lossy_quant[bits + 3] * scale_factor_quant7[scale_factor]); ++ put_bits(&c->pb, bits, quantize((int) sample, bits)); ++} ++ ++static void put_subframe(DCAContext *c, ++ int32_t subband_data[8 * SUBSUBFRAMES][MAX_CHANNELS][32], ++ int subframe) ++{ ++ int i, sub, ss, ch, max_value; ++ int32_t *lfe_data = c->lfe_data + 4 * SUBSUBFRAMES * subframe; ++ ++ /* Subsubframes count */ ++ put_bits(&c->pb, 2, SUBSUBFRAMES -1); ++ ++ /* Partial subsubframe sample count: dummy */ ++ put_bits(&c->pb, 3, 0); ++ ++ /* Prediction mode: no ADPCM, in each channel and subband */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) ++ put_bits(&c->pb, 1, 0); ++ ++ /* Prediction VQ addres: not transmitted */ ++ /* Bit allocation index */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) ++ put_bits(&c->pb, 5, QUANTIZER_BITS+3); ++ ++ if (SUBSUBFRAMES > 1) { ++ /* Transition mode: none for each channel and subband */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) ++ put_bits(&c->pb, 1, 0); /* codebook A4 */ ++ } ++ ++ /* Determine scale_factor */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) { ++ max_value = 0; ++ for (i = 0; i < 8 * SUBSUBFRAMES; i++) ++ max_value = FFMAX(max_value, FFABS(subband_data[i][ch][sub])); ++ c->scale_factor[ch][sub] = find_scale_factor7(max_value, QUANTIZER_BITS); ++ } ++ ++ if (c->lfe_channel) { ++ max_value = 0; ++ for (i = 0; i < 4 * SUBSUBFRAMES; i++) ++ max_value = FFMAX(max_value, FFABS(lfe_data[i])); ++ c->lfe_scale_factor = find_scale_factor7(max_value, LFE_BITS); ++ } ++ ++ /* Scale factors: the same for each channel and subband, ++ encoded according to Table D.1.2 */ ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) ++ put_bits(&c->pb, 7, c->scale_factor[ch][sub]); ++ ++ /* Joint subband scale factor codebook select: not transmitted */ ++ /* Scale factors for joint subband coding: not transmitted */ ++ /* Stereo down-mix coefficients: not transmitted */ ++ /* Dynamic range coefficient: not transmitted */ ++ /* Stde information CRC check word: not transmitted */ ++ /* VQ encoded high frequency subbands: not transmitted */ ++ ++ /* LFE data */ ++ if (c->lfe_channel) { ++ for (i = 0; i < 4 * SUBSUBFRAMES; i++) ++ put_sample7(c, lfe_data[i], LFE_BITS, c->lfe_scale_factor); ++ put_bits(&c->pb, 8, c->lfe_scale_factor); ++ } ++ ++ /* Audio data (subsubframes) */ ++ ++ for (ss = 0; ss < SUBSUBFRAMES ; ss++) ++ for (ch = 0; ch < c->prim_channels; ch++) ++ for (sub = 0; sub < DCA_SUBBANDS; sub++) ++ for (i = 0; i < 8; i++) ++ put_sample7(c, subband_data[ss * 8 + i][ch][sub], QUANTIZER_BITS, c->scale_factor[ch][sub]); ++ ++ /* DSYNC */ ++ put_bits(&c->pb, 16, 0xffff); ++} ++ ++static void put_frame(DCAContext *c, ++ int32_t subband_data[PCM_SAMPLES][MAX_CHANNELS][32], ++ uint8_t *frame) ++{ ++ int i; ++ init_put_bits(&c->pb, frame + DCA_HEADER_SIZE, DCA_MAX_FRAME_SIZE-DCA_HEADER_SIZE); ++ ++ put_primary_audio_header(c); ++ for (i = 0; i < SUBFRAMES; i++) ++ put_subframe(c, &subband_data[SUBSUBFRAMES * 8 * i], i); ++ ++ flush_put_bits(&c->pb); ++ c->frame_size = (put_bits_count(&c->pb) >> 3) + DCA_HEADER_SIZE; ++ ++ init_put_bits(&c->pb, frame, DCA_HEADER_SIZE); ++ put_frame_header(c); ++ flush_put_bits(&c->pb); ++} ++ ++static int encode_frame(AVCodecContext *avctx, uint8_t *frame, ++ int buf_size, void *data) ++{ ++ int i, k, channel; ++ DCAContext *c = avctx->priv_data; ++ int16_t *samples = data; ++ int real_channel = 0; ++ ++ for (i = 0; i < PCM_SAMPLES; i ++) { /* i is the decimated sample number */ ++ for (channel = 0; channel < c->prim_channels + 1; channel++) { ++ /* Get 32 PCM samples */ ++ for (k = 0; k < 32; k++) { /* k is the sample number in a 32-sample block */ ++ c->pcm[k] = samples[avctx->channels * (32 * i + k) + channel] << 16; ++ } ++ /* Put subband samples into the proper place */ ++ real_channel = c->channel_order_tab[channel]; ++ if (real_channel >= 0) { ++ qmf_decompose(c, c->pcm, &c->subband[i][real_channel][0], real_channel); ++ } ++ } ++ } ++ ++ if (c->lfe_channel) { ++ for (i = 0; i < PCM_SAMPLES / 2; i++) { ++ for (k = 0; k < LFE_INTERPOLATION; k++) /* k is the sample number in a 32-sample block */ ++ c->pcm[k] = samples[avctx->channels * (LFE_INTERPOLATION*i+k) + c->lfe_offset] << 16; ++ c->lfe_data[i] = lfe_downsample(c, c->pcm); ++ } ++ } ++ ++ put_frame(c, c->subband, frame); ++ ++ return c->frame_size; ++} ++ ++static int encode_init(AVCodecContext *avctx) ++{ ++ DCAContext *c = avctx->priv_data; ++ int i; ++ ++ c->prim_channels = avctx->channels; ++ c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6); ++ ++ switch (avctx->channel_layout) { ++ case AV_CH_LAYOUT_STEREO: c->a_mode = 2; c->num_channel = 2; break; ++ case AV_CH_LAYOUT_5POINT0: c->a_mode = 9; c->num_channel = 9; break; ++ case AV_CH_LAYOUT_5POINT1: c->a_mode = 9; c->num_channel = 9; break; ++ case AV_CH_LAYOUT_5POINT0_BACK: c->a_mode = 9; c->num_channel = 9; break; ++ case AV_CH_LAYOUT_5POINT1_BACK: c->a_mode = 9; c->num_channel = 9; break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, ++ "Only stereo, 5.0, 5.1 channel layouts supported at the moment!\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ if (c->lfe_channel) { ++ init_lfe_fir(); ++ c->prim_channels--; ++ c->channel_order_tab = dca_channel_reorder_lfe[c->a_mode]; ++ c->lfe_state = LFE_PRESENT; ++ c->lfe_offset = dca_lfe_index[c->a_mode]; ++ } else { ++ c->channel_order_tab = dca_channel_reorder_nolfe[c->a_mode]; ++ c->lfe_state = LFE_MISSING; ++ } ++ ++ for (i = 0; i < 16; i++) { ++ if (dca_sample_rates[i] && (dca_sample_rates[i] == avctx->sample_rate)) ++ break; ++ } ++ if (i == 16) { ++ av_log(avctx, AV_LOG_ERROR, "Sample rate %iHz not supported, only ", avctx->sample_rate); ++ for (i = 0; i < 16; i++) ++ av_log(avctx, AV_LOG_ERROR, "%d, ", dca_sample_rates[i]); ++ av_log(avctx, AV_LOG_ERROR, "supported.\n"); ++ return -1; ++ } ++ c->sample_rate_code = i; ++ ++ avctx->frame_size = 32 * PCM_SAMPLES; ++ ++ if (!cos_table[127]) ++ qmf_init(); ++ return 0; ++} ++ ++AVCodec ff_dca_encoder = { ++ .name = "dca", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_DTS, ++ .priv_data_size = sizeof(DCAContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .capabilities = CODEC_CAP_EXPERIMENTAL, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("DCA (DTS Coherent Acoustics)"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcaenc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcaenc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dcaenc.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dcaenc.h 2012-05-14 14:08:53.587324948 +0200 +@@ -0,0 +1,544 @@ ++/* ++ * DCA encoder tables ++ * Copyright (C) 2008 Alexander E. Patrakov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_DCAENC_H ++#define AVCODEC_DCAENC_H ++ ++/* This is a scaled version of the response of the reference decoder to ++ this vector of subband samples: ( 1.0 0.0 0.0 ... 0.0 ) ++ */ ++ ++static const int32_t UnQMF[512] = { ++ 7, ++ 4, ++ -961, ++ -2844, ++ -8024, ++ -18978, ++ -32081, ++ -15635, ++ -16582, ++ -18359, ++ -17180, ++ -14868, ++ -11664, ++ -8051, ++ -4477, ++ -1327, ++ -1670, ++ -6019, ++ -11590, ++ -18030, ++ -24762, ++ -30965, ++ -35947, ++ -36145, ++ -37223, ++ -86311, ++ -57024, ++ -27215, ++ -11274, ++ -4684, ++ 42, ++ 108, ++ 188, ++ 250, ++ -1007, ++ -596, ++ -2289, ++ -12218, ++ -27191, ++ -124367, ++ -184256, ++ -250538, ++ -323499, ++ -397784, ++ -468855, ++ -532072, ++ -583000, ++ -618041, ++ -777916, ++ -783868, ++ -765968, ++ -724740, ++ -662468, ++ -583058, ++ -490548, ++ -401623, ++ -296090, ++ -73154, ++ -36711, ++ -7766, ++ -2363, ++ -4905, ++ 2388, ++ 2681, ++ 5651, ++ 4086, ++ 71110, ++ 139742, ++ 188067, ++ 151237, ++ 101355, ++ 309917, ++ 343690, ++ 358839, ++ 357555, ++ 334606, ++ 289625, ++ 224152, ++ 142063, ++ 48725, ++ 74996, ++ 238425, ++ 411666, ++ 584160, ++ 744276, ++ 880730, ++ 983272, ++ 1041933, ++ 1054396, ++ 789531, ++ 851022, ++ 864032, ++ 675431, ++ 418134, ++ 35762, ++ 66911, ++ 103502, ++ 136403, ++ -55147, ++ -245269, ++ -499595, ++ -808470, ++ -1136858, ++ -2010912, ++ -2581654, ++ -3151901, ++ -3696328, ++ -4196599, ++ -4633761, ++ -4993229, ++ -5262495, ++ -5436311, ++ -477650, ++ -901314, ++ -1308090, ++ -1677468, ++ -1985525, ++ -2212848, ++ -2341196, ++ -2373915, ++ -2269552, ++ -2620489, ++ -2173858, ++ -1629954, ++ -946595, ++ -193499, ++ 1119459, ++ 1138657, ++ 1335311, ++ 1126544, ++ 2765033, ++ 3139603, ++ 3414913, ++ 3599213, ++ 3676363, ++ 3448981, ++ 3328726, ++ 3111551, ++ 2810887, ++ 2428657, ++ 1973684, ++ 1457278, ++ 893848, ++ 300995, ++ -292521, ++ -867621, ++ -1404936, ++ -1871278, ++ -2229831, ++ -2440932, ++ -2462684, ++ -2255006, ++ -1768898, ++ -1079574, ++ 82115, ++ 1660302, ++ 3660715, ++ 6123610, ++ 8329598, ++ 11888744, ++ 15722147, ++ 19737089, ++ 25647773, ++ 31039399, ++ 36868007, ++ 43124253, ++ 49737161, ++ 56495958, ++ 63668945, ++ 71039511, ++ 78540240, ++ 86089058, ++ 93600041, ++ 100981151, ++ 108136061, ++ 114970055, ++ 121718321, ++ 127566038, ++ 132774642, ++ 137247294, ++ 140894737, ++ 143635018, ++ 145395599, ++ 146114032, ++ 145742999, ++ 144211606, ++ 141594341, ++ 137808404, ++ 132914122, ++ 126912246, ++ 120243281, ++ 112155281, ++ 103338368, ++ 93904953, ++ 83439152, ++ 72921548, ++ 62192990, ++ 51434918, ++ 40894003, ++ 30786726, ++ 21384955, ++ 12939112, ++ 5718193, ++ -5790, ++ -3959261, ++ -5870978, ++ -5475538, ++ -2517061, ++ 3247310, ++ 12042937, ++ 24076729, ++ 39531397, ++ 58562863, ++ 81297002, ++ 107826748, ++ 138209187, ++ 172464115, ++ 210569037, ++ 252468018, ++ 298045453, ++ 347168648, ++ 399634888, ++ 455137189, ++ 513586535, ++ 574537650, ++ 637645129, ++ 702597163, ++ 768856566, ++ 836022040, ++ 903618096, ++ 971159680, ++ 1038137214, ++ 1103987353, ++ 1168195035, ++ 1230223053, ++ 1289539180, ++ 1345620373, ++ 1397957958, ++ 1446063657, ++ 1489474689, ++ 1527740502, ++ 1560502307, ++ 1587383079, ++ 1608071145, ++ 1622301248, ++ 1629859340, ++ 1630584888, ++ 1624373875, ++ 1611178348, ++ 1591018893, ++ 1563948667, ++ 1530105004, ++ 1489673227, ++ 1442904075, ++ 1390107674, ++ 1331590427, ++ 1267779478, ++ 1199115126, ++ 1126053392, ++ 1049146257, ++ 968928307, ++ 885965976, ++ 800851610, ++ 714186243, ++ 626590147, ++ 538672486, ++ 451042824, ++ 364299927, ++ 279026812, ++ 195785029, ++ 115109565, ++ 37503924, ++ -36564551, ++ -106668063, ++ -172421668, ++ -233487283, ++ -289575706, ++ -340448569, ++ -385919511, ++ -425854915, ++ -460174578, ++ -488840702, ++ -511893328, ++ -529405118, ++ -541489888, ++ -548312207, ++ -550036471, ++ -547005316, ++ -539436808, ++ -527630488, ++ -512084785, ++ -492941605, ++ -470665204, ++ -445668379, ++ -418328829, ++ -389072810, ++ -358293846, ++ -326396227, ++ -293769619, ++ -260792276, ++ -227825056, ++ -195208961, ++ -163262121, ++ -132280748, ++ -102533727, ++ -74230062, ++ -47600637, ++ -22817785, ++ -25786, ++ 20662895, ++ 39167253, ++ 55438413, ++ 69453741, ++ 81242430, ++ 90795329, ++ 98213465, ++ 103540643, ++ 106917392, ++ 108861938, ++ 108539682, ++ 106780704, ++ 103722568, ++ 99043289, ++ 93608686, ++ 87266209, ++ 80212203, ++ 72590022, ++ 64603428, ++ 56362402, ++ 48032218, ++ 39749162, ++ 31638971, ++ 23814664, ++ 16376190, ++ 9409836, ++ 2988017, ++ -2822356, ++ -7976595, ++ -12454837, ++ -16241147, ++ -19331944, ++ -21735011, ++ -23468284, ++ -24559822, ++ -25042936, ++ -25035583, ++ -24429587, ++ -23346408, ++ -21860411, ++ -20015718, ++ -17025330, ++ -14968728, ++ -12487138, ++ -9656319, ++ -7846681, ++ -5197816, ++ -2621904, ++ -144953, ++ 2144746, ++ 3990570, ++ 5845884, ++ 7454650, ++ 8820394, ++ 9929891, ++ 10784445, ++ 11390921, ++ 11762056, ++ 11916017, ++ 12261189, ++ 12117604, ++ 11815303, ++ 11374622, ++ 10815301, ++ 10157241, ++ 9418799, ++ 8629399, ++ 7780776, ++ 7303680, ++ 6353499, ++ 5392738, ++ 4457895, ++ 3543062, ++ 1305978, ++ 1402521, ++ 1084092, ++ 965652, ++ -151008, ++ -666667, ++ -1032157, ++ -1231475, ++ -1319043, ++ -1006023, ++ -915720, ++ -773426, ++ -612377, ++ -445864, ++ -291068, ++ -161337, ++ -66484, ++ -11725, ++ 133453, ++ 388184, ++ 615856, ++ 804033, ++ 942377, ++ 1022911, ++ 1041247, ++ 995854, ++ 891376, ++ 572246, ++ 457992, ++ 316365, ++ 172738, ++ 43037, ++ -117662, ++ -98542, ++ -70279, ++ -41458, ++ -535790, ++ -959038, ++ -1364456, ++ -1502265, ++ -1568530, ++ -2378681, ++ -2701111, ++ -2976407, ++ -3182552, ++ -3314415, ++ -3366600, ++ -3337701, ++ -3232252, ++ -3054999, ++ 1984841, ++ 1925903, ++ 1817377, ++ 1669153, ++ 1490069, ++ 1292040, ++ 1086223, ++ 890983, ++ 699163, ++ 201358, ++ 266971, ++ 296990, ++ 198419, ++ 91119, ++ 4737, ++ 5936, ++ 2553, ++ 2060, ++ -3828, ++ -1664, ++ -4917, ++ -20796, ++ -36822, ++ -131247, ++ -154923, ++ -162055, ++ -161354, ++ -148762, ++ -125754, ++ -94473, ++ -57821, ++ -19096, ++ 15172, ++ 43004, ++ 65624, ++ 81354, ++ 89325, ++ 89524, ++ 82766, ++ 71075, ++ 55128, ++ 13686, ++ 6921, ++ 1449, ++ 420, ++ 785, ++ -215, ++ -179, ++ -113, ++ -49, ++ 6002, ++ 16007, ++ 42978, ++ 100662, ++ 171472, ++ 83975, ++ 93702, ++ 108813, ++ 111893, ++ 110272, ++ 103914, ++ 93973, ++ 81606, ++ 68041, ++ -54058, ++ -60695, ++ -65277, ++ -67224, ++ -66213, ++ -62082, ++ -55574, ++ -42988, ++ -35272, ++ -63735, ++ -33501, ++ -12671, ++ -4038, ++ -1232, ++ 5, ++ 7 ++}; ++ ++#endif /* AVCODEC_DCAENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dca_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dca_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dca_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dca_parser.c 2012-05-14 14:08:53.578324766 +0200 +@@ -36,10 +36,10 @@ + #define IS_MARKER(state, i, buf, buf_size) \ + ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ + || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ +- || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) ++ || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE || state == DCA_HD_MARKER) + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ + static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, +@@ -57,10 +57,7 @@ + for (i = 0; i < buf_size; i++) { + state = (state << 8) | buf[i]; + if (IS_MARKER(state, i, buf, buf_size)) { +- if (pc1->lastmarker && state == pc1->lastmarker) { +- start_found = 1; +- break; +- } else if (!pc1->lastmarker) { ++ if (!pc1->lastmarker || state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER) { + start_found = 1; + pc1->lastmarker = state; + break; +@@ -74,10 +71,11 @@ + state = (state << 8) | buf[i]; + if (state == DCA_HD_MARKER && !pc1->hd_pos) + pc1->hd_pos = pc1->size; +- if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { ++ if (IS_MARKER(state, i, buf, buf_size) && (state == pc1->lastmarker || pc1->lastmarker == DCA_HD_MARKER)) { + if(pc1->framesize > pc1->size) + continue; +- if(!pc1->framesize){ ++ // We have to check that we really read a full frame here, and that it isn't a pure HD frame, because their size is not constant. ++ if(!pc1->framesize && state == pc1->lastmarker && state != DCA_HD_MARKER){ + pc1->framesize = pc1->hd_pos ? pc1->hd_pos : pc1->size; + } + pc->frame_start_found = 0; +@@ -126,9 +124,9 @@ + } + + AVCodecParser ff_dca_parser = { +- {CODEC_ID_DTS}, +- sizeof(DCAParseContext), +- dca_parse_init, +- dca_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_DTS }, ++ .priv_data_size = sizeof(DCAParseContext), ++ .parser_init = dca_parse_init, ++ .parser_parse = dca_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32.c 2012-05-14 14:08:53.592325048 +0200 +@@ -19,10 +19,19 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifdef DCT32_FLOAT ++#include "dct32.h" ++#include "mathops.h" ++ ++#if DCT32_FLOAT ++# define dct32 ff_dct32_float + # define FIXHR(x) ((float)(x)) + # define MULH3(x, y, s) ((s)*(y)*(x)) + # define INTFLOAT float ++#else ++# define dct32 ff_dct32_fixed ++# define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5)) ++# define MULH3(x, y, s) MULH((s)*(x), y) ++# define INTFLOAT int + #endif + + +@@ -103,7 +112,7 @@ + #define ADD(a, b) val##a += val##b + + /* DCT32 without 1/sqrt(2) coef zero scaling. */ +-static void dct32(INTFLOAT *out, const INTFLOAT *tab) ++void dct32(INTFLOAT *out, const INTFLOAT *tab) + { + INTFLOAT tmp0, tmp1; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32_fixed.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32_fixed.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32_fixed.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32_fixed.c 2012-05-14 14:08:53.593325068 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define DCT32_FLOAT 0 ++#include "dct32.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32_float.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32_float.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32_float.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32_float.c 2012-05-14 14:08:53.593325068 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define DCT32_FLOAT 1 ++#include "dct32.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct32.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct32.h 2012-05-14 14:08:53.592325048 +0200 +@@ -0,0 +1,25 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_DCT32_H ++#define AVCODEC_DCT32_H ++ ++void ff_dct32_float(float *dst, const float *src); ++void ff_dct32_fixed(int *dst, const int *src); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct.c 2012-05-14 14:08:53.591325028 +0200 +@@ -28,18 +28,16 @@ + */ + + #include +-#include "libavutil/mathematics.h" +-#include "fft.h" +-#include "x86/fft.h" + +-#define DCT32_FLOAT +-#include "dct32.c" ++#include "libavutil/mathematics.h" ++#include "dct.h" ++#include "dct32.h" + +-/* sin((M_PI * x / (2*n)) */ +-#define SIN(s,n,x) (s->costab[(n) - (x)]) ++/* sin((M_PI * x / (2 * n)) */ ++#define SIN(s, n, x) (s->costab[(n) - (x)]) + +-/* cos((M_PI * x / (2*n)) */ +-#define COS(s,n,x) (s->costab[x]) ++/* cos((M_PI * x / (2 * n)) */ ++#define COS(s, n, x) (s->costab[x]) + + static void ff_dst_calc_I_c(DCTContext *ctx, FFTSample *data) + { +@@ -47,28 +45,28 @@ + int i; + + data[0] = 0; +- for(i = 1; i < n/2; i++) { +- float tmp1 = data[i ]; +- float tmp2 = data[n - i]; +- float s = SIN(ctx, n, 2*i); +- +- s *= tmp1 + tmp2; +- tmp1 = (tmp1 - tmp2) * 0.5f; +- data[i ] = s + tmp1; +- data[n - i] = s - tmp1; ++ for (i = 1; i < n / 2; i++) { ++ float tmp1 = data[i ]; ++ float tmp2 = data[n - i]; ++ float s = SIN(ctx, n, 2 * i); ++ ++ s *= tmp1 + tmp2; ++ tmp1 = (tmp1 - tmp2) * 0.5f; ++ data[i] = s + tmp1; ++ data[n - i] = s - tmp1; + } + +- data[n/2] *= 2; +- ff_rdft_calc(&ctx->rdft, data); ++ data[n / 2] *= 2; ++ ctx->rdft.rdft_calc(&ctx->rdft, data); + + data[0] *= 0.5f; + +- for(i = 1; i < n-2; i += 2) { +- data[i + 1] += data[i - 1]; +- data[i ] = -data[i + 2]; ++ for (i = 1; i < n - 2; i += 2) { ++ data[i + 1] += data[i - 1]; ++ data[i] = -data[i + 2]; + } + +- data[n-1] = 0; ++ data[n - 1] = 0; + } + + static void ff_dct_calc_I_c(DCTContext *ctx, FFTSample *data) +@@ -77,27 +75,27 @@ + int i; + float next = -0.5f * (data[0] - data[n]); + +- for(i = 0; i < n/2; i++) { +- float tmp1 = data[i ]; ++ for (i = 0; i < n / 2; i++) { ++ float tmp1 = data[i]; + float tmp2 = data[n - i]; +- float s = SIN(ctx, n, 2*i); +- float c = COS(ctx, n, 2*i); ++ float s = SIN(ctx, n, 2 * i); ++ float c = COS(ctx, n, 2 * i); + + c *= tmp1 - tmp2; + s *= tmp1 - tmp2; + + next += c; + +- tmp1 = (tmp1 + tmp2) * 0.5f; +- data[i ] = tmp1 - s; ++ tmp1 = (tmp1 + tmp2) * 0.5f; ++ data[i] = tmp1 - s; + data[n - i] = tmp1 + s; + } + +- ff_rdft_calc(&ctx->rdft, data); ++ ctx->rdft.rdft_calc(&ctx->rdft, data); + data[n] = data[1]; + data[1] = next; + +- for(i = 3; i <= n; i += 2) ++ for (i = 3; i <= n; i += 2) + data[i] = data[i - 2] - data[i]; + } + +@@ -106,31 +104,31 @@ + int n = 1 << ctx->nbits; + int i; + +- float next = data[n - 1]; ++ float next = data[n - 1]; + float inv_n = 1.0f / n; + + for (i = n - 2; i >= 2; i -= 2) { +- float val1 = data[i ]; ++ float val1 = data[i]; + float val2 = data[i - 1] - data[i + 1]; +- float c = COS(ctx, n, i); +- float s = SIN(ctx, n, i); ++ float c = COS(ctx, n, i); ++ float s = SIN(ctx, n, i); + +- data[i ] = c * val1 + s * val2; ++ data[i] = c * val1 + s * val2; + data[i + 1] = s * val1 - c * val2; + } + + data[1] = 2 * next; + +- ff_rdft_calc(&ctx->rdft, data); ++ ctx->rdft.rdft_calc(&ctx->rdft, data); + + for (i = 0; i < n / 2; i++) { +- float tmp1 = data[i ] * inv_n; ++ float tmp1 = data[i] * inv_n; + float tmp2 = data[n - i - 1] * inv_n; +- float csc = ctx->csc2[i] * (tmp1 - tmp2); ++ float csc = ctx->csc2[i] * (tmp1 - tmp2); + +- tmp1 += tmp2; +- data[i ] = tmp1 + csc; +- data[n - i - 1] = tmp1 - csc; ++ tmp1 += tmp2; ++ data[i] = tmp1 + csc; ++ data[n - i - 1] = tmp1 - csc; + } + } + +@@ -140,34 +138,33 @@ + int i; + float next; + +- for (i=0; i < n/2; i++) { +- float tmp1 = data[i ]; ++ for (i = 0; i < n / 2; i++) { ++ float tmp1 = data[i]; + float tmp2 = data[n - i - 1]; +- float s = SIN(ctx, n, 2*i + 1); ++ float s = SIN(ctx, n, 2 * i + 1); + +- s *= tmp1 - tmp2; +- tmp1 = (tmp1 + tmp2) * 0.5f; ++ s *= tmp1 - tmp2; ++ tmp1 = (tmp1 + tmp2) * 0.5f; + +- data[i ] = tmp1 + s; ++ data[i] = tmp1 + s; + data[n-i-1] = tmp1 - s; + } + +- ff_rdft_calc(&ctx->rdft, data); ++ ctx->rdft.rdft_calc(&ctx->rdft, data); + +- next = data[1] * 0.5; ++ next = data[1] * 0.5; + data[1] *= -1; + + for (i = n - 2; i >= 0; i -= 2) { + float inr = data[i ]; + float ini = data[i + 1]; +- float c = COS(ctx, n, i); +- float s = SIN(ctx, n, i); +- +- data[i ] = c * inr + s * ini; ++ float c = COS(ctx, n, i); ++ float s = SIN(ctx, n, i); + +- data[i+1] = next; ++ data[i] = c * inr + s * ini; ++ data[i + 1] = next; + +- next += s * inr - c * ini; ++ next += s * inr - c * ini; + } + } + +@@ -176,45 +173,43 @@ + ctx->dct32(data, data); + } + +-void ff_dct_calc(DCTContext *s, FFTSample *data) +-{ +- s->dct_calc(s, data); +-} +- + av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse) + { + int n = 1 << nbits; + int i; + +- s->nbits = nbits; +- s->inverse = inverse; +- +- ff_init_ff_cos_tabs(nbits+2); +- +- s->costab = ff_cos_tabs[nbits+2]; ++ memset(s, 0, sizeof(*s)); + +- s->csc2 = av_malloc(n/2 * sizeof(FFTSample)); +- +- if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { +- av_free(s->csc2); +- return -1; +- } ++ s->nbits = nbits; ++ s->inverse = inverse; + +- for (i = 0; i < n/2; i++) +- s->csc2[i] = 0.5 / sin((M_PI / (2*n) * (2*i + 1))); +- +- switch(inverse) { +- case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; +- case DCT_II : s->dct_calc = ff_dct_calc_II_c ; break; +- case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; +- case DST_I : s->dct_calc = ff_dst_calc_I_c; break; +- } +- +- if (inverse == DCT_II && nbits == 5) ++ if (inverse == DCT_II && nbits == 5) { + s->dct_calc = dct32_func; ++ } else { ++ ff_init_ff_cos_tabs(nbits + 2); ++ ++ s->costab = ff_cos_tabs[nbits + 2]; ++ s->csc2 = av_malloc(n / 2 * sizeof(FFTSample)); + +- s->dct32 = dct32; +- if (HAVE_MMX) ff_dct_init_mmx(s); ++ if (ff_rdft_init(&s->rdft, nbits, inverse == DCT_III) < 0) { ++ av_free(s->csc2); ++ return -1; ++ } ++ ++ for (i = 0; i < n / 2; i++) ++ s->csc2[i] = 0.5 / sin((M_PI / (2 * n) * (2 * i + 1))); ++ ++ switch (inverse) { ++ case DCT_I : s->dct_calc = ff_dct_calc_I_c; break; ++ case DCT_II : s->dct_calc = ff_dct_calc_II_c; break; ++ case DCT_III: s->dct_calc = ff_dct_calc_III_c; break; ++ case DST_I : s->dct_calc = ff_dst_calc_I_c; break; ++ } ++ } ++ ++ s->dct32 = ff_dct32_float; ++ if (HAVE_MMX) ++ ff_dct_init_mmx(s); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct.h 2012-05-14 14:08:53.591325028 +0200 +@@ -0,0 +1,52 @@ ++/* ++ * (I)DCT Transforms ++ * Copyright (c) 2009 Peter Ross ++ * Copyright (c) 2010 Alex Converse ++ * Copyright (c) 2010 Vitor Sessak ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_DCT_H ++#define AVCODEC_DCT_H ++ ++#include "rdft.h" ++ ++struct DCTContext { ++ int nbits; ++ int inverse; ++ RDFTContext rdft; ++ const float *costab; ++ FFTSample *csc2; ++ void (*dct_calc)(struct DCTContext *s, FFTSample *data); ++ void (*dct32)(FFTSample *out, const FFTSample *in); ++}; ++ ++/** ++ * Set up DCT. ++ * @param nbits size of the input array: ++ * (1 << nbits) for DCT-II, DCT-III and DST-I ++ * (1 << nbits) + 1 for DCT-I ++ * ++ * @note the first element of the input of DST-I is ignored ++ */ ++int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type); ++void ff_dct_end (DCTContext *s); ++ ++void ff_dct_init_mmx(DCTContext *s); ++ ++#endif /* AVCODEC_DCT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dctref.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dctref.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dctref.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dctref.h 2012-05-14 14:08:53.594325088 +0200 +@@ -22,10 +22,8 @@ + #ifndef AVCODEC_DCTREF_H + #define AVCODEC_DCTREF_H + +-#include "dsputil.h" +- +-void ff_ref_fdct(DCTELEM *block); +-void ff_ref_idct(DCTELEM *block); ++void ff_ref_fdct(short *block); ++void ff_ref_idct(short *block); + void ff_ref_dct_init(void); + +-#endif ++#endif /* AVCODEC_DCTREF_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dct-test.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dct-test.c 2012-05-14 14:08:53.590325008 +0200 +@@ -68,12 +68,12 @@ + void ff_simple_idct_axp(DCTELEM *data); + + struct algo { +- const char *name; +- enum { FDCT, IDCT } is_idct; +- void (* func) (DCTELEM *block); +- void (* ref) (DCTELEM *block); +- enum formattag { NO_PERM,MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM, SSE2_PERM, PARTTRANS_PERM } format; +- int mm_support; ++ const char *name; ++ void (*func)(DCTELEM *block); ++ enum formattag { NO_PERM, MMX_PERM, MMX_SIMPLE_PERM, SCALE_PERM, ++ SSE2_PERM, PARTTRANS_PERM, TRANSPOSE_PERM } format; ++ int mm_support; ++ int nonspec; + }; + + #ifndef FAAN_POSTSCALE +@@ -84,71 +84,96 @@ + + static int cpu_flags; + +-struct algo algos[] = { +- {"REF-DBL", 0, ff_ref_fdct, ff_ref_fdct, NO_PERM}, +- {"FAAN", 0, ff_faandct, ff_ref_fdct, FAAN_SCALE}, +- {"FAANI", 1, ff_faanidct, ff_ref_idct, NO_PERM}, +- {"IJG-AAN-INT", 0, fdct_ifast, ff_ref_fdct, SCALE_PERM}, +- {"IJG-LLM-INT", 0, ff_jpeg_fdct_islow, ff_ref_fdct, NO_PERM}, +- {"REF-DBL", 1, ff_ref_idct, ff_ref_idct, NO_PERM}, +- {"INT", 1, j_rev_dct, ff_ref_idct, MMX_PERM}, +- {"SIMPLE-C", 1, ff_simple_idct, ff_ref_idct, NO_PERM}, ++static const struct algo fdct_tab[] = { ++ { "REF-DBL", ff_ref_fdct, NO_PERM }, ++ { "FAAN", ff_faandct, FAAN_SCALE }, ++ { "IJG-AAN-INT", fdct_ifast, SCALE_PERM }, ++ { "IJG-LLM-INT", ff_jpeg_fdct_islow_8, NO_PERM }, + + #if HAVE_MMX +- {"MMX", 0, ff_fdct_mmx, ff_ref_fdct, NO_PERM, AV_CPU_FLAG_MMX}, +-#if HAVE_MMX2 +- {"MMX2", 0, ff_fdct_mmx2, ff_ref_fdct, NO_PERM, AV_CPU_FLAG_MMX2}, +- {"SSE2", 0, ff_fdct_sse2, ff_ref_fdct, NO_PERM, AV_CPU_FLAG_SSE2}, ++ { "MMX", ff_fdct_mmx, NO_PERM, AV_CPU_FLAG_MMX }, ++ { "MMX2", ff_fdct_mmx2, NO_PERM, AV_CPU_FLAG_MMX2 }, ++ { "SSE2", ff_fdct_sse2, NO_PERM, AV_CPU_FLAG_SSE2 }, + #endif + +-#if CONFIG_GPL +- {"LIBMPEG2-MMX", 1, ff_mmx_idct, ff_ref_idct, MMX_PERM, AV_CPU_FLAG_MMX}, +- {"LIBMPEG2-MMX2", 1, ff_mmxext_idct, ff_ref_idct, MMX_PERM, AV_CPU_FLAG_MMX2}, ++#if HAVE_ALTIVEC ++ { "altivecfdct", fdct_altivec, NO_PERM, AV_CPU_FLAG_ALTIVEC }, + #endif +- {"SIMPLE-MMX", 1, ff_simple_idct_mmx, ff_ref_idct, MMX_SIMPLE_PERM, AV_CPU_FLAG_MMX}, +- {"XVID-MMX", 1, ff_idct_xvid_mmx, ff_ref_idct, NO_PERM, AV_CPU_FLAG_MMX}, +- {"XVID-MMX2", 1, ff_idct_xvid_mmx2, ff_ref_idct, NO_PERM, AV_CPU_FLAG_MMX2}, +- {"XVID-SSE2", 1, ff_idct_xvid_sse2, ff_ref_idct, SSE2_PERM, AV_CPU_FLAG_SSE2}, ++ ++#if ARCH_BFIN ++ { "BFINfdct", ff_bfin_fdct, NO_PERM }, + #endif + +-#if HAVE_ALTIVEC +- {"altivecfdct", 0, fdct_altivec, ff_ref_fdct, NO_PERM, AV_CPU_FLAG_ALTIVEC}, ++ { 0 } ++}; ++ ++#if HAVE_MMX ++void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize, ++ DCTELEM *block, int16_t *qmat); ++ ++static void ff_prores_idct_put_10_sse2_wrap(uint16_t *dst){ ++ int16_t qmat[64]; int i; ++ int16_t tmp[64]; ++ ++ for(i=0; i<64; i++){ ++ qmat[i]=4; ++ tmp[i]= dst[i]; ++ } ++ ff_prores_idct_put_10_sse2(dst, 16, tmp, qmat); ++} ++#endif ++ ++static const struct algo idct_tab[] = { ++ { "FAANI", ff_faanidct, NO_PERM }, ++ { "REF-DBL", ff_ref_idct, NO_PERM }, ++ { "INT", j_rev_dct, MMX_PERM }, ++ { "SIMPLE-C", ff_simple_idct_8, NO_PERM }, ++ ++#if HAVE_MMX ++#if CONFIG_GPL ++ { "LIBMPEG2-MMX", ff_mmx_idct, MMX_PERM, AV_CPU_FLAG_MMX, 1 }, ++ { "LIBMPEG2-MMX2", ff_mmxext_idct, MMX_PERM, AV_CPU_FLAG_MMX2, 1 }, ++#endif ++ { "SIMPLE-MMX", ff_simple_idct_mmx, MMX_SIMPLE_PERM, AV_CPU_FLAG_MMX }, ++ { "XVID-MMX", ff_idct_xvid_mmx, NO_PERM, AV_CPU_FLAG_MMX, 1 }, ++ { "XVID-MMX2", ff_idct_xvid_mmx2, NO_PERM, AV_CPU_FLAG_MMX2, 1 }, ++ { "XVID-SSE2", ff_idct_xvid_sse2, SSE2_PERM, AV_CPU_FLAG_SSE2, 1 }, ++#if ARCH_X86_64 ++ { "PR-SSE2", ff_prores_idct_put_10_sse2_wrap, TRANSPOSE_PERM, AV_CPU_FLAG_SSE2, 1 }, ++#endif + #endif + + #if ARCH_BFIN +- {"BFINfdct", 0, ff_bfin_fdct, ff_ref_fdct, NO_PERM}, +- {"BFINidct", 1, ff_bfin_idct, ff_ref_idct, NO_PERM}, ++ { "BFINidct", ff_bfin_idct, NO_PERM }, + #endif + + #if ARCH_ARM +- {"SIMPLE-ARM", 1, ff_simple_idct_arm, ff_ref_idct, NO_PERM }, +- {"INT-ARM", 1, ff_j_rev_dct_arm, ff_ref_idct, MMX_PERM }, ++ { "SIMPLE-ARM", ff_simple_idct_arm, NO_PERM }, ++ { "INT-ARM", ff_j_rev_dct_arm, MMX_PERM }, ++#endif + #if HAVE_ARMV5TE +- {"SIMPLE-ARMV5TE", 1, ff_simple_idct_armv5te, ff_ref_idct, NO_PERM }, ++ { "SIMPLE-ARMV5TE", ff_simple_idct_armv5te,NO_PERM }, + #endif + #if HAVE_ARMV6 +- {"SIMPLE-ARMV6", 1, ff_simple_idct_armv6, ff_ref_idct, MMX_PERM }, ++ { "SIMPLE-ARMV6", ff_simple_idct_armv6, MMX_PERM }, + #endif + #if HAVE_NEON +- {"SIMPLE-NEON", 1, ff_simple_idct_neon, ff_ref_idct, PARTTRANS_PERM }, ++ { "SIMPLE-NEON", ff_simple_idct_neon, PARTTRANS_PERM }, + #endif +-#endif /* ARCH_ARM */ + + #if ARCH_ALPHA +- {"SIMPLE-ALPHA", 1, ff_simple_idct_axp, ff_ref_idct, NO_PERM }, ++ { "SIMPLE-ALPHA", ff_simple_idct_axp, NO_PERM }, + #endif + +- { 0 } ++ { 0 } + }; + + #define AANSCALE_BITS 12 + +-uint8_t cropTbl[256 + 2 * MAX_NEG_CROP]; +- + static int64_t gettime(void) + { + struct timeval tv; +- gettimeofday(&tv,NULL); ++ gettimeofday(&tv, NULL); + return (int64_t)tv.tv_sec * 1000000 + tv.tv_usec; + } + +@@ -157,18 +182,18 @@ + + static short idct_mmx_perm[64]; + +-static short idct_simple_mmx_perm[64]={ +- 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, +- 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, +- 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, +- 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, +- 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, +- 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, +- 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, +- 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, ++static short idct_simple_mmx_perm[64] = { ++ 0x00, 0x08, 0x04, 0x09, 0x01, 0x0C, 0x05, 0x0D, ++ 0x10, 0x18, 0x14, 0x19, 0x11, 0x1C, 0x15, 0x1D, ++ 0x20, 0x28, 0x24, 0x29, 0x21, 0x2C, 0x25, 0x2D, ++ 0x12, 0x1A, 0x16, 0x1B, 0x13, 0x1E, 0x17, 0x1F, ++ 0x02, 0x0A, 0x06, 0x0B, 0x03, 0x0E, 0x07, 0x0F, ++ 0x30, 0x38, 0x34, 0x39, 0x31, 0x3C, 0x35, 0x3D, ++ 0x22, 0x2A, 0x26, 0x2B, 0x23, 0x2E, 0x27, 0x2F, ++ 0x32, 0x3A, 0x36, 0x3B, 0x33, 0x3E, 0x37, 0x3F, + }; + +-static const uint8_t idct_sse2_row_perm[8] = {0, 4, 1, 5, 2, 6, 3, 7}; ++static const uint8_t idct_sse2_row_perm[8] = { 0, 4, 1, 5, 2, 6, 3, 7 }; + + static void idct_mmx_init(void) + { +@@ -177,13 +202,11 @@ + /* the mmx/mmxext idct uses a reordered input, so we patch scan tables */ + for (i = 0; i < 64; i++) { + idct_mmx_perm[i] = (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); +-// idct_simple_mmx_perm[i] = simple_block_permute_op(i); + } + } + + DECLARE_ALIGNED(16, static DCTELEM, block)[64]; +-DECLARE_ALIGNED(8, static DCTELEM, block1)[64]; +-DECLARE_ALIGNED(8, static DCTELEM, block_org)[64]; ++DECLARE_ALIGNED(8, static DCTELEM, block1)[64]; + + static inline void mmx_emms(void) + { +@@ -193,190 +216,158 @@ + #endif + } + +-static void dct_error(const char *name, int is_idct, +- void (*fdct_func)(DCTELEM *block), +- void (*fdct_ref)(DCTELEM *block), int form, int test) ++static void init_block(DCTELEM block[64], int test, int is_idct, AVLFG *prng, int vals) + { +- int it, i, scale; +- int err_inf, v; +- int64_t err2, ti, ti1, it1; +- int64_t sysErr[64], sysErrMax=0; +- int maxout=0; +- int blockSumErrMax=0, blockSumErr; +- AVLFG prng; +- +- av_lfg_init(&prng, 1); ++ int i, j; + +- err_inf = 0; +- err2 = 0; +- for(i=0; i<64; i++) sysErr[i]=0; +- for(it=0;it>=3; +- } ++ switch (test) { ++ case 0: ++ for (i = 0; i < 64; i++) ++ block[i] = (av_lfg_get(prng) % (2*vals)) -vals; ++ if (is_idct) { ++ ff_ref_fdct(block); ++ for (i = 0; i < 64; i++) ++ block[i] >>= 3; ++ } + break; +- case 1:{ +- int num = av_lfg_get(&prng) % 10 + 1; +- for(i=0;i> 3) & 3)] = src[i]; ++ } else if (perm == TRANSPOSE_PERM) { ++ for (i = 0; i < 64; i++) ++ dst[(i>>3) | ((i<<3)&0x38)] = src[i]; ++ } else { ++ for (i = 0; i < 64; i++) ++ dst[i] = src[i]; ++ } + } +-#endif +- +- for(i=0; i<64; i++) +- block_org[i]= block1[i]; + +- if (form == MMX_PERM) { +- for(i=0;i<64;i++) +- block[idct_mmx_perm[i]] = block1[i]; +- } else if (form == MMX_SIMPLE_PERM) { +- for(i=0;i<64;i++) +- block[idct_simple_mmx_perm[i]] = block1[i]; ++static int dct_error(const struct algo *dct, int test, int is_idct, int speed, const int bits) ++{ ++ void (*ref)(DCTELEM *block) = is_idct ? ff_ref_idct : ff_ref_fdct; ++ int it, i, scale; ++ int err_inf, v; ++ int64_t err2, ti, ti1, it1, err_sum = 0; ++ int64_t sysErr[64], sysErrMax = 0; ++ int maxout = 0; ++ int blockSumErrMax = 0, blockSumErr; ++ AVLFG prng; ++ const int vals=1<>3)&3)] = block1[i]; +- } else { +- for(i=0; i<64; i++) +- block[i]= block1[i]; +- } +-#if 0 // simulate mismatch control for tested IDCT but not the ref +-{ int sum=0; +- for(i=0;i<64;i++) +- sum+=block[i]; ++ av_lfg_init(&prng, 1); + +- if((sum&1)==0) block[63]^=1; +-} +-#endif ++ err_inf = 0; ++ err2 = 0; ++ for (i = 0; i < 64; i++) ++ sysErr[i] = 0; ++ for (it = 0; it < NB_ITS; it++) { ++ init_block(block1, test, is_idct, &prng, vals); ++ permute(block, block1, dct->format); + +- fdct_func(block); ++ dct->func(block); + mmx_emms(); + +- if (form == SCALE_PERM) { +- for(i=0; i<64; i++) { +- scale = 8*(1 << (AANSCALE_BITS + 11)) / ff_aanscales[i]; +- block[i] = (block[i] * scale /*+ (1<<(AANSCALE_BITS-1))*/) >> AANSCALE_BITS; ++ if (dct->format == SCALE_PERM) { ++ for (i = 0; i < 64; i++) { ++ scale = 8 * (1 << (AANSCALE_BITS + 11)) / ff_aanscales[i]; ++ block[i] = (block[i] * scale) >> AANSCALE_BITS; + } + } + +- fdct_ref(block1); ++ ref(block1); + +- blockSumErr=0; +- for(i=0;i<64;i++) { +- v = abs(block[i] - block1[i]); ++ blockSumErr = 0; ++ for (i = 0; i < 64; i++) { ++ int err = block[i] - block1[i]; ++ err_sum += err; ++ v = abs(err); + if (v > err_inf) + err_inf = v; + err2 += v * v; + sysErr[i] += block[i] - block1[i]; + blockSumErr += v; +- if( abs(block[i])>maxout) maxout=abs(block[i]); +- } +- if(blockSumErrMax < blockSumErr) blockSumErrMax= blockSumErr; +-#if 0 // print different matrix pairs +- if(blockSumErr){ +- printf("\n"); +- for(i=0; i<64; i++){ +- if((i&7)==0) printf("\n"); +- printf("%4d ", block_org[i]); +- } +- for(i=0; i<64; i++){ +- if((i&7)==0) printf("\n"); +- printf("%4d ", block[i] - block1[i]); +- } ++ if (abs(block[i]) > maxout) ++ maxout = abs(block[i]); + } +-#endif ++ if (blockSumErrMax < blockSumErr) ++ blockSumErrMax = blockSumErr; + } +- for(i=0; i<64; i++) sysErrMax= FFMAX(sysErrMax, FFABS(sysErr[i])); ++ for (i = 0; i < 64; i++) ++ sysErrMax = FFMAX(sysErrMax, FFABS(sysErr[i])); + +-#if 1 // dump systematic errors +- for(i=0; i<64; i++){ +- if(i%8==0) printf("\n"); +- printf("%7d ", (int)sysErr[i]); ++ for (i = 0; i < 64; i++) { ++ if (i % 8 == 0) ++ printf("\n"); ++ printf("%7d ", (int) sysErr[i]); + } + printf("\n"); +-#endif + +- printf("%s %s: err_inf=%d err2=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", +- is_idct ? "IDCT" : "DCT", +- name, err_inf, (double)err2 / NB_ITS / 64.0, (double)sysErrMax / NB_ITS, maxout, blockSumErrMax); +-#if 1 //Speed test +- /* speed test */ +- for(i=0;i<64;i++) +- block1[i] = 0; +- switch(test){ +- case 0: +- for(i=0;i<64;i++) +- block1[i] = av_lfg_get(&prng) % 512 -256; +- if (is_idct){ +- ff_ref_fdct(block1); ++ omse = (double) err2 / NB_ITS / 64; ++ ome = (double) err_sum / NB_ITS / 64; + +- for(i=0;i<64;i++) +- block1[i]>>=3; +- } +- break; +- case 1:{ +- case 2: +- block1[0] = av_lfg_get(&prng) % 512 -256; +- block1[1] = av_lfg_get(&prng) % 512 -256; +- block1[2] = av_lfg_get(&prng) % 512 -256; +- block1[3] = av_lfg_get(&prng) % 512 -256; +- }break; +- } ++ spec_err = is_idct && (err_inf > 1 || omse > 0.02 || fabs(ome) > 0.0015); + +- if (form == MMX_PERM) { +- for(i=0;i<64;i++) +- block[idct_mmx_perm[i]] = block1[i]; +- } else if(form == MMX_SIMPLE_PERM) { +- for(i=0;i<64;i++) +- block[idct_simple_mmx_perm[i]] = block1[i]; +- } else { +- for(i=0; i<64; i++) +- block[i]= block1[i]; +- } ++ printf("%s %s: max_err=%d omse=%0.8f ome=%0.8f syserr=%0.8f maxout=%d blockSumErr=%d\n", ++ is_idct ? "IDCT" : "DCT", dct->name, err_inf, ++ omse, ome, (double) sysErrMax / NB_ITS, ++ maxout, blockSumErrMax); ++ ++ if (spec_err && !dct->nonspec) ++ return 1; ++ ++ if (!speed) ++ return 0; ++ ++ /* speed test */ ++ ++ init_block(block, test, is_idct, &prng, vals); ++ permute(block1, block, dct->format); + + ti = gettime(); + it1 = 0; + do { +- for(it=0;itfunc(block); + } + it1 += NB_ITS_SPEED; + ti1 = gettime() - ti; + } while (ti1 < 1000000); + mmx_emms(); + +- printf("%s %s: %0.1f kdct/s\n", +- is_idct ? "IDCT" : "DCT", +- name, (double)it1 * 1000.0 / (double)ti1); +-#endif ++ printf("%s %s: %0.1f kdct/s\n", is_idct ? "IDCT" : "DCT", dct->name, ++ (double) it1 * 1000.0 / (double) ti1); ++ ++ return 0; + } + + DECLARE_ALIGNED(8, static uint8_t, img_dest)[64]; +@@ -394,19 +385,19 @@ + if (!init) { + init = 1; + +- for(i=0;i<8;i++) { ++ for (i = 0; i < 8; i++) { + sum = 0; +- for(j=0;j<8;j++) { +- s = (i==0) ? sqrt(1.0/8.0) : sqrt(1.0/4.0); ++ for (j = 0; j < 8; j++) { ++ s = (i == 0) ? sqrt(1.0 / 8.0) : sqrt(1.0 / 4.0); + c8[i][j] = s * cos(M_PI * i * (j + 0.5) / 8.0); + sum += c8[i][j] * c8[i][j]; + } + } + +- for(i=0;i<4;i++) { ++ for (i = 0; i < 4; i++) { + sum = 0; +- for(j=0;j<4;j++) { +- s = (i==0) ? sqrt(1.0/4.0) : sqrt(1.0/2.0); ++ for (j = 0; j < 4; j++) { ++ s = (i == 0) ? sqrt(1.0 / 4.0) : sqrt(1.0 / 2.0); + c4[i][j] = s * cos(M_PI * i * (j + 0.5) / 4.0); + sum += c4[i][j] * c4[i][j]; + } +@@ -415,58 +406,59 @@ + + /* butterfly */ + s = 0.5 * sqrt(2.0); +- for(i=0;i<4;i++) { +- for(j=0;j<8;j++) { +- block1[8*(2*i)+j] = (block[8*(2*i)+j] + block[8*(2*i+1)+j]) * s; +- block1[8*(2*i+1)+j] = (block[8*(2*i)+j] - block[8*(2*i+1)+j]) * s; ++ for (i = 0; i < 4; i++) { ++ for (j = 0; j < 8; j++) { ++ block1[8 * (2 * i) + j] = ++ (block[8 * (2 * i) + j] + block[8 * (2 * i + 1) + j]) * s; ++ block1[8 * (2 * i + 1) + j] = ++ (block[8 * (2 * i) + j] - block[8 * (2 * i + 1) + j]) * s; + } + } + + /* idct8 on lines */ +- for(i=0;i<8;i++) { +- for(j=0;j<8;j++) { ++ for (i = 0; i < 8; i++) { ++ for (j = 0; j < 8; j++) { + sum = 0; +- for(k=0;k<8;k++) +- sum += c8[k][j] * block1[8*i+k]; +- block2[8*i+j] = sum; ++ for (k = 0; k < 8; k++) ++ sum += c8[k][j] * block1[8 * i + k]; ++ block2[8 * i + j] = sum; + } + } + + /* idct4 */ +- for(i=0;i<8;i++) { +- for(j=0;j<4;j++) { ++ for (i = 0; i < 8; i++) { ++ for (j = 0; j < 4; j++) { + /* top */ + sum = 0; +- for(k=0;k<4;k++) +- sum += c4[k][j] * block2[8*(2*k)+i]; +- block3[8*(2*j)+i] = sum; ++ for (k = 0; k < 4; k++) ++ sum += c4[k][j] * block2[8 * (2 * k) + i]; ++ block3[8 * (2 * j) + i] = sum; + + /* bottom */ + sum = 0; +- for(k=0;k<4;k++) +- sum += c4[k][j] * block2[8*(2*k+1)+i]; +- block3[8*(2*j+1)+i] = sum; ++ for (k = 0; k < 4; k++) ++ sum += c4[k][j] * block2[8 * (2 * k + 1) + i]; ++ block3[8 * (2 * j + 1) + i] = sum; + } + } + + /* clamp and store the result */ +- for(i=0;i<8;i++) { +- for(j=0;j<8;j++) { +- v = block3[8*i+j]; +- if (v < 0) +- v = 0; +- else if (v > 255) +- v = 255; +- dest[i * linesize + j] = (int)rint(v); ++ for (i = 0; i < 8; i++) { ++ for (j = 0; j < 8; j++) { ++ v = block3[8 * i + j]; ++ if (v < 0) v = 0; ++ else if (v > 255) v = 255; ++ dest[i * linesize + j] = (int) rint(v); + } + } + } + + static void idct248_error(const char *name, +- void (*idct248_put)(uint8_t *dest, int line_size, int16_t *block)) ++ void (*idct248_put)(uint8_t *dest, int line_size, ++ int16_t *block), ++ int speed) + { + int it, i, it1, ti, ti1, err_max, v; +- + AVLFG prng; + + av_lfg_init(&prng, 1); +@@ -474,23 +466,22 @@ + /* just one test to see if code is correct (precision is less + important here) */ + err_max = 0; +- for(it=0;it err_max) +@@ -516,18 +507,17 @@ + } + #endif + } +- printf("%s %s: err_inf=%d\n", +- 1 ? "IDCT248" : "DCT248", +- name, err_max); ++ printf("%s %s: err_inf=%d\n", 1 ? "IDCT248" : "DCT248", name, err_max); ++ ++ if (!speed) ++ return; + + ti = gettime(); + it1 = 0; + do { +- for(it=0;it]\n" ++ printf("dct-test [-i] [] []\n" + "test-number 0 -> test with random matrixes\n" + " 1 -> test with random sparse matrixes\n" + " 2 -> do 3. test from mpeg4 std\n" ++ "bits Number of time domain bits to use, 8 is default\n" + "-i test IDCT implementations\n" +- "-4 test IDCT248 implementations\n"); ++ "-4 test IDCT248 implementations\n" ++ "-t speed test\n"); + } + + int main(int argc, char **argv) + { + int test_idct = 0, test_248_dct = 0; +- int c,i; +- int test=1; ++ int c, i; ++ int test = 1; ++ int speed = 0; ++ int err = 0; ++ int bits=8; ++ + cpu_flags = av_get_cpu_flags(); + + ff_ref_dct_init(); + idct_mmx_init(); + +- for(i=0;i<256;i++) cropTbl[i + MAX_NEG_CROP] = i; +- for(i=0;ipriv_data; ++ ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ ++ s->frame_buf = av_mallocz(avctx->width * avctx->height + AV_LZO_OUTPUT_PADDING); ++ if (!s->frame_buf) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++static int decode_copy(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ const int size = width * height; ++ ++ if (src_end - src < size) ++ return -1; ++ bytestream_get_buffer(&src, frame, size); ++ return 0; ++} ++ ++static int decode_tsw1(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ const uint8_t *frame_start = frame; ++ const uint8_t *frame_end = frame + width * height; ++ int mask = 0x10000, bitbuf = 0; ++ int v, count, segments; ++ unsigned offset; ++ ++ segments = bytestream_get_le32(&src); ++ offset = bytestream_get_le32(&src); ++ if (frame_end - frame <= offset) ++ return -1; ++ frame += offset; ++ while (segments--) { ++ if (mask == 0x10000) { ++ if (src >= src_end) ++ return -1; ++ bitbuf = bytestream_get_le16(&src); ++ mask = 1; ++ } ++ if (src_end - src < 2 || frame_end - frame < 2) ++ return -1; ++ if (bitbuf & mask) { ++ v = bytestream_get_le16(&src); ++ offset = (v & 0x1FFF) << 1; ++ count = ((v >> 13) + 2) << 1; ++ if (frame - frame_start < offset || frame_end - frame < count) ++ return -1; ++ av_memcpy_backptr(frame, offset, count); ++ frame += count; ++ } else { ++ *frame++ = *src++; ++ *frame++ = *src++; ++ } ++ mask <<= 1; ++ } ++ ++ return 0; ++} ++ ++static int decode_dsw1(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ const uint8_t *frame_start = frame; ++ const uint8_t *frame_end = frame + width * height; ++ int mask = 0x10000, bitbuf = 0; ++ int v, offset, count, segments; ++ ++ segments = bytestream_get_le16(&src); ++ while (segments--) { ++ if (mask == 0x10000) { ++ if (src >= src_end) ++ return -1; ++ bitbuf = bytestream_get_le16(&src); ++ mask = 1; ++ } ++ if (src_end - src < 2 || frame_end - frame < 2) ++ return -1; ++ if (bitbuf & mask) { ++ v = bytestream_get_le16(&src); ++ offset = (v & 0x1FFF) << 1; ++ count = ((v >> 13) + 2) << 1; ++ if (frame - frame_start < offset || frame_end - frame < count) ++ return -1; ++ // can't use av_memcpy_backptr() since it can overwrite following pixels ++ for (v = 0; v < count; v++) ++ frame[v] = frame[v - offset]; ++ frame += count; ++ } else if (bitbuf & (mask << 1)) { ++ frame += bytestream_get_le16(&src); ++ } else { ++ *frame++ = *src++; ++ *frame++ = *src++; ++ } ++ mask <<= 2; ++ } ++ ++ return 0; ++} ++ ++static int decode_dds1(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ const uint8_t *frame_start = frame; ++ const uint8_t *frame_end = frame + width * height; ++ int mask = 0x10000, bitbuf = 0; ++ int i, v, offset, count, segments; ++ ++ segments = bytestream_get_le16(&src); ++ while (segments--) { ++ if (mask == 0x10000) { ++ if (src >= src_end) ++ return -1; ++ bitbuf = bytestream_get_le16(&src); ++ mask = 1; ++ } ++ if (src_end - src < 2 || frame_end - frame < 2) ++ return -1; ++ if (bitbuf & mask) { ++ v = bytestream_get_le16(&src); ++ offset = (v & 0x1FFF) << 2; ++ count = ((v >> 13) + 2) << 1; ++ if (frame - frame_start < offset || frame_end - frame < count*2 + width) ++ return -1; ++ for (i = 0; i < count; i++) { ++ frame[0] = frame[1] = ++ frame[width] = frame[width + 1] = frame[-offset]; ++ ++ frame += 2; ++ } ++ } else if (bitbuf & (mask << 1)) { ++ frame += bytestream_get_le16(&src) * 2; ++ } else { ++ frame[0] = frame[1] = ++ frame[width] = frame[width + 1] = *src++; ++ frame += 2; ++ frame[0] = frame[1] = ++ frame[width] = frame[width + 1] = *src++; ++ frame += 2; ++ } ++ mask <<= 2; ++ } ++ ++ return 0; ++} ++ ++static int decode_bdlt(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ uint8_t *line_ptr; ++ int count, lines, segments; ++ ++ count = bytestream_get_le16(&src); ++ if (count >= height) ++ return -1; ++ frame += width * count; ++ lines = bytestream_get_le16(&src); ++ if (count + lines > height || src >= src_end) ++ return -1; ++ ++ while (lines--) { ++ line_ptr = frame; ++ frame += width; ++ segments = *src++; ++ while (segments--) { ++ if (src_end - src < 3) ++ return -1; ++ if (frame - line_ptr <= *src) ++ return -1; ++ line_ptr += *src++; ++ count = (int8_t)*src++; ++ if (count >= 0) { ++ if (frame - line_ptr < count || src_end - src < count) ++ return -1; ++ bytestream_get_buffer(&src, line_ptr, count); ++ } else { ++ count = -count; ++ if (frame - line_ptr < count || src >= src_end) ++ return -1; ++ memset(line_ptr, *src++, count); ++ } ++ line_ptr += count; ++ } ++ } ++ ++ return 0; ++} ++ ++static int decode_wdlt(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ const uint8_t *frame_end = frame + width * height; ++ uint8_t *line_ptr; ++ int count, i, v, lines, segments; ++ ++ lines = bytestream_get_le16(&src); ++ if (lines > height || src >= src_end) ++ return -1; ++ ++ while (lines--) { ++ segments = bytestream_get_le16(&src); ++ while ((segments & 0xC000) == 0xC000) { ++ unsigned delta = -((int16_t)segments * width); ++ if (frame_end - frame <= delta) ++ return -1; ++ frame += delta; ++ segments = bytestream_get_le16(&src); ++ } ++ if (segments & 0x8000) { ++ frame[width - 1] = segments & 0xFF; ++ segments = bytestream_get_le16(&src); ++ } ++ line_ptr = frame; ++ frame += width; ++ while (segments--) { ++ if (src_end - src < 2) ++ return -1; ++ if (frame - line_ptr <= *src) ++ return -1; ++ line_ptr += *src++; ++ count = (int8_t)*src++; ++ if (count >= 0) { ++ if (frame - line_ptr < count*2 || src_end - src < count*2) ++ return -1; ++ bytestream_get_buffer(&src, line_ptr, count*2); ++ line_ptr += count * 2; ++ } else { ++ count = -count; ++ if (frame - line_ptr < count*2 || src_end - src < 2) ++ return -1; ++ v = bytestream_get_le16(&src); ++ for (i = 0; i < count; i++) ++ bytestream_put_le16(&line_ptr, v); ++ } ++ } ++ } ++ ++ return 0; ++} ++ ++static int decode_unk6(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ return -1; ++} ++ ++static int decode_blck(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end) ++{ ++ memset(frame, 0, width * height); ++ return 0; ++} ++ ++ ++typedef int (*chunk_decoder)(uint8_t *frame, int width, int height, ++ const uint8_t *src, const uint8_t *src_end); ++ ++static const chunk_decoder decoder[8] = { ++ decode_copy, decode_tsw1, decode_bdlt, decode_wdlt, ++ decode_unk6, decode_dsw1, decode_blck, decode_dds1, ++}; ++ ++static const char* chunk_name[8] = { ++ "COPY", "TSW1", "BDLT", "WDLT", "????", "DSW1", "BLCK", "DDS1" ++}; ++ ++static int dfa_decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ DfaContext *s = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; ++ const uint8_t *tmp_buf; ++ uint32_t chunk_type, chunk_size; ++ uint8_t *dst; ++ int ret; ++ int i, pal_elems; ++ ++ if (s->pic.data[0]) ++ avctx->release_buffer(avctx, &s->pic); ++ ++ if ((ret = avctx->get_buffer(avctx, &s->pic))) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ while (buf < buf_end) { ++ chunk_size = AV_RL32(buf + 4); ++ chunk_type = AV_RL32(buf + 8); ++ buf += 12; ++ if (buf_end - buf < chunk_size) { ++ av_log(avctx, AV_LOG_ERROR, "Chunk size is too big (%d bytes)\n", chunk_size); ++ return -1; ++ } ++ if (!chunk_type) ++ break; ++ if (chunk_type == 1) { ++ pal_elems = FFMIN(chunk_size / 3, 256); ++ tmp_buf = buf; ++ for (i = 0; i < pal_elems; i++) { ++ s->pal[i] = bytestream_get_be24(&tmp_buf) << 2; ++ s->pal[i] |= 0xFF << 24 | (s->pal[i] >> 6) & 0x30303; ++ } ++ s->pic.palette_has_changed = 1; ++ } else if (chunk_type <= 9) { ++ if (decoder[chunk_type - 2](s->frame_buf, avctx->width, avctx->height, ++ buf, buf + chunk_size)) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding %s chunk\n", ++ chunk_name[chunk_type - 2]); ++ return -1; ++ } ++ } else { ++ av_log(avctx, AV_LOG_WARNING, "Ignoring unknown chunk type %d\n", ++ chunk_type); ++ } ++ buf += chunk_size; ++ } ++ ++ buf = s->frame_buf; ++ dst = s->pic.data[0]; ++ for (i = 0; i < avctx->height; i++) { ++ memcpy(dst, buf, avctx->width); ++ dst += s->pic.linesize[0]; ++ buf += avctx->width; ++ } ++ memcpy(s->pic.data[1], s->pal, sizeof(s->pal)); ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = s->pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int dfa_decode_end(AVCodecContext *avctx) ++{ ++ DfaContext *s = avctx->priv_data; ++ ++ if (s->pic.data[0]) ++ avctx->release_buffer(avctx, &s->pic); ++ ++ av_freep(&s->frame_buf); ++ ++ return 0; ++} ++ ++AVCodec ff_dfa_decoder = { ++ .name = "dfa", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DFA, ++ .priv_data_size = sizeof(DfaContext), ++ .init = dfa_decode_init, ++ .close = dfa_decode_end, ++ .decode = dfa_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_arith.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_arith.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_arith.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_arith.c 2012-05-14 14:08:53.598325169 +0200 +@@ -0,0 +1,116 @@ ++/* ++ * Copyright (C) 2007 Marco Gerards ++ * Copyright (C) 2009 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Arithmetic decoder for Dirac ++ * @author Marco Gerards ++ */ ++ ++#include "dirac_arith.h" ++ ++ ++const uint16_t ff_dirac_prob[256] = { ++ 0, 2, 5, 8, 11, 15, 20, 24, ++ 29, 35, 41, 47, 53, 60, 67, 74, ++ 82, 89, 97, 106, 114, 123, 132, 141, ++ 150, 160, 170, 180, 190, 201, 211, 222, ++ 233, 244, 256, 267, 279, 291, 303, 315, ++ 327, 340, 353, 366, 379, 392, 405, 419, ++ 433, 447, 461, 475, 489, 504, 518, 533, ++ 548, 563, 578, 593, 609, 624, 640, 656, ++ 672, 688, 705, 721, 738, 754, 771, 788, ++ 805, 822, 840, 857, 875, 892, 910, 928, ++ 946, 964, 983, 1001, 1020, 1038, 1057, 1076, ++ 1095, 1114, 1133, 1153, 1172, 1192, 1211, 1231, ++ 1251, 1271, 1291, 1311, 1332, 1352, 1373, 1393, ++ 1414, 1435, 1456, 1477, 1498, 1520, 1541, 1562, ++ 1584, 1606, 1628, 1649, 1671, 1694, 1716, 1738, ++ 1760, 1783, 1806, 1828, 1851, 1874, 1897, 1920, ++ 1935, 1942, 1949, 1955, 1961, 1968, 1974, 1980, ++ 1985, 1991, 1996, 2001, 2006, 2011, 2016, 2021, ++ 2025, 2029, 2033, 2037, 2040, 2044, 2047, 2050, ++ 2053, 2056, 2058, 2061, 2063, 2065, 2066, 2068, ++ 2069, 2070, 2071, 2072, 2072, 2072, 2072, 2072, ++ 2072, 2071, 2070, 2069, 2068, 2066, 2065, 2063, ++ 2060, 2058, 2055, 2052, 2049, 2045, 2042, 2038, ++ 2033, 2029, 2024, 2019, 2013, 2008, 2002, 1996, ++ 1989, 1982, 1975, 1968, 1960, 1952, 1943, 1934, ++ 1925, 1916, 1906, 1896, 1885, 1874, 1863, 1851, ++ 1839, 1827, 1814, 1800, 1786, 1772, 1757, 1742, ++ 1727, 1710, 1694, 1676, 1659, 1640, 1622, 1602, ++ 1582, 1561, 1540, 1518, 1495, 1471, 1447, 1422, ++ 1396, 1369, 1341, 1312, 1282, 1251, 1219, 1186, ++ 1151, 1114, 1077, 1037, 995, 952, 906, 857, ++ 805, 750, 690, 625, 553, 471, 376, 255 ++}; ++ ++const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT] = { ++ [CTX_ZPZN_F1] = CTX_ZP_F2, ++ [CTX_ZPNN_F1] = CTX_ZP_F2, ++ [CTX_ZP_F2] = CTX_ZP_F3, ++ [CTX_ZP_F3] = CTX_ZP_F4, ++ [CTX_ZP_F4] = CTX_ZP_F5, ++ [CTX_ZP_F5] = CTX_ZP_F6, ++ [CTX_ZP_F6] = CTX_ZP_F6, ++ [CTX_NPZN_F1] = CTX_NP_F2, ++ [CTX_NPNN_F1] = CTX_NP_F2, ++ [CTX_NP_F2] = CTX_NP_F3, ++ [CTX_NP_F3] = CTX_NP_F4, ++ [CTX_NP_F4] = CTX_NP_F5, ++ [CTX_NP_F5] = CTX_NP_F6, ++ [CTX_NP_F6] = CTX_NP_F6, ++ [CTX_DELTA_Q_F] = CTX_DELTA_Q_F, ++}; ++ ++int16_t ff_dirac_prob_branchless[256][2]; ++ ++void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length) ++{ ++ int i; ++ align_get_bits(gb); ++ ++ length = FFMIN(length, get_bits_left(gb)/8); ++ ++ c->bytestream = gb->buffer + get_bits_count(gb)/8; ++ c->bytestream_end = c->bytestream + length; ++ skip_bits_long(gb, length*8); ++ ++ c->low = 0; ++ for (i = 0; i < 4; i++) { ++ c->low <<= 8; ++ if (c->bytestream < c->bytestream_end) ++ c->low |= *c->bytestream++; ++ else ++ c->low |= 0xff; ++ } ++ ++ c->counter = -16; ++ c->range = 0xffff; ++ ++ for (i = 0; i < 256; i++) { ++ ff_dirac_prob_branchless[i][0] = ff_dirac_prob[255-i]; ++ ff_dirac_prob_branchless[i][1] = -ff_dirac_prob[i]; ++ } ++ ++ for (i = 0; i < DIRAC_CTX_COUNT; i++) ++ c->contexts[i] = 0x8000; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_arith.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_arith.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_arith.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_arith.h 2012-05-14 14:08:53.599325189 +0200 +@@ -0,0 +1,190 @@ ++/* ++ * Copyright (C) 2007 Marco Gerards ++ * Copyright (C) 2009 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Arithmetic decoder for Dirac ++ * @author Marco Gerards ++ */ ++ ++#ifndef AVCODEC_DIRAC_ARITH_H ++#define AVCODEC_DIRAC_ARITH_H ++ ++#include "bytestream.h" ++#include "get_bits.h" ++ ++enum dirac_arith_contexts { ++ CTX_ZPZN_F1, ++ CTX_ZPNN_F1, ++ CTX_NPZN_F1, ++ CTX_NPNN_F1, ++ CTX_ZP_F2, ++ CTX_ZP_F3, ++ CTX_ZP_F4, ++ CTX_ZP_F5, ++ CTX_ZP_F6, ++ CTX_NP_F2, ++ CTX_NP_F3, ++ CTX_NP_F4, ++ CTX_NP_F5, ++ CTX_NP_F6, ++ CTX_COEFF_DATA, ++ CTX_SIGN_NEG, ++ CTX_SIGN_ZERO, ++ CTX_SIGN_POS, ++ CTX_ZERO_BLOCK, ++ CTX_DELTA_Q_F, ++ CTX_DELTA_Q_DATA, ++ CTX_DELTA_Q_SIGN, ++ ++ DIRAC_CTX_COUNT ++}; ++ ++// Dirac resets the arith decoder between decoding various types of data, ++// so many contexts are never used simultaneously. Thus, we can reduce ++// the number of contexts needed by reusing them. ++#define CTX_SB_F1 CTX_ZP_F5 ++#define CTX_SB_DATA 0 ++#define CTX_PMODE_REF1 0 ++#define CTX_PMODE_REF2 1 ++#define CTX_GLOBAL_BLOCK 2 ++#define CTX_MV_F1 CTX_ZP_F2 ++#define CTX_MV_DATA 0 ++#define CTX_DC_F1 CTX_ZP_F5 ++#define CTX_DC_DATA 0 ++ ++typedef struct { ++ unsigned low; ++ uint16_t range; ++ int16_t counter; ++ ++ const uint8_t *bytestream; ++ const uint8_t *bytestream_end; ++ ++ uint16_t contexts[DIRAC_CTX_COUNT]; ++} DiracArith; ++ ++extern const uint8_t ff_dirac_next_ctx[DIRAC_CTX_COUNT]; ++extern const uint16_t ff_dirac_prob[256]; ++extern int16_t ff_dirac_prob_branchless[256][2]; ++ ++static inline void renorm(DiracArith *c) ++{ ++#if HAVE_FAST_CLZ ++ int shift = 14 - av_log2_16bit(c->range-1) + ((c->range-1)>>15); ++ ++ c->low <<= shift; ++ c->range <<= shift; ++ c->counter += shift; ++#else ++ while (c->range <= 0x4000) { ++ c->low <<= 1; ++ c->range <<= 1; ++ c->counter++; ++ } ++#endif ++} ++ ++static inline void refill(DiracArith *c) ++{ ++ int counter = c->counter; ++ ++ if (counter >= 0) { ++ int new = bytestream_get_be16(&c->bytestream); ++ ++ // the spec defines overread bits to be 1, and streams rely on this ++ if (c->bytestream > c->bytestream_end) { ++ new |= 0xff; ++ if (c->bytestream > c->bytestream_end+1) ++ new |= 0xff00; ++ ++ c->bytestream = c->bytestream_end; ++ } ++ ++ c->low += new << counter; ++ counter -= 16; ++ } ++ c->counter = counter; ++} ++ ++static inline int dirac_get_arith_bit(DiracArith *c, int ctx) ++{ ++ int prob_zero = c->contexts[ctx]; ++ int range_times_prob, bit; ++ unsigned low = c->low; ++ int range = c->range; ++ ++ range_times_prob = (c->range * prob_zero) >> 16; ++ ++#if HAVE_FAST_CMOV ++ low -= range_times_prob << 16; ++ range -= range_times_prob; ++ bit = 0; ++ __asm__( ++ "cmpl %5, %4 \n\t" ++ "setae %b0 \n\t" ++ "cmovb %3, %2 \n\t" ++ "cmovb %5, %1 \n\t" ++ : "+q"(bit), "+r"(range), "+r"(low) ++ : "r"(c->low), "r"(c->low>>16), ++ "r"(range_times_prob) ++ ); ++#else ++ bit = (low >> 16) >= range_times_prob; ++ if (bit) { ++ low -= range_times_prob << 16; ++ range -= range_times_prob; ++ } else { ++ range = range_times_prob; ++ } ++#endif ++ ++ c->contexts[ctx] += ff_dirac_prob_branchless[prob_zero>>8][bit]; ++ c->low = low; ++ c->range = range; ++ ++ renorm(c); ++ refill(c); ++ return bit; ++} ++ ++static inline int dirac_get_arith_uint(DiracArith *c, int follow_ctx, int data_ctx) ++{ ++ int ret = 1; ++ while (!dirac_get_arith_bit(c, follow_ctx)) { ++ ret <<= 1; ++ ret += dirac_get_arith_bit(c, data_ctx); ++ follow_ctx = ff_dirac_next_ctx[follow_ctx]; ++ } ++ return ret-1; ++} ++ ++static inline int dirac_get_arith_int(DiracArith *c, int follow_ctx, int data_ctx) ++{ ++ int ret = dirac_get_arith_uint(c, follow_ctx, data_ctx); ++ if (ret && dirac_get_arith_bit(c, data_ctx+1)) ++ ret = -ret; ++ return ret; ++} ++ ++void ff_dirac_init_arith_decoder(DiracArith *c, GetBitContext *gb, int length); ++ ++#endif /* AVCODEC_DIRAC_ARITH_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac.c 2012-05-14 14:08:53.597325148 +0200 +@@ -1,6 +1,7 @@ + /* + * Copyright (C) 2007 Marco Gerards + * Copyright (C) 2009 David Conrad ++ * Copyright (C) 2011 Jordi Ortiz + * + * This file is part of FFmpeg. + * +@@ -22,16 +23,16 @@ + /** + * @file + * Dirac Decoder +- * @author Marco Gerards ++ * @author Marco Gerards , David Conrad, Jordi Ortiz + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "dirac.h" + #include "avcodec.h" + #include "golomb.h" + #include "mpeg12data.h" + +-// defaults for source parameters ++/* defaults for source parameters */ + static const dirac_source_params dirac_source_parameters_defaults[] = { + { 640, 480, 2, 0, 0, 1, 1, 640, 480, 0, 0, 1, 0 }, + { 176, 120, 2, 0, 0, 9, 2, 176, 120, 0, 0, 1, 1 }, +@@ -42,7 +43,6 @@ + { 704, 576, 2, 0, 1, 10, 3, 704, 576, 0, 0, 1, 2 }, + { 720, 480, 1, 1, 0, 4, 2, 704, 480, 8, 0, 3, 1 }, + { 720, 576, 1, 1, 1, 3, 3, 704, 576, 8, 0, 3, 2 }, +- + { 1280, 720, 1, 0, 1, 7, 1, 1280, 720, 0, 0, 3, 3 }, + { 1280, 720, 1, 0, 1, 6, 1, 1280, 720, 0, 0, 3, 3 }, + { 1920, 1080, 1, 1, 1, 4, 1, 1920, 1080, 0, 0, 3, 3 }, +@@ -51,13 +51,16 @@ + { 1920, 1080, 1, 0, 1, 6, 1, 1920, 1080, 0, 0, 3, 3 }, + { 2048, 1080, 0, 0, 1, 2, 1, 2048, 1080, 0, 0, 4, 4 }, + { 4096, 2160, 0, 0, 1, 2, 1, 4096, 2160, 0, 0, 4, 4 }, +- + { 3840, 2160, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, + { 3840, 2160, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, + { 7680, 4320, 1, 0, 1, 7, 1, 3840, 2160, 0, 0, 3, 3 }, + { 7680, 4320, 1, 0, 1, 6, 1, 3840, 2160, 0, 0, 3, 3 }, + }; + ++/** ++ * Dirac Specification -> ++ * Table 10.4 - Available preset pixel aspect ratio values ++ */ + static const AVRational dirac_preset_aspect_ratios[] = { + {1, 1}, + {10, 11}, +@@ -67,11 +70,19 @@ + {4, 3}, + }; + ++/** ++ * Dirac Specification -> ++ * Values 9,10 of 10.3.5 Frame Rate. Table 10.3 Available preset frame rate values ++ */ + static const AVRational dirac_frame_rate[] = { + {15000, 1001}, + {25, 2}, + }; + ++/** ++ * Dirac Specification -> ++ * This should be equivalent to Table 10.5 Available signal range presets ++ */ + static const struct { + uint8_t bitdepth; + enum AVColorRange color_range; +@@ -100,11 +111,19 @@ + { AVCOL_PRI_BT709, AVCOL_SPC_BT709, AVCOL_TRC_UNSPECIFIED /* DCinema */ }, + }; + ++/** ++ * Dirac Specification -> ++ * Table 10.2 Supported chroma sampling formats + Luma Offset ++ */ + static const enum PixelFormat dirac_pix_fmt[2][3] = { + { PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P }, + { PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P }, + }; + ++/** ++ * Dirac Specification -> ++ * 10.3 Parse Source Parameters. source_parameters(base_video_format) ++ */ + static int parse_source_parameters(AVCodecContext *avctx, GetBitContext *gb, + dirac_source_params *source) + { +@@ -112,51 +131,54 @@ + unsigned luma_depth = 8, luma_offset = 16; + int idx; + +- if (get_bits1(gb)) { +- source->width = svq3_get_ue_golomb(gb); +- source->height = svq3_get_ue_golomb(gb); ++ /* [DIRAC_STD] 10.3.2 Frame size. frame_size(video_params) */ ++ if (get_bits1(gb)) { /* [DIRAC_STD] custom_dimensions_flag */ ++ source->width = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_WIDTH */ ++ source->height = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_HEIGHT */ + } + +- // chroma subsampling +- if (get_bits1(gb)) +- source->chroma_format = svq3_get_ue_golomb(gb); +- if (source->chroma_format > 2) { ++ /* [DIRAC_STD] 10.3.3 Chroma Sampling Format. ++ chroma_sampling_format(video_params) */ ++ if (get_bits1(gb)) /* [DIRAC_STD] custom_chroma_format_flag */ ++ source->chroma_format = svq3_get_ue_golomb(gb); /*[DIRAC_STD] CHROMA_FORMAT_INDEX */ ++ if (source->chroma_format > 2U) { + av_log(avctx, AV_LOG_ERROR, "Unknown chroma format %d\n", + source->chroma_format); + return -1; + } + +- if (get_bits1(gb)) +- source->interlaced = svq3_get_ue_golomb(gb); +- if (source->interlaced > 1) ++ /* [DIRAC_STD] 10.3.4 Scan Format. scan_format(video_params) */ ++ if (get_bits1(gb)) /* [DIRAC_STD] custom_scan_format_flag */ ++ source->interlaced = svq3_get_ue_golomb(gb); /* [DIRAC_STD] SOURCE_SAMPLING */ ++ if (source->interlaced > 1U) + return -1; + +- // frame rate +- if (get_bits1(gb)) { ++ /* [DIRAC_STD] 10.3.5 Frame Rate. frame_rate(video_params) */ ++ if (get_bits1(gb)) { /* [DIRAC_STD] custom_frame_rate_flag */ + source->frame_rate_index = svq3_get_ue_golomb(gb); + +- if (source->frame_rate_index > 10) ++ if (source->frame_rate_index > 10U) + return -1; + +- if (!source->frame_rate_index) { +- frame_rate.num = svq3_get_ue_golomb(gb); +- frame_rate.den = svq3_get_ue_golomb(gb); ++ if (!source->frame_rate_index){ ++ frame_rate.num = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_RATE_NUMER */ ++ frame_rate.den = svq3_get_ue_golomb(gb); /* [DIRAC_STD] FRAME_RATE_DENOM */ + } + } +- if (source->frame_rate_index > 0) { ++ if (source->frame_rate_index > 0) { /* [DIRAC_STD] preset_frame_rate(video_params,index) */ + if (source->frame_rate_index <= 8) +- frame_rate = ff_frame_rate_tab[source->frame_rate_index]; ++ frame_rate = avpriv_frame_rate_tab[source->frame_rate_index]; /* [DIRAC_STD] Table 10.3 values 1-8 */ + else +- frame_rate = dirac_frame_rate[source->frame_rate_index-9]; ++ frame_rate = dirac_frame_rate[source->frame_rate_index-9]; /* [DIRAC_STD] Table 10.3 values 9-10 */ + } + av_reduce(&avctx->time_base.num, &avctx->time_base.den, + frame_rate.den, frame_rate.num, 1<<30); + +- // aspect ratio +- if (get_bits1(gb)) { +- source->aspect_ratio_index = svq3_get_ue_golomb(gb); ++ /* [DIRAC_STD] 10.3.6 Pixel Aspect Ratio. pixel_aspect_ratio(video_params) */ ++ if (get_bits1(gb)) { /* [DIRAC_STD] custom_pixel_aspect_ratio_flag */ ++ source->aspect_ratio_index = svq3_get_ue_golomb(gb); /* [DIRAC_STD] index */ + +- if (source->aspect_ratio_index > 6) ++ if (source->aspect_ratio_index > 6U) + return -1; + + if (!source->aspect_ratio_index) { +@@ -164,35 +186,37 @@ + avctx->sample_aspect_ratio.den = svq3_get_ue_golomb(gb); + } + } +- if (source->aspect_ratio_index > 0) ++ if (source->aspect_ratio_index > 0) /* [DIRAC_STD] Take value from Table 10.4 Available preset pixel aspect ratio values */ + avctx->sample_aspect_ratio = +- dirac_preset_aspect_ratios[source->aspect_ratio_index-1]; ++ dirac_preset_aspect_ratios[source->aspect_ratio_index-1]; + +- if (get_bits1(gb)) { +- source->clean_width = svq3_get_ue_golomb(gb); +- source->clean_height = svq3_get_ue_golomb(gb); +- source->clean_left_offset = svq3_get_ue_golomb(gb); +- source->clean_right_offset = svq3_get_ue_golomb(gb); ++ /* [DIRAC_STD] 10.3.7 Clean area. clean_area(video_params) */ ++ if (get_bits1(gb)) { /* [DIRAC_STD] custom_clean_area_flag */ ++ source->clean_width = svq3_get_ue_golomb(gb); /* [DIRAC_STD] CLEAN_WIDTH */ ++ source->clean_height = svq3_get_ue_golomb(gb); /* [DIRAC_STD] CLEAN_HEIGHT */ ++ source->clean_left_offset = svq3_get_ue_golomb(gb); /* [DIRAC_STD] CLEAN_LEFT_OFFSET */ ++ source->clean_right_offset = svq3_get_ue_golomb(gb); /* [DIRAC_STD] CLEAN_RIGHT_OFFSET */ + } + +- // Override signal range. +- if (get_bits1(gb)) { +- source->pixel_range_index = svq3_get_ue_golomb(gb); ++ /*[DIRAC_STD] 10.3.8 Signal range. signal_range(video_params) ++ WARNING: Some adaptation seemed to be done using the AVCOL_RANGE_MPEG/JPEG values */ ++ if (get_bits1(gb)) { /*[DIRAC_STD] custom_signal_range_flag */ ++ source->pixel_range_index = svq3_get_ue_golomb(gb); /*[DIRAC_STD] index */ + +- if (source->pixel_range_index > 4) ++ if (source->pixel_range_index > 4U) + return -1; + +- // This assumes either fullrange or MPEG levels only ++ /* This assumes either fullrange or MPEG levels only */ + if (!source->pixel_range_index) { + luma_offset = svq3_get_ue_golomb(gb); + luma_depth = av_log2(svq3_get_ue_golomb(gb))+1; +- svq3_get_ue_golomb(gb); // chroma offset +- svq3_get_ue_golomb(gb); // chroma excursion ++ svq3_get_ue_golomb(gb); /* chroma offset @Jordi: Why are these two ignored? */ ++ svq3_get_ue_golomb(gb); /* chroma excursion */ + + avctx->color_range = luma_offset ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; + } + } +- if (source->pixel_range_index > 0) { ++ if (source->pixel_range_index > 0) { /*[DIRAC_STD] Take values from Table 10.5 Available signal range presets */ + idx = source->pixel_range_index-1; + luma_depth = pixel_range_presets[idx].bitdepth; + avctx->color_range = pixel_range_presets[idx].color_range; +@@ -203,11 +227,11 @@ + + avctx->pix_fmt = dirac_pix_fmt[!luma_offset][source->chroma_format]; + +- // color spec +- if (get_bits1(gb)) { +- idx = source->color_spec_index = svq3_get_ue_golomb(gb); ++ /* [DIRAC_STD] 10.3.9 Colour specification. colour_spec(video_params) */ ++ if (get_bits1(gb)) { /* [DIRAC_STD] custom_colour_spec_flag */ ++ idx = source->color_spec_index = svq3_get_ue_golomb(gb); /* [DIRAC_STD] index */ + +- if (source->color_spec_index > 4) ++ if (source->color_spec_index > 4U) + return -1; + + avctx->color_primaries = dirac_color_presets[idx].color_primaries; +@@ -215,12 +239,13 @@ + avctx->color_trc = dirac_color_presets[idx].color_trc; + + if (!source->color_spec_index) { ++ /* [DIRAC_STD] 10.3.9.1 Color primaries */ + if (get_bits1(gb)) { + idx = svq3_get_ue_golomb(gb); +- if (idx < 3) ++ if (idx < 3U) + avctx->color_primaries = dirac_primaries[idx]; + } +- ++ /* [DIRAC_STD] 10.3.9.2 Color matrix */ + if (get_bits1(gb)) { + idx = svq3_get_ue_golomb(gb); + if (!idx) +@@ -228,7 +253,7 @@ + else if (idx == 1) + avctx->colorspace = AVCOL_SPC_BT470BG; + } +- ++ /* [DIRAC_STD] 10.3.9.3 Transfer function */ + if (get_bits1(gb) && !svq3_get_ue_golomb(gb)) + avctx->color_trc = AVCOL_TRC_BT709; + } +@@ -242,16 +267,23 @@ + return 0; + } + +-int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, ++/** ++ * Dirac Specification -> ++ * 10. Sequence Header. sequence_header() ++ */ ++int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, + dirac_source_params *source) + { +- unsigned version_major, version_minor; ++ unsigned version_major; + unsigned video_format, picture_coding_mode; + ++ /* [DIRAC_SPEC] 10.1 Parse Parameters. parse_parameters() */ + version_major = svq3_get_ue_golomb(gb); +- version_minor = svq3_get_ue_golomb(gb); ++ svq3_get_ue_golomb(gb); /* version_minor */ + avctx->profile = svq3_get_ue_golomb(gb); + avctx->level = svq3_get_ue_golomb(gb); ++ /* [DIRAC_SPEC] sequence_header() -> base_video_format as defined in ++ 10.2 Base Video Format, table 10.1 Dirac predefined video formats */ + video_format = svq3_get_ue_golomb(gb); + + if (version_major < 2) +@@ -259,13 +291,14 @@ + else if (version_major > 2) + av_log(avctx, AV_LOG_WARNING, "Stream may have unhandled features\n"); + +- if (video_format > 20) ++ if (video_format > 20U) + return -1; + +- // Fill in defaults for the source parameters. ++ /* Fill in defaults for the source parameters. */ + *source = dirac_source_parameters_defaults[video_format]; + +- // Override the defaults. ++ /*[DIRAC_STD] 10.3 Source Parameters ++ Override the defaults. */ + if (parse_source_parameters(avctx, gb, source)) + return -1; + +@@ -274,7 +307,8 @@ + + avcodec_set_dimensions(avctx, source->width, source->height); + +- // currently only used to signal field coding ++ /*[DIRAC_STD] picture_coding_mode shall be 0 for fields and 1 for frames ++ currently only used to signal field coding */ + picture_coding_mode = svq3_get_ue_golomb(gb); + if (picture_coding_mode != 0) { + av_log(avctx, AV_LOG_ERROR, "Unsupported picture coding mode %d", +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdec.c 2012-05-14 14:08:53.604325289 +0200 +@@ -0,0 +1,1922 @@ ++/* ++ * Copyright (C) 2007 Marco Gerards ++ * Copyright (C) 2009 David Conrad ++ * Copyright (C) 2011 Jordi Ortiz ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file libavcodec/diracdec.c ++ * Dirac Decoder ++ * @author Marco Gerards , David Conrad, Jordi Ortiz ++ */ ++ ++#include "avcodec.h" ++#include "dsputil.h" ++#include "get_bits.h" ++#include "bytestream.h" ++#include "golomb.h" ++#include "dirac_arith.h" ++#include "mpeg12data.h" ++#include "dwt.h" ++#include "dirac.h" ++#include "diracdsp.h" ++ ++/** ++ * The spec limits the number of wavelet decompositions to 4 for both ++ * level 1 (VC-2) and 128 (long-gop default). ++ * 5 decompositions is the maximum before >16-bit buffers are needed. ++ * Schroedinger allows this for DD 9,7 and 13,7 wavelets only, limiting ++ * the others to 4 decompositions (or 3 for the fidelity filter). ++ * ++ * We use this instead of MAX_DECOMPOSITIONS to save some memory. ++ */ ++#define MAX_DWT_LEVELS 5 ++ ++/** ++ * The spec limits this to 3 for frame coding, but in practice can be as high as 6 ++ */ ++#define MAX_REFERENCE_FRAMES 8 ++#define MAX_DELAY 5 /* limit for main profile for frame coding (TODO: field coding) */ ++#define MAX_FRAMES (MAX_REFERENCE_FRAMES + MAX_DELAY + 1) ++#define MAX_QUANT 68 /* max quant for VC-2 */ ++#define MAX_BLOCKSIZE 32 /* maximum xblen/yblen we support */ ++ ++/** ++ * DiracBlock->ref flags, if set then the block does MC from the given ref ++ */ ++#define DIRAC_REF_MASK_REF1 1 ++#define DIRAC_REF_MASK_REF2 2 ++#define DIRAC_REF_MASK_GLOBAL 4 ++ ++/** ++ * Value of Picture.reference when Picture is not a reference picture, but ++ * is held for delayed output. ++ */ ++#define DELAYED_PIC_REF 4 ++ ++#define ff_emulated_edge_mc ff_emulated_edge_mc_8 /* Fix: change the calls to this function regarding bit depth */ ++ ++#define CALC_PADDING(size, depth) \ ++ (((size + (1 << depth) - 1) >> depth) << depth) ++ ++#define DIVRNDUP(a, b) (((a) + (b) - 1) / (b)) ++ ++typedef struct { ++ AVFrame avframe; ++ int interpolated[3]; /* 1 if hpel[] is valid */ ++ uint8_t *hpel[3][4]; ++ uint8_t *hpel_base[3][4]; ++} DiracFrame; ++ ++typedef struct { ++ union { ++ int16_t mv[2][2]; ++ int16_t dc[3]; ++ } u; /* anonymous unions aren't in C99 :( */ ++ uint8_t ref; ++} DiracBlock; ++ ++typedef struct SubBand { ++ int level; ++ int orientation; ++ int stride; ++ int width; ++ int height; ++ int quant; ++ IDWTELEM *ibuf; ++ struct SubBand *parent; ++ ++ /* for low delay */ ++ unsigned length; ++ const uint8_t *coeff_data; ++} SubBand; ++ ++typedef struct Plane { ++ int width; ++ int height; ++ int stride; ++ ++ int idwt_width; ++ int idwt_height; ++ int idwt_stride; ++ IDWTELEM *idwt_buf; ++ IDWTELEM *idwt_buf_base; ++ IDWTELEM *idwt_tmp; ++ ++ /* block length */ ++ uint8_t xblen; ++ uint8_t yblen; ++ /* block separation (block n+1 starts after this many pixels in block n) */ ++ uint8_t xbsep; ++ uint8_t ybsep; ++ /* amount of overspill on each edge (half of the overlap between blocks) */ ++ uint8_t xoffset; ++ uint8_t yoffset; ++ ++ SubBand band[MAX_DWT_LEVELS][4]; ++} Plane; ++ ++typedef struct DiracContext { ++ AVCodecContext *avctx; ++ DSPContext dsp; ++ DiracDSPContext diracdsp; ++ GetBitContext gb; ++ dirac_source_params source; ++ int seen_sequence_header; ++ int frame_number; /* number of the next frame to display */ ++ Plane plane[3]; ++ int chroma_x_shift; ++ int chroma_y_shift; ++ ++ int zero_res; /* zero residue flag */ ++ int is_arith; /* whether coeffs use arith or golomb coding */ ++ int low_delay; /* use the low delay syntax */ ++ int globalmc_flag; /* use global motion compensation */ ++ int num_refs; /* number of reference pictures */ ++ ++ /* wavelet decoding */ ++ unsigned wavelet_depth; /* depth of the IDWT */ ++ unsigned wavelet_idx; ++ ++ /** ++ * schroedinger older than 1.0.8 doesn't store ++ * quant delta if only one codebook exists in a band ++ */ ++ unsigned old_delta_quant; ++ unsigned codeblock_mode; ++ ++ struct { ++ unsigned width; ++ unsigned height; ++ } codeblock[MAX_DWT_LEVELS+1]; ++ ++ struct { ++ unsigned num_x; /* number of horizontal slices */ ++ unsigned num_y; /* number of vertical slices */ ++ AVRational bytes; /* average bytes per slice */ ++ uint8_t quant[MAX_DWT_LEVELS][4]; /* [DIRAC_STD] E.1 */ ++ } lowdelay; ++ ++ struct { ++ int pan_tilt[2]; /* pan/tilt vector */ ++ int zrs[2][2]; /* zoom/rotate/shear matrix */ ++ int perspective[2]; /* perspective vector */ ++ unsigned zrs_exp; ++ unsigned perspective_exp; ++ } globalmc[2]; ++ ++ /* motion compensation */ ++ uint8_t mv_precision; /* [DIRAC_STD] REFS_WT_PRECISION */ ++ int16_t weight[2]; /* [DIRAC_STD] REF1_WT and REF2_WT */ ++ unsigned weight_log2denom; /* [DIRAC_STD] REFS_WT_PRECISION */ ++ ++ int blwidth; /* number of blocks (horizontally) */ ++ int blheight; /* number of blocks (vertically) */ ++ int sbwidth; /* number of superblocks (horizontally) */ ++ int sbheight; /* number of superblocks (vertically) */ ++ ++ uint8_t *sbsplit; ++ DiracBlock *blmotion; ++ ++ uint8_t *edge_emu_buffer[4]; ++ uint8_t *edge_emu_buffer_base; ++ ++ uint16_t *mctmp; /* buffer holding the MC data multipled by OBMC weights */ ++ uint8_t *mcscratch; ++ ++ DECLARE_ALIGNED(16, uint8_t, obmc_weight)[3][MAX_BLOCKSIZE*MAX_BLOCKSIZE]; ++ ++ void (*put_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++ void (*avg_pixels_tab[4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++ void (*add_obmc)(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++ dirac_weight_func weight_func; ++ dirac_biweight_func biweight_func; ++ ++ DiracFrame *current_picture; ++ DiracFrame *ref_pics[2]; ++ ++ DiracFrame *ref_frames[MAX_REFERENCE_FRAMES+1]; ++ DiracFrame *delay_frames[MAX_DELAY+1]; ++ DiracFrame all_frames[MAX_FRAMES]; ++} DiracContext; ++ ++/** ++ * Dirac Specification -> ++ * Parse code values. 9.6.1 Table 9.1 ++ */ ++enum dirac_parse_code { ++ pc_seq_header = 0x00, ++ pc_eos = 0x10, ++ pc_aux_data = 0x20, ++ pc_padding = 0x30, ++}; ++ ++enum dirac_subband { ++ subband_ll = 0, ++ subband_hl = 1, ++ subband_lh = 2, ++ subband_hh = 3 ++}; ++ ++static const uint8_t default_qmat[][4][4] = { ++ { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} }, ++ { { 4, 2, 2, 0}, { 0, 4, 4, 2}, { 0, 5, 5, 3}, { 0, 7, 7, 5} }, ++ { { 5, 3, 3, 0}, { 0, 4, 4, 1}, { 0, 5, 5, 2}, { 0, 6, 6, 3} }, ++ { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} }, ++ { { 8, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0}, { 0, 4, 4, 0} }, ++ { { 0, 4, 4, 8}, { 0, 8, 8, 12}, { 0, 13, 13, 17}, { 0, 17, 17, 21} }, ++ { { 3, 1, 1, 0}, { 0, 4, 4, 2}, { 0, 6, 6, 5}, { 0, 9, 9, 7} }, ++}; ++ ++static const int qscale_tab[MAX_QUANT+1] = { ++ 4, 5, 6, 7, 8, 10, 11, 13, ++ 16, 19, 23, 27, 32, 38, 45, 54, ++ 64, 76, 91, 108, 128, 152, 181, 215, ++ 256, 304, 362, 431, 512, 609, 724, 861, ++ 1024, 1218, 1448, 1722, 2048, 2435, 2896, 3444, ++ 4096, 4871, 5793, 6889, 8192, 9742, 11585, 13777, ++ 16384, 19484, 23170, 27554, 32768, 38968, 46341, 55109, ++ 65536, 77936 ++}; ++ ++static const int qoffset_intra_tab[MAX_QUANT+1] = { ++ 1, 2, 3, 4, 4, 5, 6, 7, ++ 8, 10, 12, 14, 16, 19, 23, 27, ++ 32, 38, 46, 54, 64, 76, 91, 108, ++ 128, 152, 181, 216, 256, 305, 362, 431, ++ 512, 609, 724, 861, 1024, 1218, 1448, 1722, ++ 2048, 2436, 2897, 3445, 4096, 4871, 5793, 6889, ++ 8192, 9742, 11585, 13777, 16384, 19484, 23171, 27555, ++ 32768, 38968 ++}; ++ ++static const int qoffset_inter_tab[MAX_QUANT+1] = { ++ 1, 2, 2, 3, 3, 4, 4, 5, ++ 6, 7, 9, 10, 12, 14, 17, 20, ++ 24, 29, 34, 41, 48, 57, 68, 81, ++ 96, 114, 136, 162, 192, 228, 272, 323, ++ 384, 457, 543, 646, 768, 913, 1086, 1292, ++ 1536, 1827, 2172, 2583, 3072, 3653, 4344, 5166, ++ 6144, 7307, 8689, 10333, 12288, 14613, 17378, 20666, ++ 24576, 29226 ++}; ++ ++/* magic number division by 3 from schroedinger */ ++static inline int divide3(int x) ++{ ++ return ((x+1)*21845 + 10922) >> 16; ++} ++ ++static DiracFrame *remove_frame(DiracFrame *framelist[], int picnum) ++{ ++ DiracFrame *remove_pic = NULL; ++ int i, remove_idx = -1; ++ ++ for (i = 0; framelist[i]; i++) ++ if (framelist[i]->avframe.display_picture_number == picnum) { ++ remove_pic = framelist[i]; ++ remove_idx = i; ++ } ++ ++ if (remove_pic) ++ for (i = remove_idx; framelist[i]; i++) ++ framelist[i] = framelist[i+1]; ++ ++ return remove_pic; ++} ++ ++static int add_frame(DiracFrame *framelist[], int maxframes, DiracFrame *frame) ++{ ++ int i; ++ for (i = 0; i < maxframes; i++) ++ if (!framelist[i]) { ++ framelist[i] = frame; ++ return 0; ++ } ++ return -1; ++} ++ ++static int alloc_sequence_buffers(DiracContext *s) ++{ ++ int sbwidth = DIVRNDUP(s->source.width, 4); ++ int sbheight = DIVRNDUP(s->source.height, 4); ++ int i, w, h, top_padding; ++ ++ /* todo: think more about this / use or set Plane here */ ++ for (i = 0; i < 3; i++) { ++ int max_xblen = MAX_BLOCKSIZE >> (i ? s->chroma_x_shift : 0); ++ int max_yblen = MAX_BLOCKSIZE >> (i ? s->chroma_y_shift : 0); ++ w = s->source.width >> (i ? s->chroma_x_shift : 0); ++ h = s->source.height >> (i ? s->chroma_y_shift : 0); ++ ++ /* we allocate the max we support here since num decompositions can ++ * change from frame to frame. Stride is aligned to 16 for SIMD, and ++ * 1<0) in arith decoding ++ * MAX_BLOCKSIZE padding for MC: blocks can spill up to half of that ++ * on each side */ ++ top_padding = FFMAX(1<plane[i].idwt_buf_base = av_mallocz((w+max_xblen)*h * sizeof(IDWTELEM)); ++ s->plane[i].idwt_tmp = av_malloc((w+16) * sizeof(IDWTELEM)); ++ s->plane[i].idwt_buf = s->plane[i].idwt_buf_base + top_padding*w; ++ if (!s->plane[i].idwt_buf_base || !s->plane[i].idwt_tmp) ++ return AVERROR(ENOMEM); ++ } ++ ++ w = s->source.width; ++ h = s->source.height; ++ ++ /* fixme: allocate using real stride here */ ++ s->sbsplit = av_malloc(sbwidth * sbheight); ++ s->blmotion = av_malloc(sbwidth * sbheight * 4 * sizeof(*s->blmotion)); ++ s->edge_emu_buffer_base = av_malloc((w+64)*MAX_BLOCKSIZE); ++ ++ s->mctmp = av_malloc((w+64+MAX_BLOCKSIZE) * (h*MAX_BLOCKSIZE) * sizeof(*s->mctmp)); ++ s->mcscratch = av_malloc((w+64)*MAX_BLOCKSIZE); ++ ++ if (!s->sbsplit || !s->blmotion) ++ return AVERROR(ENOMEM); ++ return 0; ++} ++ ++static void free_sequence_buffers(DiracContext *s) ++{ ++ int i, j, k; ++ ++ for (i = 0; i < MAX_FRAMES; i++) { ++ if (s->all_frames[i].avframe.data[0]) { ++ s->avctx->release_buffer(s->avctx, &s->all_frames[i].avframe); ++ memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated)); ++ } ++ ++ for (j = 0; j < 3; j++) ++ for (k = 1; k < 4; k++) ++ av_freep(&s->all_frames[i].hpel_base[j][k]); ++ } ++ ++ memset(s->ref_frames, 0, sizeof(s->ref_frames)); ++ memset(s->delay_frames, 0, sizeof(s->delay_frames)); ++ ++ for (i = 0; i < 3; i++) { ++ av_freep(&s->plane[i].idwt_buf_base); ++ av_freep(&s->plane[i].idwt_tmp); ++ } ++ ++ av_freep(&s->sbsplit); ++ av_freep(&s->blmotion); ++ av_freep(&s->edge_emu_buffer_base); ++ ++ av_freep(&s->mctmp); ++ av_freep(&s->mcscratch); ++} ++ ++static av_cold int dirac_decode_init(AVCodecContext *avctx) ++{ ++ DiracContext *s = avctx->priv_data; ++ s->avctx = avctx; ++ s->frame_number = -1; ++ ++ if (avctx->flags&CODEC_FLAG_EMU_EDGE) { ++ av_log(avctx, AV_LOG_ERROR, "Edge emulation not supported!\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ dsputil_init(&s->dsp, avctx); ++ ff_diracdsp_init(&s->diracdsp); ++ ++ return 0; ++} ++ ++static void dirac_decode_flush(AVCodecContext *avctx) ++{ ++ DiracContext *s = avctx->priv_data; ++ free_sequence_buffers(s); ++ s->seen_sequence_header = 0; ++ s->frame_number = -1; ++} ++ ++static av_cold int dirac_decode_end(AVCodecContext *avctx) ++{ ++ dirac_decode_flush(avctx); ++ return 0; ++} ++ ++#define SIGN_CTX(x) (CTX_SIGN_ZERO + ((x) > 0) - ((x) < 0)) ++ ++static inline void coeff_unpack_arith(DiracArith *c, int qfactor, int qoffset, ++ SubBand *b, IDWTELEM *buf, int x, int y) ++{ ++ int coeff, sign; ++ int sign_pred = 0; ++ int pred_ctx = CTX_ZPZN_F1; ++ ++ /* Check if the parent subband has a 0 in the corresponding position */ ++ if (b->parent) ++ pred_ctx += !!b->parent->ibuf[b->parent->stride * (y>>1) + (x>>1)] << 1; ++ ++ if (b->orientation == subband_hl) ++ sign_pred = buf[-b->stride]; ++ ++ /* Determine if the pixel has only zeros in its neighbourhood */ ++ if (x) { ++ pred_ctx += !(buf[-1] | buf[-b->stride] | buf[-1-b->stride]); ++ if (b->orientation == subband_lh) ++ sign_pred = buf[-1]; ++ } else { ++ pred_ctx += !buf[-b->stride]; ++ } ++ ++ coeff = dirac_get_arith_uint(c, pred_ctx, CTX_COEFF_DATA); ++ if (coeff) { ++ coeff = (coeff * qfactor + qoffset + 2) >> 2; ++ sign = dirac_get_arith_bit(c, SIGN_CTX(sign_pred)); ++ coeff = (coeff ^ -sign) + sign; ++ } ++ *buf = coeff; ++} ++ ++static inline int coeff_unpack_golomb(GetBitContext *gb, int qfactor, int qoffset) ++{ ++ int sign, coeff; ++ ++ coeff = svq3_get_ue_golomb(gb); ++ if (coeff) { ++ coeff = (coeff * qfactor + qoffset + 2) >> 2; ++ sign = get_bits1(gb); ++ coeff = (coeff ^ -sign) + sign; ++ } ++ return coeff; ++} ++ ++/** ++ * Decode the coeffs in the rectangle defined by left, right, top, bottom ++ * [DIRAC_STD] 13.4.3.2 Codeblock unpacking loop. codeblock() ++ */ ++static inline void codeblock(DiracContext *s, SubBand *b, ++ GetBitContext *gb, DiracArith *c, ++ int left, int right, int top, int bottom, ++ int blockcnt_one, int is_arith) ++{ ++ int x, y, zero_block; ++ int qoffset, qfactor; ++ IDWTELEM *buf; ++ ++ /* check for any coded coefficients in this codeblock */ ++ if (!blockcnt_one) { ++ if (is_arith) ++ zero_block = dirac_get_arith_bit(c, CTX_ZERO_BLOCK); ++ else ++ zero_block = get_bits1(gb); ++ ++ if (zero_block) ++ return; ++ } ++ ++ if (s->codeblock_mode && !(s->old_delta_quant && blockcnt_one)) { ++ int quant = b->quant; ++ if (is_arith) ++ quant += dirac_get_arith_int(c, CTX_DELTA_Q_F, CTX_DELTA_Q_DATA); ++ else ++ quant += dirac_get_se_golomb(gb); ++ if (quant < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid quant\n"); ++ return; ++ } ++ b->quant = quant; ++ } ++ ++ b->quant = FFMIN(b->quant, MAX_QUANT); ++ ++ qfactor = qscale_tab[b->quant]; ++ /* TODO: context pointer? */ ++ if (!s->num_refs) ++ qoffset = qoffset_intra_tab[b->quant]; ++ else ++ qoffset = qoffset_inter_tab[b->quant]; ++ ++ buf = b->ibuf + top * b->stride; ++ for (y = top; y < bottom; y++) { ++ for (x = left; x < right; x++) { ++ /* [DIRAC_STD] 13.4.4 Subband coefficients. coeff_unpack() */ ++ if (is_arith) ++ coeff_unpack_arith(c, qfactor, qoffset, b, buf+x, x, y); ++ else ++ buf[x] = coeff_unpack_golomb(gb, qfactor, qoffset); ++ } ++ buf += b->stride; ++ } ++} ++ ++/** ++ * Dirac Specification -> ++ * 13.3 intra_dc_prediction(band) ++ */ ++static inline void intra_dc_prediction(SubBand *b) ++{ ++ IDWTELEM *buf = b->ibuf; ++ int x, y; ++ ++ for (x = 1; x < b->width; x++) ++ buf[x] += buf[x-1]; ++ buf += b->stride; ++ ++ for (y = 1; y < b->height; y++) { ++ buf[0] += buf[-b->stride]; ++ ++ for (x = 1; x < b->width; x++) { ++ int pred = buf[x - 1] + buf[x - b->stride] + buf[x - b->stride-1]; ++ buf[x] += divide3(pred); ++ } ++ buf += b->stride; ++ } ++} ++ ++/** ++ * Dirac Specification -> ++ * 13.4.2 Non-skipped subbands. subband_coeffs() ++ */ ++static av_always_inline void decode_subband_internal(DiracContext *s, SubBand *b, int is_arith) ++{ ++ int cb_x, cb_y, left, right, top, bottom; ++ DiracArith c; ++ GetBitContext gb; ++ int cb_width = s->codeblock[b->level + (b->orientation != subband_ll)].width; ++ int cb_height = s->codeblock[b->level + (b->orientation != subband_ll)].height; ++ int blockcnt_one = (cb_width + cb_height) == 2; ++ ++ if (!b->length) ++ return; ++ ++ init_get_bits(&gb, b->coeff_data, b->length*8); ++ ++ if (is_arith) ++ ff_dirac_init_arith_decoder(&c, &gb, b->length); ++ ++ top = 0; ++ for (cb_y = 0; cb_y < cb_height; cb_y++) { ++ bottom = (b->height * (cb_y+1)) / cb_height; ++ left = 0; ++ for (cb_x = 0; cb_x < cb_width; cb_x++) { ++ right = (b->width * (cb_x+1)) / cb_width; ++ codeblock(s, b, &gb, &c, left, right, top, bottom, blockcnt_one, is_arith); ++ left = right; ++ } ++ top = bottom; ++ } ++ ++ if (b->orientation == subband_ll && s->num_refs == 0) ++ intra_dc_prediction(b); ++} ++ ++static int decode_subband_arith(AVCodecContext *avctx, void *b) ++{ ++ DiracContext *s = avctx->priv_data; ++ decode_subband_internal(s, b, 1); ++ return 0; ++} ++ ++static int decode_subband_golomb(AVCodecContext *avctx, void *arg) ++{ ++ DiracContext *s = avctx->priv_data; ++ SubBand **b = arg; ++ decode_subband_internal(s, *b, 0); ++ return 0; ++} ++ ++/** ++ * Dirac Specification -> ++ * [DIRAC_STD] 13.4.1 core_transform_data() ++ */ ++static void decode_component(DiracContext *s, int comp) ++{ ++ AVCodecContext *avctx = s->avctx; ++ SubBand *bands[3*MAX_DWT_LEVELS+1]; ++ enum dirac_subband orientation; ++ int level, num_bands = 0; ++ ++ /* Unpack all subbands at all levels. */ ++ for (level = 0; level < s->wavelet_depth; level++) { ++ for (orientation = !!level; orientation < 4; orientation++) { ++ SubBand *b = &s->plane[comp].band[level][orientation]; ++ bands[num_bands++] = b; ++ ++ align_get_bits(&s->gb); ++ /* [DIRAC_STD] 13.4.2 subband() */ ++ b->length = svq3_get_ue_golomb(&s->gb); ++ if (b->length) { ++ b->quant = svq3_get_ue_golomb(&s->gb); ++ align_get_bits(&s->gb); ++ b->coeff_data = s->gb.buffer + get_bits_count(&s->gb)/8; ++ b->length = FFMIN(b->length, FFMAX(get_bits_left(&s->gb)/8, 0)); ++ skip_bits_long(&s->gb, b->length*8); ++ } ++ } ++ /* arithmetic coding has inter-level dependencies, so we can only execute one level at a time */ ++ if (s->is_arith) ++ avctx->execute(avctx, decode_subband_arith, &s->plane[comp].band[level][!!level], ++ NULL, 4-!!level, sizeof(SubBand)); ++ } ++ /* golomb coding has no inter-level dependencies, so we can execute all subbands in parallel */ ++ if (!s->is_arith) ++ avctx->execute(avctx, decode_subband_golomb, bands, NULL, num_bands, sizeof(SubBand*)); ++} ++ ++/* [DIRAC_STD] 13.5.5.2 Luma slice subband data. luma_slice_band(level,orient,sx,sy) --> if b2 == NULL */ ++/* [DIRAC_STD] 13.5.5.3 Chroma slice subband data. chroma_slice_band(level,orient,sx,sy) --> if b2 != NULL */ ++static void lowdelay_subband(DiracContext *s, GetBitContext *gb, int quant, ++ int slice_x, int slice_y, int bits_end, ++ SubBand *b1, SubBand *b2) ++{ ++ int left = b1->width * slice_x / s->lowdelay.num_x; ++ int right = b1->width *(slice_x+1) / s->lowdelay.num_x; ++ int top = b1->height * slice_y / s->lowdelay.num_y; ++ int bottom = b1->height *(slice_y+1) / s->lowdelay.num_y; ++ ++ int qfactor = qscale_tab[FFMIN(quant, MAX_QUANT)]; ++ int qoffset = qoffset_intra_tab[FFMIN(quant, MAX_QUANT)]; ++ ++ IDWTELEM *buf1 = b1->ibuf + top * b1->stride; ++ IDWTELEM *buf2 = b2 ? b2->ibuf + top * b2->stride : NULL; ++ int x, y; ++ /* we have to constantly check for overread since the spec explictly ++ requires this, with the meaning that all remaining coeffs are set to 0 */ ++ if (get_bits_count(gb) >= bits_end) ++ return; ++ ++ for (y = top; y < bottom; y++) { ++ for (x = left; x < right; x++) { ++ buf1[x] = coeff_unpack_golomb(gb, qfactor, qoffset); ++ if (get_bits_count(gb) >= bits_end) ++ return; ++ if (buf2) { ++ buf2[x] = coeff_unpack_golomb(gb, qfactor, qoffset); ++ if (get_bits_count(gb) >= bits_end) ++ return; ++ } ++ } ++ buf1 += b1->stride; ++ if (buf2) ++ buf2 += b2->stride; ++ } ++} ++ ++struct lowdelay_slice { ++ GetBitContext gb; ++ int slice_x; ++ int slice_y; ++ int bytes; ++}; ++ ++ ++/** ++ * Dirac Specification -> ++ * 13.5.2 Slices. slice(sx,sy) ++ */ ++static int decode_lowdelay_slice(AVCodecContext *avctx, void *arg) ++{ ++ DiracContext *s = avctx->priv_data; ++ struct lowdelay_slice *slice = arg; ++ GetBitContext *gb = &slice->gb; ++ enum dirac_subband orientation; ++ int level, quant, chroma_bits, chroma_end; ++ ++ int quant_base = get_bits(gb, 7); /*[DIRAC_STD] qindex */ ++ int length_bits = av_log2(8 * slice->bytes)+1; ++ int luma_bits = get_bits_long(gb, length_bits); ++ int luma_end = get_bits_count(gb) + FFMIN(luma_bits, get_bits_left(gb)); ++ ++ /* [DIRAC_STD] 13.5.5.2 luma_slice_band */ ++ for (level = 0; level < s->wavelet_depth; level++) ++ for (orientation = !!level; orientation < 4; orientation++) { ++ quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0); ++ lowdelay_subband(s, gb, quant, slice->slice_x, slice->slice_y, luma_end, ++ &s->plane[0].band[level][orientation], NULL); ++ } ++ ++ /* consume any unused bits from luma */ ++ skip_bits_long(gb, get_bits_count(gb) - luma_end); ++ ++ chroma_bits = 8*slice->bytes - 7 - length_bits - luma_bits; ++ chroma_end = get_bits_count(gb) + FFMIN(chroma_bits, get_bits_left(gb)); ++ /* [DIRAC_STD] 13.5.5.3 chroma_slice_band */ ++ for (level = 0; level < s->wavelet_depth; level++) ++ for (orientation = !!level; orientation < 4; orientation++) { ++ quant = FFMAX(quant_base - s->lowdelay.quant[level][orientation], 0); ++ lowdelay_subband(s, gb, quant, slice->slice_x, slice->slice_y, chroma_end, ++ &s->plane[1].band[level][orientation], ++ &s->plane[2].band[level][orientation]); ++ } ++ ++ return 0; ++} ++ ++/** ++ * Dirac Specification -> ++ * 13.5.1 low_delay_transform_data() ++ */ ++static void decode_lowdelay(DiracContext *s) ++{ ++ AVCodecContext *avctx = s->avctx; ++ int slice_x, slice_y, bytes, bufsize; ++ const uint8_t *buf; ++ struct lowdelay_slice *slices; ++ int slice_num = 0; ++ ++ slices = av_mallocz(s->lowdelay.num_x * s->lowdelay.num_y * sizeof(struct lowdelay_slice)); ++ ++ align_get_bits(&s->gb); ++ /*[DIRAC_STD] 13.5.2 Slices. slice(sx,sy) */ ++ buf = s->gb.buffer + get_bits_count(&s->gb)/8; ++ bufsize = get_bits_left(&s->gb); ++ ++ for (slice_y = 0; bufsize > 0 && slice_y < s->lowdelay.num_y; slice_y++) ++ for (slice_x = 0; bufsize > 0 && slice_x < s->lowdelay.num_x; slice_x++) { ++ bytes = (slice_num+1) * s->lowdelay.bytes.num / s->lowdelay.bytes.den ++ - slice_num * s->lowdelay.bytes.num / s->lowdelay.bytes.den; ++ ++ slices[slice_num].bytes = bytes; ++ slices[slice_num].slice_x = slice_x; ++ slices[slice_num].slice_y = slice_y; ++ init_get_bits(&slices[slice_num].gb, buf, bufsize); ++ slice_num++; ++ ++ buf += bytes; ++ bufsize -= bytes*8; ++ } ++ ++ avctx->execute(avctx, decode_lowdelay_slice, slices, NULL, slice_num, ++ sizeof(struct lowdelay_slice)); /* [DIRAC_STD] 13.5.2 Slices */ ++ intra_dc_prediction(&s->plane[0].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ ++ intra_dc_prediction(&s->plane[1].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ ++ intra_dc_prediction(&s->plane[2].band[0][0]); /* [DIRAC_STD] 13.3 intra_dc_prediction() */ ++ av_free(slices); ++} ++ ++static void init_planes(DiracContext *s) ++{ ++ int i, w, h, level, orientation; ++ ++ for (i = 0; i < 3; i++) { ++ Plane *p = &s->plane[i]; ++ ++ p->width = s->source.width >> (i ? s->chroma_x_shift : 0); ++ p->height = s->source.height >> (i ? s->chroma_y_shift : 0); ++ p->idwt_width = w = CALC_PADDING(p->width , s->wavelet_depth); ++ p->idwt_height = h = CALC_PADDING(p->height, s->wavelet_depth); ++ p->idwt_stride = FFALIGN(p->idwt_width, 8); ++ ++ for (level = s->wavelet_depth-1; level >= 0; level--) { ++ w = w>>1; ++ h = h>>1; ++ for (orientation = !!level; orientation < 4; orientation++) { ++ SubBand *b = &p->band[level][orientation]; ++ ++ b->ibuf = p->idwt_buf; ++ b->level = level; ++ b->stride = p->idwt_stride << (s->wavelet_depth - level); ++ b->width = w; ++ b->height = h; ++ b->orientation = orientation; ++ ++ if (orientation & 1) ++ b->ibuf += w; ++ if (orientation > 1) ++ b->ibuf += b->stride>>1; ++ ++ if (level) ++ b->parent = &p->band[level-1][orientation]; ++ } ++ } ++ ++ if (i > 0) { ++ p->xblen = s->plane[0].xblen >> s->chroma_x_shift; ++ p->yblen = s->plane[0].yblen >> s->chroma_y_shift; ++ p->xbsep = s->plane[0].xbsep >> s->chroma_x_shift; ++ p->ybsep = s->plane[0].ybsep >> s->chroma_y_shift; ++ } ++ ++ p->xoffset = (p->xblen - p->xbsep)/2; ++ p->yoffset = (p->yblen - p->ybsep)/2; ++ } ++} ++ ++/** ++ * Unpack the motion compensation parameters ++ * Dirac Specification -> ++ * 11.2 Picture prediction data. picture_prediction() ++ */ ++static int dirac_unpack_prediction_parameters(DiracContext *s) ++{ ++ static const uint8_t default_blen[] = { 4, 12, 16, 24 }; ++ static const uint8_t default_bsep[] = { 4, 8, 12, 16 }; ++ ++ GetBitContext *gb = &s->gb; ++ unsigned idx, ref; ++ ++ align_get_bits(gb); ++ /* [DIRAC_STD] 11.2.2 Block parameters. block_parameters() */ ++ /* Luma and Chroma are equal. 11.2.3 */ ++ idx = svq3_get_ue_golomb(gb); /* [DIRAC_STD] index */ ++ ++ if (idx > 4) { ++ av_log(s->avctx, AV_LOG_ERROR, "Block prediction index too high\n"); ++ return -1; ++ } ++ ++ if (idx == 0) { ++ s->plane[0].xblen = svq3_get_ue_golomb(gb); ++ s->plane[0].yblen = svq3_get_ue_golomb(gb); ++ s->plane[0].xbsep = svq3_get_ue_golomb(gb); ++ s->plane[0].ybsep = svq3_get_ue_golomb(gb); ++ } else { ++ /*[DIRAC_STD] preset_block_params(index). Table 11.1 */ ++ s->plane[0].xblen = default_blen[idx-1]; ++ s->plane[0].yblen = default_blen[idx-1]; ++ s->plane[0].xbsep = default_bsep[idx-1]; ++ s->plane[0].ybsep = default_bsep[idx-1]; ++ } ++ /*[DIRAC_STD] 11.2.4 motion_data_dimensions() ++ Calculated in function dirac_unpack_block_motion_data */ ++ ++ if (s->plane[0].xbsep < s->plane[0].xblen/2 || s->plane[0].ybsep < s->plane[0].yblen/2) { ++ av_log(s->avctx, AV_LOG_ERROR, "Block separation too small\n"); ++ return -1; ++ } ++ if (s->plane[0].xbsep > s->plane[0].xblen || s->plane[0].ybsep > s->plane[0].yblen) { ++ av_log(s->avctx, AV_LOG_ERROR, "Block seperation greater than size\n"); ++ return -1; ++ } ++ if (FFMAX(s->plane[0].xblen, s->plane[0].yblen) > MAX_BLOCKSIZE) { ++ av_log(s->avctx, AV_LOG_ERROR, "Unsupported large block size\n"); ++ return -1; ++ } ++ ++ /*[DIRAC_STD] 11.2.5 Motion vector precision. motion_vector_precision() ++ Read motion vector precision */ ++ s->mv_precision = svq3_get_ue_golomb(gb); ++ if (s->mv_precision > 3) { ++ av_log(s->avctx, AV_LOG_ERROR, "MV precision finer than eighth-pel\n"); ++ return -1; ++ } ++ ++ /*[DIRAC_STD] 11.2.6 Global motion. global_motion() ++ Read the global motion compensation parameters */ ++ s->globalmc_flag = get_bits1(gb); ++ if (s->globalmc_flag) { ++ memset(s->globalmc, 0, sizeof(s->globalmc)); ++ /* [DIRAC_STD] pan_tilt(gparams) */ ++ for (ref = 0; ref < s->num_refs; ref++) { ++ if (get_bits1(gb)) { ++ s->globalmc[ref].pan_tilt[0] = dirac_get_se_golomb(gb); ++ s->globalmc[ref].pan_tilt[1] = dirac_get_se_golomb(gb); ++ } ++ /* [DIRAC_STD] zoom_rotate_shear(gparams) ++ zoom/rotation/shear parameters */ ++ if (get_bits1(gb)) { ++ s->globalmc[ref].zrs_exp = svq3_get_ue_golomb(gb); ++ s->globalmc[ref].zrs[0][0] = dirac_get_se_golomb(gb); ++ s->globalmc[ref].zrs[0][1] = dirac_get_se_golomb(gb); ++ s->globalmc[ref].zrs[1][0] = dirac_get_se_golomb(gb); ++ s->globalmc[ref].zrs[1][1] = dirac_get_se_golomb(gb); ++ } else { ++ s->globalmc[ref].zrs[0][0] = 1; ++ s->globalmc[ref].zrs[1][1] = 1; ++ } ++ /* [DIRAC_STD] perspective(gparams) */ ++ if (get_bits1(gb)) { ++ s->globalmc[ref].perspective_exp = svq3_get_ue_golomb(gb); ++ s->globalmc[ref].perspective[0] = dirac_get_se_golomb(gb); ++ s->globalmc[ref].perspective[1] = dirac_get_se_golomb(gb); ++ } ++ } ++ } ++ ++ /*[DIRAC_STD] 11.2.7 Picture prediction mode. prediction_mode() ++ Picture prediction mode, not currently used. */ ++ if (svq3_get_ue_golomb(gb)) { ++ av_log(s->avctx, AV_LOG_ERROR, "Unknown picture prediction mode\n"); ++ return -1; ++ } ++ ++ /* [DIRAC_STD] 11.2.8 Reference picture weight. reference_picture_weights() ++ just data read, weight calculation will be done later on. */ ++ s->weight_log2denom = 1; ++ s->weight[0] = 1; ++ s->weight[1] = 1; ++ ++ if (get_bits1(gb)) { ++ s->weight_log2denom = svq3_get_ue_golomb(gb); ++ s->weight[0] = dirac_get_se_golomb(gb); ++ if (s->num_refs == 2) ++ s->weight[1] = dirac_get_se_golomb(gb); ++ } ++ return 0; ++} ++ ++/** ++ * Dirac Specification -> ++ * 11.3 Wavelet transform data. wavelet_transform() ++ */ ++static int dirac_unpack_idwt_params(DiracContext *s) ++{ ++ GetBitContext *gb = &s->gb; ++ int i, level; ++ unsigned tmp; ++ ++#define CHECKEDREAD(dst, cond, errmsg) \ ++ tmp = svq3_get_ue_golomb(gb); \ ++ if (cond) { \ ++ av_log(s->avctx, AV_LOG_ERROR, errmsg); \ ++ return -1; \ ++ }\ ++ dst = tmp; ++ ++ align_get_bits(gb); ++ ++ s->zero_res = s->num_refs ? get_bits1(gb) : 0; ++ if (s->zero_res) ++ return 0; ++ ++ /*[DIRAC_STD] 11.3.1 Transform parameters. transform_parameters() */ ++ CHECKEDREAD(s->wavelet_idx, tmp > 6, "wavelet_idx is too big\n") ++ ++ CHECKEDREAD(s->wavelet_depth, tmp > MAX_DWT_LEVELS || tmp < 1, "invalid number of DWT decompositions\n") ++ ++ if (!s->low_delay) { ++ /* Codeblock paramaters (core syntax only) */ ++ if (get_bits1(gb)) { ++ for (i = 0; i <= s->wavelet_depth; i++) { ++ CHECKEDREAD(s->codeblock[i].width , tmp < 1, "codeblock width invalid\n") ++ CHECKEDREAD(s->codeblock[i].height, tmp < 1, "codeblock height invalid\n") ++ } ++ ++ CHECKEDREAD(s->codeblock_mode, tmp > 1, "unknown codeblock mode\n") ++ } else ++ for (i = 0; i <= s->wavelet_depth; i++) ++ s->codeblock[i].width = s->codeblock[i].height = 1; ++ } else { ++ /* Slice parameters + quantization matrix*/ ++ /*[DIRAC_STD] 11.3.4 Slice coding Parameters (low delay syntax only). slice_parameters() */ ++ s->lowdelay.num_x = svq3_get_ue_golomb(gb); ++ s->lowdelay.num_y = svq3_get_ue_golomb(gb); ++ s->lowdelay.bytes.num = svq3_get_ue_golomb(gb); ++ s->lowdelay.bytes.den = svq3_get_ue_golomb(gb); ++ ++ /* [DIRAC_STD] 11.3.5 Quantisation matrices (low-delay syntax). quant_matrix() */ ++ if (get_bits1(gb)) { ++ av_log(s->avctx,AV_LOG_DEBUG,"Low Delay: Has Custom Quantization Matrix!\n"); ++ /* custom quantization matrix */ ++ s->lowdelay.quant[0][0] = svq3_get_ue_golomb(gb); ++ for (level = 0; level < s->wavelet_depth; level++) { ++ s->lowdelay.quant[level][1] = svq3_get_ue_golomb(gb); ++ s->lowdelay.quant[level][2] = svq3_get_ue_golomb(gb); ++ s->lowdelay.quant[level][3] = svq3_get_ue_golomb(gb); ++ } ++ } else { ++ /* default quantization matrix */ ++ for (level = 0; level < s->wavelet_depth; level++) ++ for (i = 0; i < 4; i++) { ++ s->lowdelay.quant[level][i] = default_qmat[s->wavelet_idx][level][i]; ++ /* haar with no shift differs for different depths */ ++ if (s->wavelet_idx == 3) ++ s->lowdelay.quant[level][i] += 4*(s->wavelet_depth-1 - level); ++ } ++ } ++ } ++ return 0; ++} ++ ++static inline int pred_sbsplit(uint8_t *sbsplit, int stride, int x, int y) ++{ ++ static const uint8_t avgsplit[7] = { 0, 0, 1, 1, 1, 2, 2 }; ++ ++ if (!(x|y)) ++ return 0; ++ else if (!y) ++ return sbsplit[-1]; ++ else if (!x) ++ return sbsplit[-stride]; ++ ++ return avgsplit[sbsplit[-1] + sbsplit[-stride] + sbsplit[-stride-1]]; ++} ++ ++static inline int pred_block_mode(DiracBlock *block, int stride, int x, int y, int refmask) ++{ ++ int pred; ++ ++ if (!(x|y)) ++ return 0; ++ else if (!y) ++ return block[-1].ref & refmask; ++ else if (!x) ++ return block[-stride].ref & refmask; ++ ++ /* return the majority */ ++ pred = (block[-1].ref & refmask) + (block[-stride].ref & refmask) + (block[-stride-1].ref & refmask); ++ return (pred >> 1) & refmask; ++} ++ ++static inline void pred_block_dc(DiracBlock *block, int stride, int x, int y) ++{ ++ int i, n = 0; ++ ++ memset(block->u.dc, 0, sizeof(block->u.dc)); ++ ++ if (x && !(block[-1].ref & 3)) { ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] += block[-1].u.dc[i]; ++ n++; ++ } ++ ++ if (y && !(block[-stride].ref & 3)) { ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] += block[-stride].u.dc[i]; ++ n++; ++ } ++ ++ if (x && y && !(block[-1-stride].ref & 3)) { ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] += block[-1-stride].u.dc[i]; ++ n++; ++ } ++ ++ if (n == 2) { ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] = (block->u.dc[i]+1)>>1; ++ } else if (n == 3) { ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] = divide3(block->u.dc[i]); ++ } ++} ++ ++static inline void pred_mv(DiracBlock *block, int stride, int x, int y, int ref) ++{ ++ int16_t *pred[3]; ++ int refmask = ref+1; ++ int mask = refmask | DIRAC_REF_MASK_GLOBAL; /* exclude gmc blocks */ ++ int n = 0; ++ ++ if (x && (block[-1].ref & mask) == refmask) ++ pred[n++] = block[-1].u.mv[ref]; ++ ++ if (y && (block[-stride].ref & mask) == refmask) ++ pred[n++] = block[-stride].u.mv[ref]; ++ ++ if (x && y && (block[-stride-1].ref & mask) == refmask) ++ pred[n++] = block[-stride-1].u.mv[ref]; ++ ++ switch (n) { ++ case 0: ++ block->u.mv[ref][0] = 0; ++ block->u.mv[ref][1] = 0; ++ break; ++ case 1: ++ block->u.mv[ref][0] = pred[0][0]; ++ block->u.mv[ref][1] = pred[0][1]; ++ break; ++ case 2: ++ block->u.mv[ref][0] = (pred[0][0] + pred[1][0] + 1) >> 1; ++ block->u.mv[ref][1] = (pred[0][1] + pred[1][1] + 1) >> 1; ++ break; ++ case 3: ++ block->u.mv[ref][0] = mid_pred(pred[0][0], pred[1][0], pred[2][0]); ++ block->u.mv[ref][1] = mid_pred(pred[0][1], pred[1][1], pred[2][1]); ++ break; ++ } ++} ++ ++static void global_mv(DiracContext *s, DiracBlock *block, int x, int y, int ref) ++{ ++ int ez = s->globalmc[ref].zrs_exp; ++ int ep = s->globalmc[ref].perspective_exp; ++ int (*A)[2] = s->globalmc[ref].zrs; ++ int *b = s->globalmc[ref].pan_tilt; ++ int *c = s->globalmc[ref].perspective; ++ ++ int m = (1<u.mv[ref][0] = (mx + (1<<(ez+ep))) >> (ez+ep); ++ block->u.mv[ref][1] = (my + (1<<(ez+ep))) >> (ez+ep); ++} ++ ++static void decode_block_params(DiracContext *s, DiracArith arith[8], DiracBlock *block, ++ int stride, int x, int y) ++{ ++ int i; ++ ++ block->ref = pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF1); ++ block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF1); ++ ++ if (s->num_refs == 2) { ++ block->ref |= pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_REF2); ++ block->ref ^= dirac_get_arith_bit(arith, CTX_PMODE_REF2) << 1; ++ } ++ ++ if (!block->ref) { ++ pred_block_dc(block, stride, x, y); ++ for (i = 0; i < 3; i++) ++ block->u.dc[i] += dirac_get_arith_int(arith+1+i, CTX_DC_F1, CTX_DC_DATA); ++ return; ++ } ++ ++ if (s->globalmc_flag) { ++ block->ref |= pred_block_mode(block, stride, x, y, DIRAC_REF_MASK_GLOBAL); ++ block->ref ^= dirac_get_arith_bit(arith, CTX_GLOBAL_BLOCK) << 2; ++ } ++ ++ for (i = 0; i < s->num_refs; i++) ++ if (block->ref & (i+1)) { ++ if (block->ref & DIRAC_REF_MASK_GLOBAL) { ++ global_mv(s, block, x, y, i); ++ } else { ++ pred_mv(block, stride, x, y, i); ++ block->u.mv[i][0] += dirac_get_arith_int(arith + 4 + 2 * i, CTX_MV_F1, CTX_MV_DATA); ++ block->u.mv[i][1] += dirac_get_arith_int(arith + 5 + 2 * i, CTX_MV_F1, CTX_MV_DATA); ++ } ++ } ++} ++ ++/** ++ * Copies the current block to the other blocks covered by the current superblock split mode ++ */ ++static void propagate_block_data(DiracBlock *block, int stride, int size) ++{ ++ int x, y; ++ DiracBlock *dst = block; ++ ++ for (x = 1; x < size; x++) ++ dst[x] = *block; ++ ++ for (y = 1; y < size; y++) { ++ dst += stride; ++ for (x = 0; x < size; x++) ++ dst[x] = *block; ++ } ++} ++ ++/** ++ * Dirac Specification -> ++ * 12. Block motion data syntax ++ */ ++static int dirac_unpack_block_motion_data(DiracContext *s) ++{ ++ GetBitContext *gb = &s->gb; ++ uint8_t *sbsplit = s->sbsplit; ++ int i, x, y, q, p; ++ DiracArith arith[8]; ++ ++ align_get_bits(gb); ++ ++ /* [DIRAC_STD] 11.2.4 and 12.2.1 Number of blocks and superblocks */ ++ s->sbwidth = DIVRNDUP(s->source.width, 4*s->plane[0].xbsep); ++ s->sbheight = DIVRNDUP(s->source.height, 4*s->plane[0].ybsep); ++ s->blwidth = 4 * s->sbwidth; ++ s->blheight = 4 * s->sbheight; ++ ++ /* [DIRAC_STD] 12.3.1 Superblock splitting modes. superblock_split_modes() ++ decode superblock split modes */ ++ ff_dirac_init_arith_decoder(arith, gb, svq3_get_ue_golomb(gb)); /* svq3_get_ue_golomb(gb) is the length */ ++ for (y = 0; y < s->sbheight; y++) { ++ for (x = 0; x < s->sbwidth; x++) { ++ unsigned int split = dirac_get_arith_uint(arith, CTX_SB_F1, CTX_SB_DATA); ++ if (split > 2) ++ return -1; ++ sbsplit[x] = (split + pred_sbsplit(sbsplit+x, s->sbwidth, x, y)) % 3; ++ } ++ sbsplit += s->sbwidth; ++ } ++ ++ /* setup arith decoding */ ++ ff_dirac_init_arith_decoder(arith, gb, svq3_get_ue_golomb(gb)); ++ for (i = 0; i < s->num_refs; i++) { ++ ff_dirac_init_arith_decoder(arith + 4 + 2 * i, gb, svq3_get_ue_golomb(gb)); ++ ff_dirac_init_arith_decoder(arith + 5 + 2 * i, gb, svq3_get_ue_golomb(gb)); ++ } ++ for (i = 0; i < 3; i++) ++ ff_dirac_init_arith_decoder(arith+1+i, gb, svq3_get_ue_golomb(gb)); ++ ++ for (y = 0; y < s->sbheight; y++) ++ for (x = 0; x < s->sbwidth; x++) { ++ int blkcnt = 1 << s->sbsplit[y * s->sbwidth + x]; ++ int step = 4 >> s->sbsplit[y * s->sbwidth + x]; ++ ++ for (q = 0; q < blkcnt; q++) ++ for (p = 0; p < blkcnt; p++) { ++ int bx = 4 * x + p*step; ++ int by = 4 * y + q*step; ++ DiracBlock *block = &s->blmotion[by*s->blwidth + bx]; ++ decode_block_params(s, arith, block, s->blwidth, bx, by); ++ propagate_block_data(block, s->blwidth, step); ++ } ++ } ++ ++ return 0; ++} ++ ++static int weight(int i, int blen, int offset) ++{ ++#define ROLLOFF(i) offset == 1 ? ((i) ? 5 : 3) : \ ++ (1 + (6*(i) + offset - 1) / (2*offset - 1)) ++ ++ if (i < 2*offset) ++ return ROLLOFF(i); ++ else if (i > blen-1 - 2*offset) ++ return ROLLOFF(blen-1 - i); ++ return 8; ++} ++ ++static void init_obmc_weight_row(Plane *p, uint8_t *obmc_weight, int stride, ++ int left, int right, int wy) ++{ ++ int x; ++ for (x = 0; left && x < p->xblen >> 1; x++) ++ obmc_weight[x] = wy*8; ++ for (; x < p->xblen >> right; x++) ++ obmc_weight[x] = wy*weight(x, p->xblen, p->xoffset); ++ for (; x < p->xblen; x++) ++ obmc_weight[x] = wy*8; ++ for (; x < stride; x++) ++ obmc_weight[x] = 0; ++} ++ ++static void init_obmc_weight(Plane *p, uint8_t *obmc_weight, int stride, ++ int left, int right, int top, int bottom) ++{ ++ int y; ++ for (y = 0; top && y < p->yblen >> 1; y++) { ++ init_obmc_weight_row(p, obmc_weight, stride, left, right, 8); ++ obmc_weight += stride; ++ } ++ for (; y < p->yblen >> bottom; y++) { ++ int wy = weight(y, p->yblen, p->yoffset); ++ init_obmc_weight_row(p, obmc_weight, stride, left, right, wy); ++ obmc_weight += stride; ++ } ++ for (; y < p->yblen; y++) { ++ init_obmc_weight_row(p, obmc_weight, stride, left, right, 8); ++ obmc_weight += stride; ++ } ++} ++ ++static void init_obmc_weights(DiracContext *s, Plane *p, int by) ++{ ++ int top = !by; ++ int bottom = by == s->blheight-1; ++ ++ /* don't bother re-initing for rows 2 to blheight-2, the weights don't change */ ++ if (top || bottom || by == 1) { ++ init_obmc_weight(p, s->obmc_weight[0], MAX_BLOCKSIZE, 1, 0, top, bottom); ++ init_obmc_weight(p, s->obmc_weight[1], MAX_BLOCKSIZE, 0, 0, top, bottom); ++ init_obmc_weight(p, s->obmc_weight[2], MAX_BLOCKSIZE, 0, 1, top, bottom); ++ } ++} ++ ++static const uint8_t epel_weights[4][4][4] = { ++ {{ 16, 0, 0, 0 }, ++ { 12, 4, 0, 0 }, ++ { 8, 8, 0, 0 }, ++ { 4, 12, 0, 0 }}, ++ {{ 12, 0, 4, 0 }, ++ { 9, 3, 3, 1 }, ++ { 6, 6, 2, 2 }, ++ { 3, 9, 1, 3 }}, ++ {{ 8, 0, 8, 0 }, ++ { 6, 2, 6, 2 }, ++ { 4, 4, 4, 4 }, ++ { 2, 6, 2, 6 }}, ++ {{ 4, 0, 12, 0 }, ++ { 3, 1, 9, 3 }, ++ { 2, 2, 6, 6 }, ++ { 1, 3, 3, 9 }} ++}; ++ ++/** ++ * For block x,y, determine which of the hpel planes to do bilinear ++ * interpolation from and set src[] to the location in each hpel plane ++ * to MC from. ++ * ++ * @return the index of the put_dirac_pixels_tab function to use ++ * 0 for 1 plane (fpel,hpel), 1 for 2 planes (qpel), 2 for 4 planes (qpel), and 3 for epel ++ */ ++static int mc_subpel(DiracContext *s, DiracBlock *block, const uint8_t *src[5], ++ int x, int y, int ref, int plane) ++{ ++ Plane *p = &s->plane[plane]; ++ uint8_t **ref_hpel = s->ref_pics[ref]->hpel[plane]; ++ int motion_x = block->u.mv[ref][0]; ++ int motion_y = block->u.mv[ref][1]; ++ int mx, my, i, epel, nplanes = 0; ++ ++ if (plane) { ++ motion_x >>= s->chroma_x_shift; ++ motion_y >>= s->chroma_y_shift; ++ } ++ ++ mx = motion_x & ~(-1 << s->mv_precision); ++ my = motion_y & ~(-1 << s->mv_precision); ++ motion_x >>= s->mv_precision; ++ motion_y >>= s->mv_precision; ++ /* normalize subpel coordinates to epel */ ++ /* TODO: template this function? */ ++ mx <<= 3 - s->mv_precision; ++ my <<= 3 - s->mv_precision; ++ ++ x += motion_x; ++ y += motion_y; ++ epel = (mx|my)&1; ++ ++ /* hpel position */ ++ if (!((mx|my)&3)) { ++ nplanes = 1; ++ src[0] = ref_hpel[(my>>1)+(mx>>2)] + y*p->stride + x; ++ } else { ++ /* qpel or epel */ ++ nplanes = 4; ++ for (i = 0; i < 4; i++) ++ src[i] = ref_hpel[i] + y*p->stride + x; ++ ++ /* if we're interpolating in the right/bottom halves, adjust the planes as needed ++ we increment x/y because the edge changes for half of the pixels */ ++ if (mx > 4) { ++ src[0] += 1; ++ src[2] += 1; ++ x++; ++ } ++ if (my > 4) { ++ src[0] += p->stride; ++ src[1] += p->stride; ++ y++; ++ } ++ ++ /* hpel planes are: ++ [0]: F [1]: H ++ [2]: V [3]: C */ ++ if (!epel) { ++ /* check if we really only need 2 planes since either mx or my is ++ a hpel position. (epel weights of 0 handle this there) */ ++ if (!(mx&3)) { ++ /* mx == 0: average [0] and [2] ++ mx == 4: average [1] and [3] */ ++ src[!mx] = src[2 + !!mx]; ++ nplanes = 2; ++ } else if (!(my&3)) { ++ src[0] = src[(my>>1) ]; ++ src[1] = src[(my>>1)+1]; ++ nplanes = 2; ++ } ++ } else { ++ /* adjust the ordering if needed so the weights work */ ++ if (mx > 4) { ++ FFSWAP(const uint8_t *, src[0], src[1]); ++ FFSWAP(const uint8_t *, src[2], src[3]); ++ } ++ if (my > 4) { ++ FFSWAP(const uint8_t *, src[0], src[2]); ++ FFSWAP(const uint8_t *, src[1], src[3]); ++ } ++ src[4] = epel_weights[my&3][mx&3]; ++ } ++ } ++ ++ /* fixme: v/h _edge_pos */ ++ if ((unsigned)x > p->width +EDGE_WIDTH/2 - p->xblen || ++ (unsigned)y > p->height+EDGE_WIDTH/2 - p->yblen) { ++ for (i = 0; i < nplanes; i++) { ++ ff_emulated_edge_mc(s->edge_emu_buffer[i], src[i], p->stride, ++ p->xblen, p->yblen, x, y, ++ p->width+EDGE_WIDTH/2, p->height+EDGE_WIDTH/2); ++ src[i] = s->edge_emu_buffer[i]; ++ } ++ } ++ return (nplanes>>1) + epel; ++} ++ ++static void add_dc(uint16_t *dst, int dc, int stride, ++ uint8_t *obmc_weight, int xblen, int yblen) ++{ ++ int x, y; ++ dc += 128; ++ ++ for (y = 0; y < yblen; y++) { ++ for (x = 0; x < xblen; x += 2) { ++ dst[x ] += dc * obmc_weight[x ]; ++ dst[x+1] += dc * obmc_weight[x+1]; ++ } ++ dst += stride; ++ obmc_weight += MAX_BLOCKSIZE; ++ } ++} ++ ++static void block_mc(DiracContext *s, DiracBlock *block, ++ uint16_t *mctmp, uint8_t *obmc_weight, ++ int plane, int dstx, int dsty) ++{ ++ Plane *p = &s->plane[plane]; ++ const uint8_t *src[5]; ++ int idx; ++ ++ switch (block->ref&3) { ++ case 0: /* DC */ ++ add_dc(mctmp, block->u.dc[plane], p->stride, obmc_weight, p->xblen, p->yblen); ++ return; ++ case 1: ++ case 2: ++ idx = mc_subpel(s, block, src, dstx, dsty, (block->ref&3)-1, plane); ++ s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); ++ if (s->weight_func) ++ s->weight_func(s->mcscratch, p->stride, s->weight_log2denom, ++ s->weight[0] + s->weight[1], p->yblen); ++ break; ++ case 3: ++ idx = mc_subpel(s, block, src, dstx, dsty, 0, plane); ++ s->put_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); ++ idx = mc_subpel(s, block, src, dstx, dsty, 1, plane); ++ if (s->biweight_func) { ++ /* fixme: +32 is a quick hack */ ++ s->put_pixels_tab[idx](s->mcscratch + 32, src, p->stride, p->yblen); ++ s->biweight_func(s->mcscratch, s->mcscratch+32, p->stride, s->weight_log2denom, ++ s->weight[0], s->weight[1], p->yblen); ++ } else ++ s->avg_pixels_tab[idx](s->mcscratch, src, p->stride, p->yblen); ++ break; ++ } ++ s->add_obmc(mctmp, s->mcscratch, p->stride, obmc_weight, p->yblen); ++} ++ ++static void mc_row(DiracContext *s, DiracBlock *block, uint16_t *mctmp, int plane, int dsty) ++{ ++ Plane *p = &s->plane[plane]; ++ int x, dstx = p->xbsep - p->xoffset; ++ ++ block_mc(s, block, mctmp, s->obmc_weight[0], plane, -p->xoffset, dsty); ++ mctmp += p->xbsep; ++ ++ for (x = 1; x < s->blwidth-1; x++) { ++ block_mc(s, block+x, mctmp, s->obmc_weight[1], plane, dstx, dsty); ++ dstx += p->xbsep; ++ mctmp += p->xbsep; ++ } ++ block_mc(s, block+x, mctmp, s->obmc_weight[2], plane, dstx, dsty); ++} ++ ++static void select_dsp_funcs(DiracContext *s, int width, int height, int xblen, int yblen) ++{ ++ int idx = 0; ++ if (xblen > 8) ++ idx = 1; ++ if (xblen > 16) ++ idx = 2; ++ ++ memcpy(s->put_pixels_tab, s->diracdsp.put_dirac_pixels_tab[idx], sizeof(s->put_pixels_tab)); ++ memcpy(s->avg_pixels_tab, s->diracdsp.avg_dirac_pixels_tab[idx], sizeof(s->avg_pixels_tab)); ++ s->add_obmc = s->diracdsp.add_dirac_obmc[idx]; ++ if (s->weight_log2denom > 1 || s->weight[0] != 1 || s->weight[1] != 1) { ++ s->weight_func = s->diracdsp.weight_dirac_pixels_tab[idx]; ++ s->biweight_func = s->diracdsp.biweight_dirac_pixels_tab[idx]; ++ } else { ++ s->weight_func = NULL; ++ s->biweight_func = NULL; ++ } ++} ++ ++static void interpolate_refplane(DiracContext *s, DiracFrame *ref, int plane, int width, int height) ++{ ++ /* chroma allocates an edge of 8 when subsampled ++ which for 4:2:2 means an h edge of 16 and v edge of 8 ++ just use 8 for everything for the moment */ ++ int i, edge = EDGE_WIDTH/2; ++ ++ ref->hpel[plane][0] = ref->avframe.data[plane]; ++ s->dsp.draw_edges(ref->hpel[plane][0], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); /* EDGE_TOP | EDGE_BOTTOM values just copied to make it build, this needs to be ensured */ ++ ++ /* no need for hpel if we only have fpel vectors */ ++ if (!s->mv_precision) ++ return; ++ ++ for (i = 1; i < 4; i++) { ++ if (!ref->hpel_base[plane][i]) ++ ref->hpel_base[plane][i] = av_malloc((height+2*edge) * ref->avframe.linesize[plane] + 32); ++ /* we need to be 16-byte aligned even for chroma */ ++ ref->hpel[plane][i] = ref->hpel_base[plane][i] + edge*ref->avframe.linesize[plane] + 16; ++ } ++ ++ if (!ref->interpolated[plane]) { ++ s->diracdsp.dirac_hpel_filter(ref->hpel[plane][1], ref->hpel[plane][2], ++ ref->hpel[plane][3], ref->hpel[plane][0], ++ ref->avframe.linesize[plane], width, height); ++ s->dsp.draw_edges(ref->hpel[plane][1], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(ref->hpel[plane][2], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(ref->hpel[plane][3], ref->avframe.linesize[plane], width, height, edge, edge, EDGE_TOP | EDGE_BOTTOM); ++ } ++ ref->interpolated[plane] = 1; ++} ++ ++/** ++ * Dirac Specification -> ++ * 13.0 Transform data syntax. transform_data() ++ */ ++static int dirac_decode_frame_internal(DiracContext *s) ++{ ++ DWTContext d; ++ int y, i, comp, dsty; ++ ++ if (s->low_delay) { ++ /* [DIRAC_STD] 13.5.1 low_delay_transform_data() */ ++ for (comp = 0; comp < 3; comp++) { ++ Plane *p = &s->plane[comp]; ++ memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM)); ++ } ++ if (!s->zero_res) ++ decode_lowdelay(s); ++ } ++ ++ for (comp = 0; comp < 3; comp++) { ++ Plane *p = &s->plane[comp]; ++ uint8_t *frame = s->current_picture->avframe.data[comp]; ++ ++ /* FIXME: small resolutions */ ++ for (i = 0; i < 4; i++) ++ s->edge_emu_buffer[i] = s->edge_emu_buffer_base + i*FFALIGN(p->width, 16); ++ ++ if (!s->zero_res && !s->low_delay) ++ { ++ memset(p->idwt_buf, 0, p->idwt_stride * p->idwt_height * sizeof(IDWTELEM)); ++ decode_component(s, comp); /* [DIRAC_STD] 13.4.1 core_transform_data() */ ++ } ++ if (ff_spatial_idwt_init2(&d, p->idwt_buf, p->idwt_width, p->idwt_height, p->idwt_stride, ++ s->wavelet_idx+2, s->wavelet_depth, p->idwt_tmp)) ++ return -1; ++ ++ if (!s->num_refs) { /* intra */ ++ for (y = 0; y < p->height; y += 16) { ++ ff_spatial_idwt_slice2(&d, y+16); /* decode */ ++ s->diracdsp.put_signed_rect_clamped(frame + y*p->stride, p->stride, ++ p->idwt_buf + y*p->idwt_stride, p->idwt_stride, p->width, 16); ++ } ++ } else { /* inter */ ++ int rowheight = p->ybsep*p->stride; ++ ++ select_dsp_funcs(s, p->width, p->height, p->xblen, p->yblen); ++ ++ for (i = 0; i < s->num_refs; i++) ++ interpolate_refplane(s, s->ref_pics[i], comp, p->width, p->height); ++ ++ memset(s->mctmp, 0, 4*p->yoffset*p->stride); ++ ++ dsty = -p->yoffset; ++ for (y = 0; y < s->blheight; y++) { ++ int h = 0, ++ start = FFMAX(dsty, 0); ++ uint16_t *mctmp = s->mctmp + y*rowheight; ++ DiracBlock *blocks = s->blmotion + y*s->blwidth; ++ ++ init_obmc_weights(s, p, y); ++ ++ if (y == s->blheight-1 || start+p->ybsep > p->height) ++ h = p->height - start; ++ else ++ h = p->ybsep - (start - dsty); ++ if (h < 0) ++ break; ++ ++ memset(mctmp+2*p->yoffset*p->stride, 0, 2*rowheight); ++ mc_row(s, blocks, mctmp, comp, dsty); ++ ++ mctmp += (start - dsty)*p->stride + p->xoffset; ++ ff_spatial_idwt_slice2(&d, start + h); /* decode */ ++ s->diracdsp.add_rect_clamped(frame + start*p->stride, mctmp, p->stride, ++ p->idwt_buf + start*p->idwt_stride, p->idwt_stride, p->width, h); ++ ++ dsty += p->ybsep; ++ } ++ } ++ } ++ ++ ++ return 0; ++} ++ ++/** ++ * Dirac Specification -> ++ * 11.1.1 Picture Header. picture_header() ++ */ ++static int dirac_decode_picture_header(DiracContext *s) ++{ ++ int retire, picnum; ++ int i, j, refnum, refdist; ++ GetBitContext *gb = &s->gb; ++ ++ /* [DIRAC_STD] 11.1.1 Picture Header. picture_header() PICTURE_NUM */ ++ picnum = s->current_picture->avframe.display_picture_number = get_bits_long(gb, 32); ++ ++ ++ av_log(s->avctx,AV_LOG_DEBUG,"PICTURE_NUM: %d\n",picnum); ++ ++ /* if this is the first keyframe after a sequence header, start our ++ reordering from here */ ++ if (s->frame_number < 0) ++ s->frame_number = picnum; ++ ++ s->ref_pics[0] = s->ref_pics[1] = NULL; ++ for (i = 0; i < s->num_refs; i++) { ++ refnum = picnum + dirac_get_se_golomb(gb); ++ refdist = INT_MAX; ++ ++ /* find the closest reference to the one we want */ ++ /* Jordi: this is needed if the referenced picture hasn't yet arrived */ ++ for (j = 0; j < MAX_REFERENCE_FRAMES && refdist; j++) ++ if (s->ref_frames[j] ++ && FFABS(s->ref_frames[j]->avframe.display_picture_number - refnum) < refdist) { ++ s->ref_pics[i] = s->ref_frames[j]; ++ refdist = FFABS(s->ref_frames[j]->avframe.display_picture_number - refnum); ++ } ++ ++ if (!s->ref_pics[i] || refdist) ++ av_log(s->avctx, AV_LOG_DEBUG, "Reference not found\n"); ++ ++ /* if there were no references at all, allocate one */ ++ if (!s->ref_pics[i]) ++ for (j = 0; j < MAX_FRAMES; j++) ++ if (!s->all_frames[j].avframe.data[0]) { ++ s->ref_pics[i] = &s->all_frames[j]; ++ s->avctx->get_buffer(s->avctx, &s->ref_pics[i]->avframe); ++ } ++ } ++ ++ /* retire the reference frames that are not used anymore */ ++ if (s->current_picture->avframe.reference) { ++ retire = picnum + dirac_get_se_golomb(gb); ++ if (retire != picnum) { ++ DiracFrame *retire_pic = remove_frame(s->ref_frames, retire); ++ ++ if (retire_pic) ++ retire_pic->avframe.reference &= DELAYED_PIC_REF; ++ else ++ av_log(s->avctx, AV_LOG_DEBUG, "Frame to retire not found\n"); ++ } ++ ++ /* if reference array is full, remove the oldest as per the spec */ ++ while (add_frame(s->ref_frames, MAX_REFERENCE_FRAMES, s->current_picture)) { ++ av_log(s->avctx, AV_LOG_ERROR, "Reference frame overflow\n"); ++ remove_frame(s->ref_frames, s->ref_frames[0]->avframe.display_picture_number)->avframe.reference &= DELAYED_PIC_REF; ++ } ++ } ++ ++ if (s->num_refs) { ++ if (dirac_unpack_prediction_parameters(s)) /* [DIRAC_STD] 11.2 Picture Prediction Data. picture_prediction() */ ++ return -1; ++ if (dirac_unpack_block_motion_data(s)) /* [DIRAC_STD] 12. Block motion data syntax */ ++ return -1; ++ } ++ if (dirac_unpack_idwt_params(s)) /* [DIRAC_STD] 11.3 Wavelet transform data */ ++ return -1; ++ ++ init_planes(s); ++ return 0; ++} ++ ++static int get_delayed_pic(DiracContext *s, AVFrame *picture, int *data_size) ++{ ++ DiracFrame *out = s->delay_frames[0]; ++ int i, out_idx = 0; ++ ++ /* find frame with lowest picture number */ ++ for (i = 1; s->delay_frames[i]; i++) ++ if (s->delay_frames[i]->avframe.display_picture_number < out->avframe.display_picture_number) { ++ out = s->delay_frames[i]; ++ out_idx = i; ++ } ++ ++ for (i = out_idx; s->delay_frames[i]; i++) ++ s->delay_frames[i] = s->delay_frames[i+1]; ++ ++ if (out) { ++ out->avframe.reference ^= DELAYED_PIC_REF; ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)picture = out->avframe; ++ } ++ ++ return 0; ++} ++ ++/** ++ * Dirac Specification -> ++ * 9.6 Parse Info Header Syntax. parse_info() ++ * 4 byte start code + byte parse code + 4 byte size + 4 byte previous size ++ */ ++#define DATA_UNIT_HEADER_SIZE 13 ++ ++/* [DIRAC_STD] dirac_decode_data_unit makes reference to the while defined in 9.3 ++ inside the function parse_sequence() */ ++static int dirac_decode_data_unit(AVCodecContext *avctx, const uint8_t *buf, int size) ++{ ++ DiracContext *s = avctx->priv_data; ++ DiracFrame *pic = NULL; ++ int i, parse_code = buf[4]; ++ unsigned tmp; ++ ++ if (size < DATA_UNIT_HEADER_SIZE) ++ return -1; ++ ++ init_get_bits(&s->gb, &buf[13], 8*(size - DATA_UNIT_HEADER_SIZE)); ++ ++ if (parse_code == pc_seq_header) { ++ if (s->seen_sequence_header) ++ return 0; ++ ++ /* [DIRAC_STD] 10. Sequence header */ ++ if (avpriv_dirac_parse_sequence_header(avctx, &s->gb, &s->source)) ++ return -1; ++ ++ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_x_shift, &s->chroma_y_shift); ++ ++ if (alloc_sequence_buffers(s)) ++ return -1; ++ ++ s->seen_sequence_header = 1; ++ } else if (parse_code == pc_eos) { /* [DIRAC_STD] End of Sequence */ ++ free_sequence_buffers(s); ++ s->seen_sequence_header = 0; ++ } else if (parse_code == pc_aux_data) { ++ if (buf[13] == 1) { /* encoder implementation/version */ ++ int ver[3]; ++ /* versions older than 1.0.8 don't store quant delta for ++ subbands with only one codeblock */ ++ if (sscanf(buf+14, "Schroedinger %d.%d.%d", ver, ver+1, ver+2) == 3) ++ if (ver[0] == 1 && ver[1] == 0 && ver[2] <= 7) ++ s->old_delta_quant = 1; ++ } ++ } else if (parse_code & 0x8) { /* picture data unit */ ++ if (!s->seen_sequence_header) { ++ av_log(avctx, AV_LOG_DEBUG, "Dropping frame without sequence header\n"); ++ return -1; ++ } ++ ++ /* find an unused frame */ ++ for (i = 0; i < MAX_FRAMES; i++) ++ if (s->all_frames[i].avframe.data[0] == NULL) ++ pic = &s->all_frames[i]; ++ if (!pic) { ++ av_log(avctx, AV_LOG_ERROR, "framelist full\n"); ++ return -1; ++ } ++ ++ avcodec_get_frame_defaults(&pic->avframe); ++ ++ /* [DIRAC_STD] Defined in 9.6.1 ... */ ++ tmp = parse_code & 0x03; /* [DIRAC_STD] num_refs() */ ++ if (tmp > 2) { ++ av_log(avctx, AV_LOG_ERROR, "num_refs of 3\n"); ++ return -1; ++ } ++ s->num_refs = tmp; ++ s->is_arith = (parse_code & 0x48) == 0x08; /* [DIRAC_STD] using_ac() */ ++ s->low_delay = (parse_code & 0x88) == 0x88; /* [DIRAC_STD] is_low_delay() */ ++ pic->avframe.reference = (parse_code & 0x0C) == 0x0C; /* [DIRAC_STD] is_reference() */ ++ pic->avframe.key_frame = s->num_refs == 0; /* [DIRAC_STD] is_intra() */ ++ pic->avframe.pict_type = s->num_refs + 1; /* Definition of AVPictureType in avutil.h */ ++ ++ if (avctx->get_buffer(avctx, &pic->avframe) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ s->current_picture = pic; ++ s->plane[0].stride = pic->avframe.linesize[0]; ++ s->plane[1].stride = pic->avframe.linesize[1]; ++ s->plane[2].stride = pic->avframe.linesize[2]; ++ ++ /* [DIRAC_STD] 11.1 Picture parse. picture_parse() */ ++ if (dirac_decode_picture_header(s)) ++ return -1; ++ ++ /* [DIRAC_STD] 13.0 Transform data syntax. transform_data() */ ++ if (dirac_decode_frame_internal(s)) ++ return -1; ++ } ++ return 0; ++} ++ ++static int dirac_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *pkt) ++{ ++ DiracContext *s = avctx->priv_data; ++ DiracFrame *picture = data; ++ uint8_t *buf = pkt->data; ++ int buf_size = pkt->size; ++ int i, data_unit_size, buf_idx = 0; ++ ++ /* release unused frames */ ++ for (i = 0; i < MAX_FRAMES; i++) ++ if (s->all_frames[i].avframe.data[0] && !s->all_frames[i].avframe.reference) { ++ avctx->release_buffer(avctx, &s->all_frames[i].avframe); ++ memset(s->all_frames[i].interpolated, 0, sizeof(s->all_frames[i].interpolated)); ++ } ++ ++ s->current_picture = NULL; ++ *data_size = 0; ++ ++ /* end of stream, so flush delayed pics */ ++ if (buf_size == 0) ++ return get_delayed_pic(s, (AVFrame *)data, data_size); ++ ++ for (;;) { ++ /*[DIRAC_STD] Here starts the code from parse_info() defined in 9.6 ++ [DIRAC_STD] PARSE_INFO_PREFIX = "BBCD" as defined in ISO/IEC 646 ++ BBCD start code search */ ++ for (; buf_idx + DATA_UNIT_HEADER_SIZE < buf_size; buf_idx++) { ++ if (buf[buf_idx ] == 'B' && buf[buf_idx+1] == 'B' && ++ buf[buf_idx+2] == 'C' && buf[buf_idx+3] == 'D') ++ break; ++ } ++ /* BBCD found or end of data */ ++ if (buf_idx + DATA_UNIT_HEADER_SIZE >= buf_size) ++ break; ++ ++ data_unit_size = AV_RB32(buf+buf_idx+5); ++ if (buf_idx + data_unit_size > buf_size || !data_unit_size) { ++ if(buf_idx + data_unit_size > buf_size) ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Data unit with size %d is larger than input buffer, discarding\n", ++ data_unit_size); ++ buf_idx += 4; ++ continue; ++ } ++ /* [DIRAC_STD] dirac_decode_data_unit makes reference to the while defined in 9.3 inside the function parse_sequence() */ ++ if (dirac_decode_data_unit(avctx, buf+buf_idx, data_unit_size)) ++ { ++ av_log(s->avctx, AV_LOG_ERROR,"Error in dirac_decode_data_unit\n"); ++ return -1; ++ } ++ buf_idx += data_unit_size; ++ } ++ ++ if (!s->current_picture) ++ return 0; ++ ++ if (s->current_picture->avframe.display_picture_number > s->frame_number) { ++ DiracFrame *delayed_frame = remove_frame(s->delay_frames, s->frame_number); ++ ++ s->current_picture->avframe.reference |= DELAYED_PIC_REF; ++ ++ if (add_frame(s->delay_frames, MAX_DELAY, s->current_picture)) { ++ int min_num = s->delay_frames[0]->avframe.display_picture_number; ++ /* Too many delayed frames, so we display the frame with the lowest pts */ ++ av_log(avctx, AV_LOG_ERROR, "Delay frame overflow\n"); ++ delayed_frame = s->delay_frames[0]; ++ ++ for (i = 1; s->delay_frames[i]; i++) ++ if (s->delay_frames[i]->avframe.display_picture_number < min_num) ++ min_num = s->delay_frames[i]->avframe.display_picture_number; ++ ++ delayed_frame = remove_frame(s->delay_frames, min_num); ++ add_frame(s->delay_frames, MAX_DELAY, s->current_picture); ++ } ++ ++ if (delayed_frame) { ++ delayed_frame->avframe.reference ^= DELAYED_PIC_REF; ++ *(AVFrame*)data = delayed_frame->avframe; ++ *data_size = sizeof(AVFrame); ++ } ++ } else if (s->current_picture->avframe.display_picture_number == s->frame_number) { ++ /* The right frame at the right time :-) */ ++ *(AVFrame*)data = s->current_picture->avframe; ++ *data_size = sizeof(AVFrame); ++ } ++ ++ if (*data_size) ++ s->frame_number = picture->avframe.display_picture_number + 1; ++ ++ return buf_idx; ++} ++ ++AVCodec ff_dirac_decoder = { ++ .name = "dirac", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DIRAC, ++ .priv_data_size = sizeof(DiracContext), ++ .init = dirac_decode_init, ++ .close = dirac_decode_end, ++ .decode = dirac_decode_frame, ++ .capabilities = CODEC_CAP_DELAY, ++ .flush = dirac_decode_flush, ++ .long_name = NULL_IF_CONFIG_SMALL("BBC Dirac VC-2"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdsp.c 2012-05-14 14:08:53.605325309 +0200 +@@ -0,0 +1,201 @@ ++/* ++ * Copyright (C) 2009 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dsputil.h" ++#include "diracdsp.h" ++#include "libavcodec/x86/diracdsp_mmx.h" ++ ++#define FILTER(src, stride) \ ++ ((21*((src)[ 0*stride] + (src)[1*stride]) \ ++ -7*((src)[-1*stride] + (src)[2*stride]) \ ++ +3*((src)[-2*stride] + (src)[3*stride]) \ ++ -1*((src)[-3*stride] + (src)[4*stride]) + 16) >> 5) ++ ++static void dirac_hpel_filter(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src, ++ int stride, int width, int height) ++{ ++ int x, y; ++ ++ for (y = 0; y < height; y++) { ++ for (x = -3; x < width+5; x++) ++ dstv[x] = av_clip_uint8(FILTER(src+x, stride)); ++ ++ for (x = 0; x < width; x++) ++ dstc[x] = av_clip_uint8(FILTER(dstv+x, 1)); ++ ++ for (x = 0; x < width; x++) ++ dsth[x] = av_clip_uint8(FILTER(src+x, 1)); ++ ++ src += stride; ++ dsth += stride; ++ dstv += stride; ++ dstc += stride; ++ } ++} ++ ++#define PIXOP_BILINEAR(PFX, OP, WIDTH) \ ++ static void ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c(uint8_t *dst, const uint8_t *src[5], int stride, int h) \ ++ { \ ++ int x; \ ++ const uint8_t *s0 = src[0]; \ ++ const uint8_t *s1 = src[1]; \ ++ const uint8_t *s2 = src[2]; \ ++ const uint8_t *s3 = src[3]; \ ++ const uint8_t *w = src[4]; \ ++ \ ++ while (h--) { \ ++ for (x = 0; x < WIDTH; x++) { \ ++ OP(dst[x], (s0[x]*w[0] + s1[x]*w[1] + s2[x]*w[2] + s3[x]*w[3] + 8) >> 4); \ ++ } \ ++ \ ++ dst += stride; \ ++ s0 += stride; \ ++ s1 += stride; \ ++ s2 += stride; \ ++ s3 += stride; \ ++ } \ ++ } ++ ++#define OP_PUT(dst, val) (dst) = (val) ++#define OP_AVG(dst, val) (dst) = (((dst) + (val) + 1)>>1) ++ ++PIXOP_BILINEAR(put, OP_PUT, 8) ++PIXOP_BILINEAR(put, OP_PUT, 16) ++PIXOP_BILINEAR(put, OP_PUT, 32) ++PIXOP_BILINEAR(avg, OP_AVG, 8) ++PIXOP_BILINEAR(avg, OP_AVG, 16) ++PIXOP_BILINEAR(avg, OP_AVG, 32) ++ ++#define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + (1<<(log2_denom-1))) >> log2_denom) ++#define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + (1<<(log2_denom-1))) >> log2_denom) ++ ++#define DIRAC_WEIGHT(W) \ ++ static void weight_dirac_pixels ## W ## _c(uint8_t *block, int stride, int log2_denom, \ ++ int weight, int h) { \ ++ int x; \ ++ while (h--) { \ ++ for (x = 0; x < W; x++) { \ ++ op_scale1(x); \ ++ op_scale1(x+1); \ ++ } \ ++ block += stride; \ ++ } \ ++ } \ ++ static void biweight_dirac_pixels ## W ## _c(uint8_t *dst, uint8_t *src, int stride, int log2_denom, \ ++ int weightd, int weights, int h) { \ ++ int x; \ ++ while (h--) { \ ++ for (x = 0; x < W; x++) { \ ++ op_scale2(x); \ ++ op_scale2(x+1); \ ++ } \ ++ dst += stride; \ ++ src += stride; \ ++ } \ ++ } ++ ++DIRAC_WEIGHT(8) ++DIRAC_WEIGHT(16) ++DIRAC_WEIGHT(32) ++ ++#define ADD_OBMC(xblen) \ ++ static void add_obmc ## xblen ## _c(uint16_t *dst, const uint8_t *src, int stride, \ ++ const uint8_t *obmc_weight, int yblen) \ ++ { \ ++ int x; \ ++ while (yblen--) { \ ++ for (x = 0; x < xblen; x += 2) { \ ++ dst[x ] += src[x ] * obmc_weight[x ]; \ ++ dst[x+1] += src[x+1] * obmc_weight[x+1]; \ ++ } \ ++ dst += stride; \ ++ src += stride; \ ++ obmc_weight += 32; \ ++ } \ ++ } ++ ++ADD_OBMC(8) ++ADD_OBMC(16) ++ADD_OBMC(32) ++ ++static void put_signed_rect_clamped_c(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height) ++{ ++ int x, y; ++ for (y = 0; y < height; y++) { ++ for (x = 0; x < width; x+=4) { ++ dst[x ] = av_clip_uint8(src[x ] + 128); ++ dst[x+1] = av_clip_uint8(src[x+1] + 128); ++ dst[x+2] = av_clip_uint8(src[x+2] + 128); ++ dst[x+3] = av_clip_uint8(src[x+3] + 128); ++ } ++ dst += dst_stride; ++ src += src_stride; ++ } ++} ++ ++static void add_rect_clamped_c(uint8_t *dst, const uint16_t *src, int stride, ++ const int16_t *idwt, int idwt_stride, ++ int width, int height) ++{ ++ int x, y; ++ ++ for (y = 0; y < height; y++) { ++ for (x = 0; x < width; x+=2) { ++ dst[x ] = av_clip_uint8(((src[x ]+32)>>6) + idwt[x ]); ++ dst[x+1] = av_clip_uint8(((src[x+1]+32)>>6) + idwt[x+1]); ++ } ++ dst += stride; ++ src += stride; ++ idwt += idwt_stride; ++ } ++} ++ ++#define PIXFUNC(PFX, WIDTH) \ ++ c->PFX ## _dirac_pixels_tab[WIDTH>>4][0] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _c; \ ++ c->PFX ## _dirac_pixels_tab[WIDTH>>4][1] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l2_c; \ ++ c->PFX ## _dirac_pixels_tab[WIDTH>>4][2] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _l4_c; \ ++ c->PFX ## _dirac_pixels_tab[WIDTH>>4][3] = ff_ ## PFX ## _dirac_pixels ## WIDTH ## _bilinear_c ++ ++void ff_diracdsp_init(DiracDSPContext *c) ++{ ++ c->dirac_hpel_filter = dirac_hpel_filter; ++ c->add_rect_clamped = add_rect_clamped_c; ++ c->put_signed_rect_clamped = put_signed_rect_clamped_c; ++ ++ c->add_dirac_obmc[0] = add_obmc8_c; ++ c->add_dirac_obmc[1] = add_obmc16_c; ++ c->add_dirac_obmc[2] = add_obmc32_c; ++ ++ c->weight_dirac_pixels_tab[0] = weight_dirac_pixels8_c; ++ c->weight_dirac_pixels_tab[1] = weight_dirac_pixels16_c; ++ c->weight_dirac_pixels_tab[2] = weight_dirac_pixels32_c; ++ c->biweight_dirac_pixels_tab[0] = biweight_dirac_pixels8_c; ++ c->biweight_dirac_pixels_tab[1] = biweight_dirac_pixels16_c; ++ c->biweight_dirac_pixels_tab[2] = biweight_dirac_pixels32_c; ++ ++ PIXFUNC(put, 8); ++ PIXFUNC(put, 16); ++ PIXFUNC(put, 32); ++ PIXFUNC(avg, 8); ++ PIXFUNC(avg, 16); ++ PIXFUNC(avg, 32); ++ ++ if (HAVE_MMX && HAVE_YASM) ff_diracdsp_init_mmx(c); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/diracdsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/diracdsp.h 2012-05-14 14:08:53.606325330 +0200 +@@ -0,0 +1,67 @@ ++/* ++ * Copyright (C) 2010 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_DIRACDSP_H ++#define AVCODEC_DIRACDSP_H ++ ++#include ++ ++typedef void (*dirac_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int h); ++typedef void (*dirac_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int h); ++ ++typedef struct { ++ void (*dirac_hpel_filter)(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, uint8_t *src, int stride, int width, int height); ++ /** ++ * dirac_pixels_tab[width][subpel] ++ * width is 2 for 32, 1 for 16, 0 for 8 ++ * subpel is 0 for fpel and hpel (only need to copy from the first plane in src) ++ * 1 if an average of the first 2 planes is needed (TODO: worth it?) ++ * 2 for general qpel (avg of 4) ++ * 3 for general epel (biweight of 4 using the weights in src[4]) ++ * src[0-3] is each of the hpel planes ++ * src[4] is the 1/8 pel weights if needed ++ */ ++ void (*put_dirac_pixels_tab[3][4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++ void (*avg_dirac_pixels_tab[3][4])(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++ ++ void (*put_signed_rect_clamped)(uint8_t *dst/*align 16*/, int dst_stride, const int16_t *src/*align 16*/, int src_stride, int width, int height/*mod 2*/); ++ void (*put_rect_clamped)(uint8_t *dst/*align 16*/, int dst_stride, const int16_t *src/*align 16*/, int src_stride, int width, int height/*mod 2*/); ++ void (*add_rect_clamped)(uint8_t *dst/*align 16*/, const uint16_t *src/*align 16*/, int stride, const int16_t *idwt/*align 16*/, int idwt_stride, int width, int height/*mod 2*/); ++ void (*add_dirac_obmc[3])(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++ ++ dirac_weight_func weight_dirac_pixels_tab[3]; ++ dirac_biweight_func biweight_dirac_pixels_tab[3]; ++} DiracDSPContext; ++ ++#define DECL_DIRAC_PIXOP(PFX, EXT) \ ++ void ff_ ## PFX ## _dirac_pixels8_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h); \ ++ void ff_ ## PFX ## _dirac_pixels16_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h); \ ++ void ff_ ## PFX ## _dirac_pixels32_ ## EXT(uint8_t *dst, const uint8_t *src[5], int stride, int h) ++ ++DECL_DIRAC_PIXOP(put, c); ++DECL_DIRAC_PIXOP(avg, c); ++DECL_DIRAC_PIXOP(put, l2_c); ++DECL_DIRAC_PIXOP(avg, l2_c); ++DECL_DIRAC_PIXOP(put, l4_c); ++DECL_DIRAC_PIXOP(avg, l4_c); ++ ++void ff_diracdsp_init(DiracDSPContext *c); ++ ++#endif /* AVCODEC_DIRACDSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac.h 2012-05-14 14:08:53.597325148 +0200 +@@ -1,6 +1,7 @@ + /* + * Copyright (C) 2007 Marco Gerards + * Copyright (C) 2009 David Conrad ++ * Copyright (C) 2011 Jordi Ortiz + * + * This file is part of FFmpeg. + * +@@ -26,6 +27,8 @@ + * @file + * Interface to Dirac Decoder/Encoder + * @author Marco Gerards ++ * @author David Conrad ++ * @author Jordi Ortiz + */ + + #include "avcodec.h" +@@ -51,7 +54,7 @@ + uint8_t color_spec_index; ///< index into dirac_color_spec_presets[] + } dirac_source_params; + +-int ff_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, +- dirac_source_params *source); ++int avpriv_dirac_parse_sequence_header(AVCodecContext *avctx, GetBitContext *gb, ++ dirac_source_params *source); + + #endif /* AVCODEC_DIRAC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dirac_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dirac_parser.c 2012-05-14 14:08:53.599325189 +0200 +@@ -194,7 +194,7 @@ + avctx->has_b_frames = 1; + } + if (avctx->has_b_frames && s->pts == s->dts) +- s->pict_type = FF_B_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_B; + + /* Finally have a complete Dirac data unit */ + *buf = pc->dirac_unit; +@@ -248,9 +248,8 @@ + } + + AVCodecParser ff_dirac_parser = { +- { CODEC_ID_DIRAC }, +- sizeof(DiracParseContext), +- NULL, +- dirac_parse, +- dirac_parse_close, ++ .codec_ids = { CODEC_ID_DIRAC }, ++ .priv_data_size = sizeof(DiracParseContext), ++ .parser_parse = dirac_parse, ++ .parser_close = dirac_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddata.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddata.c 2012-05-14 14:08:53.611325430 +0200 +@@ -22,6 +22,28 @@ + #include "avcodec.h" + #include "dnxhddata.h" + ++static const uint8_t dnxhd_1235_luma_weight[] = { ++ 0, 32, 32, 32, 33, 35, 38, 39, ++ 32, 33, 32, 33, 36, 36, 39, 42, ++ 32, 32, 33, 36, 35, 37, 41, 43, ++ 31, 33, 34, 36, 36, 40, 42, 48, ++ 32, 34, 36, 37, 39, 42, 46, 51, ++ 36, 37, 37, 39, 41, 46, 51, 55, ++ 37, 39, 41, 41, 47, 50, 55, 56, ++ 41, 42, 41, 44, 50, 53, 60, 60 ++}; ++ ++static const uint8_t dnxhd_1235_chroma_weight[] = { ++ 0, 32, 33, 34, 39, 41, 54, 59, ++ 33, 34, 35, 38, 43, 49, 58, 84, ++ 34, 37, 39, 44, 46, 55, 74, 87, ++ 40, 42, 47, 48, 58, 70, 87, 86, ++ 43, 50, 56, 63, 72, 94, 91, 82, ++ 55, 63, 65, 75, 93, 89, 85, 73, ++ 61, 67, 82, 81, 83, 90, 79, 73, ++ 74, 84, 75, 78, 90, 85, 73, 73 ++}; ++ + static const uint8_t dnxhd_1237_luma_weight[] = { + 0, 32, 33, 34, 34, 36, 37, 36, + 36, 37, 38, 38, 38, 39, 41, 44, +@@ -108,7 +130,7 @@ + 48, 49, 51, 51, 52, 52, 54, 54, + 49, 49, 52, 53, 54, 54, 53, 53, + 55, 59, 63, 62, 60, 60, 60, 60, +- }; ++}; + + static const uint8_t dnxhd_1243_luma_weight[] = { + 0, 32, 32, 33, 33, 35, 35, 35, +@@ -132,6 +154,28 @@ + 46, 45, 46, 47, 47, 48, 47, 47, + }; + ++static const uint8_t dnxhd_1250_luma_weight[] = { ++ 0, 32, 35, 35, 36, 36, 41, 43, ++ 32, 34, 35, 36, 37, 39, 43, 47, ++ 33, 34, 36, 38, 38, 42, 42, 50, ++ 34, 36, 38, 38, 41, 40, 47, 54, ++ 35, 38, 39, 40, 39, 45, 49, 58, ++ 38, 39, 40, 39, 46, 47, 54, 60, ++ 38, 39, 41, 46, 46, 48, 57, 62, ++ 40, 41, 44, 45, 49, 54, 63, 63 ++}; ++ ++static const uint8_t dnxhd_1250_chroma_weight[] = { ++ 0, 32, 35, 36, 40, 42, 51, 51, ++ 35, 36, 39, 39, 43, 51, 52, 55, ++ 36, 41, 41, 43, 51, 53, 54, 56, ++ 43, 44, 45, 50, 54, 54, 55, 57, ++ 45, 48, 50, 51, 55, 58, 59, 58, ++ 49, 52, 49, 57, 58, 62, 58, 60, ++ 51, 51, 56, 58, 62, 61, 59, 62, ++ 52, 52, 60, 61, 59, 59, 63, 63 ++}; ++ + static const uint8_t dnxhd_1251_luma_weight[] = { + 0, 32, 32, 34, 34, 34, 34, 35, + 35, 35, 36, 37, 36, 36, 35, 36, +@@ -184,35 +228,124 @@ + }; + + static const uint16_t dnxhd_1237_ac_codes[257] = { +- 0, 1, 4, 5, 12, 26, 27, 56, 57, 58, 59, 120, 121, 244, 245, 246, 247, 248, 498, 499, 500, 501, 502, 1006, 1007, 1008, 1009, 1010, 1011, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 4072, 4073, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374, 65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382, 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, ++ 0, 1, 4, 5, 12, 26, 27, 56, ++ 57, 58, 59, 120, 121, 244, 245, 246, ++ 247, 248, 498, 499, 500, 501, 502, 1006, ++ 1007, 1008, 1009, 1010, 1011, 2024, 2025, 2026, ++ 2027, 2028, 2029, 2030, 2031, 4064, 4065, 4066, ++ 4067, 4068, 4069, 4070, 4071, 4072, 4073, 8148, ++ 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, ++ 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, ++ 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, ++ 16332, 16333, 32668, 32669, 32670, 32671, 32672, 32673, ++ 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, ++ 32682, 32683, 32684, 65370, 65371, 65372, 65373, 65374, ++ 65375, 65376, 65377, 65378, 65379, 65380, 65381, 65382, ++ 65383, 65384, 65385, 65386, 65387, 65388, 65389, 65390, ++ 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, ++ 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, ++ 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, ++ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, ++ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535, + }; + + static const uint8_t dnxhd_1237_ac_bits[257] = { +- 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 2, 2, 3, 3, 4, 5, 5, 6, 6, 6, 6, 7, 7, 8, 8, 8, ++ 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 11, 11, 11, ++ 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, ++ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, + }; + + static const uint8_t dnxhd_1237_ac_level[257] = { +- 1, 1, 2, 0, 3, 4, 2, 5, 6, 7, 3, 8, 9, 10, 11, 12, 4, 5, 13, 14, 15, 16, 6, 17, 18, 19, 20, 21, 7, 22, 23, 24, 25, 26, 27, 8, 9, 28, 29, 30, 31, 32, 33, 34, 10, 11, 12, 35, 36, 37, 38, 39, 40, 41, 13, 14, 15, 16, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 17, 18, 19, 20, 21, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 1, 22, 23, 24, 25, 26, 27, 62, 63, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +-}; +- +-static const uint8_t dnxhd_1237_ac_run_flag[257] = { +- 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-}; +- +-static const uint8_t dnxhd_1237_ac_index_flag[257] = { +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 3, 3, 5, 0, 7, 9, 5, 11, 13, 15, 7, 17, 19, 21, 23, 25, ++ 9, 11, 27, 29, 31, 33, 13, 35, 37, 39, 41, 43, 15, 45, 47, 49, ++ 51, 53, 55, 17, 19, 57, 59, 61, 63, 65, 67, 69, 21, 23, 25, 71, ++ 73, 75, 77, 79, 81, 83, 27, 29, 31, 33, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105, 35, 37, 39, 41, 43,107,109,111,113,115,117, ++ 119,121,123,129, 3, 45, 47, 49, 51, 53, 55,125,127, 5, 7, 9, ++ 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, ++ 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, ++ 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99,101,103,105, ++ 107,109,111,113,115,117,119,121,123,125,127,129, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, ++}; ++ ++static const uint8_t dnxhd_1237_ac_flags[257] = { ++ 0, 2, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0, ++ 2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, ++ 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, ++ 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 1, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, + }; + + static const uint16_t dnxhd_1237_run_codes[62] = { +- 0, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 58, 118, 119, 240, 482, 483, 484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, ++ 0, 4, 10, 11, 24, 25, 26, 54, ++ 55, 56, 57, 58, 118, 119, 240, 482, ++ 483, 484, 485, 486, 487, 488, 489, 490, ++ 491, 492, 493, 494, 990, 991, 992, 993, ++ 994, 995, 996, 997, 998, 999, 1000, 1001, ++ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, ++ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, ++ 1018, 1019, 1020, 1021, 1022, 1023, + }; + + static const uint8_t dnxhd_1237_run_bits[62] = { +- 1, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 1, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 6, 7, 7, 8, 9, ++ 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + }; + + static const uint8_t dnxhd_1237_run[62] = { +- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, ++ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ++ 17, 18, 19, 20, 21, 53, 57, 58, 59, 60, 61, 62, 22, 23, 24, 25, ++ 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, ++ 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 54, 55, 56, + }; + + static const uint8_t dnxhd_1238_dc_codes[12] = { +@@ -224,176 +357,663 @@ + }; + + static const uint16_t dnxhd_1238_ac_codes[257] = { +- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 499, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, ++ 0, 1, 4, 10, 11, 24, 25, 26, ++ 54, 55, 56, 57, 116, 117, 118, 119, ++ 240, 241, 242, 243, 244, 245, 492, 493, ++ 494, 495, 496, 497, 498, 499, 1000, 1001, ++ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 2018, ++ 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, ++ 2027, 4056, 4057, 4058, 4059, 4060, 4061, 4062, ++ 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, ++ 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, ++ 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, ++ 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, ++ 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, ++ 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, ++ 16338, 32678, 32679, 32680, 32681, 32682, 32683, 32684, ++ 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, ++ 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, ++ 32701, 32702, 32703, 32704, 32705, 65412, 65413, 65414, ++ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, ++ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535, + }; + + static const uint8_t dnxhd_1238_ac_bits[257] = { +- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, ++ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, ++ 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, ++ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, + }; + + static const uint8_t dnxhd_1238_ac_level[257] = { +- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 22, 6, 7, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 10, 11, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 12, 13, 14, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 15, 16, 17, 18, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 40, 25, 26, 27, 28, 29, 30, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, ++ 3, 3, 5, 7, 0, 9, 11, 5, 13, 15, 17, 7, 19, 21, 23, 9, ++ 25, 27, 29, 31, 33, 11, 35, 37, 39, 41, 43, 45, 13, 15, 47, 49, ++ 51, 53, 55, 57, 59, 17, 19, 61, 63, 65, 67, 69, 71, 73, 75, 21, ++ 23, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 25, 27, 29, 99, ++ 101,103,105,107,109,111,113,115,117,119,121,123, 31, 33, 35, 37, ++ 125,127,129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, ++ 29, 31, 33, 39, 41, 43, 45, 47, 49, 35, 37, 39, 41, 43, 45, 47, ++ 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 81, 51, ++ 53, 55, 57, 59, 61, 77, 79, 83, 85, 87, 89, 91, 93, 95, 97, 99, ++ 101,103,105,107,109,111,113,115,117,119,121,123,125,127,129, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, + }; /* 0 is EOB */ + +-static const uint8_t dnxhd_1238_ac_run_flag[257] = { +- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++static const uint8_t dnxhd_1238_ac_flags[257] = { ++ 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, ++ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, ++ 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, ++ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, ++ 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, ++ 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, + }; + + static const uint8_t dnxhd_1238_ac_index_flag[257] = { +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }; + +-static const uint16_t dnxhd_1238_run_codes[62] = { +- 0, 4, 10, 11, 24, 25, 26, 27, 56, 57, 58, 59, 120, 242, 486, 487, 488, 489, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, +-}; +- +-static const uint8_t dnxhd_1238_run_bits[62] = { +- 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++static const uint16_t dnxhd_1235_1238_1241_run_codes[62] = { ++ 0, 4, 10, 11, 24, 25, 26, 27, ++ 56, 57, 58, 59, 120, 242, 486, 487, ++ 488, 489, 980, 981, 982, 983, 984, 985, ++ 986, 987, 988, 989, 990, 991, 992, 993, ++ 994, 995, 996, 997, 998, 999, 1000, 1001, ++ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, ++ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, ++ 1018, 1019, 1020, 1021, 1022, 1023, ++}; ++ ++static const uint8_t dnxhd_1235_1238_1241_run_bits[62] = { ++ 1, 3, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 8, 9, 9, ++ 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + }; + + static const uint8_t dnxhd_1238_run[62] = { +- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, ++ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ++ 20, 21, 17, 18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ++ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, ++ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + }; + +-static const uint8_t dnxhd_1241_dc_codes[14] = { ++static const uint8_t dnxhd_1235_1241_dc_codes[14] = { + 10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127, + }; + +-static const uint8_t dnxhd_1241_dc_bits[14] = { ++static const uint8_t dnxhd_1235_1241_dc_bits[14] = { + 4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7, + }; +-static const uint16_t dnxhd_1241_ac_codes[257] = { +- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 498, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, +-}; +- +-static const uint8_t dnxhd_1241_ac_bits[257] = { +- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, +-}; +- +-static const uint8_t dnxhd_1241_ac_level[257] = { +- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 7, 22, 23, 24, 25, 26, 27, 28, 29, 8, 9, 30, 31, 32, 33, 34, 35, 36, 37, 38, 10, 11, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 12, 13, 14, 15, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 1, 16, 17, 18, 19, 64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 24, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 25, 26, 27, 28, 29, 30, 31, 32, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +-}; +- +-static const uint8_t dnxhd_1241_ac_run_flag[257] = { +- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-}; + +-static const uint8_t dnxhd_1241_ac_index_flag[257] = { +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-}; +- +-static const uint8_t dnxhd_1241_run[62] = { +- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, ++static const uint16_t dnxhd_1235_1241_ac_codes[257] = { ++ 0, 1, 4, 10, 11, 24, 25, 26, ++ 54, 55, 56, 57, 116, 117, 118, 119, ++ 240, 241, 242, 243, 244, 245, 492, 493, ++ 494, 495, 496, 497, 498, 998, 999, 1000, ++ 1001, 1002, 1003, 1004, 1005, 1006, 1007, 2016, ++ 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, ++ 2025, 2026, 4054, 4055, 4056, 4057, 4058, 4059, ++ 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, ++ 4068, 4069, 8140, 8141, 8142, 8143, 8144, 8145, ++ 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, ++ 8154, 8155, 8156, 8157, 16316, 16317, 16318, 16319, ++ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, ++ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, ++ 16336, 16337, 32676, 32677, 32678, 32679, 32680, 32681, ++ 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, ++ 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, ++ 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, ++ 32706, 32707, 32708, 65418, 65419, 65420, 65421, 65422, ++ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535, ++}; ++ ++static const uint8_t dnxhd_1235_1241_ac_bits[257] = { ++ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, ++ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, ++ 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, ++ 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, ++ 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, ++}; ++ ++static const uint8_t dnxhd_1235_1241_ac_level[257] = { ++ 3, 3, 5, 7, 0, 9, 11, 5, 13, 15, 17, 7, 19, 21, 23, 9, ++ 25, 27, 29, 31, 33, 11, 35, 37, 39, 41, 43, 13, 15, 45, 47, 49, ++ 51, 53, 55, 57, 59, 17, 19, 61, 63, 65, 67, 69, 71, 73, 75, 77, ++ 21, 23, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99,101, 25, 27, ++ 29, 31,103,105,107,109,111,113,115,117,119,121,123,125,127, 3, ++ 33, 35, 37, 39,129, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, ++ 27, 29, 31, 33, 35, 41, 43, 45, 47, 49, 37, 39, 41, 43, 45, 47, ++ 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, ++ 81, 83, 85, 51, 53, 55, 57, 59, 61, 63, 65, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, ++}; ++ ++static const uint8_t dnxhd_1235_1241_ac_flags[257] = { ++ 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, ++ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, ++ 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, ++ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ++ 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, ++}; ++ ++static const uint8_t dnxhd_1235_1241_run[62] = { ++ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ++ 18, 20, 17, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ++ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, ++ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, ++}; ++ ++static const uint8_t dnxhd_1250_dc_codes[14] = { ++ 10, 62, 11, 12, 13, 0, 1, 2, 3, 4, 14, 30, 126, 127 ++}; ++static const uint8_t dnxhd_1250_dc_bits[14] = { ++ 4, 6, 4, 4, 4, 3, 3, 3, 3, 3, 4, 5, 7, 7 ++}; ++static const uint16_t dnxhd_1250_ac_codes[257] = { ++ 0, 1, 4, 10, 11, 24, 25, 26, ++ 54, 55, 56, 57, 116, 117, 118, 119, ++ 240, 241, 242, 243, 244, 245, 492, 493, ++ 494, 495, 496, 497, 498, 998, 999, 1000, ++ 1001, 1002, 1003, 1004, 1005, 1006, 2014, 2015, ++ 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, ++ 2024, 2025, 4052, 4053, 4054, 4055, 4056, 4057, ++ 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, ++ 4066, 4067, 8136, 8137, 8138, 8139, 8140, 8141, ++ 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, ++ 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, ++ 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, ++ 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, ++ 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, ++ 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, ++ 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, ++ 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, ++ 32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709, ++ 32710, 32711, 32712, 65426, 65427, 65428, 65429, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535 ++}; ++static const uint8_t dnxhd_1250_ac_bits[257] = { ++ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, ++ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, ++ 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, ++ 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, ++ 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16 ++}; ++static const uint8_t dnxhd_1250_ac_level[257] = { ++ 3, 3, 5, 7, 0, 9, 11, 5, 13, 15, 17, 7, 19, 21, 23, 9, ++ 25, 27, 29, 31, 33, 11, 35, 37, 39, 41, 43, 45, 13, 47, 49, 51, ++ 53, 55, 57, 59, 15, 17, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, ++ 19, 21, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99,101,103,105, 23, ++ 25, 27,107,109,111,113,115,117,119,121,123,125,127,129, 3, 5, ++ 7, 9, 11, 29, 31, 33, 35, 13, 15, 17, 19, 21, 23, 25, 27, 29, ++ 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 37, 39, 41, 43, ++ 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, ++ 87, 89, 91, 93, 95, 97, 99,101,103,105,107,111,113, 45, 47, 49, ++ 51, 53, 55,109,115,117,119,121,123,125,127,129, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129 ++}; ++static const uint8_t dnxhd_1250_ac_flags[257] = { ++ 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, ++ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, ++ 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, ++ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, ++ 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, ++ 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, ++}; ++static const uint16_t dnxhd_1250_run_codes[62] = { ++ 0, 4, 5, 12, 26, 27, 28, 58, ++ 118, 119, 120, 242, 486, 487, 976, 977, ++ 978, 979, 980, 981, 982, 983, 984, 985, ++ 986, 987, 988, 989, 990, 991, 992, 993, ++ 994, 995, 996, 997, 998, 999, 1000, 1001, ++ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, ++ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, ++ 1018, 1019, 1020, 1021, 1022, 1023 ++}; ++static const uint8_t dnxhd_1250_run_bits[62] = { ++ 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ++}; ++static const uint8_t dnxhd_1250_run[62] = { ++ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ++ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ++ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, ++ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62 + }; + + static const uint8_t dnxhd_1251_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, + }; ++ + static const uint8_t dnxhd_1251_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, + }; ++ + static const uint16_t dnxhd_1251_ac_codes[257] = { +- 0, 1, 4, 10, 11, 24, 25, 26, 54, 55, 56, 57, 116, 117, 118, 119, 240, 241, 242, 243, 244, 245, 492, 493, 494, 495, 496, 497, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 4052, 4053, 4054, 4055, 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 8134, 8135, 8136, 8137, 8138, 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, 32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, ++ 0, 1, 4, 10, 11, 24, 25, 26, ++ 54, 55, 56, 57, 116, 117, 118, 119, ++ 240, 241, 242, 243, 244, 245, 492, 493, ++ 494, 495, 496, 497, 996, 997, 998, 999, ++ 1000, 1001, 1002, 1003, 1004, 1005, 2012, 2013, ++ 2014, 2015, 2016, 2017, 2018, 2019, 2020, 2021, ++ 2022, 2023, 2024, 2025, 4052, 4053, 4054, 4055, ++ 4056, 4057, 4058, 4059, 4060, 4061, 4062, 4063, ++ 4064, 4065, 4066, 8134, 8135, 8136, 8137, 8138, ++ 8139, 8140, 8141, 8142, 8143, 8144, 8145, 8146, ++ 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, ++ 8155, 8156, 16314, 16315, 16316, 16317, 16318, 16319, ++ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, ++ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, ++ 16336, 16337, 16338, 16339, 32680, 32681, 32682, 32683, ++ 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, ++ 32692, 32693, 32694, 32695, 32696, 32697, 32698, 32699, ++ 32700, 32701, 32702, 32703, 32704, 32705, 32706, 32707, ++ 32708, 32709, 32710, 32711, 32712, 32713, 32714, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535, + }; ++ + static const uint8_t dnxhd_1251_ac_bits[257] = { +- 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 2, 2, 3, 4, 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, ++ 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, ++ 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, ++ 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, ++ 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, + }; ++ + static const uint8_t dnxhd_1251_ac_level[257] = { +- 1, 1, 2, 3, 0, 4, 5, 2, 6, 7, 8, 3, 9, 10, 11, 4, 12, 13, 14, 15, 16, 5, 17, 18, 19, 20, 21, 6, 22, 23, 24, 25, 26, 27, 28, 29, 7, 8, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 9, 10, 11, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 12, 13, 14, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 15, 16, 17, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 18, 19, 20, 21, 22, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 23, 24, 25, 26, 27, 28, 59, 60, 61, 62, 63, 64, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +-}; +-static const uint8_t dnxhd_1251_ac_run_flag[257] = { +- 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-}; +-static const uint8_t dnxhd_1251_ac_index_flag[257] = { +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 3, 3, 5, 7, 0, 9, 11, 5, 13, 15, 17, 7, 19, 21, 23, 9, ++ 25, 27, 29, 31, 33, 11, 35, 37, 39, 41, 43, 13, 45, 47, 49, 51, ++ 53, 55, 57, 59, 15, 17, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, ++ 81, 19, 21, 23, 83, 85, 87, 89, 91, 93, 95, 97, 99,101,103,105, ++ 25, 27, 29,107,109,111,113,115,117,119,121,123,125,127,129, 3, ++ 5, 7, 9, 11, 13, 15, 17, 31, 33, 35, 19, 21, 23, 25, 27, 29, ++ 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 37, ++ 39, 41, 43, 45, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, ++ 85, 87, 89, 91, 93, 95, 97, 99,101,103,105,107,109,111,113,115, ++ 117, 47, 49, 51, 53, 55, 57,119,121,123,125,127,129, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, ++}; ++ ++static const uint8_t dnxhd_1251_ac_flags[257] = { ++ 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 2, 0, 0, 0, 2, ++ 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, ++ 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ++ 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, ++ 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, + }; ++ + static const uint16_t dnxhd_1251_run_codes[62] = { +- 0, 4, 5, 12, 26, 27, 28, 58, 118, 119, 120, 242, 486, 487, 976, 977, 978, 979, 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, ++ 0, 4, 5, 12, 26, 27, 28, 58, ++ 118, 119, 120, 242, 486, 487, 976, 977, ++ 978, 979, 980, 981, 982, 983, 984, 985, ++ 986, 987, 988, 989, 990, 991, 992, 993, ++ 994, 995, 996, 997, 998, 999, 1000, 1001, ++ 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, ++ 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, ++ 1018, 1019, 1020, 1021, 1022, 1023, + }; ++ + static const uint8_t dnxhd_1251_run_bits[62] = { +- 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 1, 3, 3, 4, 5, 5, 5, 6, 7, 7, 7, 8, 9, 9, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, ++ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + }; ++ + static const uint8_t dnxhd_1251_run[62] = { +- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, ++ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, ++ 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ++ 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, ++ 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, + }; + + static const uint8_t dnxhd_1252_dc_codes[12] = { + 0, 12, 13, 1, 2, 3, 4, 5, 14, 30, 62, 63, + }; ++ + static const uint8_t dnxhd_1252_dc_bits[12] = { + 3, 4, 4, 3, 3, 3, 3, 3, 4, 5, 6, 6, + }; ++ + static const uint16_t dnxhd_1252_ac_codes[257] = { +- 0, 1, 4, 10, 11, 12, 26, 27, 56, 57, 58, 118, 119, 120, 242, 243, 244, 245, 246, 247, 496, 497, 498, 499, 500, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 4060, 4061, 4062, 4063, 4064, 4065, 4066, 4067, 4068, 4069, 4070, 4071, 8144, 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, 32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390, 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, 65535, ++ 0, 1, 4, 10, 11, 12, 26, 27, ++ 56, 57, 58, 118, 119, 120, 242, 243, ++ 244, 245, 246, 247, 496, 497, 498, 499, ++ 500, 1002, 1003, 1004, 1005, 1006, 1007, 1008, ++ 1009, 2020, 2021, 2022, 2023, 2024, 2025, 2026, ++ 2027, 2028, 2029, 4060, 4061, 4062, 4063, 4064, ++ 4065, 4066, 4067, 4068, 4069, 4070, 4071, 8144, ++ 8145, 8146, 8147, 8148, 8149, 8150, 8151, 8152, ++ 8153, 8154, 8155, 8156, 8157, 8158, 16318, 16319, ++ 16320, 16321, 16322, 16323, 16324, 16325, 16326, 16327, ++ 16328, 16329, 16330, 16331, 16332, 16333, 16334, 16335, ++ 32672, 32673, 32674, 32675, 32676, 32677, 32678, 32679, ++ 32680, 32681, 32682, 32683, 32684, 32685, 32686, 32687, ++ 32688, 32689, 32690, 32691, 32692, 32693, 32694, 65390, ++ 65391, 65392, 65393, 65394, 65395, 65396, 65397, 65398, ++ 65399, 65400, 65401, 65402, 65403, 65404, 65405, 65406, ++ 65407, 65408, 65409, 65410, 65411, 65412, 65413, 65414, ++ 65415, 65416, 65417, 65418, 65419, 65420, 65421, 65422, ++ 65423, 65424, 65425, 65426, 65427, 65428, 65429, 65430, ++ 65431, 65432, 65433, 65434, 65435, 65436, 65437, 65438, ++ 65439, 65440, 65441, 65442, 65443, 65444, 65445, 65446, ++ 65447, 65448, 65449, 65450, 65451, 65452, 65453, 65454, ++ 65455, 65456, 65457, 65458, 65459, 65460, 65461, 65462, ++ 65463, 65464, 65465, 65466, 65467, 65468, 65469, 65470, ++ 65471, 65472, 65473, 65474, 65475, 65476, 65477, 65478, ++ 65479, 65480, 65481, 65482, 65483, 65484, 65485, 65486, ++ 65487, 65488, 65489, 65490, 65491, 65492, 65493, 65494, ++ 65495, 65496, 65497, 65498, 65499, 65500, 65501, 65502, ++ 65503, 65504, 65505, 65506, 65507, 65508, 65509, 65510, ++ 65511, 65512, 65513, 65514, 65515, 65516, 65517, 65518, ++ 65519, 65520, 65521, 65522, 65523, 65524, 65525, 65526, ++ 65527, 65528, 65529, 65530, 65531, 65532, 65533, 65534, ++ 65535, + }; ++ + static const uint8_t dnxhd_1252_ac_bits[257] = { +- 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 2, 2, 3, 4, 4, 4, 5, 5, 6, 6, 6, 7, 7, 7, 8, 8, ++ 8, 8, 8, 8, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, ++ 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, ++ 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, 13, 13, 13, 13, 13, ++ 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, ++ 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, ++ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, ++ 16, + }; ++ + static const uint8_t dnxhd_1252_ac_level[257] = { +- 1, 1, 2, 3, 2, 0, 4, 5, 6, 7, 3, 8, 9, 10, 11, 12, 13, 14, 4, 5, 15, 16, 17, 18, 6, 19, 20, 21, 22, 23, 24, 7, 8, 25, 26, 27, 28, 29, 30, 31, 32, 9, 10, 33, 34, 35, 36, 37, 38, 39, 40, 41, 11, 12, 13, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 14, 15, 16, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 17, 18, 19, 20, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, +-}; +-static const uint8_t dnxhd_1252_ac_run_flag[257] = { +- 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-}; +-static const uint8_t dnxhd_1252_ac_index_flag[257] = { +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 3, 3, 5, 7, 5, 0, 9, 11, 13, 15, 7, 17, 19, 21, 23, 25, ++ 27, 29, 9, 11, 31, 33, 35, 37, 13, 39, 41, 43, 45, 47, 49, 15, ++ 17, 51, 53, 55, 57, 59, 61, 63, 65, 19, 21, 67, 69, 71, 73, 75, ++ 77, 79, 81, 83, 23, 25, 27, 85, 87, 89, 91, 93, 95, 97, 99,101, ++ 103,105,107, 29, 31, 33,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 35, 37, 39, 41, 9, 11, 13, 15, 17, 19, 21, 23, ++ 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 43, 45, 47, 49, 51, 45, ++ 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, ++ 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99,101,103,105,107,109, ++ 111,113,115,117,119,121,123,125,127,129, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, ++ 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, ++ 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, ++ 97, 99,101,103,105,107,109,111,113,115,117,119,121,123,125,127, ++ 129, ++}; ++ ++static const uint8_t dnxhd_1252_ac_flags[257] = { ++ 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, ++ 0, 0, 2, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2, ++ 2, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, + }; + + const CIDEntry ff_dnxhd_cid_table[] = { +- { 1237, 1920, 1080, 0, 606208, 606208, 4, 8, ++ { 1235, 1920, 1080, 0, 917504, 917504, 6, 10, 4, ++ dnxhd_1235_luma_weight, dnxhd_1235_chroma_weight, ++ dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits, ++ dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level, ++ dnxhd_1235_1241_ac_flags, ++ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run, ++ { 175, 185, 365, 440 } }, ++ { 1237, 1920, 1080, 0, 606208, 606208, 4, 8, 3, + dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, +- dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, ++ dnxhd_1237_ac_flags, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 115, 120, 145, 240, 290 } }, +- { 1238, 1920, 1080, 0, 917504, 917504, 4, 8, ++ { 1238, 1920, 1080, 0, 917504, 917504, 4, 8, 4, + dnxhd_1238_luma_weight, dnxhd_1238_chroma_weight, + dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, + dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, +- dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, +- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, ++ dnxhd_1238_ac_flags, ++ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run, + { 175, 185, 220, 365, 440 } }, +- { 1241, 1920, 1080, 1, 917504, 458752, 6, 10, ++ { 1241, 1920, 1080, 1, 917504, 458752, 6, 10, 4, + dnxhd_1241_luma_weight, dnxhd_1241_chroma_weight, +- dnxhd_1241_dc_codes, dnxhd_1241_dc_bits, +- dnxhd_1241_ac_codes, dnxhd_1241_ac_bits, dnxhd_1241_ac_level, +- dnxhd_1241_ac_run_flag, dnxhd_1241_ac_index_flag, +- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1241_run, ++ dnxhd_1235_1241_dc_codes, dnxhd_1235_1241_dc_bits, ++ dnxhd_1235_1241_ac_codes, dnxhd_1235_1241_ac_bits, dnxhd_1235_1241_ac_level, ++ dnxhd_1235_1241_ac_flags, ++ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1235_1241_run, + { 185, 220 } }, +- { 1242, 1920, 1080, 1, 606208, 303104, 4, 8, ++ { 1242, 1920, 1080, 1, 606208, 303104, 4, 8, 3, + dnxhd_1242_luma_weight, dnxhd_1242_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, +- dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, ++ dnxhd_1237_ac_flags, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 120, 145 } }, +- { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, ++ { 1243, 1920, 1080, 1, 917504, 458752, 4, 8, 4, + dnxhd_1243_luma_weight, dnxhd_1243_chroma_weight, + dnxhd_1238_dc_codes, dnxhd_1238_dc_bits, + dnxhd_1238_ac_codes, dnxhd_1238_ac_bits, dnxhd_1238_ac_level, +- dnxhd_1238_ac_run_flag, dnxhd_1238_ac_index_flag, +- dnxhd_1238_run_codes, dnxhd_1238_run_bits, dnxhd_1238_run, ++ dnxhd_1238_ac_flags, ++ dnxhd_1235_1238_1241_run_codes, dnxhd_1235_1238_1241_run_bits, dnxhd_1238_run, + { 185, 220 } }, +- { 1251, 1280, 720, 0, 458752, 458752, 4, 8, ++ { 1250, 1280, 720, 0, 458752, 458752, 6, 10, 4, ++ dnxhd_1250_luma_weight, dnxhd_1250_chroma_weight, ++ dnxhd_1250_dc_codes, dnxhd_1250_dc_bits, ++ dnxhd_1250_ac_codes, dnxhd_1250_ac_bits, dnxhd_1250_ac_level, ++ dnxhd_1250_ac_flags, ++ dnxhd_1250_run_codes, dnxhd_1250_run_bits, dnxhd_1250_run, ++ { 90, 180, 220 } }, ++ { 1251, 1280, 720, 0, 458752, 458752, 4, 8, 4, + dnxhd_1251_luma_weight, dnxhd_1251_chroma_weight, + dnxhd_1251_dc_codes, dnxhd_1251_dc_bits, + dnxhd_1251_ac_codes, dnxhd_1251_ac_bits, dnxhd_1251_ac_level, +- dnxhd_1251_ac_run_flag, dnxhd_1251_ac_index_flag, ++ dnxhd_1251_ac_flags, + dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, + { 90, 110, 175, 220 } }, +- { 1252, 1280, 720, 0, 303104, 303104, 4, 8, ++ { 1252, 1280, 720, 0, 303104, 303104, 4, 8, 5, + dnxhd_1252_luma_weight, dnxhd_1252_chroma_weight, + dnxhd_1252_dc_codes, dnxhd_1252_dc_bits, + dnxhd_1252_ac_codes, dnxhd_1252_ac_bits, dnxhd_1252_ac_level, +- dnxhd_1252_ac_run_flag, dnxhd_1252_ac_index_flag, ++ dnxhd_1252_ac_flags, + dnxhd_1251_run_codes, dnxhd_1251_run_bits, dnxhd_1251_run, + { 60, 75, 115, 145 } }, +- { 1253, 1920, 1080, 0, 188416, 188416, 4, 8, ++ { 1253, 1920, 1080, 0, 188416, 188416, 4, 8, 3, + dnxhd_1237_luma_weight, dnxhd_1237_chroma_weight, + dnxhd_1237_dc_codes, dnxhd_1237_dc_bits, + dnxhd_1237_ac_codes, dnxhd_1237_ac_bits, dnxhd_1237_ac_level, +- dnxhd_1237_ac_run_flag, dnxhd_1237_ac_index_flag, ++ dnxhd_1237_ac_flags, + dnxhd_1237_run_codes, dnxhd_1237_run_bits, dnxhd_1237_run, + { 36, 45, 75, 90 } }, + }; +@@ -407,7 +1027,7 @@ + return -1; + } + +-int ff_dnxhd_find_cid(AVCodecContext *avctx) ++int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth) + { + int i, j; + int mbs = avctx->bit_rate/1000000; +@@ -417,7 +1037,7 @@ + const CIDEntry *cid = &ff_dnxhd_cid_table[i]; + if (cid->width == avctx->width && cid->height == avctx->height && + cid->interlaced == !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT) && +- cid->bit_depth == 8) { // until 10 bit is supported ++ cid->bit_depth == bit_depth) { + for (j = 0; j < sizeof(cid->bit_rates); j++) { + if (cid->bit_rates[j] == mbs) + return cid->cid; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddata.h 2012-05-14 14:08:53.612325450 +0200 +@@ -33,11 +33,12 @@ + unsigned int coding_unit_size; + int index_bits; + int bit_depth; ++ int eob_index; + const uint8_t *luma_weight, *chroma_weight; + const uint8_t *dc_codes, *dc_bits; + const uint16_t *ac_codes; + const uint8_t *ac_bits, *ac_level; +- const uint8_t *ac_run_flag, *ac_index_flag; ++ const uint8_t *ac_flags; + const uint16_t *run_codes; + const uint8_t *run_bits, *run; + int bit_rates[5]; ///< Helpher to choose variants, rounded to nearest 5Mb/s +@@ -46,6 +47,6 @@ + extern const CIDEntry ff_dnxhd_cid_table[]; + + int ff_dnxhd_get_cid_table(int cid); +-int ff_dnxhd_find_cid(AVCodecContext *avctx); ++int ff_dnxhd_find_cid(AVCodecContext *avctx, int bit_depth); + + #endif /* AVCODEC_DNXHDDATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhddec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhddec.c 2012-05-14 14:08:53.614325491 +0200 +@@ -1,6 +1,9 @@ + /* + * VC3/DNxHD decoder. + * Copyright (c) 2007 SmartJog S.A., Baptiste Coudurier ++ * Copyright (c) 2011 MirriAd Ltd ++ * ++ * 10 bit support added by MirriAd Ltd, Joseph Artsimovich + * + * This file is part of FFmpeg. + * +@@ -22,13 +25,14 @@ + //#define TRACE + //#define DEBUG + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "get_bits.h" + #include "dnxhddata.h" + #include "dsputil.h" ++#include "thread.h" + +-typedef struct { ++typedef struct DNXHDContext { + AVCodecContext *avctx; + AVFrame picture; + GetBitContext gb; +@@ -43,26 +47,35 @@ + DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; + ScanTable scantable; + const CIDEntry *cid_table; ++ int bit_depth; // 8, 10 or 0 if not initialized at all. ++ void (*decode_dct_block)(struct DNXHDContext *ctx, DCTELEM *block, ++ int n, int qscale); ++ int last_qscale; ++ int luma_scale[64]; ++ int chroma_scale[64]; + } DNXHDContext; + + #define DNXHD_VLC_BITS 9 + #define DNXHD_DC_VLC_BITS 7 + ++static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block, int n, int qscale); ++static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block, int n, int qscale); ++ + static av_cold int dnxhd_decode_init(AVCodecContext *avctx) + { + DNXHDContext *ctx = avctx->priv_data; + + ctx->avctx = avctx; +- dsputil_init(&ctx->dsp, avctx); + avctx->coded_frame = &ctx->picture; +- ctx->picture.type = FF_I_TYPE; ++ avcodec_get_frame_defaults(&ctx->picture); ++ ctx->picture.type = AV_PICTURE_TYPE_I; + ctx->picture.key_frame = 1; + return 0; + } + + static int dnxhd_init_vlc(DNXHDContext *ctx, int cid) + { +- if (!ctx->cid_table) { ++ if (cid != ctx->cid) { + int index; + + if ((index = ff_dnxhd_get_cid_table(cid)) < 0) { +@@ -70,10 +83,15 @@ + return -1; + } + ctx->cid_table = &ff_dnxhd_cid_table[index]; ++ ++ free_vlc(&ctx->ac_vlc); ++ free_vlc(&ctx->dc_vlc); ++ free_vlc(&ctx->run_vlc); ++ + init_vlc(&ctx->ac_vlc, DNXHD_VLC_BITS, 257, + ctx->cid_table->ac_bits, 1, 1, + ctx->cid_table->ac_codes, 2, 2, 0); +- init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->cid_table->bit_depth+4, ++ init_vlc(&ctx->dc_vlc, DNXHD_DC_VLC_BITS, ctx->bit_depth + 4, + ctx->cid_table->dc_bits, 1, 1, + ctx->cid_table->dc_codes, 1, 1, 0); + init_vlc(&ctx->run_vlc, DNXHD_VLC_BITS, 62, +@@ -81,6 +99,7 @@ + ctx->cid_table->run_codes, 2, 2, 0); + + ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ff_zigzag_direct); ++ ctx->cid = cid; + } + return 0; + } +@@ -88,7 +107,7 @@ + static int dnxhd_decode_header(DNXHDContext *ctx, const uint8_t *buf, int buf_size, int first_field) + { + static const uint8_t header_prefix[] = { 0x00, 0x00, 0x02, 0x80, 0x01 }; +- int i; ++ int i, cid; + + if (buf_size < 0x280) + return -1; +@@ -107,17 +126,30 @@ + ctx->height = AV_RB16(buf + 0x18); + ctx->width = AV_RB16(buf + 0x1a); + +- av_dlog(ctx->avctx, "width %d, heigth %d\n", ctx->width, ctx->height); ++ av_dlog(ctx->avctx, "width %d, height %d\n", ctx->width, ctx->height); + + if (buf[0x21] & 0x40) { +- av_log(ctx->avctx, AV_LOG_ERROR, "10 bit per component\n"); +- return -1; ++ ctx->avctx->pix_fmt = PIX_FMT_YUV422P10; ++ ctx->avctx->bits_per_raw_sample = 10; ++ if (ctx->bit_depth != 10) { ++ dsputil_init(&ctx->dsp, ctx->avctx); ++ ctx->bit_depth = 10; ++ ctx->decode_dct_block = dnxhd_decode_dct_block_10; ++ } ++ } else { ++ ctx->avctx->pix_fmt = PIX_FMT_YUV422P; ++ ctx->avctx->bits_per_raw_sample = 8; ++ if (ctx->bit_depth != 8) { ++ dsputil_init(&ctx->dsp, ctx->avctx); ++ ctx->bit_depth = 8; ++ ctx->decode_dct_block = dnxhd_decode_dct_block_8; ++ } + } + +- ctx->cid = AV_RB32(buf + 0x28); +- av_dlog(ctx->avctx, "compression id %d\n", ctx->cid); ++ cid = AV_RB32(buf + 0x28); ++ av_dlog(ctx->avctx, "compression id %d\n", cid); + +- if (dnxhd_init_vlc(ctx, ctx->cid) < 0) ++ if (dnxhd_init_vlc(ctx, cid) < 0) + return -1; + + if (buf_size < ctx->cid_table->coding_unit_size) { +@@ -151,88 +183,129 @@ + return 0; + } + +-static int dnxhd_decode_dc(DNXHDContext *ctx) ++static av_always_inline void dnxhd_decode_dct_block(DNXHDContext *ctx, ++ DCTELEM *block, int n, ++ int qscale, ++ int index_bits, ++ int level_bias, ++ int level_shift) + { +- int len; +- +- len = get_vlc2(&ctx->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1); +- return len ? get_xbits(&ctx->gb, len) : 0; +-} +- +-static void dnxhd_decode_dct_block(DNXHDContext *ctx, DCTELEM *block, int n, int qscale) +-{ +- int i, j, index, index2; ++ int i, j, index1, index2, len, flags; + int level, component, sign; +- const uint8_t *weigth_matrix; ++ const int *scale; ++ const uint8_t *weight_matrix; ++ const uint8_t *ac_level = ctx->cid_table->ac_level; ++ const uint8_t *ac_flags = ctx->cid_table->ac_flags; ++ const int eob_index = ctx->cid_table->eob_index; ++ OPEN_READER(bs, &ctx->gb); + + if (n&2) { + component = 1 + (n&1); +- weigth_matrix = ctx->cid_table->chroma_weight; ++ scale = ctx->chroma_scale; ++ weight_matrix = ctx->cid_table->chroma_weight; + } else { + component = 0; +- weigth_matrix = ctx->cid_table->luma_weight; ++ scale = ctx->luma_scale; ++ weight_matrix = ctx->cid_table->luma_weight; + } + +- ctx->last_dc[component] += dnxhd_decode_dc(ctx); ++ UPDATE_CACHE(bs, &ctx->gb); ++ GET_VLC(len, bs, &ctx->gb, ctx->dc_vlc.table, DNXHD_DC_VLC_BITS, 1); ++ if (len) { ++ level = GET_CACHE(bs, &ctx->gb); ++ LAST_SKIP_BITS(bs, &ctx->gb, len); ++ sign = ~level >> 31; ++ level = (NEG_USR32(sign ^ level, len) ^ sign) - sign; ++ ctx->last_dc[component] += level; ++ } + block[0] = ctx->last_dc[component]; + //av_log(ctx->avctx, AV_LOG_DEBUG, "dc %d\n", block[0]); +- for (i = 1; ; i++) { +- index = get_vlc2(&ctx->gb, ctx->ac_vlc.table, DNXHD_VLC_BITS, 2); +- //av_log(ctx->avctx, AV_LOG_DEBUG, "index %d\n", index); +- level = ctx->cid_table->ac_level[index]; +- if (!level) { /* EOB */ +- //av_log(ctx->avctx, AV_LOG_DEBUG, "EOB\n"); +- return; +- } +- sign = get_sbits(&ctx->gb, 1); + +- if (ctx->cid_table->ac_index_flag[index]) { +- level += get_bits(&ctx->gb, ctx->cid_table->index_bits)<<6; ++ i = 0; ++ ++ UPDATE_CACHE(bs, &ctx->gb); ++ GET_VLC(index1, bs, &ctx->gb, ctx->ac_vlc.table, ++ DNXHD_VLC_BITS, 2); ++ ++ while (index1 != eob_index) { ++ level = ac_level[index1]; ++ flags = ac_flags[index1]; ++ ++ sign = SHOW_SBITS(bs, &ctx->gb, 1); ++ SKIP_BITS(bs, &ctx->gb, 1); ++ ++ if (flags & 1) { ++ level += SHOW_UBITS(bs, &ctx->gb, index_bits) << 7; ++ SKIP_BITS(bs, &ctx->gb, index_bits); + } + +- if (ctx->cid_table->ac_run_flag[index]) { +- index2 = get_vlc2(&ctx->gb, ctx->run_vlc.table, DNXHD_VLC_BITS, 2); ++ if (flags & 2) { ++ UPDATE_CACHE(bs, &ctx->gb); ++ GET_VLC(index2, bs, &ctx->gb, ctx->run_vlc.table, ++ DNXHD_VLC_BITS, 2); + i += ctx->cid_table->run[index2]; + } + +- if (i > 63) { ++ if (++i > 63) { + av_log(ctx->avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", n, i); +- return; ++ break; + } + + j = ctx->scantable.permutated[i]; + //av_log(ctx->avctx, AV_LOG_DEBUG, "j %d\n", j); +- //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weigth %d\n", level, weigth_matrix[i]); +- level = (2*level+1) * qscale * weigth_matrix[i]; +- if (ctx->cid_table->bit_depth == 10) { +- if (weigth_matrix[i] != 8) +- level += 8; +- level >>= 4; +- } else { +- if (weigth_matrix[i] != 32) +- level += 32; +- level >>= 6; +- } ++ //av_log(ctx->avctx, AV_LOG_DEBUG, "level %d, weight %d\n", level, weight_matrix[i]); ++ level *= scale[i]; ++ if (level_bias < 32 || weight_matrix[i] != level_bias) ++ level += level_bias; ++ level >>= level_shift; ++ + //av_log(NULL, AV_LOG_DEBUG, "i %d, j %d, end level %d\n", i, j, level); + block[j] = (level^sign) - sign; ++ ++ UPDATE_CACHE(bs, &ctx->gb); ++ GET_VLC(index1, bs, &ctx->gb, ctx->ac_vlc.table, ++ DNXHD_VLC_BITS, 2); + } ++ ++ CLOSE_READER(bs, &ctx->gb); ++} ++ ++static void dnxhd_decode_dct_block_8(DNXHDContext *ctx, DCTELEM *block, ++ int n, int qscale) ++{ ++ dnxhd_decode_dct_block(ctx, block, n, qscale, 4, 32, 6); ++} ++ ++static void dnxhd_decode_dct_block_10(DNXHDContext *ctx, DCTELEM *block, ++ int n, int qscale) ++{ ++ dnxhd_decode_dct_block(ctx, block, n, qscale, 6, 8, 4); + } + + static int dnxhd_decode_macroblock(DNXHDContext *ctx, int x, int y) + { ++ int shift1 = ctx->bit_depth == 10; + int dct_linesize_luma = ctx->picture.linesize[0]; + int dct_linesize_chroma = ctx->picture.linesize[1]; + uint8_t *dest_y, *dest_u, *dest_v; +- int dct_offset; ++ int dct_y_offset, dct_x_offset; + int qscale, i; + + qscale = get_bits(&ctx->gb, 11); + skip_bits1(&ctx->gb); + //av_log(ctx->avctx, AV_LOG_DEBUG, "qscale %d\n", qscale); + ++ if (qscale != ctx->last_qscale) { ++ for (i = 0; i < 64; i++) { ++ ctx->luma_scale[i] = qscale * ctx->cid_table->luma_weight[i]; ++ ctx->chroma_scale[i] = qscale * ctx->cid_table->chroma_weight[i]; ++ } ++ ctx->last_qscale = qscale; ++ } ++ + for (i = 0; i < 8; i++) { + ctx->dsp.clear_block(ctx->blocks[i]); +- dnxhd_decode_dct_block(ctx, ctx->blocks[i], i, qscale); ++ ctx->decode_dct_block(ctx, ctx->blocks[i], i, qscale); + } + + if (ctx->picture.interlaced_frame) { +@@ -240,9 +313,9 @@ + dct_linesize_chroma <<= 1; + } + +- dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << 4); +- dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << 3); +- dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << 3); ++ dest_y = ctx->picture.data[0] + ((y * dct_linesize_luma) << 4) + (x << (4 + shift1)); ++ dest_u = ctx->picture.data[1] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1)); ++ dest_v = ctx->picture.data[2] + ((y * dct_linesize_chroma) << 4) + (x << (3 + shift1)); + + if (ctx->cur_field) { + dest_y += ctx->picture.linesize[0]; +@@ -250,18 +323,19 @@ + dest_v += ctx->picture.linesize[2]; + } + +- dct_offset = dct_linesize_luma << 3; +- ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]); +- ctx->dsp.idct_put(dest_y + 8, dct_linesize_luma, ctx->blocks[1]); +- ctx->dsp.idct_put(dest_y + dct_offset, dct_linesize_luma, ctx->blocks[4]); +- ctx->dsp.idct_put(dest_y + dct_offset + 8, dct_linesize_luma, ctx->blocks[5]); ++ dct_y_offset = dct_linesize_luma << 3; ++ dct_x_offset = 8 << shift1; ++ ctx->dsp.idct_put(dest_y, dct_linesize_luma, ctx->blocks[0]); ++ ctx->dsp.idct_put(dest_y + dct_x_offset, dct_linesize_luma, ctx->blocks[1]); ++ ctx->dsp.idct_put(dest_y + dct_y_offset, dct_linesize_luma, ctx->blocks[4]); ++ ctx->dsp.idct_put(dest_y + dct_y_offset + dct_x_offset, dct_linesize_luma, ctx->blocks[5]); + + if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) { +- dct_offset = dct_linesize_chroma << 3; +- ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]); +- ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]); +- ctx->dsp.idct_put(dest_u + dct_offset, dct_linesize_chroma, ctx->blocks[6]); +- ctx->dsp.idct_put(dest_v + dct_offset, dct_linesize_chroma, ctx->blocks[7]); ++ dct_y_offset = dct_linesize_chroma << 3; ++ ctx->dsp.idct_put(dest_u, dct_linesize_chroma, ctx->blocks[2]); ++ ctx->dsp.idct_put(dest_v, dct_linesize_chroma, ctx->blocks[3]); ++ ctx->dsp.idct_put(dest_u + dct_y_offset, dct_linesize_chroma, ctx->blocks[6]); ++ ctx->dsp.idct_put(dest_v + dct_y_offset, dct_linesize_chroma, ctx->blocks[7]); + } + + return 0; +@@ -273,7 +347,7 @@ + for (y = 0; y < ctx->mb_height; y++) { + ctx->last_dc[0] = + ctx->last_dc[1] = +- ctx->last_dc[2] = 1<<(ctx->cid_table->bit_depth+2); // for levels +2^(bitdepth-1) ++ ctx->last_dc[2] = 1 << (ctx->bit_depth + 2); // for levels +2^(bitdepth-1) + init_get_bits(&ctx->gb, buf + ctx->mb_scan_index[y], (buf_size - ctx->mb_scan_index[y]) << 3); + for (x = 0; x < ctx->mb_width; x++) { + //START_TIMER; +@@ -292,6 +366,7 @@ + DNXHDContext *ctx = avctx->priv_data; + AVFrame *picture = data; + int first_field = 1; ++ int ret; + + av_dlog(avctx, "frame size %d\n", buf_size); + +@@ -306,20 +381,21 @@ + first_field = 1; + } + +- avctx->pix_fmt = PIX_FMT_YUV422P; + if (av_image_check_size(ctx->width, ctx->height, 0, avctx)) + return -1; + avcodec_set_dimensions(avctx, ctx->width, ctx->height); + + if (first_field) { + if (ctx->picture.data[0]) +- avctx->release_buffer(avctx, &ctx->picture); +- if (avctx->get_buffer(avctx, &ctx->picture) < 0) { ++ ff_thread_release_buffer(avctx, &ctx->picture); ++ if ((ret = ff_thread_get_buffer(avctx, &ctx->picture)) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; ++ return ret; + } + } + ++ ff_thread_finish_setup(avctx); ++ + dnxhd_decode_macroblocks(ctx, buf + 0x280, buf_size - 0x280); + + if (first_field && ctx->picture.interlaced_frame) { +@@ -339,7 +415,7 @@ + DNXHDContext *ctx = avctx->priv_data; + + if (ctx->picture.data[0]) +- avctx->release_buffer(avctx, &ctx->picture); ++ ff_thread_release_buffer(avctx, &ctx->picture); + free_vlc(&ctx->ac_vlc); + free_vlc(&ctx->dc_vlc); + free_vlc(&ctx->run_vlc); +@@ -347,14 +423,13 @@ + } + + AVCodec ff_dnxhd_decoder = { +- "dnxhd", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DNXHD, +- sizeof(DNXHDContext), +- dnxhd_decode_init, +- NULL, +- dnxhd_decode_close, +- dnxhd_decode_frame, +- CODEC_CAP_DR1, ++ .name = "dnxhd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DNXHD, ++ .priv_data_size = sizeof(DNXHDContext), ++ .init = dnxhd_decode_init, ++ .close = dnxhd_decode_close, ++ .decode = dnxhd_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, + .long_name = NULL_IF_CONFIG_SMALL("VC3/DNxHD"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhdenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhdenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhdenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhdenc.c 2012-05-14 14:08:53.617325551 +0200 +@@ -1,8 +1,10 @@ + /* + * VC3/DNxHD encoder + * Copyright (c) 2007 Baptiste Coudurier ++ * Copyright (c) 2011 MirriAd Ltd + * + * VC-3 encoder funded by the British Broadcasting Corporation ++ * 10 bit support added by MirriAd Ltd, Joseph Artsimovich + * + * This file is part of FFmpeg. + * +@@ -24,16 +26,25 @@ + //#define DEBUG + #define RC_VARIANCE 1 // use variance or ssd for fast rc + ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" ++#include "mpegvideo_common.h" + #include "dnxhdenc.h" + +-int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++#define DNX10BIT_QMAT_SHIFT 18 // The largest value that will not lead to overflow for 10bit samples. ++ ++static const AVOption options[]={ ++ {"nitris_compat", "encode with Avid Nitris compatibility", offsetof(DNXHDEncContext, nitris_compat), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, VE}, ++{NULL} ++}; ++static const AVClass class = { "dnxhd", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; + + #define LAMBDA_FRAC_BITS 10 + +-static av_always_inline void dnxhd_get_pixels_8x4(DCTELEM *restrict block, const uint8_t *pixels, int line_size) ++static void dnxhd_8bit_get_pixels_8x4_sym(DCTELEM *restrict block, const uint8_t *pixels, int line_size) + { + int i; + for (i = 0; i < 4; i++) { +@@ -44,10 +55,48 @@ + pixels += line_size; + block += 8; + } +- memcpy(block , block- 8, sizeof(*block)*8); +- memcpy(block+ 8, block-16, sizeof(*block)*8); +- memcpy(block+16, block-24, sizeof(*block)*8); +- memcpy(block+24, block-32, sizeof(*block)*8); ++ memcpy(block, block - 8, sizeof(*block) * 8); ++ memcpy(block + 8, block - 16, sizeof(*block) * 8); ++ memcpy(block + 16, block - 24, sizeof(*block) * 8); ++ memcpy(block + 24, block - 32, sizeof(*block) * 8); ++} ++ ++static av_always_inline void dnxhd_10bit_get_pixels_8x4_sym(DCTELEM *restrict block, const uint8_t *pixels, int line_size) ++{ ++ int i; ++ ++ block += 32; ++ ++ for (i = 0; i < 4; i++) { ++ memcpy(block + i * 8, pixels + i * line_size, 8 * sizeof(*block)); ++ memcpy(block - (i+1) * 8, pixels + i * line_size, 8 * sizeof(*block)); ++ } ++} ++ ++static int dnxhd_10bit_dct_quantize(MpegEncContext *ctx, DCTELEM *block, ++ int n, int qscale, int *overflow) ++{ ++ const uint8_t *scantable= ctx->intra_scantable.scantable; ++ const int *qmat = n<4 ? ctx->q_intra_matrix[qscale] : ctx->q_chroma_intra_matrix[qscale]; ++ int last_non_zero = 0; ++ int i; ++ ++ ctx->dsp.fdct(block); ++ ++ // Divide by 4 with rounding, to compensate scaling of DCT coefficients ++ block[0] = (block[0] + 2) >> 2; ++ ++ for (i = 1; i < 64; ++i) { ++ int j = scantable[i]; ++ int sign = block[j] >> 31; ++ int level = (block[j] ^ sign) - sign; ++ level = level * qmat[j] >> DNX10BIT_QMAT_SHIFT; ++ block[j] = (level ^ sign) - sign; ++ if (level) ++ last_non_zero = i; ++ } ++ ++ return last_non_zero; + } + + static int dnxhd_init_vlc(DNXHDEncContext *ctx) +@@ -56,9 +105,9 @@ + int max_level = 1<<(ctx->cid_table->bit_depth+2); + + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_codes, max_level*4*sizeof(*ctx->vlc_codes), fail); +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits , max_level*4*sizeof(*ctx->vlc_bits ), fail); +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2 , fail); +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits , 63 , fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->vlc_bits, max_level*4*sizeof(*ctx->vlc_bits) , fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_codes, 63*2, fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->run_bits, 63, fail); + + ctx->vlc_codes += max_level*2; + ctx->vlc_bits += max_level*2; +@@ -73,9 +122,9 @@ + alevel -= offset<<6; + } + for (j = 0; j < 257; j++) { +- if (ctx->cid_table->ac_level[j] == alevel && +- (!offset || (ctx->cid_table->ac_index_flag[j] && offset)) && +- (!run || (ctx->cid_table->ac_run_flag [j] && run))) { ++ if (ctx->cid_table->ac_level[j] >> 1 == alevel && ++ (!offset || (ctx->cid_table->ac_flags[j] & 1) && offset) && ++ (!run || (ctx->cid_table->ac_flags[j] & 2) && run)) { + assert(!ctx->vlc_codes[index]); + if (alevel) { + ctx->vlc_codes[index] = (ctx->cid_table->ac_codes[j]<<1)|(sign&1); +@@ -110,31 +159,60 @@ + // init first elem to 1 to avoid div by 0 in convert_matrix + uint16_t weight_matrix[64] = {1,}; // convert_matrix needs uint16_t* + int qscale, i; ++ const uint8_t *luma_weight_table = ctx->cid_table->luma_weight; ++ const uint8_t *chroma_weight_table = ctx->cid_table->chroma_weight; + +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail); +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int) , fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l, (ctx->m.avctx->qmax+1) * 64 * sizeof(int), fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c, (ctx->m.avctx->qmax+1) * 64 * sizeof(int), fail); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_l16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->qmatrix_c16, (ctx->m.avctx->qmax+1) * 64 * 2 * sizeof(uint16_t), fail); + +- for (i = 1; i < 64; i++) { +- int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; +- weight_matrix[j] = ctx->cid_table->luma_weight[i]; +- } +- ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix, +- ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); +- for (i = 1; i < 64; i++) { +- int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; +- weight_matrix[j] = ctx->cid_table->chroma_weight[i]; +- } +- ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix, +- ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); +- for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { +- for (i = 0; i < 64; i++) { +- ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2; +- ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2; +- ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2; ++ if (ctx->cid_table->bit_depth == 8) { ++ for (i = 1; i < 64; i++) { ++ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; ++ weight_matrix[j] = ctx->cid_table->luma_weight[i]; ++ } ++ ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_l, ctx->qmatrix_l16, weight_matrix, ++ ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); ++ for (i = 1; i < 64; i++) { ++ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; ++ weight_matrix[j] = ctx->cid_table->chroma_weight[i]; ++ } ++ ff_convert_matrix(&ctx->m.dsp, ctx->qmatrix_c, ctx->qmatrix_c16, weight_matrix, ++ ctx->m.intra_quant_bias, 1, ctx->m.avctx->qmax, 1); ++ ++ for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { ++ for (i = 0; i < 64; i++) { ++ ctx->qmatrix_l [qscale] [i] <<= 2; ctx->qmatrix_c [qscale] [i] <<= 2; ++ ctx->qmatrix_l16[qscale][0][i] <<= 2; ctx->qmatrix_l16[qscale][1][i] <<= 2; ++ ctx->qmatrix_c16[qscale][0][i] <<= 2; ctx->qmatrix_c16[qscale][1][i] <<= 2; ++ } ++ } ++ } else { ++ // 10-bit ++ for (qscale = 1; qscale <= ctx->m.avctx->qmax; qscale++) { ++ for (i = 1; i < 64; i++) { ++ int j = ctx->m.dsp.idct_permutation[ff_zigzag_direct[i]]; ++ ++ // The quantization formula from the VC-3 standard is: ++ // quantized = sign(block[i]) * floor(abs(block[i]/s) * p / (qscale * weight_table[i])) ++ // Where p is 32 for 8-bit samples and 8 for 10-bit ones. ++ // The s factor compensates scaling of DCT coefficients done by the DCT routines, ++ // and therefore is not present in standard. It's 8 for 8-bit samples and 4 for 10-bit ones. ++ // We want values of ctx->qtmatrix_l and ctx->qtmatrix_r to be: ++ // ((1 << DNX10BIT_QMAT_SHIFT) * (p / s)) / (qscale * weight_table[i]) ++ // For 10-bit samples, p / s == 2 ++ ctx->qmatrix_l[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) / (qscale * luma_weight_table[i]); ++ ctx->qmatrix_c[qscale][j] = (1 << (DNX10BIT_QMAT_SHIFT + 1)) / (qscale * chroma_weight_table[i]); ++ } + } + } ++ ++ ctx->m.q_chroma_intra_matrix16 = ctx->qmatrix_c16; ++ ctx->m.q_chroma_intra_matrix = ctx->qmatrix_c; ++ ctx->m.q_intra_matrix16 = ctx->qmatrix_l16; ++ ctx->m.q_intra_matrix = ctx->qmatrix_l; ++ + return 0; + fail: + return -1; +@@ -146,7 +224,7 @@ + if (ctx->m.avctx->mb_decision != FF_MB_DECISION_RD) + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_cmp, ctx->m.mb_num*sizeof(RCCMPEntry), fail); + +- ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4) * 8; ++ ctx->frame_bits = (ctx->cid_table->coding_unit_size - 640 - 4 - ctx->min_padding) * 8; + ctx->qscale = 1; + ctx->lambda = 2<priv_data; +- int i, index; ++ int i, index, bit_depth; ++ ++ switch (avctx->pix_fmt) { ++ case PIX_FMT_YUV422P: ++ bit_depth = 8; ++ break; ++ case PIX_FMT_YUV422P10: ++ bit_depth = 10; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "pixel format is incompatible with DNxHD\n"); ++ return -1; ++ } + +- ctx->cid = ff_dnxhd_find_cid(avctx); +- if (!ctx->cid || avctx->pix_fmt != PIX_FMT_YUV422P) { ++ ctx->cid = ff_dnxhd_find_cid(avctx, bit_depth); ++ if (!ctx->cid) { + av_log(avctx, AV_LOG_ERROR, "video parameters incompatible with DNxHD\n"); + return -1; + } +@@ -173,15 +263,25 @@ + ctx->m.mb_intra = 1; + ctx->m.h263_aic = 1; + +- ctx->get_pixels_8x4_sym = dnxhd_get_pixels_8x4; ++ avctx->bits_per_raw_sample = ctx->cid_table->bit_depth; + + dsputil_init(&ctx->m.dsp, avctx); + ff_dct_common_init(&ctx->m); ++ if (!ctx->m.dct_quantize) ++ ctx->m.dct_quantize = dct_quantize_c; ++ ++ if (ctx->cid_table->bit_depth == 10) { ++ ctx->m.dct_quantize = dnxhd_10bit_dct_quantize; ++ ctx->get_pixels_8x4_sym = dnxhd_10bit_get_pixels_8x4_sym; ++ ctx->block_width_l2 = 4; ++ } else { ++ ctx->get_pixels_8x4_sym = dnxhd_8bit_get_pixels_8x4_sym; ++ ctx->block_width_l2 = 3; ++ } ++ + #if HAVE_MMX + ff_dnxhd_init_mmx(ctx); + #endif +- if (!ctx->m.dct_quantize) +- ctx->m.dct_quantize = dct_quantize_c; + + ctx->m.mb_height = (avctx->height + 15) / 16; + ctx->m.mb_width = (avctx->width + 15) / 16; +@@ -198,6 +298,10 @@ + if (dnxhd_init_qmat(ctx, ctx->m.intra_quant_bias, 0) < 0) // XXX tune lbias/cbias + return -1; + ++ // Avid Nitris hardware decoder requires a minimum amount of padding in the coding unit payload ++ if (ctx->nitris_compat) ++ ctx->min_padding = 1600; ++ + if (dnxhd_init_vlc(ctx) < 0) + return -1; + if (dnxhd_init_rc(ctx) < 0) +@@ -206,10 +310,10 @@ + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_size, ctx->m.mb_height*sizeof(uint32_t), fail); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->slice_offs, ctx->m.mb_height*sizeof(uint32_t), fail); + FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_bits, ctx->m.mb_num *sizeof(uint16_t), fail); +- FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t) , fail); ++ FF_ALLOCZ_OR_GOTO(ctx->m.avctx, ctx->mb_qscale, ctx->m.mb_num *sizeof(uint8_t), fail); + + ctx->frame.key_frame = 1; +- ctx->frame.pict_type = FF_I_TYPE; ++ ctx->frame.pict_type = AV_PICTURE_TYPE_I; + ctx->m.avctx->coded_frame = &ctx->frame; + + if (avctx->thread_count > MAX_THREADS) { +@@ -243,7 +347,7 @@ + AV_WB16(buf + 0x1a, avctx->width); // SPL + AV_WB16(buf + 0x1d, avctx->height>>ctx->interlaced); // NAL + +- buf[0x21] = 0x38; // FIXME 8 bit per comp ++ buf[0x21] = ctx->cid_table->bit_depth == 10 ? 0x58 : 0x38; + buf[0x22] = 0x88 + (ctx->interlaced<<2); + AV_WB32(buf + 0x28, ctx->cid); // CID + buf[0x2c] = ctx->interlaced ? 0 : 0x80; +@@ -309,15 +413,27 @@ + if (level) { + if (level < 0) { + level = (1-2*level) * qscale * weight_matrix[i]; +- if (weight_matrix[i] != 32) +- level += 32; +- level >>= 6; ++ if (ctx->cid_table->bit_depth == 10) { ++ if (weight_matrix[i] != 8) ++ level += 8; ++ level >>= 4; ++ } else { ++ if (weight_matrix[i] != 32) ++ level += 32; ++ level >>= 6; ++ } + level = -level; + } else { + level = (2*level+1) * qscale * weight_matrix[i]; +- if (weight_matrix[i] != 32) +- level += 32; +- level >>= 6; ++ if (ctx->cid_table->bit_depth == 10) { ++ if (weight_matrix[i] != 8) ++ level += 8; ++ level >>= 4; ++ } else { ++ if (weight_matrix[i] != 32) ++ level += 32; ++ level >>= 6; ++ } + } + block[j] = level; + } +@@ -329,7 +445,7 @@ + int score = 0; + int i; + for (i = 0; i < 64; i++) +- score += (block[i]-qblock[i])*(block[i]-qblock[i]); ++ score += (block[i] - qblock[i]) * (block[i] - qblock[i]); + return score; + } + +@@ -352,45 +468,42 @@ + + static av_always_inline void dnxhd_get_blocks(DNXHDEncContext *ctx, int mb_x, int mb_y) + { +- const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << 4); +- const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3); +- const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << 3); ++ const int bs = ctx->block_width_l2; ++ const int bw = 1 << bs; ++ const uint8_t *ptr_y = ctx->thread[0]->src[0] + ((mb_y << 4) * ctx->m.linesize) + (mb_x << bs+1); ++ const uint8_t *ptr_u = ctx->thread[0]->src[1] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs); ++ const uint8_t *ptr_v = ctx->thread[0]->src[2] + ((mb_y << 4) * ctx->m.uvlinesize) + (mb_x << bs); + DSPContext *dsp = &ctx->m.dsp; + +- dsp->get_pixels(ctx->blocks[0], ptr_y , ctx->m.linesize); +- dsp->get_pixels(ctx->blocks[1], ptr_y + 8, ctx->m.linesize); +- dsp->get_pixels(ctx->blocks[2], ptr_u , ctx->m.uvlinesize); +- dsp->get_pixels(ctx->blocks[3], ptr_v , ctx->m.uvlinesize); ++ dsp->get_pixels(ctx->blocks[0], ptr_y, ctx->m.linesize); ++ dsp->get_pixels(ctx->blocks[1], ptr_y + bw, ctx->m.linesize); ++ dsp->get_pixels(ctx->blocks[2], ptr_u, ctx->m.uvlinesize); ++ dsp->get_pixels(ctx->blocks[3], ptr_v, ctx->m.uvlinesize); + + if (mb_y+1 == ctx->m.mb_height && ctx->m.avctx->height == 1080) { + if (ctx->interlaced) { +- ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize); +- ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize); +- ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize); +- ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize); ++ ctx->get_pixels_8x4_sym(ctx->blocks[4], ptr_y + ctx->dct_y_offset, ctx->m.linesize); ++ ctx->get_pixels_8x4_sym(ctx->blocks[5], ptr_y + ctx->dct_y_offset + bw, ctx->m.linesize); ++ ctx->get_pixels_8x4_sym(ctx->blocks[6], ptr_u + ctx->dct_uv_offset, ctx->m.uvlinesize); ++ ctx->get_pixels_8x4_sym(ctx->blocks[7], ptr_v + ctx->dct_uv_offset, ctx->m.uvlinesize); + } else { +- dsp->clear_block(ctx->blocks[4]); dsp->clear_block(ctx->blocks[5]); +- dsp->clear_block(ctx->blocks[6]); dsp->clear_block(ctx->blocks[7]); ++ dsp->clear_block(ctx->blocks[4]); ++ dsp->clear_block(ctx->blocks[5]); ++ dsp->clear_block(ctx->blocks[6]); ++ dsp->clear_block(ctx->blocks[7]); + } + } else { +- dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset , ctx->m.linesize); +- dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + 8, ctx->m.linesize); +- dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset , ctx->m.uvlinesize); +- dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset , ctx->m.uvlinesize); ++ dsp->get_pixels(ctx->blocks[4], ptr_y + ctx->dct_y_offset, ctx->m.linesize); ++ dsp->get_pixels(ctx->blocks[5], ptr_y + ctx->dct_y_offset + bw, ctx->m.linesize); ++ dsp->get_pixels(ctx->blocks[6], ptr_u + ctx->dct_uv_offset, ctx->m.uvlinesize); ++ dsp->get_pixels(ctx->blocks[7], ptr_v + ctx->dct_uv_offset, ctx->m.uvlinesize); + } + } + + static av_always_inline int dnxhd_switch_matrix(DNXHDEncContext *ctx, int i) + { +- if (i&2) { +- ctx->m.q_intra_matrix16 = ctx->qmatrix_c16; +- ctx->m.q_intra_matrix = ctx->qmatrix_c; +- return 1 + (i&1); +- } else { +- ctx->m.q_intra_matrix16 = ctx->qmatrix_l16; +- ctx->m.q_intra_matrix = ctx->qmatrix_l; +- return 0; +- } ++ const static uint8_t component[8]={0,0,1,2,0,0,1,2}; ++ return component[i]; + } + + static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) +@@ -403,7 +516,7 @@ + + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = +- ctx->m.last_dc[2] = 1024; ++ ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2); + + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; +@@ -420,12 +533,14 @@ + int n = dnxhd_switch_matrix(ctx, i); + + memcpy(block, src_block, 64*sizeof(*block)); +- last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); ++ last_index = ctx->m.dct_quantize(&ctx->m, block, 4&(2*i), qscale, &overflow); + ac_bits += dnxhd_calc_ac_bits(ctx, block, last_index); + + diff = block[0] - ctx->m.last_dc[n]; + if (diff < 0) nbits = av_log2_16bit(-2*diff); + else nbits = av_log2_16bit( 2*diff); ++ ++ assert(nbits < ctx->cid_table->bit_depth + 4); + dc_bits += ctx->cid_table->dc_bits[nbits] + nbits; + + ctx->m.last_dc[n] = block[0]; +@@ -451,7 +566,7 @@ + + ctx->m.last_dc[0] = + ctx->m.last_dc[1] = +- ctx->m.last_dc[2] = 1024; ++ ctx->m.last_dc[2] = 1 << (ctx->cid_table->bit_depth + 2); + for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { + unsigned mb = mb_y * ctx->m.mb_width + mb_x; + int qscale = ctx->mb_qscale[mb]; +@@ -463,9 +578,8 @@ + + for (i = 0; i < 8; i++) { + DCTELEM *block = ctx->blocks[i]; +- int last_index, overflow; +- int n = dnxhd_switch_matrix(ctx, i); +- last_index = ctx->m.dct_quantize((MpegEncContext*)ctx, block, i, qscale, &overflow); ++ int overflow, n = dnxhd_switch_matrix(ctx, i); ++ int last_index = ctx->m.dct_quantize(&ctx->m, block, 4&(2*i), qscale, &overflow); + //START_TIMER; + dnxhd_encode_block(ctx, block, last_index, n); + //STOP_TIMER("encode_block"); +@@ -484,14 +598,14 @@ + for (mb_y = 0; mb_y < ctx->m.mb_height; mb_y++) { + int thread_size; + ctx->slice_offs[mb_y] = offset; +- ctx->slice_size[mb_y] = 0; +- for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { +- unsigned mb = mb_y * ctx->m.mb_width + mb_x; +- ctx->slice_size[mb_y] += ctx->mb_bits[mb]; +- } +- ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31; +- ctx->slice_size[mb_y] >>= 3; +- thread_size = ctx->slice_size[mb_y]; ++ ctx->slice_size[mb_y] = 0; ++ for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { ++ unsigned mb = mb_y * ctx->m.mb_width + mb_x; ++ ctx->slice_size[mb_y] += ctx->mb_bits[mb]; ++ } ++ ctx->slice_size[mb_y] = (ctx->slice_size[mb_y]+31)&~31; ++ ctx->slice_size[mb_y] >>= 3; ++ thread_size = ctx->slice_size[mb_y]; + offset += thread_size; + } + } +@@ -501,13 +615,40 @@ + DNXHDEncContext *ctx = avctx->priv_data; + int mb_y = jobnr, mb_x; + ctx = ctx->thread[threadnr]; +- for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) { +- unsigned mb = mb_y * ctx->m.mb_width + mb_x; +- uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize) + (mb_x<<4); +- int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize); +- int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)(sum*sum))>>8)+128)>>8; +- ctx->mb_cmp[mb].value = varc; +- ctx->mb_cmp[mb].mb = mb; ++ if (ctx->cid_table->bit_depth == 8) { ++ uint8_t *pix = ctx->thread[0]->src[0] + ((mb_y<<4) * ctx->m.linesize); ++ for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x, pix += 16) { ++ unsigned mb = mb_y * ctx->m.mb_width + mb_x; ++ int sum = ctx->m.dsp.pix_sum(pix, ctx->m.linesize); ++ int varc = (ctx->m.dsp.pix_norm1(pix, ctx->m.linesize) - (((unsigned)sum*sum)>>8)+128)>>8; ++ ctx->mb_cmp[mb].value = varc; ++ ctx->mb_cmp[mb].mb = mb; ++ } ++ } else { // 10-bit ++ int const linesize = ctx->m.linesize >> 1; ++ for (mb_x = 0; mb_x < ctx->m.mb_width; ++mb_x) { ++ uint16_t *pix = (uint16_t*)ctx->thread[0]->src[0] + ((mb_y << 4) * linesize) + (mb_x << 4); ++ unsigned mb = mb_y * ctx->m.mb_width + mb_x; ++ int sum = 0; ++ int sqsum = 0; ++ int mean, sqmean; ++ int i, j; ++ // Macroblocks are 16x16 pixels, unlike DCT blocks which are 8x8. ++ for (i = 0; i < 16; ++i) { ++ for (j = 0; j < 16; ++j) { ++ // Turn 16-bit pixels into 10-bit ones. ++ int const sample = (unsigned)pix[j] >> 6; ++ sum += sample; ++ sqsum += sample * sample; ++ // 2^10 * 2^10 * 16 * 16 = 2^28, which is less than INT_MAX ++ } ++ pix += linesize; ++ } ++ mean = sum >> 8; // 16*16 == 2^8 ++ sqmean = sqsum >> 8; ++ ctx->mb_cmp[mb].value = sqmean - mean * mean; ++ ctx->mb_cmp[mb].mb = mb; ++ } + } + return 0; + } +@@ -538,7 +679,8 @@ + int qscale = 1; + int mb = y*ctx->m.mb_width+x; + for (q = 1; q < avctx->qmax; q++) { +- unsigned score = ctx->mb_rc[q][mb].bits*lambda+(ctx->mb_rc[q][mb].ssd<mb_rc[q][mb].bits*lambda+ ++ ((unsigned)ctx->mb_rc[q][mb].ssd<>1; + else + lambda -= down_step; +- down_step *= 5; // XXX tune ? ++ down_step = FFMIN((int64_t)down_step*5, INT_MAX); + up_step = 1< +-#include "libavcodec/mpegvideo.h" +-#include "libavcodec/dnxhddata.h" ++ ++#include "mpegvideo.h" ++#include "dnxhddata.h" + + typedef struct { + uint16_t mb; +@@ -39,6 +40,7 @@ + } RCEntry; + + typedef struct DNXHDEncContext { ++ AVClass *class; + MpegEncContext m; ///< Used for quantization dsp functions + + AVFrame frame; +@@ -50,11 +52,18 @@ + + struct DNXHDEncContext *thread[MAX_THREADS]; + ++ // Because our samples are either 8 or 16 bits for 8-bit and 10-bit ++ // encoding respectively, these refer either to bytes or to two-byte words. + unsigned dct_y_offset; + unsigned dct_uv_offset; ++ unsigned block_width_l2; ++ + int interlaced; + int cur_field; + ++ int nitris_compat; ++ unsigned min_padding; ++ + DECLARE_ALIGNED(16, DCTELEM, blocks)[8][64]; + + int (*qmatrix_c) [64]; +@@ -75,8 +84,6 @@ + unsigned qscale; + unsigned lambda; + +- unsigned thread_size; +- + uint16_t *mb_bits; + uint8_t *mb_qscale; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhd_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhd_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dnxhd_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dnxhd_parser.c 2012-05-14 14:08:53.607325350 +0200 +@@ -87,9 +87,8 @@ + } + + AVCodecParser ff_dnxhd_parser = { +- { CODEC_ID_DNXHD }, +- sizeof(ParseContext), +- NULL, +- dnxhd_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_DNXHD }, ++ .priv_data_size = sizeof(ParseContext), ++ .parser_parse = dnxhd_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpcm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpcm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpcm.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpcm.c 2012-05-14 14:08:53.634325893 +0200 +@@ -39,17 +39,17 @@ + + #include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "bytestream.h" + + typedef struct DPCMContext { ++ AVFrame frame; + int channels; +- short roq_square_array[256]; +- long sample[2];//for SOL_DPCM +- const int *sol_table;//for SOL_DPCM ++ int16_t roq_square_array[256]; ++ int sample[2]; ///< previous sample (for SOL_DPCM) ++ const int8_t *sol_table; ///< delta table for SOL_DPCM + } DPCMContext; + +-#define SE_16BIT(x) if (x & 0x8000) x -= 0x10000; +- +-static const int interplay_delta_table[] = { ++static const int16_t interplay_delta_table[] = { + 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, +@@ -85,15 +85,17 @@ + + }; + +-static const int sol_table_old[16] = +- { 0x0, 0x1, 0x2 , 0x3, 0x6, 0xA, 0xF, 0x15, +- -0x15, -0xF, -0xA, -0x6, -0x3, -0x2, -0x1, 0x0}; +- +-static const int sol_table_new[16] = +- { 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15, +- 0x0, -0x1, -0x2, -0x3, -0x6, -0xA, -0xF, -0x15}; ++static const int8_t sol_table_old[16] = { ++ 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15, ++ -0x15, -0xF, -0xA, -0x6, -0x3, -0x2, -0x1, 0x0 ++}; + +-static const int sol_table_16[128] = { ++static const int8_t sol_table_new[16] = { ++ 0x0, 0x1, 0x2, 0x3, 0x6, 0xA, 0xF, 0x15, ++ 0x0, -0x1, -0x2, -0x3, -0x6, -0xA, -0xF, -0x15 ++}; ++ ++static const int16_t sol_table_16[128] = { + 0x000, 0x008, 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080, + 0x090, 0x0A0, 0x0B0, 0x0C0, 0x0D0, 0x0E0, 0x0F0, 0x100, 0x110, 0x120, + 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, 0x190, 0x1A0, 0x1B0, 0x1C0, +@@ -110,12 +112,15 @@ + }; + + +- + static av_cold int dpcm_decode_init(AVCodecContext *avctx) + { + DPCMContext *s = avctx->priv_data; + int i; +- short square; ++ ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_INFO, "invalid number of channels\n"); ++ return AVERROR(EINVAL); ++ } + + s->channels = avctx->channels; + s->sample[0] = s->sample[1] = 0; +@@ -125,25 +130,23 @@ + case CODEC_ID_ROQ_DPCM: + /* initialize square table */ + for (i = 0; i < 128; i++) { +- square = i * i; +- s->roq_square_array[i] = square; ++ int16_t square = i * i; ++ s->roq_square_array[i ] = square; + s->roq_square_array[i + 128] = -square; + } + break; + +- + case CODEC_ID_SOL_DPCM: + switch(avctx->codec_tag){ + case 1: +- s->sol_table=sol_table_old; ++ s->sol_table = sol_table_old; + s->sample[0] = s->sample[1] = 0x80; + break; + case 2: +- s->sol_table=sol_table_new; ++ s->sol_table = sol_table_new; + s->sample[0] = s->sample[1] = 0x80; + break; + case 3: +- s->sol_table=sol_table_16; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unknown SOL subcodec\n"); +@@ -155,163 +158,189 @@ + break; + } + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ if (avctx->codec->id == CODEC_ID_SOL_DPCM && avctx->codec_tag != 3) ++ avctx->sample_fmt = AV_SAMPLE_FMT_U8; ++ else ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +-static int dpcm_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++ ++static int dpcm_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; ++ const uint8_t *buf_end = buf + buf_size; + DPCMContext *s = avctx->priv_data; +- int in, out = 0; ++ int out = 0, ret; + int predictor[2]; +- int channel_number = 0; +- short *output_samples = data; +- int shift[2]; +- unsigned char byte; +- short diff; +- +- if (!buf_size) +- return 0; +- +- // almost every DPCM variant expands one byte of data into two +- if(*data_size/2 < buf_size) +- return -1; ++ int ch = 0; ++ int stereo = s->channels - 1; ++ int16_t *output_samples; ++ ++ if (stereo && (buf_size & 1)) { ++ buf_size--; ++ buf_end--; ++ } ++ ++ /* calculate output size */ ++ switch(avctx->codec->id) { ++ case CODEC_ID_ROQ_DPCM: ++ out = buf_size - 8; ++ break; ++ case CODEC_ID_INTERPLAY_DPCM: ++ out = buf_size - 6 - s->channels; ++ break; ++ case CODEC_ID_XAN_DPCM: ++ out = buf_size - 2 * s->channels; ++ break; ++ case CODEC_ID_SOL_DPCM: ++ if (avctx->codec_tag != 3) ++ out = buf_size * 2; ++ else ++ out = buf_size; ++ break; ++ } ++ if (out <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ if (out % s->channels) { ++ av_log(avctx, AV_LOG_WARNING, "channels have differing number of samples\n"); ++ } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = (out + s->channels - 1) / s->channels; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ output_samples = (int16_t *)s->frame.data[0]; + + switch(avctx->codec->id) { + + case CODEC_ID_ROQ_DPCM: +- if (s->channels == 1) +- predictor[0] = AV_RL16(&buf[6]); +- else { +- predictor[0] = buf[7] << 8; +- predictor[1] = buf[6] << 8; ++ buf += 6; ++ ++ if (stereo) { ++ predictor[1] = (int16_t)(bytestream_get_byte(&buf) << 8); ++ predictor[0] = (int16_t)(bytestream_get_byte(&buf) << 8); ++ } else { ++ predictor[0] = (int16_t)bytestream_get_le16(&buf); + } +- SE_16BIT(predictor[0]); +- SE_16BIT(predictor[1]); + + /* decode the samples */ +- for (in = 8, out = 0; in < buf_size; in++, out++) { +- predictor[channel_number] += s->roq_square_array[buf[in]]; +- predictor[channel_number] = av_clip_int16(predictor[channel_number]); +- output_samples[out] = predictor[channel_number]; ++ while (buf < buf_end) { ++ predictor[ch] += s->roq_square_array[*buf++]; ++ predictor[ch] = av_clip_int16(predictor[ch]); ++ *output_samples++ = predictor[ch]; + + /* toggle channel */ +- channel_number ^= s->channels - 1; ++ ch ^= stereo; + } + break; + + case CODEC_ID_INTERPLAY_DPCM: +- in = 6; /* skip over the stream mask and stream length */ +- predictor[0] = AV_RL16(&buf[in]); +- in += 2; +- SE_16BIT(predictor[0]) +- output_samples[out++] = predictor[0]; +- if (s->channels == 2) { +- predictor[1] = AV_RL16(&buf[in]); +- in += 2; +- SE_16BIT(predictor[1]) +- output_samples[out++] = predictor[1]; ++ buf += 6; /* skip over the stream mask and stream length */ ++ ++ for (ch = 0; ch < s->channels; ch++) { ++ predictor[ch] = (int16_t)bytestream_get_le16(&buf); ++ *output_samples++ = predictor[ch]; + } + +- while (in < buf_size) { +- predictor[channel_number] += interplay_delta_table[buf[in++]]; +- predictor[channel_number] = av_clip_int16(predictor[channel_number]); +- output_samples[out++] = predictor[channel_number]; ++ ch = 0; ++ while (buf < buf_end) { ++ predictor[ch] += interplay_delta_table[*buf++]; ++ predictor[ch] = av_clip_int16(predictor[ch]); ++ *output_samples++ = predictor[ch]; + + /* toggle channel */ +- channel_number ^= s->channels - 1; ++ ch ^= stereo; + } +- + break; + + case CODEC_ID_XAN_DPCM: +- in = 0; +- shift[0] = shift[1] = 4; +- predictor[0] = AV_RL16(&buf[in]); +- in += 2; +- SE_16BIT(predictor[0]); +- if (s->channels == 2) { +- predictor[1] = AV_RL16(&buf[in]); +- in += 2; +- SE_16BIT(predictor[1]); +- } ++ { ++ int shift[2] = { 4, 4 }; ++ ++ for (ch = 0; ch < s->channels; ch++) ++ predictor[ch] = (int16_t)bytestream_get_le16(&buf); + +- while (in < buf_size) { +- byte = buf[in++]; +- diff = (byte & 0xFC) << 8; +- if ((byte & 0x03) == 3) +- shift[channel_number]++; ++ ch = 0; ++ while (buf < buf_end) { ++ uint8_t n = *buf++; ++ int16_t diff = (n & 0xFC) << 8; ++ if ((n & 0x03) == 3) ++ shift[ch]++; + else +- shift[channel_number] -= (2 * (byte & 3)); ++ shift[ch] -= (2 * (n & 3)); + /* saturate the shifter to a lower limit of 0 */ +- if (shift[channel_number] < 0) +- shift[channel_number] = 0; ++ if (shift[ch] < 0) ++ shift[ch] = 0; + +- diff >>= shift[channel_number]; +- predictor[channel_number] += diff; ++ diff >>= shift[ch]; ++ predictor[ch] += diff; + +- predictor[channel_number] = av_clip_int16(predictor[channel_number]); +- output_samples[out++] = predictor[channel_number]; ++ predictor[ch] = av_clip_int16(predictor[ch]); ++ *output_samples++ = predictor[ch]; + + /* toggle channel */ +- channel_number ^= s->channels - 1; ++ ch ^= stereo; + } + break; ++ } + case CODEC_ID_SOL_DPCM: +- in = 0; + if (avctx->codec_tag != 3) { +- if(*data_size/4 < buf_size) +- return -1; +- while (in < buf_size) { +- int n1, n2; +- n1 = (buf[in] >> 4) & 0xF; +- n2 = buf[in++] & 0xF; +- s->sample[0] += s->sol_table[n1]; +- if (s->sample[0] < 0) s->sample[0] = 0; +- if (s->sample[0] > 255) s->sample[0] = 255; +- output_samples[out++] = (s->sample[0] - 128) << 8; +- s->sample[s->channels - 1] += s->sol_table[n2]; +- if (s->sample[s->channels - 1] < 0) s->sample[s->channels - 1] = 0; +- if (s->sample[s->channels - 1] > 255) s->sample[s->channels - 1] = 255; +- output_samples[out++] = (s->sample[s->channels - 1] - 128) << 8; ++ uint8_t *output_samples_u8 = s->frame.data[0]; ++ while (buf < buf_end) { ++ uint8_t n = *buf++; ++ ++ s->sample[0] += s->sol_table[n >> 4]; ++ s->sample[0] = av_clip_uint8(s->sample[0]); ++ *output_samples_u8++ = s->sample[0]; ++ ++ s->sample[stereo] += s->sol_table[n & 0x0F]; ++ s->sample[stereo] = av_clip_uint8(s->sample[stereo]); ++ *output_samples_u8++ = s->sample[stereo]; + } + } else { +- while (in < buf_size) { +- int n; +- n = buf[in++]; +- if (n & 0x80) s->sample[channel_number] -= s->sol_table[n & 0x7F]; +- else s->sample[channel_number] += s->sol_table[n & 0x7F]; +- s->sample[channel_number] = av_clip_int16(s->sample[channel_number]); +- output_samples[out++] = s->sample[channel_number]; ++ while (buf < buf_end) { ++ uint8_t n = *buf++; ++ if (n & 0x80) s->sample[ch] -= sol_table_16[n & 0x7F]; ++ else s->sample[ch] += sol_table_16[n & 0x7F]; ++ s->sample[ch] = av_clip_int16(s->sample[ch]); ++ *output_samples++ = s->sample[ch]; + /* toggle channel */ +- channel_number ^= s->channels - 1; ++ ch ^= stereo; + } + } + break; + } + +- *data_size = out * sizeof(short); +- return buf_size; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return avpkt->size; + } + +-#define DPCM_DECODER(id, name, long_name_) \ +-AVCodec ff_ ## name ## _decoder = { \ +- #name, \ +- AVMEDIA_TYPE_AUDIO, \ +- id, \ +- sizeof(DPCMContext), \ +- dpcm_decode_init, \ +- NULL, \ +- NULL, \ +- dpcm_decode_frame, \ +- .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ +-}; ++#define DPCM_DECODER(id_, name_, long_name_) \ ++AVCodec ff_ ## name_ ## _decoder = { \ ++ .name = #name_, \ ++ .type = AVMEDIA_TYPE_AUDIO, \ ++ .id = id_, \ ++ .priv_data_size = sizeof(DPCMContext), \ ++ .init = dpcm_decode_init, \ ++ .decode = dpcm_decode_frame, \ ++ .capabilities = CODEC_CAP_DR1, \ ++ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ ++} + + DPCM_DECODER(CODEC_ID_INTERPLAY_DPCM, interplay_dpcm, "DPCM Interplay"); +-DPCM_DECODER(CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ"); +-DPCM_DECODER(CODEC_ID_SOL_DPCM, sol_dpcm, "DPCM Sol"); +-DPCM_DECODER(CODEC_ID_XAN_DPCM, xan_dpcm, "DPCM Xan"); ++DPCM_DECODER(CODEC_ID_ROQ_DPCM, roq_dpcm, "DPCM id RoQ"); ++DPCM_DECODER(CODEC_ID_SOL_DPCM, sol_dpcm, "DPCM Sol"); ++DPCM_DECODER(CODEC_ID_XAN_DPCM, xan_dpcm, "DPCM Xan"); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpx.c 2012-05-14 14:08:53.635325913 +0200 +@@ -20,7 +20,7 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "bytestream.h" + #include "avcodec.h" + +@@ -68,6 +68,11 @@ + + unsigned int rgbBuffer; + ++ if (avpkt->size <= 1634) { ++ av_log(avctx, AV_LOG_ERROR, "Packet too small for DPX header\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ + magic_num = AV_RB32(buf); + buf += 4; + +@@ -83,6 +88,10 @@ + } + + offset = read32(&buf, endian); ++ if (avpkt->size <= offset) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid data start offset\n"); ++ return AVERROR_INVALIDDATA; ++ } + // Need to end in 0x304 offset from start of file + buf = avpkt->data + 0x304; + w = read32(&buf, endian); +@@ -97,6 +106,10 @@ + avctx->bits_per_raw_sample = + bits_per_color = buf[0]; + ++ buf += 825; ++ avctx->sample_aspect_ratio.num = read32(&buf, endian); ++ avctx->sample_aspect_ratio.den = read32(&buf, endian); ++ + switch (descriptor) { + case 51: // RGBA + elements = 4; +@@ -122,16 +135,16 @@ + case 10: + avctx->pix_fmt = PIX_FMT_RGB48; + target_packet_size = 6; +- source_packet_size = elements * 2; ++ source_packet_size = 4; + break; + case 12: + case 16: + if (endian) { +- avctx->pix_fmt = PIX_FMT_RGB48BE; ++ avctx->pix_fmt = elements == 4 ? PIX_FMT_RGBA64BE : PIX_FMT_RGB48BE; + } else { +- avctx->pix_fmt = PIX_FMT_RGB48LE; ++ avctx->pix_fmt = elements == 4 ? PIX_FMT_RGBA64LE : PIX_FMT_RGB48LE; + } +- target_packet_size = 6; ++ target_packet_size = + source_packet_size = elements * 2; + break; + default: +@@ -156,6 +169,10 @@ + ptr = p->data[0]; + stride = p->linesize[0]; + ++ if (source_packet_size*avctx->width*avctx->height > buf_end - buf) { ++ av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); ++ return -1; ++ } + switch (bits_per_color) { + case 10: + for (x = 0; x < avctx->height; x++) { +@@ -173,10 +190,6 @@ + case 8: + case 12: // Treat 12-bit as 16-bit + case 16: +- if (source_packet_size*avctx->width*avctx->height > buf_end - buf) { +- av_log(avctx, AV_LOG_ERROR, "Overread buffer. Invalid header?\n"); +- return -1; +- } + if (source_packet_size == target_packet_size) { + for (x = 0; x < avctx->height; x++) { + memcpy(ptr, buf, target_packet_size*avctx->width); +@@ -221,15 +234,12 @@ + } + + AVCodec ff_dpx_decoder = { +- "dpx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DPX, +- sizeof(DPXContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- 0, +- NULL, ++ .name = "dpx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DPX, ++ .priv_data_size = sizeof(DPXContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("DPX image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpxenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpxenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dpxenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dpxenc.c 2012-05-14 14:08:53.636325933 +0200 +@@ -0,0 +1,186 @@ ++/* ++ * DPX (.dpx) image encoder ++ * Copyright (c) 2011 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/imgutils.h" ++#include "avcodec.h" ++ ++typedef struct DPXContext { ++ AVFrame picture; ++ int big_endian; ++ int bits_per_component; ++ int descriptor; ++} DPXContext; ++ ++static av_cold int encode_init(AVCodecContext *avctx) ++{ ++ DPXContext *s = avctx->priv_data; ++ ++ avctx->coded_frame = &s->picture; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ avctx->coded_frame->key_frame = 1; ++ ++ s->big_endian = 1; ++ s->bits_per_component = 8; ++ s->descriptor = 50; /* RGB */ ++ ++ switch (avctx->pix_fmt) { ++ case PIX_FMT_RGB24: ++ break; ++ case PIX_FMT_RGBA: ++ s->descriptor = 51; /* RGBA */ ++ break; ++ case PIX_FMT_RGB48LE: ++ s->big_endian = 0; ++ case PIX_FMT_RGB48BE: ++ s->bits_per_component = avctx->bits_per_raw_sample ? avctx->bits_per_raw_sample : 16; ++ break; ++ case PIX_FMT_RGBA64LE: ++ s->big_endian = 0; ++ case PIX_FMT_RGBA64BE: ++ s->descriptor = 51; ++ s->bits_per_component = 16; ++ break; ++ default: ++ av_log(avctx, AV_LOG_INFO, "unsupported pixel format\n"); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++#define write16(p, value) \ ++do { \ ++ if (s->big_endian) AV_WB16(p, value); \ ++ else AV_WL16(p, value); \ ++} while(0) ++ ++#define write32(p, value) \ ++do { \ ++ if (s->big_endian) AV_WB32(p, value); \ ++ else AV_WL32(p, value); \ ++} while(0) ++ ++static void encode_rgb48_10bit(AVCodecContext *avctx, const AVPicture *pic, uint8_t *dst) ++{ ++ DPXContext *s = avctx->priv_data; ++ const uint8_t *src = pic->data[0]; ++ int x, y; ++ ++ for (y = 0; y < avctx->height; y++) { ++ for (x = 0; x < avctx->width; x++) { ++ int value; ++ if ((avctx->pix_fmt & 1)) { ++ value = ((AV_RB16(src + 6*x + 4) & 0xFFC0) >> 4) ++ | ((AV_RB16(src + 6*x + 2) & 0xFFC0) << 6) ++ | ((AV_RB16(src + 6*x + 0) & 0xFFC0) << 16); ++ } else { ++ value = ((AV_RL16(src + 6*x + 4) & 0xFFC0) >> 4) ++ | ((AV_RL16(src + 6*x + 2) & 0xFFC0) << 6) ++ | ((AV_RL16(src + 6*x + 0) & 0xFFC0) << 16); ++ } ++ write32(dst, value); ++ dst += 4; ++ } ++ src += pic->linesize[0]; ++ } ++} ++ ++static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data) ++{ ++ DPXContext *s = avctx->priv_data; ++ int size; ++ ++#define HEADER_SIZE 1664 /* DPX Generic header */ ++ if (buf_size < HEADER_SIZE) ++ return -1; ++ ++ memset(buf, 0, HEADER_SIZE); ++ ++ /* File information header */ ++ write32(buf, MKBETAG('S','D','P','X')); ++ write32(buf + 4, HEADER_SIZE); ++ memcpy (buf + 8, "V1.0", 4); ++ write32(buf + 20, 1); /* new image */ ++ write32(buf + 24, HEADER_SIZE); ++ if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ ++ memcpy (buf + 160, LIBAVCODEC_IDENT, FFMIN(sizeof(LIBAVCODEC_IDENT), 100)); ++ } ++ write32(buf + 660, 0xFFFFFFFF); /* unencrypted */ ++ ++ /* Image information header */ ++ write16(buf + 768, 0); /* orientation; left to right, top to bottom */ ++ write16(buf + 770, 1); /* number of elements */ ++ write32(buf + 772, avctx->width); ++ write32(buf + 776, avctx->height); ++ buf[800] = s->descriptor; ++ buf[801] = 2; /* linear transfer */ ++ buf[802] = 2; /* linear colorimetric */ ++ buf[803] = s->bits_per_component; ++ write16(buf + 804, s->bits_per_component == 10 ? 1 : 0); /* packing method */ ++ ++ /* Image source information header */ ++ write32(buf + 1628, avctx->sample_aspect_ratio.num); ++ write32(buf + 1632, avctx->sample_aspect_ratio.den); ++ ++ switch(s->bits_per_component) { ++ case 8: ++ case 16: ++ size = avpicture_layout(data, avctx->pix_fmt, ++ avctx->width, avctx->height, ++ buf + HEADER_SIZE, buf_size - HEADER_SIZE); ++ if (size < 0) ++ return size; ++ break; ++ case 10: ++ size = avctx->height * avctx->width * 4; ++ if (buf_size < HEADER_SIZE + size) ++ return -1; ++ encode_rgb48_10bit(avctx, data, buf + HEADER_SIZE); ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Unsupported bit depth: %d\n", s->bits_per_component); ++ return -1; ++ } ++ ++ size += HEADER_SIZE; ++ ++ write32(buf + 16, size); /* file size */ ++ return size; ++} ++ ++AVCodec ff_dpx_encoder = { ++ .name = "dpx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DPX, ++ .priv_data_size = sizeof(DPXContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .pix_fmts = (const enum PixelFormat[]){ ++ PIX_FMT_RGB24, ++ PIX_FMT_RGBA, ++ PIX_FMT_RGB48LE, ++ PIX_FMT_RGB48BE, ++ PIX_FMT_RGBA64LE, ++ PIX_FMT_RGBA64BE, ++ PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("DPX image"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsicinav.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsicinav.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsicinav.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsicinav.c 2012-05-14 14:08:53.637325953 +0200 +@@ -26,6 +26,7 @@ + + #include "avcodec.h" + #include "bytestream.h" ++#include "mathops.h" + + + typedef enum CinVideoBitmapIndex { +@@ -43,7 +44,7 @@ + } CinVideoContext; + + typedef struct CinAudioContext { +- AVCodecContext *avctx; ++ AVFrame frame; + int initial_decode_frame; + int delta; + } CinAudioContext; +@@ -94,6 +95,7 @@ + cin->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&cin->frame); + cin->frame.data[0] = NULL; + + cin->bitmap_size = avctx->width * avctx->height; +@@ -145,11 +147,11 @@ + return dst_cur - dst; + } + +-static void cin_decode_lzss(const unsigned char *src, int src_size, unsigned char *dst, int dst_size) ++static int cin_decode_lzss(const unsigned char *src, int src_size, unsigned char *dst, int dst_size) + { + uint16_t cmd; + int i, sz, offset, code; +- unsigned char *dst_end = dst + dst_size; ++ unsigned char *dst_end = dst + dst_size, *dst_start = dst; + const unsigned char *src_end = src + src_size; + + while (src < src_end && dst < dst_end) { +@@ -160,6 +162,8 @@ + } else { + cmd = AV_RL16(src); src += 2; + offset = cmd >> 4; ++ if ((int) (dst - dst_start) < offset + 1) ++ return AVERROR_INVALIDDATA; + sz = (cmd & 0xF) + 2; + /* don't use memcpy/memmove here as the decoding routine (ab)uses */ + /* buffer overlappings to repeat bytes in the destination */ +@@ -171,6 +175,8 @@ + } + } + } ++ ++ return 0; + } + + static void cin_decode_rle(const unsigned char *src, int src_size, unsigned char *dst, int dst_size) +@@ -200,13 +206,7 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + CinVideoContext *cin = avctx->priv_data; +- int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size; +- +- cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; +- if (avctx->reget_buffer(avctx, &cin->frame)) { +- av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n"); +- return -1; +- } ++ int i, y, palette_type, palette_colors_count, bitmap_frame_type, bitmap_frame_size, res = 0; + + palette_type = buf[0]; + palette_colors_count = AV_RL16(buf+1); +@@ -216,20 +216,22 @@ + bitmap_frame_size = buf_size - 4; + + /* handle palette */ ++ if (bitmap_frame_size < palette_colors_count * (3 + (palette_type != 0))) ++ return AVERROR_INVALIDDATA; + if (palette_type == 0) { ++ if (palette_colors_count > 256) ++ return AVERROR_INVALIDDATA; + for (i = 0; i < palette_colors_count; ++i) { +- cin->palette[i] = bytestream_get_le24(&buf); ++ cin->palette[i] = 0xFF << 24 | bytestream_get_le24(&buf); + bitmap_frame_size -= 3; + } + } else { + for (i = 0; i < palette_colors_count; ++i) { +- cin->palette[buf[0]] = AV_RL24(buf+1); ++ cin->palette[buf[0]] = 0xFF << 24 | AV_RL24(buf+1); + buf += 4; + bitmap_frame_size -= 4; + } + } +- memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette)); +- cin->frame.palette_has_changed = 1; + + /* note: the decoding routines below assumes that surface.width = surface.pitch */ + switch (bitmap_frame_type) { +@@ -262,17 +264,31 @@ + cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); + break; + case 38: +- cin_decode_lzss(buf, bitmap_frame_size, +- cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); ++ res = cin_decode_lzss(buf, bitmap_frame_size, ++ cin->bitmap_table[CIN_CUR_BMP], ++ cin->bitmap_size); ++ if (res < 0) ++ return res; + break; + case 39: +- cin_decode_lzss(buf, bitmap_frame_size, +- cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); ++ res = cin_decode_lzss(buf, bitmap_frame_size, ++ cin->bitmap_table[CIN_CUR_BMP], ++ cin->bitmap_size); ++ if (res < 0) ++ return res; + cin_apply_delta_data(cin->bitmap_table[CIN_PRE_BMP], + cin->bitmap_table[CIN_CUR_BMP], cin->bitmap_size); + break; + } + ++ cin->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; ++ if (avctx->reget_buffer(avctx, &cin->frame)) { ++ av_log(cin->avctx, AV_LOG_ERROR, "delphinecinvideo: reget_buffer() failed to allocate a frame\n"); ++ return -1; ++ } ++ ++ memcpy(cin->frame.data[1], cin->palette, sizeof(cin->palette)); ++ cin->frame.palette_has_changed = 1; + for (y = 0; y < cin->avctx->height; ++y) + memcpy(cin->frame.data[0] + (cin->avctx->height - 1 - y) * cin->frame.linesize[0], + cin->bitmap_table[CIN_CUR_BMP] + y * cin->avctx->width, +@@ -304,66 +320,78 @@ + { + CinAudioContext *cin = avctx->priv_data; + +- cin->avctx = avctx; ++ if (avctx->channels != 1) { ++ av_log_ask_for_sample(avctx, "Number of channels is not supported\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ + cin->initial_decode_frame = 1; + cin->delta = 0; + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + ++ avcodec_get_frame_defaults(&cin->frame); ++ avctx->coded_frame = &cin->frame; ++ + return 0; + } + +-static int cinaudio_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; + CinAudioContext *cin = avctx->priv_data; +- const uint8_t *src = buf; +- int16_t *samples = (int16_t *)data; +- +- buf_size = FFMIN(buf_size, *data_size/2); ++ const uint8_t *buf_end = buf + avpkt->size; ++ int16_t *samples; ++ int delta, ret; ++ ++ /* get output buffer */ ++ cin->frame.nb_samples = avpkt->size - cin->initial_decode_frame; ++ if ((ret = avctx->get_buffer(avctx, &cin->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)cin->frame.data[0]; + ++ delta = cin->delta; + if (cin->initial_decode_frame) { + cin->initial_decode_frame = 0; +- cin->delta = (int16_t)AV_RL16(src); src += 2; +- *samples++ = cin->delta; +- buf_size -= 2; ++ delta = sign_extend(AV_RL16(buf), 16); ++ buf += 2; ++ *samples++ = delta; + } +- while (buf_size > 0) { +- cin->delta += cinaudio_delta16_table[*src++]; +- cin->delta = av_clip_int16(cin->delta); +- *samples++ = cin->delta; +- --buf_size; ++ while (buf < buf_end) { ++ delta += cinaudio_delta16_table[*buf++]; ++ delta = av_clip_int16(delta); ++ *samples++ = delta; + } ++ cin->delta = delta; + +- *data_size = (uint8_t *)samples - (uint8_t *)data; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = cin->frame; + +- return src - buf; ++ return avpkt->size; + } + + + AVCodec ff_dsicinvideo_decoder = { +- "dsicinvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DSICINVIDEO, +- sizeof(CinVideoContext), +- cinvideo_decode_init, +- NULL, +- cinvideo_decode_end, +- cinvideo_decode_frame, +- CODEC_CAP_DR1, ++ .name = "dsicinvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DSICINVIDEO, ++ .priv_data_size = sizeof(CinVideoContext), ++ .init = cinvideo_decode_init, ++ .close = cinvideo_decode_end, ++ .decode = cinvideo_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN video"), + }; + + AVCodec ff_dsicinaudio_decoder = { +- "dsicinaudio", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_DSICINAUDIO, +- sizeof(CinAudioContext), +- cinaudio_decode_init, +- NULL, +- NULL, +- cinaudio_decode_frame, ++ .name = "dsicinaudio", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_DSICINAUDIO, ++ .priv_data_size = sizeof(CinAudioContext), ++ .init = cinaudio_decode_init, ++ .decode = cinaudio_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN audio"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil.c 2012-05-14 14:08:53.647326155 +0200 +@@ -27,7 +27,7 @@ + * DSP utils + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "dsputil.h" + #include "simple_idct.h" +@@ -38,11 +38,22 @@ + #include "config.h" + #include "ac3dec.h" + #include "vorbis.h" +-#include "png.h" ++#include "diracdsp.h" + + uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP] = {0, }; + uint32_t ff_squareTbl[512] = {0, }; + ++#define BIT_DEPTH 9 ++#include "dsputil_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "dsputil_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 8 ++#include "dsputil_template.c" ++ + // 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size + #define pb_7f (~0UL/255 * 0x7f) + #define pb_80 (~0UL/255 * 0x80) +@@ -134,6 +145,41 @@ + } + } + ++void ff_init_scantable_permutation(uint8_t *idct_permutation, ++ int idct_permutation_type) ++{ ++ int i; ++ ++ switch(idct_permutation_type){ ++ case FF_NO_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= i; ++ break; ++ case FF_LIBMPEG2_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); ++ break; ++ case FF_SIMPLE_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= simple_mmx_permutation[i]; ++ break; ++ case FF_TRANSPOSE_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= ((i&7)<<3) | (i>>3); ++ break; ++ case FF_PARTTRANS_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3); ++ break; ++ case FF_SSE2_IDCT_PERM: ++ for(i=0; i<64; i++) ++ idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7]; ++ break; ++ default: ++ av_log(NULL, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n"); ++ } ++} ++ + static int pix_sum_c(uint8_t * pix, int line_size) + { + int s, i, j; +@@ -174,7 +220,7 @@ + s += sq[pix[6]]; + s += sq[pix[7]]; + #else +-#if LONG_MAX > 2147483647 ++#if HAVE_FAST_64BIT + register uint64_t x=*(uint64_t*)pix; + s += sq[x&0xff]; + s += sq[(x>>8)&0xff]; +@@ -222,6 +268,12 @@ + } + } + ++static void bswap16_buf(uint16_t *dst, const uint16_t *src, int len) ++{ ++ while (len--) ++ *dst++ = av_bswap16(*src++); ++} ++ + static int sse4_c(void *v, uint8_t * pix1, uint8_t * pix2, int line_size, int h) + { + int s, i; +@@ -290,132 +342,6 @@ + return s; + } + +-/* draw the edges of width 'w' of an image of size width, height */ +-//FIXME check that this is ok for mpeg4 interlaced +-static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) +-{ +- uint8_t *ptr, *last_line; +- int i; +- +- last_line = buf + (height - 1) * wrap; +- for(i=0;i= h){ +- src+= (h-1-src_y)*linesize; +- src_y=h-1; +- }else if(src_y<=-block_h){ +- src+= (1-block_h-src_y)*linesize; +- src_y=1-block_h; +- } +- if(src_x>= w){ +- src+= (w-1-src_x); +- src_x=w-1; +- }else if(src_x<=-block_w){ +- src+= (1-block_w-src_x); +- src_x=1-block_w; +- } +- +- start_y= FFMAX(0, -src_y); +- start_x= FFMAX(0, -src_x); +- end_y= FFMIN(block_h, h-src_y); +- end_x= FFMIN(block_w, w-src_x); +- assert(start_y < end_y && block_h); +- assert(start_x < end_x && block_w); +- +- w = end_x - start_x; +- src += start_y*linesize + start_x; +- buf += start_x; +- +- //top +- for(y=0; y>1));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static void OPNAME ## _pixels_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- for(i=0; i>1));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static void OPNAME ## _no_rnd_pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- for(i=0; i>1));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static void OPNAME ## _pixels_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- for(i=0; i>1));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static void OPNAME ## _pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- const uint64_t a= AV_RN64(pixels );\ +- const uint64_t b= AV_RN64(pixels+1);\ +- uint64_t l0= (a&0x0303030303030303ULL)\ +- + (b&0x0303030303030303ULL)\ +- + 0x0202020202020202ULL;\ +- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- uint64_t l1,h1;\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- a= AV_RN64(pixels );\ +- b= AV_RN64(pixels+1);\ +- l0= (a&0x0303030303030303ULL)\ +- + (b&0x0303030303030303ULL)\ +- + 0x0202020202020202ULL;\ +- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static void OPNAME ## _no_rnd_pixels_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- const uint64_t a= AV_RN64(pixels );\ +- const uint64_t b= AV_RN64(pixels+1);\ +- uint64_t l0= (a&0x0303030303030303ULL)\ +- + (b&0x0303030303030303ULL)\ +- + 0x0101010101010101ULL;\ +- uint64_t h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- uint64_t l1,h1;\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- a= AV_RN64(pixels );\ +- b= AV_RN64(pixels+1);\ +- l0= (a&0x0303030303030303ULL)\ +- + (b&0x0303030303030303ULL)\ +- + 0x0101010101010101ULL;\ +- h0= ((a&0xFCFCFCFCFCFCFCFCULL)>>2)\ +- + ((b&0xFCFCFCFCFCFCFCFCULL)>>2);\ +- OP(*((uint64_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0F0F0F0F0FULL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels_x2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels_y2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels_xy2_c, 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels_x2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels_y2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels_xy2_c, 8) +- +-#define op_avg(a, b) a = ( ((a)|(b)) - ((((a)^(b))&0xFEFEFEFEFEFEFEFEULL)>>1) ) +-#else // 64 bit variant +- +-#define PIXOP2(OPNAME, OP) \ +-static void OPNAME ## _pixels2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +- int i;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- l1= (c&0x03030303UL)\ +- + (d&0x03030303UL);\ +- h1= ((c&0xFCFCFCFCUL)>>2)\ +- + ((d&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- a= AV_RN32(&src1[i*src_stride1+4]);\ +- b= AV_RN32(&src2[i*src_stride2+4]);\ +- c= AV_RN32(&src3[i*src_stride3+4]);\ +- d= AV_RN32(&src4[i*src_stride4+4]);\ +- l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x02020202UL;\ +- h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- l1= (c&0x03030303UL)\ +- + (d&0x03030303UL);\ +- h1= ((c&0xFCFCFCFCUL)>>2)\ +- + ((d&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- }\ +-}\ +-\ +-static inline void OPNAME ## _pixels4_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +- OPNAME ## _pixels4_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ +-}\ +-\ +-static inline void OPNAME ## _pixels4_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +- OPNAME ## _pixels4_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ +-}\ +-\ +-static inline void OPNAME ## _pixels2_x2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +- OPNAME ## _pixels2_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);\ +-}\ +-\ +-static inline void OPNAME ## _pixels2_y2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ +- OPNAME ## _pixels2_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ +-}\ +-\ +-static inline void OPNAME ## _no_rnd_pixels8_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ +- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ +- int i;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- l1= (c&0x03030303UL)\ +- + (d&0x03030303UL);\ +- h1= ((c&0xFCFCFCFCUL)>>2)\ +- + ((d&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- a= AV_RN32(&src1[i*src_stride1+4]);\ +- b= AV_RN32(&src2[i*src_stride2+4]);\ +- c= AV_RN32(&src3[i*src_stride3+4]);\ +- d= AV_RN32(&src4[i*src_stride4+4]);\ +- l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x01010101UL;\ +- h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- l1= (c&0x03030303UL)\ +- + (d&0x03030303UL);\ +- h1= ((c&0xFCFCFCFCUL)>>2)\ +- + ((d&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- }\ +-}\ +-static inline void OPNAME ## _pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ +- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ +- OPNAME ## _pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ +- OPNAME ## _pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ +-}\ +-static inline void OPNAME ## _no_rnd_pixels16_l4(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ +- int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ +- OPNAME ## _no_rnd_pixels8_l4(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ +- OPNAME ## _no_rnd_pixels8_l4(dst+8, src1+8, src2+8, src3+8, src4+8, dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ +-}\ +-\ +-static inline void OPNAME ## _pixels2_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i, a0, b0, a1, b1;\ +- a0= pixels[0];\ +- b0= pixels[1] + 2;\ +- a0 += b0;\ +- b0 += pixels[2];\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2; /* FIXME non put */\ +- block[1]= (b1+b0)>>2;\ +-\ +- pixels+=line_size;\ +- block +=line_size;\ +-\ +- a0= pixels[0];\ +- b0= pixels[1] + 2;\ +- a0 += b0;\ +- b0 += pixels[2];\ +-\ +- block[0]= (a1+a0)>>2;\ +- block[1]= (b1+b0)>>2;\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static inline void OPNAME ## _pixels4_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int i;\ +- const uint32_t a= AV_RN32(pixels );\ +- const uint32_t b= AV_RN32(pixels+1);\ +- uint32_t l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x02020202UL;\ +- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- uint32_t l1,h1;\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- a= AV_RN32(pixels );\ +- b= AV_RN32(pixels+1);\ +- l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x02020202UL;\ +- h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +-}\ +-\ +-static inline void OPNAME ## _pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int j;\ +- for(j=0; j<2; j++){\ +- int i;\ +- const uint32_t a= AV_RN32(pixels );\ +- const uint32_t b= AV_RN32(pixels+1);\ +- uint32_t l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x02020202UL;\ +- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- uint32_t l1,h1;\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- a= AV_RN32(pixels );\ +- b= AV_RN32(pixels+1);\ +- l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x02020202UL;\ +- h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +- pixels+=4-line_size*(h+1);\ +- block +=4-line_size*h;\ +- }\ +-}\ +-\ +-static inline void OPNAME ## _no_rnd_pixels8_xy2_c(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ +-{\ +- int j;\ +- for(j=0; j<2; j++){\ +- int i;\ +- const uint32_t a= AV_RN32(pixels );\ +- const uint32_t b= AV_RN32(pixels+1);\ +- uint32_t l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x01010101UL;\ +- uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- uint32_t l1,h1;\ +-\ +- pixels+=line_size;\ +- for(i=0; i>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- a= AV_RN32(pixels );\ +- b= AV_RN32(pixels+1);\ +- l0= (a&0x03030303UL)\ +- + (b&0x03030303UL)\ +- + 0x01010101UL;\ +- h0= ((a&0xFCFCFCFCUL)>>2)\ +- + ((b&0xFCFCFCFCUL)>>2);\ +- OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ +- pixels+=line_size;\ +- block +=line_size;\ +- }\ +- pixels+=4-line_size*(h+1);\ +- block +=4-line_size*h;\ +- }\ +-}\ +-\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_c , OPNAME ## _pixels8_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_x2_c , OPNAME ## _pixels8_x2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_y2_c , OPNAME ## _pixels8_y2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _pixels16_xy2_c, OPNAME ## _pixels8_xy2_c, 8)\ +-av_unused CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_c , OPNAME ## _pixels8_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_x2_c , OPNAME ## _no_rnd_pixels8_x2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_y2_c , OPNAME ## _no_rnd_pixels8_y2_c , 8)\ +-CALL_2X_PIXELS(OPNAME ## _no_rnd_pixels16_xy2_c, OPNAME ## _no_rnd_pixels8_xy2_c, 8)\ +- +-#define op_avg(a, b) a = rnd_avg32(a, b) +-#endif +-#define op_put(a, b) a = b +- +-PIXOP2(avg, op_avg) +-PIXOP2(put, op_put) +-#undef op_avg +-#undef op_put +- +-#define put_no_rnd_pixels8_c put_pixels8_c +-#define put_no_rnd_pixels16_c put_pixels16_c +- + #define avg2(a,b) ((a+b+1)>>1) + #define avg4(a,b,c,d) ((a+b+c+d+2)>>2) + +-static void put_no_rnd_pixels16_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ +- put_no_rnd_pixels16_l2(dst, a, b, stride, stride, stride, h); +-} +- +-static void put_no_rnd_pixels8_l2_c(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ +- put_no_rnd_pixels8_l2(dst, a, b, stride, stride, stride, h); +-} +- + static void gmc1_c(uint8_t *dst, uint8_t *src, int stride, int h, int x16, int y16, int rounder) + { + const int A=(16-x16)*(16-y16); +@@ -1278,10 +601,10 @@ + + static inline void put_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ + switch(width){ +- case 2: put_pixels2_c (dst, src, stride, height); break; +- case 4: put_pixels4_c (dst, src, stride, height); break; +- case 8: put_pixels8_c (dst, src, stride, height); break; +- case 16:put_pixels16_c(dst, src, stride, height); break; ++ case 2: put_pixels2_8_c (dst, src, stride, height); break; ++ case 4: put_pixels4_8_c (dst, src, stride, height); break; ++ case 8: put_pixels8_8_c (dst, src, stride, height); break; ++ case 16:put_pixels16_8_c(dst, src, stride, height); break; + } + } + +@@ -1375,10 +698,10 @@ + + static inline void avg_tpel_pixels_mc00_c(uint8_t *dst, const uint8_t *src, int stride, int width, int height){ + switch(width){ +- case 2: avg_pixels2_c (dst, src, stride, height); break; +- case 4: avg_pixels4_c (dst, src, stride, height); break; +- case 8: avg_pixels8_c (dst, src, stride, height); break; +- case 16:avg_pixels16_c(dst, src, stride, height); break; ++ case 2: avg_pixels2_8_c (dst, src, stride, height); break; ++ case 4: avg_pixels4_8_c (dst, src, stride, height); break; ++ case 8: avg_pixels8_8_c (dst, src, stride, height); break; ++ case 16:avg_pixels16_8_c(dst, src, stride, height); break; + } + } + +@@ -1469,184 +792,6 @@ + dst += stride; + } + } +-#if 0 +-#define TPEL_WIDTH(width)\ +-static void put_tpel_pixels ## width ## _mc00_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc00_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc10_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc10_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc20_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc20_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc01_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc01_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc11_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc11_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc21_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc21_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc02_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc02_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc12_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc12_c(dst, src, stride, width, height);}\ +-static void put_tpel_pixels ## width ## _mc22_c(uint8_t *dst, const uint8_t *src, int stride, int height){\ +- void put_tpel_pixels_mc22_c(dst, src, stride, width, height);} +-#endif +- +-#define H264_CHROMA_MC(OPNAME, OP)\ +-static void OPNAME ## h264_chroma_mc2_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ +- const int A=(8-x)*(8-y);\ +- const int B=( x)*(8-y);\ +- const int C=(8-x)*( y);\ +- const int D=( x)*( y);\ +- int i;\ +- \ +- assert(x<8 && y<8 && x>=0 && y>=0);\ +-\ +- if(D){\ +- for(i=0; i=0 && y>=0);\ +-\ +- if(D){\ +- for(i=0; i=0 && y>=0);\ +-\ +- if(D){\ +- for(i=0; i>6)+1)>>1) +-#define op_put(a, b) a = (((b) + 32)>>6) +- +-H264_CHROMA_MC(put_ , op_put) +-H264_CHROMA_MC(avg_ , op_avg) +-#undef op_avg +-#undef op_put +- +-static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ +- const int A=(8-x)*(8-y); +- const int B=( x)*(8-y); +- const int C=(8-x)*( y); +- const int D=( x)*( y); +- int i; +- +- assert(x<8 && y<8 && x>=0 && y>=0); +- +- for(i=0; i> 6; +- dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; +- dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; +- dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; +- dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6; +- dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6; +- dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6; +- dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6; +- dst+= stride; +- src+= stride; +- } +-} +- +-static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ +- const int A=(8-x)*(8-y); +- const int B=( x)*(8-y); +- const int C=(8-x)*( y); +- const int D=( x)*( y); +- int i; +- +- assert(x<8 && y<8 && x>=0 && y>=0); +- +- for(i=0; i> 6)); +- dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6)); +- dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6)); +- dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6)); +- dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6)); +- dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6)); +- dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6)); +- dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6)); +- dst+= stride; +- src+= stride; +- } +-} + + #define QPEL_MC(r, OPNAME, RND, OP) \ + static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){\ +@@ -1769,7 +914,7 @@ + static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t half[64];\ + put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\ +- OPNAME ## pixels8_l2(dst, src, half, stride, stride, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, src, half, stride, stride, 8, 8);\ + }\ + \ + static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1779,7 +924,7 @@ + static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t half[64];\ + put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);\ +- OPNAME ## pixels8_l2(dst, src+1, half, stride, stride, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8);\ + }\ + \ + static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1787,7 +932,7 @@ + uint8_t half[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\ +- OPNAME ## pixels8_l2(dst, full, half, stride, 16, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);\ + }\ + \ + static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1801,7 +946,7 @@ + uint8_t half[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);\ +- OPNAME ## pixels8_l2(dst, full+16, half, stride, 16, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, full+16, half, stride, 16, 8, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1812,7 +957,7 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l4(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ ++ OPNAME ## pixels8_l4_8(dst, full, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1820,9 +965,9 @@ + uint8_t halfHV[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1833,7 +978,7 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l4(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ ++ OPNAME ## pixels8_l4_8(dst, full+1, halfH, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1841,9 +986,9 @@ + uint8_t halfHV[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1854,7 +999,7 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l4(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ ++ OPNAME ## pixels8_l4_8(dst, full+16, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1862,9 +1007,9 @@ + uint8_t halfHV[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1875,7 +1020,7 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full , 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l4(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ ++ OPNAME ## pixels8_l4_8(dst, full+17, halfH+8, halfV, halfHV, stride, 16, 8, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1883,23 +1028,23 @@ + uint8_t halfHV[64];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t halfH[72];\ + uint8_t halfHV[64];\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t halfH[72];\ + uint8_t halfHV[64];\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfH+8, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfH+8, halfHV, stride, 8, 8, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ +@@ -1910,14 +1055,14 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ + uint8_t halfH[72];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);\ + OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\ + }\ + void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1929,14 +1074,14 @@ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full+1, 8, 16);\ + put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);\ +- OPNAME ## pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8);\ ++ OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);\ + }\ + static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[16*9];\ + uint8_t halfH[72];\ + copy_block9(full, src, 16, stride, 9);\ + put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);\ +- put ## RND ## pixels8_l2(halfH, halfH, full+1, 8, 8, 16, 9);\ ++ put ## RND ## pixels8_l2_8(halfH, halfH, full+1, 8, 8, 16, 9);\ + OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);\ + }\ + static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1948,7 +1093,7 @@ + static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t half[256];\ + put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\ +- OPNAME ## pixels16_l2(dst, src, half, stride, stride, 16, 16);\ ++ OPNAME ## pixels16_l2_8(dst, src, half, stride, stride, 16, 16);\ + }\ + \ + static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1958,7 +1103,7 @@ + static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t half[256];\ + put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);\ +- OPNAME ## pixels16_l2(dst, src+1, half, stride, stride, 16, 16);\ ++ OPNAME ## pixels16_l2_8(dst, src+1, half, stride, stride, 16, 16);\ + }\ + \ + static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1966,7 +1111,7 @@ + uint8_t half[256];\ + copy_block17(full, src, 24, stride, 17);\ + put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\ +- OPNAME ## pixels16_l2(dst, full, half, stride, 24, 16, 16);\ ++ OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);\ + }\ + \ + static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src, int stride){\ +@@ -1980,7 +1125,7 @@ + uint8_t half[256];\ + copy_block17(full, src, 24, stride, 17);\ + put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);\ +- OPNAME ## pixels16_l2(dst, full+24, half, stride, 24, 16, 16);\ ++ OPNAME ## pixels16_l2_8(dst, full+24, half, stride, 24, 16, 16);\ + }\ + void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[24*17];\ +@@ -1991,7 +1136,7 @@ + put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ + put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ + put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l4(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ ++ OPNAME ## pixels16_l4_8(dst, full, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ + }\ + static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[24*17];\ +@@ -1999,580 +1144,151 @@ + uint8_t halfHV[256];\ + copy_block17(full, src, 24, stride, 17);\ + put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ +-}\ +-void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfV[256];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l4(dst, full+1, halfH, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ +-}\ +-void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfV[256];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l4(dst, full+24, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ +-}\ +-void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfV[256];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full , 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l4(dst, full+25, halfH+16, halfV, halfHV, stride, 24, 16, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t halfH[272];\ +- uint8_t halfHV[256];\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH, halfHV, stride, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t halfH[272];\ +- uint8_t halfHV[256];\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfH+16, halfHV, stride, 16, 16, 16);\ +-}\ +-void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfV[256];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full, 16, 16, 24, 17);\ +- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ +-}\ +-void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- uint8_t halfV[256];\ +- uint8_t halfHV[256];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full+1, 16, 24);\ +- put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);\ +- OPNAME ## pixels16_l2(dst, halfV, halfHV, stride, 16, 16, 16);\ +-}\ +-static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t full[24*17];\ +- uint8_t halfH[272];\ +- copy_block17(full, src, 24, stride, 17);\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);\ +- put ## RND ## pixels16_l2(halfH, halfH, full+1, 16, 16, 24, 17);\ +- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ +-}\ +-static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\ +- uint8_t halfH[272];\ +- put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ +- OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ +-} +- +-#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1) +-#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1) +-#define op_put(a, b) a = cm[((b) + 16)>>5] +-#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5] +- +-QPEL_MC(0, put_ , _ , op_put) +-QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd) +-QPEL_MC(0, avg_ , _ , op_avg) +-//QPEL_MC(1, avg_no_rnd , _ , op_avg) +-#undef op_avg +-#undef op_avg_no_rnd +-#undef op_put +-#undef op_put_no_rnd +- +-#define put_qpel8_mc00_c ff_put_pixels8x8_c +-#define avg_qpel8_mc00_c ff_avg_pixels8x8_c +-#define put_qpel16_mc00_c ff_put_pixels16x16_c +-#define avg_qpel16_mc00_c ff_avg_pixels16x16_c +-#define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c +-#define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_c +- +-#if 1 +-#define H264_LOWPASS(OPNAME, OP, OP2) \ +-static av_unused void OPNAME ## h264_qpel2_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride){\ +- const int h=2;\ +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ +- int i;\ +- for(i=0; i>5]+1)>>1) +-//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) +-#define op_put(a, b) a = cm[((b) + 16)>>5] +-#define op2_avg(a, b) a = (((a)+cm[((b) + 512)>>10]+1)>>1) +-#define op2_put(a, b) a = cm[((b) + 512)>>10] +- +-H264_LOWPASS(put_ , op_put, op2_put) +-H264_LOWPASS(avg_ , op_avg, op2_avg) +-H264_MC(put_, 2) +-H264_MC(put_, 4) +-H264_MC(put_, 8) +-H264_MC(put_, 16) +-H264_MC(avg_, 4) +-H264_MC(avg_, 8) +-H264_MC(avg_, 16) ++static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src, int stride){\ ++ uint8_t halfH[272];\ ++ put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);\ ++ OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);\ ++} ++ ++#define op_avg(a, b) a = (((a)+cm[((b) + 16)>>5]+1)>>1) ++#define op_avg_no_rnd(a, b) a = (((a)+cm[((b) + 15)>>5])>>1) ++#define op_put(a, b) a = cm[((b) + 16)>>5] ++#define op_put_no_rnd(a, b) a = cm[((b) + 15)>>5] + ++QPEL_MC(0, put_ , _ , op_put) ++QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd) ++QPEL_MC(0, avg_ , _ , op_avg) ++//QPEL_MC(1, avg_no_rnd , _ , op_avg) + #undef op_avg ++#undef op_avg_no_rnd + #undef op_put +-#undef op2_avg +-#undef op2_put +-#endif ++#undef op_put_no_rnd + +-#define put_h264_qpel8_mc00_c ff_put_pixels8x8_c +-#define avg_h264_qpel8_mc00_c ff_avg_pixels8x8_c +-#define put_h264_qpel16_mc00_c ff_put_pixels16x16_c +-#define avg_h264_qpel16_mc00_c ff_avg_pixels16x16_c ++#define put_qpel8_mc00_c ff_put_pixels8x8_c ++#define avg_qpel8_mc00_c ff_avg_pixels8x8_c ++#define put_qpel16_mc00_c ff_put_pixels16x16_c ++#define avg_qpel16_mc00_c ff_avg_pixels16x16_c ++#define put_no_rnd_qpel8_mc00_c ff_put_pixels8x8_c ++#define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_8_c + + static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +@@ -2592,34 +1308,66 @@ + } + } + +-void ff_put_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride) { +- put_pixels8_c(dst, src, stride, 8); +-} +-void ff_avg_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride) { +- avg_pixels8_c(dst, src, stride, 8); +-} +-void ff_put_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride) { +- put_pixels16_c(dst, src, stride, 16); +-} +-void ff_avg_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride) { +- avg_pixels16_c(dst, src, stride, 16); +-} +- + #if CONFIG_RV40_DECODER +-static void put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ +- put_pixels16_xy2_c(dst, src, stride, 16); ++void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ ++ put_pixels16_xy2_8_c(dst, src, stride, 16); + } +-static void avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ +- avg_pixels16_xy2_c(dst, src, stride, 16); ++void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride){ ++ avg_pixels16_xy2_8_c(dst, src, stride, 16); + } +-static void put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ +- put_pixels8_xy2_c(dst, src, stride, 8); ++void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ ++ put_pixels8_xy2_8_c(dst, src, stride, 8); + } +-static void avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ +- avg_pixels8_xy2_c(dst, src, stride, 8); ++void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride){ ++ avg_pixels8_xy2_8_c(dst, src, stride, 8); + } + #endif /* CONFIG_RV40_DECODER */ + ++#if CONFIG_DIRAC_DECODER ++#define DIRAC_MC(OPNAME)\ ++void ff_ ## OPNAME ## _dirac_pixels8_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels8_8_c(dst, src[0], stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels16_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_8_c(dst, src[0], stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels32_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_8_c(dst , src[0] , stride, h);\ ++ OPNAME ## _pixels16_8_c(dst+16, src[0]+16, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels8_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels8_l2_8(dst, src[0], src[1], stride, stride, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels16_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_l2_8(dst, src[0], src[1], stride, stride, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels32_l2_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_l2_8(dst , src[0] , src[1] , stride, stride, stride, h);\ ++ OPNAME ## _pixels16_l2_8(dst+16, src[0]+16, src[1]+16, stride, stride, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels8_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels8_l4_8(dst, src[0], src[1], src[2], src[3], stride, stride, stride, stride, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels16_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_l4_8(dst, src[0], src[1], src[2], src[3], stride, stride, stride, stride, stride, h);\ ++}\ ++void ff_ ## OPNAME ## _dirac_pixels32_l4_c(uint8_t *dst, const uint8_t *src[5], int stride, int h)\ ++{\ ++ OPNAME ## _pixels16_l4_8(dst , src[0] , src[1] , src[2] , src[3] , stride, stride, stride, stride, stride, h);\ ++ OPNAME ## _pixels16_l4_8(dst+16, src[0]+16, src[1]+16, src[2]+16, src[3]+16, stride, stride, stride, stride, stride, h);\ ++} ++DIRAC_MC(put) ++DIRAC_MC(avg) ++#endif ++ + static void wmv2_mspel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int w){ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + int i; +@@ -2652,7 +1400,7 @@ + static void put_mspel8_mc10_c(uint8_t *dst, uint8_t *src, int stride){ + uint8_t half[64]; + wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); +- put_pixels8_l2(dst, src, half, stride, stride, 8, 8); ++ put_pixels8_l2_8(dst, src, half, stride, stride, 8, 8); + } + + static void put_mspel8_mc20_c(uint8_t *dst, uint8_t *src, int stride){ +@@ -2662,7 +1410,7 @@ + static void put_mspel8_mc30_c(uint8_t *dst, uint8_t *src, int stride){ + uint8_t half[64]; + wmv2_mspel8_h_lowpass(half, src, 8, stride, 8); +- put_pixels8_l2(dst, src+1, half, stride, stride, 8, 8); ++ put_pixels8_l2_8(dst, src+1, half, stride, stride, 8, 8); + } + + static void put_mspel8_mc02_c(uint8_t *dst, uint8_t *src, int stride){ +@@ -2676,7 +1424,7 @@ + wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); + wmv2_mspel8_v_lowpass(halfV, src, 8, stride, 8); + wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); +- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); ++ put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8); + } + static void put_mspel8_mc32_c(uint8_t *dst, uint8_t *src, int stride){ + uint8_t halfH[88]; +@@ -2685,7 +1433,7 @@ + wmv2_mspel8_h_lowpass(halfH, src-stride, 8, stride, 11); + wmv2_mspel8_v_lowpass(halfV, src+1, 8, stride, 8); + wmv2_mspel8_v_lowpass(halfHV, halfH+8, 8, 8, 8); +- put_pixels8_l2(dst, halfV, halfHV, stride, 8, 8, 8); ++ put_pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8); + } + static void put_mspel8_mc22_c(uint8_t *dst, uint8_t *src, int stride){ + uint8_t halfH[88]; +@@ -3070,7 +1818,7 @@ + } + + /** +- * permutes an 8x8 block. ++ * Permute an 8x8 block. + * @param block the block which will be permuted according to the given permutation vector + * @param permutation the permutation vector + * @param last the last non zero coefficient in scantable order, used to speed the permutation up +@@ -3162,19 +1910,6 @@ + } + } + +-static void clear_block_c(DCTELEM *block) +-{ +- memset(block, 0, sizeof(DCTELEM)*64); +-} +- +-/** +- * memset(blocks, 0, sizeof(DCTELEM)*6*64) +- */ +-static void clear_blocks_c(DCTELEM *blocks) +-{ +- memset(blocks, 0, sizeof(DCTELEM)*6*64); +-} +- + static void add_bytes_c(uint8_t *dst, uint8_t *src, int w){ + long i; + for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ +@@ -3186,17 +1921,6 @@ + dst[i+0] += src[i+0]; + } + +-static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ +- long i; +- for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ +- long a = *(long*)(src1+i); +- long b = *(long*)(src2+i); +- *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80); +- } +- for(; imaxi){ +- maxi=sum; +- printf("MAX:%d\n", maxi); +-} +-#endif + return sum; + } + +@@ -3527,7 +2244,7 @@ + + s->block_last_index[0/*FIXME*/]= s->fast_dct_quantize(s, temp, 0/*FIXME*/, s->qscale, &i); + s->dct_unquantize_inter(s, temp, 0, s->qscale); +- ff_simple_idct(temp); //FIXME ++ ff_simple_idct_8(temp); //FIXME + + for(i=0; i<64; i++) + sum+= (temp[i]-bak[i])*(temp[i]-bak[i]); +@@ -3801,48 +2518,12 @@ + dst[i] = src[i] * mul; + } + +-static void vector_fmul_sv_scalar_2_c(float *dst, const float *src, +- const float **sv, float mul, int len) +-{ +- int i; +- for (i = 0; i < len; i += 2, sv++) { +- dst[i ] = src[i ] * sv[0][0] * mul; +- dst[i+1] = src[i+1] * sv[0][1] * mul; +- } +-} +- +-static void vector_fmul_sv_scalar_4_c(float *dst, const float *src, +- const float **sv, float mul, int len) +-{ +- int i; +- for (i = 0; i < len; i += 4, sv++) { +- dst[i ] = src[i ] * sv[0][0] * mul; +- dst[i+1] = src[i+1] * sv[0][1] * mul; +- dst[i+2] = src[i+2] * sv[0][2] * mul; +- dst[i+3] = src[i+3] * sv[0][3] * mul; +- } +-} +- +-static void sv_fmul_scalar_2_c(float *dst, const float **sv, float mul, +- int len) +-{ +- int i; +- for (i = 0; i < len; i += 2, sv++) { +- dst[i ] = sv[0][0] * mul; +- dst[i+1] = sv[0][1] * mul; +- } +-} +- +-static void sv_fmul_scalar_4_c(float *dst, const float **sv, float mul, +- int len) ++static void vector_fmac_scalar_c(float *dst, const float *src, float mul, ++ int len) + { + int i; +- for (i = 0; i < len; i += 4, sv++) { +- dst[i ] = sv[0][0] * mul; +- dst[i+1] = sv[0][1] * mul; +- dst[i+2] = sv[0][2] * mul; +- dst[i+3] = sv[0][3] * mul; +- } ++ for (i = 0; i < len; i++) ++ dst[i] += src[i] * mul; + } + + static void butterflies_float_c(float *restrict v1, float *restrict v2, +@@ -3856,6 +2537,18 @@ + } + } + ++static void butterflies_float_interleave_c(float *dst, const float *src0, ++ const float *src1, int len) ++{ ++ int i; ++ for (i = 0; i < len; i++) { ++ float f1 = src0[i]; ++ float f2 = src1[i]; ++ dst[2*i ] = f1 + f2; ++ dst[2*i + 1] = f1 - f2; ++ } ++} ++ + static float scalarproduct_float_c(const float *v1, const float *v2, int len) + { + float p = 0.0; +@@ -3872,7 +2565,7 @@ + { + + if(a > mini) return mini; +- else if((a^(1<<31)) > maxisign) return maxi; ++ else if((a^(1U<<31)) > maxisign) return maxi; + else return a; + } + +@@ -3880,7 +2573,7 @@ + int i; + uint32_t mini = *(uint32_t*)min; + uint32_t maxi = *(uint32_t*)max; +- uint32_t maxisign = maxi ^ (1<<31); ++ uint32_t maxisign = maxi ^ (1U<<31); + uint32_t *dsti = (uint32_t*)dst; + const uint32_t *srci = (const uint32_t*)src; + for(i=0; i> 1; ++ ++ for (i = 0; i < len2; i++) { ++ int16_t w = window[i]; ++ output[i] = (MUL16(input[i], w) + (1 << 14)) >> 15; ++ output[len-i-1] = (MUL16(input[len-i-1], w) + (1 << 14)) >> 15; ++ } ++} ++ ++static void vector_clip_int32_c(int32_t *dst, const int32_t *src, int32_t min, ++ int32_t max, unsigned int len) ++{ ++ do { ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ *dst++ = av_clip(*src++, min, max); ++ len -= 8; ++ } while (len > 0); ++} ++ + #define W0 2048 + #define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ + #define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ +@@ -4009,22 +2731,22 @@ + static void ff_wmv2_idct_put_c(uint8_t *dest, int line_size, DCTELEM *block) + { + ff_wmv2_idct_c(block); +- put_pixels_clamped_c(block, dest, line_size); ++ ff_put_pixels_clamped_c(block, dest, line_size); + } + static void ff_wmv2_idct_add_c(uint8_t *dest, int line_size, DCTELEM *block) + { + ff_wmv2_idct_c(block); +- add_pixels_clamped_c(block, dest, line_size); ++ ff_add_pixels_clamped_c(block, dest, line_size); + } + static void ff_jref_idct_put(uint8_t *dest, int line_size, DCTELEM *block) + { + j_rev_dct (block); +- put_pixels_clamped_c(block, dest, line_size); ++ ff_put_pixels_clamped_c(block, dest, line_size); + } + static void ff_jref_idct_add(uint8_t *dest, int line_size, DCTELEM *block) + { + j_rev_dct (block); +- add_pixels_clamped_c(block, dest, line_size); ++ ff_add_pixels_clamped_c(block, dest, line_size); + } + + static void ff_jref_idct4_put(uint8_t *dest, int line_size, DCTELEM *block) +@@ -4051,15 +2773,11 @@ + + static void ff_jref_idct1_put(uint8_t *dest, int line_size, DCTELEM *block) + { +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- dest[0] = cm[(block[0] + 4)>>3]; ++ dest[0] = av_clip_uint8((block[0] + 4)>>3); + } + static void ff_jref_idct1_add(uint8_t *dest, int line_size, DCTELEM *block) + { +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- dest[0] = cm[dest[0] + ((block[0] + 4)>>3)]; ++ dest[0] = av_clip_uint8(dest[0] + ((block[0] + 4)>>3)); + } + + static void just_return(void *mem av_unused, int stride av_unused, int h av_unused) { return; } +@@ -4084,9 +2802,9 @@ + + int ff_check_alignment(void){ + static int did_fail=0; +- DECLARE_ALIGNED(16, int, aligned); ++ LOCAL_ALIGNED_16(int, aligned, [4]); + +- if((intptr_t)&aligned & 15){ ++ if((intptr_t)aligned & 15){ + if(!did_fail){ + #if HAVE_MMX || HAVE_ALTIVEC + av_log(NULL, AV_LOG_ERROR, +@@ -4109,28 +2827,28 @@ + ff_check_alignment(); + + #if CONFIG_ENCODERS +- if(avctx->dct_algo==FF_DCT_FASTINT) { +- c->fdct = fdct_ifast; +- c->fdct248 = fdct_ifast248; +- } +- else if(avctx->dct_algo==FF_DCT_FAAN) { +- c->fdct = ff_faandct; +- c->fdct248 = ff_faandct248; +- } +- else { +- c->fdct = ff_jpeg_fdct_islow; //slow/accurate/default +- c->fdct248 = ff_fdct248_islow; ++ if (avctx->bits_per_raw_sample == 10) { ++ c->fdct = ff_jpeg_fdct_islow_10; ++ c->fdct248 = ff_fdct248_islow_10; ++ } else { ++ if(avctx->dct_algo==FF_DCT_FASTINT) { ++ c->fdct = fdct_ifast; ++ c->fdct248 = fdct_ifast248; ++ } ++ else if(avctx->dct_algo==FF_DCT_FAAN) { ++ c->fdct = ff_faandct; ++ c->fdct248 = ff_faandct248; ++ } ++ else { ++ c->fdct = ff_jpeg_fdct_islow_8; //slow/accurate/default ++ c->fdct248 = ff_fdct248_islow_8; ++ } + } + #endif //CONFIG_ENCODERS + + if(avctx->lowres==1){ +- if(avctx->idct_algo==FF_IDCT_INT || avctx->idct_algo==FF_IDCT_AUTO || !CONFIG_H264_DECODER){ +- c->idct_put= ff_jref_idct4_put; +- c->idct_add= ff_jref_idct4_add; +- }else{ +- c->idct_put= ff_h264_lowres_idct_put_c; +- c->idct_add= ff_h264_lowres_idct_add_c; +- } ++ c->idct_put= ff_jref_idct4_put; ++ c->idct_add= ff_jref_idct4_add; + c->idct = j_rev_dct4; + c->idct_permutation_type= FF_NO_IDCT_PERM; + }else if(avctx->lowres==2){ +@@ -4144,6 +2862,12 @@ + c->idct = j_rev_dct1; + c->idct_permutation_type= FF_NO_IDCT_PERM; + }else{ ++ if (avctx->bits_per_raw_sample == 10) { ++ c->idct_put = ff_simple_idct_put_10; ++ c->idct_add = ff_simple_idct_add_10; ++ c->idct = ff_simple_idct_10; ++ c->idct_permutation_type = FF_NO_IDCT_PERM; ++ } else { + if(avctx->idct_algo==FF_IDCT_INT){ + c->idct_put= ff_jref_idct_put; + c->idct_add= ff_jref_idct_add; +@@ -4168,39 +2892,27 @@ + }else if(CONFIG_EATGQ_DECODER && avctx->idct_algo==FF_IDCT_EA) { + c->idct_put= ff_ea_idct_put_c; + c->idct_permutation_type= FF_NO_IDCT_PERM; +- }else if(CONFIG_BINK_DECODER && avctx->idct_algo==FF_IDCT_BINK) { +- c->idct = ff_bink_idct_c; +- c->idct_add = ff_bink_idct_add_c; +- c->idct_put = ff_bink_idct_put_c; +- c->idct_permutation_type = FF_NO_IDCT_PERM; + }else{ //accurate/default +- c->idct_put= ff_simple_idct_put; +- c->idct_add= ff_simple_idct_add; +- c->idct = ff_simple_idct; ++ c->idct_put = ff_simple_idct_put_8; ++ c->idct_add = ff_simple_idct_add_8; ++ c->idct = ff_simple_idct_8; + c->idct_permutation_type= FF_NO_IDCT_PERM; + } ++ } + } + +- c->get_pixels = get_pixels_c; + c->diff_pixels = diff_pixels_c; +- c->put_pixels_clamped = put_pixels_clamped_c; +- c->put_signed_pixels_clamped = put_signed_pixels_clamped_c; +- c->put_pixels_nonclamped = put_pixels_nonclamped_c; +- c->add_pixels_clamped = add_pixels_clamped_c; +- c->add_pixels8 = add_pixels8_c; +- c->add_pixels4 = add_pixels4_c; ++ c->put_pixels_clamped = ff_put_pixels_clamped_c; ++ c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_c; ++ c->add_pixels_clamped = ff_add_pixels_clamped_c; + c->sum_abs_dctelem = sum_abs_dctelem_c; +- c->emulated_edge_mc = ff_emulated_edge_mc; + c->gmc1 = gmc1_c; + c->gmc = ff_gmc_c; +- c->clear_block = clear_block_c; +- c->clear_blocks = clear_blocks_c; + c->pix_sum = pix_sum_c; + c->pix_norm1 = pix_norm1_c; + + c->fill_block_tab[0] = fill_block16_c; + c->fill_block_tab[1] = fill_block8_c; +- c->scale_block = scale_block_c; + + /* TODO [0] 16 [1] 8 */ + c->pix_abs[0][0] = pix_abs16_c; +@@ -4212,30 +2924,6 @@ + c->pix_abs[1][2] = pix_abs8_y2_c; + c->pix_abs[1][3] = pix_abs8_xy2_c; + +-#define dspfunc(PFX, IDX, NUM) \ +- c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## NUM ## _c; \ +- c->PFX ## _pixels_tab[IDX][1] = PFX ## _pixels ## NUM ## _x2_c; \ +- c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## NUM ## _y2_c; \ +- c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## NUM ## _xy2_c +- +- dspfunc(put, 0, 16); +- dspfunc(put_no_rnd, 0, 16); +- dspfunc(put, 1, 8); +- dspfunc(put_no_rnd, 1, 8); +- dspfunc(put, 2, 4); +- dspfunc(put, 3, 2); +- +- dspfunc(avg, 0, 16); +- dspfunc(avg_no_rnd, 0, 16); +- dspfunc(avg, 1, 8); +- dspfunc(avg_no_rnd, 1, 8); +- dspfunc(avg, 2, 4); +- dspfunc(avg, 3, 2); +-#undef dspfunc +- +- c->put_no_rnd_pixels_l2[0]= put_no_rnd_pixels16_l2_c; +- c->put_no_rnd_pixels_l2[1]= put_no_rnd_pixels8_l2_c; +- + c->put_tpel_pixels_tab[ 0] = put_tpel_pixels_mc00_c; + c->put_tpel_pixels_tab[ 1] = put_tpel_pixels_mc10_c; + c->put_tpel_pixels_tab[ 2] = put_tpel_pixels_mc20_c; +@@ -4286,45 +2974,14 @@ + dspfunc(avg_qpel, 1, 8); + /* dspfunc(avg_no_rnd_qpel, 1, 8); */ + +- dspfunc(put_h264_qpel, 0, 16); +- dspfunc(put_h264_qpel, 1, 8); +- dspfunc(put_h264_qpel, 2, 4); +- dspfunc(put_h264_qpel, 3, 2); +- dspfunc(avg_h264_qpel, 0, 16); +- dspfunc(avg_h264_qpel, 1, 8); +- dspfunc(avg_h264_qpel, 2, 4); +- + #undef dspfunc +- c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_c; +- c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_c; +- c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_c; +- c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_c; +- c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_c; +- c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_c; +- c->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c; +- c->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c; +- +- c->draw_edges = draw_edges_c; + + #if CONFIG_MLP_DECODER || CONFIG_TRUEHD_DECODER + ff_mlp_init(c, avctx); + #endif +-#if CONFIG_VC1_DECODER +- ff_vc1dsp_init(c,avctx); +-#endif + #if CONFIG_WMV2_DECODER || CONFIG_VC1_DECODER + ff_intrax8dsp_init(c,avctx); + #endif +-#if CONFIG_RV30_DECODER +- ff_rv30dsp_init(c,avctx); +-#endif +-#if CONFIG_RV40_DECODER +- ff_rv40dsp_init(c,avctx); +- c->put_rv40_qpel_pixels_tab[0][15] = put_rv40_qpel16_mc33_c; +- c->avg_rv40_qpel_pixels_tab[0][15] = avg_rv40_qpel16_mc33_c; +- c->put_rv40_qpel_pixels_tab[1][15] = put_rv40_qpel8_mc33_c; +- c->avg_rv40_qpel_pixels_tab[1][15] = avg_rv40_qpel8_mc33_c; +-#endif + + c->put_mspel_pixels_tab[0]= ff_put_pixels8x8_c; + c->put_mspel_pixels_tab[1]= put_mspel8_mc10_c; +@@ -4370,16 +3027,13 @@ + c->ssd_int8_vs_int16 = ssd_int8_vs_int16_c; + + c->add_bytes= add_bytes_c; +- c->add_bytes_l2= add_bytes_l2_c; + c->diff_bytes= diff_bytes_c; + c->add_hfyu_median_prediction= add_hfyu_median_prediction_c; + c->sub_hfyu_median_prediction= sub_hfyu_median_prediction_c; + c->add_hfyu_left_prediction = add_hfyu_left_prediction_c; + c->add_hfyu_left_prediction_bgr32 = add_hfyu_left_prediction_bgr32_c; + c->bswap_buf= bswap_buf; +-#if CONFIG_PNG_DECODER +- c->add_png_paeth_prediction= ff_add_png_paeth_prediction; +-#endif ++ c->bswap16_buf = bswap16_buf; + + if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { + c->h263_h_loop_filter= h263_h_loop_filter_c; +@@ -4410,15 +3064,13 @@ + c->vector_clipf = vector_clipf_c; + c->scalarproduct_int16 = scalarproduct_int16_c; + c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_c; ++ c->apply_window_int16 = apply_window_int16_c; ++ c->vector_clip_int32 = vector_clip_int32_c; + c->scalarproduct_float = scalarproduct_float_c; + c->butterflies_float = butterflies_float_c; ++ c->butterflies_float_interleave = butterflies_float_interleave_c; + c->vector_fmul_scalar = vector_fmul_scalar_c; +- +- c->vector_fmul_sv_scalar[0] = vector_fmul_sv_scalar_2_c; +- c->vector_fmul_sv_scalar[1] = vector_fmul_sv_scalar_4_c; +- +- c->sv_fmul_scalar[0] = sv_fmul_scalar_2_c; +- c->sv_fmul_scalar[1] = sv_fmul_scalar_4_c; ++ c->vector_fmac_scalar = vector_fmac_scalar_c; + + c->shrink[0]= av_image_copy_plane; + c->shrink[1]= ff_shrink22; +@@ -4430,6 +3082,98 @@ + memset(c->put_2tap_qpel_pixels_tab, 0, sizeof(c->put_2tap_qpel_pixels_tab)); + memset(c->avg_2tap_qpel_pixels_tab, 0, sizeof(c->avg_2tap_qpel_pixels_tab)); + ++#undef FUNC ++#undef FUNCC ++#define FUNC(f, depth) f ## _ ## depth ++#define FUNCC(f, depth) f ## _ ## depth ## _c ++ ++#define dspfunc1(PFX, IDX, NUM, depth)\ ++ c->PFX ## _pixels_tab[IDX][0] = FUNCC(PFX ## _pixels ## NUM , depth);\ ++ c->PFX ## _pixels_tab[IDX][1] = FUNCC(PFX ## _pixels ## NUM ## _x2 , depth);\ ++ c->PFX ## _pixels_tab[IDX][2] = FUNCC(PFX ## _pixels ## NUM ## _y2 , depth);\ ++ c->PFX ## _pixels_tab[IDX][3] = FUNCC(PFX ## _pixels ## NUM ## _xy2, depth) ++ ++#define dspfunc2(PFX, IDX, NUM, depth)\ ++ c->PFX ## _pixels_tab[IDX][ 0] = FUNCC(PFX ## NUM ## _mc00, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 1] = FUNCC(PFX ## NUM ## _mc10, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 2] = FUNCC(PFX ## NUM ## _mc20, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 3] = FUNCC(PFX ## NUM ## _mc30, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 4] = FUNCC(PFX ## NUM ## _mc01, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 5] = FUNCC(PFX ## NUM ## _mc11, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 6] = FUNCC(PFX ## NUM ## _mc21, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 7] = FUNCC(PFX ## NUM ## _mc31, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 8] = FUNCC(PFX ## NUM ## _mc02, depth);\ ++ c->PFX ## _pixels_tab[IDX][ 9] = FUNCC(PFX ## NUM ## _mc12, depth);\ ++ c->PFX ## _pixels_tab[IDX][10] = FUNCC(PFX ## NUM ## _mc22, depth);\ ++ c->PFX ## _pixels_tab[IDX][11] = FUNCC(PFX ## NUM ## _mc32, depth);\ ++ c->PFX ## _pixels_tab[IDX][12] = FUNCC(PFX ## NUM ## _mc03, depth);\ ++ c->PFX ## _pixels_tab[IDX][13] = FUNCC(PFX ## NUM ## _mc13, depth);\ ++ c->PFX ## _pixels_tab[IDX][14] = FUNCC(PFX ## NUM ## _mc23, depth);\ ++ c->PFX ## _pixels_tab[IDX][15] = FUNCC(PFX ## NUM ## _mc33, depth) ++ ++ ++#define BIT_DEPTH_FUNCS(depth, dct)\ ++ c->get_pixels = FUNCC(get_pixels ## dct , depth);\ ++ c->draw_edges = FUNCC(draw_edges , depth);\ ++ c->emulated_edge_mc = FUNC (ff_emulated_edge_mc , depth);\ ++ c->clear_block = FUNCC(clear_block ## dct , depth);\ ++ c->clear_blocks = FUNCC(clear_blocks ## dct , depth);\ ++ c->add_pixels8 = FUNCC(add_pixels8 ## dct , depth);\ ++ c->add_pixels4 = FUNCC(add_pixels4 ## dct , depth);\ ++ c->put_no_rnd_pixels_l2[0] = FUNCC(put_no_rnd_pixels16_l2, depth);\ ++ c->put_no_rnd_pixels_l2[1] = FUNCC(put_no_rnd_pixels8_l2 , depth);\ ++\ ++ c->put_h264_chroma_pixels_tab[0] = FUNCC(put_h264_chroma_mc8 , depth);\ ++ c->put_h264_chroma_pixels_tab[1] = FUNCC(put_h264_chroma_mc4 , depth);\ ++ c->put_h264_chroma_pixels_tab[2] = FUNCC(put_h264_chroma_mc2 , depth);\ ++ c->avg_h264_chroma_pixels_tab[0] = FUNCC(avg_h264_chroma_mc8 , depth);\ ++ c->avg_h264_chroma_pixels_tab[1] = FUNCC(avg_h264_chroma_mc4 , depth);\ ++ c->avg_h264_chroma_pixels_tab[2] = FUNCC(avg_h264_chroma_mc2 , depth);\ ++\ ++ dspfunc1(put , 0, 16, depth);\ ++ dspfunc1(put , 1, 8, depth);\ ++ dspfunc1(put , 2, 4, depth);\ ++ dspfunc1(put , 3, 2, depth);\ ++ dspfunc1(put_no_rnd, 0, 16, depth);\ ++ dspfunc1(put_no_rnd, 1, 8, depth);\ ++ dspfunc1(avg , 0, 16, depth);\ ++ dspfunc1(avg , 1, 8, depth);\ ++ dspfunc1(avg , 2, 4, depth);\ ++ dspfunc1(avg , 3, 2, depth);\ ++ dspfunc1(avg_no_rnd, 0, 16, depth);\ ++ dspfunc1(avg_no_rnd, 1, 8, depth);\ ++\ ++ dspfunc2(put_h264_qpel, 0, 16, depth);\ ++ dspfunc2(put_h264_qpel, 1, 8, depth);\ ++ dspfunc2(put_h264_qpel, 2, 4, depth);\ ++ dspfunc2(put_h264_qpel, 3, 2, depth);\ ++ dspfunc2(avg_h264_qpel, 0, 16, depth);\ ++ dspfunc2(avg_h264_qpel, 1, 8, depth);\ ++ dspfunc2(avg_h264_qpel, 2, 4, depth); ++ ++ switch (avctx->bits_per_raw_sample) { ++ case 9: ++ if (c->dct_bits == 32) { ++ BIT_DEPTH_FUNCS(9, _32); ++ } else { ++ BIT_DEPTH_FUNCS(9, _16); ++ } ++ break; ++ case 10: ++ if (c->dct_bits == 32) { ++ BIT_DEPTH_FUNCS(10, _32); ++ } else { ++ BIT_DEPTH_FUNCS(10, _16); ++ } ++ break; ++ default: ++ av_log(avctx, AV_LOG_DEBUG, "Unsupported bit depth: %d\n", avctx->bits_per_raw_sample); ++ case 8: ++ BIT_DEPTH_FUNCS(8, _16); ++ break; ++ } ++ ++ + if (HAVE_MMX) dsputil_init_mmx (c, avctx); + if (ARCH_ARM) dsputil_init_arm (c, avctx); + if (CONFIG_MLIB) dsputil_init_mlib (c, avctx); +@@ -4447,43 +3191,6 @@ + c->avg_2tap_qpel_pixels_tab[0][i]= c->avg_h264_qpel_pixels_tab[0][i]; + } + +- c->put_rv30_tpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0]; +- c->put_rv30_tpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0]; +- c->avg_rv30_tpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0]; +- c->avg_rv30_tpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0]; +- +- c->put_rv40_qpel_pixels_tab[0][0] = c->put_h264_qpel_pixels_tab[0][0]; +- c->put_rv40_qpel_pixels_tab[1][0] = c->put_h264_qpel_pixels_tab[1][0]; +- c->avg_rv40_qpel_pixels_tab[0][0] = c->avg_h264_qpel_pixels_tab[0][0]; +- c->avg_rv40_qpel_pixels_tab[1][0] = c->avg_h264_qpel_pixels_tab[1][0]; +- +- switch(c->idct_permutation_type){ +- case FF_NO_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= i; +- break; +- case FF_LIBMPEG2_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= (i & 0x38) | ((i & 6) >> 1) | ((i & 1) << 2); +- break; +- case FF_SIMPLE_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= simple_mmx_permutation[i]; +- break; +- case FF_TRANSPOSE_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= ((i&7)<<3) | (i>>3); +- break; +- case FF_PARTTRANS_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= (i&0x24) | ((i&3)<<3) | ((i>>3)&3); +- break; +- case FF_SSE2_IDCT_PERM: +- for(i=0; i<64; i++) +- c->idct_permutation[i]= (i&0x38) | idct_sse2_row_perm[i&7]; +- break; +- default: +- av_log(avctx, AV_LOG_ERROR, "Internal error, IDCT permutation not set\n"); +- } ++ ff_init_scantable_permutation(c->idct_permutation, ++ c->idct_permutation_type); + } +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil.h 2012-05-14 14:08:53.650326215 +0200 +@@ -40,8 +40,10 @@ + + void fdct_ifast (DCTELEM *data); + void fdct_ifast248 (DCTELEM *data); +-void ff_jpeg_fdct_islow (DCTELEM *data); +-void ff_fdct248_islow (DCTELEM *data); ++void ff_jpeg_fdct_islow_8(DCTELEM *data); ++void ff_jpeg_fdct_islow_10(DCTELEM *data); ++void ff_fdct248_islow_8(DCTELEM *data); ++void ff_fdct248_islow_10(DCTELEM *data); + + void j_rev_dct (DCTELEM *data); + void j_rev_dct4 (DCTELEM *data); +@@ -53,18 +55,24 @@ + void ff_fdct_mmx2(DCTELEM *block); + void ff_fdct_sse2(DCTELEM *block); + +-void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride); +-void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride); +-void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); +-void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride); +-void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block); +-void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block); +-void ff_h264_idct_add16_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add16intra_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct8_add4_c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add8_c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]); ++#define H264_IDCT(depth) \ ++void ff_h264_idct8_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ ++void ff_h264_idct_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ ++void ff_h264_idct8_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ ++void ff_h264_idct_dc_add_ ## depth ## _c(uint8_t *dst, DCTELEM *block, int stride);\ ++void ff_h264_idct_add16_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ ++void ff_h264_idct_add16intra_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ ++void ff_h264_idct8_add4_ ## depth ## _c(uint8_t *dst, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ ++void ff_h264_idct_add8_422_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ ++void ff_h264_idct_add8_ ## depth ## _c(uint8_t **dest, const int *blockoffset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]);\ ++void ff_h264_luma_dc_dequant_idct_ ## depth ## _c(DCTELEM *output, DCTELEM *input, int qmul);\ ++void ff_h264_chroma422_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul);\ ++void ff_h264_chroma_dc_dequant_idct_ ## depth ## _c(DCTELEM *block, int qmul); ++ ++H264_IDCT( 8) ++H264_IDCT( 9) ++H264_IDCT(10) + +-void ff_h264_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qmul); + void ff_svq3_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qp); + void ff_svq3_add_idct_c(uint8_t *dst, DCTELEM *block, int stride, int qp, int dc); + +@@ -81,10 +89,20 @@ + extern uint32_t ff_squareTbl[512]; + extern uint8_t ff_cropTbl[256 + 2 * MAX_NEG_CROP]; + +-void ff_put_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride); +-void ff_avg_pixels8x8_c(uint8_t *dst, uint8_t *src, int stride); +-void ff_put_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride); +-void ff_avg_pixels16x16_c(uint8_t *dst, uint8_t *src, int stride); ++#define PUTAVG_PIXELS(depth)\ ++void ff_put_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\ ++void ff_avg_pixels8x8_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\ ++void ff_put_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride);\ ++void ff_avg_pixels16x16_ ## depth ## _c(uint8_t *dst, uint8_t *src, int stride); ++ ++PUTAVG_PIXELS( 8) ++PUTAVG_PIXELS( 9) ++PUTAVG_PIXELS(10) ++ ++#define ff_put_pixels8x8_c ff_put_pixels8x8_8_c ++#define ff_avg_pixels8x8_c ff_avg_pixels8x8_8_c ++#define ff_put_pixels16x16_c ff_put_pixels16x16_8_c ++#define ff_avg_pixels16x16_c ff_avg_pixels16x16_8_c + + /* VP3 DSP functions */ + void ff_vp3_idct_c(DCTELEM *block/* align 16*/); +@@ -95,23 +113,16 @@ + void ff_vp3_v_loop_filter_c(uint8_t *src, int stride, int *bounding_values); + void ff_vp3_h_loop_filter_c(uint8_t *src, int stride, int *bounding_values); + +-/* Bink functions */ +-void ff_bink_idct_c (DCTELEM *block); +-void ff_bink_idct_add_c(uint8_t *dest, int linesize, DCTELEM *block); +-void ff_bink_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); +- + /* EA functions */ + void ff_ea_idct_put_c(uint8_t *dest, int linesize, DCTELEM *block); + +-/* 1/2^n downscaling functions from imgconvert.c */ +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-/** +- * @deprecated Use av_image_copy_plane() instead. +- */ +-attribute_deprecated +-void ff_img_copy_plane(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +-#endif ++/* RV40 functions */ ++void ff_put_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride); ++void ff_avg_rv40_qpel16_mc33_c(uint8_t *dst, uint8_t *src, int stride); ++void ff_put_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride); ++void ff_avg_rv40_qpel8_mc33_c(uint8_t *dst, uint8_t *src, int stride); + ++/* 1/2^n downscaling functions from imgconvert.c */ + void ff_shrink22(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); + void ff_shrink44(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); + void ff_shrink88(uint8_t *dst, int dst_wrap, const uint8_t *src, int src_wrap, int width, int height); +@@ -142,7 +153,7 @@ + + /* add and put pixel (decoding) */ + // blocksizes for op_pixels_func are 8x4,8x8 16x8 16x16 +-//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller then 4 ++//h for op_pixels_func is limited to {width/2, width} but never larger than 16 and never smaller than 4 + typedef void (*op_pixels_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int h); + typedef void (*tpel_mc_func)(uint8_t *block/*align width (8 or 16)*/, const uint8_t *pixels/*align 1*/, int line_size, int w, int h); + typedef void (*qpel_mc_func)(uint8_t *dst/*align width (8 or 16)*/, uint8_t *src/*align 1*/, int stride); +@@ -175,7 +186,7 @@ + } + + /* motion estimation */ +-// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller then 2 ++// h is limited to {width/2, width, 2*width} but never larger than 16 and never smaller than 2 + // although currently h<4 is not used as functions with width <8 are neither used nor implemented + typedef int (*me_cmp_func)(void /*MpegEncContext*/ *s, uint8_t *blk1/*align width (8 or 16)*/, uint8_t *blk2/*align 1*/, int line_size, int h)/* __attribute__ ((const))*/; + +@@ -193,21 +204,36 @@ + } ScanTable; + + void ff_init_scantable(uint8_t *, ScanTable *st, const uint8_t *src_scantable); ++void ff_init_scantable_permutation(uint8_t *idct_permutation, ++ int idct_permutation_type); + +-void ff_emulated_edge_mc(uint8_t *buf, const uint8_t *src, int linesize, +- int block_w, int block_h, ++#define EMULATED_EDGE(depth) \ ++void ff_emulated_edge_mc_ ## depth (uint8_t *buf, const uint8_t *src, int linesize,\ ++ int block_w, int block_h,\ + int src_x, int src_y, int w, int h); + ++EMULATED_EDGE(8) ++EMULATED_EDGE(9) ++EMULATED_EDGE(10) ++ ++void ff_add_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); ++void ff_put_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); ++void ff_put_signed_pixels_clamped_c(const DCTELEM *block, uint8_t *dest, int linesize); ++ + /** + * DSPContext. + */ + typedef struct DSPContext { ++ /** ++ * Size of DCT coefficients. ++ */ ++ int dct_bits; ++ + /* pixel ops : interface with DCT */ + void (*get_pixels)(DCTELEM *block/*align 16*/, const uint8_t *pixels/*align 8*/, int line_size); + void (*diff_pixels)(DCTELEM *block/*align 16*/, const uint8_t *s1/*align 8*/, const uint8_t *s2/*align 8*/, int stride); + void (*put_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*put_signed_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); +- void (*put_pixels_nonclamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*add_pixels_clamped)(const DCTELEM *block/*align 16*/, uint8_t *pixels/*align 8*/, int line_size); + void (*add_pixels8)(uint8_t *pixels, DCTELEM *block, int line_size); + void (*add_pixels4)(uint8_t *pixels, DCTELEM *block, int line_size); +@@ -341,9 +367,6 @@ + */ + h264_chroma_mc_func put_h264_chroma_pixels_tab[3]; + h264_chroma_mc_func avg_h264_chroma_pixels_tab[3]; +- /* This is really one func used in VC-1 decoding */ +- h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3]; +- h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3]; + + qpel_mc_func put_h264_qpel_pixels_tab[4][16]; + qpel_mc_func avg_h264_qpel_pixels_tab[4][16]; +@@ -355,7 +378,6 @@ + + /* huffyuv specific */ + void (*add_bytes)(uint8_t *dst/*align 16*/, uint8_t *src/*align 16*/, int w); +- void (*add_bytes_l2)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 16*/, int w); + void (*diff_bytes)(uint8_t *dst/*align 16*/, uint8_t *src1/*align 16*/, uint8_t *src2/*align 1*/,int w); + /** + * subtract huffyuv's variant of median prediction +@@ -366,8 +388,8 @@ + int (*add_hfyu_left_prediction)(uint8_t *dst, const uint8_t *src, int w, int left); + void (*add_hfyu_left_prediction_bgr32)(uint8_t *dst, const uint8_t *src, int w, int *red, int *green, int *blue, int *alpha); + /* this might write to dst[w] */ +- void (*add_png_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); + void (*bswap_buf)(uint32_t *dst, const uint32_t *src, int w); ++ void (*bswap16_buf)(uint16_t *dst, const uint16_t *src, int len); + + void (*h263_v_loop_filter)(uint8_t *src, int stride, int qscale); + void (*h263_h_loop_filter)(uint8_t *src, int stride, int qscale); +@@ -404,31 +426,16 @@ + void (*vector_fmul_scalar)(float *dst, const float *src, float mul, + int len); + /** +- * Multiply a vector of floats by concatenated short vectors of +- * floats and by a scalar float. Source and destination vectors +- * must overlap exactly or not at all. +- * [0]: short vectors of length 2, 8-byte aligned +- * [1]: short vectors of length 4, 16-byte aligned +- * @param dst output vector, 16-byte aligned ++ * Multiply a vector of floats by a scalar float and add to ++ * destination vector. Source and destination vectors must ++ * overlap exactly or not at all. ++ * @param dst result vector, 16-byte aligned + * @param src input vector, 16-byte aligned +- * @param sv array of pointers to short vectors + * @param mul scalar value +- * @param len number of elements in src and dst, multiple of 4 +- */ +- void (*vector_fmul_sv_scalar[2])(float *dst, const float *src, +- const float **sv, float mul, int len); +- /** +- * Multiply short vectors of floats by a scalar float, store +- * concatenated result. +- * [0]: short vectors of length 2, 8-byte aligned +- * [1]: short vectors of length 4, 16-byte aligned +- * @param dst output vector, 16-byte aligned +- * @param sv array of pointers to short vectors +- * @param mul scalar value +- * @param len number of output elements, multiple of 4 ++ * @param len length of vector, multiple of 4 + */ +- void (*sv_fmul_scalar[2])(float *dst, const float **sv, +- float mul, int len); ++ void (*vector_fmac_scalar)(float *dst, const float *src, float mul, ++ int len); + /** + * Calculate the scalar product of two vectors of floats. + * @param v1 first vector, 16-byte aligned +@@ -444,6 +451,23 @@ + */ + void (*butterflies_float)(float *restrict v1, float *restrict v2, int len); + ++ /** ++ * Calculate the sum and difference of two vectors of floats and interleave ++ * results into a separate output vector of floats, with each sum ++ * positioned before the corresponding difference. ++ * ++ * @param dst output vector ++ * constraints: 16-byte aligned ++ * @param src0 first input vector ++ * constraints: 32-byte aligned ++ * @param src1 second input vector ++ * constraints: 32-byte aligned ++ * @param len number of elements in the input ++ * constraints: multiple of 8 ++ */ ++ void (*butterflies_float_interleave)(float *dst, const float *src0, ++ const float *src1, int len); ++ + /* (I)DCT */ + void (*fdct)(DCTELEM *block/* align 16*/); + void (*fdct248)(DCTELEM *block/* align 16*/); +@@ -472,8 +496,8 @@ + * with the zigzag/alternate scan
+ * an example to avoid confusion: + * - (->decode coeffs -> zigzag reorder -> dequant -> reference idct ->...) +- * - (x -> referece dct -> reference idct -> x) +- * - (x -> referece dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x) ++ * - (x -> reference dct -> reference idct -> x) ++ * - (x -> reference dct -> simple_mmx_perm = idct_permutation -> simple_idct_mmx -> x) + * - (->decode coeffs -> zigzag reorder -> simple_mmx_perm -> dequant -> simple_idct_mmx ->...) + */ + uint8_t idct_permutation[64]; +@@ -490,8 +514,10 @@ + #define BASIS_SHIFT 16 + #define RECON_SHIFT 6 + +- void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w); ++ void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int h, int sides); + #define EDGE_WIDTH 16 ++#define EDGE_TOP 1 ++#define EDGE_BOTTOM 2 + + void (*prefetch)(void *mem, int stride, int h); + +@@ -503,29 +529,6 @@ + unsigned int filter_shift, int32_t mask, int blocksize, + int32_t *sample_buffer); + +- /* vc1 functions */ +- void (*vc1_inv_trans_8x8)(DCTELEM *b); +- void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); +- void (*vc1_v_overlap)(uint8_t* src, int stride); +- void (*vc1_h_overlap)(uint8_t* src, int stride); +- void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq); +- void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq); +- void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq); +- void (*vc1_h_loop_filter8)(uint8_t *src, int stride, int pq); +- void (*vc1_v_loop_filter16)(uint8_t *src, int stride, int pq); +- void (*vc1_h_loop_filter16)(uint8_t *src, int stride, int pq); +- /* put 8x8 block with bicubic interpolation and quarterpel precision +- * last argument is actually round value instead of height +- */ +- op_pixels_func put_vc1_mspel_pixels_tab[16]; +- op_pixels_func avg_vc1_mspel_pixels_tab[16]; +- + /* intrax8 functions */ + void (*x8_spatial_compensation[12])(uint8_t *src , uint8_t *dst, int linesize); + void (*x8_setup_spatial_compensation)(uint8_t *src, uint8_t *dst, int linesize, +@@ -545,19 +548,37 @@ + */ + int32_t (*scalarproduct_and_madd_int16)(int16_t *v1/*align 16*/, const int16_t *v2, const int16_t *v3, int len, int mul); + +- /* rv30 functions */ +- qpel_mc_func put_rv30_tpel_pixels_tab[4][16]; +- qpel_mc_func avg_rv30_tpel_pixels_tab[4][16]; +- +- /* rv40 functions */ +- qpel_mc_func put_rv40_qpel_pixels_tab[4][16]; +- qpel_mc_func avg_rv40_qpel_pixels_tab[4][16]; +- h264_chroma_mc_func put_rv40_chroma_pixels_tab[3]; +- h264_chroma_mc_func avg_rv40_chroma_pixels_tab[3]; ++ /** ++ * Apply symmetric window in 16-bit fixed-point. ++ * @param output destination array ++ * constraints: 16-byte aligned ++ * @param input source array ++ * constraints: 16-byte aligned ++ * @param window window array ++ * constraints: 16-byte aligned, at least len/2 elements ++ * @param len full window length ++ * constraints: multiple of ? greater than zero ++ */ ++ void (*apply_window_int16)(int16_t *output, const int16_t *input, ++ const int16_t *window, unsigned int len); ++ ++ /** ++ * Clip each element in an array of int32_t to a given minimum and maximum value. ++ * @param dst destination array ++ * constraints: 16-byte aligned ++ * @param src source array ++ * constraints: 16-byte aligned ++ * @param min minimum value ++ * constraints: must in the the range [-(1<<24), 1<<24] ++ * @param max maximum value ++ * constraints: must in the the range [-(1<<24), 1<<24] ++ * @param len number of elements in the array ++ * constraints: multiple of 32 greater than zero ++ */ ++ void (*vector_clip_int32)(int32_t *dst, const int32_t *src, int32_t min, ++ int32_t max, unsigned int len); + +- /* bink functions */ + op_fill_func fill_block_tab[2]; +- void (*scale_block)(const uint8_t src[64]/*align 8*/, uint8_t *dst/*align 8*/, int linesize); + } DSPContext; + + void dsputil_static_init(void); +@@ -574,6 +595,7 @@ + void ff_set_cmp(DSPContext* c, me_cmp_func *cmp, int type); + + #define BYTE_VEC32(c) ((c)*0x01010101UL) ++#define BYTE_VEC64(c) ((c)*0x0001000100010001UL) + + static inline uint32_t rnd_avg32(uint32_t a, uint32_t b) + { +@@ -585,6 +607,16 @@ + return (a & b) + (((a ^ b) & ~BYTE_VEC32(0x01)) >> 1); + } + ++static inline uint64_t rnd_avg64(uint64_t a, uint64_t b) ++{ ++ return (a | b) - (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); ++} ++ ++static inline uint64_t no_rnd_avg64(uint64_t a, uint64_t b) ++{ ++ return (a & b) + (((a ^ b) & ~BYTE_VEC64(0x01)) >> 1); ++} ++ + static inline int get_penalty_factor(int lambda, int lambda2, int type){ + switch(type&0xFF){ + default: +@@ -609,13 +641,6 @@ + } + } + +-/** +- * Empty mmx state. +- * this must be called between any dsp function and float/double code. +- * for example sin(); dsp->idct_put(); emms_c(); cos() +- */ +-#define emms_c() +- + void dsputil_init_alpha(DSPContext* c, AVCodecContext *avctx); + void dsputil_init_arm(DSPContext* c, AVCodecContext *avctx); + void dsputil_init_bfin(DSPContext* c, AVCodecContext *avctx); +@@ -627,25 +652,13 @@ + void dsputil_init_vis(DSPContext* c, AVCodecContext *avctx); + + void ff_dsputil_init_dwt(DSPContext *c); +-void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx); +-void ff_rv40dsp_init(DSPContext* c, AVCodecContext *avctx); +-void ff_vc1dsp_init(DSPContext* c, AVCodecContext *avctx); + void ff_intrax8dsp_init(DSPContext* c, AVCodecContext *avctx); + void ff_mlp_init(DSPContext* c, AVCodecContext *avctx); + void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx); + +-#if HAVE_MMX + +-#undef emms_c ++#if ARCH_ARM + +-static inline void emms(void) +-{ +- __asm__ volatile ("emms;":::"memory"); +-} +- +-#define emms_c() emms() +- +-#elif ARCH_ARM + + #if HAVE_NEON + # define STRIDE_ALIGN 16 +@@ -685,11 +698,6 @@ + # define LOCAL_ALIGNED_16(t, v, ...) LOCAL_ALIGNED(16, t, v, __VA_ARGS__) + #endif + +-/* PSNR */ +-void get_psnr(uint8_t *orig_image[3], uint8_t *coded_image[3], +- int orig_linesize[3], int coded_linesize, +- AVCodecContext *avctx); +- + #define WRAPPER8_16(name8, name16)\ + static int name16(void /*MpegEncContext*/ *s, uint8_t *dst, uint8_t *src, int stride, int h){\ + return name8(s, dst , src , stride, h)\ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dsputil_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dsputil_template.c 2012-05-14 14:08:53.653326276 +0200 +@@ -0,0 +1,1280 @@ ++/* ++ * DSP utils ++ * Copyright (c) 2000, 2001 Fabrice Bellard ++ * Copyright (c) 2002-2004 Michael Niedermayer ++ * ++ * gmc & q-pel & 32/64 bit based MC by Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * DSP utils ++ */ ++ ++#include "bit_depth_template.c" ++ ++static inline void FUNC(copy_block2)(uint8_t *dst, const uint8_t *src, int dstStride, int srcStride, int h) ++{ ++ int i; ++ for(i=0; i 8 ++ int j; ++ for (j = 0; j < w; j++) { ++ ptr[j-w] = ptr[0]; ++ ptr[j+width] = ptr[width-1]; ++ } ++#else ++ memset(ptr - w, ptr[0], w); ++ memset(ptr + width, ptr[width-1], w); ++#endif ++ ptr += wrap; ++ } ++ ++ /* top and bottom + corners */ ++ buf -= w; ++ last_line = buf + (height - 1) * wrap; ++ if (sides & EDGE_TOP) ++ for(i = 0; i < h; i++) ++ memcpy(buf - (i + 1) * wrap, buf, (width + w + w) * sizeof(pixel)); // top ++ if (sides & EDGE_BOTTOM) ++ for (i = 0; i < h; i++) ++ memcpy(last_line + (i + 1) * wrap, last_line, (width + w + w) * sizeof(pixel)); // bottom ++} ++ ++/** ++ * Copy a rectangular area of samples to a temporary buffer and replicate the border samples. ++ * @param buf destination buffer ++ * @param src source buffer ++ * @param linesize number of bytes between 2 vertically adjacent samples in both the source and destination buffers ++ * @param block_w width of block ++ * @param block_h height of block ++ * @param src_x x coordinate of the top left sample of the block in the source buffer ++ * @param src_y y coordinate of the top left sample of the block in the source buffer ++ * @param w width of the source buffer ++ * @param h height of the source buffer ++ */ ++void FUNC(ff_emulated_edge_mc)(uint8_t *buf, const uint8_t *src, int linesize, int block_w, int block_h, ++ int src_x, int src_y, int w, int h){ ++ int x, y; ++ int start_y, start_x, end_y, end_x; ++ ++ if(src_y>= h){ ++ src+= (h-1-src_y)*linesize; ++ src_y=h-1; ++ }else if(src_y<=-block_h){ ++ src+= (1-block_h-src_y)*linesize; ++ src_y=1-block_h; ++ } ++ if(src_x>= w){ ++ src+= (w-1-src_x)*sizeof(pixel); ++ src_x=w-1; ++ }else if(src_x<=-block_w){ ++ src+= (1-block_w-src_x)*sizeof(pixel); ++ src_x=1-block_w; ++ } ++ ++ start_y= FFMAX(0, -src_y); ++ start_x= FFMAX(0, -src_x); ++ end_y= FFMIN(block_h, h-src_y); ++ end_x= FFMIN(block_w, w-src_x); ++ assert(start_y < end_y && block_h); ++ assert(start_x < end_x && block_w); ++ ++ w = end_x - start_x; ++ src += start_y*linesize + start_x*sizeof(pixel); ++ buf += start_x*sizeof(pixel); ++ ++ //top ++ for(y=0; y 8 ++DCTELEM_FUNCS(dctcoef, _32) ++#endif ++ ++#define PIXOP2(OPNAME, OP) \ ++static void FUNCC(OPNAME ## _pixels2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ ++ int i;\ ++ for(i=0; i>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ l1= (c&0x03030303UL)\ ++ + (d&0x03030303UL);\ ++ h1= ((c&0xFCFCFCFCUL)>>2)\ ++ + ((d&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ a= AV_RN32(&src1[i*src_stride1+4]);\ ++ b= AV_RN32(&src2[i*src_stride2+4]);\ ++ c= AV_RN32(&src3[i*src_stride3+4]);\ ++ d= AV_RN32(&src4[i*src_stride4+4]);\ ++ l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x02020202UL;\ ++ h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ l1= (c&0x03030303UL)\ ++ + (d&0x03030303UL);\ ++ h1= ((c&0xFCFCFCFCUL)>>2)\ ++ + ((d&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ }\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels4_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ ++ FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels4_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ ++ FUNC(OPNAME ## _pixels4_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels2_x2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ ++ FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+sizeof(pixel), line_size, line_size, line_size, h);\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels2_y2)(uint8_t *block, const uint8_t *pixels, int line_size, int h){\ ++ FUNC(OPNAME ## _pixels2_l2)(block, pixels, pixels+line_size, line_size, line_size, line_size, h);\ ++}\ ++\ ++static inline void FUNC(OPNAME ## _no_rnd_pixels8_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ ++ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ ++ /* FIXME HIGH BIT DEPTH*/\ ++ int i;\ ++ for(i=0; i>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ l1= (c&0x03030303UL)\ ++ + (d&0x03030303UL);\ ++ h1= ((c&0xFCFCFCFCUL)>>2)\ ++ + ((d&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)&dst[i*dst_stride]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ a= AV_RN32(&src1[i*src_stride1+4]);\ ++ b= AV_RN32(&src2[i*src_stride2+4]);\ ++ c= AV_RN32(&src3[i*src_stride3+4]);\ ++ d= AV_RN32(&src4[i*src_stride4+4]);\ ++ l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x01010101UL;\ ++ h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ l1= (c&0x03030303UL)\ ++ + (d&0x03030303UL);\ ++ h1= ((c&0xFCFCFCFCUL)>>2)\ ++ + ((d&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)&dst[i*dst_stride+4]), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ }\ ++}\ ++static inline void FUNC(OPNAME ## _pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ ++ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ ++ FUNC(OPNAME ## _pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ ++ FUNC(OPNAME ## _pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ ++}\ ++static inline void FUNC(OPNAME ## _no_rnd_pixels16_l4)(uint8_t *dst, const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, const uint8_t *src4,\ ++ int dst_stride, int src_stride1, int src_stride2,int src_stride3,int src_stride4, int h){\ ++ FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst , src1 , src2 , src3 , src4 , dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ ++ FUNC(OPNAME ## _no_rnd_pixels8_l4)(dst+8*sizeof(pixel), src1+8*sizeof(pixel), src2+8*sizeof(pixel), src3+8*sizeof(pixel), src4+8*sizeof(pixel), dst_stride, src_stride1, src_stride2, src_stride3, src_stride4, h);\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels2_xy2)(uint8_t *p_block, const uint8_t *p_pixels, int line_size, int h)\ ++{\ ++ int i, a0, b0, a1, b1;\ ++ pixel *block = (pixel*)p_block;\ ++ const pixel *pixels = (const pixel*)p_pixels;\ ++ line_size >>= sizeof(pixel)-1;\ ++ a0= pixels[0];\ ++ b0= pixels[1] + 2;\ ++ a0 += b0;\ ++ b0 += pixels[2];\ ++\ ++ pixels+=line_size;\ ++ for(i=0; i>2; /* FIXME non put */\ ++ block[1]= (b1+b0)>>2;\ ++\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++\ ++ a0= pixels[0];\ ++ b0= pixels[1] + 2;\ ++ a0 += b0;\ ++ b0 += pixels[2];\ ++\ ++ block[0]= (a1+a0)>>2;\ ++ block[1]= (b1+b0)>>2;\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ }\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels4_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ ++{\ ++ /* FIXME HIGH BIT DEPTH */\ ++ int i;\ ++ const uint32_t a= AV_RN32(pixels );\ ++ const uint32_t b= AV_RN32(pixels+1);\ ++ uint32_t l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x02020202UL;\ ++ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ uint32_t l1,h1;\ ++\ ++ pixels+=line_size;\ ++ for(i=0; i>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ a= AV_RN32(pixels );\ ++ b= AV_RN32(pixels+1);\ ++ l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x02020202UL;\ ++ h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ }\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ ++{\ ++ /* FIXME HIGH BIT DEPTH */\ ++ int j;\ ++ for(j=0; j<2; j++){\ ++ int i;\ ++ const uint32_t a= AV_RN32(pixels );\ ++ const uint32_t b= AV_RN32(pixels+1);\ ++ uint32_t l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x02020202UL;\ ++ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ uint32_t l1,h1;\ ++\ ++ pixels+=line_size;\ ++ for(i=0; i>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ a= AV_RN32(pixels );\ ++ b= AV_RN32(pixels+1);\ ++ l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x02020202UL;\ ++ h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ }\ ++ pixels+=4-line_size*(h+1);\ ++ block +=4-line_size*h;\ ++ }\ ++}\ ++\ ++static inline void FUNCC(OPNAME ## _no_rnd_pixels8_xy2)(uint8_t *block, const uint8_t *pixels, int line_size, int h)\ ++{\ ++ /* FIXME HIGH BIT DEPTH */\ ++ int j;\ ++ for(j=0; j<2; j++){\ ++ int i;\ ++ const uint32_t a= AV_RN32(pixels );\ ++ const uint32_t b= AV_RN32(pixels+1);\ ++ uint32_t l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x01010101UL;\ ++ uint32_t h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ uint32_t l1,h1;\ ++\ ++ pixels+=line_size;\ ++ for(i=0; i>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ a= AV_RN32(pixels );\ ++ b= AV_RN32(pixels+1);\ ++ l0= (a&0x03030303UL)\ ++ + (b&0x03030303UL)\ ++ + 0x01010101UL;\ ++ h0= ((a&0xFCFCFCFCUL)>>2)\ ++ + ((b&0xFCFCFCFCUL)>>2);\ ++ OP(*((uint32_t*)block), h0+h1+(((l0+l1)>>2)&0x0F0F0F0FUL));\ ++ pixels+=line_size;\ ++ block +=line_size;\ ++ }\ ++ pixels+=4-line_size*(h+1);\ ++ block +=4-line_size*h;\ ++ }\ ++}\ ++\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_x2) , FUNCC(OPNAME ## _pixels8_x2) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_y2) , FUNCC(OPNAME ## _pixels8_y2) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _pixels16_xy2), FUNCC(OPNAME ## _pixels8_xy2), 8*sizeof(pixel))\ ++av_unused CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16) , FUNCC(OPNAME ## _pixels8) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_x2) , FUNCC(OPNAME ## _no_rnd_pixels8_x2) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_y2) , FUNCC(OPNAME ## _no_rnd_pixels8_y2) , 8*sizeof(pixel))\ ++CALL_2X_PIXELS(FUNCC(OPNAME ## _no_rnd_pixels16_xy2), FUNCC(OPNAME ## _no_rnd_pixels8_xy2), 8*sizeof(pixel))\ ++ ++#define op_avg(a, b) a = rnd_avg_pixel4(a, b) ++#define op_put(a, b) a = b ++ ++PIXOP2(avg, op_avg) ++PIXOP2(put, op_put) ++#undef op_avg ++#undef op_put ++ ++#define put_no_rnd_pixels8_c put_pixels8_c ++#define put_no_rnd_pixels16_c put_pixels16_c ++ ++static void FUNCC(put_no_rnd_pixels16_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ ++ FUNC(put_no_rnd_pixels16_l2)(dst, a, b, stride, stride, stride, h); ++} ++ ++static void FUNCC(put_no_rnd_pixels8_l2)(uint8_t *dst, const uint8_t *a, const uint8_t *b, int stride, int h){ ++ FUNC(put_no_rnd_pixels8_l2)(dst, a, b, stride, stride, stride, h); ++} ++ ++#define H264_CHROMA_MC(OPNAME, OP)\ ++static void FUNCC(OPNAME ## h264_chroma_mc2)(uint8_t *p_dst/*align 8*/, uint8_t *p_src/*align 1*/, int stride, int h, int x, int y){\ ++ pixel *dst = (pixel*)p_dst;\ ++ pixel *src = (pixel*)p_src;\ ++ const int A=(8-x)*(8-y);\ ++ const int B=( x)*(8-y);\ ++ const int C=(8-x)*( y);\ ++ const int D=( x)*( y);\ ++ int i;\ ++ stride >>= sizeof(pixel)-1;\ ++ \ ++ assert(x<8 && y<8 && x>=0 && y>=0);\ ++\ ++ if(D){\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ \ ++ assert(x<8 && y<8 && x>=0 && y>=0);\ ++\ ++ if(D){\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ \ ++ assert(x<8 && y<8 && x>=0 && y>=0);\ ++\ ++ if(D){\ ++ for(i=0; i>6)+1)>>1) ++#define op_put(a, b) a = (((b) + 32)>>6) ++ ++H264_CHROMA_MC(put_ , op_put) ++H264_CHROMA_MC(avg_ , op_avg) ++#undef op_avg ++#undef op_put ++ ++#define H264_LOWPASS(OPNAME, OP, OP2) \ ++static av_unused void FUNC(OPNAME ## h264_qpel2_h_lowpass)(uint8_t *p_dst, uint8_t *p_src, int dstStride, int srcStride){\ ++ const int h=2;\ ++ INIT_CLIP\ ++ int i;\ ++ pixel *dst = (pixel*)p_dst;\ ++ pixel *src = (pixel*)p_src;\ ++ dstStride >>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i 9) ? (-10 * ((1<>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ src -= 2*srcStride;\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i 9) ? (-10 * ((1<>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ src -= 2*srcStride;\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ for(i=0; i 9) ? (-10 * ((1<>= sizeof(pixel)-1;\ ++ srcStride >>= sizeof(pixel)-1;\ ++ src -= 2*srcStride;\ ++ for(i=0; i>5)+1)>>1) ++//#define op_avg2(a, b) a = (((a)*w1+cm[((b) + 16)>>5]*w2 + o + 64)>>7) ++#define op_put(a, b) a = CLIP(((b) + 16)>>5) ++#define op2_avg(a, b) a = (((a)+CLIP(((b) + 512)>>10)+1)>>1) ++#define op2_put(a, b) a = CLIP(((b) + 512)>>10) ++ ++H264_LOWPASS(put_ , op_put, op2_put) ++H264_LOWPASS(avg_ , op_avg, op2_avg) ++H264_MC(put_, 2) ++H264_MC(put_, 4) ++H264_MC(put_, 8) ++H264_MC(put_, 16) ++H264_MC(avg_, 4) ++H264_MC(avg_, 8) ++H264_MC(avg_, 16) ++ ++#undef op_avg ++#undef op_put ++#undef op2_avg ++#undef op2_put ++ ++#if BIT_DEPTH == 8 ++# define put_h264_qpel8_mc00_8_c ff_put_pixels8x8_8_c ++# define avg_h264_qpel8_mc00_8_c ff_avg_pixels8x8_8_c ++# define put_h264_qpel16_mc00_8_c ff_put_pixels16x16_8_c ++# define avg_h264_qpel16_mc00_8_c ff_avg_pixels16x16_8_c ++#elif BIT_DEPTH == 9 ++# define put_h264_qpel8_mc00_9_c ff_put_pixels8x8_9_c ++# define avg_h264_qpel8_mc00_9_c ff_avg_pixels8x8_9_c ++# define put_h264_qpel16_mc00_9_c ff_put_pixels16x16_9_c ++# define avg_h264_qpel16_mc00_9_c ff_avg_pixels16x16_9_c ++#elif BIT_DEPTH == 10 ++# define put_h264_qpel8_mc00_10_c ff_put_pixels8x8_10_c ++# define avg_h264_qpel8_mc00_10_c ff_avg_pixels8x8_10_c ++# define put_h264_qpel16_mc00_10_c ff_put_pixels16x16_10_c ++# define avg_h264_qpel16_mc00_10_c ff_avg_pixels16x16_10_c ++#endif ++ ++void FUNCC(ff_put_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) { ++ FUNCC(put_pixels8)(dst, src, stride, 8); ++} ++void FUNCC(ff_avg_pixels8x8)(uint8_t *dst, uint8_t *src, int stride) { ++ FUNCC(avg_pixels8)(dst, src, stride, 8); ++} ++void FUNCC(ff_put_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) { ++ FUNCC(put_pixels16)(dst, src, stride, 16); ++} ++void FUNCC(ff_avg_pixels16x16)(uint8_t *dst, uint8_t *src, int stride) { ++ FUNCC(avg_pixels16)(dst, src, stride, 16); ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsub.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsub.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsub.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsub.c 2012-05-14 14:08:53.658326376 +0200 +@@ -1,5 +1,5 @@ + /* +- * DVB subtitle encoding for ffmpeg ++ * DVB subtitle encoding + * Copyright (c) 2005 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -194,6 +194,61 @@ + *pq = q; + } + ++static void dvb_encode_rle8(uint8_t **pq, ++ const uint8_t *bitmap, int linesize, ++ int w, int h) ++{ ++ uint8_t *q; ++ int x, y, len, x1, f, color; ++ ++ q = *pq; ++ ++ for (y = 0; y < h; y++) { ++ *q++ = 0x12; ++ ++ x = 0; ++ f = 0; ++ while (x < w) { ++ x1 = x; ++ color = bitmap[x1++]; ++ while (x1 < w && bitmap[x1] == color) ++ x1++; ++ len = x1 - x; ++ if (len == 1 && color) { ++ // 00000001 to 11111111 1 pixel in colour x ++ *q++ = color; ++ } else { ++ if (color == 0x00) { ++ // 00000000 0LLLLLLL L pixels (1-127) in colour 0 (L > 0) ++ len = FFMIN(len, 127); ++ *q++ = 0x00; ++ *q++ = len; ++ } else if (len > 2) { ++ // 00000000 1LLLLLLL CCCCCCCC L pixels (3-127) in colour C (L > 2) ++ len = FFMIN(len, 127); ++ *q++ = 0x00; ++ *q++ = 0x80+len; ++ *q++ = color; ++ } ++ else if (len == 2) { ++ *q++ = color; ++ *q++ = color; ++ } else { ++ *q++ = color; ++ len = 1; ++ } ++ } ++ x += len; ++ } ++ /* end of line */ ++ // 00000000 00000000 end of 8-bit/pixel_code_string ++ *q++ = 0x00; ++ *q++ = 0x00; ++ bitmap += linesize; ++ } ++ *pq = q; ++} ++ + static int encode_dvb_subtitles(DVBSubtitleContext *s, + uint8_t *outbuf, AVSubtitle *h) + { +@@ -223,7 +278,7 @@ + else + page_state = 2; /* mode change */ + /* page_version = 0 + page_state */ +- *q++ = s->object_version | (page_state << 2) | 3; ++ *q++ = (s->object_version << 4) | (page_state << 2) | 3; + + for (region_id = 0; region_id < h->num_rects; region_id++) { + *q++ = region_id; +@@ -245,10 +300,15 @@ + } else if (h->rects[clut_id]->nb_colors <= 16) { + /* 4 bpp, standard encoding */ + bpp_index = 1; ++ } else if (h->rects[clut_id]->nb_colors <= 256) { ++ /* 8 bpp, standard encoding */ ++ bpp_index = 2; + } else { + return -1; + } + ++ ++ /* CLUT segment */ + *q++ = 0x0f; /* sync byte */ + *q++ = 0x12; /* CLUT definition segment */ + bytestream_put_be16(&q, page_id); +@@ -321,18 +381,25 @@ + if (!s->hide_state) { + + for (object_id = 0; object_id < h->num_rects; object_id++) { +- /* Object Data segment */ ++ void (*dvb_encode_rle)(uint8_t **pq, ++ const uint8_t *bitmap, int linesize, ++ int w, int h); + ++ /* bpp_index maths */ + if (h->rects[object_id]->nb_colors <= 4) { + /* 2 bpp, some decoders do not support it correctly */ +- bpp_index = 0; ++ dvb_encode_rle = dvb_encode_rle2; + } else if (h->rects[object_id]->nb_colors <= 16) { + /* 4 bpp, standard encoding */ +- bpp_index = 1; ++ dvb_encode_rle = dvb_encode_rle4; ++ } else if (h->rects[object_id]->nb_colors <= 256) { ++ /* 8 bpp, standard encoding */ ++ dvb_encode_rle = dvb_encode_rle8; + } else { + return -1; + } + ++ /* Object Data segment */ + *q++ = 0x0f; /* sync byte */ + *q++ = 0x13; + bytestream_put_be16(&q, page_id); +@@ -345,19 +412,12 @@ + non_modifying_color_flag */ + { + uint8_t *ptop_field_len, *pbottom_field_len, *top_ptr, *bottom_ptr; +- void (*dvb_encode_rle)(uint8_t **pq, +- const uint8_t *bitmap, int linesize, +- int w, int h); ++ + ptop_field_len = q; + q += 2; + pbottom_field_len = q; + q += 2; + +- if (bpp_index == 0) +- dvb_encode_rle = dvb_encode_rle2; +- else +- dvb_encode_rle = dvb_encode_rle4; +- + top_ptr = q; + dvb_encode_rle(&q, h->rects[object_id]->pict.data[0], h->rects[object_id]->w * 2, + h->rects[object_id]->w, h->rects[object_id]->h >> 1); +@@ -403,11 +463,10 @@ + } + + AVCodec ff_dvbsub_encoder = { +- "dvbsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_DVB_SUBTITLE, +- sizeof(DVBSubtitleContext), +- NULL, +- dvbsub_encode, ++ .name = "dvbsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_DVB_SUBTITLE, ++ .priv_data_size = sizeof(DVBSubtitleContext), ++ .encode = dvbsub_encode, + .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsubdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsubdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsubdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsubdec.c 2012-05-14 14:08:53.661326437 +0200 +@@ -1,5 +1,5 @@ + /* +- * DVB subtitle decoding for ffmpeg ++ * DVB subtitle decoding + * Copyright (c) 2005 Ian Caulfield + * + * This file is part of FFmpeg. +@@ -24,10 +24,6 @@ + #include "bytestream.h" + #include "libavutil/colorspace.h" + +-//#define DEBUG +-//#define DEBUG_PACKET_CONTENTS +-//#define DEBUG_SAVE_IMAGES +- + #define DVBSUB_PAGE_SEGMENT 0x10 + #define DVBSUB_REGION_SEGMENT 0x11 + #define DVBSUB_CLUT_SEGMENT 0x12 +@@ -37,8 +33,9 @@ + + #define cm (ff_cropTbl + MAX_NEG_CROP) + +-#ifdef DEBUG_SAVE_IMAGES ++#ifdef DEBUG + #undef fprintf ++#undef perror + #if 0 + static void png_save(const char *filename, uint8_t *bitmap, int w, int h, + uint32_t *rgba_palette) +@@ -53,7 +50,7 @@ + f = fopen(fname, "w"); + if (!f) { + perror(fname); +- exit(1); ++ return; + } + fprintf(f, "P6\n" + "%d %d\n" +@@ -75,7 +72,7 @@ + f = fopen(fname2, "w"); + if (!f) { + perror(fname2); +- exit(1); ++ return; + } + fprintf(f, "P5\n" + "%d %d\n" +@@ -109,7 +106,7 @@ + f = fopen(fname, "w"); + if (!f) { + perror(fname); +- exit(1); ++ return; + } + fprintf(f, "P6\n" + "%d %d\n" +@@ -131,7 +128,7 @@ + f = fopen(fname2, "w"); + if (!f) { + perror(fname2); +- exit(1); ++ return; + } + fprintf(f, "P5\n" + "%d %d\n" +@@ -157,6 +154,7 @@ + + typedef struct DVBSubCLUT { + int id; ++ int version; + + uint32_t clut4[4]; + uint32_t clut16[16]; +@@ -183,6 +181,7 @@ + + typedef struct DVBSubObject { + int id; ++ int version; + + int type; + +@@ -202,6 +201,7 @@ + + typedef struct DVBSubRegion { + int id; ++ int version; + + int width; + int height; +@@ -212,6 +212,7 @@ + + uint8_t *pbuf; + int buf_size; ++ int dirty; + + DVBSubObjectDisplay *display_list; + +@@ -231,6 +232,7 @@ + int composition_id; + int ancillary_id; + ++ int version; + int time_out; + DVBSubRegion *region_list; + DVBSubCLUT *clut_list; +@@ -321,23 +323,10 @@ + + } + +-static void delete_state(DVBSubContext *ctx) ++static void delete_cluts(DVBSubContext *ctx) + { +- DVBSubRegion *region; + DVBSubCLUT *clut; + +- while (ctx->region_list) { +- region = ctx->region_list; +- +- ctx->region_list = region->next; +- +- delete_region_display_list(ctx, region); +- if (region->pbuf) +- av_free(region->pbuf); +- +- av_free(region); +- } +- + while (ctx->clut_list) { + clut = ctx->clut_list; + +@@ -345,12 +334,35 @@ + + av_free(clut); + } ++} + +- av_freep(&ctx->display_definition); ++static void delete_objects(DVBSubContext *ctx) ++{ ++ DVBSubObject *object; ++ ++ while (ctx->object_list) { ++ object = ctx->object_list; ++ ++ ctx->object_list = object->next; ++ ++ av_free(object); ++ } ++} ++ ++static void delete_regions(DVBSubContext *ctx) ++{ ++ DVBSubRegion *region; ++ ++ while (ctx->region_list) { ++ region = ctx->region_list; ++ ++ ctx->region_list = region->next; + +- /* Should already be null */ +- if (ctx->object_list) +- av_log(0, AV_LOG_ERROR, "Memory deallocation error!\n"); ++ delete_region_display_list(ctx, region); ++ ++ av_free(region->pbuf); ++ av_free(region); ++ } + } + + static av_cold int dvbsub_init_decoder(AVCodecContext *avctx) +@@ -367,6 +379,8 @@ + ctx->ancillary_id = AV_RB16(avctx->extradata + 2); + } + ++ ctx->version = -1; ++ + default_clut.id = -1; + default_clut.next = NULL; + +@@ -435,7 +449,13 @@ + DVBSubContext *ctx = avctx->priv_data; + DVBSubRegionDisplay *display; + +- delete_state(ctx); ++ delete_regions(ctx); ++ ++ delete_objects(ctx); ++ ++ delete_cluts(ctx); ++ ++ av_freep(&ctx->display_definition); + + while (ctx->display_list) { + display = ctx->display_list; +@@ -449,16 +469,18 @@ + + static int dvbsub_read_2bit_string(uint8_t *destbuf, int dbuf_len, + const uint8_t **srcbuf, int buf_size, +- int non_mod, uint8_t *map_table) ++ int non_mod, uint8_t *map_table, int x_pos) + { + GetBitContext gb; + + int bits; + int run_length; +- int pixels_read = 0; ++ int pixels_read = x_pos; + + init_get_bits(&gb, *srcbuf, buf_size << 3); + ++ destbuf += x_pos; ++ + while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) { + bits = get_bits(&gb, 2); + +@@ -519,14 +541,14 @@ + } + } + } else if (bits == 1) { +- pixels_read += 2; + if (map_table) + bits = map_table[0]; + else + bits = 0; +- if (pixels_read <= dbuf_len) { +- *destbuf++ = bits; ++ run_length = 2; ++ while (run_length-- > 0 && pixels_read < dbuf_len) { + *destbuf++ = bits; ++ pixels_read++; + } + } else { + (*srcbuf) += (get_bits_count(&gb) + 7) >> 3; +@@ -554,16 +576,18 @@ + + static int dvbsub_read_4bit_string(uint8_t *destbuf, int dbuf_len, + const uint8_t **srcbuf, int buf_size, +- int non_mod, uint8_t *map_table) ++ int non_mod, uint8_t *map_table, int x_pos) + { + GetBitContext gb; + + int bits; + int run_length; +- int pixels_read = 0; ++ int pixels_read = x_pos; + + init_get_bits(&gb, *srcbuf, buf_size << 3); + ++ destbuf += x_pos; ++ + while (get_bits_count(&gb) < buf_size << 3 && pixels_read < dbuf_len) { + bits = get_bits(&gb, 4); + +@@ -643,14 +667,14 @@ + } + } + } else if (bits == 1) { +- pixels_read += 2; + if (map_table) + bits = map_table[0]; + else + bits = 0; +- if (pixels_read <= dbuf_len) { +- *destbuf++ = bits; ++ run_length = 2; ++ while (run_length-- > 0 && pixels_read < dbuf_len) { + *destbuf++ = bits; ++ pixels_read++; + } + } else { + if (map_table) +@@ -675,12 +699,14 @@ + + static int dvbsub_read_8bit_string(uint8_t *destbuf, int dbuf_len, + const uint8_t **srcbuf, int buf_size, +- int non_mod, uint8_t *map_table) ++ int non_mod, uint8_t *map_table, int x_pos) + { + const uint8_t *sbuf_end = (*srcbuf) + buf_size; + int bits; + int run_length; +- int pixels_read = 0; ++ int pixels_read = x_pos; ++ ++ destbuf += x_pos; + + while (*srcbuf < sbuf_end && pixels_read < dbuf_len) { + bits = *(*srcbuf)++; +@@ -749,38 +775,37 @@ + 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff}; + uint8_t *map_table; + ++#if 0 + av_dlog(avctx, "DVB pixel block size %d, %s field:\n", buf_size, + top_bottom ? "bottom" : "top"); + +-#ifdef DEBUG_PACKET_CONTENTS + for (i = 0; i < buf_size; i++) { + if (i % 16 == 0) +- av_log(avctx, AV_LOG_INFO, "0x%08p: ", buf+i); ++ av_dlog(avctx, "0x%8p: ", buf+i); + +- av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); ++ av_dlog(avctx, "%02x ", buf[i]); + if (i % 16 == 15) +- av_log(avctx, AV_LOG_INFO, "\n"); ++ av_dlog(avctx, "\n"); + } + + if (i % 16) +- av_log(avctx, AV_LOG_INFO, "\n"); +- ++ av_dlog(avctx, "\n"); + #endif + + if (region == 0) + return; + + pbuf = region->pbuf; ++ region->dirty = 1; + + x_pos = display->x_pos; + y_pos = display->y_pos; + +- if ((y_pos & 1) != top_bottom) +- y_pos++; ++ y_pos += top_bottom; + + while (buf < buf_end) { +- if (x_pos > region->width || y_pos > region->height) { +- av_log(avctx, AV_LOG_ERROR, "Invalid object location!\n"); ++ if ((*buf!=0xf0 && x_pos >= region->width) || y_pos >= region->height) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid object location! %d-%d %d-%d %02x\n", x_pos, region->width, y_pos, region->height, *buf); + return; + } + +@@ -793,9 +818,9 @@ + else + map_table = NULL; + +- x_pos += dvbsub_read_2bit_string(pbuf + (y_pos * region->width) + x_pos, +- region->width - x_pos, &buf, buf_size, +- non_mod, map_table); ++ x_pos = dvbsub_read_2bit_string(pbuf + (y_pos * region->width), ++ region->width, &buf, buf_end - buf, ++ non_mod, map_table, x_pos); + break; + case 0x11: + if (region->depth < 4) { +@@ -808,9 +833,9 @@ + else + map_table = NULL; + +- x_pos += dvbsub_read_4bit_string(pbuf + (y_pos * region->width) + x_pos, +- region->width - x_pos, &buf, buf_size, +- non_mod, map_table); ++ x_pos = dvbsub_read_4bit_string(pbuf + (y_pos * region->width), ++ region->width, &buf, buf_end - buf, ++ non_mod, map_table, x_pos); + break; + case 0x12: + if (region->depth < 8) { +@@ -818,9 +843,9 @@ + return; + } + +- x_pos += dvbsub_read_8bit_string(pbuf + (y_pos * region->width) + x_pos, +- region->width - x_pos, &buf, buf_size, +- non_mod, NULL); ++ x_pos = dvbsub_read_8bit_string(pbuf + (y_pos * region->width), ++ region->width, &buf, buf_end - buf, ++ non_mod, NULL, x_pos); + break; + + case 0x20: +@@ -855,7 +880,6 @@ + DVBSubContext *ctx = avctx->priv_data; + + const uint8_t *buf_end = buf + buf_size; +- const uint8_t *block; + int object_id; + DVBSubObject *object; + DVBSubObjectDisplay *display; +@@ -886,7 +910,8 @@ + } + + for (display = object->display_list; display; display = display->object_list_next) { +- block = buf; ++ const uint8_t *block = buf; ++ int bfl = bottom_field_len; + + dvbsub_parse_pixel_data_block(avctx, display, block, top_field_len, 0, + non_modifying_color); +@@ -894,9 +919,9 @@ + if (bottom_field_len > 0) + block = buf + top_field_len; + else +- bottom_field_len = top_field_len; ++ bfl = top_field_len; + +- dvbsub_parse_pixel_data_block(avctx, display, block, bottom_field_len, 1, ++ dvbsub_parse_pixel_data_block(avctx, display, block, bfl, 1, + non_modifying_color); + } + +@@ -914,29 +939,26 @@ + DVBSubContext *ctx = avctx->priv_data; + + const uint8_t *buf_end = buf + buf_size; +- int clut_id; ++ int i, clut_id; ++ int version; + DVBSubCLUT *clut; + int entry_id, depth , full_range; + int y, cr, cb, alpha; + int r, g, b, r_add, g_add, b_add; + +-#ifdef DEBUG_PACKET_CONTENTS +- int i; +- +- av_log(avctx, AV_LOG_INFO, "DVB clut packet:\n"); ++ av_dlog(avctx, "DVB clut packet:\n"); + + for (i=0; i < buf_size; i++) { +- av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); ++ av_dlog(avctx, "%02x ", buf[i]); + if (i % 16 == 15) +- av_log(avctx, AV_LOG_INFO, "\n"); ++ av_dlog(avctx, "\n"); + } + + if (i % 16) +- av_log(avctx, AV_LOG_INFO, "\n"); +- +-#endif ++ av_dlog(avctx, "\n"); + + clut_id = *buf++; ++ version = ((*buf)>>4)&15; + buf += 1; + + clut = get_clut(ctx, clut_id); +@@ -947,11 +969,16 @@ + memcpy(clut, &default_clut, sizeof(DVBSubCLUT)); + + clut->id = clut_id; ++ clut->version = -1; + + clut->next = ctx->clut_list; + ctx->clut_list = clut; + } + ++ if (clut->version != version) { ++ ++ clut->version = version; ++ + while (buf + 4 < buf_end) { + entry_id = *buf++; + +@@ -993,6 +1020,7 @@ + if (depth & 0x20) + clut->clut256[entry_id] = RGBA(r,g,b,255 - alpha); + } ++ } + } + + +@@ -1003,6 +1031,7 @@ + + const uint8_t *buf_end = buf + buf_size; + int region_id, object_id; ++ int version; + DVBSubRegion *region; + DVBSubObject *object; + DVBSubObjectDisplay *display; +@@ -1019,11 +1048,13 @@ + region = av_mallocz(sizeof(DVBSubRegion)); + + region->id = region_id; ++ region->version = -1; + + region->next = ctx->region_list; + ctx->region_list = region; + } + ++ version = ((*buf)>>4) & 15; + fill = ((*buf++) >> 3) & 1; + + region->width = AV_RB16(buf); +@@ -1032,14 +1063,14 @@ + buf += 2; + + if (region->width * region->height != region->buf_size) { +- if (region->pbuf) +- av_free(region->pbuf); ++ av_free(region->pbuf); + + region->buf_size = region->width * region->height; + + region->pbuf = av_malloc(region->buf_size); + + fill = 1; ++ region->dirty = 0; + } + + region->depth = 1 << (((*buf++) >> 2) & 7); +@@ -1049,9 +1080,10 @@ + } + region->clut = *buf++; + +- if (region->depth == 8) ++ if (region->depth == 8) { + region->bgcolor = *buf++; +- else { ++ buf += 1; ++ } else { + buf += 1; + + if (region->depth == 4) +@@ -1118,17 +1150,27 @@ + const uint8_t *buf_end = buf + buf_size; + int region_id; + int page_state; ++ int timeout; ++ int version; + + if (buf_size < 1) + return; + +- ctx->time_out = *buf++; ++ timeout = *buf++; ++ version = ((*buf)>>4) & 15; + page_state = ((*buf++) >> 2) & 3; + ++ if (ctx->version != version) { ++ ++ ctx->time_out = timeout; ++ ctx->version = version; ++ + av_dlog(avctx, "Page time out %ds, state %d\n", ctx->time_out, page_state); + +- if (page_state == 2) { +- delete_state(ctx); ++ if (page_state == 1 || page_state == 2) { ++ delete_regions(ctx); ++ delete_objects(ctx); ++ delete_cluts(ctx); + } + + tmp_display_list = ctx->display_list; +@@ -1173,11 +1215,12 @@ + + av_free(display); + } ++ } + + } + + +-#ifdef DEBUG_SAVE_IMAGES ++#ifdef DEBUG + static void save_display_set(DVBSubContext *ctx) + { + DVBSubRegion *region; +@@ -1326,10 +1369,7 @@ + int i; + int offset_x=0, offset_y=0; + +- sub->rects = NULL; +- sub->start_display_time = 0; + sub->end_display_time = ctx->time_out * 1000; +- sub->format = 0; + + if (display_def) { + offset_x = display_def->x; +@@ -1342,17 +1382,19 @@ + sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects); + for(i=0; inum_rects; i++) + sub->rects[i] = av_mallocz(sizeof(*sub->rects[i])); +- } + + i = 0; + + for (display = ctx->display_list; display; display = display->next) { + region = get_region(ctx, display->region_id); +- rect = sub->rects[i]; + + if (!region) + continue; + ++ if (!region->dirty) ++ continue; ++ ++ rect = sub->rects[i]; + rect->x = display->x_pos + offset_x; + rect->y = display->y_pos + offset_y; + rect->w = region->width; +@@ -1389,8 +1431,8 @@ + } + + sub->num_rects = i; +- +-#ifdef DEBUG_SAVE_IMAGES ++ } ++#ifdef DEBUG + save_display_set(ctx); + #endif + +@@ -1410,30 +1452,28 @@ + int page_id; + int segment_length; + int got_segment = 0; +- +-#ifdef DEBUG_PACKET_CONTENTS + int i; + +- av_log(avctx, AV_LOG_INFO, "DVB sub packet:\n"); ++ av_dlog(avctx, "DVB sub packet:\n"); + + for (i=0; i < buf_size; i++) { +- av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); ++ av_dlog(avctx, "%02x ", buf[i]); + if (i % 16 == 15) +- av_log(avctx, AV_LOG_INFO, "\n"); ++ av_dlog(avctx, "\n"); + } + + if (i % 16) +- av_log(avctx, AV_LOG_INFO, "\n"); +- +-#endif ++ av_dlog(avctx, "\n"); + +- if (buf_size <= 2) ++ if (buf_size <= 6 || *buf != 0x0f) { ++ av_dlog(avctx, "incomplete or broken packet"); + return -1; ++ } + + p = buf; + p_end = buf + buf_size; + +- while (p < p_end && *p == 0x0f) { ++ while (p_end - p >= 6 && *p == 0x0f) { + p += 1; + segment_type = *p++; + page_id = AV_RB16(p); +@@ -1441,6 +1481,11 @@ + segment_length = AV_RB16(p); + p += 2; + ++ if (p_end - p < segment_length) { ++ av_dlog(avctx, "incomplete or broken packet"); ++ return -1; ++ } ++ + if (page_id == ctx->composition_id || page_id == ctx->ancillary_id || + ctx->composition_id == -1 || ctx->ancillary_id == -1) { + switch (segment_type) { +@@ -1476,28 +1521,23 @@ + + p += segment_length; + } ++ + // Some streams do not send a display segment but if we have all the other + // segments then we need no further data. + if (got_segment == 15 && sub) + *data_size = dvbsub_display_end_segment(avctx, p, 0, sub); + +- if (p != p_end) { +- av_dlog(avctx, "Junk at end of packet\n"); +- return -1; +- } +- +- return buf_size; ++ return p - buf; + } + + + AVCodec ff_dvbsub_decoder = { +- "dvbsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_DVB_SUBTITLE, +- sizeof(DVBSubContext), +- dvbsub_init_decoder, +- NULL, +- dvbsub_close_decoder, +- dvbsub_decode, ++ .name = "dvbsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_DVB_SUBTITLE, ++ .priv_data_size = sizeof(DVBSubContext), ++ .init = dvbsub_init_decoder, ++ .close = dvbsub_close_decoder, ++ .decode = dvbsub_decode, + .long_name = NULL_IF_CONFIG_SMALL("DVB subtitles"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsub_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsub_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvbsub_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvbsub_parser.c 2012-05-14 14:08:53.658326376 +0200 +@@ -22,9 +22,6 @@ + #include "dsputil.h" + #include "get_bits.h" + +-//#define DEBUG +-//#define DEBUG_PACKET_CONTENTS +- + /* Parser (mostly) copied from dvdsub.c */ + + #define PARSE_BUF_SIZE (65536) +@@ -53,25 +50,20 @@ + { + DVBSubParseContext *pc = s->priv_data; + uint8_t *p, *p_end; +- int len, buf_pos = 0; ++ int i, len, buf_pos = 0; + + av_dlog(avctx, "DVB parse packet pts=%"PRIx64", lpts=%"PRIx64", cpts=%"PRIx64":\n", + s->pts, s->last_pts, s->cur_frame_pts[s->cur_frame_start_index]); + +-#ifdef DEBUG_PACKET_CONTENTS +- int i; +- + for (i=0; i < buf_size; i++) + { +- av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); ++ av_dlog(avctx, "%02x ", buf[i]); + if (i % 16 == 15) +- av_log(avctx, AV_LOG_INFO, "\n"); ++ av_dlog(avctx, "\n"); + } + + if (i % 16 != 0) +- av_log(avctx, AV_LOG_INFO, "\n"); +- +-#endif ++ av_dlog(avctx, "\n"); + + *poutbuf = NULL; + *poutbuf_size = 0; +@@ -180,9 +172,9 @@ + } + + AVCodecParser ff_dvbsub_parser = { +- { CODEC_ID_DVB_SUBTITLE }, +- sizeof(DVBSubParseContext), +- dvbsub_parse_init, +- dvbsub_parse, +- dvbsub_parse_close, ++ .codec_ids = { CODEC_ID_DVB_SUBTITLE }, ++ .priv_data_size = sizeof(DVBSubParseContext), ++ .parser_init = dvbsub_parse_init, ++ .parser_parse = dvbsub_parse, ++ .parser_close = dvbsub_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dv.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dv.c 2012-05-14 14:08:53.656326336 +0200 +@@ -37,7 +37,8 @@ + * @file + * DV codec. + */ +-#define ALT_BITSTREAM_READER ++ ++#include "libavutil/pixdesc.h" + #include "avcodec.h" + #include "dsputil.h" + #include "get_bits.h" +@@ -348,31 +349,27 @@ + + static av_cold int dvvideo_init_encoder(AVCodecContext *avctx) + { +- if (!ff_dv_codec_profile(avctx)) { ++ if (!avpriv_dv_codec_profile(avctx)) { + av_log(avctx, AV_LOG_ERROR, "Found no DV profile for %ix%i %s video\n", +- avctx->width, avctx->height, avcodec_get_pix_fmt_name(avctx->pix_fmt)); ++ avctx->width, avctx->height, av_get_pix_fmt_name(avctx->pix_fmt)); + return -1; + } + + return dvvideo_init(avctx); + } + +-// #define VLC_DEBUG +-// #define printf(...) av_log(NULL, AV_LOG_ERROR, __VA_ARGS__) +- + typedef struct BlockInfo { + const uint32_t *factor_table; + const uint8_t *scan_table; + uint8_t pos; /* position in block */ + void (*idct_put)(uint8_t *dest, int line_size, DCTELEM *block); + uint8_t partial_bit_count; +- uint16_t partial_bit_buffer; ++ uint32_t partial_bit_buffer; + int shift_offset; + } BlockInfo; + + /* bit budget for AC only in 5 MBs */ + static const int vs_total_ac_bits = (100 * 4 + 68*2) * 5; +-/* see dv_88_areas and dv_248_areas for details */ + static const int mb_area_start[5] = { 1, 6, 21, 43, 64 }; + + static inline int put_bits_left(PutBitContext* s) +@@ -380,7 +377,7 @@ + return (s->buf_end - s->buf) * 8 - put_bits_count(s); + } + +-/* decode ac coefficients */ ++/* decode AC coefficients */ + static void dv_decode_ac(GetBitContext *gb, BlockInfo *mb, DCTELEM *block) + { + int last_index = gb->size_in_bits; +@@ -393,19 +390,17 @@ + OPEN_READER(re, gb); + UPDATE_CACHE(re, gb); + +- /* if we must parse a partial vlc, we do it here */ ++ /* if we must parse a partial VLC, we do it here */ + if (partial_bit_count > 0) { +- re_cache = ((unsigned)re_cache >> partial_bit_count) | +- (mb->partial_bit_buffer << (sizeof(re_cache) * 8 - partial_bit_count)); ++ re_cache = re_cache >> partial_bit_count | mb->partial_bit_buffer; + re_index -= partial_bit_count; + mb->partial_bit_count = 0; + } + + /* get the AC coefficients until last_index is reached */ + for (;;) { +-#ifdef VLC_DEBUG +- printf("%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), re_index); +-#endif ++ av_dlog(NULL, "%2d: bits=%04x index=%d\n", pos, SHOW_UBITS(re, gb, 16), ++ re_index); + /* our own optimized GET_RL_VLC */ + index = NEG_USR32(re_cache, TEX_VLC_BITS); + vlc_len = dv_rl_vlc[index].len; +@@ -420,15 +415,13 @@ + if (re_index + vlc_len > last_index) { + /* should be < 16 bits otherwise a codeword could have been parsed */ + mb->partial_bit_count = last_index - re_index; +- mb->partial_bit_buffer = NEG_USR32(re_cache, mb->partial_bit_count); ++ mb->partial_bit_buffer = re_cache & ~(-1u >> mb->partial_bit_count); + re_index = last_index; + break; + } + re_index += vlc_len; + +-#ifdef VLC_DEBUG +- printf("run=%d level=%d\n", run, level); +-#endif ++ av_dlog(NULL, "run=%d level=%d\n", run, level); + pos += run; + if (pos >= 64) + break; +@@ -481,8 +474,8 @@ + GetBitContext gb; + BlockInfo mb_data[5 * DV_MAX_BPM], *mb, *mb1; + LOCAL_ALIGNED_16(DCTELEM, sblock, [5*DV_MAX_BPM], [64]); +- LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [80 + 4]); /* allow some slack */ +- LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [5 * 80 + 4]); /* allow some slack */ ++ LOCAL_ALIGNED_16(uint8_t, mb_bit_buffer, [ 80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ ++ LOCAL_ALIGNED_16(uint8_t, vs_bit_buffer, [5*80 + FF_INPUT_BUFFER_PADDING_SIZE]); /* allow some slack */ + const int log2_blocksize = 3-s->avctx->lowres; + int is_field_mode[5]; + +@@ -491,7 +484,7 @@ + + memset(sblock, 0, 5*DV_MAX_BPM*sizeof(*sblock)); + +- /* pass 1 : read DC and AC coefficients in blocks */ ++ /* pass 1: read DC and AC coefficients in blocks */ + buf_ptr = &s->buf[work_chunk->buf_offset*80]; + block1 = &sblock[0][0]; + mb1 = mb_data; +@@ -508,7 +501,7 @@ + last_index = s->sys->block_sizes[j]; + init_get_bits(&gb, buf_ptr, last_index); + +- /* get the dc */ ++ /* get the DC */ + dc = get_sbits(&gb, 9); + dct_mode = get_bits1(&gb); + class1 = get_bits(&gb, 2); +@@ -532,12 +525,10 @@ + mb->pos = 0; + mb->partial_bit_count = 0; + +-#ifdef VLC_DEBUG +- printf("MB block: %d, %d ", mb_index, j); +-#endif ++ av_dlog(avctx, "MB block: %d, %d ", mb_index, j); + dv_decode_ac(&gb, mb, block); + +- /* write the remaining bits in a new buffer only if the ++ /* write the remaining bits in a new buffer only if the + block is finished */ + if (mb->pos >= 64) + bit_copy(&pb, &gb); +@@ -546,13 +537,12 @@ + mb++; + } + +- /* pass 2 : we can do it just after */ +-#ifdef VLC_DEBUG +- printf("***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index); +-#endif ++ /* pass 2: we can do it just after */ ++ av_dlog(avctx, "***pass 2 size=%d MB#=%d\n", put_bits_count(&pb), mb_index); + block = block1; + mb = mb1; + init_get_bits(&gb, mb_bit_buffer, put_bits_count(&pb)); ++ put_bits32(&pb, 0); // padding must be zeroed + flush_put_bits(&pb); + for (j = 0; j < s->sys->bpm; j++, block += 64, mb++) { + if (mb->pos < 64 && get_bits_left(&gb) > 0) { +@@ -568,20 +558,17 @@ + bit_copy(&vs_pb, &gb); + } + +- /* we need a pass other the whole video segment */ +-#ifdef VLC_DEBUG +- printf("***pass 3 size=%d\n", put_bits_count(&vs_pb)); +-#endif ++ /* we need a pass over the whole video segment */ ++ av_dlog(avctx, "***pass 3 size=%d\n", put_bits_count(&vs_pb)); + block = &sblock[0][0]; + mb = mb_data; + init_get_bits(&gb, vs_bit_buffer, put_bits_count(&vs_pb)); ++ put_bits32(&vs_pb, 0); // padding must be zeroed + flush_put_bits(&vs_pb); + for (mb_index = 0; mb_index < 5; mb_index++) { + for (j = 0; j < s->sys->bpm; j++) { + if (mb->pos < 64) { +-#ifdef VLC_DEBUG +- printf("start %d:%d\n", mb_index, j); +-#endif ++ av_dlog(avctx, "start %d:%d\n", mb_index, j); + dv_decode_ac(&gb, mb, block); + } + if (mb->pos >= 64 && mb->pos < 127) +@@ -653,7 +640,7 @@ + } + + #if CONFIG_SMALL +-/* Converts run and level (where level != 0) pair into vlc, returning bit size */ ++/* Converts run and level (where level != 0) pair into VLC, returning bit size */ + static av_always_inline int dv_rl2vlc(int run, int level, int sign, uint32_t* vlc) + { + int size; +@@ -770,7 +757,7 @@ + if (ps > 0) { + int is = s->ildct_cmp(NULL, data , NULL, linesize<<1, 4) + + s->ildct_cmp(NULL, data + linesize, NULL, linesize<<1, 4); +- return (ps > is); ++ return ps > is; + } + } + +@@ -830,7 +817,7 @@ + + if (level + 15 > 30U) { + bi->sign[i] = (level >> 31) & 1; +- /* weigh it and and shift down into range, adding for rounding */ ++ /* weight it and and shift down into range, adding for rounding */ + /* the extra division by a factor of 2^4 reverses the 8x expansion of the DCT + AND the 2x doubling of the weights */ + level = (FFABS(level) * weight[i] + (1 << (dv_weight_bits+3))) >> (dv_weight_bits+4); +@@ -1084,7 +1071,7 @@ + const uint8_t* vsc_pack; + int apt, is16_9; + +- s->sys = ff_dv_frame_profile(s->sys, buf, buf_size); ++ s->sys = avpriv_dv_frame_profile2(avctx, s->sys, buf, buf_size); + if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) { + av_log(avctx, AV_LOG_ERROR, "could not find dv frame profile\n"); + return -1; /* NOTE: we only accept several full frames */ +@@ -1093,9 +1080,10 @@ + if (s->picture.data[0]) + avctx->release_buffer(avctx, &s->picture); + ++ avcodec_get_frame_defaults(&s->picture); + s->picture.reference = 0; + s->picture.key_frame = 1; +- s->picture.pict_type = FF_I_TYPE; ++ s->picture.pict_type = AV_PICTURE_TYPE_I; + avctx->pix_fmt = s->sys->pix_fmt; + avctx->time_base = s->sys->time_base; + avcodec_set_dimensions(avctx, s->sys->width, s->sys->height); +@@ -1120,7 +1108,7 @@ + vsc_pack = buf + 80*5 + 48 + 5; + if ( *vsc_pack == dv_video_control ) { + apt = buf[4] & 0x07; +- is16_9 = (vsc_pack && ((vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07))); ++ is16_9 = (vsc_pack[2] & 0x07) == 0x02 || (!apt && (vsc_pack[2] & 0x07) == 0x07); + avctx->sample_aspect_ratio = s->sys->sar[is16_9]; + } + +@@ -1257,14 +1245,14 @@ + { + DVVideoContext *s = c->priv_data; + +- s->sys = ff_dv_codec_profile(c); ++ s->sys = avpriv_dv_codec_profile(c); + if (!s->sys || buf_size < s->sys->frame_size || dv_init_dynamic_tables(s->sys)) + return -1; + + c->pix_fmt = s->sys->pix_fmt; + s->picture = *((AVFrame *)data); + s->picture.key_frame = 1; +- s->picture.pict_type = FF_I_TYPE; ++ s->picture.pict_type = AV_PICTURE_TYPE_I; + + s->buf = buf; + c->execute(c, dv_encode_video_segment, s->sys->work_chunks, NULL, +@@ -1291,12 +1279,13 @@ + + #if CONFIG_DVVIDEO_ENCODER + AVCodec ff_dvvideo_encoder = { +- "dvvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DVVIDEO, +- sizeof(DVVideoContext), +- dvvideo_init_encoder, +- dvvideo_encode_frame, ++ .name = "dvvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DVVIDEO, ++ .priv_data_size = sizeof(DVVideoContext), ++ .init = dvvideo_init_encoder, ++ .encode = dvvideo_encode_frame, ++ .capabilities = CODEC_CAP_SLICE_THREADS, + .pix_fmts = (const enum PixelFormat[]) {PIX_FMT_YUV411P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"), + }; +@@ -1304,16 +1293,14 @@ + + #if CONFIG_DVVIDEO_DECODER + AVCodec ff_dvvideo_decoder = { +- "dvvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DVVIDEO, +- sizeof(DVVideoContext), +- dvvideo_init, +- NULL, +- dvvideo_close, +- dvvideo_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "dvvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DVVIDEO, ++ .priv_data_size = sizeof(DVVideoContext), ++ .init = dvvideo_init, ++ .close = dvvideo_close, ++ .decode = dvvideo_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("DV (Digital Video)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdata.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdata.c 2012-05-14 14:08:53.662326457 +0200 +@@ -25,6 +25,7 @@ + */ + + #include "libavutil/rational.h" ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "dvdata.h" + +@@ -245,20 +246,25 @@ + } + }; + +-const DVprofile* ff_dv_frame_profile(const DVprofile *sys, ++const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys, + const uint8_t* frame, unsigned buf_size) + { +- int i; ++ int i, dsf, stype; + +- int dsf = (frame[3] & 0x80) >> 7; ++ if(buf_size < DV_PROFILE_BYTES) ++ return NULL; + +- int stype = frame[80*5 + 48 + 3] & 0x1f; ++ dsf = (frame[3] & 0x80) >> 7; ++ stype = frame[80*5 + 48 + 3] & 0x1f; + + /* 576i50 25Mbps 4:1:1 is a special case */ + if (dsf == 1 && stype == 0 && frame[4] & 0x07 /* the APT field */) { + return &dv_profiles[2]; + } + ++ if(codec && codec->codec_tag==AV_RL32("dvsd") && codec->width==720 && codec->height==576) ++ return &dv_profiles[1]; ++ + for (i=0; iheight == dv_profiles[i].height && +- codec->pix_fmt == dv_profiles[i].pix_fmt && +- codec->width == dv_profiles[i].width) ++ if (codec->coded_height == dv_profiles[i].height && ++ codec->pix_fmt == dv_profiles[i].pix_fmt && ++ codec->coded_width == dv_profiles[i].width) + return &dv_profiles[i]; + + return NULL; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdata.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdata.h 2012-05-14 14:08:53.663326477 +0200 +@@ -274,9 +274,11 @@ + */ + #define DV_MAX_BPM 8 + +-const DVprofile* ff_dv_frame_profile(const DVprofile *sys, ++const DVprofile* avpriv_dv_frame_profile(const DVprofile *sys, + const uint8_t* frame, unsigned buf_size); +-const DVprofile* ff_dv_codec_profile(AVCodecContext* codec); ++const DVprofile* avpriv_dv_frame_profile2(AVCodecContext* codec, const DVprofile *sys, ++ const uint8_t* frame, unsigned buf_size); ++const DVprofile* avpriv_dv_codec_profile(AVCodecContext* codec); + + static inline int dv_write_dif_id(enum dv_section_type t, uint8_t chan_num, + uint8_t seq_num, uint8_t dif_num, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsubdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsubdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsubdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsubdec.c 2012-05-14 14:08:53.665326517 +0200 +@@ -1,5 +1,5 @@ + /* +- * DVD subtitle decoding for ffmpeg ++ * DVD subtitle decoding + * Copyright (c) 2005 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -27,10 +27,10 @@ + + typedef struct DVDSubContext + { +- uint8_t colormap[4]; +- uint8_t alpha[256]; + uint32_t palette[16]; + int has_palette; ++ uint8_t colormap[4]; ++ uint8_t alpha[256]; + } DVDSubContext; + + static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values) +@@ -42,8 +42,8 @@ + + for (i = num_values; i > 0; i--) { + y = *ycbcr++; +- cb = *ycbcr++; + cr = *ycbcr++; ++ cb = *ycbcr++; + YUV_TO_RGB1_CCIR(cb, cr); + YUV_TO_RGB2_CCIR(r, g, b, y); + *rgba++ = (*alpha++ << 24) | (r << 16) | (g << 8) | b; +@@ -141,18 +141,25 @@ + return 0; + } + +-static void fill_palette(DVDSubContext* ctx, +- uint32_t *rgba_palette, +- uint32_t subtitle_color) +-{ ++static void guess_palette(uint32_t *rgba_palette, ++ DVDSubContext* ctx, ++ uint32_t subtitle_color) ++{ ++ static const uint8_t level_map[4][4] = { ++ // this configuration (full range, lowest to highest) in tests ++ // seemed most common, so assume this ++ {0xff}, ++ {0x00, 0xff}, ++ {0x00, 0x80, 0xff}, ++ {0x00, 0x55, 0xaa, 0xff}, ++ }; + uint8_t color_used[16]; + int nb_opaque_colors, i, level, j, r, g, b; +- uint8_t *colormap = ctx->colormap; +- uint8_t *alpha = ctx->alpha; ++ uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha; + + if(ctx->has_palette) { + for(i = 0; i < 4; i++) +- rgba_palette[i] = (ctx->palette[ctx->colormap[i]] & 0x00ffffff) ++ rgba_palette[i] = (ctx->palette[colormap[i]] & 0x00ffffff) + | ((alpha[i] * 17) << 24); + return; + } +@@ -172,18 +179,18 @@ + if (nb_opaque_colors == 0) + return; + +- j = nb_opaque_colors; ++ j = 0; + memset(color_used, 0, 16); + for(i = 0; i < 4; i++) { + if (alpha[i] != 0) { + if (!color_used[colormap[i]]) { +- level = (0xff * j) / nb_opaque_colors; ++ level = level_map[nb_opaque_colors][j]; + r = (((subtitle_color >> 16) & 0xff) * level) >> 8; + g = (((subtitle_color >> 8) & 0xff) * level) >> 8; + b = (((subtitle_color >> 0) & 0xff) * level) >> 8; + rgba_palette[i] = b | (g << 8) | (r << 16) | ((alpha[i] * 17) << 24); + color_used[colormap[i]] = (i + 1); +- j--; ++ j++; + } else { + rgba_palette[i] = (rgba_palette[color_used[colormap[i]] - 1] & 0x00ffffff) | + ((alpha[i] * 17) << 24); +@@ -200,15 +207,13 @@ + int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos; + int big_offsets, offset_size, is_8bit = 0; + const uint8_t *yuv_palette = 0; +- uint8_t *colormap = ctx->colormap; +- uint8_t *alpha = ctx->alpha; ++ uint8_t *colormap = ctx->colormap, *alpha = ctx->alpha; + int date; + int i; + int is_menu = 0; + + if (buf_size < 10) + return -1; +- memset(sub_header, 0, sizeof(*sub_header)); + + if (AV_RB16(buf) == 0) { /* HD subpicture with 4-byte offsets */ + big_offsets = 1; +@@ -361,7 +366,8 @@ + yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256); + } else { + sub_header->rects[0]->nb_colors = 4; +- fill_palette(ctx, sub_header->rects[0]->pict.data[1], 0xffff00); ++ guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1], ctx, ++ 0xffff00); + } + sub_header->rects[0]->x = x1; + sub_header->rects[0]->y = y1; +@@ -371,6 +377,10 @@ + sub_header->rects[0]->pict.linesize[0] = w; + } + } ++ if (next_cmd_pos < cmd_pos) { ++ av_log(NULL, AV_LOG_ERROR, "Invalid command offset\n"); ++ break; ++ } + if (next_cmd_pos == cmd_pos) + break; + cmd_pos = next_cmd_pos; +@@ -524,11 +534,15 @@ + static int dvdsub_init(AVCodecContext *avctx) + { + DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data; +- char *data = avctx->extradata; ++ char *dataorig, *data; + + if (!avctx->extradata || !avctx->extradata_size) + return 1; + ++ dataorig = data = av_malloc(avctx->extradata_size+1); ++ if (!data) ++ return AVERROR(ENOMEM); ++ memcpy(data, avctx->extradata, avctx->extradata_size); + data[avctx->extradata_size] = '\0'; + + for(;;) { +@@ -545,32 +559,35 @@ + while(*p == ',' || isspace(*p)) + p++; + } +-#if defined(DEBUG) +- av_log(avctx, AV_LOG_INFO, "palette:"); +- for(i=0;i<16;i++) +- av_log(avctx, AV_LOG_WARNING, " 0x%06x", ctx->palette[i]); +- av_log(avctx, AV_LOG_INFO, "\n"); +-#endif + } + + data += pos; + data += strspn(data, "\n\r"); + } + +- if(!ctx->has_palette && avctx->extradata_size == 64) ++ if (!ctx->has_palette && avctx->extradata_size == 64) { + ayvu_to_argb((uint8_t*)avctx->extradata, ctx->palette, 16); ++ ctx->has_palette = 1; ++ } ++ ++ if (ctx->has_palette) { ++ int i; ++ av_log(avctx, AV_LOG_DEBUG, "palette:"); ++ for(i=0;i<16;i++) ++ av_log(avctx, AV_LOG_DEBUG, " 0x%06x", ctx->palette[i]); ++ av_log(avctx, AV_LOG_DEBUG, "\n"); ++ } + ++ av_free(dataorig); + return 1; + } + + AVCodec ff_dvdsub_decoder = { +- "dvdsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_DVD_SUBTITLE, +- sizeof(DVDSubContext), +- dvdsub_init, +- NULL, +- NULL, +- dvdsub_decode, ++ .name = "dvdsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_DVD_SUBTITLE, ++ .priv_data_size = sizeof(DVDSubContext), ++ .init = dvdsub_init, ++ .decode = dvdsub_decode, + .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsubenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsubenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsubenc.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsubenc.c 2012-05-14 14:08:53.666326537 +0200 +@@ -1,5 +1,5 @@ + /* +- * DVD subtitle encoding for ffmpeg ++ * DVD subtitle encoding + * Copyright (c) 2005 Wolfram Gloger + * + * This file is part of FFmpeg. +@@ -216,11 +216,9 @@ + } + + AVCodec ff_dvdsub_encoder = { +- "dvdsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_DVD_SUBTITLE, +- 0, +- NULL, +- dvdsub_encode, ++ .name = "dvdsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_DVD_SUBTITLE, ++ .encode = dvdsub_encode, + .long_name = NULL_IF_CONFIG_SMALL("DVD subtitles"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsub_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsub_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dvdsub_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dvdsub_parser.c 2012-05-14 14:08:53.664326497 +0200 +@@ -1,5 +1,5 @@ + /* +- * DVD subtitle decoding for ffmpeg ++ * DVD subtitle decoding + * Copyright (c) 2005 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -77,9 +77,9 @@ + } + + AVCodecParser ff_dvdsub_parser = { +- { CODEC_ID_DVD_SUBTITLE }, +- sizeof(DVDSubParseContext), +- dvdsub_parse_init, +- dvdsub_parse, +- dvdsub_parse_close, ++ .codec_ids = { CODEC_ID_DVD_SUBTITLE }, ++ .priv_data_size = sizeof(DVDSubParseContext), ++ .parser_init = dvdsub_parse_init, ++ .parser_parse = dvdsub_parse, ++ .parser_close = dvdsub_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dv_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dv_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dv_tablegen.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dv_tablegen.h 2012-05-14 14:08:53.656326336 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef DV_TABLEGEN_H +-#define DV_TABLEGEN_H ++#ifndef AVCODEC_DV_TABLEGEN_H ++#define AVCODEC_DV_TABLEGEN_H + + #include + #include "dv_vlc_data.h" +@@ -93,4 +93,4 @@ + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* DV_TABLEGEN_H */ ++#endif /* AVCODEC_DV_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dwt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dwt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dwt.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dwt.c 2012-05-14 14:08:53.670326618 +0200 +@@ -1,5 +1,6 @@ + /* + * Copyright (C) 2004-2010 Michael Niedermayer ++ * Copyright (C) 2008 David Conrad + * + * This file is part of FFmpeg. + * +@@ -21,17 +22,18 @@ + #include "libavutil/attributes.h" + #include "dsputil.h" + #include "dwt.h" ++#include "libavcodec/x86/dwt.h" + + void ff_slice_buffer_init(slice_buffer * buf, int line_count, int max_allocated_lines, int line_width, IDWTELEM * base_buffer) + { + int i; + + buf->base_buffer = base_buffer; +- buf->line_count = line_count; +- buf->line_width = line_width; +- buf->data_count = max_allocated_lines; +- buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count); +- buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines); ++ buf->line_count = line_count; ++ buf->line_width = line_width; ++ buf->data_count = max_allocated_lines; ++ buf->line = av_mallocz (sizeof(IDWTELEM *) * line_count); ++ buf->data_stack = av_malloc (sizeof(IDWTELEM *) * max_allocated_lines); + + for(i = 0; i < max_allocated_lines; i++){ + buf->data_stack[i] = av_malloc (sizeof(IDWTELEM) * line_width); +@@ -45,7 +47,6 @@ + IDWTELEM * buffer; + + assert(buf->data_stack_top >= 0); +-// assert(!buf->line[line]); + if (buf->line[line]) + return buf->line[line]; + +@@ -92,8 +93,8 @@ + + static inline int mirror(int v, int m){ + while((unsigned)v > (unsigned)m){ +- v=-v; +- if(v<0) v+= 2*m; ++ v = -v; ++ if(v < 0) v+= 2*m; + } + return v; + } +@@ -103,29 +104,29 @@ + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ +- const int mirror_left= !highpass; +- const int mirror_right= (width&1) ^ highpass; +- const int w= (width>>1) - 1 + (highpass & width); ++ const int mirror_left = !highpass; ++ const int mirror_right = (width & 1) ^ highpass; ++ const int w = (width >> 1) - 1 + (highpass & width); + int i; + + #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) + if(mirror_left){ +- dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); +- dst += dst_step; +- src += src_step; ++ dst[0] = LIFT(src[0], ((mul * 2 * ref[0] + add) >> shift), inverse); ++ dst += dst_step; ++ src += src_step; + } + + for(i=0; i>shift), ++ dst[i * dst_step] = ++ LIFT(src[i * src_step], ++ ((mul * (ref[i * ref_step] + ref[(i + 1) * ref_step]) + add) >> shift), + inverse); + } + + if(mirror_right){ +- dst[w*dst_step] = +- LIFT(src[w*src_step], +- ((mul*2*ref[w*ref_step]+add)>>shift), ++ dst[w * dst_step] = ++ LIFT(src[w * src_step], ++ ((mul * 2 * ref[w * ref_step] + add) >> shift), + inverse); + } + } +@@ -135,29 +136,32 @@ + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ +- const int mirror_left= !highpass; +- const int mirror_right= (width&1) ^ highpass; +- const int w= (width>>1) - 1 + (highpass & width); ++ const int mirror_left = !highpass; ++ const int mirror_right = (width&1) ^ highpass; ++ const int w = (width >> 1) - 1 + (highpass & width); + int i; + + #define LIFT(src, ref, inv) ((src) + ((inv) ? - (ref) : + (ref))) + if(mirror_left){ +- dst[0] = LIFT(src[0], ((mul*2*ref[0]+add)>>shift), inverse); +- dst += dst_step; +- src += src_step; ++ dst[0] = ++ LIFT(src[0], ++ ((mul * 2 * ref[0] + add) >> shift), ++ inverse); ++ dst += dst_step; ++ src += src_step; + } + +- for(i=0; i>shift), ++ for(i = 0; i < w; i++){ ++ dst[i * dst_step] = ++ LIFT(src[i * src_step], ++ ((mul * (ref[i * ref_step] + ref[(i + 1) * ref_step]) + add) >> shift), + inverse); + } + + if(mirror_right){ +- dst[w*dst_step] = +- LIFT(src[w*src_step], +- ((mul*2*ref[w*ref_step]+add)>>shift), ++ dst[w * dst_step] = ++ LIFT(src[w * src_step], ++ ((mul * 2 * ref[w * ref_step] + add) >> shift), + inverse); + } + } +@@ -168,32 +172,32 @@ + int dst_step, int src_step, int ref_step, + int width, int mul, int add, int shift, + int highpass, int inverse){ +- const int mirror_left= !highpass; +- const int mirror_right= (width&1) ^ highpass; +- const int w= (width>>1) - 1 + (highpass & width); ++ const int mirror_left = !highpass; ++ const int mirror_right = (width&1) ^ highpass; ++ const int w = (width >> 1) - 1 + (highpass & width); + int i; + + assert(shift == 4); +-#define LIFTS(src, ref, inv) \ +- ((inv) ? \ +- (src) + (((ref) + 4*(src))>>shift): \ +- -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) ++#define LIFTS(src, ref, inv) \ ++ ((inv) ? \ ++ (src) + (((ref) + 4 * (src)) >> shift): \ ++ -((-16 * (src) + (ref) + add / 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23))) + if(mirror_left){ +- dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); +- dst += dst_step; +- src += src_step; ++ dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse); ++ dst += dst_step; ++ src += src_step; + } + +- for(i=0; i>1) - 1 + (highpass & width); ++ const int mirror_left = !highpass; ++ const int mirror_right = (width&1) ^ highpass; ++ const int w = (width >> 1) - 1 + (highpass & width); + int i; + + assert(shift == 4); +-#define LIFTS(src, ref, inv) \ +- ((inv) ? \ +- (src) + (((ref) + 4*(src))>>shift): \ +- -((-16*(src) + (ref) + add/4 + 1 + (5<<25))/(5*4) - (1<<23))) ++#define LIFTS(src, ref, inv) \ ++ ((inv) ? \ ++ (src) + (((ref) + 4 * (src)) >> shift): \ ++ -((-16 * (src) + (ref) + add / 4 + 1 + (5 << 25)) / (5 * 4) - (1 << 23))) + if(mirror_left){ +- dst[0] = LIFTS(src[0], mul*2*ref[0]+add, inverse); ++ dst[0] = LIFTS(src[0], mul * 2 * ref[0] + add, inverse); + dst += dst_step; + src += src_step; + } + +- for(i=0; i>1; ++ const int width2 = width>>1; ++ const int w2 = (width+1)>>1; + int x; +- const int w2= (width+1)>>1; + +- for(x=0; x>1; +- A4 += (A1 + 1)>>1; +- b[0+width2] = A1; +- b[0 ] = A4; +- for(x=1; x+1>1; +- A2 += (A1 + A3 + 2)>>2; +- b[x+width2] = A3; +- b[x ] = A2; +- +- A1= temp[x+1+width2]; +- A2= temp[x+2 ]; +- A1 -= (A2 + A4)>>1; +- A4 += (A1 + A3 + 2)>>2; +- b[x+1+width2] = A1; +- b[x+1 ] = A4; ++ A2 = temp[1 ]; ++ A4 = temp[0 ]; ++ A1 = temp[0+width2]; ++ A1 -= (A2 + A4) >> 1; ++ A4 += (A1 + 1) >> 1; ++ b[0 + width2] = A1; ++ b[0 ] = A4; ++ for(x = 1; x + 1 < width2; x += 2){ ++ A3 = temp[x + width2]; ++ A4 = temp[x + 1 ]; ++ A3 -= (A2 + A4) >> 1; ++ A2 += (A1 + A3 + 2) >> 2; ++ b[x + width2] = A3; ++ b[x ] = A2; ++ ++ A1 = temp[x + 1 + width2]; ++ A2 = temp[x + 2 ]; ++ A1 -= (A2 + A4) >> 1; ++ A4 += (A1 + A3 + 2) >> 2; ++ b[x + 1 + width2] = A1; ++ b[x + 1 ] = A4; + } +- A3= temp[width-1]; ++ A3 = temp[width - 1]; + A3 -= A2; +- A2 += (A1 + A3 + 2)>>2; ++ A2 += (A1 + A3 + 2) >> 2; + b[width -1] = A3; + b[width2-1] = A2; + } + #else +- lift(b+w2, temp+w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); +- lift(b , temp , b+w2, 1, 1, 1, width, 1, 2, 2, 0, 0); ++ lift(b + w2, temp + w2, temp, 1, 1, 1, width, -1, 0, 1, 1, 0); ++ lift(b , temp , b + w2, 1, 1, 1, width, 1, 2, 2, 0, 0); + #endif /* 0 */ + } + + static void vertical_decompose53iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>1; ++ for(i = 0; i < width; i++){ ++ b1[i] -= (b0[i] + b2[i]) >> 1; + } + } + + static void vertical_decompose53iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>2; ++ for(i = 0; i < width; i++){ ++ b1[i] += (b0[i] + b2[i] + 2) >> 2; + } + } + + static void spatial_decompose53i(DWTELEM *buffer, int width, int height, int stride){ + int y; +- DWTELEM *b0= buffer + mirror(-2-1, height-1)*stride; +- DWTELEM *b1= buffer + mirror(-2 , height-1)*stride; ++ DWTELEM *b0 = buffer + mirror(-2 - 1, height-1)*stride; ++ DWTELEM *b1 = buffer + mirror(-2 , height-1)*stride; + +- for(y=-2; y>1; ++ const int w2 = (width+1)>>1; + +- lift (temp+w2, b +1, b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); +- liftS(temp , b , temp+w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); +- lift (b +w2, temp+w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); +- lift (b , temp , b +w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); ++ lift (temp + w2, b + 1 , b , 1, 2, 2, width, W_AM, W_AO, W_AS, 1, 1); ++ liftS(temp , b , temp + w2, 1, 2, 1, width, W_BM, W_BO, W_BS, 0, 0); ++ lift (b + w2, temp + w2, temp , 1, 1, 1, width, W_CM, W_CO, W_CS, 1, 0); ++ lift (b , temp , b + w2, 1, 1, 1, width, W_DM, W_DO, W_DS, 0, 0); + } + + + static void vertical_decompose97iH0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>W_AS; ++ for(i = 0; i < width; i++){ ++ b1[i] -= (W_AM * (b0[i] + b2[i]) + W_AO) >> W_AS; + } + } + + static void vertical_decompose97iH1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>W_CS; ++ for(i=0; i < width; i++){ ++ b1[i] += (W_CM * (b0[i] + b2[i]) + W_CO) >> W_CS; + } + } + + static void vertical_decompose97iL0(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>W_BS; ++ b1[i] -= (W_BM * (b0[i] + b2[i]) + W_BO) >> W_BS; + #else +- b1[i] = (16*4*b1[i] - 4*(b0[i] + b2[i]) + W_BO*5 + (5<<27)) / (5*16) - (1<<23); ++ b1[i] = (16 * 4 * b1[i] - 4 * (b0[i] + b2[i]) + W_BO * 5 + (5 << 27)) / (5 * 16) - (1 << 23); + #endif + } + } +@@ -358,123 +362,122 @@ + static void vertical_decompose97iL1(DWTELEM *b0, DWTELEM *b1, DWTELEM *b2, int width){ + int i; + +- for(i=0; i>W_DS; ++ for(i = 0; i < width; i++){ ++ b1[i] += (W_DM * (b0[i] + b2[i]) + W_DO) >> W_DS; + } + } + + static void spatial_decompose97i(DWTELEM *buffer, int width, int height, int stride){ + int y; +- DWTELEM *b0= buffer + mirror(-4-1, height-1)*stride; +- DWTELEM *b1= buffer + mirror(-4 , height-1)*stride; +- DWTELEM *b2= buffer + mirror(-4+1, height-1)*stride; +- DWTELEM *b3= buffer + mirror(-4+2, height-1)*stride; +- +- for(y=-4; y>level, height>>level, stride<>level, height>>level, stride<> level, height >> level, stride << level); break; ++ case DWT_53: spatial_decompose53i(buffer, width >> level, height >> level, stride << level); break; + } + } + } + + static void horizontal_compose53i(IDWTELEM *b, int width){ + IDWTELEM temp[width]; +- const int width2= width>>1; +- const int w2= (width+1)>>1; ++ const int width2 = width >> 1; ++ const int w2 = (width + 1) >> 1; + int x; + +- for(x=0; x>1); +- for(x=2; x>2); +- b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1); +- } +- if(width&1){ +- b[x ] = temp[x ] - ((temp[x-1]+1)>>1); +- b[x-1] = temp[x-1] + ((b [x-2] + b [x ]+1)>>1); ++ for(x = 0; x < width2; x++){ ++ temp[2 * x ] = b[x ]; ++ temp[2 * x + 1] = b[x + w2]; ++ } ++ if(width & 1) ++ temp[2 * x ] = b[x ]; ++ ++ b[0] = temp[0] - ((temp[1] + 1) >> 1); ++ for(x = 2; x < width - 1; x += 2){ ++ b[x ] = temp[x ] - ((temp[x - 1] + temp[x + 1] + 2) >> 2); ++ b[x - 1] = temp[x - 1] + ((b [x - 2] + b [x ] + 1) >> 1); ++ } ++ if(width & 1){ ++ b[x ] = temp[x ] - ((temp[x - 1] + 1) >> 1); ++ b[x - 1] = temp[x - 1] + ((b [x - 2] + b [x ] + 1) >> 1); + }else +- b[x-1] = temp[x-1] + b[x-2]; ++ b[x - 1] = temp[x - 1] + b[x - 2]; + } + + static void vertical_compose53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + +- for(i=0; i>1; ++ for(i = 0; i < width; i++){ ++ b1[i] += (b0[i] + b2[i]) >> 1; + } + } + + static void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width){ + int i; + +- for(i=0; i>2; ++ for(i = 0; i < width; i++){ ++ b1[i] -= (b0[i] + b2[i] + 2) >> 2; + } + } + + static void spatial_compose53i_buffered_init(DWTCompose *cs, slice_buffer * sb, int height, int stride_line){ +- cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height-1) * stride_line); +- cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height-1) * stride_line); +- cs->y = -1; ++ cs->b0 = slice_buffer_get_line(sb, mirror(-1-1, height - 1) * stride_line); ++ cs->b1 = slice_buffer_get_line(sb, mirror(-1 , height - 1) * stride_line); ++ cs->y = -1; + } + + static void spatial_compose53i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride){ +- cs->b0 = buffer + mirror(-1-1, height-1)*stride; +- cs->b1 = buffer + mirror(-1 , height-1)*stride; +- cs->y = -1; ++ cs->b0 = buffer + mirror(-1-1, height - 1) * stride; ++ cs->b1 = buffer + mirror(-1 , height - 1) * stride; ++ cs->y = -1; + } + + static void spatial_compose53i_dy_buffered(DWTCompose *cs, slice_buffer * sb, int width, int height, int stride_line){ +- int y= cs->y; ++ int y = cs->y; ++ IDWTELEM *b0 = cs->b0; ++ IDWTELEM *b1 = cs->b1; ++ IDWTELEM *b2 = slice_buffer_get_line(sb, mirror(y + 1, height-1) * stride_line); ++ IDWTELEM *b3 = slice_buffer_get_line(sb, mirror(y + 2, height-1) * stride_line); + +- IDWTELEM *b0= cs->b0; +- IDWTELEM *b1= cs->b1; +- IDWTELEM *b2= slice_buffer_get_line(sb, mirror(y+1, height-1) * stride_line); +- IDWTELEM *b3= slice_buffer_get_line(sb, mirror(y+2, height-1) * stride_line); +- +- if(y+1<(unsigned)height && y<(unsigned)height){ ++ if(y + 1 < (unsigned)height && y < (unsigned)height){ + int x; + +- for(x=0; x>2; +- b1[x] += (b0[x] + b2[x])>>1; ++ for(x = 0; x < width; x++){ ++ b2[x] -= (b1[x] + b3[x] + 2) >> 2; ++ b1[x] += (b0[x] + b2[x]) >> 1; + } + }else{ +- if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); +- if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); ++ if(y + 1 < (unsigned)height) vertical_compose53iL0(b1, b2, b3, width); ++ if(y + 0 < (unsigned)height) vertical_compose53iH0(b0, b1, b2, width); + } + +- if(y-1<(unsigned)height) horizontal_compose53i(b0, width); +- if(y+0<(unsigned)height) horizontal_compose53i(b1, width); ++ if(y - 1 <(unsigned)height) horizontal_compose53i(b0, width); ++ if(y + 0 <(unsigned)height) horizontal_compose53i(b1, width); + + cs->b0 = b2; + cs->b1 = b3; +@@ -482,17 +485,17 @@ + } + + static void spatial_compose53i_dy(DWTCompose *cs, IDWTELEM *buffer, int width, int height, int stride){ +- int y= cs->y; +- IDWTELEM *b0= cs->b0; +- IDWTELEM *b1= cs->b1; +- IDWTELEM *b2= buffer + mirror(y+1, height-1)*stride; +- IDWTELEM *b3= buffer + mirror(y+2, height-1)*stride; ++ int y = cs->y; ++ IDWTELEM *b0 = cs->b0; ++ IDWTELEM *b1 = cs->b1; ++ IDWTELEM *b2 = buffer + mirror(y + 1, height - 1) * stride; ++ IDWTELEM *b3 = buffer + mirror(y + 2, height - 1) * stride; + +- if(y+1<(unsigned)height) vertical_compose53iL0(b1, b2, b3, width); +- if(y+0<(unsigned)height) vertical_compose53iH0(b0, b1, b2, width); ++ if(y + 1 < (unsigned)height) vertical_compose53iL0(b1, b2, b3, width); ++ if(y + 0 < (unsigned)height) vertical_compose53iH0(b0, b1, b2, width); + +- if(y-1<(unsigned)height) horizontal_compose53i(b0, width); +- if(y+0<(unsigned)height) horizontal_compose53i(b1, width); ++ if(y - 1 < (unsigned)height) horizontal_compose53i(b0, width); ++ if(y + 0 < (unsigned)height) horizontal_compose53i(b1, width); + + cs->b0 = b2; + cs->b1 = b3; +@@ -509,22 +512,22 @@ + + void ff_snow_horizontal_compose97i(IDWTELEM *b, int width){ + IDWTELEM temp[width]; +- const int w2= (width+1)>>1; ++ const int w2 = (width + 1) >> 1; + + #if 0 //maybe more understadable but slower +- inv_lift (temp , b , b +w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); +- inv_lift (temp+1 , b +w2, temp , 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1); ++ inv_lift (temp , b , b + w2, 2, 1, 1, width, W_DM, W_DO, W_DS, 0, 1); ++ inv_lift (temp + 1, b + w2, temp , 2, 1, 2, width, W_CM, W_CO, W_CS, 1, 1); + +- inv_liftS(b , temp , temp+1 , 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1); +- inv_lift (b+1 , temp+1 , b , 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0); ++ inv_liftS(b ,temp ,temp + 1, 2, 2, 2, width, W_BM, W_BO, W_BS, 0, 1); ++ inv_lift (b + 1 ,temp + 1,b , 2, 2, 2, width, W_AM, W_AO, W_AS, 1, 0); + #else + int x; +- temp[0] = b[0] - ((3*b[w2]+2)>>2); +- for(x=1; x<(width>>1); x++){ +- temp[2*x ] = b[x ] - ((3*(b [x+w2-1] + b[x+w2])+4)>>3); +- temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x]; ++ temp[0] = b[0] - ((3 * b[w2] + 2) >> 2); ++ for(x = 1; x < (width >> 1); x++){ ++ temp[2 * x ] = b[x ] - (( 3 * (b [ x + w2 - 1] + b[x + w2]) + 4) >> 3); ++ temp[2 * x - 1] = b[x + w2 - 1] - temp[2 * x - 2] - temp[2 * x]; + } +- if(width&1){ ++ if(width & 1){ + temp[2*x ] = b[x ] - ((3*b [x+w2-1]+2)>>2); + temp[2*x-1] = b[x+w2-1] - temp[2*x-2] - temp[2*x]; + }else +@@ -841,3 +844,541 @@ + + if (HAVE_MMX) ff_dwt_init_x86(c); + } ++ ++ ++static av_always_inline ++void interleave(IDWTELEM *dst, IDWTELEM *src0, IDWTELEM *src1, int w2, int add, int shift) ++{ ++ int i; ++ for (i = 0; i < w2; i++) { ++ dst[2*i ] = (src0[i] + add) >> shift; ++ dst[2*i+1] = (src1[i] + add) >> shift; ++ } ++} ++ ++static void horizontal_compose_dirac53i(IDWTELEM *b, IDWTELEM *temp, int w) ++{ ++ const int w2 = w >> 1; ++ int x; ++ ++ temp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); ++ for (x = 1; x < w2; x++) { ++ temp[x ] = COMPOSE_53iL0 (b[x+w2-1], b[x ], b[x+w2]); ++ temp[x+w2-1] = COMPOSE_DIRAC53iH0(temp[x-1], b[x+w2-1], temp[x]); ++ } ++ temp[w-1] = COMPOSE_DIRAC53iH0(temp[w2-1], b[w-1], temp[w2-1]); ++ ++ interleave(b, temp, temp+w2, w2, 1, 1); ++} ++ ++static void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int w) ++{ ++ const int w2 = w >> 1; ++ int x; ++ ++ tmp[0] = COMPOSE_53iL0(b[w2], b[0], b[w2]); ++ for (x = 1; x < w2; x++) ++ tmp[x] = COMPOSE_53iL0(b[x+w2-1], b[x], b[x+w2]); ++ ++ // extend the edges ++ tmp[-1] = tmp[0]; ++ tmp[w2+1] = tmp[w2] = tmp[w2-1]; ++ ++ for (x = 0; x < w2; x++) { ++ b[2*x ] = (tmp[x] + 1)>>1; ++ b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1; ++ } ++} ++ ++static void horizontal_compose_dd137i(IDWTELEM *b, IDWTELEM *tmp, int w) ++{ ++ const int w2 = w >> 1; ++ int x; ++ ++ tmp[0] = COMPOSE_DD137iL0(b[w2], b[w2], b[0], b[w2 ], b[w2+1]); ++ tmp[1] = COMPOSE_DD137iL0(b[w2], b[w2], b[1], b[w2+1], b[w2+2]); ++ for (x = 2; x < w2-1; x++) ++ tmp[x] = COMPOSE_DD137iL0(b[x+w2-2], b[x+w2-1], b[x], b[x+w2], b[x+w2+1]); ++ tmp[w2-1] = COMPOSE_DD137iL0(b[w-3], b[w-2], b[w2-1], b[w-1], b[w-1]); ++ ++ // extend the edges ++ tmp[-1] = tmp[0]; ++ tmp[w2+1] = tmp[w2] = tmp[w2-1]; ++ ++ for (x = 0; x < w2; x++) { ++ b[2*x ] = (tmp[x] + 1)>>1; ++ b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1; ++ } ++} ++ ++static av_always_inline ++void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *temp, int w, int shift) ++{ ++ const int w2 = w >> 1; ++ int x; ++ ++ for (x = 0; x < w2; x++) { ++ temp[x ] = COMPOSE_HAARiL0(b[x ], b[x+w2]); ++ temp[x+w2] = COMPOSE_HAARiH0(b[x+w2], temp[x]); ++ } ++ ++ interleave(b, temp, temp+w2, w2, shift, shift); ++} ++ ++static void horizontal_compose_haar0i(IDWTELEM *b, IDWTELEM *temp, int w) ++{ ++ horizontal_compose_haari(b, temp, w, 0); ++} ++ ++static void horizontal_compose_haar1i(IDWTELEM *b, IDWTELEM *temp, int w) ++{ ++ horizontal_compose_haari(b, temp, w, 1); ++} ++ ++static void horizontal_compose_fidelityi(IDWTELEM *b, IDWTELEM *tmp, int w) ++{ ++ const int w2 = w >> 1; ++ int i, x; ++ IDWTELEM v[8]; ++ ++ for (x = 0; x < w2; x++) { ++ for (i = 0; i < 8; i++) ++ v[i] = b[av_clip(x-3+i, 0, w2-1)]; ++ tmp[x] = COMPOSE_FIDELITYiH0(v[0], v[1], v[2], v[3], b[x+w2], v[4], v[5], v[6], v[7]); ++ } ++ ++ for (x = 0; x < w2; x++) { ++ for (i = 0; i < 8; i++) ++ v[i] = tmp[av_clip(x-4+i, 0, w2-1)]; ++ tmp[x+w2] = COMPOSE_FIDELITYiL0(v[0], v[1], v[2], v[3], b[x], v[4], v[5], v[6], v[7]); ++ } ++ ++ interleave(b, tmp+w2, tmp, w2, 0, 0); ++} ++ ++static void horizontal_compose_daub97i(IDWTELEM *b, IDWTELEM *temp, int w) ++{ ++ const int w2 = w >> 1; ++ int x, b0, b1, b2; ++ ++ temp[0] = COMPOSE_DAUB97iL1(b[w2], b[0], b[w2]); ++ for (x = 1; x < w2; x++) { ++ temp[x ] = COMPOSE_DAUB97iL1(b[x+w2-1], b[x ], b[x+w2]); ++ temp[x+w2-1] = COMPOSE_DAUB97iH1(temp[x-1], b[x+w2-1], temp[x]); ++ } ++ temp[w-1] = COMPOSE_DAUB97iH1(temp[w2-1], b[w-1], temp[w2-1]); ++ ++ // second stage combined with interleave and shift ++ b0 = b2 = COMPOSE_DAUB97iL0(temp[w2], temp[0], temp[w2]); ++ b[0] = (b0 + 1) >> 1; ++ for (x = 1; x < w2; x++) { ++ b2 = COMPOSE_DAUB97iL0(temp[x+w2-1], temp[x ], temp[x+w2]); ++ b1 = COMPOSE_DAUB97iH0( b0, temp[x+w2-1], b2 ); ++ b[2*x-1] = (b1 + 1) >> 1; ++ b[2*x ] = (b2 + 1) >> 1; ++ b0 = b2; ++ } ++ b[w-1] = (COMPOSE_DAUB97iH0(b2, temp[w-1], b2) + 1) >> 1; ++} ++ ++static void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width) ++{ ++ int i; ++ ++ for(i=0; ivertical_compose_l0; ++ vertical_compose_5tap vertical_compose_h0 = d->vertical_compose_h0; ++ DWTCompose *cs = d->cs + level; ++ ++ int i, y = cs->y; ++ IDWTELEM *b[8]; ++ for (i = 0; i < 6; i++) ++ b[i] = cs->b[i]; ++ b[6] = d->buffer + av_clip(y+5, 0, height-2)*stride; ++ b[7] = d->buffer + av_clip(y+6, 1, height-1)*stride; ++ ++ if(y+5<(unsigned)height) vertical_compose_l0( b[5], b[6], b[7], width); ++ if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); ++ ++ if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); ++ if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); ++ ++ for (i = 0; i < 6; i++) ++ cs->b[i] = b[i+2]; ++ cs->y += 2; ++} ++ ++static void spatial_compose_dirac53i_dy(DWTContext *d, int level, int width, int height, int stride) ++{ ++ vertical_compose_3tap vertical_compose_l0 = d->vertical_compose_l0; ++ vertical_compose_3tap vertical_compose_h0 = d->vertical_compose_h0; ++ DWTCompose *cs = d->cs + level; ++ ++ int y= cs->y; ++ IDWTELEM *b[4] = { cs->b[0], cs->b[1] }; ++ b[2] = d->buffer + mirror(y+1, height-1)*stride; ++ b[3] = d->buffer + mirror(y+2, height-1)*stride; ++ ++ if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); ++ if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); ++ ++ if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); ++ if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); ++ ++ cs->b[0] = b[2]; ++ cs->b[1] = b[3]; ++ cs->y += 2; ++} ++ ++ ++static void spatial_compose_dd137i_dy(DWTContext *d, int level, int width, int height, int stride) ++{ ++ vertical_compose_5tap vertical_compose_l0 = d->vertical_compose_l0; ++ vertical_compose_5tap vertical_compose_h0 = d->vertical_compose_h0; ++ DWTCompose *cs = d->cs + level; ++ ++ int i, y = cs->y; ++ IDWTELEM *b[10]; ++ for (i = 0; i < 8; i++) ++ b[i] = cs->b[i]; ++ b[8] = d->buffer + av_clip(y+7, 0, height-2)*stride; ++ b[9] = d->buffer + av_clip(y+8, 1, height-1)*stride; ++ ++ if(y+5<(unsigned)height) vertical_compose_l0(b[3], b[5], b[6], b[7], b[9], width); ++ if(y+1<(unsigned)height) vertical_compose_h0(b[0], b[2], b[3], b[4], b[6], width); ++ ++ if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); ++ if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); ++ ++ for (i = 0; i < 8; i++) ++ cs->b[i] = b[i+2]; ++ cs->y += 2; ++} ++ ++// haar makes the assumption that height is even (always true for dirac) ++static void spatial_compose_haari_dy(DWTContext *d, int level, int width, int height, int stride) ++{ ++ vertical_compose_2tap vertical_compose = d->vertical_compose; ++ int y = d->cs[level].y; ++ IDWTELEM *b0 = d->buffer + (y-1)*stride; ++ IDWTELEM *b1 = d->buffer + (y )*stride; ++ ++ vertical_compose(b0, b1, width); ++ d->horizontal_compose(b0, d->temp, width); ++ d->horizontal_compose(b1, d->temp, width); ++ ++ d->cs[level].y += 2; ++} ++ ++// Don't do sliced idwt for fidelity; the 9 tap filter makes it a bit annoying ++// Fortunately, this filter isn't used in practice. ++static void spatial_compose_fidelity(DWTContext *d, int level, int width, int height, int stride) ++{ ++ vertical_compose_9tap vertical_compose_l0 = d->vertical_compose_l0; ++ vertical_compose_9tap vertical_compose_h0 = d->vertical_compose_h0; ++ int i, y; ++ IDWTELEM *b[8]; ++ ++ for (y = 1; y < height; y += 2) { ++ for (i = 0; i < 8; i++) ++ b[i] = d->buffer + av_clip((y-7 + 2*i), 0, height-2)*stride; ++ vertical_compose_h0(d->buffer + y*stride, b, width); ++ } ++ ++ for (y = 0; y < height; y += 2) { ++ for (i = 0; i < 8; i++) ++ b[i] = d->buffer + av_clip((y-7 + 2*i), 1, height-1)*stride; ++ vertical_compose_l0(d->buffer + y*stride, b, width); ++ } ++ ++ for (y = 0; y < height; y++) ++ d->horizontal_compose(d->buffer + y*stride, d->temp, width); ++ ++ d->cs[level].y = height+1; ++} ++ ++static void spatial_compose_daub97i_dy(DWTContext *d, int level, int width, int height, int stride) ++{ ++ vertical_compose_3tap vertical_compose_l0 = d->vertical_compose_l0; ++ vertical_compose_3tap vertical_compose_h0 = d->vertical_compose_h0; ++ vertical_compose_3tap vertical_compose_l1 = d->vertical_compose_l1; ++ vertical_compose_3tap vertical_compose_h1 = d->vertical_compose_h1; ++ DWTCompose *cs = d->cs + level; ++ ++ int i, y = cs->y; ++ IDWTELEM *b[6]; ++ for (i = 0; i < 4; i++) ++ b[i] = cs->b[i]; ++ b[4] = d->buffer + mirror(y+3, height-1)*stride; ++ b[5] = d->buffer + mirror(y+4, height-1)*stride; ++ ++ if(y+3<(unsigned)height) vertical_compose_l1(b[3], b[4], b[5], width); ++ if(y+2<(unsigned)height) vertical_compose_h1(b[2], b[3], b[4], width); ++ if(y+1<(unsigned)height) vertical_compose_l0(b[1], b[2], b[3], width); ++ if(y+0<(unsigned)height) vertical_compose_h0(b[0], b[1], b[2], width); ++ ++ if(y-1<(unsigned)height) d->horizontal_compose(b[0], d->temp, width); ++ if(y+0<(unsigned)height) d->horizontal_compose(b[1], d->temp, width); ++ ++ for (i = 0; i < 4; i++) ++ cs->b[i] = b[i+2]; ++ cs->y += 2; ++} ++ ++ ++static void spatial_compose97i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) ++{ ++ cs->b[0] = buffer + mirror(-3-1, height-1)*stride; ++ cs->b[1] = buffer + mirror(-3 , height-1)*stride; ++ cs->b[2] = buffer + mirror(-3+1, height-1)*stride; ++ cs->b[3] = buffer + mirror(-3+2, height-1)*stride; ++ cs->y = -3; ++} ++ ++static void spatial_compose53i_init2(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) ++{ ++ cs->b[0] = buffer + mirror(-1-1, height-1)*stride; ++ cs->b[1] = buffer + mirror(-1 , height-1)*stride; ++ cs->y = -1; ++} ++ ++static void spatial_compose_dd97i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) ++{ ++ cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; ++ cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; ++ cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; ++ cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; ++ cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; ++ cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; ++ cs->y = -5; ++} ++ ++static void spatial_compose_dd137i_init(DWTCompose *cs, IDWTELEM *buffer, int height, int stride) ++{ ++ cs->b[0] = buffer + av_clip(-5-1, 0, height-2)*stride; ++ cs->b[1] = buffer + av_clip(-5 , 1, height-1)*stride; ++ cs->b[2] = buffer + av_clip(-5+1, 0, height-2)*stride; ++ cs->b[3] = buffer + av_clip(-5+2, 1, height-1)*stride; ++ cs->b[4] = buffer + av_clip(-5+3, 0, height-2)*stride; ++ cs->b[5] = buffer + av_clip(-5+4, 1, height-1)*stride; ++ cs->b[6] = buffer + av_clip(-5+5, 0, height-2)*stride; ++ cs->b[7] = buffer + av_clip(-5+6, 1, height-1)*stride; ++ cs->y = -5; ++} ++ ++int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height, ++ int stride, enum dwt_type type, int decomposition_count, ++ IDWTELEM *temp) ++{ ++ int level; ++ ++ d->buffer = buffer; ++ d->width = width; ++ d->height = height; ++ d->stride = stride; ++ d->decomposition_count = decomposition_count; ++ d->temp = temp + 8; ++ ++ for(level=decomposition_count-1; level>=0; level--){ ++ int hl = height >> level; ++ int stride_l = stride << level; ++ ++ switch(type){ ++ case DWT_DIRAC_DD9_7: ++ spatial_compose_dd97i_init(d->cs+level, buffer, hl, stride_l); ++ break; ++ case DWT_DIRAC_LEGALL5_3: ++ spatial_compose53i_init2(d->cs+level, buffer, hl, stride_l); ++ break; ++ case DWT_DIRAC_DD13_7: ++ spatial_compose_dd137i_init(d->cs+level, buffer, hl, stride_l); ++ break; ++ case DWT_DIRAC_HAAR0: ++ case DWT_DIRAC_HAAR1: ++ d->cs[level].y = 1; ++ break; ++ case DWT_DIRAC_DAUB9_7: ++ spatial_compose97i_init2(d->cs+level, buffer, hl, stride_l); ++ break; ++ default: ++ d->cs[level].y = 0; ++ break; ++ } ++ } ++ ++ switch (type) { ++ case DWT_DIRAC_DD9_7: ++ d->spatial_compose = spatial_compose_dd97i_dy; ++ d->vertical_compose_l0 = vertical_compose53iL0; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0; ++ d->horizontal_compose = horizontal_compose_dd97i; ++ d->support = 7; ++ break; ++ case DWT_DIRAC_LEGALL5_3: ++ d->spatial_compose = spatial_compose_dirac53i_dy; ++ d->vertical_compose_l0 = vertical_compose53iL0; ++ d->vertical_compose_h0 = vertical_compose_dirac53iH0; ++ d->horizontal_compose = horizontal_compose_dirac53i; ++ d->support = 3; ++ break; ++ case DWT_DIRAC_DD13_7: ++ d->spatial_compose = spatial_compose_dd137i_dy; ++ d->vertical_compose_l0 = vertical_compose_dd137iL0; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0; ++ d->horizontal_compose = horizontal_compose_dd137i; ++ d->support = 7; ++ break; ++ case DWT_DIRAC_HAAR0: ++ case DWT_DIRAC_HAAR1: ++ d->spatial_compose = spatial_compose_haari_dy; ++ d->vertical_compose = vertical_compose_haar; ++ if (type == DWT_DIRAC_HAAR0) ++ d->horizontal_compose = horizontal_compose_haar0i; ++ else ++ d->horizontal_compose = horizontal_compose_haar1i; ++ d->support = 1; ++ break; ++ case DWT_DIRAC_FIDELITY: ++ d->spatial_compose = spatial_compose_fidelity; ++ d->vertical_compose_l0 = vertical_compose_fidelityiL0; ++ d->vertical_compose_h0 = vertical_compose_fidelityiH0; ++ d->horizontal_compose = horizontal_compose_fidelityi; ++ break; ++ case DWT_DIRAC_DAUB9_7: ++ d->spatial_compose = spatial_compose_daub97i_dy; ++ d->vertical_compose_l0 = vertical_compose_daub97iL0; ++ d->vertical_compose_h0 = vertical_compose_daub97iH0; ++ d->vertical_compose_l1 = vertical_compose_daub97iL1; ++ d->vertical_compose_h1 = vertical_compose_daub97iH1; ++ d->horizontal_compose = horizontal_compose_daub97i; ++ d->support = 5; ++ break; ++ default: ++ av_log(NULL, AV_LOG_ERROR, "Unknown wavelet type %d\n", type); ++ return -1; ++ } ++ ++ if (HAVE_MMX) ff_spatial_idwt_init_mmx(d, type); ++ ++ return 0; ++} ++ ++void ff_spatial_idwt_slice2(DWTContext *d, int y) ++{ ++ int level, support = d->support; ++ ++ for (level = d->decomposition_count-1; level >= 0; level--) { ++ int wl = d->width >> level; ++ int hl = d->height >> level; ++ int stride_l = d->stride << level; ++ ++ while (d->cs[level].y <= FFMIN((y>>level)+support, hl)) ++ d->spatial_compose(d, level, wl, hl, stride_l); ++ } ++} ++ ++int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride, ++ enum dwt_type type, int decomposition_count, IDWTELEM *temp) ++{ ++ DWTContext d; ++ int y; ++ ++ if (ff_spatial_idwt_init2(&d, buffer, width, height, stride, type, decomposition_count, temp)) ++ return -1; ++ ++ for (y = 0; y < d.height; y += 4) ++ ff_spatial_idwt_slice2(&d, y); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dwt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dwt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dwt.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dwt.h 2012-05-14 14:08:53.670326618 +0200 +@@ -26,7 +26,12 @@ + typedef int DWTELEM; + typedef short IDWTELEM; + ++#define MAX_DWT_SUPPORT 8 ++#define MAX_DECOMPOSITIONS 8 ++ + typedef struct { ++ IDWTELEM *b[MAX_DWT_SUPPORT]; ++ + IDWTELEM *b0; + IDWTELEM *b1; + IDWTELEM *b2; +@@ -45,13 +50,99 @@ + IDWTELEM * base_buffer; ///< Buffer that this structure is caching. + } slice_buffer; + ++struct DWTContext; ++ ++// Possible prototypes for vertical_compose functions ++typedef void (*vertical_compose_2tap)(IDWTELEM *b0, IDWTELEM *b1, int width); ++typedef void (*vertical_compose_3tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width); ++typedef void (*vertical_compose_5tap)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width); ++typedef void (*vertical_compose_9tap)(IDWTELEM *dst, IDWTELEM *b[8], int width); ++ + typedef struct DWTContext { ++ IDWTELEM *buffer; ++ IDWTELEM *temp; ++ int width; ++ int height; ++ int stride; ++ int decomposition_count; ++ int support; ++ ++ void (*spatial_compose)(struct DWTContext *cs, int level, int width, int height, int stride); ++ void (*vertical_compose_l0)(void); ++ void (*vertical_compose_h0)(void); ++ void (*vertical_compose_l1)(void); ++ void (*vertical_compose_h1)(void); ++ void (*vertical_compose)(void); ///< one set of lowpass and highpass combined ++ void (*horizontal_compose)(IDWTELEM *b, IDWTELEM *tmp, int width); ++ + void (*vertical_compose97i)(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, IDWTELEM *b5, int width); + void (*horizontal_compose97i)(IDWTELEM *b, int width); + void (*inner_add_yblock)(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8); ++ ++ DWTCompose cs[MAX_DECOMPOSITIONS]; + } DWTContext; + +-#define MAX_DECOMPOSITIONS 8 ++enum dwt_type { ++ DWT_SNOW_DAUB9_7, ++ DWT_SNOW_LEGALL5_3, ++ DWT_DIRAC_DD9_7, ++ DWT_DIRAC_LEGALL5_3, ++ DWT_DIRAC_DD13_7, ++ DWT_DIRAC_HAAR0, ++ DWT_DIRAC_HAAR1, ++ DWT_DIRAC_FIDELITY, ++ DWT_DIRAC_DAUB9_7, ++ DWT_NUM_TYPES ++}; ++ ++// -1 if an error occurred, e.g. the dwt_type isn't recognized ++int ff_spatial_idwt_init2(DWTContext *d, IDWTELEM *buffer, int width, int height, ++ int stride, enum dwt_type type, int decomposition_count, ++ IDWTELEM *temp); ++ ++int ff_spatial_idwt2(IDWTELEM *buffer, int width, int height, int stride, ++ enum dwt_type type, int decomposition_count, IDWTELEM *temp); ++ ++void ff_spatial_idwt_slice2(DWTContext *d, int y); ++ ++// shared stuff for simd optimiztions ++#define COMPOSE_53iL0(b0, b1, b2)\ ++ (b1 - ((b0 + b2 + 2) >> 2)) ++ ++#define COMPOSE_DIRAC53iH0(b0, b1, b2)\ ++ (b1 + ((b0 + b2 + 1) >> 1)) ++ ++#define COMPOSE_DD97iH0(b0, b1, b2, b3, b4)\ ++ (b2 + ((-b0 + 9*b1 + 9*b3 - b4 + 8) >> 4)) ++ ++#define COMPOSE_DD137iL0(b0, b1, b2, b3, b4)\ ++ (b2 - ((-b0 + 9*b1 + 9*b3 - b4 + 16) >> 5)) ++ ++#define COMPOSE_HAARiL0(b0, b1)\ ++ (b0 - ((b1 + 1) >> 1)) ++ ++#define COMPOSE_HAARiH0(b0, b1)\ ++ (b0 + b1) ++ ++#define COMPOSE_FIDELITYiL0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\ ++ (b4 - ((-8*(b0+b8) + 21*(b1+b7) - 46*(b2+b6) + 161*(b3+b5) + 128) >> 8)) ++ ++#define COMPOSE_FIDELITYiH0(b0, b1, b2, b3, b4, b5, b6, b7, b8)\ ++ (b4 + ((-2*(b0+b8) + 10*(b1+b7) - 25*(b2+b6) + 81*(b3+b5) + 128) >> 8)) ++ ++#define COMPOSE_DAUB97iL1(b0, b1, b2)\ ++ (b1 - ((1817*(b0 + b2) + 2048) >> 12)) ++ ++#define COMPOSE_DAUB97iH1(b0, b1, b2)\ ++ (b1 - (( 113*(b0 + b2) + 64) >> 7)) ++ ++#define COMPOSE_DAUB97iL0(b0, b1, b2)\ ++ (b1 + (( 217*(b0 + b2) + 2048) >> 12)) ++ ++#define COMPOSE_DAUB97iH0(b0, b1, b2)\ ++ (b1 + ((6497*(b0 + b2) + 2048) >> 12)) ++ ++ + + #define DWT_97 0 + #define DWT_53 1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxa.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxa.c 2012-05-14 14:08:53.671326638 +0200 +@@ -209,7 +209,7 @@ + r = *buf++; + g = *buf++; + b = *buf++; +- c->pal[i] = (r << 16) | (g << 8) | b; ++ c->pal[i] = 0xFF << 24 | r << 16 | g << 8 | b; + } + pc = 1; + buf_size -= 768+4; +@@ -240,13 +240,13 @@ + switch(compr){ + case -1: + c->pic.key_frame = 0; +- c->pic.pict_type = FF_P_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_P; + if(c->prev.data[0]) + memcpy(c->pic.data[0], c->prev.data[0], c->pic.linesize[0] * avctx->height); + else{ // Should happen only when first frame is 'NULL' + memset(c->pic.data[0], 0, c->pic.linesize[0] * avctx->height); + c->pic.key_frame = 1; +- c->pic.pict_type = FF_I_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_I; + } + break; + case 2: +@@ -254,7 +254,7 @@ + case 4: + case 5: + c->pic.key_frame = !(compr & 1); +- c->pic.pict_type = (compr & 1) ? FF_P_TYPE : FF_I_TYPE; ++ c->pic.pict_type = (compr & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; + for(j = 0; j < avctx->height; j++){ + if(compr & 1){ + for(i = 0; i < avctx->width; i++) +@@ -269,7 +269,7 @@ + case 12: // ScummVM coding + case 13: + c->pic.key_frame = 0; +- c->pic.pict_type = FF_P_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_P; + decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]); + break; + default: +@@ -295,6 +295,9 @@ + c->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&c->pic); ++ avcodec_get_frame_defaults(&c->prev); ++ + c->dsize = avctx->width * avctx->height * 2; + if((c->decomp_buf = av_malloc(c->dsize)) == NULL) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); +@@ -318,15 +321,14 @@ + } + + AVCodec ff_dxa_decoder = { +- "dxa", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DXA, +- sizeof(DxaDecContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "dxa", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DXA, ++ .priv_data_size = sizeof(DxaDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Feeble Files/ScummVM DXA"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxtory.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxtory.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxtory.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxtory.c 2012-05-14 14:08:53.672326658 +0200 +@@ -0,0 +1,109 @@ ++/* ++ * Dxtory decoder ++ * ++ * Copyright (c) 2011 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "libavutil/intreadwrite.h" ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->coded_frame) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ int h, w; ++ AVFrame *pic = avctx->coded_frame; ++ const uint8_t *src = avpkt->data; ++ uint8_t *Y1, *Y2, *U, *V; ++ int ret; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ if (avpkt->size < avctx->width * avctx->height * 3 / 2 + 16) { ++ av_log(avctx, AV_LOG_ERROR, "packet too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ pic->reference = 0; ++ if ((ret = avctx->get_buffer(avctx, pic)) < 0) ++ return ret; ++ ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ pic->key_frame = 1; ++ ++ if (AV_RL32(src) != 0x01000002) { ++ av_log_ask_for_sample(avctx, "Unknown frame header %X\n", AV_RL32(src)); ++ return AVERROR_PATCHWELCOME; ++ } ++ src += 16; ++ ++ Y1 = pic->data[0]; ++ Y2 = pic->data[0] + pic->linesize[0]; ++ U = pic->data[1]; ++ V = pic->data[2]; ++ for (h = 0; h < avctx->height; h += 2) { ++ for (w = 0; w < avctx->width; w += 2) { ++ AV_WN16A(Y1 + w, AV_RN16A(src)); ++ AV_WN16A(Y2 + w, AV_RN16A(src + 2)); ++ U[w >> 1] = src[4] + 0x80; ++ V[w >> 1] = src[5] + 0x80; ++ src += 6; ++ } ++ Y1 += pic->linesize[0] << 1; ++ Y2 += pic->linesize[0] << 1; ++ U += pic->linesize[1]; ++ V += pic->linesize[2]; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int decode_close(AVCodecContext *avctx) ++{ ++ AVFrame *pic = avctx->coded_frame; ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_dxtory_decoder = { ++ .name = "dxtory", ++ .long_name = NULL_IF_CONFIG_SMALL("Dxtory"), ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DXTORY, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2.c 2012-05-14 14:08:53.673326678 +0200 +@@ -27,7 +27,7 @@ + + void *ff_dxva2_get_surface(const Picture *picture) + { +- return picture->data[3]; ++ return picture->f.data[3]; + } + + unsigned ff_dxva2_get_surface_index(const struct dxva_context *ctx, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2.h 2012-05-14 14:08:53.673326678 +0200 +@@ -25,6 +25,7 @@ + + #include + ++#include + #include + + #define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_h264.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_h264.c 2012-05-14 14:08:53.674326698 +0200 +@@ -70,15 +70,15 @@ + ff_dxva2_get_surface_index(ctx, r), + r->long_ref != 0); + +- if ((r->reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX) ++ if ((r->f.reference & PICT_TOP_FIELD) && r->field_poc[0] != INT_MAX) + pp->FieldOrderCntList[i][0] = r->field_poc[0]; +- if ((r->reference & PICT_BOTTOM_FIELD) && r->field_poc[1] != INT_MAX) ++ if ((r->f.reference & PICT_BOTTOM_FIELD) && r->field_poc[1] != INT_MAX) + pp->FieldOrderCntList[i][1] = r->field_poc[1]; + + pp->FrameNumList[i] = r->long_ref ? r->pic_id : r->frame_num; +- if (r->reference & PICT_TOP_FIELD) ++ if (r->f.reference & PICT_TOP_FIELD) + pp->UsedForReferenceFlags |= 1 << (2*i + 0); +- if (r->reference & PICT_BOTTOM_FIELD) ++ if (r->f.reference & PICT_BOTTOM_FIELD) + pp->UsedForReferenceFlags |= 1 << (2*i + 1); + } else { + pp->RefFrameList[i].bPicEntry = 0xff; +@@ -116,7 +116,7 @@ + if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) + pp->Reserved16Bits = 0; + else +- pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ ++ pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ + pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; + pp->CurrFieldOrderCnt[0] = 0; + if ((s->picture_structure & PICT_TOP_FIELD) && +@@ -162,17 +162,19 @@ + for (j = 0; j < 16; j++) + qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j]; + +- for (i = 0; i < 2; i++) +- for (j = 0; j < 64; j++) +- qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][j]; ++ for (i = 0; i < 64; i++) { ++ qm->bScalingLists8x8[0][i] = h->pps.scaling_matrix8[0][i]; ++ qm->bScalingLists8x8[1][i] = h->pps.scaling_matrix8[3][i]; ++ } + } else { +- for (i = 0; i < 6; i++) +- for (j = 0; j < 16; j++) +- qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][zigzag_scan[j]]; +- +- for (i = 0; i < 2; i++) +- for (j = 0; j < 64; j++) +- qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][ff_zigzag_direct[j]]; ++ for (i = 0; i < 6; i++) ++ for (j = 0; j < 16; j++) ++ qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][zigzag_scan[j]]; ++ ++ for (i = 0; i < 64; i++) { ++ qm->bScalingLists8x8[0][i] = h->pps.scaling_matrix8[0][ff_zigzag_direct[i]]; ++ qm->bScalingLists8x8[1][i] = h->pps.scaling_matrix8[3][ff_zigzag_direct[i]]; ++ } + } + } + +@@ -229,7 +231,7 @@ + unsigned plane; + fill_picture_entry(&slice->RefPicList[list][i], + ff_dxva2_get_surface_index(ctx, r), +- r->reference == PICT_BOTTOM_FIELD); ++ r->f.reference == PICT_BOTTOM_FIELD); + for (plane = 0; plane < 3; plane++) { + int w, o; + if (plane == 0 && h->luma_weight_flag[list]) { +@@ -259,7 +261,7 @@ + slice->slice_qs_delta = 0; /* XXX not implemented by FFmpeg */ + slice->slice_qp_delta = s->qscale - h->pps.init_qp; + slice->redundant_pic_cnt = h->redundant_pic_count; +- if (h->slice_type == FF_B_TYPE) ++ if (h->slice_type == AV_PICTURE_TYPE_B) + slice->direct_spatial_mv_pred_flag = h->direct_spatial_mv_pred; + slice->cabac_init_idc = h->pps.cabac ? h->cabac_init_idc : 0; + if (h->deblocking_filter < 2) +@@ -278,7 +280,7 @@ + const unsigned mb_count = s->mb_width * s->mb_height; + struct dxva_context *ctx = avctx->hwaccel_context; + const Picture *current_picture = h->s.current_picture_ptr; +- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; + DXVA_Slice_H264_Short *slice = NULL; + uint8_t *dxva_data, *current, *end; + unsigned dxva_size; +@@ -373,7 +375,7 @@ + { + const H264Context *h = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; +- struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = h->s.current_picture_ptr->f.hwaccel_picture_private; + + if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) + return -1; +@@ -397,7 +399,7 @@ + const H264Context *h = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; + const Picture *current_picture = h->s.current_picture_ptr; +- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; + unsigned position; + + if (ctx_pic->slice_count >= MAX_SLICES) +@@ -416,7 +418,7 @@ + position, size); + ctx_pic->slice_count++; + +- if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) ++ if (h->slice_type != AV_PICTURE_TYPE_I && h->slice_type != AV_PICTURE_TYPE_SI) + ctx_pic->pp.wBitFields &= ~(1 << 15); /* Set IntraPicFlag to 0 */ + return 0; + } +@@ -426,7 +428,7 @@ + H264Context *h = avctx->priv_data; + MpegEncContext *s = &h->s; + struct dxva2_picture_context *ctx_pic = +- h->s.current_picture_ptr->hwaccel_picture_private; ++ h->s.current_picture_ptr->f.hwaccel_picture_private; + + if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) + return -1; +@@ -449,7 +451,6 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, + .pix_fmt = PIX_FMT_DXVA2_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_internal.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_internal.h 2012-05-14 14:08:53.675326718 +0200 +@@ -23,6 +23,8 @@ + #ifndef AVCODEC_DXVA_INTERNAL_H + #define AVCODEC_DXVA_INTERNAL_H + ++#define _WIN32_WINNT 0x0600 ++#define COBJMACROS + #include "dxva2.h" + #include "avcodec.h" + #include "mpegvideo.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_mpeg2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_mpeg2.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_mpeg2.c 2012-05-14 14:08:53.676326738 +0200 +@@ -44,11 +44,11 @@ + memset(pp, 0, sizeof(*pp)); + pp->wDecodedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture); + pp->wDeblockedPictureIndex = 0; +- if (s->pict_type != FF_I_TYPE) ++ if (s->pict_type != AV_PICTURE_TYPE_I) + pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); + else + pp->wForwardRefPictureIndex = 0xffff; +- if (s->pict_type == FF_B_TYPE) ++ if (s->pict_type == AV_PICTURE_TYPE_B) + pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture); + else + pp->wBackwardRefPictureIndex = 0xffff; +@@ -61,8 +61,8 @@ + pp->bBPPminus1 = 7; + pp->bPicStructure = s->picture_structure; + pp->bSecondField = is_field && !s->first_field; +- pp->bPicIntra = s->pict_type == FF_I_TYPE; +- pp->bPicBackwardPrediction = s->pict_type == FF_B_TYPE; ++ pp->bPicIntra = s->pict_type == AV_PICTURE_TYPE_I; ++ pp->bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B; + pp->bBidirectionalAveragingMode = 0; + pp->bMVprecisionAndChromaRelation= 0; /* FIXME */ + pp->bChromaFormat = s->chroma_format; +@@ -109,10 +109,10 @@ + qm->bNewQmatrix[i] = 1; + for (i = 0; i < 64; i++) { + int n = s->dsp.idct_permutation[ff_zigzag_direct[i]]; +- qm->Qmatrix[0][i] = s->intra_matrix[n];; +- qm->Qmatrix[1][i] = s->inter_matrix[n];; +- qm->Qmatrix[2][i] = s->chroma_intra_matrix[n];; +- qm->Qmatrix[3][i] = s->chroma_inter_matrix[n];; ++ qm->Qmatrix[0][i] = s->intra_matrix[n]; ++ qm->Qmatrix[1][i] = s->inter_matrix[n]; ++ qm->Qmatrix[2][i] = s->chroma_intra_matrix[n]; ++ qm->Qmatrix[3][i] = s->chroma_inter_matrix[n]; + } + } + +@@ -151,7 +151,7 @@ + const struct MpegEncContext *s = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; + struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; ++ s->current_picture_ptr->f.hwaccel_picture_private; + const int is_field = s->picture_structure != PICT_FRAME; + const unsigned mb_count = s->mb_width * (s->mb_height >> is_field); + uint8_t *dxva_data, *current, *end; +@@ -210,7 +210,7 @@ + const struct MpegEncContext *s = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; + struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; ++ s->current_picture_ptr->f.hwaccel_picture_private; + + if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) + return -1; +@@ -242,7 +242,7 @@ + { + const struct MpegEncContext *s = avctx->priv_data; + struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; ++ s->current_picture_ptr->f.hwaccel_picture_private; + unsigned position; + DXVA_SliceInfo* slice; + +@@ -267,7 +267,7 @@ + { + struct MpegEncContext *s = avctx->priv_data; + struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; ++ s->current_picture_ptr->f.hwaccel_picture_private; + struct dxva_context *ctx = avctx->hwaccel_context; + + if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) +@@ -285,7 +285,6 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_MPEG2VIDEO, + .pix_fmt = PIX_FMT_DXVA2_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_vc1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_vc1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/dxva2_vc1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/dxva2_vc1.c 2012-05-14 14:08:53.677326758 +0200 +@@ -38,16 +38,16 @@ + { + const MpegEncContext *s = &v->s; + const Picture *current_picture = s->current_picture_ptr; +- BYTE bPicIntra = s->pict_type == FF_I_TYPE || v->bi_type == 1; +- BYTE bPicBackwardPrediction = s->pict_type == FF_B_TYPE && v->bi_type == 0; ++ BYTE bPicIntra = s->pict_type == AV_PICTURE_TYPE_I || v->bi_type == 1; ++ BYTE bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B && v->bi_type == 0; + + memset(pp, 0, sizeof(*pp)); + pp->wDecodedPictureIndex = + pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture); +- if (bPicIntra) +- pp->wForwardRefPictureIndex = 0xffff; +- else ++ if (!bPicIntra) + pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); ++ else ++ pp->wForwardRefPictureIndex = 0xffff; + if (bPicBackwardPrediction) + pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture); + else +@@ -70,7 +70,7 @@ + pp->bPicStructure |= 0x01; + if (s->picture_structure & PICT_BOTTOM_FIELD) + pp->bPicStructure |= 0x02; +- pp->bSecondField = v->interlace && v->fcm != 0x03 && !s->first_field; ++ pp->bSecondField = v->interlace && v->fcm != ILACE_FIELD && !s->first_field; + pp->bPicIntra = bPicIntra; + pp->bPicBackwardPrediction = bPicBackwardPrediction; + pp->bBidirectionalAveragingMode = (1 << 7) | +@@ -102,7 +102,7 @@ + (s->resync_marker << 4) | + (v->rangered << 3) | + (s->max_b_frames ); +- pp->bPicExtrapolation = (!v->interlace || v->fcm == 0x00) ? 1 : 2; ++ pp->bPicExtrapolation = (!v->interlace || v->fcm == PROGRESSIVE) ? 1 : 2; + pp->bPicDeblocked = ((v->overlap == 1 && + pp->bPicBackwardPrediction == 0 && + ctx->cfg->ConfigResidDiffHost == 0) << 6) | +@@ -113,10 +113,10 @@ + (v->interlace << 5) | + (v->tfcntrflag << 4) | + (v->finterpflag << 3) | +- ((s->pict_type != FF_B_TYPE) << 2) | //includes BI ++ ((s->pict_type != AV_PICTURE_TYPE_B) << 2) | + (v->psf << 1) | + (v->extended_dmv ); +- if (s->pict_type != FF_I_TYPE) ++ if (s->pict_type != AV_PICTURE_TYPE_I) + pp->bPic4MVallowed = v->mv_mode == MV_PMODE_MIXED_MV || + (v->mv_mode == MV_PMODE_INTENSITY_COMP && + v->mv_mode2 == MV_PMODE_MIXED_MV); +@@ -166,7 +166,7 @@ + const VC1Context *v = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; + const MpegEncContext *s = &v->s; +- struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = s->current_picture_ptr->f.hwaccel_picture_private; + + DXVA_SliceInfo *slice = &ctx_pic->si; + +@@ -218,7 +218,7 @@ + { + const VC1Context *v = avctx->priv_data; + struct dxva_context *ctx = avctx->hwaccel_context; +- struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private; + + if (!ctx->decoder || !ctx->cfg || ctx->surface_count <= 0) + return -1; +@@ -236,7 +236,7 @@ + { + const VC1Context *v = avctx->priv_data; + const Picture *current_picture = v->s.current_picture_ptr; +- struct dxva2_picture_context *ctx_pic = current_picture->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = current_picture->f.hwaccel_picture_private; + + if (ctx_pic->bitstream_size > 0) + return -1; +@@ -257,7 +257,7 @@ + static int end_frame(AVCodecContext *avctx) + { + VC1Context *v = avctx->priv_data; +- struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->hwaccel_picture_private; ++ struct dxva2_picture_context *ctx_pic = v->s.current_picture_ptr->f.hwaccel_picture_private; + + if (ctx_pic->bitstream_size <= 0) + return -1; +@@ -274,7 +274,6 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_WMV3, + .pix_fmt = PIX_FMT_DXVA2_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, +@@ -287,7 +286,6 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_VC1, + .pix_fmt = PIX_FMT_DXVA2_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .decode_slice = decode_slice, + .end_frame = end_frame, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3_data.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3_data.c 2012-05-14 14:08:53.681326840 +0200 +@@ -0,0 +1,1134 @@ ++/* ++ * E-AC-3 tables ++ * Copyright (c) 2007 Bartlomiej Wolowiec ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Tables taken directly from the E-AC-3 spec. ++ */ ++ ++#include "eac3_data.h" ++#include "ac3.h" ++ ++const uint8_t ff_eac3_bits_vs_hebap[20] = { ++ 0, 2, 3, 4, 5, 7, 8, 9, 3, 4, ++ 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, ++}; ++ ++/** ++ * Table E3.6, Gk=1 ++ * No gain (Gk=1) inverse quantization, remapping scale factors ++ * ff_eac3_gaq_remap[hebap+8] ++ */ ++const int16_t ff_eac3_gaq_remap_1[12] = { ++ 4681, 2185, 1057, 520, 258, 129, 64, 32, 16, 8, 2, 0 ++}; ++ ++/** ++ * Table E3.6, Gk=2 & Gk=4, A ++ * Large mantissa inverse quantization, remapping scale factors ++ * ff_eac3_gaq_remap_2_4_a[hebap-8][Gk=2,4] ++ */ ++const int16_t ff_eac3_gaq_remap_2_4_a[9][2] = { ++ { -10923, -4681 }, ++ { -14043, -6554 }, ++ { -15292, -7399 }, ++ { -15855, -7802 }, ++ { -16124, -7998 }, ++ { -16255, -8096 }, ++ { -16320, -8144 }, ++ { -16352, -8168 }, ++ { -16368, -8180 } ++}; ++ ++/** ++ * Table E3.6, Gk=2 & Gk=4, B ++ * Large mantissa inverse quantization, negative mantissa remapping offsets ++ * ff_eac3_gaq_remap_3_4_b[hebap-8][Gk=2,4] ++ */ ++const int16_t ff_eac3_gaq_remap_2_4_b[9][2] = { ++ { -5461, -1170 }, ++ { -11703, -4915 }, ++ { -14199, -6606 }, ++ { -15327, -7412 }, ++ { -15864, -7805 }, ++ { -16126, -7999 }, ++ { -16255, -8096 }, ++ { -16320, -8144 }, ++ { -16352, -8168 } ++}; ++ ++static const int16_t vq_hebap1[4][6] = { ++{ 7167, 4739, 1106, 4269, 10412, 4820}, ++{ -5702, -3187, -14483, -1392, -2027, 849}, ++{ 633, 6199, 7009, -12779, -2306, -2636}, ++{ -1468, -7031, 7592, 10617, -5946, -3062}, ++}; ++static const int16_t vq_hebap2[8][6] = { ++{ -12073, 608, -7019, 590, 4000, 869}, ++{ 6692, 15689, -6178, -9239, -74, 133}, ++{ 1855, -989, 20596, -2920, -4475, 225}, ++{ -1194, -3901, -821, -6566, -875, -20298}, ++{ -2762, -3181, -4094, -5623, -16945, 9765}, ++{ 1547, 6839, 1980, 20233, -1071, -4986}, ++{ 6221, -17915, -5516, 6266, 358, 1162}, ++{ 3753, -1066, 4283, -3227, 15928, 10186}, ++}; ++static const int16_t vq_hebap3[16][6] = { ++{ -10028, 20779, 10982, -4560, 798, -68}, ++{ 11050, 20490, -6617, -5342, -1797, -1631}, ++{ 3977, -542, 7118, -1166, 18844, 14678}, ++{ -4320, -96, -7295, -492, -22050, -4277}, ++{ 2692, 5856, 5530, 21862, -7212, -5325}, ++{ -135, -23391, 962, 8115, -644, 382}, ++{ -1563, 3400, -3299, 4693, -6892, 22398}, ++{ 3535, 3030, 7296, 6214, 20476, -12099}, ++{ 57, -6823, 1848, -22349, -5919, 6823}, ++{ -821, -3655, -387, -6253, -1735, -22373}, ++{ -6046, 1586, -18890, -14392, 9214, 705}, ++{ -5716, 264, -17964, 14618, 7921, -337}, ++{ -110, 108, 8, 74, -89, -50}, ++{ 6612, -1517, 21687, -1658, -7949, -246}, ++{ 21667, -6335, -8290, -101, -1349, -22}, ++{ -22003, -6476, 7974, 648, 2054, -331}, ++}; ++static const int16_t vq_hebap4[32][6] = { ++{ 6636, -4593, 14173, -17297, -16523, 864}, ++{ 3658, 22540, 104, -1763, -84, 6}, ++{ 21580, -17815, -7282, -1575, -2078, -320}, ++{ -2233, 10017, -2728, 14938, -13640, -17659}, ++{ -1564, -17738, -19161, 13735, 2757, 2951}, ++{ 4520, 5510, 7393, 10799, 19231, -13770}, ++{ 399, 2976, -1099, 5013, -1159, 22095}, ++{ 3624, -2359, 4680, -2238, 22702, 3765}, ++{ -4201, -8285, -6810, -12390, -18414, 15382}, ++{ -5198, -6869, -10047, -8364, -16022, -20562}, ++{ -142, -22671, -368, 4391, -464, -13}, ++{ 814, -1118, -1089, -22019, 74, 1553}, ++{ -1618, 19222, -17642, -13490, 842, -2309}, ++{ 4689, 16490, 20813, -15387, -4164, -3968}, ++{ -3308, 11214, -13542, 13599, -19473, 13770}, ++{ 1817, 854, 21225, -966, -1643, -268}, ++{ -2587, -107, -20154, 376, 1174, -304}, ++{ -2919, 453, -5390, 750, -22034, -978}, ++{ -19012, 16839, 10000, -3580, 2211, 1459}, ++{ 1363, -2658, -33, -4067, 1165, -21985}, ++{ -8592, -2760, -17520, -15985, 14897, 1323}, ++{ 652, -9331, 3253, -14622, 12181, 19692}, ++{ -6361, 5773, -15395, 17291, 16590, -2922}, ++{ -661, -601, 1609, 22610, 992, -1045}, ++{ 4961, 9107, 11225, 7829, 16320, 18627}, ++{ -21872, -1433, 138, 1470, -1891, -196}, ++{ -19499, -18203, 11056, -516, 2543, -2249}, ++{ -1196, -17574, 20150, 11462, -401, 2619}, ++{ 4638, -8154, 11891, -15759, 17615, -14955}, ++{ -83, 278, 323, 55, -154, 232}, ++{ 7788, 1462, 18395, 15296, -15763, -1131}, ++}; ++static const int16_t vq_hebap5[128][6] = { ++{ -3394, -19730, 2963, 9590, 4660, 19673}, ++{ -15665, -6405, 17671, 3860, -8232, -19429}, ++{ 4467, 412, -17873, -8037, 691, -17307}, ++{ 3580, 2363, 6886, 3763, 6379, -20522}, ++{ -17230, -14133, -1396, -23939, 8373, -12537}, ++{ -8073, -21469, -15638, 3214, 8105, -5965}, ++{ 4343, 5169, 2683, -16822, -5146, -16558}, ++{ 6348, -10668, 12995, -25500, -22090, 4091}, ++{ -2880, -8366, -5968, -17158, -2638, 23132}, ++{ -5095, -14281, -22371, 21741, 3689, 2961}, ++{ -2443, -17739, 25155, 2707, 1594, 7}, ++{ -18379, 9010, 4270, 731, -426, -640}, ++{ -23695, 24732, 5642, 612, -308, -964}, ++{ -767, 1268, 225, 1635, 173, 916}, ++{ 5455, 6493, 4902, 10560, 23041, -17140}, ++{ 17219, -21054, -18716, 4936, -3420, 3357}, ++{ -1390, 15488, -21946, -14611, 1339, 542}, ++{ -6866, -2254, -12070, -3075, -19981, -20622}, ++{ -1803, 11775, 1343, 8917, 693, 24497}, ++{ -21610, 9462, 4681, 9254, -7815, 15904}, ++{ -5559, -3018, -9169, -1347, -22547, 12868}, ++{ -366, 5076, -1727, 20427, -283, -2923}, ++{ -1886, -6313, -939, -2081, -1399, 3513}, ++{ -3161, -537, -5075, 11268, 19396, 989}, ++{ 2345, 4153, 5769, -4273, 233, -399}, ++{ -21894, -1138, -16474, 5902, 5488, -3211}, ++{ 10007, -12530, 18829, 20932, -1158, 1790}, ++{ -1165, 5014, -1199, 6415, -8418, -21038}, ++{ 1892, -3534, 3815, -5846, 16427, 20288}, ++{ -2664, -11627, -4147, -18311, -22710, 14848}, ++{ 17256, 10419, 7764, 12040, 18956, 2525}, ++{ -21419, -18685, -10897, 4368, -7051, 4539}, ++{ -1574, 2050, 5760, 24756, 15983, 17678}, ++{ -538, -22867, 11067, 10301, 385, 528}, ++{ -8465, -3025, -16357, -23237, 16491, 3654}, ++{ 5840, 575, 11890, 1947, 25157, 6653}, ++{ 6625, -3516, -1964, 3850, -390, -116}, ++{ 18005, 20900, 14323, -7621, -10922, 11802}, ++{ -4857, -2932, -13334, -7815, 21622, 2267}, ++{ -579, -9431, -748, -21321, 12367, 8265}, ++{ -8317, 1375, -17847, 2921, 9062, 22046}, ++{ 18398, 8635, -1503, -2418, -18295, -14734}, ++{ -2987, 15129, -3331, 22300, 13878, -13639}, ++{ 5874, -19026, 15587, 11350, -20738, 1971}, ++{ 1581, -6955, -21440, 2455, 65, 414}, ++{ 515, -4468, -665, -4672, 125, -19222}, ++{ 21495, -20301, -1872, -1926, -211, -1022}, ++{ 5189, -12250, -1775, -23550, -4546, 5813}, ++{ 321, -6331, 14646, 6975, -1773, 867}, ++{ -13814, 3180, 7927, 444, 19552, 3146}, ++{ -6660, 12252, -1972, 17408, -24280, -12956}, ++{ -745, 14356, -1107, 23742, -9631, -18344}, ++{ 18284, -7909, -7531, 19118, 7721, -12659}, ++{ 1926, 15101, -12848, 2153, 21631, 1864}, ++{ -2130, 23416, 17056, -15597, -1544, 87}, ++{ 8314, -11824, 14581, -20591, 7891, -2099}, ++{ 19600, 22814, -17304, -2040, 285, -3863}, ++{ -8214, -18322, 10724, -13744, -13469, -1666}, ++{ 14351, 4880, -20034, 964, -4221, -180}, ++{ -24598, -16635, 19724, 5925, 4777, 4414}, ++{ -2495, 23493, -16141, 2918, -1038, -2010}, ++{ 18974, -2540, 13343, 1405, -6194, -1136}, ++{ 2489, 13670, 22638, -7311, -129, -2792}, ++{ -13962, 16775, 23012, 728, 3397, 162}, ++{ 3038, 993, 8774, -21969, -6609, 910}, ++{ -12444, -22386, -2626, -5295, 19520, 9872}, ++{ -1911, -18274, -18506, -14962, 4760, 7119}, ++{ 8298, -2978, 25886, 7660, -7897, 1020}, ++{ 6132, 15127, 18757, -24370, -6529, -6627}, ++{ 7924, 12125, -9459, -23962, 5502, 937}, ++{ -17056, -5373, 2522, 327, 1129, -390}, ++{ 15774, 19955, -10380, 11172, -3107, 14853}, ++{ -11904, -8091, -17928, -22287, -17237, -6803}, ++{ -12862, -2172, -6509, 5927, 12458, -22355}, ++{ -497, 322, 1038, -6643, -5404, 20311}, ++{ 1083, -22984, -8494, 12130, -762, 2623}, ++{ 5067, 19712, -1901, -30, -325, 85}, ++{ 987, -5830, 4212, -9030, 9121, -25038}, ++{ -7868, 7284, -12292, 12914, -21592, 20941}, ++{ -1630, -7694, -2187, -8525, -5604, -25196}, ++{ -6668, 388, -22535, 1526, 9082, 193}, ++{ -7867, -22308, 5163, 362, 944, -259}, ++{ 3824, -11850, 7591, -23176, 25342, 23771}, ++{ -10504, 4123, -21111, 21173, 22439, -838}, ++{ -4723, 21795, 6184, -122, 1642, -717}, ++{ 24504, 19887, -2043, 986, 7, -55}, ++{ -27313, -135, 2437, 259, 89, 307}, ++{ 24446, -3873, -5391, -820, -2387, 361}, ++{ 5529, 5784, 18682, 242, -21896, -4003}, ++{ 22304, 4483, 722, -12242, 7570, 15448}, ++{ 8673, 3009, 20437, 21108, -21100, -3080}, ++{ -1132, 2705, -1825, 5420, -785, 18532}, ++{ 16932, -13517, -16509, -14858, -20327, -14221}, ++{ 2219, 1380, 21474, -1128, 327, 83}, ++{ -2177, 21517, -3856, -14180, -204, -2191}, ++{ 953, -9426, 15874, -10710, -3231, 21030}, ++{ -421, -1377, 640, -8239, -20976, 2174}, ++{ 4309, 18514, -9100, -18319, -15518, 3704}, ++{ -5943, 449, -8387, 1075, -22210, -4992}, ++{ 2953, 12788, 18285, 1430, 14937, 21731}, ++{ -2913, 401, -4739, -20105, 1699, -1147}, ++{ 3449, 5241, 8853, 22134, -7547, 1451}, ++{ -2154, 8584, 18120, -15614, 19319, -5991}, ++{ 3501, 2841, 5897, 6397, 8630, 23018}, ++{ 2467, 2956, 379, 5703, -22047, -2189}, ++{ -16963, -594, 18822, -5295, 1640, 774}, ++{ 2896, -1424, 3586, -2292, 19910, -1822}, ++{ -18575, 21219, -14001, -12573, 16466, 635}, ++{ -1998, -19314, -16527, 12208, -16576, -7854}, ++{ -9674, 1012, -21645, 2883, -12712, 2321}, ++{ -1005, 471, -3629, 8045, -11087, 25533}, ++{ 4141, -21472, -2673, 756, -663, -523}, ++{ 6490, 8531, 19289, 18949, 6092, -9347}, ++{ 16965, 24599, 14024, 10072, -536, -10438}, ++{ -8147, 2145, -23028, -17073, 5451, -4401}, ++{ -14873, 20520, -18303, -9717, -11885, -17831}, ++{ -2290, -14120, 2070, 22467, 1671, 725}, ++{ -8538, 14629, 3521, -20577, 6673, 8200}, ++{ 20248, 4410, -1366, -585, 1229, -2449}, ++{ 7467, -7148, 13667, -8246, 22392, -17320}, ++{ -1932, 3875, -9064, -3812, 958, 265}, ++{ -4399, 2959, -15911, 19598, 4954, -1105}, ++{ 18009, -9923, -18137, -3862, 11178, 5821}, ++{ -14596, -1227, 9660, 21619, 11228, -11721}, ++{ -721, -1700, 109, -2142, 61, -6772}, ++{ -24619, -22520, 5608, -1957, -1761, -1012}, ++{ -23728, -4451, -2688, -14679, -4266, 9919}, ++{ 8495, -894, 20438, -13820, -17267, 139}, ++}; ++static const int16_t vq_hebap6[256][6] = { ++{ 10154, 7365, 16861, 18681, -22893, -3636}, ++{ -2619, -3788, -5529, -5192, -9009, -20298}, ++{ -5583, -22800, 21297, 7012, 745, 720}, ++{ 428, -1459, 109, -3082, 361, -8403}, ++{ 8161, 22401, 241, 1755, -874, -2824}, ++{ 1140, 12643, 2306, 22263, -25146, -17557}, ++{ -2609, 3379, 10337, -19730, -15468, -23944}, ++{ -4040, -12796, -25772, 13096, 3905, 1315}, ++{ 4624, -23799, 13608, 25317, -1175, 2173}, ++{ -97, 13747, -5122, 23255, 4214, -22145}, ++{ 6878, -322, 18264, -854, -11916, -733}, ++{ 17280, -12669, -9693, 23563, -16240, -1309}, ++{ 5802, -4968, 19526, -21194, -24622, -183}, ++{ 5851, -16137, 15229, -9496, -1538, 377}, ++{ 14096, 25057, 13419, 8290, 23320, 16818}, ++{ -7261, 118, -15867, 19097, 9781, -277}, ++{ -4288, 21589, -13288, -16259, 16633, -4862}, ++{ 4909, -19217, 23411, 14705, -722, 125}, ++{ 19462, -4732, -1928, -11527, 20770, 5425}, ++{ -27562, -2881, -4331, 384, -2103, 1367}, ++{ -266, -9175, 5441, 26333, -1924, 4221}, ++{ -2970, -20170, -21816, 5450, -7426, 5344}, ++{ -221, -6696, 603, -9140, 1308, -27506}, ++{ 9621, -8380, -1967, 9403, -1651, 22817}, ++{ 7566, -5250, -4165, 1385, -990, 560}, ++{ -1262, 24738, -19057, 10741, 7585, -7098}, ++{ 451, 20130, -9949, -6015, -2188, -1458}, ++{ 22249, 9380, 9096, 10959, -2365, -3724}, ++{ 18668, -650, -1234, 11092, 7678, 5969}, ++{ 19207, -1485, -1076, -731, -684, 43}, ++{ -4973, 13430, 20139, 60, 476, -935}, ++{ -20029, 8710, 2499, 1016, -1158, 335}, ++{ -26413, 18598, -2201, -669, 3409, 793}, ++{ -4726, 8875, -24607, -9646, 3643, -283}, ++{ 13303, -21404, -3691, -1184, -1970, 1612}, ++{ 173, 60, 919, 1229, 6942, -665}, ++{ 16377, 16991, 5341, -14015, -2304, -20390}, ++{ 25334, -10609, 11947, -7653, -6363, 14058}, ++{ 23929, -13259, -7226, -937, 234, -187}, ++{ 6311, -1877, 12506, -1879, 18751, -23341}, ++{ 621, 6445, 3354, -24274, 8406, 5315}, ++{ -3297, -5034, -4704, -5080, -25730, 5347}, ++{ -1275, -13295, -965, -23318, 1214, 26259}, ++{ -6252, 10035, -20105, 15301, -16073, 5136}, ++{ 9562, -3911, -19510, 4745, 22270, -4171}, ++{ 7978, -19600, 14024, -5745, -20855, 8939}, ++{ 7, -4039, 991, -6065, 52, -19423}, ++{ 3485, 2969, 7732, 7786, 25312, 6206}, ++{ -959, -12812, -1840, -22743, 7324, 10830}, ++{ -4686, 1678, -10172, -5205, 4294, -1271}, ++{ 3889, 1302, 7450, 638, 20374, -3133}, ++{ -12496, -9123, 18463, -12343, -7238, 18552}, ++{ -6185, 8649, -6903, -895, 17109, 16604}, ++{ -9896, 28579, 2845, 1640, 2925, -298}, ++{ 14968, -25988, 14878, -24012, 1815, -6474}, ++{ 26107, 5166, 21225, 15873, 21617, 14825}, ++{ -21684, 16438, 20504, -14346, -7114, -4162}, ++{ 28647, 90, -1572, 789, -902, -75}, ++{ -1479, 2471, -4061, 3612, -2240, 10914}, ++{ 8616, 17491, 17255, -17456, 17022, -16357}, ++{ -20722, -18597, 25274, 17720, -3573, 1695}, ++{ -997, 6129, -6303, 11250, -11359, -19739}, ++{ -74, -4001, -1584, 13384, 162, -144}, ++{ -529, 21068, 7923, -11396, 422, -26}, ++{ 7102, -13531, -20055, 2629, -178, -429}, ++{ 9201, 1368, -22238, 2623, -20499, 24889}, ++{ -432, 6675, -266, 8723, 80, 28024}, ++{ 19493, -3108, -9261, 1910, -21777, 5345}, ++{ 14079, -11489, 12604, 6079, 19877, 1315}, ++{ 10947, 9837, -18612, 15742, 4792, 605}, ++{ -1777, 3758, -4087, 21696, 6024, -576}, ++{ 3567, -3578, 16379, 2680, -1752, 716}, ++{ -5049, -1399, -4550, -652, -17721, -3366}, ++{ -3635, -4372, -6522, -22152, 7382, 1458}, ++{ 12242, 19190, 5646, -7815, -20289, 21344}, ++{ -7508, 19952, 23542, -9753, 5669, -1990}, ++{ -2275, 15438, 10907, -17879, 6497, 13582}, ++{ -15894, -15646, -4716, 6019, 24250, -6179}, ++{ -2049, -6856, -1208, 918, 17735, -69}, ++{ -3721, 9099, -16065, -23621, 5981, -2344}, ++{ 7862, -8918, 24033, 25508, -11033, -741}, ++{ -12588, 19468, 14649, 15451, -21226, 1171}, ++{ 2102, 1147, 2789, 4096, 2179, 8750}, ++{ -18214, -17758, -10366, -5203, -1066, -3541}, ++{ -2819, -19958, -11921, 6032, 8315, 10374}, ++{ -9078, -2100, 19431, -17, 732, -689}, ++{ -14512, -19224, -7095, 18727, 1870, 22906}, ++{ 3912, 659, 25597, -4006, 9619, 877}, ++{ 2616, 22695, -5770, 17920, 3812, 20220}, ++{ 2561, 26847, -5245, -10908, 2256, -517}, ++{ -4974, 198, -21983, -3608, 22174, -18924}, ++{ 21308, -1211, 19144, 16691, -1588, 11390}, ++{ -1790, 3959, -3488, 7003, -7107, 20877}, ++{ -6108, -17955, -18722, 24763, 16508, 3211}, ++{ 20462, -24987, -20361, 4484, -5111, -478}, ++{ -6378, -1998, -10229, -561, -22039, -22339}, ++{ 3047, -18850, 7586, 14743, -19862, 6351}, ++{ -5047, 1405, -9672, 1055, -21881, 11170}, ++{ 3481, -9699, 6526, -16655, 22813, 21907}, ++{ -18570, 17501, 14664, 1291, 5026, 19676}, ++{ 16134, -19810, -16956, -17939, -16933, 5800}, ++{ -8224, 4908, 8935, 2272, -1140, -23217}, ++{ 1572, 2753, -1598, 2143, -3346, -21926}, ++{ -9832, -1060, -27818, 1214, 7289, 150}, ++{ 98, 1538, 535, 17429, -23198, -901}, ++{ 21340, -20146, 3297, -1744, -8207, -21462}, ++{ -4166, -4633, -17902, 5478, 1285, 136}, ++{ 18713, 21003, 24818, 11421, 1282, -4618}, ++{ -3535, 7636, -265, 2141, -829, -2035}, ++{ -3184, 19713, 2775, -2, 1090, 104}, ++{ -6771, -20185, 2938, -2125, -36, 1268}, ++{ 9560, 9430, 9586, 22100, 13827, 6296}, ++{ -535, -20018, 4276, -1868, -448, -17183}, ++{ -24352, 14244, -13647, -21040, 2271, 11555}, ++{ -2646, 15437, -4589, 18638, -4299, -622}, ++{ -20064, 4169, 18115, -1404, 13722, -1825}, ++{ -16359, 9080, 744, 22021, 125, 10794}, ++{ 9644, -14607, -18479, -14714, 11174, -20754}, ++{ -326, -23762, 6144, 7909, 602, 1540}, ++{ -6650, 6634, -12683, 21396, 20785, -6839}, ++{ 4252, -21043, 5628, 18687, 23860, 8328}, ++{ 17986, 5704, -5245, -18093, -555, 3219}, ++{ 6091, 14232, -5117, -17456, -19452, -11649}, ++{ -21586, 11302, 15434, 25590, 6777, -26683}, ++{ 21355, -8244, 5877, -3540, 6079, -2567}, ++{ 2603, -2455, 5421, -12286, -19100, 5574}, ++{ -1721, -26393, -23664, 22904, -349, 3787}, ++{ 2189, -1203, 5340, 3249, -22617, 104}, ++{ -1664, -11020, -2857, -20723, -24049, 19900}, ++{ 22873, -7345, -18481, -14616, -8400, -12965}, ++{ 3777, 3958, 8239, 20494, -6991, -1201}, ++{ -160, -1613, -793, -8681, 573, 776}, ++{ 4297, -3786, 20373, 6082, -5321, -18400}, ++{ 18745, 2463, 12546, -7749, -7734, -2183}, ++{ 11074, -4720, 22119, 1825, -24351, 4080}, ++{ 1503, -19178, -1569, 13, -313, 375}, ++{ 318, -575, 2544, 178, 102, 40}, ++{ -15996, -26897, 5008, 3320, 686, 1159}, ++{ 25755, 26886, 574, -5930, -3916, 1407}, ++{ -9148, -7665, -2875, -8384, -18663, 26400}, ++{ -7445, -18040, -18396, 8802, -2252, -21886}, ++{ 7851, 11773, 27485, -12847, -1410, 19590}, ++{ 2240, 5947, 11247, 15980, -6499, 24280}, ++{ 21673, -18515, 9771, 6550, -2730, 334}, ++{ -4149, 1576, -11010, 89, -24429, -5710}, ++{ 7720, 1478, 21412, -25025, -8385, 9}, ++{ -2448, 10218, -12756, -16079, 1161, -21284}, ++{ -8757, -14429, -22918, -14812, 2629, 13844}, ++{ -7252, 2843, -9639, 2882, -14625, 24497}, ++{ -674, -6530, 414, -23333, -21343, 454}, ++{ 2104, -6312, 10887, 18087, -1199, 175}, ++{ -493, -562, -2739, 118, -1074, 93}, ++{ -10011, -4075, -28071, 22180, 15077, -636}, ++{ -4637, -16408, -9003, -20418, -11608, -20932}, ++{ 4815, 15892, 24238, -13634, -3074, -1059}, ++{ -6724, 4610, -18772, -15283, -16685, 23988}, ++{ 15349, -674, -3682, 21679, 4475, -12088}, ++{ 4756, 2593, 5354, 6001, 15063, 26490}, ++{ -23815, -17251, 6944, 378, 694, 670}, ++{ 23392, -8839, -14713, 7544, -876, 11088}, ++{ 3640, 3336, 22593, -3495, -2328, -113}, ++{ 284, 6914, 3097, 10171, 6638, -18621}, ++{ 2472, 5976, 11054, -11936, -603, -663}, ++{ 16175, 16441, 13164, -4043, 4667, 7431}, ++{ 19338, 15534, -6533, 1681, -4857, 17048}, ++{ 17027, 532, -19064, -1441, -5130, 1085}, ++{ -12617, -17609, 2062, -25332, 19009, -16121}, ++{ 10056, -21000, -13634, -2949, 15367, 19934}, ++{ -648, -1605, 10046, -1592, 13296, 19808}, ++{ -1054, 10744, 538, 24938, 9630, -9052}, ++{ -10099, 3042, -25076, -24052, 13971, 100}, ++{ 6547, 6907, 7031, 10348, 23775, -17886}, ++{ -22793, -1984, -1393, -3330, 9267, 14317}, ++{ -14346, -3967, 3042, 16254, -17303, 9646}, ++{ -21393, 23628, 16773, 716, 2663, 114}, ++{ -19016, -3038, 1574, -245, 1463, -793}, ++{ 22410, 23441, -14637, -530, 17310, 13617}, ++{ -11582, 7935, -13954, 23465, -24628, 26550}, ++{ -1045, 3679, -2218, 10572, 20999, -3702}, ++{ -15513, 197, 16718, -24603, 4945, 5}, ++{ 10781, 4335, 26790, -9059, -16152, -2840}, ++{ 16075, -24100, -3933, -6833, 12645, -7029}, ++{ 2096, -25572, -8370, 6814, 11, 1178}, ++{ -11848, -583, -8889, -20543, -10471, -380}, ++{ -2487, 24777, -21639, -19341, 1660, -732}, ++{ 2313, 13679, 4085, 24549, 24691, -21179}, ++{ -2366, -504, -4130, -10570, 23668, 1961}, ++{ 20379, 17809, -9506, 3733, -18954, -6292}, ++{ -3856, 16802, -929, -20310, -17739, 6797}, ++{ 12431, 6078, -11272, -14450, 6913, 23476}, ++{ 7636, -1655, 23017, 10719, -8292, 838}, ++{ -8559, -1235, -18096, 3897, 16093, 1490}, ++{ -3586, 8276, 15165, -3791, -21149, 1741}, ++{ -4497, 21739, 2366, -278, -4792, 15549}, ++{ -23122, -13708, 7668, 16232, 24120, 15025}, ++{ -20043, 12821, -20160, 16691, -11655, -16081}, ++{ -12601, 20239, 3496, -2549, -6745, -11850}, ++{ 4441, 7812, 20783, 17080, 11523, -9643}, ++{ 24766, 8494, -23298, -3262, 11101, -7120}, ++{ -10107, -7623, -22152, -18303, 26645, 9550}, ++{ -25549, 477, 7874, -1538, 1123, -168}, ++{ 470, 9834, -347, 23945, -10381, -9467}, ++{ -4096, -9702, -6856, -21544, 20845, 7174}, ++{ 5370, 9748, -23765, -1190, 512, -1538}, ++{ -1006, -10046, -12649, 19234, -1790, -890}, ++{ 15108, 23620, -15646, -2522, -1203, -1325}, ++{ -7406, -2605, 1095, -247, -473, 177}, ++{ 8089, 4, 12424, -22284, 10405, -7728}, ++{ 22196, 10775, -5043, 690, 534, -212}, ++{ -3153, -1418, -16835, 18426, 15821, 22956}, ++{ 5681, -2229, 3196, -3414, -21817, -14807}, ++{ 19, 787, 1032, 170, -8295, -645}, ++{ -882, -2319, -27105, 432, -4392, 1499}, ++{ -1354, -11819, -76, -20380, -10293, 11328}, ++{ 211, -4753, -4675, -6933, -13538, 14479}, ++{ 6043, 5260, -459, -462, 143, -65}, ++{ -2572, 7256, -3317, 9212, -23184, -9990}, ++{ -24882, -9532, 18874, 6101, 2429, -14482}, ++{ 8314, 2277, 14192, 3512, 25881, 22000}, ++{ 208, 20218, -281, -24778, -63, -1183}, ++{ 1095, -6034, 2706, -21935, -2655, 563}, ++{ 23, -5930, 243, -8989, 5345, 20558}, ++{ -15466, 12699, 4160, 11087, 20621, -10416}, ++{ 20995, -85, -8468, 194, 1003, -9515}, ++{ -19637, -3335, -14081, 3574, -23381, -667}, ++{ -2076, 3489, -3192, -19367, 539, -1530}, ++{ 7352, -15213, 22596, 19369, 1043, 16627}, ++{ -1872, -413, 1235, -5276, -3550, 21903}, ++{ 7931, -2008, 16968, -6799, 29393, -2475}, ++{ -13589, 8389, -23636, -22091, -14178, -14297}, ++{ -11575, -20090, 16056, -1848, 15721, 4500}, ++{ 3849, -16581, 20161, -21155, 7778, 11864}, ++{ -6547, -1273, -18837, -11218, 11636, 1044}, ++{ 2528, -6691, -17917, -11362, -4894, -1008}, ++{ 1241, 4260, 2319, 6111, 3485, 20209}, ++{ 3014, -3048, 5316, -4539, 20831, 8702}, ++{ -1790, -14683, 278, 13956, -10065, -10547}, ++{ -22732, -7957, -1154, 13821, -1484, -1247}, ++{ -7317, -615, 13094, 18927, 9897, 1452}, ++{ 2552, -2338, 3424, -4630, 11124, -19584}, ++{ -11125, -20553, -10855, -10783, -20767, 6833}, ++{ 984, -15095, 5775, 25125, 5377, -19799}, ++{ 517, 13272, -7458, -1711, 20612, -6013}, ++{ -21417, 13251, -20795, 13449, 17281, 13104}, ++{ -15811, -16248, 23093, -4037, -8195, 871}, ++{ 582, 12571, -21129, -14766, -9187, 5685}, ++{ 4318, -1776, 11425, -17763, -9921, 577}, ++{ 6013, 16830, 17655, -25766, -4400, -3550}, ++{ -13744, -16541, 3636, -3330, -21091, -15886}, ++{ 6565, -11147, 8649, -13114, 23345, -13565}, ++{ -2542, -9046, -7558, 29240, 3701, -383}, ++{ -10612, 24995, 1893, -8210, 20920, -16210}, ++{ 5276, 16726, 10659, 19940, -4799, -19324}, ++{ -532, -9300, 27856, 4965, -241, 536}, ++{ -765, -20706, -3412, 18870, 2765, 1420}, ++{ -3059, 2708, -19022, -331, 3537, 116}, ++}; ++static const int16_t vq_hebap7[512][6] = { ++{ -21173, 21893, 10390, 13646, 10718, -9177}, ++{ -22519, -8193, 18328, -6629, 25518, -10848}, ++{ 6800, -13758, -13278, 22418, 14667, -20938}, ++{ 2347, 10516, 1125, -3455, 5569, 27136}, ++{ -6617, 11851, -24524, 22937, 20362, -6019}, ++{ -21768, 10681, -19615, -15021, -8478, -2081}, ++{ -2745, 8684, -4895, 27739, 7554, -11961}, ++{ -1020, 2460, -954, 4754, -627, -16368}, ++{ -19702, 23097, 75, -13684, -2644, 2108}, ++{ 4049, -2872, 5851, -4459, 22150, 12560}, ++{ -21304, -17129, -730, 7419, -11658, -10523}, ++{ 11332, 1792, 26666, 23518, -19561, -491}, ++{ -17827, -16777, -13606, -14389, -22029, -2464}, ++{ 1091, -5967, -7975, -16977, -20432, -21931}, ++{ 18388, -1103, 1933, 13342, -17463, 18114}, ++{ 22646, 17345, -9966, 17919, 18274, 698}, ++{ 1484, 20297, -5754, -26515, 4941, -22263}, ++{ -2603, 4587, -5842, 18464, 8767, -2568}, ++{ -2797, -1602, 21713, 3099, -25683, 3224}, ++{ -19027, 4693, -5007, 6060, 1972, -15095}, ++{ -2189, 9516, -530, 20669, -4662, -8301}, ++{ -22325, -8887, 2529, -11352, 5476, 998}, ++{ 22100, -5052, 1651, -2657, 4615, 2319}, ++{ 20855, -3078, -3330, 4105, 13470, 3069}, ++{ 85, 17289, 10264, -14752, 214, 90}, ++{ -26365, -18849, -19352, 19244, -10218, 9909}, ++{ -9739, 20497, -6579, -6983, 2891, -738}, ++{ 20575, -15860, -22913, 6870, 76, 327}, ++{ 8744, -12877, -22945, -2372, -19424, -9771}, ++{ -12886, 16183, 21084, 3821, 749, -13792}, ++{ -15995, 18399, 2391, -17661, 19484, -6018}, ++{ 1423, 11734, 4051, 19290, 6857, -19681}, ++{ -5200, 9766, 18246, 2463, 18764, -4852}, ++{ -597, 19498, 1323, -9096, -308, -1104}, ++{ -3099, -25731, -15665, 25332, 4634, 2635}, ++{ 19623, -2384, -7913, 11796, -9333, -14084}, ++{ 2642, 26453, -21091, -10354, -1693, -1711}, ++{ 22031, 21625, 11580, -22915, -4141, 129}, ++{ -6122, 3542, 915, -261, -17, -383}, ++{ 1696, 6704, -1425, 20838, 857, -4416}, ++{ 1423, -15280, -8550, -9667, 5210, 5687}, ++{ -4520, -613, -11683, 5618, 4230, 619}, ++{ 937, -4963, -14102, -17104, -6906, -5952}, ++{ -15068, -481, -7237, -14894, 18876, 21673}, ++{ -25658, 2910, 1143, -327, -458, -995}, ++{ -9656, -819, -24900, 2804, 20225, 1083}, ++{ -1111, -3682, -1788, -19492, 966, 821}, ++{ 7293, -21759, 10790, -7059, -23293, -1723}, ++{ -282, -11093, 170, -20950, -28926, 12615}, ++{ 17938, 3713, -1563, 885, 5, 564}, ++{ 6116, 22696, 2242, -6951, 9975, -6132}, ++{ 4338, 26808, -3705, 1976, -1079, -2570}, ++{ -661, -7901, -2668, -15194, 17722, 4375}, ++{ -4174, -11053, 717, -22506, 1562, 12252}, ++{ -6405, 18334, 6103, 6983, 5956, 18195}, ++{ 9851, 5370, 23604, -6861, -6569, -62}, ++{ 21964, 13359, -683, 3785, 2168, 209}, ++{ -3569, -1127, -19724, -1544, 1308, -803}, ++{ -3083, 16049, -13791, -3077, 4294, 23713}, ++{ -9999, 9943, -15872, 12934, -23631, 21699}, ++{ 9722, 22837, 12192, 15091, 5533, 4837}, ++{ 2243, 2099, 1243, 4089, 4748, 12956}, ++{ 4007, -2468, 3353, -3092, 8843, 17024}, ++{ 4330, 6127, 5549, 9249, 11226, 28592}, ++{ -9586, -8825, 236, 1009, 455, -964}, ++{ 6829, 19290, -1018, 200, 1821, 578}, ++{ 5196, 957, 10372, 3330, -12800, -127}, ++{ -3022, -8193, -14557, 22061, 5920, 1053}, ++{ 10982, 25942, -24546, -23278, -11905, -6789}, ++{ 22667, -11010, 5736, 2567, 23705, -10253}, ++{ -3343, -4233, -5458, 20667, -10843, -3605}, ++{ -4131, -3612, 4575, -829, -350, -847}, ++{ -3303, 3451, -7398, -11604, 3023, 455}, ++{ 3200, -9547, 3202, -22893, 11184, -26466}, ++{ -14093, -4117, 15382, 14295, -10915, -20377}, ++{ 3807, -11016, 22052, 14370, -15328, -7733}, ++{ -6291, -17719, -1560, 12048, -19805, -443}, ++{ -6147, -4234, -160, 8363, 22638, 11911}, ++{ 19197, 1175, 7422, -9875, -4136, 4704}, ++{ -72, -7652, -112, -11955, -3230, 27175}, ++{ 3274, 5963, 7501, -17019, 866, -25452}, ++{ 737, 1861, 1833, 2022, 2384, 4755}, ++{ -5217, 7512, 3323, 2715, 3065, -1606}, ++{ 4247, 565, 5629, 2497, 18019, -4920}, ++{ -2833, -17920, -8062, 15738, -1018, 2136}, ++{ 3050, -19483, 16930, 29835, -10222, 15153}, ++{ -11346, 118, -25796, -13761, 15320, -468}, ++{ -4824, 4960, -4263, 1575, -10593, 19561}, ++{ -8203, -1409, -763, -1139, -607, 1408}, ++{ -2203, -11415, 2021, -6388, -2600, 711}, ++{ -413, -2511, -216, -3519, -28267, 1719}, ++{ -14446, 17050, 13917, 13499, -25762, -16121}, ++{ 19228, 7341, -12301, 682, -3791, -199}, ++{ -4193, 20746, -15651, 11349, 5860, -824}, ++{ -21490, -3546, -3, -1705, -3959, 9213}, ++{ 15445, -1876, 2012, -19627, 16228, -4845}, ++{ -2867, -3733, -7354, -175, -20119, 11174}, ++{ -3571, -24587, 19700, 6654, 979, -654}, ++{ 21820, -7430, -6639, -10767, -8362, 15543}, ++{ 14827, 17977, -7204, -3409, 1906, -17288}, ++{ 3525, -3947, -1415, -2798, 17648, 2082}, ++{ -6580, -15255, -17913, 1337, 15338, 21158}, ++{ 6210, 9698, 15155, -24666, -22507, -3999}, ++{ -1740, -593, 1095, -7779, 25058, 5601}, ++{ 21415, -432, -1658, -6898, -1438, -14454}, ++{ -6943, 700, -12139, -745, -24187, 22466}, ++{ 6287, 3283, 11006, 3844, 19184, 14781}, ++{ -22502, 15274, 5443, -2808, -970, -3343}, ++{ 3257, -3708, 4744, -8301, 22814, -10208}, ++{ 24346, -20970, 19846, 987, -11958, -6277}, ++{ 3906, -19701, 13060, -1609, 18641, 7466}, ++{ -26409, -22549, 16305, 2014, 10975, 18032}, ++{ -7039, 4655, -14818, 18739, 15789, 1296}, ++{ 9310, -1681, 14667, -3326, 26535, -11853}, ++{ 5728, 5917, 13400, 10020, -2236, -24704}, ++{ 1741, -6727, 12695, -22009, 4080, 5450}, ++{ -2621, 9393, 21143, -25938, -3162, -2529}, ++{ 20672, 18894, -13939, 6990, -8260, 15811}, ++{ -23818, 11183, -13639, 11868, 16045, 2630}, ++{ 18361, -10220, 829, 856, -1010, 157}, ++{ 14400, -4678, 5153, -13290, -27434, -11028}, ++{ 21613, 11256, 17453, 7604, 13130, -484}, ++{ 7, 1236, 573, 4214, 5576, -3081}, ++{ 916, -9092, 1285, -8958, 1185, -28699}, ++{ 21587, 23695, 19116, -2885, -14282, -8438}, ++{ 23414, -6161, 12978, 3061, -9351, 2236}, ++{ -3070, -7344, -20140, 5788, 582, -551}, ++{ -3993, 315, -7773, 8224, -28082, -12465}, ++{ 13766, -15357, 19205, -20624, 13043, -19247}, ++{ 3777, -177, 8029, -1001, 17812, 5162}, ++{ -7308, -4327, -18096, -620, -1350, 14932}, ++{ 14756, -1221, -12819, -14922, -547, 27125}, ++{ 2234, 1708, 2764, 5416, 7986, -25163}, ++{ 2873, 3636, 3992, 5344, 10142, 21259}, ++{ 1158, 5379, 508, -10514, 290, -1615}, ++{ 1114, 24789, 16575, -25168, -298, -2832}, ++{ -1107, -6144, -1918, -7791, -2971, -23276}, ++{ 4016, 10793, 17317, -4342, -20982, -3383}, ++{ -4494, -207, -9951, -3575, 7947, 1154}, ++{ -7576, 8117, -14047, 16982, -26457, -27540}, ++{ -15164, 16096, -16844, -8886, -23720, 15906}, ++{ 24922, 5680, -1874, 420, 132, 117}, ++{ -506, -19310, -198, 412, -311, 752}, ++{ -1906, 3981, -7688, 16566, -19291, -14722}, ++{ -399, -729, -3807, -4196, -12395, 7639}, ++{ 3368, 2330, 9092, 23686, -10290, -1705}, ++{ -3148, 2596, -7986, 14602, -4807, 16627}, ++{ 8057, 1481, 49, 17205, 24869, 7474}, ++{ -19304, -513, 11905, 2346, 5588, 3365}, ++{ -5063, -21812, 11370, 10896, 4881, 261}, ++{ 4794, 20577, 5109, -6025, -8049, -1521}, ++{ 8125, -14756, 20639, -14918, 23941, -3650}, ++{ 12451, 1381, 3613, 8687, -24002, 4848}, ++{ 6726, 10643, 10086, 25217, -25159, -1065}, ++{ 6561, 13977, 2911, 21737, 16465, -26050}, ++{ -1776, 2575, -19606, -16800, 3032, 6679}, ++{ 15012, -17910, -8438, -21554, -27111, 11808}, ++{ 3448, -924, -15913, -1135, 5126, -20613}, ++{ 7720, 2226, 17463, 5434, 28942, 17552}, ++{ 1246, 15614, -11743, 24618, -17539, 3272}, ++{ 3215, 17950, 2783, -722, -22672, 5979}, ++{ -5678, -3184, -26087, 26034, 6583, 3302}, ++{ 20310, -3555, -2715, -444, -1487, 1526}, ++{ -20640, -21970, -12207, -25793, 8863, -1036}, ++{ 17888, 570, -16102, 8329, -2553, 15275}, ++{ -2677, 9950, -1879, 16477, -12762, -29007}, ++{ -120, -2221, 219, 97, 365, 35}, ++{ 1270, -718, 1480, -2689, 1930, -7527}, ++{ 1896, 8750, 1906, 18235, -12692, -6174}, ++{ -3733, 13713, -9882, -15960, -1376, -7146}, ++{ -10600, 8496, 15967, -8792, 7532, 20439}, ++{ 3041, -13457, 1032, -26952, 5787, 24984}, ++{ -4590, -8220, -9322, -6112, -17243, 25745}, ++{ -17808, 6970, 3752, 626, -114, 2178}, ++{ 4449, -4862, 7054, -5404, 4738, -2827}, ++{ 4922, -651, 18939, -9866, 848, 1886}, ++{ -336, -5410, 7234, 20444, -9583, -600}, ++{ 781, -19474, -12648, 6634, 1414, 450}, ++{ -3399, -16770, 11107, 13200, -5498, 21663}, ++{ -3265, 4859, -5961, 7530, -10837, 28086}, ++{ 10350, -12901, 25699, 25640, -639, 351}, ++{ 1163, 18763, -5466, -15087, -145, -1377}, ++{ -14477, 27229, -31383, -32653, 21439, -2894}, ++{ 15420, 18823, 22128, 19398, 22583, 13587}, ++{ -10674, 10710, 5089, -4756, 909, -20760}, ++{ -12948, -20660, 7410, 2722, 3427, 11585}, ++{ -1105, 18374, 19731, -9650, 22442, 19634}, ++{ -296, -6798, -14677, 21603, 19796, 21399}, ++{ -19350, -7501, 25446, 13144, 8588, -25298}, ++{ 3092, -10618, 20896, 9249, -3326, 1796}, ++{ -811, 1449, 3106, 4748, 12073, -14262}, ++{ -20720, 14275, -4332, -25838, -5781, -21149}, ++{ -5132, 10554, -14020, -22150, 2840, -554}, ++{ 25533, 17648, 14886, -21074, 2459, 25142}, ++{ -9370, -1788, -12862, -5870, -25811, -11023}, ++{ 6698, 819, 10313, 166, 27581, 523}, ++{ 101, -19388, 3413, 9638, 64, 806}, ++{ -2742, -17931, -2576, 22818, 8553, 1126}, ++{ 2972, 15203, 1792, 25434, -5728, -17265}, ++{ -1419, 1604, 4398, 11452, 1731, 23787}, ++{ -5136, 4625, -10653, 27981, 9897, -2510}, ++{ -10528, -28033, 2999, -1530, -832, -830}, ++{ -11133, -12511, 22206, -7243, -23578, -21698}, ++{ 16935, -21892, 1861, -9606, 9432, 19026}, ++{ 10277, 9516, 26815, 2010, -4943, -9080}, ++{ 5547, -2210, 14270, -15300, -19316, 1822}, ++{ -4850, -783, -8959, -3076, -20056, -3197}, ++{ 8232, -2794, -17752, 13308, 3229, -991}, ++{ -12237, -6581, 10315, -9552, 2260, -20648}, ++{ -7000, 5529, -7553, -7490, -10342, -10266}, ++{ 3641, 19479, -5972, -19097, -18570, 12805}, ++{ 1283, -4164, 4198, -28473, -2498, 1866}, ++{ 16047, 26826, -13053, -6316, 985, -1597}, ++{ -403, 13680, 6457, 25070, 27124, -20710}, ++{ -18070, -1790, -24986, 5953, -954, 26600}, ++{ -24224, -15383, 24788, 1953, -1136, 187}, ++{ -2289, 12505, -20738, -904, 18324, 21258}, ++{ 2658, -6140, 16179, 22276, -556, 2154}, ++{ -6087, 13950, -25682, -27713, 4049, -4795}, ++{ -21452, 26473, 19435, -9124, 895, 303}, ++{ -22200, -26177, -6026, 24729, -22926, -9030}, ++{ -14276, -15982, 23732, -22851, 9268, -3841}, ++{ 29482, 21923, -6213, 1679, -2059, -1120}, ++{ -435, 9802, -3891, 12359, -4288, -18971}, ++{ 19768, -86, 2467, 1990, -1021, -5354}, ++{ 20986, -8783, -5329, -23562, -4730, 2673}, ++{ -5095, 5605, -4629, 19150, 26037, -12259}, ++{ 972, 6858, 4551, 27949, -4025, -2272}, ++{ 6075, -3260, -4989, -373, -1571, -3730}, ++{ -7256, -12992, -8820, -5109, 23054, 5054}, ++{ 920, 2615, 7912, -7353, -4905, 20186}, ++{ -250, 5454, 3140, 6928, -18723, -2051}, ++{ -10299, -4372, 19608, 4879, -661, -1885}, ++{ 14816, -8603, -19815, 6135, -21210, 14108}, ++{ -11945, -2223, 5018, 11892, 22741, 406}, ++{ -13184, -2613, -13256, -22433, -12482, -8380}, ++{ 17066, 25267, -2273, 5056, -342, 145}, ++{ 8401, -17683, 19112, 10615, -19453, 17083}, ++{ 20821, -5700, 12298, -25598, 10391, 7692}, ++{ 4550, 15779, 17338, -19379, -4768, 1206}, ++{ -7723, 10836, -27164, -11439, 6835, -1776}, ++{ 2542, 3199, 4442, 17513, -3711, -914}, ++{ 20960, -16774, -5814, 11087, -70, 22961}, ++{ 3305, 2919, 6256, -4800, -20966, -3230}, ++{ 5924, -16547, 2183, 2733, 3446, -23306}, ++{ -6061, -194, -13852, -10971, 19488, 1029}, ++{ 4467, -5964, -19004, 1519, -359, 855}, ++{ -1581, -7607, 22070, -11580, -10032, 17102}, ++{ -12412, 2553, 4324, 22500, 5751, 12170}, ++{ -25127, 17996, -6384, 1180, 1182, 9622}, ++{ 23462, -8471, -4392, -2669, 7638, -16835}, ++{ -5511, -2887, -10757, -20883, 7246, 1053}, ++{ 2703, -20602, -7554, 7516, -7740, 5868}, ++{ 20670, 21901, 457, 14969, -17657, -11921}, ++{ 3603, -1595, -2177, -157, -43, 605}, ++{ 2513, 8954, 10527, 22559, -16100, -16041}, ++{ 6002, 4951, 6795, -4862, -22400, 18849}, ++{ 7590, -1693, -24688, -3404, 14169, 1214}, ++{ -4398, -6663, -6870, -10083, -24596, 9253}, ++{ 10468, 17751, -7748, 147, -6314, 4419}, ++{ 16187, -16557, -4119, 4302, 7625, 5409}, ++{ 3303, 2735, 7458, -19902, -2254, -3702}, ++{ -2077, 21609, 14870, 12545, -6081, -1764}, ++{ 4678, 11740, 2859, 6953, 1919, -3871}, ++{ 3522, -21853, -2469, -10453, 18893, -10742}, ++{ 3759, -10191, -4866, -2659, -17831, -1242}, ++{ 14991, 9351, 11870, -1573, -4848, 22549}, ++{ 9509, -27152, 10734, 20851, -26185, -17878}, ++{ -7170, -1392, -19495, 12746, 8198, -1988}, ++{ 1883, 28158, -846, -7235, 249, 233}, ++{ -7200, 669, -371, -2948, 23234, -5635}, ++{ 3141, 288, 3223, -1258, -98, -27607}, ++{ 17373, -23235, 5110, -11199, -2574, -11487}, ++{ -4928, 1518, -5456, 670, -18278, 1951}, ++{ 10334, -19865, -4649, 361, -160, -923}, ++{ 18732, 14264, -3155, -7485, -3328, 5959}, ++{ -3614, 21077, 7276, 3536, 8121, -1528}, ++{ -8422, 500, -19182, 18929, 26392, -1039}, ++{ 15639, 25668, 8375, 1903, 1945, -11979}, ++{ -2716, 3389, 26850, -4587, 1803, 22}, ++{ 1177, -655, 1233, -2128, 7844, 1767}, ++{ -761, 8209, -19290, -4593, 1923, -343}, ++{ -689, -3530, -3267, -3804, -2753, 18566}, ++{ -2110, 1962, -1353, 16643, 2765, -23102}, ++{ -433, 4905, 302, 13016, 15933, -5905}, ++{ 3203, 4126, 11181, -5496, -2529, -1160}, ++{ -1091, -6469, -1415, 5682, -268, 583}, ++{ -9405, -19572, 6216, 1658, 993, -75}, ++{ -1695, -4504, -2289, -4088, -6556, -16577}, ++{ 4760, -892, -10902, 6516, 24199, -6011}, ++{ -253, 1000, 63, -81, -115, -382}, ++{ -1333, 24224, -698, -4667, -2801, -19144}, ++{ -876, -28866, -21873, 12677, -6344, 3235}, ++{ 16847, 21145, -26172, -3183, -396, 230}, ++{ 18296, -7790, -12857, -679, -1473, 5}, ++{ -10488, 11429, 25805, -1122, 1401, -438}, ++{ 3782, -7429, 26720, 17567, 19257, 12542}, ++{ 6332, -746, 12789, 9316, -22542, -5354}, ++{ 3418, -22728, 26978, 18303, 1076, 956}, ++{ -27315, -2988, 920, 235, 2233, 81}, ++{ 6199, 5296, 16093, 14768, -8429, -1112}, ++{ -6432, 19244, 9921, -3253, 1278, -954}, ++{ 24213, 2049, -22931, 2585, -2410, -4216}, ++{ 9286, 14282, -19735, -3985, -2344, 1028}, ++{ -20128, 17993, -9458, 23012, -16983, 8625}, ++{ -6896, -20730, 3762, 17415, 22341, 19024}, ++{ 842, 24181, 25062, -5839, -78, 937}, ++{ -621, 19722, -24204, -1962, -14854, -56}, ++{ 22766, -5119, 17365, 23868, -19480, -6558}, ++{ -2158, 17490, -21435, 3340, -12819, -20295}, ++{ -9621, 17325, 715, 2265, -4123, -492}, ++{ 9156, 12947, 27303, -21175, -6072, -9457}, ++{ -13164, -23269, -14006, -4184, 6978, 2}, ++{ 938, -13381, 3520, -24297, 22902, 19589}, ++{ -4911, -19774, 19764, -9310, -12650, 3819}, ++{ -5462, -4249, -6987, -6260, -13943, -25150}, ++{ 9341, 10369, -13862, -6704, 22556, -519}, ++{ 6651, 18768, -4855, 12570, 14730, -10209}, ++{ -823, 18119, 398, -1582, -116, -363}, ++{ -6935, -12694, -28392, 8552, 6961, -239}, ++{ -2602, -4704, -1021, 2015, 5129, 23670}, ++{ -12559, -8190, -25028, 18544, 14179, 1663}, ++{ 3813, 21036, -9620, -5051, -1800, -1087}, ++{ -22057, 16675, 14960, 9459, 2786, 16991}, ++{ -26040, -19318, -6414, 1104, 5798, -18039}, ++{ -1737, 24825, 10417, -11087, 896, -5273}, ++{ -1855, 11661, -2803, 24809, -21435, -19792}, ++{ -23473, -16729, -5782, 5643, 2636, 4940}, ++{ -1724, 4388, -26673, -13695, 10570, -25895}, ++{ 15358, -19496, 26242, -18493, 1736, 8054}, ++{ 5684, 20890, 4091, -19100, -14588, -10468}, ++{ 17260, -16291, 14859, -17711, -19174, 12435}, ++{ -27185, -12573, 6743, -562, 976, -257}, ++{ 12395, -8618, -22248, -19843, 11013, 7762}, ++{ 3799, 11853, -27622, -8473, 1089, -1495}, ++{ 4141, -2182, -26720, -735, -774, 1469}, ++{ 3125, 13762, 4606, 29257, 18771, -9958}, ++{ -17465, -9445, -17562, -2530, -6435, -3726}, ++{ -1742, 4351, -6841, -19773, 9627, -10654}, ++{ 7251, 3525, 10835, 5601, 25198, -23348}, ++{ -10300, -17830, 631, 11640, 2044, -20878}, ++{ -873, -8502, -1063, -15674, -10693, 14934}, ++{ -15957, 28137, 5268, 477, -1053, 1158}, ++{ -1495, -8814, -5764, -24965, 25988, 7907}, ++{ -1038, -114, -2308, -1319, -6480, 1472}, ++{ 4895, -17897, -25850, 5301, -188, 1581}, ++{ 3200, 17225, 4346, 22101, -18543, 22028}, ++{ -10250, 545, -10932, 2276, -28070, 8118}, ++{ 15343, 2329, 9316, 20537, 14908, 21021}, ++{ 6329, 6130, -24508, 837, -8637, -5844}, ++{ 7386, -501, 10503, 20131, 11435, -4755}, ++{ -2745, 24174, -9274, 15273, -8389, -5835}, ++{ 2992, -2864, 6048, -7473, 11687, -19996}, ++{ -883, -11954, -9976, -21829, -4436, -27178}, ++{ 3458, 19626, 1280, 2597, 19849, 5255}, ++{ -5315, 19133, -14518, -8946, 13749, -1352}, ++{ 18642, 17655, 11001, 6817, -18418, 6336}, ++{ -1697, 2244, -4640, 3948, -12890, -5273}, ++{ 20428, 10542, 4170, -1012, 19439, 21691}, ++{ -2943, -19735, -4208, 1320, 909, -8897}, ++{ 9351, -8066, -2618, -12933, 26582, 3507}, ++{ 9705, -22628, 8311, 8167, -13293, 5608}, ++{ 3222, 3749, -1508, 165, -52, -196}, ++{ 102, -22744, -8832, 903, -11421, -14662}, ++{ -120, 5998, 19765, 13401, 3628, 5197}, ++{ 8528, 5827, -1066, 774, -39, -166}, ++{ 9411, -9476, 9581, -13004, 24456, 24900}, ++{ 17878, 2235, -21639, 20478, 4716, -7190}, ++{ -2482, 9511, 1611, -21943, 14230, -1289}, ++{ 9288, -2291, 23215, -3452, -10842, 11}, ++{ 9496, 3041, 5130, -3890, -21219, -22589}, ++{ 14262, -9838, 20195, 14019, 91, -17200}, ++{ -18591, 980, 17, 821, 120, -574}, ++{ 12285, -19269, 13742, 16373, -161, 6025}, ++{ -3364, 1530, -4005, 2454, -10872, -23839}, ++{ 105, 5085, -260, 5790, -588, 19170}, ++{ 4121, 4169, 13439, 14644, 20899, 7434}, ++{ -175, 13101, -3704, 23233, 3907, 10106}, ++{ -6101, 23467, 5204, -1341, 1599, 13174}, ++{ -3217, -3494, 15117, -8387, -11762, -4750}, ++{ 1146, 4675, -19378, 14917, -5091, 249}, ++{ -21506, 10136, -16473, -13305, 18382, -8601}, ++{ 628, 2447, 3344, 3130, -5115, 119}, ++{ 17900, -22422, -17633, 21967, -16293, -7676}, ++{ 16863, 24214, 5612, -3858, -809, 3822}, ++{ -2291, 10091, -2360, -25109, -1226, 312}, ++{ 2957, 11256, 26745, -13266, -3455, -1128}, ++{ -19762, -2708, 4604, 6355, 1638, 25501}, ++{ -19593, -7753, 3159, -85, -489, -1855}, ++{ 814, 12510, 19077, -4681, -2610, -1474}, ++{ -23408, -19027, 8137, 19878, 7912, -282}, ++{ 839, -19652, 11927, 27278, -3211, 2266}, ++{ 4020, -1110, 8226, -1274, 20922, 25060}, ++{ 26576, 325, -8693, -232, -2218, -699}, ++{ -11293, -4200, 1805, -6673, -22940, -1339}, ++{ -2005, -15886, -1047, -27687, -13235, 14370}, ++{ -22073, 1949, 13175, -15656, -1846, 8055}, ++{ 3039, 12025, 7132, -24632, 413, -2347}, ++{ -24048, -206, 12459, -6654, -417, -10091}, ++{ 18179, -23688, -20515, -16396, 7230, 763}, ++{ 5659, -5085, 13878, -23729, -11077, -19587}, ++{ 11340, 501, 25040, 7616, -19658, 1605}, ++{ -26650, 8878, 10544, 417, 1299, 261}, ++{ 14460, 11369, -3263, 9990, 8194, 18111}, ++{ 1355, -20838, -9196, -16060, -8559, -730}, ++{ -1918, -20937, -18293, -2461, -2651, 4316}, ++{ -2810, 24521, -10996, -25721, 308, -1234}, ++{ -9075, -17280, -1833, -29342, -24213, -16631}, ++{ -2843, 10165, -5339, -2888, 21858, -21340}, ++{ -15832, 14849, -23780, 5184, 10113, -20639}, ++{ -19535, -11361, 8413, 1486, -23658, -5759}, ++{ -7512, 1027, -20794, 13732, 19892, -21934}, ++{ -12132, -7022, -19175, -8840, 22125, -16490}, ++{ 1937, 5210, -6318, -23788, 13141, 11082}, ++{ -205, 6036, -380, 8658, -233, 28020}, ++{ -5523, 7477, 7635, 23595, 9763, -2590}, ++{ 21658, -28313, -3086, -300, -1032, 1744}, ++{ -22352, 16646, 208, 6665, -17400, -3028}, ++{ 18482, 9336, -2737, -19372, 407, -4389}, ++{ -4913, -17370, 18819, -17654, 13416, 15232}, ++{ 7749, 6368, 23135, -18174, 7584, -4248}, ++{ -1489, -6523, 586, -10157, 14964, 25568}, ++{ 3844, -6156, 4897, -13045, -22526, 5647}, ++{ -8491, -2105, -24774, 905, -9326, 1456}, ++{ -3040, -1476, 1166, -4428, 11236, 9204}, ++{ 3397, -1451, 13598, -15841, 24540, 5819}, ++{ 8483, -2993, 21547, -16916, 7741, 24018}, ++{ -14932, -23758, -5332, -6664, -4497, 13267}, ++{ 19379, 12916, -2142, -737, 21100, -22101}, ++{ 3393, -4629, 5735, -18913, -6969, 2687}, ++{ 1148, -16147, -21433, -28095, -630, -14449}, ++{ 7300, 672, 18530, -17452, -10149, 351}, ++{ 11356, -10974, 17212, 4624, 145, 17791}, ++{ -711, -3479, -2238, 15887, 2027, 0}, ++{ -28048, 1794, -593, -2758, -21852, 11535}, ++{ -19683, 4937, 22004, 21523, -3148, 1790}, ++{ 813, 8231, 2633, 11981, -3043, 22201}, ++{ 8952, -24760, -690, 14873, -2366, -5372}, ++{ 8406, -5439, -274, -642, -145, 778}, ++{ -6605, 7258, 20780, -23507, -18625, 22782}, ++{ -22896, -25488, 10020, -1614, 1508, -1393}, ++{ 7607, 407, -24678, -16385, -1804, -4699}, ++{ -10592, -19139, 10462, -3747, 8721, -6919}, ++{ 13010, 5292, -6230, -4884, -20904, -1797}, ++{ 16891, -13770, -465, 19343, -10741, -12959}, ++{ 25193, -14799, -5681, -521, -321, -1211}, ++{ 6917, -3093, 20183, -26903, -12026, 1295}, ++{ 305, 1992, 19457, -985, 25, -521}, ++{ 6707, -3698, 8365, -8687, 21921, -27166}, ++{ 4668, 5997, 7117, 11696, 24401, -10794}, ++{ 744, -9416, 19893, 1963, 7922, -9824}, ++{ 3430, 21282, -1736, 10844, 8821, 27015}, ++{ -8813, 1521, -24038, 1651, 7838, -1208}, ++{ 3911, -11221, 3273, -12541, 7168, 18402}, ++{ 21642, 9117, -11536, -5256, 7077, 2382}, ++{ 100, 3817, -6713, 1244, 1518, -321}, ++{ 7946, -18670, 10667, -4866, 727, 776}, ++{ -15883, -8150, -2087, 22739, 1567, -3482}, ++{ 4380, -2735, 8469, -7025, -11424, 1317}, ++{ 26970, 4393, 7665, 17561, -714, 650}, ++{ -16191, -835, 8365, 1795, -14314, 16297}, ++{ 4504, -10048, 7662, -26690, -17428, 2580}, ++{ 48, -3984, 564, -5871, 2658, -18658}, ++{ 12579, -26016, -15642, 2672, -1347, -887}, ++{ -4950, 4208, -6811, 2569, -20621, -8658}, ++{ -1836, -14818, -5571, -23322, -14800, 25867}, ++{ 5434, -28139, -2357, -2883, -570, 2431}, ++{ 13096, -2771, 24994, -12496, -24723, -1025}, ++{ -5676, -4339, 1908, 18628, -21323, 17366}, ++{ 27660, -27897, -15409, 1436, -7112, -2241}, ++{ 8019, 3847, 24568, -469, 9674, 10683}, ++{ -903, -10149, 1801, -21260, 4795, -8751}, ++{ 1122, -9582, 2625, 22791, 956, 882}, ++{ 7876, 19075, -9900, -24266, 7496, 9277}, ++{ 980, -26764, -5386, 5396, 1086, 1648}, ++{ 28838, -1270, -447, 5, -429, -20}, ++{ -15283, 6132, 22812, 1252, -9963, 511}, ++{ 851, 7925, -457, -12210, 4261, 7579}, ++{ -4530, 8452, -1246, 14501, -24951, -5760}, ++{ -17814, -10727, 9887, -23929, -13432, 1878}, ++{ -15049, 10165, 16491, -14603, -11712, -21156}, ++{ -3317, 840, -5683, 22413, 1994, 586}, ++{ 23158, -5788, -15043, -10372, -9271, -13523}, ++{ -773, -9509, -3993, -24264, 8463, 5804}, ++{ -8545, -703, -12440, -3985, -25122, -28147}, ++{ -16659, 16001, 2746, 1611, 5097, -1043}, ++{ 41, -7181, 19903, 31555, -32237, 13927}, ++{ -5658, 845, -12774, 5705, 16695, -86}, ++{ 5282, 14875, 27026, 21124, 15776, -10477}, ++{ 14712, 19648, -11487, -13361, -20196, -15229}, ++{ 8597, -9138, -626, 10891, -6015, 6346}, ++{ -1488, -1272, -1479, -1303, -3704, -5485}, ++{ -3370, 17871, -6604, 24930, 25886, -3127}, ++{ 8416, 27783, -1385, 5350, -4260, 19993}, ++{ 5688, 362, 17246, 3809, -3246, 1088}, ++{ -105, -29607, 2747, 15223, -167, 3722}, ++{ 3502, -3195, 8602, 7772, -1566, -915}, ++{ -491, 3257, -2423, 5522, 20606, -100}, ++{ -13948, -11368, -15375, -21866, -8520, 12221}, ++{ -616, 2424, -2023, 4398, -3805, 8108}, ++{ -7204, 21043, 21211, -9395, -19391, 896}, ++{ -5737, -15160, -21298, 17066, -1006, -366}, ++{ 6261, 3240, -11937, -16213, -15820, 6581}, ++{ -3155, 24796, 2733, -1257, -875, -1597}, ++{ -20469, 11094, 24071, -8987, 14136, 2220}, ++{ -14106, 11959, -22495, 4135, -1055, -5420}, ++{ 801, -2655, 60, -5324, -790, 5937}, ++{ -7372, -1764, -22433, -26060, 21707, 4178}, ++{ -5715, -6648, -14908, 1325, -24044, 1493}, ++{ -6024, -12488, 23930, 2950, 1601, 1173}, ++{ 19067, 17630, 17929, -10654, 10928, -4958}, ++{ 3231, -3284, 27336, 4174, -1683, 497}, ++}; ++ ++const int16_t (* const ff_eac3_mantissa_vq[8])[6] = { ++ NULL, ++ vq_hebap1, ++ vq_hebap2, ++ vq_hebap3, ++ vq_hebap4, ++ vq_hebap5, ++ vq_hebap6, ++ vq_hebap7, ++}; ++ ++/** ++ * Table E2.14 Frame Exponent Strategy Combinations ++ */ ++const uint8_t ff_eac3_frm_expstr[32][6] = { ++{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, ++{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, ++{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, ++{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, ++{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, ++{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, ++{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, ++{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, ++{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, ++{ EXP_D45, EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, ++{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, ++{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, ++{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, ++{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, ++{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, ++{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, ++{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, ++}; ++ ++/** ++ * Table E.25: Spectral Extension Attenuation Table ++ * ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0); ++ */ ++const float ff_eac3_spx_atten_tab[32][3] = { ++ { 0.954841603910416503f, 0.911722488558216804f, 0.870550563296124125f }, ++ { 0.911722488558216804f, 0.831237896142787758f, 0.757858283255198995f }, ++ { 0.870550563296124125f, 0.757858283255198995f, 0.659753955386447100f }, ++ { 0.831237896142787758f, 0.690956439983888004f, 0.574349177498517438f }, ++ { 0.793700525984099792f, 0.629960524947436595f, 0.500000000000000000f }, ++ { 0.757858283255198995f, 0.574349177498517438f, 0.435275281648062062f }, ++ { 0.723634618720189082f, 0.523647061410313364f, 0.378929141627599553f }, ++ { 0.690956439983888004f, 0.477420801955208307f, 0.329876977693223550f }, ++ { 0.659753955386447100f, 0.435275281648062062f, 0.287174588749258719f }, ++ { 0.629960524947436595f, 0.396850262992049896f, 0.250000000000000000f }, ++ { 0.601512518041058319f, 0.361817309360094541f, 0.217637640824031003f }, ++ { 0.574349177498517438f, 0.329876977693223550f, 0.189464570813799776f }, ++ { 0.548412489847312945f, 0.300756259020529160f, 0.164938488846611775f }, ++ { 0.523647061410313364f, 0.274206244923656473f, 0.143587294374629387f }, ++ { 0.500000000000000000f, 0.250000000000000000f, 0.125000000000000000f }, ++ { 0.477420801955208307f, 0.227930622139554201f, 0.108818820412015502f }, ++ { 0.455861244279108402f, 0.207809474035696939f, 0.094732285406899888f }, ++ { 0.435275281648062062f, 0.189464570813799776f, 0.082469244423305887f }, ++ { 0.415618948071393879f, 0.172739109995972029f, 0.071793647187314694f }, ++ { 0.396850262992049896f, 0.157490131236859149f, 0.062500000000000000f }, ++ { 0.378929141627599553f, 0.143587294374629387f, 0.054409410206007751f }, ++ { 0.361817309360094541f, 0.130911765352578369f, 0.047366142703449930f }, ++ { 0.345478219991944002f, 0.119355200488802049f, 0.041234622211652958f }, ++ { 0.329876977693223550f, 0.108818820412015502f, 0.035896823593657347f }, ++ { 0.314980262473718298f, 0.099212565748012460f, 0.031250000000000000f }, ++ { 0.300756259020529160f, 0.090454327340023621f, 0.027204705103003875f }, ++ { 0.287174588749258719f, 0.082469244423305887f, 0.023683071351724965f }, ++ { 0.274206244923656473f, 0.075189064755132290f, 0.020617311105826479f }, ++ { 0.261823530705156682f, 0.068551561230914118f, 0.017948411796828673f }, ++ { 0.250000000000000000f, 0.062500000000000000f, 0.015625000000000000f }, ++ { 0.238710400977604098f, 0.056982655534888536f, 0.013602352551501938f }, ++ { 0.227930622139554201f, 0.051952368508924235f, 0.011841535675862483f } ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3_data.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3_data.h 2012-05-14 14:08:53.682326860 +0200 +@@ -0,0 +1,36 @@ ++/* ++ * E-AC-3 tables ++ * Copyright (c) 2007 Bartlomiej Wolowiec ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_EAC3_DATA_H ++#define AVCODEC_EAC3_DATA_H ++ ++#include ++ ++extern const uint8_t ff_eac3_bits_vs_hebap[20]; ++extern const int16_t ff_eac3_gaq_remap_1[12]; ++extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2]; ++extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2]; ++ ++extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; ++extern const uint8_t ff_eac3_frm_expstr[32][6]; ++extern const float ff_eac3_spx_atten_tab[32][3]; ++ ++#endif /* AVCODEC_EAC3_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec.c 2012-05-14 14:08:53.683326880 +0200 +@@ -51,7 +51,7 @@ + #include "ac3_parser.h" + #include "ac3dec.h" + #include "ac3dec_data.h" +-#include "eac3dec_data.h" ++#include "eac3_data.h" + + /** gain adaptive quantization mode */ + typedef enum { +@@ -410,7 +410,7 @@ + + /* informational metadata */ + if (get_bits1(gbc)) { +- skip_bits(gbc, 3); // skip bit stream mode ++ s->bitstream_mode = get_bits(gbc, 3); + skip_bits(gbc, 2); // skip copyright bit and original bitstream bit + if (s->channel_mode == AC3_CHMODE_STEREO) { + skip_bits(gbc, 4); // skip Dolby surround and headphone mode +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec_data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec_data.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,1134 +0,0 @@ +-/* +- * E-AC-3 decoder tables +- * Copyright (c) 2007 Bartlomiej Wolowiec +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * Tables taken directly from the E-AC-3 spec. +- */ +- +-#include "eac3dec_data.h" +-#include "ac3.h" +- +-const uint8_t ff_eac3_bits_vs_hebap[20] = { +- 0, 2, 3, 4, 5, 7, 8, 9, 3, 4, +- 5, 6, 7, 8, 9, 10, 11, 12, 14, 16, +-}; +- +-/** +- * Table E3.6, Gk=1 +- * No gain (Gk=1) inverse quantization, remapping scale factors +- * ff_eac3_gaq_remap[hebap+8] +- */ +-const int16_t ff_eac3_gaq_remap_1[12] = { +- 4681, 2185, 1057, 520, 258, 129, 64, 32, 16, 8, 2, 0 +-}; +- +-/** +- * Table E3.6, Gk=2 & Gk=4, A +- * Large mantissa inverse quantization, remapping scale factors +- * ff_eac3_gaq_remap_2_4_a[hebap-8][Gk=2,4] +- */ +-const int16_t ff_eac3_gaq_remap_2_4_a[9][2] = { +- { -10923, -4681 }, +- { -14043, -6554 }, +- { -15292, -7399 }, +- { -15855, -7802 }, +- { -16124, -7998 }, +- { -16255, -8096 }, +- { -16320, -8144 }, +- { -16352, -8168 }, +- { -16368, -8180 } +-}; +- +-/** +- * Table E3.6, Gk=2 & Gk=4, B +- * Large mantissa inverse quantization, negative mantissa remapping offsets +- * ff_eac3_gaq_remap_3_4_b[hebap-8][Gk=2,4] +- */ +-const int16_t ff_eac3_gaq_remap_2_4_b[9][2] = { +- { -5461, -1170 }, +- { -11703, -4915 }, +- { -14199, -6606 }, +- { -15327, -7412 }, +- { -15864, -7805 }, +- { -16126, -7999 }, +- { -16255, -8096 }, +- { -16320, -8144 }, +- { -16352, -8168 } +-}; +- +-static const int16_t vq_hebap1[4][6] = { +-{ 7167, 4739, 1106, 4269, 10412, 4820}, +-{ -5702, -3187, -14483, -1392, -2027, 849}, +-{ 633, 6199, 7009, -12779, -2306, -2636}, +-{ -1468, -7031, 7592, 10617, -5946, -3062}, +-}; +-static const int16_t vq_hebap2[8][6] = { +-{ -12073, 608, -7019, 590, 4000, 869}, +-{ 6692, 15689, -6178, -9239, -74, 133}, +-{ 1855, -989, 20596, -2920, -4475, 225}, +-{ -1194, -3901, -821, -6566, -875, -20298}, +-{ -2762, -3181, -4094, -5623, -16945, 9765}, +-{ 1547, 6839, 1980, 20233, -1071, -4986}, +-{ 6221, -17915, -5516, 6266, 358, 1162}, +-{ 3753, -1066, 4283, -3227, 15928, 10186}, +-}; +-static const int16_t vq_hebap3[16][6] = { +-{ -10028, 20779, 10982, -4560, 798, -68}, +-{ 11050, 20490, -6617, -5342, -1797, -1631}, +-{ 3977, -542, 7118, -1166, 18844, 14678}, +-{ -4320, -96, -7295, -492, -22050, -4277}, +-{ 2692, 5856, 5530, 21862, -7212, -5325}, +-{ -135, -23391, 962, 8115, -644, 382}, +-{ -1563, 3400, -3299, 4693, -6892, 22398}, +-{ 3535, 3030, 7296, 6214, 20476, -12099}, +-{ 57, -6823, 1848, -22349, -5919, 6823}, +-{ -821, -3655, -387, -6253, -1735, -22373}, +-{ -6046, 1586, -18890, -14392, 9214, 705}, +-{ -5716, 264, -17964, 14618, 7921, -337}, +-{ -110, 108, 8, 74, -89, -50}, +-{ 6612, -1517, 21687, -1658, -7949, -246}, +-{ 21667, -6335, -8290, -101, -1349, -22}, +-{ -22003, -6476, 7974, 648, 2054, -331}, +-}; +-static const int16_t vq_hebap4[32][6] = { +-{ 6636, -4593, 14173, -17297, -16523, 864}, +-{ 3658, 22540, 104, -1763, -84, 6}, +-{ 21580, -17815, -7282, -1575, -2078, -320}, +-{ -2233, 10017, -2728, 14938, -13640, -17659}, +-{ -1564, -17738, -19161, 13735, 2757, 2951}, +-{ 4520, 5510, 7393, 10799, 19231, -13770}, +-{ 399, 2976, -1099, 5013, -1159, 22095}, +-{ 3624, -2359, 4680, -2238, 22702, 3765}, +-{ -4201, -8285, -6810, -12390, -18414, 15382}, +-{ -5198, -6869, -10047, -8364, -16022, -20562}, +-{ -142, -22671, -368, 4391, -464, -13}, +-{ 814, -1118, -1089, -22019, 74, 1553}, +-{ -1618, 19222, -17642, -13490, 842, -2309}, +-{ 4689, 16490, 20813, -15387, -4164, -3968}, +-{ -3308, 11214, -13542, 13599, -19473, 13770}, +-{ 1817, 854, 21225, -966, -1643, -268}, +-{ -2587, -107, -20154, 376, 1174, -304}, +-{ -2919, 453, -5390, 750, -22034, -978}, +-{ -19012, 16839, 10000, -3580, 2211, 1459}, +-{ 1363, -2658, -33, -4067, 1165, -21985}, +-{ -8592, -2760, -17520, -15985, 14897, 1323}, +-{ 652, -9331, 3253, -14622, 12181, 19692}, +-{ -6361, 5773, -15395, 17291, 16590, -2922}, +-{ -661, -601, 1609, 22610, 992, -1045}, +-{ 4961, 9107, 11225, 7829, 16320, 18627}, +-{ -21872, -1433, 138, 1470, -1891, -196}, +-{ -19499, -18203, 11056, -516, 2543, -2249}, +-{ -1196, -17574, 20150, 11462, -401, 2619}, +-{ 4638, -8154, 11891, -15759, 17615, -14955}, +-{ -83, 278, 323, 55, -154, 232}, +-{ 7788, 1462, 18395, 15296, -15763, -1131}, +-}; +-static const int16_t vq_hebap5[128][6] = { +-{ -3394, -19730, 2963, 9590, 4660, 19673}, +-{ -15665, -6405, 17671, 3860, -8232, -19429}, +-{ 4467, 412, -17873, -8037, 691, -17307}, +-{ 3580, 2363, 6886, 3763, 6379, -20522}, +-{ -17230, -14133, -1396, -23939, 8373, -12537}, +-{ -8073, -21469, -15638, 3214, 8105, -5965}, +-{ 4343, 5169, 2683, -16822, -5146, -16558}, +-{ 6348, -10668, 12995, -25500, -22090, 4091}, +-{ -2880, -8366, -5968, -17158, -2638, 23132}, +-{ -5095, -14281, -22371, 21741, 3689, 2961}, +-{ -2443, -17739, 25155, 2707, 1594, 7}, +-{ -18379, 9010, 4270, 731, -426, -640}, +-{ -23695, 24732, 5642, 612, -308, -964}, +-{ -767, 1268, 225, 1635, 173, 916}, +-{ 5455, 6493, 4902, 10560, 23041, -17140}, +-{ 17219, -21054, -18716, 4936, -3420, 3357}, +-{ -1390, 15488, -21946, -14611, 1339, 542}, +-{ -6866, -2254, -12070, -3075, -19981, -20622}, +-{ -1803, 11775, 1343, 8917, 693, 24497}, +-{ -21610, 9462, 4681, 9254, -7815, 15904}, +-{ -5559, -3018, -9169, -1347, -22547, 12868}, +-{ -366, 5076, -1727, 20427, -283, -2923}, +-{ -1886, -6313, -939, -2081, -1399, 3513}, +-{ -3161, -537, -5075, 11268, 19396, 989}, +-{ 2345, 4153, 5769, -4273, 233, -399}, +-{ -21894, -1138, -16474, 5902, 5488, -3211}, +-{ 10007, -12530, 18829, 20932, -1158, 1790}, +-{ -1165, 5014, -1199, 6415, -8418, -21038}, +-{ 1892, -3534, 3815, -5846, 16427, 20288}, +-{ -2664, -11627, -4147, -18311, -22710, 14848}, +-{ 17256, 10419, 7764, 12040, 18956, 2525}, +-{ -21419, -18685, -10897, 4368, -7051, 4539}, +-{ -1574, 2050, 5760, 24756, 15983, 17678}, +-{ -538, -22867, 11067, 10301, 385, 528}, +-{ -8465, -3025, -16357, -23237, 16491, 3654}, +-{ 5840, 575, 11890, 1947, 25157, 6653}, +-{ 6625, -3516, -1964, 3850, -390, -116}, +-{ 18005, 20900, 14323, -7621, -10922, 11802}, +-{ -4857, -2932, -13334, -7815, 21622, 2267}, +-{ -579, -9431, -748, -21321, 12367, 8265}, +-{ -8317, 1375, -17847, 2921, 9062, 22046}, +-{ 18398, 8635, -1503, -2418, -18295, -14734}, +-{ -2987, 15129, -3331, 22300, 13878, -13639}, +-{ 5874, -19026, 15587, 11350, -20738, 1971}, +-{ 1581, -6955, -21440, 2455, 65, 414}, +-{ 515, -4468, -665, -4672, 125, -19222}, +-{ 21495, -20301, -1872, -1926, -211, -1022}, +-{ 5189, -12250, -1775, -23550, -4546, 5813}, +-{ 321, -6331, 14646, 6975, -1773, 867}, +-{ -13814, 3180, 7927, 444, 19552, 3146}, +-{ -6660, 12252, -1972, 17408, -24280, -12956}, +-{ -745, 14356, -1107, 23742, -9631, -18344}, +-{ 18284, -7909, -7531, 19118, 7721, -12659}, +-{ 1926, 15101, -12848, 2153, 21631, 1864}, +-{ -2130, 23416, 17056, -15597, -1544, 87}, +-{ 8314, -11824, 14581, -20591, 7891, -2099}, +-{ 19600, 22814, -17304, -2040, 285, -3863}, +-{ -8214, -18322, 10724, -13744, -13469, -1666}, +-{ 14351, 4880, -20034, 964, -4221, -180}, +-{ -24598, -16635, 19724, 5925, 4777, 4414}, +-{ -2495, 23493, -16141, 2918, -1038, -2010}, +-{ 18974, -2540, 13343, 1405, -6194, -1136}, +-{ 2489, 13670, 22638, -7311, -129, -2792}, +-{ -13962, 16775, 23012, 728, 3397, 162}, +-{ 3038, 993, 8774, -21969, -6609, 910}, +-{ -12444, -22386, -2626, -5295, 19520, 9872}, +-{ -1911, -18274, -18506, -14962, 4760, 7119}, +-{ 8298, -2978, 25886, 7660, -7897, 1020}, +-{ 6132, 15127, 18757, -24370, -6529, -6627}, +-{ 7924, 12125, -9459, -23962, 5502, 937}, +-{ -17056, -5373, 2522, 327, 1129, -390}, +-{ 15774, 19955, -10380, 11172, -3107, 14853}, +-{ -11904, -8091, -17928, -22287, -17237, -6803}, +-{ -12862, -2172, -6509, 5927, 12458, -22355}, +-{ -497, 322, 1038, -6643, -5404, 20311}, +-{ 1083, -22984, -8494, 12130, -762, 2623}, +-{ 5067, 19712, -1901, -30, -325, 85}, +-{ 987, -5830, 4212, -9030, 9121, -25038}, +-{ -7868, 7284, -12292, 12914, -21592, 20941}, +-{ -1630, -7694, -2187, -8525, -5604, -25196}, +-{ -6668, 388, -22535, 1526, 9082, 193}, +-{ -7867, -22308, 5163, 362, 944, -259}, +-{ 3824, -11850, 7591, -23176, 25342, 23771}, +-{ -10504, 4123, -21111, 21173, 22439, -838}, +-{ -4723, 21795, 6184, -122, 1642, -717}, +-{ 24504, 19887, -2043, 986, 7, -55}, +-{ -27313, -135, 2437, 259, 89, 307}, +-{ 24446, -3873, -5391, -820, -2387, 361}, +-{ 5529, 5784, 18682, 242, -21896, -4003}, +-{ 22304, 4483, 722, -12242, 7570, 15448}, +-{ 8673, 3009, 20437, 21108, -21100, -3080}, +-{ -1132, 2705, -1825, 5420, -785, 18532}, +-{ 16932, -13517, -16509, -14858, -20327, -14221}, +-{ 2219, 1380, 21474, -1128, 327, 83}, +-{ -2177, 21517, -3856, -14180, -204, -2191}, +-{ 953, -9426, 15874, -10710, -3231, 21030}, +-{ -421, -1377, 640, -8239, -20976, 2174}, +-{ 4309, 18514, -9100, -18319, -15518, 3704}, +-{ -5943, 449, -8387, 1075, -22210, -4992}, +-{ 2953, 12788, 18285, 1430, 14937, 21731}, +-{ -2913, 401, -4739, -20105, 1699, -1147}, +-{ 3449, 5241, 8853, 22134, -7547, 1451}, +-{ -2154, 8584, 18120, -15614, 19319, -5991}, +-{ 3501, 2841, 5897, 6397, 8630, 23018}, +-{ 2467, 2956, 379, 5703, -22047, -2189}, +-{ -16963, -594, 18822, -5295, 1640, 774}, +-{ 2896, -1424, 3586, -2292, 19910, -1822}, +-{ -18575, 21219, -14001, -12573, 16466, 635}, +-{ -1998, -19314, -16527, 12208, -16576, -7854}, +-{ -9674, 1012, -21645, 2883, -12712, 2321}, +-{ -1005, 471, -3629, 8045, -11087, 25533}, +-{ 4141, -21472, -2673, 756, -663, -523}, +-{ 6490, 8531, 19289, 18949, 6092, -9347}, +-{ 16965, 24599, 14024, 10072, -536, -10438}, +-{ -8147, 2145, -23028, -17073, 5451, -4401}, +-{ -14873, 20520, -18303, -9717, -11885, -17831}, +-{ -2290, -14120, 2070, 22467, 1671, 725}, +-{ -8538, 14629, 3521, -20577, 6673, 8200}, +-{ 20248, 4410, -1366, -585, 1229, -2449}, +-{ 7467, -7148, 13667, -8246, 22392, -17320}, +-{ -1932, 3875, -9064, -3812, 958, 265}, +-{ -4399, 2959, -15911, 19598, 4954, -1105}, +-{ 18009, -9923, -18137, -3862, 11178, 5821}, +-{ -14596, -1227, 9660, 21619, 11228, -11721}, +-{ -721, -1700, 109, -2142, 61, -6772}, +-{ -24619, -22520, 5608, -1957, -1761, -1012}, +-{ -23728, -4451, -2688, -14679, -4266, 9919}, +-{ 8495, -894, 20438, -13820, -17267, 139}, +-}; +-static const int16_t vq_hebap6[256][6] = { +-{ 10154, 7365, 16861, 18681, -22893, -3636}, +-{ -2619, -3788, -5529, -5192, -9009, -20298}, +-{ -5583, -22800, 21297, 7012, 745, 720}, +-{ 428, -1459, 109, -3082, 361, -8403}, +-{ 8161, 22401, 241, 1755, -874, -2824}, +-{ 1140, 12643, 2306, 22263, -25146, -17557}, +-{ -2609, 3379, 10337, -19730, -15468, -23944}, +-{ -4040, -12796, -25772, 13096, 3905, 1315}, +-{ 4624, -23799, 13608, 25317, -1175, 2173}, +-{ -97, 13747, -5122, 23255, 4214, -22145}, +-{ 6878, -322, 18264, -854, -11916, -733}, +-{ 17280, -12669, -9693, 23563, -16240, -1309}, +-{ 5802, -4968, 19526, -21194, -24622, -183}, +-{ 5851, -16137, 15229, -9496, -1538, 377}, +-{ 14096, 25057, 13419, 8290, 23320, 16818}, +-{ -7261, 118, -15867, 19097, 9781, -277}, +-{ -4288, 21589, -13288, -16259, 16633, -4862}, +-{ 4909, -19217, 23411, 14705, -722, 125}, +-{ 19462, -4732, -1928, -11527, 20770, 5425}, +-{ -27562, -2881, -4331, 384, -2103, 1367}, +-{ -266, -9175, 5441, 26333, -1924, 4221}, +-{ -2970, -20170, -21816, 5450, -7426, 5344}, +-{ -221, -6696, 603, -9140, 1308, -27506}, +-{ 9621, -8380, -1967, 9403, -1651, 22817}, +-{ 7566, -5250, -4165, 1385, -990, 560}, +-{ -1262, 24738, -19057, 10741, 7585, -7098}, +-{ 451, 20130, -9949, -6015, -2188, -1458}, +-{ 22249, 9380, 9096, 10959, -2365, -3724}, +-{ 18668, -650, -1234, 11092, 7678, 5969}, +-{ 19207, -1485, -1076, -731, -684, 43}, +-{ -4973, 13430, 20139, 60, 476, -935}, +-{ -20029, 8710, 2499, 1016, -1158, 335}, +-{ -26413, 18598, -2201, -669, 3409, 793}, +-{ -4726, 8875, -24607, -9646, 3643, -283}, +-{ 13303, -21404, -3691, -1184, -1970, 1612}, +-{ 173, 60, 919, 1229, 6942, -665}, +-{ 16377, 16991, 5341, -14015, -2304, -20390}, +-{ 25334, -10609, 11947, -7653, -6363, 14058}, +-{ 23929, -13259, -7226, -937, 234, -187}, +-{ 6311, -1877, 12506, -1879, 18751, -23341}, +-{ 621, 6445, 3354, -24274, 8406, 5315}, +-{ -3297, -5034, -4704, -5080, -25730, 5347}, +-{ -1275, -13295, -965, -23318, 1214, 26259}, +-{ -6252, 10035, -20105, 15301, -16073, 5136}, +-{ 9562, -3911, -19510, 4745, 22270, -4171}, +-{ 7978, -19600, 14024, -5745, -20855, 8939}, +-{ 7, -4039, 991, -6065, 52, -19423}, +-{ 3485, 2969, 7732, 7786, 25312, 6206}, +-{ -959, -12812, -1840, -22743, 7324, 10830}, +-{ -4686, 1678, -10172, -5205, 4294, -1271}, +-{ 3889, 1302, 7450, 638, 20374, -3133}, +-{ -12496, -9123, 18463, -12343, -7238, 18552}, +-{ -6185, 8649, -6903, -895, 17109, 16604}, +-{ -9896, 28579, 2845, 1640, 2925, -298}, +-{ 14968, -25988, 14878, -24012, 1815, -6474}, +-{ 26107, 5166, 21225, 15873, 21617, 14825}, +-{ -21684, 16438, 20504, -14346, -7114, -4162}, +-{ 28647, 90, -1572, 789, -902, -75}, +-{ -1479, 2471, -4061, 3612, -2240, 10914}, +-{ 8616, 17491, 17255, -17456, 17022, -16357}, +-{ -20722, -18597, 25274, 17720, -3573, 1695}, +-{ -997, 6129, -6303, 11250, -11359, -19739}, +-{ -74, -4001, -1584, 13384, 162, -144}, +-{ -529, 21068, 7923, -11396, 422, -26}, +-{ 7102, -13531, -20055, 2629, -178, -429}, +-{ 9201, 1368, -22238, 2623, -20499, 24889}, +-{ -432, 6675, -266, 8723, 80, 28024}, +-{ 19493, -3108, -9261, 1910, -21777, 5345}, +-{ 14079, -11489, 12604, 6079, 19877, 1315}, +-{ 10947, 9837, -18612, 15742, 4792, 605}, +-{ -1777, 3758, -4087, 21696, 6024, -576}, +-{ 3567, -3578, 16379, 2680, -1752, 716}, +-{ -5049, -1399, -4550, -652, -17721, -3366}, +-{ -3635, -4372, -6522, -22152, 7382, 1458}, +-{ 12242, 19190, 5646, -7815, -20289, 21344}, +-{ -7508, 19952, 23542, -9753, 5669, -1990}, +-{ -2275, 15438, 10907, -17879, 6497, 13582}, +-{ -15894, -15646, -4716, 6019, 24250, -6179}, +-{ -2049, -6856, -1208, 918, 17735, -69}, +-{ -3721, 9099, -16065, -23621, 5981, -2344}, +-{ 7862, -8918, 24033, 25508, -11033, -741}, +-{ -12588, 19468, 14649, 15451, -21226, 1171}, +-{ 2102, 1147, 2789, 4096, 2179, 8750}, +-{ -18214, -17758, -10366, -5203, -1066, -3541}, +-{ -2819, -19958, -11921, 6032, 8315, 10374}, +-{ -9078, -2100, 19431, -17, 732, -689}, +-{ -14512, -19224, -7095, 18727, 1870, 22906}, +-{ 3912, 659, 25597, -4006, 9619, 877}, +-{ 2616, 22695, -5770, 17920, 3812, 20220}, +-{ 2561, 26847, -5245, -10908, 2256, -517}, +-{ -4974, 198, -21983, -3608, 22174, -18924}, +-{ 21308, -1211, 19144, 16691, -1588, 11390}, +-{ -1790, 3959, -3488, 7003, -7107, 20877}, +-{ -6108, -17955, -18722, 24763, 16508, 3211}, +-{ 20462, -24987, -20361, 4484, -5111, -478}, +-{ -6378, -1998, -10229, -561, -22039, -22339}, +-{ 3047, -18850, 7586, 14743, -19862, 6351}, +-{ -5047, 1405, -9672, 1055, -21881, 11170}, +-{ 3481, -9699, 6526, -16655, 22813, 21907}, +-{ -18570, 17501, 14664, 1291, 5026, 19676}, +-{ 16134, -19810, -16956, -17939, -16933, 5800}, +-{ -8224, 4908, 8935, 2272, -1140, -23217}, +-{ 1572, 2753, -1598, 2143, -3346, -21926}, +-{ -9832, -1060, -27818, 1214, 7289, 150}, +-{ 98, 1538, 535, 17429, -23198, -901}, +-{ 21340, -20146, 3297, -1744, -8207, -21462}, +-{ -4166, -4633, -17902, 5478, 1285, 136}, +-{ 18713, 21003, 24818, 11421, 1282, -4618}, +-{ -3535, 7636, -265, 2141, -829, -2035}, +-{ -3184, 19713, 2775, -2, 1090, 104}, +-{ -6771, -20185, 2938, -2125, -36, 1268}, +-{ 9560, 9430, 9586, 22100, 13827, 6296}, +-{ -535, -20018, 4276, -1868, -448, -17183}, +-{ -24352, 14244, -13647, -21040, 2271, 11555}, +-{ -2646, 15437, -4589, 18638, -4299, -622}, +-{ -20064, 4169, 18115, -1404, 13722, -1825}, +-{ -16359, 9080, 744, 22021, 125, 10794}, +-{ 9644, -14607, -18479, -14714, 11174, -20754}, +-{ -326, -23762, 6144, 7909, 602, 1540}, +-{ -6650, 6634, -12683, 21396, 20785, -6839}, +-{ 4252, -21043, 5628, 18687, 23860, 8328}, +-{ 17986, 5704, -5245, -18093, -555, 3219}, +-{ 6091, 14232, -5117, -17456, -19452, -11649}, +-{ -21586, 11302, 15434, 25590, 6777, -26683}, +-{ 21355, -8244, 5877, -3540, 6079, -2567}, +-{ 2603, -2455, 5421, -12286, -19100, 5574}, +-{ -1721, -26393, -23664, 22904, -349, 3787}, +-{ 2189, -1203, 5340, 3249, -22617, 104}, +-{ -1664, -11020, -2857, -20723, -24049, 19900}, +-{ 22873, -7345, -18481, -14616, -8400, -12965}, +-{ 3777, 3958, 8239, 20494, -6991, -1201}, +-{ -160, -1613, -793, -8681, 573, 776}, +-{ 4297, -3786, 20373, 6082, -5321, -18400}, +-{ 18745, 2463, 12546, -7749, -7734, -2183}, +-{ 11074, -4720, 22119, 1825, -24351, 4080}, +-{ 1503, -19178, -1569, 13, -313, 375}, +-{ 318, -575, 2544, 178, 102, 40}, +-{ -15996, -26897, 5008, 3320, 686, 1159}, +-{ 25755, 26886, 574, -5930, -3916, 1407}, +-{ -9148, -7665, -2875, -8384, -18663, 26400}, +-{ -7445, -18040, -18396, 8802, -2252, -21886}, +-{ 7851, 11773, 27485, -12847, -1410, 19590}, +-{ 2240, 5947, 11247, 15980, -6499, 24280}, +-{ 21673, -18515, 9771, 6550, -2730, 334}, +-{ -4149, 1576, -11010, 89, -24429, -5710}, +-{ 7720, 1478, 21412, -25025, -8385, 9}, +-{ -2448, 10218, -12756, -16079, 1161, -21284}, +-{ -8757, -14429, -22918, -14812, 2629, 13844}, +-{ -7252, 2843, -9639, 2882, -14625, 24497}, +-{ -674, -6530, 414, -23333, -21343, 454}, +-{ 2104, -6312, 10887, 18087, -1199, 175}, +-{ -493, -562, -2739, 118, -1074, 93}, +-{ -10011, -4075, -28071, 22180, 15077, -636}, +-{ -4637, -16408, -9003, -20418, -11608, -20932}, +-{ 4815, 15892, 24238, -13634, -3074, -1059}, +-{ -6724, 4610, -18772, -15283, -16685, 23988}, +-{ 15349, -674, -3682, 21679, 4475, -12088}, +-{ 4756, 2593, 5354, 6001, 15063, 26490}, +-{ -23815, -17251, 6944, 378, 694, 670}, +-{ 23392, -8839, -14713, 7544, -876, 11088}, +-{ 3640, 3336, 22593, -3495, -2328, -113}, +-{ 284, 6914, 3097, 10171, 6638, -18621}, +-{ 2472, 5976, 11054, -11936, -603, -663}, +-{ 16175, 16441, 13164, -4043, 4667, 7431}, +-{ 19338, 15534, -6533, 1681, -4857, 17048}, +-{ 17027, 532, -19064, -1441, -5130, 1085}, +-{ -12617, -17609, 2062, -25332, 19009, -16121}, +-{ 10056, -21000, -13634, -2949, 15367, 19934}, +-{ -648, -1605, 10046, -1592, 13296, 19808}, +-{ -1054, 10744, 538, 24938, 9630, -9052}, +-{ -10099, 3042, -25076, -24052, 13971, 100}, +-{ 6547, 6907, 7031, 10348, 23775, -17886}, +-{ -22793, -1984, -1393, -3330, 9267, 14317}, +-{ -14346, -3967, 3042, 16254, -17303, 9646}, +-{ -21393, 23628, 16773, 716, 2663, 114}, +-{ -19016, -3038, 1574, -245, 1463, -793}, +-{ 22410, 23441, -14637, -530, 17310, 13617}, +-{ -11582, 7935, -13954, 23465, -24628, 26550}, +-{ -1045, 3679, -2218, 10572, 20999, -3702}, +-{ -15513, 197, 16718, -24603, 4945, 5}, +-{ 10781, 4335, 26790, -9059, -16152, -2840}, +-{ 16075, -24100, -3933, -6833, 12645, -7029}, +-{ 2096, -25572, -8370, 6814, 11, 1178}, +-{ -11848, -583, -8889, -20543, -10471, -380}, +-{ -2487, 24777, -21639, -19341, 1660, -732}, +-{ 2313, 13679, 4085, 24549, 24691, -21179}, +-{ -2366, -504, -4130, -10570, 23668, 1961}, +-{ 20379, 17809, -9506, 3733, -18954, -6292}, +-{ -3856, 16802, -929, -20310, -17739, 6797}, +-{ 12431, 6078, -11272, -14450, 6913, 23476}, +-{ 7636, -1655, 23017, 10719, -8292, 838}, +-{ -8559, -1235, -18096, 3897, 16093, 1490}, +-{ -3586, 8276, 15165, -3791, -21149, 1741}, +-{ -4497, 21739, 2366, -278, -4792, 15549}, +-{ -23122, -13708, 7668, 16232, 24120, 15025}, +-{ -20043, 12821, -20160, 16691, -11655, -16081}, +-{ -12601, 20239, 3496, -2549, -6745, -11850}, +-{ 4441, 7812, 20783, 17080, 11523, -9643}, +-{ 24766, 8494, -23298, -3262, 11101, -7120}, +-{ -10107, -7623, -22152, -18303, 26645, 9550}, +-{ -25549, 477, 7874, -1538, 1123, -168}, +-{ 470, 9834, -347, 23945, -10381, -9467}, +-{ -4096, -9702, -6856, -21544, 20845, 7174}, +-{ 5370, 9748, -23765, -1190, 512, -1538}, +-{ -1006, -10046, -12649, 19234, -1790, -890}, +-{ 15108, 23620, -15646, -2522, -1203, -1325}, +-{ -7406, -2605, 1095, -247, -473, 177}, +-{ 8089, 4, 12424, -22284, 10405, -7728}, +-{ 22196, 10775, -5043, 690, 534, -212}, +-{ -3153, -1418, -16835, 18426, 15821, 22956}, +-{ 5681, -2229, 3196, -3414, -21817, -14807}, +-{ 19, 787, 1032, 170, -8295, -645}, +-{ -882, -2319, -27105, 432, -4392, 1499}, +-{ -1354, -11819, -76, -20380, -10293, 11328}, +-{ 211, -4753, -4675, -6933, -13538, 14479}, +-{ 6043, 5260, -459, -462, 143, -65}, +-{ -2572, 7256, -3317, 9212, -23184, -9990}, +-{ -24882, -9532, 18874, 6101, 2429, -14482}, +-{ 8314, 2277, 14192, 3512, 25881, 22000}, +-{ 208, 20218, -281, -24778, -63, -1183}, +-{ 1095, -6034, 2706, -21935, -2655, 563}, +-{ 23, -5930, 243, -8989, 5345, 20558}, +-{ -15466, 12699, 4160, 11087, 20621, -10416}, +-{ 20995, -85, -8468, 194, 1003, -9515}, +-{ -19637, -3335, -14081, 3574, -23381, -667}, +-{ -2076, 3489, -3192, -19367, 539, -1530}, +-{ 7352, -15213, 22596, 19369, 1043, 16627}, +-{ -1872, -413, 1235, -5276, -3550, 21903}, +-{ 7931, -2008, 16968, -6799, 29393, -2475}, +-{ -13589, 8389, -23636, -22091, -14178, -14297}, +-{ -11575, -20090, 16056, -1848, 15721, 4500}, +-{ 3849, -16581, 20161, -21155, 7778, 11864}, +-{ -6547, -1273, -18837, -11218, 11636, 1044}, +-{ 2528, -6691, -17917, -11362, -4894, -1008}, +-{ 1241, 4260, 2319, 6111, 3485, 20209}, +-{ 3014, -3048, 5316, -4539, 20831, 8702}, +-{ -1790, -14683, 278, 13956, -10065, -10547}, +-{ -22732, -7957, -1154, 13821, -1484, -1247}, +-{ -7317, -615, 13094, 18927, 9897, 1452}, +-{ 2552, -2338, 3424, -4630, 11124, -19584}, +-{ -11125, -20553, -10855, -10783, -20767, 6833}, +-{ 984, -15095, 5775, 25125, 5377, -19799}, +-{ 517, 13272, -7458, -1711, 20612, -6013}, +-{ -21417, 13251, -20795, 13449, 17281, 13104}, +-{ -15811, -16248, 23093, -4037, -8195, 871}, +-{ 582, 12571, -21129, -14766, -9187, 5685}, +-{ 4318, -1776, 11425, -17763, -9921, 577}, +-{ 6013, 16830, 17655, -25766, -4400, -3550}, +-{ -13744, -16541, 3636, -3330, -21091, -15886}, +-{ 6565, -11147, 8649, -13114, 23345, -13565}, +-{ -2542, -9046, -7558, 29240, 3701, -383}, +-{ -10612, 24995, 1893, -8210, 20920, -16210}, +-{ 5276, 16726, 10659, 19940, -4799, -19324}, +-{ -532, -9300, 27856, 4965, -241, 536}, +-{ -765, -20706, -3412, 18870, 2765, 1420}, +-{ -3059, 2708, -19022, -331, 3537, 116}, +-}; +-static const int16_t vq_hebap7[512][6] = { +-{ -21173, 21893, 10390, 13646, 10718, -9177}, +-{ -22519, -8193, 18328, -6629, 25518, -10848}, +-{ 6800, -13758, -13278, 22418, 14667, -20938}, +-{ 2347, 10516, 1125, -3455, 5569, 27136}, +-{ -6617, 11851, -24524, 22937, 20362, -6019}, +-{ -21768, 10681, -19615, -15021, -8478, -2081}, +-{ -2745, 8684, -4895, 27739, 7554, -11961}, +-{ -1020, 2460, -954, 4754, -627, -16368}, +-{ -19702, 23097, 75, -13684, -2644, 2108}, +-{ 4049, -2872, 5851, -4459, 22150, 12560}, +-{ -21304, -17129, -730, 7419, -11658, -10523}, +-{ 11332, 1792, 26666, 23518, -19561, -491}, +-{ -17827, -16777, -13606, -14389, -22029, -2464}, +-{ 1091, -5967, -7975, -16977, -20432, -21931}, +-{ 18388, -1103, 1933, 13342, -17463, 18114}, +-{ 22646, 17345, -9966, 17919, 18274, 698}, +-{ 1484, 20297, -5754, -26515, 4941, -22263}, +-{ -2603, 4587, -5842, 18464, 8767, -2568}, +-{ -2797, -1602, 21713, 3099, -25683, 3224}, +-{ -19027, 4693, -5007, 6060, 1972, -15095}, +-{ -2189, 9516, -530, 20669, -4662, -8301}, +-{ -22325, -8887, 2529, -11352, 5476, 998}, +-{ 22100, -5052, 1651, -2657, 4615, 2319}, +-{ 20855, -3078, -3330, 4105, 13470, 3069}, +-{ 85, 17289, 10264, -14752, 214, 90}, +-{ -26365, -18849, -19352, 19244, -10218, 9909}, +-{ -9739, 20497, -6579, -6983, 2891, -738}, +-{ 20575, -15860, -22913, 6870, 76, 327}, +-{ 8744, -12877, -22945, -2372, -19424, -9771}, +-{ -12886, 16183, 21084, 3821, 749, -13792}, +-{ -15995, 18399, 2391, -17661, 19484, -6018}, +-{ 1423, 11734, 4051, 19290, 6857, -19681}, +-{ -5200, 9766, 18246, 2463, 18764, -4852}, +-{ -597, 19498, 1323, -9096, -308, -1104}, +-{ -3099, -25731, -15665, 25332, 4634, 2635}, +-{ 19623, -2384, -7913, 11796, -9333, -14084}, +-{ 2642, 26453, -21091, -10354, -1693, -1711}, +-{ 22031, 21625, 11580, -22915, -4141, 129}, +-{ -6122, 3542, 915, -261, -17, -383}, +-{ 1696, 6704, -1425, 20838, 857, -4416}, +-{ 1423, -15280, -8550, -9667, 5210, 5687}, +-{ -4520, -613, -11683, 5618, 4230, 619}, +-{ 937, -4963, -14102, -17104, -6906, -5952}, +-{ -15068, -481, -7237, -14894, 18876, 21673}, +-{ -25658, 2910, 1143, -327, -458, -995}, +-{ -9656, -819, -24900, 2804, 20225, 1083}, +-{ -1111, -3682, -1788, -19492, 966, 821}, +-{ 7293, -21759, 10790, -7059, -23293, -1723}, +-{ -282, -11093, 170, -20950, -28926, 12615}, +-{ 17938, 3713, -1563, 885, 5, 564}, +-{ 6116, 22696, 2242, -6951, 9975, -6132}, +-{ 4338, 26808, -3705, 1976, -1079, -2570}, +-{ -661, -7901, -2668, -15194, 17722, 4375}, +-{ -4174, -11053, 717, -22506, 1562, 12252}, +-{ -6405, 18334, 6103, 6983, 5956, 18195}, +-{ 9851, 5370, 23604, -6861, -6569, -62}, +-{ 21964, 13359, -683, 3785, 2168, 209}, +-{ -3569, -1127, -19724, -1544, 1308, -803}, +-{ -3083, 16049, -13791, -3077, 4294, 23713}, +-{ -9999, 9943, -15872, 12934, -23631, 21699}, +-{ 9722, 22837, 12192, 15091, 5533, 4837}, +-{ 2243, 2099, 1243, 4089, 4748, 12956}, +-{ 4007, -2468, 3353, -3092, 8843, 17024}, +-{ 4330, 6127, 5549, 9249, 11226, 28592}, +-{ -9586, -8825, 236, 1009, 455, -964}, +-{ 6829, 19290, -1018, 200, 1821, 578}, +-{ 5196, 957, 10372, 3330, -12800, -127}, +-{ -3022, -8193, -14557, 22061, 5920, 1053}, +-{ 10982, 25942, -24546, -23278, -11905, -6789}, +-{ 22667, -11010, 5736, 2567, 23705, -10253}, +-{ -3343, -4233, -5458, 20667, -10843, -3605}, +-{ -4131, -3612, 4575, -829, -350, -847}, +-{ -3303, 3451, -7398, -11604, 3023, 455}, +-{ 3200, -9547, 3202, -22893, 11184, -26466}, +-{ -14093, -4117, 15382, 14295, -10915, -20377}, +-{ 3807, -11016, 22052, 14370, -15328, -7733}, +-{ -6291, -17719, -1560, 12048, -19805, -443}, +-{ -6147, -4234, -160, 8363, 22638, 11911}, +-{ 19197, 1175, 7422, -9875, -4136, 4704}, +-{ -72, -7652, -112, -11955, -3230, 27175}, +-{ 3274, 5963, 7501, -17019, 866, -25452}, +-{ 737, 1861, 1833, 2022, 2384, 4755}, +-{ -5217, 7512, 3323, 2715, 3065, -1606}, +-{ 4247, 565, 5629, 2497, 18019, -4920}, +-{ -2833, -17920, -8062, 15738, -1018, 2136}, +-{ 3050, -19483, 16930, 29835, -10222, 15153}, +-{ -11346, 118, -25796, -13761, 15320, -468}, +-{ -4824, 4960, -4263, 1575, -10593, 19561}, +-{ -8203, -1409, -763, -1139, -607, 1408}, +-{ -2203, -11415, 2021, -6388, -2600, 711}, +-{ -413, -2511, -216, -3519, -28267, 1719}, +-{ -14446, 17050, 13917, 13499, -25762, -16121}, +-{ 19228, 7341, -12301, 682, -3791, -199}, +-{ -4193, 20746, -15651, 11349, 5860, -824}, +-{ -21490, -3546, -3, -1705, -3959, 9213}, +-{ 15445, -1876, 2012, -19627, 16228, -4845}, +-{ -2867, -3733, -7354, -175, -20119, 11174}, +-{ -3571, -24587, 19700, 6654, 979, -654}, +-{ 21820, -7430, -6639, -10767, -8362, 15543}, +-{ 14827, 17977, -7204, -3409, 1906, -17288}, +-{ 3525, -3947, -1415, -2798, 17648, 2082}, +-{ -6580, -15255, -17913, 1337, 15338, 21158}, +-{ 6210, 9698, 15155, -24666, -22507, -3999}, +-{ -1740, -593, 1095, -7779, 25058, 5601}, +-{ 21415, -432, -1658, -6898, -1438, -14454}, +-{ -6943, 700, -12139, -745, -24187, 22466}, +-{ 6287, 3283, 11006, 3844, 19184, 14781}, +-{ -22502, 15274, 5443, -2808, -970, -3343}, +-{ 3257, -3708, 4744, -8301, 22814, -10208}, +-{ 24346, -20970, 19846, 987, -11958, -6277}, +-{ 3906, -19701, 13060, -1609, 18641, 7466}, +-{ -26409, -22549, 16305, 2014, 10975, 18032}, +-{ -7039, 4655, -14818, 18739, 15789, 1296}, +-{ 9310, -1681, 14667, -3326, 26535, -11853}, +-{ 5728, 5917, 13400, 10020, -2236, -24704}, +-{ 1741, -6727, 12695, -22009, 4080, 5450}, +-{ -2621, 9393, 21143, -25938, -3162, -2529}, +-{ 20672, 18894, -13939, 6990, -8260, 15811}, +-{ -23818, 11183, -13639, 11868, 16045, 2630}, +-{ 18361, -10220, 829, 856, -1010, 157}, +-{ 14400, -4678, 5153, -13290, -27434, -11028}, +-{ 21613, 11256, 17453, 7604, 13130, -484}, +-{ 7, 1236, 573, 4214, 5576, -3081}, +-{ 916, -9092, 1285, -8958, 1185, -28699}, +-{ 21587, 23695, 19116, -2885, -14282, -8438}, +-{ 23414, -6161, 12978, 3061, -9351, 2236}, +-{ -3070, -7344, -20140, 5788, 582, -551}, +-{ -3993, 315, -7773, 8224, -28082, -12465}, +-{ 13766, -15357, 19205, -20624, 13043, -19247}, +-{ 3777, -177, 8029, -1001, 17812, 5162}, +-{ -7308, -4327, -18096, -620, -1350, 14932}, +-{ 14756, -1221, -12819, -14922, -547, 27125}, +-{ 2234, 1708, 2764, 5416, 7986, -25163}, +-{ 2873, 3636, 3992, 5344, 10142, 21259}, +-{ 1158, 5379, 508, -10514, 290, -1615}, +-{ 1114, 24789, 16575, -25168, -298, -2832}, +-{ -1107, -6144, -1918, -7791, -2971, -23276}, +-{ 4016, 10793, 17317, -4342, -20982, -3383}, +-{ -4494, -207, -9951, -3575, 7947, 1154}, +-{ -7576, 8117, -14047, 16982, -26457, -27540}, +-{ -15164, 16096, -16844, -8886, -23720, 15906}, +-{ 24922, 5680, -1874, 420, 132, 117}, +-{ -506, -19310, -198, 412, -311, 752}, +-{ -1906, 3981, -7688, 16566, -19291, -14722}, +-{ -399, -729, -3807, -4196, -12395, 7639}, +-{ 3368, 2330, 9092, 23686, -10290, -1705}, +-{ -3148, 2596, -7986, 14602, -4807, 16627}, +-{ 8057, 1481, 49, 17205, 24869, 7474}, +-{ -19304, -513, 11905, 2346, 5588, 3365}, +-{ -5063, -21812, 11370, 10896, 4881, 261}, +-{ 4794, 20577, 5109, -6025, -8049, -1521}, +-{ 8125, -14756, 20639, -14918, 23941, -3650}, +-{ 12451, 1381, 3613, 8687, -24002, 4848}, +-{ 6726, 10643, 10086, 25217, -25159, -1065}, +-{ 6561, 13977, 2911, 21737, 16465, -26050}, +-{ -1776, 2575, -19606, -16800, 3032, 6679}, +-{ 15012, -17910, -8438, -21554, -27111, 11808}, +-{ 3448, -924, -15913, -1135, 5126, -20613}, +-{ 7720, 2226, 17463, 5434, 28942, 17552}, +-{ 1246, 15614, -11743, 24618, -17539, 3272}, +-{ 3215, 17950, 2783, -722, -22672, 5979}, +-{ -5678, -3184, -26087, 26034, 6583, 3302}, +-{ 20310, -3555, -2715, -444, -1487, 1526}, +-{ -20640, -21970, -12207, -25793, 8863, -1036}, +-{ 17888, 570, -16102, 8329, -2553, 15275}, +-{ -2677, 9950, -1879, 16477, -12762, -29007}, +-{ -120, -2221, 219, 97, 365, 35}, +-{ 1270, -718, 1480, -2689, 1930, -7527}, +-{ 1896, 8750, 1906, 18235, -12692, -6174}, +-{ -3733, 13713, -9882, -15960, -1376, -7146}, +-{ -10600, 8496, 15967, -8792, 7532, 20439}, +-{ 3041, -13457, 1032, -26952, 5787, 24984}, +-{ -4590, -8220, -9322, -6112, -17243, 25745}, +-{ -17808, 6970, 3752, 626, -114, 2178}, +-{ 4449, -4862, 7054, -5404, 4738, -2827}, +-{ 4922, -651, 18939, -9866, 848, 1886}, +-{ -336, -5410, 7234, 20444, -9583, -600}, +-{ 781, -19474, -12648, 6634, 1414, 450}, +-{ -3399, -16770, 11107, 13200, -5498, 21663}, +-{ -3265, 4859, -5961, 7530, -10837, 28086}, +-{ 10350, -12901, 25699, 25640, -639, 351}, +-{ 1163, 18763, -5466, -15087, -145, -1377}, +-{ -14477, 27229, -31383, -32653, 21439, -2894}, +-{ 15420, 18823, 22128, 19398, 22583, 13587}, +-{ -10674, 10710, 5089, -4756, 909, -20760}, +-{ -12948, -20660, 7410, 2722, 3427, 11585}, +-{ -1105, 18374, 19731, -9650, 22442, 19634}, +-{ -296, -6798, -14677, 21603, 19796, 21399}, +-{ -19350, -7501, 25446, 13144, 8588, -25298}, +-{ 3092, -10618, 20896, 9249, -3326, 1796}, +-{ -811, 1449, 3106, 4748, 12073, -14262}, +-{ -20720, 14275, -4332, -25838, -5781, -21149}, +-{ -5132, 10554, -14020, -22150, 2840, -554}, +-{ 25533, 17648, 14886, -21074, 2459, 25142}, +-{ -9370, -1788, -12862, -5870, -25811, -11023}, +-{ 6698, 819, 10313, 166, 27581, 523}, +-{ 101, -19388, 3413, 9638, 64, 806}, +-{ -2742, -17931, -2576, 22818, 8553, 1126}, +-{ 2972, 15203, 1792, 25434, -5728, -17265}, +-{ -1419, 1604, 4398, 11452, 1731, 23787}, +-{ -5136, 4625, -10653, 27981, 9897, -2510}, +-{ -10528, -28033, 2999, -1530, -832, -830}, +-{ -11133, -12511, 22206, -7243, -23578, -21698}, +-{ 16935, -21892, 1861, -9606, 9432, 19026}, +-{ 10277, 9516, 26815, 2010, -4943, -9080}, +-{ 5547, -2210, 14270, -15300, -19316, 1822}, +-{ -4850, -783, -8959, -3076, -20056, -3197}, +-{ 8232, -2794, -17752, 13308, 3229, -991}, +-{ -12237, -6581, 10315, -9552, 2260, -20648}, +-{ -7000, 5529, -7553, -7490, -10342, -10266}, +-{ 3641, 19479, -5972, -19097, -18570, 12805}, +-{ 1283, -4164, 4198, -28473, -2498, 1866}, +-{ 16047, 26826, -13053, -6316, 985, -1597}, +-{ -403, 13680, 6457, 25070, 27124, -20710}, +-{ -18070, -1790, -24986, 5953, -954, 26600}, +-{ -24224, -15383, 24788, 1953, -1136, 187}, +-{ -2289, 12505, -20738, -904, 18324, 21258}, +-{ 2658, -6140, 16179, 22276, -556, 2154}, +-{ -6087, 13950, -25682, -27713, 4049, -4795}, +-{ -21452, 26473, 19435, -9124, 895, 303}, +-{ -22200, -26177, -6026, 24729, -22926, -9030}, +-{ -14276, -15982, 23732, -22851, 9268, -3841}, +-{ 29482, 21923, -6213, 1679, -2059, -1120}, +-{ -435, 9802, -3891, 12359, -4288, -18971}, +-{ 19768, -86, 2467, 1990, -1021, -5354}, +-{ 20986, -8783, -5329, -23562, -4730, 2673}, +-{ -5095, 5605, -4629, 19150, 26037, -12259}, +-{ 972, 6858, 4551, 27949, -4025, -2272}, +-{ 6075, -3260, -4989, -373, -1571, -3730}, +-{ -7256, -12992, -8820, -5109, 23054, 5054}, +-{ 920, 2615, 7912, -7353, -4905, 20186}, +-{ -250, 5454, 3140, 6928, -18723, -2051}, +-{ -10299, -4372, 19608, 4879, -661, -1885}, +-{ 14816, -8603, -19815, 6135, -21210, 14108}, +-{ -11945, -2223, 5018, 11892, 22741, 406}, +-{ -13184, -2613, -13256, -22433, -12482, -8380}, +-{ 17066, 25267, -2273, 5056, -342, 145}, +-{ 8401, -17683, 19112, 10615, -19453, 17083}, +-{ 20821, -5700, 12298, -25598, 10391, 7692}, +-{ 4550, 15779, 17338, -19379, -4768, 1206}, +-{ -7723, 10836, -27164, -11439, 6835, -1776}, +-{ 2542, 3199, 4442, 17513, -3711, -914}, +-{ 20960, -16774, -5814, 11087, -70, 22961}, +-{ 3305, 2919, 6256, -4800, -20966, -3230}, +-{ 5924, -16547, 2183, 2733, 3446, -23306}, +-{ -6061, -194, -13852, -10971, 19488, 1029}, +-{ 4467, -5964, -19004, 1519, -359, 855}, +-{ -1581, -7607, 22070, -11580, -10032, 17102}, +-{ -12412, 2553, 4324, 22500, 5751, 12170}, +-{ -25127, 17996, -6384, 1180, 1182, 9622}, +-{ 23462, -8471, -4392, -2669, 7638, -16835}, +-{ -5511, -2887, -10757, -20883, 7246, 1053}, +-{ 2703, -20602, -7554, 7516, -7740, 5868}, +-{ 20670, 21901, 457, 14969, -17657, -11921}, +-{ 3603, -1595, -2177, -157, -43, 605}, +-{ 2513, 8954, 10527, 22559, -16100, -16041}, +-{ 6002, 4951, 6795, -4862, -22400, 18849}, +-{ 7590, -1693, -24688, -3404, 14169, 1214}, +-{ -4398, -6663, -6870, -10083, -24596, 9253}, +-{ 10468, 17751, -7748, 147, -6314, 4419}, +-{ 16187, -16557, -4119, 4302, 7625, 5409}, +-{ 3303, 2735, 7458, -19902, -2254, -3702}, +-{ -2077, 21609, 14870, 12545, -6081, -1764}, +-{ 4678, 11740, 2859, 6953, 1919, -3871}, +-{ 3522, -21853, -2469, -10453, 18893, -10742}, +-{ 3759, -10191, -4866, -2659, -17831, -1242}, +-{ 14991, 9351, 11870, -1573, -4848, 22549}, +-{ 9509, -27152, 10734, 20851, -26185, -17878}, +-{ -7170, -1392, -19495, 12746, 8198, -1988}, +-{ 1883, 28158, -846, -7235, 249, 233}, +-{ -7200, 669, -371, -2948, 23234, -5635}, +-{ 3141, 288, 3223, -1258, -98, -27607}, +-{ 17373, -23235, 5110, -11199, -2574, -11487}, +-{ -4928, 1518, -5456, 670, -18278, 1951}, +-{ 10334, -19865, -4649, 361, -160, -923}, +-{ 18732, 14264, -3155, -7485, -3328, 5959}, +-{ -3614, 21077, 7276, 3536, 8121, -1528}, +-{ -8422, 500, -19182, 18929, 26392, -1039}, +-{ 15639, 25668, 8375, 1903, 1945, -11979}, +-{ -2716, 3389, 26850, -4587, 1803, 22}, +-{ 1177, -655, 1233, -2128, 7844, 1767}, +-{ -761, 8209, -19290, -4593, 1923, -343}, +-{ -689, -3530, -3267, -3804, -2753, 18566}, +-{ -2110, 1962, -1353, 16643, 2765, -23102}, +-{ -433, 4905, 302, 13016, 15933, -5905}, +-{ 3203, 4126, 11181, -5496, -2529, -1160}, +-{ -1091, -6469, -1415, 5682, -268, 583}, +-{ -9405, -19572, 6216, 1658, 993, -75}, +-{ -1695, -4504, -2289, -4088, -6556, -16577}, +-{ 4760, -892, -10902, 6516, 24199, -6011}, +-{ -253, 1000, 63, -81, -115, -382}, +-{ -1333, 24224, -698, -4667, -2801, -19144}, +-{ -876, -28866, -21873, 12677, -6344, 3235}, +-{ 16847, 21145, -26172, -3183, -396, 230}, +-{ 18296, -7790, -12857, -679, -1473, 5}, +-{ -10488, 11429, 25805, -1122, 1401, -438}, +-{ 3782, -7429, 26720, 17567, 19257, 12542}, +-{ 6332, -746, 12789, 9316, -22542, -5354}, +-{ 3418, -22728, 26978, 18303, 1076, 956}, +-{ -27315, -2988, 920, 235, 2233, 81}, +-{ 6199, 5296, 16093, 14768, -8429, -1112}, +-{ -6432, 19244, 9921, -3253, 1278, -954}, +-{ 24213, 2049, -22931, 2585, -2410, -4216}, +-{ 9286, 14282, -19735, -3985, -2344, 1028}, +-{ -20128, 17993, -9458, 23012, -16983, 8625}, +-{ -6896, -20730, 3762, 17415, 22341, 19024}, +-{ 842, 24181, 25062, -5839, -78, 937}, +-{ -621, 19722, -24204, -1962, -14854, -56}, +-{ 22766, -5119, 17365, 23868, -19480, -6558}, +-{ -2158, 17490, -21435, 3340, -12819, -20295}, +-{ -9621, 17325, 715, 2265, -4123, -492}, +-{ 9156, 12947, 27303, -21175, -6072, -9457}, +-{ -13164, -23269, -14006, -4184, 6978, 2}, +-{ 938, -13381, 3520, -24297, 22902, 19589}, +-{ -4911, -19774, 19764, -9310, -12650, 3819}, +-{ -5462, -4249, -6987, -6260, -13943, -25150}, +-{ 9341, 10369, -13862, -6704, 22556, -519}, +-{ 6651, 18768, -4855, 12570, 14730, -10209}, +-{ -823, 18119, 398, -1582, -116, -363}, +-{ -6935, -12694, -28392, 8552, 6961, -239}, +-{ -2602, -4704, -1021, 2015, 5129, 23670}, +-{ -12559, -8190, -25028, 18544, 14179, 1663}, +-{ 3813, 21036, -9620, -5051, -1800, -1087}, +-{ -22057, 16675, 14960, 9459, 2786, 16991}, +-{ -26040, -19318, -6414, 1104, 5798, -18039}, +-{ -1737, 24825, 10417, -11087, 896, -5273}, +-{ -1855, 11661, -2803, 24809, -21435, -19792}, +-{ -23473, -16729, -5782, 5643, 2636, 4940}, +-{ -1724, 4388, -26673, -13695, 10570, -25895}, +-{ 15358, -19496, 26242, -18493, 1736, 8054}, +-{ 5684, 20890, 4091, -19100, -14588, -10468}, +-{ 17260, -16291, 14859, -17711, -19174, 12435}, +-{ -27185, -12573, 6743, -562, 976, -257}, +-{ 12395, -8618, -22248, -19843, 11013, 7762}, +-{ 3799, 11853, -27622, -8473, 1089, -1495}, +-{ 4141, -2182, -26720, -735, -774, 1469}, +-{ 3125, 13762, 4606, 29257, 18771, -9958}, +-{ -17465, -9445, -17562, -2530, -6435, -3726}, +-{ -1742, 4351, -6841, -19773, 9627, -10654}, +-{ 7251, 3525, 10835, 5601, 25198, -23348}, +-{ -10300, -17830, 631, 11640, 2044, -20878}, +-{ -873, -8502, -1063, -15674, -10693, 14934}, +-{ -15957, 28137, 5268, 477, -1053, 1158}, +-{ -1495, -8814, -5764, -24965, 25988, 7907}, +-{ -1038, -114, -2308, -1319, -6480, 1472}, +-{ 4895, -17897, -25850, 5301, -188, 1581}, +-{ 3200, 17225, 4346, 22101, -18543, 22028}, +-{ -10250, 545, -10932, 2276, -28070, 8118}, +-{ 15343, 2329, 9316, 20537, 14908, 21021}, +-{ 6329, 6130, -24508, 837, -8637, -5844}, +-{ 7386, -501, 10503, 20131, 11435, -4755}, +-{ -2745, 24174, -9274, 15273, -8389, -5835}, +-{ 2992, -2864, 6048, -7473, 11687, -19996}, +-{ -883, -11954, -9976, -21829, -4436, -27178}, +-{ 3458, 19626, 1280, 2597, 19849, 5255}, +-{ -5315, 19133, -14518, -8946, 13749, -1352}, +-{ 18642, 17655, 11001, 6817, -18418, 6336}, +-{ -1697, 2244, -4640, 3948, -12890, -5273}, +-{ 20428, 10542, 4170, -1012, 19439, 21691}, +-{ -2943, -19735, -4208, 1320, 909, -8897}, +-{ 9351, -8066, -2618, -12933, 26582, 3507}, +-{ 9705, -22628, 8311, 8167, -13293, 5608}, +-{ 3222, 3749, -1508, 165, -52, -196}, +-{ 102, -22744, -8832, 903, -11421, -14662}, +-{ -120, 5998, 19765, 13401, 3628, 5197}, +-{ 8528, 5827, -1066, 774, -39, -166}, +-{ 9411, -9476, 9581, -13004, 24456, 24900}, +-{ 17878, 2235, -21639, 20478, 4716, -7190}, +-{ -2482, 9511, 1611, -21943, 14230, -1289}, +-{ 9288, -2291, 23215, -3452, -10842, 11}, +-{ 9496, 3041, 5130, -3890, -21219, -22589}, +-{ 14262, -9838, 20195, 14019, 91, -17200}, +-{ -18591, 980, 17, 821, 120, -574}, +-{ 12285, -19269, 13742, 16373, -161, 6025}, +-{ -3364, 1530, -4005, 2454, -10872, -23839}, +-{ 105, 5085, -260, 5790, -588, 19170}, +-{ 4121, 4169, 13439, 14644, 20899, 7434}, +-{ -175, 13101, -3704, 23233, 3907, 10106}, +-{ -6101, 23467, 5204, -1341, 1599, 13174}, +-{ -3217, -3494, 15117, -8387, -11762, -4750}, +-{ 1146, 4675, -19378, 14917, -5091, 249}, +-{ -21506, 10136, -16473, -13305, 18382, -8601}, +-{ 628, 2447, 3344, 3130, -5115, 119}, +-{ 17900, -22422, -17633, 21967, -16293, -7676}, +-{ 16863, 24214, 5612, -3858, -809, 3822}, +-{ -2291, 10091, -2360, -25109, -1226, 312}, +-{ 2957, 11256, 26745, -13266, -3455, -1128}, +-{ -19762, -2708, 4604, 6355, 1638, 25501}, +-{ -19593, -7753, 3159, -85, -489, -1855}, +-{ 814, 12510, 19077, -4681, -2610, -1474}, +-{ -23408, -19027, 8137, 19878, 7912, -282}, +-{ 839, -19652, 11927, 27278, -3211, 2266}, +-{ 4020, -1110, 8226, -1274, 20922, 25060}, +-{ 26576, 325, -8693, -232, -2218, -699}, +-{ -11293, -4200, 1805, -6673, -22940, -1339}, +-{ -2005, -15886, -1047, -27687, -13235, 14370}, +-{ -22073, 1949, 13175, -15656, -1846, 8055}, +-{ 3039, 12025, 7132, -24632, 413, -2347}, +-{ -24048, -206, 12459, -6654, -417, -10091}, +-{ 18179, -23688, -20515, -16396, 7230, 763}, +-{ 5659, -5085, 13878, -23729, -11077, -19587}, +-{ 11340, 501, 25040, 7616, -19658, 1605}, +-{ -26650, 8878, 10544, 417, 1299, 261}, +-{ 14460, 11369, -3263, 9990, 8194, 18111}, +-{ 1355, -20838, -9196, -16060, -8559, -730}, +-{ -1918, -20937, -18293, -2461, -2651, 4316}, +-{ -2810, 24521, -10996, -25721, 308, -1234}, +-{ -9075, -17280, -1833, -29342, -24213, -16631}, +-{ -2843, 10165, -5339, -2888, 21858, -21340}, +-{ -15832, 14849, -23780, 5184, 10113, -20639}, +-{ -19535, -11361, 8413, 1486, -23658, -5759}, +-{ -7512, 1027, -20794, 13732, 19892, -21934}, +-{ -12132, -7022, -19175, -8840, 22125, -16490}, +-{ 1937, 5210, -6318, -23788, 13141, 11082}, +-{ -205, 6036, -380, 8658, -233, 28020}, +-{ -5523, 7477, 7635, 23595, 9763, -2590}, +-{ 21658, -28313, -3086, -300, -1032, 1744}, +-{ -22352, 16646, 208, 6665, -17400, -3028}, +-{ 18482, 9336, -2737, -19372, 407, -4389}, +-{ -4913, -17370, 18819, -17654, 13416, 15232}, +-{ 7749, 6368, 23135, -18174, 7584, -4248}, +-{ -1489, -6523, 586, -10157, 14964, 25568}, +-{ 3844, -6156, 4897, -13045, -22526, 5647}, +-{ -8491, -2105, -24774, 905, -9326, 1456}, +-{ -3040, -1476, 1166, -4428, 11236, 9204}, +-{ 3397, -1451, 13598, -15841, 24540, 5819}, +-{ 8483, -2993, 21547, -16916, 7741, 24018}, +-{ -14932, -23758, -5332, -6664, -4497, 13267}, +-{ 19379, 12916, -2142, -737, 21100, -22101}, +-{ 3393, -4629, 5735, -18913, -6969, 2687}, +-{ 1148, -16147, -21433, -28095, -630, -14449}, +-{ 7300, 672, 18530, -17452, -10149, 351}, +-{ 11356, -10974, 17212, 4624, 145, 17791}, +-{ -711, -3479, -2238, 15887, 2027, 0}, +-{ -28048, 1794, -593, -2758, -21852, 11535}, +-{ -19683, 4937, 22004, 21523, -3148, 1790}, +-{ 813, 8231, 2633, 11981, -3043, 22201}, +-{ 8952, -24760, -690, 14873, -2366, -5372}, +-{ 8406, -5439, -274, -642, -145, 778}, +-{ -6605, 7258, 20780, -23507, -18625, 22782}, +-{ -22896, -25488, 10020, -1614, 1508, -1393}, +-{ 7607, 407, -24678, -16385, -1804, -4699}, +-{ -10592, -19139, 10462, -3747, 8721, -6919}, +-{ 13010, 5292, -6230, -4884, -20904, -1797}, +-{ 16891, -13770, -465, 19343, -10741, -12959}, +-{ 25193, -14799, -5681, -521, -321, -1211}, +-{ 6917, -3093, 20183, -26903, -12026, 1295}, +-{ 305, 1992, 19457, -985, 25, -521}, +-{ 6707, -3698, 8365, -8687, 21921, -27166}, +-{ 4668, 5997, 7117, 11696, 24401, -10794}, +-{ 744, -9416, 19893, 1963, 7922, -9824}, +-{ 3430, 21282, -1736, 10844, 8821, 27015}, +-{ -8813, 1521, -24038, 1651, 7838, -1208}, +-{ 3911, -11221, 3273, -12541, 7168, 18402}, +-{ 21642, 9117, -11536, -5256, 7077, 2382}, +-{ 100, 3817, -6713, 1244, 1518, -321}, +-{ 7946, -18670, 10667, -4866, 727, 776}, +-{ -15883, -8150, -2087, 22739, 1567, -3482}, +-{ 4380, -2735, 8469, -7025, -11424, 1317}, +-{ 26970, 4393, 7665, 17561, -714, 650}, +-{ -16191, -835, 8365, 1795, -14314, 16297}, +-{ 4504, -10048, 7662, -26690, -17428, 2580}, +-{ 48, -3984, 564, -5871, 2658, -18658}, +-{ 12579, -26016, -15642, 2672, -1347, -887}, +-{ -4950, 4208, -6811, 2569, -20621, -8658}, +-{ -1836, -14818, -5571, -23322, -14800, 25867}, +-{ 5434, -28139, -2357, -2883, -570, 2431}, +-{ 13096, -2771, 24994, -12496, -24723, -1025}, +-{ -5676, -4339, 1908, 18628, -21323, 17366}, +-{ 27660, -27897, -15409, 1436, -7112, -2241}, +-{ 8019, 3847, 24568, -469, 9674, 10683}, +-{ -903, -10149, 1801, -21260, 4795, -8751}, +-{ 1122, -9582, 2625, 22791, 956, 882}, +-{ 7876, 19075, -9900, -24266, 7496, 9277}, +-{ 980, -26764, -5386, 5396, 1086, 1648}, +-{ 28838, -1270, -447, 5, -429, -20}, +-{ -15283, 6132, 22812, 1252, -9963, 511}, +-{ 851, 7925, -457, -12210, 4261, 7579}, +-{ -4530, 8452, -1246, 14501, -24951, -5760}, +-{ -17814, -10727, 9887, -23929, -13432, 1878}, +-{ -15049, 10165, 16491, -14603, -11712, -21156}, +-{ -3317, 840, -5683, 22413, 1994, 586}, +-{ 23158, -5788, -15043, -10372, -9271, -13523}, +-{ -773, -9509, -3993, -24264, 8463, 5804}, +-{ -8545, -703, -12440, -3985, -25122, -28147}, +-{ -16659, 16001, 2746, 1611, 5097, -1043}, +-{ 41, -7181, 19903, 31555, -32237, 13927}, +-{ -5658, 845, -12774, 5705, 16695, -86}, +-{ 5282, 14875, 27026, 21124, 15776, -10477}, +-{ 14712, 19648, -11487, -13361, -20196, -15229}, +-{ 8597, -9138, -626, 10891, -6015, 6346}, +-{ -1488, -1272, -1479, -1303, -3704, -5485}, +-{ -3370, 17871, -6604, 24930, 25886, -3127}, +-{ 8416, 27783, -1385, 5350, -4260, 19993}, +-{ 5688, 362, 17246, 3809, -3246, 1088}, +-{ -105, -29607, 2747, 15223, -167, 3722}, +-{ 3502, -3195, 8602, 7772, -1566, -915}, +-{ -491, 3257, -2423, 5522, 20606, -100}, +-{ -13948, -11368, -15375, -21866, -8520, 12221}, +-{ -616, 2424, -2023, 4398, -3805, 8108}, +-{ -7204, 21043, 21211, -9395, -19391, 896}, +-{ -5737, -15160, -21298, 17066, -1006, -366}, +-{ 6261, 3240, -11937, -16213, -15820, 6581}, +-{ -3155, 24796, 2733, -1257, -875, -1597}, +-{ -20469, 11094, 24071, -8987, 14136, 2220}, +-{ -14106, 11959, -22495, 4135, -1055, -5420}, +-{ 801, -2655, 60, -5324, -790, 5937}, +-{ -7372, -1764, -22433, -26060, 21707, 4178}, +-{ -5715, -6648, -14908, 1325, -24044, 1493}, +-{ -6024, -12488, 23930, 2950, 1601, 1173}, +-{ 19067, 17630, 17929, -10654, 10928, -4958}, +-{ 3231, -3284, 27336, 4174, -1683, 497}, +-}; +- +-const int16_t (* const ff_eac3_mantissa_vq[8])[6] = { +- NULL, +- vq_hebap1, +- vq_hebap2, +- vq_hebap3, +- vq_hebap4, +- vq_hebap5, +- vq_hebap6, +- vq_hebap7, +-}; +- +-/** +- * Table E2.14 Frame Exponent Strategy Combinations +- */ +-const uint8_t ff_eac3_frm_expstr[32][6] = { +-{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +-{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, +-{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, +-{ EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, +-{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, +-{ EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, +-{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +-{ EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE, EXP_D45}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D25, EXP_REUSE}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45, EXP_D45}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_REUSE}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE, EXP_D45}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D25, EXP_REUSE}, +-{ EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45, EXP_D45}, +-{ EXP_D45, EXP_D45, EXP_D15, EXP_REUSE, EXP_REUSE, EXP_REUSE}, +-{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE, EXP_D45}, +-{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D25, EXP_REUSE}, +-{ EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45, EXP_D45}, +-{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_REUSE}, +-{ EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE, EXP_D45}, +-{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D25, EXP_REUSE}, +-{ EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45, EXP_D45}, +-}; +- +-/** +- * Table E.25: Spectral Extension Attenuation Table +- * ff_eac3_spx_atten_tab[code][bin]=pow(2.0,(bin+1)*(code+1)/-15.0); +- */ +-const float ff_eac3_spx_atten_tab[32][3] = { +- { 0.954841603910416503f, 0.911722488558216804f, 0.870550563296124125f }, +- { 0.911722488558216804f, 0.831237896142787758f, 0.757858283255198995f }, +- { 0.870550563296124125f, 0.757858283255198995f, 0.659753955386447100f }, +- { 0.831237896142787758f, 0.690956439983888004f, 0.574349177498517438f }, +- { 0.793700525984099792f, 0.629960524947436595f, 0.500000000000000000f }, +- { 0.757858283255198995f, 0.574349177498517438f, 0.435275281648062062f }, +- { 0.723634618720189082f, 0.523647061410313364f, 0.378929141627599553f }, +- { 0.690956439983888004f, 0.477420801955208307f, 0.329876977693223550f }, +- { 0.659753955386447100f, 0.435275281648062062f, 0.287174588749258719f }, +- { 0.629960524947436595f, 0.396850262992049896f, 0.250000000000000000f }, +- { 0.601512518041058319f, 0.361817309360094541f, 0.217637640824031003f }, +- { 0.574349177498517438f, 0.329876977693223550f, 0.189464570813799776f }, +- { 0.548412489847312945f, 0.300756259020529160f, 0.164938488846611775f }, +- { 0.523647061410313364f, 0.274206244923656473f, 0.143587294374629387f }, +- { 0.500000000000000000f, 0.250000000000000000f, 0.125000000000000000f }, +- { 0.477420801955208307f, 0.227930622139554201f, 0.108818820412015502f }, +- { 0.455861244279108402f, 0.207809474035696939f, 0.094732285406899888f }, +- { 0.435275281648062062f, 0.189464570813799776f, 0.082469244423305887f }, +- { 0.415618948071393879f, 0.172739109995972029f, 0.071793647187314694f }, +- { 0.396850262992049896f, 0.157490131236859149f, 0.062500000000000000f }, +- { 0.378929141627599553f, 0.143587294374629387f, 0.054409410206007751f }, +- { 0.361817309360094541f, 0.130911765352578369f, 0.047366142703449930f }, +- { 0.345478219991944002f, 0.119355200488802049f, 0.041234622211652958f }, +- { 0.329876977693223550f, 0.108818820412015502f, 0.035896823593657347f }, +- { 0.314980262473718298f, 0.099212565748012460f, 0.031250000000000000f }, +- { 0.300756259020529160f, 0.090454327340023621f, 0.027204705103003875f }, +- { 0.287174588749258719f, 0.082469244423305887f, 0.023683071351724965f }, +- { 0.274206244923656473f, 0.075189064755132290f, 0.020617311105826479f }, +- { 0.261823530705156682f, 0.068551561230914118f, 0.017948411796828673f }, +- { 0.250000000000000000f, 0.062500000000000000f, 0.015625000000000000f }, +- { 0.238710400977604098f, 0.056982655534888536f, 0.013602352551501938f }, +- { 0.227930622139554201f, 0.051952368508924235f, 0.011841535675862483f } +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3dec_data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3dec_data.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-/* +- * E-AC-3 decoder tables +- * Copyright (c) 2007 Bartlomiej Wolowiec +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCODEC_EAC3DEC_DATA_H +-#define AVCODEC_EAC3DEC_DATA_H +- +-#include +- +-extern const uint8_t ff_eac3_bits_vs_hebap[20]; +-extern const int16_t ff_eac3_gaq_remap_1[12]; +-extern const int16_t ff_eac3_gaq_remap_2_4_a[9][2]; +-extern const int16_t ff_eac3_gaq_remap_2_4_b[9][2]; +- +-extern const int16_t (* const ff_eac3_mantissa_vq[8])[6]; +-extern const uint8_t ff_eac3_frm_expstr[32][6]; +-extern const float ff_eac3_spx_atten_tab[32][3]; +- +-#endif /* AVCODEC_EAC3DEC_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3enc.c 2012-05-14 14:08:53.688326980 +0200 +@@ -0,0 +1,262 @@ ++/* ++ * E-AC-3 encoder ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * E-AC-3 encoder ++ */ ++ ++#define CONFIG_AC3ENC_FLOAT 1 ++#include "ac3enc.h" ++#include "eac3enc.h" ++#include "eac3_data.h" ++ ++ ++#define AC3ENC_TYPE AC3ENC_TYPE_EAC3 ++#include "ac3enc_opts_template.c" ++static const AVClass eac3enc_class = { "E-AC-3 Encoder", av_default_item_name, ++ eac3_options, LIBAVUTIL_VERSION_INT }; ++ ++ ++/** ++ * LUT for finding a matching frame exponent strategy index from a set of ++ * exponent strategies for a single channel across all 6 blocks. ++ */ ++static int8_t eac3_frame_expstr_index_tab[3][4][4][4][4][4]; ++ ++ ++void ff_eac3_exponent_init(void) ++{ ++ int i; ++ ++ memset(eac3_frame_expstr_index_tab, -1, sizeof(eac3_frame_expstr_index_tab)); ++ for (i = 0; i < 32; i++) { ++ eac3_frame_expstr_index_tab[ff_eac3_frm_expstr[i][0]-1] ++ [ff_eac3_frm_expstr[i][1]] ++ [ff_eac3_frm_expstr[i][2]] ++ [ff_eac3_frm_expstr[i][3]] ++ [ff_eac3_frm_expstr[i][4]] ++ [ff_eac3_frm_expstr[i][5]] = i; ++ } ++} ++ ++ ++void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s) ++{ ++ int ch; ++ ++ if (s->num_blocks < 6) { ++ s->use_frame_exp_strategy = 0; ++ return; ++ } ++ ++ s->use_frame_exp_strategy = 1; ++ for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) { ++ int expstr = eac3_frame_expstr_index_tab[s->exp_strategy[ch][0]-1] ++ [s->exp_strategy[ch][1]] ++ [s->exp_strategy[ch][2]] ++ [s->exp_strategy[ch][3]] ++ [s->exp_strategy[ch][4]] ++ [s->exp_strategy[ch][5]]; ++ if (expstr < 0) { ++ s->use_frame_exp_strategy = 0; ++ break; ++ } ++ s->frame_exp_strategy[ch] = expstr; ++ } ++} ++ ++ ++ ++void ff_eac3_set_cpl_states(AC3EncodeContext *s) ++{ ++ int ch, blk; ++ int first_cpl_coords[AC3_MAX_CHANNELS]; ++ ++ /* set first cpl coords */ ++ for (ch = 1; ch <= s->fbw_channels; ch++) ++ first_cpl_coords[ch] = 1; ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (block->channel_in_cpl[ch]) { ++ if (first_cpl_coords[ch]) { ++ block->new_cpl_coords[ch] = 2; ++ first_cpl_coords[ch] = 0; ++ } ++ } else { ++ first_cpl_coords[ch] = 1; ++ } ++ } ++ } ++ ++ /* set first cpl leak */ ++ for (blk = 0; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ if (block->cpl_in_use) { ++ block->new_cpl_leak = 2; ++ break; ++ } ++ } ++} ++ ++ ++void ff_eac3_output_frame_header(AC3EncodeContext *s) ++{ ++ int blk, ch; ++ AC3EncOptions *opt = &s->options; ++ ++ put_bits(&s->pb, 16, 0x0b77); /* sync word */ ++ ++ /* BSI header */ ++ put_bits(&s->pb, 2, 0); /* stream type = independent */ ++ put_bits(&s->pb, 3, 0); /* substream id = 0 */ ++ put_bits(&s->pb, 11, (s->frame_size / 2) - 1); /* frame size */ ++ if (s->bit_alloc.sr_shift) { ++ put_bits(&s->pb, 2, 0x3); /* fscod2 */ ++ put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */ ++ } else { ++ put_bits(&s->pb, 2, s->bit_alloc.sr_code); /* sample rate code */ ++ put_bits(&s->pb, 2, s->num_blks_code); /* number of blocks */ ++ } ++ put_bits(&s->pb, 3, s->channel_mode); /* audio coding mode */ ++ put_bits(&s->pb, 1, s->lfe_on); /* LFE channel indicator */ ++ put_bits(&s->pb, 5, s->bitstream_id); /* bitstream id (EAC3=16) */ ++ put_bits(&s->pb, 5, -opt->dialogue_level); /* dialogue normalization level */ ++ put_bits(&s->pb, 1, 0); /* no compression gain */ ++ /* mixing metadata*/ ++ put_bits(&s->pb, 1, opt->eac3_mixing_metadata); ++ if (opt->eac3_mixing_metadata) { ++ if (s->channel_mode > AC3_CHMODE_STEREO) ++ put_bits(&s->pb, 2, opt->preferred_stereo_downmix); ++ if (s->has_center) { ++ put_bits(&s->pb, 3, s->ltrt_center_mix_level); ++ put_bits(&s->pb, 3, s->loro_center_mix_level); ++ } ++ if (s->has_surround) { ++ put_bits(&s->pb, 3, s->ltrt_surround_mix_level); ++ put_bits(&s->pb, 3, s->loro_surround_mix_level); ++ } ++ if (s->lfe_on) ++ put_bits(&s->pb, 1, 0); ++ put_bits(&s->pb, 1, 0); /* no program scale */ ++ put_bits(&s->pb, 1, 0); /* no ext program scale */ ++ put_bits(&s->pb, 2, 0); /* no mixing parameters */ ++ if (s->channel_mode < AC3_CHMODE_STEREO) ++ put_bits(&s->pb, 1, 0); /* no pan info */ ++ put_bits(&s->pb, 1, 0); /* no frame mix config info */ ++ } ++ /* info metadata*/ ++ put_bits(&s->pb, 1, opt->eac3_info_metadata); ++ if (opt->eac3_info_metadata) { ++ put_bits(&s->pb, 3, s->bitstream_mode); ++ put_bits(&s->pb, 1, opt->copyright); ++ put_bits(&s->pb, 1, opt->original); ++ if (s->channel_mode == AC3_CHMODE_STEREO) { ++ put_bits(&s->pb, 2, opt->dolby_surround_mode); ++ put_bits(&s->pb, 2, opt->dolby_headphone_mode); ++ } ++ if (s->channel_mode >= AC3_CHMODE_2F2R) ++ put_bits(&s->pb, 2, opt->dolby_surround_ex_mode); ++ put_bits(&s->pb, 1, opt->audio_production_info); ++ if (opt->audio_production_info) { ++ put_bits(&s->pb, 5, opt->mixing_level - 80); ++ put_bits(&s->pb, 2, opt->room_type); ++ put_bits(&s->pb, 1, opt->ad_converter_type); ++ } ++ put_bits(&s->pb, 1, 0); ++ } ++ if (s->num_blocks != 6) ++ put_bits(&s->pb, 1, !(s->avctx->frame_number % 6)); /* converter sync flag */ ++ put_bits(&s->pb, 1, 0); /* no additional bit stream info */ ++ ++ /* frame header */ ++ if (s->num_blocks == 6) { ++ put_bits(&s->pb, 1, !s->use_frame_exp_strategy);/* exponent strategy syntax */ ++ put_bits(&s->pb, 1, 0); /* aht enabled = no */ ++ } ++ put_bits(&s->pb, 2, 0); /* snr offset strategy = 1 */ ++ put_bits(&s->pb, 1, 0); /* transient pre-noise processing enabled = no */ ++ put_bits(&s->pb, 1, 0); /* block switch syntax enabled = no */ ++ put_bits(&s->pb, 1, 0); /* dither flag syntax enabled = no */ ++ put_bits(&s->pb, 1, 0); /* bit allocation model syntax enabled = no */ ++ put_bits(&s->pb, 1, 0); /* fast gain codes enabled = no */ ++ put_bits(&s->pb, 1, 0); /* dba syntax enabled = no */ ++ put_bits(&s->pb, 1, 0); /* skip field syntax enabled = no */ ++ put_bits(&s->pb, 1, 0); /* spx enabled = no */ ++ /* coupling strategy use flags */ ++ if (s->channel_mode > AC3_CHMODE_MONO) { ++ put_bits(&s->pb, 1, s->blocks[0].cpl_in_use); ++ for (blk = 1; blk < s->num_blocks; blk++) { ++ AC3Block *block = &s->blocks[blk]; ++ put_bits(&s->pb, 1, block->new_cpl_strategy); ++ if (block->new_cpl_strategy) ++ put_bits(&s->pb, 1, block->cpl_in_use); ++ } ++ } ++ /* exponent strategy */ ++ if (s->use_frame_exp_strategy) { ++ for (ch = !s->cpl_on; ch <= s->fbw_channels; ch++) ++ put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); ++ } else { ++ for (blk = 0; blk < s->num_blocks; blk++) ++ for (ch = !s->blocks[blk].cpl_in_use; ch <= s->fbw_channels; ch++) ++ put_bits(&s->pb, 2, s->exp_strategy[ch][blk]); ++ } ++ if (s->lfe_on) { ++ for (blk = 0; blk < s->num_blocks; blk++) ++ put_bits(&s->pb, 1, s->exp_strategy[s->lfe_channel][blk]); ++ } ++ /* E-AC-3 to AC-3 converter exponent strategy (not optional when num blocks == 6) */ ++ if (s->num_blocks != 6) { ++ put_bits(&s->pb, 1, 0); ++ } else { ++ for (ch = 1; ch <= s->fbw_channels; ch++) { ++ if (s->use_frame_exp_strategy) ++ put_bits(&s->pb, 5, s->frame_exp_strategy[ch]); ++ else ++ put_bits(&s->pb, 5, 0); ++ } ++ } ++ /* snr offsets */ ++ put_bits(&s->pb, 6, s->coarse_snr_offset); ++ put_bits(&s->pb, 4, s->fine_snr_offset[1]); ++ /* block start info */ ++ if (s->num_blocks > 1) ++ put_bits(&s->pb, 1, 0); ++} ++ ++ ++#if CONFIG_EAC3_ENCODER ++AVCodec ff_eac3_encoder = { ++ .name = "eac3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_EAC3, ++ .priv_data_size = sizeof(AC3EncodeContext), ++ .init = ff_ac3_encode_init, ++ .encode = ff_ac3_float_encode_frame, ++ .close = ff_ac3_encode_close, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52 E-AC-3"), ++ .priv_class = &eac3enc_class, ++ .channel_layouts = ff_ac3_channel_layouts, ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3enc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3enc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eac3enc.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eac3enc.h 2012-05-14 14:08:53.689327000 +0200 +@@ -0,0 +1,54 @@ ++/* ++ * E-AC-3 encoder ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * E-AC-3 encoder ++ */ ++ ++#ifndef AVCODEC_EAC3ENC_H ++#define AVCODEC_EAC3ENC_H ++ ++#include "ac3enc.h" ++ ++/** ++ * Initialize E-AC-3 exponent tables. ++ */ ++void ff_eac3_exponent_init(void); ++ ++/** ++ * Determine frame exponent strategy use and indices. ++ */ ++void ff_eac3_get_frame_exp_strategy(AC3EncodeContext *s); ++ ++/** ++ * Set coupling states. ++ * This determines whether certain flags must be written to the bitstream or ++ * whether they will be implicitly already known by the decoder. ++ */ ++void ff_eac3_set_cpl_states(AC3EncodeContext *s); ++ ++/** ++ * Write the E-AC-3 frame header to the output bitstream. ++ */ ++void ff_eac3_output_frame_header(AC3EncodeContext *s); ++ ++#endif /* AVCODEC_EAC3ENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eacmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eacmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eacmv.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eacmv.c 2012-05-14 14:08:53.690327020 +0200 +@@ -29,7 +29,7 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + typedef struct CmvContext { +@@ -43,6 +43,10 @@ + + static av_cold int cmv_decode_init(AVCodecContext *avctx){ + CmvContext *s = avctx->priv_data; ++ avcodec_get_frame_defaults(&s->frame); ++ avcodec_get_frame_defaults(&s->last_frame); ++ avcodec_get_frame_defaults(&s->last2_frame); ++ + s->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + return 0; +@@ -52,7 +56,7 @@ + unsigned char *dst = s->frame.data[0]; + int i; + +- for (i=0; i < s->avctx->height && buf+s->avctx->width<=buf_end; i++) { ++ for (i=0; i < s->avctx->height && buf_end - buf >= s->avctx->width; i++) { + memcpy(dst, buf, s->avctx->width); + dst += s->frame.linesize[0]; + buf += s->avctx->width; +@@ -84,7 +88,7 @@ + + i = 0; + for(y=0; yavctx->height/4; y++) +- for(x=0; xavctx->width/4 && buf+iavctx->width/4 && buf_end - buf > i; x++) { + if (buf[i]==0xFF) { + unsigned char *dst = s->frame.data[0] + (y*4)*s->frame.linesize[0] + x*4; + if (raw+16> 4)) - 7; +- cmv_motcomp(s->frame.data[0], s->frame.linesize[0], +- s->last_frame.data[0], s->last_frame.linesize[0], +- x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); ++ if (s->last_frame.data[0]) ++ cmv_motcomp(s->frame.data[0], s->frame.linesize[0], ++ s->last_frame.data[0], s->last_frame.linesize[0], ++ x*4, y*4, xoffset, yoffset, s->avctx->width, s->avctx->height); + } + i++; + } +@@ -118,7 +123,7 @@ + { + int pal_start, pal_count, i; + +- if(buf+16>=buf_end) { ++ if(buf_end - buf < 16) { + av_log(s->avctx, AV_LOG_WARNING, "truncated header\n"); + return; + } +@@ -135,8 +140,8 @@ + pal_count = AV_RL16(&buf[14]); + + buf += 16; +- for (i=pal_start; ipalette[i] = AV_RB24(buf); ++ for (i=pal_start; i= 3; i++) { ++ s->palette[i] = 0xFF << 24 | AV_RB24(buf); + buf += 3; + } + } +@@ -153,6 +158,9 @@ + CmvContext *s = avctx->priv_data; + const uint8_t *buf_end = buf + buf_size; + ++ if (buf_end - buf < EA_PREAMBLE_SIZE) ++ return AVERROR_INVALIDDATA; ++ + if (AV_RL32(buf)==MVIh_TAG||AV_RB32(buf)==MVIh_TAG) { + cmv_process_header(s, buf+EA_PREAMBLE_SIZE, buf_end); + return buf_size; +@@ -167,8 +175,10 @@ + FFSWAP(AVFrame, s->last_frame, s->last2_frame); + FFSWAP(AVFrame, s->frame, s->last_frame); + +- s->frame.reference = 1; +- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; ++ s->frame.reference = 3; ++ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | ++ FF_BUFFER_HINTS_READABLE | ++ FF_BUFFER_HINTS_PRESERVE; + if (avctx->get_buffer(avctx, &s->frame)<0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; +@@ -180,10 +190,10 @@ + if ((buf[0]&1)) { // subtype + cmv_decode_inter(s, buf+2, buf_end); + s->frame.key_frame = 0; +- s->frame.pict_type = FF_P_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_P; + }else{ + s->frame.key_frame = 1; +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + cmv_decode_intra(s, buf+2, buf_end); + } + +@@ -206,14 +216,13 @@ + } + + AVCodec ff_eacmv_decoder = { +- "eacmv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_CMV, +- sizeof(CmvContext), +- cmv_decode_init, +- NULL, +- cmv_decode_end, +- cmv_decode_frame, +- CODEC_CAP_DR1, ++ .name = "eacmv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_CMV, ++ .priv_data_size = sizeof(CmvContext), ++ .init = cmv_decode_init, ++ .close = cmv_decode_end, ++ .decode = cmv_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts CMV video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eamad.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eamad.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eamad.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eamad.c 2012-05-14 14:08:53.691327040 +0200 +@@ -22,9 +22,9 @@ + /** + * @file + * Electronic Arts Madcow Video Decoder +- * by Peter Ross ++ * @author Peter Ross + * +- * Technical details here: ++ * @see technical details at + * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_MAD + */ + +@@ -34,7 +34,7 @@ + #include "aandcttab.h" + #include "mpeg12.h" + #include "mpeg12data.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + #define EA_PREAMBLE_SIZE 8 + #define MADk_TAG MKTAG('M', 'A', 'D', 'k') /* MAD i-frame */ +@@ -85,15 +85,21 @@ + { + MpegEncContext *s = &t->s; + if (j < 4) { ++ unsigned offset = (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame.linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x; ++ if (offset >= (s->height - 7) * t->last_frame.linesize[0] - 7) ++ return; + comp(t->frame.data[0] + (mb_y*16 + ((j&2)<<2))*t->frame.linesize[0] + mb_x*16 + ((j&1)<<3), + t->frame.linesize[0], +- t->last_frame.data[0] + (mb_y*16 + ((j&2)<<2) + mv_y)*t->last_frame.linesize[0] + mb_x*16 + ((j&1)<<3) + mv_x, ++ t->last_frame.data[0] + offset, + t->last_frame.linesize[0], add); + } else if (!(s->avctx->flags & CODEC_FLAG_GRAY)) { + int index = j - 3; ++ unsigned offset = (mb_y * 8 + (mv_y/2))*t->last_frame.linesize[index] + mb_x * 8 + (mv_x/2); ++ if (offset >= (s->height/2 - 7) * t->last_frame.linesize[index] - 7) ++ return; + comp(t->frame.data[index] + (mb_y*8)*t->frame.linesize[index] + mb_x * 8, + t->frame.linesize[index], +- t->last_frame.data[index] + (mb_y * 8 + (mv_y/2))*t->last_frame.linesize[index] + mb_x * 8 + (mv_x/2), ++ t->last_frame.data[index] + offset, + t->last_frame.linesize[index], add); + } + } +@@ -113,7 +119,7 @@ + } + } + +-static inline void decode_block_intra(MadContext * t, DCTELEM * block) ++static inline int decode_block_intra(MadContext * t, DCTELEM * block) + { + MpegEncContext *s = &t->s; + int level, i, j, run; +@@ -164,13 +170,14 @@ + } + if (i > 63) { + av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); +- return; ++ return -1; + } + + block[j] = level; + } + CLOSE_READER(re, &s->gb); + } ++ return 0; + } + + static int decode_motion(GetBitContext *gb) +@@ -184,7 +191,7 @@ + return value; + } + +-static void decode_mb(MadContext *t, int inter) ++static int decode_mb(MadContext *t, int inter) + { + MpegEncContext *s = &t->s; + int mv_map = 0; +@@ -205,13 +212,16 @@ + for (j=0; j<6; j++) { + if (mv_map & (1<gb); +- comp_block(t, s->mb_x, s->mb_y, j, mv_x, mv_y, add); ++ if (t->last_frame.data[0]) ++ comp_block(t, s->mb_x, s->mb_y, j, mv_x, mv_y, add); + } else { + s->dsp.clear_block(t->block); +- decode_block_intra(t, t->block); ++ if(decode_block_intra(t, t->block) < 0) ++ return -1; + idct_put(t, t->block, s->mb_x, s->mb_y, j); + } + } ++ return 0; + } + + static void calc_intra_matrix(MadContext *t, int qscale) +@@ -261,14 +271,18 @@ + buf += 16; + + if (avctx->width != s->width || avctx->height != s->height) { ++ if((s->width * s->height)/2048*7 > buf_end-buf) ++ return -1; + if (av_image_check_size(s->width, s->height, 0, avctx) < 0) + return -1; + avcodec_set_dimensions(avctx, s->width, s->height); + if (t->frame.data[0]) + avctx->release_buffer(avctx, &t->frame); ++ if (t->last_frame.data[0]) ++ avctx->release_buffer(avctx, &t->last_frame); + } + +- t->frame.reference = 1; ++ t->frame.reference = 3; + if (!t->frame.data[0]) { + if (avctx->get_buffer(avctx, &t->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +@@ -280,11 +294,13 @@ + if (!t->bitstream_buf) + return AVERROR(ENOMEM); + bswap16_buf(t->bitstream_buf, (const uint16_t*)buf, (buf_end-buf)/2); ++ memset((uint8_t*)t->bitstream_buf + (buf_end-buf), 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&s->gb, t->bitstream_buf, 8*(buf_end-buf)); + + for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++) + for (s->mb_x=0; s->mb_x < (avctx->width +15)/16; s->mb_x++) +- decode_mb(t, inter); ++ if(decode_mb(t, inter) < 0) ++ return -1; + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = t->frame; +@@ -307,14 +323,13 @@ + } + + AVCodec ff_eamad_decoder = { +- "eamad", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MAD, +- sizeof(MadContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "eamad", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MAD, ++ .priv_data_size = sizeof(MadContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Madcow Video") + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatgq.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatgq.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatgq.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatgq.c 2012-05-14 14:08:53.692327060 +0200 +@@ -29,7 +29,7 @@ + */ + + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "bytestream.h" + #include "dsputil.h" +@@ -43,6 +43,7 @@ + ScanTable scantable; + int qtable[64]; + DECLARE_ALIGNED(16, DCTELEM, block)[6][64]; ++ GetByteContext gb; + } TgqContext; + + static av_cold int tgq_decode_init(AVCodecContext *avctx){ +@@ -141,39 +142,36 @@ + } + } + +-static void tgq_decode_mb(TgqContext *s, int mb_y, int mb_x, const uint8_t **bs, const uint8_t *buf_end){ ++static void tgq_decode_mb(TgqContext *s, int mb_y, int mb_x){ + int mode; + int i; + int8_t dc[6]; + +- mode = bytestream_get_byte(bs); +- if (mode>buf_end-*bs) { +- av_log(s->avctx, AV_LOG_ERROR, "truncated macroblock\n"); +- return; +- } +- ++ mode = bytestream2_get_byte(&s->gb); + if (mode>12) { + GetBitContext gb; +- init_get_bits(&gb, *bs, mode*8); ++ init_get_bits(&gb, s->gb.buffer, FFMIN(s->gb.buffer_end - s->gb.buffer, mode) * 8); + for(i=0; i<6; i++) + tgq_decode_block(s, s->block[i], &gb); + tgq_idct_put_mb(s, s->block, mb_x, mb_y); ++ bytestream2_skip(&s->gb, mode); + }else{ + if (mode==3) { +- memset(dc, (*bs)[0], 4); +- dc[4] = (*bs)[1]; +- dc[5] = (*bs)[2]; ++ memset(dc, bytestream2_get_byte(&s->gb), 4); ++ dc[4] = bytestream2_get_byte(&s->gb); ++ dc[5] = bytestream2_get_byte(&s->gb); + }else if (mode==6) { +- memcpy(dc, *bs, 6); ++ bytestream2_get_buffer(&s->gb, dc, 6); + }else if (mode==12) { +- for(i=0; i<6; i++) +- dc[i] = (*bs)[i*2]; ++ for (i = 0; i < 6; i++) { ++ dc[i] = bytestream2_get_byte(&s->gb); ++ bytestream2_skip(&s->gb, 1); ++ } + }else{ + av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode); + } + tgq_idct_put_mb_dconly(s, mb_x, mb_y, dc); + } +- *bs += mode; + } + + static void tgq_calculate_qtable(TgqContext *s, int quant){ +@@ -193,32 +191,34 @@ + AVPacket *avpkt){ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- const uint8_t *buf_start = buf; +- const uint8_t *buf_end = buf + buf_size; + TgqContext *s = avctx->priv_data; + int x,y; +- + int big_endian = AV_RL32(&buf[4]) > 0x000FFFFF; +- buf += 8; + +- if(8>buf_end-buf) { ++ if (buf_size < 16) { + av_log(avctx, AV_LOG_WARNING, "truncated header\n"); + return -1; + } +- s->width = big_endian ? AV_RB16(&buf[0]) : AV_RL16(&buf[0]); +- s->height = big_endian ? AV_RB16(&buf[2]) : AV_RL16(&buf[2]); ++ bytestream2_init(&s->gb, buf + 8, buf_size - 8); ++ if (big_endian) { ++ s->width = bytestream2_get_be16u(&s->gb); ++ s->height = bytestream2_get_be16u(&s->gb); ++ } else { ++ s->width = bytestream2_get_le16u(&s->gb); ++ s->height = bytestream2_get_le16u(&s->gb); ++ } + + if (s->avctx->width!=s->width || s->avctx->height!=s->height) { + avcodec_set_dimensions(s->avctx, s->width, s->height); + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + } +- tgq_calculate_qtable(s, buf[4]); +- buf += 8; ++ tgq_calculate_qtable(s, bytestream2_get_byteu(&s->gb)); ++ bytestream2_skip(&s->gb, 3); + + if (!s->frame.data[0]) { + s->frame.key_frame = 1; +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + if (avctx->get_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +@@ -226,14 +226,14 @@ + } + } + +- for (y=0; y<(avctx->height+15)/16; y++) +- for (x=0; x<(avctx->width+15)/16; x++) +- tgq_decode_mb(s, y, x, &buf, buf_end); ++ for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++) ++ for (x = 0; x < FFALIGN(avctx->width, 16) >> 4; x++) ++ tgq_decode_mb(s, y, x); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + +- return buf-buf_start; ++ return avpkt->size; + } + + static av_cold int tgq_decode_end(AVCodecContext *avctx){ +@@ -244,14 +244,13 @@ + } + + AVCodec ff_eatgq_decoder = { +- "eatgq", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TGQ, +- sizeof(TgqContext), +- tgq_decode_init, +- NULL, +- tgq_decode_end, +- tgq_decode_frame, +- CODEC_CAP_DR1, ++ .name = "eatgq", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TGQ, ++ .priv_data_size = sizeof(TgqContext), ++ .init = tgq_decode_init, ++ .close = tgq_decode_end, ++ .decode = tgq_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGQ video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatgv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatgv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatgv.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatgv.c 2012-05-14 14:08:53.693327080 +0200 +@@ -29,10 +29,10 @@ + */ + + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "libavutil/lzo.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + #define EA_PREAMBLE_SIZE 8 + #define kVGT_TAG MKTAG('k', 'V', 'G', 'T') +@@ -55,6 +55,8 @@ + s->avctx = avctx; + avctx->time_base = (AVRational){1, 15}; + avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&s->frame); ++ avcodec_get_frame_defaults(&s->last_frame); + return 0; + } + +@@ -72,7 +74,7 @@ + else + src += 2; + +- if (src+3>src_end) ++ if (src_end - src < 3) + return -1; + size = AV_RB24(src); + src += 3; +@@ -136,7 +138,7 @@ + * @return 0 on success, -1 on critical buffer underflow + */ + static int tgv_decode_inter(TgvContext * s, const uint8_t *buf, const uint8_t *buf_end){ +- unsigned char *frame0_end = s->last_frame.data[0] + s->avctx->width*s->last_frame.linesize[0]; ++ unsigned last_frame_size = s->avctx->height*s->last_frame.linesize[0]; + int num_mvs; + int num_blocks_raw; + int num_blocks_packed; +@@ -146,7 +148,7 @@ + int mvbits; + const unsigned char *blocks_raw; + +- if(buf+12>buf_end) ++ if(buf_end - buf < 12) + return -1; + + num_mvs = AV_RL16(&buf[0]); +@@ -155,7 +157,7 @@ + vector_bits = AV_RL16(&buf[6]); + buf += 12; + +- /* allocate codebook buffers as neccessary */ ++ /* allocate codebook buffers as necessary */ + if (num_mvs > s->num_mvs) { + s->mv_codebook = av_realloc(s->mv_codebook, num_mvs*2*sizeof(int)); + s->num_mvs = num_mvs; +@@ -169,7 +171,7 @@ + /* read motion vectors */ + mvbits = (num_mvs*2*10+31) & ~31; + +- if (buf+(mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed>buf_end) ++ if (buf_end - buf < (mvbits>>3)+16*num_blocks_raw+8*num_blocks_packed) + return -1; + + init_get_bits(&gb, buf, mvbits); +@@ -205,12 +207,14 @@ + int src_stride; + + if (vector < num_mvs) { +- src = s->last_frame.data[0] + +- (y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] + +- x*4 + s->mv_codebook[vector][0]; ++ unsigned offset = ++ (y*4 + s->mv_codebook[vector][1])*s->last_frame.linesize[0] + ++ x*4 + s->mv_codebook[vector][0]; ++ + src_stride = s->last_frame.linesize[0]; +- if (src+3*src_stride+3>=frame0_end) ++ if (offset >= last_frame_size - (3*src_stride+3)) + continue; ++ src = s->last_frame.data[0] + offset; + }else{ + int offset = vector - num_mvs; + if (offsetbuf_end) { ++ if(buf_end - buf < 12) { + av_log(avctx, AV_LOG_WARNING, "truncated header\n"); + return -1; + } +@@ -270,8 +277,8 @@ + + pal_count = AV_RL16(&buf[6]); + buf += 12; +- for(i=0; ipalette[i] = AV_RB24(buf); ++ for(i=0; i= 3; i++) { ++ s->palette[i] = 0xFF << 24 | AV_RB24(buf); + buf += 3; + } + } +@@ -282,11 +289,11 @@ + /* shuffle */ + FFSWAP(AVFrame, s->frame, s->last_frame); + if (!s->frame.data[0]) { +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID; + s->frame.linesize[0] = s->width; + +- /* allocate additional 12 bytes to accomodate av_memcpy_backptr() OUTBUF_PADDED optimisation */ ++ /* allocate additional 12 bytes to accommodate av_memcpy_backptr() OUTBUF_PADDED optimisation */ + s->frame.data[0] = av_malloc(s->width*s->height + 12); + if (!s->frame.data[0]) + return AVERROR(ENOMEM); +@@ -300,7 +307,7 @@ + + if(chunk_type==kVGT_TAG) { + s->frame.key_frame = 1; +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + if (unpack(buf, buf_end, s->frame.data[0], s->avctx->width, s->avctx->height)<0) { + av_log(avctx, AV_LOG_WARNING, "truncated intra frame\n"); + return -1; +@@ -311,7 +318,7 @@ + return buf_size; + } + s->frame.key_frame = 0; +- s->frame.pict_type = FF_P_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_P; + if (tgv_decode_inter(s, buf, buf_end)<0) { + av_log(avctx, AV_LOG_WARNING, "truncated inter frame\n"); + return -1; +@@ -335,13 +342,12 @@ + } + + AVCodec ff_eatgv_decoder = { +- "eatgv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TGV, +- sizeof(TgvContext), +- tgv_decode_init, +- NULL, +- tgv_decode_end, +- tgv_decode_frame, ++ .name = "eatgv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TGV, ++ .priv_data_size = sizeof(TgvContext), ++ .init = tgv_decode_init, ++ .close = tgv_decode_end, ++ .decode = tgv_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TGV video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatqi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatqi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/eatqi.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/eatqi.c 2012-05-14 14:08:53.694327101 +0200 +@@ -22,10 +22,8 @@ + /** + * @file + * Electronic Arts TQI Video Decoder +- * by Peter Ross +- * +- * Technical details here: +- * http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TQI ++ * @author Peter Ross ++ * @see http://wiki.multimedia.cx/index.php?title=Electronic_Arts_TQI + */ + + #include "avcodec.h" +@@ -59,12 +57,15 @@ + return 0; + } + +-static void tqi_decode_mb(MpegEncContext *s, DCTELEM (*block)[64]) ++static int tqi_decode_mb(MpegEncContext *s, DCTELEM (*block)[64]) + { + int n; + s->dsp.clear_blocks(block[0]); + for (n=0; n<6; n++) +- ff_mpeg1_decode_block_intra(s, block[n], n); ++ if(ff_mpeg1_decode_block_intra(s, block[n], n)<0) ++ return -1; ++ ++ return 0; + } + + static inline void tqi_idct_put(TqiContext *t, DCTELEM (*block)[64]) +@@ -126,7 +127,7 @@ + return -1; + } + +- av_fast_malloc(&t->bitstream_buf, &t->bitstream_buf_size, (buf_end-buf) + FF_INPUT_BUFFER_PADDING_SIZE); ++ av_fast_padded_malloc(&t->bitstream_buf, &t->bitstream_buf_size, buf_end-buf); + if (!t->bitstream_buf) + return AVERROR(ENOMEM); + s->dsp.bswap_buf(t->bitstream_buf, (const uint32_t*)buf, (buf_end-buf)/4); +@@ -136,7 +137,8 @@ + for (s->mb_y=0; s->mb_y<(avctx->height+15)/16; s->mb_y++) + for (s->mb_x=0; s->mb_x<(avctx->width+15)/16; s->mb_x++) + { +- tqi_decode_mb(s, t->block); ++ if(tqi_decode_mb(s, t->block) < 0) ++ break; + tqi_idct_put(t, t->block); + } + +@@ -155,14 +157,13 @@ + } + + AVCodec ff_eatqi_decoder = { +- "eatqi", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TQI, +- sizeof(TqiContext), +- tqi_decode_init, +- NULL, +- tqi_decode_end, +- tqi_decode_frame, +- CODEC_CAP_DR1, ++ .name = "eatqi", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TQI, ++ .priv_data_size = sizeof(TqiContext), ++ .init = tqi_decode_init, ++ .close = tqi_decode_end, ++ .decode = tqi_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts TQI Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/error_resilience.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/error_resilience.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/error_resilience.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/error_resilience.c 2012-05-14 14:08:53.700327222 +0200 +@@ -32,6 +32,7 @@ + #include "mpegvideo.h" + #include "h264.h" + #include "rectangle.h" ++#include "thread.h" + + /* + * H264 redefines mb_intra so it is not mistakely used (its uninitialized in h264) +@@ -39,26 +40,36 @@ + */ + #undef mb_intra + +-static void decode_mb(MpegEncContext *s, int ref){ +- s->dest[0] = s->current_picture.data[0] + (s->mb_y * 16* s->linesize ) + s->mb_x * 16; +- s->dest[1] = s->current_picture.data[1] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift); +- s->dest[2] = s->current_picture.data[2] + (s->mb_y * (16>>s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16>>s->chroma_x_shift); +- +- if(CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264){ +- H264Context *h= (void*)s; +- h->mb_xy= s->mb_x + s->mb_y*s->mb_stride; ++static void decode_mb(MpegEncContext *s, int ref) ++{ ++ s->dest[0] = s->current_picture.f.data[0] + (s->mb_y * 16 * s->linesize) + s->mb_x * 16; ++ s->dest[1] = s->current_picture.f.data[1] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift); ++ s->dest[2] = s->current_picture.f.data[2] + (s->mb_y * (16 >> s->chroma_y_shift) * s->uvlinesize) + s->mb_x * (16 >> s->chroma_x_shift); ++ ++ ff_init_block_index(s); ++ ff_update_block_index(s); ++ ++ if (CONFIG_H264_DECODER && s->codec_id == CODEC_ID_H264) { ++ H264Context *h = (void*)s; ++ h->mb_xy = s->mb_x + s->mb_y * s->mb_stride; + memset(h->non_zero_count_cache, 0, sizeof(h->non_zero_count_cache)); +- assert(ref>=0); +- if(ref >= h->ref_count[0]) //FIXME it is posible albeit uncommon that slice references differ between slices, we take the easy approuch and ignore it for now. If this turns out to have any relevance in practice then correct remapping should be added +- ref=0; +- fill_rectangle(&s->current_picture.ref_index[0][4*h->mb_xy], 2, 2, 2, ref, 1); ++ assert(ref >= 0); ++ /* FIXME: It is possible albeit uncommon that slice references ++ * differ between slices. We take the easy approach and ignore ++ * it for now. If this turns out to have any relevance in ++ * practice then correct remapping should be added. */ ++ if (ref >= h->ref_count[0]) ++ ref = 0; ++ fill_rectangle(&s->current_picture.f.ref_index[0][4 * h->mb_xy], ++ 2, 2, 2, ref, 1); + fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, ref, 1); +- fill_rectangle(h->mv_cache[0][ scan8[0] ], 4, 4, 8, pack16to32(s->mv[0][0][0],s->mv[0][0][1]), 4); ++ fill_rectangle(h->mv_cache[0][scan8[0]], 4, 4, 8, ++ pack16to32(s->mv[0][0][0], s->mv[0][0][1]), 4); + assert(!FRAME_MBAFF); + ff_h264_hl_decode_mb(h); +- }else{ +- assert(ref==0); +- MPV_decode_mb(s, s->block); ++ } else { ++ assert(ref == 0); ++ MPV_decode_mb(s, s->block); + } + } + +@@ -66,82 +77,89 @@ + * @param stride the number of MVs to get to the next row + * @param mv_step the number of MVs per row or column in a macroblock + */ +-static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride){ +- if(s->codec_id == CODEC_ID_H264){ +- H264Context *h= (void*)s; ++static void set_mv_strides(MpegEncContext *s, int *mv_step, int *stride) ++{ ++ if (s->codec_id == CODEC_ID_H264) { ++ H264Context *h = (void*)s; + assert(s->quarter_sample); +- *mv_step= 4; +- *stride= h->b_stride; +- }else{ +- *mv_step= 2; +- *stride= s->b8_stride; ++ *mv_step = 4; ++ *stride = h->b_stride; ++ } else { ++ *mv_step = 2; ++ *stride = s->b8_stride; + } + } + + /** +- * replaces the current MB with a flat dc only version. ++ * Replace the current MB with a flat dc-only version. + */ +-static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, int mb_x, int mb_y) ++static void put_dc(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, ++ uint8_t *dest_cr, int mb_x, int mb_y) + { + int dc, dcu, dcv, y, i; +- for(i=0; i<4; i++){ +- dc= s->dc_val[0][mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*s->b8_stride]; +- if(dc<0) dc=0; +- else if(dc>2040) dc=2040; +- for(y=0; y<8; y++){ ++ for (i = 0; i < 4; i++) { ++ dc = s->dc_val[0][mb_x * 2 + (i & 1) + (mb_y * 2 + (i >> 1)) * s->b8_stride]; ++ if (dc < 0) ++ dc = 0; ++ else if (dc > 2040) ++ dc = 2040; ++ for (y = 0; y < 8; y++) { + int x; +- for(x=0; x<8; x++){ +- dest_y[x + (i&1)*8 + (y + (i>>1)*8)*s->linesize]= dc/8; +- } ++ for (x = 0; x < 8; x++) ++ dest_y[x + (i & 1) * 8 + (y + (i >> 1) * 8) * s->linesize] = dc / 8; + } + } +- dcu = s->dc_val[1][mb_x + mb_y*s->mb_stride]; +- dcv = s->dc_val[2][mb_x + mb_y*s->mb_stride]; +- if (dcu<0 ) dcu=0; +- else if(dcu>2040) dcu=2040; +- if (dcv<0 ) dcv=0; +- else if(dcv>2040) dcv=2040; +- for(y=0; y<8; y++){ ++ dcu = s->dc_val[1][mb_x + mb_y * s->mb_stride]; ++ dcv = s->dc_val[2][mb_x + mb_y * s->mb_stride]; ++ if (dcu < 0) ++ dcu = 0; ++ else if (dcu > 2040) ++ dcu = 2040; ++ if (dcv < 0) ++ dcv = 0; ++ else if (dcv > 2040) ++ dcv = 2040; ++ for (y = 0; y < 8; y++) { + int x; +- for(x=0; x<8; x++){ +- dest_cb[x + y*(s->uvlinesize)]= dcu/8; +- dest_cr[x + y*(s->uvlinesize)]= dcv/8; ++ for (x = 0; x < 8; x++) { ++ dest_cb[x + y * s->uvlinesize] = dcu / 8; ++ dest_cr[x + y * s->uvlinesize] = dcv / 8; + } + } + } + +-static void filter181(int16_t *data, int width, int height, int stride){ +- int x,y; ++static void filter181(int16_t *data, int width, int height, int stride) ++{ ++ int x, y; + + /* horizontal filter */ +- for(y=1; y>16; +- prev_dc= data[x + y*stride]; +- data[x + y*stride]= dc; ++ dc = -prev_dc + ++ data[x + y * stride] * 8 - ++ data[x + 1 + y * stride]; ++ dc = (dc * 10923 + 32768) >> 16; ++ prev_dc = data[x + y * stride]; ++ data[x + y * stride] = dc; + } + } + + /* vertical filter */ +- for(x=1; x>16; +- prev_dc= data[x + y*stride]; +- data[x + y*stride]= dc; ++ dc = -prev_dc + ++ data[x + y * stride] * 8 - ++ data[x + (y + 1) * stride]; ++ dc = (dc * 10923 + 32768) >> 16; ++ prev_dc = data[x + y * stride]; ++ data[x + y * stride] = dc; + } + } + } +@@ -151,83 +169,95 @@ + * @param w width in 8 pixel blocks + * @param h height in 8 pixel blocks + */ +-static void guess_dc(MpegEncContext *s, int16_t *dc, int w, int h, int stride, int is_luma){ ++static void guess_dc(MpegEncContext *s, int16_t *dc, int w, ++ int h, int stride, int is_luma) ++{ + int b_x, b_y; ++ int16_t (*col )[4] = av_malloc(stride*h*sizeof( int16_t)*4); ++ uint16_t (*dist)[4] = av_malloc(stride*h*sizeof(uint16_t)*4); + + for(b_y=0; b_y>is_luma) + (b_y>>is_luma)*s->mb_stride; +- +- error= s->error_status_table[mb_index]; +- +- if(IS_INTER(s->current_picture.mb_type[mb_index])) continue; //inter +- if(!(error&DC_ERROR)) continue; //dc-ok +- +- /* right block */ +- for(j=b_x+1; j>is_luma) + (b_y>>is_luma)*s->mb_stride; +- int error_j= s->error_status_table[mb_index_j]; +- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]); +- if(intra_j==0 || !(error_j&DC_ERROR)){ +- color[0]= dc[j + b_y*stride]; +- distance[0]= j-b_x; +- break; +- } ++ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; ++ int error_j= s->error_status_table[mb_index_j]; ++ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); ++ if(intra_j==0 || !(error_j&ER_DC_ERROR)){ ++ color= dc[b_x + b_y*stride]; ++ distance= b_x; + } +- +- /* left block */ +- for(j=b_x-1; j>=0; j--){ +- int mb_index_j= (j>>is_luma) + (b_y>>is_luma)*s->mb_stride; +- int error_j= s->error_status_table[mb_index_j]; +- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]); +- if(intra_j==0 || !(error_j&DC_ERROR)){ +- color[1]= dc[j + b_y*stride]; +- distance[1]= b_x-j; +- break; +- } ++ col [b_x + b_y*stride][1]= color; ++ dist[b_x + b_y*stride][1]= distance >= 0 ? b_x-distance : 9999; ++ } ++ color= 1024; ++ distance= -1; ++ for(b_x=w-1; b_x>=0; b_x--){ ++ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; ++ int error_j= s->error_status_table[mb_index_j]; ++ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); ++ if(intra_j==0 || !(error_j&ER_DC_ERROR)){ ++ color= dc[b_x + b_y*stride]; ++ distance= b_x; + } +- +- /* bottom block */ +- for(j=b_y+1; j>is_luma) + (j>>is_luma)*s->mb_stride; +- int error_j= s->error_status_table[mb_index_j]; +- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]); +- if(intra_j==0 || !(error_j&DC_ERROR)){ +- color[2]= dc[b_x + j*stride]; +- distance[2]= j-b_y; +- break; +- } ++ col [b_x + b_y*stride][0]= color; ++ dist[b_x + b_y*stride][0]= distance >= 0 ? distance-b_x : 9999; ++ } ++ } ++ for(b_x=0; b_x>is_luma) + (b_y>>is_luma)*s->mb_stride; ++ int error_j= s->error_status_table[mb_index_j]; ++ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); ++ if(intra_j==0 || !(error_j&ER_DC_ERROR)){ ++ color= dc[b_x + b_y*stride]; ++ distance= b_y; + } +- +- /* top block */ +- for(j=b_y-1; j>=0; j--){ +- int mb_index_j= (b_x>>is_luma) + (j>>is_luma)*s->mb_stride; +- int error_j= s->error_status_table[mb_index_j]; +- int intra_j= IS_INTRA(s->current_picture.mb_type[mb_index_j]); +- if(intra_j==0 || !(error_j&DC_ERROR)){ +- color[3]= dc[b_x + j*stride]; +- distance[3]= b_y-j; +- break; +- } ++ col [b_x + b_y*stride][3]= color; ++ dist[b_x + b_y*stride][3]= distance >= 0 ? b_y-distance : 9999; ++ } ++ color= 1024; ++ distance= -1; ++ for(b_y=h-1; b_y>=0; b_y--){ ++ int mb_index_j= (b_x>>is_luma) + (b_y>>is_luma)*s->mb_stride; ++ int error_j= s->error_status_table[mb_index_j]; ++ int intra_j = IS_INTRA(s->current_picture.f.mb_type[mb_index_j]); ++ if(intra_j==0 || !(error_j&ER_DC_ERROR)){ ++ color= dc[b_x + b_y*stride]; ++ distance= b_y; + } ++ col [b_x + b_y*stride][2]= color; ++ dist[b_x + b_y*stride][2]= distance >= 0 ? distance-b_y : 9999; ++ } ++ } + +- weight_sum=0; +- guess=0; +- for(j=0; j<4; j++){ +- int64_t weight= 256*256*256*16/distance[j]; +- guess+= weight*(int64_t)color[j]; +- weight_sum+= weight; +- } +- guess= (guess + weight_sum/2) / weight_sum; ++ for (b_y = 0; b_y < h; b_y++) { ++ for (b_x = 0; b_x < w; b_x++) { ++ int mb_index, error, j; ++ int64_t guess, weight_sum; ++ mb_index = (b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride; ++ error = s->error_status_table[mb_index]; + +- dc[b_x + b_y*stride]= guess; ++ if (IS_INTER(s->current_picture.f.mb_type[mb_index])) ++ continue; // inter ++ if (!(error & ER_DC_ERROR)) ++ continue; // dc-ok ++ ++ weight_sum = 0; ++ guess = 0; ++ for (j = 0; j < 4; j++) { ++ int64_t weight = 256 * 256 * 256 * 16 / dist[b_x + b_y*stride][j]; ++ guess += weight*(int64_t)col[b_x + b_y*stride][j]; ++ weight_sum += weight; ++ } ++ guess = (guess + weight_sum / 2) / weight_sum; ++ dc[b_x + b_y * stride] = guess; + } + } ++ av_freep(&col); ++ av_freep(&dist); + } + + /** +@@ -235,58 +265,63 @@ + * @param w width in 8 pixel blocks + * @param h height in 8 pixel blocks + */ +-static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){ ++static void h_block_filter(MpegEncContext *s, uint8_t *dst, int w, ++ int h, int stride, int is_luma) ++{ + int b_x, b_y, mvx_stride, mvy_stride; + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + set_mv_strides(s, &mvx_stride, &mvy_stride); + mvx_stride >>= is_luma; + mvy_stride *= mvx_stride; + +- for(b_y=0; b_yerror_status_table[( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]; +- int right_status= s->error_status_table[((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]; +- int left_intra= IS_INTRA(s->current_picture.mb_type [( b_x >>is_luma) + (b_y>>is_luma)*s->mb_stride]); +- int right_intra= IS_INTRA(s->current_picture.mb_type [((b_x+1)>>is_luma) + (b_y>>is_luma)*s->mb_stride]); +- int left_damage = left_status&(DC_ERROR|AC_ERROR|MV_ERROR); +- int right_damage= right_status&(DC_ERROR|AC_ERROR|MV_ERROR); +- int offset= b_x*8 + b_y*stride*8; +- int16_t *left_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride* b_x ]; +- int16_t *right_mv= s->current_picture.motion_val[0][mvy_stride*b_y + mvx_stride*(b_x+1)]; +- +- if(!(left_damage||right_damage)) continue; // both undamaged +- +- if( (!left_intra) && (!right_intra) +- && FFABS(left_mv[0]-right_mv[0]) + FFABS(left_mv[1]+right_mv[1]) < 2) continue; +- +- for(y=0; y<8; y++){ +- int a,b,c,d; +- +- a= dst[offset + 7 + y*stride] - dst[offset + 6 + y*stride]; +- b= dst[offset + 8 + y*stride] - dst[offset + 7 + y*stride]; +- c= dst[offset + 9 + y*stride] - dst[offset + 8 + y*stride]; +- +- d= FFABS(b) - ((FFABS(a) + FFABS(c) + 1)>>1); +- d= FFMAX(d, 0); +- if(b<0) d= -d; +- +- if(d==0) continue; +- +- if(!(left_damage && right_damage)) +- d= d*16/9; +- +- if(left_damage){ +- dst[offset + 7 + y*stride] = cm[dst[offset + 7 + y*stride] + ((d*7)>>4)]; +- dst[offset + 6 + y*stride] = cm[dst[offset + 6 + y*stride] + ((d*5)>>4)]; +- dst[offset + 5 + y*stride] = cm[dst[offset + 5 + y*stride] + ((d*3)>>4)]; +- dst[offset + 4 + y*stride] = cm[dst[offset + 4 + y*stride] + ((d*1)>>4)]; ++ int left_status = s->error_status_table[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]; ++ int right_status = s->error_status_table[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]; ++ int left_intra = IS_INTRA(s->current_picture.f.mb_type[( b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]); ++ int right_intra = IS_INTRA(s->current_picture.f.mb_type[((b_x + 1) >> is_luma) + (b_y >> is_luma) * s->mb_stride]); ++ int left_damage = left_status & ER_MB_ERROR; ++ int right_damage = right_status & ER_MB_ERROR; ++ int offset = b_x * 8 + b_y * stride * 8; ++ int16_t *left_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; ++ int16_t *right_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * (b_x + 1)]; ++ if (!(left_damage || right_damage)) ++ continue; // both undamaged ++ if ((!left_intra) && (!right_intra) && ++ FFABS(left_mv[0] - right_mv[0]) + ++ FFABS(left_mv[1] + right_mv[1]) < 2) ++ continue; ++ ++ for (y = 0; y < 8; y++) { ++ int a, b, c, d; ++ ++ a = dst[offset + 7 + y * stride] - dst[offset + 6 + y * stride]; ++ b = dst[offset + 8 + y * stride] - dst[offset + 7 + y * stride]; ++ c = dst[offset + 9 + y * stride] - dst[offset + 8 + y * stride]; ++ ++ d = FFABS(b) - ((FFABS(a) + FFABS(c) + 1) >> 1); ++ d = FFMAX(d, 0); ++ if (b < 0) ++ d = -d; ++ ++ if (d == 0) ++ continue; ++ ++ if (!(left_damage && right_damage)) ++ d = d * 16 / 9; ++ ++ if (left_damage) { ++ dst[offset + 7 + y * stride] = cm[dst[offset + 7 + y * stride] + ((d * 7) >> 4)]; ++ dst[offset + 6 + y * stride] = cm[dst[offset + 6 + y * stride] + ((d * 5) >> 4)]; ++ dst[offset + 5 + y * stride] = cm[dst[offset + 5 + y * stride] + ((d * 3) >> 4)]; ++ dst[offset + 4 + y * stride] = cm[dst[offset + 4 + y * stride] + ((d * 1) >> 4)]; + } +- if(right_damage){ +- dst[offset + 8 + y*stride] = cm[dst[offset + 8 + y*stride] - ((d*7)>>4)]; +- dst[offset + 9 + y*stride] = cm[dst[offset + 9 + y*stride] - ((d*5)>>4)]; +- dst[offset + 10+ y*stride] = cm[dst[offset +10 + y*stride] - ((d*3)>>4)]; +- dst[offset + 11+ y*stride] = cm[dst[offset +11 + y*stride] - ((d*1)>>4)]; ++ if (right_damage) { ++ dst[offset + 8 + y * stride] = cm[dst[offset + 8 + y * stride] - ((d * 7) >> 4)]; ++ dst[offset + 9 + y * stride] = cm[dst[offset + 9 + y * stride] - ((d * 5) >> 4)]; ++ dst[offset + 10+ y * stride] = cm[dst[offset + 10 + y * stride] - ((d * 3) >> 4)]; ++ dst[offset + 11+ y * stride] = cm[dst[offset + 11 + y * stride] - ((d * 1) >> 4)]; + } + } + } +@@ -298,487 +333,610 @@ + * @param w width in 8 pixel blocks + * @param h height in 8 pixel blocks + */ +-static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, int stride, int is_luma){ ++static void v_block_filter(MpegEncContext *s, uint8_t *dst, int w, int h, ++ int stride, int is_luma) ++{ + int b_x, b_y, mvx_stride, mvy_stride; + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + set_mv_strides(s, &mvx_stride, &mvy_stride); + mvx_stride >>= is_luma; + mvy_stride *= mvx_stride; + +- for(b_y=0; b_yerror_status_table[(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]; +- int bottom_status= s->error_status_table[(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]; +- int top_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ( b_y >>is_luma)*s->mb_stride]); +- int bottom_intra= IS_INTRA(s->current_picture.mb_type [(b_x>>is_luma) + ((b_y+1)>>is_luma)*s->mb_stride]); +- int top_damage = top_status&(DC_ERROR|AC_ERROR|MV_ERROR); +- int bottom_damage= bottom_status&(DC_ERROR|AC_ERROR|MV_ERROR); +- int offset= b_x*8 + b_y*stride*8; +- int16_t *top_mv= s->current_picture.motion_val[0][mvy_stride* b_y + mvx_stride*b_x]; +- int16_t *bottom_mv= s->current_picture.motion_val[0][mvy_stride*(b_y+1) + mvx_stride*b_x]; +- +- if(!(top_damage||bottom_damage)) continue; // both undamaged +- +- if( (!top_intra) && (!bottom_intra) +- && FFABS(top_mv[0]-bottom_mv[0]) + FFABS(top_mv[1]+bottom_mv[1]) < 2) continue; +- +- for(x=0; x<8; x++){ +- int a,b,c,d; +- +- a= dst[offset + x + 7*stride] - dst[offset + x + 6*stride]; +- b= dst[offset + x + 8*stride] - dst[offset + x + 7*stride]; +- c= dst[offset + x + 9*stride] - dst[offset + x + 8*stride]; +- +- d= FFABS(b) - ((FFABS(a) + FFABS(c)+1)>>1); +- d= FFMAX(d, 0); +- if(b<0) d= -d; +- +- if(d==0) continue; +- +- if(!(top_damage && bottom_damage)) +- d= d*16/9; +- +- if(top_damage){ +- dst[offset + x + 7*stride] = cm[dst[offset + x + 7*stride] + ((d*7)>>4)]; +- dst[offset + x + 6*stride] = cm[dst[offset + x + 6*stride] + ((d*5)>>4)]; +- dst[offset + x + 5*stride] = cm[dst[offset + x + 5*stride] + ((d*3)>>4)]; +- dst[offset + x + 4*stride] = cm[dst[offset + x + 4*stride] + ((d*1)>>4)]; ++ int top_status = s->error_status_table[(b_x >> is_luma) + (b_y >> is_luma) * s->mb_stride]; ++ int bottom_status = s->error_status_table[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]; ++ int top_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ( b_y >> is_luma) * s->mb_stride]); ++ int bottom_intra = IS_INTRA(s->current_picture.f.mb_type[(b_x >> is_luma) + ((b_y + 1) >> is_luma) * s->mb_stride]); ++ int top_damage = top_status & ER_MB_ERROR; ++ int bottom_damage = bottom_status & ER_MB_ERROR; ++ int offset = b_x * 8 + b_y * stride * 8; ++ ++ int16_t *top_mv = s->current_picture.f.motion_val[0][mvy_stride * b_y + mvx_stride * b_x]; ++ int16_t *bottom_mv = s->current_picture.f.motion_val[0][mvy_stride * (b_y + 1) + mvx_stride * b_x]; ++ ++ if (!(top_damage || bottom_damage)) ++ continue; // both undamaged ++ ++ if ((!top_intra) && (!bottom_intra) && ++ FFABS(top_mv[0] - bottom_mv[0]) + ++ FFABS(top_mv[1] + bottom_mv[1]) < 2) ++ continue; ++ ++ for (x = 0; x < 8; x++) { ++ int a, b, c, d; ++ ++ a = dst[offset + x + 7 * stride] - dst[offset + x + 6 * stride]; ++ b = dst[offset + x + 8 * stride] - dst[offset + x + 7 * stride]; ++ c = dst[offset + x + 9 * stride] - dst[offset + x + 8 * stride]; ++ ++ d = FFABS(b) - ((FFABS(a) + FFABS(c) + 1) >> 1); ++ d = FFMAX(d, 0); ++ if (b < 0) ++ d = -d; ++ ++ if (d == 0) ++ continue; ++ ++ if (!(top_damage && bottom_damage)) ++ d = d * 16 / 9; ++ ++ if (top_damage) { ++ dst[offset + x + 7 * stride] = cm[dst[offset + x + 7 * stride] + ((d * 7) >> 4)]; ++ dst[offset + x + 6 * stride] = cm[dst[offset + x + 6 * stride] + ((d * 5) >> 4)]; ++ dst[offset + x + 5 * stride] = cm[dst[offset + x + 5 * stride] + ((d * 3) >> 4)]; ++ dst[offset + x + 4 * stride] = cm[dst[offset + x + 4 * stride] + ((d * 1) >> 4)]; + } +- if(bottom_damage){ +- dst[offset + x + 8*stride] = cm[dst[offset + x + 8*stride] - ((d*7)>>4)]; +- dst[offset + x + 9*stride] = cm[dst[offset + x + 9*stride] - ((d*5)>>4)]; +- dst[offset + x + 10*stride] = cm[dst[offset + x + 10*stride] - ((d*3)>>4)]; +- dst[offset + x + 11*stride] = cm[dst[offset + x + 11*stride] - ((d*1)>>4)]; ++ if (bottom_damage) { ++ dst[offset + x + 8 * stride] = cm[dst[offset + x + 8 * stride] - ((d * 7) >> 4)]; ++ dst[offset + x + 9 * stride] = cm[dst[offset + x + 9 * stride] - ((d * 5) >> 4)]; ++ dst[offset + x + 10 * stride] = cm[dst[offset + x + 10 * stride] - ((d * 3) >> 4)]; ++ dst[offset + x + 11 * stride] = cm[dst[offset + x + 11 * stride] - ((d * 1) >> 4)]; + } + } + } + } + } + +-static void guess_mv(MpegEncContext *s){ +- uint8_t fixed[s->mb_stride * s->mb_height]; ++static void guess_mv(MpegEncContext *s) ++{ ++ uint8_t *fixed = av_malloc(s->mb_stride * s->mb_height); + #define MV_FROZEN 3 + #define MV_CHANGED 2 + #define MV_UNCHANGED 1 + const int mb_stride = s->mb_stride; +- const int mb_width = s->mb_width; +- const int mb_height= s->mb_height; ++ const int mb_width = s->mb_width; ++ const int mb_height = s->mb_height; + int i, depth, num_avail; + int mb_x, mb_y, mot_step, mot_stride; + + set_mv_strides(s, &mot_step, &mot_stride); + +- num_avail=0; +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[ i ]; +- int f=0; +- int error= s->error_status_table[mb_xy]; +- +- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) f=MV_FROZEN; //intra //FIXME check +- if(!(error&MV_ERROR)) f=MV_FROZEN; //inter with undamaged MV ++ num_avail = 0; ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int f = 0; ++ int error = s->error_status_table[mb_xy]; ++ ++ if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) ++ f = MV_FROZEN; // intra // FIXME check ++ if (!(error & ER_MV_ERROR)) ++ f = MV_FROZEN; // inter with undamaged MV + +- fixed[mb_xy]= f; +- if(f==MV_FROZEN) ++ fixed[mb_xy] = f; ++ if (f == MV_FROZEN) + num_avail++; ++ else if(s->last_picture.f.data[0] && s->last_picture.f.motion_val[0]){ ++ const int mb_y= mb_xy / s->mb_stride; ++ const int mb_x= mb_xy % s->mb_stride; ++ const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; ++ s->current_picture.f.motion_val[0][mot_index][0]= s->last_picture.f.motion_val[0][mot_index][0]; ++ s->current_picture.f.motion_val[0][mot_index][1]= s->last_picture.f.motion_val[0][mot_index][1]; ++ s->current_picture.f.ref_index[0][4*mb_xy] = s->last_picture.f.ref_index[0][4*mb_xy]; ++ } + } + +- if((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || num_avail <= mb_width/2){ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ +- const int mb_xy= mb_x + mb_y*s->mb_stride; +- +- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) continue; +- if(!(s->error_status_table[mb_xy]&MV_ERROR)) continue; +- +- s->mv_dir = s->last_picture.data[0] ? MV_DIR_FORWARD : MV_DIR_BACKWARD; +- s->mb_intra=0; +- s->mv_type = MV_TYPE_16X16; +- s->mb_skipped=0; ++ if ((!(s->avctx->error_concealment&FF_EC_GUESS_MVS)) || ++ num_avail <= mb_width / 2) { ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ s->mb_x = 0; ++ s->mb_y = mb_y; ++ ff_init_block_index(s); ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ ++ ff_update_block_index(s); ++ ++ if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) ++ continue; ++ if (!(s->error_status_table[mb_xy] & ER_MV_ERROR)) ++ continue; ++ ++ s->mv_dir = s->last_picture.f.data[0] ? MV_DIR_FORWARD ++ : MV_DIR_BACKWARD; ++ s->mb_intra = 0; ++ s->mv_type = MV_TYPE_16X16; ++ s->mb_skipped = 0; + + s->dsp.clear_blocks(s->block[0]); + +- s->mb_x= mb_x; +- s->mb_y= mb_y; +- s->mv[0][0][0]= 0; +- s->mv[0][0][1]= 0; ++ s->mb_x = mb_x; ++ s->mb_y = mb_y; ++ s->mv[0][0][0] = 0; ++ s->mv[0][0][1] = 0; + decode_mb(s, 0); + } + } +- return; ++ goto end; + } + +- for(depth=0;; depth++){ ++ for (depth = 0; ; depth++) { + int changed, pass, none_left; + +- none_left=1; +- changed=1; +- for(pass=0; (changed || pass<2) && pass<10; pass++){ ++ none_left = 1; ++ changed = 1; ++ for (pass = 0; (changed || pass < 2) && pass < 10; pass++) { + int mb_x, mb_y; +-int score_sum=0; ++ int score_sum = 0; + +- changed=0; +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ +- const int mb_xy= mb_x + mb_y*s->mb_stride; +- int mv_predictor[8][2]={{0}}; +- int ref[8]={0}; +- int pred_count=0; ++ changed = 0; ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ s->mb_x = 0; ++ s->mb_y = mb_y; ++ ff_init_block_index(s); ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ int mv_predictor[8][2] = { { 0 } }; ++ int ref[8] = { 0 }; ++ int pred_count = 0; + int j; +- int best_score=256*256*256*64; +- int best_pred=0; +- const int mot_index= (mb_x + mb_y*mot_stride) * mot_step; +- int prev_x= s->current_picture.motion_val[0][mot_index][0]; +- int prev_y= s->current_picture.motion_val[0][mot_index][1]; +- +- if((mb_x^mb_y^pass)&1) continue; +- +- if(fixed[mb_xy]==MV_FROZEN) continue; +- assert(!IS_INTRA(s->current_picture.mb_type[mb_xy])); +- assert(s->last_picture_ptr && s->last_picture_ptr->data[0]); +- +- j=0; +- if(mb_x>0 && fixed[mb_xy-1 ]==MV_FROZEN) j=1; +- if(mb_x+10 && fixed[mb_xy-mb_stride]==MV_FROZEN) j=1; +- if(mb_y+10 && fixed[mb_xy-1 ]==MV_CHANGED) j=1; +- if(mb_x+10 && fixed[mb_xy-mb_stride]==MV_CHANGED) j=1; +- if(mb_y+11) continue; +- +- none_left=0; +- +- if(mb_x>0 && fixed[mb_xy-1]){ +- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_step][0]; +- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_step][1]; +- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-1)]; ++ int best_score = 256 * 256 * 256 * 64; ++ int best_pred = 0; ++ const int mot_index = (mb_x + mb_y * mot_stride) * mot_step; ++ int prev_x, prev_y, prev_ref; ++ ++ ff_update_block_index(s); ++ ++ if ((mb_x ^ mb_y ^ pass) & 1) ++ continue; ++ ++ if (fixed[mb_xy] == MV_FROZEN) ++ continue; ++ assert(!IS_INTRA(s->current_picture.f.mb_type[mb_xy])); ++ assert(s->last_picture_ptr && s->last_picture_ptr->f.data[0]); ++ ++ j = 0; ++ if (mb_x > 0 && fixed[mb_xy - 1] == MV_FROZEN) ++ j = 1; ++ if (mb_x + 1 < mb_width && fixed[mb_xy + 1] == MV_FROZEN) ++ j = 1; ++ if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_FROZEN) ++ j = 1; ++ if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_FROZEN) ++ j = 1; ++ if (j == 0) ++ continue; ++ ++ j = 0; ++ if (mb_x > 0 && fixed[mb_xy - 1 ] == MV_CHANGED) ++ j = 1; ++ if (mb_x + 1 < mb_width && fixed[mb_xy + 1 ] == MV_CHANGED) ++ j = 1; ++ if (mb_y > 0 && fixed[mb_xy - mb_stride] == MV_CHANGED) ++ j = 1; ++ if (mb_y + 1 < mb_height && fixed[mb_xy + mb_stride] == MV_CHANGED) ++ j = 1; ++ if (j == 0 && pass > 1) ++ continue; ++ ++ none_left = 0; ++ ++ if (mb_x > 0 && fixed[mb_xy - 1]) { ++ mv_predictor[pred_count][0] = ++ s->current_picture.f.motion_val[0][mot_index - mot_step][0]; ++ mv_predictor[pred_count][1] = ++ s->current_picture.f.motion_val[0][mot_index - mot_step][1]; ++ ref[pred_count] = ++ s->current_picture.f.ref_index[0][4 * (mb_xy - 1)]; + pred_count++; + } +- if(mb_x+1current_picture.motion_val[0][mot_index + mot_step][0]; +- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_step][1]; +- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+1)]; ++ if (mb_x + 1 < mb_width && fixed[mb_xy + 1]) { ++ mv_predictor[pred_count][0] = ++ s->current_picture.f.motion_val[0][mot_index + mot_step][0]; ++ mv_predictor[pred_count][1] = ++ s->current_picture.f.motion_val[0][mot_index + mot_step][1]; ++ ref[pred_count] = ++ s->current_picture.f.ref_index[0][4 * (mb_xy + 1)]; + pred_count++; + } +- if(mb_y>0 && fixed[mb_xy-mb_stride]){ +- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][0]; +- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index - mot_stride*mot_step][1]; +- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy-s->mb_stride)]; ++ if (mb_y > 0 && fixed[mb_xy - mb_stride]) { ++ mv_predictor[pred_count][0] = ++ s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][0]; ++ mv_predictor[pred_count][1] = ++ s->current_picture.f.motion_val[0][mot_index - mot_stride * mot_step][1]; ++ ref[pred_count] = ++ s->current_picture.f.ref_index[0][4 * (mb_xy - s->mb_stride)]; + pred_count++; + } +- if(mb_y+1current_picture.motion_val[0][mot_index + mot_stride*mot_step][0]; +- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index + mot_stride*mot_step][1]; +- ref [pred_count] = s->current_picture.ref_index[0][4*(mb_xy+s->mb_stride)]; ++ if (mb_y + 1current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][0]; ++ mv_predictor[pred_count][1] = ++ s->current_picture.f.motion_val[0][mot_index + mot_stride * mot_step][1]; ++ ref[pred_count] = ++ s->current_picture.f.ref_index[0][4 * (mb_xy + s->mb_stride)]; + pred_count++; + } +- if(pred_count==0) continue; ++ if (pred_count == 0) ++ continue; + +- if(pred_count>1){ +- int sum_x=0, sum_y=0, sum_r=0; ++ if (pred_count > 1) { ++ int sum_x = 0, sum_y = 0, sum_r = 0; + int max_x, max_y, min_x, min_y, max_r, min_r; + +- for(j=0; j=3){ +- min_y= min_x= min_r= 99999; +- max_y= max_x= max_r=-99999; +- }else{ +- min_x=min_y=max_x=max_y=min_r=max_r=0; ++ if (pred_count >= 3) { ++ min_y = min_x = min_r = 99999; ++ max_y = max_x = max_r = -99999; ++ } else { ++ min_x = min_y = max_x = max_y = min_r = max_r = 0; + } +- for(j=0; javctx->codec_id == CODEC_ID_H264) { ++ // FIXME ++ } else { ++ ff_thread_await_progress((AVFrame *) s->last_picture_ptr, ++ mb_y, 0); ++ } ++ if (!s->last_picture.f.motion_val[0] || ++ !s->last_picture.f.ref_index[0]) ++ goto skip_last_mv; ++ prev_x = s->last_picture.f.motion_val[0][mot_index][0]; ++ prev_y = s->last_picture.f.motion_val[0][mot_index][1]; ++ prev_ref = s->last_picture.f.ref_index[0][4 * mb_xy]; ++ } else { ++ prev_x = s->current_picture.f.motion_val[0][mot_index][0]; ++ prev_y = s->current_picture.f.motion_val[0][mot_index][1]; ++ prev_ref = s->current_picture.f.ref_index[0][4 * mb_xy]; ++ } ++ + /* last MV */ +- mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0]; +- mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1]; +- ref [pred_count] = s->current_picture.ref_index[0][4*mb_xy]; ++ mv_predictor[pred_count][0] = prev_x; ++ mv_predictor[pred_count][1] = prev_y; ++ ref[pred_count] = prev_ref; + pred_count++; + +- s->mv_dir = MV_DIR_FORWARD; +- s->mb_intra=0; +- s->mv_type = MV_TYPE_16X16; +- s->mb_skipped=0; ++skip_last_mv: ++ s->mv_dir = MV_DIR_FORWARD; ++ s->mb_intra = 0; ++ s->mv_type = MV_TYPE_16X16; ++ s->mb_skipped = 0; + + s->dsp.clear_blocks(s->block[0]); + +- s->mb_x= mb_x; +- s->mb_y= mb_y; +- +- for(j=0; jcurrent_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; ++ s->mb_x = mb_x; ++ s->mb_y = mb_y; + +- s->current_picture.motion_val[0][mot_index][0]= s->mv[0][0][0]= mv_predictor[j][0]; +- s->current_picture.motion_val[0][mot_index][1]= s->mv[0][0][1]= mv_predictor[j][1]; ++ for (j = 0; j < pred_count; j++) { ++ int score = 0; ++ uint8_t *src = s->current_picture.f.data[0] + ++ mb_x * 16 + mb_y * 16 * s->linesize; ++ ++ s->current_picture.f.motion_val[0][mot_index][0] = ++ s->mv[0][0][0] = mv_predictor[j][0]; ++ s->current_picture.f.motion_val[0][mot_index][1] = ++ s->mv[0][0][1] = mv_predictor[j][1]; + +- if(ref[j]<0) //predictor intra or otherwise not available ++ // predictor intra or otherwise not available ++ if (ref[j] < 0) + continue; + + decode_mb(s, ref[j]); + +- if(mb_x>0 && fixed[mb_xy-1]){ ++ if (mb_x > 0 && fixed[mb_xy - 1]) { + int k; +- for(k=0; k<16; k++) +- score += FFABS(src[k*s->linesize-1 ]-src[k*s->linesize ]); ++ for (k = 0; k < 16; k++) ++ score += FFABS(src[k * s->linesize - 1] - ++ src[k * s->linesize]); + } +- if(mb_x+1linesize+15]-src[k*s->linesize+16]); ++ for (k = 0; k < 16; k++) ++ score += FFABS(src[k * s->linesize + 15] - ++ src[k * s->linesize + 16]); + } +- if(mb_y>0 && fixed[mb_xy-mb_stride]){ ++ if (mb_y > 0 && fixed[mb_xy - mb_stride]) { + int k; +- for(k=0; k<16; k++) +- score += FFABS(src[k-s->linesize ]-src[k ]); ++ for (k = 0; k < 16; k++) ++ score += FFABS(src[k - s->linesize] - src[k]); + } +- if(mb_y+1linesize*15]-src[k+s->linesize*16]); ++ for (k = 0; k < 16; k++) ++ score += FFABS(src[k + s->linesize * 15] - ++ src[k + s->linesize * 16]); + } + +- if(score <= best_score){ // <= will favor the last MV +- best_score= score; +- best_pred= j; ++ if (score <= best_score) { // <= will favor the last MV ++ best_score = score; ++ best_pred = j; + } + } +-score_sum+= best_score; +- s->mv[0][0][0]= mv_predictor[best_pred][0]; +- s->mv[0][0][1]= mv_predictor[best_pred][1]; +- +- for(i=0; icurrent_picture.motion_val[0][mot_index+i+j*mot_stride][0]= s->mv[0][0][0]; +- s->current_picture.motion_val[0][mot_index+i+j*mot_stride][1]= s->mv[0][0][1]; ++ score_sum += best_score; ++ s->mv[0][0][0] = mv_predictor[best_pred][0]; ++ s->mv[0][0][1] = mv_predictor[best_pred][1]; ++ ++ for (i = 0; i < mot_step; i++) ++ for (j = 0; j < mot_step; j++) { ++ s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][0] = s->mv[0][0][0]; ++ s->current_picture.f.motion_val[0][mot_index + i + j * mot_stride][1] = s->mv[0][0][1]; + } + + decode_mb(s, ref[best_pred]); + + +- if(s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y){ +- fixed[mb_xy]=MV_CHANGED; ++ if (s->mv[0][0][0] != prev_x || s->mv[0][0][1] != prev_y) { ++ fixed[mb_xy] = MV_CHANGED; + changed++; +- }else +- fixed[mb_xy]=MV_UNCHANGED; ++ } else ++ fixed[mb_xy] = MV_UNCHANGED; + } + } + +-// printf(".%d/%d", changed, score_sum); fflush(stdout); ++ // printf(".%d/%d", changed, score_sum); fflush(stdout); + } + +- if(none_left) +- return; ++ if (none_left) ++ goto end; + +- for(i=0; imb_num; i++){ +- int mb_xy= s->mb_index2xy[i]; +- if(fixed[mb_xy]) +- fixed[mb_xy]=MV_FROZEN; ++ for (i = 0; i < s->mb_num; i++) { ++ int mb_xy = s->mb_index2xy[i]; ++ if (fixed[mb_xy]) ++ fixed[mb_xy] = MV_FROZEN; + } +-// printf(":"); fflush(stdout); ++ // printf(":"); fflush(stdout); + } ++end: ++ av_free(fixed); + } + +-static int is_intra_more_likely(MpegEncContext *s){ ++static int is_intra_more_likely(MpegEncContext *s) ++{ + int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y; + +- if(!s->last_picture_ptr || !s->last_picture_ptr->data[0]) return 1; //no previous frame available -> use spatial prediction ++ if (!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) ++ return 1; // no previous frame available -> use spatial prediction + +- undamaged_count=0; +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- const int error= s->error_status_table[mb_xy]; +- if(!((error&DC_ERROR) && (error&MV_ERROR))) ++ undamaged_count = 0; ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ const int error = s->error_status_table[mb_xy]; ++ if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR))) + undamaged_count++; + } + +- if(s->codec_id == CODEC_ID_H264){ +- H264Context *h= (void*)s; +- if(h->ref_count[0] <= 0 || !h->ref_list[0][0].data[0]) ++ if (s->codec_id == CODEC_ID_H264) { ++ H264Context *h = (void*) s; ++ if (h->list_count <= 0 || h->ref_count[0] <= 0 || ++ !h->ref_list[0][0].f.data[0]) + return 1; + } + +- if(undamaged_count < 5) return 0; //almost all MBs damaged -> use temporal prediction ++ if (undamaged_count < 5) ++ return 0; // almost all MBs damaged -> use temporal prediction + +- //prevent dsp.sad() check, that requires access to the image +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration && s->pict_type == FF_I_TYPE) ++ // prevent dsp.sad() check, that requires access to the image ++ if (CONFIG_MPEG_XVMC_DECODER && ++ s->avctx->xvmc_acceleration && ++ s->pict_type == AV_PICTURE_TYPE_I) + return 1; + +- skip_amount= FFMAX(undamaged_count/50, 1); //check only upto 50 MBs +- is_intra_likely=0; ++ skip_amount = FFMAX(undamaged_count / 50, 1); // check only up to 50 MBs ++ is_intra_likely = 0; + +- j=0; +- for(mb_y= 0; mb_ymb_height-1; mb_y++){ +- for(mb_x= 0; mb_xmb_width; mb_x++){ ++ j = 0; ++ for (mb_y = 0; mb_y < s->mb_height - 1; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { + int error; +- const int mb_xy= mb_x + mb_y*s->mb_stride; ++ const int mb_xy = mb_x + mb_y * s->mb_stride; + +- error= s->error_status_table[mb_xy]; +- if((error&DC_ERROR) && (error&MV_ERROR)) +- continue; //skip damaged ++ error = s->error_status_table[mb_xy]; ++ if ((error & ER_DC_ERROR) && (error & ER_MV_ERROR)) ++ continue; // skip damaged + + j++; +- if((j%skip_amount) != 0) continue; //skip a few to speed things up +- +- if(s->pict_type==FF_I_TYPE){ +- uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; +- uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize; +- ++ // skip a few to speed things up ++ if ((j % skip_amount) != 0) ++ continue; ++ ++ if (s->pict_type == AV_PICTURE_TYPE_I) { ++ uint8_t *mb_ptr = s->current_picture.f.data[0] + ++ mb_x * 16 + mb_y * 16 * s->linesize; ++ uint8_t *last_mb_ptr = s->last_picture.f.data[0] + ++ mb_x * 16 + mb_y * 16 * s->linesize; ++ ++ if (s->avctx->codec_id == CODEC_ID_H264) { ++ // FIXME ++ } else { ++ ff_thread_await_progress((AVFrame *) s->last_picture_ptr, ++ mb_y, 0); ++ } + is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16); ++ // FIXME need await_progress() here + is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16); +- }else{ +- if(IS_INTRA(s->current_picture.mb_type[mb_xy])) ++ } else { ++ if (IS_INTRA(s->current_picture.f.mb_type[mb_xy])) + is_intra_likely++; + else + is_intra_likely--; + } + } + } +-//printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type); ++ // printf("is_intra_likely: %d type:%d\n", is_intra_likely, s->pict_type); + return is_intra_likely > 0; + } + +-void ff_er_frame_start(MpegEncContext *s){ +- if(!s->error_recognition) return; ++void ff_er_frame_start(MpegEncContext *s) ++{ ++ if (!s->err_recognition) ++ return; + +- memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t)); +- s->error_count= 3*s->mb_num; ++ memset(s->error_status_table, ER_MB_ERROR | VP_START | ER_MB_END, ++ s->mb_stride * s->mb_height * sizeof(uint8_t)); ++ s->error_count = 3 * s->mb_num; ++ s->error_occurred = 0; + } + + /** +- * adds a slice. +- * @param endx x component of the last macroblock, can be -1 for the last of the previous line +- * @param status the status at the end (MV_END, AC_ERROR, ...), it is assumed that no earlier end or +- * error of the same type occurred ++ * Add a slice. ++ * @param endx x component of the last macroblock, can be -1 ++ * for the last of the previous line ++ * @param status the status at the end (ER_MV_END, ER_AC_ERROR, ...), it is ++ * assumed that no earlier end or error of the same type occurred + */ +-void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int endy, int status){ +- const int start_i= av_clip(startx + starty * s->mb_width , 0, s->mb_num-1); +- const int end_i = av_clip(endx + endy * s->mb_width , 0, s->mb_num); +- const int start_xy= s->mb_index2xy[start_i]; +- const int end_xy = s->mb_index2xy[end_i]; +- int mask= -1; ++void ff_er_add_slice(MpegEncContext *s, int startx, int starty, ++ int endx, int endy, int status) ++{ ++ const int start_i = av_clip(startx + starty * s->mb_width, 0, s->mb_num - 1); ++ const int end_i = av_clip(endx + endy * s->mb_width, 0, s->mb_num); ++ const int start_xy = s->mb_index2xy[start_i]; ++ const int end_xy = s->mb_index2xy[end_i]; ++ int mask = -1; + +- if(s->avctx->hwaccel) ++ if (s->avctx->hwaccel) + return; + +- if(start_i > end_i || start_xy > end_xy){ +- av_log(s->avctx, AV_LOG_ERROR, "internal error, slice end before start\n"); ++ if (start_i > end_i || start_xy > end_xy) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "internal error, slice end before start\n"); + return; + } + +- if(!s->error_recognition) return; ++ if (!s->err_recognition) ++ return; + + mask &= ~VP_START; +- if(status & (AC_ERROR|AC_END)){ +- mask &= ~(AC_ERROR|AC_END); ++ if (status & (ER_AC_ERROR | ER_AC_END)) { ++ mask &= ~(ER_AC_ERROR | ER_AC_END); + s->error_count -= end_i - start_i + 1; + } +- if(status & (DC_ERROR|DC_END)){ +- mask &= ~(DC_ERROR|DC_END); ++ if (status & (ER_DC_ERROR | ER_DC_END)) { ++ mask &= ~(ER_DC_ERROR | ER_DC_END); + s->error_count -= end_i - start_i + 1; + } +- if(status & (MV_ERROR|MV_END)){ +- mask &= ~(MV_ERROR|MV_END); ++ if (status & (ER_MV_ERROR | ER_MV_END)) { ++ mask &= ~(ER_MV_ERROR | ER_MV_END); + s->error_count -= end_i - start_i + 1; + } + +- if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX; ++ if (status & ER_MB_ERROR) { ++ s->error_occurred = 1; ++ s->error_count = INT_MAX; ++ } + +- if(mask == ~0x7F){ +- memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t)); +- }else{ ++ if (mask == ~0x7F) { ++ memset(&s->error_status_table[start_xy], 0, ++ (end_xy - start_xy) * sizeof(uint8_t)); ++ } else { + int i; +- for(i=start_xy; ierror_status_table[ i ] &= mask; +- } ++ for (i = start_xy; i < end_xy; i++) ++ s->error_status_table[i] &= mask; + } + +- if(end_i == s->mb_num) +- s->error_count= INT_MAX; +- else{ ++ if (end_i == s->mb_num) ++ s->error_count = INT_MAX; ++ else { + s->error_status_table[end_xy] &= mask; + s->error_status_table[end_xy] |= status; + } + + s->error_status_table[start_xy] |= VP_START; + +- if(start_xy > 0 && s->avctx->thread_count <= 1 && s->avctx->skip_top*s->mb_width < start_i){ +- int prev_status= s->error_status_table[ s->mb_index2xy[start_i - 1] ]; ++ if (start_xy > 0 && s->avctx->thread_count <= 1 && ++ s->avctx->skip_top * s->mb_width < start_i) { ++ int prev_status = s->error_status_table[s->mb_index2xy[start_i - 1]]; + + prev_status &= ~ VP_START; +- if(prev_status != (MV_END|DC_END|AC_END)) s->error_count= INT_MAX; ++ if (prev_status != (ER_MV_END | ER_DC_END | ER_AC_END)) ++ s->error_count = INT_MAX; + } + } + +-void ff_er_frame_end(MpegEncContext *s){ ++void ff_er_frame_end(MpegEncContext *s) ++{ + int i, mb_x, mb_y, error, error_type, dc_error, mv_error, ac_error; + int distance; +- int threshold_part[4]= {100,100,100}; +- int threshold= 50; ++ int threshold_part[4] = { 100, 100, 100 }; ++ int threshold = 50; + int is_intra_likely; + int size = s->b8_stride * 2 * s->mb_height; +- Picture *pic= s->current_picture_ptr; ++ Picture *pic = s->current_picture_ptr; + +- if(!s->error_recognition || s->error_count==0 || s->avctx->lowres || +- s->avctx->hwaccel || +- s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU || +- s->picture_structure != PICT_FRAME || // we dont support ER of field pictures yet, though it should not crash if enabled +- s->error_count==3*s->mb_width*(s->avctx->skip_top + s->avctx->skip_bottom)) return; ++ /* We do not support ER of field pictures yet, ++ * though it should not crash if enabled. */ ++ if (!s->err_recognition || s->error_count == 0 || s->avctx->lowres || ++ s->avctx->hwaccel || ++ s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU || ++ s->picture_structure != PICT_FRAME || ++ s->error_count == 3 * s->mb_width * ++ (s->avctx->skip_top + s->avctx->skip_bottom)) { ++ return; ++ }; + +- if(s->current_picture.motion_val[0] == NULL){ ++ if (s->current_picture.f.motion_val[0] == NULL) { + av_log(s->avctx, AV_LOG_ERROR, "Warning MVs not available\n"); + +- for(i=0; i<2; i++){ +- pic->ref_index[i]= av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t)); +- pic->motion_val_base[i]= av_mallocz((size+4) * 2 * sizeof(uint16_t)); +- pic->motion_val[i]= pic->motion_val_base[i]+4; +- } +- pic->motion_subsample_log2= 3; +- s->current_picture= *s->current_picture_ptr; ++ for (i = 0; i < 2; i++) { ++ pic->f.ref_index[i] = av_mallocz(s->mb_stride * s->mb_height * 4 * sizeof(uint8_t)); ++ pic->motion_val_base[i] = av_mallocz((size + 4) * 2 * sizeof(uint16_t)); ++ pic->f.motion_val[i] = pic->motion_val_base[i] + 4; ++ } ++ pic->f.motion_subsample_log2 = 3; ++ s->current_picture = *s->current_picture_ptr; + } + +- if(s->avctx->debug&FF_DEBUG_ER){ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ +- int status= s->error_status_table[mb_x + mb_y*s->mb_stride]; ++ if (s->avctx->debug & FF_DEBUG_ER) { ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ int status = s->error_status_table[mb_x + mb_y * s->mb_stride]; + + av_log(s->avctx, AV_LOG_DEBUG, "%2X ", status); + } +@@ -788,281 +946,317 @@ + + #if 1 + /* handle overlapping slices */ +- for(error_type=1; error_type<=3; error_type++){ +- int end_ok=0; ++ for (error_type = 1; error_type <= 3; error_type++) { ++ int end_ok = 0; + +- for(i=s->mb_num-1; i>=0; i--){ +- const int mb_xy= s->mb_index2xy[i]; +- int error= s->error_status_table[mb_xy]; +- +- if(error&(1<mb_num - 1; i >= 0; i--) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int error = s->error_status_table[mb_xy]; ++ ++ if (error & (1 << error_type)) ++ end_ok = 1; ++ if (error & (8 << error_type)) ++ end_ok = 1; + +- if(!end_ok) +- s->error_status_table[mb_xy]|= 1<error_status_table[mb_xy] |= 1 << error_type; + +- if(error&VP_START) +- end_ok=0; ++ if (error & VP_START) ++ end_ok = 0; + } + } + #endif + #if 1 + /* handle slices with partitions of different length */ +- if(s->partitioned_frame){ +- int end_ok=0; ++ if (s->partitioned_frame) { ++ int end_ok = 0; + +- for(i=s->mb_num-1; i>=0; i--){ +- const int mb_xy= s->mb_index2xy[i]; +- int error= s->error_status_table[mb_xy]; +- +- if(error&AC_END) +- end_ok=0; +- if((error&MV_END) || (error&DC_END) || (error&AC_ERROR)) +- end_ok=1; ++ for (i = s->mb_num - 1; i >= 0; i--) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int error = s->error_status_table[mb_xy]; ++ ++ if (error & ER_AC_END) ++ end_ok = 0; ++ if ((error & ER_MV_END) || ++ (error & ER_DC_END) || ++ (error & ER_AC_ERROR)) ++ end_ok = 1; + +- if(!end_ok) +- s->error_status_table[mb_xy]|= AC_ERROR; ++ if (!end_ok) ++ s->error_status_table[mb_xy]|= ER_AC_ERROR; + +- if(error&VP_START) +- end_ok=0; ++ if (error & VP_START) ++ end_ok = 0; + } + } + #endif + /* handle missing slices */ +- if(s->error_recognition>=4){ +- int end_ok=1; ++ if (s->err_recognition & AV_EF_EXPLODE) { ++ int end_ok = 1; + +- for(i=s->mb_num-2; i>=s->mb_width+100; i--){ //FIXME +100 hack +- const int mb_xy= s->mb_index2xy[i]; +- int error1= s->error_status_table[mb_xy ]; +- int error2= s->error_status_table[s->mb_index2xy[i+1]]; +- +- if(error1&VP_START) +- end_ok=1; +- +- if( error2==(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) +- && error1!=(VP_START|DC_ERROR|AC_ERROR|MV_ERROR|AC_END|DC_END|MV_END) +- && ((error1&AC_END) || (error1&DC_END) || (error1&MV_END))){ //end & uninit +- end_ok=0; ++ // FIXME + 100 hack ++ for (i = s->mb_num - 2; i >= s->mb_width + 100; i--) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int error1 = s->error_status_table[mb_xy]; ++ int error2 = s->error_status_table[s->mb_index2xy[i + 1]]; ++ ++ if (error1 & VP_START) ++ end_ok = 1; ++ ++ if (error2 == (VP_START | ER_MB_ERROR | ER_MB_END) && ++ error1 != (VP_START | ER_MB_ERROR | ER_MB_END) && ++ ((error1 & ER_AC_END) || (error1 & ER_DC_END) || ++ (error1 & ER_MV_END))) { ++ // end & uninit ++ end_ok = 0; + } + +- if(!end_ok) +- s->error_status_table[mb_xy]|= DC_ERROR|AC_ERROR|MV_ERROR; ++ if (!end_ok) ++ s->error_status_table[mb_xy] |= ER_MB_ERROR; + } + } + + #if 1 + /* backward mark errors */ +- distance=9999999; +- for(error_type=1; error_type<=3; error_type++){ +- for(i=s->mb_num-1; i>=0; i--){ +- const int mb_xy= s->mb_index2xy[i]; +- int error= s->error_status_table[mb_xy]; ++ distance = 9999999; ++ for (error_type = 1; error_type <= 3; error_type++) { ++ for (i = s->mb_num - 1; i >= 0; i--) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int error = s->error_status_table[mb_xy]; + +- if(!s->mbskip_table[mb_xy]) //FIXME partition specific ++ if (!s->mbskip_table[mb_xy]) // FIXME partition specific + distance++; +- if(error&(1<partitioned_frame){ +- if(distance < threshold_part[error_type-1]) +- s->error_status_table[mb_xy]|= 1<error_status_table[mb_xy]|= 1<partitioned_frame) { ++ if (distance < threshold_part[error_type - 1]) ++ s->error_status_table[mb_xy] |= 1 << error_type; ++ } else { ++ if (distance < threshold) ++ s->error_status_table[mb_xy] |= 1 << error_type; + } + +- if(error&VP_START) +- distance= 9999999; ++ if (error & VP_START) ++ distance = 9999999; + } + } + #endif + + /* forward mark errors */ +- error=0; +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- int old_error= s->error_status_table[mb_xy]; +- +- if(old_error&VP_START) +- error= old_error& (DC_ERROR|AC_ERROR|MV_ERROR); +- else{ +- error|= old_error& (DC_ERROR|AC_ERROR|MV_ERROR); +- s->error_status_table[mb_xy]|= error; ++ error = 0; ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int old_error = s->error_status_table[mb_xy]; ++ ++ if (old_error & VP_START) { ++ error = old_error & ER_MB_ERROR; ++ } else { ++ error |= old_error & ER_MB_ERROR; ++ s->error_status_table[mb_xy] |= error; + } + } + #if 1 + /* handle not partitioned case */ +- if(!s->partitioned_frame){ +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- error= s->error_status_table[mb_xy]; +- if(error&(AC_ERROR|DC_ERROR|MV_ERROR)) +- error|= AC_ERROR|DC_ERROR|MV_ERROR; +- s->error_status_table[mb_xy]= error; ++ if (!s->partitioned_frame) { ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ error = s->error_status_table[mb_xy]; ++ if (error & ER_MB_ERROR) ++ error |= ER_MB_ERROR; ++ s->error_status_table[mb_xy] = error; + } + } + #endif + +- dc_error= ac_error= mv_error=0; +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- error= s->error_status_table[mb_xy]; +- if(error&DC_ERROR) dc_error ++; +- if(error&AC_ERROR) ac_error ++; +- if(error&MV_ERROR) mv_error ++; ++ dc_error = ac_error = mv_error = 0; ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ error = s->error_status_table[mb_xy]; ++ if (error & ER_DC_ERROR) ++ dc_error++; ++ if (error & ER_AC_ERROR) ++ ac_error++; ++ if (error & ER_MV_ERROR) ++ mv_error++; + } +- av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", dc_error, ac_error, mv_error); ++ av_log(s->avctx, AV_LOG_INFO, "concealing %d DC, %d AC, %d MV errors\n", ++ dc_error, ac_error, mv_error); + +- is_intra_likely= is_intra_more_likely(s); ++ is_intra_likely = is_intra_more_likely(s); + + /* set unknown mb-type to most likely */ +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- error= s->error_status_table[mb_xy]; +- if(!((error&DC_ERROR) && (error&MV_ERROR))) ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ error = s->error_status_table[mb_xy]; ++ if (!((error & ER_DC_ERROR) && (error & ER_MV_ERROR))) + continue; + +- if(is_intra_likely) +- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4; ++ if (is_intra_likely) ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; + else +- s->current_picture.mb_type[mb_xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_16x16 | MB_TYPE_L0; + } + + // change inter to intra blocks if no reference frames are available +- if (!s->last_picture.data[0] && !s->next_picture.data[0]) +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- if(!IS_INTRA(s->current_picture.mb_type[mb_xy])) +- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA4x4; ++ if (!s->last_picture.f.data[0] && !s->next_picture.f.data[0]) ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ if (!IS_INTRA(s->current_picture.f.mb_type[mb_xy])) ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA4x4; + } + + /* handle inter blocks with damaged AC */ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ +- const int mb_xy= mb_x + mb_y * s->mb_stride; +- const int mb_type= s->current_picture.mb_type[mb_xy]; +- int dir = !s->last_picture.data[0]; +- error= s->error_status_table[mb_xy]; +- +- if(IS_INTRA(mb_type)) continue; //intra +- if(error&MV_ERROR) continue; //inter with damaged MV +- if(!(error&AC_ERROR)) continue; //undamaged inter +- +- s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD; +- s->mb_intra=0; +- s->mb_skipped=0; +- if(IS_8X8(mb_type)){ +- int mb_index= mb_x*2 + mb_y*2*s->b8_stride; ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ s->mb_x = 0; ++ s->mb_y = mb_y; ++ ff_init_block_index(s); ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; ++ int dir = !s->last_picture.f.data[0]; ++ ++ ff_update_block_index(s); ++ ++ error = s->error_status_table[mb_xy]; ++ ++ if (IS_INTRA(mb_type)) ++ continue; // intra ++ if (error & ER_MV_ERROR) ++ continue; // inter with damaged MV ++ if (!(error & ER_AC_ERROR)) ++ continue; // undamaged inter ++ ++ s->mv_dir = dir ? MV_DIR_BACKWARD : MV_DIR_FORWARD; ++ s->mb_intra = 0; ++ s->mb_skipped = 0; ++ if (IS_8X8(mb_type)) { ++ int mb_index = mb_x * 2 + mb_y * 2 * s->b8_stride; + int j; + s->mv_type = MV_TYPE_8X8; +- for(j=0; j<4; j++){ +- s->mv[0][j][0] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][0]; +- s->mv[0][j][1] = s->current_picture.motion_val[dir][ mb_index + (j&1) + (j>>1)*s->b8_stride ][1]; ++ for (j = 0; j < 4; j++) { ++ s->mv[0][j][0] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][0]; ++ s->mv[0][j][1] = s->current_picture.f.motion_val[dir][mb_index + (j & 1) + (j >> 1) * s->b8_stride][1]; + } +- }else{ +- s->mv_type = MV_TYPE_16X16; +- s->mv[0][0][0] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][0]; +- s->mv[0][0][1] = s->current_picture.motion_val[dir][ mb_x*2 + mb_y*2*s->b8_stride ][1]; ++ } else { ++ s->mv_type = MV_TYPE_16X16; ++ s->mv[0][0][0] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][0]; ++ s->mv[0][0][1] = s->current_picture.f.motion_val[dir][mb_x * 2 + mb_y * 2 * s->b8_stride][1]; + } + + s->dsp.clear_blocks(s->block[0]); + +- s->mb_x= mb_x; +- s->mb_y= mb_y; +- decode_mb(s, 0/*FIXME h264 partitioned slices need this set*/); ++ s->mb_x = mb_x; ++ s->mb_y = mb_y; ++ decode_mb(s, 0 /* FIXME h264 partitioned slices need this set */); + } + } + + /* guess MVs */ +- if(s->pict_type==FF_B_TYPE){ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ +- int xy= mb_x*2 + mb_y*2*s->b8_stride; +- const int mb_xy= mb_x + mb_y * s->mb_stride; +- const int mb_type= s->current_picture.mb_type[mb_xy]; +- error= s->error_status_table[mb_xy]; +- +- if(IS_INTRA(mb_type)) continue; +- if(!(error&MV_ERROR)) continue; //inter with undamaged MV +- if(!(error&AC_ERROR)) continue; //undamaged inter +- +- s->mv_dir = MV_DIR_FORWARD|MV_DIR_BACKWARD; +- if(!s->last_picture.data[0]) s->mv_dir &= ~MV_DIR_FORWARD; +- if(!s->next_picture.data[0]) s->mv_dir &= ~MV_DIR_BACKWARD; +- s->mb_intra=0; +- s->mv_type = MV_TYPE_16X16; +- s->mb_skipped=0; +- +- if(s->pp_time){ +- int time_pp= s->pp_time; +- int time_pb= s->pb_time; +- +- s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp; +- s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp; +- s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp; +- s->mv[1][0][1] = s->next_picture.motion_val[0][xy][1]*(time_pb - time_pp)/time_pp; +- }else{ +- s->mv[0][0][0]= 0; +- s->mv[0][0][1]= 0; +- s->mv[1][0][0]= 0; +- s->mv[1][0][1]= 0; ++ if (s->pict_type == AV_PICTURE_TYPE_B) { ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ s->mb_x = 0; ++ s->mb_y = mb_y; ++ ff_init_block_index(s); ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ int xy = mb_x * 2 + mb_y * 2 * s->b8_stride; ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; ++ ++ ff_update_block_index(s); ++ ++ error = s->error_status_table[mb_xy]; ++ ++ if (IS_INTRA(mb_type)) ++ continue; ++ if (!(error & ER_MV_ERROR)) ++ continue; // inter with undamaged MV ++ if (!(error & ER_AC_ERROR)) ++ continue; // undamaged inter ++ ++ s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD; ++ if (!s->last_picture.f.data[0]) ++ s->mv_dir &= ~MV_DIR_FORWARD; ++ if (!s->next_picture.f.data[0]) ++ s->mv_dir &= ~MV_DIR_BACKWARD; ++ s->mb_intra = 0; ++ s->mv_type = MV_TYPE_16X16; ++ s->mb_skipped = 0; ++ ++ if (s->pp_time) { ++ int time_pp = s->pp_time; ++ int time_pb = s->pb_time; ++ ++ if (s->avctx->codec_id == CODEC_ID_H264) { ++ // FIXME ++ } else { ++ ff_thread_await_progress((AVFrame *) s->next_picture_ptr, mb_y, 0); ++ } ++ s->mv[0][0][0] = s->next_picture.f.motion_val[0][xy][0] * time_pb / time_pp; ++ s->mv[0][0][1] = s->next_picture.f.motion_val[0][xy][1] * time_pb / time_pp; ++ s->mv[1][0][0] = s->next_picture.f.motion_val[0][xy][0] * (time_pb - time_pp) / time_pp; ++ s->mv[1][0][1] = s->next_picture.f.motion_val[0][xy][1] * (time_pb - time_pp) / time_pp; ++ } else { ++ s->mv[0][0][0] = 0; ++ s->mv[0][0][1] = 0; ++ s->mv[1][0][0] = 0; ++ s->mv[1][0][1] = 0; + } + + s->dsp.clear_blocks(s->block[0]); +- s->mb_x= mb_x; +- s->mb_y= mb_y; ++ s->mb_x = mb_x; ++ s->mb_y = mb_y; + decode_mb(s, 0); + } + } +- }else ++ } else + guess_mv(s); + + /* the filters below are not XvMC compatible, skip them */ +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) + goto ec_clean; + /* fill DC for inter blocks */ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { + int dc, dcu, dcv, y, n; + int16_t *dc_ptr; + uint8_t *dest_y, *dest_cb, *dest_cr; +- const int mb_xy= mb_x + mb_y * s->mb_stride; +- const int mb_type= s->current_picture.mb_type[mb_xy]; ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + +- error= s->error_status_table[mb_xy]; ++ error = s->error_status_table[mb_xy]; + +- if(IS_INTRA(mb_type) && s->partitioned_frame) continue; +-// if(error&MV_ERROR) continue; //inter data damaged FIXME is this good? +- +- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; +- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize; +- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize; +- +- dc_ptr= &s->dc_val[0][mb_x*2 + mb_y*2*s->b8_stride]; +- for(n=0; n<4; n++){ +- dc=0; +- for(y=0; y<8; y++){ ++ if (IS_INTRA(mb_type) && s->partitioned_frame) ++ continue; ++ // if (error & ER_MV_ERROR) ++ // continue; // inter data damaged FIXME is this good? ++ ++ dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; ++ dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; ++ dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize; ++ ++ dc_ptr = &s->dc_val[0][mb_x * 2 + mb_y * 2 * s->b8_stride]; ++ for (n = 0; n < 4; n++) { ++ dc = 0; ++ for (y = 0; y < 8; y++) { + int x; +- for(x=0; x<8; x++){ +- dc+= dest_y[x + (n&1)*8 + (y + (n>>1)*8)*s->linesize]; +- } ++ for (x = 0; x < 8; x++) ++ dc += dest_y[x + (n & 1) * 8 + ++ (y + (n >> 1) * 8) * s->linesize]; + } +- dc_ptr[(n&1) + (n>>1)*s->b8_stride]= (dc+4)>>3; ++ dc_ptr[(n & 1) + (n >> 1) * s->b8_stride] = (dc + 4) >> 3; + } + +- dcu=dcv=0; +- for(y=0; y<8; y++){ ++ dcu = dcv = 0; ++ for (y = 0; y < 8; y++) { + int x; +- for(x=0; x<8; x++){ +- dcu+=dest_cb[x + y*(s->uvlinesize)]; +- dcv+=dest_cr[x + y*(s->uvlinesize)]; ++ for (x = 0; x < 8; x++) { ++ dcu += dest_cb[x + y * s->uvlinesize]; ++ dcv += dest_cr[x + y * s->uvlinesize]; + } + } +- s->dc_val[1][mb_x + mb_y*s->mb_stride]= (dcu+4)>>3; +- s->dc_val[2][mb_x + mb_y*s->mb_stride]= (dcv+4)>>3; ++ s->dc_val[1][mb_x + mb_y * s->mb_stride] = (dcu + 4) >> 3; ++ s->dc_val[2][mb_x + mb_y * s->mb_stride] = (dcv + 4) >> 3; + } + } + #if 1 +@@ -1071,52 +1265,62 @@ + guess_dc(s, s->dc_val[1], s->mb_width , s->mb_height , s->mb_stride, 0); + guess_dc(s, s->dc_val[2], s->mb_width , s->mb_height , s->mb_stride, 0); + #endif ++ + /* filter luma DC */ +- filter181(s->dc_val[0], s->mb_width*2, s->mb_height*2, s->b8_stride); ++ filter181(s->dc_val[0], s->mb_width * 2, s->mb_height * 2, s->b8_stride); + + #if 1 + /* render DC only intra */ +- for(mb_y=0; mb_ymb_height; mb_y++){ +- for(mb_x=0; mb_xmb_width; mb_x++){ ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { + uint8_t *dest_y, *dest_cb, *dest_cr; +- const int mb_xy= mb_x + mb_y * s->mb_stride; +- const int mb_type= s->current_picture.mb_type[mb_xy]; +- +- error= s->error_status_table[mb_xy]; ++ const int mb_xy = mb_x + mb_y * s->mb_stride; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + +- if(IS_INTER(mb_type)) continue; +- if(!(error&AC_ERROR)) continue; //undamaged ++ error = s->error_status_table[mb_xy]; + +- dest_y = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize; +- dest_cb= s->current_picture.data[1] + mb_x*8 + mb_y*8 *s->uvlinesize; +- dest_cr= s->current_picture.data[2] + mb_x*8 + mb_y*8 *s->uvlinesize; ++ if (IS_INTER(mb_type)) ++ continue; ++ if (!(error & ER_AC_ERROR)) ++ continue; // undamaged ++ ++ dest_y = s->current_picture.f.data[0] + mb_x * 16 + mb_y * 16 * s->linesize; ++ dest_cb = s->current_picture.f.data[1] + mb_x * 8 + mb_y * 8 * s->uvlinesize; ++ dest_cr = s->current_picture.f.data[2] + mb_x * 8 + mb_y * 8 * s->uvlinesize; + + put_dc(s, dest_y, dest_cb, dest_cr, mb_x, mb_y); + } + } + #endif + +- if(s->avctx->error_concealment&FF_EC_DEBLOCK){ ++ if (s->avctx->error_concealment & FF_EC_DEBLOCK) { + /* filter horizontal block boundaries */ +- h_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1); +- h_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0); +- h_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0); ++ h_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2, ++ s->mb_height * 2, s->linesize, 1); ++ h_block_filter(s, s->current_picture.f.data[1], s->mb_width, ++ s->mb_height , s->uvlinesize, 0); ++ h_block_filter(s, s->current_picture.f.data[2], s->mb_width, ++ s->mb_height , s->uvlinesize, 0); + + /* filter vertical block boundaries */ +- v_block_filter(s, s->current_picture.data[0], s->mb_width*2, s->mb_height*2, s->linesize , 1); +- v_block_filter(s, s->current_picture.data[1], s->mb_width , s->mb_height , s->uvlinesize, 0); +- v_block_filter(s, s->current_picture.data[2], s->mb_width , s->mb_height , s->uvlinesize, 0); ++ v_block_filter(s, s->current_picture.f.data[0], s->mb_width * 2, ++ s->mb_height * 2, s->linesize, 1); ++ v_block_filter(s, s->current_picture.f.data[1], s->mb_width, ++ s->mb_height , s->uvlinesize, 0); ++ v_block_filter(s, s->current_picture.f.data[2], s->mb_width, ++ s->mb_height , s->uvlinesize, 0); + } + + ec_clean: + /* clean a few tables */ +- for(i=0; imb_num; i++){ +- const int mb_xy= s->mb_index2xy[i]; +- int error= s->error_status_table[mb_xy]; +- +- if(s->pict_type!=FF_B_TYPE && (error&(DC_ERROR|MV_ERROR|AC_ERROR))){ +- s->mbskip_table[mb_xy]=0; ++ for (i = 0; i < s->mb_num; i++) { ++ const int mb_xy = s->mb_index2xy[i]; ++ int error = s->error_status_table[mb_xy]; ++ ++ if (s->pict_type != AV_PICTURE_TYPE_B && ++ (error & (ER_DC_ERROR | ER_MV_ERROR | ER_AC_ERROR))) { ++ s->mbskip_table[mb_xy] = 0; + } +- s->mbintra_table[mb_xy]=1; ++ s->mbintra_table[mb_xy] = 1; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/escape124.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/escape124.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/escape124.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/escape124.c 2012-05-14 14:08:53.701327242 +0200 +@@ -21,7 +21,7 @@ + + #include "avcodec.h" + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + typedef union MacroBlock { +@@ -49,7 +49,7 @@ + } Escape124Context; + + static int can_safely_read(GetBitContext* gb, int bits) { +- return get_bits_count(gb) + bits <= gb->size_in_bits; ++ return get_bits_left(gb) >= bits; + } + + /** +@@ -61,6 +61,7 @@ + { + Escape124Context *s = avctx->priv_data; + ++ avcodec_get_frame_defaults(&s->frame); + avctx->pix_fmt = PIX_FMT_RGB555; + + s->num_superblocks = ((unsigned)avctx->width / 8) * +@@ -214,7 +215,8 @@ + uint16_t* old_frame_data, *new_frame_data; + unsigned old_stride, new_stride; + +- AVFrame new_frame = { { 0 } }; ++ AVFrame new_frame; ++ avcodec_get_frame_defaults(&new_frame); + + init_get_bits(&gb, buf, buf_size * 8); + +@@ -364,15 +366,14 @@ + + + AVCodec ff_escape124_decoder = { +- "escape124", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ESCAPE124, +- sizeof(Escape124Context), +- escape124_decode_init, +- NULL, +- escape124_decode_close, +- escape124_decode_frame, +- CODEC_CAP_DR1, ++ .name = "escape124", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ESCAPE124, ++ .priv_data_size = sizeof(Escape124Context), ++ .init = escape124_decode_init, ++ .close = escape124_decode_close, ++ .decode = escape124_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Escape 124"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/escape130.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/escape130.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/escape130.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/escape130.c 2012-05-14 14:08:53.702327262 +0200 +@@ -0,0 +1,319 @@ ++/* ++ * Escape 130 Video Decoder ++ * Copyright (C) 2008 Eli Friedman (eli.friedman gmail.com) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++#define BITSTREAM_READER_LE ++#include "get_bits.h" ++ ++typedef struct Escape130Context { ++ AVFrame frame; ++ uint8_t *bases; ++} Escape130Context; ++ ++/** ++ * Initialize the decoder ++ * @param avctx decoder context ++ * @return 0 success, negative on error ++ */ ++static av_cold int escape130_decode_init(AVCodecContext *avctx) ++{ ++ Escape130Context *s = avctx->priv_data; ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ ++ if((avctx->width&1) || (avctx->height&1)){ ++ av_log(avctx, AV_LOG_ERROR, "Dimensions are not a multiple of the block size\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ s->bases= av_malloc(avctx->width * avctx->height /4); ++ ++ return 0; ++} ++ ++static av_cold int escape130_decode_close(AVCodecContext *avctx) ++{ ++ Escape130Context *s = avctx->priv_data; ++ ++ if (s->frame.data[0]) ++ avctx->release_buffer(avctx, &s->frame); ++ ++ av_freep(&s->bases); ++ ++ return 0; ++} ++ ++static unsigned decode_skip_count(GetBitContext* gb) { ++ unsigned value; ++ // This function reads a maximum of 27 bits, ++ // which is within the padding space ++ if (get_bits_left(gb) < 1+3) ++ return -1; ++ ++ value = get_bits1(gb); ++ if (value) ++ return 0; ++ ++ value = get_bits(gb, 3); ++ if (value) ++ return value; ++ ++ value = get_bits(gb, 8); ++ if (value) ++ return value + 7; ++ ++ value = get_bits(gb, 15); ++ if (value) ++ return value + 262; ++ ++ return -1; ++} ++ ++/** ++ * Decode a single frame ++ * @param avctx decoder context ++ * @param data decoded frame ++ * @param data_size size of the decoded frame ++ * @param buf input buffer ++ * @param buf_size input buffer size ++ * @return 0 success, -1 on error ++ */ ++static int escape130_decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ Escape130Context *s = avctx->priv_data; ++ ++ GetBitContext gb; ++ unsigned i; ++ ++ uint8_t *old_y, *old_cb, *old_cr, ++ *new_y, *new_cb, *new_cr; ++ unsigned old_y_stride, old_cb_stride, old_cr_stride, ++ new_y_stride, new_cb_stride, new_cr_stride; ++ unsigned total_blocks = avctx->width * avctx->height / 4, ++ block_index, row_index = 0; ++ unsigned y[4] = {0}, cb = 16, cr = 16; ++ unsigned skip = -1; ++ unsigned y_base = 0; ++ uint8_t *yb= s->bases; ++ ++ AVFrame new_frame = { { 0 } }; ++ ++ init_get_bits(&gb, buf, buf_size * 8); ++ ++ if (get_bits_left(&gb) < 128) ++ return -1; ++ ++ // Header; no useful information in here ++ skip_bits_long(&gb, 128); ++ ++ new_frame.reference = 3; ++ if (avctx->get_buffer(avctx, &new_frame)) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ ++ new_y = new_frame.data[0]; ++ new_cb = new_frame.data[1]; ++ new_cr = new_frame.data[2]; ++ new_y_stride = new_frame.linesize[0]; ++ new_cb_stride = new_frame.linesize[1]; ++ new_cr_stride = new_frame.linesize[2]; ++ old_y = s->frame.data[0]; ++ old_cb = s->frame.data[1]; ++ old_cr = s->frame.data[2]; ++ old_y_stride = s->frame.linesize[0]; ++ old_cb_stride = s->frame.linesize[1]; ++ old_cr_stride = s->frame.linesize[2]; ++ ++ av_log(avctx, AV_LOG_DEBUG, ++ "Strides: %i, %i\n", ++ new_y_stride, new_cb_stride); ++ ++ for (block_index = 0; block_index < total_blocks; block_index++) { ++ // Note that this call will make us skip the rest of the blocks ++ // if the frame prematurely ends ++ if (skip == -1) ++ skip = decode_skip_count(&gb); ++ ++ if (skip) { ++ if (old_y) { ++ y[0] = old_y[0] / 4; ++ y[1] = old_y[1] / 4; ++ y[2] = old_y[old_y_stride] / 4; ++ y[3] = old_y[old_y_stride+1] / 4; ++ y_base= yb[0]; ++ cb = old_cb[0] / 8; ++ cr = old_cr[0] / 8; ++ } else { ++ y_base=y[0] = y[1] = y[2] = y[3] = 0; ++ cb = cr = 16; ++ } ++ } else { ++ if (get_bits1(&gb)) { ++ static const uint8_t offset_table[] = {2, 4, 10, 20}; ++ static const int8_t sign_table[64][4] = ++ { {0, 0, 0, 0}, ++ {-1, 1, 0, 0}, ++ {1, -1, 0, 0}, ++ {-1, 0, 1, 0}, ++ {-1, 1, 1, 0}, ++ {0, -1, 1, 0}, ++ {1, -1, 1, 0}, ++ {-1, -1, 1, 0}, ++ {1, 0, -1, 0}, ++ {0, 1, -1, 0}, ++ {1, 1, -1, 0}, ++ {-1, 1, -1, 0}, ++ {1, -1, -1, 0}, ++ {-1, 0, 0, 1}, ++ {-1, 1, 0, 1}, ++ {0, -1, 0, 1}, ++ ++ {0, 0, 0, 0}, ++ {1, -1, 0, 1}, ++ {-1, -1, 0, 1}, ++ {-1, 0, 1, 1}, ++ {-1, 1, 1, 1}, ++ {0, -1, 1, 1}, ++ {1, -1, 1, 1}, ++ {-1, -1, 1, 1}, ++ {0, 0, -1, 1}, ++ {1, 0, -1, 1}, ++ {-1, 0, -1, 1}, ++ {0, 1, -1, 1}, ++ {1, 1, -1, 1}, ++ {-1, 1, -1, 1}, ++ {0, -1, -1, 1}, ++ {1, -1, -1, 1}, ++ ++ {0, 0, 0, 0}, ++ {-1, -1, -1, 1}, ++ {1, 0, 0, -1}, ++ {0, 1, 0, -1}, ++ {1, 1, 0, -1}, ++ {-1, 1, 0, -1}, ++ {1, -1, 0, -1}, ++ {0, 0, 1, -1}, ++ {1, 0, 1, -1}, ++ {-1, 0, 1, -1}, ++ {0, 1, 1, -1}, ++ {1, 1, 1, -1}, ++ {-1, 1, 1, -1}, ++ {0, -1, 1, -1}, ++ {1, -1, 1, -1}, ++ {-1, -1, 1, -1}, ++ ++ {0, 0, 0, 0}, ++ {1, 0, -1, -1}, ++ {0, 1, -1, -1}, ++ {1, 1, -1, -1}, ++ {-1, 1, -1, -1}, ++ {1, -1, -1, -1} }; ++ unsigned sign_selector = get_bits(&gb, 6); ++ unsigned difference_selector = get_bits(&gb, 2); ++ y_base = 2 * get_bits(&gb, 5); ++ for (i = 0; i < 4; i++) { ++ y[i] = av_clip((int)y_base + offset_table[difference_selector] * ++ sign_table[sign_selector][i], 0, 63); ++ } ++ } else if (get_bits1(&gb)) { ++ if (get_bits1(&gb)) { ++ y_base = get_bits(&gb, 6); ++ } else { ++ unsigned adjust_index = get_bits(&gb, 3); ++ static const int8_t adjust[] = {-4, -3, -2, -1, 1, 2, 3, 4}; ++ y_base = (y_base + adjust[adjust_index]) & 63; ++ } ++ for (i = 0; i < 4; i++) ++ y[i] = y_base; ++ } ++ ++ if (get_bits1(&gb)) { ++ if (get_bits1(&gb)) { ++ cb = get_bits(&gb, 5); ++ cr = get_bits(&gb, 5); ++ } else { ++ unsigned adjust_index = get_bits(&gb, 3); ++ static const int8_t adjust[2][8] = ++ { { 1, 1, 0, -1, -1, -1, 0, 1 }, ++ { 0, 1, 1, 1, 0, -1, -1, -1 } }; ++ cb = (cb + adjust[0][adjust_index]) & 31; ++ cr = (cr + adjust[1][adjust_index]) & 31; ++ } ++ } ++ } ++ *yb++= y_base; ++ ++ new_y[0] = y[0] * 4; ++ new_y[1] = y[1] * 4; ++ new_y[new_y_stride] = y[2] * 4; ++ new_y[new_y_stride + 1] = y[3] * 4; ++ *new_cb = cb * 8; ++ *new_cr = cr * 8; ++ ++ if (old_y) ++ old_y += 2, old_cb++, old_cr++; ++ new_y += 2, new_cb++, new_cr++; ++ row_index++; ++ if (avctx->width / 2 == row_index) { ++ row_index = 0; ++ if (old_y) { ++ old_y += old_y_stride * 2 - avctx->width; ++ old_cb += old_cb_stride - avctx->width / 2; ++ old_cr += old_cr_stride - avctx->width / 2; ++ } ++ new_y += new_y_stride * 2 - avctx->width; ++ new_cb += new_cb_stride - avctx->width / 2; ++ new_cr += new_cr_stride - avctx->width / 2; ++ } ++ ++ skip--; ++ } ++ ++ av_log(avctx, AV_LOG_DEBUG, ++ "Escape sizes: %i, %i\n", ++ buf_size, get_bits_count(&gb) / 8); ++ ++ if (s->frame.data[0]) ++ avctx->release_buffer(avctx, &s->frame); ++ ++ *(AVFrame*)data = s->frame = new_frame; ++ *data_size = sizeof(AVFrame); ++ ++ return buf_size; ++} ++ ++ ++AVCodec ff_escape130_decoder = { ++ .name = "escape130", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ESCAPE130, ++ .priv_data_size = sizeof(Escape130Context), ++ .init = escape130_decode_init, ++ .close = escape130_decode_close, ++ .decode = escape130_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Escape 130"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/faxcompr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/faxcompr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/faxcompr.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/faxcompr.c 2012-05-14 14:08:53.703327282 +0200 +@@ -20,8 +20,8 @@ + */ + + /** +- * CCITT Fax Group 3 and 4 decompression + * @file ++ * CCITT Fax Group 3 and 4 decompression + * @author Konstantin Shishkov + */ + #include "avcodec.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/faxcompr.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/faxcompr.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/faxcompr.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/faxcompr.h 2012-05-14 14:08:53.704327302 +0200 +@@ -20,8 +20,8 @@ + */ + + /** +- * CCITT Fax Group 3 and 4 decompression + * @file ++ * CCITT Fax Group 3 and 4 decompression + * @author Konstantin Shishkov + */ + #ifndef AVCODEC_FAXCOMPR_H +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft.c 2012-05-14 14:08:53.708327382 +0200 +@@ -30,6 +30,7 @@ + #include + #include "libavutil/mathematics.h" + #include "fft.h" ++#include "fft-internal.h" + + /* cos(2*pi*x/n) for 0<=x<=n/4, followed by its reverse */ + #if !CONFIG_HARDCODED_TABLES +@@ -47,10 +48,21 @@ + COSTABLE(32768); + COSTABLE(65536); + #endif +-COSTABLE_CONST FFTSample * const ff_cos_tabs[] = { ++COSTABLE_CONST FFTSample * const FFT_NAME(ff_cos_tabs)[] = { + NULL, NULL, NULL, NULL, +- ff_cos_16, ff_cos_32, ff_cos_64, ff_cos_128, ff_cos_256, ff_cos_512, ff_cos_1024, +- ff_cos_2048, ff_cos_4096, ff_cos_8192, ff_cos_16384, ff_cos_32768, ff_cos_65536, ++ FFT_NAME(ff_cos_16), ++ FFT_NAME(ff_cos_32), ++ FFT_NAME(ff_cos_64), ++ FFT_NAME(ff_cos_128), ++ FFT_NAME(ff_cos_256), ++ FFT_NAME(ff_cos_512), ++ FFT_NAME(ff_cos_1024), ++ FFT_NAME(ff_cos_2048), ++ FFT_NAME(ff_cos_4096), ++ FFT_NAME(ff_cos_8192), ++ FFT_NAME(ff_cos_16384), ++ FFT_NAME(ff_cos_32768), ++ FFT_NAME(ff_cos_65536), + }; + + static void ff_fft_permute_c(FFTContext *s, FFTComplex *z); +@@ -73,14 +85,52 @@ + int i; + int m = 1<= 16; ++ else if (i < n/2) ++ return is_second_half_of_fft32(i, n/2); ++ else if (i < 3*n/4) ++ return is_second_half_of_fft32(i - n/2, n/4); ++ else ++ return is_second_half_of_fft32(i - 3*n/4, n/4); ++} ++ ++static av_cold void fft_perm_avx(FFTContext *s) ++{ ++ int i; ++ int n = 1 << s->nbits; ++ ++ for (i = 0; i < n; i += 16) { ++ int k; ++ if (is_second_half_of_fft32(i, n)) { ++ for (k = 0; k < 16; k++) ++ s->revtab[-split_radix_permutation(i + k, n, s->inverse) & (n - 1)] = ++ i + avx_tab[k]; ++ ++ } else { ++ for (k = 0; k < 16; k++) { ++ int j = i + k; ++ j = (j & ~7) | ((j >> 1) & 3) | ((j << 2) & 4); ++ s->revtab[-split_radix_permutation(i + k, n, s->inverse) & (n - 1)] = j; ++ } ++ } ++ } ++} ++ + av_cold int ff_fft_init(FFTContext *s, int nbits, int inverse) + { + int i, j, n; +@@ -97,6 +147,7 @@ + if (!s->tmp_buf) + goto fail; + s->inverse = inverse; ++ s->fft_permutation = FF_FFT_PERM_DEFAULT; + + s->fft_permute = ff_fft_permute_c; + s->fft_calc = ff_fft_calc_c; +@@ -106,15 +157,30 @@ + s->mdct_calc = ff_mdct_calc_c; + #endif + ++#if CONFIG_FFT_FLOAT + if (ARCH_ARM) ff_fft_init_arm(s); + if (HAVE_ALTIVEC) ff_fft_init_altivec(s); + if (HAVE_MMX) ff_fft_init_mmx(s); ++ if (CONFIG_MDCT) s->mdct_calcw = s->mdct_calc; ++#else ++ if (CONFIG_MDCT) s->mdct_calcw = ff_mdct_calcw_c; ++ if (ARCH_ARM) ff_fft_fixed_init_arm(s); ++#endif + + for(j=4; j<=nbits; j++) { + ff_init_ff_cos_tabs(j); + } +- for(i=0; irevtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = i; ++ ++ if (s->fft_permutation == FF_FFT_PERM_AVX) { ++ fft_perm_avx(s); ++ } else { ++ for(i=0; ifft_permutation == FF_FFT_PERM_SWAP_LSBS) ++ j = (j&~3) | ((j>>1)&1) | ((j<<1)&2); ++ s->revtab[-split_radix_permutation(i, n, s->inverse) & (n-1)] = j; ++ } ++ } + + return 0; + fail: +@@ -139,13 +205,6 @@ + av_freep(&s->tmp_buf); + } + +-#define sqrthalf (float)M_SQRT1_2 +- +-#define BF(x,y,a,b) {\ +- x = a - b;\ +- y = a + b;\ +-} +- + #define BUTTERFLIES(a0,a1,a2,a3) {\ + BF(t3, t5, t5, t1);\ + BF(a2.re, a0.re, a0.re, t5);\ +@@ -169,10 +228,8 @@ + } + + #define TRANSFORM(a0,a1,a2,a3,wre,wim) {\ +- t1 = a2.re * wre + a2.im * wim;\ +- t2 = a2.im * wre - a2.re * wim;\ +- t5 = a3.re * wre - a3.im * wim;\ +- t6 = a3.im * wre + a3.re * wim;\ ++ CMUL(t1, t2, a2.re, a2.im, wre, -wim);\ ++ CMUL(t5, t6, a3.re, a3.im, wre, wim);\ + BUTTERFLIES(a0,a1,a2,a3)\ + } + +@@ -188,7 +245,7 @@ + #define PASS(name)\ + static void name(FFTComplex *z, const FFTSample *wre, unsigned int n)\ + {\ +- FFTSample t1, t2, t3, t4, t5, t6;\ ++ FFTDouble t1, t2, t3, t4, t5, t6;\ + int o1 = 2*n;\ + int o2 = 4*n;\ + int o3 = 6*n;\ +@@ -217,12 +274,12 @@ + fft##n2(z);\ + fft##n4(z+n4*2);\ + fft##n4(z+n4*3);\ +- pass(z,ff_cos_##n,n4/2);\ ++ pass(z,FFT_NAME(ff_cos_##n),n4/2);\ + } + + static void fft4(FFTComplex *z) + { +- FFTSample t1, t2, t3, t4, t5, t6, t7, t8; ++ FFTDouble t1, t2, t3, t4, t5, t6, t7, t8; + + BF(t3, t1, z[0].re, z[1].re); + BF(t8, t6, z[3].re, z[2].re); +@@ -236,28 +293,25 @@ + + static void fft8(FFTComplex *z) + { +- FFTSample t1, t2, t3, t4, t5, t6, t7, t8; ++ FFTDouble t1, t2, t3, t4, t5, t6; + + fft4(z); + + BF(t1, z[5].re, z[4].re, -z[5].re); + BF(t2, z[5].im, z[4].im, -z[5].im); +- BF(t3, z[7].re, z[6].re, -z[7].re); +- BF(t4, z[7].im, z[6].im, -z[7].im); +- BF(t8, t1, t3, t1); +- BF(t7, t2, t2, t4); +- BF(z[4].re, z[0].re, z[0].re, t1); +- BF(z[4].im, z[0].im, z[0].im, t2); +- BF(z[6].re, z[2].re, z[2].re, t7); +- BF(z[6].im, z[2].im, z[2].im, t8); ++ BF(t5, z[7].re, z[6].re, -z[7].re); ++ BF(t6, z[7].im, z[6].im, -z[7].im); + ++ BUTTERFLIES(z[0],z[2],z[4],z[6]); + TRANSFORM(z[1],z[3],z[5],z[7],sqrthalf,sqrthalf); + } + + #if !CONFIG_SMALL + static void fft16(FFTComplex *z) + { +- FFTSample t1, t2, t3, t4, t5, t6; ++ FFTDouble t1, t2, t3, t4, t5, t6; ++ FFTSample cos_16_1 = FFT_NAME(ff_cos_16)[1]; ++ FFTSample cos_16_3 = FFT_NAME(ff_cos_16)[3]; + + fft8(z); + fft4(z+8); +@@ -265,8 +319,8 @@ + + TRANSFORM_ZERO(z[0],z[4],z[8],z[12]); + TRANSFORM(z[2],z[6],z[10],z[14],sqrthalf,sqrthalf); +- TRANSFORM(z[1],z[5],z[9],z[13],ff_cos_16[1],ff_cos_16[3]); +- TRANSFORM(z[3],z[7],z[11],z[15],ff_cos_16[3],ff_cos_16[1]); ++ TRANSFORM(z[1],z[5],z[9],z[13],cos_16_1,cos_16_3); ++ TRANSFORM(z[3],z[7],z[11],z[15],cos_16_3,cos_16_1); + } + #else + DECL_FFT(16,8,4) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft_fixed.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft_fixed.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft_fixed.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft_fixed.c 2012-05-14 14:08:53.709327403 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FFT_FLOAT 0 ++#include "fft.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-fixed-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-fixed-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-fixed-test.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-fixed-test.c 2012-05-14 14:08:53.704327302 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFMpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFMpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FFT_FLOAT 0 ++#include "fft-test.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft_float.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft_float.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft_float.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft_float.c 2012-05-14 14:08:53.710327423 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FFT_FLOAT 1 ++#include "fft.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft.h 2012-05-14 14:08:53.709327403 +0200 +@@ -22,11 +22,41 @@ + #ifndef AVCODEC_FFT_H + #define AVCODEC_FFT_H + ++#ifndef CONFIG_FFT_FLOAT ++#define CONFIG_FFT_FLOAT 1 ++#endif ++ + #include + #include "config.h" + #include "libavutil/mem.h" ++ ++#if CONFIG_FFT_FLOAT ++ + #include "avfft.h" + ++#define FFT_NAME(x) x ++ ++typedef float FFTDouble; ++ ++#else ++ ++#define FFT_NAME(x) x ## _fixed ++ ++typedef int16_t FFTSample; ++typedef int FFTDouble; ++ ++typedef struct FFTComplex { ++ int16_t re, im; ++} FFTComplex; ++ ++typedef struct FFTContext FFTContext; ++ ++#endif /* CONFIG_FFT_FLOAT */ ++ ++typedef struct FFTDComplex { ++ FFTDouble re, im; ++} FFTDComplex; ++ + /* FFT computation */ + + struct FFTContext { +@@ -39,32 +69,37 @@ + /* pre/post rotation tables */ + FFTSample *tcos; + FFTSample *tsin; ++ /** ++ * Do the permutation needed BEFORE calling fft_calc(). ++ */ + void (*fft_permute)(struct FFTContext *s, FFTComplex *z); ++ /** ++ * Do a complex FFT with the parameters defined in ff_fft_init(). The ++ * input data must be permuted before. No 1.0/sqrt(n) normalization is done. ++ */ + void (*fft_calc)(struct FFTContext *s, FFTComplex *z); + void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); + void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input); + void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input); +- int permutation; ++ void (*mdct_calcw)(struct FFTContext *s, FFTDouble *output, const FFTSample *input); ++ int fft_permutation; ++#define FF_FFT_PERM_DEFAULT 0 ++#define FF_FFT_PERM_SWAP_LSBS 1 ++#define FF_FFT_PERM_AVX 2 ++ int mdct_permutation; + #define FF_MDCT_PERM_NONE 0 + #define FF_MDCT_PERM_INTERLEAVE 1 + }; + + #if CONFIG_HARDCODED_TABLES + #define COSTABLE_CONST const +-#define SINTABLE_CONST const +-#define SINETABLE_CONST const + #else + #define COSTABLE_CONST +-#define SINTABLE_CONST +-#define SINETABLE_CONST + #endif + + #define COSTABLE(size) \ +- COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2] +-#define SINTABLE(size) \ +- SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2] +-#define SINETABLE(size) \ +- SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size] ++ COSTABLE_CONST DECLARE_ALIGNED(32, FFTSample, FFT_NAME(ff_cos_##size))[size/2] ++ + extern COSTABLE(16); + extern COSTABLE(32); + extern COSTABLE(64); +@@ -78,27 +113,18 @@ + extern COSTABLE(16384); + extern COSTABLE(32768); + extern COSTABLE(65536); +-extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17]; ++extern COSTABLE_CONST FFTSample* const FFT_NAME(ff_cos_tabs)[17]; ++ ++#define ff_init_ff_cos_tabs FFT_NAME(ff_init_ff_cos_tabs) + + /** + * Initialize the cosine table in ff_cos_tabs[index] +- * \param index index in ff_cos_tabs array of the table to initialize ++ * @param index index in ff_cos_tabs array of the table to initialize + */ + void ff_init_ff_cos_tabs(int index); + +-extern SINTABLE(16); +-extern SINTABLE(32); +-extern SINTABLE(64); +-extern SINTABLE(128); +-extern SINTABLE(256); +-extern SINTABLE(512); +-extern SINTABLE(1024); +-extern SINTABLE(2048); +-extern SINTABLE(4096); +-extern SINTABLE(8192); +-extern SINTABLE(16384); +-extern SINTABLE(32768); +-extern SINTABLE(65536); ++#define ff_fft_init FFT_NAME(ff_fft_init) ++#define ff_fft_end FFT_NAME(ff_fft_end) + + /** + * Set up a complex FFT. +@@ -107,136 +133,20 @@ + */ + int ff_fft_init(FFTContext *s, int nbits, int inverse); + ++#if CONFIG_FFT_FLOAT + void ff_fft_init_altivec(FFTContext *s); + void ff_fft_init_mmx(FFTContext *s); + void ff_fft_init_arm(FFTContext *s); +-void ff_dct_init_mmx(DCTContext *s); ++#else ++void ff_fft_fixed_init_arm(FFTContext *s); ++#endif + +-/** +- * Do the permutation needed BEFORE calling ff_fft_calc(). +- */ +-static inline void ff_fft_permute(FFTContext *s, FFTComplex *z) +-{ +- s->fft_permute(s, z); +-} +-/** +- * Do a complex FFT with the parameters defined in ff_fft_init(). The +- * input data must be permuted before. No 1.0/sqrt(n) normalization is done. +- */ +-static inline void ff_fft_calc(FFTContext *s, FFTComplex *z) +-{ +- s->fft_calc(s, z); +-} + void ff_fft_end(FFTContext *s); + +-/* MDCT computation */ +- +-static inline void ff_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input) +-{ +- s->imdct_calc(s, output, input); +-} +-static inline void ff_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input) +-{ +- s->imdct_half(s, output, input); +-} +- +-static inline void ff_mdct_calc(FFTContext *s, FFTSample *output, +- const FFTSample *input) +-{ +- s->mdct_calc(s, output, input); +-} +- +-/** +- * Maximum window size for ff_kbd_window_init. +- */ +-#define FF_KBD_WINDOW_MAX 1024 +- +-/** +- * Generate a Kaiser-Bessel Derived Window. +- * @param window pointer to half window +- * @param alpha determines window shape +- * @param n size of half window, max FF_KBD_WINDOW_MAX +- */ +-void ff_kbd_window_init(float *window, float alpha, int n); +- +-/** +- * Generate a sine window. +- * @param window pointer to half window +- * @param n size of half window +- */ +-void ff_sine_window_init(float *window, int n); +- +-/** +- * initialize the specified entry of ff_sine_windows +- */ +-void ff_init_ff_sine_windows(int index); +-extern SINETABLE( 32); +-extern SINETABLE( 64); +-extern SINETABLE( 128); +-extern SINETABLE( 256); +-extern SINETABLE( 512); +-extern SINETABLE(1024); +-extern SINETABLE(2048); +-extern SINETABLE(4096); +-extern SINETABLE_CONST float * const ff_sine_windows[13]; ++#define ff_mdct_init FFT_NAME(ff_mdct_init) ++#define ff_mdct_end FFT_NAME(ff_mdct_end) + + int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale); +-void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); +-void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); +-void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); + void ff_mdct_end(FFTContext *s); + +-/* Real Discrete Fourier Transform */ +- +-struct RDFTContext { +- int nbits; +- int inverse; +- int sign_convention; +- +- /* pre/post rotation tables */ +- const FFTSample *tcos; +- SINTABLE_CONST FFTSample *tsin; +- FFTContext fft; +- void (*rdft_calc)(struct RDFTContext *s, FFTSample *z); +-}; +- +-/** +- * Set up a real FFT. +- * @param nbits log2 of the length of the input array +- * @param trans the type of transform +- */ +-int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans); +-void ff_rdft_end(RDFTContext *s); +- +-void ff_rdft_init_arm(RDFTContext *s); +- +-static av_always_inline void ff_rdft_calc(RDFTContext *s, FFTSample *data) +-{ +- s->rdft_calc(s, data); +-} +- +-/* Discrete Cosine Transform */ +- +-struct DCTContext { +- int nbits; +- int inverse; +- RDFTContext rdft; +- const float *costab; +- FFTSample *csc2; +- void (*dct_calc)(struct DCTContext *s, FFTSample *data); +- void (*dct32)(FFTSample *out, const FFTSample *in); +-}; +- +-/** +- * Set up DCT. +- * @param nbits size of the input array: +- * (1 << nbits) for DCT-II, DCT-III and DST-I +- * (1 << nbits) + 1 for DCT-I +- * +- * @note the first element of the input of DST-I is ignored +- */ +-int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type); +-void ff_dct_calc(DCTContext *s, FFTSample *data); +-void ff_dct_end (DCTContext *s); +- + #endif /* AVCODEC_FFT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-internal.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-internal.h 2012-05-14 14:08:53.705327322 +0200 +@@ -0,0 +1,75 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_FFT_INTERNAL_H ++#define AVCODEC_FFT_INTERNAL_H ++ ++#if CONFIG_FFT_FLOAT ++ ++#define FIX15(v) (v) ++#define sqrthalf (float)M_SQRT1_2 ++ ++#define BF(x, y, a, b) do { \ ++ x = a - b; \ ++ y = a + b; \ ++ } while (0) ++ ++#define CMUL(dre, dim, are, aim, bre, bim) do { \ ++ (dre) = (are) * (bre) - (aim) * (bim); \ ++ (dim) = (are) * (bim) + (aim) * (bre); \ ++ } while (0) ++ ++#else ++ ++#include "libavutil/intmath.h" ++#include "mathops.h" ++ ++void ff_mdct_calcw_c(FFTContext *s, FFTDouble *output, const FFTSample *input); ++ ++#define SCALE_FLOAT(a, bits) lrint((a) * (double)(1 << (bits))) ++#define FIX15(a) av_clip(SCALE_FLOAT(a, 15), -32767, 32767) ++ ++#define sqrthalf ((int16_t)((1<<15)*M_SQRT1_2)) ++ ++#define BF(x, y, a, b) do { \ ++ x = (a - b) >> 1; \ ++ y = (a + b) >> 1; \ ++ } while (0) ++ ++#define CMULS(dre, dim, are, aim, bre, bim, sh) do { \ ++ (dre) = (MUL16(are, bre) - MUL16(aim, bim)) >> sh; \ ++ (dim) = (MUL16(are, bim) + MUL16(aim, bre)) >> sh; \ ++ } while (0) ++ ++#define CMUL(dre, dim, are, aim, bre, bim) \ ++ CMULS(dre, dim, are, aim, bre, bim, 15) ++ ++#define CMULL(dre, dim, are, aim, bre, bim) \ ++ CMULS(dre, dim, are, aim, bre, bim, 0) ++ ++#endif /* CONFIG_FFT_FLOAT */ ++ ++#define ff_imdct_calc_c FFT_NAME(ff_imdct_calc_c) ++#define ff_imdct_half_c FFT_NAME(ff_imdct_half_c) ++#define ff_mdct_calc_c FFT_NAME(ff_mdct_calc_c) ++ ++void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); ++void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input); ++void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input); ++ ++#endif /* AVCODEC_FFT_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fft-test.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fft-test.c 2012-05-14 14:08:53.706327342 +0200 +@@ -27,14 +27,16 @@ + #include "libavutil/lfg.h" + #include "libavutil/log.h" + #include "fft.h" ++#if CONFIG_FFT_FLOAT ++#include "dct.h" ++#include "rdft.h" ++#endif + #include + #include + #include + #include + #include + +-#undef exit +- + /* reference fft */ + + #define MUL16(a,b) ((a) * (b)) +@@ -45,7 +47,19 @@ + pim += (MUL16(are, bim) + MUL16(bre, aim));\ + } + +-FFTComplex *exptab; ++#if CONFIG_FFT_FLOAT ++# define RANGE 1.0 ++# define REF_SCALE(x, bits) (x) ++# define FMT "%10.6f" ++#else ++# define RANGE 16384 ++# define REF_SCALE(x, bits) ((x) / (1<<(bits))) ++# define FMT "%6d" ++#endif ++ ++struct { ++ float re, im; ++} *exptab; + + static void fft_ref_init(int nbits, int inverse) + { +@@ -53,7 +67,7 @@ + double c1, s1, alpha; + + n = 1 << nbits; +- exptab = av_malloc((n / 2) * sizeof(FFTComplex)); ++ exptab = av_malloc((n / 2) * sizeof(*exptab)); + + for (i = 0; i < (n/2); i++) { + alpha = 2 * M_PI * (float)i / (float)n; +@@ -90,12 +104,12 @@ + CMAC(tmp_re, tmp_im, c, s, q->re, q->im); + q++; + } +- tabr[i].re = tmp_re; +- tabr[i].im = tmp_im; ++ tabr[i].re = REF_SCALE(tmp_re, nbits); ++ tabr[i].im = REF_SCALE(tmp_im, nbits); + } + } + +-static void imdct_ref(float *out, float *in, int nbits) ++static void imdct_ref(FFTSample *out, FFTSample *in, int nbits) + { + int n = 1<= 1e-3) { +- av_log(NULL, AV_LOG_ERROR, "ERROR %5d: %10.6f %10.6f\n", ++ av_log(NULL, AV_LOG_ERROR, "ERROR %5d: "FMT" "FMT"\n", + i, tab1[i], tab2[i]); + err = 1; + } +@@ -210,7 +226,6 @@ + "-n b set the transform size to 2^b\n" + "-f x set scale factor for output data of (I)MDCT to x\n" + ); +- exit(1); + } + + enum tf_transform { +@@ -231,9 +246,12 @@ + int do_inverse = 0; + FFTContext s1, *s = &s1; + FFTContext m1, *m = &m1; ++#if CONFIG_FFT_FLOAT + RDFTContext r1, *r = &r1; + DCTContext d1, *d = &d1; +- int fft_nbits, fft_size, fft_size_2; ++ int fft_size_2; ++#endif ++ int fft_nbits, fft_size; + double scale = 1.0; + AVLFG prng; + av_lfg_init(&prng, 1); +@@ -246,7 +264,7 @@ + switch(c) { + case 'h': + help(); +- break; ++ return 1; + case 's': + do_speed = 1; + break; +@@ -272,7 +290,6 @@ + } + + fft_size = 1 << fft_nbits; +- fft_size_2 = fft_size >> 1; + tab = av_malloc(fft_size * sizeof(FFTComplex)); + tab1 = av_malloc(fft_size * sizeof(FFTComplex)); + tab_ref = av_malloc(fft_size * sizeof(FFTComplex)); +@@ -295,6 +312,7 @@ + ff_fft_init(s, fft_nbits, do_inverse); + fft_ref_init(fft_nbits, do_inverse); + break; ++#if CONFIG_FFT_FLOAT + case TRANSFORM_RDFT: + if (do_inverse) + av_log(NULL, AV_LOG_INFO,"IDFT_C2R"); +@@ -310,6 +328,10 @@ + av_log(NULL, AV_LOG_INFO,"DCT_II"); + ff_dct_init(d, fft_nbits, do_inverse ? DCT_III : DCT_II); + break; ++#endif ++ default: ++ av_log(NULL, AV_LOG_ERROR, "Requested transform not supported\n"); ++ return 1; + } + av_log(NULL, AV_LOG_INFO," %d test\n", fft_size); + +@@ -326,26 +348,28 @@ + switch (transform) { + case TRANSFORM_MDCT: + if (do_inverse) { +- imdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); +- ff_imdct_calc(m, tab2, (float *)tab1); +- err = check_diff((float *)tab_ref, tab2, fft_size, scale); ++ imdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits); ++ m->imdct_calc(m, tab2, (FFTSample *)tab1); ++ err = check_diff((FFTSample *)tab_ref, tab2, fft_size, scale); + } else { +- mdct_ref((float *)tab_ref, (float *)tab1, fft_nbits); ++ mdct_ref((FFTSample *)tab_ref, (FFTSample *)tab1, fft_nbits); + +- ff_mdct_calc(m, tab2, (float *)tab1); ++ m->mdct_calc(m, tab2, (FFTSample *)tab1); + +- err = check_diff((float *)tab_ref, tab2, fft_size / 2, scale); ++ err = check_diff((FFTSample *)tab_ref, tab2, fft_size / 2, scale); + } + break; + case TRANSFORM_FFT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); +- ff_fft_permute(s, tab); +- ff_fft_calc(s, tab); ++ s->fft_permute(s, tab); ++ s->fft_calc(s, tab); + + fft_ref(tab_ref, tab1, fft_nbits); +- err = check_diff((float *)tab_ref, (float *)tab, fft_size * 2, 1.0); ++ err = check_diff((FFTSample *)tab_ref, (FFTSample *)tab, fft_size * 2, 1.0); + break; ++#if CONFIG_FFT_FLOAT + case TRANSFORM_RDFT: ++ fft_size_2 = fft_size >> 1; + if (do_inverse) { + tab1[ 0].im = 0; + tab1[fft_size_2].im = 0; +@@ -357,7 +381,7 @@ + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); + tab2[1] = tab1[fft_size_2].re; + +- ff_rdft_calc(r, tab2); ++ r->rdft_calc(r, tab2); + fft_ref(tab_ref, tab1, fft_nbits); + for (i = 0; i < fft_size; i++) { + tab[i].re = tab2[i]; +@@ -369,7 +393,7 @@ + tab2[i] = tab1[i].re; + tab1[i].im = 0; + } +- ff_rdft_calc(r, tab2); ++ r->rdft_calc(r, tab2); + fft_ref(tab_ref, tab1, fft_nbits); + tab_ref[0].im = tab_ref[fft_size_2].re; + err = check_diff((float *)tab_ref, (float *)tab2, fft_size, 1.0); +@@ -377,7 +401,7 @@ + break; + case TRANSFORM_DCT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); +- ff_dct_calc(d, tab); ++ d->dct_calc(d, tab); + if (do_inverse) { + idct_ref(tab_ref, tab1, fft_nbits); + } else { +@@ -385,6 +409,7 @@ + } + err = check_diff((float *)tab_ref, (float *)tab, fft_size, 1.0); + break; ++#endif + } + + /* do a speed test */ +@@ -402,23 +427,25 @@ + switch (transform) { + case TRANSFORM_MDCT: + if (do_inverse) { +- ff_imdct_calc(m, (float *)tab, (float *)tab1); ++ m->imdct_calc(m, (FFTSample *)tab, (FFTSample *)tab1); + } else { +- ff_mdct_calc(m, (float *)tab, (float *)tab1); ++ m->mdct_calc(m, (FFTSample *)tab, (FFTSample *)tab1); + } + break; + case TRANSFORM_FFT: + memcpy(tab, tab1, fft_size * sizeof(FFTComplex)); +- ff_fft_calc(s, tab); ++ s->fft_calc(s, tab); + break; ++#if CONFIG_FFT_FLOAT + case TRANSFORM_RDFT: + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); +- ff_rdft_calc(r, tab2); ++ r->rdft_calc(r, tab2); + break; + case TRANSFORM_DCT: + memcpy(tab2, tab1, fft_size * sizeof(FFTSample)); +- ff_dct_calc(d, tab2); ++ d->dct_calc(d, tab2); + break; ++#endif + } + } + duration = gettime() - time_start; +@@ -439,12 +466,14 @@ + case TRANSFORM_FFT: + ff_fft_end(s); + break; ++#if CONFIG_FFT_FLOAT + case TRANSFORM_RDFT: + ff_rdft_end(r); + break; + case TRANSFORM_DCT: + ff_dct_end(d); + break; ++#endif + } + + av_free(tab); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ffv1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ffv1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ffv1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ffv1.c 2012-05-14 14:08:53.713327483 +0200 +@@ -40,26 +40,7 @@ + #define MAX_QUANT_TABLES 8 + #define MAX_CONTEXT_INPUTS 5 + +-extern const uint8_t ff_log2_run[32]; +- +-static const int8_t quant3[256]={ +- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, +-}; ++extern const uint8_t ff_log2_run[41]; + + static const int8_t quant5_10bit[256]={ + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, +@@ -98,42 +79,7 @@ + -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, + -2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,-1, + }; +-static const int8_t quant7[256]={ +- 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1, +-}; +-static const int8_t quant9[256]={ +- 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1, +-}; ++ + static const int8_t quant9_10bit[256]={ + 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, +@@ -171,24 +117,6 @@ + -4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, + -4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1, + }; +-static const int8_t quant13[256]={ +- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1, +-}; + + static const uint8_t ver2_state[256]= { + 0, 10, 10, 10, 10, 16, 16, 16, 28, 16, 16, 29, 42, 49, 20, 49, +@@ -237,6 +165,7 @@ + int version; + int width, height; + int chroma_h_shift, chroma_v_shift; ++ int transparency; + int flags; + int picture_number; + AVFrame picture; +@@ -250,8 +179,9 @@ + uint8_t (*initial_states[MAX_QUANT_TABLES])[32]; + int run_index; + int colorspace; +- int_fast16_t *sample_buffer; ++ int16_t *sample_buffer; + int gob_count; ++ int packed_at_lsb; + + int quant_table_count; + +@@ -279,7 +209,8 @@ + return diff; + } + +-static inline int predict(int_fast16_t *src, int_fast16_t *last){ ++static inline int predict(int16_t *src, int16_t *last) ++{ + const int LT= last[-1]; + const int T= last[ 0]; + const int L = src[-1]; +@@ -287,7 +218,9 @@ + return mid_pred(L, L + T - LT, T); + } + +-static inline int get_context(PlaneContext *p, int_fast16_t *src, int_fast16_t *last, int_fast16_t *last2){ ++static inline int get_context(PlaneContext *p, int16_t *src, ++ int16_t *last, int16_t *last2) ++{ + const int LT= last[-1]; + const int T= last[ 0]; + const int RT= last[ 1]; +@@ -506,7 +439,10 @@ + } + + #if CONFIG_FFV1_ENCODER +-static av_always_inline int encode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){ ++static av_always_inline int encode_line(FFV1Context *s, int w, ++ int16_t *sample[2], ++ int plane_index, int bits) ++{ + PlaneContext * const p= &s->plane[plane_index]; + RangeCoder * const c= &s->c; + int x; +@@ -591,7 +527,7 @@ + static void encode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){ + int x,y,i; + const int ring_size= s->avctx->context_model ? 3 : 2; +- int_fast16_t *sample[3]; ++ int16_t *sample[3]; + s->run_index=0; + + memset(s->sample_buffer, 0, ring_size*(w+6)*sizeof(*s->sample_buffer)); +@@ -609,8 +545,14 @@ + } + encode_line(s, w, sample, plane_index, 8); + }else{ +- for(x=0; x> (16 - s->avctx->bits_per_raw_sample); ++ if(s->packed_at_lsb){ ++ for(x=0; x> (16 - s->avctx->bits_per_raw_sample); ++ } + } + encode_line(s, w, sample, plane_index, s->avctx->bits_per_raw_sample); + } +@@ -621,21 +563,22 @@ + static void encode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){ + int x, y, p, i; + const int ring_size= s->avctx->context_model ? 3 : 2; +- int_fast16_t *sample[3][3]; ++ int16_t *sample[4][3]; + s->run_index=0; + +- memset(s->sample_buffer, 0, ring_size*3*(w+6)*sizeof(*s->sample_buffer)); ++ memset(s->sample_buffer, 0, ring_size*4*(w+6)*sizeof(*s->sample_buffer)); + + for(y=0; ysample_buffer + p*ring_size*(w+6) + ((h+i-y)%ring_size)*(w+6) + 3; + + for(x=0; x>8)&0xFF; + int r= (v>>16)&0xFF; ++ int a= v>>24; + + b -= g; + r -= g; +@@ -648,11 +591,12 @@ + sample[0][0][x]= g; + sample[1][0][x]= b; + sample[2][0][x]= r; ++ sample[3][0][x]= a; + } +- for(p=0; p<3; p++){ ++ for(p=0; p<3 + s->transparency; p++){ + sample[p][0][-1]= sample[p][1][0 ]; + sample[p][1][ w]= sample[p][1][w-1]; +- encode_line(s, w, sample[p], FFMIN(p, 1), 9); ++ encode_line(s, w, sample[p], (p+1)/2, 9); + } + } + } +@@ -699,7 +643,7 @@ + put_rac(c, state, 1); //chroma planes + put_symbol(c, state, f->chroma_h_shift, 0); + put_symbol(c, state, f->chroma_v_shift, 0); +- put_rac(c, state, 0); //no transparency plane ++ put_rac(c, state, f->transparency); + + write_quant_tables(c, f->quant_table); + }else{ +@@ -725,6 +669,8 @@ + s->avctx= avctx; + s->flags= avctx->flags; + ++ avcodec_get_frame_defaults(&s->picture); ++ + dsputil_init(&s->dsp, avctx); + + s->width = avctx->width; +@@ -744,6 +690,8 @@ + + for(i=0; islice_count; i++){ + FFV1Context *fs= f->slice_context[i]; ++ fs->plane_count= f->plane_count; ++ fs->transparency= f->transparency; + for(j=0; jplane_count; j++){ + PlaneContext * const p= &fs->plane[j]; + +@@ -792,7 +740,7 @@ + fs->slice_x = sxs; + fs->slice_y = sys; + +- fs->sample_buffer = av_malloc(6 * (fs->width+6) * sizeof(*fs->sample_buffer)); ++ fs->sample_buffer = av_malloc(3*4 * (fs->width+6) * sizeof(*fs->sample_buffer)); + if (!fs->sample_buffer) + return AVERROR(ENOMEM); + } +@@ -837,7 +785,7 @@ + put_rac(c, state, 1); //chroma planes + put_symbol(c, state, f->chroma_h_shift, 0); + put_symbol(c, state, f->chroma_v_shift, 0); +- put_rac(c, state, 0); //no transparency plane ++ put_rac(c, state, f->transparency); + put_symbol(c, state, f->num_h_slices-1, 0); + put_symbol(c, state, f->num_v_slices-1, 0); + +@@ -924,7 +872,7 @@ + for(i=1; i<256; i++) + s->state_transition[i]=ver2_state[i]; + +- s->plane_count=2; ++ s->plane_count=3; + for(i=0; i<256; i++){ + s->quant_table_count=2; + if(avctx->bits_per_raw_sample <=8){ +@@ -964,6 +912,10 @@ + + avctx->coded_frame= &s->picture; + switch(avctx->pix_fmt){ ++ case PIX_FMT_YUV420P9: ++ case PIX_FMT_YUV420P10: ++ case PIX_FMT_YUV422P10: ++ s->packed_at_lsb = 1; + case PIX_FMT_YUV444P16: + case PIX_FMT_YUV422P16: + case PIX_FMT_YUV420P16: +@@ -985,11 +937,17 @@ + break; + case PIX_FMT_RGB32: + s->colorspace= 1; ++ s->transparency= 1; ++ break; ++ case PIX_FMT_0RGB32: ++ s->colorspace= 1; + break; + default: + av_log(avctx, AV_LOG_ERROR, "format not supported\n"); + return -1; + } ++ if(!s->transparency) ++ s->plane_count= 2; + avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); + + s->picture_number=0; +@@ -1127,6 +1085,7 @@ + int x= fs->slice_x; + int y= fs->slice_y; + AVFrame * const p= &f->picture; ++ const int ps= (c->bits_per_raw_sample>8)+1; + + if(f->colorspace==0){ + const int chroma_width = -((-width )>>f->chroma_h_shift); +@@ -1134,12 +1093,12 @@ + const int cx= x>>f->chroma_h_shift; + const int cy= y>>f->chroma_v_shift; + +- encode_plane(fs, p->data[0] + x + y*p->linesize[0], width, height, p->linesize[0], 0); ++ encode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0); + +- encode_plane(fs, p->data[1] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1); +- encode_plane(fs, p->data[2] + cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1); ++ encode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1); ++ encode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[2], chroma_width, chroma_height, p->linesize[2], 1); + }else{ +- encode_rgb_frame(fs, (uint32_t*)(p->data[0]) + x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4); ++ encode_rgb_frame(fs, (uint32_t*)(p->data[0]) + ps*x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4); + } + emms_c(); + +@@ -1160,7 +1119,7 @@ + ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + + if(avctx->gop_size==0 || f->picture_number % avctx->gop_size == 0){ + put_rac(c, &keystate, 1); +@@ -1305,7 +1264,10 @@ + return 0; + } + +-static av_always_inline void decode_line(FFV1Context *s, int w, int_fast16_t *sample[2], int plane_index, int bits){ ++static av_always_inline void decode_line(FFV1Context *s, int w, ++ int16_t *sample[2], ++ int plane_index, int bits) ++{ + PlaneContext * const p= &s->plane[plane_index]; + RangeCoder * const c= &s->c; + int x; +@@ -1365,7 +1327,7 @@ + + static void decode_plane(FFV1Context *s, uint8_t *src, int w, int h, int stride, int plane_index){ + int x, y; +- int_fast16_t *sample[2]; ++ int16_t *sample[2]; + sample[0]=s->sample_buffer +3; + sample[1]=s->sample_buffer+w+6+3; + +@@ -1374,7 +1336,7 @@ + memset(s->sample_buffer, 0, 2*(w+6)*sizeof(*s->sample_buffer)); + + for(y=0; yavctx->bits_per_raw_sample); +- for(x=0; xavctx->bits_per_raw_sample); ++ if(s->packed_at_lsb){ ++ for(x=0; xavctx->bits_per_raw_sample); ++ } + } + } + //STOP_TIMER("decode-line")} +@@ -1400,31 +1368,32 @@ + + static void decode_rgb_frame(FFV1Context *s, uint32_t *src, int w, int h, int stride){ + int x, y, p; +- int_fast16_t *sample[3][2]; +- for(x=0; x<3; x++){ ++ int16_t *sample[4][2]; ++ for(x=0; x<4; x++){ + sample[x][0] = s->sample_buffer + x*2 *(w+6) + 3; + sample[x][1] = s->sample_buffer + (x*2+1)*(w+6) + 3; + } + + s->run_index=0; + +- memset(s->sample_buffer, 0, 6*(w+6)*sizeof(*s->sample_buffer)); ++ memset(s->sample_buffer, 0, 8*(w+6)*sizeof(*s->sample_buffer)); + + for(y=0; ytransparency; p++){ ++ int16_t *temp = sample[p][0]; //FIXME try a normal buffer + + sample[p][0]= sample[p][1]; + sample[p][1]= temp; + + sample[p][1][-1]= sample[p][0][0 ]; + sample[p][0][ w]= sample[p][0][w-1]; +- decode_line(s, w, sample[p], FFMIN(p, 1), 9); ++ decode_line(s, w, sample[p], (p+1)/2, 9); + } + for(x=0; x=0 && b>=0 && r>=0); + // assert(g<256 && b<512 && r<512); +@@ -1435,7 +1404,7 @@ + b += g; + r += g; + +- src[x + stride*y]= b + (g<<8) + (r<<16) + (0xFF<<24); ++ src[x + stride*y]= b + (g<<8) + (r<<16) + (a<<24); + } + } + } +@@ -1447,6 +1416,7 @@ + int height= fs->slice_height; + int x= fs->slice_x; + int y= fs->slice_y; ++ const int ps= (c->bits_per_raw_sample>8)+1; + AVFrame * const p= &f->picture; + + av_assert1(width && height); +@@ -1455,12 +1425,12 @@ + const int chroma_height= -((-height)>>f->chroma_v_shift); + const int cx= x>>f->chroma_h_shift; + const int cy= y>>f->chroma_v_shift; +- decode_plane(fs, p->data[0] + x + y*p->linesize[0], width, height, p->linesize[0], 0); ++ decode_plane(fs, p->data[0] + ps*x + y*p->linesize[0], width, height, p->linesize[0], 0); + +- decode_plane(fs, p->data[1] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1); +- decode_plane(fs, p->data[2] + cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[2], 1); ++ decode_plane(fs, p->data[1] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[1], 1); ++ decode_plane(fs, p->data[2] + ps*cx+cy*p->linesize[1], chroma_width, chroma_height, p->linesize[2], 1); + }else{ +- decode_rgb_frame(fs, (uint32_t*)p->data[0] + x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4); ++ decode_rgb_frame(fs, (uint32_t*)p->data[0] + ps*x + y*(p->linesize[0]/4), width, height, p->linesize[0]/4); + } + + emms_c(); +@@ -1533,8 +1503,8 @@ + get_rac(c, state); //no chroma = false + f->chroma_h_shift= get_symbol(c, state, 0); + f->chroma_v_shift= get_symbol(c, state, 0); +- get_rac(c, state); //transparency plane +- f->plane_count= 2; ++ f->transparency= get_rac(c, state); ++ f->plane_count= 2 + f->transparency; + f->num_h_slices= 1 + get_symbol(c, state, 0); + f->num_v_slices= 1 + get_symbol(c, state, 0); + if(f->num_h_slices > (unsigned)f->width || f->num_v_slices > (unsigned)f->height){ +@@ -1590,8 +1560,8 @@ + get_rac(c, state); //no chroma = false + f->chroma_h_shift= get_symbol(c, state, 0); + f->chroma_v_shift= get_symbol(c, state, 0); +- get_rac(c, state); //transparency plane +- f->plane_count= 2; ++ f->transparency= get_rac(c, state); ++ f->plane_count= 2 + f->transparency; + } + + if(f->colorspace==0){ +@@ -1606,7 +1576,25 @@ + av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); + return -1; + } +- }else{ ++ }else if(f->avctx->bits_per_raw_sample==9) { ++ switch(16*f->chroma_h_shift + f->chroma_v_shift){ ++ case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break; ++ case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break; ++ case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P9 ; f->packed_at_lsb=1; break; ++ default: ++ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); ++ return -1; ++ } ++ }else if(f->avctx->bits_per_raw_sample==10) { ++ switch(16*f->chroma_h_shift + f->chroma_v_shift){ ++ case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break; ++ case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P10; f->packed_at_lsb=1; break; ++ case 0x11: f->avctx->pix_fmt= PIX_FMT_YUV420P10; f->packed_at_lsb=1; break; ++ default: ++ av_log(f->avctx, AV_LOG_ERROR, "format not supported\n"); ++ return -1; ++ } ++ }else { + switch(16*f->chroma_h_shift + f->chroma_v_shift){ + case 0x00: f->avctx->pix_fmt= PIX_FMT_YUV444P16; break; + case 0x10: f->avctx->pix_fmt= PIX_FMT_YUV422P16; break; +@@ -1621,7 +1609,8 @@ + av_log(f->avctx, AV_LOG_ERROR, "chroma subsampling not supported in this colorspace\n"); + return -1; + } +- f->avctx->pix_fmt= PIX_FMT_RGB32; ++ if(f->transparency) f->avctx->pix_fmt= PIX_FMT_RGB32; ++ else f->avctx->pix_fmt= PIX_FMT_0RGB32; + }else{ + av_log(f->avctx, AV_LOG_ERROR, "colorspace not supported\n"); + return -1; +@@ -1643,6 +1632,7 @@ + for(j=0; jslice_count; j++){ + FFV1Context *fs= f->slice_context[j]; + fs->ac= f->ac; ++ fs->packed_at_lsb= f->packed_at_lsb; + + if(f->version >= 2){ + fs->slice_x = get_symbol(c, state, 0) *f->width ; +@@ -1723,7 +1713,7 @@ + ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); + + +- p->pict_type= FF_I_TYPE; //FIXME I vs. P ++ p->pict_type= AV_PICTURE_TYPE_I; //FIXME I vs. P + if(get_rac(c, &keystate)){ + p->key_frame= 1; + if(read_header(f) < 0) +@@ -1756,7 +1746,7 @@ + bytes_read = c->bytestream - c->bytestream_start - 1; + if(bytes_read ==0) av_log(avctx, AV_LOG_ERROR, "error at end of AC stream\n"); //FIXME + //printf("pos=%d\n", bytes_read); +- init_get_bits(&f->slice_context[0]->gb, buf + bytes_read, buf_size - bytes_read); ++ init_get_bits(&f->slice_context[0]->gb, buf + bytes_read, (buf_size - bytes_read) * 8); + } else { + bytes_read = 0; /* avoid warning */ + } +@@ -1773,7 +1763,7 @@ + if(fs->ac){ + ff_init_range_decoder(&fs->c, buf_p, v); + }else{ +- init_get_bits(&fs->gb, buf_p, v); ++ init_get_bits(&fs->gb, buf_p, v * 8); + } + } + +@@ -1787,29 +1777,28 @@ + } + + AVCodec ff_ffv1_decoder = { +- "ffv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FFV1, +- sizeof(FFV1Context), +- decode_init, +- NULL, +- common_end, +- decode_frame, +- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, +- NULL, ++ .name = "ffv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FFV1, ++ .priv_data_size = sizeof(FFV1Context), ++ .init = decode_init, ++ .close = common_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/ | CODEC_CAP_SLICE_THREADS, + .long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"), + }; + + #if CONFIG_FFV1_ENCODER + AVCodec ff_ffv1_encoder = { +- "ffv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FFV1, +- sizeof(FFV1Context), +- encode_init, +- encode_frame, +- common_end, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_RGB32, PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, PIX_FMT_YUV444P16, PIX_FMT_NONE}, ++ .name = "ffv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FFV1, ++ .priv_data_size = sizeof(FFV1Context), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = common_end, ++ .capabilities = CODEC_CAP_SLICE_THREADS, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_0RGB32, PIX_FMT_RGB32, PIX_FMT_YUV420P16, PIX_FMT_YUV422P16, PIX_FMT_YUV444P16, PIX_FMT_YUV420P9, PIX_FMT_YUV420P10, PIX_FMT_YUV422P10, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("FFmpeg video codec #1"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ffwavesynth.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ffwavesynth.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ffwavesynth.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ffwavesynth.c 2012-05-14 14:08:53.714327503 +0200 +@@ -0,0 +1,482 @@ ++/* ++ * Wavesynth pseudo-codec ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/log.h" ++#include "avcodec.h" ++ ++#define SIN_BITS 14 ++#define WS_MAX_CHANNELS 32 ++#define INF_TS 0x7FFFFFFFFFFFFFFF ++ ++#define PINK_UNIT 128 ++ ++/* ++ Format of the extradata and packets ++ ++ THIS INFORMATION IS NOT PART OF THE PUBLIC API OR ABI. ++ IT CAN CHANGE WITHOUT NOTIFICATION. ++ ++ All numbers are in little endian. ++ ++ The codec extradata define a set of intervals with uniform content. ++ Overlapping intervals are added together. ++ ++ extradata: ++ uint32 number of intervals ++ ... intervals ++ ++ interval: ++ int64 start timestamp; time_base must be 1/sample_rate; ++ start timestamps must be in ascending order ++ int64 end timestamp ++ uint32 type ++ uint32 channels mask ++ ... additional information, depends on type ++ ++ sine interval (type fourcc "SINE"): ++ int32 start frequency, in 1/(1<<16) Hz ++ int32 end frequency ++ int32 start amplitude, 1<<16 is the full amplitude ++ int32 end amplitude ++ uint32 start phase, 0 is sin(0), 0x20000000 is sin(pi/2), etc.; ++ n | (1<<31) means to match the phase of previous channel #n ++ ++ pink noise interval (type fourcc "NOIS"): ++ int32 start amplitude ++ int32 end amplitude ++ ++ The input packets encode the time and duration of the requested segment. ++ ++ packet: ++ int64 start timestamp ++ int32 duration ++ ++*/ ++ ++enum ws_interval_type { ++ WS_SINE = MKTAG('S','I','N','E'), ++ WS_NOISE = MKTAG('N','O','I','S'), ++}; ++ ++struct ws_interval { ++ int64_t ts_start, ts_end; ++ uint64_t phi0, dphi0, ddphi; ++ uint64_t amp0, damp; ++ uint64_t phi, dphi, amp; ++ uint32_t channels; ++ enum ws_interval_type type; ++ int next; ++}; ++ ++struct wavesynth_context { ++ int64_t cur_ts; ++ int64_t next_ts; ++ int32_t *sin; ++ AVFrame frame; ++ struct ws_interval *inter; ++ uint32_t dither_state; ++ uint32_t pink_state; ++ int32_t pink_pool[PINK_UNIT]; ++ unsigned pink_need, pink_pos; ++ int nb_inter; ++ int cur_inter; ++ int next_inter; ++}; ++ ++#define LCG_A 1284865837 ++#define LCG_C 4150755663 ++#define LCG_AI 849225893 /* A*AI = 1 [mod 1<<32] */ ++ ++static uint32_t lcg_next(uint32_t *s) ++{ ++ *s = *s * LCG_A + LCG_C; ++ return *s; ++} ++ ++static void lcg_seek(uint32_t *s, int64_t dt) ++{ ++ uint32_t a, c, t = *s; ++ ++ if (dt >= 0) { ++ a = LCG_A; ++ c = LCG_C; ++ } else { /* coefficients for a step backward */ ++ a = LCG_AI; ++ c = (uint32_t)(LCG_AI * LCG_C); ++ dt = -dt; ++ } ++ while (dt) { ++ if (dt & 1) ++ t = a * t + c; ++ c *= a + 1; /* coefficients for a double step */ ++ a *= a; ++ dt >>= 1; ++ } ++ *s = t; ++} ++ ++/* Emulate pink noise by summing white noise at the sampling frequency, ++ * white noise at half the sampling frequency (each value taken twice), ++ * etc., with a total of 8 octaves. ++ * This is known as the Voss-McCartney algorithm. */ ++ ++static void pink_fill(struct wavesynth_context *ws) ++{ ++ int32_t vt[7] = { 0 }, v = 0; ++ int i, j; ++ ++ ws->pink_pos = 0; ++ if (!ws->pink_need) ++ return; ++ for (i = 0; i < PINK_UNIT; i++) { ++ for (j = 0; j < 7; j++) { ++ if ((i >> j) & 1) ++ break; ++ v -= vt[j]; ++ vt[j] = (int32_t)lcg_next(&ws->pink_state) >> 3; ++ v += vt[j]; ++ } ++ ws->pink_pool[i] = v + ((int32_t)lcg_next(&ws->pink_state) >> 3); ++ } ++ lcg_next(&ws->pink_state); /* so we use exactly 256 steps */ ++} ++ ++/** ++ * @return (1<<64) * a / b, without overflow, if a < b ++ */ ++static uint64_t frac64(uint64_t a, uint64_t b) ++{ ++ uint64_t r = 0; ++ int i; ++ ++ if (b < (uint64_t)1 << 32) { /* b small, use two 32-bits steps */ ++ a <<= 32; ++ return ((a / b) << 32) | ((a % b) << 32) / b; ++ } ++ if (b < (uint64_t)1 << 48) { /* b medium, use four 16-bits steps */ ++ for (i = 0; i < 4; i++) { ++ a <<= 16; ++ r = (r << 16) | (a / b); ++ a %= b; ++ } ++ return r; ++ } ++ for (i = 63; i >= 0; i--) { ++ if (a >= (uint64_t)1 << 63 || a << 1 >= b) { ++ r |= (uint64_t)1 << i; ++ a = (a << 1) - b; ++ } else { ++ a <<= 1; ++ } ++ } ++ return r; ++} ++ ++static uint64_t phi_at(struct ws_interval *in, int64_t ts) ++{ ++ uint64_t dt = ts - in->ts_start; ++ uint64_t dt2 = dt & 1 ? /* dt * (dt - 1) / 2 without overflow */ ++ dt * ((dt - 1) >> 1) : (dt >> 1) * (dt - 1); ++ return in->phi0 + dt * in->dphi0 + dt2 * in->ddphi; ++} ++ ++static void wavesynth_seek(struct wavesynth_context *ws, int64_t ts) ++{ ++ int *last, i; ++ struct ws_interval *in; ++ ++ last = &ws->cur_inter; ++ for (i = 0; i < ws->nb_inter; i++) { ++ in = &ws->inter[i]; ++ if (ts < in->ts_start) ++ break; ++ if (ts >= in->ts_end) ++ continue; ++ *last = i; ++ last = &in->next; ++ in->phi = phi_at(in, ts); ++ in->dphi = in->dphi0 + (ts - in->ts_start) * in->ddphi; ++ in->amp = in->amp0 + (ts - in->ts_start) * in->damp; ++ } ++ ws->next_inter = i; ++ ws->next_ts = i < ws->nb_inter ? ws->inter[i].ts_start : INF_TS; ++ *last = -1; ++ lcg_seek(&ws->dither_state, ts - ws->cur_ts); ++ if (ws->pink_need) { ++ int64_t pink_ts_cur = (ws->cur_ts + PINK_UNIT - 1) & ~(PINK_UNIT - 1); ++ int64_t pink_ts_next = ts & ~(PINK_UNIT - 1); ++ int pos = ts & (PINK_UNIT - 1); ++ lcg_seek(&ws->pink_state, (pink_ts_next - pink_ts_cur) << 1); ++ if (pos) { ++ pink_fill(ws); ++ ws->pink_pos = pos; ++ } else { ++ ws->pink_pos = PINK_UNIT; ++ } ++ } ++ ws->cur_ts = ts; ++} ++ ++static int wavesynth_parse_extradata(AVCodecContext *avc) ++{ ++ struct wavesynth_context *ws = avc->priv_data; ++ struct ws_interval *in; ++ uint8_t *edata, *edata_end; ++ int32_t f1, f2, a1, a2; ++ uint32_t phi; ++ int64_t dphi1, dphi2, dt, cur_ts = -0x8000000000000000; ++ int i; ++ ++ if (avc->extradata_size < 4) ++ return AVERROR(EINVAL); ++ edata = avc->extradata; ++ edata_end = edata + avc->extradata_size; ++ ws->nb_inter = AV_RL32(edata); ++ edata += 4; ++ if (ws->nb_inter < 0) ++ return AVERROR(EINVAL); ++ ws->inter = av_calloc(ws->nb_inter, sizeof(*ws->inter)); ++ if (!ws->inter) ++ return AVERROR(ENOMEM); ++ for (i = 0; i < ws->nb_inter; i++) { ++ in = &ws->inter[i]; ++ if (edata_end - edata < 24) ++ return AVERROR(EINVAL); ++ in->ts_start = AV_RL64(edata + 0); ++ in->ts_end = AV_RL64(edata + 8); ++ in->type = AV_RL32(edata + 16); ++ in->channels = AV_RL32(edata + 20); ++ edata += 24; ++ if (in->ts_start < cur_ts || in->ts_end <= in->ts_start) ++ return AVERROR(EINVAL); ++ cur_ts = in->ts_start; ++ dt = in->ts_end - in->ts_start; ++ switch (in->type) { ++ case WS_SINE: ++ if (edata_end - edata < 20) ++ return AVERROR(EINVAL); ++ f1 = AV_RL32(edata + 0); ++ f2 = AV_RL32(edata + 4); ++ a1 = AV_RL32(edata + 8); ++ a2 = AV_RL32(edata + 12); ++ phi = AV_RL32(edata + 16); ++ edata += 20; ++ dphi1 = frac64(f1, (int64_t)avc->sample_rate << 16); ++ dphi2 = frac64(f2, (int64_t)avc->sample_rate << 16); ++ in->dphi0 = dphi1; ++ in->ddphi = (dphi2 - dphi1) / dt; ++ if (phi & 0x80000000) { ++ phi &= ~0x80000000; ++ if (phi >= i) ++ return AVERROR(EINVAL); ++ in->phi0 = phi_at(&ws->inter[phi], in->ts_start); ++ } else { ++ in->phi0 = (uint64_t)phi << 33; ++ } ++ break; ++ case WS_NOISE: ++ if (edata_end - edata < 8) ++ return AVERROR(EINVAL); ++ a1 = AV_RL32(edata + 0); ++ a2 = AV_RL32(edata + 4); ++ edata += 8; ++ break; ++ default: ++ return AVERROR(EINVAL); ++ } ++ in->amp0 = (int64_t)a1 << 32; ++ in->damp = (((int64_t)a2 << 32) - ((int64_t)a1 << 32)) / dt; ++ } ++ if (edata != edata_end) ++ return AVERROR(EINVAL); ++ return 0; ++} ++ ++static av_cold int wavesynth_init(AVCodecContext *avc) ++{ ++ struct wavesynth_context *ws = avc->priv_data; ++ int i, r; ++ ++ if (avc->channels > WS_MAX_CHANNELS) { ++ av_log(avc, AV_LOG_ERROR, ++ "This implementation is limited to %d channels.\n", ++ WS_MAX_CHANNELS); ++ return AVERROR(EINVAL); ++ } ++ r = wavesynth_parse_extradata(avc); ++ if (r < 0) { ++ av_log(avc, AV_LOG_ERROR, "Invalid intervals definitions.\n"); ++ goto fail; ++ } ++ ws->sin = av_malloc(sizeof(*ws->sin) << SIN_BITS); ++ if (!ws->sin) { ++ r = AVERROR(ENOMEM); ++ goto fail; ++ } ++ for (i = 0; i < 1 << SIN_BITS; i++) ++ ws->sin[i] = floor(32767 * sin(2 * M_PI * i / (1 << SIN_BITS))); ++ ws->dither_state = MKTAG('D','I','T','H'); ++ for (i = 0; i < ws->nb_inter; i++) ++ ws->pink_need += ws->inter[i].type == WS_NOISE; ++ ws->pink_state = MKTAG('P','I','N','K'); ++ ws->pink_pos = PINK_UNIT; ++ avcodec_get_frame_defaults(&ws->frame); ++ avc->coded_frame = &ws->frame; ++ wavesynth_seek(ws, 0); ++ avc->sample_fmt = AV_SAMPLE_FMT_S16; ++ return 0; ++ ++fail: ++ av_free(ws->inter); ++ av_free(ws->sin); ++ return r; ++} ++ ++static void wavesynth_synth_sample(struct wavesynth_context *ws, int64_t ts, ++ int32_t *channels) ++{ ++ int32_t amp, val, *cv; ++ struct ws_interval *in; ++ int i, *last, pink; ++ uint32_t c, all_ch = 0; ++ ++ i = ws->cur_inter; ++ last = &ws->cur_inter; ++ if (ws->pink_pos == PINK_UNIT) ++ pink_fill(ws); ++ pink = ws->pink_pool[ws->pink_pos++] >> 16; ++ while (i >= 0) { ++ in = &ws->inter[i]; ++ i = in->next; ++ if (ts >= in->ts_end) { ++ *last = i; ++ continue; ++ } ++ last = &in->next; ++ amp = in->amp >> 32; ++ in->amp += in->damp; ++ switch (in->type) { ++ case WS_SINE: ++ val = amp * ws->sin[in->phi >> (64 - SIN_BITS)]; ++ in->phi += in->dphi; ++ in->dphi += in->ddphi; ++ break; ++ case WS_NOISE: ++ val = amp * pink; ++ break; ++ default: ++ val = 0; ++ } ++ all_ch |= in->channels; ++ for (c = in->channels, cv = channels; c; c >>= 1, cv++) ++ if (c & 1) ++ *cv += val; ++ } ++ val = (int32_t)lcg_next(&ws->dither_state) >> 16; ++ for (c = all_ch, cv = channels; c; c >>= 1, cv++) ++ if (c & 1) ++ *cv += val; ++} ++ ++static void wavesynth_enter_intervals(struct wavesynth_context *ws, int64_t ts) ++{ ++ int *last, i; ++ struct ws_interval *in; ++ ++ last = &ws->cur_inter; ++ for (i = ws->cur_inter; i >= 0; i = ws->inter[i].next) ++ last = &ws->inter[i].next; ++ for (i = ws->next_inter; i < ws->nb_inter; i++) { ++ in = &ws->inter[i]; ++ if (ts < in->ts_start) ++ break; ++ if (ts >= in->ts_end) ++ continue; ++ *last = i; ++ last = &in->next; ++ in->phi = in->phi0; ++ in->dphi = in->dphi0; ++ in->amp = in->amp0; ++ } ++ ws->next_inter = i; ++ ws->next_ts = i < ws->nb_inter ? ws->inter[i].ts_start : INF_TS; ++ *last = -1; ++} ++ ++static int wavesynth_decode(AVCodecContext *avc, void *rframe, int *rgot_frame, ++ AVPacket *packet) ++{ ++ struct wavesynth_context *ws = avc->priv_data; ++ int64_t ts; ++ int duration; ++ int s, c, r; ++ int16_t *pcm; ++ int32_t channels[WS_MAX_CHANNELS]; ++ ++ *rgot_frame = 0; ++ if (packet->size != 12) ++ return AVERROR_INVALIDDATA; ++ ts = AV_RL64(packet->data); ++ if (ts != ws->cur_ts) ++ wavesynth_seek(ws, ts); ++ duration = AV_RL32(packet->data + 8); ++ if (duration <= 0) ++ return AVERROR(EINVAL); ++ ws->frame.nb_samples = duration; ++ r = avc->get_buffer(avc, &ws->frame); ++ if (r < 0) ++ return r; ++ pcm = (int16_t *)ws->frame.data[0]; ++ for (s = 0; s < duration; s++, ts++) { ++ memset(channels, 0, avc->channels * sizeof(*channels)); ++ if (ts >= ws->next_ts) ++ wavesynth_enter_intervals(ws, ts); ++ wavesynth_synth_sample(ws, ts, channels); ++ for (c = 0; c < avc->channels; c++) ++ *(pcm++) = channels[c] >> 16; ++ } ++ ws->cur_ts += duration; ++ *rgot_frame = 1; ++ *(AVFrame *)rframe = ws->frame; ++ return packet->size; ++} ++ ++static av_cold int wavesynth_close(AVCodecContext *avc) ++{ ++ struct wavesynth_context *ws = avc->priv_data; ++ ++ av_free(ws->sin); ++ av_free(ws->inter); ++ return 0; ++} ++ ++AVCodec ff_ffwavesynth_decoder = { ++ .name = "wavesynth", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_FFWAVESYNTH, ++ .priv_data_size = sizeof(struct wavesynth_context), ++ .init = wavesynth_init, ++ .close = wavesynth_close, ++ .decode = wavesynth_decode, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Wave synthesis pseudo-codec"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac.c 2012-05-14 14:08:53.715327523 +0200 +@@ -22,6 +22,7 @@ + #include "libavutil/crc.h" + #include "flac.h" + #include "flacdata.h" ++#include "vorbis.h" + + static const int8_t sample_size_table[] = { 0, 8, 12, 0, 16, 20, 24, 0 }; + +@@ -54,9 +55,12 @@ + fi->ch_mode = get_bits(gb, 4); + if (fi->ch_mode < FLAC_MAX_CHANNELS) { + fi->channels = fi->ch_mode + 1; ++ if (fi->ch_mode <= 5) ++ avctx->channel_layout = ff_vorbis_channel_layouts[fi->ch_mode]; + fi->ch_mode = FLAC_CHMODE_INDEPENDENT; + } else if (fi->ch_mode <= FLAC_CHMODE_MID_SIDE) { + fi->channels = 2; ++ avctx->channel_layout = AV_CH_LAYOUT_STEREO; + } else { + av_log(avctx, AV_LOG_ERROR + log_level_offset, + "invalid channel mode: %d\n", fi->ch_mode); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flacdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flacdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flacdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flacdec.c 2012-05-14 14:08:53.718327584 +0200 +@@ -23,9 +23,7 @@ + * @file + * FLAC (Free Lossless Audio Codec) decoder + * @author Alex Beregszaszi +- * +- * For more information on the FLAC format, visit: +- * http://flac.sourceforge.net/ ++ * @see http://flac.sourceforge.net/ + * + * This decoder can be used in 1 of 2 ways: Either raw FLAC data can be fed + * through, starting from the initial 'fLaC' signature; or by passing the +@@ -51,6 +49,7 @@ + FLACSTREAMINFO + + AVCodecContext *avctx; ///< parent AVCodecContext ++ AVFrame frame; + GetBitContext gb; ///< GetBitContext initialized to start at the current frame + + int blocksize; ///< number of samples in the current frame +@@ -65,7 +64,7 @@ + + static void allocate_buffers(FLACContext *s); + +-int ff_flac_is_extradata_valid(AVCodecContext *avctx, ++int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, + enum FLACExtradataFormat *format, + uint8_t **streaminfo_start) + { +@@ -106,11 +105,11 @@ + if (!avctx->extradata) + return 0; + +- if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo)) ++ if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo)) + return -1; + + /* initialize based on the demuxer-supplied streamdata header */ +- ff_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); ++ avpriv_flac_parse_streaminfo(avctx, (FLACStreaminfo *)s, streaminfo); + if (s->bps > 16) + avctx->sample_fmt = AV_SAMPLE_FMT_S32; + else +@@ -118,6 +117,9 @@ + allocate_buffers(s); + s->got_streaminfo = 1; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -142,7 +144,7 @@ + } + } + +-void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, ++void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, + const uint8_t *buffer) + { + GetBitContext gb; +@@ -176,7 +178,7 @@ + dump_headers(avctx, s); + } + +-void ff_flac_parse_block_header(const uint8_t *block_header, ++void avpriv_flac_parse_block_header(const uint8_t *block_header, + int *last, int *type, int *size) + { + int tmp = bytestream_get_byte(&block_header); +@@ -203,12 +205,12 @@ + /* need more data */ + return 0; + } +- ff_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); ++ avpriv_flac_parse_block_header(&buf[4], NULL, &metadata_type, &metadata_size); + if (metadata_type != FLAC_METADATA_TYPE_STREAMINFO || + metadata_size != FLAC_STREAMINFO_SIZE) { + return AVERROR_INVALIDDATA; + } +- ff_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); ++ avpriv_flac_parse_streaminfo(s->avctx, (FLACStreaminfo *)s, &buf[8]); + allocate_buffers(s); + s->got_streaminfo = 1; + +@@ -228,9 +230,11 @@ + + buf += 4; + do { +- ff_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); ++ if (buf_end - buf < 4) ++ return 0; ++ avpriv_flac_parse_block_header(buf, &metadata_last, NULL, &metadata_size); + buf += 4; +- if (buf + metadata_size > buf_end) { ++ if (buf_end - buf < metadata_size) { + /* need more data in order to read the complete header */ + return 0; + } +@@ -418,7 +422,16 @@ + type = get_bits(&s->gb, 6); + + if (get_bits1(&s->gb)) { ++ int left = get_bits_left(&s->gb); + wasted = 1; ++ if ( left < 0 || ++ (left < s->curr_bps && !show_bits_long(&s->gb, left)) || ++ !show_bits_long(&s->gb, s->curr_bps)) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Invalid number of wasted bits > available bits (%d) - left=%d\n", ++ s->curr_bps, left); ++ return AVERROR_INVALIDDATA; ++ } + while (!get_bits1(&s->gb)) + wasted++; + s->curr_bps -= wasted; +@@ -542,20 +555,18 @@ + return 0; + } + +-static int flac_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int flac_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + FLACContext *s = avctx->priv_data; + int i, j = 0, bytes_read = 0; +- int16_t *samples_16 = data; +- int32_t *samples_32 = data; +- int alloc_data_size= *data_size; +- int output_size; ++ int16_t *samples_16; ++ int32_t *samples_32; ++ int ret; + +- *data_size=0; ++ *got_frame_ptr = 0; + + if (s->max_framesize == 0) { + s->max_framesize = +@@ -586,14 +597,14 @@ + } + bytes_read = (get_bits_count(&s->gb)+7)/8; + +- /* check if allocated data size is large enough for output */ +- output_size = s->blocksize * s->channels * (s->is32 ? 4 : 2); +- if (output_size > alloc_data_size) { +- av_log(s->avctx, AV_LOG_ERROR, "output data size is larger than " +- "allocated data size\n"); +- return -1; ++ /* get output buffer */ ++ s->frame.nb_samples = s->blocksize; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } +- *data_size = output_size; ++ samples_16 = (int16_t *)s->frame.data[0]; ++ samples_32 = (int32_t *)s->frame.data[0]; + + #define DECORRELATE(left, right)\ + assert(s->channels == 2);\ +@@ -638,6 +649,9 @@ + buf_size - bytes_read, buf_size); + } + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return bytes_read; + } + +@@ -654,13 +668,13 @@ + } + + AVCodec ff_flac_decoder = { +- "flac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_FLAC, +- sizeof(FLACContext), +- flac_decode_init, +- NULL, +- flac_decode_close, +- flac_decode_frame, ++ .name = "flac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_FLAC, ++ .priv_data_size = sizeof(FLACContext), ++ .init = flac_decode_init, ++ .close = flac_decode_close, ++ .decode = flac_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flacenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flacenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flacenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flacenc.c 2012-05-14 14:08:53.720327624 +0200 +@@ -21,6 +21,7 @@ + + #include "libavutil/crc.h" + #include "libavutil/md5.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "get_bits.h" + #include "golomb.h" +@@ -43,7 +44,7 @@ + typedef struct CompressionOptions { + int compression_level; + int block_time_ms; +- enum AVLPCType lpc_type; ++ enum FFLPCType lpc_type; + int lpc_passes; + int lpc_coeff_precision; + int min_prediction_order; +@@ -80,6 +81,7 @@ + } FlacFrame; + + typedef struct FlacEncodeContext { ++ AVClass *class; + PutBitContext pb; + int channels; + int samplerate; +@@ -156,16 +158,16 @@ + av_log(avctx, AV_LOG_DEBUG, " compression: %d\n", opt->compression_level); + + switch (opt->lpc_type) { +- case AV_LPC_TYPE_NONE: ++ case FF_LPC_TYPE_NONE: + av_log(avctx, AV_LOG_DEBUG, " lpc type: None\n"); + break; +- case AV_LPC_TYPE_FIXED: ++ case FF_LPC_TYPE_FIXED: + av_log(avctx, AV_LOG_DEBUG, " lpc type: Fixed pre-defined coefficients\n"); + break; +- case AV_LPC_TYPE_LEVINSON: ++ case FF_LPC_TYPE_LEVINSON: + av_log(avctx, AV_LOG_DEBUG, " lpc type: Levinson-Durbin recursion with Welch window\n"); + break; +- case AV_LPC_TYPE_CHOLESKY: ++ case FF_LPC_TYPE_CHOLESKY: + av_log(avctx, AV_LOG_DEBUG, " lpc type: Cholesky factorization, %d pass%s\n", + opt->lpc_passes, opt->lpc_passes == 1 ? "" : "es"); + break; +@@ -266,43 +268,42 @@ + + s->options.block_time_ms = ((int[]){ 27, 27, 27,105,105,105,105,105,105,105,105,105,105})[level]; + +- s->options.lpc_type = ((int[]){ AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, AV_LPC_TYPE_FIXED, +- AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, +- AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, +- AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, AV_LPC_TYPE_LEVINSON, +- AV_LPC_TYPE_LEVINSON})[level]; ++ if (s->options.lpc_type == FF_LPC_TYPE_DEFAULT) ++ s->options.lpc_type = ((int[]){ FF_LPC_TYPE_FIXED, FF_LPC_TYPE_FIXED, FF_LPC_TYPE_FIXED, ++ FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, ++ FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, ++ FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_LEVINSON, ++ FF_LPC_TYPE_LEVINSON})[level]; + + s->options.min_prediction_order = ((int[]){ 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1})[level]; + s->options.max_prediction_order = ((int[]){ 3, 4, 4, 6, 8, 8, 8, 8, 12, 12, 12, 32, 32})[level]; + +- s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, +- ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, +- ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL, +- ORDER_METHOD_LOG, ORDER_METHOD_SEARCH, ORDER_METHOD_LOG, +- ORDER_METHOD_SEARCH})[level]; ++ if (s->options.prediction_order_method < 0) ++ s->options.prediction_order_method = ((int[]){ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ++ ORDER_METHOD_EST, ORDER_METHOD_EST, ORDER_METHOD_EST, ++ ORDER_METHOD_4LEVEL, ORDER_METHOD_LOG, ORDER_METHOD_4LEVEL, ++ ORDER_METHOD_LOG, ORDER_METHOD_SEARCH, ORDER_METHOD_LOG, ++ ORDER_METHOD_SEARCH})[level]; + +- s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level]; +- s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; ++ if (s->options.min_partition_order > s->options.max_partition_order) { ++ av_log(avctx, AV_LOG_ERROR, "invalid partition orders: min=%d max=%d\n", ++ s->options.min_partition_order, s->options.max_partition_order); ++ return AVERROR(EINVAL); ++ } ++ if (s->options.min_partition_order < 0) ++ s->options.min_partition_order = ((int[]){ 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0})[level]; ++ if (s->options.max_partition_order < 0) ++ s->options.max_partition_order = ((int[]){ 2, 2, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8})[level]; + + /* set compression option overrides from AVCodecContext */ +-#if FF_API_USE_LPC +- /* for compatibility with deprecated AVCodecContext.use_lpc */ +- if (avctx->use_lpc == 0) { +- s->options.lpc_type = AV_LPC_TYPE_FIXED; +- } else if (avctx->use_lpc == 1) { +- s->options.lpc_type = AV_LPC_TYPE_LEVINSON; +- } else if (avctx->use_lpc > 1) { +- s->options.lpc_type = AV_LPC_TYPE_CHOLESKY; +- s->options.lpc_passes = avctx->use_lpc - 1; +- } +-#endif +- if (avctx->lpc_type > AV_LPC_TYPE_DEFAULT) { +- if (avctx->lpc_type > AV_LPC_TYPE_CHOLESKY) { ++#if FF_API_FLAC_GLOBAL_OPTS ++ if (avctx->lpc_type > FF_LPC_TYPE_DEFAULT) { ++ if (avctx->lpc_type > FF_LPC_TYPE_CHOLESKY) { + av_log(avctx, AV_LOG_ERROR, "unknown lpc type: %d\n", avctx->lpc_type); + return -1; + } + s->options.lpc_type = avctx->lpc_type; +- if (s->options.lpc_type == AV_LPC_TYPE_CHOLESKY) { ++ if (s->options.lpc_type == FF_LPC_TYPE_CHOLESKY) { + if (avctx->lpc_passes < 0) { + // default number of passes for Cholesky + s->options.lpc_passes = 2; +@@ -315,11 +316,12 @@ + } + } + } ++#endif + +- if (s->options.lpc_type == AV_LPC_TYPE_NONE) { ++ if (s->options.lpc_type == FF_LPC_TYPE_NONE) { + s->options.min_prediction_order = 0; + } else if (avctx->min_prediction_order >= 0) { +- if (s->options.lpc_type == AV_LPC_TYPE_FIXED) { ++ if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { + if (avctx->min_prediction_order > MAX_FIXED_ORDER) { + av_log(avctx, AV_LOG_ERROR, "invalid min prediction order: %d\n", + avctx->min_prediction_order); +@@ -333,10 +335,10 @@ + } + s->options.min_prediction_order = avctx->min_prediction_order; + } +- if (s->options.lpc_type == AV_LPC_TYPE_NONE) { ++ if (s->options.lpc_type == FF_LPC_TYPE_NONE) { + s->options.max_prediction_order = 0; + } else if (avctx->max_prediction_order >= 0) { +- if (s->options.lpc_type == AV_LPC_TYPE_FIXED) { ++ if (s->options.lpc_type == FF_LPC_TYPE_FIXED) { + if (avctx->max_prediction_order > MAX_FIXED_ORDER) { + av_log(avctx, AV_LOG_ERROR, "invalid max prediction order: %d\n", + avctx->max_prediction_order); +@@ -356,6 +358,7 @@ + return -1; + } + ++#if FF_API_FLAC_GLOBAL_OPTS + if (avctx->prediction_order_method >= 0) { + if (avctx->prediction_order_method > ORDER_METHOD_LOG) { + av_log(avctx, AV_LOG_ERROR, "invalid prediction order method: %d\n", +@@ -386,6 +389,7 @@ + s->options.min_partition_order, s->options.max_partition_order); + return -1; + } ++#endif + + if (avctx->frame_size > 0) { + if (avctx->frame_size < FLAC_MIN_BLOCKSIZE || +@@ -399,6 +403,7 @@ + } + s->max_blocksize = s->avctx->frame_size; + ++#if FF_API_FLAC_GLOBAL_OPTS + /* set LPC precision */ + if (avctx->lpc_coeff_precision > 0) { + if (avctx->lpc_coeff_precision > MAX_LPC_PRECISION) { +@@ -407,10 +412,8 @@ + return -1; + } + s->options.lpc_coeff_precision = avctx->lpc_coeff_precision; +- } else { +- /* default LPC precision */ +- s->options.lpc_coeff_precision = 15; + } ++#endif + + /* set maximum encoded frame size in verbatim mode */ + s->max_framesize = ff_flac_get_max_frame_size(s->avctx->frame_size, +@@ -436,8 +439,30 @@ + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + ++ if (channels == 3 && ++ avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || ++ channels == 4 && ++ avctx->channel_layout != AV_CH_LAYOUT_2_2 && ++ avctx->channel_layout != AV_CH_LAYOUT_QUAD || ++ channels == 5 && ++ avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && ++ avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || ++ channels == 6 && ++ avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && ++ avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK) { ++ if (avctx->channel_layout) { ++ av_log(avctx, AV_LOG_ERROR, "Channel layout not supported by Flac, " ++ "output stream will have incorrect " ++ "channel layout.\n"); ++ } else { ++ av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder " ++ "will use Flac channel layout for " ++ "%d channels.\n", channels); ++ } ++ } ++ + ret = ff_lpc_init(&s->lpc_ctx, avctx->frame_size, +- s->options.max_prediction_order, AV_LPC_TYPE_LEVINSON); ++ s->options.max_prediction_order, FF_LPC_TYPE_LEVINSON); + + dprint_compression_options(s); + +@@ -878,8 +903,8 @@ + + /* FIXED */ + sub->type = FLAC_SUBFRAME_FIXED; +- if (s->options.lpc_type == AV_LPC_TYPE_NONE || +- s->options.lpc_type == AV_LPC_TYPE_FIXED || n <= max_order) { ++ if (s->options.lpc_type == FF_LPC_TYPE_NONE || ++ s->options.lpc_type == FF_LPC_TYPE_FIXED || n <= max_order) { + uint32_t bits[MAX_FIXED_ORDER+1]; + if (max_order > MAX_FIXED_ORDER) + max_order = MAX_FIXED_ORDER; +@@ -977,7 +1002,7 @@ + + static int count_frame_header(FlacEncodeContext *s) + { +- uint8_t tmp; ++ uint8_t av_unused tmp; + int count; + + /* +@@ -1325,17 +1350,44 @@ + return 0; + } + ++#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM ++static const AVOption options[] = { ++{ "lpc_coeff_precision", "LPC coefficient precision", offsetof(FlacEncodeContext, options.lpc_coeff_precision), AV_OPT_TYPE_INT, {.dbl = 15 }, 0, MAX_LPC_PRECISION, FLAGS }, ++{ "lpc_type", "LPC algorithm", offsetof(FlacEncodeContext, options.lpc_type), AV_OPT_TYPE_INT, {.dbl = FF_LPC_TYPE_DEFAULT }, FF_LPC_TYPE_DEFAULT, FF_LPC_TYPE_NB-1, FLAGS, "lpc_type" }, ++{ "none", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_NONE }, INT_MIN, INT_MAX, FLAGS, "lpc_type" }, ++{ "fixed", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, FLAGS, "lpc_type" }, ++{ "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, FLAGS, "lpc_type" }, ++{ "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, FLAGS, "lpc_type" }, ++{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", offsetof(FlacEncodeContext, options.lpc_passes), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, FLAGS }, ++{ "min_partition_order", NULL, offsetof(FlacEncodeContext, options.min_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS }, ++{ "max_partition_order", NULL, offsetof(FlacEncodeContext, options.max_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, MAX_PARTITION_ORDER, FLAGS }, ++{ "prediction_order_method", "Search method for selecting prediction order", offsetof(FlacEncodeContext, options.prediction_order_method), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, ORDER_METHOD_LOG, FLAGS, "predm" }, ++{ "estimation", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_EST }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ "2level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_2LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ "4level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_4LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ "8level", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_8LEVEL }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ "search", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_SEARCH }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ "log", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = ORDER_METHOD_LOG }, INT_MIN, INT_MAX, FLAGS, "predm" }, ++{ NULL }, ++}; ++ ++static const AVClass flac_encoder_class = { ++ "FLAC encoder", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; + + AVCodec ff_flac_encoder = { +- "flac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_FLAC, +- sizeof(FlacEncodeContext), +- flac_encode_init, +- flac_encode_frame, +- flac_encode_close, +- NULL, +- .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, ++ .name = "flac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_FLAC, ++ .priv_data_size = sizeof(FlacEncodeContext), ++ .init = flac_encode_init, ++ .encode = flac_encode_frame, ++ .close = flac_encode_close, ++ .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_LOSSLESS, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("FLAC (Free Lossless Audio Codec)"), ++ .priv_class = &flac_encoder_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac.h 2012-05-14 14:08:53.716327543 +0200 +@@ -95,8 +95,8 @@ + * @param[out] s where parsed information is stored + * @param[in] buffer pointer to start of 34-byte streaminfo data + */ +-void ff_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, +- const uint8_t *buffer); ++void avpriv_flac_parse_streaminfo(AVCodecContext *avctx, struct FLACStreaminfo *s, ++ const uint8_t *buffer); + + /** + * Validate the FLAC extradata. +@@ -105,9 +105,9 @@ + * @param[out] streaminfo_start pointer to start of 34-byte STREAMINFO data. + * @return 1 if valid, 0 if not valid. + */ +-int ff_flac_is_extradata_valid(AVCodecContext *avctx, +- enum FLACExtradataFormat *format, +- uint8_t **streaminfo_start); ++int avpriv_flac_is_extradata_valid(AVCodecContext *avctx, ++ enum FLACExtradataFormat *format, ++ uint8_t **streaminfo_start); + + /** + * Parse the metadata block parameters from the header. +@@ -116,8 +116,8 @@ + * @param[out] type metadata block type + * @param[out] size metadata block size + */ +-void ff_flac_parse_block_header(const uint8_t *block_header, +- int *last, int *type, int *size); ++void avpriv_flac_parse_block_header(const uint8_t *block_header, ++ int *last, int *type, int *size); + + /** + * Calculate an estimate for the maximum frame size based on verbatim mode. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flac_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flac_parser.c 2012-05-14 14:08:53.717327564 +0200 +@@ -674,9 +674,9 @@ + } + + AVCodecParser ff_flac_parser = { +- { CODEC_ID_FLAC }, +- sizeof(FLACParseContext), +- flac_parse_init, +- flac_parse, +- flac_parse_close, ++ .codec_ids = { CODEC_ID_FLAC }, ++ .priv_data_size = sizeof(FLACParseContext), ++ .parser_init = flac_parse_init, ++ .parser_parse = flac_parse, ++ .parser_close = flac_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsv2enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsv2enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsv2enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsv2enc.c 2012-05-14 14:08:53.725327725 +0200 +@@ -0,0 +1,907 @@ ++/* ++ * Flash Screen Video Version 2 encoder ++ * Copyright (C) 2009 Joshua Warner ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Flash Screen Video Version 2 encoder ++ * @author Joshua Warner ++ */ ++ ++/* Differences from version 1 stream: ++ * NOTE: Currently, the only player that supports version 2 streams is Adobe Flash Player itself. ++ * * Supports sending only a range of scanlines in a block, ++ * indicating a difference from the corresponding block in the last keyframe. ++ * * Supports initializing the zlib dictionary with data from the corresponding ++ * block in the last keyframe, to improve compression. ++ * * Supports a hybrid 15-bit rgb / 7-bit palette color space. ++ */ ++ ++/* TODO: ++ * Don't keep Block structures for both current frame and keyframe. ++ * Make better heuristics for deciding stream parameters (optimum_* functions). Currently these return constants. ++ * Figure out how to encode palette information in the stream, choose an optimum palette at each keyframe. ++ * Figure out how the zlibPrimeCompressCurrent flag works, implement support. ++ * Find other sample files (that weren't generated here), develop a decoder. ++ */ ++ ++#include ++#include ++#include ++ ++#include "libavutil/imgutils.h" ++#include "avcodec.h" ++#include "put_bits.h" ++#include "bytestream.h" ++ ++#define HAS_IFRAME_IMAGE 0x02 ++#define HAS_PALLET_INFO 0x01 ++ ++#define COLORSPACE_BGR 0x00 ++#define COLORSPACE_15_7 0x10 ++#define HAS_DIFF_BLOCKS 0x04 ++#define ZLIB_PRIME_COMPRESS_CURRENT 0x02 ++#define ZLIB_PRIME_COMPRESS_PREVIOUS 0x01 ++ ++// Disables experimental "smart" parameter-choosing code, as well as the statistics that it depends on. ++// At the moment, the "smart" code is a great example of how the parameters *shouldn't* be chosen. ++#define FLASHSV2_DUMB ++ ++typedef struct Block { ++ uint8_t *enc; ++ uint8_t *sl_begin, *sl_end; ++ int enc_size; ++ uint8_t *data; ++ unsigned long data_size; ++ ++ uint8_t start, len; ++ uint8_t dirty; ++ uint8_t col, row, width, height; ++ uint8_t flags; ++} Block; ++ ++typedef struct Palette { ++ unsigned colors[128]; ++ uint8_t index[1 << 15]; ++} Palette; ++ ++typedef struct FlashSV2Context { ++ AVCodecContext *avctx; ++ uint8_t *current_frame; ++ uint8_t *key_frame; ++ AVFrame frame; ++ uint8_t *encbuffer; ++ uint8_t *keybuffer; ++ uint8_t *databuffer; ++ ++ Block *frame_blocks; ++ Block *key_blocks; ++ int frame_size; ++ int blocks_size; ++ ++ int use15_7, dist, comp; ++ ++ int rows, cols; ++ ++ int last_key_frame; ++ ++ int image_width, image_height; ++ int block_width, block_height; ++ uint8_t flags; ++ uint8_t use_custom_palette; ++ uint8_t palette_type; ///< 0=>default, 1=>custom - changed when palette regenerated. ++ Palette palette; ++#ifndef FLASHSV2_DUMB ++ double tot_blocks; ///< blocks encoded since last keyframe ++ double diff_blocks; ///< blocks that were different since last keyframe ++ double tot_lines; ///< total scanlines in image since last keyframe ++ double diff_lines; ///< scanlines that were different since last keyframe ++ double raw_size; ///< size of raw frames since last keyframe ++ double comp_size; ///< size of compressed data since last keyframe ++ double uncomp_size; ///< size of uncompressed data since last keyframe ++ ++ double total_bits; ///< total bits written to stream so far ++#endif ++} FlashSV2Context; ++ ++static av_cold void cleanup(FlashSV2Context * s) ++{ ++ av_freep(&s->encbuffer); ++ av_freep(&s->keybuffer); ++ av_freep(&s->databuffer); ++ av_freep(&s->current_frame); ++ av_freep(&s->key_frame); ++ ++ av_freep(&s->frame_blocks); ++ av_freep(&s->key_blocks); ++} ++ ++static void init_blocks(FlashSV2Context * s, Block * blocks, ++ uint8_t * encbuf, uint8_t * databuf) ++{ ++ int row, col; ++ Block *b; ++ for (col = 0; col < s->cols; col++) { ++ for (row = 0; row < s->rows; row++) { ++ b = blocks + (col + row * s->cols); ++ b->width = (col < s->cols - 1) ? ++ s->block_width : ++ s->image_width - col * s->block_width; ++ ++ b->height = (row < s->rows - 1) ? ++ s->block_height : ++ s->image_height - row * s->block_height; ++ ++ b->row = row; ++ b->col = col; ++ b->enc = encbuf; ++ b->data = databuf; ++ encbuf += b->width * b->height * 3; ++ databuf += !databuf ? 0 : b->width * b->height * 6; ++ } ++ } ++} ++ ++static void reset_stats(FlashSV2Context * s) ++{ ++#ifndef FLASHSV2_DUMB ++ s->diff_blocks = 0.1; ++ s->tot_blocks = 1; ++ s->diff_lines = 0.1; ++ s->tot_lines = 1; ++ s->raw_size = s->comp_size = s->uncomp_size = 10; ++#endif ++} ++ ++static av_cold int flashsv2_encode_init(AVCodecContext * avctx) ++{ ++ FlashSV2Context *s = avctx->priv_data; ++ ++ s->avctx = avctx; ++ ++ s->comp = avctx->compression_level; ++ if (s->comp == -1) ++ s->comp = 9; ++ if (s->comp < 0 || s->comp > 9) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Compression level should be 0-9, not %d\n", s->comp); ++ return -1; ++ } ++ ++ ++ if ((avctx->width > 4095) || (avctx->height > 4095)) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Input dimensions too large, input must be max 4096x4096 !\n"); ++ return -1; ++ } ++ ++ if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) ++ return -1; ++ ++ ++ s->last_key_frame = 0; ++ ++ s->image_width = avctx->width; ++ s->image_height = avctx->height; ++ ++ s->block_width = (s->image_width / 12) & ~15; ++ s->block_height = (s->image_height / 12) & ~15; ++ ++ s->rows = (s->image_height + s->block_height - 1) / s->block_height; ++ s->cols = (s->image_width + s->block_width - 1) / s->block_width; ++ ++ s->frame_size = s->image_width * s->image_height * 3; ++ s->blocks_size = s->rows * s->cols * sizeof(Block); ++ ++ s->encbuffer = av_mallocz(s->frame_size); ++ s->keybuffer = av_mallocz(s->frame_size); ++ s->databuffer = av_mallocz(s->frame_size * 6); ++ s->current_frame = av_mallocz(s->frame_size); ++ s->key_frame = av_mallocz(s->frame_size); ++ s->frame_blocks = av_mallocz(s->blocks_size); ++ s->key_blocks = av_mallocz(s->blocks_size); ++ ++ init_blocks(s, s->frame_blocks, s->encbuffer, s->databuffer); ++ init_blocks(s, s->key_blocks, s->keybuffer, 0); ++ reset_stats(s); ++#ifndef FLASHSV2_DUMB ++ s->total_bits = 1; ++#endif ++ ++ s->use_custom_palette = 0; ++ s->palette_type = -1; // so that the palette will be generated in reconfigure_at_keyframe ++ ++ if (!s->encbuffer || !s->keybuffer || !s->databuffer ++ || !s->current_frame || !s->key_frame || !s->key_blocks ++ || !s->frame_blocks) { ++ av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); ++ cleanup(s); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int new_key_frame(FlashSV2Context * s) ++{ ++ int i; ++ memcpy(s->key_blocks, s->frame_blocks, s->blocks_size); ++ memcpy(s->key_frame, s->current_frame, s->frame_size); ++ ++ for (i = 0; i < s->rows * s->cols; i++) { ++ s->key_blocks[i].enc += (s->keybuffer - s->encbuffer); ++ s->key_blocks[i].sl_begin = 0; ++ s->key_blocks[i].sl_end = 0; ++ s->key_blocks[i].data = 0; ++ } ++ FFSWAP(uint8_t * , s->keybuffer, s->encbuffer); ++ ++ return 0; ++} ++ ++static int write_palette(FlashSV2Context * s, uint8_t * buf, int buf_size) ++{ ++ //this isn't implemented yet! Default palette only! ++ return -1; ++} ++ ++static int write_header(FlashSV2Context * s, uint8_t * buf, int buf_size) ++{ ++ PutBitContext pb; ++ int buf_pos, len; ++ ++ if (buf_size < 5) ++ return -1; ++ ++ init_put_bits(&pb, buf, buf_size * 8); ++ ++ put_bits(&pb, 4, (s->block_width >> 4) - 1); ++ put_bits(&pb, 12, s->image_width); ++ put_bits(&pb, 4, (s->block_height >> 4) - 1); ++ put_bits(&pb, 12, s->image_height); ++ ++ flush_put_bits(&pb); ++ buf_pos = 4; ++ ++ buf[buf_pos++] = s->flags; ++ ++ if (s->flags & HAS_PALLET_INFO) { ++ len = write_palette(s, buf + buf_pos, buf_size - buf_pos); ++ if (len < 0) ++ return -1; ++ buf_pos += len; ++ } ++ ++ return buf_pos; ++} ++ ++static int write_block(Block * b, uint8_t * buf, int buf_size) ++{ ++ int buf_pos = 0; ++ unsigned block_size = b->data_size; ++ ++ if (b->flags & HAS_DIFF_BLOCKS) ++ block_size += 2; ++ if (b->flags & ZLIB_PRIME_COMPRESS_CURRENT) ++ block_size += 2; ++ if (block_size > 0) ++ block_size += 1; ++ if (buf_size < block_size + 2) ++ return -1; ++ ++ buf[buf_pos++] = block_size >> 8; ++ buf[buf_pos++] = block_size; ++ ++ if (block_size == 0) ++ return buf_pos; ++ ++ buf[buf_pos++] = b->flags; ++ ++ if (b->flags & HAS_DIFF_BLOCKS) { ++ buf[buf_pos++] = (b->start); ++ buf[buf_pos++] = (b->len); ++ } ++ ++ if (b->flags & ZLIB_PRIME_COMPRESS_CURRENT) { ++ //This feature of the format is poorly understood, and as of now, unused. ++ buf[buf_pos++] = (b->col); ++ buf[buf_pos++] = (b->row); ++ } ++ ++ memcpy(buf + buf_pos, b->data, b->data_size); ++ ++ buf_pos += b->data_size; ++ ++ return buf_pos; ++} ++ ++static int encode_zlib(Block * b, uint8_t * buf, unsigned long *buf_size, int comp) ++{ ++ int res = compress2(buf, buf_size, b->sl_begin, b->sl_end - b->sl_begin, comp); ++ return res == Z_OK ? 0 : -1; ++} ++ ++static int encode_zlibprime(Block * b, Block * prime, uint8_t * buf, ++ int *buf_size, int comp) ++{ ++ z_stream s; ++ int res; ++ s.zalloc = NULL; ++ s.zfree = NULL; ++ s.opaque = NULL; ++ res = deflateInit(&s, comp); ++ if (res < 0) ++ return -1; ++ ++ s.next_in = prime->enc; ++ s.avail_in = prime->enc_size; ++ while (s.avail_in > 0) { ++ s.next_out = buf; ++ s.avail_out = *buf_size; ++ res = deflate(&s, Z_SYNC_FLUSH); ++ if (res < 0) ++ return -1; ++ } ++ ++ s.next_in = b->sl_begin; ++ s.avail_in = b->sl_end - b->sl_begin; ++ s.next_out = buf; ++ s.avail_out = *buf_size; ++ res = deflate(&s, Z_FINISH); ++ deflateEnd(&s); ++ *buf_size -= s.avail_out; ++ if (res != Z_STREAM_END) ++ return -1; ++ return 0; ++} ++ ++static int encode_bgr(Block * b, const uint8_t * src, int stride) ++{ ++ int i; ++ uint8_t *ptr = b->enc; ++ for (i = 0; i < b->start; i++) ++ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3); ++ b->sl_begin = ptr + i * b->width * 3; ++ for (; i < b->start + b->len; i++) ++ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3); ++ b->sl_end = ptr + i * b->width * 3; ++ for (; i < b->height; i++) ++ memcpy(ptr + i * b->width * 3, src + i * stride, b->width * 3); ++ b->enc_size = ptr + i * b->width * 3 - b->enc; ++ return b->enc_size; ++} ++ ++static inline unsigned pixel_color15(const uint8_t * src) ++{ ++ return (src[0] >> 3) | ((src[1] & 0xf8) << 2) | ((src[2] & 0xf8) << 7); ++} ++ ++static inline unsigned int chroma_diff(unsigned int c1, unsigned int c2) ++{ ++ unsigned int t1 = (c1 & 0x000000ff) + ((c1 & 0x0000ff00) >> 8) + ((c1 & 0x00ff0000) >> 16); ++ unsigned int t2 = (c2 & 0x000000ff) + ((c2 & 0x0000ff00) >> 8) + ((c2 & 0x00ff0000) >> 16); ++ ++ return abs(t1 - t2) + abs((c1 & 0x000000ff) - (c2 & 0x000000ff)) + ++ abs(((c1 & 0x0000ff00) >> 8) - ((c2 & 0x0000ff00) >> 8)) + ++ abs(((c1 & 0x00ff0000) >> 16) - ((c2 & 0x00ff0000) >> 16)); ++} ++ ++static inline int pixel_color7_fast(Palette * palette, unsigned c15) ++{ ++ return palette->index[c15]; ++} ++ ++static int pixel_color7_slow(Palette * palette, unsigned color) ++{ ++ int i, min = 0x7fffffff; ++ int minc = -1; ++ for (i = 0; i < 128; i++) { ++ int c1 = palette->colors[i]; ++ int diff = chroma_diff(c1, color); ++ if (diff < min) { ++ min = diff; ++ minc = i; ++ } ++ } ++ return minc; ++} ++ ++static inline unsigned pixel_bgr(const uint8_t * src) ++{ ++ return (src[0]) | (src[1] << 8) | (src[2] << 16); ++} ++ ++static int write_pixel_15_7(Palette * palette, uint8_t * dest, const uint8_t * src, ++ int dist) ++{ ++ unsigned c15 = pixel_color15(src); ++ unsigned color = pixel_bgr(src); ++ int d15 = chroma_diff(color, color & 0x00f8f8f8); ++ int c7 = pixel_color7_fast(palette, c15); ++ int d7 = chroma_diff(color, palette->colors[c7]); ++ if (dist + d15 >= d7) { ++ dest[0] = c7; ++ return 1; ++ } else { ++ dest[0] = 0x80 | (c15 >> 8); ++ dest[1] = c15 & 0xff; ++ return 2; ++ } ++} ++ ++static int update_palette_index(Palette * palette) ++{ ++ int r, g, b; ++ unsigned int bgr, c15, index; ++ for (r = 4; r < 256; r += 8) { ++ for (g = 4; g < 256; g += 8) { ++ for (b = 4; b < 256; b += 8) { ++ bgr = b | (g << 8) | (r << 16); ++ c15 = (b >> 3) | ((g & 0xf8) << 2) | ((r & 0xf8) << 7); ++ index = pixel_color7_slow(palette, bgr); ++ ++ palette->index[c15] = index; ++ } ++ } ++ } ++ return 0; ++} ++ ++static const unsigned int default_screen_video_v2_palette[128] = { ++ 0x00000000, 0x00333333, 0x00666666, 0x00999999, 0x00CCCCCC, 0x00FFFFFF, ++ 0x00330000, 0x00660000, 0x00990000, 0x00CC0000, 0x00FF0000, 0x00003300, ++ 0x00006600, 0x00009900, 0x0000CC00, 0x0000FF00, 0x00000033, 0x00000066, ++ 0x00000099, 0x000000CC, 0x000000FF, 0x00333300, 0x00666600, 0x00999900, ++ 0x00CCCC00, 0x00FFFF00, 0x00003333, 0x00006666, 0x00009999, 0x0000CCCC, ++ 0x0000FFFF, 0x00330033, 0x00660066, 0x00990099, 0x00CC00CC, 0x00FF00FF, ++ 0x00FFFF33, 0x00FFFF66, 0x00FFFF99, 0x00FFFFCC, 0x00FF33FF, 0x00FF66FF, ++ 0x00FF99FF, 0x00FFCCFF, 0x0033FFFF, 0x0066FFFF, 0x0099FFFF, 0x00CCFFFF, ++ 0x00CCCC33, 0x00CCCC66, 0x00CCCC99, 0x00CCCCFF, 0x00CC33CC, 0x00CC66CC, ++ 0x00CC99CC, 0x00CCFFCC, 0x0033CCCC, 0x0066CCCC, 0x0099CCCC, 0x00FFCCCC, ++ 0x00999933, 0x00999966, 0x009999CC, 0x009999FF, 0x00993399, 0x00996699, ++ 0x0099CC99, 0x0099FF99, 0x00339999, 0x00669999, 0x00CC9999, 0x00FF9999, ++ 0x00666633, 0x00666699, 0x006666CC, 0x006666FF, 0x00663366, 0x00669966, ++ 0x0066CC66, 0x0066FF66, 0x00336666, 0x00996666, 0x00CC6666, 0x00FF6666, ++ 0x00333366, 0x00333399, 0x003333CC, 0x003333FF, 0x00336633, 0x00339933, ++ 0x0033CC33, 0x0033FF33, 0x00663333, 0x00993333, 0x00CC3333, 0x00FF3333, ++ 0x00003366, 0x00336600, 0x00660033, 0x00006633, 0x00330066, 0x00663300, ++ 0x00336699, 0x00669933, 0x00993366, 0x00339966, 0x00663399, 0x00996633, ++ 0x006699CC, 0x0099CC66, 0x00CC6699, 0x0066CC99, 0x009966CC, 0x00CC9966, ++ 0x0099CCFF, 0x00CCFF99, 0x00FF99CC, 0x0099FFCC, 0x00CC99FF, 0x00FFCC99, ++ 0x00111111, 0x00222222, 0x00444444, 0x00555555, 0x00AAAAAA, 0x00BBBBBB, ++ 0x00DDDDDD, 0x00EEEEEE ++}; ++ ++static int generate_default_palette(Palette * palette) ++{ ++ memcpy(palette->colors, default_screen_video_v2_palette, ++ sizeof(default_screen_video_v2_palette)); ++ ++ return update_palette_index(palette); ++} ++ ++static int generate_optimum_palette(Palette * palette, const uint8_t * image, ++ int width, int height, int stride) ++{ ++ //this isn't implemented yet! Default palette only! ++ return -1; ++} ++ ++static inline int encode_15_7_sl(Palette * palette, uint8_t * dest, ++ const uint8_t * src, int width, int dist) ++{ ++ int len = 0, x; ++ for (x = 0; x < width; x++) { ++ len += write_pixel_15_7(palette, dest + len, src + 3 * x, dist); ++ } ++ return len; ++} ++ ++static int encode_15_7(Palette * palette, Block * b, const uint8_t * src, ++ int stride, int dist) ++{ ++ int i; ++ uint8_t *ptr = b->enc; ++ for (i = 0; i < b->start; i++) ++ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist); ++ b->sl_begin = ptr; ++ for (; i < b->start + b->len; i++) ++ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist); ++ b->sl_end = ptr; ++ for (; i < b->height; i++) ++ ptr += encode_15_7_sl(palette, ptr, src + i * stride, b->width, dist); ++ b->enc_size = ptr - b->enc; ++ return b->enc_size; ++} ++ ++static int encode_block(Palette * palette, Block * b, Block * prev, ++ const uint8_t * src, int stride, int comp, int dist, ++ int keyframe) ++{ ++ unsigned buf_size = b->width * b->height * 6; ++ uint8_t buf[buf_size]; ++ int res; ++ if (b->flags & COLORSPACE_15_7) { ++ encode_15_7(palette, b, src, stride, dist); ++ } else { ++ encode_bgr(b, src, stride); ++ } ++ ++ if (b->len > 0) { ++ b->data_size = buf_size; ++ res = encode_zlib(b, b->data, &b->data_size, comp); ++ if (res) ++ return res; ++ ++ if (!keyframe) { ++ res = encode_zlibprime(b, prev, buf, &buf_size, comp); ++ if (res) ++ return res; ++ ++ if (buf_size < b->data_size) { ++ b->data_size = buf_size; ++ memcpy(b->data, buf, buf_size); ++ b->flags |= ZLIB_PRIME_COMPRESS_PREVIOUS; ++ } ++ } ++ } else { ++ b->data_size = 0; ++ } ++ return 0; ++} ++ ++static int compare_sl(FlashSV2Context * s, Block * b, const uint8_t * src, ++ uint8_t * frame, uint8_t * key, int y, int keyframe) ++{ ++ if (memcmp(src, frame, b->width * 3) != 0) { ++ b->dirty = 1; ++ memcpy(frame, src, b->width * 3); ++#ifndef FLASHSV2_DUMB ++ s->diff_lines++; ++#endif ++ } ++ if (memcmp(src, key, b->width * 3) != 0) { ++ if (b->len == 0) ++ b->start = y; ++ b->len = y + 1 - b->start; ++ } ++ return 0; ++} ++ ++static int mark_all_blocks(FlashSV2Context * s, const uint8_t * src, int stride, ++ int keyframe) ++{ ++ int sl, rsl, col, pos, possl; ++ Block *b; ++ for (sl = s->image_height - 1; sl >= 0; sl--) { ++ for (col = 0; col < s->cols; col++) { ++ rsl = s->image_height - sl - 1; ++ b = s->frame_blocks + col + rsl / s->block_height * s->cols; ++ possl = stride * sl + col * s->block_width * 3; ++ pos = s->image_width * rsl * 3 + col * s->block_width * 3; ++ compare_sl(s, b, src + possl, s->current_frame + pos, ++ s->key_frame + pos, rsl % s->block_height, keyframe); ++ } ++ } ++#ifndef FLASHSV2_DUMB ++ s->tot_lines += s->image_height * s->cols; ++#endif ++ return 0; ++} ++ ++static int encode_all_blocks(FlashSV2Context * s, int keyframe) ++{ ++ int row, col, res; ++ uint8_t *data; ++ Block *b, *prev; ++ for (row = 0; row < s->rows; row++) { ++ for (col = 0; col < s->cols; col++) { ++ b = s->frame_blocks + (row * s->cols + col); ++ prev = s->key_blocks + (row * s->cols + col); ++ if (keyframe) { ++ b->start = 0; ++ b->len = b->height; ++ b->flags = s->use15_7 ? COLORSPACE_15_7 : 0; ++ } else if (!b->dirty) { ++ b->start = 0; ++ b->len = 0; ++ b->data_size = 0; ++ b->flags = s->use15_7 ? COLORSPACE_15_7 : 0; ++ continue; ++ } else { ++ b->flags = s->use15_7 ? COLORSPACE_15_7 | HAS_DIFF_BLOCKS : HAS_DIFF_BLOCKS; ++ } ++ data = s->current_frame + s->image_width * 3 * s->block_height * row + s->block_width * col * 3; ++ res = encode_block(&s->palette, b, prev, data, s->image_width * 3, s->comp, s->dist, keyframe); ++#ifndef FLASHSV2_DUMB ++ if (b->dirty) ++ s->diff_blocks++; ++ s->comp_size += b->data_size; ++ s->uncomp_size += b->enc_size; ++#endif ++ if (res) ++ return res; ++ } ++ } ++#ifndef FLASHSV2_DUMB ++ s->raw_size += s->image_width * s->image_height * 3; ++ s->tot_blocks += s->rows * s->cols; ++#endif ++ return 0; ++} ++ ++static int write_all_blocks(FlashSV2Context * s, uint8_t * buf, ++ int buf_size) ++{ ++ int row, col, buf_pos = 0, len; ++ Block *b; ++ for (row = 0; row < s->rows; row++) { ++ for (col = 0; col < s->cols; col++) { ++ b = s->frame_blocks + row * s->cols + col; ++ len = write_block(b, buf + buf_pos, buf_size - buf_pos); ++ b->start = b->len = b->dirty = 0; ++ if (len < 0) ++ return len; ++ buf_pos += len; ++ } ++ } ++ return buf_pos; ++} ++ ++static int write_bitstream(FlashSV2Context * s, const uint8_t * src, int stride, ++ uint8_t * buf, int buf_size, int keyframe) ++{ ++ int buf_pos, res; ++ ++ res = mark_all_blocks(s, src, stride, keyframe); ++ if (res) ++ return res; ++ res = encode_all_blocks(s, keyframe); ++ if (res) ++ return res; ++ ++ res = write_header(s, buf, buf_size); ++ if (res < 0) { ++ return res; ++ } else { ++ buf_pos = res; ++ } ++ res = write_all_blocks(s, buf + buf_pos, buf_size - buf_pos); ++ if (res < 0) ++ return res; ++ buf_pos += res; ++#ifndef FLASHSV2_DUMB ++ s->total_bits += ((double) buf_pos) * 8.0; ++#endif ++ ++ return buf_pos; ++} ++ ++static void recommend_keyframe(FlashSV2Context * s, int *keyframe) ++{ ++#ifndef FLASHSV2_DUMB ++ double block_ratio, line_ratio, enc_ratio, comp_ratio, data_ratio; ++ if (s->avctx->gop_size > 0) { ++ block_ratio = s->diff_blocks / s->tot_blocks; ++ line_ratio = s->diff_lines / s->tot_lines; ++ enc_ratio = s->uncomp_size / s->raw_size; ++ comp_ratio = s->comp_size / s->uncomp_size; ++ data_ratio = s->comp_size / s->raw_size; ++ ++ if ((block_ratio >= 0.5 && line_ratio / block_ratio <= 0.5) || line_ratio >= 0.95) { ++ *keyframe = 1; ++ return; ++ } ++ } ++#else ++ return; ++#endif ++} ++ ++static const double block_size_fraction = 1.0 / 300; ++static int optimum_block_width(FlashSV2Context * s) ++{ ++#ifndef FLASHSV2_DUMB ++ double save = (1-pow(s->diff_lines/s->diff_blocks/s->block_height, 0.5)) * s->comp_size/s->tot_blocks; ++ double width = block_size_fraction * sqrt(0.5 * save * s->rows * s->cols) * s->image_width; ++ int pwidth = ((int) width); ++ return FFCLIP(pwidth & ~15, 256, 16); ++#else ++ return 64; ++#endif ++} ++ ++static int optimum_block_height(FlashSV2Context * s) ++{ ++#ifndef FLASHSV2_DUMB ++ double save = (1-pow(s->diff_lines/s->diff_blocks/s->block_height, 0.5)) * s->comp_size/s->tot_blocks; ++ double height = block_size_fraction * sqrt(0.5 * save * s->rows * s->cols) * s->image_height; ++ int pheight = ((int) height); ++ return FFCLIP(pheight & ~15, 256, 16); ++#else ++ return 64; ++#endif ++} ++ ++static const double use15_7_threshold = 8192; ++ ++static int optimum_use15_7(FlashSV2Context * s) ++{ ++#ifndef FLASHSV2_DUMB ++ double ideal = ((double)(s->avctx->bit_rate * s->avctx->time_base.den * s->avctx->ticks_per_frame)) / ++ ((double) s->avctx->time_base.num) * s->avctx->frame_number; ++ if (ideal + use15_7_threshold < s->total_bits) { ++ return 1; ++ } else { ++ return 0; ++ } ++#else ++ return s->avctx->global_quality == 0; ++#endif ++} ++ ++static const double color15_7_factor = 100; ++ ++static int optimum_dist(FlashSV2Context * s) ++{ ++#ifndef FLASHSV2_DUMB ++ double ideal = ++ s->avctx->bit_rate * s->avctx->time_base.den * ++ s->avctx->ticks_per_frame; ++ int dist = pow((s->total_bits / ideal) * color15_7_factor, 3); ++ av_log(s->avctx, AV_LOG_DEBUG, "dist: %d\n", dist); ++ return dist; ++#else ++ return 15; ++#endif ++} ++ ++ ++static int reconfigure_at_keyframe(FlashSV2Context * s, const uint8_t * image, ++ int stride) ++{ ++ int update_palette = 0; ++ int res; ++ s->block_width = optimum_block_width(s); ++ s->block_height = optimum_block_height(s); ++ ++ s->rows = (s->image_height + s->block_height - 1) / s->block_height; ++ s->cols = (s->image_width + s->block_width - 1) / s->block_width; ++ ++ if (s->rows * s->cols != s->blocks_size / sizeof(Block)) { ++ if (s->rows * s->cols > s->blocks_size / sizeof(Block)) { ++ s->frame_blocks = av_realloc(s->frame_blocks, s->rows * s->cols * sizeof(Block)); ++ s->key_blocks = av_realloc(s->key_blocks, s->cols * s->rows * sizeof(Block)); ++ if (!s->frame_blocks || !s->key_blocks) { ++ av_log(s->avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); ++ return -1; ++ } ++ s->blocks_size = s->rows * s->cols * sizeof(Block); ++ } ++ init_blocks(s, s->frame_blocks, s->encbuffer, s->databuffer); ++ init_blocks(s, s->key_blocks, s->keybuffer, 0); ++ ++ } ++ ++ s->use15_7 = optimum_use15_7(s); ++ if (s->use15_7) { ++ if ((s->use_custom_palette && s->palette_type != 1) || update_palette) { ++ res = generate_optimum_palette(&s->palette, image, s->image_width, s->image_height, stride); ++ if (res) ++ return res; ++ s->palette_type = 1; ++ av_log(s->avctx, AV_LOG_DEBUG, "Generated optimum palette\n"); ++ } else if (!s->use_custom_palette && s->palette_type != 0) { ++ res = generate_default_palette(&s->palette); ++ if (res) ++ return res; ++ s->palette_type = 0; ++ av_log(s->avctx, AV_LOG_DEBUG, "Generated default palette\n"); ++ } ++ } ++ ++ ++ reset_stats(s); ++ ++ return 0; ++} ++ ++static int flashsv2_encode_frame(AVCodecContext * avctx, uint8_t * buf, ++ int buf_size, void *data) ++{ ++ FlashSV2Context *const s = avctx->priv_data; ++ AVFrame *pict = data; ++ AVFrame *const p = &s->frame; ++ int res; ++ int keyframe = 0; ++ ++ *p = *pict; ++ ++ /* First frame needs to be a keyframe */ ++ if (avctx->frame_number == 0) ++ keyframe = 1; ++ ++ /* Check the placement of keyframes */ ++ if (avctx->gop_size > 0) { ++ if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) ++ keyframe = 1; ++ } ++ ++ if (buf_size < s->frame_size) { ++ //Conservative upper bound check for compressed data ++ av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->frame_size); ++ return -1; ++ } ++ ++ if (!keyframe ++ && avctx->frame_number > s->last_key_frame + avctx->keyint_min) { ++ recommend_keyframe(s, &keyframe); ++ if (keyframe) ++ av_log(avctx, AV_LOG_DEBUG, "Recommending key frame at frame %d\n", avctx->frame_number); ++ } ++ ++ if (keyframe) { ++ res = reconfigure_at_keyframe(s, p->data[0], p->linesize[0]); ++ if (res) ++ return res; ++ } ++ ++ if (s->use15_7) ++ s->dist = optimum_dist(s); ++ ++ res = write_bitstream(s, p->data[0], p->linesize[0], buf, buf_size, keyframe); ++ ++ if (keyframe) { ++ new_key_frame(s); ++ p->pict_type = AV_PICTURE_TYPE_I; ++ p->key_frame = 1; ++ s->last_key_frame = avctx->frame_number; ++ av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n", avctx->frame_number); ++ } else { ++ p->pict_type = AV_PICTURE_TYPE_P; ++ p->key_frame = 0; ++ } ++ ++ avctx->coded_frame = p; ++ ++ return res; ++} ++ ++static av_cold int flashsv2_encode_end(AVCodecContext * avctx) ++{ ++ FlashSV2Context *s = avctx->priv_data; ++ ++ cleanup(s); ++ ++ return 0; ++} ++ ++AVCodec ff_flashsv2_encoder = { ++ .name = "flashsv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLASHSV2, ++ .priv_data_size = sizeof(FlashSV2Context), ++ .init = flashsv2_encode_init, ++ .encode = flashsv2_encode_frame, ++ .close = flashsv2_encode_end, ++ .pix_fmts = (enum PixelFormat[]) {PIX_FMT_BGR24, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video Version 2"), ++ .capabilities = CODEC_CAP_EXPERIMENTAL, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsv.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsv.c 2012-05-14 14:08:53.722327664 +0200 +@@ -25,88 +25,213 @@ + * Flash Screen Video decoder + * @author Alex Beregszaszi + * @author Benjamin Larsson +- */ +- +-/* Bitstream description +- * The picture is divided into blocks that are zlib compressed. +- * +- * The decoder is fed complete frames, the frameheader contains: +- * 4bits of block width +- * 12bits of frame width +- * 4bits of block height +- * 12bits of frame height ++ * @author Daniel Verkamp ++ * @author Konstantin Shishkov + * +- * Directly after the header are the compressed blocks. The blocks +- * have their compressed size represented with 16bits in the beginnig. +- * If the size = 0 then the block is unchanged from the previous frame. +- * All blocks are decompressed until the buffer is consumed. +- * +- * Encoding ideas, a basic encoder would just use a fixed block size. +- * Block sizes can be multipels of 16, from 16 to 256. The blocks don't +- * have to be quadratic. A brute force search with a set of diffrent +- * block sizes should give a better result then to just use a fixed size. ++ * A description of the bitstream format for Flash Screen Video version 1/2 ++ * is part of the SWF File Format Specification (version 10), which can be ++ * downloaded from http://www.adobe.com/devnet/swf.html. + */ + + #include + #include ++#include + ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "bytestream.h" + #include "get_bits.h" + +-#include ++typedef struct BlockInfo { ++ uint8_t *pos; ++ int size; ++ int unp_size; ++} BlockInfo; + + typedef struct FlashSVContext { + AVCodecContext *avctx; +- AVFrame frame; +- int image_width, image_height; +- int block_width, block_height; +- uint8_t* tmpblock; +- int block_size; +- z_stream zstream; ++ AVFrame frame; ++ int image_width, image_height; ++ int block_width, block_height; ++ uint8_t *tmpblock; ++ int block_size; ++ z_stream zstream; ++ int ver; ++ const uint32_t *pal; ++ int is_keyframe; ++ uint8_t *keyframedata; ++ uint8_t *keyframe; ++ BlockInfo *blocks; ++ uint8_t *deflate_block; ++ int deflate_block_size; ++ int color_depth; ++ int zlibprime_curr, zlibprime_prev; ++ int diff_start, diff_height; + } FlashSVContext; + + +-static void copy_region(uint8_t *sptr, uint8_t *dptr, +- int dx, int dy, int h, int w, int stride) ++static int decode_hybrid(const uint8_t *sptr, uint8_t *dptr, int dx, int dy, ++ int h, int w, int stride, const uint32_t *pal) + { +- int i; ++ int x, y; ++ const uint8_t *orig_src = sptr; + +- for (i = dx+h; i > dx; i--) +- { +- memcpy(dptr+(i*stride)+dy*3, sptr, w*3); +- sptr += w*3; ++ for (y = dx+h; y > dx; y--) { ++ uint8_t *dst = dptr + (y * stride) + dy * 3; ++ for (x = 0; x < w; x++) { ++ if (*sptr & 0x80) { ++ /* 15-bit color */ ++ unsigned c = AV_RB16(sptr) & ~0x8000; ++ unsigned b = c & 0x1F; ++ unsigned g = (c >> 5) & 0x1F; ++ unsigned r = c >> 10; ++ /* 000aaabb -> aaabbaaa */ ++ *dst++ = (b << 3) | (b >> 2); ++ *dst++ = (g << 3) | (g >> 2); ++ *dst++ = (r << 3) | (r >> 2); ++ sptr += 2; ++ } else { ++ /* palette index */ ++ uint32_t c = pal[*sptr++]; ++ bytestream_put_le24(&dst, c); ++ } ++ } + } ++ return sptr - orig_src; + } + +- + static av_cold int flashsv_decode_init(AVCodecContext *avctx) + { + FlashSVContext *s = avctx->priv_data; + int zret; // Zlib return code + +- s->avctx = avctx; ++ s->avctx = avctx; + s->zstream.zalloc = Z_NULL; +- s->zstream.zfree = Z_NULL; ++ s->zstream.zfree = Z_NULL; + s->zstream.opaque = Z_NULL; +- zret = inflateInit(&(s->zstream)); ++ zret = inflateInit(&s->zstream); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return 1; + } + avctx->pix_fmt = PIX_FMT_BGR24; ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; + } + + +-static int flashsv_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static void flashsv2_prime(FlashSVContext *s, uint8_t *src, ++ int size, int unp_size) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- FlashSVContext *s = avctx->priv_data; ++ z_stream zs; ++ ++ zs.zalloc = NULL; ++ zs.zfree = NULL; ++ zs.opaque = NULL; ++ ++ s->zstream.next_in = src; ++ s->zstream.avail_in = size; ++ s->zstream.next_out = s->tmpblock; ++ s->zstream.avail_out = s->block_size * 3; ++ inflate(&s->zstream, Z_SYNC_FLUSH); ++ ++ deflateInit(&zs, 0); ++ zs.next_in = s->tmpblock; ++ zs.avail_in = s->block_size * 3 - s->zstream.avail_out; ++ zs.next_out = s->deflate_block; ++ zs.avail_out = s->deflate_block_size; ++ deflate(&zs, Z_SYNC_FLUSH); ++ deflateEnd(&zs); ++ ++ inflateReset(&s->zstream); ++ ++ s->zstream.next_in = s->deflate_block; ++ s->zstream.avail_in = s->deflate_block_size - zs.avail_out; ++ s->zstream.next_out = s->tmpblock; ++ s->zstream.avail_out = s->block_size * 3; ++ inflate(&s->zstream, Z_SYNC_FLUSH); ++} ++ ++static int flashsv_decode_block(AVCodecContext *avctx, AVPacket *avpkt, ++ GetBitContext *gb, int block_size, ++ int width, int height, int x_pos, int y_pos, ++ int blk_idx) ++{ ++ struct FlashSVContext *s = avctx->priv_data; ++ uint8_t *line = s->tmpblock; ++ int k; ++ int ret = inflateReset(&s->zstream); ++ if (ret != Z_OK) { ++ //return -1; ++ } ++ if (s->zlibprime_curr || s->zlibprime_prev) { ++ flashsv2_prime(s, s->blocks[blk_idx].pos, s->blocks[blk_idx].size, ++ s->blocks[blk_idx].unp_size); ++ } ++ s->zstream.next_in = avpkt->data + get_bits_count(gb) / 8; ++ s->zstream.avail_in = block_size; ++ s->zstream.next_out = s->tmpblock; ++ s->zstream.avail_out = s->block_size * 3; ++ ret = inflate(&s->zstream, Z_FINISH); ++ if (ret == Z_DATA_ERROR) { ++ av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n"); ++ inflateSync(&s->zstream); ++ ret = inflate(&s->zstream, Z_FINISH); ++ } ++ ++ if (ret != Z_OK && ret != Z_STREAM_END) { ++ //return -1; ++ } ++ ++ if (s->is_keyframe) { ++ s->blocks[blk_idx].pos = s->keyframedata + (get_bits_count(gb) / 8); ++ s->blocks[blk_idx].size = block_size; ++ s->blocks[blk_idx].unp_size = s->block_size * 3 - s->zstream.avail_out; ++ } ++ if (!s->color_depth) { ++ /* Flash Screen Video stores the image upside down, so copy ++ * lines to destination in reverse order. */ ++ for (k = 1; k <= s->diff_height; k++) { ++ memcpy(s->frame.data[0] + x_pos * 3 + ++ (s->image_height - y_pos - s->diff_start - k) * s->frame.linesize[0], ++ line, width * 3); ++ /* advance source pointer to next line */ ++ line += width * 3; ++ } ++ } else { ++ /* hybrid 15-bit/palette mode */ ++ decode_hybrid(s->tmpblock, s->frame.data[0], ++ s->image_height - (y_pos + 1 + s->diff_start + s->diff_height), ++ x_pos, s->diff_height, width, ++ s->frame.linesize[0], s->pal); ++ } ++ skip_bits_long(gb, 8 * block_size); /* skip the consumed bits */ ++ return 0; ++} ++ ++static int calc_deflate_block_size(int tmpblock_size) ++{ ++ z_stream zstream; ++ int size; ++ ++ zstream.zalloc = Z_NULL; ++ zstream.zfree = Z_NULL; ++ zstream.opaque = Z_NULL; ++ if (deflateInit(&zstream, 0) != Z_OK) ++ return -1; ++ size = deflateBound(&zstream, tmpblock_size); ++ deflateEnd(&zstream); ++ ++ return size; ++} ++ ++static int flashsv_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ int buf_size = avpkt->size; ++ FlashSVContext *s = avctx->priv_data; + int h_blocks, v_blocks, h_part, v_part, i, j; + GetBitContext gb; + +@@ -116,118 +241,196 @@ + if (buf_size < 4) + return -1; + +- init_get_bits(&gb, buf, buf_size * 8); ++ init_get_bits(&gb, avpkt->data, buf_size * 8); + + /* start to parse the bitstream */ +- s->block_width = 16* (get_bits(&gb, 4)+1); +- s->image_width = get_bits(&gb,12); +- s->block_height= 16* (get_bits(&gb, 4)+1); +- s->image_height= get_bits(&gb,12); +- +- /* calculate amount of blocks and the size of the border blocks */ +- h_blocks = s->image_width / s->block_width; +- h_part = s->image_width % s->block_width; ++ s->block_width = 16 * (get_bits(&gb, 4) + 1); ++ s->image_width = get_bits(&gb, 12); ++ s->block_height = 16 * (get_bits(&gb, 4) + 1); ++ s->image_height = get_bits(&gb, 12); ++ ++ if (s->ver == 2) { ++ skip_bits(&gb, 6); ++ if (get_bits1(&gb)) { ++ av_log_missing_feature(avctx, "iframe", 1); ++ return AVERROR_PATCHWELCOME; ++ } ++ if (get_bits1(&gb)) { ++ av_log_missing_feature(avctx, "custom palette", 1); ++ return AVERROR_PATCHWELCOME; ++ } ++ } ++ ++ /* calculate number of blocks and size of border (partial) blocks */ ++ h_blocks = s->image_width / s->block_width; ++ h_part = s->image_width % s->block_width; + v_blocks = s->image_height / s->block_height; +- v_part = s->image_height % s->block_height; ++ v_part = s->image_height % s->block_height; + + /* the block size could change between frames, make sure the buffer + * is large enough, if not, get a larger one */ +- if(s->block_size < s->block_width*s->block_height) { +- if (s->tmpblock != NULL) +- av_free(s->tmpblock); +- if ((s->tmpblock = av_malloc(3*s->block_width*s->block_height)) == NULL) { ++ if (s->block_size < s->block_width * s->block_height) { ++ int tmpblock_size = 3 * s->block_width * s->block_height; ++ ++ s->tmpblock = av_realloc(s->tmpblock, tmpblock_size); ++ if (!s->tmpblock) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); +- return -1; ++ return AVERROR(ENOMEM); ++ } ++ if (s->ver == 2) { ++ s->deflate_block_size = calc_deflate_block_size(tmpblock_size); ++ if (s->deflate_block_size <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "Can't determine deflate buffer size.\n"); ++ return -1; ++ } ++ s->deflate_block = av_realloc(s->deflate_block, s->deflate_block_size); ++ if (!s->deflate_block) { ++ av_log(avctx, AV_LOG_ERROR, "Can't allocate deflate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } + } + } +- s->block_size = s->block_width*s->block_height; ++ s->block_size = s->block_width * s->block_height; + +- /* init the image size once */ +- if((avctx->width==0) && (avctx->height==0)){ +- avctx->width = s->image_width; ++ /* initialize the image size once */ ++ if (avctx->width == 0 && avctx->height == 0) { ++ avctx->width = s->image_width; + avctx->height = s->image_height; + } + + /* check for changes of image width and image height */ +- if ((avctx->width != s->image_width) || (avctx->height != s->image_height)) { +- av_log(avctx, AV_LOG_ERROR, "Frame width or height differs from first frames!\n"); +- av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n",avctx->height, +- avctx->width,s->image_height,s->image_width); +- return -1; ++ if (avctx->width != s->image_width || avctx->height != s->image_height) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Frame width or height differs from first frame!\n"); ++ av_log(avctx, AV_LOG_ERROR, "fh = %d, fv %d vs ch = %d, cv = %d\n", ++ avctx->height, avctx->width, s->image_height, s->image_width); ++ return AVERROR_INVALIDDATA; + } + +- av_log(avctx, AV_LOG_DEBUG, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n", +- s->image_width, s->image_height, s->block_width, s->block_height, +- h_blocks, v_blocks, h_part, v_part); +- +- s->frame.reference = 1; +- s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; +- if(avctx->reget_buffer(avctx, &s->frame) < 0){ +- av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +- return -1; ++ /* we care for keyframes only in Screen Video v2 */ ++ s->is_keyframe = (avpkt->flags & AV_PKT_FLAG_KEY) && (s->ver == 2); ++ if (s->is_keyframe) { ++ s->keyframedata = av_realloc(s->keyframedata, avpkt->size); ++ memcpy(s->keyframedata, avpkt->data, avpkt->size); ++ s->blocks = av_realloc(s->blocks, ++ (v_blocks + !!v_part) * (h_blocks + !!h_part) ++ * sizeof(s->blocks[0])); + } + +- /* loop over all block columns */ +- for (j = 0; j < v_blocks + (v_part?1:0); j++) +- { ++ av_dlog(avctx, "image: %dx%d block: %dx%d num: %dx%d part: %dx%d\n", ++ s->image_width, s->image_height, s->block_width, s->block_height, ++ h_blocks, v_blocks, h_part, v_part); ++ ++ s->frame.reference = 3; ++ s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | ++ FF_BUFFER_HINTS_PRESERVE | ++ FF_BUFFER_HINTS_REUSABLE; ++ if (avctx->reget_buffer(avctx, &s->frame) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); ++ return -1; ++ } + +- int hp = j*s->block_height; // horiz position in frame +- int hs = (jblock_height:v_part; // size of block ++ /* loop over all block columns */ ++ for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) { + ++ int y_pos = j * s->block_height; // vertical position in frame ++ int cur_blk_height = (j < v_blocks) ? s->block_height : v_part; + + /* loop over all block rows */ +- for (i = 0; i < h_blocks + (h_part?1:0); i++) +- { +- int wp = i*s->block_width; // vert position in frame +- int ws = (iblock_width:h_part; // size of block ++ for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) { ++ int x_pos = i * s->block_width; // horizontal position in frame ++ int cur_blk_width = (i < h_blocks) ? s->block_width : h_part; ++ int has_diff = 0; + + /* get the size of the compressed zlib chunk */ + int size = get_bits(&gb, 16); ++ ++ s->color_depth = 0; ++ s->zlibprime_curr = 0; ++ s->zlibprime_prev = 0; ++ s->diff_start = 0; ++ s->diff_height = cur_blk_height; ++ + if (8 * size > get_bits_left(&gb)) { + avctx->release_buffer(avctx, &s->frame); + s->frame.data[0] = NULL; +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (size == 0) { +- /* no change, don't do anything */ +- } else { +- /* decompress block */ +- int ret = inflateReset(&(s->zstream)); +- if (ret != Z_OK) +- { +- av_log(avctx, AV_LOG_ERROR, "error in decompression (reset) of block %dx%d\n", i, j); +- /* return -1; */ ++ if (s->ver == 2 && size) { ++ skip_bits(&gb, 3); ++ s->color_depth = get_bits(&gb, 2); ++ has_diff = get_bits1(&gb); ++ s->zlibprime_curr = get_bits1(&gb); ++ s->zlibprime_prev = get_bits1(&gb); ++ ++ if (s->color_depth != 0 && s->color_depth != 2) { ++ av_log(avctx, AV_LOG_ERROR, ++ "%dx%d invalid color depth %d\n", i, j, s->color_depth); ++ return AVERROR_INVALIDDATA; + } +- s->zstream.next_in = buf+(get_bits_count(&gb)/8); +- s->zstream.avail_in = size; +- s->zstream.next_out = s->tmpblock; +- s->zstream.avail_out = s->block_size*3; +- ret = inflate(&(s->zstream), Z_FINISH); +- if (ret == Z_DATA_ERROR) +- { +- av_log(avctx, AV_LOG_ERROR, "Zlib resync occurred\n"); +- inflateSync(&(s->zstream)); +- ret = inflate(&(s->zstream), Z_FINISH); ++ ++ if (has_diff) { ++ s->diff_start = get_bits(&gb, 8); ++ s->diff_height = get_bits(&gb, 8); ++ av_log(avctx, AV_LOG_DEBUG, ++ "%dx%d diff start %d height %d\n", ++ i, j, s->diff_start, s->diff_height); ++ size -= 2; + } + +- if ((ret != Z_OK) && (ret != Z_STREAM_END)) +- { +- av_log(avctx, AV_LOG_ERROR, "error in decompression of block %dx%d: %d\n", i, j, ret); +- /* return -1; */ ++ if (s->zlibprime_prev) ++ av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_prev\n", i, j); ++ ++ if (s->zlibprime_curr) { ++ int col = get_bits(&gb, 8); ++ int row = get_bits(&gb, 8); ++ av_log(avctx, AV_LOG_DEBUG, "%dx%d zlibprime_curr %dx%d\n", i, j, col, row); ++ size -= 2; ++ av_log_missing_feature(avctx, "zlibprime_curr", 1); ++ return AVERROR_PATCHWELCOME; + } +- copy_region(s->tmpblock, s->frame.data[0], s->image_height-(hp+hs+1), wp, hs, ws, s->frame.linesize[0]); +- skip_bits_long(&gb, 8*size); /* skip the consumed bits */ ++ size--; // account for flags byte ++ } ++ ++ if (has_diff) { ++ int k; ++ int off = (s->image_height - y_pos - 1) * s->frame.linesize[0]; ++ ++ for (k = 0; k < cur_blk_height; k++) ++ memcpy(s->frame.data[0] + off - k*s->frame.linesize[0] + x_pos*3, ++ s->keyframe + off - k*s->frame.linesize[0] + x_pos*3, ++ cur_blk_width * 3); ++ } ++ ++ /* skip unchanged blocks, which have size 0 */ ++ if (size) { ++ if (flashsv_decode_block(avctx, avpkt, &gb, size, ++ cur_blk_width, cur_blk_height, ++ x_pos, y_pos, ++ i + j * (h_blocks + !!h_part))) ++ av_log(avctx, AV_LOG_ERROR, ++ "error in decompression of block %dx%d\n", i, j); + } + } + } ++ if (s->is_keyframe && s->ver == 2) { ++ if (!s->keyframe) { ++ s->keyframe = av_malloc(s->frame.linesize[0] * avctx->height); ++ if (!s->keyframe) { ++ av_log(avctx, AV_LOG_ERROR, "Cannot allocate image data\n"); ++ return AVERROR(ENOMEM); ++ } ++ } ++ memcpy(s->keyframe, s->frame.data[0], s->frame.linesize[0] * avctx->height); ++ } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; + +- if ((get_bits_count(&gb)/8) != buf_size) ++ if ((get_bits_count(&gb) / 8) != buf_size) + av_log(avctx, AV_LOG_ERROR, "buffer not fully consumed (%d != %d)\n", +- buf_size, (get_bits_count(&gb)/8)); ++ buf_size, (get_bits_count(&gb) / 8)); + + /* report that the buffer was completely consumed */ + return buf_size; +@@ -237,29 +440,92 @@ + static av_cold int flashsv_decode_end(AVCodecContext *avctx) + { + FlashSVContext *s = avctx->priv_data; +- inflateEnd(&(s->zstream)); ++ inflateEnd(&s->zstream); + /* release the frame if needed */ + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + + /* free the tmpblock */ +- if (s->tmpblock != NULL) +- av_free(s->tmpblock); ++ av_free(s->tmpblock); + + return 0; + } + + ++#if CONFIG_FLASHSV_DECODER + AVCodec ff_flashsv_decoder = { +- "flashsv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FLASHSV, +- sizeof(FlashSVContext), +- flashsv_decode_init, +- NULL, +- flashsv_decode_end, +- flashsv_decode_frame, +- CODEC_CAP_DR1, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"), ++ .name = "flashsv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLASHSV, ++ .priv_data_size = sizeof(FlashSVContext), ++ .init = flashsv_decode_init, ++ .close = flashsv_decode_end, ++ .decode = flashsv_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v1"), ++}; ++#endif /* CONFIG_FLASHSV_DECODER */ ++ ++#if CONFIG_FLASHSV2_DECODER ++static const uint32_t ff_flashsv2_default_palette[128] = { ++ 0x000000, 0x333333, 0x666666, 0x999999, 0xCCCCCC, 0xFFFFFF, ++ 0x330000, 0x660000, 0x990000, 0xCC0000, 0xFF0000, 0x003300, ++ 0x006600, 0x009900, 0x00CC00, 0x00FF00, 0x000033, 0x000066, ++ 0x000099, 0x0000CC, 0x0000FF, 0x333300, 0x666600, 0x999900, ++ 0xCCCC00, 0xFFFF00, 0x003333, 0x006666, 0x009999, 0x00CCCC, ++ 0x00FFFF, 0x330033, 0x660066, 0x990099, 0xCC00CC, 0xFF00FF, ++ 0xFFFF33, 0xFFFF66, 0xFFFF99, 0xFFFFCC, 0xFF33FF, 0xFF66FF, ++ 0xFF99FF, 0xFFCCFF, 0x33FFFF, 0x66FFFF, 0x99FFFF, 0xCCFFFF, ++ 0xCCCC33, 0xCCCC66, 0xCCCC99, 0xCCCCFF, 0xCC33CC, 0xCC66CC, ++ 0xCC99CC, 0xCCFFCC, 0x33CCCC, 0x66CCCC, 0x99CCCC, 0xFFCCCC, ++ 0x999933, 0x999966, 0x9999CC, 0x9999FF, 0x993399, 0x996699, ++ 0x99CC99, 0x99FF99, 0x339999, 0x669999, 0xCC9999, 0xFF9999, ++ 0x666633, 0x666699, 0x6666CC, 0x6666FF, 0x663366, 0x669966, ++ 0x66CC66, 0x66FF66, 0x336666, 0x996666, 0xCC6666, 0xFF6666, ++ 0x333366, 0x333399, 0x3333CC, 0x3333FF, 0x336633, 0x339933, ++ 0x33CC33, 0x33FF33, 0x663333, 0x993333, 0xCC3333, 0xFF3333, ++ 0x003366, 0x336600, 0x660033, 0x006633, 0x330066, 0x663300, ++ 0x336699, 0x669933, 0x993366, 0x339966, 0x663399, 0x996633, ++ 0x6699CC, 0x99CC66, 0xCC6699, 0x66CC99, 0x9966CC, 0xCC9966, ++ 0x99CCFF, 0xCCFF99, 0xFF99CC, 0x99FFCC, 0xCC99FF, 0xFFCC99, ++ 0x111111, 0x222222, 0x444444, 0x555555, 0xAAAAAA, 0xBBBBBB, ++ 0xDDDDDD, 0xEEEEEE ++}; ++ ++static av_cold int flashsv2_decode_init(AVCodecContext *avctx) ++{ ++ FlashSVContext *s = avctx->priv_data; ++ flashsv_decode_init(avctx); ++ s->pal = ff_flashsv2_default_palette; ++ s->ver = 2; ++ ++ return 0; ++} ++ ++static av_cold int flashsv2_decode_end(AVCodecContext *avctx) ++{ ++ FlashSVContext *s = avctx->priv_data; ++ ++ av_freep(&s->keyframedata); ++ av_freep(&s->blocks); ++ av_freep(&s->keyframe); ++ av_freep(&s->deflate_block); ++ flashsv_decode_end(avctx); ++ ++ return 0; ++} ++ ++AVCodec ff_flashsv2_decoder = { ++ .name = "flashsv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLASHSV2, ++ .priv_data_size = sizeof(FlashSVContext), ++ .init = flashsv2_decode_init, ++ .close = flashsv2_decode_end, ++ .decode = flashsv_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video v2"), + }; ++#endif /* CONFIG_FLASHSV2_DECODER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flashsvenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flashsvenc.c 2012-05-14 14:08:53.726327745 +0200 +@@ -27,31 +27,21 @@ + * Flash Screen Video encoder + * @author Alex Beregszaszi + * @author Benjamin Larsson ++ * ++ * A description of the bitstream format for Flash Screen Video version 1/2 ++ * is part of the SWF File Format Specification (version 10), which can be ++ * downloaded from http://www.adobe.com/devnet/swf.html. + */ + +-/* Bitstream description +- * The picture is divided into blocks that are zlib-compressed. +- * +- * The decoder is fed complete frames, the frameheader contains: +- * 4bits of block width +- * 12bits of frame width +- * 4bits of block height +- * 12bits of frame height +- * +- * Directly after the header are the compressed blocks. The blocks +- * have their compressed size represented with 16bits in the beginig. +- * If the size = 0 then the block is unchanged from the previous frame. +- * All blocks are decompressed until the buffer is consumed. +- * +- * Encoding ideas, a basic encoder would just use a fixed block size. +- * Block sizes can be multipels of 16, from 16 to 256. The blocks don't ++/* ++ * Encoding ideas: A basic encoder would just use a fixed block size. ++ * Block sizes can be multiples of 16, from 16 to 256. The blocks don't + * have to be quadratic. A brute force search with a set of different + * block sizes should give a better result than to just use a fixed size. +- */ +- +-/* TODO: +- * Don't reencode the frame in brute force mode if the frame is a dupe. Speed up. +- * Make the difference check faster. ++ * ++ * TODO: ++ * Don't reencode the frame in brute force mode if the frame is a dupe. ++ * Speed up. Make the difference check faster. + */ + + #include +@@ -65,32 +55,33 @@ + + typedef struct FlashSVContext { + AVCodecContext *avctx; +- uint8_t *previous_frame; +- AVFrame frame; +- int image_width, image_height; +- int block_width, block_height; +- uint8_t* tmpblock; +- uint8_t* encbuffer; +- int block_size; +- z_stream zstream; +- int last_key_frame; ++ uint8_t *previous_frame; ++ AVFrame frame; ++ int image_width, image_height; ++ int block_width, block_height; ++ uint8_t *tmpblock; ++ uint8_t *encbuffer; ++ int block_size; ++ z_stream zstream; ++ int last_key_frame; + } FlashSVContext; + +-static int copy_region_enc(uint8_t *sptr, uint8_t *dptr, +- int dx, int dy, int h, int w, int stride, uint8_t *pfptr) { +- int i,j; ++static int copy_region_enc(uint8_t *sptr, uint8_t *dptr, int dx, int dy, ++ int h, int w, int stride, uint8_t *pfptr) ++{ ++ int i, j; + uint8_t *nsptr; + uint8_t *npfptr; + int diff = 0; + +- for (i = dx+h; i > dx; i--) { +- nsptr = sptr+(i*stride)+dy*3; +- npfptr = pfptr+(i*stride)+dy*3; +- for (j=0 ; j dx; i--) { ++ nsptr = sptr + i * stride + dy * 3; ++ npfptr = pfptr + i * stride + dy * 3; ++ for (j = 0; j < w * 3; j++) { ++ diff |= npfptr[j] ^ nsptr[j]; ++ dptr[j] = nsptr[j]; + } +- dptr += w*3; ++ dptr += w * 3; + } + if (diff) + return 1; +@@ -103,89 +94,92 @@ + + s->avctx = avctx; + +- if ((avctx->width > 4095) || (avctx->height > 4095)) { +- av_log(avctx, AV_LOG_ERROR, "Input dimensions too large, input must be max 4096x4096 !\n"); +- return -1; ++ if (avctx->width > 4095 || avctx->height > 4095) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Input dimensions too large, input must be max 4096x4096 !\n"); ++ return AVERROR_INVALIDDATA; + } + + // Needed if zlib unused or init aborted before deflateInit +- memset(&(s->zstream), 0, sizeof(z_stream)); ++ memset(&s->zstream, 0, sizeof(z_stream)); + +- s->last_key_frame=0; ++ s->last_key_frame = 0; + +- s->image_width = avctx->width; ++ s->image_width = avctx->width; + s->image_height = avctx->height; + +- s->tmpblock = av_mallocz(3*256*256); +- s->encbuffer = av_mallocz(s->image_width*s->image_height*3); ++ s->tmpblock = av_mallocz(3 * 256 * 256); ++ s->encbuffer = av_mallocz(s->image_width * s->image_height * 3); + + if (!s->tmpblock || !s->encbuffer) { + av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); +- return -1; ++ return AVERROR(ENOMEM); + } + + return 0; + } + + +-static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, int buf_size, +- int block_width, int block_height, uint8_t *previous_frame, int* I_frame) { ++static int encode_bitstream(FlashSVContext *s, AVFrame *p, uint8_t *buf, ++ int buf_size, int block_width, int block_height, ++ uint8_t *previous_frame, int *I_frame) ++{ + + PutBitContext pb; + int h_blocks, v_blocks, h_part, v_part, i, j; + int buf_pos, res; + int pred_blocks = 0; + +- init_put_bits(&pb, buf, buf_size*8); ++ init_put_bits(&pb, buf, buf_size * 8); + +- put_bits(&pb, 4, (block_width/16)-1); ++ put_bits(&pb, 4, block_width / 16 - 1); + put_bits(&pb, 12, s->image_width); +- put_bits(&pb, 4, (block_height/16)-1); ++ put_bits(&pb, 4, block_height / 16 - 1); + put_bits(&pb, 12, s->image_height); + flush_put_bits(&pb); +- buf_pos=4; ++ buf_pos = 4; + +- h_blocks = s->image_width / block_width; +- h_part = s->image_width % block_width; ++ h_blocks = s->image_width / block_width; ++ h_part = s->image_width % block_width; + v_blocks = s->image_height / block_height; +- v_part = s->image_height % block_height; ++ v_part = s->image_height % block_height; + + /* loop over all block columns */ +- for (j = 0; j < v_blocks + (v_part?1:0); j++) +- { ++ for (j = 0; j < v_blocks + (v_part ? 1 : 0); j++) { + +- int hp = j*block_height; // horiz position in frame +- int hs = (jdata[0], s->tmpblock, s->image_height-(hp+hs+1), wp, hs, ws, p->linesize[0], previous_frame); ++ for (i = 0; i < h_blocks + (h_part ? 1 : 0); i++) { ++ int x_pos = i * block_width; // horizontal position in frame ++ int cur_blk_width = (i < h_blocks) ? block_width : h_part; ++ int ret = Z_OK; ++ uint8_t *ptr = buf + buf_pos; ++ ++ /* copy the block to the temp buffer before compression ++ * (if it differs from the previous frame's block) */ ++ res = copy_region_enc(p->data[0], s->tmpblock, ++ s->image_height - (y_pos + cur_blk_height + 1), ++ x_pos, cur_blk_height, cur_blk_width, ++ p->linesize[0], previous_frame); + + if (res || *I_frame) { +- unsigned long zsize; +- zsize = 3*block_width*block_height; +- ret = compress2(ptr+2, &zsize, s->tmpblock, 3*ws*hs, 9); ++ unsigned long zsize = 3 * block_width * block_height; ++ ret = compress2(ptr + 2, &zsize, s->tmpblock, ++ 3 * cur_blk_width * cur_blk_height, 9); + +- +- //ret = deflateReset(&(s->zstream)); ++ //ret = deflateReset(&s->zstream); + if (ret != Z_OK) +- av_log(s->avctx, AV_LOG_ERROR, "error while compressing block %dx%d\n", i, j); ++ av_log(s->avctx, AV_LOG_ERROR, ++ "error while compressing block %dx%d\n", i, j); + +- bytestream_put_be16(&ptr,(unsigned int)zsize); +- buf_pos += zsize+2; +- //av_log(avctx, AV_LOG_ERROR, "buf_pos = %d\n", buf_pos); ++ bytestream_put_be16(&ptr, zsize); ++ buf_pos += zsize + 2; ++ av_dlog(s->avctx, "buf_pos = %d\n", buf_pos); + } else { + pred_blocks++; +- bytestream_put_be16(&ptr,0); ++ bytestream_put_be16(&ptr, 0); + buf_pos += 2; + } + } +@@ -200,7 +194,8 @@ + } + + +-static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) ++static int flashsv_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) + { + FlashSVContext * const s = avctx->priv_data; + AVFrame *pict = data; +@@ -208,57 +203,57 @@ + uint8_t *pfptr; + int res; + int I_frame = 0; +- int opt_w, opt_h; ++ int opt_w = 4, opt_h = 4; + + *p = *pict; + + /* First frame needs to be a keyframe */ + if (avctx->frame_number == 0) { +- s->previous_frame = av_mallocz(FFABS(p->linesize[0])*s->image_height); ++ s->previous_frame = av_mallocz(FFABS(p->linesize[0]) * s->image_height); + if (!s->previous_frame) { + av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); +- return -1; ++ return AVERROR(ENOMEM); + } + I_frame = 1; + } + + if (p->linesize[0] < 0) +- pfptr = s->previous_frame - ((s->image_height-1) * p->linesize[0]); ++ pfptr = s->previous_frame - (s->image_height - 1) * p->linesize[0]; + else + pfptr = s->previous_frame; + + /* Check the placement of keyframes */ +- if (avctx->gop_size > 0) { +- if (avctx->frame_number >= s->last_key_frame + avctx->gop_size) { +- I_frame = 1; +- } ++ if (avctx->gop_size > 0 && ++ avctx->frame_number >= s->last_key_frame + avctx->gop_size) { ++ I_frame = 1; + } + +- opt_w=4; +- opt_h=4; +- +- if (buf_size < s->image_width*s->image_height*3) { ++ if (buf_size < s->image_width * s->image_height * 3) { + //Conservative upper bound check for compressed data +- av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", buf_size, s->image_width*s->image_height*3); ++ av_log(avctx, AV_LOG_ERROR, "buf_size %d < %d\n", ++ buf_size, s->image_width * s->image_height * 3); + return -1; + } + +- res = encode_bitstream(s, p, buf, buf_size, opt_w*16, opt_h*16, pfptr, &I_frame); ++ res = encode_bitstream(s, p, buf, buf_size, opt_w * 16, opt_h * 16, ++ pfptr, &I_frame); + + //save the current frame +- if(p->linesize[0] > 0) +- memcpy(s->previous_frame, p->data[0], s->image_height*p->linesize[0]); ++ if (p->linesize[0] > 0) ++ memcpy(s->previous_frame, p->data[0], s->image_height * p->linesize[0]); + else +- memcpy(s->previous_frame, p->data[0] + p->linesize[0] * (s->image_height-1), s->image_height*FFABS(p->linesize[0])); ++ memcpy(s->previous_frame, ++ p->data[0] + p->linesize[0] * (s->image_height - 1), ++ s->image_height * FFABS(p->linesize[0])); + + //mark the frame type so the muxer can mux it correctly + if (I_frame) { +- p->pict_type = FF_I_TYPE; +- p->key_frame = 1; ++ p->pict_type = AV_PICTURE_TYPE_I; ++ p->key_frame = 1; + s->last_key_frame = avctx->frame_number; +- av_log(avctx, AV_LOG_DEBUG, "Inserting key frame at frame %d\n",avctx->frame_number); ++ av_dlog(avctx, "Inserting keyframe at frame %d\n", avctx->frame_number); + } else { +- p->pict_type = FF_P_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_P; + p->key_frame = 0; + } + +@@ -271,7 +266,7 @@ + { + FlashSVContext *s = avctx->priv_data; + +- deflateEnd(&(s->zstream)); ++ deflateEnd(&s->zstream); + + av_free(s->encbuffer); + av_free(s->previous_frame); +@@ -281,14 +276,14 @@ + } + + AVCodec ff_flashsv_encoder = { +- "flashsv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FLASHSV, +- sizeof(FlashSVContext), +- flashsv_encode_init, +- flashsv_encode_frame, +- flashsv_encode_end, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video"), ++ .name = "flashsv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLASHSV, ++ .priv_data_size = sizeof(FlashSVContext), ++ .init = flashsv_encode_init, ++ .encode = flashsv_encode_frame, ++ .close = flashsv_encode_end, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Flash Screen Video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flicvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flicvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flicvideo.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flicvideo.c 2012-05-14 14:08:53.729327805 +0200 +@@ -41,6 +41,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "bytestream.h" ++#include "mathops.h" + + #define FLI_256_COLOR 4 + #define FLI_DELTA 7 +@@ -61,9 +63,9 @@ + + #define CHECK_PIXEL_PTR(n) \ + if (pixel_ptr + n > pixel_limit) { \ +- av_log (s->avctx, AV_LOG_INFO, "Problem: pixel_ptr >= pixel_limit (%d >= %d)\n", \ ++ av_log (s->avctx, AV_LOG_ERROR, "Invalid pixel_ptr = %d > pixel_limit = %d\n", \ + pixel_ptr + n, pixel_limit); \ +- return -1; \ ++ return AVERROR_INVALIDDATA; \ + } \ + + typedef struct FlicDecodeContext { +@@ -81,6 +83,12 @@ + unsigned char *fli_header = (unsigned char *)avctx->extradata; + int depth; + ++ if (avctx->extradata_size != 12 && ++ avctx->extradata_size != 128) { ++ av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ + s->avctx = avctx; + + s->fli_type = AV_RL16(&fli_header[4]); /* Might be overridden if a Magic Carpet FLC */ +@@ -90,9 +98,6 @@ + /* special case for magic carpet FLIs */ + s->fli_type = FLC_MAGIC_CARPET_SYNTHETIC_TYPE_CODE; + depth = 8; +- } else if (s->avctx->extradata_size != 128) { +- av_log(avctx, AV_LOG_ERROR, "Expected extradata of 12 or 128 bytes\n"); +- return -1; + } else { + depth = AV_RL16(&fli_header[12]); + } +@@ -112,12 +117,12 @@ + case 24 : avctx->pix_fmt = PIX_FMT_BGR24; /* Supposedly BGR, but havent any files to test with */ + av_log(avctx, AV_LOG_ERROR, "24Bpp FLC/FLX is unsupported due to no test files.\n"); + return -1; +- break; + default : + av_log(avctx, AV_LOG_ERROR, "Unknown FLC/FLX depth of %d Bpp is unsupported.\n",depth); + return -1; + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + s->new_palette = 0; + +@@ -130,8 +135,7 @@ + { + FlicDecodeContext *s = avctx->priv_data; + +- int stream_ptr = 0; +- int stream_ptr_after_color_chunk; ++ GetByteContext g2; + int pixel_ptr; + int palette_ptr; + unsigned char palette_idx1; +@@ -161,7 +165,9 @@ + unsigned char *pixels; + unsigned int pixel_limit; + +- s->frame.reference = 1; ++ bytestream2_init(&g2, buf, buf_size); ++ ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -170,26 +176,33 @@ + + pixels = s->frame.data[0]; + pixel_limit = s->avctx->height * s->frame.linesize[0]; +- +- frame_size = AV_RL32(&buf[stream_ptr]); +- stream_ptr += 6; /* skip the magic number */ +- num_chunks = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 10; /* skip padding */ ++ if (buf_size < 16 || buf_size > INT_MAX - (3 * 256 + FF_INPUT_BUFFER_PADDING_SIZE)) ++ return AVERROR_INVALIDDATA; ++ frame_size = bytestream2_get_le32(&g2); ++ if (frame_size > buf_size) ++ frame_size = buf_size; ++ bytestream2_skip(&g2, 2); /* skip the magic number */ ++ num_chunks = bytestream2_get_le16(&g2); ++ bytestream2_skip(&g2, 8); /* skip padding */ + + frame_size -= 16; + + /* iterate through the chunks */ +- while ((frame_size > 0) && (num_chunks > 0)) { +- chunk_size = AV_RL32(&buf[stream_ptr]); +- stream_ptr += 4; +- chunk_type = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ while ((frame_size >= 6) && (num_chunks > 0)) { ++ int stream_ptr_after_chunk; ++ chunk_size = bytestream2_get_le32(&g2); ++ if (chunk_size > frame_size) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size); ++ chunk_size = frame_size; ++ } ++ stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size; ++ ++ chunk_type = bytestream2_get_le16(&g2); + + switch (chunk_type) { + case FLI_256_COLOR: + case FLI_COLOR: +- stream_ptr_after_color_chunk = stream_ptr + chunk_size - 6; +- + /* check special case: If this file is from the Magic Carpet + * game and uses 6-bit colors even though it reports 256-color + * chunks in a 0xAF12-type file (fli_type is set to 0xAF13 during +@@ -199,20 +212,22 @@ + else + color_shift = 2; + /* set up the palette */ +- color_packets = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ color_packets = bytestream2_get_le16(&g2); + palette_ptr = 0; + for (i = 0; i < color_packets; i++) { + /* first byte is how many colors to skip */ +- palette_ptr += buf[stream_ptr++]; ++ palette_ptr += bytestream2_get_byte(&g2); + + /* next byte indicates how many entries to change */ +- color_changes = buf[stream_ptr++]; ++ color_changes = bytestream2_get_byte(&g2); + + /* if there are 0 color changes, there are actually 256 */ + if (color_changes == 0) + color_changes = 256; + ++ if (bytestream2_tell(&g2) + color_changes * 3 > stream_ptr_after_chunk) ++ break; ++ + for (j = 0; j < color_changes; j++) { + unsigned int entry; + +@@ -220,31 +235,26 @@ + if ((unsigned)palette_ptr >= 256) + palette_ptr = 0; + +- r = buf[stream_ptr++] << color_shift; +- g = buf[stream_ptr++] << color_shift; +- b = buf[stream_ptr++] << color_shift; +- entry = (r << 16) | (g << 8) | b; ++ r = bytestream2_get_byte(&g2) << color_shift; ++ g = bytestream2_get_byte(&g2) << color_shift; ++ b = bytestream2_get_byte(&g2) << color_shift; ++ entry = 0xFF << 24 | r << 16 | g << 8 | b; ++ if (color_shift == 2) ++ entry |= entry >> 6 & 0x30303; + if (s->palette[palette_ptr] != entry) + s->new_palette = 1; + s->palette[palette_ptr++] = entry; + } + } +- +- /* color chunks sometimes have weird 16-bit alignment issues; +- * therefore, take the hardline approach and set the stream_ptr +- * to the value calculated w.r.t. the size specified by the color +- * chunk header */ +- stream_ptr = stream_ptr_after_color_chunk; +- + break; + + case FLI_DELTA: + y_ptr = 0; +- compressed_lines = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ compressed_lines = bytestream2_get_le16(&g2); + while (compressed_lines > 0) { +- line_packets = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk) ++ break; ++ line_packets = bytestream2_get_le16(&g2); + if ((line_packets & 0xC000) == 0xC000) { + // line skip opcode + line_packets = -line_packets; +@@ -262,15 +272,17 @@ + CHECK_PIXEL_PTR(0); + pixel_countdown = s->avctx->width; + for (i = 0; i < line_packets; i++) { ++ if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk) ++ break; + /* account for the skip bytes */ +- pixel_skip = buf[stream_ptr++]; ++ pixel_skip = bytestream2_get_byte(&g2); + pixel_ptr += pixel_skip; + pixel_countdown -= pixel_skip; +- byte_run = (signed char)(buf[stream_ptr++]); ++ byte_run = sign_extend(bytestream2_get_byte(&g2), 8); + if (byte_run < 0) { + byte_run = -byte_run; +- palette_idx1 = buf[stream_ptr++]; +- palette_idx2 = buf[stream_ptr++]; ++ palette_idx1 = bytestream2_get_byte(&g2); ++ palette_idx2 = bytestream2_get_byte(&g2); + CHECK_PIXEL_PTR(byte_run * 2); + for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { + pixels[pixel_ptr++] = palette_idx1; +@@ -278,9 +290,10 @@ + } + } else { + CHECK_PIXEL_PTR(byte_run * 2); ++ if (bytestream2_tell(&g2) + byte_run * 2 > stream_ptr_after_chunk) ++ break; + for (j = 0; j < byte_run * 2; j++, pixel_countdown--) { +- palette_idx1 = buf[stream_ptr++]; +- pixels[pixel_ptr++] = palette_idx1; ++ pixels[pixel_ptr++] = bytestream2_get_byte(&g2); + } + } + } +@@ -292,34 +305,37 @@ + + case FLI_LC: + /* line compressed */ +- starting_line = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ starting_line = bytestream2_get_le16(&g2); + y_ptr = 0; + y_ptr += starting_line * s->frame.linesize[0]; + +- compressed_lines = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ compressed_lines = bytestream2_get_le16(&g2); + while (compressed_lines > 0) { + pixel_ptr = y_ptr; + CHECK_PIXEL_PTR(0); + pixel_countdown = s->avctx->width; +- line_packets = buf[stream_ptr++]; ++ if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk) ++ break; ++ line_packets = bytestream2_get_byte(&g2); + if (line_packets > 0) { + for (i = 0; i < line_packets; i++) { + /* account for the skip bytes */ +- pixel_skip = buf[stream_ptr++]; ++ if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk) ++ break; ++ pixel_skip = bytestream2_get_byte(&g2); + pixel_ptr += pixel_skip; + pixel_countdown -= pixel_skip; +- byte_run = (signed char)(buf[stream_ptr++]); ++ byte_run = sign_extend(bytestream2_get_byte(&g2),8); + if (byte_run > 0) { + CHECK_PIXEL_PTR(byte_run); ++ if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk) ++ break; + for (j = 0; j < byte_run; j++, pixel_countdown--) { +- palette_idx1 = buf[stream_ptr++]; +- pixels[pixel_ptr++] = palette_idx1; ++ pixels[pixel_ptr++] = bytestream2_get_byte(&g2); + } + } else if (byte_run < 0) { + byte_run = -byte_run; +- palette_idx1 = buf[stream_ptr++]; ++ palette_idx1 = bytestream2_get_byte(&g2); + CHECK_PIXEL_PTR(byte_run); + for (j = 0; j < byte_run; j++, pixel_countdown--) { + pixels[pixel_ptr++] = palette_idx1; +@@ -347,12 +363,14 @@ + pixel_ptr = y_ptr; + /* disregard the line packets; instead, iterate through all + * pixels on a row */ +- stream_ptr++; ++ bytestream2_skip(&g2, 1); + pixel_countdown = s->avctx->width; + while (pixel_countdown > 0) { +- byte_run = (signed char)(buf[stream_ptr++]); ++ if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk) ++ break; ++ byte_run = sign_extend(bytestream2_get_byte(&g2), 8); + if (byte_run > 0) { +- palette_idx1 = buf[stream_ptr++]; ++ palette_idx1 = bytestream2_get_byte(&g2); + CHECK_PIXEL_PTR(byte_run); + for (j = 0; j < byte_run; j++) { + pixels[pixel_ptr++] = palette_idx1; +@@ -364,9 +382,10 @@ + } else { /* copy bytes if byte_run < 0 */ + byte_run = -byte_run; + CHECK_PIXEL_PTR(byte_run); ++ if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk) ++ break; + for (j = 0; j < byte_run; j++) { +- palette_idx1 = buf[stream_ptr++]; +- pixels[pixel_ptr++] = palette_idx1; ++ pixels[pixel_ptr++] = bytestream2_get_byte(&g2); + pixel_countdown--; + if (pixel_countdown < 0) + av_log(avctx, AV_LOG_ERROR, "pixel_countdown < 0 (%d) at line %d\n", +@@ -381,23 +400,21 @@ + + case FLI_COPY: + /* copy the chunk (uncompressed frame) */ +- if (chunk_size - 6 > s->avctx->width * s->avctx->height) { ++ if (chunk_size - 6 != s->avctx->width * s->avctx->height) { + av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \ +- "bigger than image, skipping chunk\n", chunk_size - 6); +- stream_ptr += chunk_size - 6; ++ "has incorrect size, skipping chunk\n", chunk_size - 6); ++ bytestream2_skip(&g2, chunk_size - 6); + } else { + for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; + y_ptr += s->frame.linesize[0]) { +- memcpy(&pixels[y_ptr], &buf[stream_ptr], +- s->avctx->width); +- stream_ptr += s->avctx->width; ++ bytestream2_get_buffer(&g2, &pixels[y_ptr], ++ s->avctx->width); + } + } + break; + + case FLI_MINI: + /* some sort of a thumbnail? disregard this chunk... */ +- stream_ptr += chunk_size - 6; + break; + + default: +@@ -405,15 +422,20 @@ + break; + } + ++ if (stream_ptr_after_chunk - bytestream2_tell(&g2) > 0) ++ bytestream2_skip(&g2, stream_ptr_after_chunk - bytestream2_tell(&g2)); ++ + frame_size -= chunk_size; + num_chunks--; + } + + /* by the end of the chunk, the stream ptr should equal the frame + * size (minus 1, possibly); if it doesn't, issue a warning */ +- if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1)) ++ if ((bytestream2_get_bytes_left(&g2) != 0) && ++ (bytestream2_get_bytes_left(&g2) != 1)) + av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \ +- "and final chunk ptr = %d\n", buf_size, stream_ptr); ++ "and final chunk ptr = %d\n", buf_size, ++ buf_size - bytestream2_get_bytes_left(&g2)); + + /* make the palette available on the way out */ + memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); +@@ -436,7 +458,7 @@ + /* Format is the pixel format, the packets are processed the same. */ + FlicDecodeContext *s = avctx->priv_data; + +- int stream_ptr = 0; ++ GetByteContext g2; + int pixel_ptr; + unsigned char palette_idx1; + +@@ -459,7 +481,9 @@ + int pixel; + unsigned int pixel_limit; + +- s->frame.reference = 1; ++ bytestream2_init(&g2, buf, buf_size); ++ ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -469,19 +493,28 @@ + pixels = s->frame.data[0]; + pixel_limit = s->avctx->height * s->frame.linesize[0]; + +- frame_size = AV_RL32(&buf[stream_ptr]); +- stream_ptr += 6; /* skip the magic number */ +- num_chunks = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 10; /* skip padding */ ++ frame_size = bytestream2_get_le32(&g2); ++ bytestream2_skip(&g2, 2); /* skip the magic number */ ++ num_chunks = bytestream2_get_le16(&g2); ++ bytestream2_skip(&g2, 8); /* skip padding */ ++ if (frame_size > buf_size) ++ frame_size = buf_size; + + frame_size -= 16; + + /* iterate through the chunks */ + while ((frame_size > 0) && (num_chunks > 0)) { +- chunk_size = AV_RL32(&buf[stream_ptr]); +- stream_ptr += 4; +- chunk_type = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ int stream_ptr_after_chunk; ++ chunk_size = bytestream2_get_le32(&g2); ++ if (chunk_size > frame_size) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Invalid chunk_size = %u > frame_size = %u\n", chunk_size, frame_size); ++ chunk_size = frame_size; ++ } ++ stream_ptr_after_chunk = bytestream2_tell(&g2) - 4 + chunk_size; ++ ++ chunk_type = bytestream2_get_le16(&g2); ++ + + switch (chunk_type) { + case FLI_256_COLOR: +@@ -490,17 +523,17 @@ + * include one of these chunks in their first frame. + * Why I do not know, it seems rather extraneous. */ + /* av_log(avctx, AV_LOG_ERROR, "Unexpected Palette chunk %d in non-paletised FLC\n",chunk_type);*/ +- stream_ptr = stream_ptr + chunk_size - 6; ++ bytestream2_skip(&g2, chunk_size - 6); + break; + + case FLI_DELTA: + case FLI_DTA_LC: + y_ptr = 0; +- compressed_lines = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ compressed_lines = bytestream2_get_le16(&g2); + while (compressed_lines > 0) { +- line_packets = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk) ++ break; ++ line_packets = bytestream2_get_le16(&g2); + if (line_packets < 0) { + line_packets = -line_packets; + y_ptr += line_packets * s->frame.linesize[0]; +@@ -511,24 +544,26 @@ + pixel_countdown = s->avctx->width; + for (i = 0; i < line_packets; i++) { + /* account for the skip bytes */ +- pixel_skip = buf[stream_ptr++]; ++ if (bytestream2_tell(&g2) + 2 > stream_ptr_after_chunk) ++ break; ++ pixel_skip = bytestream2_get_byte(&g2); + pixel_ptr += (pixel_skip*2); /* Pixel is 2 bytes wide */ + pixel_countdown -= pixel_skip; +- byte_run = (signed char)(buf[stream_ptr++]); ++ byte_run = sign_extend(bytestream2_get_byte(&g2), 8); + if (byte_run < 0) { + byte_run = -byte_run; +- pixel = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ pixel = bytestream2_get_le16(&g2); + CHECK_PIXEL_PTR(2 * byte_run); + for (j = 0; j < byte_run; j++, pixel_countdown -= 2) { + *((signed short*)(&pixels[pixel_ptr])) = pixel; + pixel_ptr += 2; + } + } else { ++ if (bytestream2_tell(&g2) + 2*byte_run > stream_ptr_after_chunk) ++ break; + CHECK_PIXEL_PTR(2 * byte_run); + for (j = 0; j < byte_run; j++, pixel_countdown--) { +- *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2); + pixel_ptr += 2; + } + } +@@ -541,7 +576,7 @@ + + case FLI_LC: + av_log(avctx, AV_LOG_ERROR, "Unexpected FLI_LC chunk in non-paletised FLC\n"); +- stream_ptr = stream_ptr + chunk_size - 6; ++ bytestream2_skip(&g2, chunk_size - 6); + break; + + case FLI_BLACK: +@@ -556,13 +591,15 @@ + pixel_ptr = y_ptr; + /* disregard the line packets; instead, iterate through all + * pixels on a row */ +- stream_ptr++; ++ bytestream2_skip(&g2, 1); + pixel_countdown = (s->avctx->width * 2); + + while (pixel_countdown > 0) { +- byte_run = (signed char)(buf[stream_ptr++]); ++ if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk) ++ break; ++ byte_run = sign_extend(bytestream2_get_byte(&g2), 8); + if (byte_run > 0) { +- palette_idx1 = buf[stream_ptr++]; ++ palette_idx1 = bytestream2_get_byte(&g2); + CHECK_PIXEL_PTR(byte_run); + for (j = 0; j < byte_run; j++) { + pixels[pixel_ptr++] = palette_idx1; +@@ -573,9 +610,11 @@ + } + } else { /* copy bytes if byte_run < 0 */ + byte_run = -byte_run; ++ if (bytestream2_tell(&g2) + byte_run > stream_ptr_after_chunk) ++ break; + CHECK_PIXEL_PTR(byte_run); + for (j = 0; j < byte_run; j++) { +- palette_idx1 = buf[stream_ptr++]; ++ palette_idx1 = bytestream2_get_byte(&g2); + pixels[pixel_ptr++] = palette_idx1; + pixel_countdown--; + if (pixel_countdown < 0) +@@ -608,14 +647,15 @@ + pixel_ptr = y_ptr; + /* disregard the line packets; instead, iterate through all + * pixels on a row */ +- stream_ptr++; ++ bytestream2_skip(&g2, 1); + pixel_countdown = s->avctx->width; /* Width is in pixels, not bytes */ + + while (pixel_countdown > 0) { +- byte_run = (signed char)(buf[stream_ptr++]); ++ if (bytestream2_tell(&g2) + 1 > stream_ptr_after_chunk) ++ break; ++ byte_run = sign_extend(bytestream2_get_byte(&g2), 8); + if (byte_run > 0) { +- pixel = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ pixel = bytestream2_get_le16(&g2); + CHECK_PIXEL_PTR(2 * byte_run); + for (j = 0; j < byte_run; j++) { + *((signed short*)(&pixels[pixel_ptr])) = pixel; +@@ -627,10 +667,11 @@ + } + } else { /* copy pixels if byte_run < 0 */ + byte_run = -byte_run; ++ if (bytestream2_tell(&g2) + 2 * byte_run > stream_ptr_after_chunk) ++ break; + CHECK_PIXEL_PTR(2 * byte_run); + for (j = 0; j < byte_run; j++) { +- *((signed short*)(&pixels[pixel_ptr])) = AV_RL16(&buf[stream_ptr]); +- stream_ptr += 2; ++ *((signed short*)(&pixels[pixel_ptr])) = bytestream2_get_le16(&g2); + pixel_ptr += 2; + pixel_countdown--; + if (pixel_countdown < 0) +@@ -650,7 +691,7 @@ + if (chunk_size - 6 > (unsigned int)(s->avctx->width * s->avctx->height)*2) { + av_log(avctx, AV_LOG_ERROR, "In chunk FLI_COPY : source data (%d bytes) " \ + "bigger than image, skipping chunk\n", chunk_size - 6); +- stream_ptr += chunk_size - 6; ++ bytestream2_skip(&g2, chunk_size - 6); + } else { + + for (y_ptr = 0; y_ptr < s->frame.linesize[0] * s->avctx->height; +@@ -659,18 +700,17 @@ + pixel_countdown = s->avctx->width; + pixel_ptr = 0; + while (pixel_countdown > 0) { +- *((signed short*)(&pixels[y_ptr + pixel_ptr])) = AV_RL16(&buf[stream_ptr+pixel_ptr]); ++ *((signed short*)(&pixels[y_ptr + pixel_ptr])) = bytestream2_get_le16(&g2); + pixel_ptr += 2; + pixel_countdown--; + } +- stream_ptr += s->avctx->width*2; + } + } + break; + + case FLI_MINI: + /* some sort of a thumbnail? disregard this chunk... */ +- stream_ptr += chunk_size - 6; ++ bytestream2_skip(&g2, chunk_size - 6); + break; + + default: +@@ -684,9 +724,9 @@ + + /* by the end of the chunk, the stream ptr should equal the frame + * size (minus 1, possibly); if it doesn't, issue a warning */ +- if ((stream_ptr != buf_size) && (stream_ptr != buf_size - 1)) ++ if ((bytestream2_get_bytes_left(&g2) != 0) && (bytestream2_get_bytes_left(&g2) != 1)) + av_log(avctx, AV_LOG_ERROR, "Processed FLI chunk where chunk size = %d " \ +- "and final chunk ptr = %d\n", buf_size, stream_ptr); ++ "and final chunk ptr = %d\n", buf_size, bytestream2_tell(&g2)); + + + *data_size=sizeof(AVFrame); +@@ -743,18 +783,13 @@ + } + + AVCodec ff_flic_decoder = { +- "flic", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FLIC, +- sizeof(FlicDecodeContext), +- flic_decode_init, +- NULL, +- flic_decode_end, +- flic_decode_frame, +- CODEC_CAP_DR1, +- NULL, +- NULL, +- NULL, +- NULL, ++ .name = "flic", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLIC, ++ .priv_data_size = sizeof(FlicDecodeContext), ++ .init = flic_decode_init, ++ .close = flic_decode_end, ++ .decode = flic_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Autodesk Animator Flic video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flvdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flvdec.c 2012-05-14 14:08:53.730327825 +0200 +@@ -20,7 +20,7 @@ + #include "mpegvideo.h" + #include "h263.h" + #include "flv.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last){ + int is11 = get_bits1(gb); +@@ -88,10 +88,10 @@ + s->width = width; + s->height = height; + +- s->pict_type = FF_I_TYPE + get_bits(&s->gb, 2); +- s->dropable= s->pict_type > FF_P_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_I + get_bits(&s->gb, 2); ++ s->dropable= s->pict_type > AV_PICTURE_TYPE_P; + if (s->dropable) +- s->pict_type = FF_P_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_P; + + skip_bits1(&s->gb); /* deblocking flag */ + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); +@@ -109,7 +109,7 @@ + + if(s->avctx->debug & FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "%c esc_type:%d, qp:%d num:%d\n", +- s->dropable ? 'D' : av_get_pict_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); ++ s->dropable ? 'D' : av_get_picture_type_char(s->pict_type), s->h263_flv-1, s->qscale, s->picture_number); + } + + s->y_dc_scale_table= +@@ -119,15 +119,14 @@ + } + + AVCodec ff_flv_decoder = { +- "flv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FLV1, +- sizeof(MpegEncContext), +- ff_h263_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "flv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLV1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_h263_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), + .pix_fmts= ff_pixfmt_list_420, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flvenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flvenc.c 2012-05-14 14:08:53.731327845 +0200 +@@ -25,7 +25,7 @@ + { + int format; + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + + put_bits(&s->pb, 17, 1); + put_bits(&s->pb, 5, (s->h263_flv-1)); /* 0: h263 escape codes 1: 11-bit escape codes */ +@@ -53,7 +53,7 @@ + put_bits(&s->pb, 16, s->width); + put_bits(&s->pb, 16, s->height); + } +- put_bits(&s->pb, 2, s->pict_type == FF_P_TYPE); /* PictureType */ ++ put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_P); /* PictureType */ + put_bits(&s->pb, 1, 1); /* DeblockingFlag: on */ + put_bits(&s->pb, 5, s->qscale); /* Quantizer */ + put_bits(&s->pb, 1, 0); /* ExtraInformation */ +@@ -85,13 +85,13 @@ + } + + AVCodec ff_flv_encoder = { +- "flv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FLV1, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "flv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FLV1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("Flash Video (FLV) / Sorenson Spark / Sorenson H.263"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flv.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flv.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/flv.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/flv.h 2012-05-14 14:08:53.729327805 +0200 +@@ -30,5 +30,4 @@ + int ff_flv_decode_picture_header(MpegEncContext *s); + void ff_flv2_decode_ac_esc(GetBitContext *gb, int *level, int *run, int *last); + +-#endif +- ++#endif /* AVCODEC_FLV_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fmtconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fmtconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/fmtconvert.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/fmtconvert.c 2012-05-14 14:08:53.732327865 +0200 +@@ -56,13 +56,64 @@ + } + } + ++void ff_float_interleave_c(float *dst, const float **src, unsigned int len, ++ int channels) ++{ ++ int j, c; ++ unsigned int i; ++ if (channels == 2) { ++ for (i = 0; i < len; i++) { ++ dst[2*i] = src[0][i]; ++ dst[2*i+1] = src[1][i]; ++ } ++ } else if (channels == 1 && len < INT_MAX / sizeof(float)) { ++ memcpy(dst, src[0], len * sizeof(float)); ++ } else { ++ for (c = 0; c < channels; c++) ++ for (i = 0, j = c; i < len; i++, j += channels) ++ dst[j] = src[c][i]; ++ } ++} ++ + av_cold void ff_fmt_convert_init(FmtConvertContext *c, AVCodecContext *avctx) + { + c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_c; + c->float_to_int16 = float_to_int16_c; + c->float_to_int16_interleave = float_to_int16_interleave_c; ++ c->float_interleave = ff_float_interleave_c; + + if (ARCH_ARM) ff_fmt_convert_init_arm(c, avctx); +- if (ARCH_PPC) ff_fmt_convert_init_ppc(c, avctx); ++ if (HAVE_ALTIVEC) ff_fmt_convert_init_altivec(c, avctx); + if (HAVE_MMX) ff_fmt_convert_init_x86(c, avctx); + } ++ ++/* ffdshow custom code */ ++void float_interleave(float *dst, const float **src, long len, int channels) ++{ ++ int i,j,c; ++ if(channels==2){ ++ for(i=0; ipriv_data; + ++ avcodec_get_frame_defaults(&s->frame); + avctx->coded_frame = (AVFrame*)&s->frame; +- avctx->pix_fmt= PIX_FMT_NONE; /* set in decode_frame */ + + s->avctx = avctx; + s->tmpbuf = NULL; +@@ -111,6 +112,10 @@ + */ + if(j) dst[i] += dst[i - stride]; + else if(Uoff) dst[i] += 0x80; ++ if (get_bits_left(&gb) < 0) { ++ free_vlc(&vlc); ++ return AVERROR_INVALIDDATA; ++ } + } + dst += stride; + } +@@ -133,8 +138,9 @@ + const uint32_t *buf32; + uint32_t *luma1,*luma2,*cb,*cr; + uint32_t offs[4]; +- int i, j, is_chroma, planes; +- ++ int i, j, is_chroma; ++ const int planes = 3; ++ enum PixelFormat pix_fmt; + + header = AV_RL32(buf); + version = header & 0xff; +@@ -147,43 +153,52 @@ + return -1; + } + +- buf+=4; +- if (header_size == 8) +- buf+=4; +- +- switch(version) { +- case 0: +- default: +- /* Fraps v0 is a reordered YUV420 */ +- avctx->pix_fmt = PIX_FMT_YUVJ420P; ++ buf += header_size; + +- if ( (buf_size != avctx->width*avctx->height*3/2+header_size) && +- (buf_size != header_size) ) { ++ if (version < 2) { ++ unsigned needed_size = avctx->width*avctx->height*3; ++ if (version == 0) needed_size /= 2; ++ needed_size += header_size; ++ if (buf_size != needed_size && buf_size != header_size) { + av_log(avctx, AV_LOG_ERROR, + "Invalid frame length %d (should be %d)\n", +- buf_size, avctx->width*avctx->height*3/2+header_size); ++ buf_size, needed_size); + return -1; + } ++ } ++ ++ f->pict_type = AV_PICTURE_TYPE_I; ++ f->key_frame = 1; ++ f->reference = 3; ++ f->buffer_hints = FF_BUFFER_HINTS_VALID | ++ FF_BUFFER_HINTS_PRESERVE | ++ FF_BUFFER_HINTS_REUSABLE; ++ ++ pix_fmt = version & 1 ? PIX_FMT_BGR24 : PIX_FMT_YUVJ420P; ++ if (avctx->pix_fmt != pix_fmt && f->data[0]) { ++ avctx->release_buffer(avctx, f); ++ } ++ avctx->pix_fmt = pix_fmt; + +- if (( (avctx->width % 8) != 0) || ( (avctx->height % 2) != 0 )) { ++ switch(version) { ++ case 0: ++ default: ++ /* Fraps v0 is a reordered YUV420 */ ++ if ( (avctx->width % 8) != 0 || (avctx->height % 2) != 0 ) { + av_log(avctx, AV_LOG_ERROR, "Invalid frame size %dx%d\n", + avctx->width, avctx->height); + return -1; + } + +- f->reference = 1; +- f->buffer_hints = FF_BUFFER_HINTS_VALID | +- FF_BUFFER_HINTS_PRESERVE | +- FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, f)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + /* bit 31 means same as previous pic */ +- f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE; +- f->key_frame = f->pict_type == FF_I_TYPE; +- +- if (f->pict_type == FF_I_TYPE) { ++ if (header & (1U<<31)) { ++ f->pict_type = AV_PICTURE_TYPE_P; ++ f->key_frame = 0; ++ } else { + buf32=(const uint32_t*)buf; + for(y=0; yheight/2; y++){ + luma1=(uint32_t*)&f->data[0][ y*2*f->linesize[0] ]; +@@ -191,12 +206,12 @@ + cr=(uint32_t*)&f->data[1][ y*f->linesize[1] ]; + cb=(uint32_t*)&f->data[2][ y*f->linesize[2] ]; + for(x=0; xwidth; x+=8){ +- *(luma1++) = *(buf32++); +- *(luma1++) = *(buf32++); +- *(luma2++) = *(buf32++); +- *(luma2++) = *(buf32++); +- *(cr++) = *(buf32++); +- *(cb++) = *(buf32++); ++ *luma1++ = *buf32++; ++ *luma1++ = *buf32++; ++ *luma2++ = *buf32++; ++ *luma2++ = *buf32++; ++ *cr++ = *buf32++; ++ *cb++ = *buf32++; + } + } + } +@@ -204,29 +219,15 @@ + + case 1: + /* Fraps v1 is an upside-down BGR24 */ +- avctx->pix_fmt = PIX_FMT_BGR24; +- +- if ( (buf_size != avctx->width*avctx->height*3+header_size) && +- (buf_size != header_size) ) { +- av_log(avctx, AV_LOG_ERROR, +- "Invalid frame length %d (should be %d)\n", +- buf_size, avctx->width*avctx->height*3+header_size); +- return -1; +- } +- +- f->reference = 1; +- f->buffer_hints = FF_BUFFER_HINTS_VALID | +- FF_BUFFER_HINTS_PRESERVE | +- FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, f)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + /* bit 31 means same as previous pic */ +- f->pict_type = (header & (1<<31))? FF_P_TYPE : FF_I_TYPE; +- f->key_frame = f->pict_type == FF_I_TYPE; +- +- if (f->pict_type == FF_I_TYPE) { ++ if (header & (1U<<31)) { ++ f->pict_type = AV_PICTURE_TYPE_P; ++ f->key_frame = 0; ++ } else { + for(y=0; yheight; y++) + memcpy(&f->data[0][ (avctx->height-y)*f->linesize[0] ], + &buf[y*avctx->width*3], +@@ -240,25 +241,17 @@ + * Fraps v2 is Huffman-coded YUV420 planes + * Fraps v4 is virtually the same + */ +- avctx->pix_fmt = PIX_FMT_YUVJ420P; +- planes = 3; +- f->reference = 1; +- f->buffer_hints = FF_BUFFER_HINTS_VALID | +- FF_BUFFER_HINTS_PRESERVE | +- FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, f)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + /* skip frame */ + if(buf_size == 8) { +- f->pict_type = FF_P_TYPE; ++ f->pict_type = AV_PICTURE_TYPE_P; + f->key_frame = 0; + break; + } +- f->pict_type = FF_I_TYPE; +- f->key_frame = 1; +- if ((AV_RL32(buf) != FPS_TAG)||(buf_size < (planes*1024 + 24))) { ++ if (AV_RL32(buf) != FPS_TAG || buf_size < planes*1024 + 24) { + av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n"); + return -1; + } +@@ -272,7 +265,9 @@ + offs[planes] = buf_size; + for(i = 0; i < planes; i++){ + is_chroma = !!i; +- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE); ++ av_fast_padded_malloc(&s->tmpbuf, &s->tmpbuf_size, offs[i + 1] - offs[i] - 1024); ++ if (!s->tmpbuf) ++ return AVERROR(ENOMEM); + if(fraps2_decode_plane(s, f->data[i], f->linesize[i], avctx->width >> is_chroma, + avctx->height >> is_chroma, buf + offs[i], offs[i + 1] - offs[i], is_chroma, 1) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); +@@ -283,25 +278,17 @@ + case 3: + case 5: + /* Virtually the same as version 4, but is for RGB24 */ +- avctx->pix_fmt = PIX_FMT_BGR24; +- planes = 3; +- f->reference = 1; +- f->buffer_hints = FF_BUFFER_HINTS_VALID | +- FF_BUFFER_HINTS_PRESERVE | +- FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, f)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + /* skip frame */ + if(buf_size == 8) { +- f->pict_type = FF_P_TYPE; ++ f->pict_type = AV_PICTURE_TYPE_P; + f->key_frame = 0; + break; + } +- f->pict_type = FF_I_TYPE; +- f->key_frame = 1; +- if ((AV_RL32(buf) != FPS_TAG)||(buf_size < (planes*1024 + 24))) { ++ if (AV_RL32(buf) != FPS_TAG || buf_size < planes*1024 + 24) { + av_log(avctx, AV_LOG_ERROR, "Fraps: error in data stream\n"); + return -1; + } +@@ -314,7 +301,9 @@ + } + offs[planes] = buf_size; + for(i = 0; i < planes; i++){ +- s->tmpbuf = av_realloc(s->tmpbuf, offs[i + 1] - offs[i] - 1024 + FF_INPUT_BUFFER_PADDING_SIZE); ++ av_fast_padded_malloc(&s->tmpbuf, &s->tmpbuf_size, offs[i + 1] - offs[i] - 1024); ++ if (!s->tmpbuf) ++ return AVERROR(ENOMEM); + if(fraps2_decode_plane(s, f->data[0] + i + (f->linesize[0] * (avctx->height - 1)), -f->linesize[0], + avctx->width, avctx->height, buf + offs[i], offs[i + 1] - offs[i], 0, 3) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error decoding plane %i\n", i); +@@ -356,14 +345,13 @@ + + + AVCodec ff_fraps_decoder = { +- "fraps", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FRAPS, +- sizeof(FrapsContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "fraps", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FRAPS, ++ .priv_data_size = sizeof(FrapsContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Fraps"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/frwu.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/frwu.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/frwu.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/frwu.c 2012-05-14 14:08:53.734327907 +0200 +@@ -27,7 +27,7 @@ + static av_cold int decode_init(AVCodecContext *avctx) + { + if (avctx->width & 1) { +- av_log(avctx, AV_LOG_ERROR, "FRWU needs even width\n"); ++ av_log(avctx, AV_LOG_ERROR, "frwu needs even width\n"); + return -1; + } + avctx->pix_fmt = PIX_FMT_UYVY422; +@@ -61,7 +61,7 @@ + if (avctx->get_buffer(avctx, pic) < 0) + return -1; + +- pic->pict_type = FF_I_TYPE; ++ pic->pict_type = AV_PICTURE_TYPE_I; + pic->key_frame = 1; + pic->interlaced_frame = 1; + pic->top_field_first = 1; +@@ -110,14 +110,12 @@ + } + + AVCodec ff_frwu_decoder = { +- "FRWU", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FRWU, +- 0, +- decode_init, +- NULL, +- decode_close, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "frwu", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FRWU, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Forward Uncompressed"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722.c 2012-05-14 14:08:53.736327947 +0200 +@@ -26,7 +26,6 @@ + + /** + * @file +- * + * G.722 ADPCM audio codec + * + * This G.722 decoder is a bit-exact implementation of the ITU G.722 +@@ -37,45 +36,8 @@ + * respectively of each byte are ignored. + */ + +-#include "avcodec.h" + #include "mathops.h" +-#include "get_bits.h" +- +-#define PREV_SAMPLES_BUF_SIZE 1024 +- +-#define FREEZE_INTERVAL 128 +- +-typedef struct { +- int16_t prev_samples[PREV_SAMPLES_BUF_SIZE]; ///< memory of past decoded samples +- int prev_samples_pos; ///< the number of values in prev_samples +- +- /** +- * The band[0] and band[1] correspond respectively to the lower band and higher band. +- */ +- struct G722Band { +- int16_t s_predictor; ///< predictor output value +- int32_t s_zero; ///< previous output signal from zero predictor +- int8_t part_reconst_mem[2]; ///< signs of previous partially reconstructed signals +- int16_t prev_qtzd_reconst; ///< previous quantized reconstructed signal (internal value, using low_inv_quant4) +- int16_t pole_mem[2]; ///< second-order pole section coefficient buffer +- int32_t diff_mem[6]; ///< quantizer difference signal memory +- int16_t zero_mem[6]; ///< Seventh-order zero section coefficient buffer +- int16_t log_factor; ///< delayed 2-logarithmic quantizer factor +- int16_t scale_factor; ///< delayed quantizer scale factor +- } band[2]; +- +- struct TrellisNode { +- struct G722Band state; +- uint32_t ssd; +- int path; +- } *node_buf[2], **nodep_buf[2]; +- +- struct TrellisPath { +- int value; +- int prev; +- } *paths[2]; +-} G722Context; +- ++#include "g722.h" + + static const int8_t sign_lookup[2] = { -1, 1 }; + +@@ -86,7 +48,7 @@ + 3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008 + }; + static const int16_t high_log_factor_step[2] = { 798, -214 }; +-static const int16_t high_inv_quant[4] = { -926, -202, 926, 202 }; ++const int16_t ff_g722_high_inv_quant[4] = { -926, -202, 926, 202 }; + /** + * low_log_factor_step[index] == wl[rl42[index]] + */ +@@ -94,11 +56,11 @@ + -60, 3042, 1198, 538, 334, 172, 58, -30, + 3042, 1198, 538, 334, 172, 58, -30, -60 + }; +-static const int16_t low_inv_quant4[16] = { ++const int16_t ff_g722_low_inv_quant4[16] = { + 0, -2557, -1612, -1121, -786, -530, -323, -150, + 2557, 1612, 1121, 786, 530, 323, 150, 0 + }; +-static const int16_t low_inv_quant6[64] = { ++const int16_t ff_g722_low_inv_quant6[64] = { + -17, -17, -17, -17, -3101, -2738, -2376, -2088, + -1873, -1689, -1535, -1399, -1279, -1170, -1072, -982, + -899, -822, -750, -682, -618, -558, -501, -447, +@@ -167,17 +129,17 @@ + band->prev_qtzd_reconst = cur_qtzd_reconst; + } + +-static int inline linear_scale_factor(const int log_factor) ++static inline int linear_scale_factor(const int log_factor) + { + const int wd1 = inv_log2_table[(log_factor >> 6) & 31]; + const int shift = log_factor >> 11; + return shift < 0 ? wd1 >> -shift : wd1 << shift; + } + +-static void update_low_predictor(struct G722Band *band, const int ilow) ++void ff_g722_update_low_predictor(struct G722Band *band, const int ilow) + { + do_adaptive_prediction(band, +- band->scale_factor * low_inv_quant4[ilow] >> 10); ++ band->scale_factor * ff_g722_low_inv_quant4[ilow] >> 10); + + // quantizer adaptation + band->log_factor = av_clip((band->log_factor * 127 >> 7) + +@@ -185,7 +147,7 @@ + band->scale_factor = linear_scale_factor(band->log_factor - (8 << 11)); + } + +-static void update_high_predictor(struct G722Band *band, const int dhigh, ++void ff_g722_update_high_predictor(struct G722Band *band, const int dhigh, + const int ihigh) + { + do_adaptive_prediction(band, dhigh); +@@ -196,7 +158,7 @@ + band->scale_factor = linear_scale_factor(band->log_factor - (10 << 11)); + } + +-static void apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2) ++void ff_g722_apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2) + { + int i; + +@@ -207,377 +169,3 @@ + MAC16(*xout1, prev_samples[2*i+1], qmf_coeffs[11-i]); + } + } +- +-static av_cold int g722_init(AVCodecContext * avctx) +-{ +- G722Context *c = avctx->priv_data; +- +- if (avctx->channels != 1) { +- av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); +- return AVERROR_INVALIDDATA; +- } +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- +- switch (avctx->bits_per_coded_sample) { +- case 8: +- case 7: +- case 6: +- break; +- default: +- av_log(avctx, AV_LOG_WARNING, "Unsupported bits_per_coded_sample [%d], " +- "assuming 8\n", +- avctx->bits_per_coded_sample); +- case 0: +- avctx->bits_per_coded_sample = 8; +- break; +- } +- +- c->band[0].scale_factor = 8; +- c->band[1].scale_factor = 2; +- c->prev_samples_pos = 22; +- +- if (avctx->lowres) +- avctx->sample_rate /= 2; +- +- if (avctx->trellis) { +- int frontier = 1 << avctx->trellis; +- int max_paths = frontier * FREEZE_INTERVAL; +- int i; +- for (i = 0; i < 2; i++) { +- c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); +- c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); +- c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf)); +- } +- } +- +- return 0; +-} +- +-static av_cold int g722_close(AVCodecContext *avctx) +-{ +- G722Context *c = avctx->priv_data; +- int i; +- for (i = 0; i < 2; i++) { +- av_freep(&c->paths[i]); +- av_freep(&c->node_buf[i]); +- av_freep(&c->nodep_buf[i]); +- } +- return 0; +-} +- +-#if CONFIG_ADPCM_G722_DECODER +-static const int16_t low_inv_quant5[32] = { +- -35, -35, -2919, -2195, -1765, -1458, -1219, -1023, +- -858, -714, -587, -473, -370, -276, -190, -110, +- 2919, 2195, 1765, 1458, 1219, 1023, 858, 714, +- 587, 473, 370, 276, 190, 110, 35, -35 +-}; +- +-static const int16_t *low_inv_quants[3] = { low_inv_quant6, low_inv_quant5, +- low_inv_quant4 }; +- +-static int g722_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) +-{ +- G722Context *c = avctx->priv_data; +- int16_t *out_buf = data; +- int j, out_len = 0; +- const int skip = 8 - avctx->bits_per_coded_sample; +- const int16_t *quantizer_table = low_inv_quants[skip]; +- GetBitContext gb; +- +- init_get_bits(&gb, avpkt->data, avpkt->size * 8); +- +- for (j = 0; j < avpkt->size; j++) { +- int ilow, ihigh, rlow; +- +- ihigh = get_bits(&gb, 2); +- ilow = get_bits(&gb, 6 - skip); +- skip_bits(&gb, skip); +- +- rlow = av_clip((c->band[0].scale_factor * quantizer_table[ilow] >> 10) +- + c->band[0].s_predictor, -16384, 16383); +- +- update_low_predictor(&c->band[0], ilow >> (2 - skip)); +- +- if (!avctx->lowres) { +- const int dhigh = c->band[1].scale_factor * +- high_inv_quant[ihigh] >> 10; +- const int rhigh = av_clip(dhigh + c->band[1].s_predictor, +- -16384, 16383); +- int xout1, xout2; +- +- update_high_predictor(&c->band[1], dhigh, ihigh); +- +- c->prev_samples[c->prev_samples_pos++] = rlow + rhigh; +- c->prev_samples[c->prev_samples_pos++] = rlow - rhigh; +- apply_qmf(c->prev_samples + c->prev_samples_pos - 24, +- &xout1, &xout2); +- out_buf[out_len++] = av_clip_int16(xout1 >> 12); +- out_buf[out_len++] = av_clip_int16(xout2 >> 12); +- if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { +- memmove(c->prev_samples, +- c->prev_samples + c->prev_samples_pos - 22, +- 22 * sizeof(c->prev_samples[0])); +- c->prev_samples_pos = 22; +- } +- } else +- out_buf[out_len++] = rlow; +- } +- *data_size = out_len << 1; +- return avpkt->size; +-} +- +-AVCodec ff_adpcm_g722_decoder = { +- .name = "g722", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_ADPCM_G722, +- .priv_data_size = sizeof(G722Context), +- .init = g722_init, +- .decode = g722_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), +- .max_lowres = 1, +-}; +-#endif +- +-#if CONFIG_ADPCM_G722_ENCODER +-static const int16_t low_quant[33] = { +- 35, 72, 110, 150, 190, 233, 276, 323, +- 370, 422, 473, 530, 587, 650, 714, 786, +- 858, 940, 1023, 1121, 1219, 1339, 1458, 1612, +- 1765, 1980, 2195, 2557, 2919 +-}; +- +-static inline void filter_samples(G722Context *c, const int16_t *samples, +- int *xlow, int *xhigh) +-{ +- int xout1, xout2; +- c->prev_samples[c->prev_samples_pos++] = samples[0]; +- c->prev_samples[c->prev_samples_pos++] = samples[1]; +- apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2); +- *xlow = xout1 + xout2 >> 13; +- *xhigh = xout1 - xout2 >> 13; +- if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { +- memmove(c->prev_samples, +- c->prev_samples + c->prev_samples_pos - 22, +- 22 * sizeof(c->prev_samples[0])); +- c->prev_samples_pos = 22; +- } +-} +- +-static inline int encode_high(const struct G722Band *state, int xhigh) +-{ +- int diff = av_clip_int16(xhigh - state->s_predictor); +- int pred = 141 * state->scale_factor >> 8; +- /* = diff >= 0 ? (diff < pred) + 2 : diff >= -pred */ +- return ((diff ^ (diff >> (sizeof(diff)*8-1))) < pred) + 2*(diff >= 0); +-} +- +-static inline int encode_low(const struct G722Band* state, int xlow) +-{ +- int diff = av_clip_int16(xlow - state->s_predictor); +- /* = diff >= 0 ? diff : -(diff + 1) */ +- int limit = diff ^ (diff >> (sizeof(diff)*8-1)); +- int i = 0; +- limit = limit + 1 << 10; +- if (limit > low_quant[8] * state->scale_factor) +- i = 9; +- while (i < 29 && limit > low_quant[i] * state->scale_factor) +- i++; +- return (diff < 0 ? (i < 2 ? 63 : 33) : 61) - i; +-} +- +-static int g722_encode_trellis(AVCodecContext *avctx, +- uint8_t *dst, int buf_size, void *data) +-{ +- G722Context *c = avctx->priv_data; +- const int16_t *samples = data; +- int i, j, k; +- int frontier = 1 << avctx->trellis; +- struct TrellisNode **nodes[2]; +- struct TrellisNode **nodes_next[2]; +- int pathn[2] = {0, 0}, froze = -1; +- struct TrellisPath *p[2]; +- +- for (i = 0; i < 2; i++) { +- nodes[i] = c->nodep_buf[i]; +- nodes_next[i] = c->nodep_buf[i] + frontier; +- memset(c->nodep_buf[i], 0, 2 * frontier * sizeof(*c->nodep_buf)); +- nodes[i][0] = c->node_buf[i] + frontier; +- nodes[i][0]->ssd = 0; +- nodes[i][0]->path = 0; +- nodes[i][0]->state = c->band[i]; +- } +- +- for (i = 0; i < buf_size >> 1; i++) { +- int xlow, xhigh; +- struct TrellisNode *next[2]; +- int heap_pos[2] = {0, 0}; +- +- for (j = 0; j < 2; j++) { +- next[j] = c->node_buf[j] + frontier*(i & 1); +- memset(nodes_next[j], 0, frontier * sizeof(**nodes_next)); +- } +- +- filter_samples(c, &samples[2*i], &xlow, &xhigh); +- +- for (j = 0; j < frontier && nodes[0][j]; j++) { +- /* Only k >> 2 affects the future adaptive state, therefore testing +- * small steps that don't change k >> 2 is useless, the orignal +- * value from encode_low is better than them. Since we step k +- * in steps of 4, make sure range is a multiple of 4, so that +- * we don't miss the original value from encode_low. */ +- int range = j < frontier/2 ? 4 : 0; +- struct TrellisNode *cur_node = nodes[0][j]; +- +- int ilow = encode_low(&cur_node->state, xlow); +- +- for (k = ilow - range; k <= ilow + range && k <= 63; k += 4) { +- int decoded, dec_diff, pos; +- uint32_t ssd; +- struct TrellisNode* node; +- +- if (k < 0) +- continue; +- +- decoded = av_clip((cur_node->state.scale_factor * +- low_inv_quant6[k] >> 10) +- + cur_node->state.s_predictor, -16384, 16383); +- dec_diff = xlow - decoded; +- +-#define STORE_NODE(index, UPDATE, VALUE)\ +- ssd = cur_node->ssd + dec_diff*dec_diff;\ +- /* Check for wraparound. Using 64 bit ssd counters would \ +- * be simpler, but is slower on x86 32 bit. */\ +- if (ssd < cur_node->ssd)\ +- continue;\ +- if (heap_pos[index] < frontier) {\ +- pos = heap_pos[index]++;\ +- assert(pathn[index] < FREEZE_INTERVAL * frontier);\ +- node = nodes_next[index][pos] = next[index]++;\ +- node->path = pathn[index]++;\ +- } else {\ +- /* Try to replace one of the leaf nodes with the new \ +- * one, but not always testing the same leaf position */\ +- pos = (frontier>>1) + (heap_pos[index] & ((frontier>>1) - 1));\ +- if (ssd >= nodes_next[index][pos]->ssd)\ +- continue;\ +- heap_pos[index]++;\ +- node = nodes_next[index][pos];\ +- }\ +- node->ssd = ssd;\ +- node->state = cur_node->state;\ +- UPDATE;\ +- c->paths[index][node->path].value = VALUE;\ +- c->paths[index][node->path].prev = cur_node->path;\ +- /* Sift the newly inserted node up in the heap to restore \ +- * the heap property */\ +- while (pos > 0) {\ +- int parent = (pos - 1) >> 1;\ +- if (nodes_next[index][parent]->ssd <= ssd)\ +- break;\ +- FFSWAP(struct TrellisNode*, nodes_next[index][parent],\ +- nodes_next[index][pos]);\ +- pos = parent;\ +- } +- STORE_NODE(0, update_low_predictor(&node->state, k >> 2), k); +- } +- } +- +- for (j = 0; j < frontier && nodes[1][j]; j++) { +- int ihigh; +- struct TrellisNode *cur_node = nodes[1][j]; +- +- /* We don't try to get any initial guess for ihigh via +- * encode_high - since there's only 4 possible values, test +- * them all. Testing all of these gives a much, much larger +- * gain than testing a larger range around ilow. */ +- for (ihigh = 0; ihigh < 4; ihigh++) { +- int dhigh, decoded, dec_diff, pos; +- uint32_t ssd; +- struct TrellisNode* node; +- +- dhigh = cur_node->state.scale_factor * +- high_inv_quant[ihigh] >> 10; +- decoded = av_clip(dhigh + cur_node->state.s_predictor, +- -16384, 16383); +- dec_diff = xhigh - decoded; +- +- STORE_NODE(1, update_high_predictor(&node->state, dhigh, ihigh), ihigh); +- } +- } +- +- for (j = 0; j < 2; j++) { +- FFSWAP(struct TrellisNode**, nodes[j], nodes_next[j]); +- +- if (nodes[j][0]->ssd > (1 << 16)) { +- for (k = 1; k < frontier && nodes[j][k]; k++) +- nodes[j][k]->ssd -= nodes[j][0]->ssd; +- nodes[j][0]->ssd = 0; +- } +- } +- +- if (i == froze + FREEZE_INTERVAL) { +- p[0] = &c->paths[0][nodes[0][0]->path]; +- p[1] = &c->paths[1][nodes[1][0]->path]; +- for (j = i; j > froze; j--) { +- dst[j] = p[1]->value << 6 | p[0]->value; +- p[0] = &c->paths[0][p[0]->prev]; +- p[1] = &c->paths[1][p[1]->prev]; +- } +- froze = i; +- pathn[0] = pathn[1] = 0; +- memset(nodes[0] + 1, 0, (frontier - 1)*sizeof(**nodes)); +- memset(nodes[1] + 1, 0, (frontier - 1)*sizeof(**nodes)); +- } +- } +- +- p[0] = &c->paths[0][nodes[0][0]->path]; +- p[1] = &c->paths[1][nodes[1][0]->path]; +- for (j = i; j > froze; j--) { +- dst[j] = p[1]->value << 6 | p[0]->value; +- p[0] = &c->paths[0][p[0]->prev]; +- p[1] = &c->paths[1][p[1]->prev]; +- } +- c->band[0] = nodes[0][0]->state; +- c->band[1] = nodes[1][0]->state; +- +- return i; +-} +- +-static int g722_encode_frame(AVCodecContext *avctx, +- uint8_t *dst, int buf_size, void *data) +-{ +- G722Context *c = avctx->priv_data; +- const int16_t *samples = data; +- int i; +- +- if (avctx->trellis) +- return g722_encode_trellis(avctx, dst, buf_size, data); +- +- for (i = 0; i < buf_size >> 1; i++) { +- int xlow, xhigh, ihigh, ilow; +- filter_samples(c, &samples[2*i], &xlow, &xhigh); +- ihigh = encode_high(&c->band[1], xhigh); +- ilow = encode_low(&c->band[0], xlow); +- update_high_predictor(&c->band[1], c->band[1].scale_factor * +- high_inv_quant[ihigh] >> 10, ihigh); +- update_low_predictor(&c->band[0], ilow >> 2); +- *dst++ = ihigh << 6 | ilow; +- } +- return i; +-} +- +-AVCodec ff_adpcm_g722_encoder = { +- .name = "g722", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_ADPCM_G722, +- .priv_data_size = sizeof(G722Context), +- .init = g722_init, +- .close = g722_close, +- .encode = g722_encode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), +- .sample_fmts = (enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +-}; +-#endif +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722dec.c 2012-05-14 14:08:53.737327967 +0200 +@@ -0,0 +1,154 @@ ++/* ++ * Copyright (c) CMU 1993 Computer Science, Speech Group ++ * Chengxiang Lu and Alex Hauptmann ++ * Copyright (c) 2005 Steve Underwood ++ * Copyright (c) 2009 Kenan Gillet ++ * Copyright (c) 2010 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * G.722 ADPCM audio decoder ++ * ++ * This G.722 decoder is a bit-exact implementation of the ITU G.722 ++ * specification for all three specified bitrates - 64000bps, 56000bps ++ * and 48000bps. It passes the ITU tests. ++ * ++ * @note For the 56000bps and 48000bps bitrates, the lowest 1 or 2 bits ++ * respectively of each byte are ignored. ++ */ ++ ++#include "avcodec.h" ++#include "get_bits.h" ++#include "g722.h" ++#include "libavutil/opt.h" ++ ++#define OFFSET(x) offsetof(G722Context, x) ++#define AD AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "bits_per_codeword", "Bits per G722 codeword", OFFSET(bits_per_codeword), AV_OPT_TYPE_FLAGS, { 8 }, 6, 8, AD }, ++ { NULL } ++}; ++ ++static const AVClass g722_decoder_class = { ++ .class_name = "g722 decoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static av_cold int g722_decode_init(AVCodecContext * avctx) ++{ ++ G722Context *c = avctx->priv_data; ++ ++ if (avctx->channels != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ c->band[0].scale_factor = 8; ++ c->band[1].scale_factor = 2; ++ c->prev_samples_pos = 22; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ ++ return 0; ++} ++ ++static const int16_t low_inv_quant5[32] = { ++ -35, -35, -2919, -2195, -1765, -1458, -1219, -1023, ++ -858, -714, -587, -473, -370, -276, -190, -110, ++ 2919, 2195, 1765, 1458, 1219, 1023, 858, 714, ++ 587, 473, 370, 276, 190, 110, 35, -35 ++}; ++ ++static const int16_t *low_inv_quants[3] = { ff_g722_low_inv_quant6, ++ low_inv_quant5, ++ ff_g722_low_inv_quant4 }; ++ ++static int g722_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ G722Context *c = avctx->priv_data; ++ int16_t *out_buf; ++ int j, ret; ++ const int skip = 8 - c->bits_per_codeword; ++ const int16_t *quantizer_table = low_inv_quants[skip]; ++ GetBitContext gb; ++ ++ /* get output buffer */ ++ c->frame.nb_samples = avpkt->size * 2; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out_buf = (int16_t *)c->frame.data[0]; ++ ++ init_get_bits(&gb, avpkt->data, avpkt->size * 8); ++ ++ for (j = 0; j < avpkt->size; j++) { ++ int ilow, ihigh, rlow, rhigh, dhigh; ++ int xout1, xout2; ++ ++ ihigh = get_bits(&gb, 2); ++ ilow = get_bits(&gb, 6 - skip); ++ skip_bits(&gb, skip); ++ ++ rlow = av_clip((c->band[0].scale_factor * quantizer_table[ilow] >> 10) ++ + c->band[0].s_predictor, -16384, 16383); ++ ++ ff_g722_update_low_predictor(&c->band[0], ilow >> (2 - skip)); ++ ++ dhigh = c->band[1].scale_factor * ff_g722_high_inv_quant[ihigh] >> 10; ++ rhigh = av_clip(dhigh + c->band[1].s_predictor, -16384, 16383); ++ ++ ff_g722_update_high_predictor(&c->band[1], dhigh, ihigh); ++ ++ c->prev_samples[c->prev_samples_pos++] = rlow + rhigh; ++ c->prev_samples[c->prev_samples_pos++] = rlow - rhigh; ++ ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, ++ &xout1, &xout2); ++ *out_buf++ = av_clip_int16(xout1 >> 11); ++ *out_buf++ = av_clip_int16(xout2 >> 11); ++ if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { ++ memmove(c->prev_samples, c->prev_samples + c->prev_samples_pos - 22, ++ 22 * sizeof(c->prev_samples[0])); ++ c->prev_samples_pos = 22; ++ } ++ } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; ++ ++ return avpkt->size; ++} ++ ++AVCodec ff_adpcm_g722_decoder = { ++ .name = "g722", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_G722, ++ .priv_data_size = sizeof(G722Context), ++ .init = g722_decode_init, ++ .decode = g722_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), ++ .priv_class = &g722_decoder_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722enc.c 2012-05-14 14:08:53.739328007 +0200 +@@ -0,0 +1,374 @@ ++/* ++ * Copyright (c) CMU 1993 Computer Science, Speech Group ++ * Chengxiang Lu and Alex Hauptmann ++ * Copyright (c) 2005 Steve Underwood ++ * Copyright (c) 2009 Kenan Gillet ++ * Copyright (c) 2010 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * G.722 ADPCM audio encoder ++ */ ++ ++#include "avcodec.h" ++#include "g722.h" ++ ++#define FREEZE_INTERVAL 128 ++ ++/* This is an arbitrary value. Allowing insanely large values leads to strange ++ problems, so we limit it to a reasonable value */ ++#define MAX_FRAME_SIZE 32768 ++ ++/* We clip the value of avctx->trellis to prevent data type overflows and ++ undefined behavior. Using larger values is insanely slow anyway. */ ++#define MIN_TRELLIS 0 ++#define MAX_TRELLIS 16 ++ ++static av_cold int g722_encode_init(AVCodecContext * avctx) ++{ ++ G722Context *c = avctx->priv_data; ++ ++ if (avctx->channels != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Only mono tracks are allowed.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ c->band[0].scale_factor = 8; ++ c->band[1].scale_factor = 2; ++ c->prev_samples_pos = 22; ++ ++ if (avctx->trellis) { ++ int frontier = 1 << avctx->trellis; ++ int max_paths = frontier * FREEZE_INTERVAL; ++ int i; ++ for (i = 0; i < 2; i++) { ++ c->paths[i] = av_mallocz(max_paths * sizeof(**c->paths)); ++ c->node_buf[i] = av_mallocz(2 * frontier * sizeof(**c->node_buf)); ++ c->nodep_buf[i] = av_mallocz(2 * frontier * sizeof(**c->nodep_buf)); ++ } ++ } ++ ++ if (avctx->frame_size) { ++ /* validate frame size */ ++ if (avctx->frame_size & 1 || avctx->frame_size > MAX_FRAME_SIZE) { ++ int new_frame_size; ++ ++ if (avctx->frame_size == 1) ++ new_frame_size = 2; ++ else if (avctx->frame_size > MAX_FRAME_SIZE) ++ new_frame_size = MAX_FRAME_SIZE; ++ else ++ new_frame_size = avctx->frame_size - 1; ++ ++ av_log(avctx, AV_LOG_WARNING, "Requested frame size is not " ++ "allowed. Using %d instead of %d\n", new_frame_size, ++ avctx->frame_size); ++ avctx->frame_size = new_frame_size; ++ } ++ } else { ++ /* This is arbitrary. We use 320 because it's 20ms @ 16kHz, which is ++ a common packet size for VoIP applications */ ++ avctx->frame_size = 320; ++ } ++ ++ if (avctx->trellis) { ++ /* validate trellis */ ++ if (avctx->trellis < MIN_TRELLIS || avctx->trellis > MAX_TRELLIS) { ++ int new_trellis = av_clip(avctx->trellis, MIN_TRELLIS, MAX_TRELLIS); ++ av_log(avctx, AV_LOG_WARNING, "Requested trellis value is not " ++ "allowed. Using %d instead of %d\n", new_trellis, ++ avctx->trellis); ++ avctx->trellis = new_trellis; ++ } ++ } ++ ++ return 0; ++} ++ ++static av_cold int g722_encode_close(AVCodecContext *avctx) ++{ ++ G722Context *c = avctx->priv_data; ++ int i; ++ for (i = 0; i < 2; i++) { ++ av_freep(&c->paths[i]); ++ av_freep(&c->node_buf[i]); ++ av_freep(&c->nodep_buf[i]); ++ } ++ return 0; ++} ++ ++static const int16_t low_quant[33] = { ++ 35, 72, 110, 150, 190, 233, 276, 323, ++ 370, 422, 473, 530, 587, 650, 714, 786, ++ 858, 940, 1023, 1121, 1219, 1339, 1458, 1612, ++ 1765, 1980, 2195, 2557, 2919 ++}; ++ ++static inline void filter_samples(G722Context *c, const int16_t *samples, ++ int *xlow, int *xhigh) ++{ ++ int xout1, xout2; ++ c->prev_samples[c->prev_samples_pos++] = samples[0]; ++ c->prev_samples[c->prev_samples_pos++] = samples[1]; ++ ff_g722_apply_qmf(c->prev_samples + c->prev_samples_pos - 24, &xout1, &xout2); ++ *xlow = xout1 + xout2 >> 14; ++ *xhigh = xout1 - xout2 >> 14; ++ if (c->prev_samples_pos >= PREV_SAMPLES_BUF_SIZE) { ++ memmove(c->prev_samples, ++ c->prev_samples + c->prev_samples_pos - 22, ++ 22 * sizeof(c->prev_samples[0])); ++ c->prev_samples_pos = 22; ++ } ++} ++ ++static inline int encode_high(const struct G722Band *state, int xhigh) ++{ ++ int diff = av_clip_int16(xhigh - state->s_predictor); ++ int pred = 141 * state->scale_factor >> 8; ++ /* = diff >= 0 ? (diff < pred) + 2 : diff >= -pred */ ++ return ((diff ^ (diff >> (sizeof(diff)*8-1))) < pred) + 2*(diff >= 0); ++} ++ ++static inline int encode_low(const struct G722Band* state, int xlow) ++{ ++ int diff = av_clip_int16(xlow - state->s_predictor); ++ /* = diff >= 0 ? diff : -(diff + 1) */ ++ int limit = diff ^ (diff >> (sizeof(diff)*8-1)); ++ int i = 0; ++ limit = limit + 1 << 10; ++ if (limit > low_quant[8] * state->scale_factor) ++ i = 9; ++ while (i < 29 && limit > low_quant[i] * state->scale_factor) ++ i++; ++ return (diff < 0 ? (i < 2 ? 63 : 33) : 61) - i; ++} ++ ++static void g722_encode_trellis(G722Context *c, int trellis, ++ uint8_t *dst, int nb_samples, ++ const int16_t *samples) ++{ ++ int i, j, k; ++ int frontier = 1 << trellis; ++ struct TrellisNode **nodes[2]; ++ struct TrellisNode **nodes_next[2]; ++ int pathn[2] = {0, 0}, froze = -1; ++ struct TrellisPath *p[2]; ++ ++ for (i = 0; i < 2; i++) { ++ nodes[i] = c->nodep_buf[i]; ++ nodes_next[i] = c->nodep_buf[i] + frontier; ++ memset(c->nodep_buf[i], 0, 2 * frontier * sizeof(*c->nodep_buf)); ++ nodes[i][0] = c->node_buf[i] + frontier; ++ nodes[i][0]->ssd = 0; ++ nodes[i][0]->path = 0; ++ nodes[i][0]->state = c->band[i]; ++ } ++ ++ for (i = 0; i < nb_samples >> 1; i++) { ++ int xlow, xhigh; ++ struct TrellisNode *next[2]; ++ int heap_pos[2] = {0, 0}; ++ ++ for (j = 0; j < 2; j++) { ++ next[j] = c->node_buf[j] + frontier*(i & 1); ++ memset(nodes_next[j], 0, frontier * sizeof(**nodes_next)); ++ } ++ ++ filter_samples(c, &samples[2*i], &xlow, &xhigh); ++ ++ for (j = 0; j < frontier && nodes[0][j]; j++) { ++ /* Only k >> 2 affects the future adaptive state, therefore testing ++ * small steps that don't change k >> 2 is useless, the original ++ * value from encode_low is better than them. Since we step k ++ * in steps of 4, make sure range is a multiple of 4, so that ++ * we don't miss the original value from encode_low. */ ++ int range = j < frontier/2 ? 4 : 0; ++ struct TrellisNode *cur_node = nodes[0][j]; ++ ++ int ilow = encode_low(&cur_node->state, xlow); ++ ++ for (k = ilow - range; k <= ilow + range && k <= 63; k += 4) { ++ int decoded, dec_diff, pos; ++ uint32_t ssd; ++ struct TrellisNode* node; ++ ++ if (k < 0) ++ continue; ++ ++ decoded = av_clip((cur_node->state.scale_factor * ++ ff_g722_low_inv_quant6[k] >> 10) ++ + cur_node->state.s_predictor, -16384, 16383); ++ dec_diff = xlow - decoded; ++ ++#define STORE_NODE(index, UPDATE, VALUE)\ ++ ssd = cur_node->ssd + dec_diff*dec_diff;\ ++ /* Check for wraparound. Using 64 bit ssd counters would \ ++ * be simpler, but is slower on x86 32 bit. */\ ++ if (ssd < cur_node->ssd)\ ++ continue;\ ++ if (heap_pos[index] < frontier) {\ ++ pos = heap_pos[index]++;\ ++ assert(pathn[index] < FREEZE_INTERVAL * frontier);\ ++ node = nodes_next[index][pos] = next[index]++;\ ++ node->path = pathn[index]++;\ ++ } else {\ ++ /* Try to replace one of the leaf nodes with the new \ ++ * one, but not always testing the same leaf position */\ ++ pos = (frontier>>1) + (heap_pos[index] & ((frontier>>1) - 1));\ ++ if (ssd >= nodes_next[index][pos]->ssd)\ ++ continue;\ ++ heap_pos[index]++;\ ++ node = nodes_next[index][pos];\ ++ }\ ++ node->ssd = ssd;\ ++ node->state = cur_node->state;\ ++ UPDATE;\ ++ c->paths[index][node->path].value = VALUE;\ ++ c->paths[index][node->path].prev = cur_node->path;\ ++ /* Sift the newly inserted node up in the heap to restore \ ++ * the heap property */\ ++ while (pos > 0) {\ ++ int parent = (pos - 1) >> 1;\ ++ if (nodes_next[index][parent]->ssd <= ssd)\ ++ break;\ ++ FFSWAP(struct TrellisNode*, nodes_next[index][parent],\ ++ nodes_next[index][pos]);\ ++ pos = parent;\ ++ } ++ STORE_NODE(0, ff_g722_update_low_predictor(&node->state, k >> 2), k); ++ } ++ } ++ ++ for (j = 0; j < frontier && nodes[1][j]; j++) { ++ int ihigh; ++ struct TrellisNode *cur_node = nodes[1][j]; ++ ++ /* We don't try to get any initial guess for ihigh via ++ * encode_high - since there's only 4 possible values, test ++ * them all. Testing all of these gives a much, much larger ++ * gain than testing a larger range around ilow. */ ++ for (ihigh = 0; ihigh < 4; ihigh++) { ++ int dhigh, decoded, dec_diff, pos; ++ uint32_t ssd; ++ struct TrellisNode* node; ++ ++ dhigh = cur_node->state.scale_factor * ++ ff_g722_high_inv_quant[ihigh] >> 10; ++ decoded = av_clip(dhigh + cur_node->state.s_predictor, ++ -16384, 16383); ++ dec_diff = xhigh - decoded; ++ ++ STORE_NODE(1, ff_g722_update_high_predictor(&node->state, dhigh, ihigh), ihigh); ++ } ++ } ++ ++ for (j = 0; j < 2; j++) { ++ FFSWAP(struct TrellisNode**, nodes[j], nodes_next[j]); ++ ++ if (nodes[j][0]->ssd > (1 << 16)) { ++ for (k = 1; k < frontier && nodes[j][k]; k++) ++ nodes[j][k]->ssd -= nodes[j][0]->ssd; ++ nodes[j][0]->ssd = 0; ++ } ++ } ++ ++ if (i == froze + FREEZE_INTERVAL) { ++ p[0] = &c->paths[0][nodes[0][0]->path]; ++ p[1] = &c->paths[1][nodes[1][0]->path]; ++ for (j = i; j > froze; j--) { ++ dst[j] = p[1]->value << 6 | p[0]->value; ++ p[0] = &c->paths[0][p[0]->prev]; ++ p[1] = &c->paths[1][p[1]->prev]; ++ } ++ froze = i; ++ pathn[0] = pathn[1] = 0; ++ memset(nodes[0] + 1, 0, (frontier - 1)*sizeof(**nodes)); ++ memset(nodes[1] + 1, 0, (frontier - 1)*sizeof(**nodes)); ++ } ++ } ++ ++ p[0] = &c->paths[0][nodes[0][0]->path]; ++ p[1] = &c->paths[1][nodes[1][0]->path]; ++ for (j = i; j > froze; j--) { ++ dst[j] = p[1]->value << 6 | p[0]->value; ++ p[0] = &c->paths[0][p[0]->prev]; ++ p[1] = &c->paths[1][p[1]->prev]; ++ } ++ c->band[0] = nodes[0][0]->state; ++ c->band[1] = nodes[1][0]->state; ++} ++ ++static av_always_inline void encode_byte(G722Context *c, uint8_t *dst, ++ const int16_t *samples) ++{ ++ int xlow, xhigh, ilow, ihigh; ++ filter_samples(c, samples, &xlow, &xhigh); ++ ihigh = encode_high(&c->band[1], xhigh); ++ ilow = encode_low (&c->band[0], xlow); ++ ff_g722_update_high_predictor(&c->band[1], c->band[1].scale_factor * ++ ff_g722_high_inv_quant[ihigh] >> 10, ihigh); ++ ff_g722_update_low_predictor(&c->band[0], ilow >> 2); ++ *dst = ihigh << 6 | ilow; ++} ++ ++static void g722_encode_no_trellis(G722Context *c, ++ uint8_t *dst, int nb_samples, ++ const int16_t *samples) ++{ ++ int i; ++ for (i = 0; i < nb_samples; i += 2) ++ encode_byte(c, dst++, &samples[i]); ++} ++ ++static int g722_encode_frame(AVCodecContext *avctx, ++ uint8_t *dst, int buf_size, void *data) ++{ ++ G722Context *c = avctx->priv_data; ++ const int16_t *samples = data; ++ int nb_samples; ++ ++ nb_samples = avctx->frame_size - (avctx->frame_size & 1); ++ ++ if (avctx->trellis) ++ g722_encode_trellis(c, avctx->trellis, dst, nb_samples, samples); ++ else ++ g722_encode_no_trellis(c, dst, nb_samples, samples); ++ ++ /* handle last frame with odd frame_size */ ++ if (nb_samples < avctx->frame_size) { ++ int16_t last_samples[2] = { samples[nb_samples], samples[nb_samples] }; ++ encode_byte(c, &dst[nb_samples >> 1], last_samples); ++ } ++ ++ return (avctx->frame_size + 1) >> 1; ++} ++ ++AVCodec ff_adpcm_g722_encoder = { ++ .name = "g722", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_G722, ++ .priv_data_size = sizeof(G722Context), ++ .init = g722_encode_init, ++ .close = g722_encode_close, ++ .encode = g722_encode_frame, ++ .capabilities = CODEC_CAP_SMALL_LAST_FRAME, ++ .long_name = NULL_IF_CONFIG_SMALL("G.722 ADPCM"), ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g722.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g722.h 2012-05-14 14:08:53.737327967 +0200 +@@ -0,0 +1,78 @@ ++/* ++ * Copyright (c) CMU 1993 Computer Science, Speech Group ++ * Chengxiang Lu and Alex Hauptmann ++ * Copyright (c) 2005 Steve Underwood ++ * Copyright (c) 2009 Kenan Gillet ++ * Copyright (c) 2010 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_G722_H ++#define AVCODEC_G722_H ++ ++#include ++#include "avcodec.h" ++ ++#define PREV_SAMPLES_BUF_SIZE 1024 ++ ++typedef struct { ++ const AVClass *class; ++ AVFrame frame; ++ int bits_per_codeword; ++ int16_t prev_samples[PREV_SAMPLES_BUF_SIZE]; ///< memory of past decoded samples ++ int prev_samples_pos; ///< the number of values in prev_samples ++ ++ /** ++ * The band[0] and band[1] correspond respectively to the lower band and higher band. ++ */ ++ struct G722Band { ++ int16_t s_predictor; ///< predictor output value ++ int32_t s_zero; ///< previous output signal from zero predictor ++ int8_t part_reconst_mem[2]; ///< signs of previous partially reconstructed signals ++ int16_t prev_qtzd_reconst; ///< previous quantized reconstructed signal (internal value, using low_inv_quant4) ++ int16_t pole_mem[2]; ///< second-order pole section coefficient buffer ++ int32_t diff_mem[6]; ///< quantizer difference signal memory ++ int16_t zero_mem[6]; ///< Seventh-order zero section coefficient buffer ++ int16_t log_factor; ///< delayed 2-logarithmic quantizer factor ++ int16_t scale_factor; ///< delayed quantizer scale factor ++ } band[2]; ++ ++ struct TrellisNode { ++ struct G722Band state; ++ uint32_t ssd; ++ int path; ++ } *node_buf[2], **nodep_buf[2]; ++ ++ struct TrellisPath { ++ int value; ++ int prev; ++ } *paths[2]; ++} G722Context; ++ ++extern const int16_t ff_g722_high_inv_quant[4]; ++extern const int16_t ff_g722_low_inv_quant4[16]; ++extern const int16_t ff_g722_low_inv_quant6[64]; ++ ++void ff_g722_update_low_predictor(struct G722Band *band, const int ilow); ++ ++void ff_g722_update_high_predictor(struct G722Band *band, const int dhigh, ++ const int ihigh); ++ ++void ff_g722_apply_qmf(const int16_t *prev_samples, int *xout1, int *xout2); ++ ++#endif /* AVCODEC_G722_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g723_1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g723_1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g723_1.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g723_1.c 2012-05-14 14:08:53.744328107 +0200 +@@ -0,0 +1,2230 @@ ++/* ++ * G.723.1 compatible decoder ++ * Copyright (c) 2006 Benjamin Larsson ++ * Copyright (c) 2010 Mohamed Naufal Basheer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * G.723.1 compatible decoder ++ */ ++ ++#include "avcodec.h" ++#define BITSTREAM_READER_LE ++#include "get_bits.h" ++#include "acelp_vectors.h" ++#include "celp_filters.h" ++#include "celp_math.h" ++#include "lsp.h" ++#include "libavutil/lzo.h" ++#include "g723_1_data.h" ++ ++typedef struct g723_1_context { ++ AVFrame frame; ++ G723_1_Subframe subframe[4]; ++ FrameType cur_frame_type; ++ FrameType past_frame_type; ++ Rate cur_rate; ++ uint8_t lsp_index[LSP_BANDS]; ++ int pitch_lag[2]; ++ int erased_frames; ++ ++ int16_t prev_lsp[LPC_ORDER]; ++ int16_t prev_excitation[PITCH_MAX]; ++ int16_t excitation[PITCH_MAX + FRAME_LEN]; ++ int16_t synth_mem[LPC_ORDER]; ++ int16_t fir_mem[LPC_ORDER]; ++ int iir_mem[LPC_ORDER]; ++ ++ int random_seed; ++ int interp_index; ++ int interp_gain; ++ int sid_gain; ++ int cur_gain; ++ int reflection_coef; ++ int pf_gain; ///< formant postfilter ++ ///< gain scaling unit memory ++ ++ int16_t prev_data[HALF_FRAME_LEN]; ++ int16_t prev_weight_sig[PITCH_MAX]; ++ ++ ++ int16_t hpf_fir_mem; ///< highpass filter fir ++ int hpf_iir_mem; ///< and iir memories ++ int16_t perf_fir_mem[LPC_ORDER]; ///< perceptual filter fir ++ int16_t perf_iir_mem[LPC_ORDER]; ///< and iir memories ++ ++ int16_t harmonic_mem[PITCH_MAX]; ++} G723_1_Context; ++ ++static av_cold int g723_1_decode_init(AVCodecContext *avctx) ++{ ++ G723_1_Context *p = avctx->priv_data; ++ ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ p->pf_gain = 1 << 12; ++ memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t)); ++ ++ avcodec_get_frame_defaults(&p->frame); ++ avctx->coded_frame = &p->frame; ++ ++ return 0; ++} ++ ++/** ++ * Unpack the frame into parameters. ++ * ++ * @param p the context ++ * @param buf pointer to the input buffer ++ * @param buf_size size of the input buffer ++ */ ++static int unpack_bitstream(G723_1_Context *p, const uint8_t *buf, ++ int buf_size) ++{ ++ GetBitContext gb; ++ int ad_cb_len; ++ int temp, info_bits, i; ++ ++ init_get_bits(&gb, buf, buf_size * 8); ++ ++ /* Extract frame type and rate info */ ++ info_bits = get_bits(&gb, 2); ++ ++ if (info_bits == 3) { ++ p->cur_frame_type = UntransmittedFrame; ++ return 0; ++ } ++ ++ /* Extract 24 bit lsp indices, 8 bit for each band */ ++ p->lsp_index[2] = get_bits(&gb, 8); ++ p->lsp_index[1] = get_bits(&gb, 8); ++ p->lsp_index[0] = get_bits(&gb, 8); ++ ++ if (info_bits == 2) { ++ p->cur_frame_type = SIDFrame; ++ p->subframe[0].amp_index = get_bits(&gb, 6); ++ return 0; ++ } ++ ++ /* Extract the info common to both rates */ ++ p->cur_rate = info_bits ? Rate5k3 : Rate6k3; ++ p->cur_frame_type = ActiveFrame; ++ ++ p->pitch_lag[0] = get_bits(&gb, 7); ++ if (p->pitch_lag[0] > 123) /* test if forbidden code */ ++ return -1; ++ p->pitch_lag[0] += PITCH_MIN; ++ p->subframe[1].ad_cb_lag = get_bits(&gb, 2); ++ ++ p->pitch_lag[1] = get_bits(&gb, 7); ++ if (p->pitch_lag[1] > 123) ++ return -1; ++ p->pitch_lag[1] += PITCH_MIN; ++ p->subframe[3].ad_cb_lag = get_bits(&gb, 2); ++ p->subframe[0].ad_cb_lag = 1; ++ p->subframe[2].ad_cb_lag = 1; ++ ++ for (i = 0; i < SUBFRAMES; i++) { ++ /* Extract combined gain */ ++ temp = get_bits(&gb, 12); ++ ad_cb_len = 170; ++ p->subframe[i].dirac_train = 0; ++ if (p->cur_rate == Rate6k3 && p->pitch_lag[i >> 1] < SUBFRAME_LEN - 2) { ++ p->subframe[i].dirac_train = temp >> 11; ++ temp &= 0x7ff; ++ ad_cb_len = 85; ++ } ++ p->subframe[i].ad_cb_gain = FASTDIV(temp, GAIN_LEVELS); ++ if (p->subframe[i].ad_cb_gain < ad_cb_len) { ++ p->subframe[i].amp_index = temp - p->subframe[i].ad_cb_gain * ++ GAIN_LEVELS; ++ } else { ++ return -1; ++ } ++ } ++ ++ p->subframe[0].grid_index = get_bits1(&gb); ++ p->subframe[1].grid_index = get_bits1(&gb); ++ p->subframe[2].grid_index = get_bits1(&gb); ++ p->subframe[3].grid_index = get_bits1(&gb); ++ ++ if (p->cur_rate == Rate6k3) { ++ skip_bits1(&gb); /* skip reserved bit */ ++ ++ /* Compute pulse_pos index using the 13-bit combined position index */ ++ temp = get_bits(&gb, 13); ++ p->subframe[0].pulse_pos = temp / 810; ++ ++ temp -= p->subframe[0].pulse_pos * 810; ++ p->subframe[1].pulse_pos = FASTDIV(temp, 90); ++ ++ temp -= p->subframe[1].pulse_pos * 90; ++ p->subframe[2].pulse_pos = FASTDIV(temp, 9); ++ p->subframe[3].pulse_pos = temp - p->subframe[2].pulse_pos * 9; ++ ++ p->subframe[0].pulse_pos = (p->subframe[0].pulse_pos << 16) + ++ get_bits(&gb, 16); ++ p->subframe[1].pulse_pos = (p->subframe[1].pulse_pos << 14) + ++ get_bits(&gb, 14); ++ p->subframe[2].pulse_pos = (p->subframe[2].pulse_pos << 16) + ++ get_bits(&gb, 16); ++ p->subframe[3].pulse_pos = (p->subframe[3].pulse_pos << 14) + ++ get_bits(&gb, 14); ++ ++ p->subframe[0].pulse_sign = get_bits(&gb, 6); ++ p->subframe[1].pulse_sign = get_bits(&gb, 5); ++ p->subframe[2].pulse_sign = get_bits(&gb, 6); ++ p->subframe[3].pulse_sign = get_bits(&gb, 5); ++ } else { /* Rate5k3 */ ++ p->subframe[0].pulse_pos = get_bits(&gb, 12); ++ p->subframe[1].pulse_pos = get_bits(&gb, 12); ++ p->subframe[2].pulse_pos = get_bits(&gb, 12); ++ p->subframe[3].pulse_pos = get_bits(&gb, 12); ++ ++ p->subframe[0].pulse_sign = get_bits(&gb, 4); ++ p->subframe[1].pulse_sign = get_bits(&gb, 4); ++ p->subframe[2].pulse_sign = get_bits(&gb, 4); ++ p->subframe[3].pulse_sign = get_bits(&gb, 4); ++ } ++ ++ return 0; ++} ++ ++/** ++ * Bitexact implementation of sqrt(val/2). ++ */ ++static int16_t square_root(int val) ++{ ++ return (ff_sqrt(val << 1) >> 1) & (~1); ++} ++ ++/** ++ * Calculate the number of left-shifts required for normalizing the input. ++ * ++ * @param num input number ++ * @param width width of the input, 16 bits(0) / 32 bits(1) ++ */ ++static int normalize_bits(int num, int width) ++{ ++ int i = 0; ++ int bits = (width) ? 31 : 15; ++ ++ if (num) { ++ if (num == -1) ++ return bits; ++ if (num < 0) ++ num = ~num; ++ i= bits - av_log2(num) - 1; ++ i= FFMAX(i, 0); ++ } ++ return i; ++} ++ ++#define normalize_bits_int16(num) normalize_bits(num, 0) ++#define normalize_bits_int32(num) normalize_bits(num, 1) ++#define dot_product(a,b,c,d) (ff_dot_product(a,b,c)<<(d)) ++ ++/** ++ * Scale vector contents based on the largest of their absolutes. ++ */ ++static int scale_vector(int16_t *vector, int length) ++{ ++ int bits, scale, max = 0; ++ int i; ++ ++ const int16_t shift_table[16] = { ++ 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080, ++ 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000, 0x7fff ++ }; ++ ++ for (i = 0; i < length; i++) ++ max = FFMAX(max, FFABS(vector[i])); ++ ++ bits = normalize_bits(max, 0); ++ scale = shift_table[bits]; ++ ++ for (i = 0; i < length; i++) ++ vector[i] = (vector[i] * scale) >> 3; ++ ++ return bits - 3; ++} ++ ++/** ++ * Perform inverse quantization of LSP frequencies. ++ * ++ * @param cur_lsp the current LSP vector ++ * @param prev_lsp the previous LSP vector ++ * @param lsp_index VQ indices ++ * @param bad_frame bad frame flag ++ */ ++static void inverse_quant(int16_t *cur_lsp, int16_t *prev_lsp, ++ uint8_t *lsp_index, int bad_frame) ++{ ++ int min_dist, pred; ++ int i, j, temp, stable; ++ ++ /* Check for frame erasure */ ++ if (!bad_frame) { ++ min_dist = 0x100; ++ pred = 12288; ++ } else { ++ min_dist = 0x200; ++ pred = 23552; ++ lsp_index[0] = lsp_index[1] = lsp_index[2] = 0; ++ } ++ ++ /* Get the VQ table entry corresponding to the transmitted index */ ++ cur_lsp[0] = lsp_band0[lsp_index[0]][0]; ++ cur_lsp[1] = lsp_band0[lsp_index[0]][1]; ++ cur_lsp[2] = lsp_band0[lsp_index[0]][2]; ++ cur_lsp[3] = lsp_band1[lsp_index[1]][0]; ++ cur_lsp[4] = lsp_band1[lsp_index[1]][1]; ++ cur_lsp[5] = lsp_band1[lsp_index[1]][2]; ++ cur_lsp[6] = lsp_band2[lsp_index[2]][0]; ++ cur_lsp[7] = lsp_band2[lsp_index[2]][1]; ++ cur_lsp[8] = lsp_band2[lsp_index[2]][2]; ++ cur_lsp[9] = lsp_band2[lsp_index[2]][3]; ++ ++ /* Add predicted vector & DC component to the previously quantized vector */ ++ for (i = 0; i < LPC_ORDER; i++) { ++ temp = ((prev_lsp[i] - dc_lsp[i]) * pred + (1 << 14)) >> 15; ++ cur_lsp[i] += dc_lsp[i] + temp; ++ } ++ ++ for (i = 0; i < LPC_ORDER; i++) { ++ cur_lsp[0] = FFMAX(cur_lsp[0], 0x180); ++ cur_lsp[LPC_ORDER - 1] = FFMIN(cur_lsp[LPC_ORDER - 1], 0x7e00); ++ ++ /* Stability check */ ++ for (j = 1; j < LPC_ORDER; j++) { ++ temp = min_dist + cur_lsp[j - 1] - cur_lsp[j]; ++ if (temp > 0) { ++ temp >>= 1; ++ cur_lsp[j - 1] -= temp; ++ cur_lsp[j] += temp; ++ } ++ } ++ stable = 1; ++ for (j = 1; j < LPC_ORDER; j++) { ++ temp = cur_lsp[j - 1] + min_dist - cur_lsp[j] - 4; ++ if (temp > 0) { ++ stable = 0; ++ break; ++ } ++ } ++ if (stable) ++ break; ++ } ++ if (!stable) ++ memcpy(cur_lsp, prev_lsp, LPC_ORDER * sizeof(int16_t)); ++} ++ ++/** ++ * Bitexact implementation of 2ab scaled by 1/2^16. ++ * ++ * @param a 32 bit multiplicand ++ * @param b 16 bit multiplier ++ */ ++#define MULL2(a, b) \ ++ MULL(a,b,15) ++ ++/** ++ * Convert LSP frequencies to LPC coefficients. ++ * ++ * @param lpc buffer for LPC coefficients ++ */ ++static void lsp2lpc(int16_t *lpc) ++{ ++ int f1[LPC_ORDER / 2 + 1]; ++ int f2[LPC_ORDER / 2 + 1]; ++ int i, j; ++ ++ /* Calculate negative cosine */ ++ for (j = 0; j < LPC_ORDER; j++) { ++ int index = lpc[j] >> 7; ++ int offset = lpc[j] & 0x7f; ++ int64_t temp1 = cos_tab[index] << 16; ++ int temp2 = (cos_tab[index + 1] - cos_tab[index]) * ++ ((offset << 8) + 0x80) << 1; ++ ++ lpc[j] = -(av_clipl_int32(((temp1 + temp2) << 1) + (1 << 15)) >> 16); ++ } ++ ++ /* ++ * Compute sum and difference polynomial coefficients ++ * (bitexact alternative to lsp2poly() in lsp.c) ++ */ ++ /* Initialize with values in Q28 */ ++ f1[0] = 1 << 28; ++ f1[1] = (lpc[0] << 14) + (lpc[2] << 14); ++ f1[2] = lpc[0] * lpc[2] + (2 << 28); ++ ++ f2[0] = 1 << 28; ++ f2[1] = (lpc[1] << 14) + (lpc[3] << 14); ++ f2[2] = lpc[1] * lpc[3] + (2 << 28); ++ ++ /* ++ * Calculate and scale the coefficients by 1/2 in ++ * each iteration for a final scaling factor of Q25 ++ */ ++ for (i = 2; i < LPC_ORDER / 2; i++) { ++ f1[i + 1] = f1[i - 1] + MULL2(f1[i], lpc[2 * i]); ++ f2[i + 1] = f2[i - 1] + MULL2(f2[i], lpc[2 * i + 1]); ++ ++ for (j = i; j >= 2; j--) { ++ f1[j] = MULL2(f1[j - 1], lpc[2 * i]) + ++ (f1[j] >> 1) + (f1[j - 2] >> 1); ++ f2[j] = MULL2(f2[j - 1], lpc[2 * i + 1]) + ++ (f2[j] >> 1) + (f2[j - 2] >> 1); ++ } ++ ++ f1[0] >>= 1; ++ f2[0] >>= 1; ++ f1[1] = ((lpc[2 * i] << 16 >> i) + f1[1]) >> 1; ++ f2[1] = ((lpc[2 * i + 1] << 16 >> i) + f2[1]) >> 1; ++ } ++ ++ /* Convert polynomial coefficients to LPC coefficients */ ++ for (i = 0; i < LPC_ORDER / 2; i++) { ++ int64_t ff1 = f1[i + 1] + f1[i]; ++ int64_t ff2 = f2[i + 1] - f2[i]; ++ ++ lpc[i] = av_clipl_int32(((ff1 + ff2) << 3) + (1 << 15)) >> 16; ++ lpc[LPC_ORDER - i - 1] = av_clipl_int32(((ff1 - ff2) << 3) + ++ (1 << 15)) >> 16; ++ } ++} ++ ++/** ++ * Quantize LSP frequencies by interpolation and convert them to ++ * the corresponding LPC coefficients. ++ * ++ * @param lpc buffer for LPC coefficients ++ * @param cur_lsp the current LSP vector ++ * @param prev_lsp the previous LSP vector ++ */ ++static void lsp_interpolate(int16_t *lpc, int16_t *cur_lsp, int16_t *prev_lsp) ++{ ++ int i; ++ int16_t *lpc_ptr = lpc; ++ ++ /* cur_lsp * 0.25 + prev_lsp * 0.75 */ ++ ff_acelp_weighted_vector_sum(lpc, cur_lsp, prev_lsp, ++ 4096, 12288, 1 << 13, 14, LPC_ORDER); ++ ff_acelp_weighted_vector_sum(lpc + LPC_ORDER, cur_lsp, prev_lsp, ++ 8192, 8192, 1 << 13, 14, LPC_ORDER); ++ ff_acelp_weighted_vector_sum(lpc + 2 * LPC_ORDER, cur_lsp, prev_lsp, ++ 12288, 4096, 1 << 13, 14, LPC_ORDER); ++ memcpy(lpc + 3 * LPC_ORDER, cur_lsp, LPC_ORDER * sizeof(int16_t)); ++ ++ for (i = 0; i < SUBFRAMES; i++) { ++ lsp2lpc(lpc_ptr); ++ lpc_ptr += LPC_ORDER; ++ } ++} ++ ++/** ++ * Generate a train of dirac functions with period as pitch lag. ++ */ ++static void gen_dirac_train(int16_t *buf, int pitch_lag) ++{ ++ int16_t vector[SUBFRAME_LEN]; ++ int i, j; ++ ++ memcpy(vector, buf, SUBFRAME_LEN * sizeof(int16_t)); ++ for (i = pitch_lag; i < SUBFRAME_LEN; i += pitch_lag) { ++ for (j = 0; j < SUBFRAME_LEN - i; j++) ++ buf[i + j] += vector[j]; ++ } ++} ++ ++/** ++ * Generate fixed codebook excitation vector. ++ * ++ * @param vector decoded excitation vector ++ * @param subfrm current subframe ++ * @param cur_rate current bitrate ++ * @param pitch_lag closed loop pitch lag ++ * @param index current subframe index ++ */ ++static void gen_fcb_excitation(int16_t *vector, G723_1_Subframe subfrm, ++ Rate cur_rate, int pitch_lag, int index) ++{ ++ int temp, i, j; ++ ++ memset(vector, 0, SUBFRAME_LEN * sizeof(int16_t)); ++ ++ if (cur_rate == Rate6k3) { ++ if (subfrm.pulse_pos >= max_pos[index]) ++ return; ++ ++ /* Decode amplitudes and positions */ ++ j = PULSE_MAX - pulses[index]; ++ temp = subfrm.pulse_pos; ++ for (i = 0; i < SUBFRAME_LEN / GRID_SIZE; i++) { ++ temp -= combinatorial_table[j][i]; ++ if (temp >= 0) ++ continue; ++ temp += combinatorial_table[j++][i]; ++ if (subfrm.pulse_sign & (1 << (PULSE_MAX - j))) { ++ vector[subfrm.grid_index + GRID_SIZE * i] = ++ -fixed_cb_gain[subfrm.amp_index]; ++ } else { ++ vector[subfrm.grid_index + GRID_SIZE * i] = ++ fixed_cb_gain[subfrm.amp_index]; ++ } ++ if (j == PULSE_MAX) ++ break; ++ } ++ if (subfrm.dirac_train == 1) ++ gen_dirac_train(vector, pitch_lag); ++ } else { /* Rate5k3 */ ++ int cb_gain = fixed_cb_gain[subfrm.amp_index]; ++ int cb_shift = subfrm.grid_index; ++ int cb_sign = subfrm.pulse_sign; ++ int cb_pos = subfrm.pulse_pos; ++ int offset, beta, lag; ++ ++ for (i = 0; i < 8; i += 2) { ++ offset = ((cb_pos & 7) << 3) + cb_shift + i; ++ vector[offset] = (cb_sign & 1) ? cb_gain : -cb_gain; ++ cb_pos >>= 3; ++ cb_sign >>= 1; ++ } ++ ++ /* Enhance harmonic components */ ++ lag = pitch_contrib[subfrm.ad_cb_gain << 1] + pitch_lag + ++ subfrm.ad_cb_lag - 1; ++ beta = pitch_contrib[(subfrm.ad_cb_gain << 1) + 1]; ++ ++ if (lag < SUBFRAME_LEN - 2) { ++ for (i = lag; i < SUBFRAME_LEN; i++) ++ vector[i] += beta * vector[i - lag] >> 15; ++ } ++ } ++} ++ ++/** ++ * Get delayed contribution from the previous excitation vector. ++ */ ++static void get_residual(int16_t *residual, int16_t *prev_excitation, int lag) ++{ ++ int offset = PITCH_MAX - PITCH_ORDER / 2 - lag; ++ int i; ++ ++ residual[0] = prev_excitation[offset]; ++ residual[1] = prev_excitation[offset + 1]; ++ ++ offset += 2; ++ for (i = 2; i < SUBFRAME_LEN + PITCH_ORDER - 1; i++) ++ residual[i] = prev_excitation[offset + (i - 2) % lag]; ++} ++ ++/** ++ * Generate adaptive codebook excitation. ++ */ ++static void gen_acb_excitation(int16_t *vector, int16_t *prev_excitation, ++ int pitch_lag, G723_1_Subframe subfrm, ++ Rate cur_rate) ++{ ++ int16_t residual[SUBFRAME_LEN + PITCH_ORDER - 1]; ++ const int16_t *cb_ptr; ++ int lag = pitch_lag + subfrm.ad_cb_lag - 1; ++ ++ int i; ++ int64_t sum; ++ ++ get_residual(residual, prev_excitation, lag); ++ ++ /* Select quantization table */ ++ if (cur_rate == Rate6k3 && pitch_lag < SUBFRAME_LEN - 2) { ++ cb_ptr = adaptive_cb_gain85; ++ } else ++ cb_ptr = adaptive_cb_gain170; ++ ++ /* Calculate adaptive vector */ ++ cb_ptr += subfrm.ad_cb_gain * 20; ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ sum = ff_dot_product(residual + i, cb_ptr, PITCH_ORDER); ++ vector[i] = av_clipl_int32((sum << 2) + (1 << 15)) >> 16; ++ } ++} ++ ++/** ++ * Estimate maximum auto-correlation around pitch lag. ++ * ++ * @param p the context ++ * @param offset offset of the excitation vector ++ * @param ccr_max pointer to the maximum auto-correlation ++ * @param pitch_lag decoded pitch lag ++ * @param length length of autocorrelation ++ * @param dir forward lag(1) / backward lag(-1) ++ */ ++static int autocorr_max(G723_1_Context *p, int offset, int *ccr_max, ++ int pitch_lag, int length, int dir) ++{ ++ int limit, ccr, lag = 0; ++ int16_t *buf = p->excitation + offset; ++ int i; ++ ++ pitch_lag = FFMIN(PITCH_MAX - 3, pitch_lag); ++ limit = FFMIN(FRAME_LEN + PITCH_MAX - offset - length, pitch_lag + 3); ++ ++ for (i = pitch_lag - 3; i <= limit; i++) { ++ ccr = ff_dot_product(buf, buf + dir * i, length)<<1; ++ ++ if (ccr > *ccr_max) { ++ *ccr_max = ccr; ++ lag = i; ++ } ++ } ++ return lag; ++} ++ ++/** ++ * Calculate pitch postfilter optimal and scaling gains. ++ * ++ * @param lag pitch postfilter forward/backward lag ++ * @param ppf pitch postfilter parameters ++ * @param cur_rate current bitrate ++ * @param tgt_eng target energy ++ * @param ccr cross-correlation ++ * @param res_eng residual energy ++ */ ++static void comp_ppf_gains(int lag, PPFParam *ppf, Rate cur_rate, ++ int tgt_eng, int ccr, int res_eng) ++{ ++ int pf_residual; /* square of postfiltered residual */ ++ int64_t temp1, temp2; ++ ++ ppf->index = lag; ++ ++ temp1 = tgt_eng * res_eng >> 1; ++ temp2 = ccr * ccr << 1; ++ ++ if (temp2 > temp1) { ++ if (ccr >= res_eng) { ++ ppf->opt_gain = ppf_gain_weight[cur_rate]; ++ } else { ++ ppf->opt_gain = (ccr << 15) / res_eng * ++ ppf_gain_weight[cur_rate] >> 15; ++ } ++ /* pf_res^2 = tgt_eng + 2*ccr*gain + res_eng*gain^2 */ ++ temp1 = (tgt_eng << 15) + (ccr * ppf->opt_gain << 1); ++ temp2 = (ppf->opt_gain * ppf->opt_gain >> 15) * res_eng; ++ pf_residual = av_clipl_int32(temp1 + temp2 + (1 << 15)) >> 16; ++ ++ if (tgt_eng >= pf_residual << 1) { ++ temp1 = 0x7fff; ++ } else { ++ temp1 = (tgt_eng << 14) / pf_residual; ++ } ++ ++ /* scaling_gain = sqrt(tgt_eng/pf_res^2) */ ++ ppf->sc_gain = square_root(temp1 << 16); ++ } else { ++ ppf->opt_gain = 0; ++ ppf->sc_gain = 0x7fff; ++ } ++ ++ ppf->opt_gain = av_clip_int16(ppf->opt_gain * ppf->sc_gain >> 15); ++} ++ ++/** ++ * Calculate pitch postfilter parameters. ++ * ++ * @param p the context ++ * @param offset offset of the excitation vector ++ * @param pitch_lag decoded pitch lag ++ * @param ppf pitch postfilter parameters ++ * @param cur_rate current bitrate ++ */ ++static void comp_ppf_coeff(G723_1_Context *p, int offset, int pitch_lag, ++ PPFParam *ppf, Rate cur_rate) ++{ ++ ++ int16_t scale; ++ int i; ++ int64_t temp1, temp2; ++ ++ /* ++ * 0 - target energy ++ * 1 - forward cross-correlation ++ * 2 - forward residual energy ++ * 3 - backward cross-correlation ++ * 4 - backward residual energy ++ */ ++ int energy[5] = {0, 0, 0, 0, 0}; ++ int16_t *buf = p->excitation + offset; ++ int fwd_lag = autocorr_max(p, offset, &energy[1], pitch_lag, ++ SUBFRAME_LEN, 1); ++ int back_lag = autocorr_max(p, offset, &energy[3], pitch_lag, ++ SUBFRAME_LEN, -1); ++ ++ ppf->index = 0; ++ ppf->opt_gain = 0; ++ ppf->sc_gain = 0x7fff; ++ ++ /* Case 0, Section 3.6 */ ++ if (!back_lag && !fwd_lag) ++ return; ++ ++ /* Compute target energy */ ++ energy[0] = ff_dot_product(buf, buf, SUBFRAME_LEN)<<1; ++ ++ /* Compute forward residual energy */ ++ if (fwd_lag) ++ energy[2] = ff_dot_product(buf + fwd_lag, buf + fwd_lag, ++ SUBFRAME_LEN)<<1; ++ ++ /* Compute backward residual energy */ ++ if (back_lag) ++ energy[4] = ff_dot_product(buf - back_lag, buf - back_lag, ++ SUBFRAME_LEN)<<1; ++ ++ /* Normalize and shorten */ ++ temp1 = 0; ++ for (i = 0; i < 5; i++) ++ temp1 = FFMAX(energy[i], temp1); ++ ++ scale = normalize_bits(temp1, 1); ++ for (i = 0; i < 5; i++) ++ energy[i] = av_clipl_int32(energy[i] << scale) >> 16; ++ ++ if (fwd_lag && !back_lag) { /* Case 1 */ ++ comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1], ++ energy[2]); ++ } else if (!fwd_lag) { /* Case 2 */ ++ comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3], ++ energy[4]); ++ } else { /* Case 3 */ ++ ++ /* ++ * Select the largest of energy[1]^2/energy[2] ++ * and energy[3]^2/energy[4] ++ */ ++ temp1 = energy[4] * ((energy[1] * energy[1] + (1 << 14)) >> 15); ++ temp2 = energy[2] * ((energy[3] * energy[3] + (1 << 14)) >> 15); ++ if (temp1 >= temp2) { ++ comp_ppf_gains(fwd_lag, ppf, cur_rate, energy[0], energy[1], ++ energy[2]); ++ } else { ++ comp_ppf_gains(-back_lag, ppf, cur_rate, energy[0], energy[3], ++ energy[4]); ++ } ++ } ++} ++ ++/** ++ * Classify frames as voiced/unvoiced. ++ * ++ * @param p the context ++ * @param pitch_lag decoded pitch_lag ++ * @param exc_eng excitation energy estimation ++ * @param scale scaling factor of exc_eng ++ * ++ * @return residual interpolation index if voiced, 0 otherwise ++ */ ++static int comp_interp_index(G723_1_Context *p, int pitch_lag, ++ int *exc_eng, int *scale) ++{ ++ int offset = PITCH_MAX + 2 * SUBFRAME_LEN; ++ int16_t *buf = p->excitation + offset; ++ ++ int index, ccr, tgt_eng, best_eng, temp; ++ ++ *scale = scale_vector(p->excitation, FRAME_LEN + PITCH_MAX); ++ ++ /* Compute maximum backward cross-correlation */ ++ ccr = 0; ++ index = autocorr_max(p, offset, &ccr, pitch_lag, SUBFRAME_LEN * 2, -1); ++ ccr = av_clipl_int32((int64_t)ccr + (1 << 15)) >> 16; ++ ++ /* Compute target energy */ ++ tgt_eng = ff_dot_product(buf, buf, SUBFRAME_LEN * 2)<<1; ++ *exc_eng = av_clipl_int32(tgt_eng + (1 << 15)) >> 16; ++ ++ if (ccr <= 0) ++ return 0; ++ ++ /* Compute best energy */ ++ best_eng = ff_dot_product(buf - index, buf - index, ++ SUBFRAME_LEN * 2)<<1; ++ best_eng = av_clipl_int32((int64_t)best_eng + (1 << 15)) >> 16; ++ ++ temp = best_eng * *exc_eng >> 3; ++ ++ if (temp < ccr * ccr) { ++ return index; ++ } else ++ return 0; ++} ++ ++/** ++ * Peform residual interpolation based on frame classification. ++ * ++ * @param buf decoded excitation vector ++ * @param out output vector ++ * @param lag decoded pitch lag ++ * @param gain interpolated gain ++ * @param rseed seed for random number generator ++ */ ++static void residual_interp(int16_t *buf, int16_t *out, int lag, ++ int gain, int *rseed) ++{ ++ int i; ++ if (lag) { /* Voiced */ ++ int16_t *vector_ptr = buf + PITCH_MAX; ++ /* Attenuate */ ++ for (i = 0; i < lag; i++) ++ vector_ptr[i - lag] = vector_ptr[i - lag] * 3 >> 2; ++ av_memcpy_backptr((uint8_t*)vector_ptr, lag * sizeof(int16_t), ++ FRAME_LEN * sizeof(int16_t)); ++ memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t)); ++ } else { /* Unvoiced */ ++ for (i = 0; i < FRAME_LEN; i++) { ++ *rseed = *rseed * 521 + 259; ++ out[i] = gain * *rseed >> 15; ++ } ++ memset(buf, 0, (FRAME_LEN + PITCH_MAX) * sizeof(int16_t)); ++ } ++} ++ ++/** ++ * Perform IIR filtering. ++ * ++ * @param fir_coef FIR coefficients ++ * @param iir_coef IIR coefficients ++ * @param src source vector ++ * @param dest destination vector ++ * @param width width of the output, 16 bits(0) / 32 bits(1) ++ */ ++#define iir_filter(fir_coef, iir_coef, src, dest, width)\ ++{\ ++ int m, n;\ ++ int res_shift = 16 & ~-(width);\ ++ int in_shift = 16 - res_shift;\ ++\ ++ for (m = 0; m < SUBFRAME_LEN; m++) {\ ++ int64_t filter = 0;\ ++ for (n = 1; n <= LPC_ORDER; n++) {\ ++ filter -= (fir_coef)[n - 1] * (src)[m - n] -\ ++ (iir_coef)[n - 1] * ((dest)[m - n] >> in_shift);\ ++ }\ ++\ ++ (dest)[m] = av_clipl_int32(((src)[m] << 16) + (filter << 3) +\ ++ (1 << 15)) >> res_shift;\ ++ }\ ++} ++ ++/** ++ * Adjust gain of postfiltered signal. ++ * ++ * @param p the context ++ * @param buf postfiltered output vector ++ * @param energy input energy coefficient ++ */ ++static void gain_scale(G723_1_Context *p, int16_t * buf, int energy) ++{ ++ int num, denom, gain, bits1, bits2; ++ int i; ++ ++ num = energy; ++ denom = 0; ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t temp = buf[i] >> 2; ++ temp = av_clipl_int32(MUL64(temp, temp) << 1); ++ denom = av_clipl_int32(denom + temp); ++ } ++ ++ if (num && denom) { ++ bits1 = normalize_bits(num, 1); ++ bits2 = normalize_bits(denom, 1); ++ num = num << bits1 >> 1; ++ denom <<= bits2; ++ ++ bits2 = 5 + bits1 - bits2; ++ bits2 = FFMAX(0, bits2); ++ ++ gain = (num >> 1) / (denom >> 16); ++ gain = square_root(gain << 16 >> bits2); ++ } else { ++ gain = 1 << 12; ++ } ++ ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ p->pf_gain = ((p->pf_gain << 4) - p->pf_gain + gain + (1 << 3)) >> 4; ++ buf[i] = av_clip_int16((buf[i] * (p->pf_gain + (p->pf_gain >> 4)) + ++ (1 << 10)) >> 11); ++ } ++} ++ ++/** ++ * Perform formant filtering. ++ * ++ * @param p the context ++ * @param lpc quantized lpc coefficients ++ * @param buf output buffer ++ */ ++static void formant_postfilter(G723_1_Context *p, int16_t *lpc, int16_t *buf) ++{ ++ int16_t filter_coef[2][LPC_ORDER], *buf_ptr; ++ int filter_signal[LPC_ORDER + FRAME_LEN], *signal_ptr; ++ int i, j, k; ++ ++ memcpy(buf, p->fir_mem, LPC_ORDER * sizeof(int16_t)); ++ memcpy(filter_signal, p->iir_mem, LPC_ORDER * sizeof(int)); ++ ++ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) { ++ for (k = 0; k < LPC_ORDER; k++) { ++ filter_coef[0][k] = (-lpc[k] * postfilter_tbl[0][k] + ++ (1 << 14)) >> 15; ++ filter_coef[1][k] = (-lpc[k] * postfilter_tbl[1][k] + ++ (1 << 14)) >> 15; ++ } ++ iir_filter(filter_coef[0], filter_coef[1], buf + i, ++ filter_signal + i, 1); ++ } ++ ++ memcpy(p->fir_mem, buf + FRAME_LEN, LPC_ORDER * sizeof(int16_t)); ++ memcpy(p->iir_mem, filter_signal + FRAME_LEN, LPC_ORDER * sizeof(int)); ++ ++ buf_ptr = buf + LPC_ORDER; ++ signal_ptr = filter_signal + LPC_ORDER; ++ for (i = 0; i < SUBFRAMES; i++) { ++ int16_t temp_vector[SUBFRAME_LEN]; ++ int16_t temp; ++ int auto_corr[2]; ++ int scale, energy; ++ ++ /* Normalize */ ++ memcpy(temp_vector, buf_ptr, SUBFRAME_LEN * sizeof(int16_t)); ++ scale = scale_vector(temp_vector, SUBFRAME_LEN); ++ ++ /* Compute auto correlation coefficients */ ++ auto_corr[0] = ff_dot_product(temp_vector, temp_vector + 1, ++ SUBFRAME_LEN - 1)<<1; ++ auto_corr[1] = ff_dot_product(temp_vector, temp_vector, ++ SUBFRAME_LEN)<<1; ++ ++ /* Compute reflection coefficient */ ++ temp = auto_corr[1] >> 16; ++ if (temp) { ++ temp = (auto_corr[0] >> 2) / temp; ++ } ++ p->reflection_coef = ((p->reflection_coef << 2) - p->reflection_coef + ++ temp + 2) >> 2; ++ temp = (p->reflection_coef * 0xffffc >> 3) & 0xfffc; ++ ++ /* Compensation filter */ ++ for (j = 0; j < SUBFRAME_LEN; j++) { ++ buf_ptr[j] = av_clipl_int32(signal_ptr[j] + ++ ((signal_ptr[j - 1] >> 16) * ++ temp << 1)) >> 16; ++ } ++ ++ /* Compute normalized signal energy */ ++ temp = 2 * scale + 4; ++ if (temp < 0) { ++ energy = av_clipl_int32((int64_t)auto_corr[1] << -temp); ++ } else ++ energy = auto_corr[1] >> temp; ++ ++ gain_scale(p, buf_ptr, energy); ++ ++ buf_ptr += SUBFRAME_LEN; ++ signal_ptr += SUBFRAME_LEN; ++ } ++} ++ ++static int g723_1_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ G723_1_Context *p = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int16_t *out; ++ int dec_mode = buf[0] & 3; ++ ++ PPFParam ppf[SUBFRAMES]; ++ int16_t cur_lsp[LPC_ORDER]; ++ int16_t lpc[SUBFRAMES * LPC_ORDER]; ++ int16_t acb_vector[SUBFRAME_LEN]; ++ int16_t *vector_ptr; ++ int bad_frame = 0, i, j, ret; ++ ++ if (!buf_size || buf_size < frame_size[dec_mode]) { ++ *got_frame_ptr = 0; ++ return buf_size; ++ } ++ ++ if (unpack_bitstream(p, buf, buf_size) < 0) { ++ bad_frame = 1; ++ p->cur_frame_type = p->past_frame_type == ActiveFrame ? ++ ActiveFrame : UntransmittedFrame; ++ } ++ ++ p->frame.nb_samples = FRAME_LEN + LPC_ORDER; ++ if ((ret = avctx->get_buffer(avctx, &p->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out= (int16_t*)p->frame.data[0]; ++ ++ ++ if(p->cur_frame_type == ActiveFrame) { ++ if (!bad_frame) { ++ p->erased_frames = 0; ++ } else if(p->erased_frames != 3) ++ p->erased_frames++; ++ ++ inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, bad_frame); ++ lsp_interpolate(lpc, cur_lsp, p->prev_lsp); ++ ++ /* Save the lsp_vector for the next frame */ ++ memcpy(p->prev_lsp, cur_lsp, LPC_ORDER * sizeof(int16_t)); ++ ++ /* Generate the excitation for the frame */ ++ memcpy(p->excitation, p->prev_excitation, PITCH_MAX * sizeof(int16_t)); ++ vector_ptr = p->excitation + PITCH_MAX; ++ if (!p->erased_frames) { ++ /* Update interpolation gain memory */ ++ p->interp_gain = fixed_cb_gain[(p->subframe[2].amp_index + ++ p->subframe[3].amp_index) >> 1]; ++ for (i = 0; i < SUBFRAMES; i++) { ++ gen_fcb_excitation(vector_ptr, p->subframe[i], p->cur_rate, ++ p->pitch_lag[i >> 1], i); ++ gen_acb_excitation(acb_vector, &p->excitation[SUBFRAME_LEN * i], ++ p->pitch_lag[i >> 1], p->subframe[i], ++ p->cur_rate); ++ /* Get the total excitation */ ++ for (j = 0; j < SUBFRAME_LEN; j++) { ++ vector_ptr[j] = av_clip_int16(vector_ptr[j] << 1); ++ vector_ptr[j] = av_clip_int16(vector_ptr[j] + ++ acb_vector[j]); ++ } ++ vector_ptr += SUBFRAME_LEN; ++ } ++ ++ vector_ptr = p->excitation + PITCH_MAX; ++ ++ /* Save the excitation */ ++ memcpy(out, vector_ptr, FRAME_LEN * sizeof(int16_t)); ++ ++ p->interp_index = comp_interp_index(p, p->pitch_lag[1], ++ &p->sid_gain, &p->cur_gain); ++ ++ for (i = PITCH_MAX, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) ++ comp_ppf_coeff(p, i, p->pitch_lag[j >> 1], ++ ppf + j, p->cur_rate); ++ ++ /* Restore the original excitation */ ++ memcpy(p->excitation, p->prev_excitation, ++ PITCH_MAX * sizeof(int16_t)); ++ memcpy(vector_ptr, out, FRAME_LEN * sizeof(int16_t)); ++ ++ /* Peform pitch postfiltering */ ++ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) ++ ff_acelp_weighted_vector_sum(out + LPC_ORDER + i, vector_ptr + i, ++ vector_ptr + i + ppf[j].index, ++ ppf[j].sc_gain, ppf[j].opt_gain, ++ 1 << 14, 15, SUBFRAME_LEN); ++ } else { ++ p->interp_gain = (p->interp_gain * 3 + 2) >> 2; ++ if (p->erased_frames == 3) { ++ /* Mute output */ ++ memset(p->excitation, 0, ++ (FRAME_LEN + PITCH_MAX) * sizeof(int16_t)); ++ memset(out, 0, (FRAME_LEN + LPC_ORDER) * sizeof(int16_t)); ++ } else { ++ /* Regenerate frame */ ++ residual_interp(p->excitation, out + LPC_ORDER, p->interp_index, ++ p->interp_gain, &p->random_seed); ++ } ++ } ++ /* Save the excitation for the next frame */ ++ memcpy(p->prev_excitation, p->excitation + FRAME_LEN, ++ PITCH_MAX * sizeof(int16_t)); ++ } else { ++ memset(out, 0, sizeof(int16_t)*FRAME_LEN); ++ av_log(avctx, AV_LOG_WARNING, ++ "G.723.1: Comfort noise generation not supported yet\n"); ++ return frame_size[dec_mode]; ++ } ++ ++ p->past_frame_type = p->cur_frame_type; ++ ++ memcpy(out, p->synth_mem, LPC_ORDER * sizeof(int16_t)); ++ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) ++ ff_celp_lp_synthesis_filter(out + i, &lpc[j * LPC_ORDER], ++ out + i, SUBFRAME_LEN, LPC_ORDER, ++ 0, 1, 1 << 12); ++ memcpy(p->synth_mem, out + FRAME_LEN, LPC_ORDER * sizeof(int16_t)); ++ ++ formant_postfilter(p, lpc, out); ++ ++ memmove(out, out + LPC_ORDER, sizeof(int16_t)*FRAME_LEN); ++ p->frame.nb_samples = FRAME_LEN; ++ *(AVFrame*)data = p->frame; ++ *got_frame_ptr = 1; ++ ++ return frame_size[dec_mode]; ++} ++ ++AVCodec ff_g723_1_decoder = { ++ .name = "g723_1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_G723_1, ++ .priv_data_size = sizeof(G723_1_Context), ++ .init = g723_1_decode_init, ++ .decode = g723_1_decode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("G.723.1"), ++ .capabilities = CODEC_CAP_SUBFRAMES, ++}; ++ ++#if CONFIG_G723_1_ENCODER ++#define BITSTREAM_WRITER_LE ++#include "put_bits.h" ++ ++static av_cold int g723_1_encode_init(AVCodecContext *avctx) ++{ ++ G723_1_Context *p = avctx->priv_data; ++ ++ if (avctx->sample_rate != 8000) { ++ av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); ++ return -1; ++ } ++ ++ if (avctx->channels != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (avctx->bit_rate == 6300) { ++ p->cur_rate = Rate6k3; ++ } else if (avctx->bit_rate == 5300) { ++ av_log(avctx, AV_LOG_ERROR, "Bitrate not supported yet, use 6.3k\n"); ++ return AVERROR_PATCHWELCOME; ++ } else { ++ av_log(avctx, AV_LOG_ERROR, ++ "Bitrate not supported, use 6.3k\n"); ++ return AVERROR(EINVAL); ++ } ++ avctx->frame_size = 240; ++ memcpy(p->prev_lsp, dc_lsp, LPC_ORDER * sizeof(int16_t)); ++ ++ return 0; ++} ++ ++/** ++ * Remove DC component from the input signal. ++ * ++ * @param buf input signal ++ * @param fir zero memory ++ * @param iir pole memory ++ */ ++static void highpass_filter(int16_t *buf, int16_t *fir, int *iir) ++{ ++ int i; ++ for (i = 0; i < FRAME_LEN; i++) { ++ *iir = (buf[i] << 15) + ((-*fir) << 15) + MULL2(*iir, 0x7f00); ++ *fir = buf[i]; ++ buf[i] = av_clipl_int32((int64_t)*iir + (1 << 15)) >> 16; ++ } ++} ++ ++/** ++ * Estimate autocorrelation of the input vector. ++ * ++ * @param buf input buffer ++ * @param autocorr autocorrelation coefficients vector ++ */ ++static void comp_autocorr(int16_t *buf, int16_t *autocorr) ++{ ++ int i, scale, temp; ++ int16_t vector[LPC_FRAME]; ++ ++ memcpy(vector, buf, LPC_FRAME * sizeof(int16_t)); ++ scale_vector(vector, LPC_FRAME); ++ ++ /* Apply the Hamming window */ ++ for (i = 0; i < LPC_FRAME; i++) ++ vector[i] = (vector[i] * hamming_window[i] + (1 << 14)) >> 15; ++ ++ /* Compute the first autocorrelation coefficient */ ++ temp = dot_product(vector, vector, LPC_FRAME, 0); ++ ++ /* Apply a white noise correlation factor of (1025/1024) */ ++ temp += temp >> 10; ++ ++ /* Normalize */ ++ scale = normalize_bits_int32(temp); ++ autocorr[0] = av_clipl_int32((int64_t)(temp << scale) + ++ (1 << 15)) >> 16; ++ ++ /* Compute the remaining coefficients */ ++ if (!autocorr[0]) { ++ memset(autocorr + 1, 0, LPC_ORDER * sizeof(int16_t)); ++ } else { ++ for (i = 1; i <= LPC_ORDER; i++) { ++ temp = dot_product(vector, vector + i, LPC_FRAME - i, 0); ++ temp = MULL2((temp << scale), binomial_window[i - 1]); ++ autocorr[i] = av_clipl_int32((int64_t)temp + (1 << 15)) >> 16; ++ } ++ } ++} ++ ++/** ++ * Use Levinson-Durbin recursion to compute LPC coefficients from ++ * autocorrelation values. ++ * ++ * @param lpc LPC coefficients vector ++ * @param autocorr autocorrelation coefficients vector ++ * @param error prediction error ++ */ ++static void levinson_durbin(int16_t *lpc, int16_t *autocorr, int16_t error) ++{ ++ int16_t vector[LPC_ORDER]; ++ int16_t partial_corr; ++ int i, j, temp; ++ ++ memset(lpc, 0, LPC_ORDER * sizeof(int16_t)); ++ ++ for (i = 0; i < LPC_ORDER; i++) { ++ /* Compute the partial correlation coefficient */ ++ temp = 0; ++ for (j = 0; j < i; j++) ++ temp -= lpc[j] * autocorr[i - j - 1]; ++ temp = ((autocorr[i] << 13) + temp) << 3; ++ ++ if (FFABS(temp) >= (error << 16)) ++ break; ++ ++ partial_corr = temp / (error << 1); ++ ++ lpc[i] = av_clipl_int32((int64_t)(partial_corr << 14) + ++ (1 << 15)) >> 16; ++ ++ /* Update the prediction error */ ++ temp = MULL2(temp, partial_corr); ++ error = av_clipl_int32((int64_t)(error << 16) - temp + ++ (1 << 15)) >> 16; ++ ++ memcpy(vector, lpc, i * sizeof(int16_t)); ++ for (j = 0; j < i; j++) { ++ temp = partial_corr * vector[i - j - 1] << 1; ++ lpc[j] = av_clipl_int32((int64_t)(lpc[j] << 16) - temp + ++ (1 << 15)) >> 16; ++ } ++ } ++} ++ ++/** ++ * Calculate LPC coefficients for the current frame. ++ * ++ * @param buf current frame ++ * @param prev_data 2 trailing subframes of the previous frame ++ * @param lpc LPC coefficients vector ++ */ ++static void comp_lpc_coeff(int16_t *buf, int16_t *lpc) ++{ ++ int16_t autocorr[(LPC_ORDER + 1) * SUBFRAMES]; ++ int16_t *autocorr_ptr = autocorr; ++ int16_t *lpc_ptr = lpc; ++ int i, j; ++ ++ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) { ++ comp_autocorr(buf + i, autocorr_ptr); ++ levinson_durbin(lpc_ptr, autocorr_ptr + 1, autocorr_ptr[0]); ++ ++ lpc_ptr += LPC_ORDER; ++ autocorr_ptr += LPC_ORDER + 1; ++ } ++} ++ ++static void lpc2lsp(int16_t *lpc, int16_t *prev_lsp, int16_t *lsp) ++{ ++ int f[LPC_ORDER + 2]; ///< coefficients of the sum and difference ++ ///< polynomials (F1, F2) ordered as ++ ///< f1[0], f2[0], ...., f1[5], f2[5] ++ ++ int max, shift, cur_val, prev_val, count, p; ++ int i, j; ++ int64_t temp; ++ ++ /* Initialize f1[0] and f2[0] to 1 in Q25 */ ++ for (i = 0; i < LPC_ORDER; i++) ++ lsp[i] = (lpc[i] * bandwidth_expand[i] + (1 << 14)) >> 15; ++ ++ /* Apply bandwidth expansion on the LPC coefficients */ ++ f[0] = f[1] = 1 << 25; ++ ++ /* Compute the remaining coefficients */ ++ for (i = 0; i < LPC_ORDER / 2; i++) { ++ /* f1 */ ++ f[2 * i + 2] = -f[2 * i] - ((lsp[i] + lsp[LPC_ORDER - 1 - i]) << 12); ++ /* f2 */ ++ f[2 * i + 3] = f[2 * i + 1] - ((lsp[i] - lsp[LPC_ORDER - 1 - i]) << 12); ++ } ++ ++ /* Divide f1[5] and f2[5] by 2 for use in polynomial evaluation */ ++ f[LPC_ORDER] >>= 1; ++ f[LPC_ORDER + 1] >>= 1; ++ ++ /* Normalize and shorten */ ++ max = FFABS(f[0]); ++ for (i = 1; i < LPC_ORDER + 2; i++) ++ max = FFMAX(max, FFABS(f[i])); ++ ++ shift = normalize_bits_int32(max); ++ ++ for (i = 0; i < LPC_ORDER + 2; i++) ++ f[i] = av_clipl_int32((int64_t)(f[i] << shift) + (1 << 15)) >> 16; ++ ++ /** ++ * Evaluate F1 and F2 at uniform intervals of pi/256 along the ++ * unit circle and check for zero crossings. ++ */ ++ p = 0; ++ temp = 0; ++ for (i = 0; i <= LPC_ORDER / 2; i++) ++ temp += f[2 * i] * cos_tab[0]; ++ prev_val = av_clipl_int32(temp << 1); ++ count = 0; ++ for ( i = 1; i < COS_TBL_SIZE / 2; i++) { ++ /* Evaluate */ ++ temp = 0; ++ for (j = 0; j <= LPC_ORDER / 2; j++) ++ temp += f[LPC_ORDER - 2 * j + p] * cos_tab[i * j % COS_TBL_SIZE]; ++ cur_val = av_clipl_int32(temp << 1); ++ ++ /* Check for sign change, indicating a zero crossing */ ++ if ((cur_val ^ prev_val) < 0) { ++ int abs_cur = FFABS(cur_val); ++ int abs_prev = FFABS(prev_val); ++ int sum = abs_cur + abs_prev; ++ ++ shift = normalize_bits_int32(sum); ++ sum <<= shift; ++ abs_prev = abs_prev << shift >> 8; ++ lsp[count++] = ((i - 1) << 7) + (abs_prev >> 1) / (sum >> 16); ++ ++ if (count == LPC_ORDER) ++ break; ++ ++ /* Switch between sum and difference polynomials */ ++ p ^= 1; ++ ++ /* Evaluate */ ++ temp = 0; ++ for (j = 0; j <= LPC_ORDER / 2; j++){ ++ temp += f[LPC_ORDER - 2 * j + p] * ++ cos_tab[i * j % COS_TBL_SIZE]; ++ } ++ cur_val = av_clipl_int32(temp<<1); ++ } ++ prev_val = cur_val; ++ } ++ ++ if (count != LPC_ORDER) ++ memcpy(lsp, prev_lsp, LPC_ORDER * sizeof(int16_t)); ++} ++ ++/** ++ * Quantize the current LSP subvector. ++ * ++ * @param num band number ++ * @param offset offset of the current subvector in an LPC_ORDER vector ++ * @param size size of the current subvector ++ */ ++#define get_index(num, offset, size) \ ++{\ ++ int error, max = -1;\ ++ int16_t temp[4];\ ++ int i, j;\ ++ for (i = 0; i < LSP_CB_SIZE; i++) {\ ++ for (j = 0; j < size; j++){\ ++ temp[j] = (weight[j + (offset)] * lsp_band##num[i][j] +\ ++ (1 << 14)) >> 15;\ ++ }\ ++ error = dot_product(lsp + (offset), temp, size, 1) << 1;\ ++ error -= dot_product(lsp_band##num[i], temp, size, 1);\ ++ if (error > max) {\ ++ max = error;\ ++ lsp_index[num] = i;\ ++ }\ ++ }\ ++} ++ ++/** ++ * Vector quantize the LSP frequencies. ++ * ++ * @param lsp the current lsp vector ++ * @param prev_lsp the previous lsp vector ++ */ ++static void lsp_quantize(uint8_t *lsp_index, int16_t *lsp, int16_t *prev_lsp) ++{ ++ int16_t weight[LPC_ORDER]; ++ int16_t min, max; ++ int shift, i; ++ ++ /* Calculate the VQ weighting vector */ ++ weight[0] = (1 << 20) / (lsp[1] - lsp[0]); ++ weight[LPC_ORDER - 1] = (1 << 20) / ++ (lsp[LPC_ORDER - 1] - lsp[LPC_ORDER - 2]); ++ ++ for (i = 1; i < LPC_ORDER - 1; i++) { ++ min = FFMIN(lsp[i] - lsp[i - 1], lsp[i + 1] - lsp[i]); ++ if (min > 0x20) ++ weight[i] = (1 << 20) / min; ++ else ++ weight[i] = INT16_MAX; ++ } ++ ++ /* Normalize */ ++ max = 0; ++ for (i = 0; i < LPC_ORDER; i++) ++ max = FFMAX(weight[i], max); ++ ++ shift = normalize_bits_int16(max); ++ for (i = 0; i < LPC_ORDER; i++) { ++ weight[i] <<= shift; ++ } ++ ++ /* Compute the VQ target vector */ ++ for (i = 0; i < LPC_ORDER; i++) { ++ lsp[i] -= dc_lsp[i] + ++ (((prev_lsp[i] - dc_lsp[i]) * 12288 + (1 << 14)) >> 15); ++ } ++ ++ get_index(0, 0, 3); ++ get_index(1, 3, 3); ++ get_index(2, 6, 4); ++} ++ ++/** ++ * Apply the formant perceptual weighting filter. ++ * ++ * @param flt_coef filter coefficients ++ * @param unq_lpc unquantized lpc vector ++ */ ++static void perceptual_filter(G723_1_Context *p, int16_t *flt_coef, ++ int16_t *unq_lpc, int16_t *buf) ++{ ++ int16_t vector[FRAME_LEN + LPC_ORDER]; ++ int i, j, k, l = 0; ++ ++ memcpy(buf, p->iir_mem, sizeof(int16_t) * LPC_ORDER); ++ memcpy(vector, p->fir_mem, sizeof(int16_t) * LPC_ORDER); ++ memcpy(vector + LPC_ORDER, buf + LPC_ORDER, sizeof(int16_t) * FRAME_LEN); ++ ++ for (i = LPC_ORDER, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) { ++ for (k = 0; k < LPC_ORDER; k++) { ++ flt_coef[k + 2 * l] = (unq_lpc[k + l] * percept_flt_tbl[0][k] + ++ (1 << 14)) >> 15; ++ flt_coef[k + 2 * l + LPC_ORDER] = (unq_lpc[k + l] * ++ percept_flt_tbl[1][k] + ++ (1 << 14)) >> 15; ++ } ++ iir_filter(flt_coef + 2 * l, flt_coef + 2 * l + LPC_ORDER, vector + i, ++ buf + i, 0); ++ l += LPC_ORDER; ++ } ++ memcpy(p->iir_mem, buf + FRAME_LEN, sizeof(int16_t) * LPC_ORDER); ++ memcpy(p->fir_mem, vector + FRAME_LEN, sizeof(int16_t) * LPC_ORDER); ++} ++ ++/** ++ * Estimate the open loop pitch period. ++ * ++ * @param buf perceptually weighted speech ++ * @param start estimation is carried out from this position ++ */ ++static int estimate_pitch(int16_t *buf, int start) ++{ ++ int max_exp = 32; ++ int max_ccr = 0x4000; ++ int max_eng = 0x7fff; ++ int index = PITCH_MIN; ++ int offset = start - PITCH_MIN + 1; ++ ++ int ccr, eng, orig_eng, ccr_eng, exp; ++ int diff, temp; ++ ++ int i; ++ ++ orig_eng = dot_product(buf + offset, buf + offset, HALF_FRAME_LEN, 0); ++ ++ for (i = PITCH_MIN; i <= PITCH_MAX - 3; i++) { ++ offset--; ++ ++ /* Update energy and compute correlation */ ++ orig_eng += buf[offset] * buf[offset] - ++ buf[offset + HALF_FRAME_LEN] * buf[offset + HALF_FRAME_LEN]; ++ ccr = dot_product(buf + start, buf + offset, HALF_FRAME_LEN, 0); ++ if (ccr <= 0) ++ continue; ++ ++ /* Split into mantissa and exponent to maintain precision */ ++ exp = normalize_bits_int32(ccr); ++ ccr = av_clipl_int32((int64_t)(ccr << exp) + (1 << 15)) >> 16; ++ exp <<= 1; ++ ccr *= ccr; ++ temp = normalize_bits_int32(ccr); ++ ccr = ccr << temp >> 16; ++ exp += temp; ++ ++ temp = normalize_bits_int32(orig_eng); ++ eng = av_clipl_int32((int64_t)(orig_eng << temp) + (1 << 15)) >> 16; ++ exp -= temp; ++ ++ if (ccr >= eng) { ++ exp--; ++ ccr >>= 1; ++ } ++ if (exp > max_exp) ++ continue; ++ ++ if (exp + 1 < max_exp) ++ goto update; ++ ++ /* Equalize exponents before comparison */ ++ if (exp + 1 == max_exp) ++ temp = max_ccr >> 1; ++ else ++ temp = max_ccr; ++ ccr_eng = ccr * max_eng; ++ diff = ccr_eng - eng * temp; ++ if (diff > 0 && (i - index < PITCH_MIN || diff > ccr_eng >> 2)) { ++update: ++ index = i; ++ max_exp = exp; ++ max_ccr = ccr; ++ max_eng = eng; ++ } ++ } ++ return index; ++} ++ ++/** ++ * Compute harmonic noise filter parameters. ++ * ++ * @param buf perceptually weighted speech ++ * @param pitch_lag open loop pitch period ++ * @param hf harmonic filter parameters ++ */ ++static void comp_harmonic_coeff(int16_t *buf, int16_t pitch_lag, HFParam *hf) ++{ ++ int ccr, eng, max_ccr, max_eng; ++ int exp, max, diff; ++ int energy[15]; ++ int i, j; ++ ++ for (i = 0, j = pitch_lag - 3; j <= pitch_lag + 3; i++, j++) { ++ /* Compute residual energy */ ++ energy[i << 1] = dot_product(buf - j, buf - j, SUBFRAME_LEN, 0); ++ /* Compute correlation */ ++ energy[(i << 1) + 1] = dot_product(buf, buf - j, SUBFRAME_LEN, 0); ++ } ++ ++ /* Compute target energy */ ++ energy[14] = dot_product(buf, buf, SUBFRAME_LEN, 0); ++ ++ /* Normalize */ ++ max = 0; ++ for (i = 0; i < 15; i++) ++ max = FFMAX(max, FFABS(energy[i])); ++ ++ exp = normalize_bits_int32(max); ++ for (i = 0; i < 15; i++) { ++ energy[i] = av_clipl_int32((int64_t)(energy[i] << exp) + ++ (1 << 15)) >> 16; ++ } ++ ++ hf->index = -1; ++ hf->gain = 0; ++ max_ccr = 1; ++ max_eng = 0x7fff; ++ ++ for (i = 0; i <= 6; i++) { ++ eng = energy[i << 1]; ++ ccr = energy[(i << 1) + 1]; ++ ++ if (ccr <= 0) ++ continue; ++ ++ ccr = (ccr * ccr + (1 << 14)) >> 15; ++ diff = ccr * max_eng - eng * max_ccr; ++ if (diff > 0) { ++ max_ccr = ccr; ++ max_eng = eng; ++ hf->index = i; ++ } ++ } ++ ++ if (hf->index == -1) { ++ hf->index = pitch_lag; ++ return; ++ } ++ ++ eng = energy[14] * max_eng; ++ eng = (eng >> 2) + (eng >> 3); ++ ccr = energy[(hf->index << 1) + 1] * energy[(hf->index << 1) + 1]; ++ if (eng < ccr) { ++ eng = energy[(hf->index << 1) + 1]; ++ ++ if (eng >= max_eng) ++ hf->gain = 0x2800; ++ else ++ hf->gain = ((eng << 15) / max_eng * 0x2800 + (1 << 14)) >> 15; ++ } ++ hf->index += pitch_lag - 3; ++} ++ ++/** ++ * Apply the harmonic noise shaping filter. ++ * ++ * @param hf filter parameters ++ */ ++static void harmonic_filter(HFParam *hf, int16_t *src, int16_t *dest) ++{ ++ int i; ++ ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t temp = hf->gain * src[i - hf->index] << 1; ++ dest[i] = av_clipl_int32((src[i] << 16) - temp + (1 << 15)) >> 16; ++ } ++} ++ ++static void harmonic_noise_sub(HFParam *hf, int16_t *src, int16_t *dest) ++{ ++ int i; ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t temp = hf->gain * src[i - hf->index] << 1; ++ dest[i] = av_clipl_int32(((dest[i] - src[i]) << 16) + temp + ++ (1 << 15)) >> 16; ++ ++ } ++} ++ ++/** ++ * Combined synthesis and formant perceptual weighting filer. ++ * ++ * @param qnt_lpc quantized lpc coefficients ++ * @param perf_lpc perceptual filter coefficients ++ * @param perf_fir perceptual filter fir memory ++ * @param perf_iir perceptual filter iir memory ++ * @param scale the filter output will be scaled by 2^scale ++ */ ++static void synth_percept_filter(int16_t *qnt_lpc, int16_t *perf_lpc, ++ int16_t *perf_fir, int16_t *perf_iir, ++ int16_t *src, int16_t *dest, int scale) ++{ ++ int i, j; ++ int16_t buf_16[SUBFRAME_LEN + LPC_ORDER]; ++ int64_t buf[SUBFRAME_LEN]; ++ ++ int16_t *bptr_16 = buf_16 + LPC_ORDER; ++ ++ memcpy(buf_16, perf_fir, sizeof(int16_t) * LPC_ORDER); ++ memcpy(dest - LPC_ORDER, perf_iir, sizeof(int16_t) * LPC_ORDER); ++ ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t temp = 0; ++ for (j = 1; j <= LPC_ORDER; j++) ++ temp -= qnt_lpc[j - 1] * bptr_16[i - j]; ++ ++ buf[i] = (src[i] << 15) + (temp << 3); ++ bptr_16[i] = av_clipl_int32(buf[i] + (1 << 15)) >> 16; ++ } ++ ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t fir = 0, iir = 0; ++ for (j = 1; j <= LPC_ORDER; j++) { ++ fir -= perf_lpc[j - 1] * bptr_16[i - j]; ++ iir += perf_lpc[j + LPC_ORDER - 1] * dest[i - j]; ++ } ++ dest[i] = av_clipl_int32(((buf[i] + (fir << 3)) << scale) + (iir << 3) + ++ (1 << 15)) >> 16; ++ } ++ memcpy(perf_fir, buf_16 + SUBFRAME_LEN, sizeof(int16_t) * LPC_ORDER); ++ memcpy(perf_iir, dest + SUBFRAME_LEN - LPC_ORDER, ++ sizeof(int16_t) * LPC_ORDER); ++} ++ ++/** ++ * Compute the adaptive codebook contribution. ++ * ++ * @param buf input signal ++ * @param index the current subframe index ++ */ ++static void acb_search(G723_1_Context *p, int16_t *residual, ++ int16_t *impulse_resp, int16_t *buf, ++ int index) ++{ ++ ++ int16_t flt_buf[PITCH_ORDER][SUBFRAME_LEN]; ++ ++ const int16_t *cb_tbl = adaptive_cb_gain85; ++ ++ int ccr_buf[PITCH_ORDER * SUBFRAMES << 2]; ++ ++ int pitch_lag = p->pitch_lag[index >> 1]; ++ int acb_lag = 1; ++ int acb_gain = 0; ++ int odd_frame = index & 1; ++ int iter = 3 + odd_frame; ++ int count = 0; ++ int tbl_size = 85; ++ ++ int i, j, k, l, max; ++ int64_t temp; ++ ++ if (!odd_frame) { ++ if (pitch_lag == PITCH_MIN) ++ pitch_lag++; ++ else ++ pitch_lag = FFMIN(pitch_lag, PITCH_MAX - 5); ++ } ++ ++ for (i = 0; i < iter; i++) { ++ get_residual(residual, p->prev_excitation, pitch_lag + i - 1); ++ ++ for (j = 0; j < SUBFRAME_LEN; j++) { ++ temp = 0; ++ for (k = 0; k <= j; k++) ++ temp += residual[PITCH_ORDER - 1 + k] * impulse_resp[j - k]; ++ flt_buf[PITCH_ORDER - 1][j] = av_clipl_int32((temp << 1) + ++ (1 << 15)) >> 16; ++ } ++ ++ for (j = PITCH_ORDER - 2; j >= 0; j--) { ++ flt_buf[j][0] = ((residual[j] << 13) + (1 << 14)) >> 15; ++ for (k = 1; k < SUBFRAME_LEN; k++) { ++ temp = (flt_buf[j + 1][k - 1] << 15) + ++ residual[j] * impulse_resp[k]; ++ flt_buf[j][k] = av_clipl_int32((temp << 1) + (1 << 15)) >> 16; ++ } ++ } ++ ++ /* Compute crosscorrelation with the signal */ ++ for (j = 0; j < PITCH_ORDER; j++) { ++ temp = dot_product(buf, flt_buf[j], SUBFRAME_LEN, 0); ++ ccr_buf[count++] = av_clipl_int32(temp << 1); ++ } ++ ++ /* Compute energies */ ++ for (j = 0; j < PITCH_ORDER; j++) { ++ ccr_buf[count++] = dot_product(flt_buf[j], flt_buf[j], ++ SUBFRAME_LEN, 1); ++ } ++ ++ for (j = 1; j < PITCH_ORDER; j++) { ++ for (k = 0; k < j; k++) { ++ temp = dot_product(flt_buf[j], flt_buf[k], SUBFRAME_LEN, 0); ++ ccr_buf[count++] = av_clipl_int32(temp<<2); ++ } ++ } ++ } ++ ++ /* Normalize and shorten */ ++ max = 0; ++ for (i = 0; i < 20 * iter; i++) ++ max = FFMAX(max, FFABS(ccr_buf[i])); ++ ++ temp = normalize_bits_int32(max); ++ ++ for (i = 0; i < 20 * iter; i++){ ++ ccr_buf[i] = av_clipl_int32((int64_t)(ccr_buf[i] << temp) + ++ (1 << 15)) >> 16; ++ } ++ ++ max = 0; ++ for (i = 0; i < iter; i++) { ++ /* Select quantization table */ ++ if (!odd_frame && pitch_lag + i - 1 >= SUBFRAME_LEN - 2 || ++ odd_frame && pitch_lag >= SUBFRAME_LEN - 2) { ++ cb_tbl = adaptive_cb_gain170; ++ tbl_size = 170; ++ } ++ ++ for (j = 0, k = 0; j < tbl_size; j++, k += 20) { ++ temp = 0; ++ for (l = 0; l < 20; l++) ++ temp += ccr_buf[20 * i + l] * cb_tbl[k + l]; ++ temp = av_clipl_int32(temp); ++ ++ if (temp > max) { ++ max = temp; ++ acb_gain = j; ++ acb_lag = i; ++ } ++ } ++ } ++ ++ if (!odd_frame) { ++ pitch_lag += acb_lag - 1; ++ acb_lag = 1; ++ } ++ ++ p->pitch_lag[index >> 1] = pitch_lag; ++ p->subframe[index].ad_cb_lag = acb_lag; ++ p->subframe[index].ad_cb_gain = acb_gain; ++} ++ ++/** ++ * Subtract the adaptive codebook contribution from the input ++ * to obtain the residual. ++ * ++ * @param buf target vector ++ */ ++static void sub_acb_contrib(int16_t *residual, int16_t *impulse_resp, ++ int16_t *buf) ++{ ++ int i, j; ++ /* Subtract adaptive CB contribution to obtain the residual */ ++ for (i = 0; i < SUBFRAME_LEN; i++) { ++ int64_t temp = buf[i] << 14; ++ for (j = 0; j <= i; j++) ++ temp -= residual[j] * impulse_resp[i - j]; ++ ++ buf[i] = av_clipl_int32((temp << 2) + (1 << 15)) >> 16; ++ } ++} ++ ++/** ++ * Quantize the residual signal using the fixed codebook (MP-MLQ). ++ * ++ * @param optim optimized fixed codebook parameters ++ * @param buf excitation vector ++ */ ++static void get_fcb_param(FCBParam *optim, int16_t *impulse_resp, ++ int16_t *buf, int pulse_cnt, int pitch_lag) ++{ ++ FCBParam param; ++ int16_t impulse_r[SUBFRAME_LEN]; ++ int16_t temp_corr[SUBFRAME_LEN]; ++ int16_t impulse_corr[SUBFRAME_LEN]; ++ ++ int ccr1[SUBFRAME_LEN]; ++ int ccr2[SUBFRAME_LEN]; ++ int amp, err, max, max_amp_index, min, scale, i, j, k, l; ++ ++ int64_t temp; ++ ++ /* Update impulse response */ ++ memcpy(impulse_r, impulse_resp, sizeof(int16_t) * SUBFRAME_LEN); ++ param.dirac_train = 0; ++ if (pitch_lag < SUBFRAME_LEN - 2) { ++ param.dirac_train = 1; ++ gen_dirac_train(impulse_r, pitch_lag); ++ } ++ ++ for (i = 0; i < SUBFRAME_LEN; i++) ++ temp_corr[i] = impulse_r[i] >> 1; ++ ++ /* Compute impulse response autocorrelation */ ++ temp = dot_product(temp_corr, temp_corr, SUBFRAME_LEN, 1); ++ ++ scale = normalize_bits_int32(temp); ++ impulse_corr[0] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16; ++ ++ for (i = 1; i < SUBFRAME_LEN; i++) { ++ temp = dot_product(temp_corr + i, temp_corr, SUBFRAME_LEN - i, 1); ++ impulse_corr[i] = av_clipl_int32((temp << scale) + (1 << 15)) >> 16; ++ } ++ ++ /* Compute crosscorrelation of impulse response with residual signal */ ++ scale -= 4; ++ for (i = 0; i < SUBFRAME_LEN; i++){ ++ temp = dot_product(buf + i, impulse_r, SUBFRAME_LEN - i, 1); ++ if (scale < 0) ++ ccr1[i] = temp >> -scale; ++ else ++ ccr1[i] = av_clipl_int32(temp << scale); ++ } ++ ++ /* Search loop */ ++ for (i = 0; i < GRID_SIZE; i++) { ++ /* Maximize the crosscorrelation */ ++ max = 0; ++ for (j = i; j < SUBFRAME_LEN; j += GRID_SIZE) { ++ temp = FFABS(ccr1[j]); ++ if (temp >= max) { ++ max = temp; ++ param.pulse_pos[0] = j; ++ } ++ } ++ ++ /* Quantize the gain (max crosscorrelation/impulse_corr[0]) */ ++ amp = max; ++ min = 1 << 30; ++ max_amp_index = GAIN_LEVELS - 2; ++ for (j = max_amp_index; j >= 2; j--) { ++ temp = av_clipl_int32((int64_t)fixed_cb_gain[j] * ++ impulse_corr[0] << 1); ++ temp = FFABS(temp - amp); ++ if (temp < min) { ++ min = temp; ++ max_amp_index = j; ++ } ++ } ++ ++ max_amp_index--; ++ /* Select additional gain values */ ++ for (j = 1; j < 5; j++) { ++ for (k = i; k < SUBFRAME_LEN; k += GRID_SIZE) { ++ temp_corr[k] = 0; ++ ccr2[k] = ccr1[k]; ++ } ++ param.amp_index = max_amp_index + j - 2; ++ amp = fixed_cb_gain[param.amp_index]; ++ ++ param.pulse_sign[0] = (ccr2[param.pulse_pos[0]] < 0) ? -amp : amp; ++ temp_corr[param.pulse_pos[0]] = 1; ++ ++ for (k = 1; k < pulse_cnt; k++) { ++ max = -1 << 30; ++ for (l = i; l < SUBFRAME_LEN; l += GRID_SIZE) { ++ if (temp_corr[l]) ++ continue; ++ temp = impulse_corr[FFABS(l - param.pulse_pos[k - 1])]; ++ temp = av_clipl_int32((int64_t)temp * ++ param.pulse_sign[k - 1] << 1); ++ ccr2[l] -= temp; ++ temp = FFABS(ccr2[l]); ++ if (temp > max) { ++ max = temp; ++ param.pulse_pos[k] = l; ++ } ++ } ++ ++ param.pulse_sign[k] = (ccr2[param.pulse_pos[k]] < 0) ? ++ -amp : amp; ++ temp_corr[param.pulse_pos[k]] = 1; ++ } ++ ++ /* Create the error vector */ ++ memset(temp_corr, 0, sizeof(int16_t) * SUBFRAME_LEN); ++ ++ for (k = 0; k < pulse_cnt; k++) ++ temp_corr[param.pulse_pos[k]] = param.pulse_sign[k]; ++ ++ for (k = SUBFRAME_LEN - 1; k >= 0; k--) { ++ temp = 0; ++ for (l = 0; l <= k; l++) { ++ int prod = av_clipl_int32((int64_t)temp_corr[l] * ++ impulse_r[k - l] << 1); ++ temp = av_clipl_int32(temp + prod); ++ } ++ temp_corr[k] = temp << 2 >> 16; ++ } ++ ++ /* Compute square of error */ ++ err = 0; ++ for (k = 0; k < SUBFRAME_LEN; k++) { ++ int64_t prod; ++ prod = av_clipl_int32((int64_t)buf[k] * temp_corr[k] << 1); ++ err = av_clipl_int32(err - prod); ++ prod = av_clipl_int32((int64_t)temp_corr[k] * temp_corr[k]); ++ err = av_clipl_int32(err + prod); ++ } ++ ++ /* Minimize */ ++ if (err < optim->min_err) { ++ optim->min_err = err; ++ optim->grid_index = i; ++ optim->amp_index = param.amp_index; ++ optim->dirac_train = param.dirac_train; ++ ++ for (k = 0; k < pulse_cnt; k++) { ++ optim->pulse_sign[k] = param.pulse_sign[k]; ++ optim->pulse_pos[k] = param.pulse_pos[k]; ++ } ++ } ++ } ++ } ++} ++ ++/** ++ * Encode the pulse position and gain of the current subframe. ++ * ++ * @param optim optimized fixed CB parameters ++ * @param buf excitation vector ++ */ ++static void pack_fcb_param(G723_1_Subframe *subfrm, FCBParam *optim, ++ int16_t *buf, int pulse_cnt) ++{ ++ int i, j; ++ ++ j = PULSE_MAX - pulse_cnt; ++ ++ subfrm->pulse_sign = 0; ++ subfrm->pulse_pos = 0; ++ ++ for (i = 0; i < SUBFRAME_LEN >> 1; i++) { ++ int val = buf[optim->grid_index + (i << 1)]; ++ if (!val) { ++ subfrm->pulse_pos += combinatorial_table[j][i]; ++ } else { ++ subfrm->pulse_sign <<= 1; ++ if (val < 0) subfrm->pulse_sign++; ++ j++; ++ ++ if (j == PULSE_MAX) break; ++ } ++ } ++ subfrm->amp_index = optim->amp_index; ++ subfrm->grid_index = optim->grid_index; ++ subfrm->dirac_train = optim->dirac_train; ++} ++ ++/** ++ * Compute the fixed codebook excitation. ++ * ++ * @param buf target vector ++ * @param impulse_resp impulse response of the combined filter ++ */ ++static void fcb_search(G723_1_Context *p, int16_t *impulse_resp, ++ int16_t *buf, int index) ++{ ++ FCBParam optim; ++ int pulse_cnt = pulses[index]; ++ int i; ++ ++ optim.min_err = 1 << 30; ++ get_fcb_param(&optim, impulse_resp, buf, pulse_cnt, SUBFRAME_LEN); ++ ++ if (p->pitch_lag[index >> 1] < SUBFRAME_LEN - 2) { ++ get_fcb_param(&optim, impulse_resp, buf, pulse_cnt, ++ p->pitch_lag[index >> 1]); ++ } ++ ++ /* Reconstruct the excitation */ ++ memset(buf, 0, sizeof(int16_t) * SUBFRAME_LEN); ++ for (i = 0; i < pulse_cnt; i++) ++ buf[optim.pulse_pos[i]] = optim.pulse_sign[i]; ++ ++ pack_fcb_param(&p->subframe[index], &optim, buf, pulse_cnt); ++ ++ if (optim.dirac_train) ++ gen_dirac_train(buf, p->pitch_lag[index >> 1]); ++} ++ ++/** ++ * Pack the frame parameters into output bitstream. ++ * ++ * @param frame output buffer ++ * @param size size of the buffer ++ */ ++static int pack_bitstream(G723_1_Context *p, unsigned char *frame, int size) ++{ ++ PutBitContext pb; ++ int info_bits, i, temp; ++ ++ init_put_bits(&pb, frame, size); ++ ++ if (p->cur_rate == Rate6k3) { ++ info_bits = 0; ++ put_bits(&pb, 2, info_bits); ++ } ++ ++ put_bits(&pb, 8, p->lsp_index[2]); ++ put_bits(&pb, 8, p->lsp_index[1]); ++ put_bits(&pb, 8, p->lsp_index[0]); ++ ++ put_bits(&pb, 7, p->pitch_lag[0] - PITCH_MIN); ++ put_bits(&pb, 2, p->subframe[1].ad_cb_lag); ++ put_bits(&pb, 7, p->pitch_lag[1] - PITCH_MIN); ++ put_bits(&pb, 2, p->subframe[3].ad_cb_lag); ++ ++ /* Write 12 bit combined gain */ ++ for (i = 0; i < SUBFRAMES; i++) { ++ temp = p->subframe[i].ad_cb_gain * GAIN_LEVELS + ++ p->subframe[i].amp_index; ++ if (p->cur_rate == Rate6k3) ++ temp += p->subframe[i].dirac_train << 11; ++ put_bits(&pb, 12, temp); ++ } ++ ++ put_bits(&pb, 1, p->subframe[0].grid_index); ++ put_bits(&pb, 1, p->subframe[1].grid_index); ++ put_bits(&pb, 1, p->subframe[2].grid_index); ++ put_bits(&pb, 1, p->subframe[3].grid_index); ++ ++ if (p->cur_rate == Rate6k3) { ++ skip_put_bits(&pb, 1); /* reserved bit */ ++ ++ /* Write 13 bit combined position index */ ++ temp = (p->subframe[0].pulse_pos >> 16) * 810 + ++ (p->subframe[1].pulse_pos >> 14) * 90 + ++ (p->subframe[2].pulse_pos >> 16) * 9 + ++ (p->subframe[3].pulse_pos >> 14); ++ put_bits(&pb, 13, temp); ++ ++ put_bits(&pb, 16, p->subframe[0].pulse_pos & 0xffff); ++ put_bits(&pb, 14, p->subframe[1].pulse_pos & 0x3fff); ++ put_bits(&pb, 16, p->subframe[2].pulse_pos & 0xffff); ++ put_bits(&pb, 14, p->subframe[3].pulse_pos & 0x3fff); ++ ++ put_bits(&pb, 6, p->subframe[0].pulse_sign); ++ put_bits(&pb, 5, p->subframe[1].pulse_sign); ++ put_bits(&pb, 6, p->subframe[2].pulse_sign); ++ put_bits(&pb, 5, p->subframe[3].pulse_sign); ++ } ++ ++ flush_put_bits(&pb); ++ return frame_size[info_bits]; ++} ++ ++static int g723_1_encode_frame(AVCodecContext *avctx, unsigned char *buf, ++ int buf_size, void *data) ++{ ++ G723_1_Context *p = avctx->priv_data; ++ int16_t unq_lpc[LPC_ORDER * SUBFRAMES]; ++ int16_t qnt_lpc[LPC_ORDER * SUBFRAMES]; ++ int16_t cur_lsp[LPC_ORDER]; ++ int16_t weighted_lpc[LPC_ORDER * SUBFRAMES << 1]; ++ int16_t vector[FRAME_LEN + PITCH_MAX]; ++ int offset; ++ int16_t *in = data; ++ ++ HFParam hf[4]; ++ int i, j; ++ ++ highpass_filter(in, &p->hpf_fir_mem, &p->hpf_iir_mem); ++ ++ memcpy(vector, p->prev_data, HALF_FRAME_LEN * sizeof(int16_t)); ++ memcpy(vector + HALF_FRAME_LEN, in, FRAME_LEN * sizeof(int16_t)); ++ ++ comp_lpc_coeff(vector, unq_lpc); ++ lpc2lsp(&unq_lpc[LPC_ORDER * 3], p->prev_lsp, cur_lsp); ++ lsp_quantize(p->lsp_index, cur_lsp, p->prev_lsp); ++ ++ /* Update memory */ ++ memcpy(vector + LPC_ORDER, p->prev_data + SUBFRAME_LEN, ++ sizeof(int16_t) * SUBFRAME_LEN); ++ memcpy(vector + LPC_ORDER + SUBFRAME_LEN, in, ++ sizeof(int16_t) * (HALF_FRAME_LEN + SUBFRAME_LEN)); ++ memcpy(p->prev_data, in + HALF_FRAME_LEN, ++ sizeof(int16_t) * HALF_FRAME_LEN); ++ memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN); ++ ++ perceptual_filter(p, weighted_lpc, unq_lpc, vector); ++ ++ memcpy(in, vector + LPC_ORDER, sizeof(int16_t) * FRAME_LEN); ++ memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX); ++ memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN); ++ ++ scale_vector(vector, FRAME_LEN + PITCH_MAX); ++ ++ p->pitch_lag[0] = estimate_pitch(vector, PITCH_MAX); ++ p->pitch_lag[1] = estimate_pitch(vector, PITCH_MAX + HALF_FRAME_LEN); ++ ++ for (i = PITCH_MAX, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) ++ comp_harmonic_coeff(vector + i, p->pitch_lag[j >> 1], hf + j); ++ ++ memcpy(vector, p->prev_weight_sig, sizeof(int16_t) * PITCH_MAX); ++ memcpy(vector + PITCH_MAX, in, sizeof(int16_t) * FRAME_LEN); ++ memcpy(p->prev_weight_sig, vector + FRAME_LEN, sizeof(int16_t) * PITCH_MAX); ++ ++ for (i = 0, j = 0; j < SUBFRAMES; i += SUBFRAME_LEN, j++) ++ harmonic_filter(hf + j, vector + PITCH_MAX + i, in + i); ++ ++ inverse_quant(cur_lsp, p->prev_lsp, p->lsp_index, 0); ++ lsp_interpolate(qnt_lpc, cur_lsp, p->prev_lsp); ++ ++ memcpy(p->prev_lsp, cur_lsp, sizeof(int16_t) * LPC_ORDER); ++ ++ offset = 0; ++ for (i = 0; i < SUBFRAMES; i++) { ++ int16_t impulse_resp[SUBFRAME_LEN]; ++ int16_t residual[SUBFRAME_LEN + PITCH_ORDER - 1]; ++ int16_t flt_in[SUBFRAME_LEN]; ++ int16_t zero[LPC_ORDER], fir[LPC_ORDER], iir[LPC_ORDER]; ++ ++ /** ++ * Compute the combined impulse response of the synthesis filter, ++ * formant perceptual weighting filter and harmonic noise shaping filter ++ */ ++ memset(zero, 0, sizeof(int16_t) * LPC_ORDER); ++ memset(vector, 0, sizeof(int16_t) * PITCH_MAX); ++ memset(flt_in, 0, sizeof(int16_t) * SUBFRAME_LEN); ++ ++ flt_in[0] = 1 << 13; /* Unit impulse */ ++ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1), ++ zero, zero, flt_in, vector + PITCH_MAX, 1); ++ harmonic_filter(hf + i, vector + PITCH_MAX, impulse_resp); ++ ++ /* Compute the combined zero input response */ ++ flt_in[0] = 0; ++ memcpy(fir, p->perf_fir_mem, sizeof(int16_t) * LPC_ORDER); ++ memcpy(iir, p->perf_iir_mem, sizeof(int16_t) * LPC_ORDER); ++ ++ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1), ++ fir, iir, flt_in, vector + PITCH_MAX, 0); ++ memcpy(vector, p->harmonic_mem, sizeof(int16_t) * PITCH_MAX); ++ harmonic_noise_sub(hf + i, vector + PITCH_MAX, in); ++ ++ acb_search(p, residual, impulse_resp, in, i); ++ gen_acb_excitation(residual, p->prev_excitation,p->pitch_lag[i >> 1], ++ p->subframe[i], p->cur_rate); ++ sub_acb_contrib(residual, impulse_resp, in); ++ ++ fcb_search(p, impulse_resp, in, i); ++ ++ /* Reconstruct the excitation */ ++ gen_acb_excitation(impulse_resp, p->prev_excitation, p->pitch_lag[i >> 1], ++ p->subframe[i], Rate6k3); ++ ++ memmove(p->prev_excitation, p->prev_excitation + SUBFRAME_LEN, ++ sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN)); ++ for (j = 0; j < SUBFRAME_LEN; j++) ++ in[j] = av_clip_int16((in[j] << 1) + impulse_resp[j]); ++ memcpy(p->prev_excitation + PITCH_MAX - SUBFRAME_LEN, in, ++ sizeof(int16_t) * SUBFRAME_LEN); ++ ++ /* Update filter memories */ ++ synth_percept_filter(qnt_lpc + offset, weighted_lpc + (offset << 1), ++ p->perf_fir_mem, p->perf_iir_mem, ++ in, vector + PITCH_MAX, 0); ++ memmove(p->harmonic_mem, p->harmonic_mem + SUBFRAME_LEN, ++ sizeof(int16_t) * (PITCH_MAX - SUBFRAME_LEN)); ++ memcpy(p->harmonic_mem + PITCH_MAX - SUBFRAME_LEN, vector + PITCH_MAX, ++ sizeof(int16_t) * SUBFRAME_LEN); ++ ++ in += SUBFRAME_LEN; ++ offset += LPC_ORDER; ++ } ++ ++ return pack_bitstream(p, buf, buf_size); ++} ++ ++AVCodec ff_g723_1_encoder = { ++ .name = "g723_1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_G723_1, ++ .priv_data_size = sizeof(G723_1_Context), ++ .init = g723_1_encode_init, ++ .encode = g723_1_encode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("G.723.1"), ++ .sample_fmts = (const enum SampleFormat[]){AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE}, ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g723_1_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g723_1_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g723_1_data.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g723_1_data.h 2012-05-14 14:08:53.748328187 +0200 +@@ -0,0 +1,1315 @@ ++/* ++ * G723.1 compatible decoder data tables. ++ * Copyright (c) 2006 Benjamin Larsson ++ * Copyright (c) 2010 Mohamed Naufal Basheer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * G723.1 compatible decoder data tables ++ */ ++ ++#define SUBFRAMES 4 ++#define SUBFRAME_LEN 60 ++#define FRAME_LEN (SUBFRAME_LEN << 2) ++#define HALF_FRAME_LEN (FRAME_LEN / 2) ++#define LPC_FRAME (HALF_FRAME_LEN + SUBFRAME_LEN) ++#define LPC_ORDER 10 ++#define LSP_BANDS 3 ++#define LSP_CB_SIZE 256 ++#define PITCH_MIN 18 ++#define PITCH_MAX (PITCH_MIN + 127) ++#define PITCH_ORDER 5 ++#define GRID_SIZE 2 ++#define PULSE_MAX 6 ++#define GAIN_LEVELS 24 ++#define COS_TBL_SIZE 512 ++ ++/** ++ * G723.1 frame types ++ */ ++typedef enum { ++ ActiveFrame, ///< Active speech ++ SIDFrame, ///< Silence Insertion Descriptor frame ++ UntransmittedFrame ++} FrameType; ++ ++static const uint8_t frame_size[4] = {24, 20, 4, 1}; ++ ++typedef enum { ++ Rate6k3, ++ Rate5k3 ++} Rate; ++ ++/** ++ * G723.1 unpacked data subframe ++ */ ++typedef struct { ++ int ad_cb_lag; ///< adaptive codebook lag ++ int ad_cb_gain; ++ int dirac_train; ++ int pulse_sign; ++ int grid_index; ++ int amp_index; ++ int pulse_pos; ++} G723_1_Subframe; ++ ++/** ++ * Pitch postfilter parameters ++ */ ++typedef struct { ++ int index; ///< postfilter backward/forward lag ++ int16_t opt_gain; ///< optimal gain ++ int16_t sc_gain; ///< scaling gain ++} PPFParam; ++ ++/** ++ * Harmonic filter parameters ++ */ ++typedef struct { ++ int index; ++ int gain; ++} HFParam; ++ ++/** ++ * Optimized fixed codebook excitation parameters ++ */ ++typedef struct { ++ int min_err; ++ int amp_index; ++ int grid_index; ++ int dirac_train; ++ int pulse_pos[PULSE_MAX]; ++ int pulse_sign[PULSE_MAX]; ++} FCBParam; ++ ++/** ++ * Postfilter gain weighting factors scaled by 2^15 ++ */ ++static const int16_t ppf_gain_weight[2] = {0x1800, 0x2000}; ++ ++/** ++ * LSP DC component ++ */ ++static const int16_t dc_lsp[LPC_ORDER] = { ++ 0x0c3b, ++ 0x1271, ++ 0x1e0a, ++ 0x2a36, ++ 0x3630, ++ 0x406f, ++ 0x4d28, ++ 0x56f4, ++ 0x638c, ++ 0x6c46 ++}; ++ ++/** ++ * Cosine table scaled by 2^14 ++ */ ++static const int16_t cos_tab[COS_TBL_SIZE] = { ++ 16384, 16383, 16379, 16373, 16364, 16353, 16340, 16324, ++ 16305, 16284, 16261, 16235, 16207, 16176, 16143, 16107, ++ 16069, 16029, 15986, 15941, 15893, 15843, 15791, 15736, ++ 15679, 15619, 15557, 15493, 15426, 15357, 15286, 15213, ++ 15137, 15059, 14978, 14896, 14811, 14724, 14635, 14543, ++ 14449, 14354, 14256, 14155, 14053, 13949, 13842, 13733, ++ 13623, 13510, 13395, 13279, 13160, 13039, 12916, 12792, ++ 12665, 12537, 12406, 12274, 12140, 12004, 11866, 11727, ++ 11585, 11442, 11297, 11151, 11003, 10853, 10702, 10549, ++ 10394, 10238, 10080, 9921, 9760, 9598, 9434, 9269, ++ 9102, 8935, 8765, 8595, 8423, 8250, 8076, 7900, ++ 7723, 7545, 7366, 7186, 7005, 6823, 6639, 6455, ++ 6270, 6084, 5897, 5708, 5520, 5330, 5139, 4948, ++ 4756, 4563, 4370, 4176, 3981, 3786, 3590, 3393, ++ 3196, 2999, 2801, 2603, 2404, 2205, 2006, 1806, ++ 1606, 1406, 1205, 1005, 804, 603, 402, 201, ++ 0, -201, -402, -603, -804, -1005, -1205, -1406, ++ -1606, -1806, -2006, -2205, -2404, -2603, -2801, -2999, ++ -3196, -3393, -3590, -3786, -3981, -4176, -4370, -4563, ++ -4756, -4948, -5139, -5330, -5520, -5708, -5897, -6084, ++ -6270, -6455, -6639, -6823, -7005, -7186, -7366, -7545, ++ -7723, -7900, -8076, -8250, -8423, -8595, -8765, -8935, ++ -9102, -9269, -9434, -9598, -9760, -9921, -10080, -10238, ++ -10394, -10549, -10702, -10853, -11003, -11151, -11297, -11442, ++ -11585, -11727, -11866, -12004, -12140, -12274, -12406, -12537, ++ -12665, -12792, -12916, -13039, -13160, -13279, -13395, -13510, ++ -13623, -13733, -13842, -13949, -14053, -14155, -14256, -14354, ++ -14449, -14543, -14635, -14724, -14811, -14896, -14978, -15059, ++ -15137, -15213, -15286, -15357, -15426, -15493, -15557, -15619, ++ -15679, -15736, -15791, -15843, -15893, -15941, -15986, -16029, ++ -16069, -16107, -16143, -16176, -16207, -16235, -16261, -16284, ++ -16305, -16324, -16340, -16353, -16364, -16373, -16379, -16383, ++ -16384, -16383, -16379, -16373, -16364, -16353, -16340, -16324, ++ -16305, -16284, -16261, -16235, -16207, -16176, -16143, -16107, ++ -16069, -16029, -15986, -15941, -15893, -15843, -15791, -15736, ++ -15679, -15619, -15557, -15493, -15426, -15357, -15286, -15213, ++ -15137, -15059, -14978, -14896, -14811, -14724, -14635, -14543, ++ -14449, -14354, -14256, -14155, -14053, -13949, -13842, -13733, ++ -13623, -13510, -13395, -13279, -13160, -13039, -12916, -12792, ++ -12665, -12537, -12406, -12274, -12140, -12004, -11866, -11727, ++ -11585, -11442, -11297, -11151, -11003, -10853, -10702, -10549, ++ -10394, -10238, -10080, -9921, -9760, -9598, -9434, -9269, ++ -9102, -8935, -8765, -8595, -8423, -8250, -8076, -7900, ++ -7723, -7545, -7366, -7186, -7005, -6823, -6639, -6455, ++ -6270, -6084, -5897, -5708, -5520, -5330, -5139, -4948, ++ -4756, -4563, -4370, -4176, -3981, -3786, -3590, -3393, ++ -3196, -2999, -2801, -2603, -2404, -2205, -2006, -1806, ++ -1606, -1406, -1205, -1005, -804, -603, -402, -201, ++ 0, 201, 402, 603, 804, 1005, 1205, 1406, ++ 1606, 1806, 2006, 2205, 2404, 2603, 2801, 2999, ++ 3196, 3393, 3590, 3786, 3981, 4176, 4370, 4563, ++ 4756, 4948, 5139, 5330, 5520, 5708, 5897, 6084, ++ 6270, 6455, 6639, 6823, 7005, 7186, 7366, 7545, ++ 7723, 7900, 8076, 8250, 8423, 8595, 8765, 8935, ++ 9102, 9269, 9434, 9598, 9760, 9921, 10080, 10238, ++ 10394, 10549, 10702, 10853, 11003, 11151, 11297, 11442, ++ 11585, 11727, 11866, 12004, 12140, 12274, 12406, 12537, ++ 12665, 12792, 12916, 13039, 13160, 13279, 13395, 13510, ++ 13623, 13733, 13842, 13949, 14053, 14155, 14256, 14354, ++ 14449, 14543, 14635, 14724, 14811, 14896, 14978, 15059, ++ 15137, 15213, 15286, 15357, 15426, 15493, 15557, 15619, ++ 15679, 15736, 15791, 15843, 15893, 15941, 15986, 16029, ++ 16069, 16107, 16143, 16176, 16207, 16235, 16261, 16284, ++ 16305, 16324, 16340, 16353, 16364, 16373, 16379, 16383, ++}; ++ ++/** ++ * LSP VQ tables ++ */ ++static const int16_t lsp_band0[LSP_CB_SIZE][3] = { ++ { 0, 0, 0}, { -270, -1372, -1032}, { -541, -1650, -1382}, ++ { -723, -2011, -2213}, { -941, -1122, -1942}, { -780, -1145, -2454}, ++ { -884, -1309, -1373}, {-1051, -1523, -1766}, {-1083, -1622, -2300}, ++ { -777, -1377, -2147}, { -935, -1467, -2763}, { -802, -1327, -3471}, ++ { -935, -1959, -3999}, { -240, -89, 222}, { -661, -257, -160}, ++ { -994, -466, -419}, { -188, -164, -278}, { -342, -512, -415}, ++ { -607, -511, -797}, { 16, 19, -716}, { 374, 425, -972}, ++ { -346, 245, -282}, { -265, 506, -754}, { -620, -147, 1955}, ++ { -742, -860, 2597}, { -150, -352, 2704}, { 305, 880, 1954}, ++ { 123, 731, 2766}, { -348, 765, 3327}, { 618, 221, 3258}, ++ { -178, -47, 4219}, { 393, 1304, 3842}, { 698, 1702, 4801}, ++ { 63, -584, 1229}, { -215, -732, 1704}, { 172, -335, 1909}, ++ { -2, 216, 1797}, { 353, 127, 2205}, {-1208, 188, 11}, ++ { -513, -75, -683}, { -973, 222, -646}, { -616, -843, -388}, ++ { -950, -1113, -359}, {-1431, -623, -705}, {-1398, -1063, -178}, ++ { -45, -461, 35}, { -9, -657, -216}, { 127, -1078, 95}, ++ { -950, -1156, 584}, {-1480, -1494, 449}, { -120, -705, 516}, ++ { -368, -961, 727}, { -378, -526, 973}, { -793, -614, 676}, ++ { -801, -755, 1287}, {-1476, -340, 1636}, { -505, -1254, 1543}, ++ {-1243, -1622, 1532}, { -776, -1477, -655}, {-1151, -1296, -823}, ++ {-1153, -1672, -1124}, {-1291, -2003, -1702}, { -622, -1283, 57}, ++ { -471, -1611, 509}, {-1060, -1570, -139}, { -873, -2156, -536}, ++ {-1716, -2021, -364}, {-2150, -3218, -1291}, {-1248, -1945, -2904}, ++ {-1215, -2633, -2855}, { 167, -244, 84}, { 349, -412, -217}, ++ { -40, -352, 632}, { 227, -529, 405}, { 68, -383, -443}, ++ { 167, -558, -706}, { -275, -854, -14}, { -351, -1089, -449}, ++ { 341, -72, -289}, { 603, -106, -474}, { 322, -219, -649}, ++ { 179, -317, -998}, { 450, -291, -996}, { 555, 195, -525}, ++ { 784, 272, -831}, { -148, -384, -849}, { 82, -536, -1357}, ++ { 238, -172, -1354}, { 422, -268, -1841}, { 297, -737, -2079}, ++ { -111, -801, -598}, { 1, -668, -984}, { -131, -818, -1299}, ++ { -329, -521, -1310}, { -151, -778, -1834}, { -93, -352, -1746}, ++ { -568, -640, -1821}, { -509, -941, -2183}, { 464, -815, -1250}, ++ { 79, -1133, -1597}, { -184, -1353, -2123}, { -196, -410, -2427}, ++ { -192, -833, -2810}, { -259, -1382, -3045}, { -217, 4, -1166}, ++ { -800, -325, -1219}, { -363, -830, -898}, { -661, -1134, -960}, ++ { -386, -980, -1501}, { -627, -1159, -1722}, { -903, -829, -855}, ++ { -685, -829, -1313}, {-1065, -959, -1405}, { 441, 25, -847}, ++ { 655, -27, -1181}, { 1159, -110, -705}, { 856, 253, -1671}, ++ { 415, 404, -1}, { 322, 903, -398}, { 670, 499, -292}, ++ { 803, 591, -610}, { 1144, 591, -814}, { 717, 183, 393}, ++ { 857, 381, 106}, { 609, 62, -27}, { 792, 198, -325}, ++ { 735, 805, 88}, { 1142, 812, 78}, { 1028, 366, -292}, ++ { 1309, 743, -237}, { 1615, 589, -79}, { 1010, 639, -243}, ++ { 999, 964, -311}, { 1500, 1137, -615}, { 988, 357, 646}, ++ { 1227, 667, 683}, { 1164, 1565, 894}, { 1392, 2015, 477}, ++ { 1138, 533, 250}, { 1437, 896, 391}, { 1765, 1118, 99}, ++ { 1112, 1090, 802}, { 1596, 846, 1134}, { 937, 1161, 279}, ++ { 1719, 1254, 683}, { 1338, 1086, 35}, { 1419, 1324, 428}, ++ { 1428, 1524, 40}, { 2108, 1594, 89}, { 1015, 544, 1222}, ++ { 1121, 925, 1263}, { 1030, 1318, 1485}, { 1295, 789, 1817}, ++ { 1323, 1272, 1909}, { 1724, 1237, 1803}, { 1797, 1689, 858}, ++ { 2149, 1367, 1301}, { 2302, 1867, 761}, { 2863, 2351, 1053}, ++ { 52, 163, -76}, { 230, 309, -492}, { -71, 619, 39}, ++ { -218, 856, 499}, { -654, 736, -207}, { -535, 1259, 155}, ++ { -480, 1476, 643}, { 262, 1081, 102}, { 309, 1592, -182}, ++ { 627, 1629, 534}, { 337, 643, 456}, { 758, 670, 713}, ++ { 202, 1126, 658}, { 612, 1131, 666}, { 686, 1223, 1136}, ++ { -131, 377, 525}, { 42, 708, 907}, { 87, 1488, 1035}, ++ { 432, 2117, 904}, { 137, 981, 1332}, { -447, 1014, 1136}, ++ { -839, 1793, 1246}, { -559, 297, 198}, { -850, 685, 446}, ++ {-1273, 632, 826}, { -401, -544, 173}, { -753, -793, 144}, ++ { -436, -9, 772}, { -115, -243, 1310}, { -670, -269, 374}, ++ {-1027, -13, 639}, { -887, -81, 1137}, {-1277, -455, 158}, ++ {-1411, -720, 736}, { 172, 88, 403}, { 386, 255, 756}, ++ { -500, 522, 910}, { -958, 659, 1388}, { -395, 301, 1344}, ++ { -356, 768, 1813}, { -613, 841, 2419}, { 445, -122, 252}, ++ { 629, -87, 723}, { 283, -253, 870}, { 456, -116, 1381}, ++ { 757, 180, 1059}, { 532, 408, 1509}, { 947, 288, 1806}, ++ { 1325, 994, 2524}, { 892, 1219, 3023}, { 1397, 1596, 3406}, ++ { 1143, 1552, 2546}, { 1850, 1433, 2710}, { -10, 134, 1002}, ++ { 154, 499, 1323}, { 508, 792, 1117}, { 509, 1340, 1616}, ++ { 762, 862, 1608}, { 787, 740, 2320}, { 794, 1727, 1283}, ++ { 465, 2108, 1660}, { -120, 1451, 1613}, { -386, 2016, 2169}, ++ { 891, 1225, 2050}, { 456, 1480, 2185}, { 1493, 1283, 1209}, ++ { 1397, 1636, 1518}, { 1776, 1738, 1552}, { 1572, 1698, 2141}, ++ { 1389, 2126, 1271}, { 1959, 2413, 1119}, { 1365, 2892, 1505}, ++ { 2206, 1971, 1623}, { 2076, 1950, 2280}, { 1717, 2291, 1867}, ++ { 2366, 2515, 1953}, { 2865, 2838, 2522}, { 2535, 3465, 2011}, ++ { 3381, 4127, 2638}, { 836, 2667, 2289}, { 1761, 2773, 2337}, ++ { 1415, 3325, 2911}, { 2354, 3138, 3126}, { 2659, 4192, 4010}, ++ { 1048, 1786, 1818}, { 1242, 2111, 2240}, { 1512, 2079, 2780}, ++ { 1573, 2491, 3138}, { 2230, 2377, 2782}, { 416, 1773, 2704}, ++ { 725, 2336, 3297}, { 1252, 2373, 3978}, { 2094, 2268, 3568}, ++ { 2011, 2712, 4528}, { 1341, 3507, 3876}, { 1216, 3919, 4922}, ++ { 1693, 4793, 6012} ++}; ++ ++static const int16_t lsp_band1[LSP_CB_SIZE][3] = { ++ { 0, 0, 0}, {-2114, -1302, 76}, {-2652, -1278, -1368}, ++ {-2847, -828, -349}, {-3812, -2190, -349}, {-3946, -364, -449}, ++ {-2725, -4492, -3607}, {-3495, -4764, -1744}, { -51, -756, 84}, ++ { -153, -1191, 504}, { 108, -1418, 1167}, { -835, -896, 390}, ++ { -569, -1702, 87}, {-1151, -1818, 933}, {-1826, -2547, 411}, ++ {-1842, -1818, 1451}, {-2438, -1611, 781}, {-2747, -2477, 1311}, ++ { -940, 1252, 477}, {-1629, 1688, 602}, {-1202, 617, 280}, ++ {-1737, 393, 580}, {-1528, 1077, 1199}, {-2165, -161, 1408}, ++ {-2504, -1087, 2371}, {-3458, -175, 1395}, {-1397, -98, -843}, ++ {-2252, -177, -1149}, {-1489, -726, -1283}, {-1558, -265, -1744}, ++ {-1867, -821, -1897}, {-2062, -1516, -2340}, {-2595, -1142, -2861}, ++ { 170, 46, -819}, { -193, -204, -1151}, { 326, -196, -1532}, ++ { 780, 329, -816}, { 201, 369, -1243}, { 650, -209, -1060}, ++ { 1144, -15, -1216}, { 1203, -259, -1867}, { -890, -564, -1430}, ++ { -638, -852, -1921}, { 177, -739, -1358}, { -261, -526, -1666}, ++ { 206, -407, -2255}, { 338, -526, -822}, { 421, -1095, -1009}, ++ { 765, -607, -1408}, { 825, -1295, -2004}, { 357, -905, -1815}, ++ { -58, -1248, -1588}, { -596, -1436, -2046}, { -73, -1159, -2116}, ++ { -115, -1382, -2581}, { -160, -1723, -1952}, { -6, -2196, -2954}, ++ { -649, -1705, -2603}, { -617, -1453, -3282}, { -949, -2019, -3102}, ++ { -812, 1544, 1937}, {-1854, 574, 2000}, {-1463, 1140, 2649}, ++ {-2683, 1748, 1452}, {-2486, 2241, 2523}, { 783, 1910, 1435}, ++ { 581, 2682, 1376}, { 236, 2197, 1885}, { -453, 2943, 2057}, ++ { -682, 2178, 2565}, {-1342, 3201, 3328}, { -288, -184, 262}, ++ { 121, -149, -183}, { 758, -412, 206}, { 1038, -204, 853}, ++ { 1577, -457, 700}, { 937, -640, -567}, { 1508, -528, -1024}, ++ { -225, -527, -427}, { -564, -1095, -332}, { -742, -353, -186}, ++ {-1288, -459, 84}, {-1853, -484, -274}, {-1554, -731, 825}, ++ {-2425, -234, 382}, {-1722, 293, -271}, {-2515, 425, -564}, ++ {-2599, 818, 464}, { -358, 118, -375}, { -613, 198, -874}, ++ { -690, 683, -324}, {-1352, 1155, -168}, {-1093, 129, -324}, ++ {-1184, 611, -858}, { 433, 386, -372}, { -120, 486, -634}, ++ { 234, 851, -631}, { 602, 128, 46}, { 1099, 410, 159}, ++ { 715, -145, -424}, { 1198, -85, -593}, { 1390, 367, -358}, ++ { 1683, 362, -964}, { 1711, 622, 45}, { 2033, 833, -383}, ++ { 2890, 549, -506}, { 7, 401, 52}, { 72, 811, 415}, ++ { 566, 668, 41}, { 467, 1218, 130}, { 68, 957, -187}, ++ { -25, 1649, -103}, { -661, 260, 214}, { -925, -94, 612}, ++ { -321, -422, 965}, { -788, -672, 1783}, { 400, -673, 779}, ++ { 741, -595, 1635}, { -161, 307, 657}, { -382, 836, 871}, ++ { -814, 400, 1223}, { 364, 606, 1247}, { 57, 75, 1571}, ++ { 151, 471, 2287}, { -81, 1021, 1502}, { 227, 1470, 1097}, ++ { 658, 1275, 1653}, { 664, 1478, 2377}, { 263, -127, 444}, ++ { 264, 89, 969}, { 794, 171, 576}, { 821, 186, 1226}, ++ { 404, 462, 517}, { 339, 918, 794}, { 1280, 1423, 196}, ++ { 1453, 2019, 365}, { 1615, 1481, 672}, { 2394, 1708, 508}, ++ { 806, 1238, 573}, { 713, 1158, 1078}, { 1285, 1436, 1232}, ++ { 1790, 1188, 1141}, { 765, 643, 864}, { 1032, 797, 1279}, ++ { 900, 563, 1827}, { 1514, 673, 2312}, { 1544, 1129, 3240}, ++ { 1469, 1050, 1594}, { 1945, 1318, 1988}, { 2397, 2026, 2060}, ++ { 3538, 2057, 2620}, { 1249, -118, 74}, { 1727, 194, 421}, ++ { 2078, -50, -463}, { 970, 688, -432}, { 1149, 952, -110}, ++ { 1254, 1275, -651}, { 1386, 929, 401}, { 1960, 1167, 232}, ++ { 407, -752, -243}, { 859, -1118, 172}, { -227, -860, -992}, ++ { -796, -1175, -1380}, { 8, -1282, -388}, { 353, -1781, -1037}, ++ { -732, -397, -807}, { -853, -28, -1342}, {-1229, -1207, -1959}, ++ {-1015, -1125, -2543}, {-1452, -1791, -2725}, {-1891, -2416, -3269}, ++ { -918, -1629, -783}, { -580, -2155, -698}, {-1097, -2364, -96}, ++ {-1387, -1513, 7}, {-1588, -2076, -664}, {-1473, -2740, -784}, ++ {-2378, -3149, -56}, {-2856, -2092, -169}, {-3391, -3708, 316}, ++ {-1176, -890, -614}, {-1944, -1061, -800}, { -299, -1517, -1000}, ++ { -640, -1850, -1526}, {-1454, -1536, -1233}, {-1890, -1955, -1756}, ++ {-1086, -1921, -2122}, { -750, -2325, -2260}, {-1325, -2413, -2673}, ++ {-1114, -2542, -3459}, {-1341, -2901, -3963}, {-1160, -2226, -1393}, ++ {-1001, -2772, -1573}, {-1594, -2641, -1978}, {-1534, -3046, -2624}, ++ {-2224, -2196, -675}, {-2807, -3054, -1102}, {-2008, -2840, -1186}, ++ {-1980, -3332, -1695}, {-1715, -3562, -505}, {-2527, -4000, -1887}, ++ {-2333, -2734, -2296}, {-3440, -2401, -3211}, {-2008, -3528, -3337}, ++ {-2247, -3291, -4510}, { -475, 949, 155}, { -149, 1365, 545}, ++ { -757, 1644, 1083}, { -217, 2053, 1353}, {-1433, 2301, 1462}, ++ { 495, 1661, 529}, { 10, 2037, 740}, { 2082, 1898, 978}, ++ { 2831, 2294, 911}, { 842, 793, 420}, { 1223, 1023, 863}, ++ { 1237, 451, 780}, { 1744, 708, 822}, { 1533, 284, 1384}, ++ { 2135, 609, 1538}, { 2305, 626, 540}, { 2368, 1187, 955}, ++ { 2586, 1255, -7}, { 3116, 1131, 726}, { 3431, 1730, 428}, ++ { 2734, 1648, 1307}, { 2988, 1231, 2010}, { 3523, 2024, 1488}, ++ { 1034, 1657, 871}, { 1206, 2163, 1036}, { 1807, 2372, 1233}, ++ { 1808, 1769, 1493}, { 1573, 2332, 1779}, { 1216, 1609, 1866}, ++ { 1480, 1898, 2513}, { 465, 2708, 2776}, { 771, 3638, 3338}, ++ { 1869, 2599, 2623}, { 2825, 2745, 2468}, { 2638, 2439, 1585}, ++ { 2094, 2970, 1308}, { 2022, 3057, 1999}, { 3428, 2912, 1816}, ++ { 4536, 2974, 2129}, { 1046, 2563, 2086}, { 1363, 3562, 2318}, ++ { 2511, 1891, 2984}, { 1866, 2306, 3986}, { 3272, 2924, 3682}, ++ { 3146, 3564, 2272}, { 3592, 3968, 2822}, { 2431, 3369, 3069}, ++ { 1931, 4709, 3090}, { 2629, 4220, 3986}, { 4639, 4056, 3664}, ++ { 4035, 5334, 4912} ++}; ++ ++static const int16_t lsp_band2[LSP_CB_SIZE][4] = { ++ { 0, 0, 0, 0}, { 601, 512, -542, 334}, ++ { 428, 1087, -484, -132}, { 652, 622, -391, -572}, ++ { 378, 799, 141, -860}, { 1040, 409, 112, -554}, ++ { 1123, 670, -75, -847}, { 1421, 494, -315, -1095}, ++ { 787, 1001, 114, -460}, { 988, 1672, 216, -681}, ++ { 1007, 1241, -132, -1247}, { 1073, 399, 186, -5}, ++ { 1262, 193, -694, -129}, { 325, 196, 51, -641}, ++ { 861, -59, 350, -458}, { 1261, 567, 586, -346}, ++ { 1532, 885, 210, -517}, { 2027, 937, 113, -792}, ++ { 1383, 1064, 334, 38}, { 1964, 1468, 459, 133}, ++ { 2062, 1186, -98, -121}, { 2577, 1445, 506, -373}, ++ { 2310, 1682, -2, -960}, { 2876, 1939, 765, 138}, ++ { 3581, 2360, 649, -414}, { 219, 176, -398, -309}, ++ { 434, -78, -435, -880}, { -344, 301, 265, -552}, ++ { -915, 470, 657, -380}, { 419, -432, -163, -453}, ++ { 351, -953, 8, -562}, { 789, -43, 20, -958}, ++ { 302, -594, -352, -1159}, { 1040, 108, -668, -924}, ++ { 1333, 210, -1217, -1663}, { 483, 589, -350, -1140}, ++ { 1003, 824, -802, -1184}, { 745, 58, -589, -1443}, ++ { 346, 247, -915, -1683}, { 270, 796, -720, -2043}, ++ { 1208, 722, -222, -193}, { 1486, 1180, -412, -672}, ++ { 1722, 179, -69, -521}, { 2047, 860, -666, -1410}, ++ { -146, 222, -281, -805}, { -189, 90, -114, -1307}, ++ { -152, 1086, -241, -764}, { -439, 733, -601, -1302}, ++ { -833, -167, -351, -601}, { -856, -422, -411, -1059}, ++ { -747, -355, -582, -1644}, { -837, 210, -916, -1144}, ++ {-1800, 32, -878, -1687}, { -48, -23, -1146, 52}, ++ { -350, -409, -1656, -364}, { 265, -728, -858, -577}, ++ { 458, -247, -1141, -997}, { 691, -407, -1988, -1161}, ++ { -66, -104, -705, -1249}, { -431, -93, -1191, -1844}, ++ { 203, -732, -1000, -1693}, { 10, -832, -1846, -1819}, ++ { 493, -128, -1436, -1768}, { 488, -311, -1730, -2540}, ++ { -653, -532, -1150, -1172}, {-1086, -289, -1706, -1533}, ++ { -699, -1205, -1216, -1766}, {-1032, -1481, -2074, -1523}, ++ { -721, -1220, -2277, -2600}, { 12, -539, -1484, -1131}, ++ { -40, -911, -2106, -441}, { -471, -484, -2267, -1549}, ++ { -141, -988, -3006, -1721}, {-1545, -2102, -583, 342}, ++ {-1383, -2772, -386, -13}, {-2118, -2589, -1205, 72}, ++ {-2147, -3231, -965, 390}, {-2949, -3300, -621, 637}, ++ {-3907, -4138, -865, 803}, {-1287, -845, -375, -548}, ++ {-1416, -1169, -487, -1277}, {-1400, -1690, -1027, -418}, ++ {-2018, -1909, -1188, -1260}, {-1418, -2222, -2029, -128}, ++ {-2067, -2998, -2693, -310}, { -950, -1028, -1538, 185}, ++ {-1616, -915, -2205, -549}, { 19, -821, -1145, 352}, ++ { 184, -1175, -1356, -627}, { -547, -1088, -1661, -911}, ++ { -216, -1502, -2197, -948}, { -795, -1306, -2374, -451}, ++ { -924, -1889, -2796, -680}, { -600, -1614, -3609, -885}, ++ {-2392, -2528, 319, 303}, {-2908, -2095, -310, 573}, ++ {-3460, -2141, 49, -113}, {-2231, -448, 675, -146}, ++ {-2805, -532, 1231, 479}, {-2684, -486, -200, 611}, ++ {-3525, -971, -198, 704}, {-3707, 173, 349, 254}, ++ {-4734, -1447, -34, 880}, { 777, -512, 114, -10}, ++ { 1250, -66, 442, -5}, { 604, 613, 452, -352}, ++ { 1224, 777, 675, -1014}, {-1372, -79, -1208, -238}, ++ {-2389, -17, -1157, -818}, {-1504, -673, -1133, -1060}, ++ {-1984, -799, -2005, -1973}, {-2037, -798, -1068, -105}, ++ {-3190, -899, -1817, -194}, { -156, -886, 394, -318}, ++ { -258, -1283, 551, 202}, { -536, -1729, 910, 331}, ++ { -847, -1109, 795, -163}, {-1171, -1128, 715, 519}, ++ {-1080, -1319, 1685, 668}, {-1000, -1921, 96, 211}, ++ {-1487, -2148, 831, 174}, {-1139, -374, 414, -4}, ++ {-1517, -1383, 396, -352}, {-1012, 439, -59, -967}, ++ {-1812, 706, -440, -1030}, {-1971, -329, -34, -827}, ++ {-2472, -1588, -151, -606}, {-2161, 374, -281, 76}, ++ {-3012, 231, -15, -690}, { 1104, 566, 721, 209}, ++ { 1685, 564, 383, 98}, { 1898, 750, 792, -97}, ++ { 556, -64, 561, -93}, { 876, 162, 913, -22}, ++ { 961, 675, 1296, 140}, { 756, -396, 851, 544}, ++ { 360, -303, 1341, 396}, { 878, -22, 1464, 863}, ++ { -309, -273, 642, -129}, { -686, -82, 842, 454}, ++ { -5, -47, 1069, 998}, { -94, 967, 1277, 298}, ++ { -489, 385, 1473, 746}, { -369, -717, 1333, 242}, ++ { 281, -993, 1726, 924}, { 464, 601, 1575, 1376}, ++ { -250, 206, 2339, 1175}, { -438, 377, -597, -285}, ++ {-1020, 787, -790, -287}, { -458, -410, 215, 295}, ++ { -589, -860, -121, 797}, {-1175, 122, -437, 466}, ++ {-1480, -121, 367, 924}, { 234, 323, 770, -555}, ++ { 145, 30, 996, 26}, { 66, 849, 93, -145}, ++ { -117, 1261, 474, -399}, {-1495, 1051, 218, -506}, ++ {-1390, 694, 994, 88}, { 616, 7, 78, 304}, ++ { 1060, 52, -62, 835}, { 833, 454, 649, 1359}, ++ { -770, 464, 47, 93}, { -574, 1199, -39, 379}, ++ { 114, -98, 488, 485}, { 727, 244, 606, 696}, ++ { -76, 455, 671, 546}, { -565, -13, 145, 819}, ++ { -376, 569, 448, 1128}, { 218, 122, 265, 1167}, ++ { 230, 738, 932, 1003}, { 138, 477, 36, 450}, ++ { 404, 787, -73, 1000}, { 497, 1259, 387, 1231}, ++ { 17, 207, 195, -79}, { 562, 358, 53, -158}, ++ { 493, 387, 478, 189}, { 678, 831, 640, 558}, ++ { -197, 523, 613, 57}, { 429, 894, 769, 111}, ++ { 67, 1174, 568, 511}, { 1242, 824, 251, 840}, ++ { 1419, 1074, 864, 481}, { 924, 1474, 669, 724}, ++ { 1539, 1879, 654, 1590}, { 445, 337, 1111, 541}, ++ { 472, 1421, 1264, 1094}, { 794, 735, 1103, 668}, ++ { 1055, 863, 1192, 1020}, { 778, 1105, 806, 1798}, ++ { 1052, 1527, 1587, 2151}, { 881, 1552, 1265, 391}, ++ { 726, 872, 1812, 601}, { 1469, 280, 1008, 616}, ++ { 1403, 577, 1803, 1244}, { 1650, 1314, 1148, 1072}, ++ { 1297, 1669, 1911, 1026}, { 2093, 1044, 2115, 1189}, ++ { 1644, 1961, 2587, 1512}, { 25, -315, -9, -106}, ++ { 290, -339, 428, -444}, { -68, -783, 735, 772}, ++ { 245, -555, 468, 47}, { 334, -895, 814, 146}, ++ { 235, 368, -964, -959}, { -203, 315, -1566, -1217}, ++ { 801, 17, -276, -354}, { 894, -495, -789, -635}, ++ { 716, 291, -1189, -357}, { 560, -260, -733, -2}, ++ { 679, -508, -1429, 211}, { -51, -62, -428, 557}, ++ { 322, -638, -211, 614}, { -878, -1057, -84, -71}, ++ { -388, -1415, -167, -318}, { -754, -1574, 214, -539}, ++ {-1419, -2004, -92, -787}, { -47, -856, -347, -255}, ++ { 23, -1211, -173, 320}, { -658, -487, -893, 353}, ++ { -783, -1587, -584, 507}, {-1420, -859, -378, 441}, ++ {-2095, -1491, -137, 439}, { -321, -1450, -1288, -12}, ++ { -359, -2113, -553, -8}, { -831, -1918, -1561, 32}, ++ {-1014, -2487, -1359, -939}, { -475, -311, -169, -236}, ++ { -907, -426, 276, -611}, { -96, -400, 50, -710}, ++ { -426, -1022, -10, -985}, { -197, -258, -744, -575}, ++ { -611, -930, -771, -394}, { -267, -776, -612, -939}, ++ { -256, -1346, -802, -1122}, { -796, -1570, -825, -754}, ++ { 712, 876, 141, 227}, { 981, 1509, 85, 124}, ++ { 1462, 1228, 979, -39}, { 1734, 999, 1481, 440}, ++ { 2293, 1116, 769, 440}, { 2504, 1480, 1241, 356}, ++ { 2474, 1909, 1558, 810}, { 917, 1134, 607, -134}, ++ { 509, 1809, 781, -123}, { 1712, 1506, 559, -423}, ++ { 2037, 2317, 726, -155}, { 3031, 2676, 1203, 331}, ++ { 3664, 3274, 1768, 531}, { 1610, 1839, 867, 183}, ++ { 1774, 1972, 1538, 97}, { 1822, 2158, 1282, 659}, ++ { 2222, 2758, 1818, 900}, { 3251, 2124, 1723, 996}, ++ { 3633, 2336, 2408, 1453}, { 2923, 3517, 2567, 1318}, ++}; ++ ++/** ++ * Used for the coding/decoding of the pulses positions ++ * for the MP-MLQ codebook ++ */ ++static const int32_t combinatorial_table[PULSE_MAX][SUBFRAME_LEN/GRID_SIZE] = { ++ {118755, 98280, 80730, 65780, 53130, ++ 42504, 33649, 26334, 20349, 15504, ++ 11628, 8568, 6188, 4368, 3003, ++ 2002, 1287, 792, 462, 252, ++ 126, 56, 21, 6, 1, ++ 0, 0, 0, 0, 0}, ++ ++ { 23751, 20475, 17550, 14950, 12650, ++ 10626, 8855, 7315, 5985, 4845, ++ 3876, 3060, 2380, 1820, 1365, ++ 1001, 715, 495, 330, 210, ++ 126, 70, 35, 15, 5, ++ 1, 0, 0, 0, 0}, ++ ++ { 3654, 3276, 2925, 2600, 2300, ++ 2024, 1771, 1540, 1330, 1140, ++ 969, 816, 680, 560, 455, ++ 364, 286, 220, 165, 120, ++ 84, 56, 35, 20, 10, ++ 4, 1, 0, 0, 0}, ++ ++ { 406, 378, 351, 325, 300, ++ 276, 253, 231, 210, 190, ++ 171, 153, 136, 120, 105, ++ 91, 78, 66, 55, 45, ++ 36, 28, 21, 15, 10, ++ 6, 3, 1, 0, 0}, ++ ++ { 29, 28, 27, 26, 25, ++ 24, 23, 22, 21, 20, ++ 19, 18, 17, 16, 15, ++ 14, 13, 12, 11, 10, ++ 9, 8, 7, 6, 5, ++ 4, 3, 2, 1, 0}, ++ ++ { 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1}, ++}; ++ ++static const int16_t pitch_contrib[340] = { ++ 60, 0, 0, 2489, 60, 0, 0, 5217, ++ 1, 6171, 0, 3953, 0, 10364, 1, 9357, ++ -1, 8843, 1, 9396, 0, 5794, -1, 10816, ++ 2, 11606, -2, 12072, 0, 8616, 1, 12170, ++ 0, 14440, 0, 7787, -1, 13721, 0, 18205, ++ 0, 14471, 0, 15807, 1, 15275, 0, 13480, ++ -1, 18375, -1, 0, 1, 11194, -1, 13010, ++ 1, 18836, -2, 20354, 1, 16233, -1, 0, ++ 60, 0, 0, 12130, 0, 13385, 1, 17834, ++ 1, 20875, 0, 21996, 1, 0, 1, 18277, ++ -1, 21321, 1, 13738, -1, 19094, -1, 20387, ++ -1, 0, 0, 21008, 60, 0, -2, 22807, ++ 0, 15900, 1, 0, 0, 17989, -1, 22259, ++ 1, 24395, 1, 23138, 0, 23948, 1, 22997, ++ 2, 22604, -1, 25942, 0, 26246, 1, 25321, ++ 0, 26423, 0, 24061, 0, 27247, 60, 0, ++ -1, 25572, 1, 23918, 1, 25930, 2, 26408, ++ -1, 19049, 1, 27357, -1, 24538, 60, 0, ++ -1, 25093, 0, 28549, 1, 0, 0, 22793, ++ -1, 25659, 0, 29377, 0, 30276, 0, 26198, ++ 1, 22521, -1, 28919, 0, 27384, 1, 30162, ++ -1, 0, 0, 24237, -1, 30062, 0, 21763, ++ 1, 30917, 60, 0, 0, 31284, 0, 29433, ++ 1, 26821, 1, 28655, 0, 31327, 2, 30799, ++ 1, 31389, 0, 32322, 1, 31760, -2, 31830, ++ 0, 26936, -1, 31180, 1, 30875, 0, 27873, ++ -1, 30429, 1, 31050, 0, 0, 0, 31912, ++ 1, 31611, 0, 31565, 0, 25557, 0, 31357, ++ 60, 0, 1, 29536, 1, 28985, -1, 26984, ++ -1, 31587, 2, 30836, -2, 31133, 0, 30243, ++ -1, 30742, -1, 32090, 60, 0, 2, 30902, ++ 60, 0, 0, 30027, 0, 29042, 60, 0, ++ 0, 31756, 0, 24553, 0, 25636, -2, 30501, ++ 60, 0, -1, 29617, 0, 30649, 60, 0, ++ 0, 29274, 2, 30415, 0, 27480, 0, 31213, ++ -1, 28147, 0, 30600, 1, 31652, 2, 29068, ++ 60, 0, 1, 28571, 1, 28730, 1, 31422, ++ 0, 28257, 0, 24797, 60, 0, 0, 0, ++ 60, 0, 0, 22105, 0, 27852, 60, 0, ++ 60, 0, -1, 24214, 0, 24642, 0, 23305, ++ 60, 0, 60, 0, 1, 22883, 0, 21601, ++ 60, 0, 2, 25650, 60, 0, -2, 31253, ++ -2, 25144, 0, 17998 ++}; ++ ++/** ++ * Number of non-zero pulses in the MP-MLQ excitation ++ */ ++static const int8_t pulses[4] = {6, 5, 6, 5}; ++ ++/** ++ * Size of the MP-MLQ fixed excitation codebooks ++ */ ++static const int32_t max_pos[4] = {593775, 142506, 593775, 142506}; ++ ++static const int16_t fixed_cb_gain[GAIN_LEVELS] = { ++ 1, 2, 3, 4, 6, 9, 13, 18, ++ 26, 38, 55, 80, 115, 166, 240, 348, ++ 502, 726, 1050, 1517, 2193, 3170, 4582, 6623, ++}; ++ ++static const int16_t adaptive_cb_gain85[85 * 20] = { ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 800, 1496, 167, -256, ++ -338, -39, -136, -1, -4, -6, -73, -8, ++ -15, 12, 23, 2, 16, 30, 3, -5, ++ -462, -686, 493, 2575, 311, -13, -28, -14, ++ -404, -5, -19, 13, 20, 72, 107, -77, ++ 8, 13, -9, -48, 1483, 144, 784, 928, ++ 1243, -134, -1, -37, -52, -94, -13, -71, ++ -6, -84, -8, -44, -112, -10, -59, -70, ++ -77, 275, 3522, 1056, -1254, 0, -4, -757, ++ -68, -95, 1, 16, -59, 4, -17, -227, ++ -5, 21, 269, 80, -125, -40, -264, 381, ++ 5027, 0, 0, -4, -8, -1542, 0, -2, ++ 0, 2, 0, 6, 38, 12, 81, -117, ++ 138, 332, 2215, 2574, 1339, -1, -6, -299, ++ -404, -109, -2, -18, -44, -21, -52, -348, ++ -11, -27, -181, -210, 3685, 2883, -887, 866, ++ -1639, -828, -507, -48, -45, -164, -648, 199, ++ 156, -194, -152, 46, 368, 288, -88, 86, ++ 1396, 2146, 2235, 345, 942, -118, -281, -305, ++ -7, -54, -182, -190, -292, -29, -45, -47, ++ -80, -123, -128, -19, 13, 4475, 3549, -804, ++ -655, 0, -1222, -768, -39, -26, -3, -2, ++ -969, 0, 219, 174, 0, 179, 141, -32, ++ -724, 254, 242, 6049, 2462, -32, -3, -3, ++ -2233, -370, 11, 10, -3, 267, -94, -89, ++ 108, -38, -36, -909, 626, -1713, 6121, 4561, ++ -1061, -23, -179, -2287, -1270, -68, 65, -233, ++ 640, -174, 477, -1704, 40, -111, 396, 295, ++ -350, 1391, 7985, 511, -405, -7, -118, -3892, ++ -15, -10, 29, 170, -678, 10, -43, -249, ++ -8, 34, 197, 12, 3144, -529, 608, 2530, ++ 3878, -603, -17, -22, -390, -918, 101, -116, ++ 19, -485, 81, -93, -744, 125, -144, -599, ++ 2589, -689, 3045, 5603, -404, -409, -29, -566, ++ -1916, -10, 108, -481, 128, -885, 235, -1041, ++ 63, -17, 75, 138, 3107, 513, 1374, -3594, ++ -4922, -589, -16, -115, -788, -1478, -97, -260, ++ -43, 681, 112, 301, 933, 154, 413, -1079, ++ 2468, 6010, 1107, -390, 1961, -372, -2204, -74, ++ -9, -234, -905, -166, -406, 58, 143, 26, ++ -295, -719, -132, 46, 4773, 2766, 2368, 4862, ++ -4044, -1390, -467, -342, -1443, -998, -806, -690, ++ -399, -1416, -821, -702, 1178, 682, 584, 1200, ++ 1665, -1879, 1443, 1701, 8562, -169, -215, -127, ++ -176, -4475, 190, -146, 165, -172, 195, -149, ++ -870, 982, -754, -889, 2716, 9011, -1007, 755, ++ -1785, -450, -4956, -61, -34, -194, -1493, 167, ++ 554, -125, -415, 46, 296, 982, -109, 82, ++ -2727, 7548, 1285, 938, 3420, -453, -3478, -100, ++ -53, -714, 1256, 213, -592, 156, -432, -73, ++ 569, -1576, -268, -196, 3677, 882, 4050, 1202, ++ 2323, -825, -47, -1001, -88, -329, -198, -909, ++ -218, -269, -64, -297, -521, -125, -574, -170, ++ 2046, -753, 122, 10102, 603, -255, -34, 0, ++ -6229, -22, 94, -15, 5, -1261, 464, -75, ++ -75, 27, -4, -372, 449, -1815, 10690, 3870, ++ -527, -12, -201, -6976, -914, -16, 49, -293, ++ 1184, -106, 428, -2525, 14, -58, 344, 124, ++ -941, 2352, 5049, 3650, 2637, -54, -337, -1556, ++ -813, -424, 135, 290, -725, 209, -524, -1125, ++ 151, -378, -812, -587, -1879, 796, 3117, 9569, ++ -404, -215, -38, -593, -5589, -9, 91, 357, ++ -151, 1097, -464, -1821, -46, 19, 76, 236, ++ -1715, 2043, -2096, 9946, 4001, -179, -254, -268, ++ -6038, -977, 213, -219, 261, 1041, -1240, 1272, ++ 418, -498, 511, -2429, -5772, -618, -3921, 284, ++ -3155, -2033, -23, -938, -4, -607, -218, -1381, ++ -148, 100, 10, 68, -1111, -119, -755, 54, ++ 382, 4748, 8003, -2064, 2198, -8, -1376, -3909, ++ -260, -294, -110, -186, -2319, 48, 598, 1008, ++ -51, -637, -1073, 277, -867, 3015, 11926, -1675, ++ 947, -45, -555, -8681, -171, -54, 159, 631, ++ -2195, -88, 308, 1219, 50, -174, -690, 96, ++ -4933, -432, 6757, 3771, 1352, -1485, -11, -2786, ++ -867, -111, -130, 2034, 178, 1135, 99, -1555, ++ 407, 35, -557, -311, 152, 9726, 4231, -1928, ++ 1490, -1, -5774, -1092, -226, -135, -90, -39, ++ -2511, 17, 1144, 498, -13, -884, -384, 175, ++ 2512, 193, 9033, 5361, -3148, -385, -2, -4980, ++ -1754, -605, -29, -1385, -106, -822, -63, -2956, ++ 482, 37, 1735, 1030, 8464, 2844, 12, 549, ++ 2132, -4373, -493, 0, -18, -277, -1469, -6, ++ -2, -284, -95, 0, -1101, -370, -1, -71, ++ 2141, -2602, 7166, 9046, -1350, -279, -413, -3134, ++ -4994, -111, 340, -936, 1138, -1182, 1436, -3957, ++ 176, -214, 590, 745, -244, 278, 13307, 1227, ++ -161, -3, -4, -10808, -91, -1, 4, 198, ++ -226, 18, -20, -997, -2, 2, 131, 12, ++ -1947, 8217, 6269, 917, -2559, -231, -4121, -2399, ++ -51, -399, 976, 745, -3144, 108, -460, -350, ++ -304, 1283, 979, 143, -1810, 2061, -2781, 6056, ++ 10058, -200, -259, -472, -2238, -6174, 227, -307, ++ 349, 669, -761, 1028, 1111, -1265, 1707, -3717, ++ 7827, 9161, -3409, 2473, -1510, -3739, -5122, -709, ++ -373, -139, -4376, 1628, 1906, -1181, -1382, 514, ++ 721, 844, -314, 228, -1430, 8313, 9541, -2955, ++ 1626, -124, -4218, -5556, -533, -161, 725, 832, ++ -4841, -257, 1499, 1721, 142, -825, -947, 293, ++ 2819, -4247, 5391, 8673, 2756, -485, -1101, -1774, ++ -4591, -463, 730, -927, 1397, -1492, 2248, -2854, ++ -474, 714, -907, -1459, 141, 14552, 690, 257, ++ -112, -1, -12926, -29, -4, 0, -125, -5, ++ -613, -2, -228, -10, 0, 99, 4, 1, ++ 11938, -1859, 1806, -962, -884, -8699, -211, -199, ++ -56, -47, 1355, -1316, 205, 701, -109, 106, ++ 644, -100, 97, -51, 3728, 1982, 2264, 4584, ++ 3131, -848, -239, -312, -1282, -598, -451, -515, ++ -273, -1043, -554, -633, -712, -378, -432, -876, ++ -1181, 766, 720, 14303, -216, -85, -35, -31, ++ -12486, -2, 55, 51, -33, 1031, -668, -628, ++ -15, 10, 9, 189, -4385, 4826, 10112, 1569, ++ 3388, -1173, -1421, -6242, -150, -700, 1291, 2706, ++ -2979, 420, -462, -969, 906, -998, -2091, -324, ++ -448, 1932, 15591, -1842, 657, -12, -227, -14837, ++ -207, -26, 52, 427, -1838, -50, 217, 1753, ++ 18, -77, -626, 74, -4141, 1844, 3962, 5517, ++ 6220, -1046, -207, -958, -1858, -2361, 466, 1001, ++ -446, 1394, -621, -1334, 1572, -700, -1504, -2094, ++ 729, -2299, 14755, 3657, -952, -32, -322, -13288, ++ -816, -55, 102, -656, 2071, -162, 513, -3294, ++ 42, -133, 857, 212, -1385, 5801, 13339, -3137, ++ 1344, -117, -2054, -10861, -600, -110, 490, 1127, ++ -4723, -265, 1111, 2554, 113, -476, -1094, 257, ++ 4710, 9661, 1073, -2467, 3274, -1354, -5697, -70, ++ -371, -654, -2777, -308, -633, 709, 1455, 161, ++ -941, -1930, -214, 493, 1843, -3624, 12422, 6898, ++ -1559, -207, -802, -9419, -2904, -148, 407, -1397, ++ 2748, -775, 1526, -5230, 175, -344, 1182, 656, ++ 1433, 2394, 2507, 1380, 8780, -125, -349, -383, ++ -116, -4705, -209, -219, -366, -120, -201, -211, ++ -768, -1283, -1343, -740, -1712, 12915, 5883, -2197, ++ 991, -179, -10181, -2112, -294, -60, 1350, 615, ++ -4638, -229, 1732, 789, 103, -781, -356, 133, ++ 15072, 2158, -1245, 910, -496, -13865, -284, -94, ++ -50, -15, -1986, 1145, 164, -837, -119, 69, ++ 456, 65, -37, 27, 4655, 7319, 4916, 586, ++ -3381, -1322, -3270, -1475, -20, -697, -2079, -1396, ++ -2196, -166, -261, -175, 960, 1510, 1014, 120, ++ 1191, -2140, 5120, 13498, -1418, -86, -279, -1600, ++ -11121, -122, 155, -372, 669, -981, 1763, -4218, ++ 103, -185, 443, 1168, -1530, -817, 8191, 9632, ++ -1452, -143, -40, -4095, -5663, -128, -76, 765, ++ 408, 900, 480, -4815, -135, -72, 726, 854, ++ -3236, 607, 1696, -2106, 11485, -639, -22, -175, ++ -270, -8051, 119, 335, -62, -416, 78, 218, ++ 2268, -425, -1189, 1476, 3203, -1903, -837, 9679, ++ 7057, -626, -221, -42, -5718, -3039, 372, 163, ++ -97, -1892, 1124, 494, -1380, 819, 360, -4169, ++ 213, -655, 17015, 620, -384, -2, -26, -17671, ++ -23, -9, 8, -221, 681, -8, 24, -644, ++ 5, -15, 399, 14, 5088, 35, -3339, 3726, ++ 8488, -1580, 0, -680, -847, -4397, -10, 1037, ++ 7, -1157, -8, 759, -2636, -18, 1730, -1930, ++ -988, 1454, -2688, 15039, 2682, -59, -129, -441, ++ -13805, -439, 87, -162, 238, 907, -1335, 2467, ++ 161, -238, 440, -2462, -4865, -2842, -53, 5495, ++ 6523, -1445, -493, 0, -1843, -2597, -844, -16, ++ -9, 1632, 953, 18, 1937, 1131, 21, -2188, ++ 3076, 15069, -2914, 1810, -971, -577, -13860, -518, ++ -200, -57, -2829, 547, 2680, -339, -1665, 322, ++ 182, 893, -172, 107, 1311, 5355, 11054, 2299, ++ -3654, -105, -1750, -7458, -322, -814, -428, -885, ++ -3613, -184, -751, -1551, 292, 1194, 2465, 512, ++ 4035, 5619, 4618, 1815, 1912, -994, -1927, -1301, ++ -201, -223, -1384, -1137, -1583, -447, -622, -511, ++ -471, -656, -539, -211, -2131, 2754, -4501, 12879, ++ 7432, -277, -463, -1236, -10124, -3371, 358, -585, ++ 756, 1675, -2165, 3538, 967, -1249, 2042, -5842, ++ 5618, -515, 3219, -4149, 4857, -1926, -16, -632, ++ -1050, -1440, 176, -1104, 101, 1422, -130, 815, ++ -1666, 152, -954, 1230, 1838, -1709, 1139, 16867, ++ 716, -206, -178, -79, -17366, -31, 191, -127, ++ 118, -1892, 1759, -1173, -80, 74, -49, -737, ++ 1978, -3845, 10050, 11854, -2492, -238, -902, -6164, ++ -8576, -379, 464, -1213, 2358, -1431, 2782, -7271, ++ 301, -585, 1529, 1803, -2600, 11246, 11289, -3647, ++ 1463, -412, -7720, -7778, -812, -130, 1784, 1791, ++ -7749, -578, 2504, 2513, 232, -1004, -1008, 325, ++ 3442, 907, 2725, 8970, 3638, -723, -50, -453, ++ -4911, -808, -190, -572, -150, -1884, -496, -1492, ++ -764, -201, -605, -1992, -126, 17498, 3481, -2003, ++ 1090, 0, -18689, -739, -244, -72, 135, 26, ++ -3717, -15, 2139, 425, 8, -1165, -231, 133, ++ -1814, 1048, -2164, 4070, 16272, -200, -67, -285, ++ -1011, -16160, 116, -239, 138, 450, -260, 537, ++ 1801, -1041, 2149, -4042, 9354, 12580, -1883, 962, ++ -617, -5341, -9660, -216, -56, -23, -7183, 1075, ++ 1446, -549, -738, 110, 352, 474, -71, 36, ++ 1708, 4199, 7387, 6335, 1003, -178, -1076, -3330, ++ -2449, -61, -437, -770, -1893, -660, -1623, -2856, ++ -104, -257, -452, -388, -2624, 5623, 17310, -2353, ++ 592, -420, -1930, -18288, -338, -21, 900, 2772, ++ -5941, -376, 807, 2486, 94, -203, -625, 85, ++ 1211, -850, 1193, -1926, 15992, -89, -44, -86, ++ -226, -15609, 62, -88, 61, 142, -100, 140, ++ -1182, 830, -1165, 1880, 3983, -2054, 11506, -19, ++ 3622, -968, -257, -8080, 0, -801, 499, -2797, ++ 1442, 4, -2, 13, -880, 454, -2544, 4, ++ -786, -1354, 16092, 7246, -1665, -37, -111, -15805, ++ -3205, -169, -65, 772, 1330, 348, 599, -7117, ++ -80, -137, 1636, 736, -4316, -511, 6674, 11665, ++ 4633, -1137, -15, -2719, -8305, -1310, -134, 1758, ++ 208, 3073, 364, -4752, 1220, 144, -1887, -3299, ++ 7912, 4557, 1937, 1885, 7037, -3821, -1267, -229, ++ -216, -3022, -2200, -935, -538, -910, -524, -222, ++ -3398, -1957, -832, -809, 3434, 2967, 5867, 8196, ++ 8766, -720, -537, -2101, -4100, -4690, -622, -1230, ++ -1062, -1718, -1484, -2935, -1837, -1588, -3139, -4385, ++ 5881, 9176, 8119, 3934, 3355, -2111, -5139, -4023, ++ -944, -687, -3294, -2914, -4547, -1412, -2203, -1949, ++ -1204, -1879, -1662, -805 ++}; ++ ++static const int16_t adaptive_cb_gain170[170 * 20] = { ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 776, 212, 715, 670, ++ 809, -36, -2, -31, -27, -39, -10, -33, ++ -9, -31, -8, -29, -38, -10, -35, -33, ++ 1296, 1316, -168, -320, -815, -102, -105, -1, ++ -6, -40, -104, 13, 13, 25, 25, -3, ++ 64, 65, -8, -15, -589, 680, 2478, 308, ++ -596, -21, -28, -375, -5, -21, 24, 89, ++ -102, 11, -12, -46, -21, 24, 90, 11, ++ -735, -487, -5, 2948, 468, -33, -14, 0, ++ -530, -13, -21, 0, 0, 132, 87, 0, ++ 21, 13, 0, -84, 1042, 1730, 1068, 333, ++ 626, -66, -182, -69, -6, -23, -110, -67, ++ -112, -21, -35, -21, -39, -66, -40, -12, ++ 486, -769, 4074, 2825, -1107, -14, -36, -1013, ++ -487, -74, 22, -120, 191, -83, 132, -702, ++ 32, -52, 275, 191, 1521, -767, -124, 4320, ++ 1026, -141, -35, 0, -1139, -64, 71, 11, ++ -5, -401, 202, 32, -95, 48, 7, -270, ++ 2425, 1267, 3439, -91, -1166, -359, -98, -722, ++ 0, -83, -187, -509, -266, 13, 7, 19, ++ 172, 90, 244, -6, -1251, 975, 173, 4039, ++ 2005, -95, -58, -1, -996, -245, 74, 13, ++ -10, 308, -240, -42, 153, -119, -21, -494, ++ 1820, 632, 1322, 2062, 1031, -202, -24, -106, ++ -259, -64, -70, -146, -51, -229, -79, -166, ++ -114, -39, -83, -129, -447, 4904, 244, -315, ++ -2038, -12, -1467, -3, -6, -253, 134, 6, ++ -73, -8, 94, 4, -55, 610, 30, -39, ++ -208, -1102, 463, -448, 5653, -2, -74, -13, ++ -12, -1950, -14, 5, 31, -5, -30, 12, ++ 71, 380, -159, 154, 4739, 2600, -1864, 856, ++ -1554, -1371, -412, -212, -44, -147, -752, 539, ++ 295, -247, -135, 97, 449, 246, -176, 81, ++ 1894, 3533, 35, -26, 2145, -219, -762, 0, ++ 0, -280, -408, -4, -7, 3, 5, 0, ++ -248, -462, -4, 3, -2699, 1841, 4072, 2443, ++ 1582, -444, -207, -1012, -364, -152, 303, 670, ++ -457, 402, -274, -607, 260, -177, -393, -236, ++ -844, 3358, 6106, -1059, -537, -43, -688, -2275, ++ -68, -17, 173, 314, -1251, -54, 217, 395, ++ -27, 110, 200, -34, 1251, 1016, 3020, 2210, ++ 1445, -95, -63, -556, -298, -127, -77, -230, ++ -187, -168, -137, -407, -110, -89, -266, -194, ++ 2099, 2277, 4038, 3533, -2870, -269, -316, -995, ++ -762, -503, -291, -517, -561, -452, -491, -871, ++ 367, 399, 707, 619, 400, -1114, 8516, 2422, ++ -1117, -9, -75, -4426, -358, -76, 27, -208, ++ 579, -59, 164, -1259, 27, -75, 580, 165, ++ -4398, -2011, 3912, -2407, 2258, -1180, -247, -934, ++ -353, -311, -540, 1050, 480, -646, -295, 575, ++ 606, 277, -539, 331, 1767, -1447, 4240, 6160, ++ -757, -190, -127, -1097, -2316, -35, 156, -457, ++ 374, -664, 544, -1594, 81, -66, 195, 284, ++ 1594, -1463, 1035, 6938, 1920, -155, -130, -65, ++ -2938, -225, 142, -100, 92, -675, 619, -438, ++ -186, 171, -121, -813, -562, 4716, 4085, -591, ++ 2421, -19, -1357, -1018, -21, -357, 162, 140, ++ -1175, -20, 170, 147, 83, -696, -603, 87, ++ 1552, 8778, -935, 354, -1424, -147, -4703, -53, ++ -7, -123, -831, 88, 501, -33, -189, 20, ++ 134, 763, -81, 30, 4831, -4431, 41, -1479, ++ -2976, -1424, -1198, 0, -133, -540, 1306, -12, ++ 11, 436, -400, 3, 877, -804, 7, -268, ++ 2090, 1192, 1006, 1645, 4853, -266, -86, -61, ++ -165, -1437, -152, -128, -73, -210, -119, -101, ++ -619, -353, -298, -487, 2386, 5712, 1426, -94, ++ 1350, -347, -1991, -124, 0, -111, -832, -207, ++ -497, 13, 32, 8, -196, -470, -117, 7, ++ -1349, 1091, 1659, 8891, 313, -111, -72, -168, ++ -4825, -5, 89, 136, -110, 732, -592, -900, ++ 25, -20, -31, -170, 9980, 916, -381, -808, ++ 88, -6080, -51, -8, -39, 0, -558, 232, ++ 21, 492, 45, -18, -53, -4, 2, 4, ++ 2338, -1031, -248, 3928, 6484, -333, -64, -3, ++ -942, -2566, 147, 35, -15, -560, 247, 59, ++ -925, 408, 98, -1555, 6166, -1240, -337, 3672, ++ -1277, -2320, -93, -6, -823, -99, 466, 126, ++ -25, -1382, 278, 75, 480, -96, -26, 286, ++ 4377, -132, -2588, 1701, 4865, -1169, -1, -409, ++ -176, -1444, 35, 691, -20, -454, 13, 268, ++ -1299, 39, 768, -505, 2594, 3295, 3944, 1481, ++ 682, -410, -662, -949, -133, -28, -521, -624, ++ -793, -234, -297, -356, -108, -137, -164, -61, ++ 4151, 624, 815, 4485, 2229, -1052, -23, -40, ++ -1228, -303, -158, -206, -31, -1136, -170, -223, ++ -565, -84, -111, -610, -3575, -361, 4924, 2791, ++ 4698, -780, -7, -1480, -475, -1347, -78, 1074, ++ 108, 609, 61, -839, 1025, 103, -1412, -800, ++ -2518, 3791, 8623, 315, 2465, -387, -877, -4538, ++ -6, -370, 582, 1325, -1995, 48, -73, -166, ++ 378, -570, -1297, -47, -691, 2989, 9957, -421, ++ -1142, -29, -545, -6051, -10, -79, 126, 420, ++ -1817, -17, 76, 256, -48, 208, 694, -29, ++ -1918, 104, -3190, -3410, -4440, -224, 0, -621, ++ -709, -1203, 12, -373, 20, -399, 21, -664, ++ -519, 28, -864, -924, -3359, -1668, 1854, 6939, ++ 1430, -688, -169, -209, -2939, -124, -341, 380, ++ 188, 1422, 706, -785, 293, 145, -161, -606, ++ 42, 9706, 3164, -952, 907, 0, -5750, -611, ++ -55, -50, -25, -8, -1874, 2, 564, 183, ++ -2, -537, -175, 52, 1607, 785, 2862, 4327, ++ 3307, -157, -37, -500, -1143, -667, -77, -280, ++ -137, -424, -207, -756, -324, -158, -577, -873, ++ 6801, 3416, 2227, 1682, -3217, -2823, -712, -302, ++ -172, -631, -1418, -924, -464, -698, -350, -228, ++ 1335, 670, 437, 330, 3459, 3898, 364, 7841, ++ -2640, -730, -927, -8, -3753, -425, -823, -76, ++ -86, -1655, -1865, -174, 557, 628, 58, 1263, ++ -5902, -3458, -2465, -1886, 4334, -2126, -730, -371, ++ -217, -1146, -1245, -888, -520, -679, -398, -283, ++ 1561, 915, 652, 499, -3710, 1133, 7849, 3443, ++ -215, -840, -78, -3760, -723, -2, 256, 1777, ++ -543, 779, -238, -1649, -48, 14, 103, 45, ++ 4132, 2828, 2, -4212, -4116, -1042, -488, 0, ++ -1083, -1034, -713, 0, 0, 1062, 727, 0, ++ 1038, 710, 0, -1058, 5875, 8496, -1796, 1376, ++ -1786, -2107, -4406, -197, -115, -194, -3047, 644, ++ 931, -493, -713, 150, 640, 926, -195, 150, ++ 3143, 3483, 3546, -793, 4489, -603, -740, -767, ++ -38, -1230, -668, -680, -754, 152, 168, 171, ++ -861, -954, -971, 217, 2845, 7965, 3695, -5432, ++ 3978, -494, -3873, -833, -1801, -966, -1383, -641, ++ -1796, 943, 2641, 1225, -691, -1934, -897, 1319, ++ 1538, 150, 7139, 2049, 3097, -144, -1, -3110, ++ -256, -585, -14, -670, -65, -192, -18, -892, ++ -290, -28, -1349, -387, 618, 7520, 4729, -238, ++ -3373, -23, -3452, -1365, -3, -694, -283, -178, ++ -2170, 8, 109, 68, 127, 1548, 973, -49, ++ 2965, -3013, 7912, 7076, -1997, -536, -554, -3821, ++ -3056, -243, 545, -1431, 1455, -1280, 1301, -3417, ++ 361, -367, 964, 862, 2443, -929, -1113, 9677, ++ 4138, -364, -52, -75, -5716, -1045, 138, 166, ++ -63, -1443, 549, 657, -617, 234, 281, -2444, ++ 1966, 3309, 10085, -3399, 2105, -236, -668, -6207, ++ -705, -270, -397, -1210, -2037, 408, 686, 2092, ++ -252, -425, -1295, 436, -112, -1368, 8868, 4822, ++ 2048, 0, -114, -4800, -1419, -256, -9, 61, ++ 740, 33, 402, -2610, 14, 171, -1108, -602, ++ -2597, 438, -1839, 6229, 7266, -411, -11, -206, ++ -2368, -3223, 69, -291, 49, 987, -166, 699, ++ 1152, -194, 816, -2763, 3454, 553, 9127, 4946, ++ -5596, -728, -18, -5084, -1493, -1911, -116, -1924, ++ -308, -1042, -166, -2755, 1179, 188, 3117, 1689, ++ -532, -663, 12262, 2495, -1004, -17, -26, -9177, ++ -380, -61, -21, 398, 496, 81, 101, -1867, ++ -32, -40, 751, 152, -2100, 1317, -1509, 11425, ++ 2997, -269, -105, -139, -7967, -548, 168, -193, ++ 121, 1464, -918, 1052, 384, -240, 276, -2090, ++ 1193, -2697, 11259, 5373, -763, -86, -444, -7737, ++ -1762, -35, 196, -819, 1853, -391, 884, -3692, ++ 55, -125, 525, 250, 2405, -471, 11079, 203, ++ 782, -353, -13, -7491, -2, -37, 69, -1626, ++ 318, -29, 5, -137, -114, 22, -529, -9, ++ -1871, 5685, 11290, -2662, 1353, -213, -1972, -7780, ++ -432, -111, 649, 1289, -3917, -304, 923, 1834, ++ 154, -469, -932, 220, -3768, 5927, -3093, 5041, ++ 5212, -866, -2144, -584, -1551, -1658, 1363, -711, ++ 1119, 1159, -1824, 951, 1198, -1885, 984, -1603, ++ -2546, 9502, 5969, -2440, 1928, -395, -5511, -2175, ++ -363, -226, 1477, 927, -3462, -379, 1415, 889, ++ 299, -1118, -702, 287, -4963, 3568, 4592, 5508, ++ 3451, -1503, -777, -1287, -1851, -727, 1080, 1391, ++ -1000, 1668, -1199, -1543, 1045, -751, -967, -1160, ++ 1745, -2586, 3983, 10899, -1551, -186, -408, -968, ++ -7250, -146, 275, -424, 628, -1161, 1720, -2649, ++ 165, -244, 377, 1032, 867, -456, -727, 3369, ++ 11822, -45, -12, -32, -692, -8531, 24, 38, ++ -20, -178, 93, 149, -625, 329, 525, -2431, ++ 7535, 2422, 1926, 1405, 1599, -3466, -358, -226, ++ -120, -156, -1114, -886, -284, -646, -207, -165, ++ -735, -236, -188, -137, 1041, -735, -142, 13209, ++ 1515, -66, -33, -1, -10649, -140, 46, 9, ++ -6, -839, 593, 114, -96, 68, 13, -1222, ++ 7950, 6745, -1444, -1008, 2721, -3857, -2777, -127, ++ -62, -452, -3273, 700, 594, 489, 415, -88, ++ -1320, -1120, 239, 167, -4754, -1379, 4522, -578, ++ -5733, -1379, -116, -1248, -20, -2006, -400, 1312, ++ 380, -167, -48, 159, -1663, -482, 1582, -202, ++ 3220, 5978, 5923, 2430, -2689, -633, -2181, -2141, ++ -360, -441, -1175, -1164, -2161, -477, -886, -878, ++ 528, 981, 972, 398, 377, 1312, 13978, -1470, ++ 677, -8, -105, -11925, -132, -28, -30, -321, ++ -1119, 33, 117, 1254, -15, -54, -577, 60, ++ -3435, 6770, 314, -885, 5686, -720, -2797, -6, ++ -47, -1973, 1419, 65, -129, -185, 366, 16, ++ 1192, -2349, -109, 307, 3171, 8774, -2260, 2679, ++ 3069, -613, -4699, -312, -438, -575, -1698, 437, ++ 1210, -518, -1435, 369, -594, -1643, 423, -501, ++ 5557, 1509, 5407, -125, -7386, -1884, -139, -1784, ++ 0, -3330, -511, -1834, -498, 42, 11, 41, ++ 2505, 680, 2438, -56, -2838, 2595, 13228, 271, ++ 1793, -491, -411, -10680, -4, -196, 449, 2291, ++ -2095, 47, -42, -219, 310, -284, -1447, -29, ++ 664, -278, 14966, 951, -711, -26, -4, -13672, ++ -55, -30, 11, -606, 253, -38, 16, -869, ++ 28, -12, 650, 41, 808, 1770, 8658, 5863, ++ -1486, -39, -191, -4576, -2098, -134, -87, -427, ++ -935, -289, -633, -3098, 73, 160, 785, 531, ++ 3063, 1539, 2000, -542, 9576, -572, -144, -244, ++ -17, -5597, -287, -374, -188, 101, 51, 66, ++ -1790, -900, -1169, 317, 514, 14083, -323, 896, ++ -891, -16, -12106, -6, -49, -48, -442, 10, ++ 277, -28, -770, 17, 27, 766, -17, 48, ++ 892, 158, 5237, 11057, -1603, -48, -1, -1674, ++ -7462, -156, -8, -285, -50, -602, -106, -3534, ++ 87, 15, 512, 1082, -1612, 2564, -4296, 12526, ++ 5710, -158, -401, -1126, -9576, -1990, 252, -422, ++ 672, 1232, -1960, 3284, 561, -893, 1497, -4365, ++ 4889, -6878, 612, 6109, 4753, -1459, -2887, -22, ++ -2277, -1379, 2052, -182, 257, -1823, 2564, -228, ++ -1418, 1995, -177, -1772, 3053, -506, 2403, 9625, ++ 1322, -569, -15, -352, -5655, -106, 94, -448, ++ 74, -1794, 297, -1412, -246, 40, -194, -777, ++ -754, 12904, 4480, -2113, 1471, -34, -10163, -1225, ++ -272, -132, 594, 206, -3529, -97, 1664, 577, ++ 67, -1159, -402, 189, 4255, 1476, 5055, 2393, ++ 2912, -1105, -132, -1559, -349, -517, -383, -1313, ++ -455, -621, -215, -738, -756, -262, -898, -425, ++ -1371, 535, 1417, 14604, -997, -114, -17, -122, ++ -13017, -60, 44, 118, -46, 1222, -477, -1263, ++ -83, 32, 86, 888, 5368, -1744, 4083, -1236, ++ 3753, -1758, -185, -1017, -93, -860, 571, -1338, ++ 434, 405, -131, 308, -1229, 399, -935, 283, ++ 1588, -3097, 14415, 3699, -1171, -154, -585, -12683, ++ -835, -83, 300, -1397, 2725, -358, 699, -3255, ++ 113, -221, 1030, 264, 212, 7989, 9471, -3344, ++ 2009, -2, -3895, -5475, -682, -246, -103, -123, ++ -4618, 43, 1630, 1933, -26, -979, -1161, 410, ++ 856, 2294, -627, 6930, 6929, -44, -321, -24, ++ -2931, -2930, -119, 32, 87, -362, -970, 265, ++ -362, -970, 265, -2931, 2357, -4187, 7162, 7683, ++ 3371, -339, -1070, -3131, -3603, -693, 602, -1030, ++ 1830, -1105, 1963, -3359, -485, 861, -1474, -1581, ++ 350, 4585, 14053, -3819, 1218, -7, -1283, -12054, ++ -890, -90, -97, -300, -3933, 81, 1068, 3275, ++ -26, -341, -1045, 284, -3248, 3531, 475, 2137, ++ 11711, -644, -761, -13, -278, -8372, 700, 94, ++ -102, 423, -460, -62, 2322, -2524, -340, -1528, ++ -3017, 3852, 1725, 8440, 5257, -555, -905, -181, ++ -4348, -1686, 709, 317, -405, 1554, -1984, -889, ++ 968, -1236, -553, -2708, -909, 3196, 15512, -2528, ++ 1066, -50, -623, -14686, -390, -69, 177, 861, ++ -3026, -140, 493, 2393, 59, -208, -1009, 164, ++ 959, -3370, 9617, 9545, -1761, -56, -693, -5645, ++ -5561, -189, 197, -563, 1978, -558, 1963, -5603, ++ 103, -362, 1034, 1026, 7575, 11796, -4845, 3252, ++ -1703, -3502, -8493, -1433, -645, -177, -5454, 2240, ++ 3488, -1503, -2341, 961, 787, 1226, -503, 338, ++ 6409, 1722, 1764, -4191, 6015, -2507, -181, -189, ++ -1072, -2208, -673, -690, -185, 1639, 440, 451, ++ -2353, -632, -647, 1538, -2420, 12161, 5038, 1286, ++ -2098, -357, -9027, -1549, -100, -268, 1796, 744, ++ -3740, 190, -954, -395, -310, 1557, 645, 164, ++ -2232, -1341, 7246, 9470, -1977, -304, -109, -3204, ++ -5474, -238, -182, 987, 593, 1290, 775, -4188, ++ -269, -161, 874, 1143, 1030, 7034, 4231, 1551, ++ 3077, -64, -3019, -1093, -146, -577, -442, -266, ++ -1816, -97, -666, -400, -193, -1321, -794, -291, ++ 5121, 11835, -477, -1749, 2298, -1601, -8549, -13, ++ -186, -322, -3699, 149, 344, 546, 1264, -50, ++ -718, -1660, 66, 245, -3328, 3827, 5921, 9976, ++ -1045, -676, -894, -2140, -6075, -66, 777, 1203, ++ -1383, 2027, -2330, -3605, -212, 244, 377, 636, ++ 3813, 5718, -4666, -3412, 5674, -887, -1995, -1329, ++ -710, -1965, -1331, 1086, 1628, 794, 1191, -972, ++ -1320, -1980, 1616, 1181, 1348, -3672, 13154, 6938, ++ -1690, -110, -823, -10561, -2938, -174, 302, -1082, ++ 2948, -570, 1555, -5570, 139, -379, 1357, 716, ++ 2151, -3586, 6949, 12131, -1224, -282, -785, -2947, ++ -8982, -91, 470, -912, 1521, -1592, 2655, -5145, ++ 160, -268, 519, 906, -2889, 9647, 10276, -2728, ++ 995, -509, -5680, -6445, -454, -60, 1701, 1812, ++ -6051, -481, 1606, 1711, 175, -586, -624, 165, ++ 6177, 2184, 555, 1985, 6589, -2329, -291, -18, ++ -240, -2650, -823, -209, -74, -748, -264, -67, ++ -2484, -878, -223, -798, -492, 391, 17166, -681, ++ 240, -14, -9, -17987, -28, -3, 11, 515, ++ -410, -20, 16, 713, 7, -5, -252, 10, ++ 12628, 5448, -2630, 3011, -2695, -9733, -1811, -422, ++ -553, -443, -4199, 2027, 874, -2321, -1001, 483, ++ 2077, 896, -432, 495, -3628, -534, 3447, 7002, ++ 6751, -803, -17, -725, -2992, -2782, -118, 763, ++ 112, 1550, 228, -1473, 1495, 220, -1420, -2885, ++ -5239, 5901, 8107, 3650, 4846, -1675, -2125, -4012, ++ -813, -1433, 1887, 2592, -2920, 1167, -1315, -1806, ++ 1550, -1745, -2398, -1080, 6157, 6678, 4099, -1074, ++ 2348, -2314, -2722, -1025, -70, -336, -2509, -1540, ++ -1670, 403, 437, 268, -882, -957, -587, 153, ++ 1079, 16099, 242, -881, 1690, -71, -15820, -3, ++ -47, -174, -1060, -16, -238, 58, 865, 13, ++ -111, -1661, -25, 90, -278, 227, -1039, 1636, ++ 16945, -4, -3, -65, -163, -17526, 3, -17, ++ 14, 27, -22, 103, 287, -234, 1074, -1693, ++ 15778, -1454, 574, -603, -107, -15195, -129, -20, ++ -22, 0, 1400, -553, 51, 581, -53, 21, ++ 103, -9, 3, -3, 2406, -836, 13224, 7993, ++ -4266, -353, -42, -10673, -3899, -1111, 122, -1942, ++ 674, -1174, 407, -6451, 626, -217, 3443, 2081, ++ 3184, 14368, -3336, 2255, -1801, -619, -12600, -679, ++ -310, -198, -2793, 648, 2926, -438, -1977, 459, ++ 350, 1580, -366, 247, -1698, 17076, 2504, -539, ++ -646, -176, -17798, -382, -17, -25, 1770, 259, ++ -2610, -55, 561, 82, -67, 673, 98, -21, ++ 2375, -797, -2696, 14483, 5383, -344, -38, -443, ++ -12803, -1769, 115, 391, -131, -2100, 705, 2384, ++ -780, 262, 886, -4759, -2691, 2554, -4520, 9573, ++ 10655, -442, -398, -1247, -5594, -6930, 419, -742, ++ 704, 1572, -1492, 2641, 1750, -1661, 2939, -6226, ++ -4332, -4399, -1657, 4880, 7375, -1145, -1181, -167, ++ -1453, -3319, -1163, -438, -444, 1290, 1310, 493, ++ 1950, 1980, 745, -2196, -3498, 7405, 9955, 2693, ++ -2971, -746, -3347, -6049, -442, -538, 1581, 2125, ++ -4499, 575, -1217, -1636, -634, 1342, 1805, 488, ++ 6717, -3792, 7739, 2798, 3489, -2754, -877, -3655, ++ -477, -743, 1554, -3173, 1791, -1147, 647, -1321, ++ -1430, 807, -1648, -595, 5263, 9770, 3463, 1069, ++ -3971, -1690, -5826, -732, -69, -962, -3138, -1112, ++ -2065, -343, -637, -226, 1275, 2368, 839, 259, ++ 1243, -2634, 16772, 1871, 332, -94, -423, -17169, ++ -213, -6, 199, -1273, 2696, -142, 300, -1915, ++ -25, 53, -339, -37, 2691, 2836, 3105, 5711, ++ 4817, -442, -491, -588, -1991, -1416, -465, -510, ++ -537, -938, -988, -1082, -791, -834, -913, -1679, ++ 4366, 2944, 7210, 3627, 1161, -1163, -529, -3172, ++ -803, -82, -784, -1921, -1295, -966, -651, -1596, ++ -309, -208, -511, -257, 13888, 3951, -671, -2305, ++ 3354, -11773, -953, -27, -324, -686, -3349, 569, ++ 161, 1954, 556, -94, -2843, -809, 137, 472, ++ 7053, 5847, 2929, 8378, -4794, -3036, -2086, -523, ++ -4284, -1403, -2517, -1261, -1045, -3607, -2990, -1498, ++ 2064, 1711, 857, 2451, -2191, 12838, 9182, -3915, ++ 1617, -293, -10059, -5146, -935, -159, 1717, 1228, ++ -7195, -523, 3068, 2194, 216, -1267, -906, 386, ++ -4881, 13114, 5767, -435, 4155, -1454, -10498, -2030, ++ -11, -1054, 3907, 1718, -4616, -129, 348, 153, ++ 1238, -3326, -1462, 110, 7843, -1250, 210, 7106, ++ -5203, -3754, -95, -2, -3082, -1652, 598, -100, ++ 16, -3402, 542, -91, 2491, -397, 66, 2257, ++ -2463, 8168, 14551, -3908, 1828, -370, -4072, -12923, ++ -932, -204, 1228, 2188, -7254, -587, 1948, 3471, ++ 274, -911, -1623, 436, -1579, 347, -272, -2735, ++ 16031, -152, -7, -4, -456, -15686, 33, -26, ++ 5, -263, 58, -45, 1545, -340, 266, 2676, ++ -6327, 1328, 5093, -5079, 7617, -2443, -107, -1583, ++ -1574, -3541, 513, 1967, -413, -1961, 411, 1578, ++ 2941, -617, -2367, 2361, 3286, -4509, 11306, 11025, ++ -2623, -659, -1241, -7802, -7419, -420, 904, -2267, ++ 3112, -2211, 3034, -7608, 526, -722, 1810, 1765, ++ 5567, 17853, -3754, 1166, -519, -1892, -19455, -860, ++ -83, -16, -6067, 1275, 4090, -396, -1271, 267, ++ 176, 566, -119, 37, -2136, -424, 15292, 5108, ++ -1648, -278, -10, -14273, -1593, -165, -55, 1993, ++ 396, 666, 132, -4768, -214, -42, 1538, 514, ++ 2267, -3297, 2549, 16563, -791, -313, -663, -396, ++ -16745, -38, 456, -352, 513, -2291, 3333, -2576, ++ 109, -159, 123, 799, 3655, 1899, -3364, 6279, ++ 12510, -815, -220, -690, -2406, -9552, -423, 750, ++ 390, -1400, -728, 1289, -2791, -1450, 2568, -4794, ++ 8052, 2285, -6193, 5138, 6003, -3957, -318, -2341, ++ -1611, -2199, -1123, 3044, 864, -2525, -716, 1942, ++ -2950, -837, 2269, -1882, -386, -2291, 7679, 15387, ++ -2723, -9, -320, -3599, -14452, -452, -54, 181, ++ 1074, 362, 2152, -7212, -64, -380, 1276, 2557, ++ 2777, -1173, 3984, 13079, 2508, -470, -84, -969, ++ -10440, -384, 198, -675, 285, -2217, 936, -3180, ++ -425, 179, -610, -2002, -1879, 1771, -2684, 16705, ++ 1833, -215, -191, -439, -17032, -205, 203, -308, ++ 290, 1916, -1805, 2736, 210, -198, 300, -1869, ++ 1052, 4495, 15519, 1467, -4032, -67, -1233, -14700, ++ -131, -992, -288, -997, -4257, -94, -402, -1389, ++ 259, 1106, 3819, 361, 3010, 2544, 6969, 7559, ++ 1996, -553, -395, -2964, -3487, -243, -467, -1280, ++ -1082, -1388, -1174, -3215, -366, -310, -849, -921, ++ -5209, -1867, 8713, 10351, 1549, -1656, -212, -4634, ++ -6540, -146, -593, 2770, 993, 3291, 1180, -5505, ++ 492, 176, -824, -979, -4314, 8513, 913, 7547, ++ -2723, -1135, -4423, -50, -3476, -452, 2241, 240, ++ -474, 1987, -3921, -420, -717, 1415, 151, 1254, ++ 12929, -1219, 2448, 1757, 6303, -10204, -90, -365, ++ -188, -2425, 962, -1932, 182, -1386, 130, -262, ++ -4974, 469, -941, -676, 6465, 4132, 3167, 3160, ++ 5697, -2551, -1042, -612, -609, -1981, -1630, -1249, ++ -798, -1247, -797, -611, -2248, -1437, -1101, -1099, ++ -3636, 4859, 18914, -1335, 810, -807, -1441, -21836, ++ -108, -40, 1078, 4198, -5609, -296, 396, 1541, ++ 179, -240, -936, 66, 8844, 7864, 654, -4063, ++ -5680, -4774, -3774, -26, -1007, -1969, -4245, -353, ++ -314, 2193, 1950, 162, 3066, 2726, 226, -1408, ++ 1859, 2634, 9228, 996, 9464, -211, -423, -5197, ++ -60, -5467, -299, -1047, -1483, -113, -160, -561, ++ -1074, -1521, -5330, -575, 2949, 12260, 10290, -497, ++ -3943, -530, -9174, -6463, -15, -949, -2206, -1852, ++ -7700, 89, 372, 312, 709, 2950, 2476, -119, ++ -2903, 1552, 14867, 9970, -496, -514, -147, -13491, ++ -6068, -15, 275, 2634, -1408, 1766, -944, -9047, ++ -87, 47, 450, 302, 3243, 8234, 7586, 3373, ++ 2151, -642, -4138, -3512, -694, -282, -1630, -1501, ++ -3812, -667, -1695, -1561, -425, -1081, -996, -442, ++ -9631, 60, 3501, 5359, 10150, -5662, 0, -748, ++ -1752, -6288, 35, 2058, -12, 3150, -19, -1145, ++ 5967, -37, -2169, -3320, -6874, -2553, -5446, -2195, ++ -7841, -2884, -397, -1810, -294, -3753, -1071, -2285, ++ -848, -921, -342, -729, -3290, -1221, -2606, -1050, ++ -3413, -1141, 4630, 13612, 7897, -711, -79, -1308, ++ -11310, -3806, -237, 964, 322, 2836, 948, -3847, ++ 1645, 550, -2231, -6561, 4410, -5678, 8006, -3992, ++ 3811, -1187, -1968, -3912, -973, -886, 1528, -2155, ++ 2775, 1074, -1383, 1951, -1025, 1321, -1862, 928, ++ 5659, 11535, 2203, -452, 7169, -1954, -8121, -296, ++ -12, -3137, -3984, -761, -1551, 156, 318, 60, ++ -2476, -5048, -964, 197, 2914, -2914, 3485, -3965, ++ 13675, -518, -518, -741, -959, -11414, 518, -620, ++ 620, 705, -705, 843, -2433, 2432, -2909, 3310, ++ 7843, 1907, 1022, 8882, 7972, -3755, -222, -63, ++ -4815, -3879, -913, -489, -119, -4252, -1034, -554, ++ -3816, -928, -497, -4322, 13807, 9531, 1436, 1612, ++ 1779, -11636, -5544, -125, -158, -193, -8032, -1210, ++ -835, -1358, -938, -141, -1499, -1035, -156, -175, ++ 13620, -5337, 5450, -2263, 1723, -11322, -1738, -1813, ++ -312, -181, 4436, -4531, 1775, 1881, -737, 752, ++ -1432, 561, -573, 238, 5297, 8374, 8872, 7694, ++ 6538, -1712, -4280, -4804, -3613, -2609, -2707, -2868, ++ -4534, -2487, -3932, -4166, -2113, -3341, -3540, -3070 ++}; ++ ++/** ++ * 0.65^i (Zero part) and 0.75^i (Pole part) scaled by 2^15 ++ */ ++static const int16_t postfilter_tbl[2][LPC_ORDER] = { ++ /* Zero */ ++ {21299, 13844, 8999, 5849, 3802, 2471, 1606, 1044, 679, 441}, ++ /* Pole */ ++ {24576, 18432, 13824, 10368, 7776, 5832, 4374, 3281, 2460, 1845} ++}; ++ ++/** ++ * Hamming window coefficients scaled by 2^15 ++ */ ++static const int16_t hamming_window[LPC_FRAME] = { ++ 2621, 2631, 2659, 2705, 2770, 2853, 2955, 3074, 3212, 3367, ++ 3541, 3731, 3939, 4164, 4405, 4663, 4937, 5226, 5531, 5851, ++ 6186, 6534, 6897, 7273, 7661, 8062, 8475, 8899, 9334, 9780, ++ 10235, 10699, 11172, 11653, 12141, 12636, 13138, 13645, 14157, 14673, ++ 15193, 15716, 16242, 16769, 17298, 17827, 18356, 18884, 19411, 19935, ++ 20457, 20975, 21489, 21999, 22503, 23002, 23494, 23978, 24455, 24924, ++ 25384, 25834, 26274, 26704, 27122, 27529, 27924, 28306, 28675, 29031, ++ 29373, 29700, 30012, 30310, 30592, 30857, 31107, 31340, 31557, 31756, ++ 31938, 32102, 32249, 32377, 32488, 32580, 32654, 32710, 32747, 32766, ++ 32766, 32747, 32710, 32654, 32580, 32488, 32377, 32249, 32102, 31938, ++ 31756, 31557, 31340, 31107, 30857, 30592, 30310, 30012, 29700, 29373, ++ 29031, 28675, 28306, 27924, 27529, 27122, 26704, 26274, 25834, 25384, ++ 24924, 24455, 23978, 23494, 23002, 22503, 21999, 21489, 20975, 20457, ++ 19935, 19411, 18884, 18356, 17827, 17298, 16769, 16242, 15716, 15193, ++ 14673, 14157, 13645, 13138, 12636, 12141, 11653, 11172, 10699, 10235, ++ 9780, 9334, 8899, 8475, 8062, 7661, 7273, 6897, 6534, 6186, ++ 5851, 5531, 5226, 4937, 4663, 4405, 4164, 3939, 3731, 3541, ++ 3367, 3212, 3074, 2955, 2853, 2770, 2705, 2659, 2631, 2621 ++}; ++ ++/** ++ * Binomial window coefficients scaled by 2^15 ++ */ ++static const int16_t binomial_window[LPC_ORDER] = { ++ 32749, 32695, 32604, 32477, 32315, 32118, 31887, 31622, 31324, 30995 ++}; ++ ++/** ++ * 0.994^i scaled by 2^15 ++ */ ++static const int16_t bandwidth_expand[LPC_ORDER] = { ++ 32571, 32376, 32182, 31989, 31797, 31606, 31416, 31228, 31040, 30854 ++}; ++ ++/** ++ * 0.5^i scaled by 2^15 ++ */ ++static const int16_t percept_flt_tbl[2][LPC_ORDER] = { ++ /* Zero part */ ++ {29491, 26542, 23888, 21499, 19349, 17414, 15673, 14106, 12695, 11425}, ++ /* Pole part */ ++ {16384, 8192, 4096, 2048, 1024, 512, 256, 128, 64, 32} ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g726.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g726.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g726.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g726.c 2012-05-14 14:08:53.750328229 +0200 +@@ -22,7 +22,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include ++#include "libavutil/avassert.h" ++#include "libavutil/opt.h" + #include "avcodec.h" ++#include "internal.h" + #include "get_bits.h" + #include "put_bits.h" + +@@ -71,6 +74,8 @@ + } G726Tables; + + typedef struct G726Context { ++ AVClass *class; ++ AVFrame frame; + G726Tables tbls; /**< static tables needed for computation */ + + Float11 sr[2]; /**< prev. reconstructed samples */ +@@ -266,11 +271,11 @@ + return av_clip(re_signal << 2, -0xffff, 0xffff); + } + +-static av_cold int g726_reset(G726Context* c, int index) ++static av_cold int g726_reset(G726Context *c) + { + int i; + +- c->tbls = G726Tables_pool[index]; ++ c->tbls = G726Tables_pool[c->code_size - 2]; + for (i=0; i<2; i++) { + c->sr[i].mant = 1<<5; + c->pk[i] = 1; +@@ -295,65 +300,59 @@ + g726_decode(c, i); + return i; + } +-#endif + + /* Interfacing to the libavcodec */ + +-static av_cold int g726_init(AVCodecContext * avctx) ++static av_cold int g726_encode_init(AVCodecContext *avctx) + { + G726Context* c = avctx->priv_data; +- unsigned int index; + +- if (avctx->sample_rate <= 0) { +- av_log(avctx, AV_LOG_ERROR, "Samplerate is invalid\n"); +- return -1; ++ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && ++ avctx->sample_rate != 8000) { ++ av_log(avctx, AV_LOG_ERROR, "Sample rates other than 8kHz are not " ++ "allowed when the compliance level is higher than unofficial. " ++ "Resample or reduce the compliance level.\n"); ++ return AVERROR(EINVAL); + } ++ av_assert0(avctx->sample_rate > 0); + +- index = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate - 2; +- +- if (avctx->bit_rate % avctx->sample_rate && avctx->codec->encode) { +- av_log(avctx, AV_LOG_ERROR, "Bitrate - Samplerate combination is invalid\n"); +- return -1; +- } + if(avctx->channels != 1){ + av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); +- return -1; +- } +- if(index>3){ +- av_log(avctx, AV_LOG_ERROR, "Unsupported number of bits %d\n", index+2); +- return -1; ++ return AVERROR(EINVAL); + } +- g726_reset(c, index); +- c->code_size = index+2; ++ ++ if (avctx->bit_rate) ++ c->code_size = (avctx->bit_rate + avctx->sample_rate/2) / avctx->sample_rate; ++ ++ c->code_size = av_clip(c->code_size, 2, 5); ++ avctx->bit_rate = c->code_size * avctx->sample_rate; ++ avctx->bits_per_coded_sample = c->code_size; ++ ++ g726_reset(c); + + avctx->coded_frame = avcodec_alloc_frame(); + if (!avctx->coded_frame) + return AVERROR(ENOMEM); + avctx->coded_frame->key_frame = 1; + +- if (avctx->codec->decode) +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- + /* select a frame size that will end on a byte boundary and have a size of + approximately 1024 bytes */ +- if (avctx->codec->encode) +- avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[index]; ++ avctx->frame_size = ((int[]){ 4096, 2736, 2048, 1640 })[c->code_size - 2]; + + return 0; + } + +-static av_cold int g726_close(AVCodecContext *avctx) ++static av_cold int g726_encode_close(AVCodecContext *avctx) + { + av_freep(&avctx->coded_frame); + return 0; + } + +-#if CONFIG_ADPCM_G726_ENCODER + static int g726_encode_frame(AVCodecContext *avctx, + uint8_t *dst, int buf_size, void *data) + { + G726Context *c = avctx->priv_data; +- const short *samples = data; ++ const int16_t *samples = data; + PutBitContext pb; + int i; + +@@ -366,54 +365,124 @@ + + return put_bits_count(&pb)>>3; + } ++ ++#define OFFSET(x) offsetof(G726Context, x) ++#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "code_size", "Bits per code", OFFSET(code_size), AV_OPT_TYPE_INT, { 4 }, 2, 5, AE }, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "g726", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVCodecDefault defaults[] = { ++ { "b", "0" }, ++ { NULL }, ++}; ++ ++AVCodec ff_adpcm_g726_encoder = { ++ .name = "g726", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_G726, ++ .priv_data_size = sizeof(G726Context), ++ .init = g726_encode_init, ++ .encode = g726_encode_frame, ++ .close = g726_encode_close, ++ .capabilities = CODEC_CAP_SMALL_LAST_FRAME, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), ++ .priv_class = &class, ++ .defaults = defaults, ++}; + #endif + +-static int g726_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++#if CONFIG_ADPCM_G726_DECODER ++static av_cold int g726_decode_init(AVCodecContext *avctx) ++{ ++ G726Context* c = avctx->priv_data; ++ ++ if (avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT && ++ avctx->sample_rate != 8000) { ++ av_log(avctx, AV_LOG_ERROR, "Only 8kHz sample rate is allowed when " ++ "the compliance level is strict. Reduce the compliance level " ++ "if you wish to decode the stream anyway.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if(avctx->channels != 1){ ++ av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ c->code_size = avctx->bits_per_coded_sample; ++ if (c->code_size < 2 || c->code_size > 5) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of bits %d\n", c->code_size); ++ return AVERROR(EINVAL); ++ } ++ g726_reset(c); ++ ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ ++ return 0; ++} ++ ++static int g726_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + G726Context *c = avctx->priv_data; +- short *samples = data; ++ int16_t *samples; + GetBitContext gb; ++ int out_samples, ret; ++ ++ out_samples = buf_size * 8 / c->code_size; ++ ++ /* get output buffer */ ++ c->frame.nb_samples = out_samples; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)c->frame.data[0]; + + init_get_bits(&gb, buf, buf_size * 8); + +- while (get_bits_count(&gb) + c->code_size <= buf_size*8) ++ while (out_samples--) + *samples++ = g726_decode(c, get_bits(&gb, c->code_size)); + +- if(buf_size*8 != get_bits_count(&gb)) ++ if (get_bits_left(&gb) > 0) + av_log(avctx, AV_LOG_ERROR, "Frame invalidly split, missing parser?\n"); + +- *data_size = (uint8_t*)samples - (uint8_t*)data; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; ++ + return buf_size; + } + +-#if CONFIG_ADPCM_G726_ENCODER +-AVCodec ff_adpcm_g726_encoder = { +- "g726", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ADPCM_G726, +- sizeof(G726Context), +- g726_init, +- g726_encode_frame, +- g726_close, +- NULL, +- .capabilities = CODEC_CAP_SMALL_LAST_FRAME, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), +-}; +-#endif ++static void g726_decode_flush(AVCodecContext *avctx) ++{ ++ G726Context *c = avctx->priv_data; ++ g726_reset(c); ++} + + AVCodec ff_adpcm_g726_decoder = { +- "g726", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ADPCM_G726, +- sizeof(G726Context), +- g726_init, +- NULL, +- g726_close, +- g726_decode_frame, ++ .name = "g726", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ADPCM_G726, ++ .priv_data_size = sizeof(G726Context), ++ .init = g726_decode_init, ++ .decode = g726_decode_frame, ++ .flush = g726_decode_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("G.726 ADPCM"), + }; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729data.h 2012-05-14 14:08:53.751328249 +0200 +@@ -1,5 +1,5 @@ + /* +- * data for G.729 decoder ++ * data for G.729, G729 Annex D decoders + * Copyright (c) 2007 Vladimir Voroshilov + * + * This file is part of FFmpeg. +@@ -246,7 +246,56 @@ + }; + + /** ++ * gain codebook (first stage), 6.4k mode (D.3.9.2 of G.729) ++ */ ++static const int16_t cb_gain_1st_6k4[1< ++ + #include +-#include +-#include + #include +-#include +-#include + + #include "avcodec.h" + #include "libavutil/avutil.h" + #include "get_bits.h" ++#include "dsputil.h" + + #include "g729.h" + #include "lsp.h" + #include "celp_math.h" ++#include "celp_filters.h" + #include "acelp_filters.h" + #include "acelp_pitch_delay.h" + #include "acelp_vectors.h" + #include "g729data.h" ++#include "g729postfilter.h" + + /** + * minimum quantized LSF value (3.2.4) +@@ -56,6 +55,9 @@ + */ + #define LSFQ_DIFF_MIN 321 + ++/// interpolation filter length ++#define INTERPOL_LEN 11 ++ + /** + * minimum gain pitch value (3.8, Equation 47) + * 0.2 in (1.14) +@@ -71,6 +73,21 @@ + */ + #define SHARP_MAX 13017 + ++/** ++ * MR_ENERGY (mean removed energy) = mean_energy + 10 * log10(2^26 * subframe_size) in (7.13) ++ */ ++#define MR_ENERGY 1018156 ++ ++#define DECISION_NOISE 0 ++#define DECISION_INTERMEDIATE 1 ++#define DECISION_VOICE 2 ++ ++typedef enum { ++ FORMAT_G729_8K = 0, ++ FORMAT_G729D_6K4, ++ FORMAT_COUNT, ++} G729Formats; ++ + typedef struct { + uint8_t ac_index_bits[2]; ///< adaptive codebook index for second subframe (size in bits) + uint8_t parity_bit; ///< parity bit for pitch delay +@@ -81,6 +98,13 @@ + } G729FormatDescription; + + typedef struct { ++ DSPContext dsp; ++ AVFrame frame; ++ ++ /// past excitation signal buffer ++ int16_t exc_base[2*SUBFRAME_SIZE+PITCH_DELAY_MAX+INTERPOL_LEN]; ++ ++ int16_t* exc; ///< start of past excitation data in buffer + int pitch_delay_int_prev; ///< integer part of previous subframe's pitch delay (4.1.3) + + /// (2.13) LSP quantizer outputs +@@ -90,6 +114,43 @@ + int16_t lsfq[10]; ///< (2.13) quantized LSF coefficients from previous frame + int16_t lsp_buf[2][10]; ///< (0.15) LSP coefficients (previous and current frames) (3.2.5) + int16_t *lsp[2]; ///< pointers to lsp_buf ++ ++ int16_t quant_energy[4]; ///< (5.10) past quantized energy ++ ++ /// previous speech data for LP synthesis filter ++ int16_t syn_filter_data[10]; ++ ++ ++ /// residual signal buffer (used in long-term postfilter) ++ int16_t residual[SUBFRAME_SIZE + RES_PREV_DATA_SIZE]; ++ ++ /// previous speech data for residual calculation filter ++ int16_t res_filter_data[SUBFRAME_SIZE+10]; ++ ++ /// previous speech data for short-term postfilter ++ int16_t pos_filter_data[SUBFRAME_SIZE+10]; ++ ++ /// (1.14) pitch gain of current and five previous subframes ++ int16_t past_gain_pitch[6]; ++ ++ /// (14.1) gain code from current and previous subframe ++ int16_t past_gain_code[2]; ++ ++ /// voice decision on previous subframe (0-noise, 1-intermediate, 2-voice), G.729D ++ int16_t voice_decision; ++ ++ int16_t onset; ///< detected onset level (0-2) ++ int16_t was_periodic; ///< whether previous frame was declared as periodic or not (4.4) ++ int16_t ht_prev_data; ///< previous data for 4.2.3, equation 86 ++ int gain_coeff; ///< (1.14) gain coefficient (4.2.4) ++ uint16_t rand_value; ///< random number generator value (4.4.4) ++ int ma_predictor_prev; ///< switched MA predictor of LSP quantizer from last good frame ++ ++ /// (14.14) high-pass filter data (past input) ++ int hpf_f[2]; ++ ++ /// high-pass filter data (past output) ++ int16_t hpf_z[2]; + } G729Context; + + static const G729FormatDescription format_g729_8k = { +@@ -111,7 +172,7 @@ + }; + + /** +- * \brief pseudo random number generator ++ * @brief pseudo random number generator + */ + static inline uint16_t g729_prng(uint16_t value) + { +@@ -126,6 +187,15 @@ + return (0x6996966996696996ULL >> (value >> 2)) & 1; + } + ++/* ++ * Decodes LSF (Line Spectral Frequencies) from L0-L3 (3.2.4). ++ * @param lsfq [out] (2.13) quantized LSF coefficients ++ * @param past_quantizer_outputs [in/out] (2.13) quantizer outputs from previous frames ++ * @param ma_predictor switched MA predictor of LSP quantizer ++ * @param vq_1st first stage vector of quantizer ++ * @param vq_2nd_low second stage lower vector of LSP quantizer ++ * @param vq_2nd_high second stage higher vector of LSP quantizer ++ */ + static void lsf_decode(int16_t* lsfq, int16_t* past_quantizer_outputs[MA_NP + 1], + int16_t ma_predictor, + int16_t vq_1st, int16_t vq_2nd_low, int16_t vq_2nd_high) +@@ -157,13 +227,122 @@ + lsfq[i] = sum >> 15; + } + +- /* Rotate past_quantizer_outputs. */ +- memmove(past_quantizer_outputs + 1, past_quantizer_outputs, MA_NP * sizeof(int16_t*)); +- past_quantizer_outputs[0] = quantizer_output; +- + ff_acelp_reorder_lsf(lsfq, LSFQ_DIFF_MIN, LSFQ_MIN, LSFQ_MAX, 10); + } + ++/** ++ * Restores past LSP quantizer output using LSF from previous frame ++ * @param lsfq [in/out] (2.13) quantized LSF coefficients ++ * @param past_quantizer_outputs [in/out] (2.13) quantizer outputs from previous frames ++ * @param ma_predictor_prev MA predictor from previous frame ++ * @param lsfq_prev (2.13) quantized LSF coefficients from previous frame ++ */ ++static void lsf_restore_from_previous(int16_t* lsfq, ++ int16_t* past_quantizer_outputs[MA_NP + 1], ++ int ma_predictor_prev) ++{ ++ int16_t* quantizer_output = past_quantizer_outputs[MA_NP]; ++ int i,k; ++ ++ for (i = 0; i < 10; i++) { ++ int tmp = lsfq[i] << 15; ++ ++ for (k = 0; k < MA_NP; k++) ++ tmp -= past_quantizer_outputs[k][i] * cb_ma_predictor[ma_predictor_prev][k][i]; ++ ++ quantizer_output[i] = ((tmp >> 15) * cb_ma_predictor_sum_inv[ma_predictor_prev][i]) >> 12; ++ } ++} ++ ++/** ++ * Constructs new excitation signal and applies phase filter to it ++ * @param out[out] constructed speech signal ++ * @param in original excitation signal ++ * @param fc_cur (2.13) original fixed-codebook vector ++ * @param gain_code (14.1) gain code ++ * @param subframe_size length of the subframe ++ */ ++static void g729d_get_new_exc( ++ int16_t* out, ++ const int16_t* in, ++ const int16_t* fc_cur, ++ int dstate, ++ int gain_code, ++ int subframe_size) ++{ ++ int i; ++ int16_t fc_new[SUBFRAME_SIZE]; ++ ++ ff_celp_convolve_circ(fc_new, fc_cur, phase_filter[dstate], subframe_size); ++ ++ for(i=0; i> 14; ++ out[i] += (gain_code * fc_new[i] + 0x2000) >> 14; ++ } ++} ++ ++/** ++ * Makes decision about onset in current subframe ++ * @param past_onset decision result of previous subframe ++ * @param past_gain_code gain code of current and previous subframe ++ * ++ * @return onset decision result for current subframe ++ */ ++static int g729d_onset_decision(int past_onset, const int16_t* past_gain_code) ++{ ++ if((past_gain_code[0] >> 1) > past_gain_code[1]) ++ return 2; ++ else ++ return FFMAX(past_onset-1, 0); ++} ++ ++/** ++ * Makes decision about voice presence in current subframe ++ * @param onset onset level ++ * @param prev_voice_decision voice decision result from previous subframe ++ * @param past_gain_pitch pitch gain of current and previous subframes ++ * ++ * @return voice decision result for current subframe ++ */ ++static int16_t g729d_voice_decision(int onset, int prev_voice_decision, const int16_t* past_gain_pitch) ++{ ++ int i, low_gain_pitch_cnt, voice_decision; ++ ++ if(past_gain_pitch[0] >= 14745) // 0.9 ++ voice_decision = DECISION_VOICE; ++ else if (past_gain_pitch[0] <= 9830) // 0.6 ++ voice_decision = DECISION_NOISE; ++ else ++ voice_decision = DECISION_INTERMEDIATE; ++ ++ for(i=0, low_gain_pitch_cnt=0; i<6; i++) ++ if(past_gain_pitch[i] < 9830) ++ low_gain_pitch_cnt++; ++ ++ if(low_gain_pitch_cnt > 2 && !onset) ++ voice_decision = DECISION_NOISE; ++ ++ if(!onset && voice_decision > prev_voice_decision + 1) ++ voice_decision--; ++ ++ if(onset && voice_decision < DECISION_VOICE) ++ voice_decision++; ++ ++ return voice_decision; ++} ++ ++static int32_t scalarproduct_int16_c(const int16_t * v1, const int16_t * v2, int order, int shift) ++{ ++ int res = 0; ++ ++ while (order--) ++ res += (*v1++ * *v2++) >> shift; ++ ++ return res; ++} ++ + static av_cold int decoder_init(AVCodecContext * avctx) + { + G729Context* ctx = avctx->priv_data; +@@ -173,10 +352,13 @@ + av_log(avctx, AV_LOG_ERROR, "Only mono sound is supported (requested channels: %d).\n", avctx->channels); + return AVERROR(EINVAL); + } ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; + + /* Both 8kbit/s and 6.4kbit/s modes uses two subframes per frame. */ + avctx->frame_size = SUBFRAME_SIZE << 1; + ++ ctx->gain_coeff = 16384; // 1.0 in (1.14) ++ + for (k = 0; k < MA_NP + 1; k++) { + ctx->past_quantizer_outputs[k] = ctx->past_quantizer_output_buf[k]; + for (i = 1; i < 11; i++) +@@ -187,20 +369,37 @@ + ctx->lsp[1] = ctx->lsp_buf[1]; + memcpy(ctx->lsp[0], lsp_init, 10 * sizeof(int16_t)); + ++ ctx->exc = &ctx->exc_base[PITCH_DELAY_MAX+INTERPOL_LEN]; ++ ++ /* random seed initialization */ ++ ctx->rand_value = 21845; ++ ++ /* quantized prediction error */ ++ for(i=0; i<4; i++) ++ ctx->quant_energy[i] = -14336; // -14 in (5.10) ++ ++ dsputil_init(&ctx->dsp, avctx); ++ ctx->dsp.scalarproduct_int16 = scalarproduct_int16_c; ++ ++ avcodec_get_frame_defaults(&ctx->frame); ++ avctx->coded_frame = &ctx->frame; ++ + return 0; + } + +-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- int16_t *out_frame = data; ++ int16_t *out_frame; + GetBitContext gb; +- G729FormatDescription format; ++ const G729FormatDescription *format; + int frame_erasure = 0; ///< frame erasure detected during decoding + int bad_pitch = 0; ///< parity check failed + int i; ++ int16_t *tmp; ++ G729Formats packet_type; + G729Context *ctx = avctx->priv_data; + int16_t lp[2][11]; // (3.12) + uint8_t ma_predictor; ///< switched MA predictor of LSP quantizer +@@ -208,19 +407,31 @@ + uint8_t quantizer_2nd_lo; ///< second stage lower vector of quantizer (size in bits) + uint8_t quantizer_2nd_hi; ///< second stage higher vector of quantizer (size in bits) + +- int pitch_delay_int; // pitch delay, integer part ++ int pitch_delay_int[2]; // pitch delay, integer part + int pitch_delay_3x; // pitch delay, multiplied by 3 +- +- if (*data_size < SUBFRAME_SIZE << 2) { +- av_log(avctx, AV_LOG_ERROR, "Error processing packet: output buffer too small\n"); +- return AVERROR(EIO); ++ int16_t fc[SUBFRAME_SIZE]; // fixed-codebook vector ++ int16_t synth[SUBFRAME_SIZE+10]; // fixed-codebook vector ++ int j, ret; ++ int gain_before, gain_after; ++ int is_periodic = 0; // whether one of the subframes is declared as periodic or not ++ ++ ctx->frame.nb_samples = SUBFRAME_SIZE<<1; ++ if ((ret = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } ++ out_frame= ctx->frame.data[0]; + + if (buf_size == 10) { +- format = format_g729_8k; ++ packet_type = FORMAT_G729_8K; ++ format = &format_g729_8k; ++ //Reset voice decision ++ ctx->onset = 0; ++ ctx->voice_decision = DECISION_VOICE; + av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729 @ 8kbit/s"); + } else if (buf_size == 8) { +- format = format_g729d_6k4; ++ packet_type = FORMAT_G729D_6K4; ++ format = &format_g729d_6k4; + av_log(avctx, AV_LOG_DEBUG, "Packet type: %s\n", "G.729D @ 6.4kbit/s"); + } else { + av_log(avctx, AV_LOG_ERROR, "Packet size %d is unknown.\n", buf_size); +@@ -231,16 +442,27 @@ + frame_erasure |= buf[i]; + frame_erasure = !frame_erasure; + +- init_get_bits(&gb, buf, buf_size); ++ init_get_bits(&gb, buf, 8*buf_size); + + ma_predictor = get_bits(&gb, 1); + quantizer_1st = get_bits(&gb, VQ_1ST_BITS); + quantizer_2nd_lo = get_bits(&gb, VQ_2ND_BITS); + quantizer_2nd_hi = get_bits(&gb, VQ_2ND_BITS); + +- lsf_decode(ctx->lsfq, ctx->past_quantizer_outputs, +- ma_predictor, +- quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi); ++ if(frame_erasure) ++ lsf_restore_from_previous(ctx->lsfq, ctx->past_quantizer_outputs, ++ ctx->ma_predictor_prev); ++ else { ++ lsf_decode(ctx->lsfq, ctx->past_quantizer_outputs, ++ ma_predictor, ++ quantizer_1st, quantizer_2nd_lo, quantizer_2nd_hi); ++ ctx->ma_predictor_prev = ma_predictor; ++ } ++ ++ tmp = ctx->past_quantizer_outputs[MA_NP]; ++ memmove(ctx->past_quantizer_outputs + 1, ctx->past_quantizer_outputs, ++ MA_NP * sizeof(int16_t*)); ++ ctx->past_quantizer_outputs[0] = tmp; + + ff_acelp_lsf2lsp(ctx->lsp[1], ctx->lsfq, 10); + +@@ -249,21 +471,25 @@ + FFSWAP(int16_t*, ctx->lsp[1], ctx->lsp[0]); + + for (i = 0; i < 2; i++) { ++ int gain_corr_factor; ++ + uint8_t ac_index; ///< adaptive codebook index + uint8_t pulses_signs; ///< fixed-codebook vector pulse signs + int fc_indexes; ///< fixed-codebook indexes + uint8_t gc_1st_index; ///< gain codebook (first stage) index + uint8_t gc_2nd_index; ///< gain codebook (second stage) index + +- ac_index = get_bits(&gb, format.ac_index_bits[i]); +- if(!i && format.parity_bit) ++ ac_index = get_bits(&gb, format->ac_index_bits[i]); ++ if(!i && format->parity_bit) + bad_pitch = get_parity(ac_index) == get_bits1(&gb); +- fc_indexes = get_bits(&gb, format.fc_indexes_bits); +- pulses_signs = get_bits(&gb, format.fc_signs_bits); +- gc_1st_index = get_bits(&gb, format.gc_1st_index_bits); +- gc_2nd_index = get_bits(&gb, format.gc_2nd_index_bits); +- +- if(!i) { ++ fc_indexes = get_bits(&gb, format->fc_indexes_bits); ++ pulses_signs = get_bits(&gb, format->fc_signs_bits); ++ gc_1st_index = get_bits(&gb, format->gc_1st_index_bits); ++ gc_2nd_index = get_bits(&gb, format->gc_2nd_index_bits); ++ ++ if (frame_erasure) ++ pitch_delay_3x = 3 * ctx->pitch_delay_int_prev; ++ else if(!i) { + if (bad_pitch) + pitch_delay_3x = 3 * ctx->pitch_delay_int_prev; + else +@@ -279,48 +505,221 @@ + } + + /* Round pitch delay to nearest (used everywhere except ff_acelp_interpolate). */ +- pitch_delay_int = (pitch_delay_3x + 1) / 3; ++ pitch_delay_int[i] = (pitch_delay_3x + 1) / 3; ++ ++ if (frame_erasure) { ++ ctx->rand_value = g729_prng(ctx->rand_value); ++ fc_indexes = ctx->rand_value & ((1 << format->fc_indexes_bits) - 1); ++ ++ ctx->rand_value = g729_prng(ctx->rand_value); ++ pulses_signs = ctx->rand_value; ++ } ++ ++ ++ memset(fc, 0, sizeof(int16_t) * SUBFRAME_SIZE); ++ switch (packet_type) { ++ case FORMAT_G729_8K: ++ ff_acelp_fc_pulse_per_track(fc, ff_fc_4pulses_8bits_tracks_13, ++ ff_fc_4pulses_8bits_track_4, ++ fc_indexes, pulses_signs, 3, 3); ++ break; ++ case FORMAT_G729D_6K4: ++ ff_acelp_fc_pulse_per_track(fc, ff_fc_2pulses_9bits_track1_gray, ++ ff_fc_2pulses_9bits_track2_gray, ++ fc_indexes, pulses_signs, 1, 4); ++ break; ++ } + +- ff_acelp_weighted_vector_sum(fc + pitch_delay_int, +- fc + pitch_delay_int, ++ /* ++ This filter enhances harmonic components of the fixed-codebook vector to ++ improve the quality of the reconstructed speech. ++ ++ / fc_v[i], i < pitch_delay ++ fc_v[i] = < ++ \ fc_v[i] + gain_pitch * fc_v[i-pitch_delay], i >= pitch_delay ++ */ ++ ff_acelp_weighted_vector_sum(fc + pitch_delay_int[i], ++ fc + pitch_delay_int[i], + fc, 1 << 14, +- av_clip(ctx->gain_pitch, SHARP_MIN, SHARP_MAX), ++ av_clip(ctx->past_gain_pitch[0], SHARP_MIN, SHARP_MAX), + 0, 14, +- SUBFRAME_SIZE - pitch_delay_int); ++ SUBFRAME_SIZE - pitch_delay_int[i]); ++ ++ memmove(ctx->past_gain_pitch+1, ctx->past_gain_pitch, 5 * sizeof(int16_t)); ++ ctx->past_gain_code[1] = ctx->past_gain_code[0]; + + if (frame_erasure) { +- ctx->gain_pitch = (29491 * ctx->gain_pitch) >> 15; // 0.90 (0.15) +- ctx->gain_code = ( 2007 * ctx->gain_code ) >> 11; // 0.98 (0.11) ++ ctx->past_gain_pitch[0] = (29491 * ctx->past_gain_pitch[0]) >> 15; // 0.90 (0.15) ++ ctx->past_gain_code[0] = ( 2007 * ctx->past_gain_code[0] ) >> 11; // 0.98 (0.11) + + gain_corr_factor = 0; + } else { +- ctx->gain_pitch = cb_gain_1st_8k[gc_1st_index][0] + +- cb_gain_2nd_8k[gc_2nd_index][0]; +- gain_corr_factor = cb_gain_1st_8k[gc_1st_index][1] + +- cb_gain_2nd_8k[gc_2nd_index][1]; ++ if (packet_type == FORMAT_G729D_6K4) { ++ ctx->past_gain_pitch[0] = cb_gain_1st_6k4[gc_1st_index][0] + ++ cb_gain_2nd_6k4[gc_2nd_index][0]; ++ gain_corr_factor = cb_gain_1st_6k4[gc_1st_index][1] + ++ cb_gain_2nd_6k4[gc_2nd_index][1]; ++ ++ /* Without check below overflow can occure in ff_acelp_update_past_gain. ++ It is not issue for G.729, because gain_corr_factor in it's case is always ++ greater than 1024, while in G.729D it can be even zero. */ ++ gain_corr_factor = FFMAX(gain_corr_factor, 1024); ++#ifndef G729_BITEXACT ++ gain_corr_factor >>= 1; ++#endif ++ } else { ++ ctx->past_gain_pitch[0] = cb_gain_1st_8k[gc_1st_index][0] + ++ cb_gain_2nd_8k[gc_2nd_index][0]; ++ gain_corr_factor = cb_gain_1st_8k[gc_1st_index][1] + ++ cb_gain_2nd_8k[gc_2nd_index][1]; ++ } ++ ++ /* Decode the fixed-codebook gain. */ ++ ctx->past_gain_code[0] = ff_acelp_decode_gain_code(&ctx->dsp, gain_corr_factor, ++ fc, MR_ENERGY, ++ ctx->quant_energy, ++ ma_prediction_coeff, ++ SUBFRAME_SIZE, 4); ++#ifdef G729_BITEXACT ++ /* ++ This correction required to get bit-exact result with ++ reference code, because gain_corr_factor in G.729D is ++ two times larger than in original G.729. ++ ++ If bit-exact result is not issue then gain_corr_factor ++ can be simpler devided by 2 before call to g729_get_gain_code ++ instead of using correction below. ++ */ ++ if (packet_type == FORMAT_G729D_6K4) { ++ gain_corr_factor >>= 1; ++ ctx->past_gain_code[0] >>= 1; ++ } ++#endif ++ } ++ ff_acelp_update_past_gain(ctx->quant_energy, gain_corr_factor, 2, frame_erasure); ++ ++ /* Routine requires rounding to lowest. */ ++ ff_acelp_interpolate(ctx->exc + i * SUBFRAME_SIZE, ++ ctx->exc + i * SUBFRAME_SIZE - pitch_delay_3x / 3, ++ ff_acelp_interp_filter, 6, ++ (pitch_delay_3x % 3) << 1, ++ 10, SUBFRAME_SIZE); + + ff_acelp_weighted_vector_sum(ctx->exc + i * SUBFRAME_SIZE, + ctx->exc + i * SUBFRAME_SIZE, fc, +- (!voicing && frame_erasure) ? 0 : ctx->gain_pitch, +- ( voicing && frame_erasure) ? 0 : ctx->gain_code, ++ (!ctx->was_periodic && frame_erasure) ? 0 : ctx->past_gain_pitch[0], ++ ( ctx->was_periodic && frame_erasure) ? 0 : ctx->past_gain_code[0], + 1 << 13, 14, SUBFRAME_SIZE); + +- ctx->pitch_delay_int_prev = pitch_delay_int; ++ memcpy(synth, ctx->syn_filter_data, 10 * sizeof(int16_t)); ++ ++ if (ff_celp_lp_synthesis_filter( ++ synth+10, ++ &lp[i][1], ++ ctx->exc + i * SUBFRAME_SIZE, ++ SUBFRAME_SIZE, ++ 10, ++ 1, ++ 0, ++ 0x800)) ++ /* Overflow occured, downscale excitation signal... */ ++ for (j = 0; j < 2 * SUBFRAME_SIZE + PITCH_DELAY_MAX + INTERPOL_LEN; j++) ++ ctx->exc_base[j] >>= 2; ++ ++ /* ... and make synthesis again. */ ++ if (packet_type == FORMAT_G729D_6K4) { ++ int16_t exc_new[SUBFRAME_SIZE]; ++ ++ ctx->onset = g729d_onset_decision(ctx->onset, ctx->past_gain_code); ++ ctx->voice_decision = g729d_voice_decision(ctx->onset, ctx->voice_decision, ctx->past_gain_pitch); ++ ++ g729d_get_new_exc(exc_new, ctx->exc + i * SUBFRAME_SIZE, fc, ctx->voice_decision, ctx->past_gain_code[0], SUBFRAME_SIZE); ++ ++ ff_celp_lp_synthesis_filter( ++ synth+10, ++ &lp[i][1], ++ exc_new, ++ SUBFRAME_SIZE, ++ 10, ++ 0, ++ 0, ++ 0x800); ++ } else { ++ ff_celp_lp_synthesis_filter( ++ synth+10, ++ &lp[i][1], ++ ctx->exc + i * SUBFRAME_SIZE, ++ SUBFRAME_SIZE, ++ 10, ++ 0, ++ 0, ++ 0x800); ++ } ++ /* Save data (without postfilter) for use in next subframe. */ ++ memcpy(ctx->syn_filter_data, synth+SUBFRAME_SIZE, 10 * sizeof(int16_t)); ++ ++ /* Calculate gain of unfiltered signal for use in AGC. */ ++ gain_before = 0; ++ for (j = 0; j < SUBFRAME_SIZE; j++) ++ gain_before += FFABS(synth[j+10]); ++ ++ /* Call postfilter and also update voicing decision for use in next frame. */ ++ ff_g729_postfilter( ++ &ctx->dsp, ++ &ctx->ht_prev_data, ++ &is_periodic, ++ &lp[i][0], ++ pitch_delay_int[0], ++ ctx->residual, ++ ctx->res_filter_data, ++ ctx->pos_filter_data, ++ synth+10, ++ SUBFRAME_SIZE); ++ ++ /* Calculate gain of filtered signal for use in AGC. */ ++ gain_after = 0; ++ for(j=0; jgain_coeff = ff_g729_adaptive_gain_control( ++ gain_before, ++ gain_after, ++ synth+10, ++ SUBFRAME_SIZE, ++ ctx->gain_coeff); ++ ++ if (frame_erasure) ++ ctx->pitch_delay_int_prev = FFMIN(ctx->pitch_delay_int_prev + 1, PITCH_DELAY_MAX); ++ else ++ ctx->pitch_delay_int_prev = pitch_delay_int[i]; ++ ++ memcpy(synth+8, ctx->hpf_z, 2*sizeof(int16_t)); ++ ff_acelp_high_pass_filter( ++ out_frame + i*SUBFRAME_SIZE, ++ ctx->hpf_f, ++ synth+10, ++ SUBFRAME_SIZE); ++ memcpy(ctx->hpf_z, synth+8+SUBFRAME_SIZE, 2*sizeof(int16_t)); + } + +- *data_size = SUBFRAME_SIZE << 2; ++ ctx->was_periodic = is_periodic; ++ ++ /* Save signal for use in next frame. */ ++ memmove(ctx->exc_base, ctx->exc_base + 2 * SUBFRAME_SIZE, (PITCH_DELAY_MAX+INTERPOL_LEN)*sizeof(int16_t)); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame*)data = ctx->frame; + return buf_size; + } + + AVCodec ff_g729_decoder = + { +- "g729", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_G729, +- sizeof(G729Context), +- decoder_init, +- NULL, +- NULL, +- decode_frame, ++ .name = "g729", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_G729, ++ .priv_data_size = sizeof(G729Context), ++ .init = decoder_init, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("G.729"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729.h 2012-05-14 14:08:53.750328229 +0200 +@@ -1,5 +1,5 @@ + /* +- * G.729 decoder ++ * G.729, G729 Annex D decoders + * Copyright (c) 2008 Vladimir Voroshilov + * + * This file is part of FFmpeg. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729postfilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729postfilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729postfilter.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729postfilter.c 2012-05-14 14:08:53.758328389 +0200 +@@ -0,0 +1,610 @@ ++/* ++ * G.729, G729 Annex D postfilter ++ * Copyright (c) 2008 Vladimir Voroshilov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++#include ++#include ++ ++#include "avcodec.h" ++#include "g729.h" ++#include "acelp_pitch_delay.h" ++#include "g729postfilter.h" ++#include "celp_math.h" ++#include "acelp_filters.h" ++#include "acelp_vectors.h" ++#include "celp_filters.h" ++ ++#define FRAC_BITS 15 ++#include "mathops.h" ++ ++/** ++ * short interpolation filter (of length 33, according to spec) ++ * for computing signal with non-integer delay ++ */ ++static const int16_t ff_g729_interp_filt_short[(ANALYZED_FRAC_DELAYS+1)*SHORT_INT_FILT_LEN] = { ++ 0, 31650, 28469, 23705, 18050, 12266, 7041, 2873, ++ 0, -1597, -2147, -1992, -1492, -933, -484, -188, ++}; ++ ++/** ++ * long interpolation filter (of length 129, according to spec) ++ * for computing signal with non-integer delay ++ */ ++static const int16_t ff_g729_interp_filt_long[(ANALYZED_FRAC_DELAYS+1)*LONG_INT_FILT_LEN] = { ++ 0, 31915, 29436, 25569, 20676, 15206, 9639, 4439, ++ 0, -3390, -5579, -6549, -6414, -5392, -3773, -1874, ++ 0, 1595, 2727, 3303, 3319, 2850, 2030, 1023, ++ 0, -887, -1527, -1860, -1876, -1614, -1150, -579, ++ 0, 501, 859, 1041, 1044, 892, 631, 315, ++ 0, -266, -453, -543, -538, -455, -317, -156, ++ 0, 130, 218, 258, 253, 212, 147, 72, ++ 0, -59, -101, -122, -123, -106, -77, -40, ++}; ++ ++/** ++ * formant_pp_factor_num_pow[i] = FORMANT_PP_FACTOR_NUM^(i+1) ++ */ ++static const int16_t formant_pp_factor_num_pow[10]= { ++ /* (0.15) */ ++ 18022, 9912, 5451, 2998, 1649, 907, 499, 274, 151, 83 ++}; ++ ++/** ++ * formant_pp_factor_den_pow[i] = FORMANT_PP_FACTOR_DEN^(i+1) ++ */ ++static const int16_t formant_pp_factor_den_pow[10] = { ++ /* (0.15) */ ++ 22938, 16057, 11240, 7868, 5508, 3856, 2699, 1889, 1322, 925 ++}; ++ ++/** ++ * \brief Residual signal calculation (4.2.1 if G.729) ++ * \param out [out] output data filtered through A(z/FORMANT_PP_FACTOR_NUM) ++ * \param filter_coeffs (3.12) A(z/FORMANT_PP_FACTOR_NUM) filter coefficients ++ * \param in input speech data to process ++ * \param subframe_size size of one subframe ++ * ++ * \note in buffer must contain 10 items of previous speech data before top of the buffer ++ * \remark It is safe to pass the same buffer for input and output. ++ */ ++static void residual_filter(int16_t* out, const int16_t* filter_coeffs, const int16_t* in, ++ int subframe_size) ++{ ++ int i, n; ++ ++ for (n = subframe_size - 1; n >= 0; n--) { ++ int sum = 0x800; ++ for (i = 0; i < 10; i++) ++ sum += filter_coeffs[i] * in[n - i - 1]; ++ ++ out[n] = in[n] + (sum >> 12); ++ } ++} ++ ++/** ++ * \brief long-term postfilter (4.2.1) ++ * \param dsp initialized DSP context ++ * \param pitch_delay_int integer part of the pitch delay in the first subframe ++ * \param residual filtering input data ++ * \param residual_filt [out] speech signal with applied A(z/FORMANT_PP_FACTOR_NUM) filter ++ * \param subframe_size size of subframe ++ * ++ * \return 0 if long-term prediction gain is less than 3dB, 1 - otherwise ++ */ ++static int16_t long_term_filter(DSPContext *dsp, int pitch_delay_int, ++ const int16_t* residual, int16_t *residual_filt, ++ int subframe_size) ++{ ++ int i, k, tmp, tmp2; ++ int sum; ++ int L_temp0; ++ int L_temp1; ++ int64_t L64_temp0; ++ int64_t L64_temp1; ++ int16_t shift; ++ int corr_int_num, corr_int_den; ++ ++ int ener; ++ int16_t sh_ener; ++ ++ int16_t gain_num,gain_den; //selected signal's gain numerator and denominator ++ int16_t sh_gain_num, sh_gain_den; ++ int gain_num_square; ++ ++ int16_t gain_long_num,gain_long_den; //filtered through long interpolation filter signal's gain numerator and denominator ++ int16_t sh_gain_long_num, sh_gain_long_den; ++ ++ int16_t best_delay_int, best_delay_frac; ++ ++ int16_t delayed_signal_offset; ++ int lt_filt_factor_a, lt_filt_factor_b; ++ ++ int16_t * selected_signal; ++ const int16_t * selected_signal_const; //Necessary to avoid compiler warning ++ ++ int16_t sig_scaled[SUBFRAME_SIZE + RES_PREV_DATA_SIZE]; ++ int16_t delayed_signal[ANALYZED_FRAC_DELAYS][SUBFRAME_SIZE+1]; ++ int corr_den[ANALYZED_FRAC_DELAYS][2]; ++ ++ tmp = 0; ++ for(i=0; i 0) ++ for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++) ++ sig_scaled[i] = residual[i] >> shift; ++ else ++ for (i = 0; i < subframe_size + RES_PREV_DATA_SIZE; i++) ++ sig_scaled[i] = residual[i] << -shift; ++ ++ /* Start of best delay searching code */ ++ gain_num = 0; ++ ++ ener = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE, ++ sig_scaled + RES_PREV_DATA_SIZE, ++ subframe_size, 0); ++ if (ener) { ++ sh_ener = FFMAX(av_log2(ener) - 14, 0); ++ ener >>= sh_ener; ++ /* Search for best pitch delay. ++ ++ sum{ r(n) * r(k,n) ] }^2 ++ R'(k)^2 := ------------------------- ++ sum{ r(k,n) * r(k,n) } ++ ++ ++ R(T) := sum{ r(n) * r(n-T) ] } ++ ++ ++ where ++ r(n-T) is integer delayed signal with delay T ++ r(k,n) is non-integer delayed signal with integer delay best_delay ++ and fractional delay k */ ++ ++ /* Find integer delay best_delay which maximizes correlation R(T). ++ ++ This is also equals to numerator of R'(0), ++ since the fine search (second step) is done with 1/8 ++ precision around best_delay. */ ++ corr_int_num = 0; ++ best_delay_int = pitch_delay_int - 1; ++ for (i = pitch_delay_int - 1; i <= pitch_delay_int + 1; i++) { ++ sum = dsp->scalarproduct_int16(sig_scaled + RES_PREV_DATA_SIZE, ++ sig_scaled + RES_PREV_DATA_SIZE - i, ++ subframe_size, 0); ++ if (sum > corr_int_num) { ++ corr_int_num = sum; ++ best_delay_int = i; ++ } ++ } ++ if (corr_int_num) { ++ /* Compute denominator of pseudo-normalized correlation R'(0). */ ++ corr_int_den = dsp->scalarproduct_int16(sig_scaled - best_delay_int + RES_PREV_DATA_SIZE, ++ sig_scaled - best_delay_int + RES_PREV_DATA_SIZE, ++ subframe_size, 0); ++ ++ /* Compute signals with non-integer delay k (with 1/8 precision), ++ where k is in [0;6] range. ++ Entire delay is qual to best_delay+(k+1)/8 ++ This is archieved by applying an interpolation filter of ++ legth 33 to source signal. */ ++ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) { ++ ff_acelp_interpolate(&delayed_signal[k][0], ++ &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int], ++ ff_g729_interp_filt_short, ++ ANALYZED_FRAC_DELAYS+1, ++ 8 - k - 1, ++ SHORT_INT_FILT_LEN, ++ subframe_size + 1); ++ } ++ ++ /* Compute denominator of pseudo-normalized correlation R'(k). ++ ++ corr_den[k][0] is square root of R'(k) denominator, for int(T) == int(T0) ++ corr_den[k][1] is square root of R'(k) denominator, for int(T) == int(T0)+1 ++ ++ Also compute maximum value of above denominators over all k. */ ++ tmp = corr_int_den; ++ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) { ++ sum = dsp->scalarproduct_int16(&delayed_signal[k][1], ++ &delayed_signal[k][1], ++ subframe_size - 1, 0); ++ corr_den[k][0] = sum + delayed_signal[k][0 ] * delayed_signal[k][0 ]; ++ corr_den[k][1] = sum + delayed_signal[k][subframe_size] * delayed_signal[k][subframe_size]; ++ ++ tmp = FFMAX3(tmp, corr_den[k][0], corr_den[k][1]); ++ } ++ ++ sh_gain_den = av_log2(tmp) - 14; ++ if (sh_gain_den >= 0) { ++ ++ sh_gain_num = FFMAX(sh_gain_den, sh_ener); ++ /* Loop through all k and find delay that maximizes ++ R'(k) correlation. ++ Search is done in [int(T0)-1; intT(0)+1] range ++ with 1/8 precision. */ ++ delayed_signal_offset = 1; ++ best_delay_frac = 0; ++ gain_den = corr_int_den >> sh_gain_den; ++ gain_num = corr_int_num >> sh_gain_num; ++ gain_num_square = gain_num * gain_num; ++ for (k = 0; k < ANALYZED_FRAC_DELAYS; k++) { ++ for (i = 0; i < 2; i++) { ++ int16_t gain_num_short, gain_den_short; ++ int gain_num_short_square; ++ /* Compute numerator of pseudo-normalized ++ correlation R'(k). */ ++ sum = dsp->scalarproduct_int16(&delayed_signal[k][i], ++ sig_scaled + RES_PREV_DATA_SIZE, ++ subframe_size, 0); ++ gain_num_short = FFMAX(sum >> sh_gain_num, 0); ++ ++ /* ++ gain_num_short_square gain_num_square ++ R'(T)^2 = -----------------------, max R'(T)^2= -------------- ++ den gain_den ++ */ ++ gain_num_short_square = gain_num_short * gain_num_short; ++ gain_den_short = corr_den[k][i] >> sh_gain_den; ++ ++ tmp = MULL(gain_num_short_square, gain_den, FRAC_BITS); ++ tmp2 = MULL(gain_num_square, gain_den_short, FRAC_BITS); ++ ++ // R'(T)^2 > max R'(T)^2 ++ if (tmp > tmp2) { ++ gain_num = gain_num_short; ++ gain_den = gain_den_short; ++ gain_num_square = gain_num_short_square; ++ delayed_signal_offset = i; ++ best_delay_frac = k + 1; ++ } ++ } ++ } ++ ++ /* ++ R'(T)^2 ++ 2 * --------- < 1 ++ R(0) ++ */ ++ L64_temp0 = (int64_t)gain_num_square << ((sh_gain_num << 1) + 1); ++ L64_temp1 = ((int64_t)gain_den * ener) << (sh_gain_den + sh_ener); ++ if (L64_temp0 < L64_temp1) ++ gain_num = 0; ++ } // if(sh_gain_den >= 0) ++ } // if(corr_int_num) ++ } // if(ener) ++ /* End of best delay searching code */ ++ ++ if (!gain_num) { ++ memcpy(residual_filt, residual + RES_PREV_DATA_SIZE, subframe_size * sizeof(int16_t)); ++ ++ /* Long-term prediction gain is less than 3dB. Long-term postfilter is disabled. */ ++ return 0; ++ } ++ if (best_delay_frac) { ++ /* Recompute delayed signal with an interpolation filter of length 129. */ ++ ff_acelp_interpolate(residual_filt, ++ &sig_scaled[RES_PREV_DATA_SIZE - best_delay_int + delayed_signal_offset], ++ ff_g729_interp_filt_long, ++ ANALYZED_FRAC_DELAYS + 1, ++ 8 - best_delay_frac, ++ LONG_INT_FILT_LEN, ++ subframe_size + 1); ++ /* Compute R'(k) correlation's numerator. */ ++ sum = dsp->scalarproduct_int16(residual_filt, ++ sig_scaled + RES_PREV_DATA_SIZE, ++ subframe_size, 0); ++ ++ if (sum < 0) { ++ gain_long_num = 0; ++ sh_gain_long_num = 0; ++ } else { ++ tmp = FFMAX(av_log2(sum) - 14, 0); ++ sum >>= tmp; ++ gain_long_num = sum; ++ sh_gain_long_num = tmp; ++ } ++ ++ /* Compute R'(k) correlation's denominator. */ ++ sum = dsp->scalarproduct_int16(residual_filt, residual_filt, subframe_size, 0); ++ ++ tmp = FFMAX(av_log2(sum) - 14, 0); ++ sum >>= tmp; ++ gain_long_den = sum; ++ sh_gain_long_den = tmp; ++ ++ /* Select between original and delayed signal. ++ Delayed signal will be selected if it increases R'(k) ++ correlation. */ ++ L_temp0 = gain_num * gain_num; ++ L_temp0 = MULL(L_temp0, gain_long_den, FRAC_BITS); ++ ++ L_temp1 = gain_long_num * gain_long_num; ++ L_temp1 = MULL(L_temp1, gain_den, FRAC_BITS); ++ ++ tmp = ((sh_gain_long_num - sh_gain_num) << 1) - (sh_gain_long_den - sh_gain_den); ++ if (tmp > 0) ++ L_temp0 >>= tmp; ++ else ++ L_temp1 >>= -tmp; ++ ++ /* Check if longer filter increases the values of R'(k). */ ++ if (L_temp1 > L_temp0) { ++ /* Select long filter. */ ++ selected_signal = residual_filt; ++ gain_num = gain_long_num; ++ gain_den = gain_long_den; ++ sh_gain_num = sh_gain_long_num; ++ sh_gain_den = sh_gain_long_den; ++ } else ++ /* Select short filter. */ ++ selected_signal = &delayed_signal[best_delay_frac-1][delayed_signal_offset]; ++ ++ /* Rescale selected signal to original value. */ ++ if (shift > 0) ++ for (i = 0; i < subframe_size; i++) ++ selected_signal[i] <<= shift; ++ else ++ for (i = 0; i < subframe_size; i++) ++ selected_signal[i] >>= -shift; ++ ++ /* necessary to avoid compiler warning */ ++ selected_signal_const = selected_signal; ++ } // if(best_delay_frac) ++ else ++ selected_signal_const = residual + RES_PREV_DATA_SIZE - (best_delay_int + 1 - delayed_signal_offset); ++#ifdef G729_BITEXACT ++ tmp = sh_gain_num - sh_gain_den; ++ if (tmp > 0) ++ gain_den >>= tmp; ++ else ++ gain_num >>= -tmp; ++ ++ if (gain_num > gain_den) ++ lt_filt_factor_a = MIN_LT_FILT_FACTOR_A; ++ else { ++ gain_num >>= 2; ++ gain_den >>= 1; ++ lt_filt_factor_a = (gain_den << 15) / (gain_den + gain_num); ++ } ++#else ++ L64_temp0 = ((int64_t)gain_num) << (sh_gain_num - 1); ++ L64_temp1 = ((int64_t)gain_den) << sh_gain_den; ++ lt_filt_factor_a = FFMAX((L64_temp1 << 15) / (L64_temp1 + L64_temp0), MIN_LT_FILT_FACTOR_A); ++#endif ++ ++ /* Filter through selected filter. */ ++ lt_filt_factor_b = 32767 - lt_filt_factor_a + 1; ++ ++ ff_acelp_weighted_vector_sum(residual_filt, residual + RES_PREV_DATA_SIZE, ++ selected_signal_const, ++ lt_filt_factor_a, lt_filt_factor_b, ++ 1<<14, 15, subframe_size); ++ ++ // Long-term prediction gain is larger than 3dB. ++ return 1; ++} ++ ++/** ++ * \brief Calculate reflection coefficient for tilt compensation filter (4.2.3). ++ * \param dsp initialized DSP context ++ * \param lp_gn (3.12) coefficients of A(z/FORMANT_PP_FACTOR_NUM) filter ++ * \param lp_gd (3.12) coefficients of A(z/FORMANT_PP_FACTOR_DEN) filter ++ * \param speech speech to update ++ * \param subframe_size size of subframe ++ * ++ * \return (3.12) reflection coefficient ++ * ++ * \remark The routine also calculates the gain term for the short-term ++ * filter (gf) and multiplies the speech data by 1/gf. ++ * ++ * \note All members of lp_gn, except 10-19 must be equal to zero. ++ */ ++static int16_t get_tilt_comp(DSPContext *dsp, int16_t *lp_gn, ++ const int16_t *lp_gd, int16_t* speech, ++ int subframe_size) ++{ ++ int rh1,rh0; // (3.12) ++ int temp; ++ int i; ++ int gain_term; ++ ++ lp_gn[10] = 4096; //1.0 in (3.12) ++ ++ /* Apply 1/A(z/FORMANT_PP_FACTOR_DEN) filter to hf. */ ++ ff_celp_lp_synthesis_filter(lp_gn + 11, lp_gd + 1, lp_gn + 11, 22, 10, 0, 0, 0x800); ++ /* Now lp_gn (starting with 10) contains impulse response ++ of A(z/FORMANT_PP_FACTOR_NUM)/A(z/FORMANT_PP_FACTOR_DEN) filter. */ ++ ++ rh0 = dsp->scalarproduct_int16(lp_gn + 10, lp_gn + 10, 20, 0); ++ rh1 = dsp->scalarproduct_int16(lp_gn + 10, lp_gn + 11, 20, 0); ++ ++ /* downscale to avoid overflow */ ++ temp = av_log2(rh0) - 14; ++ if (temp > 0) { ++ rh0 >>= temp; ++ rh1 >>= temp; ++ } ++ ++ if (FFABS(rh1) > rh0 || !rh0) ++ return 0; ++ ++ gain_term = 0; ++ for (i = 0; i < 20; i++) ++ gain_term += FFABS(lp_gn[i + 10]); ++ gain_term >>= 2; // (3.12) -> (5.10) ++ ++ if (gain_term > 0x400) { // 1.0 in (5.10) ++ temp = 0x2000000 / gain_term; // 1.0/gain_term in (0.15) ++ for (i = 0; i < subframe_size; i++) ++ speech[i] = (speech[i] * temp + 0x4000) >> 15; ++ } ++ ++ return -(rh1 << 15) / rh0; ++} ++ ++/** ++ * \brief Apply tilt compensation filter (4.2.3). ++ * \param res_pst [in/out] residual signal (partially filtered) ++ * \param k1 (3.12) reflection coefficient ++ * \param subframe_size size of subframe ++ * \param ht_prev_data previous data for 4.2.3, equation 86 ++ * ++ * \return new value for ht_prev_data ++*/ ++static int16_t apply_tilt_comp(int16_t* out, int16_t* res_pst, int refl_coeff, ++ int subframe_size, int16_t ht_prev_data) ++{ ++ int tmp, tmp2; ++ int i; ++ int gt, ga; ++ int fact, sh_fact; ++ ++ if (refl_coeff > 0) { ++ gt = (refl_coeff * G729_TILT_FACTOR_PLUS + 0x4000) >> 15; ++ fact = 0x4000; // 0.5 in (0.15) ++ sh_fact = 15; ++ } else { ++ gt = (refl_coeff * G729_TILT_FACTOR_MINUS + 0x4000) >> 15; ++ fact = 0x800; // 0.5 in (3.12) ++ sh_fact = 12; ++ } ++ ga = (fact << 15) / av_clip_int16(32768 - FFABS(gt)); ++ gt >>= 1; ++ ++ /* Apply tilt compensation filter to signal. */ ++ tmp = res_pst[subframe_size - 1]; ++ ++ for (i = subframe_size - 1; i >= 1; i--) { ++ tmp2 = (res_pst[i] << 15) + ((gt * res_pst[i-1]) << 1); ++ tmp2 = (tmp2 + 0x4000) >> 15; ++ ++ tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact; ++ out[i] = tmp2; ++ } ++ tmp2 = (res_pst[0] << 15) + ((gt * ht_prev_data) << 1); ++ tmp2 = (tmp2 + 0x4000) >> 15; ++ tmp2 = (tmp2 * ga * 2 + fact) >> sh_fact; ++ out[0] = tmp2; ++ ++ return tmp; ++} ++ ++void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing, ++ const int16_t *lp_filter_coeffs, int pitch_delay_int, ++ int16_t* residual, int16_t* res_filter_data, ++ int16_t* pos_filter_data, int16_t *speech, int subframe_size) ++{ ++ int16_t residual_filt_buf[SUBFRAME_SIZE+11]; ++ int16_t lp_gn[33]; // (3.12) ++ int16_t lp_gd[11]; // (3.12) ++ int tilt_comp_coeff; ++ int i; ++ ++ /* Zero-filling is necessary for tilt-compensation filter. */ ++ memset(lp_gn, 0, 33 * sizeof(int16_t)); ++ ++ /* Calculate A(z/FORMANT_PP_FACTOR_NUM) filter coefficients. */ ++ for (i = 0; i < 10; i++) ++ lp_gn[i + 11] = (lp_filter_coeffs[i + 1] * formant_pp_factor_num_pow[i] + 0x4000) >> 15; ++ ++ /* Calculate A(z/FORMANT_PP_FACTOR_DEN) filter coefficients. */ ++ for (i = 0; i < 10; i++) ++ lp_gd[i + 1] = (lp_filter_coeffs[i + 1] * formant_pp_factor_den_pow[i] + 0x4000) >> 15; ++ ++ /* residual signal calculation (one-half of short-term postfilter) */ ++ memcpy(speech - 10, res_filter_data, 10 * sizeof(int16_t)); ++ residual_filter(residual + RES_PREV_DATA_SIZE, lp_gn + 11, speech, subframe_size); ++ /* Save data to use it in the next subframe. */ ++ memcpy(res_filter_data, speech + subframe_size - 10, 10 * sizeof(int16_t)); ++ ++ /* long-term filter. If long-term prediction gain is larger than 3dB (returned value is ++ nonzero) then declare current subframe as periodic. */ ++ *voicing = FFMAX(*voicing, long_term_filter(dsp, pitch_delay_int, ++ residual, residual_filt_buf + 10, ++ subframe_size)); ++ ++ /* shift residual for using in next subframe */ ++ memmove(residual, residual + subframe_size, RES_PREV_DATA_SIZE * sizeof(int16_t)); ++ ++ /* short-term filter tilt compensation */ ++ tilt_comp_coeff = get_tilt_comp(dsp, lp_gn, lp_gd, residual_filt_buf + 10, subframe_size); ++ ++ /* Apply second half of short-term postfilter: 1/A(z/FORMANT_PP_FACTOR_DEN) */ ++ ff_celp_lp_synthesis_filter(pos_filter_data + 10, lp_gd + 1, ++ residual_filt_buf + 10, ++ subframe_size, 10, 0, 0, 0x800); ++ memcpy(pos_filter_data, pos_filter_data + subframe_size, 10 * sizeof(int16_t)); ++ ++ *ht_prev_data = apply_tilt_comp(speech, pos_filter_data + 10, tilt_comp_coeff, ++ subframe_size, *ht_prev_data); ++} ++ ++/** ++ * \brief Adaptive gain control (4.2.4) ++ * \param gain_before gain of speech before applying postfilters ++ * \param gain_after gain of speech after applying postfilters ++ * \param speech [in/out] signal buffer ++ * \param subframe_size length of subframe ++ * \param gain_prev (3.12) previous value of gain coefficient ++ * ++ * \return (3.12) last value of gain coefficient ++ */ ++int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech, ++ int subframe_size, int16_t gain_prev) ++{ ++ int gain; // (3.12) ++ int n; ++ int exp_before, exp_after; ++ ++ if(!gain_after && gain_before) ++ return 0; ++ ++ if (gain_before) { ++ ++ exp_before = 14 - av_log2(gain_before); ++ gain_before = bidir_sal(gain_before, exp_before); ++ ++ exp_after = 14 - av_log2(gain_after); ++ gain_after = bidir_sal(gain_after, exp_after); ++ ++ if (gain_before < gain_after) { ++ gain = (gain_before << 15) / gain_after; ++ gain = bidir_sal(gain, exp_after - exp_before - 1); ++ } else { ++ gain = ((gain_before - gain_after) << 14) / gain_after + 0x4000; ++ gain = bidir_sal(gain, exp_after - exp_before); ++ } ++ gain = (gain * G729_AGC_FAC1 + 0x4000) >> 15; // gain * (1-0.9875) ++ } else ++ gain = 0; ++ ++ for (n = 0; n < subframe_size; n++) { ++ // gain_prev = gain + 0.9875 * gain_prev ++ gain_prev = (G729_AGC_FACTOR * gain_prev + 0x4000) >> 15; ++ gain_prev = av_clip_int16(gain + gain_prev); ++ speech[n] = av_clip_int16((speech[n] * gain_prev + 0x2000) >> 14); ++ } ++ return gain_prev; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729postfilter.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729postfilter.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/g729postfilter.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/g729postfilter.h 2012-05-14 14:08:53.759328409 +0200 +@@ -0,0 +1,115 @@ ++/* ++ * G.729, G729 Annex D postfilter ++ * Copyright (c) 2008 Vladimir Voroshilov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++#ifndef FFMPEG_G729POSTFILTER_H ++#define FFMPEG_G729POSTFILTER_H ++ ++#include ++ ++/** ++ * tilt compensation factor (G.729, k1>0) ++ * 0.2 in Q15 ++ */ ++#define G729_TILT_FACTOR_PLUS 6554 ++ ++/** ++ * tilt compensation factor (G.729, k1<0) ++ * 0.9 in Q15 ++ */ ++#define G729_TILT_FACTOR_MINUS 29491 ++ ++/* 4.2.2 */ ++#define FORMANT_PP_FACTOR_NUM 18022 //0.55 in Q15 ++#define FORMANT_PP_FACTOR_DEN 22938 //0.70 in Q15 ++ ++/** ++ * gain adjustment factor (G.729, 4.2.4) ++ * 0.9875 in Q15 ++ */ ++#define G729_AGC_FACTOR 32358 ++#define G729_AGC_FAC1 (32768-G729_AGC_FACTOR) ++ ++/** ++ * 1.0 / (1.0 + 0.5) in Q15 ++ * where 0.5 is the minimum value of ++ * weight factor, controlling amount of long-term postfiltering ++ */ ++#define MIN_LT_FILT_FACTOR_A 21845 ++ ++/** ++ * Short interpolation filter length ++ */ ++#define SHORT_INT_FILT_LEN 2 ++ ++/** ++ * Long interpolation filter length ++ */ ++#define LONG_INT_FILT_LEN 8 ++ ++/** ++ * Number of analyzed fractional pitch delays in second stage of long-term ++ * postfilter ++ */ ++#define ANALYZED_FRAC_DELAYS 7 ++ ++/** ++ * Amount of past residual signal data stored in buffer ++ */ ++#define RES_PREV_DATA_SIZE (PITCH_DELAY_MAX + LONG_INT_FILT_LEN + 1) ++ ++/** ++ * \brief Signal postfiltering (4.2) ++ * \param dsp initialized DSP context ++ * \param ht_prev_data [in/out] (Q12) pointer to variable receiving tilt ++ * compensation filter data from previous subframe ++ * \param voicing [in/out] (Q0) pointer to variable receiving voicing decision ++ * \param lp_filter_coeffs (Q12) LP filter coefficients ++ * \param pitch_delay_int integer part of the pitch delay ++ * \param residual [in/out] (Q0) residual signal buffer (used in long-term postfilter) ++ * \param res_filter_data [in/out] (Q0) speech data of previous subframe ++ * \param pos_filter_data [in/out] (Q0) previous speech data for short-term postfilter ++ * \param speech [in/out] (Q0) signal buffer ++ * \param subframe_size size of subframe ++ * ++ * Filtering has the following stages: ++ * Long-term postfilter (4.2.1) ++ * Short-term postfilter (4.2.2). ++ * Tilt-compensation (4.2.3) ++ */ ++void ff_g729_postfilter(DSPContext *dsp, int16_t* ht_prev_data, int* voicing, ++ const int16_t *lp_filter_coeffs, int pitch_delay_int, ++ int16_t* residual, int16_t* res_filter_data, ++ int16_t* pos_filter_data, int16_t *speech, ++ int subframe_size); ++ ++/** ++ * \brief Adaptive gain control (4.2.4) ++ * \param gain_before (Q0) gain of speech before applying postfilters ++ * \param gain_after (Q0) gain of speech after applying postfilters ++ * \param speech [in/out] (Q0) signal buffer ++ * \param subframe_size length of subframe ++ * \param gain_prev (Q12) previous value of gain coefficient ++ * ++ * \return (Q12) last value of gain coefficient ++ */ ++int16_t ff_g729_adaptive_gain_control(int gain_before, int gain_after, int16_t *speech, ++ int subframe_size, int16_t gain_prev); ++ ++#endif // FFMPEG_G729POSTFILTER_H +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/get_bits.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/get_bits.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/get_bits.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/get_bits.h 2012-05-14 14:08:53.761328449 +0200 +@@ -27,40 +27,33 @@ + #define AVCODEC_GET_BITS_H + + #include +-#include +-#include +-#include "libavutil/bswap.h" + #include "libavutil/common.h" + #include "libavutil/intreadwrite.h" + #include "libavutil/log.h" + #include "mathops.h" + +-#if defined(ALT_BITSTREAM_READER_LE) && !defined(ALT_BITSTREAM_READER) +-# define ALT_BITSTREAM_READER +-#endif +- +-#if !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) +-# if ARCH_ARM && !HAVE_FAST_UNALIGNED +-# define A32_BITSTREAM_READER +-# else +-# define ALT_BITSTREAM_READER +-//#define A32_BITSTREAM_READER +-# endif ++/* ++ * Safe bitstream reading: ++ * optionally, the get_bits API can check to ensure that we ++ * don't read past input buffer boundaries. This is protected ++ * with CONFIG_SAFE_BITSTREAM_READER at the global level, and ++ * then below that with UNCHECKED_BITSTREAM_READER at the per- ++ * decoder level. This means that decoders that check internally ++ * can "#define UNCHECKED_BITSTREAM_READER 1" to disable ++ * overread checks. ++ * Boundary checking causes a minor performance penalty so for ++ * applications that won't want/need this, it can be disabled ++ * globally using "#define CONFIG_SAFE_BITSTREAM_READER 0". ++ */ ++#ifndef UNCHECKED_BITSTREAM_READER ++#define UNCHECKED_BITSTREAM_READER !CONFIG_SAFE_BITSTREAM_READER + #endif + +-/* bit input */ +-/* buffer, buffer_end and size_in_bits must be present and used by every reader */ + typedef struct GetBitContext { + const uint8_t *buffer, *buffer_end; +-#ifdef ALT_BITSTREAM_READER + int index; +-#elif defined A32_BITSTREAM_READER +- uint32_t *buffer_ptr; +- uint32_t cache0; +- uint32_t cache1; +- int bit_count; +-#endif + int size_in_bits; ++ int size_in_bits_plus8; + } GetBitContext; + + #define VLC_TYPE int16_t +@@ -85,13 +78,13 @@ + getbitcontext + + OPEN_READER(name, gb) +- loads gb into local variables ++ load gb into local variables + + CLOSE_READER(name, gb) +- stores local vars in gb ++ store local vars in gb + + UPDATE_CACHE(name, gb) +- refills the internal cache from the bitstream ++ refill the internal cache from the bitstream + after this call at least MIN_CACHE_BITS will be available, + + GET_CACHE(name, gb) +@@ -113,148 +106,107 @@ + SKIP_COUNTER(name, gb, num) + will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) + +-LAST_SKIP_CACHE(name, gb, num) +- will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing +- + LAST_SKIP_BITS(name, gb, num) +- is equivalent to LAST_SKIP_CACHE; SKIP_COUNTER ++ like SKIP_BITS, to be used if next call is UPDATE_CACHE or CLOSE_READER + + for examples see get_bits, show_bits, skip_bits, get_vlc + */ + +-#ifdef ALT_BITSTREAM_READER ++#ifdef LONG_BITSTREAM_READER ++# define MIN_CACHE_BITS 32 ++#else + # define MIN_CACHE_BITS 25 ++#endif ++ ++#if UNCHECKED_BITSTREAM_READER ++#define OPEN_READER(name, gb) \ ++ unsigned int name##_index = (gb)->index; \ ++ av_unused unsigned int name##_cache + +-# define OPEN_READER(name, gb) \ ++#define HAVE_BITS_REMAINING(name, gb) 1 ++#else ++#define OPEN_READER(name, gb) \ + unsigned int name##_index = (gb)->index; \ +- int name##_cache = 0 ++ unsigned int av_unused name##_cache = 0; \ ++ unsigned int av_unused name##_size_plus8 = \ ++ (gb)->size_in_bits_plus8 ++ ++#define HAVE_BITS_REMAINING(name, gb) \ ++ name##_index < name##_size_plus8 ++#endif + +-# define CLOSE_READER(name, gb) (gb)->index = name##_index ++#define CLOSE_READER(name, gb) (gb)->index = name##_index + +-# ifdef ALT_BITSTREAM_READER_LE +-# define UPDATE_CACHE(name, gb) \ +- name##_cache = AV_RL32(((const uint8_t *)(gb)->buffer)+(name##_index>>3)) >> (name##_index&0x07) ++#ifdef BITSTREAM_READER_LE + +-# define SKIP_CACHE(name, gb, num) name##_cache >>= (num) ++# ifdef LONG_BITSTREAM_READER ++# define UPDATE_CACHE(name, gb) name##_cache = \ ++ AV_RL64((gb)->buffer + (name##_index >> 3)) >> (name##_index & 7) + # else +-# define UPDATE_CACHE(name, gb) \ +- name##_cache = AV_RB32(((const uint8_t *)(gb)->buffer)+(name##_index>>3)) << (name##_index&0x07) ++# define UPDATE_CACHE(name, gb) name##_cache = \ ++ AV_RL32((gb)->buffer + (name##_index >> 3)) >> (name##_index & 7) ++# endif ++ ++# define SKIP_CACHE(name, gb, num) name##_cache >>= (num) + +-# define SKIP_CACHE(name, gb, num) name##_cache <<= (num) ++#else ++ ++# ifdef LONG_BITSTREAM_READER ++# define UPDATE_CACHE(name, gb) name##_cache = \ ++ AV_RB64((gb)->buffer + (name##_index >> 3)) >> (32 - (name##_index & 7)) ++# else ++# define UPDATE_CACHE(name, gb) name##_cache = \ ++ AV_RB32((gb)->buffer + (name##_index >> 3)) << (name##_index & 7) + # endif + +-// FIXME name? ++# define SKIP_CACHE(name, gb, num) name##_cache <<= (num) ++ ++#endif ++ ++#if UNCHECKED_BITSTREAM_READER + # define SKIP_COUNTER(name, gb, num) name##_index += (num) ++#else ++# define SKIP_COUNTER(name, gb, num) \ ++ name##_index = FFMIN(name##_size_plus8, name##_index + (num)) ++#endif + +-# define SKIP_BITS(name, gb, num) do { \ ++#define SKIP_BITS(name, gb, num) do { \ + SKIP_CACHE(name, gb, num); \ + SKIP_COUNTER(name, gb, num); \ + } while (0) + +-# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) +-# define LAST_SKIP_CACHE(name, gb, num) ++#define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) + +-# ifdef ALT_BITSTREAM_READER_LE ++#ifdef BITSTREAM_READER_LE + # define SHOW_UBITS(name, gb, num) zero_extend(name##_cache, num) +- + # define SHOW_SBITS(name, gb, num) sign_extend(name##_cache, num) +-# else ++#else + # define SHOW_UBITS(name, gb, num) NEG_USR32(name##_cache, num) +- + # define SHOW_SBITS(name, gb, num) NEG_SSR32(name##_cache, num) +-# endif ++#endif + +-# define GET_CACHE(name, gb) ((uint32_t)name##_cache) ++#define GET_CACHE(name, gb) ((uint32_t)name##_cache) + +-static inline int get_bits_count(const GetBitContext *s){ ++static inline int get_bits_count(const GetBitContext *s) ++{ + return s->index; + } + + static inline void skip_bits_long(GetBitContext *s, int n){ ++#if UNCHECKED_BITSTREAM_READER + s->index += n; +-} +- +-#elif defined A32_BITSTREAM_READER +- +-# define MIN_CACHE_BITS 32 +- +-# define OPEN_READER(name, gb) \ +- int name##_bit_count = (gb)->bit_count; \ +- uint32_t name##_cache0 = (gb)->cache0; \ +- uint32_t name##_cache1 = (gb)->cache1; \ +- uint32_t *name##_buffer_ptr = (gb)->buffer_ptr +- +-# define CLOSE_READER(name, gb) do { \ +- (gb)->bit_count = name##_bit_count; \ +- (gb)->cache0 = name##_cache0; \ +- (gb)->cache1 = name##_cache1; \ +- (gb)->buffer_ptr = name##_buffer_ptr; \ +- } while (0) +- +-# define UPDATE_CACHE(name, gb) do { \ +- if(name##_bit_count > 0){ \ +- const uint32_t next = av_be2ne32(*name##_buffer_ptr); \ +- name##_cache0 |= NEG_USR32(next, name##_bit_count); \ +- name##_cache1 |= next << name##_bit_count; \ +- name##_buffer_ptr++; \ +- name##_bit_count -= 32; \ +- } \ +- } while (0) +- +-#if ARCH_X86 +-# define SKIP_CACHE(name, gb, num) \ +- __asm__("shldl %2, %1, %0 \n\t" \ +- "shll %2, %1 \n\t" \ +- : "+r" (name##_cache0), "+r" (name##_cache1) \ +- : "Ic" ((uint8_t)(num))) + #else +-# define SKIP_CACHE(name, gb, num) do { \ +- name##_cache0 <<= (num); \ +- name##_cache0 |= NEG_USR32(name##_cache1,num); \ +- name##_cache1 <<= (num); \ +- } while (0) ++ s->index += av_clip(n, -s->index, s->size_in_bits_plus8 - s->index); + #endif +- +-# define SKIP_COUNTER(name, gb, num) name##_bit_count += (num) +- +-# define SKIP_BITS(name, gb, num) do { \ +- SKIP_CACHE(name, gb, num); \ +- SKIP_COUNTER(name, gb, num); \ +- } while (0) +- +-# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) +-# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) +- +-# define SHOW_UBITS(name, gb, num) NEG_USR32(name##_cache0, num) +- +-# define SHOW_SBITS(name, gb, num) NEG_SSR32(name##_cache0, num) +- +-# define GET_CACHE(name, gb) name##_cache0 +- +-static inline int get_bits_count(const GetBitContext *s) { +- return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; +-} +- +-static inline void skip_bits_long(GetBitContext *s, int n){ +- OPEN_READER(re, s); +- re_bit_count += n; +- re_buffer_ptr += re_bit_count>>5; +- re_bit_count &= 31; +- re_cache0 = av_be2ne32(re_buffer_ptr[-1]) << re_bit_count; +- re_cache1 = 0; +- UPDATE_CACHE(re, s); +- CLOSE_READER(re, s); + } + +-#endif +- + /** + * read mpeg1 dc style vlc (sign bit + mantisse with no MSB). + * if MSB not set it is negative + * @param n length in bits +- * @author BERO + */ +-static inline int get_xbits(GetBitContext *s, int n){ ++static inline int get_xbits(GetBitContext *s, int n) ++{ + register int sign; + register int32_t cache; + OPEN_READER(re, s); +@@ -266,7 +218,8 @@ + return (NEG_USR32(sign ^ cache, n) ^ sign) - sign; + } + +-static inline int get_sbits(GetBitContext *s, int n){ ++static inline int get_sbits(GetBitContext *s, int n) ++{ + register int tmp; + OPEN_READER(re, s); + UPDATE_CACHE(re, s); +@@ -279,7 +232,8 @@ + /** + * Read 1-25 bits. + */ +-static inline unsigned int get_bits(GetBitContext *s, int n){ ++static inline unsigned int get_bits(GetBitContext *s, int n) ++{ + register int tmp; + OPEN_READER(re, s); + UPDATE_CACHE(re, s); +@@ -290,9 +244,10 @@ + } + + /** +- * Shows 1-25 bits. ++ * Show 1-25 bits. + */ +-static inline unsigned int show_bits(GetBitContext *s, int n){ ++static inline unsigned int show_bits(GetBitContext *s, int n) ++{ + register int tmp; + OPEN_READER(re, s); + UPDATE_CACHE(re, s); +@@ -300,49 +255,53 @@ + return tmp; + } + +-static inline void skip_bits(GetBitContext *s, int n){ +- //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) ++static inline void skip_bits(GetBitContext *s, int n) ++{ + OPEN_READER(re, s); + UPDATE_CACHE(re, s); + LAST_SKIP_BITS(re, s, n); + CLOSE_READER(re, s); + } + +-static inline unsigned int get_bits1(GetBitContext *s){ +-#ifdef ALT_BITSTREAM_READER ++static inline unsigned int get_bits1(GetBitContext *s) ++{ + unsigned int index = s->index; + uint8_t result = s->buffer[index>>3]; +-#ifdef ALT_BITSTREAM_READER_LE ++#ifdef BITSTREAM_READER_LE + result >>= index & 7; + result &= 1; + #else + result <<= index & 7; + result >>= 8 - 1; + #endif +- index++; ++#if !UNCHECKED_BITSTREAM_READER ++ if (s->index < s->size_in_bits_plus8) ++#endif ++ index++; + s->index = index; + + return result; +-#else +- return get_bits(s, 1); +-#endif + } + +-static inline unsigned int show_bits1(GetBitContext *s){ ++static inline unsigned int show_bits1(GetBitContext *s) ++{ + return show_bits(s, 1); + } + +-static inline void skip_bits1(GetBitContext *s){ ++static inline void skip_bits1(GetBitContext *s) ++{ + skip_bits(s, 1); + } + + /** +- * reads 0-32 bits. ++ * Read 0-32 bits. + */ +-static inline unsigned int get_bits_long(GetBitContext *s, int n){ +- if (n <= MIN_CACHE_BITS) return get_bits(s, n); ++static inline unsigned int get_bits_long(GetBitContext *s, int n) ++{ ++ if (n <= MIN_CACHE_BITS) ++ return get_bits(s, n); + else { +-#ifdef ALT_BITSTREAM_READER_LE ++#ifdef BITSTREAM_READER_LE + int ret = get_bits(s, 16); + return ret | (get_bits(s, n-16) << 16); + #else +@@ -353,17 +312,20 @@ + } + + /** +- * reads 0-32 bits as a signed integer. ++ * Read 0-32 bits as a signed integer. + */ +-static inline int get_sbits_long(GetBitContext *s, int n) { ++static inline int get_sbits_long(GetBitContext *s, int n) ++{ + return sign_extend(get_bits_long(s, n), n); + } + + /** +- * shows 0-32 bits. ++ * Show 0-32 bits. + */ +-static inline unsigned int show_bits_long(GetBitContext *s, int n){ +- if (n <= MIN_CACHE_BITS) return show_bits(s, n); ++static inline unsigned int show_bits_long(GetBitContext *s, int n) ++{ ++ if (n <= MIN_CACHE_BITS) ++ return show_bits(s, n); + else { + GetBitContext gb = *s; + return get_bits_long(&gb, n); +@@ -380,16 +342,13 @@ + } + + /** +- * init GetBitContext. +- * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger then the actual read bits ++ * Inititalize GetBitContext. ++ * @param buffer bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE bytes larger than the actual read bits + * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end + * @param bit_size the size of the buffer in bits +- * +- * While GetBitContext stores the buffer size, for performance reasons you are +- * responsible for checking for the buffer end yourself (take advantage of the padding)! + */ +-static inline void init_get_bits(GetBitContext *s, +- const uint8_t *buffer, int bit_size) ++static inline void init_get_bits(GetBitContext *s, const uint8_t *buffer, ++ int bit_size) + { + int buffer_size = (bit_size+7)>>3; + if (buffer_size < 0 || bit_size < 0) { +@@ -399,14 +358,9 @@ + + s->buffer = buffer; + s->size_in_bits = bit_size; ++ s->size_in_bits_plus8 = bit_size + 8; + s->buffer_end = buffer + buffer_size; +-#ifdef ALT_BITSTREAM_READER + s->index = 0; +-#elif defined A32_BITSTREAM_READER +- s->buffer_ptr = (uint32_t*)((intptr_t)buffer & ~3); +- s->bit_count = 32 + 8*((intptr_t)buffer & 3); +- skip_bits_long(s, 0); +-#endif + } + + static inline void align_get_bits(GetBitContext *s) +@@ -442,12 +396,12 @@ + + + /** +- * + * If the vlc code is invalid and max_depth=1, then no bits will be removed. + * If the vlc code is invalid and max_depth>1, then the number of bits removed + * is undefined. + */ +-#define GET_VLC(code, name, gb, table, bits, max_depth) do { \ ++#define GET_VLC(code, name, gb, table, bits, max_depth) \ ++ do { \ + int n, nb_bits; \ + unsigned int index; \ + \ +@@ -478,7 +432,8 @@ + SKIP_BITS(name, gb, n); \ + } while (0) + +-#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update) do { \ ++#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth, need_update) \ ++ do { \ + int n, nb_bits; \ + unsigned int index; \ + \ +@@ -504,7 +459,7 @@ + + + /** +- * parses a vlc code, faster then get_vlc() ++ * Parse a vlc code. + * @param bits is the number of bits which will be read at once, must be + * identical to nb_bits in init_vlc() + * @param max_depth is the number of times bits bits must be read to completely +@@ -512,7 +467,7 @@ + * = (max_vlc_length + bits - 1) / bits + */ + static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], +- int bits, int max_depth) ++ int bits, int max_depth) + { + int code; + +@@ -525,7 +480,8 @@ + return code; + } + +-static inline int decode012(GetBitContext *gb){ ++static inline int decode012(GetBitContext *gb) ++{ + int n; + n = get_bits1(gb); + if (n == 0) +@@ -534,7 +490,8 @@ + return get_bits1(gb) + 1; + } + +-static inline int decode210(GetBitContext *gb){ ++static inline int decode210(GetBitContext *gb) ++{ + if (get_bits1(gb)) + return 0; + else +@@ -549,7 +506,8 @@ + //#define TRACE + + #ifdef TRACE +-static inline void print_bin(int bits, int n){ ++static inline void print_bin(int bits, int n) ++{ + int i; + + for (i = n-1; i >= 0; i--) { +@@ -560,7 +518,8 @@ + } + + static inline int get_bits_trace(GetBitContext *s, int n, char *file, +- const char *func, int line){ ++ const char *func, int line) ++{ + int r = get_bits(s, n); + + print_bin(r, n); +@@ -570,7 +529,8 @@ + } + static inline int get_vlc_trace(GetBitContext *s, VLC_TYPE (*table)[2], + int bits, int max_depth, char *file, +- const char *func, int line){ ++ const char *func, int line) ++{ + int show = show_bits(s, 24); + int pos = get_bits_count(s); + int r = get_vlc2(s, table, bits, max_depth); +@@ -584,7 +544,8 @@ + return r; + } + static inline int get_xbits_trace(GetBitContext *s, int n, char *file, +- const char *func, int line){ ++ const char *func, int line) ++{ + int show = show_bits(s, n); + int r = get_xbits(s, n); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gif.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gif.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gif.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gif.c 2012-05-14 14:08:53.765328530 +0200 +@@ -62,7 +62,7 @@ + uint8_t **bytestream, uint32_t *palette) + { + int i; +- unsigned int v; ++ unsigned int v, smallest_alpha = 0xFF, alpha_component = 0; + + bytestream_put_buffer(bytestream, "GIF", 3); + bytestream_put_buffer(bytestream, "89a", 3); +@@ -77,6 +77,20 @@ + for(i=0;i<256;i++) { + v = palette[i]; + bytestream_put_be24(bytestream, v); ++ if (v >> 24 < smallest_alpha) { ++ smallest_alpha = v >> 24; ++ alpha_component = i; ++ } ++ } ++ ++ if (smallest_alpha < 128) { ++ bytestream_put_byte(bytestream, 0x21); /* Extension Introducer */ ++ bytestream_put_byte(bytestream, 0xf9); /* Graphic Control Label */ ++ bytestream_put_byte(bytestream, 0x04); /* block length */ ++ bytestream_put_byte(bytestream, 0x01); /* Transparent Color Flag */ ++ bytestream_put_le16(bytestream, 0x00); /* no delay */ ++ bytestream_put_byte(bytestream, alpha_component); ++ bytestream_put_byte(bytestream, 0x00); + } + + return 0; +@@ -150,7 +164,7 @@ + uint8_t *end = outbuf + buf_size; + + *p = *pict; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + gif_image_write_header(avctx, &outbuf_ptr, (uint32_t *)pict->data[1]); + gif_image_write_image(avctx, &outbuf_ptr, end, pict->data[0], pict->linesize[0]); +@@ -167,13 +181,13 @@ + } + + AVCodec ff_gif_encoder = { +- "gif", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_GIF, +- sizeof(GIFContext), +- gif_encode_init, +- gif_encode_frame, +- gif_encode_close, ++ .name = "gif", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_GIF, ++ .priv_data_size = sizeof(GIFContext), ++ .init = gif_encode_init, ++ .encode = gif_encode_frame, ++ .close = gif_encode_close, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gifdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gifdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gifdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gifdec.c 2012-05-14 14:08:53.766328550 +0200 +@@ -22,7 +22,7 @@ + + //#define DEBUG + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + #include "lzw.h" +@@ -96,11 +96,11 @@ + n = (1 << bits_per_pixel); + spal = palette; + for(i = 0; i < n; i++) { +- s->image_palette[i] = (0xff << 24) | AV_RB24(spal); ++ s->image_palette[i] = (0xffu << 24) | AV_RB24(spal); + spal += 3; + } + for(; i < 256; i++) +- s->image_palette[i] = (0xff << 24); ++ s->image_palette[i] = (0xffu << 24); + /* handle transparency */ + if (s->transparent_color_index >= 0) + s->image_palette[s->transparent_color_index] = 0; +@@ -326,14 +326,13 @@ + } + + AVCodec ff_gif_decoder = { +- "gif", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_GIF, +- sizeof(GifState), +- gif_decode_init, +- NULL, +- gif_decode_close, +- gif_decode_frame, +- CODEC_CAP_DR1, ++ .name = "gif", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_GIF, ++ .priv_data_size = sizeof(GifState), ++ .init = gif_decode_init, ++ .close = gif_decode_close, ++ .decode = gif_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("GIF (Graphics Interchange Format)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/golomb.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/golomb.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/golomb.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/golomb.h 2012-05-14 14:08:53.767328570 +0200 +@@ -75,6 +75,20 @@ + } + } + ++/** ++ * Read an unsigned Exp-Golomb code in the range 0 to UINT32_MAX-1. ++ */ ++static inline unsigned get_ue_golomb_long(GetBitContext *gb) ++{ ++ unsigned buf, log; ++ ++ buf = show_bits_long(gb, 32); ++ log = 31 - av_log2(buf); ++ skip_bits_long(gb, log); ++ ++ return get_bits_long(gb, log + 1) - 1; ++} ++ + /** + * read unsigned exp golomb code, constraint to a max of 31. + * the return value is undefined if the stored value exceeds 31. +@@ -109,7 +123,7 @@ + }else{ + int ret = 1; + +- while (1) { ++ do { + buf >>= 32 - 8; + LAST_SKIP_BITS(re, gb, FFMIN(ff_interleaved_golomb_vlc_len[buf], 8)); + +@@ -121,7 +135,7 @@ + ret = (ret << 4) | ff_interleaved_dirac_golomb_vlc_code[buf]; + UPDATE_CACHE(re, gb); + buf = GET_CACHE(re, gb); +- } ++ } while (ret<0x8000000U && HAVE_BITS_REMAINING(re, gb)); + + CLOSE_READER(re, gb); + return ret - 1; +@@ -287,7 +301,9 @@ + return buf; + }else{ + int i; +- for(i=0; SHOW_UBITS(re, gb, 1) == 0; i++){ ++ for (i = 0; i < limit && SHOW_UBITS(re, gb, 1) == 0; i++) { ++ if (gb->size_in_bits <= re_index) ++ return -1; + LAST_SKIP_BITS(re, gb, 1); + UPDATE_CACHE(re, gb); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec.c 2012-05-14 14:08:53.769328610 +0200 +@@ -32,6 +32,8 @@ + + static av_cold int gsm_init(AVCodecContext *avctx) + { ++ GSMContext *s = avctx->priv_data; ++ + avctx->channels = 1; + if (!avctx->sample_rate) + avctx->sample_rate = 8000; +@@ -47,24 +49,34 @@ + avctx->block_align = GSM_MS_BLOCK_SIZE; + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + + static int gsm_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { ++ GSMContext *s = avctx->priv_data; + int res; + GetBitContext gb; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- int16_t *samples = data; +- int frame_bytes = 2 * avctx->frame_size; ++ int16_t *samples; + +- if (*data_size < frame_bytes) +- return -1; +- *data_size = 0; +- if(buf_size < avctx->block_align) ++ if (buf_size < avctx->block_align) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); + return AVERROR_INVALIDDATA; ++ } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = avctx->frame_size; ++ if ((res = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return res; ++ } ++ samples = (int16_t *)s->frame.data[0]; + + switch (avctx->codec_id) { + case CODEC_ID_GSM: +@@ -80,30 +92,39 @@ + if (res < 0) + return res; + } +- *data_size = frame_bytes; ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return avctx->block_align; + } + ++static void gsm_flush(AVCodecContext *avctx) ++{ ++ GSMContext *s = avctx->priv_data; ++ memset(s, 0, sizeof(*s)); ++} ++ + AVCodec ff_gsm_decoder = { +- "gsm", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM, +- sizeof(GSMContext), +- gsm_init, +- NULL, +- NULL, +- gsm_decode_frame, ++ .name = "gsm", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM, ++ .priv_data_size = sizeof(GSMContext), ++ .init = gsm_init, ++ .decode = gsm_decode_frame, ++ .flush = gsm_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("GSM"), + }; + + AVCodec ff_gsm_ms_decoder = { +- "gsm_ms", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM_MS, +- sizeof(GSMContext), +- gsm_init, +- NULL, +- NULL, +- gsm_decode_frame, ++ .name = "gsm_ms", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM_MS, ++ .priv_data_size = sizeof(GSMContext), ++ .init = gsm_init, ++ .decode = gsm_decode_frame, ++ .flush = gsm_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("GSM Microsoft variant"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec_data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec_data.h 2012-05-14 14:08:53.769328610 +0200 +@@ -19,17 +19,14 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef GSMDEC_DATA +-#define GSMDEC_DATA ++#ifndef AVCODEC_GSMDEC_DATA ++#define AVCODEC_GSMDEC_DATA + + #include +- +-// input and output sizes in byte +-#define GSM_BLOCK_SIZE 33 +-#define GSM_MS_BLOCK_SIZE 65 +-#define GSM_FRAME_SIZE 160 ++#include "avcodec.h" + + typedef struct { ++ AVFrame frame; + // Contains first 120 elements from the previous frame + // (used by long_term_synth according to the "lag"), + // then in the following 160 elements the current +@@ -44,4 +41,4 @@ + extern const uint16_t ff_gsm_long_term_gain_tab[4]; + extern const int16_t ff_gsm_dequant_tab[64][8]; + +-#endif ++#endif /* AVCODEC_GSMDEC_DATA */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsmdec_template.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsmdec_template.c 2012-05-14 14:08:53.770328630 +0200 +@@ -25,6 +25,7 @@ + */ + + #include "get_bits.h" ++#include "gsm.h" + #include "gsmdec_data.h" + + static void apcm_dequant_add(GetBitContext *gb, int16_t *dst) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsm.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsm.h 2012-05-14 14:08:53.768328590 +0200 +@@ -0,0 +1,31 @@ ++/* ++ * GSM common header ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_GSM_H ++#define AVCODEC_GSM_H ++ ++/* bytes per block */ ++#define GSM_BLOCK_SIZE 33 ++#define GSM_MS_BLOCK_SIZE 65 ++ ++/* samples per block */ ++#define GSM_FRAME_SIZE 160 ++ ++#endif /* AVCODEC_GSM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsm_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsm_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/gsm_parser.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/gsm_parser.c 2012-05-14 14:08:53.768328590 +0200 +@@ -0,0 +1,79 @@ ++/* ++ * Copyright (c) 2012 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * GSM audio parser ++ * ++ * Splits packets into individual blocks. ++ */ ++ ++#include "parser.h" ++#include "gsm.h" ++ ++typedef struct GSMParseContext { ++ ParseContext pc; ++ int block_size; ++ int remaining; ++} GSMParseContext; ++ ++static int gsm_parse(AVCodecParserContext *s1, AVCodecContext *avctx, ++ const uint8_t **poutbuf, int *poutbuf_size, ++ const uint8_t *buf, int buf_size) ++{ ++ GSMParseContext *s = s1->priv_data; ++ ParseContext *pc = &s->pc; ++ int next; ++ ++ if (!s->block_size) { ++ switch (avctx->codec_id) { ++ case CODEC_ID_GSM: s->block_size = GSM_BLOCK_SIZE; break; ++ case CODEC_ID_GSM_MS: s->block_size = GSM_MS_BLOCK_SIZE; break; ++ default: ++ return AVERROR(EINVAL); ++ } ++ } ++ ++ if (!s->remaining) ++ s->remaining = s->block_size; ++ if (s->remaining <= buf_size) { ++ next = s->remaining; ++ s->remaining = 0; ++ } else { ++ next = END_NOT_FOUND; ++ s->remaining -= buf_size; ++ } ++ ++ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0 || !buf_size) { ++ *poutbuf = NULL; ++ *poutbuf_size = 0; ++ return buf_size; ++ } ++ *poutbuf = buf; ++ *poutbuf_size = buf_size; ++ return next; ++} ++ ++AVCodecParser ff_gsm_parser = { ++ .codec_ids = { CODEC_ID_GSM, CODEC_ID_GSM_MS }, ++ .priv_data_size = sizeof(GSMParseContext), ++ .parser_parse = gsm_parse, ++ .parser_close = ff_parse_close, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261dec.c 2012-05-14 14:08:53.772328671 +0200 +@@ -97,7 +97,7 @@ + } + + /** +- * decodes the group of blocks header or slice header. ++ * Decode the group of blocks header or slice header. + * @return <0 if an error occurred + */ + static int h261_decode_gob_header(H261Context *h){ +@@ -136,7 +136,7 @@ + + if(s->qscale==0) { + av_log(s->avctx, AV_LOG_ERROR, "qscale has forbidden 0 value\n"); +- if (s->avctx->error_recognition >= FF_ER_COMPLIANT) ++ if (s->avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT)) + return -1; + } + +@@ -150,7 +150,7 @@ + } + + /** +- * decodes the group of blocks / video packet header. ++ * Decode the group of blocks / video packet header. + * @return <0 if no resync found + */ + static int ff_h261_resync(H261Context *h){ +@@ -191,7 +191,7 @@ + } + + /** +- * decodes skipped macroblocks ++ * Decode skipped macroblocks. + * @return 0 + */ + static int h261_decode_mb_skipped(H261Context *h, int mba1, int mba2 ) +@@ -215,7 +215,7 @@ + + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = 1; +@@ -265,7 +265,7 @@ + while( h->mba_diff == MBA_STUFFING ); // stuffing + + if ( h->mba_diff < 0 ){ +- if ( get_bits_count(&s->gb) + 7 >= s->gb.size_in_bits ) ++ if (get_bits_left(&s->gb) <= 7) + return SLICE_END; + + av_log(s->avctx, AV_LOG_ERROR, "illegal mba at %d %d\n", s->mb_x, s->mb_y); +@@ -323,14 +323,14 @@ + } + + if(s->mb_intra){ +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + goto intra; + } + + //set motion vectors + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = h->current_mv_x * 2;//gets divided by 2 in motion compensation + s->mv[0][0][1] = h->current_mv_y * 2; + +@@ -355,7 +355,7 @@ + } + + /** +- * decodes a macroblock ++ * Decode a macroblock. + * @return <0 if an error occurred + */ + static int h261_decode_block(H261Context * h, DCTELEM * block, +@@ -437,7 +437,7 @@ + } + + /** +- * decodes the H261 picture header. ++ * Decode the H.261 picture header. + * @return <0 if no startcode found + */ + static int h261_decode_picture_header(H261Context *h){ +@@ -464,7 +464,7 @@ + s->picture_number = (s->picture_number&~31) + i; + + s->avctx->time_base= (AVRational){1001, 30000}; +- s->current_picture.pts= s->picture_number; ++ s->current_picture.f.pts = s->picture_number; + + + /* PTYPE starts here */ +@@ -497,9 +497,9 @@ + skip_bits(&s->gb, 8); + } + +- // h261 has no I-FRAMES, but if we pass FF_I_TYPE for the first frame, the codec crashes if it does ++ // h261 has no I-FRAMES, but if we pass AV_PICTURE_TYPE_I for the first frame, the codec crashes if it does + // not contain all I-blocks (e.g. when a packet is lost) +- s->pict_type = FF_P_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_P; + + h->gob_number = 0; + return 0; +@@ -570,8 +570,10 @@ + } + + //we need to set current_picture_ptr before reading the header, otherwise we cannot store anyting im there +- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ ++ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { + int i= ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; + s->current_picture_ptr= &s->picture[i]; + } + +@@ -595,14 +597,12 @@ + goto retry; + } + +- // for hurry_up==5 +- s->current_picture.pict_type= s->pict_type; +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; +- +- /* skip everything if we are in a hurry>=5 */ +- if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); +- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) +- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) ++ // for skipping the frame ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; ++ ++ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) ++ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) + || avctx->skip_frame >= AVDISCARD_ALL) + return get_consumed_bytes(s, buf_size); + +@@ -622,8 +622,8 @@ + } + MPV_frame_end(s); + +-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); +-assert(s->current_picture.pict_type == s->pict_type); ++assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); ++assert(s->current_picture.f.pict_type == s->pict_type); + *pict= *(AVFrame*)s->current_picture_ptr; + ff_print_debug_info(s, pict); + +@@ -642,15 +642,14 @@ + } + + AVCodec ff_h261_decoder = { +- "h261", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H261, +- sizeof(H261Context), +- h261_decode_init, +- NULL, +- h261_decode_end, +- h261_decode_frame, +- CODEC_CAP_DR1, ++ .name = "h261", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H261, ++ .priv_data_size = sizeof(H261Context), ++ .init = h261_decode_init, ++ .close = h261_decode_end, ++ .decode = h261_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("H.261"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261enc.c 2012-05-14 14:08:53.773328691 +0200 +@@ -53,7 +53,7 @@ + H261Context * h = (H261Context *) s; + int format, temp_ref; + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + + /* Update the pointer to last GOB */ + s->ptr_lastgob = put_bits_ptr(&s->pb); +@@ -251,7 +251,7 @@ + + + /** +- * encodes a 8x8 block. ++ * Encode an 8x8 block. + * @param block the 8x8 block + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +@@ -322,13 +322,13 @@ + } + + AVCodec ff_h261_encoder = { +- "h261", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H261, +- sizeof(H261Context), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "h261", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H261, ++ .priv_data_size = sizeof(H261Context), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("H.261"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h261_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h261_parser.c 2012-05-14 14:08:53.771328650 +0200 +@@ -70,11 +70,15 @@ + ParseContext *pc = s->priv_data; + int next; + +- next= h261_find_frame_end(pc,avctx, buf, buf_size); +- if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { +- *poutbuf = NULL; +- *poutbuf_size = 0; +- return buf_size; ++ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { ++ next = buf_size; ++ } else { ++ next= h261_find_frame_end(pc,avctx, buf, buf_size); ++ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { ++ *poutbuf = NULL; ++ *poutbuf_size = 0; ++ return buf_size; ++ } + } + *poutbuf = buf; + *poutbuf_size = buf_size; +@@ -82,9 +86,8 @@ + } + + AVCodecParser ff_h261_parser = { +- { CODEC_ID_H261 }, +- sizeof(ParseContext), +- NULL, +- h261_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_H261 }, ++ .priv_data_size = sizeof(ParseContext), ++ .parser_parse = h261_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263.c 2012-05-14 14:08:53.774328711 +0200 +@@ -1,5 +1,5 @@ + /* +- * H263/MPEG4 backend for ffmpeg encoder and decoder ++ * H263/MPEG4 backend for encoder and decoder + * Copyright (c) 2000,2001 Fabrice Bellard + * H263+ support. + * Copyright (c) 2001 Juan J. Sierralta P +@@ -52,7 +52,7 @@ + const int wrap = s->b8_stride; + const int xy = s->block_index[0]; + +- s->current_picture.mbskip_table[mb_xy]= s->mb_skipped; ++ s->current_picture.f.mbskip_table[mb_xy] = s->mb_skipped; + + if(s->mv_type != MV_TYPE_8X8){ + int motion_x, motion_y; +@@ -71,30 +71,30 @@ + s->p_field_mv_table[i][0][mb_xy][0]= s->mv[0][i][0]; + s->p_field_mv_table[i][0][mb_xy][1]= s->mv[0][i][1]; + } +- s->current_picture.ref_index[0][4*mb_xy ]= +- s->current_picture.ref_index[0][4*mb_xy + 1]= s->field_select[0][0]; +- s->current_picture.ref_index[0][4*mb_xy + 2]= +- s->current_picture.ref_index[0][4*mb_xy + 3]= s->field_select[0][1]; ++ s->current_picture.f.ref_index[0][4*mb_xy ] = ++ s->current_picture.f.ref_index[0][4*mb_xy + 1] = s->field_select[0][0]; ++ s->current_picture.f.ref_index[0][4*mb_xy + 2] = ++ s->current_picture.f.ref_index[0][4*mb_xy + 3] = s->field_select[0][1]; + } + + /* no update if 8X8 because it has been done during parsing */ +- s->current_picture.motion_val[0][xy][0] = motion_x; +- s->current_picture.motion_val[0][xy][1] = motion_y; +- s->current_picture.motion_val[0][xy + 1][0] = motion_x; +- s->current_picture.motion_val[0][xy + 1][1] = motion_y; +- s->current_picture.motion_val[0][xy + wrap][0] = motion_x; +- s->current_picture.motion_val[0][xy + wrap][1] = motion_y; +- s->current_picture.motion_val[0][xy + 1 + wrap][0] = motion_x; +- s->current_picture.motion_val[0][xy + 1 + wrap][1] = motion_y; ++ s->current_picture.f.motion_val[0][xy][0] = motion_x; ++ s->current_picture.f.motion_val[0][xy][1] = motion_y; ++ s->current_picture.f.motion_val[0][xy + 1][0] = motion_x; ++ s->current_picture.f.motion_val[0][xy + 1][1] = motion_y; ++ s->current_picture.f.motion_val[0][xy + wrap][0] = motion_x; ++ s->current_picture.f.motion_val[0][xy + wrap][1] = motion_y; ++ s->current_picture.f.motion_val[0][xy + 1 + wrap][0] = motion_x; ++ s->current_picture.f.motion_val[0][xy + 1 + wrap][1] = motion_y; + } + + if(s->encoding){ //FIXME encoding MUST be cleaned up + if (s->mv_type == MV_TYPE_8X8) +- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_8x8; ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_8x8; + else if(s->mb_intra) +- s->current_picture.mb_type[mb_xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_INTRA; + else +- s->current_picture.mb_type[mb_xy]= MB_TYPE_L0 | MB_TYPE_16x16; ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_L0 | MB_TYPE_16x16; + } + } + +@@ -148,13 +148,13 @@ + uint8_t *dest_cb= s->dest[1]; + uint8_t *dest_cr= s->dest[2]; + +-// if(s->pict_type==FF_B_TYPE && !s->readable) return; ++// if(s->pict_type==AV_PICTURE_TYPE_B && !s->readable) return; + + /* + Diag Top + Left Center + */ +- if(!IS_SKIP(s->current_picture.mb_type[xy])){ ++ if (!IS_SKIP(s->current_picture.f.mb_type[xy])) { + qp_c= s->qscale; + s->dsp.h263_v_loop_filter(dest_y+8*linesize , linesize, qp_c); + s->dsp.h263_v_loop_filter(dest_y+8*linesize+8, linesize, qp_c); +@@ -164,10 +164,10 @@ + if(s->mb_y){ + int qp_dt, qp_tt, qp_tc; + +- if(IS_SKIP(s->current_picture.mb_type[xy-s->mb_stride])) ++ if (IS_SKIP(s->current_picture.f.mb_type[xy - s->mb_stride])) + qp_tt=0; + else +- qp_tt= s->current_picture.qscale_table[xy-s->mb_stride]; ++ qp_tt = s->current_picture.f.qscale_table[xy - s->mb_stride]; + + if(qp_c) + qp_tc= qp_c; +@@ -187,10 +187,10 @@ + s->dsp.h263_h_loop_filter(dest_y-8*linesize+8 , linesize, qp_tt); + + if(s->mb_x){ +- if(qp_tt || IS_SKIP(s->current_picture.mb_type[xy-1-s->mb_stride])) ++ if (qp_tt || IS_SKIP(s->current_picture.f.mb_type[xy - 1 - s->mb_stride])) + qp_dt= qp_tt; + else +- qp_dt= s->current_picture.qscale_table[xy-1-s->mb_stride]; ++ qp_dt = s->current_picture.f.qscale_table[xy - 1 - s->mb_stride]; + + if(qp_dt){ + const int chroma_qp= s->chroma_qscale_table[qp_dt]; +@@ -209,10 +209,10 @@ + + if(s->mb_x){ + int qp_lc; +- if(qp_c || IS_SKIP(s->current_picture.mb_type[xy-1])) ++ if (qp_c || IS_SKIP(s->current_picture.f.mb_type[xy - 1])) + qp_lc= qp_c; + else +- qp_lc= s->current_picture.qscale_table[xy-1]; ++ qp_lc = s->current_picture.f.qscale_table[xy - 1]; + + if(qp_lc){ + s->dsp.h263_h_loop_filter(dest_y, linesize, qp_lc); +@@ -321,7 +321,7 @@ + static const int off[4]= {2, 1, 1, -1}; + + wrap = s->b8_stride; +- mot_val = s->current_picture.motion_val[dir] + s->block_index[block]; ++ mot_val = s->current_picture.f.motion_val[dir] + s->block_index[block]; + + A = mot_val[ - 1]; + /* special case for first (slice) line */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263data.h 2012-05-14 14:08:53.776328751 +0200 +@@ -264,11 +264,11 @@ + 0, 1, 2, 3, 4, 5, 6, 6, 7, 8, 9, 9,10,10,11,11,12,12,12,13,13,13,14,14,14,14,14,15,15,15,15,15 + }; + +-uint16_t ff_mba_max[6]={ ++const uint16_t ff_mba_max[6]={ + 47, 98, 395,1583,6335,9215 + }; + +-uint8_t ff_mba_length[7]={ ++const uint8_t ff_mba_length[7]={ + 6, 7, 9, 11, 13, 14, 14 + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263dec.c 2012-05-14 14:08:53.778328791 +0200 +@@ -25,6 +25,8 @@ + * H.263 decoder. + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + #include "libavutil/cpu.h" + #include "internal.h" + #include "avcodec.h" +@@ -35,6 +37,7 @@ + #include "mpeg4video_parser.h" + #include "msmpeg4.h" + #include "vdpau_internal.h" ++#include "thread.h" + #include "flv.h" + #include "mpeg4video.h" + +@@ -69,33 +72,29 @@ + case CODEC_ID_MPEG4: + break; + case CODEC_ID_MSMPEG4V1: +- s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->msmpeg4_version=1; + break; + case CODEC_ID_MSMPEG4V2: +- s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->msmpeg4_version=2; + break; + case CODEC_ID_MSMPEG4V3: +- s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->msmpeg4_version=3; + break; + case CODEC_ID_WMV1: +- s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->msmpeg4_version=4; + break; + case CODEC_ID_WMV2: +- s->h263_msmpeg4 = 1; + s->h263_pred = 1; + s->msmpeg4_version=5; + break; + case CODEC_ID_VC1: + case CODEC_ID_WMV3: +- s->h263_msmpeg4 = 1; ++ case CODEC_ID_VC1IMAGE: ++ case CODEC_ID_WMV3IMAGE: + s->h263_pred = 1; + s->msmpeg4_version=6; + avctx->chroma_sample_location = AVCHROMA_LOC_LEFT; +@@ -130,7 +129,7 @@ + } + + /** +- * returns the number of bytes consumed for building the current frame ++ * Return the number of bytes consumed for building the current frame. + */ + static int get_consumed_bytes(MpegEncContext *s, int buf_size){ + int pos= (get_bits_count(&s->gb)+7)>>3; +@@ -151,7 +150,7 @@ + } + + static int decode_slice(MpegEncContext *s){ +- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; ++ const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; + const int mb_size= 16>>s->avctx->lowres; + s->last_resync_gb= s->gb; + s->first_slice_line= 1; +@@ -187,7 +186,7 @@ + /* per-row end of slice checks */ + if(s->msmpeg4_version){ + if(s->resync_mb_y + s->slice_height == s->mb_y){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + + return 0; + } +@@ -217,7 +216,7 @@ + //printf("%d %d %06X\n", ret, get_bits_count(&s->gb), show_bits(&s->gb, 24)); + ret= s->decode_mb(s, s->block); + +- if (s->pict_type!=FF_B_TYPE) ++ if (s->pict_type!=AV_PICTURE_TYPE_B) + ff_h263_update_motion_val(s); + + if(ret<0){ +@@ -228,23 +227,24 @@ + ff_h263_loop_filter(s); + + //printf("%d %d %d %06X\n", s->mb_x, s->mb_y, s->gb.size*8 - get_bits_count(&s->gb), show_bits(&s->gb, 24)); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); + + s->padding_bug_score--; + + if(++s->mb_x >= s->mb_width){ + s->mb_x=0; + ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ++ MPV_report_decode_progress(s); + s->mb_y++; + } + return 0; + }else if(ret==SLICE_NOEND){ + av_log(s->avctx, AV_LOG_ERROR, "Slice mismatch at MB: %d\n", xy); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x+1, s->mb_y, ER_MB_END&part_mask); + return -1; + } + av_log(s->avctx, AV_LOG_ERROR, "Error at MB: %d\n", xy); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); + + return -1; + } +@@ -255,6 +255,7 @@ + } + + ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ++ MPV_report_decode_progress(s); + + s->mb_x= 0; + } +@@ -272,7 +273,7 @@ + if( s->codec_id==CODEC_ID_MPEG4 + && (s->workaround_bugs&FF_BUG_AUTODETECT) + && get_bits_left(&s->gb) >=0 +- && get_bits_left(&s->gb) < 48 ++ && get_bits_left(&s->gb) < 137 + // && !s->resync_marker + && !s->data_partitioning){ + +@@ -307,11 +308,11 @@ + int max_extra=7; + + /* no markers in M$ crap */ +- if(s->msmpeg4_version && s->pict_type==FF_I_TYPE) ++ if(s->msmpeg4_version && s->pict_type==AV_PICTURE_TYPE_I) + max_extra+= 17; + + /* buggy padding but the frame should still end approximately at the bitstream end */ +- if((s->workaround_bugs&FF_BUG_NO_PADDING) && s->error_recognition>=3) ++ if((s->workaround_bugs&FF_BUG_NO_PADDING) && (s->err_recognition&(AV_EF_BUFFER|AV_EF_AGGRESSIVE))) + max_extra+= 48; + else if((s->workaround_bugs&FF_BUG_NO_PADDING)) + max_extra+= 256*256*256*64; +@@ -322,7 +323,7 @@ + else if(left<0){ + av_log(s->avctx, AV_LOG_ERROR, "overreading %d bits\n", -left); + }else +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + + return 0; + } +@@ -331,7 +332,7 @@ + get_bits_left(&s->gb), + show_bits(&s->gb, 24), s->padding_bug_score); + +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); + + return -1; + } +@@ -383,6 +384,18 @@ + + + retry: ++ if(s->divx_packed && s->bitstream_buffer_size){ ++ int i; ++ for(i=0; iavctx, AV_LOG_WARNING, "Discarding excessive bitstream in packed xvid\n"); ++ s->bitstream_buffer_size=0; ++ } ++ break; ++ } ++ } ++ } + + if(s->bitstream_buffer_size && (s->divx_packed || buf_size<20)){ //divx 5.01+/xvid frame reorder + init_get_bits(&s->gb, s->bitstream_buffer, s->bitstream_buffer_size*8); +@@ -397,8 +410,10 @@ + + /* We need to set current_picture_ptr before reading the header, + * otherwise we cannot store anyting in there */ +- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ ++ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { + int i= ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; + s->current_picture_ptr= &s->picture[i]; + } + +@@ -552,19 +567,10 @@ + s->workaround_bugs, s->lavc_build, s->xvid_build, s->divx_version, s->divx_build, + s->divx_packed ? "p" : ""); + +-#if 0 // dump bits per frame / qp / complexity +-{ +- static FILE *f=NULL; +- if(!f) f=fopen("rate_qp_cplx.txt", "w"); +- fprintf(f, "%d %d %f\n", buf_size, s->qscale, buf_size*(double)s->qscale); +-} +-#endif +- + #if HAVE_MMX + if (s->codec_id == CODEC_ID_MPEG4 && s->xvid_build>=0 && avctx->idct_algo == FF_IDCT_AUTO && (av_get_cpu_flags() & AV_CPU_FLAG_MMX)) { + avctx->idct_algo= FF_IDCT_XVIDMMX; +- avctx->coded_width= 0; // force reinit +-// dsputil_init(&s->dsp, avctx); ++ ff_dct_common_init(s); + s->picture_number=0; + } + #endif +@@ -578,6 +584,12 @@ + || s->height != avctx->coded_height) { + /* H.263 could change picture size any time */ + ParseContext pc= s->parse_context; //FIXME move these demuxng hack to avformat ++ ++ if (HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_FRAME)) { ++ av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0); ++ return -1; // width / height changed during parallelized decoding ++ } ++ + s->parse_context.buffer=0; + MPV_common_end(s); + s->parse_context= pc; +@@ -591,32 +603,28 @@ + if((s->codec_id==CODEC_ID_H263 || s->codec_id==CODEC_ID_H263P || s->codec_id == CODEC_ID_H263I)) + s->gob_index = ff_h263_get_gob_height(s); + +- // for hurry_up==5 +- s->current_picture.pict_type= s->pict_type; +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; ++ // for skipping the frame ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; + + /* skip B-frames if we don't have reference frames */ +- if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)) return get_consumed_bytes(s, buf_size); +- /* skip b frames if we are in a hurry */ +- if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return get_consumed_bytes(s, buf_size); +- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) +- || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) ++ if(s->last_picture_ptr==NULL && (s->pict_type==AV_PICTURE_TYPE_B || s->dropable)) return get_consumed_bytes(s, buf_size); ++ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) ++ || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) + || avctx->skip_frame >= AVDISCARD_ALL) + return get_consumed_bytes(s, buf_size); +- /* skip everything if we are in a hurry>=5 */ +- if(avctx->hurry_up>=5) return get_consumed_bytes(s, buf_size); + + if(s->next_p_frame_damaged){ +- if(s->pict_type==FF_B_TYPE) ++ if(s->pict_type==AV_PICTURE_TYPE_B) + return get_consumed_bytes(s, buf_size); + else + s->next_p_frame_damaged=0; + } + +- if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==FF_B_TYPE){ ++ if((s->avctx->flags2 & CODEC_FLAG2_FAST) && s->pict_type==AV_PICTURE_TYPE_B){ + s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; +- }else if((!s->no_rounding) || s->pict_type==FF_B_TYPE){ ++ }else if((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ + s->me.qpel_put= s->dsp.put_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; + }else{ +@@ -627,6 +635,8 @@ + if(MPV_frame_start(s, avctx) < 0) + return -1; + ++ if (!s->divx_packed) ff_thread_finish_setup(avctx); ++ + if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) { + ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer); + goto frame_end; +@@ -651,47 +661,46 @@ + s->mb_x=0; + s->mb_y=0; + +- decode_slice(s); ++ ret = decode_slice(s); + while(s->mb_ymb_height){ + if(s->msmpeg4_version){ +- if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits) ++ if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_left(&s->gb)<0) + break; + }else{ ++ int prev_x=s->mb_x, prev_y=s->mb_y; + if(ff_h263_resync(s)<0) + break; ++ if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x) ++ s->error_occurred = 1; + } + + if(s->msmpeg4_version<4 && s->h263_pred) + ff_mpeg4_clean_buffers(s); + +- decode_slice(s); ++ if (decode_slice(s) < 0) ret = AVERROR_INVALIDDATA; + } + +- if (s->h263_msmpeg4 && s->msmpeg4_version<4 && s->pict_type==FF_I_TYPE) ++ if (s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type==AV_PICTURE_TYPE_I) + if(!CONFIG_MSMPEG4_DECODER || msmpeg4_decode_ext_header(s, buf_size) < 0){ +- s->error_status_table[s->mb_num-1]= AC_ERROR|DC_ERROR|MV_ERROR; ++ s->error_status_table[s->mb_num-1]= ER_MB_ERROR; + } + + assert(s->bitstream_buffer_size==0); + frame_end: + /* divx 5.01+ bistream reorder stuff */ + if(s->codec_id==CODEC_ID_MPEG4 && s->divx_packed){ +- int current_pos= get_bits_count(&s->gb)>>3; ++ int current_pos= s->gb.buffer == s->bitstream_buffer ? 0 : (get_bits_count(&s->gb)>>3); + int startcode_found=0; + +- if(buf_size - current_pos > 5){ ++ if(buf_size - current_pos > 7){ + int i; +- for(i=current_pos; igb.buffer == s->bitstream_buffer && buf_size>7 && s->xvid_build>=0){ //xvid style +- startcode_found=1; +- current_pos=0; +- } + + if(startcode_found){ + av_fast_malloc( +@@ -715,9 +724,9 @@ + + MPV_frame_end(s); + +-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); +-assert(s->current_picture.pict_type == s->pict_type); +- if (s->pict_type == FF_B_TYPE || s->low_delay) { ++ assert(s->current_picture.f.pict_type == s->current_picture_ptr->f.pict_type); ++ assert(s->current_picture.f.pict_type == s->pict_type); ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { + *pict= *(AVFrame*)s->current_picture_ptr; + } else if (s->last_picture_ptr != NULL) { + *pict= *(AVFrame*)s->last_picture_ptr; +@@ -732,19 +741,18 @@ + av_log(avctx, AV_LOG_DEBUG, "%"PRId64"\n", rdtsc()-time); + #endif + +- return get_consumed_bytes(s, buf_size); ++ return (ret && (avctx->err_recognition & AV_EF_EXPLODE))?ret:get_consumed_bytes(s, buf_size); + } + + AVCodec ff_h263_decoder = { +- "h263", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H263, +- sizeof(MpegEncContext), +- ff_h263_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, ++ .name = "h263", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H263, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_h263_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, + .flush= ff_mpeg_flush, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996, H.263+ / H.263-1998 / H.263 version 2"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h263.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h263.h 2012-05-14 14:08:53.775328731 +0200 +@@ -59,8 +59,8 @@ + + extern const uint16_t h263_format[8][2]; + extern const uint8_t modified_quant_tab[2][32]; +-extern uint16_t ff_mba_max[6]; +-extern uint8_t ff_mba_length[7]; ++extern const uint16_t ff_mba_max[6]; ++extern const uint8_t ff_mba_length[7]; + + extern uint8_t ff_h263_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; + +@@ -200,52 +200,11 @@ + return cbp; + } + +-static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], +- int motion_x, int motion_y, int mb_type){ +- int cbp=0, i; +- +- if(s->flags & CODEC_FLAG_CBP_RD){ +- int score=0; +- const int lambda= s->lambda2 >> (FF_LAMBDA_SHIFT - 6); +- +- for(i=0; i<6; i++){ +- if(s->coded_score[i] < 0){ +- score += s->coded_score[i]; +- cbp |= 1 << (5 - i); +- } +- } +- +- if(cbp){ +- int zero_score= -6; +- if ((motion_x | motion_y | s->dquant | mb_type) == 0){ +- zero_score-= 4; //2*MV + mb_type + cbp bit +- } +- +- zero_score*= lambda; +- if(zero_score <= score){ +- cbp=0; +- } +- } +- +- for (i = 0; i < 6; i++) { +- if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i))&1)==0 ){ +- s->block_last_index[i]= -1; +- s->dsp.clear_block(s->block[i]); +- } +- } +- }else{ +- for (i = 0; i < 6; i++) { +- if (s->block_last_index[i] >= 0) +- cbp |= 1 << (5 - i); +- } +- } +- return cbp; +-} +- + static inline void memsetw(short *tab, int val, int n) + { + int i; + for(i=0;ipriv_data; + int next; + +- next= ff_h263_find_frame_end(pc, buf, buf_size); ++ if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { ++ next = buf_size; ++ } else { ++ next= ff_h263_find_frame_end(pc, buf, buf_size); + +- if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { +- *poutbuf = NULL; +- *poutbuf_size = 0; +- return buf_size; ++ if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { ++ *poutbuf = NULL; ++ *poutbuf_size = 0; ++ return buf_size; ++ } + } + + *poutbuf = buf; +@@ -84,9 +88,8 @@ + } + + AVCodecParser ff_h263_parser = { +- { CODEC_ID_H263 }, +- sizeof(ParseContext), +- NULL, +- h263_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_H263 }, ++ .priv_data_size = sizeof(ParseContext), ++ .parser_parse = h263_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c 2012-05-14 14:08:53.793329093 +0200 +@@ -25,8 +25,13 @@ + * @author Michael Niedermayer + */ + +-#include "libavcore/imgutils.h" ++#define UNCHECKED_BITSTREAM_READER 1 ++ ++#include "libavutil/imgutils.h" ++#include "libavutil/opt.h" + #include "internal.h" ++#include "cabac.h" ++#include "cabac_functions.h" + #include "dsputil.h" + #include "avcodec.h" + #include "mpegvideo.h" +@@ -36,40 +41,32 @@ + #include "golomb.h" + #include "mathops.h" + #include "rectangle.h" ++#include "thread.h" + #include "vdpau_internal.h" + #include "libavutil/avassert.h" + +-#include "cabac.h" +- + //#undef NDEBUG + #include + +-static const uint8_t rem6[52]={ +-0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, ++static const uint8_t rem6[QP_MAX_NUM+1]={ ++0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, + }; + +-static const uint8_t div6[52]={ +-0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, ++static const uint8_t div6[QP_MAX_NUM+1]={ ++0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, + }; + + static const enum PixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = { + PIX_FMT_DXVA2_VLD, + PIX_FMT_VAAPI_VLD, ++ PIX_FMT_VDA_VLD, + PIX_FMT_YUVJ420P, + PIX_FMT_NONE + }; + +-void ff_h264_write_back_intra_pred_mode(H264Context *h){ +- int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy]; +- +- AV_COPY32(mode, h->intra4x4_pred_mode_cache + 4 + 8*4); +- mode[4]= h->intra4x4_pred_mode_cache[7+8*3]; +- mode[5]= h->intra4x4_pred_mode_cache[7+8*2]; +- mode[6]= h->intra4x4_pred_mode_cache[7+8*1]; +-} +- + /** +- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. ++ * Check if the top & left blocks are available if needed and ++ * change the dc mode so it only uses the available blocks. + */ + int ff_h264_check_intra4x4_pred_mode(H264Context *h){ + MpegEncContext * const s = &h->s; +@@ -105,12 +102,9 @@ + } + + return 0; +-} //FIXME cleanup like ff_h264_check_intra_pred_mode ++} //FIXME cleanup like check_intra_pred_mode + +-/** +- * checks if the top & left blocks are available if needed & changes the dc mode so it only uses the available blocks. +- */ +-int ff_h264_check_intra_pred_mode(H264Context *h, int mode){ ++int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma){ + MpegEncContext * const s = &h->s; + static const int8_t top [7]= {LEFT_DC_PRED8x8, 1,-1,-1}; + static const int8_t left[7]= { TOP_DC_PRED8x8,-1, 2,-1,DC_128_PRED8x8}; +@@ -130,7 +124,7 @@ + + if((h->left_samples_available&0x8080) != 0x8080){ + mode= left[ mode ]; +- if(h->left_samples_available&0x8080){ //mad cow disease mode, aka MBAFF + constrained_intra_pred ++ if(is_chroma && (h->left_samples_available&0x8080)){ //mad cow disease mode, aka MBAFF + constrained_intra_pred + mode= ALZHEIMER_DC_L0T_PRED8x8 + (!(h->left_samples_available&0x8000)) + 2*(mode == DC_128_PRED8x8); + } + if(mode<0){ +@@ -142,6 +136,7 @@ + return mode; + } + ++ + const uint8_t *ff_h264_decode_nal(H264Context *h, const uint8_t *src, int *dst_length, int *consumed, int length){ + int i, si, di; + uint8_t *dst; +@@ -152,10 +147,6 @@ + h->nal_unit_type= src[0]&0x1F; + + src++; length--; +-#if 0 +- for(i=0; i=length-1){ //no escaped 0 +- *dst_length= length; +- *consumed= length+1; //+1 for the header +- return src; +- } +- + bufidx = h->nal_unit_type == NAL_DPC ? 1 : 0; // use second escape buffer for inter data +- av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE); ++ si=h->rbsp_buffer_size[bufidx]; ++ av_fast_malloc(&h->rbsp_buffer[bufidx], &h->rbsp_buffer_size[bufidx], length+FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE); + dst= h->rbsp_buffer[bufidx]; ++ if(si != h->rbsp_buffer_size[bufidx]) ++ memset(dst + length, 0, FF_INPUT_BUFFER_PADDING_SIZE+MAX_MBPAIR_SIZE); + + if (dst == NULL){ + return NULL; + } + ++ if(i>=length-1){ //no escaped 0 ++ *dst_length= length; ++ *consumed= length+1; //+1 for the header ++ if(h->s.avctx->flags2 & CODEC_FLAG2_FAST){ ++ return src; ++ }else{ ++ memcpy(dst, src, length); ++ return dst; ++ } ++ } ++ + //printf("decoding esc\n"); + memcpy(dst, src, i); + si=di=i; +@@ -249,6 +248,141 @@ + return 0; + } + ++static inline int get_lowest_part_list_y(H264Context *h, Picture *pic, int n, int height, ++ int y_offset, int list){ ++ int raw_my= h->mv_cache[list][ scan8[n] ][1]; ++ int filter_height= (raw_my&3) ? 2 : 0; ++ int full_my= (raw_my>>2) + y_offset; ++ int top = full_my - filter_height, bottom = full_my + height + filter_height; ++ ++ return FFMAX(abs(top), bottom); ++} ++ ++static inline void get_lowest_part_y(H264Context *h, int refs[2][48], int n, int height, ++ int y_offset, int list0, int list1, int *nrefs){ ++ MpegEncContext * const s = &h->s; ++ int my; ++ ++ y_offset += 16*(s->mb_y >> MB_FIELD); ++ ++ if(list0){ ++ int ref_n = h->ref_cache[0][ scan8[n] ]; ++ Picture *ref= &h->ref_list[0][ref_n]; ++ ++ // Error resilience puts the current picture in the ref list. ++ // Don't try to wait on these as it will cause a deadlock. ++ // Fields can wait on each other, though. ++ if (ref->f.thread_opaque != s->current_picture.f.thread_opaque || ++ (ref->f.reference & 3) != s->picture_structure) { ++ my = get_lowest_part_list_y(h, ref, n, height, y_offset, 0); ++ if (refs[0][ref_n] < 0) nrefs[0] += 1; ++ refs[0][ref_n] = FFMAX(refs[0][ref_n], my); ++ } ++ } ++ ++ if(list1){ ++ int ref_n = h->ref_cache[1][ scan8[n] ]; ++ Picture *ref= &h->ref_list[1][ref_n]; ++ ++ if (ref->f.thread_opaque != s->current_picture.f.thread_opaque || ++ (ref->f.reference & 3) != s->picture_structure) { ++ my = get_lowest_part_list_y(h, ref, n, height, y_offset, 1); ++ if (refs[1][ref_n] < 0) nrefs[1] += 1; ++ refs[1][ref_n] = FFMAX(refs[1][ref_n], my); ++ } ++ } ++} ++ ++/** ++ * Wait until all reference frames are available for MC operations. ++ * ++ * @param h the H264 context ++ */ ++static void await_references(H264Context *h){ ++ MpegEncContext * const s = &h->s; ++ const int mb_xy= h->mb_xy; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; ++ int refs[2][48]; ++ int nrefs[2] = {0}; ++ int ref, list; ++ ++ memset(refs, -1, sizeof(refs)); ++ ++ if(IS_16X16(mb_type)){ ++ get_lowest_part_y(h, refs, 0, 16, 0, ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); ++ }else if(IS_16X8(mb_type)){ ++ get_lowest_part_y(h, refs, 0, 8, 0, ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); ++ get_lowest_part_y(h, refs, 8, 8, 8, ++ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); ++ }else if(IS_8X16(mb_type)){ ++ get_lowest_part_y(h, refs, 0, 16, 0, ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), nrefs); ++ get_lowest_part_y(h, refs, 4, 16, 0, ++ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), nrefs); ++ }else{ ++ int i; ++ ++ assert(IS_8X8(mb_type)); ++ ++ for(i=0; i<4; i++){ ++ const int sub_mb_type= h->sub_mb_type[i]; ++ const int n= 4*i; ++ int y_offset= (i&2)<<2; ++ ++ if(IS_SUB_8X8(sub_mb_type)){ ++ get_lowest_part_y(h, refs, n , 8, y_offset, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ }else if(IS_SUB_8X4(sub_mb_type)){ ++ get_lowest_part_y(h, refs, n , 4, y_offset, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ get_lowest_part_y(h, refs, n+2, 4, y_offset+4, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ }else if(IS_SUB_4X8(sub_mb_type)){ ++ get_lowest_part_y(h, refs, n , 8, y_offset, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ get_lowest_part_y(h, refs, n+1, 8, y_offset, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ }else{ ++ int j; ++ assert(IS_SUB_4X4(sub_mb_type)); ++ for(j=0; j<4; j++){ ++ int sub_y_offset= y_offset + 2*(j&2); ++ get_lowest_part_y(h, refs, n+j, 4, sub_y_offset, ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), nrefs); ++ } ++ } ++ } ++ } ++ ++ for(list=h->list_count-1; list>=0; list--){ ++ for(ref=0; ref<48 && nrefs[list]; ref++){ ++ int row = refs[list][ref]; ++ if(row >= 0){ ++ Picture *ref_pic = &h->ref_list[list][ref]; ++ int ref_field = ref_pic->f.reference - 1; ++ int ref_field_picture = ref_pic->field_picture; ++ int pic_height = 16*s->mb_height >> ref_field_picture; ++ ++ row <<= MB_MBAFF; ++ nrefs[list]--; ++ ++ if(!FIELD_PICTURE && ref_field_picture){ // frame referencing two fields ++ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) - !(row&1), pic_height-1), 1); ++ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN((row >> 1) , pic_height-1), 0); ++ }else if(FIELD_PICTURE && !ref_field_picture){ // field referencing one field of a frame ++ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row*2 + ref_field , pic_height-1), 0); ++ }else if(FIELD_PICTURE){ ++ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), ref_field); ++ }else{ ++ ff_thread_await_progress((AVFrame*)ref_pic, FFMIN(row, pic_height-1), 0); ++ } ++ } ++ } ++ } ++} ++ + #if 0 + /** + * DCT transforms the 16 dc values. +@@ -292,27 +426,6 @@ + #undef xStride + #undef stride + +-static void chroma_dc_dequant_idct_c(DCTELEM *block, int qmul){ +- const int stride= 16*2; +- const int xStride= 16; +- int a,b,c,d,e; +- +- a= block[stride*0 + xStride*0]; +- b= block[stride*0 + xStride*1]; +- c= block[stride*1 + xStride*0]; +- d= block[stride*1 + xStride*1]; +- +- e= a-b; +- a= a+b; +- b= c-d; +- c= c+d; +- +- block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7; +- block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7; +- block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7; +- block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7; +-} +- + #if 0 + static void chroma_dc_dct_c(DCTELEM *block){ + const int stride= 16*2; +@@ -336,15 +449,20 @@ + } + #endif + +-static inline void mc_dir_part(H264Context *h, Picture *pic, int n, int square, int chroma_height, int delta, int list, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int src_x_offset, int src_y_offset, +- qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op){ ++static av_always_inline void ++mc_dir_part(H264Context *h, Picture *pic, int n, int square, ++ int height, int delta, int list, ++ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ int src_x_offset, int src_y_offset, ++ qpel_mc_func *qpix_op, h264_chroma_mc_func chroma_op, ++ int pixel_shift, int chroma_idc) ++{ + MpegEncContext * const s = &h->s; + const int mx= h->mv_cache[list][ scan8[n] ][0] + src_x_offset*8; + int my= h->mv_cache[list][ scan8[n] ][1] + src_y_offset*8; + const int luma_xy= (mx&3) + ((my&3)<<2); +- uint8_t * src_y = pic->data[0] + (mx>>2) + (my>>2)*h->mb_linesize; ++ int offset = ((mx>>2) << pixel_shift) + (my>>2)*h->mb_linesize; ++ uint8_t * src_y = pic->f.data[0] + offset; + uint8_t * src_cb, * src_cr; + int extra_width= h->emu_edge_width; + int extra_height= h->emu_edge_height; +@@ -353,6 +471,7 @@ + const int full_my= my>>2; + const int pic_width = 16*s->mb_width; + const int pic_height = 16*s->mb_height >> MB_FIELD; ++ int ysh; + + if(mx&7) extra_width -= 3; + if(my&7) extra_height -= 3; +@@ -361,8 +480,9 @@ + || full_my < 0-extra_height + || full_mx + 16/*FIXME*/ > pic_width + extra_width + || full_my + 16/*FIXME*/ > pic_height + extra_height){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_y - 2 - 2*h->mb_linesize, h->mb_linesize, 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height); +- src_y= s->edge_emu_buffer + 2 + 2*h->mb_linesize; ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_y - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize, ++ 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height); ++ src_y= s->edge_emu_buffer + (2 << pixel_shift) + 2*h->mb_linesize; + emu=1; + } + +@@ -373,48 +493,91 @@ + + if(CONFIG_GRAY && s->flags&CODEC_FLAG_GRAY) return; + +- if(MB_FIELD){ ++ if(chroma_idc == 3 /* yuv444 */){ ++ src_cb = pic->f.data[1] + offset; ++ if(emu){ ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize, ++ 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height); ++ src_cb= s->edge_emu_buffer + (2 << pixel_shift) + 2*h->mb_linesize; ++ } ++ qpix_op[luma_xy](dest_cb, src_cb, h->mb_linesize); //FIXME try variable height perhaps? ++ if(!square){ ++ qpix_op[luma_xy](dest_cb + delta, src_cb + delta, h->mb_linesize); ++ } ++ ++ src_cr = pic->f.data[2] + offset; ++ if(emu){ ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr - (2 << pixel_shift) - 2*h->mb_linesize, h->mb_linesize, ++ 16+5, 16+5/*FIXME*/, full_mx-2, full_my-2, pic_width, pic_height); ++ src_cr= s->edge_emu_buffer + (2 << pixel_shift) + 2*h->mb_linesize; ++ } ++ qpix_op[luma_xy](dest_cr, src_cr, h->mb_linesize); //FIXME try variable height perhaps? ++ if(!square){ ++ qpix_op[luma_xy](dest_cr + delta, src_cr + delta, h->mb_linesize); ++ } ++ return; ++ } ++ ++ ysh = 3 - (chroma_idc == 2 /* yuv422 */); ++ if(chroma_idc == 1 /* yuv420 */ && MB_FIELD){ + // chroma offset when predicting from a field of opposite parity +- my += 2 * ((s->mb_y & 1) - (pic->reference - 1)); ++ my += 2 * ((s->mb_y & 1) - (pic->f.reference - 1)); + emu |= (my>>3) < 0 || (my>>3) + 8 >= (pic_height>>1); + } +- src_cb= pic->data[1] + (mx>>3) + (my>>3)*h->mb_uvlinesize; +- src_cr= pic->data[2] + (mx>>3) + (my>>3)*h->mb_uvlinesize; ++ ++ src_cb = pic->f.data[1] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->mb_uvlinesize; ++ src_cr = pic->f.data[2] + ((mx >> 3) << pixel_shift) + (my >> ysh) * h->mb_uvlinesize; + + if(emu){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cb, h->mb_uvlinesize, ++ 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), ++ pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); + src_cb= s->edge_emu_buffer; + } +- chroma_op(dest_cb, src_cb, h->mb_uvlinesize, chroma_height, mx&7, my&7); ++ chroma_op(dest_cb, src_cb, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */), ++ mx&7, (my << (chroma_idc == 2 /* yuv422 */)) &7); + + if(emu){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, 9, 9/*FIXME*/, (mx>>3), (my>>3), pic_width>>1, pic_height>>1); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src_cr, h->mb_uvlinesize, ++ 9, 8 * chroma_idc + 1, (mx >> 3), (my >> ysh), ++ pic_width >> 1, pic_height >> (chroma_idc == 1 /* yuv420 */)); + src_cr= s->edge_emu_buffer; + } +- chroma_op(dest_cr, src_cr, h->mb_uvlinesize, chroma_height, mx&7, my&7); ++ chroma_op(dest_cr, src_cr, h->mb_uvlinesize, height >> (chroma_idc == 1 /* yuv420 */), ++ mx&7, (my << (chroma_idc == 2 /* yuv422 */)) &7); + } + +-static inline void mc_part_std(H264Context *h, int n, int square, int chroma_height, int delta, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int x_offset, int y_offset, +- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, +- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, +- int list0, int list1){ ++static av_always_inline void ++mc_part_std(H264Context *h, int n, int square, int height, int delta, ++ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ int x_offset, int y_offset, ++ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, ++ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, ++ int list0, int list1, int pixel_shift, int chroma_idc) ++{ + MpegEncContext * const s = &h->s; + qpel_mc_func *qpix_op= qpix_put; + h264_chroma_mc_func chroma_op= chroma_put; + +- dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize; +- dest_cb += x_offset + y_offset*h->mb_uvlinesize; +- dest_cr += x_offset + y_offset*h->mb_uvlinesize; ++ dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ if (chroma_idc == 3 /* yuv444 */) { ++ dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ } else if (chroma_idc == 2 /* yuv422 */) { ++ dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize; ++ dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize; ++ } else /* yuv420 */ { ++ dest_cb += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize; ++ dest_cr += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize; ++ } + x_offset += 8*s->mb_x; + y_offset += 8*(s->mb_y >> MB_FIELD); + + if(list0){ + Picture *ref= &h->ref_list[0][ h->ref_cache[0][ scan8[n] ] ]; +- mc_dir_part(h, ref, n, square, chroma_height, delta, 0, ++ mc_dir_part(h, ref, n, square, height, delta, 0, + dest_y, dest_cb, dest_cr, x_offset, y_offset, +- qpix_op, chroma_op); ++ qpix_op, chroma_op, pixel_shift, chroma_idc); + + qpix_op= qpix_avg; + chroma_op= chroma_avg; +@@ -422,24 +585,39 @@ + + if(list1){ + Picture *ref= &h->ref_list[1][ h->ref_cache[1][ scan8[n] ] ]; +- mc_dir_part(h, ref, n, square, chroma_height, delta, 1, ++ mc_dir_part(h, ref, n, square, height, delta, 1, + dest_y, dest_cb, dest_cr, x_offset, y_offset, +- qpix_op, chroma_op); ++ qpix_op, chroma_op, pixel_shift, chroma_idc); + } + } + +-static inline void mc_part_weighted(H264Context *h, int n, int square, int chroma_height, int delta, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int x_offset, int y_offset, +- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, +- h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, +- h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, +- int list0, int list1){ ++static av_always_inline void ++mc_part_weighted(H264Context *h, int n, int square, int height, int delta, ++ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ int x_offset, int y_offset, ++ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, ++ h264_weight_func luma_weight_op, h264_weight_func chroma_weight_op, ++ h264_biweight_func luma_weight_avg, h264_biweight_func chroma_weight_avg, ++ int list0, int list1, int pixel_shift, int chroma_idc){ + MpegEncContext * const s = &h->s; ++ int chroma_height; + +- dest_y += 2*x_offset + 2*y_offset*h-> mb_linesize; +- dest_cb += x_offset + y_offset*h->mb_uvlinesize; +- dest_cr += x_offset + y_offset*h->mb_uvlinesize; ++ dest_y += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ if (chroma_idc == 3 /* yuv444 */) { ++ chroma_height = height; ++ chroma_weight_avg = luma_weight_avg; ++ chroma_weight_op = luma_weight_op; ++ dest_cb += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ dest_cr += (2*x_offset << pixel_shift) + 2*y_offset*h->mb_linesize; ++ } else if (chroma_idc == 2 /* yuv422 */) { ++ chroma_height = height; ++ dest_cb += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize; ++ dest_cr += ( x_offset << pixel_shift) + 2*y_offset*h->mb_uvlinesize; ++ } else /* yuv420 */ { ++ chroma_height = height >> 1; ++ dest_cb += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize; ++ dest_cr += ( x_offset << pixel_shift) + y_offset*h->mb_uvlinesize; ++ } + x_offset += 8*s->mb_x; + y_offset += 8*(s->mb_y >> MB_FIELD); + +@@ -447,32 +625,37 @@ + /* don't optimize for luma-only case, since B-frames usually + * use implicit weights => chroma too. */ + uint8_t *tmp_cb = s->obmc_scratchpad; +- uint8_t *tmp_cr = s->obmc_scratchpad + 8; +- uint8_t *tmp_y = s->obmc_scratchpad + 8*h->mb_uvlinesize; ++ uint8_t *tmp_cr = s->obmc_scratchpad + (16 << pixel_shift); ++ uint8_t *tmp_y = s->obmc_scratchpad + 16*h->mb_uvlinesize; + int refn0 = h->ref_cache[0][ scan8[n] ]; + int refn1 = h->ref_cache[1][ scan8[n] ]; + +- mc_dir_part(h, &h->ref_list[0][refn0], n, square, chroma_height, delta, 0, ++ mc_dir_part(h, &h->ref_list[0][refn0], n, square, height, delta, 0, + dest_y, dest_cb, dest_cr, +- x_offset, y_offset, qpix_put, chroma_put); +- mc_dir_part(h, &h->ref_list[1][refn1], n, square, chroma_height, delta, 1, ++ x_offset, y_offset, qpix_put, chroma_put, ++ pixel_shift, chroma_idc); ++ mc_dir_part(h, &h->ref_list[1][refn1], n, square, height, delta, 1, + tmp_y, tmp_cb, tmp_cr, +- x_offset, y_offset, qpix_put, chroma_put); ++ x_offset, y_offset, qpix_put, chroma_put, ++ pixel_shift, chroma_idc); + + if(h->use_weight == 2){ + int weight0 = h->implicit_weight[refn0][refn1][s->mb_y&1]; + int weight1 = 64 - weight0; +- luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, 5, weight0, weight1, 0); +- chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, 5, weight0, weight1, 0); +- chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, 5, weight0, weight1, 0); ++ luma_weight_avg( dest_y, tmp_y, h-> mb_linesize, ++ height, 5, weight0, weight1, 0); ++ chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, ++ chroma_height, 5, weight0, weight1, 0); ++ chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, ++ chroma_height, 5, weight0, weight1, 0); + }else{ +- luma_weight_avg(dest_y, tmp_y, h->mb_linesize, h->luma_log2_weight_denom, ++ luma_weight_avg(dest_y, tmp_y, h->mb_linesize, height, h->luma_log2_weight_denom, + h->luma_weight[refn0][0][0] , h->luma_weight[refn1][1][0], + h->luma_weight[refn0][0][1] + h->luma_weight[refn1][1][1]); +- chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, h->chroma_log2_weight_denom, ++ chroma_weight_avg(dest_cb, tmp_cb, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom, + h->chroma_weight[refn0][0][0][0] , h->chroma_weight[refn1][1][0][0], + h->chroma_weight[refn0][0][0][1] + h->chroma_weight[refn1][1][0][1]); +- chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, h->chroma_log2_weight_denom, ++ chroma_weight_avg(dest_cr, tmp_cr, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom, + h->chroma_weight[refn0][0][1][0] , h->chroma_weight[refn1][1][1][0], + h->chroma_weight[refn0][0][1][1] + h->chroma_weight[refn1][1][1][1]); + } +@@ -480,40 +663,46 @@ + int list = list1 ? 1 : 0; + int refn = h->ref_cache[list][ scan8[n] ]; + Picture *ref= &h->ref_list[list][refn]; +- mc_dir_part(h, ref, n, square, chroma_height, delta, list, ++ mc_dir_part(h, ref, n, square, height, delta, list, + dest_y, dest_cb, dest_cr, x_offset, y_offset, +- qpix_put, chroma_put); ++ qpix_put, chroma_put, pixel_shift, chroma_idc); + +- luma_weight_op(dest_y, h->mb_linesize, h->luma_log2_weight_denom, ++ luma_weight_op(dest_y, h->mb_linesize, height, h->luma_log2_weight_denom, + h->luma_weight[refn][list][0], h->luma_weight[refn][list][1]); + if(h->use_weight_chroma){ +- chroma_weight_op(dest_cb, h->mb_uvlinesize, h->chroma_log2_weight_denom, ++ chroma_weight_op(dest_cb, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom, + h->chroma_weight[refn][list][0][0], h->chroma_weight[refn][list][0][1]); +- chroma_weight_op(dest_cr, h->mb_uvlinesize, h->chroma_log2_weight_denom, ++ chroma_weight_op(dest_cr, h->mb_uvlinesize, chroma_height, h->chroma_log2_weight_denom, + h->chroma_weight[refn][list][1][0], h->chroma_weight[refn][list][1][1]); + } + } + } + +-static inline void mc_part(H264Context *h, int n, int square, int chroma_height, int delta, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int x_offset, int y_offset, +- qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, +- qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, +- h264_weight_func *weight_op, h264_biweight_func *weight_avg, +- int list0, int list1){ ++static av_always_inline void ++mc_part(H264Context *h, int n, int square, int height, int delta, ++ uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ int x_offset, int y_offset, ++ qpel_mc_func *qpix_put, h264_chroma_mc_func chroma_put, ++ qpel_mc_func *qpix_avg, h264_chroma_mc_func chroma_avg, ++ h264_weight_func *weight_op, h264_biweight_func *weight_avg, ++ int list0, int list1, int pixel_shift, int chroma_idc) ++{ + if((h->use_weight==2 && list0 && list1 + && (h->implicit_weight[ h->ref_cache[0][scan8[n]] ][ h->ref_cache[1][scan8[n]] ][h->s.mb_y&1] != 32)) + || h->use_weight==1) +- mc_part_weighted(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, ++ mc_part_weighted(h, n, square, height, delta, dest_y, dest_cb, dest_cr, + x_offset, y_offset, qpix_put, chroma_put, +- weight_op[0], weight_op[3], weight_avg[0], weight_avg[3], list0, list1); ++ weight_op[0], weight_op[1], weight_avg[0], ++ weight_avg[1], list0, list1, pixel_shift, chroma_idc); + else +- mc_part_std(h, n, square, chroma_height, delta, dest_y, dest_cb, dest_cr, +- x_offset, y_offset, qpix_put, chroma_put, qpix_avg, chroma_avg, list0, list1); ++ mc_part_std(h, n, square, height, delta, dest_y, dest_cb, dest_cr, ++ x_offset, y_offset, qpix_put, chroma_put, qpix_avg, ++ chroma_avg, list0, list1, pixel_shift, chroma_idc); + } + +-static inline void prefetch_motion(H264Context *h, int list){ ++static av_always_inline void ++prefetch_motion(H264Context *h, int list, int pixel_shift, int chroma_idc) ++{ + /* fetch pixels for estimated mv 4 macroblocks ahead + * optimized for 64byte cache lines */ + MpegEncContext * const s = &h->s; +@@ -521,49 +710,63 @@ + if(refn >= 0){ + const int mx= (h->mv_cache[list][scan8[0]][0]>>2) + 16*s->mb_x + 8; + const int my= (h->mv_cache[list][scan8[0]][1]>>2) + 16*s->mb_y; +- uint8_t **src= h->ref_list[list][refn].data; +- int off= mx + (my + (s->mb_x&3)*4)*h->mb_linesize + 64; ++ uint8_t **src = h->ref_list[list][refn].f.data; ++ int off= (mx << pixel_shift) + (my + (s->mb_x&3)*4)*h->mb_linesize + (64 << pixel_shift); + s->dsp.prefetch(src[0]+off, s->linesize, 4); +- off= (mx>>1) + ((my>>1) + (s->mb_x&7))*s->uvlinesize + 64; +- s->dsp.prefetch(src[1]+off, src[2]-src[1], 2); ++ if (chroma_idc == 3 /* yuv444 */) { ++ s->dsp.prefetch(src[1]+off, s->linesize, 4); ++ s->dsp.prefetch(src[2]+off, s->linesize, 4); ++ }else{ ++ off= (((mx>>1)+64)<>1) + (s->mb_x&7))*s->uvlinesize; ++ s->dsp.prefetch(src[1]+off, src[2]-src[1], 2); ++ } + } + } + +-static void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++static av_always_inline void hl_motion(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, + qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), + qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg), +- h264_weight_func *weight_op, h264_biweight_func *weight_avg){ ++ h264_weight_func *weight_op, h264_biweight_func *weight_avg, ++ int pixel_shift, int chroma_idc) ++{ + MpegEncContext * const s = &h->s; + const int mb_xy= h->mb_xy; +- const int mb_type= s->current_picture.mb_type[mb_xy]; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + + assert(IS_INTER(mb_type)); + +- prefetch_motion(h, 0); ++ if(HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) ++ await_references(h); ++ prefetch_motion(h, 0, pixel_shift, chroma_idc); + + if(IS_16X16(mb_type)){ +- mc_part(h, 0, 1, 8, 0, dest_y, dest_cb, dest_cr, 0, 0, ++ mc_part(h, 0, 1, 16, 0, dest_y, dest_cb, dest_cr, 0, 0, + qpix_put[0], chroma_put[0], qpix_avg[0], chroma_avg[0], + weight_op, weight_avg, +- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), ++ pixel_shift, chroma_idc); + }else if(IS_16X8(mb_type)){ +- mc_part(h, 0, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 0, ++ mc_part(h, 0, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 0, + qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], +- &weight_op[1], &weight_avg[1], +- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); +- mc_part(h, 8, 0, 4, 8, dest_y, dest_cb, dest_cr, 0, 4, ++ weight_op, weight_avg, ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), ++ pixel_shift, chroma_idc); ++ mc_part(h, 8, 0, 8, 8 << pixel_shift, dest_y, dest_cb, dest_cr, 0, 4, + qpix_put[1], chroma_put[0], qpix_avg[1], chroma_avg[0], +- &weight_op[1], &weight_avg[1], +- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); ++ weight_op, weight_avg, ++ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), ++ pixel_shift, chroma_idc); + }else if(IS_8X16(mb_type)){ +- mc_part(h, 0, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0, ++ mc_part(h, 0, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 0, 0, + qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], +- &weight_op[2], &weight_avg[2], +- IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1)); +- mc_part(h, 4, 0, 8, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0, ++ &weight_op[1], &weight_avg[1], ++ IS_DIR(mb_type, 0, 0), IS_DIR(mb_type, 0, 1), ++ pixel_shift, chroma_idc); ++ mc_part(h, 4, 0, 16, 8*h->mb_linesize, dest_y, dest_cb, dest_cr, 4, 0, + qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], +- &weight_op[2], &weight_avg[2], +- IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1)); ++ &weight_op[1], &weight_avg[1], ++ IS_DIR(mb_type, 1, 0), IS_DIR(mb_type, 1, 1), ++ pixel_shift, chroma_idc); + }else{ + int i; + +@@ -576,50 +779,78 @@ + int y_offset= (i&2)<<1; + + if(IS_SUB_8X8(sub_mb_type)){ +- mc_part(h, n, 1, 4, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, ++ mc_part(h, n, 1, 8, 0, dest_y, dest_cb, dest_cr, x_offset, y_offset, + qpix_put[1], chroma_put[1], qpix_avg[1], chroma_avg[1], +- &weight_op[3], &weight_avg[3], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); ++ &weight_op[1], &weight_avg[1], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); + }else if(IS_SUB_8X4(sub_mb_type)){ +- mc_part(h, n , 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset, ++ mc_part(h, n , 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset, + qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], +- &weight_op[4], &weight_avg[4], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); +- mc_part(h, n+2, 0, 2, 4, dest_y, dest_cb, dest_cr, x_offset, y_offset+2, ++ &weight_op[1], &weight_avg[1], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); ++ mc_part(h, n+2, 0, 4, 4 << pixel_shift, dest_y, dest_cb, dest_cr, x_offset, y_offset+2, + qpix_put[2], chroma_put[1], qpix_avg[2], chroma_avg[1], +- &weight_op[4], &weight_avg[4], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); ++ &weight_op[1], &weight_avg[1], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); + }else if(IS_SUB_4X8(sub_mb_type)){ +- mc_part(h, n , 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset, ++ mc_part(h, n , 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset, y_offset, + qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], +- &weight_op[5], &weight_avg[5], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); +- mc_part(h, n+1, 0, 4, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset, ++ &weight_op[2], &weight_avg[2], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); ++ mc_part(h, n+1, 0, 8, 4*h->mb_linesize, dest_y, dest_cb, dest_cr, x_offset+2, y_offset, + qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], +- &weight_op[5], &weight_avg[5], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); ++ &weight_op[2], &weight_avg[2], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); + }else{ + int j; + assert(IS_SUB_4X4(sub_mb_type)); + for(j=0; j<4; j++){ + int sub_x_offset= x_offset + 2*(j&1); + int sub_y_offset= y_offset + (j&2); +- mc_part(h, n+j, 1, 2, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset, ++ mc_part(h, n+j, 1, 4, 0, dest_y, dest_cb, dest_cr, sub_x_offset, sub_y_offset, + qpix_put[2], chroma_put[2], qpix_avg[2], chroma_avg[2], +- &weight_op[6], &weight_avg[6], +- IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1)); ++ &weight_op[2], &weight_avg[2], ++ IS_DIR(sub_mb_type, 0, 0), IS_DIR(sub_mb_type, 0, 1), ++ pixel_shift, chroma_idc); + } + } + } + } + +- prefetch_motion(h, 1); ++ prefetch_motion(h, 1, pixel_shift, chroma_idc); + } + ++static av_always_inline void ++hl_motion_420(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), ++ qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg), ++ h264_weight_func *weight_op, h264_biweight_func *weight_avg, ++ int pixel_shift) ++{ ++ hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put, ++ qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 1); ++} ++ ++static av_always_inline void ++hl_motion_422(H264Context *h, uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, ++ qpel_mc_func (*qpix_put)[16], h264_chroma_mc_func (*chroma_put), ++ qpel_mc_func (*qpix_avg)[16], h264_chroma_mc_func (*chroma_avg), ++ h264_weight_func *weight_op, h264_biweight_func *weight_avg, ++ int pixel_shift) ++{ ++ hl_motion(h, dest_y, dest_cb, dest_cr, qpix_put, chroma_put, ++ qpix_avg, chroma_avg, weight_op, weight_avg, pixel_shift, 2); ++} + + static void free_tables(H264Context *h, int free_rbsp){ + int i; + H264Context *hx; ++ + av_freep(&h->intra4x4_pred_mode); + av_freep(&h->chroma_pred_mode_table); + av_freep(&h->cbp_table); +@@ -651,17 +882,21 @@ + } + + static void init_dequant8_coeff_table(H264Context *h){ +- int i,q,x; +- h->dequant8_coeff[0] = h->dequant8_buffer[0]; +- h->dequant8_coeff[1] = h->dequant8_buffer[1]; +- +- for(i=0; i<2; i++ ){ +- if(i && !memcmp(h->pps.scaling_matrix8[0], h->pps.scaling_matrix8[1], 64*sizeof(uint8_t))){ +- h->dequant8_coeff[1] = h->dequant8_buffer[0]; +- break; ++ int i,j,q,x; ++ const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); ++ ++ for(i=0; i<6; i++ ){ ++ h->dequant8_coeff[i] = h->dequant8_buffer[i]; ++ for(j=0; jpps.scaling_matrix8[j], h->pps.scaling_matrix8[i], 64*sizeof(uint8_t))){ ++ h->dequant8_coeff[i] = h->dequant8_buffer[j]; ++ break; ++ } + } ++ if(jsps.bit_depth_luma-8); + for(i=0; i<6; i++ ){ + h->dequant4_coeff[i] = h->dequant4_buffer[i]; + for(j=0; jdequant4_coeff[i][0][x] = 1<<6; + if(h->pps.transform_8x8_mode) +- for(i=0; i<2; i++) ++ for(i=0; i<6; i++) + for(x=0; x<64; x++) + h->dequant8_coeff[i][0][x] = 1<<6; + } +@@ -716,12 +952,12 @@ + int ff_h264_alloc_tables(H264Context *h){ + MpegEncContext * const s = &h->s; + const int big_mb_num= s->mb_stride * (s->mb_height+1); +- const int row_mb_num= 2*s->mb_stride*s->avctx->thread_count; ++ const int row_mb_num= 2*s->mb_stride*FFMAX(s->avctx->thread_count, 1); + int x,y; + + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->intra4x4_pred_mode, row_mb_num * 8 * sizeof(uint8_t), fail) + +- FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 32 * sizeof(uint8_t), fail) ++ FF_ALLOCZ_OR_GOTO(h->s.avctx, h->non_zero_count , big_mb_num * 48 * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->slice_table_base , (big_mb_num+s->mb_stride) * sizeof(*h->slice_table_base), fail) + FF_ALLOCZ_OR_GOTO(h->s.avctx, h->cbp_table, big_mb_num * sizeof(uint16_t), fail) + +@@ -775,7 +1011,7 @@ + dst->list_counts = src->list_counts; + + dst->s.obmc_scratchpad = NULL; +- ff_h264_pred_init(&dst->hpc, src->s.codec_id); ++ ff_h264_pred_init(&dst->hpc, src->s.codec_id, src->sps.bit_depth_luma, src->sps.chroma_format_idc); + } + + /** +@@ -783,8 +1019,8 @@ + * Allocate buffers which are not shared amongst multiple threads. + */ + static int context_init(H264Context *h){ +- FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) +- FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * (16+8+8) * sizeof(uint8_t), fail) ++ FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[0], h->s.mb_width * 16*3 * sizeof(uint8_t)*2, fail) ++ FF_ALLOCZ_OR_GOTO(h->s.avctx, h->top_borders[1], h->s.mb_width * 16*3 * sizeof(uint8_t)*2, fail) + + h->ref_cache[0][scan8[5 ]+1] = h->ref_cache[0][scan8[7 ]+1] = h->ref_cache[0][scan8[13]+1] = + h->ref_cache[1][scan8[5 ]+1] = h->ref_cache[1][scan8[7 ]+1] = h->ref_cache[1][scan8[13]+1] = PART_NOT_AVAILABLE; +@@ -803,30 +1039,38 @@ + s->height = s->avctx->height; + s->codec_id= s->avctx->codec->id; + +- ff_h264dsp_init(&h->h264dsp); +- ff_h264_pred_init(&h->hpc, s->codec_id); ++ s->avctx->bits_per_raw_sample = 8; ++ h->cur_chroma_format_idc = 1; ++ ++ ff_h264dsp_init(&h->h264dsp, ++ s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc); ++ ff_h264_pred_init(&h->hpc, s->codec_id, ++ s->avctx->bits_per_raw_sample, h->cur_chroma_format_idc); + + h->dequant_coeff_pps= -1; + s->unrestricted_mv=1; +- s->decode=1; //FIXME + ++ s->dsp.dct_bits = 16; + dsputil_init(&s->dsp, s->avctx); // needed so that idct permutation is known early + + memset(h->pps.scaling_matrix4, 16, 6*16*sizeof(uint8_t)); + memset(h->pps.scaling_matrix8, 16, 2*64*sizeof(uint8_t)); + } + +-int ff_h264_decode_extradata(H264Context *h) ++int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size) + { + AVCodecContext *avctx = h->s.avctx; + +- if(*(char *)avctx->extradata == 1){ ++ if(!buf || size <= 0) ++ return -1; ++ ++ if(buf[0] == 1){ + int i, cnt, nalsize; +- unsigned char *p = avctx->extradata; ++ const unsigned char *p = buf; + + h->is_avc = 1; + +- if(avctx->extradata_size < 7) { ++ if(size < 7) { + av_log(avctx, AV_LOG_ERROR, "avcC too short\n"); + return -1; + } +@@ -838,6 +1082,8 @@ + p += 6; + for (i = 0; i < cnt; i++) { + nalsize = AV_RB16(p) + 2; ++ if(nalsize > size - (p-buf)) ++ return -1; + if(decode_nal_units(h, p, nalsize) < 0) { + av_log(avctx, AV_LOG_ERROR, "Decoding sps %d from avcC failed\n", i); + return -1; +@@ -848,17 +1094,19 @@ + cnt = *(p++); // Number of pps + for (i = 0; i < cnt; i++) { + nalsize = AV_RB16(p) + 2; +- if(decode_nal_units(h, p, nalsize) != nalsize) { ++ if(nalsize > size - (p-buf)) ++ return -1; ++ if (decode_nal_units(h, p, nalsize) < 0) { + av_log(avctx, AV_LOG_ERROR, "Decoding pps %d from avcC failed\n", i); + return -1; + } + p += nalsize; + } + // Now store right nal length size, that will be use to parse all other nals +- h->nal_length_size = ((*(((char*)(avctx->extradata))+4))&0x03)+1; ++ h->nal_length_size = (buf[4] & 0x03) + 1; + } else { + h->is_avc = 0; +- if(decode_nal_units(h, avctx->extradata, avctx->extradata_size) < 0) ++ if(decode_nal_units(h, buf, size) < 0) + return -1; + } + return 0; +@@ -867,6 +1115,7 @@ + av_cold int ff_h264_decode_init(AVCodecContext *avctx){ + H264Context *h= avctx->priv_data; + MpegEncContext * const s = &h->s; ++ int i; + + MPV_decode_defaults(s); + +@@ -886,9 +1135,15 @@ + + ff_h264_decode_init_vlc(); + ++ h->pixel_shift = 0; ++ h->sps.bit_depth_luma = avctx->bits_per_raw_sample = 8; ++ + h->thread_context[0] = h; +- h->outputed_poc = INT_MIN; ++ h->outputed_poc = h->next_outputed_poc = INT_MIN; ++ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) ++ h->last_pocs[i] = INT_MIN; + h->prev_poc_msb= 1<<16; ++ h->prev_frame_num= -1; + h->x264_build = -1; + ff_h264_reset_sei(h); + if(avctx->codec_id == CODEC_ID_H264){ +@@ -899,7 +1154,7 @@ + } + + if(avctx->extradata_size > 0 && avctx->extradata && +- ff_h264_decode_extradata(h)) ++ ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size)) + return -1; + + if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames < h->sps.num_reorder_frames){ +@@ -910,9 +1165,140 @@ + return 0; + } + ++#define IN_RANGE(a, b, size) (((a) >= (b)) && ((a) < ((b)+(size)))) ++static void copy_picture_range(Picture **to, Picture **from, int count, MpegEncContext *new_base, MpegEncContext *old_base) ++{ ++ int i; ++ ++ for (i=0; ipicture, sizeof(Picture) * old_base->picture_count) || ++ !from[i])); ++ to[i] = REBASE_PICTURE(from[i], new_base, old_base); ++ } ++} ++ ++static void copy_parameter_set(void **to, void **from, int count, int size) ++{ ++ int i; ++ ++ for (i=0; ipriv_data; ++ ++ if (!avctx->internal->is_copy) ++ return 0; ++ memset(h->sps_buffers, 0, sizeof(h->sps_buffers)); ++ memset(h->pps_buffers, 0, sizeof(h->pps_buffers)); ++ ++ return 0; ++} ++ ++#define copy_fields(to, from, start_field, end_field) memcpy(&to->start_field, &from->start_field, (char*)&to->end_field - (char*)&to->start_field) ++static int decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src){ ++ H264Context *h= dst->priv_data, *h1= src->priv_data; ++ MpegEncContext * const s = &h->s, * const s1 = &h1->s; ++ int inited = s->context_initialized, err; ++ int i; ++ ++ if(dst == src || !s1->context_initialized) return 0; ++ ++ err = ff_mpeg_update_thread_context(dst, src); ++ if(err) return err; ++ ++ //FIXME handle width/height changing ++ if(!inited){ ++ for(i = 0; i < MAX_SPS_COUNT; i++) ++ av_freep(h->sps_buffers + i); ++ ++ for(i = 0; i < MAX_PPS_COUNT; i++) ++ av_freep(h->pps_buffers + i); ++ ++ memcpy(&h->s + 1, &h1->s + 1, sizeof(H264Context) - sizeof(MpegEncContext)); //copy all fields after MpegEnc ++ memset(h->sps_buffers, 0, sizeof(h->sps_buffers)); ++ memset(h->pps_buffers, 0, sizeof(h->pps_buffers)); ++ if (ff_h264_alloc_tables(h) < 0) { ++ av_log(dst, AV_LOG_ERROR, "Could not allocate memory for h264\n"); ++ return AVERROR(ENOMEM); ++ } ++ context_init(h); ++ ++ for(i=0; i<2; i++){ ++ h->rbsp_buffer[i] = NULL; ++ h->rbsp_buffer_size[i] = 0; ++ } ++ ++ h->thread_context[0] = h; ++ ++ // frame_start may not be called for the next thread (if it's decoding a bottom field) ++ // so this has to be allocated here ++ h->s.obmc_scratchpad = av_malloc(16*6*s->linesize); ++ ++ s->dsp.clear_blocks(h->mb); ++ s->dsp.clear_blocks(h->mb+(24*16<pixel_shift)); ++ } ++ ++ //extradata/NAL handling ++ h->is_avc = h1->is_avc; ++ ++ //SPS/PPS ++ copy_parameter_set((void**)h->sps_buffers, (void**)h1->sps_buffers, MAX_SPS_COUNT, sizeof(SPS)); ++ h->sps = h1->sps; ++ copy_parameter_set((void**)h->pps_buffers, (void**)h1->pps_buffers, MAX_PPS_COUNT, sizeof(PPS)); ++ h->pps = h1->pps; ++ ++ //Dequantization matrices ++ //FIXME these are big - can they be only copied when PPS changes? ++ copy_fields(h, h1, dequant4_buffer, dequant4_coeff); ++ ++ for(i=0; i<6; i++) ++ h->dequant4_coeff[i] = h->dequant4_buffer[0] + (h1->dequant4_coeff[i] - h1->dequant4_buffer[0]); ++ ++ for(i=0; i<6; i++) ++ h->dequant8_coeff[i] = h->dequant8_buffer[0] + (h1->dequant8_coeff[i] - h1->dequant8_buffer[0]); ++ ++ h->dequant_coeff_pps = h1->dequant_coeff_pps; ++ ++ //POC timing ++ copy_fields(h, h1, poc_lsb, redundant_pic_count); ++ ++ //reference lists ++ copy_fields(h, h1, ref_count, list_count); ++ copy_fields(h, h1, ref_list, intra_gb); ++ copy_fields(h, h1, short_ref, cabac_init_idc); ++ ++ copy_picture_range(h->short_ref, h1->short_ref, 32, s, s1); ++ copy_picture_range(h->long_ref, h1->long_ref, 32, s, s1); ++ copy_picture_range(h->delayed_pic, h1->delayed_pic, MAX_DELAYED_PIC_COUNT+2, s, s1); ++ ++ h->last_slice_type = h1->last_slice_type; ++ h->sync = h1->sync; ++ ++ if(!s->current_picture_ptr) return 0; ++ ++ if(!s->dropable) { ++ err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); ++ h->prev_poc_msb = h->poc_msb; ++ h->prev_poc_lsb = h->poc_lsb; ++ } ++ h->prev_frame_num_offset= h->frame_num_offset; ++ h->prev_frame_num = h->frame_num; ++ h->outputed_poc = h->next_outputed_poc; ++ ++ return err; ++} ++ + int ff_h264_frame_start(H264Context *h){ + MpegEncContext * const s = &h->s; + int i; ++ const int pixel_shift = h->pixel_shift; + + if(MPV_frame_start(s, s->avctx) < 0) + return -1; +@@ -923,32 +1309,33 @@ + * Zero here; IDR markings per slice in frame or fields are ORed in later. + * See decode_nal_units(). + */ +- s->current_picture_ptr->key_frame= 0; ++ s->current_picture_ptr->f.key_frame = 0; ++ s->current_picture_ptr->sync = 0; + s->current_picture_ptr->mmco_reset= 0; + + assert(s->linesize && s->uvlinesize); + + for(i=0; i<16; i++){ +- h->block_offset[i]= 4*((scan8[i] - scan8[0])&7) + 4*s->linesize*((scan8[i] - scan8[0])>>3); +- h->block_offset[24+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->linesize*((scan8[i] - scan8[0])>>3); ++ h->block_offset[i]= (4*((scan8[i] - scan8[0])&7) << pixel_shift) + 4*s->linesize*((scan8[i] - scan8[0])>>3); ++ h->block_offset[48+i]= (4*((scan8[i] - scan8[0])&7) << pixel_shift) + 8*s->linesize*((scan8[i] - scan8[0])>>3); + } +- for(i=0; i<4; i++){ ++ for(i=0; i<16; i++){ + h->block_offset[16+i]= +- h->block_offset[20+i]= 4*((scan8[i] - scan8[0])&7) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); +- h->block_offset[24+16+i]= +- h->block_offset[24+20+i]= 4*((scan8[i] - scan8[0])&7) + 8*s->uvlinesize*((scan8[i] - scan8[0])>>3); ++ h->block_offset[32+i]= (4*((scan8[i] - scan8[0])&7) << pixel_shift) + 4*s->uvlinesize*((scan8[i] - scan8[0])>>3); ++ h->block_offset[48+16+i]= ++ h->block_offset[48+32+i]= (4*((scan8[i] - scan8[0])&7) << pixel_shift) + 8*s->uvlinesize*((scan8[i] - scan8[0])>>3); + } + + /* can't be in alloc_tables because linesize isn't known there. + * FIXME: redo bipred weight to not require extra buffer? */ +- for(i = 0; i < s->avctx->thread_count; i++) ++ for(i = 0; i < s->slice_context_count; i++) + if(h->thread_context[i] && !h->thread_context[i]->s.obmc_scratchpad) +- h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*2*s->linesize + 8*2*s->uvlinesize); ++ h->thread_context[i]->s.obmc_scratchpad = av_malloc(16*6*s->linesize); + + /* some macroblocks can be accessed before they're available in case of lost slices, mbaff or threading*/ + memset(h->slice_table, -1, (s->mb_height*s->mb_stride-1) * sizeof(*h->slice_table)); + +-// s->decode= (s->flags&CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.reference /*|| h->contains_intra*/ || 1; ++// s->decode = (s->flags & CODEC_FLAG_PSNR) || !s->encoding || s->current_picture.f.reference /*|| h->contains_intra*/ || 1; + + // We mark the current picture as non-reference after allocating it, so + // that if we break out due to an error it can be released automatically +@@ -957,19 +1344,201 @@ + // get released even with set reference, besides SVQ3 and others do not + // mark frames as reference later "naturally". + if(s->codec_id != CODEC_ID_SVQ3) +- s->current_picture_ptr->reference= 0; ++ s->current_picture_ptr->f.reference = 0; + + s->current_picture_ptr->field_poc[0]= + s->current_picture_ptr->field_poc[1]= INT_MAX; ++ ++ h->next_output_pic = NULL; ++ + assert(s->current_picture_ptr->long_ref==0); + + return 0; + } + +-static inline void backup_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int simple){ ++/** ++ * Run setup operations that must be run after slice header decoding. ++ * This includes finding the next displayed frame. ++ * ++ * @param h h264 master context ++ * @param setup_finished enough NALs have been read that we can call ++ * ff_thread_finish_setup() ++ */ ++static void decode_postinit(H264Context *h, int setup_finished){ ++ MpegEncContext * const s = &h->s; ++ Picture *out = s->current_picture_ptr; ++ Picture *cur = s->current_picture_ptr; ++ int i, pics, out_of_order, out_idx; ++ ++ s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_H264; ++ s->current_picture_ptr->f.pict_type = s->pict_type; ++ ++ if (h->next_output_pic) return; ++ ++ if (cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) { ++ //FIXME: if we have two PAFF fields in one packet, we can't start the next thread here. ++ //If we have one field per packet, we can. The check in decode_nal_units() is not good enough ++ //to find this yet, so we assume the worst for now. ++ //if (setup_finished) ++ // ff_thread_finish_setup(s->avctx); ++ return; ++ } ++ ++ cur->f.interlaced_frame = 0; ++ cur->f.repeat_pict = 0; ++ ++ /* Signal interlacing information externally. */ ++ /* Prioritize picture timing SEI information over used decoding process if it exists. */ ++ ++ if(h->sps.pic_struct_present_flag){ ++ switch (h->sei_pic_struct) ++ { ++ case SEI_PIC_STRUCT_FRAME: ++ break; ++ case SEI_PIC_STRUCT_TOP_FIELD: ++ case SEI_PIC_STRUCT_BOTTOM_FIELD: ++ cur->f.interlaced_frame = 1; ++ break; ++ case SEI_PIC_STRUCT_TOP_BOTTOM: ++ case SEI_PIC_STRUCT_BOTTOM_TOP: ++ if (FIELD_OR_MBAFF_PICTURE) ++ cur->f.interlaced_frame = 1; ++ else ++ // try to flag soft telecine progressive ++ cur->f.interlaced_frame = h->prev_interlaced_frame; ++ break; ++ case SEI_PIC_STRUCT_TOP_BOTTOM_TOP: ++ case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: ++ // Signal the possibility of telecined film externally (pic_struct 5,6) ++ // From these hints, let the applications decide if they apply deinterlacing. ++ cur->f.repeat_pict = 1; ++ break; ++ case SEI_PIC_STRUCT_FRAME_DOUBLING: ++ // Force progressive here, as doubling interlaced frame is a bad idea. ++ cur->f.repeat_pict = 2; ++ break; ++ case SEI_PIC_STRUCT_FRAME_TRIPLING: ++ cur->f.repeat_pict = 4; ++ break; ++ } ++ ++ if ((h->sei_ct_type & 3) && h->sei_pic_struct <= SEI_PIC_STRUCT_BOTTOM_TOP) ++ cur->f.interlaced_frame = (h->sei_ct_type & (1 << 1)) != 0; ++ }else{ ++ /* Derive interlacing flag from used decoding process. */ ++ cur->f.interlaced_frame = FIELD_OR_MBAFF_PICTURE; ++ } ++ h->prev_interlaced_frame = cur->f.interlaced_frame; ++ ++ if (cur->field_poc[0] != cur->field_poc[1]){ ++ /* Derive top_field_first from field pocs. */ ++ cur->f.top_field_first = cur->field_poc[0] < cur->field_poc[1]; ++ }else{ ++ if (cur->f.interlaced_frame || h->sps.pic_struct_present_flag) { ++ /* Use picture timing SEI information. Even if it is a information of a past frame, better than nothing. */ ++ if(h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM ++ || h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP) ++ cur->f.top_field_first = 1; ++ else ++ cur->f.top_field_first = 0; ++ }else{ ++ /* Most likely progressive */ ++ cur->f.top_field_first = 0; ++ } ++ } ++ ++ cur->mmco_reset = h->mmco_reset; ++ h->mmco_reset = 0; ++ //FIXME do something with unavailable reference frames ++ ++ /* Sort B-frames into display order */ ++ ++ if(h->sps.bitstream_restriction_flag ++ && s->avctx->has_b_frames < h->sps.num_reorder_frames){ ++ s->avctx->has_b_frames = h->sps.num_reorder_frames; ++ s->low_delay = 0; ++ } ++ ++ if( s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT ++ && !h->sps.bitstream_restriction_flag){ ++ s->avctx->has_b_frames = MAX_DELAYED_PIC_COUNT - 1; ++ s->low_delay= 0; ++ } ++ ++ for (i = 0; 1; i++) { ++ if(i == MAX_DELAYED_PIC_COUNT || cur->poc < h->last_pocs[i]){ ++ if(i) ++ h->last_pocs[i-1] = cur->poc; ++ break; ++ } else if(i) { ++ h->last_pocs[i-1]= h->last_pocs[i]; ++ } ++ } ++ out_of_order = MAX_DELAYED_PIC_COUNT - i; ++ if( cur->f.pict_type == AV_PICTURE_TYPE_B ++ || (h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > INT_MIN && h->last_pocs[MAX_DELAYED_PIC_COUNT-1] - h->last_pocs[MAX_DELAYED_PIC_COUNT-2] > 2)) ++ out_of_order = FFMAX(out_of_order, 1); ++ if(s->avctx->has_b_frames < out_of_order && !h->sps.bitstream_restriction_flag){ ++ av_log(s->avctx, AV_LOG_WARNING, "Increasing reorder buffer to %d\n", out_of_order); ++ s->avctx->has_b_frames = out_of_order; ++ s->low_delay = 0; ++ } ++ ++ pics = 0; ++ while(h->delayed_pic[pics]) pics++; ++ ++ av_assert0(pics <= MAX_DELAYED_PIC_COUNT); ++ ++ h->delayed_pic[pics++] = cur; ++ if (cur->f.reference == 0) ++ cur->f.reference = DELAYED_PIC_REF; ++ ++ out = h->delayed_pic[0]; ++ out_idx = 0; ++ for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++) ++ if(h->delayed_pic[i]->poc < out->poc){ ++ out = h->delayed_pic[i]; ++ out_idx = i; ++ } ++ if (s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) ++ h->next_outputed_poc= INT_MIN; ++ out_of_order = out->poc < h->next_outputed_poc; ++ ++ if(out_of_order || pics > s->avctx->has_b_frames){ ++ out->f.reference &= ~DELAYED_PIC_REF; ++ out->owner2 = s; // for frame threading, the owner must be the second field's thread ++ // or else the first thread can release the picture and reuse it unsafely ++ for(i=out_idx; h->delayed_pic[i]; i++) ++ h->delayed_pic[i] = h->delayed_pic[i+1]; ++ } ++ if(!out_of_order && pics > s->avctx->has_b_frames){ ++ h->next_output_pic = out; ++ if (out_idx == 0 && h->delayed_pic[0] && (h->delayed_pic[0]->f.key_frame || h->delayed_pic[0]->mmco_reset)) { ++ h->next_outputed_poc = INT_MIN; ++ } else ++ h->next_outputed_poc = out->poc; ++ }else{ ++ av_log(s->avctx, AV_LOG_DEBUG, "no picture %s\n", out_of_order ? "ooo" : ""); ++ } ++ ++ if (h->next_output_pic && h->next_output_pic->sync) { ++ h->sync |= 2; ++ } ++ ++ if (setup_finished) ++ ff_thread_finish_setup(s->avctx); ++} ++ ++static av_always_inline void backup_mb_border(H264Context *h, uint8_t *src_y, ++ uint8_t *src_cb, uint8_t *src_cr, ++ int linesize, int uvlinesize, int simple) ++{ + MpegEncContext * const s = &h->s; + uint8_t *top_border; + int top_idx = 1; ++ const int pixel_shift = h->pixel_shift; ++ int chroma444 = CHROMA444; ++ int chroma422 = CHROMA422; + + src_y -= linesize; + src_cb -= uvlinesize; +@@ -980,9 +1549,36 @@ + if(!MB_MBAFF){ + top_border = h->top_borders[0][s->mb_x]; + AV_COPY128(top_border, src_y + 15*linesize); ++ if (pixel_shift) ++ AV_COPY128(top_border+16, src_y+15*linesize+16); + if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ +- AV_COPY64(top_border+16, src_cb+7*uvlinesize); +- AV_COPY64(top_border+24, src_cr+7*uvlinesize); ++ if(chroma444){ ++ if (pixel_shift){ ++ AV_COPY128(top_border+32, src_cb + 15*uvlinesize); ++ AV_COPY128(top_border+48, src_cb + 15*uvlinesize+16); ++ AV_COPY128(top_border+64, src_cr + 15*uvlinesize); ++ AV_COPY128(top_border+80, src_cr + 15*uvlinesize+16); ++ } else { ++ AV_COPY128(top_border+16, src_cb + 15*uvlinesize); ++ AV_COPY128(top_border+32, src_cr + 15*uvlinesize); ++ } ++ } else if(chroma422){ ++ if (pixel_shift) { ++ AV_COPY128(top_border+32, src_cb + 15*uvlinesize); ++ AV_COPY128(top_border+48, src_cr + 15*uvlinesize); ++ } else { ++ AV_COPY64(top_border+16, src_cb + 15*uvlinesize); ++ AV_COPY64(top_border+24, src_cr + 15*uvlinesize); ++ } ++ } else { ++ if (pixel_shift) { ++ AV_COPY128(top_border+32, src_cb+7*uvlinesize); ++ AV_COPY128(top_border+48, src_cr+7*uvlinesize); ++ } else { ++ AV_COPY64(top_border+16, src_cb+7*uvlinesize); ++ AV_COPY64(top_border+24, src_cr+7*uvlinesize); ++ } ++ } + } + } + }else if(MB_MBAFF){ +@@ -995,16 +1591,47 @@ + // There are two lines saved, the line above the the top macroblock of a pair, + // and the line above the bottom macroblock + AV_COPY128(top_border, src_y + 16*linesize); ++ if (pixel_shift) ++ AV_COPY128(top_border+16, src_y+16*linesize+16); + + if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ +- AV_COPY64(top_border+16, src_cb+8*uvlinesize); +- AV_COPY64(top_border+24, src_cr+8*uvlinesize); ++ if(chroma444){ ++ if (pixel_shift){ ++ AV_COPY128(top_border+32, src_cb + 16*linesize); ++ AV_COPY128(top_border+48, src_cb + 16*linesize+16); ++ AV_COPY128(top_border+64, src_cr + 16*linesize); ++ AV_COPY128(top_border+80, src_cr + 16*linesize+16); ++ } else { ++ AV_COPY128(top_border+16, src_cb + 16*linesize); ++ AV_COPY128(top_border+32, src_cr + 16*linesize); ++ } ++ } else if(chroma422) { ++ if (pixel_shift) { ++ AV_COPY128(top_border+32, src_cb+16*uvlinesize); ++ AV_COPY128(top_border+48, src_cr+16*uvlinesize); ++ } else { ++ AV_COPY64(top_border+16, src_cb+16*uvlinesize); ++ AV_COPY64(top_border+24, src_cr+16*uvlinesize); ++ } ++ } else { ++ if (pixel_shift) { ++ AV_COPY128(top_border+32, src_cb+8*uvlinesize); ++ AV_COPY128(top_border+48, src_cr+8*uvlinesize); ++ } else { ++ AV_COPY64(top_border+16, src_cb+8*uvlinesize); ++ AV_COPY64(top_border+24, src_cr+8*uvlinesize); ++ } ++ } + } + } + +-static inline void xchg_mb_border(H264Context *h, uint8_t *src_y, uint8_t *src_cb, uint8_t *src_cr, int linesize, int uvlinesize, int xchg, int simple){ ++static av_always_inline void xchg_mb_border(H264Context *h, uint8_t *src_y, ++ uint8_t *src_cb, uint8_t *src_cr, ++ int linesize, int uvlinesize, ++ int xchg, int chroma444, ++ int simple, int pixel_shift){ + MpegEncContext * const s = &h->s; +- int deblock_left; ++ int deblock_topleft; + int deblock_top; + int top_idx = 1; + uint8_t *top_border_m1; +@@ -1020,80 +1647,271 @@ + } + + if(h->deblocking_filter == 2) { +- deblock_left = h->left_type[0]; +- deblock_top = h->top_type; ++ deblock_topleft = h->slice_table[h->mb_xy - 1 - s->mb_stride] == h->slice_num; ++ deblock_top = h->top_type; + } else { +- deblock_left = (s->mb_x > 0); +- deblock_top = (s->mb_y > !!MB_FIELD); ++ deblock_topleft = (s->mb_x > 0); ++ deblock_top = (s->mb_y > !!MB_FIELD); + } + +- src_y -= linesize + 1; +- src_cb -= uvlinesize + 1; +- src_cr -= uvlinesize + 1; ++ src_y -= linesize + 1 + pixel_shift; ++ src_cb -= uvlinesize + 1 + pixel_shift; ++ src_cr -= uvlinesize + 1 + pixel_shift; + + top_border_m1 = h->top_borders[top_idx][s->mb_x-1]; + top_border = h->top_borders[top_idx][s->mb_x]; + + #define XCHG(a,b,xchg)\ ++ if (pixel_shift) {\ ++ if (xchg) {\ ++ AV_SWAP64(b+0,a+0);\ ++ AV_SWAP64(b+8,a+8);\ ++ } else {\ ++ AV_COPY128(b,a); \ ++ }\ ++ } else \ + if (xchg) AV_SWAP64(b,a);\ + else AV_COPY64(b,a); + + if(deblock_top){ +- if(deblock_left){ +- XCHG(top_border_m1+8, src_y -7, 1); ++ if(deblock_topleft){ ++ XCHG(top_border_m1 + (8 << pixel_shift), src_y - (7 << pixel_shift), 1); + } +- XCHG(top_border+0, src_y +1, xchg); +- XCHG(top_border+8, src_y +9, 1); ++ XCHG(top_border + (0 << pixel_shift), src_y + (1 << pixel_shift), xchg); ++ XCHG(top_border + (8 << pixel_shift), src_y + (9 << pixel_shift), 1); + if(s->mb_x+1 < s->mb_width){ +- XCHG(h->top_borders[top_idx][s->mb_x+1], src_y +17, 1); ++ XCHG(h->top_borders[top_idx][s->mb_x+1], src_y + (17 << pixel_shift), 1); + } + } +- + if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ +- if(deblock_top){ +- if(deblock_left){ +- XCHG(top_border_m1+16, src_cb -7, 1); +- XCHG(top_border_m1+24, src_cr -7, 1); ++ if(chroma444){ ++ if(deblock_topleft){ ++ XCHG(top_border_m1 + (24 << pixel_shift), src_cb - (7 << pixel_shift), 1); ++ XCHG(top_border_m1 + (40 << pixel_shift), src_cr - (7 << pixel_shift), 1); ++ } ++ XCHG(top_border + (16 << pixel_shift), src_cb + (1 << pixel_shift), xchg); ++ XCHG(top_border + (24 << pixel_shift), src_cb + (9 << pixel_shift), 1); ++ XCHG(top_border + (32 << pixel_shift), src_cr + (1 << pixel_shift), xchg); ++ XCHG(top_border + (40 << pixel_shift), src_cr + (9 << pixel_shift), 1); ++ if(s->mb_x+1 < s->mb_width){ ++ XCHG(h->top_borders[top_idx][s->mb_x+1] + (16 << pixel_shift), src_cb + (17 << pixel_shift), 1); ++ XCHG(h->top_borders[top_idx][s->mb_x+1] + (32 << pixel_shift), src_cr + (17 << pixel_shift), 1); ++ } ++ } else { ++ if(deblock_top){ ++ if(deblock_topleft){ ++ XCHG(top_border_m1 + (16 << pixel_shift), src_cb - (7 << pixel_shift), 1); ++ XCHG(top_border_m1 + (24 << pixel_shift), src_cr - (7 << pixel_shift), 1); ++ } ++ XCHG(top_border + (16 << pixel_shift), src_cb+1+pixel_shift, 1); ++ XCHG(top_border + (24 << pixel_shift), src_cr+1+pixel_shift, 1); + } +- XCHG(top_border+16, src_cb+1, 1); +- XCHG(top_border+24, src_cr+1, 1); + } + } + } + +-static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple){ ++static av_always_inline int dctcoef_get(DCTELEM *mb, int high_bit_depth, int index) { ++ if (high_bit_depth) { ++ return AV_RN32A(((int32_t*)mb) + index); ++ } else ++ return AV_RN16A(mb + index); ++} ++ ++static av_always_inline void dctcoef_set(DCTELEM *mb, int high_bit_depth, int index, int value) { ++ if (high_bit_depth) { ++ AV_WN32A(((int32_t*)mb) + index, value); ++ } else ++ AV_WN16A(mb + index, value); ++} ++ ++static av_always_inline void hl_decode_mb_predict_luma(H264Context *h, int mb_type, int is_h264, int simple, int transform_bypass, ++ int pixel_shift, int *block_offset, int linesize, uint8_t *dest_y, int p) ++{ ++ MpegEncContext * const s = &h->s; ++ void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); ++ void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride); ++ int i; ++ int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; ++ block_offset += 16*p; ++ if(IS_INTRA4x4(mb_type)){ ++ if(simple || !s->encoding){ ++ if(IS_8x8DCT(mb_type)){ ++ if(transform_bypass){ ++ idct_dc_add = ++ idct_add = s->dsp.add_pixels8; ++ }else{ ++ idct_dc_add = h->h264dsp.h264_idct8_dc_add; ++ idct_add = h->h264dsp.h264_idct8_add; ++ } ++ for(i=0; i<16; i+=4){ ++ uint8_t * const ptr= dest_y + block_offset[i]; ++ const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; ++ if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ ++ h->hpc.pred8x8l_add[dir](ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ }else{ ++ const int nnz = h->non_zero_count_cache[ scan8[i+p*16] ]; ++ h->hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<topright_samples_available<mb, pixel_shift, i*16+p*256)) ++ idct_dc_add(ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ else ++ idct_add (ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ } ++ } ++ } ++ }else{ ++ if(transform_bypass){ ++ idct_dc_add = ++ idct_add = s->dsp.add_pixels4; ++ }else{ ++ idct_dc_add = h->h264dsp.h264_idct_dc_add; ++ idct_add = h->h264dsp.h264_idct_add; ++ } ++ for(i=0; i<16; i++){ ++ uint8_t * const ptr= dest_y + block_offset[i]; ++ const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; ++ ++ if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ ++ h->hpc.pred4x4_add[dir](ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ }else{ ++ uint8_t *topright; ++ int nnz, tr; ++ uint64_t tr_high; ++ if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){ ++ const int topright_avail= (h->topright_samples_available<mb_y || linesize <= block_offset[i]); ++ if(!topright_avail){ ++ if (pixel_shift) { ++ tr_high= ((uint16_t*)ptr)[3 - linesize/2]*0x0001000100010001ULL; ++ topright= (uint8_t*) &tr_high; ++ } else { ++ tr= ptr[3 - linesize]*0x01010101u; ++ topright= (uint8_t*) &tr; ++ } ++ }else ++ topright= ptr + (4 << pixel_shift) - linesize; ++ }else ++ topright= NULL; ++ ++ h->hpc.pred4x4[ dir ](ptr, topright, linesize); ++ nnz = h->non_zero_count_cache[ scan8[i+p*16] ]; ++ if(nnz){ ++ if(is_h264){ ++ if(nnz == 1 && dctcoef_get(h->mb, pixel_shift, i*16+p*256)) ++ idct_dc_add(ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ else ++ idct_add (ptr, h->mb + (i*16+p*256 << pixel_shift), linesize); ++ } else if (CONFIG_SVQ3_DECODER) ++ ff_svq3_add_idct_c(ptr, h->mb + i*16+p*256, linesize, qscale, 0); ++ } ++ } ++ } ++ } ++ } ++ }else{ ++ h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); ++ if(is_h264){ ++ if(h->non_zero_count_cache[ scan8[LUMA_DC_BLOCK_INDEX+p] ]){ ++ if(!transform_bypass) ++ h->h264dsp.h264_luma_dc_dequant_idct(h->mb+(p*256 << pixel_shift), h->mb_luma_dc[p], h->dequant4_coeff[p][qscale][0]); ++ else{ ++ static const uint8_t dc_mapping[16] = { 0*16, 1*16, 4*16, 5*16, 2*16, 3*16, 6*16, 7*16, ++ 8*16, 9*16,12*16,13*16,10*16,11*16,14*16,15*16}; ++ for(i = 0; i < 16; i++) ++ dctcoef_set(h->mb+(p*256 << pixel_shift), pixel_shift, dc_mapping[i], dctcoef_get(h->mb_luma_dc[p], pixel_shift, i)); ++ } ++ } ++ } else if (CONFIG_SVQ3_DECODER) ++ ff_svq3_luma_dc_dequant_idct_c(h->mb+p*256, h->mb_luma_dc[p], qscale); ++ } ++} ++ ++static av_always_inline void hl_decode_mb_idct_luma(H264Context *h, int mb_type, int is_h264, int simple, int transform_bypass, ++ int pixel_shift, int *block_offset, int linesize, uint8_t *dest_y, int p) ++{ ++ MpegEncContext * const s = &h->s; ++ void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); ++ int i; ++ block_offset += 16*p; ++ if(!IS_INTRA4x4(mb_type)){ ++ if(is_h264){ ++ if(IS_INTRA16x16(mb_type)){ ++ if(transform_bypass){ ++ if(h->sps.profile_idc==244 && (h->intra16x16_pred_mode==VERT_PRED8x8 || h->intra16x16_pred_mode==HOR_PRED8x8)){ ++ h->hpc.pred16x16_add[h->intra16x16_pred_mode](dest_y, block_offset, h->mb + (p*256 << pixel_shift), linesize); ++ }else{ ++ for(i=0; i<16; i++){ ++ if(h->non_zero_count_cache[ scan8[i+p*16] ] || dctcoef_get(h->mb, pixel_shift, i*16+p*256)) ++ s->dsp.add_pixels4(dest_y + block_offset[i], h->mb + (i*16+p*256 << pixel_shift), linesize); ++ } ++ } ++ }else{ ++ h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb + (p*256 << pixel_shift), linesize, h->non_zero_count_cache+p*5*8); ++ } ++ }else if(h->cbp&15){ ++ if(transform_bypass){ ++ const int di = IS_8x8DCT(mb_type) ? 4 : 1; ++ idct_add= IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4; ++ for(i=0; i<16; i+=di){ ++ if(h->non_zero_count_cache[ scan8[i+p*16] ]){ ++ idct_add(dest_y + block_offset[i], h->mb + (i*16+p*256 << pixel_shift), linesize); ++ } ++ } ++ }else{ ++ if(IS_8x8DCT(mb_type)){ ++ h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb + (p*256 << pixel_shift), linesize, h->non_zero_count_cache+p*5*8); ++ }else{ ++ h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb + (p*256 << pixel_shift), linesize, h->non_zero_count_cache+p*5*8); ++ } ++ } ++ } ++ } else if (CONFIG_SVQ3_DECODER) { ++ for(i=0; i<16; i++){ ++ if(h->non_zero_count_cache[ scan8[i+p*16] ] || h->mb[i*16+p*256]){ //FIXME benchmark weird rule, & below ++ uint8_t * const ptr= dest_y + block_offset[i]; ++ ff_svq3_add_idct_c(ptr, h->mb + i*16 + p*256, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); ++ } ++ } ++ } ++ } ++} ++ ++static av_always_inline void hl_decode_mb_internal(H264Context *h, int simple, int pixel_shift) ++{ + MpegEncContext * const s = &h->s; + const int mb_x= s->mb_x; + const int mb_y= s->mb_y; + const int mb_xy= h->mb_xy; +- const int mb_type= s->current_picture.mb_type[mb_xy]; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + uint8_t *dest_y, *dest_cb, *dest_cr; + int linesize, uvlinesize /*dct_offset*/; +- int i; ++ int i, j; + int *block_offset = &h->block_offset[0]; + const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass); + /* is_h264 should always be true if SVQ3 is disabled. */ + const int is_h264 = !CONFIG_SVQ3_DECODER || simple || s->codec_id == CODEC_ID_H264; + void (*idct_add)(uint8_t *dst, DCTELEM *block, int stride); +- void (*idct_dc_add)(uint8_t *dst, DCTELEM *block, int stride); ++ const int block_h = 16 >> s->chroma_y_shift; ++ const int chroma422 = CHROMA422; + +- dest_y = s->current_picture.data[0] + (mb_x + mb_y * s->linesize ) * 16; +- dest_cb = s->current_picture.data[1] + (mb_x + mb_y * s->uvlinesize) * 8; +- dest_cr = s->current_picture.data[2] + (mb_x + mb_y * s->uvlinesize) * 8; ++ dest_y = s->current_picture.f.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16; ++ dest_cb = s->current_picture.f.data[1] + (mb_x << pixel_shift)*8 + mb_y * s->uvlinesize * block_h; ++ dest_cr = s->current_picture.f.data[2] + (mb_x << pixel_shift)*8 + mb_y * s->uvlinesize * block_h; + +- s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + 64, s->linesize, 4); +- s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + 64, dest_cr - dest_cb, 2); ++ s->dsp.prefetch(dest_y + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4); ++ s->dsp.prefetch(dest_cb + (s->mb_x&7)*s->uvlinesize + (64 << pixel_shift), dest_cr - dest_cb, 2); + + h->list_counts[mb_xy]= h->list_count; + + if (!simple && MB_FIELD) { + linesize = h->mb_linesize = s->linesize * 2; + uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; +- block_offset = &h->block_offset[24]; ++ block_offset = &h->block_offset[48]; + if(mb_y&1){ //FIXME move out of this function? + dest_y -= s->linesize*15; +- dest_cb-= s->uvlinesize*7; +- dest_cr-= s->uvlinesize*7; ++ dest_cb-= s->uvlinesize * (block_h - 1); ++ dest_cr-= s->uvlinesize * (block_h - 1); + } + if(FRAME_MBAFF) { + int list; +@@ -1119,190 +1937,138 @@ + } + + if (!simple && IS_INTRA_PCM(mb_type)) { +- for (i=0; i<16; i++) { +- memcpy(dest_y + i* linesize, h->mb + i*8, 16); +- } +- for (i=0; i<8; i++) { +- memcpy(dest_cb+ i*uvlinesize, h->mb + 128 + i*4, 8); +- memcpy(dest_cr+ i*uvlinesize, h->mb + 160 + i*4, 8); ++ const int bit_depth = h->sps.bit_depth_luma; ++ if (pixel_shift) { ++ int j; ++ GetBitContext gb; ++ init_get_bits(&gb, (uint8_t*)h->mb, 384*bit_depth); ++ ++ for (i = 0; i < 16; i++) { ++ uint16_t *tmp_y = (uint16_t*)(dest_y + i*linesize); ++ for (j = 0; j < 16; j++) ++ tmp_y[j] = get_bits(&gb, bit_depth); ++ } ++ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ ++ if (!h->sps.chroma_format_idc) { ++ for (i = 0; i < block_h; i++) { ++ uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize); ++ uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize); ++ for (j = 0; j < 8; j++) { ++ tmp_cb[j] = tmp_cr[j] = 1 << (bit_depth - 1); ++ } ++ } ++ } else { ++ for (i = 0; i < block_h; i++) { ++ uint16_t *tmp_cb = (uint16_t*)(dest_cb + i*uvlinesize); ++ for (j = 0; j < 8; j++) ++ tmp_cb[j] = get_bits(&gb, bit_depth); ++ } ++ for (i = 0; i < block_h; i++) { ++ uint16_t *tmp_cr = (uint16_t*)(dest_cr + i*uvlinesize); ++ for (j = 0; j < 8; j++) ++ tmp_cr[j] = get_bits(&gb, bit_depth); ++ } ++ } ++ } ++ } else { ++ for (i=0; i<16; i++) { ++ memcpy(dest_y + i* linesize, h->mb + i*8, 16); ++ } ++ if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ ++ if (!h->sps.chroma_format_idc) { ++ for (i=0; i<8; i++) { ++ memset(dest_cb + i*uvlinesize, 1 << (bit_depth - 1), 8); ++ memset(dest_cr + i*uvlinesize, 1 << (bit_depth - 1), 8); ++ } ++ } else { ++ for (i=0; imb + 128 + i*4, 8); ++ memcpy(dest_cr + i*uvlinesize, h->mb + 160 + i*4, 8); ++ } ++ } ++ } + } + } else { + if(IS_INTRA(mb_type)){ + if(h->deblocking_filter) +- xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, simple); ++ xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 1, 0, simple, pixel_shift); + + if(simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ + h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cb, uvlinesize); + h->hpc.pred8x8[ h->chroma_pred_mode ](dest_cr, uvlinesize); + } + +- if(IS_INTRA4x4(mb_type)){ +- if(simple || !s->encoding){ +- if(IS_8x8DCT(mb_type)){ +- if(transform_bypass){ +- idct_dc_add = +- idct_add = s->dsp.add_pixels8; +- }else{ +- idct_dc_add = h->h264dsp.h264_idct8_dc_add; +- idct_add = h->h264dsp.h264_idct8_add; +- } +- for(i=0; i<16; i+=4){ +- uint8_t * const ptr= dest_y + block_offset[i]; +- const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; +- if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ +- h->hpc.pred8x8l_add[dir](ptr, h->mb + i*16, linesize); +- }else{ +- const int nnz = h->non_zero_count_cache[ scan8[i] ]; +- h->hpc.pred8x8l[ dir ](ptr, (h->topleft_samples_available<topright_samples_available<mb[i*16]) +- idct_dc_add(ptr, h->mb + i*16, linesize); +- else +- idct_add (ptr, h->mb + i*16, linesize); +- } +- } +- } +- }else{ +- if(transform_bypass){ +- idct_dc_add = +- idct_add = s->dsp.add_pixels4; +- }else{ +- idct_dc_add = h->h264dsp.h264_idct_dc_add; +- idct_add = h->h264dsp.h264_idct_add; +- } +- for(i=0; i<16; i++){ +- uint8_t * const ptr= dest_y + block_offset[i]; +- const int dir= h->intra4x4_pred_mode_cache[ scan8[i] ]; ++ hl_decode_mb_predict_luma(h, mb_type, is_h264, simple, transform_bypass, pixel_shift, block_offset, linesize, dest_y, 0); + +- if(transform_bypass && h->sps.profile_idc==244 && dir<=1){ +- h->hpc.pred4x4_add[dir](ptr, h->mb + i*16, linesize); +- }else{ +- uint8_t *topright; +- int nnz, tr; +- if(dir == DIAG_DOWN_LEFT_PRED || dir == VERT_LEFT_PRED){ +- const int topright_avail= (h->topright_samples_available<hpc.pred4x4[ dir ](ptr, topright, linesize); +- nnz = h->non_zero_count_cache[ scan8[i] ]; +- if(nnz){ +- if(is_h264){ +- if(nnz == 1 && h->mb[i*16]) +- idct_dc_add(ptr, h->mb + i*16, linesize); +- else +- idct_add (ptr, h->mb + i*16, linesize); +- }else +- ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, 0); +- } +- } +- } +- } +- } +- }else{ +- h->hpc.pred16x16[ h->intra16x16_pred_mode ](dest_y , linesize); +- if(is_h264){ +- if(h->non_zero_count_cache[ scan8[LUMA_DC_BLOCK_INDEX] ]){ +- if(!transform_bypass) +- h->h264dsp.h264_luma_dc_dequant_idct(h->mb, h->mb_luma_dc, h->dequant4_coeff[0][s->qscale][0]); +- else{ +- static const uint8_t dc_mapping[16] = { 0*16, 1*16, 4*16, 5*16, 2*16, 3*16, 6*16, 7*16, +- 8*16, 9*16,12*16,13*16,10*16,11*16,14*16,15*16}; +- for(i = 0; i < 16; i++) +- h->mb[dc_mapping[i]] = h->mb_luma_dc[i]; +- } +- } +- }else +- ff_svq3_luma_dc_dequant_idct_c(h->mb, h->mb_luma_dc, s->qscale); +- } + if(h->deblocking_filter) +- xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, simple); ++ xchg_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0, 0, simple, pixel_shift); + }else if(is_h264){ +- hl_motion(h, dest_y, dest_cb, dest_cr, +- s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, +- s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, +- h->h264dsp.weight_h264_pixels_tab, h->h264dsp.biweight_h264_pixels_tab); +- } +- +- +- if(!IS_INTRA4x4(mb_type)){ +- if(is_h264){ +- if(IS_INTRA16x16(mb_type)){ +- if(transform_bypass){ +- if(h->sps.profile_idc==244 && (h->intra16x16_pred_mode==VERT_PRED8x8 || h->intra16x16_pred_mode==HOR_PRED8x8)){ +- h->hpc.pred16x16_add[h->intra16x16_pred_mode](dest_y, block_offset, h->mb, linesize); +- }else{ +- for(i=0; i<16; i++){ +- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]) +- s->dsp.add_pixels4(dest_y + block_offset[i], h->mb + i*16, linesize); +- } +- } +- }else{ +- h->h264dsp.h264_idct_add16intra(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); +- } +- }else if(h->cbp&15){ +- if(transform_bypass){ +- const int di = IS_8x8DCT(mb_type) ? 4 : 1; +- idct_add= IS_8x8DCT(mb_type) ? s->dsp.add_pixels8 : s->dsp.add_pixels4; +- for(i=0; i<16; i+=di){ +- if(h->non_zero_count_cache[ scan8[i] ]){ +- idct_add(dest_y + block_offset[i], h->mb + i*16, linesize); +- } +- } +- }else{ +- if(IS_8x8DCT(mb_type)){ +- h->h264dsp.h264_idct8_add4(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); +- }else{ +- h->h264dsp.h264_idct_add16(dest_y, block_offset, h->mb, linesize, h->non_zero_count_cache); +- } +- } +- } +- }else{ +- for(i=0; i<16; i++){ +- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ //FIXME benchmark weird rule, & below +- uint8_t * const ptr= dest_y + block_offset[i]; +- ff_svq3_add_idct_c(ptr, h->mb + i*16, linesize, s->qscale, IS_INTRA(mb_type) ? 1 : 0); +- } +- } ++ if (chroma422) { ++ hl_motion_422(h, dest_y, dest_cb, dest_cr, ++ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, ++ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, ++ h->h264dsp.weight_h264_pixels_tab, ++ h->h264dsp.biweight_h264_pixels_tab, ++ pixel_shift); ++ } else { ++ hl_motion_420(h, dest_y, dest_cb, dest_cr, ++ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, ++ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, ++ h->h264dsp.weight_h264_pixels_tab, ++ h->h264dsp.biweight_h264_pixels_tab, ++ pixel_shift); + } + } + ++ hl_decode_mb_idct_luma(h, mb_type, is_h264, simple, transform_bypass, pixel_shift, block_offset, linesize, dest_y, 0); ++ + if((simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) && (h->cbp&0x30)){ + uint8_t *dest[2] = {dest_cb, dest_cr}; + if(transform_bypass){ + if(IS_INTRA(mb_type) && h->sps.profile_idc==244 && (h->chroma_pred_mode==VERT_PRED8x8 || h->chroma_pred_mode==HOR_PRED8x8)){ +- h->hpc.pred8x8_add[h->chroma_pred_mode](dest[0], block_offset + 16, h->mb + 16*16, uvlinesize); +- h->hpc.pred8x8_add[h->chroma_pred_mode](dest[1], block_offset + 20, h->mb + 20*16, uvlinesize); ++ h->hpc.pred8x8_add[h->chroma_pred_mode](dest[0], block_offset + 16, h->mb + (16*16*1 << pixel_shift), uvlinesize); ++ h->hpc.pred8x8_add[h->chroma_pred_mode](dest[1], block_offset + 32, h->mb + (16*16*2 << pixel_shift), uvlinesize); + }else{ + idct_add = s->dsp.add_pixels4; +- for(i=16; i<16+8; i++){ +- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]) +- idct_add (dest[(i&4)>>2] + block_offset[i], h->mb + i*16, uvlinesize); ++ for(j=1; j<3; j++){ ++ for(i=j*16; inon_zero_count_cache[ scan8[i] ] || dctcoef_get(h->mb, pixel_shift, i*16)) ++ idct_add (dest[j-1] + block_offset[i], h->mb + (i*16 << pixel_shift), uvlinesize); ++ } ++ if (chroma422) { ++ for(i=j*16+4; inon_zero_count_cache[ scan8[i+4] ] || dctcoef_get(h->mb, pixel_shift, i*16)) ++ idct_add (dest[j-1] + block_offset[i+4], h->mb + (i*16 << pixel_shift), uvlinesize); ++ } ++ } + } + } + }else{ + if(is_h264){ ++ int qp[2]; ++ if (chroma422) { ++ qp[0] = h->chroma_qp[0] + 3; ++ qp[1] = h->chroma_qp[1] + 3; ++ } else { ++ qp[0] = h->chroma_qp[0]; ++ qp[1] = h->chroma_qp[1]; ++ } + if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+0] ]) +- chroma_dc_dequant_idct_c(h->mb + 16*16 , h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); ++ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*1 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][qp[0]][0]); + if(h->non_zero_count_cache[ scan8[CHROMA_DC_BLOCK_INDEX+1] ]) +- chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); ++ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + (16*16*2 << pixel_shift), h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][qp[1]][0]); + h->h264dsp.h264_idct_add8(dest, block_offset, + h->mb, uvlinesize, + h->non_zero_count_cache); +- }else{ +- chroma_dc_dequant_idct_c(h->mb + 16*16 , h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); +- chroma_dc_dequant_idct_c(h->mb + 16*16+4*16, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); +- for(i=16; i<16+8; i++){ +- if(h->non_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ +- uint8_t * const ptr= dest[(i&4)>>2] + block_offset[i]; +- ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[s->qscale + 12] - 12, 2); ++ } else if (CONFIG_SVQ3_DECODER) { ++ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*1, h->dequant4_coeff[IS_INTRA(mb_type) ? 1:4][h->chroma_qp[0]][0]); ++ h->h264dsp.h264_chroma_dc_dequant_idct(h->mb + 16*16*2, h->dequant4_coeff[IS_INTRA(mb_type) ? 2:5][h->chroma_qp[1]][0]); ++ for(j=1; j<3; j++){ ++ for(i=j*16; inon_zero_count_cache[ scan8[i] ] || h->mb[i*16]){ ++ uint8_t * const ptr= dest[j-1] + block_offset[i]; ++ ff_svq3_add_idct_c(ptr, h->mb + i*16, uvlinesize, ff_h264_chroma_qp[0][s->qscale + 12] - 12, 2); ++ } + } + } + } +@@ -1310,32 +2076,150 @@ + } + } + if(h->cbp || IS_INTRA(mb_type)) ++ { ++ s->dsp.clear_blocks(h->mb); ++ s->dsp.clear_blocks(h->mb+(24*16<s; ++ const int mb_x= s->mb_x; ++ const int mb_y= s->mb_y; ++ const int mb_xy= h->mb_xy; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; ++ uint8_t *dest[3]; ++ int linesize; ++ int i, j, p; ++ int *block_offset = &h->block_offset[0]; ++ const int transform_bypass = !simple && (s->qscale == 0 && h->sps.transform_bypass); ++ const int plane_count = (simple || !CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) ? 3 : 1; ++ ++ for (p = 0; p < plane_count; p++) ++ { ++ dest[p] = s->current_picture.f.data[p] + ((mb_x << pixel_shift) + mb_y * s->linesize) * 16; ++ s->dsp.prefetch(dest[p] + (s->mb_x&3)*4*s->linesize + (64 << pixel_shift), s->linesize, 4); ++ } ++ ++ h->list_counts[mb_xy]= h->list_count; ++ ++ if (!simple && MB_FIELD) { ++ linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize * 2; ++ block_offset = &h->block_offset[48]; ++ if(mb_y&1) //FIXME move out of this function? ++ for (p = 0; p < 3; p++) ++ dest[p] -= s->linesize*15; ++ if(FRAME_MBAFF) { ++ int list; ++ for(list=0; listlist_count; list++){ ++ if(!USES_LIST(mb_type, list)) ++ continue; ++ if(IS_16X16(mb_type)){ ++ int8_t *ref = &h->ref_cache[list][scan8[0]]; ++ fill_rectangle(ref, 4, 4, 8, (16+*ref)^(s->mb_y&1), 1); ++ }else{ ++ for(i=0; i<16; i+=4){ ++ int ref = h->ref_cache[list][scan8[i]]; ++ if(ref >= 0) ++ fill_rectangle(&h->ref_cache[list][scan8[i]], 2, 2, 8, (16+ref)^(s->mb_y&1), 1); ++ } ++ } ++ } ++ } ++ } else { ++ linesize = h->mb_linesize = h->mb_uvlinesize = s->linesize; ++ } ++ ++ if (!simple && IS_INTRA_PCM(mb_type)) { ++ if (pixel_shift) { ++ const int bit_depth = h->sps.bit_depth_luma; ++ GetBitContext gb; ++ init_get_bits(&gb, (uint8_t*)h->mb, 768*bit_depth); ++ ++ for (p = 0; p < plane_count; p++) { ++ for (i = 0; i < 16; i++) { ++ uint16_t *tmp = (uint16_t*)(dest[p] + i*linesize); ++ for (j = 0; j < 16; j++) ++ tmp[j] = get_bits(&gb, bit_depth); ++ } ++ } ++ } else { ++ for (p = 0; p < plane_count; p++) { ++ for (i = 0; i < 16; i++) { ++ memcpy(dest[p] + i*linesize, h->mb + p*128 + i*8, 16); ++ } ++ } ++ } ++ } else { ++ if(IS_INTRA(mb_type)){ ++ if(h->deblocking_filter) ++ xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 1, 1, simple, pixel_shift); ++ ++ for (p = 0; p < plane_count; p++) ++ hl_decode_mb_predict_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p); ++ ++ if(h->deblocking_filter) ++ xchg_mb_border(h, dest[0], dest[1], dest[2], linesize, linesize, 0, 1, simple, pixel_shift); ++ }else{ ++ hl_motion(h, dest[0], dest[1], dest[2], ++ s->me.qpel_put, s->dsp.put_h264_chroma_pixels_tab, ++ s->me.qpel_avg, s->dsp.avg_h264_chroma_pixels_tab, ++ h->h264dsp.weight_h264_pixels_tab, ++ h->h264dsp.biweight_h264_pixels_tab, pixel_shift, 3); ++ } ++ ++ for (p = 0; p < plane_count; p++) ++ hl_decode_mb_idct_luma(h, mb_type, 1, simple, transform_bypass, pixel_shift, block_offset, linesize, dest[p], p); ++ } ++ if(h->cbp || IS_INTRA(mb_type)) ++ { + s->dsp.clear_blocks(h->mb); ++ s->dsp.clear_blocks(h->mb+(24*16<pixel_shift); ++} ++ ++static void av_noinline hl_decode_mb_444_complex(H264Context *h){ ++ hl_decode_mb_444_internal(h, 0, h->pixel_shift); ++} ++ ++static void av_noinline hl_decode_mb_444_simple(H264Context *h){ ++ hl_decode_mb_444_internal(h, 1, 0); + } + + void ff_h264_hl_decode_mb(H264Context *h){ + MpegEncContext * const s = &h->s; + const int mb_xy= h->mb_xy; +- const int mb_type= s->current_picture.mb_type[mb_xy]; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + int is_complex = CONFIG_SMALL || h->is_complex || IS_INTRA_PCM(mb_type) || s->qscale == 0; + +- if (is_complex) ++ if (CHROMA444) { ++ if(is_complex || h->pixel_shift) ++ hl_decode_mb_444_complex(h); ++ else ++ hl_decode_mb_444_simple(h); ++ } else if (is_complex) { + hl_decode_mb_complex(h); +- else hl_decode_mb_simple(h); ++ } else if (h->pixel_shift) { ++ hl_decode_mb_simple_16(h); ++ } else ++ hl_decode_mb_simple_8(h); + } + + static int pred_weight_table(H264Context *h){ +@@ -1346,7 +2230,7 @@ + h->use_weight= 0; + h->use_weight_chroma= 0; + h->luma_log2_weight_denom= get_ue_golomb(&s->gb); +- if(CHROMA) ++ if(h->sps.chroma_format_idc) + h->chroma_log2_weight_denom= get_ue_golomb(&s->gb); + luma_def = 1<luma_log2_weight_denom; + chroma_def = 1<chroma_log2_weight_denom; +@@ -1371,7 +2255,7 @@ + h->luma_weight[i][list][1]= 0; + } + +- if(CHROMA){ ++ if(h->sps.chroma_format_idc){ + chroma_weight_flag= get_bits1(&s->gb); + if(chroma_weight_flag){ + int j; +@@ -1393,7 +2277,7 @@ + } + } + } +- if(h->slice_type_nos != FF_B_TYPE) break; ++ if(h->slice_type_nos != AV_PICTURE_TYPE_B) break; + } + h->use_weight= h->use_weight || h->use_weight_chroma; + return 0; +@@ -1414,7 +2298,11 @@ + } + + if(field < 0){ +- cur_poc = s->current_picture_ptr->poc; ++ if (s->picture_structure == PICT_FRAME) { ++ cur_poc = s->current_picture_ptr->poc; ++ } else { ++ cur_poc = s->current_picture_ptr->field_poc[s->picture_structure - 1]; ++ } + if( h->ref_count[0] == 1 && h->ref_count[1] == 1 && !FRAME_MBAFF + && h->ref_list[0][0].poc + h->ref_list[1][0].poc == 2*cur_poc){ + h->use_weight= 0; +@@ -1439,15 +2327,17 @@ + for(ref0=ref_start; ref0 < ref_count0; ref0++){ + int poc0 = h->ref_list[0][ref0].poc; + for(ref1=ref_start; ref1 < ref_count1; ref1++){ +- int poc1 = h->ref_list[1][ref1].poc; +- int td = av_clip(poc1 - poc0, -128, 127); +- int w= 32; +- if(td){ +- int tb = av_clip(cur_poc - poc0, -128, 127); +- int tx = (16384 + (FFABS(td) >> 1)) / td; +- int dist_scale_factor = (tb*tx + 32) >> 8; +- if(dist_scale_factor >= -64 && dist_scale_factor <= 128) +- w = 64 - dist_scale_factor; ++ int w = 32; ++ if (!h->ref_list[0][ref0].long_ref && !h->ref_list[1][ref1].long_ref) { ++ int poc1 = h->ref_list[1][ref1].poc; ++ int td = av_clip(poc1 - poc0, -128, 127); ++ if(td){ ++ int tb = av_clip(cur_poc - poc0, -128, 127); ++ int tx = (16384 + (FFABS(td) >> 1)) / td; ++ int dist_scale_factor = (tb*tx + 32) >> 8; ++ if(dist_scale_factor >= -64 && dist_scale_factor <= 128) ++ w = 64 - dist_scale_factor; ++ } + } + if(field<0){ + h->implicit_weight[ref0][ref1][0]= +@@ -1463,31 +2353,37 @@ + * instantaneous decoder refresh. + */ + static void idr(H264Context *h){ ++ int i; + ff_h264_remove_all_refs(h); +- h->prev_frame_num= -1; ++ h->prev_frame_num= 0; + h->prev_frame_num_offset= 0; +- h->prev_poc_msb= ++ h->prev_poc_msb= 1<<16; + h->prev_poc_lsb= 0; ++ for (i = 0; i < MAX_DELAYED_PIC_COUNT; i++) ++ h->last_pocs[i] = INT_MIN; + } + + /* forget old pics after a seek */ + static void flush_dpb(AVCodecContext *avctx){ + H264Context *h= avctx->priv_data; + int i; +- for(i=0; idelayed_pic[i]) +- h->delayed_pic[i]->reference= 0; ++ h->delayed_pic[i]->f.reference = 0; + h->delayed_pic[i]= NULL; + } +- h->got_first_iframe = 0; +- h->outputed_poc= INT_MIN; ++ h->got_first_iframe = 0; ++ h->outputed_poc=h->next_outputed_poc= INT_MIN; + h->prev_interlaced_frame = 1; + idr(h); ++ h->prev_frame_num= -1; + if(h->s.current_picture_ptr) +- h->s.current_picture_ptr->reference= 0; ++ h->s.current_picture_ptr->f.reference = 0; + h->s.first_field= 0; + ff_h264_reset_sei(h); + ff_mpeg_flush(avctx); ++ h->recovery_frame= -1; ++ h->sync= 0; + } + + static int init_poc(H264Context *h){ +@@ -1604,24 +2500,29 @@ + } + } + +-static void field_end(H264Context *h){ ++static int field_end(H264Context *h, int in_setup){ + MpegEncContext * const s = &h->s; + AVCodecContext * const avctx= s->avctx; ++ int err = 0; + s->mb_y= 0; + +- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_H264; +- s->current_picture_ptr->pict_type= s->pict_type; ++ if (!in_setup && !s->dropable) ++ ff_thread_report_progress((AVFrame*)s->current_picture_ptr, (16*s->mb_height >> FIELD_PICTURE) - 1, ++ s->picture_structure==PICT_BOTTOM_FIELD); + + if (CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_set_reference_frames(s); + +- if(!s->dropable) { +- ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); +- h->prev_poc_msb= h->poc_msb; +- h->prev_poc_lsb= h->poc_lsb; ++ if(in_setup || !(avctx->active_thread_type&FF_THREAD_FRAME)){ ++ if(!s->dropable) { ++ err = ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); ++ h->prev_poc_msb= h->poc_msb; ++ h->prev_poc_lsb= h->poc_lsb; ++ } ++ h->prev_frame_num_offset= h->frame_num_offset; ++ h->prev_frame_num= h->frame_num; ++ h->outputed_poc = h->next_outputed_poc; + } +- h->prev_frame_num_offset= h->frame_num_offset; +- h->prev_frame_num= h->frame_num; + + if (avctx->hwaccel) { + if (avctx->hwaccel->end_frame(avctx) < 0) +@@ -1649,6 +2550,8 @@ + MPV_frame_end(s); + + h->current_slice=0; ++ ++ return err; + } + + /** +@@ -1679,7 +2582,7 @@ + } + + /** +- * computes profile from profile_idc and constraint_set?_flags ++ * Compute profile from profile_idc and constraint_set?_flags. + * + * @param sps SPS + * +@@ -1706,7 +2609,7 @@ + } + + /** +- * decodes a slice header. ++ * Decode a slice header. + * This will also call MPV_common_init() and frame_start() as needed. + * + * @param h h264context +@@ -1726,7 +2629,8 @@ + + s->dropable= h->nal_ref_idc == 0; + +- if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc){ ++ /* FIXME: 2tap qpel isn't implemented for high bit depth. */ ++ if((s->avctx->flags2 & CODEC_FLAG2_FAST) && !h->nal_ref_idc && !h->pixel_shift){ + s->me.qpel_put= s->dsp.put_2tap_qpel_pixels_tab; + s->me.qpel_avg= s->dsp.avg_2tap_qpel_pixels_tab; + }else{ +@@ -1734,11 +2638,11 @@ + s->me.qpel_avg= s->dsp.avg_h264_qpel_pixels_tab; + } + +- first_mb_in_slice= get_ue_golomb(&s->gb); ++ first_mb_in_slice= get_ue_golomb_long(&s->gb); + + if(first_mb_in_slice == 0){ //FIXME better field boundary detection + if(h0->current_slice && FIELD_PICTURE){ +- field_end(h); ++ field_end(h, 1); + } + + h0->current_slice = 0; +@@ -1758,7 +2662,7 @@ + h->slice_type_fixed=0; + + slice_type= golomb_to_pict_type[ slice_type ]; +- if (slice_type == FF_I_TYPE ++ if (slice_type == AV_PICTURE_TYPE_I + || (h0->current_slice != 0 && slice_type == h0->last_slice_type) ) { + default_ref_list_done = 1; + } +@@ -1788,44 +2692,62 @@ + s->avctx->level = h->sps.level_idc; + s->avctx->refs = h->sps.ref_frame_count; + +- if(h == h0 && h->dequant_coeff_pps != pps_id){ +- h->dequant_coeff_pps = pps_id; +- init_dequant_tables(h); +- } +- + s->mb_width= h->sps.mb_width; + s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); + + h->b_stride= s->mb_width*4; ++ ++ s->chroma_y_shift = h->sps.chroma_format_idc <= 1; // 400 uses yuv420p ++ + s->width = 16*s->mb_width; + s->height= 16*s->mb_height; + + if (s->context_initialized + && ( s->width != s->avctx->coded_width || s->height != s->avctx->coded_height ++ || s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma ++ || h->cur_chroma_format_idc != h->sps.chroma_format_idc + || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) { +- if(h != h0) ++ if(h != h0 || (s->avctx->active_thread_type & FF_THREAD_FRAME)) { ++ av_log_missing_feature(s->avctx, "Width/height/bit depth/chroma idc changing with threads is", 0); + return -1; // width / height changed during parallelized decoding ++ } + free_tables(h, 0); + flush_dpb(s->avctx); + MPV_common_end(s); ++ h->list_count = 0; + } + if (!s->context_initialized) { +- if(h != h0) +- return -1; // we cant (re-)initialize context during parallel decoding +- ++ if (h != h0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "Cannot (re-)initialize context during parallel decoding.\n"); ++ return -1; ++ } + avcodec_set_dimensions(s->avctx, s->width, s->height); +- +- s->avctx->width -= 2*FFMIN(h->sps.crop_right, 7); +- if(h->sps.frame_mbs_only_flag) +- s->avctx->height-=2*FFMIN(h->sps.crop_bottom, 7); +- else +- s->avctx->height-=4*FFMIN(h->sps.crop_bottom, 7); +- ++ s->avctx->width -= (2>>CHROMA444)*FFMIN(h->sps.crop_right, (8<avctx->height -= (1<chroma_y_shift)*FFMIN(h->sps.crop_bottom, (16>>s->chroma_y_shift)-1) * (2 - h->sps.frame_mbs_only_flag); + s->avctx->sample_aspect_ratio= h->sps.sar; + av_assert0(s->avctx->sample_aspect_ratio.den); + ++ if (s->avctx->bits_per_raw_sample != h->sps.bit_depth_luma || ++ h->cur_chroma_format_idc != h->sps.chroma_format_idc) { ++ if (h->sps.bit_depth_luma >= 8 && h->sps.bit_depth_luma <= 10 && ++ (h->sps.bit_depth_luma != 9 || !CHROMA422)) { ++ s->avctx->bits_per_raw_sample = h->sps.bit_depth_luma; ++ h->cur_chroma_format_idc = h->sps.chroma_format_idc; ++ h->pixel_shift = h->sps.bit_depth_luma > 8; ++ ++ ff_h264dsp_init(&h->h264dsp, h->sps.bit_depth_luma, h->sps.chroma_format_idc); ++ ff_h264_pred_init(&h->hpc, s->codec_id, h->sps.bit_depth_luma, h->sps.chroma_format_idc); ++ s->dsp.dct_bits = h->sps.bit_depth_luma > 8 ? 32 : 16; ++ dsputil_init(&s->dsp, s->avctx); ++ } else { ++ av_log(s->avctx, AV_LOG_ERROR, "Unsupported bit depth: %d chroma_idc: %d\n", ++ h->sps.bit_depth_luma, h->sps.chroma_format_idc); ++ return -1; ++ } ++ } ++ + if(h->sps.video_signal_type_present_flag){ +- s->avctx->color_range = h->sps.full_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; ++ s->avctx->color_range = h->sps.full_range>0 ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; + if(h->sps.colour_description_present_flag){ + s->avctx->color_primaries = h->sps.color_primaries; + s->avctx->color_trc = h->sps.color_trc; +@@ -1840,38 +2762,103 @@ + av_reduce(&s->avctx->time_base.num, &s->avctx->time_base.den, + h->sps.num_units_in_tick, den, 1<<30); + } +- s->avctx->pix_fmt = s->avctx->get_format(s->avctx, +- s->avctx->codec->pix_fmts ? +- s->avctx->codec->pix_fmts : +- s->avctx->color_range == AVCOL_RANGE_JPEG ? +- hwaccel_pixfmt_list_h264_jpeg_420 : +- ff_hwaccel_pixfmt_list_420); ++ ++ switch (h->sps.bit_depth_luma) { ++ case 9 : ++ if (CHROMA444) { ++ if (s->avctx->colorspace == AVCOL_SPC_RGB) { ++ s->avctx->pix_fmt = PIX_FMT_GBRP9; ++ } else ++ s->avctx->pix_fmt = PIX_FMT_YUV444P9; ++ } else if (CHROMA422) ++ s->avctx->pix_fmt = PIX_FMT_YUV422P9; ++ else ++ s->avctx->pix_fmt = PIX_FMT_YUV420P9; ++ break; ++ case 10 : ++ if (CHROMA444) { ++ if (s->avctx->colorspace == AVCOL_SPC_RGB) { ++ s->avctx->pix_fmt = PIX_FMT_GBRP10; ++ } else ++ s->avctx->pix_fmt = PIX_FMT_YUV444P10; ++ } else if (CHROMA422) ++ s->avctx->pix_fmt = PIX_FMT_YUV422P10; ++ else ++ s->avctx->pix_fmt = PIX_FMT_YUV420P10; ++ break; ++ case 8: ++ if (CHROMA444){ ++ s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ444P : PIX_FMT_YUV444P; ++ if (s->avctx->colorspace == AVCOL_SPC_RGB) { ++ s->avctx->pix_fmt = PIX_FMT_GBR24P; ++ av_log(h->s.avctx, AV_LOG_DEBUG, "Detected GBR colorspace.\n"); ++ } else if (s->avctx->colorspace == AVCOL_SPC_YCGCO) { ++ av_log(h->s.avctx, AV_LOG_WARNING, "Detected unsupported YCgCo colorspace.\n"); ++ } ++ } else if (CHROMA422) { ++ s->avctx->pix_fmt = s->avctx->color_range == AVCOL_RANGE_JPEG ? PIX_FMT_YUVJ422P : PIX_FMT_YUV422P; ++ }else{ ++ s->avctx->pix_fmt = s->avctx->get_format(s->avctx, ++ s->avctx->codec->pix_fmts ? ++ s->avctx->codec->pix_fmts : ++ s->avctx->color_range == AVCOL_RANGE_JPEG ? ++ hwaccel_pixfmt_list_h264_jpeg_420 : ++ ff_hwaccel_pixfmt_list_420); ++ } ++ break; ++ default: ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Unsupported bit depth: %d\n", h->sps.bit_depth_luma); ++ return AVERROR_INVALIDDATA; ++ } ++ + s->avctx->hwaccel = ff_find_hwaccel(s->avctx->codec->id, s->avctx->pix_fmt); + +- if (MPV_common_init(s) < 0) ++ if (MPV_common_init(s) < 0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "MPV_common_init() failed.\n"); + return -1; ++ } + s->first_field = 0; + h->prev_interlaced_frame = 1; + h->got_first_iframe = 0; + + init_scan_tables(h); +- ff_h264_alloc_tables(h); +- +- for(i = 1; i < s->avctx->thread_count; i++) { +- H264Context *c; +- c = h->thread_context[i] = av_malloc(sizeof(H264Context)); +- memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); +- memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); +- c->h264dsp = h->h264dsp; +- c->sps = h->sps; +- c->pps = h->pps; +- init_scan_tables(c); +- clone_tables(c, h, i); ++ if (ff_h264_alloc_tables(h) < 0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "Could not allocate memory for h264\n"); ++ return AVERROR(ENOMEM); + } + +- for(i = 0; i < s->avctx->thread_count; i++) +- if(context_init(h->thread_context[i]) < 0) ++ if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_SLICE)) { ++ if (context_init(h) < 0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); + return -1; ++ } ++ } else { ++ for(i = 1; i < s->slice_context_count; i++) { ++ H264Context *c; ++ c = h->thread_context[i] = av_malloc(sizeof(H264Context)); ++ memcpy(c, h->s.thread_context[i], sizeof(MpegEncContext)); ++ memset(&c->s + 1, 0, sizeof(H264Context) - sizeof(MpegEncContext)); ++ c->h264dsp = h->h264dsp; ++ c->sps = h->sps; ++ c->pps = h->pps; ++ c->pixel_shift = h->pixel_shift; ++ c->cur_chroma_format_idc = h->cur_chroma_format_idc; ++ init_scan_tables(c); ++ clone_tables(c, h, i); ++ } ++ ++ for(i = 0; i < s->slice_context_count; i++) ++ if (context_init(h->thread_context[i]) < 0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "context_init() failed.\n"); ++ return -1; ++ } ++ } ++ } ++ ++ if(h == h0 && h->dequant_coeff_pps != pps_id){ ++ h->dequant_coeff_pps = pps_id; ++ init_dequant_tables(h); + } + + h->frame_num= get_bits(&s->gb, h->sps.log2_max_frame_num); +@@ -1882,6 +2869,10 @@ + if(h->sps.frame_mbs_only_flag){ + s->picture_structure= PICT_FRAME; + }else{ ++ if(!h->sps.direct_8x8_inference_flag && slice_type == AV_PICTURE_TYPE_B){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); ++ return -1; ++ } + if(get_bits1(&s->gb)) { //field_pic_flag + s->picture_structure= PICT_TOP_FIELD + get_bits1(&s->gb); //bottom_field_flag + } else { +@@ -1892,6 +2883,21 @@ + h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME; + + if(h0->current_slice == 0){ ++ // Shorten frame num gaps so we don't have to allocate reference frames just to throw them away ++ if(h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0) { ++ int unwrap_prev_frame_num = h->prev_frame_num, max_frame_num = 1<sps.log2_max_frame_num; ++ ++ if (unwrap_prev_frame_num > h->frame_num) unwrap_prev_frame_num -= max_frame_num; ++ ++ if ((h->frame_num - unwrap_prev_frame_num) > h->sps.ref_frame_count) { ++ unwrap_prev_frame_num = (h->frame_num - h->sps.ref_frame_count) - 1; ++ if (unwrap_prev_frame_num < 0) ++ unwrap_prev_frame_num += max_frame_num; ++ ++ h->prev_frame_num = unwrap_prev_frame_num; ++ } ++ } ++ + while(h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0 && + h->frame_num != (h->prev_frame_num+1)%(1<sps.log2_max_frame_num)){ + Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; +@@ -1901,18 +2907,22 @@ + h->prev_frame_num++; + h->prev_frame_num %= 1<sps.log2_max_frame_num; + s->current_picture_ptr->frame_num= h->prev_frame_num; ++ ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 0); ++ ff_thread_report_progress((AVFrame*)s->current_picture_ptr, INT_MAX, 1); + ff_generate_sliding_window_mmcos(h); +- ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index); ++ if (ff_h264_execute_ref_pic_marking(h, h->mmco, h->mmco_index) < 0 && ++ (s->avctx->err_recognition & AV_EF_EXPLODE)) ++ return AVERROR_INVALIDDATA; + /* Error concealment: if a ref is missing, copy the previous ref in its place. + * FIXME: avoiding a memcpy would be nice, but ref handling makes many assumptions + * about there being no actual duplicates. + * FIXME: this doesn't copy padding for out-of-frame motion vectors. Given we're +- * concealing a lost frame, this probably isn't noticable by comparison, but it should ++ * concealing a lost frame, this probably isn't noticeable by comparison, but it should + * be fixed. */ + if (h->short_ref_count) { + if (prev) { +- av_image_copy(h->short_ref[0]->data, h->short_ref[0]->linesize, +- (const uint8_t**)prev->data, prev->linesize, ++ av_image_copy(h->short_ref[0]->f.data, h->short_ref[0]->f.linesize, ++ (const uint8_t**)prev->f.data, prev->f.linesize, + s->avctx->pix_fmt, s->mb_width*16, s->mb_height*16); + h->short_ref[0]->poc = prev->poc+2; + } +@@ -1923,8 +2933,8 @@ + /* See if we have a decoded first field looking for a pair... */ + if (s0->first_field) { + assert(s0->current_picture_ptr); +- assert(s0->current_picture_ptr->data[0]); +- assert(s0->current_picture_ptr->reference != DELAYED_PIC_REF); ++ assert(s0->current_picture_ptr->f.data[0]); ++ assert(s0->current_picture_ptr->f.reference != DELAYED_PIC_REF); + + /* figure out if we have a complementary field pair */ + if (!FIELD_PICTURE || s->picture_structure == last_pic_structure) { +@@ -1958,9 +2968,13 @@ + s0->first_field = FIELD_PICTURE; + } + +- if((!FIELD_PICTURE || s0->first_field) && ff_h264_frame_start(h) < 0) { +- s0->first_field = 0; +- return -1; ++ if(!FIELD_PICTURE || s0->first_field) { ++ if (ff_h264_frame_start(h) < 0) { ++ s0->first_field = 0; ++ return -1; ++ } ++ } else { ++ ff_release_unused_pictures(s, 0); + } + } + if(h != h0) +@@ -2017,50 +3031,55 @@ + h->ref_count[0]= h->pps.ref_count[0]; + h->ref_count[1]= h->pps.ref_count[1]; + +- if(h->slice_type_nos != FF_I_TYPE){ +- if(h->slice_type_nos == FF_B_TYPE){ ++ if(h->slice_type_nos != AV_PICTURE_TYPE_I){ ++ unsigned max= s->picture_structure == PICT_FRAME ? 15 : 31; ++ ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ + h->direct_spatial_mv_pred= get_bits1(&s->gb); + } + num_ref_idx_active_override_flag= get_bits1(&s->gb); + + if(num_ref_idx_active_override_flag){ + h->ref_count[0]= get_ue_golomb(&s->gb) + 1; +- if(h->slice_type_nos==FF_B_TYPE) ++ if(h->slice_type_nos==AV_PICTURE_TYPE_B) + h->ref_count[1]= get_ue_golomb(&s->gb) + 1; ++ } + +- if(h->ref_count[0]-1 > 32-1 || h->ref_count[1]-1 > 32-1){ +- av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); +- h->ref_count[0]= h->ref_count[1]= 1; +- return -1; +- } ++ if (h->ref_count[0]-1 > max || h->ref_count[1]-1 > max){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "reference overflow\n"); ++ h->ref_count[0] = h->ref_count[1] = 1; ++ return AVERROR_INVALIDDATA; + } +- if(h->slice_type_nos == FF_B_TYPE) ++ ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B) + h->list_count= 2; + else + h->list_count= 1; + }else +- h->list_count= 0; ++ h->ref_count[1]= h->ref_count[0]= h->list_count= 0; + + if(!default_ref_list_done){ + ff_h264_fill_default_ref_list(h); + } + +- if(h->slice_type_nos!=FF_I_TYPE && ff_h264_decode_ref_pic_list_reordering(h) < 0) ++ if(h->slice_type_nos!=AV_PICTURE_TYPE_I && ff_h264_decode_ref_pic_list_reordering(h) < 0) { ++ h->ref_count[1]= h->ref_count[0]= 0; + return -1; ++ } + +- if(h->slice_type_nos!=FF_I_TYPE){ ++ if(h->slice_type_nos!=AV_PICTURE_TYPE_I){ + s->last_picture_ptr= &h->ref_list[0][0]; + ff_copy_picture(&s->last_picture, s->last_picture_ptr); + } +- if(h->slice_type_nos==FF_B_TYPE){ ++ if(h->slice_type_nos==AV_PICTURE_TYPE_B){ + s->next_picture_ptr= &h->ref_list[1][0]; + ff_copy_picture(&s->next_picture, s->next_picture_ptr); + } + +- if( (h->pps.weighted_pred && h->slice_type_nos == FF_P_TYPE ) +- || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== FF_B_TYPE ) ) ++ if( (h->pps.weighted_pred && h->slice_type_nos == AV_PICTURE_TYPE_P ) ++ || (h->pps.weighted_bipred_idc==1 && h->slice_type_nos== AV_PICTURE_TYPE_B ) ) + pred_weight_table(h); +- else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){ ++ else if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){ + implicit_weight_table(h, -1); + }else { + h->use_weight = 0; +@@ -2070,23 +3089,24 @@ + } + } + +- if(h->nal_ref_idc) +- ff_h264_decode_ref_pic_marking(h0, &s->gb); ++ if(h->nal_ref_idc && ff_h264_decode_ref_pic_marking(h0, &s->gb) < 0 && ++ (s->avctx->err_recognition & AV_EF_EXPLODE)) ++ return AVERROR_INVALIDDATA; + + if(FRAME_MBAFF){ + ff_h264_fill_mbaff_ref_list(h); + +- if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== FF_B_TYPE){ ++ if(h->pps.weighted_bipred_idc==2 && h->slice_type_nos== AV_PICTURE_TYPE_B){ + implicit_weight_table(h, 0); + implicit_weight_table(h, 1); + } + } + +- if(h->slice_type_nos==FF_B_TYPE && !h->direct_spatial_mv_pred) ++ if(h->slice_type_nos==AV_PICTURE_TYPE_B && !h->direct_spatial_mv_pred) + ff_h264_direct_dist_scale_factor(h); + ff_h264_direct_ref_list_init(h); + +- if( h->slice_type_nos != FF_I_TYPE && h->pps.cabac ){ ++ if( h->slice_type_nos != AV_PICTURE_TYPE_I && h->pps.cabac ){ + tmp = get_ue_golomb_31(&s->gb); + if(tmp > 2){ + av_log(s->avctx, AV_LOG_ERROR, "cabac_init_idc overflow\n"); +@@ -2097,7 +3117,7 @@ + + h->last_qscale_diff = 0; + tmp = h->pps.init_qp + get_se_golomb(&s->gb); +- if(tmp>51){ ++ if(tmp>51+6*(h->sps.bit_depth_luma-8)){ + av_log(s->avctx, AV_LOG_ERROR, "QP %u out of range\n", tmp); + return -1; + } +@@ -2105,10 +3125,10 @@ + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + //FIXME qscale / qp ... stuff +- if(h->slice_type == FF_SP_TYPE){ ++ if(h->slice_type == AV_PICTURE_TYPE_SP){ + get_bits1(&s->gb); /* sp_for_switch_flag */ + } +- if(h->slice_type==FF_SP_TYPE || h->slice_type == FF_SI_TYPE){ ++ if(h->slice_type==AV_PICTURE_TYPE_SP || h->slice_type == AV_PICTURE_TYPE_SI){ + get_se_golomb(&s->gb); /* slice_qs_delta */ + } + +@@ -2137,8 +3157,8 @@ + } + + if( s->avctx->skip_loop_filter >= AVDISCARD_ALL +- ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != FF_I_TYPE) +- ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == FF_B_TYPE) ++ ||(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY && h->slice_type_nos != AV_PICTURE_TYPE_I) ++ ||(s->avctx->skip_loop_filter >= AVDISCARD_BIDIR && h->slice_type_nos == AV_PICTURE_TYPE_B) + ||(s->avctx->skip_loop_filter >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) + h->deblocking_filter= 0; + +@@ -2153,11 +3173,15 @@ + av_log(s->avctx, AV_LOG_INFO, "Cannot parallelize deblocking type 1, decoding such frames in sequential order\n"); + h0->single_decode_warning = 1; + } +- if(h != h0) +- return 1; // deblocking switched inside frame ++ if (h != h0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "Deblocking switched inside frame.\n"); ++ return 1; ++ } + } + } +- h->qp_thresh= 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]); ++ h->qp_thresh = 15 + 52 - FFMIN(h->slice_alpha_c0_offset, h->slice_beta_offset) ++ - FFMAX3(0, h->pps.chroma_qp_index_offset[0], h->pps.chroma_qp_index_offset[1]) ++ + 6 * (h->sps.bit_depth_luma - 8); + + #if 0 //FMO + if( h->pps.num_slice_groups > 1 && h->pps.mb_slice_group_map_type >= 3 && h->pps.mb_slice_group_map_type <= 5) +@@ -2166,8 +3190,14 @@ + + h0->last_slice_type = slice_type; + h->slice_num = ++h0->current_slice; +- if(h->slice_num >= MAX_SLICES){ +- av_log(s->avctx, AV_LOG_ERROR, "Too many slices, increase MAX_SLICES and recompile\n"); ++ ++ if(h->slice_num) ++ h0->slice_row[(h->slice_num-1)&(MAX_SLICES-1)]= s->resync_mb_y; ++ if ( h0->slice_row[h->slice_num&(MAX_SLICES-1)] + 3 >= s->resync_mb_y ++ && h0->slice_row[h->slice_num&(MAX_SLICES-1)] <= s->resync_mb_y ++ && h->slice_num >= MAX_SLICES) { ++ //in case of ASO this check needs to be updated depending on how we decide to assign slice numbers in this case ++ av_log(s->avctx, AV_LOG_WARNING, "Possibly too many slices (%d >= %d), increase MAX_SLICES and recompile if there are artifacts\n", h->slice_num, MAX_SLICES); + } + + for(j=0; j<2; j++){ +@@ -2175,16 +3205,16 @@ + int *ref2frm= h->ref2frm[h->slice_num&(MAX_SLICES-1)][j]; + for(i=0; i<16; i++){ + id_list[i]= 60; +- if(h->ref_list[j][i].data[0]){ ++ if (h->ref_list[j][i].f.data[0]) { + int k; +- uint8_t *base= h->ref_list[j][i].base[0]; ++ uint8_t *base = h->ref_list[j][i].f.base[0]; + for(k=0; kshort_ref_count; k++) +- if(h->short_ref[k]->base[0] == base){ ++ if (h->short_ref[k]->f.base[0] == base) { + id_list[i]= k; + break; + } + for(k=0; klong_ref_count; k++) +- if(h->long_ref[k] && h->long_ref[k]->base[0] == base){ ++ if (h->long_ref[k] && h->long_ref[k]->f.base[0] == base) { + id_list[i]= h->short_ref_count + k; + break; + } +@@ -2195,15 +3225,16 @@ + ref2frm[1]= -1; + for(i=0; i<16; i++) + ref2frm[i+2]= 4*id_list[i] +- +(h->ref_list[j][i].reference&3); ++ + (h->ref_list[j][i].f.reference & 3); + ref2frm[18+0]= + ref2frm[18+1]= -1; + for(i=16; i<48; i++) + ref2frm[i+4]= 4*id_list[(i-16)>>1] +- +(h->ref_list[j][i].reference&3); ++ + (h->ref_list[j][i].f.reference & 3); + } + +- h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE) ? 0 : 16; ++ //FIXME: fix draw_edges+PAFF+frame threads ++ h->emu_edge_width= (s->flags&CODEC_FLAG_EMU_EDGE || (!h->sps.frame_mbs_only_flag && s->avctx->active_thread_type)) ? 0 : 16; + h->emu_edge_height= (FRAME_MBAFF || FIELD_PICTURE) ? 0 : h->emu_edge_width; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ +@@ -2211,7 +3242,7 @@ + h->slice_num, + (s->picture_structure==PICT_FRAME ? "F" : s->picture_structure==PICT_TOP_FIELD ? "T" : "B"), + first_mb_in_slice, +- av_get_pict_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", ++ av_get_picture_type_char(h->slice_type), h->slice_type_fixed ? " fix" : "", h->nal_unit_type == NAL_IDR_SLICE ? " IDR" : "", + pps_id, h->frame_num, + s->current_picture_ptr->field_poc[0], s->current_picture_ptr->field_poc[1], + h->ref_count[0], h->ref_count[1], +@@ -2219,7 +3250,7 @@ + h->deblocking_filter, h->slice_alpha_c0_offset/2-26, h->slice_beta_offset/2-26, + h->use_weight, + h->use_weight==1 && h->use_weight_chroma ? "c" : "", +- h->slice_type == FF_B_TYPE ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "" ++ h->slice_type == AV_PICTURE_TYPE_B ? (h->direct_spatial_mv_pred ? "SPAT" : "TEMP") : "" + ); + } + +@@ -2229,245 +3260,238 @@ + int ff_h264_get_slice_type(const H264Context *h) + { + switch (h->slice_type) { +- case FF_P_TYPE: return 0; +- case FF_B_TYPE: return 1; +- case FF_I_TYPE: return 2; +- case FF_SP_TYPE: return 3; +- case FF_SI_TYPE: return 4; ++ case AV_PICTURE_TYPE_P: return 0; ++ case AV_PICTURE_TYPE_B: return 1; ++ case AV_PICTURE_TYPE_I: return 2; ++ case AV_PICTURE_TYPE_SP: return 3; ++ case AV_PICTURE_TYPE_SI: return 4; + default: return -1; + } + } + ++static av_always_inline void fill_filter_caches_inter(H264Context *h, MpegEncContext * const s, int mb_type, int top_xy, ++ int left_xy[LEFT_MBS], int top_type, int left_type[LEFT_MBS], int mb_xy, int list) ++{ ++ int b_stride = h->b_stride; ++ int16_t (*mv_dst)[2] = &h->mv_cache[list][scan8[0]]; ++ int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; ++ if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ ++ if(USES_LIST(top_type, list)){ ++ const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride; ++ const int b8_xy= 4*top_xy + 2; ++ int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); ++ AV_COPY128(mv_dst - 1*8, s->current_picture.f.motion_val[list][b_xy + 0]); ++ ref_cache[0 - 1*8]= ++ ref_cache[1 - 1*8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 0]]; ++ ref_cache[2 - 1*8]= ++ ref_cache[3 - 1*8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 1]]; ++ }else{ ++ AV_ZERO128(mv_dst - 1*8); ++ AV_WN32A(&ref_cache[0 - 1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); ++ } ++ ++ if(!IS_INTERLACED(mb_type^left_type[LTOP])){ ++ if(USES_LIST(left_type[LTOP], list)){ ++ const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3; ++ const int b8_xy= 4*left_xy[LTOP] + 1; ++ int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[LTOP]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); ++ AV_COPY32(mv_dst - 1 + 0, s->current_picture.f.motion_val[list][b_xy + b_stride*0]); ++ AV_COPY32(mv_dst - 1 + 8, s->current_picture.f.motion_val[list][b_xy + b_stride*1]); ++ AV_COPY32(mv_dst - 1 + 16, s->current_picture.f.motion_val[list][b_xy + b_stride*2]); ++ AV_COPY32(mv_dst - 1 + 24, s->current_picture.f.motion_val[list][b_xy + b_stride*3]); ++ ref_cache[-1 + 0]= ++ ref_cache[-1 + 8]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2*0]]; ++ ref_cache[-1 + 16]= ++ ref_cache[-1 + 24]= ref2frm[list][s->current_picture.f.ref_index[list][b8_xy + 2*1]]; ++ }else{ ++ AV_ZERO32(mv_dst - 1 + 0); ++ AV_ZERO32(mv_dst - 1 + 8); ++ AV_ZERO32(mv_dst - 1 +16); ++ AV_ZERO32(mv_dst - 1 +24); ++ ref_cache[-1 + 0]= ++ ref_cache[-1 + 8]= ++ ref_cache[-1 + 16]= ++ ref_cache[-1 + 24]= LIST_NOT_USED; ++ } ++ } ++ } ++ ++ if(!USES_LIST(mb_type, list)){ ++ fill_rectangle(mv_dst, 4, 4, 8, pack16to32(0,0), 4); ++ AV_WN32A(&ref_cache[0*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); ++ AV_WN32A(&ref_cache[1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); ++ AV_WN32A(&ref_cache[2*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); ++ AV_WN32A(&ref_cache[3*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); ++ return; ++ } ++ ++ { ++ int8_t *ref = &s->current_picture.f.ref_index[list][4*mb_xy]; ++ int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); ++ uint32_t ref01 = (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101; ++ uint32_t ref23 = (pack16to32(ref2frm[list][ref[2]],ref2frm[list][ref[3]])&0x00FF00FF)*0x0101; ++ AV_WN32A(&ref_cache[0*8], ref01); ++ AV_WN32A(&ref_cache[1*8], ref01); ++ AV_WN32A(&ref_cache[2*8], ref23); ++ AV_WN32A(&ref_cache[3*8], ref23); ++ } ++ ++ { ++ int16_t (*mv_src)[2] = &s->current_picture.f.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride]; ++ AV_COPY128(mv_dst + 8*0, mv_src + 0*b_stride); ++ AV_COPY128(mv_dst + 8*1, mv_src + 1*b_stride); ++ AV_COPY128(mv_dst + 8*2, mv_src + 2*b_stride); ++ AV_COPY128(mv_dst + 8*3, mv_src + 3*b_stride); ++ } ++} ++ + /** + * +- * @return non zero if the loop filter can be skiped ++ * @return non zero if the loop filter can be skipped + */ + static int fill_filter_caches(H264Context *h, int mb_type){ + MpegEncContext * const s = &h->s; + const int mb_xy= h->mb_xy; +- int top_xy, left_xy[2]; +- int top_type, left_type[2]; ++ int top_xy, left_xy[LEFT_MBS]; ++ int top_type, left_type[LEFT_MBS]; ++ uint8_t *nnz; ++ uint8_t *nnz_cache; + + top_xy = mb_xy - (s->mb_stride << MB_FIELD); + +- //FIXME deblocking could skip the intra and nnz parts. +- + /* Wow, what a mess, why didn't they simplify the interlacing & intra + * stuff, I can't imagine that these complex rules are worth it. */ + +- left_xy[1] = left_xy[0] = mb_xy-1; ++ left_xy[LBOT] = left_xy[LTOP] = mb_xy-1; + if(FRAME_MBAFF){ +- const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]); ++ const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]); + const int curr_mb_field_flag = IS_INTERLACED(mb_type); + if(s->mb_y&1){ + if (left_mb_field_flag != curr_mb_field_flag) { +- left_xy[0] -= s->mb_stride; ++ left_xy[LTOP] -= s->mb_stride; + } + }else{ + if(curr_mb_field_flag){ +- top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1); ++ top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy] >> 7) & 1) - 1); + } + if (left_mb_field_flag != curr_mb_field_flag) { +- left_xy[1] += s->mb_stride; ++ left_xy[LBOT] += s->mb_stride; + } + } + } + + h->top_mb_xy = top_xy; +- h->left_mb_xy[0] = left_xy[0]; +- h->left_mb_xy[1] = left_xy[1]; ++ h->left_mb_xy[LTOP] = left_xy[LTOP]; ++ h->left_mb_xy[LBOT] = left_xy[LBOT]; + { + //for sufficiently low qp, filtering wouldn't do anything + //this is a conservative estimate: could also check beta_offset and more accurate chroma_qp + int qp_thresh = h->qp_thresh; //FIXME strictly we should store qp_thresh for each mb of a slice +- int qp = s->current_picture.qscale_table[mb_xy]; ++ int qp = s->current_picture.f.qscale_table[mb_xy]; + if(qp <= qp_thresh +- && (left_xy[0]<0 || ((qp + s->current_picture.qscale_table[left_xy[0]] + 1)>>1) <= qp_thresh) +- && (top_xy < 0 || ((qp + s->current_picture.qscale_table[top_xy ] + 1)>>1) <= qp_thresh)){ ++ && (left_xy[LTOP] < 0 || ((qp + s->current_picture.f.qscale_table[left_xy[LTOP]] + 1) >> 1) <= qp_thresh) ++ && (top_xy < 0 || ((qp + s->current_picture.f.qscale_table[top_xy ] + 1) >> 1) <= qp_thresh)) { + if(!FRAME_MBAFF) + return 1; +- if( (left_xy[0]< 0 || ((qp + s->current_picture.qscale_table[left_xy[1] ] + 1)>>1) <= qp_thresh) +- && (top_xy < s->mb_stride || ((qp + s->current_picture.qscale_table[top_xy -s->mb_stride] + 1)>>1) <= qp_thresh)) ++ if ((left_xy[LTOP] < 0 || ((qp + s->current_picture.f.qscale_table[left_xy[LBOT] ] + 1) >> 1) <= qp_thresh) && ++ (top_xy < s->mb_stride || ((qp + s->current_picture.f.qscale_table[top_xy - s->mb_stride] + 1) >> 1) <= qp_thresh)) + return 1; + } + } + +- top_type = s->current_picture.mb_type[top_xy] ; +- left_type[0] = s->current_picture.mb_type[left_xy[0]]; +- left_type[1] = s->current_picture.mb_type[left_xy[1]]; ++ top_type = s->current_picture.f.mb_type[top_xy]; ++ left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]]; ++ left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]]; + if(h->deblocking_filter == 2){ +- if(h->slice_table[top_xy ] != h->slice_num) top_type= 0; +- if(h->slice_table[left_xy[0] ] != h->slice_num) left_type[0]= left_type[1]= 0; ++ if(h->slice_table[top_xy ] != h->slice_num) top_type= 0; ++ if(h->slice_table[left_xy[LBOT]] != h->slice_num) left_type[LTOP]= left_type[LBOT]= 0; + }else{ +- if(h->slice_table[top_xy ] == 0xFFFF) top_type= 0; +- if(h->slice_table[left_xy[0] ] == 0xFFFF) left_type[0]= left_type[1] =0; ++ if(h->slice_table[top_xy ] == 0xFFFF) top_type= 0; ++ if(h->slice_table[left_xy[LBOT]] == 0xFFFF) left_type[LTOP]= left_type[LBOT] =0; + } +- h->top_type = top_type ; +- h->left_type[0]= left_type[0]; +- h->left_type[1]= left_type[1]; ++ h->top_type = top_type; ++ h->left_type[LTOP]= left_type[LTOP]; ++ h->left_type[LBOT]= left_type[LBOT]; + + if(IS_INTRA(mb_type)) + return 0; + +- AV_COPY64(&h->non_zero_count_cache[0+8*1], &h->non_zero_count[mb_xy][ 0]); +- AV_COPY64(&h->non_zero_count_cache[0+8*2], &h->non_zero_count[mb_xy][ 8]); +- AV_COPY32(&h->non_zero_count_cache[0+8*5], &h->non_zero_count[mb_xy][16]); +- AV_COPY32(&h->non_zero_count_cache[4+8*3], &h->non_zero_count[mb_xy][20]); +- AV_COPY64(&h->non_zero_count_cache[0+8*4], &h->non_zero_count[mb_xy][24]); +- ++ fill_filter_caches_inter(h, s, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 0); ++ if(h->list_count == 2) ++ fill_filter_caches_inter(h, s, mb_type, top_xy, left_xy, top_type, left_type, mb_xy, 1); ++ ++ nnz = h->non_zero_count[mb_xy]; ++ nnz_cache = h->non_zero_count_cache; ++ AV_COPY32(&nnz_cache[4+8*1], &nnz[ 0]); ++ AV_COPY32(&nnz_cache[4+8*2], &nnz[ 4]); ++ AV_COPY32(&nnz_cache[4+8*3], &nnz[ 8]); ++ AV_COPY32(&nnz_cache[4+8*4], &nnz[12]); + h->cbp= h->cbp_table[mb_xy]; + +- { +- int list; +- for(list=0; listlist_count; list++){ +- int8_t *ref; +- int y, b_stride; +- int16_t (*mv_dst)[2]; +- int16_t (*mv_src)[2]; +- +- if(!USES_LIST(mb_type, list)){ +- fill_rectangle( h->mv_cache[list][scan8[0]], 4, 4, 8, pack16to32(0,0), 4); +- AV_WN32A(&h->ref_cache[list][scan8[ 0]], ((LIST_NOT_USED)&0xFF)*0x01010101u); +- AV_WN32A(&h->ref_cache[list][scan8[ 2]], ((LIST_NOT_USED)&0xFF)*0x01010101u); +- AV_WN32A(&h->ref_cache[list][scan8[ 8]], ((LIST_NOT_USED)&0xFF)*0x01010101u); +- AV_WN32A(&h->ref_cache[list][scan8[10]], ((LIST_NOT_USED)&0xFF)*0x01010101u); +- continue; +- } +- +- ref = &s->current_picture.ref_index[list][4*mb_xy]; +- { +- int (*ref2frm)[64] = h->ref2frm[ h->slice_num&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); +- AV_WN32A(&h->ref_cache[list][scan8[ 0]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); +- AV_WN32A(&h->ref_cache[list][scan8[ 2]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); +- ref += 2; +- AV_WN32A(&h->ref_cache[list][scan8[ 8]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); +- AV_WN32A(&h->ref_cache[list][scan8[10]], (pack16to32(ref2frm[list][ref[0]],ref2frm[list][ref[1]])&0x00FF00FF)*0x0101); +- } +- +- b_stride = h->b_stride; +- mv_dst = &h->mv_cache[list][scan8[0]]; +- mv_src = &s->current_picture.motion_val[list][4*s->mb_x + 4*s->mb_y*b_stride]; +- for(y=0; y<4; y++){ +- AV_COPY128(mv_dst + 8*y, mv_src + y*b_stride); +- } +- +- } +- } +- +- +-/* +-0 . T T. T T T T +-1 L . .L . . . . +-2 L . .L . . . . +-3 . T TL . . . . +-4 L . .L . . . . +-5 L . .. . . . . +-*/ +-//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec) + if(top_type){ +- AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); ++ nnz = h->non_zero_count[top_xy]; ++ AV_COPY32(&nnz_cache[4+8*0], &nnz[3*4]); + } + +- if(left_type[0]){ +- h->non_zero_count_cache[3+8*1]= h->non_zero_count[left_xy[0]][7+0*8]; +- h->non_zero_count_cache[3+8*2]= h->non_zero_count[left_xy[0]][7+1*8]; +- h->non_zero_count_cache[3+8*3]= h->non_zero_count[left_xy[0]][7+2*8]; +- h->non_zero_count_cache[3+8*4]= h->non_zero_count[left_xy[0]][7+3*8]; ++ if(left_type[LTOP]){ ++ nnz = h->non_zero_count[left_xy[LTOP]]; ++ nnz_cache[3+8*1]= nnz[3+0*4]; ++ nnz_cache[3+8*2]= nnz[3+1*4]; ++ nnz_cache[3+8*3]= nnz[3+2*4]; ++ nnz_cache[3+8*4]= nnz[3+3*4]; + } + + // CAVLC 8x8dct requires NNZ values for residual decoding that differ from what the loop filter needs + if(!CABAC && h->pps.transform_8x8_mode){ + if(IS_8x8DCT(top_type)){ +- h->non_zero_count_cache[4+8*0]= +- h->non_zero_count_cache[5+8*0]= h->cbp_table[top_xy] & 4; +- h->non_zero_count_cache[6+8*0]= +- h->non_zero_count_cache[7+8*0]= h->cbp_table[top_xy] & 8; +- } +- if(IS_8x8DCT(left_type[0])){ +- h->non_zero_count_cache[3+8*1]= +- h->non_zero_count_cache[3+8*2]= h->cbp_table[left_xy[0]]&2; //FIXME check MBAFF +- } +- if(IS_8x8DCT(left_type[1])){ +- h->non_zero_count_cache[3+8*3]= +- h->non_zero_count_cache[3+8*4]= h->cbp_table[left_xy[1]]&8; //FIXME check MBAFF ++ nnz_cache[4+8*0]= ++ nnz_cache[5+8*0]= (h->cbp_table[top_xy] & 0x4000) >> 12; ++ nnz_cache[6+8*0]= ++ nnz_cache[7+8*0]= (h->cbp_table[top_xy] & 0x8000) >> 12; ++ } ++ if(IS_8x8DCT(left_type[LTOP])){ ++ nnz_cache[3+8*1]= ++ nnz_cache[3+8*2]= (h->cbp_table[left_xy[LTOP]]&0x2000) >> 12; //FIXME check MBAFF ++ } ++ if(IS_8x8DCT(left_type[LBOT])){ ++ nnz_cache[3+8*3]= ++ nnz_cache[3+8*4]= (h->cbp_table[left_xy[LBOT]]&0x8000) >> 12; //FIXME check MBAFF + } + + if(IS_8x8DCT(mb_type)){ +- h->non_zero_count_cache[scan8[0 ]]= h->non_zero_count_cache[scan8[1 ]]= +- h->non_zero_count_cache[scan8[2 ]]= h->non_zero_count_cache[scan8[3 ]]= h->cbp & 1; +- +- h->non_zero_count_cache[scan8[0+ 4]]= h->non_zero_count_cache[scan8[1+ 4]]= +- h->non_zero_count_cache[scan8[2+ 4]]= h->non_zero_count_cache[scan8[3+ 4]]= h->cbp & 2; +- +- h->non_zero_count_cache[scan8[0+ 8]]= h->non_zero_count_cache[scan8[1+ 8]]= +- h->non_zero_count_cache[scan8[2+ 8]]= h->non_zero_count_cache[scan8[3+ 8]]= h->cbp & 4; ++ nnz_cache[scan8[0 ]]= nnz_cache[scan8[1 ]]= ++ nnz_cache[scan8[2 ]]= nnz_cache[scan8[3 ]]= (h->cbp & 0x1000) >> 12; + +- h->non_zero_count_cache[scan8[0+12]]= h->non_zero_count_cache[scan8[1+12]]= +- h->non_zero_count_cache[scan8[2+12]]= h->non_zero_count_cache[scan8[3+12]]= h->cbp & 8; +- } +- } ++ nnz_cache[scan8[0+ 4]]= nnz_cache[scan8[1+ 4]]= ++ nnz_cache[scan8[2+ 4]]= nnz_cache[scan8[3+ 4]]= (h->cbp & 0x2000) >> 12; + +- if(IS_INTER(mb_type) || IS_DIRECT(mb_type)){ +- int list; +- for(list=0; listlist_count; list++){ +- if(USES_LIST(top_type, list)){ +- const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; +- const int b8_xy= 4*top_xy + 2; +- int (*ref2frm)[64] = h->ref2frm[ h->slice_table[top_xy]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); +- AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); +- h->ref_cache[list][scan8[0] + 0 - 1*8]= +- h->ref_cache[list][scan8[0] + 1 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 0]]; +- h->ref_cache[list][scan8[0] + 2 - 1*8]= +- h->ref_cache[list][scan8[0] + 3 - 1*8]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 1]]; +- }else{ +- AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); +- AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((LIST_NOT_USED)&0xFF)*0x01010101u); +- } ++ nnz_cache[scan8[0+ 8]]= nnz_cache[scan8[1+ 8]]= ++ nnz_cache[scan8[2+ 8]]= nnz_cache[scan8[3+ 8]]= (h->cbp & 0x4000) >> 12; + +- if(!IS_INTERLACED(mb_type^left_type[0])){ +- if(USES_LIST(left_type[0], list)){ +- const int b_xy= h->mb2b_xy[left_xy[0]] + 3; +- const int b8_xy= 4*left_xy[0] + 1; +- int (*ref2frm)[64] = h->ref2frm[ h->slice_table[left_xy[0]]&(MAX_SLICES-1) ][0] + (MB_MBAFF ? 20 : 2); +- AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 0 ], s->current_picture.motion_val[list][b_xy + h->b_stride*0]); +- AV_COPY32(h->mv_cache[list][scan8[0] - 1 + 8 ], s->current_picture.motion_val[list][b_xy + h->b_stride*1]); +- AV_COPY32(h->mv_cache[list][scan8[0] - 1 +16 ], s->current_picture.motion_val[list][b_xy + h->b_stride*2]); +- AV_COPY32(h->mv_cache[list][scan8[0] - 1 +24 ], s->current_picture.motion_val[list][b_xy + h->b_stride*3]); +- h->ref_cache[list][scan8[0] - 1 + 0 ]= +- h->ref_cache[list][scan8[0] - 1 + 8 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*0]]; +- h->ref_cache[list][scan8[0] - 1 +16 ]= +- h->ref_cache[list][scan8[0] - 1 +24 ]= ref2frm[list][s->current_picture.ref_index[list][b8_xy + 2*1]]; +- }else{ +- AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 0 ]); +- AV_ZERO32(h->mv_cache [list][scan8[0] - 1 + 8 ]); +- AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +16 ]); +- AV_ZERO32(h->mv_cache [list][scan8[0] - 1 +24 ]); +- h->ref_cache[list][scan8[0] - 1 + 0 ]= +- h->ref_cache[list][scan8[0] - 1 + 8 ]= +- h->ref_cache[list][scan8[0] - 1 + 16 ]= +- h->ref_cache[list][scan8[0] - 1 + 24 ]= LIST_NOT_USED; +- } +- } ++ nnz_cache[scan8[0+12]]= nnz_cache[scan8[1+12]]= ++ nnz_cache[scan8[2+12]]= nnz_cache[scan8[3+12]]= (h->cbp & 0x8000) >> 12; + } + } + + return 0; + } + +-static void loop_filter(H264Context *h){ ++static void loop_filter(H264Context *h, int start_x, int end_x){ + MpegEncContext * const s = &h->s; + uint8_t *dest_y, *dest_cb, *dest_cr; + int linesize, uvlinesize, mb_x, mb_y; + const int end_mb_y= s->mb_y + FRAME_MBAFF; + const int old_slice_type= h->slice_type; ++ const int pixel_shift = h->pixel_shift; ++ const int block_h = 16 >> s->chroma_y_shift; + + if(h->deblocking_filter) { +- for(mb_x= 0; mb_xmb_width; mb_x++){ ++ for(mb_x= start_x; mb_xmb_xy = mb_x + mb_y*s->mb_stride; + h->slice_num= h->slice_table[mb_xy]; +- mb_type= s->current_picture.mb_type[mb_xy]; ++ mb_type = s->current_picture.f.mb_type[mb_xy]; + h->list_count= h->list_counts[mb_xy]; + + if(FRAME_MBAFF) +@@ -2475,9 +3499,9 @@ + + s->mb_x= mb_x; + s->mb_y= mb_y; +- dest_y = s->current_picture.data[0] + (mb_x + mb_y * s->linesize ) * 16; +- dest_cb = s->current_picture.data[1] + (mb_x + mb_y * s->uvlinesize) * 8; +- dest_cr = s->current_picture.data[2] + (mb_x + mb_y * s->uvlinesize) * 8; ++ dest_y = s->current_picture.f.data[0] + ((mb_x << pixel_shift) + mb_y * s->linesize ) * 16; ++ dest_cb = s->current_picture.f.data[1] + (mb_x << pixel_shift) * (8 << CHROMA444) + mb_y * s->uvlinesize * block_h; ++ dest_cr = s->current_picture.f.data[2] + (mb_x << pixel_shift) * (8 << CHROMA444) + mb_y * s->uvlinesize * block_h; + //FIXME simplify above + + if (MB_FIELD) { +@@ -2485,8 +3509,8 @@ + uvlinesize = h->mb_uvlinesize = s->uvlinesize * 2; + if(mb_y&1){ //FIXME move out of this function? + dest_y -= s->linesize*15; +- dest_cb-= s->uvlinesize*7; +- dest_cr-= s->uvlinesize*7; ++ dest_cb-= s->uvlinesize * (block_h - 1); ++ dest_cr-= s->uvlinesize * (block_h - 1); + } + } else { + linesize = h->mb_linesize = s->linesize; +@@ -2495,8 +3519,8 @@ + backup_mb_border(h, dest_y, dest_cb, dest_cr, linesize, uvlinesize, 0); + if(fill_filter_caches(h, mb_type)) + continue; +- h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.qscale_table[mb_xy]); +- h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.qscale_table[mb_xy]); ++ h->chroma_qp[0] = get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mb_xy]); ++ h->chroma_qp[1] = get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mb_xy]); + + if (FRAME_MBAFF) { + ff_h264_filter_mb (h, mb_x, mb_y, dest_y, dest_cb, dest_cr, linesize, uvlinesize); +@@ -2507,7 +3531,7 @@ + } + } + h->slice_type= old_slice_type; +- s->mb_x= 0; ++ s->mb_x= end_x; + s->mb_y= end_mb_y - FRAME_MBAFF; + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); +@@ -2517,17 +3541,52 @@ + MpegEncContext * const s = &h->s; + const int mb_xy= s->mb_x + s->mb_y*s->mb_stride; + int mb_type = (h->slice_table[mb_xy-1] == h->slice_num) +- ? s->current_picture.mb_type[mb_xy-1] ++ ? s->current_picture.f.mb_type[mb_xy - 1] + : (h->slice_table[mb_xy-s->mb_stride] == h->slice_num) +- ? s->current_picture.mb_type[mb_xy-s->mb_stride] ++ ? s->current_picture.f.mb_type[mb_xy - s->mb_stride] + : 0; + h->mb_mbaff = h->mb_field_decoding_flag = IS_INTERLACED(mb_type) ? 1 : 0; + } + ++/** ++ * Draw edges and report progress for the last MB row. ++ */ ++static void decode_finish_row(H264Context *h){ ++ MpegEncContext * const s = &h->s; ++ int top = 16*(s->mb_y >> FIELD_PICTURE); ++ int height = 16 << FRAME_MBAFF; ++ int deblock_border = (16 + 4) << FRAME_MBAFF; ++ int pic_height = 16*s->mb_height >> FIELD_PICTURE; ++ ++ if (h->deblocking_filter) { ++ if((top + height) >= pic_height) ++ height += deblock_border; ++ ++ top -= deblock_border; ++ } ++ ++ if (top >= pic_height || (top + height) < h->emu_edge_height) ++ return; ++ ++ height = FFMIN(height, pic_height - top); ++ if (top < h->emu_edge_height) { ++ height = top+height; ++ top = 0; ++ } ++ ++ ff_draw_horiz_band(s, top, height); ++ ++ if (s->dropable) return; ++ ++ ff_thread_report_progress((AVFrame*)s->current_picture_ptr, top + height - 1, ++ s->picture_structure==PICT_BOTTOM_FIELD); ++} ++ + static int decode_slice(struct AVCodecContext *avctx, void *arg){ + H264Context *h = *(void**)arg; + MpegEncContext * const s = &h->s; +- const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F; ++ const int part_mask= s->partitioned_frame ? (ER_AC_END|ER_AC_ERROR) : 0x7F; ++ int lf_x_start = s->mb_x; + + s->mb_skip_run= -1; + +@@ -2565,19 +3624,20 @@ + eos = get_cabac_terminate( &h->cabac ); + + if((s->workaround_bugs & FF_BUG_TRUNCATED) && h->cabac.bytestream > h->cabac.bytestream_end + 2){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); ++ if (s->mb_x >= lf_x_start) loop_filter(h, lf_x_start, s->mb_x + 1); + return 0; + } + if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { +- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%u)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); ++ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%d)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); + return -1; + } + + if( ++s->mb_x >= s->mb_width ) { +- s->mb_x = 0; +- loop_filter(h); +- ff_draw_horiz_band(s, 16*s->mb_y, 16); ++ loop_filter(h, lf_x_start, s->mb_x); ++ s->mb_x = lf_x_start = 0; ++ decode_finish_row(h); + ++s->mb_y; + if(FIELD_OR_MBAFF_PICTURE) { + ++s->mb_y; +@@ -2588,7 +3648,8 @@ + + if( eos || s->mb_y >= s->mb_height ) { + tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); ++ if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x); + return 0; + } + } +@@ -2609,15 +3670,14 @@ + + if(ret<0){ + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); +- ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); + return -1; + } + + if(++s->mb_x >= s->mb_width){ +- s->mb_x=0; +- loop_filter(h); +- ff_draw_horiz_band(s, 16*s->mb_y, 16); ++ loop_filter(h, lf_x_start, s->mb_x); ++ s->mb_x = lf_x_start = 0; ++ decode_finish_row(h); + ++s->mb_y; + if(FIELD_OR_MBAFF_PICTURE) { + ++s->mb_y; +@@ -2627,79 +3687,34 @@ + if(s->mb_y >= s->mb_height){ + tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); + +- if(get_bits_count(&s->gb) == s->gb.size_in_bits ) { +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ if ( get_bits_left(&s->gb) == 0 ++ || get_bits_left(&s->gb) > 0 && !(s->avctx->err_recognition & AV_EF_AGGRESSIVE)) { ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); + + return 0; + }else{ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_END&part_mask); + + return -1; + } + } + } + +- if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->mb_skip_run<=0){ ++ if (get_bits_left(&s->gb) <= 0 && s->mb_skip_run <= 0){ + tprintf(s->avctx, "slice end %d %d\n", get_bits_count(&s->gb), s->gb.size_in_bits); +- if(get_bits_count(&s->gb) == s->gb.size_in_bits ){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); +- +- return 0; +- }else{ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); +- +- return -1; +- } +- } +- } +- } +- +-#if 0 +- for(;s->mb_y < s->mb_height; s->mb_y++){ +- for(;s->mb_x < s->mb_width; s->mb_x++){ +- int ret= decode_mb(h); +- +- ff_h264_hl_decode_mb(h); +- +- if(ret<0){ +- av_log(s->avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); +- +- return -1; +- } +- +- if(++s->mb_x >= s->mb_width){ +- s->mb_x=0; +- if(++s->mb_y >= s->mb_height){ +- if(get_bits_count(s->gb) == s->gb.size_in_bits){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); +- +- return 0; +- }else{ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); +- +- return -1; +- } +- } +- } +- +- if(get_bits_count(s->?gb) >= s->gb?.size_in_bits){ +- if(get_bits_count(s->gb) == s->gb.size_in_bits){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, (AC_END|DC_END|MV_END)&part_mask); ++ if (get_bits_left(&s->gb) == 0) { ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END&part_mask); ++ if (s->mb_x > lf_x_start) loop_filter(h, lf_x_start, s->mb_x); + + return 0; + }else{ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); + + return -1; + } + } + } +- s->mb_x=0; +- ff_draw_horiz_band(s, 16*s->mb_y, 16); + } +-#endif +- return -1; //not reached + } + + /** +@@ -2708,26 +3723,25 @@ + * @param h h264 master context + * @param context_count number of contexts to execute + */ +-static void execute_decode_slices(H264Context *h, int context_count){ ++static int execute_decode_slices(H264Context *h, int context_count){ + MpegEncContext * const s = &h->s; + AVCodecContext * const avctx= s->avctx; + H264Context *hx; + int i; + +- if (s->avctx->hwaccel) +- return; +- if(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) +- return; ++ if (s->avctx->hwaccel || s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) ++ return 0; + if(context_count == 1) { +- decode_slice(avctx, &h); ++ return decode_slice(avctx, &h); + } else { + for(i = 1; i < context_count; i++) { + hx = h->thread_context[i]; +- hx->s.error_recognition = avctx->error_recognition; ++ hx->s.err_recognition = avctx->err_recognition; + hx->s.error_count = 0; ++ hx->x264_build= h->x264_build; + } + +- avctx->execute(avctx, (void *)decode_slice, ++ avctx->execute(avctx, decode_slice, + h->thread_context, NULL, context_count, sizeof(void*)); + + /* pull back stuff from slices to master context */ +@@ -2739,24 +3753,28 @@ + for(i = 1; i < context_count; i++) + h->s.error_count += h->thread_context[i]->s.error_count; + } ++ ++ return 0; + } + + + static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){ + MpegEncContext * const s = &h->s; + AVCodecContext * const avctx= s->avctx; +- int buf_index=0; + H264Context *hx; ///< thread context +- int context_count = 0; +- int next_avc= h->is_avc ? 0 : buf_size; ++ int buf_index; ++ int context_count; ++ int next_avc; ++ int pass = !(avctx->active_thread_type & FF_THREAD_FRAME); ++ int nals_needed=0; ///< number of NALs that need decoding before the next frame thread starts ++ int nal_index; ++ ++ h->nal_unit_type= 0; ++ ++ if(!s->slice_context_count) ++ s->slice_context_count= 1; ++ h->max_contexts = s->slice_context_count; + +- h->max_contexts = avctx->thread_count; +-#if 0 +- int i; +- for(i=0; i<50; i++){ +- av_log(NULL, AV_LOG_ERROR,"%02X ", buf[i]); +- } +-#endif + if(!(s->flags2 & CODEC_FLAG2_CHUNKS)){ + h->current_slice = 0; + if (!s->first_field) +@@ -2764,6 +3782,11 @@ + ff_h264_reset_sei(h); + } + ++ for(;pass <= 1;pass++){ ++ buf_index = 0; ++ context_count = 0; ++ next_avc = h->is_avc ? 0 : buf_size; ++ nal_index = 0; + for(;;){ + int consumed; + int dst_length; +@@ -2773,7 +3796,7 @@ + int err; + + if(buf_index >= next_avc) { +- if(buf_index >= buf_size) break; ++ if (buf_index >= buf_size - h->nal_length_size) break; + nalsize = 0; + for(i = 0; i < h->nal_length_size; i++) + nalsize = (nalsize << 8) | buf[buf_index++]; +@@ -2808,13 +3831,13 @@ + s->workaround_bugs |= FF_BUG_TRUNCATED; + + if(!(s->workaround_bugs & FF_BUG_TRUNCATED)){ +- while(ptr[dst_length - 1] == 0 && dst_length > 0) ++ while(dst_length > 0 && ptr[dst_length - 1] == 0) + dst_length--; + } + bit_length= !dst_length ? 0 : (8*dst_length - ff_h264_decode_rbsp_trailing(h, ptr + dst_length - 1)); + + if(s->avctx->debug&FF_DEBUG_STARTCODE){ +- av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d at %d/%d length %d\n", hx->nal_unit_type, buf_index, buf_size, dst_length); ++ av_log(h->s.avctx, AV_LOG_DEBUG, "NAL %d/%d at %d/%d length %d pass %d\n", hx->nal_unit_type, hx->nal_ref_idc, buf_index, buf_size, dst_length, pass); + } + + if (h->is_avc && (nalsize != consumed) && nalsize){ +@@ -2822,9 +3845,28 @@ + } + + buf_index += consumed; ++ nal_index++; ++ ++ if(pass == 0) { ++ // packets can sometimes contain multiple PPS/SPS ++ // e.g. two PAFF field pictures in one packet, or a demuxer which splits NALs strangely ++ // if so, when frame threading we can't start the next thread until we've read all of them ++ switch (hx->nal_unit_type) { ++ case NAL_SPS: ++ case NAL_PPS: ++ nals_needed = nal_index; ++ break; ++ case NAL_IDR_SLICE: ++ case NAL_SLICE: ++ init_get_bits(&hx->s.gb, ptr, bit_length); ++ if (!get_ue_golomb(&hx->s.gb)) ++ nals_needed = nal_index; ++ } ++ continue; ++ } + +- if( (s->hurry_up == 1 && h->nal_ref_idc == 0) //FIXME do not discard SEI id +- ||(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0)) ++ //FIXME do not discard SEI id ++ if(avctx->skip_frame >= AVDISCARD_NONREF && h->nal_ref_idc == 0) + continue; + + again: +@@ -2832,10 +3874,10 @@ + switch(hx->nal_unit_type){ + case NAL_IDR_SLICE: + if (h->nal_unit_type != NAL_IDR_SLICE) { +- av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices"); ++ av_log(h->s.avctx, AV_LOG_ERROR, "Invalid mix of idr and non-idr slices\n"); + return -1; + } +- idr(h); //FIXME ensure we don't loose some frames if there is reordering ++ idr(h); // FIXME ensure we don't lose some frames if there is reordering + case NAL_SLICE: + init_get_bits(&hx->s.gb, ptr, bit_length); + hx->intra_gb_ptr= +@@ -2845,20 +3887,40 @@ + if((err = decode_slice_header(hx, h))) + break; + ++ if ( h->sei_recovery_frame_cnt >= 0 ++ && ( h->recovery_frame<0 ++ || ((h->recovery_frame - h->frame_num) & ((1 << h->sps.log2_max_frame_num)-1)) > h->sei_recovery_frame_cnt)) { ++ h->recovery_frame = (h->frame_num + h->sei_recovery_frame_cnt) % ++ (1 << h->sps.log2_max_frame_num); ++ } ++ ++ s->current_picture_ptr->f.key_frame |= ++ (hx->nal_unit_type == NAL_IDR_SLICE); ++ ++ if (h->recovery_frame == h->frame_num) { ++ s->current_picture_ptr->sync |= 1; ++ h->recovery_frame = -1; ++ } ++ ++ h->sync |= !!s->current_picture_ptr->f.key_frame; ++ h->sync |= 3*!!(s->flags2 & CODEC_FLAG2_SHOW_ALL); ++ s->current_picture_ptr->sync |= h->sync; ++ + if (h->current_slice == 1) { ++ if(!(s->flags2 & CODEC_FLAG2_CHUNKS)) { ++ decode_postinit(h, nal_index >= nals_needed); ++ } ++ + if (s->avctx->hwaccel && s->avctx->hwaccel->start_frame(s->avctx, NULL, 0) < 0) + return -1; + if(CONFIG_H264_VDPAU_DECODER && s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_h264_picture_start(s); + } + +- s->current_picture_ptr->key_frame |= +- (hx->nal_unit_type == NAL_IDR_SLICE) || +- (h->sei_recovery_frame_cnt >= 0); +- if(hx->redundant_pic_count==0 && hx->s.hurry_up < 5 ++ if(hx->redundant_pic_count==0 + && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) +- && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) +- && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE) ++ && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B) ++ && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I) + && avctx->skip_frame < AVDISCARD_ALL){ + if(avctx->hwaccel) { + if (avctx->hwaccel->decode_slice(avctx, &buf[buf_index - consumed], consumed) < 0) +@@ -2893,10 +3955,9 @@ + + if(hx->redundant_pic_count==0 && hx->intra_gb_ptr && hx->s.data_partitioning + && s->context_initialized +- && s->hurry_up < 5 + && (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) +- && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) +- && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE) ++ && (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=AV_PICTURE_TYPE_B) ++ && (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==AV_PICTURE_TYPE_I) + && avctx->skip_frame < AVDISCARD_ALL) + context_count++; + break; +@@ -2906,9 +3967,15 @@ + break; + case NAL_SPS: + init_get_bits(&s->gb, ptr, bit_length); +- ff_h264_decode_seq_parameter_set(h); ++ if (ff_h264_decode_seq_parameter_set(h) < 0 && (h->is_avc ? (nalsize != consumed) && nalsize : 1)){ ++ av_log(h->s.avctx, AV_LOG_DEBUG, "SPS decoding failure, trying alternative mode\n"); ++ if(h->is_avc) av_assert0(next_avc - buf_index + consumed == nalsize); ++ init_get_bits(&s->gb, &buf[buf_index + 1 - consumed], 8*(next_avc - buf_index + consumed - 1)); ++ ff_h264_decode_seq_parameter_set(h); ++ } + +- if(s->flags& CODEC_FLAG_LOW_DELAY) ++ if (s->flags& CODEC_FLAG_LOW_DELAY || ++ (h->sps.bitstream_restriction_flag && !h->sps.num_reorder_frames)) + s->low_delay=1; + + if(avctx->has_b_frames < 2) +@@ -2949,13 +4016,14 @@ + goto again; + } + } ++ } + if(context_count) + execute_decode_slices(h, context_count); + return buf_index; + } + + /** +- * returns the number of bytes consumed for building the current frame ++ * Return the number of bytes consumed for building the current frame. + */ + static int get_consumed_bytes(MpegEncContext *s, int pos, int buf_size){ + if(pos==0) pos=1; //avoid infinite loops (i doubt that is needed but ...) +@@ -2973,21 +4041,23 @@ + H264Context *h = avctx->priv_data; + MpegEncContext *s = &h->s; + AVFrame *pict = data; +- int buf_index; ++ int buf_index = 0; ++ Picture *out; ++ int i, out_idx; + + s->flags= avctx->flags; + s->flags2= avctx->flags2; + + /* end of stream, output what is still in the buffers */ +- out: + if (buf_size == 0) { +- Picture *out; +- int i, out_idx; ++ out: ++ ++ s->current_picture_ptr = NULL; + + //FIXME factorize this with the output code below + out = h->delayed_pic[0]; + out_idx = 0; +- for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++) ++ for (i = 1; h->delayed_pic[i] && !h->delayed_pic[i]->f.key_frame && !h->delayed_pic[i]->mmco_reset; i++) + if(h->delayed_pic[i]->poc < out->poc){ + out = h->delayed_pic[i]; + out_idx = i; +@@ -3001,162 +4071,58 @@ + *pict= *(AVFrame*)out; + } + +- return 0; ++ return buf_index; ++ } ++ if(h->is_avc && buf_size >= 9 && buf[0]==1 && buf[2]==0 && (buf[4]&0xFC)==0xFC && (buf[5]&0x1F) && buf[8]==0x67){ ++ int cnt= buf[5]&0x1f; ++ uint8_t *p= buf+6; ++ while(cnt--){ ++ int nalsize= AV_RB16(p) + 2; ++ if(nalsize > buf_size - (p-buf) || p[2]!=0x67) ++ goto not_extra; ++ p += nalsize; ++ } ++ cnt = *(p++); ++ if(!cnt) ++ goto not_extra; ++ while(cnt--){ ++ int nalsize= AV_RB16(p) + 2; ++ if(nalsize > buf_size - (p-buf) || p[2]!=0x68) ++ goto not_extra; ++ p += nalsize; ++ } ++ ++ return ff_h264_decode_extradata(h, buf, buf_size); + } ++not_extra: + + buf_index=decode_nal_units(h, buf, buf_size); + if(buf_index < 0) + return -1; + + if (!s->current_picture_ptr && h->nal_unit_type == NAL_END_SEQUENCE) { +- buf_size = 0; ++ av_assert0(buf_index <= buf_size); + goto out; + } + + if(!(s->flags2 & CODEC_FLAG2_CHUNKS) && !s->current_picture_ptr){ +- if (avctx->skip_frame >= AVDISCARD_NONREF || s->hurry_up) return 0; ++ if (avctx->skip_frame >= AVDISCARD_NONREF || ++ buf_size >= 4 && !memcmp("Q264", buf, 4)) ++ return buf_size; + av_log(avctx, AV_LOG_ERROR, "no frame!\n"); + return -1; + } + + if(!(s->flags2 & CODEC_FLAG2_CHUNKS) || (s->mb_y >= s->mb_height && s->mb_height)){ +- Picture *out = s->current_picture_ptr; +- Picture *cur = s->current_picture_ptr; +- int i, pics, out_of_order, out_idx; +- +- field_end(h); +- +- if (cur->field_poc[0]==INT_MAX || cur->field_poc[1]==INT_MAX) { +- /* Wait for second field. */ +- *data_size = 0; +- +- } else { +- cur->interlaced_frame = 0; +- cur->repeat_pict = 0; +- +- /* Signal interlacing information externally. */ +- /* Prioritize picture timing SEI information over used decoding process if it exists. */ +- +- if(h->sps.pic_struct_present_flag){ +- switch (h->sei_pic_struct) +- { +- case SEI_PIC_STRUCT_FRAME: +- break; +- case SEI_PIC_STRUCT_TOP_FIELD: +- case SEI_PIC_STRUCT_BOTTOM_FIELD: +- cur->interlaced_frame = 1; +- break; +- case SEI_PIC_STRUCT_TOP_BOTTOM: +- case SEI_PIC_STRUCT_BOTTOM_TOP: +- if (FIELD_OR_MBAFF_PICTURE) +- cur->interlaced_frame = 1; +- else +- // try to flag soft telecine progressive +- cur->interlaced_frame = h->prev_interlaced_frame; +- break; +- case SEI_PIC_STRUCT_TOP_BOTTOM_TOP: +- case SEI_PIC_STRUCT_BOTTOM_TOP_BOTTOM: +- // Signal the possibility of telecined film externally (pic_struct 5,6) +- // From these hints, let the applications decide if they apply deinterlacing. +- cur->repeat_pict = 1; +- break; +- case SEI_PIC_STRUCT_FRAME_DOUBLING: +- // Force progressive here, as doubling interlaced frame is a bad idea. +- cur->repeat_pict = 2; +- break; +- case SEI_PIC_STRUCT_FRAME_TRIPLING: +- cur->repeat_pict = 4; +- break; +- } +- +- if ((h->sei_ct_type & 3) && h->sei_pic_struct <= SEI_PIC_STRUCT_BOTTOM_TOP) +- cur->interlaced_frame = (h->sei_ct_type & (1<<1)) != 0; +- }else{ +- /* Derive interlacing flag from used decoding process. */ +- cur->interlaced_frame = FIELD_OR_MBAFF_PICTURE; +- } +- h->prev_interlaced_frame = cur->interlaced_frame; +- +- if (cur->field_poc[0] != cur->field_poc[1]){ +- /* Derive top_field_first from field pocs. */ +- cur->top_field_first = cur->field_poc[0] < cur->field_poc[1]; +- }else{ +- if(cur->interlaced_frame || h->sps.pic_struct_present_flag){ +- /* Use picture timing SEI information. Even if it is a information of a past frame, better than nothing. */ +- if(h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM +- || h->sei_pic_struct == SEI_PIC_STRUCT_TOP_BOTTOM_TOP) +- cur->top_field_first = 1; +- else +- cur->top_field_first = 0; +- }else{ +- /* Most likely progressive */ +- cur->top_field_first = 0; +- } +- } +- +- //FIXME do something with unavailable reference frames +- +- /* Sort B-frames into display order */ +- +- if(h->sps.bitstream_restriction_flag +- && s->avctx->has_b_frames < h->sps.num_reorder_frames){ +- s->avctx->has_b_frames = h->sps.num_reorder_frames; +- s->low_delay = 0; +- } +- +- if( s->avctx->strict_std_compliance >= FF_COMPLIANCE_STRICT +- && !h->sps.bitstream_restriction_flag){ +- s->avctx->has_b_frames= MAX_DELAYED_PIC_COUNT; +- s->low_delay= 0; +- } +- +- pics = 0; +- while(h->delayed_pic[pics]) pics++; +- +- assert(pics <= MAX_DELAYED_PIC_COUNT); + +- h->delayed_pic[pics++] = cur; +- if(cur->reference == 0) +- cur->reference = DELAYED_PIC_REF; ++ if(s->flags2 & CODEC_FLAG2_CHUNKS) decode_postinit(h, 1); + +- out = h->delayed_pic[0]; +- out_idx = 0; +- for(i=1; h->delayed_pic[i] && !h->delayed_pic[i]->key_frame && !h->delayed_pic[i]->mmco_reset; i++) +- if(h->delayed_pic[i]->poc < out->poc){ +- out = h->delayed_pic[i]; +- out_idx = i; +- } +- if(s->avctx->has_b_frames == 0 && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset)) +- h->outputed_poc= INT_MIN; +- out_of_order = out->poc < h->outputed_poc; +- +- if(h->sps.bitstream_restriction_flag && s->avctx->has_b_frames >= h->sps.num_reorder_frames) +- { } +- else if((out_of_order && pics-1 == s->avctx->has_b_frames && s->avctx->has_b_frames < MAX_DELAYED_PIC_COUNT) +- || (s->low_delay && +- ((h->outputed_poc != INT_MIN && out->poc > h->outputed_poc + 2) +- || cur->pict_type == FF_B_TYPE))) +- { +- s->low_delay = 0; +- s->avctx->has_b_frames++; +- } ++ field_end(h, 0); + +- if(out_of_order || pics > s->avctx->has_b_frames){ +- out->reference &= ~DELAYED_PIC_REF; +- for(i=out_idx; h->delayed_pic[i]; i++) +- h->delayed_pic[i] = h->delayed_pic[i+1]; +- } +- if(!out_of_order && pics > s->avctx->has_b_frames){ ++ *data_size = 0; /* Wait for second field. */ ++ if (h->next_output_pic && (h->next_output_pic->sync || h->sync>1)) { + *data_size = sizeof(AVFrame); +- +- if(out_idx==0 && h->delayed_pic[0] && (h->delayed_pic[0]->key_frame || h->delayed_pic[0]->mmco_reset)) { +- h->outputed_poc = INT_MIN; +- } else +- h->outputed_poc = out->poc; +- *pict= *(AVFrame*)out; +- }else{ +- av_log(avctx, AV_LOG_DEBUG, "no picture\n"); +- } ++ *pict = *(AVFrame*)h->next_output_pic; + } + } + +@@ -3191,15 +4157,17 @@ + #undef random + #define COUNT 8000 + #define SIZE (COUNT*40) ++extern AVCodec ff_h264_decoder; + int main(void){ + int i; + uint8_t temp[SIZE]; + PutBitContext pb; + GetBitContext gb; +-// int int_temp[10000]; + DSPContext dsp; + AVCodecContext avctx; + ++ avcodec_get_context_defaults3(&avctx, &ff_h264_decoder); ++ + dsputil_init(&dsp, &avctx); + + init_put_bits(&pb, temp, SIZE); +@@ -3213,17 +4181,15 @@ + + init_get_bits(&gb, temp, 8*SIZE); + for(i=0; ih264dsp.h264_idct_add(ref, block, 4); +-/* for(j=0; j<16; j++){ +- printf("%d ", ref[j]); +- } +- printf("\n");*/ +- +- for(j=0; j<16; j++){ +- int diff= FFABS(src[j] - ref[j]); +- +- error+= diff*diff; +- max_error= FFMAX(max_error, diff); +- } +- } +- printf("error=%f max_error=%d\n", ((float)error)/COUNT/16, (int)max_error ); +- printf("testing quantizer\n"); +- for(qp=0; qp<52; qp++){ +- for(i=0; i<16; i++) +- src1_block[i]= src2_block[i]= random()%255; +- +- } +- printf("Testing NAL layer\n"); +- +- uint8_t bitstream[COUNT]; +- uint8_t nal[COUNT*2]; +- H264Context h; +- memset(&h, 0, sizeof(H264Context)); +- +- for(i=0; ipriv_data; + MpegEncContext *s = &h->s; + ++ ff_h264_remove_all_refs(h); + ff_h264_free_context(h); + + MPV_common_end(s); +@@ -3399,41 +4261,65 @@ + { FF_PROFILE_H264_HIGH_10_INTRA, "High 10 Intra" }, + { FF_PROFILE_H264_HIGH_422, "High 4:2:2" }, + { FF_PROFILE_H264_HIGH_422_INTRA, "High 4:2:2 Intra" }, ++ { FF_PROFILE_H264_HIGH_444, "High 4:4:4" }, + { FF_PROFILE_H264_HIGH_444_PREDICTIVE, "High 4:4:4 Predictive" }, + { FF_PROFILE_H264_HIGH_444_INTRA, "High 4:4:4 Intra" }, + { FF_PROFILE_H264_CAVLC_444, "CAVLC 4:4:4" }, + { FF_PROFILE_UNKNOWN }, + }; + ++static const AVOption h264_options[] = { ++ {"is_avc", "is avc", offsetof(H264Context, is_avc), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, 0}, ++ {"nal_length_size", "nal_length_size", offsetof(H264Context, nal_length_size), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 4, 0}, ++ {NULL} ++}; ++ ++static const AVClass h264_class = { ++ "H264 Decoder", ++ av_default_item_name, ++ h264_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVClass h264_vdpau_class = { ++ "H264 VDPAU Decoder", ++ av_default_item_name, ++ h264_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_h264_decoder = { +- "h264", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H264, +- sizeof(H264Context), +- ff_h264_decode_init, +- NULL, +- ff_h264_decode_end, +- decode_frame, +- /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .name = "h264", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .priv_data_size = sizeof(H264Context), ++ .init = ff_h264_decode_init, ++ .close = ff_h264_decode_end, ++ .decode = decode_frame, ++ .capabilities = /*CODEC_CAP_DRAW_HORIZ_BAND |*/ CODEC_CAP_DR1 | CODEC_CAP_DELAY | ++ CODEC_CAP_SLICE_THREADS | CODEC_CAP_FRAME_THREADS, + .flush= flush_dpb, + .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(decode_update_thread_context), + .profiles = NULL_IF_CONFIG_SMALL(profiles), ++ .priv_class = &h264_class, + }; + + #if CONFIG_H264_VDPAU_DECODER + AVCodec ff_h264_vdpau_decoder = { +- "h264_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H264, +- sizeof(H264Context), +- ff_h264_decode_init, +- NULL, +- ff_h264_decode_end, +- decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, ++ .name = "h264_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .priv_data_size = sizeof(H264Context), ++ .init = ff_h264_decode_init, ++ .close = ff_h264_decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, + .flush= flush_dpb, + .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"), + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_H264, PIX_FMT_NONE}, + .profiles = NULL_IF_CONFIG_SMALL(profiles), ++ .priv_class = &h264_vdpau_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_cabac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_cabac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_cabac.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_cabac.c 2012-05-14 14:08:53.803329295 +0200 +@@ -26,7 +26,11 @@ + */ + + #define CABAC 1 ++#define UNCHECKED_BITSTREAM_READER 1 + ++#include "config.h" ++#include "cabac.h" ++#include "cabac_functions.h" + #include "internal.h" + #include "dsputil.h" + #include "avcodec.h" +@@ -35,7 +39,6 @@ + #include "h264_mvpred.h" + #include "golomb.h" + +-#include "cabac.h" + #if ARCH_X86 + #include "x86/h264_i386.h" + #endif +@@ -45,7 +48,7 @@ + + /* Cabac pre state table */ + +-static const int8_t cabac_context_init_I[460][2] = ++static const int8_t cabac_context_init_I[1024][2] = + { + /* 0 - 10 */ + { 20, -15 }, { 2, 54 }, { 3, 74 }, { 20, -15 }, +@@ -211,10 +214,153 @@ + { -10, 73 }, { -10, 70 }, { -10, 69 }, { -5, 66 }, + { -9, 64 }, { -5, 58 }, { 2, 59 }, { 21, -10 }, + { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 }, +- { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 } ++ { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 }, ++ ++ /* 460 -> 1024 */ ++ { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 }, ++ { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 }, ++ { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }, ++ { -17, 123 }, { -12, 115 }, { -16, 122 }, { -11, 115 }, ++ { -12, 63 }, { -2, 68 }, { -15, 84 }, { -13, 104 }, ++ { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }, ++ { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 }, ++ { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 }, ++ { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 }, ++ { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 }, ++ { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 }, ++ { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 }, ++ { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 }, ++ { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 }, ++ { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 }, ++ { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 }, ++ { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 }, ++ { -7, 93 }, { -11, 87 }, { -3, 77 }, { -5, 71 }, ++ { -4, 63 }, { -4, 68 }, { -12, 84 }, { -7, 62 }, ++ { -7, 65 }, { 8, 61 }, { 5, 56 }, { -2, 66 }, ++ { 1, 64 }, { 0, 61 }, { -2, 78 }, { 1, 50 }, ++ { 7, 52 }, { 10, 35 }, { 0, 44 }, { 11, 38 }, ++ { 1, 45 }, { 0, 46 }, { 5, 44 }, { 31, 17 }, ++ { 1, 51 }, { 7, 50 }, { 28, 19 }, { 16, 33 }, ++ { 14, 62 }, { -13, 108 }, { -15, 100 }, { -13, 101 }, ++ { -13, 91 }, { -12, 94 }, { -10, 88 }, { -16, 84 }, ++ { -10, 86 }, { -7, 83 }, { -13, 87 }, { -19, 94 }, ++ { 1, 70 }, { 0, 72 }, { -5, 74 }, { 18, 59 }, ++ { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 }, ++ { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 }, ++ { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 }, ++ { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 }, ++ { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 }, ++ { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 }, ++ { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 }, ++ { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 }, ++ { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 }, ++ { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 }, ++ { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 }, ++ { 24, 0 }, { 15, 9 }, { 8, 25 }, { 13, 18 }, ++ { 15, 9 }, { 13, 19 }, { 10, 37 }, { 12, 18 }, ++ { 6, 29 }, { 20, 33 }, { 15, 30 }, { 4, 45 }, ++ { 1, 58 }, { 0, 62 }, { 7, 61 }, { 12, 38 }, ++ { 11, 45 }, { 15, 39 }, { 11, 42 }, { 13, 44 }, ++ { 16, 45 }, { 12, 41 }, { 10, 49 }, { 30, 34 }, ++ { 18, 42 }, { 10, 55 }, { 17, 51 }, { 17, 46 }, ++ { 0, 89 }, { 26, -19 }, { 22, -17 }, { 26, -17 }, ++ { 30, -25 }, { 28, -20 }, { 33, -23 }, { 37, -27 }, ++ { 33, -23 }, { 40, -28 }, { 38, -17 }, { 33, -11 }, ++ { 40, -15 }, { 41, -6 }, { 38, 1 }, { 41, 17 }, ++ { -17, 120 }, { -20, 112 }, { -18, 114 }, { -11, 85 }, ++ { -15, 92 }, { -14, 89 }, { -26, 71 }, { -15, 81 }, ++ { -14, 80 }, { 0, 68 }, { -14, 70 }, { -24, 56 }, ++ { -23, 68 }, { -24, 50 }, { -11, 74 }, { -14, 106 }, ++ { -13, 97 }, { -15, 90 }, { -12, 90 }, { -18, 88 }, ++ { -10, 73 }, { -9, 79 }, { -14, 86 }, { -10, 73 }, ++ { -10, 70 }, { -10, 69 }, { -5, 66 }, { -9, 64 }, ++ { -5, 58 }, { 2, 59 }, { 23, -13 }, { 26, -13 }, ++ { 40, -15 }, { 49, -14 }, { 44, 3 }, { 45, 6 }, ++ { 44, 34 }, { 33, 54 }, { 19, 82 }, { 21, -10 }, ++ { 24, -11 }, { 28, -8 }, { 28, -1 }, { 29, 3 }, ++ { 29, 9 }, { 35, 20 }, { 29, 36 }, { 14, 67 }, ++ { -3, 75 }, { -1, 23 }, { 1, 34 }, { 1, 43 }, ++ { 0, 54 }, { -2, 55 }, { 0, 61 }, { 1, 64 }, ++ { 0, 68 }, { -9, 92 }, { -17, 120 }, { -20, 112 }, ++ { -18, 114 }, { -11, 85 }, { -15, 92 }, { -14, 89 }, ++ { -26, 71 }, { -15, 81 }, { -14, 80 }, { 0, 68 }, ++ { -14, 70 }, { -24, 56 }, { -23, 68 }, { -24, 50 }, ++ { -11, 74 }, { -14, 106 }, { -13, 97 }, { -15, 90 }, ++ { -12, 90 }, { -18, 88 }, { -10, 73 }, { -9, 79 }, ++ { -14, 86 }, { -10, 73 }, { -10, 70 }, { -10, 69 }, ++ { -5, 66 }, { -9, 64 }, { -5, 58 }, { 2, 59 }, ++ { 23, -13 }, { 26, -13 }, { 40, -15 }, { 49, -14 }, ++ { 44, 3 }, { 45, 6 }, { 44, 34 }, { 33, 54 }, ++ { 19, 82 }, { 21, -10 }, { 24, -11 }, { 28, -8 }, ++ { 28, -1 }, { 29, 3 }, { 29, 9 }, { 35, 20 }, ++ { 29, 36 }, { 14, 67 }, { -3, 75 }, { -1, 23 }, ++ { 1, 34 }, { 1, 43 }, { 0, 54 }, { -2, 55 }, ++ { 0, 61 }, { 1, 64 }, { 0, 68 }, { -9, 92 }, ++ { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 }, ++ { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 }, ++ { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 }, ++ { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 }, ++ { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 }, ++ { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 }, ++ { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 }, ++ { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 }, ++ { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 }, ++ { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 }, ++ { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 }, ++ { -6, 93 }, { -6, 84 }, { -8, 79 }, { 0, 66 }, ++ { -1, 71 }, { 0, 62 }, { -2, 60 }, { -2, 59 }, ++ { -5, 75 }, { -3, 62 }, { -4, 58 }, { -9, 66 }, ++ { -1, 79 }, { 0, 71 }, { 3, 68 }, { 10, 44 }, ++ { -7, 62 }, { 15, 36 }, { 14, 40 }, { 16, 27 }, ++ { 12, 29 }, { 1, 44 }, { 20, 36 }, { 18, 32 }, ++ { 5, 42 }, { 1, 48 }, { 10, 62 }, { 17, 46 }, ++ { 9, 64 }, { -12, 104 }, { -11, 97 }, { -16, 96 }, ++ { -7, 88 }, { -8, 85 }, { -7, 85 }, { -9, 85 }, ++ { -13, 88 }, { 4, 66 }, { -3, 77 }, { -3, 76 }, ++ { -6, 76 }, { 10, 58 }, { -1, 76 }, { -1, 83 }, ++ { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 }, ++ { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 }, ++ { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 }, ++ { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 }, ++ { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 }, ++ { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 }, ++ { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 }, ++ { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 }, ++ { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 }, ++ { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 }, ++ { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 }, ++ { 15, 6 }, { 6, 19 }, { 7, 16 }, { 12, 14 }, ++ { 18, 13 }, { 13, 11 }, { 13, 15 }, { 15, 16 }, ++ { 12, 23 }, { 13, 23 }, { 15, 20 }, { 14, 26 }, ++ { 14, 44 }, { 17, 40 }, { 17, 47 }, { 24, 17 }, ++ { 21, 21 }, { 25, 22 }, { 31, 27 }, { 22, 29 }, ++ { 19, 35 }, { 14, 50 }, { 10, 57 }, { 7, 63 }, ++ { -2, 77 }, { -4, 82 }, { -3, 94 }, { 9, 69 }, ++ { -12, 109 }, { 36, -35 }, { 36, -34 }, { 32, -26 }, ++ { 37, -30 }, { 44, -32 }, { 34, -18 }, { 34, -15 }, ++ { 40, -15 }, { 33, -7 }, { 35, -5 }, { 33, 0 }, ++ { 38, 2 }, { 33, 13 }, { 23, 35 }, { 13, 58 }, ++ { -3, 71 }, { -6, 42 }, { -5, 50 }, { -3, 54 }, ++ { -2, 62 }, { 0, 58 }, { 1, 63 }, { -2, 72 }, ++ { -1, 74 }, { -9, 91 }, { -5, 67 }, { -5, 27 }, ++ { -3, 39 }, { -2, 44 }, { 0, 46 }, { -16, 64 }, ++ { -8, 68 }, { -10, 78 }, { -6, 77 }, { -10, 86 }, ++ { -12, 92 }, { -15, 55 }, { -10, 60 }, { -6, 62 }, ++ { -4, 65 }, { -12, 73 }, { -8, 76 }, { -7, 80 }, ++ { -9, 88 }, { -17, 110 }, { -3, 71 }, { -6, 42 }, ++ { -5, 50 }, { -3, 54 }, { -2, 62 }, { 0, 58 }, ++ { 1, 63 }, { -2, 72 }, { -1, 74 }, { -9, 91 }, ++ { -5, 67 }, { -5, 27 }, { -3, 39 }, { -2, 44 }, ++ { 0, 46 }, { -16, 64 }, { -8, 68 }, { -10, 78 }, ++ { -6, 77 }, { -10, 86 }, { -12, 92 }, { -15, 55 }, ++ { -10, 60 }, { -6, 62 }, { -4, 65 }, { -12, 73 }, ++ { -8, 76 }, { -7, 80 }, { -9, 88 }, { -17, 110 }, ++ { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }, ++ { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 }, ++ { -3, 70 }, { -8, 93 }, { -10, 90 }, { -30, 127 } + }; + +-static const int8_t cabac_context_init_PB[3][460][2] = ++static const int8_t cabac_context_init_PB[3][1024][2] = + { + /* i_cabac_init_idc == 0 */ + { +@@ -370,6 +516,149 @@ + { -14, 66 }, { 0, 59 }, { 2, 59 }, { 21, -13 }, + { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 }, + { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 }, ++ ++ /* 460 - 1024 */ ++ { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 }, ++ { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 }, ++ { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }, ++ { -7, 92 }, { -5, 89 }, { -7, 96 }, { -13, 108 }, ++ { -3, 46 }, { -1, 65 }, { -1, 57 }, { -9, 93 }, ++ { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }, ++ { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 }, ++ { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 }, ++ { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 }, ++ { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 }, ++ { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 }, ++ { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 }, ++ { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 }, ++ { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 }, ++ { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 }, ++ { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 }, ++ { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 }, ++ { -2, 85 }, { -6, 78 }, { -1, 75 }, { -7, 77 }, ++ { 2, 54 }, { 5, 50 }, { -3, 68 }, { 1, 50 }, ++ { 6, 42 }, { -4, 81 }, { 1, 63 }, { -4, 70 }, ++ { 0, 67 }, { 2, 57 }, { -2, 76 }, { 11, 35 }, ++ { 4, 64 }, { 1, 61 }, { 11, 35 }, { 18, 25 }, ++ { 12, 24 }, { 13, 29 }, { 13, 36 }, { -10, 93 }, ++ { -7, 73 }, { -2, 73 }, { 13, 46 }, { 9, 49 }, ++ { -7, 100 }, { 9, 53 }, { 2, 53 }, { 5, 53 }, ++ { -2, 61 }, { 0, 56 }, { 0, 56 }, { -13, 63 }, ++ { -5, 60 }, { -1, 62 }, { 4, 57 }, { -6, 69 }, ++ { 4, 57 }, { 14, 39 }, { 4, 51 }, { 13, 68 }, ++ { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 }, ++ { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 }, ++ { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 }, ++ { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 }, ++ { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 }, ++ { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 }, ++ { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 }, ++ { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 }, ++ { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 }, ++ { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 }, ++ { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 }, ++ { 11, 28 }, { 2, 40 }, { 3, 44 }, { 0, 49 }, ++ { 0, 46 }, { 2, 44 }, { 2, 51 }, { 0, 47 }, ++ { 4, 39 }, { 2, 62 }, { 6, 46 }, { 0, 54 }, ++ { 3, 54 }, { 2, 58 }, { 4, 63 }, { 6, 51 }, ++ { 6, 57 }, { 7, 53 }, { 6, 52 }, { 6, 55 }, ++ { 11, 45 }, { 14, 36 }, { 8, 53 }, { -1, 82 }, ++ { 7, 55 }, { -3, 78 }, { 15, 46 }, { 22, 31 }, ++ { -1, 84 }, { 25, 7 }, { 30, -7 }, { 28, 3 }, ++ { 28, 4 }, { 32, 0 }, { 34, -1 }, { 30, 6 }, ++ { 30, 6 }, { 32, 9 }, { 31, 19 }, { 26, 27 }, ++ { 26, 30 }, { 37, 20 }, { 28, 34 }, { 17, 70 }, ++ { -4, 79 }, { -7, 71 }, { -5, 69 }, { -9, 70 }, ++ { -8, 66 }, { -10, 68 }, { -19, 73 }, { -12, 69 }, ++ { -16, 70 }, { -15, 67 }, { -20, 62 }, { -19, 70 }, ++ { -16, 66 }, { -22, 65 }, { -20, 63 }, { -5, 85 }, ++ { -6, 81 }, { -10, 77 }, { -7, 81 }, { -17, 80 }, ++ { -18, 73 }, { -4, 74 }, { -10, 83 }, { -9, 71 }, ++ { -9, 67 }, { -1, 61 }, { -8, 66 }, { -14, 66 }, ++ { 0, 59 }, { 2, 59 }, { 9, -2 }, { 26, -9 }, ++ { 33, -9 }, { 39, -7 }, { 41, -2 }, { 45, 3 }, ++ { 49, 9 }, { 45, 27 }, { 36, 59 }, { 21, -13 }, ++ { 33, -14 }, { 39, -7 }, { 46, -2 }, { 51, 2 }, ++ { 60, 6 }, { 61, 17 }, { 55, 34 }, { 42, 62 }, ++ { -6, 66 }, { -7, 35 }, { -7, 42 }, { -8, 45 }, ++ { -5, 48 }, { -12, 56 }, { -6, 60 }, { -5, 62 }, ++ { -8, 66 }, { -8, 76 }, { -4, 79 }, { -7, 71 }, ++ { -5, 69 }, { -9, 70 }, { -8, 66 }, { -10, 68 }, ++ { -19, 73 }, { -12, 69 }, { -16, 70 }, { -15, 67 }, ++ { -20, 62 }, { -19, 70 }, { -16, 66 }, { -22, 65 }, ++ { -20, 63 }, { -5, 85 }, { -6, 81 }, { -10, 77 }, ++ { -7, 81 }, { -17, 80 }, { -18, 73 }, { -4, 74 }, ++ { -10, 83 }, { -9, 71 }, { -9, 67 }, { -1, 61 }, ++ { -8, 66 }, { -14, 66 }, { 0, 59 }, { 2, 59 }, ++ { 9, -2 }, { 26, -9 }, { 33, -9 }, { 39, -7 }, ++ { 41, -2 }, { 45, 3 }, { 49, 9 }, { 45, 27 }, ++ { 36, 59 }, { 21, -13 }, { 33, -14 }, { 39, -7 }, ++ { 46, -2 }, { 51, 2 }, { 60, 6 }, { 61, 17 }, ++ { 55, 34 }, { 42, 62 }, { -6, 66 }, { -7, 35 }, ++ { -7, 42 }, { -8, 45 }, { -5, 48 }, { -12, 56 }, ++ { -6, 60 }, { -5, 62 }, { -8, 66 }, { -8, 76 }, ++ { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 }, ++ { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 }, ++ { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 }, ++ { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 }, ++ { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 }, ++ { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 }, ++ { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 }, ++ { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 }, ++ { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 }, ++ { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 }, ++ { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 }, ++ { -13, 106 }, { -16, 106 }, { -10, 87 }, { -21, 114 }, ++ { -18, 110 }, { -14, 98 }, { -22, 110 }, { -21, 106 }, ++ { -18, 103 }, { -21, 107 }, { -23, 108 }, { -26, 112 }, ++ { -10, 96 }, { -12, 95 }, { -5, 91 }, { -9, 93 }, ++ { -22, 94 }, { -5, 86 }, { 9, 67 }, { -4, 80 }, ++ { -10, 85 }, { -1, 70 }, { 7, 60 }, { 9, 58 }, ++ { 5, 61 }, { 12, 50 }, { 15, 50 }, { 18, 49 }, ++ { 17, 54 }, { 10, 41 }, { 7, 46 }, { -1, 51 }, ++ { 7, 49 }, { 8, 52 }, { 9, 41 }, { 6, 47 }, ++ { 2, 55 }, { 13, 41 }, { 10, 44 }, { 6, 50 }, ++ { 5, 53 }, { 13, 49 }, { 4, 63 }, { 6, 64 }, ++ { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 }, ++ { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 }, ++ { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 }, ++ { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 }, ++ { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 }, ++ { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 }, ++ { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 }, ++ { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 }, ++ { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 }, ++ { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 }, ++ { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 }, ++ { 14, 11 }, { 11, 14 }, { 9, 11 }, { 18, 11 }, ++ { 21, 9 }, { 23, -2 }, { 32, -15 }, { 32, -15 }, ++ { 34, -21 }, { 39, -23 }, { 42, -33 }, { 41, -31 }, ++ { 46, -28 }, { 38, -12 }, { 21, 29 }, { 45, -24 }, ++ { 53, -45 }, { 48, -26 }, { 65, -43 }, { 43, -19 }, ++ { 39, -10 }, { 30, 9 }, { 18, 26 }, { 20, 27 }, ++ { 0, 57 }, { -14, 82 }, { -5, 75 }, { -19, 97 }, ++ { -35, 125 }, { 27, 0 }, { 28, 0 }, { 31, -4 }, ++ { 27, 6 }, { 34, 8 }, { 30, 10 }, { 24, 22 }, ++ { 33, 19 }, { 22, 32 }, { 26, 31 }, { 21, 41 }, ++ { 26, 44 }, { 23, 47 }, { 16, 65 }, { 14, 71 }, ++ { -6, 76 }, { -2, 44 }, { 0, 45 }, { 0, 52 }, ++ { -3, 64 }, { -2, 59 }, { -4, 70 }, { -4, 75 }, ++ { -8, 82 }, { -17, 102 }, { -9, 77 }, { 3, 24 }, ++ { 0, 42 }, { 0, 48 }, { 0, 55 }, { -6, 59 }, ++ { -7, 71 }, { -12, 83 }, { -11, 87 }, { -30, 119 }, ++ { 1, 58 }, { -3, 29 }, { -1, 36 }, { 1, 38 }, ++ { 2, 43 }, { -6, 55 }, { 0, 58 }, { 0, 64 }, ++ { -3, 74 }, { -10, 90 }, { -6, 76 }, { -2, 44 }, ++ { 0, 45 }, { 0, 52 }, { -3, 64 }, { -2, 59 }, ++ { -4, 70 }, { -4, 75 }, { -8, 82 }, { -17, 102 }, ++ { -9, 77 }, { 3, 24 }, { 0, 42 }, { 0, 48 }, ++ { 0, 55 }, { -6, 59 }, { -7, 71 }, { -12, 83 }, ++ { -11, 87 }, { -30, 119 }, { 1, 58 }, { -3, 29 }, ++ { -1, 36 }, { 1, 38 }, { 2, 43 }, { -6, 55 }, ++ { 0, 58 }, { 0, 64 }, { -3, 74 }, { -10, 90 }, ++ { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }, ++ { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 }, ++ { -3, 74 }, { -9, 92 }, { -8, 87 }, { -23, 126 } + }, + + /* i_cabac_init_idc == 1 */ +@@ -526,6 +815,149 @@ + { -9, 60 }, { 1, 54 }, { 2, 58 }, { 17, -10 }, + { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, + { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, ++ ++ /* 460 - 1024 */ ++ { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 }, ++ { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 }, ++ { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }, ++ { 0, 80 }, { -5, 89 }, { -7, 94 }, { -4, 92 }, ++ { 0, 39 }, { 0, 65 }, { -15, 84 }, { -35, 127 }, ++ { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }, ++ { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 }, ++ { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 }, ++ { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 }, ++ { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 }, ++ { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 }, ++ { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 }, ++ { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 }, ++ { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 }, ++ { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 }, ++ { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 }, ++ { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 }, ++ { -13, 103 }, { -13, 91 }, { -9, 89 }, { -14, 92 }, ++ { -8, 76 }, { -12, 87 }, { -23, 110 }, { -24, 105 }, ++ { -10, 78 }, { -20, 112 }, { -17, 99 }, { -78, 127 }, ++ { -70, 127 }, { -50, 127 }, { -46, 127 }, { -4, 66 }, ++ { -5, 78 }, { -4, 71 }, { -8, 72 }, { 2, 59 }, ++ { -1, 55 }, { -7, 70 }, { -6, 75 }, { -8, 89 }, ++ { -34, 119 }, { -3, 75 }, { 32, 20 }, { 30, 22 }, ++ { -44, 127 }, { 0, 54 }, { -5, 61 }, { 0, 58 }, ++ { -1, 60 }, { -3, 61 }, { -8, 67 }, { -25, 84 }, ++ { -14, 74 }, { -5, 65 }, { 5, 52 }, { 2, 57 }, ++ { 0, 61 }, { -9, 69 }, { -11, 70 }, { 18, 55 }, ++ { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 }, ++ { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 }, ++ { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 }, ++ { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 }, ++ { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 }, ++ { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 }, ++ { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 }, ++ { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 }, ++ { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 }, ++ { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 }, ++ { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 }, ++ { 4, 45 }, { 10, 28 }, { 10, 31 }, { 33, -11 }, ++ { 52, -43 }, { 18, 15 }, { 28, 0 }, { 35, -22 }, ++ { 38, -25 }, { 34, 0 }, { 39, -18 }, { 32, -12 }, ++ { 102, -94 }, { 0, 0 }, { 56, -15 }, { 33, -4 }, ++ { 29, 10 }, { 37, -5 }, { 51, -29 }, { 39, -9 }, ++ { 52, -34 }, { 69, -58 }, { 67, -63 }, { 44, -5 }, ++ { 32, 7 }, { 55, -29 }, { 32, 1 }, { 0, 0 }, ++ { 27, 36 }, { 33, -25 }, { 34, -30 }, { 36, -28 }, ++ { 38, -28 }, { 38, -27 }, { 34, -18 }, { 35, -16 }, ++ { 34, -14 }, { 32, -8 }, { 37, -6 }, { 35, 0 }, ++ { 30, 10 }, { 28, 18 }, { 26, 25 }, { 29, 41 }, ++ { -5, 85 }, { -6, 81 }, { -10, 77 }, { -7, 81 }, ++ { -17, 80 }, { -18, 73 }, { -4, 74 }, { -10, 83 }, ++ { -9, 71 }, { -9, 67 }, { -1, 61 }, { -8, 66 }, ++ { -14, 66 }, { 0, 59 }, { 2, 59 }, { -3, 81 }, ++ { -3, 76 }, { -7, 72 }, { -6, 78 }, { -12, 72 }, ++ { -14, 68 }, { -3, 70 }, { -6, 76 }, { -5, 66 }, ++ { -5, 62 }, { 0, 57 }, { -4, 61 }, { -9, 60 }, ++ { 1, 54 }, { 2, 58 }, { 17, -10 }, { 32, -13 }, ++ { 42, -9 }, { 49, -5 }, { 53, 0 }, { 64, 3 }, ++ { 68, 10 }, { 66, 27 }, { 47, 57 }, { 17, -10 }, ++ { 32, -13 }, { 42, -9 }, { 49, -5 }, { 53, 0 }, ++ { 64, 3 }, { 68, 10 }, { 66, 27 }, { 47, 57 }, ++ { -5, 71 }, { 0, 24 }, { -1, 36 }, { -2, 42 }, ++ { -2, 52 }, { -9, 57 }, { -6, 63 }, { -4, 65 }, ++ { -4, 67 }, { -7, 82 }, { -5, 85 }, { -6, 81 }, ++ { -10, 77 }, { -7, 81 }, { -17, 80 }, { -18, 73 }, ++ { -4, 74 }, { -10, 83 }, { -9, 71 }, { -9, 67 }, ++ { -1, 61 }, { -8, 66 }, { -14, 66 }, { 0, 59 }, ++ { 2, 59 }, { -3, 81 }, { -3, 76 }, { -7, 72 }, ++ { -6, 78 }, { -12, 72 }, { -14, 68 }, { -3, 70 }, ++ { -6, 76 }, { -5, 66 }, { -5, 62 }, { 0, 57 }, ++ { -4, 61 }, { -9, 60 }, { 1, 54 }, { 2, 58 }, ++ { 17, -10 }, { 32, -13 }, { 42, -9 }, { 49, -5 }, ++ { 53, 0 }, { 64, 3 }, { 68, 10 }, { 66, 27 }, ++ { 47, 57 }, { 17, -10 }, { 32, -13 }, { 42, -9 }, ++ { 49, -5 }, { 53, 0 }, { 64, 3 }, { 68, 10 }, ++ { 66, 27 }, { 47, 57 }, { -5, 71 }, { 0, 24 }, ++ { -1, 36 }, { -2, 42 }, { -2, 52 }, { -9, 57 }, ++ { -6, 63 }, { -4, 65 }, { -4, 67 }, { -7, 82 }, ++ { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 }, ++ { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 }, ++ { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 }, ++ { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 }, ++ { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 }, ++ { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 }, ++ { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 }, ++ { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 }, ++ { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 }, ++ { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 }, ++ { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 }, ++ { -21, 126 }, { -23, 124 }, { -20, 110 }, { -26, 126 }, ++ { -25, 124 }, { -17, 105 }, { -27, 121 }, { -27, 117 }, ++ { -17, 102 }, { -26, 117 }, { -27, 116 }, { -33, 122 }, ++ { -10, 95 }, { -14, 100 }, { -8, 95 }, { -17, 111 }, ++ { -28, 114 }, { -6, 89 }, { -2, 80 }, { -4, 82 }, ++ { -9, 85 }, { -8, 81 }, { -1, 72 }, { 5, 64 }, ++ { 1, 67 }, { 9, 56 }, { 0, 69 }, { 1, 69 }, ++ { 7, 69 }, { -7, 69 }, { -6, 67 }, { -16, 77 }, ++ { -2, 64 }, { 2, 61 }, { -6, 67 }, { -3, 64 }, ++ { 2, 57 }, { -3, 65 }, { -3, 66 }, { 0, 62 }, ++ { 9, 51 }, { -1, 66 }, { -2, 71 }, { -2, 75 }, ++ { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 }, ++ { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 }, ++ { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 }, ++ { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 }, ++ { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 }, ++ { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 }, ++ { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 }, ++ { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 }, ++ { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 }, ++ { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 }, ++ { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 }, ++ { 19, -6 }, { 18, -6 }, { 14, 0 }, { 26, -12 }, ++ { 31, -16 }, { 33, -25 }, { 33, -22 }, { 37, -28 }, ++ { 39, -30 }, { 42, -30 }, { 47, -42 }, { 45, -36 }, ++ { 49, -34 }, { 41, -17 }, { 32, 9 }, { 69, -71 }, ++ { 63, -63 }, { 66, -64 }, { 77, -74 }, { 54, -39 }, ++ { 52, -35 }, { 41, -10 }, { 36, 0 }, { 40, -1 }, ++ { 30, 14 }, { 28, 26 }, { 23, 37 }, { 12, 55 }, ++ { 11, 65 }, { 37, -33 }, { 39, -36 }, { 40, -37 }, ++ { 38, -30 }, { 46, -33 }, { 42, -30 }, { 40, -24 }, ++ { 49, -29 }, { 38, -12 }, { 40, -10 }, { 38, -3 }, ++ { 46, -5 }, { 31, 20 }, { 29, 30 }, { 25, 44 }, ++ { -23, 112 }, { -15, 71 }, { -7, 61 }, { 0, 53 }, ++ { -5, 66 }, { -11, 77 }, { -9, 80 }, { -9, 84 }, ++ { -10, 87 }, { -34, 127 }, { -21, 101 }, { -3, 39 }, ++ { -5, 53 }, { -7, 61 }, { -11, 75 }, { -15, 77 }, ++ { -17, 91 }, { -25, 107 }, { -25, 111 }, { -28, 122 }, ++ { -11, 76 }, { -10, 44 }, { -10, 52 }, { -10, 57 }, ++ { -9, 58 }, { -16, 72 }, { -7, 69 }, { -4, 69 }, ++ { -5, 74 }, { -9, 86 }, { -23, 112 }, { -15, 71 }, ++ { -7, 61 }, { 0, 53 }, { -5, 66 }, { -11, 77 }, ++ { -9, 80 }, { -9, 84 }, { -10, 87 }, { -34, 127 }, ++ { -21, 101 }, { -3, 39 }, { -5, 53 }, { -7, 61 }, ++ { -11, 75 }, { -15, 77 }, { -17, 91 }, { -25, 107 }, ++ { -25, 111 }, { -28, 122 }, { -11, 76 }, { -10, 44 }, ++ { -10, 52 }, { -10, 57 }, { -9, 58 }, { -16, 72 }, ++ { -7, 69 }, { -4, 69 }, { -5, 74 }, { -9, 86 }, ++ { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }, ++ { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 }, ++ { -2, 73 }, { -12, 104 }, { -9, 91 }, { -31, 127 } + }, + + /* i_cabac_init_idc == 2 */ +@@ -682,6 +1114,149 @@ + { -14, 59 }, { -9, 52 }, { -11, 68 }, { 9, -2 }, + { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, + { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, ++ ++ /* 460 - 1024 */ ++ { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 }, ++ { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 }, ++ { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }, ++ { 11, 80 }, { 5, 76 }, { 2, 84 }, { 5, 78 }, ++ { -6, 55 }, { 4, 61 }, { -14, 83 }, { -37, 127 }, ++ { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }, ++ { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 }, ++ { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 }, ++ { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 }, ++ { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 }, ++ { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 }, ++ { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 }, ++ { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 }, ++ { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 }, ++ { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 }, ++ { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 }, ++ { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 }, ++ { -4, 86 }, { -12, 88 }, { -5, 82 }, { -3, 72 }, ++ { -4, 67 }, { -8, 72 }, { -16, 89 }, { -9, 69 }, ++ { -1, 59 }, { 5, 66 }, { 4, 57 }, { -4, 71 }, ++ { -2, 71 }, { 2, 58 }, { -1, 74 }, { -4, 44 }, ++ { -1, 69 }, { 0, 62 }, { -7, 51 }, { -4, 47 }, ++ { -6, 42 }, { -3, 41 }, { -6, 53 }, { 8, 76 }, ++ { -9, 78 }, { -11, 83 }, { 9, 52 }, { 0, 67 }, ++ { -5, 90 }, { 1, 67 }, { -15, 72 }, { -5, 75 }, ++ { -8, 80 }, { -21, 83 }, { -21, 64 }, { -13, 31 }, ++ { -25, 64 }, { -29, 94 }, { 9, 75 }, { 17, 63 }, ++ { -8, 74 }, { -5, 35 }, { -2, 27 }, { 13, 91 }, ++ { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 }, ++ { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 }, ++ { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 }, ++ { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 }, ++ { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 }, ++ { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 }, ++ { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 }, ++ { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 }, ++ { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 }, ++ { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 }, ++ { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 }, ++ { 4, 39 }, { 0, 42 }, { 7, 34 }, { 11, 29 }, ++ { 8, 31 }, { 6, 37 }, { 7, 42 }, { 3, 40 }, ++ { 8, 33 }, { 13, 43 }, { 13, 36 }, { 4, 47 }, ++ { 3, 55 }, { 2, 58 }, { 6, 60 }, { 8, 44 }, ++ { 11, 44 }, { 14, 42 }, { 7, 48 }, { 4, 56 }, ++ { 4, 52 }, { 13, 37 }, { 9, 49 }, { 19, 58 }, ++ { 10, 48 }, { 12, 45 }, { 0, 69 }, { 20, 33 }, ++ { 8, 63 }, { 35, -18 }, { 33, -25 }, { 28, -3 }, ++ { 24, 10 }, { 27, 0 }, { 34, -14 }, { 52, -44 }, ++ { 39, -24 }, { 19, 17 }, { 31, 25 }, { 36, 29 }, ++ { 24, 33 }, { 34, 15 }, { 30, 20 }, { 22, 73 }, ++ { -3, 78 }, { -8, 74 }, { -9, 72 }, { -10, 72 }, ++ { -18, 75 }, { -12, 71 }, { -11, 63 }, { -5, 70 }, ++ { -17, 75 }, { -14, 72 }, { -16, 67 }, { -8, 53 }, ++ { -14, 59 }, { -9, 52 }, { -11, 68 }, { -3, 78 }, ++ { -8, 74 }, { -9, 72 }, { -10, 72 }, { -18, 75 }, ++ { -12, 71 }, { -11, 63 }, { -5, 70 }, { -17, 75 }, ++ { -14, 72 }, { -16, 67 }, { -8, 53 }, { -14, 59 }, ++ { -9, 52 }, { -11, 68 }, { 9, -2 }, { 30, -10 }, ++ { 31, -4 }, { 33, -1 }, { 33, 7 }, { 31, 12 }, ++ { 37, 23 }, { 31, 38 }, { 20, 64 }, { 9, -2 }, ++ { 30, -10 }, { 31, -4 }, { 33, -1 }, { 33, 7 }, ++ { 31, 12 }, { 37, 23 }, { 31, 38 }, { 20, 64 }, ++ { -9, 71 }, { -7, 37 }, { -8, 44 }, { -11, 49 }, ++ { -10, 56 }, { -12, 59 }, { -8, 63 }, { -9, 67 }, ++ { -6, 68 }, { -10, 79 }, { -3, 78 }, { -8, 74 }, ++ { -9, 72 }, { -10, 72 }, { -18, 75 }, { -12, 71 }, ++ { -11, 63 }, { -5, 70 }, { -17, 75 }, { -14, 72 }, ++ { -16, 67 }, { -8, 53 }, { -14, 59 }, { -9, 52 }, ++ { -11, 68 }, { -3, 78 }, { -8, 74 }, { -9, 72 }, ++ { -10, 72 }, { -18, 75 }, { -12, 71 }, { -11, 63 }, ++ { -5, 70 }, { -17, 75 }, { -14, 72 }, { -16, 67 }, ++ { -8, 53 }, { -14, 59 }, { -9, 52 }, { -11, 68 }, ++ { 9, -2 }, { 30, -10 }, { 31, -4 }, { 33, -1 }, ++ { 33, 7 }, { 31, 12 }, { 37, 23 }, { 31, 38 }, ++ { 20, 64 }, { 9, -2 }, { 30, -10 }, { 31, -4 }, ++ { 33, -1 }, { 33, 7 }, { 31, 12 }, { 37, 23 }, ++ { 31, 38 }, { 20, 64 }, { -9, 71 }, { -7, 37 }, ++ { -8, 44 }, { -11, 49 }, { -10, 56 }, { -12, 59 }, ++ { -8, 63 }, { -9, 67 }, { -6, 68 }, { -10, 79 }, ++ { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 }, ++ { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 }, ++ { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 }, ++ { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 }, ++ { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 }, ++ { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 }, ++ { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 }, ++ { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 }, ++ { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 }, ++ { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 }, ++ { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 }, ++ { -22, 127 }, { -25, 127 }, { -25, 120 }, { -27, 127 }, ++ { -19, 114 }, { -23, 117 }, { -25, 118 }, { -26, 117 }, ++ { -24, 113 }, { -28, 118 }, { -31, 120 }, { -37, 124 }, ++ { -10, 94 }, { -15, 102 }, { -10, 99 }, { -13, 106 }, ++ { -50, 127 }, { -5, 92 }, { 17, 57 }, { -5, 86 }, ++ { -13, 94 }, { -12, 91 }, { -2, 77 }, { 0, 71 }, ++ { -1, 73 }, { 4, 64 }, { -7, 81 }, { 5, 64 }, ++ { 15, 57 }, { 1, 67 }, { 0, 68 }, { -10, 67 }, ++ { 1, 68 }, { 0, 77 }, { 2, 64 }, { 0, 68 }, ++ { -5, 78 }, { 7, 55 }, { 5, 59 }, { 2, 65 }, ++ { 14, 54 }, { 15, 44 }, { 5, 60 }, { 2, 70 }, ++ { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 }, ++ { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 }, ++ { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 }, ++ { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 }, ++ { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 }, ++ { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 }, ++ { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 }, ++ { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 }, ++ { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 }, ++ { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 }, ++ { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 }, ++ { 17, -13 }, { 16, -9 }, { 17, -12 }, { 27, -21 }, ++ { 37, -30 }, { 41, -40 }, { 42, -41 }, { 48, -47 }, ++ { 39, -32 }, { 46, -40 }, { 52, -51 }, { 46, -41 }, ++ { 52, -39 }, { 43, -19 }, { 32, 11 }, { 61, -55 }, ++ { 56, -46 }, { 62, -50 }, { 81, -67 }, { 45, -20 }, ++ { 35, -2 }, { 28, 15 }, { 34, 1 }, { 39, 1 }, ++ { 30, 17 }, { 20, 38 }, { 18, 45 }, { 15, 54 }, ++ { 0, 79 }, { 36, -16 }, { 37, -14 }, { 37, -17 }, ++ { 32, 1 }, { 34, 15 }, { 29, 15 }, { 24, 25 }, ++ { 34, 22 }, { 31, 16 }, { 35, 18 }, { 31, 28 }, ++ { 33, 41 }, { 36, 28 }, { 27, 47 }, { 21, 62 }, ++ { -24, 115 }, { -22, 82 }, { -9, 62 }, { 0, 53 }, ++ { 0, 59 }, { -14, 85 }, { -13, 89 }, { -13, 94 }, ++ { -11, 92 }, { -29, 127 }, { -21, 100 }, { -14, 57 }, ++ { -12, 67 }, { -11, 71 }, { -10, 77 }, { -21, 85 }, ++ { -16, 88 }, { -23, 104 }, { -15, 98 }, { -37, 127 }, ++ { -10, 82 }, { -8, 48 }, { -8, 61 }, { -8, 66 }, ++ { -7, 70 }, { -14, 75 }, { -10, 79 }, { -9, 83 }, ++ { -12, 92 }, { -18, 108 }, { -24, 115 }, { -22, 82 }, ++ { -9, 62 }, { 0, 53 }, { 0, 59 }, { -14, 85 }, ++ { -13, 89 }, { -13, 94 }, { -11, 92 }, { -29, 127 }, ++ { -21, 100 }, { -14, 57 }, { -12, 67 }, { -11, 71 }, ++ { -10, 77 }, { -21, 85 }, { -16, 88 }, { -23, 104 }, ++ { -15, 98 }, { -37, 127 }, { -10, 82 }, { -8, 48 }, ++ { -8, 61 }, { -8, 66 }, { -7, 70 }, { -14, 75 }, ++ { -10, 79 }, { -9, 83 }, { -12, 92 }, { -18, 108 }, ++ { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }, ++ { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 }, ++ { -5, 79 }, { -11, 104 }, { -11, 91 }, { -30, 127 } + } + }; + +@@ -689,13 +1264,14 @@ + MpegEncContext * const s = &h->s; + int i; + const int8_t (*tab)[2]; ++ const int slice_qp = av_clip(s->qscale - 6*(h->sps.bit_depth_luma-8), 0, 51); + +- if( h->slice_type_nos == FF_I_TYPE ) tab = cabac_context_init_I; ++ if( h->slice_type_nos == AV_PICTURE_TYPE_I ) tab = cabac_context_init_I; + else tab = cabac_context_init_PB[h->cabac_init_idc]; + + /* calculate pre-state */ +- for( i= 0; i < 460; i++ ) { +- int pre = 2*(((tab[i][0] * s->qscale) >>4 ) + tab[i][1]) - 127; ++ for( i= 0; i < 1024; i++ ) { ++ int pre = 2*(((tab[i][0] * slice_qp) >>4 ) + tab[i][1]) - 127; + + pre^= pre>>31; + if(pre > 124) +@@ -711,8 +1287,8 @@ + + unsigned long ctx = 0; + +- ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.mb_type[mba_xy]>>7)&(h->slice_table[mba_xy] == h->slice_num); +- ctx += (s->current_picture.mb_type[mbb_xy]>>7)&(h->slice_table[mbb_xy] == h->slice_num); ++ ctx += h->mb_field_decoding_flag & !!s->mb_x; //for FMO:(s->current_picture.f.mb_type[mba_xy] >> 7) & (h->slice_table[mba_xy] == h->slice_num); ++ ctx += (s->current_picture.f.mb_type[mbb_xy] >> 7) & (h->slice_table[mbb_xy] == h->slice_num); + + return get_cabac_noinline( &h->cabac, &(h->cabac_state+70)[ctx] ); + } +@@ -723,9 +1299,9 @@ + + if(intra_slice){ + int ctx=0; +- if( h->left_type[0] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) ++ if( h->left_type[LTOP] & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) + ctx++; +- if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) ++ if( h->top_type & (MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)) + ctx++; + if( get_cabac_noinline( &h->cabac, &state[ctx] ) == 0 ) + return 0; /* I4x4 */ +@@ -757,13 +1333,13 @@ + mba_xy = mb_xy - 1; + if( (mb_y&1) + && h->slice_table[mba_xy] == h->slice_num +- && MB_FIELD == !!IS_INTERLACED( s->current_picture.mb_type[mba_xy] ) ) ++ && MB_FIELD == !!IS_INTERLACED( s->current_picture.f.mb_type[mba_xy] ) ) + mba_xy += s->mb_stride; + if( MB_FIELD ){ + mbb_xy = mb_xy - s->mb_stride; + if( !(mb_y&1) + && h->slice_table[mbb_xy] == h->slice_num +- && IS_INTERLACED( s->current_picture.mb_type[mbb_xy] ) ) ++ && IS_INTERLACED( s->current_picture.f.mb_type[mbb_xy] ) ) + mbb_xy -= s->mb_stride; + }else + mbb_xy = mb_x + (mb_y-1)*s->mb_stride; +@@ -773,12 +1349,12 @@ + mbb_xy = mb_xy - (s->mb_stride << FIELD_PICTURE); + } + +- if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mba_xy] )) ++ if( h->slice_table[mba_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mba_xy] )) + ctx++; +- if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.mb_type[mbb_xy] )) ++ if( h->slice_table[mbb_xy] == h->slice_num && !IS_SKIP( s->current_picture.f.mb_type[mbb_xy] )) + ctx++; + +- if( h->slice_type_nos == FF_B_TYPE ) ++ if( h->slice_type_nos == AV_PICTURE_TYPE_B ) + ctx += 13; + return get_cabac_noinline( &h->cabac, &h->cabac_state[11+ctx] ); + } +@@ -803,10 +1379,10 @@ + int ctx = 0; + + /* No need to test for IS_INTRA4x4 and IS_INTRA16x16, as we set chroma_pred_mode_table to 0 */ +- if( h->left_type[0] && h->chroma_pred_mode_table[mba_xy] != 0 ) ++ if( h->left_type[LTOP] && h->chroma_pred_mode_table[mba_xy] != 0 ) + ctx++; + +- if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 ) ++ if( h->top_type && h->chroma_pred_mode_table[mbb_xy] != 0 ) + ctx++; + + if( get_cabac_noinline( &h->cabac, &h->cabac_state[64+ctx] ) == 0 ) +@@ -887,7 +1463,7 @@ + int ref = 0; + int ctx = 0; + +- if( h->slice_type_nos == FF_B_TYPE) { ++ if( h->slice_type_nos == AV_PICTURE_TYPE_B) { + if( refa > 0 && !(h->direct_cache[scan8[n] - 1]&(MB_TYPE_DIRECT2>>1)) ) + ctx++; + if( refb > 0 && !(h->direct_cache[scan8[n] - 8]&(MB_TYPE_DIRECT2>>1)) ) +@@ -956,21 +1532,22 @@ + my += decode_cabac_mb_mvd( h, 47, amvd1, &mpy );\ + } + +-static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int is_dc ) { ++static av_always_inline int get_cabac_cbf_ctx( H264Context *h, int cat, int idx, int max_coeff, int is_dc ) { + int nza, nzb; + int ctx = 0; ++ static const uint16_t base_ctx[14] = {85,89,93,97,101,1012,460,464,468,1016,472,476,480,1020}; + + if( is_dc ) { +- if( cat == 0 ) { +- nza = h->left_cbp&0x100; +- nzb = h-> top_cbp&0x100; +- } else { ++ if( cat == 3 ) { + idx -= CHROMA_DC_BLOCK_INDEX; + nza = (h->left_cbp>>(6+idx))&0x01; + nzb = (h-> top_cbp>>(6+idx))&0x01; ++ } else { ++ idx -= LUMA_DC_BLOCK_INDEX; ++ nza = h->left_cbp&(0x100< top_cbp&(0x100<non_zero_count_cache[scan8[idx] - 1]; + nzb = h->non_zero_count_cache[scan8[idx] - 8]; + } +@@ -981,7 +1558,7 @@ + if( nzb > 0 ) + ctx += 2; + +- return ctx + 4 * cat; ++ return base_ctx[cat] + ctx; + } + + DECLARE_ASM_CONST(1, uint8_t, last_coeff_flag_offset_8x8)[63] = { +@@ -991,17 +1568,22 @@ + 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8 + }; + +-static av_always_inline void decode_cabac_residual_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff, int is_dc ) { +- static const int significant_coeff_flag_offset[2][6] = { +- { 105+0, 105+15, 105+29, 105+44, 105+47, 402 }, +- { 277+0, 277+15, 277+29, 277+44, 277+47, 436 } ++static av_always_inline void ++decode_cabac_residual_internal(H264Context *h, DCTELEM *block, ++ int cat, int n, const uint8_t *scantable, ++ const uint32_t *qmul, int max_coeff, ++ int is_dc, int chroma422) ++{ ++ static const int significant_coeff_flag_offset[2][14] = { ++ { 105+0, 105+15, 105+29, 105+44, 105+47, 402, 484+0, 484+15, 484+29, 660, 528+0, 528+15, 528+29, 718 }, ++ { 277+0, 277+15, 277+29, 277+44, 277+47, 436, 776+0, 776+15, 776+29, 675, 820+0, 820+15, 820+29, 733 } + }; +- static const int last_coeff_flag_offset[2][6] = { +- { 166+0, 166+15, 166+29, 166+44, 166+47, 417 }, +- { 338+0, 338+15, 338+29, 338+44, 338+47, 451 } ++ static const int last_coeff_flag_offset[2][14] = { ++ { 166+0, 166+15, 166+29, 166+44, 166+47, 417, 572+0, 572+15, 572+29, 690, 616+0, 616+15, 616+29, 748 }, ++ { 338+0, 338+15, 338+29, 338+44, 338+47, 451, 864+0, 864+15, 864+29, 699, 908+0, 908+15, 908+29, 757 } + }; +- static const int coeff_abs_level_m1_offset[6] = { +- 227+0, 227+10, 227+20, 227+30, 227+39, 426 ++ static const int coeff_abs_level_m1_offset[14] = { ++ 227+0, 227+10, 227+20, 227+30, 227+39, 426, 952+0, 952+10, 952+20, 708, 982+0, 982+10, 982+20, 766 + }; + static const uint8_t significant_coeff_flag_offset_8x8[2][63] = { + { 0, 1, 2, 3, 4, 5, 5, 4, 4, 3, 3, 4, 4, 4, 5, 5, +@@ -1013,12 +1595,16 @@ + 9, 9,10,10, 8,11,12,11, 9, 9,10,10, 8,13,13, 9, + 9,10,10, 8,13,13, 9, 9,10,10,14,14,14,14,14 } + }; ++ static const uint8_t sig_coeff_offset_dc[7] = { 0, 0, 1, 1, 2, 2, 2 }; + /* node ctx: 0..3: abslevel1 (with abslevelgt1 == 0). + * 4..7: abslevelgt1 + 3 (and abslevel1 doesn't matter). + * map node ctx => cabac ctx for level=1 */ + static const uint8_t coeff_abs_level1_ctx[8] = { 1, 2, 3, 4, 0, 0, 0, 0 }; + /* map node ctx => cabac ctx for level>1 */ +- static const uint8_t coeff_abs_levelgt1_ctx[8] = { 5, 5, 5, 5, 6, 7, 8, 9 }; ++ static const uint8_t coeff_abs_levelgt1_ctx[2][8] = { ++ { 5, 5, 5, 5, 6, 7, 8, 9 }, ++ { 5, 5, 5, 5, 6, 7, 8, 8 }, // 422/dc case ++ }; + static const uint8_t coeff_abs_level_transition[2][8] = { + /* update node ctx after decoding a level=1 */ + { 1, 2, 3, 3, 4, 5, 6, 7 }, +@@ -1056,7 +1642,7 @@ + abs_level_m1_ctx_base = h->cabac_state + + coeff_abs_level_m1_offset[cat]; + +- if( !is_dc && cat == 5 ) { ++ if( !is_dc && max_coeff == 64 ) { + #define DECODE_SIGNIFICANCE( coefs, sig_off, last_off ) \ + for(last= 0; last < coefs; last++) { \ + uint8_t *sig_ctx = significant_coeff_ctx_base + sig_off; \ +@@ -1073,74 +1659,92 @@ + index[coeff_count++] = last;\ + } + const uint8_t *sig_off = significant_coeff_flag_offset_8x8[MB_FIELD]; +-#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) +- coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, sig_off); ++#if ARCH_X86 && HAVE_7REGS && !defined(BROKEN_RELOCATIONS) ++ coeff_count= decode_significance_8x8_x86(CC, significant_coeff_ctx_base, index, ++ last_coeff_ctx_base, sig_off); + } else { +- coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index); ++ if (is_dc && chroma422) { // dc 422 ++ DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]); ++ } else { ++ coeff_count= decode_significance_x86(CC, max_coeff, significant_coeff_ctx_base, index, ++ last_coeff_ctx_base-significant_coeff_ctx_base); ++ } + #else + DECODE_SIGNIFICANCE( 63, sig_off[last], last_coeff_flag_offset_8x8[last] ); + } else { +- DECODE_SIGNIFICANCE( max_coeff - 1, last, last ); ++ if (is_dc && chroma422) { // dc 422 ++ DECODE_SIGNIFICANCE(7, sig_coeff_offset_dc[last], sig_coeff_offset_dc[last]); ++ } else { ++ DECODE_SIGNIFICANCE(max_coeff - 1, last, last); ++ } + #endif + } + assert(coeff_count > 0); + + if( is_dc ) { +- if( cat == 0 ) +- h->cbp_table[h->mb_xy] |= 0x100; +- else ++ if( cat == 3 ) + h->cbp_table[h->mb_xy] |= 0x40 << (n - CHROMA_DC_BLOCK_INDEX); ++ else ++ h->cbp_table[h->mb_xy] |= 0x100 << (n - LUMA_DC_BLOCK_INDEX); + h->non_zero_count_cache[scan8[n]] = coeff_count; + } else { +- if( cat == 5 ) ++ if( max_coeff == 64 ) + fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, coeff_count, 1); + else { +- assert( cat == 1 || cat == 2 || cat == 4 ); ++ assert( cat == 1 || cat == 2 || cat == 4 || cat == 7 || cat == 8 || cat == 11 || cat == 12 ); + h->non_zero_count_cache[scan8[n]] = coeff_count; + } + } + +- do { +- uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; + +- int j= scantable[index[--coeff_count]]; ++#define STORE_BLOCK(type) \ ++ do { \ ++ uint8_t *ctx = coeff_abs_level1_ctx[node_ctx] + abs_level_m1_ctx_base; \ ++ \ ++ int j= scantable[index[--coeff_count]]; \ ++ \ ++ if( get_cabac( CC, ctx ) == 0 ) { \ ++ node_ctx = coeff_abs_level_transition[0][node_ctx]; \ ++ if( is_dc ) { \ ++ ((type*)block)[j] = get_cabac_bypass_sign( CC, -1); \ ++ }else{ \ ++ ((type*)block)[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; \ ++ } \ ++ } else { \ ++ int coeff_abs = 2; \ ++ ctx = coeff_abs_levelgt1_ctx[is_dc && chroma422][node_ctx] + abs_level_m1_ctx_base; \ ++ node_ctx = coeff_abs_level_transition[1][node_ctx]; \ ++\ ++ while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { \ ++ coeff_abs++; \ ++ } \ ++\ ++ if( coeff_abs >= 15 ) { \ ++ int j = 0; \ ++ while( get_cabac_bypass( CC ) ) { \ ++ j++; \ ++ } \ ++\ ++ coeff_abs=1; \ ++ while( j-- ) { \ ++ coeff_abs += coeff_abs + get_cabac_bypass( CC ); \ ++ } \ ++ coeff_abs+= 14; \ ++ } \ ++\ ++ if( is_dc ) { \ ++ ((type*)block)[j] = get_cabac_bypass_sign( CC, -coeff_abs ); \ ++ }else{ \ ++ ((type*)block)[j] = ((int)(get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32)) >> 6; \ ++ } \ ++ } \ ++ } while ( coeff_count ); + +- if( get_cabac( CC, ctx ) == 0 ) { +- node_ctx = coeff_abs_level_transition[0][node_ctx]; +- if( is_dc ) { +- block[j] = get_cabac_bypass_sign( CC, -1); +- }else{ +- block[j] = (get_cabac_bypass_sign( CC, -qmul[j]) + 32) >> 6; +- } ++ if (h->pixel_shift) { ++ STORE_BLOCK(int32_t) + } else { +- int coeff_abs = 2; +- ctx = coeff_abs_levelgt1_ctx[node_ctx] + abs_level_m1_ctx_base; +- node_ctx = coeff_abs_level_transition[1][node_ctx]; +- +- while( coeff_abs < 15 && get_cabac( CC, ctx ) ) { +- coeff_abs++; +- } +- +- if( coeff_abs >= 15 ) { +- int j = 0; +- while( get_cabac_bypass( CC ) ) { +- j++; +- } +- +- coeff_abs=1; +- while( j-- ) { +- coeff_abs += coeff_abs + get_cabac_bypass( CC ); +- } +- coeff_abs+= 14; +- } +- +- if( is_dc ) { +- block[j] = get_cabac_bypass_sign( CC, -coeff_abs ); +- }else{ +- block[j] = (get_cabac_bypass_sign( CC, -coeff_abs ) * qmul[j] + 32) >> 6; +- } ++ STORE_BLOCK(int16_t) + } +- } while( coeff_count ); + #ifdef CABAC_ON_STACK + h->cabac.range = cc.range ; + h->cabac.low = cc.low ; +@@ -1150,11 +1754,18 @@ + } + + static void decode_cabac_residual_dc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) { +- decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1); ++ decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 0); ++} ++ ++static void decode_cabac_residual_dc_internal_422(H264Context *h, DCTELEM *block, ++ int cat, int n, const uint8_t *scantable, ++ int max_coeff) ++{ ++ decode_cabac_residual_internal(h, block, cat, n, scantable, NULL, max_coeff, 1, 1); + } + + static void decode_cabac_residual_nondc_internal( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { +- decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0); ++ decode_cabac_residual_internal(h, block, cat, n, scantable, qmul, max_coeff, 0, 0); + } + + /* cat: 0-> DC 16x16 n = 0 +@@ -1171,36 +1782,105 @@ + + static av_always_inline void decode_cabac_residual_dc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, int max_coeff ) { + /* read coded block flag */ +- if( get_cabac( &h->cabac, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n, 1 ) ] ) == 0 ) { ++ if( get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 1 ) ] ) == 0 ) { + h->non_zero_count_cache[scan8[n]] = 0; + return; + } + decode_cabac_residual_dc_internal( h, block, cat, n, scantable, max_coeff ); + } + +-static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { ++static av_always_inline void ++decode_cabac_residual_dc_422(H264Context *h, DCTELEM *block, ++ int cat, int n, const uint8_t *scantable, ++ int max_coeff) ++{ + /* read coded block flag */ +- if( cat != 5 && get_cabac( &h->cabac, &h->cabac_state[85 + get_cabac_cbf_ctx( h, cat, n, 0 ) ] ) == 0 ) { ++ if (get_cabac(&h->cabac, &h->cabac_state[get_cabac_cbf_ctx(h, cat, n, max_coeff, 1)]) == 0) { + h->non_zero_count_cache[scan8[n]] = 0; + return; + } ++ decode_cabac_residual_dc_internal_422(h, block, cat, n, scantable, max_coeff); ++} ++ ++static av_always_inline void decode_cabac_residual_nondc( H264Context *h, DCTELEM *block, int cat, int n, const uint8_t *scantable, const uint32_t *qmul, int max_coeff ) { ++ /* read coded block flag */ ++ if( (cat != 5 || CHROMA444) && get_cabac( &h->cabac, &h->cabac_state[get_cabac_cbf_ctx( h, cat, n, max_coeff, 0 ) ] ) == 0 ) { ++ if( max_coeff == 64 ) { ++ fill_rectangle(&h->non_zero_count_cache[scan8[n]], 2, 2, 8, 0, 1); ++ } else { ++ h->non_zero_count_cache[scan8[n]] = 0; ++ } ++ return; ++ } + decode_cabac_residual_nondc_internal( h, block, cat, n, scantable, qmul, max_coeff ); + } + ++static av_always_inline void decode_cabac_luma_residual( H264Context *h, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p ) ++{ ++ static const uint8_t ctx_cat[4][3] = {{0,6,10},{1,7,11},{2,8,12},{5,9,13}}; ++ const uint32_t *qmul; ++ int i8x8, i4x4; ++ MpegEncContext * const s = &h->s; ++ int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; ++ if( IS_INTRA16x16( mb_type ) ) { ++ //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); ++ AV_ZERO128(h->mb_luma_dc[p]+0); ++ AV_ZERO128(h->mb_luma_dc[p]+8); ++ AV_ZERO128(h->mb_luma_dc[p]+16); ++ AV_ZERO128(h->mb_luma_dc[p]+24); ++ decode_cabac_residual_dc(h, h->mb_luma_dc[p], ctx_cat[0][p], LUMA_DC_BLOCK_INDEX+p, scan, 16); ++ ++ if( cbp&15 ) { ++ qmul = h->dequant4_coeff[p][qscale]; ++ for( i4x4 = 0; i4x4 < 16; i4x4++ ) { ++ const int index = 16*p + i4x4; ++ //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", index ); ++ decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[1][p], index, scan + 1, qmul, 15); ++ } ++ } else { ++ fill_rectangle(&h->non_zero_count_cache[scan8[16*p]], 4, 4, 8, 0, 1); ++ } ++ } else { ++ int cqm = (IS_INTRA( mb_type ) ? 0:3) + p; ++ for( i8x8 = 0; i8x8 < 4; i8x8++ ) { ++ if( cbp & (1<mb + (16*index << pixel_shift), ctx_cat[3][p], index, ++ scan8x8, h->dequant8_coeff[cqm][qscale], 64); ++ } else { ++ qmul = h->dequant4_coeff[cqm][qscale]; ++ for( i4x4 = 0; i4x4 < 4; i4x4++ ) { ++ const int index = 16*p + 4*i8x8 + i4x4; ++ //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); ++//START_TIMER ++ decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), ctx_cat[2][p], index, scan, qmul, 16); ++//STOP_TIMER("decode_residual") ++ } ++ } ++ } else { ++ fill_rectangle(&h->non_zero_count_cache[scan8[4*i8x8+16*p]], 2, 2, 8, 0, 1); ++ } ++ } ++ } ++} ++ + /** +- * decodes a macroblock +- * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed ++ * Decode a macroblock. ++ * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed + */ + int ff_h264_decode_mb_cabac(H264Context *h) { + MpegEncContext * const s = &h->s; + int mb_xy; + int mb_type, partition_count, cbp = 0; + int dct8x8_allowed= h->pps.transform_8x8_mode; ++ int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2; ++ const int pixel_shift = h->pixel_shift; + + mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + + tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); +- if( h->slice_type_nos != FF_I_TYPE ) { ++ if( h->slice_type_nos != AV_PICTURE_TYPE_I ) { + int skip; + /* a skipped mb needs the aff flag from the following mb */ + if( FRAME_MBAFF && (s->mb_y&1)==1 && h->prev_mb_skipped ) +@@ -1210,7 +1890,7 @@ + /* read skip flags */ + if( skip ) { + if( FRAME_MBAFF && (s->mb_y&1)==0 ){ +- s->current_picture.mb_type[mb_xy] = MB_TYPE_SKIP; ++ s->current_picture.f.mb_type[mb_xy] = MB_TYPE_SKIP; + h->next_mb_skipped = decode_cabac_mb_skip( h, s->mb_x, s->mb_y+1 ); + if(!h->next_mb_skipped) + h->mb_mbaff = h->mb_field_decoding_flag = decode_cabac_field_decoding_flag(h); +@@ -1236,11 +1916,11 @@ + + fill_decode_neighbors(h, -(MB_FIELD)); + +- if( h->slice_type_nos == FF_B_TYPE ) { ++ if( h->slice_type_nos == AV_PICTURE_TYPE_B ) { + int ctx = 0; +- assert(h->slice_type_nos == FF_B_TYPE); ++ assert(h->slice_type_nos == AV_PICTURE_TYPE_B); + +- if( !IS_DIRECT( h->left_type[0]-1 ) ) ++ if( !IS_DIRECT( h->left_type[LTOP]-1 ) ) + ctx++; + if( !IS_DIRECT( h->top_type-1 ) ) + ctx++; +@@ -1271,7 +1951,7 @@ + } + partition_count= b_mb_type_info[mb_type].partition_count; + mb_type= b_mb_type_info[mb_type].type; +- } else if( h->slice_type_nos == FF_P_TYPE ) { ++ } else if( h->slice_type_nos == AV_PICTURE_TYPE_P ) { + if( get_cabac_noinline( &h->cabac, &h->cabac_state[14] ) == 0 ) { + /* P-type */ + if( get_cabac_noinline( &h->cabac, &h->cabac_state[15] ) == 0 ) { +@@ -1289,9 +1969,9 @@ + } + } else { + mb_type= decode_cabac_intra_mb_type(h, 3, 1); +- if(h->slice_type == FF_SI_TYPE && mb_type) ++ if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type) + mb_type--; +- assert(h->slice_type_nos == FF_I_TYPE); ++ assert(h->slice_type_nos == AV_PICTURE_TYPE_I); + decode_intra_mb: + partition_count = 0; + cbp= i_mb_type_info[mb_type].cbp; +@@ -1304,6 +1984,8 @@ + h->slice_table[ mb_xy ]= h->slice_num; + + if(IS_INTRA_PCM(mb_type)) { ++ static const uint16_t mb_sizes[4] = {256,384,512,768}; ++ const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3; + const uint8_t *ptr; + + // We assume these blocks are very rare so we do not optimize it. +@@ -1316,21 +1998,20 @@ + } + + // The pixels are stored in the same order as levels in h->mb array. +- memcpy(h->mb, ptr, 256); ptr+=256; +- if(CHROMA){ +- memcpy(h->mb+128, ptr, 128); ptr+=128; +- } ++ if ((int) (h->cabac.bytestream_end - ptr) < mb_size) ++ return -1; ++ memcpy(h->mb, ptr, mb_size); ptr+=mb_size; + + ff_init_cabac_decoder(&h->cabac, ptr, h->cabac.bytestream_end - ptr); + + // All blocks are present +- h->cbp_table[mb_xy] = 0x1ef; ++ h->cbp_table[mb_xy] = 0xf7ef; + h->chroma_pred_mode_table[mb_xy] = 0; + // In deblocking, the quantizer is 0 +- s->current_picture.qscale_table[mb_xy]= 0; ++ s->current_picture.f.qscale_table[mb_xy] = 0; + // All coeffs are present +- memset(h->non_zero_count[mb_xy], 16, 32); +- s->current_picture.mb_type[mb_xy]= mb_type; ++ memset(h->non_zero_count[mb_xy], 16, 48); ++ s->current_picture.f.mb_type[mb_xy] = mb_type; + h->last_qscale_diff = 0; + return 0; + } +@@ -1360,17 +2041,17 @@ + //av_log( s->avctx, AV_LOG_ERROR, "i4x4 pred=%d mode=%d\n", pred, h->intra4x4_pred_mode_cache[ scan8[i] ] ); + } + } +- ff_h264_write_back_intra_pred_mode(h); ++ write_back_intra_pred_mode(h); + if( ff_h264_check_intra4x4_pred_mode(h) < 0 ) return -1; + } else { +- h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode ); ++ h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode( h, h->intra16x16_pred_mode, 0 ); + if( h->intra16x16_pred_mode < 0 ) return -1; + } +- if(CHROMA){ ++ if(decode_chroma){ + h->chroma_pred_mode_table[mb_xy] = + pred_mode = decode_cabac_mb_chroma_pre_mode( h ); + +- pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode ); ++ pred_mode= ff_h264_check_intra_pred_mode( h, pred_mode, 1 ); + if( pred_mode < 0 ) return -1; + h->chroma_pred_mode= pred_mode; + } else { +@@ -1379,7 +2060,7 @@ + } else if( partition_count == 4 ) { + int i, j, sub_partition_count[4], list, ref[2][4]; + +- if( h->slice_type_nos == FF_B_TYPE ) { ++ if( h->slice_type_nos == AV_PICTURE_TYPE_B ) { + for( i = 0; i < 4; i++ ) { + h->sub_mb_type[i] = decode_cabac_b_mb_sub_type( h ); + sub_partition_count[i]= b_sub_mb_type_info[ h->sub_mb_type[i] ].partition_count; +@@ -1595,7 +2276,7 @@ + + if( !IS_INTRA16x16( mb_type ) ) { + cbp = decode_cabac_mb_cbp_luma( h ); +- if(CHROMA) ++ if(decode_chroma) + cbp |= decode_cabac_mb_cbp_chroma( h ) << 4; + } + +@@ -1604,7 +2285,30 @@ + if( dct8x8_allowed && (cbp&15) && !IS_INTRA( mb_type ) ) { + mb_type |= MB_TYPE_8x8DCT * get_cabac_noinline( &h->cabac, &h->cabac_state[399 + h->neighbor_transform_size] ); + } +- s->current_picture.mb_type[mb_xy]= mb_type; ++ ++ /* It would be better to do this in fill_decode_caches, but we don't know ++ * the transform mode of the current macroblock there. */ ++ if (CHROMA444 && IS_8x8DCT(mb_type)){ ++ int i; ++ uint8_t *nnz_cache = h->non_zero_count_cache; ++ for (i = 0; i < 2; i++){ ++ if (h->left_type[LEFT(i)] && !IS_8x8DCT(h->left_type[LEFT(i)])){ ++ nnz_cache[3+8* 1 + 2*8*i]= ++ nnz_cache[3+8* 2 + 2*8*i]= ++ nnz_cache[3+8* 6 + 2*8*i]= ++ nnz_cache[3+8* 7 + 2*8*i]= ++ nnz_cache[3+8*11 + 2*8*i]= ++ nnz_cache[3+8*12 + 2*8*i]= IS_INTRA(mb_type) ? 64 : 0; ++ } ++ } ++ if (h->top_type && !IS_8x8DCT(h->top_type)){ ++ uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; ++ AV_WN32A(&nnz_cache[4+8* 0], top_empty); ++ AV_WN32A(&nnz_cache[4+8* 5], top_empty); ++ AV_WN32A(&nnz_cache[4+8*10], top_empty); ++ } ++ } ++ s->current_picture.f.mb_type[mb_xy] = mb_type; + + if( cbp || IS_INTRA16x16( mb_type ) ) { + const uint8_t *scan, *scan8x8; +@@ -1622,11 +2326,12 @@ + if(get_cabac_noinline( &h->cabac, &h->cabac_state[60 + (h->last_qscale_diff != 0)])){ + int val = 1; + int ctx= 2; ++ const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); + + while( get_cabac_noinline( &h->cabac, &h->cabac_state[60 + ctx] ) ) { + ctx= 3; + val++; +- if(val > 102){ //prevent infinite loop ++ if(val > 2*max_qp){ //prevent infinite loop + av_log(h->s.avctx, AV_LOG_ERROR, "cabac decode of qscale diff failed at %d %d\n", s->mb_x, s->mb_y); + return -1; + } +@@ -1638,87 +2343,80 @@ + val= -((val + 1)>>1); + h->last_qscale_diff = val; + s->qscale += val; +- if(((unsigned)s->qscale) > 51){ +- if(s->qscale<0) s->qscale+= 52; +- else s->qscale-= 52; ++ if(((unsigned)s->qscale) > max_qp){ ++ if(s->qscale<0) s->qscale+= max_qp+1; ++ else s->qscale-= max_qp+1; + } + h->chroma_qp[0] = get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1] = get_chroma_qp(h, 1, s->qscale); + }else + h->last_qscale_diff=0; + +- if( IS_INTRA16x16( mb_type ) ) { +- int i; +- //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 DC\n" ); +- AV_ZERO128(h->mb_luma_dc+0); +- AV_ZERO128(h->mb_luma_dc+8); +- decode_cabac_residual_dc( h, h->mb_luma_dc, 0, LUMA_DC_BLOCK_INDEX, scan, 16); +- +- if( cbp&15 ) { +- qmul = h->dequant4_coeff[0][s->qscale]; +- for( i = 0; i < 16; i++ ) { +- //av_log( s->avctx, AV_LOG_ERROR, "INTRA16x16 AC:%d\n", i ); +- decode_cabac_residual_nondc(h, h->mb + 16*i, 1, i, scan + 1, qmul, 15); ++ decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 0); ++ if(CHROMA444){ ++ decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 1); ++ decode_cabac_luma_residual(h, scan, scan8x8, pixel_shift, mb_type, cbp, 2); ++ } else if (CHROMA422) { ++ if( cbp&0x30 ){ ++ int c; ++ for( c = 0; c < 2; c++ ) { ++ //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); ++ decode_cabac_residual_dc_422(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, ++ CHROMA_DC_BLOCK_INDEX + c, ++ chroma422_dc_scan, 8); + } +- } else { +- fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); + } +- } else { +- int i8x8, i4x4; +- for( i8x8 = 0; i8x8 < 4; i8x8++ ) { +- if( cbp & (1<mb + 64*i8x8, 5, 4*i8x8, +- scan8x8, h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 64); +- } else { +- qmul = h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale]; +- for( i4x4 = 0; i4x4 < 4; i4x4++ ) { +- const int index = 4*i8x8 + i4x4; +- //av_log( s->avctx, AV_LOG_ERROR, "Luma4x4: %d\n", index ); +-//START_TIMER +- decode_cabac_residual_nondc(h, h->mb + 16*index, 2, index, scan, qmul, 16); +-//STOP_TIMER("decode_residual") ++ ++ if( cbp&0x20 ) { ++ int c, i, i8x8; ++ for( c = 0; c < 2; c++ ) { ++ DCTELEM *mb = h->mb + (16*(16 + 16*c) << pixel_shift); ++ qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; ++ for (i8x8 = 0; i8x8 < 2; i8x8++) { ++ for (i = 0; i < 4; i++) { ++ const int index = 16 + 16 * c + 8*i8x8 + i; ++ //av_log(s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16); ++ decode_cabac_residual_nondc(h, mb, 4, index, scan + 1, qmul, 15); ++ mb += 16<non_zero_count_cache[ scan8[4*i8x8] ]; +- nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; + } ++ } else { ++ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + } +- } +- +- if( cbp&0x30 ){ +- int c; +- for( c = 0; c < 2; c++ ) { +- //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); +- decode_cabac_residual_dc(h, h->mb + 256 + 16*4*c, 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4); ++ } else /* yuv420 */ { ++ if( cbp&0x30 ){ ++ int c; ++ for( c = 0; c < 2; c++ ) { ++ //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-DC\n",c ); ++ decode_cabac_residual_dc(h, h->mb + ((256 + 16*16*c) << pixel_shift), 3, CHROMA_DC_BLOCK_INDEX+c, chroma_dc_scan, 4); ++ } + } +- } + +- if( cbp&0x20 ) { +- int c, i; +- for( c = 0; c < 2; c++ ) { +- qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; +- for( i = 0; i < 4; i++ ) { +- const int index = 16 + 4 * c + i; +- //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); +- decode_cabac_residual_nondc(h, h->mb + 16*index, 4, index, scan + 1, qmul, 15); ++ if( cbp&0x20 ) { ++ int c, i; ++ for( c = 0; c < 2; c++ ) { ++ qmul = h->dequant4_coeff[c+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[c]]; ++ for( i = 0; i < 4; i++ ) { ++ const int index = 16 + 16 * c + i; ++ //av_log( s->avctx, AV_LOG_ERROR, "INTRA C%d-AC %d\n",c, index - 16 ); ++ decode_cabac_residual_nondc(h, h->mb + (16*index << pixel_shift), 4, index, scan + 1, qmul, 15); ++ } + } ++ } else { ++ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + } +- } else { +- uint8_t * const nnz= &h->non_zero_count_cache[0]; +- nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = +- nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + } + } else { +- uint8_t * const nnz= &h->non_zero_count_cache[0]; +- fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); +- nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = +- nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; ++ fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + h->last_qscale_diff = 0; + } + +- s->current_picture.qscale_table[mb_xy]= s->qscale; ++ s->current_picture.f.qscale_table[mb_xy] = s->qscale; + write_back_non_zero_count(h); + + if(MB_MBAFF){ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_cavlc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_cavlc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_cavlc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_cavlc.c 2012-05-14 14:08:53.806329355 +0200 +@@ -26,6 +26,7 @@ + */ + + #define CABAC 0 ++#define UNCHECKED_BITSTREAM_READER 1 + + #include "internal.h" + #include "avcodec.h" +@@ -62,6 +63,30 @@ + 2, 3, 2, 0, + }; + ++static const uint8_t chroma422_dc_coeff_token_len[4*9]={ ++ 1, 0, 0, 0, ++ 7, 2, 0, 0, ++ 7, 7, 3, 0, ++ 9, 7, 7, 5, ++ 9, 9, 7, 6, ++ 10, 10, 9, 7, ++ 11, 11, 10, 7, ++ 12, 12, 11, 10, ++ 13, 12, 12, 11, ++}; ++ ++static const uint8_t chroma422_dc_coeff_token_bits[4*9]={ ++ 1, 0, 0, 0, ++ 15, 1, 0, 0, ++ 14, 13, 1, 0, ++ 7, 12, 11, 1, ++ 6, 5, 10, 1, ++ 7, 6, 4, 9, ++ 7, 6, 5, 8, ++ 7, 6, 5, 4, ++ 7, 5, 4, 4, ++}; ++ + static const uint8_t coeff_token_len[4][4*17]={ + { + 1, 0, 0, 0, +@@ -172,6 +197,26 @@ + { 1, 0, 0, 0,}, + }; + ++static const uint8_t chroma422_dc_total_zeros_len[7][8]= { ++ { 1, 3, 3, 4, 4, 4, 5, 5 }, ++ { 3, 2, 3, 3, 3, 3, 3 }, ++ { 3, 3, 2, 2, 3, 3 }, ++ { 3, 2, 2, 2, 3 }, ++ { 2, 2, 2, 2 }, ++ { 2, 2, 1 }, ++ { 1, 1 }, ++}; ++ ++static const uint8_t chroma422_dc_total_zeros_bits[7][8]= { ++ { 1, 2, 3, 2, 3, 1, 1, 0 }, ++ { 0, 1, 1, 4, 5, 6, 7 }, ++ { 0, 1, 1, 2, 6, 7 }, ++ { 6, 0, 1, 2, 7 }, ++ { 0, 1, 2, 3 }, ++ { 0, 1, 1 }, ++ { 0, 1 }, ++}; ++ + static const uint8_t run_len[7][16]={ + {1,1}, + {1,2,2}, +@@ -200,6 +245,10 @@ + static VLC_TYPE chroma_dc_coeff_token_vlc_table[256][2]; + static const int chroma_dc_coeff_token_vlc_table_size = 256; + ++static VLC chroma422_dc_coeff_token_vlc; ++static VLC_TYPE chroma422_dc_coeff_token_vlc_table[8192][2]; ++static const int chroma422_dc_coeff_token_vlc_table_size = 8192; ++ + static VLC total_zeros_vlc[15]; + static VLC_TYPE total_zeros_vlc_tables[15][512][2]; + static const int total_zeros_vlc_tables_size = 512; +@@ -208,6 +257,10 @@ + static VLC_TYPE chroma_dc_total_zeros_vlc_tables[3][8][2]; + static const int chroma_dc_total_zeros_vlc_tables_size = 8; + ++static VLC chroma422_dc_total_zeros_vlc[7]; ++static VLC_TYPE chroma422_dc_total_zeros_vlc_tables[7][32][2]; ++static const int chroma422_dc_total_zeros_vlc_tables_size = 32; ++ + static VLC run_vlc[6]; + static VLC_TYPE run_vlc_tables[6][8][2]; + static const int run_vlc_tables_size = 8; +@@ -219,9 +272,17 @@ + #define LEVEL_TAB_BITS 8 + static int8_t cavlc_level_tab[7][1<>(LEVEL_TAB_BITS-prefix-1-suffix_length)) - (1<>1) ^ mask) - mask; + if(prefix + 1 + suffix_length <= LEVEL_TAB_BITS){ ++ int level_code = (prefix << suffix_length) + ++ (i >> (av_log2(i) - suffix_length)) - (1 << suffix_length); ++ int mask = -(level_code&1); ++ level_code = (((2 + level_code) >> 1) ^ mask) - mask; + cavlc_level_tab[suffix_length][i][0]= level_code; + cavlc_level_tab[suffix_length][i][1]= prefix + 1 + suffix_length; + }else if(prefix + 1 <= LEVEL_TAB_BITS){ +@@ -277,6 +339,13 @@ + &chroma_dc_coeff_token_bits[0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + ++ chroma422_dc_coeff_token_vlc.table = chroma422_dc_coeff_token_vlc_table; ++ chroma422_dc_coeff_token_vlc.table_allocated = chroma422_dc_coeff_token_vlc_table_size; ++ init_vlc(&chroma422_dc_coeff_token_vlc, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 4*9, ++ &chroma422_dc_coeff_token_len [0], 1, 1, ++ &chroma422_dc_coeff_token_bits[0], 1, 1, ++ INIT_VLC_USE_NEW_STATIC); ++ + offset = 0; + for(i=0; i<4; i++){ + coeff_token_vlc[i].table = coeff_token_vlc_tables+offset; +@@ -303,6 +372,17 @@ + &chroma_dc_total_zeros_bits[i][0], 1, 1, + INIT_VLC_USE_NEW_STATIC); + } ++ ++ for(i=0; i<7; i++){ ++ chroma422_dc_total_zeros_vlc[i].table = chroma422_dc_total_zeros_vlc_tables[i]; ++ chroma422_dc_total_zeros_vlc[i].table_allocated = chroma422_dc_total_zeros_vlc_tables_size; ++ init_vlc(&chroma422_dc_total_zeros_vlc[i], ++ CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 8, ++ &chroma422_dc_total_zeros_len [i][0], 1, 1, ++ &chroma422_dc_total_zeros_bits[i][0], 1, 1, ++ INIT_VLC_USE_NEW_STATIC); ++ } ++ + for(i=0; i<15; i++){ + total_zeros_vlc[i].table = total_zeros_vlc_tables[i]; + total_zeros_vlc[i].table_allocated = total_zeros_vlc_tables_size; +@@ -357,7 +437,7 @@ + } + + /** +- * decodes a residual block. ++ * Decode a residual block. + * @param n block index + * @param scantable scantable + * @param max_coeff number of coefficients in the block +@@ -371,12 +451,15 @@ + + //FIXME put trailing_onex into the context + +- if(n >= CHROMA_DC_BLOCK_INDEX){ +- coeff_token= get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); ++ if(max_coeff <= 8){ ++ if (max_coeff == 4) ++ coeff_token = get_vlc2(gb, chroma_dc_coeff_token_vlc.table, CHROMA_DC_COEFF_TOKEN_VLC_BITS, 1); ++ else ++ coeff_token = get_vlc2(gb, chroma422_dc_coeff_token_vlc.table, CHROMA422_DC_COEFF_TOKEN_VLC_BITS, 1); + total_coeff= coeff_token>>2; + }else{ +- if(n == LUMA_DC_BLOCK_INDEX){ +- total_coeff= pred_non_zero_count(h, 0); ++ if(n >= LUMA_DC_BLOCK_INDEX){ ++ total_coeff= pred_non_zero_count(h, (n - LUMA_DC_BLOCK_INDEX)*16); + coeff_token= get_vlc2(gb, coeff_token_vlc[ coeff_token_table_index[total_coeff] ].table, COEFF_TOKEN_VLC_BITS, 2); + total_coeff= coeff_token>>2; + }else{ +@@ -482,43 +565,56 @@ + if(total_coeff == max_coeff) + zeros_left=0; + else{ +- if(n >= CHROMA_DC_BLOCK_INDEX) +- zeros_left= get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[ total_coeff ].table, CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); +- else ++ if (max_coeff <= 8) { ++ if (max_coeff == 4) ++ zeros_left = get_vlc2(gb, (chroma_dc_total_zeros_vlc-1)[total_coeff].table, ++ CHROMA_DC_TOTAL_ZEROS_VLC_BITS, 1); ++ else ++ zeros_left = get_vlc2(gb, (chroma422_dc_total_zeros_vlc-1)[total_coeff].table, ++ CHROMA422_DC_TOTAL_ZEROS_VLC_BITS, 1); ++ } else { + zeros_left= get_vlc2(gb, (total_zeros_vlc-1)[ total_coeff ].table, TOTAL_ZEROS_VLC_BITS, 1); ++ } + } + +- scantable += zeros_left + total_coeff - 1; +- if(n >= LUMA_DC_BLOCK_INDEX){ +- block[*scantable] = level[0]; +- for(i=1;i 0;i++) { +- if(zeros_left < 7) +- run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); +- else +- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); +- zeros_left -= run_before; +- scantable -= 1 + run_before; +- block[*scantable]= level[i]; +- } +- for(;i>6; +- for(i=1;i 0;i++) { +- if(zeros_left < 7) +- run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); +- else +- run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); +- zeros_left -= run_before; +- scantable -= 1 + run_before; +- block[*scantable]= (level[i] * qmul[*scantable] + 32)>>6; +- } +- for(;i>6; +- } ++#define STORE_BLOCK(type) \ ++ scantable += zeros_left + total_coeff - 1; \ ++ if(n >= LUMA_DC_BLOCK_INDEX){ \ ++ ((type*)block)[*scantable] = level[0]; \ ++ for(i=1;i 0;i++) { \ ++ if(zeros_left < 7) \ ++ run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \ ++ else \ ++ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \ ++ zeros_left -= run_before; \ ++ scantable -= 1 + run_before; \ ++ ((type*)block)[*scantable]= level[i]; \ ++ } \ ++ for(;i>6; \ ++ for(i=1;i 0;i++) { \ ++ if(zeros_left < 7) \ ++ run_before= get_vlc2(gb, (run_vlc-1)[zeros_left].table, RUN_VLC_BITS, 1); \ ++ else \ ++ run_before= get_vlc2(gb, run7_vlc.table, RUN7_VLC_BITS, 2); \ ++ zeros_left -= run_before; \ ++ scantable -= 1 + run_before; \ ++ ((type*)block)[*scantable]= ((int)(level[i] * qmul[*scantable] + 32))>>6; \ ++ } \ ++ for(;i>6; \ ++ } \ ++ } ++ ++ if (h->pixel_shift) { ++ STORE_BLOCK(int32_t) ++ } else { ++ STORE_BLOCK(int16_t) + } + + if(zeros_left<0){ +@@ -529,19 +625,88 @@ + return 0; + } + ++static av_always_inline int decode_luma_residual(H264Context *h, GetBitContext *gb, const uint8_t *scan, const uint8_t *scan8x8, int pixel_shift, int mb_type, int cbp, int p){ ++ int i4x4, i8x8; ++ MpegEncContext * const s = &h->s; ++ int qscale = p == 0 ? s->qscale : h->chroma_qp[p-1]; ++ if(IS_INTRA16x16(mb_type)){ ++ AV_ZERO128(h->mb_luma_dc[p]+0); ++ AV_ZERO128(h->mb_luma_dc[p]+8); ++ AV_ZERO128(h->mb_luma_dc[p]+16); ++ AV_ZERO128(h->mb_luma_dc[p]+24); ++ if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc[p], LUMA_DC_BLOCK_INDEX+p, scan, NULL, 16) < 0){ ++ return -1; //FIXME continue if partitioned and other return -1 too ++ } ++ ++ assert((cbp&15) == 0 || (cbp&15) == 15); ++ ++ if(cbp&15){ ++ for(i8x8=0; i8x8<4; i8x8++){ ++ for(i4x4=0; i4x4<4; i4x4++){ ++ const int index= i4x4 + 4*i8x8 + p*16; ++ if( decode_residual(h, h->intra_gb_ptr, h->mb + (16*index << pixel_shift), ++ index, scan + 1, h->dequant4_coeff[p][qscale], 15) < 0 ){ ++ return -1; ++ } ++ } ++ } ++ return 0xf; ++ }else{ ++ fill_rectangle(&h->non_zero_count_cache[scan8[p*16]], 4, 4, 8, 0, 1); ++ return 0; ++ } ++ }else{ ++ int cqm = (IS_INTRA( mb_type ) ? 0:3)+p; ++ /* For CAVLC 4:4:4, we need to keep track of the luma 8x8 CBP for deblocking nnz purposes. */ ++ int new_cbp = 0; ++ for(i8x8=0; i8x8<4; i8x8++){ ++ if(cbp & (1<mb[64*i8x8+256*p << pixel_shift]; ++ uint8_t *nnz; ++ for(i4x4=0; i4x4<4; i4x4++){ ++ const int index= i4x4 + 4*i8x8 + p*16; ++ if( decode_residual(h, gb, buf, index, scan8x8+16*i4x4, ++ h->dequant8_coeff[cqm][qscale], 16) < 0 ) ++ return -1; ++ } ++ nnz= &h->non_zero_count_cache[ scan8[4*i8x8+p*16] ]; ++ nnz[0] += nnz[1] + nnz[8] + nnz[9]; ++ new_cbp |= !!nnz[0] << i8x8; ++ }else{ ++ for(i4x4=0; i4x4<4; i4x4++){ ++ const int index= i4x4 + 4*i8x8 + p*16; ++ if( decode_residual(h, gb, h->mb + (16*index << pixel_shift), index, ++ scan, h->dequant4_coeff[cqm][qscale], 16) < 0 ){ ++ return -1; ++ } ++ new_cbp |= h->non_zero_count_cache[ scan8[index] ] << i8x8; ++ } ++ } ++ }else{ ++ uint8_t * const nnz= &h->non_zero_count_cache[ scan8[4*i8x8+p*16] ]; ++ nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; ++ } ++ } ++ return new_cbp; ++ } ++} ++ + int ff_h264_decode_mb_cavlc(H264Context *h){ + MpegEncContext * const s = &h->s; + int mb_xy; + int partition_count; + unsigned int mb_type, cbp; + int dct8x8_allowed= h->pps.transform_8x8_mode; ++ int decode_chroma = h->sps.chroma_format_idc == 1 || h->sps.chroma_format_idc == 2; ++ const int pixel_shift = h->pixel_shift; + + mb_xy = h->mb_xy = s->mb_x + s->mb_y*s->mb_stride; + + tprintf(s->avctx, "pic:%d mb:%d/%d\n", h->frame_num, s->mb_x, s->mb_y); + cbp = 0; /* avoid warning. FIXME: find a solution without slowing + down the code */ +- if(h->slice_type_nos != FF_I_TYPE){ ++ if(h->slice_type_nos != AV_PICTURE_TYPE_I){ + if(s->mb_skip_run==-1) + s->mb_skip_run= get_ue_golomb(&s->gb); + +@@ -562,7 +727,7 @@ + h->prev_mb_skipped= 0; + + mb_type= get_ue_golomb(&s->gb); +- if(h->slice_type_nos == FF_B_TYPE){ ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ + if(mb_type < 23){ + partition_count= b_mb_type_info[mb_type].partition_count; + mb_type= b_mb_type_info[mb_type].type; +@@ -570,7 +735,7 @@ + mb_type -= 23; + goto decode_intra_mb; + } +- }else if(h->slice_type_nos == FF_P_TYPE){ ++ }else if(h->slice_type_nos == AV_PICTURE_TYPE_P){ + if(mb_type < 5){ + partition_count= p_mb_type_info[mb_type].partition_count; + mb_type= p_mb_type_info[mb_type].type; +@@ -579,12 +744,12 @@ + goto decode_intra_mb; + } + }else{ +- assert(h->slice_type_nos == FF_I_TYPE); +- if(h->slice_type == FF_SI_TYPE && mb_type) ++ assert(h->slice_type_nos == AV_PICTURE_TYPE_I); ++ if(h->slice_type == AV_PICTURE_TYPE_SI && mb_type) + mb_type--; + decode_intra_mb: + if(mb_type > 25){ +- av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_pict_type_char(h->slice_type), s->mb_x, s->mb_y); ++ av_log(h->s.avctx, AV_LOG_ERROR, "mb_type %d in %c slice too large at %d %d\n", mb_type, av_get_picture_type_char(h->slice_type), s->mb_x, s->mb_y); + return -1; + } + partition_count=0; +@@ -600,21 +765,23 @@ + + if(IS_INTRA_PCM(mb_type)){ + unsigned int x; ++ static const uint16_t mb_sizes[4] = {256,384,512,768}; ++ const int mb_size = mb_sizes[h->sps.chroma_format_idc]*h->sps.bit_depth_luma >> 3; + + // We assume these blocks are very rare so we do not optimize it. + align_get_bits(&s->gb); + + // The pixels are stored in the same order as levels in h->mb array. +- for(x=0; x < (CHROMA ? 384 : 256); x++){ ++ for(x=0; x < mb_size; x++){ + ((uint8_t*)h->mb)[x]= get_bits(&s->gb, 8); + } + + // In deblocking, the quantizer is 0 +- s->current_picture.qscale_table[mb_xy]= 0; ++ s->current_picture.f.qscale_table[mb_xy] = 0; + // All coeffs are present +- memset(h->non_zero_count[mb_xy], 16, 32); ++ memset(h->non_zero_count[mb_xy], 16, 48); + +- s->current_picture.mb_type[mb_xy]= mb_type; ++ s->current_picture.f.mb_type[mb_xy] = mb_type; + return 0; + } + +@@ -652,16 +819,16 @@ + else + h->intra4x4_pred_mode_cache[ scan8[i] ] = mode; + } +- ff_h264_write_back_intra_pred_mode(h); ++ write_back_intra_pred_mode(h); + if( ff_h264_check_intra4x4_pred_mode(h) < 0) + return -1; + }else{ +- h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode); ++ h->intra16x16_pred_mode= ff_h264_check_intra_pred_mode(h, h->intra16x16_pred_mode, 0); + if(h->intra16x16_pred_mode < 0) + return -1; + } +- if(CHROMA){ +- pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb)); ++ if(decode_chroma){ ++ pred_mode= ff_h264_check_intra_pred_mode(h, get_ue_golomb_31(&s->gb), 1); + if(pred_mode < 0) + return -1; + h->chroma_pred_mode= pred_mode; +@@ -671,7 +838,7 @@ + }else if(partition_count==4){ + int i, j, sub_partition_count[4], list, ref[2][4]; + +- if(h->slice_type_nos == FF_B_TYPE){ ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ + for(i=0; i<4; i++){ + h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + if(h->sub_mb_type[i] >=13){ +@@ -689,7 +856,7 @@ + h->ref_cache[1][scan8[12]] = PART_NOT_AVAILABLE; + } + }else{ +- assert(h->slice_type_nos == FF_P_TYPE); //FIXME SP correct ? ++ assert(h->slice_type_nos == AV_PICTURE_TYPE_P); //FIXME SP correct ? + for(i=0; i<4; i++){ + h->sub_mb_type[i]= get_ue_golomb_31(&s->gb); + if(h->sub_mb_type[i] >=4){ +@@ -888,15 +1055,19 @@ + + if(!IS_INTRA16x16(mb_type)){ + cbp= get_ue_golomb(&s->gb); +- if(cbp > 47){ +- av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); +- return -1; +- } + +- if(CHROMA){ ++ if(decode_chroma){ ++ if(cbp > 47){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); ++ return -1; ++ } + if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp[cbp]; + else cbp= golomb_to_inter_cbp [cbp]; + }else{ ++ if(cbp > 15){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "cbp too large (%u) at %d %d\n", cbp, s->mb_x, s->mb_y); ++ return -1; ++ } + if(IS_INTRA4x4(mb_type)) cbp= golomb_to_intra4x4_cbp_gray[cbp]; + else cbp= golomb_to_inter_cbp_gray[cbp]; + } +@@ -907,13 +1078,15 @@ + } + h->cbp= + h->cbp_table[mb_xy]= cbp; +- s->current_picture.mb_type[mb_xy]= mb_type; ++ s->current_picture.f.mb_type[mb_xy] = mb_type; + + if(cbp || IS_INTRA16x16(mb_type)){ +- int i8x8, i4x4, chroma_idx; ++ int i4x4, i8x8, chroma_idx; + int dquant; ++ int ret; + GetBitContext *gb= IS_INTRA(mb_type) ? h->intra_gb_ptr : h->inter_gb_ptr; + const uint8_t *scan, *scan8x8; ++ const int max_qp = 51 + 6*(h->sps.bit_depth_luma-8); + + if(IS_INTERLACED(mb_type)){ + scan8x8= s->qscale ? h->field_scan8x8_cavlc : h->field_scan8x8_cavlc_q0; +@@ -927,10 +1100,10 @@ + + s->qscale += dquant; + +- if(((unsigned)s->qscale) > 51){ +- if(s->qscale<0) s->qscale+= 52; +- else s->qscale-= 52; +- if(((unsigned)s->qscale) > 51){ ++ if(((unsigned)s->qscale) > max_qp){ ++ if(s->qscale<0) s->qscale+= max_qp+1; ++ else s->qscale-= max_qp+1; ++ if(((unsigned)s->qscale) > max_qp){ + av_log(h->s.avctx, AV_LOG_ERROR, "dquant out of range (%d) at %d %d\n", dquant, s->mb_x, s->mb_y); + return -1; + } +@@ -938,85 +1111,55 @@ + + h->chroma_qp[0]= get_chroma_qp(h, 0, s->qscale); + h->chroma_qp[1]= get_chroma_qp(h, 1, s->qscale); +- if(IS_INTRA16x16(mb_type)){ +- AV_ZERO128(h->mb_luma_dc+0); +- AV_ZERO128(h->mb_luma_dc+8); +- if( decode_residual(h, h->intra_gb_ptr, h->mb_luma_dc, LUMA_DC_BLOCK_INDEX, scan, h->dequant4_coeff[0][s->qscale], 16) < 0){ +- return -1; //FIXME continue if partitioned and other return -1 too +- } + +- assert((cbp&15) == 0 || (cbp&15) == 15); ++ if( (ret = decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 0)) < 0 ){ ++ return -1; ++ } ++ h->cbp_table[mb_xy] |= ret << 12; ++ if(CHROMA444){ ++ if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 1) < 0 ){ ++ return -1; ++ } ++ if( decode_luma_residual(h, gb, scan, scan8x8, pixel_shift, mb_type, cbp, 2) < 0 ){ ++ return -1; ++ } ++ } else { ++ const int num_c8x8 = h->sps.chroma_format_idc; + +- if(cbp&15){ +- for(i8x8=0; i8x8<4; i8x8++){ +- for(i4x4=0; i4x4<4; i4x4++){ +- const int index= i4x4 + 4*i8x8; +- if( decode_residual(h, h->intra_gb_ptr, h->mb + 16*index, index, scan + 1, h->dequant4_coeff[0][s->qscale], 15) < 0 ){ +- return -1; +- } ++ if(cbp&0x30){ ++ for(chroma_idx=0; chroma_idx<2; chroma_idx++) ++ if (decode_residual(h, gb, h->mb + ((256 + 16*16*chroma_idx) << pixel_shift), ++ CHROMA_DC_BLOCK_INDEX+chroma_idx, ++ CHROMA422 ? chroma422_dc_scan : chroma_dc_scan, ++ NULL, 4*num_c8x8) < 0) { ++ return -1; + } +- } +- }else{ +- fill_rectangle(&h->non_zero_count_cache[scan8[0]], 4, 4, 8, 0, 1); + } +- }else{ +- for(i8x8=0; i8x8<4; i8x8++){ +- if(cbp & (1<mb[64*i8x8]; +- uint8_t *nnz; +- for(i4x4=0; i4x4<4; i4x4++){ +- if( decode_residual(h, gb, buf, i4x4+4*i8x8, scan8x8+16*i4x4, +- h->dequant8_coeff[IS_INTRA( mb_type ) ? 0:1][s->qscale], 16) <0 ) +- return -1; +- } +- nnz= &h->non_zero_count_cache[ scan8[4*i8x8] ]; +- nnz[0] += nnz[1] + nnz[8] + nnz[9]; +- }else{ +- for(i4x4=0; i4x4<4; i4x4++){ +- const int index= i4x4 + 4*i8x8; + +- if( decode_residual(h, gb, h->mb + 16*index, index, scan, h->dequant4_coeff[IS_INTRA( mb_type ) ? 0:3][s->qscale], 16) <0 ){ ++ if(cbp&0x20){ ++ for(chroma_idx=0; chroma_idx<2; chroma_idx++){ ++ const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]]; ++ DCTELEM *mb = h->mb + (16*(16 + 16*chroma_idx) << pixel_shift); ++ for (i8x8=0; i8x8non_zero_count_cache[ scan8[4*i8x8] ]; +- nnz[0] = nnz[1] = nnz[8] = nnz[9] = 0; +- } +- } +- } +- +- if(cbp&0x30){ +- for(chroma_idx=0; chroma_idx<2; chroma_idx++) +- if( decode_residual(h, gb, h->mb + 256 + 16*4*chroma_idx, CHROMA_DC_BLOCK_INDEX+chroma_idx, chroma_dc_scan, NULL, 4) < 0){ +- return -1; +- } +- } +- +- if(cbp&0x20){ +- for(chroma_idx=0; chroma_idx<2; chroma_idx++){ +- const uint32_t *qmul = h->dequant4_coeff[chroma_idx+1+(IS_INTRA( mb_type ) ? 0:3)][h->chroma_qp[chroma_idx]]; +- for(i4x4=0; i4x4<4; i4x4++){ +- const int index= 16 + 4*chroma_idx + i4x4; +- if( decode_residual(h, gb, h->mb + 16*index, index, scan + 1, qmul, 15) < 0){ +- return -1; +- } + } ++ }else{ ++ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + } +- }else{ +- uint8_t * const nnz= &h->non_zero_count_cache[0]; +- nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = +- nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; + } + }else{ +- uint8_t * const nnz= &h->non_zero_count_cache[0]; +- fill_rectangle(&nnz[scan8[0]], 4, 4, 8, 0, 1); +- nnz[ scan8[16]+0 ] = nnz[ scan8[16]+1 ] =nnz[ scan8[16]+8 ] =nnz[ scan8[16]+9 ] = +- nnz[ scan8[20]+0 ] = nnz[ scan8[20]+1 ] =nnz[ scan8[20]+8 ] =nnz[ scan8[20]+9 ] = 0; ++ fill_rectangle(&h->non_zero_count_cache[scan8[ 0]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[16]], 4, 4, 8, 0, 1); ++ fill_rectangle(&h->non_zero_count_cache[scan8[32]], 4, 4, 8, 0, 1); + } +- s->current_picture.qscale_table[mb_xy]= s->qscale; ++ s->current_picture.f.qscale_table[mb_xy] = s->qscale; + write_back_non_zero_count(h); + + if(MB_MBAFF){ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264data.h 2012-05-14 14:08:53.821329657 +0200 +@@ -36,7 +36,7 @@ + + + static const uint8_t golomb_to_pict_type[5]= +-{FF_P_TYPE, FF_B_TYPE, FF_I_TYPE, FF_SP_TYPE, FF_SI_TYPE}; ++{AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_SP, AV_PICTURE_TYPE_SI}; + + static const uint8_t golomb_to_intra4x4_cbp[48]={ + 47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46, +@@ -80,7 +80,14 @@ + + static const uint8_t chroma_dc_scan[4]={ + (0+0*2)*16, (1+0*2)*16, +- (0+1*2)*16, (1+1*2)*16, //FIXME ++ (0+1*2)*16, (1+1*2)*16, ++}; ++ ++static const uint8_t chroma422_dc_scan[8]={ ++ (0+0*2)*16, (0+1*2)*16, ++ (1+0*2)*16, (0+2*2)*16, ++ (0+3*2)*16, (1+1*2)*16, ++ (1+2*2)*16, (1+3*2)*16, + }; + + // zigzag_scan8x8_cavlc[i] = zigzag_scan8x8[(i/4) + 16*(i%4)] +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_direct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_direct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_direct.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_direct.c 2012-05-14 14:08:53.807329375 +0200 +@@ -31,6 +31,7 @@ + #include "mpegvideo.h" + #include "h264.h" + #include "rectangle.h" ++#include "thread.h" + + //#undef NDEBUG + #include +@@ -86,9 +87,10 @@ + poc= (poc&~3) + rfield + 1; + + for(j=start; jref_list[0][j].frame_num + (h->ref_list[0][j].reference&3) == poc){ ++ if (4 * h->ref_list[0][j].frame_num + (h->ref_list[0][j].f.reference & 3) == poc) { + int cur_ref= mbafi ? (j-16)^field : j; +- map[list][2*old_ref + (rfield^field) + 16] = cur_ref; ++ if(ref1->mbaff) ++ map[list][2*old_ref + (rfield^field) + 16] = cur_ref; + if(rfield == field || !interl) + map[list][old_ref] = cur_ref; + break; +@@ -104,12 +106,12 @@ + Picture * const cur = s->current_picture_ptr; + int list, j, field; + int sidx= (s->picture_structure&1)^1; +- int ref1sidx= (ref1->reference&1)^1; ++ int ref1sidx = (ref1->f.reference&1)^1; + + for(list=0; list<2; list++){ + cur->ref_count[sidx][list] = h->ref_count[list]; + for(j=0; jref_count[list]; j++) +- cur->ref_poc[sidx][list][j] = 4*h->ref_list[list][j].frame_num + (h->ref_list[list][j].reference&3); ++ cur->ref_poc[sidx][list][j] = 4 * h->ref_list[list][j].frame_num + (h->ref_list[list][j].f.reference & 3); + } + + if(s->picture_structure == PICT_FRAME){ +@@ -125,11 +127,11 @@ + int *col_poc = h->ref_list[1]->field_poc; + h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc)); + ref1sidx=sidx= h->col_parity; +- }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity +- h->col_fieldoff= s->mb_stride*(2*(h->ref_list[1][0].reference) - 3); ++ } else if (!(s->picture_structure & h->ref_list[1][0].f.reference) && !h->ref_list[1][0].mbaff) { // FL -> FL & differ parity ++ h->col_fieldoff = 2 * h->ref_list[1][0].f.reference - 3; + } + +- if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred) ++ if (cur->f.pict_type != AV_PICTURE_TYPE_B || h->direct_spatial_mv_pred) + return; + + for(list=0; list<2; list++){ +@@ -140,11 +142,27 @@ + } + } + ++static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y) ++{ ++ int ref_field = ref->f.reference - 1; ++ int ref_field_picture = ref->field_picture; ++ int ref_height = 16*h->s.mb_height >> ref_field_picture; ++ ++ if(!HAVE_THREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME)) ++ return; ++ ++ //FIXME it can be safe to access mb stuff ++ //even if pixels aren't deblocked yet ++ ++ ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1), ++ ref_field_picture && ref_field); ++} ++ + static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ + MpegEncContext * const s = &h->s; + int b8_stride = 2; + int b4_stride = h->b_stride; +- int mb_xy = h->mb_xy; ++ int mb_xy = h->mb_xy, mb_y = s->mb_y; + int mb_type_col[2]; + const int16_t (*l1mv0)[2], (*l1mv1)[2]; + const int8_t *l1ref0, *l1ref1; +@@ -155,7 +173,9 @@ + int mv[2]; + int list; + +- assert(h->ref_list[1][0].reference&3); ++ assert(h->ref_list[1][0].f.reference & 3); ++ ++ await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); + + #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) + +@@ -215,21 +235,28 @@ + return; + } + +- if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL +- if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL ++ if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL ++ if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL ++ mb_y = (s->mb_y&~1) + h->col_parity; + mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + b8_stride = 0; + }else{ +- mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity ++ mb_y += h->col_fieldoff; ++ mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity + } + goto single_col; + }else{ // AFL/AFR/FR/FL -> AFR/FR + if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR ++ mb_y = s->mb_y&~1; + mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; +- mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; +- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride]; ++ mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; ++ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; + b8_stride = 2+4*s->mb_stride; + b4_stride *= 6; ++ if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { ++ mb_type_col[0] &= ~MB_TYPE_INTERLACED; ++ mb_type_col[1] &= ~MB_TYPE_INTERLACED; ++ } + + sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + if( (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA) +@@ -242,7 +269,7 @@ + }else{ // AFR/FR -> AFR/FR + single_col: + mb_type_col[0] = +- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy]; ++ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy]; + + sub_mb_type |= MB_TYPE_16x16|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){ +@@ -260,10 +287,12 @@ + } + } + +- l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]]; +- l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]]; +- l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy]; +- l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy]; ++ await_reference_mb_row(h, &h->ref_list[1][0], mb_y); ++ ++ l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]]; ++ l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]]; ++ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; ++ l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; + if(!b8_stride){ + if(s->mb_y&1){ + l1ref0 += 2; +@@ -384,7 +413,7 @@ + MpegEncContext * const s = &h->s; + int b8_stride = 2; + int b4_stride = h->b_stride; +- int mb_xy = h->mb_xy; ++ int mb_xy = h->mb_xy, mb_y = s->mb_y; + int mb_type_col[2]; + const int16_t (*l1mv0)[2], (*l1mv1)[2]; + const int8_t *l1ref0, *l1ref1; +@@ -392,23 +421,32 @@ + unsigned int sub_mb_type; + int i8, i4; + +- assert(h->ref_list[1][0].reference&3); ++ assert(h->ref_list[1][0].f.reference & 3); + +- if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL +- if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL ++ await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type)); ++ ++ if (IS_INTERLACED(h->ref_list[1][0].f.mb_type[mb_xy])) { // AFL/AFR/FR/FL -> AFL/FL ++ if (!IS_INTERLACED(*mb_type)) { // AFR/FR -> AFL/FL ++ mb_y = (s->mb_y&~1) + h->col_parity; + mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; + b8_stride = 0; + }else{ +- mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity ++ mb_y += h->col_fieldoff; ++ mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity + } + goto single_col; + }else{ // AFL/AFR/FR/FL -> AFR/FR + if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR ++ mb_y = s->mb_y&~1; + mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; +- mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; +- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride]; ++ mb_type_col[0] = h->ref_list[1][0].f.mb_type[mb_xy]; ++ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy + s->mb_stride]; + b8_stride = 2+4*s->mb_stride; + b4_stride *= 6; ++ if (IS_INTERLACED(mb_type_col[0]) != IS_INTERLACED(mb_type_col[1])) { ++ mb_type_col[0] &= ~MB_TYPE_INTERLACED; ++ mb_type_col[1] &= ~MB_TYPE_INTERLACED; ++ } + + sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + +@@ -422,7 +460,7 @@ + }else{ // AFR/FR -> AFR/FR + single_col: + mb_type_col[0] = +- mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy]; ++ mb_type_col[1] = h->ref_list[1][0].f.mb_type[mb_xy]; + + sub_mb_type = MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P0L1|MB_TYPE_DIRECT2; /* B_SUB_8x8 */ + if(!is_b8x8 && (mb_type_col[0] & MB_TYPE_16x16_OR_INTRA)){ +@@ -440,10 +478,12 @@ + } + } + +- l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]]; +- l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]]; +- l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy]; +- l1ref1 = &h->ref_list[1][0].ref_index [1][4*mb_xy]; ++ await_reference_mb_row(h, &h->ref_list[1][0], mb_y); ++ ++ l1mv0 = &h->ref_list[1][0].f.motion_val[0][h->mb2b_xy [mb_xy]]; ++ l1mv1 = &h->ref_list[1][0].f.motion_val[1][h->mb2b_xy [mb_xy]]; ++ l1ref0 = &h->ref_list[1][0].f.ref_index [0][4 * mb_xy]; ++ l1ref1 = &h->ref_list[1][0].f.ref_index [1][4 * mb_xy]; + if(!b8_stride){ + if(s->mb_y&1){ + l1ref0 += 2; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp.c 2012-05-14 14:08:53.822329677 +0200 +@@ -29,293 +29,89 @@ + #include "avcodec.h" + #include "h264dsp.h" + +-#define op_scale1(x) block[x] = av_clip_uint8( (block[x]*weight + offset) >> log2_denom ) +-#define op_scale2(x) dst[x] = av_clip_uint8( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1)) +-#define H264_WEIGHT(W,H) \ +-static void weight_h264_pixels ## W ## x ## H ## _c(uint8_t *block, int stride, int log2_denom, int weight, int offset){ \ +- int y; \ +- offset <<= log2_denom; \ +- if(log2_denom) offset += 1<<(log2_denom-1); \ +- for(y=0; y> 1 ) ) >> 1) - p1, -tc0[i], tc0[i] ); +- tc++; +- } +- if( FFABS( q2 - q0 ) < beta ) { +- if(tc0[i]) +- pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc0[i], tc0[i] ); +- tc++; +- } +- +- i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); +- pix[-xstride] = av_clip_uint8( p0 + i_delta ); /* p0' */ +- pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ +- } +- pix += ystride; +- } +- } +-} +-static void h264_v_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +-{ +- h264_loop_filter_luma_c(pix, stride, 1, alpha, beta, tc0); +-} +-static void h264_h_loop_filter_luma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +-{ +- h264_loop_filter_luma_c(pix, 1, stride, alpha, beta, tc0); +-} +- +-static av_always_inline av_flatten void h264_loop_filter_luma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) +-{ +- int d; +- for( d = 0; d < 16; d++ ) { +- const int p2 = pix[-3*xstride]; +- const int p1 = pix[-2*xstride]; +- const int p0 = pix[-1*xstride]; +- +- const int q0 = pix[ 0*xstride]; +- const int q1 = pix[ 1*xstride]; +- const int q2 = pix[ 2*xstride]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { +- +- if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ +- if( FFABS( p2 - p0 ) < beta) +- { +- const int p3 = pix[-4*xstride]; +- /* p0', p1', p2' */ +- pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; +- pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; +- pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; +- } else { +- /* p0' */ +- pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; +- } +- if( FFABS( q2 - q0 ) < beta) +- { +- const int q3 = pix[3*xstride]; +- /* q0', q1', q2' */ +- pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; +- pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; +- pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; +- } else { +- /* q0' */ +- pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; +- } +- }else{ +- /* p0', q0' */ +- pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; +- pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; +- } +- } +- pix += ystride; +- } +-} +-static void h264_v_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +-{ +- h264_loop_filter_luma_intra_c(pix, stride, 1, alpha, beta); +-} +-static void h264_h_loop_filter_luma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +-{ +- h264_loop_filter_luma_intra_c(pix, 1, stride, alpha, beta); +-} +- +-static av_always_inline av_flatten void h264_loop_filter_chroma_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta, int8_t *tc0) +-{ +- int i, d; +- for( i = 0; i < 4; i++ ) { +- const int tc = tc0[i]; +- if( tc <= 0 ) { +- pix += 2*ystride; +- continue; +- } +- for( d = 0; d < 2; d++ ) { +- const int p0 = pix[-1*xstride]; +- const int p1 = pix[-2*xstride]; +- const int q0 = pix[0]; +- const int q1 = pix[1*xstride]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { +- +- int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); +- +- pix[-xstride] = av_clip_uint8( p0 + delta ); /* p0' */ +- pix[0] = av_clip_uint8( q0 - delta ); /* q0' */ +- } +- pix += ystride; +- } +- } +-} +-static void h264_v_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +-{ +- h264_loop_filter_chroma_c(pix, stride, 1, alpha, beta, tc0); +-} +-static void h264_h_loop_filter_chroma_c(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) +-{ +- h264_loop_filter_chroma_c(pix, 1, stride, alpha, beta, tc0); +-} +- +-static av_always_inline av_flatten void h264_loop_filter_chroma_intra_c(uint8_t *pix, int xstride, int ystride, int alpha, int beta) +-{ +- int d; +- for( d = 0; d < 8; d++ ) { +- const int p0 = pix[-1*xstride]; +- const int p1 = pix[-2*xstride]; +- const int q0 = pix[0]; +- const int q1 = pix[1*xstride]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { ++#define BIT_DEPTH 8 ++#include "h264dsp_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 9 ++#include "h264dsp_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "h264dsp_template.c" ++#undef BIT_DEPTH ++ ++void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) ++{ ++#undef FUNC ++#define FUNC(a, depth) a ## _ ## depth ## _c ++ ++#define H264_DSP(depth) \ ++ c->h264_idct_add= FUNC(ff_h264_idct_add, depth);\ ++ c->h264_idct8_add= FUNC(ff_h264_idct8_add, depth);\ ++ c->h264_idct_dc_add= FUNC(ff_h264_idct_dc_add, depth);\ ++ c->h264_idct8_dc_add= FUNC(ff_h264_idct8_dc_add, depth);\ ++ c->h264_idct_add16 = FUNC(ff_h264_idct_add16, depth);\ ++ c->h264_idct8_add4 = FUNC(ff_h264_idct8_add4, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_idct_add8 = FUNC(ff_h264_idct_add8, depth);\ ++ else\ ++ c->h264_idct_add8 = FUNC(ff_h264_idct_add8_422, depth);\ ++ c->h264_idct_add16intra= FUNC(ff_h264_idct_add16intra, depth);\ ++ c->h264_luma_dc_dequant_idct= FUNC(ff_h264_luma_dc_dequant_idct, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma_dc_dequant_idct, depth);\ ++ else\ ++ c->h264_chroma_dc_dequant_idct= FUNC(ff_h264_chroma422_dc_dequant_idct, depth);\ ++\ ++ c->weight_h264_pixels_tab[0]= FUNC(weight_h264_pixels16, depth);\ ++ c->weight_h264_pixels_tab[1]= FUNC(weight_h264_pixels8, depth);\ ++ c->weight_h264_pixels_tab[2]= FUNC(weight_h264_pixels4, depth);\ ++ c->weight_h264_pixels_tab[3]= FUNC(weight_h264_pixels2, depth);\ ++ c->biweight_h264_pixels_tab[0]= FUNC(biweight_h264_pixels16, depth);\ ++ c->biweight_h264_pixels_tab[1]= FUNC(biweight_h264_pixels8, depth);\ ++ c->biweight_h264_pixels_tab[2]= FUNC(biweight_h264_pixels4, depth);\ ++ c->biweight_h264_pixels_tab[3]= FUNC(biweight_h264_pixels2, depth);\ ++\ ++ c->h264_v_loop_filter_luma= FUNC(h264_v_loop_filter_luma, depth);\ ++ c->h264_h_loop_filter_luma= FUNC(h264_h_loop_filter_luma, depth);\ ++ c->h264_h_loop_filter_luma_mbaff= FUNC(h264_h_loop_filter_luma_mbaff, depth);\ ++ c->h264_v_loop_filter_luma_intra= FUNC(h264_v_loop_filter_luma_intra, depth);\ ++ c->h264_h_loop_filter_luma_intra= FUNC(h264_h_loop_filter_luma_intra, depth);\ ++ c->h264_h_loop_filter_luma_mbaff_intra= FUNC(h264_h_loop_filter_luma_mbaff_intra, depth);\ ++ c->h264_v_loop_filter_chroma= FUNC(h264_v_loop_filter_chroma, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_h_loop_filter_chroma= FUNC(h264_h_loop_filter_chroma, depth);\ ++ else\ ++ c->h264_h_loop_filter_chroma= FUNC(h264_h_loop_filter_chroma422, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_h_loop_filter_chroma_mbaff= FUNC(h264_h_loop_filter_chroma_mbaff, depth);\ ++ else\ ++ c->h264_h_loop_filter_chroma_mbaff= FUNC(h264_h_loop_filter_chroma422_mbaff, depth);\ ++ c->h264_v_loop_filter_chroma_intra= FUNC(h264_v_loop_filter_chroma_intra, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_h_loop_filter_chroma_intra= FUNC(h264_h_loop_filter_chroma_intra, depth);\ ++ else\ ++ c->h264_h_loop_filter_chroma_intra= FUNC(h264_h_loop_filter_chroma422_intra, depth);\ ++ if (chroma_format_idc == 1)\ ++ c->h264_h_loop_filter_chroma_mbaff_intra= FUNC(h264_h_loop_filter_chroma_mbaff_intra, depth);\ ++ else\ ++ c->h264_h_loop_filter_chroma_mbaff_intra= FUNC(h264_h_loop_filter_chroma422_mbaff_intra, depth);\ ++ c->h264_loop_filter_strength= NULL; + +- pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ +- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ +- } +- pix += ystride; ++ switch (bit_depth) { ++ case 9: ++ H264_DSP(9); ++ break; ++ case 10: ++ H264_DSP(10); ++ break; ++ default: ++ H264_DSP(8); ++ break; + } +-} +-static void h264_v_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +-{ +- h264_loop_filter_chroma_intra_c(pix, stride, 1, alpha, beta); +-} +-static void h264_h_loop_filter_chroma_intra_c(uint8_t *pix, int stride, int alpha, int beta) +-{ +- h264_loop_filter_chroma_intra_c(pix, 1, stride, alpha, beta); +-} +- +-void ff_h264dsp_init(H264DSPContext *c) +-{ +- c->h264_idct_add= ff_h264_idct_add_c; +- c->h264_idct8_add= ff_h264_idct8_add_c; +- c->h264_idct_dc_add= ff_h264_idct_dc_add_c; +- c->h264_idct8_dc_add= ff_h264_idct8_dc_add_c; +- c->h264_idct_add16 = ff_h264_idct_add16_c; +- c->h264_idct8_add4 = ff_h264_idct8_add4_c; +- c->h264_idct_add8 = ff_h264_idct_add8_c; +- c->h264_idct_add16intra= ff_h264_idct_add16intra_c; +- c->h264_luma_dc_dequant_idct= ff_h264_luma_dc_dequant_idct_c; +- +- c->weight_h264_pixels_tab[0]= weight_h264_pixels16x16_c; +- c->weight_h264_pixels_tab[1]= weight_h264_pixels16x8_c; +- c->weight_h264_pixels_tab[2]= weight_h264_pixels8x16_c; +- c->weight_h264_pixels_tab[3]= weight_h264_pixels8x8_c; +- c->weight_h264_pixels_tab[4]= weight_h264_pixels8x4_c; +- c->weight_h264_pixels_tab[5]= weight_h264_pixels4x8_c; +- c->weight_h264_pixels_tab[6]= weight_h264_pixels4x4_c; +- c->weight_h264_pixels_tab[7]= weight_h264_pixels4x2_c; +- c->weight_h264_pixels_tab[8]= weight_h264_pixels2x4_c; +- c->weight_h264_pixels_tab[9]= weight_h264_pixels2x2_c; +- c->biweight_h264_pixels_tab[0]= biweight_h264_pixels16x16_c; +- c->biweight_h264_pixels_tab[1]= biweight_h264_pixels16x8_c; +- c->biweight_h264_pixels_tab[2]= biweight_h264_pixels8x16_c; +- c->biweight_h264_pixels_tab[3]= biweight_h264_pixels8x8_c; +- c->biweight_h264_pixels_tab[4]= biweight_h264_pixels8x4_c; +- c->biweight_h264_pixels_tab[5]= biweight_h264_pixels4x8_c; +- c->biweight_h264_pixels_tab[6]= biweight_h264_pixels4x4_c; +- c->biweight_h264_pixels_tab[7]= biweight_h264_pixels4x2_c; +- c->biweight_h264_pixels_tab[8]= biweight_h264_pixels2x4_c; +- c->biweight_h264_pixels_tab[9]= biweight_h264_pixels2x2_c; +- +- c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_c; +- c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_c; +- c->h264_v_loop_filter_luma_intra= h264_v_loop_filter_luma_intra_c; +- c->h264_h_loop_filter_luma_intra= h264_h_loop_filter_luma_intra_c; +- c->h264_v_loop_filter_chroma= h264_v_loop_filter_chroma_c; +- c->h264_h_loop_filter_chroma= h264_h_loop_filter_chroma_c; +- c->h264_v_loop_filter_chroma_intra= h264_v_loop_filter_chroma_intra_c; +- c->h264_h_loop_filter_chroma_intra= h264_h_loop_filter_chroma_intra_c; +- c->h264_loop_filter_strength= NULL; + +- if (ARCH_ARM) ff_h264dsp_init_arm(c); +- if (HAVE_ALTIVEC) ff_h264dsp_init_ppc(c); +- if (HAVE_MMX) ff_h264dsp_init_x86(c); ++ if (ARCH_ARM) ff_h264dsp_init_arm(c, bit_depth, chroma_format_idc); ++ if (HAVE_ALTIVEC) ff_h264dsp_init_ppc(c, bit_depth, chroma_format_idc); ++ if (HAVE_MMX) ff_h264dsp_init_x86(c, bit_depth, chroma_format_idc); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp.h 2012-05-14 14:08:53.823329697 +0200 +@@ -31,27 +31,33 @@ + #include "dsputil.h" + + //typedef void (*h264_chroma_mc_func)(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int srcStride, int h, int x, int y); +-typedef void (*h264_weight_func)(uint8_t *block, int stride, int log2_denom, int weight, int offset); +-typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int log2_denom, int weightd, int weights, int offset); ++typedef void (*h264_weight_func)(uint8_t *block, int stride, int height, ++ int log2_denom, int weight, int offset); ++typedef void (*h264_biweight_func)(uint8_t *dst, uint8_t *src, int stride, int height, ++ int log2_denom, int weightd, int weights, int offset); + + /** + * Context for storing H.264 DSP functions + */ + typedef struct H264DSPContext{ + /* weighted MC */ +- h264_weight_func weight_h264_pixels_tab[10]; +- h264_biweight_func biweight_h264_pixels_tab[10]; ++ h264_weight_func weight_h264_pixels_tab[4]; ++ h264_biweight_func biweight_h264_pixels_tab[4]; + + /* loop filter */ + void (*h264_v_loop_filter_luma)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_luma)(uint8_t *pix/*align 4 */, int stride, int alpha, int beta, int8_t *tc0); ++ void (*h264_h_loop_filter_luma_mbaff)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta, int8_t *tc0); + /* v/h_loop_filter_luma_intra: align 16 */ + void (*h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); + void (*h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta); ++ void (*h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix/*align 16*/, int stride, int alpha, int beta); + void (*h264_v_loop_filter_chroma)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_h_loop_filter_chroma)(uint8_t *pix/*align 4*/, int stride, int alpha, int beta, int8_t *tc0); ++ void (*h264_h_loop_filter_chroma_mbaff)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta, int8_t *tc0); + void (*h264_v_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); + void (*h264_h_loop_filter_chroma_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); ++ void (*h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix/*align 8*/, int stride, int alpha, int beta); + // h264_loop_filter_strength: simd only. the C version is inlined in h264.c + void (*h264_loop_filter_strength)(int16_t bS[2][4][4], uint8_t nnz[40], int8_t ref[2][40], int16_t mv[2][40][2], + int bidir, int edges, int step, int mask_mv0, int mask_mv1, int field); +@@ -62,17 +68,17 @@ + void (*h264_idct_dc_add)(uint8_t *dst/*align 4*/, DCTELEM *block/*align 16*/, int stride); + void (*h264_idct8_dc_add)(uint8_t *dst/*align 8*/, DCTELEM *block/*align 16*/, int stride); + +- void (*h264_dct)(DCTELEM block[4][4]); +- void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); +- void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); +- void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); +- void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[6*8]); ++ void (*h264_idct_add16)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]); ++ void (*h264_idct8_add4)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]); ++ void (*h264_idct_add8)(uint8_t **dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]); ++ void (*h264_idct_add16intra)(uint8_t *dst/*align 16*/, const int *blockoffset, DCTELEM *block/*align 16*/, int stride, const uint8_t nnzc[15*8]); + void (*h264_luma_dc_dequant_idct)(DCTELEM *output, DCTELEM *input/*align 16*/, int qmul); ++ void (*h264_chroma_dc_dequant_idct)(DCTELEM *block, int qmul); + }H264DSPContext; + +-void ff_h264dsp_init(H264DSPContext *c); +-void ff_h264dsp_init_arm(H264DSPContext *c); +-void ff_h264dsp_init_ppc(H264DSPContext *c); +-void ff_h264dsp_init_x86(H264DSPContext *c); ++void ff_h264dsp_init(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); ++void ff_h264dsp_init_arm(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); ++void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); ++void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc); + + #endif /* AVCODEC_H264DSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264dsp_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264dsp_template.c 2012-05-14 14:08:53.825329737 +0200 +@@ -0,0 +1,328 @@ ++/* ++ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder ++ * Copyright (c) 2003-2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * H.264 / AVC / MPEG4 part10 DSP functions. ++ * @author Michael Niedermayer ++ */ ++ ++#include "bit_depth_template.c" ++ ++#define op_scale1(x) block[x] = av_clip_pixel( (block[x]*weight + offset) >> log2_denom ) ++#define op_scale2(x) dst[x] = av_clip_pixel( (src[x]*weights + dst[x]*weightd + offset) >> (log2_denom+1)) ++#define H264_WEIGHT(W) \ ++static void FUNCC(weight_h264_pixels ## W)(uint8_t *_block, int stride, int height, \ ++ int log2_denom, int weight, int offset) \ ++{ \ ++ int y; \ ++ pixel *block = (pixel*)_block; \ ++ stride >>= sizeof(pixel)-1; \ ++ offset <<= (log2_denom + (BIT_DEPTH-8)); \ ++ if(log2_denom) offset += 1<<(log2_denom-1); \ ++ for (y = 0; y < height; y++, block += stride) { \ ++ op_scale1(0); \ ++ op_scale1(1); \ ++ if(W==2) continue; \ ++ op_scale1(2); \ ++ op_scale1(3); \ ++ if(W==4) continue; \ ++ op_scale1(4); \ ++ op_scale1(5); \ ++ op_scale1(6); \ ++ op_scale1(7); \ ++ if(W==8) continue; \ ++ op_scale1(8); \ ++ op_scale1(9); \ ++ op_scale1(10); \ ++ op_scale1(11); \ ++ op_scale1(12); \ ++ op_scale1(13); \ ++ op_scale1(14); \ ++ op_scale1(15); \ ++ } \ ++} \ ++static void FUNCC(biweight_h264_pixels ## W)(uint8_t *_dst, uint8_t *_src, int stride, int height, \ ++ int log2_denom, int weightd, int weights, int offset) \ ++{ \ ++ int y; \ ++ pixel *dst = (pixel*)_dst; \ ++ pixel *src = (pixel*)_src; \ ++ stride >>= sizeof(pixel)-1; \ ++ offset <<= (BIT_DEPTH-8); \ ++ offset = ((offset + 1) | 1) << log2_denom; \ ++ for (y = 0; y < height; y++, dst += stride, src += stride) { \ ++ op_scale2(0); \ ++ op_scale2(1); \ ++ if(W==2) continue; \ ++ op_scale2(2); \ ++ op_scale2(3); \ ++ if(W==4) continue; \ ++ op_scale2(4); \ ++ op_scale2(5); \ ++ op_scale2(6); \ ++ op_scale2(7); \ ++ if(W==8) continue; \ ++ op_scale2(8); \ ++ op_scale2(9); \ ++ op_scale2(10); \ ++ op_scale2(11); \ ++ op_scale2(12); \ ++ op_scale2(13); \ ++ op_scale2(14); \ ++ op_scale2(15); \ ++ } \ ++} ++ ++H264_WEIGHT(16) ++H264_WEIGHT(8) ++H264_WEIGHT(4) ++H264_WEIGHT(2) ++ ++#undef op_scale1 ++#undef op_scale2 ++#undef H264_WEIGHT ++ ++static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0) ++{ ++ pixel *pix = (pixel*)p_pix; ++ int i, d; ++ xstride >>= sizeof(pixel)-1; ++ ystride >>= sizeof(pixel)-1; ++ alpha <<= BIT_DEPTH - 8; ++ beta <<= BIT_DEPTH - 8; ++ for( i = 0; i < 4; i++ ) { ++ const int tc_orig = tc0[i] << (BIT_DEPTH - 8); ++ if( tc_orig < 0 ) { ++ pix += inner_iters*ystride; ++ continue; ++ } ++ for( d = 0; d < inner_iters; d++ ) { ++ const int p0 = pix[-1*xstride]; ++ const int p1 = pix[-2*xstride]; ++ const int p2 = pix[-3*xstride]; ++ const int q0 = pix[0]; ++ const int q1 = pix[1*xstride]; ++ const int q2 = pix[2*xstride]; ++ ++ if( FFABS( p0 - q0 ) < alpha && ++ FFABS( p1 - p0 ) < beta && ++ FFABS( q1 - q0 ) < beta ) { ++ ++ int tc = tc_orig; ++ int i_delta; ++ ++ if( FFABS( p2 - p0 ) < beta ) { ++ if(tc_orig) ++ pix[-2*xstride] = p1 + av_clip( (( p2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - p1, -tc_orig, tc_orig ); ++ tc++; ++ } ++ if( FFABS( q2 - q0 ) < beta ) { ++ if(tc_orig) ++ pix[ xstride] = q1 + av_clip( (( q2 + ( ( p0 + q0 + 1 ) >> 1 ) ) >> 1) - q1, -tc_orig, tc_orig ); ++ tc++; ++ } ++ ++ i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); ++ pix[-xstride] = av_clip_pixel( p0 + i_delta ); /* p0' */ ++ pix[0] = av_clip_pixel( q0 - i_delta ); /* q0' */ ++ } ++ pix += ystride; ++ } ++ } ++} ++static void FUNCC(h264_v_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_luma)(pix, stride, sizeof(pixel), 4, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_luma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_luma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_luma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0); ++} ++ ++static av_always_inline av_flatten void FUNCC(h264_loop_filter_luma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta) ++{ ++ pixel *pix = (pixel*)p_pix; ++ int d; ++ xstride >>= sizeof(pixel)-1; ++ ystride >>= sizeof(pixel)-1; ++ alpha <<= BIT_DEPTH - 8; ++ beta <<= BIT_DEPTH - 8; ++ for( d = 0; d < 4 * inner_iters; d++ ) { ++ const int p2 = pix[-3*xstride]; ++ const int p1 = pix[-2*xstride]; ++ const int p0 = pix[-1*xstride]; ++ ++ const int q0 = pix[ 0*xstride]; ++ const int q1 = pix[ 1*xstride]; ++ const int q2 = pix[ 2*xstride]; ++ ++ if( FFABS( p0 - q0 ) < alpha && ++ FFABS( p1 - p0 ) < beta && ++ FFABS( q1 - q0 ) < beta ) { ++ ++ if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ ++ if( FFABS( p2 - p0 ) < beta) ++ { ++ const int p3 = pix[-4*xstride]; ++ /* p0', p1', p2' */ ++ pix[-1*xstride] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; ++ pix[-2*xstride] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; ++ pix[-3*xstride] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; ++ } else { ++ /* p0' */ ++ pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; ++ } ++ if( FFABS( q2 - q0 ) < beta) ++ { ++ const int q3 = pix[3*xstride]; ++ /* q0', q1', q2' */ ++ pix[0*xstride] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; ++ pix[1*xstride] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; ++ pix[2*xstride] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; ++ } else { ++ /* q0' */ ++ pix[0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; ++ } ++ }else{ ++ /* p0', q0' */ ++ pix[-1*xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; ++ pix[ 0*xstride] = ( 2*q1 + q0 + p1 + 2 ) >> 2; ++ } ++ } ++ pix += ystride; ++ } ++} ++static void FUNCC(h264_v_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_luma_intra)(pix, stride, sizeof(pixel), 4, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_luma_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_luma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_luma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta); ++} ++ ++static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta, int8_t *tc0) ++{ ++ pixel *pix = (pixel*)p_pix; ++ int i, d; ++ alpha <<= BIT_DEPTH - 8; ++ beta <<= BIT_DEPTH - 8; ++ xstride >>= sizeof(pixel)-1; ++ ystride >>= sizeof(pixel)-1; ++ for( i = 0; i < 4; i++ ) { ++ const int tc = ((tc0[i] - 1) << (BIT_DEPTH - 8)) + 1; ++ if( tc <= 0 ) { ++ pix += inner_iters*ystride; ++ continue; ++ } ++ for( d = 0; d < inner_iters; d++ ) { ++ const int p0 = pix[-1*xstride]; ++ const int p1 = pix[-2*xstride]; ++ const int q0 = pix[0]; ++ const int q1 = pix[1*xstride]; ++ ++ if( FFABS( p0 - q0 ) < alpha && ++ FFABS( p1 - p0 ) < beta && ++ FFABS( q1 - q0 ) < beta ) { ++ ++ int delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); ++ ++ pix[-xstride] = av_clip_pixel( p0 + delta ); /* p0' */ ++ pix[0] = av_clip_pixel( q0 - delta ); /* q0' */ ++ } ++ pix += ystride; ++ } ++ } ++} ++static void FUNCC(h264_v_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_chroma)(pix, stride, sizeof(pixel), 2, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_chroma)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_chroma_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 1, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_chroma422)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 4, alpha, beta, tc0); ++} ++static void FUNCC(h264_h_loop_filter_chroma422_mbaff)(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++{ ++ FUNCC(h264_loop_filter_chroma)(pix, sizeof(pixel), stride, 2, alpha, beta, tc0); ++} ++ ++static av_always_inline av_flatten void FUNCC(h264_loop_filter_chroma_intra)(uint8_t *p_pix, int xstride, int ystride, int inner_iters, int alpha, int beta) ++{ ++ pixel *pix = (pixel*)p_pix; ++ int d; ++ xstride >>= sizeof(pixel)-1; ++ ystride >>= sizeof(pixel)-1; ++ alpha <<= BIT_DEPTH - 8; ++ beta <<= BIT_DEPTH - 8; ++ for( d = 0; d < 4 * inner_iters; d++ ) { ++ const int p0 = pix[-1*xstride]; ++ const int p1 = pix[-2*xstride]; ++ const int q0 = pix[0]; ++ const int q1 = pix[1*xstride]; ++ ++ if( FFABS( p0 - q0 ) < alpha && ++ FFABS( p1 - p0 ) < beta && ++ FFABS( q1 - q0 ) < beta ) { ++ ++ pix[-xstride] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ ++ pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ ++ } ++ pix += ystride; ++ } ++} ++static void FUNCC(h264_v_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_chroma_intra)(pix, stride, sizeof(pixel), 2, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_chroma_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_chroma_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 1, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_chroma422_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 4, alpha, beta); ++} ++static void FUNCC(h264_h_loop_filter_chroma422_mbaff_intra)(uint8_t *pix, int stride, int alpha, int beta) ++{ ++ FUNCC(h264_loop_filter_chroma_intra)(pix, sizeof(pixel), stride, 2, alpha, beta); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264.h 2012-05-14 14:08:53.797329174 +0200 +@@ -39,16 +39,6 @@ + #define interlaced_dct interlaced_dct_is_a_bad_name + #define mb_intra mb_intra_is_not_initialized_see_mb_type + +-#define LUMA_DC_BLOCK_INDEX 24 +-#define CHROMA_DC_BLOCK_INDEX 25 +- +-#define CHROMA_DC_COEFF_TOKEN_VLC_BITS 8 +-#define COEFF_TOKEN_VLC_BITS 8 +-#define TOTAL_ZEROS_VLC_BITS 9 +-#define CHROMA_DC_TOTAL_ZEROS_VLC_BITS 3 +-#define RUN_VLC_BITS 3 +-#define RUN7_VLC_BITS 6 +- + #define MAX_SPS_COUNT 32 + #define MAX_PPS_COUNT 256 + +@@ -56,12 +46,12 @@ + + #define MAX_DELAYED_PIC_COUNT 16 + ++#define MAX_MBPAIR_SIZE (256*1024) // a tighter bound could be calculated if someone cares about a few bytes ++ + /* Compiling in interlaced support reduces the speed + * of progressive decoding by about 2%. */ + #define ALLOW_INTERLACE + +-#define ALLOW_NOCHROMA +- + #define FMO 0 + + /** +@@ -75,6 +65,10 @@ + #define MB_FIELD h->mb_field_decoding_flag + #define FRAME_MBAFF h->mb_aff_frame + #define FIELD_PICTURE (s->picture_structure != PICT_FRAME) ++#define LEFT_MBS 2 ++#define LTOP 0 ++#define LBOT 1 ++#define LEFT(i) (i) + #else + #define MB_MBAFF 0 + #define MB_FIELD 0 +@@ -82,19 +76,20 @@ + #define FIELD_PICTURE 0 + #undef IS_INTERLACED + #define IS_INTERLACED(mb_type) 0 ++#define LEFT_MBS 1 ++#define LTOP 0 ++#define LBOT 0 ++#define LEFT(i) 0 + #endif + #define FIELD_OR_MBAFF_PICTURE (FRAME_MBAFF || FIELD_PICTURE) + +-#ifdef ALLOW_NOCHROMA +-#define CHROMA h->sps.chroma_format_idc +-#else +-#define CHROMA 1 +-#endif +- + #ifndef CABAC + #define CABAC h->pps.cabac + #endif + ++#define CHROMA422 (h->sps.chroma_format_idc == 2) ++#define CHROMA444 (h->sps.chroma_format_idc == 3) ++ + #define EXTENDED_SAR 255 + + #define MB_TYPE_REF0 MB_TYPE_ACPRED //dirty but it fits in 16 bit +@@ -108,6 +103,7 @@ + */ + #define DELAYED_PIC_REF 4 + ++#define QP_MAX_NUM (51 + 4*6) // The maximum supported qp + + /* NAL unit types */ + enum { +@@ -197,7 +193,7 @@ + int num_reorder_frames; + int scaling_matrix_present; + uint8_t scaling_matrix4[6][16]; +- uint8_t scaling_matrix8[2][64]; ++ uint8_t scaling_matrix8[6][64]; + int nal_hrd_parameters_present_flag; + int vcl_hrd_parameters_present_flag; + int pic_struct_present_flag; +@@ -232,8 +228,8 @@ + int redundant_pic_cnt_present; ///< redundant_pic_cnt_present_flag + int transform_8x8_mode; ///< transform_8x8_mode_flag + uint8_t scaling_matrix4[6][16]; +- uint8_t scaling_matrix8[2][64]; +- uint8_t chroma_qp_table[2][64]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table ++ uint8_t scaling_matrix8[6][64]; ++ uint8_t chroma_qp_table[2][QP_MAX_NUM+1]; ///< pre-scaled (with chroma_qp_index_offset) version of qp_table + int chroma_qp_diff; + }PPS; + +@@ -265,6 +261,7 @@ + typedef struct H264Context{ + MpegEncContext s; + H264DSPContext h264dsp; ++ int pixel_shift; ///< 0 for 8-bit H264, 1 for high-bit-depth H264 + int chroma_qp[2]; //QPc + + int qp_thresh; ///< QP threshold to skip loopfilter +@@ -279,12 +276,12 @@ + int topleft_mb_xy; + int top_mb_xy; + int topright_mb_xy; +- int left_mb_xy[2]; ++ int left_mb_xy[LEFT_MBS]; + + int topleft_type; + int top_type; + int topright_type; +- int left_type[2]; ++ int left_type[LEFT_MBS]; + + const uint8_t * left_block; + int topleft_partition; +@@ -296,21 +293,15 @@ + unsigned int top_samples_available; + unsigned int topright_samples_available; + unsigned int left_samples_available; +- uint8_t (*top_borders[2])[16+2*8]; ++ uint8_t (*top_borders[2])[(16*3)*2]; + + /** + * non zero coeff count cache. + * is 64 if not available. + */ +- DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[6*8]; ++ DECLARE_ALIGNED(8, uint8_t, non_zero_count_cache)[15*8]; + +- /* +- .UU.YYYY +- .UU.YYYY +- .vv.YYYY +- .VV.YYYY +- */ +- uint8_t (*non_zero_count)[32]; ++ uint8_t (*non_zero_count)[48]; + + /** + * Motion vector cache. +@@ -321,11 +312,6 @@ + #define PART_NOT_AVAILABLE -2 + + /** +- * is 1 if the specific list MV&references are set to 0,0,-2. +- */ +- int mv_cache_clean[2]; +- +- /** + * number of neighbors (top and/or left) that used 8x8 dct + */ + int neighbor_transform_size; +@@ -334,7 +320,7 @@ + * block_offset[ 0..23] for frame macroblocks + * block_offset[24..47] for field macroblocks + */ +- int block_offset[2*(16+8)]; ++ int block_offset[2*(16*3)]; + + uint32_t *mb2b_xy; //FIXME are these 4 a good idea? + uint32_t *mb2br_xy; +@@ -353,10 +339,10 @@ + */ + PPS pps; //FIXME move to Picture perhaps? (->no) do we need that? + +- uint32_t dequant4_buffer[6][52][16]; //FIXME should these be moved down? +- uint32_t dequant8_buffer[2][52][64]; ++ uint32_t dequant4_buffer[6][QP_MAX_NUM+1][16]; //FIXME should these be moved down? ++ uint32_t dequant8_buffer[6][QP_MAX_NUM+1][64]; + uint32_t (*dequant4_coeff[6])[16]; +- uint32_t (*dequant8_coeff[2])[64]; ++ uint32_t (*dequant8_coeff[6])[64]; + + int slice_num; + uint16_t *slice_table; ///< slice_table_base + 2*mb_stride + 1 +@@ -392,9 +378,9 @@ + /** + * num_ref_idx_l0/1_active_minus1 + 1 + */ ++ uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type + unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode + unsigned int list_count; +- uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type + Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. + Reordered version of default_ref_list + according to picture reordering in slice header */ +@@ -406,15 +392,15 @@ + GetBitContext *intra_gb_ptr; + GetBitContext *inter_gb_ptr; + +- DECLARE_ALIGNED(16, DCTELEM, mb)[16*24]; +- DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[16]; +- DCTELEM mb_padding[256]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb ++ DECLARE_ALIGNED(16, DCTELEM, mb)[16*48*2]; ///< as a dct coeffecient is int32_t in high depth, we need to reserve twice the space. ++ DECLARE_ALIGNED(16, DCTELEM, mb_luma_dc)[3][16*2]; ++ DCTELEM mb_padding[256*2]; ///< as mb is addressed by scantable[i] and scantable is uint8_t we can either check that i is not too large or ensure that there is some unused stuff after mb + + /** + * Cabac + */ + CABACContext cabac; +- uint8_t cabac_state[460]; ++ uint8_t cabac_state[1024]; + + /* 0x100 -> non null luma_dc, 0x80/0x40 -> non null chroma_dc (cb/cr), 0x?0 -> chroma_cbp(0,1,2), 0x0? luma_cbp */ + uint16_t *cbp_table; +@@ -504,13 +490,17 @@ + Picture *long_ref[32]; + Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture + Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size? ++ int last_pocs[MAX_DELAYED_PIC_COUNT]; ++ Picture *next_output_pic; + int outputed_poc; ++ int next_outputed_poc; + + /** + * memory management control operations buffer. + */ + MMCO mmco[MAX_MMCO_COUNT]; + int mmco_index; ++ int mmco_reset; + + int long_ref_count; ///< number of actual long term references + int short_ref_count; ///< number of actual short term references +@@ -518,7 +508,7 @@ + int cabac_init_idc; + + /** +- * @defgroup multithreading Members for slice based multithreading ++ * @name Members for slice based multithreading + * @{ + */ + struct H264Context *thread_context[MAX_THREADS]; +@@ -583,6 +573,13 @@ + * frames. + */ + int sei_recovery_frame_cnt; ++ /** ++ * recovery_frame is the frame_num at which the next frame should ++ * be fully constructed. ++ * ++ * Set to -1 when not expecting a recovery point. ++ */ ++ int recovery_frame; + + int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag + int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag +@@ -593,16 +590,19 @@ + int sei_buffering_period_present; ///< Buffering period SEI flag + int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs + +- //SVQ3 specific fields +- int halfpel_flag; +- int thirdpel_flag; +- int unknown_svq3_flag; +- int next_slice_index; +- uint32_t svq3_watermark_key; ++ int cur_chroma_format_idc; ++ ++ int16_t slice_row[MAX_SLICES]; ///< to detect when MAX_SLICES is too low ++ ++ int sync; ///< did we had a keyframe or recovery point ++ ++ uint8_t parse_history[4]; ++ int parse_history_count; ++ int parse_last_mb; + }H264Context; + + +-extern const uint8_t ff_h264_chroma_qp[52]; ++extern const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM+1]; ///< One chroma qp table for each possible bit depth (8-12). + + /** + * Decode SEI +@@ -673,28 +673,24 @@ + */ + int ff_h264_check_intra4x4_pred_mode(H264Context *h); + +-/** +- * Check if the top & left blocks are available if needed & change the dc mode so it only uses the available blocks. +- */ +-int ff_h264_check_intra_pred_mode(H264Context *h, int mode); ++int ff_h264_check_intra_pred_mode(H264Context *h, int mode, int is_chroma); + +-void ff_h264_write_back_intra_pred_mode(H264Context *h); + void ff_h264_hl_decode_mb(H264Context *h); + int ff_h264_frame_start(H264Context *h); +-int ff_h264_decode_extradata(H264Context *h); ++int ff_h264_decode_extradata(H264Context *h, const uint8_t *buf, int size); + av_cold int ff_h264_decode_init(AVCodecContext *avctx); + av_cold int ff_h264_decode_end(AVCodecContext *avctx); + av_cold void ff_h264_decode_init_vlc(void); + + /** + * Decode a macroblock +- * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed ++ * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed + */ + int ff_h264_decode_mb_cavlc(H264Context *h); + + /** + * Decode a CABAC coded macroblock +- * @return 0 if OK, AC_ERROR / DC_ERROR / MV_ERROR if an error is noticed ++ * @return 0 if OK, ER_AC_ERROR / ER_DC_ERROR / ER_MV_ERROR if an error is noticed + */ + int ff_h264_decode_mb_cabac(H264Context *h); + +@@ -726,27 +722,43 @@ + */ + + /* Scan8 organization: +- * 0 1 2 3 4 5 6 7 +- * 0 u u y y y y y +- * 1 u U U y Y Y Y Y +- * 2 u U U y Y Y Y Y +- * 3 v v y Y Y Y Y +- * 4 v V V y Y Y Y Y +- * 5 v V V DYDUDV ++ * 0 1 2 3 4 5 6 7 ++ * 0 DY y y y y y ++ * 1 y Y Y Y Y ++ * 2 y Y Y Y Y ++ * 3 y Y Y Y Y ++ * 4 y Y Y Y Y ++ * 5 DU u u u u u ++ * 6 u U U U U ++ * 7 u U U U U ++ * 8 u U U U U ++ * 9 u U U U U ++ * 10 DV v v v v v ++ * 11 v V V V V ++ * 12 v V V V V ++ * 13 v V V V V ++ * 14 v V V V V + * DY/DU/DV are for luma/chroma DC. + */ + ++#define LUMA_DC_BLOCK_INDEX 48 ++#define CHROMA_DC_BLOCK_INDEX 49 ++ + //This table must be here because scan8[constant] must be known at compiletime +-static const uint8_t scan8[16 + 2*4 + 3]={ +- 4+1*8, 5+1*8, 4+2*8, 5+2*8, +- 6+1*8, 7+1*8, 6+2*8, 7+2*8, +- 4+3*8, 5+3*8, 4+4*8, 5+4*8, +- 6+3*8, 7+3*8, 6+4*8, 7+4*8, +- 1+1*8, 2+1*8, +- 1+2*8, 2+2*8, +- 1+4*8, 2+4*8, +- 1+5*8, 2+5*8, +- 4+5*8, 5+5*8, 6+5*8 ++static const uint8_t scan8[16*3 + 3]={ ++ 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8, ++ 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8, ++ 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8, ++ 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8, ++ 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8, ++ 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8, ++ 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8, ++ 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8, ++ 4+11*8, 5+11*8, 4+12*8, 5+12*8, ++ 6+11*8, 7+11*8, 6+12*8, 7+12*8, ++ 4+13*8, 5+13*8, 4+14*8, 5+14*8, ++ 6+13*8, 7+13*8, 6+14*8, 7+14*8, ++ 0+ 0*8, 0+ 5*8, 0+10*8 + }; + + static av_always_inline uint32_t pack16to32(int a, int b){ +@@ -766,423 +778,16 @@ + } + + /** +- * gets the chroma qp. ++ * Get the chroma qp. + */ +-static inline int get_chroma_qp(H264Context *h, int t, int qscale){ ++static av_always_inline int get_chroma_qp(H264Context *h, int t, int qscale){ + return h->pps.chroma_qp_table[t][qscale]; + } + +-static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my); +- +-static void fill_decode_neighbors(H264Context *h, int mb_type){ +- MpegEncContext * const s = &h->s; +- const int mb_xy= h->mb_xy; +- int topleft_xy, top_xy, topright_xy, left_xy[2]; +- static const uint8_t left_block_options[4][16]={ +- {0,1,2,3,7,10,8,11,7+0*8, 7+1*8, 7+2*8, 7+3*8, 2+0*8, 2+3*8, 2+1*8, 2+2*8}, +- {2,2,3,3,8,11,8,11,7+2*8, 7+2*8, 7+3*8, 7+3*8, 2+1*8, 2+2*8, 2+1*8, 2+2*8}, +- {0,0,1,1,7,10,7,10,7+0*8, 7+0*8, 7+1*8, 7+1*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8}, +- {0,2,0,2,7,10,7,10,7+0*8, 7+2*8, 7+0*8, 7+2*8, 2+0*8, 2+3*8, 2+0*8, 2+3*8} +- }; +- +- h->topleft_partition= -1; +- +- top_xy = mb_xy - (s->mb_stride << MB_FIELD); +- +- /* Wow, what a mess, why didn't they simplify the interlacing & intra +- * stuff, I can't imagine that these complex rules are worth it. */ +- +- topleft_xy = top_xy - 1; +- topright_xy= top_xy + 1; +- left_xy[1] = left_xy[0] = mb_xy-1; +- h->left_block = left_block_options[0]; +- if(FRAME_MBAFF){ +- const int left_mb_field_flag = IS_INTERLACED(s->current_picture.mb_type[mb_xy-1]); +- const int curr_mb_field_flag = IS_INTERLACED(mb_type); +- if(s->mb_y&1){ +- if (left_mb_field_flag != curr_mb_field_flag) { +- left_xy[1] = left_xy[0] = mb_xy - s->mb_stride - 1; +- if (curr_mb_field_flag) { +- left_xy[1] += s->mb_stride; +- h->left_block = left_block_options[3]; +- } else { +- topleft_xy += s->mb_stride; +- // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition +- h->topleft_partition = 0; +- h->left_block = left_block_options[1]; +- } +- } +- }else{ +- if(curr_mb_field_flag){ +- topleft_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy - 1]>>7)&1)-1); +- topright_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy + 1]>>7)&1)-1); +- top_xy += s->mb_stride & (((s->current_picture.mb_type[top_xy ]>>7)&1)-1); +- } +- if (left_mb_field_flag != curr_mb_field_flag) { +- if (curr_mb_field_flag) { +- left_xy[1] += s->mb_stride; +- h->left_block = left_block_options[3]; +- } else { +- h->left_block = left_block_options[2]; +- } +- } +- } +- } +- +- h->topleft_mb_xy = topleft_xy; +- h->top_mb_xy = top_xy; +- h->topright_mb_xy= topright_xy; +- h->left_mb_xy[0] = left_xy[0]; +- h->left_mb_xy[1] = left_xy[1]; +- //FIXME do we need all in the context? +- +- h->topleft_type = s->current_picture.mb_type[topleft_xy] ; +- h->top_type = s->current_picture.mb_type[top_xy] ; +- h->topright_type= s->current_picture.mb_type[topright_xy]; +- h->left_type[0] = s->current_picture.mb_type[left_xy[0]] ; +- h->left_type[1] = s->current_picture.mb_type[left_xy[1]] ; +- +- if(FMO){ +- if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0; +- if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0; +- if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0; +- }else{ +- if(h->slice_table[topleft_xy ] != h->slice_num){ +- h->topleft_type = 0; +- if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0; +- if(h->slice_table[left_xy[0] ] != h->slice_num) h->left_type[0] = h->left_type[1] = 0; +- } +- } +- if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0; +-} +- +-static void fill_decode_caches(H264Context *h, int mb_type){ +- MpegEncContext * const s = &h->s; +- int topleft_xy, top_xy, topright_xy, left_xy[2]; +- int topleft_type, top_type, topright_type, left_type[2]; +- const uint8_t * left_block= h->left_block; +- int i; +- +- topleft_xy = h->topleft_mb_xy ; +- top_xy = h->top_mb_xy ; +- topright_xy = h->topright_mb_xy; +- left_xy[0] = h->left_mb_xy[0] ; +- left_xy[1] = h->left_mb_xy[1] ; +- topleft_type = h->topleft_type ; +- top_type = h->top_type ; +- topright_type= h->topright_type ; +- left_type[0] = h->left_type[0] ; +- left_type[1] = h->left_type[1] ; +- +- if(!IS_SKIP(mb_type)){ +- if(IS_INTRA(mb_type)){ +- int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; +- h->topleft_samples_available= +- h->top_samples_available= +- h->left_samples_available= 0xFFFF; +- h->topright_samples_available= 0xEEEA; +- +- if(!(top_type & type_mask)){ +- h->topleft_samples_available= 0xB3FF; +- h->top_samples_available= 0x33FF; +- h->topright_samples_available= 0x26EA; +- } +- if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[0])){ +- if(IS_INTERLACED(mb_type)){ +- if(!(left_type[0] & type_mask)){ +- h->topleft_samples_available&= 0xDFFF; +- h->left_samples_available&= 0x5FFF; +- } +- if(!(left_type[1] & type_mask)){ +- h->topleft_samples_available&= 0xFF5F; +- h->left_samples_available&= 0xFF5F; +- } +- }else{ +- int left_typei = s->current_picture.mb_type[left_xy[0] + s->mb_stride]; +- +- assert(left_xy[0] == left_xy[1]); +- if(!((left_typei & type_mask) && (left_type[0] & type_mask))){ +- h->topleft_samples_available&= 0xDF5F; +- h->left_samples_available&= 0x5F5F; +- } +- } +- }else{ +- if(!(left_type[0] & type_mask)){ +- h->topleft_samples_available&= 0xDF5F; +- h->left_samples_available&= 0x5F5F; +- } +- } +- +- if(!(topleft_type & type_mask)) +- h->topleft_samples_available&= 0x7FFF; +- +- if(!(topright_type & type_mask)) +- h->topright_samples_available&= 0xFBFF; +- +- if(IS_INTRA4x4(mb_type)){ +- if(IS_INTRA4x4(top_type)){ +- AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); +- }else{ +- h->intra4x4_pred_mode_cache[4+8*0]= +- h->intra4x4_pred_mode_cache[5+8*0]= +- h->intra4x4_pred_mode_cache[6+8*0]= +- h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask); +- } +- for(i=0; i<2; i++){ +- if(IS_INTRA4x4(left_type[i])){ +- int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[i]]; +- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]]; +- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]]; +- }else{ +- h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= +- h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[i] & type_mask); +- } +- } +- } +- } +- +- +-/* +-0 . T T. T T T T +-1 L . .L . . . . +-2 L . .L . . . . +-3 . T TL . . . . +-4 L . .L . . . . +-5 L . .. . . . . +-*/ +-//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec) +- if(top_type){ +- AV_COPY32(&h->non_zero_count_cache[4+8*0], &h->non_zero_count[top_xy][4+3*8]); +- h->non_zero_count_cache[1+8*0]= h->non_zero_count[top_xy][1+1*8]; +- h->non_zero_count_cache[2+8*0]= h->non_zero_count[top_xy][2+1*8]; +- +- h->non_zero_count_cache[1+8*3]= h->non_zero_count[top_xy][1+2*8]; +- h->non_zero_count_cache[2+8*3]= h->non_zero_count[top_xy][2+2*8]; +- }else { +- h->non_zero_count_cache[1+8*0]= +- h->non_zero_count_cache[2+8*0]= +- +- h->non_zero_count_cache[1+8*3]= +- h->non_zero_count_cache[2+8*3]= +- AV_WN32A(&h->non_zero_count_cache[4+8*0], CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040); +- } +- +- for (i=0; i<2; i++) { +- if(left_type[i]){ +- h->non_zero_count_cache[3+8*1 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+0+2*i]]; +- h->non_zero_count_cache[3+8*2 + 2*8*i]= h->non_zero_count[left_xy[i]][left_block[8+1+2*i]]; +- h->non_zero_count_cache[0+8*1 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+4+2*i]]; +- h->non_zero_count_cache[0+8*4 + 8*i]= h->non_zero_count[left_xy[i]][left_block[8+5+2*i]]; +- }else{ +- h->non_zero_count_cache[3+8*1 + 2*8*i]= +- h->non_zero_count_cache[3+8*2 + 2*8*i]= +- h->non_zero_count_cache[0+8*1 + 8*i]= +- h->non_zero_count_cache[0+8*4 + 8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; +- } +- } +- +- if( CABAC ) { +- // top_cbp +- if(top_type) { +- h->top_cbp = h->cbp_table[top_xy]; +- } else { +- h->top_cbp = IS_INTRA(mb_type) ? 0x1CF : 0x00F; +- } +- // left_cbp +- if (left_type[0]) { +- h->left_cbp = (h->cbp_table[left_xy[0]] & 0x1f0) +- | ((h->cbp_table[left_xy[0]]>>(left_block[0]&(~1)))&2) +- | (((h->cbp_table[left_xy[1]]>>(left_block[2]&(~1)))&2) << 2); +- } else { +- h->left_cbp = IS_INTRA(mb_type) ? 0x1CF : 0x00F; +- } +- } +- } +- +-#if 1 +- if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ +- int list; +- for(list=0; listlist_count; list++){ +- if(!USES_LIST(mb_type, list)){ +- /*if(!h->mv_cache_clean[list]){ +- memset(h->mv_cache [list], 0, 8*5*2*sizeof(int16_t)); //FIXME clean only input? clean at all? +- memset(h->ref_cache[list], PART_NOT_AVAILABLE, 8*5*sizeof(int8_t)); +- h->mv_cache_clean[list]= 1; +- }*/ +- continue; +- } +- assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); +- +- h->mv_cache_clean[list]= 0; +- +- if(USES_LIST(top_type, list)){ +- const int b_xy= h->mb2b_xy[top_xy] + 3*h->b_stride; +- AV_COPY128(h->mv_cache[list][scan8[0] + 0 - 1*8], s->current_picture.motion_val[list][b_xy + 0]); +- h->ref_cache[list][scan8[0] + 0 - 1*8]= +- h->ref_cache[list][scan8[0] + 1 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 2]; +- h->ref_cache[list][scan8[0] + 2 - 1*8]= +- h->ref_cache[list][scan8[0] + 3 - 1*8]= s->current_picture.ref_index[list][4*top_xy + 3]; +- }else{ +- AV_ZERO128(h->mv_cache[list][scan8[0] + 0 - 1*8]); +- AV_WN32A(&h->ref_cache[list][scan8[0] + 0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101); +- } +- +- if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){ +- for(i=0; i<2; i++){ +- int cache_idx = scan8[0] - 1 + i*2*8; +- if(USES_LIST(left_type[i], list)){ +- const int b_xy= h->mb2b_xy[left_xy[i]] + 3; +- const int b8_xy= 4*left_xy[i] + 1; +- AV_COPY32(h->mv_cache[list][cache_idx ], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0+i*2]]); +- AV_COPY32(h->mv_cache[list][cache_idx+8], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[1+i*2]]); +- h->ref_cache[list][cache_idx ]= s->current_picture.ref_index[list][b8_xy + (left_block[0+i*2]&~1)]; +- h->ref_cache[list][cache_idx+8]= s->current_picture.ref_index[list][b8_xy + (left_block[1+i*2]&~1)]; +- }else{ +- AV_ZERO32(h->mv_cache [list][cache_idx ]); +- AV_ZERO32(h->mv_cache [list][cache_idx+8]); +- h->ref_cache[list][cache_idx ]= +- h->ref_cache[list][cache_idx+8]= (left_type[i]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; +- } +- } +- }else{ +- if(USES_LIST(left_type[0], list)){ +- const int b_xy= h->mb2b_xy[left_xy[0]] + 3; +- const int b8_xy= 4*left_xy[0] + 1; +- AV_COPY32(h->mv_cache[list][scan8[0] - 1], s->current_picture.motion_val[list][b_xy + h->b_stride*left_block[0]]); +- h->ref_cache[list][scan8[0] - 1]= s->current_picture.ref_index[list][b8_xy + (left_block[0]&~1)]; +- }else{ +- AV_ZERO32(h->mv_cache [list][scan8[0] - 1]); +- h->ref_cache[list][scan8[0] - 1]= left_type[0] ? LIST_NOT_USED : PART_NOT_AVAILABLE; +- } +- } +- +- if(USES_LIST(topright_type, list)){ +- const int b_xy= h->mb2b_xy[topright_xy] + 3*h->b_stride; +- AV_COPY32(h->mv_cache[list][scan8[0] + 4 - 1*8], s->current_picture.motion_val[list][b_xy]); +- h->ref_cache[list][scan8[0] + 4 - 1*8]= s->current_picture.ref_index[list][4*topright_xy + 2]; +- }else{ +- AV_ZERO32(h->mv_cache [list][scan8[0] + 4 - 1*8]); +- h->ref_cache[list][scan8[0] + 4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; +- } +- if(h->ref_cache[list][scan8[0] + 4 - 1*8] < 0){ +- if(USES_LIST(topleft_type, list)){ +- const int b_xy = h->mb2b_xy [topleft_xy] + 3 + h->b_stride + (h->topleft_partition & 2*h->b_stride); +- const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2); +- AV_COPY32(h->mv_cache[list][scan8[0] - 1 - 1*8], s->current_picture.motion_val[list][b_xy]); +- h->ref_cache[list][scan8[0] - 1 - 1*8]= s->current_picture.ref_index[list][b8_xy]; +- }else{ +- AV_ZERO32(h->mv_cache[list][scan8[0] - 1 - 1*8]); +- h->ref_cache[list][scan8[0] - 1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; +- } +- } +- +- if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) +- continue; +- +- if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))) { +- h->ref_cache[list][scan8[4 ]] = +- h->ref_cache[list][scan8[12]] = PART_NOT_AVAILABLE; +- AV_ZERO32(h->mv_cache [list][scan8[4 ]]); +- AV_ZERO32(h->mv_cache [list][scan8[12]]); +- +- if( CABAC ) { +- /* XXX beurk, Load mvd */ +- if(USES_LIST(top_type, list)){ +- const int b_xy= h->mb2br_xy[top_xy]; +- AV_COPY64(h->mvd_cache[list][scan8[0] + 0 - 1*8], h->mvd_table[list][b_xy + 0]); +- }else{ +- AV_ZERO64(h->mvd_cache[list][scan8[0] + 0 - 1*8]); +- } +- if(USES_LIST(left_type[0], list)){ +- const int b_xy= h->mb2br_xy[left_xy[0]] + 6; +- AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 0*8], h->mvd_table[list][b_xy - left_block[0]]); +- AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 1*8], h->mvd_table[list][b_xy - left_block[1]]); +- }else{ +- AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 0*8]); +- AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 1*8]); +- } +- if(USES_LIST(left_type[1], list)){ +- const int b_xy= h->mb2br_xy[left_xy[1]] + 6; +- AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 2*8], h->mvd_table[list][b_xy - left_block[2]]); +- AV_COPY16(h->mvd_cache[list][scan8[0] - 1 + 3*8], h->mvd_table[list][b_xy - left_block[3]]); +- }else{ +- AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 2*8]); +- AV_ZERO16(h->mvd_cache [list][scan8[0] - 1 + 3*8]); +- } +- AV_ZERO16(h->mvd_cache [list][scan8[4 ]]); +- AV_ZERO16(h->mvd_cache [list][scan8[12]]); +- if(h->slice_type_nos == FF_B_TYPE){ +- fill_rectangle(&h->direct_cache[scan8[0]], 4, 4, 8, MB_TYPE_16x16>>1, 1); +- +- if(IS_DIRECT(top_type)){ +- AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1)); +- }else if(IS_8X8(top_type)){ +- int b8_xy = 4*top_xy; +- h->direct_cache[scan8[0] + 0 - 1*8]= h->direct_table[b8_xy + 2]; +- h->direct_cache[scan8[0] + 2 - 1*8]= h->direct_table[b8_xy + 3]; +- }else{ +- AV_WN32A(&h->direct_cache[scan8[0] - 1*8], 0x01010101*(MB_TYPE_16x16>>1)); +- } +- +- if(IS_DIRECT(left_type[0])) +- h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_DIRECT2>>1; +- else if(IS_8X8(left_type[0])) +- h->direct_cache[scan8[0] - 1 + 0*8]= h->direct_table[4*left_xy[0] + 1 + (left_block[0]&~1)]; +- else +- h->direct_cache[scan8[0] - 1 + 0*8]= MB_TYPE_16x16>>1; +- +- if(IS_DIRECT(left_type[1])) +- h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_DIRECT2>>1; +- else if(IS_8X8(left_type[1])) +- h->direct_cache[scan8[0] - 1 + 2*8]= h->direct_table[4*left_xy[1] + 1 + (left_block[2]&~1)]; +- else +- h->direct_cache[scan8[0] - 1 + 2*8]= MB_TYPE_16x16>>1; +- } +- } +- } +- if(FRAME_MBAFF){ +-#define MAP_MVS\ +- MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ +- MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ +- MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ +- MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ +- MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ +- MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ +- MAP_F2F(scan8[0] - 1 + 0*8, left_type[0])\ +- MAP_F2F(scan8[0] - 1 + 1*8, left_type[0])\ +- MAP_F2F(scan8[0] - 1 + 2*8, left_type[1])\ +- MAP_F2F(scan8[0] - 1 + 3*8, left_type[1]) +- if(MB_FIELD){ +-#define MAP_F2F(idx, mb_type)\ +- if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ +- h->ref_cache[list][idx] <<= 1;\ +- h->mv_cache[list][idx][1] /= 2;\ +- h->mvd_cache[list][idx][1] >>=1;\ +- } +- MAP_MVS +-#undef MAP_F2F +- }else{ +-#define MAP_F2F(idx, mb_type)\ +- if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ +- h->ref_cache[list][idx] >>= 1;\ +- h->mv_cache[list][idx][1] <<= 1;\ +- h->mvd_cache[list][idx][1] <<= 1;\ +- } +- MAP_MVS +-#undef MAP_F2F +- } +- } +- } +- } +-#endif +- +- h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[0]); +-} +- + /** +- * gets the predicted intra4x4 prediction mode. ++ * Get the predicted intra4x4 prediction mode. + */ +-static inline int pred_intra_mode(H264Context *h, int n){ ++static av_always_inline int pred_intra_mode(H264Context *h, int n){ + const int index8= scan8[n]; + const int left= h->intra4x4_pred_mode_cache[index8 - 1]; + const int top = h->intra4x4_pred_mode_cache[index8 - 8]; +@@ -1194,62 +799,87 @@ + else return min; + } + +-static inline void write_back_non_zero_count(H264Context *h){ ++static av_always_inline void write_back_intra_pred_mode(H264Context *h){ ++ int8_t *i4x4= h->intra4x4_pred_mode + h->mb2br_xy[h->mb_xy]; ++ int8_t *i4x4_cache= h->intra4x4_pred_mode_cache; ++ ++ AV_COPY32(i4x4, i4x4_cache + 4 + 8*4); ++ i4x4[4]= i4x4_cache[7+8*3]; ++ i4x4[5]= i4x4_cache[7+8*2]; ++ i4x4[6]= i4x4_cache[7+8*1]; ++} ++ ++static av_always_inline void write_back_non_zero_count(H264Context *h){ + const int mb_xy= h->mb_xy; ++ uint8_t *nnz = h->non_zero_count[mb_xy]; ++ uint8_t *nnz_cache = h->non_zero_count_cache; ++ ++ AV_COPY32(&nnz[ 0], &nnz_cache[4+8* 1]); ++ AV_COPY32(&nnz[ 4], &nnz_cache[4+8* 2]); ++ AV_COPY32(&nnz[ 8], &nnz_cache[4+8* 3]); ++ AV_COPY32(&nnz[12], &nnz_cache[4+8* 4]); ++ AV_COPY32(&nnz[16], &nnz_cache[4+8* 6]); ++ AV_COPY32(&nnz[20], &nnz_cache[4+8* 7]); ++ AV_COPY32(&nnz[32], &nnz_cache[4+8*11]); ++ AV_COPY32(&nnz[36], &nnz_cache[4+8*12]); ++ ++ if(!h->s.chroma_y_shift){ ++ AV_COPY32(&nnz[24], &nnz_cache[4+8* 8]); ++ AV_COPY32(&nnz[28], &nnz_cache[4+8* 9]); ++ AV_COPY32(&nnz[40], &nnz_cache[4+8*13]); ++ AV_COPY32(&nnz[44], &nnz_cache[4+8*14]); ++ } ++} ++ ++static av_always_inline void write_back_motion_list(H264Context *h, MpegEncContext * const s, int b_stride, ++ int b_xy, int b8_xy, int mb_type, int list ) ++{ ++ int16_t (*mv_dst)[2] = &s->current_picture.f.motion_val[list][b_xy]; ++ int16_t (*mv_src)[2] = &h->mv_cache[list][scan8[0]]; ++ AV_COPY128(mv_dst + 0*b_stride, mv_src + 8*0); ++ AV_COPY128(mv_dst + 1*b_stride, mv_src + 8*1); ++ AV_COPY128(mv_dst + 2*b_stride, mv_src + 8*2); ++ AV_COPY128(mv_dst + 3*b_stride, mv_src + 8*3); ++ if( CABAC ) { ++ uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]]; ++ uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]]; ++ if(IS_SKIP(mb_type)) ++ AV_ZERO128(mvd_dst); ++ else{ ++ AV_COPY64(mvd_dst, mvd_src + 8*3); ++ AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0); ++ AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1); ++ AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2); ++ } ++ } + +- AV_COPY64(&h->non_zero_count[mb_xy][ 0], &h->non_zero_count_cache[0+8*1]); +- AV_COPY64(&h->non_zero_count[mb_xy][ 8], &h->non_zero_count_cache[0+8*2]); +- AV_COPY32(&h->non_zero_count[mb_xy][16], &h->non_zero_count_cache[0+8*5]); +- AV_COPY32(&h->non_zero_count[mb_xy][20], &h->non_zero_count_cache[4+8*3]); +- AV_COPY64(&h->non_zero_count[mb_xy][24], &h->non_zero_count_cache[0+8*4]); ++ { ++ int8_t *ref_index = &s->current_picture.f.ref_index[list][b8_xy]; ++ int8_t *ref_cache = h->ref_cache[list]; ++ ref_index[0+0*2]= ref_cache[scan8[0]]; ++ ref_index[1+0*2]= ref_cache[scan8[4]]; ++ ref_index[0+1*2]= ref_cache[scan8[8]]; ++ ref_index[1+1*2]= ref_cache[scan8[12]]; ++ } + } + +-static inline void write_back_motion(H264Context *h, int mb_type){ ++static av_always_inline void write_back_motion(H264Context *h, int mb_type){ + MpegEncContext * const s = &h->s; ++ const int b_stride = h->b_stride; + const int b_xy = 4*s->mb_x + 4*s->mb_y*h->b_stride; //try mb2b(8)_xy + const int b8_xy= 4*h->mb_xy; +- int list; + +- if(!USES_LIST(mb_type, 0)) +- fill_rectangle(&s->current_picture.ref_index[0][b8_xy], 2, 2, 2, (uint8_t)LIST_NOT_USED, 1); +- +- for(list=0; listlist_count; list++){ +- int y, b_stride; +- int16_t (*mv_dst)[2]; +- int16_t (*mv_src)[2]; +- +- if(!USES_LIST(mb_type, list)) +- continue; +- +- b_stride = h->b_stride; +- mv_dst = &s->current_picture.motion_val[list][b_xy]; +- mv_src = &h->mv_cache[list][scan8[0]]; +- for(y=0; y<4; y++){ +- AV_COPY128(mv_dst + y*b_stride, mv_src + 8*y); +- } +- if( CABAC ) { +- uint8_t (*mvd_dst)[2] = &h->mvd_table[list][FMO ? 8*h->mb_xy : h->mb2br_xy[h->mb_xy]]; +- uint8_t (*mvd_src)[2] = &h->mvd_cache[list][scan8[0]]; +- if(IS_SKIP(mb_type)) +- AV_ZERO128(mvd_dst); +- else{ +- AV_COPY64(mvd_dst, mvd_src + 8*3); +- AV_COPY16(mvd_dst + 3 + 3, mvd_src + 3 + 8*0); +- AV_COPY16(mvd_dst + 3 + 2, mvd_src + 3 + 8*1); +- AV_COPY16(mvd_dst + 3 + 1, mvd_src + 3 + 8*2); +- } +- } +- +- { +- int8_t *ref_index = &s->current_picture.ref_index[list][b8_xy]; +- ref_index[0+0*2]= h->ref_cache[list][scan8[0]]; +- ref_index[1+0*2]= h->ref_cache[list][scan8[4]]; +- ref_index[0+1*2]= h->ref_cache[list][scan8[8]]; +- ref_index[1+1*2]= h->ref_cache[list][scan8[12]]; +- } ++ if(USES_LIST(mb_type, 0)){ ++ write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 0); ++ }else{ ++ fill_rectangle(&s->current_picture.f.ref_index[0][b8_xy], ++ 2, 2, 2, (uint8_t)LIST_NOT_USED, 1); ++ } ++ if(USES_LIST(mb_type, 1)){ ++ write_back_motion_list(h, s, b_stride, b_xy, b8_xy, mb_type, 1); + } + +- if(h->slice_type_nos == FF_B_TYPE && CABAC){ ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B && CABAC){ + if(IS_8X8(mb_type)){ + uint8_t *direct_table = &h->direct_table[4*h->mb_xy]; + direct_table[1] = h->sub_mb_type[1]>>1; +@@ -1259,57 +889,11 @@ + } + } + +-static inline int get_dct8x8_allowed(H264Context *h){ ++static av_always_inline int get_dct8x8_allowed(H264Context *h){ + if(h->sps.direct_8x8_inference_flag) + return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8 )*0x0001000100010001ULL)); + else + return !(AV_RN64A(h->sub_mb_type) & ((MB_TYPE_16x8|MB_TYPE_8x16|MB_TYPE_8x8|MB_TYPE_DIRECT2)*0x0001000100010001ULL)); + } + +-/** +- * decodes a P_SKIP or B_SKIP macroblock +- */ +-static void av_unused decode_mb_skip(H264Context *h){ +- MpegEncContext * const s = &h->s; +- const int mb_xy= h->mb_xy; +- int mb_type=0; +- +- memset(h->non_zero_count[mb_xy], 0, 32); +- memset(h->non_zero_count_cache + 8, 0, 8*5); //FIXME ugly, remove pfui +- +- if(MB_FIELD) +- mb_type|= MB_TYPE_INTERLACED; +- +- if( h->slice_type_nos == FF_B_TYPE ) +- { +- // just for fill_caches. pred_direct_motion will set the real mb_type +- mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; +- if(h->direct_spatial_mv_pred){ +- fill_decode_neighbors(h, mb_type); +- fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ... +- } +- ff_h264_pred_direct_motion(h, &mb_type); +- mb_type|= MB_TYPE_SKIP; +- } +- else +- { +- int mx, my; +- mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; +- +- fill_decode_neighbors(h, mb_type); +- fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ... +- pred_pskip_motion(h, &mx, &my); +- fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); +- fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); +- } +- +- write_back_motion(h, mb_type); +- s->current_picture.mb_type[mb_xy]= mb_type; +- s->current_picture.qscale_table[mb_xy]= s->qscale; +- h->slice_table[ mb_xy ]= h->slice_num; +- h->prev_mb_skipped= 1; +-} +- +-#include "h264_mvpred.h" //For pred_pskip_motion() +- + #endif /* AVCODEC_H264_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264idct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264idct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264idct.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264idct.c 2012-05-14 14:08:53.826329757 +0200 +@@ -25,229 +25,14 @@ + * @author Michael Niedermayer + */ + +-#include "dsputil.h" +- +-static av_always_inline void idct_internal(uint8_t *dst, DCTELEM *block, int stride, int block_stride, int shift, int add){ +- int i; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- block[0] += 1<<(shift-1); +- +- for(i=0; i<4; i++){ +- const int z0= block[i + block_stride*0] + block[i + block_stride*2]; +- const int z1= block[i + block_stride*0] - block[i + block_stride*2]; +- const int z2= (block[i + block_stride*1]>>1) - block[i + block_stride*3]; +- const int z3= block[i + block_stride*1] + (block[i + block_stride*3]>>1); +- +- block[i + block_stride*0]= z0 + z3; +- block[i + block_stride*1]= z1 + z2; +- block[i + block_stride*2]= z1 - z2; +- block[i + block_stride*3]= z0 - z3; +- } +- +- for(i=0; i<4; i++){ +- const int z0= block[0 + block_stride*i] + block[2 + block_stride*i]; +- const int z1= block[0 + block_stride*i] - block[2 + block_stride*i]; +- const int z2= (block[1 + block_stride*i]>>1) - block[3 + block_stride*i]; +- const int z3= block[1 + block_stride*i] + (block[3 + block_stride*i]>>1); +- +- dst[i + 0*stride]= cm[ add*dst[i + 0*stride] + ((z0 + z3) >> shift) ]; +- dst[i + 1*stride]= cm[ add*dst[i + 1*stride] + ((z1 + z2) >> shift) ]; +- dst[i + 2*stride]= cm[ add*dst[i + 2*stride] + ((z1 - z2) >> shift) ]; +- dst[i + 3*stride]= cm[ add*dst[i + 3*stride] + ((z0 - z3) >> shift) ]; +- } +-} +- +-void ff_h264_idct_add_c(uint8_t *dst, DCTELEM *block, int stride){ +- idct_internal(dst, block, stride, 4, 6, 1); +-} +- +-void ff_h264_lowres_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){ +- idct_internal(dst, block, stride, 8, 3, 1); +-} +- +-void ff_h264_lowres_idct_put_c(uint8_t *dst, int stride, DCTELEM *block){ +- idct_internal(dst, block, stride, 8, 3, 0); +-} +- +-void ff_h264_idct8_add_c(uint8_t *dst, DCTELEM *block, int stride){ +- int i; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- block[0] += 32; +- +- for( i = 0; i < 8; i++ ) +- { +- const int a0 = block[i+0*8] + block[i+4*8]; +- const int a2 = block[i+0*8] - block[i+4*8]; +- const int a4 = (block[i+2*8]>>1) - block[i+6*8]; +- const int a6 = (block[i+6*8]>>1) + block[i+2*8]; +- +- const int b0 = a0 + a6; +- const int b2 = a2 + a4; +- const int b4 = a2 - a4; +- const int b6 = a0 - a6; +- +- const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1); +- const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1); +- const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1); +- const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1); +- +- const int b1 = (a7>>2) + a1; +- const int b3 = a3 + (a5>>2); +- const int b5 = (a3>>2) - a5; +- const int b7 = a7 - (a1>>2); +- +- block[i+0*8] = b0 + b7; +- block[i+7*8] = b0 - b7; +- block[i+1*8] = b2 + b5; +- block[i+6*8] = b2 - b5; +- block[i+2*8] = b4 + b3; +- block[i+5*8] = b4 - b3; +- block[i+3*8] = b6 + b1; +- block[i+4*8] = b6 - b1; +- } +- for( i = 0; i < 8; i++ ) +- { +- const int a0 = block[0+i*8] + block[4+i*8]; +- const int a2 = block[0+i*8] - block[4+i*8]; +- const int a4 = (block[2+i*8]>>1) - block[6+i*8]; +- const int a6 = (block[6+i*8]>>1) + block[2+i*8]; +- +- const int b0 = a0 + a6; +- const int b2 = a2 + a4; +- const int b4 = a2 - a4; +- const int b6 = a0 - a6; +- +- const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1); +- const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1); +- const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1); +- const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1); +- +- const int b1 = (a7>>2) + a1; +- const int b3 = a3 + (a5>>2); +- const int b5 = (a3>>2) - a5; +- const int b7 = a7 - (a1>>2); +- +- dst[i + 0*stride] = cm[ dst[i + 0*stride] + ((b0 + b7) >> 6) ]; +- dst[i + 1*stride] = cm[ dst[i + 1*stride] + ((b2 + b5) >> 6) ]; +- dst[i + 2*stride] = cm[ dst[i + 2*stride] + ((b4 + b3) >> 6) ]; +- dst[i + 3*stride] = cm[ dst[i + 3*stride] + ((b6 + b1) >> 6) ]; +- dst[i + 4*stride] = cm[ dst[i + 4*stride] + ((b6 - b1) >> 6) ]; +- dst[i + 5*stride] = cm[ dst[i + 5*stride] + ((b4 - b3) >> 6) ]; +- dst[i + 6*stride] = cm[ dst[i + 6*stride] + ((b2 - b5) >> 6) ]; +- dst[i + 7*stride] = cm[ dst[i + 7*stride] + ((b0 - b7) >> 6) ]; +- } +-} +- +-// assumes all AC coefs are 0 +-void ff_h264_idct_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){ +- int i, j; +- int dc = (block[0] + 32) >> 6; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + dc; +- for( j = 0; j < 4; j++ ) +- { +- for( i = 0; i < 4; i++ ) +- dst[i] = cm[ dst[i] ]; +- dst += stride; +- } +-} +- +-void ff_h264_idct8_dc_add_c(uint8_t *dst, DCTELEM *block, int stride){ +- int i, j; +- int dc = (block[0] + 32) >> 6; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + dc; +- for( j = 0; j < 8; j++ ) +- { +- for( i = 0; i < 8; i++ ) +- dst[i] = cm[ dst[i] ]; +- dst += stride; +- } +-} +- +-//FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split +-static const uint8_t scan8[16 + 2*4]={ +- 4+1*8, 5+1*8, 4+2*8, 5+2*8, +- 6+1*8, 7+1*8, 6+2*8, 7+2*8, +- 4+3*8, 5+3*8, 4+4*8, 5+4*8, +- 6+3*8, 7+3*8, 6+4*8, 7+4*8, +- 1+1*8, 2+1*8, +- 1+2*8, 2+2*8, +- 1+4*8, 2+4*8, +- 1+5*8, 2+5*8, +-}; +- +-void ff_h264_idct_add16_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ +- int i; +- for(i=0; i<16; i++){ +- int nnz = nnzc[ scan8[i] ]; +- if(nnz){ +- if(nnz==1 && block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride); +- else idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1); +- } +- } +-} +- +-void ff_h264_idct_add16intra_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ +- int i; +- for(i=0; i<16; i++){ +- if(nnzc[ scan8[i] ]) idct_internal (dst + block_offset[i], block + i*16, stride, 4, 6, 1); +- else if(block[i*16]) ff_h264_idct_dc_add_c(dst + block_offset[i], block + i*16, stride); +- } +-} +- +-void ff_h264_idct8_add4_c(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ +- int i; +- for(i=0; i<16; i+=4){ +- int nnz = nnzc[ scan8[i] ]; +- if(nnz){ +- if(nnz==1 && block[i*16]) ff_h264_idct8_dc_add_c(dst + block_offset[i], block + i*16, stride); +- else ff_h264_idct8_add_c (dst + block_offset[i], block + i*16, stride); +- } +- } +-} +- +-void ff_h264_idct_add8_c(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ +- int i; +- for(i=16; i<16+8; i++){ +- if(nnzc[ scan8[i] ]) +- ff_h264_idct_add_c (dest[(i&4)>>2] + block_offset[i], block + i*16, stride); +- else if(block[i*16]) +- ff_h264_idct_dc_add_c(dest[(i&4)>>2] + block_offset[i], block + i*16, stride); +- } +-} +-/** +- * IDCT transforms the 16 dc values and dequantizes them. +- * @param qp quantization parameter +- */ +-void ff_h264_luma_dc_dequant_idct_c(DCTELEM *output, DCTELEM *input, int qmul){ +-#define stride 16 +- int i; +- int temp[16]; +- static const uint8_t x_offset[4]={0, 2*stride, 8*stride, 10*stride}; +- +- for(i=0; i<4; i++){ +- const int z0= input[4*i+0] + input[4*i+1]; +- const int z1= input[4*i+0] - input[4*i+1]; +- const int z2= input[4*i+2] - input[4*i+3]; +- const int z3= input[4*i+2] + input[4*i+3]; +- +- temp[4*i+0]= z0+z3; +- temp[4*i+1]= z0-z3; +- temp[4*i+2]= z1-z2; +- temp[4*i+3]= z1+z2; +- } +- +- for(i=0; i<4; i++){ +- const int offset= x_offset[i]; +- const int z0= temp[4*0+i] + temp[4*2+i]; +- const int z1= temp[4*0+i] - temp[4*2+i]; +- const int z2= temp[4*1+i] - temp[4*3+i]; +- const int z3= temp[4*1+i] + temp[4*3+i]; +- +- output[stride* 0+offset]= ((((z0 + z3)*qmul + 128 ) >> 8)); +- output[stride* 1+offset]= ((((z1 + z2)*qmul + 128 ) >> 8)); +- output[stride* 4+offset]= ((((z1 - z2)*qmul + 128 ) >> 8)); +- output[stride* 5+offset]= ((((z0 - z3)*qmul + 128 ) >> 8)); +- } +-} ++#define BIT_DEPTH 8 ++#include "h264idct_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 9 ++#include "h264idct_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "h264idct_template.c" ++#undef BIT_DEPTH +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264idct_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264idct_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264idct_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264idct_template.c 2012-05-14 14:08:53.827329777 +0200 +@@ -0,0 +1,332 @@ ++/* ++ * H.264 IDCT ++ * Copyright (c) 2004-2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * H.264 IDCT. ++ * @author Michael Niedermayer ++ */ ++ ++#include "bit_depth_template.c" ++ ++#ifndef AVCODEC_H264IDCT_INTERNAL_H ++#define AVCODEC_H264IDCT_INTERNAL_H ++//FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split ++static const uint8_t scan8[16*3]={ ++ 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8, ++ 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8, ++ 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8, ++ 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8, ++ 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8, ++ 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8, ++ 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8, ++ 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8, ++ 4+11*8, 5+11*8, 4+12*8, 5+12*8, ++ 6+11*8, 7+11*8, 6+12*8, 7+12*8, ++ 4+13*8, 5+13*8, 4+14*8, 5+14*8, ++ 6+13*8, 7+13*8, 6+14*8, 7+14*8 ++}; ++#endif ++ ++void FUNCC(ff_h264_idct_add)(uint8_t *_dst, DCTELEM *_block, int stride) ++{ ++ int i; ++ pixel *dst = (pixel*)_dst; ++ dctcoef *block = (dctcoef*)_block; ++ stride >>= sizeof(pixel)-1; ++ ++ block[0] += 1 << 5; ++ ++ for(i=0; i<4; i++){ ++ const int z0= block[i + 4*0] + block[i + 4*2]; ++ const int z1= block[i + 4*0] - block[i + 4*2]; ++ const int z2= (block[i + 4*1]>>1) - block[i + 4*3]; ++ const int z3= block[i + 4*1] + (block[i + 4*3]>>1); ++ ++ block[i + 4*0]= z0 + z3; ++ block[i + 4*1]= z1 + z2; ++ block[i + 4*2]= z1 - z2; ++ block[i + 4*3]= z0 - z3; ++ } ++ ++ for(i=0; i<4; i++){ ++ const int z0= block[0 + 4*i] + block[2 + 4*i]; ++ const int z1= block[0 + 4*i] - block[2 + 4*i]; ++ const int z2= (block[1 + 4*i]>>1) - block[3 + 4*i]; ++ const int z3= block[1 + 4*i] + (block[3 + 4*i]>>1); ++ ++ dst[i + 0*stride]= av_clip_pixel(dst[i + 0*stride] + ((z0 + z3) >> 6)); ++ dst[i + 1*stride]= av_clip_pixel(dst[i + 1*stride] + ((z1 + z2) >> 6)); ++ dst[i + 2*stride]= av_clip_pixel(dst[i + 2*stride] + ((z1 - z2) >> 6)); ++ dst[i + 3*stride]= av_clip_pixel(dst[i + 3*stride] + ((z0 - z3) >> 6)); ++ } ++} ++ ++void FUNCC(ff_h264_idct8_add)(uint8_t *_dst, DCTELEM *_block, int stride){ ++ int i; ++ pixel *dst = (pixel*)_dst; ++ dctcoef *block = (dctcoef*)_block; ++ stride >>= sizeof(pixel)-1; ++ ++ block[0] += 32; ++ ++ for( i = 0; i < 8; i++ ) ++ { ++ const int a0 = block[i+0*8] + block[i+4*8]; ++ const int a2 = block[i+0*8] - block[i+4*8]; ++ const int a4 = (block[i+2*8]>>1) - block[i+6*8]; ++ const int a6 = (block[i+6*8]>>1) + block[i+2*8]; ++ ++ const int b0 = a0 + a6; ++ const int b2 = a2 + a4; ++ const int b4 = a2 - a4; ++ const int b6 = a0 - a6; ++ ++ const int a1 = -block[i+3*8] + block[i+5*8] - block[i+7*8] - (block[i+7*8]>>1); ++ const int a3 = block[i+1*8] + block[i+7*8] - block[i+3*8] - (block[i+3*8]>>1); ++ const int a5 = -block[i+1*8] + block[i+7*8] + block[i+5*8] + (block[i+5*8]>>1); ++ const int a7 = block[i+3*8] + block[i+5*8] + block[i+1*8] + (block[i+1*8]>>1); ++ ++ const int b1 = (a7>>2) + a1; ++ const int b3 = a3 + (a5>>2); ++ const int b5 = (a3>>2) - a5; ++ const int b7 = a7 - (a1>>2); ++ ++ block[i+0*8] = b0 + b7; ++ block[i+7*8] = b0 - b7; ++ block[i+1*8] = b2 + b5; ++ block[i+6*8] = b2 - b5; ++ block[i+2*8] = b4 + b3; ++ block[i+5*8] = b4 - b3; ++ block[i+3*8] = b6 + b1; ++ block[i+4*8] = b6 - b1; ++ } ++ for( i = 0; i < 8; i++ ) ++ { ++ const int a0 = block[0+i*8] + block[4+i*8]; ++ const int a2 = block[0+i*8] - block[4+i*8]; ++ const int a4 = (block[2+i*8]>>1) - block[6+i*8]; ++ const int a6 = (block[6+i*8]>>1) + block[2+i*8]; ++ ++ const int b0 = a0 + a6; ++ const int b2 = a2 + a4; ++ const int b4 = a2 - a4; ++ const int b6 = a0 - a6; ++ ++ const int a1 = -block[3+i*8] + block[5+i*8] - block[7+i*8] - (block[7+i*8]>>1); ++ const int a3 = block[1+i*8] + block[7+i*8] - block[3+i*8] - (block[3+i*8]>>1); ++ const int a5 = -block[1+i*8] + block[7+i*8] + block[5+i*8] + (block[5+i*8]>>1); ++ const int a7 = block[3+i*8] + block[5+i*8] + block[1+i*8] + (block[1+i*8]>>1); ++ ++ const int b1 = (a7>>2) + a1; ++ const int b3 = a3 + (a5>>2); ++ const int b5 = (a3>>2) - a5; ++ const int b7 = a7 - (a1>>2); ++ ++ dst[i + 0*stride] = av_clip_pixel( dst[i + 0*stride] + ((b0 + b7) >> 6) ); ++ dst[i + 1*stride] = av_clip_pixel( dst[i + 1*stride] + ((b2 + b5) >> 6) ); ++ dst[i + 2*stride] = av_clip_pixel( dst[i + 2*stride] + ((b4 + b3) >> 6) ); ++ dst[i + 3*stride] = av_clip_pixel( dst[i + 3*stride] + ((b6 + b1) >> 6) ); ++ dst[i + 4*stride] = av_clip_pixel( dst[i + 4*stride] + ((b6 - b1) >> 6) ); ++ dst[i + 5*stride] = av_clip_pixel( dst[i + 5*stride] + ((b4 - b3) >> 6) ); ++ dst[i + 6*stride] = av_clip_pixel( dst[i + 6*stride] + ((b2 - b5) >> 6) ); ++ dst[i + 7*stride] = av_clip_pixel( dst[i + 7*stride] + ((b0 - b7) >> 6) ); ++ } ++} ++ ++// assumes all AC coefs are 0 ++void FUNCC(ff_h264_idct_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ ++ int i, j; ++ int dc = (((dctcoef*)block)[0] + 32) >> 6; ++ pixel *dst = (pixel*)p_dst; ++ stride >>= sizeof(pixel)-1; ++ for( j = 0; j < 4; j++ ) ++ { ++ for( i = 0; i < 4; i++ ) ++ dst[i] = av_clip_pixel( dst[i] + dc ); ++ dst += stride; ++ } ++} ++ ++void FUNCC(ff_h264_idct8_dc_add)(uint8_t *p_dst, DCTELEM *block, int stride){ ++ int i, j; ++ int dc = (((dctcoef*)block)[0] + 32) >> 6; ++ pixel *dst = (pixel*)p_dst; ++ stride >>= sizeof(pixel)-1; ++ for( j = 0; j < 8; j++ ) ++ { ++ for( i = 0; i < 8; i++ ) ++ dst[i] = av_clip_pixel( dst[i] + dc ); ++ dst += stride; ++ } ++} ++ ++void FUNCC(ff_h264_idct_add16)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ ++ int i; ++ for(i=0; i<16; i++){ ++ int nnz = nnzc[ scan8[i] ]; ++ if(nnz){ ++ if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ else FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ } ++ } ++} ++ ++void FUNCC(ff_h264_idct_add16intra)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ ++ int i; ++ for(i=0; i<16; i++){ ++ if(nnzc[ scan8[i] ]) FUNCC(ff_h264_idct_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ else if(((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ } ++} ++ ++void FUNCC(ff_h264_idct8_add4)(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ ++ int i; ++ for(i=0; i<16; i+=4){ ++ int nnz = nnzc[ scan8[i] ]; ++ if(nnz){ ++ if(nnz==1 && ((dctcoef*)block)[i*16]) FUNCC(ff_h264_idct8_dc_add)(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ else FUNCC(ff_h264_idct8_add )(dst + block_offset[i], block + i*16*sizeof(pixel), stride); ++ } ++ } ++} ++ ++void FUNCC(ff_h264_idct_add8)(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ ++ int i, j; ++ for(j=1; j<3; j++){ ++ for(i=j*16; i> 8)); ++ output[stride* 1+offset]= ((((z1 + z2)*qmul + 128 ) >> 8)); ++ output[stride* 4+offset]= ((((z1 - z2)*qmul + 128 ) >> 8)); ++ output[stride* 5+offset]= ((((z0 - z3)*qmul + 128 ) >> 8)); ++ } ++#undef stride ++} ++ ++void FUNCC(ff_h264_chroma422_dc_dequant_idct)(DCTELEM *_block, int qmul){ ++ const int stride= 16*2; ++ const int xStride= 16; ++ int i; ++ int temp[8]; ++ static const uint8_t x_offset[2]={0, 16}; ++ dctcoef *block = (dctcoef*)_block; ++ ++ for(i=0; i<4; i++){ ++ temp[2*i+0] = block[stride*i + xStride*0] + block[stride*i + xStride*1]; ++ temp[2*i+1] = block[stride*i + xStride*0] - block[stride*i + xStride*1]; ++ } ++ ++ for(i=0; i<2; i++){ ++ const int offset= x_offset[i]; ++ const int z0= temp[2*0+i] + temp[2*2+i]; ++ const int z1= temp[2*0+i] - temp[2*2+i]; ++ const int z2= temp[2*1+i] - temp[2*3+i]; ++ const int z3= temp[2*1+i] + temp[2*3+i]; ++ ++ block[stride*0+offset]= ((z0 + z3)*qmul + 128) >> 8; ++ block[stride*1+offset]= ((z1 + z2)*qmul + 128) >> 8; ++ block[stride*2+offset]= ((z1 - z2)*qmul + 128) >> 8; ++ block[stride*3+offset]= ((z0 - z3)*qmul + 128) >> 8; ++ } ++} ++ ++void FUNCC(ff_h264_chroma_dc_dequant_idct)(DCTELEM *_block, int qmul){ ++ const int stride= 16*2; ++ const int xStride= 16; ++ int a,b,c,d,e; ++ dctcoef *block = (dctcoef*)_block; ++ ++ a= block[stride*0 + xStride*0]; ++ b= block[stride*0 + xStride*1]; ++ c= block[stride*1 + xStride*0]; ++ d= block[stride*1 + xStride*1]; ++ ++ e= a-b; ++ a= a+b; ++ b= c-d; ++ c= c+d; ++ ++ block[stride*0 + xStride*0]= ((a+c)*qmul) >> 7; ++ block[stride*0 + xStride*1]= ((e+b)*qmul) >> 7; ++ block[stride*1 + xStride*0]= ((a-c)*qmul) >> 7; ++ block[stride*1 + xStride*1]= ((e-b)*qmul) >> 7; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_loopfilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_loopfilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_loopfilter.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_loopfilter.c 2012-05-14 14:08:53.811329455 +0200 +@@ -100,13 +100,18 @@ + {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, {-1,13,17,25 }, + }; + +-static void av_always_inline filter_mb_edgev( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h) { +- const unsigned int index_a = qp + h->slice_alpha_c0_offset; ++/* intra: 0 if this loopfilter call is guaranteed to be inter (bS < 4), 1 if it might be intra (bS == 4) */ ++static av_always_inline void filter_mb_edgev(uint8_t *pix, int stride, ++ const int16_t bS[4], ++ unsigned int qp, int a, int b, ++ H264Context *h, int intra) ++{ ++ const unsigned int index_a = qp + a; + const int alpha = alpha_table[index_a]; +- const int beta = beta_table[qp + h->slice_beta_offset]; ++ const int beta = beta_table[qp + b]; + if (alpha ==0 || beta == 0) return; + +- if( bS[0] < 4 ) { ++ if( bS[0] < 4 || !intra ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; +@@ -117,13 +122,18 @@ + h->h264dsp.h264_h_loop_filter_luma_intra(pix, stride, alpha, beta); + } + } +-static void av_always_inline filter_mb_edgecv( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { +- const unsigned int index_a = qp + h->slice_alpha_c0_offset; ++ ++static av_always_inline void filter_mb_edgecv(uint8_t *pix, int stride, ++ const int16_t bS[4], ++ unsigned int qp, int a, int b, ++ H264Context *h, int intra) ++{ ++ const unsigned int index_a = qp + a; + const int alpha = alpha_table[index_a]; +- const int beta = beta_table[qp + h->slice_beta_offset]; ++ const int beta = beta_table[qp + b]; + if (alpha ==0 || beta == 0) return; + +- if( bS[0] < 4 ) { ++ if( bS[0] < 4 || !intra ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; +@@ -135,148 +145,63 @@ + } + } + +-static void filter_mb_mbaff_edgev( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { +- int i; +- int index_a = qp + h->slice_alpha_c0_offset; +- int alpha = alpha_table[index_a]; +- int beta = beta_table[qp + h->slice_beta_offset]; +- for( i = 0; i < 8; i++, pix += stride) { +- const int bS_index = (i >> 1) * bsi; +- +- if( bS[bS_index] == 0 ) { +- continue; +- } +- +- if( bS[bS_index] < 4 ) { +- const int tc0 = tc0_table[index_a][bS[bS_index]]; +- const int p0 = pix[-1]; +- const int p1 = pix[-2]; +- const int p2 = pix[-3]; +- const int q0 = pix[0]; +- const int q1 = pix[1]; +- const int q2 = pix[2]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { +- int tc = tc0; +- int i_delta; +- +- if( FFABS( p2 - p0 ) < beta ) { +- if(tc0) +- pix[-2] = p1 + av_clip( ( p2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( p1 << 1 ) ) >> 1, -tc0, tc0 ); +- tc++; +- } +- if( FFABS( q2 - q0 ) < beta ) { +- if(tc0) +- pix[1] = q1 + av_clip( ( q2 + ( ( p0 + q0 + 1 ) >> 1 ) - ( q1 << 1 ) ) >> 1, -tc0, tc0 ); +- tc++; +- } +- +- i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); +- pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ +- pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ +- tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); +- } +- }else{ +- const int p0 = pix[-1]; +- const int p1 = pix[-2]; +- const int p2 = pix[-3]; +- +- const int q0 = pix[0]; +- const int q1 = pix[1]; +- const int q2 = pix[2]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { ++static av_always_inline void filter_mb_mbaff_edgev(H264Context *h, uint8_t *pix, ++ int stride, ++ const int16_t bS[7], int bsi, ++ int qp, int a, int b, ++ int intra) ++{ ++ const unsigned int index_a = qp + a; ++ const int alpha = alpha_table[index_a]; ++ const int beta = beta_table[qp + b]; ++ if (alpha ==0 || beta == 0) return; + +- if(FFABS( p0 - q0 ) < (( alpha >> 2 ) + 2 )){ +- if( FFABS( p2 - p0 ) < beta) +- { +- const int p3 = pix[-4]; +- /* p0', p1', p2' */ +- pix[-1] = ( p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4 ) >> 3; +- pix[-2] = ( p2 + p1 + p0 + q0 + 2 ) >> 2; +- pix[-3] = ( 2*p3 + 3*p2 + p1 + p0 + q0 + 4 ) >> 3; +- } else { +- /* p0' */ +- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; +- } +- if( FFABS( q2 - q0 ) < beta) +- { +- const int q3 = pix[3]; +- /* q0', q1', q2' */ +- pix[0] = ( p1 + 2*p0 + 2*q0 + 2*q1 + q2 + 4 ) >> 3; +- pix[1] = ( p0 + q0 + q1 + q2 + 2 ) >> 2; +- pix[2] = ( 2*q3 + 3*q2 + q1 + q0 + p0 + 4 ) >> 3; +- } else { +- /* q0' */ +- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; +- } +- }else{ +- /* p0', q0' */ +- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; +- pix[ 0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; +- } +- tprintf(h->s.avctx, "filter_mb_mbaff_edgev i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, p2, p1, p0, q0, q1, q2, pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); +- } +- } ++ if( bS[0] < 4 || !intra ) { ++ int8_t tc[4]; ++ tc[0] = tc0_table[index_a][bS[0*bsi]]; ++ tc[1] = tc0_table[index_a][bS[1*bsi]]; ++ tc[2] = tc0_table[index_a][bS[2*bsi]]; ++ tc[3] = tc0_table[index_a][bS[3*bsi]]; ++ h->h264dsp.h264_h_loop_filter_luma_mbaff(pix, stride, alpha, beta, tc); ++ } else { ++ h->h264dsp.h264_h_loop_filter_luma_mbaff_intra(pix, stride, alpha, beta); + } + } +-static void filter_mb_mbaff_edgecv( H264Context *h, uint8_t *pix, int stride, int16_t bS[4], int bsi, int qp ) { +- int i; +- int index_a = qp + h->slice_alpha_c0_offset; +- int alpha = alpha_table[index_a]; +- int beta = beta_table[qp + h->slice_beta_offset]; +- for( i = 0; i < 4; i++, pix += stride) { +- const int bS_index = i*bsi; +- +- if( bS[bS_index] == 0 ) { +- continue; +- } +- +- if( bS[bS_index] < 4 ) { +- const int tc = tc0_table[index_a][bS[bS_index]] + 1; +- const int p0 = pix[-1]; +- const int p1 = pix[-2]; +- const int q0 = pix[0]; +- const int q1 = pix[1]; +- +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { +- const int i_delta = av_clip( (((q0 - p0 ) << 2) + (p1 - q1) + 4) >> 3, -tc, tc ); +- +- pix[-1] = av_clip_uint8( p0 + i_delta ); /* p0' */ +- pix[0] = av_clip_uint8( q0 - i_delta ); /* q0' */ +- tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d, qp:%d, indexA:%d, alpha:%d, beta:%d, tc:%d\n# bS:%d -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x]\n", i, qp[qp_index], index_a, alpha, beta, tc, bS[bS_index], pix[-3], p1, p0, q0, q1, pix[2], p1, pix[-1], pix[0], q1); +- } +- }else{ +- const int p0 = pix[-1]; +- const int p1 = pix[-2]; +- const int q0 = pix[0]; +- const int q1 = pix[1]; + +- if( FFABS( p0 - q0 ) < alpha && +- FFABS( p1 - p0 ) < beta && +- FFABS( q1 - q0 ) < beta ) { ++static av_always_inline void filter_mb_mbaff_edgecv(H264Context *h, ++ uint8_t *pix, int stride, ++ const int16_t bS[7], ++ int bsi, int qp, int a, ++ int b, int intra) ++{ ++ const unsigned int index_a = qp + a; ++ const int alpha = alpha_table[index_a]; ++ const int beta = beta_table[qp + b]; ++ if (alpha ==0 || beta == 0) return; + +- pix[-1] = ( 2*p1 + p0 + q1 + 2 ) >> 2; /* p0' */ +- pix[0] = ( 2*q1 + q0 + p1 + 2 ) >> 2; /* q0' */ +- tprintf(h->s.avctx, "filter_mb_mbaff_edgecv i:%d\n# bS:4 -> [%02x, %02x, %02x, %02x, %02x, %02x] =>[%02x, %02x, %02x, %02x, %02x, %02x]\n", i, pix[-3], p1, p0, q0, q1, pix[2], pix[-3], pix[-2], pix[-1], pix[0], pix[1], pix[2]); +- } +- } ++ if( bS[0] < 4 || !intra ) { ++ int8_t tc[4]; ++ tc[0] = tc0_table[index_a][bS[0*bsi]] + 1; ++ tc[1] = tc0_table[index_a][bS[1*bsi]] + 1; ++ tc[2] = tc0_table[index_a][bS[2*bsi]] + 1; ++ tc[3] = tc0_table[index_a][bS[3*bsi]] + 1; ++ h->h264dsp.h264_h_loop_filter_chroma_mbaff(pix, stride, alpha, beta, tc); ++ } else { ++ h->h264dsp.h264_h_loop_filter_chroma_mbaff_intra(pix, stride, alpha, beta); + } + } + +-static void av_always_inline filter_mb_edgeh( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { +- const unsigned int index_a = qp + h->slice_alpha_c0_offset; ++static av_always_inline void filter_mb_edgeh(uint8_t *pix, int stride, ++ const int16_t bS[4], ++ unsigned int qp, int a, int b, ++ H264Context *h, int intra) ++{ ++ const unsigned int index_a = qp + a; + const int alpha = alpha_table[index_a]; +- const int beta = beta_table[qp + h->slice_beta_offset]; ++ const int beta = beta_table[qp + b]; + if (alpha ==0 || beta == 0) return; + +- if( bS[0] < 4 ) { ++ if( bS[0] < 4 || !intra ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]; + tc[1] = tc0_table[index_a][bS[1]]; +@@ -288,13 +213,17 @@ + } + } + +-static void av_always_inline filter_mb_edgech( uint8_t *pix, int stride, int16_t bS[4], unsigned int qp, H264Context *h ) { +- const unsigned int index_a = qp + h->slice_alpha_c0_offset; ++static av_always_inline void filter_mb_edgech(uint8_t *pix, int stride, ++ const int16_t bS[4], ++ unsigned int qp, int a, int b, ++ H264Context *h, int intra) ++{ ++ const unsigned int index_a = qp + a; + const int alpha = alpha_table[index_a]; +- const int beta = beta_table[qp + h->slice_beta_offset]; ++ const int beta = beta_table[qp + b]; + if (alpha ==0 || beta == 0) return; + +- if( bS[0] < 4 ) { ++ if( bS[0] < 4 || !intra ) { + int8_t tc[4]; + tc[0] = tc0_table[index_a][bS[0]]+1; + tc[1] = tc0_table[index_a][bS[1]]+1; +@@ -306,71 +235,133 @@ + } + } + +-void ff_h264_filter_mb_fast( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { ++static av_always_inline void h264_filter_mb_fast_internal(H264Context *h, ++ int mb_x, int mb_y, ++ uint8_t *img_y, ++ uint8_t *img_cb, ++ uint8_t *img_cr, ++ unsigned int linesize, ++ unsigned int uvlinesize, ++ int pixel_shift) ++{ + MpegEncContext * const s = &h->s; +- int mb_xy; +- int mb_type, left_type; +- int qp, qp0, qp1, qpc, qpc0, qpc1, qp_thresh; +- +- mb_xy = h->mb_xy; +- +- if(!h->top_type || !h->h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) { +- ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); +- return; +- } +- assert(!FRAME_MBAFF); +- left_type= h->left_type[0]; +- +- mb_type = s->current_picture.mb_type[mb_xy]; +- qp = s->current_picture.qscale_table[mb_xy]; +- qp0 = s->current_picture.qscale_table[mb_xy-1]; +- qp1 = s->current_picture.qscale_table[h->top_mb_xy]; +- qpc = get_chroma_qp( h, 0, qp ); +- qpc0 = get_chroma_qp( h, 0, qp0 ); +- qpc1 = get_chroma_qp( h, 0, qp1 ); ++ int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); ++ int chroma444 = CHROMA444; ++ int chroma422 = CHROMA422; ++ ++ int mb_xy = h->mb_xy; ++ int left_type= h->left_type[LTOP]; ++ int top_type= h->top_type; ++ ++ int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); ++ int a = h->slice_alpha_c0_offset - qp_bd_offset; ++ int b = h->slice_beta_offset - qp_bd_offset; ++ ++ int mb_type = s->current_picture.f.mb_type[mb_xy]; ++ int qp = s->current_picture.f.qscale_table[mb_xy]; ++ int qp0 = s->current_picture.f.qscale_table[mb_xy - 1]; ++ int qp1 = s->current_picture.f.qscale_table[h->top_mb_xy]; ++ int qpc = get_chroma_qp( h, 0, qp ); ++ int qpc0 = get_chroma_qp( h, 0, qp0 ); ++ int qpc1 = get_chroma_qp( h, 0, qp1 ); + qp0 = (qp + qp0 + 1) >> 1; + qp1 = (qp + qp1 + 1) >> 1; + qpc0 = (qpc + qpc0 + 1) >> 1; + qpc1 = (qpc + qpc1 + 1) >> 1; +- qp_thresh = 15+52 - h->slice_alpha_c0_offset; +- if(qp <= qp_thresh && qp0 <= qp_thresh && qp1 <= qp_thresh && +- qpc <= qp_thresh && qpc0 <= qp_thresh && qpc1 <= qp_thresh) +- return; + + if( IS_INTRA(mb_type) ) { +- int16_t bS4[4] = {4,4,4,4}; +- int16_t bS3[4] = {3,3,3,3}; +- int16_t *bSH = FIELD_PICTURE ? bS3 : bS4; ++ static const int16_t bS4[4] = {4,4,4,4}; ++ static const int16_t bS3[4] = {3,3,3,3}; ++ const int16_t *bSH = FIELD_PICTURE ? bS3 : bS4; + if(left_type) +- filter_mb_edgev( &img_y[4*0], linesize, bS4, qp0, h); ++ filter_mb_edgev( &img_y[4*0<cbp&7) == 7 ) { ++ if( IS_8x8DCT(mb_type) && (h->cbp&7) == 7 && !chroma444 ) { + edges = 4; + AV_WN64A(bS[0][0], 0x0002000200020002ULL); + AV_WN64A(bS[0][2], 0x0002000200020002ULL); +@@ -378,7 +369,7 @@ + AV_WN64A(bS[1][2], 0x0002000200020002ULL); + } else { + int mask_edge1 = (3*(((5*mb_type)>>5)&1)) | (mb_type>>4); //(mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : (mb_type & MB_TYPE_16x8) ? 1 : 0; +- int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); // (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) && (h->left_type[0] & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : 0; ++ int mask_edge0 = 3*((mask_edge1>>1) & ((5*left_type)>>5)&1); // (mb_type & (MB_TYPE_16x16 | MB_TYPE_8x16)) && (h->left_type[LTOP] & (MB_TYPE_16x16 | MB_TYPE_8x16)) ? 3 : 0; + int step = 1+(mb_type>>24); //IS_8x8DCT(mb_type) ? 2 : 1; + edges = 4 - 3*((mb_type>>3) & !(h->cbp & 15)); //(mb_type & MB_TYPE_16x16) && !(h->cbp & 15) ? 1 : 4; + h->h264dsp.h264_loop_filter_strength( bS, h->non_zero_count_cache, h->ref_cache, h->mv_cache, +@@ -386,38 +377,64 @@ + } + if( IS_INTRA(left_type) ) + AV_WN64A(bS[0][0], 0x0004000400040004ULL); +- if( IS_INTRA(h->top_type) ) ++ if( IS_INTRA(top_type) ) + AV_WN64A(bS[1][0], FIELD_PICTURE ? 0x0003000300030003ULL : 0x0004000400040004ULL); + +-#define FILTER(hv,dir,edge)\ ++#define FILTER(hv,dir,edge,intra)\ + if(AV_RN64A(bS[dir][edge])) { \ +- filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1)], linesize, bS[dir][edge], edge ? qp : qp##dir, h );\ +- if(!(edge&1)) {\ +- filter_mb_edgec##hv( &img_cb[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\ +- filter_mb_edgec##hv( &img_cr[2*edge*(dir?uvlinesize:1)], uvlinesize, bS[dir][edge], edge ? qpc : qpc##dir, h );\ ++ filter_mb_edge##hv( &img_y[4*edge*(dir?linesize:1<h264dsp.h264_loop_filter_strength || h->pps.chroma_qp_diff) { ++ ff_h264_filter_mb(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize); ++ return; ++ } ++ ++#if CONFIG_SMALL ++ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, h->pixel_shift); ++#else ++ if(h->pixel_shift){ ++ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 1); ++ }else{ ++ h264_filter_mb_fast_internal(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, 0); ++ } ++#endif ++} ++ + static int check_mv(H264Context *h, long b_idx, long bn_idx, int mvy_limit){ + int v; + +@@ -447,11 +464,14 @@ + return v; + } + +-static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int dir) { ++static av_always_inline void filter_mb_dir(H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize, int mb_xy, int mb_type, int mvy_limit, int first_vertical_edge_done, int a, int b, int chroma, int dir) { + MpegEncContext * const s = &h->s; + int edge; ++ int chroma_qp_avg[2]; ++ int chroma444 = CHROMA444; ++ int chroma422 = CHROMA422; + const int mbm_xy = dir == 0 ? mb_xy -1 : h->top_mb_xy; +- const int mbm_type = dir == 0 ? h->left_type[0] : h->top_type; ++ const int mbm_type = dir == 0 ? h->left_type[LTOP] : h->top_type; + + // how often to recheck mv-based bS when iterating between edges + static const uint8_t mask_edge_tab[2][8]={{0,3,3,3,1,1,1,1}, +@@ -479,16 +499,16 @@ + for(j=0; j<2; j++, mbn_xy += s->mb_stride){ + DECLARE_ALIGNED(8, int16_t, bS)[4]; + int qp; +- if( IS_INTRA(mb_type|s->current_picture.mb_type[mbn_xy]) ) { ++ if (IS_INTRA(mb_type | s->current_picture.f.mb_type[mbn_xy])) { + AV_WN64A(bS, 0x0003000300030003ULL); + } else { +- if(!CABAC && IS_8x8DCT(s->current_picture.mb_type[mbn_xy])){ +- bS[0]= 1+((h->cbp_table[mbn_xy] & 4)||h->non_zero_count_cache[scan8[0]+0]); +- bS[1]= 1+((h->cbp_table[mbn_xy] & 4)||h->non_zero_count_cache[scan8[0]+1]); +- bS[2]= 1+((h->cbp_table[mbn_xy] & 8)||h->non_zero_count_cache[scan8[0]+2]); +- bS[3]= 1+((h->cbp_table[mbn_xy] & 8)||h->non_zero_count_cache[scan8[0]+3]); ++ if (!CABAC && IS_8x8DCT(s->current_picture.f.mb_type[mbn_xy])) { ++ bS[0]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+0]); ++ bS[1]= 1+((h->cbp_table[mbn_xy] & 0x4000)||h->non_zero_count_cache[scan8[0]+1]); ++ bS[2]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+2]); ++ bS[3]= 1+((h->cbp_table[mbn_xy] & 0x8000)||h->non_zero_count_cache[scan8[0]+3]); + }else{ +- const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 4+3*8; ++ const uint8_t *mbn_nnz = h->non_zero_count[mbn_xy] + 3*4; + int i; + for( i = 0; i < 4; i++ ) { + bS[i] = 1 + !!(h->non_zero_count_cache[scan8[0]+i] | mbn_nnz[i]); +@@ -497,14 +517,21 @@ + } + // Do not use s->qscale as luma quantizer because it has not the same + // value in IPCM macroblocks. +- qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbn_xy] + 1 ) >> 1; ++ qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbn_xy] + 1) >> 1; + tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, tmp_linesize, tmp_uvlinesize); + { int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } +- filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, h ); +- filter_mb_edgech( &img_cb[j*uvlinesize], tmp_uvlinesize, bS, +- ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h); +- filter_mb_edgech( &img_cr[j*uvlinesize], tmp_uvlinesize, bS, +- ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbn_xy] ) + 1 ) >> 1, h); ++ filter_mb_edgeh( &img_y[j*linesize], tmp_linesize, bS, qp, a, b, h, 0 ); ++ chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; ++ chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbn_xy]) + 1) >> 1; ++ if (chroma) { ++ if (chroma444) { ++ filter_mb_edgeh (&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0); ++ filter_mb_edgeh (&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0); ++ } else { ++ filter_mb_edgech(&img_cb[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[0], a, b, h, 0); ++ filter_mb_edgech(&img_cr[j*uvlinesize], tmp_uvlinesize, bS, chroma_qp_avg[1], a, b, h, 0); ++ } ++ } + } + }else{ + DECLARE_ALIGNED(8, int16_t, bS)[4]; +@@ -555,27 +582,33 @@ + // Do not use s->qscale as luma quantizer because it has not the same + // value in IPCM macroblocks. + if(bS[0]+bS[1]+bS[2]+bS[3]){ +- qp = ( s->current_picture.qscale_table[mb_xy] + s->current_picture.qscale_table[mbm_xy] + 1 ) >> 1; ++ qp = (s->current_picture.f.qscale_table[mb_xy] + s->current_picture.f.qscale_table[mbm_xy] + 1) >> 1; + //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); + tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); + //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } ++ chroma_qp_avg[0] = (h->chroma_qp[0] + get_chroma_qp(h, 0, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; ++ chroma_qp_avg[1] = (h->chroma_qp[1] + get_chroma_qp(h, 1, s->current_picture.f.qscale_table[mbm_xy]) + 1) >> 1; + if( dir == 0 ) { +- filter_mb_edgev( &img_y[0], linesize, bS, qp, h ); +- { +- int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; +- filter_mb_edgecv( &img_cb[0], uvlinesize, bS, qp, h); +- if(h->pps.chroma_qp_diff) +- qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; +- filter_mb_edgecv( &img_cr[0], uvlinesize, bS, qp, h); ++ filter_mb_edgev( &img_y[0], linesize, bS, qp, a, b, h, 1 ); ++ if (chroma) { ++ if (chroma444) { ++ filter_mb_edgev ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1); ++ filter_mb_edgev ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1); ++ } else { ++ filter_mb_edgecv( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1); ++ filter_mb_edgecv( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1); ++ } + } + } else { +- filter_mb_edgeh( &img_y[0], linesize, bS, qp, h ); +- { +- int qp= ( h->chroma_qp[0] + get_chroma_qp( h, 0, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; +- filter_mb_edgech( &img_cb[0], uvlinesize, bS, qp, h); +- if(h->pps.chroma_qp_diff) +- qp= ( h->chroma_qp[1] + get_chroma_qp( h, 1, s->current_picture.qscale_table[mbm_xy] ) + 1 ) >> 1; +- filter_mb_edgech( &img_cr[0], uvlinesize, bS, qp, h); ++ filter_mb_edgeh( &img_y[0], linesize, bS, qp, a, b, h, 1 ); ++ if (chroma) { ++ if (chroma444) { ++ filter_mb_edgeh ( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1); ++ filter_mb_edgeh ( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1); ++ } else { ++ filter_mb_edgech( &img_cb[0], uvlinesize, bS, chroma_qp_avg[0], a, b, h, 1); ++ filter_mb_edgech( &img_cr[0], uvlinesize, bS, chroma_qp_avg[1], a, b, h, 1); ++ } + } + } + } +@@ -586,8 +619,9 @@ + for( edge = 1; edge < edges; edge++ ) { + DECLARE_ALIGNED(8, int16_t, bS)[4]; + int qp; ++ const int deblock_edge = !IS_8x8DCT(mb_type & (edge<<24)); // (edge&1) && IS_8x8DCT(mb_type) + +- if( IS_8x8DCT(mb_type & (edge<<24)) ) // (edge&1) && IS_8x8DCT(mb_type) ++ if (!deblock_edge && (!chroma422 || dir == 0)) + continue; + + if( IS_INTRA(mb_type)) { +@@ -633,21 +667,40 @@ + /* Filter edge */ + // Do not use s->qscale as luma quantizer because it has not the same + // value in IPCM macroblocks. +- qp = s->current_picture.qscale_table[mb_xy]; ++ qp = s->current_picture.f.qscale_table[mb_xy]; + //tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d, QPc:%d, QPcn:%d\n", mb_x, mb_y, dir, edge, qp, h->chroma_qp[0], s->current_picture.qscale_table[mbn_xy]); + tprintf(s->avctx, "filter mb:%d/%d dir:%d edge:%d, QPy:%d ls:%d uvls:%d", mb_x, mb_y, dir, edge, qp, linesize, uvlinesize); + //{ int i; for (i = 0; i < 4; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } + if( dir == 0 ) { +- filter_mb_edgev( &img_y[4*edge], linesize, bS, qp, h ); +- if( (edge&1) == 0 ) { +- filter_mb_edgecv( &img_cb[2*edge], uvlinesize, bS, h->chroma_qp[0], h); +- filter_mb_edgecv( &img_cr[2*edge], uvlinesize, bS, h->chroma_qp[1], h); ++ filter_mb_edgev( &img_y[4*edge << h->pixel_shift], linesize, bS, qp, a, b, h, 0 ); ++ if (chroma) { ++ if (chroma444) { ++ filter_mb_edgev ( &img_cb[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0); ++ filter_mb_edgev ( &img_cr[4*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0); ++ } else if( (edge&1) == 0 ) { ++ filter_mb_edgecv( &img_cb[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0); ++ filter_mb_edgecv( &img_cr[2*edge << h->pixel_shift], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0); ++ } + } + } else { +- filter_mb_edgeh( &img_y[4*edge*linesize], linesize, bS, qp, h ); +- if( (edge&1) == 0 ) { +- filter_mb_edgech( &img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], h); +- filter_mb_edgech( &img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], h); ++ if (chroma422) { ++ if (deblock_edge) ++ filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0); ++ if (chroma) { ++ filter_mb_edgech(&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0); ++ filter_mb_edgech(&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0); ++ } ++ } else { ++ filter_mb_edgeh(&img_y[4*edge*linesize], linesize, bS, qp, a, b, h, 0); ++ if (chroma) { ++ if (chroma444) { ++ filter_mb_edgeh (&img_cb[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0); ++ filter_mb_edgeh (&img_cr[4*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0); ++ } else if ((edge&1) == 0) { ++ filter_mb_edgech(&img_cb[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[0], a, b, h, 0); ++ filter_mb_edgech(&img_cr[2*edge*uvlinesize], uvlinesize, bS, h->chroma_qp[1], a, b, h, 0); ++ } ++ } + } + } + } +@@ -656,16 +709,20 @@ + void ff_h264_filter_mb( H264Context *h, int mb_x, int mb_y, uint8_t *img_y, uint8_t *img_cb, uint8_t *img_cr, unsigned int linesize, unsigned int uvlinesize) { + MpegEncContext * const s = &h->s; + const int mb_xy= mb_x + mb_y*s->mb_stride; +- const int mb_type = s->current_picture.mb_type[mb_xy]; ++ const int mb_type = s->current_picture.f.mb_type[mb_xy]; + const int mvy_limit = IS_INTERLACED(mb_type) ? 2 : 4; + int first_vertical_edge_done = 0; + av_unused int dir; ++ int chroma = !(CONFIG_GRAY && (s->flags&CODEC_FLAG_GRAY)); ++ int qp_bd_offset = 6 * (h->sps.bit_depth_luma - 8); ++ int a = h->slice_alpha_c0_offset - qp_bd_offset; ++ int b = h->slice_beta_offset - qp_bd_offset; + + if (FRAME_MBAFF + // and current and left pair do not have the same interlaced type +- && IS_INTERLACED(mb_type^h->left_type[0]) ++ && IS_INTERLACED(mb_type^h->left_type[LTOP]) + // and left mb is in available to us +- && h->left_type[0]) { ++ && h->left_type[LTOP]) { + /* First vertical edge is different in MBAFF frames + * There are 8 different bS to compute and 2 different Qp + */ +@@ -683,34 +740,34 @@ + } else { + static const uint8_t offset[2][2][8]={ + { +- {7+8*0, 7+8*0, 7+8*0, 7+8*0, 7+8*1, 7+8*1, 7+8*1, 7+8*1}, +- {7+8*2, 7+8*2, 7+8*2, 7+8*2, 7+8*3, 7+8*3, 7+8*3, 7+8*3}, ++ {3+4*0, 3+4*0, 3+4*0, 3+4*0, 3+4*1, 3+4*1, 3+4*1, 3+4*1}, ++ {3+4*2, 3+4*2, 3+4*2, 3+4*2, 3+4*3, 3+4*3, 3+4*3, 3+4*3}, + },{ +- {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3}, +- {7+8*0, 7+8*1, 7+8*2, 7+8*3, 7+8*0, 7+8*1, 7+8*2, 7+8*3}, ++ {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3}, ++ {3+4*0, 3+4*1, 3+4*2, 3+4*3, 3+4*0, 3+4*1, 3+4*2, 3+4*3}, + } + }; + const uint8_t *off= offset[MB_FIELD][mb_y&1]; + for( i = 0; i < 8; i++ ) { + int j= MB_FIELD ? i>>2 : i&1; +- int mbn_xy = h->left_mb_xy[j]; +- int mbn_type= h->left_type[j]; ++ int mbn_xy = h->left_mb_xy[LEFT(j)]; ++ int mbn_type= h->left_type[LEFT(j)]; + + if( IS_INTRA( mbn_type ) ) + bS[i] = 4; + else{ + bS[i] = 1 + !!(h->non_zero_count_cache[12+8*(i>>1)] | + ((!h->pps.cabac && IS_8x8DCT(mbn_type)) ? +- (h->cbp_table[mbn_xy] & ((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2)) ++ (h->cbp_table[mbn_xy] & (((MB_FIELD ? (i&2) : (mb_y&1)) ? 8 : 2) << 12)) + : + h->non_zero_count[mbn_xy][ off[i] ])); + } + } + } + +- mb_qp = s->current_picture.qscale_table[mb_xy]; +- mbn0_qp = s->current_picture.qscale_table[h->left_mb_xy[0]]; +- mbn1_qp = s->current_picture.qscale_table[h->left_mb_xy[1]]; ++ mb_qp = s->current_picture.f.qscale_table[mb_xy]; ++ mbn0_qp = s->current_picture.f.qscale_table[h->left_mb_xy[0]]; ++ mbn1_qp = s->current_picture.f.qscale_table[h->left_mb_xy[1]]; + qp[0] = ( mb_qp + mbn0_qp + 1 ) >> 1; + bqp[0] = ( get_chroma_qp( h, 0, mb_qp ) + + get_chroma_qp( h, 0, mbn0_qp ) + 1 ) >> 1; +@@ -726,27 +783,50 @@ + tprintf(s->avctx, "filter mb:%d/%d MBAFF, QPy:%d/%d, QPb:%d/%d QPr:%d/%d ls:%d uvls:%d", mb_x, mb_y, qp[0], qp[1], bqp[0], bqp[1], rqp[0], rqp[1], linesize, uvlinesize); + { int i; for (i = 0; i < 8; i++) tprintf(s->avctx, " bS[%d]:%d", i, bS[i]); tprintf(s->avctx, "\n"); } + if(MB_FIELD){ +- filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0] ); +- filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1] ); +- filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0] ); +- filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1] ); +- filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0] ); +- filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1] ); ++ filter_mb_mbaff_edgev ( h, img_y , linesize, bS , 1, qp [0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_y + 8* linesize, linesize, bS+4, 1, qp [1], a, b, 1 ); ++ if (chroma){ ++ if (CHROMA444) { ++ filter_mb_mbaff_edgev ( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 ); ++ } else if (CHROMA422) { ++ filter_mb_mbaff_edgecv(h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1); ++ filter_mb_mbaff_edgecv(h, img_cb + 8*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1); ++ filter_mb_mbaff_edgecv(h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1); ++ filter_mb_mbaff_edgecv(h, img_cr + 8*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1); ++ }else{ ++ filter_mb_mbaff_edgecv( h, img_cb, uvlinesize, bS , 1, bqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cb + 4*uvlinesize, uvlinesize, bS+4, 1, bqp[1], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cr, uvlinesize, bS , 1, rqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cr + 4*uvlinesize, uvlinesize, bS+4, 1, rqp[1], a, b, 1 ); ++ } ++ } + }else{ +- filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0] ); +- filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1] ); +- filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0] ); +- filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1] ); +- filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0] ); +- filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1] ); ++ filter_mb_mbaff_edgev ( h, img_y , 2* linesize, bS , 2, qp [0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_y + linesize, 2* linesize, bS+1, 2, qp [1], a, b, 1 ); ++ if (chroma){ ++ if (CHROMA444) { ++ filter_mb_mbaff_edgev ( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgev ( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 ); ++ }else{ ++ filter_mb_mbaff_edgecv( h, img_cb, 2*uvlinesize, bS , 2, bqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cb + uvlinesize, 2*uvlinesize, bS+1, 2, bqp[1], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cr, 2*uvlinesize, bS , 2, rqp[0], a, b, 1 ); ++ filter_mb_mbaff_edgecv( h, img_cr + uvlinesize, 2*uvlinesize, bS+1, 2, rqp[1], a, b, 1 ); ++ } ++ } + } + } + + #if CONFIG_SMALL + for( dir = 0; dir < 2; dir++ ) +- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, dir); ++ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, dir ? 0 : first_vertical_edge_done, a, b, chroma, dir); + #else +- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, 0); +- filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, 1); ++ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, first_vertical_edge_done, a, b, chroma, 0); ++ filter_mb_dir(h, mb_x, mb_y, img_y, img_cb, img_cr, linesize, uvlinesize, mb_xy, mb_type, mvy_limit, 0, a, b, chroma, 1); + #endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_mp4toannexb_bsf.c 2012-05-14 14:08:53.812329476 +0200 +@@ -63,6 +63,7 @@ + int32_t nal_size; + uint32_t cumul_size = 0; + const uint8_t *buf_end = buf + buf_size; ++ int ret = AVERROR(EINVAL); + + /* nothing to filter */ + if (!avctx->extradata || avctx->extradata_size < 6) { +@@ -75,7 +76,7 @@ + if (!ctx->extradata_parsed) { + uint16_t unit_size; + uint64_t total_size = 0; +- uint8_t *out = NULL, unit_nb, sps_done = 0; ++ uint8_t *out = NULL, unit_nb, sps_done = 0, sps_seen = 0, pps_seen = 0; + const uint8_t *extradata = avctx->extradata+4; + static const uint8_t nalu_header[4] = {0, 0, 0, 1}; + +@@ -87,9 +88,11 @@ + /* retrieve sps and pps unit(s) */ + unit_nb = *extradata++ & 0x1f; /* number of sps unit(s) */ + if (!unit_nb) { +- unit_nb = *extradata++; /* number of pps unit(s) */ +- sps_done++; ++ goto pps; ++ } else { ++ sps_seen = 1; + } ++ + while (unit_nb--) { + void *tmp; + +@@ -109,12 +112,22 @@ + memcpy(out+total_size-unit_size-4, nalu_header, 4); + memcpy(out+total_size-unit_size, extradata+2, unit_size); + extradata += 2+unit_size; +- +- if (!unit_nb && !sps_done++) ++pps: ++ if (!unit_nb && !sps_done++) { + unit_nb = *extradata++; /* number of pps unit(s) */ ++ if (unit_nb) ++ pps_seen = 1; ++ } + } + +- memset(out + total_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); ++ if(out) ++ memset(out + total_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); ++ ++ if (!sps_seen) ++ av_log(avctx, AV_LOG_WARNING, "Warning: SPS NALU missing or invalid. The resulting stream may not play.\n"); ++ if (!pps_seen) ++ av_log(avctx, AV_LOG_WARNING, "Warning: PPS NALU missing or invalid. The resulting stream may not play.\n"); ++ + av_free(avctx->extradata); + avctx->extradata = out; + avctx->extradata_size = total_size; +@@ -125,6 +138,7 @@ + *poutbuf_size = 0; + *poutbuf = NULL; + do { ++ ret= AVERROR(EINVAL); + if (buf + ctx->length_size > buf_end) + goto fail; + +@@ -143,15 +157,15 @@ + + /* prepend only to the first type 5 NAL unit of an IDR picture */ + if (ctx->first_idr && unit_type == 5) { +- if (alloc_and_copy(poutbuf, poutbuf_size, ++ if ((ret=alloc_and_copy(poutbuf, poutbuf_size, + avctx->extradata, avctx->extradata_size, +- buf, nal_size) < 0) ++ buf, nal_size)) < 0) + goto fail; + ctx->first_idr = 0; + } else { +- if (alloc_and_copy(poutbuf, poutbuf_size, ++ if ((ret=alloc_and_copy(poutbuf, poutbuf_size, + NULL, 0, +- buf, nal_size) < 0) ++ buf, nal_size)) < 0) + goto fail; + if (!ctx->first_idr && unit_type == 1) + ctx->first_idr = 1; +@@ -166,7 +180,7 @@ + fail: + av_freep(poutbuf); + *poutbuf_size = 0; +- return AVERROR(EINVAL); ++ return ret; + } + + AVBitStreamFilter ff_h264_mp4toannexb_bsf = { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_mvpred.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_mvpred.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_mvpred.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_mvpred.h 2012-05-14 14:08:53.815329536 +0200 +@@ -35,7 +35,7 @@ + //#undef NDEBUG + #include + +-static inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ ++static av_always_inline int fetch_diagonal_mv(H264Context *h, const int16_t **C, int i, int list, int part_width){ + const int topright_ref= h->ref_cache[list][ i - 8 + part_width ]; + MpegEncContext *s = &h->s; + +@@ -48,15 +48,15 @@ + const int mb_type = mb_types[xy+(y4>>2)*s->mb_stride];\ + if(!USES_LIST(mb_type,list))\ + return LIST_NOT_USED;\ +- mv = s->current_picture_ptr->motion_val[list][h->mb2b_xy[xy]+3 + y4*h->b_stride];\ ++ mv = s->current_picture_ptr->f.motion_val[list][h->mb2b_xy[xy] + 3 + y4*h->b_stride];\ + h->mv_cache[list][scan8[0]-2][0] = mv[0];\ + h->mv_cache[list][scan8[0]-2][1] = mv[1] MV_OP;\ +- return s->current_picture_ptr->ref_index[list][4*xy+1 + (y4&~1)] REF_OP; ++ return s->current_picture_ptr->f.ref_index[list][4*xy + 1 + (y4 & ~1)] REF_OP; + + if(topright_ref == PART_NOT_AVAILABLE + && i >= scan8[0]+8 && (i&7)==4 + && h->ref_cache[list][scan8[0]-1] != PART_NOT_AVAILABLE){ +- const uint32_t *mb_types = s->current_picture_ptr->mb_type; ++ const uint32_t *mb_types = s->current_picture_ptr->f.mb_type; + const int16_t *mv; + AV_ZERO32(h->mv_cache[list][scan8[0]-2]); + *C = h->mv_cache[list][scan8[0]-2]; +@@ -64,7 +64,6 @@ + if(!MB_FIELD + && IS_INTERLACED(h->left_type[0])){ + SET_DIAG_MV(*2, >>1, h->left_mb_xy[0]+s->mb_stride, (s->mb_y&1)*2+(i>>5)); +- assert(h->left_mb_xy[0] == h->left_mb_xy[1]); + } + if(MB_FIELD + && !IS_INTERLACED(h->left_type[0])){ +@@ -87,13 +86,13 @@ + } + + /** +- * gets the predicted MV. ++ * Get the predicted MV. + * @param n the block index + * @param part_width the width of the partition (4, 8,16) -> (1, 2, 4) + * @param mx the x component of the predicted motion vector + * @param my the y component of the predicted motion vector + */ +-static inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ ++static av_always_inline void pred_motion(H264Context * const h, int n, int part_width, int list, int ref, int * const mx, int * const my){ + const int index8= scan8[n]; + const int top_ref= h->ref_cache[list][ index8 - 8 ]; + const int left_ref= h->ref_cache[list][ index8 - 1 ]; +@@ -143,12 +142,12 @@ + } + + /** +- * gets the directionally predicted 16x8 MV. ++ * Get the directionally predicted 16x8 MV. + * @param n the block index + * @param mx the x component of the predicted motion vector + * @param my the y component of the predicted motion vector + */ +-static inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ ++static av_always_inline void pred_16x8_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ + if(n==0){ + const int top_ref= h->ref_cache[list][ scan8[0] - 8 ]; + const int16_t * const B= h->mv_cache[list][ scan8[0] - 8 ]; +@@ -178,12 +177,12 @@ + } + + /** +- * gets the directionally predicted 8x16 MV. ++ * Get the directionally predicted 8x16 MV. + * @param n the block index + * @param mx the x component of the predicted motion vector + * @param my the y component of the predicted motion vector + */ +-static inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ ++static av_always_inline void pred_8x16_motion(H264Context * const h, int n, int list, int ref, int * const mx, int * const my){ + if(n==0){ + const int left_ref= h->ref_cache[list][ scan8[0] - 1 ]; + const int16_t * const A= h->mv_cache[list][ scan8[0] - 1 ]; +@@ -214,23 +213,580 @@ + pred_motion(h, n, 2, list, ref, mx, my); + } + +-static inline void pred_pskip_motion(H264Context * const h, int * const mx, int * const my){ +- const int top_ref = h->ref_cache[0][ scan8[0] - 8 ]; +- const int left_ref= h->ref_cache[0][ scan8[0] - 1 ]; ++#define FIX_MV_MBAFF(type, refn, mvn, idx)\ ++ if(FRAME_MBAFF){\ ++ if(MB_FIELD){\ ++ if(!IS_INTERLACED(type)){\ ++ refn <<= 1;\ ++ AV_COPY32(mvbuf[idx], mvn);\ ++ mvbuf[idx][1] /= 2;\ ++ mvn = mvbuf[idx];\ ++ }\ ++ }else{\ ++ if(IS_INTERLACED(type)){\ ++ refn >>= 1;\ ++ AV_COPY32(mvbuf[idx], mvn);\ ++ mvbuf[idx][1] <<= 1;\ ++ mvn = mvbuf[idx];\ ++ }\ ++ }\ ++ } + +- tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); ++static av_always_inline void pred_pskip_motion(H264Context * const h){ ++ DECLARE_ALIGNED(4, static const int16_t, zeromv)[2] = {0}; ++ DECLARE_ALIGNED(4, int16_t, mvbuf)[3][2]; ++ MpegEncContext * const s = &h->s; ++ int8_t *ref = s->current_picture.f.ref_index[0]; ++ int16_t (*mv)[2] = s->current_picture.f.motion_val[0]; ++ int top_ref, left_ref, diagonal_ref, match_count, mx, my; ++ const int16_t *A, *B, *C; ++ int b_stride = h->b_stride; ++ ++ fill_rectangle(&h->ref_cache[0][scan8[0]], 4, 4, 8, 0, 1); ++ ++ /* To avoid doing an entire fill_decode_caches, we inline the relevant parts here. ++ * FIXME: this is a partial duplicate of the logic in fill_decode_caches, but it's ++ * faster this way. Is there a way to avoid this duplication? ++ */ ++ if(USES_LIST(h->left_type[LTOP], 0)){ ++ left_ref = ref[4*h->left_mb_xy[LTOP] + 1 + (h->left_block[0]&~1)]; ++ A = mv[h->mb2b_xy[h->left_mb_xy[LTOP]] + 3 + b_stride*h->left_block[0]]; ++ FIX_MV_MBAFF(h->left_type[LTOP], left_ref, A, 0); ++ if(!(left_ref | AV_RN32A(A))){ ++ goto zeromv; ++ } ++ }else if(h->left_type[LTOP]){ ++ left_ref = LIST_NOT_USED; ++ A = zeromv; ++ }else{ ++ goto zeromv; ++ } + +- if(top_ref == PART_NOT_AVAILABLE || left_ref == PART_NOT_AVAILABLE +- || !( top_ref | AV_RN32A(h->mv_cache[0][ scan8[0] - 8 ])) +- || !(left_ref | AV_RN32A(h->mv_cache[0][ scan8[0] - 1 ]))){ ++ if(USES_LIST(h->top_type, 0)){ ++ top_ref = ref[4*h->top_mb_xy + 2]; ++ B = mv[h->mb2b_xy[h->top_mb_xy] + 3*b_stride]; ++ FIX_MV_MBAFF(h->top_type, top_ref, B, 1); ++ if(!(top_ref | AV_RN32A(B))){ ++ goto zeromv; ++ } ++ }else if(h->top_type){ ++ top_ref = LIST_NOT_USED; ++ B = zeromv; ++ }else{ ++ goto zeromv; ++ } + +- *mx = *my = 0; +- return; ++ tprintf(h->s.avctx, "pred_pskip: (%d) (%d) at %2d %2d\n", top_ref, left_ref, h->s.mb_x, h->s.mb_y); ++ ++ if(USES_LIST(h->topright_type, 0)){ ++ diagonal_ref = ref[4*h->topright_mb_xy + 2]; ++ C = mv[h->mb2b_xy[h->topright_mb_xy] + 3*b_stride]; ++ FIX_MV_MBAFF(h->topright_type, diagonal_ref, C, 2); ++ }else if(h->topright_type){ ++ diagonal_ref = LIST_NOT_USED; ++ C = zeromv; ++ }else{ ++ if(USES_LIST(h->topleft_type, 0)){ ++ diagonal_ref = ref[4*h->topleft_mb_xy + 1 + (h->topleft_partition & 2)]; ++ C = mv[h->mb2b_xy[h->topleft_mb_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride)]; ++ FIX_MV_MBAFF(h->topleft_type, diagonal_ref, C, 2); ++ }else if(h->topleft_type){ ++ diagonal_ref = LIST_NOT_USED; ++ C = zeromv; ++ }else{ ++ diagonal_ref = PART_NOT_AVAILABLE; ++ C = zeromv; ++ } + } + +- pred_motion(h, 0, 4, 0, 0, mx, my); ++ match_count= !diagonal_ref + !top_ref + !left_ref; ++ tprintf(h->s.avctx, "pred_pskip_motion match_count=%d\n", match_count); ++ if(match_count > 1){ ++ mx = mid_pred(A[0], B[0], C[0]); ++ my = mid_pred(A[1], B[1], C[1]); ++ }else if(match_count==1){ ++ if(!left_ref){ ++ mx = A[0]; ++ my = A[1]; ++ }else if(!top_ref){ ++ mx = B[0]; ++ my = B[1]; ++ }else{ ++ mx = C[0]; ++ my = C[1]; ++ } ++ }else{ ++ mx = mid_pred(A[0], B[0], C[0]); ++ my = mid_pred(A[1], B[1], C[1]); ++ } + ++ fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, pack16to32(mx,my), 4); ++ return; ++zeromv: ++ fill_rectangle( h->mv_cache[0][scan8[0]], 4, 4, 8, 0, 4); + return; + } + ++static void fill_decode_neighbors(H264Context *h, int mb_type){ ++ MpegEncContext * const s = &h->s; ++ const int mb_xy= h->mb_xy; ++ int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; ++ static const uint8_t left_block_options[4][32]={ ++ {0,1,2,3,7,10,8,11,3+0*4, 3+1*4, 3+2*4, 3+3*4, 1+4*4, 1+8*4, 1+5*4, 1+9*4}, ++ {2,2,3,3,8,11,8,11,3+2*4, 3+2*4, 3+3*4, 3+3*4, 1+5*4, 1+9*4, 1+5*4, 1+9*4}, ++ {0,0,1,1,7,10,7,10,3+0*4, 3+0*4, 3+1*4, 3+1*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4}, ++ {0,2,0,2,7,10,7,10,3+0*4, 3+2*4, 3+0*4, 3+2*4, 1+4*4, 1+8*4, 1+4*4, 1+8*4} ++ }; ++ ++ h->topleft_partition= -1; ++ ++ top_xy = mb_xy - (s->mb_stride << MB_FIELD); ++ ++ /* Wow, what a mess, why didn't they simplify the interlacing & intra ++ * stuff, I can't imagine that these complex rules are worth it. */ ++ ++ topleft_xy = top_xy - 1; ++ topright_xy= top_xy + 1; ++ left_xy[LBOT] = left_xy[LTOP] = mb_xy-1; ++ h->left_block = left_block_options[0]; ++ if(FRAME_MBAFF){ ++ const int left_mb_field_flag = IS_INTERLACED(s->current_picture.f.mb_type[mb_xy - 1]); ++ const int curr_mb_field_flag = IS_INTERLACED(mb_type); ++ if(s->mb_y&1){ ++ if (left_mb_field_flag != curr_mb_field_flag) { ++ left_xy[LBOT] = left_xy[LTOP] = mb_xy - s->mb_stride - 1; ++ if (curr_mb_field_flag) { ++ left_xy[LBOT] += s->mb_stride; ++ h->left_block = left_block_options[3]; ++ } else { ++ topleft_xy += s->mb_stride; ++ // take top left mv from the middle of the mb, as opposed to all other modes which use the bottom right partition ++ h->topleft_partition = 0; ++ h->left_block = left_block_options[1]; ++ } ++ } ++ }else{ ++ if(curr_mb_field_flag){ ++ topleft_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy - 1] >> 7) & 1) - 1); ++ topright_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy + 1] >> 7) & 1) - 1); ++ top_xy += s->mb_stride & (((s->current_picture.f.mb_type[top_xy ] >> 7) & 1) - 1); ++ } ++ if (left_mb_field_flag != curr_mb_field_flag) { ++ if (curr_mb_field_flag) { ++ left_xy[LBOT] += s->mb_stride; ++ h->left_block = left_block_options[3]; ++ } else { ++ h->left_block = left_block_options[2]; ++ } ++ } ++ } ++ } ++ ++ h->topleft_mb_xy = topleft_xy; ++ h->top_mb_xy = top_xy; ++ h->topright_mb_xy= topright_xy; ++ h->left_mb_xy[LTOP] = left_xy[LTOP]; ++ h->left_mb_xy[LBOT] = left_xy[LBOT]; ++ //FIXME do we need all in the context? ++ ++ h->topleft_type = s->current_picture.f.mb_type[topleft_xy]; ++ h->top_type = s->current_picture.f.mb_type[top_xy]; ++ h->topright_type = s->current_picture.f.mb_type[topright_xy]; ++ h->left_type[LTOP] = s->current_picture.f.mb_type[left_xy[LTOP]]; ++ h->left_type[LBOT] = s->current_picture.f.mb_type[left_xy[LBOT]]; ++ ++ if(FMO){ ++ if(h->slice_table[topleft_xy ] != h->slice_num) h->topleft_type = 0; ++ if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0; ++ if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0; ++ }else{ ++ if(h->slice_table[topleft_xy ] != h->slice_num){ ++ h->topleft_type = 0; ++ if(h->slice_table[top_xy ] != h->slice_num) h->top_type = 0; ++ if(h->slice_table[left_xy[LTOP] ] != h->slice_num) h->left_type[LTOP] = h->left_type[LBOT] = 0; ++ } ++ } ++ if(h->slice_table[topright_xy] != h->slice_num) h->topright_type= 0; ++} ++ ++static void fill_decode_caches(H264Context *h, int mb_type){ ++ MpegEncContext * const s = &h->s; ++ int topleft_xy, top_xy, topright_xy, left_xy[LEFT_MBS]; ++ int topleft_type, top_type, topright_type, left_type[LEFT_MBS]; ++ const uint8_t * left_block= h->left_block; ++ int i; ++ uint8_t *nnz; ++ uint8_t *nnz_cache; ++ ++ topleft_xy = h->topleft_mb_xy; ++ top_xy = h->top_mb_xy; ++ topright_xy = h->topright_mb_xy; ++ left_xy[LTOP] = h->left_mb_xy[LTOP]; ++ left_xy[LBOT] = h->left_mb_xy[LBOT]; ++ topleft_type = h->topleft_type; ++ top_type = h->top_type; ++ topright_type = h->topright_type; ++ left_type[LTOP]= h->left_type[LTOP]; ++ left_type[LBOT]= h->left_type[LBOT]; ++ ++ if(!IS_SKIP(mb_type)){ ++ if(IS_INTRA(mb_type)){ ++ int type_mask= h->pps.constrained_intra_pred ? IS_INTRA(-1) : -1; ++ h->topleft_samples_available= ++ h->top_samples_available= ++ h->left_samples_available= 0xFFFF; ++ h->topright_samples_available= 0xEEEA; ++ ++ if(!(top_type & type_mask)){ ++ h->topleft_samples_available= 0xB3FF; ++ h->top_samples_available= 0x33FF; ++ h->topright_samples_available= 0x26EA; ++ } ++ if(IS_INTERLACED(mb_type) != IS_INTERLACED(left_type[LTOP])){ ++ if(IS_INTERLACED(mb_type)){ ++ if(!(left_type[LTOP] & type_mask)){ ++ h->topleft_samples_available&= 0xDFFF; ++ h->left_samples_available&= 0x5FFF; ++ } ++ if(!(left_type[LBOT] & type_mask)){ ++ h->topleft_samples_available&= 0xFF5F; ++ h->left_samples_available&= 0xFF5F; ++ } ++ }else{ ++ int left_typei = s->current_picture.f.mb_type[left_xy[LTOP] + s->mb_stride]; ++ ++ assert(left_xy[LTOP] == left_xy[LBOT]); ++ if(!((left_typei & type_mask) && (left_type[LTOP] & type_mask))){ ++ h->topleft_samples_available&= 0xDF5F; ++ h->left_samples_available&= 0x5F5F; ++ } ++ } ++ }else{ ++ if(!(left_type[LTOP] & type_mask)){ ++ h->topleft_samples_available&= 0xDF5F; ++ h->left_samples_available&= 0x5F5F; ++ } ++ } ++ ++ if(!(topleft_type & type_mask)) ++ h->topleft_samples_available&= 0x7FFF; ++ ++ if(!(topright_type & type_mask)) ++ h->topright_samples_available&= 0xFBFF; ++ ++ if(IS_INTRA4x4(mb_type)){ ++ if(IS_INTRA4x4(top_type)){ ++ AV_COPY32(h->intra4x4_pred_mode_cache+4+8*0, h->intra4x4_pred_mode + h->mb2br_xy[top_xy]); ++ }else{ ++ h->intra4x4_pred_mode_cache[4+8*0]= ++ h->intra4x4_pred_mode_cache[5+8*0]= ++ h->intra4x4_pred_mode_cache[6+8*0]= ++ h->intra4x4_pred_mode_cache[7+8*0]= 2 - 3*!(top_type & type_mask); ++ } ++ for(i=0; i<2; i++){ ++ if(IS_INTRA4x4(left_type[LEFT(i)])){ ++ int8_t *mode= h->intra4x4_pred_mode + h->mb2br_xy[left_xy[LEFT(i)]]; ++ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= mode[6-left_block[0+2*i]]; ++ h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= mode[6-left_block[1+2*i]]; ++ }else{ ++ h->intra4x4_pred_mode_cache[3+8*1 + 2*8*i]= ++ h->intra4x4_pred_mode_cache[3+8*2 + 2*8*i]= 2 - 3*!(left_type[LEFT(i)] & type_mask); ++ } ++ } ++ } ++ } ++ ++ ++/* ++0 . T T. T T T T ++1 L . .L . . . . ++2 L . .L . . . . ++3 . T TL . . . . ++4 L . .L . . . . ++5 L . .. . . . . ++*/ ++//FIXME constraint_intra_pred & partitioning & nnz (let us hope this is just a typo in the spec) ++ nnz_cache = h->non_zero_count_cache; ++ if(top_type){ ++ nnz = h->non_zero_count[top_xy]; ++ AV_COPY32(&nnz_cache[4+8* 0], &nnz[4*3]); ++ if(!s->chroma_y_shift){ ++ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 7]); ++ AV_COPY32(&nnz_cache[4+8*10], &nnz[4*11]); ++ }else{ ++ AV_COPY32(&nnz_cache[4+8* 5], &nnz[4* 5]); ++ AV_COPY32(&nnz_cache[4+8*10], &nnz[4* 9]); ++ } ++ }else{ ++ uint32_t top_empty = CABAC && !IS_INTRA(mb_type) ? 0 : 0x40404040; ++ AV_WN32A(&nnz_cache[4+8* 0], top_empty); ++ AV_WN32A(&nnz_cache[4+8* 5], top_empty); ++ AV_WN32A(&nnz_cache[4+8*10], top_empty); ++ } ++ ++ for (i=0; i<2; i++) { ++ if(left_type[LEFT(i)]){ ++ nnz = h->non_zero_count[left_xy[LEFT(i)]]; ++ nnz_cache[3+8* 1 + 2*8*i]= nnz[left_block[8+0+2*i]]; ++ nnz_cache[3+8* 2 + 2*8*i]= nnz[left_block[8+1+2*i]]; ++ if(CHROMA444){ ++ nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]+4*4]; ++ nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]+4*4]; ++ nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]+8*4]; ++ nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]+8*4]; ++ }else if(CHROMA422) { ++ nnz_cache[3+8* 6 + 2*8*i]= nnz[left_block[8+0+2*i]-2+4*4]; ++ nnz_cache[3+8* 7 + 2*8*i]= nnz[left_block[8+1+2*i]-2+4*4]; ++ nnz_cache[3+8*11 + 2*8*i]= nnz[left_block[8+0+2*i]-2+8*4]; ++ nnz_cache[3+8*12 + 2*8*i]= nnz[left_block[8+1+2*i]-2+8*4]; ++ }else{ ++ nnz_cache[3+8* 6 + 8*i]= nnz[left_block[8+4+2*i]]; ++ nnz_cache[3+8*11 + 8*i]= nnz[left_block[8+5+2*i]]; ++ } ++ }else{ ++ nnz_cache[3+8* 1 + 2*8*i]= ++ nnz_cache[3+8* 2 + 2*8*i]= ++ nnz_cache[3+8* 6 + 2*8*i]= ++ nnz_cache[3+8* 7 + 2*8*i]= ++ nnz_cache[3+8*11 + 2*8*i]= ++ nnz_cache[3+8*12 + 2*8*i]= CABAC && !IS_INTRA(mb_type) ? 0 : 64; ++ } ++ } ++ ++ if( CABAC ) { ++ // top_cbp ++ if(top_type) { ++ h->top_cbp = h->cbp_table[top_xy]; ++ } else { ++ h->top_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; ++ } ++ // left_cbp ++ if (left_type[LTOP]) { ++ h->left_cbp = (h->cbp_table[left_xy[LTOP]] & 0x7F0) ++ | ((h->cbp_table[left_xy[LTOP]]>>(left_block[0]&(~1)))&2) ++ | (((h->cbp_table[left_xy[LBOT]]>>(left_block[2]&(~1)))&2) << 2); ++ } else { ++ h->left_cbp = IS_INTRA(mb_type) ? 0x7CF : 0x00F; ++ } ++ } ++ } ++ ++ if(IS_INTER(mb_type) || (IS_DIRECT(mb_type) && h->direct_spatial_mv_pred)){ ++ int list; ++ int b_stride = h->b_stride; ++ for(list=0; listlist_count; list++){ ++ int8_t *ref_cache = &h->ref_cache[list][scan8[0]]; ++ int8_t *ref = s->current_picture.f.ref_index[list]; ++ int16_t (*mv_cache)[2] = &h->mv_cache[list][scan8[0]]; ++ int16_t (*mv)[2] = s->current_picture.f.motion_val[list]; ++ if(!USES_LIST(mb_type, list)){ ++ continue; ++ } ++ assert(!(IS_DIRECT(mb_type) && !h->direct_spatial_mv_pred)); ++ ++ if(USES_LIST(top_type, list)){ ++ const int b_xy= h->mb2b_xy[top_xy] + 3*b_stride; ++ AV_COPY128(mv_cache[0 - 1*8], mv[b_xy + 0]); ++ ref_cache[0 - 1*8]= ++ ref_cache[1 - 1*8]= ref[4*top_xy + 2]; ++ ref_cache[2 - 1*8]= ++ ref_cache[3 - 1*8]= ref[4*top_xy + 3]; ++ }else{ ++ AV_ZERO128(mv_cache[0 - 1*8]); ++ AV_WN32A(&ref_cache[0 - 1*8], ((top_type ? LIST_NOT_USED : PART_NOT_AVAILABLE)&0xFF)*0x01010101u); ++ } ++ ++ if(mb_type & (MB_TYPE_16x8|MB_TYPE_8x8)){ ++ for(i=0; i<2; i++){ ++ int cache_idx = -1 + i*2*8; ++ if(USES_LIST(left_type[LEFT(i)], list)){ ++ const int b_xy= h->mb2b_xy[left_xy[LEFT(i)]] + 3; ++ const int b8_xy= 4*left_xy[LEFT(i)] + 1; ++ AV_COPY32(mv_cache[cache_idx ], mv[b_xy + b_stride*left_block[0+i*2]]); ++ AV_COPY32(mv_cache[cache_idx+8], mv[b_xy + b_stride*left_block[1+i*2]]); ++ ref_cache[cache_idx ]= ref[b8_xy + (left_block[0+i*2]&~1)]; ++ ref_cache[cache_idx+8]= ref[b8_xy + (left_block[1+i*2]&~1)]; ++ }else{ ++ AV_ZERO32(mv_cache[cache_idx ]); ++ AV_ZERO32(mv_cache[cache_idx+8]); ++ ref_cache[cache_idx ]= ++ ref_cache[cache_idx+8]= (left_type[LEFT(i)]) ? LIST_NOT_USED : PART_NOT_AVAILABLE; ++ } ++ } ++ }else{ ++ if(USES_LIST(left_type[LTOP], list)){ ++ const int b_xy= h->mb2b_xy[left_xy[LTOP]] + 3; ++ const int b8_xy= 4*left_xy[LTOP] + 1; ++ AV_COPY32(mv_cache[-1], mv[b_xy + b_stride*left_block[0]]); ++ ref_cache[-1]= ref[b8_xy + (left_block[0]&~1)]; ++ }else{ ++ AV_ZERO32(mv_cache[-1]); ++ ref_cache[-1]= left_type[LTOP] ? LIST_NOT_USED : PART_NOT_AVAILABLE; ++ } ++ } ++ ++ if(USES_LIST(topright_type, list)){ ++ const int b_xy= h->mb2b_xy[topright_xy] + 3*b_stride; ++ AV_COPY32(mv_cache[4 - 1*8], mv[b_xy]); ++ ref_cache[4 - 1*8]= ref[4*topright_xy + 2]; ++ }else{ ++ AV_ZERO32(mv_cache[4 - 1*8]); ++ ref_cache[4 - 1*8]= topright_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; ++ } ++ if(ref_cache[2 - 1*8] < 0 || ref_cache[4 - 1*8] < 0){ ++ if(USES_LIST(topleft_type, list)){ ++ const int b_xy = h->mb2b_xy[topleft_xy] + 3 + b_stride + (h->topleft_partition & 2*b_stride); ++ const int b8_xy= 4*topleft_xy + 1 + (h->topleft_partition & 2); ++ AV_COPY32(mv_cache[-1 - 1*8], mv[b_xy]); ++ ref_cache[-1 - 1*8]= ref[b8_xy]; ++ }else{ ++ AV_ZERO32(mv_cache[-1 - 1*8]); ++ ref_cache[-1 - 1*8]= topleft_type ? LIST_NOT_USED : PART_NOT_AVAILABLE; ++ } ++ } ++ ++ if((mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2)) && !FRAME_MBAFF) ++ continue; ++ ++ if(!(mb_type&(MB_TYPE_SKIP|MB_TYPE_DIRECT2))){ ++ uint8_t (*mvd_cache)[2] = &h->mvd_cache[list][scan8[0]]; ++ uint8_t (*mvd)[2] = h->mvd_table[list]; ++ ref_cache[2+8*0] = ++ ref_cache[2+8*2] = PART_NOT_AVAILABLE; ++ AV_ZERO32(mv_cache[2+8*0]); ++ AV_ZERO32(mv_cache[2+8*2]); ++ ++ if( CABAC ) { ++ if(USES_LIST(top_type, list)){ ++ const int b_xy= h->mb2br_xy[top_xy]; ++ AV_COPY64(mvd_cache[0 - 1*8], mvd[b_xy + 0]); ++ }else{ ++ AV_ZERO64(mvd_cache[0 - 1*8]); ++ } ++ if(USES_LIST(left_type[LTOP], list)){ ++ const int b_xy= h->mb2br_xy[left_xy[LTOP]] + 6; ++ AV_COPY16(mvd_cache[-1 + 0*8], mvd[b_xy - left_block[0]]); ++ AV_COPY16(mvd_cache[-1 + 1*8], mvd[b_xy - left_block[1]]); ++ }else{ ++ AV_ZERO16(mvd_cache[-1 + 0*8]); ++ AV_ZERO16(mvd_cache[-1 + 1*8]); ++ } ++ if(USES_LIST(left_type[LBOT], list)){ ++ const int b_xy= h->mb2br_xy[left_xy[LBOT]] + 6; ++ AV_COPY16(mvd_cache[-1 + 2*8], mvd[b_xy - left_block[2]]); ++ AV_COPY16(mvd_cache[-1 + 3*8], mvd[b_xy - left_block[3]]); ++ }else{ ++ AV_ZERO16(mvd_cache[-1 + 2*8]); ++ AV_ZERO16(mvd_cache[-1 + 3*8]); ++ } ++ AV_ZERO16(mvd_cache[2+8*0]); ++ AV_ZERO16(mvd_cache[2+8*2]); ++ if(h->slice_type_nos == AV_PICTURE_TYPE_B){ ++ uint8_t *direct_cache = &h->direct_cache[scan8[0]]; ++ uint8_t *direct_table = h->direct_table; ++ fill_rectangle(direct_cache, 4, 4, 8, MB_TYPE_16x16>>1, 1); ++ ++ if(IS_DIRECT(top_type)){ ++ AV_WN32A(&direct_cache[-1*8], 0x01010101u*(MB_TYPE_DIRECT2>>1)); ++ }else if(IS_8X8(top_type)){ ++ int b8_xy = 4*top_xy; ++ direct_cache[0 - 1*8]= direct_table[b8_xy + 2]; ++ direct_cache[2 - 1*8]= direct_table[b8_xy + 3]; ++ }else{ ++ AV_WN32A(&direct_cache[-1*8], 0x01010101*(MB_TYPE_16x16>>1)); ++ } ++ ++ if(IS_DIRECT(left_type[LTOP])) ++ direct_cache[-1 + 0*8]= MB_TYPE_DIRECT2>>1; ++ else if(IS_8X8(left_type[LTOP])) ++ direct_cache[-1 + 0*8]= direct_table[4*left_xy[LTOP] + 1 + (left_block[0]&~1)]; ++ else ++ direct_cache[-1 + 0*8]= MB_TYPE_16x16>>1; ++ ++ if(IS_DIRECT(left_type[LBOT])) ++ direct_cache[-1 + 2*8]= MB_TYPE_DIRECT2>>1; ++ else if(IS_8X8(left_type[LBOT])) ++ direct_cache[-1 + 2*8]= direct_table[4*left_xy[LBOT] + 1 + (left_block[2]&~1)]; ++ else ++ direct_cache[-1 + 2*8]= MB_TYPE_16x16>>1; ++ } ++ } ++ } ++ if(FRAME_MBAFF){ ++#define MAP_MVS\ ++ MAP_F2F(scan8[0] - 1 - 1*8, topleft_type)\ ++ MAP_F2F(scan8[0] + 0 - 1*8, top_type)\ ++ MAP_F2F(scan8[0] + 1 - 1*8, top_type)\ ++ MAP_F2F(scan8[0] + 2 - 1*8, top_type)\ ++ MAP_F2F(scan8[0] + 3 - 1*8, top_type)\ ++ MAP_F2F(scan8[0] + 4 - 1*8, topright_type)\ ++ MAP_F2F(scan8[0] - 1 + 0*8, left_type[LTOP])\ ++ MAP_F2F(scan8[0] - 1 + 1*8, left_type[LTOP])\ ++ MAP_F2F(scan8[0] - 1 + 2*8, left_type[LBOT])\ ++ MAP_F2F(scan8[0] - 1 + 3*8, left_type[LBOT]) ++ if(MB_FIELD){ ++#define MAP_F2F(idx, mb_type)\ ++ if(!IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ ++ h->ref_cache[list][idx] <<= 1;\ ++ h->mv_cache[list][idx][1] /= 2;\ ++ h->mvd_cache[list][idx][1] >>=1;\ ++ } ++ MAP_MVS ++#undef MAP_F2F ++ }else{ ++#define MAP_F2F(idx, mb_type)\ ++ if(IS_INTERLACED(mb_type) && h->ref_cache[list][idx] >= 0){\ ++ h->ref_cache[list][idx] >>= 1;\ ++ h->mv_cache[list][idx][1] <<= 1;\ ++ h->mvd_cache[list][idx][1] <<= 1;\ ++ } ++ MAP_MVS ++#undef MAP_F2F ++ } ++ } ++ } ++ } ++ ++ h->neighbor_transform_size= !!IS_8x8DCT(top_type) + !!IS_8x8DCT(left_type[LTOP]); ++} ++ ++/** ++ * decodes a P_SKIP or B_SKIP macroblock ++ */ ++static void av_unused decode_mb_skip(H264Context *h){ ++ MpegEncContext * const s = &h->s; ++ const int mb_xy= h->mb_xy; ++ int mb_type=0; ++ ++ memset(h->non_zero_count[mb_xy], 0, 48); ++ ++ if(MB_FIELD) ++ mb_type|= MB_TYPE_INTERLACED; ++ ++ if( h->slice_type_nos == AV_PICTURE_TYPE_B ) ++ { ++ // just for fill_caches. pred_direct_motion will set the real mb_type ++ mb_type|= MB_TYPE_L0L1|MB_TYPE_DIRECT2|MB_TYPE_SKIP; ++ if(h->direct_spatial_mv_pred){ ++ fill_decode_neighbors(h, mb_type); ++ fill_decode_caches(h, mb_type); //FIXME check what is needed and what not ... ++ } ++ ff_h264_pred_direct_motion(h, &mb_type); ++ mb_type|= MB_TYPE_SKIP; ++ } ++ else ++ { ++ mb_type|= MB_TYPE_16x16|MB_TYPE_P0L0|MB_TYPE_P1L0|MB_TYPE_SKIP; ++ ++ fill_decode_neighbors(h, mb_type); ++ pred_pskip_motion(h); ++ } ++ ++ write_back_motion(h, mb_type); ++ s->current_picture.f.mb_type[mb_xy] = mb_type; ++ s->current_picture.f.qscale_table[mb_xy] = s->qscale; ++ h->slice_table[ mb_xy ]= h->slice_num; ++ h->prev_mb_skipped= 1; ++} ++ + #endif /* AVCODEC_H264_MVPRED_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_parser.c 2012-05-14 14:08:53.816329556 +0200 +@@ -25,6 +25,8 @@ + * @author Michael Niedermayer + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + #include "parser.h" + #include "h264data.h" + #include "golomb.h" +@@ -34,30 +36,48 @@ + + static int ff_h264_find_frame_end(H264Context *h, const uint8_t *buf, int buf_size) + { +- int i; ++ int i, j; + uint32_t state; + ParseContext *pc = &(h->s.parse_context); ++ int next_avc= h->is_avc ? 0 : buf_size; ++ + //printf("first %02X%02X%02X%02X\n", buf[0], buf[1],buf[2],buf[3]); + // mb_addr= pc->mb_addr - 1; + state= pc->state; + if(state>13) + state= 7; + ++ if(h->is_avc && !h->nal_length_size) ++ av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal length size invalid\n"); ++ + for(i=0; i= next_avc) { ++ int nalsize = 0; ++ i = next_avc; ++ for(j = 0; j < h->nal_length_size; j++) ++ nalsize = (nalsize << 8) | buf[i++]; ++ if(nalsize <= 0 || nalsize > buf_size - i){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "AVC-parser: nal size %d remaining %d\n", nalsize, buf_size - i); ++ return buf_size; ++ } ++ next_avc= i + nalsize; ++ state= 5; ++ } ++ + if(state==7){ + #if HAVE_FAST_UNALIGNED + /* we check iparse_history[h->parse_history_count++]= buf[i]; ++ if(h->parse_history_count>3){ ++ unsigned int mb, last_mb= h->parse_last_mb; ++ GetBitContext gb; ++ ++ init_get_bits(&gb, h->parse_history, 8*h->parse_history_count); ++ h->parse_history_count=0; ++ mb= get_ue_golomb_long(&gb); ++ last_mb= h->parse_last_mb; ++ h->parse_last_mb= mb; + if(pc->frame_start_found){ +- state+=8; +- continue; ++ if(mb <= last_mb) ++ goto found; + }else + pc->frame_start_found = 1; ++ state= 7; + } +- state= 7; +- }else{ +- if(buf[i] & 0x80) +- goto found; +- state= 7; + } + } + pc->state= state; ++ if(h->is_avc) ++ return next_avc; + return END_NOT_FOUND; + + found: + pc->state=7; + pc->frame_start_found= 0; +- return i-(state&5); ++ if(h->is_avc) ++ return next_avc; ++ return i-(state&5) - 3*(state>7); + } + +-/*! ++/** + * Parse NAL units of found picture and decode some basic information. + * + * @param s parser context. +@@ -115,9 +150,10 @@ + unsigned int slice_type; + int state = -1; + const uint8_t *ptr; ++ int q264 = buf_size >=4 && !memcmp("Q264", buf, 4); + + /* set some sane default values */ +- s->pict_type = FF_I_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_I; + s->key_frame = 0; + + h->s.avctx= avctx; +@@ -131,7 +167,7 @@ + + for(;;) { + int src_length, dst_length, consumed; +- buf = ff_find_start_code(buf, buf_end, &state); ++ buf = avpriv_mpv_find_start_code(buf, buf_end, &state); + if(buf >= buf_end) + break; + --buf; +@@ -163,7 +199,7 @@ + s->key_frame = 1; + /* fall through */ + case NAL_SLICE: +- get_ue_golomb(&h->s.gb); // skip first_mb_in_slice ++ get_ue_golomb_long(&h->s.gb); // skip first_mb_in_slice + slice_type = get_ue_golomb_31(&h->s.gb); + s->pict_type = golomb_to_pict_type[slice_type % 5]; + if (h->sei_recovery_frame_cnt >= 0) { +@@ -233,8 +269,10 @@ + } + buf += consumed; + } ++ if (q264) ++ return 0; + /* didn't find a picture! */ +- av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit\n"); ++ av_log(h->s.avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); + return -1; + } + +@@ -251,7 +289,13 @@ + h->got_first = 1; + if (avctx->extradata_size) { + h->s.avctx = avctx; +- ff_h264_decode_extradata(h); ++ // must be done like in decoder, otherwise opening the parser, ++ // letting it create extradata and then closing and opening again ++ // will cause has_b_frames to be always set. ++ // Note that estimate_timings_from_pts does exactly this. ++ if (!avctx->has_b_frames) ++ h->s.low_delay = 1; ++ ff_h264_decode_extradata(h, avctx->extradata, avctx->extradata_size); + } + } + +@@ -270,21 +314,24 @@ + assert(pc->last_index + next >= 0 ); + ff_h264_find_frame_end(h, &pc->buffer[pc->last_index + next], -next); //update state + } ++ } + +- parse_nal_units(s, avctx, buf, buf_size); ++ if(!h->is_avc){ ++ parse_nal_units(s, avctx, buf, buf_size); + +- if (h->sei_cpb_removal_delay >= 0) { +- s->dts_sync_point = h->sei_buffering_period_present; +- s->dts_ref_dts_delta = h->sei_cpb_removal_delay; +- s->pts_dts_delta = h->sei_dpb_output_delay; +- } else { +- s->dts_sync_point = INT_MIN; +- s->dts_ref_dts_delta = INT_MIN; +- s->pts_dts_delta = INT_MIN; +- } +- if (s->flags & PARSER_FLAG_ONCE) { +- s->flags &= PARSER_FLAG_COMPLETE_FRAMES; +- } ++ if (h->sei_cpb_removal_delay >= 0) { ++ s->dts_sync_point = h->sei_buffering_period_present; ++ s->dts_ref_dts_delta = h->sei_cpb_removal_delay; ++ s->pts_dts_delta = h->sei_dpb_output_delay; ++ } else { ++ s->dts_sync_point = INT_MIN; ++ s->dts_ref_dts_delta = INT_MIN; ++ s->pts_dts_delta = INT_MIN; ++ } ++ ++ if (s->flags & PARSER_FLAG_ONCE) { ++ s->flags &= PARSER_FLAG_COMPLETE_FRAMES; ++ } + } + + *poutbuf = buf; +@@ -329,14 +376,15 @@ + { + H264Context *h = s->priv_data; + h->thread_context[0] = h; ++ h->s.slice_context_count = 1; + return 0; + } + + AVCodecParser ff_h264_parser = { +- { CODEC_ID_H264 }, +- sizeof(H264Context), +- init, +- h264_parse, +- close, +- h264_split, ++ .codec_ids = { CODEC_ID_H264 }, ++ .priv_data_size = sizeof(H264Context), ++ .parser_init = init, ++ .parser_parse = h264_parse, ++ .parser_close = close, ++ .split = h264_split, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred.c 2012-05-14 14:08:53.831329858 +0200 +@@ -25,108 +25,28 @@ + * @author Michael Niedermayer + */ + +-#include "avcodec.h" +-#include "mpegvideo.h" + #include "h264pred.h" +-#include "mathops.h" + +-static void pred4x4_vertical_c(uint8_t *src, const uint8_t *topright, int stride){ +- const uint32_t a= ((uint32_t*)(src-stride))[0]; +- ((uint32_t*)(src+0*stride))[0]= a; +- ((uint32_t*)(src+1*stride))[0]= a; +- ((uint32_t*)(src+2*stride))[0]= a; +- ((uint32_t*)(src+3*stride))[0]= a; +-} +- +-static void pred4x4_horizontal_c(uint8_t *src, const uint8_t *topright, int stride){ +- ((uint32_t*)(src+0*stride))[0]= src[-1+0*stride]*0x01010101; +- ((uint32_t*)(src+1*stride))[0]= src[-1+1*stride]*0x01010101; +- ((uint32_t*)(src+2*stride))[0]= src[-1+2*stride]*0x01010101; +- ((uint32_t*)(src+3*stride))[0]= src[-1+3*stride]*0x01010101; +-} +- +-static void pred4x4_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] +- + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; +- +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +-} +- +-static void pred4x4_left_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; +- +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +-} +- +-static void pred4x4_top_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; +- +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= dc* 0x01010101; +-} +- +-static void pred4x4_128_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= 128U*0x01010101U; +-} +- +-static void pred4x4_127_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= 127U*0x01010101U; +-} +- +-static void pred4x4_129_dc_c(uint8_t *src, const uint8_t *topright, int stride){ +- ((uint32_t*)(src+0*stride))[0]= +- ((uint32_t*)(src+1*stride))[0]= +- ((uint32_t*)(src+2*stride))[0]= +- ((uint32_t*)(src+3*stride))[0]= 129U*0x01010101U; +-} +- +- +-#define LOAD_TOP_RIGHT_EDGE\ +- const int av_unused t4= topright[0];\ +- const int av_unused t5= topright[1];\ +- const int av_unused t6= topright[2];\ +- const int av_unused t7= topright[3];\ +- +-#define LOAD_DOWN_LEFT_EDGE\ +- const int av_unused l4= src[-1+4*stride];\ +- const int av_unused l5= src[-1+5*stride];\ +- const int av_unused l6= src[-1+6*stride];\ +- const int av_unused l7= src[-1+7*stride];\ +- +-#define LOAD_LEFT_EDGE\ +- const int av_unused l0= src[-1+0*stride];\ +- const int av_unused l1= src[-1+1*stride];\ +- const int av_unused l2= src[-1+2*stride];\ +- const int av_unused l3= src[-1+3*stride];\ +- +-#define LOAD_TOP_EDGE\ +- const int av_unused t0= src[ 0-1*stride];\ +- const int av_unused t1= src[ 1-1*stride];\ +- const int av_unused t2= src[ 2-1*stride];\ +- const int av_unused t3= src[ 3-1*stride];\ ++#define BIT_DEPTH 8 ++#include "h264pred_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 9 ++#include "h264pred_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "h264pred_template.c" ++#undef BIT_DEPTH + + static void pred4x4_vertical_vp8_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int lt= src[-1-1*stride]; ++ const unsigned lt = src[-1-1*stride]; + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + uint32_t v = PACK_4U8((lt + 2*t0 + t1 + 2) >> 2, +- (t0 + 2*t1 + t2 + 2) >> 2, +- (t1 + 2*t2 + t3 + 2) >> 2, +- (t2 + 2*t3 + t4 + 2) >> 2); ++ (t0 + 2*t1 + t2 + 2) >> 2, ++ (t1 + 2*t2 + t3 + 2) >> 2, ++ (t2 + 2*t3 + t4 + 2) >> 2); + + AV_WN32A(src+0*stride, v); + AV_WN32A(src+1*stride, v); +@@ -135,7 +55,7 @@ + } + + static void pred4x4_horizontal_vp8_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int lt= src[-1-1*stride]; ++ const unsigned lt = src[-1-1*stride]; + LOAD_LEFT_EDGE + + AV_WN32A(src+0*stride, ((lt + 2*l0 + l1 + 2) >> 2)*0x01010101); +@@ -144,57 +64,9 @@ + AV_WN32A(src+3*stride, ((l2 + 2*l3 + l3 + 2) >> 2)*0x01010101); + } + +-static void pred4x4_down_right_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int lt= src[-1-1*stride]; +- LOAD_TOP_EDGE +- LOAD_LEFT_EDGE +- +- src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; +- src[0+2*stride]= +- src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; +- src[0+1*stride]= +- src[1+2*stride]= +- src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; +- src[0+0*stride]= +- src[1+1*stride]= +- src[2+2*stride]= +- src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; +- src[1+0*stride]= +- src[2+1*stride]= +- src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; +- src[2+0*stride]= +- src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; +- src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; +-} +- +-static void pred4x4_down_left_c(uint8_t *src, const uint8_t *topright, int stride){ +- LOAD_TOP_EDGE +- LOAD_TOP_RIGHT_EDGE +-// LOAD_LEFT_EDGE +- +- src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; +- src[1+0*stride]= +- src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; +- src[2+0*stride]= +- src[1+1*stride]= +- src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; +- src[3+0*stride]= +- src[2+1*stride]= +- src[1+2*stride]= +- src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; +- src[3+1*stride]= +- src[2+2*stride]= +- src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; +- src[3+2*stride]= +- src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; +- src[3+3*stride]=(t6 + 3*t7 + 2)>>2; +-} +- + static void pred4x4_down_left_svq3_c(uint8_t *src, const uint8_t *topright, int stride){ + LOAD_TOP_EDGE + LOAD_LEFT_EDGE +- const av_unused int unu0= t0; +- const av_unused int unu1= l0; + + src[0+0*stride]=(l1 + t1)>>1; + src[1+0*stride]= +@@ -261,53 +133,8 @@ + src[3+3*stride]=(t6 + t7 + 1 + 2*l3 + 1)>>2; + } + +-static void pred4x4_vertical_right_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int lt= src[-1-1*stride]; +- LOAD_TOP_EDGE +- LOAD_LEFT_EDGE +- +- src[0+0*stride]= +- src[1+2*stride]=(lt + t0 + 1)>>1; +- src[1+0*stride]= +- src[2+2*stride]=(t0 + t1 + 1)>>1; +- src[2+0*stride]= +- src[3+2*stride]=(t1 + t2 + 1)>>1; +- src[3+0*stride]=(t2 + t3 + 1)>>1; +- src[0+1*stride]= +- src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; +- src[1+1*stride]= +- src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; +- src[2+1*stride]= +- src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; +- src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; +- src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; +- src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; +-} +- +-static void pred4x4_vertical_left_c(uint8_t *src, const uint8_t *topright, int stride){ +- LOAD_TOP_EDGE +- LOAD_TOP_RIGHT_EDGE +- +- src[0+0*stride]=(t0 + t1 + 1)>>1; +- src[1+0*stride]= +- src[0+2*stride]=(t1 + t2 + 1)>>1; +- src[2+0*stride]= +- src[1+2*stride]=(t2 + t3 + 1)>>1; +- src[3+0*stride]= +- src[2+2*stride]=(t3 + t4+ 1)>>1; +- src[3+2*stride]=(t4 + t5+ 1)>>1; +- src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; +- src[1+1*stride]= +- src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; +- src[2+1*stride]= +- src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; +- src[3+1*stride]= +- src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; +- src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; +-} +- + static void pred4x4_vertical_left_rv40(uint8_t *src, const uint8_t *topright, int stride, +- const int l0, const int l1, const int l2, const int l3, const int l4){ ++ const int l0, const int l1, const int l2, const int l3, const int l4){ + LOAD_TOP_EDGE + LOAD_TOP_RIGHT_EDGE + +@@ -364,27 +191,6 @@ + src[3+3*stride]=(t5 + 2*t6 + t7 + 2)>>2; + } + +-static void pred4x4_horizontal_up_c(uint8_t *src, const uint8_t *topright, int stride){ +- LOAD_LEFT_EDGE +- +- src[0+0*stride]=(l0 + l1 + 1)>>1; +- src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; +- src[2+0*stride]= +- src[0+1*stride]=(l1 + l2 + 1)>>1; +- src[3+0*stride]= +- src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; +- src[2+1*stride]= +- src[0+2*stride]=(l2 + l3 + 1)>>1; +- src[3+1*stride]= +- src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; +- src[3+2*stride]= +- src[1+3*stride]= +- src[0+3*stride]= +- src[2+2*stride]= +- src[2+3*stride]= +- src[3+3*stride]=l3; +-} +- + static void pred4x4_horizontal_up_rv40_c(uint8_t *src, const uint8_t *topright, int stride){ + LOAD_LEFT_EDGE + LOAD_DOWN_LEFT_EDGE +@@ -432,29 +238,6 @@ + src[3+3*stride]=l3; + } + +-static void pred4x4_horizontal_down_c(uint8_t *src, const uint8_t *topright, int stride){ +- const int lt= src[-1-1*stride]; +- LOAD_TOP_EDGE +- LOAD_LEFT_EDGE +- +- src[0+0*stride]= +- src[2+1*stride]=(lt + l0 + 1)>>1; +- src[1+0*stride]= +- src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; +- src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; +- src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; +- src[0+1*stride]= +- src[2+2*stride]=(l0 + l1 + 1)>>1; +- src[1+1*stride]= +- src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; +- src[0+2*stride]= +- src[2+3*stride]=(l1 + l2+ 1)>>1; +- src[1+2*stride]= +- src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; +- src[0+3*stride]=(l2 + l3 + 1)>>1; +- src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; +-} +- + static void pred4x4_tm_vp8_c(uint8_t *src, const uint8_t *topright, int stride){ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP - src[-1-stride]; + uint8_t *top = src-stride; +@@ -470,172 +253,12 @@ + } + } + +-static void pred16x16_vertical_c(uint8_t *src, int stride){ +- int i; +- const uint32_t a= ((uint32_t*)(src-stride))[0]; +- const uint32_t b= ((uint32_t*)(src-stride))[1]; +- const uint32_t c= ((uint32_t*)(src-stride))[2]; +- const uint32_t d= ((uint32_t*)(src-stride))[3]; +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= a; +- ((uint32_t*)(src+i*stride))[1]= b; +- ((uint32_t*)(src+i*stride))[2]= c; +- ((uint32_t*)(src+i*stride))[3]= d; +- } +-} +- +-static void pred16x16_horizontal_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= src[-1+i*stride]*0x01010101; +- } +-} +- +-static void pred16x16_dc_c(uint8_t *src, int stride){ +- int i, dc=0; +- +- for(i=0;i<16; i++){ +- dc+= src[-1+i*stride]; +- } +- +- for(i=0;i<16; i++){ +- dc+= src[i-stride]; +- } +- +- dc= 0x01010101*((dc + 16)>>5); +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= dc; +- } +-} +- +-static void pred16x16_left_dc_c(uint8_t *src, int stride){ +- int i, dc=0; +- +- for(i=0;i<16; i++){ +- dc+= src[-1+i*stride]; +- } +- +- dc= 0x01010101*((dc + 8)>>4); +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= dc; +- } +-} +- +-static void pred16x16_top_dc_c(uint8_t *src, int stride){ +- int i, dc=0; +- +- for(i=0;i<16; i++){ +- dc+= src[i-stride]; +- } +- dc= 0x01010101*((dc + 8)>>4); +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= dc; +- } +-} +- +-static void pred16x16_128_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= 0x01010101U*128U; +- } +-} +- +-static void pred16x16_127_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= 0x01010101U*127U; +- } +-} +- +-static void pred16x16_129_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<16; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= +- ((uint32_t*)(src+i*stride))[2]= +- ((uint32_t*)(src+i*stride))[3]= 0x01010101U*129U; +- } +-} +- +-static inline void pred16x16_plane_compat_c(uint8_t *src, int stride, const int svq3, const int rv40){ +- int i, j, k; +- int a; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- const uint8_t * const src0 = src+7-stride; +- const uint8_t *src1 = src+8*stride-1; +- const uint8_t *src2 = src1-2*stride; // == src+6*stride-1; +- int H = src0[1] - src0[-1]; +- int V = src1[0] - src2[ 0]; +- for(k=2; k<=8; ++k) { +- src1 += stride; src2 -= stride; +- H += k*(src0[k] - src0[-k]); +- V += k*(src1[0] - src2[ 0]); +- } +- if(svq3){ +- H = ( 5*(H/4) ) / 16; +- V = ( 5*(V/4) ) / 16; +- +- /* required for 100% accuracy */ +- i = H; H = V; V = i; +- }else if(rv40){ +- H = ( H + (H>>2) ) >> 4; +- V = ( V + (V>>2) ) >> 4; +- }else{ +- H = ( 5*H+32 ) >> 6; +- V = ( 5*V+32 ) >> 6; +- } +- +- a = 16*(src1[0] + src2[16] + 1) - 7*(V+H); +- for(j=16; j>0; --j) { +- int b = a; +- a += V; +- for(i=-16; i<0; i+=4) { +- src[16+i] = cm[ (b ) >> 5 ]; +- src[17+i] = cm[ (b+ H) >> 5 ]; +- src[18+i] = cm[ (b+2*H) >> 5 ]; +- src[19+i] = cm[ (b+3*H) >> 5 ]; +- b += 4*H; +- } +- src += stride; +- } +-} +- +-static void pred16x16_plane_c(uint8_t *src, int stride){ +- pred16x16_plane_compat_c(src, stride, 0, 0); +-} +- + static void pred16x16_plane_svq3_c(uint8_t *src, int stride){ +- pred16x16_plane_compat_c(src, stride, 1, 0); ++ pred16x16_plane_compat_8_c(src, stride, 1, 0); + } + + static void pred16x16_plane_rv40_c(uint8_t *src, int stride){ +- pred16x16_plane_compat_c(src, stride, 0, 1); ++ pred16x16_plane_compat_8_c(src, stride, 0, 1); + } + + static void pred16x16_tm_vp8_c(uint8_t *src, int stride){ +@@ -665,77 +288,9 @@ + } + } + +-static void pred8x8_vertical_c(uint8_t *src, int stride){ +- int i; +- const uint32_t a= ((uint32_t*)(src-stride))[0]; +- const uint32_t b= ((uint32_t*)(src-stride))[1]; +- +- for(i=0; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= a; +- ((uint32_t*)(src+i*stride))[1]= b; +- } +-} +- +-static void pred8x8_horizontal_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= src[-1+i*stride]*0x01010101; +- } +-} +- +-static void pred8x8_128_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*128U; +- } +-} +- +-static void pred8x8_127_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*127U; +- } +-} +-static void pred8x8_129_dc_c(uint8_t *src, int stride){ +- int i; +- +- for(i=0; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= 0x01010101U*129U; +- } +-} +- +-static void pred8x8_left_dc_c(uint8_t *src, int stride){ +- int i; +- int dc0, dc2; +- +- dc0=dc2=0; +- for(i=0;i<4; i++){ +- dc0+= src[-1+i*stride]; +- dc2+= src[-1+(i+4)*stride]; +- } +- dc0= 0x01010101*((dc0 + 2)>>2); +- dc2= 0x01010101*((dc2 + 2)>>2); +- +- for(i=0; i<4; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= dc0; +- } +- for(i=4; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= +- ((uint32_t*)(src+i*stride))[1]= dc2; +- } +-} +- + static void pred8x8_left_dc_rv40_c(uint8_t *src, int stride){ + int i; +- int dc0; ++ unsigned dc0; + + dc0=0; + for(i=0;i<8; i++) +@@ -748,31 +303,9 @@ + } + } + +-static void pred8x8_top_dc_c(uint8_t *src, int stride){ +- int i; +- int dc0, dc1; +- +- dc0=dc1=0; +- for(i=0;i<4; i++){ +- dc0+= src[i-stride]; +- dc1+= src[4+i-stride]; +- } +- dc0= 0x01010101*((dc0 + 2)>>2); +- dc1= 0x01010101*((dc1 + 2)>>2); +- +- for(i=0; i<4; i++){ +- ((uint32_t*)(src+i*stride))[0]= dc0; +- ((uint32_t*)(src+i*stride))[1]= dc1; +- } +- for(i=4; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= dc0; +- ((uint32_t*)(src+i*stride))[1]= dc1; +- } +-} +- + static void pred8x8_top_dc_rv40_c(uint8_t *src, int stride){ + int i; +- int dc0; ++ unsigned dc0; + + dc0=0; + for(i=0;i<8; i++) +@@ -785,58 +318,9 @@ + } + } + +- +-static void pred8x8_dc_c(uint8_t *src, int stride){ +- int i; +- int dc0, dc1, dc2, dc3; +- +- dc0=dc1=dc2=0; +- for(i=0;i<4; i++){ +- dc0+= src[-1+i*stride] + src[i-stride]; +- dc1+= src[4+i-stride]; +- dc2+= src[-1+(i+4)*stride]; +- } +- dc3= 0x01010101*((dc1 + dc2 + 4)>>3); +- dc0= 0x01010101*((dc0 + 4)>>3); +- dc1= 0x01010101*((dc1 + 2)>>2); +- dc2= 0x01010101*((dc2 + 2)>>2); +- +- for(i=0; i<4; i++){ +- ((uint32_t*)(src+i*stride))[0]= dc0; +- ((uint32_t*)(src+i*stride))[1]= dc1; +- } +- for(i=4; i<8; i++){ +- ((uint32_t*)(src+i*stride))[0]= dc2; +- ((uint32_t*)(src+i*stride))[1]= dc3; +- } +-} +- +-//the following 4 function should not be optimized! +-static void pred8x8_mad_cow_dc_l0t(uint8_t *src, int stride){ +- pred8x8_top_dc_c(src, stride); +- pred4x4_dc_c(src, NULL, stride); +-} +- +-static void pred8x8_mad_cow_dc_0lt(uint8_t *src, int stride){ +- pred8x8_dc_c(src, stride); +- pred4x4_top_dc_c(src, NULL, stride); +-} +- +-static void pred8x8_mad_cow_dc_l00(uint8_t *src, int stride){ +- pred8x8_left_dc_c(src, stride); +- pred4x4_128_dc_c(src + 4*stride , NULL, stride); +- pred4x4_128_dc_c(src + 4*stride + 4, NULL, stride); +-} +- +-static void pred8x8_mad_cow_dc_0l0(uint8_t *src, int stride){ +- pred8x8_left_dc_c(src, stride); +- pred4x4_128_dc_c(src , NULL, stride); +- pred4x4_128_dc_c(src + 4, NULL, stride); +-} +- + static void pred8x8_dc_rv40_c(uint8_t *src, int stride){ + int i; +- int dc0=0; ++ unsigned dc0 = 0; + + for(i=0;i<4; i++){ + dc0+= src[-1+i*stride] + src[i-stride]; +@@ -855,39 +339,6 @@ + } + } + +-static void pred8x8_plane_c(uint8_t *src, int stride){ +- int j, k; +- int a; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- const uint8_t * const src0 = src+3-stride; +- const uint8_t *src1 = src+4*stride-1; +- const uint8_t *src2 = src1-2*stride; // == src+2*stride-1; +- int H = src0[1] - src0[-1]; +- int V = src1[0] - src2[ 0]; +- for(k=2; k<=4; ++k) { +- src1 += stride; src2 -= stride; +- H += k*(src0[k] - src0[-k]); +- V += k*(src1[0] - src2[ 0]); +- } +- H = ( 17*H+16 ) >> 5; +- V = ( 17*V+16 ) >> 5; +- +- a = 16*(src1[0] + src2[8]+1) - 3*(V+H); +- for(j=8; j>0; --j) { +- int b = a; +- a += V; +- src[0] = cm[ (b ) >> 5 ]; +- src[1] = cm[ (b+ H) >> 5 ]; +- src[2] = cm[ (b+2*H) >> 5 ]; +- src[3] = cm[ (b+3*H) >> 5 ]; +- src[4] = cm[ (b+4*H) >> 5 ]; +- src[5] = cm[ (b+5*H) >> 5 ]; +- src[6] = cm[ (b+6*H) >> 5 ]; +- src[7] = cm[ (b+7*H) >> 5 ]; +- src += stride; +- } +-} +- + static void pred8x8_tm_vp8_c(uint8_t *src, int stride){ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP - src[-1-stride]; + uint8_t *top = src-stride; +@@ -907,462 +358,180 @@ + } + } + +-#define SRC(x,y) src[(x)+(y)*stride] +-#define PL(y) \ +- const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2; +-#define PREDICT_8x8_LOAD_LEFT \ +- const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \ +- + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \ +- PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \ +- const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2 +- +-#define PT(x) \ +- const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; +-#define PREDICT_8x8_LOAD_TOP \ +- const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \ +- + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \ +- PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \ +- const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \ +- + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2 +- +-#define PTR(x) \ +- t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; +-#define PREDICT_8x8_LOAD_TOPRIGHT \ +- int t8, t9, t10, t11, t12, t13, t14, t15; \ +- if(has_topright) { \ +- PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \ +- t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \ +- } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1); +- +-#define PREDICT_8x8_LOAD_TOPLEFT \ +- const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2 +- +-#define PREDICT_8x8_DC(v) \ +- int y; \ +- for( y = 0; y < 8; y++ ) { \ +- ((uint32_t*)src)[0] = \ +- ((uint32_t*)src)[1] = v; \ +- src += stride; \ +- } +- +-static void pred8x8l_128_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_DC(0x80808080); +-} +-static void pred8x8l_left_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_LEFT; +- const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3) * 0x01010101; +- PREDICT_8x8_DC(dc); +-} +-static void pred8x8l_top_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- const uint32_t dc = ((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3) * 0x01010101; +- PREDICT_8x8_DC(dc); +-} +-static void pred8x8l_dc_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_LEFT; +- PREDICT_8x8_LOAD_TOP; +- const uint32_t dc = ((l0+l1+l2+l3+l4+l5+l6+l7 +- +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4) * 0x01010101; +- PREDICT_8x8_DC(dc); +-} +-static void pred8x8l_horizontal_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_LEFT; +-#define ROW(y) ((uint32_t*)(src+y*stride))[0] =\ +- ((uint32_t*)(src+y*stride))[1] = 0x01010101 * l##y +- ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7); +-#undef ROW +-} +-static void pred8x8l_vertical_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- int y; +- PREDICT_8x8_LOAD_TOP; +- src[0] = t0; +- src[1] = t1; +- src[2] = t2; +- src[3] = t3; +- src[4] = t4; +- src[5] = t5; +- src[6] = t6; +- src[7] = t7; +- for( y = 1; y < 8; y++ ) +- *(uint64_t*)(src+y*stride) = *(uint64_t*)src; +-} +-static void pred8x8l_down_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- PREDICT_8x8_LOAD_TOPRIGHT; +- SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2; +- SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2; +- SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2; +- SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2; +- SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2; +- SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2; +- SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2; +- SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2; +- SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2; +- SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2; +- SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2; +- SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2; +- SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2; +- SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2; +- SRC(7,7)= (t14 + 3*t15 + 2) >> 2; +-} +-static void pred8x8l_down_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- PREDICT_8x8_LOAD_LEFT; +- PREDICT_8x8_LOAD_TOPLEFT; +- SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2; +- SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2; +- SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2; +- SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2; +- SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2; +- SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2; +- SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2; +- SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2; +- SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2; +- SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2; +- SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2; +- SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2; +- SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2; +- SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2; +- SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2; +- +-} +-static void pred8x8l_vertical_right_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- PREDICT_8x8_LOAD_LEFT; +- PREDICT_8x8_LOAD_TOPLEFT; +- SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2; +- SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2; +- SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2; +- SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2; +- SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2; +- SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2; +- SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2; +- SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1; +- SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2; +- SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1; +- SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2; +- SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1; +- SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2; +- SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1; +- SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2; +- SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1; +- SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2; +- SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1; +- SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2; +- SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1; +- SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2; +- SRC(7,0)= (t6 + t7 + 1) >> 1; +-} +-static void pred8x8l_horizontal_down_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- PREDICT_8x8_LOAD_LEFT; +- PREDICT_8x8_LOAD_TOPLEFT; +- SRC(0,7)= (l6 + l7 + 1) >> 1; +- SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2; +- SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1; +- SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2; +- SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1; +- SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2; +- SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1; +- SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2; +- SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1; +- SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2; +- SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1; +- SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2; +- SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1; +- SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2; +- SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1; +- SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2; +- SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2; +- SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2; +- SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2; +- SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2; +- SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2; +- SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2; +-} +-static void pred8x8l_vertical_left_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_TOP; +- PREDICT_8x8_LOAD_TOPRIGHT; +- SRC(0,0)= (t0 + t1 + 1) >> 1; +- SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2; +- SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1; +- SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2; +- SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1; +- SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2; +- SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1; +- SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2; +- SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1; +- SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2; +- SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1; +- SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2; +- SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1; +- SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2; +- SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1; +- SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2; +- SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1; +- SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2; +- SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1; +- SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2; +- SRC(7,6)= (t10 + t11 + 1) >> 1; +- SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2; +-} +-static void pred8x8l_horizontal_up_c(uint8_t *src, int has_topleft, int has_topright, int stride) +-{ +- PREDICT_8x8_LOAD_LEFT; +- SRC(0,0)= (l0 + l1 + 1) >> 1; +- SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2; +- SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1; +- SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2; +- SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1; +- SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2; +- SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1; +- SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2; +- SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1; +- SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2; +- SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1; +- SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2; +- SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1; +- SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2; +- SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)= +- SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)= +- SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)= +- SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7; +-} +-#undef PREDICT_8x8_LOAD_LEFT +-#undef PREDICT_8x8_LOAD_TOP +-#undef PREDICT_8x8_LOAD_TOPLEFT +-#undef PREDICT_8x8_LOAD_TOPRIGHT +-#undef PREDICT_8x8_DC +-#undef PTR +-#undef PT +-#undef PL +-#undef SRC +- +-static void pred4x4_vertical_add_c(uint8_t *pix, const DCTELEM *block, int stride){ +- int i; +- pix -= stride; +- for(i=0; i<4; i++){ +- uint8_t v = pix[0]; +- pix[1*stride]= v += block[0]; +- pix[2*stride]= v += block[4]; +- pix[3*stride]= v += block[8]; +- pix[4*stride]= v + block[12]; +- pix++; +- block++; +- } +-} +- +-static void pred4x4_horizontal_add_c(uint8_t *pix, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<4; i++){ +- uint8_t v = pix[-1]; +- pix[0]= v += block[0]; +- pix[1]= v += block[1]; +- pix[2]= v += block[2]; +- pix[3]= v + block[3]; +- pix+= stride; +- block+= 4; +- } +-} +- +-static void pred8x8l_vertical_add_c(uint8_t *pix, const DCTELEM *block, int stride){ +- int i; +- pix -= stride; +- for(i=0; i<8; i++){ +- uint8_t v = pix[0]; +- pix[1*stride]= v += block[0]; +- pix[2*stride]= v += block[8]; +- pix[3*stride]= v += block[16]; +- pix[4*stride]= v += block[24]; +- pix[5*stride]= v += block[32]; +- pix[6*stride]= v += block[40]; +- pix[7*stride]= v += block[48]; +- pix[8*stride]= v + block[56]; +- pix++; +- block++; +- } +-} +- +-static void pred8x8l_horizontal_add_c(uint8_t *pix, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<8; i++){ +- uint8_t v = pix[-1]; +- pix[0]= v += block[0]; +- pix[1]= v += block[1]; +- pix[2]= v += block[2]; +- pix[3]= v += block[3]; +- pix[4]= v += block[4]; +- pix[5]= v += block[5]; +- pix[6]= v += block[6]; +- pix[7]= v + block[7]; +- pix+= stride; +- block+= 8; +- } +-} +- +-static void pred16x16_vertical_add_c(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<16; i++) +- pred4x4_vertical_add_c(pix + block_offset[i], block + i*16, stride); +-} +- +-static void pred16x16_horizontal_add_c(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<16; i++) +- pred4x4_horizontal_add_c(pix + block_offset[i], block + i*16, stride); +-} +- +-static void pred8x8_vertical_add_c(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<4; i++) +- pred4x4_vertical_add_c(pix + block_offset[i], block + i*16, stride); +-} +- +-static void pred8x8_horizontal_add_c(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ +- int i; +- for(i=0; i<4; i++) +- pred4x4_horizontal_add_c(pix + block_offset[i], block + i*16, stride); +-} +- +- + /** + * Set the intra prediction function pointers. + */ +-void ff_h264_pred_init(H264PredContext *h, int codec_id){ ++void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc){ + // MpegEncContext * const s = &h->s; + +- if(codec_id != CODEC_ID_RV40){ +- if(codec_id == CODEC_ID_VP8) { +- h->pred4x4[VERT_PRED ]= pred4x4_vertical_vp8_c; +- h->pred4x4[HOR_PRED ]= pred4x4_horizontal_vp8_c; +- } else { +- h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; +- h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; +- } +- h->pred4x4[DC_PRED ]= pred4x4_dc_c; +- if(codec_id == CODEC_ID_SVQ3) +- h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_svq3_c; +- else +- h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_c; +- h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; +- h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; +- h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; +- if (codec_id == CODEC_ID_VP8) { +- h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_vp8_c; +- } else +- h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_c; +- h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_c; +- if(codec_id != CODEC_ID_VP8) { +- h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; +- h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; +- h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; +- } else { +- h->pred4x4[TM_VP8_PRED ]= pred4x4_tm_vp8_c; +- h->pred4x4[DC_127_PRED ]= pred4x4_127_dc_c; +- h->pred4x4[DC_129_PRED ]= pred4x4_129_dc_c; +- h->pred4x4[VERT_VP8_PRED ]= pred4x4_vertical_c; +- h->pred4x4[HOR_VP8_PRED ]= pred4x4_horizontal_c; +- } +- }else{ +- h->pred4x4[VERT_PRED ]= pred4x4_vertical_c; +- h->pred4x4[HOR_PRED ]= pred4x4_horizontal_c; +- h->pred4x4[DC_PRED ]= pred4x4_dc_c; +- h->pred4x4[DIAG_DOWN_LEFT_PRED ]= pred4x4_down_left_rv40_c; +- h->pred4x4[DIAG_DOWN_RIGHT_PRED]= pred4x4_down_right_c; +- h->pred4x4[VERT_RIGHT_PRED ]= pred4x4_vertical_right_c; +- h->pred4x4[HOR_DOWN_PRED ]= pred4x4_horizontal_down_c; +- h->pred4x4[VERT_LEFT_PRED ]= pred4x4_vertical_left_rv40_c; +- h->pred4x4[HOR_UP_PRED ]= pred4x4_horizontal_up_rv40_c; +- h->pred4x4[LEFT_DC_PRED ]= pred4x4_left_dc_c; +- h->pred4x4[TOP_DC_PRED ]= pred4x4_top_dc_c; +- h->pred4x4[DC_128_PRED ]= pred4x4_128_dc_c; +- h->pred4x4[DIAG_DOWN_LEFT_PRED_RV40_NODOWN]= pred4x4_down_left_rv40_nodown_c; +- h->pred4x4[HOR_UP_PRED_RV40_NODOWN]= pred4x4_horizontal_up_rv40_nodown_c; +- h->pred4x4[VERT_LEFT_PRED_RV40_NODOWN]= pred4x4_vertical_left_rv40_nodown_c; +- } +- +- h->pred8x8l[VERT_PRED ]= pred8x8l_vertical_c; +- h->pred8x8l[HOR_PRED ]= pred8x8l_horizontal_c; +- h->pred8x8l[DC_PRED ]= pred8x8l_dc_c; +- h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= pred8x8l_down_left_c; +- h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= pred8x8l_down_right_c; +- h->pred8x8l[VERT_RIGHT_PRED ]= pred8x8l_vertical_right_c; +- h->pred8x8l[HOR_DOWN_PRED ]= pred8x8l_horizontal_down_c; +- h->pred8x8l[VERT_LEFT_PRED ]= pred8x8l_vertical_left_c; +- h->pred8x8l[HOR_UP_PRED ]= pred8x8l_horizontal_up_c; +- h->pred8x8l[LEFT_DC_PRED ]= pred8x8l_left_dc_c; +- h->pred8x8l[TOP_DC_PRED ]= pred8x8l_top_dc_c; +- h->pred8x8l[DC_128_PRED ]= pred8x8l_128_dc_c; +- +- h->pred8x8[VERT_PRED8x8 ]= pred8x8_vertical_c; +- h->pred8x8[HOR_PRED8x8 ]= pred8x8_horizontal_c; +- if (codec_id != CODEC_ID_VP8) { +- h->pred8x8[PLANE_PRED8x8]= pred8x8_plane_c; +- } else +- h->pred8x8[PLANE_PRED8x8]= pred8x8_tm_vp8_c; +- if(codec_id != CODEC_ID_RV40 && codec_id != CODEC_ID_VP8){ +- h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_c; +- h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_c; +- h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_c; +- h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= pred8x8_mad_cow_dc_l0t; +- h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= pred8x8_mad_cow_dc_0lt; +- h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= pred8x8_mad_cow_dc_l00; +- h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= pred8x8_mad_cow_dc_0l0; +- }else{ +- h->pred8x8[DC_PRED8x8 ]= pred8x8_dc_rv40_c; +- h->pred8x8[LEFT_DC_PRED8x8]= pred8x8_left_dc_rv40_c; +- h->pred8x8[TOP_DC_PRED8x8 ]= pred8x8_top_dc_rv40_c; +- if (codec_id == CODEC_ID_VP8) { +- h->pred8x8[DC_127_PRED8x8]= pred8x8_127_dc_c; +- h->pred8x8[DC_129_PRED8x8]= pred8x8_129_dc_c; +- } +- } +- h->pred8x8[DC_128_PRED8x8 ]= pred8x8_128_dc_c; +- +- h->pred16x16[DC_PRED8x8 ]= pred16x16_dc_c; +- h->pred16x16[VERT_PRED8x8 ]= pred16x16_vertical_c; +- h->pred16x16[HOR_PRED8x8 ]= pred16x16_horizontal_c; +- switch(codec_id){ +- case CODEC_ID_SVQ3: +- h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_svq3_c; +- break; +- case CODEC_ID_RV40: +- h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_rv40_c; +- break; +- case CODEC_ID_VP8: +- h->pred16x16[PLANE_PRED8x8 ]= pred16x16_tm_vp8_c; +- h->pred16x16[DC_127_PRED8x8]= pred16x16_127_dc_c; +- h->pred16x16[DC_129_PRED8x8]= pred16x16_129_dc_c; +- break; +- default: +- h->pred16x16[PLANE_PRED8x8 ]= pred16x16_plane_c; +- break; ++#undef FUNC ++#undef FUNCC ++#define FUNC(a, depth) a ## _ ## depth ++#define FUNCC(a, depth) a ## _ ## depth ## _c ++#define FUNCD(a) a ## _c ++ ++#define H264_PRED(depth) \ ++ if(codec_id != CODEC_ID_RV40){\ ++ if(codec_id == CODEC_ID_VP8) {\ ++ h->pred4x4[VERT_PRED ]= FUNCD(pred4x4_vertical_vp8);\ ++ h->pred4x4[HOR_PRED ]= FUNCD(pred4x4_horizontal_vp8);\ ++ } else {\ ++ h->pred4x4[VERT_PRED ]= FUNCC(pred4x4_vertical , depth);\ ++ h->pred4x4[HOR_PRED ]= FUNCC(pred4x4_horizontal , depth);\ ++ }\ ++ h->pred4x4[DC_PRED ]= FUNCC(pred4x4_dc , depth);\ ++ if(codec_id == CODEC_ID_SVQ3)\ ++ h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_svq3);\ ++ else\ ++ h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred4x4_down_left , depth);\ ++ h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right , depth);\ ++ h->pred4x4[VERT_RIGHT_PRED ]= FUNCC(pred4x4_vertical_right , depth);\ ++ h->pred4x4[HOR_DOWN_PRED ]= FUNCC(pred4x4_horizontal_down , depth);\ ++ if (codec_id == CODEC_ID_VP8) {\ ++ h->pred4x4[VERT_LEFT_PRED ]= FUNCD(pred4x4_vertical_left_vp8);\ ++ } else\ ++ h->pred4x4[VERT_LEFT_PRED ]= FUNCC(pred4x4_vertical_left , depth);\ ++ h->pred4x4[HOR_UP_PRED ]= FUNCC(pred4x4_horizontal_up , depth);\ ++ if(codec_id != CODEC_ID_VP8) {\ ++ h->pred4x4[LEFT_DC_PRED ]= FUNCC(pred4x4_left_dc , depth);\ ++ h->pred4x4[TOP_DC_PRED ]= FUNCC(pred4x4_top_dc , depth);\ ++ h->pred4x4[DC_128_PRED ]= FUNCC(pred4x4_128_dc , depth);\ ++ } else {\ ++ h->pred4x4[TM_VP8_PRED ]= FUNCD(pred4x4_tm_vp8);\ ++ h->pred4x4[DC_127_PRED ]= FUNCC(pred4x4_127_dc , depth);\ ++ h->pred4x4[DC_129_PRED ]= FUNCC(pred4x4_129_dc , depth);\ ++ h->pred4x4[VERT_VP8_PRED ]= FUNCC(pred4x4_vertical , depth);\ ++ h->pred4x4[HOR_VP8_PRED ]= FUNCC(pred4x4_horizontal , depth);\ ++ }\ ++ }else{\ ++ h->pred4x4[VERT_PRED ]= FUNCC(pred4x4_vertical , depth);\ ++ h->pred4x4[HOR_PRED ]= FUNCC(pred4x4_horizontal , depth);\ ++ h->pred4x4[DC_PRED ]= FUNCC(pred4x4_dc , depth);\ ++ h->pred4x4[DIAG_DOWN_LEFT_PRED ]= FUNCD(pred4x4_down_left_rv40);\ ++ h->pred4x4[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred4x4_down_right , depth);\ ++ h->pred4x4[VERT_RIGHT_PRED ]= FUNCC(pred4x4_vertical_right , depth);\ ++ h->pred4x4[HOR_DOWN_PRED ]= FUNCC(pred4x4_horizontal_down , depth);\ ++ h->pred4x4[VERT_LEFT_PRED ]= FUNCD(pred4x4_vertical_left_rv40);\ ++ h->pred4x4[HOR_UP_PRED ]= FUNCD(pred4x4_horizontal_up_rv40);\ ++ h->pred4x4[LEFT_DC_PRED ]= FUNCC(pred4x4_left_dc , depth);\ ++ h->pred4x4[TOP_DC_PRED ]= FUNCC(pred4x4_top_dc , depth);\ ++ h->pred4x4[DC_128_PRED ]= FUNCC(pred4x4_128_dc , depth);\ ++ h->pred4x4[DIAG_DOWN_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_down_left_rv40_nodown);\ ++ h->pred4x4[HOR_UP_PRED_RV40_NODOWN]= FUNCD(pred4x4_horizontal_up_rv40_nodown);\ ++ h->pred4x4[VERT_LEFT_PRED_RV40_NODOWN]= FUNCD(pred4x4_vertical_left_rv40_nodown);\ ++ }\ ++\ ++ h->pred8x8l[VERT_PRED ]= FUNCC(pred8x8l_vertical , depth);\ ++ h->pred8x8l[HOR_PRED ]= FUNCC(pred8x8l_horizontal , depth);\ ++ h->pred8x8l[DC_PRED ]= FUNCC(pred8x8l_dc , depth);\ ++ h->pred8x8l[DIAG_DOWN_LEFT_PRED ]= FUNCC(pred8x8l_down_left , depth);\ ++ h->pred8x8l[DIAG_DOWN_RIGHT_PRED]= FUNCC(pred8x8l_down_right , depth);\ ++ h->pred8x8l[VERT_RIGHT_PRED ]= FUNCC(pred8x8l_vertical_right , depth);\ ++ h->pred8x8l[HOR_DOWN_PRED ]= FUNCC(pred8x8l_horizontal_down , depth);\ ++ h->pred8x8l[VERT_LEFT_PRED ]= FUNCC(pred8x8l_vertical_left , depth);\ ++ h->pred8x8l[HOR_UP_PRED ]= FUNCC(pred8x8l_horizontal_up , depth);\ ++ h->pred8x8l[LEFT_DC_PRED ]= FUNCC(pred8x8l_left_dc , depth);\ ++ h->pred8x8l[TOP_DC_PRED ]= FUNCC(pred8x8l_top_dc , depth);\ ++ h->pred8x8l[DC_128_PRED ]= FUNCC(pred8x8l_128_dc , depth);\ ++\ ++ if (chroma_format_idc == 1) {\ ++ h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x8_vertical , depth);\ ++ h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x8_horizontal , depth);\ ++ } else {\ ++ h->pred8x8[VERT_PRED8x8 ]= FUNCC(pred8x16_vertical , depth);\ ++ h->pred8x8[HOR_PRED8x8 ]= FUNCC(pred8x16_horizontal , depth);\ ++ }\ ++ if (codec_id != CODEC_ID_VP8) {\ ++ if (chroma_format_idc == 1) {\ ++ h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x8_plane , depth);\ ++ } else {\ ++ h->pred8x8[PLANE_PRED8x8]= FUNCC(pred8x16_plane , depth);\ ++ }\ ++ } else\ ++ h->pred8x8[PLANE_PRED8x8]= FUNCD(pred8x8_tm_vp8);\ ++ if(codec_id != CODEC_ID_RV40 && codec_id != CODEC_ID_VP8){\ ++ if (chroma_format_idc == 1) {\ ++ h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x8_dc , depth);\ ++ h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x8_left_dc , depth);\ ++ h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x8_top_dc , depth);\ ++ h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l0t, depth);\ ++ h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0lt, depth);\ ++ h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_l00, depth);\ ++ h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x8_mad_cow_dc_0l0, depth);\ ++ } else {\ ++ h->pred8x8[DC_PRED8x8 ]= FUNCC(pred8x16_dc , depth);\ ++ h->pred8x8[LEFT_DC_PRED8x8]= FUNCC(pred8x16_left_dc , depth);\ ++ h->pred8x8[TOP_DC_PRED8x8 ]= FUNCC(pred8x16_top_dc , depth);\ ++ h->pred8x8[ALZHEIMER_DC_L0T_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l0t, depth);\ ++ h->pred8x8[ALZHEIMER_DC_0LT_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0lt, depth);\ ++ h->pred8x8[ALZHEIMER_DC_L00_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_l00, depth);\ ++ h->pred8x8[ALZHEIMER_DC_0L0_PRED8x8 ]= FUNC(pred8x16_mad_cow_dc_0l0, depth);\ ++ }\ ++ }else{\ ++ h->pred8x8[DC_PRED8x8 ]= FUNCD(pred8x8_dc_rv40);\ ++ h->pred8x8[LEFT_DC_PRED8x8]= FUNCD(pred8x8_left_dc_rv40);\ ++ h->pred8x8[TOP_DC_PRED8x8 ]= FUNCD(pred8x8_top_dc_rv40);\ ++ if (codec_id == CODEC_ID_VP8) {\ ++ h->pred8x8[DC_127_PRED8x8]= FUNCC(pred8x8_127_dc , depth);\ ++ h->pred8x8[DC_129_PRED8x8]= FUNCC(pred8x8_129_dc , depth);\ ++ }\ ++ }\ ++ if (chroma_format_idc == 1) {\ ++ h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x8_128_dc , depth);\ ++ } else {\ ++ h->pred8x8[DC_128_PRED8x8 ]= FUNCC(pred8x16_128_dc , depth);\ ++ }\ ++\ ++ h->pred16x16[DC_PRED8x8 ]= FUNCC(pred16x16_dc , depth);\ ++ h->pred16x16[VERT_PRED8x8 ]= FUNCC(pred16x16_vertical , depth);\ ++ h->pred16x16[HOR_PRED8x8 ]= FUNCC(pred16x16_horizontal , depth);\ ++ switch(codec_id){\ ++ case CODEC_ID_SVQ3:\ ++ h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_plane_svq3);\ ++ break;\ ++ case CODEC_ID_RV40:\ ++ h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_plane_rv40);\ ++ break;\ ++ case CODEC_ID_VP8:\ ++ h->pred16x16[PLANE_PRED8x8 ]= FUNCD(pred16x16_tm_vp8);\ ++ h->pred16x16[DC_127_PRED8x8]= FUNCC(pred16x16_127_dc , depth);\ ++ h->pred16x16[DC_129_PRED8x8]= FUNCC(pred16x16_129_dc , depth);\ ++ break;\ ++ default:\ ++ h->pred16x16[PLANE_PRED8x8 ]= FUNCC(pred16x16_plane , depth);\ ++ break;\ ++ }\ ++ h->pred16x16[LEFT_DC_PRED8x8]= FUNCC(pred16x16_left_dc , depth);\ ++ h->pred16x16[TOP_DC_PRED8x8 ]= FUNCC(pred16x16_top_dc , depth);\ ++ h->pred16x16[DC_128_PRED8x8 ]= FUNCC(pred16x16_128_dc , depth);\ ++\ ++ /* special lossless h/v prediction for h264 */ \ ++ h->pred4x4_add [VERT_PRED ]= FUNCC(pred4x4_vertical_add , depth);\ ++ h->pred4x4_add [ HOR_PRED ]= FUNCC(pred4x4_horizontal_add , depth);\ ++ h->pred8x8l_add [VERT_PRED ]= FUNCC(pred8x8l_vertical_add , depth);\ ++ h->pred8x8l_add [ HOR_PRED ]= FUNCC(pred8x8l_horizontal_add , depth);\ ++ if (chroma_format_idc == 1) {\ ++ h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x8_vertical_add , depth);\ ++ h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x8_horizontal_add , depth);\ ++ } else {\ ++ h->pred8x8_add [VERT_PRED8x8]= FUNCC(pred8x16_vertical_add , depth);\ ++ h->pred8x8_add [ HOR_PRED8x8]= FUNCC(pred8x16_horizontal_add , depth);\ ++ }\ ++ h->pred16x16_add[VERT_PRED8x8]= FUNCC(pred16x16_vertical_add , depth);\ ++ h->pred16x16_add[ HOR_PRED8x8]= FUNCC(pred16x16_horizontal_add , depth);\ ++ ++ switch (bit_depth) { ++ case 9: ++ H264_PRED(9) ++ break; ++ case 10: ++ H264_PRED(10) ++ break; ++ default: ++ H264_PRED(8) ++ break; + } +- h->pred16x16[LEFT_DC_PRED8x8]= pred16x16_left_dc_c; +- h->pred16x16[TOP_DC_PRED8x8 ]= pred16x16_top_dc_c; +- h->pred16x16[DC_128_PRED8x8 ]= pred16x16_128_dc_c; +- +- //special lossless h/v prediction for h264 +- h->pred4x4_add [VERT_PRED ]= pred4x4_vertical_add_c; +- h->pred4x4_add [ HOR_PRED ]= pred4x4_horizontal_add_c; +- h->pred8x8l_add [VERT_PRED ]= pred8x8l_vertical_add_c; +- h->pred8x8l_add [ HOR_PRED ]= pred8x8l_horizontal_add_c; +- h->pred8x8_add [VERT_PRED8x8]= pred8x8_vertical_add_c; +- h->pred8x8_add [ HOR_PRED8x8]= pred8x8_horizontal_add_c; +- h->pred16x16_add[VERT_PRED8x8]= pred16x16_vertical_add_c; +- h->pred16x16_add[ HOR_PRED8x8]= pred16x16_horizontal_add_c; + +- if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id); +- if (HAVE_MMX) ff_h264_pred_init_x86(h, codec_id); ++ if (ARCH_ARM) ff_h264_pred_init_arm(h, codec_id, bit_depth, chroma_format_idc); ++ if (HAVE_MMX) ff_h264_pred_init_x86(h, codec_id, bit_depth, chroma_format_idc); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred.h 2012-05-14 14:08:53.831329858 +0200 +@@ -101,8 +101,8 @@ + void (*pred16x16_add[3])(uint8_t *pix/*align 16*/, const int *block_offset, const DCTELEM *block/*align 16*/, int stride); + }H264PredContext; + +-void ff_h264_pred_init(H264PredContext *h, int codec_id); +-void ff_h264_pred_init_arm(H264PredContext *h, int codec_id); +-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id); ++void ff_h264_pred_init(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc); ++void ff_h264_pred_init_arm(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc); ++void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc); + + #endif /* AVCODEC_H264PRED_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264pred_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264pred_template.c 2012-05-14 14:08:53.834329918 +0200 +@@ -0,0 +1,1171 @@ ++/* ++ * H.26L/H.264/AVC/JVT/14496-10/... encoder/decoder ++ * Copyright (c) 2003-2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * H.264 / AVC / MPEG4 part10 prediction functions. ++ * @author Michael Niedermayer ++ */ ++ ++#include "mathops.h" ++ ++#include "bit_depth_template.c" ++ ++static void FUNCC(pred4x4_vertical)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a= AV_RN4PA(src-stride); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_horizontal)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ AV_WN4PA(src+0*stride, PIXEL_SPLAT_X4(src[-1+0*stride])); ++ AV_WN4PA(src+1*stride, PIXEL_SPLAT_X4(src[-1+1*stride])); ++ AV_WN4PA(src+2*stride, PIXEL_SPLAT_X4(src[-1+2*stride])); ++ AV_WN4PA(src+3*stride, PIXEL_SPLAT_X4(src[-1+3*stride])); ++} ++ ++static void FUNCC(pred4x4_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] ++ + src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 4) >>3; ++ const pixel4 a = PIXEL_SPLAT_X4(dc); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_left_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int dc= ( src[-1+0*stride] + src[-1+1*stride] + src[-1+2*stride] + src[-1+3*stride] + 2) >>2; ++ const pixel4 a = PIXEL_SPLAT_X4(dc); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_top_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int dc= ( src[-stride] + src[1-stride] + src[2-stride] + src[3-stride] + 2) >>2; ++ const pixel4 a = PIXEL_SPLAT_X4(dc); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_128_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a = PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1)); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_127_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))-1); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++static void FUNCC(pred4x4_129_dc)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a = PIXEL_SPLAT_X4((1<<(BIT_DEPTH-1))+1); ++ ++ AV_WN4PA(src+0*stride, a); ++ AV_WN4PA(src+1*stride, a); ++ AV_WN4PA(src+2*stride, a); ++ AV_WN4PA(src+3*stride, a); ++} ++ ++ ++#define LOAD_TOP_RIGHT_EDGE\ ++ const unsigned av_unused t4 = topright[0];\ ++ const unsigned av_unused t5 = topright[1];\ ++ const unsigned av_unused t6 = topright[2];\ ++ const unsigned av_unused t7 = topright[3];\ ++ ++#define LOAD_DOWN_LEFT_EDGE\ ++ const unsigned av_unused l4 = src[-1+4*stride];\ ++ const unsigned av_unused l5 = src[-1+5*stride];\ ++ const unsigned av_unused l6 = src[-1+6*stride];\ ++ const unsigned av_unused l7 = src[-1+7*stride];\ ++ ++#define LOAD_LEFT_EDGE\ ++ const unsigned av_unused l0 = src[-1+0*stride];\ ++ const unsigned av_unused l1 = src[-1+1*stride];\ ++ const unsigned av_unused l2 = src[-1+2*stride];\ ++ const unsigned av_unused l3 = src[-1+3*stride];\ ++ ++#define LOAD_TOP_EDGE\ ++ const unsigned av_unused t0 = src[ 0-1*stride];\ ++ const unsigned av_unused t1 = src[ 1-1*stride];\ ++ const unsigned av_unused t2 = src[ 2-1*stride];\ ++ const unsigned av_unused t3 = src[ 3-1*stride];\ ++ ++static void FUNCC(pred4x4_down_right)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int lt= src[-1-1*stride]; ++ LOAD_TOP_EDGE ++ LOAD_LEFT_EDGE ++ ++ src[0+3*stride]=(l3 + 2*l2 + l1 + 2)>>2; ++ src[0+2*stride]= ++ src[1+3*stride]=(l2 + 2*l1 + l0 + 2)>>2; ++ src[0+1*stride]= ++ src[1+2*stride]= ++ src[2+3*stride]=(l1 + 2*l0 + lt + 2)>>2; ++ src[0+0*stride]= ++ src[1+1*stride]= ++ src[2+2*stride]= ++ src[3+3*stride]=(l0 + 2*lt + t0 + 2)>>2; ++ src[1+0*stride]= ++ src[2+1*stride]= ++ src[3+2*stride]=(lt + 2*t0 + t1 + 2)>>2; ++ src[2+0*stride]= ++ src[3+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; ++ src[3+0*stride]=(t1 + 2*t2 + t3 + 2)>>2; ++} ++ ++static void FUNCC(pred4x4_down_left)(uint8_t *_src, const uint8_t *_topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ const pixel *topright = (const pixel*)_topright; ++ int stride = _stride>>(sizeof(pixel)-1); ++ LOAD_TOP_EDGE ++ LOAD_TOP_RIGHT_EDGE ++// LOAD_LEFT_EDGE ++ ++ src[0+0*stride]=(t0 + t2 + 2*t1 + 2)>>2; ++ src[1+0*stride]= ++ src[0+1*stride]=(t1 + t3 + 2*t2 + 2)>>2; ++ src[2+0*stride]= ++ src[1+1*stride]= ++ src[0+2*stride]=(t2 + t4 + 2*t3 + 2)>>2; ++ src[3+0*stride]= ++ src[2+1*stride]= ++ src[1+2*stride]= ++ src[0+3*stride]=(t3 + t5 + 2*t4 + 2)>>2; ++ src[3+1*stride]= ++ src[2+2*stride]= ++ src[1+3*stride]=(t4 + t6 + 2*t5 + 2)>>2; ++ src[3+2*stride]= ++ src[2+3*stride]=(t5 + t7 + 2*t6 + 2)>>2; ++ src[3+3*stride]=(t6 + 3*t7 + 2)>>2; ++} ++ ++static void FUNCC(pred4x4_vertical_right)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int lt= src[-1-1*stride]; ++ LOAD_TOP_EDGE ++ LOAD_LEFT_EDGE ++ ++ src[0+0*stride]= ++ src[1+2*stride]=(lt + t0 + 1)>>1; ++ src[1+0*stride]= ++ src[2+2*stride]=(t0 + t1 + 1)>>1; ++ src[2+0*stride]= ++ src[3+2*stride]=(t1 + t2 + 1)>>1; ++ src[3+0*stride]=(t2 + t3 + 1)>>1; ++ src[0+1*stride]= ++ src[1+3*stride]=(l0 + 2*lt + t0 + 2)>>2; ++ src[1+1*stride]= ++ src[2+3*stride]=(lt + 2*t0 + t1 + 2)>>2; ++ src[2+1*stride]= ++ src[3+3*stride]=(t0 + 2*t1 + t2 + 2)>>2; ++ src[3+1*stride]=(t1 + 2*t2 + t3 + 2)>>2; ++ src[0+2*stride]=(lt + 2*l0 + l1 + 2)>>2; ++ src[0+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; ++} ++ ++static void FUNCC(pred4x4_vertical_left)(uint8_t *_src, const uint8_t *_topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ const pixel *topright = (const pixel*)_topright; ++ int stride = _stride>>(sizeof(pixel)-1); ++ LOAD_TOP_EDGE ++ LOAD_TOP_RIGHT_EDGE ++ ++ src[0+0*stride]=(t0 + t1 + 1)>>1; ++ src[1+0*stride]= ++ src[0+2*stride]=(t1 + t2 + 1)>>1; ++ src[2+0*stride]= ++ src[1+2*stride]=(t2 + t3 + 1)>>1; ++ src[3+0*stride]= ++ src[2+2*stride]=(t3 + t4+ 1)>>1; ++ src[3+2*stride]=(t4 + t5+ 1)>>1; ++ src[0+1*stride]=(t0 + 2*t1 + t2 + 2)>>2; ++ src[1+1*stride]= ++ src[0+3*stride]=(t1 + 2*t2 + t3 + 2)>>2; ++ src[2+1*stride]= ++ src[1+3*stride]=(t2 + 2*t3 + t4 + 2)>>2; ++ src[3+1*stride]= ++ src[2+3*stride]=(t3 + 2*t4 + t5 + 2)>>2; ++ src[3+3*stride]=(t4 + 2*t5 + t6 + 2)>>2; ++} ++ ++static void FUNCC(pred4x4_horizontal_up)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ LOAD_LEFT_EDGE ++ ++ src[0+0*stride]=(l0 + l1 + 1)>>1; ++ src[1+0*stride]=(l0 + 2*l1 + l2 + 2)>>2; ++ src[2+0*stride]= ++ src[0+1*stride]=(l1 + l2 + 1)>>1; ++ src[3+0*stride]= ++ src[1+1*stride]=(l1 + 2*l2 + l3 + 2)>>2; ++ src[2+1*stride]= ++ src[0+2*stride]=(l2 + l3 + 1)>>1; ++ src[3+1*stride]= ++ src[1+2*stride]=(l2 + 2*l3 + l3 + 2)>>2; ++ src[3+2*stride]= ++ src[1+3*stride]= ++ src[0+3*stride]= ++ src[2+2*stride]= ++ src[2+3*stride]= ++ src[3+3*stride]=l3; ++} ++ ++static void FUNCC(pred4x4_horizontal_down)(uint8_t *_src, const uint8_t *topright, int _stride){ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const int lt= src[-1-1*stride]; ++ LOAD_TOP_EDGE ++ LOAD_LEFT_EDGE ++ ++ src[0+0*stride]= ++ src[2+1*stride]=(lt + l0 + 1)>>1; ++ src[1+0*stride]= ++ src[3+1*stride]=(l0 + 2*lt + t0 + 2)>>2; ++ src[2+0*stride]=(lt + 2*t0 + t1 + 2)>>2; ++ src[3+0*stride]=(t0 + 2*t1 + t2 + 2)>>2; ++ src[0+1*stride]= ++ src[2+2*stride]=(l0 + l1 + 1)>>1; ++ src[1+1*stride]= ++ src[3+2*stride]=(lt + 2*l0 + l1 + 2)>>2; ++ src[0+2*stride]= ++ src[2+3*stride]=(l1 + l2+ 1)>>1; ++ src[1+2*stride]= ++ src[3+3*stride]=(l0 + 2*l1 + l2 + 2)>>2; ++ src[0+3*stride]=(l2 + l3 + 1)>>1; ++ src[1+3*stride]=(l1 + 2*l2 + l3 + 2)>>2; ++} ++ ++static void FUNCC(pred16x16_vertical)(uint8_t *_src, int _stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a = AV_RN4PA(((pixel4*)(src-stride))+0); ++ const pixel4 b = AV_RN4PA(((pixel4*)(src-stride))+1); ++ const pixel4 c = AV_RN4PA(((pixel4*)(src-stride))+2); ++ const pixel4 d = AV_RN4PA(((pixel4*)(src-stride))+3); ++ ++ for(i=0; i<16; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, b); ++ AV_WN4PA(((pixel4*)(src+i*stride))+2, c); ++ AV_WN4PA(((pixel4*)(src+i*stride))+3, d); ++ } ++} ++ ++static void FUNCC(pred16x16_horizontal)(uint8_t *_src, int stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ for(i=0; i<16; i++){ ++ const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]); ++ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+2, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+3, a); ++ } ++} ++ ++#define PREDICT_16x16_DC(v)\ ++ for(i=0; i<16; i++){\ ++ AV_WN4PA(src+ 0, v);\ ++ AV_WN4PA(src+ 4, v);\ ++ AV_WN4PA(src+ 8, v);\ ++ AV_WN4PA(src+12, v);\ ++ src += stride;\ ++ } ++ ++static void FUNCC(pred16x16_dc)(uint8_t *_src, int stride){ ++ int i, dc=0; ++ pixel *src = (pixel*)_src; ++ pixel4 dcsplat; ++ stride >>= sizeof(pixel)-1; ++ ++ for(i=0;i<16; i++){ ++ dc+= src[-1+i*stride]; ++ } ++ ++ for(i=0;i<16; i++){ ++ dc+= src[i-stride]; ++ } ++ ++ dcsplat = PIXEL_SPLAT_X4((dc+16)>>5); ++ PREDICT_16x16_DC(dcsplat); ++} ++ ++static void FUNCC(pred16x16_left_dc)(uint8_t *_src, int stride){ ++ int i, dc=0; ++ pixel *src = (pixel*)_src; ++ pixel4 dcsplat; ++ stride >>= sizeof(pixel)-1; ++ ++ for(i=0;i<16; i++){ ++ dc+= src[-1+i*stride]; ++ } ++ ++ dcsplat = PIXEL_SPLAT_X4((dc+8)>>4); ++ PREDICT_16x16_DC(dcsplat); ++} ++ ++static void FUNCC(pred16x16_top_dc)(uint8_t *_src, int stride){ ++ int i, dc=0; ++ pixel *src = (pixel*)_src; ++ pixel4 dcsplat; ++ stride >>= sizeof(pixel)-1; ++ ++ for(i=0;i<16; i++){ ++ dc+= src[i-stride]; ++ } ++ ++ dcsplat = PIXEL_SPLAT_X4((dc+8)>>4); ++ PREDICT_16x16_DC(dcsplat); ++} ++ ++#define PRED16x16_X(n, v) \ ++static void FUNCC(pred16x16_##n##_dc)(uint8_t *_src, int stride){\ ++ int i;\ ++ pixel *src = (pixel*)_src;\ ++ stride >>= sizeof(pixel)-1;\ ++ PREDICT_16x16_DC(PIXEL_SPLAT_X4(v));\ ++} ++ ++PRED16x16_X(127, (1<<(BIT_DEPTH-1))-1) ++PRED16x16_X(128, (1<<(BIT_DEPTH-1))+0) ++PRED16x16_X(129, (1<<(BIT_DEPTH-1))+1) ++ ++static inline void FUNCC(pred16x16_plane_compat)(uint8_t *p_src, int p_stride, const int svq3, const int rv40){ ++ int i, j, k; ++ int a; ++ INIT_CLIP ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ const pixel * const src0 = src +7-stride; ++ const pixel * src1 = src +8*stride-1; ++ const pixel * src2 = src1-2*stride; // == src+6*stride-1; ++ int H = src0[1] - src0[-1]; ++ int V = src1[0] - src2[ 0]; ++ for(k=2; k<=8; ++k) { ++ src1 += stride; src2 -= stride; ++ H += k*(src0[k] - src0[-k]); ++ V += k*(src1[0] - src2[ 0]); ++ } ++ if(svq3){ ++ H = ( 5*(H/4) ) / 16; ++ V = ( 5*(V/4) ) / 16; ++ ++ /* required for 100% accuracy */ ++ i = H; H = V; V = i; ++ }else if(rv40){ ++ H = ( H + (H>>2) ) >> 4; ++ V = ( V + (V>>2) ) >> 4; ++ }else{ ++ H = ( 5*H+32 ) >> 6; ++ V = ( 5*V+32 ) >> 6; ++ } ++ ++ a = 16*(src1[0] + src2[16] + 1) - 7*(V+H); ++ for(j=16; j>0; --j) { ++ int b = a; ++ a += V; ++ for(i=-16; i<0; i+=4) { ++ src[16+i] = CLIP((b ) >> 5); ++ src[17+i] = CLIP((b+ H) >> 5); ++ src[18+i] = CLIP((b+2*H) >> 5); ++ src[19+i] = CLIP((b+3*H) >> 5); ++ b += 4*H; ++ } ++ src += stride; ++ } ++} ++ ++static void FUNCC(pred16x16_plane)(uint8_t *src, int stride){ ++ FUNCC(pred16x16_plane_compat)(src, stride, 0, 0); ++} ++ ++static void FUNCC(pred8x8_vertical)(uint8_t *_src, int _stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0); ++ const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1); ++ ++ for(i=0; i<8; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, b); ++ } ++} ++ ++static void FUNCC(pred8x16_vertical)(uint8_t *_src, int _stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel4 a= AV_RN4PA(((pixel4*)(src-stride))+0); ++ const pixel4 b= AV_RN4PA(((pixel4*)(src-stride))+1); ++ ++ for(i=0; i<16; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, b); ++ } ++} ++ ++static void FUNCC(pred8x8_horizontal)(uint8_t *_src, int stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ for(i=0; i<8; i++){ ++ const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]); ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, a); ++ } ++} ++ ++static void FUNCC(pred8x16_horizontal)(uint8_t *_src, int stride){ ++ int i; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ for(i=0; i<16; i++){ ++ const pixel4 a = PIXEL_SPLAT_X4(src[-1+i*stride]); ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, a); ++ } ++} ++ ++#define PRED8x8_X(n, v)\ ++static void FUNCC(pred8x8_##n##_dc)(uint8_t *_src, int stride){\ ++ int i;\ ++ const pixel4 a = PIXEL_SPLAT_X4(v);\ ++ pixel *src = (pixel*)_src;\ ++ stride >>= sizeof(pixel)-1;\ ++ for(i=0; i<8; i++){\ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, a);\ ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, a);\ ++ }\ ++} ++ ++PRED8x8_X(127, (1<<(BIT_DEPTH-1))-1) ++PRED8x8_X(128, (1<<(BIT_DEPTH-1))+0) ++PRED8x8_X(129, (1<<(BIT_DEPTH-1))+1) ++ ++static void FUNCC(pred8x16_128_dc)(uint8_t *_src, int stride){ ++ FUNCC(pred8x8_128_dc)(_src, stride); ++ FUNCC(pred8x8_128_dc)(_src+8*stride, stride); ++} ++ ++static void FUNCC(pred8x8_left_dc)(uint8_t *_src, int stride){ ++ int i; ++ int dc0, dc2; ++ pixel4 dc0splat, dc2splat; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ dc0=dc2=0; ++ for(i=0;i<4; i++){ ++ dc0+= src[-1+i*stride]; ++ dc2+= src[-1+(i+4)*stride]; ++ } ++ dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2); ++ dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2); ++ ++ for(i=0; i<4; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc0splat); ++ } ++ for(i=4; i<8; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc2splat); ++ } ++} ++ ++static void FUNCC(pred8x16_left_dc)(uint8_t *_src, int stride){ ++ FUNCC(pred8x8_left_dc)(_src, stride); ++ FUNCC(pred8x8_left_dc)(_src+8*stride, stride); ++} ++ ++static void FUNCC(pred8x8_top_dc)(uint8_t *_src, int stride){ ++ int i; ++ int dc0, dc1; ++ pixel4 dc0splat, dc1splat; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ dc0=dc1=0; ++ for(i=0;i<4; i++){ ++ dc0+= src[i-stride]; ++ dc1+= src[4+i-stride]; ++ } ++ dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2); ++ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2); ++ ++ for(i=0; i<4; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat); ++ } ++ for(i=4; i<8; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat); ++ } ++} ++ ++static void FUNCC(pred8x16_top_dc)(uint8_t *_src, int stride){ ++ int i; ++ int dc0, dc1; ++ pixel4 dc0splat, dc1splat; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ dc0=dc1=0; ++ for(i=0;i<4; i++){ ++ dc0+= src[i-stride]; ++ dc1+= src[4+i-stride]; ++ } ++ dc0splat = PIXEL_SPLAT_X4((dc0 + 2)>>2); ++ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2); ++ ++ for(i=0; i<16; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat); ++ } ++} ++ ++static void FUNCC(pred8x8_dc)(uint8_t *_src, int stride){ ++ int i; ++ int dc0, dc1, dc2; ++ pixel4 dc0splat, dc1splat, dc2splat, dc3splat; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ dc0=dc1=dc2=0; ++ for(i=0;i<4; i++){ ++ dc0+= src[-1+i*stride] + src[i-stride]; ++ dc1+= src[4+i-stride]; ++ dc2+= src[-1+(i+4)*stride]; ++ } ++ dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3); ++ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2); ++ dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2); ++ dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3); ++ ++ for(i=0; i<4; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat); ++ } ++ for(i=4; i<8; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat); ++ } ++} ++ ++static void FUNCC(pred8x16_dc)(uint8_t *_src, int stride){ ++ int i; ++ int dc0, dc1, dc2, dc3, dc4; ++ pixel4 dc0splat, dc1splat, dc2splat, dc3splat, dc4splat, dc5splat, dc6splat, dc7splat; ++ pixel *src = (pixel*)_src; ++ stride >>= sizeof(pixel)-1; ++ ++ dc0=dc1=dc2=dc3=dc4=0; ++ for(i=0;i<4; i++){ ++ dc0+= src[-1+i*stride] + src[i-stride]; ++ dc1+= src[4+i-stride]; ++ dc2+= src[-1+(i+4)*stride]; ++ dc3+= src[-1+(i+8)*stride]; ++ dc4+= src[-1+(i+12)*stride]; ++ } ++ dc0splat = PIXEL_SPLAT_X4((dc0 + 4)>>3); ++ dc1splat = PIXEL_SPLAT_X4((dc1 + 2)>>2); ++ dc2splat = PIXEL_SPLAT_X4((dc2 + 2)>>2); ++ dc3splat = PIXEL_SPLAT_X4((dc1 + dc2 + 4)>>3); ++ dc4splat = PIXEL_SPLAT_X4((dc3 + 2)>>2); ++ dc5splat = PIXEL_SPLAT_X4((dc1 + dc3 + 4)>>3); ++ dc6splat = PIXEL_SPLAT_X4((dc4 + 2)>>2); ++ dc7splat = PIXEL_SPLAT_X4((dc1 + dc4 + 4)>>3); ++ ++ for(i=0; i<4; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc0splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc1splat); ++ } ++ for(i=4; i<8; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc2splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc3splat); ++ } ++ for(i=8; i<12; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc4splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc5splat); ++ } ++ for(i=12; i<16; i++){ ++ AV_WN4PA(((pixel4*)(src+i*stride))+0, dc6splat); ++ AV_WN4PA(((pixel4*)(src+i*stride))+1, dc7splat); ++ } ++} ++ ++//the following 4 function should not be optimized! ++static void FUNC(pred8x8_mad_cow_dc_l0t)(uint8_t *src, int stride){ ++ FUNCC(pred8x8_top_dc)(src, stride); ++ FUNCC(pred4x4_dc)(src, NULL, stride); ++} ++ ++static void FUNC(pred8x16_mad_cow_dc_l0t)(uint8_t *src, int stride){ ++ FUNCC(pred8x16_top_dc)(src, stride); ++ FUNCC(pred4x4_dc)(src, NULL, stride); ++} ++ ++static void FUNC(pred8x8_mad_cow_dc_0lt)(uint8_t *src, int stride){ ++ FUNCC(pred8x8_dc)(src, stride); ++ FUNCC(pred4x4_top_dc)(src, NULL, stride); ++} ++ ++static void FUNC(pred8x16_mad_cow_dc_0lt)(uint8_t *src, int stride){ ++ FUNCC(pred8x16_dc)(src, stride); ++ FUNCC(pred4x4_top_dc)(src, NULL, stride); ++} ++ ++static void FUNC(pred8x8_mad_cow_dc_l00)(uint8_t *src, int stride){ ++ FUNCC(pred8x8_left_dc)(src, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride); ++} ++ ++static void FUNC(pred8x16_mad_cow_dc_l00)(uint8_t *src, int stride){ ++ FUNCC(pred8x16_left_dc)(src, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*stride , NULL, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*stride + 4*sizeof(pixel), NULL, stride); ++} ++ ++static void FUNC(pred8x8_mad_cow_dc_0l0)(uint8_t *src, int stride){ ++ FUNCC(pred8x8_left_dc)(src, stride); ++ FUNCC(pred4x4_128_dc)(src , NULL, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride); ++} ++ ++static void FUNC(pred8x16_mad_cow_dc_0l0)(uint8_t *src, int stride){ ++ FUNCC(pred8x16_left_dc)(src, stride); ++ FUNCC(pred4x4_128_dc)(src , NULL, stride); ++ FUNCC(pred4x4_128_dc)(src + 4*sizeof(pixel), NULL, stride); ++} ++ ++static void FUNCC(pred8x8_plane)(uint8_t *_src, int _stride){ ++ int j, k; ++ int a; ++ INIT_CLIP ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel * const src0 = src +3-stride; ++ const pixel * src1 = src +4*stride-1; ++ const pixel * src2 = src1-2*stride; // == src+2*stride-1; ++ int H = src0[1] - src0[-1]; ++ int V = src1[0] - src2[ 0]; ++ for(k=2; k<=4; ++k) { ++ src1 += stride; src2 -= stride; ++ H += k*(src0[k] - src0[-k]); ++ V += k*(src1[0] - src2[ 0]); ++ } ++ H = ( 17*H+16 ) >> 5; ++ V = ( 17*V+16 ) >> 5; ++ ++ a = 16*(src1[0] + src2[8]+1) - 3*(V+H); ++ for(j=8; j>0; --j) { ++ int b = a; ++ a += V; ++ src[0] = CLIP((b ) >> 5); ++ src[1] = CLIP((b+ H) >> 5); ++ src[2] = CLIP((b+2*H) >> 5); ++ src[3] = CLIP((b+3*H) >> 5); ++ src[4] = CLIP((b+4*H) >> 5); ++ src[5] = CLIP((b+5*H) >> 5); ++ src[6] = CLIP((b+6*H) >> 5); ++ src[7] = CLIP((b+7*H) >> 5); ++ src += stride; ++ } ++} ++ ++static void FUNCC(pred8x16_plane)(uint8_t *_src, int _stride){ ++ int j, k; ++ int a; ++ INIT_CLIP ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ const pixel * const src0 = src +3-stride; ++ const pixel * src1 = src +8*stride-1; ++ const pixel * src2 = src1-2*stride; // == src+6*stride-1; ++ int H = src0[1] - src0[-1]; ++ int V = src1[0] - src2[ 0]; ++ ++ for (k = 2; k <= 4; ++k) { ++ src1 += stride; src2 -= stride; ++ H += k*(src0[k] - src0[-k]); ++ V += k*(src1[0] - src2[ 0]); ++ } ++ for (; k <= 8; ++k) { ++ src1 += stride; src2 -= stride; ++ V += k*(src1[0] - src2[0]); ++ } ++ ++ H = (17*H+16) >> 5; ++ V = (5*V+32) >> 6; ++ ++ a = 16*(src1[0] + src2[8] + 1) - 7*V - 3*H; ++ for(j=16; j>0; --j) { ++ int b = a; ++ a += V; ++ src[0] = CLIP((b ) >> 5); ++ src[1] = CLIP((b+ H) >> 5); ++ src[2] = CLIP((b+2*H) >> 5); ++ src[3] = CLIP((b+3*H) >> 5); ++ src[4] = CLIP((b+4*H) >> 5); ++ src[5] = CLIP((b+5*H) >> 5); ++ src[6] = CLIP((b+6*H) >> 5); ++ src[7] = CLIP((b+7*H) >> 5); ++ src += stride; ++ } ++} ++ ++#define SRC(x,y) src[(x)+(y)*stride] ++#define PL(y) \ ++ const int l##y = (SRC(-1,y-1) + 2*SRC(-1,y) + SRC(-1,y+1) + 2) >> 2; ++#define PREDICT_8x8_LOAD_LEFT \ ++ const int l0 = ((has_topleft ? SRC(-1,-1) : SRC(-1,0)) \ ++ + 2*SRC(-1,0) + SRC(-1,1) + 2) >> 2; \ ++ PL(1) PL(2) PL(3) PL(4) PL(5) PL(6) \ ++ const int l7 av_unused = (SRC(-1,6) + 3*SRC(-1,7) + 2) >> 2 ++ ++#define PT(x) \ ++ const int t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; ++#define PREDICT_8x8_LOAD_TOP \ ++ const int t0 = ((has_topleft ? SRC(-1,-1) : SRC(0,-1)) \ ++ + 2*SRC(0,-1) + SRC(1,-1) + 2) >> 2; \ ++ PT(1) PT(2) PT(3) PT(4) PT(5) PT(6) \ ++ const int t7 av_unused = ((has_topright ? SRC(8,-1) : SRC(7,-1)) \ ++ + 2*SRC(7,-1) + SRC(6,-1) + 2) >> 2 ++ ++#define PTR(x) \ ++ t##x = (SRC(x-1,-1) + 2*SRC(x,-1) + SRC(x+1,-1) + 2) >> 2; ++#define PREDICT_8x8_LOAD_TOPRIGHT \ ++ int t8, t9, t10, t11, t12, t13, t14, t15; \ ++ if(has_topright) { \ ++ PTR(8) PTR(9) PTR(10) PTR(11) PTR(12) PTR(13) PTR(14) \ ++ t15 = (SRC(14,-1) + 3*SRC(15,-1) + 2) >> 2; \ ++ } else t8=t9=t10=t11=t12=t13=t14=t15= SRC(7,-1); ++ ++#define PREDICT_8x8_LOAD_TOPLEFT \ ++ const int lt = (SRC(-1,0) + 2*SRC(-1,-1) + SRC(0,-1) + 2) >> 2 ++ ++#define PREDICT_8x8_DC(v) \ ++ int y; \ ++ for( y = 0; y < 8; y++ ) { \ ++ AV_WN4PA(((pixel4*)src)+0, v); \ ++ AV_WN4PA(((pixel4*)src)+1, v); \ ++ src += stride; \ ++ } ++ ++static void FUNCC(pred8x8l_128_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride) ++{ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ ++ PREDICT_8x8_DC(PIXEL_SPLAT_X4(1<<(BIT_DEPTH-1))); ++} ++static void FUNCC(pred8x8l_left_dc)(uint8_t *_src, int has_topleft, int has_topright, int _stride) ++{ ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ ++ PREDICT_8x8_LOAD_LEFT; ++ const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7+4) >> 3); ++ PREDICT_8x8_DC(dc); ++} ++static void FUNCC(pred8x8l_top_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ ++ PREDICT_8x8_LOAD_TOP; ++ const pixel4 dc = PIXEL_SPLAT_X4((t0+t1+t2+t3+t4+t5+t6+t7+4) >> 3); ++ PREDICT_8x8_DC(dc); ++} ++static void FUNCC(pred8x8l_dc)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ ++ PREDICT_8x8_LOAD_LEFT; ++ PREDICT_8x8_LOAD_TOP; ++ const pixel4 dc = PIXEL_SPLAT_X4((l0+l1+l2+l3+l4+l5+l6+l7 ++ +t0+t1+t2+t3+t4+t5+t6+t7+8) >> 4); ++ PREDICT_8x8_DC(dc); ++} ++static void FUNCC(pred8x8l_horizontal)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ pixel4 a; ++ ++ PREDICT_8x8_LOAD_LEFT; ++#define ROW(y) a = PIXEL_SPLAT_X4(l##y); \ ++ AV_WN4PA(src+y*stride, a); \ ++ AV_WN4PA(src+y*stride+4, a); ++ ROW(0); ROW(1); ROW(2); ROW(3); ROW(4); ROW(5); ROW(6); ROW(7); ++#undef ROW ++} ++static void FUNCC(pred8x8l_vertical)(uint8_t *_src, int has_topleft, int has_topright, int _stride) ++{ ++ int y; ++ pixel *src = (pixel*)_src; ++ int stride = _stride>>(sizeof(pixel)-1); ++ pixel4 a, b; ++ ++ PREDICT_8x8_LOAD_TOP; ++ src[0] = t0; ++ src[1] = t1; ++ src[2] = t2; ++ src[3] = t3; ++ src[4] = t4; ++ src[5] = t5; ++ src[6] = t6; ++ src[7] = t7; ++ a = AV_RN4PA(((pixel4*)src)+0); ++ b = AV_RN4PA(((pixel4*)src)+1); ++ for( y = 1; y < 8; y++ ) { ++ AV_WN4PA(((pixel4*)(src+y*stride))+0, a); ++ AV_WN4PA(((pixel4*)(src+y*stride))+1, b); ++ } ++} ++static void FUNCC(pred8x8l_down_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_TOP; ++ PREDICT_8x8_LOAD_TOPRIGHT; ++ SRC(0,0)= (t0 + 2*t1 + t2 + 2) >> 2; ++ SRC(0,1)=SRC(1,0)= (t1 + 2*t2 + t3 + 2) >> 2; ++ SRC(0,2)=SRC(1,1)=SRC(2,0)= (t2 + 2*t3 + t4 + 2) >> 2; ++ SRC(0,3)=SRC(1,2)=SRC(2,1)=SRC(3,0)= (t3 + 2*t4 + t5 + 2) >> 2; ++ SRC(0,4)=SRC(1,3)=SRC(2,2)=SRC(3,1)=SRC(4,0)= (t4 + 2*t5 + t6 + 2) >> 2; ++ SRC(0,5)=SRC(1,4)=SRC(2,3)=SRC(3,2)=SRC(4,1)=SRC(5,0)= (t5 + 2*t6 + t7 + 2) >> 2; ++ SRC(0,6)=SRC(1,5)=SRC(2,4)=SRC(3,3)=SRC(4,2)=SRC(5,1)=SRC(6,0)= (t6 + 2*t7 + t8 + 2) >> 2; ++ SRC(0,7)=SRC(1,6)=SRC(2,5)=SRC(3,4)=SRC(4,3)=SRC(5,2)=SRC(6,1)=SRC(7,0)= (t7 + 2*t8 + t9 + 2) >> 2; ++ SRC(1,7)=SRC(2,6)=SRC(3,5)=SRC(4,4)=SRC(5,3)=SRC(6,2)=SRC(7,1)= (t8 + 2*t9 + t10 + 2) >> 2; ++ SRC(2,7)=SRC(3,6)=SRC(4,5)=SRC(5,4)=SRC(6,3)=SRC(7,2)= (t9 + 2*t10 + t11 + 2) >> 2; ++ SRC(3,7)=SRC(4,6)=SRC(5,5)=SRC(6,4)=SRC(7,3)= (t10 + 2*t11 + t12 + 2) >> 2; ++ SRC(4,7)=SRC(5,6)=SRC(6,5)=SRC(7,4)= (t11 + 2*t12 + t13 + 2) >> 2; ++ SRC(5,7)=SRC(6,6)=SRC(7,5)= (t12 + 2*t13 + t14 + 2) >> 2; ++ SRC(6,7)=SRC(7,6)= (t13 + 2*t14 + t15 + 2) >> 2; ++ SRC(7,7)= (t14 + 3*t15 + 2) >> 2; ++} ++static void FUNCC(pred8x8l_down_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_TOP; ++ PREDICT_8x8_LOAD_LEFT; ++ PREDICT_8x8_LOAD_TOPLEFT; ++ SRC(0,7)= (l7 + 2*l6 + l5 + 2) >> 2; ++ SRC(0,6)=SRC(1,7)= (l6 + 2*l5 + l4 + 2) >> 2; ++ SRC(0,5)=SRC(1,6)=SRC(2,7)= (l5 + 2*l4 + l3 + 2) >> 2; ++ SRC(0,4)=SRC(1,5)=SRC(2,6)=SRC(3,7)= (l4 + 2*l3 + l2 + 2) >> 2; ++ SRC(0,3)=SRC(1,4)=SRC(2,5)=SRC(3,6)=SRC(4,7)= (l3 + 2*l2 + l1 + 2) >> 2; ++ SRC(0,2)=SRC(1,3)=SRC(2,4)=SRC(3,5)=SRC(4,6)=SRC(5,7)= (l2 + 2*l1 + l0 + 2) >> 2; ++ SRC(0,1)=SRC(1,2)=SRC(2,3)=SRC(3,4)=SRC(4,5)=SRC(5,6)=SRC(6,7)= (l1 + 2*l0 + lt + 2) >> 2; ++ SRC(0,0)=SRC(1,1)=SRC(2,2)=SRC(3,3)=SRC(4,4)=SRC(5,5)=SRC(6,6)=SRC(7,7)= (l0 + 2*lt + t0 + 2) >> 2; ++ SRC(1,0)=SRC(2,1)=SRC(3,2)=SRC(4,3)=SRC(5,4)=SRC(6,5)=SRC(7,6)= (lt + 2*t0 + t1 + 2) >> 2; ++ SRC(2,0)=SRC(3,1)=SRC(4,2)=SRC(5,3)=SRC(6,4)=SRC(7,5)= (t0 + 2*t1 + t2 + 2) >> 2; ++ SRC(3,0)=SRC(4,1)=SRC(5,2)=SRC(6,3)=SRC(7,4)= (t1 + 2*t2 + t3 + 2) >> 2; ++ SRC(4,0)=SRC(5,1)=SRC(6,2)=SRC(7,3)= (t2 + 2*t3 + t4 + 2) >> 2; ++ SRC(5,0)=SRC(6,1)=SRC(7,2)= (t3 + 2*t4 + t5 + 2) >> 2; ++ SRC(6,0)=SRC(7,1)= (t4 + 2*t5 + t6 + 2) >> 2; ++ SRC(7,0)= (t5 + 2*t6 + t7 + 2) >> 2; ++} ++static void FUNCC(pred8x8l_vertical_right)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_TOP; ++ PREDICT_8x8_LOAD_LEFT; ++ PREDICT_8x8_LOAD_TOPLEFT; ++ SRC(0,6)= (l5 + 2*l4 + l3 + 2) >> 2; ++ SRC(0,7)= (l6 + 2*l5 + l4 + 2) >> 2; ++ SRC(0,4)=SRC(1,6)= (l3 + 2*l2 + l1 + 2) >> 2; ++ SRC(0,5)=SRC(1,7)= (l4 + 2*l3 + l2 + 2) >> 2; ++ SRC(0,2)=SRC(1,4)=SRC(2,6)= (l1 + 2*l0 + lt + 2) >> 2; ++ SRC(0,3)=SRC(1,5)=SRC(2,7)= (l2 + 2*l1 + l0 + 2) >> 2; ++ SRC(0,1)=SRC(1,3)=SRC(2,5)=SRC(3,7)= (l0 + 2*lt + t0 + 2) >> 2; ++ SRC(0,0)=SRC(1,2)=SRC(2,4)=SRC(3,6)= (lt + t0 + 1) >> 1; ++ SRC(1,1)=SRC(2,3)=SRC(3,5)=SRC(4,7)= (lt + 2*t0 + t1 + 2) >> 2; ++ SRC(1,0)=SRC(2,2)=SRC(3,4)=SRC(4,6)= (t0 + t1 + 1) >> 1; ++ SRC(2,1)=SRC(3,3)=SRC(4,5)=SRC(5,7)= (t0 + 2*t1 + t2 + 2) >> 2; ++ SRC(2,0)=SRC(3,2)=SRC(4,4)=SRC(5,6)= (t1 + t2 + 1) >> 1; ++ SRC(3,1)=SRC(4,3)=SRC(5,5)=SRC(6,7)= (t1 + 2*t2 + t3 + 2) >> 2; ++ SRC(3,0)=SRC(4,2)=SRC(5,4)=SRC(6,6)= (t2 + t3 + 1) >> 1; ++ SRC(4,1)=SRC(5,3)=SRC(6,5)=SRC(7,7)= (t2 + 2*t3 + t4 + 2) >> 2; ++ SRC(4,0)=SRC(5,2)=SRC(6,4)=SRC(7,6)= (t3 + t4 + 1) >> 1; ++ SRC(5,1)=SRC(6,3)=SRC(7,5)= (t3 + 2*t4 + t5 + 2) >> 2; ++ SRC(5,0)=SRC(6,2)=SRC(7,4)= (t4 + t5 + 1) >> 1; ++ SRC(6,1)=SRC(7,3)= (t4 + 2*t5 + t6 + 2) >> 2; ++ SRC(6,0)=SRC(7,2)= (t5 + t6 + 1) >> 1; ++ SRC(7,1)= (t5 + 2*t6 + t7 + 2) >> 2; ++ SRC(7,0)= (t6 + t7 + 1) >> 1; ++} ++static void FUNCC(pred8x8l_horizontal_down)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_TOP; ++ PREDICT_8x8_LOAD_LEFT; ++ PREDICT_8x8_LOAD_TOPLEFT; ++ SRC(0,7)= (l6 + l7 + 1) >> 1; ++ SRC(1,7)= (l5 + 2*l6 + l7 + 2) >> 2; ++ SRC(0,6)=SRC(2,7)= (l5 + l6 + 1) >> 1; ++ SRC(1,6)=SRC(3,7)= (l4 + 2*l5 + l6 + 2) >> 2; ++ SRC(0,5)=SRC(2,6)=SRC(4,7)= (l4 + l5 + 1) >> 1; ++ SRC(1,5)=SRC(3,6)=SRC(5,7)= (l3 + 2*l4 + l5 + 2) >> 2; ++ SRC(0,4)=SRC(2,5)=SRC(4,6)=SRC(6,7)= (l3 + l4 + 1) >> 1; ++ SRC(1,4)=SRC(3,5)=SRC(5,6)=SRC(7,7)= (l2 + 2*l3 + l4 + 2) >> 2; ++ SRC(0,3)=SRC(2,4)=SRC(4,5)=SRC(6,6)= (l2 + l3 + 1) >> 1; ++ SRC(1,3)=SRC(3,4)=SRC(5,5)=SRC(7,6)= (l1 + 2*l2 + l3 + 2) >> 2; ++ SRC(0,2)=SRC(2,3)=SRC(4,4)=SRC(6,5)= (l1 + l2 + 1) >> 1; ++ SRC(1,2)=SRC(3,3)=SRC(5,4)=SRC(7,5)= (l0 + 2*l1 + l2 + 2) >> 2; ++ SRC(0,1)=SRC(2,2)=SRC(4,3)=SRC(6,4)= (l0 + l1 + 1) >> 1; ++ SRC(1,1)=SRC(3,2)=SRC(5,3)=SRC(7,4)= (lt + 2*l0 + l1 + 2) >> 2; ++ SRC(0,0)=SRC(2,1)=SRC(4,2)=SRC(6,3)= (lt + l0 + 1) >> 1; ++ SRC(1,0)=SRC(3,1)=SRC(5,2)=SRC(7,3)= (l0 + 2*lt + t0 + 2) >> 2; ++ SRC(2,0)=SRC(4,1)=SRC(6,2)= (t1 + 2*t0 + lt + 2) >> 2; ++ SRC(3,0)=SRC(5,1)=SRC(7,2)= (t2 + 2*t1 + t0 + 2) >> 2; ++ SRC(4,0)=SRC(6,1)= (t3 + 2*t2 + t1 + 2) >> 2; ++ SRC(5,0)=SRC(7,1)= (t4 + 2*t3 + t2 + 2) >> 2; ++ SRC(6,0)= (t5 + 2*t4 + t3 + 2) >> 2; ++ SRC(7,0)= (t6 + 2*t5 + t4 + 2) >> 2; ++} ++static void FUNCC(pred8x8l_vertical_left)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_TOP; ++ PREDICT_8x8_LOAD_TOPRIGHT; ++ SRC(0,0)= (t0 + t1 + 1) >> 1; ++ SRC(0,1)= (t0 + 2*t1 + t2 + 2) >> 2; ++ SRC(0,2)=SRC(1,0)= (t1 + t2 + 1) >> 1; ++ SRC(0,3)=SRC(1,1)= (t1 + 2*t2 + t3 + 2) >> 2; ++ SRC(0,4)=SRC(1,2)=SRC(2,0)= (t2 + t3 + 1) >> 1; ++ SRC(0,5)=SRC(1,3)=SRC(2,1)= (t2 + 2*t3 + t4 + 2) >> 2; ++ SRC(0,6)=SRC(1,4)=SRC(2,2)=SRC(3,0)= (t3 + t4 + 1) >> 1; ++ SRC(0,7)=SRC(1,5)=SRC(2,3)=SRC(3,1)= (t3 + 2*t4 + t5 + 2) >> 2; ++ SRC(1,6)=SRC(2,4)=SRC(3,2)=SRC(4,0)= (t4 + t5 + 1) >> 1; ++ SRC(1,7)=SRC(2,5)=SRC(3,3)=SRC(4,1)= (t4 + 2*t5 + t6 + 2) >> 2; ++ SRC(2,6)=SRC(3,4)=SRC(4,2)=SRC(5,0)= (t5 + t6 + 1) >> 1; ++ SRC(2,7)=SRC(3,5)=SRC(4,3)=SRC(5,1)= (t5 + 2*t6 + t7 + 2) >> 2; ++ SRC(3,6)=SRC(4,4)=SRC(5,2)=SRC(6,0)= (t6 + t7 + 1) >> 1; ++ SRC(3,7)=SRC(4,5)=SRC(5,3)=SRC(6,1)= (t6 + 2*t7 + t8 + 2) >> 2; ++ SRC(4,6)=SRC(5,4)=SRC(6,2)=SRC(7,0)= (t7 + t8 + 1) >> 1; ++ SRC(4,7)=SRC(5,5)=SRC(6,3)=SRC(7,1)= (t7 + 2*t8 + t9 + 2) >> 2; ++ SRC(5,6)=SRC(6,4)=SRC(7,2)= (t8 + t9 + 1) >> 1; ++ SRC(5,7)=SRC(6,5)=SRC(7,3)= (t8 + 2*t9 + t10 + 2) >> 2; ++ SRC(6,6)=SRC(7,4)= (t9 + t10 + 1) >> 1; ++ SRC(6,7)=SRC(7,5)= (t9 + 2*t10 + t11 + 2) >> 2; ++ SRC(7,6)= (t10 + t11 + 1) >> 1; ++ SRC(7,7)= (t10 + 2*t11 + t12 + 2) >> 2; ++} ++static void FUNCC(pred8x8l_horizontal_up)(uint8_t *p_src, int has_topleft, int has_topright, int p_stride) ++{ ++ pixel *src = (pixel*)p_src; ++ int stride = p_stride>>(sizeof(pixel)-1); ++ PREDICT_8x8_LOAD_LEFT; ++ SRC(0,0)= (l0 + l1 + 1) >> 1; ++ SRC(1,0)= (l0 + 2*l1 + l2 + 2) >> 2; ++ SRC(0,1)=SRC(2,0)= (l1 + l2 + 1) >> 1; ++ SRC(1,1)=SRC(3,0)= (l1 + 2*l2 + l3 + 2) >> 2; ++ SRC(0,2)=SRC(2,1)=SRC(4,0)= (l2 + l3 + 1) >> 1; ++ SRC(1,2)=SRC(3,1)=SRC(5,0)= (l2 + 2*l3 + l4 + 2) >> 2; ++ SRC(0,3)=SRC(2,2)=SRC(4,1)=SRC(6,0)= (l3 + l4 + 1) >> 1; ++ SRC(1,3)=SRC(3,2)=SRC(5,1)=SRC(7,0)= (l3 + 2*l4 + l5 + 2) >> 2; ++ SRC(0,4)=SRC(2,3)=SRC(4,2)=SRC(6,1)= (l4 + l5 + 1) >> 1; ++ SRC(1,4)=SRC(3,3)=SRC(5,2)=SRC(7,1)= (l4 + 2*l5 + l6 + 2) >> 2; ++ SRC(0,5)=SRC(2,4)=SRC(4,3)=SRC(6,2)= (l5 + l6 + 1) >> 1; ++ SRC(1,5)=SRC(3,4)=SRC(5,3)=SRC(7,2)= (l5 + 2*l6 + l7 + 2) >> 2; ++ SRC(0,6)=SRC(2,5)=SRC(4,4)=SRC(6,3)= (l6 + l7 + 1) >> 1; ++ SRC(1,6)=SRC(3,5)=SRC(5,4)=SRC(7,3)= (l6 + 3*l7 + 2) >> 2; ++ SRC(0,7)=SRC(1,7)=SRC(2,6)=SRC(2,7)=SRC(3,6)= ++ SRC(3,7)=SRC(4,5)=SRC(4,6)=SRC(4,7)=SRC(5,5)= ++ SRC(5,6)=SRC(5,7)=SRC(6,4)=SRC(6,5)=SRC(6,6)= ++ SRC(6,7)=SRC(7,4)=SRC(7,5)=SRC(7,6)=SRC(7,7)= l7; ++} ++#undef PREDICT_8x8_LOAD_LEFT ++#undef PREDICT_8x8_LOAD_TOP ++#undef PREDICT_8x8_LOAD_TOPLEFT ++#undef PREDICT_8x8_LOAD_TOPRIGHT ++#undef PREDICT_8x8_DC ++#undef PTR ++#undef PT ++#undef PL ++#undef SRC ++ ++static void FUNCC(pred4x4_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){ ++ int i; ++ pixel *pix = (pixel*)p_pix; ++ const dctcoef *block = (const dctcoef*)p_block; ++ stride >>= sizeof(pixel)-1; ++ pix -= stride; ++ for(i=0; i<4; i++){ ++ pixel v = pix[0]; ++ pix[1*stride]= v += block[0]; ++ pix[2*stride]= v += block[4]; ++ pix[3*stride]= v += block[8]; ++ pix[4*stride]= v + block[12]; ++ pix++; ++ block++; ++ } ++} ++ ++static void FUNCC(pred4x4_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){ ++ int i; ++ pixel *pix = (pixel*)p_pix; ++ const dctcoef *block = (const dctcoef*)p_block; ++ stride >>= sizeof(pixel)-1; ++ for(i=0; i<4; i++){ ++ pixel v = pix[-1]; ++ pix[0]= v += block[0]; ++ pix[1]= v += block[1]; ++ pix[2]= v += block[2]; ++ pix[3]= v + block[3]; ++ pix+= stride; ++ block+= 4; ++ } ++} ++ ++static void FUNCC(pred8x8l_vertical_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){ ++ int i; ++ pixel *pix = (pixel*)p_pix; ++ const dctcoef *block = (const dctcoef*)p_block; ++ stride >>= sizeof(pixel)-1; ++ pix -= stride; ++ for(i=0; i<8; i++){ ++ pixel v = pix[0]; ++ pix[1*stride]= v += block[0]; ++ pix[2*stride]= v += block[8]; ++ pix[3*stride]= v += block[16]; ++ pix[4*stride]= v += block[24]; ++ pix[5*stride]= v += block[32]; ++ pix[6*stride]= v += block[40]; ++ pix[7*stride]= v += block[48]; ++ pix[8*stride]= v + block[56]; ++ pix++; ++ block++; ++ } ++} ++ ++static void FUNCC(pred8x8l_horizontal_add)(uint8_t *p_pix, const DCTELEM *p_block, int stride){ ++ int i; ++ pixel *pix = (pixel*)p_pix; ++ const dctcoef *block = (const dctcoef*)p_block; ++ stride >>= sizeof(pixel)-1; ++ for(i=0; i<8; i++){ ++ pixel v = pix[-1]; ++ pix[0]= v += block[0]; ++ pix[1]= v += block[1]; ++ pix[2]= v += block[2]; ++ pix[3]= v += block[3]; ++ pix[4]= v += block[4]; ++ pix[5]= v += block[5]; ++ pix[6]= v += block[6]; ++ pix[7]= v + block[7]; ++ pix+= stride; ++ block+= 8; ++ } ++} ++ ++static void FUNCC(pred16x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<16; i++) ++ FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++} ++ ++static void FUNCC(pred16x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<16; i++) ++ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++} ++ ++static void FUNCC(pred8x8_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<4; i++) ++ FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++} ++ ++static void FUNCC(pred8x16_vertical_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<4; i++) ++ FUNCC(pred4x4_vertical_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++ for(i=4; i<8; i++) ++ FUNCC(pred4x4_vertical_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride); ++} ++ ++static void FUNCC(pred8x8_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<4; i++) ++ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++} ++ ++static void FUNCC(pred8x16_horizontal_add)(uint8_t *pix, const int *block_offset, const DCTELEM *block, int stride){ ++ int i; ++ for(i=0; i<4; i++) ++ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i], block + i*16*sizeof(pixel), stride); ++ for(i=4; i<8; i++) ++ FUNCC(pred4x4_horizontal_add)(pix + block_offset[i+4], block + i*16*sizeof(pixel), stride); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_ps.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_ps.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_ps.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_ps.c 2012-05-14 14:08:53.818329596 +0200 +@@ -25,7 +25,7 @@ + * @author Michael Niedermayer + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "internal.h" + #include "dsputil.h" + #include "avcodec.h" +@@ -57,11 +57,45 @@ + {2, 1}, + }; + +-const uint8_t ff_h264_chroma_qp[52]={ +- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11, +- 12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27, +- 28,29,29,30,31,32,32,33,34,34,35,35,36,36,37,37, +- 37,38,38,38,39,39,39,39 ++#define QP(qP,depth) ( (qP)+6*((depth)-8) ) ++ ++#define CHROMA_QP_TABLE_END(d) \ ++ QP(0,d), QP(1,d), QP(2,d), QP(3,d), QP(4,d), QP(5,d),\ ++ QP(6,d), QP(7,d), QP(8,d), QP(9,d), QP(10,d), QP(11,d),\ ++ QP(12,d), QP(13,d), QP(14,d), QP(15,d), QP(16,d), QP(17,d),\ ++ QP(18,d), QP(19,d), QP(20,d), QP(21,d), QP(22,d), QP(23,d),\ ++ QP(24,d), QP(25,d), QP(26,d), QP(27,d), QP(28,d), QP(29,d),\ ++ QP(29,d), QP(30,d), QP(31,d), QP(32,d), QP(32,d), QP(33,d),\ ++ QP(34,d), QP(34,d), QP(35,d), QP(35,d), QP(36,d), QP(36,d),\ ++ QP(37,d), QP(37,d), QP(37,d), QP(38,d), QP(38,d), QP(38,d),\ ++ QP(39,d), QP(39,d), QP(39,d), QP(39,d) ++ ++const uint8_t ff_h264_chroma_qp[5][QP_MAX_NUM+1] = { ++ { ++ CHROMA_QP_TABLE_END(8) ++ }, ++ { ++ 0, 1, 2, 3, 4, 5, ++ CHROMA_QP_TABLE_END(9) ++ }, ++ { ++ 0, 1, 2, 3, 4, 5, ++ 6, 7, 8, 9, 10, 11, ++ CHROMA_QP_TABLE_END(10) ++ }, ++ { ++ 0, 1, 2, 3, 4, 5, ++ 6, 7, 8, 9, 10, 11, ++ 12,13,14,15, 16, 17, ++ CHROMA_QP_TABLE_END(11) ++ }, ++ { ++ 0, 1, 2, 3, 4, 5, ++ 6, 7, 8, 9, 10, 11, ++ 12,13,14,15, 16, 17, ++ 18,19,20,21, 22, 23, ++ CHROMA_QP_TABLE_END(12) ++ }, + }; + + static const uint8_t default_scaling4[2][16]={ +@@ -109,8 +143,8 @@ + get_bits(&s->gb, 4); /* bit_rate_scale */ + get_bits(&s->gb, 4); /* cpb_size_scale */ + for(i=0; igb); /* bit_rate_value_minus1 */ +- get_ue_golomb(&s->gb); /* cpb_size_value_minus1 */ ++ get_ue_golomb_long(&s->gb); /* bit_rate_value_minus1 */ ++ get_ue_golomb_long(&s->gb); /* cpb_size_value_minus1 */ + get_bits1(&s->gb); /* cbr_flag */ + } + sps->initial_cpb_removal_delay_length = get_bits(&s->gb, 5) + 1; +@@ -195,7 +229,8 @@ + if(sps->nal_hrd_parameters_present_flag || sps->vcl_hrd_parameters_present_flag) + get_bits1(&s->gb); /* low_delay_hrd_flag */ + sps->pic_struct_present_flag = get_bits1(&s->gb); +- ++ if(!get_bits_left(&s->gb)) ++ return 0; + sps->bitstream_restriction_flag = get_bits1(&s->gb); + if(sps->bitstream_restriction_flag){ + get_bits1(&s->gb); /* motion_vectors_over_pic_boundaries_flag */ +@@ -206,8 +241,7 @@ + sps->num_reorder_frames= get_ue_golomb(&s->gb); + get_ue_golomb(&s->gb); /*max_dec_frame_buffering*/ + +- if(s->gb.size_in_bits < get_bits_count(&s->gb)){ +- av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", get_bits_count(&s->gb) - s->gb.size_in_bits); ++ if (get_bits_left(&s->gb) < 0) { + sps->num_reorder_frames=0; + sps->bitstream_restriction_flag= 0; + } +@@ -217,6 +251,10 @@ + return -1; + } + } ++ if (get_bits_left(&s->gb) < 0) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "Overread VUI by %d bits\n", -get_bits_left(&s->gb)); ++ return AVERROR_INVALIDDATA; ++ } + + return 0; + } +@@ -248,7 +286,7 @@ + fallback_sps ? sps->scaling_matrix4[0] : default_scaling4[0], + fallback_sps ? sps->scaling_matrix4[3] : default_scaling4[1], + fallback_sps ? sps->scaling_matrix8[0] : default_scaling8[0], +- fallback_sps ? sps->scaling_matrix8[1] : default_scaling8[1] ++ fallback_sps ? sps->scaling_matrix8[3] : default_scaling8[1] + }; + if(get_bits1(&s->gb)){ + sps->scaling_matrix_present |= is_sps; +@@ -260,7 +298,15 @@ + decode_scaling_list(h,scaling_matrix4[5],16,default_scaling4[1],scaling_matrix4[4]); // Inter, Cb + if(is_sps || pps->transform_8x8_mode){ + decode_scaling_list(h,scaling_matrix8[0],64,default_scaling8[0],fallback[2]); // Intra, Y +- decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[1],fallback[3]); // Inter, Y ++ if(sps->chroma_format_idc == 3){ ++ decode_scaling_list(h,scaling_matrix8[1],64,default_scaling8[0],scaling_matrix8[0]); // Intra, Cr ++ decode_scaling_list(h,scaling_matrix8[2],64,default_scaling8[0],scaling_matrix8[1]); // Intra, Cb ++ } ++ decode_scaling_list(h,scaling_matrix8[3],64,default_scaling8[1],fallback[3]); // Inter, Y ++ if(sps->chroma_format_idc == 3){ ++ decode_scaling_list(h,scaling_matrix8[4],64,default_scaling8[1],scaling_matrix8[3]); // Inter, Cr ++ decode_scaling_list(h,scaling_matrix8[5],64,default_scaling8[1],scaling_matrix8[4]); // Inter, Cb ++ } + } + } + } +@@ -293,17 +339,28 @@ + sps->profile_idc= profile_idc; + sps->constraint_set_flags = constraint_set_flags; + sps->level_idc= level_idc; ++ sps->full_range = -1; + + memset(sps->scaling_matrix4, 16, sizeof(sps->scaling_matrix4)); + memset(sps->scaling_matrix8, 16, sizeof(sps->scaling_matrix8)); + sps->scaling_matrix_present = 0; ++ sps->colorspace = 2; //AVCOL_SPC_UNSPECIFIED + + if(sps->profile_idc >= 100){ //high profile + sps->chroma_format_idc= get_ue_golomb_31(&s->gb); ++ if (sps->chroma_format_idc > 3U) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "chroma_format_idc %d is illegal\n", sps->chroma_format_idc); ++ goto fail; ++ } + if(sps->chroma_format_idc == 3) + sps->residual_color_transform_flag = get_bits1(&s->gb); + sps->bit_depth_luma = get_ue_golomb(&s->gb) + 8; + sps->bit_depth_chroma = get_ue_golomb(&s->gb) + 8; ++ if (sps->bit_depth_luma > 12U || sps->bit_depth_chroma > 12U) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "illegal bit depth value (%d, %d)\n", ++ sps->bit_depth_luma, sps->bit_depth_chroma); ++ goto fail; ++ } + sps->transform_bypass = get_bits1(&s->gb); + decode_scaling_matrices(h, sps, NULL, 1, sps->scaling_matrix4, sps->scaling_matrix8); + }else{ +@@ -336,7 +393,7 @@ + } + + sps->ref_frame_count= get_ue_golomb_31(&s->gb); +- if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count >= 32U){ ++ if(sps->ref_frame_count > MAX_PICTURE_COUNT-2 || sps->ref_frame_count > 16U){ + av_log(h->s.avctx, AV_LOG_ERROR, "too many reference frames\n"); + goto fail; + } +@@ -356,10 +413,6 @@ + sps->mb_aff= 0; + + sps->direct_8x8_inference_flag= get_bits1(&s->gb); +- if(!sps->frame_mbs_only_flag && !sps->direct_8x8_inference_flag){ +- av_log(h->s.avctx, AV_LOG_ERROR, "This stream was generated by a broken encoder, invalid 8x8 inference\n"); +- goto fail; +- } + + #ifndef ALLOW_INTERLACE + if(sps->mb_aff) +@@ -367,15 +420,24 @@ + #endif + sps->crop= get_bits1(&s->gb); + if(sps->crop){ ++ int crop_vertical_limit = sps->chroma_format_idc & 2 ? 16 : 8; ++ int crop_horizontal_limit = sps->chroma_format_idc == 3 ? 16 : 8; + sps->crop_left = get_ue_golomb(&s->gb); + sps->crop_right = get_ue_golomb(&s->gb); + sps->crop_top = get_ue_golomb(&s->gb); + sps->crop_bottom= get_ue_golomb(&s->gb); + if(sps->crop_left || sps->crop_top){ +- av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ...\n"); ++ av_log(h->s.avctx, AV_LOG_ERROR, "insane cropping not completely supported, this could look slightly wrong ... (left: %d, top: %d)\n", sps->crop_left, sps->crop_top); + } +- if(sps->crop_right >= 8 || sps->crop_bottom >= 8){ +- av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, this could look slightly wrong ...\n"); ++ if(sps->crop_right >= crop_horizontal_limit || sps->crop_bottom >= crop_vertical_limit){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "brainfart cropping not supported, cropping disabled (right: %d, bottom: %d)\n", sps->crop_right, sps->crop_bottom); ++ /* It is very unlikely that partial cropping will make anybody happy. ++ * Not cropping at all fixes for example playback of Sisvel 3D streams ++ * in applications supporting Sisvel 3D. */ ++ sps->crop_left = ++ sps->crop_right = ++ sps->crop_top = ++ sps->crop_bottom= 0; + } + }else{ + sps->crop_left = +@@ -393,7 +455,7 @@ + sps->sar.den= 1; + + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ +- av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d\n", ++ av_log(h->s.avctx, AV_LOG_DEBUG, "sps:%u profile:%d/%d poc:%d ref:%d %dx%d %s %s crop:%d/%d/%d/%d %s %s %d/%d b%d\n", + sps_id, sps->profile_idc, sps->level_idc, + sps->poc_type, + sps->ref_frame_count, +@@ -405,7 +467,8 @@ + sps->vui_parameters_present_flag ? "VUI" : "", + ((const char*[]){"Gray","420","422","444"})[sps->chroma_format_idc], + sps->timing_info_present_flag ? sps->num_units_in_tick : 0, +- sps->timing_info_present_flag ? sps->time_scale : 0 ++ sps->timing_info_present_flag ? sps->time_scale : 0, ++ sps->bit_depth_luma + ); + } + +@@ -419,17 +482,35 @@ + } + + static void +-build_qp_table(PPS *pps, int t, int index) ++build_qp_table(PPS *pps, int t, int index, const int depth) + { + int i; +- for(i = 0; i < 52; i++) +- pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[av_clip(i + index, 0, 51)]; ++ const int max_qp = 51 + 6*(depth-8); ++ for(i = 0; i < max_qp+1; i++) ++ pps->chroma_qp_table[t][i] = ff_h264_chroma_qp[depth-8][av_clip(i + index, 0, max_qp)]; ++} ++ ++static int more_rbsp_data_in_pps(H264Context *h, PPS *pps) ++{ ++ const SPS *sps = h->sps_buffers[pps->sps_id]; ++ int profile_idc = sps->profile_idc; ++ ++ if ((profile_idc == 66 || profile_idc == 77 || ++ profile_idc == 88) && (sps->constraint_set_flags & 7)) { ++ av_log(h->s.avctx, AV_LOG_VERBOSE, ++ "Current profile doesn't provide more RBSP data in PPS, skipping\n"); ++ return 0; ++ } ++ ++ return 1; + } + + int ff_h264_decode_picture_parameter_set(H264Context *h, int bit_length){ + MpegEncContext * const s = &h->s; + unsigned int pps_id= get_ue_golomb(&s->gb); + PPS *pps; ++ const int qp_bd_offset = 6*(h->sps.bit_depth_luma-8); ++ int bits_left; + + if(pps_id >= MAX_PPS_COUNT) { + av_log(h->s.avctx, AV_LOG_ERROR, "pps_id (%d) out of range\n", pps_id); +@@ -494,8 +575,8 @@ + + pps->weighted_pred= get_bits1(&s->gb); + pps->weighted_bipred_idc= get_bits(&s->gb, 2); +- pps->init_qp= get_se_golomb(&s->gb) + 26; +- pps->init_qs= get_se_golomb(&s->gb) + 26; ++ pps->init_qp= get_se_golomb(&s->gb) + 26 + qp_bd_offset; ++ pps->init_qs= get_se_golomb(&s->gb) + 26 + qp_bd_offset; + pps->chroma_qp_index_offset[0]= get_se_golomb(&s->gb); + pps->deblocking_filter_parameters_present= get_bits1(&s->gb); + pps->constrained_intra_pred= get_bits1(&s->gb); +@@ -506,7 +587,8 @@ + memcpy(pps->scaling_matrix4, h->sps_buffers[pps->sps_id]->scaling_matrix4, sizeof(pps->scaling_matrix4)); + memcpy(pps->scaling_matrix8, h->sps_buffers[pps->sps_id]->scaling_matrix8, sizeof(pps->scaling_matrix8)); + +- if(get_bits_count(&s->gb) < bit_length){ ++ bits_left = bit_length - get_bits_count(&s->gb); ++ if(bits_left > 0 && more_rbsp_data_in_pps(h, pps)){ + pps->transform_8x8_mode= get_bits1(&s->gb); + decode_scaling_matrices(h, h->sps_buffers[pps->sps_id], pps, 0, pps->scaling_matrix4, pps->scaling_matrix8); + pps->chroma_qp_index_offset[1]= get_se_golomb(&s->gb); //second_chroma_qp_index_offset +@@ -514,8 +596,8 @@ + pps->chroma_qp_index_offset[1]= pps->chroma_qp_index_offset[0]; + } + +- build_qp_table(pps, 0, pps->chroma_qp_index_offset[0]); +- build_qp_table(pps, 1, pps->chroma_qp_index_offset[1]); ++ build_qp_table(pps, 0, pps->chroma_qp_index_offset[0], h->sps.bit_depth_luma); ++ build_qp_table(pps, 1, pps->chroma_qp_index_offset[1], h->sps.bit_depth_luma); + if(pps->chroma_qp_index_offset[0] != pps->chroma_qp_index_offset[1]) + pps->chroma_qp_diff= 1; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_refs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_refs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_refs.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_refs.c 2012-05-14 14:08:53.820329637 +0200 +@@ -25,6 +25,7 @@ + * @author Michael Niedermayer + */ + ++#include "libavutil/avassert.h" + #include "internal.h" + #include "dsputil.h" + #include "avcodec.h" +@@ -39,16 +40,16 @@ + int i; + for (i = 0; i < 4; ++i) { + if (parity == PICT_BOTTOM_FIELD) +- pic->data[i] += pic->linesize[i]; +- pic->reference = parity; +- pic->linesize[i] *= 2; ++ pic->f.data[i] += pic->f.linesize[i]; ++ pic->f.reference = parity; ++ pic->f.linesize[i] *= 2; + } + pic->poc= pic->field_poc[parity == PICT_BOTTOM_FIELD]; + } + + static int split_field_copy(Picture *dest, Picture *src, + int parity, int id_add){ +- int match = !!(src->reference & parity); ++ int match = !!(src->f.reference & parity); + + if (match) { + *dest = *src; +@@ -67,9 +68,9 @@ + int index=0; + + while(i[0]reference & sel))) ++ while (i[0] < len && !(in[ i[0] ] && (in[ i[0] ]->f.reference & sel))) + i[0]++; +- while(i[1]reference & (sel^3)))) ++ while (i[1] < len && !(in[ i[1] ] && (in[ i[1] ]->f.reference & (sel^3)))) + i[1]++; + if(i[0] < len){ + in[ i[0] ]->pic_id= is_long ? i[0] : in[ i[0] ]->frame_num; +@@ -109,7 +110,7 @@ + MpegEncContext * const s = &h->s; + int i, len; + +- if(h->slice_type_nos==FF_B_TYPE){ ++ if(h->slice_type_nos==AV_PICTURE_TYPE_B){ + Picture *sorted[32]; + int cur_poc, list; + int lens[2]; +@@ -133,7 +134,7 @@ + } + + if(lens[0] == lens[1] && lens[1] > 1){ +- for(i=0; h->default_ref_list[0][i].data[0] == h->default_ref_list[1][i].data[0] && idefault_ref_list[0][i].f.data[0] == h->default_ref_list[1][i].f.data[0] && i < lens[0]; i++); + if(i == lens[0]) + FFSWAP(Picture, h->default_ref_list[1][0], h->default_ref_list[1][1]); + } +@@ -148,7 +149,7 @@ + for (i=0; iref_count[0]; i++) { + tprintf(h->s.avctx, "List0: %s fn:%d 0x%p\n", (h->default_ref_list[0][i].long_ref ? "LT" : "ST"), h->default_ref_list[0][i].pic_id, h->default_ref_list[0][i].data[0]); + } +- if(h->slice_type_nos==FF_B_TYPE){ ++ if(h->slice_type_nos==AV_PICTURE_TYPE_B){ + for (i=0; iref_count[1]; i++) { + tprintf(h->s.avctx, "List1: %s fn:%d 0x%p\n", (h->default_ref_list[1][i].long_ref ? "LT" : "ST"), h->default_ref_list[1][i].pic_id, h->default_ref_list[1][i].data[0]); + } +@@ -229,11 +230,11 @@ + + for(i= h->short_ref_count-1; i>=0; i--){ + ref = h->short_ref[i]; +- assert(ref->reference); ++ assert(ref->f.reference); + assert(!ref->long_ref); + if( + ref->frame_num == frame_num && +- (ref->reference & pic_structure) ++ (ref->f.reference & pic_structure) + ) + break; + } +@@ -250,8 +251,8 @@ + return -1; + } + ref = h->long_ref[long_idx]; +- assert(!(ref && !ref->reference)); +- if(ref && (ref->reference & pic_structure)){ ++ assert(!(ref && !ref->f.reference)); ++ if (ref && (ref->f.reference & pic_structure)) { + ref->pic_id= pic_id; + assert(ref->long_ref); + i=0; +@@ -285,9 +286,9 @@ + } + for(list=0; listlist_count; list++){ + for(index= 0; index < h->ref_count[list]; index++){ +- if(!h->ref_list[list][index].data[0]){ ++ if (!h->ref_list[list][index].f.data[0]) { + av_log(h->s.avctx, AV_LOG_ERROR, "Missing reference picture\n"); +- if(h->default_ref_list[list][0].data[0]) ++ if (h->default_ref_list[list][0].f.data[0]) + h->ref_list[list][index]= h->default_ref_list[list][0]; + else + return -1; +@@ -300,19 +301,19 @@ + + void ff_h264_fill_mbaff_ref_list(H264Context *h){ + int list, i, j; +- for(list=0; list<2; list++){ //FIXME try list_count ++ for(list=0; listlist_count; list++){ + for(i=0; iref_count[list]; i++){ + Picture *frame = &h->ref_list[list][i]; + Picture *field = &h->ref_list[list][16+2*i]; + field[0] = *frame; + for(j=0; j<3; j++) +- field[0].linesize[j] <<= 1; +- field[0].reference = PICT_TOP_FIELD; ++ field[0].f.linesize[j] <<= 1; ++ field[0].f.reference = PICT_TOP_FIELD; + field[0].poc= field[0].field_poc[0]; + field[1] = field[0]; + for(j=0; j<3; j++) +- field[1].data[j] += frame->linesize[j]; +- field[1].reference = PICT_BOTTOM_FIELD; ++ field[1].f.data[j] += frame->f.linesize[j]; ++ field[1].f.reference = PICT_BOTTOM_FIELD; + field[1].poc= field[1].field_poc[1]; + + h->luma_weight[16+2*i][list][0] = h->luma_weight[16+2*i+1][list][0] = h->luma_weight[i][list][0]; +@@ -338,12 +339,12 @@ + */ + static inline int unreference_pic(H264Context *h, Picture *pic, int refmask){ + int i; +- if (pic->reference &= refmask) { ++ if (pic->f.reference &= refmask) { + return 0; + } else { + for(i = 0; h->delayed_pic[i]; i++) + if(pic == h->delayed_pic[i]){ +- pic->reference=DELAYED_PIC_REF; ++ pic->f.reference = DELAYED_PIC_REF; + break; + } + return 1; +@@ -453,7 +454,8 @@ + av_log(h->s.avctx, AV_LOG_DEBUG, "short term list:\n"); + for(i=0; ishort_ref_count; i++){ + Picture *pic= h->short_ref[i]; +- av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); ++ av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", ++ i, pic->frame_num, pic->poc, pic->f.data[0]); + } + } + } +@@ -468,7 +470,8 @@ + for(i = 0; i < 16; i++){ + Picture *pic= h->long_ref[i]; + if (pic) { +- av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", i, pic->frame_num, pic->poc, pic->data[0]); ++ av_log(h->s.avctx, AV_LOG_DEBUG, "%d fn:%d poc:%d %p\n", ++ i, pic->frame_num, pic->poc, pic->f.data[0]); + } + } + } +@@ -476,11 +479,10 @@ + + void ff_generate_sliding_window_mmcos(H264Context *h) { + MpegEncContext * const s = &h->s; +- assert(h->long_ref_count + h->short_ref_count <= h->sps.ref_frame_count); + + h->mmco_index= 0; +- if(h->short_ref_count && h->long_ref_count + h->short_ref_count == h->sps.ref_frame_count && +- !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->reference)) { ++ if(h->short_ref_count && h->long_ref_count + h->short_ref_count >= h->sps.ref_frame_count && ++ !(FIELD_PICTURE && !s->first_field && s->current_picture_ptr->f.reference)) { + h->mmco[0].opcode= MMCO_SHORT2UNUSED; + h->mmco[0].short_pic_num= h->short_ref[ h->short_ref_count - 1 ]->frame_num; + h->mmco_index= 1; +@@ -496,7 +498,7 @@ + int ff_h264_execute_ref_pic_marking(H264Context *h, MMCO *mmco, int mmco_count){ + MpegEncContext * const s = &h->s; + int i, av_uninit(j); +- int current_ref_assigned=0; ++ int current_ref_assigned=0, err=0; + Picture *av_uninit(pic); + + if((s->avctx->debug&FF_DEBUG_MMCO) && mmco_count==0) +@@ -513,8 +515,10 @@ + pic = find_short(h, frame_num, &j); + if(!pic){ + if(mmco[i].opcode != MMCO_SHORT2LONG || !h->long_ref[mmco[i].long_arg] +- || h->long_ref[mmco[i].long_arg]->frame_num != frame_num) +- av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); ++ || h->long_ref[mmco[i].long_arg]->frame_num != frame_num) { ++ av_log(h->s.avctx, AV_LOG_ERROR, "mmco: unref short failure\n"); ++ err = AVERROR_INVALIDDATA; ++ } + continue; + } + } +@@ -561,7 +565,7 @@ + h->long_ref_count++; + } + +- s->current_picture_ptr->reference |= s->picture_structure; ++ s->current_picture_ptr->f.reference |= s->picture_structure; + current_ref_assigned=1; + break; + case MMCO_SET_MAX_LONG: +@@ -578,14 +582,12 @@ + for(j = 0; j < 16; j++) { + remove_long(h, j, 0); + } +- s->current_picture_ptr->poc= +- s->current_picture_ptr->field_poc[0]= +- s->current_picture_ptr->field_poc[1]= +- h->poc_lsb= +- h->poc_msb= + h->frame_num= + s->current_picture_ptr->frame_num= 0; ++ h->mmco_reset = 1; + s->current_picture_ptr->mmco_reset=1; ++ for (j = 0; j < MAX_DELAYED_PIC_COUNT; j++) ++ h->last_pocs[j] = INT_MIN; + break; + default: assert(0); + } +@@ -600,16 +602,18 @@ + */ + if (h->short_ref_count && h->short_ref[0] == s->current_picture_ptr) { + /* Just mark the second field valid */ +- s->current_picture_ptr->reference = PICT_FRAME; ++ s->current_picture_ptr->f.reference = PICT_FRAME; + } else if (s->current_picture_ptr->long_ref) { + av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term reference " + "assignment for second field " + "in complementary field pair " + "(first field is long term)\n"); ++ err = AVERROR_INVALIDDATA; + } else { + pic= remove_short(h, s->current_picture_ptr->frame_num, 0); + if(pic){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal short term buffer state detected\n"); ++ err = AVERROR_INVALIDDATA; + } + + if(h->short_ref_count) +@@ -617,19 +621,21 @@ + + h->short_ref[0]= s->current_picture_ptr; + h->short_ref_count++; +- s->current_picture_ptr->reference |= s->picture_structure; ++ s->current_picture_ptr->f.reference |= s->picture_structure; + } + } + +- if (h->long_ref_count + h->short_ref_count > h->sps.ref_frame_count){ ++ if (h->long_ref_count + h->short_ref_count > FFMAX(h->sps.ref_frame_count, 1)){ + + /* We have too many reference frames, probably due to corrupted + * stream. Need to discard one frame. Prevents overrun of the + * short_ref and long_ref buffers. + */ + av_log(h->s.avctx, AV_LOG_ERROR, +- "number of reference frames exceeds max (probably " +- "corrupt input), discarding one\n"); ++ "number of reference frames (%d+%d) exceeds max (%d; probably " ++ "corrupt input), discarding one\n", ++ h->long_ref_count, h->short_ref_count, h->sps.ref_frame_count); ++ err = AVERROR_INVALIDDATA; + + if (h->long_ref_count && !h->short_ref_count) { + for (i = 0; i < 16; ++i) +@@ -646,7 +652,12 @@ + + print_short_term(h); + print_long_term(h); +- return 0; ++ ++ if(err >= 0 && h->long_ref_count==0 && h->short_ref_count<=2 && h->pps.ref_count[0]<=1 + (s->picture_structure != PICT_FRAME) && s->current_picture_ptr->f.pict_type == AV_PICTURE_TYPE_I){ ++ s->current_picture_ptr->sync |= 1; ++ } ++ ++ return (h->s.avctx->err_recognition & AV_EF_EXPLODE) ? err : 0; + } + + int ff_h264_decode_ref_pic_marking(H264Context *h, GetBitContext *gb){ +@@ -676,7 +687,7 @@ + } + if(opcode==MMCO_SHORT2LONG || opcode==MMCO_LONG2UNUSED || opcode==MMCO_LONG || opcode==MMCO_SET_MAX_LONG){ + unsigned int long_arg= get_ue_golomb_31(gb); +- if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ ++ if(long_arg >= 32 || (long_arg >= 16 && !(opcode == MMCO_SET_MAX_LONG && long_arg == 16) && !(opcode == MMCO_LONG2UNUSED && FIELD_PICTURE))){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal long ref in memory management control operation %d\n", opcode); + return -1; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_sei.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_sei.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/h264_sei.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/h264_sei.c 2012-05-14 14:08:53.820329637 +0200 +@@ -164,19 +164,26 @@ + int ff_h264_decode_sei(H264Context *h){ + MpegEncContext * const s = &h->s; + +- while(get_bits_count(&s->gb) + 16 < s->gb.size_in_bits){ ++ while (get_bits_left(&s->gb) > 16) { + int size, type; + + type=0; + do{ ++ if (get_bits_left(&s->gb) < 8) ++ return -1; + type+= show_bits(&s->gb, 8); + }while(get_bits(&s->gb, 8) == 255); + + size=0; + do{ ++ if (get_bits_left(&s->gb) < 8) ++ return -1; + size+= show_bits(&s->gb, 8); + }while(get_bits(&s->gb, 8) == 255); + ++ if(s->avctx->debug&FF_DEBUG_STARTCODE) ++ av_log(h->s.avctx, AV_LOG_DEBUG, "SEI %d len:%d\n", type, size); ++ + switch(type){ + case SEI_TYPE_PIC_TIMING: // Picture timing SEI + if(decode_picture_timing(h) < 0) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffman.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffman.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffman.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffman.c 2012-05-14 14:08:53.835329938 +0200 +@@ -1,6 +1,4 @@ +-/** +- * @file +- * huffman tree builder and VLC generator ++/* + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. +@@ -20,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * huffman tree builder and VLC generator ++ */ ++ + #include "avcodec.h" + #include "get_bits.h" + #include "huffman.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffman.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffman.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffman.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffman.h 2012-05-14 14:08:53.835329938 +0200 +@@ -1,6 +1,4 @@ +-/** +- * @file +- * huffman tree builder and VLC generator ++/* + * Copyright (C) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -20,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * huffman tree builder and VLC generator ++ */ ++ + #ifndef AVCODEC_HUFFMAN_H + #define AVCODEC_HUFFMAN_H + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffyuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffyuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/huffyuv.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/huffyuv.c 2012-05-14 14:08:53.838330000 +0200 +@@ -32,6 +32,7 @@ + #include "get_bits.h" + #include "put_bits.h" + #include "dsputil.h" ++#include "thread.h" + + #define VLC_BITS 11 + +@@ -81,13 +82,15 @@ + DSPContext dsp; + }HYuvContext; + +-static const unsigned char classic_shift_luma[] = { ++#define classic_shift_luma_table_size 42 ++static const unsigned char classic_shift_luma[classic_shift_luma_table_size + FF_INPUT_BUFFER_PADDING_SIZE] = { + 34,36,35,69,135,232,9,16,10,24,11,23,12,16,13,10,14,8,15,8, + 16,8,17,20,16,10,207,206,205,236,11,8,10,21,9,23,8,8,199,70, + 69,68, 0 + }; + +-static const unsigned char classic_shift_chroma[] = { ++#define classic_shift_chroma_table_size 59 ++static const unsigned char classic_shift_chroma[classic_shift_chroma_table_size + FF_INPUT_BUFFER_PADDING_SIZE] = { + 66,36,37,38,39,40,41,75,76,77,110,239,144,81,82,83,84,85,118,183, + 56,57,88,89,56,89,154,57,58,57,26,141,57,56,58,57,58,57,184,119, + 214,245,116,83,82,49,80,79,78,77,44,75,41,40,39,38,37,36,34, 0 +@@ -151,27 +154,55 @@ + } + } + +-static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){ ++static inline void sub_left_prediction_bgr32(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue, int *alpha){ + int i; +- int r,g,b; ++ int r,g,b,a; + r= *red; + g= *green; + b= *blue; ++ a= *alpha; + for(i=0; idsp.diff_bytes(dst+16, src+16, src+12, w*4-16); + *red= src[(w-1)*4+R]; + *green= src[(w-1)*4+G]; + *blue= src[(w-1)*4+B]; ++ *alpha= src[(w-1)*4+A]; ++} ++ ++static inline void sub_left_prediction_rgb24(HYuvContext *s, uint8_t *dst, uint8_t *src, int w, int *red, int *green, int *blue){ ++ int i; ++ int r,g,b; ++ r= *red; ++ g= *green; ++ b= *blue; ++ for(i=0; idsp.diff_bytes(dst+48, src+48, src+48-3, w*3-48); ++ *red= src[(w-1)*3+0]; ++ *green= src[(w-1)*3+1]; ++ *blue= src[(w-1)*3+2]; + } + + static int read_len_table(uint8_t *dst, GetBitContext *gb){ +@@ -183,7 +214,7 @@ + if(repeat==0) + repeat= get_bits(gb, 8); + //printf("%d %d\n", val, repeat); +- if(i+repeat > 256) { ++ if(i+repeat > 256 || get_bits_left(gb) < 0) { + av_log(NULL, AV_LOG_ERROR, "Error reading huffman table\n"); + return -1; + } +@@ -351,11 +382,6 @@ + if(generate_bits_table(s->bits[i], s->len[i])<0){ + return -1; + } +-#if 0 +-for(j=0; j<256; j++){ +-printf("%6X, %2d, %3d\n", s->bits[i][j], s->len[i][j], j); +-} +-#endif + free_vlc(&s->vlc[i]); + init_vlc(&s->vlc[i], VLC_BITS, 256, s->len[i], 1, 1, s->bits[i], 4, 4, 0); + } +@@ -370,10 +396,10 @@ + GetBitContext gb; + int i; + +- init_get_bits(&gb, classic_shift_luma, sizeof(classic_shift_luma)*8); ++ init_get_bits(&gb, classic_shift_luma, classic_shift_luma_table_size*8); + if(read_len_table(s->len[0], &gb)<0) + return -1; +- init_get_bits(&gb, classic_shift_chroma, sizeof(classic_shift_chroma)*8); ++ init_get_bits(&gb, classic_shift_chroma, classic_shift_chroma_table_size*8); + if(read_len_table(s->len[1], &gb)<0) + return -1; + +@@ -437,6 +463,7 @@ + memset(s->vlc, 0, 3*sizeof(VLC)); + + avctx->coded_frame= &s->picture; ++ avcodec_get_frame_defaults(&s->picture); + s->interlaced= s->height > 288; + + s->bgr32=1; +@@ -518,7 +545,7 @@ + } + break; + default: +- assert(0); ++ return AVERROR_INVALIDDATA; + } + + alloc_temp(s); +@@ -527,6 +554,28 @@ + + return 0; + } ++ ++static av_cold int decode_init_thread_copy(AVCodecContext *avctx) ++{ ++ HYuvContext *s = avctx->priv_data; ++ int i; ++ ++ avctx->coded_frame= &s->picture; ++ alloc_temp(s); ++ ++ for (i = 0; i < 6; i++) ++ s->vlc[i].table = NULL; ++ ++ if(s->version==2){ ++ if(read_huffman_tables(s, ((uint8_t*)avctx->extradata)+4, avctx->extradata_size) < 0) ++ return -1; ++ }else{ ++ if(read_old_huffman_tables(s) < 0) ++ return -1; ++ } ++ ++ return 0; ++} + #endif /* CONFIG_HUFFYUV_DECODER || CONFIG_FFVHUFF_DECODER */ + + #if CONFIG_HUFFYUV_ENCODER || CONFIG_FFVHUFF_ENCODER +@@ -574,6 +623,9 @@ + s->bitstream_bpp= 16; + break; + case PIX_FMT_RGB32: ++ s->bitstream_bpp= 32; ++ break; ++ case PIX_FMT_RGB24: + s->bitstream_bpp= 24; + break; + default: +@@ -700,7 +752,7 @@ + count/=2; + + if(count >= (get_bits_left(&s->gb))/(31*4)){ +- for(i=0; igb) < s->gb.size_in_bits; i++){ ++ for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { + READ_2PIX(s->temp[0][2*i ], s->temp[1][i], 1); + READ_2PIX(s->temp[0][2*i+1], s->temp[2][i], 2); + } +@@ -718,7 +770,7 @@ + count/=2; + + if(count >= (get_bits_left(&s->gb))/(31*2)){ +- for(i=0; igb) < s->gb.size_in_bits; i++){ ++ for (i = 0; i < count && get_bits_left(&s->gb) > 0; i++) { + READ_2PIX(s->temp[0][2*i ], s->temp[0][2*i+1], 0); + } + }else{ +@@ -860,26 +912,29 @@ + } + } + +-static int encode_bgr_bitstream(HYuvContext *s, int count){ ++static inline int encode_bgra_bitstream(HYuvContext *s, int count, int planes){ + int i; + +- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 3*4*count){ ++ if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < 4*planes*count){ + av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); + return -1; + } + + #define LOAD3\ +- int g= s->temp[0][4*i+G];\ +- int b= (s->temp[0][4*i+B] - g) & 0xff;\ +- int r= (s->temp[0][4*i+R] - g) & 0xff; ++ int g= s->temp[0][planes==3 ? 3*i+1 : 4*i+G];\ ++ int b= (s->temp[0][planes==3 ? 3*i+2 : 4*i+B] - g) & 0xff;\ ++ int r= (s->temp[0][planes==3 ? 3*i+0 : 4*i+R] - g) & 0xff;\ ++ int a= s->temp[0][planes*i+A]; + #define STAT3\ + s->stats[0][b]++;\ + s->stats[1][g]++;\ +- s->stats[2][r]++; ++ s->stats[2][r]++;\ ++ if(planes==4) s->stats[2][a]++; + #define WRITE3\ + put_bits(&s->pb, s->len[1][g], s->bits[1][g]);\ + put_bits(&s->pb, s->len[0][b], s->bits[0][b]);\ +- put_bits(&s->pb, s->len[2][r], s->bits[2][r]); ++ put_bits(&s->pb, s->len[2][r], s->bits[2][r]);\ ++ if(planes==4) put_bits(&s->pb, s->len[2][a], s->bits[2][a]); + + if((s->flags&CODEC_FLAG_PASS1) && (s->avctx->flags2&CODEC_FLAG2_NO_OUTPUT)){ + for(i=0; iavctx->draw_horiz_band==NULL) + return; +@@ -921,7 +976,8 @@ + offset[0] = s->picture.linesize[0]*y; + offset[1] = s->picture.linesize[1]*cy; + offset[2] = s->picture.linesize[2]*cy; +- offset[3] = 0; ++ for (i = 3; i < AV_NUM_DATA_POINTERS; i++) ++ offset[i] = 0; + emms_c(); + + s->avctx->draw_horiz_band(s->avctx, &s->picture, offset, y, 3, h); +@@ -950,10 +1006,10 @@ + s->dsp.bswap_buf((uint32_t*)s->bitstream_buffer, (const uint32_t*)buf, buf_size/4); + + if(p->data[0]) +- avctx->release_buffer(avctx, p); ++ ff_thread_release_buffer(avctx, p); + + p->reference= 0; +- if(avctx->get_buffer(avctx, p) < 0){ ++ if(ff_thread_get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +@@ -1220,7 +1276,7 @@ + int i, j, size=0; + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + if(s->context){ +@@ -1347,25 +1403,50 @@ + const int stride = -p->linesize[0]; + const int fake_stride = -fake_ystride; + int y; +- int leftr, leftg, leftb; ++ int leftr, leftg, leftb, lefta; + ++ put_bits(&s->pb, 8, lefta= data[A]); + put_bits(&s->pb, 8, leftr= data[R]); + put_bits(&s->pb, 8, leftg= data[G]); + put_bits(&s->pb, 8, leftb= data[B]); +- put_bits(&s->pb, 8, 0); + +- sub_left_prediction_bgr32(s, s->temp[0], data+4, width-1, &leftr, &leftg, &leftb); +- encode_bgr_bitstream(s, width-1); ++ sub_left_prediction_bgr32(s, s->temp[0], data+4, width-1, &leftr, &leftg, &leftb, &lefta); ++ encode_bgra_bitstream(s, width-1, 4); + + for(y=1; yheight; y++){ + uint8_t *dst = data + y*stride; + if(s->predictor == PLANE && s->interlaced < y){ + s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width*4); +- sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb); ++ sub_left_prediction_bgr32(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb, &lefta); ++ }else{ ++ sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb, &lefta); ++ } ++ encode_bgra_bitstream(s, width, 4); ++ } ++ }else if(avctx->pix_fmt == PIX_FMT_RGB24){ ++ uint8_t *data = p->data[0] + (height-1)*p->linesize[0]; ++ const int stride = -p->linesize[0]; ++ const int fake_stride = -fake_ystride; ++ int y; ++ int leftr, leftg, leftb; ++ ++ put_bits(&s->pb, 8, leftr= data[0]); ++ put_bits(&s->pb, 8, leftg= data[1]); ++ put_bits(&s->pb, 8, leftb= data[2]); ++ put_bits(&s->pb, 8, 0); ++ ++ sub_left_prediction_rgb24(s, s->temp[0], data+3, width-1, &leftr, &leftg, &leftb); ++ encode_bgra_bitstream(s, width-1, 3); ++ ++ for(y=1; yheight; y++){ ++ uint8_t *dst = data + y*stride; ++ if(s->predictor == PLANE && s->interlaced < y){ ++ s->dsp.diff_bytes(s->temp[1], dst, dst - fake_stride, width*3); ++ sub_left_prediction_rgb24(s, s->temp[0], s->temp[1], width, &leftr, &leftg, &leftb); + }else{ +- sub_left_prediction_bgr32(s, s->temp[0], dst, width, &leftr, &leftg, &leftb); ++ sub_left_prediction_rgb24(s, s->temp[0], dst, width, &leftr, &leftg, &leftb); + } +- encode_bgr_bitstream(s, width); ++ encode_bgra_bitstream(s, width, 3); + } + }else{ + av_log(avctx, AV_LOG_ERROR, "Format not supported!\n"); +@@ -1417,60 +1498,58 @@ + + #if CONFIG_HUFFYUV_DECODER + AVCodec ff_huffyuv_decoder = { +- "huffyuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_HUFFYUV, +- sizeof(HYuvContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, +- NULL, ++ .name = "huffyuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_HUFFYUV, ++ .priv_data_size = sizeof(HYuvContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS, ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), + .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), + }; + #endif + + #if CONFIG_FFVHUFF_DECODER + AVCodec ff_ffvhuff_decoder = { +- "ffvhuff", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FFVHUFF, +- sizeof(HYuvContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, +- NULL, ++ .name = "ffvhuff", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FFVHUFF, ++ .priv_data_size = sizeof(HYuvContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS, ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(decode_init_thread_copy), + .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"), + }; + #endif + + #if CONFIG_HUFFYUV_ENCODER + AVCodec ff_huffyuv_encoder = { +- "huffyuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_HUFFYUV, +- sizeof(HYuvContext), +- encode_init, +- encode_frame, +- encode_end, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE}, ++ .name = "huffyuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_HUFFYUV, ++ .priv_data_size = sizeof(HYuvContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("Huffyuv / HuffYUV"), + }; + #endif + + #if CONFIG_FFVHUFF_ENCODER + AVCodec ff_ffvhuff_encoder = { +- "ffvhuff", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_FFVHUFF, +- sizeof(HYuvContext), +- encode_init, +- encode_frame, +- encode_end, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB32, PIX_FMT_NONE}, ++ .name = "ffvhuff", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_FFVHUFF, ++ .priv_data_size = sizeof(HYuvContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("Huffyuv FFmpeg variant"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/idcinvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/idcinvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/idcinvideo.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/idcinvideo.c 2012-05-14 14:08:53.839330020 +0200 +@@ -36,7 +36,7 @@ + * a little more compression by exploiting the fact that adjacent pixels + * tend to be similar. + * +- * Note that this decoder could use ffmpeg's optimized VLC facilities ++ * Note that this decoder could use libavcodec's optimized VLC facilities + * rather than naive, tree-based Huffman decoding. However, there are 256 + * Huffman tables. Plus, the VLC bit coding order is right -> left instead + * or left -> right, so all of the bits would have to be reversed. Further, +@@ -72,6 +72,7 @@ + hnode huff_nodes[256][HUF_TOKENS*2]; + int num_huff_nodes[256]; + ++ uint32_t pal[256]; + } IdcinContext; + + /* +@@ -165,6 +166,7 @@ + huff_build_tree(s, i); + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -213,7 +215,7 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + IdcinContext *s = avctx->priv_data; +- AVPaletteControl *palette_control = avctx->palctrl; ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); + + s->buf = buf; + s->size = buf_size; +@@ -228,13 +230,12 @@ + + idcin_decode_vlcs(s); + +- /* make the palette available on the way out */ +- memcpy(s->frame.data[1], palette_control->palette, PALETTE_COUNT * 4); +- /* If palette changed inform application*/ +- if (palette_control->palette_changed) { +- palette_control->palette_changed = 0; ++ if (pal) { + s->frame.palette_has_changed = 1; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); + } ++ /* make the palette available on the way out */ ++ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; +@@ -254,15 +255,14 @@ + } + + AVCodec ff_idcin_decoder = { +- "idcinvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_IDCIN, +- sizeof(IdcinContext), +- idcin_decode_init, +- NULL, +- idcin_decode_end, +- idcin_decode_frame, +- CODEC_CAP_DR1, ++ .name = "idcinvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_IDCIN, ++ .priv_data_size = sizeof(IdcinContext), ++ .init = idcin_decode_init, ++ .close = idcin_decode_end, ++ .decode = idcin_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("id Quake II CIN video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/iff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/iff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/iff.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/iff.c 2012-05-14 14:08:53.841330060 +0200 +@@ -25,15 +25,33 @@ + * IFF PBM/ILBM bitmap decoder + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "bytestream.h" + #include "avcodec.h" + #include "get_bits.h" + ++// TODO: masking bits ++typedef enum { ++ MASK_NONE, ++ MASK_HAS_MASK, ++ MASK_HAS_TRANSPARENT_COLOR, ++ MASK_LASSO ++} mask_type; ++ + typedef struct { + AVFrame frame; + int planesize; + uint8_t * planebuf; ++ uint8_t * ham_buf; ///< temporary buffer for planar to chunky conversation ++ uint32_t *ham_palbuf; ///< HAM decode table ++ uint32_t *mask_buf; ///< temporary buffer for palette indices ++ uint32_t *mask_palbuf; ///< masking palette table ++ unsigned compression; ///< delta compression method used ++ unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM) ++ unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise) ++ unsigned flags; ///< 1 for EHB, 0 is no extra half darkening ++ unsigned transparency; ///< TODO: transparency color index in palette ++ unsigned masking; ///< TODO: masking method used + int init; // 1 if buffer and palette data already initialized, 0 otherwise + } IffContext; + +@@ -121,7 +139,10 @@ + */ + static int ff_cmap_read_palette(AVCodecContext *avctx, uint32_t *pal) + { ++ IffContext *s = avctx->priv_data; + int count, i; ++ const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata); ++ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata); + + if (avctx->bits_per_coded_sample > 8) { + av_log(avctx, AV_LOG_ERROR, "bit_per_coded_sample > 8 not supported\n"); +@@ -130,10 +151,15 @@ + + count = 1 << avctx->bits_per_coded_sample; + // If extradata is smaller than actually needed, fill the remaining with black. +- count = FFMIN(avctx->extradata_size / 3, count); ++ count = FFMIN(palette_size / 3, count); + if (count) { + for (i=0; i < count; i++) { +- pal[i] = 0xFF000000 | AV_RB24( avctx->extradata + i*3 ); ++ pal[i] = 0xFF000000 | AV_RB24(palette + i*3); ++ } ++ if (s->flags && count >= 32) { // EHB ++ for (i = 0; i < 32; i++) ++ pal[i + 32] = 0xFF000000 | (AV_RB24(palette + i*3) & 0xFEFEFE) >> 1; ++ count = FFMAX(count, 64); + } + } else { // Create gray-scale color palette for bps < 8 + count = 1 << avctx->bits_per_coded_sample; +@@ -142,6 +168,141 @@ + pal[i] = 0xFF000000 | gray2rgb((i * 255) >> avctx->bits_per_coded_sample); + } + } ++ if (s->masking == MASK_HAS_MASK) { ++ memcpy(pal + (1 << avctx->bits_per_coded_sample), pal, count * 4); ++ for (i = 0; i < count; i++) ++ pal[i] &= 0xFFFFFF; ++ } else if (s->masking == MASK_HAS_TRANSPARENT_COLOR && ++ s->transparency < 1 << avctx->bits_per_coded_sample) ++ pal[s->transparency] &= 0xFFFFFF; ++ return 0; ++} ++ ++/** ++ * Extracts the IFF extra context and updates internal ++ * decoder structures. ++ * ++ * @param avctx the AVCodecContext where to extract extra context to ++ * @param avpkt the AVPacket to extract extra context from or NULL to use avctx ++ * @return 0 in case of success, a negative error code otherwise ++ */ ++static int extract_header(AVCodecContext *const avctx, ++ const AVPacket *const avpkt) { ++ const uint8_t *buf; ++ unsigned buf_size; ++ IffContext *s = avctx->priv_data; ++ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata); ++ ++ if (avpkt) { ++ int image_size; ++ if (avpkt->size < 2) ++ return AVERROR_INVALIDDATA; ++ image_size = avpkt->size - AV_RB16(avpkt->data); ++ buf = avpkt->data; ++ buf_size = bytestream_get_be16(&buf); ++ if (buf_size <= 1 || image_size <= 1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid image size received: %u -> image data offset: %d\n", ++ buf_size, image_size); ++ return AVERROR_INVALIDDATA; ++ } ++ } else { ++ if (avctx->extradata_size < 2) ++ return AVERROR_INVALIDDATA; ++ buf = avctx->extradata; ++ buf_size = bytestream_get_be16(&buf); ++ if (buf_size <= 1 || palette_size < 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid palette size received: %u -> palette data offset: %d\n", ++ buf_size, palette_size); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ ++ if (buf_size > 8) { ++ s->compression = bytestream_get_byte(&buf); ++ s->bpp = bytestream_get_byte(&buf); ++ s->ham = bytestream_get_byte(&buf); ++ s->flags = bytestream_get_byte(&buf); ++ s->transparency = bytestream_get_be16(&buf); ++ s->masking = bytestream_get_byte(&buf); ++ if (s->masking == MASK_HAS_MASK) { ++ if (s->bpp >= 8) { ++ avctx->pix_fmt = PIX_FMT_RGB32; ++ av_freep(&s->mask_buf); ++ av_freep(&s->mask_palbuf); ++ s->mask_buf = av_malloc((s->planesize * 32) + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!s->mask_buf) ++ return AVERROR(ENOMEM); ++ s->mask_palbuf = av_malloc((2 << s->bpp) * sizeof(uint32_t) + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!s->mask_palbuf) { ++ av_freep(&s->mask_buf); ++ return AVERROR(ENOMEM); ++ } ++ } ++ s->bpp++; ++ } else if (s->masking != MASK_NONE && s->masking != MASK_HAS_TRANSPARENT_COLOR) { ++ av_log(avctx, AV_LOG_ERROR, "Masking not supported\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ if (!s->bpp || s->bpp > 32) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of bitplanes: %u\n", s->bpp); ++ return AVERROR_INVALIDDATA; ++ } else if (s->ham >= 8) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of hold bits for HAM: %u\n", s->ham); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ av_freep(&s->ham_buf); ++ av_freep(&s->ham_palbuf); ++ ++ if (s->ham) { ++ int i, count = FFMIN(palette_size / 3, 1 << s->ham); ++ int ham_count; ++ const uint8_t *const palette = avctx->extradata + AV_RB16(avctx->extradata); ++ ++ s->ham_buf = av_malloc((s->planesize * 8) + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!s->ham_buf) ++ return AVERROR(ENOMEM); ++ ++ ham_count = 8 * (1 << s->ham); ++ s->ham_palbuf = av_malloc((ham_count << !!(s->masking == MASK_HAS_MASK)) * sizeof (uint32_t) + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!s->ham_palbuf) { ++ av_freep(&s->ham_buf); ++ return AVERROR(ENOMEM); ++ } ++ ++ if (count) { // HAM with color palette attached ++ // prefill with black and palette and set HAM take direct value mask to zero ++ memset(s->ham_palbuf, 0, (1 << s->ham) * 2 * sizeof (uint32_t)); ++ for (i=0; i < count; i++) { ++ s->ham_palbuf[i*2+1] = AV_RL24(palette + i*3); ++ } ++ count = 1 << s->ham; ++ } else { // HAM with grayscale color palette ++ count = 1 << s->ham; ++ for (i=0; i < count; i++) { ++ s->ham_palbuf[i*2] = 0; // take direct color value from palette ++ s->ham_palbuf[i*2+1] = av_le2ne32(gray2rgb((i * 255) >> s->ham)); ++ } ++ } ++ for (i=0; i < count; i++) { ++ uint32_t tmp = i << (8 - s->ham); ++ tmp |= tmp >> s->ham; ++ s->ham_palbuf[(i+count)*2] = 0x00FFFF; // just modify blue color component ++ s->ham_palbuf[(i+count*2)*2] = 0xFFFF00; // just modify red color component ++ s->ham_palbuf[(i+count*3)*2] = 0xFF00FF; // just modify green color component ++ s->ham_palbuf[(i+count)*2+1] = tmp << 16; ++ s->ham_palbuf[(i+count*2)*2+1] = tmp; ++ s->ham_palbuf[(i+count*3)*2+1] = tmp << 8; ++ } ++ if (s->masking == MASK_HAS_MASK) { ++ for (i = 0; i < ham_count; i++) ++ s->ham_palbuf[(1 << s->bpp) + i] = s->ham_palbuf[i] | 0xFF000000; ++ } ++ } ++ } ++ + return 0; + } + +@@ -151,9 +312,9 @@ + int err; + + if (avctx->bits_per_coded_sample <= 8) { +- avctx->pix_fmt = (avctx->bits_per_coded_sample < 8 || +- avctx->extradata_size) ? PIX_FMT_PAL8 +- : PIX_FMT_GRAY8; ++ int palette_size = avctx->extradata_size - AV_RB16(avctx->extradata); ++ avctx->pix_fmt = (avctx->bits_per_coded_sample < 8) || ++ (avctx->extradata_size >= 2 && palette_size) ? PIX_FMT_PAL8 : PIX_FMT_GRAY8; + } else if (avctx->bits_per_coded_sample <= 32) { + avctx->pix_fmt = PIX_FMT_BGR32; + } else { +@@ -167,7 +328,12 @@ + if (!s->planebuf) + return AVERROR(ENOMEM); + +- s->frame.reference = 1; ++ s->bpp = avctx->bits_per_coded_sample; ++ avcodec_get_frame_defaults(&s->frame); ++ ++ if ((err = extract_header(avctx, NULL)) < 0) ++ return err; ++ s->frame.reference = 3; + + return 0; + } +@@ -214,6 +380,47 @@ + } while (--buf_size); + } + ++#define DECODE_HAM_PLANE32(x) \ ++ first = buf[x] << 1; \ ++ second = buf[(x)+1] << 1; \ ++ delta &= pal[first++]; \ ++ delta |= pal[first]; \ ++ dst[x] = delta; \ ++ delta &= pal[second++]; \ ++ delta |= pal[second]; \ ++ dst[(x)+1] = delta ++ ++/** ++ * Converts one line of HAM6/8-encoded chunky buffer to 24bpp. ++ * ++ * @param dst the destination 24bpp buffer ++ * @param buf the source 8bpp chunky buffer ++ * @param pal the HAM decode table ++ * @param buf_size the plane size in bytes ++ */ ++static void decode_ham_plane32(uint32_t *dst, const uint8_t *buf, ++ const uint32_t *const pal, unsigned buf_size) ++{ ++ uint32_t delta = 0; ++ do { ++ uint32_t first, second; ++ DECODE_HAM_PLANE32(0); ++ DECODE_HAM_PLANE32(2); ++ DECODE_HAM_PLANE32(4); ++ DECODE_HAM_PLANE32(6); ++ buf += 8; ++ dst += 8; ++ } while (--buf_size); ++} ++ ++static void lookup_pal_indicies(uint32_t *dst, const uint32_t *buf, ++ const uint32_t *const pal, unsigned width) ++{ ++ do { ++ *dst++ = pal[*buf++]; ++ } while (--width); ++} ++ + /** + * Decode one complete byterun1 encoded line. + * +@@ -250,11 +457,14 @@ + AVPacket *avpkt) + { + IffContext *s = avctx->priv_data; +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL; ++ const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0; + const uint8_t *buf_end = buf+buf_size; + int y, plane, res; + ++ if ((res = extract_header(avctx, avpkt)) < 0) ++ return res; ++ + if (s->init) { + if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -269,21 +479,55 @@ + } + s->init = 1; + +- if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved ++ if (avctx->codec_tag == MKTAG('A','C','B','M')) { ++ if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { ++ memset(s->frame.data[0], 0, avctx->height * s->frame.linesize[0]); ++ for (plane = 0; plane < s->bpp; plane++) { ++ for(y = 0; y < avctx->height && buf < buf_end; y++ ) { ++ uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; ++ decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane); ++ buf += s->planesize; ++ } ++ } ++ } else if (s->ham) { // HAM to PIX_FMT_BGR32 ++ memset(s->frame.data[0], 0, avctx->height * s->frame.linesize[0]); ++ for(y = 0; y < avctx->height; y++) { ++ uint8_t *row = &s->frame.data[0][y * s->frame.linesize[0]]; ++ memset(s->ham_buf, 0, s->planesize * 8); ++ for (plane = 0; plane < s->bpp; plane++) { ++ const uint8_t * start = buf + (plane * avctx->height + y) * s->planesize; ++ if (start >= buf_end) ++ break; ++ decodeplane8(s->ham_buf, start, FFMIN(s->planesize, buf_end - start), plane); ++ } ++ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); ++ } ++ } ++ } else if (avctx->codec_tag == MKTAG('I','L','B','M')) { // interleaved + if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { + for(y = 0; y < avctx->height; y++ ) { + uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; + memset(row, 0, avctx->width); +- for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) { ++ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { + decodeplane8(row, buf, FFMIN(s->planesize, buf_end - buf), plane); + buf += s->planesize; + } + } ++ } else if (s->ham) { // HAM to PIX_FMT_BGR32 ++ for (y = 0; y < avctx->height; y++) { ++ uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; ++ memset(s->ham_buf, 0, s->planesize * 8); ++ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { ++ decodeplane8(s->ham_buf, buf, FFMIN(s->planesize, buf_end - buf), plane); ++ buf += s->planesize; ++ } ++ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); ++ } + } else { // PIX_FMT_BGR32 + for(y = 0; y < avctx->height; y++ ) { + uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; + memset(row, 0, avctx->width << 2); +- for (plane = 0; plane < avctx->bits_per_coded_sample && buf < buf_end; plane++) { ++ for (plane = 0; plane < s->bpp && buf < buf_end; plane++) { + decodeplane32((uint32_t *) row, buf, FFMIN(s->planesize, buf_end - buf), plane); + buf += s->planesize; + } +@@ -295,6 +539,13 @@ + memcpy(row, buf, FFMIN(avctx->width, buf_end - buf)); + buf += avctx->width + (avctx->width % 2); // padding if odd + } ++ } else { // IFF-PBM: HAM to PIX_FMT_BGR32 ++ for (y = 0; y < avctx->height; y++) { ++ uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; ++ memcpy(s->ham_buf, buf, FFMIN(avctx->width, buf_end - buf)); ++ buf += avctx->width + (avctx->width & 1); // padding if odd ++ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width); ++ } + } + + *data_size = sizeof(AVFrame); +@@ -307,11 +558,13 @@ + AVPacket *avpkt) + { + IffContext *s = avctx->priv_data; +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->size >= 2 ? avpkt->data + AV_RB16(avpkt->data) : NULL; ++ const int buf_size = avpkt->size >= 2 ? avpkt->size - AV_RB16(avpkt->data) : 0; + const uint8_t *buf_end = buf+buf_size; + int y, plane, res; + ++ if ((res = extract_header(avctx, avpkt)) < 0) ++ return res; + if (s->init) { + if ((res = avctx->reget_buffer(avctx, &s->frame)) < 0) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -320,9 +573,12 @@ + } else if ((res = avctx->get_buffer(avctx, &s->frame)) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return res; +- } else if (avctx->bits_per_coded_sample <= 8 && avctx->pix_fmt != PIX_FMT_GRAY8) { ++ } else if (avctx->pix_fmt == PIX_FMT_PAL8) { + if ((res = ff_cmap_read_palette(avctx, (uint32_t*)s->frame.data[1])) < 0) + return res; ++ } else if (avctx->pix_fmt == PIX_FMT_RGB32 && avctx->bits_per_coded_sample <= 8) { ++ if ((res = ff_cmap_read_palette(avctx, s->mask_palbuf)) < 0) ++ return res; + } + s->init = 1; + +@@ -331,26 +587,52 @@ + for(y = 0; y < avctx->height ; y++ ) { + uint8_t *row = &s->frame.data[0][ y*s->frame.linesize[0] ]; + memset(row, 0, avctx->width); +- for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { ++ for (plane = 0; plane < s->bpp; plane++) { + buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); + decodeplane8(row, s->planebuf, s->planesize, plane); + } + } ++ } else if (avctx->bits_per_coded_sample <= 8) { //8-bit (+ mask) to PIX_FMT_BGR32 ++ for (y = 0; y < avctx->height ; y++ ) { ++ uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; ++ memset(s->mask_buf, 0, avctx->width * sizeof(uint32_t)); ++ for (plane = 0; plane < s->bpp; plane++) { ++ buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); ++ decodeplane32(s->mask_buf, s->planebuf, s->planesize, plane); ++ } ++ lookup_pal_indicies((uint32_t *) row, s->mask_buf, s->mask_palbuf, avctx->width); ++ } ++ } else if (s->ham) { // HAM to PIX_FMT_BGR32 ++ for (y = 0; y < avctx->height ; y++) { ++ uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; ++ memset(s->ham_buf, 0, s->planesize * 8); ++ for (plane = 0; plane < s->bpp; plane++) { ++ buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); ++ decodeplane8(s->ham_buf, s->planebuf, s->planesize, plane); ++ } ++ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, s->planesize); ++ } + } else { //PIX_FMT_BGR32 + for(y = 0; y < avctx->height ; y++ ) { + uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; + memset(row, 0, avctx->width << 2); +- for (plane = 0; plane < avctx->bits_per_coded_sample; plane++) { ++ for (plane = 0; plane < s->bpp; plane++) { + buf += decode_byterun(s->planebuf, s->planesize, buf, buf_end); + decodeplane32((uint32_t *) row, s->planebuf, s->planesize, plane); + } + } + } +- } else { ++ } else if (avctx->pix_fmt == PIX_FMT_PAL8 || avctx->pix_fmt == PIX_FMT_GRAY8) { // IFF-PBM + for(y = 0; y < avctx->height ; y++ ) { + uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; + buf += decode_byterun(row, avctx->width, buf, buf_end); + } ++ } else { // IFF-PBM: HAM to PIX_FMT_BGR32 ++ for (y = 0; y < avctx->height ; y++) { ++ uint8_t *row = &s->frame.data[0][y*s->frame.linesize[0]]; ++ buf += decode_byterun(s->ham_buf, avctx->width, buf, buf_end); ++ decode_ham_plane32((uint32_t *) row, s->ham_buf, s->ham_palbuf, avctx->width); ++ } + } + + *data_size = sizeof(AVFrame); +@@ -364,31 +646,31 @@ + if (s->frame.data[0]) + avctx->release_buffer(avctx, &s->frame); + av_freep(&s->planebuf); ++ av_freep(&s->ham_buf); ++ av_freep(&s->ham_palbuf); + return 0; + } + + AVCodec ff_iff_ilbm_decoder = { +- "iff_ilbm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_IFF_ILBM, +- sizeof(IffContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame_ilbm, +- CODEC_CAP_DR1, ++ .name = "iff_ilbm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_IFF_ILBM, ++ .priv_data_size = sizeof(IffContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame_ilbm, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IFF ILBM"), + }; + + AVCodec ff_iff_byterun1_decoder = { +- "iff_byterun1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_IFF_BYTERUN1, +- sizeof(IffContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame_byterun1, +- CODEC_CAP_DR1, ++ .name = "iff_byterun1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_IFF_BYTERUN1, ++ .priv_data_size = sizeof(IffContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame_byterun1, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IFF ByteRun1"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/iirfilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/iirfilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/iirfilter.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/iirfilter.c 2012-05-14 14:08:53.842330080 +0200 +@@ -151,8 +151,6 @@ + // during filtering, the delay state will include the gain multiplication + c->cx[0] = lrintf(x0 / c->gain); + c->cx[1] = lrintf(x1 / c->gain); +- c->cy[0] /= c->gain; +- c->cy[1] /= c->gain; + + return 0; + } +@@ -313,6 +311,9 @@ + } + + #ifdef TEST ++#undef printf ++#include ++ + #define FILT_ORDER 4 + #define SIZE 1024 + int main(void) +@@ -322,9 +323,8 @@ + float cutoff_coeff = 0.4; + int16_t x[SIZE], y[SIZE]; + int i; +- FILE* fd; + +- fcoeffs = ff_iir_filter_init_coeffs(FF_FILTER_TYPE_BUTTERWORTH, ++ fcoeffs = ff_iir_filter_init_coeffs(NULL, FF_FILTER_TYPE_BUTTERWORTH, + FF_FILTER_MODE_LOWPASS, FILT_ORDER, + cutoff_coeff, 0.0, 0.0); + fstate = ff_iir_filter_init_state(FILT_ORDER); +@@ -335,13 +335,8 @@ + + ff_iir_filter(fcoeffs, fstate, SIZE, x, 1, y, 1); + +- fd = fopen("in.bin", "w"); +- fwrite(x, sizeof(x[0]), SIZE, fd); +- fclose(fd); +- +- fd = fopen("out.bin", "w"); +- fwrite(y, sizeof(y[0]), SIZE, fd); +- fclose(fd); ++ for (i = 0; i < SIZE; i++) ++ printf("%6d %6d\n", x[i], y[i]); + + ff_iir_filter_free_coeffs(fcoeffs); + ff_iir_filter_free_state(fstate); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/imc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/imc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/imc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/imc.c 2012-05-14 14:08:53.843330100 +0200 +@@ -35,11 +35,12 @@ + #include + #include + +-#define ALT_BITSTREAM_READER + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" + #include "fft.h" ++#include "libavutil/audioconvert.h" ++#include "sinewin.h" + + #include "imcdata.h" + +@@ -49,6 +50,8 @@ + #define COEFFS 256 + + typedef struct { ++ AVFrame frame; ++ + float old_floor[BANDS]; + float flcoeffs1[BANDS]; + float flcoeffs2[BANDS]; +@@ -86,7 +89,7 @@ + + DSPContext dsp; + FFTContext fft; +- DECLARE_ALIGNED(16, FFTComplex, samples)[COEFFS/2]; ++ DECLARE_ALIGNED(32, FFTComplex, samples)[COEFFS/2]; + float *out_samples; + } IMCContext; + +@@ -102,10 +105,15 @@ + + static av_cold int imc_decode_init(AVCodecContext * avctx) + { +- int i, j; ++ int i, j, ret; + IMCContext *q = avctx->priv_data; + double r1, r2; + ++ if (avctx->channels != 1) { ++ av_log_ask_for_sample(avctx, "Number of channels is not supported\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ + q->decoder_reset = 1; + + for(i = 0; i < BANDS; i++) +@@ -154,10 +162,17 @@ + } + q->one_div_log2 = 1/log(2); + +- ff_fft_init(&q->fft, 7, 1); ++ if ((ret = ff_fft_init(&q->fft, 7, 1))) { ++ av_log(avctx, AV_LOG_INFO, "FFT init failed\n"); ++ return ret; ++ } + dsputil_init(&q->dsp, avctx); + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ avctx->channel_layout = AV_CH_LAYOUT_MONO; ++ ++ avcodec_get_frame_defaults(&q->frame); ++ avctx->coded_frame = &q->frame; ++ + return 0; + } + +@@ -334,7 +349,7 @@ + indx = 2; + + if (indx == -1) +- return -1; ++ return AVERROR_INVALIDDATA; + + q->flcoeffs4[i] = q->flcoeffs4[i] + xTab[(indx*2 + (q->flcoeffs1[i] < highest)) * 2 + flag]; + } +@@ -563,8 +578,8 @@ + } + + /* FFT */ +- ff_fft_permute(&q->fft, q->samples); +- ff_fft_calc (&q->fft, q->samples); ++ q->fft.fft_permute(&q->fft, q->samples); ++ q->fft.fft_calc (&q->fft, q->samples); + + /* postrotation, window and reorder */ + for(i = 0; i < COEFFS/2; i++){ +@@ -593,7 +608,7 @@ + middle_value = max_size >> 1; + + if (q->codewords[j] >= max_size || q->codewords[j] < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (cw_len >= 4){ + quantizer = imc_quantizer2[(stream_format_code & 2) >> 1]; +@@ -626,7 +641,7 @@ + + if (get_bits_count(&q->gb) + cw_len > 512){ + //av_log(NULL,0,"Band %i coeff %i cw_len %i\n",i,j,cw_len); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if(cw_len && (!q->bandFlagsBuf[i] || !q->skipFlags[j])) +@@ -639,9 +654,8 @@ + return 0; + } + +-static int imc_decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int imc_decode_frame(AVCodecContext * avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +@@ -649,20 +663,27 @@ + IMCContext *q = avctx->priv_data; + + int stream_format_code; +- int imc_hdr, i, j; ++ int imc_hdr, i, j, ret; + int flag; + int bits, summer; + int counter, bitscount; +- uint16_t buf16[IMC_BLOCK_SIZE / 2]; ++ LOCAL_ALIGNED_16(uint16_t, buf16, [IMC_BLOCK_SIZE / 2]); + + if (buf_size < IMC_BLOCK_SIZE) { + av_log(avctx, AV_LOG_ERROR, "imc frame too small!\n"); +- return -1; ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* get output buffer */ ++ q->frame.nb_samples = COEFFS; ++ if ((ret = avctx->get_buffer(avctx, &q->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } +- for(i = 0; i < IMC_BLOCK_SIZE / 2; i++) +- buf16[i] = av_bswap16(((const uint16_t*)buf)[i]); ++ q->out_samples = (float *)q->frame.data[0]; ++ ++ q->dsp.bswap16_buf(buf16, (const uint16_t*)buf, IMC_BLOCK_SIZE / 2); + +- q->out_samples = data; + init_get_bits(&q->gb, (const uint8_t*)buf16, IMC_BLOCK_SIZE * 8); + + /* Check the frame header */ +@@ -670,13 +691,13 @@ + if (imc_hdr != IMC_FRAME_ID) { + av_log(avctx, AV_LOG_ERROR, "imc frame header check failed!\n"); + av_log(avctx, AV_LOG_ERROR, "got %x instead of 0x21.\n", imc_hdr); +- return -1; ++ return AVERROR_INVALIDDATA; + } + stream_format_code = get_bits(&q->gb, 3); + + if(stream_format_code & 1){ + av_log(avctx, AV_LOG_ERROR, "Stream code format %X is not supported\n", stream_format_code); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + // av_log(avctx, AV_LOG_DEBUG, "stream_format_code = %d\n", stream_format_code); +@@ -736,10 +757,11 @@ + } + } + +- if(bit_allocation (q, stream_format_code, 512 - bitscount - get_bits_count(&q->gb), flag) < 0) { ++ if((ret = bit_allocation (q, stream_format_code, ++ 512 - bitscount - get_bits_count(&q->gb), flag)) < 0) { + av_log(avctx, AV_LOG_ERROR, "Bit allocations failed\n"); + q->decoder_reset = 1; +- return -1; ++ return ret; + } + + for(i = 0; i < BANDS; i++) { +@@ -793,20 +815,21 @@ + if(imc_get_coeffs(q) < 0) { + av_log(avctx, AV_LOG_ERROR, "Read coefficients failed\n"); + q->decoder_reset = 1; +- return 0; ++ return AVERROR_INVALIDDATA; + } + + if(inverse_quant_coeff(q, stream_format_code) < 0) { + av_log(avctx, AV_LOG_ERROR, "Inverse quantization of coefficients failed\n"); + q->decoder_reset = 1; +- return 0; ++ return AVERROR_INVALIDDATA; + } + + memset(q->skipFlags, 0, sizeof(q->skipFlags)); + + imc_imdct256(q); + +- *data_size = COEFFS * sizeof(float); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = q->frame; + + return IMC_BLOCK_SIZE; + } +@@ -817,6 +840,7 @@ + IMCContext *q = avctx->priv_data; + + ff_fft_end(&q->fft); ++ + return 0; + } + +@@ -829,5 +853,6 @@ + .init = imc_decode_init, + .close = imc_decode_close, + .decode = imc_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IMC (Intel Music Coder)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/imgconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/imgconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/imgconvert.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/imgconvert.c 2012-05-14 14:08:53.846330160 +0200 +@@ -36,25 +36,17 @@ + #include "imgconvert.h" + #include "libavutil/colorspace.h" + #include "libavutil/pixdesc.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/internal.h" ++#include "libavutil/imgutils.h" + + #if HAVE_MMX && HAVE_YASM + #include "x86/dsputil_mmx.h" + #endif + +-#define xglue(x, y) x ## y +-#define glue(x, y) xglue(x, y) +- + #define FF_COLOR_RGB 0 /**< RGB color space */ + #define FF_COLOR_GRAY 1 /**< gray color space */ + #define FF_COLOR_YUV 2 /**< YUV color space. 16 <= Y <= 235, 16 <= U, V <= 240 */ + #define FF_COLOR_YUV_JPEG 3 /**< YUV color space. 0 <= Y <= 255, 0 <= U, V <= 255 */ + +-#define FF_PIXEL_PLANAR 0 /**< each channel has one component in AVPicture */ +-#define FF_PIXEL_PACKED 1 /**< only one components containing all the channels */ +-#define FF_PIXEL_PALETTE 2 /**< one components containing indexes for a palette */ +- + #if HAVE_MMX && HAVE_YASM + #define deinterlace_line_inplace ff_deinterlace_line_inplace_mmx + #define deinterlace_line ff_deinterlace_line_mmx +@@ -64,351 +56,230 @@ + #endif + + typedef struct PixFmtInfo { +- uint8_t nb_channels; /**< number of channels (including alpha) */ + uint8_t color_type; /**< color type (see FF_COLOR_xxx constants) */ +- uint8_t pixel_type; /**< pixel storage type (see FF_PIXEL_xxx constants) */ + uint8_t is_alpha : 1; /**< true if alpha can be specified */ +- uint8_t depth; /**< bit depth of the color components */ ++ uint8_t padded_size; /**< padded size in bits if different from the non-padded size */ + } PixFmtInfo; + + /* this table gives more information about formats */ + static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = { + /* YUV formats */ + [PIX_FMT_YUV420P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUV422P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUV444P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUYV422] = { +- .nb_channels = 1, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_UYVY422] = { +- .nb_channels = 1, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_YUV410P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUV411P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUV440P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUV420P16LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_YUV422P16LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_YUV444P16LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_YUV420P16BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_YUV422P16BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_YUV444P16BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + +- + /* YUV formats with alpha plane */ + [PIX_FMT_YUVA420P] = { +- .nb_channels = 4, ++ .is_alpha = 1, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + + /* JPEG YUV */ + [PIX_FMT_YUVJ420P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV_JPEG, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUVJ422P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV_JPEG, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUVJ444P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV_JPEG, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_YUVJ440P] = { +- .nb_channels = 3, + .color_type = FF_COLOR_YUV_JPEG, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + + /* RGB formats */ + [PIX_FMT_RGB24] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_BGR24] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_ARGB] = { +- .nb_channels = 4, .is_alpha = 1, ++ .is_alpha = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_RGB48BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 16, + }, + [PIX_FMT_RGB48LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 16, ++ }, ++ [PIX_FMT_RGBA64BE] = { ++ .is_alpha = 1, ++ .color_type = FF_COLOR_RGB, ++ }, ++ [PIX_FMT_RGBA64LE] = { ++ .is_alpha = 1, ++ .color_type = FF_COLOR_RGB, + }, + [PIX_FMT_RGB565BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, + }, + [PIX_FMT_RGB565LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, + }, + [PIX_FMT_RGB555BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_RGB555LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_RGB444BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, ++ .padded_size = 16, + }, + [PIX_FMT_RGB444LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, ++ .padded_size = 16, + }, + + /* gray / mono formats */ + [PIX_FMT_GRAY16BE] = { +- .nb_channels = 1, + .color_type = FF_COLOR_GRAY, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_GRAY16LE] = { +- .nb_channels = 1, + .color_type = FF_COLOR_GRAY, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 16, + }, + [PIX_FMT_GRAY8] = { +- .nb_channels = 1, + .color_type = FF_COLOR_GRAY, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, ++ }, ++ [PIX_FMT_GRAY8A] = { ++ .is_alpha = 1, ++ .color_type = FF_COLOR_GRAY, + }, + [PIX_FMT_MONOWHITE] = { +- .nb_channels = 1, + .color_type = FF_COLOR_GRAY, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 1, + }, + [PIX_FMT_MONOBLACK] = { +- .nb_channels = 1, + .color_type = FF_COLOR_GRAY, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 1, + }, + + /* paletted formats */ + [PIX_FMT_PAL8] = { +- .nb_channels = 4, .is_alpha = 1, ++ .is_alpha = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PALETTE, +- .depth = 8, + }, + [PIX_FMT_UYYVYY411] = { +- .nb_channels = 1, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_ABGR] = { +- .nb_channels = 4, .is_alpha = 1, ++ .is_alpha = 1, ++ .color_type = FF_COLOR_RGB, ++ }, ++ [PIX_FMT_BGR48BE] = { ++ .color_type = FF_COLOR_RGB, ++ }, ++ [PIX_FMT_BGR48LE] = { ++ .color_type = FF_COLOR_RGB, ++ }, ++ [PIX_FMT_BGRA64BE] = { ++ .is_alpha = 1, ++ .color_type = FF_COLOR_RGB, ++ }, ++ [PIX_FMT_BGRA64LE] = { ++ .is_alpha = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_BGR565BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_BGR565LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_BGR555BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_BGR555LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 5, ++ .padded_size = 16, + }, + [PIX_FMT_BGR444BE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, ++ .padded_size = 16, + }, + [PIX_FMT_BGR444LE] = { +- .nb_channels = 3, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, ++ .padded_size = 16, + }, + [PIX_FMT_RGB8] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_RGB4] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, + }, + [PIX_FMT_RGB4_BYTE] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, ++ .padded_size = 8, + }, + [PIX_FMT_BGR8] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_BGR4] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 4, + }, + [PIX_FMT_BGR4_BYTE] = { +- .nb_channels = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, ++ .padded_size = 8, + }, + [PIX_FMT_NV12] = { +- .nb_channels = 2, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + [PIX_FMT_NV21] = { +- .nb_channels = 2, + .color_type = FF_COLOR_YUV, +- .pixel_type = FF_PIXEL_PLANAR, +- .depth = 8, + }, + + [PIX_FMT_BGRA] = { +- .nb_channels = 4, .is_alpha = 1, ++ .is_alpha = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + [PIX_FMT_RGBA] = { +- .nb_channels = 4, .is_alpha = 1, ++ .is_alpha = 1, + .color_type = FF_COLOR_RGB, +- .pixel_type = FF_PIXEL_PACKED, +- .depth = 8, + }, + }; + +@@ -418,23 +289,10 @@ + *v_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; + } + ++#if FF_API_GET_PIX_FMT_NAME + const char *avcodec_get_pix_fmt_name(enum PixelFormat pix_fmt) + { +- if ((unsigned)pix_fmt >= PIX_FMT_NB) +- return NULL; +- else +- return av_pix_fmt_descriptors[pix_fmt].name; +-} +- +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-enum PixelFormat avcodec_get_pix_fmt(const char *name) +-{ +- return av_get_pix_fmt(name); +-} +- +-void avcodec_pix_fmt_string (char *buf, int buf_size, enum PixelFormat pix_fmt) +-{ +- av_get_pix_fmt_string(buf, buf_size, pix_fmt); ++ return av_get_pix_fmt_name(pix_fmt); + } + #endif + +@@ -443,23 +301,6 @@ + return av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL; + } + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-int ff_set_systematic_pal(uint32_t pal[256], enum PixelFormat pix_fmt){ +- return ff_set_systematic_pal2(pal, pix_fmt); +-} +- +-int ff_fill_linesize(AVPicture *picture, enum PixelFormat pix_fmt, int width) +-{ +- return av_image_fill_linesizes(picture->linesize, pix_fmt, width); +-} +- +-int ff_fill_pointer(AVPicture *picture, uint8_t *ptr, enum PixelFormat pix_fmt, +- int height) +-{ +- return av_image_fill_pointers(picture->data, pix_fmt, height, ptr, picture->linesize); +-} +-#endif +- + int avpicture_fill(AVPicture *picture, uint8_t *ptr, + enum PixelFormat pix_fmt, int width, int height) + { +@@ -501,6 +342,16 @@ + } + } + ++ switch (pix_fmt) { ++ case PIX_FMT_RGB8: ++ case PIX_FMT_BGR8: ++ case PIX_FMT_RGB4_BYTE: ++ case PIX_FMT_BGR4_BYTE: ++ case PIX_FMT_GRAY8: ++ // do not include palette for these pseudo-paletted formats ++ return size; ++ } ++ + if (desc->flags & PIX_FMT_PAL) + memcpy((unsigned char *)(((size_t)dest + 3) & ~3), src->data[1], 256 * 4); + +@@ -524,28 +375,55 @@ + return avpicture_fill(&dummy_pict, NULL, pix_fmt, width, height); + } + ++static int get_pix_fmt_depth(int *min, int *max, enum PixelFormat pix_fmt) ++{ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ int i; ++ ++ if (!desc->nb_components) { ++ *min = *max = 0; ++ return AVERROR(EINVAL); ++ } ++ ++ *min = INT_MAX, *max = -INT_MAX; ++ for (i = 0; i < desc->nb_components; i++) { ++ *min = FFMIN(desc->comp[i].depth_minus1+1, *min); ++ *max = FFMAX(desc->comp[i].depth_minus1+1, *max); ++ } ++ return 0; ++} ++ + int avcodec_get_pix_fmt_loss(enum PixelFormat dst_pix_fmt, enum PixelFormat src_pix_fmt, + int has_alpha) + { + const PixFmtInfo *pf, *ps; +- const AVPixFmtDescriptor *src_desc = &av_pix_fmt_descriptors[src_pix_fmt]; +- const AVPixFmtDescriptor *dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt]; +- int loss; ++ const AVPixFmtDescriptor *src_desc; ++ const AVPixFmtDescriptor *dst_desc; ++ int src_min_depth, src_max_depth, dst_min_depth, dst_max_depth; ++ int ret, loss; ++ ++ if (dst_pix_fmt >= PIX_FMT_NB || dst_pix_fmt <= PIX_FMT_NONE) ++ return ~0; + ++ src_desc = &av_pix_fmt_descriptors[src_pix_fmt]; ++ dst_desc = &av_pix_fmt_descriptors[dst_pix_fmt]; + ps = &pix_fmt_info[src_pix_fmt]; + + /* compute loss */ + loss = 0; +- pf = &pix_fmt_info[dst_pix_fmt]; +- if (pf->depth < ps->depth || +- ((dst_pix_fmt == PIX_FMT_RGB555BE || dst_pix_fmt == PIX_FMT_RGB555LE || +- dst_pix_fmt == PIX_FMT_BGR555BE || dst_pix_fmt == PIX_FMT_BGR555LE) && +- (src_pix_fmt == PIX_FMT_RGB565BE || src_pix_fmt == PIX_FMT_RGB565LE || +- src_pix_fmt == PIX_FMT_BGR565BE || src_pix_fmt == PIX_FMT_BGR565LE))) ++ ++ if ((ret = get_pix_fmt_depth(&src_min_depth, &src_max_depth, src_pix_fmt)) < 0) ++ return ret; ++ if ((ret = get_pix_fmt_depth(&dst_min_depth, &dst_max_depth, dst_pix_fmt)) < 0) ++ return ret; ++ if (dst_min_depth < src_min_depth || ++ dst_max_depth < src_max_depth) + loss |= FF_LOSS_DEPTH; + if (dst_desc->log2_chroma_w > src_desc->log2_chroma_w || + dst_desc->log2_chroma_h > src_desc->log2_chroma_h) + loss |= FF_LOSS_RESOLUTION; ++ ++ pf = &pix_fmt_info[dst_pix_fmt]; + switch(pf->color_type) { + case FF_COLOR_RGB: + if (ps->color_type != FF_COLOR_RGB && +@@ -577,95 +455,44 @@ + loss |= FF_LOSS_CHROMA; + if (!pf->is_alpha && (ps->is_alpha && has_alpha)) + loss |= FF_LOSS_ALPHA; +- if (pf->pixel_type == FF_PIXEL_PALETTE && +- (ps->pixel_type != FF_PIXEL_PALETTE && ps->color_type != FF_COLOR_GRAY)) ++ if (dst_pix_fmt == PIX_FMT_PAL8 && ++ (src_pix_fmt != PIX_FMT_PAL8 && (ps->color_type != FF_COLOR_GRAY || (ps->is_alpha && has_alpha)))) + loss |= FF_LOSS_COLORQUANT; ++ + return loss; + } + + static int avg_bits_per_pixel(enum PixelFormat pix_fmt) + { +- int bits; +- const PixFmtInfo *pf; ++ const PixFmtInfo *info = &pix_fmt_info[pix_fmt]; + const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; + +- pf = &pix_fmt_info[pix_fmt]; +- switch(pf->pixel_type) { +- case FF_PIXEL_PACKED: +- switch(pix_fmt) { +- case PIX_FMT_YUYV422: +- case PIX_FMT_UYVY422: +- case PIX_FMT_RGB565BE: +- case PIX_FMT_RGB565LE: +- case PIX_FMT_RGB555BE: +- case PIX_FMT_RGB555LE: +- case PIX_FMT_RGB444BE: +- case PIX_FMT_RGB444LE: +- case PIX_FMT_BGR565BE: +- case PIX_FMT_BGR565LE: +- case PIX_FMT_BGR555BE: +- case PIX_FMT_BGR555LE: +- case PIX_FMT_BGR444BE: +- case PIX_FMT_BGR444LE: +- bits = 16; +- break; +- case PIX_FMT_UYYVYY411: +- bits = 12; +- break; +- default: +- bits = pf->depth * pf->nb_channels; +- break; +- } +- break; +- case FF_PIXEL_PLANAR: +- if (desc->log2_chroma_w == 0 && desc->log2_chroma_h == 0) { +- bits = pf->depth * pf->nb_channels; +- } else { +- bits = pf->depth + ((2 * pf->depth) >> +- (desc->log2_chroma_w + desc->log2_chroma_h)); +- } +- break; +- case FF_PIXEL_PALETTE: +- bits = 8; +- break; +- default: +- bits = -1; +- break; +- } +- return bits; ++ return info->padded_size ? ++ info->padded_size : av_get_bits_per_pixel(desc); + } + +-static enum PixelFormat avcodec_find_best_pix_fmt1(int64_t pix_fmt_mask, +- enum PixelFormat src_pix_fmt, +- int has_alpha, +- int loss_mask) ++enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, ++ int has_alpha, int *loss_ptr) + { +- int dist, i, loss, min_dist; + enum PixelFormat dst_pix_fmt; ++ int i; + +- /* find exact color match with smallest size */ +- dst_pix_fmt = PIX_FMT_NONE; +- min_dist = 0x7fffffff; +- for(i = 0;i < PIX_FMT_NB; i++) { +- if (pix_fmt_mask & (1ULL << i)) { +- loss = avcodec_get_pix_fmt_loss(i, src_pix_fmt, has_alpha) & loss_mask; +- if (loss == 0) { +- dist = avg_bits_per_pixel(i); +- if (dist < min_dist) { +- min_dist = dist; +- dst_pix_fmt = i; +- } +- } +- } ++ if (loss_ptr) /* all losses count (for backward compatibility) */ ++ *loss_ptr = 0; ++ ++ dst_pix_fmt = PIX_FMT_NONE; /* so first iteration doesn't have to be treated special */ ++ for(i = 0; i< FFMIN(PIX_FMT_NB, 64); i++){ ++ if (pix_fmt_mask & (1ULL << i)) ++ dst_pix_fmt = avcodec_find_best_pix_fmt2(dst_pix_fmt, i, src_pix_fmt, has_alpha, loss_ptr); + } + return dst_pix_fmt; + } + +-enum PixelFormat avcodec_find_best_pix_fmt(int64_t pix_fmt_mask, enum PixelFormat src_pix_fmt, +- int has_alpha, int *loss_ptr) ++enum PixelFormat avcodec_find_best_pix_fmt2(enum PixelFormat dst_pix_fmt1, enum PixelFormat dst_pix_fmt2, ++ enum PixelFormat src_pix_fmt, int has_alpha, int *loss_ptr) + { + enum PixelFormat dst_pix_fmt; +- int loss_mask, i; ++ int loss1, loss2, loss_order1, loss_order2, i, loss_mask; + static const int loss_mask_order[] = { + ~0, /* no loss first */ + ~FF_LOSS_ALPHA, +@@ -673,49 +500,34 @@ + ~(FF_LOSS_COLORSPACE | FF_LOSS_RESOLUTION), + ~FF_LOSS_COLORQUANT, + ~FF_LOSS_DEPTH, ++ ~(FF_LOSS_RESOLUTION | FF_LOSS_DEPTH | FF_LOSS_COLORSPACE | FF_LOSS_ALPHA | ++ FF_LOSS_COLORQUANT | FF_LOSS_CHROMA), ++ 0x80000, //non zero entry that combines all loss variants including future additions + 0, + }; + ++ loss_mask= loss_ptr?~*loss_ptr:~0; /* use loss mask if provided */ ++ dst_pix_fmt = PIX_FMT_NONE; ++ loss1 = avcodec_get_pix_fmt_loss(dst_pix_fmt1, src_pix_fmt, has_alpha) & loss_mask; ++ loss2 = avcodec_get_pix_fmt_loss(dst_pix_fmt2, src_pix_fmt, has_alpha) & loss_mask; ++ + /* try with successive loss */ +- i = 0; +- for(;;) { +- loss_mask = loss_mask_order[i++]; +- dst_pix_fmt = avcodec_find_best_pix_fmt1(pix_fmt_mask, src_pix_fmt, +- has_alpha, loss_mask); +- if (dst_pix_fmt >= 0) +- goto found; +- if (loss_mask == 0) +- break; ++ for(i = 0;loss_mask_order[i] != 0 && dst_pix_fmt == PIX_FMT_NONE;i++) { ++ loss_order1 = loss1 & loss_mask_order[i]; ++ loss_order2 = loss2 & loss_mask_order[i]; ++ ++ if (loss_order1 == 0 && loss_order2 == 0){ /* use format with smallest depth */ ++ dst_pix_fmt = avg_bits_per_pixel(dst_pix_fmt2) < avg_bits_per_pixel(dst_pix_fmt1) ? dst_pix_fmt2 : dst_pix_fmt1; ++ } else if (loss_order1 == 0 || loss_order2 == 0) { /* use format with no loss */ ++ dst_pix_fmt = loss_order2 ? dst_pix_fmt1 : dst_pix_fmt2; ++ } + } +- return PIX_FMT_NONE; +- found: ++ + if (loss_ptr) + *loss_ptr = avcodec_get_pix_fmt_loss(dst_pix_fmt, src_pix_fmt, has_alpha); + return dst_pix_fmt; + } + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-void ff_img_copy_plane(uint8_t *dst, int dst_wrap, +- const uint8_t *src, int src_wrap, +- int width, int height) +-{ +- av_image_copy_plane(dst, dst_wrap, src, src_wrap, width, height); +-} +- +-int ff_get_plane_bytewidth(enum PixelFormat pix_fmt, int width, int plane) +-{ +- return av_image_get_linesize(pix_fmt, width, plane); +-} +- +-void av_picture_data_copy(uint8_t *dst_data[4], int dst_linesize[4], +- uint8_t *src_data[4], int src_linesize[4], +- enum PixelFormat pix_fmt, int width, int height) +-{ +- av_image_copy(dst_data, dst_linesize, src_data, src_linesize, +- pix_fmt, width, height); +-} +-#endif +- + void av_picture_copy(AVPicture *dst, const AVPicture *src, + enum PixelFormat pix_fmt, int width, int height) + { +@@ -829,11 +641,26 @@ + } + + /* return true if yuv planar */ +-static inline int is_yuv_planar(const PixFmtInfo *ps) ++static inline int is_yuv_planar(enum PixelFormat fmt) + { +- return (ps->color_type == FF_COLOR_YUV || +- ps->color_type == FF_COLOR_YUV_JPEG) && +- ps->pixel_type == FF_PIXEL_PLANAR; ++ const PixFmtInfo *info = &pix_fmt_info[fmt]; ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[fmt]; ++ int i; ++ int planes[4] = { 0 }; ++ ++ if (info->color_type != FF_COLOR_YUV && ++ info->color_type != FF_COLOR_YUV_JPEG) ++ return 0; ++ ++ /* set the used planes */ ++ for (i = 0; i < desc->nb_components; i++) ++ planes[desc->comp[i].plane] = 1; ++ ++ /* if there is an unused plane, the format is not planar */ ++ for (i = 0; i < desc->nb_components; i++) ++ if (!planes[i]) ++ return 0; ++ return 1; + } + + int av_picture_crop(AVPicture *dst, const AVPicture *src, +@@ -842,15 +669,23 @@ + int y_shift; + int x_shift; + +- if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || !is_yuv_planar(&pix_fmt_info[pix_fmt])) ++ if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB) + return -1; + + y_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_h; + x_shift = av_pix_fmt_descriptors[pix_fmt].log2_chroma_w; + ++ if (is_yuv_planar(pix_fmt)) { + dst->data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band; + dst->data[1] = src->data[1] + ((top_band >> y_shift) * src->linesize[1]) + (left_band >> x_shift); + dst->data[2] = src->data[2] + ((top_band >> y_shift) * src->linesize[2]) + (left_band >> x_shift); ++ } else{ ++ if(top_band % (1<data[0] = src->data[0] + (top_band * src->linesize[0]) + left_band; ++ } + + dst->linesize[0] = src->linesize[0]; + dst->linesize[1] = src->linesize[1]; +@@ -869,7 +704,7 @@ + int i, y; + + if (pix_fmt < 0 || pix_fmt >= PIX_FMT_NB || +- !is_yuv_planar(&pix_fmt_info[pix_fmt])) return -1; ++ !is_yuv_planar(pix_fmt)) return -1; + + for (i = 0; i < 3; i++) { + x_shift = i ? av_pix_fmt_descriptors[pix_fmt].log2_chroma_w : 0; +@@ -918,6 +753,7 @@ + return 0; + } + ++#if FF_API_GET_ALPHA_INFO + /* NOTE: we scan all the pixels to have an exact information */ + static int get_alpha_info_pal8(const AVPicture *src, int width, int height) + { +@@ -964,6 +800,7 @@ + } + return ret; + } ++#endif + + #if !(HAVE_MMX && HAVE_YASM) + /* filter parameters: [-1 4 2 4 -1] // 8 */ +@@ -1054,7 +891,7 @@ + uint8_t *src_m1, *src_0, *src_p1, *src_p2; + int y; + uint8_t *buf; +- buf = (uint8_t*)av_malloc(width); ++ buf = av_malloc(width); + + src_m1 = src1; + memcpy(buf,src_m1,width); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo2.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo2.c 2012-05-14 14:08:53.847330180 +0200 +@@ -23,7 +23,7 @@ + * @file + * Intel Indeo 2 decoder. + */ +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "get_bits.h" + #include "indeo2data.h" +@@ -146,26 +146,29 @@ + AVFrame * const p= (AVFrame*)&s->picture; + int start; + +- if(p->data[0]) +- avctx->release_buffer(avctx, p); +- +- p->reference = 1; ++ p->reference = 3; + p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, p)) { + av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + ++ start = 48; /* hardcoded for now */ ++ ++ if (start >= buf_size) { ++ av_log(s->avctx, AV_LOG_ERROR, "input buffer size too small (%d)\n", buf_size); ++ return AVERROR_INVALIDDATA; ++ } ++ + s->decode_delta = buf[18]; + + /* decide whether frame uses deltas or not */ +-#ifndef ALT_BITSTREAM_READER_LE ++#ifndef BITSTREAM_READER_LE + for (i = 0; i < buf_size; i++) + buf[i] = av_reverse[buf[i]]; + #endif +- start = 48; /* hardcoded for now */ + +- init_get_bits(&s->gb, buf + start, buf_size - start); ++ init_get_bits(&s->gb, buf + start, (buf_size - start) * 8); + + if (s->decode_delta) { /* intraframe */ + ir2_decode_plane(s, avctx->width, avctx->height, +@@ -195,13 +198,14 @@ + Ir2Context * const ic = avctx->priv_data; + static VLC_TYPE vlc_tables[1 << CODE_VLC_BITS][2]; + ++ avcodec_get_frame_defaults(&ic->picture); + ic->avctx = avctx; + + avctx->pix_fmt= PIX_FMT_YUV410P; + + ir2_vlc.table = vlc_tables; + ir2_vlc.table_allocated = 1 << CODE_VLC_BITS; +-#ifdef ALT_BITSTREAM_READER_LE ++#ifdef BITSTREAM_READER_LE + init_vlc(&ir2_vlc, CODE_VLC_BITS, IR2_CODES, + &ir2_codes[0][1], 4, 2, + &ir2_codes[0][0], 4, 2, INIT_VLC_USE_NEW_STATIC | INIT_VLC_LE); +@@ -225,14 +229,13 @@ + } + + AVCodec ff_indeo2_decoder = { +- "indeo2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_INDEO2, +- sizeof(Ir2Context), +- ir2_decode_init, +- NULL, +- ir2_decode_end, +- ir2_decode_frame, +- CODEC_CAP_DR1, ++ .name = "indeo2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_INDEO2, ++ .priv_data_size = sizeof(Ir2Context), ++ .init = ir2_decode_init, ++ .close = ir2_decode_end, ++ .decode = ir2_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo2data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo2data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo2data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo2data.h 2012-05-14 14:08:53.847330180 +0200 +@@ -26,7 +26,7 @@ + + #define IR2_CODES 143 + static const uint16_t ir2_codes[IR2_CODES][2] = { +-#ifdef ALT_BITSTREAM_READER_LE ++#ifdef BITSTREAM_READER_LE + {0x0000, 3}, {0x0004, 3}, {0x0006, 3}, {0x0001, 5}, + {0x0009, 5}, {0x0019, 5}, {0x000D, 5}, {0x001D, 5}, + {0x0023, 6}, {0x0013, 6}, {0x0033, 6}, {0x000B, 6}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo3.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo3.c 2012-05-14 14:08:53.853330302 +0200 +@@ -1,6 +1,6 @@ + /* +- * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg +- * written, produced, and directed by Alan Smithee ++ * Indeo Video v3 compatible decoder ++ * Copyright (c) 2009 - 2011 Maxim Poliakovski + * + * This file is part of FFmpeg. + * +@@ -19,1134 +19,1075 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include +-#include +-#include ++/** ++ * @file ++ * This is a decoder for Intel Indeo Video v3. ++ * It is based on vector quantization, run-length coding and motion compensation. ++ * Known container formats: .avi and .mov ++ * Known FOURCCs: 'IV31', 'IV32' ++ * ++ * @see http://wiki.multimedia.cx/index.php?title=Indeo_3 ++ */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "dsputil.h" + #include "bytestream.h" ++#include "get_bits.h" + + #include "indeo3data.h" + +-typedef struct +-{ +- uint8_t *Ybuf; +- uint8_t *Ubuf; +- uint8_t *Vbuf; +- unsigned short y_w, y_h; +- unsigned short uv_w, uv_h; +-} YUVBufs; ++/* RLE opcodes. */ ++enum { ++ RLE_ESC_F9 = 249, ///< same as RLE_ESC_FA + do the same with next block ++ RLE_ESC_FA = 250, ///< INTRA: skip block, INTER: copy data from reference ++ RLE_ESC_FB = 251, ///< apply null delta to N blocks / skip N blocks ++ RLE_ESC_FC = 252, ///< same as RLE_ESC_FD + do the same with next block ++ RLE_ESC_FD = 253, ///< apply null delta to all remaining lines of this block ++ RLE_ESC_FE = 254, ///< apply null delta to all lines up to the 3rd line ++ RLE_ESC_FF = 255 ///< apply null delta to all lines up to the 2nd line ++}; ++ ++ ++/* Some constants for parsing frame bitstream flags. */ ++#define BS_8BIT_PEL (1 << 1) ///< 8bit pixel bitdepth indicator ++#define BS_KEYFRAME (1 << 2) ///< intra frame indicator ++#define BS_MV_Y_HALF (1 << 4) ///< vertical mv halfpel resolution indicator ++#define BS_MV_X_HALF (1 << 5) ///< horizontal mv halfpel resolution indicator ++#define BS_NONREF (1 << 8) ///< nonref (discardable) frame indicator ++#define BS_BUFFER 9 ///< indicates which of two frame buffers should be used ++ ++ ++typedef struct Plane { ++ uint8_t *buffers[2]; ++ uint8_t *pixels[2]; ///< pointer to the actual pixel data of the buffers above ++ uint32_t width; ++ uint32_t height; ++ uint32_t pitch; ++} Plane; ++ ++#define CELL_STACK_MAX 20 ++ ++typedef struct Cell { ++ int16_t xpos; ///< cell coordinates in 4x4 blocks ++ int16_t ypos; ++ int16_t width; ///< cell width in 4x4 blocks ++ int16_t height; ///< cell height in 4x4 blocks ++ uint8_t tree; ///< tree id: 0- MC tree, 1 - VQ tree ++ const int8_t *mv_ptr; ///< ptr to the motion vector if any ++} Cell; + + typedef struct Indeo3DecodeContext { + AVCodecContext *avctx; +- int width, height; +- AVFrame frame; ++ AVFrame frame; ++ DSPContext dsp; + +- uint8_t *buf; +- YUVBufs iv_frame[2]; +- YUVBufs *cur_frame; +- YUVBufs *ref_frame; +- +- uint8_t *ModPred; +- uint8_t *corrector_type; ++ GetBitContext gb; ++ int need_resync; ++ int skip_bits; ++ const uint8_t *next_cell_data; ++ const uint8_t *last_byte; ++ const int8_t *mc_vectors; ++ unsigned num_vectors; ///< number of motion vectors in mc_vectors ++ ++ int16_t width, height; ++ uint32_t frame_num; ///< current frame number (zero-based) ++ uint32_t data_size; ///< size of the frame data in bytes ++ uint16_t frame_flags; ///< frame properties ++ uint8_t cb_offset; ///< needed for selecting VQ tables ++ uint8_t buf_sel; ///< active frame buffer: 0 - primary, 1 -secondary ++ const uint8_t *y_data_ptr; ++ const uint8_t *v_data_ptr; ++ const uint8_t *u_data_ptr; ++ int32_t y_data_size; ++ int32_t v_data_size; ++ int32_t u_data_size; ++ const uint8_t *alt_quant; ///< secondary VQ table set for the modes 1 and 4 ++ Plane planes[3]; + } Indeo3DecodeContext; + +-static const uint8_t corrector_type_0[24] = { +- 195, 159, 133, 115, 101, 93, 87, 77, +- 195, 159, 133, 115, 101, 93, 87, 77, +- 128, 79, 79, 79, 79, 79, 79, 79 +-}; + +-static const uint8_t corrector_type_2[8] = { 9, 7, 6, 8, 5, 4, 3, 2 }; ++static uint8_t requant_tab[8][128]; + +-static av_cold int build_modpred(Indeo3DecodeContext *s) ++/* ++ * Build the static requantization table. ++ * This table is used to remap pixel values according to a specific ++ * quant index and thus avoid overflows while adding deltas. ++ */ ++static av_cold void build_requant_tab(void) + { +- int i, j; ++ static int8_t offsets[8] = { 1, 1, 2, -3, -3, 3, 4, 4 }; ++ static int8_t deltas [8] = { 0, 1, 0, 4, 4, 1, 0, 1 }; + +- if (!(s->ModPred = av_malloc(8 * 128))) +- return AVERROR(ENOMEM); ++ int i, j, step; + +- for (i=0; i < 128; ++i) { +- s->ModPred[i+0*128] = i > 126 ? 254 : 2*(i + 1 - ((i + 1) % 2)); +- s->ModPred[i+1*128] = i == 7 ? 20 : +- i == 119 || +- i == 120 ? 236 : 2*(i + 2 - ((i + 1) % 3)); +- s->ModPred[i+2*128] = i > 125 ? 248 : 2*(i + 2 - ((i + 2) % 4)); +- s->ModPred[i+3*128] = 2*(i + 1 - ((i - 3) % 5)); +- s->ModPred[i+4*128] = i == 8 ? 20 : 2*(i + 1 - ((i - 3) % 6)); +- s->ModPred[i+5*128] = 2*(i + 4 - ((i + 3) % 7)); +- s->ModPred[i+6*128] = i > 123 ? 240 : 2*(i + 4 - ((i + 4) % 8)); +- s->ModPred[i+7*128] = 2*(i + 5 - ((i + 4) % 9)); +- } +- +- if (!(s->corrector_type = av_malloc(24 * 256))) +- return AVERROR(ENOMEM); +- +- for (i=0; i < 24; ++i) { +- for (j=0; j < 256; ++j) { +- s->corrector_type[i*256+j] = j < corrector_type_0[i] ? 1 : +- j < 248 || (i == 16 && j == 248) ? 0 : +- corrector_type_2[j - 248]; +- } ++ for (i = 0; i < 8; i++) { ++ step = i + 2; ++ for (j = 0; j < 128; j++) ++ requant_tab[i][j] = (j + offsets[i]) / step * step + deltas[i]; + } + +- return 0; ++ /* some last elements calculated above will have values >= 128 */ ++ /* pixel values shall never exceed 127 so set them to non-overflowing values */ ++ /* according with the quantization step of the respective section */ ++ requant_tab[0][127] = 126; ++ requant_tab[1][119] = 118; ++ requant_tab[1][120] = 118; ++ requant_tab[2][126] = 124; ++ requant_tab[2][127] = 124; ++ requant_tab[6][124] = 120; ++ requant_tab[6][125] = 120; ++ requant_tab[6][126] = 120; ++ requant_tab[6][127] = 120; ++ ++ /* Patch for compatibility with the Intel's binary decoders */ ++ requant_tab[1][7] = 10; ++ requant_tab[4][8] = 10; + } + +-static av_cold int iv_alloc_frames(Indeo3DecodeContext *s) ++ ++static av_cold int allocate_frame_buffers(Indeo3DecodeContext *ctx, ++ AVCodecContext *avctx) + { +- int luma_width = (s->width + 3) & ~3, +- luma_height = (s->height + 3) & ~3, +- chroma_width = ((luma_width >> 2) + 3) & ~3, +- chroma_height = ((luma_height >> 2) + 3) & ~3, +- luma_pixels = luma_width * luma_height, +- chroma_pixels = chroma_width * chroma_height, +- i; +- unsigned int bufsize = luma_pixels * 2 + luma_width * 3 + +- (chroma_pixels + chroma_width) * 4; +- +- av_freep(&s->buf); +- if(!(s->buf = av_malloc(bufsize))) +- return AVERROR(ENOMEM); +- s->iv_frame[0].y_w = s->iv_frame[1].y_w = luma_width; +- s->iv_frame[0].y_h = s->iv_frame[1].y_h = luma_height; +- s->iv_frame[0].uv_w = s->iv_frame[1].uv_w = chroma_width; +- s->iv_frame[0].uv_h = s->iv_frame[1].uv_h = chroma_height; +- +- s->iv_frame[0].Ybuf = s->buf + luma_width; +- i = luma_pixels + luma_width * 2; +- s->iv_frame[1].Ybuf = s->buf + i; +- i += (luma_pixels + luma_width); +- s->iv_frame[0].Ubuf = s->buf + i; +- i += (chroma_pixels + chroma_width); +- s->iv_frame[1].Ubuf = s->buf + i; +- i += (chroma_pixels + chroma_width); +- s->iv_frame[0].Vbuf = s->buf + i; +- i += (chroma_pixels + chroma_width); +- s->iv_frame[1].Vbuf = s->buf + i; +- +- for(i = 1; i <= luma_width; i++) +- s->iv_frame[0].Ybuf[-i] = s->iv_frame[1].Ybuf[-i] = +- s->iv_frame[0].Ubuf[-i] = 0x80; +- +- for(i = 1; i <= chroma_width; i++) { +- s->iv_frame[1].Ubuf[-i] = 0x80; +- s->iv_frame[0].Vbuf[-i] = 0x80; +- s->iv_frame[1].Vbuf[-i] = 0x80; +- s->iv_frame[1].Vbuf[chroma_pixels+i-1] = 0x80; ++ int p, luma_width, luma_height, chroma_width, chroma_height; ++ int luma_pitch, chroma_pitch, luma_size, chroma_size; ++ ++ luma_width = ctx->width; ++ luma_height = ctx->height; ++ ++ if (luma_width < 16 || luma_width > 640 || ++ luma_height < 16 || luma_height > 480 || ++ luma_width & 3 || luma_height & 3) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid picture dimensions: %d x %d!\n", ++ luma_width, luma_height); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ chroma_width = FFALIGN(luma_width >> 2, 4); ++ chroma_height = FFALIGN(luma_height >> 2, 4); ++ ++ luma_pitch = FFALIGN(luma_width, 16); ++ chroma_pitch = FFALIGN(chroma_width, 16); ++ ++ /* Calculate size of the luminance plane. */ ++ /* Add one line more for INTRA prediction. */ ++ luma_size = luma_pitch * (luma_height + 1); ++ ++ /* Calculate size of a chrominance planes. */ ++ /* Add one line more for INTRA prediction. */ ++ chroma_size = chroma_pitch * (chroma_height + 1); ++ ++ /* allocate frame buffers */ ++ for (p = 0; p < 3; p++) { ++ ctx->planes[p].pitch = !p ? luma_pitch : chroma_pitch; ++ ctx->planes[p].width = !p ? luma_width : chroma_width; ++ ctx->planes[p].height = !p ? luma_height : chroma_height; ++ ++ ctx->planes[p].buffers[0] = av_malloc(!p ? luma_size : chroma_size); ++ ctx->planes[p].buffers[1] = av_malloc(!p ? luma_size : chroma_size); ++ ++ /* fill the INTRA prediction lines with the middle pixel value = 64 */ ++ memset(ctx->planes[p].buffers[0], 0x40, ctx->planes[p].pitch); ++ memset(ctx->planes[p].buffers[1], 0x40, ctx->planes[p].pitch); ++ ++ /* set buffer pointers = buf_ptr + pitch and thus skip the INTRA prediction line */ ++ ctx->planes[p].pixels[0] = ctx->planes[p].buffers[0] + ctx->planes[p].pitch; ++ ctx->planes[p].pixels[1] = ctx->planes[p].buffers[1] + ctx->planes[p].pitch; + } + + return 0; + } + +-static av_cold void iv_free_func(Indeo3DecodeContext *s) ++ ++static av_cold void free_frame_buffers(Indeo3DecodeContext *ctx) + { +- av_freep(&s->buf); +- av_freep(&s->ModPred); +- av_freep(&s->corrector_type); ++ int p; ++ ++ for (p = 0; p < 3; p++) { ++ av_freep(&ctx->planes[p].buffers[0]); ++ av_freep(&ctx->planes[p].buffers[1]); ++ } + } + +-struct ustr { +- long xpos; +- long ypos; +- long width; +- long height; +- long split_flag; +- long split_direction; +- long usl7; +-}; + ++/** ++ * Copy pixels of the cell(x + mv_x, y + mv_y) from the previous frame into ++ * the cell(x, y) in the current frame. ++ * ++ * @param ctx pointer to the decoder context ++ * @param plane pointer to the plane descriptor ++ * @param cell pointer to the cell descriptor ++ */ ++static void copy_cell(Indeo3DecodeContext *ctx, Plane *plane, Cell *cell) ++{ ++ int h, w, mv_x, mv_y, offset, offset_dst; ++ uint8_t *src, *dst; + +-#define LV1_CHECK(buf1,rle_v3,lv1,lp2) \ +- if((lv1 & 0x80) != 0) { \ +- if(rle_v3 != 0) \ +- rle_v3 = 0; \ +- else { \ +- rle_v3 = 1; \ +- buf1 -= 2; \ +- } \ +- } \ +- lp2 = 4; +- +- +-#define RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) \ +- if(rle_v3 == 0) { \ +- rle_v2 = *buf1; \ +- rle_v1 = 1; \ +- if(rle_v2 > 32) { \ +- rle_v2 -= 32; \ +- rle_v1 = 0; \ +- } \ +- rle_v3 = 1; \ +- } \ +- buf1--; +- +- +-#define LP2_CHECK(buf1,rle_v3,lp2) \ +- if(lp2 == 0 && rle_v3 != 0) \ +- rle_v3 = 0; \ +- else { \ +- buf1--; \ +- rle_v3 = 1; \ ++ /* setup output and reference pointers */ ++ offset_dst = (cell->ypos << 2) * plane->pitch + (cell->xpos << 2); ++ dst = plane->pixels[ctx->buf_sel] + offset_dst; ++ if(cell->mv_ptr){ ++ mv_y = cell->mv_ptr[0]; ++ mv_x = cell->mv_ptr[1]; ++ }else ++ mv_x= mv_y= 0; ++ offset = offset_dst + mv_y * plane->pitch + mv_x; ++ src = plane->pixels[ctx->buf_sel ^ 1] + offset; ++ ++ h = cell->height << 2; ++ ++ for (w = cell->width; w > 0;) { ++ /* copy using 16xH blocks */ ++ if (!((cell->xpos << 2) & 15) && w >= 4) { ++ for (; w >= 4; src += 16, dst += 16, w -= 4) ++ ctx->dsp.put_no_rnd_pixels_tab[0][0](dst, src, plane->pitch, h); ++ } ++ ++ /* copy using 8xH blocks */ ++ if (!((cell->xpos << 2) & 7) && w >= 2) { ++ ctx->dsp.put_no_rnd_pixels_tab[1][0](dst, src, plane->pitch, h); ++ w -= 2; ++ src += 8; ++ dst += 8; ++ } ++ ++ if (w >= 1) { ++ copy_block4(dst, src, plane->pitch, plane->pitch, h); ++ w--; ++ src += 4; ++ dst += 4; ++ } + } ++} ++ ++ ++/* Average 4/8 pixels at once without rounding using SWAR */ ++#define AVG_32(dst, src, ref) \ ++ AV_WN32A(dst, ((AV_RN32A(src) + AV_RN32A(ref)) >> 1) & 0x7F7F7F7FUL) + ++#define AVG_64(dst, src, ref) \ ++ AV_WN64A(dst, ((AV_RN64A(src) + AV_RN64A(ref)) >> 1) & 0x7F7F7F7F7F7F7F7FULL) + +-#define RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) \ +- rle_v2--; \ +- if(rle_v2 == 0) { \ +- rle_v3 = 0; \ +- buf1 += 2; \ +- } \ +- lp2 = 4; +- +-static void iv_Decode_Chunk(Indeo3DecodeContext *s, +- uint8_t *cur, uint8_t *ref, int width, int height, +- const uint8_t *buf1, long cb_offset, const uint8_t *hdr, +- const uint8_t *buf2, int min_width_160) ++ ++/* ++ * Replicate each even pixel as follows: ++ * ABCDEFGH -> AACCEEGG ++ */ ++static inline uint64_t replicate64(uint64_t a) { ++#if HAVE_BIGENDIAN ++ a &= 0xFF00FF00FF00FF00ULL; ++ a |= a >> 8; ++#else ++ a &= 0x00FF00FF00FF00FFULL; ++ a |= a << 8; ++#endif ++ return a; ++} ++ ++static inline uint32_t replicate32(uint32_t a) { ++#if HAVE_BIGENDIAN ++ a &= 0xFF00FF00UL; ++ a |= a >> 8; ++#else ++ a &= 0x00FF00FFUL; ++ a |= a << 8; ++#endif ++ return a; ++} ++ ++ ++/* Fill n lines with 64bit pixel value pix */ ++static inline void fill_64(uint8_t *dst, const uint64_t pix, int32_t n, ++ int32_t row_offset) + { +- uint8_t bit_buf; +- unsigned long bit_pos, lv, lv1, lv2; +- long *width_tbl, width_tbl_arr[10]; +- const signed char *ref_vectors; +- uint8_t *cur_frm_pos, *ref_frm_pos, *cp, *cp2; +- uint32_t *cur_lp, *ref_lp; +- const uint32_t *correction_lp[2], *correctionloworder_lp[2], *correctionhighorder_lp[2]; +- uint8_t *correction_type_sp[2]; +- struct ustr strip_tbl[20], *strip; +- int i, j, k, lp1, lp2, flag1, cmd, blks_width, blks_height, region_160_width, +- rle_v1, rle_v2, rle_v3; +- unsigned short res; +- +- bit_buf = 0; +- ref_vectors = NULL; +- +- width_tbl = width_tbl_arr + 1; +- i = (width < 0 ? width + 3 : width)/4; +- for(j = -1; j < 8; j++) +- width_tbl[j] = i * j; +- +- strip = strip_tbl; +- +- for(region_160_width = 0; region_160_width < (width - min_width_160); region_160_width += min_width_160); +- +- strip->ypos = strip->xpos = 0; +- for(strip->width = min_width_160; width > strip->width; strip->width *= 2); +- strip->height = height; +- strip->split_direction = 0; +- strip->split_flag = 0; +- strip->usl7 = 0; +- +- bit_pos = 0; +- +- rle_v1 = rle_v2 = rle_v3 = 0; +- +- while(strip >= strip_tbl) { +- if(bit_pos <= 0) { +- bit_pos = 8; +- bit_buf = *buf1++; +- } ++ for (; n > 0; dst += row_offset, n--) ++ AV_WN64A(dst, pix); ++} + +- bit_pos -= 2; +- cmd = (bit_buf >> bit_pos) & 0x03; + +- if(cmd == 0) { +- strip++; +- if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) { +- av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n"); +- break; +- } +- memcpy(strip, strip-1, sizeof(*strip)); +- strip->split_flag = 1; +- strip->split_direction = 0; +- strip->height = (strip->height > 8 ? ((strip->height+8)>>4)<<3 : 4); +- continue; +- } else if(cmd == 1) { +- strip++; +- if(strip >= strip_tbl + FF_ARRAY_ELEMS(strip_tbl)) { +- av_log(s->avctx, AV_LOG_WARNING, "out of range strip\n"); +- break; +- } +- memcpy(strip, strip-1, sizeof(*strip)); +- strip->split_flag = 1; +- strip->split_direction = 1; +- strip->width = (strip->width > 8 ? ((strip->width+8)>>4)<<3 : 4); +- continue; +- } else if(cmd == 2) { +- if(strip->usl7 == 0) { +- strip->usl7 = 1; +- ref_vectors = NULL; +- continue; +- } +- } else if(cmd == 3) { +- if(strip->usl7 == 0) { +- strip->usl7 = 1; +- ref_vectors = (const signed char*)buf2 + (*buf1 * 2); +- buf1++; +- continue; +- } +- } ++/* Error codes for cell decoding. */ ++enum { ++ IV3_NOERR = 0, ++ IV3_BAD_RLE = 1, ++ IV3_BAD_DATA = 2, ++ IV3_BAD_COUNTER = 3, ++ IV3_UNSUPPORTED = 4, ++ IV3_OUT_OF_DATA = 5 ++}; + +- cur_frm_pos = cur + width * strip->ypos + strip->xpos; + +- if((blks_width = strip->width) < 0) +- blks_width += 3; +- blks_width >>= 2; +- blks_height = strip->height; +- +- if(ref_vectors != NULL) { +- ref_frm_pos = ref + (ref_vectors[0] + strip->ypos) * width + +- ref_vectors[1] + strip->xpos; +- } else +- ref_frm_pos = cur_frm_pos - width_tbl[4]; ++#define BUFFER_PRECHECK \ ++if (*data_ptr >= last_ptr) \ ++ return IV3_OUT_OF_DATA; \ ++ ++#define RLE_BLOCK_COPY \ ++ if (cell->mv_ptr || !skip_flag) \ ++ copy_block4(dst, ref, row_offset, row_offset, 4 << v_zoom) ++ ++#define RLE_BLOCK_COPY_8 \ ++ pix64 = AV_RN64A(ref);\ ++ if (is_first_row) {/* special prediction case: top line of a cell */\ ++ pix64 = replicate64(pix64);\ ++ fill_64(dst + row_offset, pix64, 7, row_offset);\ ++ AVG_64(dst, ref, dst + row_offset);\ ++ } else \ ++ fill_64(dst, pix64, 8, row_offset) ++ ++#define RLE_LINES_COPY \ ++ copy_block4(dst, ref, row_offset, row_offset, num_lines << v_zoom) ++ ++#define RLE_LINES_COPY_M10 \ ++ pix64 = AV_RN64A(ref);\ ++ if (is_top_of_cell) {\ ++ pix64 = replicate64(pix64);\ ++ fill_64(dst + row_offset, pix64, (num_lines << 1) - 1, row_offset);\ ++ AVG_64(dst, ref, dst + row_offset);\ ++ } else \ ++ fill_64(dst, pix64, num_lines << 1, row_offset) ++ ++#define APPLY_DELTA_4 \ ++ AV_WN16A(dst + line_offset , AV_RN16A(ref ) + delta_tab->deltas[dyad1]);\ ++ AV_WN16A(dst + line_offset + 2, AV_RN16A(ref + 2) + delta_tab->deltas[dyad2]);\ ++ if (mode >= 3) {\ ++ if (is_top_of_cell && !cell->ypos) {\ ++ AV_COPY32(dst, dst + row_offset);\ ++ } else {\ ++ AVG_32(dst, ref, dst + row_offset);\ ++ }\ ++ } + +- if(cmd == 2) { +- if(bit_pos <= 0) { +- bit_pos = 8; +- bit_buf = *buf1++; +- } ++#define APPLY_DELTA_8 \ ++ /* apply two 32-bit VQ deltas to next even line */\ ++ if (is_top_of_cell) { \ ++ AV_WN32A(dst + row_offset , \ ++ replicate32(AV_RN32A(ref )) + delta_tab->deltas_m10[dyad1]);\ ++ AV_WN32A(dst + row_offset + 4, \ ++ replicate32(AV_RN32A(ref + 4)) + delta_tab->deltas_m10[dyad2]);\ ++ } else { \ ++ AV_WN32A(dst + row_offset , \ ++ AV_RN32A(ref ) + delta_tab->deltas_m10[dyad1]);\ ++ AV_WN32A(dst + row_offset + 4, \ ++ AV_RN32A(ref + 4) + delta_tab->deltas_m10[dyad2]);\ ++ } \ ++ /* odd lines are not coded but rather interpolated/replicated */\ ++ /* first line of the cell on the top of image? - replicate */\ ++ /* otherwise - interpolate */\ ++ if (is_top_of_cell && !cell->ypos) {\ ++ AV_COPY64(dst, dst + row_offset);\ ++ } else \ ++ AVG_64(dst, ref, dst + row_offset); ++ ++ ++#define APPLY_DELTA_1011_INTER \ ++ if (mode == 10) { \ ++ AV_WN32A(dst , \ ++ AV_RN32A(dst ) + delta_tab->deltas_m10[dyad1]);\ ++ AV_WN32A(dst + 4 , \ ++ AV_RN32A(dst + 4 ) + delta_tab->deltas_m10[dyad2]);\ ++ AV_WN32A(dst + row_offset , \ ++ AV_RN32A(dst + row_offset ) + delta_tab->deltas_m10[dyad1]);\ ++ AV_WN32A(dst + row_offset + 4, \ ++ AV_RN32A(dst + row_offset + 4) + delta_tab->deltas_m10[dyad2]);\ ++ } else { \ ++ AV_WN16A(dst , \ ++ AV_RN16A(dst ) + delta_tab->deltas[dyad1]);\ ++ AV_WN16A(dst + 2 , \ ++ AV_RN16A(dst + 2 ) + delta_tab->deltas[dyad2]);\ ++ AV_WN16A(dst + row_offset , \ ++ AV_RN16A(dst + row_offset ) + delta_tab->deltas[dyad1]);\ ++ AV_WN16A(dst + row_offset + 2, \ ++ AV_RN16A(dst + row_offset + 2) + delta_tab->deltas[dyad2]);\ ++ } + +- bit_pos -= 2; +- cmd = (bit_buf >> bit_pos) & 0x03; + +- if(cmd == 0 || ref_vectors != NULL) { +- for(lp1 = 0; lp1 < blks_width; lp1++) { +- for(i = 0, j = 0; i < blks_height; i++, j += width_tbl[1]) +- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; +- cur_frm_pos += 4; +- ref_frm_pos += 4; +- } +- } else if(cmd != 1) +- return; +- } else { +- k = *buf1 >> 4; +- j = *buf1 & 0x0f; +- buf1++; +- lv = j + cb_offset; +- +- if((lv - 8) <= 7 && (k == 0 || k == 3 || k == 10)) { +- cp2 = s->ModPred + ((lv - 8) << 7); +- cp = ref_frm_pos; +- for(i = 0; i < blks_width << 2; i++) { +- int v = *cp >> 1; +- *(cp++) = cp2[v]; ++static int decode_cell_data(Cell *cell, uint8_t *block, uint8_t *ref_block, ++ int pitch, int h_zoom, int v_zoom, int mode, ++ const vqEntry *delta[2], int swap_quads[2], ++ const uint8_t **data_ptr, const uint8_t *last_ptr) ++{ ++ int x, y, line, num_lines; ++ int rle_blocks = 0; ++ uint8_t code, *dst, *ref; ++ const vqEntry *delta_tab; ++ unsigned int dyad1, dyad2; ++ uint64_t pix64; ++ int skip_flag = 0, is_top_of_cell, is_first_row = 1; ++ int row_offset, blk_row_offset, line_offset; ++ ++ row_offset = pitch; ++ blk_row_offset = (row_offset << (2 + v_zoom)) - (cell->width << 2); ++ line_offset = v_zoom ? row_offset : 0; ++ ++ for (y = 0; y < cell->height; is_first_row = 0, y += 1 + v_zoom) { ++ for (x = 0; x < cell->width; x += 1 + h_zoom) { ++ ref = ref_block; ++ dst = block; ++ ++ if (rle_blocks > 0) { ++ if (mode <= 4) { ++ RLE_BLOCK_COPY; ++ } else if (mode == 10 && !cell->mv_ptr) { ++ RLE_BLOCK_COPY_8; + } +- } +- +- if(k == 1 || k == 4) { +- lv = (hdr[j] & 0xf) + cb_offset; +- correction_type_sp[0] = s->corrector_type + (lv << 8); +- correction_lp[0] = correction + (lv << 8); +- lv = (hdr[j] >> 4) + cb_offset; +- correction_lp[1] = correction + (lv << 8); +- correction_type_sp[1] = s->corrector_type + (lv << 8); ++ rle_blocks--; + } else { +- correctionloworder_lp[0] = correctionloworder_lp[1] = correctionloworder + (lv << 8); +- correctionhighorder_lp[0] = correctionhighorder_lp[1] = correctionhighorder + (lv << 8); +- correction_type_sp[0] = correction_type_sp[1] = s->corrector_type + (lv << 8); +- correction_lp[0] = correction_lp[1] = correction + (lv << 8); +- } +- +- switch(k) { +- case 1: +- case 0: /********** CASE 0 **********/ +- for( ; blks_height > 0; blks_height -= 4) { +- for(lp1 = 0; lp1 < blks_width; lp1++) { +- for(lp2 = 0; lp2 < 4; ) { +- k = *buf1++; +- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2]; +- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2]; +- +- switch(correction_type_sp[0][k]) { +- case 0: +- *cur_lp = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); +- lp2++; +- break; +- case 1: +- res = ((av_le2ne16(((unsigned short *)(ref_lp))[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; +- ((unsigned short *)cur_lp)[0] = av_le2ne16(res); +- res = ((av_le2ne16(((unsigned short *)(ref_lp))[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; +- ((unsigned short *)cur_lp)[1] = av_le2ne16(res); +- buf1++; +- lp2++; +- break; +- case 2: +- if(lp2 == 0) { +- for(i = 0, j = 0; i < 2; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 += 2; +- } +- break; +- case 3: +- if(lp2 < 2) { +- for(i = 0, j = 0; i < (3 - lp2); i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 = 3; +- } +- break; +- case 8: +- if(lp2 == 0) { +- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) +- +- if(rle_v1 == 1 || ref_vectors != NULL) { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- } +- +- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) +- break; +- } else { +- rle_v1 = 1; +- rle_v2 = *buf1 - 1; +- } +- case 5: +- LP2_CHECK(buf1,rle_v3,lp2) +- case 4: +- for(i = 0, j = 0; i < (4 - lp2); i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 = 4; +- break; +- +- case 7: +- if(rle_v3 != 0) +- rle_v3 = 0; +- else { +- buf1--; +- rle_v3 = 1; ++ for (line = 0; line < 4;) { ++ num_lines = 1; ++ is_top_of_cell = is_first_row && !line; ++ ++ /* select primary VQ table for odd, secondary for even lines */ ++ if (mode <= 4) ++ delta_tab = delta[line & 1]; ++ else ++ delta_tab = delta[1]; ++ BUFFER_PRECHECK; ++ code = bytestream_get_byte(data_ptr); ++ if (code < 248) { ++ if (code < delta_tab->num_dyads) { ++ BUFFER_PRECHECK; ++ dyad1 = bytestream_get_byte(data_ptr); ++ dyad2 = code; ++ if (dyad1 >= delta_tab->num_dyads || dyad1 >= 248) ++ return IV3_BAD_DATA; ++ } else { ++ /* process QUADS */ ++ code -= delta_tab->num_dyads; ++ dyad1 = code / delta_tab->quad_exp; ++ dyad2 = code % delta_tab->quad_exp; ++ if (swap_quads[line & 1]) ++ FFSWAP(unsigned int, dyad1, dyad2); ++ } ++ if (mode <= 4) { ++ APPLY_DELTA_4; ++ } else if (mode == 10 && !cell->mv_ptr) { ++ APPLY_DELTA_8; ++ } else { ++ APPLY_DELTA_1011_INTER; ++ } ++ } else { ++ /* process RLE codes */ ++ switch (code) { ++ case RLE_ESC_FC: ++ skip_flag = 0; ++ rle_blocks = 1; ++ code = 253; ++ /* FALLTHROUGH */ ++ case RLE_ESC_FF: ++ case RLE_ESC_FE: ++ case RLE_ESC_FD: ++ num_lines = 257 - code - line; ++ if (num_lines <= 0) ++ return IV3_BAD_RLE; ++ if (mode <= 4) { ++ RLE_LINES_COPY; ++ } else if (mode == 10 && !cell->mv_ptr) { ++ RLE_LINES_COPY_M10; ++ } ++ break; ++ case RLE_ESC_FB: ++ BUFFER_PRECHECK; ++ code = bytestream_get_byte(data_ptr); ++ rle_blocks = (code & 0x1F) - 1; /* set block counter */ ++ if (code >= 64 || rle_blocks < 0) ++ return IV3_BAD_COUNTER; ++ skip_flag = code & 0x20; ++ num_lines = 4 - line; /* enforce next block processing */ ++ if (mode >= 10 || (cell->mv_ptr || !skip_flag)) { ++ if (mode <= 4) { ++ RLE_LINES_COPY; ++ } else if (mode == 10 && !cell->mv_ptr) { ++ RLE_LINES_COPY_M10; + } +- case 6: +- if(ref_vectors != NULL) { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; ++ } ++ break; ++ case RLE_ESC_F9: ++ skip_flag = 1; ++ rle_blocks = 1; ++ /* FALLTHROUGH */ ++ case RLE_ESC_FA: ++ if (line) ++ return IV3_BAD_RLE; ++ num_lines = 4; /* enforce next block processing */ ++ if (cell->mv_ptr) { ++ if (mode <= 4) { ++ RLE_LINES_COPY; ++ } else if (mode == 10 && !cell->mv_ptr) { ++ RLE_LINES_COPY_M10; + } +- lp2 = 4; +- break; +- +- case 9: +- lv1 = *buf1++; +- lv = (lv1 & 0x7F) << 1; +- lv += (lv << 8); +- lv += (lv << 16); +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = lv; +- +- LV1_CHECK(buf1,rle_v3,lv1,lp2) +- break; +- default: +- return; + } ++ break; ++ default: ++ return IV3_UNSUPPORTED; + } +- +- cur_frm_pos += 4; +- ref_frm_pos += 4; + } + +- cur_frm_pos += ((width - blks_width) * 4); +- ref_frm_pos += ((width - blks_width) * 4); ++ line += num_lines; ++ ref += row_offset * (num_lines << v_zoom); ++ dst += row_offset * (num_lines << v_zoom); + } +- break; ++ } + +- case 4: +- case 3: /********** CASE 3 **********/ +- if(ref_vectors != NULL) +- return; +- flag1 = 1; +- +- for( ; blks_height > 0; blks_height -= 8) { +- for(lp1 = 0; lp1 < blks_width; lp1++) { +- for(lp2 = 0; lp2 < 4; ) { +- k = *buf1++; +- +- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; +- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; +- +- switch(correction_type_sp[lp2 & 0x01][k]) { +- case 0: +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); +- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- else +- cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); +- lp2++; +- break; +- +- case 1: +- res = ((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + correction_lp[lp2 & 0x01][*buf1]) << 1; +- ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res); +- res = ((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1; +- ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res); +- +- if(lp2 > 0 || flag1 == 0 || strip->ypos != 0) +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- else +- cur_lp[0] = cur_lp[width_tbl[1]]; +- buf1++; +- lp2++; +- break; +- +- case 2: +- if(lp2 == 0) { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = *ref_lp; +- lp2 += 2; +- } +- break; ++ /* move to next horizontal block */ ++ block += 4 << h_zoom; ++ ref_block += 4 << h_zoom; ++ } + +- case 3: +- if(lp2 < 2) { +- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) +- cur_lp[j] = *ref_lp; +- lp2 = 3; +- } +- break; ++ /* move to next line of blocks */ ++ ref_block += blk_row_offset; ++ block += blk_row_offset; ++ } ++ return IV3_NOERR; ++} + +- case 6: +- lp2 = 4; +- break; +- +- case 7: +- if(rle_v3 != 0) +- rle_v3 = 0; +- else { +- buf1--; +- rle_v3 = 1; +- } +- lp2 = 4; +- break; + +- case 8: +- if(lp2 == 0) { +- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) +- +- if(rle_v1 == 1) { +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- } +- +- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) +- break; +- } else { +- rle_v2 = (*buf1) - 1; +- rle_v1 = 1; +- } +- case 5: +- LP2_CHECK(buf1,rle_v3,lp2) +- case 4: +- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) +- cur_lp[j] = *ref_lp; +- lp2 = 4; +- break; +- +- case 9: +- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); +- lv1 = *buf1++; +- lv = (lv1 & 0x7F) << 1; +- lv += (lv << 8); +- lv += (lv << 16); ++/** ++ * Decode a vector-quantized cell. ++ * It consists of several routines, each of which handles one or more "modes" ++ * with which a cell can be encoded. ++ * ++ * @param ctx pointer to the decoder context ++ * @param avctx ptr to the AVCodecContext ++ * @param plane pointer to the plane descriptor ++ * @param cell pointer to the cell descriptor ++ * @param data_ptr pointer to the compressed data ++ * @param last_ptr pointer to the last byte to catch reads past end of buffer ++ * @return number of consumed bytes or negative number in case of error ++ */ ++static int decode_cell(Indeo3DecodeContext *ctx, AVCodecContext *avctx, ++ Plane *plane, Cell *cell, const uint8_t *data_ptr, ++ const uint8_t *last_ptr) ++{ ++ int x, mv_x, mv_y, mode, vq_index, prim_indx, second_indx; ++ int zoom_fac; ++ int offset, error = 0, swap_quads[2]; ++ uint8_t code, *block, *ref_block = 0; ++ const vqEntry *delta[2]; ++ const uint8_t *data_start = data_ptr; ++ ++ /* get coding mode and VQ table index from the VQ descriptor byte */ ++ code = *data_ptr++; ++ mode = code >> 4; ++ vq_index = code & 0xF; ++ ++ /* setup output and reference pointers */ ++ offset = (cell->ypos << 2) * plane->pitch + (cell->xpos << 2); ++ block = plane->pixels[ctx->buf_sel] + offset; ++ if (!cell->mv_ptr) { ++ /* use previous line as reference for INTRA cells */ ++ ref_block = block - plane->pitch; ++ } else if (mode >= 10) { ++ /* for mode 10 and 11 INTER first copy the predicted cell into the current one */ ++ /* so we don't need to do data copying for each RLE code later */ ++ copy_cell(ctx, plane, cell); ++ } else { ++ /* set the pointer to the reference pixels for modes 0-4 INTER */ ++ mv_y = cell->mv_ptr[0]; ++ mv_x = cell->mv_ptr[1]; ++ offset += mv_y * plane->pitch + mv_x; ++ ref_block = plane->pixels[ctx->buf_sel ^ 1] + offset; ++ } + +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = lv; ++ /* select VQ tables as follows: */ ++ /* modes 0 and 3 use only the primary table for all lines in a block */ ++ /* while modes 1 and 4 switch between primary and secondary tables on alternate lines */ ++ if (mode == 1 || mode == 4) { ++ code = ctx->alt_quant[vq_index]; ++ prim_indx = (code >> 4) + ctx->cb_offset; ++ second_indx = (code & 0xF) + ctx->cb_offset; ++ } else { ++ vq_index += ctx->cb_offset; ++ prim_indx = second_indx = vq_index; ++ } + +- LV1_CHECK(buf1,rle_v3,lv1,lp2) +- break; ++ if (prim_indx >= 24 || second_indx >= 24) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid VQ table indexes! Primary: %d, secondary: %d!\n", ++ prim_indx, second_indx); ++ return AVERROR_INVALIDDATA; ++ } + +- default: +- return; +- } +- } ++ delta[0] = &vq_tab[second_indx]; ++ delta[1] = &vq_tab[prim_indx]; ++ swap_quads[0] = second_indx >= 16; ++ swap_quads[1] = prim_indx >= 16; ++ ++ /* requantize the prediction if VQ index of this cell differs from VQ index */ ++ /* of the predicted cell in order to avoid overflows. */ ++ if (vq_index >= 8 && ref_block) { ++ for (x = 0; x < cell->width << 2; x++) ++ ref_block[x] = requant_tab[vq_index & 7][ref_block[x]]; ++ } + +- cur_frm_pos += 4; +- } ++ error = IV3_NOERR; + +- cur_frm_pos += (((width * 2) - blks_width) * 4); +- flag1 = 0; +- } +- break; ++ switch (mode) { ++ case 0: /*------------------ MODES 0 & 1 (4x4 block processing) --------------------*/ ++ case 1: ++ case 3: /*------------------ MODES 3 & 4 (4x8 block processing) --------------------*/ ++ case 4: ++ if (mode >= 3 && cell->mv_ptr) { ++ av_log(avctx, AV_LOG_ERROR, "Attempt to apply Mode 3/4 to an INTER cell!\n"); ++ return AVERROR_INVALIDDATA; ++ } + +- case 10: /********** CASE 10 **********/ +- if(ref_vectors == NULL) { +- flag1 = 1; +- +- for( ; blks_height > 0; blks_height -= 8) { +- for(lp1 = 0; lp1 < blks_width; lp1 += 2) { +- for(lp2 = 0; lp2 < 4; ) { +- k = *buf1++; +- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; +- ref_lp = ((uint32_t *)cur_frm_pos) + width_tbl[(lp2 * 2) - 1]; +- lv1 = ref_lp[0]; +- lv2 = ref_lp[1]; +- if(lp2 == 0 && flag1 != 0) { +-#if HAVE_BIGENDIAN +- lv1 = lv1 & 0xFF00FF00; +- lv1 = (lv1 >> 8) | lv1; +- lv2 = lv2 & 0xFF00FF00; +- lv2 = (lv2 >> 8) | lv2; +-#else +- lv1 = lv1 & 0x00FF00FF; +- lv1 = (lv1 << 8) | lv1; +- lv2 = lv2 & 0x00FF00FF; +- lv2 = (lv2 << 8) | lv2; +-#endif +- } ++ zoom_fac = mode >= 3; ++ error = decode_cell_data(cell, block, ref_block, plane->pitch, 0, zoom_fac, ++ mode, delta, swap_quads, &data_ptr, last_ptr); ++ break; ++ case 10: /*-------------------- MODE 10 (8x8 block processing) ---------------------*/ ++ case 11: /*----------------- MODE 11 (4x8 INTER block processing) ------------------*/ ++ if (mode == 10 && !cell->mv_ptr) { /* MODE 10 INTRA processing */ ++ error = decode_cell_data(cell, block, ref_block, plane->pitch, 1, 1, ++ mode, delta, swap_quads, &data_ptr, last_ptr); ++ } else { /* mode 10 and 11 INTER processing */ ++ if (mode == 11 && !cell->mv_ptr) { ++ av_log(avctx, AV_LOG_ERROR, "Attempt to use Mode 11 for an INTRA cell!\n"); ++ return AVERROR_INVALIDDATA; ++ } + +- switch(correction_type_sp[lp2 & 0x01][k]) { +- case 0: +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1); +- cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionhighorder_lp[lp2 & 0x01][k]) << 1); +- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- cur_lp[0] = cur_lp[width_tbl[1]]; +- cur_lp[1] = cur_lp[width_tbl[1]+1]; +- } +- lp2++; +- break; +- +- case 1: +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(lv1) >> 1) + correctionloworder_lp[lp2 & 0x01][*buf1]) << 1); +- cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(lv2) >> 1) + correctionloworder_lp[lp2 & 0x01][k]) << 1); +- if(lp2 > 0 || strip->ypos != 0 || flag1 == 0) { +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- cur_lp[0] = cur_lp[width_tbl[1]]; +- cur_lp[1] = cur_lp[width_tbl[1]+1]; +- } +- buf1++; +- lp2++; +- break; +- +- case 2: +- if(lp2 == 0) { +- if(flag1 != 0) { +- for(i = 0, j = width_tbl[1]; i < 3; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- } +- lp2 += 2; +- } +- break; +- +- case 3: +- if(lp2 < 2) { +- if(lp2 == 0 && flag1 != 0) { +- for(i = 0, j = width_tbl[1]; i < 5; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- } +- lp2 = 3; +- } +- break; +- +- case 8: +- if(lp2 == 0) { +- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) +- if(rle_v1 == 1) { +- if(flag1 != 0) { +- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- } +- } +- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) +- break; +- } else { +- rle_v1 = 1; +- rle_v2 = (*buf1) - 1; +- } +- case 5: +- LP2_CHECK(buf1,rle_v3,lp2) +- case 4: +- if(lp2 == 0 && flag1 != 0) { +- for(i = 0, j = width_tbl[1]; i < 7; i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- cur_lp[0] = ((cur_lp[-width_tbl[1]] >> 1) + (cur_lp[width_tbl[1]] >> 1)) & 0xFEFEFEFE; +- cur_lp[1] = ((cur_lp[-width_tbl[1]+1] >> 1) + (cur_lp[width_tbl[1]+1] >> 1)) & 0xFEFEFEFE; +- } else { +- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { +- cur_lp[j] = lv1; +- cur_lp[j+1] = lv2; +- } +- } +- lp2 = 4; +- break; +- +- case 6: +- lp2 = 4; +- break; +- +- case 7: +- if(lp2 == 0) { +- if(rle_v3 != 0) +- rle_v3 = 0; +- else { +- buf1--; +- rle_v3 = 1; +- } +- lp2 = 4; +- } +- break; +- +- case 9: +- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); +- lv1 = *buf1; +- lv = (lv1 & 0x7F) << 1; +- lv += (lv << 8); +- lv += (lv << 16); +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) +- cur_lp[j] = lv; +- LV1_CHECK(buf1,rle_v3,lv1,lp2) +- break; ++ zoom_fac = mode == 10; ++ error = decode_cell_data(cell, block, ref_block, plane->pitch, ++ zoom_fac, 1, mode, delta, swap_quads, ++ &data_ptr, last_ptr); ++ } ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Unsupported coding mode: %d\n", mode); ++ return AVERROR_INVALIDDATA; ++ }//switch mode ++ ++ switch (error) { ++ case IV3_BAD_RLE: ++ av_log(avctx, AV_LOG_ERROR, "Mode %d: RLE code %X is not allowed at the current line\n", ++ mode, data_ptr[-1]); ++ return AVERROR_INVALIDDATA; ++ case IV3_BAD_DATA: ++ av_log(avctx, AV_LOG_ERROR, "Mode %d: invalid VQ data\n", mode); ++ return AVERROR_INVALIDDATA; ++ case IV3_BAD_COUNTER: ++ av_log(avctx, AV_LOG_ERROR, "Mode %d: RLE-FB invalid counter: %d\n", mode, code); ++ return AVERROR_INVALIDDATA; ++ case IV3_UNSUPPORTED: ++ av_log(avctx, AV_LOG_ERROR, "Mode %d: unsupported RLE code: %X\n", mode, data_ptr[-1]); ++ return AVERROR_INVALIDDATA; ++ case IV3_OUT_OF_DATA: ++ av_log(avctx, AV_LOG_ERROR, "Mode %d: attempt to read past end of buffer\n", mode); ++ return AVERROR_INVALIDDATA; ++ } + +- default: +- return; +- } +- } ++ return data_ptr - data_start; /* report number of bytes consumed from the input buffer */ ++} + +- cur_frm_pos += 8; +- } + +- cur_frm_pos += (((width * 2) - blks_width) * 4); +- flag1 = 0; +- } +- } else { +- for( ; blks_height > 0; blks_height -= 8) { +- for(lp1 = 0; lp1 < blks_width; lp1 += 2) { +- for(lp2 = 0; lp2 < 4; ) { +- k = *buf1++; +- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; +- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; +- +- switch(correction_type_sp[lp2 & 0x01][k]) { +- case 0: +- lv1 = correctionloworder_lp[lp2 & 0x01][k]; +- lv2 = correctionhighorder_lp[lp2 & 0x01][k]; +- cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1); +- cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1); +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); +- cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); +- lp2++; +- break; +- +- case 1: +- lv1 = correctionloworder_lp[lp2 & 0x01][*buf1++]; +- lv2 = correctionloworder_lp[lp2 & 0x01][k]; +- cur_lp[0] = av_le2ne32(((av_le2ne32(ref_lp[0]) >> 1) + lv1) << 1); +- cur_lp[1] = av_le2ne32(((av_le2ne32(ref_lp[1]) >> 1) + lv2) << 1); +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + lv1) << 1); +- cur_lp[width_tbl[1]+1] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]+1]) >> 1) + lv2) << 1); +- lp2++; +- break; +- +- case 2: +- if(lp2 == 0) { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) { +- cur_lp[j] = ref_lp[j]; +- cur_lp[j+1] = ref_lp[j+1]; +- } +- lp2 += 2; +- } +- break; +- +- case 3: +- if(lp2 < 2) { +- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) { +- cur_lp[j] = ref_lp[j]; +- cur_lp[j+1] = ref_lp[j+1]; +- } +- lp2 = 3; +- } +- break; +- +- case 8: +- if(lp2 == 0) { +- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) { +- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)ref_frm_pos)[j]; +- ((uint32_t *)cur_frm_pos)[j+1] = ((uint32_t *)ref_frm_pos)[j+1]; +- } +- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) +- break; +- } else { +- rle_v1 = 1; +- rle_v2 = (*buf1) - 1; +- } +- case 5: +- case 7: +- LP2_CHECK(buf1,rle_v3,lp2) +- case 6: +- case 4: +- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) { +- cur_lp[j] = ref_lp[j]; +- cur_lp[j+1] = ref_lp[j+1]; +- } +- lp2 = 4; +- break; +- +- case 9: +- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); +- lv1 = *buf1; +- lv = (lv1 & 0x7F) << 1; +- lv += (lv << 8); +- lv += (lv << 16); +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) +- ((uint32_t *)cur_frm_pos)[j] = ((uint32_t *)cur_frm_pos)[j+1] = lv; +- LV1_CHECK(buf1,rle_v3,lv1,lp2) +- break; ++/* Binary tree codes. */ ++enum { ++ H_SPLIT = 0, ++ V_SPLIT = 1, ++ INTRA_NULL = 2, ++ INTER_DATA = 3 ++}; + +- default: +- return; +- } +- } + +- cur_frm_pos += 8; +- ref_frm_pos += 8; +- } ++#define SPLIT_CELL(size, new_size) (new_size) = ((size) > 2) ? ((((size) + 2) >> 2) << 1) : 1 + +- cur_frm_pos += (((width * 2) - blks_width) * 4); +- ref_frm_pos += (((width * 2) - blks_width) * 4); +- } +- } +- break; ++#define UPDATE_BITPOS(n) \ ++ ctx->skip_bits += (n); \ ++ ctx->need_resync = 1 ++ ++#define RESYNC_BITSTREAM \ ++ if (ctx->need_resync && !(get_bits_count(&ctx->gb) & 7)) { \ ++ skip_bits_long(&ctx->gb, ctx->skip_bits); \ ++ ctx->skip_bits = 0; \ ++ ctx->need_resync = 0; \ ++ } + +- case 11: /********** CASE 11 **********/ +- if(ref_vectors == NULL) +- return; +- +- for( ; blks_height > 0; blks_height -= 8) { +- for(lp1 = 0; lp1 < blks_width; lp1++) { +- for(lp2 = 0; lp2 < 4; ) { +- k = *buf1++; +- cur_lp = ((uint32_t *)cur_frm_pos) + width_tbl[lp2 * 2]; +- ref_lp = ((uint32_t *)ref_frm_pos) + width_tbl[lp2 * 2]; +- +- switch(correction_type_sp[lp2 & 0x01][k]) { +- case 0: +- cur_lp[0] = av_le2ne32(((av_le2ne32(*ref_lp) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); +- cur_lp[width_tbl[1]] = av_le2ne32(((av_le2ne32(ref_lp[width_tbl[1]]) >> 1) + correction_lp[lp2 & 0x01][k]) << 1); +- lp2++; +- break; +- +- case 1: +- lv1 = (unsigned short)(correction_lp[lp2 & 0x01][*buf1++]); +- lv2 = (unsigned short)(correction_lp[lp2 & 0x01][k]); +- res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[0]) >> 1) + lv1) << 1); +- ((unsigned short *)cur_lp)[0] = av_le2ne16(res); +- res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[1]) >> 1) + lv2) << 1); +- ((unsigned short *)cur_lp)[1] = av_le2ne16(res); +- res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]]) >> 1) + lv1) << 1); +- ((unsigned short *)cur_lp)[width_tbl[2]] = av_le2ne16(res); +- res = (unsigned short)(((av_le2ne16(((unsigned short *)ref_lp)[width_tbl[2]+1]) >> 1) + lv2) << 1); +- ((unsigned short *)cur_lp)[width_tbl[2]+1] = av_le2ne16(res); +- lp2++; +- break; +- +- case 2: +- if(lp2 == 0) { +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 += 2; +- } +- break; ++#define CHECK_CELL \ ++ if (curr_cell.xpos + curr_cell.width > (plane->width >> 2) || \ ++ curr_cell.ypos + curr_cell.height > (plane->height >> 2)) { \ ++ av_log(avctx, AV_LOG_ERROR, "Invalid cell: x=%d, y=%d, w=%d, h=%d\n", \ ++ curr_cell.xpos, curr_cell.ypos, curr_cell.width, curr_cell.height); \ ++ return AVERROR_INVALIDDATA; \ ++ } + +- case 3: +- if(lp2 < 2) { +- for(i = 0, j = 0; i < 6 - (lp2 * 2); i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 = 3; +- } +- break; + +- case 8: +- if(lp2 == 0) { +- RLE_V3_CHECK(buf1,rle_v1,rle_v2,rle_v3) +- +- for(i = 0, j = 0; i < 8; i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- +- RLE_V2_CHECK(buf1,rle_v2, rle_v3,lp2) +- break; +- } else { +- rle_v1 = 1; +- rle_v2 = (*buf1) - 1; +- } +- case 5: +- case 7: +- LP2_CHECK(buf1,rle_v3,lp2) +- case 4: +- case 6: +- for(i = 0, j = 0; i < 8 - (lp2 * 2); i++, j += width_tbl[1]) +- cur_lp[j] = ref_lp[j]; +- lp2 = 4; +- break; +- +- case 9: +- av_log(s->avctx, AV_LOG_ERROR, "UNTESTED.\n"); +- lv1 = *buf1++; +- lv = (lv1 & 0x7F) << 1; +- lv += (lv << 8); +- lv += (lv << 16); +- for(i = 0, j = 0; i < 4; i++, j += width_tbl[1]) +- cur_lp[j] = lv; +- LV1_CHECK(buf1,rle_v3,lv1,lp2) +- break; ++static int parse_bintree(Indeo3DecodeContext *ctx, AVCodecContext *avctx, ++ Plane *plane, int code, Cell *ref_cell, ++ const int depth, const int strip_width) ++{ ++ Cell curr_cell; ++ int bytes_used; + +- default: +- return; +- } +- } ++ if (depth <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "Stack overflow (corrupted binary tree)!\n"); ++ return AVERROR_INVALIDDATA; // unwind recursion ++ } + +- cur_frm_pos += 4; +- ref_frm_pos += 4; +- } ++ curr_cell = *ref_cell; // clone parent cell ++ if (code == H_SPLIT) { ++ SPLIT_CELL(ref_cell->height, curr_cell.height); ++ ref_cell->ypos += curr_cell.height; ++ ref_cell->height -= curr_cell.height; ++ if (ref_cell->height <= 0 || curr_cell.height <= 0) ++ return AVERROR_INVALIDDATA; ++ } else if (code == V_SPLIT) { ++ if (curr_cell.width > strip_width) { ++ /* split strip */ ++ curr_cell.width = (curr_cell.width <= (strip_width << 1) ? 1 : 2) * strip_width; ++ } else ++ SPLIT_CELL(ref_cell->width, curr_cell.width); ++ ref_cell->xpos += curr_cell.width; ++ ref_cell->width -= curr_cell.width; ++ if (ref_cell->width <= 0 || curr_cell.width <= 0) ++ return AVERROR_INVALIDDATA; ++ } + +- cur_frm_pos += (((width * 2) - blks_width) * 4); +- ref_frm_pos += (((width * 2) - blks_width) * 4); ++ while (get_bits_left(&ctx->gb) >= 2) { /* loop until return */ ++ RESYNC_BITSTREAM; ++ switch (code = get_bits(&ctx->gb, 2)) { ++ case H_SPLIT: ++ case V_SPLIT: ++ if (parse_bintree(ctx, avctx, plane, code, &curr_cell, depth - 1, strip_width)) ++ return AVERROR_INVALIDDATA; ++ break; ++ case INTRA_NULL: ++ if (!curr_cell.tree) { /* MC tree INTRA code */ ++ curr_cell.mv_ptr = 0; /* mark the current strip as INTRA */ ++ curr_cell.tree = 1; /* enter the VQ tree */ ++ } else { /* VQ tree NULL code */ ++ RESYNC_BITSTREAM; ++ code = get_bits(&ctx->gb, 2); ++ if (code >= 2) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid VQ_NULL code: %d\n", code); ++ return AVERROR_INVALIDDATA; + } +- break; ++ if (code == 1) ++ av_log(avctx, AV_LOG_ERROR, "SkipCell procedure not implemented yet!\n"); + +- default: +- return; ++ CHECK_CELL ++ if (!curr_cell.mv_ptr) ++ return AVERROR_INVALIDDATA; ++ copy_cell(ctx, plane, &curr_cell); ++ return 0; + } +- } +- +- for( ; strip >= strip_tbl; strip--) { +- if(strip->split_flag != 0) { +- strip->split_flag = 0; +- strip->usl7 = (strip-1)->usl7; +- +- if(strip->split_direction) { +- strip->xpos += strip->width; +- strip->width = (strip-1)->width - strip->width; +- if(region_160_width <= strip->xpos && width < strip->width + strip->xpos) +- strip->width = width - strip->xpos; +- } else { +- strip->ypos += strip->height; +- strip->height = (strip-1)->height - strip->height; ++ break; ++ case INTER_DATA: ++ if (!curr_cell.tree) { /* MC tree INTER code */ ++ unsigned mv_idx; ++ /* get motion vector index and setup the pointer to the mv set */ ++ if (!ctx->need_resync) ++ ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3]; ++ mv_idx = *(ctx->next_cell_data++); ++ if (mv_idx >= ctx->num_vectors) { ++ av_log(avctx, AV_LOG_ERROR, "motion vector index out of range\n"); ++ return AVERROR_INVALIDDATA; + } +- break; ++ curr_cell.mv_ptr = &ctx->mc_vectors[mv_idx << 1]; ++ curr_cell.tree = 1; /* enter the VQ tree */ ++ UPDATE_BITPOS(8); ++ } else { /* VQ tree DATA code */ ++ if (!ctx->need_resync) ++ ctx->next_cell_data = &ctx->gb.buffer[(get_bits_count(&ctx->gb) + 7) >> 3]; ++ ++ CHECK_CELL ++ bytes_used = decode_cell(ctx, avctx, plane, &curr_cell, ++ ctx->next_cell_data, ctx->last_byte); ++ if (bytes_used < 0) ++ return AVERROR_INVALIDDATA; ++ ++ UPDATE_BITPOS(bytes_used << 3); ++ ctx->next_cell_data += bytes_used; ++ return 0; + } ++ break; + } +- } ++ }//while ++ ++ return AVERROR_INVALIDDATA; + } + +-static av_cold int indeo3_decode_init(AVCodecContext *avctx) ++ ++static int decode_plane(Indeo3DecodeContext *ctx, AVCodecContext *avctx, ++ Plane *plane, const uint8_t *data, int32_t data_size, ++ int32_t strip_width) + { +- Indeo3DecodeContext *s = avctx->priv_data; +- int ret = 0; ++ Cell curr_cell; ++ unsigned num_vectors; + +- s->avctx = avctx; +- s->width = avctx->width; +- s->height = avctx->height; +- avctx->pix_fmt = PIX_FMT_YUV410P; ++ /* each plane data starts with mc_vector_count field, */ ++ /* an optional array of motion vectors followed by the vq data */ ++ num_vectors = bytestream_get_le32(&data); ++ if (num_vectors > 256) { ++ av_log(ctx->avctx, AV_LOG_ERROR, ++ "Read invalid number of motion vectors %d\n", num_vectors); ++ return AVERROR_INVALIDDATA; ++ } ++ if (num_vectors * 2 >= data_size) ++ return AVERROR_INVALIDDATA; ++ ++ ctx->num_vectors = num_vectors; ++ ctx->mc_vectors = num_vectors ? data : 0; + +- if (!(ret = build_modpred(s))) +- ret = iv_alloc_frames(s); +- if (ret) +- iv_free_func(s); ++ /* init the bitreader */ ++ init_get_bits(&ctx->gb, &data[num_vectors * 2], (data_size - num_vectors * 2) << 3); ++ ctx->skip_bits = 0; ++ ctx->need_resync = 0; ++ ++ ctx->last_byte = data + data_size - 1; ++ ++ /* initialize the 1st cell and set its dimensions to whole plane */ ++ curr_cell.xpos = curr_cell.ypos = 0; ++ curr_cell.width = plane->width >> 2; ++ curr_cell.height = plane->height >> 2; ++ curr_cell.tree = 0; // we are in the MC tree now ++ curr_cell.mv_ptr = 0; // no motion vector = INTRA cell + +- return ret; ++ return parse_bintree(ctx, avctx, plane, INTRA_NULL, &curr_cell, CELL_STACK_MAX, strip_width); + } + +-static int iv_decode_frame(AVCodecContext *avctx, +- const uint8_t *buf, int buf_size) ++ ++#define OS_HDR_ID MKBETAG('F', 'R', 'M', 'H') ++ ++static int decode_frame_headers(Indeo3DecodeContext *ctx, AVCodecContext *avctx, ++ const uint8_t *buf, int buf_size) + { +- Indeo3DecodeContext *s = avctx->priv_data; +- unsigned int image_width, image_height, +- chroma_width, chroma_height; +- unsigned long flags, cb_offset, data_size, +- y_offset, v_offset, u_offset, mc_vector_count; +- const uint8_t *hdr_pos, *buf_pos; +- +- buf_pos = buf; +- buf_pos += 18; /* skip OS header (16 bytes) and version number */ +- +- flags = bytestream_get_le16(&buf_pos); +- data_size = bytestream_get_le32(&buf_pos); +- cb_offset = *buf_pos++; +- buf_pos += 3; /* skip reserved byte and checksum */ +- image_height = bytestream_get_le16(&buf_pos); +- image_width = bytestream_get_le16(&buf_pos); +- +- if(av_image_check_size(image_width, image_height, 0, avctx)) +- return -1; +- if (image_width != avctx->width || image_height != avctx->height) { +- int ret; +- avcodec_set_dimensions(avctx, image_width, image_height); +- s->width = avctx->width; +- s->height = avctx->height; +- ret = iv_alloc_frames(s); +- if (ret < 0) { +- s->width = s->height = 0; +- return ret; +- } ++ const uint8_t *buf_ptr = buf, *bs_hdr; ++ uint32_t frame_num, word2, check_sum, data_size; ++ uint32_t y_offset, u_offset, v_offset, starts[3], ends[3]; ++ uint16_t height, width; ++ int i, j; ++ ++ /* parse and check the OS header */ ++ frame_num = bytestream_get_le32(&buf_ptr); ++ word2 = bytestream_get_le32(&buf_ptr); ++ check_sum = bytestream_get_le32(&buf_ptr); ++ data_size = bytestream_get_le32(&buf_ptr); ++ ++ if ((frame_num ^ word2 ^ data_size ^ OS_HDR_ID) != check_sum) { ++ av_log(avctx, AV_LOG_ERROR, "OS header checksum mismatch!\n"); ++ return AVERROR_INVALIDDATA; + } + +- chroma_height = ((image_height >> 2) + 3) & 0x7ffc; +- chroma_width = ((image_width >> 2) + 3) & 0x7ffc; +- y_offset = bytestream_get_le32(&buf_pos); +- v_offset = bytestream_get_le32(&buf_pos); +- u_offset = bytestream_get_le32(&buf_pos); +- buf_pos += 4; /* reserved */ +- hdr_pos = buf_pos; +- if(data_size == 0x80) return 4; +- +- if(FFMAX3(y_offset, v_offset, u_offset) >= buf_size-16) { +- av_log(s->avctx, AV_LOG_ERROR, "y/u/v offset outside buffer\n"); +- return -1; +- } +- +- if(flags & 0x200) { +- s->cur_frame = s->iv_frame + 1; +- s->ref_frame = s->iv_frame; +- } else { +- s->cur_frame = s->iv_frame; +- s->ref_frame = s->iv_frame + 1; ++ /* parse the bitstream header */ ++ bs_hdr = buf_ptr; ++ ++ if (bytestream_get_le16(&buf_ptr) != 32) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported codec version!\n"); ++ return AVERROR_INVALIDDATA; + } + +- buf_pos = buf + 16 + y_offset; +- mc_vector_count = bytestream_get_le32(&buf_pos); +- if(2LL*mc_vector_count >= buf_size-16-y_offset) { +- av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); +- return -1; ++ ctx->frame_num = frame_num; ++ ctx->frame_flags = bytestream_get_le16(&buf_ptr); ++ ctx->data_size = (bytestream_get_le32(&buf_ptr) + 7) >> 3; ++ ctx->cb_offset = *buf_ptr++; ++ ++ if (ctx->data_size == 16) ++ return 4; ++ if (ctx->data_size > buf_size) ++ ctx->data_size = buf_size; ++ ++ buf_ptr += 3; // skip reserved byte and checksum ++ ++ /* check frame dimensions */ ++ height = bytestream_get_le16(&buf_ptr); ++ width = bytestream_get_le16(&buf_ptr); ++ if (av_image_check_size(width, height, 0, avctx)) ++ return AVERROR_INVALIDDATA; ++ ++ if (width != ctx->width || height != ctx->height) { ++ int res; ++ ++ av_dlog(avctx, "Frame dimensions changed!\n"); ++ ++ ctx->width = width; ++ ctx->height = height; ++ ++ free_frame_buffers(ctx); ++ if ((res = allocate_frame_buffers(ctx, avctx)) < 0) ++ return res; ++ avcodec_set_dimensions(avctx, width, height); + } + +- iv_Decode_Chunk(s, s->cur_frame->Ybuf, s->ref_frame->Ybuf, image_width, +- image_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, +- FFMIN(image_width, 160)); ++ y_offset = bytestream_get_le32(&buf_ptr); ++ v_offset = bytestream_get_le32(&buf_ptr); ++ u_offset = bytestream_get_le32(&buf_ptr); ++ ++ /* unfortunately there is no common order of planes in the buffer */ ++ /* so we use that sorting algo for determining planes data sizes */ ++ starts[0] = y_offset; ++ starts[1] = v_offset; ++ starts[2] = u_offset; ++ ++ for (j = 0; j < 3; j++) { ++ ends[j] = ctx->data_size; ++ for (i = 2; i >= 0; i--) ++ if (starts[i] < ends[j] && starts[i] > starts[j]) ++ ends[j] = starts[i]; ++ } + +- if (!(s->avctx->flags & CODEC_FLAG_GRAY)) +- { ++ ctx->y_data_size = ends[0] - starts[0]; ++ ctx->v_data_size = ends[1] - starts[1]; ++ ctx->u_data_size = ends[2] - starts[2]; ++ if (FFMAX3(y_offset, v_offset, u_offset) >= ctx->data_size - 16 || ++ FFMIN3(ctx->y_data_size, ctx->v_data_size, ctx->u_data_size) <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "One of the y/u/v offsets is invalid\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->y_data_ptr = bs_hdr + y_offset; ++ ctx->v_data_ptr = bs_hdr + v_offset; ++ ctx->u_data_ptr = bs_hdr + u_offset; ++ ctx->alt_quant = buf_ptr + sizeof(uint32_t); ++ ++ if (ctx->data_size == 16) { ++ av_log(avctx, AV_LOG_DEBUG, "Sync frame encountered!\n"); ++ return 16; ++ } ++ ++ if (ctx->frame_flags & BS_8BIT_PEL) { ++ av_log_ask_for_sample(avctx, "8-bit pixel format\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ if (ctx->frame_flags & BS_MV_X_HALF || ctx->frame_flags & BS_MV_Y_HALF) { ++ av_log_ask_for_sample(avctx, "halfpel motion vectors\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ return 0; ++} + +- buf_pos = buf + 16 + v_offset; +- mc_vector_count = bytestream_get_le32(&buf_pos); +- if(2LL*mc_vector_count >= buf_size-16-v_offset) { +- av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); +- return -1; +- } + +- iv_Decode_Chunk(s, s->cur_frame->Vbuf, s->ref_frame->Vbuf, chroma_width, +- chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, +- FFMIN(chroma_width, 40)); +- +- buf_pos = buf + 16 + u_offset; +- mc_vector_count = bytestream_get_le32(&buf_pos); +- if(2LL*mc_vector_count >= buf_size-16-u_offset) { +- av_log(s->avctx, AV_LOG_ERROR, "mc_vector_count too large\n"); +- return -1; ++/** ++ * Convert and output the current plane. ++ * All pixel values will be upsampled by shifting right by one bit. ++ * ++ * @param[in] plane pointer to the descriptor of the plane being processed ++ * @param[in] buf_sel indicates which frame buffer the input data stored in ++ * @param[out] dst pointer to the buffer receiving converted pixels ++ * @param[in] dst_pitch pitch for moving to the next y line ++ */ ++static void output_plane(const Plane *plane, int buf_sel, uint8_t *dst, int dst_pitch) ++{ ++ int x,y; ++ const uint8_t *src = plane->pixels[buf_sel]; ++ uint32_t pitch = plane->pitch; ++ ++ for (y = 0; y < plane->height; y++) { ++ /* convert four pixels at once using SWAR */ ++ for (x = 0; x < plane->width >> 2; x++) { ++ AV_WN32A(dst, (AV_RN32A(src) & 0x7F7F7F7F) << 1); ++ src += 4; ++ dst += 4; + } + +- iv_Decode_Chunk(s, s->cur_frame->Ubuf, s->ref_frame->Ubuf, chroma_width, +- chroma_height, buf_pos + mc_vector_count * 2, cb_offset, hdr_pos, buf_pos, +- FFMIN(chroma_width, 40)); ++ for (x <<= 2; x < plane->width; x++) ++ *dst++ = *src++ << 1; + ++ src += pitch - plane->width; ++ dst += dst_pitch - plane->width; + } ++} ++ ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ Indeo3DecodeContext *ctx = avctx->priv_data; ++ ++ ctx->avctx = avctx; ++ ctx->width = avctx->width; ++ ctx->height = avctx->height; ++ avctx->pix_fmt = PIX_FMT_YUV410P; ++ avcodec_get_frame_defaults(&ctx->frame); + +- return 8; ++ build_requant_tab(); ++ ++ dsputil_init(&ctx->dsp, avctx); ++ ++ return allocate_frame_buffers(ctx, avctx); + } + +-static int indeo3_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) + { ++ Indeo3DecodeContext *ctx = avctx->priv_data; + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- Indeo3DecodeContext *s=avctx->priv_data; +- uint8_t *src, *dest; +- int y; +- +- if (iv_decode_frame(avctx, buf, buf_size) < 0) +- return -1; +- +- if(s->frame.data[0]) +- avctx->release_buffer(avctx, &s->frame); +- +- s->frame.reference = 0; +- if(avctx->get_buffer(avctx, &s->frame) < 0) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; +- } +- +- src = s->cur_frame->Ybuf; +- dest = s->frame.data[0]; +- for (y = 0; y < s->height; y++) { +- memcpy(dest, src, s->cur_frame->y_w); +- src += s->cur_frame->y_w; +- dest += s->frame.linesize[0]; +- } +- +- if (!(s->avctx->flags & CODEC_FLAG_GRAY)) +- { +- src = s->cur_frame->Ubuf; +- dest = s->frame.data[1]; +- for (y = 0; y < s->height / 4; y++) { +- memcpy(dest, src, s->cur_frame->uv_w); +- src += s->cur_frame->uv_w; +- dest += s->frame.linesize[1]; +- } ++ int buf_size = avpkt->size; ++ int res; + +- src = s->cur_frame->Vbuf; +- dest = s->frame.data[2]; +- for (y = 0; y < s->height / 4; y++) { +- memcpy(dest, src, s->cur_frame->uv_w); +- src += s->cur_frame->uv_w; +- dest += s->frame.linesize[2]; +- } ++ res = decode_frame_headers(ctx, avctx, buf, buf_size); ++ if (res < 0) ++ return res; ++ ++ /* skip sync(null) frames */ ++ if (res) { ++ // we have processed 16 bytes but no data was decoded ++ *data_size = 0; ++ return buf_size; + } + +- *data_size=sizeof(AVFrame); +- *(AVFrame*)data= s->frame; ++ /* skip droppable INTER frames if requested */ ++ if (ctx->frame_flags & BS_NONREF && ++ (avctx->skip_frame >= AVDISCARD_NONREF)) ++ return 0; ++ ++ /* skip INTER frames if requested */ ++ if (!(ctx->frame_flags & BS_KEYFRAME) && avctx->skip_frame >= AVDISCARD_NONKEY) ++ return 0; ++ ++ /* use BS_BUFFER flag for buffer switching */ ++ ctx->buf_sel = (ctx->frame_flags >> BS_BUFFER) & 1; ++ ++ /* decode luma plane */ ++ if ((res = decode_plane(ctx, avctx, ctx->planes, ctx->y_data_ptr, ctx->y_data_size, 40))) ++ return res; ++ ++ /* decode chroma planes */ ++ if ((res = decode_plane(ctx, avctx, &ctx->planes[1], ctx->u_data_ptr, ctx->u_data_size, 10))) ++ return res; ++ ++ if ((res = decode_plane(ctx, avctx, &ctx->planes[2], ctx->v_data_ptr, ctx->v_data_size, 10))) ++ return res; ++ ++ if (ctx->frame.data[0]) ++ avctx->release_buffer(avctx, &ctx->frame); ++ ++ ctx->frame.reference = 0; ++ if ((res = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(ctx->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return res; ++ } ++ ++ output_plane(&ctx->planes[0], ctx->buf_sel, ctx->frame.data[0], ctx->frame.linesize[0]); ++ output_plane(&ctx->planes[1], ctx->buf_sel, ctx->frame.data[1], ctx->frame.linesize[1]); ++ output_plane(&ctx->planes[2], ctx->buf_sel, ctx->frame.data[2], ctx->frame.linesize[2]); ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = ctx->frame; + + return buf_size; + } + +-static av_cold int indeo3_decode_end(AVCodecContext *avctx) ++ ++static av_cold int decode_close(AVCodecContext *avctx) + { +- Indeo3DecodeContext *s = avctx->priv_data; ++ Indeo3DecodeContext *ctx = avctx->priv_data; ++ ++ free_frame_buffers(avctx->priv_data); + +- iv_free_func(s); ++ if (ctx->frame.data[0]) ++ avctx->release_buffer(avctx, &ctx->frame); + + return 0; + } + + AVCodec ff_indeo3_decoder = { +- "indeo3", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_INDEO3, +- sizeof(Indeo3DecodeContext), +- indeo3_decode_init, +- NULL, +- indeo3_decode_end, +- indeo3_decode_frame, +- CODEC_CAP_DR1, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"), ++ .name = "indeo3", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_INDEO3, ++ .priv_data_size = sizeof(Indeo3DecodeContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo 3"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo3data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo3data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo3data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo3data.h 2012-05-14 14:08:53.868330603 +0200 +@@ -1,6 +1,6 @@ + /* +- * Intel Indeo 3 (IV31, IV32, etc.) video decoder for ffmpeg +- * written, produced, and directed by Alan Smithee ++ * Indeo Video v3 compatible decoder ++ * Copyright (c) 2009 - 2011 Maxim Poliakovski + * + * This file is part of FFmpeg. + * +@@ -24,2319 +24,339 @@ + + #include + +-static const uint32_t correction[] = { +- 0x00000000, 0x00000202, 0xfffffdfe, 0x000002ff, 0xfffffd01, 0xffffff03, 0x000000fd, 0x00000404, +- 0xfffffbfc, 0x00000501, 0xfffffaff, 0x00000105, 0xfffffefb, 0x000003fc, 0xfffffc04, 0x000005fe, +- 0xfffffa02, 0xfffffe06, 0x000001fa, 0x00000904, 0xfffff6fc, 0x00000409, 0xfffffbf7, 0x00000909, +- 0xfffff6f7, 0x00000a01, 0xfffff5ff, 0x0000010a, 0xfffffef6, 0x000007fb, 0xfffff805, 0xfffffb08, +- 0x000004f8, 0x00000f09, 0xfffff0f7, 0x0000090f, 0xfffff6f1, 0x00000bfd, 0xfffff403, 0xfffffd0c, +- 0x000002f4, 0x00001004, 0xffffeffc, 0x00000410, 0xfffffbf0, 0x00001010, 0xffffeff0, 0x00001200, +- 0xffffee00, 0x00000012, 0xffffffee, 0x00000bf4, 0xfffff40c, 0x00000ff7, 0xfffff009, 0xfffff710, +- 0x000008f0, 0x00001b0b, 0xffffe4f5, 0x00000b1b, 0xfffff4e5, 0x00001c13, 0xffffe3ed, 0x0000131c, +- 0xffffece4, 0x000015fa, 0xffffea06, 0xfffffa16, 0x000005ea, 0x00001d04, 0xffffe2fc, 0x0000041d, +- 0xfffffbe3, 0x00001e1e, 0xffffe1e2, 0x000020fe, 0xffffdf02, 0xfffffe21, 0x000001df, 0x000016ee, +- 0xffffe912, 0xffffee17, 0x000011e9, 0x00001df1, 0xffffe20f, 0xfffff11e, 0x00000ee2, 0x00002e16, +- 0xffffd1ea, 0x0000162e, 0xffffe9d2, 0x00002f0d, 0xffffd0f3, 0x00000d2f, 0xfffff2d1, 0x00003123, +- 0xffffcedd, 0x00002331, 0xffffdccf, 0x000028f5, 0xffffd70b, 0xfffff529, 0x00000ad7, 0x00003304, +- 0xffffccfc, 0x00000433, 0xfffffbcd, 0x00003636, 0xffffc9ca, 0x000021de, 0xffffde22, 0x000029e3, +- 0xffffd61d, 0xffffe32a, 0x00001cd6, 0x00003bfa, 0xffffc406, 0xfffffa3c, 0x000005c4, 0x00004c1b, +- 0xffffb3e5, 0x00001b4c, 0xffffe4b4, 0x00004d2b, 0xffffb2d5, 0x00002b4d, 0xffffd4b3, 0x000036e8, +- 0xffffc918, 0xffffe837, 0x000017c9, 0x00004f0e, 0xffffb0f2, 0x00000e4f, 0xfffff1b1, 0x0000533f, +- 0xffffacc1, 0x00003f53, 0xffffc0ad, 0x000049ec, 0xffffb614, 0xffffec4a, 0x000013b6, 0x00005802, +- 0xffffa7fe, 0x00000258, 0xfffffda8, 0x00005d5d, 0xffffa2a3, 0x00003ccc, 0xffffc334, 0xffffcc3d, +- 0x000033c3, 0x00007834, 0xffff87cc, 0x00003478, 0xffffcb88, 0x00004ad3, 0xffffb52d, 0xffffd34b, +- 0x00002cb5, 0x00007d4b, 0xffff82b5, 0x00004b7d, 0xffffb483, 0x00007a21, 0xffff85df, 0x0000217a, +- 0xffffde86, 0x000066f3, 0xffff990d, 0xfffff367, 0x00000c99, 0x00005fd8, 0xffffa028, 0xffffd860, +- 0x000027a0, 0x00007ede, 0xffff8122, 0xffffde7f, 0x00002181, 0x000058a7, 0xffffa759, 0x000068b2, +- 0xffff974e, 0xffffb269, 0x00004d97, 0x00000c0c, 0xfffff3f4, 0x00001717, 0xffffe8e9, 0x00002a2a, +- 0xffffd5d6, 0x00004949, 0xffffb6b7, 0x00000000, 0x02020000, 0xfdfe0000, 0x02ff0000, 0xfd010000, +- 0xff030000, 0x00fd0000, 0x00000202, 0x02020202, 0xfdfe0202, 0x02ff0202, 0xfd010202, 0xff030202, +- 0x00fd0202, 0xfffffdfe, 0x0201fdfe, 0xfdfdfdfe, 0x02fefdfe, 0xfd00fdfe, 0xff02fdfe, 0x00fcfdfe, +- 0x000002ff, 0x020202ff, 0xfdfe02ff, 0x02ff02ff, 0xfd0102ff, 0xff0302ff, 0x00fd02ff, 0xfffffd01, +- 0x0201fd01, 0xfdfdfd01, 0x02fefd01, 0xfd00fd01, 0xff02fd01, 0x00fcfd01, 0xffffff03, 0x0201ff03, +- 0xfdfdff03, 0x02feff03, 0xfd00ff03, 0xff02ff03, 0x00fcff03, 0x000000fd, 0x020200fd, 0xfdfe00fd, +- 0x02ff00fd, 0xfd0100fd, 0xff0300fd, 0x00fd00fd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000303, 0xfffffcfd, 0x000003ff, 0xfffffc01, 0xffffff04, 0x000000fc, 0x00000707, +- 0xfffff8f9, 0x00000802, 0xfffff7fe, 0x00000208, 0xfffffdf8, 0x000008fe, 0xfffff702, 0xfffffe09, +- 0x000001f7, 0x000005fa, 0xfffffa06, 0x00000d06, 0xfffff2fa, 0x0000060d, 0xfffff9f3, 0x00000d0d, +- 0xfffff2f3, 0x00000e01, 0xfffff1ff, 0x0000010e, 0xfffffef2, 0x00000bf8, 0xfffff408, 0xfffff80c, +- 0x000007f4, 0x0000170e, 0xffffe8f2, 0x00000e17, 0xfffff1e9, 0x000011fb, 0xffffee05, 0xfffffb12, +- 0x000004ee, 0x00001806, 0xffffe7fa, 0x00000618, 0xfffff9e8, 0x00001818, 0xffffe7e8, 0x00001aff, +- 0xffffe501, 0xffffff1b, 0x000000e5, 0x000010ef, 0xffffef11, 0x000016f3, 0xffffe90d, 0xfffff317, +- 0x00000ce9, 0x00002810, 0xffffd7f0, 0x00001028, 0xffffefd8, 0x0000291c, 0xffffd6e4, 0x00001c29, +- 0xffffe3d7, 0x000020f7, 0xffffdf09, 0xfffff721, 0x000008df, 0x00002b06, 0xffffd4fa, 0x0000062b, +- 0xfffff9d5, 0x00002e2e, 0xffffd1d2, 0x000031fc, 0xffffce04, 0xfffffc32, 0x000003ce, 0x000021e5, +- 0xffffde1b, 0xffffe522, 0x00001ade, 0x00002cea, 0xffffd316, 0xffffea2d, 0x000015d3, 0x00004522, +- 0xffffbade, 0x00002245, 0xffffddbb, 0x00004613, 0xffffb9ed, 0x00001346, 0xffffecba, 0x00004935, +- 0xffffb6cb, 0x00003549, 0xffffcab7, 0x00003def, 0xffffc211, 0xffffef3e, 0x000010c2, 0x00004d05, +- 0xffffb2fb, 0x0000054d, 0xfffffab3, 0x00005252, 0xffffadae, 0x000032cd, 0xffffcd33, 0x00003fd5, +- 0xffffc02b, 0xffffd540, 0x00002ac0, 0x000059f6, 0xffffa60a, 0xfffff65a, 0x000009a6, 0x00007229, +- 0xffff8dd7, 0x00002972, 0xffffd68e, 0x00007440, 0xffff8bc0, 0x00004074, 0xffffbf8c, 0x000051db, +- 0xffffae25, 0xffffdb52, 0x000024ae, 0x00007716, 0xffff88ea, 0x00001677, 0xffffe989, 0x00007c5f, +- 0xffff83a1, 0x00005f7c, 0xffffa084, 0x00006ee2, 0xffff911e, 0xffffe26f, 0x00001d91, 0x00005bb2, +- 0xffffa44e, 0xffffb25c, 0x00004da4, 0x000070bc, 0xffff8f44, 0xffffbc71, 0x0000438f, 0x00001212, +- 0xffffedee, 0x00002222, 0xffffddde, 0x00003f3f, 0xffffc0c1, 0x00006d6d, 0xffff9293, 0x00000000, +- 0x03030000, 0xfcfd0000, 0x03ff0000, 0xfc010000, 0xff040000, 0x00fc0000, 0x07070000, 0xf8f90000, +- 0x00000303, 0x03030303, 0xfcfd0303, 0x03ff0303, 0xfc010303, 0xff040303, 0x00fc0303, 0x07070303, +- 0xf8f90303, 0xfffffcfd, 0x0302fcfd, 0xfcfcfcfd, 0x03fefcfd, 0xfc00fcfd, 0xff03fcfd, 0x00fbfcfd, +- 0x0706fcfd, 0xf8f8fcfd, 0x000003ff, 0x030303ff, 0xfcfd03ff, 0x03ff03ff, 0xfc0103ff, 0xff0403ff, +- 0x00fc03ff, 0x070703ff, 0xf8f903ff, 0xfffffc01, 0x0302fc01, 0xfcfcfc01, 0x03fefc01, 0xfc00fc01, +- 0xff03fc01, 0x00fbfc01, 0x0706fc01, 0xf8f8fc01, 0xffffff04, 0x0302ff04, 0xfcfcff04, 0x03feff04, +- 0xfc00ff04, 0xff03ff04, 0x00fbff04, 0x0706ff04, 0xf8f8ff04, 0x000000fc, 0x030300fc, 0xfcfd00fc, +- 0x03ff00fc, 0xfc0100fc, 0xff0400fc, 0x00fc00fc, 0x070700fc, 0xf8f900fc, 0x00000707, 0x03030707, +- 0xfcfd0707, 0x03ff0707, 0xfc010707, 0xff040707, 0x00fc0707, 0x07070707, 0xf8f90707, 0xfffff8f9, +- 0x0302f8f9, 0xfcfcf8f9, 0x03fef8f9, 0xfc00f8f9, 0xff03f8f9, 0x00fbf8f9, 0x0706f8f9, 0xf8f8f8f9, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000404, 0xfffffbfc, 0x000004ff, 0xfffffb01, 0xffffff05, 0x000000fb, 0x00000a03, +- 0xfffff5fd, 0x0000030a, 0xfffffcf6, 0x00000909, 0xfffff6f7, 0x000006f9, 0xfffff907, 0x00000bfd, +- 0xfffff403, 0xfffffd0c, 0x000002f4, 0x00001108, 0xffffeef8, 0x00000811, 0xfffff7ef, 0x00001111, +- 0xffffeeef, 0x00001301, 0xffffecff, 0x00000113, 0xfffffeed, 0x00000ff5, 0xfffff00b, 0xfffff510, +- 0x00000af0, 0x000016fa, 0xffffe906, 0xfffffa17, 0x000005e9, 0x00001f12, 0xffffe0ee, 0x0000121f, +- 0xffffede1, 0x00002008, 0xffffdff8, 0x00000820, 0xfffff7e0, 0x00002121, 0xffffdedf, 0x000023ff, +- 0xffffdc01, 0xffffff24, 0x000000dc, 0x000016e9, 0xffffe917, 0x00001eef, 0xffffe111, 0xffffef1f, +- 0x000010e1, 0x00003615, 0xffffc9eb, 0x00001536, 0xffffeaca, 0x00003725, 0xffffc8db, 0x00002537, +- 0xffffdac9, 0x00002bf4, 0xffffd40c, 0xfffff42c, 0x00000bd4, 0x00003908, 0xffffc6f8, 0x00000839, +- 0xfffff7c7, 0x00003d3d, 0xffffc2c3, 0x000041fb, 0xffffbe05, 0xfffffb42, 0x000004be, 0x00002cdc, +- 0xffffd324, 0xffffdc2d, 0x000023d3, 0x00003be3, 0xffffc41d, 0xffffe33c, 0x00001cc4, 0x00005c2d, +- 0xffffa3d3, 0x00002d5c, 0xffffd2a4, 0x00005d19, 0xffffa2e7, 0x0000195d, 0xffffe6a3, 0x00006147, +- 0xffff9eb9, 0x00004761, 0xffffb89f, 0x000052ea, 0xffffad16, 0xffffea53, 0x000015ad, 0x00006607, +- 0xffff99f9, 0x00000766, 0xfffff89a, 0x00006d6d, 0xffff9293, 0x000043bc, 0xffffbc44, 0x000054c7, +- 0xffffab39, 0xffffc755, 0x000038ab, 0x000077f3, 0xffff880d, 0xfffff378, 0x00000c88, 0x00006dcf, +- 0xffff9231, 0xffffcf6e, 0x00003092, 0x00007a98, 0xffff8568, 0xffff987b, 0x00006785, 0x00001818, +- 0xffffe7e8, 0x00002e2e, 0xffffd1d2, 0x00005454, 0xffffabac, 0x00000000, 0x04040000, 0xfbfc0000, +- 0x04ff0000, 0xfb010000, 0xff050000, 0x00fb0000, 0x0a030000, 0xf5fd0000, 0x030a0000, 0x00000404, +- 0x04040404, 0xfbfc0404, 0x04ff0404, 0xfb010404, 0xff050404, 0x00fb0404, 0x0a030404, 0xf5fd0404, +- 0x030a0404, 0xfffffbfc, 0x0403fbfc, 0xfbfbfbfc, 0x04fefbfc, 0xfb00fbfc, 0xff04fbfc, 0x00fafbfc, +- 0x0a02fbfc, 0xf5fcfbfc, 0x0309fbfc, 0x000004ff, 0x040404ff, 0xfbfc04ff, 0x04ff04ff, 0xfb0104ff, +- 0xff0504ff, 0x00fb04ff, 0x0a0304ff, 0xf5fd04ff, 0x030a04ff, 0xfffffb01, 0x0403fb01, 0xfbfbfb01, +- 0x04fefb01, 0xfb00fb01, 0xff04fb01, 0x00fafb01, 0x0a02fb01, 0xf5fcfb01, 0x0309fb01, 0xffffff05, +- 0x0403ff05, 0xfbfbff05, 0x04feff05, 0xfb00ff05, 0xff04ff05, 0x00faff05, 0x0a02ff05, 0xf5fcff05, +- 0x0309ff05, 0x000000fb, 0x040400fb, 0xfbfc00fb, 0x04ff00fb, 0xfb0100fb, 0xff0500fb, 0x00fb00fb, +- 0x0a0300fb, 0xf5fd00fb, 0x030a00fb, 0x00000a03, 0x04040a03, 0xfbfc0a03, 0x04ff0a03, 0xfb010a03, +- 0xff050a03, 0x00fb0a03, 0x0a030a03, 0xf5fd0a03, 0x030a0a03, 0xfffff5fd, 0x0403f5fd, 0xfbfbf5fd, +- 0x04fef5fd, 0xfb00f5fd, 0xff04f5fd, 0x00faf5fd, 0x0a02f5fd, 0xf5fcf5fd, 0x0309f5fd, 0x0000030a, +- 0x0404030a, 0xfbfc030a, 0x04ff030a, 0xfb01030a, 0xff05030a, 0x00fb030a, 0x0a03030a, 0xf5fd030a, +- 0x030a030a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000505, 0xfffffafb, 0x000006fe, 0xfffff902, 0xfffffe07, 0x000001f9, 0x00000b0b, +- 0xfffff4f5, 0x00000d03, 0xfffff2fd, 0x0000030d, 0xfffffcf3, 0x000008f7, 0xfffff709, 0x00000efc, +- 0xfffff104, 0xfffffc0f, 0x000003f1, 0x0000160b, 0xffffe9f5, 0x00000b16, 0xfffff4ea, 0x00001515, +- 0xffffeaeb, 0x00001802, 0xffffe7fe, 0x00000218, 0xfffffde8, 0x000013f2, 0xffffec0e, 0xfffff214, +- 0x00000dec, 0x00002617, 0xffffd9e9, 0x00001726, 0xffffe8da, 0x00001cf8, 0xffffe308, 0xfffff81d, +- 0x000007e3, 0x0000270b, 0xffffd8f5, 0x00000b27, 0xfffff4d9, 0x00002929, 0xffffd6d7, 0x00002cff, +- 0xffffd301, 0xffffff2d, 0x000000d3, 0x00001ce3, 0xffffe31d, 0x000026ea, 0xffffd916, 0xffffea27, +- 0x000015d9, 0x0000431b, 0xffffbce5, 0x00001b43, 0xffffe4bd, 0x0000452f, 0xffffbad1, 0x00002f45, +- 0xffffd0bb, 0x000037f1, 0xffffc80f, 0xfffff138, 0x00000ec8, 0x0000470b, 0xffffb8f5, 0x00000b47, +- 0xfffff4b9, 0x00004c4c, 0xffffb3b4, 0x000052fa, 0xffffad06, 0xfffffa53, 0x000005ad, 0x000038d3, +- 0xffffc72d, 0xffffd339, 0x00002cc7, 0x00004adc, 0xffffb524, 0xffffdc4b, 0x000023b5, 0x00007338, +- 0xffff8cc8, 0x00003873, 0xffffc78d, 0x0000751f, 0xffff8ae1, 0x00001f75, 0xffffe08b, 0x00007a58, +- 0xffff85a8, 0x0000587a, 0xffffa786, 0x000067e4, 0xffff981c, 0xffffe468, 0x00001b98, 0x000054ab, +- 0xffffab55, 0x000069b8, 0xffff9648, 0xffffb86a, 0x00004796, 0x00001e1e, 0xffffe1e2, 0x00003a3a, +- 0xffffc5c6, 0x00006969, 0xffff9697, 0x00000000, 0x05050000, 0xfafb0000, 0x06fe0000, 0xf9020000, +- 0xfe070000, 0x01f90000, 0x0b0b0000, 0xf4f50000, 0x0d030000, 0xf2fd0000, 0x00000505, 0x05050505, +- 0xfafb0505, 0x06fe0505, 0xf9020505, 0xfe070505, 0x01f90505, 0x0b0b0505, 0xf4f50505, 0x0d030505, +- 0xf2fd0505, 0xfffffafb, 0x0504fafb, 0xfafafafb, 0x06fdfafb, 0xf901fafb, 0xfe06fafb, 0x01f8fafb, +- 0x0b0afafb, 0xf4f4fafb, 0x0d02fafb, 0xf2fcfafb, 0x000006fe, 0x050506fe, 0xfafb06fe, 0x06fe06fe, +- 0xf90206fe, 0xfe0706fe, 0x01f906fe, 0x0b0b06fe, 0xf4f506fe, 0x0d0306fe, 0xf2fd06fe, 0xfffff902, +- 0x0504f902, 0xfafaf902, 0x06fdf902, 0xf901f902, 0xfe06f902, 0x01f8f902, 0x0b0af902, 0xf4f4f902, +- 0x0d02f902, 0xf2fcf902, 0xfffffe07, 0x0504fe07, 0xfafafe07, 0x06fdfe07, 0xf901fe07, 0xfe06fe07, +- 0x01f8fe07, 0x0b0afe07, 0xf4f4fe07, 0x0d02fe07, 0xf2fcfe07, 0x000001f9, 0x050501f9, 0xfafb01f9, +- 0x06fe01f9, 0xf90201f9, 0xfe0701f9, 0x01f901f9, 0x0b0b01f9, 0xf4f501f9, 0x0d0301f9, 0xf2fd01f9, +- 0x00000b0b, 0x05050b0b, 0xfafb0b0b, 0x06fe0b0b, 0xf9020b0b, 0xfe070b0b, 0x01f90b0b, 0x0b0b0b0b, +- 0xf4f50b0b, 0x0d030b0b, 0xf2fd0b0b, 0xfffff4f5, 0x0504f4f5, 0xfafaf4f5, 0x06fdf4f5, 0xf901f4f5, +- 0xfe06f4f5, 0x01f8f4f5, 0x0b0af4f5, 0xf4f4f4f5, 0x0d02f4f5, 0xf2fcf4f5, 0x00000d03, 0x05050d03, +- 0xfafb0d03, 0x06fe0d03, 0xf9020d03, 0xfe070d03, 0x01f90d03, 0x0b0b0d03, 0xf4f50d03, 0x0d030d03, +- 0xf2fd0d03, 0xfffff2fd, 0x0504f2fd, 0xfafaf2fd, 0x06fdf2fd, 0xf901f2fd, 0xfe06f2fd, 0x01f8f2fd, +- 0x0b0af2fd, 0xf4f4f2fd, 0x0d02f2fd, 0xf2fcf2fd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000606, 0xfffff9fa, 0x000007fe, 0xfffff802, 0xfffffe08, 0x000001f8, 0x00000d0d, +- 0xfffff2f3, 0x00000f04, 0xfffff0fc, 0x0000040f, 0xfffffbf1, 0x00000af5, 0xfffff50b, 0x000011fb, +- 0xffffee05, 0xfffffb12, 0x000004ee, 0x00001a0d, 0xffffe5f3, 0x00000d1a, 0xfffff2e6, 0x00001a1a, +- 0xffffe5e6, 0x00001d02, 0xffffe2fe, 0x0000021d, 0xfffffde3, 0x000017f0, 0xffffe810, 0xfffff018, +- 0x00000fe8, 0x00002e1c, 0xffffd1e4, 0x00001c2e, 0xffffe3d2, 0x000022f7, 0xffffdd09, 0xfffff723, +- 0x000008dd, 0x00002f0d, 0xffffd0f3, 0x00000d2f, 0xfffff2d1, 0x00003131, 0xffffcecf, 0x000035ff, +- 0xffffca01, 0xffffff36, 0x000000ca, 0x000022dd, 0xffffdd23, 0x00002ee6, 0xffffd11a, 0xffffe62f, +- 0x000019d1, 0x00005120, 0xffffaee0, 0x00002051, 0xffffdfaf, 0x00005338, 0xffffacc8, 0x00003853, +- 0xffffc7ad, 0x000042ee, 0xffffbd12, 0xffffee43, 0x000011bd, 0x0000560d, 0xffffa9f3, 0x00000d56, +- 0xfffff2aa, 0x00005b5b, 0xffffa4a5, 0x000062f9, 0xffff9d07, 0xfffff963, 0x0000069d, 0x000043ca, +- 0xffffbc36, 0xffffca44, 0x000035bc, 0x000059d4, 0xffffa62c, 0xffffd45a, 0x00002ba6, 0x00007bdf, +- 0xffff8421, 0xffffdf7c, 0x00002084, 0x00006699, 0xffff9967, 0x00007eaa, 0xffff8156, 0xffffaa7f, +- 0x00005581, 0x00002525, 0xffffdadb, 0x00004545, 0xffffbabb, 0x00000000, 0x06060000, 0xf9fa0000, +- 0x07fe0000, 0xf8020000, 0xfe080000, 0x01f80000, 0x0d0d0000, 0xf2f30000, 0x0f040000, 0xf0fc0000, +- 0x040f0000, 0x00000606, 0x06060606, 0xf9fa0606, 0x07fe0606, 0xf8020606, 0xfe080606, 0x01f80606, +- 0x0d0d0606, 0xf2f30606, 0x0f040606, 0xf0fc0606, 0x040f0606, 0xfffff9fa, 0x0605f9fa, 0xf9f9f9fa, +- 0x07fdf9fa, 0xf801f9fa, 0xfe07f9fa, 0x01f7f9fa, 0x0d0cf9fa, 0xf2f2f9fa, 0x0f03f9fa, 0xf0fbf9fa, +- 0x040ef9fa, 0x000007fe, 0x060607fe, 0xf9fa07fe, 0x07fe07fe, 0xf80207fe, 0xfe0807fe, 0x01f807fe, +- 0x0d0d07fe, 0xf2f307fe, 0x0f0407fe, 0xf0fc07fe, 0x040f07fe, 0xfffff802, 0x0605f802, 0xf9f9f802, +- 0x07fdf802, 0xf801f802, 0xfe07f802, 0x01f7f802, 0x0d0cf802, 0xf2f2f802, 0x0f03f802, 0xf0fbf802, +- 0x040ef802, 0xfffffe08, 0x0605fe08, 0xf9f9fe08, 0x07fdfe08, 0xf801fe08, 0xfe07fe08, 0x01f7fe08, +- 0x0d0cfe08, 0xf2f2fe08, 0x0f03fe08, 0xf0fbfe08, 0x040efe08, 0x000001f8, 0x060601f8, 0xf9fa01f8, +- 0x07fe01f8, 0xf80201f8, 0xfe0801f8, 0x01f801f8, 0x0d0d01f8, 0xf2f301f8, 0x0f0401f8, 0xf0fc01f8, +- 0x040f01f8, 0x00000d0d, 0x06060d0d, 0xf9fa0d0d, 0x07fe0d0d, 0xf8020d0d, 0xfe080d0d, 0x01f80d0d, +- 0x0d0d0d0d, 0xf2f30d0d, 0x0f040d0d, 0xf0fc0d0d, 0x040f0d0d, 0xfffff2f3, 0x0605f2f3, 0xf9f9f2f3, +- 0x07fdf2f3, 0xf801f2f3, 0xfe07f2f3, 0x01f7f2f3, 0x0d0cf2f3, 0xf2f2f2f3, 0x0f03f2f3, 0xf0fbf2f3, +- 0x040ef2f3, 0x00000f04, 0x06060f04, 0xf9fa0f04, 0x07fe0f04, 0xf8020f04, 0xfe080f04, 0x01f80f04, +- 0x0d0d0f04, 0xf2f30f04, 0x0f040f04, 0xf0fc0f04, 0x040f0f04, 0xfffff0fc, 0x0605f0fc, 0xf9f9f0fc, +- 0x07fdf0fc, 0xf801f0fc, 0xfe07f0fc, 0x01f7f0fc, 0x0d0cf0fc, 0xf2f2f0fc, 0x0f03f0fc, 0xf0fbf0fc, +- 0x040ef0fc, 0x0000040f, 0x0606040f, 0xf9fa040f, 0x07fe040f, 0xf802040f, 0xfe08040f, 0x01f8040f, +- 0x0d0d040f, 0xf2f3040f, 0x0f04040f, 0xf0fc040f, 0x040f040f, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000707, 0xfffff8f9, 0x000009fd, 0xfffff603, 0xfffffd0a, 0x000002f6, 0x00001010, +- 0xffffeff0, 0x00001205, 0xffffedfb, 0x00000512, 0xfffffaee, 0x00000cf3, 0xfffff30d, 0x000014fa, +- 0xffffeb06, 0xfffffa15, 0x000005eb, 0x00001e0f, 0xffffe1f1, 0x00000f1e, 0xfffff0e2, 0x00001e1e, +- 0xffffe1e2, 0x00002202, 0xffffddfe, 0x00000222, 0xfffffdde, 0x00001bed, 0xffffe413, 0xffffed1c, +- 0x000012e4, 0x00003620, 0xffffc9e0, 0x00002036, 0xffffdfca, 0x000028f5, 0xffffd70b, 0xfffff529, +- 0x00000ad7, 0x0000370f, 0xffffc8f1, 0x00000f37, 0xfffff0c9, 0x00003939, 0xffffc6c7, 0x00003eff, +- 0xffffc101, 0xffffff3f, 0x000000c1, 0x000027d8, 0xffffd828, 0x000036e2, 0xffffc91e, 0xffffe237, +- 0x00001dc9, 0x00005e25, 0xffffa1db, 0x0000255e, 0xffffdaa2, 0x00006041, 0xffff9fbf, 0x00004160, +- 0xffffbea0, 0x00004deb, 0xffffb215, 0xffffeb4e, 0x000014b2, 0x0000640f, 0xffff9bf1, 0x00000f64, +- 0xfffff09c, 0x00006a6a, 0xffff9596, 0x000073f8, 0xffff8c08, 0xfffff874, 0x0000078c, 0x00004ec1, +- 0xffffb13f, 0xffffc14f, 0x00003eb1, 0x000068cd, 0xffff9733, 0xffffcd69, 0x00003297, 0x00007788, +- 0xffff8878, 0x00002b2b, 0xffffd4d5, 0x00005050, 0xffffafb0, 0x00000000, 0x07070000, 0xf8f90000, +- 0x09fd0000, 0xf6030000, 0xfd0a0000, 0x02f60000, 0x10100000, 0xeff00000, 0x12050000, 0xedfb0000, +- 0x05120000, 0x00000707, 0x07070707, 0xf8f90707, 0x09fd0707, 0xf6030707, 0xfd0a0707, 0x02f60707, +- 0x10100707, 0xeff00707, 0x12050707, 0xedfb0707, 0x05120707, 0xfffff8f9, 0x0706f8f9, 0xf8f8f8f9, +- 0x09fcf8f9, 0xf602f8f9, 0xfd09f8f9, 0x02f5f8f9, 0x100ff8f9, 0xefeff8f9, 0x1204f8f9, 0xedfaf8f9, +- 0x0511f8f9, 0x000009fd, 0x070709fd, 0xf8f909fd, 0x09fd09fd, 0xf60309fd, 0xfd0a09fd, 0x02f609fd, +- 0x101009fd, 0xeff009fd, 0x120509fd, 0xedfb09fd, 0x051209fd, 0xfffff603, 0x0706f603, 0xf8f8f603, +- 0x09fcf603, 0xf602f603, 0xfd09f603, 0x02f5f603, 0x100ff603, 0xefeff603, 0x1204f603, 0xedfaf603, +- 0x0511f603, 0xfffffd0a, 0x0706fd0a, 0xf8f8fd0a, 0x09fcfd0a, 0xf602fd0a, 0xfd09fd0a, 0x02f5fd0a, +- 0x100ffd0a, 0xefeffd0a, 0x1204fd0a, 0xedfafd0a, 0x0511fd0a, 0x000002f6, 0x070702f6, 0xf8f902f6, +- 0x09fd02f6, 0xf60302f6, 0xfd0a02f6, 0x02f602f6, 0x101002f6, 0xeff002f6, 0x120502f6, 0xedfb02f6, +- 0x051202f6, 0x00001010, 0x07071010, 0xf8f91010, 0x09fd1010, 0xf6031010, 0xfd0a1010, 0x02f61010, +- 0x10101010, 0xeff01010, 0x12051010, 0xedfb1010, 0x05121010, 0xffffeff0, 0x0706eff0, 0xf8f8eff0, +- 0x09fceff0, 0xf602eff0, 0xfd09eff0, 0x02f5eff0, 0x100feff0, 0xefefeff0, 0x1204eff0, 0xedfaeff0, +- 0x0511eff0, 0x00001205, 0x07071205, 0xf8f91205, 0x09fd1205, 0xf6031205, 0xfd0a1205, 0x02f61205, +- 0x10101205, 0xeff01205, 0x12051205, 0xedfb1205, 0x05121205, 0xffffedfb, 0x0706edfb, 0xf8f8edfb, +- 0x09fcedfb, 0xf602edfb, 0xfd09edfb, 0x02f5edfb, 0x100fedfb, 0xefefedfb, 0x1204edfb, 0xedfaedfb, +- 0x0511edfb, 0x00000512, 0x07070512, 0xf8f90512, 0x09fd0512, 0xf6030512, 0xfd0a0512, 0x02f60512, +- 0x10100512, 0xeff00512, 0x12050512, 0xedfb0512, 0x05120512, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000808, 0xfffff7f8, 0x00000afd, 0xfffff503, 0xfffffd0b, 0x000002f5, 0x00001212, +- 0xffffedee, 0x00001405, 0xffffebfb, 0x00000514, 0xfffffaec, 0x00000ef1, 0xfffff10f, 0x000017f9, +- 0xffffe807, 0xfffff918, 0x000006e8, 0x00002311, 0xffffdcef, 0x00001123, 0xffffeedd, 0x00002222, +- 0xffffddde, 0x00002603, 0xffffd9fd, 0x00000326, 0xfffffcda, 0x00001fea, 0xffffe016, 0xffffea20, +- 0x000015e0, 0x00003d25, 0xffffc2db, 0x0000253d, 0xffffdac3, 0x00002ef3, 0xffffd10d, 0xfffff32f, +- 0x00000cd1, 0x00003f11, 0xffffc0ef, 0x0000113f, 0xffffeec1, 0x00004141, 0xffffbebf, 0x000047ff, +- 0xffffb801, 0xffffff48, 0x000000b8, 0x00002dd2, 0xffffd22e, 0x00003edd, 0xffffc123, 0xffffdd3f, +- 0x000022c1, 0x00006b2b, 0xffff94d5, 0x00002b6b, 0xffffd495, 0x00006e4b, 0xffff91b5, 0x00004b6e, +- 0xffffb492, 0x000058e8, 0xffffa718, 0xffffe859, 0x000017a7, 0x00007211, 0xffff8def, 0x00001172, +- 0xffffee8e, 0x00007979, 0xffff8687, 0x00005ab8, 0xffffa548, 0xffffb85b, 0x000047a5, 0x000077c6, +- 0xffff883a, 0xffffc678, 0x00003988, 0x00003131, 0xffffcecf, 0x00005c5c, 0xffffa3a4, 0x00000000, +- 0x08080000, 0xf7f80000, 0x0afd0000, 0xf5030000, 0xfd0b0000, 0x02f50000, 0x12120000, 0xedee0000, +- 0x14050000, 0xebfb0000, 0x05140000, 0x00000808, 0x08080808, 0xf7f80808, 0x0afd0808, 0xf5030808, +- 0xfd0b0808, 0x02f50808, 0x12120808, 0xedee0808, 0x14050808, 0xebfb0808, 0x05140808, 0xfffff7f8, +- 0x0807f7f8, 0xf7f7f7f8, 0x0afcf7f8, 0xf502f7f8, 0xfd0af7f8, 0x02f4f7f8, 0x1211f7f8, 0xededf7f8, +- 0x1404f7f8, 0xebfaf7f8, 0x0513f7f8, 0x00000afd, 0x08080afd, 0xf7f80afd, 0x0afd0afd, 0xf5030afd, +- 0xfd0b0afd, 0x02f50afd, 0x12120afd, 0xedee0afd, 0x14050afd, 0xebfb0afd, 0x05140afd, 0xfffff503, +- 0x0807f503, 0xf7f7f503, 0x0afcf503, 0xf502f503, 0xfd0af503, 0x02f4f503, 0x1211f503, 0xededf503, +- 0x1404f503, 0xebfaf503, 0x0513f503, 0xfffffd0b, 0x0807fd0b, 0xf7f7fd0b, 0x0afcfd0b, 0xf502fd0b, +- 0xfd0afd0b, 0x02f4fd0b, 0x1211fd0b, 0xededfd0b, 0x1404fd0b, 0xebfafd0b, 0x0513fd0b, 0x000002f5, +- 0x080802f5, 0xf7f802f5, 0x0afd02f5, 0xf50302f5, 0xfd0b02f5, 0x02f502f5, 0x121202f5, 0xedee02f5, +- 0x140502f5, 0xebfb02f5, 0x051402f5, 0x00001212, 0x08081212, 0xf7f81212, 0x0afd1212, 0xf5031212, +- 0xfd0b1212, 0x02f51212, 0x12121212, 0xedee1212, 0x14051212, 0xebfb1212, 0x05141212, 0xffffedee, +- 0x0807edee, 0xf7f7edee, 0x0afcedee, 0xf502edee, 0xfd0aedee, 0x02f4edee, 0x1211edee, 0xedededee, +- 0x1404edee, 0xebfaedee, 0x0513edee, 0x00001405, 0x08081405, 0xf7f81405, 0x0afd1405, 0xf5031405, +- 0xfd0b1405, 0x02f51405, 0x12121405, 0xedee1405, 0x14051405, 0xebfb1405, 0x05141405, 0xffffebfb, +- 0x0807ebfb, 0xf7f7ebfb, 0x0afcebfb, 0xf502ebfb, 0xfd0aebfb, 0x02f4ebfb, 0x1211ebfb, 0xededebfb, +- 0x1404ebfb, 0xebfaebfb, 0x0513ebfb, 0x00000514, 0x08080514, 0xf7f80514, 0x0afd0514, 0xf5030514, +- 0xfd0b0514, 0x02f50514, 0x12120514, 0xedee0514, 0x14050514, 0xebfb0514, 0x05140514, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000909, 0xfffff6f7, 0x00000bfd, 0xfffff403, 0xfffffd0c, 0x000002f4, 0x00001414, +- 0xffffebec, 0x00001706, 0xffffe8fa, 0x00000617, 0xfffff9e9, 0x000010ef, 0xffffef11, 0x00001af9, +- 0xffffe507, 0xfffff91b, 0x000006e5, 0x00002713, 0xffffd8ed, 0x00001327, 0xffffecd9, 0x00002727, +- 0xffffd8d9, 0x00002b03, 0xffffd4fd, 0x0000032b, 0xfffffcd5, 0x000023e8, 0xffffdc18, 0xffffe824, +- 0x000017dc, 0x0000452a, 0xffffbad6, 0x00002a45, 0xffffd5bb, 0x000034f2, 0xffffcb0e, 0xfffff235, +- 0x00000dcb, 0x00004713, 0xffffb8ed, 0x00001347, 0xffffecb9, 0x00004949, 0xffffb6b7, 0x00004ffe, +- 0xffffb002, 0xfffffe50, 0x000001b0, 0x000033cc, 0xffffcc34, 0x000045d9, 0xffffba27, 0xffffd946, +- 0x000026ba, 0x00007930, 0xffff86d0, 0x00003079, 0xffffcf87, 0x00007c54, 0xffff83ac, 0x0000547c, +- 0xffffab84, 0x000063e5, 0xffff9c1b, 0xffffe564, 0x00001a9c, 0x000065af, 0xffff9a51, 0xffffaf66, +- 0x0000509a, 0x00003737, 0xffffc8c9, 0x00006868, 0xffff9798, 0x00000000, 0x09090000, 0xf6f70000, +- 0x0bfd0000, 0xf4030000, 0xfd0c0000, 0x02f40000, 0x14140000, 0xebec0000, 0x17060000, 0xe8fa0000, +- 0x06170000, 0xf9e90000, 0x00000909, 0x09090909, 0xf6f70909, 0x0bfd0909, 0xf4030909, 0xfd0c0909, +- 0x02f40909, 0x14140909, 0xebec0909, 0x17060909, 0xe8fa0909, 0x06170909, 0xf9e90909, 0xfffff6f7, +- 0x0908f6f7, 0xf6f6f6f7, 0x0bfcf6f7, 0xf402f6f7, 0xfd0bf6f7, 0x02f3f6f7, 0x1413f6f7, 0xebebf6f7, +- 0x1705f6f7, 0xe8f9f6f7, 0x0616f6f7, 0xf9e8f6f7, 0x00000bfd, 0x09090bfd, 0xf6f70bfd, 0x0bfd0bfd, +- 0xf4030bfd, 0xfd0c0bfd, 0x02f40bfd, 0x14140bfd, 0xebec0bfd, 0x17060bfd, 0xe8fa0bfd, 0x06170bfd, +- 0xf9e90bfd, 0xfffff403, 0x0908f403, 0xf6f6f403, 0x0bfcf403, 0xf402f403, 0xfd0bf403, 0x02f3f403, +- 0x1413f403, 0xebebf403, 0x1705f403, 0xe8f9f403, 0x0616f403, 0xf9e8f403, 0xfffffd0c, 0x0908fd0c, +- 0xf6f6fd0c, 0x0bfcfd0c, 0xf402fd0c, 0xfd0bfd0c, 0x02f3fd0c, 0x1413fd0c, 0xebebfd0c, 0x1705fd0c, +- 0xe8f9fd0c, 0x0616fd0c, 0xf9e8fd0c, 0x000002f4, 0x090902f4, 0xf6f702f4, 0x0bfd02f4, 0xf40302f4, +- 0xfd0c02f4, 0x02f402f4, 0x141402f4, 0xebec02f4, 0x170602f4, 0xe8fa02f4, 0x061702f4, 0xf9e902f4, +- 0x00001414, 0x09091414, 0xf6f71414, 0x0bfd1414, 0xf4031414, 0xfd0c1414, 0x02f41414, 0x14141414, +- 0xebec1414, 0x17061414, 0xe8fa1414, 0x06171414, 0xf9e91414, 0xffffebec, 0x0908ebec, 0xf6f6ebec, +- 0x0bfcebec, 0xf402ebec, 0xfd0bebec, 0x02f3ebec, 0x1413ebec, 0xebebebec, 0x1705ebec, 0xe8f9ebec, +- 0x0616ebec, 0xf9e8ebec, 0x00001706, 0x09091706, 0xf6f71706, 0x0bfd1706, 0xf4031706, 0xfd0c1706, +- 0x02f41706, 0x14141706, 0xebec1706, 0x17061706, 0xe8fa1706, 0x06171706, 0xf9e91706, 0xffffe8fa, +- 0x0908e8fa, 0xf6f6e8fa, 0x0bfce8fa, 0xf402e8fa, 0xfd0be8fa, 0x02f3e8fa, 0x1413e8fa, 0xebebe8fa, +- 0x1705e8fa, 0xe8f9e8fa, 0x0616e8fa, 0xf9e8e8fa, 0x00000617, 0x09090617, 0xf6f70617, 0x0bfd0617, +- 0xf4030617, 0xfd0c0617, 0x02f40617, 0x14140617, 0xebec0617, 0x17060617, 0xe8fa0617, 0x06170617, +- 0xf9e90617, 0xfffff9e9, 0x0908f9e9, 0xf6f6f9e9, 0x0bfcf9e9, 0xf402f9e9, 0xfd0bf9e9, 0x02f3f9e9, +- 0x1413f9e9, 0xebebf9e9, 0x1705f9e9, 0xe8f9f9e9, 0x0616f9e9, 0xf9e8f9e9, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404, +- 0xfffffbfc, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x000003fc, 0xfffffc04, 0x000005fe, +- 0xfffffa02, 0xfffffe06, 0x000001fa, 0x00000804, 0xfffff7fc, 0x00000408, 0xfffffbf8, 0x00000808, +- 0xfffff7f8, 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x000007fc, 0xfffff804, 0xfffffc08, +- 0x000003f8, 0x00000e08, 0xfffff1f8, 0x0000080e, 0xfffff7f2, 0x00000bfe, 0xfffff402, 0xfffffe0c, +- 0x000001f4, 0x00001004, 0xffffeffc, 0x00000410, 0xfffffbf0, 0x00001010, 0xffffeff0, 0x00001200, +- 0xffffee00, 0x00000012, 0xffffffee, 0x00000bf4, 0xfffff40c, 0x00000ff8, 0xfffff008, 0xfffff810, +- 0x000007f0, 0x00001a0a, 0xffffe5f6, 0x00000a1a, 0xfffff5e6, 0x00001c12, 0xffffe3ee, 0x0000121c, +- 0xffffede4, 0x000015fa, 0xffffea06, 0xfffffa16, 0x000005ea, 0x00001c04, 0xffffe3fc, 0x0000041c, +- 0xfffffbe4, 0x00001e1e, 0xffffe1e2, 0x00001ffe, 0xffffe002, 0xfffffe20, 0x000001e0, 0x000015ee, +- 0xffffea12, 0xffffee16, 0x000011ea, 0x00001df2, 0xffffe20e, 0xfffff21e, 0x00000de2, 0x00002e16, +- 0xffffd1ea, 0x0000162e, 0xffffe9d2, 0x00002e0c, 0xffffd1f4, 0x00000c2e, 0xfffff3d2, 0x00003022, +- 0xffffcfde, 0x00002230, 0xffffddd0, 0x000027f6, 0xffffd80a, 0xfffff628, 0x000009d8, 0x00003204, +- 0xffffcdfc, 0x00000432, 0xfffffbce, 0x00003636, 0xffffc9ca, 0x000021de, 0xffffde22, 0x000029e4, +- 0xffffd61c, 0xffffe42a, 0x00001bd6, 0x00003bfa, 0xffffc406, 0xfffffa3c, 0x000005c4, 0x00004c1a, +- 0xffffb3e6, 0x00001a4c, 0xffffe5b4, 0x00004c2a, 0xffffb3d6, 0x00002a4c, 0xffffd5b4, 0x000035e8, +- 0xffffca18, 0xffffe836, 0x000017ca, 0x00004e0e, 0xffffb1f2, 0x00000e4e, 0xfffff1b2, 0x0000523e, +- 0xffffadc2, 0x00003e52, 0xffffc1ae, 0x000049ec, 0xffffb614, 0xffffec4a, 0x000013b6, 0x00005802, +- 0xffffa7fe, 0x00000258, 0xfffffda8, 0x00005c5c, 0xffffa3a4, 0x00003bcc, 0xffffc434, 0xffffcc3c, +- 0x000033c4, 0x00007634, 0xffff89cc, 0x00003476, 0xffffcb8a, 0x000049d4, 0xffffb62c, 0xffffd44a, +- 0x00002bb6, 0x0000764a, 0xffff89b6, 0x00004a76, 0xffffb58a, 0x00007620, 0xffff89e0, 0x00002076, +- 0xffffdf8a, 0x000065f4, 0xffff9a0c, 0xfffff466, 0x00000b9a, 0x00005fd8, 0xffffa028, 0xffffd860, +- 0x000027a0, 0x000075de, 0xffff8a22, 0xffffde76, 0x0000218a, 0x000057a8, 0xffffa858, 0x000067b2, +- 0xffff984e, 0xffffb268, 0x00004d98, 0x00000c0c, 0xfffff3f4, 0x00001616, 0xffffe9ea, 0x00002a2a, +- 0xffffd5d6, 0x00004848, 0xffffb7b8, 0x00000000, 0x02020000, 0xfdfe0000, 0x02000000, 0xfe000000, +- 0x00020000, 0xfffe0000, 0x00000202, 0x02020202, 0xfdfe0202, 0x02000202, 0xfe000202, 0x00020202, +- 0xfffe0202, 0xfffffdfe, 0x0201fdfe, 0xfdfdfdfe, 0x01fffdfe, 0xfdfffdfe, 0x0001fdfe, 0xfffdfdfe, +- 0x00000200, 0x02020200, 0xfdfe0200, 0x02000200, 0xfe000200, 0x00020200, 0xfffe0200, 0xfffffe00, +- 0x0201fe00, 0xfdfdfe00, 0x01fffe00, 0xfdfffe00, 0x0001fe00, 0xfffdfe00, 0x00000002, 0x02020002, +- 0xfdfe0002, 0x02000002, 0xfe000002, 0x00020002, 0xfffe0002, 0xfffffffe, 0x0201fffe, 0xfdfdfffe, +- 0x01fffffe, 0xfdfffffe, 0x0001fffe, 0xfffdfffe, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000303, 0xfffffcfd, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606, +- 0xfffff9fa, 0x00000903, 0xfffff6fd, 0x00000309, 0xfffffcf7, 0x000008fd, 0xfffff703, 0xfffffd09, +- 0x000002f7, 0x000005fa, 0xfffffa06, 0x00000c06, 0xfffff3fa, 0x0000060c, 0xfffff9f4, 0x00000c0c, +- 0xfffff3f4, 0x00000f00, 0xfffff100, 0x0000000f, 0xfffffff1, 0x00000bf7, 0xfffff409, 0xfffff70c, +- 0x000008f4, 0x0000180f, 0xffffe7f1, 0x00000f18, 0xfffff0e8, 0x000011fa, 0xffffee06, 0xfffffa12, +- 0x000005ee, 0x00001806, 0xffffe7fa, 0x00000618, 0xfffff9e8, 0x00001818, 0xffffe7e8, 0x00001b00, +- 0xffffe500, 0x0000001b, 0xffffffe5, 0x000011ee, 0xffffee12, 0x000017f4, 0xffffe80c, 0xfffff418, +- 0x00000be8, 0x0000270f, 0xffffd8f1, 0x00000f27, 0xfffff0d9, 0x00002a1b, 0xffffd5e5, 0x00001b2a, +- 0xffffe4d6, 0x000020f7, 0xffffdf09, 0xfffff721, 0x000008df, 0x00002a06, 0xffffd5fa, 0x0000062a, +- 0xfffff9d6, 0x00002d2d, 0xffffd2d3, 0x000032fd, 0xffffcd03, 0xfffffd33, 0x000002cd, 0x000020e5, +- 0xffffdf1b, 0xffffe521, 0x00001adf, 0x00002ceb, 0xffffd315, 0xffffeb2d, 0x000014d3, 0x00004521, +- 0xffffbadf, 0x00002145, 0xffffdebb, 0x00004512, 0xffffbaee, 0x00001245, 0xffffedbb, 0x00004836, +- 0xffffb7ca, 0x00003648, 0xffffc9b8, 0x00003eee, 0xffffc112, 0xffffee3f, 0x000011c1, 0x00004e06, +- 0xffffb1fa, 0x0000064e, 0xfffff9b2, 0x00005151, 0xffffaeaf, 0x000032cd, 0xffffcd33, 0x00003ed6, +- 0xffffc12a, 0xffffd63f, 0x000029c1, 0x000059f7, 0xffffa609, 0xfffff75a, 0x000008a6, 0x0000722a, +- 0xffff8dd6, 0x00002a72, 0xffffd58e, 0x0000753f, 0xffff8ac1, 0x00003f75, 0xffffc08b, 0x000050dc, +- 0xffffaf24, 0xffffdc51, 0x000023af, 0x00007815, 0xffff87eb, 0x00001578, 0xffffea88, 0x00007b60, +- 0xffff84a0, 0x0000607b, 0xffff9f85, 0x00006ee2, 0xffff911e, 0xffffe26f, 0x00001d91, 0x00005cb2, +- 0xffffa34e, 0xffffb25d, 0x00004da3, 0x000071bb, 0xffff8e45, 0xffffbb72, 0x0000448e, 0x00001212, +- 0xffffedee, 0x00002121, 0xffffdedf, 0x00003f3f, 0xffffc0c1, 0x00006c6c, 0xffff9394, 0x00000000, +- 0x03030000, 0xfcfd0000, 0x03000000, 0xfd000000, 0x00030000, 0xfffd0000, 0x06060000, 0xf9fa0000, +- 0x00000303, 0x03030303, 0xfcfd0303, 0x03000303, 0xfd000303, 0x00030303, 0xfffd0303, 0x06060303, +- 0xf9fa0303, 0xfffffcfd, 0x0302fcfd, 0xfcfcfcfd, 0x02fffcfd, 0xfcfffcfd, 0x0002fcfd, 0xfffcfcfd, +- 0x0605fcfd, 0xf9f9fcfd, 0x00000300, 0x03030300, 0xfcfd0300, 0x03000300, 0xfd000300, 0x00030300, +- 0xfffd0300, 0x06060300, 0xf9fa0300, 0xfffffd00, 0x0302fd00, 0xfcfcfd00, 0x02fffd00, 0xfcfffd00, +- 0x0002fd00, 0xfffcfd00, 0x0605fd00, 0xf9f9fd00, 0x00000003, 0x03030003, 0xfcfd0003, 0x03000003, +- 0xfd000003, 0x00030003, 0xfffd0003, 0x06060003, 0xf9fa0003, 0xfffffffd, 0x0302fffd, 0xfcfcfffd, +- 0x02fffffd, 0xfcfffffd, 0x0002fffd, 0xfffcfffd, 0x0605fffd, 0xf9f9fffd, 0x00000606, 0x03030606, +- 0xfcfd0606, 0x03000606, 0xfd000606, 0x00030606, 0xfffd0606, 0x06060606, 0xf9fa0606, 0xfffff9fa, +- 0x0302f9fa, 0xfcfcf9fa, 0x02fff9fa, 0xfcfff9fa, 0x0002f9fa, 0xfffcf9fa, 0x0605f9fa, 0xf9f9f9fa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000404, 0xfffffbfc, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000804, +- 0xfffff7fc, 0x00000408, 0xfffffbf8, 0x00000808, 0xfffff7f8, 0x000007f8, 0xfffff808, 0x00000bfc, +- 0xfffff404, 0xfffffc0c, 0x000003f4, 0x00001008, 0xffffeff8, 0x00000810, 0xfffff7f0, 0x00001010, +- 0xffffeff0, 0x00001400, 0xffffec00, 0x00000014, 0xffffffec, 0x00000ff4, 0xfffff00c, 0xfffff410, +- 0x00000bf0, 0x000017fc, 0xffffe804, 0xfffffc18, 0x000003e8, 0x00002010, 0xffffdff0, 0x00001020, +- 0xffffefe0, 0x00002008, 0xffffdff8, 0x00000820, 0xfffff7e0, 0x00002020, 0xffffdfe0, 0x00002400, +- 0xffffdc00, 0x00000024, 0xffffffdc, 0x000017e8, 0xffffe818, 0x00001ff0, 0xffffe010, 0xfffff020, +- 0x00000fe0, 0x00003414, 0xffffcbec, 0x00001434, 0xffffebcc, 0x00003824, 0xffffc7dc, 0x00002438, +- 0xffffdbc8, 0x00002bf4, 0xffffd40c, 0xfffff42c, 0x00000bd4, 0x00003808, 0xffffc7f8, 0x00000838, +- 0xfffff7c8, 0x00003c3c, 0xffffc3c4, 0x00003ffc, 0xffffc004, 0xfffffc40, 0x000003c0, 0x00002bdc, +- 0xffffd424, 0xffffdc2c, 0x000023d4, 0x00003be4, 0xffffc41c, 0xffffe43c, 0x00001bc4, 0x00005c2c, +- 0xffffa3d4, 0x00002c5c, 0xffffd3a4, 0x00005c18, 0xffffa3e8, 0x0000185c, 0xffffe7a4, 0x00006048, +- 0xffff9fb8, 0x00004860, 0xffffb7a0, 0x000053ec, 0xffffac14, 0xffffec54, 0x000013ac, 0x00006408, +- 0xffff9bf8, 0x00000864, 0xfffff79c, 0x00006c6c, 0xffff9394, 0x000043bc, 0xffffbc44, 0x000053c8, +- 0xffffac38, 0xffffc854, 0x000037ac, 0x000077f4, 0xffff880c, 0xfffff478, 0x00000b88, 0x00006bd0, +- 0xffff9430, 0xffffd06c, 0x00002f94, 0x00007b98, 0xffff8468, 0xffff987c, 0x00006784, 0x00001818, +- 0xffffe7e8, 0x00002c2c, 0xffffd3d4, 0x00005454, 0xffffabac, 0x00000000, 0x04040000, 0xfbfc0000, +- 0x04000000, 0xfc000000, 0x00040000, 0xfffc0000, 0x08040000, 0xf7fc0000, 0x04080000, 0x00000404, +- 0x04040404, 0xfbfc0404, 0x04000404, 0xfc000404, 0x00040404, 0xfffc0404, 0x08040404, 0xf7fc0404, +- 0x04080404, 0xfffffbfc, 0x0403fbfc, 0xfbfbfbfc, 0x03fffbfc, 0xfbfffbfc, 0x0003fbfc, 0xfffbfbfc, +- 0x0803fbfc, 0xf7fbfbfc, 0x0407fbfc, 0x00000400, 0x04040400, 0xfbfc0400, 0x04000400, 0xfc000400, +- 0x00040400, 0xfffc0400, 0x08040400, 0xf7fc0400, 0x04080400, 0xfffffc00, 0x0403fc00, 0xfbfbfc00, +- 0x03fffc00, 0xfbfffc00, 0x0003fc00, 0xfffbfc00, 0x0803fc00, 0xf7fbfc00, 0x0407fc00, 0x00000004, +- 0x04040004, 0xfbfc0004, 0x04000004, 0xfc000004, 0x00040004, 0xfffc0004, 0x08040004, 0xf7fc0004, +- 0x04080004, 0xfffffffc, 0x0403fffc, 0xfbfbfffc, 0x03fffffc, 0xfbfffffc, 0x0003fffc, 0xfffbfffc, +- 0x0803fffc, 0xf7fbfffc, 0x0407fffc, 0x00000804, 0x04040804, 0xfbfc0804, 0x04000804, 0xfc000804, +- 0x00040804, 0xfffc0804, 0x08040804, 0xf7fc0804, 0x04080804, 0xfffff7fc, 0x0403f7fc, 0xfbfbf7fc, +- 0x03fff7fc, 0xfbfff7fc, 0x0003f7fc, 0xfffbf7fc, 0x0803f7fc, 0xf7fbf7fc, 0x0407f7fc, 0x00000408, +- 0x04040408, 0xfbfc0408, 0x04000408, 0xfc000408, 0x00040408, 0xfffc0408, 0x08040408, 0xf7fc0408, +- 0x04080408, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000505, 0xfffffafb, 0x00000500, 0xfffffb00, 0x00000005, 0xfffffffb, 0x00000a0a, +- 0xfffff5f6, 0x00000f05, 0xfffff0fb, 0x0000050f, 0xfffffaf1, 0x000009f6, 0xfffff60a, 0x00000efb, +- 0xfffff105, 0xfffffb0f, 0x000004f1, 0x0000140a, 0xffffebf6, 0x00000a14, 0xfffff5ec, 0x00001414, +- 0xffffebec, 0x00001900, 0xffffe700, 0x00000019, 0xffffffe7, 0x000013f1, 0xffffec0f, 0xfffff114, +- 0x00000eec, 0x00002819, 0xffffd7e7, 0x00001928, 0xffffe6d8, 0x00001df6, 0xffffe20a, 0xfffff61e, +- 0x000009e2, 0x0000280a, 0xffffd7f6, 0x00000a28, 0xfffff5d8, 0x00002828, 0xffffd7d8, 0x00002d00, +- 0xffffd300, 0x0000002d, 0xffffffd3, 0x00001de2, 0xffffe21e, 0x000027ec, 0xffffd814, 0xffffec28, +- 0x000013d8, 0x00004119, 0xffffbee7, 0x00001941, 0xffffe6bf, 0x0000462d, 0xffffb9d3, 0x00002d46, +- 0xffffd2ba, 0x000036f1, 0xffffc90f, 0xfffff137, 0x00000ec9, 0x0000460a, 0xffffb9f6, 0x00000a46, +- 0xfffff5ba, 0x00004b4b, 0xffffb4b5, 0x000054fb, 0xffffab05, 0xfffffb55, 0x000004ab, 0x000036d3, +- 0xffffc92d, 0xffffd337, 0x00002cc9, 0x00004add, 0xffffb523, 0xffffdd4b, 0x000022b5, 0x00007337, +- 0xffff8cc9, 0x00003773, 0xffffc88d, 0x0000731e, 0xffff8ce2, 0x00001e73, 0xffffe18d, 0x0000785a, +- 0xffff87a6, 0x00005a78, 0xffffa588, 0x000068e2, 0xffff971e, 0xffffe269, 0x00001d97, 0x000054ab, +- 0xffffab55, 0x000068ba, 0xffff9746, 0xffffba69, 0x00004597, 0x00001e1e, 0xffffe1e2, 0x00003c3c, +- 0xffffc3c4, 0x00006969, 0xffff9697, 0x00000000, 0x05050000, 0xfafb0000, 0x05000000, 0xfb000000, +- 0x00050000, 0xfffb0000, 0x0a0a0000, 0xf5f60000, 0x0f050000, 0xf0fb0000, 0x00000505, 0x05050505, +- 0xfafb0505, 0x05000505, 0xfb000505, 0x00050505, 0xfffb0505, 0x0a0a0505, 0xf5f60505, 0x0f050505, +- 0xf0fb0505, 0xfffffafb, 0x0504fafb, 0xfafafafb, 0x04fffafb, 0xfafffafb, 0x0004fafb, 0xfffafafb, +- 0x0a09fafb, 0xf5f5fafb, 0x0f04fafb, 0xf0fafafb, 0x00000500, 0x05050500, 0xfafb0500, 0x05000500, +- 0xfb000500, 0x00050500, 0xfffb0500, 0x0a0a0500, 0xf5f60500, 0x0f050500, 0xf0fb0500, 0xfffffb00, +- 0x0504fb00, 0xfafafb00, 0x04fffb00, 0xfafffb00, 0x0004fb00, 0xfffafb00, 0x0a09fb00, 0xf5f5fb00, +- 0x0f04fb00, 0xf0fafb00, 0x00000005, 0x05050005, 0xfafb0005, 0x05000005, 0xfb000005, 0x00050005, +- 0xfffb0005, 0x0a0a0005, 0xf5f60005, 0x0f050005, 0xf0fb0005, 0xfffffffb, 0x0504fffb, 0xfafafffb, +- 0x04fffffb, 0xfafffffb, 0x0004fffb, 0xfffafffb, 0x0a09fffb, 0xf5f5fffb, 0x0f04fffb, 0xf0fafffb, +- 0x00000a0a, 0x05050a0a, 0xfafb0a0a, 0x05000a0a, 0xfb000a0a, 0x00050a0a, 0xfffb0a0a, 0x0a0a0a0a, +- 0xf5f60a0a, 0x0f050a0a, 0xf0fb0a0a, 0xfffff5f6, 0x0504f5f6, 0xfafaf5f6, 0x04fff5f6, 0xfafff5f6, +- 0x0004f5f6, 0xfffaf5f6, 0x0a09f5f6, 0xf5f5f5f6, 0x0f04f5f6, 0xf0faf5f6, 0x00000f05, 0x05050f05, +- 0xfafb0f05, 0x05000f05, 0xfb000f05, 0x00050f05, 0xfffb0f05, 0x0a0a0f05, 0xf5f60f05, 0x0f050f05, +- 0xf0fb0f05, 0xfffff0fb, 0x0504f0fb, 0xfafaf0fb, 0x04fff0fb, 0xfafff0fb, 0x0004f0fb, 0xfffaf0fb, +- 0x0a09f0fb, 0xf5f5f0fb, 0x0f04f0fb, 0xf0faf0fb, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000606, 0xfffff9fa, 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x00000c0c, +- 0xfffff3f4, 0x00000c06, 0xfffff3fa, 0x0000060c, 0xfffff9f4, 0x00000bf4, 0xfffff40c, 0x000011fa, +- 0xffffee06, 0xfffffa12, 0x000005ee, 0x0000180c, 0xffffe7f4, 0x00000c18, 0xfffff3e8, 0x00001818, +- 0xffffe7e8, 0x00001e00, 0xffffe200, 0x0000001e, 0xffffffe2, 0x000017ee, 0xffffe812, 0xffffee18, +- 0x000011e8, 0x0000301e, 0xffffcfe2, 0x00001e30, 0xffffe1d0, 0x000023fa, 0xffffdc06, 0xfffffa24, +- 0x000005dc, 0x0000300c, 0xffffcff4, 0x00000c30, 0xfffff3d0, 0x00003030, 0xffffcfd0, 0x00003600, +- 0xffffca00, 0x00000036, 0xffffffca, 0x000023dc, 0xffffdc24, 0x00002fe8, 0xffffd018, 0xffffe830, +- 0x000017d0, 0x00004e1e, 0xffffb1e2, 0x00001e4e, 0xffffe1b2, 0x00005436, 0xffffabca, 0x00003654, +- 0xffffc9ac, 0x000041ee, 0xffffbe12, 0xffffee42, 0x000011be, 0x0000540c, 0xffffabf4, 0x00000c54, +- 0xfffff3ac, 0x00005a5a, 0xffffa5a6, 0x00005ffa, 0xffffa006, 0xfffffa60, 0x000005a0, 0x000041ca, +- 0xffffbe36, 0xffffca42, 0x000035be, 0x000059d6, 0xffffa62a, 0xffffd65a, 0x000029a6, 0x00007de2, +- 0xffff821e, 0xffffe27e, 0x00001d82, 0x0000659a, 0xffff9a66, 0x00007dac, 0xffff8254, 0xffffac7e, +- 0x00005382, 0x00002424, 0xffffdbdc, 0x00004242, 0xffffbdbe, 0x00000000, 0x06060000, 0xf9fa0000, +- 0x06000000, 0xfa000000, 0x00060000, 0xfffa0000, 0x0c0c0000, 0xf3f40000, 0x0c060000, 0xf3fa0000, +- 0x060c0000, 0x00000606, 0x06060606, 0xf9fa0606, 0x06000606, 0xfa000606, 0x00060606, 0xfffa0606, +- 0x0c0c0606, 0xf3f40606, 0x0c060606, 0xf3fa0606, 0x060c0606, 0xfffff9fa, 0x0605f9fa, 0xf9f9f9fa, +- 0x05fff9fa, 0xf9fff9fa, 0x0005f9fa, 0xfff9f9fa, 0x0c0bf9fa, 0xf3f3f9fa, 0x0c05f9fa, 0xf3f9f9fa, +- 0x060bf9fa, 0x00000600, 0x06060600, 0xf9fa0600, 0x06000600, 0xfa000600, 0x00060600, 0xfffa0600, +- 0x0c0c0600, 0xf3f40600, 0x0c060600, 0xf3fa0600, 0x060c0600, 0xfffffa00, 0x0605fa00, 0xf9f9fa00, +- 0x05fffa00, 0xf9fffa00, 0x0005fa00, 0xfff9fa00, 0x0c0bfa00, 0xf3f3fa00, 0x0c05fa00, 0xf3f9fa00, +- 0x060bfa00, 0x00000006, 0x06060006, 0xf9fa0006, 0x06000006, 0xfa000006, 0x00060006, 0xfffa0006, +- 0x0c0c0006, 0xf3f40006, 0x0c060006, 0xf3fa0006, 0x060c0006, 0xfffffffa, 0x0605fffa, 0xf9f9fffa, +- 0x05fffffa, 0xf9fffffa, 0x0005fffa, 0xfff9fffa, 0x0c0bfffa, 0xf3f3fffa, 0x0c05fffa, 0xf3f9fffa, +- 0x060bfffa, 0x00000c0c, 0x06060c0c, 0xf9fa0c0c, 0x06000c0c, 0xfa000c0c, 0x00060c0c, 0xfffa0c0c, +- 0x0c0c0c0c, 0xf3f40c0c, 0x0c060c0c, 0xf3fa0c0c, 0x060c0c0c, 0xfffff3f4, 0x0605f3f4, 0xf9f9f3f4, +- 0x05fff3f4, 0xf9fff3f4, 0x0005f3f4, 0xfff9f3f4, 0x0c0bf3f4, 0xf3f3f3f4, 0x0c05f3f4, 0xf3f9f3f4, +- 0x060bf3f4, 0x00000c06, 0x06060c06, 0xf9fa0c06, 0x06000c06, 0xfa000c06, 0x00060c06, 0xfffa0c06, +- 0x0c0c0c06, 0xf3f40c06, 0x0c060c06, 0xf3fa0c06, 0x060c0c06, 0xfffff3fa, 0x0605f3fa, 0xf9f9f3fa, +- 0x05fff3fa, 0xf9fff3fa, 0x0005f3fa, 0xfff9f3fa, 0x0c0bf3fa, 0xf3f3f3fa, 0x0c05f3fa, 0xf3f9f3fa, +- 0x060bf3fa, 0x0000060c, 0x0606060c, 0xf9fa060c, 0x0600060c, 0xfa00060c, 0x0006060c, 0xfffa060c, +- 0x0c0c060c, 0xf3f4060c, 0x0c06060c, 0xf3fa060c, 0x060c060c, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000707, 0xfffff8f9, 0x00000700, 0xfffff900, 0x00000007, 0xfffffff9, 0x00000e0e, +- 0xfffff1f2, 0x00001507, 0xffffeaf9, 0x00000715, 0xfffff8eb, 0x00000df2, 0xfffff20e, 0x000014f9, +- 0xffffeb07, 0xfffff915, 0x000006eb, 0x00001c0e, 0xffffe3f2, 0x00000e1c, 0xfffff1e4, 0x00001c1c, +- 0xffffe3e4, 0x00002300, 0xffffdd00, 0x00000023, 0xffffffdd, 0x00001beb, 0xffffe415, 0xffffeb1c, +- 0x000014e4, 0x00003823, 0xffffc7dd, 0x00002338, 0xffffdcc8, 0x000029f2, 0xffffd60e, 0xfffff22a, +- 0x00000dd6, 0x0000380e, 0xffffc7f2, 0x00000e38, 0xfffff1c8, 0x00003838, 0xffffc7c8, 0x00003f00, +- 0xffffc100, 0x0000003f, 0xffffffc1, 0x000029d6, 0xffffd62a, 0x000037e4, 0xffffc81c, 0xffffe438, +- 0x00001bc8, 0x00005b23, 0xffffa4dd, 0x0000235b, 0xffffdca5, 0x0000623f, 0xffff9dc1, 0x00003f62, +- 0xffffc09e, 0x00004ceb, 0xffffb315, 0xffffeb4d, 0x000014b3, 0x0000620e, 0xffff9df2, 0x00000e62, +- 0xfffff19e, 0x00006969, 0xffff9697, 0x000076f9, 0xffff8907, 0xfffff977, 0x00000689, 0x00004cc1, +- 0xffffb33f, 0xffffc14d, 0x00003eb3, 0x000068cf, 0xffff9731, 0xffffcf69, 0x00003097, 0x00007689, +- 0xffff8977, 0x00002a2a, 0xffffd5d6, 0x00004d4d, 0xffffb2b3, 0x00000000, 0x07070000, 0xf8f90000, +- 0x07000000, 0xf9000000, 0x00070000, 0xfff90000, 0x0e0e0000, 0xf1f20000, 0x15070000, 0xeaf90000, +- 0x07150000, 0x00000707, 0x07070707, 0xf8f90707, 0x07000707, 0xf9000707, 0x00070707, 0xfff90707, +- 0x0e0e0707, 0xf1f20707, 0x15070707, 0xeaf90707, 0x07150707, 0xfffff8f9, 0x0706f8f9, 0xf8f8f8f9, +- 0x06fff8f9, 0xf8fff8f9, 0x0006f8f9, 0xfff8f8f9, 0x0e0df8f9, 0xf1f1f8f9, 0x1506f8f9, 0xeaf8f8f9, +- 0x0714f8f9, 0x00000700, 0x07070700, 0xf8f90700, 0x07000700, 0xf9000700, 0x00070700, 0xfff90700, +- 0x0e0e0700, 0xf1f20700, 0x15070700, 0xeaf90700, 0x07150700, 0xfffff900, 0x0706f900, 0xf8f8f900, +- 0x06fff900, 0xf8fff900, 0x0006f900, 0xfff8f900, 0x0e0df900, 0xf1f1f900, 0x1506f900, 0xeaf8f900, +- 0x0714f900, 0x00000007, 0x07070007, 0xf8f90007, 0x07000007, 0xf9000007, 0x00070007, 0xfff90007, +- 0x0e0e0007, 0xf1f20007, 0x15070007, 0xeaf90007, 0x07150007, 0xfffffff9, 0x0706fff9, 0xf8f8fff9, +- 0x06fffff9, 0xf8fffff9, 0x0006fff9, 0xfff8fff9, 0x0e0dfff9, 0xf1f1fff9, 0x1506fff9, 0xeaf8fff9, +- 0x0714fff9, 0x00000e0e, 0x07070e0e, 0xf8f90e0e, 0x07000e0e, 0xf9000e0e, 0x00070e0e, 0xfff90e0e, +- 0x0e0e0e0e, 0xf1f20e0e, 0x15070e0e, 0xeaf90e0e, 0x07150e0e, 0xfffff1f2, 0x0706f1f2, 0xf8f8f1f2, +- 0x06fff1f2, 0xf8fff1f2, 0x0006f1f2, 0xfff8f1f2, 0x0e0df1f2, 0xf1f1f1f2, 0x1506f1f2, 0xeaf8f1f2, +- 0x0714f1f2, 0x00001507, 0x07071507, 0xf8f91507, 0x07001507, 0xf9001507, 0x00071507, 0xfff91507, +- 0x0e0e1507, 0xf1f21507, 0x15071507, 0xeaf91507, 0x07151507, 0xffffeaf9, 0x0706eaf9, 0xf8f8eaf9, +- 0x06ffeaf9, 0xf8ffeaf9, 0x0006eaf9, 0xfff8eaf9, 0x0e0deaf9, 0xf1f1eaf9, 0x1506eaf9, 0xeaf8eaf9, +- 0x0714eaf9, 0x00000715, 0x07070715, 0xf8f90715, 0x07000715, 0xf9000715, 0x00070715, 0xfff90715, +- 0x0e0e0715, 0xf1f20715, 0x15070715, 0xeaf90715, 0x07150715, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000808, 0xfffff7f8, 0x00000800, 0xfffff800, 0x00000008, 0xfffffff8, 0x00001010, +- 0xffffeff0, 0x00001008, 0xffffeff8, 0x00000810, 0xfffff7f0, 0x00000ff0, 0xfffff010, 0x000017f8, +- 0xffffe808, 0xfffff818, 0x000007e8, 0x00002010, 0xffffdff0, 0x00001020, 0xffffefe0, 0x00002020, +- 0xffffdfe0, 0x00002800, 0xffffd800, 0x00000028, 0xffffffd8, 0x00001fe8, 0xffffe018, 0xffffe820, +- 0x000017e0, 0x00004028, 0xffffbfd8, 0x00002840, 0xffffd7c0, 0x00002ff0, 0xffffd010, 0xfffff030, +- 0x00000fd0, 0x00004010, 0xffffbff0, 0x00001040, 0xffffefc0, 0x00004040, 0xffffbfc0, 0x00004800, +- 0xffffb800, 0x00000048, 0xffffffb8, 0x00002fd0, 0xffffd030, 0x00003fe0, 0xffffc020, 0xffffe040, +- 0x00001fc0, 0x00006828, 0xffff97d8, 0x00002868, 0xffffd798, 0x00007048, 0xffff8fb8, 0x00004870, +- 0xffffb790, 0x000057e8, 0xffffa818, 0xffffe858, 0x000017a8, 0x00007010, 0xffff8ff0, 0x00001070, +- 0xffffef90, 0x00007878, 0xffff8788, 0x000057b8, 0xffffa848, 0xffffb858, 0x000047a8, 0x000077c8, +- 0xffff8838, 0xffffc878, 0x00003788, 0x00003030, 0xffffcfd0, 0x00005858, 0xffffa7a8, 0x00000000, +- 0x08080000, 0xf7f80000, 0x08000000, 0xf8000000, 0x00080000, 0xfff80000, 0x10100000, 0xeff00000, +- 0x10080000, 0xeff80000, 0x08100000, 0x00000808, 0x08080808, 0xf7f80808, 0x08000808, 0xf8000808, +- 0x00080808, 0xfff80808, 0x10100808, 0xeff00808, 0x10080808, 0xeff80808, 0x08100808, 0xfffff7f8, +- 0x0807f7f8, 0xf7f7f7f8, 0x07fff7f8, 0xf7fff7f8, 0x0007f7f8, 0xfff7f7f8, 0x100ff7f8, 0xefeff7f8, +- 0x1007f7f8, 0xeff7f7f8, 0x080ff7f8, 0x00000800, 0x08080800, 0xf7f80800, 0x08000800, 0xf8000800, +- 0x00080800, 0xfff80800, 0x10100800, 0xeff00800, 0x10080800, 0xeff80800, 0x08100800, 0xfffff800, +- 0x0807f800, 0xf7f7f800, 0x07fff800, 0xf7fff800, 0x0007f800, 0xfff7f800, 0x100ff800, 0xefeff800, +- 0x1007f800, 0xeff7f800, 0x080ff800, 0x00000008, 0x08080008, 0xf7f80008, 0x08000008, 0xf8000008, +- 0x00080008, 0xfff80008, 0x10100008, 0xeff00008, 0x10080008, 0xeff80008, 0x08100008, 0xfffffff8, +- 0x0807fff8, 0xf7f7fff8, 0x07fffff8, 0xf7fffff8, 0x0007fff8, 0xfff7fff8, 0x100ffff8, 0xefeffff8, +- 0x1007fff8, 0xeff7fff8, 0x080ffff8, 0x00001010, 0x08081010, 0xf7f81010, 0x08001010, 0xf8001010, +- 0x00081010, 0xfff81010, 0x10101010, 0xeff01010, 0x10081010, 0xeff81010, 0x08101010, 0xffffeff0, +- 0x0807eff0, 0xf7f7eff0, 0x07ffeff0, 0xf7ffeff0, 0x0007eff0, 0xfff7eff0, 0x100feff0, 0xefefeff0, +- 0x1007eff0, 0xeff7eff0, 0x080feff0, 0x00001008, 0x08081008, 0xf7f81008, 0x08001008, 0xf8001008, +- 0x00081008, 0xfff81008, 0x10101008, 0xeff01008, 0x10081008, 0xeff81008, 0x08101008, 0xffffeff8, +- 0x0807eff8, 0xf7f7eff8, 0x07ffeff8, 0xf7ffeff8, 0x0007eff8, 0xfff7eff8, 0x100feff8, 0xefefeff8, +- 0x1007eff8, 0xeff7eff8, 0x080feff8, 0x00000810, 0x08080810, 0xf7f80810, 0x08000810, 0xf8000810, +- 0x00080810, 0xfff80810, 0x10100810, 0xeff00810, 0x10080810, 0xeff80810, 0x08100810, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000909, 0xfffff6f7, 0x00000900, 0xfffff700, 0x00000009, 0xfffffff7, 0x00001212, +- 0xffffedee, 0x00001b09, 0xffffe4f7, 0x0000091b, 0xfffff6e5, 0x000011ee, 0xffffee12, 0x00001af7, +- 0xffffe509, 0xfffff71b, 0x000008e5, 0x00002412, 0xffffdbee, 0x00001224, 0xffffeddc, 0x00002424, +- 0xffffdbdc, 0x00002d00, 0xffffd300, 0x0000002d, 0xffffffd3, 0x000023e5, 0xffffdc1b, 0xffffe524, +- 0x00001adc, 0x0000482d, 0xffffb7d3, 0x00002d48, 0xffffd2b8, 0x000035ee, 0xffffca12, 0xffffee36, +- 0x000011ca, 0x00004812, 0xffffb7ee, 0x00001248, 0xffffedb8, 0x00004848, 0xffffb7b8, 0x00005100, +- 0xffffaf00, 0x00000051, 0xffffffaf, 0x000035ca, 0xffffca36, 0x000047dc, 0xffffb824, 0xffffdc48, +- 0x000023b8, 0x0000752d, 0xffff8ad3, 0x00002d75, 0xffffd28b, 0x00007e51, 0xffff81af, 0x0000517e, +- 0xffffae82, 0x000062e5, 0xffff9d1b, 0xffffe563, 0x00001a9d, 0x000062af, 0xffff9d51, 0xffffaf63, +- 0x0000509d, 0x00003636, 0xffffc9ca, 0x00006c6c, 0xffff9394, 0x00000000, 0x09090000, 0xf6f70000, +- 0x09000000, 0xf7000000, 0x00090000, 0xfff70000, 0x12120000, 0xedee0000, 0x1b090000, 0xe4f70000, +- 0x091b0000, 0xf6e50000, 0x00000909, 0x09090909, 0xf6f70909, 0x09000909, 0xf7000909, 0x00090909, +- 0xfff70909, 0x12120909, 0xedee0909, 0x1b090909, 0xe4f70909, 0x091b0909, 0xf6e50909, 0xfffff6f7, +- 0x0908f6f7, 0xf6f6f6f7, 0x08fff6f7, 0xf6fff6f7, 0x0008f6f7, 0xfff6f6f7, 0x1211f6f7, 0xededf6f7, +- 0x1b08f6f7, 0xe4f6f6f7, 0x091af6f7, 0xf6e4f6f7, 0x00000900, 0x09090900, 0xf6f70900, 0x09000900, +- 0xf7000900, 0x00090900, 0xfff70900, 0x12120900, 0xedee0900, 0x1b090900, 0xe4f70900, 0x091b0900, +- 0xf6e50900, 0xfffff700, 0x0908f700, 0xf6f6f700, 0x08fff700, 0xf6fff700, 0x0008f700, 0xfff6f700, +- 0x1211f700, 0xededf700, 0x1b08f700, 0xe4f6f700, 0x091af700, 0xf6e4f700, 0x00000009, 0x09090009, +- 0xf6f70009, 0x09000009, 0xf7000009, 0x00090009, 0xfff70009, 0x12120009, 0xedee0009, 0x1b090009, +- 0xe4f70009, 0x091b0009, 0xf6e50009, 0xfffffff7, 0x0908fff7, 0xf6f6fff7, 0x08fffff7, 0xf6fffff7, +- 0x0008fff7, 0xfff6fff7, 0x1211fff7, 0xededfff7, 0x1b08fff7, 0xe4f6fff7, 0x091afff7, 0xf6e4fff7, +- 0x00001212, 0x09091212, 0xf6f71212, 0x09001212, 0xf7001212, 0x00091212, 0xfff71212, 0x12121212, +- 0xedee1212, 0x1b091212, 0xe4f71212, 0x091b1212, 0xf6e51212, 0xffffedee, 0x0908edee, 0xf6f6edee, +- 0x08ffedee, 0xf6ffedee, 0x0008edee, 0xfff6edee, 0x1211edee, 0xedededee, 0x1b08edee, 0xe4f6edee, +- 0x091aedee, 0xf6e4edee, 0x00001b09, 0x09091b09, 0xf6f71b09, 0x09001b09, 0xf7001b09, 0x00091b09, +- 0xfff71b09, 0x12121b09, 0xedee1b09, 0x1b091b09, 0xe4f71b09, 0x091b1b09, 0xf6e51b09, 0xffffe4f7, +- 0x0908e4f7, 0xf6f6e4f7, 0x08ffe4f7, 0xf6ffe4f7, 0x0008e4f7, 0xfff6e4f7, 0x1211e4f7, 0xedede4f7, +- 0x1b08e4f7, 0xe4f6e4f7, 0x091ae4f7, 0xf6e4e4f7, 0x0000091b, 0x0909091b, 0xf6f7091b, 0x0900091b, +- 0xf700091b, 0x0009091b, 0xfff7091b, 0x1212091b, 0xedee091b, 0x1b09091b, 0xe4f7091b, 0x091b091b, +- 0xf6e5091b, 0xfffff6e5, 0x0908f6e5, 0xf6f6f6e5, 0x08fff6e5, 0xf6fff6e5, 0x0008f6e5, 0xfff6f6e5, +- 0x1211f6e5, 0xededf6e5, 0x1b08f6e5, 0xe4f6f6e5, 0x091af6e5, 0xf6e4f6e5, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606, +- 0xfffff9fa, 0x00000700, 0xfffff900, 0x00000007, 0xfffffff9, 0x000004fb, 0xfffffb05, 0xfffffb05, +- 0x000004fb, 0x00000b06, 0xfffff4fa, 0x0000060b, 0xfffff9f5, 0x00000800, 0xfffff800, 0x00000008, +- 0xfffffff8, 0x00000b0b, 0xfffff4f5, 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x0000110c, +- 0xffffeef4, 0x00000c11, 0xfffff3ef, 0x00001111, 0xffffeeef, 0x00001206, 0xffffedfa, 0x00000612, +- 0xfffff9ee, 0x00000af8, 0xfffff508, 0xfffff80b, 0x000007f5, 0x00000f00, 0xfffff100, 0x0000000f, +- 0xfffffff1, 0x00001400, 0xffffec00, 0x00000014, 0xffffffec, 0x00001912, 0xffffe6ee, 0x00001219, +- 0xffffede7, 0x0000190b, 0xffffe6f5, 0x00000b19, 0xfffff4e7, 0x00001919, 0xffffe6e7, 0x00000df2, +- 0xfffff20e, 0xfffff20e, 0x00000df2, 0x00001a00, 0xffffe600, 0x0000001a, 0xffffffe6, 0x000011f5, +- 0xffffee0b, 0xfffff512, 0x00000aee, 0x000015f9, 0xffffea07, 0xfffff916, 0x000006ea, 0x0000221a, +- 0xffffdde6, 0x00001a22, 0xffffe5de, 0x00002212, 0xffffddee, 0x00001222, 0xffffedde, 0x00002222, +- 0xffffddde, 0x0000230b, 0xffffdcf5, 0x00000b23, 0xfffff4dd, 0x00001d00, 0xffffe300, 0x0000001d, +- 0xffffffe3, 0x000015ed, 0xffffea13, 0xffffed16, 0x000012ea, 0x000019f1, 0xffffe60f, 0xfffff11a, +- 0x00000ee6, 0x00002500, 0xffffdb00, 0x00000025, 0xffffffdb, 0x00002c1b, 0xffffd3e5, 0x00001b2c, +- 0xffffe4d4, 0x00002c24, 0xffffd3dc, 0x0000242c, 0xffffdbd4, 0x00002c12, 0xffffd3ee, 0x0000122c, +- 0xffffedd4, 0x000020f6, 0xffffdf0a, 0xfffff621, 0x000009df, 0x00002d2d, 0xffffd2d3, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000300, 0xfffffd00, 0x00000003, 0xfffffffd, 0x00000606, +- 0xfffff9fa, 0x00000700, 0xfffff900, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020300, 0x0201fd00, +- 0x02020003, 0x0201fffd, 0x02020606, 0x0201f9fa, 0x02020700, 0x0201f900, 0xfdfe0000, 0xfdfe0202, +- 0xfdfdfdfe, 0xfdfe0300, 0xfdfdfd00, 0xfdfe0003, 0xfdfdfffd, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0700, +- 0xfdfdf900, 0x03000000, 0x03000202, 0x02fffdfe, 0x03000300, 0x02fffd00, 0x03000003, 0x02fffffd, +- 0x03000606, 0x02fff9fa, 0x03000700, 0x02fff900, 0xfd000000, 0xfd000202, 0xfcfffdfe, 0xfd000300, +- 0xfcfffd00, 0xfd000003, 0xfcfffffd, 0xfd000606, 0xfcfff9fa, 0xfd000700, 0xfcfff900, 0x00030000, +- 0x00030202, 0x0002fdfe, 0x00030300, 0x0002fd00, 0x00030003, 0x0002fffd, 0x00030606, 0x0002f9fa, +- 0x00030700, 0x0002f900, 0xfffd0000, 0xfffd0202, 0xfffcfdfe, 0xfffd0300, 0xfffcfd00, 0xfffd0003, +- 0xfffcfffd, 0xfffd0606, 0xfffcf9fa, 0xfffd0700, 0xfffcf900, 0x06060000, 0x06060202, 0x0605fdfe, +- 0x06060300, 0x0605fd00, 0x06060003, 0x0605fffd, 0x06060606, 0x0605f9fa, 0x06060700, 0x0605f900, +- 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0300, 0xf9f9fd00, 0xf9fa0003, 0xf9f9fffd, 0xf9fa0606, +- 0xf9f9f9fa, 0xf9fa0700, 0xf9f9f900, 0x07000000, 0x07000202, 0x06fffdfe, 0x07000300, 0x06fffd00, +- 0x07000003, 0x06fffffd, 0x07000606, 0x06fff9fa, 0x07000700, 0x06fff900, 0xf9000000, 0xf9000202, +- 0xf8fffdfe, 0xf9000300, 0xf8fffd00, 0xf9000003, 0xf8fffffd, 0xf9000606, 0xf8fff9fa, 0xf9000700, +- 0xf8fff900, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000202, 0xfffffdfe, 0x00000606, +- 0xfffff9fa, 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x000003fc, 0xfffffc04, 0xfffffa0a, +- 0x000005f6, 0xfffff400, 0x00000c00, 0xfffff3fa, 0xfffff406, 0x00000bfa, 0x00000c06, 0xfffffff2, +- 0x0000000e, 0x00000c0c, 0xfffff3f4, 0xffffee00, 0x00001200, 0xfffff40e, 0x00000bf2, 0xfffff9ee, +- 0xfffffa12, 0x000005ee, 0x00000612, 0xffffedf6, 0xffffee0a, 0x000011f6, 0x0000120a, 0xffffffea, +- 0x00000016, 0xffffe800, 0x00001800, 0xfffff3ea, 0xfffff416, 0x00000bea, 0x00000c16, 0xffffe7f8, +- 0xffffe808, 0x000017f8, 0x00001808, 0xfffff9e6, 0xfffffa1a, 0x000005e6, 0x0000061a, 0xffffffe4, +- 0x0000001c, 0x00001414, 0xffffebec, 0xffffe5f2, 0x00001a0e, 0xfffff3e2, 0x00000c1e, 0xffffdff6, +- 0x0000200a, 0xffffdfee, 0x00002012, 0xffffe5e6, 0x00001a1a, 0xffffebde, 0x00001422, 0xfffff3da, +- 0x00000c26, 0xffffdfe0, 0x00002020, 0x00002020, 0xffffd7ea, 0xffffddde, 0x00002222, 0x00000000, +- 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, +- 0x00000600, 0xfffffa00, 0x00000006, 0xfffffffa, 0x02000000, 0x02000200, 0x01fffe00, 0x02000002, +- 0x01fffffe, 0x02000202, 0x01fffdfe, 0x02000606, 0x01fff9fa, 0x02000600, 0x01fffa00, 0x02000006, +- 0x01fffffa, 0xfe000000, 0xfe000200, 0xfdfffe00, 0xfe000002, 0xfdfffffe, 0xfe000202, 0xfdfffdfe, +- 0xfe000606, 0xfdfff9fa, 0xfe000600, 0xfdfffa00, 0xfe000006, 0xfdfffffa, 0x00020000, 0x00020200, +- 0x0001fe00, 0x00020002, 0x0001fffe, 0x00020202, 0x0001fdfe, 0x00020606, 0x0001f9fa, 0x00020600, +- 0x0001fa00, 0x00020006, 0x0001fffa, 0xfffe0000, 0xfffe0200, 0xfffdfe00, 0xfffe0002, 0xfffdfffe, +- 0xfffe0202, 0xfffdfdfe, 0xfffe0606, 0xfffdf9fa, 0xfffe0600, 0xfffdfa00, 0xfffe0006, 0xfffdfffa, +- 0x02020000, 0x02020200, 0x0201fe00, 0x02020002, 0x0201fffe, 0x02020202, 0x0201fdfe, 0x02020606, +- 0x0201f9fa, 0x02020600, 0x0201fa00, 0x02020006, 0x0201fffa, 0xfdfe0000, 0xfdfe0200, 0xfdfdfe00, +- 0xfdfe0002, 0xfdfdfffe, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0600, 0xfdfdfa00, +- 0xfdfe0006, 0xfdfdfffa, 0x06060000, 0x06060200, 0x0605fe00, 0x06060002, 0x0605fffe, 0x06060202, +- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060600, 0x0605fa00, 0x06060006, 0x0605fffa, 0xf9fa0000, +- 0xf9fa0200, 0xf9f9fe00, 0xf9fa0002, 0xf9f9fffe, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa, +- 0xf9fa0600, 0xf9f9fa00, 0xf9fa0006, 0xf9f9fffa, 0x06000000, 0x06000200, 0x05fffe00, 0x06000002, +- 0x05fffffe, 0x06000202, 0x05fffdfe, 0x06000606, 0x05fff9fa, 0x06000600, 0x05fffa00, 0x06000006, +- 0x05fffffa, 0xfa000000, 0xfa000200, 0xf9fffe00, 0xfa000002, 0xf9fffffe, 0xfa000202, 0xf9fffdfe, +- 0xfa000606, 0xf9fff9fa, 0xfa000600, 0xf9fffa00, 0xfa000006, 0xf9fffffa, 0x00060000, 0x00060200, +- 0x0005fe00, 0x00060002, 0x0005fffe, 0x00060202, 0x0005fdfe, 0x00060606, 0x0005f9fa, 0x00060600, +- 0x0005fa00, 0x00060006, 0x0005fffa, 0xfffa0000, 0xfffa0200, 0xfff9fe00, 0xfffa0002, 0xfff9fffe, +- 0xfffa0202, 0xfff9fdfe, 0xfffa0606, 0xfff9f9fa, 0xfffa0600, 0xfff9fa00, 0xfffa0006, 0xfff9fffa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404, 0xfffffbfc, 0x00000a0a, +- 0xfffff5f6, 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x000005fa, 0xfffffa06, 0xfffff80e, +- 0x000007f2, 0xffffffee, 0x00000012, 0xfffff00a, 0x00000ff6, 0xffffe800, 0x00001800, 0xfffff7e8, +- 0xfffff818, 0x000007e8, 0x00000818, 0x00001212, 0xffffedee, 0xfffff014, 0x00000fec, 0xffffe5f2, +- 0xffffe60e, 0x000019f2, 0x00001a0e, 0xffffffe2, 0x0000001e, 0xffffde00, 0x00002200, 0xfffff7de, +- 0xfffff822, 0x000007de, 0x00000822, 0xffffede2, 0xffffee1e, 0x000011e2, 0x0000121e, 0xffffddf6, +- 0xffffde0a, 0x000021f6, 0x0000220a, 0xffffddec, 0x00002214, 0xffffffd8, 0x00000028, 0x00001e1e, +- 0xffffe1e2, 0xffffedd8, 0x00001228, 0xffffd400, 0x00002c00, 0xffffd3f0, 0x00002c10, 0xffffdbdc, +- 0xffffdbdc, 0x00002424, 0xffffd3e6, 0x00002c1a, 0xffffe5d2, 0x00001a2e, 0xffffedcc, 0x00001234, +- 0xffffc9ec, 0xffffd3d4, 0x00002c2c, 0xffffc9e0, 0xffffd1d2, 0xffffd1d2, 0x00002e2e, 0x00000000, +- 0x00000200, 0xfffffe00, 0x00000002, 0xfffffffe, 0x00000404, 0xfffffbfc, 0x00000a0a, 0xfffff5f6, +- 0x00000a00, 0xfffff600, 0x0000000a, 0xfffffff6, 0x02000000, 0x02000200, 0x01fffe00, 0x02000002, +- 0x01fffffe, 0x02000404, 0x01fffbfc, 0x02000a0a, 0x01fff5f6, 0x02000a00, 0x01fff600, 0x0200000a, +- 0x01fffff6, 0xfe000000, 0xfe000200, 0xfdfffe00, 0xfe000002, 0xfdfffffe, 0xfe000404, 0xfdfffbfc, +- 0xfe000a0a, 0xfdfff5f6, 0xfe000a00, 0xfdfff600, 0xfe00000a, 0xfdfffff6, 0x00020000, 0x00020200, +- 0x0001fe00, 0x00020002, 0x0001fffe, 0x00020404, 0x0001fbfc, 0x00020a0a, 0x0001f5f6, 0x00020a00, +- 0x0001f600, 0x0002000a, 0x0001fff6, 0xfffe0000, 0xfffe0200, 0xfffdfe00, 0xfffe0002, 0xfffdfffe, +- 0xfffe0404, 0xfffdfbfc, 0xfffe0a0a, 0xfffdf5f6, 0xfffe0a00, 0xfffdf600, 0xfffe000a, 0xfffdfff6, +- 0x04040000, 0x04040200, 0x0403fe00, 0x04040002, 0x0403fffe, 0x04040404, 0x0403fbfc, 0x04040a0a, +- 0x0403f5f6, 0x04040a00, 0x0403f600, 0x0404000a, 0x0403fff6, 0xfbfc0000, 0xfbfc0200, 0xfbfbfe00, +- 0xfbfc0002, 0xfbfbfffe, 0xfbfc0404, 0xfbfbfbfc, 0xfbfc0a0a, 0xfbfbf5f6, 0xfbfc0a00, 0xfbfbf600, +- 0xfbfc000a, 0xfbfbfff6, 0x0a0a0000, 0x0a0a0200, 0x0a09fe00, 0x0a0a0002, 0x0a09fffe, 0x0a0a0404, +- 0x0a09fbfc, 0x0a0a0a0a, 0x0a09f5f6, 0x0a0a0a00, 0x0a09f600, 0x0a0a000a, 0x0a09fff6, 0xf5f60000, +- 0xf5f60200, 0xf5f5fe00, 0xf5f60002, 0xf5f5fffe, 0xf5f60404, 0xf5f5fbfc, 0xf5f60a0a, 0xf5f5f5f6, +- 0xf5f60a00, 0xf5f5f600, 0xf5f6000a, 0xf5f5fff6, 0x0a000000, 0x0a000200, 0x09fffe00, 0x0a000002, +- 0x09fffffe, 0x0a000404, 0x09fffbfc, 0x0a000a0a, 0x09fff5f6, 0x0a000a00, 0x09fff600, 0x0a00000a, +- 0x09fffff6, 0xf6000000, 0xf6000200, 0xf5fffe00, 0xf6000002, 0xf5fffffe, 0xf6000404, 0xf5fffbfc, +- 0xf6000a0a, 0xf5fff5f6, 0xf6000a00, 0xf5fff600, 0xf600000a, 0xf5fffff6, 0x000a0000, 0x000a0200, +- 0x0009fe00, 0x000a0002, 0x0009fffe, 0x000a0404, 0x0009fbfc, 0x000a0a0a, 0x0009f5f6, 0x000a0a00, +- 0x0009f600, 0x000a000a, 0x0009fff6, 0xfff60000, 0xfff60200, 0xfff5fe00, 0xfff60002, 0xfff5fffe, +- 0xfff60404, 0xfff5fbfc, 0xfff60a0a, 0xfff5f5f6, 0xfff60a00, 0xfff5f600, 0xfff6000a, 0xfff5fff6, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000404, 0xfffffbfc, 0x00000c0c, +- 0xfffff3f4, 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x000007f8, 0xfffff808, 0xfffff008, +- 0x00000ff8, 0xffffe800, 0x00001800, 0xfffff7e8, 0xfffff818, 0x000007e8, 0x00000818, 0xfffff014, +- 0x00000fec, 0xffffffe4, 0x0000001c, 0xffffe7f0, 0xffffe810, 0x000017f0, 0x00001810, 0xffffe000, +- 0x00002000, 0xffffefe4, 0xfffff01c, 0x00000fe4, 0x0000101c, 0xffffdff8, 0xffffe008, 0xfffff7e0, +- 0xfffff820, 0x000007e0, 0x00000820, 0x00001ff8, 0x00002008, 0x00001818, 0xffffe7e8, 0xffffe818, +- 0x000017e8, 0xffffdfec, 0x00002014, 0xffffffd8, 0x00000028, 0xffffefd8, 0x00001028, 0xffffd400, +- 0xffffd400, 0xffffffd4, 0x0000002c, 0x00002c00, 0x00002c00, 0xffffdfe0, 0x00002020, 0xffffd3f0, +- 0x00002c10, 0xffffd3e8, 0xffffe7d4, 0x0000182c, 0x00002c18, 0xffffefd0, 0x00001030, 0xffffdbdc, +- 0xffffdbdc, 0x00002424, 0x00002424, 0xffffcbec, 0x00002828, 0xffffd7d8, 0xffffcbe0, 0x00000000, +- 0x00000400, 0xfffffc00, 0x00000004, 0xfffffffc, 0x00000404, 0xfffffbfc, 0x00000c0c, 0xfffff3f4, +- 0x00000c00, 0xfffff400, 0x0000000c, 0xfffffff4, 0x04000000, 0x04000400, 0x03fffc00, 0x04000004, +- 0x03fffffc, 0x04000404, 0x03fffbfc, 0x04000c0c, 0x03fff3f4, 0x04000c00, 0x03fff400, 0x0400000c, +- 0x03fffff4, 0xfc000000, 0xfc000400, 0xfbfffc00, 0xfc000004, 0xfbfffffc, 0xfc000404, 0xfbfffbfc, +- 0xfc000c0c, 0xfbfff3f4, 0xfc000c00, 0xfbfff400, 0xfc00000c, 0xfbfffff4, 0x00040000, 0x00040400, +- 0x0003fc00, 0x00040004, 0x0003fffc, 0x00040404, 0x0003fbfc, 0x00040c0c, 0x0003f3f4, 0x00040c00, +- 0x0003f400, 0x0004000c, 0x0003fff4, 0xfffc0000, 0xfffc0400, 0xfffbfc00, 0xfffc0004, 0xfffbfffc, +- 0xfffc0404, 0xfffbfbfc, 0xfffc0c0c, 0xfffbf3f4, 0xfffc0c00, 0xfffbf400, 0xfffc000c, 0xfffbfff4, +- 0x04040000, 0x04040400, 0x0403fc00, 0x04040004, 0x0403fffc, 0x04040404, 0x0403fbfc, 0x04040c0c, +- 0x0403f3f4, 0x04040c00, 0x0403f400, 0x0404000c, 0x0403fff4, 0xfbfc0000, 0xfbfc0400, 0xfbfbfc00, +- 0xfbfc0004, 0xfbfbfffc, 0xfbfc0404, 0xfbfbfbfc, 0xfbfc0c0c, 0xfbfbf3f4, 0xfbfc0c00, 0xfbfbf400, +- 0xfbfc000c, 0xfbfbfff4, 0x0c0c0000, 0x0c0c0400, 0x0c0bfc00, 0x0c0c0004, 0x0c0bfffc, 0x0c0c0404, +- 0x0c0bfbfc, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c0c00, 0x0c0bf400, 0x0c0c000c, 0x0c0bfff4, 0xf3f40000, +- 0xf3f40400, 0xf3f3fc00, 0xf3f40004, 0xf3f3fffc, 0xf3f40404, 0xf3f3fbfc, 0xf3f40c0c, 0xf3f3f3f4, +- 0xf3f40c00, 0xf3f3f400, 0xf3f4000c, 0xf3f3fff4, 0x0c000000, 0x0c000400, 0x0bfffc00, 0x0c000004, +- 0x0bfffffc, 0x0c000404, 0x0bfffbfc, 0x0c000c0c, 0x0bfff3f4, 0x0c000c00, 0x0bfff400, 0x0c00000c, +- 0x0bfffff4, 0xf4000000, 0xf4000400, 0xf3fffc00, 0xf4000004, 0xf3fffffc, 0xf4000404, 0xf3fffbfc, +- 0xf4000c0c, 0xf3fff3f4, 0xf4000c00, 0xf3fff400, 0xf400000c, 0xf3fffff4, 0x000c0000, 0x000c0400, +- 0x000bfc00, 0x000c0004, 0x000bfffc, 0x000c0404, 0x000bfbfc, 0x000c0c0c, 0x000bf3f4, 0x000c0c00, +- 0x000bf400, 0x000c000c, 0x000bfff4, 0xfff40000, 0xfff40400, 0xfff3fc00, 0xfff40004, 0xfff3fffc, +- 0xfff40404, 0xfff3fbfc, 0xfff40c0c, 0xfff3f3f4, 0xfff40c00, 0xfff3f400, 0xfff4000c, 0xfff3fff4, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, +- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec, +- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606, +- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e, +- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4, +- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202, +- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020, +- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa, +- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2, +- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414, +- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe, +- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0, +- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c, +- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000, +- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec, +- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606, +- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e, +- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4, +- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202, +- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020, +- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa, +- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, +- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec, +- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606, +- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e, +- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4, +- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202, +- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020, +- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa, +- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2, +- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414, +- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe, +- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0, +- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c, +- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000, +- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec, +- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606, +- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e, +- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4, +- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202, +- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020, +- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa, +- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, +- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec, +- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606, +- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e, +- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4, +- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202, +- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020, +- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa, +- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2, +- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414, +- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe, +- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0, +- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c, +- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000, +- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec, +- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606, +- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e, +- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4, +- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202, +- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020, +- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa, +- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, +- 0xffffebec, 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000202, 0xfffffdfe, 0x00000606, 0xfffff9fa, 0x00000c0c, 0xfffff3f4, 0x00001414, 0xffffebec, +- 0x00002020, 0xffffdfe0, 0x00002e2e, 0xffffd1d2, 0x02020000, 0x02020202, 0x0201fdfe, 0x02020606, +- 0x0201f9fa, 0x02020c0c, 0x0201f3f4, 0x02021414, 0x0201ebec, 0x02022020, 0x0201dfe0, 0x02022e2e, +- 0x0201d1d2, 0xfdfe0000, 0xfdfe0202, 0xfdfdfdfe, 0xfdfe0606, 0xfdfdf9fa, 0xfdfe0c0c, 0xfdfdf3f4, +- 0xfdfe1414, 0xfdfdebec, 0xfdfe2020, 0xfdfddfe0, 0xfdfe2e2e, 0xfdfdd1d2, 0x06060000, 0x06060202, +- 0x0605fdfe, 0x06060606, 0x0605f9fa, 0x06060c0c, 0x0605f3f4, 0x06061414, 0x0605ebec, 0x06062020, +- 0x0605dfe0, 0x06062e2e, 0x0605d1d2, 0xf9fa0000, 0xf9fa0202, 0xf9f9fdfe, 0xf9fa0606, 0xf9f9f9fa, +- 0xf9fa0c0c, 0xf9f9f3f4, 0xf9fa1414, 0xf9f9ebec, 0xf9fa2020, 0xf9f9dfe0, 0xf9fa2e2e, 0xf9f9d1d2, +- 0x0c0c0000, 0x0c0c0202, 0x0c0bfdfe, 0x0c0c0606, 0x0c0bf9fa, 0x0c0c0c0c, 0x0c0bf3f4, 0x0c0c1414, +- 0x0c0bebec, 0x0c0c2020, 0x0c0bdfe0, 0x0c0c2e2e, 0x0c0bd1d2, 0xf3f40000, 0xf3f40202, 0xf3f3fdfe, +- 0xf3f40606, 0xf3f3f9fa, 0xf3f40c0c, 0xf3f3f3f4, 0xf3f41414, 0xf3f3ebec, 0xf3f42020, 0xf3f3dfe0, +- 0xf3f42e2e, 0xf3f3d1d2, 0x14140000, 0x14140202, 0x1413fdfe, 0x14140606, 0x1413f9fa, 0x14140c0c, +- 0x1413f3f4, 0x14141414, 0x1413ebec, 0x14142020, 0x1413dfe0, 0x14142e2e, 0x1413d1d2, 0xebec0000, +- 0xebec0202, 0xebebfdfe, 0xebec0606, 0xebebf9fa, 0xebec0c0c, 0xebebf3f4, 0xebec1414, 0xebebebec, +- 0xebec2020, 0xebebdfe0, 0xebec2e2e, 0xebebd1d2, 0x20200000, 0x20200202, 0x201ffdfe, 0x20200606, +- 0x201ff9fa, 0x20200c0c, 0x201ff3f4, 0x20201414, 0x201febec, 0x20202020, 0x201fdfe0, 0x20202e2e, +- 0x201fd1d2, 0xdfe00000, 0xdfe00202, 0xdfdffdfe, 0xdfe00606, 0xdfdff9fa, 0xdfe00c0c, 0xdfdff3f4, +- 0xdfe01414, 0xdfdfebec, 0xdfe02020, 0xdfdfdfe0, 0xdfe02e2e, 0xdfdfd1d2, 0x2e2e0000, 0x2e2e0202, +- 0x2e2dfdfe, 0x2e2e0606, 0x2e2df9fa, 0x2e2e0c0c, 0x2e2df3f4, 0x2e2e1414, 0x2e2debec, 0x2e2e2020, +- 0x2e2ddfe0, 0x2e2e2e2e, 0x2e2dd1d2, 0xd1d20000, 0xd1d20202, 0xd1d1fdfe, 0xd1d20606, 0xd1d1f9fa, +- 0xd1d20c0c, 0xd1d1f3f4, 0xd1d21414, 0xd1d1ebec, 0xd1d22020, 0xd1d1dfe0, 0xd1d22e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 +-}; ++#include "config.h" ++ ++/* ++ * Define compressed VQ tables. ++ */ + ++#define TAB_1_1 \ ++ PD( 0, 0), E2( 2, 2), E4( -1, 3), E2( 4, 4), E4( 1, 5),\ ++ E2( -4, 4), E4( -2, 6), E4( 4, 9), E2( 9, 9), E4( 1, 10),\ ++ E4( -5, 8), E4( 9, 15), E4( -3, 12), E4( 4, 16), E2( 16, 16),\ ++ E4( 0, 18), E2( -12, 12), E4( -9, 16), E4( 11, 27), E4( 19, 28),\ ++ E4( -6, 22), E4( 4, 29), E2( 30, 30), E4( -2, 33), E4( -18, 23),\ ++ E4( -15, 30), E4( 22, 46), E4( 13, 47), E4( 35, 49), E4( -11, 41),\ ++ E4( 4, 51), E2( 54, 54), E2( -34, 34), E4( -29, 42), E4( -6, 60),\ ++ E4( 27, 76), E4( 43, 77), E4( -24, 55), E4( 14, 79), E4( 63, 83),\ ++ E4( -20, 74), E4( 2, 88), E2( 93, 93), E4( -52, 61), E4( 52, 120),\ ++ E4( -45, 75), E4( 75, 125), E4( 33, 122), E4( -13, 103), E4( -40, 96),\ ++ E4( -34, 127), E2( -89, 89), E4( -78, 105), E2( 12, 12), E2( 23, 23),\ ++ E2( 42, 42), E2( 73, 73) + +-static const uint32_t correctionloworder[] = { +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x04040404, +- 0xfbfbfbfc, 0x05050101, 0xfafafeff, 0x01010505, 0xfefefafb, 0x0403fbfc, 0xfbfc0404, 0x0605fdfe, +- 0xf9fa0202, 0xfdfe0606, 0x0201f9fa, 0x09090404, 0xf6f6fbfc, 0x04040909, 0xfbfbf6f7, 0x09090909, +- 0xf6f6f6f7, 0x0a0a0101, 0xf5f5feff, 0x01010a0a, 0xfefef5f6, 0x0807fafb, 0xf7f80505, 0xfafb0808, +- 0x0504f7f8, 0x0f0f0909, 0xf0f0f6f7, 0x09090f0f, 0xf6f6f0f1, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, +- 0x0302f3f4, 0x10100404, 0xefeffbfc, 0x04041010, 0xfbfbeff0, 0x10101010, 0xefefeff0, 0x12120000, +- 0xedee0000, 0x00001212, 0xffffedee, 0x0c0bf3f4, 0xf3f40c0c, 0x100ff6f7, 0xeff00909, 0xf6f71010, +- 0x0908eff0, 0x1b1b0b0b, 0xe4e4f4f5, 0x0b0b1b1b, 0xf4f4e4e5, 0x1c1c1313, 0xe3e3eced, 0x13131c1c, +- 0xecece3e4, 0x1615f9fa, 0xe9ea0606, 0xf9fa1616, 0x0605e9ea, 0x1d1d0404, 0xe2e2fbfc, 0x04041d1d, +- 0xfbfbe2e3, 0x1e1e1e1e, 0xe1e1e1e2, 0x2120fdfe, 0xdedf0202, 0xfdfe2121, 0x0201dedf, 0x1716edee, +- 0xe8e91212, 0xedee1717, 0x1211e8e9, 0x1e1df0f1, 0xe1e20f0f, 0xf0f11e1e, 0x0f0ee1e2, 0x2e2e1616, +- 0xd1d1e9ea, 0x16162e2e, 0xe9e9d1d2, 0x2f2f0d0d, 0xd0d0f2f3, 0x0d0d2f2f, 0xf2f2d0d1, 0x31312323, +- 0xcecedcdd, 0x23233131, 0xdcdccecf, 0x2928f4f5, 0xd6d70b0b, 0xf4f52929, 0x0b0ad6d7, 0x33330404, +- 0xccccfbfc, 0x04043333, 0xfbfbcccd, 0x36363636, 0xc9c9c9ca, 0x2221ddde, 0xddde2222, 0x2a29e2e3, +- 0xd5d61d1d, 0xe2e32a2a, 0x1d1cd5d6, 0x3c3bf9fa, 0xc3c40606, 0xf9fa3c3c, 0x0605c3c4, 0x4c4c1b1b, +- 0xb3b3e4e5, 0x1b1b4c4c, 0xe4e4b3b4, 0x4d4d2b2b, 0xb2b2d4d5, 0x2b2b4d4d, 0xd4d4b2b3, 0x3736e7e8, +- 0xc8c91818, 0xe7e83737, 0x1817c8c9, 0x4f4f0e0e, 0xb0b0f1f2, 0x0e0e4f4f, 0xf1f1b0b1, 0x53533f3f, +- 0xacacc0c1, 0x3f3f5353, 0xc0c0acad, 0x4a49ebec, 0xb5b61414, 0xebec4a4a, 0x1413b5b6, 0x58580202, +- 0xa7a7fdfe, 0x02025858, 0xfdfda7a8, 0x5d5d5d5d, 0xa2a2a2a3, 0x3d3ccbcc, 0xc2c33434, 0xcbcc3d3d, +- 0x3433c2c3, 0x78783434, 0x8787cbcc, 0x34347878, 0xcbcb8788, 0x4b4ad2d3, 0xb4b52d2d, 0xd2d34b4b, +- 0x2d2cb4b5, 0x7d7d4b4b, 0x8282b4b5, 0x4b4b7d7d, 0xb4b48283, 0x7a7a2121, 0x8585dedf, 0x21217a7a, +- 0xdede8586, 0x6766f2f3, 0x98990d0d, 0xf2f36767, 0x0d0c9899, 0x605fd7d8, 0x9fa02828, 0xd7d86060, +- 0x28279fa0, 0x7f7eddde, 0x80812222, 0xddde7f7f, 0x22218081, 0x5958a6a7, 0xa6a75959, 0x6968b1b2, +- 0x96974e4e, 0xb1b26969, 0x4e4d9697, 0x0c0c0c0c, 0xf3f3f3f4, 0x17171717, 0xe8e8e8e9, 0x2a2a2a2a, +- 0xd5d5d5d6, 0x49494949, 0xb6b6b6b7, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0x0302feff, 0xfcfd0101, +- 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfcfd0101, 0xfeff0303, 0xfeff0303, +- 0xfeff0303, 0xfeff0303, 0xfeff0303, 0xfeff0303, 0xfeff0303, 0x0100fcfd, 0x0100fcfd, 0x0100fcfd, +- 0x0100fcfd, 0x0100fcfd, 0x0100fcfd, 0x0100fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, +- 0xf8f8f8f9, 0x08080202, 0xf7f7fdfe, 0x02020808, 0xfdfdf7f8, 0x0908fdfe, 0xf6f70202, 0xfdfe0909, +- 0x0201f6f7, 0x0605f9fa, 0xf9fa0606, 0x0d0d0606, 0xf2f2f9fa, 0x06060d0d, 0xf9f9f2f3, 0x0d0d0d0d, +- 0xf2f2f2f3, 0x0e0e0101, 0xf1f1feff, 0x01010e0e, 0xfefef1f2, 0x0c0bf7f8, 0xf3f40808, 0xf7f80c0c, +- 0x0807f3f4, 0x17170e0e, 0xe8e8f1f2, 0x0e0e1717, 0xf1f1e8e9, 0x1211fafb, 0xedee0505, 0xfafb1212, +- 0x0504edee, 0x18180606, 0xe7e7f9fa, 0x06061818, 0xf9f9e7e8, 0x18181818, 0xe7e7e7e8, 0x1b1afeff, +- 0xe4e50101, 0xfeff1b1b, 0x0100e4e5, 0x1110eeef, 0xeeef1111, 0x1716f2f3, 0xe8e90d0d, 0xf2f31717, +- 0x0d0ce8e9, 0x28281010, 0xd7d7eff0, 0x10102828, 0xefefd7d8, 0x29291c1c, 0xd6d6e3e4, 0x1c1c2929, +- 0xe3e3d6d7, 0x2120f6f7, 0xdedf0909, 0xf6f72121, 0x0908dedf, 0x2b2b0606, 0xd4d4f9fa, 0x06062b2b, +- 0xf9f9d4d5, 0x2e2e2e2e, 0xd1d1d1d2, 0x3231fbfc, 0xcdce0404, 0xfbfc3232, 0x0403cdce, 0x2221e4e5, +- 0xddde1b1b, 0xe4e52222, 0x1b1addde, 0x2d2ce9ea, 0xd2d31616, 0xe9ea2d2d, 0x1615d2d3, 0x45452222, +- 0xbabaddde, 0x22224545, 0xddddbabb, 0x46461313, 0xb9b9eced, 0x13134646, 0xececb9ba, 0x49493535, +- 0xb6b6cacb, 0x35354949, 0xcacab6b7, 0x3e3deeef, 0xc1c21111, 0xeeef3e3e, 0x1110c1c2, 0x4d4d0505, +- 0xb2b2fafb, 0x05054d4d, 0xfafab2b3, 0x52525252, 0xadadadae, 0x3332cccd, 0xcccd3333, 0x403fd4d5, +- 0xbfc02b2b, 0xd4d54040, 0x2b2abfc0, 0x5a59f5f6, 0xa5a60a0a, 0xf5f65a5a, 0x0a09a5a6, 0x72722929, +- 0x8d8dd6d7, 0x29297272, 0xd6d68d8e, 0x74744040, 0x8b8bbfc0, 0x40407474, 0xbfbf8b8c, 0x5251dadb, +- 0xadae2525, 0xdadb5252, 0x2524adae, 0x77771616, 0x8888e9ea, 0x16167777, 0xe9e98889, 0x7c7c5f5f, +- 0x8383a0a1, 0x5f5f7c7c, 0xa0a08384, 0x6f6ee1e2, 0x90911e1e, 0xe1e26f6f, 0x1e1d9091, 0x5c5bb1b2, +- 0xa3a44e4e, 0xb1b25c5c, 0x4e4da3a4, 0x7170bbbc, 0x8e8f4444, 0xbbbc7171, 0x44438e8f, 0x12121212, +- 0xedededee, 0x22222222, 0xddddddde, 0x3f3f3f3f, 0xc0c0c0c1, 0x6d6d6d6d, 0x92929293, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, +- 0x03030303, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, +- 0xfcfcfcfd, 0xfcfcfcfd, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff, 0x0403feff, +- 0x0403feff, 0x0403feff, 0x0403feff, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, +- 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfbfc0101, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404, +- 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0xfeff0404, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, +- 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x0100fbfc, 0x07070707, 0x07070707, +- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9, +- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, +- 0xf5f5fcfd, 0x03030a0a, 0xfcfcf5f6, 0x09090909, 0xf6f6f6f7, 0x0706f8f9, 0xf8f90707, 0x0c0bfcfd, +- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x11110808, 0xeeeef7f8, 0x08081111, 0xf7f7eeef, 0x11111111, +- 0xeeeeeeef, 0x13130101, 0xececfeff, 0x01011313, 0xfefeeced, 0x100ff4f5, 0xeff00b0b, 0xf4f51010, +- 0x0b0aeff0, 0x1716f9fa, 0xe8e90606, 0xf9fa1717, 0x0605e8e9, 0x1f1f1212, 0xe0e0edee, 0x12121f1f, +- 0xedede0e1, 0x20200808, 0xdfdff7f8, 0x08082020, 0xf7f7dfe0, 0x21212121, 0xdedededf, 0x2423feff, +- 0xdbdc0101, 0xfeff2424, 0x0100dbdc, 0x1716e8e9, 0xe8e91717, 0x1f1eeeef, 0xe0e11111, 0xeeef1f1f, +- 0x1110e0e1, 0x36361515, 0xc9c9eaeb, 0x15153636, 0xeaeac9ca, 0x37372525, 0xc8c8dadb, 0x25253737, +- 0xdadac8c9, 0x2c2bf3f4, 0xd3d40c0c, 0xf3f42c2c, 0x0c0bd3d4, 0x39390808, 0xc6c6f7f8, 0x08083939, +- 0xf7f7c6c7, 0x3d3d3d3d, 0xc2c2c2c3, 0x4241fafb, 0xbdbe0505, 0xfafb4242, 0x0504bdbe, 0x2d2cdbdc, +- 0xd2d32424, 0xdbdc2d2d, 0x2423d2d3, 0x3c3be2e3, 0xc3c41d1d, 0xe2e33c3c, 0x1d1cc3c4, 0x5c5c2d2d, +- 0xa3a3d2d3, 0x2d2d5c5c, 0xd2d2a3a4, 0x5d5d1919, 0xa2a2e6e7, 0x19195d5d, 0xe6e6a2a3, 0x61614747, +- 0x9e9eb8b9, 0x47476161, 0xb8b89e9f, 0x5352e9ea, 0xacad1616, 0xe9ea5353, 0x1615acad, 0x66660707, +- 0x9999f8f9, 0x07076666, 0xf8f8999a, 0x6d6d6d6d, 0x92929293, 0x4443bbbc, 0xbbbc4444, 0x5554c6c7, +- 0xaaab3939, 0xc6c75555, 0x3938aaab, 0x7877f2f3, 0x87880d0d, 0xf2f37878, 0x0d0c8788, 0x6e6dcecf, +- 0x91923131, 0xcecf6e6e, 0x31309192, 0x7b7a9798, 0x84856868, 0x97987b7b, 0x68678485, 0x18181818, +- 0xe7e7e7e8, 0x2e2e2e2e, 0xd1d1d1d2, 0x54545454, 0xabababac, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040404, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, +- 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, +- 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0x0504feff, 0xfafb0101, 0xfafb0101, 0xfafb0101, +- 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfafb0101, 0xfeff0505, +- 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, 0xfeff0505, +- 0xfeff0505, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0100fafb, +- 0x0100fafb, 0x0100fafb, 0x0100fafb, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, +- 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0x0a0a0303, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, +- 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0xf5f5fcfd, 0x03030a0a, +- 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, 0x03030a0a, +- 0x03030a0a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, +- 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x03030d0d, 0xfcfcf2f3, 0x0908f6f7, 0xf6f70909, 0x0f0efbfc, +- 0xf0f10404, 0xfbfc0f0f, 0x0403f0f1, 0x16160b0b, 0xe9e9f4f5, 0x0b0b1616, 0xf4f4e9ea, 0x15151515, +- 0xeaeaeaeb, 0x18180202, 0xe7e7fdfe, 0x02021818, 0xfdfde7e8, 0x1413f1f2, 0xebec0e0e, 0xf1f21414, +- 0x0e0debec, 0x26261717, 0xd9d9e8e9, 0x17172626, 0xe8e8d9da, 0x1d1cf7f8, 0xe2e30808, 0xf7f81d1d, +- 0x0807e2e3, 0x27270b0b, 0xd8d8f4f5, 0x0b0b2727, 0xf4f4d8d9, 0x29292929, 0xd6d6d6d7, 0x2d2cfeff, +- 0xd2d30101, 0xfeff2d2d, 0x0100d2d3, 0x1d1ce2e3, 0xe2e31d1d, 0x2726e9ea, 0xd8d91616, 0xe9ea2727, +- 0x1615d8d9, 0x43431b1b, 0xbcbce4e5, 0x1b1b4343, 0xe4e4bcbd, 0x45452f2f, 0xbabad0d1, 0x2f2f4545, +- 0xd0d0babb, 0x3837f0f1, 0xc7c80f0f, 0xf0f13838, 0x0f0ec7c8, 0x47470b0b, 0xb8b8f4f5, 0x0b0b4747, +- 0xf4f4b8b9, 0x4c4c4c4c, 0xb3b3b3b4, 0x5352f9fa, 0xacad0606, 0xf9fa5353, 0x0605acad, 0x3938d2d3, +- 0xc6c72d2d, 0xd2d33939, 0x2d2cc6c7, 0x4b4adbdc, 0xb4b52424, 0xdbdc4b4b, 0x2423b4b5, 0x73733838, +- 0x8c8cc7c8, 0x38387373, 0xc7c78c8d, 0x75751f1f, 0x8a8ae0e1, 0x1f1f7575, 0xe0e08a8b, 0x7a7a5858, +- 0x8585a7a8, 0x58587a7a, 0xa7a78586, 0x6867e3e4, 0x97981c1c, 0xe3e46868, 0x1c1b9798, 0x5554aaab, +- 0xaaab5555, 0x6a69b7b8, 0x95964848, 0xb7b86a6a, 0x48479596, 0x1e1e1e1e, 0xe1e1e1e2, 0x3a3a3a3a, +- 0xc5c5c5c6, 0x69696969, 0x96969697, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x05050505, 0x05050505, +- 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, +- 0x05050505, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, +- 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, +- 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0x0706fdfe, 0xf8f90202, +- 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, 0xf8f90202, +- 0xf8f90202, 0xf8f90202, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, +- 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0xfdfe0707, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, +- 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, 0x0201f8f9, +- 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, +- 0x0b0b0b0b, 0x0b0b0b0b, 0x0b0b0b0b, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, +- 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0xf4f4f4f5, 0x0d0d0303, 0x0d0d0303, +- 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, 0x0d0d0303, +- 0x0d0d0303, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, +- 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0xf2f2fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, +- 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0xfbfbf0f1, 0x0b0af4f5, 0xf4f50b0b, 0x1211fafb, +- 0xedee0505, 0xfafb1212, 0x0504edee, 0x1a1a0d0d, 0xe5e5f2f3, 0x0d0d1a1a, 0xf2f2e5e6, 0x1a1a1a1a, +- 0xe5e5e5e6, 0x1d1d0202, 0xe2e2fdfe, 0x02021d1d, 0xfdfde2e3, 0x1817eff0, 0xe7e81010, 0xeff01818, +- 0x100fe7e8, 0x2e2e1c1c, 0xd1d1e3e4, 0x1c1c2e2e, 0xe3e3d1d2, 0x2322f6f7, 0xdcdd0909, 0xf6f72323, +- 0x0908dcdd, 0x2f2f0d0d, 0xd0d0f2f3, 0x0d0d2f2f, 0xf2f2d0d1, 0x31313131, 0xcecececf, 0x3635feff, +- 0xc9ca0101, 0xfeff3636, 0x0100c9ca, 0x2322dcdd, 0xdcdd2323, 0x2f2ee5e6, 0xd0d11a1a, 0xe5e62f2f, +- 0x1a19d0d1, 0x51512020, 0xaeaedfe0, 0x20205151, 0xdfdfaeaf, 0x53533838, 0xacacc7c8, 0x38385353, +- 0xc7c7acad, 0x4342edee, 0xbcbd1212, 0xedee4343, 0x1211bcbd, 0x56560d0d, 0xa9a9f2f3, 0x0d0d5656, +- 0xf2f2a9aa, 0x5b5b5b5b, 0xa4a4a4a5, 0x6362f8f9, 0x9c9d0707, 0xf8f96363, 0x07069c9d, 0x4443c9ca, +- 0xbbbc3636, 0xc9ca4444, 0x3635bbbc, 0x5a59d3d4, 0xa5a62c2c, 0xd3d45a5a, 0x2c2ba5a6, 0x7c7bdedf, +- 0x83842121, 0xdedf7c7c, 0x21208384, 0x67669899, 0x98996767, 0x7f7ea9aa, 0x80815656, 0xa9aa7f7f, +- 0x56558081, 0x25252525, 0xdadadadb, 0x45454545, 0xbabababb, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, +- 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0x0807fdfe, 0xf7f80202, 0xf7f80202, 0xf7f80202, +- 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, 0xf7f80202, +- 0xf7f80202, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, +- 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0xfdfe0808, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, +- 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, 0x0201f7f8, +- 0x0201f7f8, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, +- 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0x0d0d0d0d, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, +- 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, 0xf2f2f2f3, +- 0xf2f2f2f3, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, +- 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0x0f0f0404, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, +- 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, 0xf0f0fbfc, +- 0xf0f0fbfc, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, +- 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x04040f0f, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, +- 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0xfafaedee, 0x0d0cf2f3, 0xf2f30d0d, 0x1514f9fa, +- 0xeaeb0606, 0xf9fa1515, 0x0605eaeb, 0x1e1e0f0f, 0xe1e1f0f1, 0x0f0f1e1e, 0xf0f0e1e2, 0x1e1e1e1e, +- 0xe1e1e1e2, 0x22220202, 0xddddfdfe, 0x02022222, 0xfdfdddde, 0x1c1beced, 0xe3e41313, 0xeced1c1c, +- 0x1312e3e4, 0x36362020, 0xc9c9dfe0, 0x20203636, 0xdfdfc9ca, 0x2928f4f5, 0xd6d70b0b, 0xf4f52929, +- 0x0b0ad6d7, 0x37370f0f, 0xc8c8f0f1, 0x0f0f3737, 0xf0f0c8c9, 0x39393939, 0xc6c6c6c7, 0x3f3efeff, +- 0xc0c10101, 0xfeff3f3f, 0x0100c0c1, 0x2827d7d8, 0xd7d82828, 0x3736e1e2, 0xc8c91e1e, 0xe1e23737, +- 0x1e1dc8c9, 0x5e5e2525, 0xa1a1dadb, 0x25255e5e, 0xdadaa1a2, 0x60604141, 0x9f9fbebf, 0x41416060, +- 0xbebe9fa0, 0x4e4deaeb, 0xb1b21515, 0xeaeb4e4e, 0x1514b1b2, 0x64640f0f, 0x9b9bf0f1, 0x0f0f6464, +- 0xf0f09b9c, 0x6a6a6a6a, 0x95959596, 0x7473f7f8, 0x8b8c0808, 0xf7f87474, 0x08078b8c, 0x4f4ec0c1, +- 0xb0b13f3f, 0xc0c14f4f, 0x3f3eb0b1, 0x6968cccd, 0x96973333, 0xcccd6969, 0x33329697, 0x78778788, +- 0x87887878, 0x2b2b2b2b, 0xd4d4d4d5, 0x50505050, 0xafafafb0, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, +- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, +- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, +- 0xf8f8f8f9, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, +- 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0x0a09fcfd, 0xf5f60303, 0xf5f60303, 0xf5f60303, +- 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, 0xf5f60303, +- 0xf5f60303, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, +- 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0xfcfd0a0a, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, +- 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, 0x0302f5f6, +- 0x0302f5f6, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, +- 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0xefefeff0, 0xefefeff0, 0xefefeff0, +- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, +- 0xefefeff0, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, +- 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0x12120505, 0xededfafb, 0xededfafb, 0xededfafb, +- 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, 0xededfafb, +- 0xededfafb, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, +- 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x05051212, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, +- 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0xfafaebec, 0x0f0ef0f1, 0xf0f10f0f, 0x1817f8f9, +- 0xe7e80707, 0xf8f91818, 0x0706e7e8, 0x23231111, 0xdcdceeef, 0x11112323, 0xeeeedcdd, 0x22222222, +- 0xddddddde, 0x26260303, 0xd9d9fcfd, 0x03032626, 0xfcfcd9da, 0x201fe9ea, 0xdfe01616, 0xe9ea2020, +- 0x1615dfe0, 0x3d3d2525, 0xc2c2dadb, 0x25253d3d, 0xdadac2c3, 0x2f2ef2f3, 0xd0d10d0d, 0xf2f32f2f, +- 0x0d0cd0d1, 0x3f3f1111, 0xc0c0eeef, 0x11113f3f, 0xeeeec0c1, 0x41414141, 0xbebebebf, 0x4847feff, +- 0xb7b80101, 0xfeff4848, 0x0100b7b8, 0x2e2dd1d2, 0xd1d22e2e, 0x3f3edcdd, 0xc0c12323, 0xdcdd3f3f, +- 0x2322c0c1, 0x6b6b2b2b, 0x9494d4d5, 0x2b2b6b6b, 0xd4d49495, 0x6e6e4b4b, 0x9191b4b5, 0x4b4b6e6e, +- 0xb4b49192, 0x5958e7e8, 0xa6a71818, 0xe7e85959, 0x1817a6a7, 0x72721111, 0x8d8deeef, 0x11117272, +- 0xeeee8d8e, 0x79797979, 0x86868687, 0x5b5ab7b8, 0xa4a54848, 0xb7b85b5b, 0x4847a4a5, 0x7877c5c6, +- 0x87883a3a, 0xc5c67878, 0x3a398788, 0x31313131, 0xcecececf, 0x5c5c5c5c, 0xa3a3a3a4, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, +- 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0xf7f7f7f8, +- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, +- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, +- 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0x0b0afcfd, 0xf4f50303, +- 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xf4f50303, +- 0xf4f50303, 0xf4f50303, 0xf4f50303, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, +- 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0xfcfd0b0b, 0x0302f4f5, +- 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, +- 0x0302f4f5, 0x0302f4f5, 0x0302f4f5, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, +- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0xedededee, +- 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, +- 0xedededee, 0xedededee, 0xedededee, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, +- 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0x14140505, 0xebebfafb, +- 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, 0xebebfafb, +- 0xebebfafb, 0xebebfafb, 0xebebfafb, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, +- 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x05051414, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, +- 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x1110eeef, 0xeeef1111, 0x1b1af8f9, +- 0xe4e50707, 0xf8f91b1b, 0x0706e4e5, 0x27271313, 0xd8d8eced, 0x13132727, 0xececd8d9, 0x27272727, +- 0xd8d8d8d9, 0x2b2b0303, 0xd4d4fcfd, 0x03032b2b, 0xfcfcd4d5, 0x2423e7e8, 0xdbdc1818, 0xe7e82424, +- 0x1817dbdc, 0x45452a2a, 0xbabad5d6, 0x2a2a4545, 0xd5d5babb, 0x3534f1f2, 0xcacb0e0e, 0xf1f23535, +- 0x0e0dcacb, 0x47471313, 0xb8b8eced, 0x13134747, 0xececb8b9, 0x49494949, 0xb6b6b6b7, 0x504ffdfe, +- 0xafb00202, 0xfdfe5050, 0x0201afb0, 0x3433cbcc, 0xcbcc3434, 0x4645d8d9, 0xb9ba2727, 0xd8d94646, +- 0x2726b9ba, 0x79793030, 0x8686cfd0, 0x30307979, 0xcfcf8687, 0x7c7c5454, 0x8383abac, 0x54547c7c, +- 0xabab8384, 0x6463e4e5, 0x9b9c1b1b, 0xe4e56464, 0x1b1a9b9c, 0x6665aeaf, 0x999a5151, 0xaeaf6666, +- 0x5150999a, 0x37373737, 0xc8c8c8c9, 0x68686868, 0x97979798, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, +- 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0xf6f6f6f7, +- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, +- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, +- 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, 0x0c0bfcfd, +- 0x0c0bfcfd, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, +- 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xf3f40303, 0xfcfd0c0c, 0xfcfd0c0c, +- 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, +- 0xfcfd0c0c, 0xfcfd0c0c, 0xfcfd0c0c, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, +- 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, 0x0302f3f4, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, +- 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0x17170606, 0xe8e8f9fa, +- 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, +- 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0xe8e8f9fa, 0x06061717, 0x06061717, 0x06061717, 0x06061717, +- 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, 0x06061717, +- 0x06061717, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, +- 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0xf9f9e8e9, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, +- 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x0403fbfc, 0xfbfc0404, 0x0605fdfe, +- 0xf9fa0202, 0xfdfe0606, 0x0201f9fa, 0x08080404, 0xf7f7fbfc, 0x04040808, 0xfbfbf7f8, 0x08080808, +- 0xf7f7f7f8, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x0807fbfc, 0xf7f80404, 0xfbfc0808, +- 0x0403f7f8, 0x0e0e0808, 0xf1f1f7f8, 0x08080e0e, 0xf7f7f1f2, 0x0c0bfdfe, 0xf3f40202, 0xfdfe0c0c, +- 0x0201f3f4, 0x10100404, 0xefeffbfc, 0x04041010, 0xfbfbeff0, 0x10101010, 0xefefeff0, 0x12120000, +- 0xedee0000, 0x00001212, 0xffffedee, 0x0c0bf3f4, 0xf3f40c0c, 0x100ff7f8, 0xeff00808, 0xf7f81010, +- 0x0807eff0, 0x1a1a0a0a, 0xe5e5f5f6, 0x0a0a1a1a, 0xf5f5e5e6, 0x1c1c1212, 0xe3e3edee, 0x12121c1c, +- 0xedede3e4, 0x1615f9fa, 0xe9ea0606, 0xf9fa1616, 0x0605e9ea, 0x1c1c0404, 0xe3e3fbfc, 0x04041c1c, +- 0xfbfbe3e4, 0x1e1e1e1e, 0xe1e1e1e2, 0x201ffdfe, 0xdfe00202, 0xfdfe2020, 0x0201dfe0, 0x1615edee, +- 0xe9ea1212, 0xedee1616, 0x1211e9ea, 0x1e1df1f2, 0xe1e20e0e, 0xf1f21e1e, 0x0e0de1e2, 0x2e2e1616, +- 0xd1d1e9ea, 0x16162e2e, 0xe9e9d1d2, 0x2e2e0c0c, 0xd1d1f3f4, 0x0c0c2e2e, 0xf3f3d1d2, 0x30302222, +- 0xcfcfddde, 0x22223030, 0xddddcfd0, 0x2827f5f6, 0xd7d80a0a, 0xf5f62828, 0x0a09d7d8, 0x32320404, +- 0xcdcdfbfc, 0x04043232, 0xfbfbcdce, 0x36363636, 0xc9c9c9ca, 0x2221ddde, 0xddde2222, 0x2a29e3e4, +- 0xd5d61c1c, 0xe3e42a2a, 0x1c1bd5d6, 0x3c3bf9fa, 0xc3c40606, 0xf9fa3c3c, 0x0605c3c4, 0x4c4c1a1a, +- 0xb3b3e5e6, 0x1a1a4c4c, 0xe5e5b3b4, 0x4c4c2a2a, 0xb3b3d5d6, 0x2a2a4c4c, 0xd5d5b3b4, 0x3635e7e8, +- 0xc9ca1818, 0xe7e83636, 0x1817c9ca, 0x4e4e0e0e, 0xb1b1f1f2, 0x0e0e4e4e, 0xf1f1b1b2, 0x52523e3e, +- 0xadadc1c2, 0x3e3e5252, 0xc1c1adae, 0x4a49ebec, 0xb5b61414, 0xebec4a4a, 0x1413b5b6, 0x58580202, +- 0xa7a7fdfe, 0x02025858, 0xfdfda7a8, 0x5c5c5c5c, 0xa3a3a3a4, 0x3c3bcbcc, 0xc3c43434, 0xcbcc3c3c, +- 0x3433c3c4, 0x76763434, 0x8989cbcc, 0x34347676, 0xcbcb898a, 0x4a49d3d4, 0xb5b62c2c, 0xd3d44a4a, +- 0x2c2bb5b6, 0x76764a4a, 0x8989b5b6, 0x4a4a7676, 0xb5b5898a, 0x76762020, 0x8989dfe0, 0x20207676, +- 0xdfdf898a, 0x6665f3f4, 0x999a0c0c, 0xf3f46666, 0x0c0b999a, 0x605fd7d8, 0x9fa02828, 0xd7d86060, +- 0x28279fa0, 0x7675ddde, 0x898a2222, 0xddde7676, 0x2221898a, 0x5857a7a8, 0xa7a85858, 0x6867b1b2, +- 0x97984e4e, 0xb1b26868, 0x4e4d9798, 0x0c0c0c0c, 0xf3f3f3f4, 0x16161616, 0xe9e9e9ea, 0x2a2a2a2a, +- 0xd5d5d5d6, 0x48484848, 0xb7b7b7b8, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0xfdfe0000, +- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202, +- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, +- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, +- 0xf9f9f9fa, 0x09090303, 0xf6f6fcfd, 0x03030909, 0xfcfcf6f7, 0x0908fcfd, 0xf6f70303, 0xfcfd0909, +- 0x0302f6f7, 0x0605f9fa, 0xf9fa0606, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0xf9f9f3f4, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x0f0f0000, 0xf0f10000, 0x00000f0f, 0xfffff0f1, 0x0c0bf6f7, 0xf3f40909, 0xf6f70c0c, +- 0x0908f3f4, 0x18180f0f, 0xe7e7f0f1, 0x0f0f1818, 0xf0f0e7e8, 0x1211f9fa, 0xedee0606, 0xf9fa1212, +- 0x0605edee, 0x18180606, 0xe7e7f9fa, 0x06061818, 0xf9f9e7e8, 0x18181818, 0xe7e7e7e8, 0x1b1b0000, +- 0xe4e50000, 0x00001b1b, 0xffffe4e5, 0x1211edee, 0xedee1212, 0x1817f3f4, 0xe7e80c0c, 0xf3f41818, +- 0x0c0be7e8, 0x27270f0f, 0xd8d8f0f1, 0x0f0f2727, 0xf0f0d8d9, 0x2a2a1b1b, 0xd5d5e4e5, 0x1b1b2a2a, +- 0xe4e4d5d6, 0x2120f6f7, 0xdedf0909, 0xf6f72121, 0x0908dedf, 0x2a2a0606, 0xd5d5f9fa, 0x06062a2a, +- 0xf9f9d5d6, 0x2d2d2d2d, 0xd2d2d2d3, 0x3332fcfd, 0xcccd0303, 0xfcfd3333, 0x0302cccd, 0x2120e4e5, +- 0xdedf1b1b, 0xe4e52121, 0x1b1adedf, 0x2d2ceaeb, 0xd2d31515, 0xeaeb2d2d, 0x1514d2d3, 0x45452121, +- 0xbabadedf, 0x21214545, 0xdedebabb, 0x45451212, 0xbabaedee, 0x12124545, 0xededbabb, 0x48483636, +- 0xb7b7c9ca, 0x36364848, 0xc9c9b7b8, 0x3f3eedee, 0xc0c11212, 0xedee3f3f, 0x1211c0c1, 0x4e4e0606, +- 0xb1b1f9fa, 0x06064e4e, 0xf9f9b1b2, 0x51515151, 0xaeaeaeaf, 0x3332cccd, 0xcccd3333, 0x3f3ed5d6, +- 0xc0c12a2a, 0xd5d63f3f, 0x2a29c0c1, 0x5a59f6f7, 0xa5a60909, 0xf6f75a5a, 0x0908a5a6, 0x72722a2a, +- 0x8d8dd5d6, 0x2a2a7272, 0xd5d58d8e, 0x75753f3f, 0x8a8ac0c1, 0x3f3f7575, 0xc0c08a8b, 0x5150dbdc, +- 0xaeaf2424, 0xdbdc5151, 0x2423aeaf, 0x78781515, 0x8787eaeb, 0x15157878, 0xeaea8788, 0x7b7b6060, +- 0x84849fa0, 0x60607b7b, 0x9f9f8485, 0x6f6ee1e2, 0x90911e1e, 0xe1e26f6f, 0x1e1d9091, 0x5d5cb1b2, +- 0xa2a34e4e, 0xb1b25d5d, 0x4e4da2a3, 0x7271babb, 0x8d8e4545, 0xbabb7272, 0x45448d8e, 0x12121212, +- 0xedededee, 0x21212121, 0xdedededf, 0x3f3f3f3f, 0xc0c0c0c1, 0x6c6c6c6c, 0x93939394, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, 0x03030303, +- 0x03030303, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, 0xfcfcfcfd, +- 0xfcfcfcfd, 0xfcfcfcfd, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, +- 0x03030000, 0x03030000, 0x03030000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, +- 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0x00000303, 0x00000303, 0x00000303, 0x00000303, +- 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, +- 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, +- 0xf7f7fbfc, 0x04040808, 0xfbfbf7f8, 0x08080808, 0xf7f7f7f8, 0x0807f7f8, 0xf7f80808, 0x0c0bfbfc, +- 0xf3f40404, 0xfbfc0c0c, 0x0403f3f4, 0x10100808, 0xefeff7f8, 0x08081010, 0xf7f7eff0, 0x10101010, +- 0xefefeff0, 0x14140000, 0xebec0000, 0x00001414, 0xffffebec, 0x100ff3f4, 0xeff00c0c, 0xf3f41010, +- 0x0c0beff0, 0x1817fbfc, 0xe7e80404, 0xfbfc1818, 0x0403e7e8, 0x20201010, 0xdfdfeff0, 0x10102020, +- 0xefefdfe0, 0x20200808, 0xdfdff7f8, 0x08082020, 0xf7f7dfe0, 0x20202020, 0xdfdfdfe0, 0x24240000, +- 0xdbdc0000, 0x00002424, 0xffffdbdc, 0x1817e7e8, 0xe7e81818, 0x201feff0, 0xdfe01010, 0xeff02020, +- 0x100fdfe0, 0x34341414, 0xcbcbebec, 0x14143434, 0xebebcbcc, 0x38382424, 0xc7c7dbdc, 0x24243838, +- 0xdbdbc7c8, 0x2c2bf3f4, 0xd3d40c0c, 0xf3f42c2c, 0x0c0bd3d4, 0x38380808, 0xc7c7f7f8, 0x08083838, +- 0xf7f7c7c8, 0x3c3c3c3c, 0xc3c3c3c4, 0x403ffbfc, 0xbfc00404, 0xfbfc4040, 0x0403bfc0, 0x2c2bdbdc, +- 0xd3d42424, 0xdbdc2c2c, 0x2423d3d4, 0x3c3be3e4, 0xc3c41c1c, 0xe3e43c3c, 0x1c1bc3c4, 0x5c5c2c2c, +- 0xa3a3d3d4, 0x2c2c5c5c, 0xd3d3a3a4, 0x5c5c1818, 0xa3a3e7e8, 0x18185c5c, 0xe7e7a3a4, 0x60604848, +- 0x9f9fb7b8, 0x48486060, 0xb7b79fa0, 0x5453ebec, 0xabac1414, 0xebec5454, 0x1413abac, 0x64640808, +- 0x9b9bf7f8, 0x08086464, 0xf7f79b9c, 0x6c6c6c6c, 0x93939394, 0x4443bbbc, 0xbbbc4444, 0x5453c7c8, +- 0xabac3838, 0xc7c85454, 0x3837abac, 0x7877f3f4, 0x87880c0c, 0xf3f47878, 0x0c0b8788, 0x6c6bcfd0, +- 0x93943030, 0xcfd06c6c, 0x302f9394, 0x7c7b9798, 0x83846868, 0x97987c7c, 0x68678384, 0x18181818, +- 0xe7e7e7e8, 0x2c2c2c2c, 0xd3d3d3d4, 0x54545454, 0xabababac, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040404, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, +- 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, +- 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, +- 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0x00000404, +- 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, +- 0x00000404, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, +- 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0x08080404, +- 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0x08080404, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, +- 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0xf7f7fbfc, 0x04040808, +- 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, 0x04040808, +- 0x04040808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, +- 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x05050f0f, 0xfafaf0f1, 0x0a09f5f6, 0xf5f60a0a, 0x0f0efafb, +- 0xf0f10505, 0xfafb0f0f, 0x0504f0f1, 0x14140a0a, 0xebebf5f6, 0x0a0a1414, 0xf5f5ebec, 0x14141414, +- 0xebebebec, 0x19190000, 0xe6e70000, 0x00001919, 0xffffe6e7, 0x1413f0f1, 0xebec0f0f, 0xf0f11414, +- 0x0f0eebec, 0x28281919, 0xd7d7e6e7, 0x19192828, 0xe6e6d7d8, 0x1e1df5f6, 0xe1e20a0a, 0xf5f61e1e, +- 0x0a09e1e2, 0x28280a0a, 0xd7d7f5f6, 0x0a0a2828, 0xf5f5d7d8, 0x28282828, 0xd7d7d7d8, 0x2d2d0000, +- 0xd2d30000, 0x00002d2d, 0xffffd2d3, 0x1e1de1e2, 0xe1e21e1e, 0x2827ebec, 0xd7d81414, 0xebec2828, +- 0x1413d7d8, 0x41411919, 0xbebee6e7, 0x19194141, 0xe6e6bebf, 0x46462d2d, 0xb9b9d2d3, 0x2d2d4646, +- 0xd2d2b9ba, 0x3736f0f1, 0xc8c90f0f, 0xf0f13737, 0x0f0ec8c9, 0x46460a0a, 0xb9b9f5f6, 0x0a0a4646, +- 0xf5f5b9ba, 0x4b4b4b4b, 0xb4b4b4b5, 0x5554fafb, 0xaaab0505, 0xfafb5555, 0x0504aaab, 0x3736d2d3, +- 0xc8c92d2d, 0xd2d33737, 0x2d2cc8c9, 0x4b4adcdd, 0xb4b52323, 0xdcdd4b4b, 0x2322b4b5, 0x73733737, +- 0x8c8cc8c9, 0x37377373, 0xc8c88c8d, 0x73731e1e, 0x8c8ce1e2, 0x1e1e7373, 0xe1e18c8d, 0x78785a5a, +- 0x8787a5a6, 0x5a5a7878, 0xa5a58788, 0x6968e1e2, 0x96971e1e, 0xe1e26969, 0x1e1d9697, 0x5554aaab, +- 0xaaab5555, 0x6968b9ba, 0x96974646, 0xb9ba6969, 0x46459697, 0x1e1e1e1e, 0xe1e1e1e2, 0x3c3c3c3c, +- 0xc3c3c3c4, 0x69696969, 0x96969697, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x05050505, 0x05050505, +- 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, 0x05050505, +- 0x05050505, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, +- 0xfafafafb, 0xfafafafb, 0xfafafafb, 0xfafafafb, 0x05050000, 0x05050000, 0x05050000, 0x05050000, +- 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0x05050000, 0xfafb0000, +- 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, 0xfafb0000, +- 0xfafb0000, 0xfafb0000, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505, +- 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0x00000505, 0xfffffafb, 0xfffffafb, 0xfffffafb, +- 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, 0xfffffafb, +- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, +- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, +- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0x0f0f0505, 0x0f0f0505, +- 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, 0x0f0f0505, +- 0x0f0f0505, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, +- 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0xf0f0fafb, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0xf9f9f3f4, 0x0c0bf3f4, 0xf3f40c0c, 0x1211f9fa, +- 0xedee0606, 0xf9fa1212, 0x0605edee, 0x18180c0c, 0xe7e7f3f4, 0x0c0c1818, 0xf3f3e7e8, 0x18181818, +- 0xe7e7e7e8, 0x1e1e0000, 0xe1e20000, 0x00001e1e, 0xffffe1e2, 0x1817edee, 0xe7e81212, 0xedee1818, +- 0x1211e7e8, 0x30301e1e, 0xcfcfe1e2, 0x1e1e3030, 0xe1e1cfd0, 0x2423f9fa, 0xdbdc0606, 0xf9fa2424, +- 0x0605dbdc, 0x30300c0c, 0xcfcff3f4, 0x0c0c3030, 0xf3f3cfd0, 0x30303030, 0xcfcfcfd0, 0x36360000, +- 0xc9ca0000, 0x00003636, 0xffffc9ca, 0x2423dbdc, 0xdbdc2424, 0x302fe7e8, 0xcfd01818, 0xe7e83030, +- 0x1817cfd0, 0x4e4e1e1e, 0xb1b1e1e2, 0x1e1e4e4e, 0xe1e1b1b2, 0x54543636, 0xababc9ca, 0x36365454, +- 0xc9c9abac, 0x4241edee, 0xbdbe1212, 0xedee4242, 0x1211bdbe, 0x54540c0c, 0xababf3f4, 0x0c0c5454, +- 0xf3f3abac, 0x5a5a5a5a, 0xa5a5a5a6, 0x605ff9fa, 0x9fa00606, 0xf9fa6060, 0x06059fa0, 0x4241c9ca, +- 0xbdbe3636, 0xc9ca4242, 0x3635bdbe, 0x5a59d5d6, 0xa5a62a2a, 0xd5d65a5a, 0x2a29a5a6, 0x7e7de1e2, +- 0x81821e1e, 0xe1e27e7e, 0x1e1d8182, 0x6665999a, 0x999a6666, 0x7e7dabac, 0x81825454, 0xabac7e7e, +- 0x54538182, 0x24242424, 0xdbdbdbdc, 0x42424242, 0xbdbdbdbe, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, +- 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, +- 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, +- 0xf9fa0000, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, +- 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, +- 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, +- 0xfffff9fa, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, +- 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0x0c0c0606, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, +- 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, 0xf3f3f9fa, +- 0xf3f3f9fa, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, +- 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x06060c0c, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, +- 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0xf8f8eaeb, 0x0e0df1f2, 0xf1f20e0e, 0x1514f8f9, +- 0xeaeb0707, 0xf8f91515, 0x0706eaeb, 0x1c1c0e0e, 0xe3e3f1f2, 0x0e0e1c1c, 0xf1f1e3e4, 0x1c1c1c1c, +- 0xe3e3e3e4, 0x23230000, 0xdcdd0000, 0x00002323, 0xffffdcdd, 0x1c1beaeb, 0xe3e41515, 0xeaeb1c1c, +- 0x1514e3e4, 0x38382323, 0xc7c7dcdd, 0x23233838, 0xdcdcc7c8, 0x2a29f1f2, 0xd5d60e0e, 0xf1f22a2a, +- 0x0e0dd5d6, 0x38380e0e, 0xc7c7f1f2, 0x0e0e3838, 0xf1f1c7c8, 0x38383838, 0xc7c7c7c8, 0x3f3f0000, +- 0xc0c10000, 0x00003f3f, 0xffffc0c1, 0x2a29d5d6, 0xd5d62a2a, 0x3837e3e4, 0xc7c81c1c, 0xe3e43838, +- 0x1c1bc7c8, 0x5b5b2323, 0xa4a4dcdd, 0x23235b5b, 0xdcdca4a5, 0x62623f3f, 0x9d9dc0c1, 0x3f3f6262, +- 0xc0c09d9e, 0x4d4ceaeb, 0xb2b31515, 0xeaeb4d4d, 0x1514b2b3, 0x62620e0e, 0x9d9df1f2, 0x0e0e6262, +- 0xf1f19d9e, 0x69696969, 0x96969697, 0x7776f8f9, 0x88890707, 0xf8f97777, 0x07068889, 0x4d4cc0c1, +- 0xb2b33f3f, 0xc0c14d4d, 0x3f3eb2b3, 0x6968cecf, 0x96973131, 0xcecf6969, 0x31309697, 0x77768889, +- 0x88897777, 0x2a2a2a2a, 0xd5d5d5d6, 0x4d4d4d4d, 0xb2b2b2b3, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, +- 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0x07070707, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, +- 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, 0xf8f8f8f9, +- 0xf8f8f8f9, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, +- 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0xf8f90000, 0xf8f90000, 0xf8f90000, +- 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, +- 0xf8f90000, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, +- 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0x00000707, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, +- 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, 0xfffff8f9, +- 0xfffff8f9, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, +- 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0x0e0e0e0e, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, +- 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, 0xf1f1f1f2, +- 0xf1f1f1f2, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, +- 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0x15150707, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, +- 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, 0xeaeaf8f9, +- 0xeaeaf8f9, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, +- 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x07071515, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, +- 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0xf7f7eff0, 0x100feff0, 0xeff01010, 0x1817f7f8, +- 0xe7e80808, 0xf7f81818, 0x0807e7e8, 0x20201010, 0xdfdfeff0, 0x10102020, 0xefefdfe0, 0x20202020, +- 0xdfdfdfe0, 0x28280000, 0xd7d80000, 0x00002828, 0xffffd7d8, 0x201fe7e8, 0xdfe01818, 0xe7e82020, +- 0x1817dfe0, 0x40402828, 0xbfbfd7d8, 0x28284040, 0xd7d7bfc0, 0x302feff0, 0xcfd01010, 0xeff03030, +- 0x100fcfd0, 0x40401010, 0xbfbfeff0, 0x10104040, 0xefefbfc0, 0x40404040, 0xbfbfbfc0, 0x48480000, +- 0xb7b80000, 0x00004848, 0xffffb7b8, 0x302fcfd0, 0xcfd03030, 0x403fdfe0, 0xbfc02020, 0xdfe04040, +- 0x201fbfc0, 0x68682828, 0x9797d7d8, 0x28286868, 0xd7d79798, 0x70704848, 0x8f8fb7b8, 0x48487070, +- 0xb7b78f90, 0x5857e7e8, 0xa7a81818, 0xe7e85858, 0x1817a7a8, 0x70701010, 0x8f8feff0, 0x10107070, +- 0xefef8f90, 0x78787878, 0x87878788, 0x5857b7b8, 0xa7a84848, 0xb7b85858, 0x4847a7a8, 0x7877c7c8, +- 0x87883838, 0xc7c87878, 0x38378788, 0x30303030, 0xcfcfcfd0, 0x58585858, 0xa7a7a7a8, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, +- 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0x08080808, 0xf7f7f7f8, +- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, +- 0xf7f7f7f8, 0xf7f7f7f8, 0xf7f7f7f8, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, +- 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0x08080000, 0xf7f80000, +- 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, 0xf7f80000, +- 0xf7f80000, 0xf7f80000, 0xf7f80000, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, +- 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0x00000808, 0xfffff7f8, +- 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, +- 0xfffff7f8, 0xfffff7f8, 0xfffff7f8, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, +- 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0x10101010, 0xefefeff0, +- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, 0xefefeff0, +- 0xefefeff0, 0xefefeff0, 0xefefeff0, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, +- 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0x10100808, 0xefeff7f8, +- 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, +- 0xefeff7f8, 0xefeff7f8, 0xefeff7f8, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, +- 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x08081010, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, +- 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x1211edee, 0xedee1212, 0x1b1af6f7, +- 0xe4e50909, 0xf6f71b1b, 0x0908e4e5, 0x24241212, 0xdbdbedee, 0x12122424, 0xededdbdc, 0x24242424, +- 0xdbdbdbdc, 0x2d2d0000, 0xd2d30000, 0x00002d2d, 0xffffd2d3, 0x2423e4e5, 0xdbdc1b1b, 0xe4e52424, +- 0x1b1adbdc, 0x48482d2d, 0xb7b7d2d3, 0x2d2d4848, 0xd2d2b7b8, 0x3635edee, 0xc9ca1212, 0xedee3636, +- 0x1211c9ca, 0x48481212, 0xb7b7edee, 0x12124848, 0xededb7b8, 0x48484848, 0xb7b7b7b8, 0x51510000, +- 0xaeaf0000, 0x00005151, 0xffffaeaf, 0x3635c9ca, 0xc9ca3636, 0x4847dbdc, 0xb7b82424, 0xdbdc4848, +- 0x2423b7b8, 0x75752d2d, 0x8a8ad2d3, 0x2d2d7575, 0xd2d28a8b, 0x7e7e5151, 0x8181aeaf, 0x51517e7e, +- 0xaeae8182, 0x6362e4e5, 0x9c9d1b1b, 0xe4e56363, 0x1b1a9c9d, 0x6362aeaf, 0x9c9d5151, 0xaeaf6363, +- 0x51509c9d, 0x36363636, 0xc9c9c9ca, 0x6c6c6c6c, 0x93939394, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, +- 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0x09090909, 0xf6f6f6f7, +- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, +- 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0xf6f6f6f7, 0x09090000, 0x09090000, 0x09090000, 0x09090000, +- 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, 0x09090000, +- 0x09090000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, +- 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0xf6f70000, 0x00000909, 0x00000909, +- 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, 0x00000909, +- 0x00000909, 0x00000909, 0x00000909, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, +- 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, 0xfffff6f7, +- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, +- 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0x12121212, 0xedededee, 0xedededee, 0xedededee, +- 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, 0xedededee, +- 0xedededee, 0xedededee, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, +- 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0x1b1b0909, 0xe4e4f6f7, +- 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, +- 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0xe4e4f6f7, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, +- 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, 0x09091b1b, +- 0x09091b1b, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, +- 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0xf6f6e4e5, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, +- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0504fafb, 0xfafb0505, 0xfafb0505, +- 0x0504fafb, 0x0b0b0606, 0xf4f4f9fa, 0x06060b0b, 0xf9f9f4f5, 0x08080000, 0xf7f80000, 0x00000808, +- 0xfffff7f8, 0x0b0b0b0b, 0xf4f4f4f5, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x11110c0c, +- 0xeeeef3f4, 0x0c0c1111, 0xf3f3eeef, 0x11111111, 0xeeeeeeef, 0x12120606, 0xededf9fa, 0x06061212, +- 0xf9f9edee, 0x0b0af7f8, 0xf4f50808, 0xf7f80b0b, 0x0807f4f5, 0x0f0f0000, 0xf0f10000, 0x00000f0f, +- 0xfffff0f1, 0x14140000, 0xebec0000, 0x00001414, 0xffffebec, 0x19191212, 0xe6e6edee, 0x12121919, +- 0xedede6e7, 0x19190b0b, 0xe6e6f4f5, 0x0b0b1919, 0xf4f4e6e7, 0x19191919, 0xe6e6e6e7, 0x0e0df1f2, +- 0xf1f20e0e, 0xf1f20e0e, 0x0e0df1f2, 0x1a1a0000, 0xe5e60000, 0x00001a1a, 0xffffe5e6, 0x1211f4f5, +- 0xedee0b0b, 0xf4f51212, 0x0b0aedee, 0x1615f8f9, 0xe9ea0707, 0xf8f91616, 0x0706e9ea, 0x22221a1a, +- 0xdddde5e6, 0x1a1a2222, 0xe5e5ddde, 0x22221212, 0xddddedee, 0x12122222, 0xededddde, 0x22222222, +- 0xddddddde, 0x23230b0b, 0xdcdcf4f5, 0x0b0b2323, 0xf4f4dcdd, 0x1d1d0000, 0xe2e30000, 0x00001d1d, +- 0xffffe2e3, 0x1615eced, 0xe9ea1313, 0xeced1616, 0x1312e9ea, 0x1a19f0f1, 0xe5e60f0f, 0xf0f11a1a, +- 0x0f0ee5e6, 0x25250000, 0xdadb0000, 0x00002525, 0xffffdadb, 0x2c2c1b1b, 0xd3d3e4e5, 0x1b1b2c2c, +- 0xe4e4d3d4, 0x2c2c2424, 0xd3d3dbdc, 0x24242c2c, 0xdbdbd3d4, 0x2c2c1212, 0xd3d3edee, 0x12122c2c, +- 0xededd3d4, 0x2120f5f6, 0xdedf0a0a, 0xf5f62121, 0x0a09dedf, 0x2d2d2d2d, 0xd2d2d2d3, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, +- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, +- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, +- 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, +- 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, +- 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, +- 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, +- 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, +- 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x03030000, 0xfcfd0000, +- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, 0xf8f90000, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x07070000, +- 0xf8f90000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0403fbfc, 0xfbfc0404, 0xf9fa0a0a, +- 0x0605f5f6, 0xf3f40000, 0x0c0c0000, 0xf3f3f9fa, 0xf3f40606, 0x0c0bf9fa, 0x0c0c0606, 0xfffff1f2, +- 0x00000e0e, 0x0c0c0c0c, 0xf3f3f3f4, 0xedee0000, 0x12120000, 0xf3f40e0e, 0x0c0bf1f2, 0xf9f9edee, +- 0xf9fa1212, 0x0605edee, 0x06061212, 0xededf5f6, 0xedee0a0a, 0x1211f5f6, 0x12120a0a, 0xffffe9ea, +- 0x00001616, 0xe7e80000, 0x18180000, 0xf3f3e9ea, 0xf3f41616, 0x0c0be9ea, 0x0c0c1616, 0xe7e7f7f8, +- 0xe7e80808, 0x1817f7f8, 0x18180808, 0xf9f9e5e6, 0xf9fa1a1a, 0x0605e5e6, 0x06061a1a, 0xffffe3e4, +- 0x00001c1c, 0x14141414, 0xebebebec, 0xe5e5f1f2, 0x1a1a0e0e, 0xf3f3e1e2, 0x0c0c1e1e, 0xdfdff5f6, +- 0x20200a0a, 0xdfdfedee, 0x20201212, 0xe5e5e5e6, 0x1a1a1a1a, 0xebebddde, 0x14142222, 0xf3f3d9da, +- 0x0c0c2626, 0xdfdfdfe0, 0x20202020, 0x20202020, 0xd7d7e9ea, 0xddddddde, 0x22222222, 0x00000000, +- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, +- 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, +- 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, +- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, +- 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, +- 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, +- 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, +- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, +- 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, +- 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, +- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, +- 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, +- 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x0605f9fa, 0xf9fa0606, 0xf7f80e0e, +- 0x0807f1f2, 0xffffedee, 0x00001212, 0xeff00a0a, 0x100ff5f6, 0xe7e80000, 0x18180000, 0xf7f7e7e8, +- 0xf7f81818, 0x0807e7e8, 0x08081818, 0x12121212, 0xedededee, 0xeff01414, 0x100febec, 0xe5e5f1f2, +- 0xe5e60e0e, 0x1a19f1f2, 0x1a1a0e0e, 0xffffe1e2, 0x00001e1e, 0xddde0000, 0x22220000, 0xf7f7ddde, +- 0xf7f82222, 0x0807ddde, 0x08082222, 0xedede1e2, 0xedee1e1e, 0x1211e1e2, 0x12121e1e, 0xddddf5f6, +- 0xddde0a0a, 0x2221f5f6, 0x22220a0a, 0xddddebec, 0x22221414, 0xffffd7d8, 0x00002828, 0x1e1e1e1e, +- 0xe1e1e1e2, 0xededd7d8, 0x12122828, 0xd3d40000, 0x2c2c0000, 0xd3d3eff0, 0x2c2c1010, 0xdbdbdbdc, +- 0xdbdbdbdc, 0x24242424, 0xd3d3e5e6, 0x2c2c1a1a, 0xe5e5d1d2, 0x1a1a2e2e, 0xededcbcc, 0x12123434, +- 0xc9c9ebec, 0xd3d3d3d4, 0x2c2c2c2c, 0xc9c9dfe0, 0xd1d1d1d2, 0xd1d1d1d2, 0x2e2e2e2e, 0x00000000, +- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, +- 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, +- 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, +- 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, +- 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, +- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, +- 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, +- 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, +- 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, +- 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, +- 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, +- 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, +- 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, +- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, +- 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, +- 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, +- 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, +- 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, +- 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, +- 0xf5f60000, 0x00000a0a, 0xfffff5f6, 0x00000000, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, +- 0x04040404, 0xfbfbfbfc, 0x0a0a0a0a, 0xf5f5f5f6, 0x0a0a0000, 0xf5f60000, 0x00000a0a, 0xfffff5f6, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x0807f7f8, 0xf7f80808, 0xeff00808, +- 0x100ff7f8, 0xe7e80000, 0x18180000, 0xf7f7e7e8, 0xf7f81818, 0x0807e7e8, 0x08081818, 0xeff01414, +- 0x100febec, 0xffffe3e4, 0x00001c1c, 0xe7e7eff0, 0xe7e81010, 0x1817eff0, 0x18181010, 0xdfe00000, +- 0x20200000, 0xefefe3e4, 0xeff01c1c, 0x100fe3e4, 0x10101c1c, 0xdfdff7f8, 0xdfe00808, 0xf7f7dfe0, +- 0xf7f82020, 0x0807dfe0, 0x08082020, 0x201ff7f8, 0x20200808, 0x18181818, 0xe7e7e7e8, 0xe7e81818, +- 0x1817e7e8, 0xdfdfebec, 0x20201414, 0xffffd7d8, 0x00002828, 0xefefd7d8, 0x10102828, 0xd3d40000, +- 0xd3d40000, 0xffffd3d4, 0x00002c2c, 0x2c2c0000, 0x2c2c0000, 0xdfdfdfe0, 0x20202020, 0xd3d3eff0, +- 0x2c2c1010, 0xd3d3e7e8, 0xe7e7d3d4, 0x18182c2c, 0x2c2c1818, 0xefefcfd0, 0x10103030, 0xdbdbdbdc, +- 0xdbdbdbdc, 0x24242424, 0x24242424, 0xcbcbebec, 0x28282828, 0xd7d7d7d8, 0xcbcbdfe0, 0x00000000, +- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, +- 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, +- 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, +- 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, +- 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, +- 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, +- 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, +- 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, +- 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, +- 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, +- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, +- 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, +- 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, +- 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, +- 0xf3f40000, 0x00000c0c, 0xfffff3f4, 0x00000000, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, +- 0x04040404, 0xfbfbfbfc, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0000, 0xf3f40000, 0x00000c0c, 0xfffff3f4, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, +- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, +- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, +- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, +- 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, +- 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, +- 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, +- 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, +- 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, +- 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, +- 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, +- 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x06060606, 0xf9f9f9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x14141414, 0xebebebec, 0x20202020, 0xdfdfdfe0, 0x2e2e2e2e, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 +-}; ++#define TAB_1_2 \ ++ PD( 0, 0), E2( 3, 3), E4( -1, 4), E2( 7, 7), E4( 2, 8),\ ++ E4( -2, 9), E2( -6, 6), E4( 6, 13), E2( 13, 13), E4( 1, 14),\ ++ E4( -8, 12), E4( 14, 23), E4( -5, 18), E4( 6, 24), E2( 24, 24),\ ++ E4( -1, 27), E2( -17, 17), E4( -13, 23), E4( 16, 40), E4( 28, 41),\ ++ E4( -9, 33), E4( 6, 43), E2( 46, 46), E4( -4, 50), E4( -27, 34),\ ++ E4( -22, 45), E4( 34, 69), E4( 19, 70), E4( 53, 73), E4( -17, 62),\ ++ E4( 5, 77), E2( 82, 82), E2( -51, 51), E4( -43, 64), E4( -10, 90),\ ++ E4( 41, 114), E4( 64, 116), E4( -37, 82), E4( 22, 119), E4( 95, 124),\ ++ E4( -30, 111), E4( -78, 92), E4( -68, 113), E2( 18, 18), E2( 34, 34),\ ++ E2( 63, 63), E2( 109, 109) ++ ++#define TAB_1_3 \ ++ PD( 0, 0), E2( 4, 4), E4( -1, 5), E4( 3, 10), E2( 9, 9),\ ++ E2( -7, 7), E4( -3, 12), E4( 8, 17), E2( 17, 17), E4( 1, 19),\ ++ E4( -11, 16), E4( -6, 23), E4( 18, 31), E4( 8, 32), E2( 33, 33),\ ++ E4( -1, 36), E2( -23, 23), E4( -17, 31), E4( 21, 54), E4( 37, 55),\ ++ E4( -12, 44), E4( 8, 57), E2( 61, 61), E4( -5, 66), E4( -36, 45),\ ++ E4( -29, 60), E4( 45, 92), E4( 25, 93), E4( 71, 97), E4( -22, 83),\ ++ E4( 7, 102), E2( 109, 109), E2( -68, 68), E4( -57, 85), E4( -13, 120),\ ++ E4( -49, 110), E4(-104, 123), E2( 24, 24), E2( 46, 46), E2( 84, 84) ++ ++#define TAB_1_4 \ ++ PD( 0, 0), E2( 5, 5), E4( -2, 7), E2( 11, 11), E4( 3, 13),\ ++ E2( -9, 9), E4( -4, 15), E4( 11, 22), E2( 21, 21), E4( 2, 24),\ ++ E4( -14, 20), E4( 23, 38), E4( -8, 29), E4( 11, 39), E2( 41, 41),\ ++ E4( -1, 45), E2( -29, 29), E4( -22, 39), E4( 27, 67), E4( 47, 69),\ ++ E4( -15, 56), E4( 11, 71), E2( 76, 76), E4( -6, 83), E4( -45, 57),\ ++ E4( -36, 75), E4( 56, 115), E4( 31, 117), E4( 88, 122), E4( -28, 104),\ ++ E2( -85, 85), E4( -72, 106), E2( 30, 30), E2( 58, 58), E2( 105, 105) ++ ++#define TAB_1_5 \ ++ PD( 0, 0), E2( 6, 6), E4( -2, 8), E2( 13, 13), E4( 4, 15),\ ++ E2( -11, 11), E4( -5, 18), E4( 13, 26), E2( 26, 26), E4( 2, 29),\ ++ E4( -16, 24), E4( 28, 46), E4( -9, 35), E4( 13, 47), E2( 49, 49),\ ++ E4( -1, 54), E2( -35, 35), E4( -26, 47), E4( 32, 81), E4( 56, 83),\ ++ E4( -18, 67), E4( 13, 86), E2( 91, 91), E4( -7, 99), E4( -54, 68),\ ++ E4( -44, 90), E4( -33, 124), E2(-103, 103), E4( -86, 127), E2( 37, 37),\ ++ E2( 69, 69) ++ ++#define TAB_1_6 \ ++ PD( 0, 0), E2( 7, 7), E4( -3, 10), E2( 16, 16), E4( 5, 18),\ ++ E2( -13, 13), E4( -6, 21), E4( 15, 30), E2( 30, 30), E4( 2, 34),\ ++ E4( -19, 28), E4( 32, 54), E4( -11, 41), E4( 15, 55), E2( 57, 57),\ ++ E4( -1, 63), E2( -40, 40), E4( -30, 55), E4( 37, 94), E4( 65, 96),\ ++ E4( -21, 78), E4( 15, 100), E2( 106, 106), E4( -8, 116), E4( -63, 79),\ ++ E4( -51, 105), E2(-120, 120), E2( 43, 43), E2( 80, 80) ++ ++#define TAB_1_7 \ ++ PD( 0, 0), E2( 8, 8), E4( -3, 11), E2( 18, 18), E4( 5, 20),\ ++ E2( -15, 15), E4( -7, 24), E4( 17, 35), E2( 34, 34), E4( 3, 38),\ ++ E4( -22, 32), E4( 37, 61), E4( -13, 47), E4( 17, 63), E2( 65, 65),\ ++ E4( -1, 72), E2( -46, 46), E4( -35, 63), E4( 43, 107), E4( 75, 110),\ ++ E4( -24, 89), E4( 17, 114), E2( 121, 121), E4( -72, 91), E4( -58, 120),\ ++ E2( 49, 49), E2( 92, 92) ++ ++#define TAB_1_8 \ ++ PD( 0, 0), E2( 9, 9), E4( -3, 12), E2( 20, 20), E4( 6, 23),\ ++ E2( -17, 17), E4( -7, 27), E4( 19, 39), E2( 39, 39), E4( 3, 43),\ ++ E4( -24, 36), E4( 42, 69), E4( -14, 53), E4( 19, 71), E2( 73, 73),\ ++ E4( -2, 80), E2( -52, 52), E4( -39, 70), E4( 48, 121), E4( 84, 124),\ ++ E4( -27, 100), E4( -81, 102), E2( 55, 55), E2( 104, 104) ++ ++#define TAB_2_1 \ ++ PD( 0, 0), E2( 2, 2), E4( 0, 2), E2( 4, 4), E4( 0, 4),\ ++ E2( -4, 4), E4( -2, 6), E4( 4, 8), E2( 8, 8), E4( 0, 10),\ ++ E4( -4, 8), E4( 8, 14), E4( -2, 12), E4( 4, 16), E2( 16, 16),\ ++ E4( 0, 18), E2( -12, 12), E4( -8, 16), E4( 10, 26), E4( 18, 28),\ ++ E4( -6, 22), E4( 4, 28), E2( 30, 30), E4( -2, 32), E4( -18, 22),\ ++ E4( -14, 30), E4( 22, 46), E4( 12, 46), E4( 34, 48), E4( -10, 40),\ ++ E4( 4, 50), E2( 54, 54), E2( -34, 34), E4( -28, 42), E4( -6, 60),\ ++ E4( 26, 76), E4( 42, 76), E4( -24, 54), E4( 14, 78), E4( 62, 82),\ ++ E4( -20, 74), E4( 2, 88), E2( 92, 92), E4( -52, 60), E4( 52, 118),\ ++ E4( -44, 74), E4( 74, 118), E4( 32, 118), E4( -12, 102), E4( -40, 96),\ ++ E4( -34, 118), E2( -88, 88), E4( -78, 104), E2( 12, 12), E2( 22, 22),\ ++ E2( 42, 42), E2( 72, 72) ++ ++#define TAB_2_2 \ ++ PD( 0, 0), E2( 3, 3), E4( 0, 3), E2( 6, 6), E4( 3, 9),\ ++ E4( -3, 9), E2( -6, 6), E4( 6, 12), E2( 12, 12), E4( 0, 15),\ ++ E4( -9, 12), E4( 15, 24), E4( -6, 18), E4( 6, 24), E2( 24, 24),\ ++ E4( 0, 27), E2( -18, 18), E4( -12, 24), E4( 15, 39), E4( 27, 42),\ ++ E4( -9, 33), E4( 6, 42), E2( 45, 45), E4( -3, 51), E4( -27, 33),\ ++ E4( -21, 45), E4( 33, 69), E4( 18, 69), E4( 54, 72), E4( -18, 63),\ ++ E4( 6, 78), E2( 81, 81), E2( -51, 51), E4( -42, 63), E4( -9, 90),\ ++ E4( 42, 114), E4( 63, 117), E4( -36, 81), E4( 21, 120), E4( 96, 123),\ ++ E4( -30, 111), E4( -78, 93), E4( -69, 114), E2( 18, 18), E2( 33, 33),\ ++ E2( 63, 63), E2( 108, 108) ++ ++#define TAB_2_3 \ ++ PD( 0, 0), E2( 4, 4), E4( 0, 4), E4( 4, 8), E2( 8, 8),\ ++ E2( -8, 8), E4( -4, 12), E4( 8, 16), E2( 16, 16), E4( 0, 20),\ ++ E4( -12, 16), E4( -4, 24), E4( 16, 32), E4( 8, 32), E2( 32, 32),\ ++ E4( 0, 36), E2( -24, 24), E4( -16, 32), E4( 20, 52), E4( 36, 56),\ ++ E4( -12, 44), E4( 8, 56), E2( 60, 60), E4( -4, 64), E4( -36, 44),\ ++ E4( -28, 60), E4( 44, 92), E4( 24, 92), E4( 72, 96), E4( -20, 84),\ ++ E4( 8, 100), E2( 108, 108), E2( -68, 68), E4( -56, 84), E4( -12, 120),\ ++ E4( -48, 108), E4(-104, 124), E2( 24, 24), E2( 44, 44), E2( 84, 84) ++ ++#define TAB_2_4 \ ++ PD( 0, 0), E2( 5, 5), E4( 0, 5), E2( 10, 10), E4( 5, 15),\ ++ E2( -10, 10), E4( -5, 15), E4( 10, 20), E2( 20, 20), E4( 0, 25),\ ++ E4( -15, 20), E4( 25, 40), E4( -10, 30), E4( 10, 40), E2( 40, 40),\ ++ E4( 0, 45), E2( -30, 30), E4( -20, 40), E4( 25, 65), E4( 45, 70),\ ++ E4( -15, 55), E4( 10, 70), E2( 75, 75), E4( -5, 85), E4( -45, 55),\ ++ E4( -35, 75), E4( 55, 115), E4( 30, 115), E4( 90, 120), E4( -30, 105),\ ++ E2( -85, 85), E4( -70, 105), E2( 30, 30), E2( 60, 60), E2( 105, 105) ++ ++#define TAB_2_5 \ ++ PD( 0, 0), E2( 6, 6), E4( 0, 6), E2( 12, 12), E4( 6, 12),\ ++ E2( -12, 12), E4( -6, 18), E4( 12, 24), E2( 24, 24), E4( 0, 30),\ ++ E4( -18, 24), E4( 30, 48), E4( -6, 36), E4( 12, 48), E2( 48, 48),\ ++ E4( 0, 54), E2( -36, 36), E4( -24, 48), E4( 30, 78), E4( 54, 84),\ ++ E4( -18, 66), E4( 12, 84), E2( 90, 90), E4( -6, 96), E4( -54, 66),\ ++ E4( -42, 90), E4( -30, 126), E2(-102, 102), E4( -84, 126), E2( 36, 36),\ ++ E2( 66, 66) ++ ++#define TAB_2_6 \ ++ PD( 0, 0), E2( 7, 7), E4( 0, 7), E2( 14, 14), E4( 7, 21),\ ++ E2( -14, 14), E4( -7, 21), E4( 14, 28), E2( 28, 28), E4( 0, 35),\ ++ E4( -21, 28), E4( 35, 56), E4( -14, 42), E4( 14, 56), E2( 56, 56),\ ++ E4( 0, 63), E2( -42, 42), E4( -28, 56), E4( 35, 91), E4( 63, 98),\ ++ E4( -21, 77), E4( 14, 98), E2( 105, 105), E4( -7, 119), E4( -63, 77),\ ++ E4( -49, 105), E2(-119, 119), E2( 42, 42), E2( 77, 77) ++ ++#define TAB_2_7 \ ++ PD( 0, 0), E2( 8, 8), E4( 0, 8), E2( 16, 16), E4( 8, 16),\ ++ E2( -16, 16), E4( -8, 24), E4( 16, 32), E2( 32, 32), E4( 0, 40),\ ++ E4( -24, 32), E4( 40, 64), E4( -16, 48), E4( 16, 64), E2( 64, 64),\ ++ E4( 0, 72), E2( -48, 48), E4( -32, 64), E4( 40, 104), E4( 72, 112),\ ++ E4( -24, 88), E4( 16, 112), E2( 120, 120), E4( -72, 88), E4( -56, 120),\ ++ E2( 48, 48), E2( 88, 88) ++ ++#define TAB_2_8 \ ++ PD( 0, 0), E2( 9, 9), E4( 0, 9), E2( 18, 18), E4( 9, 27),\ ++ E2( -18, 18), E4( -9, 27), E4( 18, 36), E2( 36, 36), E4( 0, 45),\ ++ E4( -27, 36), E4( 45, 72), E4( -18, 54), E4( 18, 72), E2( 72, 72),\ ++ E4( 0, 81), E2( -54, 54), E4( -36, 72), E4( 45, 117), E4( 81, 126),\ ++ E4( -27, 99), E4( -81, 99), E2( 54, 54), E2( 108, 108) ++ ++#define TAB_3_1 \ ++ PD( 0, 0), E2( 2, 2), E4( 0, 3), E2( 6, 6), E4( 0, 7),\ ++ E2( -5, 5), E2( 5, -5), E4( 6, 11), E4( 0, 8), E2( 11, 11),\ ++ E4( 0, 12), E4( 12, 17), E2( 17, 17), E4( 6, 18), E4( -8, 11),\ ++ E4( 0, 15), E4( 0, 20), E4( 18, 25), E4( 11, 25), E2( 25, 25),\ ++ E2( -14, 14), E2( 14, -14), E4( 0, 26), E4( -11, 18), E4( -7, 22),\ ++ E4( 26, 34), E4( 18, 34), E2( 34, 34), E4( 11, 35), E4( 0, 29),\ ++ E4( -19, 22), E4( -15, 26), E4( 0, 37), E4( 27, 44), E4( 36, 44),\ ++ E4( 18, 44), E4( -10, 33), E2( 45, 45) ++ ++#define TAB_3_2 \ ++ PD( 0, 0), E4( 0, 2), E2( 2, 2), E2( 6, 6), E4( 0, 6),\ ++ E2( -4, 4), E2( 10, -6), E2( 0, -12), PD( -6, -12), E2( 6, -12),\ ++ PD( 6, 12), E2( -14, 0), E2( 12, 12), E2( 0, -18), E2( 14, -12),\ ++ PD( -18, -6), E2( 18, -6), PD( 18, 6), PD( -10, -18), E2( 10, -18),\ ++ PD( 10, 18), E2( -22, 0), E2( 0, -24), PD( -22, -12), E2( 22, -12),\ ++ PD( 22, 12), PD( -8, -24), E2( 8, -24), PD( 8, 24), PD( -26, -6),\ ++ E2( 26, -6), PD( 26, 6), E2( -28, 0), E2( 20, 20), E2( -14, -26),\ ++ E2( -30, -12), E2( -10, -32), E2( -18, -32), E2( -26, -26), E2( -34, -20),\ ++ E2( -38, -12), E2( -32, -32), PD( 32, 32), PD( -22, -40), E2( -34, -34) ++ ++#define TAB_3_3 \ ++ PD( 0, 0), E4( 0, 2), E2( 4, 4), E2( 10, 10), E4( 0, 10),\ ++ E2( -6, 6), E2( 14, -8), E2( -18, 0), E2( 10, -16), E2( 0, -24),\ ++ PD( -24, -8), E2( 24, -8), PD( 24, 8), E2( 18, 18), E2( 20, -16),\ ++ PD( -14, -26), E2( 14, -26), PD( 14, 26), E2( -30, 0), E2( 0, -34),\ ++ PD( -34, -8), E2( 34, -8), PD( 34, 8), PD( -30, -18), E2( 30, -18),\ ++ PD( 30, 18), PD( -10, -34), E2( 10, -34), PD( 10, 34), E2( -20, -34),\ ++ E2( -40, 0), E2( 30, 30), E2( -40, -18), E2( 0, -44), E2( -16, -44),\ ++ PD( -36, -36), E2( -36, -36), E2( -26, -44), E2( -46, -26), E2( -52, -18),\ ++ PD( -20, -54), E2( -44, -44), PD( -32, -54), PD( -46, -46), E2( -46, -46) ++ ++#define TAB_3_4 \ ++ PD( 0, 0), E4( 0, 4), E2( 4, 4), E2( 12, 12), E4( 0, 12),\ ++ E2( -8, 8), E2( 8, -16), E2( 0, -24), PD( -24, -8), E2( 24, -8),\ ++ PD( 24, 8), E2( 20, -16), E2( -28, 0), PD( -16, -24), E2( 16, -24),\ ++ PD( 16, 24), E2( 0, -32), PD( -28, -16), E2( 28, -16), PD( 28, 16),\ ++ PD( -8, -32), PD( 8, -32), PD( -32, -8), E2( 32, -8), PD( 32, 8),\ ++ PD( -8, 32), PD( 8, 32), E2( 24, 24), E2( 24, -24), E2( -20, -32),\ ++ E2( -40, 0), E2( -40, -16), PD( 0, -44), PD( 0, -44), E2( -44, 0),\ ++ PD( 0, 44), PD( 0, 44), E2( -32, -32), E2( -16, -44), PD( -24, -44),\ ++ E2( -44, -24), PD( 24, 44), E2( -48, -16), PD( -36, -36), E2( -36, -36),\ ++ PD( 36, 36), PD( -20, -52), E2( 40, 40), PD( -32, -52) ++ ++#define TAB_3_5 \ ++ PD( 0, 0), E2( 2, 2), E2( 6, 6), E2( 12, 12), E2( 20, 20),\ ++ E2( 32, 32), E2( 46, 46) ++ ++ ++/** ++ * Pack two delta values (a,b) into one 16bit word ++ * according with endianess of the host machine. ++ */ ++#if HAVE_BIGENDIAN ++#define PD(a,b) (((a) << 8) + (b)) ++#else ++#define PD(a,b) (((b) << 8) + (a)) ++#endif ++ ++/** ++ * Expand a pair of delta values (a,b) ++ * into two/four delta entries. ++ */ ++#define E2(a, b) PD(a, b), PD(-a, -b) ++#define E4(a, b) PD(a, b), PD(-a, -b), PD(b, a), PD(-b, -a) ++ ++/* ++ * VQ tables for 4x4 block modes. ++ * Let the compiler decompress and build the tables for us. ++ */ ++static const int16_t delta_tab_1_1[195] = { TAB_1_1 }; ++static const int16_t delta_tab_1_2[159] = { TAB_1_2 }; ++static const int16_t delta_tab_1_3[133] = { TAB_1_3 }; ++static const int16_t delta_tab_1_4[115] = { TAB_1_4 }; ++static const int16_t delta_tab_1_5[101] = { TAB_1_5 }; ++static const int16_t delta_tab_1_6[93] = { TAB_1_6 }; ++static const int16_t delta_tab_1_7[87] = { TAB_1_7 }; ++static const int16_t delta_tab_1_8[77] = { TAB_1_8 }; ++ ++static const int16_t delta_tab_2_1[195] = { TAB_2_1 }; ++static const int16_t delta_tab_2_2[159] = { TAB_2_2 }; ++static const int16_t delta_tab_2_3[133] = { TAB_2_3 }; ++static const int16_t delta_tab_2_4[115] = { TAB_2_4 }; ++static const int16_t delta_tab_2_5[101] = { TAB_2_5 }; ++static const int16_t delta_tab_2_6[93] = { TAB_2_6 }; ++static const int16_t delta_tab_2_7[87] = { TAB_2_7 }; ++static const int16_t delta_tab_2_8[77] = { TAB_2_8 }; ++ ++static const int16_t delta_tab_3_1[128] = { TAB_3_1 }; ++static const int16_t delta_tab_3_2[79] = { TAB_3_2 }; ++static const int16_t delta_tab_3_3[79] = { TAB_3_3 }; ++static const int16_t delta_tab_3_4[79] = { TAB_3_4 }; ++static const int16_t delta_tab_3_5[79] = { TAB_3_5 }; ++ ++#undef PD ++ ++/** ++ * Pack four delta values (a,a,b,b) into one 32bit word ++ * according with endianess of the host machine. ++ */ ++#if HAVE_BIGENDIAN ++#define PD(a,b) (((a) << 24) + ((a) << 16) + ((b) << 8) + (b)) ++#else ++#define PD(a,b) (((b) << 24) + ((b) << 16) + ((a) << 8) + (a)) ++#endif ++ ++/* ++ * VQ tables for 8x8 block modes. ++ * Those are based on the same delta tables by using ++ * each value twice: ABCD --> AABBCCDD. ++ */ ++static const int32_t delta_tab_1_1_m10[195] = { TAB_1_1 }; ++static const int32_t delta_tab_1_2_m10[159] = { TAB_1_2 }; ++static const int32_t delta_tab_1_3_m10[133] = { TAB_1_3 }; ++static const int32_t delta_tab_1_4_m10[115] = { TAB_1_4 }; ++static const int32_t delta_tab_1_5_m10[101] = { TAB_1_5 }; ++static const int32_t delta_tab_1_6_m10[93] = { TAB_1_6 }; ++static const int32_t delta_tab_1_7_m10[87] = { TAB_1_7 }; ++static const int32_t delta_tab_1_8_m10[77] = { TAB_1_8 }; ++ ++static const int32_t delta_tab_2_1_m10[195] = { TAB_2_1 }; ++static const int32_t delta_tab_2_2_m10[159] = { TAB_2_2 }; ++static const int32_t delta_tab_2_3_m10[133] = { TAB_2_3 }; ++static const int32_t delta_tab_2_4_m10[115] = { TAB_2_4 }; ++static const int32_t delta_tab_2_5_m10[101] = { TAB_2_5 }; ++static const int32_t delta_tab_2_6_m10[93] = { TAB_2_6 }; ++static const int32_t delta_tab_2_7_m10[87] = { TAB_2_7 }; ++static const int32_t delta_tab_2_8_m10[77] = { TAB_2_8 }; ++ ++static const int32_t delta_tab_3_1_m10[128] = { TAB_3_1 }; ++static const int32_t delta_tab_3_2_m10[79] = { TAB_3_2 }; ++static const int32_t delta_tab_3_3_m10[79] = { TAB_3_3 }; ++static const int32_t delta_tab_3_4_m10[79] = { TAB_3_4 }; ++static const int32_t delta_tab_3_5_m10[79] = { TAB_3_5 }; ++ ++ ++typedef struct { ++ const int16_t *deltas; ///< delta tables for 4x4 block modes ++ const int32_t *deltas_m10; ///< delta tables for 8x8 block modes ++ uint8_t num_dyads; ///< number of two-pixel deltas ++ uint8_t quad_exp; ///< log2 of four-pixel deltas ++} vqEntry; ++ ++static const vqEntry vq_tab[24] = { ++ /* set 1 */ ++ { delta_tab_1_1, delta_tab_1_1_m10, 195, 7 }, ++ { delta_tab_1_2, delta_tab_1_2_m10, 159, 9 }, ++ { delta_tab_1_3, delta_tab_1_3_m10, 133, 10 }, ++ { delta_tab_1_4, delta_tab_1_4_m10, 115, 11 }, ++ { delta_tab_1_5, delta_tab_1_5_m10, 101, 12 }, ++ { delta_tab_1_6, delta_tab_1_6_m10, 93, 12 }, ++ { delta_tab_1_7, delta_tab_1_7_m10, 87, 12 }, ++ { delta_tab_1_8, delta_tab_1_8_m10, 77, 13 }, + ++ /* set 2 */ ++ { delta_tab_2_1, delta_tab_2_1_m10, 195, 7 }, ++ { delta_tab_2_2, delta_tab_2_2_m10, 159, 9 }, ++ { delta_tab_2_3, delta_tab_2_3_m10, 133, 10 }, ++ { delta_tab_2_4, delta_tab_2_4_m10, 115, 11 }, ++ { delta_tab_2_5, delta_tab_2_5_m10, 101, 12 }, ++ { delta_tab_2_6, delta_tab_2_6_m10, 93, 12 }, ++ { delta_tab_2_7, delta_tab_2_7_m10, 87, 12 }, ++ { delta_tab_2_8, delta_tab_2_8_m10, 77, 13 }, + +-static const uint32_t correctionhighorder[] = { +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, +- 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, +- 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x0302feff, 0xfcfd0101, 0xfeff0303, 0x0100fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, +- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, +- 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, +- 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, +- 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, +- 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x0403feff, +- 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, 0xfcfcfcfd, +- 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, 0x03030303, +- 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, 0x00000000, +- 0x03030303, 0xfcfcfcfd, 0x0403feff, 0xfbfc0101, 0xfeff0404, 0x0100fbfc, 0x07070707, 0xf8f8f8f9, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, +- 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, +- 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, +- 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, +- 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, +- 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, +- 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, 0x03030a0a, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x0504feff, 0xfafb0101, 0xfeff0505, 0x0100fafb, 0x0a0a0303, 0xf5f5fcfd, +- 0x03030a0a, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, +- 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, +- 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, +- 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, +- 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, +- 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, +- 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, +- 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, +- 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, +- 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, +- 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, +- 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, +- 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x05050505, +- 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, +- 0xf2f2fcfd, 0x00000000, 0x05050505, 0xfafafafb, 0x0706fdfe, 0xf8f90202, 0xfdfe0707, 0x0201f8f9, +- 0x0b0b0b0b, 0xf4f4f4f5, 0x0d0d0303, 0xf2f2fcfd, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, +- 0x04040f0f, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x0807fdfe, 0xf7f80202, 0xfdfe0808, 0x0201f7f8, +- 0x0d0d0d0d, 0xf2f2f2f3, 0x0f0f0404, 0xf0f0fbfc, 0x04040f0f, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, +- 0x05051212, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x0a09fcfd, 0xf5f60303, 0xfcfd0a0a, 0x0302f5f6, +- 0x10101010, 0xefefeff0, 0x12120505, 0xededfafb, 0x05051212, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, +- 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x0b0afcfd, 0xf4f50303, +- 0xfcfd0b0b, 0x0302f4f5, 0x12121212, 0xedededee, 0x14140505, 0xebebfafb, 0x05051414, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x09090909, 0xf6f6f6f7, +- 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, +- 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, +- 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, +- 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, +- 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, +- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, +- 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, +- 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, +- 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, +- 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, +- 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, +- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, +- 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, +- 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, +- 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, +- 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, +- 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, +- 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, +- 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, +- 0xf9f9e8e9, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x0c0bfcfd, 0xf3f40303, 0xfcfd0c0c, 0x0302f3f4, +- 0x14141414, 0xebebebec, 0x17170606, 0xe8e8f9fa, 0x06061717, 0xf9f9e8e9, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, +- 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, +- 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, +- 0x00000000, 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, +- 0x02020202, 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202, +- 0xfdfdfdfe, 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x02020202, 0xfdfdfdfe, +- 0x02020000, 0xfdfe0000, 0x00000202, 0xfffffdfe, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, +- 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, +- 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, +- 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, +- 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, +- 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, 0x03030000, +- 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, 0xfcfcfcfd, +- 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, 0x03030303, +- 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, 0x00000000, +- 0x03030303, 0xfcfcfcfd, 0x03030000, 0xfcfd0000, 0x00000303, 0xfffffcfd, 0x06060606, 0xf9f9f9fa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, +- 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, +- 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, +- 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, +- 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, +- 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, +- 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, 0x04040404, 0xfbfbfbfc, +- 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, 0x04040808, 0x00000000, +- 0x04040404, 0xfbfbfbfc, 0x04040000, 0xfbfc0000, 0x00000404, 0xfffffbfc, 0x08080404, 0xf7f7fbfc, +- 0x04040808, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, +- 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, +- 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, +- 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, +- 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, +- 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, +- 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, +- 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, +- 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, +- 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, +- 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, +- 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, +- 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x05050505, +- 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, +- 0xf0f0fafb, 0x00000000, 0x05050505, 0xfafafafb, 0x05050000, 0xfafb0000, 0x00000505, 0xfffffafb, +- 0x0a0a0a0a, 0xf5f5f5f6, 0x0f0f0505, 0xf0f0fafb, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, +- 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, +- 0x06060c0c, 0x00000000, 0x06060606, 0xf9f9f9fa, 0x06060000, 0xf9fa0000, 0x00000606, 0xfffff9fa, +- 0x0c0c0c0c, 0xf3f3f3f4, 0x0c0c0606, 0xf3f3f9fa, 0x06060c0c, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, +- 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, +- 0x07071515, 0x00000000, 0x07070707, 0xf8f8f8f9, 0x07070000, 0xf8f90000, 0x00000707, 0xfffff8f9, +- 0x0e0e0e0e, 0xf1f1f1f2, 0x15150707, 0xeaeaf8f9, 0x07071515, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, +- 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, 0x08080808, 0xf7f7f7f8, 0x08080000, 0xf7f80000, +- 0x00000808, 0xfffff7f8, 0x10101010, 0xefefeff0, 0x10100808, 0xefeff7f8, 0x08081010, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, 0x09090909, 0xf6f6f6f7, +- 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, +- 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, +- 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, +- 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, +- 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, +- 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, +- 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, +- 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, +- 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, +- 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, +- 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, +- 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, +- 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, +- 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, +- 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, +- 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, +- 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, +- 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, +- 0xf6f70000, 0x00000909, 0xfffff6f7, 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, +- 0xf6f6e4e5, 0x00000000, 0x09090909, 0xf6f6f6f7, 0x09090000, 0xf6f70000, 0x00000909, 0xfffff6f7, +- 0x12121212, 0xedededee, 0x1b1b0909, 0xe4e4f6f7, 0x09091b1b, 0xf6f6e4e5, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0x03030000, +- 0x03030000, 0x03030000, 0x03030000, 0x03030000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, +- 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0xfcfd0000, 0x00000303, +- 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, 0x00000303, +- 0x00000303, 0x00000303, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, +- 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0xfffffcfd, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, +- 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0x07070000, 0xf8f90000, 0xf8f90000, +- 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, 0xf8f90000, +- 0xf8f90000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, +- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, +- 0x02020000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, +- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202, +- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, +- 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, +- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0x06060000, 0x06060000, 0x06060000, 0x06060000, +- 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, 0x06060000, +- 0x06060000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, +- 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0xf9fa0000, 0x00000606, 0x00000606, +- 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, 0x00000606, +- 0x00000606, 0x00000606, 0x00000606, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, +- 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, 0xfffff9fa, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, +- 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, 0x02020000, +- 0x02020000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, +- 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0xfdfe0000, 0x00000202, 0x00000202, +- 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, 0x00000202, +- 0x00000202, 0x00000202, 0x00000202, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, +- 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, 0xfffffdfe, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, +- 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0x0a0a0a0a, 0xf5f5f5f6, +- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, +- 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0xf5f5f5f6, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, +- 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, 0x0a0a0000, +- 0x0a0a0000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, +- 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0xf5f60000, 0x00000a0a, 0x00000a0a, +- 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, 0x00000a0a, +- 0x00000a0a, 0x00000a0a, 0x00000a0a, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, +- 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, 0xfffff5f6, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, +- 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, 0x04040000, +- 0x04040000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, +- 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0xfbfc0000, 0x00000404, 0x00000404, +- 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, 0x00000404, +- 0x00000404, 0x00000404, 0x00000404, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, +- 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, 0xfffffbfc, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, +- 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0x04040404, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, 0xfbfbfbfc, +- 0xfbfbfbfc, 0xfbfbfbfc, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, +- 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, 0x0c0c0000, +- 0x0c0c0000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, +- 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0xf3f40000, 0x00000c0c, 0x00000c0c, +- 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, 0x00000c0c, +- 0x00000c0c, 0x00000c0c, 0x00000c0c, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, +- 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, 0xfffff3f4, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, +- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, +- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, +- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, +- 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0xdeadbeef, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, 0x02020202, +- 0x02020202, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, +- 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0xfdfdfdfe, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, 0x06060606, +- 0x06060606, 0x06060606, 0x06060606, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, 0xf9f9f9fa, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, +- 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0x0c0c0c0c, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, 0xf3f3f3f4, +- 0xf3f3f3f4, 0xf3f3f3f4, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, +- 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0x14141414, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, +- 0xebebebec, 0xebebebec, 0xebebebec, 0xebebebec, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, 0x20202020, +- 0x20202020, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, +- 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0xdfdfdfe0, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, +- 0x2e2e2e2e, 0x2e2e2e2e, 0x2e2e2e2e, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, 0xd1d1d1d2, +- 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000 ++ /* set 3 */ ++ { delta_tab_3_1, delta_tab_3_1_m10, 128, 11 }, ++ { delta_tab_3_2, delta_tab_3_2_m10, 79, 13 }, ++ { delta_tab_3_3, delta_tab_3_3_m10, 79, 13 }, ++ { delta_tab_3_4, delta_tab_3_4_m10, 79, 13 }, ++ { delta_tab_3_5, delta_tab_3_5_m10, 79, 13 }, ++ { delta_tab_3_5, delta_tab_3_5_m10, 79, 13 }, ++ { delta_tab_3_5, delta_tab_3_5_m10, 79, 13 }, ++ { delta_tab_3_5, delta_tab_3_5_m10, 79, 13 } + }; + + #endif /* AVCODEC_INDEO3DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo4.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo4.c 2012-05-14 14:08:53.870330643 +0200 +@@ -0,0 +1,826 @@ ++/* ++ * Indeo Video Interactive v4 compatible decoder ++ * Copyright (c) 2009-2011 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Indeo Video Interactive version 4 decoder ++ * ++ * Indeo 4 data is usually transported within .avi or .mov files. ++ * Known FOURCCs: 'IV41' ++ */ ++ ++#define BITSTREAM_READER_LE ++#include "avcodec.h" ++#include "get_bits.h" ++#include "dsputil.h" ++#include "ivi_dsp.h" ++#include "ivi_common.h" ++#include "indeo4data.h" ++ ++#define IVI4_STREAM_ANALYSER 0 ++#define IVI4_DEBUG_CHECKSUM 0 ++ ++/** ++ * Indeo 4 frame types. ++ */ ++enum { ++ FRAMETYPE_INTRA = 0, ++ FRAMETYPE_BIDIR1 = 1, ///< bidirectional frame ++ FRAMETYPE_INTER = 2, ///< non-droppable P-frame ++ FRAMETYPE_BIDIR = 3, ///< bidirectional frame ++ FRAMETYPE_INTER_NOREF = 4, ///< droppable P-frame ++ FRAMETYPE_NULL_FIRST = 5, ///< empty frame with no data ++ FRAMETYPE_NULL_LAST = 6 ///< empty frame with no data ++}; ++ ++#define IVI4_PIC_SIZE_ESC 7 ++ ++ ++typedef struct { ++ GetBitContext gb; ++ AVFrame frame; ++ RVMapDesc rvmap_tabs[9]; ///< local corrected copy of the static rvmap tables ++ ++ uint32_t frame_num; ++ int frame_type; ++ int prev_frame_type; ///< frame type of the previous frame ++ uint32_t data_size; ///< size of the frame data in bytes from picture header ++ int is_scalable; ++ int transp_status; ///< transparency mode status: 1 - enabled ++ ++ IVIPicConfig pic_conf; ++ IVIPlaneDesc planes[3]; ///< color planes ++ ++ int buf_switch; ///< used to switch between three buffers ++ int dst_buf; ///< buffer index for the currently decoded frame ++ int ref_buf; ///< inter frame reference buffer index ++ ++ IVIHuffTab mb_vlc; ///< current macroblock table descriptor ++ IVIHuffTab blk_vlc; ///< current block table descriptor ++ ++ uint16_t checksum; ///< frame checksum ++ ++ uint8_t rvmap_sel; ++ uint8_t in_imf; ++ uint8_t in_q; ///< flag for explicitly stored quantiser delta ++ uint8_t pic_glob_quant; ++ uint8_t unknown1; ++ ++#if IVI4_STREAM_ANALYSER ++ uint8_t has_b_frames; ++ uint8_t has_transp; ++ uint8_t uses_tiling; ++ uint8_t uses_haar; ++ uint8_t uses_fullpel; ++#endif ++} IVI4DecContext; ++ ++ ++static const struct { ++ InvTransformPtr *inv_trans; ++ DCTransformPtr *dc_trans; ++ int is_2d_trans; ++} transforms[18] = { ++ { ff_ivi_inverse_haar_8x8, ff_ivi_dc_haar_2d, 1 }, ++ { NULL, NULL, 0 }, /* inverse Haar 8x1 */ ++ { NULL, NULL, 0 }, /* inverse Haar 1x8 */ ++ { ff_ivi_put_pixels_8x8, ff_ivi_put_dc_pixel_8x8, 1 }, ++ { ff_ivi_inverse_slant_8x8, ff_ivi_dc_slant_2d, 1 }, ++ { ff_ivi_row_slant8, ff_ivi_dc_row_slant, 1 }, ++ { ff_ivi_col_slant8, ff_ivi_dc_col_slant, 1 }, ++ { NULL, NULL, 0 }, /* inverse DCT 8x8 */ ++ { NULL, NULL, 0 }, /* inverse DCT 8x1 */ ++ { NULL, NULL, 0 }, /* inverse DCT 1x8 */ ++ { NULL, NULL, 0 }, /* inverse Haar 4x4 */ ++ { ff_ivi_inverse_slant_4x4, ff_ivi_dc_slant_2d, 1 }, ++ { NULL, NULL, 0 }, /* no transform 4x4 */ ++ { NULL, NULL, 0 }, /* inverse Haar 1x4 */ ++ { NULL, NULL, 0 }, /* inverse Haar 4x1 */ ++ { NULL, NULL, 0 }, /* inverse slant 1x4 */ ++ { NULL, NULL, 0 }, /* inverse slant 4x1 */ ++ { NULL, NULL, 0 }, /* inverse DCT 4x4 */ ++}; ++ ++/** ++ * Decode subdivision of a plane. ++ * This is a simplified version that checks for two supported subdivisions: ++ * - 1 wavelet band per plane, size factor 1:1, code pattern: 3 ++ * - 4 wavelet bands per plane, size factor 1:4, code pattern: 2,3,3,3,3 ++ * Anything else is either unsupported or corrupt. ++ * ++ * @param[in,out] gb the GetBit context ++ * @return number of wavelet bands or 0 on error ++ */ ++static int decode_plane_subdivision(GetBitContext *gb) ++{ ++ int i; ++ ++ switch (get_bits(gb, 2)) { ++ case 3: ++ return 1; ++ case 2: ++ for (i = 0; i < 4; i++) ++ if (get_bits(gb, 2) != 3) ++ return 0; ++ return 4; ++ default: ++ return 0; ++ } ++} ++ ++static inline int scale_tile_size(int def_size, int size_factor) ++{ ++ return size_factor == 15 ? def_size : (size_factor + 1) << 5; ++} ++ ++/** ++ * Decode Indeo 4 picture header. ++ * ++ * @param[in,out] ctx pointer to the decoder context ++ * @param[in] avctx pointer to the AVCodecContext ++ * @return result code: 0 = OK, negative number = error ++ */ ++static int decode_pic_hdr(IVI4DecContext *ctx, AVCodecContext *avctx) ++{ ++ int pic_size_indx, i, p; ++ IVIPicConfig pic_conf; ++ ++ if (get_bits(&ctx->gb, 18) != 0x3FFF8) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid picture start code!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->prev_frame_type = ctx->frame_type; ++ ctx->frame_type = get_bits(&ctx->gb, 3); ++ if (ctx->frame_type == 7) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid frame type: %d\n", ctx->frame_type); ++ return AVERROR_INVALIDDATA; ++ } ++ ++#if IVI4_STREAM_ANALYSER ++ if ( ctx->frame_type == FRAMETYPE_BIDIR1 ++ || ctx->frame_type == FRAMETYPE_BIDIR) ++ ctx->has_b_frames = 1; ++#endif ++ ++ ctx->transp_status = get_bits1(&ctx->gb); ++#if IVI4_STREAM_ANALYSER ++ if (ctx->transp_status) { ++ ctx->has_transp = 1; ++ } ++#endif ++ ++ /* unknown bit: Mac decoder ignores this bit, XANIM returns error */ ++ if (get_bits1(&ctx->gb)) { ++ av_log(avctx, AV_LOG_ERROR, "Sync bit is set!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->data_size = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 24) : 0; ++ ++ /* null frames don't contain anything else so we just return */ ++ if (ctx->frame_type >= FRAMETYPE_NULL_FIRST) { ++ av_dlog(avctx, "Null frame encountered!\n"); ++ return 0; ++ } ++ ++ /* Check key lock status. If enabled - ignore lock word. */ ++ /* Usually we have to prompt the user for the password, but */ ++ /* we don't do that because Indeo 4 videos can be decoded anyway */ ++ if (get_bits1(&ctx->gb)) { ++ skip_bits_long(&ctx->gb, 32); ++ av_dlog(avctx, "Password-protected clip!\n"); ++ } ++ ++ pic_size_indx = get_bits(&ctx->gb, 3); ++ if (pic_size_indx == IVI4_PIC_SIZE_ESC) { ++ pic_conf.pic_height = get_bits(&ctx->gb, 16); ++ pic_conf.pic_width = get_bits(&ctx->gb, 16); ++ } else { ++ pic_conf.pic_height = ivi4_common_pic_sizes[pic_size_indx * 2 + 1]; ++ pic_conf.pic_width = ivi4_common_pic_sizes[pic_size_indx * 2 ]; ++ } ++ ++ /* Decode tile dimensions. */ ++ if (get_bits1(&ctx->gb)) { ++ pic_conf.tile_height = scale_tile_size(pic_conf.pic_height, get_bits(&ctx->gb, 4)); ++ pic_conf.tile_width = scale_tile_size(pic_conf.pic_width, get_bits(&ctx->gb, 4)); ++#if IVI4_STREAM_ANALYSER ++ ctx->uses_tiling = 1; ++#endif ++ } else { ++ pic_conf.tile_height = pic_conf.pic_height; ++ pic_conf.tile_width = pic_conf.pic_width; ++ } ++ ++ /* Decode chroma subsampling. We support only 4:4 aka YVU9. */ ++ if (get_bits(&ctx->gb, 2)) { ++ av_log(avctx, AV_LOG_ERROR, "Only YVU9 picture format is supported!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ pic_conf.chroma_height = (pic_conf.pic_height + 3) >> 2; ++ pic_conf.chroma_width = (pic_conf.pic_width + 3) >> 2; ++ ++ /* decode subdivision of the planes */ ++ pic_conf.luma_bands = decode_plane_subdivision(&ctx->gb); ++ if (pic_conf.luma_bands) ++ pic_conf.chroma_bands = decode_plane_subdivision(&ctx->gb); ++ ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1; ++ if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) { ++ av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n", ++ pic_conf.luma_bands, pic_conf.chroma_bands); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* check if picture layout was changed and reallocate buffers */ ++ if (ivi_pic_config_cmp(&pic_conf, &ctx->pic_conf)) { ++ if (ff_ivi_init_planes(ctx->planes, &pic_conf)) { ++ av_log(avctx, AV_LOG_ERROR, "Couldn't reallocate color planes!\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ ctx->pic_conf = pic_conf; ++ ++ /* set default macroblock/block dimensions */ ++ for (p = 0; p <= 2; p++) { ++ for (i = 0; i < (!p ? pic_conf.luma_bands : pic_conf.chroma_bands); i++) { ++ ctx->planes[p].bands[i].mb_size = !p ? (!ctx->is_scalable ? 16 : 8) : 4; ++ ctx->planes[p].bands[i].blk_size = !p ? 8 : 4; ++ } ++ } ++ ++ if (ff_ivi_init_tiles(ctx->planes, ctx->pic_conf.tile_width, ++ ctx->pic_conf.tile_height)) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Couldn't reallocate internal structures!\n"); ++ return AVERROR(ENOMEM); ++ } ++ } ++ ++ ctx->frame_num = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 20) : 0; ++ ++ /* skip decTimeEst field if present */ ++ if (get_bits1(&ctx->gb)) ++ skip_bits(&ctx->gb, 8); ++ ++ /* decode macroblock and block huffman codebooks */ ++ if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_MB_HUFF, &ctx->mb_vlc, avctx) || ++ ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, &ctx->blk_vlc, avctx)) ++ return AVERROR_INVALIDDATA; ++ ++ ctx->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8; ++ ++ ctx->in_imf = get_bits1(&ctx->gb); ++ ctx->in_q = get_bits1(&ctx->gb); ++ ++ ctx->pic_glob_quant = get_bits(&ctx->gb, 5); ++ ++ /* TODO: ignore this parameter if unused */ ++ ctx->unknown1 = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 0; ++ ++ ctx->checksum = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 16) : 0; ++ ++ /* skip picture header extension if any */ ++ while (get_bits1(&ctx->gb)) { ++ av_dlog(avctx, "Pic hdr extension encountered!\n"); ++ skip_bits(&ctx->gb, 8); ++ } ++ ++ if (get_bits1(&ctx->gb)) { ++ av_log(avctx, AV_LOG_ERROR, "Bad blocks bits encountered!\n"); ++ } ++ ++ align_get_bits(&ctx->gb); ++ ++ return 0; ++} ++ ++ ++/** ++ * Decode Indeo 4 band header. ++ * ++ * @param[in,out] ctx pointer to the decoder context ++ * @param[in,out] band pointer to the band descriptor ++ * @param[in] avctx pointer to the AVCodecContext ++ * @return result code: 0 = OK, negative number = error ++ */ ++static int decode_band_hdr(IVI4DecContext *ctx, IVIBandDesc *band, ++ AVCodecContext *avctx) ++{ ++ int plane, band_num, indx, transform_id, scan_indx; ++ int i; ++ ++ plane = get_bits(&ctx->gb, 2); ++ band_num = get_bits(&ctx->gb, 4); ++ if (band->plane != plane || band->band_num != band_num) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid band header sequence!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ band->is_empty = get_bits1(&ctx->gb); ++ if (!band->is_empty) { ++ /* skip header size ++ * If header size is not given, header size is 4 bytes. */ ++ if (get_bits1(&ctx->gb)) ++ skip_bits(&ctx->gb, 16); ++ ++ band->is_halfpel = get_bits(&ctx->gb, 2); ++ if (band->is_halfpel >= 2) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid/unsupported mv resolution: %d!\n", ++ band->is_halfpel); ++ return AVERROR_INVALIDDATA; ++ } ++#if IVI4_STREAM_ANALYSER ++ if (!band->is_halfpel) ++ ctx->uses_fullpel = 1; ++#endif ++ ++ band->checksum_present = get_bits1(&ctx->gb); ++ if (band->checksum_present) ++ band->checksum = get_bits(&ctx->gb, 16); ++ ++ indx = get_bits(&ctx->gb, 2); ++ if (indx == 3) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid block size!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ band->mb_size = 16 >> indx; ++ band->blk_size = 8 >> (indx >> 1); ++ ++ band->inherit_mv = get_bits1(&ctx->gb); ++ band->inherit_qdelta = get_bits1(&ctx->gb); ++ ++ band->glob_quant = get_bits(&ctx->gb, 5); ++ ++ if (!get_bits1(&ctx->gb) || ctx->frame_type == FRAMETYPE_INTRA) { ++ transform_id = get_bits(&ctx->gb, 5); ++ if (!transforms[transform_id].inv_trans) { ++ av_log_ask_for_sample(avctx, "Unimplemented transform: %d!\n", transform_id); ++ return AVERROR_PATCHWELCOME; ++ } ++ if ((transform_id >= 7 && transform_id <= 9) || ++ transform_id == 17) { ++ av_log_ask_for_sample(avctx, "DCT transform not supported yet!\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++#if IVI4_STREAM_ANALYSER ++ if ((transform_id >= 0 && transform_id <= 2) || transform_id == 10) ++ ctx->uses_haar = 1; ++#endif ++ ++ band->inv_transform = transforms[transform_id].inv_trans; ++ band->dc_transform = transforms[transform_id].dc_trans; ++ band->is_2d_trans = transforms[transform_id].is_2d_trans; ++ ++ scan_indx = get_bits(&ctx->gb, 4); ++ if (scan_indx == 15) { ++ av_log(avctx, AV_LOG_ERROR, "Custom scan pattern encountered!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ band->scan = scan_index_to_tab[scan_indx]; ++ ++ band->quant_mat = get_bits(&ctx->gb, 5); ++ if (band->quant_mat == 31) { ++ av_log(avctx, AV_LOG_ERROR, "Custom quant matrix encountered!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ ++ /* decode block huffman codebook */ ++ if (ff_ivi_dec_huff_desc(&ctx->gb, get_bits1(&ctx->gb), IVI_BLK_HUFF, ++ &band->blk_vlc, avctx)) ++ return AVERROR_INVALIDDATA; ++ ++ /* select appropriate rvmap table for this band */ ++ band->rvmap_sel = get_bits1(&ctx->gb) ? get_bits(&ctx->gb, 3) : 8; ++ ++ /* decode rvmap probability corrections if any */ ++ band->num_corr = 0; /* there is no corrections */ ++ if (get_bits1(&ctx->gb)) { ++ band->num_corr = get_bits(&ctx->gb, 8); /* get number of correction pairs */ ++ if (band->num_corr > 61) { ++ av_log(avctx, AV_LOG_ERROR, "Too many corrections: %d\n", ++ band->num_corr); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* read correction pairs */ ++ for (i = 0; i < band->num_corr * 2; i++) ++ band->corr[i] = get_bits(&ctx->gb, 8); ++ } ++ } ++ ++ if (band->blk_size == 8) { ++ band->intra_base = &ivi4_quant_8x8_intra[quant_index_to_tab[band->quant_mat]][0]; ++ band->inter_base = &ivi4_quant_8x8_inter[quant_index_to_tab[band->quant_mat]][0]; ++ } else { ++ band->intra_base = &ivi4_quant_4x4_intra[quant_index_to_tab[band->quant_mat]][0]; ++ band->inter_base = &ivi4_quant_4x4_inter[quant_index_to_tab[band->quant_mat]][0]; ++ } ++ ++ /* Indeo 4 doesn't use scale tables */ ++ band->intra_scale = NULL; ++ band->inter_scale = NULL; ++ ++ align_get_bits(&ctx->gb); ++ ++ return 0; ++} ++ ++ ++/** ++ * Decode information (block type, cbp, quant delta, motion vector) ++ * for all macroblocks in the current tile. ++ * ++ * @param[in,out] ctx pointer to the decoder context ++ * @param[in,out] band pointer to the band descriptor ++ * @param[in,out] tile pointer to the tile descriptor ++ * @param[in] avctx pointer to the AVCodecContext ++ * @return result code: 0 = OK, negative number = error ++ */ ++static int decode_mb_info(IVI4DecContext *ctx, IVIBandDesc *band, ++ IVITile *tile, AVCodecContext *avctx) ++{ ++ int x, y, mv_x, mv_y, mv_delta, offs, mb_offset, blks_per_mb, ++ mv_scale, mb_type_bits; ++ IVIMbInfo *mb, *ref_mb; ++ int row_offset = band->mb_size * band->pitch; ++ ++ mb = tile->mbs; ++ ref_mb = tile->ref_mbs; ++ offs = tile->ypos * band->pitch + tile->xpos; ++ ++ blks_per_mb = band->mb_size != band->blk_size ? 4 : 1; ++ mb_type_bits = ctx->frame_type == FRAMETYPE_BIDIR ? 2 : 1; ++ ++ /* scale factor for motion vectors */ ++ mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); ++ mv_x = mv_y = 0; ++ ++ for (y = tile->ypos; y < tile->ypos + tile->height; y += band->mb_size) { ++ mb_offset = offs; ++ ++ for (x = tile->xpos; x < tile->xpos + tile->width; x += band->mb_size) { ++ mb->xpos = x; ++ mb->ypos = y; ++ mb->buf_offs = mb_offset; ++ ++ if (get_bits1(&ctx->gb)) { ++ if (ctx->frame_type == FRAMETYPE_INTRA) { ++ av_log(avctx, AV_LOG_ERROR, "Empty macroblock in an INTRA picture!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ mb->type = 1; /* empty macroblocks are always INTER */ ++ mb->cbp = 0; /* all blocks are empty */ ++ ++ mb->q_delta = 0; ++ if (!band->plane && !band->band_num && ctx->in_q) { ++ mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, ++ IVI_VLC_BITS, 1); ++ mb->q_delta = IVI_TOSIGNED(mb->q_delta); ++ } ++ ++ mb->mv_x = mb->mv_y = 0; /* no motion vector coded */ ++ if (band->inherit_mv) { ++ /* motion vector inheritance */ ++ if (mv_scale) { ++ mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); ++ mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); ++ } else { ++ mb->mv_x = ref_mb->mv_x; ++ mb->mv_y = ref_mb->mv_y; ++ } ++ } ++ } else { ++ if (band->inherit_mv) { ++ mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */ ++ } else if (ctx->frame_type == FRAMETYPE_INTRA) { ++ mb->type = 0; /* mb_type is always INTRA for intra-frames */ ++ } else { ++ mb->type = get_bits(&ctx->gb, mb_type_bits); ++ } ++ ++ mb->cbp = get_bits(&ctx->gb, blks_per_mb); ++ ++ mb->q_delta = 0; ++ if (band->inherit_qdelta) { ++ if (ref_mb) mb->q_delta = ref_mb->q_delta; ++ } else if (mb->cbp || (!band->plane && !band->band_num && ++ ctx->in_q)) { ++ mb->q_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, ++ IVI_VLC_BITS, 1); ++ mb->q_delta = IVI_TOSIGNED(mb->q_delta); ++ } ++ ++ if (!mb->type) { ++ mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */ ++ } else { ++ if (band->inherit_mv) { ++ /* motion vector inheritance */ ++ if (mv_scale) { ++ mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); ++ mb->mv_y = ivi_scale_mv(ref_mb->mv_y, mv_scale); ++ } else { ++ mb->mv_x = ref_mb->mv_x; ++ mb->mv_y = ref_mb->mv_y; ++ } ++ } else { ++ /* decode motion vector deltas */ ++ mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, ++ IVI_VLC_BITS, 1); ++ mv_y += IVI_TOSIGNED(mv_delta); ++ mv_delta = get_vlc2(&ctx->gb, ctx->mb_vlc.tab->table, ++ IVI_VLC_BITS, 1); ++ mv_x += IVI_TOSIGNED(mv_delta); ++ mb->mv_x = mv_x; ++ mb->mv_y = mv_y; ++ } ++ } ++ } ++ ++ mb++; ++ if (ref_mb) ++ ref_mb++; ++ mb_offset += band->mb_size; ++ } ++ ++ offs += row_offset; ++ } ++ ++ align_get_bits(&ctx->gb); ++ ++ return 0; ++} ++ ++ ++/** ++ * Decode an Indeo 4 band. ++ * ++ * @param[in,out] ctx pointer to the decoder context ++ * @param[in,out] band pointer to the band descriptor ++ * @param[in] avctx pointer to the AVCodecContext ++ * @return result code: 0 = OK, negative number = error ++ */ ++static int decode_band(IVI4DecContext *ctx, int plane_num, ++ IVIBandDesc *band, AVCodecContext *avctx) ++{ ++ int result, i, t, pos, idx1, idx2; ++ IVITile *tile; ++ ++ band->buf = band->bufs[ctx->dst_buf]; ++ band->ref_buf = band->bufs[ctx->ref_buf]; ++ ++ result = decode_band_hdr(ctx, band, avctx); ++ if (result) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding band header\n"); ++ return result; ++ } ++ ++ if (band->is_empty) { ++ av_log(avctx, AV_LOG_ERROR, "Empty band encountered!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ band->rv_map = &ctx->rvmap_tabs[band->rvmap_sel]; ++ ++ /* apply corrections to the selected rvmap table if present */ ++ for (i = 0; i < band->num_corr; i++) { ++ idx1 = band->corr[i * 2]; ++ idx2 = band->corr[i * 2 + 1]; ++ FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); ++ FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); ++ } ++ ++ pos = get_bits_count(&ctx->gb); ++ ++ for (t = 0; t < band->num_tiles; t++) { ++ tile = &band->tiles[t]; ++ ++ tile->is_empty = get_bits1(&ctx->gb); ++ if (tile->is_empty) { ++ ff_ivi_process_empty_tile(avctx, band, tile, ++ (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3)); ++ av_dlog(avctx, "Empty tile encountered!\n"); ++ } else { ++ tile->data_size = ff_ivi_dec_tile_data_size(&ctx->gb); ++ if (!tile->data_size) { ++ av_log(avctx, AV_LOG_ERROR, "Tile data size is zero!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ result = decode_mb_info(ctx, band, tile, avctx); ++ if (result < 0) ++ break; ++ ++ result = ff_ivi_decode_blocks(&ctx->gb, band, tile); ++ if (result < 0 || ((get_bits_count(&ctx->gb) - pos) >> 3) != tile->data_size) { ++ av_log(avctx, AV_LOG_ERROR, "Corrupted tile data encountered!\n"); ++ break; ++ } ++ ++ pos += tile->data_size << 3; // skip to next tile ++ } ++ } ++ ++ /* restore the selected rvmap table by applying its corrections in reverse order */ ++ for (i = band->num_corr - 1; i >= 0; i--) { ++ idx1 = band->corr[i * 2]; ++ idx2 = band->corr[i * 2 + 1]; ++ FFSWAP(uint8_t, band->rv_map->runtab[idx1], band->rv_map->runtab[idx2]); ++ FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); ++ } ++ ++#if defined(DEBUG) && IVI4_DEBUG_CHECKSUM ++ if (band->checksum_present) { ++ uint16_t chksum = ivi_calc_band_checksum(band); ++ if (chksum != band->checksum) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Band checksum mismatch! Plane %d, band %d, received: %x, calculated: %x\n", ++ band->plane, band->band_num, band->checksum, chksum); ++ } ++ } ++#endif ++ ++ align_get_bits(&ctx->gb); ++ ++ return 0; ++} ++ ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ IVI4DecContext *ctx = avctx->priv_data; ++ ++ ff_ivi_init_static_vlc(); ++ ++ /* copy rvmap tables in our context so we can apply changes to them */ ++ memcpy(ctx->rvmap_tabs, ff_ivi_rvmap_tabs, sizeof(ff_ivi_rvmap_tabs)); ++ ++ /* Force allocation of the internal buffers */ ++ /* during picture header decoding. */ ++ ctx->pic_conf.pic_width = 0; ++ ctx->pic_conf.pic_height = 0; ++ ++ avctx->pix_fmt = PIX_FMT_YUV410P; ++ ++ return 0; ++} ++ ++ ++/** ++ * Rearrange decoding and reference buffers. ++ * ++ * @param[in,out] ctx pointer to the decoder context ++ */ ++static void switch_buffers(IVI4DecContext *ctx) ++{ ++ switch (ctx->prev_frame_type) { ++ case FRAMETYPE_INTRA: ++ case FRAMETYPE_INTER: ++ ctx->buf_switch ^= 1; ++ ctx->dst_buf = ctx->buf_switch; ++ ctx->ref_buf = ctx->buf_switch ^ 1; ++ break; ++ case FRAMETYPE_INTER_NOREF: ++ break; ++ } ++ ++ switch (ctx->frame_type) { ++ case FRAMETYPE_INTRA: ++ ctx->buf_switch = 0; ++ /* FALLTHROUGH */ ++ case FRAMETYPE_INTER: ++ ctx->dst_buf = ctx->buf_switch; ++ ctx->ref_buf = ctx->buf_switch ^ 1; ++ break; ++ case FRAMETYPE_INTER_NOREF: ++ case FRAMETYPE_NULL_FIRST: ++ case FRAMETYPE_NULL_LAST: ++ break; ++ } ++} ++ ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ IVI4DecContext *ctx = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int result, p, b; ++ ++ init_get_bits(&ctx->gb, buf, buf_size * 8); ++ ++ result = decode_pic_hdr(ctx, avctx); ++ if (result) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding picture header\n"); ++ return result; ++ } ++ ++ switch_buffers(ctx); ++ ++ if (ctx->frame_type < FRAMETYPE_NULL_FIRST) { ++ for (p = 0; p < 3; p++) { ++ for (b = 0; b < ctx->planes[p].num_bands; b++) { ++ result = decode_band(ctx, p, &ctx->planes[p].bands[b], avctx); ++ if (result) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Error decoding band: %d, plane: %d\n", b, p); ++ return result; ++ } ++ } ++ } ++ } ++ ++ /* If the bidirectional mode is enabled, next I and the following P frame will */ ++ /* be sent together. Unfortunately the approach below seems to be the only way */ ++ /* to handle the B-frames mode. That's exactly the same Intel decoders do. */ ++ if (ctx->frame_type == FRAMETYPE_INTRA) { ++ while (get_bits(&ctx->gb, 8)); // skip version string ++ skip_bits_long(&ctx->gb, 64); // skip padding, TODO: implement correct 8-bytes alignment ++ if (get_bits_left(&ctx->gb) > 18 && show_bits(&ctx->gb, 18) == 0x3FFF8) ++ av_log(avctx, AV_LOG_ERROR, "Buffer contains IP frames!\n"); ++ } ++ ++ if (ctx->frame.data[0]) ++ avctx->release_buffer(avctx, &ctx->frame); ++ ++ ctx->frame.reference = 0; ++ if ((result = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return result; ++ } ++ ++ if (ctx->is_scalable) { ++ ff_ivi_recompose_haar(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0], 4); ++ } else { ++ ff_ivi_output_plane(&ctx->planes[0], ctx->frame.data[0], ctx->frame.linesize[0]); ++ } ++ ++ ff_ivi_output_plane(&ctx->planes[2], ctx->frame.data[1], ctx->frame.linesize[1]); ++ ff_ivi_output_plane(&ctx->planes[1], ctx->frame.data[2], ctx->frame.linesize[2]); ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = ctx->frame; ++ ++ return buf_size; ++} ++ ++ ++static av_cold int decode_close(AVCodecContext *avctx) ++{ ++ IVI4DecContext *ctx = avctx->priv_data; ++ ++ ff_ivi_free_buffers(&ctx->planes[0]); ++ ++ if (ctx->frame.data[0]) ++ avctx->release_buffer(avctx, &ctx->frame); ++ ++#if IVI4_STREAM_ANALYSER ++ if (ctx->is_scalable) ++ av_log(avctx, AV_LOG_ERROR, "This video uses scalability mode!\n"); ++ if (ctx->uses_tiling) ++ av_log(avctx, AV_LOG_ERROR, "This video uses local decoding!\n"); ++ if (ctx->has_b_frames) ++ av_log(avctx, AV_LOG_ERROR, "This video contains B-frames!\n"); ++ if (ctx->has_transp) ++ av_log(avctx, AV_LOG_ERROR, "Transparency mode is enabled!\n"); ++ if (ctx->uses_haar) ++ av_log(avctx, AV_LOG_ERROR, "This video uses Haar transform!\n"); ++ if (ctx->uses_fullpel) ++ av_log(avctx, AV_LOG_ERROR, "This video uses fullpel motion vectors!\n"); ++#endif ++ ++ return 0; ++} ++ ++ ++AVCodec ff_indeo4_decoder = { ++ .name = "indeo4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_INDEO4, ++ .priv_data_size = sizeof(IVI4DecContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("Intel Indeo Video Interactive 4"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo4data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo4data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo4data.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo4data.h 2012-05-14 14:08:53.871330663 +0200 +@@ -0,0 +1,350 @@ ++/* ++ * Indeo Video Interactive 4 compatible decoder ++ * Copyright (c) 2009-2010 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * This file contains data needed for the Indeo 4 decoder. ++ */ ++ ++#ifndef AVCODEC_INDEO4DATA_H ++#define AVCODEC_INDEO4DATA_H ++ ++#include ++#include "dsputil.h" ++#include "ivi_common.h" ++ ++/** ++ * standard picture dimensions ++ */ ++static const uint16_t ivi4_common_pic_sizes[14] = { ++ 640, 480, 320, 240, 160, 120, 704, 480, 352, 240, 352, 288, 176, 144 ++}; ++ ++/** ++ * Indeo 4 8x8 scan (zigzag) patterns ++ */ ++static const uint8_t ivi4_alternate_scan_8x8[64] = { ++ 0, 8, 1, 9, 16, 24, 2, 3, 17, 25, 10, 11, 32, 40, 48, 56, ++ 4, 5, 6, 7, 33, 41, 49, 57, 18, 19, 26, 27, 12, 13, 14, 15, ++ 34, 35, 43, 42, 50, 51, 59, 58, 20, 21, 22, 23, 31, 30, 29, 28, ++ 36, 37, 38, 39, 47, 46, 45, 44, 52, 53, 54, 55, 63, 62, 61, 60 ++}; ++ ++static const uint8_t ivi4_alternate_scan_4x4[16] = { ++ 0, 1, 4, 5, 8, 12, 2, 3, 9, 13, 6, 7, 10, 11, 14, 15 ++}; ++ ++static const uint8_t ivi4_vertical_scan_4x4[16] = { ++ 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15 ++}; ++ ++static const uint8_t ivi4_horizontal_scan_4x4[16] = { ++ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ++}; ++ ++static const uint8_t *scan_index_to_tab[15] = { ++ // for 8x8 transforms ++ ff_zigzag_direct, ++ ivi4_alternate_scan_8x8, ++ ff_ivi_horizontal_scan_8x8, ++ ff_ivi_vertical_scan_8x8, ++ ff_zigzag_direct, ++ ++ // for 4x4 transforms ++ ff_ivi_direct_scan_4x4, ++ ivi4_alternate_scan_4x4, ++ ivi4_vertical_scan_4x4, ++ ivi4_horizontal_scan_4x4, ++ ff_ivi_direct_scan_4x4, ++ ++ // TODO: check if those are needed ++ ff_ivi_horizontal_scan_8x8, ++ ff_ivi_horizontal_scan_8x8, ++ ff_ivi_horizontal_scan_8x8, ++ ff_ivi_horizontal_scan_8x8, ++ ff_ivi_horizontal_scan_8x8 ++}; ++ ++/** ++ * Indeo 4 dequant tables ++ */ ++static const uint16_t ivi4_quant_8x8_intra[9][64] = { ++ { ++ 43, 342, 385, 470, 555, 555, 598, 726, ++ 342, 342, 470, 513, 555, 598, 726, 769, ++ 385, 470, 555, 555, 598, 726, 726, 811, ++ 470, 470, 555, 555, 598, 726, 769, 854, ++ 470, 555, 555, 598, 683, 726, 854, 1025, ++ 555, 555, 598, 683, 726, 854, 1025, 1153, ++ 555, 555, 598, 726, 811, 982, 1195, 1451, ++ 555, 598, 726, 811, 982, 1195, 1451, 1793 ++ }, ++ { ++ 86, 1195, 2390, 2390, 4865, 4865, 4865, 4865, ++ 1195, 1195, 2390, 2390, 4865, 4865, 4865, 4865, ++ 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827, ++ 2390, 2390, 4865, 4865, 6827, 6827, 6827, 6827, ++ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, ++ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, ++ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827, ++ 4865, 4865, 6827, 6827, 6827, 6827, 6827, 6827 ++ }, ++ { ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835, ++ 235, 1067, 1195, 1323, 1451, 1579, 1707, 1835 ++ }, ++ { ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414, ++ 1707, 1707, 3414, 3414, 3414, 3414, 3414, 3414 ++ }, ++ { ++ 897, 897, 897, 897, 897, 897, 897, 897, ++ 1067, 1067, 1067, 1067, 1067, 1067, 1067, 1067, ++ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, ++ 1409, 1409, 1409, 1409, 1409, 1409, 1409, 1409, ++ 1579, 1579, 1579, 1579, 1579, 1579, 1579, 1579, ++ 1750, 1750, 1750, 1750, 1750, 1750, 1750, 1750, ++ 1921, 1921, 1921, 1921, 1921, 1921, 1921, 1921, ++ 2091, 2091, 2091, 2091, 2091, 2091, 2091, 2091 ++ }, ++ { ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414 ++ }, ++ { ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390, ++ 2390, 2390, 2390, 2390, 2390, 2390, 2390, 2390 ++ }, ++ { ++ 22, 171, 214, 257, 257, 299, 299, 342, ++ 171, 171, 257, 257, 299, 299, 342, 385, ++ 214, 257, 257, 299, 299, 342, 342, 385, ++ 257, 257, 257, 299, 299, 342, 385, 427, ++ 257, 257, 299, 299, 342, 385, 427, 513, ++ 257, 299, 299, 342, 385, 427, 513, 598, ++ 299, 299, 299, 385, 385, 470, 598, 726, ++ 299, 299, 385, 385, 470, 598, 726, 897 ++ }, ++ { ++ 86, 598, 1195, 1195, 2390, 2390, 2390, 2390, ++ 598, 598, 1195, 1195, 2390, 2390, 2390, 2390, ++ 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414, ++ 1195, 1195, 2390, 2390, 3414, 3414, 3414, 3414, ++ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, ++ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, ++ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414, ++ 2390, 2390, 3414, 3414, 3414, 3414, 3414, 3414 ++ } ++}; ++ ++static const uint16_t ivi4_quant_8x8_inter[9][64] = { ++ { ++ 427, 427, 470, 427, 427, 427, 470, 470, ++ 427, 427, 470, 427, 427, 427, 470, 470, ++ 470, 470, 470, 470, 470, 470, 470, 470, ++ 427, 427, 470, 470, 427, 427, 470, 470, ++ 427, 427, 470, 427, 427, 427, 470, 470, ++ 427, 427, 470, 427, 427, 427, 470, 470, ++ 470, 470, 470, 470, 470, 470, 470, 470, ++ 470, 470, 470, 470, 470, 470, 470, 470 ++ }, ++ { ++ 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414, ++ 1707, 1707, 2433, 2433, 3414, 3414, 3414, 3414, ++ 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822, ++ 2433, 2433, 3414, 3414, 4822, 4822, 4822, 4822, ++ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, ++ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, ++ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414, ++ 3414, 3414, 4822, 4822, 3414, 3414, 3414, 3414 ++ }, ++ { ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281, ++ 1195, 1195, 1281, 1238, 1195, 1195, 1281, 1281 ++ }, ++ { ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433, ++ 2433, 2433, 3414, 3414, 2433, 2433, 2433, 2433 ++ }, ++ { ++ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, ++ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, ++ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281, ++ 1238, 1238, 1238, 1238, 1238, 1238, 1238, 1238, ++ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, ++ 1195, 1195, 1195, 1195, 1195, 1195, 1195, 1195, ++ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281, ++ 1281, 1281, 1281, 1281, 1281, 1281, 1281, 1281 ++ }, ++ { ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 3414, 3414, 3414, 3414, 3414, 3414, 3414, 3414, ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433, ++ 2433, 2433, 2433, 2433, 2433, 2433, 2433, 2433 ++ }, ++ { ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707, ++ 1707, 1707, 1707, 1707, 1707, 1707, 1707, 1707 ++ }, ++ { ++ 86, 171, 171, 214, 214, 214, 214, 257, ++ 171, 171, 214, 214, 214, 214, 257, 257, ++ 171, 214, 214, 214, 214, 257, 257, 257, ++ 214, 214, 214, 214, 257, 257, 257, 299, ++ 214, 214, 214, 257, 257, 257, 299, 299, ++ 214, 214, 257, 257, 257, 299, 299, 299, ++ 214, 257, 257, 257, 299, 299, 299, 342, ++ 257, 257, 257, 299, 299, 299, 342, 342 ++ }, ++ { ++ 854, 854, 1195, 1195, 1707, 1707, 1707, 1707, ++ 854, 854, 1195, 1195, 1707, 1707, 1707, 1707, ++ 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390, ++ 1195, 1195, 1707, 1707, 2390, 2390, 2390, 2390, ++ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, ++ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, ++ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707, ++ 1707, 1707, 2390, 2390, 1707, 1707, 1707, 1707 ++ } ++}; ++ ++static const uint16_t ivi4_quant_4x4_intra[5][16] = { ++ { ++ 22, 214, 257, 299, ++ 214, 257, 299, 342, ++ 257, 299, 342, 427, ++ 299, 342, 427, 513 ++ }, ++ { ++ 129, 1025, 1451, 1451, ++ 1025, 1025, 1451, 1451, ++ 1451, 1451, 2049, 2049, ++ 1451, 1451, 2049, 2049 ++ }, ++ { ++ 43, 171, 171, 171, ++ 43, 171, 171, 171, ++ 43, 171, 171, 171, ++ 43, 171, 171, 171 ++ }, ++ { ++ 43, 43, 43, 43, ++ 171, 171, 171, 171, ++ 171, 171, 171, 171, ++ 171, 171, 171, 171 ++ }, ++ { ++ 43, 43, 43, 43, ++ 43, 43, 43, 43, ++ 43, 43, 43, 43, ++ 43, 43, 43, 43 ++ } ++}; ++ ++static const uint16_t ivi4_quant_4x4_inter[5][16] = { ++ { ++ 107, 214, 257, 299, ++ 214, 257, 299, 299, ++ 257, 299, 299, 342, ++ 299, 299, 342, 342 ++ }, ++ { ++ 513, 1025, 1238, 1238, ++ 1025, 1025, 1238, 1238, ++ 1238, 1238, 1451, 1451, ++ 1238, 1238, 1451, 1451 ++ }, ++ { ++ 43, 171, 171, 171, ++ 43, 171, 171, 171, ++ 43, 171, 171, 171, ++ 43, 171, 171, 171 ++ }, ++ { ++ 43, 43, 43, 43, ++ 171, 171, 171, 171, ++ 171, 171, 171, 171, ++ 171, 171, 171, 171 ++ }, ++ { ++ 43, 43, 43, 43, ++ 43, 43, 43, 43, ++ 43, 43, 43, 43, ++ 43, 43, 43, 43 ++ } ++}; ++ ++/** ++ * Table for mapping quant matrix index from the bitstream ++ * into internal quant table number. ++ */ ++static const uint8_t quant_index_to_tab[22] = { ++ 0, 1, 0, 2, 1, 3, 0, 4, 1, 5, 0, 1, 6, 7, 8, // for 8x8 quant matrixes ++ 0, 1, 2, 2, 3, 3, 4 // for 4x4 quant matrixes ++}; ++ ++#endif /* AVCODEC_INDEO4DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo5.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo5.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/indeo5.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/indeo5.c 2012-05-14 14:08:53.872330683 +0200 +@@ -27,7 +27,7 @@ + * Known FOURCCs: 'IV50' + */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" +@@ -90,7 +90,7 @@ + */ + static int decode_gop_header(IVI5DecContext *ctx, AVCodecContext *avctx) + { +- int result, i, p, tile_size, pic_size_indx, mb_size, blk_size; ++ int result, i, p, tile_size, pic_size_indx, mb_size, blk_size, is_scalable; + int quant_mat, blk_size_changed = 0; + IVIBandDesc *band, *band1, *band2; + IVIPicConfig pic_conf; +@@ -112,8 +112,8 @@ + /* num_levels * 3 + 1 */ + pic_conf.luma_bands = get_bits(&ctx->gb, 2) * 3 + 1; + pic_conf.chroma_bands = get_bits1(&ctx->gb) * 3 + 1; +- ctx->is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1; +- if (ctx->is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) { ++ is_scalable = pic_conf.luma_bands != 1 || pic_conf.chroma_bands != 1; ++ if (is_scalable && (pic_conf.luma_bands != 4 || pic_conf.chroma_bands != 1)) { + av_log(avctx, AV_LOG_ERROR, "Scalability: unsupported subdivision! Luma bands: %d, chroma bands: %d\n", + pic_conf.luma_bands, pic_conf.chroma_bands); + return -1; +@@ -151,6 +151,7 @@ + return -1; + } + ctx->pic_conf = pic_conf; ++ ctx->is_scalable = is_scalable; + blk_size_changed = 1; /* force reallocation of the internal structures */ + } + +@@ -453,6 +454,10 @@ + ref_mb = tile->ref_mbs; + offs = tile->ypos * band->pitch + tile->xpos; + ++ if (!ref_mb && ++ ((band->qdelta_present && band->inherit_qdelta) || band->inherit_mv)) ++ return AVERROR_INVALIDDATA; ++ + /* scale factor for motion vectors */ + mv_scale = (ctx->planes[0].bands[0].mb_size >> 3) - (band->mb_size >> 3); + mv_x = mv_y = 0; +@@ -481,7 +486,7 @@ + } + + mb->mv_x = mb->mv_y = 0; /* no motion vector coded */ +- if (band->inherit_mv){ ++ if (band->inherit_mv && ref_mb){ + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); +@@ -492,7 +497,7 @@ + } + } + } else { +- if (band->inherit_mv) { ++ if (band->inherit_mv && ref_mb) { + mb->type = ref_mb->type; /* copy mb_type from corresponding reference mb */ + } else if (ctx->frame_type == FRAMETYPE_INTRA) { + mb->type = 0; /* mb_type is always INTRA for intra-frames */ +@@ -518,7 +523,7 @@ + if (!mb->type) { + mb->mv_x = mb->mv_y = 0; /* there is no motion vector in intra-macroblocks */ + } else { +- if (band->inherit_mv){ ++ if (band->inherit_mv && ref_mb){ + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); +@@ -629,7 +634,7 @@ + FFSWAP(int16_t, band->rv_map->valtab[idx1], band->rv_map->valtab[idx2]); + } + +-#if IVI_DEBUG ++#ifdef DEBUG + if (band->checksum_present) { + uint16_t chksum = ivi_calc_band_checksum(band); + if (chksum != band->checksum) { +@@ -713,6 +718,8 @@ + ctx->pic_conf.tile_height = avctx->height; + ctx->pic_conf.luma_bands = ctx->pic_conf.chroma_bands = 1; + ++ avcodec_get_frame_defaults(&ctx->frame); ++ + result = ff_ivi_init_planes(ctx->planes, &ctx->pic_conf); + if (result) { + av_log(avctx, AV_LOG_ERROR, "Couldn't allocate color planes!\n"); +@@ -757,7 +764,7 @@ + + switch_buffers(ctx); + +- //START_TIMER; ++ //{ START_TIMER; + + if (ctx->frame_type != FRAMETYPE_NULL) { + for (p = 0; p < 3; p++) { +@@ -772,7 +779,7 @@ + } + } + +- //STOP_TIMER("decode_planes"); ++ //STOP_TIMER("decode_planes"); } + + if (ctx->frame.data[0]) + avctx->release_buffer(avctx, &ctx->frame); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/intelh263dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/intelh263dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/intelh263dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/intelh263dec.c 2012-05-14 14:08:53.873330703 +0200 +@@ -46,13 +46,13 @@ + skip_bits1(&s->gb); /* freeze picture release off */ + + format = get_bits(&s->gb, 3); +- if (format != 7) { ++ if (format == 0 || format == 6) { + av_log(s->avctx, AV_LOG_ERROR, "Intel H263 free format not supported\n"); + return -1; + } + s->h263_plus = 0; + +- s->pict_type = FF_I_TYPE + get_bits1(&s->gb); ++ s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); + + s->unrestricted_mv = get_bits1(&s->gb); + s->h263_long_vectors = s->unrestricted_mv; +@@ -64,7 +64,12 @@ + s->obmc= get_bits1(&s->gb); + s->pb_frame = get_bits1(&s->gb); + +- if(format == 7){ ++ if (format < 6) { ++ s->width = h263_format[format][0]; ++ s->height = h263_format[format][1]; ++ s->avctx->sample_aspect_ratio.num = 12; ++ s->avctx->sample_aspect_ratio.den = 11; ++ } else { + format = get_bits(&s->gb, 3); + if(format == 0 || format == 7){ + av_log(s->avctx, AV_LOG_ERROR, "Wrong Intel H263 format\n"); +@@ -88,9 +93,13 @@ + skip_bits1(&s->gb); + skip_bits(&s->gb, 9); // display height + if(ar == 15){ +- skip_bits(&s->gb, 8); // aspect ratio - width +- skip_bits(&s->gb, 8); // aspect ratio - height ++ s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 8); // aspect ratio - width ++ s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 8); // aspect ratio - height ++ } else { ++ s->avctx->sample_aspect_ratio = ff_h263_pixel_aspect[ar]; + } ++ if (s->avctx->sample_aspect_ratio.num == 0) ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid aspect ratio.\n"); + } + + s->chroma_qscale= s->qscale = get_bits(&s->gb, 5); +@@ -116,15 +125,14 @@ + } + + AVCodec ff_h263i_decoder = { +- "h263i", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H263I, +- sizeof(MpegEncContext), +- ff_h263_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "h263i", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H263I, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_h263_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Intel H.263"), + .pix_fmts= ff_pixfmt_list_420, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/internal.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/internal.h 2012-05-14 14:08:53.874330723 +0200 +@@ -25,8 +25,57 @@ + #define AVCODEC_INTERNAL_H + + #include ++ ++#include "libavutil/pixfmt.h" + #include "avcodec.h" + ++typedef struct InternalBuffer { ++ uint8_t *base[AV_NUM_DATA_POINTERS]; ++ uint8_t *data[AV_NUM_DATA_POINTERS]; ++ int linesize[AV_NUM_DATA_POINTERS]; ++ int width; ++ int height; ++ enum PixelFormat pix_fmt; ++ uint8_t **extended_data; ++ int audio_data_size; ++ int nb_channels; ++} InternalBuffer; ++ ++typedef struct AVCodecInternal { ++ /** ++ * internal buffer count ++ * used by default get/release/reget_buffer(). ++ */ ++ int buffer_count; ++ ++ /** ++ * internal buffers ++ * used by default get/release/reget_buffer(). ++ */ ++ InternalBuffer *buffer; ++ ++ /** ++ * Whether the parent AVCodecContext is a copy of the context which had ++ * init() called on it. ++ * This is used by multithreading - shared tables and picture pointers ++ * should be freed from the original context only. ++ */ ++ int is_copy; ++ ++#if FF_API_OLD_DECODE_AUDIO ++ /** ++ * Internal sample count used by avcodec_encode_audio() to fabricate pts. ++ * Can be removed along with avcodec_encode_audio(). ++ */ ++ int sample_count; ++#endif ++} AVCodecInternal; ++ ++struct AVCodecDefault { ++ const uint8_t *key; ++ const uint8_t *value; ++}; ++ + /** + * Determine whether pix_fmt is a hardware accelerated format. + */ +@@ -48,6 +97,43 @@ + */ + int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b); + +-unsigned int ff_toupper4(unsigned int x); ++unsigned int avpriv_toupper4(unsigned int x); ++ ++/** ++ * does needed setup of pkt_pts/pos and such for (re)get_buffer(); ++ */ ++void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic); ++ ++/** ++ * Remove and free all side data from packet. ++ */ ++void ff_packet_free_side_data(AVPacket *pkt); ++ ++int avpriv_lock_avformat(void); ++int avpriv_unlock_avformat(void); ++ ++/** ++ * Maximum size in bytes of extradata. ++ * This value was chosen such that every bit of the buffer is ++ * addressable by a 32-bit signed integer as used by get_bits. ++ */ ++#define FF_MAX_EXTRADATA_SIZE ((1 << 28) - FF_INPUT_BUFFER_PADDING_SIZE) ++ ++/** ++ * Check AVPacket size and/or allocate data. ++ * ++ * Encoders supporting AVCodec.encode2() can use this as a convenience to ++ * ensure the output packet data is large enough, whether provided by the user ++ * or allocated in this function. ++ * ++ * @param avpkt the AVPacket ++ * If avpkt->data is already set, avpkt->size is checked ++ * to ensure it is large enough. ++ * If avpkt->data is NULL, a new buffer is allocated. ++ * All other AVPacket fields will be reset with av_init_packet(). ++ * @param size the minimum required packet size ++ * @return 0 on success, negative error code on failure ++ */ ++int ff_alloc_packet(AVPacket *avpkt, int size); + + #endif /* AVCODEC_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/interplayvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/interplayvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/interplayvideo.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/interplayvideo.c 2012-05-14 14:08:53.876330764 +0200 +@@ -41,19 +41,11 @@ + #include "avcodec.h" + #include "bytestream.h" + #include "dsputil.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + #define PALETTE_COUNT 256 + +-/* debugging support */ +-#define DEBUG_INTERPLAY 0 +-#if DEBUG_INTERPLAY +-#define debug_interplay(x,...) av_log(NULL, AV_LOG_DEBUG, x, __VA_ARGS__) +-#else +-static inline void debug_interplay(const char *format, ...) { } +-#endif +- + typedef struct IpvideoContext { + + AVCodecContext *avctx; +@@ -77,6 +69,7 @@ + int stride; + int upper_motion_limit_offset; + ++ uint32_t pal[256]; + } IpvideoContext; + + #define CHECK_STREAM_PTR(stream_ptr, stream_end, n) \ +@@ -140,7 +133,7 @@ + y = 8 + ((B - 56) / 29); + } + +- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); ++ av_dlog(NULL, " motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); + return copy_from(s, &s->second_last_frame, x, y); + } + +@@ -168,7 +161,7 @@ + y = -( 8 + ((B - 56) / 29)); + } + +- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); ++ av_dlog(NULL, " motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); + return copy_from(s, &s->current_frame, x, y); + } + +@@ -191,7 +184,7 @@ + x = -8 + BL; + y = -8 + BH; + +- debug_interplay (" motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); ++ av_dlog(NULL, " motion byte = %d, (x, y) = (%d, %d)\n", B, x, y); + return copy_from(s, &s->last_frame, x, y); + } + +@@ -206,7 +199,7 @@ + x = *s->stream_ptr++; + y = *s->stream_ptr++; + +- debug_interplay (" motion bytes = %d, %d\n", x, y); ++ av_dlog(NULL, " motion bytes = %d, %d\n", x, y); + return copy_from(s, &s->last_frame, x, y); + } + +@@ -587,7 +580,7 @@ + x = *s->stream_ptr++; + y = *s->stream_ptr++; + +- debug_interplay (" motion bytes = %d, %d\n", x, y); ++ av_dlog(NULL, " motion bytes = %d, %d\n", x, y); + return copy_from(s, &s->second_last_frame, x, y); + } + +@@ -964,12 +957,12 @@ + static int frame = 0; + GetBitContext gb; + +- debug_interplay("------------------ frame %d\n", frame); ++ av_dlog(NULL, "------------------ frame %d\n", frame); + frame++; + + if (!s->is_16bpp) { + /* this is PAL8, so make the palette available */ +- memcpy(s->current_frame.data[1], s->avctx->palctrl->palette, PALETTE_COUNT * 4); ++ memcpy(s->current_frame.data[1], s->pal, AVPALETTE_SIZE); + + s->stride = s->current_frame.linesize[0]; + s->stream_ptr = s->buf + 14; /* data starts 14 bytes in */ +@@ -990,8 +983,8 @@ + for (x = 0; x < s->avctx->width; x += 8) { + opcode = get_bits(&gb, 4); + +- debug_interplay(" block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", +- x, y, opcode, s->stream_ptr); ++ av_dlog(NULL, " block @ (%3d, %3d): encoding 0x%X, data ptr @ %p\n", ++ x, y, opcode, s->stream_ptr); + + if (!s->is_16bpp) { + s->pixel_ptr = s->current_frame.data[0] + x +@@ -1023,15 +1016,12 @@ + + s->is_16bpp = avctx->bits_per_coded_sample == 16; + avctx->pix_fmt = s->is_16bpp ? PIX_FMT_RGB555 : PIX_FMT_PAL8; +- if (!s->is_16bpp && s->avctx->palctrl == NULL) { +- av_log(avctx, AV_LOG_ERROR, " Interplay video: palette expected.\n"); +- return -1; +- } + + dsputil_init(&s->dsp, avctx); + +- /* decoding map contains 4 bits of information per 8x8 block */ +- s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); ++ avcodec_get_frame_defaults(&s->second_last_frame); ++ avcodec_get_frame_defaults(&s->last_frame); ++ avcodec_get_frame_defaults(&s->current_frame); + + s->current_frame.data[0] = s->last_frame.data[0] = + s->second_last_frame.data[0] = NULL; +@@ -1046,7 +1036,9 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + IpvideoContext *s = avctx->priv_data; +- AVPaletteControl *palette_control = avctx->palctrl; ++ ++ /* decoding map contains 4 bits of information per 8x8 block */ ++ s->decoding_map_size = avctx->width * avctx->height / (8 * 8 * 2); + + /* compressed buffer needs to be large enough to at least hold an entire + * decoding map */ +@@ -1063,13 +1055,16 @@ + return -1; + } + +- ipvideo_decode_opcodes(s); +- +- if (!s->is_16bpp && palette_control->palette_changed) { +- palette_control->palette_changed = 0; +- s->current_frame.palette_has_changed = 1; ++ if (!s->is_16bpp) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ if (pal) { ++ s->current_frame.palette_has_changed = 1; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); ++ } + } + ++ ipvideo_decode_opcodes(s); ++ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->current_frame; + +@@ -1098,14 +1093,13 @@ + } + + AVCodec ff_interplay_video_decoder = { +- "interplayvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_INTERPLAY_VIDEO, +- sizeof(IpvideoContext), +- ipvideo_decode_init, +- NULL, +- ipvideo_decode_end, +- ipvideo_decode_frame, +- CODEC_CAP_DR1, ++ .name = "interplayvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_INTERPLAY_VIDEO, ++ .priv_data_size = sizeof(IpvideoContext), ++ .init = ipvideo_decode_init, ++ .close = ipvideo_decode_end, ++ .decode = ipvideo_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE, + .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/intrax8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/intrax8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/intrax8.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/intrax8.c 2012-05-14 14:08:53.877330784 +0200 +@@ -304,7 +304,7 @@ + int quant; + + s->dsp.x8_setup_spatial_compensation(s->dest[chroma], s->edge_emu_buffer, +- s->current_picture.linesize[chroma>0], ++ s->current_picture.f.linesize[chroma>0], + &range, &sum, w->edges); + if(chroma){ + w->orient=w->chroma_orient; +@@ -613,7 +613,7 @@ + dc_level+= (w->predicted_dc*divide_quant + (1<<12) )>>13; + + dsp_x8_put_solidcolor( av_clip_uint8((dc_level*dc_quant+4)>>3), +- s->dest[chroma], s->current_picture.linesize[!!chroma]); ++ s->dest[chroma], s->current_picture.f.linesize[!!chroma]); + + goto block_placed; + } +@@ -637,15 +637,15 @@ + } + + if(w->flat_dc){ +- dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.linesize[!!chroma]); ++ dsp_x8_put_solidcolor(w->predicted_dc, s->dest[chroma], s->current_picture.f.linesize[!!chroma]); + }else{ + s->dsp.x8_spatial_compensation[w->orient]( s->edge_emu_buffer, + s->dest[chroma], +- s->current_picture.linesize[!!chroma] ); ++ s->current_picture.f.linesize[!!chroma] ); + } + if(!zeros_only) + s->dsp.idct_add ( s->dest[chroma], +- s->current_picture.linesize[!!chroma], ++ s->current_picture.f.linesize[!!chroma], + s->block[0] ); + + block_placed: +@@ -656,7 +656,7 @@ + + if(s->loop_filter){ + uint8_t* ptr = s->dest[chroma]; +- int linesize = s->current_picture.linesize[!!chroma]; ++ int linesize = s->current_picture.f.linesize[!!chroma]; + + if(!( (w->edges&2) || ( zeros_only && (w->orient|4)==4 ) )){ + s->dsp.x8_h_loop_filter(ptr, linesize, w->quant); +@@ -671,12 +671,12 @@ + static void x8_init_block_index(MpegEncContext *s){ //FIXME maybe merge with ff_* + //not s->linesize as this would be wrong for field pics + //not that IntraX8 has interlacing support ;) +- const int linesize = s->current_picture.linesize[0]; +- const int uvlinesize= s->current_picture.linesize[1]; ++ const int linesize = s->current_picture.f.linesize[0]; ++ const int uvlinesize = s->current_picture.f.linesize[1]; + +- s->dest[0] = s->current_picture.data[0]; +- s->dest[1] = s->current_picture.data[1]; +- s->dest[2] = s->current_picture.data[2]; ++ s->dest[0] = s->current_picture.f.data[0]; ++ s->dest[1] = s->current_picture.f.data[1]; ++ s->dest[2] = s->current_picture.f.data[2]; + + s->dest[0] += s->mb_y * linesize << 3; + s->dest[1] += ( s->mb_y&(~1) ) * uvlinesize << 2;//chroma blocks are on add rows +@@ -771,7 +771,7 @@ + /*emulate MB info in the relevant tables*/ + s->mbskip_table [mb_xy]=0; + s->mbintra_table[mb_xy]=1; +- s->current_picture.qscale_table[mb_xy]=w->quant; ++ s->current_picture.f.qscale_table[mb_xy] = w->quant; + mb_xy++; + } + s->dest[0]+= 8; +@@ -784,6 +784,6 @@ + error: + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, + (s->mb_x>>1)-1, (s->mb_y>>1)-1, +- (AC_END|DC_END|MV_END) ); ++ ER_MB_END ); + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ituh263dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ituh263dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ituh263dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ituh263dec.c 2012-05-14 14:08:53.879330824 +0200 +@@ -27,9 +27,12 @@ + * h263 decoder. + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + //#define DEBUG + #include + ++#include "libavutil/mathematics.h" + #include "dsputil.h" + #include "avcodec.h" + #include "mpegvideo.h" +@@ -71,7 +74,7 @@ + void ff_h263_show_pict_info(MpegEncContext *s){ + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d %c size:%d rnd:%d%s%s%s%s%s%s%s%s%s %d/%d\n", +- s->qscale, av_get_pict_type_char(s->pict_type), ++ s->qscale, av_get_picture_type_char(s->pict_type), + s->gb.size_in_bits, 1-s->no_rounding, + s->obmc ? " AP" : "", + s->umvplus ? " UMV" : "", +@@ -147,12 +150,12 @@ + } + + /** +- * decodes the group of blocks header or slice header. ++ * Decode the group of blocks header or slice header. + * @return <0 if an error occurred + */ + static int h263_decode_gob_header(MpegEncContext *s) + { +- unsigned int val, gfid, gob_number; ++ unsigned int val, gob_number; + int left; + + /* Check for GOB Start Code */ +@@ -183,12 +186,12 @@ + s->qscale = get_bits(&s->gb, 5); /* SQUANT */ + if(get_bits1(&s->gb)==0) + return -1; +- gfid = get_bits(&s->gb, 2); /* GFID */ ++ skip_bits(&s->gb, 2); /* GFID */ + }else{ + gob_number = get_bits(&s->gb, 5); /* GN */ + s->mb_x= 0; + s->mb_y= s->gob_index* gob_number; +- gfid = get_bits(&s->gb, 2); /* GFID */ ++ skip_bits(&s->gb, 2); /* GFID */ + s->qscale = get_bits(&s->gb, 5); /* GQUANT */ + } + +@@ -202,7 +205,7 @@ + } + + /** +- * finds the next resync_marker ++ * Find the next resync_marker. + * @param p pointer to buffer to scan + * @param end pointer to the end of the buffer + * @return pointer to the next resync_marker, or end if none was found +@@ -223,7 +226,7 @@ + } + + /** +- * decodes the group of blocks / video packet header. ++ * Decode the group of blocks / video packet header. + * @return bit position of the resync_marker, or <0 if none was found + */ + int ff_h263_resync(MpegEncContext *s){ +@@ -270,7 +273,7 @@ + + int h263_decode_motion(MpegEncContext * s, int pred, int f_code) + { +- int code, val, sign, shift, l; ++ int code, val, sign, shift; + code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); + + if (code == 0) +@@ -292,8 +295,7 @@ + + /* modulo decoding */ + if (!s->h263_long_vectors) { +- l = INT_BIT - 5 - f_code; +- val = (val<>l; ++ val = sign_extend(val, 5 + f_code); + } else { + /* horrible h263 long vector mode */ + if (pred < -31 && val < -63) +@@ -306,7 +308,7 @@ + } + + +-/* Decodes RVLC of H.263+ UMV */ ++/* Decode RVLC of H.263+ UMV */ + static int h263p_decode_umotion(MpegEncContext * s, int pred) + { + int code = 0, sign; +@@ -347,25 +349,25 @@ + s->block_index[i]+= 1; + s->mb_x++; + +- assert(s->pict_type == FF_P_TYPE); ++ assert(s->pict_type == AV_PICTURE_TYPE_P); + + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ +- mot_val = s->current_picture.motion_val[0][ s->block_index[0] ]; ++ mot_val = s->current_picture.f.motion_val[0][s->block_index[0]]; + mot_val[0 ]= mot_val[2 ]= + mot_val[0+stride]= mot_val[2+stride]= 0; + mot_val[1 ]= mot_val[3 ]= + mot_val[1+stride]= mot_val[3+stride]= 0; + +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + goto end; + } + cbpc = get_vlc2(&s->gb, ff_h263_inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); + }while(cbpc == 20); + + if(cbpc & 4){ +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + }else{ + get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if (cbpc & 8) { +@@ -377,7 +379,7 @@ + } + + if ((cbpc & 16) == 0) { +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; + /* 16x16 motion prediction */ + mot_val= h263_pred_motion(s, 0, 0, &pred_x, &pred_y); + if (s->umvplus) +@@ -395,7 +397,7 @@ + mot_val[1 ]= mot_val[3 ]= + mot_val[1+stride]= mot_val[3+stride]= my; + } else { +- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; + for(i=0;i<4;i++) { + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); + if (s->umvplus) +@@ -460,7 +462,7 @@ + /* DC coef */ + if(s->codec_id == CODEC_ID_RV10){ + #if CONFIG_RV10_DECODER +- if (s->rv10_version == 3 && s->pict_type == FF_I_TYPE) { ++ if (s->rv10_version == 3 && s->pict_type == AV_PICTURE_TYPE_I) { + int component, diff; + component = (n <= 3 ? 0 : n - 4 + 1); + level = s->last_dc[component]; +@@ -484,7 +486,7 @@ + level = get_bits(&s->gb, 8); + if((level&0x7F) == 0){ + av_log(s->avctx, AV_LOG_ERROR, "illegal dc %d at %d %d\n", level, s->mb_x, s->mb_y); +- if(s->error_recognition >= FF_ER_COMPLIANT) ++ if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) + return -1; + } + if (level == 255) +@@ -608,7 +610,7 @@ + + assert(!s->h263_pred); + +- if (s->pict_type == FF_P_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ +@@ -617,7 +619,7 @@ + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; + s->mb_skipped = !(s->obmc | s->loop_filter); +@@ -650,7 +652,7 @@ + + s->mv_dir = MV_DIR_FORWARD; + if ((cbpc & 16) == 0) { +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; + /* 16x16 motion prediction */ + s->mv_type = MV_TYPE_16X16; + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); +@@ -675,7 +677,7 @@ + if (s->umvplus && (mx - pred_x) == 1 && (my - pred_y) == 1) + skip_bits1(&s->gb); /* Bit stuffing to prevent PSC */ + } else { +- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; + s->mv_type = MV_TYPE_8X8; + for(i=0;i<4;i++) { + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); +@@ -700,11 +702,11 @@ + mot_val[1] = my; + } + } +- } else if(s->pict_type==FF_B_TYPE) { ++ } else if(s->pict_type==AV_PICTURE_TYPE_B) { + int mb_type; + const int stride= s->b8_stride; +- int16_t *mot_val0 = s->current_picture.motion_val[0][ 2*(s->mb_x + s->mb_y*stride) ]; +- int16_t *mot_val1 = s->current_picture.motion_val[1][ 2*(s->mb_x + s->mb_y*stride) ]; ++ int16_t *mot_val0 = s->current_picture.f.motion_val[0][2 * (s->mb_x + s->mb_y * stride)]; ++ int16_t *mot_val1 = s->current_picture.f.motion_val[1][2 * (s->mb_x + s->mb_y * stride)]; + // const int mv_xy= s->mb_x + 1 + s->mb_y * s->mb_stride; + + //FIXME ugly +@@ -787,7 +789,7 @@ + } + } + +- s->current_picture.mb_type[xy]= mb_type; ++ s->current_picture.f.mb_type[xy] = mb_type; + } else { /* I-Frame */ + do{ + cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); +@@ -802,11 +804,11 @@ + dquant = cbpc & 4; + s->mb_intra = 1; + intra: +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + if (s->h263_aic) { + s->ac_pred = get_bits1(&s->gb); + if(s->ac_pred){ +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; + + s->h263_aic_dir = get_bits1(&s->gb); + } +@@ -843,7 +845,7 @@ + if(s->pb_frame && h263_skip_b_part(s, cbpb) < 0) + return -1; + if(s->obmc && !s->mb_intra){ +- if(s->pict_type == FF_P_TYPE && s->mb_x+1mb_width && s->mb_num_left != 1) ++ if(s->pict_type == AV_PICTURE_TYPE_P && s->mb_x+1mb_width && s->mb_num_left != 1) + preview_obmc(s); + } + end: +@@ -852,8 +854,8 @@ + { + int v= show_bits(&s->gb, 16); + +- if(get_bits_count(&s->gb) + 16 > s->gb.size_in_bits){ +- v>>= get_bits_count(&s->gb) + 16 - s->gb.size_in_bits; ++ if (get_bits_left(&s->gb) < 16) { ++ v >>= 16 - get_bits_left(&s->gb); + } + + if(v==0) +@@ -888,7 +890,7 @@ + i = get_bits(&s->gb, 8); /* picture timestamp */ + if( (s->picture_number&~0xFF)+i < s->picture_number) + i+= 256; +- s->current_picture_ptr->pts= ++ s->current_picture_ptr->f.pts = + s->picture_number= (s->picture_number&~0xFF) + i; + + /* PTYPE starts here */ +@@ -921,7 +923,7 @@ + if (!width) + return -1; + +- s->pict_type = FF_I_TYPE + get_bits1(&s->gb); ++ s->pict_type = AV_PICTURE_TYPE_I + get_bits1(&s->gb); + + s->h263_long_vectors = get_bits1(&s->gb); + +@@ -985,11 +987,11 @@ + /* MPPTYPE */ + s->pict_type = get_bits(&s->gb, 3); + switch(s->pict_type){ +- case 0: s->pict_type= FF_I_TYPE;break; +- case 1: s->pict_type= FF_P_TYPE;break; +- case 2: s->pict_type= FF_P_TYPE;s->pb_frame = 3;break; +- case 3: s->pict_type= FF_B_TYPE;break; +- case 7: s->pict_type= FF_I_TYPE;break; //ZYGO ++ case 0: s->pict_type= AV_PICTURE_TYPE_I;break; ++ case 1: s->pict_type= AV_PICTURE_TYPE_P;break; ++ case 2: s->pict_type= AV_PICTURE_TYPE_P;s->pb_frame = 3;break; ++ case 3: s->pict_type= AV_PICTURE_TYPE_B;break; ++ case 7: s->pict_type= AV_PICTURE_TYPE_I;break; //ZYGO + default: + return -1; + } +@@ -1112,7 +1114,7 @@ + } + + ff_h263_show_pict_info(s); +- if (s->pict_type == FF_I_TYPE && s->codec_tag == AV_RL32("ZYGO")){ ++ if (s->pict_type == AV_PICTURE_TYPE_I && s->codec_tag == AV_RL32("ZYGO")){ + int i,j; + for(i=0; i<85; i++) av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); + av_log(s->avctx, AV_LOG_DEBUG, "\n"); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ituh263enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ituh263enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ituh263enc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ituh263enc.c 2012-05-14 14:08:53.880330844 +0200 +@@ -126,7 +126,7 @@ + coded_frame_rate= 1800000; + coded_frame_rate_base= (1000+best_clock_code)*best_divisor; + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + + /* Update the pointer to last GOB */ + s->ptr_lastgob = put_bits_ptr(&s->pb); +@@ -145,7 +145,7 @@ + if (!s->h263_plus) { + /* H.263v1 */ + put_bits(&s->pb, 3, format); +- put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); ++ put_bits(&s->pb, 1, (s->pict_type == AV_PICTURE_TYPE_P)); + /* By now UMV IS DISABLED ON H.263v1, since the restrictions + of H.263v1 UMV implies to check the predicted MV after + calculation of the current MB to see if we're on the limits */ +@@ -181,7 +181,7 @@ + put_bits(&s->pb,1,1); /* "1" to prevent start code emulation */ + put_bits(&s->pb,3,0); /* Reserved */ + +- put_bits(&s->pb, 3, s->pict_type == FF_P_TYPE); ++ put_bits(&s->pb, 3, s->pict_type == AV_PICTURE_TYPE_P); + + put_bits(&s->pb,1,0); /* Reference Picture Resampling: off */ + put_bits(&s->pb,1,0); /* Reduced-Resolution Update: off */ +@@ -260,12 +260,12 @@ + put_bits(&s->pb, 1, 1); + put_bits(&s->pb, 5, s->qscale); /* GQUANT */ + put_bits(&s->pb, 1, 1); +- put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ ++ put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */ + }else{ + int gob_number= mb_line / s->gob_index; + + put_bits(&s->pb, 5, gob_number); /* GN */ +- put_bits(&s->pb, 2, s->pict_type == FF_I_TYPE); /* GFID */ ++ put_bits(&s->pb, 2, s->pict_type == AV_PICTURE_TYPE_I); /* GFID */ + put_bits(&s->pb, 5, s->qscale); /* GQUANT */ + } + } +@@ -275,7 +275,7 @@ + */ + void ff_clean_h263_qscales(MpegEncContext *s){ + int i; +- int8_t * const qscale_table= s->current_picture.qscale_table; ++ int8_t * const qscale_table = s->current_picture.f.qscale_table; + + ff_init_qscale_tab(s); + +@@ -302,7 +302,7 @@ + static const int dquant_code[5]= {1,0,9,2,3}; + + /** +- * encodes a 8x8 block. ++ * Encode an 8x8 block. + * @param block the 8x8 block + * @param n block index (0-3 are luma, 4-5 are chroma) + */ +@@ -529,8 +529,8 @@ + /* motion vectors: 8x8 mode*/ + h263_pred_motion(s, i, 0, &pred_x, &pred_y); + +- motion_x= s->current_picture.motion_val[0][ s->block_index[i] ][0]; +- motion_y= s->current_picture.motion_val[0][ s->block_index[i] ][1]; ++ motion_x = s->current_picture.f.motion_val[0][s->block_index[i]][0]; ++ motion_y = s->current_picture.f.motion_val[0][s->block_index[i]][1]; + if (!s->umvplus) { + ff_h263_encode_motion_vector(s, motion_x - pred_x, + motion_y - pred_y, 1); +@@ -607,7 +607,7 @@ + } + + cbpc = cbp & 3; +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + if(s->dquant) cbpc+=4; + put_bits(&s->pb, + ff_h263_intra_MCBPC_bits[cbpc], +@@ -657,7 +657,7 @@ + + void ff_h263_encode_motion(MpegEncContext * s, int val, int f_code) + { +- int range, l, bit_size, sign, code, bits; ++ int range, bit_size, sign, code, bits; + + if (val == 0) { + /* zero vector */ +@@ -667,8 +667,7 @@ + bit_size = f_code - 1; + range = 1 << bit_size; + /* modulo encoding */ +- l= INT_BIT - 6 - bit_size; +- val = (val<>l; ++ val = sign_extend(val, 6 + bit_size); + sign = val>>31; + val= (val^sign)-sign; + sign&=1; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_common.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_common.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_common.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_common.c 2012-05-14 14:08:53.882330884 +0200 +@@ -26,7 +26,7 @@ + * Indeo5 decoders. + */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "get_bits.h" + #include "ivi_common.h" +@@ -260,6 +260,8 @@ + t_width >>= 1; + t_height >>= 1; + } ++ if(t_width<=0 || t_height<=0) ++ return AVERROR(EINVAL); + + for (b = 0; b < planes[p].num_bands; b++) { + band = &planes[p].bands[b]; +@@ -418,8 +420,8 @@ + break; + pos = band->scan[scan_pos]; + +- if (IVI_DEBUG && !val) +- av_log(NULL, AV_LOG_ERROR, "Val = 0 encountered!\n"); ++ if (!val) ++ av_dlog(NULL, "Val = 0 encountered!\n"); + + q = (base_tab[pos] * quant) >> 9; + if (q > 1) +@@ -506,7 +508,7 @@ + if (band->inherit_qdelta && ref_mb) + mb->q_delta = ref_mb->q_delta; + +- if (band->inherit_mv) { ++ if (band->inherit_mv && ref_mb) { + /* motion vector inheritance */ + if (mv_scale) { + mb->mv_x = ivi_scale_mv(ref_mb->mv_x, mv_scale); +@@ -563,7 +565,7 @@ + } + + +-#if IVI_DEBUG ++#ifdef DEBUG + uint16_t ivi_calc_band_checksum (IVIBandDesc *band) + { + int x, y; +@@ -611,6 +613,9 @@ + const int16_t *src = plane->bands[0].buf; + uint32_t pitch = plane->bands[0].pitch; + ++ if (!src) ++ return; ++ + for (y = 0; y < plane->height; y++) { + for (x = 0; x < plane->width; x++) + dst[x] = av_clip_uint8(src[x] + 128); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_common.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_common.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_common.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_common.h 2012-05-14 14:08:53.882330884 +0200 +@@ -33,8 +33,6 @@ + #include "get_bits.h" + #include + +-#define IVI_DEBUG 0 +- + #define IVI_VLC_BITS 13 ///< max number of bits of the ivi's huffman codes + + /** +@@ -53,7 +51,7 @@ + /// or "7" for custom one + VLC *tab; /// pointer to the table associated with tab_sel + +- //! the following are used only when tab_sel == 7 ++ /// the following are used only when tab_sel == 7 + IVIHuffDesc cust_desc; /// custom Huffman codebook descriptor + VLC cust_tab; /// vlc table for custom codebook + } IVIHuffTab; +@@ -197,10 +195,10 @@ + /** compare some properties of two pictures */ + static inline int ivi_pic_config_cmp(IVIPicConfig *str1, IVIPicConfig *str2) + { +- return (str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height || +- str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height || +- str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height || +- str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands); ++ return str1->pic_width != str2->pic_width || str1->pic_height != str2->pic_height || ++ str1->chroma_width != str2->chroma_width || str1->chroma_height != str2->chroma_height || ++ str1->tile_width != str2->tile_width || str1->tile_height != str2->tile_height || ++ str1->luma_bands != str2->luma_bands || str1->chroma_bands != str2->chroma_bands; + } + + /** calculate number of tiles in a stride */ +@@ -340,7 +338,6 @@ + */ + void ff_ivi_output_plane(IVIPlaneDesc *plane, uint8_t *dst, int dst_pitch); + +-#if IVI_DEBUG + /** + * Calculate band checksum from band data. + */ +@@ -350,6 +347,5 @@ + * Verify that band data lies in range. + */ + int ivi_check_band (IVIBandDesc *band, const uint8_t *ref, int pitch); +-#endif + + #endif /* AVCODEC_IVI_COMMON_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_dsp.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_dsp.c 2012-05-14 14:08:53.884330925 +0200 +@@ -1,7 +1,7 @@ + /* + * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * +- * Copyright (c) 2009 Maxim Poliakovski ++ * Copyright (c) 2009-2011 Maxim Poliakovski + * + * This file is part of FFmpeg. + * +@@ -178,6 +178,153 @@ + } + } + ++void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, ++ const int dst_pitch, const int num_bands) ++{ ++ int x, y, indx, b0, b1, b2, b3, p0, p1, p2, p3; ++ const IDWTELEM *b0_ptr, *b1_ptr, *b2_ptr, *b3_ptr; ++ int32_t pitch; ++ ++ /* all bands should have the same pitch */ ++ pitch = plane->bands[0].pitch; ++ ++ /* get pointers to the wavelet bands */ ++ b0_ptr = plane->bands[0].buf; ++ b1_ptr = plane->bands[1].buf; ++ b2_ptr = plane->bands[2].buf; ++ b3_ptr = plane->bands[3].buf; ++ ++ for (y = 0; y < plane->height; y += 2) { ++ for (x = 0, indx = 0; x < plane->width; x += 2, indx++) { ++ /* load coefficients */ ++ b0 = b0_ptr[indx]; //should be: b0 = (num_bands > 0) ? b0_ptr[indx] : 0; ++ b1 = b1_ptr[indx]; //should be: b1 = (num_bands > 1) ? b1_ptr[indx] : 0; ++ b2 = b2_ptr[indx]; //should be: b2 = (num_bands > 2) ? b2_ptr[indx] : 0; ++ b3 = b3_ptr[indx]; //should be: b3 = (num_bands > 3) ? b3_ptr[indx] : 0; ++ ++ /* haar wavelet recomposition */ ++ p0 = (b0 + b1 + b2 + b3 + 2) >> 2; ++ p1 = (b0 + b1 - b2 - b3 + 2) >> 2; ++ p2 = (b0 - b1 + b2 - b3 + 2) >> 2; ++ p3 = (b0 - b1 - b2 + b3 + 2) >> 2; ++ ++ /* bias, convert and output four pixels */ ++ dst[x] = av_clip_uint8(p0 + 128); ++ dst[x + 1] = av_clip_uint8(p1 + 128); ++ dst[dst_pitch + x] = av_clip_uint8(p2 + 128); ++ dst[dst_pitch + x + 1] = av_clip_uint8(p3 + 128); ++ }// for x ++ ++ dst += dst_pitch << 1; ++ ++ b0_ptr += pitch; ++ b1_ptr += pitch; ++ b2_ptr += pitch; ++ b3_ptr += pitch; ++ }// for y ++} ++ ++/** butterfly operation for the inverse Haar transform */ ++#define IVI_HAAR_BFLY(s1, s2, o1, o2, t) \ ++ t = (s1 - s2) >> 1;\ ++ o1 = (s1 + s2) >> 1;\ ++ o2 = t;\ ++ ++/** inverse 8-point Haar transform */ ++#define INV_HAAR8(s1, s5, s3, s7, s2, s4, s6, s8,\ ++ d1, d2, d3, d4, d5, d6, d7, d8,\ ++ t0, t1, t2, t3, t4, t5, t6, t7, t8) {\ ++ t1 = s1 << 1; t5 = s5 << 1;\ ++ IVI_HAAR_BFLY(t1, t5, t1, t5, t0); IVI_HAAR_BFLY(t1, s3, t1, t3, t0);\ ++ IVI_HAAR_BFLY(t5, s7, t5, t7, t0); IVI_HAAR_BFLY(t1, s2, t1, t2, t0);\ ++ IVI_HAAR_BFLY(t3, s4, t3, t4, t0); IVI_HAAR_BFLY(t5, s6, t5, t6, t0);\ ++ IVI_HAAR_BFLY(t7, s8, t7, t8, t0);\ ++ d1 = COMPENSATE(t1);\ ++ d2 = COMPENSATE(t2);\ ++ d3 = COMPENSATE(t3);\ ++ d4 = COMPENSATE(t4);\ ++ d5 = COMPENSATE(t5);\ ++ d6 = COMPENSATE(t6);\ ++ d7 = COMPENSATE(t7);\ ++ d8 = COMPENSATE(t8); } ++ ++/** inverse 4-point Haar transform */ ++#define INV_HAAR4(s1, s3, s5, s7) {\ ++ HAAR_BFLY(s1, s5); HAAR_BFLY(s1, s3); HAAR_BFLY(s5, s7);\ ++ s1 = COMPENSATE(s1);\ ++ s3 = COMPENSATE(s3);\ ++ s5 = COMPENSATE(s5);\ ++ s7 = COMPENSATE(s7); } ++ ++void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch, ++ const uint8_t *flags) ++{ ++ int i, shift, sp1, sp2, sp3, sp4; ++ const int32_t *src; ++ int32_t *dst; ++ int tmp[64]; ++ int t0, t1, t2, t3, t4, t5, t6, t7, t8; ++ ++ /* apply the InvHaar8 to all columns */ ++#define COMPENSATE(x) (x) ++ src = in; ++ dst = tmp; ++ for (i = 0; i < 8; i++) { ++ if (flags[i]) { ++ /* pre-scaling */ ++ shift = !(i & 4); ++ sp1 = src[ 0] << shift; ++ sp2 = src[ 8] << shift; ++ sp3 = src[16] << shift; ++ sp4 = src[24] << shift; ++ INV_HAAR8( sp1, sp2, sp3, sp4, ++ src[32], src[40], src[48], src[56], ++ dst[ 0], dst[ 8], dst[16], dst[24], ++ dst[32], dst[40], dst[48], dst[56], ++ t0, t1, t2, t3, t4, t5, t6, t7, t8); ++ } else ++ dst[ 0] = dst[ 8] = dst[16] = dst[24] = ++ dst[32] = dst[40] = dst[48] = dst[56] = 0; ++ ++ src++; ++ dst++; ++ } ++#undef COMPENSATE ++ ++ /* apply the InvHaar8 to all rows */ ++#define COMPENSATE(x) (x) ++ src = tmp; ++ for (i = 0; i < 8; i++) { ++ if ( !src[0] && !src[1] && !src[2] && !src[3] ++ && !src[4] && !src[5] && !src[6] && !src[7]) { ++ memset(out, 0, 8 * sizeof(out[0])); ++ } else { ++ INV_HAAR8(src[0], src[1], src[2], src[3], ++ src[4], src[5], src[6], src[7], ++ out[0], out[1], out[2], out[3], ++ out[4], out[5], out[6], out[7], ++ t0, t1, t2, t3, t4, t5, t6, t7, t8); ++ } ++ src += 8; ++ out += pitch; ++ } ++#undef COMPENSATE ++} ++ ++void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch, ++ int blk_size) ++{ ++ int x, y; ++ int16_t dc_coeff; ++ ++ dc_coeff = (*in + 0) >> 3; ++ ++ for (y = 0; y < blk_size; out += pitch, y++) { ++ for (x = 0; x < blk_size; x++) ++ out[x] = dc_coeff; ++ } ++} ++ + /** butterfly operation for the inverse slant transform */ + #define IVI_SLANT_BFLY(s1, s2, o1, o2, t) \ + t = s1 - s2;\ +@@ -461,7 +608,7 @@ + #define OP_PUT(a, b) (a) = (b) + #define OP_ADD(a, b) (a) += (b) + +-IVI_MC_TEMPLATE(8, _no_delta, OP_PUT); +-IVI_MC_TEMPLATE(8, _delta, OP_ADD); +-IVI_MC_TEMPLATE(4, _no_delta, OP_PUT); +-IVI_MC_TEMPLATE(4, _delta, OP_ADD); ++IVI_MC_TEMPLATE(8, _no_delta, OP_PUT) ++IVI_MC_TEMPLATE(8, _delta, OP_ADD) ++IVI_MC_TEMPLATE(4, _no_delta, OP_PUT) ++IVI_MC_TEMPLATE(4, _delta, OP_ADD) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ivi_dsp.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ivi_dsp.h 2012-05-14 14:08:53.885330945 +0200 +@@ -1,7 +1,7 @@ + /* + * DSP functions for Indeo Video Interactive codecs (Indeo4 and Indeo5) + * +- * Copyright (c) 2009 Maxim Poliakovski ++ * Copyright (c) 2009-2011 Maxim Poliakovski + * + * This file is part of FFmpeg. + * +@@ -44,6 +44,43 @@ + const int dst_pitch, const int num_bands); + + /** ++ * Haar wavelet recomposition filter for Indeo 4 ++ * ++ * @param[in] plane pointer to the descriptor of the plane being processed ++ * @param[out] dst pointer to the destination buffer ++ * @param[in] dst_pitch pitch of the destination buffer ++ * @param[in] num_bands number of wavelet bands to be processed ++ */ ++void ff_ivi_recompose_haar(const IVIPlaneDesc *plane, uint8_t *dst, ++ const int dst_pitch, const int num_bands); ++ ++/** ++ * two-dimensional inverse Haar 8x8 transform for Indeo 4 ++ * ++ * @param[in] in pointer to the vector of transform coefficients ++ * @param[out] out pointer to the output buffer (frame) ++ * @param[in] pitch pitch to move to the next y line ++ * @param[in] flags pointer to the array of column flags: ++ * != 0 - non_empty column, 0 - empty one ++ * (this array must be filled by caller) ++ */ ++void ff_ivi_inverse_haar_8x8(const int32_t *in, int16_t *out, uint32_t pitch, ++ const uint8_t *flags); ++ ++/** ++ * DC-only two-dimensional inverse Haar transform for Indeo 4. ++ * Performing the inverse transform in this case is equivalent to ++ * spreading DC_coeff >> 3 over the whole block. ++ * ++ * @param[in] in pointer to the dc coefficient ++ * @param[out] out pointer to the output buffer (frame) ++ * @param[in] pitch pitch to move to the next y line ++ * @param[in] blk_size transform block size ++ */ ++void ff_ivi_dc_haar_2d(const int32_t *in, int16_t *out, uint32_t pitch, ++ int blk_size); ++ ++/** + * two-dimensional inverse slant 8x8 transform + * + * @param[in] in pointer to the vector of transform coefficients +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k.c 2012-05-14 14:08:53.886330965 +0200 +@@ -0,0 +1,392 @@ ++/* ++ * JPEG2000 encoder and decoder common functions ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * JPEG2000 image encoder and decoder common functions ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++ ++#include "avcodec.h" ++#include "j2k.h" ++ ++#define SHL(a, n) ((n)>=0 ? (a) << (n) : (a) >> -(n)) ++ ++#if 0 ++void ff_j2k_printv(int *tab, int l) ++{ ++ int i; ++ for (i = 0; i < l; i++) ++ printf("%.3d ", tab[i]); ++ printf("\n"); ++} ++ ++void ff_j2k_printu(uint8_t *tab, int l) ++{ ++ int i; ++ for (i = 0; i < l; i++) ++ printf("%.3hd ", tab[i]); ++ printf("\n"); ++} ++#endif ++ ++/* tag tree routines */ ++ ++/** allocate the memory for tag tree */ ++ ++static int tag_tree_size(int w, int h) ++{ ++ int res = 0; ++ while (w > 1 || h > 1){ ++ res += w * h; ++ w = (w+1) >> 1; ++ h = (h+1) >> 1; ++ } ++ return res + 1; ++} ++ ++J2kTgtNode *ff_j2k_tag_tree_init(int w, int h) ++{ ++ int pw = w, ph = h; ++ J2kTgtNode *res, *t, *t2; ++ ++ t = res = av_mallocz(tag_tree_size(w, h)*sizeof(J2kTgtNode)); ++ ++ if (res == NULL) ++ return NULL; ++ ++ while (w > 1 || h > 1){ ++ int i, j; ++ pw = w; ++ ph = h; ++ ++ w = (w+1) >> 1; ++ h = (h+1) >> 1; ++ t2 = t + pw*ph; ++ ++ for (i = 0; i < ph; i++) ++ for (j = 0; j < pw; j++){ ++ t[i*pw + j].parent = &t2[(i>>1)*w + (j>>1)]; ++ } ++ t = t2; ++ } ++ t[0].parent = NULL; ++ return res; ++} ++ ++static void tag_tree_zero(J2kTgtNode *t, int w, int h) ++{ ++ int i, siz = tag_tree_size(w, h); ++ ++ for (i = 0; i < siz; i++){ ++ t[i].val = 0; ++ t[i].vis = 0; ++ } ++} ++ ++uint8_t ff_j2k_nbctxno_lut[256][4]; ++ ++static int getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol) ++{ ++ int h, v, d; ++ ++ h = ((flag & J2K_T1_SIG_E) ? 1:0)+ ++ ((flag & J2K_T1_SIG_W) ? 1:0); ++ v = ((flag & J2K_T1_SIG_N) ? 1:0); ++ if (!vert_causal_ctx_csty_symbol) ++ v = v + ((flag & J2K_T1_SIG_S) ? 1:0); ++ d = ((flag & J2K_T1_SIG_NE) ? 1:0)+ ++ ((flag & J2K_T1_SIG_NW) ? 1:0); ++ if (!vert_causal_ctx_csty_symbol) ++ d = d + ((flag & J2K_T1_SIG_SE) ? 1:0)+ ++ ((flag & J2K_T1_SIG_SW) ? 1:0); ++ if (bandno < 3){ ++ if (bandno == 1) ++ FFSWAP(int, h, v); ++ if (h == 2) return 8; ++ if (h == 1){ ++ if (v >= 1) return 7; ++ if (d >= 1) return 6; ++ return 5; ++ } ++ if (v == 2) return 4; ++ if (v == 1) return 3; ++ if (d >= 2) return 2; ++ if (d == 1) return 1; ++ return 0; ++ } else{ ++ if (d >= 3) return 8; ++ if (d == 2){ ++ if (h+v >= 1) return 7; ++ return 6; ++ } ++ if (d == 1){ ++ if (h+v >= 2) return 5; ++ if (h+v == 1) return 4; ++ return 3; ++ } ++ if (h+v >= 2) return 2; ++ if (h+v == 1) return 1; ++ return 0; ++ } ++ assert(0); ++} ++ ++uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16]; ++ ++static int getsgnctxno(int flag, uint8_t *xorbit) ++{ ++ int vcontrib, hcontrib; ++ static const int contribtab[3][3] = {{0, -1, 1}, {-1, -1, 0}, {1, 0, 1}}; ++ static const int ctxlbltab[3][3] = {{13, 12, 11}, {10, 9, 10}, {11, 12, 13}}; ++ static const int xorbittab[3][3] = {{1, 1, 1,}, {1, 0, 0}, {0, 0, 0}}; ++ ++ hcontrib = contribtab[flag & J2K_T1_SIG_E ? flag & J2K_T1_SGN_E ? 1:2:0] ++ [flag & J2K_T1_SIG_W ? flag & J2K_T1_SGN_W ? 1:2:0]+1; ++ vcontrib = contribtab[flag & J2K_T1_SIG_S ? flag & J2K_T1_SGN_S ? 1:2:0] ++ [flag & J2K_T1_SIG_N ? flag & J2K_T1_SGN_N ? 1:2:0]+1; ++ *xorbit = xorbittab[hcontrib][vcontrib]; ++ return ctxlbltab[hcontrib][vcontrib]; ++} ++ ++void ff_j2k_init_tier1_luts(void) ++{ ++ int i, j; ++ for (i = 0; i < 256; i++) ++ for (j = 0; j < 4; j++) ++ ff_j2k_nbctxno_lut[i][j] = getnbctxno(i, j, 0); ++ for (i = 0; i < 16; i++) ++ for (j = 0; j < 16; j++) ++ ff_j2k_sgnctxno_lut[i][j] = getsgnctxno(i + (j << 8), &ff_j2k_xorbit_lut[i][j]); ++} ++ ++void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative) ++{ ++ x++; y++; ++ t1->flags[y][x] |= J2K_T1_SIG; ++ if (negative){ ++ t1->flags[y][x+1] |= J2K_T1_SIG_W | J2K_T1_SGN_W; ++ t1->flags[y][x-1] |= J2K_T1_SIG_E | J2K_T1_SGN_E; ++ t1->flags[y+1][x] |= J2K_T1_SIG_N | J2K_T1_SGN_N; ++ t1->flags[y-1][x] |= J2K_T1_SIG_S | J2K_T1_SGN_S; ++ } else{ ++ t1->flags[y][x+1] |= J2K_T1_SIG_W; ++ t1->flags[y][x-1] |= J2K_T1_SIG_E; ++ t1->flags[y+1][x] |= J2K_T1_SIG_N; ++ t1->flags[y-1][x] |= J2K_T1_SIG_S; ++ } ++ t1->flags[y+1][x+1] |= J2K_T1_SIG_NW; ++ t1->flags[y+1][x-1] |= J2K_T1_SIG_NE; ++ t1->flags[y-1][x+1] |= J2K_T1_SIG_SW; ++ t1->flags[y-1][x-1] |= J2K_T1_SIG_SE; ++} ++ ++int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy) ++{ ++ int reslevelno, bandno, gbandno = 0, ret, i, j, csize = 1; ++ ++ if (ret=ff_j2k_dwt_init(&comp->dwt, comp->coord, codsty->nreslevels-1, codsty->transform)) ++ return ret; ++ for (i = 0; i < 2; i++) ++ csize *= comp->coord[i][1] - comp->coord[i][0]; ++ ++ comp->data = av_malloc(csize * sizeof(int)); ++ if (!comp->data) ++ return AVERROR(ENOMEM); ++ comp->reslevel = av_malloc(codsty->nreslevels * sizeof(J2kResLevel)); ++ ++ if (!comp->reslevel) ++ return AVERROR(ENOMEM); ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ int declvl = codsty->nreslevels - reslevelno; ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ ++ for (i = 0; i < 2; i++) ++ for (j = 0; j < 2; j++) ++ reslevel->coord[i][j] = ++ ff_j2k_ceildivpow2(comp->coord[i][j], declvl - 1); ++ ++ if (reslevelno == 0) ++ reslevel->nbands = 1; ++ else ++ reslevel->nbands = 3; ++ ++ if (reslevel->coord[0][1] == reslevel->coord[0][0]) ++ reslevel->num_precincts_x = 0; ++ else ++ reslevel->num_precincts_x = ff_j2k_ceildivpow2(reslevel->coord[0][1], codsty->log2_prec_width) ++ - (reslevel->coord[0][0] >> codsty->log2_prec_width); ++ ++ if (reslevel->coord[1][1] == reslevel->coord[1][0]) ++ reslevel->num_precincts_y = 0; ++ else ++ reslevel->num_precincts_y = ff_j2k_ceildivpow2(reslevel->coord[1][1], codsty->log2_prec_height) ++ - (reslevel->coord[1][0] >> codsty->log2_prec_height); ++ ++ reslevel->band = av_malloc(reslevel->nbands * sizeof(J2kBand)); ++ if (!reslevel->band) ++ return AVERROR(ENOMEM); ++ for (bandno = 0; bandno < reslevel->nbands; bandno++, gbandno++){ ++ J2kBand *band = reslevel->band + bandno; ++ int cblkno, precx, precy, precno; ++ int x0, y0, x1, y1; ++ int xi0, yi0, xi1, yi1; ++ int cblkperprecw, cblkperprech; ++ ++ if (qntsty->quantsty != J2K_QSTY_NONE){ ++ const static uint8_t lut_gain[2][4] = {{0, 0, 0, 0}, {0, 1, 1, 2}}; ++ int numbps; ++ ++ numbps = cbps + lut_gain[codsty->transform][bandno + reslevelno>0]; ++ band->stepsize = SHL(2048 + qntsty->mant[gbandno], 2 + numbps - qntsty->expn[gbandno]); ++ } else ++ band->stepsize = 1 << 13; ++ ++ if (reslevelno == 0){ // the same everywhere ++ band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width-1); ++ band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height-1); ++ for (i = 0; i < 2; i++) ++ for (j = 0; j < 2; j++) ++ band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], declvl-1); ++ } else{ ++ band->codeblock_width = 1 << FFMIN(codsty->log2_cblk_width, codsty->log2_prec_width); ++ band->codeblock_height = 1 << FFMIN(codsty->log2_cblk_height, codsty->log2_prec_height); ++ ++ for (i = 0; i < 2; i++) ++ for (j = 0; j < 2; j++) ++ band->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j] - (((bandno+1>>i)&1) << declvl-1), declvl); ++ } ++ band->cblknx = ff_j2k_ceildiv(band->coord[0][1], band->codeblock_width) - band->coord[0][0] / band->codeblock_width; ++ band->cblkny = ff_j2k_ceildiv(band->coord[1][1], band->codeblock_height) - band->coord[1][0] / band->codeblock_height; ++ ++ for (j = 0; j < 2; j++) ++ band->coord[0][j] = ff_j2k_ceildiv(band->coord[0][j], dx); ++ for (j = 0; j < 2; j++) ++ band->coord[1][j] = ff_j2k_ceildiv(band->coord[1][j], dy); ++ ++ band->cblknx = ff_j2k_ceildiv(band->cblknx, dx); ++ band->cblkny = ff_j2k_ceildiv(band->cblkny, dy); ++ ++ band->cblk = av_malloc(band->cblknx * band->cblkny * sizeof(J2kCblk)); ++ if (!band->cblk) ++ return AVERROR(ENOMEM); ++ band->prec = av_malloc(reslevel->num_precincts_x * reslevel->num_precincts_y * sizeof(J2kPrec)); ++ if (!band->prec) ++ return AVERROR(ENOMEM); ++ ++ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ ++ J2kCblk *cblk = band->cblk + cblkno; ++ cblk->zero = 0; ++ cblk->lblock = 3; ++ cblk->length = 0; ++ cblk->lengthinc = 0; ++ cblk->npasses = 0; ++ } ++ ++ y0 = band->coord[1][0]; ++ y1 = ((band->coord[1][0] + (1<log2_prec_height)) & ~((1<log2_prec_height)-1)) - y0; ++ yi0 = 0; ++ yi1 = ff_j2k_ceildivpow2(y1 - y0, codsty->log2_cblk_height) << codsty->log2_cblk_height; ++ yi1 = FFMIN(yi1, band->cblkny); ++ cblkperprech = 1<<(codsty->log2_prec_height - codsty->log2_cblk_height); ++ for (precy = 0, precno = 0; precy < reslevel->num_precincts_y; precy++){ ++ for (precx = 0; precx < reslevel->num_precincts_x; precx++, precno++){ ++ band->prec[precno].yi0 = yi0; ++ band->prec[precno].yi1 = yi1; ++ } ++ yi1 += cblkperprech; ++ yi0 = yi1 - cblkperprech; ++ yi1 = FFMIN(yi1, band->cblkny); ++ } ++ x0 = band->coord[0][0]; ++ x1 = ((band->coord[0][0] + (1<log2_prec_width)) & ~((1<log2_prec_width)-1)) - x0; ++ xi0 = 0; ++ xi1 = ff_j2k_ceildivpow2(x1 - x0, codsty->log2_cblk_width) << codsty->log2_cblk_width; ++ xi1 = FFMIN(xi1, band->cblknx); ++ ++ cblkperprecw = 1<<(codsty->log2_prec_width - codsty->log2_cblk_width); ++ for (precx = 0, precno = 0; precx < reslevel->num_precincts_x; precx++){ ++ for (precy = 0; precy < reslevel->num_precincts_y; precy++, precno = 0){ ++ J2kPrec *prec = band->prec + precno; ++ prec->xi0 = xi0; ++ prec->xi1 = xi1; ++ prec->cblkincl = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0, ++ prec->yi1 - prec->yi0); ++ prec->zerobits = ff_j2k_tag_tree_init(prec->xi1 - prec->xi0, ++ prec->yi1 - prec->yi0); ++ if (!prec->cblkincl || !prec->zerobits) ++ return AVERROR(ENOMEM); ++ ++ } ++ xi1 += cblkperprecw; ++ xi0 = xi1 - cblkperprecw; ++ xi1 = FFMIN(xi1, band->cblknx); ++ } ++ } ++ } ++ return 0; ++} ++ ++void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty) ++{ ++ int reslevelno, bandno, cblkno, precno; ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ J2kResLevel *rlevel = comp->reslevel + reslevelno; ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ for(precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){ ++ J2kPrec *prec = band->prec + precno; ++ tag_tree_zero(prec->zerobits, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); ++ tag_tree_zero(prec->cblkincl, prec->xi1 - prec->xi0, prec->yi1 - prec->yi0); ++ } ++ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ ++ J2kCblk *cblk = band->cblk + cblkno; ++ cblk->length = 0; ++ cblk->lblock = 3; ++ } ++ } ++ } ++} ++ ++void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty) ++{ ++ int reslevelno, bandno, precno; ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ ++ for (bandno = 0; bandno < reslevel->nbands ; bandno++){ ++ J2kBand *band = reslevel->band + bandno; ++ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){ ++ J2kPrec *prec = band->prec + precno; ++ av_freep(&prec->zerobits); ++ av_freep(&prec->cblkincl); ++ } ++ av_freep(&band->cblk); ++ av_freep(&band->prec); ++ } ++ av_freep(&reslevel->band); ++ } ++ ++ ff_j2k_dwt_destroy(&comp->dwt); ++ av_freep(&comp->reslevel); ++ av_freep(&comp->data); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2kdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2kdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2kdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2kdec.c 2012-05-14 14:08:53.892331086 +0200 +@@ -0,0 +1,1090 @@ ++/* ++ * JPEG2000 image decoder ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * JPEG2000 image decoder ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "avcodec.h" ++#include "bytestream.h" ++#include "j2k.h" ++#include "libavutil/common.h" ++ ++#define JP2_SIG_TYPE 0x6A502020 ++#define JP2_SIG_VALUE 0x0D0A870A ++#define JP2_CODESTREAM 0x6A703263 ++ ++#define HAD_COC 0x01 ++#define HAD_QCC 0x02 ++ ++typedef struct { ++ J2kComponent *comp; ++ uint8_t properties[4]; ++ J2kCodingStyle codsty[4]; ++ J2kQuantStyle qntsty[4]; ++} J2kTile; ++ ++typedef struct { ++ AVCodecContext *avctx; ++ AVFrame picture; ++ ++ int width, height; ///< image width and height ++ int image_offset_x, image_offset_y; ++ int tile_offset_x, tile_offset_y; ++ uint8_t cbps[4]; ///< bits per sample in particular components ++ uint8_t sgnd[4]; ///< if a component is signed ++ uint8_t properties[4]; ++ int cdx[4], cdy[4]; ++ int precision; ++ int ncomponents; ++ int tile_width, tile_height; ///< tile size ++ int numXtiles, numYtiles; ++ int maxtilelen; ++ ++ J2kCodingStyle codsty[4]; ++ J2kQuantStyle qntsty[4]; ++ ++ const uint8_t *buf_start; ++ const uint8_t *buf; ++ const uint8_t *buf_end; ++ int bit_index; ++ ++ int16_t curtileno; ++ ++ J2kTile *tile; ++} J2kDecoderContext; ++ ++static int get_bits(J2kDecoderContext *s, int n) ++{ ++ int res = 0; ++ if (s->buf_end - s->buf < ((n - s->bit_index) >> 8)) ++ return AVERROR(EINVAL); ++ while (--n >= 0){ ++ res <<= 1; ++ if (s->bit_index == 0){ ++ s->bit_index = 7 + (*s->buf != 0xff); ++ s->buf++; ++ } ++ s->bit_index--; ++ res |= (*s->buf >> s->bit_index) & 1; ++ } ++ return res; ++} ++ ++static void j2k_flush(J2kDecoderContext *s) ++{ ++ if (*s->buf == 0xff) ++ s->buf++; ++ s->bit_index = 8; ++ s->buf++; ++} ++#if 0 ++void printcomp(J2kComponent *comp) ++{ ++ int i; ++ for (i = 0; i < comp->y1 - comp->y0; i++) ++ ff_j2k_printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0); ++} ++ ++static void nspaces(FILE *fd, int n) ++{ ++ while(n--) putc(' ', fd); ++} ++ ++static void dump(J2kDecoderContext *s, FILE *fd) ++{ ++ int tileno, compno, reslevelno, bandno, precno; ++ fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n" ++ "numXtiles = %d, numYtiles = %d, ncomponents = %d\n" ++ "tiles:\n", ++ s->width, s->height, s->tile_width, s->tile_height, ++ s->numXtiles, s->numYtiles, s->ncomponents); ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ J2kTile *tile = s->tile + tileno; ++ nspaces(fd, 2); ++ fprintf(fd, "tile %d:\n", tileno); ++ for(compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ nspaces(fd, 4); ++ fprintf(fd, "component %d:\n", compno); ++ nspaces(fd, 4); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n", ++ comp->x0, comp->x1, comp->y0, comp->y1); ++ for(reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ nspaces(fd, 6); ++ fprintf(fd, "reslevel %d:\n", reslevelno); ++ nspaces(fd, 6); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n", ++ reslevel->x0, reslevel->x1, reslevel->y0, ++ reslevel->y1, reslevel->nbands); ++ for(bandno = 0; bandno < reslevel->nbands; bandno++){ ++ J2kBand *band = reslevel->band + bandno; ++ nspaces(fd, 8); ++ fprintf(fd, "band %d:\n", bandno); ++ nspaces(fd, 8); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d," ++ "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n", ++ band->x0, band->x1, ++ band->y0, band->y1, ++ band->codeblock_width, band->codeblock_height, ++ band->cblknx, band->cblkny); ++ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){ ++ J2kPrec *prec = band->prec + precno; ++ nspaces(fd, 10); ++ fprintf(fd, "prec %d:\n", precno); ++ nspaces(fd, 10); ++ fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n", ++ prec->xi0, prec->xi1, prec->yi0, prec->yi1); ++ } ++ } ++ } ++ } ++ } ++} ++#endif ++ ++/** decode the value stored in node */ ++static int tag_tree_decode(J2kDecoderContext *s, J2kTgtNode *node, int threshold) ++{ ++ J2kTgtNode *stack[30]; ++ int sp = -1, curval = 0; ++ ++ while(node && !node->vis){ ++ stack[++sp] = node; ++ node = node->parent; ++ } ++ ++ if (node) ++ curval = node->val; ++ else ++ curval = stack[sp]->val; ++ ++ while(curval < threshold && sp >= 0){ ++ if (curval < stack[sp]->val) ++ curval = stack[sp]->val; ++ while (curval < threshold){ ++ int ret; ++ if ((ret = get_bits(s, 1)) > 0){ ++ stack[sp]->vis++; ++ break; ++ } else if (!ret) ++ curval++; ++ else ++ return ret; ++ } ++ stack[sp]->val = curval; ++ sp--; ++ } ++ return curval; ++} ++ ++/* marker segments */ ++/** get sizes and offsets of image, tiles; number of components */ ++static int get_siz(J2kDecoderContext *s) ++{ ++ int i, ret; ++ ++ if (s->buf_end - s->buf < 36) ++ return AVERROR(EINVAL); ++ ++ bytestream_get_be16(&s->buf); // Rsiz (skipped) ++ s->width = bytestream_get_be32(&s->buf); // width ++ s->height = bytestream_get_be32(&s->buf); // height ++ s->image_offset_x = bytestream_get_be32(&s->buf); // X0Siz ++ s->image_offset_y = bytestream_get_be32(&s->buf); // Y0Siz ++ ++ s->tile_width = bytestream_get_be32(&s->buf); // XTSiz ++ s->tile_height = bytestream_get_be32(&s->buf); // YTSiz ++ s->tile_offset_x = bytestream_get_be32(&s->buf); // XT0Siz ++ s->tile_offset_y = bytestream_get_be32(&s->buf); // YT0Siz ++ s->ncomponents = bytestream_get_be16(&s->buf); // CSiz ++ ++ if(s->tile_width<=0 || s->tile_height<=0) ++ return AVERROR(EINVAL); ++ ++ if (s->buf_end - s->buf < 2 * s->ncomponents) ++ return AVERROR(EINVAL); ++ ++ for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i ++ uint8_t x = bytestream_get_byte(&s->buf); ++ s->cbps[i] = (x & 0x7f) + 1; ++ s->precision = FFMAX(s->cbps[i], s->precision); ++ s->sgnd[i] = !!(x & 0x80); ++ s->cdx[i] = bytestream_get_byte(&s->buf); ++ s->cdy[i] = bytestream_get_byte(&s->buf); ++ } ++ ++ s->numXtiles = ff_j2k_ceildiv(s->width - s->tile_offset_x, s->tile_width); ++ s->numYtiles = ff_j2k_ceildiv(s->height - s->tile_offset_y, s->tile_height); ++ ++ if(s->numXtiles * (uint64_t)s->numYtiles > INT_MAX/sizeof(J2kTile)) ++ return AVERROR(EINVAL); ++ ++ s->tile = av_mallocz(s->numXtiles * s->numYtiles * sizeof(J2kTile)); ++ if (!s->tile) ++ return AVERROR(ENOMEM); ++ ++ for (i = 0; i < s->numXtiles * s->numYtiles; i++){ ++ J2kTile *tile = s->tile + i; ++ ++ tile->comp = av_mallocz(s->ncomponents * sizeof(J2kComponent)); ++ if (!tile->comp) ++ return AVERROR(ENOMEM); ++ } ++ ++ s->avctx->width = s->width - s->image_offset_x; ++ s->avctx->height = s->height - s->image_offset_y; ++ ++ switch(s->ncomponents){ ++ case 1: if (s->precision > 8) { ++ s->avctx->pix_fmt = PIX_FMT_GRAY16; ++ } else s->avctx->pix_fmt = PIX_FMT_GRAY8; ++ break; ++ case 3: if (s->precision > 8) { ++ s->avctx->pix_fmt = PIX_FMT_RGB48; ++ } else s->avctx->pix_fmt = PIX_FMT_RGB24; ++ break; ++ case 4: s->avctx->pix_fmt = PIX_FMT_BGRA; break; ++ } ++ ++ if (s->picture.data[0]) ++ s->avctx->release_buffer(s->avctx, &s->picture); ++ ++ if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0) ++ return ret; ++ ++ s->picture.pict_type = AV_PICTURE_TYPE_I; ++ s->picture.key_frame = 1; ++ ++ return 0; ++} ++ ++/** get common part for COD and COC segments */ ++static int get_cox(J2kDecoderContext *s, J2kCodingStyle *c) ++{ ++ if (s->buf_end - s->buf < 5) ++ return AVERROR(EINVAL); ++ c->nreslevels = bytestream_get_byte(&s->buf) + 1; // num of resolution levels - 1 ++ c->log2_cblk_width = bytestream_get_byte(&s->buf) + 2; // cblk width ++ c->log2_cblk_height = bytestream_get_byte(&s->buf) + 2; // cblk height ++ ++ c->cblk_style = bytestream_get_byte(&s->buf); ++ if (c->cblk_style != 0){ // cblk style ++ av_log(s->avctx, AV_LOG_WARNING, "extra cblk styles %X\n", c->cblk_style); ++ } ++ c->transform = bytestream_get_byte(&s->buf); // transformation ++ if (c->csty & J2K_CSTY_PREC) { ++ int i; ++ for (i = 0; i < c->nreslevels; i++) ++ bytestream_get_byte(&s->buf); ++ } ++ return 0; ++} ++ ++/** get coding parameters for a particular tile or whole image*/ ++static int get_cod(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties) ++{ ++ J2kCodingStyle tmp; ++ int compno; ++ ++ if (s->buf_end - s->buf < 5) ++ return AVERROR(EINVAL); ++ ++ tmp.log2_prec_width = ++ tmp.log2_prec_height = 15; ++ ++ tmp.csty = bytestream_get_byte(&s->buf); ++ ++ if (bytestream_get_byte(&s->buf)){ // progression level ++ av_log(s->avctx, AV_LOG_ERROR, "only LRCP progression supported\n"); ++ return -1; ++ } ++ ++ tmp.nlayers = bytestream_get_be16(&s->buf); ++ tmp.mct = bytestream_get_byte(&s->buf); // multiple component transformation ++ ++ get_cox(s, &tmp); ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ if (!(properties[compno] & HAD_COC)) ++ memcpy(c + compno, &tmp, sizeof(J2kCodingStyle)); ++ } ++ return 0; ++} ++ ++/** get coding parameters for a component in the whole image on a particular tile */ ++static int get_coc(J2kDecoderContext *s, J2kCodingStyle *c, uint8_t *properties) ++{ ++ int compno; ++ ++ if (s->buf_end - s->buf < 2) ++ return AVERROR(EINVAL); ++ ++ compno = bytestream_get_byte(&s->buf); ++ ++ c += compno; ++ c->csty = bytestream_get_byte(&s->buf); ++ get_cox(s, c); ++ ++ properties[compno] |= HAD_COC; ++ return 0; ++} ++ ++/** get common part for QCD and QCC segments */ ++static int get_qcx(J2kDecoderContext *s, int n, J2kQuantStyle *q) ++{ ++ int i, x; ++ ++ if (s->buf_end - s->buf < 1) ++ return AVERROR(EINVAL); ++ ++ x = bytestream_get_byte(&s->buf); // Sqcd ++ ++ q->nguardbits = x >> 5; ++ q->quantsty = x & 0x1f; ++ ++ if (q->quantsty == J2K_QSTY_NONE){ ++ n -= 3; ++ if (s->buf_end - s->buf < n || 32*3 < n) ++ return AVERROR(EINVAL); ++ for (i = 0; i < n; i++) ++ q->expn[i] = bytestream_get_byte(&s->buf) >> 3; ++ } else if (q->quantsty == J2K_QSTY_SI){ ++ if (s->buf_end - s->buf < 2) ++ return AVERROR(EINVAL); ++ x = bytestream_get_be16(&s->buf); ++ q->expn[0] = x >> 11; ++ q->mant[0] = x & 0x7ff; ++ for (i = 1; i < 32 * 3; i++){ ++ int curexpn = FFMAX(0, q->expn[0] - (i-1)/3); ++ q->expn[i] = curexpn; ++ q->mant[i] = q->mant[0]; ++ } ++ } else{ ++ n = (n - 3) >> 1; ++ if (s->buf_end - s->buf < n || 32*3 < n) ++ return AVERROR(EINVAL); ++ for (i = 0; i < n; i++){ ++ x = bytestream_get_be16(&s->buf); ++ q->expn[i] = x >> 11; ++ q->mant[i] = x & 0x7ff; ++ } ++ } ++ return 0; ++} ++ ++/** get quantization parameters for a particular tile or a whole image */ ++static int get_qcd(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties) ++{ ++ J2kQuantStyle tmp; ++ int compno; ++ ++ if (get_qcx(s, n, &tmp)) ++ return -1; ++ for (compno = 0; compno < s->ncomponents; compno++) ++ if (!(properties[compno] & HAD_QCC)) ++ memcpy(q + compno, &tmp, sizeof(J2kQuantStyle)); ++ return 0; ++} ++ ++/** get quantization parameters for a component in the whole image on in a particular tile */ ++static int get_qcc(J2kDecoderContext *s, int n, J2kQuantStyle *q, uint8_t *properties) ++{ ++ int compno; ++ ++ if (s->buf_end - s->buf < 1) ++ return AVERROR(EINVAL); ++ ++ compno = bytestream_get_byte(&s->buf); ++ properties[compno] |= HAD_QCC; ++ return get_qcx(s, n-1, q+compno); ++} ++ ++/** get start of tile segment */ ++static uint8_t get_sot(J2kDecoderContext *s) ++{ ++ if (s->buf_end - s->buf < 4) ++ return AVERROR(EINVAL); ++ ++ s->curtileno = bytestream_get_be16(&s->buf); ///< Isot ++ if((unsigned)s->curtileno >= s->numXtiles * s->numYtiles){ ++ s->curtileno=0; ++ return AVERROR(EINVAL); ++ } ++ ++ s->buf += 4; ///< Psot (ignored) ++ ++ if (!bytestream_get_byte(&s->buf)){ ///< TPsot ++ J2kTile *tile = s->tile + s->curtileno; ++ ++ /* copy defaults */ ++ memcpy(tile->codsty, s->codsty, s->ncomponents * sizeof(J2kCodingStyle)); ++ memcpy(tile->qntsty, s->qntsty, s->ncomponents * sizeof(J2kQuantStyle)); ++ } ++ bytestream_get_byte(&s->buf); ///< TNsot ++ ++ return 0; ++} ++ ++static int init_tile(J2kDecoderContext *s, int tileno) ++{ ++ int compno, ++ tilex = tileno % s->numXtiles, ++ tiley = tileno / s->numXtiles; ++ J2kTile *tile = s->tile + tileno; ++ ++ if (!tile->comp) ++ return AVERROR(ENOMEM); ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ J2kCodingStyle *codsty = tile->codsty + compno; ++ J2kQuantStyle *qntsty = tile->qntsty + compno; ++ int ret; // global bandno ++ ++ comp->coord[0][0] = FFMAX(tilex * s->tile_width + s->tile_offset_x, s->image_offset_x); ++ comp->coord[0][1] = FFMIN((tilex+1)*s->tile_width + s->tile_offset_x, s->width); ++ comp->coord[1][0] = FFMAX(tiley * s->tile_height + s->tile_offset_y, s->image_offset_y); ++ comp->coord[1][1] = FFMIN((tiley+1)*s->tile_height + s->tile_offset_y, s->height); ++ ++ if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], s->cdx[compno], s->cdy[compno])) ++ return ret; ++ } ++ return 0; ++} ++ ++/** read the number of coding passes */ ++static int getnpasses(J2kDecoderContext *s) ++{ ++ int num; ++ if (!get_bits(s, 1)) ++ return 1; ++ if (!get_bits(s, 1)) ++ return 2; ++ if ((num = get_bits(s, 2)) != 3) ++ return num < 0 ? num : 3 + num; ++ if ((num = get_bits(s, 5)) != 31) ++ return num < 0 ? num : 6 + num; ++ num = get_bits(s, 7); ++ return num < 0 ? num : 37 + num; ++} ++ ++static int getlblockinc(J2kDecoderContext *s) ++{ ++ int res = 0, ret; ++ while (ret = get_bits(s, 1)){ ++ if (ret < 0) ++ return ret; ++ res++; ++ } ++ return res; ++} ++ ++static int decode_packet(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kResLevel *rlevel, int precno, ++ int layno, uint8_t *expn, int numgbits) ++{ ++ int bandno, cblkny, cblknx, cblkno, ret; ++ ++ if (!(ret = get_bits(s, 1))){ ++ j2k_flush(s); ++ return 0; ++ } else if (ret < 0) ++ return ret; ++ ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ J2kPrec *prec = band->prec + precno; ++ int pos = 0; ++ ++ if (band->coord[0][0] == band->coord[0][1] ++ || band->coord[1][0] == band->coord[1][1]) ++ continue; ++ ++ for (cblkny = prec->yi0; cblkny < prec->yi1; cblkny++) ++ for(cblknx = prec->xi0, cblkno = cblkny * band->cblknx + cblknx; cblknx < prec->xi1; cblknx++, cblkno++, pos++){ ++ J2kCblk *cblk = band->cblk + cblkno; ++ int incl, newpasses, llen; ++ ++ if (cblk->npasses) ++ incl = get_bits(s, 1); ++ else ++ incl = tag_tree_decode(s, prec->cblkincl + pos, layno+1) == layno; ++ if (!incl) ++ continue; ++ else if (incl < 0) ++ return incl; ++ ++ if (!cblk->npasses) ++ cblk->nonzerobits = expn[bandno] + numgbits - 1 - tag_tree_decode(s, prec->zerobits + pos, 100); ++ if ((newpasses = getnpasses(s)) < 0) ++ return newpasses; ++ if ((llen = getlblockinc(s)) < 0) ++ return llen; ++ cblk->lblock += llen; ++ if ((ret = get_bits(s, av_log2(newpasses) + cblk->lblock)) < 0) ++ return ret; ++ cblk->lengthinc = ret; ++ cblk->npasses += newpasses; ++ } ++ } ++ j2k_flush(s); ++ ++ if (codsty->csty & J2K_CSTY_EPH) { ++ if (AV_RB16(s->buf) == J2K_EPH) { ++ s->buf += 2; ++ } else { ++ av_log(s->avctx, AV_LOG_ERROR, "EPH marker not found.\n"); ++ } ++ } ++ ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ int yi, cblknw = band->prec[precno].xi1 - band->prec[precno].xi0; ++ for (yi = band->prec[precno].yi0; yi < band->prec[precno].yi1; yi++){ ++ int xi; ++ for (xi = band->prec[precno].xi0; xi < band->prec[precno].xi1; xi++){ ++ J2kCblk *cblk = band->cblk + yi * cblknw + xi; ++ if (s->buf_end - s->buf < cblk->lengthinc) ++ return AVERROR(EINVAL); ++ bytestream_get_buffer(&s->buf, cblk->data, cblk->lengthinc); ++ cblk->length += cblk->lengthinc; ++ cblk->lengthinc = 0; ++ } ++ } ++ } ++ return 0; ++} ++ ++static int decode_packets(J2kDecoderContext *s, J2kTile *tile) ++{ ++ int layno, reslevelno, compno, precno, ok_reslevel; ++ s->bit_index = 8; ++ for (layno = 0; layno < tile->codsty[0].nlayers; layno++){ ++ ok_reslevel = 1; ++ for (reslevelno = 0; ok_reslevel; reslevelno++){ ++ ok_reslevel = 0; ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kCodingStyle *codsty = tile->codsty + compno; ++ J2kQuantStyle *qntsty = tile->qntsty + compno; ++ if (reslevelno < codsty->nreslevels){ ++ J2kResLevel *rlevel = tile->comp[compno].reslevel + reslevelno; ++ ok_reslevel = 1; ++ for (precno = 0; precno < rlevel->num_precincts_x * rlevel->num_precincts_y; precno++){ ++ if (decode_packet(s, codsty, rlevel, precno, layno, qntsty->expn + ++ (reslevelno ? 3*(reslevelno-1)+1 : 0), qntsty->nguardbits)) ++ return -1; ++ } ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++/* TIER-1 routines */ ++static void decode_sigpass(J2kT1Context *t1, int width, int height, int bpno, int bandno, int bpass_csty_symbol, ++ int vert_causal_ctx_csty_symbol) ++{ ++ int mask = 3 << (bpno - 1), y0, x, y; ++ ++ for (y0 = 0; y0 < height; y0 += 4) ++ for (x = 0; x < width; x++) ++ for (y = y0; y < height && y < y0+4; y++){ ++ if ((t1->flags[y+1][x+1] & J2K_T1_SIG_NB) ++ && !(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){ ++ int vert_causal_ctx_csty_loc_symbol = vert_causal_ctx_csty_symbol && (x == 3 && y == 3); ++ if (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, ++ vert_causal_ctx_csty_loc_symbol))){ ++ int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit); ++ if (bpass_csty_symbol) ++ t1->data[y][x] = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? -mask : mask; ++ else ++ t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? ++ -mask : mask; ++ ++ ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0); ++ } ++ t1->flags[y+1][x+1] |= J2K_T1_VIS; ++ } ++ } ++} ++ ++static void decode_refpass(J2kT1Context *t1, int width, int height, int bpno) ++{ ++ int phalf, nhalf; ++ int y0, x, y; ++ ++ phalf = 1 << (bpno - 1); ++ nhalf = -phalf; ++ ++ for (y0 = 0; y0 < height; y0 += 4) ++ for (x = 0; x < width; x++) ++ for (y = y0; y < height && y < y0+4; y++){ ++ if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){ ++ int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]); ++ int r = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ? phalf : nhalf; ++ t1->data[y][x] += t1->data[y][x] < 0 ? -r : r; ++ t1->flags[y+1][x+1] |= J2K_T1_REF; ++ } ++ } ++} ++ ++static void decode_clnpass(J2kDecoderContext *s, J2kT1Context *t1, int width, int height, ++ int bpno, int bandno, int seg_symbols) ++{ ++ int mask = 3 << (bpno - 1), y0, x, y, runlen, dec; ++ ++ for (y0 = 0; y0 < height; y0 += 4) { ++ for (x = 0; x < width; x++){ ++ if (y0 + 3 < height && !( ++ (t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)))){ ++ if (!ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL)) ++ continue; ++ runlen = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ runlen = (runlen << 1) | ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ dec = 1; ++ } else{ ++ runlen = 0; ++ dec = 0; ++ } ++ ++ for (y = y0 + runlen; y < y0 + 4 && y < height; y++){ ++ if (!dec){ ++ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))) ++ dec = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ff_j2k_getnbctxno(t1->flags[y+1][x+1], ++ bandno, 0)); ++ } ++ if (dec){ ++ int xorbit, ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit); ++ t1->data[y][x] = (ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + ctxno) ^ xorbit) ? -mask : mask; ++ ff_j2k_set_significant(t1, x, y, t1->data[y][x] < 0); ++ } ++ dec = 0; ++ t1->flags[y+1][x+1] &= ~J2K_T1_VIS; ++ } ++ } ++ } ++ if (seg_symbols) { ++ int val; ++ val = ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ val = (val << 1) + ff_mqc_decode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI); ++ if (val != 0xa) { ++ av_log(s->avctx, AV_LOG_ERROR,"Segmentation symbol value incorrect\n"); ++ } ++ } ++} ++ ++static int decode_cblk(J2kDecoderContext *s, J2kCodingStyle *codsty, J2kT1Context *t1, J2kCblk *cblk, ++ int width, int height, int bandpos) ++{ ++ int passno = cblk->npasses, pass_t = 2, bpno = cblk->nonzerobits - 1, y, clnpass_cnt = 0; ++ int bpass_csty_symbol = J2K_CBLK_BYPASS & codsty->cblk_style; ++ int vert_causal_ctx_csty_symbol = J2K_CBLK_VSC & codsty->cblk_style; ++ ++ for (y = 0; y < height+2; y++) ++ memset(t1->flags[y], 0, (width+2)*sizeof(int)); ++ ++ for (y = 0; y < height; y++) ++ memset(t1->data[y], 0, width*sizeof(int)); ++ ++ cblk->data[cblk->length] = 0xff; ++ cblk->data[cblk->length+1] = 0xff; ++ ff_mqc_initdec(&t1->mqc, cblk->data); ++ ++ while(passno--){ ++ switch(pass_t){ ++ case 0: decode_sigpass(t1, width, height, bpno+1, bandpos, ++ bpass_csty_symbol && (clnpass_cnt >= 4), vert_causal_ctx_csty_symbol); ++ break; ++ case 1: decode_refpass(t1, width, height, bpno+1); ++ if (bpass_csty_symbol && clnpass_cnt >= 4) ++ ff_mqc_initdec(&t1->mqc, cblk->data); ++ break; ++ case 2: decode_clnpass(s, t1, width, height, bpno+1, bandpos, ++ codsty->cblk_style & J2K_CBLK_SEGSYM); ++ clnpass_cnt = clnpass_cnt + 1; ++ if (bpass_csty_symbol && clnpass_cnt >= 4) ++ ff_mqc_initdec(&t1->mqc, cblk->data); ++ break; ++ } ++ ++ pass_t++; ++ if (pass_t == 3){ ++ bpno--; ++ pass_t = 0; ++ } ++ } ++ return 0; ++} ++ ++static void mct_decode(J2kDecoderContext *s, J2kTile *tile) ++{ ++ int i, *src[3], i0, i1, i2, csize = 1; ++ ++ for (i = 0; i < 3; i++) ++ src[i] = tile->comp[i].data; ++ ++ for (i = 0; i < 2; i++) ++ csize *= tile->comp[0].coord[i][1] - tile->comp[0].coord[i][0]; ++ ++ if (tile->codsty[0].transform == FF_DWT97){ ++ for (i = 0; i < csize; i++){ ++ i0 = *src[0] + (*src[2] * 46802 >> 16); ++ i1 = *src[0] - (*src[1] * 22553 + *src[2] * 46802 >> 16); ++ i2 = *src[0] + (116130 * *src[1] >> 16); ++ *src[0]++ = i0; ++ *src[1]++ = i1; ++ *src[2]++ = i2; ++ } ++ } else{ ++ for (i = 0; i < csize; i++){ ++ i1 = *src[0] - (*src[2] + *src[1] >> 2); ++ i0 = i1 + *src[2]; ++ i2 = i1 + *src[1]; ++ *src[0]++ = i0; ++ *src[1]++ = i1; ++ *src[2]++ = i2; ++ } ++ } ++} ++ ++static int decode_tile(J2kDecoderContext *s, J2kTile *tile) ++{ ++ int compno, reslevelno, bandno; ++ int x, y, *src[4]; ++ uint8_t *line; ++ J2kT1Context t1; ++ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ J2kCodingStyle *codsty = tile->codsty + compno; ++ ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ J2kResLevel *rlevel = comp->reslevel + reslevelno; ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos; ++ ++ bandpos = bandno + (reslevelno > 0); ++ ++ yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0]; ++ y0 = yy0; ++ yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height, ++ band->coord[1][1]) - band->coord[1][0] + yy0; ++ ++ if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1]) ++ continue; ++ ++ for (cblky = 0; cblky < band->cblkny; cblky++){ ++ if (reslevelno == 0 || bandno == 1) ++ xx0 = 0; ++ else ++ xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0]; ++ x0 = xx0; ++ xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width, ++ band->coord[0][1]) - band->coord[0][0] + xx0; ++ ++ for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){ ++ int y, x; ++ decode_cblk(s, codsty, &t1, band->cblk + cblkno, xx1 - xx0, yy1 - yy0, bandpos); ++ if (codsty->transform == FF_DWT53){ ++ for (y = yy0; y < yy1; y+=s->cdy[compno]){ ++ int *ptr = t1.data[y-yy0]; ++ for (x = xx0; x < xx1; x+=s->cdx[compno]){ ++ comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] = *ptr++ >> 1; ++ } ++ } ++ } else{ ++ for (y = yy0; y < yy1; y+=s->cdy[compno]){ ++ int *ptr = t1.data[y-yy0]; ++ for (x = xx0; x < xx1; x+=s->cdx[compno]){ ++ int tmp = ((int64_t)*ptr++) * ((int64_t)band->stepsize) >> 13, tmp2; ++ tmp2 = FFABS(tmp>>1) + FFABS(tmp&1); ++ comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] = tmp < 0 ? -tmp2 : tmp2; ++ } ++ } ++ } ++ xx0 = xx1; ++ xx1 = FFMIN(xx1 + band->codeblock_width, band->coord[0][1] - band->coord[0][0] + x0); ++ } ++ yy0 = yy1; ++ yy1 = FFMIN(yy1 + band->codeblock_height, band->coord[1][1] - band->coord[1][0] + y0); ++ } ++ } ++ } ++ ff_j2k_dwt_decode(&comp->dwt, comp->data); ++ src[compno] = comp->data; ++ } ++ if (tile->codsty[0].mct) ++ mct_decode(s, tile); ++ ++ if (s->avctx->pix_fmt == PIX_FMT_BGRA) // RGBA -> BGRA ++ FFSWAP(int *, src[0], src[2]); ++ ++ if (s->precision <= 8) { ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ y = tile->comp[compno].coord[1][0] - s->image_offset_y; ++ line = s->picture.data[0] + y * s->picture.linesize[0]; ++ for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]){ ++ uint8_t *dst; ++ ++ x = tile->comp[compno].coord[0][0] - s->image_offset_x; ++ dst = line + x * s->ncomponents + compno; ++ ++ for (; x < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s->cdx[compno]) { ++ *src[compno] += 1 << (s->cbps[compno]-1); ++ if (*src[compno] < 0) ++ *src[compno] = 0; ++ else if (*src[compno] >= (1 << s->cbps[compno])) ++ *src[compno] = (1 << s->cbps[compno]) - 1; ++ *dst = *src[compno]++; ++ dst += s->ncomponents; ++ } ++ line += s->picture.linesize[0]; ++ } ++ } ++ } else { ++ for (compno = 0; compno < s->ncomponents; compno++) { ++ y = tile->comp[compno].coord[1][0] - s->image_offset_y; ++ line = s->picture.data[0] + y * s->picture.linesize[0]; ++ for (; y < tile->comp[compno].coord[1][1] - s->image_offset_y; y += s->cdy[compno]) { ++ uint16_t *dst; ++ x = tile->comp[compno].coord[0][0] - s->image_offset_x; ++ dst = line + (x * s->ncomponents + compno) * 2; ++ for (; x < tile->comp[compno].coord[0][1] - s->image_offset_x; x += s-> cdx[compno]) { ++ int32_t val; ++ val = *src[compno]++ << (16 - s->cbps[compno]); ++ val += 1 << 15; ++ val = av_clip(val, 0, (1 << 16) - 1); ++ *dst = val; ++ dst += s->ncomponents; ++ } ++ line += s->picture.linesize[0]; ++ } ++ } ++ } ++ return 0; ++} ++ ++static void cleanup(J2kDecoderContext *s) ++{ ++ int tileno, compno; ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = s->tile[tileno].comp + compno; ++ J2kCodingStyle *codsty = s->tile[tileno].codsty + compno; ++ ++ ff_j2k_cleanup(comp, codsty); ++ } ++ av_freep(&s->tile[tileno].comp); ++ } ++ av_freep(&s->tile); ++} ++ ++static int decode_codestream(J2kDecoderContext *s) ++{ ++ J2kCodingStyle *codsty = s->codsty; ++ J2kQuantStyle *qntsty = s->qntsty; ++ uint8_t *properties = s->properties; ++ ++ for (;;){ ++ int marker, len, ret = 0; ++ const uint8_t *oldbuf; ++ if (s->buf_end - s->buf < 2){ ++ av_log(s->avctx, AV_LOG_ERROR, "Missing EOC\n"); ++ break; ++ } ++ ++ marker = bytestream_get_be16(&s->buf); ++ if(s->avctx->debug & FF_DEBUG_STARTCODE) ++ av_log(s->avctx, AV_LOG_DEBUG, "marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4); ++ oldbuf = s->buf; ++ ++ if (marker == J2K_SOD){ ++ J2kTile *tile = s->tile + s->curtileno; ++ if (ret = init_tile(s, s->curtileno)) ++ return ret; ++ if (ret = decode_packets(s, tile)) ++ return ret; ++ continue; ++ } ++ if (marker == J2K_EOC) ++ break; ++ ++ if (s->buf_end - s->buf < 2) ++ return AVERROR(EINVAL); ++ len = bytestream_get_be16(&s->buf); ++ switch(marker){ ++ case J2K_SIZ: ++ ret = get_siz(s); break; ++ case J2K_COC: ++ ret = get_coc(s, codsty, properties); break; ++ case J2K_COD: ++ ret = get_cod(s, codsty, properties); break; ++ case J2K_QCC: ++ ret = get_qcc(s, len, qntsty, properties); break; ++ case J2K_QCD: ++ ret = get_qcd(s, len, qntsty, properties); break; ++ case J2K_SOT: ++ if (!(ret = get_sot(s))){ ++ codsty = s->tile[s->curtileno].codsty; ++ qntsty = s->tile[s->curtileno].qntsty; ++ properties = s->tile[s->curtileno].properties; ++ } ++ break; ++ case J2K_COM: ++ // the comment is ignored ++ s->buf += len - 2; break; ++ default: ++ av_log(s->avctx, AV_LOG_ERROR, "unsupported marker 0x%.4X at pos 0x%tx\n", marker, s->buf - s->buf_start - 4); ++ s->buf += len - 2; break; ++ } ++ if (s->buf - oldbuf != len || ret){ ++ av_log(s->avctx, AV_LOG_ERROR, "error during processing marker segment %.4x\n", marker); ++ return ret ? ret : -1; ++ } ++ } ++ return 0; ++} ++ ++static int jp2_find_codestream(J2kDecoderContext *s) ++{ ++ uint32_t atom_size; ++ int found_codestream = 0, search_range = 10; ++ ++ // skip jpeg2k signature atom ++ s->buf += 12; ++ ++ while(!found_codestream && search_range && s->buf_end - s->buf >= 8) { ++ atom_size = AV_RB32(s->buf); ++ if(AV_RB32(s->buf + 4) == JP2_CODESTREAM) { ++ found_codestream = 1; ++ s->buf += 8; ++ } else { ++ if (s->buf_end - s->buf < atom_size) ++ return 0; ++ s->buf += atom_size; ++ search_range--; ++ } ++ } ++ ++ if(found_codestream) ++ return 1; ++ return 0; ++} ++ ++static int decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ J2kDecoderContext *s = avctx->priv_data; ++ AVFrame *picture = data; ++ int tileno, ret; ++ ++ s->avctx = avctx; ++ av_log(s->avctx, AV_LOG_DEBUG, "start\n"); ++ ++ // init ++ s->buf = s->buf_start = avpkt->data; ++ s->buf_end = s->buf_start + avpkt->size; ++ s->curtileno = -1; ++ ++ ff_j2k_init_tier1_luts(); ++ ++ if (s->buf_end - s->buf < 2) { ++ ret = AVERROR(EINVAL); ++ goto err_out; ++ } ++ ++ // check if the image is in jp2 format ++ if(s->buf_end - s->buf >= 12 && ++ (AV_RB32(s->buf) == 12) && (AV_RB32(s->buf + 4) == JP2_SIG_TYPE) && ++ (AV_RB32(s->buf + 8) == JP2_SIG_VALUE)) { ++ if(!jp2_find_codestream(s)) { ++ av_log(avctx, AV_LOG_ERROR, "couldn't find jpeg2k codestream atom\n"); ++ ret = -1; ++ goto err_out; ++ } ++ } ++ ++ if (bytestream_get_be16(&s->buf) != J2K_SOC){ ++ av_log(avctx, AV_LOG_ERROR, "SOC marker not present\n"); ++ ret = -1; ++ goto err_out; ++ } ++ if (ret = decode_codestream(s)) ++ goto err_out; ++ ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++) ++ if (ret = decode_tile(s, s->tile + tileno)) ++ goto err_out; ++ ++ cleanup(s); ++ av_log(s->avctx, AV_LOG_DEBUG, "end\n"); ++ ++ *data_size = sizeof(AVPicture); ++ *picture = s->picture; ++ ++ return s->buf - s->buf_start; ++ ++err_out: ++ cleanup(s); ++ return ret; ++} ++ ++static av_cold int j2kdec_init(AVCodecContext *avctx) ++{ ++ J2kDecoderContext *s = avctx->priv_data; ++ ++ avcodec_get_frame_defaults((AVFrame*)&s->picture); ++ avctx->coded_frame = (AVFrame*)&s->picture; ++ return 0; ++} ++ ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ J2kDecoderContext *s = avctx->priv_data; ++ ++ if (s->picture.data[0]) ++ avctx->release_buffer(avctx, &s->picture); ++ ++ return 0; ++} ++ ++AVCodec ff_jpeg2000_decoder = { ++ .name = "j2k", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEG2000, ++ .priv_data_size = sizeof(J2kDecoderContext), ++ .init = j2kdec_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_EXPERIMENTAL, ++ .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"), ++ .pix_fmts = ++ (const enum PixelFormat[]) {PIX_FMT_GRAY8, PIX_FMT_RGB24, PIX_FMT_NONE} ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k_dwt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k_dwt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k_dwt.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k_dwt.c 2012-05-14 14:08:53.888331005 +0200 +@@ -0,0 +1,386 @@ ++/* ++ * Discrete wavelet transform ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * Discrete wavelet transform ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "j2k_dwt.h" ++ ++const static float scale97[] = {1.625786, 1.230174}; ++ ++static inline void extend53(int *p, int i0, int i1) ++{ ++ p[i0 - 1] = p[i0 + 1]; ++ p[i1 ] = p[i1 - 2]; ++ p[i0 - 2] = p[i0 + 2]; ++ p[i1 + 1] = p[i1 - 3]; ++} ++ ++static inline void extend97(float *p, int i0, int i1) ++{ ++ int i; ++ ++ for (i = 1; i <= 4; i++){ ++ p[i0 - i] = p[i0 + i]; ++ p[i1 + i - 1] = p[i1 - i - 1]; ++ } ++} ++ ++static void sd_1d53(int *p, int i0, int i1) ++{ ++ int i; ++ ++ if (i1 == i0 + 1) ++ return; ++ ++ extend53(p, i0, i1); ++ ++ for (i = (i0+1)/2 - 1; i < (i1+1)/2; i++) ++ p[2*i+1] -= (p[2*i] + p[2*i+2]) >> 1; ++ for (i = (i0+1)/2; i < (i1+1)/2; i++) ++ p[2*i] += (p[2*i-1] + p[2*i+1] + 2) >> 2; ++} ++ ++static void dwt_encode53(DWTContext *s, int *t) ++{ ++ int lev, ++ w = s->linelen[s->ndeclevels-1][0]; ++ int *line = s->linebuf; ++ line += 3; ++ ++ for (lev = s->ndeclevels-1; lev >= 0; lev--){ ++ int lh = s->linelen[lev][0], ++ lv = s->linelen[lev][1], ++ mh = s->mod[lev][0], ++ mv = s->mod[lev][1], ++ lp; ++ int *l; ++ ++ // HOR_SD ++ l = line + mh; ++ for (lp = 0; lp < lv; lp++){ ++ int i, j = 0; ++ ++ for (i = 0; i < lh; i++) ++ l[i] = t[w*lp + i]; ++ ++ sd_1d53(line, mh, mh + lh); ++ ++ // copy back and deinterleave ++ for (i = mh; i < lh; i+=2, j++) ++ t[w*lp + j] = l[i]; ++ for (i = 1-mh; i < lh; i+=2, j++) ++ t[w*lp + j] = l[i]; ++ } ++ ++ // VER_SD ++ l = line + mv; ++ for (lp = 0; lp < lh; lp++) { ++ int i, j = 0; ++ ++ for (i = 0; i < lv; i++) ++ l[i] = t[w*i + lp]; ++ ++ sd_1d53(line, mv, mv + lv); ++ ++ // copy back and deinterleave ++ for (i = mv; i < lv; i+=2, j++) ++ t[w*j + lp] = l[i]; ++ for (i = 1-mv; i < lv; i+=2, j++) ++ t[w*j + lp] = l[i]; ++ } ++ } ++} ++ ++static void sd_1d97(float *p, int i0, int i1) ++{ ++ int i; ++ ++ if (i1 == i0 + 1) ++ return; ++ ++ extend97(p, i0, i1); ++ i0++; i1++; ++ ++ for (i = i0/2 - 2; i < i1/2 + 1; i++) ++ p[2*i+1] -= 1.586134 * (p[2*i] + p[2*i+2]); ++ for (i = i0/2 - 1; i < i1/2 + 1; i++) ++ p[2*i] -= 0.052980 * (p[2*i-1] + p[2*i+1]); ++ for (i = i0/2 - 1; i < i1/2; i++) ++ p[2*i+1] += 0.882911 * (p[2*i] + p[2*i+2]); ++ for (i = i0/2; i < i1/2; i++) ++ p[2*i] += 0.443506 * (p[2*i-1] + p[2*i+1]); ++} ++ ++static void dwt_encode97(DWTContext *s, int *t) ++{ ++ int lev, ++ w = s->linelen[s->ndeclevels-1][0]; ++ float *line = s->linebuf; ++ line += 5; ++ ++ for (lev = s->ndeclevels-1; lev >= 0; lev--){ ++ int lh = s->linelen[lev][0], ++ lv = s->linelen[lev][1], ++ mh = s->mod[lev][0], ++ mv = s->mod[lev][1], ++ lp; ++ float *l; ++ ++ // HOR_SD ++ l = line + mh; ++ for (lp = 0; lp < lv; lp++){ ++ int i, j = 0; ++ ++ for (i = 0; i < lh; i++) ++ l[i] = t[w*lp + i]; ++ ++ sd_1d97(line, mh, mh + lh); ++ ++ // copy back and deinterleave ++ for (i = mh; i < lh; i+=2, j++) ++ t[w*lp + j] = scale97[mh] * l[i] / 2; ++ for (i = 1-mh; i < lh; i+=2, j++) ++ t[w*lp + j] = scale97[mh] * l[i] / 2; ++ } ++ ++ // VER_SD ++ l = line + mv; ++ for (lp = 0; lp < lh; lp++) { ++ int i, j = 0; ++ ++ for (i = 0; i < lv; i++) ++ l[i] = t[w*i + lp]; ++ ++ sd_1d97(line, mv, mv + lv); ++ ++ // copy back and deinterleave ++ for (i = mv; i < lv; i+=2, j++) ++ t[w*j + lp] = scale97[mv] * l[i] / 2; ++ for (i = 1-mv; i < lv; i+=2, j++) ++ t[w*j + lp] = scale97[mv] * l[i] / 2; ++ } ++ } ++} ++ ++static void sr_1d53(int *p, int i0, int i1) ++{ ++ int i; ++ ++ if (i1 == i0 + 1) ++ return; ++ ++ extend53(p, i0, i1); ++ ++ for (i = i0/2; i < i1/2 + 1; i++) ++ p[2*i] -= (p[2*i-1] + p[2*i+1] + 2) >> 2; ++ for (i = i0/2; i < i1/2; i++) ++ p[2*i+1] += (p[2*i] + p[2*i+2]) >> 1; ++} ++ ++static void dwt_decode53(DWTContext *s, int *t) ++{ ++ int lev, ++ w = s->linelen[s->ndeclevels-1][0]; ++ int *line = s->linebuf; ++ line += 3; ++ ++ for (lev = 0; lev < s->ndeclevels; lev++){ ++ int lh = s->linelen[lev][0], ++ lv = s->linelen[lev][1], ++ mh = s->mod[lev][0], ++ mv = s->mod[lev][1], ++ lp; ++ int *l; ++ ++ // HOR_SD ++ l = line + mh; ++ for (lp = 0; lp < lv; lp++){ ++ int i, j = 0; ++ // copy with interleaving ++ for (i = mh; i < lh; i+=2, j++) ++ l[i] = t[w*lp + j]; ++ for (i = 1-mh; i < lh; i+=2, j++) ++ l[i] = t[w*lp + j]; ++ ++ sr_1d53(line, mh, mh + lh); ++ ++ for (i = 0; i < lh; i++) ++ t[w*lp + i] = l[i]; ++ } ++ ++ // VER_SD ++ l = line + mv; ++ for (lp = 0; lp < lh; lp++){ ++ int i, j = 0; ++ // copy with interleaving ++ for (i = mv; i < lv; i+=2, j++) ++ l[i] = t[w*j + lp]; ++ for (i = 1-mv; i < lv; i+=2, j++) ++ l[i] = t[w*j + lp]; ++ ++ sr_1d53(line, mv, mv + lv); ++ ++ for (i = 0; i < lv; i++) ++ t[w*i + lp] = l[i]; ++ } ++ } ++} ++ ++static void sr_1d97(float *p, int i0, int i1) ++{ ++ int i; ++ ++ if (i1 == i0 + 1) ++ return; ++ ++ extend97(p, i0, i1); ++ ++ for (i = i0/2 - 1; i < i1/2 + 2; i++) ++ p[2*i] -= 0.443506 * (p[2*i-1] + p[2*i+1]); ++ for (i = i0/2 - 1; i < i1/2 + 1; i++) ++ p[2*i+1] -= 0.882911 * (p[2*i] + p[2*i+2]); ++ for (i = i0/2; i < i1/2 + 1; i++) ++ p[2*i] += 0.052980 * (p[2*i-1] + p[2*i+1]); ++ for (i = i0/2; i < i1/2; i++) ++ p[2*i+1] += 1.586134 * (p[2*i] + p[2*i+2]); ++} ++ ++static void dwt_decode97(DWTContext *s, int *t) ++{ ++ int lev, ++ w = s->linelen[s->ndeclevels-1][0]; ++ float *line = s->linebuf; ++ line += 5; ++ ++ for (lev = 0; lev < s->ndeclevels; lev++){ ++ int lh = s->linelen[lev][0], ++ lv = s->linelen[lev][1], ++ mh = s->mod[lev][0], ++ mv = s->mod[lev][1], ++ lp; ++ float *l; ++ ++ // HOR_SD ++ l = line + mh; ++ for (lp = 0; lp < lv; lp++){ ++ int i, j = 0; ++ // copy with interleaving ++ for (i = mh; i < lh; i+=2, j++) ++ l[i] = scale97[1-mh] * t[w*lp + j]; ++ for (i = 1-mh; i < lh; i+=2, j++) ++ l[i] = scale97[1-mh] * t[w*lp + j]; ++ ++ sr_1d97(line, mh, mh + lh); ++ ++ for (i = 0; i < lh; i++) ++ t[w*lp + i] = l[i]; ++ } ++ ++ // VER_SD ++ l = line + mv; ++ for (lp = 0; lp < lh; lp++){ ++ int i, j = 0; ++ // copy with interleaving ++ for (i = mv; i < lv; i+=2, j++) ++ l[i] = scale97[1-mv] * t[w*j + lp]; ++ for (i = 1-mv; i < lv; i+=2, j++) ++ l[i] = scale97[1-mv] * t[w*j + lp]; ++ ++ sr_1d97(line, mv, mv + lv); ++ ++ for (i = 0; i < lv; i++) ++ t[w*i + lp] = l[i]; ++ } ++ } ++} ++ ++int ff_j2k_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type) ++{ ++ int i, j, lev = decomp_levels, maxlen, ++ b[2][2]; ++ ++ if ((unsigned)decomp_levels >= FF_DWT_MAX_DECLVLS) ++ return AVERROR_INVALIDDATA; ++ s->ndeclevels = decomp_levels; ++ s->type = type; ++ ++ for (i = 0; i < 2; i++) ++ for(j = 0; j < 2; j++) ++ b[i][j] = border[i][j]; ++ ++ maxlen = FFMAX(b[0][1] - b[0][0], ++ b[1][1] - b[1][0]); ++ ++ while(--lev >= 0){ ++ for (i = 0; i < 2; i++){ ++ s->linelen[lev][i] = b[i][1] - b[i][0]; ++ s->mod[lev][i] = b[i][0] & 1; ++ for (j = 0; j < 2; j++) ++ b[i][j] = (b[i][j] + 1) >> 1; ++ } ++ } ++ if (type == FF_DWT97) ++ s->linebuf = av_malloc((maxlen + 12) * sizeof(float)); ++ else if (type == FF_DWT53) ++ s->linebuf = av_malloc((maxlen + 6) * sizeof(int)); ++ else ++ return -1; ++ ++ if (!s->linebuf) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++int ff_j2k_dwt_encode(DWTContext *s, int *t) ++{ ++ switch(s->type){ ++ case FF_DWT97: ++ dwt_encode97(s, t); break; ++ case FF_DWT53: ++ dwt_encode53(s, t); break; ++ default: ++ return -1; ++ } ++ return 0; ++} ++ ++int ff_j2k_dwt_decode(DWTContext *s, int *t) ++{ ++ switch(s->type){ ++ case FF_DWT97: ++ dwt_decode97(s, t); break; ++ case FF_DWT53: ++ dwt_decode53(s, t); break; ++ default: ++ return -1; ++ } ++ return 0; ++} ++ ++void ff_j2k_dwt_destroy(DWTContext *s) ++{ ++ av_freep(&s->linebuf); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k_dwt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k_dwt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k_dwt.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k_dwt.h 2012-05-14 14:08:53.889331025 +0200 +@@ -0,0 +1,63 @@ ++/* ++ * Discrete wavelet transform ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_DWT_H ++#define AVCODEC_DWT_H ++ ++/** ++ * Discrete wavelet transform ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "avcodec.h" ++ ++#define FF_DWT_MAX_DECLVLS 32 ///< max number of decomposition levels ++ ++enum DWTType{ ++ FF_DWT97, ++ FF_DWT53 ++}; ++ ++typedef struct { ++ ///line lengths {horizontal, vertical} in consecutive decomposition levels ++ uint16_t linelen[FF_DWT_MAX_DECLVLS][2]; ++ uint8_t mod[FF_DWT_MAX_DECLVLS][2]; ///< coordinates (x0, y0) of decomp. levels mod 2 ++ uint8_t ndeclevels; ///< number of decomposition levels ++ uint8_t type; ///< 0 for 9/7; 1 for 5/3 ++ void *linebuf; ///< buffer used by transform (int or float) ++} DWTContext; ++ ++/** ++ * initialize DWT ++ * @param s DWT context ++ * @param border coordinates of transformed region {{x0, x1}, {y0, y1}} ++ * @param decomp_levels number of decomposition levels ++ * @param type 0 for DWT 9/7; 1 for DWT 5/3 ++ */ ++int ff_j2k_dwt_init(DWTContext *s, uint16_t border[2][2], int decomp_levels, int type); ++ ++int ff_j2k_dwt_encode(DWTContext *s, int *t); ++int ff_j2k_dwt_decode(DWTContext *s, int *t); ++ ++void ff_j2k_dwt_destroy(DWTContext *s); ++ ++#endif /* AVCODEC_DWT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2kenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2kenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2kenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2kenc.c 2012-05-14 14:08:53.894331127 +0200 +@@ -0,0 +1,1054 @@ ++/* ++ * JPEG2000 image encoder ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * JPEG2000 image encoder ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include ++#include "avcodec.h" ++#include "bytestream.h" ++#include "j2k.h" ++#include "libavutil/common.h" ++ ++#define NMSEDEC_BITS 7 ++#define NMSEDEC_FRACBITS (NMSEDEC_BITS-1) ++#define WMSEDEC_SHIFT 13 ///< must be >= 13 ++#define LAMBDA_SCALE (100000000LL << (WMSEDEC_SHIFT - 13)) ++ ++static int lut_nmsedec_ref [1<y1 - comp->y0; i++) ++ printv(comp->data + i * (comp->x1 - comp->x0), comp->x1 - comp->x0); ++} ++ ++static void dump(J2kEncoderContext *s, FILE *fd) ++{ ++ int tileno, compno, reslevelno, bandno, precno; ++ fprintf(fd, "XSiz = %d, YSiz = %d, tile_width = %d, tile_height = %d\n" ++ "numXtiles = %d, numYtiles = %d, ncomponents = %d\n" ++ "tiles:\n", ++ s->width, s->height, s->tile_width, s->tile_height, ++ s->numXtiles, s->numYtiles, s->ncomponents); ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ J2kTile *tile = s->tile + tileno; ++ nspaces(fd, 2); ++ fprintf(fd, "tile %d:\n", tileno); ++ for(compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ nspaces(fd, 4); ++ fprintf(fd, "component %d:\n", compno); ++ nspaces(fd, 4); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d\n", ++ comp->x0, comp->x1, comp->y0, comp->y1); ++ for(reslevelno = 0; reslevelno < s->nreslevels; reslevelno++){ ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ nspaces(fd, 6); ++ fprintf(fd, "reslevel %d:\n", reslevelno); ++ nspaces(fd, 6); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d, nbands = %d\n", ++ reslevel->x0, reslevel->x1, reslevel->y0, ++ reslevel->y1, reslevel->nbands); ++ for(bandno = 0; bandno < reslevel->nbands; bandno++){ ++ J2kBand *band = reslevel->band + bandno; ++ nspaces(fd, 8); ++ fprintf(fd, "band %d:\n", bandno); ++ nspaces(fd, 8); ++ fprintf(fd, "x0 = %d, x1 = %d, y0 = %d, y1 = %d," ++ "codeblock_width = %d, codeblock_height = %d cblknx = %d cblkny = %d\n", ++ band->x0, band->x1, ++ band->y0, band->y1, ++ band->codeblock_width, band->codeblock_height, ++ band->cblknx, band->cblkny); ++ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){ ++ J2kPrec *prec = band->prec + precno; ++ nspaces(fd, 10); ++ fprintf(fd, "prec %d:\n", precno); ++ nspaces(fd, 10); ++ fprintf(fd, "xi0 = %d, xi1 = %d, yi0 = %d, yi1 = %d\n", ++ prec->xi0, prec->xi1, prec->yi0, prec->yi1); ++ } ++ } ++ } ++ } ++ } ++} ++#endif ++ ++/* bitstream routines */ ++ ++/** put n times val bit */ ++static void put_bits(J2kEncoderContext *s, int val, int n) // TODO: optimize ++{ ++ while (n-- > 0){ ++ if (s->bit_index == 8) ++ { ++ s->bit_index = *s->buf == 0xff; ++ *(++s->buf) = 0; ++ } ++ *s->buf |= val << (7 - s->bit_index++); ++ } ++} ++ ++/** put n least significant bits of a number num */ ++static void put_num(J2kEncoderContext *s, int num, int n) ++{ ++ while(--n >= 0) ++ put_bits(s, (num >> n) & 1, 1); ++} ++ ++/** flush the bitstream */ ++static void j2k_flush(J2kEncoderContext *s) ++{ ++ if (s->bit_index){ ++ s->bit_index = 0; ++ s->buf++; ++ } ++} ++ ++/* tag tree routines */ ++ ++/** code the value stored in node */ ++static void tag_tree_code(J2kEncoderContext *s, J2kTgtNode *node, int threshold) ++{ ++ J2kTgtNode *stack[30]; ++ int sp = 1, curval = 0; ++ stack[0] = node; ++ ++ node = node->parent; ++ while(node){ ++ if (node->vis){ ++ curval = node->val; ++ break; ++ } ++ node->vis++; ++ stack[sp++] = node; ++ node = node->parent; ++ } ++ while(--sp >= 0){ ++ if (stack[sp]->val >= threshold){ ++ put_bits(s, 0, threshold - curval); ++ break; ++ } ++ put_bits(s, 0, stack[sp]->val - curval); ++ put_bits(s, 1, 1); ++ curval = stack[sp]->val; ++ } ++} ++ ++/** update the value in node */ ++static void tag_tree_update(J2kTgtNode *node) ++{ ++ int lev = 0; ++ while (node->parent){ ++ if (node->parent->val <= node->val) ++ break; ++ node->parent->val = node->val; ++ node = node->parent; ++ lev++; ++ } ++} ++ ++static int put_siz(J2kEncoderContext *s) ++{ ++ int i; ++ ++ if (s->buf_end - s->buf < 40 + 3 * s->ncomponents) ++ return -1; ++ ++ bytestream_put_be16(&s->buf, J2K_SIZ); ++ bytestream_put_be16(&s->buf, 38 + 3 * s->ncomponents); // Lsiz ++ bytestream_put_be16(&s->buf, 0); // Rsiz ++ bytestream_put_be32(&s->buf, s->width); // width ++ bytestream_put_be32(&s->buf, s->height); // height ++ bytestream_put_be32(&s->buf, 0); // X0Siz ++ bytestream_put_be32(&s->buf, 0); // Y0Siz ++ ++ bytestream_put_be32(&s->buf, s->tile_width); // XTSiz ++ bytestream_put_be32(&s->buf, s->tile_height); // YTSiz ++ bytestream_put_be32(&s->buf, 0); // XT0Siz ++ bytestream_put_be32(&s->buf, 0); // YT0Siz ++ bytestream_put_be16(&s->buf, s->ncomponents); // CSiz ++ ++ for (i = 0; i < s->ncomponents; i++){ // Ssiz_i XRsiz_i, YRsiz_i ++ bytestream_put_byte(&s->buf, 7); ++ bytestream_put_byte(&s->buf, i?1<chroma_shift[0]:1); ++ bytestream_put_byte(&s->buf, i?1<chroma_shift[1]:1); ++ } ++ return 0; ++} ++ ++static int put_cod(J2kEncoderContext *s) ++{ ++ J2kCodingStyle *codsty = &s->codsty; ++ ++ if (s->buf_end - s->buf < 14) ++ return -1; ++ ++ bytestream_put_be16(&s->buf, J2K_COD); ++ bytestream_put_be16(&s->buf, 12); // Lcod ++ bytestream_put_byte(&s->buf, 0); // Scod ++ // SGcod ++ bytestream_put_byte(&s->buf, 0); // progression level ++ bytestream_put_be16(&s->buf, 1); // num of layers ++ if(s->avctx->pix_fmt == PIX_FMT_YUV444P){ ++ bytestream_put_byte(&s->buf, 2); // ICT ++ }else{ ++ bytestream_put_byte(&s->buf, 0); // unspecified ++ } ++ // SPcod ++ bytestream_put_byte(&s->buf, codsty->nreslevels - 1); // num of decomp. levels ++ bytestream_put_byte(&s->buf, codsty->log2_cblk_width-2); // cblk width ++ bytestream_put_byte(&s->buf, codsty->log2_cblk_height-2); // cblk height ++ bytestream_put_byte(&s->buf, 0); // cblk style ++ bytestream_put_byte(&s->buf, codsty->transform); // transformation ++ return 0; ++} ++ ++static int put_qcd(J2kEncoderContext *s, int compno) ++{ ++ int i, size; ++ J2kCodingStyle *codsty = &s->codsty; ++ J2kQuantStyle *qntsty = &s->qntsty; ++ ++ if (qntsty->quantsty == J2K_QSTY_NONE) ++ size = 4 + 3 * (codsty->nreslevels-1); ++ else // QSTY_SE ++ size = 5 + 6 * (codsty->nreslevels-1); ++ ++ if (s->buf_end - s->buf < size + 2) ++ return -1; ++ ++ bytestream_put_be16(&s->buf, J2K_QCD); ++ bytestream_put_be16(&s->buf, size); // LQcd ++ bytestream_put_byte(&s->buf, (qntsty->nguardbits << 5) | qntsty->quantsty); // Sqcd ++ if (qntsty->quantsty == J2K_QSTY_NONE) ++ for (i = 0; i < codsty->nreslevels * 3 - 2; i++) ++ bytestream_put_byte(&s->buf, qntsty->expn[i] << 3); ++ else // QSTY_SE ++ for (i = 0; i < codsty->nreslevels * 3 - 2; i++) ++ bytestream_put_be16(&s->buf, (qntsty->expn[i] << 11) | qntsty->mant[i]); ++ return 0; ++} ++ ++static uint8_t *put_sot(J2kEncoderContext *s, int tileno) ++{ ++ uint8_t *psotptr; ++ ++ if (s->buf_end - s->buf < 12) ++ return NULL; ++ ++ bytestream_put_be16(&s->buf, J2K_SOT); ++ bytestream_put_be16(&s->buf, 10); // Lsot ++ bytestream_put_be16(&s->buf, tileno); // Isot ++ ++ psotptr = s->buf; ++ bytestream_put_be32(&s->buf, 0); // Psot (filled in later) ++ ++ bytestream_put_byte(&s->buf, 0); // TPsot ++ bytestream_put_byte(&s->buf, 1); // TNsot ++ return psotptr; ++} ++ ++/** ++ * compute the sizes of tiles, resolution levels, bands, etc. ++ * allocate memory for them ++ * divide the input image into tile-components ++ */ ++static int init_tiles(J2kEncoderContext *s) ++{ ++ int tileno, tilex, tiley, compno; ++ J2kCodingStyle *codsty = &s->codsty; ++ J2kQuantStyle *qntsty = &s->qntsty; ++ ++ s->numXtiles = ff_j2k_ceildiv(s->width, s->tile_width); ++ s->numYtiles = ff_j2k_ceildiv(s->height, s->tile_height); ++ ++ s->tile = av_malloc(s->numXtiles * s->numYtiles * sizeof(J2kTile)); ++ if (!s->tile) ++ return AVERROR(ENOMEM); ++ for (tileno = 0, tiley = 0; tiley < s->numYtiles; tiley++) ++ for (tilex = 0; tilex < s->numXtiles; tilex++, tileno++){ ++ J2kTile *tile = s->tile + tileno; ++ ++ tile->comp = av_malloc(s->ncomponents * sizeof(J2kComponent)); ++ if (!tile->comp) ++ return AVERROR(ENOMEM); ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ int ret, i, j; ++ ++ comp->coord[0][0] = tilex * s->tile_width; ++ comp->coord[0][1] = FFMIN((tilex+1)*s->tile_width, s->width); ++ comp->coord[1][0] = tiley * s->tile_height; ++ comp->coord[1][1] = FFMIN((tiley+1)*s->tile_height, s->height); ++ if (compno > 0) ++ for (i = 0; i < 2; i++) ++ for (j = 0; j < 2; j++) ++ comp->coord[i][j] = ff_j2k_ceildivpow2(comp->coord[i][j], s->chroma_shift[i]); ++ ++ if (ret = ff_j2k_init_component(comp, codsty, qntsty, s->cbps[compno], compno?1<chroma_shift[0]:1, compno?1<chroma_shift[1]:1)) ++ return ret; ++ } ++ } ++ return 0; ++} ++ ++static void copy_frame(J2kEncoderContext *s) ++{ ++ int tileno, compno, i, y, x; ++ uint8_t *line; ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ J2kTile *tile = s->tile + tileno; ++ if (s->planar){ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ int *dst = comp->data; ++ line = s->picture.data[compno] ++ + comp->coord[1][0] * s->picture.linesize[compno] ++ + comp->coord[0][0]; ++ for (y = comp->coord[1][0]; y < comp->coord[1][1]; y++){ ++ uint8_t *ptr = line; ++ for (x = comp->coord[0][0]; x < comp->coord[0][1]; x++) ++ *dst++ = *ptr++ - (1 << 7); ++ line += s->picture.linesize[compno]; ++ } ++ } ++ } else{ ++ line = s->picture.data[0] + tile->comp[0].coord[1][0] * s->picture.linesize[0] ++ + tile->comp[0].coord[0][0] * s->ncomponents; ++ ++ i = 0; ++ for (y = tile->comp[0].coord[1][0]; y < tile->comp[0].coord[1][1]; y++){ ++ uint8_t *ptr = line; ++ for (x = tile->comp[0].coord[0][0]; x < tile->comp[0].coord[0][1]; x++, i++){ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ tile->comp[compno].data[i] = *ptr++ - (1 << 7); ++ } ++ } ++ line += s->picture.linesize[0]; ++ } ++ } ++ } ++} ++ ++static void init_quantization(J2kEncoderContext *s) ++{ ++ int compno, reslevelno, bandno; ++ J2kQuantStyle *qntsty = &s->qntsty; ++ J2kCodingStyle *codsty = &s->codsty; ++ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ int gbandno = 0; ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ int nbands, lev = codsty->nreslevels - reslevelno - 1; ++ nbands = reslevelno ? 3 : 1; ++ for (bandno = 0; bandno < nbands; bandno++, gbandno++){ ++ int expn, mant; ++ ++ if (codsty->transform == FF_DWT97){ ++ int bandpos = bandno + (reslevelno>0), ++ ss = 81920000 / dwt_norms[0][bandpos][lev], ++ log = av_log2(ss); ++ mant = (11 - log < 0 ? ss >> log - 11 : ss << 11 - log) & 0x7ff; ++ expn = s->cbps[compno] - log + 13; ++ } else ++ expn = ((bandno&2)>>1) + (reslevelno>0) + s->cbps[compno]; ++ ++ qntsty->expn[gbandno] = expn; ++ qntsty->mant[gbandno] = mant; ++ } ++ } ++ } ++} ++ ++static void init_luts() ++{ ++ int i, a, ++ mask = ~((1<> (NMSEDEC_BITS-2)&2) + 1; ++ lut_nmsedec_ref[i] = FFMAX((-2*i + (1< NMSEDEC_FRACBITS) ++ return lut_nmsedec_sig[(x >> (bpno - NMSEDEC_FRACBITS)) & ((1 << NMSEDEC_BITS) - 1)]; ++ return lut_nmsedec_sig0[x & ((1 << NMSEDEC_BITS) - 1)]; ++} ++ ++static int getnmsedec_ref(int x, int bpno) ++{ ++ if (bpno > NMSEDEC_FRACBITS) ++ return lut_nmsedec_ref[(x >> (bpno - NMSEDEC_FRACBITS)) & ((1 << NMSEDEC_BITS) - 1)]; ++ return lut_nmsedec_ref0[x & ((1 << NMSEDEC_BITS) - 1)]; ++} ++ ++static void encode_sigpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno) ++{ ++ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); ++ int vert_causal_ctx_csty_loc_symbol; ++ for (y0 = 0; y0 < height; y0 += 4) ++ for (x = 0; x < width; x++) ++ for (y = y0; y < height && y < y0+4; y++){ ++ if (!(t1->flags[y+1][x+1] & J2K_T1_SIG) && (t1->flags[y+1][x+1] & J2K_T1_SIG_NB)){ ++ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol), ++ bit = t1->data[y][x] & mask ? 1 : 0; ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, bit); ++ if (bit){ ++ int xorbit; ++ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit); ++ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS); ++ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15); ++ } ++ t1->flags[y+1][x+1] |= J2K_T1_VIS; ++ } ++ } ++} ++ ++static void encode_refpass(J2kT1Context *t1, int width, int height, int *nmsedec, int bpno) ++{ ++ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); ++ for (y0 = 0; y0 < height; y0 += 4) ++ for (x = 0; x < width; x++) ++ for (y = y0; y < height && y < y0+4; y++) ++ if ((t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS)) == J2K_T1_SIG){ ++ int ctxno = ff_j2k_getrefctxno(t1->flags[y+1][x+1]); ++ *nmsedec += getnmsedec_ref(t1->data[y][x], bpno + NMSEDEC_FRACBITS); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0); ++ t1->flags[y+1][x+1] |= J2K_T1_REF; ++ } ++} ++ ++static void encode_clnpass(J2kT1Context *t1, int width, int height, int bandno, int *nmsedec, int bpno) ++{ ++ int y0, x, y, mask = 1 << (bpno + NMSEDEC_FRACBITS); ++ int vert_causal_ctx_csty_loc_symbol; ++ for (y0 = 0; y0 < height; y0 += 4) ++ for (x = 0; x < width; x++){ ++ if (y0 + 3 < height && !( ++ (t1->flags[y0+1][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+2][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+3][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)) || ++ (t1->flags[y0+4][x+1] & (J2K_T1_SIG_NB | J2K_T1_VIS | J2K_T1_SIG)))) ++ { ++ // aggregation mode ++ int rlen; ++ for (rlen = 0; rlen < 4; rlen++) ++ if (t1->data[y0+rlen][x] & mask) ++ break; ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_RL, rlen != 4); ++ if (rlen == 4) ++ continue; ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen >> 1); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + MQC_CX_UNI, rlen & 1); ++ for (y = y0 + rlen; y < y0 + 4; y++){ ++ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){ ++ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol); ++ if (y > y0 + rlen) ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0); ++ if (t1->data[y][x] & mask){ // newly significant ++ int xorbit; ++ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit); ++ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit); ++ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15); ++ } ++ } ++ t1->flags[y+1][x+1] &= ~J2K_T1_VIS; ++ } ++ } else{ ++ for (y = y0; y < y0 + 4 && y < height; y++){ ++ if (!(t1->flags[y+1][x+1] & (J2K_T1_SIG | J2K_T1_VIS))){ ++ int ctxno = ff_j2k_getnbctxno(t1->flags[y+1][x+1], bandno, vert_causal_ctx_csty_loc_symbol); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, t1->data[y][x] & mask ? 1:0); ++ if (t1->data[y][x] & mask){ // newly significant ++ int xorbit; ++ int ctxno = ff_j2k_getsgnctxno(t1->flags[y+1][x+1], &xorbit); ++ *nmsedec += getnmsedec_sig(t1->data[y][x], bpno + NMSEDEC_FRACBITS); ++ ff_mqc_encode(&t1->mqc, t1->mqc.cx_states + ctxno, (t1->flags[y+1][x+1] >> 15) ^ xorbit); ++ ff_j2k_set_significant(t1, x, y, t1->flags[y+1][x+1] >> 15); ++ } ++ } ++ t1->flags[y+1][x+1] &= ~J2K_T1_VIS; ++ } ++ } ++ } ++} ++ ++static void encode_cblk(J2kEncoderContext *s, J2kT1Context *t1, J2kCblk *cblk, J2kTile *tile, ++ int width, int height, int bandpos, int lev) ++{ ++ int pass_t = 2, passno, x, y, max=0, nmsedec, bpno; ++ int64_t wmsedec = 0; ++ ++ for (y = 0; y < height+2; y++) ++ memset(t1->flags[y], 0, (width+2)*sizeof(int)); ++ ++ for (y = 0; y < height; y++){ ++ for (x = 0; x < width; x++){ ++ if (t1->data[y][x] < 0){ ++ t1->flags[y+1][x+1] |= J2K_T1_SGN; ++ t1->data[y][x] = -t1->data[y][x]; ++ } ++ max = FFMAX(max, t1->data[y][x]); ++ } ++ } ++ ++ if (max == 0){ ++ cblk->nonzerobits = 0; ++ bpno = 0; ++ } else{ ++ cblk->nonzerobits = av_log2(max) + 1 - NMSEDEC_FRACBITS; ++ bpno = cblk->nonzerobits - 1; ++ } ++ ++ ff_mqc_initenc(&t1->mqc, cblk->data); ++ ++ for (passno = 0; bpno >= 0; passno++){ ++ nmsedec=0; ++ ++ switch(pass_t){ ++ case 0: encode_sigpass(t1, width, height, bandpos, &nmsedec, bpno); ++ break; ++ case 1: encode_refpass(t1, width, height, &nmsedec, bpno); ++ break; ++ case 2: encode_clnpass(t1, width, height, bandpos, &nmsedec, bpno); ++ break; ++ } ++ ++ cblk->passes[passno].rate = 3 + ff_mqc_length(&t1->mqc); ++ wmsedec += (int64_t)nmsedec << (2*bpno); ++ cblk->passes[passno].disto = wmsedec; ++ ++ if (++pass_t == 3){ ++ pass_t = 0; ++ bpno--; ++ } ++ } ++ cblk->npasses = passno; ++ cblk->ninclpasses = passno; ++ ++ // TODO: optional flush on each pass ++ cblk->passes[passno-1].rate = ff_mqc_flush(&t1->mqc); ++} ++ ++/* tier-2 routines: */ ++ ++static void putnumpasses(J2kEncoderContext *s, int n) ++{ ++ if (n == 1) ++ put_num(s, 0, 1); ++ else if (n == 2) ++ put_num(s, 2, 2); ++ else if (n <= 5) ++ put_num(s, 0xc | (n-3), 4); ++ else if (n <= 36) ++ put_num(s, 0x1e0 | (n-6), 9); ++ else ++ put_num(s, 0xff80 | (n-37), 16); ++} ++ ++ ++static int encode_packet(J2kEncoderContext *s, J2kResLevel *rlevel, int precno, ++ uint8_t *expn, int numgbits) ++{ ++ int bandno, empty = 1; ++ ++ // init bitstream ++ *s->buf = 0; ++ s->bit_index = 0; ++ ++ // header ++ ++ // is the packet empty? ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ if (rlevel->band[bandno].coord[0][0] < rlevel->band[bandno].coord[0][1] ++ && rlevel->band[bandno].coord[1][0] < rlevel->band[bandno].coord[1][1]){ ++ empty = 0; ++ break; ++ } ++ } ++ ++ put_bits(s, !empty, 1); ++ if (empty){ ++ j2k_flush(s); ++ return 0; ++ } ++ ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ J2kPrec *prec = band->prec + precno; ++ int yi, xi, pos; ++ int cblknw = prec->xi1 - prec->xi0; ++ ++ if (band->coord[0][0] == band->coord[0][1] ++ || band->coord[1][0] == band->coord[1][1]) ++ continue; ++ ++ for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){ ++ for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){ ++ prec->cblkincl[pos].val = band->cblk[yi * cblknw + xi].ninclpasses == 0; ++ tag_tree_update(prec->cblkincl + pos); ++ prec->zerobits[pos].val = expn[bandno] + numgbits - 1 - band->cblk[yi * cblknw + xi].nonzerobits; ++ tag_tree_update(prec->zerobits + pos); ++ } ++ } ++ ++ for (pos=0, yi = prec->yi0; yi < prec->yi1; yi++){ ++ for (xi = prec->xi0; xi < prec->xi1; xi++, pos++){ ++ int pad = 0, llen, length; ++ J2kCblk *cblk = band->cblk + yi * cblknw + xi; ++ ++ if (s->buf_end - s->buf < 20) // approximately ++ return -1; ++ ++ // inclusion information ++ tag_tree_code(s, prec->cblkincl + pos, 1); ++ if (!cblk->ninclpasses) ++ continue; ++ // zerobits information ++ tag_tree_code(s, prec->zerobits + pos, 100); ++ // number of passes ++ putnumpasses(s, cblk->ninclpasses); ++ ++ length = cblk->passes[cblk->ninclpasses-1].rate; ++ llen = av_log2(length) - av_log2(cblk->ninclpasses) - 2; ++ if (llen < 0){ ++ pad = -llen; ++ llen = 0; ++ } ++ // length of code block ++ put_bits(s, 1, llen); ++ put_bits(s, 0, 1); ++ put_num(s, length, av_log2(length)+1+pad); ++ } ++ } ++ } ++ j2k_flush(s); ++ for (bandno = 0; bandno < rlevel->nbands; bandno++){ ++ J2kBand *band = rlevel->band + bandno; ++ J2kPrec *prec = band->prec + precno; ++ int yi, cblknw = prec->xi1 - prec->xi0; ++ for (yi = prec->yi0; yi < prec->yi1; yi++){ ++ int xi; ++ for (xi = prec->xi0; xi < prec->xi1; xi++){ ++ J2kCblk *cblk = band->cblk + yi * cblknw + xi; ++ if (cblk->ninclpasses){ ++ if (s->buf_end - s->buf < cblk->passes[cblk->ninclpasses-1].rate) ++ return -1; ++ bytestream_put_buffer(&s->buf, cblk->data, cblk->passes[cblk->ninclpasses-1].rate); ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++static int encode_packets(J2kEncoderContext *s, J2kTile *tile, int tileno) ++{ ++ int compno, reslevelno, ret; ++ J2kCodingStyle *codsty = &s->codsty; ++ J2kQuantStyle *qntsty = &s->qntsty; ++ ++ av_log(s->avctx, AV_LOG_DEBUG, "tier2\n"); ++ // lay-rlevel-comp-pos progression ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ int precno; ++ J2kResLevel *reslevel = s->tile[tileno].comp[compno].reslevel + reslevelno; ++ for (precno = 0; precno < reslevel->num_precincts_x * reslevel->num_precincts_y; precno++){ ++ if (ret = encode_packet(s, reslevel, precno, qntsty->expn + (reslevelno ? 3*reslevelno-2 : 0), ++ qntsty->nguardbits)) ++ return ret; ++ } ++ } ++ } ++ av_log(s->avctx, AV_LOG_DEBUG, "after tier2\n"); ++ return 0; ++} ++ ++static int getcut(J2kCblk *cblk, int64_t lambda, int dwt_norm) ++{ ++ int passno, res = 0; ++ for (passno = 0; passno < cblk->npasses; passno++){ ++ int dr; ++ int64_t dd; ++ ++ dr = cblk->passes[passno].rate ++ - (res ? cblk->passes[res-1].rate:0); ++ dd = cblk->passes[passno].disto ++ - (res ? cblk->passes[res-1].disto:0); ++ ++ if (((dd * dwt_norm) >> WMSEDEC_SHIFT) * dwt_norm >= dr * lambda) ++ res = passno+1; ++ } ++ return res; ++} ++ ++static void truncpasses(J2kEncoderContext *s, J2kTile *tile) ++{ ++ int compno, reslevelno, bandno, cblkno, lev; ++ J2kCodingStyle *codsty = &s->codsty; ++ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = tile->comp + compno; ++ ++ for (reslevelno = 0, lev = codsty->nreslevels-1; reslevelno < codsty->nreslevels; reslevelno++, lev--){ ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ ++ for (bandno = 0; bandno < reslevel->nbands ; bandno++){ ++ int bandpos = bandno + (reslevelno > 0); ++ J2kBand *band = reslevel->band + bandno; ++ ++ for (cblkno = 0; cblkno < band->cblknx * band->cblkny; cblkno++){ ++ J2kCblk *cblk = band->cblk + cblkno; ++ ++ cblk->ninclpasses = getcut(cblk, s->lambda, ++ (int64_t)dwt_norms[codsty->transform][bandpos][lev] * (int64_t)band->stepsize >> 13); ++ } ++ } ++ } ++ } ++} ++ ++static int encode_tile(J2kEncoderContext *s, J2kTile *tile, int tileno) ++{ ++ int compno, reslevelno, bandno, ret; ++ J2kT1Context t1; ++ J2kCodingStyle *codsty = &s->codsty; ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = s->tile[tileno].comp + compno; ++ ++ av_log(s->avctx, AV_LOG_DEBUG,"dwt\n"); ++ if (ret = ff_j2k_dwt_encode(&comp->dwt, comp->data)) ++ return ret; ++ av_log(s->avctx, AV_LOG_DEBUG,"after dwt -> tier1\n"); ++ ++ for (reslevelno = 0; reslevelno < codsty->nreslevels; reslevelno++){ ++ J2kResLevel *reslevel = comp->reslevel + reslevelno; ++ ++ for (bandno = 0; bandno < reslevel->nbands ; bandno++){ ++ J2kBand *band = reslevel->band + bandno; ++ int cblkx, cblky, cblkno=0, xx0, x0, xx1, y0, yy0, yy1, bandpos; ++ yy0 = bandno == 0 ? 0 : comp->reslevel[reslevelno-1].coord[1][1] - comp->reslevel[reslevelno-1].coord[1][0]; ++ y0 = yy0; ++ yy1 = FFMIN(ff_j2k_ceildiv(band->coord[1][0] + 1, band->codeblock_height) * band->codeblock_height, ++ band->coord[1][1]) - band->coord[1][0] + yy0; ++ ++ if (band->coord[0][0] == band->coord[0][1] || band->coord[1][0] == band->coord[1][1]) ++ continue; ++ ++ bandpos = bandno + (reslevelno > 0); ++ ++ for (cblky = 0; cblky < band->cblkny; cblky++){ ++ if (reslevelno == 0 || bandno == 1) ++ xx0 = 0; ++ else ++ xx0 = comp->reslevel[reslevelno-1].coord[0][1] - comp->reslevel[reslevelno-1].coord[0][0]; ++ x0 = xx0; ++ xx1 = FFMIN(ff_j2k_ceildiv(band->coord[0][0] + 1, band->codeblock_width) * band->codeblock_width, ++ band->coord[0][1]) - band->coord[0][0] + xx0; ++ ++ for (cblkx = 0; cblkx < band->cblknx; cblkx++, cblkno++){ ++ int y, x; ++ if (codsty->transform == FF_DWT53){ ++ for (y = yy0; y < yy1; y++){ ++ int *ptr = t1.data[y-yy0]; ++ for (x = xx0; x < xx1; x++){ ++ *ptr++ = comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x] << NMSEDEC_FRACBITS; ++ } ++ } ++ } else{ ++ for (y = yy0; y < yy1; y++){ ++ int *ptr = t1.data[y-yy0]; ++ for (x = xx0; x < xx1; x++){ ++ *ptr = (comp->data[(comp->coord[0][1] - comp->coord[0][0]) * y + x]); ++ *ptr = (int64_t)*ptr * (int64_t)(8192 * 8192 / band->stepsize) >> 13 - NMSEDEC_FRACBITS; ++ *ptr++; ++ } ++ } ++ } ++ encode_cblk(s, &t1, band->cblk + cblkno, tile, xx1 - xx0, yy1 - yy0, ++ bandpos, codsty->nreslevels - reslevelno - 1); ++ xx0 = xx1; ++ xx1 = FFMIN(xx1 + band->codeblock_width, band->coord[0][1] - band->coord[0][0] + x0); ++ } ++ yy0 = yy1; ++ yy1 = FFMIN(yy1 + band->codeblock_height, band->coord[1][1] - band->coord[1][0] + y0); ++ } ++ } ++ } ++ av_log(s->avctx, AV_LOG_DEBUG, "after tier1\n"); ++ } ++ ++ av_log(s->avctx, AV_LOG_DEBUG, "rate control\n"); ++ truncpasses(s, tile); ++ if (ret = encode_packets(s, tile, tileno)) ++ return ret; ++ av_log(s->avctx, AV_LOG_DEBUG, "after rate control\n"); ++ return 0; ++} ++ ++static void cleanup(J2kEncoderContext *s) ++{ ++ int tileno, compno; ++ J2kCodingStyle *codsty = &s->codsty; ++ ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ for (compno = 0; compno < s->ncomponents; compno++){ ++ J2kComponent *comp = s->tile[tileno].comp + compno; ++ ff_j2k_cleanup(comp, codsty); ++ } ++ av_freep(&s->tile[tileno].comp); ++ } ++ av_freep(&s->tile); ++} ++ ++static void reinit(J2kEncoderContext *s) ++{ ++ int tileno, compno; ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ J2kTile *tile = s->tile + tileno; ++ for (compno = 0; compno < s->ncomponents; compno++) ++ ff_j2k_reinit(tile->comp + compno, &s->codsty); ++ } ++} ++ ++static int encode_frame(AVCodecContext *avctx, ++ uint8_t *buf, int buf_size, ++ void *data) ++{ ++ int tileno, ret; ++ J2kEncoderContext *s = avctx->priv_data; ++ ++ // init: ++ s->buf = s->buf_start = buf; ++ s->buf_end = buf + buf_size; ++ ++ s->picture = *(AVFrame*)data; ++ avctx->coded_frame= &s->picture; ++ ++ s->lambda = s->picture.quality * LAMBDA_SCALE; ++ ++ copy_frame(s); ++ reinit(s); ++ ++ if (s->buf_end - s->buf < 2) ++ return -1; ++ bytestream_put_be16(&s->buf, J2K_SOC); ++ if (ret = put_siz(s)) ++ return ret; ++ if (ret = put_cod(s)) ++ return ret; ++ if (ret = put_qcd(s, 0)) ++ return ret; ++ ++ for (tileno = 0; tileno < s->numXtiles * s->numYtiles; tileno++){ ++ uint8_t *psotptr; ++ if (!(psotptr = put_sot(s, tileno))) ++ return -1; ++ if (s->buf_end - s->buf < 2) ++ return -1; ++ bytestream_put_be16(&s->buf, J2K_SOD); ++ if (ret = encode_tile(s, s->tile + tileno, tileno)) ++ return ret; ++ bytestream_put_be32(&psotptr, s->buf - psotptr + 6); ++ } ++ if (s->buf_end - s->buf < 2) ++ return -1; ++ bytestream_put_be16(&s->buf, J2K_EOC); ++ ++ av_log(s->avctx, AV_LOG_DEBUG, "end\n"); ++ return s->buf - s->buf_start; ++} ++ ++static av_cold int j2kenc_init(AVCodecContext *avctx) ++{ ++ int i, ret; ++ J2kEncoderContext *s = avctx->priv_data; ++ J2kCodingStyle *codsty = &s->codsty; ++ J2kQuantStyle *qntsty = &s->qntsty; ++ ++ s->avctx = avctx; ++ av_log(s->avctx, AV_LOG_DEBUG, "init\n"); ++ ++ // defaults: ++ // TODO: implement setting non-standard precinct size ++ codsty->log2_prec_width = 15; ++ codsty->log2_prec_height = 15; ++ codsty->nreslevels = 7; ++ codsty->log2_cblk_width = 4; ++ codsty->log2_cblk_height = 4; ++ codsty->transform = 1; ++ ++ qntsty->nguardbits = 1; ++ ++ s->tile_width = 256; ++ s->tile_height = 256; ++ ++ if (codsty->transform == FF_DWT53) ++ qntsty->quantsty = J2K_QSTY_NONE; ++ else ++ qntsty->quantsty = J2K_QSTY_SE; ++ ++ s->width = avctx->width; ++ s->height = avctx->height; ++ ++ for (i = 0; i < 3; i++) ++ s->cbps[i] = 8; ++ ++ if (avctx->pix_fmt == PIX_FMT_RGB24){ ++ s->ncomponents = 3; ++ } else if (avctx->pix_fmt == PIX_FMT_GRAY8){ ++ s->ncomponents = 1; ++ } else{ // planar YUV ++ s->planar = 1; ++ s->ncomponents = 3; ++ avcodec_get_chroma_sub_sample(avctx->pix_fmt, ++ s->chroma_shift, s->chroma_shift + 1); ++ } ++ ++ ff_j2k_init_tier1_luts(); ++ ++ init_luts(); ++ ++ init_quantization(s); ++ if (ret=init_tiles(s)) ++ return ret; ++ ++ av_log(s->avctx, AV_LOG_DEBUG, "after init\n"); ++ ++ return 0; ++} ++ ++static int j2kenc_destroy(AVCodecContext *avctx) ++{ ++ J2kEncoderContext *s = avctx->priv_data; ++ ++ cleanup(s); ++ return 0; ++} ++ ++AVCodec ff_jpeg2000_encoder = { ++ .name = "j2k", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEG2000, ++ .priv_data_size = sizeof(J2kEncoderContext), ++ .init = j2kenc_init, ++ .encode = encode_frame, ++ .close = j2kenc_destroy, ++ .capabilities= CODEC_CAP_EXPERIMENTAL, ++ .long_name = NULL_IF_CONFIG_SMALL("JPEG 2000"), ++ .pix_fmts = ++ (const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_YUV444P, PIX_FMT_GRAY8, ++/* PIX_FMT_YUV420P, ++ PIX_FMT_YUV422P, PIX_FMT_YUV444P, ++ PIX_FMT_YUV410P, PIX_FMT_YUV411P,*/ ++ -1} ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/j2k.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/j2k.h 2012-05-14 14:08:53.887330985 +0200 +@@ -0,0 +1,234 @@ ++/* ++ * JPEG2000 tables ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_J2K_H ++#define AVCODEC_J2K_H ++ ++/** ++ * JPEG2000 tables ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "mqc.h" ++#include "j2k_dwt.h" ++ ++enum J2kMarkers{ ++ J2K_SOC = 0xff4f, ///< start of codestream ++ J2K_SIZ = 0xff51, ///< image and tile size ++ J2K_COD, ///< coding style default ++ J2K_COC, ///< coding style component ++ J2K_TLM = 0xff55, ///< packed packet headers, tile-part header ++ J2K_PLM = 0xff57, ///< tile-part lengths ++ J2K_PLT, ///< packet length, main header ++ J2K_QCD = 0xff5c, ///< quantization default ++ J2K_QCC, ///< quantization component ++ J2K_RGN, ///< region of interest ++ J2K_POC, ///< progression order change ++ J2K_PPM, ///< packet length, tile-part header ++ J2K_PPT, ///< packed packet headers, main header ++ J2K_CRG = 0xff63, ///< component registration ++ J2K_COM, ///< comment ++ J2K_SOT = 0xff90, ///< start of tile-part ++ J2K_SOP, ///< start of packet ++ J2K_EPH, ///< end of packet header ++ J2K_SOD, ///< start of data ++ J2K_EOC = 0xffd9, ///< end of codestream ++}; ++ ++enum J2kQuantsty{ ///< quantization style ++ J2K_QSTY_NONE, ///< no quantization ++ J2K_QSTY_SI, ///< scalar derived ++ J2K_QSTY_SE ///< scalar expoounded ++}; ++ ++#define J2K_MAX_CBLKW 64 ++#define J2K_MAX_CBLKH 64 ++ ++// T1 flags ++// flags determining significance of neighbour coefficients ++#define J2K_T1_SIG_N 0x0001 ++#define J2K_T1_SIG_E 0x0002 ++#define J2K_T1_SIG_W 0x0004 ++#define J2K_T1_SIG_S 0x0008 ++#define J2K_T1_SIG_NE 0x0010 ++#define J2K_T1_SIG_NW 0x0020 ++#define J2K_T1_SIG_SE 0x0040 ++#define J2K_T1_SIG_SW 0x0080 ++#define J2K_T1_SIG_NB (J2K_T1_SIG_N | J2K_T1_SIG_E | J2K_T1_SIG_S | J2K_T1_SIG_W \ ++ |J2K_T1_SIG_NE | J2K_T1_SIG_NW | J2K_T1_SIG_SE | J2K_T1_SIG_SW) ++// flags determining sign bit of neighbour coefficients ++#define J2K_T1_SGN_N 0x0100 ++#define J2K_T1_SGN_S 0x0200 ++#define J2K_T1_SGN_W 0x0400 ++#define J2K_T1_SGN_E 0x0800 ++ ++#define J2K_T1_VIS 0x1000 ++#define J2K_T1_SIG 0x2000 ++#define J2K_T1_REF 0x4000 ++ ++#define J2K_T1_SGN 0x8000 ++ ++// Codeblock coding styles ++#define J2K_CBLK_BYPASS 0x01 // Selective arithmetic coding bypass ++#define J2K_CBLK_RESET 0x02 // Reset context probabilities ++#define J2K_CBLK_TERMALL 0x04 // Terminate after each coding pass ++#define J2K_CBLK_VSC 0x08 // Vertical stripe causal context formation ++#define J2K_CBLK_PREDTERM 0x10 // Predictable termination ++#define J2K_CBLK_SEGSYM 0x20 // Segmentation symbols present ++ ++// Coding styles ++#define J2K_CSTY_PREC 0x01 // Precincts defined in coding style ++#define J2K_CSTY_SOP 0x02 // SOP marker present ++#define J2K_CSTY_EPH 0x04 // EPH marker present ++ ++typedef struct { ++ int data[J2K_MAX_CBLKW][J2K_MAX_CBLKH]; ++ int flags[J2K_MAX_CBLKW+2][J2K_MAX_CBLKH+2]; ++ MqcState mqc; ++} J2kT1Context; ++ ++typedef struct J2kTgtNode { ++ uint8_t val; ++ uint8_t vis; ++ struct J2kTgtNode *parent; ++} J2kTgtNode; ++ ++typedef struct { ++ uint8_t nreslevels; ///< number of resolution levels ++ uint8_t log2_cblk_width, ++ log2_cblk_height; ///< exponent of codeblock size ++ uint8_t transform; ///< DWT type ++ uint8_t csty; ///< coding style ++ uint8_t log2_prec_width, ++ log2_prec_height; ///< precinct size ++ uint8_t nlayers; ///< number of layers ++ uint8_t mct; ///< multiple component transformation ++ uint8_t cblk_style; ///< codeblock coding style ++} J2kCodingStyle; ++ ++typedef struct { ++ uint8_t expn[32 * 3]; ///< quantization exponent ++ uint16_t mant[32 * 3]; ///< quantization mantissa ++ uint8_t quantsty; ///< quantization style ++ uint8_t nguardbits; ///< number of guard bits ++} J2kQuantStyle; ++ ++typedef struct { ++ uint16_t rate; ++ int64_t disto; ++} J2kPass; ++ ++typedef struct { ++ uint8_t npasses; ++ uint8_t ninclpasses; ///< number coding of passes included in codestream ++ uint8_t nonzerobits; ++ uint16_t length; ++ uint16_t lengthinc; ++ uint8_t lblock; ++ uint8_t zero; ++ uint8_t data[8192]; ++ J2kPass passes[100]; ++} J2kCblk; ///< code block ++ ++typedef struct { ++ uint16_t xi0, xi1, yi0, yi1; ///< codeblock indexes ([xi0, xi1)) ++ J2kTgtNode *zerobits; ++ J2kTgtNode *cblkincl; ++} J2kPrec; ///< precinct ++ ++typedef struct { ++ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}} ++ uint16_t codeblock_width, codeblock_height; ++ uint16_t cblknx, cblkny; ++ uint32_t stepsize; ///< quantization stepsize (* 2^13) ++ J2kPrec *prec; ++ J2kCblk *cblk; ++} J2kBand; ///< subband ++ ++typedef struct { ++ uint8_t nbands; ++ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}} ++ uint16_t num_precincts_x, num_precincts_y; ///< number of precincts in x/y direction ++ uint8_t log2_prec_width, log2_prec_height; ///< exponent of precinct size ++ J2kBand *band; ++} J2kResLevel; ///< resolution level ++ ++typedef struct { ++ J2kResLevel *reslevel; ++ DWTContext dwt; ++ int *data; ++ uint16_t coord[2][2]; ///< border coordinates {{x0, x1}, {y0, y1}} ++} J2kComponent; ++ ++/* debug routines */ ++#if 0 ++#undef fprintf ++#undef printf ++void ff_j2k_printv(int *tab, int l); ++void ff_j2k_printu(uint8_t *tab, int l); ++#endif ++ ++/* misc tools */ ++static inline int ff_j2k_ceildivpow2(int a, int b) ++{ ++ return (a + (1 << b) - 1)>> b; ++} ++ ++static inline int ff_j2k_ceildiv(int a, int b) ++{ ++ return (a + b - 1) / b; ++} ++ ++/* tag tree routines */ ++J2kTgtNode *ff_j2k_tag_tree_init(int w, int h); ++ ++/* TIER-1 routines */ ++void ff_j2k_init_tier1_luts(void); ++ ++void ff_j2k_set_significant(J2kT1Context *t1, int x, int y, int negative); ++ ++extern uint8_t ff_j2k_nbctxno_lut[256][4]; ++ ++static inline int ff_j2k_getnbctxno(int flag, int bandno, int vert_causal_ctx_csty_symbol) ++{ ++ return ff_j2k_nbctxno_lut[flag&255][bandno]; ++} ++ ++static inline int ff_j2k_getrefctxno(int flag) ++{ ++ static const uint8_t refctxno_lut[2][2] = {{14, 15}, {16, 16}}; ++ return refctxno_lut[(flag>>14)&1][(flag & 255) != 0]; ++} ++ ++extern uint8_t ff_j2k_sgnctxno_lut[16][16], ff_j2k_xorbit_lut[16][16]; ++ ++static inline int ff_j2k_getsgnctxno(int flag, int *xorbit) ++{ ++ *xorbit = ff_j2k_xorbit_lut[flag&15][(flag>>8)&15]; ++ return ff_j2k_sgnctxno_lut[flag&15][(flag>>8)&15]; ++} ++ ++int ff_j2k_init_component(J2kComponent *comp, J2kCodingStyle *codsty, J2kQuantStyle *qntsty, int cbps, int dx, int dy); ++void ff_j2k_reinit(J2kComponent *comp, J2kCodingStyle *codsty); ++void ff_j2k_cleanup(J2kComponent *comp, J2kCodingStyle *codsty); ++ ++#endif /* AVCODEC_J2K_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctfst.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctfst.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctfst.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctfst.c 2012-05-14 14:08:53.895331147 +0200 +@@ -1,6 +1,4 @@ + /* +- * jfdctfst.c +- * + * This file is part of the Independent JPEG Group's software. + * + * The authors make NO WARRANTY or representation, either express or implied, +@@ -145,9 +143,9 @@ + #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS)) + + static av_always_inline void row_fdct(DCTELEM * data){ +- int_fast16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast16_t tmp10, tmp11, tmp12, tmp13; +- int_fast16_t z1, z2, z3, z4, z5, z11, z13; ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1, z2, z3, z4, z5, z11, z13; + DCTELEM *dataptr; + int ctr; + +@@ -209,9 +207,9 @@ + GLOBAL(void) + fdct_ifast (DCTELEM * data) + { +- int_fast16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast16_t tmp10, tmp11, tmp12, tmp13; +- int_fast16_t z1, z2, z3, z4, z5, z11, z13; ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1, z2, z3, z4, z5, z11, z13; + DCTELEM *dataptr; + int ctr; + +@@ -275,9 +273,9 @@ + GLOBAL(void) + fdct_ifast248 (DCTELEM * data) + { +- int_fast16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast16_t tmp10, tmp11, tmp12, tmp13; +- int_fast16_t z1; ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1; + DCTELEM *dataptr; + int ctr; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctint.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctint.c 2012-05-14 14:08:53.897331187 +0200 +@@ -1,402 +1,25 @@ +-/* +- * jfdctint.c +- * +- * This file is part of the Independent JPEG Group's software. +- * +- * The authors make NO WARRANTY or representation, either express or implied, +- * with respect to this software, its quality, accuracy, merchantability, or +- * fitness for a particular purpose. This software is provided "AS IS", and +- * you, its user, assume the entire risk as to its quality and accuracy. +- * +- * This software is copyright (C) 1991-1996, Thomas G. Lane. +- * All Rights Reserved except as specified below. +- * +- * Permission is hereby granted to use, copy, modify, and distribute this +- * software (or portions thereof) for any purpose, without fee, subject to +- * these conditions: +- * (1) If any part of the source code for this software is distributed, then +- * this README file must be included, with this copyright and no-warranty +- * notice unaltered; and any additions, deletions, or changes to the original +- * files must be clearly indicated in accompanying documentation. +- * (2) If only executable code is distributed, then the accompanying +- * documentation must state that "this software is based in part on the work +- * of the Independent JPEG Group". +- * (3) Permission for use of this software is granted only if the user accepts +- * full responsibility for any undesirable consequences; the authors accept +- * NO LIABILITY for damages of any kind. +- * +- * These conditions apply to any software derived from or based on the IJG +- * code, not just to the unmodified library. If you use our work, you ought +- * to acknowledge us. +- * +- * Permission is NOT granted for the use of any IJG author's name or company +- * name in advertising or publicity relating to this software or products +- * derived from it. This software may be referred to only as "the Independent +- * JPEG Group's software". +- * +- * We specifically permit and encourage the use of this software as the basis +- * of commercial products, provided that all warranty or liability claims are +- * assumed by the product vendor. +- * +- * This file contains a slow-but-accurate integer implementation of the +- * forward DCT (Discrete Cosine Transform). +- * +- * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT +- * on each column. Direct algorithms are also available, but they are +- * much more complex and seem not to be any faster when reduced to code. +- * +- * This implementation is based on an algorithm described in +- * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT +- * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, +- * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. +- * The primary algorithm described there uses 11 multiplies and 29 adds. +- * We use their alternate method with 12 multiplies and 32 adds. +- * The advantage of this method is that no data path contains more than one +- * multiplication; this allows a very simple and accurate implementation in +- * scaled fixed-point arithmetic, with a minimal number of shifts. +- */ +- + /** +- * @file +- * Independent JPEG Group's slow & accurate dct. +- */ +- +-#include +-#include +-#include "libavutil/common.h" +-#include "dsputil.h" +- +-#define DCTSIZE 8 +-#define BITS_IN_JSAMPLE 8 +-#define GLOBAL(x) x +-#define RIGHT_SHIFT(x, n) ((x) >> (n)) +-#define MULTIPLY16C16(var,const) ((var)*(const)) +- +-#if 1 //def USE_ACCURATE_ROUNDING +-#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n) +-#else +-#define DESCALE(x,n) RIGHT_SHIFT(x, n) +-#endif +- +- +-/* +- * This module is specialized to the case DCTSIZE = 8. +- */ +- +-#if DCTSIZE != 8 +- Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */ +-#endif +- +- +-/* +- * The poop on this scaling stuff is as follows: +- * +- * Each 1-D DCT step produces outputs which are a factor of sqrt(N) +- * larger than the true DCT outputs. The final outputs are therefore +- * a factor of N larger than desired; since N=8 this can be cured by +- * a simple right shift at the end of the algorithm. The advantage of +- * this arrangement is that we save two multiplications per 1-D DCT, +- * because the y0 and y4 outputs need not be divided by sqrt(N). +- * In the IJG code, this factor of 8 is removed by the quantization step +- * (in jcdctmgr.c), NOT in this module. +- * +- * We have to do addition and subtraction of the integer inputs, which +- * is no problem, and multiplication by fractional constants, which is +- * a problem to do in integer arithmetic. We multiply all the constants +- * by CONST_SCALE and convert them to integer constants (thus retaining +- * CONST_BITS bits of precision in the constants). After doing a +- * multiplication we have to divide the product by CONST_SCALE, with proper +- * rounding, to produce the correct output. This division can be done +- * cheaply as a right shift of CONST_BITS bits. We postpone shifting +- * as long as possible so that partial sums can be added together with +- * full fractional precision. ++ * This file is part of Libav. + * +- * The outputs of the first pass are scaled up by PASS1_BITS bits so that +- * they are represented to better-than-integral precision. These outputs +- * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word +- * with the recommended scaling. (For 12-bit sample data, the intermediate +- * array is int32_t anyway.) +- * +- * To avoid overflow of the 32-bit intermediate results in pass 2, we must +- * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis +- * shows that the values given below are the most effective. +- */ +- +-#if BITS_IN_JSAMPLE == 8 +-#define CONST_BITS 13 +-#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */ +-#else +-#define CONST_BITS 13 +-#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ +-#endif +- +-/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus +- * causing a lot of useless floating-point operations at run time. +- * To get around this we use the following pre-calculated constants. +- * If you change CONST_BITS you may want to add appropriate values. +- * (With a reasonable C compiler, you can just rely on the FIX() macro...) +- */ +- +-#if CONST_BITS == 13 +-#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */ +-#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */ +-#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */ +-#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */ +-#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */ +-#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */ +-#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */ +-#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */ +-#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */ +-#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */ +-#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */ +-#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */ +-#else +-#define FIX_0_298631336 FIX(0.298631336) +-#define FIX_0_390180644 FIX(0.390180644) +-#define FIX_0_541196100 FIX(0.541196100) +-#define FIX_0_765366865 FIX(0.765366865) +-#define FIX_0_899976223 FIX(0.899976223) +-#define FIX_1_175875602 FIX(1.175875602) +-#define FIX_1_501321110 FIX(1.501321110) +-#define FIX_1_847759065 FIX(1.847759065) +-#define FIX_1_961570560 FIX(1.961570560) +-#define FIX_2_053119869 FIX(2.053119869) +-#define FIX_2_562915447 FIX(2.562915447) +-#define FIX_3_072711026 FIX(3.072711026) +-#endif +- +- +-/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result. +- * For 8-bit samples with the recommended scaling, all the variable +- * and constant values involved are no more than 16 bits wide, so a +- * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. +- * For 12-bit samples, a full 32-bit multiplication will be needed. +- */ +- +-#if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2 +-#define MULTIPLY(var,const) MULTIPLY16C16(var,const) +-#else +-#define MULTIPLY(var,const) ((var) * (const)) +-#endif +- +- +-static av_always_inline void row_fdct(DCTELEM * data){ +- int_fast32_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast32_t tmp10, tmp11, tmp12, tmp13; +- int_fast32_t z1, z2, z3, z4, z5; +- DCTELEM *dataptr; +- int ctr; +- +- /* Pass 1: process rows. */ +- /* Note results are scaled up by sqrt(8) compared to a true DCT; */ +- /* furthermore, we scale the results by 2**PASS1_BITS. */ +- +- dataptr = data; +- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { +- tmp0 = dataptr[0] + dataptr[7]; +- tmp7 = dataptr[0] - dataptr[7]; +- tmp1 = dataptr[1] + dataptr[6]; +- tmp6 = dataptr[1] - dataptr[6]; +- tmp2 = dataptr[2] + dataptr[5]; +- tmp5 = dataptr[2] - dataptr[5]; +- tmp3 = dataptr[3] + dataptr[4]; +- tmp4 = dataptr[3] - dataptr[4]; +- +- /* Even part per LL&M figure 1 --- note that published figure is faulty; +- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". +- */ +- +- tmp10 = tmp0 + tmp3; +- tmp13 = tmp0 - tmp3; +- tmp11 = tmp1 + tmp2; +- tmp12 = tmp1 - tmp2; +- +- dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); +- dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); +- +- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); +- dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), +- CONST_BITS-PASS1_BITS); +- dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), +- CONST_BITS-PASS1_BITS); +- +- /* Odd part per figure 8 --- note paper omits factor of sqrt(2). +- * cK represents cos(K*pi/16). +- * i0..i3 in the paper are tmp4..tmp7 here. +- */ +- +- z1 = tmp4 + tmp7; +- z2 = tmp5 + tmp6; +- z3 = tmp4 + tmp6; +- z4 = tmp5 + tmp7; +- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ +- +- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ +- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ +- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ +- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ +- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ +- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ +- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ +- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ +- +- z3 += z5; +- z4 += z5; +- +- dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); +- dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); +- dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); +- dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); +- +- dataptr += DCTSIZE; /* advance pointer to next row */ +- } +-} +- +-/* +- * Perform the forward DCT on one block of samples. +- */ +- +-GLOBAL(void) +-ff_jpeg_fdct_islow (DCTELEM * data) +-{ +- int_fast32_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast32_t tmp10, tmp11, tmp12, tmp13; +- int_fast32_t z1, z2, z3, z4, z5; +- DCTELEM *dataptr; +- int ctr; +- +- row_fdct(data); +- +- /* Pass 2: process columns. +- * We remove the PASS1_BITS scaling, but leave the results scaled up +- * by an overall factor of 8. +- */ +- +- dataptr = data; +- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { +- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; +- tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; +- tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; +- tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; +- tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; +- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; +- tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; +- tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; +- +- /* Even part per LL&M figure 1 --- note that published figure is faulty; +- * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". +- */ +- +- tmp10 = tmp0 + tmp3; +- tmp13 = tmp0 - tmp3; +- tmp11 = tmp1 + tmp2; +- tmp12 = tmp1 - tmp2; +- +- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); +- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); +- +- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); +- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), +- CONST_BITS+PASS1_BITS); +- +- /* Odd part per figure 8 --- note paper omits factor of sqrt(2). +- * cK represents cos(K*pi/16). +- * i0..i3 in the paper are tmp4..tmp7 here. +- */ +- +- z1 = tmp4 + tmp7; +- z2 = tmp5 + tmp6; +- z3 = tmp4 + tmp6; +- z4 = tmp5 + tmp7; +- z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ +- +- tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ +- tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ +- tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ +- tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ +- z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ +- z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ +- z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ +- z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ +- +- z3 += z5; +- z4 += z5; +- +- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, +- CONST_BITS+PASS1_BITS); +- +- dataptr++; /* advance pointer to next column */ +- } +-} +- +-/* +- * The secret of DCT2-4-8 is really simple -- you do the usual 1-DCT +- * on the rows and then, instead of doing even and odd, part on the colums +- * you do even part two times. +- */ +-GLOBAL(void) +-ff_fdct248_islow (DCTELEM * data) +-{ +- int_fast32_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; +- int_fast32_t tmp10, tmp11, tmp12, tmp13; +- int_fast32_t z1; +- DCTELEM *dataptr; +- int ctr; +- +- row_fdct(data); +- +- /* Pass 2: process columns. +- * We remove the PASS1_BITS scaling, but leave the results scaled up +- * by an overall factor of 8. +- */ +- +- dataptr = data; +- for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { +- tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*1]; +- tmp1 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3]; +- tmp2 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5]; +- tmp3 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7]; +- tmp4 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*1]; +- tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3]; +- tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5]; +- tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7]; +- +- tmp10 = tmp0 + tmp3; +- tmp11 = tmp1 + tmp2; +- tmp12 = tmp1 - tmp2; +- tmp13 = tmp0 - tmp3; +- +- dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); +- dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); +- +- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); +- dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), +- CONST_BITS+PASS1_BITS); +- +- tmp10 = tmp4 + tmp7; +- tmp11 = tmp5 + tmp6; +- tmp12 = tmp5 - tmp6; +- tmp13 = tmp4 - tmp7; +- +- dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS); +- dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS); +- +- z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); +- dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), +- CONST_BITS+PASS1_BITS); +- dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), +- CONST_BITS+PASS1_BITS); +- +- dataptr++; /* advance pointer to next column */ +- } +-} ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define BIT_DEPTH 8 ++#include "jfdctint_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "jfdctint_template.c" ++#undef BIT_DEPTH +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctint_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctint_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jfdctint_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jfdctint_template.c 2012-05-14 14:08:53.898331207 +0200 +@@ -0,0 +1,403 @@ ++/* ++ * This file is part of the Independent JPEG Group's software. ++ * ++ * The authors make NO WARRANTY or representation, either express or implied, ++ * with respect to this software, its quality, accuracy, merchantability, or ++ * fitness for a particular purpose. This software is provided "AS IS", and ++ * you, its user, assume the entire risk as to its quality and accuracy. ++ * ++ * This software is copyright (C) 1991-1996, Thomas G. Lane. ++ * All Rights Reserved except as specified below. ++ * ++ * Permission is hereby granted to use, copy, modify, and distribute this ++ * software (or portions thereof) for any purpose, without fee, subject to ++ * these conditions: ++ * (1) If any part of the source code for this software is distributed, then ++ * this README file must be included, with this copyright and no-warranty ++ * notice unaltered; and any additions, deletions, or changes to the original ++ * files must be clearly indicated in accompanying documentation. ++ * (2) If only executable code is distributed, then the accompanying ++ * documentation must state that "this software is based in part on the work ++ * of the Independent JPEG Group". ++ * (3) Permission for use of this software is granted only if the user accepts ++ * full responsibility for any undesirable consequences; the authors accept ++ * NO LIABILITY for damages of any kind. ++ * ++ * These conditions apply to any software derived from or based on the IJG ++ * code, not just to the unmodified library. If you use our work, you ought ++ * to acknowledge us. ++ * ++ * Permission is NOT granted for the use of any IJG author's name or company ++ * name in advertising or publicity relating to this software or products ++ * derived from it. This software may be referred to only as "the Independent ++ * JPEG Group's software". ++ * ++ * We specifically permit and encourage the use of this software as the basis ++ * of commercial products, provided that all warranty or liability claims are ++ * assumed by the product vendor. ++ * ++ * This file contains a slow-but-accurate integer implementation of the ++ * forward DCT (Discrete Cosine Transform). ++ * ++ * A 2-D DCT can be done by 1-D DCT on each row followed by 1-D DCT ++ * on each column. Direct algorithms are also available, but they are ++ * much more complex and seem not to be any faster when reduced to code. ++ * ++ * This implementation is based on an algorithm described in ++ * C. Loeffler, A. Ligtenberg and G. Moschytz, "Practical Fast 1-D DCT ++ * Algorithms with 11 Multiplications", Proc. Int'l. Conf. on Acoustics, ++ * Speech, and Signal Processing 1989 (ICASSP '89), pp. 988-991. ++ * The primary algorithm described there uses 11 multiplies and 29 adds. ++ * We use their alternate method with 12 multiplies and 32 adds. ++ * The advantage of this method is that no data path contains more than one ++ * multiplication; this allows a very simple and accurate implementation in ++ * scaled fixed-point arithmetic, with a minimal number of shifts. ++ */ ++ ++/** ++ * @file ++ * Independent JPEG Group's slow & accurate dct. ++ */ ++ ++#include "libavutil/common.h" ++#include "dsputil.h" ++ ++#include "bit_depth_template.c" ++ ++#define DCTSIZE 8 ++#define BITS_IN_JSAMPLE BIT_DEPTH ++#define GLOBAL(x) x ++#define RIGHT_SHIFT(x, n) ((x) >> (n)) ++#define MULTIPLY16C16(var,const) ((var)*(const)) ++ ++#if 1 //def USE_ACCURATE_ROUNDING ++#define DESCALE(x,n) RIGHT_SHIFT((x) + (1 << ((n) - 1)), n) ++#else ++#define DESCALE(x,n) RIGHT_SHIFT(x, n) ++#endif ++ ++ ++/* ++ * This module is specialized to the case DCTSIZE = 8. ++ */ ++ ++#if DCTSIZE != 8 ++#error "Sorry, this code only copes with 8x8 DCTs." ++#endif ++ ++ ++/* ++ * The poop on this scaling stuff is as follows: ++ * ++ * Each 1-D DCT step produces outputs which are a factor of sqrt(N) ++ * larger than the true DCT outputs. The final outputs are therefore ++ * a factor of N larger than desired; since N=8 this can be cured by ++ * a simple right shift at the end of the algorithm. The advantage of ++ * this arrangement is that we save two multiplications per 1-D DCT, ++ * because the y0 and y4 outputs need not be divided by sqrt(N). ++ * In the IJG code, this factor of 8 is removed by the quantization step ++ * (in jcdctmgr.c), NOT in this module. ++ * ++ * We have to do addition and subtraction of the integer inputs, which ++ * is no problem, and multiplication by fractional constants, which is ++ * a problem to do in integer arithmetic. We multiply all the constants ++ * by CONST_SCALE and convert them to integer constants (thus retaining ++ * CONST_BITS bits of precision in the constants). After doing a ++ * multiplication we have to divide the product by CONST_SCALE, with proper ++ * rounding, to produce the correct output. This division can be done ++ * cheaply as a right shift of CONST_BITS bits. We postpone shifting ++ * as long as possible so that partial sums can be added together with ++ * full fractional precision. ++ * ++ * The outputs of the first pass are scaled up by PASS1_BITS bits so that ++ * they are represented to better-than-integral precision. These outputs ++ * require BITS_IN_JSAMPLE + PASS1_BITS + 3 bits; this fits in a 16-bit word ++ * with the recommended scaling. (For 12-bit sample data, the intermediate ++ * array is int32_t anyway.) ++ * ++ * To avoid overflow of the 32-bit intermediate results in pass 2, we must ++ * have BITS_IN_JSAMPLE + CONST_BITS + PASS1_BITS <= 26. Error analysis ++ * shows that the values given below are the most effective. ++ */ ++ ++#undef CONST_BITS ++#undef PASS1_BITS ++#undef OUT_SHIFT ++ ++#if BITS_IN_JSAMPLE == 8 ++#define CONST_BITS 13 ++#define PASS1_BITS 4 /* set this to 2 if 16x16 multiplies are faster */ ++#define OUT_SHIFT PASS1_BITS ++#else ++#define CONST_BITS 13 ++#define PASS1_BITS 1 /* lose a little precision to avoid overflow */ ++#define OUT_SHIFT (PASS1_BITS + 1) ++#endif ++ ++/* Some C compilers fail to reduce "FIX(constant)" at compile time, thus ++ * causing a lot of useless floating-point operations at run time. ++ * To get around this we use the following pre-calculated constants. ++ * If you change CONST_BITS you may want to add appropriate values. ++ * (With a reasonable C compiler, you can just rely on the FIX() macro...) ++ */ ++ ++#if CONST_BITS == 13 ++#define FIX_0_298631336 ((int32_t) 2446) /* FIX(0.298631336) */ ++#define FIX_0_390180644 ((int32_t) 3196) /* FIX(0.390180644) */ ++#define FIX_0_541196100 ((int32_t) 4433) /* FIX(0.541196100) */ ++#define FIX_0_765366865 ((int32_t) 6270) /* FIX(0.765366865) */ ++#define FIX_0_899976223 ((int32_t) 7373) /* FIX(0.899976223) */ ++#define FIX_1_175875602 ((int32_t) 9633) /* FIX(1.175875602) */ ++#define FIX_1_501321110 ((int32_t) 12299) /* FIX(1.501321110) */ ++#define FIX_1_847759065 ((int32_t) 15137) /* FIX(1.847759065) */ ++#define FIX_1_961570560 ((int32_t) 16069) /* FIX(1.961570560) */ ++#define FIX_2_053119869 ((int32_t) 16819) /* FIX(2.053119869) */ ++#define FIX_2_562915447 ((int32_t) 20995) /* FIX(2.562915447) */ ++#define FIX_3_072711026 ((int32_t) 25172) /* FIX(3.072711026) */ ++#else ++#define FIX_0_298631336 FIX(0.298631336) ++#define FIX_0_390180644 FIX(0.390180644) ++#define FIX_0_541196100 FIX(0.541196100) ++#define FIX_0_765366865 FIX(0.765366865) ++#define FIX_0_899976223 FIX(0.899976223) ++#define FIX_1_175875602 FIX(1.175875602) ++#define FIX_1_501321110 FIX(1.501321110) ++#define FIX_1_847759065 FIX(1.847759065) ++#define FIX_1_961570560 FIX(1.961570560) ++#define FIX_2_053119869 FIX(2.053119869) ++#define FIX_2_562915447 FIX(2.562915447) ++#define FIX_3_072711026 FIX(3.072711026) ++#endif ++ ++ ++/* Multiply an int32_t variable by an int32_t constant to yield an int32_t result. ++ * For 8-bit samples with the recommended scaling, all the variable ++ * and constant values involved are no more than 16 bits wide, so a ++ * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. ++ * For 12-bit samples, a full 32-bit multiplication will be needed. ++ */ ++ ++#if BITS_IN_JSAMPLE == 8 && CONST_BITS<=13 && PASS1_BITS<=2 ++#define MULTIPLY(var,const) MULTIPLY16C16(var,const) ++#else ++#define MULTIPLY(var,const) ((var) * (const)) ++#endif ++ ++ ++static av_always_inline void FUNC(row_fdct)(DCTELEM *data) ++{ ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1, z2, z3, z4, z5; ++ DCTELEM *dataptr; ++ int ctr; ++ ++ /* Pass 1: process rows. */ ++ /* Note results are scaled up by sqrt(8) compared to a true DCT; */ ++ /* furthermore, we scale the results by 2**PASS1_BITS. */ ++ ++ dataptr = data; ++ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { ++ tmp0 = dataptr[0] + dataptr[7]; ++ tmp7 = dataptr[0] - dataptr[7]; ++ tmp1 = dataptr[1] + dataptr[6]; ++ tmp6 = dataptr[1] - dataptr[6]; ++ tmp2 = dataptr[2] + dataptr[5]; ++ tmp5 = dataptr[2] - dataptr[5]; ++ tmp3 = dataptr[3] + dataptr[4]; ++ tmp4 = dataptr[3] - dataptr[4]; ++ ++ /* Even part per LL&M figure 1 --- note that published figure is faulty; ++ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". ++ */ ++ ++ tmp10 = tmp0 + tmp3; ++ tmp13 = tmp0 - tmp3; ++ tmp11 = tmp1 + tmp2; ++ tmp12 = tmp1 - tmp2; ++ ++ dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS); ++ dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS); ++ ++ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); ++ dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), ++ CONST_BITS-PASS1_BITS); ++ dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), ++ CONST_BITS-PASS1_BITS); ++ ++ /* Odd part per figure 8 --- note paper omits factor of sqrt(2). ++ * cK represents cos(K*pi/16). ++ * i0..i3 in the paper are tmp4..tmp7 here. ++ */ ++ ++ z1 = tmp4 + tmp7; ++ z2 = tmp5 + tmp6; ++ z3 = tmp4 + tmp6; ++ z4 = tmp5 + tmp7; ++ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ ++ ++ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ ++ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ ++ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ ++ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ ++ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ ++ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ ++ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ ++ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ ++ ++ z3 += z5; ++ z4 += z5; ++ ++ dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS); ++ dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS); ++ dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS); ++ dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS); ++ ++ dataptr += DCTSIZE; /* advance pointer to next row */ ++ } ++} ++ ++/* ++ * Perform the forward DCT on one block of samples. ++ */ ++ ++GLOBAL(void) ++FUNC(ff_jpeg_fdct_islow)(DCTELEM *data) ++{ ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1, z2, z3, z4, z5; ++ DCTELEM *dataptr; ++ int ctr; ++ ++ FUNC(row_fdct)(data); ++ ++ /* Pass 2: process columns. ++ * We remove the PASS1_BITS scaling, but leave the results scaled up ++ * by an overall factor of 8. ++ */ ++ ++ dataptr = data; ++ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { ++ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; ++ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; ++ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; ++ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; ++ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; ++ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; ++ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; ++ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; ++ ++ /* Even part per LL&M figure 1 --- note that published figure is faulty; ++ * rotator "sqrt(2)*c1" should be "sqrt(2)*c6". ++ */ ++ ++ tmp10 = tmp0 + tmp3; ++ tmp13 = tmp0 - tmp3; ++ tmp11 = tmp1 + tmp2; ++ tmp12 = tmp1 - tmp2; ++ ++ dataptr[DCTSIZE*0] = DESCALE(tmp10 + tmp11, OUT_SHIFT); ++ dataptr[DCTSIZE*4] = DESCALE(tmp10 - tmp11, OUT_SHIFT); ++ ++ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); ++ dataptr[DCTSIZE*2] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), ++ CONST_BITS + OUT_SHIFT); ++ dataptr[DCTSIZE*6] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), ++ CONST_BITS + OUT_SHIFT); ++ ++ /* Odd part per figure 8 --- note paper omits factor of sqrt(2). ++ * cK represents cos(K*pi/16). ++ * i0..i3 in the paper are tmp4..tmp7 here. ++ */ ++ ++ z1 = tmp4 + tmp7; ++ z2 = tmp5 + tmp6; ++ z3 = tmp4 + tmp6; ++ z4 = tmp5 + tmp7; ++ z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */ ++ ++ tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */ ++ tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */ ++ tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */ ++ tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */ ++ z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */ ++ z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */ ++ z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */ ++ z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */ ++ ++ z3 += z5; ++ z4 += z5; ++ ++ dataptr[DCTSIZE*7] = DESCALE(tmp4 + z1 + z3, CONST_BITS + OUT_SHIFT); ++ dataptr[DCTSIZE*5] = DESCALE(tmp5 + z2 + z4, CONST_BITS + OUT_SHIFT); ++ dataptr[DCTSIZE*3] = DESCALE(tmp6 + z2 + z3, CONST_BITS + OUT_SHIFT); ++ dataptr[DCTSIZE*1] = DESCALE(tmp7 + z1 + z4, CONST_BITS + OUT_SHIFT); ++ ++ dataptr++; /* advance pointer to next column */ ++ } ++} ++ ++/* ++ * The secret of DCT2-4-8 is really simple -- you do the usual 1-DCT ++ * on the rows and then, instead of doing even and odd, part on the columns ++ * you do even part two times. ++ */ ++GLOBAL(void) ++FUNC(ff_fdct248_islow)(DCTELEM *data) ++{ ++ int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int tmp10, tmp11, tmp12, tmp13; ++ int z1; ++ DCTELEM *dataptr; ++ int ctr; ++ ++ FUNC(row_fdct)(data); ++ ++ /* Pass 2: process columns. ++ * We remove the PASS1_BITS scaling, but leave the results scaled up ++ * by an overall factor of 8. ++ */ ++ ++ dataptr = data; ++ for (ctr = DCTSIZE-1; ctr >= 0; ctr--) { ++ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*1]; ++ tmp1 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*3]; ++ tmp2 = dataptr[DCTSIZE*4] + dataptr[DCTSIZE*5]; ++ tmp3 = dataptr[DCTSIZE*6] + dataptr[DCTSIZE*7]; ++ tmp4 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*1]; ++ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*3]; ++ tmp6 = dataptr[DCTSIZE*4] - dataptr[DCTSIZE*5]; ++ tmp7 = dataptr[DCTSIZE*6] - dataptr[DCTSIZE*7]; ++ ++ tmp10 = tmp0 + tmp3; ++ tmp11 = tmp1 + tmp2; ++ tmp12 = tmp1 - tmp2; ++ tmp13 = tmp0 - tmp3; ++ ++ dataptr[DCTSIZE*0] = DESCALE(tmp10 + tmp11, OUT_SHIFT); ++ dataptr[DCTSIZE*4] = DESCALE(tmp10 - tmp11, OUT_SHIFT); ++ ++ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); ++ dataptr[DCTSIZE*2] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), ++ CONST_BITS+OUT_SHIFT); ++ dataptr[DCTSIZE*6] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), ++ CONST_BITS+OUT_SHIFT); ++ ++ tmp10 = tmp4 + tmp7; ++ tmp11 = tmp5 + tmp6; ++ tmp12 = tmp5 - tmp6; ++ tmp13 = tmp4 - tmp7; ++ ++ dataptr[DCTSIZE*1] = DESCALE(tmp10 + tmp11, OUT_SHIFT); ++ dataptr[DCTSIZE*5] = DESCALE(tmp10 - tmp11, OUT_SHIFT); ++ ++ z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100); ++ dataptr[DCTSIZE*3] = DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865), ++ CONST_BITS + OUT_SHIFT); ++ dataptr[DCTSIZE*7] = DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065), ++ CONST_BITS + OUT_SHIFT); ++ ++ dataptr++; /* advance pointer to next column */ ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpeglsdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpeglsdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpeglsdec.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpeglsdec.c 2012-05-14 14:08:53.900331247 +0200 +@@ -198,6 +198,9 @@ + r = ff_log2_run[state->run_index[comp]]; + if(r) + r = get_bits_long(&s->gb, r); ++ if(x + r * stride > w) { ++ r = (w - x) / stride; ++ } + for(i = 0; i < r; i++) { + W(dst, x, Ra); + x += stride; +@@ -286,8 +289,8 @@ + // av_log(s->avctx, AV_LOG_DEBUG, "JPEG-LS params: %ix%i NEAR=%i MV=%i T(%i,%i,%i) RESET=%i, LIMIT=%i, qbpp=%i, RANGE=%i\n",s->width,s->height,state->near,state->maxval,state->T1,state->T2,state->T3,state->reset,state->limit,state->qbpp, state->range); + // av_log(s->avctx, AV_LOG_DEBUG, "JPEG params: ILV=%i Pt=%i BPP=%i, scan = %i\n", ilv, point_transform, s->bits, s->cur_scan); + if(ilv == 0) { /* separate planes */ +- off = s->cur_scan - 1; + stride = (s->nb_components > 1) ? 3 : 1; ++ off = av_clip(s->cur_scan - 1, 0, stride); + width = s->width * stride; + cur += off; + for(i = 0; i < s->height; i++) { +@@ -309,11 +312,12 @@ + } else if(ilv == 1) { /* line interleaving */ + int j; + int Rc[3] = {0, 0, 0}; ++ stride = (s->nb_components > 1) ? 3 : 1; + memset(cur, 0, s->picture.linesize[0]); +- width = s->width * 3; ++ width = s->width * stride; + for(i = 0; i < s->height; i++) { +- for(j = 0; j < 3; j++) { +- ls_decode_line(state, s, last + j, cur + j, Rc[j], width, 3, j, 8); ++ for(j = 0; j < stride; j++) { ++ ls_decode_line(state, s, last + j, cur + j, Rc[j], width, stride, j, 8); + Rc[j] = last[j]; + + if (s->restart_interval && !--s->restart_count) { +@@ -364,14 +368,13 @@ + + + AVCodec ff_jpegls_decoder = { +- "jpegls", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_JPEGLS, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- ff_mjpeg_decode_frame, +- CODEC_CAP_DR1, ++ .name = "jpegls", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEGLS, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = ff_mjpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpeglsenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpeglsenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpeglsenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpeglsenc.c 2012-05-14 14:08:53.900331247 +0200 +@@ -245,7 +245,7 @@ + init_put_bits(&pb2, buf2, buf_size); + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + if(avctx->pix_fmt == PIX_FMT_GRAY8 || avctx->pix_fmt == PIX_FMT_GRAY16) +@@ -357,7 +357,7 @@ + put_bits(&pb, 8, v); + } + } +- align_put_bits(&pb); ++ avpriv_align_put_bits(&pb); + av_free(buf2); + + /* End of image */ +@@ -383,13 +383,12 @@ + } + + AVCodec ff_jpegls_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them +- "jpegls", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_JPEGLS, +- sizeof(JpeglsContext), +- encode_init_ls, +- encode_picture_ls, +- NULL, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, PIX_FMT_NONE}, +- .long_name= NULL_IF_CONFIG_SMALL("JPEG-LS"), ++ .name = "jpegls", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEGLS, ++ .priv_data_size = sizeof(JpeglsContext), ++ .init = encode_init_ls, ++ .encode = encode_picture_ls, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_BGR24, PIX_FMT_RGB24, PIX_FMT_GRAY8, PIX_FMT_GRAY16, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("JPEG-LS"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpegls.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpegls.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jpegls.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jpegls.h 2012-05-14 14:08:53.899331227 +0200 +@@ -86,6 +86,8 @@ + } + + static inline int ff_jpegls_update_state_regular(JLSState *state, int Q, int err){ ++ if(FFABS(err) > 0xFFFF) ++ return -0x10000; + state->A[Q] += FFABS(err); + err *= state->twonear; + state->B[Q] += err; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jrevdct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jrevdct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jrevdct.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jrevdct.c 2012-05-14 14:08:53.902331287 +0200 +@@ -1,6 +1,4 @@ + /* +- * jrevdct.c +- * + * This file is part of the Independent JPEG Group's software. + * + * The authors make NO WARRANTY or representation, either express or implied, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/jvdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/jvdec.c 2012-05-14 14:08:53.902331287 +0200 +@@ -0,0 +1,216 @@ ++/* ++ * Bitmap Brothers JV video decoder ++ * Copyright (c) 2011 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Bitmap Brothers JV video decoder ++ * @author Peter Ross ++ */ ++ ++#include "avcodec.h" ++#include "dsputil.h" ++#include "get_bits.h" ++#include "libavutil/intreadwrite.h" ++ ++typedef struct JvContext { ++ DSPContext dsp; ++ AVFrame frame; ++ uint32_t palette[AVPALETTE_COUNT]; ++ int palette_has_changed; ++} JvContext; ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ JvContext *s = avctx->priv_data; ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ dsputil_init(&s->dsp, avctx); ++ return 0; ++} ++ ++/** ++ * Decode 2x2 block ++ */ ++static inline void decode2x2(GetBitContext *gb, uint8_t *dst, int linesize) ++{ ++ int i, j, v[2]; ++ ++ switch (get_bits(gb, 2)) { ++ case 1: ++ v[0] = get_bits(gb, 8); ++ for (j = 0; j < 2; j++) ++ memset(dst + j*linesize, v[0], 2); ++ break; ++ case 2: ++ v[0] = get_bits(gb, 8); ++ v[1] = get_bits(gb, 8); ++ for (j = 0; j < 2; j++) ++ for (i = 0; i < 2; i++) ++ dst[j*linesize + i] = v[get_bits1(gb)]; ++ break; ++ case 3: ++ for (j = 0; j < 2; j++) ++ for (i = 0; i < 2; i++) ++ dst[j*linesize + i] = get_bits(gb, 8); ++ } ++} ++ ++/** ++ * Decode 4x4 block ++ */ ++static inline void decode4x4(GetBitContext *gb, uint8_t *dst, int linesize) ++{ ++ int i, j, v[2]; ++ ++ switch (get_bits(gb, 2)) { ++ case 1: ++ v[0] = get_bits(gb, 8); ++ for (j = 0; j < 4; j++) ++ memset(dst + j*linesize, v[0], 4); ++ break; ++ case 2: ++ v[0] = get_bits(gb, 8); ++ v[1] = get_bits(gb, 8); ++ for (j = 2; j >= 0; j -= 2) { ++ for (i = 0; i < 4; i++) ++ dst[j*linesize + i] = v[get_bits1(gb)]; ++ for (i = 0; i < 4; i++) ++ dst[(j+1)*linesize + i] = v[get_bits1(gb)]; ++ } ++ break; ++ case 3: ++ for (j = 0; j < 4; j += 2) ++ for (i = 0; i < 4; i += 2) ++ decode2x2(gb, dst + j*linesize + i, linesize); ++ } ++} ++ ++/** ++ * Decode 8x8 block ++ */ ++static inline void decode8x8(GetBitContext *gb, uint8_t *dst, int linesize, DSPContext *dsp) ++{ ++ int i, j, v[2]; ++ ++ switch (get_bits(gb, 2)) { ++ case 1: ++ v[0] = get_bits(gb, 8); ++ dsp->fill_block_tab[1](dst, v[0], linesize, 8); ++ break; ++ case 2: ++ v[0] = get_bits(gb, 8); ++ v[1] = get_bits(gb, 8); ++ for (j = 7; j >= 0; j--) ++ for (i = 0; i < 8; i++) ++ dst[j*linesize + i] = v[get_bits1(gb)]; ++ break; ++ case 3: ++ for (j = 0; j < 8; j += 4) ++ for (i = 0; i < 8; i += 4) ++ decode4x4(gb, dst + j*linesize + i, linesize); ++ } ++} ++ ++static int decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ JvContext *s = avctx->priv_data; ++ int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = buf + buf_size; ++ int video_size, video_type, i, j; ++ ++ video_size = AV_RL32(buf); ++ video_type = buf[4]; ++ buf += 5; ++ ++ if (video_size) { ++ if (avctx->reget_buffer(avctx, &s->frame) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ ++ if (video_type == 0 || video_type == 1) { ++ GetBitContext gb; ++ init_get_bits(&gb, buf, 8 * FFMIN(video_size, buf_end - buf)); ++ ++ for (j = 0; j < avctx->height; j += 8) ++ for (i = 0; i < avctx->width; i += 8) ++ decode8x8(&gb, s->frame.data[0] + j*s->frame.linesize[0] + i, ++ s->frame.linesize[0], &s->dsp); ++ ++ buf += video_size; ++ } else if (video_type == 2) { ++ if (buf + 1 <= buf_end) { ++ int v = *buf++; ++ for (j = 0; j < avctx->height; j++) ++ memset(s->frame.data[0] + j*s->frame.linesize[0], v, avctx->width); ++ } ++ } else { ++ av_log(avctx, AV_LOG_WARNING, "unsupported frame type %i\n", video_type); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ ++ if (buf < buf_end) { ++ for (i = 0; i < AVPALETTE_COUNT && buf + 3 <= buf_end; i++) { ++ uint32_t pal = AV_RB24(buf); ++ s->palette[i] = 0xFF << 24 | pal << 2 | ((pal >> 4) & 0x30303); ++ buf += 3; ++ } ++ s->palette_has_changed = 1; ++ } ++ ++ if (video_size) { ++ s->frame.key_frame = 1; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; ++ s->frame.palette_has_changed = s->palette_has_changed; ++ s->palette_has_changed = 0; ++ memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = s->frame; ++ } ++ ++ return buf_size; ++} ++ ++static av_cold int decode_close(AVCodecContext *avctx) ++{ ++ JvContext *s = avctx->priv_data; ++ ++ if(s->frame.data[0]) ++ avctx->release_buffer(avctx, &s->frame); ++ ++ return 0; ++} ++ ++AVCodec ff_jv_decoder = { ++ .name = "jv", ++ .long_name = NULL_IF_CONFIG_SMALL("Bitmap Brothers JV video"), ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JV, ++ .priv_data_size = sizeof(JvContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kbdwin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kbdwin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kbdwin.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kbdwin.c 2012-05-14 14:08:53.903331307 +0200 +@@ -0,0 +1,48 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include "libavutil/attributes.h" ++#include "kbdwin.h" ++ ++#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation ++ ++av_cold void ff_kbd_window_init(float *window, float alpha, int n) ++{ ++ int i, j; ++ double sum = 0.0, bessel, tmp; ++ double local_window[FF_KBD_WINDOW_MAX]; ++ double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); ++ ++ assert(n <= FF_KBD_WINDOW_MAX); ++ ++ for (i = 0; i < n; i++) { ++ tmp = i * (n - i) * alpha2; ++ bessel = 1.0; ++ for (j = BESSEL_I0_ITER; j > 0; j--) ++ bessel = bessel * tmp / (j * j) + 1; ++ sum += bessel; ++ local_window[i] = sum; ++ } ++ ++ sum++; ++ for (i = 0; i < n; i++) ++ window[i] = sqrt(local_window[i] / sum); ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kbdwin.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kbdwin.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kbdwin.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kbdwin.h 2012-05-14 14:08:53.903331307 +0200 +@@ -0,0 +1,35 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_KBDWIN_H ++#define AVCODEC_KBDWIN_H ++ ++/** ++ * Maximum window size for ff_kbd_window_init. ++ */ ++#define FF_KBD_WINDOW_MAX 1024 ++ ++/** ++ * Generate a Kaiser-Bessel Derived Window. ++ * @param window pointer to half window ++ * @param alpha determines window shape ++ * @param n size of half window, max FF_KBD_WINDOW_MAX ++ */ ++void ff_kbd_window_init(float *window, float alpha, int n); ++ ++#endif /* AVCODEC_KBDWIN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kgv1dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kgv1dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kgv1dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kgv1dec.c 2012-05-14 14:08:53.904331327 +0200 +@@ -25,24 +25,31 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + typedef struct { + AVCodecContext *avctx; +- AVFrame pic; +- uint16_t *prev, *cur; ++ AVFrame prev, cur; + } KgvContext; + ++static void decode_flush(AVCodecContext *avctx) ++{ ++ KgvContext * const c = avctx->priv_data; ++ ++ if (c->prev.data[0]) ++ avctx->release_buffer(avctx, &c->prev); ++} ++ + static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + const uint8_t *buf_end = buf + avpkt->size; + KgvContext * const c = avctx->priv_data; +- int offsets[7]; ++ int offsets[8]; + uint16_t *out, *prev; + int outcnt = 0, maxcnt; +- int w, h, i; ++ int w, h, i, res; + + if (avpkt->size < 2) + return -1; +@@ -54,22 +61,25 @@ + if (av_image_check_size(w, h, 0, avctx)) + return -1; + +- if (w != avctx->width || h != avctx->height) ++ if (w != avctx->width || h != avctx->height) { ++ if (c->prev.data[0]) ++ avctx->release_buffer(avctx, &c->prev); + avcodec_set_dimensions(avctx, w, h); ++ } + + maxcnt = w * h; + +- out = av_realloc(c->cur, w * h * 2); +- if (!out) +- return -1; +- c->cur = out; +- +- prev = av_realloc(c->prev, w * h * 2); +- if (!prev) +- return -1; +- c->prev = prev; ++ c->cur.reference = 3; ++ if ((res = avctx->get_buffer(avctx, &c->cur)) < 0) ++ return res; ++ out = (uint16_t *) c->cur.data[0]; ++ if (c->prev.data[0]) { ++ prev = (uint16_t *) c->prev.data[0]; ++ } else { ++ prev = NULL; ++ } + +- for (i = 0; i < 7; i++) ++ for (i = 0; i < 8; i++) + offsets[i] = -1; + + while (outcnt < maxcnt && buf_end - 2 > buf) { +@@ -80,6 +90,7 @@ + out[outcnt++] = code; // rgb555 pixel coded directly + } else { + int count; ++ int inp_off; + uint16_t *inp; + + if ((code & 0x6000) == 0x6000) { +@@ -101,7 +112,14 @@ + if (maxcnt - start < count) + break; + +- inp = prev + start; ++ if (!prev) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Frame reference does not exist\n"); ++ break; ++ } ++ ++ inp = prev; ++ inp_off = start; + } else { + // copy from earlier in this frame + int offset = (code & 0x1FFF) + 1; +@@ -119,27 +137,28 @@ + if (outcnt < offset) + break; + +- inp = out + outcnt - offset; ++ inp = out; ++ inp_off = outcnt - offset; + } + + if (maxcnt - outcnt < count) + break; + +- for (i = 0; i < count; i++) ++ for (i = inp_off; i < count + inp_off; i++) { + out[outcnt++] = inp[i]; ++ } + } + } + + if (outcnt - maxcnt) + av_log(avctx, AV_LOG_DEBUG, "frame finished with %d diff\n", outcnt - maxcnt); + +- c->pic.data[0] = (uint8_t *)c->cur; +- c->pic.linesize[0] = w * 2; +- + *data_size = sizeof(AVFrame); +- *(AVFrame*)data = c->pic; ++ *(AVFrame*)data = c->cur; + +- FFSWAP(uint16_t *, c->cur, c->prev); ++ if (c->prev.data[0]) ++ avctx->release_buffer(avctx, &c->prev); ++ FFSWAP(AVFrame, c->cur, c->prev); + + return avpkt->size; + } +@@ -150,29 +169,25 @@ + + c->avctx = avctx; + avctx->pix_fmt = PIX_FMT_RGB555; ++ avctx->flags |= CODEC_FLAG_EMU_EDGE; + + return 0; + } + + static av_cold int decode_end(AVCodecContext *avctx) + { +- KgvContext * const c = avctx->priv_data; +- +- av_freep(&c->cur); +- av_freep(&c->prev); +- ++ decode_flush(avctx); + return 0; + } + + AVCodec ff_kgv1_decoder = { +- "kgv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_KGV1, +- sizeof(KgvContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- .max_lowres = 1, ++ .name = "kgv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_KGV1, ++ .priv_data_size = sizeof(KgvContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .flush = decode_flush, + .long_name = NULL_IF_CONFIG_SMALL("Kega Game Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kmvc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kmvc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/kmvc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/kmvc.c 2012-05-14 14:08:53.906331367 +0200 +@@ -33,6 +33,7 @@ + #define KMVC_KEYFRAME 0x80 + #define KMVC_PALETTE 0x40 + #define KMVC_METHOD 0x0F ++#define MAX_PALSIZE 256 + + /* + * Decoder context +@@ -43,9 +44,10 @@ + + int setpal; + int palsize; +- uint32_t pal[256]; ++ uint32_t pal[MAX_PALSIZE]; + uint8_t *cur, *prev; + uint8_t *frm0, *frm1; ++ GetByteContext g; + } KmvcContext; + + typedef struct BitBuf { +@@ -55,19 +57,19 @@ + + #define BLK(data, x, y) data[(x) + (y) * 320] + +-#define kmvc_init_getbits(bb, src) bb.bits = 7; bb.bitbuf = *src++; ++#define kmvc_init_getbits(bb, g) bb.bits = 7; bb.bitbuf = bytestream2_get_byte(g); + +-#define kmvc_getbit(bb, src, res) {\ ++#define kmvc_getbit(bb, g, res) {\ + res = 0; \ + if (bb.bitbuf & (1 << bb.bits)) res = 1; \ + bb.bits--; \ + if(bb.bits == -1) { \ +- bb.bitbuf = *src++; \ ++ bb.bitbuf = bytestream2_get_byte(g); \ + bb.bits = 7; \ + } \ + } + +-static void kmvc_decode_intra_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) ++static int kmvc_decode_intra_8x8(KmvcContext * ctx, int w, int h) + { + BitBuf bb; + int res, val; +@@ -76,28 +78,32 @@ + int l0x, l1x, l0y, l1y; + int mx, my; + +- kmvc_init_getbits(bb, src); ++ kmvc_init_getbits(bb, &ctx->g); + + for (by = 0; by < h; by += 8) + for (bx = 0; bx < w; bx += 8) { +- kmvc_getbit(bb, src, res); ++ if (!bytestream2_get_bytes_left(&ctx->g)) { ++ av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 8x8 block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + for (i = 0; i < 64; i++) + BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val; + } else { // handle four 4x4 subblocks + for (i = 0; i < 4; i++) { + l0x = bx + (i & 1) * 4; + l0y = by + (i & 2) * 2; +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 4x4 block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + for (j = 0; j < 16; j++) + BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val; + } else { // copy block from already decoded place +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + mx = val & 0xF; + my = val >> 4; + for (j = 0; j < 16; j++) +@@ -108,17 +114,17 @@ + for (j = 0; j < 4; j++) { + l1x = l0x + (j & 1) * 2; + l1y = l0y + (j & 2); +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 2x2 block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + BLK(ctx->cur, l1x, l1y) = val; + BLK(ctx->cur, l1x + 1, l1y) = val; + BLK(ctx->cur, l1x, l1y + 1) = val; + BLK(ctx->cur, l1x + 1, l1y + 1) = val; + } else { // copy block from already decoded place +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + mx = val & 0xF; + my = val >> 4; + BLK(ctx->cur, l1x, l1y) = BLK(ctx->cur, l1x - mx, l1y - my); +@@ -130,19 +136,21 @@ + BLK(ctx->cur, l1x + 1 - mx, l1y + 1 - my); + } + } else { // read values for block +- BLK(ctx->cur, l1x, l1y) = *src++; +- BLK(ctx->cur, l1x + 1, l1y) = *src++; +- BLK(ctx->cur, l1x, l1y + 1) = *src++; +- BLK(ctx->cur, l1x + 1, l1y + 1) = *src++; ++ BLK(ctx->cur, l1x, l1y) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x + 1, l1y + 1) = bytestream2_get_byte(&ctx->g); + } + } + } + } + } + } ++ ++ return 0; + } + +-static void kmvc_decode_inter_8x8(KmvcContext * ctx, const uint8_t * src, int w, int h) ++static int kmvc_decode_inter_8x8(KmvcContext * ctx, int w, int h) + { + BitBuf bb; + int res, val; +@@ -151,15 +159,19 @@ + int l0x, l1x, l0y, l1y; + int mx, my; + +- kmvc_init_getbits(bb, src); ++ kmvc_init_getbits(bb, &ctx->g); + + for (by = 0; by < h; by += 8) + for (bx = 0; bx < w; bx += 8) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 8x8 block +- val = *src++; ++ if (!bytestream2_get_bytes_left(&ctx->g)) { ++ av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ val = bytestream2_get_byte(&ctx->g); + for (i = 0; i < 64; i++) + BLK(ctx->cur, bx + (i & 0x7), by + (i >> 3)) = val; + } else { // copy block from previous frame +@@ -168,18 +180,22 @@ + BLK(ctx->prev, bx + (i & 0x7), by + (i >> 3)); + } + } else { // handle four 4x4 subblocks ++ if (!bytestream2_get_bytes_left(&ctx->g)) { ++ av_log(ctx->avctx, AV_LOG_ERROR, "Data overrun\n"); ++ return AVERROR_INVALIDDATA; ++ } + for (i = 0; i < 4; i++) { + l0x = bx + (i & 1) * 4; + l0y = by + (i & 2) * 2; +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 4x4 block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + for (j = 0; j < 16; j++) + BLK(ctx->cur, l0x + (j & 3), l0y + (j >> 2)) = val; + } else { // copy block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + mx = (val & 0xF) - 8; + my = (val >> 4) - 8; + for (j = 0; j < 16; j++) +@@ -190,17 +206,17 @@ + for (j = 0; j < 4; j++) { + l1x = l0x + (j & 1) * 2; + l1y = l0y + (j & 2); +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { +- kmvc_getbit(bb, src, res); ++ kmvc_getbit(bb, &ctx->g, res); + if (!res) { // fill whole 2x2 block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + BLK(ctx->cur, l1x, l1y) = val; + BLK(ctx->cur, l1x + 1, l1y) = val; + BLK(ctx->cur, l1x, l1y + 1) = val; + BLK(ctx->cur, l1x + 1, l1y + 1) = val; + } else { // copy block +- val = *src++; ++ val = bytestream2_get_byte(&ctx->g); + mx = (val & 0xF) - 8; + my = (val >> 4) - 8; + BLK(ctx->cur, l1x, l1y) = BLK(ctx->prev, l1x + mx, l1y + my); +@@ -212,73 +228,73 @@ + BLK(ctx->prev, l1x + 1 + mx, l1y + 1 + my); + } + } else { // read values for block +- BLK(ctx->cur, l1x, l1y) = *src++; +- BLK(ctx->cur, l1x + 1, l1y) = *src++; +- BLK(ctx->cur, l1x, l1y + 1) = *src++; +- BLK(ctx->cur, l1x + 1, l1y + 1) = *src++; ++ BLK(ctx->cur, l1x, l1y) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x + 1, l1y) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x, l1y + 1) = bytestream2_get_byte(&ctx->g); ++ BLK(ctx->cur, l1x + 1, l1y + 1) = bytestream2_get_byte(&ctx->g); + } + } + } + } + } + } ++ ++ return 0; + } + + static int decode_frame(AVCodecContext * avctx, void *data, int *data_size, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; + KmvcContext *const ctx = avctx->priv_data; + uint8_t *out, *src; + int i; + int header; + int blocksize; ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); + ++ bytestream2_init(&ctx->g, avpkt->data, avpkt->size); + if (ctx->pic.data[0]) + avctx->release_buffer(avctx, &ctx->pic); + +- ctx->pic.reference = 1; ++ ctx->pic.reference = 3; + ctx->pic.buffer_hints = FF_BUFFER_HINTS_VALID; + if (avctx->get_buffer(avctx, &ctx->pic) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + +- header = *buf++; ++ header = bytestream2_get_byte(&ctx->g); + + /* blocksize 127 is really palette change event */ +- if (buf[0] == 127) { +- buf += 3; ++ if (bytestream2_peek_byte(&ctx->g) == 127) { ++ bytestream2_skip(&ctx->g, 3); + for (i = 0; i < 127; i++) { +- ctx->pal[i + (header & 0x81)] = AV_RB24(buf); +- buf += 4; ++ ctx->pal[i + (header & 0x81)] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g); ++ bytestream2_skip(&ctx->g, 1); + } +- buf -= 127 * 4 + 3; ++ bytestream2_seek(&ctx->g, -127 * 4 - 3, SEEK_CUR); + } + + if (header & KMVC_KEYFRAME) { + ctx->pic.key_frame = 1; +- ctx->pic.pict_type = FF_I_TYPE; ++ ctx->pic.pict_type = AV_PICTURE_TYPE_I; + } else { + ctx->pic.key_frame = 0; +- ctx->pic.pict_type = FF_P_TYPE; +- } +- +- /* if palette has been changed, copy it from palctrl */ +- if (ctx->avctx->palctrl && ctx->avctx->palctrl->palette_changed) { +- memcpy(ctx->pal, ctx->avctx->palctrl->palette, AVPALETTE_SIZE); +- ctx->setpal = 1; +- ctx->avctx->palctrl->palette_changed = 0; ++ ctx->pic.pict_type = AV_PICTURE_TYPE_P; + } + + if (header & KMVC_PALETTE) { + ctx->pic.palette_has_changed = 1; + // palette starts from index 1 and has 127 entries + for (i = 1; i <= ctx->palsize; i++) { +- ctx->pal[i] = bytestream_get_be24(&buf); ++ ctx->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&ctx->g); + } + } + ++ if (pal) { ++ ctx->pic.palette_has_changed = 1; ++ memcpy(ctx->pal, pal, AVPALETTE_SIZE); ++ } ++ + if (ctx->setpal) { + ctx->setpal = 0; + ctx->pic.palette_has_changed = 1; +@@ -287,7 +303,7 @@ + /* make the palette available on the way out */ + memcpy(ctx->pic.data[1], ctx->pal, 1024); + +- blocksize = *buf++; ++ blocksize = bytestream2_get_byte(&ctx->g); + + if (blocksize != 8 && blocksize != 127) { + av_log(avctx, AV_LOG_ERROR, "Block size = %i\n", blocksize); +@@ -300,10 +316,10 @@ + memcpy(ctx->cur, ctx->prev, 320 * 200); + break; + case 3: +- kmvc_decode_intra_8x8(ctx, buf, avctx->width, avctx->height); ++ kmvc_decode_intra_8x8(ctx, avctx->width, avctx->height); + break; + case 4: +- kmvc_decode_inter_8x8(ctx, buf, avctx->width, avctx->height); ++ kmvc_decode_inter_8x8(ctx, avctx->width, avctx->height); + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unknown compression method %i\n", header & KMVC_METHOD); +@@ -331,7 +347,7 @@ + *(AVFrame *) data = ctx->pic; + + /* always report that the buffer was completely consumed */ +- return buf_size; ++ return avpkt->size; + } + + +@@ -357,7 +373,7 @@ + c->prev = c->frm1; + + for (i = 0; i < 256; i++) { +- c->pal[i] = i * 0x10101; ++ c->pal[i] = 0xFF << 24 | i * 0x10101; + } + + if (avctx->extradata_size < 12) { +@@ -365,6 +381,11 @@ + c->palsize = 127; + } else { + c->palsize = AV_RL16(avctx->extradata + 10); ++ if (c->palsize >= (unsigned)MAX_PALSIZE) { ++ c->palsize = 127; ++ av_log(avctx, AV_LOG_ERROR, "KMVC palette too large\n"); ++ return AVERROR_INVALIDDATA; ++ } + } + + if (avctx->extradata_size == 1036) { // palette in extradata +@@ -374,11 +395,9 @@ + src += 4; + } + c->setpal = 1; +- if (c->avctx->palctrl) { +- c->avctx->palctrl->palette_changed = 0; +- } + } + ++ avcodec_get_frame_defaults(&c->pic); + avctx->pix_fmt = PIX_FMT_PAL8; + + return 0; +@@ -402,14 +421,13 @@ + } + + AVCodec ff_kmvc_decoder = { +- "kmvc", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_KMVC, +- sizeof(KmvcContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "kmvc", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_KMVC, ++ .priv_data_size = sizeof(KmvcContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Karl Morton's video codec"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarith.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarith.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarith.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarith.c 2012-05-14 14:08:53.908331408 +0200 +@@ -20,7 +20,7 @@ + */ + + /** +- * @file libavcodec/lagarith.c ++ * @file + * Lagarith lossless decoder + * @author Nathan Caldwell + */ +@@ -32,25 +32,27 @@ + #include "lagarithrac.h" + + enum LagarithFrameType { +- FRAME_RAW = 1, /*!< uncompressed */ +- FRAME_U_RGB24 = 2, /*!< unaligned RGB24 */ +- FRAME_ARITH_YUY2 = 3, /*!< arithmetic coded YUY2 */ +- FRAME_ARITH_RGB24 = 4, /*!< arithmetic coded RGB24 */ +- FRAME_SOLID_GRAY = 5, /*!< solid grayscale color frame */ +- FRAME_SOLID_COLOR = 6, /*!< solid non-grayscale color frame */ +- FRAME_OLD_ARITH_RGB = 7, /*!< obsolete arithmetic coded RGB (no longer encoded by upstream since version 1.1.0) */ +- FRAME_ARITH_RGBA = 8, /*!< arithmetic coded RGBA */ +- FRAME_SOLID_RGBA = 9, /*!< solid RGBA color frame */ +- FRAME_ARITH_YV12 = 10, /*!< arithmetic coded YV12 */ +- FRAME_REDUCED_RES = 11, /*!< reduced resolution YV12 frame */ ++ FRAME_RAW = 1, /**< uncompressed */ ++ FRAME_U_RGB24 = 2, /**< unaligned RGB24 */ ++ FRAME_ARITH_YUY2 = 3, /**< arithmetic coded YUY2 */ ++ FRAME_ARITH_RGB24 = 4, /**< arithmetic coded RGB24 */ ++ FRAME_SOLID_GRAY = 5, /**< solid grayscale color frame */ ++ FRAME_SOLID_COLOR = 6, /**< solid non-grayscale color frame */ ++ FRAME_OLD_ARITH_RGB = 7, /**< obsolete arithmetic coded RGB (no longer encoded by upstream since version 1.1.0) */ ++ FRAME_ARITH_RGBA = 8, /**< arithmetic coded RGBA */ ++ FRAME_SOLID_RGBA = 9, /**< solid RGBA color frame */ ++ FRAME_ARITH_YV12 = 10, /**< arithmetic coded YV12 */ ++ FRAME_REDUCED_RES = 11, /**< reduced resolution YV12 frame */ + }; + + typedef struct LagarithContext { + AVCodecContext *avctx; + AVFrame picture; + DSPContext dsp; +- int zeros; /*!< number of consecutive zero bytes encountered */ +- int zeros_rem; /*!< number of zero bytes remaining to output */ ++ int zeros; /**< number of consecutive zero bytes encountered */ ++ int zeros_rem; /**< number of zero bytes remaining to output */ ++ uint8_t *rgb_planes; ++ int rgb_stride; + } LagarithContext; + + /** +@@ -245,21 +247,21 @@ + { + int L, TL; + ++ /* Left pixel is actually prev_row[width] */ ++ L = buf[width - stride - 1]; + if (!line) { + /* Left prediction only for first line */ + L = l->dsp.add_hfyu_left_prediction(buf + 1, buf + 1, + width - 1, buf[0]); + return; + } else if (line == 1) { +- /* Second line, left predict first pixel, the rest of the line is median predicted */ +- /* FIXME: In the case of RGB this pixel is top predicted */ +- TL = buf[-stride]; ++ /* Second line, left predict first pixel, the rest of the line is median predicted ++ * NOTE: In the case of RGB this pixel is top predicted */ ++ TL = l->avctx->pix_fmt == PIX_FMT_YUV420P ? buf[-stride] : L; + } else { + /* Top left is 2 rows back, last pixel */ + TL = buf[width - (2 * stride) - 1]; + } +- /* Left pixel is actually prev_row[width] */ +- L = buf[width - stride - 1]; + + add_lag_median_prediction(buf, buf - stride, buf, + width, &L, &TL); +@@ -443,6 +445,9 @@ + AVFrame *const p = &l->picture; + uint8_t frametype = 0; + uint32_t offset_gu = 0, offset_bv = 0, offset_ry = 9; ++ int offs[4]; ++ uint8_t *srcs[4], *dst; ++ int i, j; + + AVFrame *picture = data; + +@@ -458,6 +463,111 @@ + offset_bv = AV_RL32(buf + 5); + + switch (frametype) { ++ case FRAME_SOLID_RGBA: ++ avctx->pix_fmt = PIX_FMT_RGB32; ++ ++ if (avctx->get_buffer(avctx, p) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ ++ dst = p->data[0]; ++ for (j = 0; j < avctx->height; j++) { ++ for (i = 0; i < avctx->width; i++) ++ AV_WN32(dst + i * 4, offset_gu); ++ dst += p->linesize[0]; ++ } ++ break; ++ case FRAME_ARITH_RGBA: ++ avctx->pix_fmt = PIX_FMT_RGB32; ++ ++ if (avctx->get_buffer(avctx, p) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ offs[0] = offset_bv; ++ offs[1] = offset_gu; ++ offs[2] = 13; ++ offs[3] = AV_RL32(buf + 9); ++ ++ if (!l->rgb_planes) { ++ l->rgb_stride = FFALIGN(avctx->width, 16); ++ l->rgb_planes = av_malloc(l->rgb_stride * avctx->height * 4); ++ if (!l->rgb_planes) { ++ av_log(avctx, AV_LOG_ERROR, "cannot allocate temporary buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ } ++ for (i = 0; i < 4; i++) ++ srcs[i] = l->rgb_planes + (i + 1) * l->rgb_stride * avctx->height - l->rgb_stride; ++ for (i = 0; i < 4; i++) ++ lag_decode_arith_plane(l, srcs[i], ++ avctx->width, avctx->height, ++ -l->rgb_stride, buf + offs[i], ++ buf_size); ++ dst = p->data[0]; ++ for (i = 0; i < 4; i++) ++ srcs[i] = l->rgb_planes + i * l->rgb_stride * avctx->height; ++ for (j = 0; j < avctx->height; j++) { ++ for (i = 0; i < avctx->width; i++) { ++ uint8_t r, g, b, a; ++ r = srcs[0][i]; ++ g = srcs[1][i]; ++ b = srcs[2][i]; ++ a = srcs[3][i]; ++ r += g; ++ b += g; ++ AV_WN32(dst + i * 4, MKBETAG(a, r, g, b)); ++ } ++ dst += p->linesize[0]; ++ for (i = 0; i < 4; i++) ++ srcs[i] += l->rgb_stride; ++ } ++ break; ++ case FRAME_ARITH_RGB24: ++ avctx->pix_fmt = PIX_FMT_RGB24; ++ ++ if (avctx->get_buffer(avctx, p) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ offs[0] = offset_bv; ++ offs[1] = offset_gu; ++ offs[2] = 9; ++ ++ if (!l->rgb_planes) { ++ l->rgb_stride = FFALIGN(avctx->width, 16); ++ l->rgb_planes = av_malloc(l->rgb_stride * avctx->height * 3); ++ if (!l->rgb_planes) { ++ av_log(avctx, AV_LOG_ERROR, "cannot allocate temporary buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ } ++ for (i = 0; i < 3; i++) ++ srcs[i] = l->rgb_planes + (i + 1) * l->rgb_stride * avctx->height - l->rgb_stride; ++ for (i = 0; i < 3; i++) ++ lag_decode_arith_plane(l, srcs[i], ++ avctx->width, avctx->height, ++ -l->rgb_stride, buf + offs[i], ++ buf_size); ++ dst = p->data[0]; ++ for (i = 0; i < 3; i++) ++ srcs[i] = l->rgb_planes + i * l->rgb_stride * avctx->height; ++ for (j = 0; j < avctx->height; j++) { ++ for (i = 0; i < avctx->width; i++) { ++ uint8_t r, g, b; ++ r = srcs[0][i]; ++ g = srcs[1][i]; ++ b = srcs[2][i]; ++ dst[3*i+0] = r+g; ++ dst[3*i+1] = g; ++ dst[3*i+2] = b+g; ++ } ++ dst += p->linesize[0]; ++ for (i = 0; i < 3; i++) ++ srcs[i] += l->rgb_stride; ++ } ++ break; + case FRAME_ARITH_YV12: + avctx->pix_fmt = PIX_FMT_YUV420P; + +@@ -504,19 +614,19 @@ + + if (l->picture.data[0]) + avctx->release_buffer(avctx, &l->picture); ++ av_freep(&l->rgb_planes); + + return 0; + } + + AVCodec ff_lagarith_decoder = { +- "lagarith", +- CODEC_TYPE_VIDEO, +- CODEC_ID_LAGARITH, +- sizeof(LagarithContext), +- lag_decode_init, +- NULL, +- lag_decode_end, +- lag_decode_frame, +- CODEC_CAP_DR1, ++ .name = "lagarith", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_LAGARITH, ++ .priv_data_size = sizeof(LagarithContext), ++ .init = lag_decode_init, ++ .close = lag_decode_end, ++ .decode = lag_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Lagarith lossless"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarithrac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarithrac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarithrac.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarithrac.c 2012-05-14 14:08:53.908331408 +0200 +@@ -21,7 +21,7 @@ + */ + + /** +- * @file libavcodec/lagarithrac.c ++ * @file + * Lagarith range decoder + * @author Nathan Caldwell + * @author David Conrad +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarithrac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarithrac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lagarithrac.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lagarithrac.h 2012-05-14 14:08:53.909331429 +0200 +@@ -21,7 +21,7 @@ + */ + + /** +- * @file libavcodec/lagarithrac.h ++ * @file + * Lagarith range decoder + * @author Nathan Caldwell + * @author David Conrad +@@ -40,15 +40,15 @@ + AVCodecContext *avctx; + unsigned low; + unsigned range; +- unsigned scale; /*!< Number of bits of precision in range. */ +- unsigned hash_shift; /*!< Number of bits to shift to calculate hash for radix search. */ ++ unsigned scale; /**< Number of bits of precision in range. */ ++ unsigned hash_shift; /**< Number of bits to shift to calculate hash for radix search. */ + +- const uint8_t *bytestream_start; /*!< Start of input bytestream. */ +- const uint8_t *bytestream; /*!< Current position in input bytestream. */ +- const uint8_t *bytestream_end; /*!< End position of input bytestream. */ ++ const uint8_t *bytestream_start; /**< Start of input bytestream. */ ++ const uint8_t *bytestream; /**< Current position in input bytestream. */ ++ const uint8_t *bytestream_end; /**< End position of input bytestream. */ + +- uint32_t prob[258]; /*!< Table of cumulative probability for each symbol. */ +- uint8_t range_hash[256]; /*!< Hash table mapping upper byte to approximate symbol. */ ++ uint32_t prob[258]; /**< Table of cumulative probability for each symbol. */ ++ uint8_t range_hash[256]; /**< Hash table mapping upper byte to approximate symbol. */ + } lag_rac; + + void lag_rac_init(lag_rac *l, GetBitContext *gb, int length); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/latm_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/latm_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/latm_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/latm_parser.c 2012-05-14 14:08:53.910331449 +0200 +@@ -36,7 +36,7 @@ + } LATMParseContext; + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ + static int latm_find_frame_end(AVCodecParserContext *s1, const uint8_t *buf, +@@ -106,9 +106,8 @@ + } + + AVCodecParser ff_aac_latm_parser = { +- { CODEC_ID_AAC_LATM }, +- sizeof(LATMParseContext), +- NULL, +- latm_parse, +- ff_parse_close ++ .codec_ids = { CODEC_ID_AAC_LATM }, ++ .priv_data_size = sizeof(LATMParseContext), ++ .parser_parse = latm_parse, ++ .parser_close = ff_parse_close + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lcldec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lcldec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lcldec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lcldec.c 2012-05-14 14:08:53.911331469 +0200 +@@ -73,8 +73,8 @@ + + + /** +- * \param srcptr compressed source buffer, must be padded with at least 5 extra bytes +- * \param destptr must be padded sufficiently for av_memcpy_backptr ++ * @param srcptr compressed source buffer, must be padded with at least 5 extra bytes ++ * @param destptr must be padded sufficiently for av_memcpy_backptr + */ + static unsigned int mszh_decomp(const unsigned char * srcptr, int srclen, unsigned char * destptr, unsigned int destsize) + { +@@ -96,7 +96,13 @@ + ofs = FFMIN(ofs, destptr - destptr_bak); + cnt *= 4; + cnt = FFMIN(cnt, destptr_end - destptr); +- av_memcpy_backptr(destptr, ofs, cnt); ++ if (ofs) { ++ av_memcpy_backptr(destptr, ofs, cnt); ++ } else { ++ // Not known what the correct behaviour is, but ++ // this at least avoids uninitialized data. ++ memset(destptr, 0, cnt); ++ } + destptr += cnt; + } + maskbit >>= 1; +@@ -119,11 +125,11 @@ + + #if CONFIG_ZLIB_DECODER + /** +- * \brief decompress a zlib-compressed data block into decomp_buf +- * \param src compressed input buffer +- * \param src_len data length in input buffer +- * \param offset offset in decomp_buf +- * \param expected expected decompressed length ++ * @brief decompress a zlib-compressed data block into decomp_buf ++ * @param src compressed input buffer ++ * @param src_len data length in input buffer ++ * @param offset offset in decomp_buf ++ * @param expected expected decompressed length + */ + static int zlib_decomp(AVCodecContext *avctx, const uint8_t *src, int src_len, int offset, int expected) + { +@@ -223,8 +229,29 @@ + len = mszh_dlen; + } + break; +- case COMP_MSZH_NOCOMP: ++ case COMP_MSZH_NOCOMP: { ++ int bppx2; ++ switch (c->imgtype) { ++ case IMGTYPE_YUV111: ++ case IMGTYPE_RGB24: ++ bppx2 = 6; ++ break; ++ case IMGTYPE_YUV422: ++ case IMGTYPE_YUV211: ++ bppx2 = 4; ++ break; ++ case IMGTYPE_YUV411: ++ case IMGTYPE_YUV420: ++ bppx2 = 3; ++ break; ++ default: ++ bppx2 = 0; // will error out below ++ break; ++ } ++ if (len < ((width * height * bppx2) >> 1)) ++ return AVERROR_INVALIDDATA; + break; ++ } + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown MSZH compression in frame decoder.\n"); + return -1; +@@ -453,9 +480,10 @@ + unsigned int max_basesize = FFALIGN(avctx->width, 4) * FFALIGN(avctx->height, 4) + AV_LZO_OUTPUT_PADDING; + unsigned int max_decomp_size; + ++ avcodec_get_frame_defaults(&c->pic); + if (avctx->extradata_size < 8) { + av_log(avctx, AV_LOG_ERROR, "Extradata size too small.\n"); +- return 1; ++ return AVERROR_INVALIDDATA; + } + + /* Check codec type */ +@@ -504,7 +532,7 @@ + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported image format %d.\n", c->imgtype); +- return 1; ++ return AVERROR_INVALIDDATA; + } + + /* Detect compression method */ +@@ -521,7 +549,7 @@ + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported compression format for MSZH (%d).\n", c->compression); +- return 1; ++ return AVERROR_INVALIDDATA; + } + break; + #if CONFIG_ZLIB_DECODER +@@ -539,7 +567,7 @@ + default: + if (c->compression < Z_NO_COMPRESSION || c->compression > Z_BEST_COMPRESSION) { + av_log(avctx, AV_LOG_ERROR, "Unsupported compression level for ZLIB: (%d).\n", c->compression); +- return 1; ++ return AVERROR_INVALIDDATA; + } + av_log(avctx, AV_LOG_DEBUG, "Compression level for ZLIB: (%d).\n", c->compression); + } +@@ -547,14 +575,14 @@ + #endif + default: + av_log(avctx, AV_LOG_ERROR, "BUG! Unknown codec in compression switch.\n"); +- return 1; ++ return AVERROR_INVALIDDATA; + } + + /* Allocate decompression buffer */ + if (c->decomp_size) { + if ((c->decomp_buf = av_malloc(max_decomp_size)) == NULL) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); +- return 1; ++ return AVERROR(ENOMEM); + } + } + +@@ -580,7 +608,7 @@ + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + av_freep(&c->decomp_buf); +- return 1; ++ return AVERROR_UNKNOWN; + } + } + #endif +@@ -610,30 +638,28 @@ + + #if CONFIG_MSZH_DECODER + AVCodec ff_mszh_decoder = { +- "mszh", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSZH, +- sizeof(LclDecContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "mszh", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSZH, ++ .priv_data_size = sizeof(LclDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) MSZH"), + }; + #endif + + #if CONFIG_ZLIB_DECODER + AVCodec ff_zlib_decoder = { +- "zlib", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ZLIB, +- sizeof(LclDecContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "zlib", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ZLIB, ++ .priv_data_size = sizeof(LclDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lclenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lclenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lclenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lclenc.c 2012-05-14 14:08:53.912331489 +0200 +@@ -76,7 +76,7 @@ + int zret; // Zlib return code + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + if(avctx->pix_fmt != PIX_FMT_BGR24){ +@@ -171,13 +171,13 @@ + } + + AVCodec ff_zlib_encoder = { +- "zlib", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ZLIB, +- sizeof(LclEncContext), +- encode_init, +- encode_frame, +- encode_end, ++ .name = "zlib", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ZLIB, ++ .priv_data_size = sizeof(LclEncContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGR24, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("LCL (LossLess Codec Library) ZLIB"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libaacplus.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libaacplus.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libaacplus.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libaacplus.c 2012-05-14 14:08:53.912331489 +0200 +@@ -0,0 +1,134 @@ ++/* ++ * Interface to libaacplus for aac+ (sbr+ps) encoding ++ * Copyright (c) 2010 tipok ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Interface to libaacplus for aac+ (sbr+ps) encoding. ++ */ ++ ++#include "avcodec.h" ++#include ++ ++typedef struct aacPlusAudioContext { ++ aacplusEncHandle aacplus_handle; ++} aacPlusAudioContext; ++ ++static av_cold int aacPlus_encode_init(AVCodecContext *avctx) ++{ ++ aacPlusAudioContext *s = avctx->priv_data; ++ aacplusEncConfiguration *aacplus_cfg; ++ unsigned long samples_input, max_bytes_output; ++ ++ /* number of channels */ ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "encoding %d channel(s) is not allowed\n", avctx->channels); ++ return -1; ++ } ++ ++ s->aacplus_handle = aacplusEncOpen(avctx->sample_rate, ++ avctx->channels, ++ &samples_input, &max_bytes_output); ++ if(!s->aacplus_handle) { ++ av_log(avctx, AV_LOG_ERROR, "can't open encoder\n"); ++ return -1; ++ } ++ ++ /* check aacplus version */ ++ aacplus_cfg = aacplusEncGetCurrentConfiguration(s->aacplus_handle); ++ ++ /* put the options in the configuration struct */ ++ if(avctx->profile != FF_PROFILE_AAC_LOW && avctx->profile != FF_PROFILE_UNKNOWN) { ++ av_log(avctx, AV_LOG_ERROR, "invalid AAC profile: %d, only LC supported\n", avctx->profile); ++ aacplusEncClose(s->aacplus_handle); ++ return -1; ++ } ++ ++ aacplus_cfg->bitRate = avctx->bit_rate; ++ aacplus_cfg->bandWidth = avctx->cutoff; ++ aacplus_cfg->outputFormat = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER); ++ aacplus_cfg->inputFormat = AACPLUS_INPUT_16BIT; ++ if (!aacplusEncSetConfiguration(s->aacplus_handle, aacplus_cfg)) { ++ av_log(avctx, AV_LOG_ERROR, "libaacplus doesn't support this output format!\n"); ++ return -1; ++ } ++ ++ avctx->frame_size = samples_input / avctx->channels; ++ ++ avctx->coded_frame= avcodec_alloc_frame(); ++ avctx->coded_frame->key_frame= 1; ++ ++ /* Set decoder specific info */ ++ avctx->extradata_size = 0; ++ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { ++ ++ unsigned char *buffer = NULL; ++ unsigned long decoder_specific_info_size; ++ ++ if (aacplusEncGetDecoderSpecificInfo(s->aacplus_handle, &buffer, ++ &decoder_specific_info_size) == 1) { ++ avctx->extradata = av_malloc(decoder_specific_info_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ avctx->extradata_size = decoder_specific_info_size; ++ memcpy(avctx->extradata, buffer, avctx->extradata_size); ++ } ++#undef free ++ free(buffer); ++#define free please_use_av_free ++ } ++ return 0; ++} ++ ++static int aacPlus_encode_frame(AVCodecContext *avctx, ++ unsigned char *frame, int buf_size, void *data) ++{ ++ aacPlusAudioContext *s = avctx->priv_data; ++ int bytes_written; ++ ++ bytes_written = aacplusEncEncode(s->aacplus_handle, ++ data, ++ avctx->frame_size * avctx->channels, ++ frame, ++ buf_size); ++ ++ return bytes_written; ++} ++ ++static av_cold int aacPlus_encode_close(AVCodecContext *avctx) ++{ ++ aacPlusAudioContext *s = avctx->priv_data; ++ ++ av_freep(&avctx->coded_frame); ++ av_freep(&avctx->extradata); ++ ++ aacplusEncClose(s->aacplus_handle); ++ return 0; ++} ++ ++AVCodec ff_libaacplus_encoder = { ++ .name = "libaacplus", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AAC, ++ .priv_data_size = sizeof(aacPlusAudioContext), ++ .init = aacPlus_encode_init, ++ .encode = aacPlus_encode_frame, ++ .close = aacPlus_encode_close, ++ .sample_fmts = (const enum SampleFormat[]){AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("libaacplus AAC+ (Advanced Audio Codec with SBR+PS)"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libavcodec.v xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libavcodec.v +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libavcodec.v 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libavcodec.v 2012-05-14 14:08:53.913331509 +0200 +@@ -1,9 +1,31 @@ + LIBAVCODEC_$MAJOR { +- global: *; +- local: +- ff_*_bsf; +- ff_*_decoder; +- ff_*_encoder; +- ff_*_hwaccel; +- ff_*_parser; ++ global: av*; ++ audio_resample; ++ audio_resample_close; ++ #deprecated, remove after next bump ++ img_get_alpha_info; ++ dsputil_init; ++ ff_find_pix_fmt; ++ ff_framenum_to_drop_timecode; ++ ff_framenum_to_smtpe_timecode; ++ ff_raw_pix_fmt_tags; ++ ff_init_smtpe_timecode; ++ ff_fft*; ++ ff_mdct*; ++ ff_dct*; ++ ff_rdft*; ++ ff_prores_idct_put_10_sse2; ++ ff_simple_idct*; ++ ff_aanscales; ++ ff_faan*; ++ ff_mmx_idct; ++ ff_fdct*; ++ fdct_ifast; ++ j_rev_dct; ++ ff_mmxext_idct; ++ ff_idct_xvid*; ++ ff_jpeg_fdct*; ++ #XBMC's configure checks for ff_vdpau_vc1_decode_picture() ++ ff_vdpau_vc1_decode_picture; ++ local: *; + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libcelt_dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libcelt_dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libcelt_dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libcelt_dec.c 2012-05-14 14:08:53.914331529 +0200 +@@ -0,0 +1,145 @@ ++/* ++ * Xiph CELT decoder using libcelt ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include "avcodec.h" ++#include "libavutil/intreadwrite.h" ++ ++struct libcelt_context { ++ CELTMode *mode; ++ CELTDecoder *dec; ++ AVFrame frame; ++ int discard; ++}; ++ ++static int ff_celt_error_to_averror(int err) ++{ ++ switch (err) { ++ case CELT_BAD_ARG: return AVERROR(EINVAL); ++#ifdef CELT_BUFFER_TOO_SMALL ++ case CELT_BUFFER_TOO_SMALL: return AVERROR(ENOBUFS); ++#endif ++ case CELT_INTERNAL_ERROR: return AVERROR(EFAULT); ++ case CELT_CORRUPTED_DATA: return AVERROR_INVALIDDATA; ++ case CELT_UNIMPLEMENTED: return AVERROR(ENOSYS); ++#ifdef ENOTRECOVERABLE ++ case CELT_INVALID_STATE: return AVERROR(ENOTRECOVERABLE); ++#endif ++ case CELT_ALLOC_FAIL: return AVERROR(ENOMEM); ++ default: return AVERROR(EINVAL); ++ } ++} ++ ++static int ff_celt_bitstream_version_hack(CELTMode *mode) ++{ ++ CELTHeader header = { .version_id = 0 }; ++ celt_header_init(&header, mode, 960, 2); ++ return header.version_id; ++} ++ ++static av_cold int libcelt_dec_init(AVCodecContext *c) ++{ ++ struct libcelt_context *celt = c->priv_data; ++ int err; ++ ++ if (!c->channels || !c->frame_size || ++ c->frame_size > INT_MAX / sizeof(int16_t) / c->channels) ++ return AVERROR(EINVAL); ++ celt->mode = celt_mode_create(c->sample_rate, c->frame_size, &err); ++ if (!celt->mode) ++ return ff_celt_error_to_averror(err); ++ celt->dec = celt_decoder_create_custom(celt->mode, c->channels, &err); ++ if (!celt->dec) { ++ celt_mode_destroy(celt->mode); ++ return ff_celt_error_to_averror(err); ++ } ++ if (c->extradata_size >= 4) { ++ celt->discard = AV_RL32(c->extradata); ++ if (celt->discard < 0 || celt->discard >= c->frame_size) { ++ av_log(c, AV_LOG_WARNING, ++ "Invalid overlap (%d), ignored.\n", celt->discard); ++ celt->discard = 0; ++ } ++ } ++ if (c->extradata_size >= 8) { ++ unsigned version = AV_RL32(c->extradata + 4); ++ unsigned lib_version = ff_celt_bitstream_version_hack(celt->mode); ++ if (version != lib_version) ++ av_log(c, AV_LOG_WARNING, ++ "CELT bitstream version 0x%x may be " ++ "improperly decoded by libcelt for version 0x%x.\n", ++ version, lib_version); ++ } ++ c->sample_fmt = AV_SAMPLE_FMT_S16; ++ avcodec_get_frame_defaults(&celt->frame); ++ c->coded_frame = &celt->frame; ++ return 0; ++} ++ ++static av_cold int libcelt_dec_close(AVCodecContext *c) ++{ ++ struct libcelt_context *celt = c->priv_data; ++ ++ celt_decoder_destroy(celt->dec); ++ celt_mode_destroy(celt->mode); ++ return 0; ++} ++ ++static int libcelt_dec_decode(AVCodecContext *c, void *frame, ++ int *got_frame_ptr, AVPacket *pkt) ++{ ++ struct libcelt_context *celt = c->priv_data; ++ int err; ++ int16_t *pcm; ++ ++ celt->frame.nb_samples = c->frame_size; ++ err = c->get_buffer(c, &celt->frame); ++ if (err < 0) { ++ av_log(c, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return err; ++ } ++ pcm = (int16_t *)celt->frame.data[0]; ++ err = celt_decode(celt->dec, pkt->data, pkt->size, pcm, c->frame_size); ++ if (err < 0) ++ return ff_celt_error_to_averror(err); ++ if (celt->discard) { ++ celt->frame.nb_samples -= celt->discard; ++ memmove(pcm, pcm + celt->discard * c->channels, ++ celt->frame.nb_samples * c->channels * sizeof(int16_t)); ++ celt->discard = 0; ++ } ++ *got_frame_ptr = 1; ++ *(AVFrame *)frame = celt->frame; ++ return pkt->size; ++} ++ ++AVCodec ff_libcelt_decoder = { ++ .name = "libcelt", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_CELT, ++ .priv_data_size = sizeof(struct libcelt_context), ++ .init = libcelt_dec_init, ++ .close = libcelt_dec_close, ++ .decode = libcelt_dec_decode, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Xiph CELT decoder using libcelt"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdiracdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdiracdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdiracdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdiracdec.c 2012-05-14 14:08:53.917331589 +0200 +@@ -28,7 +28,7 @@ + * (http://dirac.sourceforge.net/specification.html). + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "libdirac.h" + + #undef NDEBUG +@@ -37,34 +37,34 @@ + #include + + /** contains a single frame returned from Dirac */ +-typedef struct FfmpegDiracDecoderParams { ++typedef struct DiracDecoderParams { + /** decoder handle */ + dirac_decoder_t* p_decoder; + + /** buffer to hold decoded frame */ + unsigned char* p_out_frame_buf; +-} FfmpegDiracDecoderParams; ++} DiracDecoderParams; + + + /** + * returns FFmpeg chroma format + */ +-static enum PixelFormat GetFfmpegChromaFormat(dirac_chroma_t dirac_pix_fmt) ++static enum PixelFormat get_chroma_format(dirac_chroma_t dirac_pix_fmt) + { +- int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) / +- sizeof(ffmpeg_dirac_pixel_format_map[0]); ++ int num_formats = sizeof(dirac_pixel_format_map) / ++ sizeof(dirac_pixel_format_map[0]); + int idx; + + for (idx = 0; idx < num_formats; ++idx) +- if (ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) +- return ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt; ++ if (dirac_pixel_format_map[idx].dirac_pix_fmt == dirac_pix_fmt) ++ return dirac_pixel_format_map[idx].ff_pix_fmt; + return PIX_FMT_NONE; + } + + static av_cold int libdirac_decode_init(AVCodecContext *avccontext) + { + +- FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; ++ DiracDecoderParams *p_dirac_params = avccontext->priv_data; + p_dirac_params->p_decoder = dirac_decoder_init(avccontext->debug); + + if (!p_dirac_params->p_decoder) +@@ -80,7 +80,7 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + +- FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; ++ DiracDecoderParams *p_dirac_params = avccontext->priv_data; + AVPicture *picture = data; + AVPicture pic; + int pict_size; +@@ -117,7 +117,7 @@ + avccontext->height = src_params->height; + avccontext->width = src_params->width; + +- avccontext->pix_fmt = GetFfmpegChromaFormat(src_params->chroma); ++ avccontext->pix_fmt = get_chroma_format(src_params->chroma); + if (avccontext->pix_fmt == PIX_FMT_NONE) { + av_log(avccontext, AV_LOG_ERROR, + "Dirac chroma format %d not supported currently\n", +@@ -174,7 +174,7 @@ + + static av_cold int libdirac_decode_close(AVCodecContext *avccontext) + { +- FfmpegDiracDecoderParams *p_dirac_params = avccontext->priv_data; ++ DiracDecoderParams *p_dirac_params = avccontext->priv_data; + dirac_decoder_close(p_dirac_params->p_decoder); + + av_freep(&p_dirac_params->p_out_frame_buf); +@@ -195,15 +195,14 @@ + + + AVCodec ff_libdirac_decoder = { +- "libdirac", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DIRAC, +- sizeof(FfmpegDiracDecoderParams), +- libdirac_decode_init, +- NULL, +- libdirac_decode_close, +- libdirac_decode_frame, +- CODEC_CAP_DELAY, ++ .name = "libdirac", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DIRAC, ++ .priv_data_size = sizeof(DiracDecoderParams), ++ .init = libdirac_decode_init, ++ .close = libdirac_decode_close, ++ .decode = libdirac_decode_frame, ++ .capabilities = CODEC_CAP_DELAY, + .flush = libdirac_flush, + .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdiracenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdiracenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdiracenc.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdiracenc.c 2012-05-14 14:08:53.918331609 +0200 +@@ -38,7 +38,7 @@ + #include + + /** Dirac encoder private data */ +-typedef struct FfmpegDiracEncoderParams { ++typedef struct DiracEncoderParams { + /** Dirac encoder context */ + dirac_encoder_context_t enc_ctx; + +@@ -61,27 +61,27 @@ + int enc_buf_size; + + /** queue storing encoded frames */ +- FfmpegDiracSchroQueue enc_frame_queue; ++ DiracSchroQueue enc_frame_queue; + + /** end of sequence signalled by user, 0 - false, 1 - true */ + int eos_signalled; + + /** end of sequence returned by encoder, 0 - false, 1 - true */ + int eos_pulled; +-} FfmpegDiracEncoderParams; ++} DiracEncoderParams; + + /** + * Works out Dirac-compatible chroma format. + */ + static dirac_chroma_t GetDiracChromaFormat(enum PixelFormat ff_pix_fmt) + { +- int num_formats = sizeof(ffmpeg_dirac_pixel_format_map) / +- sizeof(ffmpeg_dirac_pixel_format_map[0]); ++ int num_formats = sizeof(dirac_pixel_format_map) / ++ sizeof(dirac_pixel_format_map[0]); + int idx; + + for (idx = 0; idx < num_formats; ++idx) +- if (ffmpeg_dirac_pixel_format_map[idx].ff_pix_fmt == ff_pix_fmt) +- return ffmpeg_dirac_pixel_format_map[idx].dirac_pix_fmt; ++ if (dirac_pixel_format_map[idx].ff_pix_fmt == ff_pix_fmt) ++ return dirac_pixel_format_map[idx].dirac_pix_fmt; + return formatNK; + } + +@@ -127,7 +127,7 @@ + static av_cold int libdirac_encode_init(AVCodecContext *avccontext) + { + +- FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; ++ DiracEncoderParams* p_dirac_params = avccontext->priv_data; + int no_local = 1; + int verbose = avccontext->debug; + VideoFormat preset; +@@ -136,7 +136,7 @@ + preset = GetDiracVideoFormatPreset(avccontext); + + /* initialize the encoder context */ +- dirac_encoder_context_init(&(p_dirac_params->enc_ctx), preset); ++ dirac_encoder_context_init(&p_dirac_params->enc_ctx, preset); + + p_dirac_params->enc_ctx.src_params.chroma = GetDiracChromaFormat(avccontext->pix_fmt); + +@@ -199,7 +199,7 @@ + * irrespective of the type of source material */ + p_dirac_params->enc_ctx.enc_params.picture_coding_mode = 1; + +- p_dirac_params->p_encoder = dirac_encoder_init(&(p_dirac_params->enc_ctx), ++ p_dirac_params->p_encoder = dirac_encoder_init(&p_dirac_params->enc_ctx, + verbose); + + if (!p_dirac_params->p_encoder) { +@@ -219,9 +219,9 @@ + + static void DiracFreeFrame(void *data) + { +- FfmpegDiracSchroEncodedFrame *enc_frame = data; ++ DiracSchroEncodedFrame *enc_frame = data; + +- av_freep(&(enc_frame->p_encbuf)); ++ av_freep(&enc_frame->p_encbuf); + av_free(enc_frame); + } + +@@ -231,9 +231,9 @@ + { + int enc_size = 0; + dirac_encoder_state_t state; +- FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; +- FfmpegDiracSchroEncodedFrame* p_frame_output = NULL; +- FfmpegDiracSchroEncodedFrame* p_next_output_frame = NULL; ++ DiracEncoderParams *p_dirac_params = avccontext->priv_data; ++ DiracSchroEncodedFrame *p_frame_output = NULL; ++ DiracSchroEncodedFrame *p_next_output_frame = NULL; + int go = 1; + int last_frame_in_sequence = 0; + +@@ -303,7 +303,7 @@ + break; + + /* create output frame */ +- p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame)); ++ p_frame_output = av_mallocz(sizeof(DiracSchroEncodedFrame)); + /* set output data */ + p_frame_output->size = p_dirac_params->enc_buf_size; + p_frame_output->p_encbuf = p_dirac_params->enc_buf; +@@ -371,7 +371,7 @@ + + static av_cold int libdirac_encode_close(AVCodecContext *avccontext) + { +- FfmpegDiracEncoderParams* p_dirac_params = avccontext->priv_data; ++ DiracEncoderParams *p_dirac_params = avccontext->priv_data; + + /* close the encoder */ + dirac_encoder_close(p_dirac_params->p_encoder); +@@ -392,13 +392,13 @@ + + + AVCodec ff_libdirac_encoder = { +- "libdirac", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DIRAC, +- sizeof(FfmpegDiracEncoderParams), +- libdirac_encode_init, +- libdirac_encode_frame, +- libdirac_encode_close, ++ .name = "libdirac", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DIRAC, ++ .priv_data_size = sizeof(DiracEncoderParams), ++ .init = libdirac_encode_init, ++ .encode = libdirac_encode_frame, ++ .close = libdirac_encode_close, + .capabilities = CODEC_CAP_DELAY, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libdirac Dirac 2.2"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac.h 2012-05-14 14:08:53.914331529 +0200 +@@ -20,7 +20,7 @@ + + /** + * @file +-* data structures common to libdiracenc.c and libdiracdec.c ++* data structures common to libdirac encoder and decoder + */ + + #ifndef AVCODEC_LIBDIRAC_H +@@ -35,7 +35,7 @@ + static const struct { + enum PixelFormat ff_pix_fmt; + dirac_chroma_t dirac_pix_fmt; +-} ffmpeg_dirac_pixel_format_map[] = { ++} dirac_pixel_format_map[] = { + { PIX_FMT_YUV420P, format420 }, + { PIX_FMT_YUV422P, format422 }, + { PIX_FMT_YUV444P, format444 }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac_libschro.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac_libschro.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac_libschro.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac_libschro.c 2012-05-14 14:08:53.915331549 +0200 +@@ -25,7 +25,7 @@ + + #include "libdirac_libschro.h" + +-static const FfmpegDiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = { ++static const DiracSchroVideoFormatInfo ff_dirac_schro_video_format_info[] = { + { 640, 480, 24000, 1001}, + { 176, 120, 15000, 1001}, + { 176, 144, 25, 2 }, +@@ -53,7 +53,7 @@ + sizeof(ff_dirac_schro_video_format_info[0]); + + for (idx = 1; idx < num_formats; ++idx) { +- const FfmpegDiracSchroVideoFormatInfo *vf = &ff_dirac_schro_video_format_info[idx]; ++ const DiracSchroVideoFormatInfo *vf = &ff_dirac_schro_video_format_info[idx]; + if (avccontext->width == vf->width && + avccontext->height == vf->height) { + ret_idx = idx; +@@ -65,22 +65,22 @@ + return ret_idx; + } + +-void ff_dirac_schro_queue_init(FfmpegDiracSchroQueue *queue) ++void ff_dirac_schro_queue_init(DiracSchroQueue *queue) + { + queue->p_head = queue->p_tail = NULL; + queue->size = 0; + } + +-void ff_dirac_schro_queue_free(FfmpegDiracSchroQueue *queue, ++void ff_dirac_schro_queue_free(DiracSchroQueue *queue, + void (*free_func)(void *)) + { + while (queue->p_head) + free_func(ff_dirac_schro_queue_pop(queue)); + } + +-int ff_dirac_schro_queue_push_back(FfmpegDiracSchroQueue *queue, void *p_data) ++int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data) + { +- FfmpegDiracSchroQueueElement *p_new = av_mallocz(sizeof(FfmpegDiracSchroQueueElement)); ++ DiracSchroQueueElement *p_new = av_mallocz(sizeof(DiracSchroQueueElement)); + + if (!p_new) + return -1; +@@ -97,9 +97,9 @@ + return 0; + } + +-void *ff_dirac_schro_queue_pop(FfmpegDiracSchroQueue *queue) ++void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue) + { +- FfmpegDiracSchroQueueElement *top = queue->p_head; ++ DiracSchroQueueElement *top = queue->p_head; + + if (top) { + void *data = top->data; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac_libschro.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac_libschro.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libdirac_libschro.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libdirac_libschro.h 2012-05-14 14:08:53.916331569 +0200 +@@ -33,7 +33,7 @@ + uint16_t height; + uint16_t frame_rate_num; + uint16_t frame_rate_denom; +-} FfmpegDiracSchroVideoFormatInfo; ++} DiracSchroVideoFormatInfo; + + /** + * Returns the index into the Dirac Schro common video format info table +@@ -43,7 +43,7 @@ + /** + * contains a single encoded frame returned from Dirac or Schroedinger + */ +-typedef struct FfmpegDiracSchroEncodedFrame { ++typedef struct DiracSchroEncodedFrame { + /** encoded frame data */ + uint8_t *p_encbuf; + +@@ -55,51 +55,51 @@ + + /** key frame flag. 1 : is key frame , 0 : in not key frame */ + uint16_t key_frame; +-} FfmpegDiracSchroEncodedFrame; ++} DiracSchroEncodedFrame; + + /** + * queue element + */ +-typedef struct FfmpegDiracSchroQueueElement { ++typedef struct DiracSchroQueueElement { + /** Data to be stored in queue*/ + void *data; + /** Pointer to next element queue */ +- struct FfmpegDiracSchroQueueElement *next; +-} FfmpegDiracSchroQueueElement; ++ struct DiracSchroQueueElement *next; ++} DiracSchroQueueElement; + + + /** + * A simple queue implementation used in libdirac and libschroedinger + */ +-typedef struct FfmpegDiracSchroQueue { ++typedef struct DiracSchroQueue { + /** Pointer to head of queue */ +- FfmpegDiracSchroQueueElement *p_head; ++ DiracSchroQueueElement *p_head; + /** Pointer to tail of queue */ +- FfmpegDiracSchroQueueElement *p_tail; ++ DiracSchroQueueElement *p_tail; + /** Queue size*/ + int size; +-} FfmpegDiracSchroQueue; ++} DiracSchroQueue; + + /** + * Initialise the queue + */ +-void ff_dirac_schro_queue_init(FfmpegDiracSchroQueue *queue); ++void ff_dirac_schro_queue_init(DiracSchroQueue *queue); + + /** + * Add an element to the end of the queue + */ +-int ff_dirac_schro_queue_push_back(FfmpegDiracSchroQueue *queue, void *p_data); ++int ff_dirac_schro_queue_push_back(DiracSchroQueue *queue, void *p_data); + + /** + * Return the first element in the queue + */ +-void *ff_dirac_schro_queue_pop(FfmpegDiracSchroQueue *queue); ++void *ff_dirac_schro_queue_pop(DiracSchroQueue *queue); + + /** + * Free the queue resources. free_func is a function supplied by the caller to + * free any resources allocated by the caller. The data field of the queue + * element is passed to it. + */ +-void ff_dirac_schro_queue_free(FfmpegDiracSchroQueue *queue, ++void ff_dirac_schro_queue_free(DiracSchroQueue *queue, + void (*free_func)(void *)); + #endif /* AVCODEC_LIBDIRAC_LIBSCHRO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libfaac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libfaac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libfaac.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libfaac.c 2012-05-14 14:08:53.919331629 +0200 +@@ -31,6 +31,13 @@ + faacEncHandle faac_handle; + } FaacAudioContext; + ++static const int channel_maps[][6] = { ++ { 2, 0, 1 }, //< C L R ++ { 2, 0, 1, 3 }, //< C L R Cs ++ { 2, 0, 1, 3, 4 }, //< C L R Ls Rs ++ { 2, 0, 1, 4, 5, 3 }, //< C L R Ls Rs LFE ++}; ++ + static av_cold int Faac_encode_init(AVCodecContext *avctx) + { + FaacAudioContext *s = avctx->priv_data; +@@ -86,6 +93,9 @@ + } + faac_cfg->outputFormat = 1; + faac_cfg->inputFormat = FAAC_INPUT_16BIT; ++ if (avctx->channels > 2) ++ memcpy(faac_cfg->channel_map, channel_maps[avctx->channels-3], ++ avctx->channels * sizeof(int)); + + avctx->frame_size = samples_input / avctx->channels; + +@@ -155,13 +165,13 @@ + }; + + AVCodec ff_libfaac_encoder = { +- "libfaac", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AAC, +- sizeof(FaacAudioContext), +- Faac_encode_init, +- Faac_encode_frame, +- Faac_encode_close, ++ .name = "libfaac", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AAC, ++ .priv_data_size = sizeof(FaacAudioContext), ++ .init = Faac_encode_init, ++ .encode = Faac_encode_frame, ++ .close = Faac_encode_close, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libfaac AAC (Advanced Audio Codec)"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libgsm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libgsm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libgsm.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libgsm.c 2012-05-14 14:08:53.920331649 +0200 +@@ -27,44 +27,31 @@ + + // The idiosyncrasies of GSM-in-WAV are explained at http://kbs.cs.tu-berlin.de/~jutta/toast.html + +-#include "avcodec.h" + #include + +-// gsm.h misses some essential constants +-#define GSM_BLOCK_SIZE 33 +-#define GSM_MS_BLOCK_SIZE 65 +-#define GSM_FRAME_SIZE 160 ++#include "avcodec.h" ++#include "gsm.h" + +-static av_cold int libgsm_init(AVCodecContext *avctx) { ++static av_cold int libgsm_encode_init(AVCodecContext *avctx) { + if (avctx->channels > 1) { + av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n", + avctx->channels); + return -1; + } + +- if(avctx->codec->decode){ +- if(!avctx->channels) +- avctx->channels= 1; +- +- if(!avctx->sample_rate) +- avctx->sample_rate= 8000; +- +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- }else{ +- if (avctx->sample_rate != 8000) { +- av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n", +- avctx->sample_rate); +- if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) +- return -1; +- } +- if (avctx->bit_rate != 13000 /* Official */ && +- avctx->bit_rate != 13200 /* Very common */ && +- avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) { +- av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n", +- avctx->bit_rate); +- if(avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) +- return -1; +- } ++ if (avctx->sample_rate != 8000) { ++ av_log(avctx, AV_LOG_ERROR, "Sample rate 8000Hz required for GSM, got %dHz\n", ++ avctx->sample_rate); ++ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) ++ return -1; ++ } ++ if (avctx->bit_rate != 13000 /* Official */ && ++ avctx->bit_rate != 13200 /* Very common */ && ++ avctx->bit_rate != 0 /* Unknown; a.o. mov does not set bitrate when decoding */ ) { ++ av_log(avctx, AV_LOG_ERROR, "Bitrate 13000bps required for GSM, got %dbps\n", ++ avctx->bit_rate); ++ if (avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL) ++ return -1; + } + + avctx->priv_data = gsm_create(); +@@ -88,7 +75,7 @@ + return 0; + } + +-static av_cold int libgsm_close(AVCodecContext *avctx) { ++static av_cold int libgsm_encode_close(AVCodecContext *avctx) { + av_freep(&avctx->coded_frame); + gsm_destroy(avctx->priv_data); + avctx->priv_data = NULL; +@@ -113,69 +100,145 @@ + + + AVCodec ff_libgsm_encoder = { +- "libgsm", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM, +- 0, +- libgsm_init, +- libgsm_encode_frame, +- libgsm_close, ++ .name = "libgsm", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM, ++ .init = libgsm_encode_init, ++ .encode = libgsm_encode_frame, ++ .close = libgsm_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"), + }; + + AVCodec ff_libgsm_ms_encoder = { +- "libgsm_ms", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM_MS, +- 0, +- libgsm_init, +- libgsm_encode_frame, +- libgsm_close, ++ .name = "libgsm_ms", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM_MS, ++ .init = libgsm_encode_init, ++ .encode = libgsm_encode_frame, ++ .close = libgsm_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"), + }; + +-static int libgsm_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- *data_size = 0; /* In case of error */ +- if(buf_size < avctx->block_align) return -1; ++typedef struct LibGSMDecodeContext { ++ AVFrame frame; ++ struct gsm_state *state; ++} LibGSMDecodeContext; ++ ++static av_cold int libgsm_decode_init(AVCodecContext *avctx) { ++ LibGSMDecodeContext *s = avctx->priv_data; ++ ++ if (avctx->channels > 1) { ++ av_log(avctx, AV_LOG_ERROR, "Mono required for GSM, got %d channels\n", ++ avctx->channels); ++ return -1; ++ } ++ ++ if (!avctx->channels) ++ avctx->channels = 1; ++ ++ if (!avctx->sample_rate) ++ avctx->sample_rate = 8000; ++ ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ s->state = gsm_create(); ++ + switch(avctx->codec_id) { + case CODEC_ID_GSM: +- if(gsm_decode(avctx->priv_data,buf,data)) return -1; +- *data_size = GSM_FRAME_SIZE*sizeof(int16_t); ++ avctx->frame_size = GSM_FRAME_SIZE; ++ avctx->block_align = GSM_BLOCK_SIZE; + break; +- case CODEC_ID_GSM_MS: +- if(gsm_decode(avctx->priv_data,buf,data) || +- gsm_decode(avctx->priv_data,buf+33,((int16_t*)data)+GSM_FRAME_SIZE)) return -1; +- *data_size = GSM_FRAME_SIZE*sizeof(int16_t)*2; ++ case CODEC_ID_GSM_MS: { ++ int one = 1; ++ gsm_option(s->state, GSM_OPT_WAV49, &one); ++ avctx->frame_size = 2 * GSM_FRAME_SIZE; ++ avctx->block_align = GSM_MS_BLOCK_SIZE; ++ } ++ } ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ ++ return 0; ++} ++ ++static av_cold int libgsm_decode_close(AVCodecContext *avctx) { ++ LibGSMDecodeContext *s = avctx->priv_data; ++ ++ gsm_destroy(s->state); ++ s->state = NULL; ++ return 0; ++} ++ ++static int libgsm_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ int i, ret; ++ LibGSMDecodeContext *s = avctx->priv_data; ++ uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int16_t *samples; ++ ++ if (buf_size < avctx->block_align) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; + } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = avctx->frame_size; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)s->frame.data[0]; ++ ++ for (i = 0; i < avctx->frame_size / GSM_FRAME_SIZE; i++) { ++ if ((ret = gsm_decode(s->state, buf, samples)) < 0) ++ return -1; ++ buf += GSM_BLOCK_SIZE; ++ samples += GSM_FRAME_SIZE; ++ } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return avctx->block_align; + } + ++static void libgsm_flush(AVCodecContext *avctx) { ++ LibGSMDecodeContext *s = avctx->priv_data; ++ int one = 1; ++ ++ gsm_destroy(s->state); ++ s->state = gsm_create(); ++ if (avctx->codec_id == CODEC_ID_GSM_MS) ++ gsm_option(s->state, GSM_OPT_WAV49, &one); ++} ++ + AVCodec ff_libgsm_decoder = { +- "libgsm", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM, +- 0, +- libgsm_init, +- NULL, +- libgsm_close, +- libgsm_decode_frame, ++ .name = "libgsm", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM, ++ .priv_data_size = sizeof(LibGSMDecodeContext), ++ .init = libgsm_decode_init, ++ .close = libgsm_decode_close, ++ .decode = libgsm_decode_frame, ++ .flush = libgsm_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM"), + }; + + AVCodec ff_libgsm_ms_decoder = { +- "libgsm_ms", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_GSM_MS, +- 0, +- libgsm_init, +- NULL, +- libgsm_close, +- libgsm_decode_frame, ++ .name = "libgsm_ms", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_GSM_MS, ++ .priv_data_size = sizeof(LibGSMDecodeContext), ++ .init = libgsm_decode_init, ++ .close = libgsm_decode_close, ++ .decode = libgsm_decode_frame, ++ .flush = libgsm_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("libgsm GSM Microsoft variant"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libmp3lame.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libmp3lame.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libmp3lame.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libmp3lame.c 2012-05-14 14:08:53.921331669 +0200 +@@ -24,24 +24,36 @@ + * Interface to libmp3lame for mp3 encoding. + */ + ++#include "libavutil/intreadwrite.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "mpegaudio.h" + #include + +-#define BUFFER_SIZE (7200 + 2*MPA_FRAME_SIZE + MPA_FRAME_SIZE/4) ++#define BUFFER_SIZE (7200 + 2 * MPA_FRAME_SIZE + MPA_FRAME_SIZE / 4+1000) // FIXME: Buffer size to small? Adding 1000 to make up for it. + typedef struct Mp3AudioContext { ++ AVClass *class; + lame_global_flags *gfp; + int stereo; + uint8_t buffer[BUFFER_SIZE]; + int buffer_index; ++ struct { ++ int *left; ++ int *right; ++ } s32_data; ++ int reservoir; + } Mp3AudioContext; + + static av_cold int MP3lame_encode_init(AVCodecContext *avctx) + { + Mp3AudioContext *s = avctx->priv_data; + +- if (avctx->channels > 2) +- return -1; ++ if (avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid number of channels %d, must be <= 2\n", avctx->channels); ++ return AVERROR(EINVAL); ++ } + + s->stereo = avctx->channels > 1 ? 1 : 0; + +@@ -50,27 +62,47 @@ + lame_set_in_samplerate(s->gfp, avctx->sample_rate); + lame_set_out_samplerate(s->gfp, avctx->sample_rate); + lame_set_num_channels(s->gfp, avctx->channels); +- if(avctx->compression_level == FF_COMPRESSION_DEFAULT) { ++ if (avctx->compression_level == FF_COMPRESSION_DEFAULT) { + lame_set_quality(s->gfp, 5); + } else { + lame_set_quality(s->gfp, avctx->compression_level); + } + lame_set_mode(s->gfp, s->stereo ? JOINT_STEREO : MONO); +- lame_set_brate(s->gfp, avctx->bit_rate/1000); +- if(avctx->flags & CODEC_FLAG_QSCALE) { ++ lame_set_brate(s->gfp, avctx->bit_rate / 1000); ++ if (avctx->flags & CODEC_FLAG_QSCALE) { + lame_set_brate(s->gfp, 0); + lame_set_VBR(s->gfp, vbr_default); +- lame_set_VBR_quality(s->gfp, avctx->global_quality/(float)FF_QP2LAMBDA); ++ lame_set_VBR_quality(s->gfp, avctx->global_quality / (float)FF_QP2LAMBDA); + } + lame_set_bWriteVbrTag(s->gfp,0); +- lame_set_disable_reservoir(s->gfp, avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR ? 0 : 1); ++#if FF_API_LAME_GLOBAL_OPTS ++ s->reservoir = avctx->flags2 & CODEC_FLAG2_BIT_RESERVOIR; ++#endif ++ lame_set_disable_reservoir(s->gfp, !s->reservoir); + if (lame_init_params(s->gfp) < 0) + goto err_close; + +- avctx->frame_size = lame_get_framesize(s->gfp); ++ avctx->frame_size = lame_get_framesize(s->gfp); ++ ++ if(!(avctx->coded_frame= avcodec_alloc_frame())) { ++ lame_close(s->gfp); ++ ++ return AVERROR(ENOMEM); ++ } ++ avctx->coded_frame->key_frame = 1; ++ ++ if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt && s->stereo) { ++ int nelem = 2 * avctx->frame_size; ++ ++ if(! (s->s32_data.left = av_malloc(nelem * sizeof(int)))) { ++ av_freep(&avctx->coded_frame); ++ lame_close(s->gfp); + +- avctx->coded_frame= avcodec_alloc_frame(); +- avctx->coded_frame->key_frame= 1; ++ return AVERROR(ENOMEM); ++ } ++ ++ s->s32_data.right = s->s32_data.left + avctx->frame_size; ++ } + + return 0; + +@@ -85,60 +117,62 @@ + }; + + static const int sBitRates[2][3][15] = { +- { { 0, 32, 64, 96,128,160,192,224,256,288,320,352,384,416,448}, +- { 0, 32, 48, 56, 64, 80, 96,112,128,160,192,224,256,320,384}, +- { 0, 32, 40, 48, 56, 64, 80, 96,112,128,160,192,224,256,320} ++ { ++ { 0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, ++ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, ++ { 0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } + }, +- { { 0, 32, 48, 56, 64, 80, 96,112,128,144,160,176,192,224,256}, +- { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160}, +- { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96,112,128,144,160} ++ { ++ { 0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256 }, ++ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 }, ++ { 0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160 } + }, + }; + +-static const int sSamplesPerFrame[2][3] = +-{ +- { 384, 1152, 1152 }, +- { 384, 1152, 576 } ++static const int sSamplesPerFrame[2][3] = { ++ { 384, 1152, 1152 }, ++ { 384, 1152, 576 } + }; + +-static const int sBitsPerSlot[3] = { +- 32, +- 8, +- 8 +-}; ++static const int sBitsPerSlot[3] = { 32, 8, 8 }; + + static int mp3len(void *data, int *samplesPerFrame, int *sampleRate) + { +- uint32_t header = AV_RB32(data); +- int layerID = 3 - ((header >> 17) & 0x03); +- int bitRateID = ((header >> 12) & 0x0f); ++ uint32_t header = AV_RB32(data); ++ int layerID = 3 - ((header >> 17) & 0x03); ++ int bitRateID = ((header >> 12) & 0x0f); + int sampleRateID = ((header >> 10) & 0x03); +- int bitsPerSlot = sBitsPerSlot[layerID]; +- int isPadded = ((header >> 9) & 0x01); +- static int const mode_tab[4]= {2,3,1,0}; +- int mode= mode_tab[(header >> 19) & 0x03]; +- int mpeg_id= mode>0; ++ int bitsPerSlot = sBitsPerSlot[layerID]; ++ int isPadded = ((header >> 9) & 0x01); ++ static int const mode_tab[4] = { 2, 3, 1, 0 }; ++ int mode = mode_tab[(header >> 19) & 0x03]; ++ int mpeg_id = mode > 0; + int temp0, temp1, bitRate; + +- if ( (( header >> 21 ) & 0x7ff) != 0x7ff || mode == 3 || layerID==3 || sampleRateID==3) { ++ if (((header >> 21) & 0x7ff) != 0x7ff || mode == 3 || layerID == 3 || ++ sampleRateID == 3) { + return -1; + } + +- if(!samplesPerFrame) samplesPerFrame= &temp0; +- if(!sampleRate ) sampleRate = &temp1; ++ if (!samplesPerFrame) ++ samplesPerFrame = &temp0; ++ if (!sampleRate) ++ sampleRate = &temp1; + +-// *isMono = ((header >> 6) & 0x03) == 0x03; ++ //*isMono = ((header >> 6) & 0x03) == 0x03; + +- *sampleRate = sSampleRates[sampleRateID]>>mode; +- bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000; ++ *sampleRate = sSampleRates[sampleRateID] >> mode; ++ bitRate = sBitRates[mpeg_id][layerID][bitRateID] * 1000; + *samplesPerFrame = sSamplesPerFrame[mpeg_id][layerID]; +-//av_log(NULL, AV_LOG_DEBUG, "sr:%d br:%d spf:%d l:%d m:%d\n", *sampleRate, bitRate, *samplesPerFrame, layerID, mode); ++ //av_log(NULL, AV_LOG_DEBUG, ++ // "sr:%d br:%d spf:%d l:%d m:%d\n", ++ // *sampleRate, bitRate, *samplesPerFrame, layerID, mode); + + return *samplesPerFrame * bitRate / (bitsPerSlot * *sampleRate) + isPadded; + } + +-static int MP3lame_encode_frame(AVCodecContext *avctx, +- unsigned char *frame, int buf_size, void *data) ++static int MP3lame_encode_frame(AVCodecContext *avctx, unsigned char *frame, ++ int buf_size, void *data) + { + Mp3AudioContext *s = avctx->priv_data; + int len; +@@ -146,17 +180,35 @@ + + /* lame 3.91 dies on '1-channel interleaved' data */ + +- if(data){ ++ if (!data){ ++ lame_result= lame_encode_flush( ++ s->gfp, ++ s->buffer + s->buffer_index, ++ BUFFER_SIZE - s->buffer_index ++ ); ++#if 2147483647 == INT_MAX ++ }else if(AV_SAMPLE_FMT_S32 == avctx->sample_fmt){ + if (s->stereo) { +- lame_result = lame_encode_buffer_interleaved( ++ int32_t *rp = data; ++ int32_t *mp = rp + 2*avctx->frame_size; ++ int *wpl = s->s32_data.left; ++ int *wpr = s->s32_data.right; ++ ++ while (rp < mp) { ++ *wpl++ = *rp++; ++ *wpr++ = *rp++; ++ } ++ ++ lame_result = lame_encode_buffer_int( + s->gfp, +- data, ++ s->s32_data.left, ++ s->s32_data.right, + avctx->frame_size, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); + } else { +- lame_result = lame_encode_buffer( ++ lame_result = lame_encode_buffer_int( + s->gfp, + data, + data, +@@ -165,40 +217,57 @@ + BUFFER_SIZE - s->buffer_index + ); + } ++#endif + }else{ +- lame_result= lame_encode_flush( ++ if (s->stereo) { ++ lame_result = lame_encode_buffer_interleaved( + s->gfp, ++ data, ++ avctx->frame_size, + s->buffer + s->buffer_index, + BUFFER_SIZE - s->buffer_index + ); ++ } else { ++ lame_result = lame_encode_buffer( ++ s->gfp, ++ data, ++ data, ++ avctx->frame_size, ++ s->buffer + s->buffer_index, ++ BUFFER_SIZE - s->buffer_index ++ ); ++ } + } + +- if(lame_result < 0){ +- if(lame_result==-1) { ++ if (lame_result < 0) { ++ if (lame_result == -1) { + /* output buffer too small */ +- av_log(avctx, AV_LOG_ERROR, "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", s->buffer_index, BUFFER_SIZE - s->buffer_index); ++ av_log(avctx, AV_LOG_ERROR, ++ "lame: output buffer too small (buffer index: %d, free bytes: %d)\n", ++ s->buffer_index, BUFFER_SIZE - s->buffer_index); + } + return -1; + } + + s->buffer_index += lame_result; + +- if(s->buffer_index<4) ++ if (s->buffer_index < 4) + return 0; + +- len= mp3len(s->buffer, NULL, NULL); +-//av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", avctx->frame_size, len, s->buffer_index); +- if(len <= s->buffer_index){ ++ len = mp3len(s->buffer, NULL, NULL); ++ //av_log(avctx, AV_LOG_DEBUG, "in:%d packet-len:%d index:%d\n", ++ // avctx->frame_size, len, s->buffer_index); ++ if (len <= s->buffer_index) { + memcpy(frame, s->buffer, len); + s->buffer_index -= len; + +- memmove(s->buffer, s->buffer+len, s->buffer_index); +- //FIXME fix the audio codec API, so we do not need the memcpy() +-/*for(i=0; ibuffer, s->buffer + len, s->buffer_index); ++ // FIXME fix the audio codec API, so we do not need the memcpy() ++ /*for(i=0; ipriv_data; + ++ av_freep(&s->s32_data.left); + av_freep(&avctx->coded_frame); + + lame_close(s->gfp); + return 0; + } + ++#define OFFSET(x) offsetof(Mp3AudioContext, x) ++#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "reservoir", "Use bit reservoir.", OFFSET(reservoir), AV_OPT_TYPE_INT, { 1 }, 0, 1, AE }, ++ { NULL }, ++}; ++ ++static const AVClass libmp3lame_class = { ++ .class_name = "libmp3lame encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + + AVCodec ff_libmp3lame_encoder = { +- "libmp3lame", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3, +- sizeof(Mp3AudioContext), +- MP3lame_encode_init, +- MP3lame_encode_frame, +- MP3lame_encode_close, +- .capabilities= CODEC_CAP_DELAY, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .supported_samplerates= sSampleRates, +- .long_name= NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), ++ .name = "libmp3lame", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3, ++ .priv_data_size = sizeof(Mp3AudioContext), ++ .init = MP3lame_encode_init, ++ .encode = MP3lame_encode_frame, ++ .close = MP3lame_encode_close, ++ .capabilities = CODEC_CAP_DELAY, ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, ++#if 2147483647 == INT_MAX ++ AV_SAMPLE_FMT_S32, ++#endif ++ AV_SAMPLE_FMT_NONE }, ++ .supported_samplerates = sSampleRates, ++ .long_name = NULL_IF_CONFIG_SMALL("libmp3lame MP3 (MPEG audio layer 3)"), ++ .priv_class = &libmp3lame_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopencore-amr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopencore-amr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopencore-amr.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopencore-amr.c 2012-05-14 14:08:53.923331710 +0200 +@@ -20,6 +20,8 @@ + */ + + #include "avcodec.h" ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" + + static void amr_decode_fix_avctx(AVCodecContext *avctx) + { +@@ -40,9 +42,6 @@ + #include + #include + +-static const char nb_bitrate_unsupported[] = +- "bitrate not supported: use one of 4.75k, 5.15k, 5.9k, 6.7k, 7.4k, 7.95k, 10.2k or 12.2k\n"; +- + /* Common code for fixed and float version*/ + typedef struct AMR_bitrates { + int rate; +@@ -50,41 +49,60 @@ + } AMR_bitrates; + + /* Match desired bitrate */ +-static int getBitrateMode(int bitrate) ++static int get_bitrate_mode(int bitrate, void *log_ctx) + { + /* make the correspondance between bitrate and mode */ +- AMR_bitrates rates[] = { { 4750, MR475}, +- { 5150, MR515}, +- { 5900, MR59}, +- { 6700, MR67}, +- { 7400, MR74}, +- { 7950, MR795}, +- {10200, MR102}, +- {12200, MR122}, }; +- int i; ++ static const AMR_bitrates rates[] = { ++ { 4750, MR475 }, { 5150, MR515 }, { 5900, MR59 }, { 6700, MR67 }, ++ { 7400, MR74 }, { 7950, MR795 }, { 10200, MR102 }, { 12200, MR122 } ++ }; ++ int i, best = -1, min_diff = 0; ++ char log_buf[200]; + +- for (i = 0; i < 8; i++) ++ for (i = 0; i < 8; i++) { + if (rates[i].rate == bitrate) + return rates[i].mode; +- /* no bitrate matching, return an error */ +- return -1; ++ if (best < 0 || abs(rates[i].rate - bitrate) < min_diff) { ++ best = i; ++ min_diff = abs(rates[i].rate - bitrate); ++ } ++ } ++ /* no bitrate matching exactly, log a warning */ ++ snprintf(log_buf, sizeof(log_buf), "bitrate not supported: use one of "); ++ for (i = 0; i < 8; i++) ++ av_strlcatf(log_buf, sizeof(log_buf), "%.2fk, ", rates[i].rate / 1000.f); ++ av_strlcatf(log_buf, sizeof(log_buf), "using %.2fk", rates[best].rate / 1000.f); ++ av_log(log_ctx, AV_LOG_WARNING, "%s\n", log_buf); ++ ++ return best; + } + + typedef struct AMRContext { +- int frameCount; +- void *decState; +- int *enstate; ++ AVClass *av_class; ++ AVFrame frame; ++ void *dec_state; ++ void *enc_state; + int enc_bitrate; ++ int enc_mode; ++ int enc_dtx; + } AMRContext; + ++static const AVOption options[] = { ++ { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRContext, enc_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, ++ { NULL } ++}; ++ ++static const AVClass class = { ++ "libopencore_amrnb", av_default_item_name, options, LIBAVUTIL_VERSION_INT ++}; ++ + static av_cold int amr_nb_decode_init(AVCodecContext *avctx) + { +- AMRContext *s = avctx->priv_data; ++ AMRContext *s = avctx->priv_data; + +- s->frameCount = 0; +- s->decState = Decoder_Interface_init(); +- if (!s->decState) { +- av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\r\n"); ++ s->dec_state = Decoder_Interface_init(); ++ if (!s->dec_state) { ++ av_log(avctx, AV_LOG_ERROR, "Decoder_Interface_init error\n"); + return -1; + } + +@@ -92,9 +110,12 @@ + + if (avctx->channels > 1) { + av_log(avctx, AV_LOG_ERROR, "amr_nb: multichannel decoding not supported\n"); +- return -1; ++ return AVERROR(ENOSYS); + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -102,52 +123,60 @@ + { + AMRContext *s = avctx->priv_data; + +- Decoder_Interface_exit(s->decState); ++ Decoder_Interface_exit(s->dec_state); ++ + return 0; + } + + static int amr_nb_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- AMRContext *s = avctx->priv_data; +- const uint8_t *amrData = buf; ++ AMRContext *s = avctx->priv_data; + static const uint8_t block_size[16] = { 12, 13, 15, 17, 19, 20, 26, 31, 5, 0, 0, 0, 0, 0, 0, 0 }; + enum Mode dec_mode; +- int packet_size; ++ int packet_size, ret; + +- /* av_log(NULL, AV_LOG_DEBUG, "amr_decode_frame buf=%p buf_size=%d frameCount=%d!!\n", +- buf, buf_size, s->frameCount); */ ++ av_dlog(avctx, "amr_decode_frame buf=%p buf_size=%d frame_count=%d!!\n", ++ buf, buf_size, avctx->frame_number); + +- dec_mode = (buf[0] >> 3) & 0x000F; ++ /* get output buffer */ ++ s->frame.nb_samples = 160; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ dec_mode = (buf[0] >> 3) & 0x000F; + packet_size = block_size[dec_mode] + 1; + + if (packet_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", + buf_size, packet_size); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- s->frameCount++; +- /* av_log(NULL, AV_LOG_DEBUG, "packet_size=%d amrData= 0x%X %X %X %X\n", +- packet_size, amrData[0], amrData[1], amrData[2], amrData[3]); */ ++ av_dlog(avctx, "packet_size=%d buf= 0x%X %X %X %X\n", ++ packet_size, buf[0], buf[1], buf[2], buf[3]); + /* call decoder */ +- Decoder_Interface_Decode(s->decState, amrData, data, 0); +- *data_size = 160 * 2; ++ Decoder_Interface_Decode(s->dec_state, buf, (short *)s->frame.data[0], 0); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + + return packet_size; + } + + AVCodec ff_libopencore_amrnb_decoder = { +- "libopencore_amrnb", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AMR_NB, +- sizeof(AMRContext), +- amr_nb_decode_init, +- NULL, +- amr_nb_decode_close, +- amr_nb_decode_frame, ++ .name = "libopencore_amrnb", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AMR_NB, ++ .priv_data_size = sizeof(AMRContext), ++ .init = amr_nb_decode_init, ++ .close = amr_nb_decode_close, ++ .decode = amr_nb_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"), + }; + +@@ -155,31 +184,27 @@ + { + AMRContext *s = avctx->priv_data; + +- s->frameCount = 0; +- + if (avctx->sample_rate != 8000) { + av_log(avctx, AV_LOG_ERROR, "Only 8000Hz sample rate supported\n"); +- return -1; ++ return AVERROR(ENOSYS); + } + + if (avctx->channels != 1) { + av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); +- return -1; ++ return AVERROR(ENOSYS); + } + + avctx->frame_size = 160; + avctx->coded_frame = avcodec_alloc_frame(); + +- s->enstate=Encoder_Interface_init(0); +- if (!s->enstate) { ++ s->enc_state = Encoder_Interface_init(s->enc_dtx); ++ if (!s->enc_state) { + av_log(avctx, AV_LOG_ERROR, "Encoder_Interface_init error\n"); + return -1; + } + +- if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) { +- av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); +- return -1; +- } ++ s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx); ++ s->enc_bitrate = avctx->bit_rate; + + return 0; + } +@@ -188,7 +213,7 @@ + { + AMRContext *s = avctx->priv_data; + +- Encoder_Interface_exit(s->enstate); ++ Encoder_Interface_exit(s->enc_state); + av_freep(&avctx->coded_frame); + return 0; + } +@@ -200,30 +225,30 @@ + AMRContext *s = avctx->priv_data; + int written; + +- if ((s->enc_bitrate = getBitrateMode(avctx->bit_rate)) < 0) { +- av_log(avctx, AV_LOG_ERROR, nb_bitrate_unsupported); +- return -1; ++ if (s->enc_bitrate != avctx->bit_rate) { ++ s->enc_mode = get_bitrate_mode(avctx->bit_rate, avctx); ++ s->enc_bitrate = avctx->bit_rate; + } + +- written = Encoder_Interface_Encode(s->enstate, s->enc_bitrate, data, ++ written = Encoder_Interface_Encode(s->enc_state, s->enc_mode, data, + frame, 0); +- /* av_log(NULL, AV_LOG_DEBUG, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n", +- written, s->enc_bitrate, frame[0] ); */ ++ av_dlog(avctx, "amr_nb_encode_frame encoded %u bytes, bitrate %u, first byte was %#02x\n", ++ written, s->enc_mode, frame[0]); + + return written; + } + + AVCodec ff_libopencore_amrnb_encoder = { +- "libopencore_amrnb", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AMR_NB, +- sizeof(AMRContext), +- amr_nb_encode_init, +- amr_nb_encode_frame, +- amr_nb_encode_close, +- NULL, ++ .name = "libopencore_amrnb", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AMR_NB, ++ .priv_data_size = sizeof(AMRContext), ++ .init = amr_nb_encode_init, ++ .encode = amr_nb_encode_frame, ++ .close = amr_nb_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Narrow-Band"), ++ .priv_class = &class, + }; + + #endif +@@ -231,74 +256,64 @@ + /* -----------AMR wideband ------------*/ + #if CONFIG_LIBOPENCORE_AMRWB + +-#ifdef _TYPEDEF_H +-//To avoid duplicate typedefs from typedef in amr-nb +-#define typedef_h +-#endif +- + #include + #include + +-static const char wb_bitrate_unsupported[] = +- "bitrate not supported: use one of 6.6k, 8.85k, 12.65k, 14.25k, 15.85k, 18.25k, 19.85k, 23.05k, or 23.85k\n"; +- +-/* Common code for fixed and float version*/ +-typedef struct AMRWB_bitrates { +- int rate; +- int mode; +-} AMRWB_bitrates; +- + typedef struct AMRWBContext { +- int frameCount; ++ AVFrame frame; + void *state; +- int mode; +- Word16 allow_dtx; + } AMRWBContext; + + static av_cold int amr_wb_decode_init(AVCodecContext *avctx) + { + AMRWBContext *s = avctx->priv_data; + +- s->frameCount = 0; +- s->state = D_IF_init(); ++ s->state = D_IF_init(); + + amr_decode_fix_avctx(avctx); + + if (avctx->channels > 1) { + av_log(avctx, AV_LOG_ERROR, "amr_wb: multichannel decoding not supported\n"); +- return -1; ++ return AVERROR(ENOSYS); + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + + static int amr_wb_decode_frame(AVCodecContext *avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- AMRWBContext *s = avctx->priv_data; +- const uint8_t *amrData = buf; +- int mode; ++ AMRWBContext *s = avctx->priv_data; ++ int mode, ret; + int packet_size; + static const uint8_t block_size[16] = {18, 24, 33, 37, 41, 47, 51, 59, 61, 6, 6, 0, 0, 0, 1, 1}; + +- if (!buf_size) +- /* nothing to do */ +- return 0; ++ /* get output buffer */ ++ s->frame.nb_samples = 320; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } + +- mode = (amrData[0] >> 3) & 0x000F; ++ mode = (buf[0] >> 3) & 0x000F; + packet_size = block_size[mode]; + + if (packet_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "amr frame too short (%u, should be %u)\n", + buf_size, packet_size + 1); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- s->frameCount++; +- D_IF_decode(s->state, amrData, data, _good_frame); +- *data_size = 320 * 2; ++ D_IF_decode(s->state, buf, (short *)s->frame.data[0], _good_frame); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return packet_size; + } + +@@ -311,14 +326,14 @@ + } + + AVCodec ff_libopencore_amrwb_decoder = { +- "libopencore_amrwb", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_AMR_WB, +- sizeof(AMRWBContext), +- amr_wb_decode_init, +- NULL, +- amr_wb_decode_close, +- amr_wb_decode_frame, ++ .name = "libopencore_amrwb", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AMR_WB, ++ .priv_data_size = sizeof(AMRWBContext), ++ .init = amr_wb_decode_init, ++ .close = amr_wb_decode_close, ++ .decode = amr_wb_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("OpenCORE Adaptive Multi-Rate (AMR) Wide-Band"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpeg.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpeg.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,199 +0,0 @@ +-/* +- * JPEG 2000 decoding support via OpenJPEG +- * Copyright (c) 2009 Jaikrishnan Menon +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +-* @file +-* JPEG 2000 decoder using libopenjpeg +-*/ +- +-#include "libavcore/imgutils.h" +-#include "avcodec.h" +-#include "libavutil/intreadwrite.h" +-#define OPJ_STATIC +-#include +- +-#define JP2_SIG_TYPE 0x6A502020 +-#define JP2_SIG_VALUE 0x0D0A870A +- +-typedef struct { +- opj_dparameters_t dec_params; +- AVFrame image; +-} LibOpenJPEGContext; +- +-static int check_image_attributes(opj_image_t *image) +-{ +- return image->comps[0].dx == image->comps[1].dx && +- image->comps[1].dx == image->comps[2].dx && +- image->comps[0].dy == image->comps[1].dy && +- image->comps[1].dy == image->comps[2].dy && +- image->comps[0].prec == image->comps[1].prec && +- image->comps[1].prec == image->comps[2].prec; +-} +- +-static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx) +-{ +- LibOpenJPEGContext *ctx = avctx->priv_data; +- +- opj_set_default_decoder_parameters(&ctx->dec_params); +- avctx->coded_frame = &ctx->image; +- return 0; +-} +- +-static int libopenjpeg_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) +-{ +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- LibOpenJPEGContext *ctx = avctx->priv_data; +- AVFrame *picture = &ctx->image, *output = data; +- opj_dinfo_t *dec; +- opj_cio_t *stream; +- opj_image_t *image; +- int width, height, has_alpha = 0, ret = -1; +- int x, y, index; +- uint8_t *img_ptr; +- int adjust[4]; +- +- *data_size = 0; +- +- // Check if input is a raw jpeg2k codestream or in jp2 wrapping +- if((AV_RB32(buf) == 12) && +- (AV_RB32(buf + 4) == JP2_SIG_TYPE) && +- (AV_RB32(buf + 8) == JP2_SIG_VALUE)) { +- dec = opj_create_decompress(CODEC_JP2); +- } else { +- // If the AVPacket contains a jp2c box, then skip to +- // the starting byte of the codestream. +- if (AV_RB32(buf + 4) == AV_RB32("jp2c")) +- buf += 8; +- dec = opj_create_decompress(CODEC_J2K); +- } +- +- if(!dec) { +- av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n"); +- return -1; +- } +- opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL); +- +- ctx->dec_params.cp_reduce = avctx->lowres; +- // Tie decoder with decoding parameters +- opj_setup_decoder(dec, &ctx->dec_params); +- stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size); +- if(!stream) { +- av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n"); +- opj_destroy_decompress(dec); +- return -1; +- } +- +- // Decode the codestream +- image = opj_decode_with_info(dec, stream, NULL); +- opj_cio_close(stream); +- if(!image) { +- av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); +- opj_destroy_decompress(dec); +- return -1; +- } +- width = image->comps[0].w << avctx->lowres; +- height = image->comps[0].h << avctx->lowres; +- if(av_image_check_size(width, height, 0, avctx) < 0) { +- av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height); +- goto done; +- } +- avcodec_set_dimensions(avctx, width, height); +- +- switch(image->numcomps) +- { +- case 1: avctx->pix_fmt = PIX_FMT_GRAY8; +- break; +- case 3: if(check_image_attributes(image)) { +- avctx->pix_fmt = PIX_FMT_RGB24; +- } else { +- avctx->pix_fmt = PIX_FMT_GRAY8; +- av_log(avctx, AV_LOG_ERROR, "Only first component will be used.\n"); +- } +- break; +- case 4: has_alpha = 1; +- avctx->pix_fmt = PIX_FMT_RGBA; +- break; +- default: av_log(avctx, AV_LOG_ERROR, "%d components unsupported.\n", image->numcomps); +- goto done; +- } +- +- if(picture->data[0]) +- avctx->release_buffer(avctx, picture); +- +- if(avctx->get_buffer(avctx, picture) < 0) { +- av_log(avctx, AV_LOG_ERROR, "Couldn't allocate image buffer.\n"); +- return -1; +- } +- +- for(x = 0; x < image->numcomps; x++) { +- adjust[x] = FFMAX(image->comps[x].prec - 8, 0); +- } +- +- for(y = 0; y < avctx->height; y++) { +- index = y*avctx->width; +- img_ptr = picture->data[0] + y*picture->linesize[0]; +- for(x = 0; x < avctx->width; x++, index++) { +- *img_ptr++ = image->comps[0].data[index] >> adjust[0]; +- if(image->numcomps > 2 && check_image_attributes(image)) { +- *img_ptr++ = image->comps[1].data[index] >> adjust[1]; +- *img_ptr++ = image->comps[2].data[index] >> adjust[2]; +- if(has_alpha) +- *img_ptr++ = image->comps[3].data[index] >> adjust[3]; +- } +- } +- } +- +- *output = ctx->image; +- *data_size = sizeof(AVPicture); +- ret = buf_size; +- +-done: +- opj_image_destroy(image); +- opj_destroy_decompress(dec); +- return ret; +-} +- +-static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx) +-{ +- LibOpenJPEGContext *ctx = avctx->priv_data; +- +- if(ctx->image.data[0]) +- avctx->release_buffer(avctx, &ctx->image); +- return 0 ; +-} +- +- +-AVCodec ff_libopenjpeg_decoder = { +- "libopenjpeg", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_JPEG2000, +- sizeof(LibOpenJPEGContext), +- libopenjpeg_decode_init, +- NULL, +- libopenjpeg_decode_close, +- libopenjpeg_decode_frame, +- CODEC_CAP_DR1, +- .max_lowres = 5, +- .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"), +-} ; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpegdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpegdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpegdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpegdec.c 2012-05-14 14:08:53.925331750 +0200 +@@ -0,0 +1,356 @@ ++/* ++ * JPEG 2000 decoding support via OpenJPEG ++ * Copyright (c) 2009 Jaikrishnan Menon ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++* @file ++* JPEG 2000 decoder using libopenjpeg ++*/ ++ ++#include "libavutil/imgutils.h" ++#include "libavutil/pixfmt.h" ++#include "avcodec.h" ++#include "libavutil/intreadwrite.h" ++#include "thread.h" ++#define OPJ_STATIC ++#include ++ ++#define JP2_SIG_TYPE 0x6A502020 ++#define JP2_SIG_VALUE 0x0D0A870A ++ ++typedef struct { ++ opj_dparameters_t dec_params; ++ AVFrame image; ++} LibOpenJPEGContext; ++ ++static enum PixelFormat check_image_attributes(AVCodecContext *avctx, opj_image_t *image) ++{ ++ opj_image_comp_t c0 = image->comps[0]; ++ opj_image_comp_t c1 = image->comps[1]; ++ opj_image_comp_t c2 = image->comps[2]; ++ int compRatio = 0; ++ compRatio |= c0.dx << 15 | c0.dy << 12; ++ compRatio |= c1.dx << 9 | c1.dy << 6; ++ compRatio |= c2.dx << 3 | c2.dy; ++ ++ switch (compRatio) { ++ case 0111111: goto libopenjpeg_yuv444_rgb; ++ case 0111212: return PIX_FMT_YUV440P; ++ case 0112121: goto libopenjpeg_yuv422; ++ case 0112222: goto libopenjpeg_yuv420; ++ default: goto libopenjpeg_rgb; ++ } ++ ++libopenjpeg_yuv420: ++ switch (c0.prec) { ++ case 8: return PIX_FMT_YUV420P; ++ case 9: return PIX_FMT_YUV420P9; ++ case 10: return PIX_FMT_YUV420P10; ++ case 16: return PIX_FMT_YUV420P16; ++ } ++ ++libopenjpeg_yuv422: ++ switch (c0.prec) { ++ case 8: return PIX_FMT_YUV422P; ++ case 9: return PIX_FMT_YUV422P9; ++ case 10: return PIX_FMT_YUV422P10; ++ case 16: return PIX_FMT_YUV422P16; ++ } ++ ++libopenjpeg_yuv444_rgb: ++ switch (c0.prec) { ++ case 8: return PIX_FMT_RGB24; ++ case 9: return PIX_FMT_YUV444P9; ++ case 10: return PIX_FMT_YUV444P10; ++ case 16: return PIX_FMT_YUV444P16; ++ } ++ ++libopenjpeg_rgb: ++ switch (c0.prec) { ++ case 8: return PIX_FMT_RGB24; ++ default: return PIX_FMT_RGB48; ++ } ++ ++ return PIX_FMT_RGB24; ++} ++ ++static int is_yuva420(opj_image_t *image) ++{ ++ return image->numcomps == 4 && ++ image->comps[0].dx == 1 && image->comps[0].dy == 1 && ++ image->comps[1].dx == 2 && image->comps[1].dy == 2 && ++ image->comps[2].dx == 2 && image->comps[2].dy == 2 && ++ image->comps[3].dx == 1 && image->comps[3].dy == 1; ++} ++ ++static inline int libopenjpeg_ispacked(enum PixelFormat pix_fmt) { ++ int i, component_plane; ++ component_plane = av_pix_fmt_descriptors[pix_fmt].comp[0].plane; ++ for(i = 1; i < av_pix_fmt_descriptors[pix_fmt].nb_components; i++) { ++ if (component_plane != av_pix_fmt_descriptors[pix_fmt].comp[i].plane) ++ return 0; ++ } ++ return 1; ++} ++ ++static inline void libopenjpeg_copy_to_packed8(AVFrame *picture, opj_image_t *image) { ++ uint8_t *img_ptr; ++ int index, x, y, c; ++ for(y = 0; y < picture->height; y++) { ++ index = y*picture->width; ++ img_ptr = picture->data[0] + y*picture->linesize[0]; ++ for(x = 0; x < picture->width; x++, index++) { ++ for(c = 0; c < image->numcomps; c++) { ++ *img_ptr++ = image->comps[c].data[index]; ++ } ++ } ++ } ++} ++ ++static inline void libopenjpeg_copy_to_packed16(AVFrame *picture, opj_image_t *image) { ++ uint16_t *img_ptr; ++ int index, x, y, c; ++ int adjust[4]; ++ for (x = 0; x < image->numcomps; x++) { ++ adjust[x] = FFMAX(FFMIN(16 - image->comps[x].prec, 8), 0); ++ } ++ for (y = 0; y < picture->height; y++) { ++ index = y*picture->width; ++ img_ptr = (uint16_t*) (picture->data[0] + y*picture->linesize[0]); ++ for (x = 0; x < picture->width; x++, index++) { ++ for (c = 0; c < image->numcomps; c++) { ++ *img_ptr++ = image->comps[c].data[index] << adjust[c]; ++ } ++ } ++ } ++} ++ ++static inline void libopenjpeg_copyto8(AVFrame *picture, opj_image_t *image) { ++ int *comp_data; ++ uint8_t *img_ptr; ++ int index, x, y; ++ ++ for(index = 0; index < image->numcomps; index++) { ++ comp_data = image->comps[index].data; ++ for(y = 0; y < image->comps[index].h; y++) { ++ img_ptr = picture->data[index] + y * picture->linesize[index]; ++ for(x = 0; x < image->comps[index].w; x++) { ++ *img_ptr = (uint8_t) *comp_data; ++ img_ptr++; ++ comp_data++; ++ } ++ } ++ } ++} ++ ++static inline void libopenjpeg_copyto16(AVFrame *picture, opj_image_t *image) { ++ int *comp_data; ++ uint16_t *img_ptr; ++ int index, x, y; ++ for(index = 0; index < image->numcomps; index++) { ++ comp_data = image->comps[index].data; ++ for(y = 0; y < image->comps[index].h; y++) { ++ img_ptr = (uint16_t*) (picture->data[index] + y * picture->linesize[index]); ++ for(x = 0; x < image->comps[index].w; x++) { ++ *img_ptr = *comp_data; ++ img_ptr++; ++ comp_data++; ++ } ++ } ++ } ++} ++ ++static av_cold int libopenjpeg_decode_init(AVCodecContext *avctx) ++{ ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ ++ opj_set_default_decoder_parameters(&ctx->dec_params); ++ avcodec_get_frame_defaults(&ctx->image); ++ avctx->coded_frame = &ctx->image; ++ return 0; ++} ++ ++static av_cold int libopenjpeg_decode_init_thread_copy(AVCodecContext *avctx) ++{ ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ ++ avctx->coded_frame = &ctx->image; ++ return 0; ++} ++ ++static int libopenjpeg_decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ AVFrame *picture = &ctx->image, *output = data; ++ opj_dinfo_t *dec; ++ opj_cio_t *stream; ++ opj_image_t *image; ++ int width, height, ret = -1; ++ int pixel_size = 0; ++ int ispacked = 0; ++ ++ *data_size = 0; ++ ++ // Check if input is a raw jpeg2k codestream or in jp2 wrapping ++ if((AV_RB32(buf) == 12) && ++ (AV_RB32(buf + 4) == JP2_SIG_TYPE) && ++ (AV_RB32(buf + 8) == JP2_SIG_VALUE)) { ++ dec = opj_create_decompress(CODEC_JP2); ++ } else { ++ // If the AVPacket contains a jp2c box, then skip to ++ // the starting byte of the codestream. ++ if (AV_RB32(buf + 4) == AV_RB32("jp2c")) ++ buf += 8; ++ dec = opj_create_decompress(CODEC_J2K); ++ } ++ ++ if(!dec) { ++ av_log(avctx, AV_LOG_ERROR, "Error initializing decoder.\n"); ++ return -1; ++ } ++ opj_set_event_mgr((opj_common_ptr)dec, NULL, NULL); ++ ++ ctx->dec_params.cp_limit_decoding = LIMIT_TO_MAIN_HEADER; ++ // Tie decoder with decoding parameters ++ opj_setup_decoder(dec, &ctx->dec_params); ++ stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size); ++ if(!stream) { ++ av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n"); ++ opj_destroy_decompress(dec); ++ return -1; ++ } ++ ++ // Decode the header only ++ image = opj_decode_with_info(dec, stream, NULL); ++ opj_cio_close(stream); ++ if(!image) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding codestream.\n"); ++ opj_destroy_decompress(dec); ++ return -1; ++ } ++ width = image->x1 - image->x0; ++ height = image->y1 - image->y0; ++ if(av_image_check_size(width, height, 0, avctx) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "%dx%d dimension invalid.\n", width, height); ++ goto done; ++ } ++ avcodec_set_dimensions(avctx, width, height); ++ ++ switch (image->numcomps) { ++ case 1: avctx->pix_fmt = PIX_FMT_GRAY8; ++ break; ++ case 3: avctx->pix_fmt = check_image_attributes(avctx, image); ++ break; ++ case 4: avctx->pix_fmt = is_yuva420(image) ? PIX_FMT_YUVA420P : PIX_FMT_RGBA; ++ break; ++ default: av_log(avctx, AV_LOG_ERROR, "%d components unsupported.\n", image->numcomps); ++ goto done; ++ } ++ ++ if(picture->data[0]) ++ ff_thread_release_buffer(avctx, picture); ++ ++ if(ff_thread_get_buffer(avctx, picture) < 0){ ++ av_log(avctx, AV_LOG_ERROR, "ff_thread_get_buffer() failed\n"); ++ return -1; ++ } ++ ++ ctx->dec_params.cp_limit_decoding = NO_LIMITATION; ++ ctx->dec_params.cp_reduce = avctx->lowres; ++ // Tie decoder with decoding parameters ++ opj_setup_decoder(dec, &ctx->dec_params); ++ stream = opj_cio_open((opj_common_ptr)dec, buf, buf_size); ++ if(!stream) { ++ av_log(avctx, AV_LOG_ERROR, "Codestream could not be opened for reading.\n"); ++ opj_destroy_decompress(dec); ++ return -1; ++ } ++ ++ // Decode the codestream ++ image = opj_decode_with_info(dec, stream, NULL); ++ opj_cio_close(stream); ++ ++ pixel_size = av_pix_fmt_descriptors[avctx->pix_fmt].comp[0].step_minus1 + 1; ++ ispacked = libopenjpeg_ispacked(avctx->pix_fmt); ++ ++ switch (pixel_size) { ++ case 1: ++ if (ispacked) { ++ libopenjpeg_copy_to_packed8(picture, image); ++ } else { ++ libopenjpeg_copyto8(picture, image); ++ } ++ break; ++ case 2: ++ libopenjpeg_copyto16(picture, image); ++ break; ++ case 3: ++ case 4: ++ if (ispacked) { ++ libopenjpeg_copy_to_packed8(picture, image); ++ } ++ break; ++ case 6: ++ if (ispacked) { ++ libopenjpeg_copy_to_packed16(picture, image); ++ } ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "unsupported pixel size %d\n", pixel_size); ++ goto done; ++ } ++ ++ *output = ctx->image; ++ *data_size = sizeof(AVPicture); ++ ret = buf_size; ++ ++done: ++ opj_image_destroy(image); ++ opj_destroy_decompress(dec); ++ return ret; ++} ++ ++static av_cold int libopenjpeg_decode_close(AVCodecContext *avctx) ++{ ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ ++ if(ctx->image.data[0]) ++ ff_thread_release_buffer(avctx, &ctx->image); ++ return 0 ; ++} ++ ++ ++AVCodec ff_libopenjpeg_decoder = { ++ .name = "libopenjpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEG2000, ++ .priv_data_size = sizeof(LibOpenJPEGContext), ++ .init = libopenjpeg_decode_init, ++ .close = libopenjpeg_decode_close, ++ .decode = libopenjpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, ++ .max_lowres = 5, ++ .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 decoder"), ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(libopenjpeg_decode_init_thread_copy) ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpegenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpegenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libopenjpegenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libopenjpegenc.c 2012-05-14 14:08:53.926331770 +0200 +@@ -0,0 +1,445 @@ ++/* ++ * JPEG 2000 encoding support via OpenJPEG ++ * Copyright (c) 2011 Michael Bradshaw ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++* @file ++* JPEG 2000 encoder using libopenjpeg ++*/ ++ ++#include "libavutil/imgutils.h" ++#include "libavutil/avassert.h" ++#include "avcodec.h" ++#include "libavutil/intreadwrite.h" ++#define OPJ_STATIC ++#include ++ ++typedef struct { ++ opj_image_t *image; ++ opj_cparameters_t enc_params; ++ opj_cinfo_t *compress; ++ opj_event_mgr_t event_mgr; ++} LibOpenJPEGContext; ++ ++static void error_callback(const char *msg, void *data) ++{ ++ av_log((AVCodecContext*)data, AV_LOG_ERROR, "libopenjpeg: %s\n", msg); ++} ++ ++static void warning_callback(const char *msg, void *data) ++{ ++ av_log((AVCodecContext*)data, AV_LOG_WARNING, "libopenjpeg: %s\n", msg); ++} ++ ++static opj_image_t *mj2_create_image(AVCodecContext *avctx, opj_cparameters_t *parameters) ++{ ++ opj_image_cmptparm_t *cmptparm; ++ opj_image_t *img; ++ int i; ++ int bpp = 8; ++ int sub_dx[4]; ++ int sub_dy[4]; ++ int numcomps = 0; ++ OPJ_COLOR_SPACE color_space = CLRSPC_UNKNOWN; ++ ++ sub_dx[0] = sub_dx[3] = 1; ++ sub_dy[0] = sub_dy[3] = 1; ++ sub_dx[1] = sub_dx[2] = 1<pix_fmt].log2_chroma_w; ++ sub_dy[1] = sub_dy[2] = 1<pix_fmt].log2_chroma_h; ++ ++ switch (avctx->pix_fmt) { ++ case PIX_FMT_GRAY8: ++ color_space = CLRSPC_GRAY; ++ numcomps = 1; ++ break; ++ case PIX_FMT_GRAY8A: ++ color_space = CLRSPC_GRAY; ++ numcomps = 2; ++ break; ++ case PIX_FMT_GRAY16: ++ color_space = CLRSPC_GRAY; ++ numcomps = 1; ++ bpp = 16; ++ break; ++ case PIX_FMT_RGB24: ++ color_space = CLRSPC_SRGB; ++ numcomps = 3; ++ break; ++ case PIX_FMT_RGBA: ++ color_space = CLRSPC_SRGB; ++ numcomps = 4; ++ break; ++ case PIX_FMT_RGB48: ++ color_space = CLRSPC_SRGB; ++ numcomps = 3; ++ bpp = 16; ++ break; ++ case PIX_FMT_RGBA64: ++ color_space = CLRSPC_SRGB; ++ numcomps = 4; ++ bpp = 16; ++ break; ++ case PIX_FMT_YUV420P: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ break; ++ case PIX_FMT_YUV422P: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ break; ++ case PIX_FMT_YUV440P: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ break; ++ case PIX_FMT_YUV444P: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ break; ++ case PIX_FMT_YUVA420P: ++ color_space = CLRSPC_SYCC; ++ numcomps = 4; ++ break; ++ case PIX_FMT_YUV420P9: ++ case PIX_FMT_YUV422P9: ++ case PIX_FMT_YUV444P9: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ bpp = 9; ++ break; ++ case PIX_FMT_YUV420P10: ++ case PIX_FMT_YUV422P10: ++ case PIX_FMT_YUV444P10: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ bpp = 10; ++ break; ++ case PIX_FMT_YUV420P16: ++ case PIX_FMT_YUV422P16: ++ case PIX_FMT_YUV444P16: ++ color_space = CLRSPC_SYCC; ++ numcomps = 3; ++ bpp = 16; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "The requested pixel format '%s' is not supported\n", av_get_pix_fmt_name(avctx->pix_fmt)); ++ return NULL; ++ } ++ ++ cmptparm = av_mallocz(numcomps * sizeof(opj_image_cmptparm_t)); ++ if (!cmptparm) { ++ av_log(avctx, AV_LOG_ERROR, "Not enough memory"); ++ return NULL; ++ } ++ for (i = 0; i < numcomps; i++) { ++ cmptparm[i].prec = bpp; ++ cmptparm[i].bpp = bpp; ++ cmptparm[i].sgnd = 0; ++ cmptparm[i].dx = sub_dx[i]; ++ cmptparm[i].dy = sub_dy[i]; ++ cmptparm[i].w = avctx->width / sub_dx[i]; ++ cmptparm[i].h = avctx->height / sub_dy[i]; ++ } ++ ++ img = opj_image_create(numcomps, cmptparm, color_space); ++ av_freep(&cmptparm); ++ return img; ++} ++ ++static av_cold int libopenjpeg_encode_init(AVCodecContext *avctx) ++{ ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ ++ opj_set_default_encoder_parameters(&ctx->enc_params); ++ ctx->enc_params.tcp_numlayers = 1; ++ ctx->enc_params.tcp_rates[0] = FFMAX(avctx->compression_level, 0) * 2; ++ ctx->enc_params.cp_disto_alloc = 1; ++ ++ ctx->compress = opj_create_compress(CODEC_J2K); ++ if (!ctx->compress) { ++ av_log(avctx, AV_LOG_ERROR, "Error creating the compressor\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->coded_frame) { ++ av_freep(&ctx->compress); ++ av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ ctx->image = mj2_create_image(avctx, &ctx->enc_params); ++ if (!ctx->image) { ++ av_freep(&ctx->compress); ++ av_freep(&avctx->coded_frame); ++ av_log(avctx, AV_LOG_ERROR, "Error creating the mj2 image\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ memset(&ctx->event_mgr, 0, sizeof(opj_event_mgr_t)); ++ ctx->event_mgr.error_handler = error_callback; ++ ctx->event_mgr.warning_handler = warning_callback; ++ ctx->event_mgr.info_handler = NULL; ++ opj_set_event_mgr((opj_common_ptr)ctx->compress, &ctx->event_mgr, avctx); ++ ++ return 0; ++} ++ ++static int libopenjpeg_copy_packed8(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image) ++{ ++ int compno; ++ int x; ++ int y; ++ int image_index; ++ int frame_index; ++ const int numcomps = image->numcomps; ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ if (image->comps[compno].w > frame->linesize[0] / numcomps) { ++ av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); ++ return 0; ++ } ++ } ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ for (y = 0; y < avctx->height; ++y) { ++ image_index = y * avctx->width; ++ frame_index = y * frame->linesize[0] + compno; ++ for (x = 0; x < avctx->width; ++x) { ++ image->comps[compno].data[image_index++] = frame->data[0][frame_index]; ++ frame_index += numcomps; ++ } ++ } ++ } ++ ++ return 1; ++} ++ ++static int libopenjpeg_copy_packed16(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image) ++{ ++ int compno; ++ int x; ++ int y; ++ int image_index; ++ int frame_index; ++ const int numcomps = image->numcomps; ++ uint16_t *frame_ptr = (uint16_t*)frame->data[0]; ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ if (image->comps[compno].w > frame->linesize[0] / numcomps) { ++ av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); ++ return 0; ++ } ++ } ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ for (y = 0; y < avctx->height; ++y) { ++ image_index = y * avctx->width; ++ frame_index = y * (frame->linesize[0] / 2) + compno; ++ for (x = 0; x < avctx->width; ++x) { ++ image->comps[compno].data[image_index++] = frame_ptr[frame_index]; ++ frame_index += numcomps; ++ } ++ } ++ } ++ ++ return 1; ++} ++ ++static int libopenjpeg_copy_unpacked8(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image) ++{ ++ int compno; ++ int x; ++ int y; ++ int width; ++ int height; ++ int image_index; ++ int frame_index; ++ const int numcomps = image->numcomps; ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ if (image->comps[compno].w > frame->linesize[compno]) { ++ av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); ++ return 0; ++ } ++ } ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ width = avctx->width / image->comps[compno].dx; ++ height = avctx->height / image->comps[compno].dy; ++ for (y = 0; y < height; ++y) { ++ image_index = y * width; ++ frame_index = y * frame->linesize[compno]; ++ for (x = 0; x < width; ++x) { ++ image->comps[compno].data[image_index++] = frame->data[compno][frame_index++]; ++ } ++ } ++ } ++ ++ return 1; ++} ++ ++static int libopenjpeg_copy_unpacked16(AVCodecContext *avctx, AVFrame *frame, opj_image_t *image) ++{ ++ int compno; ++ int x; ++ int y; ++ int width; ++ int height; ++ int image_index; ++ int frame_index; ++ const int numcomps = image->numcomps; ++ uint16_t *frame_ptr; ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ if (image->comps[compno].w > frame->linesize[compno]) { ++ av_log(avctx, AV_LOG_ERROR, "Error: frame's linesize is too small for the image\n"); ++ return 0; ++ } ++ } ++ ++ for (compno = 0; compno < numcomps; ++compno) { ++ width = avctx->width / image->comps[compno].dx; ++ height = avctx->height / image->comps[compno].dy; ++ frame_ptr = (uint16_t*)frame->data[compno]; ++ for (y = 0; y < height; ++y) { ++ image_index = y * width; ++ frame_index = y * (frame->linesize[compno] / 2); ++ for (x = 0; x < width; ++x) { ++ image->comps[compno].data[image_index++] = frame_ptr[frame_index++]; ++ } ++ } ++ } ++ ++ return 1; ++} ++ ++static int libopenjpeg_encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) ++{ ++ AVFrame *frame = data; ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ opj_cinfo_t *compress = ctx->compress; ++ opj_image_t *image = ctx->image; ++ opj_cio_t *stream; ++ int cpyresult = 0; ++ int len = 0; ++ ++ // x0, y0 is the top left corner of the image ++ // x1, y1 is the width, height of the reference grid ++ image->x0 = 0; ++ image->y0 = 0; ++ image->x1 = (avctx->width - 1) * ctx->enc_params.subsampling_dx + 1; ++ image->y1 = (avctx->height - 1) * ctx->enc_params.subsampling_dy + 1; ++ ++ switch (avctx->pix_fmt) { ++ case PIX_FMT_RGB24: ++ case PIX_FMT_RGBA: ++ case PIX_FMT_GRAY8A: ++ cpyresult = libopenjpeg_copy_packed8(avctx, frame, image); ++ break; ++ case PIX_FMT_RGB48: ++ case PIX_FMT_RGBA64: ++ cpyresult = libopenjpeg_copy_packed16(avctx, frame, image); ++ break; ++ case PIX_FMT_GRAY8: ++ case PIX_FMT_YUV420P: ++ case PIX_FMT_YUV422P: ++ case PIX_FMT_YUV440P: ++ case PIX_FMT_YUV444P: ++ case PIX_FMT_YUVA420P: ++ cpyresult = libopenjpeg_copy_unpacked8(avctx, frame, image); ++ break; ++ case PIX_FMT_GRAY16: ++ case PIX_FMT_YUV420P9: ++ case PIX_FMT_YUV420P10: ++ case PIX_FMT_YUV420P16: ++ case PIX_FMT_YUV422P9: ++ case PIX_FMT_YUV422P10: ++ case PIX_FMT_YUV422P16: ++ case PIX_FMT_YUV444P9: ++ case PIX_FMT_YUV444P10: ++ case PIX_FMT_YUV444P16: ++ cpyresult = libopenjpeg_copy_unpacked16(avctx, frame, image); ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "The frame's pixel format '%s' is not supported\n", av_get_pix_fmt_name(avctx->pix_fmt)); ++ return AVERROR(EINVAL); ++ break; ++ } ++ ++ if (!cpyresult) { ++ av_log(avctx, AV_LOG_ERROR, "Could not copy the frame data to the internal image buffer\n"); ++ return -1; ++ } ++ ++ opj_setup_encoder(compress, &ctx->enc_params, image); ++ stream = opj_cio_open((opj_common_ptr)compress, NULL, 0); ++ if (!stream) { ++ av_log(avctx, AV_LOG_ERROR, "Error creating the cio stream\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ if (!opj_encode(compress, stream, image, NULL)) { ++ opj_cio_close(stream); ++ av_log(avctx, AV_LOG_ERROR, "Error during the opj encode\n"); ++ return -1; ++ } ++ ++ len = cio_tell(stream); ++ if (len > buf_size) { ++ opj_cio_close(stream); ++ av_log(avctx, AV_LOG_ERROR, "Error with buf_size, not large enough to hold the frame\n"); ++ return -1; ++ } ++ ++ memcpy(buf, stream->buffer, len); ++ opj_cio_close(stream); ++ return len; ++} ++ ++static av_cold int libopenjpeg_encode_close(AVCodecContext *avctx) ++{ ++ LibOpenJPEGContext *ctx = avctx->priv_data; ++ ++ opj_destroy_compress(ctx->compress); ++ opj_image_destroy(ctx->image); ++ av_freep(&avctx->coded_frame); ++ return 0 ; ++} ++ ++ ++AVCodec ff_libopenjpeg_encoder = { ++ .name = "libopenjpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_JPEG2000, ++ .priv_data_size = sizeof(LibOpenJPEGContext), ++ .init = libopenjpeg_encode_init, ++ .encode = libopenjpeg_encode_frame, ++ .close = libopenjpeg_encode_close, ++ .capabilities = 0, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24,PIX_FMT_RGBA,PIX_FMT_RGB48,PIX_FMT_RGBA64, ++ PIX_FMT_GRAY8,PIX_FMT_GRAY8A,PIX_FMT_GRAY16, ++ PIX_FMT_YUV420P,PIX_FMT_YUV422P,PIX_FMT_YUVA420P, ++ PIX_FMT_YUV440P,PIX_FMT_YUV444P, ++ PIX_FMT_YUV420P9,PIX_FMT_YUV422P9,PIX_FMT_YUV444P9, ++ PIX_FMT_YUV420P10,PIX_FMT_YUV422P10,PIX_FMT_YUV444P10, ++ PIX_FMT_YUV420P16,PIX_FMT_YUV422P16,PIX_FMT_YUV444P16, ++ PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("OpenJPEG based JPEG 2000 encoder"), ++} ; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedinger.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedinger.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedinger.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedinger.c 2012-05-14 14:08:53.927331790 +0200 +@@ -20,7 +20,7 @@ + + /** + * @file +-* function definitions common to libschroedingerdec.c and libschroedingerenc.c ++* function definitions common to libschroedinger decoder and encoder + */ + + #include "libdirac_libschro.h" +@@ -64,14 +64,14 @@ + int ff_get_schro_frame_format (SchroChromaFormat schro_pix_fmt, + SchroFrameFormat *schro_frame_fmt) + { +- unsigned int num_formats = sizeof(ffmpeg_schro_pixel_format_map) / +- sizeof(ffmpeg_schro_pixel_format_map[0]); ++ unsigned int num_formats = sizeof(schro_pixel_format_map) / ++ sizeof(schro_pixel_format_map[0]); + + int idx; + + for (idx = 0; idx < num_formats; ++idx) { +- if (ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) { +- *schro_frame_fmt = ffmpeg_schro_pixel_format_map[idx].schro_frame_fmt; ++ if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) { ++ *schro_frame_fmt = schro_pixel_format_map[idx].schro_frame_fmt; + return 0; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedingerdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedingerdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedingerdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedingerdec.c 2012-05-14 14:08:53.929331830 +0200 +@@ -27,7 +27,7 @@ + * (http://dirac.sourceforge.net/specification.html). + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "libdirac_libschro.h" + #include "libschroedinger.h" +@@ -41,7 +41,7 @@ + #include + + /** libschroedinger decoder private data */ +-typedef struct FfmpegSchroDecoderParams { ++typedef struct SchroDecoderParams { + /** Schroedinger video format */ + SchroVideoFormat *format; + +@@ -52,7 +52,7 @@ + SchroDecoder* decoder; + + /** queue storing decoded frames */ +- FfmpegDiracSchroQueue dec_frame_queue; ++ DiracSchroQueue dec_frame_queue; + + /** end of sequence signalled */ + int eos_signalled; +@@ -62,25 +62,25 @@ + + /** decoded picture */ + AVPicture dec_pic; +-} FfmpegSchroDecoderParams; ++} SchroDecoderParams; + +-typedef struct FfmpegSchroParseUnitContext { ++typedef struct SchroParseUnitContext { + const uint8_t *buf; + int buf_size; +-} FfmpegSchroParseUnitContext; ++} SchroParseUnitContext; + + + static void libschroedinger_decode_buffer_free(SchroBuffer *schro_buf, + void *priv); + +-static void FfmpegSchroParseContextInit(FfmpegSchroParseUnitContext *parse_ctx, +- const uint8_t *buf, int buf_size) ++static void SchroParseContextInit(SchroParseUnitContext *parse_ctx, ++ const uint8_t *buf, int buf_size) + { + parse_ctx->buf = buf; + parse_ctx->buf_size = buf_size; + } + +-static SchroBuffer* FfmpegFindNextSchroParseUnit(FfmpegSchroParseUnitContext *parse_ctx) ++static SchroBuffer *FindNextSchroParseUnit(SchroParseUnitContext *parse_ctx) + { + SchroBuffer *enc_buf = NULL; + int next_pu_offset = 0; +@@ -120,22 +120,22 @@ + /** + * Returns FFmpeg chroma format. + */ +-static enum PixelFormat GetFfmpegChromaFormat(SchroChromaFormat schro_pix_fmt) ++static enum PixelFormat get_chroma_format(SchroChromaFormat schro_pix_fmt) + { +- int num_formats = sizeof(ffmpeg_schro_pixel_format_map) / +- sizeof(ffmpeg_schro_pixel_format_map[0]); ++ int num_formats = sizeof(schro_pixel_format_map) / ++ sizeof(schro_pixel_format_map[0]); + int idx; + + for (idx = 0; idx < num_formats; ++idx) +- if (ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) +- return ffmpeg_schro_pixel_format_map[idx].ff_pix_fmt; ++ if (schro_pixel_format_map[idx].schro_pix_fmt == schro_pix_fmt) ++ return schro_pixel_format_map[idx].ff_pix_fmt; + return PIX_FMT_NONE; + } + + static av_cold int libschroedinger_decode_init(AVCodecContext *avccontext) + { + +- FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data; ++ SchroDecoderParams *p_schro_params = avccontext->priv_data; + /* First of all, initialize our supporting libraries. */ + schro_init(); + +@@ -164,7 +164,7 @@ + + static void libschroedinger_handle_first_access_unit(AVCodecContext *avccontext) + { +- FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data; ++ SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoder *decoder = p_schro_params->decoder; + + p_schro_params->format = schro_decoder_get_video_format(decoder); +@@ -179,7 +179,7 @@ + } + avccontext->height = p_schro_params->format->height; + avccontext->width = p_schro_params->format->width; +- avccontext->pix_fmt = GetFfmpegChromaFormat(p_schro_params->format->chroma_format); ++ avccontext->pix_fmt = get_chroma_format(p_schro_params->format->chroma_format); + + if (ff_get_schro_frame_format(p_schro_params->format->chroma_format, + &p_schro_params->frame_format) == -1) { +@@ -206,20 +206,19 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + +- FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data; ++ SchroDecoderParams *p_schro_params = avccontext->priv_data; + SchroDecoder *decoder = p_schro_params->decoder; +- SchroVideoFormat *format; + AVPicture *picture = data; + SchroBuffer *enc_buf; + SchroFrame* frame; + int state; + int go = 1; + int outer = 1; +- FfmpegSchroParseUnitContext parse_ctx; ++ SchroParseUnitContext parse_ctx; + + *data_size = 0; + +- FfmpegSchroParseContextInit(&parse_ctx, buf, buf_size); ++ SchroParseContextInit(&parse_ctx, buf, buf_size); + if (!buf_size) { + if (!p_schro_params->eos_signalled) { + state = schro_decoder_push_end_of_stream(decoder); +@@ -229,7 +228,7 @@ + + /* Loop through all the individual parse units in the input buffer */ + do { +- if ((enc_buf = FfmpegFindNextSchroParseUnit(&parse_ctx))) { ++ if ((enc_buf = FindNextSchroParseUnit(&parse_ctx))) { + /* Push buffer into decoder. */ + if (SCHRO_PARSE_CODE_IS_PICTURE(enc_buf->data[4]) && + SCHRO_PARSE_CODE_NUM_REFS(enc_buf->data[4]) > 0) +@@ -240,7 +239,6 @@ + go = 1; + } else + outer = 0; +- format = p_schro_params->format; + + while (go) { + /* Parse data and process result. */ +@@ -316,7 +314,7 @@ + + static av_cold int libschroedinger_decode_close(AVCodecContext *avccontext) + { +- FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data; ++ SchroDecoderParams *p_schro_params = avccontext->priv_data; + /* Free the decoder. */ + schro_decoder_free(p_schro_params->decoder); + av_freep(&p_schro_params->format); +@@ -334,7 +332,7 @@ + { + /* Got a seek request. Free the decoded frames queue and then reset + * the decoder */ +- FfmpegSchroDecoderParams *p_schro_params = avccontext->priv_data; ++ SchroDecoderParams *p_schro_params = avccontext->priv_data; + + /* Free data in the output frame queue. */ + ff_dirac_schro_queue_free(&p_schro_params->dec_frame_queue, +@@ -347,15 +345,14 @@ + } + + AVCodec ff_libschroedinger_decoder = { +- "libschroedinger", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DIRAC, +- sizeof(FfmpegSchroDecoderParams), +- libschroedinger_decode_init, +- NULL, +- libschroedinger_decode_close, +- libschroedinger_decode_frame, +- CODEC_CAP_DELAY, ++ .name = "libschroedinger", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DIRAC, ++ .priv_data_size = sizeof(SchroDecoderParams), ++ .init = libschroedinger_decode_init, ++ .close = libschroedinger_decode_close, ++ .decode = libschroedinger_decode_frame, ++ .capabilities = CODEC_CAP_DELAY, + .flush = libschroedinger_flush, + .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedingerenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedingerenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedingerenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedingerenc.c 2012-05-14 14:08:53.930331850 +0200 +@@ -41,7 +41,7 @@ + + + /** libschroedinger encoder private data */ +-typedef struct FfmpegSchroEncoderParams { ++typedef struct SchroEncoderParams { + /** Schroedinger video format */ + SchroVideoFormat *format; + +@@ -64,31 +64,31 @@ + int enc_buf_size; + + /** queue storing encoded frames */ +- FfmpegDiracSchroQueue enc_frame_queue; ++ DiracSchroQueue enc_frame_queue; + + /** end of sequence signalled */ + int eos_signalled; + + /** end of sequence pulled */ + int eos_pulled; +-} FfmpegSchroEncoderParams; ++} SchroEncoderParams; + + /** + * Works out Schro-compatible chroma format. + */ + static int SetSchroChromaFormat(AVCodecContext *avccontext) + { +- int num_formats = sizeof(ffmpeg_schro_pixel_format_map) / +- sizeof(ffmpeg_schro_pixel_format_map[0]); ++ int num_formats = sizeof(schro_pixel_format_map) / ++ sizeof(schro_pixel_format_map[0]); + int idx; + +- FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; ++ SchroEncoderParams *p_schro_params = avccontext->priv_data; + + for (idx = 0; idx < num_formats; ++idx) { +- if (ffmpeg_schro_pixel_format_map[idx].ff_pix_fmt == ++ if (schro_pixel_format_map[idx].ff_pix_fmt == + avccontext->pix_fmt) { + p_schro_params->format->chroma_format = +- ffmpeg_schro_pixel_format_map[idx].schro_pix_fmt; ++ schro_pixel_format_map[idx].schro_pix_fmt; + return 0; + } + } +@@ -102,7 +102,7 @@ + + static int libschroedinger_encode_init(AVCodecContext *avccontext) + { +- FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; ++ SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroVideoFormatEnum preset; + + /* Initialize the libraries that libschroedinger depends on. */ +@@ -238,7 +238,7 @@ + static SchroFrame *libschroedinger_frame_from_data(AVCodecContext *avccontext, + void *in_data) + { +- FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; ++ SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroFrame *in_frame; + /* Input line size may differ from what the codec supports. Especially + * when transcoding from one format to another. So use avpicture_layout +@@ -256,9 +256,9 @@ + + static void SchroedingerFreeFrame(void *data) + { +- FfmpegDiracSchroEncodedFrame *enc_frame = data; ++ DiracSchroEncodedFrame *enc_frame = data; + +- av_freep(&(enc_frame->p_encbuf)); ++ av_freep(&enc_frame->p_encbuf); + av_free(enc_frame); + } + +@@ -267,9 +267,9 @@ + int buf_size, void *data) + { + int enc_size = 0; +- FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; ++ SchroEncoderParams *p_schro_params = avccontext->priv_data; + SchroEncoder *encoder = p_schro_params->encoder; +- struct FfmpegDiracSchroEncodedFrame* p_frame_output = NULL; ++ struct DiracSchroEncodedFrame *p_frame_output = NULL; + int go = 1; + SchroBuffer *enc_buf; + int presentation_frame; +@@ -328,7 +328,7 @@ + } + + /* Create output frame. */ +- p_frame_output = av_mallocz(sizeof(FfmpegDiracSchroEncodedFrame)); ++ p_frame_output = av_mallocz(sizeof(DiracSchroEncodedFrame)); + /* Set output data. */ + p_frame_output->size = p_schro_params->enc_buf_size; + p_frame_output->p_encbuf = p_schro_params->enc_buf; +@@ -400,8 +400,7 @@ + + static int libschroedinger_encode_close(AVCodecContext *avccontext) + { +- +- FfmpegSchroEncoderParams* p_schro_params = avccontext->priv_data; ++ SchroEncoderParams *p_schro_params = avccontext->priv_data; + + /* Close the encoder. */ + schro_encoder_free(p_schro_params->encoder); +@@ -423,13 +422,13 @@ + + + AVCodec ff_libschroedinger_encoder = { +- "libschroedinger", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_DIRAC, +- sizeof(FfmpegSchroEncoderParams), +- libschroedinger_encode_init, +- libschroedinger_encode_frame, +- libschroedinger_encode_close, ++ .name = "libschroedinger", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_DIRAC, ++ .priv_data_size = sizeof(SchroEncoderParams), ++ .init = libschroedinger_encode_init, ++ .encode = libschroedinger_encode_frame, ++ .close = libschroedinger_encode_close, + .capabilities = CODEC_CAP_DELAY, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libschroedinger Dirac 2.2"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedinger.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedinger.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libschroedinger.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libschroedinger.h 2012-05-14 14:08:53.928331810 +0200 +@@ -20,7 +20,7 @@ + + /** + * @file +-* data structures common to libschroedingerdec.c and libschroedingerenc.c ++* data structures common to libschroedinger decoder and encoder + */ + + #ifndef AVCODEC_LIBSCHROEDINGER_H +@@ -34,7 +34,7 @@ + enum PixelFormat ff_pix_fmt; + SchroChromaFormat schro_pix_fmt; + SchroFrameFormat schro_frame_fmt; +-} ffmpeg_schro_pixel_format_map[] = { ++} schro_pixel_format_map[] = { + { PIX_FMT_YUV420P, SCHRO_CHROMA_420, SCHRO_FRAME_FORMAT_U8_420 }, + { PIX_FMT_YUV422P, SCHRO_CHROMA_422, SCHRO_FRAME_FORMAT_U8_422 }, + { PIX_FMT_YUV444P, SCHRO_CHROMA_444, SCHRO_FRAME_FORMAT_U8_444 }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libspeexdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libspeexdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libspeexdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libspeexdec.c 2012-05-14 14:08:53.931331871 +0200 +@@ -18,13 +18,14 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "avcodec.h" + #include + #include + #include + #include ++#include "avcodec.h" + + typedef struct { ++ AVFrame frame; + SpeexBits bits; + SpeexStereoState stereo; + void *dec_state; +@@ -60,14 +61,14 @@ + mode = speex_lib_get_mode(s->header->mode); + if (!mode) { + av_log(avctx, AV_LOG_ERROR, "Unknown Speex mode %d", s->header->mode); +- return -1; ++ return AVERROR_INVALIDDATA; + } + } else + av_log(avctx, AV_LOG_INFO, "Missing Speex header, assuming defaults.\n"); + + if (avctx->channels > 2) { + av_log(avctx, AV_LOG_ERROR, "Only stereo and mono are supported.\n"); +- return -1; ++ return AVERROR(EINVAL); + } + + speex_bits_init(&s->bits); +@@ -89,42 +90,57 @@ + s->stereo = (SpeexStereoState)SPEEX_STEREO_STATE_INIT; + speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback); + } ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +-static int libspeex_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int libspeex_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; ++ uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + LibSpeexContext *s = avctx->priv_data; +- int16_t *output = data, *end; +- int i, num_samples; +- +- num_samples = s->frame_size * avctx->channels; +- end = output + *data_size / sizeof(*output); ++ int16_t *output; ++ int ret, consumed = 0; + +- speex_bits_read_from(&s->bits, buf, buf_size); +- +- for (i = 0; speex_bits_remaining(&s->bits) && output + num_samples < end; i++) { +- int ret = speex_decode_int(s->dec_state, &s->bits, output); +- if (ret <= -2) { +- av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n"); +- return -1; +- } else if (ret == -1) +- // end of stream +- break; ++ /* get output buffer */ ++ s->frame.nb_samples = s->frame_size; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ output = (int16_t *)s->frame.data[0]; + +- if (avctx->channels == 2) +- speex_decode_stereo_int(output, s->frame_size, &s->stereo); ++ /* if there is not enough data left for the smallest possible frame, ++ reset the libspeex buffer using the current packet, otherwise ignore ++ the current packet and keep decoding frames from the libspeex buffer. */ ++ if (speex_bits_remaining(&s->bits) < 43) { ++ /* check for flush packet */ ++ if (!buf || !buf_size) { ++ *got_frame_ptr = 0; ++ return buf_size; ++ } ++ /* set new buffer */ ++ speex_bits_read_from(&s->bits, buf, buf_size); ++ consumed = buf_size; ++ } + +- output += num_samples; ++ /* decode a single frame */ ++ ret = speex_decode_int(s->dec_state, &s->bits, output); ++ if (ret <= -2) { ++ av_log(avctx, AV_LOG_ERROR, "Error decoding Speex frame.\n"); ++ return AVERROR_INVALIDDATA; + } ++ if (avctx->channels == 2) ++ speex_decode_stereo_int(output, s->frame_size, &s->stereo); + +- avctx->frame_size = s->frame_size * i; +- *data_size = avctx->channels * avctx->frame_size * sizeof(*output); +- return buf_size; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return consumed; + } + + static av_cold int libspeex_decode_close(AVCodecContext *avctx) +@@ -138,14 +154,21 @@ + return 0; + } + ++static av_cold void libspeex_decode_flush(AVCodecContext *avctx) ++{ ++ LibSpeexContext *s = avctx->priv_data; ++ speex_bits_reset(&s->bits); ++} ++ + AVCodec ff_libspeex_decoder = { +- "libspeex", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SPEEX, +- sizeof(LibSpeexContext), +- libspeex_decode_init, +- NULL, +- libspeex_decode_close, +- libspeex_decode_frame, ++ .name = "libspeex", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SPEEX, ++ .priv_data_size = sizeof(LibSpeexContext), ++ .init = libspeex_decode_init, ++ .close = libspeex_decode_close, ++ .decode = libspeex_decode_frame, ++ .flush = libspeex_decode_flush, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libspeexenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libspeexenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libspeexenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libspeexenc.c 2012-05-14 14:08:53.932331891 +0200 +@@ -0,0 +1,326 @@ ++/* ++ * Copyright (C) 2009 Justin Ruggles ++ * Copyright (c) 2009 Xuggle Incorporated ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libspeex Speex audio encoder ++ * ++ * Usage Guide ++ * This explains the values that need to be set prior to initialization in ++ * order to control various encoding parameters. ++ * ++ * Channels ++ * Speex only supports mono or stereo, so avctx->channels must be set to ++ * 1 or 2. ++ * ++ * Sample Rate / Encoding Mode ++ * Speex has 3 modes, each of which uses a specific sample rate. ++ * narrowband : 8 kHz ++ * wideband : 16 kHz ++ * ultra-wideband : 32 kHz ++ * avctx->sample_rate must be set to one of these 3 values. This will be ++ * used to set the encoding mode. ++ * ++ * Rate Control ++ * VBR mode is turned on by setting CODEC_FLAG_QSCALE in avctx->flags. ++ * avctx->global_quality is used to set the encoding quality. ++ * For CBR mode, avctx->bit_rate can be used to set the constant bitrate. ++ * Alternatively, the 'cbr_quality' option can be set from 0 to 10 to set ++ * a constant bitrate based on quality. ++ * For ABR mode, set avctx->bit_rate and set the 'abr' option to 1. ++ * Approx. Bitrate Range: ++ * narrowband : 2400 - 25600 bps ++ * wideband : 4000 - 43200 bps ++ * ultra-wideband : 4400 - 45200 bps ++ * ++ * Complexity ++ * Encoding complexity is controlled by setting avctx->compression_level. ++ * The valid range is 0 to 10. A higher setting gives generally better ++ * quality at the expense of encoding speed. This does not affect the ++ * bit rate. ++ * ++ * Frames-per-Packet ++ * The encoder defaults to using 1 frame-per-packet. However, it is ++ * sometimes desirable to use multiple frames-per-packet to reduce the ++ * amount of container overhead. This can be done by setting the ++ * 'frames_per_packet' option to a value 1 to 8. ++ */ ++ ++#include ++#include ++#include ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" ++#include "avcodec.h" ++#include "internal.h" ++ ++typedef struct { ++ AVClass *class; ///< AVClass for private options ++ SpeexBits bits; ///< libspeex bitwriter context ++ SpeexHeader header; ///< libspeex header struct ++ void *enc_state; ///< libspeex encoder state ++ int frames_per_packet; ///< number of frames to encode in each packet ++ float vbr_quality; ///< VBR quality 0.0 to 10.0 ++ int cbr_quality; ///< CBR quality 0 to 10 ++ int abr; ///< flag to enable ABR ++ int pkt_frame_count; ///< frame count for the current packet ++ int lookahead; ///< encoder delay ++ int64_t next_pts; ///< next pts, in sample_rate time base ++ int pkt_sample_count; ///< sample count in the current packet ++} LibSpeexEncContext; ++ ++static av_cold void print_enc_params(AVCodecContext *avctx, ++ LibSpeexEncContext *s) ++{ ++ const char *mode_str = "unknown"; ++ ++ av_log(avctx, AV_LOG_DEBUG, "channels: %d\n", avctx->channels); ++ switch (s->header.mode) { ++ case SPEEX_MODEID_NB: mode_str = "narrowband"; break; ++ case SPEEX_MODEID_WB: mode_str = "wideband"; break; ++ case SPEEX_MODEID_UWB: mode_str = "ultra-wideband"; break; ++ } ++ av_log(avctx, AV_LOG_DEBUG, "mode: %s\n", mode_str); ++ if (s->header.vbr) { ++ av_log(avctx, AV_LOG_DEBUG, "rate control: VBR\n"); ++ av_log(avctx, AV_LOG_DEBUG, " quality: %f\n", s->vbr_quality); ++ } else if (s->abr) { ++ av_log(avctx, AV_LOG_DEBUG, "rate control: ABR\n"); ++ av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate); ++ } else { ++ av_log(avctx, AV_LOG_DEBUG, "rate control: CBR\n"); ++ av_log(avctx, AV_LOG_DEBUG, " bitrate: %d bps\n", avctx->bit_rate); ++ } ++ av_log(avctx, AV_LOG_DEBUG, "complexity: %d\n", ++ avctx->compression_level); ++ av_log(avctx, AV_LOG_DEBUG, "frame size: %d samples\n", ++ avctx->frame_size); ++ av_log(avctx, AV_LOG_DEBUG, "frames per packet: %d\n", ++ s->frames_per_packet); ++ av_log(avctx, AV_LOG_DEBUG, "packet size: %d\n", ++ avctx->frame_size * s->frames_per_packet); ++} ++ ++static av_cold int encode_init(AVCodecContext *avctx) ++{ ++ LibSpeexEncContext *s = avctx->priv_data; ++ const SpeexMode *mode; ++ uint8_t *header_data; ++ int header_size; ++ int32_t complexity; ++ ++ /* channels */ ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid channels (%d). Only stereo and " ++ "mono are supported\n", avctx->channels); ++ return AVERROR(EINVAL); ++ } ++ ++ /* sample rate and encoding mode */ ++ switch (avctx->sample_rate) { ++ case 8000: mode = &speex_nb_mode; break; ++ case 16000: mode = &speex_wb_mode; break; ++ case 32000: mode = &speex_uwb_mode; break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Sample rate of %d Hz is not supported. " ++ "Resample to 8, 16, or 32 kHz.\n", avctx->sample_rate); ++ return AVERROR(EINVAL); ++ } ++ ++ /* initialize libspeex */ ++ s->enc_state = speex_encoder_init(mode); ++ if (!s->enc_state) { ++ av_log(avctx, AV_LOG_ERROR, "Error initializing libspeex\n"); ++ return -1; ++ } ++ speex_init_header(&s->header, avctx->sample_rate, avctx->channels, mode); ++ ++ /* rate control method and parameters */ ++ if (avctx->flags & CODEC_FLAG_QSCALE) { ++ /* VBR */ ++ s->header.vbr = 1; ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR, &s->header.vbr); ++ s->vbr_quality = av_clipf(avctx->global_quality / (float)FF_QP2LAMBDA, ++ 0.0f, 10.0f); ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_VBR_QUALITY, &s->vbr_quality); ++ } else { ++ s->header.bitrate = avctx->bit_rate; ++ if (avctx->bit_rate > 0) { ++ /* CBR or ABR by bitrate */ ++ if (s->abr) { ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_ABR, ++ &s->header.bitrate); ++ speex_encoder_ctl(s->enc_state, SPEEX_GET_ABR, ++ &s->header.bitrate); ++ } else { ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_BITRATE, ++ &s->header.bitrate); ++ speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE, ++ &s->header.bitrate); ++ } ++ } else { ++ /* CBR by quality */ ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_QUALITY, ++ &s->cbr_quality); ++ speex_encoder_ctl(s->enc_state, SPEEX_GET_BITRATE, ++ &s->header.bitrate); ++ } ++ /* stereo side information adds about 800 bps to the base bitrate */ ++ /* TODO: this should be calculated exactly */ ++ avctx->bit_rate = s->header.bitrate + (avctx->channels == 2 ? 800 : 0); ++ } ++ ++ /* set encoding complexity */ ++ if (avctx->compression_level > FF_COMPRESSION_DEFAULT) { ++ complexity = av_clip(avctx->compression_level, 0, 10); ++ speex_encoder_ctl(s->enc_state, SPEEX_SET_COMPLEXITY, &complexity); ++ } ++ speex_encoder_ctl(s->enc_state, SPEEX_GET_COMPLEXITY, &complexity); ++ avctx->compression_level = complexity; ++ ++ /* set packet size */ ++ avctx->frame_size = s->header.frame_size; ++ s->header.frames_per_packet = s->frames_per_packet; ++ ++ /* set encoding delay */ ++ speex_encoder_ctl(s->enc_state, SPEEX_GET_LOOKAHEAD, &s->lookahead); ++ s->next_pts = -s->lookahead; ++ ++ /* create header packet bytes from header struct */ ++ /* note: libspeex allocates the memory for header_data, which is freed ++ below with speex_header_free() */ ++ header_data = speex_header_to_packet(&s->header, &header_size); ++ ++ /* allocate extradata and coded_frame */ ++ avctx->extradata = av_malloc(header_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->extradata || !avctx->coded_frame) { ++ speex_header_free(header_data); ++ speex_encoder_destroy(s->enc_state); ++ av_log(avctx, AV_LOG_ERROR, "memory allocation error\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ /* copy header packet to extradata */ ++ memcpy(avctx->extradata, header_data, header_size); ++ avctx->extradata_size = header_size; ++ speex_header_free(header_data); ++ ++ /* init libspeex bitwriter */ ++ speex_bits_init(&s->bits); ++ ++ print_enc_params(avctx, s); ++ return 0; ++} ++ ++static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, ++ void *data) ++{ ++ LibSpeexEncContext *s = avctx->priv_data; ++ int16_t *samples = data; ++ ++ if (data) { ++ /* encode Speex frame */ ++ if (avctx->channels == 2) ++ speex_encode_stereo_int(samples, s->header.frame_size, &s->bits); ++ speex_encode_int(s->enc_state, samples, &s->bits); ++ s->pkt_frame_count++; ++ s->pkt_sample_count += avctx->frame_size; ++ } else { ++ /* handle end-of-stream */ ++ if (!s->pkt_frame_count) ++ return 0; ++ /* add extra terminator codes for unused frames in last packet */ ++ while (s->pkt_frame_count < s->frames_per_packet) { ++ speex_bits_pack(&s->bits, 15, 5); ++ s->pkt_frame_count++; ++ } ++ } ++ ++ /* write output if all frames for the packet have been encoded */ ++ if (s->pkt_frame_count == s->frames_per_packet) { ++ s->pkt_frame_count = 0; ++ avctx->coded_frame->pts = ++ av_rescale_q(s->next_pts, (AVRational){ 1, avctx->sample_rate }, ++ avctx->time_base); ++ s->next_pts += s->pkt_sample_count; ++ s->pkt_sample_count = 0; ++ if (buf_size > speex_bits_nbytes(&s->bits)) { ++ int ret = speex_bits_write(&s->bits, frame, buf_size); ++ speex_bits_reset(&s->bits); ++ return ret; ++ } else { ++ av_log(avctx, AV_LOG_ERROR, "output buffer too small"); ++ return AVERROR(EINVAL); ++ } ++ } ++ return 0; ++} ++ ++static av_cold int encode_close(AVCodecContext *avctx) ++{ ++ LibSpeexEncContext *s = avctx->priv_data; ++ ++ speex_bits_destroy(&s->bits); ++ speex_encoder_destroy(s->enc_state); ++ ++ av_freep(&avctx->coded_frame); ++ av_freep(&avctx->extradata); ++ ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(LibSpeexEncContext, x) ++#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "abr", "Use average bit rate", OFFSET(abr), AV_OPT_TYPE_INT, { 0 }, 0, 1, AE }, ++ { "cbr_quality", "Set quality value (0 to 10) for CBR", OFFSET(cbr_quality), AV_OPT_TYPE_INT, { 8 }, 0, 10, AE }, ++ { "frames_per_packet", "Number of frames to encode in each packet", OFFSET(frames_per_packet), AV_OPT_TYPE_INT, { 1 }, 1, 8, AE }, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "libspeex", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVCodecDefault defaults[] = { ++ { "b", "0" }, ++ { "compression_level", "3" }, ++ { NULL }, ++}; ++ ++AVCodec ff_libspeex_encoder = { ++ .name = "libspeex", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SPEEX, ++ .priv_data_size = sizeof(LibSpeexEncContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_close, ++ .capabilities = CODEC_CAP_DELAY, ++ .sample_fmts = (const enum SampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("libspeex Speex"), ++ .priv_class = &class, ++ .defaults = defaults, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libstagefright.cpp xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libstagefright.cpp +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libstagefright.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libstagefright.cpp 2012-05-14 14:08:53.933331911 +0200 +@@ -0,0 +1,552 @@ ++/* ++ * Interface to the Android Stagefright library for ++ * H/W accelerated H.264 decoding ++ * ++ * Copyright (C) 2011 Mohamed Naufal ++ * Copyright (C) 2011 Martin Storsjö ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++extern "C" { ++#include "avcodec.h" ++#include "libavutil/imgutils.h" ++} ++ ++#define OMX_QCOM_COLOR_FormatYVU420SemiPlanar 0x7FA30C00 ++ ++using namespace android; ++ ++struct Frame { ++ status_t status; ++ size_t size; ++ int64_t time; ++ int key; ++ uint8_t *buffer; ++ MediaBuffer* mbuffer; ++ int32_t w, h; ++}; ++ ++class CustomSource; ++ ++struct StagefrightContext { ++ AVCodecContext *avctx; ++ AVBitStreamFilterContext *bsfc; ++ uint8_t* orig_extradata; ++ int orig_extradata_size; ++ sp *source; ++ List *in_queue, *out_queue; ++ pthread_mutex_t in_mutex, out_mutex; ++ pthread_cond_t condition; ++ pthread_t decode_thread_id; ++ ++ Frame *end_frame; ++ bool source_done; ++ volatile sig_atomic_t thread_started, thread_exited, stop_decode; ++ ++ AVFrame ret_frame; ++ ++ uint8_t *dummy_buf; ++ int dummy_bufsize; ++ ++ OMXClient *client; ++ sp *decoder; ++ const char *decoder_component; ++}; ++ ++class CustomSource : public MediaSource { ++public: ++ CustomSource(AVCodecContext *avctx, sp meta) { ++ s = (StagefrightContext*)avctx->priv_data; ++ source_meta = meta; ++ frame_size = (avctx->width * avctx->height * 3) / 2; ++ buf_group.add_buffer(new MediaBuffer(frame_size)); ++ } ++ ++ virtual sp getFormat() { ++ return source_meta; ++ } ++ ++ virtual status_t start(MetaData *params) { ++ return OK; ++ } ++ ++ virtual status_t stop() { ++ return OK; ++ } ++ ++ virtual status_t read(MediaBuffer **buffer, ++ const MediaSource::ReadOptions *options) { ++ Frame *frame; ++ status_t ret; ++ ++ if (s->thread_exited) ++ return ERROR_END_OF_STREAM; ++ pthread_mutex_lock(&s->in_mutex); ++ ++ while (s->in_queue->empty()) ++ pthread_cond_wait(&s->condition, &s->in_mutex); ++ ++ frame = *s->in_queue->begin(); ++ ret = frame->status; ++ ++ if (ret == OK) { ++ ret = buf_group.acquire_buffer(buffer); ++ if (ret == OK) { ++ memcpy((*buffer)->data(), frame->buffer, frame->size); ++ (*buffer)->set_range(0, frame->size); ++ (*buffer)->meta_data()->clear(); ++ (*buffer)->meta_data()->setInt32(kKeyIsSyncFrame,frame->key); ++ (*buffer)->meta_data()->setInt64(kKeyTime, frame->time); ++ } else { ++ av_log(s->avctx, AV_LOG_ERROR, "Failed to acquire MediaBuffer\n"); ++ } ++ av_freep(&frame->buffer); ++ } ++ ++ s->in_queue->erase(s->in_queue->begin()); ++ pthread_mutex_unlock(&s->in_mutex); ++ ++ av_freep(&frame); ++ return ret; ++ } ++ ++private: ++ MediaBufferGroup buf_group; ++ sp source_meta; ++ StagefrightContext *s; ++ int frame_size; ++}; ++ ++void* decode_thread(void *arg) ++{ ++ AVCodecContext *avctx = (AVCodecContext*)arg; ++ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; ++ Frame* frame; ++ MediaBuffer *buffer; ++ int decode_done = 0; ++ do { ++ buffer = NULL; ++ frame = (Frame*)av_mallocz(sizeof(Frame)); ++ if (!frame) { ++ frame = s->end_frame; ++ frame->status = AVERROR(ENOMEM); ++ decode_done = 1; ++ s->end_frame = NULL; ++ } else { ++ frame->status = (*s->decoder)->read(&buffer); ++ if (frame->status == OK) { ++ sp outFormat = (*s->decoder)->getFormat(); ++ outFormat->findInt32(kKeyWidth , &frame->w); ++ outFormat->findInt32(kKeyHeight, &frame->h); ++ frame->size = buffer->range_length(); ++ frame->mbuffer = buffer; ++ } else if (frame->status == INFO_FORMAT_CHANGED) { ++ if (buffer) ++ buffer->release(); ++ av_free(frame); ++ continue; ++ } else { ++ decode_done = 1; ++ } ++ } ++ while (true) { ++ pthread_mutex_lock(&s->out_mutex); ++ if (s->out_queue->size() >= 10) { ++ pthread_mutex_unlock(&s->out_mutex); ++ usleep(10000); ++ continue; ++ } ++ break; ++ } ++ s->out_queue->push_back(frame); ++ pthread_mutex_unlock(&s->out_mutex); ++ } while (!decode_done && !s->stop_decode); ++ ++ s->thread_exited = true; ++ ++ return 0; ++} ++ ++static av_cold int Stagefright_init(AVCodecContext *avctx) ++{ ++ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; ++ sp meta, outFormat; ++ int32_t colorFormat = 0; ++ int ret; ++ ++ if (!avctx->extradata || !avctx->extradata_size || avctx->extradata[0] != 1) ++ return -1; ++ ++ s->avctx = avctx; ++ s->bsfc = av_bitstream_filter_init("h264_mp4toannexb"); ++ if (!s->bsfc) { ++ av_log(avctx, AV_LOG_ERROR, "Cannot open the h264_mp4toannexb BSF!\n"); ++ return -1; ++ } ++ ++ s->orig_extradata_size = avctx->extradata_size; ++ s->orig_extradata = (uint8_t*) av_mallocz(avctx->extradata_size + ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!s->orig_extradata) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ memcpy(s->orig_extradata, avctx->extradata, avctx->extradata_size); ++ ++ meta = new MetaData; ++ if (meta == NULL) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ meta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_VIDEO_AVC); ++ meta->setInt32(kKeyWidth, avctx->width); ++ meta->setInt32(kKeyHeight, avctx->height); ++ meta->setData(kKeyAVCC, kTypeAVCC, avctx->extradata, avctx->extradata_size); ++ ++ android::ProcessState::self()->startThreadPool(); ++ ++ s->source = new sp(); ++ *s->source = new CustomSource(avctx, meta); ++ s->in_queue = new List; ++ s->out_queue = new List; ++ s->client = new OMXClient; ++ s->end_frame = (Frame*)av_mallocz(sizeof(Frame)); ++ if (s->source == NULL || !s->in_queue || !s->out_queue || !s->client || ++ !s->end_frame) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ ++ if (s->client->connect() != OK) { ++ av_log(avctx, AV_LOG_ERROR, "Cannot connect OMX client\n"); ++ ret = -1; ++ goto fail; ++ } ++ ++ s->decoder = new sp(); ++ *s->decoder = OMXCodec::Create(s->client->interface(), meta, ++ false, *s->source, NULL, ++ OMXCodec::kClientNeedsFramebuffer); ++ if ((*s->decoder)->start() != OK) { ++ av_log(avctx, AV_LOG_ERROR, "Cannot start decoder\n"); ++ ret = -1; ++ s->client->disconnect(); ++ goto fail; ++ } ++ ++ outFormat = (*s->decoder)->getFormat(); ++ outFormat->findInt32(kKeyColorFormat, &colorFormat); ++ if (colorFormat == OMX_QCOM_COLOR_FormatYVU420SemiPlanar || ++ colorFormat == OMX_COLOR_FormatYUV420SemiPlanar) ++ avctx->pix_fmt = PIX_FMT_NV21; ++ else ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ ++ outFormat->findCString(kKeyDecoderComponent, &s->decoder_component); ++ if (s->decoder_component) ++ s->decoder_component = av_strdup(s->decoder_component); ++ ++ pthread_mutex_init(&s->in_mutex, NULL); ++ pthread_mutex_init(&s->out_mutex, NULL); ++ pthread_cond_init(&s->condition, NULL); ++ return 0; ++ ++fail: ++ av_bitstream_filter_close(s->bsfc); ++ av_freep(&s->orig_extradata); ++ av_freep(&s->end_frame); ++ delete s->in_queue; ++ delete s->out_queue; ++ delete s->client; ++ return ret; ++} ++ ++static int Stagefright_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; ++ Frame *frame; ++ MediaBuffer *mbuffer; ++ status_t status; ++ size_t size; ++ uint8_t *buf; ++ const uint8_t *src_data[3]; ++ int w, h; ++ int src_linesize[3]; ++ int orig_size = avpkt->size; ++ AVPacket pkt = *avpkt; ++ int ret; ++ ++ if (!s->thread_started) { ++ pthread_create(&s->decode_thread_id, NULL, &decode_thread, avctx); ++ s->thread_started = true; ++ } ++ ++ if (avpkt && avpkt->data) { ++ av_bitstream_filter_filter(s->bsfc, avctx, NULL, &pkt.data, &pkt.size, ++ avpkt->data, avpkt->size, avpkt->flags & AV_PKT_FLAG_KEY); ++ avpkt = &pkt; ++ } ++ ++ if (!s->source_done) { ++ if(!s->dummy_buf) { ++ s->dummy_buf = (uint8_t*)av_malloc(avpkt->size); ++ if (!s->dummy_buf) ++ return AVERROR(ENOMEM); ++ s->dummy_bufsize = avpkt->size; ++ memcpy(s->dummy_buf, avpkt->data, avpkt->size); ++ } ++ ++ frame = (Frame*)av_mallocz(sizeof(Frame)); ++ if (avpkt->data) { ++ frame->status = OK; ++ frame->size = avpkt->size; ++ // Stagefright can't handle negative timestamps - ++ // if needed, work around this by offsetting them manually? ++ if (avpkt->pts >= 0) ++ frame->time = avpkt->pts; ++ frame->key = avpkt->flags & AV_PKT_FLAG_KEY ? 1 : 0; ++ frame->buffer = (uint8_t*)av_malloc(avpkt->size); ++ if (!frame->buffer) { ++ av_freep(&frame); ++ return AVERROR(ENOMEM); ++ } ++ uint8_t *ptr = avpkt->data; ++ // The OMX.SEC decoder fails without this. ++ if (avpkt->size == orig_size + avctx->extradata_size) { ++ ptr += avctx->extradata_size; ++ frame->size = orig_size; ++ } ++ memcpy(frame->buffer, ptr, orig_size); ++ } else { ++ frame->status = ERROR_END_OF_STREAM; ++ s->source_done = true; ++ } ++ ++ while (true) { ++ if (s->thread_exited) { ++ s->source_done = true; ++ break; ++ } ++ pthread_mutex_lock(&s->in_mutex); ++ if (s->in_queue->size() >= 10) { ++ pthread_mutex_unlock(&s->in_mutex); ++ usleep(10000); ++ continue; ++ } ++ s->in_queue->push_back(frame); ++ pthread_cond_signal(&s->condition); ++ pthread_mutex_unlock(&s->in_mutex); ++ break; ++ } ++ } ++ while (true) { ++ pthread_mutex_lock(&s->out_mutex); ++ if (!s->out_queue->empty()) break; ++ pthread_mutex_unlock(&s->out_mutex); ++ if (s->source_done) { ++ usleep(10000); ++ continue; ++ } else { ++ return orig_size; ++ } ++ } ++ ++ frame = *s->out_queue->begin(); ++ s->out_queue->erase(s->out_queue->begin()); ++ pthread_mutex_unlock(&s->out_mutex); ++ ++ mbuffer = frame->mbuffer; ++ status = frame->status; ++ size = frame->size; ++ w = frame->w; ++ h = frame->h; ++ av_freep(&frame); ++ ++ if (status == ERROR_END_OF_STREAM) ++ return 0; ++ if (status != OK) { ++ if (status == AVERROR(ENOMEM)) ++ return status; ++ av_log(avctx, AV_LOG_ERROR, "Decode failed: %x\n", status); ++ return -1; ++ } ++ ++ // The OMX.SEC decoder doesn't signal the modified width/height ++ if (s->decoder_component && !strncmp(s->decoder_component, "OMX.SEC", 7) && ++ (w & 15 || h & 15)) { ++ if (((w + 15)&~15) * ((h + 15)&~15) * 3/2 == size) { ++ w = (w + 15)&~15; ++ h = (h + 15)&~15; ++ } ++ } ++ ++ if (!avctx->width || !avctx->height || avctx->width > w || avctx->height > h) { ++ avctx->width = w; ++ avctx->height = h; ++ } ++ ++ ret = avctx->reget_buffer(avctx, &s->ret_frame); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, "reget buffer() failed\n"); ++ goto end; ++ } ++ ++ src_linesize[0] = w; ++ if (avctx->pix_fmt == PIX_FMT_YUV420P) ++ src_linesize[1] = src_linesize[2] = w/2; ++ else if (avctx->pix_fmt == PIX_FMT_NV21) ++ src_linesize[1] = w; ++ ++ buf = (uint8_t*)mbuffer->data(); ++ src_data[0] = buf; ++ src_data[1] = buf + src_linesize[0] * h; ++ src_data[2] = src_data[1] + src_linesize[1] * h/2; ++ av_image_copy(s->ret_frame.data, s->ret_frame.linesize, ++ src_data, src_linesize, ++ avctx->pix_fmt, avctx->width, avctx->height); ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = s->ret_frame; ++ ret = orig_size; ++end: ++ mbuffer->release(); ++ return ret; ++} ++ ++static av_cold int Stagefright_close(AVCodecContext *avctx) ++{ ++ StagefrightContext *s = (StagefrightContext*)avctx->priv_data; ++ Frame *frame; ++ ++ if (s->thread_started) { ++ if (!s->thread_exited) { ++ s->stop_decode = 1; ++ ++ // Make sure decode_thread() doesn't get stuck ++ pthread_mutex_lock(&s->out_mutex); ++ while (!s->out_queue->empty()) { ++ frame = *s->out_queue->begin(); ++ s->out_queue->erase(s->out_queue->begin()); ++ if (frame->size) ++ frame->mbuffer->release(); ++ av_freep(&frame); ++ } ++ pthread_mutex_unlock(&s->out_mutex); ++ ++ // Feed a dummy frame prior to signalling EOF. ++ // This is required to terminate the decoder(OMX.SEC) ++ // when only one frame is read during stream info detection. ++ if (s->dummy_buf && (frame = (Frame*)av_mallocz(sizeof(Frame)))) { ++ frame->status = OK; ++ frame->size = s->dummy_bufsize; ++ frame->key = 1; ++ frame->buffer = s->dummy_buf; ++ pthread_mutex_lock(&s->in_mutex); ++ s->in_queue->push_back(frame); ++ pthread_cond_signal(&s->condition); ++ pthread_mutex_unlock(&s->in_mutex); ++ s->dummy_buf = NULL; ++ } ++ ++ pthread_mutex_lock(&s->in_mutex); ++ s->end_frame->status = ERROR_END_OF_STREAM; ++ s->in_queue->push_back(s->end_frame); ++ pthread_cond_signal(&s->condition); ++ pthread_mutex_unlock(&s->in_mutex); ++ s->end_frame = NULL; ++ } ++ ++ pthread_join(s->decode_thread_id, NULL); ++ ++ if (s->ret_frame.data[0]) ++ avctx->release_buffer(avctx, &s->ret_frame); ++ ++ s->thread_started = false; ++ } ++ ++ while (!s->in_queue->empty()) { ++ frame = *s->in_queue->begin(); ++ s->in_queue->erase(s->in_queue->begin()); ++ if (frame->size) ++ av_freep(&frame->buffer); ++ av_freep(&frame); ++ } ++ ++ while (!s->out_queue->empty()) { ++ frame = *s->out_queue->begin(); ++ s->out_queue->erase(s->out_queue->begin()); ++ if (frame->size) ++ frame->mbuffer->release(); ++ av_freep(&frame); ++ } ++ ++ (*s->decoder)->stop(); ++ s->client->disconnect(); ++ ++ if (s->decoder_component) ++ av_freep(&s->decoder_component); ++ av_freep(&s->dummy_buf); ++ av_freep(&s->end_frame); ++ ++ // Reset the extradata back to the original mp4 format, so that ++ // the next invocation (both when decoding and when called from ++ // av_find_stream_info) get the original mp4 format extradata. ++ av_freep(&avctx->extradata); ++ avctx->extradata = s->orig_extradata; ++ avctx->extradata_size = s->orig_extradata_size; ++ ++ delete s->in_queue; ++ delete s->out_queue; ++ delete s->client; ++ delete s->decoder; ++ delete s->source; ++ ++ pthread_mutex_destroy(&s->in_mutex); ++ pthread_mutex_destroy(&s->out_mutex); ++ pthread_cond_destroy(&s->condition); ++ av_bitstream_filter_close(s->bsfc); ++ return 0; ++} ++ ++AVCodec ff_libstagefright_h264_decoder = { ++ "libstagefright_h264", ++ AVMEDIA_TYPE_VIDEO, ++ CODEC_ID_H264, ++ sizeof(StagefrightContext), ++ Stagefright_init, ++ NULL, //encode ++ Stagefright_close, ++ Stagefright_decode_frame, ++ CODEC_CAP_DELAY, ++ NULL, //next ++ NULL, //flush ++ NULL, //supported_framerates ++ NULL, //pixel_formats ++ NULL_IF_CONFIG_SMALL("libstagefright H.264"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libtheoraenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libtheoraenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libtheoraenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libtheoraenc.c 2012-05-14 14:08:53.934331931 +0200 +@@ -241,7 +241,7 @@ + header, comment, and tables. + + Each one is prefixed with a 16bit size, then they +- are concatenated together into ffmpeg's extradata. ++ are concatenated together into libavcodec's extradata. + */ + offset = 0; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libutvideo.cpp xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libutvideo.cpp +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libutvideo.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libutvideo.cpp 2012-05-14 14:08:53.935331951 +0200 +@@ -0,0 +1,205 @@ ++/* ++ * Copyright (c) 2011 Derek Buitenhuis ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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; ++ * version 2 of the License. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Known FOURCCs: ++ * 'ULY0' (YCbCr 4:2:0), 'ULY2' (YCbCr 4:2:2), 'ULRG' (RGB), 'ULRA' (RGBA) ++ */ ++ ++extern "C" { ++#include "avcodec.h" ++} ++ ++#include ++#include ++#include ++ ++#include "get_bits.h" ++ ++typedef struct { ++ uint32_t version; ++ uint32_t original_format; ++ uint32_t frameinfo_size; ++ uint32_t flags; ++} UtVideoExtra; ++ ++typedef struct { ++ CCodec *codec; ++ unsigned int buf_size; ++ uint8_t *output; ++} UtVideoContext; ++ ++static av_cold int utvideo_decode_init(AVCodecContext *avctx) ++{ ++ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; ++ UtVideoExtra info; ++ int format; ++ int begin_ret; ++ ++ if (avctx->extradata_size != 4*4) { ++ av_log(avctx, AV_LOG_ERROR, "Extradata size mismatch.\n"); ++ return -1; ++ } ++ ++ /* Read extradata */ ++ info.version = AV_RL32(avctx->extradata); ++ info.original_format = AV_RL32(avctx->extradata + 4); ++ info.frameinfo_size = AV_RL32(avctx->extradata + 8); ++ info.flags = AV_RL32(avctx->extradata + 12); ++ ++ /* Pick format based on FOURCC */ ++ switch (avctx->codec_tag) { ++ case MKTAG('U', 'L', 'Y', '0'): ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ format = UTVF_YV12; ++ break; ++ case MKTAG('U', 'L', 'Y', '2'): ++ avctx->pix_fmt = PIX_FMT_YUYV422; ++ format = UTVF_YUY2; ++ break; ++ case MKTAG('U', 'L', 'R', 'G'): ++ avctx->pix_fmt = PIX_FMT_BGR24; ++ format = UTVF_RGB24_WIN; ++ break; ++ case MKTAG('U', 'L', 'R', 'A'): ++ avctx->pix_fmt = PIX_FMT_RGB32; ++ format = UTVF_RGB32_WIN; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, ++ "Not a Ut Video FOURCC: %X\n", avctx->codec_tag); ++ return -1; ++ } ++ ++ /* Only allocate the buffer once */ ++ utv->buf_size = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); ++ utv->output = (uint8_t *)av_malloc(utv->buf_size * sizeof(uint8_t)); ++ ++ if (utv->output == NULL) { ++ av_log(avctx, AV_LOG_ERROR, "Unable to allocate output buffer.\n"); ++ return -1; ++ } ++ ++ /* Allocate the output frame */ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ /* Ut Video only supports 8-bit */ ++ avctx->bits_per_raw_sample = 8; ++ ++ /* Is it interlaced? */ ++ avctx->coded_frame->interlaced_frame = info.flags & 0x800 ? 1 : 0; ++ ++ /* Apparently Ut Video doesn't store this info... */ ++ avctx->coded_frame->top_field_first = 1; ++ ++ /* ++ * Create a Ut Video instance. Since the function wants ++ * an "interface name" string, pass it the name of the lib. ++ */ ++ utv->codec = CCodec::CreateInstance(UNFCC(avctx->codec_tag), "libavcodec"); ++ ++ /* Initialize Decoding */ ++ begin_ret = utv->codec->DecodeBegin(format, avctx->width, avctx->height, ++ CBGROSSWIDTH_WINDOWS, &info, sizeof(UtVideoExtra)); ++ ++ /* Check to see if the decoder initlized properly */ ++ if (begin_ret != 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Could not initialize decoder: %d\n", begin_ret); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int utvideo_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; ++ AVFrame *pic = avctx->coded_frame; ++ int w = avctx->width, h = avctx->height; ++ ++ /* Set flags */ ++ pic->reference = 0; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ pic->key_frame = 1; ++ ++ /* Decode the frame */ ++ utv->codec->DecodeFrame(utv->output, avpkt->data, true); ++ ++ /* Set the output data depending on the colorspace */ ++ switch (avctx->pix_fmt) { ++ case PIX_FMT_YUV420P: ++ pic->linesize[0] = w; ++ pic->linesize[1] = pic->linesize[2] = w / 2; ++ pic->data[0] = utv->output; ++ pic->data[2] = utv->output + (w * h); ++ pic->data[1] = pic->data[2] + (w * h / 4); ++ break; ++ case PIX_FMT_YUYV422: ++ pic->linesize[0] = w * 2; ++ pic->data[0] = utv->output; ++ break; ++ case PIX_FMT_BGR24: ++ case PIX_FMT_RGB32: ++ /* Make the linesize negative, since Ut Video uses bottom-up BGR */ ++ pic->linesize[0] = -1 * w * (avctx->pix_fmt == PIX_FMT_BGR24 ? 3 : 4); ++ pic->data[0] = utv->output + utv->buf_size + pic->linesize[0]; ++ break; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int utvideo_decode_close(AVCodecContext *avctx) ++{ ++ UtVideoContext *utv = (UtVideoContext *)avctx->priv_data; ++ ++ /* Free output */ ++ av_freep(&avctx->coded_frame); ++ av_freep(&utv->output); ++ ++ /* Finish decoding and clean up the instance */ ++ utv->codec->DecodeEnd(); ++ CCodec::DeleteInstance(utv->codec); ++ ++ return 0; ++} ++ ++AVCodec ff_libutvideo_decoder = { ++ "libutvideo", ++ AVMEDIA_TYPE_VIDEO, ++ CODEC_ID_UTVIDEO, ++ sizeof(UtVideoContext), ++ utvideo_decode_init, ++ NULL, ++ utvideo_decode_close, ++ utvideo_decode_frame, ++ NULL, ++ NULL, ++ NULL, ++ NULL, ++ NULL, ++ NULL_IF_CONFIG_SMALL("Ut Video"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvo-aacenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvo-aacenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvo-aacenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvo-aacenc.c 2012-05-14 14:08:53.936331971 +0200 +@@ -0,0 +1,129 @@ ++/* ++ * AAC encoder wrapper ++ * Copyright (c) 2010 Martin Storsjo ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++ ++#include "avcodec.h" ++#include "mpeg4audio.h" ++ ++typedef struct AACContext { ++ VO_AUDIO_CODECAPI codec_api; ++ VO_HANDLE handle; ++ VO_MEM_OPERATOR mem_operator; ++ VO_CODEC_INIT_USERDATA user_data; ++} AACContext; ++ ++static av_cold int aac_encode_init(AVCodecContext *avctx) ++{ ++ AACContext *s = avctx->priv_data; ++ AACENC_PARAM params = { 0 }; ++ int index; ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ avctx->frame_size = 1024; ++ ++ voGetAACEncAPI(&s->codec_api); ++ ++ s->mem_operator.Alloc = cmnMemAlloc; ++ s->mem_operator.Copy = cmnMemCopy; ++ s->mem_operator.Free = cmnMemFree; ++ s->mem_operator.Set = cmnMemSet; ++ s->mem_operator.Check = cmnMemCheck; ++ s->user_data.memflag = VO_IMF_USERMEMOPERATOR; ++ s->user_data.memData = &s->mem_operator; ++ s->codec_api.Init(&s->handle, VO_AUDIO_CodingAAC, &s->user_data); ++ ++ params.sampleRate = avctx->sample_rate; ++ params.bitRate = avctx->bit_rate; ++ params.nChannels = avctx->channels; ++ params.adtsUsed = !(avctx->flags & CODEC_FLAG_GLOBAL_HEADER); ++ if (s->codec_api.SetParam(s->handle, VO_PID_AAC_ENCPARAM, ¶ms) ++ != VO_ERR_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "Unable to set encoding parameters\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ for (index = 0; index < 16; index++) ++ if (avctx->sample_rate == avpriv_mpeg4audio_sample_rates[index]) ++ break; ++ if (index == 16) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported sample rate %d\n", ++ avctx->sample_rate); ++ return AVERROR(ENOSYS); ++ } ++ if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) { ++ avctx->extradata_size = 2; ++ avctx->extradata = av_mallocz(avctx->extradata_size + ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!avctx->extradata) ++ return AVERROR(ENOMEM); ++ ++ avctx->extradata[0] = 0x02 << 3 | index >> 1; ++ avctx->extradata[1] = (index & 0x01) << 7 | avctx->channels << 3; ++ } ++ return 0; ++} ++ ++static int aac_encode_close(AVCodecContext *avctx) ++{ ++ AACContext *s = avctx->priv_data; ++ ++ s->codec_api.Uninit(s->handle); ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++static int aac_encode_frame(AVCodecContext *avctx, ++ unsigned char *frame/*out*/, ++ int buf_size, void *data/*in*/) ++{ ++ AACContext *s = avctx->priv_data; ++ VO_CODECBUFFER input = { 0 }, output = { 0 }; ++ VO_AUDIO_OUTPUTINFO output_info = { { 0 } }; ++ ++ input.Buffer = data; ++ input.Length = 2 * avctx->channels * avctx->frame_size; ++ output.Buffer = frame; ++ output.Length = buf_size; ++ ++ s->codec_api.SetInputData(s->handle, &input); ++ if (s->codec_api.GetOutputData(s->handle, &output, &output_info) ++ != VO_ERR_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "Unable to encode frame\n"); ++ return AVERROR(EINVAL); ++ } ++ return output.Length; ++} ++ ++AVCodec ff_libvo_aacenc_encoder = { ++ .name = "libvo_aacenc", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AAC, ++ .priv_data_size = sizeof(AACContext), ++ .init = aac_encode_init, ++ .encode = aac_encode_frame, ++ .close = aac_encode_close, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn AAC"), ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvo-amrwbenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvo-amrwbenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvo-amrwbenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvo-amrwbenc.c 2012-05-14 14:08:53.936331971 +0200 +@@ -0,0 +1,133 @@ ++/* ++ * AMR Audio encoder stub ++ * Copyright (c) 2003 the ffmpeg project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "avcodec.h" ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++ ++typedef struct AMRWBContext { ++ AVClass *av_class; ++ void *state; ++ int mode; ++ int last_bitrate; ++ int allow_dtx; ++} AMRWBContext; ++ ++static const AVOption options[] = { ++ { "dtx", "Allow DTX (generate comfort noise)", offsetof(AMRWBContext, allow_dtx), AV_OPT_TYPE_INT, { 0 }, 0, 1, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, ++ { NULL } ++}; ++ ++static const AVClass class = { ++ "libvo_amrwbenc", av_default_item_name, options, LIBAVUTIL_VERSION_INT ++}; ++ ++static int get_wb_bitrate_mode(int bitrate, void *log_ctx) ++{ ++ /* make the correspondance between bitrate and mode */ ++ static const int rates[] = { 6600, 8850, 12650, 14250, 15850, 18250, ++ 19850, 23050, 23850 }; ++ int i, best = -1, min_diff = 0; ++ char log_buf[200]; ++ ++ for (i = 0; i < 9; i++) { ++ if (rates[i] == bitrate) ++ return i; ++ if (best < 0 || abs(rates[i] - bitrate) < min_diff) { ++ best = i; ++ min_diff = abs(rates[i] - bitrate); ++ } ++ } ++ /* no bitrate matching exactly, log a warning */ ++ snprintf(log_buf, sizeof(log_buf), "bitrate not supported: use one of "); ++ for (i = 0; i < 9; i++) ++ av_strlcatf(log_buf, sizeof(log_buf), "%.2fk, ", rates[i] / 1000.f); ++ av_strlcatf(log_buf, sizeof(log_buf), "using %.2fk", rates[best] / 1000.f); ++ av_log(log_ctx, AV_LOG_WARNING, "%s\n", log_buf); ++ ++ return best; ++} ++ ++static av_cold int amr_wb_encode_init(AVCodecContext *avctx) ++{ ++ AMRWBContext *s = avctx->priv_data; ++ ++ if (avctx->sample_rate != 16000) { ++ av_log(avctx, AV_LOG_ERROR, "Only 16000Hz sample rate supported\n"); ++ return AVERROR(ENOSYS); ++ } ++ ++ if (avctx->channels != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Only mono supported\n"); ++ return AVERROR(ENOSYS); ++ } ++ ++ s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx); ++ s->last_bitrate = avctx->bit_rate; ++ ++ avctx->frame_size = 320; ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ s->state = E_IF_init(); ++ ++ return 0; ++} ++ ++static int amr_wb_encode_close(AVCodecContext *avctx) ++{ ++ AMRWBContext *s = avctx->priv_data; ++ ++ E_IF_exit(s->state); ++ av_freep(&avctx->coded_frame); ++ return 0; ++} ++ ++static int amr_wb_encode_frame(AVCodecContext *avctx, ++ unsigned char *frame/*out*/, ++ int buf_size, void *data/*in*/) ++{ ++ AMRWBContext *s = avctx->priv_data; ++ int size; ++ ++ if (s->last_bitrate != avctx->bit_rate) { ++ s->mode = get_wb_bitrate_mode(avctx->bit_rate, avctx); ++ s->last_bitrate = avctx->bit_rate; ++ } ++ size = E_IF_encode(s->state, s->mode, data, frame, s->allow_dtx); ++ return size; ++} ++ ++AVCodec ff_libvo_amrwbenc_encoder = { ++ .name = "libvo_amrwbenc", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_AMR_WB, ++ .priv_data_size = sizeof(AMRWBContext), ++ .init = amr_wb_encode_init, ++ .encode = amr_wb_encode_frame, ++ .close = amr_wb_encode_close, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Android VisualOn Adaptive Multi-Rate " ++ "(AMR) Wide-Band"), ++ .priv_class = &class, ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvorbis.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvorbis.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvorbis.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvorbis.c 2012-05-14 14:08:53.938332011 +0200 +@@ -30,105 +30,164 @@ + #include "avcodec.h" + #include "bytestream.h" + #include "vorbis.h" ++#include "libavutil/mathematics.h" + + #undef NDEBUG + #include + + #define OGGVORBIS_FRAME_SIZE 64 + +-#define BUFFER_SIZE (1024*64) ++#define BUFFER_SIZE (1024 * 64) + + typedef struct OggVorbisContext { + AVClass *av_class; +- vorbis_info vi ; +- vorbis_dsp_state vd ; +- vorbis_block vb ; ++ vorbis_info vi; ++ vorbis_dsp_state vd; ++ vorbis_block vb; + uint8_t buffer[BUFFER_SIZE]; + int buffer_index; + int eof; + + /* decoder */ +- vorbis_comment vc ; ++ vorbis_comment vc; + ogg_packet op; + + double iblock; +-} OggVorbisContext ; ++} OggVorbisContext; + +-static const AVOption options[]={ +-{"iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), FF_OPT_TYPE_DOUBLE, 0, -15, 0, AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_ENCODING_PARAM}, +-{NULL} ++static const AVOption options[] = { ++ { "iblock", "Sets the impulse block bias", offsetof(OggVorbisContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, ++ { NULL } + }; + static const AVClass class = { "libvorbis", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; + +-static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) { +- OggVorbisContext *context = avccontext->priv_data ; ++static const char * error(int oggerr, int *averr) ++{ ++ switch (oggerr) { ++ case OV_EFAULT: *averr = AVERROR(EFAULT); return "internal error"; ++ case OV_EIMPL: *averr = AVERROR(EINVAL); return "not supported"; ++ case OV_EINVAL: *averr = AVERROR(EINVAL); return "invalid request"; ++ default: *averr = AVERROR(EINVAL); return "unknown error"; ++ } ++} ++ ++static av_cold int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) ++{ ++ OggVorbisContext *context = avccontext->priv_data; + double cfreq; ++ int r; + +- if(avccontext->flags & CODEC_FLAG_QSCALE) { ++ if (avccontext->flags & CODEC_FLAG_QSCALE) { + /* variable bitrate */ +- if(vorbis_encode_setup_vbr(vi, avccontext->channels, +- avccontext->sample_rate, +- avccontext->global_quality / (float)FF_QP2LAMBDA / 10.0)) +- return -1; ++ float quality = avccontext->global_quality / (float)FF_QP2LAMBDA; ++ r = vorbis_encode_setup_vbr(vi, avccontext->channels, ++ avccontext->sample_rate, ++ quality / 10.0); ++ if (r) { ++ av_log(avccontext, AV_LOG_ERROR, ++ "Unable to set quality to %g: %s\n", quality, error(r, &r)); ++ return r; ++ } + } else { + int minrate = avccontext->rc_min_rate > 0 ? avccontext->rc_min_rate : -1; + int maxrate = avccontext->rc_min_rate > 0 ? avccontext->rc_max_rate : -1; + + /* constant bitrate */ +- if(vorbis_encode_setup_managed(vi, avccontext->channels, +- avccontext->sample_rate, minrate, avccontext->bit_rate, maxrate)) +- return -1; ++ r = vorbis_encode_setup_managed(vi, avccontext->channels, ++ avccontext->sample_rate, minrate, ++ avccontext->bit_rate, maxrate); ++ if (r) { ++ av_log(avccontext, AV_LOG_ERROR, ++ "Unable to set CBR to %d: %s\n", avccontext->bit_rate, ++ error(r, &r)); ++ return r; ++ } + + /* variable bitrate by estimate, disable slow rate management */ +- if(minrate == -1 && maxrate == -1) +- if(vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) +- return -1; ++ if (minrate == -1 && maxrate == -1) ++ if (vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL)) ++ return AVERROR(EINVAL); /* should not happen */ + } + + /* cutoff frequency */ +- if(avccontext->cutoff > 0) { ++ if (avccontext->cutoff > 0) { + cfreq = avccontext->cutoff / 1000.0; +- if(vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) +- return -1; ++ if (vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq)) ++ return AVERROR(EINVAL); /* should not happen */ + } + +- if(context->iblock){ ++ if (context->iblock) { + vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &context->iblock); + } + ++ if (avccontext->channels == 3 && ++ avccontext->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || ++ avccontext->channels == 4 && ++ avccontext->channel_layout != AV_CH_LAYOUT_2_2 && ++ avccontext->channel_layout != AV_CH_LAYOUT_QUAD || ++ avccontext->channels == 5 && ++ avccontext->channel_layout != AV_CH_LAYOUT_5POINT0 && ++ avccontext->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || ++ avccontext->channels == 6 && ++ avccontext->channel_layout != AV_CH_LAYOUT_5POINT1 && ++ avccontext->channel_layout != AV_CH_LAYOUT_5POINT1_BACK || ++ avccontext->channels == 7 && ++ avccontext->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) || ++ avccontext->channels == 8 && ++ avccontext->channel_layout != AV_CH_LAYOUT_7POINT1) { ++ if (avccontext->channel_layout) { ++ char name[32]; ++ av_get_channel_layout_string(name, sizeof(name), avccontext->channels, ++ avccontext->channel_layout); ++ av_log(avccontext, AV_LOG_ERROR, "%s not supported by Vorbis: " ++ "output stream will have incorrect " ++ "channel layout.\n", name); ++ } else { ++ av_log(avccontext, AV_LOG_WARNING, "No channel layout specified. The encoder " ++ "will use Vorbis channel layout for " ++ "%d channels.\n", avccontext->channels); ++ } ++ } ++ + return vorbis_encode_setup_init(vi); + } + + /* How many bytes are needed for a buffer of length 'l' */ +-static int xiph_len(int l) { return (1 + l / 255 + l); } ++static int xiph_len(int l) ++{ ++ return 1 + l / 255 + l; ++} + +-static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) { +- OggVorbisContext *context = avccontext->priv_data ; ++static av_cold int oggvorbis_encode_init(AVCodecContext *avccontext) ++{ ++ OggVorbisContext *context = avccontext->priv_data; + ogg_packet header, header_comm, header_code; + uint8_t *p; + unsigned int offset; ++ int r; + +- vorbis_info_init(&context->vi) ; +- if(oggvorbis_init_encoder(&context->vi, avccontext) < 0) { +- av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init: init_encoder failed\n") ; +- return -1 ; ++ vorbis_info_init(&context->vi); ++ r = oggvorbis_init_encoder(&context->vi, avccontext); ++ if (r < 0) { ++ av_log(avccontext, AV_LOG_ERROR, "oggvorbis_encode_init failed\n"); ++ return r; + } +- vorbis_analysis_init(&context->vd, &context->vi) ; +- vorbis_block_init(&context->vd, &context->vb) ; ++ vorbis_analysis_init(&context->vd, &context->vi); ++ vorbis_block_init(&context->vd, &context->vb); + + vorbis_comment_init(&context->vc); +- vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; ++ vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT); + + vorbis_analysis_headerout(&context->vd, &context->vc, &header, +- &header_comm, &header_code); ++ &header_comm, &header_code); + +- avccontext->extradata_size= ++ avccontext->extradata_size = + 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + + header_code.bytes; + p = avccontext->extradata = +- av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- p[0] = 2; +- offset = 1; ++ av_malloc(avccontext->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ p[0] = 2; ++ offset = 1; + offset += av_xiphlacing(&p[offset], header.bytes); + offset += av_xiphlacing(&p[offset], header_comm.bytes); + memcpy(&p[offset], header.packet, header.bytes); +@@ -139,60 +198,61 @@ + offset += header_code.bytes; + assert(offset == avccontext->extradata_size); + +-/* vorbis_block_clear(&context->vb); ++#if 0 ++ vorbis_block_clear(&context->vb); + vorbis_dsp_clear(&context->vd); +- vorbis_info_clear(&context->vi);*/ ++ vorbis_info_clear(&context->vi); ++#endif + vorbis_comment_clear(&context->vc); + +- avccontext->frame_size = OGGVORBIS_FRAME_SIZE ; ++ avccontext->frame_size = OGGVORBIS_FRAME_SIZE; + +- avccontext->coded_frame= avcodec_alloc_frame(); +- avccontext->coded_frame->key_frame= 1; ++ avccontext->coded_frame = avcodec_alloc_frame(); ++ avccontext->coded_frame->key_frame = 1; + +- return 0 ; ++ return 0; + } + +- + static int oggvorbis_encode_frame(AVCodecContext *avccontext, + unsigned char *packets, +- int buf_size, void *data) ++ int buf_size, void *data) + { +- OggVorbisContext *context = avccontext->priv_data ; +- ogg_packet op ; +- signed short *audio = data ; ++ OggVorbisContext *context = avccontext->priv_data; ++ ogg_packet op; ++ signed short *audio = data; + int l; + +- if(data) { ++ if (data) { + const int samples = avccontext->frame_size; +- float **buffer ; ++ float **buffer; + int c, channels = context->vi.channels; + +- buffer = vorbis_analysis_buffer(&context->vd, samples) ; ++ buffer = vorbis_analysis_buffer(&context->vd, samples); + for (c = 0; c < channels; c++) { + int co = (channels > 8) ? c : +- ff_vorbis_encoding_channel_layout_offsets[channels-1][c]; +- for(l = 0 ; l < samples ; l++) +- buffer[c][l]=audio[l*channels+co]/32768.f; ++ ff_vorbis_encoding_channel_layout_offsets[channels - 1][c]; ++ for (l = 0; l < samples; l++) ++ buffer[c][l] = audio[l * channels + co] / 32768.f; + } +- vorbis_analysis_wrote(&context->vd, samples) ; ++ vorbis_analysis_wrote(&context->vd, samples); + } else { +- if(!context->eof) +- vorbis_analysis_wrote(&context->vd, 0) ; ++ if (!context->eof) ++ vorbis_analysis_wrote(&context->vd, 0); + context->eof = 1; + } + +- while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { ++ while (vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { + vorbis_analysis(&context->vb, NULL); +- vorbis_bitrate_addblock(&context->vb) ; ++ vorbis_bitrate_addblock(&context->vb); + +- while(vorbis_bitrate_flushpacket(&context->vd, &op)) { ++ while (vorbis_bitrate_flushpacket(&context->vd, &op)) { + /* i'd love to say the following line is a hack, but sadly it's + * not, apparently the end of stream decision is in libogg. */ +- if(op.bytes==1 && op.e_o_s) ++ if (op.bytes == 1 && op.e_o_s) + continue; + if (context->buffer_index + sizeof(ogg_packet) + op.bytes > BUFFER_SIZE) { +- av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow."); +- return -1; ++ av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n"); ++ return AVERROR(EINVAL); + } + memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); + context->buffer_index += sizeof(ogg_packet); +@@ -202,18 +262,18 @@ + } + } + +- l=0; +- if(context->buffer_index){ +- ogg_packet *op2= (ogg_packet*)context->buffer; ++ l = 0; ++ if (context->buffer_index) { ++ ogg_packet *op2 = (ogg_packet *)context->buffer; + op2->packet = context->buffer + sizeof(ogg_packet); + +- l= op2->bytes; +- avccontext->coded_frame->pts= av_rescale_q(op2->granulepos, (AVRational){1, avccontext->sample_rate}, avccontext->time_base); ++ l = op2->bytes; ++ avccontext->coded_frame->pts = av_rescale_q(op2->granulepos, (AVRational) { 1, avccontext->sample_rate }, avccontext->time_base); + //FIXME we should reorder the user supplied pts and not assume that they are spaced by 1/sample_rate + + if (l > buf_size) { +- av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow."); +- return -1; ++ av_log(avccontext, AV_LOG_ERROR, "libvorbis: buffer overflow.\n"); ++ return AVERROR(EINVAL); + } + + memcpy(packets, op2->packet, l); +@@ -225,12 +285,12 @@ + return l; + } + +- +-static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) { +- OggVorbisContext *context = avccontext->priv_data ; ++static av_cold int oggvorbis_encode_close(AVCodecContext *avccontext) ++{ ++ OggVorbisContext *context = avccontext->priv_data; + /* ogg_packet op ; */ + +- vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ ++ vorbis_analysis_wrote(&context->vd, 0); /* notify vorbisenc this is EOF */ + + vorbis_block_clear(&context->vb); + vorbis_dsp_clear(&context->vd); +@@ -239,20 +299,19 @@ + av_freep(&avccontext->coded_frame); + av_freep(&avccontext->extradata); + +- return 0 ; ++ return 0; + } + +- + AVCodec ff_libvorbis_encoder = { +- "libvorbis", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_VORBIS, +- sizeof(OggVorbisContext), +- oggvorbis_encode_init, +- oggvorbis_encode_frame, +- oggvorbis_encode_close, +- .capabilities= CODEC_CAP_DELAY, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name= NULL_IF_CONFIG_SMALL("libvorbis Vorbis"), +- .priv_class= &class, +-} ; ++ .name = "libvorbis", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_VORBIS, ++ .priv_data_size = sizeof(OggVorbisContext), ++ .init = oggvorbis_encode_init, ++ .encode = oggvorbis_encode_frame, ++ .close = oggvorbis_encode_close, ++ .capabilities = CODEC_CAP_DELAY, ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("libvorbis Vorbis"), ++ .priv_class = &class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvpxdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvpxdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvpxdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvpxdec.c 2012-05-14 14:08:53.939332032 +0200 +@@ -27,7 +27,7 @@ + #include + #include + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + typedef struct VP8DecoderContext { +@@ -112,14 +112,13 @@ + } + + AVCodec ff_libvpx_decoder = { +- "libvpx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP8, +- sizeof(VP8Context), +- vp8_init, +- NULL, /* encode */ +- vp8_free, +- vp8_decode, +- 0, /* capabilities */ +- .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), ++ .name = "libvpx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP8, ++ .priv_data_size = sizeof(VP8Context), ++ .init = vp8_init, ++ .close = vp8_free, ++ .decode = vp8_decode, ++ .capabilities = CODEC_CAP_AUTO_THREADS, ++ .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvpxenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvpxenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libvpxenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libvpxenc.c 2012-05-14 14:08:53.940332052 +0200 +@@ -29,7 +29,10 @@ + #include + + #include "avcodec.h" ++#include "internal.h" + #include "libavutil/base64.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" + + /** + * Portion of struct vpx_codec_cx_pkt from vpx_encoder.h. +@@ -47,11 +50,30 @@ + }; + + typedef struct VP8EncoderContext { ++ AVClass *class; + struct vpx_codec_ctx encoder; + struct vpx_image rawimg; + struct vpx_fixed_buf twopass_stats; +- unsigned long deadline; //i.e., RT/GOOD/BEST ++ int deadline; //i.e., RT/GOOD/BEST + struct FrameListData *coded_frame_list; ++ ++ int cpu_used; ++ /** ++ * VP8 specific flags, see VP8F_* below. ++ */ ++ int flags; ++#define VP8F_ERROR_RESILIENT 0x00000001 ///< Enable measures appropriate for streaming over lossy links ++#define VP8F_AUTO_ALT_REF 0x00000002 ///< Enable automatic alternate reference frame generation ++ ++ int auto_alt_ref; ++ ++ int arnr_max_frames; ++ int arnr_strength; ++ int arnr_type; ++ ++ int lag_in_frames; ++ int error_resilient; ++ int crf; + } VP8Context; + + /** String mappings for enum vp8e_enc_control_id */ +@@ -72,6 +94,7 @@ + [VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES", + [VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH", + [VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE", ++ [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL", + }; + + static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc) +@@ -204,7 +227,6 @@ + { + VP8Context *ctx = avctx->priv_data; + const struct vpx_codec_iface *iface = &vpx_codec_vp8_cx_algo; +- int cpuused = 3; + struct vpx_codec_enc_cfg enccfg; + int res; + +@@ -223,6 +245,14 @@ + enccfg.g_timebase.num = avctx->time_base.num; + enccfg.g_timebase.den = avctx->time_base.den; + enccfg.g_threads = avctx->thread_count; ++#if FF_API_X264_GLOBAL_OPTS ++ if(avctx->rc_lookahead >= 0) ++ enccfg.g_lag_in_frames= FFMIN(avctx->rc_lookahead, 25); //0-25, avoids init failure ++ if (ctx->lag_in_frames >= 0) ++ enccfg.g_lag_in_frames = ctx->lag_in_frames; ++#else ++ enccfg.g_lag_in_frames= ctx->lag_in_frames; ++#endif + + if (avctx->flags & CODEC_FLAG_PASS1) + enccfg.g_pass = VPX_RC_FIRST_PASS; +@@ -234,11 +264,18 @@ + if (avctx->rc_min_rate == avctx->rc_max_rate && + avctx->rc_min_rate == avctx->bit_rate) + enccfg.rc_end_usage = VPX_CBR; ++#if FF_API_X264_GLOBAL_OPTS ++ else if (avctx->crf || ctx->crf > 0) ++#else ++ else if (ctx->crf) ++#endif ++ enccfg.rc_end_usage = VPX_CQ; + enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000, + AV_ROUND_NEAR_INF); +- +- enccfg.rc_min_quantizer = avctx->qmin; +- enccfg.rc_max_quantizer = avctx->qmax; ++ if (avctx->qmin > 0) ++ enccfg.rc_min_quantizer = avctx->qmin; ++ if (avctx->qmax > 0) ++ enccfg.rc_max_quantizer = avctx->qmax; + enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold; + + //0-100 (0 => CBR, 100 => VBR) +@@ -256,11 +293,13 @@ + enccfg.rc_buf_initial_sz = + avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate; + enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6; ++ enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100); + + //_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO +- if (avctx->keyint_min == avctx->gop_size) ++ if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size) + enccfg.kf_min_dist = avctx->keyint_min; +- enccfg.kf_max_dist = avctx->gop_size; ++ if (avctx->gop_size >= 0) ++ enccfg.kf_max_dist = avctx->gop_size; + + if (enccfg.g_pass == VPX_RC_FIRST_PASS) + enccfg.g_lag_in_frames = 0; +@@ -291,13 +330,14 @@ + enccfg.rc_twopass_stats_in = ctx->twopass_stats; + } + +- ctx->deadline = VPX_DL_GOOD_QUALITY; + /* 0-3: For non-zero values the encoder increasingly optimizes for reduced + complexity playback on low powered devices at the expense of encode + quality. */ + if (avctx->profile != FF_PROFILE_UNKNOWN) + enccfg.g_profile = avctx->profile; + ++ enccfg.g_error_resilient = ctx->error_resilient || ctx->flags & VP8F_ERROR_RESILIENT; ++ + dump_enc_cfg(avctx, &enccfg); + /* Construct Encoder Context */ + res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, 0); +@@ -308,9 +348,30 @@ + + //codec control failures are currently treated only as warnings + av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n"); +- codecctl_int(avctx, VP8E_SET_CPUUSED, cpuused); ++ if (ctx->cpu_used != INT_MIN) ++ codecctl_int(avctx, VP8E_SET_CPUUSED, ctx->cpu_used); ++ if (ctx->flags & VP8F_AUTO_ALT_REF) ++ ctx->auto_alt_ref = 1; ++ if (ctx->auto_alt_ref >= 0) ++ codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref); ++ if (ctx->arnr_max_frames >= 0) ++ codecctl_int(avctx, VP8E_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames); ++ if (ctx->arnr_strength >= 0) ++ codecctl_int(avctx, VP8E_SET_ARNR_STRENGTH, ctx->arnr_strength); ++ if (ctx->arnr_type >= 0) ++ codecctl_int(avctx, VP8E_SET_ARNR_TYPE, ctx->arnr_type); + codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction); + codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices)); ++ codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, avctx->mb_threshold); ++#if FF_API_X264_GLOBAL_OPTS ++ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, (int)avctx->crf); ++ if (ctx->crf >= 0) ++ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf); ++#else ++ codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf); ++#endif ++ ++ av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline); + + //provide dummy value to initialize wrapper, values will be updated each _encode() + vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1, +@@ -353,9 +414,9 @@ + coded_frame->key_frame = !!(cx_frame->flags & VPX_FRAME_IS_KEY); + + if (coded_frame->key_frame) +- coded_frame->pict_type = FF_I_TYPE; ++ coded_frame->pict_type = AV_PICTURE_TYPE_I; + else +- coded_frame->pict_type = FF_P_TYPE; ++ coded_frame->pict_type = AV_PICTURE_TYPE_P; + } else { + av_log(avctx, AV_LOG_ERROR, + "Compressed frame larger than storage provided! (%zu/%d)\n", +@@ -430,8 +491,8 @@ + break; + case VPX_CODEC_STATS_PKT: { + struct vpx_fixed_buf *stats = &ctx->twopass_stats; +- stats->buf = av_realloc(stats->buf, +- stats->sz + pkt->data.twopass_stats.sz); ++ stats->buf = av_realloc_f(stats->buf, 1, ++ stats->sz + pkt->data.twopass_stats.sz); + if (!stats->buf) { + av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n"); + return AVERROR(ENOMEM); +@@ -494,16 +555,76 @@ + return coded_size; + } + ++#define OFFSET(x) offsetof(VP8Context, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE}, ++ { "auto-alt-ref", "Enable use of alternate reference " ++ "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {-1}, -1, 1, VE}, ++ { "lag-in-frames", "Number of frames to look ahead for " ++ "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE}, ++ { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE}, ++ { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE}, ++ { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {-1}, -1, INT_MAX, VE, "arnr_type"}, ++ { "backward", NULL, 0, AV_OPT_TYPE_CONST, {1}, 0, 0, VE, "arnr_type" }, ++ { "forward", NULL, 0, AV_OPT_TYPE_CONST, {2}, 0, 0, VE, "arnr_type" }, ++ { "centered", NULL, 0, AV_OPT_TYPE_CONST, {3}, 0, 0, VE, "arnr_type" }, ++ { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, ++ { "best", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, ++ { "good", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, ++ { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {VPX_DL_REALTIME}, 0, 0, VE, "quality"}, ++ { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, VE, "er"}, ++#ifdef VPX_ERROR_RESILIENT_DEFAULT ++ { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, ++ { "partitions", "The frame partitions are independently decodable " ++ "by the bool decoder, meaning that partitions can be decoded even " ++ "though earlier partitions have been lost. Note that intra predicition" ++ " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, ++#endif ++{"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.dbl = 3}, -16, 16, VE}, ++{"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.dbl = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, ++{"vp8flags", "", offsetof(VP8Context, flags), FF_OPT_TYPE_FLAGS, {.dbl = 0}, 0, UINT_MAX, VE, "flags"}, ++{"error_resilient", "enable error resilience", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, ++{"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, "flags"}, ++{"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 15, VE}, ++{"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.dbl = 3}, 0, 6, VE}, ++{"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.dbl = 3}, 1, 3, VE}, ++#if FF_API_X264_GLOBAL_OPTS ++{"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 25, VE}, ++{"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 63, VE}, ++#else ++{"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.dbl = 25}, 0, 25, VE}, ++{"crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 63, VE}, ++#endif ++{NULL} ++}; ++ ++static const AVClass class = { ++ .class_name = "libvpx encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVCodecDefault defaults[] = { ++ { "qmin", "-1" }, ++ { "qmax", "-1" }, ++ { "g", "-1" }, ++ { "keyint_min", "-1" }, ++ { NULL }, ++}; ++ + AVCodec ff_libvpx_encoder = { +- "libvpx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP8, +- sizeof(VP8Context), +- vp8_init, +- vp8_encode, +- vp8_free, +- NULL, +- CODEC_CAP_DELAY, ++ .name = "libvpx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP8, ++ .priv_data_size = sizeof(VP8Context), ++ .init = vp8_init, ++ .encode = vp8_encode, ++ .close = vp8_free, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"), ++ .priv_class = &class, ++ .defaults = defaults, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libx264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libx264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libx264.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libx264.c 2012-05-14 14:08:53.943332112 +0200 +@@ -19,20 +19,57 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/opt.h" ++#include "libavutil/pixdesc.h" + #include "avcodec.h" ++#include "internal.h" + #include ++#include + #include + #include + #include + #include + + typedef struct X264Context { ++ AVClass *class; + x264_param_t params; + x264_t *enc; + x264_picture_t pic; + uint8_t *sei; + int sei_size; + AVFrame out_pic; ++ char *preset; ++ char *tune; ++ char *profile; ++ char *level; ++ int fastfirstpass; ++ char *stats; ++ char *wpredp; ++ char *x264opts; ++ float crf; ++ float crf_max; ++ int cqp; ++ int aq_mode; ++ float aq_strength; ++ char *psy_rd; ++ int psy; ++ int rc_lookahead; ++ int weightp; ++ int weightb; ++ int ssim; ++ int intra_refresh; ++ int b_bias; ++ int b_pyramid; ++ int mixed_refs; ++ int dct8x8; ++ int fast_pskip; ++ int aud; ++ int mbtree; ++ char *deblock; ++ float cplxblur; ++ char *partitions; ++ int direct_pred; ++ int slice_max_size; + } X264Context; + + static void X264_log(void *p, int level, const char *fmt, va_list args) +@@ -60,9 +97,14 @@ + + /* Write the SEI as part of the first frame. */ + if (x4->sei_size > 0 && nnal > 0) { ++ if (x4->sei_size > size) { ++ av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n"); ++ return -1; ++ } + memcpy(p, x4->sei, x4->sei_size); + p += x4->sei_size; + x4->sei_size = 0; ++ av_freep(&x4->sei); + } + + for (i = 0; i < nnal; i++){ +@@ -73,6 +115,11 @@ + memcpy(x4->sei, nals[i].p_payload, nals[i].i_payload); + continue; + } ++ if (nals[i].i_payload > (size - (p - buf))) { ++ // return only complete nals which fit in buf ++ av_log(ctx, AV_LOG_ERROR, "Error: nal buffer is too small\n"); ++ break; ++ } + memcpy(p, nals[i].p_payload, nals[i].i_payload); + p += nals[i].i_payload; + } +@@ -80,38 +127,67 @@ + return p - buf; + } + ++static int avfmt2_num_planes(int avfmt) ++{ ++ switch (avfmt) { ++ case PIX_FMT_YUV420P: ++ case PIX_FMT_YUVJ420P: ++ case PIX_FMT_YUV420P9: ++ case PIX_FMT_YUV420P10: ++ case PIX_FMT_YUV444P: ++ return 3; ++ ++ case PIX_FMT_BGR24: ++ case PIX_FMT_RGB24: ++ return 1; ++ ++ default: ++ return 3; ++ } ++} ++ + static int X264_frame(AVCodecContext *ctx, uint8_t *buf, +- int bufsize, void *data) ++ int orig_bufsize, void *data) + { + X264Context *x4 = ctx->priv_data; + AVFrame *frame = data; + x264_nal_t *nal; + int nnal, i; + x264_picture_t pic_out; ++ int bufsize; + + x264_picture_init( &x4->pic ); +- x4->pic.img.i_csp = X264_CSP_I420; +- x4->pic.img.i_plane = 3; ++ x4->pic.img.i_csp = x4->params.i_csp; ++ if (x264_bit_depth > 8) ++ x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH; ++ x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt); + + if (frame) { +- for (i = 0; i < 3; i++) { ++ for (i = 0; i < x4->pic.img.i_plane; i++) { + x4->pic.img.plane[i] = frame->data[i]; + x4->pic.img.i_stride[i] = frame->linesize[i]; + } + + x4->pic.i_pts = frame->pts; + x4->pic.i_type = +- frame->pict_type == FF_I_TYPE ? X264_TYPE_KEYFRAME : +- frame->pict_type == FF_P_TYPE ? X264_TYPE_P : +- frame->pict_type == FF_B_TYPE ? X264_TYPE_B : ++ frame->pict_type == AV_PICTURE_TYPE_I ? X264_TYPE_KEYFRAME : ++ frame->pict_type == AV_PICTURE_TYPE_P ? X264_TYPE_P : ++ frame->pict_type == AV_PICTURE_TYPE_B ? X264_TYPE_B : + X264_TYPE_AUTO; + if (x4->params.b_tff != frame->top_field_first) { + x4->params.b_tff = frame->top_field_first; + x264_encoder_reconfig(x4->enc, &x4->params); + } ++ if (x4->params.vui.i_sar_height != ctx->sample_aspect_ratio.den ++ || x4->params.vui.i_sar_width != ctx->sample_aspect_ratio.num) { ++ x4->params.vui.i_sar_height = ctx->sample_aspect_ratio.den; ++ x4->params.vui.i_sar_width = ctx->sample_aspect_ratio.num; ++ x264_encoder_reconfig(x4->enc, &x4->params); ++ } + } + + do { ++ bufsize = orig_bufsize; + if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0) + return -1; + +@@ -126,19 +202,20 @@ + switch (pic_out.i_type) { + case X264_TYPE_IDR: + case X264_TYPE_I: +- x4->out_pic.pict_type = FF_I_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_I; + break; + case X264_TYPE_P: +- x4->out_pic.pict_type = FF_P_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_P; + break; + case X264_TYPE_B: + case X264_TYPE_BREF: +- x4->out_pic.pict_type = FF_B_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_B; + break; + } + + x4->out_pic.key_frame = pic_out.b_keyframe; +- x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; ++ if (bufsize) ++ x4->out_pic.quality = (pic_out.i_qpplus1 - 1) * FF_QP2LAMBDA; + + return bufsize; + } +@@ -156,25 +233,88 @@ + return 0; + } + ++#define OPT_STR(opt, param) \ ++ do { \ ++ int ret; \ ++ if (param && (ret = x264_param_parse(&x4->params, opt, param)) < 0) { \ ++ if(ret == X264_PARAM_BAD_NAME) \ ++ av_log(avctx, AV_LOG_ERROR, \ ++ "bad option '%s': '%s'\n", opt, param); \ ++ else \ ++ av_log(avctx, AV_LOG_ERROR, \ ++ "bad value for '%s': '%s'\n", opt, param); \ ++ return -1; \ ++ } \ ++ } while (0) ++ ++static int convert_pix_fmt(enum PixelFormat pix_fmt) ++{ ++ switch (pix_fmt) { ++ case PIX_FMT_YUV420P: ++ case PIX_FMT_YUVJ420P: ++ case PIX_FMT_YUV420P9: ++ case PIX_FMT_YUV420P10: return X264_CSP_I420; ++ case PIX_FMT_YUV422P: ++ case PIX_FMT_YUV422P10: return X264_CSP_I422; ++ case PIX_FMT_YUV444P: ++ case PIX_FMT_YUV444P9: ++ case PIX_FMT_YUV444P10: return X264_CSP_I444; ++#ifdef X264_CSP_BGR ++ case PIX_FMT_BGR24: ++ return X264_CSP_BGR; ++ ++ case PIX_FMT_RGB24: ++ return X264_CSP_RGB; ++#endif ++ }; ++ return 0; ++} ++ ++#define PARSE_X264_OPT(name, var)\ ++ if (x4->var && x264_param_parse(&x4->params, name, x4->var) < 0) {\ ++ av_log(avctx, AV_LOG_ERROR, "Error parsing option '%s' with value '%s'.\n", name, x4->var);\ ++ return AVERROR(EINVAL);\ ++ } ++ + static av_cold int X264_init(AVCodecContext *avctx) + { + X264Context *x4 = avctx->priv_data; ++ int sw,sh; + +- x4->sei_size = 0; + x264_param_default(&x4->params); + ++ x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; ++ ++ x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); ++ x4->params.rc.f_pb_factor = avctx->b_quant_factor; ++ x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; ++ if (x4->preset || x4->tune) ++ if (x264_param_default_preset(&x4->params, x4->preset, x4->tune) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Error setting preset/tune %s/%s.\n", x4->preset, x4->tune); ++ return AVERROR(EINVAL); ++ } ++ ++ if (avctx->level > 0) ++ x4->params.i_level_idc = avctx->level; ++ + x4->params.pf_log = X264_log; + x4->params.p_log_private = avctx; ++ x4->params.i_log_level = X264_LOG_DEBUG; ++ x4->params.i_csp = convert_pix_fmt(avctx->pix_fmt); ++ ++ OPT_STR("weightp", x4->wpredp); + +- x4->params.i_keyint_max = avctx->gop_size; +- x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH; +- x4->params.rc.i_bitrate = avctx->bit_rate / 1000; ++ if (avctx->bit_rate) { ++ x4->params.rc.i_bitrate = avctx->bit_rate / 1000; ++ x4->params.rc.i_rc_method = X264_RC_ABR; ++ } + x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; + x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; + x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1; + if (avctx->flags & CODEC_FLAG_PASS2) { + x4->params.rc.b_stat_read = 1; + } else { ++#if FF_API_X264_GLOBAL_OPTS + if (avctx->crf) { + x4->params.rc.i_rc_method = X264_RC_CRF; + x4->params.rc.f_rf_constant = avctx->crf; +@@ -183,48 +323,66 @@ + x4->params.rc.i_rc_method = X264_RC_CQP; + x4->params.rc.i_qp_constant = avctx->cqp; + } +- } ++#endif + +- // if neither crf nor cqp modes are selected we have to enable the RC +- // we do it this way because we cannot check if the bitrate has been set +- if (!(avctx->crf || (avctx->cqp > -1))) +- x4->params.rc.i_rc_method = X264_RC_ABR; ++ if (x4->crf >= 0) { ++ x4->params.rc.i_rc_method = X264_RC_CRF; ++ x4->params.rc.f_rf_constant = x4->crf; ++ } else if (x4->cqp >= 0) { ++ x4->params.rc.i_rc_method = X264_RC_CQP; ++ x4->params.rc.i_qp_constant = x4->cqp; ++ } + +- x4->params.i_bframe = avctx->max_b_frames; +- x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; +- x4->params.i_bframe_adaptive = avctx->b_frame_strategy; +- x4->params.i_bframe_bias = avctx->bframebias; +- x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE; +- avctx->has_b_frames = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? 2 : !!avctx->max_b_frames; +- +- x4->params.i_keyint_min = avctx->keyint_min; +- if (x4->params.i_keyint_min > x4->params.i_keyint_max) +- x4->params.i_keyint_min = x4->params.i_keyint_max; ++ if (x4->crf_max >= 0) ++ x4->params.rc.f_rf_constant_max = x4->crf_max; ++ } + +- x4->params.i_scenecut_threshold = avctx->scenechange_threshold; ++ OPT_STR("stats", x4->stats); + +- x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; +- x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; +- x4->params.i_deblocking_filter_beta = avctx->deblockbeta; ++ if (avctx->rc_buffer_size && avctx->rc_initial_buffer_occupancy && ++ (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { ++ x4->params.rc.f_vbv_buffer_init = ++ (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; ++ } + +- x4->params.rc.i_qp_min = avctx->qmin; +- x4->params.rc.i_qp_max = avctx->qmax; +- x4->params.rc.i_qp_step = avctx->max_qdiff; +- +- x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ +- x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ +- x4->params.rc.f_complexity_blur = avctx->complexityblur; +- +- x4->params.i_frame_reference = avctx->refs; +- +- x4->params.i_width = avctx->width; +- x4->params.i_height = avctx->height; +- x4->params.vui.i_sar_width = avctx->sample_aspect_ratio.num; +- x4->params.vui.i_sar_height = avctx->sample_aspect_ratio.den; +- x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den; +- x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num; ++ OPT_STR("level", x4->level); ++ ++ if(x4->x264opts){ ++ const char *p= x4->x264opts; ++ while(p){ ++ char param[256]={0}, val[256]={0}; ++ if(sscanf(p, "%255[^:=]=%255[^:]", param, val) == 1){ ++ OPT_STR(param, "1"); ++ }else ++ OPT_STR(param, val); ++ p= strchr(p, ':'); ++ p+=!!p; ++ } ++ } + +- x4->params.analyse.inter = 0; ++#if FF_API_X264_GLOBAL_OPTS ++ if (avctx->aq_mode >= 0) ++ x4->params.rc.i_aq_mode = avctx->aq_mode; ++ if (avctx->aq_strength >= 0) ++ x4->params.rc.f_aq_strength = avctx->aq_strength; ++ if (avctx->psy_rd >= 0) ++ x4->params.analyse.f_psy_rd = avctx->psy_rd; ++ if (avctx->psy_trellis >= 0) ++ x4->params.analyse.f_psy_trellis = avctx->psy_trellis; ++ if (avctx->rc_lookahead >= 0) ++ x4->params.rc.i_lookahead = avctx->rc_lookahead; ++ if (avctx->weighted_p_pred >= 0) ++ x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred; ++ if (avctx->bframebias) ++ x4->params.i_bframe_bias = avctx->bframebias; ++ if (avctx->deblockalpha) ++ x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; ++ if (avctx->deblockbeta) ++ x4->params.i_deblocking_filter_beta = avctx->deblockbeta; ++ if (avctx->complexityblur >= 0) ++ x4->params.rc.f_complexity_blur = avctx->complexityblur; ++ if (avctx->directpred >= 0) ++ x4->params.analyse.i_direct_mv_pred = avctx->directpred; + if (avctx->partitions) { + if (avctx->partitions & X264_PART_I4X4) + x4->params.analyse.inter |= X264_ANALYSE_I4x4; +@@ -237,11 +395,19 @@ + if (avctx->partitions & X264_PART_B8X8) + x4->params.analyse.inter |= X264_ANALYSE_BSUB16x16; + } +- +- x4->params.analyse.i_direct_mv_pred = avctx->directpred; +- +- x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; +- x4->params.analyse.i_weighted_pred = avctx->weighted_p_pred; ++ if (avctx->flags2) { ++ x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM; ++ x4->params.b_intra_refresh = avctx->flags2 & CODEC_FLAG2_INTRA_REFRESH; ++ x4->params.i_bframe_pyramid = avctx->flags2 & CODEC_FLAG2_BPYRAMID ? X264_B_PYRAMID_NORMAL : X264_B_PYRAMID_NONE; ++ x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; ++ x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; ++ x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT; ++ x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; ++ x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; ++ x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; ++ x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); ++ } ++#endif + + if (avctx->me_method == ME_EPZS) + x4->params.analyse.i_me_method = X264_ME_DIA; +@@ -253,52 +419,110 @@ + x4->params.analyse.i_me_method = X264_ME_ESA; + else if (avctx->me_method == ME_TESA) + x4->params.analyse.i_me_method = X264_ME_TESA; +- else x4->params.analyse.i_me_method = X264_ME_HEX; +- +- x4->params.rc.i_aq_mode = avctx->aq_mode; +- x4->params.rc.f_aq_strength = avctx->aq_strength; +- x4->params.rc.i_lookahead = avctx->rc_lookahead; +- +- x4->params.analyse.b_psy = avctx->flags2 & CODEC_FLAG2_PSY; +- x4->params.analyse.f_psy_rd = avctx->psy_rd; +- x4->params.analyse.f_psy_trellis = avctx->psy_trellis; +- +- x4->params.analyse.i_me_range = avctx->me_range; +- x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; +- +- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; +- x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; +- x4->params.analyse.b_transform_8x8 = avctx->flags2 & CODEC_FLAG2_8X8DCT; +- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; +- +- x4->params.analyse.i_trellis = avctx->trellis; +- x4->params.analyse.i_noise_reduction = avctx->noise_reduction; +- +- if (avctx->level > 0) +- x4->params.i_level_idc = avctx->level; + +- if ((avctx->rc_buffer_size != 0) && +- (avctx->rc_initial_buffer_occupancy <= avctx->rc_buffer_size)) { +- x4->params.rc.f_vbv_buffer_init = +- (float)avctx->rc_initial_buffer_occupancy / avctx->rc_buffer_size; +- } else +- x4->params.rc.f_vbv_buffer_init = 0.9; ++ if (avctx->gop_size >= 0) ++ x4->params.i_keyint_max = avctx->gop_size; ++ if (avctx->max_b_frames >= 0) ++ x4->params.i_bframe = avctx->max_b_frames; ++ if (avctx->scenechange_threshold >= 0) ++ x4->params.i_scenecut_threshold = avctx->scenechange_threshold; ++ if (avctx->qmin >= 0) ++ x4->params.rc.i_qp_min = avctx->qmin; ++ if (avctx->qmax >= 0) ++ x4->params.rc.i_qp_max = avctx->qmax; ++ if (avctx->max_qdiff >= 0) ++ x4->params.rc.i_qp_step = avctx->max_qdiff; ++ if (avctx->qblur >= 0) ++ x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ ++ if (avctx->qcompress >= 0) ++ x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ ++ if (avctx->refs >= 0) ++ x4->params.i_frame_reference = avctx->refs; ++ if (avctx->trellis >= 0) ++ x4->params.analyse.i_trellis = avctx->trellis; ++ if (avctx->me_range >= 0) ++ x4->params.analyse.i_me_range = avctx->me_range; ++ if (avctx->noise_reduction >= 0) ++ x4->params.analyse.i_noise_reduction = avctx->noise_reduction; ++ if (avctx->me_subpel_quality >= 0) ++ x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; ++ if (avctx->b_frame_strategy >= 0) ++ x4->params.i_bframe_adaptive = avctx->b_frame_strategy; ++ if (avctx->keyint_min >= 0) ++ x4->params.i_keyint_min = avctx->keyint_min; ++ if (avctx->coder_type >= 0) ++ x4->params.b_cabac = avctx->coder_type == FF_CODER_TYPE_AC; ++ if (avctx->me_cmp >= 0) ++ x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; ++ ++ if (x4->aq_mode >= 0) ++ x4->params.rc.i_aq_mode = x4->aq_mode; ++ if (x4->aq_strength >= 0) ++ x4->params.rc.f_aq_strength = x4->aq_strength; ++ PARSE_X264_OPT("psy-rd", psy_rd); ++ PARSE_X264_OPT("deblock", deblock); ++ PARSE_X264_OPT("partitions", partitions); ++ PARSE_X264_OPT("stats", stats); ++ if (x4->psy >= 0) ++ x4->params.analyse.b_psy = x4->psy; ++ if (x4->rc_lookahead >= 0) ++ x4->params.rc.i_lookahead = x4->rc_lookahead; ++ if (x4->weightp >= 0) ++ x4->params.analyse.i_weighted_pred = x4->weightp; ++ if (x4->weightb >= 0) ++ x4->params.analyse.b_weighted_bipred = x4->weightb; ++ if (x4->cplxblur >= 0) ++ x4->params.rc.f_complexity_blur = x4->cplxblur; ++ ++ if (x4->ssim >= 0) ++ x4->params.analyse.b_ssim = x4->ssim; ++ if (x4->intra_refresh >= 0) ++ x4->params.b_intra_refresh = x4->intra_refresh; ++ if (x4->b_bias != INT_MIN) ++ x4->params.i_bframe_bias = x4->b_bias; ++ if (x4->b_pyramid >= 0) ++ x4->params.i_bframe_pyramid = x4->b_pyramid; ++ if (x4->mixed_refs >= 0) ++ x4->params.analyse.b_mixed_references = x4->mixed_refs; ++ if (x4->dct8x8 >= 0) ++ x4->params.analyse.b_transform_8x8 = x4->dct8x8; ++ if (x4->fast_pskip >= 0) ++ x4->params.analyse.b_fast_pskip = x4->fast_pskip; ++ if (x4->aud >= 0) ++ x4->params.b_aud = x4->aud; ++ if (x4->mbtree >= 0) ++ x4->params.rc.b_mb_tree = x4->mbtree; ++ if (x4->direct_pred >= 0) ++ x4->params.analyse.i_direct_mv_pred = x4->direct_pred; ++ ++ if (x4->slice_max_size >= 0) ++ x4->params.i_slice_max_size = x4->slice_max_size; ++ ++ if (x4->fastfirstpass) ++ x264_param_apply_fastfirstpass(&x4->params); ++ ++ if (x4->profile) ++ if (x264_param_apply_profile(&x4->params, x4->profile) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Error setting profile %s.\n", x4->profile); ++ return AVERROR(EINVAL); ++ } + +- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); +- x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); +- x4->params.rc.f_pb_factor = avctx->b_quant_factor; +- x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; ++ x4->params.i_width = avctx->width; ++ x4->params.i_height = avctx->height; ++ av_reduce(&sw, &sh, avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 4096); ++ x4->params.vui.i_sar_width = sw; ++ x4->params.vui.i_sar_height = sh; ++ x4->params.i_fps_num = x4->params.i_timebase_den = avctx->time_base.den; ++ x4->params.i_fps_den = x4->params.i_timebase_num = avctx->time_base.num; + + x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR; +- x4->params.analyse.b_ssim = avctx->flags2 & CODEC_FLAG2_SSIM; +- x4->params.i_log_level = X264_LOG_DEBUG; +- +- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; + + x4->params.i_threads = avctx->thread_count; + + x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; + ++// x4->params.b_open_gop = !(avctx->flags & CODEC_FLAG_CLOSED_GOP); ++ + x4->params.i_slice_count = avctx->slices; + + x4->params.vui.b_fullrange = avctx->pix_fmt == PIX_FMT_YUVJ420P; +@@ -306,6 +530,17 @@ + if (avctx->flags & CODEC_FLAG_GLOBAL_HEADER) + x4->params.b_repeat_headers = 0; + ++ // update AVCodecContext with x264 parameters ++ avctx->has_b_frames = x4->params.i_bframe ? ++ x4->params.i_bframe_pyramid ? 2 : 1 : 0; ++ if (avctx->max_b_frames < 0) ++ avctx->max_b_frames = 0; ++ ++ avctx->bit_rate = x4->params.rc.i_bitrate*1000; ++#if FF_API_X264_GLOBAL_OPTS ++ avctx->crf = x4->params.rc.f_rf_constant; ++#endif ++ + x4->enc = x264_encoder_open(&x4->params); + if (!x4->enc) + return -1; +@@ -329,6 +564,135 @@ + return 0; + } + ++static const enum PixelFormat pix_fmts_8bit[] = { ++ PIX_FMT_YUV420P, ++ PIX_FMT_YUVJ420P, ++ PIX_FMT_YUV422P, ++ PIX_FMT_YUV444P, ++ PIX_FMT_NONE ++}; ++static const enum PixelFormat pix_fmts_9bit[] = { ++ PIX_FMT_YUV420P9, ++ PIX_FMT_YUV444P9, ++ PIX_FMT_NONE ++}; ++static const enum PixelFormat pix_fmts_10bit[] = { ++ PIX_FMT_YUV420P10, ++ PIX_FMT_YUV422P10, ++ PIX_FMT_YUV444P10, ++ PIX_FMT_NONE ++}; ++static const enum PixelFormat pix_fmts_8bit_rgb[] = { ++#ifdef X264_CSP_BGR ++ PIX_FMT_BGR24, ++ PIX_FMT_RGB24, ++#endif ++ PIX_FMT_NONE ++}; ++ ++static av_cold void X264_init_static(AVCodec *codec) ++{ ++ if (x264_bit_depth == 8) ++ codec->pix_fmts = pix_fmts_8bit; ++ else if (x264_bit_depth == 9) ++ codec->pix_fmts = pix_fmts_9bit; ++ else if (x264_bit_depth == 10) ++ codec->pix_fmts = pix_fmts_10bit; ++} ++ ++#define OFFSET(x) offsetof(X264Context, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "preset", "Set the encoding preset (cf. x264 --fullhelp)", OFFSET(preset), AV_OPT_TYPE_STRING, { .str = "medium" }, 0, 0, VE}, ++ { "tune", "Tune the encoding params (cf. x264 --fullhelp)", OFFSET(tune), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, ++ { "profile", "Set profile restrictions (cf. x264 --fullhelp) ", OFFSET(profile), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, ++ { "fastfirstpass", "Use fast settings when encoding first pass", OFFSET(fastfirstpass), AV_OPT_TYPE_INT, { 1 }, 0, 1, VE}, ++ {"level", "Specify level (as defined by Annex A)", OFFSET(level), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, ++ {"passlogfile", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, ++ {"wpredp", "Weighted prediction for P-frames", OFFSET(wpredp), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, ++ {"x264opts", "x264 options", OFFSET(x264opts), AV_OPT_TYPE_STRING, {.str=NULL}, 0, 0, VE}, ++ { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, ++ { "crf_max", "In CRF mode, prevents VBV from lowering quality beyond this point.",OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, ++ { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, ++ { "aq-mode", "AQ method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "aq_mode"}, ++ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_AQ_NONE}, INT_MIN, INT_MAX, VE, "aq_mode" }, ++ { "variance", "Variance AQ (complexity mask)", 0, AV_OPT_TYPE_CONST, {X264_AQ_VARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, ++ { "autovariance", "Auto-variance AQ (experimental)", 0, AV_OPT_TYPE_CONST, {X264_AQ_AUTOVARIANCE}, INT_MIN, INT_MAX, VE, "aq_mode" }, ++ { "aq-strength", "AQ strength. Reduces blocking and blurring in flat and textured areas.", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {-1}, -1, FLT_MAX, VE}, ++ { "psy", "Use psychovisual optimizations.", OFFSET(psy), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE }, ++ { "psy-rd", "Strength of psychovisual optimization, in : format.", OFFSET(psy_rd), AV_OPT_TYPE_STRING, {0 }, 0, 0, VE}, ++ { "rc-lookahead", "Number of frames to look ahead for frametype and ratecontrol", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, ++ { "weightb", "Weighted prediction for B-frames.", OFFSET(weightb), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE }, ++ { "weightp", "Weighted prediction analysis method.", OFFSET(weightp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "weightp" }, ++ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_NONE}, INT_MIN, INT_MAX, VE, "weightp" }, ++ { "simple", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SIMPLE}, INT_MIN, INT_MAX, VE, "weightp" }, ++ { "smart", NULL, 0, AV_OPT_TYPE_CONST, {X264_WEIGHTP_SMART}, INT_MIN, INT_MAX, VE, "weightp" }, ++ { "ssim", "Calculate and print SSIM stats.", OFFSET(ssim), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE }, ++ { "intra-refresh", "Use Periodic Intra Refresh instead of IDR frames.",OFFSET(intra_refresh),AV_OPT_TYPE_INT, {-1 }, -1, 1, VE }, ++ { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE }, ++ { "b-pyramid", "Keep some B-frames as references.", OFFSET(b_pyramid), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "b_pyramid" }, ++ { "none", NULL, 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NONE}, INT_MIN, INT_MAX, VE, "b_pyramid" }, ++ { "strict", "Strictly hierarchical pyramid", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_STRICT}, INT_MIN, INT_MAX, VE, "b_pyramid" }, ++ { "normal", "Non-strict (not Blu-ray compatible)", 0, AV_OPT_TYPE_CONST, {X264_B_PYRAMID_NORMAL}, INT_MIN, INT_MAX, VE, "b_pyramid" }, ++ { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE }, ++ { "8x8dct", "High profile 8x8 transform.", OFFSET(dct8x8), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "deblock", "Loop filter parameters, in form.", OFFSET(deblock), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, ++ { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, ++ { "partitions", "A comma-separated list of partitions to consider. " ++ "Possible values: p8x8, p4x4, b8x8, i8x8, i4x4, none, all", OFFSET(partitions), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE}, ++ { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" }, ++ { "none", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" }, ++ { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" }, ++ { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" }, ++ { "auto", NULL, 0, AV_OPT_TYPE_CONST, { X264_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" }, ++ { "slice-max-size","Limit the size of each slice in bytes", OFFSET(slice_max_size),AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, ++ { "stats", "Filename for 2 pass stats", OFFSET(stats), AV_OPT_TYPE_STRING, { 0 }, 0, 0, VE }, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "libx264", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVClass rgbclass = { ++ .class_name = "libx264rgb", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVCodecDefault x264_defaults[] = { ++ { "b", "0" }, ++ { "bf", "-1" }, ++ { "flags2", "0" }, ++ { "g", "-1" }, ++ { "qmin", "-1" }, ++ { "qmax", "-1" }, ++ { "qdiff", "-1" }, ++ { "qblur", "-1" }, ++ { "qcomp", "-1" }, ++ { "rc_lookahead", "-1" }, ++ { "refs", "-1" }, ++ { "sc_threshold", "-1" }, ++ { "trellis", "-1" }, ++ { "nr", "-1" }, ++ { "me_range", "-1" }, ++ { "me_method", "-1" }, ++ { "subq", "-1" }, ++ { "b_strategy", "-1" }, ++ { "keyint_min", "-1" }, ++ { "coder", "-1" }, ++ { "cmp", "-1" }, ++ { "threads", AV_STRINGIFY(X264_THREADS_AUTO) }, ++ { NULL }, ++}; ++ + AVCodec ff_libx264_encoder = { + .name = "libx264", + .type = AVMEDIA_TYPE_VIDEO, +@@ -337,7 +701,24 @@ + .init = X264_init, + .encode = X264_frame, + .close = X264_close, +- .capabilities = CODEC_CAP_DELAY, +- .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_NONE }, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS, + .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), ++ .priv_class = &class, ++ .defaults = x264_defaults, ++ .init_static_data = X264_init_static, ++}; ++ ++AVCodec ff_libx264rgb_encoder = { ++ .name = "libx264rgb", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .priv_data_size = sizeof(X264Context), ++ .init = X264_init, ++ .encode = X264_frame, ++ .close = X264_close, ++ .capabilities = CODEC_CAP_DELAY, ++ .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"), ++ .priv_class = &rgbclass, ++ .defaults = x264_defaults, ++ .pix_fmts = pix_fmts_8bit_rgb, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxavs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxavs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxavs.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxavs.c 2012-05-14 14:08:53.945332152 +0200 +@@ -24,8 +24,11 @@ + #include + #include + #include ++#include + #include + #include "avcodec.h" ++#include "internal.h" ++#include "libavutil/opt.h" + + #define END_OF_STREAM 0x001 + +@@ -41,6 +44,15 @@ + int sei_size; + AVFrame out_pic; + int end_of_stream; ++ float crf; ++ int cqp; ++ int b_bias; ++ float cplxblur; ++ int direct_pred; ++ int aud; ++ int fast_pskip; ++ int mbtree; ++ int mixed_refs; + } XavsContext; + + static void XAVS_log(void *p, int level, const char *fmt, va_list args) +@@ -138,14 +150,14 @@ + switch (pic_out.i_type) { + case XAVS_TYPE_IDR: + case XAVS_TYPE_I: +- x4->out_pic.pict_type = FF_I_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_I; + break; + case XAVS_TYPE_P: +- x4->out_pic.pict_type = FF_P_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_P; + break; + case XAVS_TYPE_B: + case XAVS_TYPE_BREF: +- x4->out_pic.pict_type = FF_B_TYPE; ++ x4->out_pic.pict_type = AV_PICTURE_TYPE_B; + break; + } + +@@ -181,13 +193,17 @@ + x4->params.pf_log = XAVS_log; + x4->params.p_log_private = avctx; + x4->params.i_keyint_max = avctx->gop_size; +- x4->params.rc.i_bitrate = avctx->bit_rate / 1000; ++ if (avctx->bit_rate) { ++ x4->params.rc.i_bitrate = avctx->bit_rate / 1000; ++ x4->params.rc.i_rc_method = XAVS_RC_ABR; ++ } + x4->params.rc.i_vbv_buffer_size = avctx->rc_buffer_size / 1000; + x4->params.rc.i_vbv_max_bitrate = avctx->rc_max_rate / 1000; + x4->params.rc.b_stat_write = avctx->flags & CODEC_FLAG_PASS1; + if (avctx->flags & CODEC_FLAG_PASS2) { + x4->params.rc.b_stat_read = 1; + } else { ++#if FF_API_X264_GLOBAL_OPTS + if (avctx->crf) { + x4->params.rc.i_rc_method = XAVS_RC_CRF; + x4->params.rc.f_rf_constant = avctx->crf; +@@ -195,19 +211,63 @@ + x4->params.rc.i_rc_method = XAVS_RC_CQP; + x4->params.rc.i_qp_constant = avctx->cqp; + } ++#endif ++ ++ if (x4->crf >= 0) { ++ x4->params.rc.i_rc_method = XAVS_RC_CRF; ++ x4->params.rc.f_rf_constant = x4->crf; ++ } else if (x4->cqp >= 0) { ++ x4->params.rc.i_rc_method = XAVS_RC_CQP; ++ x4->params.rc.i_qp_constant = x4->cqp; ++ } + } + +- /* if neither crf nor cqp modes are selected we have to enable the RC */ +- /* we do it this way because we cannot check if the bitrate has been set */ +- if (!(avctx->crf || (avctx->cqp > -1))) +- x4->params.rc.i_rc_method = XAVS_RC_ABR; ++#if FF_API_X264_GLOBAL_OPTS ++ if (avctx->bframebias) ++ x4->params.i_bframe_bias = avctx->bframebias; ++ if (avctx->deblockalpha) ++ x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; ++ if (avctx->deblockbeta) ++ x4->params.i_deblocking_filter_beta = avctx->deblockbeta; ++ if (avctx->complexityblur >= 0) ++ x4->params.rc.f_complexity_blur = avctx->complexityblur; ++ if (avctx->directpred >= 0) ++ x4->params.analyse.i_direct_mv_pred = avctx->directpred; ++ if (avctx->partitions) { ++ if (avctx->partitions & XAVS_PART_I8X8) ++ x4->params.analyse.inter |= XAVS_ANALYSE_I8x8; ++ if (avctx->partitions & XAVS_PART_P8X8) ++ x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16; ++ if (avctx->partitions & XAVS_PART_B8X8) ++ x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16; ++ } ++ x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); ++ x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; ++ x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; ++ x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; ++ x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; ++#endif ++ ++ if (x4->aud >= 0) ++ x4->params.b_aud = x4->aud; ++ if (x4->mbtree >= 0) ++ x4->params.rc.b_mb_tree = x4->mbtree; ++ if (x4->direct_pred >= 0) ++ x4->params.analyse.i_direct_mv_pred = x4->direct_pred; ++ if (x4->fast_pskip >= 0) ++ x4->params.analyse.b_fast_pskip = x4->fast_pskip; ++ if (x4->mixed_refs >= 0) ++ x4->params.analyse.b_mixed_references = x4->mixed_refs; ++ if (x4->b_bias != INT_MIN) ++ x4->params.i_bframe_bias = x4->b_bias; ++ if (x4->cplxblur >= 0) ++ x4->params.rc.f_complexity_blur = x4->cplxblur; + + x4->params.i_bframe = avctx->max_b_frames; + /* cabac is not included in AVS JiZhun Profile */ + x4->params.b_cabac = 0; + + x4->params.i_bframe_adaptive = avctx->b_frame_strategy; +- x4->params.i_bframe_bias = avctx->bframebias; + + avctx->has_b_frames = !!avctx->max_b_frames; + +@@ -220,8 +280,6 @@ + x4->params.i_scenecut_threshold = avctx->scenechange_threshold; + + // x4->params.b_deblocking_filter = avctx->flags & CODEC_FLAG_LOOP_FILTER; +- x4->params.i_deblocking_filter_alphac0 = avctx->deblockalpha; +- x4->params.i_deblocking_filter_beta = avctx->deblockbeta; + + x4->params.rc.i_qp_min = avctx->qmin; + x4->params.rc.i_qp_max = avctx->qmax; +@@ -229,7 +287,6 @@ + + x4->params.rc.f_qcompress = avctx->qcompress; /* 0.0 => cbr, 1.0 => constant qp */ + x4->params.rc.f_qblur = avctx->qblur; /* temporally blur quants */ +- x4->params.rc.f_complexity_blur = avctx->complexityblur; + + x4->params.i_frame_reference = avctx->refs; + +@@ -241,20 +298,6 @@ + x4->params.i_fps_num = avctx->time_base.den; + x4->params.i_fps_den = avctx->time_base.num; + x4->params.analyse.inter = XAVS_ANALYSE_I8x8 |XAVS_ANALYSE_PSUB16x16| XAVS_ANALYSE_BSUB16x16; +- if (avctx->partitions) { +- if (avctx->partitions & XAVS_PART_I8X8) +- x4->params.analyse.inter |= XAVS_ANALYSE_I8x8; +- +- if (avctx->partitions & XAVS_PART_P8X8) +- x4->params.analyse.inter |= XAVS_ANALYSE_PSUB16x16; +- +- if (avctx->partitions & XAVS_PART_B8X8) +- x4->params.analyse.inter |= XAVS_ANALYSE_BSUB16x16; +- } +- +- x4->params.analyse.i_direct_mv_pred = avctx->directpred; +- +- x4->params.analyse.b_weighted_bipred = avctx->flags2 & CODEC_FLAG2_WPRED; + + switch (avctx->me_method) { + case ME_EPZS: +@@ -279,11 +322,9 @@ + x4->params.analyse.i_me_range = avctx->me_range; + x4->params.analyse.i_subpel_refine = avctx->me_subpel_quality; + +- x4->params.analyse.b_mixed_references = avctx->flags2 & CODEC_FLAG2_MIXED_REFS; + x4->params.analyse.b_chroma_me = avctx->me_cmp & FF_CMP_CHROMA; + /* AVS P2 only enables 8x8 transform */ + x4->params.analyse.b_transform_8x8 = 1; //avctx->flags2 & CODEC_FLAG2_8X8DCT; +- x4->params.analyse.b_fast_pskip = avctx->flags2 & CODEC_FLAG2_FASTPSKIP; + + x4->params.analyse.i_trellis = avctx->trellis; + x4->params.analyse.i_noise_reduction = avctx->noise_reduction; +@@ -303,14 +344,12 @@ + + /* TAG:do we have MB tree RC method */ + /* what is the RC method we are now using? Default NO */ +- x4->params.rc.b_mb_tree = !!(avctx->flags2 & CODEC_FLAG2_MBTREE); + x4->params.rc.f_ip_factor = 1 / fabs(avctx->i_quant_factor); + x4->params.rc.f_pb_factor = avctx->b_quant_factor; + x4->params.analyse.i_chroma_qp_offset = avctx->chromaoffset; + + x4->params.analyse.b_psnr = avctx->flags & CODEC_FLAG_PSNR; + x4->params.i_log_level = XAVS_LOG_DEBUG; +- x4->params.b_aud = avctx->flags2 & CODEC_FLAG2_AUD; + x4->params.i_threads = avctx->thread_count; + x4->params.b_interlaced = avctx->flags & CODEC_FLAG_INTERLACED_DCT; + +@@ -336,6 +375,37 @@ + return 0; + } + ++#define OFFSET(x) offsetof(XavsContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "crf", "Select the quality for constant quality mode", OFFSET(crf), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE }, ++ { "qp", "Constant quantization parameter rate control method",OFFSET(cqp), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE }, ++ { "b-bias", "Influences how often B-frames are used", OFFSET(b_bias), AV_OPT_TYPE_INT, {INT_MIN}, INT_MIN, INT_MAX, VE }, ++ { "cplxblur", "Reduce fluctuations in QP (before curve compression)", OFFSET(cplxblur), AV_OPT_TYPE_FLOAT, {-1 }, -1, FLT_MAX, VE}, ++ { "direct-pred", "Direct MV prediction mode", OFFSET(direct_pred), AV_OPT_TYPE_INT, {-1 }, -1, INT_MAX, VE, "direct-pred" }, ++ { "none", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_NONE }, 0, 0, VE, "direct-pred" }, ++ { "spatial", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_SPATIAL }, 0, 0, VE, "direct-pred" }, ++ { "temporal", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_TEMPORAL }, 0, 0, VE, "direct-pred" }, ++ { "auto", NULL, 0, AV_OPT_TYPE_CONST, { XAVS_DIRECT_PRED_AUTO }, 0, 0, VE, "direct-pred" }, ++ { "aud", "Use access unit delimiters.", OFFSET(aud), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "mbtree", "Use macroblock tree ratecontrol.", OFFSET(mbtree), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { "mixed-refs", "One reference per partition, as opposed to one reference per macroblock", OFFSET(mixed_refs), AV_OPT_TYPE_INT, {-1}, -1, 1, VE }, ++ { "fast-pskip", NULL, OFFSET(fast_pskip), AV_OPT_TYPE_INT, {-1 }, -1, 1, VE}, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "libxavs", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVCodecDefault xavs_defaults[] = { ++ { "b", "0" }, ++ { NULL }, ++}; ++ + AVCodec ff_libxavs_encoder = { + .name = "libxavs", + .type = AVMEDIA_TYPE_VIDEO, +@@ -344,8 +414,10 @@ + .init = XAVS_init, + .encode = XAVS_frame, + .close = XAVS_close, +- .capabilities = CODEC_CAP_DELAY, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS, + .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV420P, PIX_FMT_NONE }, + .long_name = NULL_IF_CONFIG_SMALL("libxavs - the Chinese Audio Video Standard Encoder"), ++ .priv_class = &class, ++ .defaults = xavs_defaults, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxvidff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxvidff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxvidff.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxvidff.c 2012-05-14 14:08:53.947332193 +0200 +@@ -25,18 +25,14 @@ + * @author Adam Thayer (krevnik@comcast.net) + */ + +-/* needed for mkstemp() */ +-#define _XOPEN_SOURCE 600 +- + #include + #include + #include "avcodec.h" ++#include "libavutil/file.h" + #include "libavutil/cpu.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "libxvid_internal.h" +-#if !HAVE_MKSTEMP +-#include +-#endif + + /** + * Buffer management macros. +@@ -79,42 +75,6 @@ + int xvid_ff_2pass(void *ref, int opt, void *p1, void *p2); + void xvid_correct_framerate(AVCodecContext *avctx); + +-/* Wrapper to work around the lack of mkstemp() on mingw. +- * Also, tries to create file in /tmp first, if possible. +- * *prefix can be a character constant; *filename will be allocated internally. +- * @return file descriptor of opened file (or -1 on error) +- * and opened file name in **filename. */ +-int ff_tempfile(const char *prefix, char **filename) { +- int fd=-1; +-#if !HAVE_MKSTEMP +- *filename = tempnam(".", prefix); +-#else +- size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ +- *filename = av_malloc(len); +-#endif +- /* -----common section-----*/ +- if (*filename == NULL) { +- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); +- return -1; +- } +-#if !HAVE_MKSTEMP +- fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444); +-#else +- snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); +- fd = mkstemp(*filename); +- if (fd < 0) { +- snprintf(*filename, len, "./%sXXXXXX", prefix); +- fd = mkstemp(*filename); +- } +-#endif +- /* -----common section-----*/ +- if (fd < 0) { +- av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); +- return -1; +- } +- return fd; /* success */ +-} +- + #if CONFIG_LIBXVID_ENCODER + + /** +@@ -272,7 +232,7 @@ + rc2pass2.version = XVID_VERSION; + rc2pass2.bitrate = avctx->bit_rate; + +- fd = ff_tempfile("xvidff.", &(x->twopassfile)); ++ fd = av_tempfile("xvidff.", &x->twopassfile, 0, avctx); + if( fd == -1 ) { + av_log(avctx, AV_LOG_ERROR, + "Xvid: Cannot write 2-pass pipe\n"); +@@ -416,7 +376,7 @@ + char *tmp; + struct xvid_context *x = avctx->priv_data; + AVFrame *picture = data; +- AVFrame *p = &(x->encoded_picture); ++ AVFrame *p = &x->encoded_picture; + + xvid_enc_frame_t xvid_enc_frame; + xvid_enc_stats_t xvid_enc_stats; +@@ -450,14 +410,14 @@ + xvid_enc_frame.vol_flags = x->vol_flags; + xvid_enc_frame.motion = x->me_flags; + xvid_enc_frame.type = +- picture->pict_type == FF_I_TYPE ? XVID_TYPE_IVOP : +- picture->pict_type == FF_P_TYPE ? XVID_TYPE_PVOP : +- picture->pict_type == FF_B_TYPE ? XVID_TYPE_BVOP : ++ picture->pict_type == AV_PICTURE_TYPE_I ? XVID_TYPE_IVOP : ++ picture->pict_type == AV_PICTURE_TYPE_P ? XVID_TYPE_PVOP : ++ picture->pict_type == AV_PICTURE_TYPE_B ? XVID_TYPE_BVOP : + XVID_TYPE_AUTO; + + /* Pixel aspect ratio setting */ +- if (avctx->sample_aspect_ratio.num < 1 || avctx->sample_aspect_ratio.num > 255 || +- avctx->sample_aspect_ratio.den < 1 || avctx->sample_aspect_ratio.den > 255) { ++ if (avctx->sample_aspect_ratio.num < 0 || avctx->sample_aspect_ratio.num > 255 || ++ avctx->sample_aspect_ratio.den < 0 || avctx->sample_aspect_ratio.den > 255) { + av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i\n", + avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); + return -1; +@@ -493,13 +453,13 @@ + if( 0 <= xerr ) { + p->quality = xvid_enc_stats.quant * FF_QP2LAMBDA; + if( xvid_enc_stats.type == XVID_TYPE_PVOP ) +- p->pict_type = FF_P_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_P; + else if( xvid_enc_stats.type == XVID_TYPE_BVOP ) +- p->pict_type = FF_B_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_B; + else if( xvid_enc_stats.type == XVID_TYPE_SVOP ) +- p->pict_type = FF_S_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_S; + else +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + if( xvid_enc_frame.out_flags & XVID_KEYFRAME ) { + p->key_frame = 1; + if( x->quicktime_format ) +@@ -527,18 +487,15 @@ + + xvid_encore(x->encoder_handle, XVID_ENC_DESTROY, NULL, NULL); + +- if( avctx->extradata != NULL ) +- av_freep(&avctx->extradata); ++ av_freep(&avctx->extradata); + if( x->twopassbuffer != NULL ) { + av_free(x->twopassbuffer); + av_free(x->old_twopassbuffer); ++ avctx->stats_out = NULL; + } +- if( x->twopassfile != NULL ) +- av_free(x->twopassfile); +- if( x->intra_matrix != NULL ) +- av_free(x->intra_matrix); +- if( x->inter_matrix != NULL ) +- av_free(x->inter_matrix); ++ av_free(x->twopassfile); ++ av_free(x->intra_matrix); ++ av_free(x->inter_matrix); + + return 0; + } +@@ -581,7 +538,7 @@ + } + /* Less dangerous now, memmove properly copies the two + chunks of overlapping data */ +- memmove(frame, &(frame[vo_len]), frame_len - vo_len); ++ memmove(frame, &frame[vo_len], frame_len - vo_len); + return frame_len - vo_len; + } else + return frame_len; +@@ -755,7 +712,7 @@ + static int xvid_ff_2pass_after(struct xvid_context *ref, + xvid_plg_data_t *param) { + char *log = ref->twopassbuffer; +- char *frame_types = " ipbs"; ++ const char *frame_types = " ipbs"; + char frame_type; + + /* Quick bounds check */ +@@ -815,13 +772,13 @@ + * Xvid codec definition for libavcodec. + */ + AVCodec ff_libxvid_encoder = { +- "libxvid", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG4, +- sizeof(struct xvid_context), +- xvid_encode_init, +- xvid_encode_frame, +- xvid_encode_close, ++ .name = "libxvid", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG4, ++ .priv_data_size = sizeof(struct xvid_context), ++ .init = xvid_encode_init, ++ .encode = xvid_encode_frame, ++ .close = xvid_encode_close, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("libxvidcore MPEG-4 part 2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxvid_rc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxvid_rc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/libxvid_rc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/libxvid_rc.c 2012-05-14 14:08:53.945332152 +0200 +@@ -22,6 +22,7 @@ + + #include + #include ++#include "libavutil/file.h" + #include "avcodec.h" + #include "libxvid_internal.h" + //#include "dsputil.h" +@@ -40,7 +41,7 @@ + + //xvid_debug=-1; + +- fd=ff_tempfile("xvidrc.", &tmp_name); ++ fd=av_tempfile("xvidrc.", &tmp_name, 0, s->avctx); + if (fd == -1) { + av_log(NULL, AV_LOG_ERROR, "Can't create temporary pass2 file.\n"); + return -1; +@@ -134,7 +135,7 @@ + if(!dry_run) + s->rc_context.dry_run_qscale= 0; + +- if(s->pict_type == FF_B_TYPE) //FIXME this is not exactly identical to xvid ++ if(s->pict_type == AV_PICTURE_TYPE_B) //FIXME this is not exactly identical to xvid + return xvid_plg_data.quant * FF_QP2LAMBDA * s->avctx->b_quant_factor + s->avctx->b_quant_offset; + else + return xvid_plg_data.quant * FF_QP2LAMBDA; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ljpegenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ljpegenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ljpegenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ljpegenc.c 2012-05-14 14:08:53.947332193 +0200 +@@ -49,7 +49,7 @@ + init_put_bits(&s->pb, buf, buf_size); + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + ff_mjpeg_encode_picture_header(s); +@@ -187,12 +187,12 @@ + + + AVCodec ff_ljpeg_encoder = { //FIXME avoid MPV_* lossless JPEG should not need them +- "ljpeg", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_LJPEG, +- sizeof(MpegEncContext), +- MPV_encode_init, +- encode_picture_lossless, +- MPV_encode_end, +- .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"), ++ .name = "ljpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_LJPEG, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = encode_picture_lossless, ++ .close = MPV_encode_end, ++ .long_name = NULL_IF_CONFIG_SMALL("Lossless JPEG"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/loco.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/loco.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/loco.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/loco.c 2012-05-14 14:08:53.948332214 +0200 +@@ -123,6 +123,9 @@ + int val; + int i, j; + ++ if(buf_size<=0) ++ return -1; ++ + init_get_bits(&rc.gb, buf, buf_size*8); + rc.save = 0; + rc.run = 0; +@@ -225,7 +228,7 @@ + *data_size = sizeof(AVFrame); + *(AVFrame*)data = l->pic; + +- return buf_size; ++ return buf_size < 0 ? -1 : buf_size; + } + + static av_cold int decode_init(AVCodecContext *avctx){ +@@ -248,7 +251,7 @@ + break; + default: + l->lossy = AV_RL32(avctx->extradata + 8); +- av_log(avctx, AV_LOG_INFO, "This is LOCO codec version %i, please upload file for study\n", version); ++ av_log_ask_for_sample(avctx, "This is LOCO codec version %i.\n", version); + } + + l->mode = AV_RL32(avctx->extradata + 4); +@@ -272,6 +275,8 @@ + if(avctx->debug & FF_DEBUG_PICT_INFO) + av_log(avctx, AV_LOG_INFO, "lossy:%i, version:%i, mode: %i\n", l->lossy, version, l->mode); + ++ avcodec_get_frame_defaults(&l->pic); ++ + return 0; + } + +@@ -286,14 +291,13 @@ + } + + AVCodec ff_loco_decoder = { +- "loco", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_LOCO, +- sizeof(LOCOContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "loco", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_LOCO, ++ .priv_data_size = sizeof(LOCOContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("LOCO"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lpc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lpc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lpc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lpc.c 2012-05-14 14:08:53.949332234 +0200 +@@ -35,8 +35,9 @@ + double w; + double c; + +- assert(!(len&1)); //the optimization in r11881 does not support odd len +- //if someone wants odd len extend the change in r11881 ++ /* The optimization in commit fa4ed8c does not support odd len. ++ * If someone wants odd len extend that change. */ ++ assert(!(len & 1)); + + n2 = (len >> 1); + c = 2.0 / (len - 1.0); +@@ -149,16 +150,14 @@ + /** + * Calculate LPC coefficients for multiple orders + * +- * @param use_lpc LPC method for determining coefficients +- * 0 = LPC with fixed pre-defined coeffs +- * 1 = LPC with coeffs determined by Levinson-Durbin recursion +- * 2+ = LPC with coeffs determined by Cholesky factorization using (use_lpc-1) passes. ++ * @param lpc_type LPC method for determining coefficients, ++ * see #FFLPCType for details + */ + int ff_lpc_calc_coefs(LPCContext *s, + const int32_t *samples, int blocksize, int min_order, + int max_order, int precision, + int32_t coefs[][MAX_LPC_ORDER], int *shift, +- enum AVLPCType lpc_type, int lpc_passes, ++ enum FFLPCType lpc_type, int lpc_passes, + int omethod, int max_shift, int zero_shift) + { + double autoc[MAX_LPC_ORDER+1]; +@@ -168,7 +167,7 @@ + int opt_order; + + assert(max_order >= MIN_LPC_ORDER && max_order <= MAX_LPC_ORDER && +- lpc_type > AV_LPC_TYPE_FIXED); ++ lpc_type > FF_LPC_TYPE_FIXED); + + /* reinit LPC context if parameters have changed */ + if (blocksize != s->blocksize || max_order != s->max_order || +@@ -177,7 +176,7 @@ + ff_lpc_init(s, blocksize, max_order, lpc_type); + } + +- if (lpc_type == AV_LPC_TYPE_LEVINSON) { ++ if (lpc_type == FF_LPC_TYPE_LEVINSON) { + double *windowed_samples = s->windowed_samples + max_order; + + s->lpc_apply_welch_window(samples, blocksize, windowed_samples); +@@ -188,7 +187,7 @@ + + for(i=0; iblocksize = blocksize; + s->max_order = max_order; + s->lpc_type = lpc_type; + +- if (lpc_type == AV_LPC_TYPE_LEVINSON) { ++ if (lpc_type == FF_LPC_TYPE_LEVINSON) { + s->windowed_samples = av_mallocz((blocksize + max_order + 2) * + sizeof(*s->windowed_samples)); + if (!s->windowed_samples) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lpc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lpc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lpc.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lpc.h 2012-05-14 14:08:53.950332254 +0200 +@@ -35,11 +35,22 @@ + #define MIN_LPC_ORDER 1 + #define MAX_LPC_ORDER 32 + ++/** ++ * LPC analysis type ++ */ ++enum FFLPCType { ++ FF_LPC_TYPE_DEFAULT = -1, ///< use the codec default LPC type ++ FF_LPC_TYPE_NONE = 0, ///< do not use LPC prediction or use all zero coefficients ++ FF_LPC_TYPE_FIXED = 1, ///< fixed LPC coefficients ++ FF_LPC_TYPE_LEVINSON = 2, ///< Levinson-Durbin recursion ++ FF_LPC_TYPE_CHOLESKY = 3, ///< Cholesky factorization ++ FF_LPC_TYPE_NB , ///< Not part of ABI ++}; + + typedef struct LPCContext { + int blocksize; + int max_order; +- enum AVLPCType lpc_type; ++ enum FFLPCType lpc_type; + double *windowed_samples; + + /** +@@ -56,7 +67,7 @@ + * Perform autocorrelation on input samples with delay of 0 to lag. + * @param data input samples. + * constraints: no alignment needed, but must have have at +- * least lag*sizeof(double) valid bytes preceeding it, and ++ * least lag*sizeof(double) valid bytes preceding it, and + * size must be at least (len+1)*sizeof(double) if data is + * 16-byte aligned or (len+2)*sizeof(double) if data is + * unaligned. +@@ -77,14 +88,14 @@ + const int32_t *samples, int blocksize, int min_order, + int max_order, int precision, + int32_t coefs[][MAX_LPC_ORDER], int *shift, +- enum AVLPCType lpc_type, int lpc_passes, ++ enum FFLPCType lpc_type, int lpc_passes, + int omethod, int max_shift, int zero_shift); + + /** + * Initialize LPCContext. + */ + int ff_lpc_init(LPCContext *s, int blocksize, int max_order, +- enum AVLPCType lpc_type); ++ enum FFLPCType lpc_type); + void ff_lpc_init_x86(LPCContext *s); + + /** +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lsp.c 2012-05-14 14:08:53.951332274 +0200 +@@ -74,9 +74,9 @@ + } + + /** +- * \brief decodes polynomial coefficients from LSP +- * \param f [out] decoded polynomial coefficients (-0x20000000 <= (3.22) <= 0x1fffffff) +- * \param lsp LSP coefficients (-0x8000 <= (0.15) <= 0x7fff) ++ * @brief decodes polynomial coefficients from LSP ++ * @param[out] f decoded polynomial coefficients (-0x20000000 <= (3.22) <= 0x1fffffff) ++ * @param lsp LSP coefficients (-0x8000 <= (0.15) <= 0x7fff) + */ + static void lsp2poly(int* f, const int16_t* lsp, int lp_half_order) + { +@@ -120,8 +120,8 @@ + void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order) + { + int lp_half_order = lp_order >> 1; +- double buf[lp_half_order + 1]; +- double pa[lp_half_order + 1]; ++ double buf[MAX_LP_HALF_ORDER + 1]; ++ double pa[MAX_LP_HALF_ORDER + 1]; + double *qa = buf + 1; + int i,j; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lsp.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lsp.h 2012-05-14 14:08:53.951332274 +0200 +@@ -30,12 +30,12 @@ + */ + + /** +- * \brief ensure a minimum distance between LSFs +- * \param[in,out] lsfq LSF to check and adjust +- * \param lsfq_min_distance minimum distance between LSFs +- * \param lsfq_min minimum allowed LSF value +- * \param lsfq_max maximum allowed LSF value +- * \param lp_order LP filter order ++ * @brief ensure a minimum distance between LSFs ++ * @param[in,out] lsfq LSF to check and adjust ++ * @param lsfq_min_distance minimum distance between LSFs ++ * @param lsfq_min minimum allowed LSF value ++ * @param lsfq_max maximum allowed LSF value ++ * @param lp_order LP filter order + */ + void ff_acelp_reorder_lsf(int16_t* lsfq, int lsfq_min_distance, int lsfq_min, int lsfq_max, int lp_order); + +@@ -53,12 +53,12 @@ + void ff_set_min_dist_lsf(float *lsf, double min_spacing, int size); + + /** +- * \brief Convert LSF to LSP +- * \param[out] lsp LSP coefficients (-0x8000 <= (0.15) < 0x8000) +- * \param lsf normalized LSF coefficients (0 <= (2.13) < 0x2000 * PI) +- * \param lp_order LP filter order ++ * @brief Convert LSF to LSP ++ * @param[out] lsp LSP coefficients (-0x8000 <= (0.15) < 0x8000) ++ * @param lsf normalized LSF coefficients (0 <= (2.13) < 0x2000 * PI) ++ * @param lp_order LP filter order + * +- * \remark It is safe to pass the same array into the lsf and lsp parameters. ++ * @remark It is safe to pass the same array into the lsf and lsp parameters. + */ + void ff_acelp_lsf2lsp(int16_t *lsp, const int16_t *lsf, int lp_order); + +@@ -68,10 +68,10 @@ + void ff_acelp_lsf2lspd(double *lsp, const float *lsf, int lp_order); + + /** +- * \brief LSP to LP conversion (3.2.6 of G.729) +- * \param[out] lp decoded LP coefficients (-0x8000 <= (3.12) < 0x8000) +- * \param lsp LSP coefficients (-0x8000 <= (0.15) < 0x8000) +- * \param lp_half_order LP filter order, divided by 2 ++ * @brief LSP to LP conversion (3.2.6 of G.729) ++ * @param[out] lp decoded LP coefficients (-0x8000 <= (3.12) < 0x8000) ++ * @param lsp LSP coefficients (-0x8000 <= (0.15) < 0x8000) ++ * @param lp_half_order LP filter order, divided by 2 + */ + void ff_acelp_lsp2lpc(int16_t* lp, const int16_t* lsp, int lp_half_order); + +@@ -81,17 +81,17 @@ + void ff_amrwb_lsp2lpc(const double *lsp, float *lp, int lp_order); + + /** +- * \brief Interpolate LSP for the first subframe and convert LSP -> LP for both subframes (3.2.5 and 3.2.6 of G.729) +- * \param[out] lp_1st decoded LP coefficients for first subframe (-0x8000 <= (3.12) < 0x8000) +- * \param[out] lp_2nd decoded LP coefficients for second subframe (-0x8000 <= (3.12) < 0x8000) +- * \param lsp_2nd LSP coefficients of the second subframe (-0x8000 <= (0.15) < 0x8000) +- * \param lsp_prev LSP coefficients from the second subframe of the previous frame (-0x8000 <= (0.15) < 0x8000) +- * \param lp_order LP filter order ++ * @brief Interpolate LSP for the first subframe and convert LSP -> LP for both subframes (3.2.5 and 3.2.6 of G.729) ++ * @param[out] lp_1st decoded LP coefficients for first subframe (-0x8000 <= (3.12) < 0x8000) ++ * @param[out] lp_2nd decoded LP coefficients for second subframe (-0x8000 <= (3.12) < 0x8000) ++ * @param lsp_2nd LSP coefficients of the second subframe (-0x8000 <= (0.15) < 0x8000) ++ * @param lsp_prev LSP coefficients from the second subframe of the previous frame (-0x8000 <= (0.15) < 0x8000) ++ * @param lp_order LP filter order + */ + void ff_acelp_lp_decode(int16_t* lp_1st, int16_t* lp_2nd, const int16_t* lsp_2nd, const int16_t* lsp_prev, int lp_order); + + +-#define MAX_LP_HALF_ORDER 8 ++#define MAX_LP_HALF_ORDER 10 + #define MAX_LP_ORDER (2*MAX_LP_HALF_ORDER) + + /** +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzw.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzw.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzw.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzw.c 2012-05-14 14:08:53.952332294 +0200 +@@ -24,7 +24,7 @@ + * @file + * @brief LZW decoding routines + * @author Fabrice Bellard +- * Modified for use in TIFF by Konstantin Shishkov ++ * @author modified for use in TIFF by Konstantin Shishkov + */ + + #include "avcodec.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzwenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzwenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzwenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzwenc.c 2012-05-14 14:08:53.953332314 +0200 +@@ -20,8 +20,8 @@ + */ + + /** +- * LZW encoder + * @file ++ * LZW encoder + * @author Bartlomiej Wolowiec + */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzw.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzw.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/lzw.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/lzw.h 2012-05-14 14:08:53.953332314 +0200 +@@ -24,7 +24,7 @@ + * @file + * @brief LZW decoding routines + * @author Fabrice Bellard +- * Modified for use in TIFF by Konstantin Shishkov ++ * @author modified for use in TIFF by Konstantin Shishkov + */ + + #ifndef AVCODEC_LZW_H +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mace.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mace.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mace.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mace.c 2012-05-14 14:08:53.954332334 +0200 +@@ -27,7 +27,7 @@ + #include "avcodec.h" + + /* +- * Adapted to ffmpeg by Francois Revol ++ * Adapted to libavcodec by Francois Revol + * (removed 68k REG stuff, changed types, added some statics and consts, + * libavcodec api, context stuff, interlaced stereo out). + */ +@@ -153,6 +153,7 @@ + } ChannelData; + + typedef struct MACEContext { ++ AVFrame frame; + ChannelData chd[2]; + } MACEContext; + +@@ -228,27 +229,35 @@ + + static av_cold int mace_decode_init(AVCodecContext * avctx) + { ++ MACEContext *ctx = avctx->priv_data; ++ + if (avctx->channels > 2) + return -1; + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&ctx->frame); ++ avctx->coded_frame = &ctx->frame; ++ + return 0; + } + +-static int mace_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int mace_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- int16_t *samples = data; ++ int16_t *samples; + MACEContext *ctx = avctx->priv_data; +- int i, j, k, l; ++ int i, j, k, l, ret; + int is_mace3 = (avctx->codec_id == CODEC_ID_MACE3); + +- if (*data_size < (3 * buf_size << (2-is_mace3))) { +- av_log(avctx, AV_LOG_ERROR, "Output buffer too small!\n"); +- return -1; ++ /* get output buffer */ ++ ctx->frame.nb_samples = 3 * (buf_size << (1 - is_mace3)) / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } ++ samples = (int16_t *)ctx->frame.data[0]; + + for(i = 0; i < avctx->channels; i++) { + int16_t *output = samples + i; +@@ -274,32 +283,31 @@ + } + } + +- *data_size = 3 * buf_size << (2-is_mace3); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ctx->frame; + + return buf_size; + } + + AVCodec ff_mace3_decoder = { +- "mace3", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MACE3, +- sizeof(MACEContext), +- mace_decode_init, +- NULL, +- NULL, +- mace_decode_frame, ++ .name = "mace3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MACE3, ++ .priv_data_size = sizeof(MACEContext), ++ .init = mace_decode_init, ++ .decode = mace_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 3:1"), + }; + + AVCodec ff_mace6_decoder = { +- "mace6", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MACE6, +- sizeof(MACEContext), +- mace_decode_init, +- NULL, +- NULL, +- mace_decode_frame, ++ .name = "mace6", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MACE6, ++ .priv_data_size = sizeof(MACEContext), ++ .init = mace_decode_init, ++ .decode = mace_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("MACE (Macintosh Audio Compression/Expansion) 6:1"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/Makefile 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile 2012-05-14 14:08:53.276318688 +0200 +@@ -1,9 +1,9 @@ + include $(SUBDIR)../config.mak + + NAME = avcodec +-FFLIBS = avcore avutil ++FFLIBS = avutil + +-HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vdpau.h xvmc.h ++HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vda.h vdpau.h version.h xvmc.h + + OBJS = allcodecs.o \ + audioconvert.o \ +@@ -15,10 +15,10 @@ + fmtconvert.o \ + imgconvert.o \ + jrevdct.o \ +- opt.o \ + options.o \ + parser.o \ + raw.o \ ++ rawdec.o \ + resample.o \ + resample2.o \ + simple_idct.o \ +@@ -26,37 +26,46 @@ + + # parts needed for many different codecs + OBJS-$(CONFIG_AANDCT) += aandcttab.o ++OBJS-$(CONFIG_AC3DSP) += ac3dsp.o ++OBJS-$(CONFIG_CRYSTALHD) += crystalhd.o + OBJS-$(CONFIG_ENCODERS) += faandct.o jfdctfst.o jfdctint.o +-OBJS-$(CONFIG_DCT) += dct.o ++OBJS-$(CONFIG_DCT) += dct.o dct32_fixed.o dct32_float.o + OBJS-$(CONFIG_DWT) += dwt.o + OBJS-$(CONFIG_DXVA2) += dxva2.o +-FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o +-OBJS-$(CONFIG_FFT) += avfft.o fft.o $(FFT-OBJS-yes) ++FFT-OBJS-$(CONFIG_HARDCODED_TABLES) += cos_tables.o cos_fixed_tables.o ++OBJS-$(CONFIG_FFT) += avfft.o fft_fixed.o fft_float.o \ ++ $(FFT-OBJS-yes) + OBJS-$(CONFIG_GOLOMB) += golomb.o + OBJS-$(CONFIG_H264DSP) += h264dsp.o h264idct.o + OBJS-$(CONFIG_H264PRED) += h264pred.o + OBJS-$(CONFIG_HUFFMAN) += huffman.o + OBJS-$(CONFIG_LPC) += lpc.o + OBJS-$(CONFIG_LSP) += lsp.o +-OBJS-$(CONFIG_MDCT) += mdct.o ++OBJS-$(CONFIG_MDCT) += mdct_fixed.o mdct_float.o ++OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \ ++ mpegaudiodsp_fixed.o \ ++ mpegaudiodsp_float.o + RDFT-OBJS-$(CONFIG_HARDCODED_TABLES) += sin_tables.o + OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) ++OBJS-$(CONFIG_SINEWIN) += sinewin.o + OBJS-$(CONFIG_VAAPI) += vaapi.o ++OBJS-$(CONFIG_VDA) += vda.o + OBJS-$(CONFIG_VDPAU) += vdpau.o + + # decoders/encoders/hardware accelerators + OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o + OBJS-$(CONFIG_A64MULTI5_ENCODER) += a64multienc.o elbg.o + OBJS-$(CONFIG_AAC_DECODER) += aacdec.o aactab.o aacsbr.o aacps.o \ +- aacadtsdec.o mpeg4audio.o ++ aacadtsdec.o mpeg4audio.o kbdwin.o + OBJS-$(CONFIG_AAC_ENCODER) += aacenc.o aaccoder.o \ + aacpsy.o aactab.o \ + psymodel.o iirfilter.o \ +- mpeg4audio.o ++ mpeg4audio.o kbdwin.o + OBJS-$(CONFIG_AASC_DECODER) += aasc.o msrledec.o +-OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o +-OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3tab.o ac3.o +-OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3tab.o ac3.o ++OBJS-$(CONFIG_AC3_DECODER) += ac3dec.o ac3dec_data.o ac3.o kbdwin.o ++OBJS-$(CONFIG_AC3_ENCODER) += ac3enc_float.o ac3enc.o ac3tab.o \ ++ ac3.o kbdwin.o ++OBJS-$(CONFIG_AC3_FIXED_ENCODER) += ac3enc_fixed.o ac3enc.o ac3tab.o ac3.o + OBJS-$(CONFIG_ALAC_DECODER) += alac.o + OBJS-$(CONFIG_ALAC_ENCODER) += alacenc.o + OBJS-$(CONFIG_ALS_DECODER) += alsdec.o bgmc.o mpeg4audio.o +@@ -72,7 +81,7 @@ + OBJS-$(CONFIG_ANM_DECODER) += anm.o + OBJS-$(CONFIG_ANSI_DECODER) += ansi.o cga_data.o + OBJS-$(CONFIG_APE_DECODER) += apedec.o +-OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o ++OBJS-$(CONFIG_ASS_DECODER) += assdec.o ass.o ass_split.o + OBJS-$(CONFIG_ASS_ENCODER) += assenc.o ass.o + OBJS-$(CONFIG_ASV1_DECODER) += asv1.o mpeg12data.o + OBJS-$(CONFIG_ASV1_ENCODER) += asv1.o mpeg12data.o +@@ -82,14 +91,19 @@ + OBJS-$(CONFIG_ATRAC3_DECODER) += atrac3.o atrac.o + OBJS-$(CONFIG_AURA_DECODER) += cyuv.o + OBJS-$(CONFIG_AURA2_DECODER) += aura.o ++OBJS-$(CONFIG_AVRP_DECODER) += r210dec.o ++OBJS-$(CONFIG_AVRP_ENCODER) += r210enc.o + OBJS-$(CONFIG_AVS_DECODER) += avs.o + OBJS-$(CONFIG_BETHSOFTVID_DECODER) += bethsoftvideo.o + OBJS-$(CONFIG_BFI_DECODER) += bfi.o +-OBJS-$(CONFIG_BINK_DECODER) += bink.o binkidct.o ++OBJS-$(CONFIG_BINK_DECODER) += bink.o binkdsp.o + OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER) += binkaudio.o wma.o + OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER) += binkaudio.o wma.o ++OBJS-$(CONFIG_BINTEXT_DECODER) += bintext.o cga_data.o + OBJS-$(CONFIG_BMP_DECODER) += bmp.o msrledec.o + OBJS-$(CONFIG_BMP_ENCODER) += bmpenc.o ++OBJS-$(CONFIG_BMV_VIDEO_DECODER) += bmv.o ++OBJS-$(CONFIG_BMV_AUDIO_DECODER) += bmv.o + OBJS-$(CONFIG_C93_DECODER) += c93.o + OBJS-$(CONFIG_CAVS_DECODER) += cavs.o cavsdec.o cavsdsp.o \ + mpeg12data.o mpegvideo.o +@@ -101,12 +115,17 @@ + OBJS-$(CONFIG_CSCD_DECODER) += cscd.o + OBJS-$(CONFIG_CYUV_DECODER) += cyuv.o + OBJS-$(CONFIG_DCA_DECODER) += dca.o synth_filter.o dcadsp.o ++OBJS-$(CONFIG_DCA_ENCODER) += dcaenc.o ++OBJS-$(CONFIG_DIRAC_DECODER) += diracdec.o dirac.o diracdsp.o \ ++ dirac_arith.o mpeg12data.o dwt.o ++OBJS-$(CONFIG_DFA_DECODER) += dfa.o + OBJS-$(CONFIG_DNXHD_DECODER) += dnxhddec.o dnxhddata.o + OBJS-$(CONFIG_DNXHD_ENCODER) += dnxhdenc.o dnxhddata.o \ + mpegvideo_enc.o motion_est.o \ + ratecontrol.o mpeg12data.o \ + mpegvideo.o + OBJS-$(CONFIG_DPX_DECODER) += dpx.o ++OBJS-$(CONFIG_DPX_ENCODER) += dpxenc.o + OBJS-$(CONFIG_DSICINAUDIO_DECODER) += dsicinav.o + OBJS-$(CONFIG_DSICINVIDEO_DECODER) += dsicinav.o + OBJS-$(CONFIG_DVBSUB_DECODER) += dvbsubdec.o +@@ -116,7 +135,10 @@ + OBJS-$(CONFIG_DVVIDEO_DECODER) += dv.o dvdata.o + OBJS-$(CONFIG_DVVIDEO_ENCODER) += dv.o dvdata.o + OBJS-$(CONFIG_DXA_DECODER) += dxa.o +-OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3dec_data.o ++OBJS-$(CONFIG_DXTORY_DECODER) += dxtory.o ++OBJS-$(CONFIG_EAC3_DECODER) += eac3dec.o eac3_data.o ++OBJS-$(CONFIG_EAC3_ENCODER) += eac3enc.o ac3enc.o ac3enc_float.o \ ++ ac3tab.o ac3.o kbdwin.o eac3_data.o + OBJS-$(CONFIG_EACMV_DECODER) += eacmv.o + OBJS-$(CONFIG_EAMAD_DECODER) += eamad.o eaidct.o mpeg12.o \ + mpeg12data.o mpegvideo.o \ +@@ -129,19 +151,28 @@ + OBJS-$(CONFIG_EIGHTBPS_DECODER) += 8bps.o + OBJS-$(CONFIG_EIGHTSVX_EXP_DECODER) += 8svx.o + OBJS-$(CONFIG_EIGHTSVX_FIB_DECODER) += 8svx.o ++OBJS-$(CONFIG_EIGHTSVX_RAW_DECODER) += 8svx.o + OBJS-$(CONFIG_ESCAPE124_DECODER) += escape124.o ++OBJS-$(CONFIG_ESCAPE130_DECODER) += escape130.o + OBJS-$(CONFIG_FFV1_DECODER) += ffv1.o rangecoder.o + OBJS-$(CONFIG_FFV1_ENCODER) += ffv1.o rangecoder.o + OBJS-$(CONFIG_FFVHUFF_DECODER) += huffyuv.o + OBJS-$(CONFIG_FFVHUFF_ENCODER) += huffyuv.o +-OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o flac.o +-OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o flac.o ++OBJS-$(CONFIG_FFWAVESYNTH_DECODER) += ffwavesynth.o ++OBJS-$(CONFIG_FLAC_DECODER) += flacdec.o flacdata.o flac.o vorbis_data.o ++OBJS-$(CONFIG_FLAC_ENCODER) += flacenc.o flacdata.o flac.o vorbis_data.o + OBJS-$(CONFIG_FLASHSV_DECODER) += flashsv.o + OBJS-$(CONFIG_FLASHSV_ENCODER) += flashsvenc.o ++OBJS-$(CONFIG_FLASHSV2_ENCODER) += flashsv2enc.o ++OBJS-$(CONFIG_FLASHSV2_DECODER) += flashsv.o + OBJS-$(CONFIG_FLIC_DECODER) += flicvideo.o + OBJS-$(CONFIG_FOURXM_DECODER) += 4xm.o + OBJS-$(CONFIG_FRAPS_DECODER) += fraps.o + OBJS-$(CONFIG_FRWU_DECODER) += frwu.o ++OBJS-$(CONFIG_G723_1_DECODER) += g723_1.o acelp_vectors.o \ ++ celp_filters.o celp_math.o ++OBJS-$(CONFIG_G723_1_ENCODER) += g723_1.o ++OBJS-$(CONFIG_G729_DECODER) += g729dec.o lsp.o celp_math.o acelp_filters.o acelp_pitch_delay.o acelp_vectors.o g729postfilter.o + OBJS-$(CONFIG_GIF_DECODER) += gifdec.o lzw.o + OBJS-$(CONFIG_GIF_ENCODER) += gif.o lzwenc.o + OBJS-$(CONFIG_GSM_DECODER) += gsmdec.o gsmdec_data.o msgsmdec.o +@@ -169,20 +200,26 @@ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o + OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o ++OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o + OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o + OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o + OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o ++OBJS-$(CONFIG_IDF_DECODER) += bintext.o cga_data.o + OBJS-$(CONFIG_IFF_BYTERUN1_DECODER) += iff.o + OBJS-$(CONFIG_IFF_ILBM_DECODER) += iff.o + OBJS-$(CONFIG_IMC_DECODER) += imc.o + OBJS-$(CONFIG_INDEO2_DECODER) += indeo2.o + OBJS-$(CONFIG_INDEO3_DECODER) += indeo3.o ++OBJS-$(CONFIG_INDEO4_DECODER) += indeo4.o ivi_common.o ivi_dsp.o + OBJS-$(CONFIG_INDEO5_DECODER) += indeo5.o ivi_common.o ivi_dsp.o + OBJS-$(CONFIG_INTERPLAY_DPCM_DECODER) += dpcm.o + OBJS-$(CONFIG_INTERPLAY_VIDEO_DECODER) += interplayvideo.o ++OBJS-$(CONFIG_JPEG2000_DECODER) += j2kdec.o mqcdec.o mqc.o j2k.o j2k_dwt.o ++OBJS-$(CONFIG_JPEG2000_ENCODER) += j2kenc.o mqcenc.o mqc.o j2k.o j2k_dwt.o + OBJS-$(CONFIG_JPEGLS_DECODER) += jpeglsdec.o jpegls.o \ + mjpegdec.o mjpeg.o + OBJS-$(CONFIG_JPEGLS_ENCODER) += jpeglsenc.o jpegls.o ++OBJS-$(CONFIG_JV_DECODER) += jvdec.o + OBJS-$(CONFIG_KGV1_DECODER) += kgv1dec.o + OBJS-$(CONFIG_KMVC_DECODER) += kmvc.o + OBJS-$(CONFIG_LAGARITH_DECODER) += lagarith.o lagarithrac.o +@@ -241,6 +278,7 @@ + OBJS-$(CONFIG_MPEG1VIDEO_DECODER) += mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_MPEG1VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ ++ timecode.o \ + motion_est.o ratecontrol.o \ + mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o +@@ -249,13 +287,12 @@ + OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ ++ timecode.o \ + motion_est.o ratecontrol.o \ + mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_MPEG4_VAAPI_HWACCEL) += vaapi_mpeg4.o + OBJS-$(CONFIG_MSMPEG4V1_DECODER) += msmpeg4.o msmpeg4data.o +-OBJS-$(CONFIG_MSMPEG4V1_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \ +- h263.o ituh263dec.o mpeg4videodec.o + OBJS-$(CONFIG_MSMPEG4V2_DECODER) += msmpeg4.o msmpeg4data.o h263dec.o \ + h263.o ituh263dec.o mpeg4videodec.o + OBJS-$(CONFIG_MSMPEG4V2_ENCODER) += msmpeg4.o msmpeg4data.o h263dec.o \ +@@ -266,7 +303,9 @@ + h263.o ituh263dec.o mpeg4videodec.o + OBJS-$(CONFIG_MSRLE_DECODER) += msrle.o msrledec.o + OBJS-$(CONFIG_MSVIDEO1_DECODER) += msvideo1.o ++OBJS-$(CONFIG_MSVIDEO1_ENCODER) += msvideo1enc.o elbg.o + OBJS-$(CONFIG_MSZH_DECODER) += lcldec.o ++OBJS-$(CONFIG_MXPEG_DECODER) += mxpegdec.o mjpegdec.o mjpeg.o + OBJS-$(CONFIG_NELLYMOSER_DECODER) += nellymoserdec.o nellymoser.o + OBJS-$(CONFIG_NELLYMOSER_ENCODER) += nellymoserenc.o nellymoser.o + OBJS-$(CONFIG_NUV_DECODER) += nuv.o rtjpeg.o +@@ -286,6 +325,9 @@ + OBJS-$(CONFIG_PNG_ENCODER) += png.o pngenc.o + OBJS-$(CONFIG_PPM_DECODER) += pnmdec.o pnm.o + OBJS-$(CONFIG_PPM_ENCODER) += pnmenc.o pnm.o ++OBJS-$(CONFIG_PRORES_DECODER) += proresdec2.o ++OBJS-$(CONFIG_PRORES_LGPL_DECODER) += proresdec_lgpl.o proresdsp.o ++OBJS-$(CONFIG_PRORES_ENCODER) += proresenc.o + OBJS-$(CONFIG_PTX_DECODER) += ptx.o + OBJS-$(CONFIG_QCELP_DECODER) += qcelpdec.o celp_math.o \ + celp_filters.o acelp_vectors.o \ +@@ -298,7 +340,9 @@ + OBJS-$(CONFIG_QTRLE_DECODER) += qtrle.o + OBJS-$(CONFIG_QTRLE_ENCODER) += qtrleenc.o + OBJS-$(CONFIG_R10K_DECODER) += r210dec.o ++OBJS-$(CONFIG_R10K_ENCODER) += r210enc.o + OBJS-$(CONFIG_R210_DECODER) += r210dec.o ++OBJS-$(CONFIG_R210_ENCODER) += r210enc.o + OBJS-$(CONFIG_RA_144_DECODER) += ra144dec.o ra144.o celp_filters.o + OBJS-$(CONFIG_RA_144_ENCODER) += ra144enc.o ra144.o celp_filters.o + OBJS-$(CONFIG_RA_288_DECODER) += ra288.o celp_math.o celp_filters.o +@@ -314,10 +358,11 @@ + OBJS-$(CONFIG_RV10_ENCODER) += rv10enc.o + OBJS-$(CONFIG_RV20_DECODER) += rv10.o + OBJS-$(CONFIG_RV20_ENCODER) += rv20enc.o +-OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o \ ++OBJS-$(CONFIG_RV30_DECODER) += rv30.o rv34.o rv30dsp.o rv34dsp.o \ + mpegvideo.o error_resilience.o +-OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv40dsp.o \ ++OBJS-$(CONFIG_RV40_DECODER) += rv40.o rv34.o rv34dsp.o rv40dsp.o \ + mpegvideo.o error_resilience.o ++OBJS-$(CONFIG_S302M_DECODER) += s302m.o + OBJS-$(CONFIG_SGI_DECODER) += sgidec.o + OBJS-$(CONFIG_SGI_ENCODER) += sgienc.o rle.o + OBJS-$(CONFIG_SHORTEN_DECODER) += shorten.o +@@ -328,18 +373,19 @@ + OBJS-$(CONFIG_SMACKAUD_DECODER) += smacker.o + OBJS-$(CONFIG_SMACKER_DECODER) += smacker.o + OBJS-$(CONFIG_SMC_DECODER) += smc.o +-OBJS-$(CONFIG_SNOW_DECODER) += snow.o rangecoder.o +-OBJS-$(CONFIG_SNOW_ENCODER) += snow.o rangecoder.o motion_est.o \ +- ratecontrol.o h263.o \ +- mpegvideo.o error_resilience.o \ +- ituh263enc.o mpegvideo_enc.o \ +- mpeg12data.o ++OBJS-$(CONFIG_SNOW_DECODER) += snowdec.o snow.o rangecoder.o ++OBJS-$(CONFIG_SNOW_ENCODER) += snowenc.o snow.o rangecoder.o \ ++ motion_est.o ratecontrol.o \ ++ h263.o mpegvideo.o \ ++ error_resilience.o ituh263enc.o \ ++ mpegvideo_enc.o mpeg12data.o + OBJS-$(CONFIG_SOL_DPCM_DECODER) += dpcm.o + OBJS-$(CONFIG_SONIC_DECODER) += sonic.o + OBJS-$(CONFIG_SONIC_ENCODER) += sonic.o + OBJS-$(CONFIG_SONIC_LS_ENCODER) += sonic.o + OBJS-$(CONFIG_SP5X_DECODER) += sp5xdec.o mjpegdec.o mjpeg.o + OBJS-$(CONFIG_SRT_DECODER) += srtdec.o ass.o ++OBJS-$(CONFIG_SRT_ENCODER) += srtenc.o ass_split.o + OBJS-$(CONFIG_SUNRAST_DECODER) += sunrast.o + OBJS-$(CONFIG_SVQ1_DECODER) += svq1dec.o svq1.o h263.o \ + mpegvideo.o error_resilience.o +@@ -370,10 +416,16 @@ + OBJS-$(CONFIG_TWINVQ_DECODER) += twinvq.o celp_math.o + OBJS-$(CONFIG_TXD_DECODER) += txd.o s3tc.o + OBJS-$(CONFIG_ULTI_DECODER) += ulti.o ++OBJS-$(CONFIG_UTVIDEO_DECODER) += utvideo.o + OBJS-$(CONFIG_V210_DECODER) += v210dec.o + OBJS-$(CONFIG_V210_ENCODER) += v210enc.o ++OBJS-$(CONFIG_V308_DECODER) += v308dec.o ++OBJS-$(CONFIG_V308_ENCODER) += v308enc.o ++OBJS-$(CONFIG_V410_DECODER) += v410dec.o ++OBJS-$(CONFIG_V410_ENCODER) += v410enc.o + OBJS-$(CONFIG_V210X_DECODER) += v210x.o + OBJS-$(CONFIG_VB_DECODER) += vb.o ++OBJS-$(CONFIG_VBLE_DECODER) += vble.o + OBJS-$(CONFIG_VC1_DECODER) += vc1dec.o vc1.o vc1data.o vc1dsp.o \ + msmpeg4.o msmpeg4data.o \ + intrax8.o intrax8dsp.o +@@ -384,9 +436,9 @@ + OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o + OBJS-$(CONFIG_VMDVIDEO_DECODER) += vmdav.o + OBJS-$(CONFIG_VMNC_DECODER) += vmnc.o +-OBJS-$(CONFIG_VORBIS_DECODER) += vorbis_dec.o vorbis.o \ ++OBJS-$(CONFIG_VORBIS_DECODER) += vorbisdec.o vorbis.o \ + vorbis_data.o xiph.o +-OBJS-$(CONFIG_VORBIS_ENCODER) += vorbis_enc.o vorbis.o \ ++OBJS-$(CONFIG_VORBIS_ENCODER) += vorbisenc.o vorbis.o \ + vorbis_data.o + OBJS-$(CONFIG_VP3_DECODER) += vp3.o vp3dsp.o + OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56dsp.o \ +@@ -396,6 +448,7 @@ + OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp8dsp.o vp56rac.o + OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o + OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o ++OBJS-$(CONFIG_WMALOSSLESS_DECODER) += wmalosslessdec.o wma.o + OBJS-$(CONFIG_WMAPRO_DECODER) += wmaprodec.o wma.o + OBJS-$(CONFIG_WMAV1_DECODER) += wmadec.o wma.o aactab.o + OBJS-$(CONFIG_WMAV1_ENCODER) += wmaenc.o wma.o aactab.o +@@ -415,11 +468,18 @@ + OBJS-$(CONFIG_WS_SND1_DECODER) += ws-snd1.o + OBJS-$(CONFIG_XAN_DPCM_DECODER) += dpcm.o + OBJS-$(CONFIG_XAN_WC3_DECODER) += xan.o +-OBJS-$(CONFIG_XAN_WC4_DECODER) += xan.o ++OBJS-$(CONFIG_XAN_WC4_DECODER) += xxan.o ++OBJS-$(CONFIG_XBIN_DECODER) += bintext.o cga_data.o + OBJS-$(CONFIG_XL_DECODER) += xl.o + OBJS-$(CONFIG_XSUB_DECODER) += xsubdec.o + OBJS-$(CONFIG_XSUB_ENCODER) += xsubenc.o ++OBJS-$(CONFIG_XWD_DECODER) += xwddec.o ++OBJS-$(CONFIG_XWD_ENCODER) += xwdenc.o ++OBJS-$(CONFIG_Y41P_DECODER) += y41pdec.o ++OBJS-$(CONFIG_Y41P_ENCODER) += y41penc.o + OBJS-$(CONFIG_YOP_DECODER) += yop.o ++OBJS-$(CONFIG_YUV4_DECODER) += yuv4dec.o ++OBJS-$(CONFIG_YUV4_ENCODER) += yuv4enc.o + OBJS-$(CONFIG_ZLIB_DECODER) += lcldec.o + OBJS-$(CONFIG_ZLIB_ENCODER) += lclenc.o + OBJS-$(CONFIG_ZMBV_DECODER) += zmbv.o +@@ -444,6 +504,7 @@ + OBJS-$(CONFIG_PCM_MULAW_ENCODER) += pcm.o + OBJS-$(CONFIG_PCM_S8_DECODER) += pcm.o + OBJS-$(CONFIG_PCM_S8_ENCODER) += pcm.o ++OBJS-$(CONFIG_PCM_S8_PLANAR_DECODER) += 8svx.o + OBJS-$(CONFIG_PCM_S16BE_DECODER) += pcm.o + OBJS-$(CONFIG_PCM_S16BE_ENCODER) += pcm.o + OBJS-$(CONFIG_PCM_S16LE_DECODER) += pcm.o +@@ -474,77 +535,85 @@ + OBJS-$(CONFIG_PCM_U32LE_DECODER) += pcm.o + OBJS-$(CONFIG_PCM_U32LE_ENCODER) += pcm.o + OBJS-$(CONFIG_PCM_ZORK_DECODER) += pcm.o +-OBJS-$(CONFIG_PCM_ZORK_ENCODER) += pcm.o + +-OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o +-OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o +-OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o +-OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o ++OBJS-$(CONFIG_ADPCM_4XM_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_ADX_DECODER) += adxdec.o adx.o ++OBJS-$(CONFIG_ADPCM_ADX_ENCODER) += adxenc.o adx.o ++OBJS-$(CONFIG_ADPCM_CT_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_MAXIS_XA_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_R1_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_R2_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_R3_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_EA_XAS_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_G722_DECODER) += g722.o g722dec.o ++OBJS-$(CONFIG_ADPCM_G722_ENCODER) += g722.o g722enc.o + OBJS-$(CONFIG_ADPCM_G726_DECODER) += g726.o + OBJS-$(CONFIG_ADPCM_G726_ENCODER) += g726.o +-OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_ISS_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o +-OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcm.o ++OBJS-$(CONFIG_ADPCM_IMA_AMV_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_APC_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_DK3_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_DK4_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_EA_EACS_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_EA_SEAD_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_ISS_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_QT_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_QT_ENCODER) += adpcmenc.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_SMJPEG_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_WAV_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_WAV_ENCODER) += adpcmenc.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_IMA_WS_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_MS_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_MS_ENCODER) += adpcmenc.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_SBPRO_2_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_SBPRO_3_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_SBPRO_4_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_SWF_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_SWF_ENCODER) += adpcmenc.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_THP_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_XA_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_YAMAHA_DECODER) += adpcm.o adpcm_data.o ++OBJS-$(CONFIG_ADPCM_YAMAHA_ENCODER) += adpcmenc.o adpcm_data.o + + # libavformat dependencies + OBJS-$(CONFIG_ADTS_MUXER) += mpeg4audio.o ++OBJS-$(CONFIG_ADX_DEMUXER) += adx.o + OBJS-$(CONFIG_CAF_DEMUXER) += mpeg4audio.o mpegaudiodata.o + OBJS-$(CONFIG_DV_DEMUXER) += dvdata.o +-OBJS-$(CONFIG_DV_MUXER) += dvdata.o +-OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o flac.o +-OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o flac.o ++OBJS-$(CONFIG_DV_MUXER) += dvdata.o timecode.o ++OBJS-$(CONFIG_FLAC_DEMUXER) += flacdec.o flacdata.o flac.o vorbis_data.o ++OBJS-$(CONFIG_FLAC_MUXER) += flacdec.o flacdata.o flac.o vorbis_data.o + OBJS-$(CONFIG_FLV_DEMUXER) += mpeg4audio.o + OBJS-$(CONFIG_GXF_DEMUXER) += mpeg12data.o + OBJS-$(CONFIG_IFF_DEMUXER) += iff.o +-OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o \ ++OBJS-$(CONFIG_LATM_MUXER) += mpeg4audio.o ++OBJS-$(CONFIG_MATROSKA_AUDIO_MUXER) += xiph.o mpeg4audio.o vorbis_data.o \ + flacdec.o flacdata.o flac.o + OBJS-$(CONFIG_MATROSKA_DEMUXER) += mpeg4audio.o mpegaudiodata.o + OBJS-$(CONFIG_MATROSKA_MUXER) += xiph.o mpeg4audio.o \ + flacdec.o flacdata.o flac.o \ +- mpegaudiodata.o +-OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o ++ mpegaudiodata.o vorbis_data.o ++OBJS-$(CONFIG_MP3_MUXER) += mpegaudiodata.o mpegaudiodecheader.o ++OBJS-$(CONFIG_MOV_DEMUXER) += mpeg4audio.o mpegaudiodata.o ac3tab.o timecode.o + OBJS-$(CONFIG_MOV_MUXER) += mpeg4audio.o mpegaudiodata.o + OBJS-$(CONFIG_MPEGTS_MUXER) += mpegvideo.o mpeg4audio.o + OBJS-$(CONFIG_MPEGTS_DEMUXER) += mpeg4audio.o mpegaudiodata.o ++OBJS-$(CONFIG_MXF_MUXER) += timecode.o + OBJS-$(CONFIG_NUT_MUXER) += mpegaudiodata.o + OBJS-$(CONFIG_OGG_DEMUXER) += flacdec.o flacdata.o flac.o \ +- dirac.o mpeg12data.o +-OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o flac.o +-OBJS-$(CONFIG_RTP_MUXER) += mpegvideo.o xiph.o ++ dirac.o mpeg12data.o vorbis_data.o ++OBJS-$(CONFIG_OGG_MUXER) += xiph.o flacdec.o flacdata.o flac.o \ ++ vorbis_data.o ++OBJS-$(CONFIG_RTP_MUXER) += mpeg4audio.o mpegvideo.o xiph.o + OBJS-$(CONFIG_SPDIF_DEMUXER) += aacadtsdec.o mpeg4audio.o + OBJS-$(CONFIG_WEBM_MUXER) += xiph.o mpeg4audio.o \ + flacdec.o flacdata.o flac.o \ +- mpegaudiodata.o ++ mpegaudiodata.o vorbis_data.o ++OBJS-$(CONFIG_WTV_DEMUXER) += mpeg4audio.o mpegaudiodata.o + + # external codec libraries ++OBJS-$(CONFIG_LIBAACPLUS_ENCODER) += libaacplus.o ++OBJS-$(CONFIG_LIBCELT_DECODER) += libcelt_dec.o + OBJS-$(CONFIG_LIBDIRAC_DECODER) += libdiracdec.o + OBJS-$(CONFIG_LIBDIRAC_ENCODER) += libdiracenc.o libdirac_libschro.o + OBJS-$(CONFIG_LIBFAAC_ENCODER) += libfaac.o +@@ -556,7 +625,8 @@ + OBJS-$(CONFIG_LIBOPENCORE_AMRNB_DECODER) += libopencore-amr.o + OBJS-$(CONFIG_LIBOPENCORE_AMRNB_ENCODER) += libopencore-amr.o + OBJS-$(CONFIG_LIBOPENCORE_AMRWB_DECODER) += libopencore-amr.o +-OBJS-$(CONFIG_LIBOPENJPEG_DECODER) += libopenjpeg.o ++OBJS-$(CONFIG_LIBOPENJPEG_DECODER) += libopenjpegdec.o ++OBJS-$(CONFIG_LIBOPENJPEG_ENCODER) += libopenjpegenc.o + OBJS-$(CONFIG_LIBSCHROEDINGER_DECODER) += libschroedingerdec.o \ + libschroedinger.o \ + libdirac_libschro.o +@@ -564,7 +634,12 @@ + libschroedinger.o \ + libdirac_libschro.o + OBJS-$(CONFIG_LIBSPEEX_DECODER) += libspeexdec.o ++OBJS-$(CONFIG_LIBSPEEX_ENCODER) += libspeexenc.o ++OBJS-$(CONFIG_LIBSTAGEFRIGHT_H264_DECODER)+= libstagefright.o + OBJS-$(CONFIG_LIBTHEORA_ENCODER) += libtheoraenc.o ++OBJS-$(CONFIG_LIBUTVIDEO_DECODER) += libutvideo.o ++OBJS-$(CONFIG_LIBVO_AACENC_ENCODER) += libvo-aacenc.o mpeg4audio.o ++OBJS-$(CONFIG_LIBVO_AMRWBENC_ENCODER) += libvo-amrwbenc.o + OBJS-$(CONFIG_LIBVORBIS_ENCODER) += libvorbis.o vorbis_data.o + OBJS-$(CONFIG_LIBVPX_DECODER) += libvpxdec.o + OBJS-$(CONFIG_LIBVPX_ENCODER) += libvpxenc.o +@@ -577,13 +652,16 @@ + aacadtsdec.o mpeg4audio.o + OBJS-$(CONFIG_AC3_PARSER) += ac3_parser.o ac3tab.o \ + aac_ac3_parser.o ++OBJS-$(CONFIG_ADX_PARSER) += adx_parser.o adx.o + OBJS-$(CONFIG_CAVSVIDEO_PARSER) += cavs_parser.o + OBJS-$(CONFIG_DCA_PARSER) += dca_parser.o + OBJS-$(CONFIG_DIRAC_PARSER) += dirac_parser.o + OBJS-$(CONFIG_DNXHD_PARSER) += dnxhd_parser.o + OBJS-$(CONFIG_DVBSUB_PARSER) += dvbsub_parser.o + OBJS-$(CONFIG_DVDSUB_PARSER) += dvdsub_parser.o +-OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o ++OBJS-$(CONFIG_FLAC_PARSER) += flac_parser.o flacdata.o flac.o \ ++ vorbis_data.o ++OBJS-$(CONFIG_GSM_PARSER) += gsm_parser.o + OBJS-$(CONFIG_H261_PARSER) += h261_parser.o + OBJS-$(CONFIG_H263_PARSER) += h263_parser.o + OBJS-$(CONFIG_H264_PARSER) += h264_parser.o h264.o \ +@@ -605,6 +683,8 @@ + mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_PNM_PARSER) += pnm_parser.o pnm.o ++OBJS-$(CONFIG_RV30_PARSER) += rv34_parser.o ++OBJS-$(CONFIG_RV40_PARSER) += rv34_parser.o + OBJS-$(CONFIG_VC1_PARSER) += vc1_parser.o vc1.o vc1data.o \ + msmpeg4.o msmpeg4data.o mpeg4video.o \ + h263.o mpegvideo.o error_resilience.o +@@ -630,7 +710,8 @@ + + # thread libraries + OBJS-$(HAVE_PTHREADS) += pthread.o +-OBJS-$(HAVE_W32THREADS) += w32thread.o ++OBJS-$(HAVE_W32THREADS) += pthread.o ++OBJS-$(HAVE_OS2THREADS) += pthread.o + + OBJS-$(CONFIG_MLIB) += mlib/dsputil_mlib.o \ + +@@ -640,46 +721,40 @@ + # well. + OBJS-$(!CONFIG_SMALL) += inverse.o + +--include $(SUBDIR)$(ARCH)/Makefile +- +-SKIPHEADERS = %_tablegen.h ++SKIPHEADERS += %_tablegen.h \ ++ %_tables.h \ ++ aac_tablegen_decl.h \ ++ fft-internal.h \ ++ tableprint.h \ ++ $(ARCH)/vp56_arith.h + SKIPHEADERS-$(CONFIG_DXVA2) += dxva2.h dxva2_internal.h + SKIPHEADERS-$(CONFIG_LIBDIRAC) += libdirac.h + SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h + SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h ++SKIPHEADERS-$(CONFIG_VDA) += vda_internal.h + SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h + SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h +-SKIPHEADERS += mpegaudio3.h ++SKIPHEADERS-$(HAVE_W32THREADS) += w32pthreads.h + +-EXAMPLES = api +- +-TESTPROGS = cabac dct eval fft h264 iirfilter rangecoder snow ++TESTPROGS = cabac dct fft fft-fixed h264 iirfilter rangecoder snowenc + TESTPROGS-$(HAVE_MMX) += motion + TESTOBJS = dctref.o + +-HOSTPROGS = costablegen ++HOSTPROGS = aac_tablegen aacps_tablegen cbrt_tablegen cos_tablegen \ ++ dv_tablegen motionpixels_tablegen mpegaudio_tablegen \ ++ pcm_tablegen qdm2_tablegen sinewin_tablegen + + DIRS = alpha arm bfin mlib ppc ps2 sh4 sparc x86 + +-CLEANFILES = sin_tables.c cos_tables.c *_tables.h *_tablegen$(HOSTEXESUF) +- +-include $(SUBDIR)../subdir.mak ++CLEANFILES = *_tables.c *_tables.h *_tablegen$(HOSTEXESUF) + + $(SUBDIR)dct-test$(EXESUF): $(SUBDIR)dctref.o + +-$(SUBDIR)cos_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) +- $(M)./$< > $@ +- +-$(SUBDIR)sin_tables.c: $(SUBDIR)costablegen$(HOSTEXESUF) +- $(M)./$< sin > $@ ++TRIG_TABLES = cos cos_fixed sin ++TRIG_TABLES := $(TRIG_TABLES:%=$(SUBDIR)%_tables.c) + +-ifdef CONFIG_MPEGAUDIO_HP +-$(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=23 +-$(SUBDIR)mpegaudio_tablegen.ho: CPPFLAGS += -DFRAC_BITS=23 +-else +-$(SUBDIR)mpegaudio_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DFRAC_BITS=15 +-$(SUBDIR)mpegaudio_tablegen.ho: CPPFLAGS += -DFRAC_BITS=15 +-endif ++$(TRIG_TABLES): $(SUBDIR)%_tables.c: $(SUBDIR)cos_tablegen$(HOSTEXESUF) ++ $(M)./$< $* > $@ + + ifdef CONFIG_SMALL + $(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=1 +@@ -687,11 +762,8 @@ + $(SUBDIR)%_tablegen$(HOSTEXESUF): HOSTCFLAGS += -DCONFIG_SMALL=0 + endif + +-$(SUBDIR)%_tablegen$(HOSTEXESUF): $(SUBDIR)%_tablegen.c $(SUBDIR)%_tablegen.h $(SUBDIR)tableprint.c +- $(HOSTCC) $(HOSTCFLAGS) $(HOSTLDFLAGS) -o $@ $(filter %.c,$^) $(HOSTLIBS) +- + GEN_HEADERS = cbrt_tables.h aacps_tables.h aac_tables.h dv_tables.h \ +- mdct_tables.h mpegaudio_tables.h motionpixels_tables.h \ ++ sinewin_tables.h mpegaudio_tables.h motionpixels_tables.h \ + pcm_tables.h qdm2_tables.h + GEN_HEADERS := $(addprefix $(SUBDIR), $(GEN_HEADERS)) + +@@ -703,10 +775,17 @@ + $(SUBDIR)aacps.o: $(SUBDIR)aacps_tables.h + $(SUBDIR)aactab.o: $(SUBDIR)aac_tables.h + $(SUBDIR)dv.o: $(SUBDIR)dv_tables.h +-$(SUBDIR)mdct.o: $(SUBDIR)mdct_tables.h ++$(SUBDIR)sinewin.o: $(SUBDIR)sinewin_tables.h + $(SUBDIR)mpegaudiodec.o: $(SUBDIR)mpegaudio_tables.h + $(SUBDIR)mpegaudiodec_float.o: $(SUBDIR)mpegaudio_tables.h + $(SUBDIR)motionpixels.o: $(SUBDIR)motionpixels_tables.h + $(SUBDIR)pcm.o: $(SUBDIR)pcm_tables.h + $(SUBDIR)qdm2.o: $(SUBDIR)qdm2_tables.h + endif ++ ++CODEC_NAMES_SH := $(SRC_PATH)/$(SUBDIR)codec_names.sh ++AVCODEC_H := $(SRC_PATH)/$(SUBDIR)avcodec.h ++$(SUBDIR)codec_names.h: $(CODEC_NAMES_SH) config.h $(AVCODEC_H) ++ $(CC) $(CPPFLAGS) $(CFLAGS) -E $(AVCODEC_H) | \ ++ $(CODEC_NAMES_SH) config.h $@ ++$(SUBDIR)utils.o: $(SUBDIR)codec_names.h +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mathops.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mathops.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mathops.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mathops.h 2012-05-14 14:08:53.955332354 +0200 +@@ -23,6 +23,7 @@ + #define AVCODEC_MATHOPS_H + + #include "libavutil/common.h" ++#include "config.h" + + #if ARCH_ARM + # include "arm/mathops.h" +@@ -40,16 +41,17 @@ + + /* generic implementation */ + ++#ifndef MUL64 ++# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b)) ++#endif ++ + #ifndef MULL +-# define MULL(a,b,s) (((int64_t)(a) * (int64_t)(b)) >> (s)) ++# define MULL(a,b,s) (MUL64(a, b) >> (s)) + #endif + + #ifndef MULH +-//gcc 3.4 creates an incredibly bloated mess out of this +-//# define MULH(a,b) (((int64_t)(a) * (int64_t)(b))>>32) +- + static av_always_inline int MULH(int a, int b){ +- return ((int64_t)(a) * (int64_t)(b))>>32; ++ return MUL64(a, b) >> 32; + } + #endif + +@@ -59,10 +61,6 @@ + } + #endif + +-#ifndef MUL64 +-# define MUL64(a,b) ((int64_t)(a) * (int64_t)(b)) +-#endif +- + #ifndef MAC64 + # define MAC64(d, a, b) ((d) += MUL64(a, b)) + #endif +@@ -118,7 +116,9 @@ + #ifndef sign_extend + static inline av_const int sign_extend(int val, unsigned bits) + { +- return (val << ((8 * sizeof(int)) - bits)) >> ((8 * sizeof(int)) - bits); ++ unsigned shift = 8 * sizeof(int) - bits; ++ union { unsigned u; int s; } v = { (unsigned) val << shift }; ++ return v.s >> shift; + } + #endif + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdct.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdct.c 2012-05-14 14:08:53.956332374 +0200 +@@ -24,38 +24,18 @@ + #include "libavutil/common.h" + #include "libavutil/mathematics.h" + #include "fft.h" ++#include "fft-internal.h" + + /** + * @file + * MDCT/IMDCT transforms. + */ + +-// Generate a Kaiser-Bessel Derived Window. +-#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation +-av_cold void ff_kbd_window_init(float *window, float alpha, int n) +-{ +- int i, j; +- double sum = 0.0, bessel, tmp; +- double local_window[FF_KBD_WINDOW_MAX]; +- double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); +- +- assert(n <= FF_KBD_WINDOW_MAX); +- +- for (i = 0; i < n; i++) { +- tmp = i * (n - i) * alpha2; +- bessel = 1.0; +- for (j = BESSEL_I0_ITER; j > 0; j--) +- bessel = bessel * tmp / (j * j) + 1; +- sum += bessel; +- local_window[i] = sum; +- } +- +- sum++; +- for (i = 0; i < n; i++) +- window[i] = sqrt(local_window[i] / sum); +-} +- +-#include "mdct_tablegen.h" ++#if CONFIG_FFT_FLOAT ++# define RSCALE(x) (x) ++#else ++# define RSCALE(x) ((x) >> 1) ++#endif + + /** + * init MDCT or IMDCT computation. +@@ -71,7 +51,7 @@ + s->mdct_bits = nbits; + s->mdct_size = n; + n4 = n >> 2; +- s->permutation = FF_MDCT_PERM_NONE; ++ s->mdct_permutation = FF_MDCT_PERM_NONE; + + if (ff_fft_init(s, s->mdct_bits - 2, inverse) < 0) + goto fail; +@@ -80,7 +60,7 @@ + if (!s->tcos) + goto fail; + +- switch (s->permutation) { ++ switch (s->mdct_permutation) { + case FF_MDCT_PERM_NONE: + s->tsin = s->tcos + n4; + tstep = 1; +@@ -97,8 +77,8 @@ + scale = sqrt(fabs(scale)); + for(i=0;itcos[i*tstep] = -cos(alpha) * scale; +- s->tsin[i*tstep] = -sin(alpha) * scale; ++ s->tcos[i*tstep] = FIX15(-cos(alpha) * scale); ++ s->tsin[i*tstep] = FIX15(-sin(alpha) * scale); + } + return 0; + fail: +@@ -106,17 +86,6 @@ + return -1; + } + +-/* complex multiplication: p = a * b */ +-#define CMUL(pre, pim, are, aim, bre, bim) \ +-{\ +- FFTSample _are = (are);\ +- FFTSample _aim = (aim);\ +- FFTSample _bre = (bre);\ +- FFTSample _bim = (bim);\ +- (pre) = _are * _bre - _aim * _bim;\ +- (pim) = _are * _bim + _aim * _bre;\ +-} +- + /** + * Compute the middle half of the inverse MDCT of size N = 2^nbits, + * thus excluding the parts that can be derived by symmetry +@@ -146,7 +115,7 @@ + in1 += 2; + in2 -= 2; + } +- ff_fft_calc(s, z); ++ s->fft_calc(s, z); + + /* post rotation + reordering */ + for(k = 0; k < n8; k++) { +@@ -188,7 +157,7 @@ + void ff_mdct_calc_c(FFTContext *s, FFTSample *out, const FFTSample *input) + { + int i, j, n, n8, n4, n2, n3; +- FFTSample re, im; ++ FFTDouble re, im; + const uint16_t *revtab = s->revtab; + const FFTSample *tcos = s->tcos; + const FFTSample *tsin = s->tsin; +@@ -202,18 +171,18 @@ + + /* pre rotation */ + for(i=0;ifft_calc(s, x); + + /* post rotation */ + for(i=0;irevtab; ++ const FFTSample *tcos = s->tcos; ++ const FFTSample *tsin = s->tsin; ++ FFTComplex *x = s->tmp_buf; ++ FFTDComplex *o = (FFTDComplex *)out; ++ ++ n = 1 << s->mdct_bits; ++ n2 = n >> 1; ++ n4 = n >> 2; ++ n8 = n >> 3; ++ n3 = 3 * n4; ++ ++ /* pre rotation */ ++ for(i=0;ifft_calc(s, x); ++ ++ /* post rotation */ ++ for(i=0;i +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +-#define CONFIG_HARDCODED_TABLES 0 +-#define SINETABLE_CONST +-#define SINETABLE(size) \ +- float ff_sine_##size[size] +-#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) +-#ifndef M_PI +-#define M_PI 3.14159265358979323846 +-#endif +-#include "mdct_tablegen.h" +-#include "tableprint.h" +- +-int main(void) +-{ +- int i; +- +- write_fileheader(); +- +- for (i = 5; i <= 12; i++) { +- ff_init_ff_sine_windows(i); +- printf("SINETABLE(%4i) = {\n", 1 << i); +- write_float_array(ff_sine_windows[i], 1 << i); +- printf("};\n"); +- } +- +- return 0; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdct_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdct_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdct_tablegen.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdct_tablegen.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,60 +0,0 @@ +-/* +- * Header file for hardcoded MDCT tables +- * +- * Copyright (c) 2009 Reimar Döffinger +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +-// do not use libavutil/libm.h since this is compiled both +-// for the host and the target and config.h is only valid for the target +-#include +-#include "libavutil/attributes.h" +- +-#if !CONFIG_HARDCODED_TABLES +-SINETABLE( 32); +-SINETABLE( 64); +-SINETABLE( 128); +-SINETABLE( 256); +-SINETABLE( 512); +-SINETABLE(1024); +-SINETABLE(2048); +-SINETABLE(4096); +-#else +-#include "libavcodec/mdct_tables.h" +-#endif +- +-SINETABLE_CONST float * const ff_sine_windows[] = { +- NULL, NULL, NULL, NULL, NULL, // unused +- ff_sine_32 , ff_sine_64 , +- ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 +-}; +- +-// Generate a sine window. +-av_cold void ff_sine_window_init(float *window, int n) { +- int i; +- for(i = 0; i < n; i++) +- window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); +-} +- +-av_cold void ff_init_ff_sine_windows(int index) { +- assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows)); +-#if !CONFIG_HARDCODED_TABLES +- ff_sine_window_init(ff_sine_windows[index], 1 << index); +-#endif +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mdec.c 2012-05-14 14:08:53.959332434 +0200 +@@ -31,6 +31,7 @@ + #include "dsputil.h" + #include "mpegvideo.h" + #include "mpeg12.h" ++#include "thread.h" + + typedef struct MDECContext{ + AVCodecContext *avctx; +@@ -125,7 +126,8 @@ + a->dsp.clear_blocks(block[0]); + + for(i=0; i<6; i++){ +- if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0) ++ if( mdec_decode_block_intra(a, block[ block_index[i] ], block_index[i]) < 0 || ++ get_bits_left(&a->gb) < 0) + return -1; + } + return 0; +@@ -162,14 +164,14 @@ + int i; + + if(p->data[0]) +- avctx->release_buffer(avctx, p); ++ ff_thread_release_buffer(avctx, p); + + p->reference= 0; +- if(avctx->get_buffer(avctx, p) < 0){ ++ if(ff_thread_get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + av_fast_malloc(&a->bitstream_buffer, &a->bitstream_buffer_size, buf_size + FF_INPUT_BUFFER_PADDING_SIZE); +@@ -217,6 +219,7 @@ + a->mb_width = (avctx->coded_width + 15) / 16; + a->mb_height = (avctx->coded_height + 15) / 16; + ++ avcodec_get_frame_defaults(&a->picture); + avctx->coded_frame= &a->picture; + a->avctx= avctx; + } +@@ -238,6 +241,19 @@ + return 0; + } + ++static av_cold int decode_init_thread_copy(AVCodecContext *avctx){ ++ MDECContext * const a = avctx->priv_data; ++ AVFrame *p = (AVFrame*)&a->picture; ++ ++ avctx->coded_frame= p; ++ a->avctx= avctx; ++ ++ p->qscale_table= av_mallocz(a->mb_width); ++ ++ return 0; ++} ++ ++ + static av_cold int decode_end(AVCodecContext *avctx){ + MDECContext * const a = avctx->priv_data; + +@@ -251,15 +267,15 @@ + } + + AVCodec ff_mdec_decoder = { +- "mdec", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MDEC, +- sizeof(MDECContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "mdec", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MDEC, ++ .priv_data_size = sizeof(MDECContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, + .long_name= NULL_IF_CONFIG_SMALL("Sony PlayStation MDEC (Motion DECoder)"), ++ .init_thread_copy= ONLY_IF_THREADS_ENABLED(decode_init_thread_copy) + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mimic.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mimic.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mimic.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mimic.c 2012-05-14 14:08:53.960332454 +0200 +@@ -1,6 +1,6 @@ + /* + * Copyright (C) 2005 Ole André Vadla Ravnås +- * Copyright (C) 2008 Ramiro Polla ++ * Copyright (C) 2008 Ramiro Polla + * + * This file is part of FFmpeg. + * +@@ -24,9 +24,11 @@ + #include + + #include "avcodec.h" ++#include "internal.h" + #include "get_bits.h" + #include "bytestream.h" + #include "dsputil.h" ++#include "thread.h" + + #define MIMIC_HEADER_SIZE 20 + +@@ -51,6 +53,10 @@ + ScanTable scantable; + DSPContext dsp; + VLC vlc; ++ ++ /* Kept in the context so multithreading can have a constant to read from */ ++ int next_cur_index; ++ int next_prev_index; + } MimicContext; + + static const uint32_t huffcodes[] = { +@@ -121,6 +127,23 @@ + return 0; + } + ++static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from) ++{ ++ MimicContext *dst = avctx->priv_data, *src = avctx_from->priv_data; ++ ++ if (avctx == avctx_from) return 0; ++ ++ dst->cur_index = src->next_cur_index; ++ dst->prev_index = src->next_prev_index; ++ ++ memcpy(dst->buf_ptrs, src->buf_ptrs, sizeof(src->buf_ptrs)); ++ memcpy(dst->flipped_ptrs, src->flipped_ptrs, sizeof(src->flipped_ptrs)); ++ ++ memset(&dst->buf_ptrs[dst->cur_index], 0, sizeof(AVFrame)); ++ ++ return 0; ++} ++ + static const int8_t vlcdec_lookup[9][64] = { + { 0, }, + { -1, 1, }, +@@ -205,7 +228,7 @@ + static int decode(MimicContext *ctx, int quality, int num_coeffs, + int is_iframe) + { +- int y, x, plane; ++ int y, x, plane, cur_row = 0; + + for(plane = 0; plane < 3; plane++) { + const int is_chroma = !!plane; +@@ -236,6 +259,7 @@ + int index = (ctx->cur_index+backref)&15; + uint8_t *p = ctx->flipped_ptrs[index].data[0]; + ++ ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0); + if(p) { + p += src - + ctx->flipped_ptrs[ctx->prev_index].data[plane]; +@@ -246,6 +270,7 @@ + } + } + } else { ++ ff_thread_await_progress(&ctx->buf_ptrs[ctx->prev_index], cur_row, 0); + ctx->dsp.put_pixels_tab[1][0](dst, src, stride, 8); + } + src += 8; +@@ -253,6 +278,8 @@ + } + src += (stride - ctx->num_hblocks[plane])<<3; + dst += (stride - ctx->num_hblocks[plane])<<3; ++ ++ ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], cur_row++, 0); + } + } + +@@ -325,17 +352,22 @@ + return -1; + } + +- ctx->buf_ptrs[ctx->cur_index].reference = 1; +- if(avctx->get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) { ++ ctx->buf_ptrs[ctx->cur_index].reference = 3; ++ ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? AV_PICTURE_TYPE_P:AV_PICTURE_TYPE_I; ++ if(ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + ++ ctx->next_prev_index = ctx->cur_index; ++ ctx->next_cur_index = (ctx->cur_index - 1) & 15; ++ + prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index], + (AVPicture*) &ctx->buf_ptrs[ctx->cur_index]); + +- av_fast_malloc(&ctx->swap_buf, &ctx->swap_buf_size, +- swap_buf_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ ff_thread_finish_setup(avctx); ++ ++ av_fast_padded_malloc(&ctx->swap_buf, &ctx->swap_buf_size, swap_buf_size); + if(!ctx->swap_buf) + return AVERROR(ENOMEM); + +@@ -345,21 +377,23 @@ + init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3); + + if(!decode(ctx, quality, num_coeffs, !is_pframe)) { +- avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); +- return -1; ++ if (avctx->active_thread_type&FF_THREAD_FRAME) ++ ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0); ++ else { ++ ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); ++ return -1; ++ } + } + +- ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE; + *(AVFrame*)data = ctx->buf_ptrs[ctx->cur_index]; + *data_size = sizeof(AVFrame); + +- ctx->prev_index = ctx->cur_index; +- ctx->cur_index--; +- ctx->cur_index &= 15; ++ ctx->prev_index = ctx->next_prev_index; ++ ctx->cur_index = ctx->next_cur_index; + + /* Only release frames that aren't used for backreferences anymore */ + if(ctx->buf_ptrs[ctx->cur_index].data[0]) +- avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); ++ ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); + + return buf_size; + } +@@ -370,23 +404,27 @@ + int i; + + av_free(ctx->swap_buf); ++ ++ if (avctx->internal->is_copy) ++ return 0; ++ + for(i = 0; i < 16; i++) + if(ctx->buf_ptrs[i].data[0]) +- avctx->release_buffer(avctx, &ctx->buf_ptrs[i]); ++ ff_thread_release_buffer(avctx, &ctx->buf_ptrs[i]); + free_vlc(&ctx->vlc); + + return 0; + } + + AVCodec ff_mimic_decoder = { +- "mimic", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MIMIC, +- sizeof(MimicContext), +- mimic_decode_init, +- NULL, +- mimic_decode_end, +- mimic_decode_frame, +- CODEC_CAP_DR1, ++ .name = "mimic", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MIMIC, ++ .priv_data_size = sizeof(MimicContext), ++ .init = mimic_decode_init, ++ .close = mimic_decode_end, ++ .decode = mimic_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, + .long_name = NULL_IF_CONFIG_SMALL("Mimic"), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context) + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg2jpeg_bsf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg2jpeg_bsf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg2jpeg_bsf.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg2jpeg_bsf.c 2012-05-14 14:08:53.961332474 +0200 +@@ -108,6 +108,5 @@ + + AVBitStreamFilter ff_mjpeg2jpeg_bsf = { + .name = "mjpeg2jpeg", +- .priv_data_size = 0, + .filter = mjpeg2jpeg_filter, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegbdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegbdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegbdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegbdec.c 2012-05-14 14:08:53.963332515 +0200 +@@ -59,6 +59,9 @@ + s->restart_count = 0; + s->mjpb_skiptosod = 0; + ++ if (buf_end - buf_ptr >= 1 << 28) ++ return AVERROR_INVALIDDATA; ++ + init_get_bits(&hgb, buf_ptr, /*buf_size*/(buf_end - buf_ptr)*8); + + skip_bits(&hgb, 32); /* reserved zeros */ +@@ -66,7 +69,7 @@ + if (get_bits_long(&hgb, 32) != MKBETAG('m','j','p','g')) + { + av_log(avctx, AV_LOG_WARNING, "not mjpeg-b (bad fourcc)\n"); +- return 0; ++ return AVERROR_INVALIDDATA; + } + + field_size = get_bits_long(&hgb, 32); /* field size */ +@@ -81,7 +84,9 @@ + { + init_get_bits(&s->gb, buf_ptr+dqt_offs, (buf_end - (buf_ptr+dqt_offs))*8); + s->start_code = DQT; +- ff_mjpeg_decode_dqt(s); ++ if (ff_mjpeg_decode_dqt(s) < 0 && ++ (avctx->err_recognition & AV_EF_EXPLODE)) ++ return AVERROR_INVALIDDATA; + } + + dht_offs = read_offs(avctx, &hgb, buf_end - buf_ptr, "dht is %d and size is %d\n"); +@@ -109,11 +114,13 @@ + av_log(avctx, AV_LOG_DEBUG, "sod offs: 0x%x\n", sod_offs); + if (sos_offs) + { +-// init_get_bits(&s->gb, buf+sos_offs, (buf_end - (buf+sos_offs))*8); +- init_get_bits(&s->gb, buf_ptr+sos_offs, field_size*8); ++ init_get_bits(&s->gb, buf_ptr + sos_offs, ++ 8 * FFMIN(field_size, buf_end - buf_ptr - sos_offs)); + s->mjpb_skiptosod = (sod_offs - sos_offs - show_bits(&s->gb, 16)); + s->start_code = SOS; +- ff_mjpeg_decode_sos(s); ++ if (ff_mjpeg_decode_sos(s, NULL, NULL) < 0 && ++ (avctx->err_recognition & AV_EF_EXPLODE)) ++ return AVERROR_INVALIDDATA; + } + + if (s->interlaced) { +@@ -129,7 +136,7 @@ + + //XXX FIXME factorize, this looks very similar to the EOI code + +- *picture= s->picture; ++ *picture= *s->picture_ptr; + *data_size = sizeof(AVFrame); + + if(!s->lossless){ +@@ -142,20 +149,18 @@ + picture->quality*= FF_QP2LAMBDA; + } + +- return buf_ptr - buf; ++ return buf_size; + } + + AVCodec ff_mjpegb_decoder = { +- "mjpegb", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MJPEGB, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- mjpegb_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "mjpegb", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MJPEGB, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = mjpegb_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("Apple MJPEG-B"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegdec.c 2012-05-14 14:08:53.969332636 +0200 +@@ -30,10 +30,12 @@ + * MJPEG decoder. + */ + +-//#define DEBUG ++// #define DEBUG + #include + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/avassert.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mjpeg.h" +@@ -41,8 +43,9 @@ + #include "jpeglsdec.h" + + +-static int build_vlc(VLC *vlc, const uint8_t *bits_table, const uint8_t *val_table, +- int nb_codes, int use_static, int is_ac) ++static int build_vlc(VLC *vlc, const uint8_t *bits_table, ++ const uint8_t *val_table, int nb_codes, ++ int use_static, int is_ac) + { + uint8_t huff_size[256]; + uint16_t huff_code[256]; +@@ -54,15 +57,18 @@ + memset(huff_size, 0, sizeof(huff_size)); + ff_mjpeg_build_huffman_codes(huff_size, huff_code, bits_table, val_table); + +- for(i=0; i<256; i++) +- huff_sym[i]= i + 16*is_ac; ++ for (i = 0; i < 256; i++) ++ huff_sym[i] = i + 16 * is_ac; + +- if(is_ac) huff_sym[0]= 16*256; ++ if (is_ac) ++ huff_sym[0] = 16 * 256; + +- return init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1, huff_code, 2, 2, huff_sym, 2, 2, use_static); ++ return init_vlc_sparse(vlc, 9, nb_codes, huff_size, 1, 1, ++ huff_code, 2, 2, huff_sym, 2, 2, use_static); + } + +-static void build_basic_mjpeg_vlc(MJpegDecodeContext * s) { ++static void build_basic_mjpeg_vlc(MJpegDecodeContext *s) ++{ + build_vlc(&s->vlcs[0][0], ff_mjpeg_bits_dc_luminance, + ff_mjpeg_val_dc, 12, 0, 0); + build_vlc(&s->vlcs[0][1], ff_mjpeg_bits_dc_chrominance, +@@ -81,33 +87,38 @@ + { + MJpegDecodeContext *s = avctx->priv_data; + ++ if (!s->picture_ptr) ++ s->picture_ptr = &s->picture; ++ avcodec_get_frame_defaults(&s->picture); ++ + s->avctx = avctx; + dsputil_init(&s->dsp, avctx); + ff_init_scantable(s->dsp.idct_permutation, &s->scantable, ff_zigzag_direct); +- s->buffer_size = 0; +- s->buffer = NULL; +- s->start_code = -1; ++ s->buffer_size = 0; ++ s->buffer = NULL; ++ s->start_code = -1; + s->first_picture = 1; +- s->org_height = avctx->coded_height; ++ s->org_height = avctx->coded_height; + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; + + build_basic_mjpeg_vlc(s); + ++#if FF_API_MJPEG_GLOBAL_OPTS + if (avctx->flags & CODEC_FLAG_EXTERN_HUFF) +- { ++ s->extern_huff = 1; ++#endif ++ if (s->extern_huff) { + av_log(avctx, AV_LOG_INFO, "mjpeg: using external huffman table\n"); +- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size*8); ++ init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8); + if (ff_mjpeg_decode_dht(s)) { +- av_log(avctx, AV_LOG_ERROR, "mjpeg: error using external huffman table, switching back to internal\n"); ++ av_log(avctx, AV_LOG_ERROR, ++ "mjpeg: error using external huffman table, switching back to internal\n"); + build_basic_mjpeg_vlc(s); + } + } +- if (avctx->extradata_size > 9 && +- AV_RL32(avctx->extradata + 4) == MKTAG('f','i','e','l')) { +- if (avctx->extradata[9] == 6) { /* quicktime icefloe 019 */ +- s->interlace_polarity = 1; /* bottom field first */ +- av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); +- } ++ if (avctx->field_order == AV_FIELD_BB) { /* quicktime icefloe 019 */ ++ s->interlace_polarity = 1; /* bottom field first */ ++ av_log(avctx, AV_LOG_DEBUG, "mjpeg bottom field first\n"); + } + if (avctx->codec->id == CODEC_ID_AMV) + s->flipped = 1; +@@ -125,8 +136,7 @@ + + while (len >= 65) { + /* only 8 bit precision handled */ +- if (get_bits(&s->gb, 4) != 0) +- { ++ if (get_bits(&s->gb, 4) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "dqt: 16bit precision\n"); + return -1; + } +@@ -135,19 +145,18 @@ + return -1; + av_log(s->avctx, AV_LOG_DEBUG, "index=%d\n", index); + /* read quant table */ +- for(i=0;i<64;i++) { ++ for (i = 0; i < 64; i++) { + j = s->scantable.permutated[i]; + s->quant_matrixes[index][j] = get_bits(&s->gb, 8); + } + +- //XXX FIXME finetune, and perhaps add dc too +- s->qscale[index]= FFMAX( +- s->quant_matrixes[index][s->scantable.permutated[1]], +- s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1; +- av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", index, s->qscale[index]); ++ // XXX FIXME finetune, and perhaps add dc too ++ s->qscale[index] = FFMAX(s->quant_matrixes[index][s->scantable.permutated[1]], ++ s->quant_matrixes[index][s->scantable.permutated[8]]) >> 1; ++ av_log(s->avctx, AV_LOG_DEBUG, "qscale[%d]: %d\n", ++ index, s->qscale[index]); + len -= 65; + } +- + return 0; + } + +@@ -170,7 +179,7 @@ + if (index >= 4) + return -1; + n = 0; +- for(i=1;i<=16;i++) { ++ for (i = 1; i <= 16; i++) { + bits_table[i] = get_bits(&s->gb, 8); + n += bits_table[i]; + } +@@ -179,7 +188,7 @@ + return -1; + + code_max = 0; +- for(i=0;igb, 8); + if (v > code_max) + code_max = v; +@@ -191,15 +200,15 @@ + free_vlc(&s->vlcs[class][index]); + av_log(s->avctx, AV_LOG_DEBUG, "class=%d index=%d nb_codes=%d\n", + class, index, code_max + 1); +- if(build_vlc(&s->vlcs[class][index], bits_table, val_table, code_max + 1, 0, class > 0) < 0){ ++ if (build_vlc(&s->vlcs[class][index], bits_table, val_table, ++ code_max + 1, 0, class > 0) < 0) + return -1; +- } + +- if(class>0){ ++ if (class > 0) { + free_vlc(&s->vlcs[2][index]); +- if(build_vlc(&s->vlcs[2][index], bits_table, val_table, code_max + 1, 0, 0) < 0){ +- return -1; +- } ++ if (build_vlc(&s->vlcs[2][index], bits_table, val_table, ++ code_max + 1, 0, 0) < 0) ++ return -1; + } + } + return 0; +@@ -209,45 +218,56 @@ + { + int len, nb_components, i, width, height, pix_fmt_id; + ++ s->cur_scan = 0; ++ s->upscale_h = s->upscale_v = 0; ++ + /* XXX: verify len field validity */ +- len = get_bits(&s->gb, 16); +- s->bits= get_bits(&s->gb, 8); ++ len = get_bits(&s->gb, 16); ++ s->bits = get_bits(&s->gb, 8); + +- if(s->pegasus_rct) s->bits=9; +- if(s->bits==9 && !s->pegasus_rct) s->rct=1; //FIXME ugly ++ if (s->pegasus_rct) ++ s->bits = 9; ++ if (s->bits == 9 && !s->pegasus_rct) ++ s->rct = 1; // FIXME ugly + +- if (s->bits != 8 && !s->lossless){ ++ if (s->bits != 8 && !s->lossless) { + av_log(s->avctx, AV_LOG_ERROR, "only 8 bits/component accepted\n"); + return -1; + } + ++ if(s->lossless && s->avctx->lowres){ ++ av_log(s->avctx, AV_LOG_ERROR, "lowres is not possible with lossless jpeg\n"); ++ return -1; ++ } ++ + height = get_bits(&s->gb, 16); +- width = get_bits(&s->gb, 16); ++ width = get_bits(&s->gb, 16); + +- //HACK for odd_height.mov +- if(s->interlaced && s->width == width && s->height == height + 1) ++ // HACK for odd_height.mov ++ if (s->interlaced && s->width == width && s->height == height + 1) + height= s->height; + + av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height); +- if(av_image_check_size(width, height, 0, s->avctx)) ++ if (av_image_check_size(width, height, 0, s->avctx)) + return -1; + + nb_components = get_bits(&s->gb, 8); + if (nb_components <= 0 || + nb_components > MAX_COMPONENTS) + return -1; +- if (s->ls && !(s->bits <= 8 || nb_components == 1)){ +- av_log(s->avctx, AV_LOG_ERROR, "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n"); ++ if (s->ls && !(s->bits <= 8 || nb_components == 1)) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "only <= 8 bits/component or 16-bit gray accepted for JPEG-LS\n"); + return -1; + } + s->nb_components = nb_components; +- s->h_max = 1; +- s->v_max = 1; +- for(i=0;ih_max = 1; ++ s->v_max = 1; ++ for (i = 0; i < nb_components; i++) { + /* component id */ + s->component_id[i] = get_bits(&s->gb, 8) - 1; +- s->h_count[i] = get_bits(&s->gb, 4); +- s->v_count[i] = get_bits(&s->gb, 4); ++ s->h_count[i] = get_bits(&s->gb, 4); ++ s->v_count[i] = get_bits(&s->gb, 4); + /* compute hmax and vmax (only used in interleaved case) */ + if (s->h_count[i] > s->h_max) + s->h_max = s->h_count[i]; +@@ -256,45 +276,47 @@ + s->quant_index[i] = get_bits(&s->gb, 8); + if (s->quant_index[i] >= 4) + return -1; +- av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", i, s->h_count[i], +- s->v_count[i], s->component_id[i], s->quant_index[i]); ++ av_log(s->avctx, AV_LOG_DEBUG, "component %d %d:%d id: %d quant:%d\n", ++ i, s->h_count[i], s->v_count[i], ++ s->component_id[i], s->quant_index[i]); + } + +- if(s->ls && (s->h_max > 1 || s->v_max > 1)) { +- av_log(s->avctx, AV_LOG_ERROR, "Subsampling in JPEG-LS is not supported.\n"); ++ if (s->ls && (s->h_max > 1 || s->v_max > 1)) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Subsampling in JPEG-LS is not supported.\n"); + return -1; + } + +- if(s->v_max==1 && s->h_max==1 && s->lossless==1) s->rgb=1; ++ if (s->v_max == 1 && s->h_max == 1 && s->lossless==1 && nb_components==3) ++ s->rgb = 1; + + /* if different size, realloc/alloc picture */ + /* XXX: also check h_count and v_count */ + if (width != s->width || height != s->height) { + av_freep(&s->qscale_table); + +- s->width = width; +- s->height = height; ++ s->width = width; ++ s->height = height; + s->interlaced = 0; + + /* test interlaced mode */ +- if (s->first_picture && ++ if (s->first_picture && + s->org_height != 0 && + s->height < ((s->org_height * 3) / 4)) { +- s->interlaced = 1; +- s->bottom_field = s->interlace_polarity; +- s->picture.interlaced_frame = 1; +- s->picture.top_field_first = !s->interlace_polarity; ++ s->interlaced = 1; ++ s->bottom_field = s->interlace_polarity; ++ s->picture_ptr->interlaced_frame = 1; ++ s->picture_ptr->top_field_first = !s->interlace_polarity; + height *= 2; + } + + avcodec_set_dimensions(s->avctx, width, height); + +- s->qscale_table= av_mallocz((s->width+15)/16); +- ++ s->qscale_table = av_mallocz((s->width + 15) / 16); + s->first_picture = 0; + } + +- if(s->interlaced && (s->bottom_field == !s->interlace_polarity)) ++ if (s->interlaced && (s->bottom_field == !s->interlace_polarity)) + return 0; + + /* XXX: not complete test ! */ +@@ -303,78 +325,123 @@ + (s->h_count[2] << 12) | (s->v_count[2] << 8) | + (s->h_count[3] << 4) | s->v_count[3]; + av_log(s->avctx, AV_LOG_DEBUG, "pix fmt id %x\n", pix_fmt_id); +- //NOTE we do not allocate pictures large enough for the possible padding of h/v_count being 4 +- if(!(pix_fmt_id & 0xD0D0D0D0)) +- pix_fmt_id-= (pix_fmt_id & 0xF0F0F0F0)>>1; +- if(!(pix_fmt_id & 0x0D0D0D0D)) +- pix_fmt_id-= (pix_fmt_id & 0x0F0F0F0F)>>1; ++ /* NOTE we do not allocate pictures large enough for the possible ++ * padding of h/v_count being 4 */ ++ if (!(pix_fmt_id & 0xD0D0D0D0)) ++ pix_fmt_id -= (pix_fmt_id & 0xF0F0F0F0) >> 1; ++ if (!(pix_fmt_id & 0x0D0D0D0D)) ++ pix_fmt_id -= (pix_fmt_id & 0x0F0F0F0F) >> 1; + +- switch(pix_fmt_id){ ++ switch (pix_fmt_id) { + case 0x11111100: +- if(s->rgb){ +- s->avctx->pix_fmt = PIX_FMT_BGRA; +- }else ++ if (s->rgb) ++ s->avctx->pix_fmt = PIX_FMT_BGR24; ++ else { ++ if (s->component_id[0] == 'Q' && s->component_id[1] == 'F' && s->component_id[2] == 'A') { ++ s->avctx->pix_fmt = PIX_FMT_GBR24P; ++ } else { + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; +- assert(s->nb_components==3); ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ } ++ } ++ assert(s->nb_components == 3); ++ break; ++ case 0x12121100: ++ case 0x22122100: ++ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ s->upscale_v = 2; ++ s->upscale_h = (pix_fmt_id == 0x22122100); ++ s->chroma_height = s->height; ++ break; ++ case 0x21211100: ++ case 0x22211200: ++ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ s->upscale_v = (pix_fmt_id == 0x22211200); ++ s->upscale_h = 2; ++ s->chroma_height = s->height; ++ break; ++ case 0x22221100: ++ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV444P : PIX_FMT_YUVJ444P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ s->upscale_v = 2; ++ s->upscale_h = 2; ++ s->chroma_height = s->height / 2; + break; + case 0x11000000: +- s->avctx->pix_fmt = PIX_FMT_GRAY8; ++ if(s->bits <= 8) ++ s->avctx->pix_fmt = PIX_FMT_GRAY8; ++ else ++ s->avctx->pix_fmt = PIX_FMT_GRAY16; + break; + case 0x12111100: ++ case 0x22211100: ++ case 0x22112100: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV440P : PIX_FMT_YUVJ440P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ s->upscale_h = (pix_fmt_id == 0x22211100) * 2 + (pix_fmt_id == 0x22112100); ++ s->chroma_height = s->height / 2; + break; + case 0x21111100: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ break; ++ case 0x22121100: ++ case 0x22111200: ++ s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV422P : PIX_FMT_YUVJ422P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; ++ s->upscale_v = (pix_fmt_id == 0x22121100) + 1; + break; + case 0x22111100: + s->avctx->pix_fmt = s->cs_itu601 ? PIX_FMT_YUV420P : PIX_FMT_YUVJ420P; ++ s->avctx->color_range = s->cs_itu601 ? AVCOL_RANGE_MPEG : AVCOL_RANGE_JPEG; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "Unhandled pixel format 0x%x\n", pix_fmt_id); + return -1; + } +- if(s->ls){ +- if(s->nb_components > 1) ++ if (s->ls) { ++ s->upscale_h = s->upscale_v = 0; ++ if (s->nb_components > 1) + s->avctx->pix_fmt = PIX_FMT_RGB24; +- else if(s->bits <= 8) ++ else if (s->bits <= 8) + s->avctx->pix_fmt = PIX_FMT_GRAY8; + else + s->avctx->pix_fmt = PIX_FMT_GRAY16; + } + +- if(s->picture.data[0]) +- s->avctx->release_buffer(s->avctx, &s->picture); ++ if (s->picture_ptr->data[0]) ++ s->avctx->release_buffer(s->avctx, s->picture_ptr); + +- s->picture.reference= 0; +- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ ++ if (s->avctx->get_buffer(s->avctx, s->picture_ptr) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- s->picture.pict_type= FF_I_TYPE; +- s->picture.key_frame= 1; +- s->got_picture = 1; +- +- for(i=0; i<3; i++){ +- s->linesize[i]= s->picture.linesize[i] << s->interlaced; +- } +- +-// printf("%d %d %d %d %d %d\n", s->width, s->height, s->linesize[0], s->linesize[1], s->interlaced, s->avctx->height); ++ s->picture_ptr->pict_type = AV_PICTURE_TYPE_I; ++ s->picture_ptr->key_frame = 1; ++ s->got_picture = 1; ++ ++ for (i = 0; i < 3; i++) ++ s->linesize[i] = s->picture_ptr->linesize[i] << s->interlaced; ++ ++// printf("%d %d %d %d %d %d\n", ++// s->width, s->height, s->linesize[0], s->linesize[1], ++// s->interlaced, s->avctx->height); + +- if (len != (8+(3*nb_components))) +- { ++ if (len != (8 + (3 * nb_components))) + av_log(s->avctx, AV_LOG_DEBUG, "decode_sof0: error, len(%d) mismatch\n", len); +- } + + /* totally blank picture as progressive JPEG will only add details to it */ +- if(s->progressive){ +- int bw = (width + s->h_max*8-1) / (s->h_max*8); +- int bh = (height + s->v_max*8-1) / (s->v_max*8); +- for(i=0; inb_components; i++) { ++ if (s->progressive) { ++ int bw = (width + s->h_max * 8 - 1) / (s->h_max * 8); ++ int bh = (height + s->v_max * 8 - 1) / (s->v_max * 8); ++ for (i = 0; i < s->nb_components; i++) { + int size = bw * bh * s->h_count[i] * s->v_count[i]; + av_freep(&s->blocks[i]); + av_freep(&s->last_nnz[i]); +- s->blocks[i] = av_malloc(size * sizeof(**s->blocks)); +- s->last_nnz[i] = av_mallocz(size * sizeof(**s->last_nnz)); ++ s->blocks[i] = av_malloc(size * sizeof(**s->blocks)); ++ s->last_nnz[i] = av_mallocz(size * sizeof(**s->last_nnz)); + s->block_stride[i] = bw * s->h_count[i]; + } + memset(s->coefs_finished, 0, sizeof(s->coefs_finished)); +@@ -386,22 +453,22 @@ + { + int code; + code = get_vlc2(&s->gb, s->vlcs[0][dc_index].table, 9, 2); +- if (code < 0) +- { +- av_log(s->avctx, AV_LOG_WARNING, "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", 0, dc_index, +- &s->vlcs[0][dc_index]); ++ if (code < 0) { ++ av_log(s->avctx, AV_LOG_WARNING, ++ "mjpeg_decode_dc: bad vlc: %d:%d (%p)\n", ++ 0, dc_index, &s->vlcs[0][dc_index]); + return 0xffff; + } + +- if(code) ++ if (code) + return get_xbits(&s->gb, code); + else + return 0; + } + + /* decode block and dequantize */ +-static int decode_block(MJpegDecodeContext *s, DCTELEM *block, +- int component, int dc_index, int ac_index, int16_t *quant_matrix) ++static int decode_block(MJpegDecodeContext *s, DCTELEM *block, int component, ++ int dc_index, int ac_index, int16_t *quant_matrix) + { + int code, i, j, level, val; + +@@ -423,14 +490,14 @@ + + i += ((unsigned)code) >> 4; + code &= 0xf; +- if(code){ +- if(code > MIN_CACHE_BITS - 16){ ++ if (code) { ++ if (code > MIN_CACHE_BITS - 16) + UPDATE_CACHE(re, &s->gb); +- } ++ + { +- int cache=GET_CACHE(re,&s->gb); +- int sign=(~cache)>>31; +- level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; ++ int cache = GET_CACHE(re, &s->gb); ++ int sign = (~cache) >> 31; ++ level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; + } + + LAST_SKIP_BITS(re, &s->gb, code); +@@ -439,17 +506,18 @@ + av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); + return -1; + } +- j = s->scantable.permutated[i]; ++ j = s->scantable.permutated[i]; + block[j] = level * quant_matrix[j]; + } +- }while(i<63); ++ } while (i < 63); + CLOSE_READER(re, &s->gb);} + + return 0; + } + +-static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, int component, +- int dc_index, int16_t *quant_matrix, int Al) ++static int decode_dc_progressive(MJpegDecodeContext *s, DCTELEM *block, ++ int component, int dc_index, ++ int16_t *quant_matrix, int Al) + { + int val; + s->dsp.clear_block(block); +@@ -465,113 +533,121 @@ + } + + /* decode block and dequantize - progressive JPEG version */ +-static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz, +- int ac_index, int16_t *quant_matrix, ++static int decode_block_progressive(MJpegDecodeContext *s, DCTELEM *block, ++ uint8_t *last_nnz, int ac_index, ++ int16_t *quant_matrix, + int ss, int se, int Al, int *EOBRUN) + { + int code, i, j, level, val, run; + +- if(*EOBRUN){ ++ if (*EOBRUN) { + (*EOBRUN)--; + return 0; + } +- {OPEN_READER(re, &s->gb); +- for(i=ss;;i++) { +- UPDATE_CACHE(re, &s->gb); +- GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2); + +- run = ((unsigned) code) >> 4; +- code &= 0xF; +- if(code) { +- i += run; +- if(code > MIN_CACHE_BITS - 16){ +- UPDATE_CACHE(re, &s->gb); +- } +- { +- int cache=GET_CACHE(re,&s->gb); +- int sign=(~cache)>>31; +- level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; +- } ++ { ++ OPEN_READER(re, &s->gb); ++ for (i = ss; ; i++) { ++ UPDATE_CACHE(re, &s->gb); ++ GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2); + +- LAST_SKIP_BITS(re, &s->gb, code); ++ run = ((unsigned) code) >> 4; ++ code &= 0xF; ++ if (code) { ++ i += run; ++ if (code > MIN_CACHE_BITS - 16) ++ UPDATE_CACHE(re, &s->gb); + +- if (i >= se) { +- if(i == se){ +- j = s->scantable.permutated[se]; +- block[j] = level * quant_matrix[j] << Al; +- break; ++ { ++ int cache = GET_CACHE(re, &s->gb); ++ int sign = (~cache) >> 31; ++ level = (NEG_USR32(sign ^ cache,code) ^ sign) - sign; + } +- av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); +- return -1; +- } +- j = s->scantable.permutated[i]; +- block[j] = level * quant_matrix[j] << Al; +- }else{ +- if(run == 0xF){// ZRL - skip 15 coefficients +- i += 15; ++ ++ LAST_SKIP_BITS(re, &s->gb, code); ++ + if (i >= se) { +- av_log(s->avctx, AV_LOG_ERROR, "ZRL overflow: %d\n", i); ++ if (i == se) { ++ j = s->scantable.permutated[se]; ++ block[j] = level * quant_matrix[j] << Al; ++ break; ++ } ++ av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); + return -1; + } +- }else{ +- val = (1 << run); +- if(run){ +- UPDATE_CACHE(re, &s->gb); +- val += NEG_USR32(GET_CACHE(re, &s->gb), run); +- LAST_SKIP_BITS(re, &s->gb, run); ++ j = s->scantable.permutated[i]; ++ block[j] = level * quant_matrix[j] << Al; ++ } else { ++ if (run == 0xF) {// ZRL - skip 15 coefficients ++ i += 15; ++ if (i >= se) { ++ av_log(s->avctx, AV_LOG_ERROR, "ZRL overflow: %d\n", i); ++ return -1; ++ } ++ } else { ++ val = (1 << run); ++ if (run) { ++ UPDATE_CACHE(re, &s->gb); ++ val += NEG_USR32(GET_CACHE(re, &s->gb), run); ++ LAST_SKIP_BITS(re, &s->gb, run); ++ } ++ *EOBRUN = val - 1; ++ break; + } +- *EOBRUN = val - 1; +- break; + } + } ++ CLOSE_READER(re, &s->gb); + } +- CLOSE_READER(re, &s->gb);} +- if(i > *last_nnz) ++ ++ if (i > *last_nnz) + *last_nnz = i; ++ + return 0; + } + +-#define REFINE_BIT(j) {\ +- UPDATE_CACHE(re, &s->gb);\ +- sign = block[j]>>15;\ +- block[j] += SHOW_UBITS(re, &s->gb, 1) * ((quant_matrix[j]^sign)-sign) << Al;\ +- LAST_SKIP_BITS(re, &s->gb, 1);\ +-} +- +-#define ZERO_RUN \ +-for(;;i++) {\ +- if(i > last) {\ +- i += run;\ +- if(i > se) {\ +- av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i);\ +- return -1;\ +- }\ +- break;\ +- }\ +- j = s->scantable.permutated[i];\ +- if(block[j])\ +- REFINE_BIT(j)\ +- else if(run-- == 0)\ +- break;\ ++#define REFINE_BIT(j) { \ ++ UPDATE_CACHE(re, &s->gb); \ ++ sign = block[j] >> 15; \ ++ block[j] += SHOW_UBITS(re, &s->gb, 1) * \ ++ ((quant_matrix[j] ^ sign) - sign) << Al; \ ++ LAST_SKIP_BITS(re, &s->gb, 1); \ ++} ++ ++#define ZERO_RUN \ ++for (; ; i++) { \ ++ if (i > last) { \ ++ i += run; \ ++ if (i > se) { \ ++ av_log(s->avctx, AV_LOG_ERROR, "error count: %d\n", i); \ ++ return -1; \ ++ } \ ++ break; \ ++ } \ ++ j = s->scantable.permutated[i]; \ ++ if (block[j]) \ ++ REFINE_BIT(j) \ ++ else if (run-- == 0) \ ++ break; \ + } + + /* decode block and dequantize - progressive JPEG refinement pass */ +-static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, uint8_t *last_nnz, +- int ac_index, int16_t *quant_matrix, +- int ss, int se, int Al, int *EOBRUN) ++static int decode_block_refinement(MJpegDecodeContext *s, DCTELEM *block, ++ uint8_t *last_nnz, ++ int ac_index, int16_t *quant_matrix, ++ int ss, int se, int Al, int *EOBRUN) + { +- int code, i=ss, j, sign, val, run; +- int last = FFMIN(se, *last_nnz); ++ int code, i = ss, j, sign, val, run; ++ int last = FFMIN(se, *last_nnz); + + OPEN_READER(re, &s->gb); +- if(*EOBRUN) ++ if (*EOBRUN) { + (*EOBRUN)--; +- else { +- for(;;i++) { ++ } else { ++ for (; ; i++) { + UPDATE_CACHE(re, &s->gb); + GET_VLC(code, re, &s->gb, s->vlcs[2][ac_index].table, 9, 2); + +- if(code & 0xF) { ++ if (code & 0xF) { + run = ((unsigned) code) >> 4; + UPDATE_CACHE(re, &s->gb); + val = SHOW_UBITS(re, &s->gb, 1); +@@ -579,21 +655,21 @@ + ZERO_RUN; + j = s->scantable.permutated[i]; + val--; +- block[j] = ((quant_matrix[j]^val)-val) << Al; +- if(i == se) { +- if(i > *last_nnz) ++ block[j] = ((quant_matrix[j]^val) - val) << Al; ++ if (i == se) { ++ if (i > *last_nnz) + *last_nnz = i; + CLOSE_READER(re, &s->gb); + return 0; + } +- }else{ ++ } else { + run = ((unsigned) code) >> 4; +- if(run == 0xF){ ++ if (run == 0xF) { + ZERO_RUN; +- }else{ ++ } else { + val = run; + run = (1 << run); +- if(val) { ++ if (val) { + UPDATE_CACHE(re, &s->gb); + run += SHOW_UBITS(re, &s->gb, val); + LAST_SKIP_BITS(re, &s->gb, val); +@@ -604,13 +680,13 @@ + } + } + +- if(i > *last_nnz) ++ if (i > *last_nnz) + *last_nnz = i; + } + +- for(;i<=last;i++) { ++ for (; i <= last; i++) { + j = s->scantable.permutated[i]; +- if(block[j]) ++ if (block[j]) + REFINE_BIT(j) + } + CLOSE_READER(re, &s->gb); +@@ -620,43 +696,61 @@ + #undef REFINE_BIT + #undef ZERO_RUN + +-static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int predictor, int point_transform){ ++static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int predictor, int point_transform) ++{ + int i, mb_x, mb_y; + uint16_t (*buffer)[4]; + int left[3], top[3], topleft[3]; +- const int linesize= s->linesize[0]; +- const int mask= (1<bits)-1; ++ const int linesize = s->linesize[0]; ++ const int mask = (1 << s->bits) - 1; ++ int resync_mb_y = 0; ++ int resync_mb_x = 0; + +- av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0])); +- buffer= s->ljpeg_buffer; ++ s->restart_count = s->restart_interval; + +- for(i=0; i<3; i++){ +- buffer[0][i]= 1 << (s->bits + point_transform - 1); +- } +- for(mb_y = 0; mb_y < s->mb_height; mb_y++) { +- const int modified_predictor= mb_y ? predictor : 1; ++ av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size, ++ (unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0])); ++ buffer = s->ljpeg_buffer; ++ ++ for (i = 0; i < 3; i++) ++ buffer[0][i] = 1 << (s->bits - 1); ++ ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + uint8_t *ptr = s->picture.data[0] + (linesize * mb_y); + + if (s->interlaced && s->bottom_field) + ptr += linesize >> 1; + +- for(i=0; i<3; i++){ +- top[i]= left[i]= topleft[i]= buffer[0][i]; +- } +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { +- if (s->restart_interval && !s->restart_count) ++ for (i = 0; i < 3; i++) ++ top[i] = left[i] = topleft[i] = buffer[0][i]; ++ ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ int modified_predictor = predictor; ++ ++ if (s->restart_interval && !s->restart_count){ + s->restart_count = s->restart_interval; ++ resync_mb_x = mb_x; ++ resync_mb_y = mb_y; ++ for(i=0; i<3; i++) ++ top[i] = left[i]= topleft[i]= 1 << (s->bits - 1); ++ } ++ if (mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x || !mb_x) ++ modified_predictor = 1; + +- for(i=0;i<3;i++) { +- int pred; ++ for (i=0;idc_index[i]) << point_transform)); ++ dc = mjpeg_decode_dc(s, s->dc_index[i]); ++ if(dc == 0xFFFF) ++ return -1; ++ ++ left[i] = buffer[mb_x][i] = ++ mask & (pred + (dc << point_transform)); + } + + if (s->restart_interval && !--s->restart_count) { +@@ -665,41 +759,57 @@ + } + } + +- if(s->rct){ +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { +- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200)>>2); +- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; +- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; +- } +- }else if(s->pegasus_rct){ +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { +- ptr[4*mb_x+1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2])>>2); +- ptr[4*mb_x+0] = buffer[mb_x][1] + ptr[4*mb_x+1]; +- ptr[4*mb_x+2] = buffer[mb_x][2] + ptr[4*mb_x+1]; +- } +- }else{ +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { +- ptr[4*mb_x+0] = buffer[mb_x][2]; +- ptr[4*mb_x+1] = buffer[mb_x][1]; +- ptr[4*mb_x+2] = buffer[mb_x][0]; ++ if (s->rct) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2] - 0x200) >> 2); ++ ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1]; ++ ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1]; ++ } ++ } else if (s->pegasus_rct) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ ptr[3*mb_x + 1] = buffer[mb_x][0] - ((buffer[mb_x][1] + buffer[mb_x][2]) >> 2); ++ ptr[3*mb_x + 0] = buffer[mb_x][1] + ptr[3*mb_x + 1]; ++ ptr[3*mb_x + 2] = buffer[mb_x][2] + ptr[3*mb_x + 1]; ++ } ++ } else { ++ for(i=0; icomp_index[i]; ++ for(mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ ptr[3*mb_x+2-c] = buffer[mb_x][i]; ++ } + } + } + } + return 0; + } + +-static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, int point_transform){ ++static int ljpeg_decode_yuv_scan(MJpegDecodeContext *s, int predictor, ++ int point_transform) ++{ + int i, mb_x, mb_y; +- const int nb_components=3; +- +- for(mb_y = 0; mb_y < s->mb_height; mb_y++) { +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { +- if (s->restart_interval && !s->restart_count) ++ const int nb_components=s->nb_components; ++ int bits= (s->bits+7)&~7; ++ int resync_mb_y = 0; ++ int resync_mb_x = 0; ++ ++ point_transform += bits - s->bits; ++ ++ av_assert0(nb_components==1 || nb_components==3); ++ ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ if (s->restart_interval && !s->restart_count){ + s->restart_count = s->restart_interval; ++ resync_mb_x = mb_x; ++ resync_mb_y = mb_y; ++ } + +- if(mb_x==0 || mb_y==0 || s->interlaced){ +- for(i=0;iinterlaced){ ++ int toprow = mb_y == resync_mb_y || mb_y == resync_mb_y+1 && mb_x < resync_mb_x; ++ int leftcol = !mb_x || mb_y == resync_mb_y && mb_x == resync_mb_x; ++ for (i = 0; i < nb_components; i++) { + uint8_t *ptr; ++ uint16_t *ptr16; + int n, h, v, x, y, c, j, linesize; + n = s->nb_blocks[i]; + c = s->comp_index[i]; +@@ -709,18 +819,24 @@ + y = 0; + linesize= s->linesize[c]; + ++ if(bits>8) linesize /= 2; ++ + for(j=0; jdc_index[i]); ++ if(dc == 0xFFFF) ++ return -1; ++ if(bits<=8){ + ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap +- if(y==0 && mb_y==0){ +- if(x==0 && mb_x==0){ +- pred= 128 << point_transform; ++ if(y==0 && toprow){ ++ if(x==0 && leftcol){ ++ pred= 1 << (bits - 1); + }else{ + pred= ptr[-1]; + } + }else{ +- if(x==0 && mb_x==0){ ++ if(x==0 && leftcol){ + pred= ptr[-linesize]; + }else{ + PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); +@@ -729,32 +845,72 @@ + + if (s->interlaced && s->bottom_field) + ptr += linesize >> 1; +- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); ++ pred &= (-1)<<(8-s->bits); ++ *ptr= pred + (dc << point_transform); ++ }else{ ++ ptr16 = s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x); //FIXME optimize this crap ++ if(y==0 && toprow){ ++ if(x==0 && leftcol){ ++ pred= 1 << (bits - 1); ++ }else{ ++ pred= ptr16[-1]; ++ } ++ }else{ ++ if(x==0 && leftcol){ ++ pred= ptr16[-linesize]; ++ }else{ ++ PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor); ++ } ++ } + ++ if (s->interlaced && s->bottom_field) ++ ptr16 += linesize >> 1; ++ pred &= (-1)<<(16-s->bits); ++ *ptr16= pred + (dc << point_transform); ++ } + if (++x == h) { + x = 0; + y++; + } + } + } +- }else{ +- for(i=0;inb_blocks[i]; +- c = s->comp_index[i]; +- h = s->h_scount[i]; +- v = s->v_scount[i]; +- x = 0; +- y = 0; +- linesize= s->linesize[c]; ++ uint16_t *ptr16; ++ int n, h, v, x, y, c, j, linesize, dc; ++ n = s->nb_blocks[i]; ++ c = s->comp_index[i]; ++ h = s->h_scount[i]; ++ v = s->v_scount[i]; ++ x = 0; ++ y = 0; ++ linesize = s->linesize[c]; + +- for(j=0; j8) linesize /= 2; ++ ++ for (j = 0; j < n; j++) { + int pred; + +- ptr = s->picture.data[c] + (linesize * (v * mb_y + y)) + (h * mb_x + x); //FIXME optimize this crap +- PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); +- *ptr= pred + (mjpeg_decode_dc(s, s->dc_index[i]) << point_transform); ++ dc = mjpeg_decode_dc(s, s->dc_index[i]); ++ if(dc == 0xFFFF) ++ return -1; ++ if(bits<=8){ ++ ptr = s->picture.data[c] + ++ (linesize * (v * mb_y + y)) + ++ (h * mb_x + x); //FIXME optimize this crap ++ PREDICT(pred, ptr[-linesize-1], ptr[-linesize], ptr[-1], predictor); ++ ++ pred &= (-1)<<(8-s->bits); ++ *ptr = pred + (dc << point_transform); ++ }else{ ++ ptr16 = s->picture.data[c] + 2*(linesize * (v * mb_y + y)) + 2*(h * mb_x + x); //FIXME optimize this crap ++ PREDICT(pred, ptr16[-linesize-1], ptr16[-linesize], ptr16[-1], predictor); ++ ++ pred &= (-1)<<(16-s->bits); ++ *ptr16= pred + (dc << point_transform); ++ } ++ + if (++x == h) { + x = 0; + y++; +@@ -771,68 +927,120 @@ + return 0; + } + +-static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, int Al){ ++static av_always_inline void mjpeg_copy_block(uint8_t *dst, const uint8_t *src, ++ int linesize, int lowres) ++{ ++ switch (lowres) { ++ case 0: copy_block8(dst, src, linesize, linesize, 8); ++ break; ++ case 1: copy_block4(dst, src, linesize, linesize, 4); ++ break; ++ case 2: copy_block2(dst, src, linesize, linesize, 2); ++ break; ++ case 3: *dst = *src; ++ break; ++ } ++} ++ ++static int mjpeg_decode_scan(MJpegDecodeContext *s, int nb_components, int Ah, ++ int Al, const uint8_t *mb_bitmask, ++ const AVFrame *reference) ++{ + int i, mb_x, mb_y; +- uint8_t* data[MAX_COMPONENTS]; ++ uint8_t *data[MAX_COMPONENTS]; ++ const uint8_t *reference_data[MAX_COMPONENTS]; + int linesize[MAX_COMPONENTS]; ++ GetBitContext mb_bitmask_gb; ++ ++ if (mb_bitmask) ++ init_get_bits(&mb_bitmask_gb, mb_bitmask, s->mb_width * s->mb_height); + +- if(s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) { +- av_log(s->avctx, AV_LOG_ERROR, "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n"); ++ if (s->flipped && s->avctx->flags & CODEC_FLAG_EMU_EDGE) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Can not flip image with CODEC_FLAG_EMU_EDGE set!\n"); + s->flipped = 0; + } +- for(i=0; i < nb_components; i++) { +- int c = s->comp_index[i]; +- data[c] = s->picture.data[c]; +- linesize[c]=s->linesize[c]; ++ ++ for (i = 0; i < nb_components; i++) { ++ int c = s->comp_index[i]; ++ data[c] = s->picture_ptr->data[c]; ++ reference_data[c] = reference ? reference->data[c] : NULL; ++ linesize[c] = s->linesize[c]; + s->coefs_finished[c] |= 1; +- if(s->flipped) { +- //picture should be flipped upside-down for this codec +- data[c] += (linesize[c] * (s->v_scount[i] * (8 * s->mb_height -((s->height/s->v_max)&7)) - 1 )); +- linesize[c] *= -1; ++ if (s->flipped) { ++ // picture should be flipped upside-down for this codec ++ int offset = (linesize[c] * (s->v_scount[i] * ++ (8 * s->mb_height - ((s->height / s->v_max) & 7)) - 1)); ++ data[c] += offset; ++ reference_data[c] += offset; ++ linesize[c] *= -1; + } + } + +- for(mb_y = 0; mb_y < s->mb_height; mb_y++) { +- for(mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ const int copy_mb = mb_bitmask && !get_bits1(&mb_bitmask_gb); ++ + if (s->restart_interval && !s->restart_count) + s->restart_count = s->restart_interval; + +- for(i=0;igb) < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "overread %d\n", ++ -get_bits_left(&s->gb)); ++ return -1; ++ } ++ for (i = 0; i < nb_components; i++) { + uint8_t *ptr; + int n, h, v, x, y, c, j; ++ int block_offset; + n = s->nb_blocks[i]; + c = s->comp_index[i]; + h = s->h_scount[i]; + v = s->v_scount[i]; + x = 0; + y = 0; +- for(j=0;j> s->avctx->lowres); +- if(s->interlaced && s->bottom_field) +- ptr += linesize[c] >> 1; +- if(!s->progressive) { +- s->dsp.clear_block(s->block); +- if(decode_block(s, s->block, i, +- s->dc_index[i], s->ac_index[i], +- s->quant_matrixes[ s->quant_index[c] ]) < 0) { +- av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); +- return -1; ++ for (j = 0; j < n; j++) { ++ block_offset = (((linesize[c] * (v * mb_y + y) * 8) + ++ (h * mb_x + x) * 8) >> s->avctx->lowres); ++ ++ if (s->interlaced && s->bottom_field) ++ block_offset += linesize[c] >> 1; ++ ptr = data[c] + block_offset; ++ if (!s->progressive) { ++ if (copy_mb) ++ mjpeg_copy_block(ptr, reference_data[c] + block_offset, ++ linesize[c], s->avctx->lowres); ++ else { ++ s->dsp.clear_block(s->block); ++ if (decode_block(s, s->block, i, ++ s->dc_index[i], s->ac_index[i], ++ s->quant_matrixes[s->quant_index[c]]) < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "error y=%d x=%d\n", mb_y, mb_x); ++ return -1; ++ } ++ s->dsp.idct_put(ptr, linesize[c], s->block); + } +- s->dsp.idct_put(ptr, linesize[c], s->block); + } else { +- int block_idx = s->block_stride[c] * (v * mb_y + y) + (h * mb_x + x); ++ int block_idx = s->block_stride[c] * (v * mb_y + y) + ++ (h * mb_x + x); + DCTELEM *block = s->blocks[c][block_idx]; +- if(Ah) +- block[0] += get_bits1(&s->gb) * s->quant_matrixes[ s->quant_index[c] ][0] << Al; +- else if(decode_dc_progressive(s, block, i, s->dc_index[i], s->quant_matrixes[ s->quant_index[c] ], Al) < 0) { +- av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); ++ if (Ah) ++ block[0] += get_bits1(&s->gb) * ++ s->quant_matrixes[s->quant_index[c]][0] << Al; ++ else if (decode_dc_progressive(s, block, i, s->dc_index[i], ++ s->quant_matrixes[s->quant_index[c]], ++ Al) < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "error y=%d x=%d\n", mb_y, mb_x); + return -1; + } + } +-// av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", mb_y, mb_x); +-//av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", mb_x, mb_y, x, y, c, s->bottom_field, (v * mb_y + y) * 8, (h * mb_x + x) * 8); ++ // av_log(s->avctx, AV_LOG_DEBUG, "mb: %d %d processed\n", ++ // mb_y, mb_x); ++ // av_log(NULL, AV_LOG_DEBUG, "%d %d %d %d %d %d %d %d \n", ++ // mb_x, mb_y, x, y, c, s->bottom_field, ++ // (v * mb_y + y) * 8, (h * mb_x + x) * 8); + if (++x == h) { + x = 0; + y++; +@@ -840,89 +1048,110 @@ + } + } + +- if (s->restart_interval && !--s->restart_count) { +- align_get_bits(&s->gb); +- skip_bits(&s->gb, 16); /* skip RSTn */ +- for (i=0; ilast_dc[i] = 1024; ++ if (s->restart_interval) { ++ s->restart_count--; ++ if(s->restart_count == 0 && s->avctx->codec_id == CODEC_ID_THP){ ++ align_get_bits(&s->gb); ++ for (i = 0; i < nb_components; i++) /* reset dc */ ++ s->last_dc[i] = 1024; ++ } ++ ++ i = 8 + ((-get_bits_count(&s->gb)) & 7); ++ /* skip RSTn */ ++ if (show_bits(&s->gb, i) == (1 << i) - 1) { ++ int pos = get_bits_count(&s->gb); ++ align_get_bits(&s->gb); ++ while (get_bits_left(&s->gb) >= 8 && show_bits(&s->gb, 8) == 0xFF) ++ skip_bits(&s->gb, 8); ++ if (get_bits_left(&s->gb) >= 8 && (get_bits(&s->gb, 8) & 0xF8) == 0xD0) { ++ for (i = 0; i < nb_components; i++) /* reset dc */ ++ s->last_dc[i] = 1024; ++ } else ++ skip_bits_long(&s->gb, pos - get_bits_count(&s->gb)); ++ } + } + } + } + return 0; + } + +-static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, int se, int Ah, int Al){ ++static int mjpeg_decode_scan_progressive_ac(MJpegDecodeContext *s, int ss, ++ int se, int Ah, int Al) ++{ + int mb_x, mb_y; + int EOBRUN = 0; + int c = s->comp_index[0]; +- uint8_t* data = s->picture.data[c]; +- int linesize = s->linesize[c]; ++ uint8_t *data = s->picture.data[c]; ++ int linesize = s->linesize[c]; + int last_scan = 0; +- int16_t *quant_matrix = s->quant_matrixes[ s->quant_index[c] ]; ++ int16_t *quant_matrix = s->quant_matrixes[s->quant_index[c]]; + +- if(!Al) { +- s->coefs_finished[c] |= (1LL<<(se+1))-(1LL<coefs_finished[c] |= (1LL << (se + 1)) - (1LL << ss); + last_scan = !~s->coefs_finished[c]; + } + +- if(s->interlaced && s->bottom_field) ++ if (s->interlaced && s->bottom_field) + data += linesize >> 1; + +- for(mb_y = 0; mb_y < s->mb_height; mb_y++) { +- uint8_t *ptr = data + (mb_y*linesize*8 >> s->avctx->lowres); +- int block_idx = mb_y * s->block_stride[c]; ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { ++ uint8_t *ptr = data + (mb_y * linesize * 8 >> s->avctx->lowres); ++ int block_idx = mb_y * s->block_stride[c]; + DCTELEM (*block)[64] = &s->blocks[c][block_idx]; +- uint8_t *last_nnz = &s->last_nnz[c][block_idx]; +- for(mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) { +- int ret; +- if(Ah) +- ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0], +- quant_matrix, ss, se, Al, &EOBRUN); +- else +- ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0], +- quant_matrix, ss, se, Al, &EOBRUN); +- if(ret < 0) { +- av_log(s->avctx, AV_LOG_ERROR, "error y=%d x=%d\n", mb_y, mb_x); +- return -1; +- } +- if(last_scan) { +- s->dsp.idct_put(ptr, linesize, *block); +- ptr += 8 >> s->avctx->lowres; ++ uint8_t *last_nnz = &s->last_nnz[c][block_idx]; ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++, block++, last_nnz++) { ++ int ret; ++ if (Ah) ++ ret = decode_block_refinement(s, *block, last_nnz, s->ac_index[0], ++ quant_matrix, ss, se, Al, &EOBRUN); ++ else ++ ret = decode_block_progressive(s, *block, last_nnz, s->ac_index[0], ++ quant_matrix, ss, se, Al, &EOBRUN); ++ if (ret < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "error y=%d x=%d\n", mb_y, mb_x); ++ return -1; ++ } ++ ++ if (last_scan) { ++ s->dsp.idct_put(ptr, linesize, *block); ++ ptr += 8 >> s->avctx->lowres; + } + } + } + return 0; + } + +-int ff_mjpeg_decode_sos(MJpegDecodeContext *s) ++int ff_mjpeg_decode_sos(MJpegDecodeContext *s, const uint8_t *mb_bitmask, ++ const AVFrame *reference) + { + int len, nb_components, i, h, v, predictor, point_transform; + int index, id; +- const int block_size= s->lossless ? 1 : 8; ++ const int block_size = s->lossless ? 1 : 8; + int ilv, prev_shift; + + /* XXX: verify len field validity */ + len = get_bits(&s->gb, 16); + nb_components = get_bits(&s->gb, 8); +- if (nb_components == 0 || nb_components > MAX_COMPONENTS){ +- av_log(s->avctx, AV_LOG_ERROR, "decode_sos: nb_components (%d) unsupported\n", nb_components); ++ if (nb_components == 0 || nb_components > MAX_COMPONENTS) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "decode_sos: nb_components (%d) unsupported\n", nb_components); + return -1; + } +- if (len != 6+2*nb_components) +- { ++ if (len != 6 + 2 * nb_components) { + av_log(s->avctx, AV_LOG_ERROR, "decode_sos: invalid len (%d)\n", len); + return -1; + } +- for(i=0;igb, 8) - 1; + av_log(s->avctx, AV_LOG_DEBUG, "component: %d\n", id); + /* find component index */ +- for(index=0;indexnb_components;index++) ++ for (index = 0; index < s->nb_components; index++) + if (id == s->component_id[index]) + break; +- if (index == s->nb_components) +- { +- av_log(s->avctx, AV_LOG_ERROR, "decode_sos: index(%d) out of components\n", index); ++ if (index == s->nb_components) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "decode_sos: index(%d) out of components\n", index); + return -1; + } + /* Metasoft MJPEG codec has Cb and Cr swapped */ +@@ -930,11 +1159,14 @@ + && nb_components == 3 && s->nb_components == 3 && i) + index = 3 - i; + ++ if(nb_components == 3 && s->nb_components == 3 && s->avctx->pix_fmt == PIX_FMT_GBR24P) ++ index = (i+2)%3; ++ + s->comp_index[i] = index; + + s->nb_blocks[i] = s->h_count[index] * s->v_count[index]; +- s->h_scount[i] = s->h_count[index]; +- s->v_scount[i] = s->v_count[index]; ++ s->h_scount[i] = s->h_count[index]; ++ s->v_scount[i] = s->v_count[index]; + + s->dc_index[i] = get_bits(&s->gb, 4); + s->ac_index[i] = get_bits(&s->gb, 4); +@@ -942,64 +1174,72 @@ + if (s->dc_index[i] < 0 || s->ac_index[i] < 0 || + s->dc_index[i] >= 4 || s->ac_index[i] >= 4) + goto out_of_range; +- if (!s->vlcs[0][s->dc_index[i]].table || !s->vlcs[1][s->ac_index[i]].table) ++ if (!s->vlcs[0][s->dc_index[i]].table || !(s->progressive ? s->vlcs[2][s->ac_index[0]].table : s->vlcs[1][s->ac_index[i]].table)) + goto out_of_range; + } + +- predictor= get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ +- ilv= get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ +- prev_shift = get_bits(&s->gb, 4); /* Ah */ +- point_transform= get_bits(&s->gb, 4); /* Al */ ++ predictor = get_bits(&s->gb, 8); /* JPEG Ss / lossless JPEG predictor /JPEG-LS NEAR */ ++ ilv = get_bits(&s->gb, 8); /* JPEG Se / JPEG-LS ILV */ ++ if(s->avctx->codec_tag != AV_RL32("CJPG")){ ++ prev_shift = get_bits(&s->gb, 4); /* Ah */ ++ point_transform = get_bits(&s->gb, 4); /* Al */ ++ }else ++ prev_shift = point_transform = 0; + +- for(i=0;ilast_dc[i] = 1024; + + if (nb_components > 1) { + /* interleaved stream */ + s->mb_width = (s->width + s->h_max * block_size - 1) / (s->h_max * block_size); + s->mb_height = (s->height + s->v_max * block_size - 1) / (s->v_max * block_size); +- } else if(!s->ls) { /* skip this for JPEG-LS */ ++ } else if (!s->ls) { /* skip this for JPEG-LS */ + h = s->h_max / s->h_scount[0]; + v = s->v_max / s->v_scount[0]; +- s->mb_width = (s->width + h * block_size - 1) / (h * block_size); +- s->mb_height = (s->height + v * block_size - 1) / (v * block_size); ++ s->mb_width = (s->width + h * block_size - 1) / (h * block_size); ++ s->mb_height = (s->height + v * block_size - 1) / (v * block_size); + s->nb_blocks[0] = 1; +- s->h_scount[0] = 1; +- s->v_scount[0] = 1; ++ s->h_scount[0] = 1; ++ s->v_scount[0] = 1; + } + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) +- av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d %s\n", s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "", +- predictor, point_transform, ilv, s->bits, +- s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : "")); ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) ++ av_log(s->avctx, AV_LOG_DEBUG, "%s %s p:%d >>:%d ilv:%d bits:%d skip:%d %s comp:%d\n", ++ s->lossless ? "lossless" : "sequential DCT", s->rgb ? "RGB" : "", ++ predictor, point_transform, ilv, s->bits, s->mjpb_skiptosod, ++ s->pegasus_rct ? "PRCT" : (s->rct ? "RCT" : ""), nb_components); + + + /* mjpeg-b can have padding bytes between sos and image data, skip them */ + for (i = s->mjpb_skiptosod; i > 0; i--) + skip_bits(&s->gb, 8); + +- if(s->lossless){ +- if(CONFIG_JPEGLS_DECODER && s->ls){ +-// for(){ ++ if (s->lossless) { ++ av_assert0(s->picture_ptr == &s->picture); ++ if (CONFIG_JPEGLS_DECODER && s->ls) { ++// for () { + // reset_ls_coding_parameters(s, 0); + +- if(ff_jpegls_decode_picture(s, predictor, point_transform, ilv) < 0) ++ if (ff_jpegls_decode_picture(s, predictor, point_transform, ilv) < 0) + return -1; +- }else{ +- if(s->rgb){ +- if(ljpeg_decode_rgb_scan(s, predictor, point_transform) < 0) ++ } else { ++ if (s->rgb) { ++ if (ljpeg_decode_rgb_scan(s, nb_components, predictor, point_transform) < 0) + return -1; +- }else{ +- if(ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0) ++ } else { ++ if (ljpeg_decode_yuv_scan(s, predictor, point_transform) < 0) + return -1; + } + } +- }else{ +- if(s->progressive && predictor) { +- if(mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, point_transform) < 0) ++ } else { ++ if (s->progressive && predictor) { ++ av_assert0(s->picture_ptr == &s->picture); ++ if (mjpeg_decode_scan_progressive_ac(s, predictor, ilv, prev_shift, ++ point_transform) < 0) + return -1; + } else { +- if(mjpeg_decode_scan(s, nb_components, prev_shift, point_transform) < 0) ++ if (mjpeg_decode_scan(s, nb_components, prev_shift, point_transform, ++ mb_bitmask, reference) < 0) + return -1; + } + } +@@ -1015,8 +1255,9 @@ + if (get_bits(&s->gb, 16) != 4) + return -1; + s->restart_interval = get_bits(&s->gb, 16); +- s->restart_count = 0; +- av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", s->restart_interval); ++ s->restart_count = 0; ++ av_log(s->avctx, AV_LOG_DEBUG, "restart interval: %d\n", ++ s->restart_interval); + + return 0; + } +@@ -1028,22 +1269,20 @@ + len = get_bits(&s->gb, 16); + if (len < 5) + return -1; +- if(8*len + get_bits_count(&s->gb) > s->gb.size_in_bits) ++ if (8 * len > get_bits_left(&s->gb)) + return -1; + +- id = get_bits_long(&s->gb, 32); +- id = av_be2ne32(id); ++ id = get_bits_long(&s->gb, 32); ++ id = av_be2ne32(id); + len -= 6; + +- if(s->avctx->debug & FF_DEBUG_STARTCODE){ ++ if (s->avctx->debug & FF_DEBUG_STARTCODE) + av_log(s->avctx, AV_LOG_DEBUG, "APPx %8X\n", id); +- } + +- /* buggy AVID, it puts EOI only at every 10th frame */ +- /* also this fourcc is used by non-avid files too, it holds some +- informations, but it's always present in AVID creates files */ +- if (id == AV_RL32("AVI1")) +- { ++ /* Buggy AVID, it puts EOI only at every 10th frame. */ ++ /* Also, this fourcc is used by non-avid files too, it holds some ++ information, but it's always present in AVID-created files. */ ++ if (id == AV_RL32("AVI1")) { + /* structure: + 4bytes AVI1 + 1bytes polarity +@@ -1054,9 +1293,8 @@ + s->buggy_avid = 1; + // if (s->first_picture) + // printf("mjpeg: workarounding buggy AVID\n"); +- i = get_bits(&s->gb, 8); +- if (i==2) s->bottom_field= 1; +- else if(i==1) s->bottom_field= 0; ++ i = get_bits(&s->gb, 8); len--; ++ av_log(s->avctx, AV_LOG_DEBUG, "polarity %d\n", i); + #if 0 + skip_bits(&s->gb, 8); + skip_bits(&s->gb, 32); +@@ -1070,63 +1308,61 @@ + + // len -= 2; + +- if (id == AV_RL32("JFIF")) +- { ++ if (id == AV_RL32("JFIF")) { + int t_w, t_h, v1, v2; + skip_bits(&s->gb, 8); /* the trailing zero-byte */ +- v1= get_bits(&s->gb, 8); +- v2= get_bits(&s->gb, 8); ++ v1 = get_bits(&s->gb, 8); ++ v2 = get_bits(&s->gb, 8); + skip_bits(&s->gb, 8); + +- s->avctx->sample_aspect_ratio.num= get_bits(&s->gb, 16); +- s->avctx->sample_aspect_ratio.den= get_bits(&s->gb, 16); ++ s->avctx->sample_aspect_ratio.num = get_bits(&s->gb, 16); ++ s->avctx->sample_aspect_ratio.den = get_bits(&s->gb, 16); + + if (s->avctx->debug & FF_DEBUG_PICT_INFO) +- av_log(s->avctx, AV_LOG_INFO, "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n", +- v1, v2, +- s->avctx->sample_aspect_ratio.num, +- s->avctx->sample_aspect_ratio.den +- ); ++ av_log(s->avctx, AV_LOG_INFO, ++ "mjpeg: JFIF header found (version: %x.%x) SAR=%d/%d\n", ++ v1, v2, ++ s->avctx->sample_aspect_ratio.num, ++ s->avctx->sample_aspect_ratio.den); + + t_w = get_bits(&s->gb, 8); + t_h = get_bits(&s->gb, 8); +- if (t_w && t_h) +- { ++ if (t_w && t_h) { + /* skip thumbnail */ +- if (len-10-(t_w*t_h*3) > 0) +- len -= t_w*t_h*3; ++ if (len -10 - (t_w * t_h * 3) > 0) ++ len -= t_w * t_h * 3; + } + len -= 10; + goto out; + } + +- if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e')) +- { ++ if (id == AV_RL32("Adob") && (get_bits(&s->gb, 8) == 'e')) { + if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg: Adobe header found\n"); + skip_bits(&s->gb, 16); /* version */ + skip_bits(&s->gb, 16); /* flags0 */ + skip_bits(&s->gb, 16); /* flags1 */ +- skip_bits(&s->gb, 8); /* transform */ ++ skip_bits(&s->gb, 8); /* transform */ + len -= 7; + goto out; + } + +- if (id == AV_RL32("LJIF")){ ++ if (id == AV_RL32("LJIF")) { + if (s->avctx->debug & FF_DEBUG_PICT_INFO) +- av_log(s->avctx, AV_LOG_INFO, "Pegasus lossless jpeg header found\n"); ++ av_log(s->avctx, AV_LOG_INFO, ++ "Pegasus lossless jpeg header found\n"); + skip_bits(&s->gb, 16); /* version ? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ + skip_bits(&s->gb, 16); /* unknwon always 0? */ +- switch( get_bits(&s->gb, 8)){ ++ switch (get_bits(&s->gb, 8)) { + case 1: +- s->rgb= 1; +- s->pegasus_rct=0; ++ s->rgb = 1; ++ s->pegasus_rct = 0; + break; + case 2: +- s->rgb= 1; +- s->pegasus_rct=1; ++ s->rgb = 1; ++ s->pegasus_rct = 1; + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "unknown colorspace\n"); +@@ -1136,13 +1372,12 @@ + } + + /* Apple MJPEG-A */ +- if ((s->start_code == APP1) && (len > (0x28 - 8))) +- { +- id = get_bits_long(&s->gb, 32); +- id = av_be2ne32(id); ++ if ((s->start_code == APP1) && (len > (0x28 - 8))) { ++ id = get_bits_long(&s->gb, 32); ++ id = av_be2ne32(id); + len -= 4; +- if (id == AV_RL32("mjpg")) /* Apple MJPEG-A */ +- { ++ /* Apple MJPEG-A */ ++ if (id == AV_RL32("mjpg")) { + #if 0 + skip_bits(&s->gb, 32); /* field size */ + skip_bits(&s->gb, 32); /* pad field size */ +@@ -1161,8 +1396,9 @@ + out: + /* slow but needed for extreme adobe jpegs */ + if (len < 0) +- av_log(s->avctx, AV_LOG_ERROR, "mjpeg: error, decode_app parser read over the end\n"); +- while(--len > 0) ++ av_log(s->avctx, AV_LOG_ERROR, ++ "mjpeg: error, decode_app parser read over the end\n"); ++ while (--len > 0) + skip_bits(&s->gb, 8); + + return 0; +@@ -1171,34 +1407,30 @@ + static int mjpeg_decode_com(MJpegDecodeContext *s) + { + int len = get_bits(&s->gb, 16); +- if (len >= 2 && 8*len - 16 + get_bits_count(&s->gb) <= s->gb.size_in_bits) { ++ if (len >= 2 && 8 * len - 16 <= get_bits_left(&s->gb)) { + char *cbuf = av_malloc(len - 1); + if (cbuf) { + int i; + for (i = 0; i < len - 2; i++) + cbuf[i] = get_bits(&s->gb, 8); +- if (i > 0 && cbuf[i-1] == '\n') +- cbuf[i-1] = 0; ++ if (i > 0 && cbuf[i - 1] == '\n') ++ cbuf[i - 1] = 0; + else + cbuf[i] = 0; + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_INFO, "mjpeg comment: '%s'\n", cbuf); + + /* buggy avid, it puts EOI only at every 10th frame */ +- if (!strcmp(cbuf, "AVID")) +- { ++ if (!strcmp(cbuf, "AVID")) { + s->buggy_avid = 1; +- // if (s->first_picture) +- // printf("mjpeg: workarounding buggy AVID\n"); +- } +- else if(!strcmp(cbuf, "CS=ITU601")){ +- s->cs_itu601= 1; +- } +- else if((len > 20 && !strncmp(cbuf, "Intel(R) JPEG Library", 21)) || +- (len > 19 && !strncmp(cbuf, "Metasoft MJPEG Codec", 20))){ ++ // if (s->first_picture) ++ // printf("mjpeg: workarounding buggy AVID\n"); ++ } else if (!strcmp(cbuf, "CS=ITU601")) ++ s->cs_itu601 = 1; ++ else if ((len > 20 && !strncmp(cbuf, "Intel(R) JPEG Library", 21)) || ++ (len > 19 && !strncmp(cbuf, "Metasoft MJPEG Codec", 20))) + s->flipped = 1; +- } + + av_free(cbuf); + } +@@ -1207,29 +1439,6 @@ + return 0; + } + +-#if 0 +-static int valid_marker_list[] = +-{ +- /* 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f */ +-/* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 2 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 3 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 4 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 5 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 6 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 7 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-/* c */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-/* d */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-/* e */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +-/* f */ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, +-} +-#endif +- + /* return the 8 bit start code value and update the search + state. Return -1 if no start code found */ + static int find_marker(const uint8_t **pbuf_ptr, const uint8_t *buf_end) +@@ -1237,21 +1446,17 @@ + const uint8_t *buf_ptr; + unsigned int v, v2; + int val; +-#ifdef DEBUG +- int skipped=0; +-#endif ++ int skipped = 0; + + buf_ptr = *pbuf_ptr; + while (buf_ptr < buf_end) { +- v = *buf_ptr++; ++ v = *buf_ptr++; + v2 = *buf_ptr; + if ((v == 0xff) && (v2 >= 0xc0) && (v2 <= 0xfe) && buf_ptr < buf_end) { + val = *buf_ptr++; + goto found; + } +-#ifdef DEBUG + skipped++; +-#endif + } + val = -1; + found: +@@ -1260,15 +1465,101 @@ + return val; + } + +-int ff_mjpeg_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++int ff_mjpeg_find_marker(MJpegDecodeContext *s, ++ const uint8_t **buf_ptr, const uint8_t *buf_end, ++ const uint8_t **unescaped_buf_ptr, ++ int *unescaped_buf_size) ++{ ++ int start_code; ++ start_code = find_marker(buf_ptr, buf_end); ++ ++ av_fast_padded_malloc(&s->buffer, &s->buffer_size, buf_end - *buf_ptr); ++ if (!s->buffer) ++ return AVERROR(ENOMEM); ++ ++ /* unescape buffer of SOS, use special treatment for JPEG-LS */ ++ if (start_code == SOS && !s->ls) { ++ const uint8_t *src = *buf_ptr; ++ uint8_t *dst = s->buffer; ++ ++ while (src < buf_end) { ++ uint8_t x = *(src++); ++ ++ *(dst++) = x; ++ if (s->avctx->codec_id != CODEC_ID_THP) { ++ if (x == 0xff) { ++ while (src < buf_end && x == 0xff) ++ x = *(src++); ++ ++ if (x >= 0xd0 && x <= 0xd7) ++ *(dst++) = x; ++ else if (x) ++ break; ++ } ++ } ++ } ++ *unescaped_buf_ptr = s->buffer; ++ *unescaped_buf_size = dst - s->buffer; ++ ++ av_log(s->avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n", ++ (buf_end - *buf_ptr) - (dst - s->buffer)); ++ } else if (start_code == SOS && s->ls) { ++ const uint8_t *src = *buf_ptr; ++ uint8_t *dst = s->buffer; ++ int bit_count = 0; ++ int t = 0, b = 0; ++ PutBitContext pb; ++ ++ s->cur_scan++; ++ ++ /* find marker */ ++ while (src + t < buf_end) { ++ uint8_t x = src[t++]; ++ if (x == 0xff) { ++ while ((src + t < buf_end) && x == 0xff) ++ x = src[t++]; ++ if (x & 0x80) { ++ t -= 2; ++ break; ++ } ++ } ++ } ++ bit_count = t * 8; ++ init_put_bits(&pb, dst, t); ++ ++ /* unescape bitstream */ ++ while (b < t) { ++ uint8_t x = src[b++]; ++ put_bits(&pb, 8, x); ++ if (x == 0xFF) { ++ x = src[b++]; ++ put_bits(&pb, 7, x); ++ bit_count--; ++ } ++ } ++ flush_put_bits(&pb); ++ ++ *unescaped_buf_ptr = dst; ++ *unescaped_buf_size = (bit_count + 7) >> 3; ++ } else { ++ *unescaped_buf_ptr = *buf_ptr; ++ *unescaped_buf_size = buf_end - *buf_ptr; ++ } ++ ++ return start_code; ++} ++ ++int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ int buf_size = avpkt->size; + MJpegDecodeContext *s = avctx->priv_data; + const uint8_t *buf_end, *buf_ptr; ++ const uint8_t *unescaped_buf_ptr; ++ int unescaped_buf_size; + int start_code; ++ int i, index; + AVFrame *picture = data; + + s->got_picture = 0; // picture from previous image can not be reused +@@ -1276,228 +1567,153 @@ + buf_end = buf + buf_size; + while (buf_ptr < buf_end) { + /* find start next marker */ +- start_code = find_marker(&buf_ptr, buf_end); +- { +- /* EOF */ +- if (start_code < 0) { +- goto the_end; +- } else { +- av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", start_code, buf_end - buf_ptr); +- +- if ((buf_end - buf_ptr) > s->buffer_size) +- { +- av_free(s->buffer); +- s->buffer_size = buf_end-buf_ptr; +- s->buffer = av_malloc(s->buffer_size + FF_INPUT_BUFFER_PADDING_SIZE); +- av_log(avctx, AV_LOG_DEBUG, "buffer too small, expanding to %d bytes\n", +- s->buffer_size); +- } +- +- /* unescape buffer of SOS, use special treatment for JPEG-LS */ +- if (start_code == SOS && !s->ls) +- { +- const uint8_t *src = buf_ptr; +- uint8_t *dst = s->buffer; +- +- while (srccodec_id != CODEC_ID_THP) +- { +- if (x == 0xff) { +- while (src < buf_end && x == 0xff) +- x = *(src++); +- +- if (x >= 0xd0 && x <= 0xd7) +- *(dst++) = x; +- else if (x) +- break; +- } +- } +- } +- init_get_bits(&s->gb, s->buffer, (dst - s->buffer)*8); +- +- av_log(avctx, AV_LOG_DEBUG, "escaping removed %td bytes\n", +- (buf_end - buf_ptr) - (dst - s->buffer)); +- } +- else if(start_code == SOS && s->ls){ +- const uint8_t *src = buf_ptr; +- uint8_t *dst = s->buffer; +- int bit_count = 0; +- int t = 0, b = 0; +- PutBitContext pb; +- +- s->cur_scan++; +- +- /* find marker */ +- while (src + t < buf_end){ +- uint8_t x = src[t++]; +- if (x == 0xff){ +- while((src + t < buf_end) && x == 0xff) +- x = src[t++]; +- if (x & 0x80) { +- t -= 2; +- break; +- } +- } +- } +- bit_count = t * 8; +- +- init_put_bits(&pb, dst, t); ++ start_code = ff_mjpeg_find_marker(s, &buf_ptr, buf_end, ++ &unescaped_buf_ptr, ++ &unescaped_buf_size); ++ /* EOF */ ++ if (start_code < 0) { ++ goto the_end; ++ } else if (unescaped_buf_size > (1U<<29)) { ++ av_log(avctx, AV_LOG_ERROR, "MJPEG packet 0x%x too big (0x%x/0x%x), corrupt data?\n", ++ start_code, unescaped_buf_ptr, buf_size); ++ return AVERROR_INVALIDDATA; ++ } else { ++ av_log(avctx, AV_LOG_DEBUG, "marker=%x avail_size_in_buf=%td\n", ++ start_code, buf_end - buf_ptr); + +- /* unescape bitstream */ +- while(b < t){ +- uint8_t x = src[b++]; +- put_bits(&pb, 8, x); +- if(x == 0xFF){ +- x = src[b++]; +- put_bits(&pb, 7, x); +- bit_count--; +- } +- } +- flush_put_bits(&pb); ++ init_get_bits(&s->gb, unescaped_buf_ptr, unescaped_buf_size * 8); + +- init_get_bits(&s->gb, dst, bit_count); ++ s->start_code = start_code; ++ if (s->avctx->debug & FF_DEBUG_STARTCODE) ++ av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); ++ ++ /* process markers */ ++ if (start_code >= 0xd0 && start_code <= 0xd7) ++ av_log(avctx, AV_LOG_DEBUG, ++ "restart marker: %d\n", start_code & 0x0f); ++ /* APP fields */ ++ else if (start_code >= APP0 && start_code <= APP15) ++ mjpeg_decode_app(s); ++ /* Comment */ ++ else if (start_code == COM) ++ mjpeg_decode_com(s); ++ ++ switch (start_code) { ++ case SOI: ++ s->restart_interval = 0; ++ s->restart_count = 0; ++ /* nothing to do on SOI */ ++ break; ++ case DQT: ++ ff_mjpeg_decode_dqt(s); ++ break; ++ case DHT: ++ if (ff_mjpeg_decode_dht(s) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n"); ++ return -1; + } +- else +- init_get_bits(&s->gb, buf_ptr, (buf_end - buf_ptr)*8); +- +- s->start_code = start_code; +- if(s->avctx->debug & FF_DEBUG_STARTCODE){ +- av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code); ++ break; ++ case SOF0: ++ case SOF1: ++ s->lossless = 0; ++ s->ls = 0; ++ s->progressive = 0; ++ if (ff_mjpeg_decode_sof(s) < 0) ++ return -1; ++ break; ++ case SOF2: ++ s->lossless = 0; ++ s->ls = 0; ++ s->progressive = 1; ++ if (ff_mjpeg_decode_sof(s) < 0) ++ return -1; ++ break; ++ case SOF3: ++ s->lossless = 1; ++ s->ls = 0; ++ s->progressive = 0; ++ if (ff_mjpeg_decode_sof(s) < 0) ++ return -1; ++ break; ++ case SOF48: ++ s->lossless = 1; ++ s->ls = 1; ++ s->progressive = 0; ++ if (ff_mjpeg_decode_sof(s) < 0) ++ return -1; ++ break; ++ case LSE: ++ if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0) ++ return -1; ++ break; ++ case EOI: ++eoi_parser: ++ s->cur_scan = 0; ++ if (!s->got_picture) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Found EOI before any SOF, ignoring\n"); ++ break; + } +- +- /* process markers */ +- if (start_code >= 0xd0 && start_code <= 0xd7) { +- av_log(avctx, AV_LOG_DEBUG, "restart marker: %d\n", start_code&0x0f); +- /* APP fields */ +- } else if (start_code >= APP0 && start_code <= APP15) { +- mjpeg_decode_app(s); +- /* Comment */ +- } else if (start_code == COM){ +- mjpeg_decode_com(s); ++ if (s->interlaced) { ++ s->bottom_field ^= 1; ++ /* if not bottom field, do not output image yet */ ++ if (s->bottom_field == !s->interlace_polarity) ++ break; + } ++ *picture = *s->picture_ptr; ++ *data_size = sizeof(AVFrame); + +- switch(start_code) { +- case SOI: +- s->restart_interval = 0; +- +- s->restart_count = 0; +- /* nothing to do on SOI */ +- break; +- case DQT: +- ff_mjpeg_decode_dqt(s); +- break; +- case DHT: +- if(ff_mjpeg_decode_dht(s) < 0){ +- av_log(avctx, AV_LOG_ERROR, "huffman table decode error\n"); +- return -1; ++ if (!s->lossless) { ++ picture->quality = FFMAX3(s->qscale[0], ++ s->qscale[1], ++ s->qscale[2]); ++ picture->qstride = 0; ++ picture->qscale_table = s->qscale_table; ++ memset(picture->qscale_table, picture->quality, ++ (s->width + 15) / 16); ++ if (avctx->debug & FF_DEBUG_QP) ++ av_log(avctx, AV_LOG_DEBUG, ++ "QP: %d\n", picture->quality); ++ picture->quality *= FF_QP2LAMBDA; + } +- break; +- case SOF0: +- case SOF1: +- s->lossless=0; +- s->ls=0; +- s->progressive=0; +- if (ff_mjpeg_decode_sof(s) < 0) +- return -1; +- break; +- case SOF2: +- s->lossless=0; +- s->ls=0; +- s->progressive=1; +- if (ff_mjpeg_decode_sof(s) < 0) +- return -1; +- break; +- case SOF3: +- s->lossless=1; +- s->ls=0; +- s->progressive=0; +- if (ff_mjpeg_decode_sof(s) < 0) +- return -1; +- break; +- case SOF48: +- s->lossless=1; +- s->ls=1; +- s->progressive=0; +- if (ff_mjpeg_decode_sof(s) < 0) +- return -1; +- break; +- case LSE: +- if (!CONFIG_JPEGLS_DECODER || ff_jpegls_decode_lse(s) < 0) +- return -1; +- break; +- case EOI: +- s->cur_scan = 0; +- if ((s->buggy_avid && !s->interlaced) || s->restart_interval) +- break; +-eoi_parser: +- if (!s->got_picture) { +- av_log(avctx, AV_LOG_WARNING, "Found EOI before any SOF, ignoring\n"); +- break; +- } +- { +- if (s->interlaced) { +- s->bottom_field ^= 1; +- /* if not bottom field, do not output image yet */ +- if (s->bottom_field == !s->interlace_polarity) +- goto not_the_end; +- } +- *picture = s->picture; +- *data_size = sizeof(AVFrame); +- +- if(!s->lossless){ +- picture->quality= FFMAX3(s->qscale[0], s->qscale[1], s->qscale[2]); +- picture->qstride= 0; +- picture->qscale_table= s->qscale_table; +- memset(picture->qscale_table, picture->quality, (s->width+15)/16); +- if(avctx->debug & FF_DEBUG_QP) +- av_log(avctx, AV_LOG_DEBUG, "QP: %d\n", picture->quality); +- picture->quality*= FF_QP2LAMBDA; +- } + +- goto the_end; +- } ++ goto the_end; ++ case SOS: ++ if (!s->got_picture) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Can not process SOS before SOF, skipping\n"); + break; +- case SOS: +- if (!s->got_picture) { +- av_log(avctx, AV_LOG_WARNING, "Can not process SOS before SOF, skipping\n"); +- break; + } +- ff_mjpeg_decode_sos(s); +- /* buggy avid puts EOI every 10-20th frame */ +- /* if restart period is over process EOI */ +- if ((s->buggy_avid && !s->interlaced) || s->restart_interval) +- goto eoi_parser; +- break; +- case DRI: +- mjpeg_decode_dri(s); +- break; +- case SOF5: +- case SOF6: +- case SOF7: +- case SOF9: +- case SOF10: +- case SOF11: +- case SOF13: +- case SOF14: +- case SOF15: +- case JPG: +- av_log(avctx, AV_LOG_ERROR, "mjpeg: unsupported coding type (%x)\n", start_code); +- break; +-// default: +-// printf("mjpeg: unsupported marker (%x)\n", start_code); +-// break; +- } +- +-not_the_end: +- /* eof process start code */ +- buf_ptr += (get_bits_count(&s->gb)+7)/8; +- av_log(avctx, AV_LOG_DEBUG, "marker parser used %d bytes (%d bits)\n", +- (get_bits_count(&s->gb)+7)/8, get_bits_count(&s->gb)); ++ if (ff_mjpeg_decode_sos(s, NULL, NULL) < 0 && ++ (avctx->err_recognition & AV_EF_EXPLODE)) ++ return AVERROR_INVALIDDATA; ++ break; ++ case DRI: ++ mjpeg_decode_dri(s); ++ break; ++ case SOF5: ++ case SOF6: ++ case SOF7: ++ case SOF9: ++ case SOF10: ++ case SOF11: ++ case SOF13: ++ case SOF14: ++ case SOF15: ++ case JPG: ++ av_log(avctx, AV_LOG_ERROR, ++ "mjpeg: unsupported coding type (%x)\n", start_code); ++ break; ++// default: ++// printf("mjpeg: unsupported marker (%x)\n", start_code); ++// break; + } ++ ++ /* eof process start code */ ++ buf_ptr += (get_bits_count(&s->gb) + 7) / 8; ++ av_log(avctx, AV_LOG_DEBUG, ++ "marker parser used %d bytes (%d bits)\n", ++ (get_bits_count(&s->gb) + 7) / 8, get_bits_count(&s->gb)); + } + } + if (s->got_picture) { +@@ -1507,8 +1723,39 @@ + av_log(avctx, AV_LOG_FATAL, "No JPEG data found in image\n"); + return -1; + the_end: +- av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", buf_end - buf_ptr); +-// return buf_end - buf_ptr; ++ if (s->upscale_h) { ++ uint8_t *line = s->picture_ptr->data[s->upscale_h]; ++ av_assert0(avctx->pix_fmt == PIX_FMT_YUVJ444P || ++ avctx->pix_fmt == PIX_FMT_YUV444P || ++ avctx->pix_fmt == PIX_FMT_YUVJ440P || ++ avctx->pix_fmt == PIX_FMT_YUV440P); ++ for (i = 0; i < s->chroma_height; i++) { ++ for (index = s->width - 1; index; index--) ++ line[index] = (line[index / 2] + line[(index + 1) / 2]) >> 1; ++ line += s->linesize[s->upscale_h]; ++ } ++ } ++ if (s->upscale_v) { ++ uint8_t *dst = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(s->height - 1) * s->linesize[s->upscale_v]]; ++ av_assert0(avctx->pix_fmt == PIX_FMT_YUVJ444P || ++ avctx->pix_fmt == PIX_FMT_YUV444P || ++ avctx->pix_fmt == PIX_FMT_YUVJ422P || ++ avctx->pix_fmt == PIX_FMT_YUV422P); ++ for (i = s->height - 1; i; i--) { ++ uint8_t *src1 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[i / 2 * s->linesize[s->upscale_v]]; ++ uint8_t *src2 = &((uint8_t *)s->picture_ptr->data[s->upscale_v])[(i + 1) / 2 * s->linesize[s->upscale_v]]; ++ if (src1 == src2) { ++ memcpy(dst, src1, s->width); ++ } else { ++ for (index = 0; index < s->width; index++) ++ dst[index] = (src1[index] + src2[index]) >> 1; ++ } ++ dst -= s->linesize[s->upscale_v]; ++ } ++ } ++ av_log(avctx, AV_LOG_DEBUG, "mjpeg decode frame unused %td bytes\n", ++ buf_end - buf_ptr); ++// return buf_end - buf_ptr; + return buf_ptr - buf; + } + +@@ -1517,51 +1764,63 @@ + MJpegDecodeContext *s = avctx->priv_data; + int i, j; + +- if (s->picture.data[0]) +- avctx->release_buffer(avctx, &s->picture); ++ if (s->picture_ptr && s->picture_ptr->data[0]) ++ avctx->release_buffer(avctx, s->picture_ptr); + + av_free(s->buffer); + av_free(s->qscale_table); + av_freep(&s->ljpeg_buffer); +- s->ljpeg_buffer_size=0; ++ s->ljpeg_buffer_size = 0; + +- for(i=0;i<3;i++) { +- for(j=0;j<4;j++) ++ for (i = 0; i < 3; i++) { ++ for (j = 0; j < 4; j++) + free_vlc(&s->vlcs[i][j]); + } +- for(i=0; iblocks[i]); + av_freep(&s->last_nnz[i]); + } + return 0; + } + ++#define OFFSET(x) offsetof(MJpegDecodeContext, x) ++#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "extern_huff", "Use external huffman table.", ++ OFFSET(extern_huff), AV_OPT_TYPE_INT, { 0 }, 0, 1, VD }, ++ { NULL }, ++}; ++ ++static const AVClass mjpegdec_class = { ++ .class_name = "MJPEG decoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_mjpeg_decoder = { +- "mjpeg", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MJPEG, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- ff_mjpeg_decode_frame, +- CODEC_CAP_DR1, +- NULL, +- .max_lowres = 4, +- .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), ++ .name = "mjpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MJPEG, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = ff_mjpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .max_lowres = 3, ++ .long_name = NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), ++ .priv_class = &mjpegdec_class, + }; + + AVCodec ff_thp_decoder = { +- "thp", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_THP, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- ff_mjpeg_decode_frame, +- CODEC_CAP_DR1, +- NULL, +- .max_lowres = 3, +- .long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"), ++ .name = "thp", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_THP, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = ff_mjpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .max_lowres = 3, ++ .long_name = NULL_IF_CONFIG_SMALL("Nintendo Gamecube THP video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegdec.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegdec.h 2012-05-14 14:08:53.970332656 +0200 +@@ -29,6 +29,8 @@ + #ifndef AVCODEC_MJPEGDEC_H + #define AVCODEC_MJPEGDEC_H + ++#include "libavutil/log.h" ++ + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" +@@ -36,6 +38,7 @@ + #define MAX_COMPONENTS 4 + + typedef struct MJpegDecodeContext { ++ AVClass *class; + AVCodecContext *avctx; + GetBitContext gb; + +@@ -55,6 +58,9 @@ + int ls; + int progressive; + int rgb; ++ int upscale_h; ++ int chroma_height; ++ int upscale_v; + int rct; /* standard rct */ + int pegasus_rct; /* pegasus reversible colorspace transform */ + int bits; /* bits per component */ +@@ -81,6 +87,7 @@ + int quant_index[4]; /* quant table index for each component */ + int last_dc[MAX_COMPONENTS]; /* last DEQUANTIZED dc (XXX: am I right to do that ?) */ + AVFrame picture; /* picture structure */ ++ AVFrame *picture_ptr; /* pointer to picture structure */ + int got_picture; ///< we found a SOF and picture is valid, too. + int linesize[MAX_COMPONENTS]; ///< linesize << interlaced + int8_t *qscale_table; +@@ -105,6 +112,8 @@ + + uint16_t (*ljpeg_buffer)[4]; + unsigned int ljpeg_buffer_size; ++ ++ int extern_huff; + } MJpegDecodeContext; + + int ff_mjpeg_decode_init(AVCodecContext *avctx); +@@ -115,6 +124,10 @@ + int ff_mjpeg_decode_dqt(MJpegDecodeContext *s); + int ff_mjpeg_decode_dht(MJpegDecodeContext *s); + int ff_mjpeg_decode_sof(MJpegDecodeContext *s); +-int ff_mjpeg_decode_sos(MJpegDecodeContext *s); ++int ff_mjpeg_decode_sos(MJpegDecodeContext *s, ++ const uint8_t *mb_bitmask, const AVFrame *reference); ++int ff_mjpeg_find_marker(MJpegDecodeContext *s, ++ const uint8_t **buf_ptr, const uint8_t *buf_end, ++ const uint8_t **unescaped_buf_ptr, int *unescaped_buf_size); + + #endif /* AVCODEC_MJPEGDEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpegenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpegenc.c 2012-05-14 14:08:53.971332676 +0200 +@@ -156,13 +156,13 @@ + int size; + uint8_t *ptr; + +- if (s->aspect_ratio_info /* && !lossless */) ++ if (s->avctx->sample_aspect_ratio.num /* && !lossless */) + { + /* JFIF header */ + put_marker(p, APP0); + put_bits(p, 16, 16); + ff_put_string(p, "JFIF", 1); /* this puts the trailing zero-byte too */ +- put_bits(p, 16, 0x0201); /* v 1.02 */ ++ put_bits(p, 16, 0x0102); /* v 1.02 */ + put_bits(p, 8, 0); /* units type: 0 - aspect ratio */ + put_bits(p, 16, s->avctx->sample_aspect_ratio.num); + put_bits(p, 16, s->avctx->sample_aspect_ratio.den); +@@ -200,6 +200,9 @@ + + put_marker(&s->pb, SOI); + ++ // hack for AMV mjpeg format ++ if(s->avctx->codec_id == CODEC_ID_AMV) return; ++ + jpeg_put_comments(s); + + jpeg_table_header(s); +@@ -445,14 +448,48 @@ + s->i_tex_bits += get_bits_diff(s); + } + ++// maximum over s->mjpeg_vsample[i] ++#define V_MAX 2 ++static int amv_encode_picture(AVCodecContext *avctx, ++ unsigned char *buf, int buf_size, void *data) ++{ ++ ++ AVFrame* pic=data; ++ MpegEncContext *s = avctx->priv_data; ++ int i; ++ ++ //CODEC_FLAG_EMU_EDGE have to be cleared ++ if(s->avctx->flags & CODEC_FLAG_EMU_EDGE) ++ return -1; ++ ++ //picture should be flipped upside-down ++ for(i=0; i < 3; i++) { ++ pic->data[i] += (pic->linesize[i] * (s->mjpeg_vsample[i] * (8 * s->mb_height -((s->height/V_MAX)&7)) - 1 )); ++ pic->linesize[i] *= -1; ++ } ++ return MPV_encode_picture(avctx,buf, buf_size, pic); ++} ++ + AVCodec ff_mjpeg_encoder = { +- "mjpeg", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MJPEG, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "mjpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MJPEG, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("MJPEG (Motion JPEG)"), + }; ++ ++AVCodec ff_amv_encoder = { ++ .name = "amv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AMV, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = amv_encode_picture, ++ .close = MPV_encode_end, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("AMV Video"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg.h 2012-05-14 14:08:53.960332454 +0200 +@@ -127,6 +127,7 @@ + + #define PREDICT(ret, topleft, top, left, predictor)\ + switch(predictor){\ ++ case 0: ret= 0; break;\ + case 1: ret= left; break;\ + case 2: ret= top; break;\ + case 3: ret= topleft; break;\ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mjpeg_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mjpeg_parser.c 2012-05-14 14:08:53.962332494 +0200 +@@ -28,27 +28,44 @@ + + #include "parser.h" + ++typedef struct MJPEGParserContext{ ++ ParseContext pc; ++ int size; ++}MJPEGParserContext; + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ +-static int find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size){ ++static int find_frame_end(MJPEGParserContext *m, const uint8_t *buf, int buf_size){ ++ ParseContext *pc= &m->pc; + int vop_found, i; +- uint16_t state; ++ uint32_t state; + + vop_found= pc->frame_start_found; + state= pc->state; + + i=0; + if(!vop_found){ +- for(i=0; i=0xFFC00000 && state<=0xFFFEFFFF){ ++ if(state>=0xFFD80000 && state<=0xFFD8FFFF){ ++ i++; ++ vop_found=1; ++ break; ++ }else if(state<0xFFD00000 || state>0xFFD9FFFF){ ++ m->size= (state&0xFFFF)-1; ++ } + } ++ if(m->size>0){ ++ int size= FFMIN(buf_size-i, m->size); ++ i+=size; ++ m->size-=size; ++ state=0; ++ continue; ++ }else ++ i++; + } + } + +@@ -56,13 +73,25 @@ + /* EOF considered as end of frame */ + if (buf_size == 0) + return 0; +- for(; iframe_start_found=0; +- pc->state=0; +- return i-1; ++ if(state>=0xFFC00000 && state<=0xFFFEFFFF){ ++ if(state>=0xFFD80000 && state<=0xFFD8FFFF){ ++ pc->frame_start_found=0; ++ pc->state=0; ++ return i-3; ++ } else if(state<0xFFD00000 || state>0xFFD9FFFF){ ++ m->size= (state&0xFFFF)-1; ++ } + } ++ if(m->size>0){ ++ int size= FFMIN(buf_size-i, m->size); ++ i+=size; ++ m->size-=size; ++ state=0; ++ continue; ++ }else ++ i++; + } + } + pc->frame_start_found= vop_found; +@@ -75,13 +104,14 @@ + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) + { +- ParseContext *pc = s->priv_data; ++ MJPEGParserContext *m = s->priv_data; ++ ParseContext *pc = &m->pc; + int next; + + if(s->flags & PARSER_FLAG_COMPLETE_FRAMES){ + next= buf_size; + }else{ +- next= find_frame_end(pc, buf, buf_size); ++ next= find_frame_end(m, buf, buf_size); + + if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { + *poutbuf = NULL; +@@ -97,9 +127,8 @@ + + + AVCodecParser ff_mjpeg_parser = { +- { CODEC_ID_MJPEG }, +- sizeof(ParseContext), +- NULL, +- jpeg_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_MJPEG }, ++ .priv_data_size = sizeof(MJPEGParserContext), ++ .parser_parse = jpeg_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlib/dsputil_mlib.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlib/dsputil_mlib.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlib/dsputil_mlib.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlib/dsputil_mlib.c 2012-05-14 14:08:53.972332696 +0200 +@@ -421,10 +421,14 @@ + + void dsputil_init_mlib(DSPContext* c, AVCodecContext *avctx) + { +- c->get_pixels = get_pixels_mlib; ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ + c->diff_pixels = diff_pixels_mlib; + c->add_pixels_clamped = add_pixels_clamped_mlib; + ++ if (!high_bit_depth) { ++ c->get_pixels = get_pixels_mlib; ++ + c->put_pixels_tab[0][0] = put_pixels16_mlib; + c->put_pixels_tab[0][1] = put_pixels16_x2_mlib; + c->put_pixels_tab[0][2] = put_pixels16_y2_mlib; +@@ -445,6 +449,7 @@ + + c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mlib; + c->put_no_rnd_pixels_tab[1][0] = put_pixels8_mlib; ++ } + + c->bswap_buf = bswap_buf_mlib; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlpdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlpdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlpdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlpdec.c 2012-05-14 14:08:53.977332796 +0200 +@@ -45,35 +45,35 @@ + "a sample of this file."; + + typedef struct SubStream { +- //! Set if a valid restart header has been read. Otherwise the substream cannot be decoded. ++ /// Set if a valid restart header has been read. Otherwise the substream cannot be decoded. + uint8_t restart_seen; + + //@{ + /** restart header data */ +- //! The type of noise to be used in the rematrix stage. ++ /// The type of noise to be used in the rematrix stage. + uint16_t noise_type; + +- //! The index of the first channel coded in this substream. ++ /// The index of the first channel coded in this substream. + uint8_t min_channel; +- //! The index of the last channel coded in this substream. ++ /// The index of the last channel coded in this substream. + uint8_t max_channel; +- //! The number of channels input into the rematrix stage. ++ /// The number of channels input into the rematrix stage. + uint8_t max_matrix_channel; +- //! For each channel output by the matrix, the output channel to map it to ++ /// For each channel output by the matrix, the output channel to map it to + uint8_t ch_assign[MAX_CHANNELS]; + +- //! Channel coding parameters for channels in the substream ++ /// Channel coding parameters for channels in the substream + ChannelParams channel_params[MAX_CHANNELS]; + +- //! The left shift applied to random noise in 0x31ea substreams. ++ /// The left shift applied to random noise in 0x31ea substreams. + uint8_t noise_shift; +- //! The current seed value for the pseudorandom noise generator(s). ++ /// The current seed value for the pseudorandom noise generator(s). + uint32_t noisegen_seed; + +- //! Set if the substream contains extra info to check the size of VLC blocks. ++ /// Set if the substream contains extra info to check the size of VLC blocks. + uint8_t data_check_present; + +- //! Bitmask of which parameter sets are conveyed in a decoding parameter block. ++ /// Bitmask of which parameter sets are conveyed in a decoding parameter block. + uint8_t param_presence_flags; + #define PARAM_BLOCKSIZE (1 << 7) + #define PARAM_MATRIX (1 << 6) +@@ -88,54 +88,58 @@ + //@{ + /** matrix data */ + +- //! Number of matrices to be applied. ++ /// Number of matrices to be applied. + uint8_t num_primitive_matrices; + +- //! matrix output channel ++ /// matrix output channel + uint8_t matrix_out_ch[MAX_MATRICES]; + +- //! Whether the LSBs of the matrix output are encoded in the bitstream. ++ /// Whether the LSBs of the matrix output are encoded in the bitstream. + uint8_t lsb_bypass[MAX_MATRICES]; +- //! Matrix coefficients, stored as 2.14 fixed point. ++ /// Matrix coefficients, stored as 2.14 fixed point. + int32_t matrix_coeff[MAX_MATRICES][MAX_CHANNELS]; +- //! Left shift to apply to noise values in 0x31eb substreams. ++ /// Left shift to apply to noise values in 0x31eb substreams. + uint8_t matrix_noise_shift[MAX_MATRICES]; + //@} + +- //! Left shift to apply to Huffman-decoded residuals. ++ /// Left shift to apply to Huffman-decoded residuals. + uint8_t quant_step_size[MAX_CHANNELS]; + +- //! number of PCM samples in current audio block ++ /// number of PCM samples in current audio block + uint16_t blocksize; +- //! Number of PCM samples decoded so far in this frame. ++ /// Number of PCM samples decoded so far in this frame. + uint16_t blockpos; + +- //! Left shift to apply to decoded PCM values to get final 24-bit output. ++ /// Left shift to apply to decoded PCM values to get final 24-bit output. + int8_t output_shift[MAX_CHANNELS]; + +- //! Running XOR of all output samples. ++ /// Running XOR of all output samples. + int32_t lossless_check_data; + + } SubStream; + + typedef struct MLPDecodeContext { + AVCodecContext *avctx; ++ AVFrame frame; + +- //! Current access unit being read has a major sync. ++ /// Current access unit being read has a major sync. + int is_major_sync_unit; + +- //! Set if a valid major sync block has been read. Otherwise no decoding is possible. ++ /// Set if a valid major sync block has been read. Otherwise no decoding is possible. + uint8_t params_valid; + +- //! Number of substreams contained within this stream. ++ /// Number of substreams contained within this stream. + uint8_t num_substreams; + +- //! Index of the last substream to decode - further substreams are skipped. ++ /// Index of the last substream to decode - further substreams are skipped. + uint8_t max_decoded_substream; + +- //! number of PCM samples contained in each frame ++ /// Stream needs channel reordering to comply with FFmpeg's channel order ++ uint8_t needs_reordering; ++ ++ /// number of PCM samples contained in each frame + int access_unit_size; +- //! next power of two above the number of samples in each frame ++ /// next power of two above the number of samples in each frame + int access_unit_size_pow2; + + SubStream substream[MAX_SUBSTREAMS]; +@@ -214,7 +218,7 @@ + VLC_BITS, (9 + VLC_BITS - 1) / VLC_BITS); + + if (result < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (lsb_bits > 0) + result = (result << lsb_bits) + get_bits(gbp, lsb_bits); +@@ -239,6 +243,9 @@ + m->substream[substr].lossless_check_data = 0xffffffff; + dsputil_init(&m->dsp, avctx); + ++ avcodec_get_frame_defaults(&m->frame); ++ avctx->coded_frame = &m->frame; ++ + return 0; + } + +@@ -250,61 +257,61 @@ + static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb) + { + MLPHeaderInfo mh; +- int substr; ++ int substr, ret; + +- if (ff_mlp_read_major_sync(m->avctx, &mh, gb) != 0) +- return -1; ++ if ((ret = ff_mlp_read_major_sync(m->avctx, &mh, gb)) != 0) ++ return ret; + + if (mh.group1_bits == 0) { + av_log(m->avctx, AV_LOG_ERROR, "invalid/unknown bits per sample\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (mh.group2_bits > mh.group1_bits) { + av_log(m->avctx, AV_LOG_ERROR, + "Channel group 2 cannot have more bits per sample than group 1.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (mh.group2_samplerate && mh.group2_samplerate != mh.group1_samplerate) { + av_log(m->avctx, AV_LOG_ERROR, + "Channel groups with differing sample rates are not currently supported.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (mh.group1_samplerate == 0) { + av_log(m->avctx, AV_LOG_ERROR, "invalid/unknown sampling rate\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (mh.group1_samplerate > MAX_SAMPLERATE) { + av_log(m->avctx, AV_LOG_ERROR, + "Sampling rate %d is greater than the supported maximum (%d).\n", + mh.group1_samplerate, MAX_SAMPLERATE); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (mh.access_unit_size > MAX_BLOCKSIZE) { + av_log(m->avctx, AV_LOG_ERROR, + "Block size %d is greater than the supported maximum (%d).\n", + mh.access_unit_size, MAX_BLOCKSIZE); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (mh.access_unit_size_pow2 > MAX_BLOCKSIZE_POW2) { + av_log(m->avctx, AV_LOG_ERROR, + "Block size pow2 %d is greater than the supported maximum (%d).\n", + mh.access_unit_size_pow2, MAX_BLOCKSIZE_POW2); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (mh.num_substreams == 0) +- return -1; ++ return AVERROR_INVALIDDATA; + if (m->avctx->codec_id == CODEC_ID_MLP && mh.num_substreams > 2) { + av_log(m->avctx, AV_LOG_ERROR, "MLP only supports up to 2 substreams.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (mh.num_substreams > MAX_SUBSTREAMS) { + av_log(m->avctx, AV_LOG_ERROR, + "Number of substreams %d is larger than the maximum supported " + "by the decoder. %s\n", mh.num_substreams, sample_message); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + m->access_unit_size = mh.access_unit_size; +@@ -326,6 +333,26 @@ + for (substr = 0; substr < MAX_SUBSTREAMS; substr++) + m->substream[substr].restart_seen = 0; + ++ if (mh.stream_type == 0xbb) { ++ /* MLP stream */ ++ m->avctx->channel_layout = ff_mlp_layout[mh.channels_mlp]; ++ } else { /* mh.stream_type == 0xba */ ++ /* TrueHD stream */ ++ if (mh.channels_thd_stream2) { ++ m->avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream2); ++ } else { ++ m->avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream1); ++ } ++ if (m->avctx->channels && ++ !m->avctx->request_channels && !m->avctx->request_channel_layout && ++ av_get_channel_layout_nb_channels(m->avctx->channel_layout) != m->avctx->channels) { ++ m->avctx->channel_layout = 0; ++ av_log_ask_for_sample(m->avctx, "Unknown channel layout."); ++ } ++ } ++ ++ m->needs_reordering = mh.channels_mlp >= 18 && mh.channels_mlp <= 20; ++ + return 0; + } + +@@ -351,14 +378,14 @@ + if (sync_word != 0x31ea >> 1) { + av_log(m->avctx, AV_LOG_ERROR, + "restart header sync incorrect (got 0x%04x)\n", sync_word); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + s->noise_type = get_bits1(gbp); + + if (m->avctx->codec_id == CODEC_ID_MLP && s->noise_type) { + av_log(m->avctx, AV_LOG_ERROR, "MLP must have 0x31ea sync word.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + skip_bits(gbp, 16); /* Output timestamp */ +@@ -371,13 +398,13 @@ + av_log(m->avctx, AV_LOG_ERROR, + "Max matrix channel cannot be greater than %d.\n", + max_matrix_channel); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (s->max_channel != s->max_matrix_channel) { + av_log(m->avctx, AV_LOG_ERROR, + "Max channel must be equal max matrix channel.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + /* This should happen for TrueHD streams with >6 channels and MLP's noise +@@ -386,13 +413,13 @@ + av_log(m->avctx, AV_LOG_ERROR, + "Number of channels %d is larger than the maximum supported " + "by the decoder. %s\n", s->max_channel+2, sample_message); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (s->min_channel > s->max_channel) { + av_log(m->avctx, AV_LOG_ERROR, + "Substream min channel cannot be greater than max channel.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (m->avctx->request_channels > 0 +@@ -431,11 +458,38 @@ + av_log(m->avctx, AV_LOG_ERROR, + "Assignment of matrix channel %d to invalid output channel %d. %s\n", + ch, ch_assign, sample_message); +- return -1; ++ return AVERROR_INVALIDDATA; + } + s->ch_assign[ch_assign] = ch; + } + ++ if (m->avctx->codec_id == CODEC_ID_MLP && m->needs_reordering) { ++ if (m->avctx->channel_layout == (AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY) || ++ m->avctx->channel_layout == AV_CH_LAYOUT_5POINT0_BACK) { ++ int i = s->ch_assign[4]; ++ s->ch_assign[4] = s->ch_assign[3]; ++ s->ch_assign[3] = s->ch_assign[2]; ++ s->ch_assign[2] = i; ++ } else if (m->avctx->channel_layout == AV_CH_LAYOUT_5POINT1_BACK) { ++ FFSWAP(int, s->ch_assign[2], s->ch_assign[4]); ++ FFSWAP(int, s->ch_assign[3], s->ch_assign[5]); ++ } ++ } ++ if (m->avctx->codec_id == CODEC_ID_TRUEHD && ++ (m->avctx->channel_layout == AV_CH_LAYOUT_7POINT1 || ++ m->avctx->channel_layout == AV_CH_LAYOUT_7POINT1_WIDE)) { ++ FFSWAP(int, s->ch_assign[4], s->ch_assign[6]); ++ FFSWAP(int, s->ch_assign[5], s->ch_assign[7]); ++ } else if (m->avctx->codec_id == CODEC_ID_TRUEHD && ++ (m->avctx->channel_layout == AV_CH_LAYOUT_6POINT1 || ++ m->avctx->channel_layout == (AV_CH_LAYOUT_6POINT1 | AV_CH_TOP_CENTER) || ++ m->avctx->channel_layout == (AV_CH_LAYOUT_6POINT1 | AV_CH_TOP_FRONT_CENTER))) { ++ int i = s->ch_assign[6]; ++ s->ch_assign[6] = s->ch_assign[5]; ++ s->ch_assign[5] = s->ch_assign[4]; ++ s->ch_assign[4] = i; ++ } ++ + checksum = ff_mlp_restart_checksum(buf, get_bits_count(gbp) - start_count); + + if (checksum != get_bits(gbp, 8)) +@@ -487,7 +541,7 @@ + + if (m->filter_changed[channel][filter]++ > 1) { + av_log(m->avctx, AV_LOG_ERROR, "Filters may change only once per access unit.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + order = get_bits(gbp, 4); +@@ -495,7 +549,7 @@ + av_log(m->avctx, AV_LOG_ERROR, + "%cIR filter order %d is greater than maximum %d.\n", + fchar, order, max_order); +- return -1; ++ return AVERROR_INVALIDDATA; + } + fp->order = order; + +@@ -511,13 +565,13 @@ + av_log(m->avctx, AV_LOG_ERROR, + "%cIR filter coeff_bits must be between 1 and 16.\n", + fchar); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (coeff_bits + coeff_shift > 16) { + av_log(m->avctx, AV_LOG_ERROR, + "Sum of coeff_bits and coeff_shift for %cIR filter must be 16 or less.\n", + fchar); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + for (i = 0; i < order; i++) +@@ -529,7 +583,7 @@ + if (filter == FIR) { + av_log(m->avctx, AV_LOG_ERROR, + "FIR filter has state data specified.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + state_bits = get_bits(gbp, 4); +@@ -557,7 +611,7 @@ + + if (m->matrix_changed++ > 1) { + av_log(m->avctx, AV_LOG_ERROR, "Matrices may change only once per access unit.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + s->num_primitive_matrices = get_bits(gbp, 4); +@@ -566,7 +620,7 @@ + av_log(m->avctx, AV_LOG_ERROR, + "Number of primitive matrices cannot be greater than %d.\n", + max_primitive_matrices); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + for (mat = 0; mat < s->num_primitive_matrices; mat++) { +@@ -579,12 +633,12 @@ + av_log(m->avctx, AV_LOG_ERROR, + "Invalid channel %d specified as output from matrix.\n", + s->matrix_out_ch[mat]); +- return -1; ++ return AVERROR_INVALIDDATA; + } + if (frac_bits > 14) { + av_log(m->avctx, AV_LOG_ERROR, + "Too many fractional bits specified.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + max_chan = s->max_matrix_channel; +@@ -617,27 +671,28 @@ + ChannelParams *cp = &s->channel_params[ch]; + FilterParams *fir = &cp->filter_params[FIR]; + FilterParams *iir = &cp->filter_params[IIR]; ++ int ret; + + if (s->param_presence_flags & PARAM_FIR) + if (get_bits1(gbp)) +- if (read_filter_params(m, gbp, substr, ch, FIR) < 0) +- return -1; ++ if ((ret = read_filter_params(m, gbp, substr, ch, FIR)) < 0) ++ return ret; + + if (s->param_presence_flags & PARAM_IIR) + if (get_bits1(gbp)) +- if (read_filter_params(m, gbp, substr, ch, IIR) < 0) +- return -1; ++ if ((ret = read_filter_params(m, gbp, substr, ch, IIR)) < 0) ++ return ret; + + if (fir->order + iir->order > 8) { + av_log(m->avctx, AV_LOG_ERROR, "Total filter orders too high.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (fir->order && iir->order && + fir->shift != iir->shift) { + av_log(m->avctx, AV_LOG_ERROR, + "FIR and IIR filters must use the same precision.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + /* The FIR and IIR filters must have the same precision. + * To simplify the filtering code, only the precision of the +@@ -656,7 +711,7 @@ + + if (cp->huff_lsbs > 24) { + av_log(m->avctx, AV_LOG_ERROR, "Invalid huff_lsbs.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); +@@ -672,6 +727,7 @@ + { + SubStream *s = &m->substream[substr]; + unsigned int ch; ++ int ret; + + if (s->param_presence_flags & PARAM_PRESENCE) + if (get_bits1(gbp)) +@@ -683,14 +739,14 @@ + if (s->blocksize < 8 || s->blocksize > m->access_unit_size) { + av_log(m->avctx, AV_LOG_ERROR, "Invalid blocksize."); + s->blocksize = 0; +- return -1; ++ return AVERROR_INVALIDDATA; + } + } + + if (s->param_presence_flags & PARAM_MATRIX) + if (get_bits1(gbp)) +- if (read_matrix_params(m, substr, gbp) < 0) +- return -1; ++ if ((ret = read_matrix_params(m, substr, gbp)) < 0) ++ return ret; + + if (s->param_presence_flags & PARAM_OUTSHIFT) + if (get_bits1(gbp)) +@@ -709,8 +765,8 @@ + + for (ch = s->min_channel; ch <= s->max_channel; ch++) + if (get_bits1(gbp)) +- if (read_channel_params(m, substr, gbp, ch) < 0) +- return -1; ++ if ((ret = read_channel_params(m, substr, gbp, ch)) < 0) ++ return ret; + + return 0; + } +@@ -752,6 +808,7 @@ + { + SubStream *s = &m->substream[substr]; + unsigned int i, ch, expected_stream_pos = 0; ++ int ret; + + if (s->data_check_present) { + expected_stream_pos = get_bits_count(gbp); +@@ -762,15 +819,15 @@ + + if (s->blockpos + s->blocksize > m->access_unit_size) { + av_log(m->avctx, AV_LOG_ERROR, "too many audio samples in frame\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + memset(&m->bypassed_lsbs[s->blockpos][0], 0, + s->blocksize * sizeof(m->bypassed_lsbs[0])); + + for (i = 0; i < s->blocksize; i++) +- if (read_huff_channels(m, gbp, substr, i) < 0) +- return -1; ++ if ((ret = read_huff_channels(m, gbp, substr, i)) < 0) ++ return ret; + + for (ch = s->min_channel; ch <= s->max_channel; ch++) + filter_channel(m, substr, ch); +@@ -901,16 +958,30 @@ + + /** Write the audio data into the output buffer. */ + +-static int output_data_internal(MLPDecodeContext *m, unsigned int substr, +- uint8_t *data, unsigned int *data_size, int is32) ++static int output_data(MLPDecodeContext *m, unsigned int substr, ++ void *data, int *got_frame_ptr) + { ++ AVCodecContext *avctx = m->avctx; + SubStream *s = &m->substream[substr]; + unsigned int i, out_ch = 0; +- int32_t *data_32 = (int32_t*) data; +- int16_t *data_16 = (int16_t*) data; +- +- if (*data_size < (s->max_channel + 1) * s->blockpos * (is32 ? 4 : 2)) +- return -1; ++ int32_t *data_32; ++ int16_t *data_16; ++ int ret; ++ int is32 = (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32); ++ ++ if (m->avctx->channels != s->max_matrix_channel + 1) { ++ av_log(m->avctx, AV_LOG_ERROR, "channel count mismatch\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* get output buffer */ ++ m->frame.nb_samples = s->blockpos; ++ if ((ret = avctx->get_buffer(avctx, &m->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ data_32 = (int32_t *)m->frame.data[0]; ++ data_16 = (int16_t *)m->frame.data[0]; + + for (i = 0; i < s->blockpos; i++) { + for (out_ch = 0; out_ch <= s->max_matrix_channel; out_ch++) { +@@ -923,27 +994,18 @@ + } + } + +- *data_size = i * out_ch * (is32 ? 4 : 2); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = m->frame; + + return 0; + } + +-static int output_data(MLPDecodeContext *m, unsigned int substr, +- uint8_t *data, unsigned int *data_size) +-{ +- if (m->avctx->sample_fmt == AV_SAMPLE_FMT_S32) +- return output_data_internal(m, substr, data, data_size, 1); +- else +- return output_data_internal(m, substr, data, data_size, 0); +-} +- +- + /** Read an access unit from the stream. + * @return negative on error, 0 if not enough data is present in the input stream, + * otherwise the number of bytes consumed. */ + +-static int read_access_unit(AVCodecContext *avctx, void* data, int *data_size, +- AVPacket *avpkt) ++static int read_access_unit(AVCodecContext *avctx, void* data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +@@ -956,6 +1018,7 @@ + uint8_t substream_parity_present[MAX_SUBSTREAMS]; + uint16_t substream_data_len[MAX_SUBSTREAMS]; + uint8_t parity_bits; ++ int ret; + + if (buf_size < 4) + return 0; +@@ -963,7 +1026,7 @@ + length = (AV_RB16(buf) & 0xfff) * 2; + + if (length < 4 || length > buf_size) +- return -1; ++ return AVERROR_INVALIDDATA; + + init_get_bits(&gb, (buf + 4), (length - 4) * 8); + +@@ -978,7 +1041,7 @@ + if (!m->params_valid) { + av_log(m->avctx, AV_LOG_WARNING, + "Stream parameters not seen; skipping frame.\n"); +- *data_size = 0; ++ *got_frame_ptr = 0; + return length; + } + +@@ -1069,8 +1132,8 @@ + if (!s->restart_seen) + goto next_substr; + +- if (read_block_data(m, &gb, substr) < 0) +- return -1; ++ if ((ret = read_block_data(m, &gb, substr)) < 0) ++ return ret; + + if (get_bits_count(&gb) >= substream_data_len[substr] * 8) + goto substream_length_mismatch; +@@ -1083,13 +1146,13 @@ + int shorten_by; + + if (get_bits(&gb, 16) != 0xD234) +- return -1; ++ return AVERROR_INVALIDDATA; + + shorten_by = get_bits(&gb, 16); + if (m->avctx->codec_id == CODEC_ID_TRUEHD && shorten_by & 0x2000) + s->blockpos -= FFMIN(shorten_by & 0x1FFF, s->blockpos); + else if (m->avctx->codec_id == CODEC_ID_MLP && shorten_by != 0xD234) +- return -1; ++ return AVERROR_INVALIDDATA; + + if (substr == m->max_decoded_substream) + av_log(m->avctx, AV_LOG_INFO, "End of stream indicated.\n"); +@@ -1123,42 +1186,40 @@ + + rematrix_channels(m, m->max_decoded_substream); + +- if (output_data(m, m->max_decoded_substream, data, data_size) < 0) +- return -1; ++ if ((ret = output_data(m, m->max_decoded_substream, data, got_frame_ptr)) < 0) ++ return ret; + + return length; + + substream_length_mismatch: + av_log(m->avctx, AV_LOG_ERROR, "substream %d length mismatch\n", substr); +- return -1; ++ return AVERROR_INVALIDDATA; + + error: + m->params_valid = 0; +- return -1; ++ return AVERROR_INVALIDDATA; + } + + AVCodec ff_mlp_decoder = { +- "mlp", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MLP, +- sizeof(MLPDecodeContext), +- mlp_decode_init, +- NULL, +- NULL, +- read_access_unit, ++ .name = "mlp", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MLP, ++ .priv_data_size = sizeof(MLPDecodeContext), ++ .init = mlp_decode_init, ++ .decode = read_access_unit, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("MLP (Meridian Lossless Packing)"), + }; + + #if CONFIG_TRUEHD_DECODER + AVCodec ff_truehd_decoder = { +- "truehd", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_TRUEHD, +- sizeof(MLPDecodeContext), +- mlp_decode_init, +- NULL, +- NULL, +- read_access_unit, ++ .name = "truehd", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_TRUEHD, ++ .priv_data_size = sizeof(MLPDecodeContext), ++ .init = mlp_decode_init, ++ .decode = read_access_unit, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("TrueHD"), + }; + #endif /* CONFIG_TRUEHD_DECODER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlpdsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlpdsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlpdsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlpdsp.c 2012-05-14 14:08:53.977332796 +0200 +@@ -19,8 +19,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcodec/mlp.h" + #include "dsputil.h" ++#include "mlp.h" + + static void ff_mlp_filter_channel(int32_t *state, const int32_t *coeff, + int firorder, int iirorder, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlp_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlp_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlp_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlp_parser.c 2012-05-14 14:08:53.973332716 +0200 +@@ -27,6 +27,7 @@ + #include + + #include "libavutil/crc.h" ++#include "libavutil/audioconvert.h" + #include "get_bits.h" + #include "parser.h" + #include "mlp_parser.h" +@@ -42,11 +43,52 @@ + 5, 6, 5, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + }; + ++const uint64_t ff_mlp_layout[32] = { ++ AV_CH_LAYOUT_MONO, ++ AV_CH_LAYOUT_STEREO, ++ AV_CH_LAYOUT_2_1, ++ AV_CH_LAYOUT_QUAD, ++ AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_SURROUND, ++ AV_CH_LAYOUT_4POINT0, ++ AV_CH_LAYOUT_5POINT0_BACK, ++ AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_5POINT1_BACK, ++ AV_CH_LAYOUT_4POINT0, ++ AV_CH_LAYOUT_5POINT0_BACK, ++ AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_5POINT1_BACK, ++ AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_5POINT0_BACK, ++ AV_CH_LAYOUT_5POINT1_BACK, ++ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ++}; ++ + static const uint8_t thd_chancount[13] = { + // LR C LFE LRs LRvh LRc LRrs Cs Ts LRsd LRw Cvh LFE2 + 2, 1, 1, 2, 2, 2, 2, 1, 1, 2, 2, 1, 1 + }; + ++static const uint64_t thd_layout[13] = { ++ AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT, // LR ++ AV_CH_FRONT_CENTER, // C ++ AV_CH_LOW_FREQUENCY, // LFE ++ AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRs ++ AV_CH_TOP_FRONT_LEFT|AV_CH_TOP_FRONT_RIGHT, // LRvh ++ AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRc ++ AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, // LRrs ++ AV_CH_BACK_CENTER, // Cs ++ AV_CH_TOP_CENTER, // Ts ++ AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, // LRsd - TODO: Surround Direct ++ AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER, // LRw - TODO: Wide ++ AV_CH_TOP_FRONT_CENTER, // Cvh ++ AV_CH_LOW_FREQUENCY // LFE2 ++}; ++ + static int mlp_samplerate(int in) + { + if (in == 0xF) +@@ -65,6 +107,16 @@ + return channels; + } + ++uint64_t ff_truehd_layout(int chanmap) ++{ ++ int layout = 0, i; ++ ++ for (i = 0; i < 13; i++) ++ layout |= thd_layout[i] * ((chanmap >> i) & 1); ++ ++ return layout; ++} ++ + /** Read a major sync info header - contains high level information about + * the stream - sample rate, channel arrangement etc. Most of this + * information is not actually necessary for decoding, only for playback. +@@ -86,11 +138,11 @@ + checksum = ff_mlp_checksum16(gb->buffer, 26); + if (checksum != AV_RL16(gb->buffer+26)) { + av_log(log, AV_LOG_ERROR, "major sync info header checksum error\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + if (get_bits_long(gb, 24) != 0xf8726f) /* Sync words */ +- return -1; ++ return AVERROR_INVALIDDATA; + + mh->stream_type = get_bits(gb, 8); + +@@ -121,7 +173,7 @@ + + mh->channels_thd_stream2 = get_bits(gb, 13); + } else +- return -1; ++ return AVERROR_INVALIDDATA; + + mh->access_unit_size = 40 << (ratebits & 7); + mh->access_unit_size_pow2 = 64 << (ratebits & 7); +@@ -211,6 +263,9 @@ + mp->bytes_left = ((mp->pc.index > 0 ? mp->pc.buffer[0] : buf[0]) << 8) + | (mp->pc.index > 1 ? mp->pc.buffer[1] : buf[1-mp->pc.index]); + mp->bytes_left = (mp->bytes_left & 0xfff) * 2; ++ if (mp->bytes_left <= 0) { // prevent infinite loop ++ goto lost_sync; ++ } + mp->bytes_left -= mp->pc.index; + } + +@@ -264,12 +319,16 @@ + if (mh.stream_type == 0xbb) { + /* MLP stream */ + avctx->channels = mlp_channels[mh.channels_mlp]; ++ avctx->channel_layout = ff_mlp_layout[mh.channels_mlp]; + } else { /* mh.stream_type == 0xba */ + /* TrueHD stream */ +- if (mh.channels_thd_stream2) ++ if (mh.channels_thd_stream2) { + avctx->channels = truehd_channels(mh.channels_thd_stream2); +- else ++ avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream2); ++ } else { + avctx->channels = truehd_channels(mh.channels_thd_stream1); ++ avctx->channel_layout = ff_truehd_layout(mh.channels_thd_stream1); ++ } + } + + if (!mh.is_vbr) /* Stream is CBR */ +@@ -289,9 +348,9 @@ + } + + AVCodecParser ff_mlp_parser = { +- { CODEC_ID_MLP, CODEC_ID_TRUEHD }, +- sizeof(MLPParseContext), +- mlp_init, +- mlp_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_MLP, CODEC_ID_TRUEHD }, ++ .priv_data_size = sizeof(MLPParseContext), ++ .parser_init = mlp_init, ++ .parser_parse = mlp_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlp_parser.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlp_parser.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mlp_parser.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mlp_parser.h 2012-05-14 14:08:53.974332736 +0200 +@@ -54,6 +54,9 @@ + + + int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb); ++uint64_t ff_truehd_layout(int chanmap); ++ ++extern const uint64_t ff_mlp_layout[32]; + + #endif /* AVCODEC_MLP_PARSER_H */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mmvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mmvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mmvideo.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mmvideo.c 2012-05-14 14:08:53.979332837 +0200 +@@ -33,6 +33,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "bytestream.h" + + #define MM_PREAMBLE_SIZE 6 + +@@ -48,6 +49,7 @@ + AVCodecContext *avctx; + AVFrame frame; + int palette[AVPALETTE_COUNT]; ++ GetByteContext gb; + } MmContext; + + static av_cold int mm_decode_init(AVCodecContext *avctx) +@@ -58,49 +60,46 @@ + + avctx->pix_fmt = PIX_FMT_PAL8; + +- s->frame.reference = 1; +- if (avctx->get_buffer(avctx, &s->frame)) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; +- } ++ avcodec_get_frame_defaults(&s->frame); ++ s->frame.reference = 3; + + return 0; + } + +-static void mm_decode_pal(MmContext *s, const uint8_t *buf, const uint8_t *buf_end) ++static int mm_decode_pal(MmContext *s) + { + int i; +- buf += 4; +- for (i=0; i<128 && buf+2palette[i] = AV_RB24(buf); ++ ++ bytestream2_skip(&s->gb, 4); ++ for (i = 0; i < 128; i++) { ++ s->palette[i] = 0xFF << 24 | bytestream2_get_be24(&s->gb); + s->palette[i+128] = s->palette[i]<<2; +- buf += 3; + } ++ ++ return 0; + } + + /** + * @param half_horiz Half horizontal resolution (0 or 1) + * @param half_vert Half vertical resolution (0 or 1) + */ +-static void mm_decode_intra(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) ++static int mm_decode_intra(MmContext * s, int half_horiz, int half_vert) + { + int i, x, y; + i=0; x=0; y=0; + +- while(igb) > 0) { + int run_length, color; + + if (y >= s->avctx->height) +- return; ++ return 0; + +- if (buf[i] & 0x80) { ++ color = bytestream2_get_byte(&s->gb); ++ if (color & 0x80) { + run_length = 1; +- color = buf[i]; +- i++; + }else{ +- run_length = (buf[i] & 0x7f) + 2; +- color = buf[i+1]; +- i+=2; ++ run_length = (color & 0x7f) + 2; ++ color = bytestream2_get_byte(&s->gb); + } + + if (half_horiz) +@@ -118,23 +117,28 @@ + y += 1 + half_vert; + } + } ++ ++ return 0; + } + + /* + * @param half_horiz Half horizontal resolution (0 or 1) + * @param half_vert Half vertical resolution (0 or 1) + */ +-static void mm_decode_inter(MmContext * s, int half_horiz, int half_vert, const uint8_t *buf, int buf_size) ++static int mm_decode_inter(MmContext * s, int half_horiz, int half_vert) + { +- const int data_ptr = 2 + AV_RL16(&buf[0]); +- int d, r, y; +- d = data_ptr; r = 2; y = 0; ++ int data_off = bytestream2_get_le16(&s->gb), y = 0; ++ GetByteContext data_ptr; + +- while(r < data_ptr) { ++ if (bytestream2_get_bytes_left(&s->gb) < data_off) ++ return AVERROR_INVALIDDATA; ++ ++ bytestream2_init(&data_ptr, s->gb.buffer + data_off, bytestream2_get_bytes_left(&s->gb) - data_off); ++ while (s->gb.buffer < data_ptr.buffer_start) { + int i, j; +- int length = buf[r] & 0x7f; +- int x = buf[r+1] + ((buf[r] & 0x80) << 1); +- r += 2; ++ int length = bytestream2_get_byte(&s->gb); ++ int x = bytestream2_get_byte(&s->gb) + ((length & 0x80) << 1); ++ length &= 0x7F; + + if (length==0) { + y += x; +@@ -142,13 +146,14 @@ + } + + if (y + half_vert >= s->avctx->height) +- return; ++ return 0; + + for(i=0; igb); + for(j=0; j<8; j++) { +- int replace = (buf[r+i] >> (7-j)) & 1; ++ int replace = (replace_array >> (7-j)) & 1; + if (replace) { +- int color = buf[d]; ++ int color = bytestream2_get_byte(&data_ptr); + s->frame.data[0][y*s->frame.linesize[0] + x] = color; + if (half_horiz) + s->frame.data[0][y*s->frame.linesize[0] + x + 1] = color; +@@ -157,15 +162,15 @@ + if (half_horiz) + s->frame.data[0][(y+1)*s->frame.linesize[0] + x + 1] = color; + } +- d++; + } + x += 1 + half_horiz; + } + } + +- r += length; + y += 1 + half_vert; + } ++ ++ return 0; + } + + static int mm_decode_frame(AVCodecContext *avctx, +@@ -175,25 +180,35 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + MmContext *s = avctx->priv_data; +- const uint8_t *buf_end = buf+buf_size; +- int type; ++ int type, res; + ++ if (buf_size < MM_PREAMBLE_SIZE) ++ return AVERROR_INVALIDDATA; + type = AV_RL16(&buf[0]); + buf += MM_PREAMBLE_SIZE; + buf_size -= MM_PREAMBLE_SIZE; ++ bytestream2_init(&s->gb, buf, buf_size); + +- switch(type) { +- case MM_TYPE_PALETTE : mm_decode_pal(s, buf, buf_end); return buf_size; +- case MM_TYPE_INTRA : mm_decode_intra(s, 0, 0, buf, buf_size); break; +- case MM_TYPE_INTRA_HH : mm_decode_intra(s, 1, 0, buf, buf_size); break; +- case MM_TYPE_INTRA_HHV : mm_decode_intra(s, 1, 1, buf, buf_size); break; +- case MM_TYPE_INTER : mm_decode_inter(s, 0, 0, buf, buf_size); break; +- case MM_TYPE_INTER_HH : mm_decode_inter(s, 1, 0, buf, buf_size); break; +- case MM_TYPE_INTER_HHV : mm_decode_inter(s, 1, 1, buf, buf_size); break; +- default : ++ if (avctx->reget_buffer(avctx, &s->frame) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + ++ switch(type) { ++ case MM_TYPE_PALETTE : res = mm_decode_pal(s); return buf_size; ++ case MM_TYPE_INTRA : res = mm_decode_intra(s, 0, 0); break; ++ case MM_TYPE_INTRA_HH : res = mm_decode_intra(s, 1, 0); break; ++ case MM_TYPE_INTRA_HHV : res = mm_decode_intra(s, 1, 1); break; ++ case MM_TYPE_INTER : res = mm_decode_inter(s, 0, 0); break; ++ case MM_TYPE_INTER_HH : res = mm_decode_inter(s, 1, 0); break; ++ case MM_TYPE_INTER_HHV : res = mm_decode_inter(s, 1, 1); break; ++ default: ++ res = AVERROR_INVALIDDATA; ++ break; ++ } ++ if (res < 0) ++ return res; ++ + memcpy(s->frame.data[1], s->palette, AVPALETTE_SIZE); + + *data_size = sizeof(AVFrame); +@@ -213,14 +228,13 @@ + } + + AVCodec ff_mmvideo_decoder = { +- "mmvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MMVIDEO, +- sizeof(MmContext), +- mm_decode_init, +- NULL, +- mm_decode_end, +- mm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "mmvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MMVIDEO, ++ .priv_data_size = sizeof(MmContext), ++ .init = mm_decode_init, ++ .close = mm_decode_end, ++ .decode = mm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion_est.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion_est.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion_est.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion_est.c 2012-05-14 14:08:53.983332917 +0200 +@@ -52,7 +52,7 @@ + int src_index, int ref_index, + int size, int h); + +-static inline int update_map_generation(MotionEstContext *c) ++static inline unsigned update_map_generation(MotionEstContext *c) + { + c->map_generation+= 1<<(ME_MAP_MV_BITS*2); + if(c->map_generation==0){ +@@ -248,7 +248,7 @@ + } + } + +-/*! \brief compares a block (either a full macroblock or a partition thereof) ++/** @brief compares a block (either a full macroblock or a partition thereof) + against a proposed motion-compensated prediction of that block + */ + static av_always_inline int cmp(MpegEncContext *s, const int x, const int y, const int subx, const int suby, +@@ -374,30 +374,6 @@ + return 0; + } + +-#if 0 +-static int pix_dev(uint8_t * pix, int line_size, int mean) +-{ +- int s, i, j; +- +- s = 0; +- for (i = 0; i < 16; i++) { +- for (j = 0; j < 16; j += 8) { +- s += FFABS(pix[0]-mean); +- s += FFABS(pix[1]-mean); +- s += FFABS(pix[2]-mean); +- s += FFABS(pix[3]-mean); +- s += FFABS(pix[4]-mean); +- s += FFABS(pix[5]-mean); +- s += FFABS(pix[6]-mean); +- s += FFABS(pix[7]-mean); +- pix += 8; +- } +- pix += line_size - 16; +- } +- return s; +-} +-#endif +- + static inline void no_motion_search(MpegEncContext * s, + int *mx_ptr, int *my_ptr) + { +@@ -533,16 +509,16 @@ + if(mv4){ + int mot_xy= s->block_index[0]; + +- s->current_picture.motion_val[0][mot_xy ][0]= mx; +- s->current_picture.motion_val[0][mot_xy ][1]= my; +- s->current_picture.motion_val[0][mot_xy+1][0]= mx; +- s->current_picture.motion_val[0][mot_xy+1][1]= my; ++ s->current_picture.f.motion_val[0][mot_xy ][0] = mx; ++ s->current_picture.f.motion_val[0][mot_xy ][1] = my; ++ s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx; ++ s->current_picture.f.motion_val[0][mot_xy + 1][1] = my; + + mot_xy += s->b8_stride; +- s->current_picture.motion_val[0][mot_xy ][0]= mx; +- s->current_picture.motion_val[0][mot_xy ][1]= my; +- s->current_picture.motion_val[0][mot_xy+1][0]= mx; +- s->current_picture.motion_val[0][mot_xy+1][1]= my; ++ s->current_picture.f.motion_val[0][mot_xy ][0] = mx; ++ s->current_picture.f.motion_val[0][mot_xy ][1] = my; ++ s->current_picture.f.motion_val[0][mot_xy + 1][0] = mx; ++ s->current_picture.f.motion_val[0][mot_xy + 1][1] = my; + } + } + +@@ -560,8 +536,8 @@ + if (s->unrestricted_mv) { + c->xmin = - x - 16; + c->ymin = - y - 16; +- c->xmax = - x + s->mb_width *16; +- c->ymax = - y + s->mb_height*16; ++ c->xmax = - x + s->width; ++ c->ymax = - y + s->height; + } else if (s->out_format == FMT_H261){ + // Search range of H261 is different from other codec standards + c->xmin = (x > 15) ? - 15 : 0; +@@ -600,10 +576,11 @@ + const int h=8; + int block; + int P[10][2]; +- int dmin_sum=0, mx4_sum=0, my4_sum=0; ++ int dmin_sum=0, mx4_sum=0, my4_sum=0, i; + int same=1; + const int stride= c->stride; + uint8_t *mv_penalty= c->current_mv_penalty; ++ int saftey_cliping= s->unrestricted_mv && (s->width&15) && (s->height&15); + + init_mv4_ref(c); + +@@ -615,8 +592,13 @@ + const int mot_stride = s->b8_stride; + const int mot_xy = s->block_index[block]; + +- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; +- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; ++ if(saftey_cliping){ ++ c->xmax = - 16*s->mb_x + s->width - 8*(block &1); ++ c->ymax = - 16*s->mb_y + s->height - 8*(block>>1); ++ } ++ ++ P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0]; ++ P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1]; + + if(P_LEFT[0] > (c->xmax<xmax<pred_x= pred_x4= P_LEFT[0]; + c->pred_y= pred_y4= P_LEFT[1]; + } else { +- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; +- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; +- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][0]; +- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + off[block]][1]; ++ P_TOP[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][0]; ++ P_TOP[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][1]; ++ P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][0]; ++ P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + off[block]][1]; + if(P_TOP[1] > (c->ymax<ymax<xmin<xmin< (c->xmax<xmax< (c->xmax<xmax< (c->ymax<ymax<p_mv_table, (1<<16)>>shift); + +@@ -680,8 +667,8 @@ + my4_sum+= my4; + } + +- s->current_picture.motion_val[0][ s->block_index[block] ][0]= mx4; +- s->current_picture.motion_val[0][ s->block_index[block] ][1]= my4; ++ s->current_picture.f.motion_val[0][s->block_index[block]][0] = mx4; ++ s->current_picture.f.motion_val[0][s->block_index[block]][1] = my4; + + if(mx4 != mx || my4 != my) same=0; + } +@@ -690,7 +677,7 @@ + return INT_MAX; + + if(s->dsp.me_sub_cmp[0] != s->dsp.mb_cmp[0]){ +- dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16); ++ dmin_sum += s->dsp.mb_cmp[0](s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*16*stride, c->scratchpad, stride, 16); + } + + if(c->avctx->mb_cmp&FF_CMP_CHROMA){ +@@ -705,15 +692,15 @@ + offset= (s->mb_x*8 + (mx>>1)) + (s->mb_y*8 + (my>>1))*s->uvlinesize; + + if(s->no_rounding){ +- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); +- s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); ++ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad , s->last_picture.f.data[1] + offset, s->uvlinesize, 8); ++ s->dsp.put_no_rnd_pixels_tab[1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8); + }else{ +- s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.data[1] + offset, s->uvlinesize, 8); +- s->dsp.put_pixels_tab [1][dxy](c->scratchpad+8 , s->last_picture.data[2] + offset, s->uvlinesize, 8); ++ s->dsp.put_pixels_tab [1][dxy](c->scratchpad , s->last_picture.f.data[1] + offset, s->uvlinesize, 8); ++ s->dsp.put_pixels_tab [1][dxy](c->scratchpad + 8, s->last_picture.f.data[2] + offset, s->uvlinesize, 8); + } + +- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8); +- dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8); ++ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad , s->uvlinesize, 8); ++ dmin_sum += s->dsp.mb_cmp[1](s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*8*s->uvlinesize, c->scratchpad+8, s->uvlinesize, 8); + } + + c->pred_x= mx; +@@ -879,7 +866,7 @@ + Picture *p= s->current_picture_ptr; + int mb_xy= mb_x + mb_y*s->mb_stride; + int xy= 2*mb_x + 2*mb_y*s->b8_stride; +- int mb_type= s->current_picture.mb_type[mb_xy]; ++ int mb_type= s->current_picture.f.mb_type[mb_xy]; + int flags= c->flags; + int shift= (flags&FLAG_QPEL) + 1; + int mask= (1<block_index[i]; +- clip_input_mv(s, p->motion_val[0][xy], !!IS_INTERLACED(mb_type)); +- clip_input_mv(s, p->motion_val[1][xy], !!IS_INTERLACED(mb_type)); ++ clip_input_mv(s, p->f.motion_val[0][xy], !!IS_INTERLACED(mb_type)); ++ clip_input_mv(s, p->f.motion_val[1][xy], !!IS_INTERLACED(mb_type)); + } + + if(IS_INTERLACED(mb_type)){ +@@ -912,8 +899,8 @@ + } + + if(USES_LIST(mb_type, 0)){ +- int field_select0= p->ref_index[0][4*mb_xy ]; +- int field_select1= p->ref_index[0][4*mb_xy+2]; ++ int field_select0= p->f.ref_index[0][4*mb_xy ]; ++ int field_select1= p->f.ref_index[0][4*mb_xy+2]; + assert(field_select0==0 ||field_select0==1); + assert(field_select1==0 ||field_select1==1); + init_interlaced_ref(s, 0); +@@ -921,46 +908,46 @@ + if(p_type){ + s->p_field_select_table[0][mb_xy]= field_select0; + s->p_field_select_table[1][mb_xy]= field_select1; +- *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ]; +- *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2]; ++ *(uint32_t*)s->p_field_mv_table[0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ]; ++ *(uint32_t*)s->p_field_mv_table[1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2]; + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER_I; + }else{ + s->b_field_select_table[0][0][mb_xy]= field_select0; + s->b_field_select_table[0][1][mb_xy]= field_select1; +- *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[0][xy ]; +- *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[0][xy2]; ++ *(uint32_t*)s->b_field_mv_table[0][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy ]; ++ *(uint32_t*)s->b_field_mv_table[0][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[0][xy2]; + s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_FORWARD_I; + } + +- x= p->motion_val[0][xy ][0]; +- y= p->motion_val[0][xy ][1]; ++ x = p->f.motion_val[0][xy ][0]; ++ y = p->f.motion_val[0][xy ][1]; + d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0, 0, cmpf, chroma_cmpf, flags); +- x= p->motion_val[0][xy2][0]; +- y= p->motion_val[0][xy2][1]; ++ x = p->f.motion_val[0][xy2][0]; ++ y = p->f.motion_val[0][xy2][1]; + d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1, 1, cmpf, chroma_cmpf, flags); + } + if(USES_LIST(mb_type, 1)){ +- int field_select0= p->ref_index[1][4*mb_xy ]; +- int field_select1= p->ref_index[1][4*mb_xy+2]; ++ int field_select0 = p->f.ref_index[1][4 * mb_xy ]; ++ int field_select1 = p->f.ref_index[1][4 * mb_xy + 2]; + assert(field_select0==0 ||field_select0==1); + assert(field_select1==0 ||field_select1==1); + init_interlaced_ref(s, 2); + + s->b_field_select_table[1][0][mb_xy]= field_select0; + s->b_field_select_table[1][1][mb_xy]= field_select1; +- *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy]= *(uint32_t*)p->motion_val[1][xy ]; +- *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy]= *(uint32_t*)p->motion_val[1][xy2]; ++ *(uint32_t*)s->b_field_mv_table[1][0][field_select0][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy ]; ++ *(uint32_t*)s->b_field_mv_table[1][1][field_select1][mb_xy] = *(uint32_t*)p->f.motion_val[1][xy2]; + if(USES_LIST(mb_type, 0)){ + s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BIDIR_I; + }else{ + s->mb_type[mb_xy]= CANDIDATE_MB_TYPE_BACKWARD_I; + } + +- x= p->motion_val[1][xy ][0]; +- y= p->motion_val[1][xy ][1]; ++ x = p->f.motion_val[1][xy ][0]; ++ y = p->f.motion_val[1][xy ][1]; + d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select0+2, 0, cmpf, chroma_cmpf, flags); +- x= p->motion_val[1][xy2][0]; +- y= p->motion_val[1][xy2][1]; ++ x = p->f.motion_val[1][xy2][0]; ++ y = p->f.motion_val[1][xy2][1]; + d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 8, field_select1+2, 1, cmpf, chroma_cmpf, flags); + //FIXME bidir scores + } +@@ -976,33 +963,33 @@ + init_mv4_ref(c); + for(i=0; i<4; i++){ + xy= s->block_index[i]; +- x= p->motion_val[0][xy][0]; +- y= p->motion_val[0][xy][1]; ++ x= p->f.motion_val[0][xy][0]; ++ y= p->f.motion_val[0][xy][1]; + d+= cmp(s, x>>shift, y>>shift, x&mask, y&mask, 1, 8, i, i, cmpf, chroma_cmpf, flags); + } + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER4V; + }else{ + if(USES_LIST(mb_type, 0)){ + if(p_type){ +- *(uint32_t*)s->p_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; ++ *(uint32_t*)s->p_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy]; + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTER; + }else if(USES_LIST(mb_type, 1)){ +- *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; +- *(uint32_t*)s->b_bidir_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy]; ++ *(uint32_t*)s->b_bidir_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy]; ++ *(uint32_t*)s->b_bidir_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy]; + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BIDIR; + }else{ +- *(uint32_t*)s->b_forw_mv_table[mb_xy]= *(uint32_t*)p->motion_val[0][xy]; ++ *(uint32_t*)s->b_forw_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[0][xy]; + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_FORWARD; + } +- x= p->motion_val[0][xy][0]; +- y= p->motion_val[0][xy][1]; ++ x = p->f.motion_val[0][xy][0]; ++ y = p->f.motion_val[0][xy][1]; + d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 0, 0, cmpf, chroma_cmpf, flags); + }else if(USES_LIST(mb_type, 1)){ +- *(uint32_t*)s->b_back_mv_table[mb_xy]= *(uint32_t*)p->motion_val[1][xy]; ++ *(uint32_t*)s->b_back_mv_table[mb_xy] = *(uint32_t*)p->f.motion_val[1][xy]; + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_BACKWARD; + +- x= p->motion_val[1][xy][0]; +- y= p->motion_val[1][xy][1]; ++ x = p->f.motion_val[1][xy][0]; ++ y = p->f.motion_val[1][xy][1]; + d = cmp(s, x>>shift, y>>shift, x&mask, y&mask, 0, 16, 2, 0, cmpf, chroma_cmpf, flags); + }else + s->mb_type[mb_xy]=CANDIDATE_MB_TYPE_INTRA; +@@ -1023,7 +1010,7 @@ + int mb_type=0; + Picture * const pic= &s->current_picture; + +- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0); ++ init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0); + + assert(s->quarter_sample==0 || s->quarter_sample==1); + assert(s->linesize == c->stride); +@@ -1040,7 +1027,7 @@ + /* intra / predictive decision */ + pix = c->src[0][0]; + sum = s->dsp.pix_sum(pix, s->linesize); +- varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500; ++ varc = s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500; + + pic->mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; + pic->mb_var [s->mb_stride * mb_y + mb_x] = (varc+128)>>8; +@@ -1075,16 +1062,16 @@ + const int mot_stride = s->b8_stride; + const int mot_xy = s->block_index[0]; + +- P_LEFT[0] = s->current_picture.motion_val[0][mot_xy - 1][0]; +- P_LEFT[1] = s->current_picture.motion_val[0][mot_xy - 1][1]; ++ P_LEFT[0] = s->current_picture.f.motion_val[0][mot_xy - 1][0]; ++ P_LEFT[1] = s->current_picture.f.motion_val[0][mot_xy - 1][1]; + + if(P_LEFT[0] > (c->xmax<xmax<first_slice_line) { +- P_TOP[0] = s->current_picture.motion_val[0][mot_xy - mot_stride ][0]; +- P_TOP[1] = s->current_picture.motion_val[0][mot_xy - mot_stride ][1]; +- P_TOPRIGHT[0] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][0]; +- P_TOPRIGHT[1] = s->current_picture.motion_val[0][mot_xy - mot_stride + 2][1]; ++ P_TOP[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][0]; ++ P_TOP[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride ][1]; ++ P_TOPRIGHT[0] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][0]; ++ P_TOPRIGHT[1] = s->current_picture.f.motion_val[0][mot_xy - mot_stride + 2][1]; + if(P_TOP[1] > (c->ymax<ymax<xmin<xmin< (c->ymax<ymax<mb_cmp_score[s->mb_stride * mb_y + mb_x] = dmin; + c->mc_mb_var_sum_temp += (vard+128)>>8; + +-#if 0 +- printf("varc=%4d avg_var=%4d (sum=%4d) vard=%4d mx=%2d my=%2d\n", +- varc, s->avg_mb_var, sum, vard, mx - xx, my - yy); +-#endif + if(mb_type){ + int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); + int i_score= varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*20; +@@ -1206,7 +1189,7 @@ + if((c->avctx->mb_cmp&0xFF)==FF_CMP_SSE){ + intra_score= varc - 500; + }else{ +- int mean= (sum+128)>>8; ++ unsigned mean = (sum+128)>>8; + mean*= 0x01010101; + + for(i=0; i<16; i++){ +@@ -1218,37 +1201,13 @@ + + intra_score= s->dsp.mb_cmp[0](s, c->scratchpad, pix, s->linesize, 16); + } +-#if 0 //FIXME +- /* get chroma score */ +- if(c->avctx->mb_cmp&FF_CMP_CHROMA){ +- for(i=1; i<3; i++){ +- uint8_t *dest_c; +- int mean; +- +- if(s->out_format == FMT_H263){ +- mean= (s->dc_val[i][mb_x + mb_y*s->b8_stride] + 4)>>3; //FIXME not exact but simple ;) +- }else{ +- mean= (s->last_dc[i] + 4)>>3; +- } +- dest_c = s->new_picture.data[i] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; +- +- mean*= 0x01010101; +- for(i=0; i<8; i++){ +- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 0]) = mean; +- *(uint32_t*)(&c->scratchpad[i*s->uvlinesize+ 4]) = mean; +- } +- +- intra_score+= s->dsp.mb_cmp[1](s, c->scratchpad, dest_c, s->uvlinesize); +- } +- } +-#endif + intra_score += c->mb_penalty_factor*16; + + if(intra_score < dmin){ + mb_type= CANDIDATE_MB_TYPE_INTRA; +- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup ++ s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = CANDIDATE_MB_TYPE_INTRA; //FIXME cleanup + }else +- s->current_picture.mb_type[mb_y*s->mb_stride + mb_x]= 0; ++ s->current_picture.f.mb_type[mb_y*s->mb_stride + mb_x] = 0; + + { + int p_score= FFMIN(vard, varc-500+(s->lambda2>>FF_LAMBDA_SHIFT)*100); +@@ -1268,7 +1227,7 @@ + int P[10][2]; + const int shift= 1+s->quarter_sample; + const int xy= mb_x + mb_y*s->mb_stride; +- init_ref(c, s->new_picture.data, s->last_picture.data, NULL, 16*mb_x, 16*mb_y, 0); ++ init_ref(c, s->new_picture.f.data, s->last_picture.f.data, NULL, 16*mb_x, 16*mb_y, 0); + + assert(s->quarter_sample==0 || s->quarter_sample==1); + +@@ -1342,28 +1301,26 @@ + break; + case ME_X1: + case ME_EPZS: +- { +- P_LEFT[0] = mv_table[mot_xy - 1][0]; +- P_LEFT[1] = mv_table[mot_xy - 1][1]; ++ P_LEFT[0] = mv_table[mot_xy - 1][0]; ++ P_LEFT[1] = mv_table[mot_xy - 1][1]; + +- if(P_LEFT[0] > (c->xmax<xmax< (c->xmax << shift)) P_LEFT[0] = (c->xmax << shift); + +- /* special case for first line */ +- if (!s->first_slice_line) { +- P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; +- P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; +- P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1 ][0]; +- P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1 ][1]; +- if(P_TOP[1] > (c->ymax<ymax<xmin<xmin< (c->ymax<ymax<first_slice_line) { ++ P_TOP[0] = mv_table[mot_xy - mot_stride ][0]; ++ P_TOP[1] = mv_table[mot_xy - mot_stride ][1]; ++ P_TOPRIGHT[0] = mv_table[mot_xy - mot_stride + 1][0]; ++ P_TOPRIGHT[1] = mv_table[mot_xy - mot_stride + 1][1]; ++ if (P_TOP[1] > (c->ymax << shift)) P_TOP[1] = (c->ymax << shift); ++ if (P_TOPRIGHT[0] < (c->xmin << shift)) P_TOPRIGHT[0] = (c->xmin << shift); ++ if (P_TOPRIGHT[1] > (c->ymax << shift)) P_TOPRIGHT[1] = (c->ymax << shift); + +- P_MEDIAN[0]= mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); +- P_MEDIAN[1]= mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); +- } +- c->pred_x= P_LEFT[0]; +- c->pred_y= P_LEFT[1]; ++ P_MEDIAN[0] = mid_pred(P_LEFT[0], P_TOP[0], P_TOPRIGHT[0]); ++ P_MEDIAN[1] = mid_pred(P_LEFT[1], P_TOP[1], P_TOPRIGHT[1]); + } ++ c->pred_x = P_LEFT[0]; ++ c->pred_y = P_LEFT[1]; + + if(mv_table == s->b_forw_mv_table){ + mv_scale= (s->pb_time<<16) / (s->pp_time<>shift; + ymax= xmax= 31>>shift; + +- if(IS_8X8(s->next_picture.mb_type[mot_xy])){ ++ if (IS_8X8(s->next_picture.f.mb_type[mot_xy])) { + s->mv_type= MV_TYPE_8X8; + }else{ + s->mv_type= MV_TYPE_16X16; +@@ -1629,8 +1586,8 @@ + int index= s->block_index[i]; + int min, max; + +- c->co_located_mv[i][0]= s->next_picture.motion_val[0][index][0]; +- c->co_located_mv[i][1]= s->next_picture.motion_val[0][index][1]; ++ c->co_located_mv[i][0] = s->next_picture.f.motion_val[0][index][0]; ++ c->co_located_mv[i][1] = s->next_picture.f.motion_val[0][index][1]; + c->direct_basis_mv[i][0]= c->co_located_mv[i][0]*time_pb/time_pp + ((i& 1)<<(shift+3)); + c->direct_basis_mv[i][1]= c->co_located_mv[i][1]*time_pb/time_pp + ((i>>1)<<(shift+3)); + // c->direct_basis_mv[1][i][0]= c->co_located_mv[i][0]*(time_pb - time_pp)/time_pp + ((i &1)<<(shift+3); +@@ -1712,13 +1669,14 @@ + int fmin, bmin, dmin, fbmin, bimin, fimin; + int type=0; + const int xy = mb_y*s->mb_stride + mb_x; +- init_ref(c, s->new_picture.data, s->last_picture.data, s->next_picture.data, 16*mb_x, 16*mb_y, 2); ++ init_ref(c, s->new_picture.f.data, s->last_picture.f.data, ++ s->next_picture.f.data, 16 * mb_x, 16 * mb_y, 2); + + get_limits(s, 16*mb_x, 16*mb_y); + + c->skip=0; + +- if(s->codec_id == CODEC_ID_MPEG4 && s->next_picture.mbskip_table[xy]){ ++ if (s->codec_id == CODEC_ID_MPEG4 && s->next_picture.f.mbskip_table[xy]) { + int score= direct_search(s, mb_x, mb_y); //FIXME just check 0,0 + + score= ((unsigned)(score*score + 128*256))>>16; +@@ -1853,10 +1811,6 @@ + if(dmin>256*256*16) type&= ~CANDIDATE_MB_TYPE_DIRECT; //do not try direct mode if it is invalid for this MB + if(s->codec_id == CODEC_ID_MPEG4 && type&CANDIDATE_MB_TYPE_DIRECT && s->flags&CODEC_FLAG_MV0 && *(uint32_t*)s->b_direct_mv_table[xy]) + type |= CANDIDATE_MB_TYPE_DIRECT0; +-#if 0 +- if(s->out_format == FMT_MPEG1) +- type |= CANDIDATE_MB_TYPE_INTRA; +-#endif + } + + s->mb_type[mb_y*s->mb_stride + mb_x]= type; +@@ -1895,7 +1849,7 @@ + continue; + + for(j=0; jpict_type==FF_B_TYPE || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) ++ if(s->pict_type==AV_PICTURE_TYPE_B || s->current_picture.mc_mb_var[xy] < s->current_picture.mb_var[xy]) + score[j]-= 170; + } + } +@@ -1927,7 +1881,7 @@ + MotionEstContext * const c= &s->me; + const int f_code= s->f_code; + int y, range; +- assert(s->pict_type==FF_P_TYPE); ++ assert(s->pict_type==AV_PICTURE_TYPE_P); + + range = (((s->out_format == FMT_MPEG1 || s->msmpeg4_version) ? 8 : 16) << f_code); + +@@ -1951,14 +1905,14 @@ + int block; + for(block=0; block<4; block++){ + int off= (block& 1) + (block>>1)*wrap; +- int mx= s->current_picture.motion_val[0][ xy + off ][0]; +- int my= s->current_picture.motion_val[0][ xy + off ][1]; ++ int mx = s->current_picture.f.motion_val[0][ xy + off ][0]; ++ int my = s->current_picture.f.motion_val[0][ xy + off ][1]; + + if( mx >=range || mx <-range + || my >=range || my <-range){ + s->mb_type[i] &= ~CANDIDATE_MB_TYPE_INTER4V; + s->mb_type[i] |= CANDIDATE_MB_TYPE_INTRA; +- s->current_picture.mb_type[i]= CANDIDATE_MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[i] = CANDIDATE_MB_TYPE_INTRA; + } + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion_est_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion_est_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion_est_template.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion_est_template.c 2012-05-14 14:08:53.986332978 +0200 +@@ -44,75 +44,6 @@ + COPY3_IF_LT(dmin, d, bx, hx, by, hy)\ + } + +-#if 0 +-static int hpel_motion_search)(MpegEncContext * s, +- int *mx_ptr, int *my_ptr, int dmin, +- uint8_t *ref_data[3], +- int size) +-{ +- const int xx = 16 * s->mb_x + 8*(n&1); +- const int yy = 16 * s->mb_y + 8*(n>>1); +- const int mx = *mx_ptr; +- const int my = *my_ptr; +- const int penalty_factor= c->sub_penalty_factor; +- +- LOAD_COMMON +- +- // INIT; +- //FIXME factorize +- me_cmp_func cmp, chroma_cmp, cmp_sub, chroma_cmp_sub; +- +- if(s->no_rounding /*FIXME b_type*/){ +- hpel_put= &s->dsp.put_no_rnd_pixels_tab[size]; +- chroma_hpel_put= &s->dsp.put_no_rnd_pixels_tab[size+1]; +- }else{ +- hpel_put=& s->dsp.put_pixels_tab[size]; +- chroma_hpel_put= &s->dsp.put_pixels_tab[size+1]; +- } +- cmpf= s->dsp.me_cmp[size]; +- chroma_cmpf= s->dsp.me_cmp[size+1]; +- cmp_sub= s->dsp.me_sub_cmp[size]; +- chroma_cmp_sub= s->dsp.me_sub_cmp[size+1]; +- +- if(c->skip){ //FIXME somehow move up (benchmark) +- *mx_ptr = 0; +- *my_ptr = 0; +- return dmin; +- } +- +- if(c->avctx->me_cmp != c->avctx->me_sub_cmp){ +- CMP_HPEL(dmin, 0, 0, mx, my, size); +- if(mx || my) +- dmin += (mv_penalty[2*mx - pred_x] + mv_penalty[2*my - pred_y])*penalty_factor; +- } +- +- if (mx > xmin && mx < xmax && +- my > ymin && my < ymax) { +- int bx=2*mx, by=2*my; +- int d= dmin; +- +- CHECK_HALF_MV(1, 1, mx-1, my-1) +- CHECK_HALF_MV(0, 1, mx , my-1) +- CHECK_HALF_MV(1, 1, mx , my-1) +- CHECK_HALF_MV(1, 0, mx-1, my ) +- CHECK_HALF_MV(1, 0, mx , my ) +- CHECK_HALF_MV(1, 1, mx-1, my ) +- CHECK_HALF_MV(0, 1, mx , my ) +- CHECK_HALF_MV(1, 1, mx , my ) +- +- assert(bx >= xmin*2 || bx <= xmax*2 || by >= ymin*2 || by <= ymax*2); +- +- *mx_ptr = bx; +- *my_ptr = by; +- }else{ +- *mx_ptr =2*mx; +- *my_ptr =2*my; +- } +- +- return dmin; +-} +- +-#else + static int hpel_motion_search(MpegEncContext * s, + int *mx_ptr, int *my_ptr, int dmin, + int src_index, int ref_index, +@@ -159,8 +90,8 @@ + + (mv_penalty[bx - pred_x] + mv_penalty[by+2 - pred_y])*c->penalty_factor; + + #if 1 +- int key; +- int map_generation= c->map_generation; ++ unsigned key; ++ unsigned map_generation= c->map_generation; + #ifndef NDEBUG + uint32_t *map= c->map; + #endif +@@ -220,7 +151,6 @@ + + return dmin; + } +-#endif + + static int no_sub_motion_search(MpegEncContext * s, + int *mx_ptr, int *my_ptr, int dmin, +@@ -280,7 +210,7 @@ + const int mx = *mx_ptr; + const int my = *my_ptr; + const int penalty_factor= c->sub_penalty_factor; +- const int map_generation= c->map_generation; ++ const unsigned map_generation = c->map_generation; + const int subpel_quality= c->avctx->me_subpel_quality; + uint32_t *map= c->map; + me_cmp_func cmpf, chroma_cmpf; +@@ -323,7 +253,6 @@ + int best_pos[8][2]; + + memset(best, 64, sizeof(int)*8); +-#if 1 + if(s->me.dia_size>=2){ + const int tl= score_map[(index-(1<>2, ny>>2) + } + +-#if 0 +- const int tl= score_map[(index-(1<>2, (ny + oy[i])>>2) +- } +-#endif +-#if 0 +- //outer ring +- CHECK_QUARTER_MV(1, 3, mx-1, my-1) +- CHECK_QUARTER_MV(1, 2, mx-1, my-1) +- CHECK_QUARTER_MV(1, 1, mx-1, my-1) +- CHECK_QUARTER_MV(2, 1, mx-1, my-1) +- CHECK_QUARTER_MV(3, 1, mx-1, my-1) +- CHECK_QUARTER_MV(0, 1, mx , my-1) +- CHECK_QUARTER_MV(1, 1, mx , my-1) +- CHECK_QUARTER_MV(2, 1, mx , my-1) +- CHECK_QUARTER_MV(3, 1, mx , my-1) +- CHECK_QUARTER_MV(3, 2, mx , my-1) +- CHECK_QUARTER_MV(3, 3, mx , my-1) +- CHECK_QUARTER_MV(3, 0, mx , my ) +- CHECK_QUARTER_MV(3, 1, mx , my ) +- CHECK_QUARTER_MV(3, 2, mx , my ) +- CHECK_QUARTER_MV(3, 3, mx , my ) +- CHECK_QUARTER_MV(2, 3, mx , my ) +- CHECK_QUARTER_MV(1, 3, mx , my ) +- CHECK_QUARTER_MV(0, 3, mx , my ) +- CHECK_QUARTER_MV(3, 3, mx-1, my ) +- CHECK_QUARTER_MV(2, 3, mx-1, my ) +- CHECK_QUARTER_MV(1, 3, mx-1, my ) +- CHECK_QUARTER_MV(1, 2, mx-1, my ) +- CHECK_QUARTER_MV(1, 1, mx-1, my ) +- CHECK_QUARTER_MV(1, 0, mx-1, my ) +-#endif + assert(bx >= xmin*4 && bx <= xmax*4 && by >= ymin*4 && by <= ymax*4); + + *mx_ptr = bx; +@@ -497,7 +356,7 @@ + + #define CHECK_MV(x,y)\ + {\ +- const int key= ((y)<= xmin);\ + assert((x) <= xmax);\ +@@ -525,7 +384,7 @@ + + #define CHECK_MV_DIR(x,y,new_dir)\ + {\ +- const int key= ((y)<map_generation; ++ unsigned map_generation = c->map_generation; + + cmpf= s->dsp.me_cmp[size]; + chroma_cmpf= s->dsp.me_cmp[size+1]; + + { /* ensure that the best point is in the MAP as h/qpel refinement needs it */ +- const int key= (best[1]<map_generation; ++ unsigned map_generation = c->map_generation; + + cmpf= s->dsp.me_cmp[size]; + chroma_cmpf= s->dsp.me_cmp[size+1]; +@@ -634,25 +493,6 @@ + + if(x!=best[0] || y!=best[1]) + dia_size=0; +-#if 0 +-{ +-int dx, dy, i; +-static int stats[8*8]; +-dx= FFABS(x-best[0]); +-dy= FFABS(y-best[1]); +-if(dy>dx){ +- dx^=dy; dy^=dx; dx^=dy; +-} +-stats[dy*8 + dx] ++; +-if(256*256*256*64 % (stats[0]+1)==0){ +- for(i=0; i<64; i++){ +- if((i&7)==0) printf("\n"); +- printf("%8d ", stats[i]); +- } +- printf("\n"); +-} +-} +-#endif + } + return dmin; + } +@@ -665,7 +505,7 @@ + me_cmp_func cmpf, chroma_cmpf; + LOAD_COMMON + LOAD_COMMON2 +- int map_generation= c->map_generation; ++ unsigned map_generation = c->map_generation; + int x,y,d; + const int dec= dia_size & (dia_size-1); + +@@ -699,7 +539,7 @@ + me_cmp_func cmpf, chroma_cmpf; + LOAD_COMMON + LOAD_COMMON2 +- int map_generation= c->map_generation; ++ unsigned map_generation = c->map_generation; + int x,y,i,d; + int dia_size= c->dia_size&0xFF; + const int dec= dia_size & (dia_size-1); +@@ -737,7 +577,7 @@ + me_cmp_func cmpf, chroma_cmpf; + LOAD_COMMON + LOAD_COMMON2 +- int map_generation= c->map_generation; ++ unsigned map_generation = c->map_generation; + int x,y,x2,y2, i, j, d; + const int dia_size= c->dia_size&0xFE; + static const int hex[16][2]={{-4,-2}, {-4,-1}, {-4, 0}, {-4, 1}, {-4, 2}, +@@ -784,7 +624,7 @@ + me_cmp_func cmpf, chroma_cmpf; + LOAD_COMMON + LOAD_COMMON2 +- int map_generation= c->map_generation; ++ unsigned map_generation = c->map_generation; + int x,y, d; + const int dia_size= c->dia_size&0xFF; + +@@ -813,7 +653,7 @@ + + #define SAB_CHECK_MV(ax,ay)\ + {\ +- const int key= ((ay)<map_generation; ++ unsigned map_generation = c->map_generation; + + cmpf= s->dsp.me_cmp[size]; + chroma_cmpf= s->dsp.me_cmp[size+1]; +@@ -937,7 +777,7 @@ + int dia_size; + LOAD_COMMON + LOAD_COMMON2 +- int map_generation= c->map_generation; ++ unsigned map_generation = c->map_generation; + + cmpf= s->dsp.me_cmp[size]; + chroma_cmpf= s->dsp.me_cmp[size+1]; +@@ -985,22 +825,6 @@ + + if(x!=best[0] || y!=best[1]) + dia_size=0; +-#if 0 +-{ +-int dx, dy, i; +-static int stats[8*8]; +-dx= FFABS(x-best[0]); +-dy= FFABS(y-best[1]); +-stats[dy*8 + dx] ++; +-if(256*256*256*64 % (stats[0]+1)==0){ +- for(i=0; i<64; i++){ +- if((i&7)==0) printf("\n"); +- printf("%6d ", stats[i]); +- } +- printf("\n"); +-} +-} +-#endif + } + return dmin; + } +@@ -1027,8 +851,8 @@ + return var_diamond_search(s, best, dmin, src_index, ref_index, penalty_factor, size, h, flags); + } + +-/*! +- \param P[10][2] a list of candidate mvs to check before starting the ++/** ++ @param P a list of candidate mvs to check before starting the + iterative search. If one of the candidates is close to the optimal mv, then + it takes fewer iterations. And it increases the chance that we find the + optimal mv. +@@ -1038,14 +862,14 @@ + int ref_mv_scale, int flags, int size, int h) + { + MotionEstContext * const c= &s->me; +- int best[2]={0, 0}; /*!< x and y coordinates of the best motion vector. ++ int best[2]={0, 0}; /**< x and y coordinates of the best motion vector. + i.e. the difference between the position of the + block currently being encoded and the position of + the block chosen to predict it from. */ + int d; ///< the score (cmp + penalty) of any given mv +- int dmin; /*!< the best value of d, i.e. the score ++ int dmin; /**< the best value of d, i.e. the score + corresponding to the mv stored in best[]. */ +- int map_generation; ++ unsigned map_generation; + int penalty_factor; + const int ref_mv_stride= s->mb_stride; //pass as arg FIXME + const int ref_mv_xy= s->mb_x + s->mb_y*ref_mv_stride; //add to last_mv beforepassing FIXME +@@ -1072,7 +896,7 @@ + score_map[0]= dmin; + + //FIXME precalc first term below? +- if((s->pict_type == FF_B_TYPE && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0) ++ if((s->pict_type == AV_PICTURE_TYPE_B && !(c->flags & FLAG_DIRECT)) || s->flags&CODEC_FLAG_MV0) + dmin += (mv_penalty[pred_x] + mv_penalty[pred_y])*penalty_factor; + + /* first line */ +@@ -1173,7 +997,7 @@ + MotionEstContext * const c= &s->me; + int best[2]={0, 0}; + int d, dmin; +- int map_generation; ++ unsigned map_generation; + const int penalty_factor= c->penalty_factor; + const int size=1; + const int h=8; +@@ -1233,7 +1057,7 @@ + MotionEstContext * const c= &s->me; + int best[2]={0, 0}; + int d, dmin; +- int map_generation; ++ unsigned map_generation; + const int penalty_factor= c->penalty_factor; + const int size=0; //FIXME pass as arg + const int h=8; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motionpixels.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motionpixels.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motionpixels.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motionpixels.c 2012-05-14 14:08:53.987332998 +0200 +@@ -52,15 +52,18 @@ + static av_cold int mp_decode_init(AVCodecContext *avctx) + { + MotionPixelsContext *mp = avctx->priv_data; ++ int w4 = (avctx->width + 3) & ~3; ++ int h4 = (avctx->height + 3) & ~3; + + motionpixels_tableinit(); + mp->avctx = avctx; + dsputil_init(&mp->dsp, avctx); +- mp->changes_map = av_mallocz(avctx->width * avctx->height); ++ mp->changes_map = av_mallocz(avctx->width * h4); + mp->offset_bits_len = av_log2(avctx->width * avctx->height) + 1; + mp->vpt = av_mallocz(avctx->height * sizeof(YuvPixel)); +- mp->hpt = av_mallocz(avctx->height * avctx->width / 16 * sizeof(YuvPixel)); ++ mp->hpt = av_mallocz(h4 * w4 / 16 * sizeof(YuvPixel)); + avctx->pix_fmt = PIX_FMT_RGB555; ++ avcodec_get_frame_defaults(&mp->frame); + return 0; + } + +@@ -238,7 +241,7 @@ + GetBitContext gb; + int i, count1, count2, sz; + +- mp->frame.reference = 1; ++ mp->frame.reference = 3; + mp->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &mp->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -252,6 +255,7 @@ + mp->dsp.bswap_buf((uint32_t *)mp->bswapbuf, (const uint32_t *)buf, buf_size / 4); + if (buf_size & 3) + memcpy(mp->bswapbuf + (buf_size & ~3), buf + (buf_size & ~3), buf_size & 3); ++ memset(mp->bswapbuf + buf_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + init_get_bits(&gb, mp->bswapbuf, buf_size * 8); + + memset(mp->changes_map, 0, avctx->width * avctx->height); +@@ -278,7 +282,10 @@ + if (sz == 0) + goto end; + +- init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0); ++ if (mp->max_codes_bits <= 0) ++ goto end; ++ if (init_vlc(&mp->vlc, mp->max_codes_bits, mp->codes_count, &mp->codes[0].size, sizeof(HuffCode), 1, &mp->codes[0].code, sizeof(HuffCode), 4, 0)) ++ goto end; + mp_decode_frame_helper(mp, &gb); + free_vlc(&mp->vlc); + +@@ -303,14 +310,13 @@ + } + + AVCodec ff_motionpixels_decoder = { +- "motionpixels", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MOTIONPIXELS, +- sizeof(MotionPixelsContext), +- mp_decode_init, +- NULL, +- mp_decode_end, +- mp_decode_frame, +- CODEC_CAP_DR1, ++ .name = "motionpixels", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MOTIONPIXELS, ++ .priv_data_size = sizeof(MotionPixelsContext), ++ .init = mp_decode_init, ++ .close = mp_decode_end, ++ .decode = mp_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Motion Pixels video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motionpixels_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motionpixels_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motionpixels_tablegen.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motionpixels_tablegen.h 2012-05-14 14:08:53.987332998 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef MOTIONPIXELS_TABLEGEN_H +-#define MOTIONPIXELS_TABLEGEN_H ++#ifndef AVCODEC_MOTIONPIXELS_TABLEGEN_H ++#define AVCODEC_MOTIONPIXELS_TABLEGEN_H + + #include + +@@ -30,7 +30,7 @@ + } YuvPixel; + + static int mp_yuv_to_rgb(int y, int v, int u, int clip_rgb) { +- static const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; ++ const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + int r, g, b; + + r = (1000 * y + 701 * v) / 1000; +@@ -88,4 +88,4 @@ + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* MOTIONPIXELS_TABLEGEN_H */ ++#endif /* AVCODEC_MOTIONPIXELS_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/motion-test.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/motion-test.c 2012-05-14 14:08:53.979332837 +0200 +@@ -33,14 +33,13 @@ + #include "dsputil.h" + #include "libavutil/lfg.h" + +-#undef exit + #undef printf + + #define WIDTH 64 + #define HEIGHT 64 + +-uint8_t img1[WIDTH * HEIGHT]; +-uint8_t img2[WIDTH * HEIGHT]; ++static uint8_t img1[WIDTH * HEIGHT]; ++static uint8_t img2[WIDTH * HEIGHT]; + + static void fill_random(uint8_t *tab, int size) + { +@@ -61,7 +60,6 @@ + { + printf("motion-test [-h]\n" + "test motion implementations\n"); +- exit(1); + } + + static int64_t gettime(void) +@@ -138,13 +136,13 @@ + switch(c) { + case 'h': + help(); +- break; ++ return 1; + } + } + + printf("ffmpeg motion test\n"); + +- ctx = avcodec_alloc_context(); ++ ctx = avcodec_alloc_context3(NULL); + ctx->dsp_mask = AV_CPU_FLAG_FORCE; + dsputil_init(&cctx, ctx); + for (c = 0; c < flags_size; c++) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mp3_header_compress_bsf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mp3_header_compress_bsf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mp3_header_compress_bsf.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mp3_header_compress_bsf.c 2012-05-14 14:08:53.988333018 +0200 +@@ -18,8 +18,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" +-#include "mpegaudio.h" ++#include "mpegaudiodecheader.h" + + + static int mp3_header_compress(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mp3_header_decompress_bsf.c 2012-05-14 14:08:53.988333018 +0200 +@@ -18,8 +18,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" +-#include "mpegaudio.h" ++#include "mpegaudiodecheader.h" + #include "mpegaudiodata.h" + + +@@ -49,10 +50,10 @@ + lsf = sample_rate < (24000+32000)/2; + mpeg25 = sample_rate < (12000+16000)/2; + sample_rate_index= (header>>10)&3; +- sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off ++ sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); //in case sample rate is a little off + + for(bitrate_index=2; bitrate_index<30; bitrate_index++){ +- frame_size = ff_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; ++ frame_size = avpriv_mpa_bitrate_tab[lsf][2][bitrate_index>>1]; + frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); + if(frame_size == buf_size + 4) + break; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc7.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc7.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc7.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc7.c 2012-05-14 14:08:53.991333078 +0200 +@@ -29,7 +29,8 @@ + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" +-#include "mpegaudio.h" ++#include "mpegaudiodsp.h" ++#include "libavutil/audioconvert.h" + + #include "mpc.h" + #include "mpc7data.h" +@@ -60,6 +61,13 @@ + static VLC_TYPE hdr_table[1 << MPC7_HDR_BITS][2]; + static VLC_TYPE quant_tables[7224][2]; + ++ /* Musepack SV7 is always stereo */ ++ if (avctx->channels != 2) { ++ av_log_ask_for_sample(avctx, "Unsupported number of channels: %d\n", ++ avctx->channels); ++ return AVERROR_PATCHWELCOME; ++ } ++ + if(avctx->extradata_size < 16){ + av_log(avctx, AV_LOG_ERROR, "Too small extradata size (%i)!\n", avctx->extradata_size); + return -1; +@@ -67,6 +75,7 @@ + memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); + av_lfg_init(&c->rnd, 0xDEADBEEF); + dsputil_init(&c->dsp, avctx); ++ ff_mpadsp_init(&c->mpadsp); + c->dsp.bswap_buf((uint32_t*)buf, (const uint32_t*)avctx->extradata, 4); + ff_mpc_init(); + init_get_bits(&gb, buf, 128); +@@ -86,7 +95,7 @@ + c->frames_to_skip = 0; + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ avctx->channel_layout = AV_CH_LAYOUT_STEREO; + + if(vlc_initialized) return 0; + av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); +@@ -127,6 +136,10 @@ + } + } + vlc_initialized = 1; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ + return 0; + } + +@@ -180,32 +193,40 @@ + int t = get_vlc2(gb, dscf_vlc.table, MPC7_DSCF_BITS, 1) - 7; + if (t == 8) + return get_bits(gb, 6); +- return ref + t; ++ return av_clip_uintp2(ref + t, 7); + } + +-static int mpc7_decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int mpc7_decode_frame(AVCodecContext * avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + MPCContext *c = avctx->priv_data; + GetBitContext gb; +- uint8_t *bits; + int i, ch; + int mb = -1; + Band *bands = c->bands; +- int off; ++ int off, ret; + int bits_used, bits_avail; + +- memset(bands, 0, sizeof(bands)); ++ memset(bands, 0, sizeof(*bands) * (c->maxbands + 1)); + if(buf_size <= 4){ + av_log(avctx, AV_LOG_ERROR, "Too small buffer passed (%i bytes)\n", buf_size); ++ return AVERROR(EINVAL); + } + +- bits = av_malloc(((buf_size - 1) & ~3) + FF_INPUT_BUFFER_PADDING_SIZE); +- c->dsp.bswap_buf((uint32_t*)bits, (const uint32_t*)(buf + 4), (buf_size - 4) >> 2); +- init_get_bits(&gb, bits, (buf_size - 4)* 8); ++ /* get output buffer */ ++ c->frame.nb_samples = buf[1] ? c->lastframelen : MPC_FRAME_SIZE; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ av_fast_padded_malloc(&c->buffer, &c->buffer_size, FFALIGN(buf_size - 1, 4)); ++ if (!c->buffer) ++ return AVERROR(ENOMEM); ++ c->dsp.bswap_buf((uint32_t*)c->buffer, (const uint32_t*)(buf + 4), (buf_size - 4) >> 2); ++ init_get_bits(&gb, c->buffer, (buf_size - 4)* 8); + skip_bits_long(&gb, buf[0]); + + /* read subband indexes */ +@@ -214,7 +235,7 @@ + int t = 4; + if(i) t = get_vlc2(&gb, hdr_vlc.table, MPC7_HDR_BITS, 1) - 5; + if(t == 4) bands[i].res[ch] = get_bits(&gb, 4); +- else bands[i].res[ch] = bands[i-1].res[ch] + t; ++ else bands[i].res[ch] = av_clip(bands[i-1].res[ch] + t, 0, 17); + } + + if(bands[i].res[0] || bands[i].res[1]){ +@@ -260,9 +281,7 @@ + for(ch = 0; ch < 2; ch++) + idx_to_quant(c, &gb, bands[i].res[ch], c->Q[ch] + off); + +- ff_mpc_dequantize_and_synth(c, mb, data, 2); +- +- av_free(bits); ++ ff_mpc_dequantize_and_synth(c, mb, c->frame.data[0], 2); + + bits_used = get_bits_count(&gb); + bits_avail = (buf_size - 4) * 8; +@@ -272,10 +291,12 @@ + } + if(c->frames_to_skip){ + c->frames_to_skip--; +- *data_size = 0; ++ *got_frame_ptr = 0; + return buf_size; + } +- *data_size = (buf[1] ? c->lastframelen : MPC_FRAME_SIZE) * 4; ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; + + return buf_size; + } +@@ -288,15 +309,23 @@ + c->frames_to_skip = 32; + } + ++static av_cold int mpc7_decode_close(AVCodecContext *avctx) ++{ ++ MPCContext *c = avctx->priv_data; ++ av_freep(&c->buffer); ++ c->buffer_size = 0; ++ return 0; ++} ++ + AVCodec ff_mpc7_decoder = { +- "mpc7", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MUSEPACK7, +- sizeof(MPCContext), +- mpc7_decode_init, +- NULL, +- NULL, +- mpc7_decode_frame, ++ .name = "mpc7", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MUSEPACK7, ++ .priv_data_size = sizeof(MPCContext), ++ .init = mpc7_decode_init, ++ .close = mpc7_decode_close, ++ .decode = mpc7_decode_frame, + .flush = mpc7_decode_flush, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Musepack SV7"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc8.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc8.c 2012-05-14 14:08:53.992333098 +0200 +@@ -29,10 +29,10 @@ + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" +-#include "mpegaudio.h" ++#include "mpegaudiodsp.h" ++#include "libavutil/audioconvert.h" + + #include "mpc.h" +-#include "mpcdata.h" + #include "mpc8data.h" + #include "mpc8huff.h" + +@@ -119,6 +119,7 @@ + memset(c->oldDSCF, 0, sizeof(c->oldDSCF)); + av_lfg_init(&c->rnd, 0xDEADBEEF); + dsputil_init(&c->dsp, avctx); ++ ff_mpadsp_init(&c->mpadsp); + + ff_mpc_init(); + +@@ -126,6 +127,8 @@ + + skip_bits(&gb, 3);//sample rate + c->maxbands = get_bits(&gb, 5) + 1; ++ if (c->maxbands >= BANDS) ++ return AVERROR_INVALIDDATA; + channels = get_bits(&gb, 4) + 1; + if (channels > 2) { + av_log_missing_feature(avctx, "Multichannel MPC SV8", 1); +@@ -135,7 +138,7 @@ + c->frames = 1 << (get_bits(&gb, 3) * 2); + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + + if(vlc_initialized) return 0; + av_log(avctx, AV_LOG_DEBUG, "Initing VLC\n"); +@@ -227,12 +230,15 @@ + &mpc8_q8_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + } + vlc_initialized = 1; ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ + return 0; + } + +-static int mpc8_decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int mpc8_decode_frame(AVCodecContext * avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +@@ -244,6 +250,13 @@ + int maxband, keyframe; + int last[2]; + ++ /* get output buffer */ ++ c->frame.nb_samples = MPC_FRAME_SIZE; ++ if ((res = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return res; ++ } ++ + keyframe = c->cur_frame == 0; + + if(keyframe){ +@@ -259,6 +272,8 @@ + maxband = c->last_max_band + get_vlc2(gb, band_vlc.table, MPC8_BANDS_BITS, 2); + if(maxband > 32) maxband -= 33; + } ++ if(maxband > c->maxbands) ++ return AVERROR_INVALIDDATA; + c->last_max_band = maxband; + + /* read subband indexes */ +@@ -392,26 +407,27 @@ + } + } + +- ff_mpc_dequantize_and_synth(c, maxband, data, avctx->channels); ++ ff_mpc_dequantize_and_synth(c, maxband, c->frame.data[0], avctx->channels); + + c->cur_frame++; + + c->last_bits_used = get_bits_count(gb); + if(c->cur_frame >= c->frames) + c->cur_frame = 0; +- *data_size = MPC_FRAME_SIZE * 2 * avctx->channels; ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; + + return c->cur_frame ? c->last_bits_used >> 3 : buf_size; + } + + AVCodec ff_mpc8_decoder = { +- "mpc8", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MUSEPACK8, +- sizeof(MPCContext), +- mpc8_decode_init, +- NULL, +- NULL, +- mpc8_decode_frame, ++ .name = "mpc8", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MUSEPACK8, ++ .priv_data_size = sizeof(MPCContext), ++ .init = mpc8_decode_init, ++ .decode = mpc8_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Musepack SV8"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc.c 2012-05-14 14:08:53.989333038 +0200 +@@ -29,6 +29,7 @@ + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" ++#include "mpegaudiodsp.h" + #include "mpegaudio.h" + + #include "mpc.h" +@@ -36,7 +37,7 @@ + + void ff_mpc_init(void) + { +- ff_mpa_synth_init(ff_mpa_synth_window); ++ ff_mpa_synth_init_fixed(ff_mpa_synth_window_fixed); + } + + /** +@@ -51,8 +52,9 @@ + for(ch = 0; ch < channels; ch++){ + samples_ptr = samples + ch; + for(i = 0; i < SAMPLES_PER_BAND; i++) { +- ff_mpa_synth_filter(c->synth_buf[ch], &(c->synth_buf_offset[ch]), +- ff_mpa_synth_window, &dither_state, ++ ff_mpa_synth_filter_fixed(&c->mpadsp, ++ c->synth_buf[ch], &(c->synth_buf_offset[ch]), ++ ff_mpa_synth_window_fixed, &dither_state, + samples_ptr, channels, + c->sb_samples[ch][i]); + samples_ptr += 32 * channels; +@@ -76,13 +78,13 @@ + for(ch = 0; ch < 2; ch++){ + if(bands[i].res[ch]){ + j = 0; +- mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][0]]; ++ mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][0]+6]; + for(; j < 12; j++) + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; +- mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][1]]; ++ mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][1]+6]; + for(; j < 24; j++) + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; +- mul = mpc_CC[bands[i].res[ch]] * mpc_SCF[bands[i].scf_idx[ch][2]]; ++ mul = mpc_CC[bands[i].res[ch] + 1] * mpc_SCF[bands[i].scf_idx[ch][2]+6]; + for(; j < 36; j++) + c->sb_samples[ch][j][i] = mul * c->Q[ch][j + off]; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpcdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpcdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpcdata.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpcdata.h 2012-05-14 14:08:53.992333098 +0200 +@@ -22,15 +22,17 @@ + #ifndef AVCODEC_MPCDATA_H + #define AVCODEC_MPCDATA_H + +-#include +- +-static const float mpc_CC[18] = { +- 65536.0000, 21845.3333, 13107.2000, 9362.2857, 7281.7778, 4369.0667, 2114.0645, ++static const float mpc_CC[18+1] = { ++ 111.285962475327f, // 32768/2/255*sqrt(3) ++ 65536.0000 /* this value is never used */, ++ 21845.3333, 13107.2000, 9362.2857, 7281.7778, 4369.0667, 2114.0645, + 1040.2539, 516.0315, 257.0039, 128.2505, 64.0626, 32.0156, 16.0039, 8.0010, + 4.0002, 2.0001, 1.0000 + }; + +-static const float mpc_SCF[128] = { ++static const float mpc_SCF[128+6] = { ++ 920.016296386718750000, 766.355773925781250000, 638.359558105468750000, ++ 531.741149902343750000, 442.930114746093750000, 368.952209472656250000, + 307.330047607421875000, 255.999984741210937500, 213.243041992187500000, 177.627334594726562500, + 147.960128784179687500, 123.247924804687500000, 102.663139343261718750, 85.516410827636718750, + 71.233520507812500000, 59.336143493652343750, 49.425861358642578125, 41.170787811279296875, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpc.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpc.h 2012-05-14 14:08:53.990333058 +0200 +@@ -34,8 +34,7 @@ + #include "get_bits.h" + #include "dsputil.h" + #include "mpegaudio.h" +- +-#include "mpcdata.h" ++#include "mpegaudiodsp.h" + + #define BANDS 32 + #define SAMPLES_PER_BAND 36 +@@ -51,7 +50,9 @@ + }Band; + + typedef struct { ++ AVFrame frame; + DSPContext dsp; ++ MPADSPContext mpadsp; + GetBitContext gb; + int IS, MSS, gapless; + int lastframelen; +@@ -65,6 +66,8 @@ + int buf_size; + AVLFG rnd; + int frames_to_skip; ++ uint8_t *buffer; ++ int buffer_size; + /* for synthesis */ + DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512*2]; + int synth_buf_offset[MPA_MAX_CHANNELS]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12.c 2012-05-14 14:08:54.004333340 +0200 +@@ -1,6 +1,6 @@ + /* + * MPEG-1/2 decoder +- * Copyright (c) 2000,2001 Fabrice Bellard ++ * Copyright (c) 2000, 2001 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * + * This file is part of FFmpeg. +@@ -25,11 +25,14 @@ + * MPEG-1/2 decoder + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + //#define DEBUG + #include "internal.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" ++#include "libavutil/avassert.h" + + #include "mpeg12.h" + #include "mpeg12data.h" +@@ -37,6 +40,7 @@ + #include "bytestream.h" + #include "vdpau_internal.h" + #include "xvmc_internal.h" ++#include "thread.h" + + //#undef NDEBUG + //#include +@@ -48,343 +52,867 @@ + #define MB_PTYPE_VLC_BITS 6 + #define MB_BTYPE_VLC_BITS 6 + +-static inline int mpeg1_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n); +-static inline int mpeg1_decode_block_inter(MpegEncContext *s, +- DCTELEM *block, +- int n); +-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n); +-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, +- DCTELEM *block, +- int n); +-static inline int mpeg2_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n); +-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n); +-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n); +-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); +-static void exchange_uv(MpegEncContext *s); +- +-static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = { +- PIX_FMT_XVMC_MPEG2_IDCT, +- PIX_FMT_XVMC_MPEG2_MC, +- PIX_FMT_NONE}; +- +-uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; +- +- +-#define INIT_2D_VLC_RL(rl, static_size)\ +-{\ +- static RL_VLC_ELEM rl_vlc_table[static_size];\ +- INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\ +- &rl.table_vlc[0][1], 4, 2,\ +- &rl.table_vlc[0][0], 4, 2, static_size);\ +-\ +- rl.rl_vlc[0]= rl_vlc_table;\ +- init_2d_vlc_rl(&rl);\ +-} ++static VLC mv_vlc; + +-static void init_2d_vlc_rl(RLTable *rl) ++/* as H.263, but only 17 codes */ ++static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) + { +- int i; ++ int code, sign, val, shift; + +- for(i=0; ivlc.table_size; i++){ +- int code= rl->vlc.table[i][0]; +- int len = rl->vlc.table[i][1]; +- int level, run; ++ code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); ++ if (code == 0) { ++ return pred; ++ } ++ if (code < 0) { ++ return 0xffff; ++ } + +- if(len==0){ // illegal code +- run= 65; +- level= MAX_LEVEL; +- }else if(len<0){ //more bits needed +- run= 0; +- level= code; +- }else{ +- if(code==rl->n){ //esc +- run= 65; +- level= 0; +- }else if(code==rl->n+1){ //eob +- run= 0; +- level= 127; +- }else{ +- run= rl->table_run [code] + 1; +- level= rl->table_level[code]; +- } +- } +- rl->rl_vlc[0][i].len= len; +- rl->rl_vlc[0][i].level= level; +- rl->rl_vlc[0][i].run= run; ++ sign = get_bits1(&s->gb); ++ shift = fcode - 1; ++ val = code; ++ if (shift) { ++ val = (val - 1) << shift; ++ val |= get_bits(&s->gb, shift); ++ val++; + } ++ if (sign) ++ val = -val; ++ val += pred; ++ ++ /* modulo decoding */ ++ return sign_extend(val, 5 + shift); + } + +-void ff_mpeg12_common_init(MpegEncContext *s) ++static inline int mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) + { ++ int level, dc, diff, i, j, run; ++ int component; ++ RLTable *rl = &ff_rl_mpeg1; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const uint16_t *quant_matrix = s->intra_matrix; ++ const int qscale = s->qscale; + +- s->y_dc_scale_table= +- s->c_dc_scale_table= ff_mpeg2_dc_scale_table[s->intra_dc_precision]; ++ /* DC coefficient */ ++ component = (n <= 3 ? 0 : n - 4 + 1); ++ diff = decode_dc(&s->gb, component); ++ if (diff >= 0xffff) ++ return -1; ++ dc = s->last_dc[component]; ++ dc += diff; ++ s->last_dc[component] = dc; ++ block[0] = dc * quant_matrix[0]; ++ av_dlog(s->avctx, "dc=%d diff=%d\n", dc, diff); ++ i = 0; ++ { ++ OPEN_READER(re, &s->gb); ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ UPDATE_CACHE(re, &s->gb); ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + +-} ++ if (level == 127) { ++ break; ++ } else if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ level = (level - 1) | 1; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ LAST_SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); ++ if (level == -128) { ++ level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); ++ } else if (level == 0) { ++ level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); ++ } ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = -level; ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ level = (level - 1) | 1; ++ level = -level; ++ } else { ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ level = (level - 1) | 1; ++ } ++ } ++ if (i > 63) { ++ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } + +-void ff_mpeg1_clean_buffers(MpegEncContext *s){ +- s->last_dc[0] = 1 << (7 + s->intra_dc_precision); +- s->last_dc[1] = s->last_dc[0]; +- s->last_dc[2] = s->last_dc[0]; +- memset(s->last_mv, 0, sizeof(s->last_mv)); ++ block[j] = level; ++ } ++ CLOSE_READER(re, &s->gb); ++ } ++ s->block_last_index[n] = i; ++ return 0; + } + +- +-/******************************************/ +-/* decoding */ +- +-VLC ff_dc_lum_vlc; +-VLC ff_dc_chroma_vlc; +- +-static VLC mv_vlc; +-static VLC mbincr_vlc; +-static VLC mb_ptype_vlc; +-static VLC mb_btype_vlc; +-static VLC mb_pat_vlc; +- +-av_cold void ff_mpeg12_init_vlcs(void) ++int ff_mpeg1_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) + { +- static int done = 0; ++ return mpeg1_decode_block_intra(s, block, n); ++} + +- if (!done) { +- done = 1; ++static inline int mpeg1_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) ++{ ++ int level, i, j, run; ++ RLTable *rl = &ff_rl_mpeg1; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const uint16_t *quant_matrix = s->inter_matrix; ++ const int qscale = s->qscale; + +- INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12, +- ff_mpeg12_vlc_dc_lum_bits, 1, 1, +- ff_mpeg12_vlc_dc_lum_code, 2, 2, 512); +- INIT_VLC_STATIC(&ff_dc_chroma_vlc, DC_VLC_BITS, 12, +- ff_mpeg12_vlc_dc_chroma_bits, 1, 1, +- ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514); +- INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17, +- &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1, +- &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518); +- INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36, +- &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1, +- &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538); +- INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64, +- &ff_mpeg12_mbPatTable[0][1], 2, 1, +- &ff_mpeg12_mbPatTable[0][0], 2, 1, 512); ++ { ++ OPEN_READER(re, &s->gb); ++ i = -1; ++ // special case for first coefficient, no need to add second VLC table ++ UPDATE_CACHE(re, &s->gb); ++ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { ++ level = (3 * qscale * quant_matrix[0]) >> 5; ++ level = (level - 1) | 1; ++ if (GET_CACHE(re, &s->gb) & 0x40000000) ++ level = -level; ++ block[0] = level; ++ i++; ++ SKIP_BITS(re, &s->gb, 2); ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ goto end; ++ } ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + +- INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7, +- &table_mb_ptype[0][1], 2, 1, +- &table_mb_ptype[0][0], 2, 1, 64); +- INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11, +- &table_mb_btype[0][1], 2, 1, +- &table_mb_btype[0][0], 2, 1, 64); +- init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); +- init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); ++ if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ level = (level - 1) | 1; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); ++ if (level == -128) { ++ level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); ++ } else if (level == 0) { ++ level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); ++ } ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = -level; ++ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ level = (level - 1) | 1; ++ level = -level; ++ } else { ++ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ level = (level - 1) | 1; ++ } ++ } ++ if (i > 63) { ++ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } + +- INIT_2D_VLC_RL(ff_rl_mpeg1, 680); +- INIT_2D_VLC_RL(ff_rl_mpeg2, 674); ++ block[j] = level; ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ break; ++ UPDATE_CACHE(re, &s->gb); ++ } ++end: ++ LAST_SKIP_BITS(re, &s->gb, 2); ++ CLOSE_READER(re, &s->gb); + } ++ s->block_last_index[n] = i; ++ return 0; + } + +-static inline int get_dmv(MpegEncContext *s) ++static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) + { +- if(get_bits1(&s->gb)) +- return 1 - (get_bits1(&s->gb) << 1); +- else +- return 0; +-} ++ int level, i, j, run; ++ RLTable *rl = &ff_rl_mpeg1; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const int qscale = s->qscale; + +-static inline int get_qscale(MpegEncContext *s) +-{ +- int qscale = get_bits(&s->gb, 5); +- if (s->q_scale_type) { +- return non_linear_qscale[qscale]; +- } else { +- return qscale << 1; ++ { ++ OPEN_READER(re, &s->gb); ++ i = -1; ++ // special case for first coefficient, no need to add second VLC table ++ UPDATE_CACHE(re, &s->gb); ++ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { ++ level = (3 * qscale) >> 1; ++ level = (level - 1) | 1; ++ if (GET_CACHE(re, &s->gb) & 0x40000000) ++ level = -level; ++ block[0] = level; ++ i++; ++ SKIP_BITS(re, &s->gb, 2); ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ goto end; ++ } ++ ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); ++ ++ if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = ((level * 2 + 1) * qscale) >> 1; ++ level = (level - 1) | 1; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); ++ if (level == -128) { ++ level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); ++ } else if (level == 0) { ++ level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); ++ } ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = -level; ++ level = ((level * 2 + 1) * qscale) >> 1; ++ level = (level - 1) | 1; ++ level = -level; ++ } else { ++ level = ((level * 2 + 1) * qscale) >> 1; ++ level = (level - 1) | 1; ++ } ++ } ++ ++ block[j] = level; ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ break; ++ UPDATE_CACHE(re, &s->gb); ++ } ++end: ++ LAST_SKIP_BITS(re, &s->gb, 2); ++ CLOSE_READER(re, &s->gb); + } ++ s->block_last_index[n] = i; ++ return 0; + } + +-/* motion type (for MPEG-2) */ +-#define MT_FIELD 1 +-#define MT_FRAME 2 +-#define MT_16X8 2 +-#define MT_DMV 3 + +-static int mpeg_decode_mb(MpegEncContext *s, +- DCTELEM block[12][64]) ++static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, DCTELEM *block, int n) + { +- int i, j, k, cbp, val, mb_type, motion_type; +- const int mb_block_count = 4 + (1<< s->chroma_format); ++ int level, i, j, run; ++ RLTable *rl = &ff_rl_mpeg1; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const uint16_t *quant_matrix; ++ const int qscale = s->qscale; ++ int mismatch; + +- av_dlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); ++ mismatch = 1; + +- assert(s->mb_skipped==0); ++ { ++ OPEN_READER(re, &s->gb); ++ i = -1; ++ if (n < 4) ++ quant_matrix = s->inter_matrix; ++ else ++ quant_matrix = s->chroma_inter_matrix; + +- if (s->mb_skip_run-- != 0) { +- if (s->pict_type == FF_P_TYPE) { +- s->mb_skipped = 1; +- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; +- } else { +- int mb_type; ++ // special case for first coefficient, no need to add second VLC table ++ UPDATE_CACHE(re, &s->gb); ++ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { ++ level= (3 * qscale * quant_matrix[0]) >> 5; ++ if (GET_CACHE(re, &s->gb) & 0x40000000) ++ level = -level; ++ block[0] = level; ++ mismatch ^= level; ++ i++; ++ SKIP_BITS(re, &s->gb, 2); ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ goto end; ++ } + +- if(s->mb_x) +- mb_type= s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]; +- else +- mb_type= s->current_picture.mb_type[ s->mb_width + (s->mb_y-1)*s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all +- if(IS_INTRA(mb_type)) +- return -1; ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + +- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= +- mb_type | MB_TYPE_SKIP; +-// assert(s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride - 1]&(MB_TYPE_16x16|MB_TYPE_16x8)); +- +- if((s->mv[0][0][0]|s->mv[0][0][1]|s->mv[1][0][0]|s->mv[1][0][1])==0) +- s->mb_skipped = 1; +- } +- +- return 0; +- } ++ if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); + +- switch(s->pict_type) { +- default: +- case FF_I_TYPE: +- if (get_bits1(&s->gb) == 0) { +- if (get_bits1(&s->gb) == 0){ +- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = ((-level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ level = -level; ++ } else { ++ level = ((level * 2 + 1) * qscale * quant_matrix[j]) >> 5; ++ } ++ } ++ if (i > 63) { ++ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } +- mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; +- } else { +- mb_type = MB_TYPE_INTRA; +- } +- break; +- case FF_P_TYPE: +- mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); +- if (mb_type < 0){ +- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- mb_type = ptype2mb_type[ mb_type ]; +- break; +- case FF_B_TYPE: +- mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); +- if (mb_type < 0){ +- av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); +- return -1; ++ ++ mismatch ^= level; ++ block[j] = level; ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ break; ++ UPDATE_CACHE(re, &s->gb); + } +- mb_type = btype2mb_type[ mb_type ]; +- break; ++end: ++ LAST_SKIP_BITS(re, &s->gb, 2); ++ CLOSE_READER(re, &s->gb); + } +- av_dlog(s->avctx, "mb_type=%x\n", mb_type); +-// motion_type = 0; /* avoid warning */ +- if (IS_INTRA(mb_type)) { +- s->dsp.clear_blocks(s->block[0]); ++ block[63] ^= (mismatch & 1); + +- if(!s->chroma_y_shift){ +- s->dsp.clear_blocks(s->block[6]); +- } ++ s->block_last_index[n] = i; ++ return 0; ++} + +- /* compute DCT type */ +- if (s->picture_structure == PICT_FRAME && //FIXME add an interlaced_dct coded var? +- !s->frame_pred_frame_dct) { +- s->interlaced_dct = get_bits1(&s->gb); +- } ++static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, ++ DCTELEM *block, int n) ++{ ++ int level, i, j, run; ++ RLTable *rl = &ff_rl_mpeg1; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const int qscale = s->qscale; ++ OPEN_READER(re, &s->gb); ++ i = -1; + +- if (IS_QUANT(mb_type)) +- s->qscale = get_qscale(s); ++ // special case for first coefficient, no need to add second VLC table ++ UPDATE_CACHE(re, &s->gb); ++ if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { ++ level = (3 * qscale) >> 1; ++ if (GET_CACHE(re, &s->gb) & 0x40000000) ++ level = -level; ++ block[0] = level; ++ i++; ++ SKIP_BITS(re, &s->gb, 2); ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ goto end; ++ } + +- if (s->concealment_motion_vectors) { +- /* just parse them */ +- if (s->picture_structure != PICT_FRAME) +- skip_bits1(&s->gb); /* field select */ ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); + +- s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] = +- mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]); +- s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] = +- mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]); ++ if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = ((level * 2 + 1) * qscale) >> 1; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); + +- skip_bits1(&s->gb); /* marker */ +- }else +- memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ +- s->mb_intra = 1; +- //if 1, we memcpy blocks in xvmcvideo +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){ +- ff_xvmc_pack_pblocks(s,-1);//inter are always full blocks +- if(s->swap_uv){ +- exchange_uv(s); ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = ((-level * 2 + 1) * qscale) >> 1; ++ level = -level; ++ } else { ++ level = ((level * 2 + 1) * qscale) >> 1; + } + } + +- if (s->codec_id == CODEC_ID_MPEG2VIDEO) { +- if(s->flags2 & CODEC_FLAG2_FAST){ +- for(i=0;i<6;i++) { +- mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i); +- } +- }else{ +- for(i=0;ipblocks[i], i) < 0) +- return -1; ++ block[j] = level; ++ if (((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) ++ break; ++ UPDATE_CACHE(re, &s->gb); ++ } ++end: ++ LAST_SKIP_BITS(re, &s->gb, 2); ++ CLOSE_READER(re, &s->gb); ++ s->block_last_index[n] = i; ++ return 0; ++} ++ ++ ++static inline int mpeg2_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) ++{ ++ int level, dc, diff, i, j, run; ++ int component; ++ RLTable *rl; ++ uint8_t * const scantable = s->intra_scantable.permutated; ++ const uint16_t *quant_matrix; ++ const int qscale = s->qscale; ++ int mismatch; ++ ++ /* DC coefficient */ ++ if (n < 4) { ++ quant_matrix = s->intra_matrix; ++ component = 0; ++ } else { ++ quant_matrix = s->chroma_intra_matrix; ++ component = (n & 1) + 1; ++ } ++ diff = decode_dc(&s->gb, component); ++ if (diff >= 0xffff) ++ return -1; ++ dc = s->last_dc[component]; ++ dc += diff; ++ s->last_dc[component] = dc; ++ block[0] = dc << (3 - s->intra_dc_precision); ++ av_dlog(s->avctx, "dc=%d\n", block[0]); ++ mismatch = block[0] ^ 1; ++ i = 0; ++ if (s->intra_vlc_format) ++ rl = &ff_rl_mpeg2; ++ else ++ rl = &ff_rl_mpeg1; ++ ++ { ++ OPEN_READER(re, &s->gb); ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ UPDATE_CACHE(re, &s->gb); ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); ++ ++ if (level == 127) { ++ break; ++ } else if (level != 0) { ++ i += run; ++ j = scantable[i]; ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ LAST_SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); ++ i += run; ++ j = scantable[i]; ++ if (level < 0) { ++ level = (-level * qscale * quant_matrix[j]) >> 4; ++ level = -level; ++ } else { ++ level = (level * qscale * quant_matrix[j]) >> 4; + } + } +- } else { +- for(i=0;i<6;i++) { +- if (mpeg1_decode_block_intra(s, *s->pblocks[i], i) < 0) +- return -1; ++ if (i > 63) { ++ av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); ++ return -1; + } ++ ++ mismatch ^= level; ++ block[j] = level; + } ++ CLOSE_READER(re, &s->gb); ++ } ++ block[63] ^= mismatch & 1; ++ ++ s->block_last_index[n] = i; ++ return 0; ++} ++ ++static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, DCTELEM *block, int n) ++{ ++ int level, dc, diff, j, run; ++ int component; ++ RLTable *rl; ++ uint8_t * scantable = s->intra_scantable.permutated; ++ const uint16_t *quant_matrix; ++ const int qscale = s->qscale; ++ ++ /* DC coefficient */ ++ if (n < 4) { ++ quant_matrix = s->intra_matrix; ++ component = 0; + } else { +- if (mb_type & MB_TYPE_ZERO_MV){ +- assert(mb_type & MB_TYPE_CBP); ++ quant_matrix = s->chroma_intra_matrix; ++ component = (n & 1) + 1; ++ } ++ diff = decode_dc(&s->gb, component); ++ if (diff >= 0xffff) ++ return -1; ++ dc = s->last_dc[component]; ++ dc += diff; ++ s->last_dc[component] = dc; ++ block[0] = dc << (3 - s->intra_dc_precision); ++ if (s->intra_vlc_format) ++ rl = &ff_rl_mpeg2; ++ else ++ rl = &ff_rl_mpeg1; + +- s->mv_dir = MV_DIR_FORWARD; +- if(s->picture_structure == PICT_FRAME){ +- if(!s->frame_pred_frame_dct) +- s->interlaced_dct = get_bits1(&s->gb); +- s->mv_type = MV_TYPE_16X16; +- }else{ +- s->mv_type = MV_TYPE_FIELD; +- mb_type |= MB_TYPE_INTERLACED; +- s->field_select[0][0]= s->picture_structure - 1; ++ { ++ OPEN_READER(re, &s->gb); ++ /* now quantify & encode AC coefficients */ ++ for (;;) { ++ UPDATE_CACHE(re, &s->gb); ++ GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); ++ ++ if (level == 127) { ++ break; ++ } else if (level != 0) { ++ scantable += run; ++ j = *scantable; ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); ++ LAST_SKIP_BITS(re, &s->gb, 1); ++ } else { ++ /* escape */ ++ run = SHOW_UBITS(re, &s->gb, 6) + 1; LAST_SKIP_BITS(re, &s->gb, 6); ++ UPDATE_CACHE(re, &s->gb); ++ level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); ++ scantable += run; ++ j = *scantable; ++ if (level < 0) { ++ level = (-level * qscale * quant_matrix[j]) >> 4; ++ level = -level; ++ } else { ++ level = (level * qscale * quant_matrix[j]) >> 4; ++ } + } + +- if (IS_QUANT(mb_type)) +- s->qscale = get_qscale(s); ++ block[j] = level; ++ } ++ CLOSE_READER(re, &s->gb); ++ } + +- s->last_mv[0][0][0] = 0; +- s->last_mv[0][0][1] = 0; +- s->last_mv[0][1][0] = 0; +- s->last_mv[0][1][1] = 0; +- s->mv[0][0][0] = 0; +- s->mv[0][0][1] = 0; +- }else{ +- assert(mb_type & MB_TYPE_L0L1); +-//FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED +- /* get additional motion vector type */ +- if (s->frame_pred_frame_dct) +- motion_type = MT_FRAME; +- else{ +- motion_type = get_bits(&s->gb, 2); +- if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type)) +- s->interlaced_dct = get_bits1(&s->gb); +- } ++ s->block_last_index[n] = scantable - s->intra_scantable.permutated; ++ return 0; ++} + +- if (IS_QUANT(mb_type)) +- s->qscale = get_qscale(s); ++uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; + +- /* motion vectors */ +- s->mv_dir= (mb_type>>13)&3; +- av_dlog(s->avctx, "motion_type=%d\n", motion_type); +- switch(motion_type) { +- case MT_FRAME: /* or MT_16X8 */ +- if (s->picture_structure == PICT_FRAME) { +- mb_type |= MB_TYPE_16x16; +- s->mv_type = MV_TYPE_16X16; +- for(i=0;i<2;i++) { +- if (USES_LIST(mb_type, i)) { +- /* MT_FRAME */ +- s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] = +- mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); +- s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] = +- mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]); ++#define INIT_2D_VLC_RL(rl, static_size)\ ++{\ ++ static RL_VLC_ELEM rl_vlc_table[static_size];\ ++ INIT_VLC_STATIC(&rl.vlc, TEX_VLC_BITS, rl.n + 2,\ ++ &rl.table_vlc[0][1], 4, 2,\ ++ &rl.table_vlc[0][0], 4, 2, static_size);\ ++\ ++ rl.rl_vlc[0] = rl_vlc_table;\ ++ init_2d_vlc_rl(&rl);\ ++} ++ ++static void init_2d_vlc_rl(RLTable *rl) ++{ ++ int i; ++ ++ for (i = 0; i < rl->vlc.table_size; i++) { ++ int code = rl->vlc.table[i][0]; ++ int len = rl->vlc.table[i][1]; ++ int level, run; ++ ++ if (len == 0) { // illegal code ++ run = 65; ++ level = MAX_LEVEL; ++ } else if (len<0) { //more bits needed ++ run = 0; ++ level = code; ++ } else { ++ if (code == rl->n) { //esc ++ run = 65; ++ level = 0; ++ } else if (code == rl->n+1) { //eob ++ run = 0; ++ level = 127; ++ } else { ++ run = rl->table_run [code] + 1; ++ level = rl->table_level[code]; ++ } ++ } ++ rl->rl_vlc[0][i].len = len; ++ rl->rl_vlc[0][i].level = level; ++ rl->rl_vlc[0][i].run = run; ++ } ++} ++ ++void ff_mpeg12_common_init(MpegEncContext *s) ++{ ++ ++ s->y_dc_scale_table = ++ s->c_dc_scale_table = ff_mpeg2_dc_scale_table[s->intra_dc_precision]; ++ ++} ++ ++void ff_mpeg1_clean_buffers(MpegEncContext *s) ++{ ++ s->last_dc[0] = 1 << (7 + s->intra_dc_precision); ++ s->last_dc[1] = s->last_dc[0]; ++ s->last_dc[2] = s->last_dc[0]; ++ memset(s->last_mv, 0, sizeof(s->last_mv)); ++} ++ ++ ++/******************************************/ ++/* decoding */ ++ ++VLC ff_dc_lum_vlc; ++VLC ff_dc_chroma_vlc; ++ ++static VLC mbincr_vlc; ++static VLC mb_ptype_vlc; ++static VLC mb_btype_vlc; ++static VLC mb_pat_vlc; ++ ++av_cold void ff_mpeg12_init_vlcs(void) ++{ ++ static int done = 0; ++ ++ if (!done) { ++ done = 1; ++ ++ INIT_VLC_STATIC(&ff_dc_lum_vlc, DC_VLC_BITS, 12, ++ ff_mpeg12_vlc_dc_lum_bits, 1, 1, ++ ff_mpeg12_vlc_dc_lum_code, 2, 2, 512); ++ INIT_VLC_STATIC(&ff_dc_chroma_vlc, DC_VLC_BITS, 12, ++ ff_mpeg12_vlc_dc_chroma_bits, 1, 1, ++ ff_mpeg12_vlc_dc_chroma_code, 2, 2, 514); ++ INIT_VLC_STATIC(&mv_vlc, MV_VLC_BITS, 17, ++ &ff_mpeg12_mbMotionVectorTable[0][1], 2, 1, ++ &ff_mpeg12_mbMotionVectorTable[0][0], 2, 1, 518); ++ INIT_VLC_STATIC(&mbincr_vlc, MBINCR_VLC_BITS, 36, ++ &ff_mpeg12_mbAddrIncrTable[0][1], 2, 1, ++ &ff_mpeg12_mbAddrIncrTable[0][0], 2, 1, 538); ++ INIT_VLC_STATIC(&mb_pat_vlc, MB_PAT_VLC_BITS, 64, ++ &ff_mpeg12_mbPatTable[0][1], 2, 1, ++ &ff_mpeg12_mbPatTable[0][0], 2, 1, 512); ++ ++ INIT_VLC_STATIC(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 7, ++ &table_mb_ptype[0][1], 2, 1, ++ &table_mb_ptype[0][0], 2, 1, 64); ++ INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11, ++ &table_mb_btype[0][1], 2, 1, ++ &table_mb_btype[0][0], 2, 1, 64); ++ init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]); ++ init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]); ++ ++ INIT_2D_VLC_RL(ff_rl_mpeg1, 680); ++ INIT_2D_VLC_RL(ff_rl_mpeg2, 674); ++ } ++} ++ ++static inline int get_dmv(MpegEncContext *s) ++{ ++ if (get_bits1(&s->gb)) ++ return 1 - (get_bits1(&s->gb) << 1); ++ else ++ return 0; ++} ++ ++static inline int get_qscale(MpegEncContext *s) ++{ ++ int qscale = get_bits(&s->gb, 5); ++ if (s->q_scale_type) { ++ return non_linear_qscale[qscale]; ++ } else { ++ return qscale << 1; ++ } ++} ++ ++static void exchange_uv(MpegEncContext *s) ++{ ++ DCTELEM (*tmp)[64]; ++ ++ tmp = s->pblocks[4]; ++ s->pblocks[4] = s->pblocks[5]; ++ s->pblocks[5] = tmp; ++} ++ ++/* motion type (for MPEG-2) */ ++#define MT_FIELD 1 ++#define MT_FRAME 2 ++#define MT_16X8 2 ++#define MT_DMV 3 ++ ++static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64]) ++{ ++ int i, j, k, cbp, val, mb_type, motion_type; ++ const int mb_block_count = 4 + (1 << s->chroma_format); ++ ++ av_dlog(s->avctx, "decode_mb: x=%d y=%d\n", s->mb_x, s->mb_y); ++ ++ assert(s->mb_skipped == 0); ++ ++ if (s->mb_skip_run-- != 0) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { ++ s->mb_skipped = 1; ++ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = MB_TYPE_SKIP | MB_TYPE_L0 | MB_TYPE_16x16; ++ } else { ++ int mb_type; ++ ++ if (s->mb_x) ++ mb_type = s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1]; ++ else ++ mb_type = s->current_picture.f.mb_type[s->mb_width + (s->mb_y - 1) * s->mb_stride - 1]; // FIXME not sure if this is allowed in MPEG at all ++ if (IS_INTRA(mb_type)) ++ return -1; ++ s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride] = ++ mb_type | MB_TYPE_SKIP; ++// assert(s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride - 1] & (MB_TYPE_16x16 | MB_TYPE_16x8)); ++ ++ if ((s->mv[0][0][0] | s->mv[0][0][1] | s->mv[1][0][0] | s->mv[1][0][1]) == 0) ++ s->mb_skipped = 1; ++ } ++ ++ return 0; ++ } ++ ++ switch (s->pict_type) { ++ default: ++ case AV_PICTURE_TYPE_I: ++ if (get_bits1(&s->gb) == 0) { ++ if (get_bits1(&s->gb) == 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in I Frame at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } ++ mb_type = MB_TYPE_QUANT | MB_TYPE_INTRA; ++ } else { ++ mb_type = MB_TYPE_INTRA; ++ } ++ break; ++ case AV_PICTURE_TYPE_P: ++ mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); ++ if (mb_type < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in P Frame at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } ++ mb_type = ptype2mb_type[mb_type]; ++ break; ++ case AV_PICTURE_TYPE_B: ++ mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); ++ if (mb_type < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid mb type in B Frame at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } ++ mb_type = btype2mb_type[mb_type]; ++ break; ++ } ++ av_dlog(s->avctx, "mb_type=%x\n", mb_type); ++// motion_type = 0; /* avoid warning */ ++ if (IS_INTRA(mb_type)) { ++ s->dsp.clear_blocks(s->block[0]); ++ ++ if (!s->chroma_y_shift) { ++ s->dsp.clear_blocks(s->block[6]); ++ } ++ ++ /* compute DCT type */ ++ if (s->picture_structure == PICT_FRAME && // FIXME add an interlaced_dct coded var? ++ !s->frame_pred_frame_dct) { ++ s->interlaced_dct = get_bits1(&s->gb); ++ } ++ ++ if (IS_QUANT(mb_type)) ++ s->qscale = get_qscale(s); ++ ++ if (s->concealment_motion_vectors) { ++ /* just parse them */ ++ if (s->picture_structure != PICT_FRAME) ++ skip_bits1(&s->gb); /* field select */ ++ ++ s->mv[0][0][0]= s->last_mv[0][0][0]= s->last_mv[0][1][0] = ++ mpeg_decode_motion(s, s->mpeg_f_code[0][0], s->last_mv[0][0][0]); ++ s->mv[0][0][1]= s->last_mv[0][0][1]= s->last_mv[0][1][1] = ++ mpeg_decode_motion(s, s->mpeg_f_code[0][1], s->last_mv[0][0][1]); ++ ++ skip_bits1(&s->gb); /* marker */ ++ } else ++ memset(s->last_mv, 0, sizeof(s->last_mv)); /* reset mv prediction */ ++ s->mb_intra = 1; ++ // if 1, we memcpy blocks in xvmcvideo ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) { ++ ff_xvmc_pack_pblocks(s, -1); // inter are always full blocks ++ if (s->swap_uv) { ++ exchange_uv(s); ++ } ++ } ++ ++ if (s->codec_id == CODEC_ID_MPEG2VIDEO) { ++ if (s->flags2 & CODEC_FLAG2_FAST) { ++ for (i = 0; i < 6; i++) { ++ mpeg2_fast_decode_block_intra(s, *s->pblocks[i], i); ++ } ++ } else { ++ for (i = 0; i < mb_block_count; i++) { ++ if (mpeg2_decode_block_intra(s, *s->pblocks[i], i) < 0) ++ return -1; ++ } ++ } ++ } else { ++ for (i = 0; i < 6; i++) { ++ if (mpeg1_decode_block_intra(s, *s->pblocks[i], i) < 0) ++ return -1; ++ } ++ } ++ } else { ++ if (mb_type & MB_TYPE_ZERO_MV) { ++ assert(mb_type & MB_TYPE_CBP); ++ ++ s->mv_dir = MV_DIR_FORWARD; ++ if (s->picture_structure == PICT_FRAME) { ++ if (!s->frame_pred_frame_dct) ++ s->interlaced_dct = get_bits1(&s->gb); ++ s->mv_type = MV_TYPE_16X16; ++ } else { ++ s->mv_type = MV_TYPE_FIELD; ++ mb_type |= MB_TYPE_INTERLACED; ++ s->field_select[0][0] = s->picture_structure - 1; ++ } ++ ++ if (IS_QUANT(mb_type)) ++ s->qscale = get_qscale(s); ++ ++ s->last_mv[0][0][0] = 0; ++ s->last_mv[0][0][1] = 0; ++ s->last_mv[0][1][0] = 0; ++ s->last_mv[0][1][1] = 0; ++ s->mv[0][0][0] = 0; ++ s->mv[0][0][1] = 0; ++ } else { ++ assert(mb_type & MB_TYPE_L0L1); ++ // FIXME decide if MBs in field pictures are MB_TYPE_INTERLACED ++ /* get additional motion vector type */ ++ if (s->frame_pred_frame_dct) ++ motion_type = MT_FRAME; ++ else { ++ motion_type = get_bits(&s->gb, 2); ++ if (s->picture_structure == PICT_FRAME && HAS_CBP(mb_type)) ++ s->interlaced_dct = get_bits1(&s->gb); ++ } ++ ++ if (IS_QUANT(mb_type)) ++ s->qscale = get_qscale(s); ++ ++ /* motion vectors */ ++ s->mv_dir = (mb_type >> 13) & 3; ++ av_dlog(s->avctx, "motion_type=%d\n", motion_type); ++ switch (motion_type) { ++ case MT_FRAME: /* or MT_16X8 */ ++ if (s->picture_structure == PICT_FRAME) { ++ mb_type |= MB_TYPE_16x16; ++ s->mv_type = MV_TYPE_16X16; ++ for (i = 0; i < 2; i++) { ++ if (USES_LIST(mb_type, i)) { ++ /* MT_FRAME */ ++ s->mv[i][0][0]= s->last_mv[i][0][0]= s->last_mv[i][1][0] = ++ mpeg_decode_motion(s, s->mpeg_f_code[i][0], s->last_mv[i][0][0]); ++ s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] = ++ mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]); + /* full_pel: only for MPEG-1 */ +- if (s->full_pel[i]){ ++ if (s->full_pel[i]) { + s->mv[i][0][0] <<= 1; + s->mv[i][0][1] <<= 1; + } +@@ -393,16 +921,16 @@ + } else { + mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; + s->mv_type = MV_TYPE_16X8; +- for(i=0;i<2;i++) { ++ for (i = 0; i < 2; i++) { + if (USES_LIST(mb_type, i)) { + /* MT_16X8 */ +- for(j=0;j<2;j++) { ++ for (j = 0; j < 2; j++) { + s->field_select[i][j] = get_bits1(&s->gb); +- for(k=0;k<2;k++) { ++ for (k = 0; k < 2; k++) { + val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], + s->last_mv[i][j][k]); + s->last_mv[i][j][k] = val; +- s->mv[i][j][k] = val; ++ s->mv[i][j][k] = val; + } + } + } +@@ -413,741 +941,179 @@ + s->mv_type = MV_TYPE_FIELD; + if (s->picture_structure == PICT_FRAME) { + mb_type |= MB_TYPE_16x8 | MB_TYPE_INTERLACED; +- for(i=0;i<2;i++) { ++ for (i = 0; i < 2; i++) { + if (USES_LIST(mb_type, i)) { +- for(j=0;j<2;j++) { ++ for (j = 0; j < 2; j++) { + s->field_select[i][j] = get_bits1(&s->gb); + val = mpeg_decode_motion(s, s->mpeg_f_code[i][0], + s->last_mv[i][j][0]); + s->last_mv[i][j][0] = val; +- s->mv[i][j][0] = val; ++ s->mv[i][j][0] = val; + av_dlog(s->avctx, "fmx=%d\n", val); + val = mpeg_decode_motion(s, s->mpeg_f_code[i][1], + s->last_mv[i][j][1] >> 1); + s->last_mv[i][j][1] = val << 1; +- s->mv[i][j][1] = val; ++ s->mv[i][j][1] = val; + av_dlog(s->avctx, "fmy=%d\n", val); + } + } + } + } else { ++ av_assert0(!s->progressive_sequence); + mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; +- for(i=0;i<2;i++) { ++ for (i = 0; i < 2; i++) { + if (USES_LIST(mb_type, i)) { + s->field_select[i][0] = get_bits1(&s->gb); +- for(k=0;k<2;k++) { ++ for (k = 0; k < 2; k++) { + val = mpeg_decode_motion(s, s->mpeg_f_code[i][k], + s->last_mv[i][0][k]); + s->last_mv[i][0][k] = val; + s->last_mv[i][1][k] = val; +- s->mv[i][0][k] = val; ++ s->mv[i][0][k] = val; + } + } + } + } + break; + case MT_DMV: ++ if(s->progressive_sequence){ ++ av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n"); ++ return -1; ++ } + s->mv_type = MV_TYPE_DMV; +- for(i=0;i<2;i++) { +- if (USES_LIST(mb_type, i)) { +- int dmx, dmy, mx, my, m; +- const int my_shift= s->picture_structure == PICT_FRAME; +- +- mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], +- s->last_mv[i][0][0]); +- s->last_mv[i][0][0] = mx; +- s->last_mv[i][1][0] = mx; +- dmx = get_dmv(s); +- my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], +- s->last_mv[i][0][1] >> my_shift); +- dmy = get_dmv(s); +- +- +- s->last_mv[i][0][1] = my<last_mv[i][1][1] = my<mv[i][0][0] = mx; +- s->mv[i][0][1] = my; +- s->mv[i][1][0] = mx;//not used +- s->mv[i][1][1] = my;//not used +- +- if (s->picture_structure == PICT_FRAME) { +- mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; +- +- //m = 1 + 2 * s->top_field_first; +- m = s->top_field_first ? 1 : 3; +- +- /* top -> top pred */ +- s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; +- s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; +- m = 4 - m; +- s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; +- s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; +- } else { +- mb_type |= MB_TYPE_16x16; +- +- s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; +- s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; +- if(s->picture_structure == PICT_TOP_FIELD) +- s->mv[i][2][1]--; +- else +- s->mv[i][2][1]++; +- } +- } +- } +- break; +- default: +- av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- } +- +- s->mb_intra = 0; +- if (HAS_CBP(mb_type)) { +- s->dsp.clear_blocks(s->block[0]); +- +- cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); +- if(mb_block_count > 6){ +- cbp<<= mb_block_count-6; +- cbp |= get_bits(&s->gb, mb_block_count-6); +- s->dsp.clear_blocks(s->block[6]); +- } +- if (cbp <= 0){ +- av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- +- //if 1, we memcpy blocks in xvmcvideo +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1){ +- ff_xvmc_pack_pblocks(s,cbp); +- if(s->swap_uv){ +- exchange_uv(s); +- } +- } +- +- if (s->codec_id == CODEC_ID_MPEG2VIDEO) { +- if(s->flags2 & CODEC_FLAG2_FAST){ +- for(i=0;i<6;i++) { +- if(cbp & 32) { +- mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i); +- } else { +- s->block_last_index[i] = -1; +- } +- cbp+=cbp; +- } +- }else{ +- cbp<<= 12-mb_block_count; +- +- for(i=0;ipblocks[i], i) < 0) +- return -1; +- } else { +- s->block_last_index[i] = -1; +- } +- cbp+=cbp; +- } +- } +- } else { +- if(s->flags2 & CODEC_FLAG2_FAST){ +- for(i=0;i<6;i++) { +- if (cbp & 32) { +- mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i); +- } else { +- s->block_last_index[i] = -1; +- } +- cbp+=cbp; +- } +- }else{ +- for(i=0;i<6;i++) { +- if (cbp & 32) { +- if (mpeg1_decode_block_inter(s, *s->pblocks[i], i) < 0) +- return -1; +- } else { +- s->block_last_index[i] = -1; +- } +- cbp+=cbp; +- } +- } +- } +- }else{ +- for(i=0;i<12;i++) +- s->block_last_index[i] = -1; +- } +- } +- +- s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]= mb_type; +- +- return 0; +-} +- +-/* as H.263, but only 17 codes */ +-static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) +-{ +- int code, sign, val, l, shift; +- +- code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); +- if (code == 0) { +- return pred; +- } +- if (code < 0) { +- return 0xffff; +- } +- +- sign = get_bits1(&s->gb); +- shift = fcode - 1; +- val = code; +- if (shift) { +- val = (val - 1) << shift; +- val |= get_bits(&s->gb, shift); +- val++; +- } +- if (sign) +- val = -val; +- val += pred; +- +- /* modulo decoding */ +- l= INT_BIT - 5 - shift; +- val = (val<>l; +- return val; +-} +- +-static inline int mpeg1_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, dc, diff, i, j, run; +- int component; +- RLTable *rl = &ff_rl_mpeg1; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const uint16_t *quant_matrix= s->intra_matrix; +- const int qscale= s->qscale; +- +- /* DC coefficient */ +- component = (n <= 3 ? 0 : n - 4 + 1); +- diff = decode_dc(&s->gb, component); +- if (diff >= 0xffff) +- return -1; +- dc = s->last_dc[component]; +- dc += diff; +- s->last_dc[component] = dc; +- block[0] = dc*quant_matrix[0]; +- av_dlog(s->avctx, "dc=%d diff=%d\n", dc, diff); +- i = 0; +- { +- OPEN_READER(re, &s->gb); +- /* now quantify & encode AC coefficients */ +- for(;;) { +- UPDATE_CACHE(re, &s->gb); +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); +- +- if(level == 127){ +- break; +- } else if(level != 0) { +- i += run; +- j = scantable[i]; +- level= (level*qscale*quant_matrix[j])>>4; +- level= (level-1)|1; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- LAST_SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); +- if (level == -128) { +- level = SHOW_UBITS(re, &s->gb, 8) - 256; LAST_SKIP_BITS(re, &s->gb, 8); +- } else if (level == 0) { +- level = SHOW_UBITS(re, &s->gb, 8) ; LAST_SKIP_BITS(re, &s->gb, 8); +- } +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= -level; +- level= (level*qscale*quant_matrix[j])>>4; +- level= (level-1)|1; +- level= -level; +- }else{ +- level= (level*qscale*quant_matrix[j])>>4; +- level= (level-1)|1; +- } +- } +- if (i > 63){ +- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- +- block[j] = level; +- } +- CLOSE_READER(re, &s->gb); +- } +- s->block_last_index[n] = i; +- return 0; +-} +- +-int ff_mpeg1_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- return mpeg1_decode_block_intra(s, block, n); +-} +- +-static inline int mpeg1_decode_block_inter(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, i, j, run; +- RLTable *rl = &ff_rl_mpeg1; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const uint16_t *quant_matrix= s->inter_matrix; +- const int qscale= s->qscale; +- +- { +- OPEN_READER(re, &s->gb); +- i = -1; +- // special case for first coefficient, no need to add second VLC table +- UPDATE_CACHE(re, &s->gb); +- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { +- level= (3*qscale*quant_matrix[0])>>5; +- level= (level-1)|1; +- if(GET_CACHE(re, &s->gb)&0x40000000) +- level= -level; +- block[0] = level; +- i++; +- SKIP_BITS(re, &s->gb, 2); +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- goto end; +- } +- /* now quantify & encode AC coefficients */ +- for(;;) { +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); +- +- if(level != 0) { +- i += run; +- j = scantable[i]; +- level= ((level*2+1)*qscale*quant_matrix[j])>>5; +- level= (level-1)|1; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); +- if (level == -128) { +- level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); +- } else if (level == 0) { +- level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); +- } +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= -level; +- level= ((level*2+1)*qscale*quant_matrix[j])>>5; +- level= (level-1)|1; +- level= -level; +- }else{ +- level= ((level*2+1)*qscale*quant_matrix[j])>>5; +- level= (level-1)|1; +- } +- } +- if (i > 63){ +- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- +- block[j] = level; +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- break; +- UPDATE_CACHE(re, &s->gb); +- } +-end: +- LAST_SKIP_BITS(re, &s->gb, 2); +- CLOSE_READER(re, &s->gb); +- } +- s->block_last_index[n] = i; +- return 0; +-} +- +-static inline int mpeg1_fast_decode_block_inter(MpegEncContext *s, DCTELEM *block, int n) +-{ +- int level, i, j, run; +- RLTable *rl = &ff_rl_mpeg1; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const int qscale= s->qscale; +- +- { +- OPEN_READER(re, &s->gb); +- i = -1; +- // special case for first coefficient, no need to add second VLC table +- UPDATE_CACHE(re, &s->gb); +- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { +- level= (3*qscale)>>1; +- level= (level-1)|1; +- if(GET_CACHE(re, &s->gb)&0x40000000) +- level= -level; +- block[0] = level; +- i++; +- SKIP_BITS(re, &s->gb, 2); +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- goto end; +- } +- +- /* now quantify & encode AC coefficients */ +- for(;;) { +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); +- +- if(level != 0) { +- i += run; +- j = scantable[i]; +- level= ((level*2+1)*qscale)>>1; +- level= (level-1)|1; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 8); SKIP_BITS(re, &s->gb, 8); +- if (level == -128) { +- level = SHOW_UBITS(re, &s->gb, 8) - 256; SKIP_BITS(re, &s->gb, 8); +- } else if (level == 0) { +- level = SHOW_UBITS(re, &s->gb, 8) ; SKIP_BITS(re, &s->gb, 8); +- } +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= -level; +- level= ((level*2+1)*qscale)>>1; +- level= (level-1)|1; +- level= -level; +- }else{ +- level= ((level*2+1)*qscale)>>1; +- level= (level-1)|1; +- } +- } +- +- block[j] = level; +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- break; +- UPDATE_CACHE(re, &s->gb); +- } +-end: +- LAST_SKIP_BITS(re, &s->gb, 2); +- CLOSE_READER(re, &s->gb); +- } +- s->block_last_index[n] = i; +- return 0; +-} +- +- +-static inline int mpeg2_decode_block_non_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, i, j, run; +- RLTable *rl = &ff_rl_mpeg1; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const uint16_t *quant_matrix; +- const int qscale= s->qscale; +- int mismatch; +- +- mismatch = 1; +- +- { +- OPEN_READER(re, &s->gb); +- i = -1; +- if (n < 4) +- quant_matrix = s->inter_matrix; +- else +- quant_matrix = s->chroma_inter_matrix; +- +- // special case for first coefficient, no need to add second VLC table +- UPDATE_CACHE(re, &s->gb); +- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { +- level= (3*qscale*quant_matrix[0])>>5; +- if(GET_CACHE(re, &s->gb)&0x40000000) +- level= -level; +- block[0] = level; +- mismatch ^= level; +- i++; +- SKIP_BITS(re, &s->gb, 2); +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- goto end; +- } +- +- /* now quantify & encode AC coefficients */ +- for(;;) { +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); +- +- if(level != 0) { +- i += run; +- j = scantable[i]; +- level= ((level*2+1)*qscale*quant_matrix[j])>>5; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); +- +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= ((-level*2+1)*qscale*quant_matrix[j])>>5; +- level= -level; +- }else{ +- level= ((level*2+1)*qscale*quant_matrix[j])>>5; +- } +- } +- if (i > 63){ +- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); +- return -1; +- } +- +- mismatch ^= level; +- block[j] = level; +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- break; +- UPDATE_CACHE(re, &s->gb); +- } +-end: +- LAST_SKIP_BITS(re, &s->gb, 2); +- CLOSE_READER(re, &s->gb); +- } +- block[63] ^= (mismatch & 1); +- +- s->block_last_index[n] = i; +- return 0; +-} +- +-static inline int mpeg2_fast_decode_block_non_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, i, j, run; +- RLTable *rl = &ff_rl_mpeg1; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const int qscale= s->qscale; +- OPEN_READER(re, &s->gb); +- i = -1; +- +- // special case for first coefficient, no need to add second VLC table +- UPDATE_CACHE(re, &s->gb); +- if (((int32_t)GET_CACHE(re, &s->gb)) < 0) { +- level= (3*qscale)>>1; +- if(GET_CACHE(re, &s->gb)&0x40000000) +- level= -level; +- block[0] = level; +- i++; +- SKIP_BITS(re, &s->gb, 2); +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- goto end; +- } +- +- /* now quantify & encode AC coefficients */ +- for(;;) { +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); +- +- if(level != 0) { +- i += run; +- j = scantable[i]; +- level= ((level*2+1)*qscale)>>1; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); +- +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= ((-level*2+1)*qscale)>>1; +- level= -level; +- }else{ +- level= ((level*2+1)*qscale)>>1; +- } +- } +- +- block[j] = level; +- if(((int32_t)GET_CACHE(re, &s->gb)) <= (int32_t)0xBFFFFFFF) +- break; +- UPDATE_CACHE(re, &s->gb); +- } +-end: +- LAST_SKIP_BITS(re, &s->gb, 2); +- CLOSE_READER(re, &s->gb); +- s->block_last_index[n] = i; +- return 0; +-} +- +- +-static inline int mpeg2_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, dc, diff, i, j, run; +- int component; +- RLTable *rl; +- uint8_t * const scantable= s->intra_scantable.permutated; +- const uint16_t *quant_matrix; +- const int qscale= s->qscale; +- int mismatch; +- +- /* DC coefficient */ +- if (n < 4){ +- quant_matrix = s->intra_matrix; +- component = 0; +- }else{ +- quant_matrix = s->chroma_intra_matrix; +- component = (n&1) + 1; +- } +- diff = decode_dc(&s->gb, component); +- if (diff >= 0xffff) +- return -1; +- dc = s->last_dc[component]; +- dc += diff; +- s->last_dc[component] = dc; +- block[0] = dc << (3 - s->intra_dc_precision); +- av_dlog(s->avctx, "dc=%d\n", block[0]); +- mismatch = block[0] ^ 1; +- i = 0; +- if (s->intra_vlc_format) +- rl = &ff_rl_mpeg2; +- else +- rl = &ff_rl_mpeg1; ++ for (i = 0; i < 2; i++) { ++ if (USES_LIST(mb_type, i)) { ++ int dmx, dmy, mx, my, m; ++ const int my_shift = s->picture_structure == PICT_FRAME; + +- { +- OPEN_READER(re, &s->gb); +- /* now quantify & encode AC coefficients */ +- for(;;) { +- UPDATE_CACHE(re, &s->gb); +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); ++ mx = mpeg_decode_motion(s, s->mpeg_f_code[i][0], ++ s->last_mv[i][0][0]); ++ s->last_mv[i][0][0] = mx; ++ s->last_mv[i][1][0] = mx; ++ dmx = get_dmv(s); ++ my = mpeg_decode_motion(s, s->mpeg_f_code[i][1], ++ s->last_mv[i][0][1] >> my_shift); ++ dmy = get_dmv(s); + +- if(level == 127){ +- break; +- } else if(level != 0) { +- i += run; +- j = scantable[i]; +- level= (level*qscale*quant_matrix[j])>>4; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- LAST_SKIP_BITS(re, &s->gb, 1); +- } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); +- i += run; +- j = scantable[i]; +- if(level<0){ +- level= (-level*qscale*quant_matrix[j])>>4; +- level= -level; +- }else{ +- level= (level*qscale*quant_matrix[j])>>4; ++ ++ s->last_mv[i][0][1] = my << my_shift; ++ s->last_mv[i][1][1] = my << my_shift; ++ ++ s->mv[i][0][0] = mx; ++ s->mv[i][0][1] = my; ++ s->mv[i][1][0] = mx; // not used ++ s->mv[i][1][1] = my; // not used ++ ++ if (s->picture_structure == PICT_FRAME) { ++ mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED; ++ ++ // m = 1 + 2 * s->top_field_first; ++ m = s->top_field_first ? 1 : 3; ++ ++ /* top -> top pred */ ++ s->mv[i][2][0] = ((mx * m + (mx > 0)) >> 1) + dmx; ++ s->mv[i][2][1] = ((my * m + (my > 0)) >> 1) + dmy - 1; ++ m = 4 - m; ++ s->mv[i][3][0] = ((mx * m + (mx > 0)) >> 1) + dmx; ++ s->mv[i][3][1] = ((my * m + (my > 0)) >> 1) + dmy + 1; ++ } else { ++ mb_type |= MB_TYPE_16x16; ++ ++ s->mv[i][2][0] = ((mx + (mx > 0)) >> 1) + dmx; ++ s->mv[i][2][1] = ((my + (my > 0)) >> 1) + dmy; ++ if (s->picture_structure == PICT_TOP_FIELD) ++ s->mv[i][2][1]--; ++ else ++ s->mv[i][2][1]++; ++ } ++ } + } +- } +- if (i > 63){ +- av_log(s->avctx, AV_LOG_ERROR, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); ++ break; ++ default: ++ av_log(s->avctx, AV_LOG_ERROR, "00 motion_type at %d %d\n", s->mb_x, s->mb_y); + return -1; + } +- +- mismatch^= level; +- block[j] = level; + } +- CLOSE_READER(re, &s->gb); +- } +- block[63]^= mismatch&1; + +- s->block_last_index[n] = i; +- return 0; +-} ++ s->mb_intra = 0; ++ if (HAS_CBP(mb_type)) { ++ s->dsp.clear_blocks(s->block[0]); + +-static inline int mpeg2_fast_decode_block_intra(MpegEncContext *s, +- DCTELEM *block, +- int n) +-{ +- int level, dc, diff, j, run; +- int component; +- RLTable *rl; +- uint8_t * scantable= s->intra_scantable.permutated; +- const uint16_t *quant_matrix; +- const int qscale= s->qscale; ++ cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); ++ if (mb_block_count > 6) { ++ cbp <<= mb_block_count - 6; ++ cbp |= get_bits(&s->gb, mb_block_count - 6); ++ s->dsp.clear_blocks(s->block[6]); ++ } ++ if (cbp <= 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid cbp at %d %d\n", s->mb_x, s->mb_y); ++ return -1; ++ } + +- /* DC coefficient */ +- if (n < 4){ +- quant_matrix = s->intra_matrix; +- component = 0; +- }else{ +- quant_matrix = s->chroma_intra_matrix; +- component = (n&1) + 1; +- } +- diff = decode_dc(&s->gb, component); +- if (diff >= 0xffff) +- return -1; +- dc = s->last_dc[component]; +- dc += diff; +- s->last_dc[component] = dc; +- block[0] = dc << (3 - s->intra_dc_precision); +- if (s->intra_vlc_format) +- rl = &ff_rl_mpeg2; +- else +- rl = &ff_rl_mpeg1; ++ //if 1, we memcpy blocks in xvmcvideo ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) { ++ ff_xvmc_pack_pblocks(s, cbp); ++ if (s->swap_uv) { ++ exchange_uv(s); ++ } ++ } + +- { +- OPEN_READER(re, &s->gb); +- /* now quantify & encode AC coefficients */ +- for(;;) { +- UPDATE_CACHE(re, &s->gb); +- GET_RL_VLC(level, run, re, &s->gb, rl->rl_vlc[0], TEX_VLC_BITS, 2, 0); ++ if (s->codec_id == CODEC_ID_MPEG2VIDEO) { ++ if (s->flags2 & CODEC_FLAG2_FAST) { ++ for (i = 0; i < 6; i++) { ++ if (cbp & 32) { ++ mpeg2_fast_decode_block_non_intra(s, *s->pblocks[i], i); ++ } else { ++ s->block_last_index[i] = -1; ++ } ++ cbp += cbp; ++ } ++ } else { ++ cbp <<= 12-mb_block_count; + +- if(level == 127){ +- break; +- } else if(level != 0) { +- scantable += run; +- j = *scantable; +- level= (level*qscale*quant_matrix[j])>>4; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); +- LAST_SKIP_BITS(re, &s->gb, 1); ++ for (i = 0; i < mb_block_count; i++) { ++ if (cbp & (1 << 11)) { ++ if (mpeg2_decode_block_non_intra(s, *s->pblocks[i], i) < 0) ++ return -1; ++ } else { ++ s->block_last_index[i] = -1; ++ } ++ cbp += cbp; ++ } ++ } + } else { +- /* escape */ +- run = SHOW_UBITS(re, &s->gb, 6)+1; LAST_SKIP_BITS(re, &s->gb, 6); +- UPDATE_CACHE(re, &s->gb); +- level = SHOW_SBITS(re, &s->gb, 12); SKIP_BITS(re, &s->gb, 12); +- scantable += run; +- j = *scantable; +- if(level<0){ +- level= (-level*qscale*quant_matrix[j])>>4; +- level= -level; +- }else{ +- level= (level*qscale*quant_matrix[j])>>4; ++ if (s->flags2 & CODEC_FLAG2_FAST) { ++ for (i = 0; i < 6; i++) { ++ if (cbp & 32) { ++ mpeg1_fast_decode_block_inter(s, *s->pblocks[i], i); ++ } else { ++ s->block_last_index[i] = -1; ++ } ++ cbp += cbp; ++ } ++ } else { ++ for (i = 0; i < 6; i++) { ++ if (cbp & 32) { ++ if (mpeg1_decode_block_inter(s, *s->pblocks[i], i) < 0) ++ return -1; ++ } else { ++ s->block_last_index[i] = -1; ++ } ++ cbp += cbp; ++ } + } + } +- +- block[j] = level; ++ } else { ++ for (i = 0; i < 12; i++) ++ s->block_last_index[i] = -1; + } +- CLOSE_READER(re, &s->gb); + } + +- s->block_last_index[n] = scantable - s->intra_scantable.permutated; ++ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = mb_type; ++ + return 0; + } + +-typedef struct Mpeg1Context { +- MpegEncContext mpeg_enc_ctx; +- int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ +- int repeat_field; /* true if we must repeat the field */ +- AVPanScan pan_scan; /**< some temporary storage for the panscan */ +- int slice_count; +- int swap_uv;//indicate VCR2 +- int save_aspect_info; +- int save_width, save_height, save_progressive_seq; +- AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator +- int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame? +-} Mpeg1Context; +- + static av_cold int mpeg_decode_init(AVCodecContext *avctx) + { + Mpeg1Context *s = avctx->priv_data; +@@ -1156,22 +1122,22 @@ + + /* we need some permutation to store matrices, + * until MPV_common_init() sets the real permutation. */ +- for(i=0;i<64;i++) ++ for (i = 0; i < 64; i++) + s2->dsp.idct_permutation[i]=i; + + MPV_decode_defaults(s2); + +- s->mpeg_enc_ctx.avctx= avctx; +- s->mpeg_enc_ctx.flags= avctx->flags; +- s->mpeg_enc_ctx.flags2= avctx->flags2; ++ s->mpeg_enc_ctx.avctx = avctx; ++ s->mpeg_enc_ctx.flags = avctx->flags; ++ s->mpeg_enc_ctx.flags2 = avctx->flags2; + ff_mpeg12_common_init(&s->mpeg_enc_ctx); + ff_mpeg12_init_vlcs(); + +- s->mpeg_enc_ctx_allocated = 0; ++ s->mpeg_enc_ctx_allocated = 0; + s->mpeg_enc_ctx.picture_number = 0; +- s->repeat_field = 0; +- s->mpeg_enc_ctx.codec_id= avctx->codec->id; +- avctx->color_range= AVCOL_RANGE_MPEG; ++ s->repeat_field = 0; ++ s->mpeg_enc_ctx.codec_id = avctx->codec->id; ++ avctx->color_range = AVCOL_RANGE_MPEG; + if (avctx->codec->id == CODEC_ID_MPEG1VIDEO) + avctx->chroma_sample_location = AVCHROMA_LOC_CENTER; + else +@@ -1179,139 +1145,203 @@ + return 0; + } + ++static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from) ++{ ++ Mpeg1Context *ctx = avctx->priv_data, *ctx_from = avctx_from->priv_data; ++ MpegEncContext *s = &ctx->mpeg_enc_ctx, *s1 = &ctx_from->mpeg_enc_ctx; ++ int err; ++ ++ if (avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !s1->context_initialized) ++ return 0; ++ ++ err = ff_mpeg_update_thread_context(avctx, avctx_from); ++ if (err) return err; ++ ++ if (!ctx->mpeg_enc_ctx_allocated) ++ memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext)); ++ ++ if (!(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay)) ++ s->picture_number++; ++ ++ return 0; ++} ++ + static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm, +- const uint8_t *new_perm){ ++ const uint8_t *new_perm) ++{ + uint16_t temp_matrix[64]; + int i; + +- memcpy(temp_matrix,matrix,64*sizeof(uint16_t)); ++ memcpy(temp_matrix, matrix, 64 * sizeof(uint16_t)); + +- for(i=0;i<64;i++){ ++ for (i = 0; i < 64; i++) { + matrix[new_perm[i]] = temp_matrix[old_perm[i]]; + } + } + +-static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx){ ++static const enum PixelFormat mpeg1_hwaccel_pixfmt_list_420[] = { ++#if CONFIG_MPEG_XVMC_DECODER ++ PIX_FMT_XVMC_MPEG2_IDCT, ++ PIX_FMT_XVMC_MPEG2_MC, ++#endif ++#if CONFIG_MPEG1_VDPAU_HWACCEL ++ PIX_FMT_VDPAU_MPEG1, ++#endif ++ PIX_FMT_YUV420P, ++ PIX_FMT_NONE ++}; ++ ++static const enum PixelFormat mpeg2_hwaccel_pixfmt_list_420[] = { ++#if CONFIG_MPEG_XVMC_DECODER ++ PIX_FMT_XVMC_MPEG2_IDCT, ++ PIX_FMT_XVMC_MPEG2_MC, ++#endif ++#if CONFIG_MPEG2_VDPAU_HWACCEL ++ PIX_FMT_VDPAU_MPEG2, ++#endif ++#if CONFIG_MPEG2_DXVA2_HWACCEL ++ PIX_FMT_DXVA2_VLD, ++#endif ++#if CONFIG_MPEG2_VAAPI_HWACCEL ++ PIX_FMT_VAAPI_VLD, ++#endif ++ PIX_FMT_YUV420P, ++ PIX_FMT_NONE ++}; ++ ++static inline int uses_vdpau(AVCodecContext *avctx) { ++ return avctx->pix_fmt == PIX_FMT_VDPAU_MPEG1 || avctx->pix_fmt == PIX_FMT_VDPAU_MPEG2; ++} ++ ++static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx) ++{ + Mpeg1Context *s1 = avctx->priv_data; + MpegEncContext *s = &s1->mpeg_enc_ctx; + +- if(avctx->xvmc_acceleration) +- return avctx->get_format(avctx,pixfmt_xvmc_mpg2_420); +- else if(avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){ +- if(avctx->codec_id == CODEC_ID_MPEG1VIDEO) +- return PIX_FMT_VDPAU_MPEG1; +- else +- return PIX_FMT_VDPAU_MPEG2; +- }else{ +- if(s->chroma_format < 2) +- return avctx->get_format(avctx,ff_hwaccel_pixfmt_list_420); +- else if(s->chroma_format == 2) +- return PIX_FMT_YUV422P; +- else +- return PIX_FMT_YUV444P; +- } ++ if(s->chroma_format < 2) { ++ enum PixelFormat res; ++ res = avctx->get_format(avctx, ++ avctx->codec_id == CODEC_ID_MPEG1VIDEO ? ++ mpeg1_hwaccel_pixfmt_list_420 : ++ mpeg2_hwaccel_pixfmt_list_420); ++ if (res != PIX_FMT_XVMC_MPEG2_IDCT && res != PIX_FMT_XVMC_MPEG2_MC) { ++ avctx->xvmc_acceleration = 0; ++ } else if (!avctx->xvmc_acceleration) { ++ avctx->xvmc_acceleration = 2; ++ } ++ return res; ++ } else if(s->chroma_format == 2) ++ return PIX_FMT_YUV422P; ++ else ++ return PIX_FMT_YUV444P; + } + + /* Call this function when we know all parameters. + * It may be called in different places for MPEG-1 and MPEG-2. */ +-static int mpeg_decode_postinit(AVCodecContext *avctx){ ++static int mpeg_decode_postinit(AVCodecContext *avctx) ++{ + Mpeg1Context *s1 = avctx->priv_data; + MpegEncContext *s = &s1->mpeg_enc_ctx; + uint8_t old_permutation[64]; + +- if ( +- (s1->mpeg_enc_ctx_allocated == 0)|| +- avctx->coded_width != s->width || +- avctx->coded_height != s->height|| +- s1->save_width != s->width || +- s1->save_height != s->height || +- s1->save_aspect_info != s->aspect_ratio_info|| ++ if ((s1->mpeg_enc_ctx_allocated == 0) || ++ avctx->coded_width != s->width || ++ avctx->coded_height != s->height || ++ s1->save_width != s->width || ++ s1->save_height != s->height || ++ s1->save_aspect_info != s->aspect_ratio_info || + s1->save_progressive_seq != s->progressive_sequence || + 0) + { + + if (s1->mpeg_enc_ctx_allocated) { +- ParseContext pc= s->parse_context; +- s->parse_context.buffer=0; ++ ParseContext pc = s->parse_context; ++ s->parse_context.buffer = 0; + MPV_common_end(s); +- s->parse_context= pc; ++ s->parse_context = pc; + } + +- if( (s->width == 0 )||(s->height == 0)) ++ if ((s->width == 0) || (s->height == 0)) + return -2; + + avcodec_set_dimensions(avctx, s->width, s->height); +- avctx->bit_rate = s->bit_rate; +- s1->save_aspect_info = s->aspect_ratio_info; +- s1->save_width = s->width; +- s1->save_height = s->height; ++ avctx->bit_rate = s->bit_rate; ++ s1->save_aspect_info = s->aspect_ratio_info; ++ s1->save_width = s->width; ++ s1->save_height = s->height; + s1->save_progressive_seq = s->progressive_sequence; + + /* low_delay may be forced, in this case we will have B-frames + * that behave like P-frames. */ +- avctx->has_b_frames = !(s->low_delay); ++ avctx->has_b_frames = !s->low_delay; + +- assert((avctx->sub_id==1) == (avctx->codec_id==CODEC_ID_MPEG1VIDEO)); +- if(avctx->codec_id==CODEC_ID_MPEG1VIDEO){ ++ assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO)); ++ if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) { + //MPEG-1 fps +- avctx->time_base.den= ff_frame_rate_tab[s->frame_rate_index].num; +- avctx->time_base.num= ff_frame_rate_tab[s->frame_rate_index].den; ++ avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num; ++ avctx->time_base.num = avpriv_frame_rate_tab[s->frame_rate_index].den; + //MPEG-1 aspect +- avctx->sample_aspect_ratio= av_d2q( +- 1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); ++ avctx->sample_aspect_ratio = av_d2q(1.0/ff_mpeg1_aspect[s->aspect_ratio_info], 255); + avctx->ticks_per_frame=1; +- }else{//MPEG-2 ++ } else {//MPEG-2 + //MPEG-2 fps +- av_reduce( +- &s->avctx->time_base.den, +- &s->avctx->time_base.num, +- ff_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2, +- ff_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, +- 1<<30); +- avctx->ticks_per_frame=2; +- //MPEG-2 aspect +- if(s->aspect_ratio_info > 1){ +- //we ignore the spec here as reality does not match the spec, see for example ++ av_reduce(&s->avctx->time_base.den, ++ &s->avctx->time_base.num, ++ avpriv_frame_rate_tab[s->frame_rate_index].num * s1->frame_rate_ext.num*2, ++ avpriv_frame_rate_tab[s->frame_rate_index].den * s1->frame_rate_ext.den, ++ 1 << 30); ++ avctx->ticks_per_frame = 2; ++ //MPEG-2 aspect ++ if (s->aspect_ratio_info > 1) { ++ AVRational dar = ++ av_mul_q(av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info], ++ (AVRational) {s1->pan_scan.width, s1->pan_scan.height}), ++ (AVRational) {s->width, s->height}); ++ ++ // we ignore the spec here and guess a bit as reality does not match the spec, see for example + // res_change_ffmpeg_aspect.ts and sequence-display-aspect.mpg +- if( (s1->pan_scan.width == 0 )||(s1->pan_scan.height == 0) || 1){ +- s->avctx->sample_aspect_ratio= +- av_div_q( +- ff_mpeg2_aspect[s->aspect_ratio_info], +- (AVRational){s->width, s->height} +- ); +- }else{ +- s->avctx->sample_aspect_ratio= +- av_div_q( +- ff_mpeg2_aspect[s->aspect_ratio_info], +- (AVRational){s1->pan_scan.width, s1->pan_scan.height} +- ); ++ // issue1613, 621, 562 ++ if ((s1->pan_scan.width == 0) || (s1->pan_scan.height == 0) || ++ (av_cmp_q(dar, (AVRational) {4, 3}) && av_cmp_q(dar, (AVRational) {16, 9}))) { ++ s->avctx->sample_aspect_ratio = ++ av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info], ++ (AVRational) {s->width, s->height}); ++ } else { ++ s->avctx->sample_aspect_ratio = ++ av_div_q(ff_mpeg2_aspect[s->aspect_ratio_info], ++ (AVRational) {s1->pan_scan.width, s1->pan_scan.height}); ++//issue1613 4/3 16/9 -> 16/9 ++//res_change_ffmpeg_aspect.ts 4/3 225/44 ->4/3 ++//widescreen-issue562.mpg 4/3 16/9 -> 16/9 ++// s->avctx->sample_aspect_ratio = av_mul_q(s->avctx->sample_aspect_ratio, (AVRational) {s->width, s->height}); ++//av_log(NULL, AV_LOG_ERROR, "A %d/%d\n", ff_mpeg2_aspect[s->aspect_ratio_info].num, ff_mpeg2_aspect[s->aspect_ratio_info].den); ++//av_log(NULL, AV_LOG_ERROR, "B %d/%d\n", s->avctx->sample_aspect_ratio.num, s->avctx->sample_aspect_ratio.den); + } +- }else{ +- s->avctx->sample_aspect_ratio= ++ } else { ++ s->avctx->sample_aspect_ratio = + ff_mpeg2_aspect[s->aspect_ratio_info]; + } +- }//MPEG-2 ++ } // MPEG-2 + + avctx->pix_fmt = mpeg_get_pixelformat(avctx); + avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); +- //until then pix_fmt may be changed right after codec init +- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || +- avctx->hwaccel || +- s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ) +- if( avctx->idct_algo == FF_IDCT_AUTO ) ++ // until then pix_fmt may be changed right after codec init ++ if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || ++ avctx->hwaccel ) ++ if (avctx->idct_algo == FF_IDCT_AUTO) + avctx->idct_algo = FF_IDCT_SIMPLE; + + /* Quantization matrices may need reordering + * if DCT permutation is changed. */ +- memcpy(old_permutation,s->dsp.idct_permutation,64*sizeof(uint8_t)); ++ memcpy(old_permutation, s->dsp.idct_permutation, 64 * sizeof(uint8_t)); + + if (MPV_common_init(s) < 0) + return -2; + +- quant_matrix_rebuild(s->intra_matrix, old_permutation,s->dsp.idct_permutation); +- quant_matrix_rebuild(s->inter_matrix, old_permutation,s->dsp.idct_permutation); +- quant_matrix_rebuild(s->chroma_intra_matrix,old_permutation,s->dsp.idct_permutation); +- quant_matrix_rebuild(s->chroma_inter_matrix,old_permutation,s->dsp.idct_permutation); ++ quant_matrix_rebuild(s->intra_matrix, old_permutation, s->dsp.idct_permutation); ++ quant_matrix_rebuild(s->inter_matrix, old_permutation, s->dsp.idct_permutation); ++ quant_matrix_rebuild(s->chroma_intra_matrix, old_permutation, s->dsp.idct_permutation); ++ quant_matrix_rebuild(s->chroma_inter_matrix, old_permutation, s->dsp.idct_permutation); + + s1->mpeg_enc_ctx_allocated = 1; + } +@@ -1329,30 +1359,30 @@ + + ref = get_bits(&s->gb, 10); /* temporal ref */ + s->pict_type = get_bits(&s->gb, 3); +- if(s->pict_type == 0 || s->pict_type > 3) ++ if (s->pict_type == 0 || s->pict_type > 3) + return -1; + +- vbv_delay= get_bits(&s->gb, 16); +- if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) { ++ vbv_delay = get_bits(&s->gb, 16); ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) { + s->full_pel[0] = get_bits1(&s->gb); + f_code = get_bits(&s->gb, 3); +- if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT) ++ if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) + return -1; + s->mpeg_f_code[0][0] = f_code; + s->mpeg_f_code[0][1] = f_code; + } +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + s->full_pel[1] = get_bits1(&s->gb); + f_code = get_bits(&s->gb, 3); +- if (f_code == 0 && avctx->error_recognition >= FF_ER_COMPLIANT) ++ if (f_code == 0 && (avctx->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT))) + return -1; + s->mpeg_f_code[1][0] = f_code; + s->mpeg_f_code[1][1] = f_code; + } +- s->current_picture.pict_type= s->pict_type; +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; + +- if(avctx->debug & FF_DEBUG_PICT_INFO) ++ if (avctx->debug & FF_DEBUG_PICT_INFO) + av_log(avctx, AV_LOG_DEBUG, "vbv_delay %d, ref %d type:%d\n", vbv_delay, ref, s->pict_type); + + s->y_dc_scale = 8; +@@ -1367,30 +1397,31 @@ + int bit_rate_ext; + + skip_bits(&s->gb, 1); /* profile and level esc*/ +- s->avctx->profile= get_bits(&s->gb, 3); +- s->avctx->level= get_bits(&s->gb, 4); ++ s->avctx->profile = get_bits(&s->gb, 3); ++ s->avctx->level = get_bits(&s->gb, 4); + s->progressive_sequence = get_bits1(&s->gb); /* progressive_sequence */ +- s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */ +- horiz_size_ext = get_bits(&s->gb, 2); +- vert_size_ext = get_bits(&s->gb, 2); +- s->width |= (horiz_size_ext << 12); +- s->height |= (vert_size_ext << 12); ++ s->chroma_format = get_bits(&s->gb, 2); /* chroma_format 1=420, 2=422, 3=444 */ ++ horiz_size_ext = get_bits(&s->gb, 2); ++ vert_size_ext = get_bits(&s->gb, 2); ++ s->width |= (horiz_size_ext << 12); ++ s->height |= (vert_size_ext << 12); + bit_rate_ext = get_bits(&s->gb, 12); /* XXX: handle it */ + s->bit_rate += (bit_rate_ext << 18) * 400; + skip_bits1(&s->gb); /* marker */ +- s->avctx->rc_buffer_size += get_bits(&s->gb, 8)*1024*16<<10; ++ s->avctx->rc_buffer_size += get_bits(&s->gb, 8) * 1024 * 16 << 10; + + s->low_delay = get_bits1(&s->gb); +- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; ++ if (s->flags & CODEC_FLAG_LOW_DELAY) ++ s->low_delay = 1; + +- s1->frame_rate_ext.num = get_bits(&s->gb, 2)+1; +- s1->frame_rate_ext.den = get_bits(&s->gb, 5)+1; ++ s1->frame_rate_ext.num = get_bits(&s->gb, 2) + 1; ++ s1->frame_rate_ext.den = get_bits(&s->gb, 5) + 1; + + av_dlog(s->avctx, "sequence extension\n"); +- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; ++ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO; + s->avctx->sub_id = 2; /* indicates MPEG-2 found */ + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n", + s->avctx->profile, s->avctx->level, s->avctx->rc_buffer_size, s->bit_rate); + +@@ -1398,78 +1429,78 @@ + + static void mpeg_decode_sequence_display_extension(Mpeg1Context *s1) + { +- MpegEncContext *s= &s1->mpeg_enc_ctx; ++ MpegEncContext *s = &s1->mpeg_enc_ctx; + int color_description, w, h; + + skip_bits(&s->gb, 3); /* video format */ +- color_description= get_bits1(&s->gb); +- if(color_description){ +- s->avctx->color_primaries= get_bits(&s->gb, 8); +- s->avctx->color_trc = get_bits(&s->gb, 8); +- s->avctx->colorspace = get_bits(&s->gb, 8); ++ color_description = get_bits1(&s->gb); ++ if (color_description) { ++ s->avctx->color_primaries = get_bits(&s->gb, 8); ++ s->avctx->color_trc = get_bits(&s->gb, 8); ++ s->avctx->colorspace = get_bits(&s->gb, 8); + } +- w= get_bits(&s->gb, 14); ++ w = get_bits(&s->gb, 14); + skip_bits(&s->gb, 1); //marker +- h= get_bits(&s->gb, 14); ++ h = get_bits(&s->gb, 14); + // remaining 3 bits are zero padding + +- s1->pan_scan.width= 16*w; +- s1->pan_scan.height=16*h; ++ s1->pan_scan.width = 16 * w; ++ s1->pan_scan.height = 16 * h; + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "sde w:%d, h:%d\n", w, h); + } + + static void mpeg_decode_picture_display_extension(Mpeg1Context *s1) + { +- MpegEncContext *s= &s1->mpeg_enc_ctx; +- int i,nofco; ++ MpegEncContext *s = &s1->mpeg_enc_ctx; ++ int i, nofco; + + nofco = 1; +- if(s->progressive_sequence){ +- if(s->repeat_first_field){ ++ if (s->progressive_sequence) { ++ if (s->repeat_first_field) { + nofco++; +- if(s->top_field_first) ++ if (s->top_field_first) + nofco++; + } +- }else{ +- if(s->picture_structure == PICT_FRAME){ ++ } else { ++ if (s->picture_structure == PICT_FRAME) { + nofco++; +- if(s->repeat_first_field) ++ if (s->repeat_first_field) + nofco++; + } + } +- for(i=0; ipan_scan.position[i][0]= get_sbits(&s->gb, 16); +- skip_bits(&s->gb, 1); //marker +- s1->pan_scan.position[i][1]= get_sbits(&s->gb, 16); +- skip_bits(&s->gb, 1); //marker ++ for (i = 0; i < nofco; i++) { ++ s1->pan_scan.position[i][0] = get_sbits(&s->gb, 16); ++ skip_bits(&s->gb, 1); // marker ++ s1->pan_scan.position[i][1] = get_sbits(&s->gb, 16); ++ skip_bits(&s->gb, 1); // marker + } + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "pde (%d,%d) (%d,%d) (%d,%d)\n", +- s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], +- s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], +- s1->pan_scan.position[2][0], s1->pan_scan.position[2][1] +- ); ++ s1->pan_scan.position[0][0], s1->pan_scan.position[0][1], ++ s1->pan_scan.position[1][0], s1->pan_scan.position[1][1], ++ s1->pan_scan.position[2][0], s1->pan_scan.position[2][1]); + } + +-static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra){ ++static int load_matrix(MpegEncContext *s, uint16_t matrix0[64], uint16_t matrix1[64], int intra) ++{ + int i; + +- for(i=0; i<64; i++) { +- int j = s->dsp.idct_permutation[ ff_zigzag_direct[i] ]; ++ for (i = 0; i < 64; i++) { ++ int j = s->dsp.idct_permutation[ff_zigzag_direct[i]]; + int v = get_bits(&s->gb, 8); +- if(v==0){ ++ if (v == 0) { + av_log(s->avctx, AV_LOG_ERROR, "matrix damaged\n"); + return -1; + } +- if(intra && i==0 && v!=8){ ++ if (intra && i == 0 && v != 8) { + av_log(s->avctx, AV_LOG_ERROR, "intra matrix invalid, ignoring\n"); +- v= 8; // needed by pink.mpg / issue1046 ++ v = 8; // needed by pink.mpg / issue1046 + } + matrix0[j] = v; +- if(matrix1) ++ if (matrix1) + matrix1[j] = v; + } + return 0; +@@ -1479,75 +1510,74 @@ + { + av_dlog(s->avctx, "matrix extension\n"); + +- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1); +- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0); +- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1); +- if(get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0); ++ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1); ++ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0); ++ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_intra_matrix, NULL , 1); ++ if (get_bits1(&s->gb)) load_matrix(s, s->chroma_inter_matrix, NULL , 0); + } + + static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1) + { +- MpegEncContext *s= &s1->mpeg_enc_ctx; ++ MpegEncContext *s = &s1->mpeg_enc_ctx; + + s->full_pel[0] = s->full_pel[1] = 0; + s->mpeg_f_code[0][0] = get_bits(&s->gb, 4); + s->mpeg_f_code[0][1] = get_bits(&s->gb, 4); + s->mpeg_f_code[1][0] = get_bits(&s->gb, 4); + s->mpeg_f_code[1][1] = get_bits(&s->gb, 4); +- if(!s->pict_type && s1->mpeg_enc_ctx_allocated){ ++ if (!s->pict_type && s1->mpeg_enc_ctx_allocated) { + av_log(s->avctx, AV_LOG_ERROR, "Missing picture start code, guessing missing values\n"); +- if(s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1]==15){ +- if(s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15) +- s->pict_type= FF_I_TYPE; ++ if (s->mpeg_f_code[1][0] == 15 && s->mpeg_f_code[1][1] == 15) { ++ if (s->mpeg_f_code[0][0] == 15 && s->mpeg_f_code[0][1] == 15) ++ s->pict_type = AV_PICTURE_TYPE_I; + else +- s->pict_type= FF_P_TYPE; +- }else +- s->pict_type= FF_B_TYPE; +- s->current_picture.pict_type= s->pict_type; +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; +- } +- s->intra_dc_precision = get_bits(&s->gb, 2); +- s->picture_structure = get_bits(&s->gb, 2); +- s->top_field_first = get_bits1(&s->gb); +- s->frame_pred_frame_dct = get_bits1(&s->gb); ++ s->pict_type = AV_PICTURE_TYPE_P; ++ } else ++ s->pict_type = AV_PICTURE_TYPE_B; ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; ++ } ++ s->intra_dc_precision = get_bits(&s->gb, 2); ++ s->picture_structure = get_bits(&s->gb, 2); ++ s->top_field_first = get_bits1(&s->gb); ++ s->frame_pred_frame_dct = get_bits1(&s->gb); + s->concealment_motion_vectors = get_bits1(&s->gb); +- s->q_scale_type = get_bits1(&s->gb); +- s->intra_vlc_format = get_bits1(&s->gb); +- s->alternate_scan = get_bits1(&s->gb); +- s->repeat_first_field = get_bits1(&s->gb); +- s->chroma_420_type = get_bits1(&s->gb); +- s->progressive_frame = get_bits1(&s->gb); ++ s->q_scale_type = get_bits1(&s->gb); ++ s->intra_vlc_format = get_bits1(&s->gb); ++ s->alternate_scan = get_bits1(&s->gb); ++ s->repeat_first_field = get_bits1(&s->gb); ++ s->chroma_420_type = get_bits1(&s->gb); ++ s->progressive_frame = get_bits1(&s->gb); + +- if(s->progressive_sequence && !s->progressive_frame){ +- s->progressive_frame= 1; ++ if (s->progressive_sequence && !s->progressive_frame) { ++ s->progressive_frame = 1; + av_log(s->avctx, AV_LOG_ERROR, "interlaced frame in progressive sequence, ignoring\n"); + } + +- if(s->picture_structure==0 || (s->progressive_frame && s->picture_structure!=PICT_FRAME)){ ++ if (s->picture_structure == 0 || (s->progressive_frame && s->picture_structure != PICT_FRAME)) { + av_log(s->avctx, AV_LOG_ERROR, "picture_structure %d invalid, ignoring\n", s->picture_structure); +- s->picture_structure= PICT_FRAME; ++ s->picture_structure = PICT_FRAME; + } + +- if(s->progressive_sequence && !s->frame_pred_frame_dct){ ++ if (s->progressive_sequence && !s->frame_pred_frame_dct) { + av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n"); +- s->frame_pred_frame_dct= 1; + } + +- if(s->picture_structure == PICT_FRAME){ +- s->first_field=0; +- s->v_edge_pos= 16*s->mb_height; +- }else{ ++ if (s->picture_structure == PICT_FRAME) { ++ s->first_field = 0; ++ s->v_edge_pos = 16 * s->mb_height; ++ } else { + s->first_field ^= 1; +- s->v_edge_pos= 8*s->mb_height; +- memset(s->mbskip_table, 0, s->mb_stride*s->mb_height); ++ s->v_edge_pos = 8 * s->mb_height; ++ memset(s->mbskip_table, 0, s->mb_stride * s->mb_height); + } + +- if(s->alternate_scan){ +- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); +- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); +- }else{ +- ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); +- ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); ++ if (s->alternate_scan) { ++ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_alternate_vertical_scan); ++ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_alternate_vertical_scan); ++ } else { ++ ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable, ff_zigzag_direct); ++ ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable, ff_zigzag_direct); + } + + /* composite display not parsed */ +@@ -1562,53 +1592,49 @@ + av_dlog(s->avctx, "progressive_frame=%d\n", s->progressive_frame); + } + +-static void exchange_uv(MpegEncContext *s){ +- DCTELEM (*tmp)[64]; +- +- tmp = s->pblocks[4]; +- s->pblocks[4] = s->pblocks[5]; +- s->pblocks[5] = tmp; +-} +- +-static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size){ +- AVCodecContext *avctx= s->avctx; ++static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) ++{ ++ AVCodecContext *avctx = s->avctx; + Mpeg1Context *s1 = (Mpeg1Context*)s; + + /* start frame decoding */ +- if(s->first_field || s->picture_structure==PICT_FRAME){ +- if(MPV_frame_start(s, avctx) < 0) ++ if (s->first_field || s->picture_structure == PICT_FRAME) { ++ if (MPV_frame_start(s, avctx) < 0) + return -1; + + ff_er_frame_start(s); + + /* first check if we must repeat the frame */ +- s->current_picture_ptr->repeat_pict = 0; ++ s->current_picture_ptr->f.repeat_pict = 0; + if (s->repeat_first_field) { + if (s->progressive_sequence) { + if (s->top_field_first) +- s->current_picture_ptr->repeat_pict = 4; ++ s->current_picture_ptr->f.repeat_pict = 4; + else +- s->current_picture_ptr->repeat_pict = 2; ++ s->current_picture_ptr->f.repeat_pict = 2; + } else if (s->progressive_frame) { +- s->current_picture_ptr->repeat_pict = 1; ++ s->current_picture_ptr->f.repeat_pict = 1; + } + } + +- *s->current_picture_ptr->pan_scan= s1->pan_scan; +- }else{ //second field +- int i; ++ *s->current_picture_ptr->f.pan_scan = s1->pan_scan; + +- if(!s->current_picture_ptr){ +- av_log(s->avctx, AV_LOG_ERROR, "first field missing\n"); +- return -1; +- } ++ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME)) ++ ff_thread_finish_setup(avctx); ++ } else { // second field ++ int i; + +- for(i=0; i<4; i++){ +- s->current_picture.data[i] = s->current_picture_ptr->data[i]; +- if(s->picture_structure == PICT_BOTTOM_FIELD){ +- s->current_picture.data[i] += s->current_picture_ptr->linesize[i]; +- } ++ if (!s->current_picture_ptr) { ++ av_log(s->avctx, AV_LOG_ERROR, "first field missing\n"); ++ return -1; ++ } ++ ++ for (i = 0; i < 4; i++) { ++ s->current_picture.f.data[i] = s->current_picture_ptr->f.data[i]; ++ if (s->picture_structure == PICT_BOTTOM_FIELD) { ++ s->current_picture.f.data[i] += s->current_picture_ptr->f.linesize[i]; + } ++ } + } + + if (avctx->hwaccel) { +@@ -1618,42 +1644,42 @@ + + // MPV_frame_start will call this function too, + // but we need to call it on every field +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) +- if(ff_xvmc_field_start(s,avctx) < 0) ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) ++ if (ff_xvmc_field_start(s, avctx) < 0) + return -1; + + return 0; + } + + #define DECODE_SLICE_ERROR -1 +-#define DECODE_SLICE_OK 0 ++#define DECODE_SLICE_OK 0 + + /** +- * decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode +- * @return DECODE_SLICE_ERROR if the slice is damaged
+- * DECODE_SLICE_OK if this slice is ok
++ * Decode a slice. ++ * MpegEncContext.mb_y must be set to the MB row from the startcode. ++ * @return DECODE_SLICE_ERROR if the slice is damaged, ++ * DECODE_SLICE_OK if this slice is OK + */ +-static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, ++static int mpeg_decode_slice(MpegEncContext *s, int mb_y, + const uint8_t **buf, int buf_size) + { +- MpegEncContext *s = &s1->mpeg_enc_ctx; +- AVCodecContext *avctx= s->avctx; +- const int field_pic= s->picture_structure != PICT_FRAME; +- const int lowres= s->avctx->lowres; ++ AVCodecContext *avctx = s->avctx; ++ const int lowres = s->avctx->lowres; ++ const int field_pic = s->picture_structure != PICT_FRAME; + +- s->resync_mb_x= +- s->resync_mb_y= -1; ++ s->resync_mb_x = ++ s->resync_mb_y = -1; + + assert(mb_y < s->mb_height); + +- init_get_bits(&s->gb, *buf, buf_size*8); ++ init_get_bits(&s->gb, *buf, buf_size * 8); + + ff_mpeg1_clean_buffers(s); + s->interlaced_dct = 0; + + s->qscale = get_qscale(s); + +- if(s->qscale == 0){ ++ if (s->qscale == 0) { + av_log(s->avctx, AV_LOG_ERROR, "qscale == 0\n"); + return -1; + } +@@ -1663,14 +1689,14 @@ + skip_bits(&s->gb, 8); + } + +- s->mb_x=0; ++ s->mb_x = 0; + +- if(mb_y==0 && s->codec_tag == AV_RL32("SLIF")){ ++ if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) { + skip_bits1(&s->gb); +- }else{ +- for(;;) { ++ } else { ++ while (get_bits_left(&s->gb) > 0) { + int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); +- if (code < 0){ ++ if (code < 0) { + av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n"); + return -1; + } +@@ -1686,7 +1712,7 @@ + } + } + +- if(s->mb_x >= (unsigned)s->mb_width){ ++ if (s->mb_x >= (unsigned)s->mb_width) { + av_log(s->avctx, AV_LOG_ERROR, "initial skip overflow\n"); + return -1; + } +@@ -1694,7 +1720,7 @@ + if (avctx->hwaccel) { + const uint8_t *buf_end, *buf_start = *buf - 4; /* include start_code */ + int start_code = -1; +- buf_end = ff_find_start_code(buf_start + 2, *buf + buf_size, &start_code); ++ buf_end = avpriv_mpv_find_start_code(buf_start + 2, *buf + buf_size, &start_code); + if (buf_end < *buf + buf_size) + buf_end -= 4; + s->mb_y = mb_y; +@@ -1704,41 +1730,41 @@ + return DECODE_SLICE_OK; + } + +- s->resync_mb_x= s->mb_x; +- s->resync_mb_y= s->mb_y= mb_y; +- s->mb_skip_run= 0; ++ s->resync_mb_x = s->mb_x; ++ s->resync_mb_y = s->mb_y = mb_y; ++ s->mb_skip_run = 0; + ff_init_block_index(s); + +- if (s->mb_y==0 && s->mb_x==0 && (s->first_field || s->picture_structure==PICT_FRAME)) { +- if(s->avctx->debug&FF_DEBUG_PICT_INFO){ ++ if (s->mb_y == 0 && s->mb_x == 0 && (s->first_field || s->picture_structure == PICT_FRAME)) { ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) { + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%2d%2d%2d%2d %s %s %s %s %s dc:%d pstruct:%d fdct:%d cmv:%d qtype:%d ivlc:%d rff:%d %s\n", +- s->qscale, s->mpeg_f_code[0][0],s->mpeg_f_code[0][1],s->mpeg_f_code[1][0],s->mpeg_f_code[1][1], +- s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), +- s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", +- s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, +- s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); ++ s->qscale, s->mpeg_f_code[0][0], s->mpeg_f_code[0][1], s->mpeg_f_code[1][0], s->mpeg_f_code[1][1], ++ s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")), ++ s->progressive_sequence ? "ps" :"", s->progressive_frame ? "pf" : "", s->alternate_scan ? "alt" :"", s->top_field_first ? "top" :"", ++ s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors, ++ s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :""); + } + } + +- for(;;) { +- //If 1, we memcpy blocks in xvmcvideo. +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) +- ff_xvmc_init_block(s);//set s->block ++ for (;;) { ++ // If 1, we memcpy blocks in xvmcvideo. ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1) ++ ff_xvmc_init_block(s); // set s->block + +- if(mpeg_decode_mb(s, s->block) < 0) ++ if (mpeg_decode_mb(s, s->block) < 0) + return -1; + +- if(s->current_picture.motion_val[0] && !s->encoding){ //note motion_val is normally NULL unless we want to extract the MVs ++ if (s->current_picture.f.motion_val[0] && !s->encoding) { // note motion_val is normally NULL unless we want to extract the MVs + const int wrap = s->b8_stride; +- int xy = s->mb_x*2 + s->mb_y*2*wrap; +- int b8_xy= 4*(s->mb_x + s->mb_y*s->mb_stride); ++ int xy = s->mb_x * 2 + s->mb_y * 2 * wrap; ++ int b8_xy = 4 * (s->mb_x + s->mb_y * s->mb_stride); + int motion_x, motion_y, dir, i; + +- for(i=0; i<2; i++){ +- for(dir=0; dir<2; dir++){ +- if (s->mb_intra || (dir==1 && s->pict_type != FF_B_TYPE)) { ++ for (i = 0; i < 2; i++) { ++ for (dir = 0; dir < 2; dir++) { ++ if (s->mb_intra || (dir == 1 && s->pict_type != AV_PICTURE_TYPE_B)) { + motion_x = motion_y = 0; +- }else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)){ ++ } else if (s->mv_type == MV_TYPE_16X16 || (s->mv_type == MV_TYPE_FIELD && field_pic)) { + motion_x = s->mv[dir][0][0]; + motion_y = s->mv[dir][0][1]; + } else /*if ((s->mv_type == MV_TYPE_FIELD) || (s->mv_type == MV_TYPE_16X8))*/ { +@@ -1746,13 +1772,13 @@ + motion_y = s->mv[dir][i][1]; + } + +- s->current_picture.motion_val[dir][xy ][0] = motion_x; +- s->current_picture.motion_val[dir][xy ][1] = motion_y; +- s->current_picture.motion_val[dir][xy + 1][0] = motion_x; +- s->current_picture.motion_val[dir][xy + 1][1] = motion_y; +- s->current_picture.ref_index [dir][b8_xy ]= +- s->current_picture.ref_index [dir][b8_xy + 1]= s->field_select[dir][i]; +- assert(s->field_select[dir][i]==0 || s->field_select[dir][i]==1); ++ s->current_picture.f.motion_val[dir][xy ][0] = motion_x; ++ s->current_picture.f.motion_val[dir][xy ][1] = motion_y; ++ s->current_picture.f.motion_val[dir][xy + 1][0] = motion_x; ++ s->current_picture.f.motion_val[dir][xy + 1][1] = motion_y; ++ s->current_picture.f.ref_index [dir][b8_xy ] = ++ s->current_picture.f.ref_index [dir][b8_xy + 1] = s->field_select[dir][i]; ++ assert(s->field_select[dir][i] == 0 || s->field_select[dir][i] == 1); + } + xy += wrap; + b8_xy +=2; +@@ -1766,24 +1792,25 @@ + MPV_decode_mb(s, s->block); + + if (++s->mb_x >= s->mb_width) { +- const int mb_size= 16>>s->avctx->lowres; ++ const int mb_size = 16 >> s->avctx->lowres; + +- ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size); ++ ff_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size); ++ MPV_report_decode_progress(s); + + s->mb_x = 0; +- s->mb_y += 1<mb_y += 1 << field_pic; + +- if(s->mb_y >= s->mb_height){ +- int left= get_bits_left(&s->gb); +- int is_d10= s->chroma_format==2 && s->pict_type==FF_I_TYPE && avctx->profile==0 && avctx->level==5 +- && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0 +- && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/; ++ if (s->mb_y >= s->mb_height) { ++ int left = get_bits_left(&s->gb); ++ int is_d10 = s->chroma_format == 2 && s->pict_type == AV_PICTURE_TYPE_I && avctx->profile == 0 && avctx->level == 5 ++ && s->intra_dc_precision == 2 && s->q_scale_type == 1 && s->alternate_scan == 0 ++ && s->progressive_frame == 0 /* vbv_delay == 0xBBB || 0xE10*/; + +- if(left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) +- || (avctx->error_recognition >= FF_ER_AGGRESSIVE && left>8)){ ++ if (left < 0 || (left && show_bits(&s->gb, FFMIN(left, 23)) && !is_d10) ++ || ((avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_AGGRESSIVE)) && left > 8)) { + av_log(avctx, AV_LOG_ERROR, "end mismatch left=%d %0X\n", left, show_bits(&s->gb, FFMIN(left, 23))); + return -1; +- }else ++ } else + goto eos; + } + +@@ -1794,17 +1821,17 @@ + if (s->mb_skip_run == -1) { + /* read increment again */ + s->mb_skip_run = 0; +- for(;;) { ++ for (;;) { + int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); +- if (code < 0){ ++ if (code < 0) { + av_log(s->avctx, AV_LOG_ERROR, "mb incr damaged\n"); + return -1; + } + if (code >= 33) { + if (code == 33) { + s->mb_skip_run += 33; +- }else if(code == 35){ +- if(s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0){ ++ } else if (code == 35) { ++ if (s->mb_skip_run != 0 || show_bits(&s->gb, 15) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "slice mismatch\n"); + return -1; + } +@@ -1816,28 +1843,28 @@ + break; + } + } +- if(s->mb_skip_run){ ++ if (s->mb_skip_run) { + int i; +- if(s->pict_type == FF_I_TYPE){ ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + av_log(s->avctx, AV_LOG_ERROR, "skipped MB in I frame at %d %d\n", s->mb_x, s->mb_y); + return -1; + } + + /* skip mb */ + s->mb_intra = 0; +- for(i=0;i<12;i++) ++ for (i = 0; i < 12; i++) + s->block_last_index[i] = -1; +- if(s->picture_structure == PICT_FRAME) ++ if (s->picture_structure == PICT_FRAME) + s->mv_type = MV_TYPE_16X16; + else + s->mv_type = MV_TYPE_FIELD; +- if (s->pict_type == FF_P_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { + /* if P type, zero motion vector is implied */ +- s->mv_dir = MV_DIR_FORWARD; +- s->mv[0][0][0] = s->mv[0][0][1] = 0; +- s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; +- s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; +- s->field_select[0][0]= (s->picture_structure - 1) & 1; ++ s->mv_dir = MV_DIR_FORWARD; ++ s->mv[0][0][0] = s->mv[0][0][1] = 0; ++ s->last_mv[0][0][0] = s->last_mv[0][0][1] = 0; ++ s->last_mv[0][1][0] = s->last_mv[0][1][1] = 0; ++ s->field_select[0][0] = (s->picture_structure - 1) & 1; + } else { + /* if B type, reuse previous vectors and directions */ + s->mv[0][0][0] = s->last_mv[0][0][0]; +@@ -1854,40 +1881,43 @@ + return 0; + } + +-static int slice_decode_thread(AVCodecContext *c, void *arg){ +- MpegEncContext *s= *(void**)arg; +- const uint8_t *buf= s->gb.buffer; +- int mb_y= s->start_mb_y; +- const int field_pic= s->picture_structure != PICT_FRAME; ++static int slice_decode_thread(AVCodecContext *c, void *arg) ++{ ++ MpegEncContext *s = *(void**)arg; ++ const uint8_t *buf = s->gb.buffer; ++ int mb_y = s->start_mb_y; ++ const int field_pic = s->picture_structure != PICT_FRAME; + +- s->error_count= (3*(s->end_mb_y - s->start_mb_y)*s->mb_width) >> field_pic; ++ s->error_count = (3 * (s->end_mb_y - s->start_mb_y) * s->mb_width) >> field_pic; + +- for(;;){ ++ for (;;) { + uint32_t start_code; + int ret; + +- ret= mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf); ++ ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf); + emms_c(); + //av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n", + //ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count); +- if(ret < 0){ +- if(s->resync_mb_x>=0 && s->resync_mb_y>=0) +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR); +- }else{ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); ++ if (ret < 0) { ++ if (c->err_recognition & AV_EF_EXPLODE) ++ return ret; ++ if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0) ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); ++ } else { ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); + } + +- if(s->mb_y == s->end_mb_y) ++ if (s->mb_y == s->end_mb_y) + return 0; + +- start_code= -1; +- buf = ff_find_start_code(buf, s->gb.buffer_end, &start_code); +- mb_y= start_code - SLICE_MIN_START_CODE; +- if(mb_y < 0 || mb_y >= s->end_mb_y) ++ start_code = -1; ++ buf = avpriv_mpv_find_start_code(buf, s->gb.buffer_end, &start_code); ++ mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic; ++ if (s->picture_structure == PICT_BOTTOM_FIELD) ++ mb_y++; ++ if (mb_y < 0 || mb_y >= s->end_mb_y) + return -1; + } +- +- return 0; //not reached + } + + /** +@@ -1907,28 +1937,29 @@ + av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode picture\n"); + } + +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) + ff_xvmc_field_end(s); + + /* end of slice reached */ +- if (/*s->mb_y<mb_height &&*/ !s->first_field && !s->first_slice) { ++ if (/*s->mb_y << field_pic == s->mb_height &&*/ !s->first_field && !s->first_slice) { + /* end of image */ + +- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2; ++ s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_MPEG2; + + ff_er_frame_end(s); + + MPV_frame_end(s); + +- if (s->pict_type == FF_B_TYPE || s->low_delay) { +- *pict= *(AVFrame*)s->current_picture_ptr; ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { ++ *pict = *(AVFrame*)s->current_picture_ptr; + ff_print_debug_info(s, pict); + } else { +- s->picture_number++; ++ if (avctx->active_thread_type & FF_THREAD_FRAME) ++ s->picture_number++; + /* latency of 1 frame for I- and P-frames */ + /* XXX: use another variable than picture_number */ + if (s->last_picture_ptr != NULL) { +- *pict= *(AVFrame*)s->last_picture_ptr; ++ *pict = *(AVFrame*)s->last_picture_ptr; + ff_print_debug_info(s, pict); + } + } +@@ -1944,19 +1975,19 @@ + { + Mpeg1Context *s1 = avctx->priv_data; + MpegEncContext *s = &s1->mpeg_enc_ctx; +- int width,height; ++ int width, height; + int i, v, j; + + init_get_bits(&s->gb, buf, buf_size*8); + +- width = get_bits(&s->gb, 12); ++ width = get_bits(&s->gb, 12); + height = get_bits(&s->gb, 12); + if (width <= 0 || height <= 0) + return -1; +- s->aspect_ratio_info= get_bits(&s->gb, 4); ++ s->aspect_ratio_info = get_bits(&s->gb, 4); + if (s->aspect_ratio_info == 0) { + av_log(avctx, AV_LOG_ERROR, "aspect ratio has forbidden 0 value\n"); +- if (avctx->error_recognition >= FF_ER_COMPLIANT) ++ if (avctx->err_recognition & (AV_EF_BITSTREAM | AV_EF_COMPLIANT)) + return -1; + } + s->frame_rate_index = get_bits(&s->gb, 4); +@@ -1965,52 +1996,54 @@ + s->bit_rate = get_bits(&s->gb, 18) * 400; + if (get_bits1(&s->gb) == 0) /* marker */ + return -1; +- s->width = width; ++ s->width = width; + s->height = height; + +- s->avctx->rc_buffer_size= get_bits(&s->gb, 10) * 1024*16; ++ s->avctx->rc_buffer_size = get_bits(&s->gb, 10) * 1024 * 16; + skip_bits(&s->gb, 1); + + /* get matrix */ + if (get_bits1(&s->gb)) { + load_matrix(s, s->chroma_intra_matrix, s->intra_matrix, 1); + } else { +- for(i=0;i<64;i++) { ++ for (i = 0; i < 64; i++) { + j = s->dsp.idct_permutation[i]; + v = ff_mpeg1_default_intra_matrix[i]; +- s->intra_matrix[j] = v; ++ s->intra_matrix[j] = v; + s->chroma_intra_matrix[j] = v; + } + } + if (get_bits1(&s->gb)) { + load_matrix(s, s->chroma_inter_matrix, s->inter_matrix, 0); + } else { +- for(i=0;i<64;i++) { +- int j= s->dsp.idct_permutation[i]; ++ for (i = 0; i < 64; i++) { ++ int j = s->dsp.idct_permutation[i]; + v = ff_mpeg1_default_non_intra_matrix[i]; +- s->inter_matrix[j] = v; ++ s->inter_matrix[j] = v; + s->chroma_inter_matrix[j] = v; + } + } + +- if(show_bits(&s->gb, 23) != 0){ ++ if (show_bits(&s->gb, 23) != 0) { + av_log(s->avctx, AV_LOG_ERROR, "sequence header damaged\n"); + return -1; + } + + /* we set MPEG-2 parameters so that it emulates MPEG-1 */ + s->progressive_sequence = 1; +- s->progressive_frame = 1; +- s->picture_structure = PICT_FRAME; ++ s->progressive_frame = 1; ++ s->picture_structure = PICT_FRAME; ++ s->first_field = 0; + s->frame_pred_frame_dct = 1; +- s->chroma_format = 1; +- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG1VIDEO; +- avctx->sub_id = 1; /* indicates MPEG-1 */ +- s->out_format = FMT_MPEG1; +- s->swap_uv = 0;//AFAIK VCR2 does not have SEQ_HEADER +- if(s->flags & CODEC_FLAG_LOW_DELAY) s->low_delay=1; ++ s->chroma_format = 1; ++ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO; ++ avctx->sub_id = 1; /* indicates MPEG-1 */ ++ s->out_format = FMT_MPEG1; ++ s->swap_uv = 0; // AFAIK VCR2 does not have SEQ_HEADER ++ if (s->flags & CODEC_FLAG_LOW_DELAY) ++ s->low_delay = 1; + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) + av_log(s->avctx, AV_LOG_DEBUG, "vbv buffer: %d, bitrate:%d\n", + s->avctx->rc_buffer_size, s->bit_rate); + +@@ -2030,41 +2063,46 @@ + } + s->width = avctx->coded_width; + s->height = avctx->coded_height; +- avctx->has_b_frames= 0; //true? +- s->low_delay= 1; ++ avctx->has_b_frames = 0; // true? ++ s->low_delay = 1; + + avctx->pix_fmt = mpeg_get_pixelformat(avctx); + avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); + +- if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel || +- s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU ) +- if( avctx->idct_algo == FF_IDCT_AUTO ) ++ if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ) ++ if (avctx->idct_algo == FF_IDCT_AUTO) + avctx->idct_algo = FF_IDCT_SIMPLE; + + if (MPV_common_init(s) < 0) + return -1; +- exchange_uv(s);//common init reset pblocks, so we swap them here +- s->swap_uv = 1;// in case of xvmc we need to swap uv for each MB + s1->mpeg_enc_ctx_allocated = 1; + +- for(i=0;i<64;i++) { +- int j= s->dsp.idct_permutation[i]; ++ for (i = 0; i < 64; i++) { ++ int j = s->dsp.idct_permutation[i]; + v = ff_mpeg1_default_intra_matrix[i]; +- s->intra_matrix[j] = v; ++ s->intra_matrix[j] = v; + s->chroma_intra_matrix[j] = v; + + v = ff_mpeg1_default_non_intra_matrix[i]; +- s->inter_matrix[j] = v; ++ s->inter_matrix[j] = v; + s->chroma_inter_matrix[j] = v; + } + +- s->progressive_sequence = 1; +- s->progressive_frame = 1; +- s->picture_structure = PICT_FRAME; +- s->frame_pred_frame_dct = 1; +- s->chroma_format = 1; +- s->codec_id= s->avctx->codec_id= CODEC_ID_MPEG2VIDEO; +- avctx->sub_id = 2; /* indicates MPEG-2 */ ++ s->progressive_sequence = 1; ++ s->progressive_frame = 1; ++ s->picture_structure = PICT_FRAME; ++ s->first_field = 0; ++ s->frame_pred_frame_dct = 1; ++ s->chroma_format = 1; ++ if (s->codec_tag == AV_RL32("BW10")) { ++ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO; ++ avctx->sub_id = 1; /* indicates MPEG-1 */ ++ } else { ++ exchange_uv(s); // common init reset pblocks, so we swap them here ++ s->swap_uv = 1; // in case of xvmc we need to swap uv for each MB ++ s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO; ++ avctx->sub_id = 2; /* indicates MPEG-2 */ ++ } + s1->save_width = s->width; + s1->save_height = s->height; + s1->save_progressive_seq = s->progressive_sequence; +@@ -2075,7 +2113,21 @@ + static void mpeg_decode_user_data(AVCodecContext *avctx, + const uint8_t *p, int buf_size) + { +- const uint8_t *buf_end = p+buf_size; ++ Mpeg1Context *s = avctx->priv_data; ++ const uint8_t *buf_end = p + buf_size; ++ ++ if(buf_size > 29){ ++ int i; ++ for(i=0; i<20; i++) ++ if(!memcmp(p+i, "\0TMPGEXS\0", 9)){ ++ s->tmpgexs= 1; ++ } ++ ++/* for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i= 5 && +@@ -2095,24 +2147,16 @@ + } + + static void mpeg_decode_gop(AVCodecContext *avctx, +- const uint8_t *buf, int buf_size){ +- Mpeg1Context *s1 = avctx->priv_data; ++ const uint8_t *buf, int buf_size) ++{ ++ Mpeg1Context *s1 = avctx->priv_data; + MpegEncContext *s = &s1->mpeg_enc_ctx; +- +- int drop_frame_flag; +- int time_code_hours, time_code_minutes; +- int time_code_seconds, time_code_pictures; + int broken_link; ++ int64_t tc; + + init_get_bits(&s->gb, buf, buf_size*8); + +- drop_frame_flag = get_bits1(&s->gb); +- +- time_code_hours=get_bits(&s->gb,5); +- time_code_minutes = get_bits(&s->gb,6); +- skip_bits1(&s->gb);//marker bit +- time_code_seconds = get_bits(&s->gb,6); +- time_code_pictures = get_bits(&s->gb,6); ++ tc = avctx->timecode_frame_start = get_bits(&s->gb, 25); + + s->closed_gop = get_bits1(&s->gb); + /*broken_link indicate that after editing the +@@ -2120,10 +2164,17 @@ + are missing (open gop)*/ + broken_link = get_bits1(&s->gb); + +- if(s->avctx->debug & FF_DEBUG_PICT_INFO) +- av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n", +- time_code_hours, time_code_minutes, time_code_seconds, +- time_code_pictures, s->closed_gop, broken_link); ++ if (s->avctx->debug & FF_DEBUG_PICT_INFO) { ++ int time_code_hours = tc>>19 & 0x1f; ++ int time_code_minutes = tc>>13 & 0x3f; ++ int time_code_seconds = tc>>6 & 0x3f; ++ int drop_frame_flag = tc & 1<<24; ++ int time_code_pictures = tc & 0x3f; ++ av_log(s->avctx, AV_LOG_DEBUG, "GOP (%02d:%02d:%02d%c%02d) closed_gop=%d broken_link=%d\n", ++ time_code_hours, time_code_minutes, time_code_seconds, ++ drop_frame_flag ? ';' : ':', ++ time_code_pictures, s->closed_gop, broken_link); ++ } + } + /** + * Find the end of the current frame in the bitstream. +@@ -2132,7 +2183,7 @@ + int ff_mpeg1_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size, AVCodecParserContext *s) + { + int i; +- uint32_t state= pc->state; ++ uint32_t state = pc->state; + + /* EOF considered as end of frame */ + if (buf_size == 0) +@@ -2146,49 +2197,52 @@ + 4 searching end + */ + +- for(i=0; iframe_start_found>=0 && pc->frame_start_found<=4); +- if(pc->frame_start_found&1){ +- if(state == EXT_START_CODE && (buf[i]&0xF0) != 0x80) ++ for (i = 0; i < buf_size; i++) { ++ assert(pc->frame_start_found >= 0 && pc->frame_start_found <= 4); ++ if (pc->frame_start_found & 1) { ++ if (state == EXT_START_CODE && (buf[i] & 0xF0) != 0x80) + pc->frame_start_found--; +- else if(state == EXT_START_CODE+2){ +- if((buf[i]&3) == 3) pc->frame_start_found= 0; +- else pc->frame_start_found= (pc->frame_start_found+1)&3; ++ else if (state == EXT_START_CODE + 2) { ++ if ((buf[i] & 3) == 3) ++ pc->frame_start_found = 0; ++ else ++ pc->frame_start_found = (pc->frame_start_found + 1) & 3; + } + state++; +- }else{ +- i= ff_find_start_code(buf+i, buf+buf_size, &state) - buf - 1; +- if(pc->frame_start_found==0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE){ ++ } else { ++ i = avpriv_mpv_find_start_code(buf + i, buf + buf_size, &state) - buf - 1; ++ if (pc->frame_start_found == 0 && state >= SLICE_MIN_START_CODE && state <= SLICE_MAX_START_CODE) { + i++; +- pc->frame_start_found=4; ++ pc->frame_start_found = 4; + } +- if(state == SEQ_END_CODE){ ++ if (state == SEQ_END_CODE) { ++ pc->frame_start_found = 0; + pc->state=-1; + return i+1; + } +- if(pc->frame_start_found==2 && state == SEQ_START_CODE) +- pc->frame_start_found= 0; +- if(pc->frame_start_found<4 && state == EXT_START_CODE) ++ if (pc->frame_start_found == 2 && state == SEQ_START_CODE) ++ pc->frame_start_found = 0; ++ if (pc->frame_start_found < 4 && state == EXT_START_CODE) + pc->frame_start_found++; +- if(pc->frame_start_found == 4 && (state&0xFFFFFF00) == 0x100){ +- if(state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE){ +- pc->frame_start_found=0; +- pc->state=-1; +- return i-3; ++ if (pc->frame_start_found == 4 && (state & 0xFFFFFF00) == 0x100) { ++ if (state < SLICE_MIN_START_CODE || state > SLICE_MAX_START_CODE) { ++ pc->frame_start_found = 0; ++ pc->state = -1; ++ return i - 3; + } + } +- if(pc->frame_start_found == 0 && s && state == PICTURE_START_CODE){ +- ff_fetch_timestamp(s, i-3, 1); ++ if (pc->frame_start_found == 0 && s && state == PICTURE_START_CODE) { ++ ff_fetch_timestamp(s, i - 3, 1); + } + } + } +- pc->state= state; ++ pc->state = state; + return END_NOT_FOUND; + } + + static int decode_chunks(AVCodecContext *avctx, +- AVFrame *picture, int *data_size, +- const uint8_t *buf, int buf_size); ++ AVFrame *picture, int *data_size, ++ const uint8_t *buf, int buf_size); + + /* handle buffering and image synchronisation */ + static int mpeg_decode_frame(AVCodecContext *avctx, +@@ -2204,126 +2258,142 @@ + + if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) { + /* special case for last picture */ +- if (s2->low_delay==0 && s2->next_picture_ptr) { +- *picture= *(AVFrame*)s2->next_picture_ptr; +- s2->next_picture_ptr= NULL; ++ if (s2->low_delay == 0 && s2->next_picture_ptr) { ++ *picture = *(AVFrame*)s2->next_picture_ptr; ++ s2->next_picture_ptr = NULL; + + *data_size = sizeof(AVFrame); + } + return buf_size; + } + +- if(s2->flags&CODEC_FLAG_TRUNCATED){ +- int next= ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL); ++ if (s2->flags & CODEC_FLAG_TRUNCATED) { ++ int next = ff_mpeg1_find_frame_end(&s2->parse_context, buf, buf_size, NULL); + +- if( ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0 ) ++ if (ff_combine_frame(&s2->parse_context, next, (const uint8_t **)&buf, &buf_size) < 0) + return buf_size; + } + +-#if 0 +- if (s->repeat_field % 2 == 1) { +- s->repeat_field++; +- //fprintf(stderr,"\nRepeating last frame: %d -> %d! pict: %d %d", avctx->frame_number-1, avctx->frame_number, +- // s2->picture_number, s->repeat_field); +- if (avctx->flags & CODEC_FLAG_REPEAT_FIELD) { +- *data_size = sizeof(AVPicture); +- goto the_end; +- } +- } +-#endif +- +- if(s->mpeg_enc_ctx_allocated==0 && avctx->codec_tag == AV_RL32("VCR2")) ++ s2->codec_tag = avpriv_toupper4(avctx->codec_tag); ++ if (s->mpeg_enc_ctx_allocated == 0 && ( s2->codec_tag == AV_RL32("VCR2") ++ || s2->codec_tag == AV_RL32("BW10") ++ )) + vcr2_init_sequence(avctx); + +- s->slice_count= 0; ++ s->slice_count = 0; + +- if(avctx->extradata && !avctx->frame_number) +- decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size); ++ if (avctx->extradata && !avctx->frame_number) { ++ int ret = decode_chunks(avctx, picture, data_size, avctx->extradata, avctx->extradata_size); ++ if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) ++ return ret; ++ } + + return decode_chunks(avctx, picture, data_size, buf, buf_size); + } + + static int decode_chunks(AVCodecContext *avctx, +- AVFrame *picture, int *data_size, +- const uint8_t *buf, int buf_size) ++ AVFrame *picture, int *data_size, ++ const uint8_t *buf, int buf_size) + { + Mpeg1Context *s = avctx->priv_data; + MpegEncContext *s2 = &s->mpeg_enc_ctx; + const uint8_t *buf_ptr = buf; + const uint8_t *buf_end = buf + buf_size; + int ret, input_size; +- int last_code= 0; ++ int last_code = 0; + +- for(;;) { ++ for (;;) { + /* find next start code */ + uint32_t start_code = -1; +- buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); +- if (start_code > 0x1ff){ +- if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ +- if(avctx->thread_count > 1){ ++ buf_ptr = avpriv_mpv_find_start_code(buf_ptr, buf_end, &start_code); ++ if (start_code > 0x1ff) { ++ if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) { ++ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) { + int i; ++ av_assert0(avctx->thread_count > 1); + + avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*)); +- for(i=0; islice_count; i++) ++ for (i = 0; i < s->slice_count; i++) + s2->error_count += s2->thread_context[i]->error_count; + } + +- if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) ++ if (CONFIG_VDPAU && uses_vdpau(avctx)) + ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count); + ++ + if (slice_end(avctx, picture)) { +- if(s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice ++ if (s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice + *data_size = sizeof(AVPicture); + } + } +- s2->pict_type= 0; ++ s2->pict_type = 0; + return FFMAX(0, buf_ptr - buf - s2->parse_context.last_index); + } + + input_size = buf_end - buf_ptr; + +- if(avctx->debug & FF_DEBUG_STARTCODE){ ++ if (avctx->debug & FF_DEBUG_STARTCODE) { + av_log(avctx, AV_LOG_DEBUG, "%3X at %td left %d\n", start_code, buf_ptr-buf, input_size); + } + + /* prepare data for next start code */ +- switch(start_code) { ++ switch (start_code) { + case SEQ_START_CODE: +- if(last_code == 0){ +- mpeg1_decode_sequence(avctx, buf_ptr, +- input_size); +- s->sync=1; +- }else{ ++ if (last_code == 0) { ++ mpeg1_decode_sequence(avctx, buf_ptr, input_size); ++ if(buf != avctx->extradata) ++ s->sync=1; ++ } else { + av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + } + break; + + case PICTURE_START_CODE: +- if(last_code == 0 || last_code == SLICE_MIN_START_CODE){ +- if(mpeg_decode_postinit(avctx) < 0){ +- av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n"); +- return -1; ++ if(s->tmpgexs){ ++ s2->intra_dc_precision= 3; ++ s2->intra_matrix[0]= 1; + } ++ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && s->slice_count) { ++ int i; + +- /* we have a complete image: we try to decompress it */ +- if(mpeg1_decode_picture(avctx, +- buf_ptr, input_size) < 0) +- s2->pict_type=0; ++ avctx->execute(avctx, slice_decode_thread, ++ s2->thread_context, NULL, ++ s->slice_count, sizeof(void*)); ++ for (i = 0; i < s->slice_count; i++) ++ s2->error_count += s2->thread_context[i]->error_count; ++ s->slice_count = 0; ++ } ++ if (last_code == 0 || last_code == SLICE_MIN_START_CODE) { ++ ret = mpeg_decode_postinit(avctx); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, "mpeg_decode_postinit() failure\n"); ++ return ret; ++ } ++ ++ /* we have a complete image: we try to decompress it */ ++ if (mpeg1_decode_picture(avctx, buf_ptr, input_size) < 0) ++ s2->pict_type = 0; + s2->first_slice = 1; +- last_code= PICTURE_START_CODE; +- }else{ ++ last_code = PICTURE_START_CODE; ++ } else { + av_log(avctx, AV_LOG_ERROR, "ignoring pic after %X\n", last_code); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + } + break; + case EXT_START_CODE: + init_get_bits(&s2->gb, buf_ptr, input_size*8); + +- switch(get_bits(&s2->gb, 4)) { ++ switch (get_bits(&s2->gb, 4)) { + case 0x1: +- if(last_code == 0){ ++ if (last_code == 0) { + mpeg_decode_sequence_extension(s); +- }else{ ++ } else { + av_log(avctx, AV_LOG_ERROR, "ignoring seq ext after %X\n", last_code); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + } + break; + case 0x2: +@@ -2336,116 +2406,122 @@ + mpeg_decode_picture_display_extension(s); + break; + case 0x8: +- if(last_code == PICTURE_START_CODE){ +- mpeg_decode_picture_coding_extension(s); +- }else{ ++ if (last_code == PICTURE_START_CODE) { ++ mpeg_decode_picture_coding_extension(s); ++ } else { + av_log(avctx, AV_LOG_ERROR, "ignoring pic cod ext after %X\n", last_code); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + } + break; + } + break; + case USER_START_CODE: +- mpeg_decode_user_data(avctx, +- buf_ptr, input_size); ++ mpeg_decode_user_data(avctx, buf_ptr, input_size); + break; + case GOP_START_CODE: +- if(last_code == 0){ +- s2->first_field=0; +- mpeg_decode_gop(avctx, +- buf_ptr, input_size); ++ if (last_code == 0) { ++ s2->first_field=0; ++ mpeg_decode_gop(avctx, buf_ptr, input_size); + s->sync=1; +- }else{ ++ } else { + av_log(avctx, AV_LOG_ERROR, "ignoring GOP_START_CODE after %X\n", last_code); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + } + break; + default: + if (start_code >= SLICE_MIN_START_CODE && +- start_code <= SLICE_MAX_START_CODE && last_code!=0) { +- const int field_pic= s2->picture_structure != PICT_FRAME; +- int mb_y= (start_code - SLICE_MIN_START_CODE) << field_pic; +- last_code= SLICE_MIN_START_CODE; ++ start_code <= SLICE_MAX_START_CODE && last_code != 0) { ++ const int field_pic = s2->picture_structure != PICT_FRAME; ++ int mb_y = (start_code - SLICE_MIN_START_CODE) << field_pic; ++ last_code = SLICE_MIN_START_CODE; + +- if(s2->picture_structure == PICT_BOTTOM_FIELD) ++ if (s2->picture_structure == PICT_BOTTOM_FIELD) + mb_y++; + +- if (mb_y >= s2->mb_height){ ++ if (mb_y >= s2->mb_height) { + av_log(s2->avctx, AV_LOG_ERROR, "slice below image (%d >= %d)\n", mb_y, s2->mb_height); + return -1; + } + +- if(s2->last_picture_ptr==NULL){ ++ if (s2->last_picture_ptr == NULL) { + /* Skip B-frames if we do not have reference frames and gop is not closed */ +- if(s2->pict_type==FF_B_TYPE){ +- if(!s2->closed_gop) ++ if (s2->pict_type == AV_PICTURE_TYPE_B) { ++ if (!s2->closed_gop) + break; + } + } +- if(s2->pict_type==FF_I_TYPE) ++ if (s2->pict_type == AV_PICTURE_TYPE_I || (s2->flags2 & CODEC_FLAG2_SHOW_ALL)) + s->sync=1; +- if(s2->next_picture_ptr==NULL){ ++ if (s2->next_picture_ptr == NULL) { + /* Skip P-frames if we do not have a reference frame or we have an invalid header. */ +- if(s2->pict_type==FF_P_TYPE && !s->sync) break; ++ if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) break; + } +- /* Skip B-frames if we are in a hurry. */ +- if(avctx->hurry_up && s2->pict_type==FF_B_TYPE) break; +- if( (avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type==FF_B_TYPE) +- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type!=FF_I_TYPE) +- || avctx->skip_frame >= AVDISCARD_ALL) ++ if ((avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type == AV_PICTURE_TYPE_B) || ++ (avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type != AV_PICTURE_TYPE_I) || ++ avctx->skip_frame >= AVDISCARD_ALL) + break; +- /* Skip everything if we are in a hurry>=5. */ +- if(avctx->hurry_up>=5) break; + +- if (!s->mpeg_enc_ctx_allocated) break; ++ if (!s->mpeg_enc_ctx_allocated) ++ break; + +- if(s2->codec_id == CODEC_ID_MPEG2VIDEO){ +- if(mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom) ++ if (s2->codec_id == CODEC_ID_MPEG2VIDEO) { ++ if (mb_y < avctx->skip_top || mb_y >= s2->mb_height - avctx->skip_bottom) + break; + } + +- if(!s2->pict_type){ ++ if (!s2->pict_type) { + av_log(avctx, AV_LOG_ERROR, "Missing picture start code\n"); ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return AVERROR_INVALIDDATA; + break; + } + +- if(s2->first_slice){ +- s2->first_slice=0; +- if(mpeg_field_start(s2, buf, buf_size) < 0) ++ if (s2->first_slice) { ++ s2->first_slice = 0; ++ if (mpeg_field_start(s2, buf, buf_size) < 0) + return -1; + } +- if(!s2->current_picture_ptr){ ++ if (!s2->current_picture_ptr) { + av_log(avctx, AV_LOG_ERROR, "current_picture not initialized\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) { ++ if (uses_vdpau(avctx)) { + s->slice_count++; + break; + } + +- if(avctx->thread_count > 1){ +- int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count; +- if(threshold <= mb_y){ +- MpegEncContext *thread_context= s2->thread_context[s->slice_count]; +- +- thread_context->start_mb_y= mb_y; +- thread_context->end_mb_y = s2->mb_height; +- if(s->slice_count){ +- s2->thread_context[s->slice_count-1]->end_mb_y= mb_y; ++ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) { ++ int threshold = (s2->mb_height * s->slice_count + ++ s2->slice_context_count / 2) / ++ s2->slice_context_count; ++ av_assert0(avctx->thread_count > 1); ++ if (threshold <= mb_y) { ++ MpegEncContext *thread_context = s2->thread_context[s->slice_count]; ++ ++ thread_context->start_mb_y = mb_y; ++ thread_context->end_mb_y = s2->mb_height; ++ if (s->slice_count) { ++ s2->thread_context[s->slice_count-1]->end_mb_y = mb_y; + ff_update_duplicate_context(thread_context, s2); + } + init_get_bits(&thread_context->gb, buf_ptr, input_size*8); + s->slice_count++; + } +- buf_ptr += 2; //FIXME add minimum number of bytes per slice +- }else{ +- ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size); ++ buf_ptr += 2; // FIXME add minimum number of bytes per slice ++ } else { ++ ret = mpeg_decode_slice(s2, mb_y, &buf_ptr, input_size); + emms_c(); + +- if(ret < 0){ +- if(s2->resync_mb_x>=0 && s2->resync_mb_y>=0) +- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR|DC_ERROR|MV_ERROR); +- }else{ +- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END|DC_END|MV_END); ++ if (ret < 0) { ++ if (avctx->err_recognition & AV_EF_EXPLODE) ++ return ret; ++ if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0) ++ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR); ++ } else { ++ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END); + } + } + } +@@ -2454,7 +2530,8 @@ + } + } + +-static void flush(AVCodecContext *avctx){ ++static void flush(AVCodecContext *avctx) ++{ + Mpeg1Context *s = avctx->priv_data; + + s->sync=0; +@@ -2471,114 +2548,124 @@ + return 0; + } + ++static const AVProfile mpeg2_video_profiles[] = { ++ { FF_PROFILE_MPEG2_422, "4:2:2" }, ++ { FF_PROFILE_MPEG2_HIGH, "High" }, ++ { FF_PROFILE_MPEG2_SS, "Spatially Scalable" }, ++ { FF_PROFILE_MPEG2_SNR_SCALABLE, "SNR Scalable" }, ++ { FF_PROFILE_MPEG2_MAIN, "Main" }, ++ { FF_PROFILE_MPEG2_SIMPLE, "Simple" }, ++ { FF_PROFILE_RESERVED, "Reserved" }, ++ { FF_PROFILE_RESERVED, "Reserved" }, ++ { FF_PROFILE_UNKNOWN }, ++}; ++ ++ + AVCodec ff_mpeg1video_decoder = { +- "mpeg1video", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG1VIDEO, +- sizeof(Mpeg1Context), +- mpeg_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, +- .flush= flush, +- .max_lowres= 3, +- .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), ++ .name = "mpeg1video", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG1VIDEO, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, ++ .flush = flush, ++ .max_lowres = 3, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context) + }; + + AVCodec ff_mpeg2video_decoder = { +- "mpeg2video", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG2VIDEO, +- sizeof(Mpeg1Context), +- mpeg_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, +- .flush= flush, +- .max_lowres= 3, +- .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), ++ .name = "mpeg2video", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, ++ .flush = flush, ++ .max_lowres = 3, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"), ++ .profiles = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles), + }; + + //legacy decoder + AVCodec ff_mpegvideo_decoder = { +- "mpegvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG2VIDEO, +- sizeof(Mpeg1Context), +- mpeg_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, +- .flush= flush, +- .max_lowres= 3, +- .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), ++ .name = "mpegvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, ++ .flush = flush, ++ .max_lowres = 3, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"), + }; + + #if CONFIG_MPEG_XVMC_DECODER +-static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ +- if( avctx->thread_count > 1) ++static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx) ++{ ++ if (avctx->active_thread_type & FF_THREAD_SLICE) + return -1; +- if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) ++ if (!(avctx->slice_flags & SLICE_FLAG_CODED_ORDER)) + return -1; +- if( !(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD) ){ ++ if (!(avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) { + av_dlog(avctx, "mpeg12.c: XvMC decoder will work better if SLICE_FLAG_ALLOW_FIELD is set\n"); + } + mpeg_decode_init(avctx); + +- avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT; +- avctx->xvmc_acceleration = 2;//2 - the blocks are packed! ++ avctx->pix_fmt = PIX_FMT_XVMC_MPEG2_IDCT; ++ avctx->xvmc_acceleration = 2; // 2 - the blocks are packed! + + return 0; + } + + AVCodec ff_mpeg_xvmc_decoder = { +- "mpegvideo_xvmc", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG2VIDEO_XVMC, +- sizeof(Mpeg1Context), +- mpeg_mc_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY, +- .flush= flush, +- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"), ++ .name = "mpegvideo_xvmc", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO_XVMC, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_mc_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"), + }; + + #endif + + #if CONFIG_MPEG_VDPAU_DECODER + AVCodec ff_mpeg_vdpau_decoder = { +- "mpegvideo_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG2VIDEO, +- sizeof(Mpeg1Context), +- mpeg_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, +- .flush= flush, +- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"), ++ .name = "mpegvideo_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"), + }; + #endif + + #if CONFIG_MPEG1_VDPAU_DECODER + AVCodec ff_mpeg1_vdpau_decoder = { +- "mpeg1video_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG1VIDEO, +- sizeof(Mpeg1Context), +- mpeg_decode_init, +- NULL, +- mpeg_decode_end, +- mpeg_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, +- .flush= flush, +- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"), ++ .name = "mpeg1video_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG1VIDEO, ++ .priv_data_size = sizeof(Mpeg1Context), ++ .init = mpeg_decode_init, ++ .close = mpeg_decode_end, ++ .decode = mpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY, ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"), + }; + #endif + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12data.c 2012-05-14 14:08:54.005333360 +0200 +@@ -305,7 +305,7 @@ + { 0xc, 10 }, + }; + +-const AVRational ff_frame_rate_tab[] = { ++const AVRational avpriv_frame_rate_tab[16] = { + { 0, 0}, + {24000, 1001}, + { 24, 1}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12data.h 2012-05-14 14:08:54.006333380 +0200 +@@ -48,7 +48,7 @@ + + extern const uint8_t ff_mpeg12_mbMotionVectorTable[17][2]; + +-extern const AVRational ff_frame_rate_tab[]; ++extern const AVRational avpriv_frame_rate_tab[]; + + extern const float ff_mpeg1_aspect[16]; + extern const AVRational ff_mpeg2_aspect[16]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12enc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12enc.c 2012-05-14 14:08:54.008333420 +0200 +@@ -27,12 +27,16 @@ + + #include "avcodec.h" + #include "dsputil.h" ++#include "mathops.h" + #include "mpegvideo.h" + + #include "mpeg12.h" + #include "mpeg12data.h" + #include "bytestream.h" +- ++#include "timecode.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/avassert.h" + + static const uint8_t inv_non_linear_qscale[13] = { + 0, 2, 4, 6, 8, +@@ -71,11 +75,12 @@ + for(i=0; i<128; i++){ + int level= i-64; + int run; ++ if (!level) ++ continue; + for(run=0; run<64; run++){ +- int len, bits, code; ++ int len, code; + + int alevel= FFABS(level); +- int sign= (level>>31)&1; + + if (alevel > rl->max_level[0][run]) + code= 111; /*rl->n*/ +@@ -83,25 +88,15 @@ + code= rl->index_run[0][run] + alevel - 1; + + if (code < 111 /* rl->n */) { +- /* store the vlc & sign at once */ ++ /* length of vlc and sign */ + len= rl->table_vlc[code][1]+1; +- bits= (rl->table_vlc[code][0]<<1) + sign; + } else { + len= rl->table_vlc[111/*rl->n*/][1]+6; +- bits= rl->table_vlc[111/*rl->n*/][0]<<6; + +- bits|= run; + if (alevel < 128) { +- bits<<=8; len+=8; +- bits|= level & 0xff; ++ len += 8; + } else { +- bits<<=16; len+=16; +- bits|= level & 0xff; +- if (level < 0) { +- bits|= 0x8001 + level + 255; +- } else { +- bits|= level & 0xffff; +- } ++ len += 16; + } + } + +@@ -117,7 +112,7 @@ + int64_t d; + + for(i=1;i<14;i++) { +- int64_t n0= 1001LL/ff_frame_rate_tab[i].den*ff_frame_rate_tab[i].num*s->avctx->time_base.num; ++ int64_t n0= 1001LL/avpriv_frame_rate_tab[i].den*avpriv_frame_rate_tab[i].num*s->avctx->time_base.num; + int64_t n1= 1001LL*s->avctx->time_base.den; + if(s->avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL && i>=9) break; + +@@ -140,6 +135,13 @@ + if(MPV_encode_init(avctx) < 0) + return -1; + ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) ++ s->drop_frame_timecode = 1; ++ if (avctx->flags & CODEC_FLAG_SVCD_SCAN_OFFSET) ++ s->scan_offset = 1; ++#endif ++ + if(find_frame_rate_index(s) < 0){ + if(s->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ + av_log(avctx, AV_LOG_ERROR, "MPEG1/2 does not support %d/%d fps\n", avctx->time_base.den, avctx->time_base.num); +@@ -172,17 +174,27 @@ + } + } + +- if((avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) && s->frame_rate_index != 4){ ++ s->drop_frame_timecode = s->tc.drop = s->drop_frame_timecode || !!(avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE); ++ if (s->drop_frame_timecode && s->frame_rate_index != 4) { + av_log(avctx, AV_LOG_ERROR, "Drop frame time code only allowed with 1001/30000 fps\n"); + return -1; + } + ++ if (s->tc.str) { ++ s->tc.rate = avpriv_frame_rate_tab[s->frame_rate_index]; ++ if (avpriv_init_smpte_timecode(s, &s->tc) < 0) ++ return -1; ++ s->drop_frame_timecode = s->tc.drop; ++ s->avctx->timecode_frame_start = s->tc.start; ++ } else { ++ s->avctx->timecode_frame_start = 0; // default is -1 ++ } + return 0; + } + + static void put_header(MpegEncContext *s, int header) + { +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + put_bits(&s->pb, 16, header>>16); + put_sbits(&s->pb, 16, header); + } +@@ -200,8 +212,8 @@ + + if(aspect_ratio==0.0) aspect_ratio= 1.0; //pixel aspect 1:1 (VGA) + +- if (s->current_picture.key_frame) { +- AVRational framerate= ff_frame_rate_tab[s->frame_rate_index]; ++ if (s->current_picture.f.key_frame) { ++ AVRational framerate= avpriv_frame_rate_tab[s->frame_rate_index]; + + /* mpeg1 header repeated every gop */ + put_header(s, SEQ_START_CODE); +@@ -283,20 +295,16 @@ + } + + put_header(s, GOP_START_CODE); +- put_bits(&s->pb, 1, !!(s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE)); /* drop frame flag */ ++ put_bits(&s->pb, 1, s->drop_frame_timecode); /* drop frame flag */ + /* time code : we must convert from the real frame rate to a + fake mpeg frame rate in case of low frame rate */ + fps = (framerate.num + framerate.den/2)/ framerate.den; +- time_code = s->current_picture_ptr->coded_picture_number + s->avctx->timecode_frame_start; ++ time_code = s->current_picture_ptr->f.coded_picture_number + s->avctx->timecode_frame_start; + +- s->gop_picture_number = s->current_picture_ptr->coded_picture_number; +- if (s->avctx->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE) { +- /* only works for NTSC 29.97 */ +- int d = time_code / 17982; +- int m = time_code % 17982; +- //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */ +- time_code += 18 * d + 2 * ((m - 2) / 1798); +- } ++ s->gop_picture_number = s->current_picture_ptr->f.coded_picture_number; ++ av_assert0(s->drop_frame_timecode == s->tc.drop); ++ if (s->tc.drop) ++ time_code = avpriv_framenum_to_drop_timecode(time_code); + put_bits(&s->pb, 5, (uint32_t)((time_code / (fps * 3600)) % 24)); + put_bits(&s->pb, 6, (uint32_t)((time_code / (fps * 60)) % 60)); + put_bits(&s->pb, 1, 1); +@@ -354,7 +362,7 @@ + put_bits(&s->pb, 16, 0xFFFF); /* vbv_delay */ + + // RAL: Forward f_code also needed for B frames +- if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) { + put_bits(&s->pb, 1, 0); /* half pel coordinates */ + if(s->codec_id == CODEC_ID_MPEG1VIDEO) + put_bits(&s->pb, 3, s->f_code); /* forward_f_code */ +@@ -363,7 +371,7 @@ + } + + // RAL: Backward f_code necessary for B frames +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + put_bits(&s->pb, 1, 0); /* half pel coordinates */ + if(s->codec_id == CODEC_ID_MPEG1VIDEO) + put_bits(&s->pb, 3, s->b_code); /* backward_f_code */ +@@ -377,13 +385,13 @@ + if(s->codec_id == CODEC_ID_MPEG2VIDEO){ + put_header(s, EXT_START_CODE); + put_bits(&s->pb, 4, 8); //pic ext +- if (s->pict_type == FF_P_TYPE || s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) { + put_bits(&s->pb, 4, s->f_code); + put_bits(&s->pb, 4, s->f_code); + }else{ + put_bits(&s->pb, 8, 255); + } +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + put_bits(&s->pb, 4, s->b_code); + put_bits(&s->pb, 4, s->b_code); + }else{ +@@ -396,7 +404,7 @@ + if (s->progressive_sequence) { + put_bits(&s->pb, 1, 0); /* no repeat */ + } else { +- put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); ++ put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first); + } + /* XXX: optimize the generation of this flag with entropy + measures */ +@@ -413,7 +421,7 @@ + put_bits(&s->pb, 1, s->progressive_frame); + put_bits(&s->pb, 1, 0); //composite_display_flag + } +- if(s->flags & CODEC_FLAG_SVCD_SCAN_OFFSET){ ++ if (s->scan_offset) { + int i; + + put_header(s, USER_START_CODE); +@@ -456,15 +464,15 @@ + + if (cbp == 0 && !first_mb && s->mv_type == MV_TYPE_16X16 && + (mb_x != s->mb_width - 1 || (mb_y != s->mb_height - 1 && s->codec_id == CODEC_ID_MPEG1VIDEO)) && +- ((s->pict_type == FF_P_TYPE && (motion_x | motion_y) == 0) || +- (s->pict_type == FF_B_TYPE && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) | ++ ((s->pict_type == AV_PICTURE_TYPE_P && (motion_x | motion_y) == 0) || ++ (s->pict_type == AV_PICTURE_TYPE_B && s->mv_dir == s->last_mv_dir && (((s->mv_dir & MV_DIR_FORWARD) ? ((s->mv[0][0][0] - s->last_mv[0][0][0])|(s->mv[0][0][1] - s->last_mv[0][0][1])) : 0) | + ((s->mv_dir & MV_DIR_BACKWARD) ? ((s->mv[1][0][0] - s->last_mv[1][0][0])|(s->mv[1][0][1] - s->last_mv[1][0][1])) : 0)) == 0))) { + s->mb_skip_run++; + s->qscale -= s->dquant; + s->skip_count++; + s->misc_bits++; + s->last_bits++; +- if(s->pict_type == FF_P_TYPE){ ++ if(s->pict_type == AV_PICTURE_TYPE_P){ + s->last_mv[0][1][0]= s->last_mv[0][0][0]= + s->last_mv[0][1][1]= s->last_mv[0][0][1]= 0; + } +@@ -476,7 +484,7 @@ + encode_mb_skip_run(s, s->mb_skip_run); + } + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + if(s->dquant && cbp){ + put_mb_modes(s, 2, 1, 0, 0); /* macroblock_type : macroblock_quant = 1 */ + put_qscale(s); +@@ -497,7 +505,7 @@ + s->misc_bits+= get_bits_diff(s); + s->i_count++; + memset(s->last_mv, 0, sizeof(s->last_mv)); +- } else if (s->pict_type == FF_P_TYPE) { ++ } else if (s->pict_type == AV_PICTURE_TYPE_P) { + if(s->mv_type == MV_TYPE_16X16){ + if (cbp != 0) { + if ((motion_x|motion_y) == 0) { +@@ -681,8 +689,7 @@ + int bit_size = f_or_b_code - 1; + int range = 1 << bit_size; + /* modulo encoding */ +- int l= INT_BIT - 5 - bit_size; +- val= (val<>l; ++ val = sign_extend(val, 5 + bit_size); + + if (val >= 0) { + val--; +@@ -761,10 +768,9 @@ + + if(mv==0) len= ff_mpeg12_mbMotionVectorTable[0][1]; + else{ +- int val, bit_size, range, code; ++ int val, bit_size, code; + + bit_size = f_code - 1; +- range = 1 << bit_size; + + val=mv; + if (val < 0) +@@ -888,10 +894,6 @@ + j = s->intra_scantable.permutated[i]; + level = block[j]; + next_coef: +-#if 0 +- if (level != 0) +- av_dlog(s->avctx, "level[%d]=%d\n", i, level); +-#endif + /* encode using VLC */ + if (level != 0) { + run = i - last_non_zero - 1; +@@ -930,30 +932,64 @@ + put_bits(&s->pb, table_vlc[112][1], table_vlc[112][0]); + } + ++#define OFFSET(x) offsetof(MpegEncContext, x) ++#define VE AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM ++#define COMMON_OPTS\ ++ {TIMECODE_OPT(MpegEncContext,\ ++ AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)},\ ++ { "intra_vlc", "Use MPEG-2 intra VLC table.", OFFSET(intra_vlc_format), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE },\ ++ { "drop_frame_timecode", "Timecode is in drop frame format.", OFFSET(drop_frame_timecode), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, \ ++ { "scan_offset", "Reserve space for SVCD scan offset user data.", OFFSET(scan_offset), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ ++static const AVOption mpeg1_options[] = { ++ COMMON_OPTS ++ { NULL }, ++}; ++ ++static const AVOption mpeg2_options[] = { ++ COMMON_OPTS ++ { "non_linear_quant", "Use nonlinear quantizer.", OFFSET(q_scale_type), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { NULL }, ++}; ++ ++#define mpeg12_class(x)\ ++static const AVClass mpeg## x ##_class = {\ ++ .class_name = "mpeg" #x "video encoder",\ ++ .item_name = av_default_item_name,\ ++ .option = mpeg## x ##_options,\ ++ .version = LIBAVUTIL_VERSION_INT,\ ++}; ++ ++mpeg12_class(1) ++mpeg12_class(2) ++ + AVCodec ff_mpeg1video_encoder = { +- "mpeg1video", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG1VIDEO, +- sizeof(MpegEncContext), +- encode_init, +- MPV_encode_picture, +- MPV_encode_end, +- .supported_framerates= ff_frame_rate_tab+1, ++ .name = "mpeg1video", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG1VIDEO, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, ++ .supported_framerates= avpriv_frame_rate_tab+1, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .capabilities= CODEC_CAP_DELAY, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), ++ .priv_class = &mpeg1_class, + }; + + AVCodec ff_mpeg2video_encoder = { +- "mpeg2video", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG2VIDEO, +- sizeof(MpegEncContext), +- encode_init, +- MPV_encode_picture, +- MPV_encode_end, +- .supported_framerates= ff_frame_rate_tab+1, ++ .name = "mpeg2video", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, ++ .supported_framerates= avpriv_frame_rate_tab+1, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_NONE}, +- .capabilities= CODEC_CAP_DELAY, ++ .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-2 video"), ++ .priv_class = &mpeg2_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg12.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg12.h 2012-05-14 14:08:54.004333340 +0200 +@@ -30,6 +30,20 @@ + extern VLC ff_dc_lum_vlc; + extern VLC ff_dc_chroma_vlc; + ++typedef struct Mpeg1Context { ++ MpegEncContext mpeg_enc_ctx; ++ int mpeg_enc_ctx_allocated; /* true if decoding context allocated */ ++ int repeat_field; /* true if we must repeat the field */ ++ AVPanScan pan_scan; /**< some temporary storage for the panscan */ ++ int slice_count; ++ int swap_uv;//indicate VCR2 ++ int save_aspect_info; ++ int save_width, save_height, save_progressive_seq; ++ AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator ++ int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame? ++ int tmpgexs; ++} Mpeg1Context; ++ + extern uint8_t ff_mpeg12_static_rl_table_store[2][2][2*MAX_RUN + MAX_LEVEL + 3]; + + void ff_mpeg12_common_init(MpegEncContext *s); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4audio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4audio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4audio.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4audio.c 2012-05-14 14:08:54.009333440 +0200 +@@ -52,7 +52,7 @@ + return 0; + } + +-const int ff_mpeg4audio_sample_rates[16] = { ++const int avpriv_mpeg4audio_sample_rates[16] = { + 96000, 88200, 64000, 48000, 44100, 32000, + 24000, 22050, 16000, 12000, 11025, 8000, 7350 + }; +@@ -73,15 +73,19 @@ + { + *index = get_bits(gb, 4); + return *index == 0x0f ? get_bits(gb, 24) : +- ff_mpeg4audio_sample_rates[*index]; ++ avpriv_mpeg4audio_sample_rates[*index]; + } + +-int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size) ++int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, ++ int bit_size, int sync_extension) + { + GetBitContext gb; + int specific_config_bitindex; + +- init_get_bits(&gb, buf, buf_size*8); ++ if(bit_size<=0) ++ return AVERROR_INVALIDDATA; ++ ++ init_get_bits(&gb, buf, bit_size); + c->object_type = get_object_type(&gb); + c->sample_rate = get_sample_rate(&gb, &c->sampling_index); + c->chan_config = get_bits(&gb, 4); +@@ -117,7 +121,7 @@ + return -1; + } + +- if (c->ext_object_type != AOT_SBR) { ++ if (c->ext_object_type != AOT_SBR && sync_extension) { + while (get_bits_left(&gb) > 15) { + if (show_bits(&gb, 11) == 0x2b7) { // sync extension + get_bits(&gb, 11); +@@ -151,7 +155,7 @@ + return el; + } + +-int ff_copy_pce_data(PutBitContext *pb, GetBitContext *gb) ++int avpriv_copy_pce_data(PutBitContext *pb, GetBitContext *gb) + { + int five_bit_ch, four_bit_ch, comment_size, bits; + int offset = put_bits_count(pb); +@@ -173,7 +177,7 @@ + copy_bits(pb, gb, 16); + if (bits) + copy_bits(pb, gb, bits); +- align_put_bits(pb); ++ avpriv_align_put_bits(pb); + align_get_bits(gb); + comment_size = copy_bits(pb, gb, 8); + for (; comment_size > 0; comment_size--) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4audio.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4audio.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4audio.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4audio.h 2012-05-14 14:08:54.009333440 +0200 +@@ -31,25 +31,28 @@ + int sampling_index; + int sample_rate; + int chan_config; +- int sbr; //< -1 implicit, 1 presence ++ int sbr; ///< -1 implicit, 1 presence + int ext_object_type; + int ext_sampling_index; + int ext_sample_rate; + int ext_chan_config; + int channels; +- int ps; //< -1 implicit, 1 presence ++ int ps; ///< -1 implicit, 1 presence + } MPEG4AudioConfig; + +-extern const int ff_mpeg4audio_sample_rates[16]; ++extern const int avpriv_mpeg4audio_sample_rates[16]; + extern const uint8_t ff_mpeg4audio_channels[8]; ++ + /** + * Parse MPEG-4 systems extradata to retrieve audio configuration. + * @param[in] c MPEG4AudioConfig structure to fill. + * @param[in] buf Extradata from container. +- * @param[in] buf_size Extradata size. ++ * @param[in] bit_size Extradata size in bits. ++ * @param[in] sync_extension look for a sync extension after config if true. + * @return On error -1 is returned, on success AudioSpecificConfig bit index in extradata. + */ +-int ff_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, int buf_size); ++int avpriv_mpeg4audio_get_config(MPEG4AudioConfig *c, const uint8_t *buf, ++ int bit_size, int sync_extension); + + enum AudioObjectType { + AOT_NULL, +@@ -57,7 +60,7 @@ + AOT_AAC_MAIN, ///< Y Main + AOT_AAC_LC, ///< Y Low Complexity + AOT_AAC_SSR, ///< N (code in SoC repo) Scalable Sample Rate +- AOT_AAC_LTP, ///< N (code in SoC repo) Long Term Prediction ++ AOT_AAC_LTP, ///< Y Long Term Prediction + AOT_SBR, ///< Y Spectral Band Replication + AOT_AAC_SCALABLE, ///< N Scalable + AOT_TWINVQ, ///< N Twin Vector Quantizer +@@ -101,6 +104,6 @@ + #define MAX_PCE_SIZE 304 ///pict_type){ +- case FF_I_TYPE: ++ case AV_PICTURE_TYPE_I: + return 16; +- case FF_P_TYPE: +- case FF_S_TYPE: ++ case AV_PICTURE_TYPE_P: ++ case AV_PICTURE_TYPE_S: + return s->f_code+15; +- case FF_B_TYPE: ++ case AV_PICTURE_TYPE_B: + return FFMAX3(s->f_code, s->b_code, 2) + 15; + default: + return -1; +@@ -89,7 +89,7 @@ + uint16_t time_pb= s->pb_time; + int p_mx, p_my; + +- p_mx= s->next_picture.motion_val[0][xy][0]; ++ p_mx = s->next_picture.f.motion_val[0][xy][0]; + if((unsigned)(p_mx + tab_bias) < tab_size){ + s->mv[0][i][0] = s->direct_scale_mv[0][p_mx + tab_bias] + mx; + s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx +@@ -99,7 +99,7 @@ + s->mv[1][i][0] = mx ? s->mv[0][i][0] - p_mx + : p_mx*(time_pb - time_pp)/time_pp; + } +- p_my= s->next_picture.motion_val[0][xy][1]; ++ p_my = s->next_picture.f.motion_val[0][xy][1]; + if((unsigned)(p_my + tab_bias) < tab_size){ + s->mv[0][i][1] = s->direct_scale_mv[0][p_my + tab_bias] + my; + s->mv[1][i][1] = my ? s->mv[0][i][1] - p_my +@@ -120,7 +120,7 @@ + */ + int ff_mpeg4_set_direct_mv(MpegEncContext *s, int mx, int my){ + const int mb_index= s->mb_x + s->mb_y*s->mb_stride; +- const int colocated_mb_type= s->next_picture.mb_type[mb_index]; ++ const int colocated_mb_type = s->next_picture.f.mb_type[mb_index]; + uint16_t time_pp; + uint16_t time_pb; + int i; +@@ -137,7 +137,7 @@ + } else if(IS_INTERLACED(colocated_mb_type)){ + s->mv_type = MV_TYPE_FIELD; + for(i=0; i<2; i++){ +- int field_select= s->next_picture.ref_index[0][4*mb_index + 2*i]; ++ int field_select = s->next_picture.f.ref_index[0][4 * mb_index + 2 * i]; + s->field_select[0][i]= field_select; + s->field_select[1][i]= i; + if(s->top_field_first){ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4videodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4videodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4videodec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4videodec.c 2012-05-14 14:08:54.018333622 +0200 +@@ -20,9 +20,13 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ ++#include "libavutil/opt.h" + #include "mpegvideo.h" + #include "mpeg4video.h" + #include "h263.h" ++#include "thread.h" + + // The defines below define the number of bits that are read at once for + // reading vlc values. Changing these may improve speed and data cache needs +@@ -45,7 +49,7 @@ + }; + + /** +- * predicts the ac. ++ * Predict the ac. + * @param n block index (0-3 are luma, 4-5 are chroma) + * @param dir the ac prediction direction + */ +@@ -54,7 +58,7 @@ + { + int i; + int16_t *ac_val, *ac_val1; +- int8_t * const qscale_table= s->current_picture.qscale_table; ++ int8_t * const qscale_table = s->current_picture.f.qscale_table; + + /* find prediction */ + ac_val = s->ac_val[0][0] + s->block_index[n] * 16; +@@ -112,12 +116,12 @@ + int bits_count= get_bits_count(&s->gb); + int v= show_bits(&s->gb, 16); + +- if(s->workaround_bugs&FF_BUG_NO_PADDING){ ++ if(s->workaround_bugs&FF_BUG_NO_PADDING && !s->resync_marker){ + return 0; + } + + while(v<=0xFF){ +- if(s->pict_type==FF_B_TYPE || (v>>(8-s->pict_type)!=1) || s->partitioned_frame) ++ if(s->pict_type==AV_PICTURE_TYPE_B || (v>>(8-s->pict_type)!=1) || s->partitioned_frame) + break; + skip_bits(&s->gb, 8+s->pict_type); + bits_count+= 8+s->pict_type; +@@ -129,10 +133,11 @@ + v|= 0x7F >> (7-(bits_count&7)); + + if(v==0x7F) +- return 1; ++ return s->mb_num; + }else{ + if(v == ff_mpeg4_resync_prefix[bits_count&7]){ +- int len; ++ int len, mb_num; ++ int mb_num_bits= av_log2(s->mb_num - 1) + 1; + GetBitContext gb= s->gb; + + skip_bits(&s->gb, 1); +@@ -142,16 +147,20 @@ + if(get_bits1(&s->gb)) break; + } + ++ mb_num= get_bits(&s->gb, mb_num_bits); ++ if(!mb_num || mb_num > s->mb_num || get_bits_count(&s->gb)+6 > s->gb.size_in_bits) ++ mb_num= -1; ++ + s->gb= gb; + + if(len>=ff_mpeg4_get_video_packet_prefix_length(s)) +- return 1; ++ return mb_num; + } + } + return 0; + } + +-static void mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) ++static int mpeg4_decode_sprite_trajectory(MpegEncContext * s, GetBitContext *gb) + { + int i; + int a= 2<sprite_warping_accuracy; +@@ -167,6 +176,9 @@ + int h= s->height; + int min_ab; + ++ if(w<=0 || h<=0) ++ return -1; ++ + for(i=0; inum_sprite_warping_points; i++){ + int length; + int x=0, y=0; +@@ -339,10 +351,11 @@ + } + s->real_sprite_warping_points= s->num_sprite_warping_points; + } ++ return 0; + } + + /** +- * decodes the next video packet. ++ * Decode the next video packet. + * @return <0 if something went wrong + */ + int mpeg4_decode_video_packet_header(MpegEncContext *s) +@@ -372,10 +385,6 @@ + av_log(s->avctx, AV_LOG_ERROR, "illegal mb_num in video packet (%d %d) \n", mb_num, s->mb_num); + return -1; + } +- if(s->pict_type == FF_B_TYPE){ +- while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++; +- if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded +- } + + s->mb_x= mb_num % s->mb_width; + s->mb_y= mb_num / s->mb_width; +@@ -390,14 +399,13 @@ + header_extension= get_bits1(&s->gb); + } + if(header_extension){ +- int time_increment; + int time_incr=0; + + while (get_bits1(&s->gb) != 0) + time_incr++; + + check_marker(&s->gb, "before time_increment in video packed header"); +- time_increment= get_bits(&s->gb, s->time_increment_bits); ++ skip_bits(&s->gb, s->time_increment_bits); /* time_increment */ + check_marker(&s->gb, "before vop_coding_type in video packed header"); + + skip_bits(&s->gb, 2); /* vop coding type */ +@@ -406,20 +414,21 @@ + if(s->shape != BIN_ONLY_SHAPE){ + skip_bits(&s->gb, 3); /* intra dc vlc threshold */ + //FIXME don't just ignore everything +- if(s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ +- mpeg4_decode_sprite_trajectory(s, &s->gb); ++ if(s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){ ++ if(mpeg4_decode_sprite_trajectory(s, &s->gb) < 0) ++ return -1; + av_log(s->avctx, AV_LOG_ERROR, "untested\n"); + } + + //FIXME reduced res stuff here + +- if (s->pict_type != FF_I_TYPE) { ++ if (s->pict_type != AV_PICTURE_TYPE_I) { + int f_code = get_bits(&s->gb, 3); /* fcode_for */ + if(f_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (f_code=0)\n"); + } + } +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + int b_code = get_bits(&s->gb, 3); + if(b_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, video packet header damaged (b_code=0)\n"); +@@ -433,7 +442,7 @@ + } + + /** +- * gets the average motion vector for a GMC MB. ++ * Get the average motion vector for a GMC MB. + * @param n either 0 for the x component or 1 for y + * @return the average MV for a GMC MB + */ +@@ -479,7 +488,7 @@ + } + + /** +- * decodes the dc value. ++ * Decode the dc value. + * @param n block index (0-3 are luma, 4-5 are chroma) + * @param dir_ptr the prediction direction will be stored here + * @return the quantized dc +@@ -514,7 +523,7 @@ + + if (code > 8){ + if(get_bits1(&s->gb)==0){ /* marker */ +- if(s->error_recognition>=2){ ++ if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT)){ + av_log(s->avctx, AV_LOG_ERROR, "dc marker bit missing\n"); + return -1; + } +@@ -526,7 +535,7 @@ + } + + /** +- * decodes first partition. ++ * Decode first partition. + * @return number of MBs decoded or <0 if an error occurred + */ + static int mpeg4_decode_partition_a(MpegEncContext *s){ +@@ -548,7 +557,7 @@ + if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) + s->first_slice_line=0; + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + int i; + + do{ +@@ -564,13 +573,13 @@ + }while(cbpc == 8); + + s->cbp_table[xy]= cbpc & 3; +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + s->mb_intra = 1; + + if(cbpc & 4) { + ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); + } +- s->current_picture.qscale_table[xy]= s->qscale; ++ s->current_picture.f.qscale_table[xy]= s->qscale; + + s->mbintra_table[xy]= 1; + for(i=0; i<6; i++){ +@@ -586,7 +595,7 @@ + s->pred_dir_table[xy]= dir; + }else{ /* P/S_TYPE */ + int mx, my, pred_x, pred_y, bits; +- int16_t * const mot_val= s->current_picture.motion_val[0][s->block_index[0]]; ++ int16_t * const mot_val = s->current_picture.f.motion_val[0][s->block_index[0]]; + const int stride= s->b8_stride*2; + + try_again: +@@ -597,12 +606,12 @@ + skip_bits1(&s->gb); + if(bits&0x10000){ + /* skip mb */ +- if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; ++ if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){ ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; + mx= get_amv(s, 0); + my= get_amv(s, 1); + }else{ +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + mx=my=0; + } + mot_val[0 ]= mot_val[2 ]= +@@ -628,7 +637,7 @@ + s->mb_intra = ((cbpc & 4) != 0); + + if(s->mb_intra){ +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + s->mbintra_table[xy]= 1; + mot_val[0 ]= mot_val[2 ]= + mot_val[0+stride]= mot_val[2+stride]= 0; +@@ -638,7 +647,7 @@ + if(s->mbintra_table[xy]) + ff_clean_intra_table_entries(s); + +- if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) ++ if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) + s->mcsel= get_bits1(&s->gb); + else s->mcsel= 0; + +@@ -654,11 +663,11 @@ + my = h263_decode_motion(s, pred_y, s->f_code); + if (my >= 0xffff) + return -1; +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; + } else { + mx = get_amv(s, 0); + my = get_amv(s, 1); +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_GMC | MB_TYPE_L0; + } + + mot_val[0 ]= mot_val[2 ] = +@@ -667,7 +676,7 @@ + mot_val[1+stride]= mot_val[3+stride]= my; + } else { + int i; +- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; + for(i=0;i<4;i++) { + int16_t *mot_val= h263_pred_motion(s, i, 0, &pred_x, &pred_y); + mx = h263_decode_motion(s, pred_x, s->f_code); +@@ -710,7 +719,7 @@ + if(s->mb_x == s->resync_mb_x && s->mb_y == s->resync_mb_y+1) + s->first_slice_line=0; + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + int ac_pred= get_bits1(&s->gb); + int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ +@@ -719,9 +728,9 @@ + } + + s->cbp_table[xy]|= cbpy<<2; +- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; ++ s->current_picture.f.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; + }else{ /* P || S_TYPE */ +- if(IS_INTRA(s->current_picture.mb_type[xy])){ ++ if (IS_INTRA(s->current_picture.f.mb_type[xy])) { + int dir=0,i; + int ac_pred = get_bits1(&s->gb); + int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); +@@ -734,7 +743,7 @@ + if(s->cbp_table[xy] & 8) { + ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); + } +- s->current_picture.qscale_table[xy]= s->qscale; ++ s->current_picture.f.qscale_table[xy] = s->qscale; + + for(i=0; i<6; i++){ + int dc_pred_dir; +@@ -748,10 +757,10 @@ + } + s->cbp_table[xy]&= 3; //remove dquant + s->cbp_table[xy]|= cbpy<<2; +- s->current_picture.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; ++ s->current_picture.f.mb_type[xy] |= ac_pred*MB_TYPE_ACPRED; + s->pred_dir_table[xy]= dir; +- }else if(IS_SKIP(s->current_picture.mb_type[xy])){ +- s->current_picture.qscale_table[xy]= s->qscale; ++ } else if (IS_SKIP(s->current_picture.f.mb_type[xy])) { ++ s->current_picture.f.qscale_table[xy] = s->qscale; + s->cbp_table[xy]= 0; + }else{ + int cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); +@@ -764,7 +773,7 @@ + if(s->cbp_table[xy] & 8) { + ff_set_qscale(s, s->qscale + quant_tab[get_bits(&s->gb, 2)]); + } +- s->current_picture.qscale_table[xy]= s->qscale; ++ s->current_picture.f.qscale_table[xy] = s->qscale; + + s->cbp_table[xy]&= 3; //remove dquant + s->cbp_table[xy]|= (cbpy^0xf)<<2; +@@ -778,14 +787,14 @@ + } + + /** +- * decodes the first & second partition ++ * Decode the first and second partition. + * @return <0 if error (and sets error type in the error_status_table) + */ + int ff_mpeg4_decode_partitions(MpegEncContext *s) + { + int mb_num; +- const int part_a_error= s->pict_type==FF_I_TYPE ? (DC_ERROR|MV_ERROR) : MV_ERROR; +- const int part_a_end = s->pict_type==FF_I_TYPE ? (DC_END |MV_END) : MV_END; ++ const int part_a_error= s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_ERROR|ER_MV_ERROR) : ER_MV_ERROR; ++ const int part_a_end = s->pict_type==AV_PICTURE_TYPE_I ? (ER_DC_END |ER_MV_END) : ER_MV_END; + + mb_num= mpeg4_decode_partition_a(s); + if(mb_num<0){ +@@ -801,7 +810,7 @@ + + s->mb_num_left= mb_num; + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + while(show_bits(&s->gb, 9) == 1) + skip_bits(&s->gb, 9); + if(get_bits_long(&s->gb, 19)!=DC_MARKER){ +@@ -819,19 +828,19 @@ + ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, part_a_end); + + if( mpeg4_decode_partition_b(s, mb_num) < 0){ +- if(s->pict_type==FF_P_TYPE) +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, DC_ERROR); ++ if(s->pict_type==AV_PICTURE_TYPE_P) ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_DC_ERROR); + return -1; + }else{ +- if(s->pict_type==FF_P_TYPE) +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, DC_END); ++ if(s->pict_type==AV_PICTURE_TYPE_P) ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_DC_END); + } + + return 0; + } + + /** +- * decodes a block. ++ * Decode a block. + * @return <0 if an error occurred + */ + static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, +@@ -928,7 +937,7 @@ + }; SKIP_CACHE(re, &s->gb, 1); + + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); +- run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); ++ run= SHOW_UBITS(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 1+1+6); + UPDATE_CACHE(re, &s->gb); + +@@ -945,7 +954,7 @@ + }; SKIP_CACHE(re, &s->gb, 5); + + level= level * qmul + qadd; +- level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); LAST_SKIP_CACHE(re, &s->gb, 1); ++ level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + SKIP_COUNTER(re, &s->gb, 1+11+5+1); + + i+= run + 1; +@@ -962,7 +971,7 @@ + /* third escape */ + SKIP_CACHE(re, &s->gb, 2); + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); +- run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); ++ run= SHOW_UBITS(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 2+1+6); + UPDATE_CACHE(re, &s->gb); + +@@ -979,7 +988,7 @@ + if(SHOW_UBITS(re, &s->gb, 1)==0){ + av_log(s->avctx, AV_LOG_ERROR, "2. marker bit missing in 3. esc\n"); + return -1; +- }; LAST_SKIP_CACHE(re, &s->gb, 1); ++ } + + SKIP_COUNTER(re, &s->gb, 1+12+1); + } +@@ -1010,7 +1019,7 @@ + else level= level * qmul - qadd; + + if((unsigned)(level + 2048) > 4095){ +- if(s->error_recognition > FF_ER_COMPLIANT){ ++ if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)){ + if(level > 2560 || level<-2560){ + av_log(s->avctx, AV_LOG_ERROR, "|level| overflow in 3. esc, qp=%d\n", s->qscale); + return -1; +@@ -1085,20 +1094,20 @@ + int cbp, mb_type; + const int xy= s->mb_x + s->mb_y*s->mb_stride; + +- mb_type= s->current_picture.mb_type[xy]; ++ mb_type = s->current_picture.f.mb_type[xy]; + cbp = s->cbp_table[xy]; + + s->use_intra_dc_vlc= s->qscale < s->intra_dc_threshold; + +- if(s->current_picture.qscale_table[xy] != s->qscale){ +- ff_set_qscale(s, s->current_picture.qscale_table[xy] ); ++ if (s->current_picture.f.qscale_table[xy] != s->qscale) { ++ ff_set_qscale(s, s->current_picture.f.qscale_table[xy]); + } + +- if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) { + int i; + for(i=0; i<4; i++){ +- s->mv[0][i][0] = s->current_picture.motion_val[0][ s->block_index[i] ][0]; +- s->mv[0][i][1] = s->current_picture.motion_val[0][ s->block_index[i] ][1]; ++ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0]; ++ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1]; + } + s->mb_intra = IS_INTRA(mb_type); + +@@ -1108,7 +1117,7 @@ + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; +- if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ ++ if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){ + s->mcsel=1; + s->mb_skipped = 0; + }else{ +@@ -1116,7 +1125,7 @@ + s->mb_skipped = 1; + } + }else if(s->mb_intra){ +- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); ++ s->ac_pred = IS_ACPRED(s->current_picture.f.mb_type[xy]); + }else if(!s->mb_intra){ + // s->mcsel= 0; //FIXME do we need to init that + +@@ -1129,7 +1138,7 @@ + } + } else { /* I-Frame */ + s->mb_intra = 1; +- s->ac_pred = IS_ACPRED(s->current_picture.mb_type[xy]); ++ s->ac_pred = IS_ACPRED(s->current_picture.f.mb_type[xy]); + } + + if (!IS_SKIP(mb_type)) { +@@ -1172,7 +1181,7 @@ + + assert(s->h263_pred); + +- if (s->pict_type == FF_P_TYPE || s->pict_type==FF_S_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) { + do{ + if (get_bits1(&s->gb)) { + /* skip mb */ +@@ -1181,15 +1190,15 @@ + s->block_last_index[i] = -1; + s->mv_dir = MV_DIR_FORWARD; + s->mv_type = MV_TYPE_16X16; +- if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE){ +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; ++ if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE){ ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; + s->mcsel=1; + s->mv[0][0][0]= get_amv(s, 0); + s->mv[0][0][1]= get_amv(s, 1); + + s->mb_skipped = 0; + }else{ +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + s->mcsel=0; + s->mv[0][0][0] = 0; + s->mv[0][0][1] = 0; +@@ -1209,7 +1218,7 @@ + s->mb_intra = ((cbpc & 4) != 0); + if (s->mb_intra) goto intra; + +- if(s->pict_type==FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) ++ if(s->pict_type==AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) + s->mcsel= get_bits1(&s->gb); + else s->mcsel= 0; + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1) ^ 0x0F; +@@ -1224,7 +1233,7 @@ + s->mv_dir = MV_DIR_FORWARD; + if ((cbpc & 16) == 0) { + if(s->mcsel){ +- s->current_picture.mb_type[xy]= MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_GMC | MB_TYPE_16x16 | MB_TYPE_L0; + /* 16x16 global motion prediction */ + s->mv_type = MV_TYPE_16X16; + mx= get_amv(s, 0); +@@ -1232,7 +1241,7 @@ + s->mv[0][0][0] = mx; + s->mv[0][0][1] = my; + }else if((!s->progressive_sequence) && get_bits1(&s->gb)){ +- s->current_picture.mb_type[xy]= MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x8 | MB_TYPE_L0 | MB_TYPE_INTERLACED; + /* 16x8 field motion prediction */ + s->mv_type= MV_TYPE_FIELD; + +@@ -1254,7 +1263,7 @@ + s->mv[0][i][1] = my; + } + }else{ +- s->current_picture.mb_type[xy]= MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_16x16 | MB_TYPE_L0; + /* 16x16 motion prediction */ + s->mv_type = MV_TYPE_16X16; + h263_pred_motion(s, 0, 0, &pred_x, &pred_y); +@@ -1271,7 +1280,7 @@ + s->mv[0][0][1] = my; + } + } else { +- s->current_picture.mb_type[xy]= MB_TYPE_8x8 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_8x8 | MB_TYPE_L0; + s->mv_type = MV_TYPE_8X8; + for(i=0;i<4;i++) { + mot_val = h263_pred_motion(s, i, 0, &pred_x, &pred_y); +@@ -1288,7 +1297,7 @@ + mot_val[1] = my; + } + } +- } else if(s->pict_type==FF_B_TYPE) { ++ } else if(s->pict_type==AV_PICTURE_TYPE_B) { + int modb1; // first bit of modb + int modb2; // second bit of modb + int mb_type; +@@ -1303,10 +1312,12 @@ + s->last_mv[i][1][0]= + s->last_mv[i][1][1]= 0; + } ++ ++ ff_thread_await_progress((AVFrame*)s->next_picture_ptr, s->mb_y, 0); + } + + /* if we skipped it in the future P Frame than skip it now too */ +- s->mb_skipped= s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC ++ s->mb_skipped = s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]; // Note, skiptab=0 if last was GMC + + if(s->mb_skipped){ + /* skip mb */ +@@ -1319,7 +1330,7 @@ + s->mv[0][0][1] = 0; + s->mv[1][0][0] = 0; + s->mv[1][0][1] = 0; +- s->current_picture.mb_type[xy]= MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_SKIP | MB_TYPE_16x16 | MB_TYPE_L0; + goto end; + } + +@@ -1425,7 +1436,7 @@ + s->mv_dir = MV_DIR_FORWARD | MV_DIR_BACKWARD | MV_DIRECT; + mb_type |= ff_mpeg4_set_direct_mv(s, mx, my); + } +- s->current_picture.mb_type[xy]= mb_type; ++ s->current_picture.f.mb_type[xy] = mb_type; + } else { /* I-Frame */ + do{ + cbpc = get_vlc2(&s->gb, ff_h263_intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 2); +@@ -1440,9 +1451,9 @@ + intra: + s->ac_pred = get_bits1(&s->gb); + if(s->ac_pred) +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA | MB_TYPE_ACPRED; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA | MB_TYPE_ACPRED; + else +- s->current_picture.mb_type[xy]= MB_TYPE_INTRA; ++ s->current_picture.f.mb_type[xy] = MB_TYPE_INTRA; + + cbpy = get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1); + if(cbpy<0){ +@@ -1480,10 +1491,21 @@ + + /* per-MB end of slice check */ + if(s->codec_id==CODEC_ID_MPEG4){ +- if(mpeg4_is_resync(s)){ +- const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; +- if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta]) +- return SLICE_OK; ++ int next= mpeg4_is_resync(s); ++ if(next) { ++ if (s->mb_x + s->mb_y*s->mb_width + 1 > next && s->avctx->error_recognition >= FF_ER_AGGRESSIVE) { ++ return -1; ++ } else if (s->mb_x + s->mb_y*s->mb_width + 1 >= next) ++ return SLICE_END; ++ ++ if(s->pict_type==AV_PICTURE_TYPE_B){ ++ const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; ++ ff_thread_await_progress((AVFrame*)s->next_picture_ptr, ++ (s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0); ++ if (s->next_picture.f.mbskip_table[xy + delta]) ++ return SLICE_OK; ++ } ++ + return SLICE_END; + } + } +@@ -1495,6 +1517,11 @@ + static int mpeg4_decode_gop_header(MpegEncContext * s, GetBitContext *gb){ + int hours, minutes, seconds; + ++ if(!show_bits(gb, 23)){ ++ av_log(s->avctx, AV_LOG_WARNING, "GOP header invalid\n"); ++ return -1; ++ } ++ + hours= get_bits(gb, 5); + minutes= get_bits(gb, 6); + skip_bits1(gb); +@@ -1508,6 +1535,19 @@ + return 0; + } + ++static int mpeg4_decode_profile_level(MpegEncContext * s, GetBitContext *gb){ ++ ++ s->avctx->profile = get_bits(gb, 4); ++ s->avctx->level = get_bits(gb, 4); ++ ++ // for Simple profile, level 0 ++ if (s->avctx->profile == 0 && s->avctx->level == 8) { ++ s->avctx->level = 0; ++ } ++ ++ return 0; ++} ++ + static int decode_vol_header(MpegEncContext *s, GetBitContext *gb){ + int width, height, vo_ver_id; + +@@ -1785,16 +1825,14 @@ + + if (s->scalability) { + GetBitContext bak= *gb; +- int ref_layer_id; +- int ref_layer_sampling_dir; + int h_sampling_factor_n; + int h_sampling_factor_m; + int v_sampling_factor_n; + int v_sampling_factor_m; + + s->hierachy_type= get_bits1(gb); +- ref_layer_id= get_bits(gb, 4); +- ref_layer_sampling_dir= get_bits1(gb); ++ skip_bits(gb, 4); /* ref_layer_id */ ++ skip_bits1(gb); /* ref_layer_sampling_dir */ + h_sampling_factor_n= get_bits(gb, 5); + h_sampling_factor_m= get_bits(gb, 5); + v_sampling_factor_n= get_bits(gb, 5); +@@ -1817,7 +1855,7 @@ + } + + /** +- * decodes the user data stuff in the header. ++ * Decode the user data stuff in the header. + * Also initializes divx/xvid/lavc_version/build. + */ + static int decode_user_data(MpegEncContext *s, GetBitContext *gb){ +@@ -1847,7 +1885,7 @@ + } + } + +- /* ffmpeg detection */ ++ /* libavcodec detection */ + e=sscanf(buf, "FFmpe%*[^b]b%d", &build)+3; + if(e!=4) + e=sscanf(buf, "FFmpeg v%d.%d.%d / libavcodec build: %d", &ver, &ver2, &ver3, &build); +@@ -1877,13 +1915,13 @@ + static int decode_vop_header(MpegEncContext *s, GetBitContext *gb){ + int time_incr, time_increment; + +- s->pict_type = get_bits(gb, 2) + FF_I_TYPE; /* pict type: I = 0 , P = 1 */ +- if(s->pict_type==FF_B_TYPE && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){ ++ s->pict_type = get_bits(gb, 2) + AV_PICTURE_TYPE_I; /* pict type: I = 0 , P = 1 */ ++ if(s->pict_type==AV_PICTURE_TYPE_B && s->low_delay && s->vol_control_parameters==0 && !(s->flags & CODEC_FLAG_LOW_DELAY)){ + av_log(s->avctx, AV_LOG_ERROR, "low_delay flag incorrectly, clearing it\n"); + s->low_delay=0; + } + +- s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; ++ s->partitioned_frame= s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B; + if(s->partitioned_frame) + s->decode_mb= mpeg4_decode_partitioned_mb; + else +@@ -1899,8 +1937,8 @@ + av_log(s->avctx, AV_LOG_ERROR, "hmm, seems the headers are not complete, trying to guess time_increment_bits\n"); + + for(s->time_increment_bits=1 ;s->time_increment_bits<16; s->time_increment_bits++){ +- if ( s->pict_type == FF_P_TYPE +- || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { ++ if ( s->pict_type == AV_PICTURE_TYPE_P ++ || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE)) { + if((show_bits(gb, s->time_increment_bits+6)&0x37) == 0x30) break; + }else + if((show_bits(gb, s->time_increment_bits+5)&0x1F) == 0x18) break; +@@ -1912,7 +1950,7 @@ + if(IS_3IV1) time_increment= get_bits1(gb); //FIXME investigate further + else time_increment= get_bits(gb, s->time_increment_bits); + +- if(s->pict_type!=FF_B_TYPE){ ++ if(s->pict_type!=AV_PICTURE_TYPE_B){ + s->last_time_base= s->time_base; + s->time_base+= time_incr; + s->time= s->time_base*s->avctx->time_base.den + time_increment; +@@ -1948,11 +1986,12 @@ + } + + if(s->avctx->time_base.num) +- s->current_picture_ptr->pts= (s->time + s->avctx->time_base.num/2) / s->avctx->time_base.num; ++ s->current_picture_ptr->f.pts = (s->time + s->avctx->time_base.num / 2) / s->avctx->time_base.num; + else +- s->current_picture_ptr->pts= AV_NOPTS_VALUE; ++ s->current_picture_ptr->f.pts = AV_NOPTS_VALUE; + if(s->avctx->debug&FF_DEBUG_PTS) +- av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", s->current_picture_ptr->pts); ++ av_log(s->avctx, AV_LOG_DEBUG, "MPEG4 PTS: %"PRId64"\n", ++ s->current_picture_ptr->f.pts); + + check_marker(gb, "before vop_coded"); + +@@ -1962,8 +2001,8 @@ + av_log(s->avctx, AV_LOG_ERROR, "vop not coded\n"); + return FRAME_SKIPPED; + } +- if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == FF_P_TYPE +- || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE))) { ++ if (s->shape != BIN_ONLY_SHAPE && ( s->pict_type == AV_PICTURE_TYPE_P ++ || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE))) { + /* rounding type for motion estimation */ + s->no_rounding = get_bits1(gb); + } else { +@@ -1972,16 +2011,14 @@ + //FIXME reduced res stuff + + if (s->shape != RECT_SHAPE) { +- if (s->vol_sprite_usage != 1 || s->pict_type != FF_I_TYPE) { +- int width, height, hor_spat_ref, ver_spat_ref; +- +- width = get_bits(gb, 13); ++ if (s->vol_sprite_usage != 1 || s->pict_type != AV_PICTURE_TYPE_I) { ++ skip_bits(gb, 13); /* width */ + skip_bits1(gb); /* marker */ +- height = get_bits(gb, 13); ++ skip_bits(gb, 13); /* height */ + skip_bits1(gb); /* marker */ +- hor_spat_ref = get_bits(gb, 13); /* hor_spat_ref */ ++ skip_bits(gb, 13); /* hor_spat_ref */ + skip_bits1(gb); /* marker */ +- ver_spat_ref = get_bits(gb, 13); /* ver_spat_ref */ ++ skip_bits(gb, 13); /* ver_spat_ref */ + } + skip_bits1(gb); /* change_CR_disable */ + +@@ -1993,9 +2030,9 @@ + + if (s->shape != BIN_ONLY_SHAPE) { + skip_bits_long(gb, s->cplx_estimation_trash_i); +- if(s->pict_type != FF_I_TYPE) ++ if(s->pict_type != AV_PICTURE_TYPE_I) + skip_bits_long(gb, s->cplx_estimation_trash_p); +- if(s->pict_type == FF_B_TYPE) ++ if(s->pict_type == AV_PICTURE_TYPE_B) + skip_bits_long(gb, s->cplx_estimation_trash_b); + + s->intra_dc_threshold= mpeg4_dc_threshold[ get_bits(gb, 3) ]; +@@ -2018,8 +2055,9 @@ + ff_init_scantable(s->dsp.idct_permutation, &s->intra_v_scantable, ff_alternate_vertical_scan); + } + +- if(s->pict_type == FF_S_TYPE && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ +- mpeg4_decode_sprite_trajectory(s, gb); ++ if(s->pict_type == AV_PICTURE_TYPE_S && (s->vol_sprite_usage==STATIC_SPRITE || s->vol_sprite_usage==GMC_SPRITE)){ ++ if(mpeg4_decode_sprite_trajectory(s, gb) < 0) ++ return -1; + if(s->sprite_brightness_change) av_log(s->avctx, AV_LOG_ERROR, "sprite_brightness_change not supported\n"); + if(s->vol_sprite_usage==STATIC_SPRITE) av_log(s->avctx, AV_LOG_ERROR, "static sprite not supported\n"); + } +@@ -2031,7 +2069,7 @@ + return -1; // makes no sense to continue, as there is nothing left from the image then + } + +- if (s->pict_type != FF_I_TYPE) { ++ if (s->pict_type != AV_PICTURE_TYPE_I) { + s->f_code = get_bits(gb, 3); /* fcode_for */ + if(s->f_code==0){ + av_log(s->avctx, AV_LOG_ERROR, "Error, header damaged or not MPEG4 header (f_code=0)\n"); +@@ -2040,7 +2078,7 @@ + }else + s->f_code=1; + +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + s->b_code = get_bits(gb, 3); + }else + s->b_code=1; +@@ -2048,14 +2086,14 @@ + if(s->avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(s->avctx, AV_LOG_DEBUG, "qp:%d fc:%d,%d %s size:%d pro:%d alt:%d top:%d %spel part:%d resync:%d w:%d a:%d rnd:%d vot:%d%s dc:%d ce:%d/%d/%d\n", + s->qscale, s->f_code, s->b_code, +- s->pict_type == FF_I_TYPE ? "I" : (s->pict_type == FF_P_TYPE ? "P" : (s->pict_type == FF_B_TYPE ? "B" : "S")), ++ s->pict_type == AV_PICTURE_TYPE_I ? "I" : (s->pict_type == AV_PICTURE_TYPE_P ? "P" : (s->pict_type == AV_PICTURE_TYPE_B ? "B" : "S")), + gb->size_in_bits,s->progressive_sequence, s->alternate_scan, s->top_field_first, + s->quarter_sample ? "q" : "h", s->data_partitioning, s->resync_marker, s->num_sprite_warping_points, + s->sprite_warping_accuracy, 1-s->no_rounding, s->vo_type, s->vol_control_parameters ? " VOLC" : " ", s->intra_dc_threshold, s->cplx_estimation_trash_i, s->cplx_estimation_trash_p, s->cplx_estimation_trash_b); + } + + if(!s->scalability){ +- if (s->shape!=RECT_SHAPE && s->pict_type!=FF_I_TYPE) { ++ if (s->shape!=RECT_SHAPE && s->pict_type!=AV_PICTURE_TYPE_I) { + skip_bits1(gb); // vop shape coding type + } + }else{ +@@ -2071,7 +2109,7 @@ + /* detect buggy encoders which don't set the low_delay flag (divx4/xvid/opendivx)*/ + // note we cannot detect divx5 without b-frames easily (although it's buggy too) + if(s->vo_type==0 && s->vol_control_parameters==0 && s->divx_version==-1 && s->picture_number==0){ +- av_log(s->avctx, AV_LOG_ERROR, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); ++ av_log(s->avctx, AV_LOG_WARNING, "looks like this file was encoded with (divx4/(old)xvid/opendivx) -> forcing low_delay flag\n"); + s->low_delay=1; + } + +@@ -2088,14 +2126,14 @@ + } + + /** +- * decode mpeg4 headers ++ * Decode mpeg4 headers. + * @return <0 if no VOP found (or a damaged one) + * FRAME_SKIPPED if a not coded VOP is found + * 0 if a VOP is found + */ + int ff_mpeg4_decode_picture_header(MpegEncContext * s, GetBitContext *gb) + { +- int startcode, v; ++ unsigned startcode, v; + + /* search next start code */ + align_get_bits(gb); +@@ -2109,8 +2147,8 @@ + startcode = 0xff; + for(;;) { + if(get_bits_count(gb) >= gb->size_in_bits){ +- if(gb->size_in_bits==8 && (s->divx_version>=0 || s->xvid_build>=0)){ +- av_log(s->avctx, AV_LOG_ERROR, "frame skip %d\n", gb->size_in_bits); ++ if(gb->size_in_bits==8 && (s->divx_version>=0 || s->xvid_build>=0) || s->codec_tag == AV_RL32("QMP4")){ ++ av_log(s->avctx, AV_LOG_VERBOSE, "frame skip %d\n", gb->size_in_bits); + return FRAME_SKIPPED; //divx bug + }else + return -1; //end of stream +@@ -2165,6 +2203,9 @@ + else if(startcode == GOP_STARTCODE){ + mpeg4_decode_gop_header(s, gb); + } ++ else if(startcode == VOS_STARTCODE){ ++ mpeg4_decode_profile_level(s, gb); ++ } + else if(startcode == VOP_STARTCODE){ + break; + } +@@ -2225,35 +2266,76 @@ + return 0; + } + ++static const AVProfile mpeg4_video_profiles[] = { ++ { FF_PROFILE_MPEG4_SIMPLE, "Simple Profile" }, ++ { FF_PROFILE_MPEG4_SIMPLE_SCALABLE, "Simple Scalable Profile" }, ++ { FF_PROFILE_MPEG4_CORE, "Core Profile" }, ++ { FF_PROFILE_MPEG4_MAIN, "Main Profile" }, ++ { FF_PROFILE_MPEG4_N_BIT, "N-bit Profile" }, ++ { FF_PROFILE_MPEG4_SCALABLE_TEXTURE, "Scalable Texture Profile" }, ++ { FF_PROFILE_MPEG4_SIMPLE_FACE_ANIMATION, "Simple Face Animation Profile" }, ++ { FF_PROFILE_MPEG4_BASIC_ANIMATED_TEXTURE, "Basic Animated Texture Profile" }, ++ { FF_PROFILE_MPEG4_HYBRID, "Hybrid Profile" }, ++ { FF_PROFILE_MPEG4_ADVANCED_REAL_TIME, "Advanced Real Time Simple Profile" }, ++ { FF_PROFILE_MPEG4_CORE_SCALABLE, "Code Scalable Profile" }, ++ { FF_PROFILE_MPEG4_ADVANCED_CODING, "Advanced Coding Profile" }, ++ { FF_PROFILE_MPEG4_ADVANCED_CORE, "Advanced Core Profile" }, ++ { FF_PROFILE_MPEG4_ADVANCED_SCALABLE_TEXTURE, "Advanced Scalable Texture Profile" }, ++ { FF_PROFILE_MPEG4_SIMPLE_STUDIO, "Simple Studio Profile" }, ++ { FF_PROFILE_MPEG4_ADVANCED_SIMPLE, "Advanced Simple Profile" }, ++}; ++ ++static const AVOption mpeg4_options[] = { ++ {"quarter_sample", "1/4 subpel MC", offsetof(MpegEncContext, quarter_sample), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, 0}, ++ {"divx_packed", "divx style packed b frames", offsetof(MpegEncContext, divx_packed), FF_OPT_TYPE_INT, {.dbl = 0}, 0, 1, 0}, ++ {NULL} ++}; ++ ++static const AVClass mpeg4_class = { ++ "MPEG4 Video Decoder", ++ av_default_item_name, ++ mpeg4_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++static const AVClass mpeg4_vdpau_class = { ++ "MPEG4 Video VDPAU Decoder", ++ av_default_item_name, ++ mpeg4_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_mpeg4_decoder = { +- "mpeg4", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG4, +- sizeof(MpegEncContext), +- decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, ++ .name = "mpeg4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG4, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS, + .flush= ff_mpeg_flush, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), + .pix_fmts= ff_hwaccel_pixfmt_list_420, ++ .profiles = NULL_IF_CONFIG_SMALL(mpeg4_video_profiles), ++ .update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context), ++ .priv_class = &mpeg4_class, + }; + + + #if CONFIG_MPEG4_VDPAU_DECODER + AVCodec ff_mpeg4_vdpau_decoder = { +- "mpeg4_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG4, +- sizeof(MpegEncContext), +- decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, ++ .name = "mpeg4_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG4, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 (VDPAU)"), + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_VDPAU_MPEG4, PIX_FMT_NONE}, ++ .priv_class = &mpeg4_vdpau_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4videoenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4videoenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4videoenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4videoenc.c 2012-05-14 14:08:54.021333682 +0200 +@@ -20,6 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + #include "mpegvideo.h" + #include "h263.h" + #include "mpeg4video.h" +@@ -124,7 +126,7 @@ + { + int score= 0; + int i, n; +- int8_t * const qscale_table= s->current_picture.qscale_table; ++ int8_t * const qscale_table = s->current_picture.f.qscale_table; + + memcpy(zigzag_last_index, s->block_last_index, sizeof(int)*6); + +@@ -201,11 +203,11 @@ + */ + void ff_clean_mpeg4_qscales(MpegEncContext *s){ + int i; +- int8_t * const qscale_table= s->current_picture.qscale_table; ++ int8_t * const qscale_table = s->current_picture.f.qscale_table; + + ff_clean_h263_qscales(s); + +- if(s->pict_type== FF_B_TYPE){ ++ if(s->pict_type== AV_PICTURE_TYPE_B){ + int odd=0; + /* ok, come on, this isn't funny anymore, there's more code for handling this mpeg4 mess than for the actual adaptive quantization */ + +@@ -236,7 +238,7 @@ + + + /** +- * encodes the dc value. ++ * Encode the dc value. + * @param n block index (0-3 are luma, 4-5 are chroma) + */ + static inline void mpeg4_encode_dc(PutBitContext * s, int level, int n) +@@ -289,17 +291,13 @@ + } + + /** +- * encodes a 8x8 block ++ * Encode an 8x8 block. + * @param n block index (0-3 are luma, 4-5 are chroma) + */ + static inline void mpeg4_encode_block(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, + uint8_t *scan_table, PutBitContext *dc_pb, PutBitContext *ac_pb) + { + int i, last_non_zero; +-#if 0 //variables for the outcommented version +- int code, sign, last; +-#endif +- const RLTable *rl; + uint32_t *bits_tab; + uint8_t *len_tab; + const int last_index = s->block_last_index[n]; +@@ -309,20 +307,17 @@ + mpeg4_encode_dc(dc_pb, intra_dc, n); + if(last_index<1) return; + i = 1; +- rl = &ff_mpeg4_rl_intra; + bits_tab= uni_mpeg4_intra_rl_bits; + len_tab = uni_mpeg4_intra_rl_len; + } else { + if(last_index<0) return; + i = 0; +- rl = &ff_h263_rl_inter; + bits_tab= uni_mpeg4_inter_rl_bits; + len_tab = uni_mpeg4_inter_rl_len; + } + + /* AC coefs */ + last_non_zero = i - 1; +-#if 1 + for (; i < last_index; i++) { + int level = block[ scan_table[i] ]; + if (level) { +@@ -348,64 +343,6 @@ + put_bits(ac_pb, 7+2+1+6+1+12+1, (3<<23)+(3<<21)+(1<<20)+(run<<14)+(1<<13)+(((level-64)&0xfff)<<1)+1); + } + } +-#else +- for (; i <= last_index; i++) { +- const int slevel = block[ scan_table[i] ]; +- if (slevel) { +- int level; +- int run = i - last_non_zero - 1; +- last = (i == last_index); +- sign = 0; +- level = slevel; +- if (level < 0) { +- sign = 1; +- level = -level; +- } +- code = get_rl_index(rl, last, run, level); +- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); +- if (code == rl->n) { +- int level1, run1; +- level1 = level - rl->max_level[last][run]; +- if (level1 < 1) +- goto esc2; +- code = get_rl_index(rl, last, run, level1); +- if (code == rl->n) { +- esc2: +- put_bits(ac_pb, 1, 1); +- if (level > MAX_LEVEL) +- goto esc3; +- run1 = run - rl->max_run[last][level] - 1; +- if (run1 < 0) +- goto esc3; +- code = get_rl_index(rl, last, run1, level); +- if (code == rl->n) { +- esc3: +- /* third escape */ +- put_bits(ac_pb, 1, 1); +- put_bits(ac_pb, 1, last); +- put_bits(ac_pb, 6, run); +- put_bits(ac_pb, 1, 1); +- put_sbits(ac_pb, 12, slevel); +- put_bits(ac_pb, 1, 1); +- } else { +- /* second escape */ +- put_bits(ac_pb, 1, 0); +- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); +- put_bits(ac_pb, 1, sign); +- } +- } else { +- /* first escape */ +- put_bits(ac_pb, 1, 0); +- put_bits(ac_pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); +- put_bits(ac_pb, 1, sign); +- } +- } else { +- put_bits(ac_pb, 1, sign); +- } +- last_non_zero = i; +- } +- } +-#endif + } + + static int mpeg4_get_block_length(MpegEncContext * s, DCTELEM * block, int n, int intra_dc, +@@ -488,6 +425,46 @@ + } + } + ++static inline int get_b_cbp(MpegEncContext * s, DCTELEM block[6][64], ++ int motion_x, int motion_y, int mb_type) ++{ ++ int cbp = 0, i; ++ ++ if (s->flags & CODEC_FLAG_CBP_RD) { ++ int score = 0; ++ const int lambda = s->lambda2 >> (FF_LAMBDA_SHIFT - 6); ++ ++ for (i = 0; i < 6; i++) ++ if (s->coded_score[i] < 0) { ++ score += s->coded_score[i]; ++ cbp |= 1 << (5 - i); ++ } ++ ++ if (cbp) { ++ int zero_score = -6; ++ if ((motion_x | motion_y | s->dquant | mb_type) == 0) ++ zero_score -= 4; //2*MV + mb_type + cbp bit ++ ++ zero_score *= lambda; ++ if (zero_score <= score) ++ cbp = 0; ++ } ++ ++ for (i = 0; i < 6; i++) { ++ if (s->block_last_index[i] >= 0 && ((cbp >> (5 - i)) & 1) == 0) { ++ s->block_last_index[i] = -1; ++ s->dsp.clear_block(s->block[i]); ++ } ++ } ++ } else { ++ for (i = 0; i < 6; i++) { ++ if (s->block_last_index[i] >= 0) ++ cbp |= 1 << (5 - i); ++ } ++ } ++ return cbp; ++} ++ + //FIXME this is duplicated to h263.c + static const int dquant_code[5]= {1,0,9,2,3}; + +@@ -497,14 +474,14 @@ + { + int cbpc, cbpy, pred_x, pred_y; + PutBitContext * const pb2 = s->data_partitioning ? &s->pb2 : &s->pb; +- PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=FF_B_TYPE ? &s->tex_pb : &s->pb; +- PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=FF_I_TYPE ? &s->pb2 : &s->pb; ++ PutBitContext * const tex_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B ? &s->tex_pb : &s->pb; ++ PutBitContext * const dc_pb = s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_I ? &s->pb2 : &s->pb; + const int interleaved_stats= (s->flags&CODEC_FLAG_PASS1) && !s->data_partitioning ? 1 : 0; + + if (!s->mb_intra) { + int i, cbp; + +- if(s->pict_type==FF_B_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_B){ + static const int mb_type_table[8]= {-1, 3, 2, 1,-1,-1,-1, 0}; /* convert from mv_dir to type */ + int mb_type= mb_type_table[s->mv_dir]; + +@@ -522,7 +499,7 @@ + assert(mb_type>=0); + + /* nothing to do if this MB was skipped in the next P Frame */ +- if(s->next_picture.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]){ //FIXME avoid DCT & ... ++ if (s->next_picture.f.mbskip_table[s->mb_y * s->mb_stride + s->mb_x]) { //FIXME avoid DCT & ... + s->skip_count++; + s->mv[0][0][0]= + s->mv[0][0][1]= +@@ -637,7 +614,7 @@ + s->p_tex_bits+= get_bits_diff(s); + } + +- }else{ /* s->pict_type==FF_B_TYPE */ ++ }else{ /* s->pict_type==AV_PICTURE_TYPE_B */ + cbp= get_p_cbp(s, block, motion_x, motion_y); + + if ((cbp | motion_x | motion_y | s->dquant) == 0 && s->mv_type==MV_TYPE_16X16) { +@@ -650,11 +627,9 @@ + + x= s->mb_x*16; + y= s->mb_y*16; +- if(x+16 > s->width) x= s->width-16; +- if(y+16 > s->height) y= s->height-16; + + offset= x + y*s->linesize; +- p_pic= s->new_picture.data[0] + offset; ++ p_pic = s->new_picture.f.data[0] + offset; + + s->mb_skipped=1; + for(i=0; imax_b_frames; i++){ +@@ -662,12 +637,27 @@ + int diff; + Picture *pic= s->reordered_input_picture[i+1]; + +- if(pic==NULL || pic->pict_type!=FF_B_TYPE) break; ++ if (pic == NULL || pic->f.pict_type != AV_PICTURE_TYPE_B) ++ break; + +- b_pic= pic->data[0] + offset; +- if(pic->type != FF_BUFFER_TYPE_SHARED) ++ b_pic = pic->f.data[0] + offset; ++ if (pic->f.type != FF_BUFFER_TYPE_SHARED) + b_pic+= INPLACE_OFFSET; +- diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); ++ ++ if(x+16 > s->width || y+16 > s->height){ ++ int x1,y1; ++ int xe= FFMIN(16, s->width - x); ++ int ye= FFMIN(16, s->height- y); ++ diff=0; ++ for(y1=0; y1linesize] - b_pic[x1+y1*s->linesize]); ++ } ++ } ++ diff= diff*256/(xe*ye); ++ }else{ ++ diff= s->dsp.sad[0](NULL, p_pic, b_pic, s->linesize, 16); ++ } + if(diff>s->qscale*70){ //FIXME check that 70 is optimal + s->mb_skipped=0; + break; +@@ -769,8 +759,8 @@ + /* motion vectors: 8x8 mode*/ + h263_pred_motion(s, i, 0, &pred_x, &pred_y); + +- ff_h263_encode_motion_vector(s, s->current_picture.motion_val[0][ s->block_index[i] ][0] - pred_x, +- s->current_picture.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); ++ ff_h263_encode_motion_vector(s, s->current_picture.f.motion_val[0][ s->block_index[i] ][0] - pred_x, ++ s->current_picture.f.motion_val[0][ s->block_index[i] ][1] - pred_y, s->f_code); + } + } + +@@ -812,7 +802,7 @@ + } + + cbpc = cbp & 3; +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + if(s->dquant) cbpc+=4; + put_bits(&s->pb, + ff_h263_intra_MCBPC_bits[cbpc], +@@ -864,11 +854,11 @@ + + /* must be called before writing the header */ + void ff_set_mpeg4_time(MpegEncContext * s){ +- if(s->pict_type==FF_B_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_B){ + ff_mpeg4_init_direct_mv(s); + }else{ + s->last_time_base= s->time_base; +- s->time_base= s->time/s->avctx->time_base.den; ++ s->time_base= FFUDIV(s->time, s->avctx->time_base.den); + } + } + +@@ -879,15 +869,16 @@ + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, GOP_STARTCODE); + +- time= s->current_picture_ptr->pts; ++ time = s->current_picture_ptr->f.pts; + if(s->reordered_input_picture[1]) +- time= FFMIN(time, s->reordered_input_picture[1]->pts); ++ time = FFMIN(time, s->reordered_input_picture[1]->f.pts); + time= time*s->avctx->time_base.num; ++ s->last_time_base= FFUDIV(time, s->avctx->time_base.den); + +- seconds= time/s->avctx->time_base.den; +- minutes= seconds/60; seconds %= 60; +- hours= minutes/60; minutes %= 60; +- hours%=24; ++ seconds= FFUDIV(time, s->avctx->time_base.den); ++ minutes= FFUDIV(seconds, 60); seconds = FFUMOD(seconds, 60); ++ hours = FFUDIV(minutes, 60); minutes = FFUMOD(minutes, 60); ++ hours = FFUMOD(hours , 24); + + put_bits(&s->pb, 5, hours); + put_bits(&s->pb, 6, minutes); +@@ -897,8 +888,6 @@ + put_bits(&s->pb, 1, !!(s->flags&CODEC_FLAG_CLOSED_GOP)); + put_bits(&s->pb, 1, 0); //broken link == NO + +- s->last_time_base= time / s->avctx->time_base.den; +- + ff_mpeg4_stuffing(&s->pb); + } + +@@ -1054,7 +1043,7 @@ + int time_incr; + int time_div, time_mod; + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + if(!(s->flags&CODEC_FLAG_GLOBAL_HEADER)){ + if(s->strict_std_compliance < FF_COMPLIANCE_VERY_STRICT) //HACK, the reference sw is buggy + mpeg4_encode_visual_object_header(s); +@@ -1065,15 +1054,14 @@ + mpeg4_encode_gop_header(s); + } + +- s->partitioned_frame= s->data_partitioning && s->pict_type!=FF_B_TYPE; ++ s->partitioned_frame= s->data_partitioning && s->pict_type!=AV_PICTURE_TYPE_B; + + put_bits(&s->pb, 16, 0); /* vop header */ + put_bits(&s->pb, 16, VOP_STARTCODE); /* vop header */ + put_bits(&s->pb, 2, s->pict_type - 1); /* pict type: I = 0 , P = 1 */ + +- assert(s->time>=0); +- time_div= s->time/s->avctx->time_base.den; +- time_mod= s->time%s->avctx->time_base.den; ++ time_div= FFUDIV(s->time, s->avctx->time_base.den); ++ time_mod= FFUMOD(s->time, s->avctx->time_base.den); + time_incr= time_div - s->last_time_base; + assert(time_incr >= 0); + while(time_incr--) +@@ -1085,22 +1073,22 @@ + put_bits(&s->pb, s->time_increment_bits, time_mod); /* time increment */ + put_bits(&s->pb, 1, 1); /* marker */ + put_bits(&s->pb, 1, 1); /* vop coded */ +- if ( s->pict_type == FF_P_TYPE +- || (s->pict_type == FF_S_TYPE && s->vol_sprite_usage==GMC_SPRITE)) { ++ if ( s->pict_type == AV_PICTURE_TYPE_P ++ || (s->pict_type == AV_PICTURE_TYPE_S && s->vol_sprite_usage==GMC_SPRITE)) { + put_bits(&s->pb, 1, s->no_rounding); /* rounding type */ + } + put_bits(&s->pb, 3, 0); /* intra dc VLC threshold */ + if(!s->progressive_sequence){ +- put_bits(&s->pb, 1, s->current_picture_ptr->top_field_first); ++ put_bits(&s->pb, 1, s->current_picture_ptr->f.top_field_first); + put_bits(&s->pb, 1, s->alternate_scan); + } + //FIXME sprite stuff + + put_bits(&s->pb, 5, s->qscale); + +- if (s->pict_type != FF_I_TYPE) ++ if (s->pict_type != AV_PICTURE_TYPE_I) + put_bits(&s->pb, 3, s->f_code); /* fcode_for */ +- if (s->pict_type == FF_B_TYPE) ++ if (s->pict_type == AV_PICTURE_TYPE_B) + put_bits(&s->pb, 3, s->b_code); /* fcode_back */ + } + +@@ -1265,7 +1253,6 @@ + s->inter_ac_vlc_length = uni_mpeg4_inter_rl_len; + s->inter_ac_vlc_last_length= uni_mpeg4_inter_rl_len + 128*64; + s->luma_dc_vlc_length= uni_DCtab_lum_len; +- s->chroma_dc_vlc_length= uni_DCtab_chrom_len; + s->ac_esc_length= 7+2+1+6+1+12+1; + s->y_dc_scale_table= ff_mpeg4_y_dc_scale_table; + s->c_dc_scale_table= ff_mpeg4_c_dc_scale_table; +@@ -1305,7 +1292,7 @@ + const int tex_pb_len= put_bits_count(&s->tex_pb); + const int bits= put_bits_count(&s->pb); + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + put_bits(&s->pb, 19, DC_MARKER); + s->misc_bits+=19 + pb2_len + bits - s->last_bits; + s->i_tex_bits+= tex_pb_len; +@@ -1320,8 +1307,8 @@ + flush_put_bits(&s->tex_pb); + + set_put_bits_buffer_size(&s->pb, s->pb2.buf_end - s->pb.buf); +- ff_copy_bits(&s->pb, s->pb2.buf , pb2_len); +- ff_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len); ++ avpriv_copy_bits(&s->pb, s->pb2.buf , pb2_len); ++ avpriv_copy_bits(&s->pb, s->tex_pb.buf, tex_pb_len); + s->last_bits= put_bits_count(&s->pb); + } + +@@ -1338,15 +1325,31 @@ + put_bits(&s->pb, 1, 0); /* no HEC */ + } + ++#define OFFSET(x) offsetof(MpegEncContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "data_partitioning", "Use data partitioning.", OFFSET(data_partitioning), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "alternate_scan", "Enable alternate scantable.", OFFSET(alternate_scan), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { NULL }, ++}; ++ ++static const AVClass mpeg4enc_class = { ++ .class_name = "MPEG4 encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_mpeg4_encoder = { +- "mpeg4", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MPEG4, +- sizeof(MpegEncContext), +- encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "mpeg4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG4, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, +- .capabilities= CODEC_CAP_DELAY, ++ .capabilities= CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), ++ .priv_class = &mpeg4enc_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video.h 2012-05-14 14:08:54.012333502 +0200 +@@ -66,10 +66,7 @@ + extern RLTable ff_mpeg4_rl_intra; + + /* Note this is identical to the intra rvlc except that it is reordered. */ +-extern const uint16_t inter_rvlc[170][2]; + extern RLTable rvlc_rl_inter; +- +-extern const uint16_t intra_rvlc[170][2]; + extern RLTable rvlc_rl_intra; + + extern const uint16_t sprite_trajectory_tab[15][2]; +@@ -122,7 +119,7 @@ + + + /** +- * predicts the dc. ++ * Predict the dc. + * encoding quantized level -> quantized diff + * decoding quantized diff -> quantized level + * @param n block index (0-3 are luma, 4-5 are chroma) +@@ -177,7 +174,7 @@ + }else{ + level += pred; + ret= level; +- if(s->error_recognition>=3){ ++ if(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_AGGRESSIVE)){ + if(level<0){ + av_log(s->avctx, AV_LOG_ERROR, "dc<0 at %dx%d\n", s->mb_x, s->mb_y); + return -1; +@@ -199,4 +196,4 @@ + + return ret; + } +-#endif ++#endif /* AVCODEC_MPEG4VIDEO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video_parser.c 2012-05-14 14:08:54.012333502 +0200 +@@ -20,6 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + #include "parser.h" + #include "mpegvideo.h" + #include "mpeg4video.h" +@@ -99,6 +101,8 @@ + if (!pc->enc) + return -1; + pc->first_picture = 1; ++ pc->enc->quant_precision=5; ++ pc->enc->slice_context_count = 1; + return 0; + } + +@@ -130,10 +134,10 @@ + + + AVCodecParser ff_mpeg4video_parser = { +- { CODEC_ID_MPEG4 }, +- sizeof(ParseContext1), +- mpeg4video_parse_init, +- mpeg4video_parse, +- ff_parse1_close, +- ff_mpeg4video_split, ++ .codec_ids = { CODEC_ID_MPEG4 }, ++ .priv_data_size = sizeof(ParseContext1), ++ .parser_init = mpeg4video_parse_init, ++ .parser_parse = mpeg4video_parse, ++ .parser_close = ff_parse1_close, ++ .split = ff_mpeg4video_split, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video_parser.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video_parser.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpeg4video_parser.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpeg4video_parser.h 2012-05-14 14:08:54.013333522 +0200 +@@ -26,7 +26,7 @@ + #include "parser.h" + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ + int ff_mpeg4_find_frame_end(ParseContext *pc, const uint8_t *buf, int buf_size); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio3.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio3.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio3.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio3.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,53 +0,0 @@ +-/* +- * Copyright (c) 2007 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/* layer 3 "granule" */ +-typedef struct GranuleDef { +- uint8_t scfsi; +- int part2_3_length; +- int big_values; +- int global_gain; +- int scalefac_compress; +- uint8_t block_type; +- uint8_t switch_point; +- int table_select[3]; +- int subblock_gain[3]; +- uint8_t scalefac_scale; +- uint8_t count1table_select; +- int region_size[3]; /* number of huffman codes in each region */ +- int preflag; +- int short_start, long_end; /* long/short band indexes */ +- uint8_t scale_factors[40]; +- int32_t sb_hybrid[SBLIMIT * 18]; /* 576 samples */ +-} GranuleDef; +- +-void ff_mp3_init(void); +- +-/** +- * Compute huffman coded region sizes. +- */ +-void ff_init_short_region(MPADecodeContext *s, GranuleDef *g); +- +-/** +- * Compute huffman coded region sizes. +- */ +-void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2); +- +-void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodata.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodata.c 2012-05-14 14:08:54.025333762 +0200 +@@ -27,17 +27,17 @@ + #include "mpegaudiodata.h" + + +-const uint16_t ff_mpa_bitrate_tab[2][3][15] = { ++const uint16_t avpriv_mpa_bitrate_tab[2][3][15] = { + { {0, 32, 64, 96, 128, 160, 192, 224, 256, 288, 320, 352, 384, 416, 448 }, +- {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, +- {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } }, +- { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, +- {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, +- {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160} ++ {0, 32, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320, 384 }, ++ {0, 32, 40, 48, 56, 64, 80, 96, 112, 128, 160, 192, 224, 256, 320 } }, ++ { {0, 32, 48, 56, 64, 80, 96, 112, 128, 144, 160, 176, 192, 224, 256}, ++ {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160}, ++ {0, 8, 16, 24, 32, 40, 48, 56, 64, 80, 96, 112, 128, 144, 160} + } + }; + +-const uint16_t ff_mpa_freq_tab[3] = { 44100, 48000, 32000 }; ++const uint16_t avpriv_mpa_freq_tab[3] = { 44100, 48000, 32000 }; + + /*******************************************************/ + /* half mpeg encoding window (full precision) */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodata.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodata.h 2012-05-14 14:08:54.026333783 +0200 +@@ -27,13 +27,13 @@ + #ifndef AVCODEC_MPEGAUDIODATA_H + #define AVCODEC_MPEGAUDIODATA_H + +-#include "libavutil/common.h" ++#include + + #define MODE_EXT_MS_STEREO 2 + #define MODE_EXT_I_STEREO 1 + +-extern const uint16_t ff_mpa_bitrate_tab[2][3][15]; +-extern const uint16_t ff_mpa_freq_tab[3]; ++extern const uint16_t avpriv_mpa_bitrate_tab[2][3][15]; ++extern const uint16_t avpriv_mpa_freq_tab[3]; + extern const int32_t ff_mpa_enwindow[257]; + extern const int ff_mpa_sblimit_table[5]; + extern const int ff_mpa_quant_steps[17]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodec.c 2012-05-14 14:08:54.033333923 +0200 +@@ -21,43 +21,89 @@ + + /** + * @file +- * MPEG Audio decoder. ++ * MPEG Audio decoder + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "get_bits.h" +-#include "dsputil.h" ++#include "mathops.h" ++#include "mpegaudiodsp.h" + + /* + * TODO: +- * - in low precision mode, use more 16 bit multiplies in synth filter + * - test lsf / mpeg25 extensively. + */ + + #include "mpegaudio.h" + #include "mpegaudiodecheader.h" + +-#include "mathops.h" ++#define BACKSTEP_SIZE 512 ++#define EXTRABYTES 24 ++#define LAST_BUF_SIZE 2 * BACKSTEP_SIZE + EXTRABYTES ++ ++/* layer 3 "granule" */ ++typedef struct GranuleDef { ++ uint8_t scfsi; ++ int part2_3_length; ++ int big_values; ++ int global_gain; ++ int scalefac_compress; ++ uint8_t block_type; ++ uint8_t switch_point; ++ int table_select[3]; ++ int subblock_gain[3]; ++ uint8_t scalefac_scale; ++ uint8_t count1table_select; ++ int region_size[3]; /* number of huffman codes in each region */ ++ int preflag; ++ int short_start, long_end; /* long/short band indexes */ ++ uint8_t scale_factors[40]; ++ DECLARE_ALIGNED(16, INTFLOAT, sb_hybrid)[SBLIMIT * 18]; /* 576 samples */ ++} GranuleDef; ++ ++typedef struct MPADecodeContext { ++ MPA_DECODE_HEADER ++ uint8_t last_buf[LAST_BUF_SIZE]; ++ int last_buf_size; ++ /* next header (used in free format parsing) */ ++ uint32_t free_format_next_header; ++ GetBitContext gb; ++ GetBitContext in_gb; ++ DECLARE_ALIGNED(32, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2]; ++ int synth_buf_offset[MPA_MAX_CHANNELS]; ++ DECLARE_ALIGNED(32, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT]; ++ INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ ++ GranuleDef granules[2][2]; /* Used in Layer 3 */ ++ int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 ++ int dither_state; ++ int err_recognition; ++ AVCodecContext* avctx; ++ MPADSPContext mpadsp; ++ AVFrame frame; ++} MPADecodeContext; + + #if CONFIG_FLOAT + # define SHR(a,b) ((a)*(1.0f/(1<<(b)))) +-# define compute_antialias compute_antialias_float + # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5)) + # define FIXR(x) ((float)(x)) + # define FIXHR(x) ((float)(x)) + # define MULH3(x, y, s) ((s)*(y)*(x)) + # define MULLx(x, y, s) ((y)*(x)) + # define RENAME(a) a ## _float ++# define OUT_FMT AV_SAMPLE_FMT_FLT + #else + # define SHR(a,b) ((a)>>(b)) +-# define compute_antialias compute_antialias_integer +-/* WARNING: only correct for posititive numbers */ ++/* WARNING: only correct for positive numbers */ + # define FIXR_OLD(a) ((int)((a) * FRAC_ONE + 0.5)) + # define FIXR(a) ((int)((a) * FRAC_ONE + 0.5)) + # define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5)) + # define MULH3(x, y, s) MULH((s)*(x), y) + # define MULLx(x, y, s) MULL(x,y,s) +-# define RENAME(a) a ++# define RENAME(a) a ## _fixed ++# define OUT_FMT AV_SAMPLE_FMT_S16 + #endif + + /****************/ +@@ -67,40 +113,26 @@ + #include "mpegaudiodata.h" + #include "mpegaudiodectab.h" + +-#if CONFIG_FLOAT +-# include "fft.h" +-#else +-# include "dct32.c" +-#endif +- +-static void compute_antialias(MPADecodeContext *s, GranuleDef *g); +-static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window, +- int *dither_state, OUT_INT *samples, int incr); +- + /* vlc structure for decoding layer 3 huffman tables */ + static VLC huff_vlc[16]; + static VLC_TYPE huff_vlc_tables[ +- 0+128+128+128+130+128+154+166+ +- 142+204+190+170+542+460+662+414 ++ 0 + 128 + 128 + 128 + 130 + 128 + 154 + 166 + ++ 142 + 204 + 190 + 170 + 542 + 460 + 662 + 414 + ][2]; + static const int huff_vlc_tables_sizes[16] = { +- 0, 128, 128, 128, 130, 128, 154, 166, +- 142, 204, 190, 170, 542, 460, 662, 414 ++ 0, 128, 128, 128, 130, 128, 154, 166, ++ 142, 204, 190, 170, 542, 460, 662, 414 + }; + static VLC huff_quad_vlc[2]; +-static VLC_TYPE huff_quad_vlc_tables[128+16][2]; +-static const int huff_quad_vlc_tables_sizes[2] = { +- 128, 16 +-}; ++static VLC_TYPE huff_quad_vlc_tables[128+16][2]; ++static const int huff_quad_vlc_tables_sizes[2] = { 128, 16 }; + /* computed from band_size_long */ + static uint16_t band_index_long[9][23]; + #include "mpegaudio_tablegen.h" + /* intensity stereo coef table */ + static INTFLOAT is_table[2][16]; + static INTFLOAT is_table_lsf[2][2][16]; +-static int32_t csa_table[8][4]; +-static float csa_table_float[8][4]; +-static INTFLOAT mdct_win[8][36]; ++static INTFLOAT csa_table[8][4]; + + static int16_t division_tab3[1<<6 ]; + static int16_t division_tab5[1<<8 ]; +@@ -125,23 +157,23 @@ + SCALE_GEN(4.0 / 9.0), /* 9 steps */ + }; + +-DECLARE_ALIGNED(16, MPA_INT, RENAME(ff_mpa_synth_window))[512+256]; +- + /** + * Convert region offsets to region sizes and truncate + * size to big_values. + */ +-static void ff_region_offset2size(GranuleDef *g){ +- int i, k, j=0; +- g->region_size[2] = (576 / 2); +- for(i=0;i<3;i++) { ++static void ff_region_offset2size(GranuleDef *g) ++{ ++ int i, k, j = 0; ++ g->region_size[2] = 576 / 2; ++ for (i = 0; i < 3; i++) { + k = FFMIN(g->region_size[i], g->big_values); + g->region_size[i] = k - j; + j = k; + } + } + +-static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g){ ++static void ff_init_short_region(MPADecodeContext *s, GranuleDef *g) ++{ + if (g->block_type == 2) + g->region_size[0] = (36 / 2); + else { +@@ -155,17 +187,17 @@ + g->region_size[1] = (576 / 2); + } + +-static void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2){ ++static void ff_init_long_region(MPADecodeContext *s, GranuleDef *g, int ra1, int ra2) ++{ + int l; +- g->region_size[0] = +- band_index_long[s->sample_rate_index][ra1 + 1] >> 1; ++ g->region_size[0] = band_index_long[s->sample_rate_index][ra1 + 1] >> 1; + /* should not overflow */ + l = FFMIN(ra1 + ra2 + 2, 22); +- g->region_size[1] = +- band_index_long[s->sample_rate_index][l] >> 1; ++ g->region_size[1] = band_index_long[s->sample_rate_index][ l] >> 1; + } + +-static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g){ ++static void ff_compute_band_indexes(MPADecodeContext *s, GranuleDef *g) ++{ + if (g->block_type == 2) { + if (g->switch_point) { + /* if switched mode, we handle the 36 first samples as +@@ -180,12 +212,12 @@ + + g->short_start = 2 + (s->sample_rate_index != 8); + } else { +- g->long_end = 0; ++ g->long_end = 0; + g->short_start = 0; + } + } else { + g->short_start = 13; +- g->long_end = 22; ++ g->long_end = 22; + } + } + +@@ -196,11 +228,11 @@ + int shift, mod; + int64_t val; + +- shift = scale_factor_modshift[scale_factor]; +- mod = shift & 3; ++ shift = scale_factor_modshift[scale_factor]; ++ mod = shift & 3; + shift >>= 2; +- val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]); +- shift += n; ++ val = MUL64(mant + (-1 << n) + 1, scale_factor_mult[n-1][mod]); ++ shift += n; + /* NOTE: at this point, 1 <= shift >= 21 + 15 */ + return (int)((val + (1LL << (shift - 1))) >> shift); + } +@@ -209,8 +241,8 @@ + { + int shift, mod, val; + +- shift = scale_factor_modshift[scale_factor]; +- mod = shift & 3; ++ shift = scale_factor_modshift[scale_factor]; ++ mod = shift & 3; + shift >>= 2; + + val = (mant - (steps >> 1)) * scale_factor_mult2[steps >> 2][mod]; +@@ -226,542 +258,199 @@ + unsigned int m; + int e; + +- e = table_4_3_exp [4*value + (exponent&3)]; +- m = table_4_3_value[4*value + (exponent&3)]; +- e -= (exponent >> 2); +- assert(e>=1); ++ e = table_4_3_exp [4 * value + (exponent & 3)]; ++ m = table_4_3_value[4 * value + (exponent & 3)]; ++ e -= exponent >> 2; ++ assert(e >= 1); + if (e > 31) + return 0; +- m = (m + (1 << (e-1))) >> e; ++ m = (m + (1 << (e - 1))) >> e; + + return m; + } + +-/* all integer n^(4/3) computation code */ +-#define DEV_ORDER 13 +- +-#define POW_FRAC_BITS 24 +-#define POW_FRAC_ONE (1 << POW_FRAC_BITS) +-#define POW_FIX(a) ((int)((a) * POW_FRAC_ONE)) +-#define POW_MULL(a,b) (((int64_t)(a) * (int64_t)(b)) >> POW_FRAC_BITS) +- +-static int dev_4_3_coefs[DEV_ORDER]; +- +-#if 0 /* unused */ +-static int pow_mult3[3] = { +- POW_FIX(1.0), +- POW_FIX(1.25992104989487316476), +- POW_FIX(1.58740105196819947474), +-}; +-#endif +- +-static av_cold void int_pow_init(void) ++static av_cold void decode_init_static(void) + { +- int i, a; ++ int i, j, k; ++ int offset; + +- a = POW_FIX(1.0); +- for(i=0;i= 0; j--) +- a1 = POW_MULL(a, dev_4_3_coefs[j] + a1); +- a = (1 << POW_FRAC_BITS) + a1; +- /* exponent compute (exact) */ +- e = e * 4; +- er = e % 3; +- eq = e / 3; +- a = POW_MULL(a, pow_mult3[er]); +- while (a >= 2 * POW_FRAC_ONE) { +- a = a >> 1; +- eq++; +- } +- /* convert to float */ +- while (a < POW_FRAC_ONE) { +- a = a << 1; +- eq--; +- } +- /* now POW_FRAC_ONE <= a < 2 * POW_FRAC_ONE */ +-#if POW_FRAC_BITS > FRAC_BITS +- a = (a + (1 << (POW_FRAC_BITS - FRAC_BITS - 1))) >> (POW_FRAC_BITS - FRAC_BITS); +- /* correct overflow */ +- if (a >= 2 * (1 << FRAC_BITS)) { +- a = a >> 1; +- eq++; ++ /* scale factor multiply for layer 1 */ ++ for (i = 0; i < 15; i++) { ++ int n, norm; ++ n = i + 2; ++ norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); ++ scale_factor_mult[i][0] = MULLx(norm, FIXR(1.0 * 2.0), FRAC_BITS); ++ scale_factor_mult[i][1] = MULLx(norm, FIXR(0.7937005259 * 2.0), FRAC_BITS); ++ scale_factor_mult[i][2] = MULLx(norm, FIXR(0.6299605249 * 2.0), FRAC_BITS); ++ av_dlog(NULL, "%d: norm=%x s=%x %x %x\n", i, norm, ++ scale_factor_mult[i][0], ++ scale_factor_mult[i][1], ++ scale_factor_mult[i][2]); + } +-#endif +- *exp_ptr = eq; +- return a; +-} +-#endif + +-static av_cold int decode_init(AVCodecContext * avctx) +-{ +- MPADecodeContext *s = avctx->priv_data; +- static int init=0; +- int i, j, k; ++ RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window)); + +- s->avctx = avctx; +- s->apply_window_mp3 = apply_window_mp3_c; +-#if HAVE_MMX && CONFIG_FLOAT +- ff_mpegaudiodec_init_mmx(s); +-#endif +-#if CONFIG_FLOAT +- ff_dct_init(&s->dct, 5, DCT_II); +-#endif +- if (HAVE_ALTIVEC && CONFIG_FLOAT) ff_mpegaudiodec_init_altivec(s); +- +- avctx->sample_fmt= OUT_FMT; +- s->error_recognition= avctx->error_recognition; +- +- if (!init && !avctx->parse_only) { +- int offset; ++ /* huffman decode tables */ ++ offset = 0; ++ for (i = 1; i < 16; i++) { ++ const HuffTable *h = &mpa_huff_tables[i]; ++ int xsize, x, y; ++ uint8_t tmp_bits [512]; ++ uint16_t tmp_codes[512]; + +- /* scale factors table for layer 1/2 */ +- for(i=0;i<64;i++) { +- int shift, mod; +- /* 1.0 (i = 3) is normalized to 2 ^ FRAC_BITS */ +- shift = (i / 3); +- mod = i % 3; +- scale_factor_modshift[i] = mod | (shift << 2); +- } +- +- /* scale factor multiply for layer 1 */ +- for(i=0;i<15;i++) { +- int n, norm; +- n = i + 2; +- norm = ((INT64_C(1) << n) * FRAC_ONE) / ((1 << n) - 1); +- scale_factor_mult[i][0] = MULLx(norm, FIXR(1.0 * 2.0), FRAC_BITS); +- scale_factor_mult[i][1] = MULLx(norm, FIXR(0.7937005259 * 2.0), FRAC_BITS); +- scale_factor_mult[i][2] = MULLx(norm, FIXR(0.6299605249 * 2.0), FRAC_BITS); +- av_dlog(avctx, "%d: norm=%x s=%x %x %x\n", +- i, norm, +- scale_factor_mult[i][0], +- scale_factor_mult[i][1], +- scale_factor_mult[i][2]); +- } +- +- RENAME(ff_mpa_synth_init)(RENAME(ff_mpa_synth_window)); +- +- /* huffman decode tables */ +- offset = 0; +- for(i=1;i<16;i++) { +- const HuffTable *h = &mpa_huff_tables[i]; +- int xsize, x, y; +- uint8_t tmp_bits [512]; +- uint16_t tmp_codes[512]; ++ memset(tmp_bits , 0, sizeof(tmp_bits )); ++ memset(tmp_codes, 0, sizeof(tmp_codes)); + +- memset(tmp_bits , 0, sizeof(tmp_bits )); +- memset(tmp_codes, 0, sizeof(tmp_codes)); ++ xsize = h->xsize; + +- xsize = h->xsize; +- +- j = 0; +- for(x=0;xbits [j ]; +- tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++]; +- } ++ j = 0; ++ for (x = 0; x < xsize; x++) { ++ for (y = 0; y < xsize; y++) { ++ tmp_bits [(x << 5) | y | ((x&&y)<<4)]= h->bits [j ]; ++ tmp_codes[(x << 5) | y | ((x&&y)<<4)]= h->codes[j++]; + } +- +- /* XXX: fail test */ +- huff_vlc[i].table = huff_vlc_tables+offset; +- huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i]; +- init_vlc(&huff_vlc[i], 7, 512, +- tmp_bits, 1, 1, tmp_codes, 2, 2, +- INIT_VLC_USE_NEW_STATIC); +- offset += huff_vlc_tables_sizes[i]; +- } +- assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables)); +- +- offset = 0; +- for(i=0;i<2;i++) { +- huff_quad_vlc[i].table = huff_quad_vlc_tables+offset; +- huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i]; +- init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16, +- mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, +- INIT_VLC_USE_NEW_STATIC); +- offset += huff_quad_vlc_tables_sizes[i]; +- } +- assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables)); +- +- for(i=0;i<9;i++) { +- k = 0; +- for(j=0;j<22;j++) { +- band_index_long[i][j] = k; +- k += band_size_long[i][j]; +- } +- band_index_long[i][22] = k; + } + +- /* compute n ^ (4/3) and store it in mantissa/exp format */ +- +- int_pow_init(); +- mpegaudio_tableinit(); +- +- for (i = 0; i < 4; i++) +- if (ff_mpa_quant_bits[i] < 0) +- for (j = 0; j < (1<<(-ff_mpa_quant_bits[i]+1)); j++) { +- int val1, val2, val3, steps; +- int val = j; +- steps = ff_mpa_quant_steps[i]; +- val1 = val % steps; +- val /= steps; +- val2 = val % steps; +- val3 = val / steps; +- division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8); +- } ++ /* XXX: fail test */ ++ huff_vlc[i].table = huff_vlc_tables+offset; ++ huff_vlc[i].table_allocated = huff_vlc_tables_sizes[i]; ++ init_vlc(&huff_vlc[i], 7, 512, ++ tmp_bits, 1, 1, tmp_codes, 2, 2, ++ INIT_VLC_USE_NEW_STATIC); ++ offset += huff_vlc_tables_sizes[i]; ++ } ++ assert(offset == FF_ARRAY_ELEMS(huff_vlc_tables)); + ++ offset = 0; ++ for (i = 0; i < 2; i++) { ++ huff_quad_vlc[i].table = huff_quad_vlc_tables+offset; ++ huff_quad_vlc[i].table_allocated = huff_quad_vlc_tables_sizes[i]; ++ init_vlc(&huff_quad_vlc[i], i == 0 ? 7 : 4, 16, ++ mpa_quad_bits[i], 1, 1, mpa_quad_codes[i], 1, 1, ++ INIT_VLC_USE_NEW_STATIC); ++ offset += huff_quad_vlc_tables_sizes[i]; ++ } ++ assert(offset == FF_ARRAY_ELEMS(huff_quad_vlc_tables)); + +- for(i=0;i<7;i++) { +- float f; +- INTFLOAT v; +- if (i != 6) { +- f = tan((double)i * M_PI / 12.0); +- v = FIXR(f / (1.0 + f)); +- } else { +- v = FIXR(1.0); +- } +- is_table[0][i] = v; +- is_table[1][6 - i] = v; +- } +- /* invalid values */ +- for(i=7;i<16;i++) +- is_table[0][i] = is_table[1][i] = 0.0; +- +- for(i=0;i<16;i++) { +- double f; +- int e, k; +- +- for(j=0;j<2;j++) { +- e = -(j + 1) * ((i + 1) >> 1); +- f = pow(2.0, e / 4.0); +- k = i & 1; +- is_table_lsf[j][k ^ 1][i] = FIXR(f); +- is_table_lsf[j][k][i] = FIXR(1.0); +- av_dlog(avctx, "is_table_lsf %d %d: %x %x\n", +- i, j, is_table_lsf[j][0][i], is_table_lsf[j][1][i]); +- } ++ for (i = 0; i < 9; i++) { ++ k = 0; ++ for (j = 0; j < 22; j++) { ++ band_index_long[i][j] = k; ++ k += band_size_long[i][j]; + } ++ band_index_long[i][22] = k; ++ } + +- for(i=0;i<8;i++) { +- float ci, cs, ca; +- ci = ci_table[i]; +- cs = 1.0 / sqrt(1.0 + ci * ci); +- ca = cs * ci; +- csa_table[i][0] = FIXHR(cs/4); +- csa_table[i][1] = FIXHR(ca/4); +- csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4); +- csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4); +- csa_table_float[i][0] = cs; +- csa_table_float[i][1] = ca; +- csa_table_float[i][2] = ca + cs; +- csa_table_float[i][3] = ca - cs; +- } +- +- /* compute mdct windows */ +- for(i=0;i<36;i++) { +- for(j=0; j<4; j++){ +- double d; +- +- if(j==2 && i%3 != 1) +- continue; +- +- d= sin(M_PI * (i + 0.5) / 36.0); +- if(j==1){ +- if (i>=30) d= 0; +- else if(i>=24) d= sin(M_PI * (i - 18 + 0.5) / 12.0); +- else if(i>=18) d= 1; +- }else if(j==3){ +- if (i< 6) d= 0; +- else if(i< 12) d= sin(M_PI * (i - 6 + 0.5) / 12.0); +- else if(i< 18) d= 1; +- } +- //merge last stage of imdct into the window coefficients +- d*= 0.5 / cos(M_PI*(2*i + 19)/72); ++ /* compute n ^ (4/3) and store it in mantissa/exp format */ + +- if(j==2) +- mdct_win[j][i/3] = FIXHR((d / (1<<5))); +- else +- mdct_win[j][i ] = FIXHR((d / (1<<5))); +- } +- } ++ mpegaudio_tableinit(); + +- /* NOTE: we do frequency inversion adter the MDCT by changing +- the sign of the right window coefs */ +- for(j=0;j<4;j++) { +- for(i=0;i<36;i+=2) { +- mdct_win[j + 4][i] = mdct_win[j][i]; +- mdct_win[j + 4][i + 1] = -mdct_win[j][i + 1]; ++ for (i = 0; i < 4; i++) { ++ if (ff_mpa_quant_bits[i] < 0) { ++ for (j = 0; j < (1 << (-ff_mpa_quant_bits[i]+1)); j++) { ++ int val1, val2, val3, steps; ++ int val = j; ++ steps = ff_mpa_quant_steps[i]; ++ val1 = val % steps; ++ val /= steps; ++ val2 = val % steps; ++ val3 = val / steps; ++ division_tabs[i][j] = val1 + (val2 << 4) + (val3 << 8); + } + } +- +- init = 1; + } + +- if (avctx->codec_id == CODEC_ID_MP3ADU) +- s->adu_mode = 1; +- return 0; +-} +- +- +-#if CONFIG_FLOAT +-static inline float round_sample(float *sum) +-{ +- float sum1=*sum; +- *sum = 0; +- return sum1; +-} +- +-/* signed 16x16 -> 32 multiply add accumulate */ +-#define MACS(rt, ra, rb) rt+=(ra)*(rb) +- +-/* signed 16x16 -> 32 multiply */ +-#define MULS(ra, rb) ((ra)*(rb)) +- +-#define MLSS(rt, ra, rb) rt-=(ra)*(rb) +- +-#elif FRAC_BITS <= 15 +- +-static inline int round_sample(int *sum) +-{ +- int sum1; +- sum1 = (*sum) >> OUT_SHIFT; +- *sum &= (1< 32 multiply add accumulate */ +-#define MACS(rt, ra, rb) MAC16(rt, ra, rb) +- +-/* signed 16x16 -> 32 multiply */ +-#define MULS(ra, rb) MUL16(ra, rb) + +-#define MLSS(rt, ra, rb) MLS16(rt, ra, rb) ++ for (i = 0; i < 7; i++) { ++ float f; ++ INTFLOAT v; ++ if (i != 6) { ++ f = tan((double)i * M_PI / 12.0); ++ v = FIXR(f / (1.0 + f)); ++ } else { ++ v = FIXR(1.0); ++ } ++ is_table[0][ i] = v; ++ is_table[1][6 - i] = v; ++ } ++ /* invalid values */ ++ for (i = 7; i < 16; i++) ++ is_table[0][i] = is_table[1][i] = 0.0; ++ ++ for (i = 0; i < 16; i++) { ++ double f; ++ int e, k; ++ ++ for (j = 0; j < 2; j++) { ++ e = -(j + 1) * ((i + 1) >> 1); ++ f = pow(2.0, e / 4.0); ++ k = i & 1; ++ is_table_lsf[j][k ^ 1][i] = FIXR(f); ++ is_table_lsf[j][k ][i] = FIXR(1.0); ++ av_dlog(NULL, "is_table_lsf %d %d: %f %f\n", ++ i, j, (float) is_table_lsf[j][0][i], ++ (float) is_table_lsf[j][1][i]); ++ } ++ } + ++ for (i = 0; i < 8; i++) { ++ float ci, cs, ca; ++ ci = ci_table[i]; ++ cs = 1.0 / sqrt(1.0 + ci * ci); ++ ca = cs * ci; ++#if !CONFIG_FLOAT ++ csa_table[i][0] = FIXHR(cs/4); ++ csa_table[i][1] = FIXHR(ca/4); ++ csa_table[i][2] = FIXHR(ca/4) + FIXHR(cs/4); ++ csa_table[i][3] = FIXHR(ca/4) - FIXHR(cs/4); + #else +- +-static inline int round_sample(int64_t *sum) +-{ +- int sum1; +- sum1 = (int)((*sum) >> OUT_SHIFT); +- *sum &= (1<> (16 - WFRAC_BITS); ++ csa_table[i][0] = cs; ++ csa_table[i][1] = ca; ++ csa_table[i][2] = ca + cs; ++ csa_table[i][3] = ca - cs; + #endif +- window[i] = v; +- if ((i & 63) != 0) +- v = -v; +- if (i != 0) +- window[512 - i] = v; + } +- +- // Needed for avoiding shuffles in ASM implementations +- for(i=0; i < 8; i++) +- for(j=0; j < 16; j++) +- window[512+16*i+j] = window[64*i+32-j]; +- +- for(i=0; i < 8; i++) +- for(j=0; j < 16; j++) +- window[512+128+16*i+j] = window[64*i+48-j]; + } + +-static void apply_window_mp3_c(MPA_INT *synth_buf, MPA_INT *window, +- int *dither_state, OUT_INT *samples, int incr) ++static av_cold int decode_init(AVCodecContext * avctx) + { +- register const MPA_INT *w, *w2, *p; +- int j; +- OUT_INT *samples2; +-#if CONFIG_FLOAT +- float sum, sum2; +-#elif FRAC_BITS <= 15 +- int sum, sum2; +-#else +- int64_t sum, sum2; +-#endif ++ static int initialized_tables = 0; ++ MPADecodeContext *s = avctx->priv_data; + +- /* copy to avoid wrap */ +- memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); ++ if (!initialized_tables) { ++ decode_init_static(); ++ initialized_tables = 1; ++ } + +- samples2 = samples + 31 * incr; +- w = window; +- w2 = window + 31; +- +- sum = *dither_state; +- p = synth_buf + 16; +- SUM8(MACS, sum, w, p); +- p = synth_buf + 48; +- SUM8(MLSS, sum, w + 32, p); +- *samples = round_sample(&sum); +- samples += incr; +- w++; +- +- /* we calculate two samples at the same time to avoid one memory +- access per two sample */ +- for(j=1;j<16;j++) { +- sum2 = 0; +- p = synth_buf + 16 + j; +- SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); +- p = synth_buf + 48 - j; +- SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); +- +- *samples = round_sample(&sum); +- samples += incr; +- sum += sum2; +- *samples2 = round_sample(&sum); +- samples2 -= incr; +- w++; +- w2--; +- } +- +- p = synth_buf + 32; +- SUM8(MLSS, sum, w + 32, p); +- *samples = round_sample(&sum); +- *dither_state= sum; +-} ++ s->avctx = avctx; + ++ ff_mpadsp_init(&s->mpadsp); + +-/* 32 sub band synthesis filter. Input: 32 sub band samples, Output: +- 32 samples. */ +-/* XXX: optimize by avoiding ring buffer usage */ +-#if !CONFIG_FLOAT +-void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, +- MPA_INT *window, int *dither_state, +- OUT_INT *samples, int incr, +- INTFLOAT sb_samples[SBLIMIT]) +-{ +- register MPA_INT *synth_buf; +- int offset; +-#if FRAC_BITS <= 15 +- int32_t tmp[32]; +- int j; +-#endif +- +- offset = *synth_buf_offset; +- synth_buf = synth_buf_ptr + offset; ++ avctx->sample_fmt= OUT_FMT; ++ s->err_recognition = avctx->err_recognition; + +-#if FRAC_BITS <= 15 +- dct32(tmp, sb_samples); +- for(j=0;j<32;j++) { +- /* NOTE: can cause a loss in precision if very high amplitude +- sound */ +- synth_buf[j] = av_clip_int16(tmp[j]); +- } +-#else +- dct32(synth_buf, sb_samples); +-#endif ++ if (avctx->codec_id == CODEC_ID_MP3ADU) ++ s->adu_mode = 1; + +- apply_window_mp3_c(synth_buf, window, dither_state, samples, incr); ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; + +- offset = (offset - 32) & 511; +- *synth_buf_offset = offset; ++ return 0; + } +-#endif + + #define C3 FIXHR(0.86602540378443864676/2) +- +-/* 0.5 / cos(pi*(2*i+1)/36) */ +-static const INTFLOAT icos36[9] = { +- FIXR(0.50190991877167369479), +- FIXR(0.51763809020504152469), //0 +- FIXR(0.55168895948124587824), +- FIXR(0.61038729438072803416), +- FIXR(0.70710678118654752439), //1 +- FIXR(0.87172339781054900991), +- FIXR(1.18310079157624925896), +- FIXR(1.93185165257813657349), //2 +- FIXR(5.73685662283492756461), +-}; +- +-/* 0.5 / cos(pi*(2*i+1)/36) */ +-static const INTFLOAT icos36h[9] = { +- FIXHR(0.50190991877167369479/2), +- FIXHR(0.51763809020504152469/2), //0 +- FIXHR(0.55168895948124587824/2), +- FIXHR(0.61038729438072803416/2), +- FIXHR(0.70710678118654752439/2), //1 +- FIXHR(0.87172339781054900991/2), +- FIXHR(1.18310079157624925896/4), +- FIXHR(1.93185165257813657349/4), //2 +-// FIXHR(5.73685662283492756461), +-}; ++#define C4 FIXHR(0.70710678118654752439/2) //0.5 / cos(pi*(9)/36) ++#define C5 FIXHR(0.51763809020504152469/2) //0.5 / cos(pi*(5)/36) ++#define C6 FIXHR(1.93185165257813657349/4) //0.5 / cos(pi*(15)/36) + + /* 12 points IMDCT. We compute it "by hand" by factorizing obvious + cases. */ +@@ -769,133 +458,41 @@ + { + INTFLOAT in0, in1, in2, in3, in4, in5, t1, t2; + +- in0= in[0*3]; +- in1= in[1*3] + in[0*3]; +- in2= in[2*3] + in[1*3]; +- in3= in[3*3] + in[2*3]; +- in4= in[4*3] + in[3*3]; +- in5= in[5*3] + in[4*3]; ++ in0 = in[0*3]; ++ in1 = in[1*3] + in[0*3]; ++ in2 = in[2*3] + in[1*3]; ++ in3 = in[3*3] + in[2*3]; ++ in4 = in[4*3] + in[3*3]; ++ in5 = in[5*3] + in[4*3]; + in5 += in3; + in3 += in1; + +- in2= MULH3(in2, C3, 2); +- in3= MULH3(in3, C3, 4); ++ in2 = MULH3(in2, C3, 2); ++ in3 = MULH3(in3, C3, 4); + +- t1 = in0 - in4; +- t2 = MULH3(in1 - in5, icos36h[4], 2); ++ t1 = in0 - in4; ++ t2 = MULH3(in1 - in5, C4, 2); + +- out[ 7]= +- out[10]= t1 + t2; +- out[ 1]= +- out[ 4]= t1 - t2; +- +- in0 += SHR(in4, 1); +- in4 = in0 + in2; +- in5 += 2*in1; +- in1 = MULH3(in5 + in3, icos36h[1], 1); +- out[ 8]= +- out[ 9]= in4 + in1; +- out[ 2]= +- out[ 3]= in4 - in1; +- +- in0 -= in2; +- in5 = MULH3(in5 - in3, icos36h[7], 2); +- out[ 0]= +- out[ 5]= in0 - in5; +- out[ 6]= +- out[11]= in0 + in5; +-} +- +-/* cos(pi*i/18) */ +-#define C1 FIXHR(0.98480775301220805936/2) +-#define C2 FIXHR(0.93969262078590838405/2) +-#define C3 FIXHR(0.86602540378443864676/2) +-#define C4 FIXHR(0.76604444311897803520/2) +-#define C5 FIXHR(0.64278760968653932632/2) +-#define C6 FIXHR(0.5/2) +-#define C7 FIXHR(0.34202014332566873304/2) +-#define C8 FIXHR(0.17364817766693034885/2) +- +- +-/* using Lee like decomposition followed by hand coded 9 points DCT */ +-static void imdct36(INTFLOAT *out, INTFLOAT *buf, INTFLOAT *in, INTFLOAT *win) +-{ +- int i, j; +- INTFLOAT t0, t1, t2, t3, s0, s1, s2, s3; +- INTFLOAT tmp[18], *tmp1, *in1; +- +- for(i=17;i>=1;i--) +- in[i] += in[i-1]; +- for(i=17;i>=3;i-=2) +- in[i] += in[i-2]; +- +- for(j=0;j<2;j++) { +- tmp1 = tmp + j; +- in1 = in + j; +- +- t2 = in1[2*4] + in1[2*8] - in1[2*2]; +- +- t3 = in1[2*0] + SHR(in1[2*6],1); +- t1 = in1[2*0] - in1[2*6]; +- tmp1[ 6] = t1 - SHR(t2,1); +- tmp1[16] = t1 + t2; +- +- t0 = MULH3(in1[2*2] + in1[2*4] , C2, 2); +- t1 = MULH3(in1[2*4] - in1[2*8] , -2*C8, 1); +- t2 = MULH3(in1[2*2] + in1[2*8] , -C4, 2); +- +- tmp1[10] = t3 - t0 - t2; +- tmp1[ 2] = t3 + t0 + t1; +- tmp1[14] = t3 + t2 - t1; +- +- tmp1[ 4] = MULH3(in1[2*5] + in1[2*7] - in1[2*1], -C3, 2); +- t2 = MULH3(in1[2*1] + in1[2*5], C1, 2); +- t3 = MULH3(in1[2*5] - in1[2*7], -2*C7, 1); +- t0 = MULH3(in1[2*3], C3, 2); +- +- t1 = MULH3(in1[2*1] + in1[2*7], -C5, 2); +- +- tmp1[ 0] = t2 + t3 + t0; +- tmp1[12] = t2 + t1 - t0; +- tmp1[ 8] = t3 - t1 - t0; +- } +- +- i = 0; +- for(j=0;j<4;j++) { +- t0 = tmp[i]; +- t1 = tmp[i + 2]; +- s0 = t1 + t0; +- s2 = t1 - t0; +- +- t2 = tmp[i + 1]; +- t3 = tmp[i + 3]; +- s1 = MULH3(t3 + t2, icos36h[j], 2); +- s3 = MULLx(t3 - t2, icos36[8 - j], FRAC_BITS); +- +- t0 = s0 + s1; +- t1 = s0 - s1; +- out[(9 + j)*SBLIMIT] = MULH3(t1, win[9 + j], 1) + buf[9 + j]; +- out[(8 - j)*SBLIMIT] = MULH3(t1, win[8 - j], 1) + buf[8 - j]; +- buf[9 + j] = MULH3(t0, win[18 + 9 + j], 1); +- buf[8 - j] = MULH3(t0, win[18 + 8 - j], 1); +- +- t0 = s2 + s3; +- t1 = s2 - s3; +- out[(9 + 8 - j)*SBLIMIT] = MULH3(t1, win[9 + 8 - j], 1) + buf[9 + 8 - j]; +- out[( j)*SBLIMIT] = MULH3(t1, win[ j], 1) + buf[ j]; +- buf[9 + 8 - j] = MULH3(t0, win[18 + 9 + 8 - j], 1); +- buf[ + j] = MULH3(t0, win[18 + j], 1); +- i += 4; +- } +- +- s0 = tmp[16]; +- s1 = MULH3(tmp[17], icos36h[4], 2); +- t0 = s0 + s1; +- t1 = s0 - s1; +- out[(9 + 4)*SBLIMIT] = MULH3(t1, win[9 + 4], 1) + buf[9 + 4]; +- out[(8 - 4)*SBLIMIT] = MULH3(t1, win[8 - 4], 1) + buf[8 - 4]; +- buf[9 + 4] = MULH3(t0, win[18 + 9 + 4], 1); +- buf[8 - 4] = MULH3(t0, win[18 + 8 - 4], 1); ++ out[ 7] = ++ out[10] = t1 + t2; ++ out[ 1] = ++ out[ 4] = t1 - t2; ++ ++ in0 += SHR(in4, 1); ++ in4 = in0 + in2; ++ in5 += 2*in1; ++ in1 = MULH3(in5 + in3, C5, 1); ++ out[ 8] = ++ out[ 9] = in4 + in1; ++ out[ 2] = ++ out[ 3] = in4 - in1; ++ ++ in0 -= in2; ++ in5 = MULH3(in5 - in3, C6, 2); ++ out[ 0] = ++ out[ 5] = in0 - in5; ++ out[ 6] = ++ out[11] = in0 + in5; + } + + /* return the number of decoded frames */ +@@ -911,23 +508,22 @@ + bound = SBLIMIT; + + /* allocation bits */ +- for(i=0;inb_channels;ch++) { ++ for (i = 0; i < bound; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + allocation[ch][i] = get_bits(&s->gb, 4); + } + } +- for(i=bound;igb, 4); +- } + + /* scale factors */ +- for(i=0;inb_channels;ch++) { ++ for (i = 0; i < bound; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + if (allocation[ch][i]) + scale_factors[ch][i] = get_bits(&s->gb, 6); + } + } +- for(i=bound;igb, 6); + scale_factors[1][i] = get_bits(&s->gb, 6); +@@ -935,9 +531,9 @@ + } + + /* compute samples */ +- for(j=0;j<12;j++) { +- for(i=0;inb_channels;ch++) { ++ for (j = 0; j < 12; j++) { ++ for (i = 0; i < bound; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + n = allocation[ch][i]; + if (n) { + mant = get_bits(&s->gb, n + 1); +@@ -948,7 +544,7 @@ + s->sb_samples[ch][j][i] = v; + } + } +- for(i=bound;igb, n + 1); +@@ -977,8 +573,8 @@ + + /* select decoding table */ + table = ff_mpa_l2_select_table(s->bit_rate / 1000, s->nb_channels, +- s->sample_rate, s->lsf); +- sblimit = ff_mpa_sblimit_table[table]; ++ s->sample_rate, s->lsf); ++ sblimit = ff_mpa_sblimit_table[table]; + alloc_table = ff_mpa_alloc_tables[table]; + + if (s->mode == MPA_JSTEREO) +@@ -989,18 +585,18 @@ + av_dlog(s->avctx, "bound=%d sblimit=%d\n", bound, sblimit); + + /* sanity check */ +- if( bound > sblimit ) bound = sblimit; ++ if (bound > sblimit) ++ bound = sblimit; + + /* parse bit allocation */ + j = 0; +- for(i=0;inb_channels;ch++) { ++ for (ch = 0; ch < s->nb_channels; ch++) + bit_alloc[ch][i] = get_bits(&s->gb, bit_alloc_bits); +- } + j += 1 << bit_alloc_bits; + } +- for(i=bound;igb, bit_alloc_bits); + bit_alloc[0][i] = v; +@@ -1009,19 +605,19 @@ + } + + /* scale codes */ +- for(i=0;inb_channels;ch++) { ++ for (i = 0; i < sblimit; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + if (bit_alloc[ch][i]) + scale_code[ch][i] = get_bits(&s->gb, 2); + } + } + + /* scale factors */ +- for(i=0;inb_channels;ch++) { ++ for (i = 0; i < sblimit; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + if (bit_alloc[ch][i]) { + sf = scale_factors[ch][i]; +- switch(scale_code[ch][i]) { ++ switch (scale_code[ch][i]) { + default: + case 0: + sf[0] = get_bits(&s->gb, 6); +@@ -1049,12 +645,12 @@ + } + + /* samples */ +- for(k=0;k<3;k++) { +- for(l=0;l<12;l+=3) { ++ for (k = 0; k < 3; k++) { ++ for (l = 0; l < 12; l += 3) { + j = 0; +- for(i=0;inb_channels;ch++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + b = bit_alloc[ch][i]; + if (b) { + scale = scale_factors[ch][i][k]; +@@ -1068,13 +664,13 @@ + steps = ff_mpa_quant_steps[qindex]; + + s->sb_samples[ch][k * 12 + l + 0][i] = +- l2_unscale_group(steps, v2 & 15, scale); ++ l2_unscale_group(steps, v2 & 15, scale); + s->sb_samples[ch][k * 12 + l + 1][i] = + l2_unscale_group(steps, (v2 >> 4) & 15, scale); + s->sb_samples[ch][k * 12 + l + 2][i] = + l2_unscale_group(steps, v2 >> 8 , scale); + } else { +- for(m=0;m<3;m++) { ++ for (m = 0; m < 3; m++) { + v = get_bits(&s->gb, bits); + v = l1_unscale(bits - 1, v, scale); + s->sb_samples[ch][k * 12 + l + m][i] = v; +@@ -1090,7 +686,7 @@ + j += 1 << bit_alloc_bits; + } + /* XXX: find a way to avoid this duplication of code */ +- for(i=bound;isb_samples[1][k * 12 + l + 2][i] = + l2_unscale_group(steps, v, scale1); + } else { +- for(m=0;m<3;m++) { ++ for (m = 0; m < 3; m++) { + mant = get_bits(&s->gb, bits); + s->sb_samples[0][k * 12 + l + m][i] = + l1_unscale(bits - 1, mant, scale0); +@@ -1140,8 +736,8 @@ + j += 1 << bit_alloc_bits; + } + /* fill remaining samples to zero */ +- for(i=sblimit;inb_channels;ch++) { ++ for (i = sblimit; i < SBLIMIT; i++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + s->sb_samples[ch][k * 12 + l + 0][i] = 0; + s->sb_samples[ch][k * 12 + l + 1][i] = 0; + s->sb_samples[ch][k * 12 + l + 2][i] = 0; +@@ -1152,28 +748,28 @@ + return 3 * 12; + } + +-#define SPLIT(dst,sf,n)\ +- if(n==3){\ +- int m= (sf*171)>>9;\ +- dst= sf - 3*m;\ +- sf=m;\ +- }else if(n==4){\ +- dst= sf&3;\ +- sf>>=2;\ +- }else if(n==5){\ +- int m= (sf*205)>>10;\ +- dst= sf - 5*m;\ +- sf=m;\ +- }else if(n==6){\ +- int m= (sf*171)>>10;\ +- dst= sf - 6*m;\ +- sf=m;\ +- }else{\ +- dst=0;\ ++#define SPLIT(dst,sf,n) \ ++ if (n == 3) { \ ++ int m = (sf * 171) >> 9; \ ++ dst = sf - 3 * m; \ ++ sf = m; \ ++ } else if (n == 4) { \ ++ dst = sf & 3; \ ++ sf >>= 2; \ ++ } else if (n == 5) { \ ++ int m = (sf * 205) >> 10; \ ++ dst = sf - 5 * m; \ ++ sf = m; \ ++ } else if (n == 6) { \ ++ int m = (sf * 171) >> 10; \ ++ dst = sf - 6 * m; \ ++ sf = m; \ ++ } else { \ ++ dst = 0; \ + } + +-static av_always_inline void lsf_sf_expand(int *slen, +- int sf, int n1, int n2, int n3) ++static av_always_inline void lsf_sf_expand(int *slen, int sf, int n1, int n2, ++ int n3) + { + SPLIT(slen[3], sf, n3) + SPLIT(slen[2], sf, n2) +@@ -1181,8 +777,7 @@ + slen[0] = sf; + } + +-static void exponents_from_scale_factors(MPADecodeContext *s, +- GranuleDef *g, ++static void exponents_from_scale_factors(MPADecodeContext *s, GranuleDef *g, + int16_t *exponents) + { + const uint8_t *bstab, *pretab; +@@ -1190,30 +785,30 @@ + int16_t *exp_ptr; + + exp_ptr = exponents; +- gain = g->global_gain - 210; +- shift = g->scalefac_scale + 1; ++ gain = g->global_gain - 210; ++ shift = g->scalefac_scale + 1; + +- bstab = band_size_long[s->sample_rate_index]; ++ bstab = band_size_long[s->sample_rate_index]; + pretab = mpa_pretab[g->preflag]; +- for(i=0;ilong_end;i++) { ++ for (i = 0; i < g->long_end; i++) { + v0 = gain - ((g->scale_factors[i] + pretab[i]) << shift) + 400; + len = bstab[i]; +- for(j=len;j>0;j--) ++ for (j = len; j > 0; j--) + *exp_ptr++ = v0; + } + + if (g->short_start < 13) { +- bstab = band_size_short[s->sample_rate_index]; ++ bstab = band_size_short[s->sample_rate_index]; + gains[0] = gain - (g->subblock_gain[0] << 3); + gains[1] = gain - (g->subblock_gain[1] << 3); + gains[2] = gain - (g->subblock_gain[2] << 3); +- k = g->long_end; +- for(i=g->short_start;i<13;i++) { ++ k = g->long_end; ++ for (i = g->short_start; i < 13; i++) { + len = bstab[i]; +- for(l=0;l<3;l++) { ++ for (l = 0; l < 3; l++) { + v0 = gains[l] - (g->scale_factors[k++] << shift) + 400; +- for(j=len;j>0;j--) +- *exp_ptr++ = v0; ++ for (j = len; j > 0; j--) ++ *exp_ptr++ = v0; + } + } + } +@@ -1222,22 +817,21 @@ + /* handle n = 0 too */ + static inline int get_bitsz(GetBitContext *s, int n) + { +- if (n == 0) +- return 0; +- else +- return get_bits(s, n); ++ return n ? get_bits(s, n) : 0; + } + + +-static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, int *end_pos2){ +- if(s->in_gb.buffer && *pos >= s->gb.size_in_bits){ +- s->gb= s->in_gb; +- s->in_gb.buffer=NULL; ++static void switch_buffer(MPADecodeContext *s, int *pos, int *end_pos, ++ int *end_pos2) ++{ ++ if (s->in_gb.buffer && *pos >= s->gb.size_in_bits) { ++ s->gb = s->in_gb; ++ s->in_gb.buffer = NULL; + assert((get_bits_count(&s->gb) & 7) == 0); + skip_bits_long(&s->gb, *pos - *end_pos); +- *end_pos2= +- *end_pos= *end_pos2 + get_bits_count(&s->gb) - *pos; +- *pos= get_bits_count(&s->gb); ++ *end_pos2 = ++ *end_pos = *end_pos2 + get_bits_count(&s->gb) - *pos; ++ *pos = get_bits_count(&s->gb); + } + } + +@@ -1248,13 +842,13 @@ + *dst = v; + */ + #if CONFIG_FLOAT +-#define READ_FLIP_SIGN(dst,src)\ +- v = AV_RN32A(src) ^ (get_bits1(&s->gb)<<31);\ +- AV_WN32A(dst, v); ++#define READ_FLIP_SIGN(dst,src) \ ++ v = AV_RN32A(src) ^ (get_bits1(&s->gb) << 31); \ ++ AV_WN32A(dst, v); + #else +-#define READ_FLIP_SIGN(dst,src)\ +- v= -get_bits1(&s->gb);\ +- *(dst) = (*(src) ^ v) - v; ++#define READ_FLIP_SIGN(dst,src) \ ++ v = -get_bits1(&s->gb); \ ++ *(dst) = (*(src) ^ v) - v; + #endif + + static int huffman_decode(MPADecodeContext *s, GranuleDef *g, +@@ -1264,43 +858,43 @@ + int i; + int last_pos, bits_left; + VLC *vlc; +- int end_pos= FFMIN(end_pos2, s->gb.size_in_bits); ++ int end_pos = FFMIN(end_pos2, s->gb.size_in_bits); + + /* low frequencies (called big values) */ + s_index = 0; +- for(i=0;i<3;i++) { ++ for (i = 0; i < 3; i++) { + int j, k, l, linbits; + j = g->region_size[i]; + if (j == 0) + continue; + /* select vlc table */ +- k = g->table_select[i]; +- l = mpa_huff_data[k][0]; ++ k = g->table_select[i]; ++ l = mpa_huff_data[k][0]; + linbits = mpa_huff_data[k][1]; +- vlc = &huff_vlc[l]; ++ vlc = &huff_vlc[l]; + +- if(!l){ +- memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*2*j); +- s_index += 2*j; ++ if (!l) { ++ memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * 2 * j); ++ s_index += 2 * j; + continue; + } + + /* read huffcode and compute each couple */ +- for(;j>0;j--) { ++ for (; j > 0; j--) { + int exponent, x, y; + int v; +- int pos= get_bits_count(&s->gb); ++ int pos = get_bits_count(&s->gb); + + if (pos >= end_pos){ + // av_log(NULL, AV_LOG_ERROR, "pos: %d %d %d %d\n", pos, end_pos, end_pos2, s_index); + switch_buffer(s, &pos, &end_pos, &end_pos2); + // av_log(NULL, AV_LOG_ERROR, "new pos: %d %d\n", pos, end_pos); +- if(pos >= end_pos) ++ if (pos >= end_pos) + break; + } + y = get_vlc2(&s->gb, vlc->table, 7, 3); + +- if(!y){ ++ if (!y) { + g->sb_hybrid[s_index ] = + g->sb_hybrid[s_index+1] = 0; + s_index += 2; +@@ -1311,100 +905,100 @@ + + av_dlog(s->avctx, "region=%d n=%d x=%d y=%d exp=%d\n", + i, g->region_size[i] - j, x, y, exponent); +- if(y&16){ ++ if (y & 16) { + x = y >> 5; + y = y & 0x0f; +- if (x < 15){ +- READ_FLIP_SIGN(g->sb_hybrid+s_index, RENAME(expval_table)[ exponent ]+x) +- }else{ ++ if (x < 15) { ++ READ_FLIP_SIGN(g->sb_hybrid + s_index, RENAME(expval_table)[exponent] + x) ++ } else { + x += get_bitsz(&s->gb, linbits); +- v = l3_unscale(x, exponent); ++ v = l3_unscale(x, exponent); + if (get_bits1(&s->gb)) + v = -v; + g->sb_hybrid[s_index] = v; + } +- if (y < 15){ +- READ_FLIP_SIGN(g->sb_hybrid+s_index+1, RENAME(expval_table)[ exponent ]+y) +- }else{ ++ if (y < 15) { ++ READ_FLIP_SIGN(g->sb_hybrid + s_index + 1, RENAME(expval_table)[exponent] + y) ++ } else { + y += get_bitsz(&s->gb, linbits); +- v = l3_unscale(y, exponent); ++ v = l3_unscale(y, exponent); + if (get_bits1(&s->gb)) + v = -v; + g->sb_hybrid[s_index+1] = v; + } +- }else{ ++ } else { + x = y >> 5; + y = y & 0x0f; + x += y; +- if (x < 15){ +- READ_FLIP_SIGN(g->sb_hybrid+s_index+!!y, RENAME(expval_table)[ exponent ]+x) +- }else{ ++ if (x < 15) { ++ READ_FLIP_SIGN(g->sb_hybrid + s_index + !!y, RENAME(expval_table)[exponent] + x) ++ } else { + x += get_bitsz(&s->gb, linbits); +- v = l3_unscale(x, exponent); ++ v = l3_unscale(x, exponent); + if (get_bits1(&s->gb)) + v = -v; + g->sb_hybrid[s_index+!!y] = v; + } +- g->sb_hybrid[s_index+ !y] = 0; ++ g->sb_hybrid[s_index + !y] = 0; + } +- s_index+=2; ++ s_index += 2; + } + } + + /* high frequencies */ + vlc = &huff_quad_vlc[g->count1table_select]; +- last_pos=0; ++ last_pos = 0; + while (s_index <= 572) { + int pos, code; + pos = get_bits_count(&s->gb); + if (pos >= end_pos) { +- if (pos > end_pos2 && last_pos){ ++ if (pos > end_pos2 && last_pos) { + /* some encoders generate an incorrect size for this + part. We must go back into the data */ + s_index -= 4; + skip_bits_long(&s->gb, last_pos - pos); + av_log(s->avctx, AV_LOG_INFO, "overread, skip %d enddists: %d %d\n", last_pos - pos, end_pos-pos, end_pos2-pos); +- if(s->error_recognition >= FF_ER_COMPLIANT) ++ if(s->err_recognition & (AV_EF_BITSTREAM|AV_EF_COMPLIANT)) + s_index=0; + break; + } + // av_log(NULL, AV_LOG_ERROR, "pos2: %d %d %d %d\n", pos, end_pos, end_pos2, s_index); + switch_buffer(s, &pos, &end_pos, &end_pos2); + // av_log(NULL, AV_LOG_ERROR, "new pos2: %d %d %d\n", pos, end_pos, s_index); +- if(pos >= end_pos) ++ if (pos >= end_pos) + break; + } +- last_pos= pos; ++ last_pos = pos; + + code = get_vlc2(&s->gb, vlc->table, vlc->bits, 1); + av_dlog(s->avctx, "t=%d code=%d\n", g->count1table_select, code); +- g->sb_hybrid[s_index+0]= +- g->sb_hybrid[s_index+1]= +- g->sb_hybrid[s_index+2]= +- g->sb_hybrid[s_index+3]= 0; +- while(code){ +- static const int idxtab[16]={3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0}; ++ g->sb_hybrid[s_index+0] = ++ g->sb_hybrid[s_index+1] = ++ g->sb_hybrid[s_index+2] = ++ g->sb_hybrid[s_index+3] = 0; ++ while (code) { ++ static const int idxtab[16] = { 3,3,2,2,1,1,1,1,0,0,0,0,0,0,0,0 }; + int v; +- int pos= s_index+idxtab[code]; +- code ^= 8>>idxtab[code]; +- READ_FLIP_SIGN(g->sb_hybrid+pos, RENAME(exp_table)+exponents[pos]) ++ int pos = s_index + idxtab[code]; ++ code ^= 8 >> idxtab[code]; ++ READ_FLIP_SIGN(g->sb_hybrid + pos, RENAME(exp_table)+exponents[pos]) + } +- s_index+=4; ++ s_index += 4; + } + /* skip extension bits */ + bits_left = end_pos2 - get_bits_count(&s->gb); + //av_log(NULL, AV_LOG_ERROR, "left:%d buf:%p\n", bits_left, s->in_gb.buffer); +- if (bits_left < 0 && s->error_recognition >= FF_ER_COMPLIANT) { ++ if (bits_left < 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_COMPLIANT))) { + av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left); + s_index=0; +- }else if(bits_left > 0 && s->error_recognition >= FF_ER_AGGRESSIVE){ ++ } else if (bits_left > 0 && (s->err_recognition & (AV_EF_BUFFER|AV_EF_AGGRESSIVE))) { + av_log(s->avctx, AV_LOG_ERROR, "bits_left=%d\n", bits_left); +- s_index=0; ++ s_index = 0; + } +- memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid)*(576 - s_index)); ++ memset(&g->sb_hybrid[s_index], 0, sizeof(*g->sb_hybrid) * (576 - s_index)); + skip_bits_long(&s->gb, bits_left); + +- i= get_bits_count(&s->gb); ++ i = get_bits_count(&s->gb); + switch_buffer(s, &i, &end_pos, &end_pos2); + + return 0; +@@ -1423,34 +1017,32 @@ + return; + + if (g->switch_point) { +- if (s->sample_rate_index != 8) { ++ if (s->sample_rate_index != 8) + ptr = g->sb_hybrid + 36; +- } else { ++ else + ptr = g->sb_hybrid + 48; +- } + } else { + ptr = g->sb_hybrid; + } + +- for(i=g->short_start;i<13;i++) { +- len = band_size_short[s->sample_rate_index][i]; ++ for (i = g->short_start; i < 13; i++) { ++ len = band_size_short[s->sample_rate_index][i]; + ptr1 = ptr; +- dst = tmp; +- for(j=len;j>0;j--) { ++ dst = tmp; ++ for (j = len; j > 0; j--) { + *dst++ = ptr[0*len]; + *dst++ = ptr[1*len]; + *dst++ = ptr[2*len]; + ptr++; + } +- ptr+=2*len; ++ ptr += 2 * len; + memcpy(ptr1, tmp, len * 3 * sizeof(*ptr1)); + } + } + + #define ISQRT2 FIXR(0.70710678118654752440) + +-static void compute_stereo(MPADecodeContext *s, +- GranuleDef *g0, GranuleDef *g1) ++static void compute_stereo(MPADecodeContext *s, GranuleDef *g0, GranuleDef *g1) + { + int i, j, k, l; + int sf_max, sf, len, non_zero_found; +@@ -1474,17 +1066,17 @@ + non_zero_found_short[1] = 0; + non_zero_found_short[2] = 0; + k = (13 - g1->short_start) * 3 + g1->long_end - 3; +- for(i = 12;i >= g1->short_start;i--) { ++ for (i = 12; i >= g1->short_start; i--) { + /* for last band, use previous scale factor */ + if (i != 11) + k -= 3; + len = band_size_short[s->sample_rate_index][i]; +- for(l=2;l>=0;l--) { ++ for (l = 2; l >= 0; l--) { + tab0 -= len; + tab1 -= len; + if (!non_zero_found_short[l]) { + /* test if non zero band. if so, stop doing i-stereo */ +- for(j=0;jmode_ext & MODE_EXT_MS_STEREO) { + /* lower part of the spectrum : do ms stereo + if enabled */ +- for(j=0;jlong_end - 1;i >= 0;i--) { +- len = band_size_long[s->sample_rate_index][i]; ++ for (i = g1->long_end - 1;i >= 0;i--) { ++ len = band_size_long[s->sample_rate_index][i]; + tab0 -= len; + tab1 -= len; + /* test if non zero band. if so, stop doing i-stereo */ + if (!non_zero_found) { +- for(j=0;jscale_factors[k]; + if (sf >= sf_max) + goto found2; + v1 = is_tab[0][sf]; + v2 = is_tab[1][sf]; +- for(j=0;jmode_ext & MODE_EXT_MS_STEREO) { + /* lower part of the spectrum : do ms stereo + if enabled */ +- for(j=0;jsb_hybrid; + tab1 = g1->sb_hybrid; +- for(i=0;i<576;i++) { +- tmp0 = tab0[i]; +- tmp1 = tab1[i]; ++ for (i = 0; i < 576; i++) { ++ tmp0 = tab0[i]; ++ tmp1 = tab1[i]; + tab0[i] = tmp0 + tmp1; + tab1[i] = tmp0 - tmp1; + } + } + } + +-#if !CONFIG_FLOAT +-static void compute_antialias_integer(MPADecodeContext *s, +- GranuleDef *g) ++#if CONFIG_FLOAT ++#define AA(j) do { \ ++ float tmp0 = ptr[-1-j]; \ ++ float tmp1 = ptr[ j]; \ ++ ptr[-1-j] = tmp0 * csa_table[j][0] - tmp1 * csa_table[j][1]; \ ++ ptr[ j] = tmp0 * csa_table[j][1] + tmp1 * csa_table[j][0]; \ ++ } while (0) ++#else ++#define AA(j) do { \ ++ int tmp0 = ptr[-1-j]; \ ++ int tmp1 = ptr[ j]; \ ++ int tmp2 = MULH(tmp0 + tmp1, csa_table[j][0]); \ ++ ptr[-1-j] = 4 * (tmp2 - MULH(tmp1, csa_table[j][2])); \ ++ ptr[ j] = 4 * (tmp2 + MULH(tmp0, csa_table[j][3])); \ ++ } while (0) ++#endif ++ ++static void compute_antialias(MPADecodeContext *s, GranuleDef *g) + { +- int32_t *ptr, *csa; ++ INTFLOAT *ptr; + int n, i; + + /* we antialias only "long" bands */ +@@ -1592,47 +1199,35 @@ + } + + ptr = g->sb_hybrid + 18; +- for(i = n;i > 0;i--) { +- int tmp0, tmp1, tmp2; +- csa = &csa_table[0][0]; +-#define INT_AA(j) \ +- tmp0 = ptr[-1-j];\ +- tmp1 = ptr[ j];\ +- tmp2= MULH(tmp0 + tmp1, csa[0+4*j]);\ +- ptr[-1-j] = 4*(tmp2 - MULH(tmp1, csa[2+4*j]));\ +- ptr[ j] = 4*(tmp2 + MULH(tmp0, csa[3+4*j])); +- +- INT_AA(0) +- INT_AA(1) +- INT_AA(2) +- INT_AA(3) +- INT_AA(4) +- INT_AA(5) +- INT_AA(6) +- INT_AA(7) ++ for (i = n; i > 0; i--) { ++ AA(0); ++ AA(1); ++ AA(2); ++ AA(3); ++ AA(4); ++ AA(5); ++ AA(6); ++ AA(7); + + ptr += 18; + } + } +-#endif + +-static void compute_imdct(MPADecodeContext *s, +- GranuleDef *g, +- INTFLOAT *sb_samples, +- INTFLOAT *mdct_buf) ++static void compute_imdct(MPADecodeContext *s, GranuleDef *g, ++ INTFLOAT *sb_samples, INTFLOAT *mdct_buf) + { +- INTFLOAT *win, *win1, *out_ptr, *ptr, *buf, *ptr1; ++ INTFLOAT *win, *out_ptr, *ptr, *buf, *ptr1; + INTFLOAT out2[12]; + int i, j, mdct_long_end, sblimit; + + /* find last non zero block */ +- ptr = g->sb_hybrid + 576; ++ ptr = g->sb_hybrid + 576; + ptr1 = g->sb_hybrid + 2 * 18; + while (ptr >= ptr1) { + int32_t *p; + ptr -= 6; +- p= (int32_t*)ptr; +- if(p[0] | p[1] | p[2] | p[3] | p[4] | p[5]) ++ p = (int32_t*)ptr; ++ if (p[0] | p[1] | p[2] | p[3] | p[4] | p[5]) + break; + } + sblimit = ((ptr - g->sb_hybrid) / 18) + 1; +@@ -1647,70 +1242,60 @@ + mdct_long_end = sblimit; + } + +- buf = mdct_buf; +- ptr = g->sb_hybrid; +- for(j=0;jswitch_point && j < 2) +- win1 = mdct_win[0]; +- else +- win1 = mdct_win[g->block_type]; +- /* select frequency inversion */ +- win = win1 + ((4 * 36) & -(j & 1)); +- imdct36(out_ptr, buf, ptr, win); +- out_ptr += 18*SBLIMIT; +- ptr += 18; +- buf += 18; +- } +- for(j=mdct_long_end;jmpadsp.RENAME(imdct36_blocks)(sb_samples, mdct_buf, g->sb_hybrid, ++ mdct_long_end, g->switch_point, ++ g->block_type); ++ ++ buf = mdct_buf + 4*18*(mdct_long_end >> 2) + (mdct_long_end & 3); ++ ptr = g->sb_hybrid + 18 * mdct_long_end; ++ ++ for (j = mdct_long_end; j < sblimit; j++) { + /* select frequency inversion */ +- win = mdct_win[2] + ((4 * 36) & -(j & 1)); ++ win = RENAME(ff_mdct_win)[2 + (4 & -(j & 1))]; + out_ptr = sb_samples + j; + +- for(i=0; i<6; i++){ +- *out_ptr = buf[i]; ++ for (i = 0; i < 6; i++) { ++ *out_ptr = buf[4*i]; + out_ptr += SBLIMIT; + } + imdct12(out2, ptr + 0); +- for(i=0;i<6;i++) { +- *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[i + 6*1]; +- buf[i + 6*2] = MULH3(out2[i + 6], win[i + 6], 1); ++ for (i = 0; i < 6; i++) { ++ *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*1)]; ++ buf[4*(i + 6*2)] = MULH3(out2[i + 6], win[i + 6], 1); + out_ptr += SBLIMIT; + } + imdct12(out2, ptr + 1); +- for(i=0;i<6;i++) { +- *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[i + 6*2]; +- buf[i + 6*0] = MULH3(out2[i + 6], win[i + 6], 1); ++ for (i = 0; i < 6; i++) { ++ *out_ptr = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*2)]; ++ buf[4*(i + 6*0)] = MULH3(out2[i + 6], win[i + 6], 1); + out_ptr += SBLIMIT; + } + imdct12(out2, ptr + 2); +- for(i=0;i<6;i++) { +- buf[i + 6*0] = MULH3(out2[i ], win[i ], 1) + buf[i + 6*0]; +- buf[i + 6*1] = MULH3(out2[i + 6], win[i + 6], 1); +- buf[i + 6*2] = 0; ++ for (i = 0; i < 6; i++) { ++ buf[4*(i + 6*0)] = MULH3(out2[i ], win[i ], 1) + buf[4*(i + 6*0)]; ++ buf[4*(i + 6*1)] = MULH3(out2[i + 6], win[i + 6], 1); ++ buf[4*(i + 6*2)] = 0; + } + ptr += 18; +- buf += 18; ++ buf += (j&3) != 3 ? 1 : (4*18-3); + } + /* zero bands */ +- for(j=sblimit;jlsf) { + main_data_begin = get_bits(&s->gb, 8); +- private_bits = get_bits(&s->gb, s->nb_channels); ++ skip_bits(&s->gb, s->nb_channels); + nb_granules = 1; + } else { + main_data_begin = get_bits(&s->gb, 9); + if (s->nb_channels == 2) +- private_bits = get_bits(&s->gb, 3); ++ skip_bits(&s->gb, 3); + else +- private_bits = get_bits(&s->gb, 5); ++ skip_bits(&s->gb, 5); + nb_granules = 2; +- for(ch=0;chnb_channels;ch++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + s->granules[ch][0].scfsi = 0;/* all scale factors are transmitted */ + s->granules[ch][1].scfsi = get_bits(&s->gb, 4); + } + } + +- for(gr=0;grnb_channels;ch++) { ++ for (gr = 0; gr < nb_granules; gr++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + av_dlog(s->avctx, "gr=%d ch=%d: side_info\n", gr, ch); + g = &s->granules[ch][gr]; + g->part2_3_length = get_bits(&s->gb, 12); +- g->big_values = get_bits(&s->gb, 9); +- if(g->big_values > 288){ ++ g->big_values = get_bits(&s->gb, 9); ++ if (g->big_values > 288) { + av_log(s->avctx, AV_LOG_ERROR, "big_values too big\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + g->global_gain = get_bits(&s->gb, 8); +@@ -1757,21 +1342,21 @@ + blocksplit_flag = get_bits1(&s->gb); + if (blocksplit_flag) { + g->block_type = get_bits(&s->gb, 2); +- if (g->block_type == 0){ ++ if (g->block_type == 0) { + av_log(s->avctx, AV_LOG_ERROR, "invalid block type\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + g->switch_point = get_bits1(&s->gb); +- for(i=0;i<2;i++) ++ for (i = 0; i < 2; i++) + g->table_select[i] = get_bits(&s->gb, 5); +- for(i=0;i<3;i++) ++ for (i = 0; i < 3; i++) + g->subblock_gain[i] = get_bits(&s->gb, 3); + ff_init_short_region(s, g); + } else { + int region_address1, region_address2; + g->block_type = 0; + g->switch_point = 0; +- for(i=0;i<3;i++) ++ for (i = 0; i < 3; i++) + g->table_select[i] = get_bits(&s->gb, 5); + /* compute huffman coded region sizes */ + region_address1 = get_bits(&s->gb, 4); +@@ -1786,38 +1371,44 @@ + g->preflag = 0; + if (!s->lsf) + g->preflag = get_bits1(&s->gb); +- g->scalefac_scale = get_bits1(&s->gb); ++ g->scalefac_scale = get_bits1(&s->gb); + g->count1table_select = get_bits1(&s->gb); + av_dlog(s->avctx, "block_type=%d switch_point=%d\n", + g->block_type, g->switch_point); + } + } + +- if (!s->adu_mode) { +- const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); +- assert((get_bits_count(&s->gb) & 7) == 0); +- /* now we get bits from the main_data_begin offset */ +- av_dlog(s->avctx, "seekback: %d\n", main_data_begin); +-//av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); ++ if (!s->adu_mode) { ++ int skip; ++ const uint8_t *ptr = s->gb.buffer + (get_bits_count(&s->gb)>>3); ++ int extrasize = av_clip(get_bits_left(&s->gb) >> 3, 0, ++ FFMAX(0, LAST_BUF_SIZE - s->last_buf_size)); ++ assert((get_bits_count(&s->gb) & 7) == 0); ++ /* now we get bits from the main_data_begin offset */ ++ av_dlog(s->avctx, "seekback: %d\n", main_data_begin); ++ //av_log(NULL, AV_LOG_ERROR, "backstep:%d, lastbuf:%d\n", main_data_begin, s->last_buf_size); + +- memcpy(s->last_buf + s->last_buf_size, ptr, EXTRABYTES); +- s->in_gb= s->gb; ++ memcpy(s->last_buf + s->last_buf_size, ptr, extrasize); ++ s->in_gb = s->gb; + init_get_bits(&s->gb, s->last_buf, s->last_buf_size*8); ++#if !UNCHECKED_BITSTREAM_READER ++ s->gb.size_in_bits_plus8 += extrasize * 8; ++#endif + skip_bits_long(&s->gb, 8*(s->last_buf_size - main_data_begin)); +- } ++ } + +- for(gr=0;grnb_channels;ch++) { ++ for (gr = 0; gr < nb_granules; gr++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + g = &s->granules[ch][gr]; +- if(get_bits_count(&s->gb)<0){ ++ if (get_bits_count(&s->gb) < 0) { + av_log(s->avctx, AV_LOG_DEBUG, "mdb:%d, lastbuf:%d skipping granule %d\n", +- main_data_begin, s->last_buf_size, gr); ++ main_data_begin, s->last_buf_size, gr); + skip_bits_long(&s->gb, g->part2_3_length); + memset(g->sb_hybrid, 0, sizeof(g->sb_hybrid)); +- if(get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer){ ++ if (get_bits_count(&s->gb) >= s->gb.size_in_bits && s->in_gb.buffer) { + skip_bits_long(&s->in_gb, get_bits_count(&s->gb) - s->gb.size_in_bits); +- s->gb= s->in_gb; +- s->in_gb.buffer=NULL; ++ s->gb = s->in_gb; ++ s->in_gb.buffer = NULL; + } + continue; + } +@@ -1835,39 +1426,39 @@ + if (g->block_type == 2) { + n = g->switch_point ? 17 : 18; + j = 0; +- if(slen1){ +- for(i=0;iscale_factors[j++] = get_bits(&s->gb, slen1); +- }else{ +- for(i=0;iscale_factors[j++] = 0; + } +- if(slen2){ +- for(i=0;i<18;i++) ++ if (slen2) { ++ for (i = 0; i < 18; i++) + g->scale_factors[j++] = get_bits(&s->gb, slen2); +- for(i=0;i<3;i++) ++ for (i = 0; i < 3; i++) + g->scale_factors[j++] = 0; +- }else{ +- for(i=0;i<21;i++) ++ } else { ++ for (i = 0; i < 21; i++) + g->scale_factors[j++] = 0; + } + } else { + sc = s->granules[ch][0].scale_factors; + j = 0; +- for(k=0;k<4;k++) { +- n = (k == 0 ? 6 : 5); ++ for (k = 0; k < 4; k++) { ++ n = k == 0 ? 6 : 5; + if ((g->scfsi & (0x8 >> k)) == 0) { + slen = (k < 2) ? slen1 : slen2; +- if(slen){ +- for(i=0;iscale_factors[j++] = get_bits(&s->gb, slen); +- }else{ +- for(i=0;iscale_factors[j++] = 0; + } + } else { + /* simply copy from last granule */ +- for(i=0;iscale_factors[j] = sc[j]; + j++; + } +@@ -1879,11 +1470,11 @@ + int tindex, tindex2, slen[4], sl, sf; + + /* LSF scale factors */ +- if (g->block_type == 2) { ++ if (g->block_type == 2) + tindex = g->switch_point ? 2 : 1; +- } else { ++ else + tindex = 0; +- } ++ + sf = g->scalefac_compress; + if ((s->mode_ext & MODE_EXT_I_STEREO) && ch == 1) { + /* intensity stereo case */ +@@ -1914,19 +1505,19 @@ + } + + j = 0; +- for(k=0;k<4;k++) { +- n = lsf_nsf_table[tindex2][tindex][k]; ++ for (k = 0; k < 4; k++) { ++ n = lsf_nsf_table[tindex2][tindex][k]; + sl = slen[k]; +- if(sl){ +- for(i=0;iscale_factors[j++] = get_bits(&s->gb, sl); +- }else{ +- for(i=0;iscale_factors[j++] = 0; + } + } + /* XXX: should compute exact size */ +- for(;j<40;j++) ++ for (; j < 40; j++) + g->scale_factors[j] = 0; + } + +@@ -1939,7 +1530,7 @@ + if (s->nb_channels == 2) + compute_stereo(s, &s->granules[0][gr], &s->granules[1][gr]); + +- for(ch=0;chnb_channels;ch++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + g = &s->granules[ch][gr]; + + reorder_block(s, g); +@@ -1947,24 +1538,23 @@ + compute_imdct(s, g, &s->sb_samples[ch][18 * gr][0], s->mdct_buf[ch]); + } + } /* gr */ +- if(get_bits_count(&s->gb)<0) ++ if (get_bits_count(&s->gb) < 0) + skip_bits_long(&s->gb, -get_bits_count(&s->gb)); + return nb_granules * 18; + } + +-static int mp_decode_frame(MPADecodeContext *s, +- OUT_INT *samples, const uint8_t *buf, int buf_size) ++static int mp_decode_frame(MPADecodeContext *s, OUT_INT *samples, ++ const uint8_t *buf, int buf_size) + { +- int i, nb_frames, ch; ++ int i, nb_frames, ch, ret; + OUT_INT *samples_ptr; + +- init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE)*8); ++ init_get_bits(&s->gb, buf + HEADER_SIZE, (buf_size - HEADER_SIZE) * 8); + + /* skip error protection field */ + if (s->error_protection) + skip_bits(&s->gb, 16); + +- av_dlog(s->avctx, "frame %d:\n", s->frame_count); + switch(s->layer) { + case 1: + s->avctx->frame_size = 384; +@@ -1980,42 +1570,48 @@ + nb_frames = mp_decode_layer3(s); + + s->last_buf_size=0; +- if(s->in_gb.buffer){ ++ if (s->in_gb.buffer) { + align_get_bits(&s->gb); +- i= get_bits_left(&s->gb)>>3; +- if(i >= 0 && i <= BACKSTEP_SIZE){ ++ i = get_bits_left(&s->gb)>>3; ++ if (i >= 0 && i <= BACKSTEP_SIZE) { + memmove(s->last_buf, s->gb.buffer + (get_bits_count(&s->gb)>>3), i); + s->last_buf_size=i; +- }else ++ } else + av_log(s->avctx, AV_LOG_ERROR, "invalid old backstep %d\n", i); +- s->gb= s->in_gb; +- s->in_gb.buffer= NULL; ++ s->gb = s->in_gb; ++ s->in_gb.buffer = NULL; + } + + align_get_bits(&s->gb); + assert((get_bits_count(&s->gb) & 7) == 0); +- i= get_bits_left(&s->gb)>>3; ++ i = get_bits_left(&s->gb) >> 3; + +- if(i<0 || i > BACKSTEP_SIZE || nb_frames<0){ +- if(i<0) ++ if (i < 0 || i > BACKSTEP_SIZE || nb_frames < 0) { ++ if (i < 0) + av_log(s->avctx, AV_LOG_ERROR, "invalid new backstep %d\n", i); +- i= FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE); ++ i = FFMIN(BACKSTEP_SIZE, buf_size - HEADER_SIZE); + } +- assert(i <= buf_size - HEADER_SIZE && i>= 0); ++ assert(i <= buf_size - HEADER_SIZE && i >= 0); + memcpy(s->last_buf + s->last_buf_size, s->gb.buffer + buf_size - HEADER_SIZE - i, i); + s->last_buf_size += i; ++ } + +- break; ++ /* get output buffer */ ++ if (!samples) { ++ s->frame.nb_samples = s->avctx->frame_size; ++ if ((ret = s->avctx->get_buffer(s->avctx, &s->frame)) < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (OUT_INT *)s->frame.data[0]; + } + + /* apply the synthesis filter */ +- for(ch=0;chnb_channels;ch++) { ++ for (ch = 0; ch < s->nb_channels; ch++) { + samples_ptr = samples + ch; +- for(i=0;impadsp, + s->synth_buf[ch], &(s->synth_buf_offset[ch]), + RENAME(ff_mpa_synth_window), &s->dither_state, + samples_ptr, s->nb_channels, +@@ -2027,84 +1623,87 @@ + return nb_frames * 32 * sizeof(OUT_INT) * s->nb_channels; + } + +-static int decode_frame(AVCodecContext * avctx, +- void *data, int *data_size, ++static int decode_frame(AVCodecContext * avctx, void *data, int *got_frame_ptr, + AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; + MPADecodeContext *s = avctx->priv_data; + uint32_t header; + int out_size; +- OUT_INT *out_samples = data; + +- if(buf_size < HEADER_SIZE) +- return -1; ++ if (buf_size < HEADER_SIZE) ++ return AVERROR_INVALIDDATA; + + header = AV_RB32(buf); +- if(ff_mpa_check_header(header) < 0){ ++ if (ff_mpa_check_header(header) < 0) { + av_log(avctx, AV_LOG_ERROR, "Header missing\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { ++ if (avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) { + /* free format: prepare to compute frame size */ + s->frame_size = -1; +- return -1; ++ return AVERROR_INVALIDDATA; + } + /* update codec info */ +- avctx->channels = s->nb_channels; ++ avctx->channels = s->nb_channels; ++ avctx->channel_layout = s->nb_channels == 1 ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; + if (!avctx->bit_rate) + avctx->bit_rate = s->bit_rate; + avctx->sub_id = s->layer; + +- if(*data_size < 1152*avctx->channels*sizeof(OUT_INT)) +- return -1; +- *data_size = 0; +- +- if(s->frame_size<=0 || s->frame_size > buf_size){ ++ if (s->frame_size <= 0 || s->frame_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "incomplete frame\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + }else if(s->frame_size < buf_size){ +- av_log(avctx, AV_LOG_ERROR, "incorrect frame size\n"); ++ av_log(avctx, AV_LOG_DEBUG, "incorrect frame size - multiple frames in buffer?\n"); + buf_size= s->frame_size; + } + +- out_size = mp_decode_frame(s, out_samples, buf, buf_size); +- if(out_size>=0){ +- *data_size = out_size; ++ out_size = mp_decode_frame(s, NULL, buf, buf_size); ++ if (out_size >= 0) { ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + avctx->sample_rate = s->sample_rate; + //FIXME maybe move the other codec info stuff from above here too +- }else +- av_log(avctx, AV_LOG_DEBUG, "Error while decoding MPEG audio frame.\n"); //FIXME return -1 / but also return the number of bytes consumed ++ } else { ++ av_log(avctx, AV_LOG_ERROR, "Error while decoding MPEG audio frame.\n"); ++ /* Only return an error if the bad frame makes up the whole packet. ++ If there is more data in the packet, just consume the bad frame ++ instead of returning an error, which would discard the whole ++ packet. */ ++ *got_frame_ptr = 0; ++ if (buf_size == avpkt->size) ++ return out_size; ++ } + s->frame_size = 0; + return buf_size; + } + +-static void flush(AVCodecContext *avctx){ ++static void flush(AVCodecContext *avctx) ++{ + MPADecodeContext *s = avctx->priv_data; + memset(s->synth_buf, 0, sizeof(s->synth_buf)); +- s->last_buf_size= 0; ++ s->last_buf_size = 0; + } + + #if CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER +-static int decode_frame_adu(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int decode_frame_adu(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; + MPADecodeContext *s = avctx->priv_data; + uint32_t header; + int len, out_size; +- OUT_INT *out_samples = data; + + len = buf_size; + + // Discard too short frames + if (buf_size < HEADER_SIZE) { +- *data_size = 0; +- return buf_size; ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; + } + + +@@ -2115,27 +1714,30 @@ + header = AV_RB32(buf) | 0xffe00000; + + if (ff_mpa_check_header(header) < 0) { // Bad header, discard frame +- *data_size = 0; +- return buf_size; ++ av_log(avctx, AV_LOG_ERROR, "Invalid frame header\n"); ++ return AVERROR_INVALIDDATA; + } + +- ff_mpegaudio_decode_header((MPADecodeHeader *)s, header); ++ avpriv_mpegaudio_decode_header((MPADecodeHeader *)s, header); + /* update codec info */ + avctx->sample_rate = s->sample_rate; +- avctx->channels = s->nb_channels; ++ avctx->channels = s->nb_channels; + if (!avctx->bit_rate) + avctx->bit_rate = s->bit_rate; + avctx->sub_id = s->layer; + + s->frame_size = len; + +- if (avctx->parse_only) { ++#if FF_API_PARSE_FRAME ++ if (avctx->parse_only) + out_size = buf_size; +- } else { +- out_size = mp_decode_frame(s, out_samples, buf, buf_size); +- } ++ else ++#endif ++ out_size = mp_decode_frame(s, NULL, buf, buf_size); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + +- *data_size = out_size; + return buf_size; + } + #endif /* CONFIG_MP3ADU_DECODER || CONFIG_MP3ADUFLOAT_DECODER */ +@@ -2146,28 +1748,58 @@ + * Context for MP3On4 decoder + */ + typedef struct MP3On4DecodeContext { +- int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) +- int syncword; ///< syncword patch +- const uint8_t *coff; ///< channels offsets in output buffer ++ AVFrame *frame; ++ int frames; ///< number of mp3 frames per block (number of mp3 decoder instances) ++ int syncword; ///< syncword patch ++ const uint8_t *coff; ///< channel offsets in output buffer + MPADecodeContext *mp3decctx[5]; ///< MPADecodeContext for every decoder instance ++ OUT_INT *decoded_buf; ///< output buffer for decoded samples + } MP3On4DecodeContext; + + #include "mpeg4audio.h" + + /* Next 3 arrays are indexed by channel config number (passed via codecdata) */ +-static const uint8_t mp3Frames[8] = {0,1,1,2,3,3,4,5}; /* number of mp3 decoder instances */ +-/* offsets into output buffer, assume output order is FL FR BL BR C LFE */ ++ ++/* number of mp3 decoder instances */ ++static const uint8_t mp3Frames[8] = { 0, 1, 1, 2, 3, 3, 4, 5 }; ++ ++/* offsets into output buffer, assume output order is FL FR C LFE BL BR SL SR */ + static const uint8_t chan_offset[8][5] = { +- {0}, +- {0}, // C +- {0}, // FLR +- {2,0}, // C FLR +- {2,0,3}, // C FLR BS +- {4,0,2}, // C FLR BLRS +- {4,0,2,5}, // C FLR BLRS LFE +- {4,0,2,6,5}, // C FLR BLRS BLR LFE ++ { 0 }, ++ { 0 }, // C ++ { 0 }, // FLR ++ { 2, 0 }, // C FLR ++ { 2, 0, 3 }, // C FLR BS ++ { 2, 0, 3 }, // C FLR BLRS ++ { 2, 0, 4, 3 }, // C FLR BLRS LFE ++ { 2, 0, 6, 4, 3 }, // C FLR BLRS BLR LFE + }; + ++/* mp3on4 channel layouts */ ++static const int16_t chan_layout[8] = { ++ 0, ++ AV_CH_LAYOUT_MONO, ++ AV_CH_LAYOUT_STEREO, ++ AV_CH_LAYOUT_SURROUND, ++ AV_CH_LAYOUT_4POINT0, ++ AV_CH_LAYOUT_5POINT0, ++ AV_CH_LAYOUT_5POINT1, ++ AV_CH_LAYOUT_7POINT1 ++}; ++ ++static av_cold int decode_close_mp3on4(AVCodecContext * avctx) ++{ ++ MP3On4DecodeContext *s = avctx->priv_data; ++ int i; ++ ++ for (i = 0; i < s->frames; i++) ++ av_free(s->mp3decctx[i]); ++ ++ av_freep(&s->decoded_buf); ++ ++ return 0; ++} ++ + + static int decode_init_mp3on4(AVCodecContext * avctx) + { +@@ -2177,17 +1809,19 @@ + + if ((avctx->extradata_size < 2) || (avctx->extradata == NULL)) { + av_log(avctx, AV_LOG_ERROR, "Codec extradata missing or too short.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- ff_mpeg4audio_get_config(&cfg, avctx->extradata, avctx->extradata_size); ++ avpriv_mpeg4audio_get_config(&cfg, avctx->extradata, ++ avctx->extradata_size * 8, 1); + if (!cfg.chan_config || cfg.chan_config > 7) { + av_log(avctx, AV_LOG_ERROR, "Invalid channel config number.\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } +- s->frames = mp3Frames[cfg.chan_config]; +- s->coff = chan_offset[cfg.chan_config]; +- avctx->channels = ff_mpeg4audio_channels[cfg.chan_config]; ++ s->frames = mp3Frames[cfg.chan_config]; ++ s->coff = chan_offset[cfg.chan_config]; ++ avctx->channels = ff_mpeg4audio_channels[cfg.chan_config]; ++ avctx->channel_layout = chan_layout[cfg.chan_config]; + + if (cfg.sample_rate < 16000) + s->syncword = 0xffe00000; +@@ -2201,9 +1835,12 @@ + */ + // Allocate zeroed memory for the first decoder context + s->mp3decctx[0] = av_mallocz(sizeof(MPADecodeContext)); ++ if (!s->mp3decctx[0]) ++ goto alloc_fail; + // Put decoder context in place to make init_decode() happy + avctx->priv_data = s->mp3decctx[0]; + decode_init(avctx); ++ s->frame = avctx->coded_frame; + // Restore mp3on4 context pointer + avctx->priv_data = s; + s->mp3decctx[0]->adu_mode = 1; // Set adu mode +@@ -2213,85 +1850,114 @@ + */ + for (i = 1; i < s->frames; i++) { + s->mp3decctx[i] = av_mallocz(sizeof(MPADecodeContext)); ++ if (!s->mp3decctx[i]) ++ goto alloc_fail; + s->mp3decctx[i]->adu_mode = 1; + s->mp3decctx[i]->avctx = avctx; ++ s->mp3decctx[i]->mpadsp = s->mp3decctx[0]->mpadsp; ++ } ++ ++ /* Allocate buffer for multi-channel output if needed */ ++ if (s->frames > 1) { ++ s->decoded_buf = av_malloc(MPA_FRAME_SIZE * MPA_MAX_CHANNELS * ++ sizeof(*s->decoded_buf)); ++ if (!s->decoded_buf) ++ goto alloc_fail; + } + + return 0; ++alloc_fail: ++ decode_close_mp3on4(avctx); ++ return AVERROR(ENOMEM); + } + + +-static av_cold int decode_close_mp3on4(AVCodecContext * avctx) ++static void flush_mp3on4(AVCodecContext *avctx) + { +- MP3On4DecodeContext *s = avctx->priv_data; + int i; ++ MP3On4DecodeContext *s = avctx->priv_data; + +- for (i = 0; i < s->frames; i++) +- if (s->mp3decctx[i]) +- av_free(s->mp3decctx[i]); +- +- return 0; ++ for (i = 0; i < s->frames; i++) { ++ MPADecodeContext *m = s->mp3decctx[i]; ++ memset(m->synth_buf, 0, sizeof(m->synth_buf)); ++ m->last_buf_size = 0; ++ } + } + + +-static int decode_frame_mp3on4(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int decode_frame_mp3on4(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; + MP3On4DecodeContext *s = avctx->priv_data; + MPADecodeContext *m; + int fsize, len = buf_size, out_size = 0; + uint32_t header; +- OUT_INT *out_samples = data; +- OUT_INT decoded_buf[MPA_FRAME_SIZE * MPA_MAX_CHANNELS]; ++ OUT_INT *out_samples; + OUT_INT *outptr, *bp; +- int fr, j, n; ++ int fr, j, n, ch, ret; + +- if(*data_size < MPA_FRAME_SIZE * MPA_MAX_CHANNELS * s->frames * sizeof(OUT_INT)) +- return -1; ++ /* get output buffer */ ++ s->frame->nb_samples = MPA_FRAME_SIZE; ++ if ((ret = avctx->get_buffer(avctx, s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out_samples = (OUT_INT *)s->frame->data[0]; + +- *data_size = 0; + // Discard too short frames + if (buf_size < HEADER_SIZE) +- return -1; ++ return AVERROR_INVALIDDATA; + + // If only one decoder interleave is not needed +- outptr = s->frames == 1 ? out_samples : decoded_buf; ++ outptr = s->frames == 1 ? out_samples : s->decoded_buf; + + avctx->bit_rate = 0; + ++ ch = 0; + for (fr = 0; fr < s->frames; fr++) { + fsize = AV_RB16(buf) >> 4; + fsize = FFMIN3(fsize, len, MPA_MAX_CODED_FRAME_SIZE); +- m = s->mp3decctx[fr]; +- assert (m != NULL); ++ m = s->mp3decctx[fr]; ++ assert(m != NULL); + ++ if (fsize < HEADER_SIZE) { ++ av_log(avctx, AV_LOG_ERROR, "Frame size smaller than header size\n"); ++ return AVERROR_INVALIDDATA; ++ } + header = (AV_RB32(buf) & 0x000fffff) | s->syncword; // patch header + + if (ff_mpa_check_header(header) < 0) // Bad header, discard block + break; + +- ff_mpegaudio_decode_header((MPADecodeHeader *)m, header); ++ avpriv_mpegaudio_decode_header((MPADecodeHeader *)m, header); ++ ++ if (ch + m->nb_channels > avctx->channels) { ++ av_log(avctx, AV_LOG_ERROR, "frame channel count exceeds codec " ++ "channel count\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ch += m->nb_channels; ++ + out_size += mp_decode_frame(m, outptr, buf, fsize); +- buf += fsize; +- len -= fsize; ++ buf += fsize; ++ len -= fsize; + +- if(s->frames > 1) { ++ if (s->frames > 1) { + n = m->avctx->frame_size*m->nb_channels; + /* interleave output data */ + bp = out_samples + s->coff[fr]; +- if(m->nb_channels == 1) { +- for(j = 0; j < n; j++) { +- *bp = decoded_buf[j]; ++ if (m->nb_channels == 1) { ++ for (j = 0; j < n; j++) { ++ *bp = s->decoded_buf[j]; + bp += avctx->channels; + } + } else { +- for(j = 0; j < n; j++) { +- bp[0] = decoded_buf[j++]; +- bp[1] = decoded_buf[j]; +- bp += avctx->channels; ++ for (j = 0; j < n; j++) { ++ bp[0] = s->decoded_buf[j++]; ++ bp[1] = s->decoded_buf[j]; ++ bp += avctx->channels; + } + } + } +@@ -2301,89 +1967,95 @@ + /* update codec info */ + avctx->sample_rate = s->mp3decctx[0]->sample_rate; + +- *data_size = out_size; ++ s->frame->nb_samples = out_size / (avctx->channels * sizeof(OUT_INT)); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = *s->frame; ++ + return buf_size; + } + #endif /* CONFIG_MP3ON4_DECODER || CONFIG_MP3ON4FLOAT_DECODER */ + + #if !CONFIG_FLOAT + #if CONFIG_MP1_DECODER +-AVCodec ff_mp1_decoder = +-{ +- "mp1", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP1, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- NULL, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"), ++AVCodec ff_mp1_decoder = { ++ .name = "mp1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP1, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"), + }; + #endif + #if CONFIG_MP2_DECODER +-AVCodec ff_mp2_decoder = +-{ +- "mp2", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP2, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- NULL, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), ++AVCodec ff_mp2_decoder = { ++ .name = "mp2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP2, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), + }; + #endif + #if CONFIG_MP3_DECODER +-AVCodec ff_mp3_decoder = +-{ +- "mp3", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- NULL, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"), ++AVCodec ff_mp3_decoder = { ++ .name = "mp3", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"), + }; + #endif + #if CONFIG_MP3ADU_DECODER +-AVCodec ff_mp3adu_decoder = +-{ +- "mp3adu", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3ADU, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- NULL, +- decode_frame_adu, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"), ++AVCodec ff_mp3adu_decoder = { ++ .name = "mp3adu", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3ADU, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame_adu, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"), + }; + #endif + #if CONFIG_MP3ON4_DECODER +-AVCodec ff_mp3on4_decoder = +-{ +- "mp3on4", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3ON4, +- sizeof(MP3On4DecodeContext), +- decode_init_mp3on4, +- NULL, +- decode_close_mp3on4, +- decode_frame_mp3on4, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"), ++AVCodec ff_mp3on4_decoder = { ++ .name = "mp3on4", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3ON4, ++ .priv_data_size = sizeof(MP3On4DecodeContext), ++ .init = decode_init_mp3on4, ++ .close = decode_close_mp3on4, ++ .decode = decode_frame_mp3on4, ++ .capabilities = CODEC_CAP_DR1, ++ .flush = flush_mp3on4, ++ .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"), + }; + #endif + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodec_float.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodec_float.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodec_float.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodec_float.c 2012-05-14 14:08:54.034333944 +0200 +@@ -22,147 +22,85 @@ + #define CONFIG_FLOAT 1 + #include "mpegaudiodec.c" + +-void ff_mpa_synth_filter_float(MPADecodeContext *s, float *synth_buf_ptr, +- int *synth_buf_offset, +- float *window, int *dither_state, +- float *samples, int incr, +- float sb_samples[SBLIMIT]) +-{ +- float *synth_buf; +- int offset; +- +- offset = *synth_buf_offset; +- synth_buf = synth_buf_ptr + offset; +- +- s->dct.dct32(synth_buf, sb_samples); +- s->apply_window_mp3(synth_buf, window, dither_state, samples, incr); +- +- offset = (offset - 32) & 511; +- *synth_buf_offset = offset; +-} +- +-static void compute_antialias_float(MPADecodeContext *s, +- GranuleDef *g) +-{ +- float *ptr; +- int n, i; +- +- /* we antialias only "long" bands */ +- if (g->block_type == 2) { +- if (!g->switch_point) +- return; +- /* XXX: check this for 8000Hz case */ +- n = 1; +- } else { +- n = SBLIMIT - 1; +- } +- +- ptr = g->sb_hybrid + 18; +- for(i = n;i > 0;i--) { +- float tmp0, tmp1; +- float *csa = &csa_table_float[0][0]; +-#define FLOAT_AA(j)\ +- tmp0= ptr[-1-j];\ +- tmp1= ptr[ j];\ +- ptr[-1-j] = tmp0 * csa[0+4*j] - tmp1 * csa[1+4*j];\ +- ptr[ j] = tmp0 * csa[1+4*j] + tmp1 * csa[0+4*j]; +- +- FLOAT_AA(0) +- FLOAT_AA(1) +- FLOAT_AA(2) +- FLOAT_AA(3) +- FLOAT_AA(4) +- FLOAT_AA(5) +- FLOAT_AA(6) +- FLOAT_AA(7) +- +- ptr += 18; +- } +-} +- +-static av_cold int decode_end(AVCodecContext * avctx) +-{ +- MPADecodeContext *s = avctx->priv_data; +- ff_dct_end(&s->dct); +- return 0; +-} +- + #if CONFIG_MP1FLOAT_DECODER +-AVCodec ff_mp1float_decoder = +-{ +- "mp1float", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP1, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"), ++AVCodec ff_mp1float_decoder = { ++ .name = "mp1float", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP1, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP1 (MPEG audio layer 1)"), + }; + #endif + #if CONFIG_MP2FLOAT_DECODER +-AVCodec ff_mp2float_decoder = +-{ +- "mp2float", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP2, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), ++AVCodec ff_mp2float_decoder = { ++ .name = "mp2float", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP2, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), + }; + #endif + #if CONFIG_MP3FLOAT_DECODER +-AVCodec ff_mp3float_decoder = +-{ +- "mp3float", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"), ++AVCodec ff_mp3float_decoder = { ++ .name = "mp3float", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("MP3 (MPEG audio layer 3)"), + }; + #endif + #if CONFIG_MP3ADUFLOAT_DECODER +-AVCodec ff_mp3adufloat_decoder = +-{ +- "mp3adufloat", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3ADU, +- sizeof(MPADecodeContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame_adu, +- CODEC_CAP_PARSE_ONLY, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"), ++AVCodec ff_mp3adufloat_decoder = { ++ .name = "mp3adufloat", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3ADU, ++ .priv_data_size = sizeof(MPADecodeContext), ++ .init = decode_init, ++ .decode = decode_frame_adu, ++#if FF_API_PARSE_FRAME ++ .capabilities = CODEC_CAP_PARSE_ONLY | CODEC_CAP_DR1, ++#else ++ .capabilities = CODEC_CAP_DR1, ++#endif ++ .flush = flush, ++ .long_name = NULL_IF_CONFIG_SMALL("ADU (Application Data Unit) MP3 (MPEG audio layer 3)"), + }; + #endif + #if CONFIG_MP3ON4FLOAT_DECODER +-AVCodec ff_mp3on4float_decoder = +-{ +- "mp3on4float", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP3ON4, +- sizeof(MP3On4DecodeContext), +- decode_init_mp3on4, +- NULL, +- decode_close_mp3on4, +- decode_frame_mp3on4, +- .flush= flush, +- .long_name= NULL_IF_CONFIG_SMALL("MP3onMP4"), ++AVCodec ff_mp3on4float_decoder = { ++ .name = "mp3on4float", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP3ON4, ++ .priv_data_size = sizeof(MP3On4DecodeContext), ++ .init = decode_init_mp3on4, ++ .close = decode_close_mp3on4, ++ .decode = decode_frame_mp3on4, ++ .capabilities = CODEC_CAP_DR1, ++ .flush = flush_mp3on4, ++ .long_name = NULL_IF_CONFIG_SMALL("MP3onMP4"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodecheader.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodecheader.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodecheader.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodecheader.c 2012-05-14 14:08:54.035333964 +0200 +@@ -31,7 +31,7 @@ + #include "mpegaudiodecheader.h" + + +-int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) ++int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header) + { + int sample_rate, frame_size, mpeg25, padding; + int sample_rate_index, bitrate_index; +@@ -46,7 +46,7 @@ + s->layer = 4 - ((header >> 17) & 3); + /* extract frequency */ + sample_rate_index = (header >> 10) & 3; +- sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); ++ sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25); + sample_rate_index += 3 * (s->lsf + mpeg25); + s->sample_rate_index = sample_rate_index; + s->error_protection = ((header >> 16) & 1) ^ 1; +@@ -67,7 +67,7 @@ + s->nb_channels = 2; + + if (bitrate_index != 0) { +- frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; ++ frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index]; + s->bit_rate = frame_size * 1000; + switch(s->layer) { + case 1: +@@ -108,3 +108,40 @@ + #endif + return 0; + } ++ ++int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) ++{ ++ MPADecodeHeader s1, *s = &s1; ++ ++ if (ff_mpa_check_header(head) != 0) ++ return -1; ++ ++ if (avpriv_mpegaudio_decode_header(s, head) != 0) { ++ return -1; ++ } ++ ++ switch(s->layer) { ++ case 1: ++ avctx->codec_id = CODEC_ID_MP1; ++ *frame_size = 384; ++ break; ++ case 2: ++ avctx->codec_id = CODEC_ID_MP2; ++ *frame_size = 1152; ++ break; ++ default: ++ case 3: ++ avctx->codec_id = CODEC_ID_MP3; ++ if (s->lsf) ++ *frame_size = 576; ++ else ++ *frame_size = 1152; ++ break; ++ } ++ ++ *sample_rate = s->sample_rate; ++ *channels = s->nb_channels; ++ *bit_rate = s->bit_rate; ++ avctx->sub_id = s->layer; ++ return s->frame_size; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodecheader.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodecheader.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodecheader.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodecheader.h 2012-05-14 14:08:54.036333984 +0200 +@@ -27,13 +27,50 @@ + #ifndef AVCODEC_MPEGAUDIODECHEADER_H + #define AVCODEC_MPEGAUDIODECHEADER_H + +-#include "libavutil/common.h" +-#include "mpegaudio.h" ++#include "avcodec.h" + ++#define MP3_MASK 0xFFFE0CCF ++ ++#define MPA_DECODE_HEADER \ ++ int frame_size; \ ++ int error_protection; \ ++ int layer; \ ++ int sample_rate; \ ++ int sample_rate_index; /* between 0 and 8 */ \ ++ int bit_rate; \ ++ int nb_channels; \ ++ int mode; \ ++ int mode_ext; \ ++ int lsf; ++ ++typedef struct MPADecodeHeader { ++ MPA_DECODE_HEADER ++} MPADecodeHeader; + + /* header decoding. MUST check the header before because no + consistency check is done there. Return 1 if free format found and + that the frame size must be computed externally */ +-int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); ++int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header); ++ ++/* useful helper to get mpeg audio stream infos. Return -1 if error in ++ header, otherwise the coded frame size in bytes */ ++int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); ++ ++/* fast header check for resync */ ++static inline int ff_mpa_check_header(uint32_t header){ ++ /* header */ ++ if ((header & 0xffe00000) != 0xffe00000) ++ return -1; ++ /* layer check */ ++ if ((header & (3<<17)) == 0) ++ return -1; ++ /* bit rate */ ++ if ((header & (0xf<<12)) == 0xf<<12) ++ return -1; ++ /* frequency */ ++ if ((header & (3<<10)) == 3<<10) ++ return -1; ++ return 0; ++} + + #endif /* AVCODEC_MPEGAUDIODECHEADER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodectab.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodectab.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodectab.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodectab.h 2012-05-14 14:08:54.037334004 +0200 +@@ -27,12 +27,21 @@ + #ifndef AVCODEC_MPEGAUDIODECTAB_H + #define AVCODEC_MPEGAUDIODECTAB_H + ++#include + #include ++ + #include "mpegaudio.h" + + /*******************************************************/ + /* layer 3 tables */ + ++/* layer 3 huffman tables */ ++typedef struct HuffTable { ++ int xsize; ++ const uint8_t *bits; ++ const uint16_t *codes; ++} HuffTable; ++ + /* layer3 scale factor size */ + static const uint8_t slen_table[2][16] = { + { 0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp.c 2012-05-14 14:08:54.037334004 +0200 +@@ -0,0 +1,46 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "config.h" ++#include "mpegaudiodsp.h" ++#include "dct.h" ++#include "dct32.h" ++ ++void ff_mpadsp_init(MPADSPContext *s) ++{ ++ DCTContext dct; ++ ++ ff_dct_init(&dct, 5, DCT_II); ++ ff_init_mpadsp_tabs_float(); ++ ff_init_mpadsp_tabs_fixed(); ++ ++ s->apply_window_float = ff_mpadsp_apply_window_float; ++ s->apply_window_fixed = ff_mpadsp_apply_window_fixed; ++ ++ s->dct32_float = dct.dct32; ++ s->dct32_fixed = ff_dct32_fixed; ++ ++ s->imdct36_blocks_float = ff_imdct36_blocks_float; ++ s->imdct36_blocks_fixed = ff_imdct36_blocks_fixed; ++ ++ if (ARCH_ARM) ff_mpadsp_init_arm(s); ++ if (HAVE_MMX) ff_mpadsp_init_mmx(s); ++ if (HAVE_ALTIVEC) ff_mpadsp_init_altivec(s); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_fixed.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_fixed.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_fixed.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_fixed.c 2012-05-14 14:08:54.038334024 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FLOAT 0 ++#include "mpegaudiodsp_template.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_float.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_float.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_float.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_float.c 2012-05-14 14:08:54.039334044 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define CONFIG_FLOAT 1 ++#include "mpegaudiodsp_template.c" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp.h 2012-05-14 14:08:54.038334024 +0200 +@@ -0,0 +1,85 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_MPEGAUDIODSP_H ++#define AVCODEC_MPEGAUDIODSP_H ++ ++#include ++#include "libavutil/common.h" ++ ++typedef struct MPADSPContext { ++ void (*apply_window_float)(float *synth_buf, float *window, ++ int *dither_state, float *samples, int incr); ++ void (*apply_window_fixed)(int32_t *synth_buf, int32_t *window, ++ int *dither_state, int16_t *samples, int incr); ++ void (*dct32_float)(float *dst, const float *src); ++ void (*dct32_fixed)(int *dst, const int *src); ++ ++ void (*imdct36_blocks_float)(float *out, float *buf, float *in, ++ int count, int switch_point, int block_type); ++ void (*imdct36_blocks_fixed)(int *out, int *buf, int *in, ++ int count, int switch_point, int block_type); ++} MPADSPContext; ++ ++void ff_mpadsp_init(MPADSPContext *s); ++ ++extern int32_t ff_mpa_synth_window_fixed[]; ++extern float ff_mpa_synth_window_float[]; ++ ++void ff_mpa_synth_filter_fixed(MPADSPContext *s, ++ int32_t *synth_buf_ptr, int *synth_buf_offset, ++ int32_t *window, int *dither_state, ++ int16_t *samples, int incr, ++ int32_t *sb_samples); ++ ++void ff_mpa_synth_filter_float(MPADSPContext *s, ++ float *synth_buf_ptr, int *synth_buf_offset, ++ float *window, int *dither_state, ++ float *samples, int incr, ++ float *sb_samples); ++ ++void ff_mpadsp_init_arm(MPADSPContext *s); ++void ff_mpadsp_init_mmx(MPADSPContext *s); ++void ff_mpadsp_init_altivec(MPADSPContext *s); ++ ++void ff_mpa_synth_init_float(float *window); ++void ff_mpa_synth_init_fixed(int32_t *window); ++ ++void ff_mpadsp_apply_window_float(float *synth_buf, float *window, ++ int *dither_state, float *samples, ++ int incr); ++void ff_mpadsp_apply_window_fixed(int32_t *synth_buf, int32_t *window, ++ int *dither_state, int16_t *samples, ++ int incr); ++ ++void ff_imdct36_blocks_float(float *out, float *buf, float *in, ++ int count, int switch_point, int block_type); ++ ++void ff_imdct36_blocks_fixed(int *out, int *buf, int *in, ++ int count, int switch_point, int block_type); ++ ++void ff_init_mpadsp_tabs_float(void); ++void ff_init_mpadsp_tabs_fixed(void); ++ ++/** For SSE implementation, MDCT_BUF_SIZE/2 should be 128-bit aligned */ ++#define MDCT_BUF_SIZE FFALIGN(36, 2*4) ++ ++extern int ff_mdct_win_fixed[8][MDCT_BUF_SIZE]; ++extern float ff_mdct_win_float[8][MDCT_BUF_SIZE]; ++ ++#endif /* AVCODEC_MPEGAUDIODSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudiodsp_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudiodsp_template.c 2012-05-14 14:08:54.040334064 +0200 +@@ -0,0 +1,401 @@ ++/* ++ * Copyright (c) 2001, 2002 Fabrice Bellard ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "libavutil/mem.h" ++#include "dct32.h" ++#include "mathops.h" ++#include "mpegaudiodsp.h" ++#include "mpegaudio.h" ++#include "mpegaudiodata.h" ++ ++#if CONFIG_FLOAT ++#define RENAME(n) n##_float ++ ++static inline float round_sample(float *sum) ++{ ++ float sum1=*sum; ++ *sum = 0; ++ return sum1; ++} ++ ++#define MACS(rt, ra, rb) rt+=(ra)*(rb) ++#define MULS(ra, rb) ((ra)*(rb)) ++#define MULH3(x, y, s) ((s)*(y)*(x)) ++#define MLSS(rt, ra, rb) rt-=(ra)*(rb) ++#define MULLx(x, y, s) ((y)*(x)) ++#define FIXHR(x) ((float)(x)) ++#define FIXR(x) ((float)(x)) ++#define SHR(a,b) ((a)*(1.0f/(1<<(b)))) ++ ++#else ++ ++#define RENAME(n) n##_fixed ++#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15) ++ ++static inline int round_sample(int64_t *sum) ++{ ++ int sum1; ++ sum1 = (int)((*sum) >> OUT_SHIFT); ++ *sum &= (1<>(b)) ++# define FIXR(a) ((int)((a) * FRAC_ONE + 0.5)) ++# define FIXHR(a) ((int)((a) * (1LL<<32) + 0.5)) ++#endif ++ ++/** Window for MDCT. Actually only the elements in [0,17] and ++ [MDCT_BUF_SIZE/2, MDCT_BUF_SIZE/2 + 17] are actually used. The rest ++ is just to preserve alignment for SIMD implementations. ++*/ ++DECLARE_ALIGNED(16, INTFLOAT, RENAME(ff_mdct_win))[8][MDCT_BUF_SIZE]; ++ ++DECLARE_ALIGNED(16, MPA_INT, RENAME(ff_mpa_synth_window))[512+256]; ++ ++#define SUM8(op, sum, w, p) \ ++{ \ ++ op(sum, (w)[0 * 64], (p)[0 * 64]); \ ++ op(sum, (w)[1 * 64], (p)[1 * 64]); \ ++ op(sum, (w)[2 * 64], (p)[2 * 64]); \ ++ op(sum, (w)[3 * 64], (p)[3 * 64]); \ ++ op(sum, (w)[4 * 64], (p)[4 * 64]); \ ++ op(sum, (w)[5 * 64], (p)[5 * 64]); \ ++ op(sum, (w)[6 * 64], (p)[6 * 64]); \ ++ op(sum, (w)[7 * 64], (p)[7 * 64]); \ ++} ++ ++#define SUM8P2(sum1, op1, sum2, op2, w1, w2, p) \ ++{ \ ++ INTFLOAT tmp;\ ++ tmp = p[0 * 64];\ ++ op1(sum1, (w1)[0 * 64], tmp);\ ++ op2(sum2, (w2)[0 * 64], tmp);\ ++ tmp = p[1 * 64];\ ++ op1(sum1, (w1)[1 * 64], tmp);\ ++ op2(sum2, (w2)[1 * 64], tmp);\ ++ tmp = p[2 * 64];\ ++ op1(sum1, (w1)[2 * 64], tmp);\ ++ op2(sum2, (w2)[2 * 64], tmp);\ ++ tmp = p[3 * 64];\ ++ op1(sum1, (w1)[3 * 64], tmp);\ ++ op2(sum2, (w2)[3 * 64], tmp);\ ++ tmp = p[4 * 64];\ ++ op1(sum1, (w1)[4 * 64], tmp);\ ++ op2(sum2, (w2)[4 * 64], tmp);\ ++ tmp = p[5 * 64];\ ++ op1(sum1, (w1)[5 * 64], tmp);\ ++ op2(sum2, (w2)[5 * 64], tmp);\ ++ tmp = p[6 * 64];\ ++ op1(sum1, (w1)[6 * 64], tmp);\ ++ op2(sum2, (w2)[6 * 64], tmp);\ ++ tmp = p[7 * 64];\ ++ op1(sum1, (w1)[7 * 64], tmp);\ ++ op2(sum2, (w2)[7 * 64], tmp);\ ++} ++ ++void RENAME(ff_mpadsp_apply_window)(MPA_INT *synth_buf, MPA_INT *window, ++ int *dither_state, OUT_INT *samples, ++ int incr) ++{ ++ register const MPA_INT *w, *w2, *p; ++ int j; ++ OUT_INT *samples2; ++#if CONFIG_FLOAT ++ float sum, sum2; ++#else ++ int64_t sum, sum2; ++#endif ++ ++ /* copy to avoid wrap */ ++ memcpy(synth_buf + 512, synth_buf, 32 * sizeof(*synth_buf)); ++ ++ samples2 = samples + 31 * incr; ++ w = window; ++ w2 = window + 31; ++ ++ sum = *dither_state; ++ p = synth_buf + 16; ++ SUM8(MACS, sum, w, p); ++ p = synth_buf + 48; ++ SUM8(MLSS, sum, w + 32, p); ++ *samples = round_sample(&sum); ++ samples += incr; ++ w++; ++ ++ /* we calculate two samples at the same time to avoid one memory ++ access per two sample */ ++ for(j=1;j<16;j++) { ++ sum2 = 0; ++ p = synth_buf + 16 + j; ++ SUM8P2(sum, MACS, sum2, MLSS, w, w2, p); ++ p = synth_buf + 48 - j; ++ SUM8P2(sum, MLSS, sum2, MLSS, w + 32, w2 + 32, p); ++ ++ *samples = round_sample(&sum); ++ samples += incr; ++ sum += sum2; ++ *samples2 = round_sample(&sum); ++ samples2 -= incr; ++ w++; ++ w2--; ++ } ++ ++ p = synth_buf + 32; ++ SUM8(MLSS, sum, w + 32, p); ++ *samples = round_sample(&sum); ++ *dither_state= sum; ++} ++ ++/* 32 sub band synthesis filter. Input: 32 sub band samples, Output: ++ 32 samples. */ ++void RENAME(ff_mpa_synth_filter)(MPADSPContext *s, MPA_INT *synth_buf_ptr, ++ int *synth_buf_offset, ++ MPA_INT *window, int *dither_state, ++ OUT_INT *samples, int incr, ++ MPA_INT *sb_samples) ++{ ++ MPA_INT *synth_buf; ++ int offset; ++ ++ offset = *synth_buf_offset; ++ synth_buf = synth_buf_ptr + offset; ++ ++ s->RENAME(dct32)(synth_buf, sb_samples); ++ s->RENAME(apply_window)(synth_buf, window, dither_state, samples, incr); ++ ++ offset = (offset - 32) & 511; ++ *synth_buf_offset = offset; ++} ++ ++void av_cold RENAME(ff_mpa_synth_init)(MPA_INT *window) ++{ ++ int i, j; ++ ++ /* max = 18760, max sum over all 16 coefs : 44736 */ ++ for(i=0;i<257;i++) { ++ INTFLOAT v; ++ v = ff_mpa_enwindow[i]; ++#if CONFIG_FLOAT ++ v *= 1.0 / (1LL<<(16 + FRAC_BITS)); ++#endif ++ window[i] = v; ++ if ((i & 63) != 0) ++ v = -v; ++ if (i != 0) ++ window[512 - i] = v; ++ } ++ ++ ++ // Needed for avoiding shuffles in ASM implementations ++ for(i=0; i < 8; i++) ++ for(j=0; j < 16; j++) ++ window[512+16*i+j] = window[64*i+32-j]; ++ ++ for(i=0; i < 8; i++) ++ for(j=0; j < 16; j++) ++ window[512+128+16*i+j] = window[64*i+48-j]; ++} ++ ++void RENAME(ff_init_mpadsp_tabs)(void) ++{ ++ int i, j; ++ /* compute mdct windows */ ++ for (i = 0; i < 36; i++) { ++ for (j = 0; j < 4; j++) { ++ double d; ++ ++ if (j == 2 && i % 3 != 1) ++ continue; ++ ++ d = sin(M_PI * (i + 0.5) / 36.0); ++ if (j == 1) { ++ if (i >= 30) d = 0; ++ else if (i >= 24) d = sin(M_PI * (i - 18 + 0.5) / 12.0); ++ else if (i >= 18) d = 1; ++ } else if (j == 3) { ++ if (i < 6) d = 0; ++ else if (i < 12) d = sin(M_PI * (i - 6 + 0.5) / 12.0); ++ else if (i < 18) d = 1; ++ } ++ //merge last stage of imdct into the window coefficients ++ d *= 0.5 / cos(M_PI * (2 * i + 19) / 72); ++ ++ if (j == 2) ++ RENAME(ff_mdct_win)[j][i/3] = FIXHR((d / (1<<5))); ++ else { ++ int idx = i < 18 ? i : i + (MDCT_BUF_SIZE/2 - 18); ++ RENAME(ff_mdct_win)[j][idx] = FIXHR((d / (1<<5))); ++ } ++ } ++ } ++ ++ /* NOTE: we do frequency inversion adter the MDCT by changing ++ the sign of the right window coefs */ ++ for (j = 0; j < 4; j++) { ++ for (i = 0; i < MDCT_BUF_SIZE; i += 2) { ++ RENAME(ff_mdct_win)[j + 4][i ] = RENAME(ff_mdct_win)[j][i ]; ++ RENAME(ff_mdct_win)[j + 4][i + 1] = -RENAME(ff_mdct_win)[j][i + 1]; ++ } ++ } ++} ++/* cos(pi*i/18) */ ++#define C1 FIXHR(0.98480775301220805936/2) ++#define C2 FIXHR(0.93969262078590838405/2) ++#define C3 FIXHR(0.86602540378443864676/2) ++#define C4 FIXHR(0.76604444311897803520/2) ++#define C5 FIXHR(0.64278760968653932632/2) ++#define C6 FIXHR(0.5/2) ++#define C7 FIXHR(0.34202014332566873304/2) ++#define C8 FIXHR(0.17364817766693034885/2) ++ ++/* 0.5 / cos(pi*(2*i+1)/36) */ ++static const INTFLOAT icos36[9] = { ++ FIXR(0.50190991877167369479), ++ FIXR(0.51763809020504152469), //0 ++ FIXR(0.55168895948124587824), ++ FIXR(0.61038729438072803416), ++ FIXR(0.70710678118654752439), //1 ++ FIXR(0.87172339781054900991), ++ FIXR(1.18310079157624925896), ++ FIXR(1.93185165257813657349), //2 ++ FIXR(5.73685662283492756461), ++}; ++ ++/* 0.5 / cos(pi*(2*i+1)/36) */ ++static const INTFLOAT icos36h[9] = { ++ FIXHR(0.50190991877167369479/2), ++ FIXHR(0.51763809020504152469/2), //0 ++ FIXHR(0.55168895948124587824/2), ++ FIXHR(0.61038729438072803416/2), ++ FIXHR(0.70710678118654752439/2), //1 ++ FIXHR(0.87172339781054900991/2), ++ FIXHR(1.18310079157624925896/4), ++ FIXHR(1.93185165257813657349/4), //2 ++// FIXHR(5.73685662283492756461), ++}; ++ ++/* using Lee like decomposition followed by hand coded 9 points DCT */ ++static void imdct36(INTFLOAT *out, INTFLOAT *buf, INTFLOAT *in, INTFLOAT *win) ++{ ++ int i, j; ++ INTFLOAT t0, t1, t2, t3, s0, s1, s2, s3; ++ INTFLOAT tmp[18], *tmp1, *in1; ++ ++ for (i = 17; i >= 1; i--) ++ in[i] += in[i-1]; ++ for (i = 17; i >= 3; i -= 2) ++ in[i] += in[i-2]; ++ ++ for (j = 0; j < 2; j++) { ++ tmp1 = tmp + j; ++ in1 = in + j; ++ ++ t2 = in1[2*4] + in1[2*8] - in1[2*2]; ++ ++ t3 = in1[2*0] + SHR(in1[2*6],1); ++ t1 = in1[2*0] - in1[2*6]; ++ tmp1[ 6] = t1 - SHR(t2,1); ++ tmp1[16] = t1 + t2; ++ ++ t0 = MULH3(in1[2*2] + in1[2*4] , C2, 2); ++ t1 = MULH3(in1[2*4] - in1[2*8] , -2*C8, 1); ++ t2 = MULH3(in1[2*2] + in1[2*8] , -C4, 2); ++ ++ tmp1[10] = t3 - t0 - t2; ++ tmp1[ 2] = t3 + t0 + t1; ++ tmp1[14] = t3 + t2 - t1; ++ ++ tmp1[ 4] = MULH3(in1[2*5] + in1[2*7] - in1[2*1], -C3, 2); ++ t2 = MULH3(in1[2*1] + in1[2*5], C1, 2); ++ t3 = MULH3(in1[2*5] - in1[2*7], -2*C7, 1); ++ t0 = MULH3(in1[2*3], C3, 2); ++ ++ t1 = MULH3(in1[2*1] + in1[2*7], -C5, 2); ++ ++ tmp1[ 0] = t2 + t3 + t0; ++ tmp1[12] = t2 + t1 - t0; ++ tmp1[ 8] = t3 - t1 - t0; ++ } ++ ++ i = 0; ++ for (j = 0; j < 4; j++) { ++ t0 = tmp[i]; ++ t1 = tmp[i + 2]; ++ s0 = t1 + t0; ++ s2 = t1 - t0; ++ ++ t2 = tmp[i + 1]; ++ t3 = tmp[i + 3]; ++ s1 = MULH3(t3 + t2, icos36h[ j], 2); ++ s3 = MULLx(t3 - t2, icos36 [8 - j], FRAC_BITS); ++ ++ t0 = s0 + s1; ++ t1 = s0 - s1; ++ out[(9 + j) * SBLIMIT] = MULH3(t1, win[ 9 + j], 1) + buf[4*(9 + j)]; ++ out[(8 - j) * SBLIMIT] = MULH3(t1, win[ 8 - j], 1) + buf[4*(8 - j)]; ++ buf[4 * ( 9 + j )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + 9 + j], 1); ++ buf[4 * ( 8 - j )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + 8 - j], 1); ++ ++ t0 = s2 + s3; ++ t1 = s2 - s3; ++ out[(9 + 8 - j) * SBLIMIT] = MULH3(t1, win[ 9 + 8 - j], 1) + buf[4*(9 + 8 - j)]; ++ out[ j * SBLIMIT] = MULH3(t1, win[ j], 1) + buf[4*( j)]; ++ buf[4 * ( 9 + 8 - j )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + 9 + 8 - j], 1); ++ buf[4 * ( j )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + j], 1); ++ i += 4; ++ } ++ ++ s0 = tmp[16]; ++ s1 = MULH3(tmp[17], icos36h[4], 2); ++ t0 = s0 + s1; ++ t1 = s0 - s1; ++ out[(9 + 4) * SBLIMIT] = MULH3(t1, win[ 9 + 4], 1) + buf[4*(9 + 4)]; ++ out[(8 - 4) * SBLIMIT] = MULH3(t1, win[ 8 - 4], 1) + buf[4*(8 - 4)]; ++ buf[4 * ( 9 + 4 )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + 9 + 4], 1); ++ buf[4 * ( 8 - 4 )] = MULH3(t0, win[MDCT_BUF_SIZE/2 + 8 - 4], 1); ++} ++ ++void RENAME(ff_imdct36_blocks)(INTFLOAT *out, INTFLOAT *buf, INTFLOAT *in, ++ int count, int switch_point, int block_type) ++{ ++ int j; ++ for (j=0 ; j < count; j++) { ++ /* apply window & overlap with previous buffer */ ++ ++ /* select window */ ++ int win_idx = (switch_point && j < 2) ? 0 : block_type; ++ INTFLOAT *win = RENAME(ff_mdct_win)[win_idx + (4 & -(j & 1))]; ++ ++ imdct36(out, buf, in, win); ++ ++ in += 18; ++ buf += ((j&3) != 3 ? 1 : (72-3)); ++ out++; ++ } ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudioenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudioenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudioenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudioenc.c 2012-05-14 14:08:54.041334084 +0200 +@@ -25,10 +25,12 @@ + */ + + #include "avcodec.h" ++#include "internal.h" + #include "put_bits.h" + +-#undef CONFIG_MPEGAUDIO_HP +-#define CONFIG_MPEGAUDIO_HP 0 ++#define FRAC_BITS 15 /* fractional bits for sb_samples and dct */ ++#define WFRAC_BITS 14 /* fractional bits for window */ ++ + #include "mpegaudio.h" + + /* currently, cannot change these constants (need to modify +@@ -82,9 +84,9 @@ + /* encoding freq */ + s->lsf = 0; + for(i=0;i<3;i++) { +- if (ff_mpa_freq_tab[i] == freq) ++ if (avpriv_mpa_freq_tab[i] == freq) + break; +- if ((ff_mpa_freq_tab[i] / 2) == freq) { ++ if ((avpriv_mpa_freq_tab[i] / 2) == freq) { + s->lsf = 1; + break; + } +@@ -97,7 +99,7 @@ + + /* encoding bitrate & frequency */ + for(i=0;i<15;i++) { +- if (ff_mpa_bitrate_tab[s->lsf][1][i] == bitrate) ++ if (avpriv_mpa_bitrate_tab[s->lsf][1][i] == bitrate) + break; + } + if (i == 15){ +@@ -314,8 +316,6 @@ + int tmp1[32]; + int *out; + +- // print_pow1(samples, 1152); +- + offset = s->samples_offset[ch]; + out = &s->sb_samples[ch][0][0][0]; + for(j=0;j<36;j++) { +@@ -359,8 +359,6 @@ + } + } + s->samples_offset[ch] = offset; +- +- // print_pow(s->sb_samples, 1152); + } + + static void compute_scale_factors(unsigned char scale_code[SBLIMIT], +@@ -399,10 +397,8 @@ + index = 62; /* value 63 is not allowed */ + } + +-#if 0 +- printf("%2d:%d in=%x %x %d\n", +- j, i, vmax, scale_factor_table[index], index); +-#endif ++ av_dlog(NULL, "%2d:%d in=%x %x %d\n", ++ j, i, vmax, scale_factor_table[index], index); + /* store the scale factor */ + assert(index >=0 && index <= 63); + sf[i] = index; +@@ -470,10 +466,8 @@ + code = 0; /* kill warning */ + } + +-#if 0 +- printf("%d: %2d %2d %2d %d %d -> %d\n", j, +- sf[0], sf[1], sf[2], d1, d2, code); +-#endif ++ av_dlog(NULL, "%d: %2d %2d %2d %d %d -> %d\n", j, ++ sf[0], sf[1], sf[2], d1, d2, code); + scale_code[j] = code; + sf += 3; + } +@@ -547,13 +541,11 @@ + } + } + } +-#if 0 +- printf("current=%d max=%d max_sb=%d alloc=%d\n", +- current_frame_size, max_frame_size, max_sb, +- bit_alloc[max_sb]); +-#endif + if (max_sb < 0) + break; ++ av_dlog(NULL, "current=%d max=%d max_sb=%d max_ch=%d alloc=%d\n", ++ current_frame_size, max_frame_size, max_sb, max_ch, ++ bit_alloc[max_ch][max_sb]); + + /* find alloc table entry (XXX: not optimal, should use + pointer table) */ +@@ -591,13 +583,6 @@ + } + *padding = max_frame_size - current_frame_size; + assert(*padding >= 0); +- +-#if 0 +- for(i=0;isblimit;i++) { +- printf("%d ", bit_alloc[i]); +- } +- printf("\n"); +-#endif + } + + /* +@@ -719,15 +704,7 @@ + /* group the 3 values to save bits */ + put_bits(p, -bits, + q[0] + steps * (q[1] + steps * q[2])); +-#if 0 +- printf("%d: gr1 %d\n", +- i, q[0] + steps * (q[1] + steps * q[2])); +-#endif + } else { +-#if 0 +- printf("%d: gr3 %d %d %d\n", +- i, q[0], q[1], q[2]); +-#endif + put_bits(p, bits, q[0]); + put_bits(p, bits, q[1]); + put_bits(p, bits, q[2]); +@@ -783,18 +760,21 @@ + return 0; + } + ++static const AVCodecDefault mp2_defaults[] = { ++ { "b", "128k" }, ++ { NULL }, ++}; ++ + AVCodec ff_mp2_encoder = { +- "mp2", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_MP2, +- sizeof(MpegAudioContext), +- MPA_encode_init, +- MPA_encode_frame, +- MPA_encode_close, +- NULL, ++ .name = "mp2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_MP2, ++ .priv_data_size = sizeof(MpegAudioContext), ++ .init = MPA_encode_init, ++ .encode = MPA_encode_frame, ++ .close = MPA_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .supported_samplerates= (const int[]){44100, 48000, 32000, 22050, 24000, 16000, 0}, + .long_name = NULL_IF_CONFIG_SMALL("MP2 (MPEG audio layer 2)"), ++ .defaults = mp2_defaults, + }; +- +-#undef FIX +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio.h 2012-05-14 14:08:54.022333702 +0200 +@@ -30,12 +30,7 @@ + # define CONFIG_FLOAT 0 + #endif + +-#include "avcodec.h" +-#include "get_bits.h" +-#include "dsputil.h" +-#include "fft.h" +- +-#define CONFIG_AUDIO_NONSHORT 0 ++#include + + /* max frame size, in samples */ + #define MPA_FRAME_SIZE 1152 +@@ -52,18 +47,9 @@ + #define MPA_DUAL 2 + #define MPA_MONO 3 + +-/* header + layer + bitrate + freq + lsf/mpeg25 */ +-#define SAME_HEADER_MASK \ +- (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19)) +- +-#define MP3_MASK 0xFFFE0CCF +- +-#if CONFIG_MPEGAUDIO_HP ++#ifndef FRAC_BITS + #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */ + #define WFRAC_BITS 16 /* fractional bits for window */ +-#else +-#define FRAC_BITS 15 /* fractional bits for sb_samples and dct */ +-#define WFRAC_BITS 14 /* fractional bits for window */ + #endif + + #define FRAC_ONE (1 << FRAC_BITS) +@@ -71,140 +57,19 @@ + #define FIX(a) ((int)((a) * FRAC_ONE)) + + #if CONFIG_FLOAT +-typedef float OUT_INT; +-#define OUT_FMT AV_SAMPLE_FMT_FLT +-#elif CONFIG_MPEGAUDIO_HP && CONFIG_AUDIO_NONSHORT +-typedef int32_t OUT_INT; +-#define OUT_MAX INT32_MAX +-#define OUT_MIN INT32_MIN +-#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31) +-#define OUT_FMT AV_SAMPLE_FMT_S32 +-#else +-typedef int16_t OUT_INT; +-#define OUT_MAX INT16_MAX +-#define OUT_MIN INT16_MIN +-#define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15) +-#define OUT_FMT AV_SAMPLE_FMT_S16 +-#endif +- +-#if CONFIG_FLOAT + # define INTFLOAT float + typedef float MPA_INT; ++typedef float OUT_INT; + #elif FRAC_BITS <= 15 + # define INTFLOAT int + typedef int16_t MPA_INT; ++typedef int16_t OUT_INT; + #else + # define INTFLOAT int + typedef int32_t MPA_INT; ++typedef int16_t OUT_INT; + #endif + +-#define BACKSTEP_SIZE 512 +-#define EXTRABYTES 24 +- +-/* layer 3 "granule" */ +-typedef struct GranuleDef { +- uint8_t scfsi; +- int part2_3_length; +- int big_values; +- int global_gain; +- int scalefac_compress; +- uint8_t block_type; +- uint8_t switch_point; +- int table_select[3]; +- int subblock_gain[3]; +- uint8_t scalefac_scale; +- uint8_t count1table_select; +- int region_size[3]; /* number of huffman codes in each region */ +- int preflag; +- int short_start, long_end; /* long/short band indexes */ +- uint8_t scale_factors[40]; +- INTFLOAT sb_hybrid[SBLIMIT * 18]; /* 576 samples */ +-} GranuleDef; +- +-#define MPA_DECODE_HEADER \ +- int frame_size; \ +- int error_protection; \ +- int layer; \ +- int sample_rate; \ +- int sample_rate_index; /* between 0 and 8 */ \ +- int bit_rate; \ +- int nb_channels; \ +- int mode; \ +- int mode_ext; \ +- int lsf; +- +-typedef struct MPADecodeHeader { +- MPA_DECODE_HEADER +-} MPADecodeHeader; +- +-typedef struct MPADecodeContext { +- MPA_DECODE_HEADER +- uint8_t last_buf[2*BACKSTEP_SIZE + EXTRABYTES]; +- int last_buf_size; +- /* next header (used in free format parsing) */ +- uint32_t free_format_next_header; +- GetBitContext gb; +- GetBitContext in_gb; +- DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512 * 2]; +- int synth_buf_offset[MPA_MAX_CHANNELS]; +- DECLARE_ALIGNED(16, INTFLOAT, sb_samples)[MPA_MAX_CHANNELS][36][SBLIMIT]; +- INTFLOAT mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */ +- GranuleDef granules[2][2]; /* Used in Layer 3 */ +-#ifdef DEBUG +- int frame_count; +-#endif +- int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3 +- int dither_state; +- int error_recognition; +- AVCodecContext* avctx; +-#if CONFIG_FLOAT +- DCTContext dct; +-#endif +- void (*apply_window_mp3)(MPA_INT *synth_buf, MPA_INT *window, +- int *dither_state, OUT_INT *samples, int incr); +-} MPADecodeContext; +- +-/* layer 3 huffman tables */ +-typedef struct HuffTable { +- int xsize; +- const uint8_t *bits; +- const uint16_t *codes; +-} HuffTable; +- + int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf); +-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bitrate); +-extern MPA_INT ff_mpa_synth_window[]; +-void ff_mpa_synth_init(MPA_INT *window); +-void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset, +- MPA_INT *window, int *dither_state, +- OUT_INT *samples, int incr, +- INTFLOAT sb_samples[SBLIMIT]); +- +-void ff_mpa_synth_init_float(MPA_INT *window); +-void ff_mpa_synth_filter_float(MPADecodeContext *s, +- MPA_INT *synth_buf_ptr, int *synth_buf_offset, +- MPA_INT *window, int *dither_state, +- OUT_INT *samples, int incr, +- INTFLOAT sb_samples[SBLIMIT]); +- +-void ff_mpegaudiodec_init_mmx(MPADecodeContext *s); +-void ff_mpegaudiodec_init_altivec(MPADecodeContext *s); +- +-/* fast header check for resync */ +-static inline int ff_mpa_check_header(uint32_t header){ +- /* header */ +- if ((header & 0xffe00000) != 0xffe00000) +- return -1; +- /* layer check */ +- if ((header & (3<<17)) == 0) +- return -1; +- /* bit rate */ +- if ((header & (0xf<<12)) == 0xf<<12) +- return -1; +- /* frequency */ +- if ((header & (3<<10)) == 3<<10) +- return -1; +- return 0; +-} + + #endif /* AVCODEC_MPEGAUDIO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_parser.c 2012-05-14 14:08:54.023333722 +0200 +@@ -21,7 +21,6 @@ + */ + + #include "parser.h" +-#include "mpegaudio.h" + #include "mpegaudiodecheader.h" + + +@@ -35,49 +34,9 @@ + #define MPA_HEADER_SIZE 4 + + /* header + layer + bitrate + freq + lsf/mpeg25 */ +-#undef SAME_HEADER_MASK /* mpegaudio.h defines different version */ + #define SAME_HEADER_MASK \ + (0xffe00000 | (3 << 17) | (3 << 10) | (3 << 19)) + +-/* useful helper to get mpeg audio stream infos. Return -1 if error in +- header, otherwise the coded frame size in bytes */ +-int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) +-{ +- MPADecodeHeader s1, *s = &s1; +- +- if (ff_mpa_check_header(head) != 0) +- return -1; +- +- if (ff_mpegaudio_decode_header(s, head) != 0) { +- return -1; +- } +- +- switch(s->layer) { +- case 1: +- avctx->codec_id = CODEC_ID_MP1; +- *frame_size = 384; +- break; +- case 2: +- avctx->codec_id = CODEC_ID_MP2; +- *frame_size = 1152; +- break; +- default: +- case 3: +- avctx->codec_id = CODEC_ID_MP3; +- if (s->lsf) +- *frame_size = 576; +- else +- *frame_size = 1152; +- break; +- } +- +- *sample_rate = s->sample_rate; +- *channels = s->nb_channels; +- *bit_rate = s->bit_rate; +- avctx->sub_id = s->layer; +- return s->frame_size; +-} +- + static int mpegaudio_parse(AVCodecParserContext *s1, + AVCodecContext *avctx, + const uint8_t **poutbuf, int *poutbuf_size, +@@ -105,9 +64,10 @@ + + state= (state<<8) + buf[i++]; + +- ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate); ++ ret = avpriv_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate); + if (ret < 4) { +- s->header_count= -2; ++ if(i > 4) ++ s->header_count= -2; + } else { + if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header) + s->header_count= -3; +@@ -141,9 +101,8 @@ + + + AVCodecParser ff_mpegaudio_parser = { +- { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 }, +- sizeof(MpegAudioParseContext), +- NULL, +- mpegaudio_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 }, ++ .priv_data_size = sizeof(MpegAudioParseContext), ++ .parser_parse = mpegaudio_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_tablegen.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_tablegen.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_tablegen.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_tablegen.c 2012-05-14 14:08:54.024333742 +0200 +@@ -33,9 +33,9 @@ + + WRITE_ARRAY("static const", int8_t, table_4_3_exp); + WRITE_ARRAY("static const", uint32_t, table_4_3_value); +- WRITE_ARRAY("static const", uint32_t, exp_table); ++ WRITE_ARRAY("static const", uint32_t, exp_table_fixed); + WRITE_ARRAY("static const", float, exp_table_float); +- WRITE_2D_ARRAY("static const", uint32_t, expval_table); ++ WRITE_2D_ARRAY("static const", uint32_t, expval_table_fixed); + WRITE_2D_ARRAY("static const", float, expval_table_float); + + return 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegaudio_tablegen.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegaudio_tablegen.h 2012-05-14 14:08:54.024333742 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef MPEGAUDIO_TABLEGEN_H +-#define MPEGAUDIO_TABLEGEN_H ++#ifndef AVCODEC_MPEGAUDIO_TABLEGEN_H ++#define AVCODEC_MPEGAUDIO_TABLEGEN_H + + #include + #include +@@ -33,11 +33,13 @@ + #else + static int8_t table_4_3_exp[TABLE_4_3_SIZE]; + static uint32_t table_4_3_value[TABLE_4_3_SIZE]; +-static uint32_t exp_table[512]; +-static uint32_t expval_table[512][16]; ++static uint32_t exp_table_fixed[512]; ++static uint32_t expval_table_fixed[512][16]; + static float exp_table_float[512]; + static float expval_table_float[512][16]; + ++#define FRAC_BITS 23 ++ + static void mpegaudio_tableinit(void) + { + int i, value, exponent; +@@ -57,13 +59,13 @@ + for (exponent = 0; exponent < 512; exponent++) { + for (value = 0; value < 16; value++) { + double f = (double)value * cbrtf(value) * pow(2, (exponent - 400) * 0.25 + FRAC_BITS + 5); +- expval_table[exponent][value] = llrint(f); ++ expval_table_fixed[exponent][value] = llrint(f); + expval_table_float[exponent][value] = f; + } +- exp_table[exponent] = expval_table[exponent][1]; ++ exp_table_fixed[exponent] = expval_table_fixed[exponent][1]; + exp_table_float[exponent] = expval_table_float[exponent][1]; + } + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* MPEGAUDIO_TABLEGEN_H */ ++#endif /* AVCODEC_MPEGAUDIO_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c 2012-05-14 14:08:54.052334307 +0200 +@@ -28,7 +28,7 @@ + */ + + #include "libavutil/intmath.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "dsputil.h" + #include "internal.h" +@@ -38,6 +38,7 @@ + #include "msmpeg4.h" + #include "faandct.h" + #include "xvmc_internal.h" ++#include "thread.h" + #include + + //#undef NDEBUG +@@ -65,44 +66,61 @@ + //#define DEBUG + + +-static const uint8_t ff_default_chroma_qscale_table[32]={ +-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 ++static const uint8_t ff_default_chroma_qscale_table[32] = { ++// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ++ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ++ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 + }; + +-const uint8_t ff_mpeg1_dc_scale_table[128]={ +-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, +- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, +- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, +- 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++const uint8_t ff_mpeg1_dc_scale_table[128] = { ++// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, ++ 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, + }; + +-static const uint8_t mpeg2_dc_scale_table1[128]={ +-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++static const uint8_t mpeg2_dc_scale_table1[128] = { ++// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + }; + +-static const uint8_t mpeg2_dc_scale_table2[128]={ +-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++static const uint8_t mpeg2_dc_scale_table2[128] = { ++// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + }; + +-static const uint8_t mpeg2_dc_scale_table3[128]={ +-// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++static const uint8_t mpeg2_dc_scale_table3[128] = { ++// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + }; + +-const uint8_t * const ff_mpeg2_dc_scale_table[4]={ ++const uint8_t *const ff_mpeg2_dc_scale_table[4] = { + ff_mpeg1_dc_scale_table, + mpeg2_dc_scale_table1, + mpeg2_dc_scale_table2, +@@ -117,53 +135,59 @@ + const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = { + PIX_FMT_DXVA2_VLD, + PIX_FMT_VAAPI_VLD, ++ PIX_FMT_VDA_VLD, + PIX_FMT_YUV420P, + PIX_FMT_NONE + }; + +-const uint8_t *ff_find_start_code(const uint8_t * restrict p, const uint8_t *end, uint32_t * restrict state){ ++const uint8_t *avpriv_mpv_find_start_code(const uint8_t *restrict p, ++ const uint8_t *end, ++ uint32_t * restrict state) ++{ + int i; + +- assert(p<=end); +- if(p>=end) ++ assert(p <= end); ++ if (p >= end) + return end; + +- for(i=0; i<3; i++){ +- uint32_t tmp= *state << 8; +- *state= tmp + *(p++); +- if(tmp == 0x100 || p==end) ++ for (i = 0; i < 3; i++) { ++ uint32_t tmp = *state << 8; ++ *state = tmp + *(p++); ++ if (tmp == 0x100 || p == end) + return p; + } + +- while(p 1 ) p+= 3; +- else if(p[-2] ) p+= 2; +- else if(p[-3]|(p[-1]-1)) p++; +- else{ ++ while (p < end) { ++ if (p[-1] > 1 ) p += 3; ++ else if (p[-2] ) p += 2; ++ else if (p[-3]|(p[-1]-1)) p++; ++ else { + p++; + break; + } + } + +- p= FFMIN(p, end)-4; +- *state= AV_RB32(p); ++ p = FFMIN(p, end) - 4; ++ *state = AV_RB32(p); + +- return p+4; ++ return p + 4; + } + + /* init common dct for both encoder and decoder */ + av_cold int ff_dct_common_init(MpegEncContext *s) + { ++ dsputil_init(&s->dsp, s->avctx); ++ + s->dct_unquantize_h263_intra = dct_unquantize_h263_intra_c; + s->dct_unquantize_h263_inter = dct_unquantize_h263_inter_c; + s->dct_unquantize_mpeg1_intra = dct_unquantize_mpeg1_intra_c; + s->dct_unquantize_mpeg1_inter = dct_unquantize_mpeg1_inter_c; + s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_c; +- if(s->flags & CODEC_FLAG_BITEXACT) ++ if (s->flags & CODEC_FLAG_BITEXACT) + s->dct_unquantize_mpeg2_intra = dct_unquantize_mpeg2_intra_bitexact; + s->dct_unquantize_mpeg2_inter = dct_unquantize_mpeg2_inter_c; + +-#if HAVE_MMX ++#if HAVE_MMX + MPV_common_init_mmx(s); + #elif ARCH_ALPHA + MPV_common_init_axp(s); +@@ -180,12 +204,12 @@ + #endif + + /* load & permutate scantables +- note: only wmv uses different ones +- */ +- if(s->alternate_scan){ ++ * note: only wmv uses different ones ++ */ ++ if (s->alternate_scan) { + ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_alternate_vertical_scan); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_alternate_vertical_scan); +- }else{ ++ } else { + ff_init_scantable(s->dsp.idct_permutation, &s->inter_scantable , ff_zigzag_direct); + ff_init_scantable(s->dsp.idct_permutation, &s->intra_scantable , ff_zigzag_direct); + } +@@ -195,9 +219,10 @@ + return 0; + } + +-void ff_copy_picture(Picture *dst, Picture *src){ ++void ff_copy_picture(Picture *dst, Picture *src) ++{ + *dst = *src; +- dst->type= FF_BUFFER_TYPE_COPY; ++ dst->f.type = FF_BUFFER_TYPE_COPY; + } + + /** +@@ -205,8 +230,14 @@ + */ + static void free_frame_buffer(MpegEncContext *s, Picture *pic) + { +- s->avctx->release_buffer(s->avctx, (AVFrame*)pic); +- av_freep(&pic->hwaccel_picture_private); ++ /* Windows Media Image codecs allocate internal buffers with different ++ * dimensions; ignore user defined callbacks for these ++ */ ++ if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE) ++ ff_thread_release_buffer(s->avctx, (AVFrame *) pic); ++ else ++ avcodec_default_release_buffer(s->avctx, (AVFrame *) pic); ++ av_freep(&pic->f.hwaccel_picture_private); + } + + /** +@@ -217,32 +248,39 @@ + int r; + + if (s->avctx->hwaccel) { +- assert(!pic->hwaccel_picture_private); ++ assert(!pic->f.hwaccel_picture_private); + if (s->avctx->hwaccel->priv_data_size) { +- pic->hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size); +- if (!pic->hwaccel_picture_private) { ++ pic->f.hwaccel_picture_private = av_mallocz(s->avctx->hwaccel->priv_data_size); ++ if (!pic->f.hwaccel_picture_private) { + av_log(s->avctx, AV_LOG_ERROR, "alloc_frame_buffer() failed (hwaccel private data allocation)\n"); + return -1; + } + } + } + +- r = s->avctx->get_buffer(s->avctx, (AVFrame*)pic); ++ if (s->codec_id != CODEC_ID_WMV3IMAGE && s->codec_id != CODEC_ID_VC1IMAGE) ++ r = ff_thread_get_buffer(s->avctx, (AVFrame *) pic); ++ else ++ r = avcodec_default_get_buffer(s->avctx, (AVFrame *) pic); + +- if (r<0 || !pic->age || !pic->type || !pic->data[0]) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %d %p)\n", r, pic->age, pic->type, pic->data[0]); +- av_freep(&pic->hwaccel_picture_private); ++ if (r < 0 || !pic->f.type || !pic->f.data[0]) { ++ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (%d %d %p)\n", ++ r, pic->f.type, pic->f.data[0]); ++ av_freep(&pic->f.hwaccel_picture_private); + return -1; + } + +- if (s->linesize && (s->linesize != pic->linesize[0] || s->uvlinesize != pic->linesize[1])) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (stride changed)\n"); ++ if (s->linesize && (s->linesize != pic->f.linesize[0] || ++ s->uvlinesize != pic->f.linesize[1])) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "get_buffer() failed (stride changed)\n"); + free_frame_buffer(s, pic); + return -1; + } + +- if (pic->linesize[1] != pic->linesize[2]) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed (uv stride mismatch)\n"); ++ if (pic->f.linesize[1] != pic->f.linesize[2]) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "get_buffer() failed (uv stride mismatch)\n"); + free_frame_buffer(s, pic); + return -1; + } +@@ -251,144 +289,170 @@ + } + + /** +- * allocates a Picture +- * The pixels are allocated/set by calling get_buffer() if shared=0 ++ * Allocate a Picture. ++ * The pixels are allocated/set by calling get_buffer() if shared = 0 + */ +-int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared){ +- const int big_mb_num= s->mb_stride*(s->mb_height+1) + 1; //the +1 is needed so memset(,,stride*height) does not sig11 +- const int mb_array_size= s->mb_stride*s->mb_height; +- const int b8_array_size= s->b8_stride*s->mb_height*2; +- const int b4_array_size= s->b4_stride*s->mb_height*4; ++int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared) ++{ ++ const int big_mb_num = s->mb_stride * (s->mb_height + 1) + 1; ++ ++ // the + 1 is needed so memset(,,stride*height) does not sig11 ++ ++ const int mb_array_size = s->mb_stride * s->mb_height; ++ const int b8_array_size = s->b8_stride * s->mb_height * 2; ++ const int b4_array_size = s->b4_stride * s->mb_height * 4; + int i; +- int r= -1; ++ int r = -1; + +- if(shared){ +- assert(pic->data[0]); +- assert(pic->type == 0 || pic->type == FF_BUFFER_TYPE_SHARED); +- pic->type= FF_BUFFER_TYPE_SHARED; +- }else{ +- assert(!pic->data[0]); ++ if (shared) { ++ assert(pic->f.data[0]); ++ assert(pic->f.type == 0 || pic->f.type == FF_BUFFER_TYPE_SHARED); ++ pic->f.type = FF_BUFFER_TYPE_SHARED; ++ } else { ++ assert(!pic->f.data[0]); + + if (alloc_frame_buffer(s, pic) < 0) + return -1; + +- s->linesize = pic->linesize[0]; +- s->uvlinesize= pic->linesize[1]; ++ s->linesize = pic->f.linesize[0]; ++ s->uvlinesize = pic->f.linesize[1]; + } + +- if(pic->qscale_table==NULL){ ++ if (pic->f.qscale_table == NULL) { + if (s->encoding) { +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var , mb_array_size * sizeof(int16_t) , fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, mb_array_size * sizeof(int16_t) , fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean , mb_array_size * sizeof(int8_t ) , fail) +- } +- +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mbskip_table , mb_array_size * sizeof(uint8_t)+2, fail) //the +2 is for the slice end check +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table , mb_array_size * sizeof(uint8_t) , fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base , (big_mb_num + s->mb_stride) * sizeof(uint32_t), fail) +- pic->mb_type= pic->mb_type_base + 2*s->mb_stride+1; +- if(s->out_format == FMT_H264){ +- for(i=0; i<2; i++){ +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b4_array_size+4) * sizeof(int16_t), fail) +- pic->motion_val[i]= pic->motion_val_base[i]+4; +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) +- } +- pic->motion_subsample_log2= 2; +- }else if(s->out_format == FMT_H263 || s->encoding || (s->avctx->debug&FF_DEBUG_MV) || (s->avctx->debug_mv)){ +- for(i=0; i<2; i++){ +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], 2 * (b8_array_size+4) * sizeof(int16_t), fail) +- pic->motion_val[i]= pic->motion_val_base[i]+4; +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->ref_index[i], 4*mb_array_size * sizeof(uint8_t), fail) +- } +- pic->motion_subsample_log2= 3; +- } +- if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->dct_coeff, 64 * mb_array_size * sizeof(DCTELEM)*6, fail) +- } +- pic->qstride= s->mb_stride; +- FF_ALLOCZ_OR_GOTO(s->avctx, pic->pan_scan , 1 * sizeof(AVPanScan), fail) +- } +- +- /* It might be nicer if the application would keep track of these +- * but it would require an API change. */ +- memmove(s->prev_pict_types+1, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE-1); +- s->prev_pict_types[0]= s->dropable ? FF_B_TYPE : s->pict_type; +- if(pic->age < PREV_PICT_TYPES_BUFFER_SIZE && s->prev_pict_types[pic->age] == FF_B_TYPE) +- pic->age= INT_MAX; // Skipped MBs in B-frames are quite rare in MPEG-1/2 and it is a bit tricky to skip them anyway. ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_var, ++ mb_array_size * sizeof(int16_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->mc_mb_var, ++ mb_array_size * sizeof(int16_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_mean, ++ mb_array_size * sizeof(int8_t ), fail) ++ } ++ ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.mbskip_table, ++ mb_array_size * sizeof(uint8_t) + 2, fail)// the + 2 is for the slice end check ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->qscale_table_base, ++ (big_mb_num + s->mb_stride) * sizeof(uint8_t), ++ fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->mb_type_base, ++ (big_mb_num + s->mb_stride) * sizeof(uint32_t), ++ fail) ++ pic->f.mb_type = pic->mb_type_base + 2 * s->mb_stride + 1; ++ pic->f.qscale_table = pic->qscale_table_base + 2 * s->mb_stride + 1; ++ if (s->out_format == FMT_H264) { ++ for (i = 0; i < 2; i++) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], ++ 2 * (b4_array_size + 4) * sizeof(int16_t), ++ fail) ++ pic->f.motion_val[i] = pic->motion_val_base[i] + 4; ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], ++ 4 * mb_array_size * sizeof(uint8_t), fail) ++ } ++ pic->f.motion_subsample_log2 = 2; ++ } else if (s->out_format == FMT_H263 || s->encoding || ++ (s->avctx->debug & FF_DEBUG_MV) || s->avctx->debug_mv) { ++ for (i = 0; i < 2; i++) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->motion_val_base[i], ++ 2 * (b8_array_size + 4) * sizeof(int16_t), ++ fail) ++ pic->f.motion_val[i] = pic->motion_val_base[i] + 4; ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.ref_index[i], ++ 4 * mb_array_size * sizeof(uint8_t), fail) ++ } ++ pic->f.motion_subsample_log2 = 3; ++ } ++ if (s->avctx->debug&FF_DEBUG_DCT_COEFF) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.dct_coeff, ++ 64 * mb_array_size * sizeof(DCTELEM) * 6, fail) ++ } ++ pic->f.qstride = s->mb_stride; ++ FF_ALLOCZ_OR_GOTO(s->avctx, pic->f.pan_scan, ++ 1 * sizeof(AVPanScan), fail) ++ } ++ ++ pic->owner2 = s; + + return 0; +-fail: //for the FF_ALLOCZ_OR_GOTO macro +- if(r>=0) ++fail: // for the FF_ALLOCZ_OR_GOTO macro ++ if (r >= 0) + free_frame_buffer(s, pic); + return -1; + } + + /** +- * deallocates a picture ++ * Deallocate a picture. + */ +-static void free_picture(MpegEncContext *s, Picture *pic){ ++static void free_picture(MpegEncContext *s, Picture *pic) ++{ + int i; + +- if(pic->data[0] && pic->type!=FF_BUFFER_TYPE_SHARED){ ++ if (pic->f.data[0] && pic->f.type != FF_BUFFER_TYPE_SHARED) { + free_frame_buffer(s, pic); + } + + av_freep(&pic->mb_var); + av_freep(&pic->mc_mb_var); + av_freep(&pic->mb_mean); +- av_freep(&pic->mbskip_table); +- av_freep(&pic->qscale_table); ++ av_freep(&pic->f.mbskip_table); ++ av_freep(&pic->qscale_table_base); + av_freep(&pic->mb_type_base); +- av_freep(&pic->dct_coeff); +- av_freep(&pic->pan_scan); +- pic->mb_type= NULL; +- for(i=0; i<2; i++){ ++ av_freep(&pic->f.dct_coeff); ++ av_freep(&pic->f.pan_scan); ++ pic->f.mb_type = NULL; ++ for (i = 0; i < 2; i++) { + av_freep(&pic->motion_val_base[i]); +- av_freep(&pic->ref_index[i]); ++ av_freep(&pic->f.ref_index[i]); + } + +- if(pic->type == FF_BUFFER_TYPE_SHARED){ +- for(i=0; i<4; i++){ +- pic->base[i]= +- pic->data[i]= NULL; ++ if (pic->f.type == FF_BUFFER_TYPE_SHARED) { ++ for (i = 0; i < 4; i++) { ++ pic->f.base[i] = ++ pic->f.data[i] = NULL; + } +- pic->type= 0; ++ pic->f.type = 0; + } + } + +-static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base){ ++static int init_duplicate_context(MpegEncContext *s, MpegEncContext *base) ++{ + int y_size = s->b8_stride * (2 * s->mb_height + 1); + int c_size = s->mb_stride * (s->mb_height + 1); + int yc_size = y_size + 2 * c_size; + int i; + +- // edge emu needs blocksize + filter length - 1 (=17x17 for halfpel / 21x21 for h264) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->allocated_edge_emu_buffer, (s->width+64)*2*21*2, fail); //(width + edge + align)*interlaced*MBsize*tolerance +- s->edge_emu_buffer= s->allocated_edge_emu_buffer + (s->width+64)*2*21; +- +- //FIXME should be linesize instead of s->width*2 but that is not known before get_buffer() +- FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, (s->width+64)*4*16*2*sizeof(uint8_t), fail) +- s->me.temp= s->me.scratchpad; +- s->rd_scratchpad= s->me.scratchpad; +- s->b_scratchpad= s->me.scratchpad; +- s->obmc_scratchpad= s->me.scratchpad + 16; ++ // edge emu needs blocksize + filter length - 1 ++ // (= 17x17 for halfpel / 21x21 for h264) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->edge_emu_buffer, ++ (s->width + 64) * 2 * 21 * 2, fail); // (width + edge + align)*interlaced*MBsize*tolerance ++ ++ // FIXME should be linesize instead of s->width * 2 ++ // but that is not known before get_buffer() ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->me.scratchpad, ++ (s->width + 64) * 4 * 16 * 2 * sizeof(uint8_t), fail) ++ s->me.temp = s->me.scratchpad; ++ s->rd_scratchpad = s->me.scratchpad; ++ s->b_scratchpad = s->me.scratchpad; ++ s->obmc_scratchpad = s->me.scratchpad + 16; + if (s->encoding) { +- FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map , ME_MAP_SIZE*sizeof(uint32_t), fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ME_MAP_SIZE*sizeof(uint32_t), fail) +- if(s->avctx->noise_reduction){ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, 2 * 64 * sizeof(int), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->me.map, ++ ME_MAP_SIZE * sizeof(uint32_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->me.score_map, ++ ME_MAP_SIZE * sizeof(uint32_t), fail) ++ if (s->avctx->noise_reduction) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_error_sum, ++ 2 * 64 * sizeof(int), fail) + } + } +- FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64*12*2 * sizeof(DCTELEM), fail) +- s->block= s->blocks[0]; ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->blocks, 64 * 12 * 2 * sizeof(DCTELEM), fail) ++ s->block = s->blocks[0]; + +- for(i=0;i<12;i++){ ++ for (i = 0; i < 12; i++) { + s->pblocks[i] = &s->block[i]; + } + + if (s->out_format == FMT_H263) { + /* ac values */ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, yc_size * sizeof(int16_t) * 16, fail); ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->ac_val_base, ++ yc_size * sizeof(int16_t) * 16, fail); + s->ac_val[0] = s->ac_val_base + s->b8_stride + 1; + s->ac_val[1] = s->ac_val_base + y_size + s->mb_stride + 1; + s->ac_val[2] = s->ac_val[1] + c_size; +@@ -396,30 +460,32 @@ + + return 0; + fail: +- return -1; //free() through MPV_common_end() ++ return -1; // free() through MPV_common_end() + } + +-static void free_duplicate_context(MpegEncContext *s){ +- if(s==NULL) return; ++static void free_duplicate_context(MpegEncContext *s) ++{ ++ if (s == NULL) ++ return; + +- av_freep(&s->allocated_edge_emu_buffer); s->edge_emu_buffer= NULL; ++ av_freep(&s->edge_emu_buffer); + av_freep(&s->me.scratchpad); +- s->me.temp= +- s->rd_scratchpad= +- s->b_scratchpad= +- s->obmc_scratchpad= NULL; ++ s->me.temp = ++ s->rd_scratchpad = ++ s->b_scratchpad = ++ s->obmc_scratchpad = NULL; + + av_freep(&s->dct_error_sum); + av_freep(&s->me.map); + av_freep(&s->me.score_map); + av_freep(&s->blocks); + av_freep(&s->ac_val_base); +- s->block= NULL; ++ s->block = NULL; + } + +-static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src){ +-#define COPY(a) bak->a= src->a +- COPY(allocated_edge_emu_buffer); ++static void backup_duplicate_context(MpegEncContext *bak, MpegEncContext *src) ++{ ++#define COPY(a) bak->a = src->a + COPY(edge_emu_buffer); + COPY(me.scratchpad); + COPY(me.temp); +@@ -444,47 +510,145 @@ + #undef COPY + } + +-void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src){ ++void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src) ++{ + MpegEncContext bak; + int i; +- //FIXME copy only needed parts +-//START_TIMER ++ // FIXME copy only needed parts ++ // START_TIMER + backup_duplicate_context(&bak, dst); + memcpy(dst, src, sizeof(MpegEncContext)); + backup_duplicate_context(dst, &bak); +- for(i=0;i<12;i++){ ++ for (i = 0; i < 12; i++) { + dst->pblocks[i] = &dst->block[i]; + } +-//STOP_TIMER("update_duplicate_context") //about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads ++ // STOP_TIMER("update_duplicate_context") ++ // about 10k cycles / 0.01 sec for 1000frames on 1ghz with 2 threads ++} ++ ++int ff_mpeg_update_thread_context(AVCodecContext *dst, ++ const AVCodecContext *src) ++{ ++ MpegEncContext *s = dst->priv_data, *s1 = src->priv_data; ++ ++ if (dst == src || !s1->context_initialized) ++ return 0; ++ ++ // FIXME can parameters change on I-frames? ++ // in that case dst may need a reinit ++ if (!s->context_initialized) { ++ memcpy(s, s1, sizeof(MpegEncContext)); ++ ++ s->avctx = dst; ++ s->picture_range_start += MAX_PICTURE_COUNT; ++ s->picture_range_end += MAX_PICTURE_COUNT; ++ s->bitstream_buffer = NULL; ++ s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0; ++ ++ MPV_common_init(s); ++ } ++ ++ s->avctx->coded_height = s1->avctx->coded_height; ++ s->avctx->coded_width = s1->avctx->coded_width; ++ s->avctx->width = s1->avctx->width; ++ s->avctx->height = s1->avctx->height; ++ ++ s->coded_picture_number = s1->coded_picture_number; ++ s->picture_number = s1->picture_number; ++ s->input_picture_number = s1->input_picture_number; ++ ++ memcpy(s->picture, s1->picture, s1->picture_count * sizeof(Picture)); ++ memcpy(&s->last_picture, &s1->last_picture, ++ (char *) &s1->last_picture_ptr - (char *) &s1->last_picture); ++ ++ s->last_picture_ptr = REBASE_PICTURE(s1->last_picture_ptr, s, s1); ++ s->current_picture_ptr = REBASE_PICTURE(s1->current_picture_ptr, s, s1); ++ s->next_picture_ptr = REBASE_PICTURE(s1->next_picture_ptr, s, s1); ++ ++ // Error/bug resilience ++ s->next_p_frame_damaged = s1->next_p_frame_damaged; ++ s->workaround_bugs = s1->workaround_bugs; ++ s->padding_bug_score = s1->padding_bug_score; ++ ++ // MPEG4 timing info ++ memcpy(&s->time_increment_bits, &s1->time_increment_bits, ++ (char *) &s1->shape - (char *) &s1->time_increment_bits); ++ ++ // B-frame info ++ s->max_b_frames = s1->max_b_frames; ++ s->low_delay = s1->low_delay; ++ s->dropable = s1->dropable; ++ ++ // DivX handling (doesn't work) ++ s->divx_packed = s1->divx_packed; ++ ++ if (s1->bitstream_buffer) { ++ if (s1->bitstream_buffer_size + ++ FF_INPUT_BUFFER_PADDING_SIZE > s->allocated_bitstream_buffer_size) ++ av_fast_malloc(&s->bitstream_buffer, ++ &s->allocated_bitstream_buffer_size, ++ s1->allocated_bitstream_buffer_size); ++ s->bitstream_buffer_size = s1->bitstream_buffer_size; ++ memcpy(s->bitstream_buffer, s1->bitstream_buffer, ++ s1->bitstream_buffer_size); ++ memset(s->bitstream_buffer + s->bitstream_buffer_size, 0, ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ } ++ ++ // MPEG2/interlacing info ++ memcpy(&s->progressive_sequence, &s1->progressive_sequence, ++ (char *) &s1->rtp_mode - (char *) &s1->progressive_sequence); ++ ++ if (!s1->first_field) { ++ s->last_pict_type = s1->pict_type; ++ if (s1->current_picture_ptr) ++ s->last_lambda_for[s1->pict_type] = s1->current_picture_ptr->f.quality; ++ ++ if (s1->pict_type != AV_PICTURE_TYPE_B) { ++ s->last_non_b_pict_type = s1->pict_type; ++ } ++ } ++ ++ return 0; + } + + /** +- * sets the given MpegEncContext to common defaults (same for encoding and decoding). +- * the changed fields will not depend upon the prior state of the MpegEncContext. ++ * Set the given MpegEncContext to common defaults ++ * (same for encoding and decoding). ++ * The changed fields will not depend upon the ++ * prior state of the MpegEncContext. + */ +-void MPV_common_defaults(MpegEncContext *s){ +- s->y_dc_scale_table= +- s->c_dc_scale_table= ff_mpeg1_dc_scale_table; +- s->chroma_qscale_table= ff_default_chroma_qscale_table; +- s->progressive_frame= 1; +- s->progressive_sequence= 1; +- s->picture_structure= PICT_FRAME; +- +- s->coded_picture_number = 0; +- s->picture_number = 0; +- s->input_picture_number = 0; ++void MPV_common_defaults(MpegEncContext *s) ++{ ++ s->y_dc_scale_table = ++ s->c_dc_scale_table = ff_mpeg1_dc_scale_table; ++ s->chroma_qscale_table = ff_default_chroma_qscale_table; ++ s->progressive_frame = 1; ++ s->progressive_sequence = 1; ++ s->picture_structure = PICT_FRAME; ++ ++ s->coded_picture_number = 0; ++ s->picture_number = 0; ++ s->input_picture_number = 0; + + s->picture_in_gop_number = 0; + +- s->f_code = 1; +- s->b_code = 1; ++ s->f_code = 1; ++ s->b_code = 1; ++ ++ s->picture_range_start = 0; ++ s->picture_range_end = MAX_PICTURE_COUNT; ++ ++ s->slice_context_count = 1; + } + + /** +- * sets the given MpegEncContext to defaults for decoding. +- * the changed fields will not depend upon the prior state of the MpegEncContext. ++ * Set the given MpegEncContext to defaults for decoding. ++ * the changed fields will not depend upon ++ * the prior state of the MpegEncContext. + */ +-void MPV_decode_defaults(MpegEncContext *s){ ++void MPV_decode_defaults(MpegEncContext *s) ++{ + MPV_common_defaults(s); + } + +@@ -494,74 +658,85 @@ + */ + av_cold int MPV_common_init(MpegEncContext *s) + { +- int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y, threads; ++ int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; ++ int nb_slices = (HAVE_THREADS && ++ s->avctx->active_thread_type & FF_THREAD_SLICE) ? ++ s->avctx->thread_count : 1; + +- if(s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) ++ if (s->encoding && s->avctx->slices) ++ nb_slices = s->avctx->slices; ++ ++ if (s->codec_id == CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) + s->mb_height = (s->height + 31) / 32 * 2; + else if (s->codec_id != CODEC_ID_H264) + s->mb_height = (s->height + 15) / 16; + +- if(s->avctx->pix_fmt == PIX_FMT_NONE){ +- av_log(s->avctx, AV_LOG_ERROR, "decoding to PIX_FMT_NONE is not supported.\n"); ++ if (s->avctx->pix_fmt == PIX_FMT_NONE) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "decoding to PIX_FMT_NONE is not supported.\n"); + return -1; + } + +- if(s->avctx->thread_count > MAX_THREADS || (s->avctx->thread_count > s->mb_height && s->mb_height)){ +- av_log(s->avctx, AV_LOG_ERROR, "too many threads\n"); +- return -1; ++ if (nb_slices > MAX_THREADS || (nb_slices > s->mb_height && s->mb_height)) { ++ int max_slices; ++ if (s->mb_height) ++ max_slices = FFMIN(MAX_THREADS, s->mb_height); ++ else ++ max_slices = MAX_THREADS; ++ av_log(s->avctx, AV_LOG_WARNING, "too many threads/slices (%d)," ++ " reducing to %d\n", nb_slices, max_slices); ++ nb_slices = max_slices; + } + +- if((s->width || s->height) && av_image_check_size(s->width, s->height, 0, s->avctx)) ++ if ((s->width || s->height) && ++ av_image_check_size(s->width, s->height, 0, s->avctx)) + return -1; + +- dsputil_init(&s->dsp, s->avctx); + ff_dct_common_init(s); + +- s->flags= s->avctx->flags; +- s->flags2= s->avctx->flags2; ++ s->flags = s->avctx->flags; ++ s->flags2 = s->avctx->flags2; + +- s->mb_width = (s->width + 15) / 16; +- s->mb_stride = s->mb_width + 1; +- s->b8_stride = s->mb_width*2 + 1; +- s->b4_stride = s->mb_width*4 + 1; +- mb_array_size= s->mb_height * s->mb_stride; +- mv_table_size= (s->mb_height+2) * s->mb_stride + 1; +- +- /* set chroma shifts */ +- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt,&(s->chroma_x_shift), +- &(s->chroma_y_shift) ); ++ s->mb_width = (s->width + 15) / 16; ++ s->mb_stride = s->mb_width + 1; ++ s->b8_stride = s->mb_width * 2 + 1; ++ s->b4_stride = s->mb_width * 4 + 1; ++ mb_array_size = s->mb_height * s->mb_stride; ++ mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; ++ ++ /* set chroma shifts */ ++ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &s->chroma_x_shift, ++ &s->chroma_y_shift); + + /* set default edge pos, will be overriden in decode_header if needed */ +- s->h_edge_pos= s->mb_width*16; +- s->v_edge_pos= s->mb_height*16; ++ s->h_edge_pos = s->mb_width * 16; ++ s->v_edge_pos = s->mb_height * 16; + + s->mb_num = s->mb_width * s->mb_height; + +- s->block_wrap[0]= +- s->block_wrap[1]= +- s->block_wrap[2]= +- s->block_wrap[3]= s->b8_stride; +- s->block_wrap[4]= +- s->block_wrap[5]= s->mb_stride; ++ s->block_wrap[0] = ++ s->block_wrap[1] = ++ s->block_wrap[2] = ++ s->block_wrap[3] = s->b8_stride; ++ s->block_wrap[4] = ++ s->block_wrap[5] = s->mb_stride; + + y_size = s->b8_stride * (2 * s->mb_height + 1); + c_size = s->mb_stride * (s->mb_height + 1); + yc_size = y_size + 2 * c_size; + + /* convert fourcc to upper case */ +- s->codec_tag = ff_toupper4(s->avctx->codec_tag); ++ s->codec_tag = avpriv_toupper4(s->avctx->codec_tag); ++ s->stream_codec_tag = avpriv_toupper4(s->avctx->stream_codec_tag); + +- s->stream_codec_tag = ff_toupper4(s->avctx->stream_codec_tag); ++ s->avctx->coded_frame = (AVFrame*)&s->current_picture; + +- s->avctx->coded_frame= (AVFrame*)&s->current_picture; ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num + 1) * sizeof(int), fail); // error ressilience code looks cleaner with this ++ for (y = 0; y < s->mb_height; y++) ++ for (x = 0; x < s->mb_width; x++) ++ s->mb_index2xy[x + y * s->mb_width] = x + y * s->mb_stride; + +- FF_ALLOCZ_OR_GOTO(s->avctx, s->mb_index2xy, (s->mb_num+1)*sizeof(int), fail) //error ressilience code looks cleaner with this +- for(y=0; ymb_height; y++){ +- for(x=0; xmb_width; x++){ +- s->mb_index2xy[ x + y*s->mb_width ] = x + y*s->mb_stride; +- } +- } +- s->mb_index2xy[ s->mb_height*s->mb_width ] = (s->mb_height-1)*s->mb_stride + s->mb_width; //FIXME really needed? ++ s->mb_index2xy[s->mb_height * s->mb_width] = (s->mb_height - 1) * s->mb_stride + s->mb_width; // FIXME really needed? + + if (s->encoding) { + /* Allocate MV tables */ +@@ -588,10 +763,12 @@ + + FF_ALLOCZ_OR_GOTO(s->avctx, s->lambda_table, mb_array_size * sizeof(int), fail) + +- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16, 64*32*2 * sizeof(uint16_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix , 64*32 * sizeof(int), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix , 64*32 * sizeof(int), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix , 64*32 * sizeof(int), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_intra_matrix16 , 64*32*2 * sizeof(uint16_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_chroma_intra_matrix16, 64*32*2 * sizeof(uint16_t), fail) ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->q_inter_matrix16 , 64*32*2 * sizeof(uint16_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->reordered_input_picture, MAX_PICTURE_COUNT * sizeof(Picture*), fail) + +@@ -599,82 +776,89 @@ + FF_ALLOCZ_OR_GOTO(s->avctx, s->dct_offset, 2 * 64 * sizeof(uint16_t), fail) + } + } +- FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, MAX_PICTURE_COUNT * sizeof(Picture), fail) +- for(i = 0; i < MAX_PICTURE_COUNT; i++) { +- avcodec_get_frame_defaults((AVFrame *)&s->picture[i]); ++ ++ s->picture_count = MAX_PICTURE_COUNT * FFMAX(1, s->avctx->thread_count); ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->picture, ++ s->picture_count * sizeof(Picture), fail); ++ for (i = 0; i < s->picture_count; i++) { ++ avcodec_get_frame_defaults((AVFrame *) &s->picture[i]); + } + + FF_ALLOCZ_OR_GOTO(s->avctx, s->error_status_table, mb_array_size*sizeof(uint8_t), fail) + +- if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ +- /* interlaced direct mode decoding tables */ +- for(i=0; i<2; i++){ ++ if(s->codec_id==CODEC_ID_MPEG4 || (s->flags & CODEC_FLAG_INTERLACED_ME)){ ++ /* interlaced direct mode decoding tables */ ++ for (i = 0; i < 2; i++) { + int j, k; +- for(j=0; j<2; j++){ +- for(k=0; k<2; k++){ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail) ++ for (j = 0; j < 2; j++) { ++ for (k = 0; k < 2; k++) { ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_mv_table_base[i][j][k], mv_table_size * 2 * sizeof(int16_t), fail) + s->b_field_mv_table[i][j][k] = s->b_field_mv_table_base[i][j][k] + s->mb_stride + 1; + } + FF_ALLOCZ_OR_GOTO(s->avctx, s->b_field_select_table [i][j], mb_array_size * 2 * sizeof(uint8_t), fail) + FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_mv_table_base[i][j], mv_table_size * 2 * sizeof(int16_t), fail) +- s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j]+ s->mb_stride + 1; ++ s->p_field_mv_table[i][j] = s->p_field_mv_table_base[i][j] + s->mb_stride + 1; + } + FF_ALLOCZ_OR_GOTO(s->avctx, s->p_field_select_table[i], mb_array_size * 2 * sizeof(uint8_t), fail) + } +- } +- if (s->out_format == FMT_H263) { +- /* cbp values */ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail); +- s->coded_block= s->coded_block_base + s->b8_stride + 1; +- +- /* cbp, ac_pred, pred_dir */ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail) +- FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail) +- } +- +- if (s->h263_pred || s->h263_plus || !s->encoding) { +- /* dc values */ +- //MN: we need these for error resilience of intra-frames +- FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail); +- s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; +- s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; +- s->dc_val[2] = s->dc_val[1] + c_size; +- for(i=0;idc_val_base[i] = 1024; +- } +- +- /* which mb is a intra block */ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); +- memset(s->mbintra_table, 1, mb_array_size); +- +- /* init macroblock skip table */ +- FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size+2, fail); +- //Note the +1 is for a quicker mpeg4 slice_end detection +- FF_ALLOCZ_OR_GOTO(s->avctx, s->prev_pict_types, PREV_PICT_TYPES_BUFFER_SIZE, fail); +- +- s->parse_context.state= -1; +- if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ +- s->visualization_buffer[0] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); +- s->visualization_buffer[1] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); +- s->visualization_buffer[2] = av_malloc((s->mb_width*16 + 2*EDGE_WIDTH) * s->mb_height*16 + 2*EDGE_WIDTH); +- } +- +- s->context_initialized = 1; +- +- s->thread_context[0]= s; +- threads = s->avctx->thread_count; +- +- for(i=1; ithread_context[i]= av_malloc(sizeof(MpegEncContext)); +- memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); +- } +- +- for(i=0; ithread_context[i], s) < 0) +- goto fail; +- s->thread_context[i]->start_mb_y= (s->mb_height*(i ) + s->avctx->thread_count/2) / s->avctx->thread_count; +- s->thread_context[i]->end_mb_y = (s->mb_height*(i+1) + s->avctx->thread_count/2) / s->avctx->thread_count; +- } ++ } ++ if (s->out_format == FMT_H263) { ++ /* cbp values */ ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->coded_block_base, y_size, fail); ++ s->coded_block = s->coded_block_base + s->b8_stride + 1; ++ ++ /* cbp, ac_pred, pred_dir */ ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->cbp_table , mb_array_size * sizeof(uint8_t), fail); ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->pred_dir_table, mb_array_size * sizeof(uint8_t), fail); ++ } ++ ++ if (s->h263_pred || s->h263_plus || !s->encoding) { ++ /* dc values */ ++ // MN: we need these for error resilience of intra-frames ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->dc_val_base, yc_size * sizeof(int16_t), fail); ++ s->dc_val[0] = s->dc_val_base + s->b8_stride + 1; ++ s->dc_val[1] = s->dc_val_base + y_size + s->mb_stride + 1; ++ s->dc_val[2] = s->dc_val[1] + c_size; ++ for (i = 0; i < yc_size; i++) ++ s->dc_val_base[i] = 1024; ++ } ++ ++ /* which mb is a intra block */ ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->mbintra_table, mb_array_size, fail); ++ memset(s->mbintra_table, 1, mb_array_size); ++ ++ /* init macroblock skip table */ ++ FF_ALLOCZ_OR_GOTO(s->avctx, s->mbskip_table, mb_array_size + 2, fail); ++ // Note the + 1 is for a quicker mpeg4 slice_end detection ++ ++ s->parse_context.state = -1; ++ ++ s->context_initialized = 1; ++ s->thread_context[0] = s; ++ ++// if (s->width && s->height) { ++ if (nb_slices > 1) { ++ for (i = 1; i < nb_slices; i++) { ++ s->thread_context[i] = av_malloc(sizeof(MpegEncContext)); ++ memcpy(s->thread_context[i], s, sizeof(MpegEncContext)); ++ } ++ ++ for (i = 0; i < nb_slices; i++) { ++ if (init_duplicate_context(s->thread_context[i], s) < 0) ++ goto fail; ++ s->thread_context[i]->start_mb_y = ++ (s->mb_height * (i) + nb_slices / 2) / nb_slices; ++ s->thread_context[i]->end_mb_y = ++ (s->mb_height * (i + 1) + nb_slices / 2) / nb_slices; ++ } ++ } else { ++ if (init_duplicate_context(s, s) < 0) ++ goto fail; ++ s->start_mb_y = 0; ++ s->end_mb_y = s->mb_height; ++ } ++ s->slice_context_count = nb_slices; ++// } + + return 0; + fail: +@@ -687,15 +871,18 @@ + { + int i, j, k; + +- for(i=0; iavctx->thread_count; i++){ +- free_duplicate_context(s->thread_context[i]); +- } +- for(i=1; iavctx->thread_count; i++){ +- av_freep(&s->thread_context[i]); +- } ++ if (s->slice_context_count > 1) { ++ for (i = 0; i < s->slice_context_count; i++) { ++ free_duplicate_context(s->thread_context[i]); ++ } ++ for (i = 1; i < s->slice_context_count; i++) { ++ av_freep(&s->thread_context[i]); ++ } ++ s->slice_context_count = 1; ++ } else free_duplicate_context(s); + + av_freep(&s->parse_context.buffer); +- s->parse_context.buffer_size=0; ++ s->parse_context.buffer_size = 0; + + av_freep(&s->mb_type); + av_freep(&s->p_mv_table_base); +@@ -704,21 +891,21 @@ + av_freep(&s->b_bidir_forw_mv_table_base); + av_freep(&s->b_bidir_back_mv_table_base); + av_freep(&s->b_direct_mv_table_base); +- s->p_mv_table= NULL; +- s->b_forw_mv_table= NULL; +- s->b_back_mv_table= NULL; +- s->b_bidir_forw_mv_table= NULL; +- s->b_bidir_back_mv_table= NULL; +- s->b_direct_mv_table= NULL; +- for(i=0; i<2; i++){ +- for(j=0; j<2; j++){ +- for(k=0; k<2; k++){ ++ s->p_mv_table = NULL; ++ s->b_forw_mv_table = NULL; ++ s->b_back_mv_table = NULL; ++ s->b_bidir_forw_mv_table = NULL; ++ s->b_bidir_back_mv_table = NULL; ++ s->b_direct_mv_table = NULL; ++ for (i = 0; i < 2; i++) { ++ for (j = 0; j < 2; j++) { ++ for (k = 0; k < 2; k++) { + av_freep(&s->b_field_mv_table_base[i][j][k]); +- s->b_field_mv_table[i][j][k]=NULL; ++ s->b_field_mv_table[i][j][k] = NULL; + } + av_freep(&s->b_field_select_table[i][j]); + av_freep(&s->p_field_mv_table_base[i][j]); +- s->p_field_mv_table[i][j]=NULL; ++ s->p_field_mv_table[i][j] = NULL; + } + av_freep(&s->p_field_select_table[i]); + } +@@ -730,15 +917,18 @@ + av_freep(&s->pred_dir_table); + + av_freep(&s->mbskip_table); +- av_freep(&s->prev_pict_types); + av_freep(&s->bitstream_buffer); +- s->allocated_bitstream_buffer_size=0; ++ s->allocated_bitstream_buffer_size = 0; + + av_freep(&s->avctx->stats_out); + av_freep(&s->ac_stats); + av_freep(&s->error_status_table); + av_freep(&s->mb_index2xy); + av_freep(&s->lambda_table); ++ if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); ++ if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); ++ s->q_chroma_intra_matrix= NULL; ++ s->q_chroma_intra_matrix16= NULL; + av_freep(&s->q_intra_matrix); + av_freep(&s->q_inter_matrix); + av_freep(&s->q_intra_matrix16); +@@ -747,36 +937,38 @@ + av_freep(&s->reordered_input_picture); + av_freep(&s->dct_offset); + +- if(s->picture){ +- for(i=0; ipicture && !s->avctx->internal->is_copy) { ++ for (i = 0; i < s->picture_count; i++) { + free_picture(s, &s->picture[i]); + } + } + av_freep(&s->picture); +- s->context_initialized = 0; +- s->last_picture_ptr= +- s->next_picture_ptr= +- s->current_picture_ptr= NULL; +- s->linesize= s->uvlinesize= 0; ++ s->context_initialized = 0; ++ s->last_picture_ptr = ++ s->next_picture_ptr = ++ s->current_picture_ptr = NULL; ++ s->linesize = s->uvlinesize = 0; + +- for(i=0; i<3; i++) ++ for (i = 0; i < 3; i++) + av_freep(&s->visualization_buffer[i]); + +- avcodec_default_free_buffers(s->avctx); ++ if (!(s->avctx->active_thread_type & FF_THREAD_FRAME)) ++ avcodec_default_free_buffers(s->avctx); + } + +-void init_rl(RLTable *rl, uint8_t static_store[2][2*MAX_RUN + MAX_LEVEL + 3]) ++void init_rl(RLTable *rl, ++ uint8_t static_store[2][2 * MAX_RUN + MAX_LEVEL + 3]) + { +- int8_t max_level[MAX_RUN+1], max_run[MAX_LEVEL+1]; +- uint8_t index_run[MAX_RUN+1]; ++ int8_t max_level[MAX_RUN + 1], max_run[MAX_LEVEL + 1]; ++ uint8_t index_run[MAX_RUN + 1]; + int last, run, level, start, end, i; + + /* If table is static, we can quit if rl->max_level[0] is not NULL */ +- if(static_store && rl->max_level[0]) ++ if (static_store && rl->max_level[0]) + return; + + /* compute max_level[], max_run[] and index_run[] */ +- for(last=0;last<2;last++) { ++ for (last = 0; last < 2; last++) { + if (last == 0) { + start = 0; + end = rl->last; +@@ -788,8 +980,8 @@ + memset(max_level, 0, MAX_RUN + 1); + memset(max_run, 0, MAX_LEVEL + 1); + memset(index_run, rl->n, MAX_RUN + 1); +- for(i=start;itable_run[i]; ++ for (i = start; i < end; i++) { ++ run = rl->table_run[i]; + level = rl->table_level[i]; + if (index_run[run] == rl->n) + index_run[run] = i; +@@ -798,17 +990,17 @@ + if (run > max_run[level]) + max_run[level] = run; + } +- if(static_store) ++ if (static_store) + rl->max_level[last] = static_store[last]; + else + rl->max_level[last] = av_malloc(MAX_RUN + 1); + memcpy(rl->max_level[last], max_level, MAX_RUN + 1); +- if(static_store) +- rl->max_run[last] = static_store[last] + MAX_RUN + 1; ++ if (static_store) ++ rl->max_run[last] = static_store[last] + MAX_RUN + 1; + else +- rl->max_run[last] = av_malloc(MAX_LEVEL + 1); ++ rl->max_run[last] = av_malloc(MAX_LEVEL + 1); + memcpy(rl->max_run[last], max_run, MAX_LEVEL + 1); +- if(static_store) ++ if (static_store) + rl->index_run[last] = static_store[last] + MAX_RUN + MAX_LEVEL + 2; + else + rl->index_run[last] = av_malloc(MAX_RUN + 1); +@@ -820,59 +1012,79 @@ + { + int i, q; + +- for(q=0; q<32; q++){ +- int qmul= q*2; +- int qadd= (q-1)|1; +- +- if(q==0){ +- qmul=1; +- qadd=0; +- } +- for(i=0; ivlc.table_size; i++){ +- int code= rl->vlc.table[i][0]; +- int len = rl->vlc.table[i][1]; ++ for (q = 0; q < 32; q++) { ++ int qmul = q * 2; ++ int qadd = (q - 1) | 1; ++ ++ if (q == 0) { ++ qmul = 1; ++ qadd = 0; ++ } ++ for (i = 0; i < rl->vlc.table_size; i++) { ++ int code = rl->vlc.table[i][0]; ++ int len = rl->vlc.table[i][1]; + int level, run; + +- if(len==0){ // illegal code +- run= 66; +- level= MAX_LEVEL; +- }else if(len<0){ //more bits needed +- run= 0; +- level= code; +- }else{ +- if(code==rl->n){ //esc +- run= 66; +- level= 0; +- }else{ +- run= rl->table_run [code] + 1; +- level= rl->table_level[code] * qmul + qadd; +- if(code >= rl->last) run+=192; ++ if (len == 0) { // illegal code ++ run = 66; ++ level = MAX_LEVEL; ++ } else if (len < 0) { // more bits needed ++ run = 0; ++ level = code; ++ } else { ++ if (code == rl->n) { // esc ++ run = 66; ++ level = 0; ++ } else { ++ run = rl->table_run[code] + 1; ++ level = rl->table_level[code] * qmul + qadd; ++ if (code >= rl->last) run += 192; + } + } +- rl->rl_vlc[q][i].len= len; +- rl->rl_vlc[q][i].level= level; +- rl->rl_vlc[q][i].run= run; ++ rl->rl_vlc[q][i].len = len; ++ rl->rl_vlc[q][i].level = level; ++ rl->rl_vlc[q][i].run = run; + } + } + } + +-int ff_find_unused_picture(MpegEncContext *s, int shared){ ++void ff_release_unused_pictures(MpegEncContext*s, int remove_current) ++{ + int i; + +- if(shared){ +- for(i=0; ipicture[i].data[0]==NULL && s->picture[i].type==0) return i; ++ /* release non reference frames */ ++ for (i = 0; i < s->picture_count; i++) { ++ if (s->picture[i].f.data[0] && !s->picture[i].f.reference && ++ (!s->picture[i].owner2 || s->picture[i].owner2 == s) && ++ (remove_current || &s->picture[i] != s->current_picture_ptr) ++ /* && s->picture[i].type!= FF_BUFFER_TYPE_SHARED */) { ++ free_frame_buffer(s, &s->picture[i]); + } +- }else{ +- for(i=0; ipicture[i].data[0]==NULL && s->picture[i].type!=0) return i; //FIXME ++ } ++} ++ ++int ff_find_unused_picture(MpegEncContext *s, int shared) ++{ ++ int i; ++ ++ if (shared) { ++ for (i = s->picture_range_start; i < s->picture_range_end; i++) { ++ if (s->picture[i].f.data[0] == NULL && s->picture[i].f.type == 0) ++ return i; ++ } ++ } else { ++ for (i = s->picture_range_start; i < s->picture_range_end; i++) { ++ if (s->picture[i].f.data[0] == NULL && s->picture[i].f.type != 0) ++ return i; // FIXME + } +- for(i=0; ipicture[i].data[0]==NULL) return i; ++ for (i = s->picture_range_start; i < s->picture_range_end; i++) { ++ if (s->picture[i].f.data[0] == NULL) ++ return i; + } + } + +- av_log(s->avctx, AV_LOG_FATAL, "Internal error, picture buffer overflow\n"); ++ av_log(s->avctx, AV_LOG_FATAL, ++ "Internal error, picture buffer overflow\n"); + /* We could return -1, but the codec would crash trying to draw into a + * non-existing frame anyway. This is safer than waiting for a random crash. + * Also the return of this is never useful, an encoder must only allocate +@@ -888,25 +1100,30 @@ + return -1; + } + +-static void update_noise_reduction(MpegEncContext *s){ ++static void update_noise_reduction(MpegEncContext *s) ++{ + int intra, i; + +- for(intra=0; intra<2; intra++){ +- if(s->dct_count[intra] > (1<<16)){ +- for(i=0; i<64; i++){ +- s->dct_error_sum[intra][i] >>=1; ++ for (intra = 0; intra < 2; intra++) { ++ if (s->dct_count[intra] > (1 << 16)) { ++ for (i = 0; i < 64; i++) { ++ s->dct_error_sum[intra][i] >>= 1; + } + s->dct_count[intra] >>= 1; + } + +- for(i=0; i<64; i++){ +- s->dct_offset[intra][i]= (s->avctx->noise_reduction * s->dct_count[intra] + s->dct_error_sum[intra][i]/2) / (s->dct_error_sum[intra][i]+1); ++ for (i = 0; i < 64; i++) { ++ s->dct_offset[intra][i] = (s->avctx->noise_reduction * ++ s->dct_count[intra] + ++ s->dct_error_sum[intra][i] / 2) / ++ (s->dct_error_sum[intra][i] + 1); + } + } + } + + /** +- * generic function for encode/decode called after coding/decoding the header and before a frame is coded/decoded ++ * generic function for encode/decode called after coding/decoding ++ * the header and before a frame is coded/decoded. + */ + int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) + { +@@ -914,275 +1131,355 @@ + Picture *pic; + s->mb_skipped = 0; + +- assert(s->last_picture_ptr==NULL || s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3); ++ assert(s->last_picture_ptr == NULL || s->out_format != FMT_H264 || ++ s->codec_id == CODEC_ID_SVQ3); + +- /* mark&release old frames */ +- if (s->pict_type != FF_B_TYPE && s->last_picture_ptr && s->last_picture_ptr != s->next_picture_ptr && s->last_picture_ptr->data[0]) { +- if(s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3){ +- free_frame_buffer(s, s->last_picture_ptr); ++ /* mark & release old frames */ ++ if (s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3) { ++ if (s->pict_type != AV_PICTURE_TYPE_B && s->last_picture_ptr && ++ s->last_picture_ptr != s->next_picture_ptr && ++ s->last_picture_ptr->f.data[0]) { ++ if (s->last_picture_ptr->owner2 == s) ++ free_frame_buffer(s, s->last_picture_ptr); ++ } + + /* release forgotten pictures */ +- /* if(mpeg124/h263) */ +- if(!s->encoding){ +- for(i=0; ipicture[i].data[0] && &s->picture[i] != s->next_picture_ptr && s->picture[i].reference){ +- av_log(avctx, AV_LOG_ERROR, "releasing zombie picture\n"); ++ /* if (mpeg124/h263) */ ++ if (!s->encoding) { ++ for (i = 0; i < s->picture_count; i++) { ++ if (s->picture[i].owner2 == s && s->picture[i].f.data[0] && ++ &s->picture[i] != s->last_picture_ptr && ++ &s->picture[i] != s->next_picture_ptr && ++ s->picture[i].f.reference) { ++ if (!(avctx->active_thread_type & FF_THREAD_FRAME)) ++ av_log(avctx, AV_LOG_ERROR, ++ "releasing zombie picture\n"); + free_frame_buffer(s, &s->picture[i]); + } + } + } +- } + } + +- if(!s->encoding){ +- /* release non reference frames */ +- for(i=0; ipicture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ +- free_frame_buffer(s, &s->picture[i]); +- } +- } ++ if (!s->encoding) { ++ ff_release_unused_pictures(s, 1); + +- if(s->current_picture_ptr && s->current_picture_ptr->data[0]==NULL) +- pic= s->current_picture_ptr; //we already have a unused image (maybe it was set before reading the header) +- else{ +- i= ff_find_unused_picture(s, 0); +- pic= &s->picture[i]; ++ if (s->current_picture_ptr && ++ s->current_picture_ptr->f.data[0] == NULL) { ++ // we already have a unused image ++ // (maybe it was set before reading the header) ++ pic = s->current_picture_ptr; ++ } else { ++ i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; ++ pic = &s->picture[i]; + } + +- pic->reference= 0; +- if (!s->dropable){ ++ pic->f.reference = 0; ++ if (!s->dropable) { + if (s->codec_id == CODEC_ID_H264) +- pic->reference = s->picture_structure; +- else if (s->pict_type != FF_B_TYPE) +- pic->reference = 3; ++ pic->f.reference = s->picture_structure; ++ else if (s->pict_type != AV_PICTURE_TYPE_B) ++ pic->f.reference = 3; + } + +- pic->coded_picture_number= s->coded_picture_number++; ++ pic->f.coded_picture_number = s->coded_picture_number++; + +- if(ff_alloc_picture(s, pic, 0) < 0) ++ if (ff_alloc_picture(s, pic, 0) < 0) + return -1; + +- s->current_picture_ptr= pic; +- //FIXME use only the vars from current_pic +- s->current_picture_ptr->top_field_first= s->top_field_first; +- if(s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) { +- if(s->picture_structure != PICT_FRAME) +- s->current_picture_ptr->top_field_first= (s->picture_structure == PICT_TOP_FIELD) == s->first_field; +- } +- s->current_picture_ptr->interlaced_frame= !s->progressive_frame && !s->progressive_sequence; +- } +- +- s->current_picture_ptr->pict_type= s->pict_type; +-// if(s->flags && CODEC_FLAG_QSCALE) +- // s->current_picture_ptr->quality= s->new_picture_ptr->quality; +- s->current_picture_ptr->key_frame= s->pict_type == FF_I_TYPE; ++ s->current_picture_ptr = pic; ++ // FIXME use only the vars from current_pic ++ s->current_picture_ptr->f.top_field_first = s->top_field_first; ++ if (s->codec_id == CODEC_ID_MPEG1VIDEO || ++ s->codec_id == CODEC_ID_MPEG2VIDEO) { ++ if (s->picture_structure != PICT_FRAME) ++ s->current_picture_ptr->f.top_field_first = ++ (s->picture_structure == PICT_TOP_FIELD) == s->first_field; ++ } ++ s->current_picture_ptr->f.interlaced_frame = !s->progressive_frame && ++ !s->progressive_sequence; ++ s->current_picture_ptr->field_picture = s->picture_structure != PICT_FRAME; ++ } ++ ++ s->current_picture_ptr->f.pict_type = s->pict_type; ++ // if (s->flags && CODEC_FLAG_QSCALE) ++ // s->current_picture_ptr->quality = s->new_picture_ptr->quality; ++ s->current_picture_ptr->f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; + + ff_copy_picture(&s->current_picture, s->current_picture_ptr); + +- if (s->pict_type != FF_B_TYPE) { +- s->last_picture_ptr= s->next_picture_ptr; +- if(!s->dropable) +- s->next_picture_ptr= s->current_picture_ptr; +- } +-/* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr, +- s->last_picture_ptr ? s->last_picture_ptr->data[0] : NULL, +- s->next_picture_ptr ? s->next_picture_ptr->data[0] : NULL, +- s->current_picture_ptr ? s->current_picture_ptr->data[0] : NULL, +- s->pict_type, s->dropable);*/ +- +- if(s->codec_id != CODEC_ID_H264){ +- if((s->last_picture_ptr==NULL || s->last_picture_ptr->data[0]==NULL) && s->pict_type!=FF_I_TYPE){ +- av_log(avctx, AV_LOG_ERROR, "warning: first frame is no keyframe\n"); ++ if (s->pict_type != AV_PICTURE_TYPE_B) { ++ s->last_picture_ptr = s->next_picture_ptr; ++ if (!s->dropable) ++ s->next_picture_ptr = s->current_picture_ptr; ++ } ++ /* av_log(s->avctx, AV_LOG_DEBUG, "L%p N%p C%p L%p N%p C%p type:%d drop:%d\n", ++ s->last_picture_ptr, s->next_picture_ptr,s->current_picture_ptr, ++ s->last_picture_ptr ? s->last_picture_ptr->f.data[0] : NULL, ++ s->next_picture_ptr ? s->next_picture_ptr->f.data[0] : NULL, ++ s->current_picture_ptr ? s->current_picture_ptr->f.data[0] : NULL, ++ s->pict_type, s->dropable); */ ++ ++ if (s->codec_id != CODEC_ID_H264) { ++ if ((s->last_picture_ptr == NULL || ++ s->last_picture_ptr->f.data[0] == NULL) && ++ (s->pict_type != AV_PICTURE_TYPE_I || ++ s->picture_structure != PICT_FRAME)) { ++ if (s->pict_type != AV_PICTURE_TYPE_I) ++ av_log(avctx, AV_LOG_ERROR, ++ "warning: first frame is no keyframe\n"); ++ else if (s->picture_structure != PICT_FRAME) ++ av_log(avctx, AV_LOG_INFO, ++ "allocate dummy last picture for field based first keyframe\n"); ++ + /* Allocate a dummy frame */ +- i= ff_find_unused_picture(s, 0); ++ i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; + s->last_picture_ptr= &s->picture[i]; +- s->last_picture_ptr->key_frame = 0; +- if(ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) ++ s->last_picture_ptr->f.key_frame = 0; ++ if (ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) + return -1; +- } +- if((s->next_picture_ptr==NULL || s->next_picture_ptr->data[0]==NULL) && s->pict_type==FF_B_TYPE){ ++ ++ if(s->codec_id == CODEC_ID_FLV1 || s->codec_id == CODEC_ID_H263){ ++ for(i=0; iheight; i++) ++ memset(s->last_picture_ptr->f.data[0] + s->last_picture_ptr->f.linesize[0]*i, 16, avctx->width); ++ } ++ ++ ff_thread_report_progress((AVFrame *) s->last_picture_ptr, ++ INT_MAX, 0); ++ ff_thread_report_progress((AVFrame *) s->last_picture_ptr, ++ INT_MAX, 1); ++ } ++ if ((s->next_picture_ptr == NULL || ++ s->next_picture_ptr->f.data[0] == NULL) && ++ s->pict_type == AV_PICTURE_TYPE_B) { + /* Allocate a dummy frame */ +- i= ff_find_unused_picture(s, 0); ++ i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; + s->next_picture_ptr= &s->picture[i]; +- s->next_picture_ptr->key_frame = 0; +- if(ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) ++ s->next_picture_ptr->f.key_frame = 0; ++ if (ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) + return -1; ++ ff_thread_report_progress((AVFrame *) s->next_picture_ptr, ++ INT_MAX, 0); ++ ff_thread_report_progress((AVFrame *) s->next_picture_ptr, ++ INT_MAX, 1); + } + } + +- if(s->last_picture_ptr) ff_copy_picture(&s->last_picture, s->last_picture_ptr); +- if(s->next_picture_ptr) ff_copy_picture(&s->next_picture, s->next_picture_ptr); ++ if (s->last_picture_ptr) ++ ff_copy_picture(&s->last_picture, s->last_picture_ptr); ++ if (s->next_picture_ptr) ++ ff_copy_picture(&s->next_picture, s->next_picture_ptr); ++ ++ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_FRAME) && ++ (s->out_format != FMT_H264 || s->codec_id == CODEC_ID_SVQ3)) { ++ if (s->next_picture_ptr) ++ s->next_picture_ptr->owner2 = s; ++ if (s->last_picture_ptr) ++ s->last_picture_ptr->owner2 = s; ++ } + +- assert(s->pict_type == FF_I_TYPE || (s->last_picture_ptr && s->last_picture_ptr->data[0])); ++ assert(s->pict_type == AV_PICTURE_TYPE_I || (s->last_picture_ptr && ++ s->last_picture_ptr->f.data[0])); + +- if(s->picture_structure!=PICT_FRAME && s->out_format != FMT_H264){ ++ if (s->picture_structure!= PICT_FRAME && s->out_format != FMT_H264) { + int i; +- for(i=0; i<4; i++){ +- if(s->picture_structure == PICT_BOTTOM_FIELD){ +- s->current_picture.data[i] += s->current_picture.linesize[i]; ++ for (i = 0; i < 4; i++) { ++ if (s->picture_structure == PICT_BOTTOM_FIELD) { ++ s->current_picture.f.data[i] += ++ s->current_picture.f.linesize[i]; + } +- s->current_picture.linesize[i] *= 2; +- s->last_picture.linesize[i] *=2; +- s->next_picture.linesize[i] *=2; ++ s->current_picture.f.linesize[i] *= 2; ++ s->last_picture.f.linesize[i] *= 2; ++ s->next_picture.f.linesize[i] *= 2; + } + } + +- s->hurry_up= s->avctx->hurry_up; +- s->error_recognition= avctx->error_recognition; ++ s->err_recognition = avctx->err_recognition; + +- /* set dequantizer, we can't do it during init as it might change for mpeg4 +- and we can't do it in the header decode as init is not called for mpeg4 there yet */ +- if(s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO){ ++ /* set dequantizer, we can't do it during init as ++ * it might change for mpeg4 and we can't do it in the header ++ * decode as init is not called for mpeg4 there yet */ ++ if (s->mpeg_quant || s->codec_id == CODEC_ID_MPEG2VIDEO) { + s->dct_unquantize_intra = s->dct_unquantize_mpeg2_intra; + s->dct_unquantize_inter = s->dct_unquantize_mpeg2_inter; +- }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ ++ } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { + s->dct_unquantize_intra = s->dct_unquantize_h263_intra; + s->dct_unquantize_inter = s->dct_unquantize_h263_inter; +- }else{ ++ } else { + s->dct_unquantize_intra = s->dct_unquantize_mpeg1_intra; + s->dct_unquantize_inter = s->dct_unquantize_mpeg1_inter; + } + +- if(s->dct_error_sum){ ++ if (s->dct_error_sum) { + assert(s->avctx->noise_reduction && s->encoding); +- + update_noise_reduction(s); + } + +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) + return ff_xvmc_field_start(s, avctx); + + return 0; + } + +-/* generic function for encode/decode called after a frame has been coded/decoded */ ++/* generic function for encode/decode called after a ++ * frame has been coded/decoded. */ + void MPV_frame_end(MpegEncContext *s) + { + int i; +- /* draw edge for correct motion prediction if outside */ +- //just to make sure that all data is rendered. +- if(CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration){ ++ /* redraw edges for the frame if decoding didn't complete */ ++ // just to make sure that all data is rendered. ++ if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) { + ff_xvmc_field_end(s); +- }else if(!s->avctx->hwaccel +- && !(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) +- && s->unrestricted_mv +- && s->current_picture.reference +- && !s->intra_only +- && !(s->flags&CODEC_FLAG_EMU_EDGE)) { +- s->dsp.draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); +- s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); +- s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); ++ } else if((s->error_count || s->encoding || !(s->avctx->codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND)) && ++ !s->avctx->hwaccel && ++ !(s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) && ++ s->unrestricted_mv && ++ s->current_picture.f.reference && ++ !s->intra_only && ++ !(s->flags & CODEC_FLAG_EMU_EDGE)) { ++ int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w; ++ int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h; ++ s->dsp.draw_edges(s->current_picture.f.data[0], s->current_picture.f.linesize[0], ++ s->h_edge_pos, s->v_edge_pos, ++ EDGE_WIDTH, EDGE_WIDTH, ++ EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(s->current_picture.f.data[1], s->current_picture.f.linesize[1], ++ s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, ++ EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, ++ EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(s->current_picture.f.data[2], s->current_picture.f.linesize[2], ++ s->h_edge_pos >> hshift, s->v_edge_pos >> vshift, ++ EDGE_WIDTH >> hshift, EDGE_WIDTH >> vshift, ++ EDGE_TOP | EDGE_BOTTOM); + } ++ + emms_c(); + +- s->last_pict_type = s->pict_type; +- s->last_lambda_for[s->pict_type]= s->current_picture_ptr->quality; +- if(s->pict_type!=FF_B_TYPE){ +- s->last_non_b_pict_type= s->pict_type; ++ s->last_pict_type = s->pict_type; ++ s->last_lambda_for [s->pict_type] = s->current_picture_ptr->f.quality; ++ if (s->pict_type!= AV_PICTURE_TYPE_B) { ++ s->last_non_b_pict_type = s->pict_type; + } + #if 0 +- /* copy back current_picture variables */ +- for(i=0; ipicture[i].data[0] == s->current_picture.data[0]){ +- s->picture[i]= s->current_picture; ++ /* copy back current_picture variables */ ++ for (i = 0; i < MAX_PICTURE_COUNT; i++) { ++ if (s->picture[i].f.data[0] == s->current_picture.f.data[0]) { ++ s->picture[i] = s->current_picture; + break; + } + } +- assert(iencoding){ ++ if (s->encoding) { + /* release non-reference frames */ +- for(i=0; ipicture[i].data[0] && !s->picture[i].reference /*&& s->picture[i].type!=FF_BUFFER_TYPE_SHARED*/){ ++ for (i = 0; i < s->picture_count; i++) { ++ if (s->picture[i].f.data[0] && !s->picture[i].f.reference ++ /* && s->picture[i].type != FF_BUFFER_TYPE_SHARED */) { + free_frame_buffer(s, &s->picture[i]); + } + } + } + // clear copies, to avoid confusion + #if 0 +- memset(&s->last_picture, 0, sizeof(Picture)); +- memset(&s->next_picture, 0, sizeof(Picture)); ++ memset(&s->last_picture, 0, sizeof(Picture)); ++ memset(&s->next_picture, 0, sizeof(Picture)); + memset(&s->current_picture, 0, sizeof(Picture)); + #endif +- s->avctx->coded_frame= (AVFrame*)s->current_picture_ptr; ++ s->avctx->coded_frame = (AVFrame *) s->current_picture_ptr; ++ ++ if (s->codec_id != CODEC_ID_H264 && s->current_picture.f.reference) { ++ ff_thread_report_progress((AVFrame *) s->current_picture_ptr, ++ s->mb_height - 1, 0); ++ } + } + + /** +- * draws an line from (ex, ey) -> (sx, sy). ++ * Draw a line from (ex, ey) -> (sx, sy). + * @param w width of the image + * @param h height of the image + * @param stride stride/linesize of the image + * @param color color of the arrow + */ +-static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ ++static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey, ++ int w, int h, int stride, int color) ++{ + int x, y, fr, f; + +- sx= av_clip(sx, 0, w-1); +- sy= av_clip(sy, 0, h-1); +- ex= av_clip(ex, 0, w-1); +- ey= av_clip(ey, 0, h-1); ++ sx = av_clip(sx, 0, w - 1); ++ sy = av_clip(sy, 0, h - 1); ++ ex = av_clip(ex, 0, w - 1); ++ ey = av_clip(ey, 0, h - 1); + +- buf[sy*stride + sx]+= color; ++ buf[sy * stride + sx] += color; + +- if(FFABS(ex - sx) > FFABS(ey - sy)){ +- if(sx > ex){ ++ if (FFABS(ex - sx) > FFABS(ey - sy)) { ++ if (sx > ex) { + FFSWAP(int, sx, ex); + FFSWAP(int, sy, ey); + } +- buf+= sx + sy*stride; +- ex-= sx; +- f= ((ey-sy)<<16)/ex; ++ buf += sx + sy * stride; ++ ex -= sx; ++ f = ((ey - sy) << 16) / ex; + for(x= 0; x <= ex; x++){ +- y = (x*f)>>16; +- fr= (x*f)&0xFFFF; +- buf[ y *stride + x]+= (color*(0x10000-fr))>>16; +- buf[(y+1)*stride + x]+= (color* fr )>>16; ++ y = (x * f) >> 16; ++ fr = (x * f) & 0xFFFF; ++ buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; ++ buf[(y + 1) * stride + x] += (color * fr ) >> 16; + } +- }else{ +- if(sy > ey){ ++ } else { ++ if (sy > ey) { + FFSWAP(int, sx, ex); + FFSWAP(int, sy, ey); + } +- buf+= sx + sy*stride; +- ey-= sy; +- if(ey) f= ((ex-sx)<<16)/ey; +- else f= 0; ++ buf += sx + sy * stride; ++ ey -= sy; ++ if (ey) ++ f = ((ex - sx) << 16) / ey; ++ else ++ f = 0; + for(y= 0; y <= ey; y++){ +- x = (y*f)>>16; +- fr= (y*f)&0xFFFF; +- buf[y*stride + x ]+= (color*(0x10000-fr))>>16; +- buf[y*stride + x+1]+= (color* fr )>>16; ++ x = (y*f) >> 16; ++ fr = (y*f) & 0xFFFF; ++ buf[y * stride + x] += (color * (0x10000 - fr)) >> 16; ++ buf[y * stride + x + 1] += (color * fr ) >> 16; + } + } + } + + /** +- * draws an arrow from (ex, ey) -> (sx, sy). ++ * Draw an arrow from (ex, ey) -> (sx, sy). + * @param w width of the image + * @param h height of the image + * @param stride stride/linesize of the image + * @param color color of the arrow + */ +-static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, int ey, int w, int h, int stride, int color){ ++static void draw_arrow(uint8_t *buf, int sx, int sy, int ex, ++ int ey, int w, int h, int stride, int color) ++{ + int dx,dy; + +- sx= av_clip(sx, -100, w+100); +- sy= av_clip(sy, -100, h+100); +- ex= av_clip(ex, -100, w+100); +- ey= av_clip(ey, -100, h+100); +- +- dx= ex - sx; +- dy= ey - sy; +- +- if(dx*dx + dy*dy > 3*3){ +- int rx= dx + dy; +- int ry= -dx + dy; +- int length= ff_sqrt((rx*rx + ry*ry)<<8); +- +- //FIXME subpixel accuracy +- rx= ROUNDED_DIV(rx*3<<4, length); +- ry= ROUNDED_DIV(ry*3<<4, length); ++ sx = av_clip(sx, -100, w + 100); ++ sy = av_clip(sy, -100, h + 100); ++ ex = av_clip(ex, -100, w + 100); ++ ey = av_clip(ey, -100, h + 100); ++ ++ dx = ex - sx; ++ dy = ey - sy; ++ ++ if (dx * dx + dy * dy > 3 * 3) { ++ int rx = dx + dy; ++ int ry = -dx + dy; ++ int length = ff_sqrt((rx * rx + ry * ry) << 8); ++ ++ // FIXME subpixel accuracy ++ rx = ROUNDED_DIV(rx * 3 << 4, length); ++ ry = ROUNDED_DIV(ry * 3 << 4, length); + + draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color); + draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color); +@@ -1191,305 +1488,337 @@ + } + + /** +- * prints debuging info for the given picture. ++ * Print debugging info for the given picture. + */ +-void ff_print_debug_info(MpegEncContext *s, AVFrame *pict){ +- +- if(s->avctx->hwaccel || !pict || !pict->mb_type) return; ++void ff_print_debug_info(MpegEncContext *s, AVFrame *pict) ++{ ++ if (s->avctx->hwaccel || !pict || !pict->mb_type) ++ return; + +- if(s->avctx->debug&(FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)){ ++ if (s->avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) { + int x,y; + +- av_log(s->avctx,AV_LOG_DEBUG,"New frame, type: "); +- switch (pict->pict_type) { +- case FF_I_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"I\n"); break; +- case FF_P_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"P\n"); break; +- case FF_B_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"B\n"); break; +- case FF_S_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"S\n"); break; +- case FF_SI_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SI\n"); break; +- case FF_SP_TYPE: av_log(s->avctx,AV_LOG_DEBUG,"SP\n"); break; +- } +- for(y=0; ymb_height; y++){ +- for(x=0; xmb_width; x++){ +- if(s->avctx->debug&FF_DEBUG_SKIP){ +- int count= s->mbskip_table[x + y*s->mb_stride]; +- if(count>9) count=9; ++ av_log(s->avctx, AV_LOG_DEBUG, "New frame, type: %c\n", ++ av_get_picture_type_char(pict->pict_type)); ++ for (y = 0; y < s->mb_height; y++) { ++ for (x = 0; x < s->mb_width; x++) { ++ if (s->avctx->debug & FF_DEBUG_SKIP) { ++ int count = s->mbskip_table[x + y * s->mb_stride]; ++ if (count > 9) ++ count = 9; + av_log(s->avctx, AV_LOG_DEBUG, "%1d", count); + } +- if(s->avctx->debug&FF_DEBUG_QP){ +- av_log(s->avctx, AV_LOG_DEBUG, "%2d", pict->qscale_table[x + y*s->mb_stride]); ++ if (s->avctx->debug & FF_DEBUG_QP) { ++ av_log(s->avctx, AV_LOG_DEBUG, "%2d", ++ pict->qscale_table[x + y * s->mb_stride]); + } +- if(s->avctx->debug&FF_DEBUG_MB_TYPE){ +- int mb_type= pict->mb_type[x + y*s->mb_stride]; +- //Type & MV direction +- if(IS_PCM(mb_type)) ++ if (s->avctx->debug & FF_DEBUG_MB_TYPE) { ++ int mb_type = pict->mb_type[x + y * s->mb_stride]; ++ // Type & MV direction ++ if (IS_PCM(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "P"); +- else if(IS_INTRA(mb_type) && IS_ACPRED(mb_type)) ++ else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "A"); +- else if(IS_INTRA4x4(mb_type)) ++ else if (IS_INTRA4x4(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "i"); +- else if(IS_INTRA16x16(mb_type)) ++ else if (IS_INTRA16x16(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "I"); +- else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)) ++ else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "d"); +- else if(IS_DIRECT(mb_type)) ++ else if (IS_DIRECT(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "D"); +- else if(IS_GMC(mb_type) && IS_SKIP(mb_type)) ++ else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "g"); +- else if(IS_GMC(mb_type)) ++ else if (IS_GMC(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "G"); +- else if(IS_SKIP(mb_type)) ++ else if (IS_SKIP(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "S"); +- else if(!USES_LIST(mb_type, 1)) ++ else if (!USES_LIST(mb_type, 1)) + av_log(s->avctx, AV_LOG_DEBUG, ">"); +- else if(!USES_LIST(mb_type, 0)) ++ else if (!USES_LIST(mb_type, 0)) + av_log(s->avctx, AV_LOG_DEBUG, "<"); +- else{ ++ else { + assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); + av_log(s->avctx, AV_LOG_DEBUG, "X"); + } + +- //segmentation +- if(IS_8X8(mb_type)) ++ // segmentation ++ if (IS_8X8(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "+"); +- else if(IS_16X8(mb_type)) ++ else if (IS_16X8(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "-"); +- else if(IS_8X16(mb_type)) ++ else if (IS_8X16(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "|"); +- else if(IS_INTRA(mb_type) || IS_16X16(mb_type)) ++ else if (IS_INTRA(mb_type) || IS_16X16(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, " "); + else + av_log(s->avctx, AV_LOG_DEBUG, "?"); + + +- if(IS_INTERLACED(mb_type)) ++ if (IS_INTERLACED(mb_type)) + av_log(s->avctx, AV_LOG_DEBUG, "="); + else + av_log(s->avctx, AV_LOG_DEBUG, " "); + } +-// av_log(s->avctx, AV_LOG_DEBUG, " "); ++ // av_log(s->avctx, AV_LOG_DEBUG, " "); + } + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + } + } + +- if((s->avctx->debug&(FF_DEBUG_VIS_QP|FF_DEBUG_VIS_MB_TYPE)) || (s->avctx->debug_mv)){ +- const int shift= 1 + s->quarter_sample; ++ if ((s->avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || ++ (s->avctx->debug_mv)) { ++ const int shift = 1 + s->quarter_sample; + int mb_y; + uint8_t *ptr; + int i; + int h_chroma_shift, v_chroma_shift, block_height; +- const int width = s->avctx->width; +- const int height= s->avctx->height; +- const int mv_sample_log2= 4 - pict->motion_subsample_log2; +- const int mv_stride= (s->mb_width << mv_sample_log2) + (s->codec_id == CODEC_ID_H264 ? 0 : 1); +- s->low_delay=0; //needed to see the vectors without trashing the buffers +- +- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); +- for(i=0; i<3; i++){ +- memcpy(s->visualization_buffer[i], pict->data[i], (i==0) ? pict->linesize[i]*height:pict->linesize[i]*height >> v_chroma_shift); +- pict->data[i]= s->visualization_buffer[i]; +- } +- pict->type= FF_BUFFER_TYPE_COPY; +- ptr= pict->data[0]; +- block_height = 16>>v_chroma_shift; ++ const int width = s->avctx->width; ++ const int height = s->avctx->height; ++ const int mv_sample_log2 = 4 - pict->motion_subsample_log2; ++ const int mv_stride = (s->mb_width << mv_sample_log2) + ++ (s->codec_id == CODEC_ID_H264 ? 0 : 1); ++ s->low_delay = 0; // needed to see the vectors without trashing the buffers ++ ++ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, ++ &h_chroma_shift, &v_chroma_shift); ++ for (i = 0; i < 3; i++) { ++ size_t size= (i == 0) ? pict->linesize[i] * height: ++ pict->linesize[i] * height >> v_chroma_shift; ++ s->visualization_buffer[i]= av_realloc(s->visualization_buffer[i], size); ++ memcpy(s->visualization_buffer[i], pict->data[i], size); ++ pict->data[i] = s->visualization_buffer[i]; ++ } ++ pict->type = FF_BUFFER_TYPE_COPY; ++ pict->opaque= NULL; ++ ptr = pict->data[0]; ++ block_height = 16 >> v_chroma_shift; + +- for(mb_y=0; mb_ymb_height; mb_y++){ ++ for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + int mb_x; +- for(mb_x=0; mb_xmb_width; mb_x++){ +- const int mb_index= mb_x + mb_y*s->mb_stride; +- if((s->avctx->debug_mv) && pict->motion_val){ +- int type; +- for(type=0; type<3; type++){ +- int direction = 0; +- switch (type) { +- case 0: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_P_FOR)) || (pict->pict_type!=FF_P_TYPE)) ++ for (mb_x = 0; mb_x < s->mb_width; mb_x++) { ++ const int mb_index = mb_x + mb_y * s->mb_stride; ++ if ((s->avctx->debug_mv) && pict->motion_val) { ++ int type; ++ for (type = 0; type < 3; type++) { ++ int direction = 0; ++ switch (type) { ++ case 0: ++ if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) || ++ (pict->pict_type!= AV_PICTURE_TYPE_P)) + continue; +- direction = 0; +- break; +- case 1: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_FOR)) || (pict->pict_type!=FF_B_TYPE)) ++ direction = 0; ++ break; ++ case 1: ++ if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) || ++ (pict->pict_type!= AV_PICTURE_TYPE_B)) + continue; +- direction = 0; +- break; +- case 2: if ((!(s->avctx->debug_mv&FF_DEBUG_VIS_MV_B_BACK)) || (pict->pict_type!=FF_B_TYPE)) ++ direction = 0; ++ break; ++ case 2: ++ if ((!(s->avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) || ++ (pict->pict_type!= AV_PICTURE_TYPE_B)) + continue; +- direction = 1; +- break; +- } +- if(!USES_LIST(pict->mb_type[mb_index], direction)) +- continue; +- +- if(IS_8X8(pict->mb_type[mb_index])){ +- int i; +- for(i=0; i<4; i++){ +- int sx= mb_x*16 + 4 + 8*(i&1); +- int sy= mb_y*16 + 4 + 8*(i>>1); +- int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1); +- int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; +- int my= (pict->motion_val[direction][xy][1]>>shift) + sy; +- draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); +- } +- }else if(IS_16X8(pict->mb_type[mb_index])){ +- int i; +- for(i=0; i<2; i++){ +- int sx=mb_x*16 + 8; +- int sy=mb_y*16 + 4 + 8*i; +- int xy= (mb_x*2 + (mb_y*2 + i)*mv_stride) << (mv_sample_log2-1); +- int mx=(pict->motion_val[direction][xy][0]>>shift); +- int my=(pict->motion_val[direction][xy][1]>>shift); +- +- if(IS_INTERLACED(pict->mb_type[mb_index])) +- my*=2; +- +- draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100); +- } +- }else if(IS_8X16(pict->mb_type[mb_index])){ +- int i; +- for(i=0; i<2; i++){ +- int sx=mb_x*16 + 4 + 8*i; +- int sy=mb_y*16 + 8; +- int xy= (mb_x*2 + i + mb_y*2*mv_stride) << (mv_sample_log2-1); +- int mx=(pict->motion_val[direction][xy][0]>>shift); +- int my=(pict->motion_val[direction][xy][1]>>shift); +- +- if(IS_INTERLACED(pict->mb_type[mb_index])) +- my*=2; ++ direction = 1; ++ break; ++ } ++ if (!USES_LIST(pict->mb_type[mb_index], direction)) ++ continue; + +- draw_arrow(ptr, sx, sy, mx+sx, my+sy, width, height, s->linesize, 100); +- } +- }else{ +- int sx= mb_x*16 + 8; +- int sy= mb_y*16 + 8; +- int xy= (mb_x + mb_y*mv_stride) << mv_sample_log2; +- int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; +- int my= (pict->motion_val[direction][xy][1]>>shift) + sy; +- draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); ++ if (IS_8X8(pict->mb_type[mb_index])) { ++ int i; ++ for (i = 0; i < 4; i++) { ++ int sx = mb_x * 16 + 4 + 8 * (i & 1); ++ int sy = mb_y * 16 + 4 + 8 * (i >> 1); ++ int xy = (mb_x * 2 + (i & 1) + ++ (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1); ++ int mx = (pict->motion_val[direction][xy][0] >> shift) + sx; ++ int my = (pict->motion_val[direction][xy][1] >> shift) + sy; ++ draw_arrow(ptr, sx, sy, mx, my, width, ++ height, s->linesize, 100); ++ } ++ } else if (IS_16X8(pict->mb_type[mb_index])) { ++ int i; ++ for (i = 0; i < 2; i++) { ++ int sx = mb_x * 16 + 8; ++ int sy = mb_y * 16 + 4 + 8 * i; ++ int xy = (mb_x * 2 + (mb_y * 2 + i) * mv_stride) << (mv_sample_log2 - 1); ++ int mx = (pict->motion_val[direction][xy][0] >> shift); ++ int my = (pict->motion_val[direction][xy][1] >> shift); ++ ++ if (IS_INTERLACED(pict->mb_type[mb_index])) ++ my *= 2; ++ ++ draw_arrow(ptr, sx, sy, mx + sx, my + sy, width, ++ height, s->linesize, 100); ++ } ++ } else if (IS_8X16(pict->mb_type[mb_index])) { ++ int i; ++ for (i = 0; i < 2; i++) { ++ int sx = mb_x * 16 + 4 + 8 * i; ++ int sy = mb_y * 16 + 8; ++ int xy = (mb_x * 2 + i + mb_y * 2 * mv_stride) << (mv_sample_log2 - 1); ++ int mx = pict->motion_val[direction][xy][0] >> shift; ++ int my = pict->motion_val[direction][xy][1] >> shift; ++ ++ if (IS_INTERLACED(pict->mb_type[mb_index])) ++ my *= 2; ++ ++ draw_arrow(ptr, sx, sy, mx + sx, my + sy, width, ++ height, s->linesize, 100); ++ } ++ } else { ++ int sx= mb_x * 16 + 8; ++ int sy= mb_y * 16 + 8; ++ int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2; ++ int mx= (pict->motion_val[direction][xy][0]>>shift) + sx; ++ int my= (pict->motion_val[direction][xy][1]>>shift) + sy; ++ draw_arrow(ptr, sx, sy, mx, my, width, height, s->linesize, 100); ++ } + } +- } + } +- if((s->avctx->debug&FF_DEBUG_VIS_QP) && pict->motion_val){ +- uint64_t c= (pict->qscale_table[mb_index]*128/31) * 0x0101010101010101ULL; ++ if ((s->avctx->debug & FF_DEBUG_VIS_QP) && pict->motion_val) { ++ uint64_t c = (pict->qscale_table[mb_index] * 128 / 31) * ++ 0x0101010101010101ULL; + int y; +- for(y=0; ydata[1] + 8*mb_x + (block_height*mb_y + y)*pict->linesize[1])= c; +- *(uint64_t*)(pict->data[2] + 8*mb_x + (block_height*mb_y + y)*pict->linesize[2])= c; ++ for (y = 0; y < block_height; y++) { ++ *(uint64_t *)(pict->data[1] + 8 * mb_x + ++ (block_height * mb_y + y) * ++ pict->linesize[1]) = c; ++ *(uint64_t *)(pict->data[2] + 8 * mb_x + ++ (block_height * mb_y + y) * ++ pict->linesize[2]) = c; + } + } +- if((s->avctx->debug&FF_DEBUG_VIS_MB_TYPE) && pict->motion_val){ +- int mb_type= pict->mb_type[mb_index]; ++ if ((s->avctx->debug & FF_DEBUG_VIS_MB_TYPE) && ++ pict->motion_val) { ++ int mb_type = pict->mb_type[mb_index]; + uint64_t u,v; + int y; +-#define COLOR(theta, r)\ +-u= (int)(128 + r*cos(theta*3.141592/180));\ +-v= (int)(128 + r*sin(theta*3.141592/180)); +- +- +- u=v=128; +- if(IS_PCM(mb_type)){ +- COLOR(120,48) +- }else if((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || IS_INTRA16x16(mb_type)){ +- COLOR(30,48) +- }else if(IS_INTRA4x4(mb_type)){ +- COLOR(90,48) +- }else if(IS_DIRECT(mb_type) && IS_SKIP(mb_type)){ +-// COLOR(120,48) +- }else if(IS_DIRECT(mb_type)){ +- COLOR(150,48) +- }else if(IS_GMC(mb_type) && IS_SKIP(mb_type)){ +- COLOR(170,48) +- }else if(IS_GMC(mb_type)){ +- COLOR(190,48) +- }else if(IS_SKIP(mb_type)){ +-// COLOR(180,48) +- }else if(!USES_LIST(mb_type, 1)){ +- COLOR(240,48) +- }else if(!USES_LIST(mb_type, 0)){ +- COLOR(0,48) +- }else{ ++#define COLOR(theta, r) \ ++ u = (int)(128 + r * cos(theta * 3.141592 / 180)); \ ++ v = (int)(128 + r * sin(theta * 3.141592 / 180)); ++ ++ ++ u = v = 128; ++ if (IS_PCM(mb_type)) { ++ COLOR(120, 48) ++ } else if ((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) || ++ IS_INTRA16x16(mb_type)) { ++ COLOR(30, 48) ++ } else if (IS_INTRA4x4(mb_type)) { ++ COLOR(90, 48) ++ } else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) { ++ // COLOR(120, 48) ++ } else if (IS_DIRECT(mb_type)) { ++ COLOR(150, 48) ++ } else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) { ++ COLOR(170, 48) ++ } else if (IS_GMC(mb_type)) { ++ COLOR(190, 48) ++ } else if (IS_SKIP(mb_type)) { ++ // COLOR(180, 48) ++ } else if (!USES_LIST(mb_type, 1)) { ++ COLOR(240, 48) ++ } else if (!USES_LIST(mb_type, 0)) { ++ COLOR(0, 48) ++ } else { + assert(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1)); + COLOR(300,48) + } + +- u*= 0x0101010101010101ULL; +- v*= 0x0101010101010101ULL; +- for(y=0; ydata[1] + 8*mb_x + (block_height*mb_y + y)*pict->linesize[1])= u; +- *(uint64_t*)(pict->data[2] + 8*mb_x + (block_height*mb_y + y)*pict->linesize[2])= v; +- } +- +- //segmentation +- if(IS_8X8(mb_type) || IS_16X8(mb_type)){ +- *(uint64_t*)(pict->data[0] + 16*mb_x + 0 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; +- *(uint64_t*)(pict->data[0] + 16*mb_x + 8 + (16*mb_y + 8)*pict->linesize[0])^= 0x8080808080808080ULL; +- } +- if(IS_8X8(mb_type) || IS_8X16(mb_type)){ +- for(y=0; y<16; y++) +- pict->data[0][16*mb_x + 8 + (16*mb_y + y)*pict->linesize[0]]^= 0x80; +- } +- if(IS_8X8(mb_type) && mv_sample_log2 >= 2){ +- int dm= 1 << (mv_sample_log2-2); +- for(i=0; i<4; i++){ +- int sx= mb_x*16 + 8*(i&1); +- int sy= mb_y*16 + 8*(i>>1); +- int xy= (mb_x*2 + (i&1) + (mb_y*2 + (i>>1))*mv_stride) << (mv_sample_log2-1); +- //FIXME bidir +- int32_t *mv = (int32_t*)&pict->motion_val[0][xy]; +- if(mv[0] != mv[dm] || mv[dm*mv_stride] != mv[dm*(mv_stride+1)]) +- for(y=0; y<8; y++) +- pict->data[0][sx + 4 + (sy + y)*pict->linesize[0]]^= 0x80; +- if(mv[0] != mv[dm*mv_stride] || mv[dm] != mv[dm*(mv_stride+1)]) +- *(uint64_t*)(pict->data[0] + sx + (sy + 4)*pict->linesize[0])^= 0x8080808080808080ULL; ++ u *= 0x0101010101010101ULL; ++ v *= 0x0101010101010101ULL; ++ for (y = 0; y < block_height; y++) { ++ *(uint64_t *)(pict->data[1] + 8 * mb_x + ++ (block_height * mb_y + y) * pict->linesize[1]) = u; ++ *(uint64_t *)(pict->data[2] + 8 * mb_x + ++ (block_height * mb_y + y) * pict->linesize[2]) = v; ++ } ++ ++ // segmentation ++ if (IS_8X8(mb_type) || IS_16X8(mb_type)) { ++ *(uint64_t *)(pict->data[0] + 16 * mb_x + 0 + ++ (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL; ++ *(uint64_t *)(pict->data[0] + 16 * mb_x + 8 + ++ (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL; ++ } ++ if (IS_8X8(mb_type) || IS_8X16(mb_type)) { ++ for (y = 0; y < 16; y++) ++ pict->data[0][16 * mb_x + 8 + (16 * mb_y + y) * ++ pict->linesize[0]] ^= 0x80; ++ } ++ if (IS_8X8(mb_type) && mv_sample_log2 >= 2) { ++ int dm = 1 << (mv_sample_log2 - 2); ++ for (i = 0; i < 4; i++) { ++ int sx = mb_x * 16 + 8 * (i & 1); ++ int sy = mb_y * 16 + 8 * (i >> 1); ++ int xy = (mb_x * 2 + (i & 1) + ++ (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1); ++ // FIXME bidir ++ int32_t *mv = (int32_t *) &pict->motion_val[0][xy]; ++ if (mv[0] != mv[dm] || ++ mv[dm * mv_stride] != mv[dm * (mv_stride + 1)]) ++ for (y = 0; y < 8; y++) ++ pict->data[0][sx + 4 + (sy + y) * pict->linesize[0]] ^= 0x80; ++ if (mv[0] != mv[dm * mv_stride] || mv[dm] != mv[dm * (mv_stride + 1)]) ++ *(uint64_t *)(pict->data[0] + sx + (sy + 4) * ++ pict->linesize[0]) ^= 0x8080808080808080ULL; + } + } + +- if(IS_INTERLACED(mb_type) && s->codec_id == CODEC_ID_H264){ ++ if (IS_INTERLACED(mb_type) && ++ s->codec_id == CODEC_ID_H264) { + // hmm + } + } +- s->mbskip_table[mb_index]=0; ++ s->mbskip_table[mb_index] = 0; + } + } + } + } + + static inline int hpel_motion_lowres(MpegEncContext *s, +- uint8_t *dest, uint8_t *src, +- int field_based, int field_select, +- int src_x, int src_y, +- int width, int height, int stride, +- int h_edge_pos, int v_edge_pos, +- int w, int h, h264_chroma_mc_func *pix_op, +- int motion_x, int motion_y) +-{ +- const int lowres= s->avctx->lowres; +- const int op_index= FFMIN(lowres, 2); +- const int s_mask= (2<avctx->lowres; ++ const int op_index = FFMIN(lowres, 2); ++ const int s_mask = (2 << lowres) - 1; ++ int emu = 0; + int sx, sy; + +- if(s->quarter_sample){ +- motion_x/=2; +- motion_y/=2; +- } +- +- sx= motion_x & s_mask; +- sy= motion_y & s_mask; +- src_x += motion_x >> (lowres+1); +- src_y += motion_y >> (lowres+1); +- +- src += src_y * stride + src_x; +- +- if( (unsigned)src_x > h_edge_pos - (!!sx) - w +- || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<edge_emu_buffer; +- emu=1; +- } +- +- sx= (sx << 2) >> lowres; +- sy= (sy << 2) >> lowres; +- if(field_select) ++ if (s->quarter_sample) { ++ motion_x /= 2; ++ motion_y /= 2; ++ } ++ ++ sx = motion_x & s_mask; ++ sy = motion_y & s_mask; ++ src_x += motion_x >> lowres + 1; ++ src_y += motion_y >> lowres + 1; ++ ++ src += src_y * stride + src_x; ++ ++ if ((unsigned)src_x > FFMAX( h_edge_pos - (!!sx) - w, 0) || ++ (unsigned)src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w + 1, ++ (h + 1) << field_based, src_x, ++ src_y << field_based, ++ h_edge_pos, ++ v_edge_pos); ++ src = s->edge_emu_buffer; ++ emu = 1; ++ } ++ ++ sx = (sx << 2) >> lowres; ++ sy = (sy << 2) >> lowres; ++ if (field_select) + src += s->linesize; + pix_op[op_index](dest, src, stride, h, sx, sy); + return emu; +@@ -1497,149 +1826,187 @@ + + /* apply one mpeg motion vector to the three components */ + static av_always_inline void mpeg_motion_lowres(MpegEncContext *s, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int field_based, int bottom_field, int field_select, +- uint8_t **ref_picture, h264_chroma_mc_func *pix_op, +- int motion_x, int motion_y, int h, int mb_y) ++ uint8_t *dest_y, ++ uint8_t *dest_cb, ++ uint8_t *dest_cr, ++ int field_based, ++ int bottom_field, ++ int field_select, ++ uint8_t **ref_picture, ++ h264_chroma_mc_func *pix_op, ++ int motion_x, int motion_y, ++ int h, int mb_y) + { + uint8_t *ptr_y, *ptr_cb, *ptr_cr; +- int mx, my, src_x, src_y, uvsrc_x, uvsrc_y, uvlinesize, linesize, sx, sy, uvsx, uvsy; +- const int lowres= s->avctx->lowres; +- const int op_index= FFMIN(lowres, 2); +- const int block_s= 8>>lowres; +- const int s_mask= (2<avctx->lowres; ++ const int op_index = FFMIN(lowres-1+s->chroma_x_shift, 2); ++ const int block_s = 8>>lowres; ++ const int s_mask = (2 << lowres) - 1; + const int h_edge_pos = s->h_edge_pos >> lowres; + const int v_edge_pos = s->v_edge_pos >> lowres; +- linesize = s->current_picture.linesize[0] << field_based; +- uvlinesize = s->current_picture.linesize[1] << field_based; ++ linesize = s->current_picture.f.linesize[0] << field_based; ++ uvlinesize = s->current_picture.f.linesize[1] << field_based; + +- if(s->quarter_sample){ //FIXME obviously not perfect but qpel will not work in lowres anyway +- motion_x/=2; +- motion_y/=2; ++ // FIXME obviously not perfect but qpel will not work in lowres anyway ++ if (s->quarter_sample) { ++ motion_x /= 2; ++ motion_y /= 2; + } + + if(field_based){ +- motion_y += (bottom_field - field_select)*((1<mb_x*2*block_s + (motion_x >> (lowres+1)); +- src_y =( mb_y*2*block_s>>field_based) + (motion_y >> (lowres+1)); ++ sx = motion_x & s_mask; ++ sy = motion_y & s_mask; ++ src_x = s->mb_x * 2 * block_s + (motion_x >> lowres + 1); ++ src_y = (mb_y * 2 * block_s >> field_based) + (motion_y >> lowres + 1); + + if (s->out_format == FMT_H263) { +- uvsx = ((motion_x>>1) & s_mask) | (sx&1); +- uvsy = ((motion_y>>1) & s_mask) | (sy&1); +- uvsrc_x = src_x>>1; +- uvsrc_y = src_y>>1; +- }else if(s->out_format == FMT_H261){//even chroma mv's are full pel in H261 +- mx = motion_x / 4; +- my = motion_y / 4; +- uvsx = (2*mx) & s_mask; +- uvsy = (2*my) & s_mask; +- uvsrc_x = s->mb_x*block_s + (mx >> lowres); +- uvsrc_y = mb_y*block_s + (my >> lowres); ++ uvsx = ((motion_x >> 1) & s_mask) | (sx & 1); ++ uvsy = ((motion_y >> 1) & s_mask) | (sy & 1); ++ uvsrc_x = src_x >> 1; ++ uvsrc_y = src_y >> 1; ++ } else if (s->out_format == FMT_H261) { ++ // even chroma mv's are full pel in H261 ++ mx = motion_x / 4; ++ my = motion_y / 4; ++ uvsx = (2 * mx) & s_mask; ++ uvsy = (2 * my) & s_mask; ++ uvsrc_x = s->mb_x * block_s + (mx >> lowres); ++ uvsrc_y = mb_y * block_s + (my >> lowres); + } else { +- mx = motion_x / 2; +- my = motion_y / 2; +- uvsx = mx & s_mask; +- uvsy = my & s_mask; +- uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); +- uvsrc_y =( mb_y*block_s>>field_based) + (my >> (lowres+1)); ++ if(s->chroma_y_shift){ ++ mx = motion_x / 2; ++ my = motion_y / 2; ++ uvsx = mx & s_mask; ++ uvsy = my & s_mask; ++ uvsrc_x = s->mb_x * block_s + (mx >> lowres + 1); ++ uvsrc_y = (mb_y * block_s >> field_based) + (my >> lowres + 1); ++ } else { ++ if(s->chroma_x_shift){ ++ //Chroma422 ++ mx = motion_x / 2; ++ uvsx = mx & s_mask; ++ uvsy = motion_y & s_mask; ++ uvsrc_y = src_y; ++ uvsrc_x = s->mb_x*block_s + (mx >> (lowres+1)); ++ } else { ++ //Chroma444 ++ uvsx = motion_x & s_mask; ++ uvsy = motion_y & s_mask; ++ uvsrc_x = src_x; ++ uvsrc_y = src_y; ++ } ++ } + } + +- ptr_y = ref_picture[0] + src_y * linesize + src_x; ++ ptr_y = ref_picture[0] + src_y * linesize + src_x; + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + +- if( (unsigned)src_x > h_edge_pos - (!!sx) - 2*block_s +- || (unsigned)src_y >(v_edge_pos >> field_based) - (!!sy) - h){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, 17, 17+field_based, +- src_x, src_y<edge_emu_buffer; +- if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ +- uint8_t *uvbuf= s->edge_emu_buffer+18*s->linesize; +- s->dsp.emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, 9+field_based, +- uvsrc_x, uvsrc_y<>1, v_edge_pos>>1); +- s->dsp.emulated_edge_mc(uvbuf+16, ptr_cr, s->uvlinesize, 9, 9+field_based, +- uvsrc_x, uvsrc_y<>1, v_edge_pos>>1); +- ptr_cb= uvbuf; +- ptr_cr= uvbuf+16; +- } ++ if ((unsigned) src_x > FFMAX( h_edge_pos - (!!sx) - 2 * block_s, 0) || ++ (unsigned) src_y > FFMAX((v_edge_pos >> field_based) - (!!sy) - h, 0)) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, ++ s->linesize, 17, 17 + field_based, ++ src_x, src_y << field_based, h_edge_pos, ++ v_edge_pos); ++ ptr_y = s->edge_emu_buffer; ++ if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { ++ uint8_t *uvbuf = s->edge_emu_buffer + 18 * s->linesize; ++ s->dsp.emulated_edge_mc(uvbuf , ptr_cb, s->uvlinesize, 9, ++ 9 + field_based, ++ uvsrc_x, uvsrc_y << field_based, ++ h_edge_pos >> 1, v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(uvbuf + 16, ptr_cr, s->uvlinesize, 9, ++ 9 + field_based, ++ uvsrc_x, uvsrc_y << field_based, ++ h_edge_pos >> 1, v_edge_pos >> 1); ++ ptr_cb = uvbuf; ++ ptr_cr = uvbuf + 16; ++ } + } + +- if(bottom_field){ //FIXME use this for field pix too instead of the obnoxious hack which changes picture.data +- dest_y += s->linesize; +- dest_cb+= s->uvlinesize; +- dest_cr+= s->uvlinesize; +- } +- +- if(field_select){ +- ptr_y += s->linesize; +- ptr_cb+= s->uvlinesize; +- ptr_cr+= s->uvlinesize; +- } +- +- sx= (sx << 2) >> lowres; +- sy= (sy << 2) >> lowres; +- pix_op[lowres-1](dest_y, ptr_y, linesize, h, sx, sy); +- +- if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)){ +- uvsx= (uvsx << 2) >> lowres; +- uvsy= (uvsy << 2) >> lowres; +- pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); +- pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); ++ // FIXME use this for field pix too instead of the obnoxious hack which changes picture.f.data ++ if (bottom_field) { ++ dest_y += s->linesize; ++ dest_cb += s->uvlinesize; ++ dest_cr += s->uvlinesize; ++ } ++ ++ if (field_select) { ++ ptr_y += s->linesize; ++ ptr_cb += s->uvlinesize; ++ ptr_cr += s->uvlinesize; ++ } ++ ++ sx = (sx << 2) >> lowres; ++ sy = (sy << 2) >> lowres; ++ pix_op[lowres - 1](dest_y, ptr_y, linesize, h, sx, sy); ++ ++ if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) { ++ uvsx = (uvsx << 2) >> lowres; ++ uvsy = (uvsy << 2) >> lowres; ++ if (h >> s->chroma_y_shift) { ++ pix_op[op_index](dest_cb, ptr_cb, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); ++ pix_op[op_index](dest_cr, ptr_cr, uvlinesize, h >> s->chroma_y_shift, uvsx, uvsy); ++ } + } +- //FIXME h261 lowres loop filter ++ // FIXME h261 lowres loop filter + } + + static inline void chroma_4mv_motion_lowres(MpegEncContext *s, +- uint8_t *dest_cb, uint8_t *dest_cr, +- uint8_t **ref_picture, +- h264_chroma_mc_func *pix_op, +- int mx, int my){ +- const int lowres= s->avctx->lowres; +- const int op_index= FFMIN(lowres, 2); +- const int block_s= 8>>lowres; +- const int s_mask= (2<h_edge_pos >> (lowres+1); +- const int v_edge_pos = s->v_edge_pos >> (lowres+1); +- int emu=0, src_x, src_y, offset, sx, sy; ++ uint8_t *dest_cb, uint8_t *dest_cr, ++ uint8_t **ref_picture, ++ h264_chroma_mc_func * pix_op, ++ int mx, int my) ++{ ++ const int lowres = s->avctx->lowres; ++ const int op_index = FFMIN(lowres, 2); ++ const int block_s = 8 >> lowres; ++ const int s_mask = (2 << lowres) - 1; ++ const int h_edge_pos = s->h_edge_pos >> lowres + 1; ++ const int v_edge_pos = s->v_edge_pos >> lowres + 1; ++ int emu = 0, src_x, src_y, offset, sx, sy; + uint8_t *ptr; + +- if(s->quarter_sample){ +- mx/=2; +- my/=2; ++ if (s->quarter_sample) { ++ mx /= 2; ++ my /= 2; + } + + /* In case of 8X8, we construct a single chroma motion vector + with a special rounding */ +- mx= ff_h263_round_chroma(mx); +- my= ff_h263_round_chroma(my); ++ mx = ff_h263_round_chroma(mx); ++ my = ff_h263_round_chroma(my); + +- sx= mx & s_mask; +- sy= my & s_mask; +- src_x = s->mb_x*block_s + (mx >> (lowres+1)); +- src_y = s->mb_y*block_s + (my >> (lowres+1)); ++ sx = mx & s_mask; ++ sy = my & s_mask; ++ src_x = s->mb_x * block_s + (mx >> lowres + 1); ++ src_y = s->mb_y * block_s + (my >> lowres + 1); + + offset = src_y * s->uvlinesize + src_x; + ptr = ref_picture[1] + offset; +- if(s->flags&CODEC_FLAG_EMU_EDGE){ +- if( (unsigned)src_x > h_edge_pos - (!!sx) - block_s +- || (unsigned)src_y > v_edge_pos - (!!sy) - block_s){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); +- ptr= s->edge_emu_buffer; +- emu=1; ++ if (s->flags & CODEC_FLAG_EMU_EDGE) { ++ if ((unsigned) src_x > FFMAX(h_edge_pos - (!!sx) - block_s, 0) || ++ (unsigned) src_y > FFMAX(v_edge_pos - (!!sy) - block_s, 0)) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, ++ 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); ++ ptr = s->edge_emu_buffer; ++ emu = 1; + } + } +- sx= (sx << 2) >> lowres; +- sy= (sy << 2) >> lowres; ++ sx = (sx << 2) >> lowres; ++ sy = (sy << 2) >> lowres; + pix_op[op_index](dest_cb, ptr, s->uvlinesize, block_s, sx, sy); + + ptr = ref_picture[2] + offset; +- if(emu){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, h_edge_pos, v_edge_pos); +- ptr= s->edge_emu_buffer; ++ if (emu) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, ++ src_x, src_y, h_edge_pos, v_edge_pos); ++ ptr = s->edge_emu_buffer; + } + pix_op[op_index](dest_cr, ptr, s->uvlinesize, block_s, sx, sy); + } +@@ -1656,118 +2023,171 @@ + * the motion vectors are taken from s->mv and the MV type from s->mv_type + */ + static inline void MPV_motion_lowres(MpegEncContext *s, +- uint8_t *dest_y, uint8_t *dest_cb, uint8_t *dest_cr, +- int dir, uint8_t **ref_picture, +- h264_chroma_mc_func *pix_op) ++ uint8_t *dest_y, uint8_t *dest_cb, ++ uint8_t *dest_cr, ++ int dir, uint8_t **ref_picture, ++ h264_chroma_mc_func *pix_op) + { + int mx, my; + int mb_x, mb_y, i; +- const int lowres= s->avctx->lowres; +- const int block_s= 8>>lowres; ++ const int lowres = s->avctx->lowres; ++ const int block_s = 8 >>lowres; + + mb_x = s->mb_x; + mb_y = s->mb_y; + +- switch(s->mv_type) { ++ switch (s->mv_type) { + case MV_TYPE_16X16: + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 0, 0, 0, +- ref_picture, pix_op, +- s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s, mb_y); ++ 0, 0, 0, ++ ref_picture, pix_op, ++ s->mv[dir][0][0], s->mv[dir][0][1], ++ 2 * block_s, mb_y); + break; + case MV_TYPE_8X8: + mx = 0; + my = 0; +- for(i=0;i<4;i++) { +- hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * s->linesize)*block_s, +- ref_picture[0], 0, 0, +- (2*mb_x + (i & 1))*block_s, (2*mb_y + (i >>1))*block_s, +- s->width, s->height, s->linesize, +- s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, +- block_s, block_s, pix_op, +- s->mv[dir][i][0], s->mv[dir][i][1]); +- +- mx += s->mv[dir][i][0]; +- my += s->mv[dir][i][1]; +- } +- +- if(!CONFIG_GRAY || !(s->flags&CODEC_FLAG_GRAY)) +- chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, pix_op, mx, my); ++ for (i = 0; i < 4; i++) { ++ hpel_motion_lowres(s, dest_y + ((i & 1) + (i >> 1) * ++ s->linesize) * block_s, ++ ref_picture[0], 0, 0, ++ (2 * mb_x + (i & 1)) * block_s, ++ (2 * mb_y + (i >> 1)) * block_s, ++ s->width, s->height, s->linesize, ++ s->h_edge_pos >> lowres, s->v_edge_pos >> lowres, ++ block_s, block_s, pix_op, ++ s->mv[dir][i][0], s->mv[dir][i][1]); ++ ++ mx += s->mv[dir][i][0]; ++ my += s->mv[dir][i][1]; ++ } ++ ++ if (!CONFIG_GRAY || !(s->flags & CODEC_FLAG_GRAY)) ++ chroma_4mv_motion_lowres(s, dest_cb, dest_cr, ref_picture, ++ pix_op, mx, my); + break; + case MV_TYPE_FIELD: + if (s->picture_structure == PICT_FRAME) { + /* top field */ + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 1, 0, s->field_select[dir][0], +- ref_picture, pix_op, +- s->mv[dir][0][0], s->mv[dir][0][1], block_s, mb_y); ++ 1, 0, s->field_select[dir][0], ++ ref_picture, pix_op, ++ s->mv[dir][0][0], s->mv[dir][0][1], ++ block_s, mb_y); + /* bottom field */ + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 1, 1, s->field_select[dir][1], +- ref_picture, pix_op, +- s->mv[dir][1][0], s->mv[dir][1][1], block_s, mb_y); ++ 1, 1, s->field_select[dir][1], ++ ref_picture, pix_op, ++ s->mv[dir][1][0], s->mv[dir][1][1], ++ block_s, mb_y); + } else { +- if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){ +- ref_picture= s->current_picture_ptr->data; +- } ++ if (s->picture_structure != s->field_select[dir][0] + 1 && ++ s->pict_type != AV_PICTURE_TYPE_B && !s->first_field) { ++ ref_picture = s->current_picture_ptr->f.data; + ++ } + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 0, 0, s->field_select[dir][0], +- ref_picture, pix_op, +- s->mv[dir][0][0], s->mv[dir][0][1], 2*block_s, mb_y>>1); +- } ++ 0, 0, s->field_select[dir][0], ++ ref_picture, pix_op, ++ s->mv[dir][0][0], ++ s->mv[dir][0][1], 2 * block_s, mb_y >> 1); ++ } + break; + case MV_TYPE_16X8: +- for(i=0; i<2; i++){ +- uint8_t ** ref2picture; ++ for (i = 0; i < 2; i++) { ++ uint8_t **ref2picture; + +- if(s->picture_structure == s->field_select[dir][i] + 1 || s->pict_type == FF_B_TYPE || s->first_field){ +- ref2picture= ref_picture; +- }else{ +- ref2picture= s->current_picture_ptr->data; ++ if (s->picture_structure == s->field_select[dir][i] + 1 || ++ s->pict_type == AV_PICTURE_TYPE_B || s->first_field) { ++ ref2picture = ref_picture; ++ } else { ++ ref2picture = s->current_picture_ptr->f.data; + } + + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 0, 0, s->field_select[dir][i], +- ref2picture, pix_op, +- s->mv[dir][i][0], s->mv[dir][i][1] + 2*block_s*i, block_s, mb_y>>1); +- +- dest_y += 2*block_s*s->linesize; +- dest_cb+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; +- dest_cr+= (2*block_s>>s->chroma_y_shift)*s->uvlinesize; ++ 0, 0, s->field_select[dir][i], ++ ref2picture, pix_op, ++ s->mv[dir][i][0], s->mv[dir][i][1] + ++ 2 * block_s * i, block_s, mb_y >> 1); ++ ++ dest_y += 2 * block_s * s->linesize; ++ dest_cb += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; ++ dest_cr += (2 * block_s >> s->chroma_y_shift) * s->uvlinesize; + } + break; + case MV_TYPE_DMV: +- if(s->picture_structure == PICT_FRAME){ +- for(i=0; i<2; i++){ ++ if (s->picture_structure == PICT_FRAME) { ++ for (i = 0; i < 2; i++) { + int j; +- for(j=0; j<2; j++){ ++ for (j = 0; j < 2; j++) { + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 1, j, j^i, +- ref_picture, pix_op, +- s->mv[dir][2*i + j][0], s->mv[dir][2*i + j][1], block_s, mb_y); ++ 1, j, j ^ i, ++ ref_picture, pix_op, ++ s->mv[dir][2 * i + j][0], ++ s->mv[dir][2 * i + j][1], ++ block_s, mb_y); + } + pix_op = s->dsp.avg_h264_chroma_pixels_tab; + } +- }else{ +- for(i=0; i<2; i++){ ++ } else { ++ for (i = 0; i < 2; i++) { + mpeg_motion_lowres(s, dest_y, dest_cb, dest_cr, +- 0, 0, s->picture_structure != i+1, +- ref_picture, pix_op, +- s->mv[dir][2*i][0],s->mv[dir][2*i][1],2*block_s, mb_y>>1); ++ 0, 0, s->picture_structure != i + 1, ++ ref_picture, pix_op, ++ s->mv[dir][2 * i][0],s->mv[dir][2 * i][1], ++ 2 * block_s, mb_y >> 1); + + // after put we make avg of the same block + pix_op = s->dsp.avg_h264_chroma_pixels_tab; + +- //opposite parity is always in the same frame if this is second field +- if(!s->first_field){ +- ref_picture = s->current_picture_ptr->data; ++ // opposite parity is always in the same ++ // frame if this is second field ++ if (!s->first_field) { ++ ref_picture = s->current_picture_ptr->f.data; + } + } + } +- break; +- default: assert(0); ++ break; ++ default: ++ assert(0); ++ } ++} ++ ++/** ++ * find the lowest MB row referenced in the MVs ++ */ ++int MPV_lowest_referenced_row(MpegEncContext *s, int dir) ++{ ++ int my_max = INT_MIN, my_min = INT_MAX, qpel_shift = !s->quarter_sample; ++ int my, off, i, mvs; ++ ++ if (s->picture_structure != PICT_FRAME) goto unhandled; ++ ++ switch (s->mv_type) { ++ case MV_TYPE_16X16: ++ mvs = 1; ++ break; ++ case MV_TYPE_16X8: ++ mvs = 2; ++ break; ++ case MV_TYPE_8X8: ++ mvs = 4; ++ break; ++ default: ++ goto unhandled; + } ++ ++ for (i = 0; i < mvs; i++) { ++ my = s->mv[dir][i][1]<> 6; ++ ++ return FFMIN(FFMAX(s->mb_y + off, 0), s->mb_height-1); ++unhandled: ++ return s->mb_height-1; + } + + /* put block[] to dest[] */ +@@ -1798,7 +2218,7 @@ + } + + /** +- * cleans dc, ac, coded_block for the current non intra MB ++ * Clean dc, ac, coded_block for the current non-intra MB. + */ + void ff_clean_intra_table_entries(MpegEncContext *s) + { +@@ -1853,13 +2273,18 @@ + if(s->avctx->debug&FF_DEBUG_DCT_COEFF) { + /* save DCT coefficients */ + int i,j; +- DCTELEM *dct = &s->current_picture.dct_coeff[mb_xy*64*6]; +- for(i=0; i<6; i++) +- for(j=0; j<64; j++) ++ DCTELEM *dct = &s->current_picture.f.dct_coeff[mb_xy * 64 * 6]; ++ av_log(s->avctx, AV_LOG_DEBUG, "DCT coeffs of MB at %dx%d:\n", s->mb_x, s->mb_y); ++ for(i=0; i<6; i++){ ++ for(j=0; j<64; j++){ + *dct++ = block[i][s->dsp.idct_permutation[j]]; ++ av_log(s->avctx, AV_LOG_DEBUG, "%5d", dct[-1]); ++ } ++ av_log(s->avctx, AV_LOG_DEBUG, "\n"); ++ } + } + +- s->current_picture.qscale_table[mb_xy]= s->qscale; ++ s->current_picture.f.qscale_table[mb_xy] = s->qscale; + + /* update DC predictors for P macroblocks */ + if (!s->mb_intra) { +@@ -1875,45 +2300,34 @@ + else if (!is_mpeg12 && (s->h263_pred || s->h263_aic)) + s->mbintra_table[mb_xy]=1; + +- if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==FF_B_TYPE) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc ++ if ((s->flags&CODEC_FLAG_PSNR) || !(s->encoding && (s->intra_only || s->pict_type==AV_PICTURE_TYPE_B) && s->avctx->mb_decision != FF_MB_DECISION_RD)) { //FIXME precalc + uint8_t *dest_y, *dest_cb, *dest_cr; + int dct_linesize, dct_offset; + op_pixels_func (*op_pix)[4]; + qpel_mc_func (*op_qpix)[16]; +- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics +- const int uvlinesize= s->current_picture.linesize[1]; +- const int readable= s->pict_type != FF_B_TYPE || s->encoding || s->avctx->draw_horiz_band || lowres_flag; ++ const int linesize = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics ++ const int uvlinesize = s->current_picture.f.linesize[1]; ++ const int readable= s->pict_type != AV_PICTURE_TYPE_B || s->encoding || s->avctx->draw_horiz_band || lowres_flag; + const int block_size= lowres_flag ? 8>>s->avctx->lowres : 8; + + /* avoid copy if macroblock skipped in last frame too */ + /* skip only during decoding as we might trash the buffers during encoding a bit */ + if(!s->encoding){ + uint8_t *mbskip_ptr = &s->mbskip_table[mb_xy]; +- const int age= s->current_picture.age; +- +- assert(age); + + if (s->mb_skipped) { + s->mb_skipped= 0; +- assert(s->pict_type!=FF_I_TYPE); +- +- (*mbskip_ptr) ++; /* indicate that this time we skipped it */ +- if(*mbskip_ptr >99) *mbskip_ptr= 99; +- +- /* if previous was skipped too, then nothing to do ! */ +- if (*mbskip_ptr >= age && s->current_picture.reference){ +- return; +- } +- } else if(!s->current_picture.reference){ +- (*mbskip_ptr) ++; /* increase counter so the age can be compared cleanly */ +- if(*mbskip_ptr >99) *mbskip_ptr= 99; ++ assert(s->pict_type!=AV_PICTURE_TYPE_I); ++ *mbskip_ptr = 1; ++ } else if(!s->current_picture.f.reference) { ++ *mbskip_ptr = 1; + } else{ + *mbskip_ptr = 0; /* not skipped */ + } + } + + dct_linesize = linesize << s->interlaced_dct; +- dct_offset =(s->interlaced_dct)? linesize : linesize*block_size; ++ dct_offset = s->interlaced_dct ? linesize : linesize * block_size; + + if(readable){ + dest_y= s->dest[0]; +@@ -1929,45 +2343,54 @@ + /* motion handling */ + /* decoding or more than one mb_type (MC was already done otherwise) */ + if(!s->encoding){ ++ ++ if(HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) { ++ if (s->mv_dir & MV_DIR_FORWARD) { ++ ff_thread_await_progress((AVFrame*)s->last_picture_ptr, MPV_lowest_referenced_row(s, 0), 0); ++ } ++ if (s->mv_dir & MV_DIR_BACKWARD) { ++ ff_thread_await_progress((AVFrame*)s->next_picture_ptr, MPV_lowest_referenced_row(s, 1), 0); ++ } ++ } ++ + if(lowres_flag){ + h264_chroma_mc_func *op_pix = s->dsp.put_h264_chroma_pixels_tab; + + if (s->mv_dir & MV_DIR_FORWARD) { +- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix); ++ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix); + op_pix = s->dsp.avg_h264_chroma_pixels_tab; + } + if (s->mv_dir & MV_DIR_BACKWARD) { +- MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix); ++ MPV_motion_lowres(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix); + } + }else{ + op_qpix= s->me.qpel_put; +- if ((!s->no_rounding) || s->pict_type==FF_B_TYPE){ ++ if ((!s->no_rounding) || s->pict_type==AV_PICTURE_TYPE_B){ + op_pix = s->dsp.put_pixels_tab; + }else{ + op_pix = s->dsp.put_no_rnd_pixels_tab; + } + if (s->mv_dir & MV_DIR_FORWARD) { +- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); ++ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, op_pix, op_qpix); + op_pix = s->dsp.avg_pixels_tab; + op_qpix= s->me.qpel_avg; + } + if (s->mv_dir & MV_DIR_BACKWARD) { +- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); ++ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, op_pix, op_qpix); + } + } + } + + /* skip dequant / idct if we are really late ;) */ +- if(s->hurry_up>1) goto skip_idct; + if(s->avctx->skip_idct){ +- if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE) +- ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE) ++ if( (s->avctx->skip_idct >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ++ ||(s->avctx->skip_idct >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) + || s->avctx->skip_idct >= AVDISCARD_ALL) + goto skip_idct; + } + + /* add dct residue */ +- if(s->encoding || !( s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO ++ if(s->encoding || !( s->msmpeg4_version || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO + || (s->codec_id==CODEC_ID_MPEG4 && !s->mpeg_quant))){ + add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); + add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); +@@ -2000,17 +2423,17 @@ + }else{ + //chroma422 + dct_linesize = uvlinesize << s->interlaced_dct; +- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; ++ dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; + + add_dct(s, block[4], 4, dest_cb, dct_linesize); + add_dct(s, block[5], 5, dest_cr, dct_linesize); + add_dct(s, block[6], 6, dest_cb+dct_offset, dct_linesize); + add_dct(s, block[7], 7, dest_cr+dct_offset, dct_linesize); + if(!s->chroma_x_shift){//Chroma444 +- add_dct(s, block[8], 8, dest_cb+8, dct_linesize); +- add_dct(s, block[9], 9, dest_cr+8, dct_linesize); +- add_dct(s, block[10], 10, dest_cb+8+dct_offset, dct_linesize); +- add_dct(s, block[11], 11, dest_cr+8+dct_offset, dct_linesize); ++ add_dct(s, block[8], 8, dest_cb+block_size, dct_linesize); ++ add_dct(s, block[9], 9, dest_cr+block_size, dct_linesize); ++ add_dct(s, block[10], 10, dest_cb+block_size+dct_offset, dct_linesize); ++ add_dct(s, block[11], 11, dest_cr+block_size+dct_offset, dct_linesize); + } + } + }//fi gray +@@ -2052,17 +2475,17 @@ + }else{ + + dct_linesize = uvlinesize << s->interlaced_dct; +- dct_offset =(s->interlaced_dct)? uvlinesize : uvlinesize*8; ++ dct_offset = s->interlaced_dct? uvlinesize : uvlinesize*block_size; + + s->dsp.idct_put(dest_cb, dct_linesize, block[4]); + s->dsp.idct_put(dest_cr, dct_linesize, block[5]); + s->dsp.idct_put(dest_cb + dct_offset, dct_linesize, block[6]); + s->dsp.idct_put(dest_cr + dct_offset, dct_linesize, block[7]); + if(!s->chroma_x_shift){//Chroma444 +- s->dsp.idct_put(dest_cb + 8, dct_linesize, block[8]); +- s->dsp.idct_put(dest_cr + 8, dct_linesize, block[9]); +- s->dsp.idct_put(dest_cb + 8 + dct_offset, dct_linesize, block[10]); +- s->dsp.idct_put(dest_cr + 8 + dct_offset, dct_linesize, block[11]); ++ s->dsp.idct_put(dest_cb + block_size, dct_linesize, block[8]); ++ s->dsp.idct_put(dest_cr + block_size, dct_linesize, block[9]); ++ s->dsp.idct_put(dest_cb + block_size + dct_offset, dct_linesize, block[10]); ++ s->dsp.idct_put(dest_cr + block_size + dct_offset, dct_linesize, block[11]); + } + } + }//gray +@@ -2089,40 +2512,65 @@ + } + + /** +- * + * @param h is the normal height, this will be reduced automatically if needed for the last row + */ + void ff_draw_horiz_band(MpegEncContext *s, int y, int h){ +- if (s->avctx->draw_horiz_band) { +- AVFrame *src; +- const int field_pic= s->picture_structure != PICT_FRAME; +- int offset[4]; ++ const int field_pic= s->picture_structure != PICT_FRAME; ++ if(field_pic){ ++ h <<= 1; ++ y <<= 1; ++ } ++ ++ if (!s->avctx->hwaccel ++ && !(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) ++ && s->unrestricted_mv ++ && s->current_picture.f.reference ++ && !s->intra_only ++ && !(s->flags&CODEC_FLAG_EMU_EDGE)) { ++ int sides = 0, edge_h; ++ int hshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_w; ++ int vshift = av_pix_fmt_descriptors[s->avctx->pix_fmt].log2_chroma_h; ++ if (y==0) sides |= EDGE_TOP; ++ if (y + h >= s->v_edge_pos) sides |= EDGE_BOTTOM; ++ ++ edge_h= FFMIN(h, s->v_edge_pos - y); ++ ++ s->dsp.draw_edges(s->current_picture_ptr->f.data[0] + y *s->linesize, ++ s->linesize, s->h_edge_pos, edge_h, ++ EDGE_WIDTH, EDGE_WIDTH, sides); ++ s->dsp.draw_edges(s->current_picture_ptr->f.data[1] + (y>>vshift)*s->uvlinesize, ++ s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift, ++ EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides); ++ s->dsp.draw_edges(s->current_picture_ptr->f.data[2] + (y>>vshift)*s->uvlinesize, ++ s->uvlinesize, s->h_edge_pos>>hshift, edge_h>>vshift, ++ EDGE_WIDTH>>hshift, EDGE_WIDTH>>vshift, sides); ++ } + +- h= FFMIN(h, (s->avctx->height>>field_pic) - y); ++ h= FFMIN(h, s->avctx->height - y); + +- if(field_pic && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)){ +- h <<= 1; +- y <<= 1; +- if(s->first_field) return; +- } ++ if(field_pic && s->first_field && !(s->avctx->slice_flags&SLICE_FLAG_ALLOW_FIELD)) return; ++ ++ if (s->avctx->draw_horiz_band) { ++ AVFrame *src; ++ int offset[AV_NUM_DATA_POINTERS]; ++ int i; + +- if(s->pict_type==FF_B_TYPE || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) ++ if(s->pict_type==AV_PICTURE_TYPE_B || s->low_delay || (s->avctx->slice_flags&SLICE_FLAG_CODED_ORDER)) + src= (AVFrame*)s->current_picture_ptr; + else if(s->last_picture_ptr) + src= (AVFrame*)s->last_picture_ptr; + else + return; + +- if(s->pict_type==FF_B_TYPE && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){ +- offset[0]= +- offset[1]= +- offset[2]= +- offset[3]= 0; ++ if(s->pict_type==AV_PICTURE_TYPE_B && s->picture_structure == PICT_FRAME && s->out_format != FMT_H264){ ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) ++ offset[i] = 0; + }else{ + offset[0]= y * s->linesize; + offset[1]= + offset[2]= (y >> s->chroma_y_shift) * s->uvlinesize; +- offset[3]= 0; ++ for (i = 3; i < AV_NUM_DATA_POINTERS; i++) ++ offset[i] = 0; + } + + emms_c(); +@@ -2133,8 +2581,8 @@ + } + + void ff_init_block_index(MpegEncContext *s){ //FIXME maybe rename +- const int linesize= s->current_picture.linesize[0]; //not s->linesize as this would be wrong for field pics +- const int uvlinesize= s->current_picture.linesize[1]; ++ const int linesize = s->current_picture.f.linesize[0]; //not s->linesize as this would be wrong for field pics ++ const int uvlinesize = s->current_picture.f.linesize[1]; + const int mb_size= 4 - s->avctx->lowres; + + s->block_index[0]= s->b8_stride*(s->mb_y*2 ) - 2 + s->mb_x*2; +@@ -2145,11 +2593,11 @@ + s->block_index[5]= s->mb_stride*(s->mb_y + s->mb_height + 2) + s->b8_stride*s->mb_height*2 + s->mb_x - 1; + //block_index is not used by mpeg2, so it is not affected by chroma_format + +- s->dest[0] = s->current_picture.data[0] + ((s->mb_x - 1) << mb_size); +- s->dest[1] = s->current_picture.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); +- s->dest[2] = s->current_picture.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); ++ s->dest[0] = s->current_picture.f.data[0] + ((s->mb_x - 1) << mb_size); ++ s->dest[1] = s->current_picture.f.data[1] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); ++ s->dest[2] = s->current_picture.f.data[2] + ((s->mb_x - 1) << (mb_size - s->chroma_x_shift)); + +- if(!(s->pict_type==FF_B_TYPE && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME)) ++ if(!(s->pict_type==AV_PICTURE_TYPE_B && s->avctx->draw_horiz_band && s->picture_structure==PICT_FRAME)) + { + if(s->picture_structure==PICT_FRAME){ + s->dest[0] += s->mb_y * linesize << mb_size; +@@ -2171,9 +2619,10 @@ + if(s==NULL || s->picture==NULL) + return; + +- for(i=0; ipicture[i].data[0] && ( s->picture[i].type == FF_BUFFER_TYPE_INTERNAL +- || s->picture[i].type == FF_BUFFER_TYPE_USER)) ++ for(i=0; ipicture_count; i++){ ++ if (s->picture[i].f.data[0] && ++ (s->picture[i].f.type == FF_BUFFER_TYPE_INTERNAL || ++ s->picture[i].f.type == FF_BUFFER_TYPE_USER)) + free_frame_buffer(s, &s->picture[i]); + } + s->current_picture_ptr = s->last_picture_ptr = s->next_picture_ptr = NULL; +@@ -2425,3 +2874,9 @@ + s->y_dc_scale= s->y_dc_scale_table[ qscale ]; + s->c_dc_scale= s->c_dc_scale_table[ s->chroma_qscale ]; + } ++ ++void MPV_report_decode_progress(MpegEncContext *s) ++{ ++ if (s->pict_type != AV_PICTURE_TYPE_B && !s->partitioned_frame && !s->error_occurred) ++ ff_thread_report_progress((AVFrame*)s->current_picture_ptr, s->mb_y, 0); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_common.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_common.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_common.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_common.h 2012-05-14 14:08:54.056334387 +0200 +@@ -42,14 +42,14 @@ + int dct_quantize_c(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); + + /** +- * allocates a Picture +- * The pixels are allocated/set by calling get_buffer() if shared=0 ++ * Allocate a Picture. ++ * The pixels are allocated/set by calling get_buffer() if shared = 0. + */ + int alloc_picture(MpegEncContext *s, Picture *pic, int shared); + + /** +- * sets the given MpegEncContext to common defaults (same for encoding and decoding). +- * the changed fields will not depend upon the prior state of the MpegEncContext. ++ * Set the given MpegEncContext to common defaults (same for encoding and decoding). ++ * The changed fields will not depend upon the prior state of the MpegEncContext. + */ + void MPV_common_defaults(MpegEncContext *s); + +@@ -81,8 +81,8 @@ + ptr = ref_picture[0] + (src_y * linesize) + src_x; + + if(s->flags&CODEC_FLAG_EMU_EDGE){ +- if( (unsigned)src_x >= s->h_edge_pos - 17 +- || (unsigned)src_y >= s->v_edge_pos - 17){ ++ if( (unsigned)src_x >= FFMAX(s->h_edge_pos - 17, 0) ++ || (unsigned)src_y >= FFMAX(s->v_edge_pos - 17, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, 17, src_x, src_y, s->h_edge_pos, s->v_edge_pos); + ptr= s->edge_emu_buffer; + } +@@ -120,8 +120,8 @@ + offset = (src_y * uvlinesize) + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ +- if( (unsigned)src_x >= (s->h_edge_pos>>1) - 9 +- || (unsigned)src_y >= (s->v_edge_pos>>1) - 9){ ++ if( (unsigned)src_x >= FFMAX((s->h_edge_pos>>1) - 9, 0) ++ || (unsigned)src_y >= FFMAX((s->v_edge_pos>>1) - 9, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, uvlinesize, 9, 9, src_x, src_y, s->h_edge_pos>>1, s->v_edge_pos>>1); + ptr= s->edge_emu_buffer; + emu=1; +@@ -221,8 +221,8 @@ + src += src_y * stride + src_x; + + if(s->unrestricted_mv && (s->flags&CODEC_FLAG_EMU_EDGE)){ +- if( (unsigned)src_x > h_edge_pos - (motion_x&1) - w +- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ ++ if( (unsigned)src_x > FFMAX(h_edge_pos - (motion_x&1) - w, 0) ++ || (unsigned)src_y > FFMAX(v_edge_pos - (motion_y&1) - h, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, w+1, (h+1)<v_edge_pos); + src= s->edge_emu_buffer; +@@ -255,8 +255,8 @@ + #endif + + v_edge_pos = s->v_edge_pos >> field_based; +- linesize = s->current_picture.linesize[0] << field_based; +- uvlinesize = s->current_picture.linesize[1] << field_based; ++ linesize = s->current_picture.f.linesize[0] << field_based; ++ uvlinesize = s->current_picture.f.linesize[1] << field_based; + + dxy = ((motion_y & 1) << 1) | (motion_x & 1); + src_x = s->mb_x* 16 + (motion_x >> 1); +@@ -307,8 +307,8 @@ + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + +- if( (unsigned)src_x > s->h_edge_pos - (motion_x&1) - 16 +- || (unsigned)src_y > v_edge_pos - (motion_y&1) - h){ ++ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&1) - 16, 0) ++ || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&1) - h , 0)){ + if(is_mpeg12 || s->codec_id == CODEC_ID_MPEG2VIDEO || + s->codec_id == CODEC_ID_MPEG1VIDEO){ + av_log(s->avctx,AV_LOG_DEBUG, +@@ -510,8 +510,8 @@ + ptr_cb = ref_picture[1] + uvsrc_y * uvlinesize + uvsrc_x; + ptr_cr = ref_picture[2] + uvsrc_y * uvlinesize + uvsrc_x; + +- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 16 +- || (unsigned)src_y > v_edge_pos - (motion_y&3) - h ){ ++ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 16, 0) ++ || (unsigned)src_y > FFMAX( v_edge_pos - (motion_y&3) - h , 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr_y, s->linesize, + 17, 17+field_based, src_x, src_y<h_edge_pos, s->v_edge_pos); +@@ -585,11 +585,11 @@ + if (src_y == (s->height >> 1)) + dxy &= ~2; + +- offset = (src_y * (s->uvlinesize)) + src_x; ++ offset = src_y * s->uvlinesize + src_x; + ptr = ref_picture[1] + offset; + if(s->flags&CODEC_FLAG_EMU_EDGE){ +- if( (unsigned)src_x > (s->h_edge_pos>>1) - (dxy &1) - 8 +- || (unsigned)src_y > (s->v_edge_pos>>1) - (dxy>>1) - 8){ ++ if( (unsigned)src_x > FFMAX((s->h_edge_pos>>1) - (dxy &1) - 8, 0) ++ || (unsigned)src_y > FFMAX((s->v_edge_pos>>1) - (dxy>>1) - 8, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, + 9, 9, src_x, src_y, + s->h_edge_pos>>1, s->v_edge_pos>>1); +@@ -649,7 +649,7 @@ + + prefetch_motion(s, ref_picture, dir); + +- if(!is_mpeg12 && s->obmc && s->pict_type != FF_B_TYPE){ ++ if(!is_mpeg12 && s->obmc && s->pict_type != AV_PICTURE_TYPE_B){ + int16_t mv_cache[4][4][2]; + const int xy= s->mb_x + s->mb_y*s->mb_stride; + const int mot_stride= s->b8_stride; +@@ -657,30 +657,30 @@ + + assert(!s->mb_skipped); + +- memcpy(mv_cache[1][1], s->current_picture.motion_val[0][mot_xy ], sizeof(int16_t)*4); +- memcpy(mv_cache[2][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); +- memcpy(mv_cache[3][1], s->current_picture.motion_val[0][mot_xy+mot_stride], sizeof(int16_t)*4); ++ memcpy(mv_cache[1][1], s->current_picture.f.motion_val[0][mot_xy ], sizeof(int16_t) * 4); ++ memcpy(mv_cache[2][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); ++ memcpy(mv_cache[3][1], s->current_picture.f.motion_val[0][mot_xy + mot_stride], sizeof(int16_t) * 4); + +- if(mb_y==0 || IS_INTRA(s->current_picture.mb_type[xy-s->mb_stride])){ ++ if (mb_y == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - s->mb_stride])) { + memcpy(mv_cache[0][1], mv_cache[1][1], sizeof(int16_t)*4); + }else{ +- memcpy(mv_cache[0][1], s->current_picture.motion_val[0][mot_xy-mot_stride], sizeof(int16_t)*4); ++ memcpy(mv_cache[0][1], s->current_picture.f.motion_val[0][mot_xy - mot_stride], sizeof(int16_t) * 4); + } + +- if(mb_x==0 || IS_INTRA(s->current_picture.mb_type[xy-1])){ ++ if (mb_x == 0 || IS_INTRA(s->current_picture.f.mb_type[xy - 1])) { + AV_COPY32(mv_cache[1][0], mv_cache[1][1]); + AV_COPY32(mv_cache[2][0], mv_cache[2][1]); + }else{ +- AV_COPY32(mv_cache[1][0], s->current_picture.motion_val[0][mot_xy-1]); +- AV_COPY32(mv_cache[2][0], s->current_picture.motion_val[0][mot_xy-1+mot_stride]); ++ AV_COPY32(mv_cache[1][0], s->current_picture.f.motion_val[0][mot_xy - 1]); ++ AV_COPY32(mv_cache[2][0], s->current_picture.f.motion_val[0][mot_xy - 1 + mot_stride]); + } + +- if(mb_x+1>=s->mb_width || IS_INTRA(s->current_picture.mb_type[xy+1])){ ++ if (mb_x + 1 >= s->mb_width || IS_INTRA(s->current_picture.f.mb_type[xy + 1])) { + AV_COPY32(mv_cache[1][3], mv_cache[1][2]); + AV_COPY32(mv_cache[2][3], mv_cache[2][2]); + }else{ +- AV_COPY32(mv_cache[1][3], s->current_picture.motion_val[0][mot_xy+2]); +- AV_COPY32(mv_cache[2][3], s->current_picture.motion_val[0][mot_xy+2+mot_stride]); ++ AV_COPY32(mv_cache[1][3], s->current_picture.f.motion_val[0][mot_xy + 2]); ++ AV_COPY32(mv_cache[2][3], s->current_picture.f.motion_val[0][mot_xy + 2 + mot_stride]); + } + + mx = 0; +@@ -725,7 +725,7 @@ + 0, 0, 0, + ref_picture, pix_op, qpix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); +- }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel){ ++ }else if(!is_mpeg12 && (CONFIG_WMV2_DECODER || CONFIG_WMV2_ENCODER) && s->mspel && s->codec_id == CODEC_ID_WMV2){ + ff_mspel_motion(s, dest_y, dest_cb, dest_cr, + ref_picture, pix_op, + s->mv[dir][0][0], s->mv[dir][0][1], 16); +@@ -760,8 +760,8 @@ + + ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); + if(s->flags&CODEC_FLAG_EMU_EDGE){ +- if( (unsigned)src_x > s->h_edge_pos - (motion_x&3) - 8 +- || (unsigned)src_y > s->v_edge_pos - (motion_y&3) - 8 ){ ++ if( (unsigned)src_x > FFMAX(s->h_edge_pos - (motion_x&3) - 8, 0) ++ || (unsigned)src_y > FFMAX(s->v_edge_pos - (motion_y&3) - 8, 0)){ + s->dsp.emulated_edge_mc(s->edge_emu_buffer, ptr, + s->linesize, 9, 9, + src_x, src_y, +@@ -816,8 +816,8 @@ + s->mv[dir][1][0], s->mv[dir][1][1], 8, mb_y); + } + } else { +- if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != FF_B_TYPE && !s->first_field){ +- ref_picture= s->current_picture_ptr->data; ++ if(s->picture_structure != s->field_select[dir][0] + 1 && s->pict_type != AV_PICTURE_TYPE_B && !s->first_field){ ++ ref_picture = s->current_picture_ptr->f.data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, +@@ -831,10 +831,10 @@ + uint8_t ** ref2picture; + + if(s->picture_structure == s->field_select[dir][i] + 1 +- || s->pict_type == FF_B_TYPE || s->first_field){ ++ || s->pict_type == AV_PICTURE_TYPE_B || s->first_field){ + ref2picture= ref_picture; + }else{ +- ref2picture= s->current_picture_ptr->data; ++ ref2picture = s->current_picture_ptr->f.data; + } + + mpeg_motion(s, dest_y, dest_cb, dest_cr, +@@ -871,7 +871,7 @@ + + //opposite parity is always in the same frame if this is second field + if(!s->first_field){ +- ref_picture = s->current_picture_ptr->data; ++ ref_picture = s->current_picture_ptr->f.data; + } + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_enc.c 2012-05-14 14:08:54.068334629 +0200 +@@ -28,6 +28,8 @@ + */ + + #include "libavutil/intmath.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" +@@ -36,11 +38,13 @@ + #include "mjpegenc.h" + #include "msmpeg4.h" + #include "faandct.h" ++#include "thread.h" + #include "aandcttab.h" + #include "flv.h" + #include "mpeg4video.h" + #include "internal.h" + #include ++#include "sp5x.h" + + //#undef NDEBUG + //#include +@@ -56,156 +60,187 @@ + + //#define DEBUG + +-static uint8_t default_mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; +-static uint8_t default_fcode_tab[MAX_MV*2+1]; ++static uint8_t default_mv_penalty[MAX_FCODE + 1][MAX_MV * 2 + 1]; ++static uint8_t default_fcode_tab[MAX_MV * 2 + 1]; + +-void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], uint16_t (*qmat16)[2][64], +- const uint16_t *quant_matrix, int bias, int qmin, int qmax, int intra) ++void ff_convert_matrix(DSPContext *dsp, int (*qmat)[64], ++ uint16_t (*qmat16)[2][64], ++ const uint16_t *quant_matrix, ++ int bias, int qmin, int qmax, int intra) + { + int qscale; +- int shift=0; ++ int shift = 0; + +- for(qscale=qmin; qscale<=qmax; qscale++){ ++ for (qscale = qmin; qscale <= qmax; qscale++) { + int i; +- if (dsp->fdct == ff_jpeg_fdct_islow ++ if (dsp->fdct == ff_jpeg_fdct_islow_8 || ++ dsp->fdct == ff_jpeg_fdct_islow_10 + #ifdef FAAN_POSTSCALE + || dsp->fdct == ff_faandct + #endif + ) { +- for(i=0;i<64;i++) { +- const int j= dsp->idct_permutation[i]; +- /* 16 <= qscale * quant_matrix[i] <= 7905 */ +- /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ +- /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1 << 36) / 249205026 */ +- /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */ ++ for (i = 0; i < 64; i++) { ++ const int j = dsp->idct_permutation[i]; ++ /* 16 <= qscale * quant_matrix[i] <= 7905 ++ * Assume x = ff_aanscales[i] * qscale * quant_matrix[i] ++ * 19952 <= x <= 249205026 ++ * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026 ++ * 3444240 >= (1 << 36) / (x) >= 275 */ + + qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / +- (qscale * quant_matrix[j])); ++ (qscale * quant_matrix[j])); + } + } else if (dsp->fdct == fdct_ifast + #ifndef FAAN_POSTSCALE + || dsp->fdct == ff_faandct + #endif + ) { +- for(i=0;i<64;i++) { +- const int j= dsp->idct_permutation[i]; +- /* 16 <= qscale * quant_matrix[i] <= 7905 */ +- /* 19952 <= ff_aanscales[i] * qscale * quant_matrix[i] <= 249205026 */ +- /* (1 << 36) / 19952 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= (1<<36)/249205026 */ +- /* 3444240 >= (1 << 36) / (ff_aanscales[i] * qscale * quant_matrix[i]) >= 275 */ ++ for (i = 0; i < 64; i++) { ++ const int j = dsp->idct_permutation[i]; ++ /* 16 <= qscale * quant_matrix[i] <= 7905 ++ * Assume x = ff_aanscales[i] * qscale * quant_matrix[i] ++ * 19952 <= x <= 249205026 ++ * (1 << 36) / 19952 >= (1 << 36) / (x) >= (1 << 36) / 249205026 ++ * 3444240 >= (1 << 36) / (x) >= 275 */ + + qmat[qscale][i] = (int)((UINT64_C(1) << (QMAT_SHIFT + 14)) / +- (ff_aanscales[i] * qscale * quant_matrix[j])); ++ (ff_aanscales[i] * qscale * quant_matrix[j])); + } + } else { +- for(i=0;i<64;i++) { +- const int j= dsp->idct_permutation[i]; ++ for (i = 0; i < 64; i++) { ++ const int j = dsp->idct_permutation[i]; + /* We can safely suppose that 16 <= quant_matrix[i] <= 255 +- So 16 <= qscale * quant_matrix[i] <= 7905 +- so (1<<19) / 16 >= (1<<19) / (qscale * quant_matrix[i]) >= (1<<19) / 7905 +- so 32768 >= (1<<19) / (qscale * quant_matrix[i]) >= 67 +- */ +- qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / (qscale * quant_matrix[j])); +-// qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[i]); +- qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / (qscale * quant_matrix[j]); +- +- if(qmat16[qscale][0][i]==0 || qmat16[qscale][0][i]==128*256) qmat16[qscale][0][i]=128*256-1; +- qmat16[qscale][1][i]= ROUNDED_DIV(bias<<(16-QUANT_BIAS_SHIFT), qmat16[qscale][0][i]); ++ * Assume x = qscale * quant_matrix[i] ++ * So 16 <= x <= 7905 ++ * so (1 << 19) / 16 >= (1 << 19) / (x) >= (1 << 19) / 7905 ++ * so 32768 >= (1 << 19) / (x) >= 67 */ ++ qmat[qscale][i] = (int)((UINT64_C(1) << QMAT_SHIFT) / ++ (qscale * quant_matrix[j])); ++ //qmat [qscale][i] = (1 << QMAT_SHIFT_MMX) / ++ // (qscale * quant_matrix[i]); ++ qmat16[qscale][0][i] = (1 << QMAT_SHIFT_MMX) / ++ (qscale * quant_matrix[j]); ++ ++ if (qmat16[qscale][0][i] == 0 || ++ qmat16[qscale][0][i] == 128 * 256) ++ qmat16[qscale][0][i] = 128 * 256 - 1; ++ qmat16[qscale][1][i] = ++ ROUNDED_DIV(bias << (16 - QUANT_BIAS_SHIFT), ++ qmat16[qscale][0][i]); + } + } + +- for(i=intra; i<64; i++){ +- int64_t max= 8191; ++ for (i = intra; i < 64; i++) { ++ int64_t max = 8191; + if (dsp->fdct == fdct_ifast + #ifndef FAAN_POSTSCALE +- || dsp->fdct == ff_faandct ++ || dsp->fdct == ff_faandct + #endif +- ) { +- max = (8191LL*ff_aanscales[i]) >> 14; ++ ) { ++ max = (8191LL * ff_aanscales[i]) >> 14; + } +- while(((max * qmat[qscale][i]) >> shift) > INT_MAX){ ++ while (((max * qmat[qscale][i]) >> shift) > INT_MAX) { + shift++; + } + } + } +- if(shift){ +- av_log(NULL, AV_LOG_INFO, "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", QMAT_SHIFT - shift); ++ if (shift) { ++ av_log(NULL, AV_LOG_INFO, ++ "Warning, QMAT_SHIFT is larger than %d, overflows possible\n", ++ QMAT_SHIFT - shift); + } + } + +-static inline void update_qscale(MpegEncContext *s){ +- s->qscale= (s->lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); +- s->qscale= av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); ++static inline void update_qscale(MpegEncContext *s) ++{ ++ s->qscale = (s->lambda * 139 + FF_LAMBDA_SCALE * 64) >> ++ (FF_LAMBDA_SHIFT + 7); ++ s->qscale = av_clip(s->qscale, s->avctx->qmin, s->avctx->qmax); + +- s->lambda2= (s->lambda*s->lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; ++ s->lambda2 = (s->lambda * s->lambda + FF_LAMBDA_SCALE / 2) >> ++ FF_LAMBDA_SHIFT; + } + +-void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix){ ++void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix) ++{ + int i; + +- if(matrix){ ++ if (matrix) { + put_bits(pb, 1, 1); +- for(i=0;i<64;i++) { +- put_bits(pb, 8, matrix[ ff_zigzag_direct[i] ]); ++ for (i = 0; i < 64; i++) { ++ put_bits(pb, 8, matrix[ff_zigzag_direct[i]]); + } +- }else ++ } else + put_bits(pb, 1, 0); + } + + /** + * init s->current_picture.qscale_table from s->lambda_table + */ +-void ff_init_qscale_tab(MpegEncContext *s){ +- int8_t * const qscale_table= s->current_picture.qscale_table; ++void ff_init_qscale_tab(MpegEncContext *s) ++{ ++ int8_t * const qscale_table = s->current_picture.f.qscale_table; + int i; + +- for(i=0; imb_num; i++){ +- unsigned int lam= s->lambda_table[ s->mb_index2xy[i] ]; +- int qp= (lam*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); +- qscale_table[ s->mb_index2xy[i] ]= av_clip(qp, s->avctx->qmin, s->avctx->qmax); ++ for (i = 0; i < s->mb_num; i++) { ++ unsigned int lam = s->lambda_table[s->mb_index2xy[i]]; ++ int qp = (lam * 139 + FF_LAMBDA_SCALE * 64) >> (FF_LAMBDA_SHIFT + 7); ++ qscale_table[s->mb_index2xy[i]] = av_clip(qp, s->avctx->qmin, ++ s->avctx->qmax); + } + } + +-static void copy_picture_attributes(MpegEncContext *s, AVFrame *dst, AVFrame *src){ ++static void copy_picture_attributes(MpegEncContext *s, ++ AVFrame *dst, ++ AVFrame *src) ++{ + int i; + + dst->pict_type = src->pict_type; + dst->quality = src->quality; + dst->coded_picture_number = src->coded_picture_number; + dst->display_picture_number = src->display_picture_number; +-// dst->reference = src->reference; ++ //dst->reference = src->reference; + dst->pts = src->pts; + dst->interlaced_frame = src->interlaced_frame; + dst->top_field_first = src->top_field_first; + +- if(s->avctx->me_threshold){ +- if(!src->motion_val[0]) ++ if (s->avctx->me_threshold) { ++ if (!src->motion_val[0]) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_val not set!\n"); +- if(!src->mb_type) ++ if (!src->mb_type) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.mb_type not set!\n"); +- if(!src->ref_index[0]) ++ if (!src->ref_index[0]) + av_log(s->avctx, AV_LOG_ERROR, "AVFrame.ref_index not set!\n"); +- if(src->motion_subsample_log2 != dst->motion_subsample_log2) +- av_log(s->avctx, AV_LOG_ERROR, "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", +- src->motion_subsample_log2, dst->motion_subsample_log2); ++ if (src->motion_subsample_log2 != dst->motion_subsample_log2) ++ av_log(s->avctx, AV_LOG_ERROR, ++ "AVFrame.motion_subsample_log2 doesn't match! (%d!=%d)\n", ++ src->motion_subsample_log2, dst->motion_subsample_log2); + +- memcpy(dst->mb_type, src->mb_type, s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); ++ memcpy(dst->mb_type, src->mb_type, ++ s->mb_stride * s->mb_height * sizeof(dst->mb_type[0])); + +- for(i=0; i<2; i++){ +- int stride= ((16*s->mb_width )>>src->motion_subsample_log2) + 1; +- int height= ((16*s->mb_height)>>src->motion_subsample_log2); ++ for (i = 0; i < 2; i++) { ++ int stride = ((16 * s->mb_width ) >> ++ src->motion_subsample_log2) + 1; ++ int height = ((16 * s->mb_height) >> src->motion_subsample_log2); + +- if(src->motion_val[i] && src->motion_val[i] != dst->motion_val[i]){ +- memcpy(dst->motion_val[i], src->motion_val[i], 2*stride*height*sizeof(int16_t)); ++ if (src->motion_val[i] && ++ src->motion_val[i] != dst->motion_val[i]) { ++ memcpy(dst->motion_val[i], src->motion_val[i], ++ 2 * stride * height * sizeof(int16_t)); + } +- if(src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]){ +- memcpy(dst->ref_index[i], src->ref_index[i], s->mb_stride*4*s->mb_height*sizeof(int8_t)); ++ if (src->ref_index[i] && src->ref_index[i] != dst->ref_index[i]) { ++ memcpy(dst->ref_index[i], src->ref_index[i], ++ s->mb_stride * 4 * s->mb_height * sizeof(int8_t)); + } + } + } + } + +-static void update_duplicate_context_after_me(MpegEncContext *dst, MpegEncContext *src){ ++static void update_duplicate_context_after_me(MpegEncContext *dst, ++ MpegEncContext *src) ++{ + #define COPY(a) dst->a= src->a + COPY(pict_type); + COPY(current_picture); +@@ -216,25 +251,26 @@ + COPY(lambda2); + COPY(picture_in_gop_number); + COPY(gop_picture_number); +- COPY(frame_pred_frame_dct); //FIXME don't set in encode_header +- COPY(progressive_frame); //FIXME don't set in encode_header +- COPY(partitioned_frame); //FIXME don't set in encode_header ++ COPY(frame_pred_frame_dct); // FIXME don't set in encode_header ++ COPY(progressive_frame); // FIXME don't set in encode_header ++ COPY(partitioned_frame); // FIXME don't set in encode_header + #undef COPY + } + + /** +- * sets the given MpegEncContext to defaults for encoding. ++ * Set the given MpegEncContext to defaults for encoding. + * the changed fields will not depend upon the prior state of the MpegEncContext. + */ +-static void MPV_encode_defaults(MpegEncContext *s){ ++static void MPV_encode_defaults(MpegEncContext *s) ++{ + int i; + MPV_common_defaults(s); + +- for(i=-16; i<16; i++){ +- default_fcode_tab[i + MAX_MV]= 1; ++ for (i = -16; i < 16; i++) { ++ default_fcode_tab[i + MAX_MV] = 1; + } +- s->me.mv_penalty= default_mv_penalty; +- s->fcode_tab= default_fcode_tab; ++ s->me.mv_penalty = default_mv_penalty; ++ s->fcode_tab = default_fcode_tab; + } + + /* init video encoder */ +@@ -248,27 +284,39 @@ + + switch (avctx->codec_id) { + case CODEC_ID_MPEG2VIDEO: +- if(avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P){ +- av_log(avctx, AV_LOG_ERROR, "only YUV420 and YUV422 are supported\n"); ++ if (avctx->pix_fmt != PIX_FMT_YUV420P && ++ avctx->pix_fmt != PIX_FMT_YUV422P) { ++ av_log(avctx, AV_LOG_ERROR, ++ "only YUV420 and YUV422 are supported\n"); + return -1; + } + break; + case CODEC_ID_LJPEG: +- if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && avctx->pix_fmt != PIX_FMT_YUVJ444P && avctx->pix_fmt != PIX_FMT_BGRA && +- ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P && avctx->pix_fmt != PIX_FMT_YUV444P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ ++ if (avctx->pix_fmt != PIX_FMT_YUVJ420P && ++ avctx->pix_fmt != PIX_FMT_YUVJ422P && ++ avctx->pix_fmt != PIX_FMT_YUVJ444P && ++ avctx->pix_fmt != PIX_FMT_BGRA && ++ ((avctx->pix_fmt != PIX_FMT_YUV420P && ++ avctx->pix_fmt != PIX_FMT_YUV422P && ++ avctx->pix_fmt != PIX_FMT_YUV444P) || ++ avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) { + av_log(avctx, AV_LOG_ERROR, "colorspace not supported in LJPEG\n"); + return -1; + } + break; + case CODEC_ID_MJPEG: +- if(avctx->pix_fmt != PIX_FMT_YUVJ420P && avctx->pix_fmt != PIX_FMT_YUVJ422P && +- ((avctx->pix_fmt != PIX_FMT_YUV420P && avctx->pix_fmt != PIX_FMT_YUV422P) || avctx->strict_std_compliance>FF_COMPLIANCE_UNOFFICIAL)){ ++ case CODEC_ID_AMV: ++ if (avctx->pix_fmt != PIX_FMT_YUVJ420P && ++ avctx->pix_fmt != PIX_FMT_YUVJ422P && ++ ((avctx->pix_fmt != PIX_FMT_YUV420P && ++ avctx->pix_fmt != PIX_FMT_YUV422P) || ++ avctx->strict_std_compliance > FF_COMPLIANCE_UNOFFICIAL)) { + av_log(avctx, AV_LOG_ERROR, "colorspace not supported in jpeg\n"); + return -1; + } + break; + default: +- if(avctx->pix_fmt != PIX_FMT_YUV420P){ ++ if (avctx->pix_fmt != PIX_FMT_YUV420P) { + av_log(avctx, AV_LOG_ERROR, "only YUV420 is supported\n"); + return -1; + } +@@ -287,31 +335,37 @@ + } + + s->bit_rate = avctx->bit_rate; +- s->width = avctx->width; +- s->height = avctx->height; +- if(avctx->gop_size > 600 && avctx->strict_std_compliance>FF_COMPLIANCE_EXPERIMENTAL){ +- av_log(avctx, AV_LOG_ERROR, "Warning keyframe interval too large! reducing it ...\n"); +- avctx->gop_size=600; +- } +- s->gop_size = avctx->gop_size; +- s->avctx = avctx; +- s->flags= avctx->flags; +- s->flags2= avctx->flags2; +- s->max_b_frames= avctx->max_b_frames; +- s->codec_id= avctx->codec->id; +- s->luma_elim_threshold = avctx->luma_elim_threshold; +- s->chroma_elim_threshold= avctx->chroma_elim_threshold; +- s->strict_std_compliance= avctx->strict_std_compliance; +- s->data_partitioning= avctx->flags & CODEC_FLAG_PART; +- s->quarter_sample= (avctx->flags & CODEC_FLAG_QPEL)!=0; +- s->mpeg_quant= avctx->mpeg_quant; +- s->rtp_mode= !!avctx->rtp_payload_size; +- s->intra_dc_precision= avctx->intra_dc_precision; ++ s->width = avctx->width; ++ s->height = avctx->height; ++ if (avctx->gop_size > 600 && ++ avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { ++ av_log(avctx, AV_LOG_WARNING, ++ "keyframe interval too large!, reducing it from %d to %d\n", ++ avctx->gop_size, 600); ++ avctx->gop_size = 600; ++ } ++ s->gop_size = avctx->gop_size; ++ s->avctx = avctx; ++ s->flags = avctx->flags; ++ s->flags2 = avctx->flags2; ++ s->max_b_frames = avctx->max_b_frames; ++ s->codec_id = avctx->codec->id; ++ s->luma_elim_threshold = avctx->luma_elim_threshold; ++ s->chroma_elim_threshold = avctx->chroma_elim_threshold; ++ s->strict_std_compliance = avctx->strict_std_compliance; ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (avctx->flags & CODEC_FLAG_PART) ++ s->data_partitioning = 1; ++#endif ++ s->quarter_sample = (avctx->flags & CODEC_FLAG_QPEL) != 0; ++ s->mpeg_quant = avctx->mpeg_quant; ++ s->rtp_mode = !!avctx->rtp_payload_size; ++ s->intra_dc_precision = avctx->intra_dc_precision; + s->user_specified_pts = AV_NOPTS_VALUE; + + if (s->gop_size <= 1) { + s->intra_only = 1; +- s->gop_size = 12; ++ s->gop_size = 12; + } else { + s->intra_only = 0; + } +@@ -321,397 +375,472 @@ + /* Fixed QSCALE */ + s->fixed_qscale = !!(avctx->flags & CODEC_FLAG_QSCALE); + +- s->adaptive_quant= ( s->avctx->lumi_masking +- || s->avctx->dark_masking +- || s->avctx->temporal_cplx_masking +- || s->avctx->spatial_cplx_masking +- || s->avctx->p_masking +- || s->avctx->border_masking +- || (s->flags&CODEC_FLAG_QP_RD)) +- && !s->fixed_qscale; +- +- s->obmc= !!(s->flags & CODEC_FLAG_OBMC); +- s->loop_filter= !!(s->flags & CODEC_FLAG_LOOP_FILTER); +- s->alternate_scan= !!(s->flags & CODEC_FLAG_ALT_SCAN); +- s->intra_vlc_format= !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); +- s->q_scale_type= !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); ++ s->adaptive_quant = (s->avctx->lumi_masking || ++ s->avctx->dark_masking || ++ s->avctx->temporal_cplx_masking || ++ s->avctx->spatial_cplx_masking || ++ s->avctx->p_masking || ++ s->avctx->border_masking || ++ (s->flags & CODEC_FLAG_QP_RD)) && ++ !s->fixed_qscale; ++ ++ s->loop_filter = !!(s->flags & CODEC_FLAG_LOOP_FILTER); ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ s->alternate_scan = !!(s->flags & CODEC_FLAG_ALT_SCAN); ++ s->intra_vlc_format = !!(s->flags2 & CODEC_FLAG2_INTRA_VLC); ++ s->q_scale_type = !!(s->flags2 & CODEC_FLAG2_NON_LINEAR_QUANT); ++ s->obmc = !!(s->flags & CODEC_FLAG_OBMC); ++#endif + +- if(avctx->rc_max_rate && !avctx->rc_buffer_size){ +- av_log(avctx, AV_LOG_ERROR, "a vbv buffer size is needed, for encoding with a maximum bitrate\n"); ++ if (avctx->rc_max_rate && !avctx->rc_buffer_size) { ++ av_log(avctx, AV_LOG_ERROR, ++ "a vbv buffer size is needed, " ++ "for encoding with a maximum bitrate\n"); + return -1; + } + +- if(avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate){ +- av_log(avctx, AV_LOG_INFO, "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); ++ if (avctx->rc_min_rate && avctx->rc_max_rate != avctx->rc_min_rate) { ++ av_log(avctx, AV_LOG_INFO, ++ "Warning min_rate > 0 but min_rate != max_rate isn't recommended!\n"); + } + +- if(avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate){ ++ if (avctx->rc_min_rate && avctx->rc_min_rate > avctx->bit_rate) { + av_log(avctx, AV_LOG_ERROR, "bitrate below min bitrate\n"); + return -1; + } + +- if(avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate){ +- av_log(avctx, AV_LOG_INFO, "bitrate above max bitrate\n"); ++ if (avctx->rc_max_rate && avctx->rc_max_rate < avctx->bit_rate) { ++ av_log(avctx, AV_LOG_ERROR, "bitrate above max bitrate\n"); + return -1; + } + +- if(avctx->rc_max_rate && avctx->rc_max_rate == avctx->bit_rate && avctx->rc_max_rate != avctx->rc_min_rate){ +- av_log(avctx, AV_LOG_INFO, "impossible bitrate constraints, this will fail\n"); ++ if (avctx->rc_max_rate && ++ avctx->rc_max_rate == avctx->bit_rate && ++ avctx->rc_max_rate != avctx->rc_min_rate) { ++ av_log(avctx, AV_LOG_INFO, ++ "impossible bitrate constraints, this will fail\n"); + } + +- if(avctx->rc_buffer_size && avctx->bit_rate*(int64_t)avctx->time_base.num > avctx->rc_buffer_size * (int64_t)avctx->time_base.den){ ++ if (avctx->rc_buffer_size && ++ avctx->bit_rate * (int64_t)avctx->time_base.num > ++ avctx->rc_buffer_size * (int64_t)avctx->time_base.den) { + av_log(avctx, AV_LOG_ERROR, "VBV buffer too small for bitrate\n"); + return -1; + } + +- if(!s->fixed_qscale && avctx->bit_rate*av_q2d(avctx->time_base) > avctx->bit_rate_tolerance){ +- av_log(avctx, AV_LOG_ERROR, "bitrate tolerance too small for bitrate\n"); ++ if (!s->fixed_qscale && ++ avctx->bit_rate * av_q2d(avctx->time_base) > ++ avctx->bit_rate_tolerance) { ++ av_log(avctx, AV_LOG_ERROR, ++ "bitrate tolerance too small for bitrate\n"); + return -1; + } + +- if( s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate +- && (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO) +- && 90000LL * (avctx->rc_buffer_size-1) > s->avctx->rc_max_rate*0xFFFFLL){ +- +- av_log(avctx, AV_LOG_INFO, "Warning vbv_delay will be set to 0xFFFF (=VBR) as the specified vbv buffer is too large for the given bitrate!\n"); ++ if (s->avctx->rc_max_rate && ++ s->avctx->rc_min_rate == s->avctx->rc_max_rate && ++ (s->codec_id == CODEC_ID_MPEG1VIDEO || ++ s->codec_id == CODEC_ID_MPEG2VIDEO) && ++ 90000LL * (avctx->rc_buffer_size - 1) > ++ s->avctx->rc_max_rate * 0xFFFFLL) { ++ av_log(avctx, AV_LOG_INFO, ++ "Warning vbv_delay will be set to 0xFFFF (=VBR) as the " ++ "specified vbv buffer is too large for the given bitrate!\n"); + } + +- if((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 +- && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && s->codec_id != CODEC_ID_FLV1){ ++ if ((s->flags & CODEC_FLAG_4MV) && s->codec_id != CODEC_ID_MPEG4 && ++ s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P && ++ s->codec_id != CODEC_ID_FLV1) { + av_log(avctx, AV_LOG_ERROR, "4MV not supported by codec\n"); + return -1; + } + +- if(s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE){ +- av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with simple mb decision\n"); ++ if (s->obmc && s->avctx->mb_decision != FF_MB_DECISION_SIMPLE) { ++ av_log(avctx, AV_LOG_ERROR, ++ "OBMC is only supported with simple mb decision\n"); + return -1; + } + +- if(s->obmc && s->codec_id != CODEC_ID_H263 && s->codec_id != CODEC_ID_H263P){ ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (s->obmc && s->codec_id != CODEC_ID_H263 && ++ s->codec_id != CODEC_ID_H263P) { + av_log(avctx, AV_LOG_ERROR, "OBMC is only supported with H263(+)\n"); + return -1; + } ++#endif + +- if(s->quarter_sample && s->codec_id != CODEC_ID_MPEG4){ ++ if (s->quarter_sample && s->codec_id != CODEC_ID_MPEG4) { + av_log(avctx, AV_LOG_ERROR, "qpel not supported by codec\n"); + return -1; + } + +- if(s->data_partitioning && s->codec_id != CODEC_ID_MPEG4){ +- av_log(avctx, AV_LOG_ERROR, "data partitioning not supported by codec\n"); ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (s->data_partitioning && s->codec_id != CODEC_ID_MPEG4) { ++ av_log(avctx, AV_LOG_ERROR, ++ "data partitioning not supported by codec\n"); + return -1; + } ++#endif + +- if(s->max_b_frames && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO){ ++ if (s->max_b_frames && ++ s->codec_id != CODEC_ID_MPEG4 && ++ s->codec_id != CODEC_ID_MPEG1VIDEO && ++ s->codec_id != CODEC_ID_MPEG2VIDEO) { + av_log(avctx, AV_LOG_ERROR, "b frames not supported by codec\n"); + return -1; + } + +- if ((s->codec_id == CODEC_ID_MPEG4 || s->codec_id == CODEC_ID_H263 || ++ if ((s->codec_id == CODEC_ID_MPEG4 || ++ s->codec_id == CODEC_ID_H263 || + s->codec_id == CODEC_ID_H263P) && +- (avctx->sample_aspect_ratio.num > 255 || avctx->sample_aspect_ratio.den > 255)) { +- av_log(avctx, AV_LOG_ERROR, "Invalid pixel aspect ratio %i/%i, limit is 255/255\n", ++ (avctx->sample_aspect_ratio.num > 255 || ++ avctx->sample_aspect_ratio.den > 255)) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Invalid pixel aspect ratio %i/%i, limit is 255/255 reducing\n", + avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den); +- return -1; ++ av_reduce(&avctx->sample_aspect_ratio.num, &avctx->sample_aspect_ratio.den, ++ avctx->sample_aspect_ratio.num, avctx->sample_aspect_ratio.den, 255); + } + +- if((s->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)) +- && s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO){ ++ if ((s->flags & (CODEC_FLAG_INTERLACED_DCT | CODEC_FLAG_INTERLACED_ME ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ | CODEC_FLAG_ALT_SCAN ++#endif ++ )) && ++ s->codec_id != CODEC_ID_MPEG4 && s->codec_id != CODEC_ID_MPEG2VIDEO) { + av_log(avctx, AV_LOG_ERROR, "interlacing not supported by codec\n"); + return -1; + } + +- if(s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4){ //FIXME mpeg2 uses that too +- av_log(avctx, AV_LOG_ERROR, "mpeg2 style quantization not supported by codec\n"); ++ // FIXME mpeg2 uses that too ++ if (s->mpeg_quant && s->codec_id != CODEC_ID_MPEG4) { ++ av_log(avctx, AV_LOG_ERROR, ++ "mpeg2 style quantization not supported by codec\n"); + return -1; + } + +- if((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis){ ++ if ((s->flags & CODEC_FLAG_CBP_RD) && !avctx->trellis) { + av_log(avctx, AV_LOG_ERROR, "CBP RD needs trellis quant\n"); + return -1; + } + +- if((s->flags & CODEC_FLAG_QP_RD) && s->avctx->mb_decision != FF_MB_DECISION_RD){ ++ if ((s->flags & CODEC_FLAG_QP_RD) && ++ s->avctx->mb_decision != FF_MB_DECISION_RD) { + av_log(avctx, AV_LOG_ERROR, "QP RD needs mbd=2\n"); + return -1; + } + +- if(s->avctx->scenechange_threshold < 1000000000 && (s->flags & CODEC_FLAG_CLOSED_GOP)){ +- av_log(avctx, AV_LOG_ERROR, "closed gop with scene change detection are not supported yet, set threshold to 1000000000\n"); ++ if (s->avctx->scenechange_threshold < 1000000000 && ++ (s->flags & CODEC_FLAG_CLOSED_GOP)) { ++ av_log(avctx, AV_LOG_ERROR, ++ "closed gop with scene change detection are not supported yet, " ++ "set threshold to 1000000000\n"); + return -1; + } + +- if((s->flags2 & CODEC_FLAG2_INTRA_VLC) && s->codec_id != CODEC_ID_MPEG2VIDEO){ +- av_log(avctx, AV_LOG_ERROR, "intra vlc table not supported by codec\n"); ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if ((s->flags2 & CODEC_FLAG2_INTRA_VLC) && ++ s->codec_id != CODEC_ID_MPEG2VIDEO) { ++ av_log(avctx, AV_LOG_ERROR, ++ "intra vlc table not supported by codec\n"); + return -1; + } ++#endif + +- if(s->flags & CODEC_FLAG_LOW_DELAY){ +- if (s->codec_id != CODEC_ID_MPEG2VIDEO){ +- av_log(avctx, AV_LOG_ERROR, "low delay forcing is only available for mpeg2\n"); ++ if (s->flags & CODEC_FLAG_LOW_DELAY) { ++ if (s->codec_id != CODEC_ID_MPEG2VIDEO) { ++ av_log(avctx, AV_LOG_ERROR, ++ "low delay forcing is only available for mpeg2\n"); + return -1; + } +- if (s->max_b_frames != 0){ +- av_log(avctx, AV_LOG_ERROR, "b frames cannot be used with low delay\n"); ++ if (s->max_b_frames != 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "b frames cannot be used with low delay\n"); + return -1; + } + } + +- if(s->q_scale_type == 1){ +- if(s->codec_id != CODEC_ID_MPEG2VIDEO){ +- av_log(avctx, AV_LOG_ERROR, "non linear quant is only available for mpeg2\n"); ++ if (s->q_scale_type == 1) { ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (s->codec_id != CODEC_ID_MPEG2VIDEO) { ++ av_log(avctx, AV_LOG_ERROR, ++ "non linear quant is only available for mpeg2\n"); + return -1; + } +- if(avctx->qmax > 12){ +- av_log(avctx, AV_LOG_ERROR, "non linear quant only supports qmax <= 12 currently\n"); ++#endif ++ if (avctx->qmax > 12) { ++ av_log(avctx, AV_LOG_ERROR, ++ "non linear quant only supports qmax <= 12 currently\n"); + return -1; + } + } + +- if(s->avctx->thread_count > 1 && s->codec_id != CODEC_ID_MPEG4 +- && s->codec_id != CODEC_ID_MPEG1VIDEO && s->codec_id != CODEC_ID_MPEG2VIDEO +- && (s->codec_id != CODEC_ID_H263P || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT))){ +- av_log(avctx, AV_LOG_ERROR, "multi threaded encoding not supported by codec\n"); ++ if (s->avctx->thread_count > 1 && ++ s->codec_id != CODEC_ID_MPEG4 && ++ s->codec_id != CODEC_ID_MPEG1VIDEO && ++ s->codec_id != CODEC_ID_MPEG2VIDEO && ++ (s->codec_id != CODEC_ID_H263P ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ || !(s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ++#endif ++ )) { ++ av_log(avctx, AV_LOG_ERROR, ++ "multi threaded encoding not supported by codec\n"); + return -1; + } + +- if(s->avctx->thread_count < 1){ +- av_log(avctx, AV_LOG_ERROR, "automatic thread number detection not supported by codec, patch welcome\n"); ++ if (s->avctx->thread_count < 1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "automatic thread number detection not supported by codec, " ++ "patch welcome\n"); + return -1; + } + +- if(s->avctx->thread_count > 1) +- s->rtp_mode= 1; ++ if (s->avctx->thread_count > 1) ++ s->rtp_mode = 1; + +- if(!avctx->time_base.den || !avctx->time_base.num){ ++ if (!avctx->time_base.den || !avctx->time_base.num) { + av_log(avctx, AV_LOG_ERROR, "framerate not set\n"); + return -1; + } + +- i= (INT_MAX/2+128)>>8; +- if(avctx->me_threshold >= i){ +- av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", i - 1); ++ i = (INT_MAX / 2 + 128) >> 8; ++ if (avctx->me_threshold >= i) { ++ av_log(avctx, AV_LOG_ERROR, "me_threshold too large, max is %d\n", ++ i - 1); + return -1; + } +- if(avctx->mb_threshold >= i){ +- av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", i - 1); ++ if (avctx->mb_threshold >= i) { ++ av_log(avctx, AV_LOG_ERROR, "mb_threshold too large, max is %d\n", ++ i - 1); + return -1; + } + +- if(avctx->b_frame_strategy && (avctx->flags&CODEC_FLAG_PASS2)){ +- av_log(avctx, AV_LOG_INFO, "notice: b_frame_strategy only affects the first pass\n"); ++ if (avctx->b_frame_strategy && (avctx->flags & CODEC_FLAG_PASS2)) { ++ av_log(avctx, AV_LOG_INFO, ++ "notice: b_frame_strategy only affects the first pass\n"); + avctx->b_frame_strategy = 0; + } + +- i= av_gcd(avctx->time_base.den, avctx->time_base.num); +- if(i > 1){ ++ i = av_gcd(avctx->time_base.den, avctx->time_base.num); ++ if (i > 1) { + av_log(avctx, AV_LOG_INFO, "removing common factors from framerate\n"); + avctx->time_base.den /= i; + avctx->time_base.num /= i; +-// return -1; ++ //return -1; + } + +- if(s->mpeg_quant || s->codec_id==CODEC_ID_MPEG1VIDEO || s->codec_id==CODEC_ID_MPEG2VIDEO || s->codec_id==CODEC_ID_MJPEG){ +- s->intra_quant_bias= 3<<(QUANT_BIAS_SHIFT-3); //(a + x*3/8)/x +- s->inter_quant_bias= 0; +- }else{ +- s->intra_quant_bias=0; +- s->inter_quant_bias=-(1<<(QUANT_BIAS_SHIFT-2)); //(a - x/4)/x +- } +- +- if(avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) +- s->intra_quant_bias= avctx->intra_quant_bias; +- if(avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) +- s->inter_quant_bias= avctx->inter_quant_bias; +- +- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, &chroma_v_shift); +- +- if(avctx->codec_id == CODEC_ID_MPEG4 && s->avctx->time_base.den > (1<<16)-1){ +- av_log(avctx, AV_LOG_ERROR, "timebase %d/%d not supported by MPEG 4 standard, " +- "the maximum admitted value for the timebase denominator is %d\n", +- s->avctx->time_base.num, s->avctx->time_base.den, (1<<16)-1); ++ if (s->mpeg_quant || s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id==CODEC_ID_AMV) { ++ // (a + x * 3 / 8) / x ++ s->intra_quant_bias = 3 << (QUANT_BIAS_SHIFT - 3); ++ s->inter_quant_bias = 0; ++ } else { ++ s->intra_quant_bias = 0; ++ // (a - x / 4) / x ++ s->inter_quant_bias = -(1 << (QUANT_BIAS_SHIFT - 2)); ++ } ++ ++ if (avctx->intra_quant_bias != FF_DEFAULT_QUANT_BIAS) ++ s->intra_quant_bias = avctx->intra_quant_bias; ++ if (avctx->inter_quant_bias != FF_DEFAULT_QUANT_BIAS) ++ s->inter_quant_bias = avctx->inter_quant_bias; ++ ++ av_log(avctx, AV_LOG_DEBUG, "intra_quant_bias = %d inter_quant_bias = %d\n",s->intra_quant_bias,s->inter_quant_bias); ++ ++ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &chroma_h_shift, ++ &chroma_v_shift); ++ ++ if (avctx->codec_id == CODEC_ID_MPEG4 && ++ s->avctx->time_base.den > (1 << 16) - 1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "timebase %d/%d not supported by MPEG 4 standard, " ++ "the maximum admitted value for the timebase denominator " ++ "is %d\n", s->avctx->time_base.num, s->avctx->time_base.den, ++ (1 << 16) - 1); + return -1; + } + s->time_increment_bits = av_log2(s->avctx->time_base.den - 1) + 1; + +- switch(avctx->codec->id) { ++ switch (avctx->codec->id) { + case CODEC_ID_MPEG1VIDEO: + s->out_format = FMT_MPEG1; +- s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); +- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); ++ s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY); ++ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); + break; + case CODEC_ID_MPEG2VIDEO: + s->out_format = FMT_MPEG1; +- s->low_delay= !!(s->flags & CODEC_FLAG_LOW_DELAY); +- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); +- s->rtp_mode= 1; ++ s->low_delay = !!(s->flags & CODEC_FLAG_LOW_DELAY); ++ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); ++ s->rtp_mode = 1; + break; + case CODEC_ID_LJPEG: + case CODEC_ID_MJPEG: ++ case CODEC_ID_AMV: + s->out_format = FMT_MJPEG; + s->intra_only = 1; /* force intra only for jpeg */ +- if(avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA){ ++ if (avctx->codec->id == CODEC_ID_LJPEG && avctx->pix_fmt == PIX_FMT_BGRA) { + s->mjpeg_vsample[0] = s->mjpeg_hsample[0] = + s->mjpeg_vsample[1] = s->mjpeg_hsample[1] = + s->mjpeg_vsample[2] = s->mjpeg_hsample[2] = 1; +- }else{ ++ } else { + s->mjpeg_vsample[0] = 2; +- s->mjpeg_vsample[1] = 2>>chroma_v_shift; +- s->mjpeg_vsample[2] = 2>>chroma_v_shift; ++ s->mjpeg_vsample[1] = 2 >> chroma_v_shift; ++ s->mjpeg_vsample[2] = 2 >> chroma_v_shift; + s->mjpeg_hsample[0] = 2; +- s->mjpeg_hsample[1] = 2>>chroma_h_shift; +- s->mjpeg_hsample[2] = 2>>chroma_h_shift; ++ s->mjpeg_hsample[1] = 2 >> chroma_h_shift; ++ s->mjpeg_hsample[2] = 2 >> chroma_h_shift; + } +- if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) +- || ff_mjpeg_encode_init(s) < 0) ++ if (!(CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) || ++ ff_mjpeg_encode_init(s) < 0) + return -1; +- avctx->delay=0; +- s->low_delay=1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_H261: +- if (!CONFIG_H261_ENCODER) return -1; ++ if (!CONFIG_H261_ENCODER) ++ return -1; + if (ff_h261_get_picture_format(s->width, s->height) < 0) { +- av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the H.261 codec.\nValid sizes are 176x144, 352x288\n", s->width, s->height); ++ av_log(avctx, AV_LOG_ERROR, ++ "The specified picture size of %dx%d is not valid for the " ++ "H.261 codec.\nValid sizes are 176x144, 352x288\n", ++ s->width, s->height); + return -1; + } + s->out_format = FMT_H261; +- avctx->delay=0; +- s->low_delay=1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_H263: +- if (!CONFIG_H263_ENCODER) return -1; +- if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), s->width, s->height) == 8) { +- av_log(avctx, AV_LOG_INFO, "The specified picture size of %dx%d is not valid for the H.263 codec.\nValid sizes are 128x96, 176x144, 352x288, 704x576, and 1408x1152. Try H.263+.\n", s->width, s->height); ++ if (!CONFIG_H263_ENCODER) ++ return -1; ++ if (ff_match_2uint16(h263_format, FF_ARRAY_ELEMS(h263_format), ++ s->width, s->height) == 8) { ++ av_log(avctx, AV_LOG_ERROR, ++ "The specified picture size of %dx%d is not valid for " ++ "the H.263 codec.\nValid sizes are 128x96, 176x144, " ++ "352x288, 704x576, and 1408x1152. " ++ "Try H.263+.\n", s->width, s->height); + return -1; + } + s->out_format = FMT_H263; +- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; +- avctx->delay=0; +- s->low_delay=1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_H263P: + s->out_format = FMT_H263; +- s->h263_plus = 1; ++ s->h263_plus = 1; + /* Fx */ +- s->umvplus = (avctx->flags & CODEC_FLAG_H263P_UMV) ? 1:0; +- s->h263_aic= (avctx->flags & CODEC_FLAG_AC_PRED) ? 1:0; +- s->modified_quant= s->h263_aic; +- s->alt_inter_vlc= (avctx->flags & CODEC_FLAG_H263P_AIV) ? 1:0; +- s->obmc= (avctx->flags & CODEC_FLAG_OBMC) ? 1:0; +- s->loop_filter= (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1:0; +- s->unrestricted_mv= s->obmc || s->loop_filter || s->umvplus; +- s->h263_slice_structured= (s->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ? 1:0; ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++ if (avctx->flags & CODEC_FLAG_H263P_UMV) ++ s->umvplus = 1; ++ if (avctx->flags & CODEC_FLAG_H263P_AIV) ++ s->alt_inter_vlc = 1; ++ if (avctx->flags & CODEC_FLAG_H263P_SLICE_STRUCT) ++ s->h263_slice_structured = 1; ++#endif ++ s->h263_aic = (avctx->flags & CODEC_FLAG_AC_PRED) ? 1 : 0; ++ s->modified_quant = s->h263_aic; ++ s->loop_filter = (avctx->flags & CODEC_FLAG_LOOP_FILTER) ? 1 : 0; ++ s->unrestricted_mv = s->obmc || s->loop_filter || s->umvplus; + + /* /Fx */ + /* These are just to be sure */ +- avctx->delay=0; +- s->low_delay=1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_FLV1: +- s->out_format = FMT_H263; +- s->h263_flv = 2; /* format = 1; 11-bit codes */ ++ s->out_format = FMT_H263; ++ s->h263_flv = 2; /* format = 1; 11-bit codes */ + s->unrestricted_mv = 1; +- s->rtp_mode=0; /* don't allow GOB */ +- avctx->delay=0; +- s->low_delay=1; ++ s->rtp_mode = 0; /* don't allow GOB */ ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_RV10: + s->out_format = FMT_H263; +- avctx->delay=0; +- s->low_delay=1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_RV20: +- s->out_format = FMT_H263; +- avctx->delay=0; +- s->low_delay=1; +- s->modified_quant=1; +- s->h263_aic=1; +- s->h263_plus=1; +- s->loop_filter=1; +- s->unrestricted_mv= 0; ++ s->out_format = FMT_H263; ++ avctx->delay = 0; ++ s->low_delay = 1; ++ s->modified_quant = 1; ++ s->h263_aic = 1; ++ s->h263_plus = 1; ++ s->loop_filter = 1; ++ s->unrestricted_mv = 0; + break; + case CODEC_ID_MPEG4: +- s->out_format = FMT_H263; +- s->h263_pred = 1; +- s->unrestricted_mv = 1; +- s->low_delay= s->max_b_frames ? 0 : 1; +- avctx->delay= s->low_delay ? 0 : (s->max_b_frames + 1); +- break; +- case CODEC_ID_MSMPEG4V1: +- s->out_format = FMT_H263; +- s->h263_msmpeg4 = 1; +- s->h263_pred = 1; ++ s->out_format = FMT_H263; ++ s->h263_pred = 1; + s->unrestricted_mv = 1; +- s->msmpeg4_version= 1; +- avctx->delay=0; +- s->low_delay=1; ++ s->low_delay = s->max_b_frames ? 0 : 1; ++ avctx->delay = s->low_delay ? 0 : (s->max_b_frames + 1); + break; + case CODEC_ID_MSMPEG4V2: +- s->out_format = FMT_H263; +- s->h263_msmpeg4 = 1; +- s->h263_pred = 1; ++ s->out_format = FMT_H263; ++ s->h263_pred = 1; + s->unrestricted_mv = 1; +- s->msmpeg4_version= 2; +- avctx->delay=0; +- s->low_delay=1; ++ s->msmpeg4_version = 2; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_MSMPEG4V3: +- s->out_format = FMT_H263; +- s->h263_msmpeg4 = 1; +- s->h263_pred = 1; +- s->unrestricted_mv = 1; +- s->msmpeg4_version= 3; +- s->flipflop_rounding=1; +- avctx->delay=0; +- s->low_delay=1; ++ s->out_format = FMT_H263; ++ s->h263_pred = 1; ++ s->unrestricted_mv = 1; ++ s->msmpeg4_version = 3; ++ s->flipflop_rounding = 1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_WMV1: +- s->out_format = FMT_H263; +- s->h263_msmpeg4 = 1; +- s->h263_pred = 1; +- s->unrestricted_mv = 1; +- s->msmpeg4_version= 4; +- s->flipflop_rounding=1; +- avctx->delay=0; +- s->low_delay=1; ++ s->out_format = FMT_H263; ++ s->h263_pred = 1; ++ s->unrestricted_mv = 1; ++ s->msmpeg4_version = 4; ++ s->flipflop_rounding = 1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + case CODEC_ID_WMV2: +- s->out_format = FMT_H263; +- s->h263_msmpeg4 = 1; +- s->h263_pred = 1; +- s->unrestricted_mv = 1; +- s->msmpeg4_version= 5; +- s->flipflop_rounding=1; +- avctx->delay=0; +- s->low_delay=1; ++ s->out_format = FMT_H263; ++ s->h263_pred = 1; ++ s->unrestricted_mv = 1; ++ s->msmpeg4_version = 5; ++ s->flipflop_rounding = 1; ++ avctx->delay = 0; ++ s->low_delay = 1; + break; + default: + return -1; + } + +- avctx->has_b_frames= !s->low_delay; ++ avctx->has_b_frames = !s->low_delay; + + s->encoding = 1; + +- s->progressive_frame= +- s->progressive_sequence= !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT|CODEC_FLAG_INTERLACED_ME|CODEC_FLAG_ALT_SCAN)); ++ s->progressive_frame = ++ s->progressive_sequence = !(avctx->flags & (CODEC_FLAG_INTERLACED_DCT | ++ CODEC_FLAG_INTERLACED_ME) || ++ s->alternate_scan); + + /* init */ + if (MPV_common_init(s) < 0) + return -1; + +- if(!s->dct_quantize) ++ if (!s->dct_quantize) + s->dct_quantize = dct_quantize_c; +- if(!s->denoise_dct) +- s->denoise_dct = denoise_dct_c; ++ if (!s->denoise_dct) ++ s->denoise_dct = denoise_dct_c; + s->fast_dct_quantize = s->dct_quantize; +- if(avctx->trellis) +- s->dct_quantize = dct_quantize_trellis_c; ++ if (avctx->trellis) ++ s->dct_quantize = dct_quantize_trellis_c; + +- if((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant) +- s->chroma_qscale_table= ff_h263_chroma_qscale_table; ++ if ((CONFIG_H263P_ENCODER || CONFIG_RV20_ENCODER) && s->modified_quant) ++ s->chroma_qscale_table = ff_h263_chroma_qscale_table; + +- s->quant_precision=5; ++ s->quant_precision = 5; + + ff_set_cmp(&s->dsp, s->dsp.ildct_cmp, s->avctx->ildct_cmp); + ff_set_cmp(&s->dsp, s->dsp.frame_skip_cmp, s->avctx->frame_skip_cmp); +@@ -727,22 +856,23 @@ + ff_mpeg1_encode_init(s); + + /* init q matrix */ +- for(i=0;i<64;i++) { +- int j= s->dsp.idct_permutation[i]; +- if(CONFIG_MPEG4_ENCODER && s->codec_id==CODEC_ID_MPEG4 && s->mpeg_quant){ ++ for (i = 0; i < 64; i++) { ++ int j = s->dsp.idct_permutation[i]; ++ if (CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4 && ++ s->mpeg_quant) { + s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i]; + s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i]; +- }else if(s->out_format == FMT_H263 || s->out_format == FMT_H261){ ++ } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) { + s->intra_matrix[j] = + s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; +- }else +- { /* mpeg1/2 */ ++ } else { ++ /* mpeg1/2 */ + s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i]; + s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i]; + } +- if(s->avctx->intra_matrix) ++ if (s->avctx->intra_matrix) + s->intra_matrix[j] = s->avctx->intra_matrix[i]; +- if(s->avctx->inter_matrix) ++ if (s->avctx->inter_matrix) + s->inter_matrix[j] = s->avctx->inter_matrix[i]; + } + +@@ -750,12 +880,14 @@ + /* for mjpeg, we do include qscale in the matrix */ + if (s->out_format != FMT_MJPEG) { + ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, +- s->intra_matrix, s->intra_quant_bias, avctx->qmin, 31, 1); ++ s->intra_matrix, s->intra_quant_bias, avctx->qmin, ++ 31, 1); + ff_convert_matrix(&s->dsp, s->q_inter_matrix, s->q_inter_matrix16, +- s->inter_matrix, s->inter_quant_bias, avctx->qmin, 31, 0); ++ s->inter_matrix, s->inter_quant_bias, avctx->qmin, ++ 31, 0); + } + +- if(ff_rate_control_init(s) < 0) ++ if (ff_rate_control_init(s) < 0) + return -1; + + return 0; +@@ -768,7 +900,8 @@ + ff_rate_control_uninit(s); + + MPV_common_end(s); +- if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && s->out_format == FMT_MJPEG) ++ if ((CONFIG_MJPEG_ENCODER || CONFIG_LJPEG_ENCODER) && ++ s->out_format == FMT_MJPEG) + ff_mjpeg_encode_close(s); + + av_freep(&avctx->extradata); +@@ -776,129 +909,152 @@ + return 0; + } + +-static int get_sae(uint8_t *src, int ref, int stride){ ++static int get_sae(uint8_t *src, int ref, int stride) ++{ + int x,y; +- int acc=0; ++ int acc = 0; + +- for(y=0; y<16; y++){ +- for(x=0; x<16; x++){ +- acc+= FFABS(src[x+y*stride] - ref); ++ for (y = 0; y < 16; y++) { ++ for (x = 0; x < 16; x++) { ++ acc += FFABS(src[x + y * stride] - ref); + } + } + + return acc; + } + +-static int get_intra_count(MpegEncContext *s, uint8_t *src, uint8_t *ref, int stride){ ++static int get_intra_count(MpegEncContext *s, uint8_t *src, ++ uint8_t *ref, int stride) ++{ + int x, y, w, h; +- int acc=0; ++ int acc = 0; + +- w= s->width &~15; +- h= s->height&~15; ++ w = s->width & ~15; ++ h = s->height & ~15; + +- for(y=0; ydsp.sad[0](NULL, src + offset, ref + offset, stride, 16); +- int mean= (s->dsp.pix_sum(src + offset, stride) + 128)>>8; +- int sae = get_sae(src + offset, mean, stride); ++ for (y = 0; y < h; y += 16) { ++ for (x = 0; x < w; x += 16) { ++ int offset = x + y * stride; ++ int sad = s->dsp.sad[0](NULL, src + offset, ref + offset, stride, ++ 16); ++ int mean = (s->dsp.pix_sum(src + offset, stride) + 128) >> 8; ++ int sae = get_sae(src + offset, mean, stride); + +- acc+= sae + 500 < sad; ++ acc += sae + 500 < sad; + } + } + return acc; + } + + +-static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg){ +- AVFrame *pic=NULL; ++static int load_input_picture(MpegEncContext *s, AVFrame *pic_arg) ++{ ++ AVFrame *pic = NULL; + int64_t pts; + int i; +- const int encoding_delay= s->max_b_frames; +- int direct=1; +- +- if(pic_arg){ +- pts= pic_arg->pts; +- pic_arg->display_picture_number= s->input_picture_number++; +- +- if(pts != AV_NOPTS_VALUE){ +- if(s->user_specified_pts != AV_NOPTS_VALUE){ +- int64_t time= pts; +- int64_t last= s->user_specified_pts; ++ const int encoding_delay = s->max_b_frames; ++ int direct = 1; + +- if(time <= last){ +- av_log(s->avctx, AV_LOG_ERROR, "Error, Invalid timestamp=%"PRId64", last=%"PRId64"\n", pts, s->user_specified_pts); ++ if (pic_arg) { ++ pts = pic_arg->pts; ++ pic_arg->display_picture_number = s->input_picture_number++; ++ ++ if (pts != AV_NOPTS_VALUE) { ++ if (s->user_specified_pts != AV_NOPTS_VALUE) { ++ int64_t time = pts; ++ int64_t last = s->user_specified_pts; ++ ++ if (time <= last) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Error, Invalid timestamp=%"PRId64", " ++ "last=%"PRId64"\n", pts, s->user_specified_pts); + return -1; + } + } +- s->user_specified_pts= pts; +- }else{ +- if(s->user_specified_pts != AV_NOPTS_VALUE){ +- s->user_specified_pts= +- pts= s->user_specified_pts + 1; +- av_log(s->avctx, AV_LOG_INFO, "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", pts); +- }else{ +- pts= pic_arg->display_picture_number; ++ s->user_specified_pts = pts; ++ } else { ++ if (s->user_specified_pts != AV_NOPTS_VALUE) { ++ s->user_specified_pts = ++ pts = s->user_specified_pts + 1; ++ av_log(s->avctx, AV_LOG_INFO, ++ "Warning: AVFrame.pts=? trying to guess (%"PRId64")\n", ++ pts); ++ } else { ++ pts = pic_arg->display_picture_number; + } + } + } + +- if(pic_arg){ +- if(encoding_delay && !(s->flags&CODEC_FLAG_INPUT_PRESERVED)) direct=0; +- if(pic_arg->linesize[0] != s->linesize) direct=0; +- if(pic_arg->linesize[1] != s->uvlinesize) direct=0; +- if(pic_arg->linesize[2] != s->uvlinesize) direct=0; ++ if (pic_arg) { ++ if (encoding_delay && !(s->flags & CODEC_FLAG_INPUT_PRESERVED)) ++ direct = 0; ++ if (pic_arg->linesize[0] != s->linesize) ++ direct = 0; ++ if (pic_arg->linesize[1] != s->uvlinesize) ++ direct = 0; ++ if (pic_arg->linesize[2] != s->uvlinesize) ++ direct = 0; + +-// av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], pic_arg->linesize[1], s->linesize, s->uvlinesize); ++ //av_log(AV_LOG_DEBUG, "%d %d %d %d\n",pic_arg->linesize[0], ++ // pic_arg->linesize[1], s->linesize, s->uvlinesize); + +- if(direct){ +- i= ff_find_unused_picture(s, 1); ++ if (direct) { ++ i = ff_find_unused_picture(s, 1); ++ if (i < 0) ++ return i; + +- pic= (AVFrame*)&s->picture[i]; +- pic->reference= 3; ++ pic = (AVFrame *) &s->picture[i]; ++ pic->reference = 3; + +- for(i=0; i<4; i++){ +- pic->data[i]= pic_arg->data[i]; +- pic->linesize[i]= pic_arg->linesize[i]; ++ for (i = 0; i < 4; i++) { ++ pic->data[i] = pic_arg->data[i]; ++ pic->linesize[i] = pic_arg->linesize[i]; + } +- if(ff_alloc_picture(s, (Picture*)pic, 1) < 0){ ++ if (ff_alloc_picture(s, (Picture *) pic, 1) < 0) { + return -1; + } +- }else{ +- i= ff_find_unused_picture(s, 0); ++ } else { ++ i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; + +- pic= (AVFrame*)&s->picture[i]; +- pic->reference= 3; ++ pic = (AVFrame *) &s->picture[i]; ++ pic->reference = 3; + +- if(ff_alloc_picture(s, (Picture*)pic, 0) < 0){ ++ if (ff_alloc_picture(s, (Picture *) pic, 0) < 0) { + return -1; + } + +- if( pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] +- && pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] +- && pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]){ +- // empty +- }else{ ++ if (pic->data[0] + INPLACE_OFFSET == pic_arg->data[0] && ++ pic->data[1] + INPLACE_OFFSET == pic_arg->data[1] && ++ pic->data[2] + INPLACE_OFFSET == pic_arg->data[2]) { ++ // empty ++ } else { + int h_chroma_shift, v_chroma_shift; +- avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift); ++ avcodec_get_chroma_sub_sample(s->avctx->pix_fmt, &h_chroma_shift, ++ &v_chroma_shift); + +- for(i=0; i<3; i++){ +- int src_stride= pic_arg->linesize[i]; +- int dst_stride= i ? s->uvlinesize : s->linesize; +- int h_shift= i ? h_chroma_shift : 0; +- int v_shift= i ? v_chroma_shift : 0; +- int w= s->width >>h_shift; +- int h= s->height>>v_shift; +- uint8_t *src= pic_arg->data[i]; +- uint8_t *dst= pic->data[i]; +- +- if(!s->avctx->rc_buffer_size) +- dst +=INPLACE_OFFSET; +- +- if(src_stride==dst_stride) +- memcpy(dst, src, src_stride*h); +- else{ +- while(h--){ ++ for (i = 0; i < 3; i++) { ++ int src_stride = pic_arg->linesize[i]; ++ int dst_stride = i ? s->uvlinesize : s->linesize; ++ int h_shift = i ? h_chroma_shift : 0; ++ int v_shift = i ? v_chroma_shift : 0; ++ int w = s->width >> h_shift; ++ int h = s->height >> v_shift; ++ uint8_t *src = pic_arg->data[i]; ++ uint8_t *dst = pic->data[i]; ++ ++ if(s->codec_id == CODEC_ID_AMV && !(s->avctx->flags & CODEC_FLAG_EMU_EDGE)){ ++ h= ((s->height+15)/16*16)>>v_shift; ++ } ++ ++ if (!s->avctx->rc_buffer_size) ++ dst += INPLACE_OFFSET; ++ ++ if (src_stride == dst_stride) ++ memcpy(dst, src, src_stride * h); ++ else { ++ while (h--) { + memcpy(dst, src, w); + dst += dst_stride; + src += src_stride; +@@ -908,146 +1064,166 @@ + } + } + copy_picture_attributes(s, pic, pic_arg); +- pic->pts= pts; //we set this here to avoid modifiying pic_arg ++ pic->pts = pts; // we set this here to avoid modifiying pic_arg + } + + /* shift buffer entries */ +- for(i=1; iencoding_delay+1*/; i++) +- s->input_picture[i-1]= s->input_picture[i]; ++ for (i = 1; i < MAX_PICTURE_COUNT /*s->encoding_delay + 1*/; i++) ++ s->input_picture[i - 1] = s->input_picture[i]; + +- s->input_picture[encoding_delay]= (Picture*)pic; ++ s->input_picture[encoding_delay] = (Picture*) pic; + + return 0; + } + +-static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){ ++static int skip_check(MpegEncContext *s, Picture *p, Picture *ref) ++{ + int x, y, plane; +- int score=0; +- int64_t score64=0; ++ int score = 0; ++ int64_t score64 = 0; + +- for(plane=0; plane<3; plane++){ +- const int stride= p->linesize[plane]; +- const int bw= plane ? 1 : 2; +- for(y=0; ymb_height*bw; y++){ +- for(x=0; xmb_width*bw; x++){ +- int off= p->type == FF_BUFFER_TYPE_SHARED ? 0: 16; +- int v= s->dsp.frame_skip_cmp[1](s, p->data[plane] + 8*(x + y*stride)+off, ref->data[plane] + 8*(x + y*stride), stride, 8); ++ for (plane = 0; plane < 3; plane++) { ++ const int stride = p->f.linesize[plane]; ++ const int bw = plane ? 1 : 2; ++ for (y = 0; y < s->mb_height * bw; y++) { ++ for (x = 0; x < s->mb_width * bw; x++) { ++ int off = p->f.type == FF_BUFFER_TYPE_SHARED ? 0 : 16; ++ uint8_t *dptr = p->f.data[plane] + 8 * (x + y * stride) + off; ++ uint8_t *rptr = ref->f.data[plane] + 8 * (x + y * stride); ++ int v = s->dsp.frame_skip_cmp[1](s, dptr, rptr, stride, 8); + +- switch(s->avctx->frame_skip_exp){ +- case 0: score= FFMAX(score, v); break; +- case 1: score+= FFABS(v);break; +- case 2: score+= v*v;break; +- case 3: score64+= FFABS(v*v*(int64_t)v);break; +- case 4: score64+= v*v*(int64_t)(v*v);break; ++ switch (s->avctx->frame_skip_exp) { ++ case 0: score = FFMAX(score, v); break; ++ case 1: score += FFABS(v); break; ++ case 2: score += v * v; break; ++ case 3: score64 += FFABS(v * v * (int64_t)v); break; ++ case 4: score64 += v * v * (int64_t)(v * v); break; + } + } + } + } + +- if(score) score64= score; ++ if (score) ++ score64 = score; + +- if(score64 < s->avctx->frame_skip_threshold) ++ if (score64 < s->avctx->frame_skip_threshold) + return 1; +- if(score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda)>>8)) ++ if (score64 < ((s->avctx->frame_skip_factor * (int64_t)s->lambda) >> 8)) + return 1; + return 0; + } + +-static int estimate_best_b_count(MpegEncContext *s){ +- AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id); +- AVCodecContext *c= avcodec_alloc_context(); +- AVFrame input[FF_MAX_B_FRAMES+2]; +- const int scale= s->avctx->brd_scale; ++static int estimate_best_b_count(MpegEncContext *s) ++{ ++ AVCodec *codec = avcodec_find_encoder(s->avctx->codec_id); ++ AVCodecContext *c = avcodec_alloc_context3(NULL); ++ AVFrame input[FF_MAX_B_FRAMES + 2]; ++ const int scale = s->avctx->brd_scale; + int i, j, out_size, p_lambda, b_lambda, lambda2; +- int outbuf_size= s->width * s->height; //FIXME +- uint8_t *outbuf= av_malloc(outbuf_size); +- int64_t best_rd= INT64_MAX; +- int best_b_count= -1; +- +- assert(scale>=0 && scale <=3); +- +-// emms_c(); +- p_lambda= s->last_lambda_for[FF_P_TYPE]; //s->next_picture_ptr->quality; +- b_lambda= s->last_lambda_for[FF_B_TYPE]; //p_lambda *FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; +- if(!b_lambda) b_lambda= p_lambda; //FIXME we should do this somewhere else +- lambda2= (b_lambda*b_lambda + (1<> FF_LAMBDA_SHIFT; +- +- c->width = s->width >> scale; +- c->height= s->height>> scale; +- c->flags= CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; +- c->flags|= s->avctx->flags & CODEC_FLAG_QPEL; +- c->mb_decision= s->avctx->mb_decision; +- c->me_cmp= s->avctx->me_cmp; +- c->mb_cmp= s->avctx->mb_cmp; +- c->me_sub_cmp= s->avctx->me_sub_cmp; +- c->pix_fmt = PIX_FMT_YUV420P; +- c->time_base= s->avctx->time_base; +- c->max_b_frames= s->max_b_frames; +- +- if (avcodec_open(c, codec) < 0) +- return -1; +- +- for(i=0; imax_b_frames+2; i++){ +- int ysize= c->width*c->height; +- int csize= (c->width/2)*(c->height/2); +- Picture pre_input, *pre_input_ptr= i ? s->input_picture[i-1] : s->next_picture_ptr; ++ int outbuf_size = s->width * s->height; // FIXME ++ uint8_t *outbuf = av_malloc(outbuf_size); ++ int64_t best_rd = INT64_MAX; ++ int best_b_count = -1; ++ ++ assert(scale >= 0 && scale <= 3); ++ ++ //emms_c(); ++ //s->next_picture_ptr->quality; ++ p_lambda = s->last_lambda_for[AV_PICTURE_TYPE_P]; ++ //p_lambda * FFABS(s->avctx->b_quant_factor) + s->avctx->b_quant_offset; ++ b_lambda = s->last_lambda_for[AV_PICTURE_TYPE_B]; ++ if (!b_lambda) // FIXME we should do this somewhere else ++ b_lambda = p_lambda; ++ lambda2 = (b_lambda * b_lambda + (1 << FF_LAMBDA_SHIFT) / 2) >> ++ FF_LAMBDA_SHIFT; ++ ++ c->width = s->width >> scale; ++ c->height = s->height >> scale; ++ c->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_PSNR | ++ CODEC_FLAG_INPUT_PRESERVED /*| CODEC_FLAG_EMU_EDGE*/; ++ c->flags |= s->avctx->flags & CODEC_FLAG_QPEL; ++ c->mb_decision = s->avctx->mb_decision; ++ c->me_cmp = s->avctx->me_cmp; ++ c->mb_cmp = s->avctx->mb_cmp; ++ c->me_sub_cmp = s->avctx->me_sub_cmp; ++ c->pix_fmt = PIX_FMT_YUV420P; ++ c->time_base = s->avctx->time_base; ++ c->max_b_frames = s->max_b_frames; + +- avcodec_get_frame_defaults(&input[i]); +- input[i].data[0]= av_malloc(ysize + 2*csize); +- input[i].data[1]= input[i].data[0] + ysize; +- input[i].data[2]= input[i].data[1] + csize; +- input[i].linesize[0]= c->width; +- input[i].linesize[1]= +- input[i].linesize[2]= c->width/2; +- +- if(pre_input_ptr && (!i || s->input_picture[i-1])) { +- pre_input= *pre_input_ptr; ++ if (avcodec_open2(c, codec, NULL) < 0) ++ return -1; + +- if(pre_input.type != FF_BUFFER_TYPE_SHARED && i) { +- pre_input.data[0]+=INPLACE_OFFSET; +- pre_input.data[1]+=INPLACE_OFFSET; +- pre_input.data[2]+=INPLACE_OFFSET; +- } ++ for (i = 0; i < s->max_b_frames + 2; i++) { ++ int ysize = c->width * c->height; ++ int csize = (c->width / 2) * (c->height / 2); ++ Picture pre_input, *pre_input_ptr = i ? s->input_picture[i - 1] : ++ s->next_picture_ptr; + +- s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], pre_input.data[0], pre_input.linesize[0], c->width, c->height); +- s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], pre_input.data[1], pre_input.linesize[1], c->width>>1, c->height>>1); +- s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], pre_input.data[2], pre_input.linesize[2], c->width>>1, c->height>>1); ++ avcodec_get_frame_defaults(&input[i]); ++ input[i].data[0] = av_malloc(ysize + 2 * csize); ++ input[i].data[1] = input[i].data[0] + ysize; ++ input[i].data[2] = input[i].data[1] + csize; ++ input[i].linesize[0] = c->width; ++ input[i].linesize[1] = ++ input[i].linesize[2] = c->width / 2; ++ ++ if (pre_input_ptr && (!i || s->input_picture[i - 1])) { ++ pre_input = *pre_input_ptr; ++ ++ if (pre_input.f.type != FF_BUFFER_TYPE_SHARED && i) { ++ pre_input.f.data[0] += INPLACE_OFFSET; ++ pre_input.f.data[1] += INPLACE_OFFSET; ++ pre_input.f.data[2] += INPLACE_OFFSET; ++ } ++ ++ s->dsp.shrink[scale](input[i].data[0], input[i].linesize[0], ++ pre_input.f.data[0], pre_input.f.linesize[0], ++ c->width, c->height); ++ s->dsp.shrink[scale](input[i].data[1], input[i].linesize[1], ++ pre_input.f.data[1], pre_input.f.linesize[1], ++ c->width >> 1, c->height >> 1); ++ s->dsp.shrink[scale](input[i].data[2], input[i].linesize[2], ++ pre_input.f.data[2], pre_input.f.linesize[2], ++ c->width >> 1, c->height >> 1); + } + } + +- for(j=0; jmax_b_frames+1; j++){ +- int64_t rd=0; ++ for (j = 0; j < s->max_b_frames + 1; j++) { ++ int64_t rd = 0; + +- if(!s->input_picture[j]) ++ if (!s->input_picture[j]) + break; + +- c->error[0]= c->error[1]= c->error[2]= 0; ++ c->error[0] = c->error[1] = c->error[2] = 0; + +- input[0].pict_type= FF_I_TYPE; +- input[0].quality= 1 * FF_QP2LAMBDA; +- out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[0]); +-// rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT; +- +- for(i=0; imax_b_frames+1; i++){ +- int is_p= i % (j+1) == j || i==s->max_b_frames; +- +- input[i+1].pict_type= is_p ? FF_P_TYPE : FF_B_TYPE; +- input[i+1].quality= is_p ? p_lambda : b_lambda; +- out_size = avcodec_encode_video(c, outbuf, outbuf_size, &input[i+1]); ++ input[0].pict_type = AV_PICTURE_TYPE_I; ++ input[0].quality = 1 * FF_QP2LAMBDA; ++ out_size = avcodec_encode_video(c, outbuf, ++ outbuf_size, &input[0]); ++ //rd += (out_size * lambda2) >> FF_LAMBDA_SHIFT; ++ ++ for (i = 0; i < s->max_b_frames + 1; i++) { ++ int is_p = i % (j + 1) == j || i == s->max_b_frames; ++ ++ input[i + 1].pict_type = is_p ? ++ AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_B; ++ input[i + 1].quality = is_p ? p_lambda : b_lambda; ++ out_size = avcodec_encode_video(c, outbuf, outbuf_size, ++ &input[i + 1]); + rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + } + + /* get the delayed frames */ +- while(out_size){ ++ while (out_size) { + out_size = avcodec_encode_video(c, outbuf, outbuf_size, NULL); + rd += (out_size * lambda2) >> (FF_LAMBDA_SHIFT - 3); + } + + rd += c->error[0] + c->error[1] + c->error[2]; + +- if(rd < best_rd){ +- best_rd= rd; +- best_b_count= j; ++ if (rd < best_rd) { ++ best_rd = rd; ++ best_b_count = j; + } + } + +@@ -1055,43 +1231,50 @@ + avcodec_close(c); + av_freep(&c); + +- for(i=0; imax_b_frames+2; i++){ ++ for (i = 0; i < s->max_b_frames + 2; i++) { + av_freep(&input[i].data[0]); + } + + return best_b_count; + } + +-static int select_input_picture(MpegEncContext *s){ ++static int select_input_picture(MpegEncContext *s) ++{ + int i; + +- for(i=1; ireordered_input_picture[i-1]= s->reordered_input_picture[i]; +- s->reordered_input_picture[MAX_PICTURE_COUNT-1]= NULL; ++ for (i = 1; i < MAX_PICTURE_COUNT; i++) ++ s->reordered_input_picture[i - 1] = s->reordered_input_picture[i]; ++ s->reordered_input_picture[MAX_PICTURE_COUNT - 1] = NULL; + + /* set next picture type & ordering */ +- if(s->reordered_input_picture[0]==NULL && s->input_picture[0]){ +- if(/*s->picture_in_gop_number >= s->gop_size ||*/ s->next_picture_ptr==NULL || s->intra_only){ +- s->reordered_input_picture[0]= s->input_picture[0]; +- s->reordered_input_picture[0]->pict_type= FF_I_TYPE; +- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; +- }else{ ++ if (s->reordered_input_picture[0] == NULL && s->input_picture[0]) { ++ if (/*s->picture_in_gop_number >= s->gop_size ||*/ ++ s->next_picture_ptr == NULL || s->intra_only) { ++ s->reordered_input_picture[0] = s->input_picture[0]; ++ s->reordered_input_picture[0]->f.pict_type = AV_PICTURE_TYPE_I; ++ s->reordered_input_picture[0]->f.coded_picture_number = ++ s->coded_picture_number++; ++ } else { + int b_frames; + +- if(s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor){ +- if(s->picture_in_gop_number < s->gop_size && skip_check(s, s->input_picture[0], s->next_picture_ptr)){ +- //FIXME check that te gop check above is +-1 correct +-//av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", s->input_picture[0]->data[0], s->input_picture[0]->pts); +- +- if(s->input_picture[0]->type == FF_BUFFER_TYPE_SHARED){ +- for(i=0; i<4; i++) +- s->input_picture[0]->data[i]= NULL; +- s->input_picture[0]->type= 0; +- }else{ +- assert( s->input_picture[0]->type==FF_BUFFER_TYPE_USER +- || s->input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); ++ if (s->avctx->frame_skip_threshold || s->avctx->frame_skip_factor) { ++ if (s->picture_in_gop_number < s->gop_size && ++ skip_check(s, s->input_picture[0], s->next_picture_ptr)) { ++ // FIXME check that te gop check above is +-1 correct ++ //av_log(NULL, AV_LOG_DEBUG, "skip %p %"PRId64"\n", ++ // s->input_picture[0]->f.data[0], ++ // s->input_picture[0]->pts); ++ ++ if (s->input_picture[0]->f.type == FF_BUFFER_TYPE_SHARED) { ++ for (i = 0; i < 4; i++) ++ s->input_picture[0]->f.data[i] = NULL; ++ s->input_picture[0]->f.type = 0; ++ } else { ++ assert(s->input_picture[0]->f.type == FF_BUFFER_TYPE_USER || ++ s->input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL); + +- s->avctx->release_buffer(s->avctx, (AVFrame*)s->input_picture[0]); ++ s->avctx->release_buffer(s->avctx, ++ (AVFrame *) s->input_picture[0]); + } + + emms_c(); +@@ -1101,134 +1284,157 @@ + } + } + +- if(s->flags&CODEC_FLAG_PASS2){ +- for(i=0; imax_b_frames+1; i++){ +- int pict_num= s->input_picture[0]->display_picture_number + i; ++ if (s->flags & CODEC_FLAG_PASS2) { ++ for (i = 0; i < s->max_b_frames + 1; i++) { ++ int pict_num = s->input_picture[0]->f.display_picture_number + i; + +- if(pict_num >= s->rc_context.num_entries) ++ if (pict_num >= s->rc_context.num_entries) + break; +- if(!s->input_picture[i]){ +- s->rc_context.entry[pict_num-1].new_pict_type = FF_P_TYPE; ++ if (!s->input_picture[i]) { ++ s->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; + break; + } + +- s->input_picture[i]->pict_type= ++ s->input_picture[i]->f.pict_type = + s->rc_context.entry[pict_num].new_pict_type; + } + } + +- if(s->avctx->b_frame_strategy==0){ +- b_frames= s->max_b_frames; +- while(b_frames && !s->input_picture[b_frames]) b_frames--; +- }else if(s->avctx->b_frame_strategy==1){ +- for(i=1; imax_b_frames+1; i++){ +- if(s->input_picture[i] && s->input_picture[i]->b_frame_score==0){ +- s->input_picture[i]->b_frame_score= +- get_intra_count(s, s->input_picture[i ]->data[0], +- s->input_picture[i-1]->data[0], s->linesize) + 1; ++ if (s->avctx->b_frame_strategy == 0) { ++ b_frames = s->max_b_frames; ++ while (b_frames && !s->input_picture[b_frames]) ++ b_frames--; ++ } else if (s->avctx->b_frame_strategy == 1) { ++ for (i = 1; i < s->max_b_frames + 1; i++) { ++ if (s->input_picture[i] && ++ s->input_picture[i]->b_frame_score == 0) { ++ s->input_picture[i]->b_frame_score = ++ get_intra_count(s, ++ s->input_picture[i ]->f.data[0], ++ s->input_picture[i - 1]->f.data[0], ++ s->linesize) + 1; + } + } +- for(i=0; imax_b_frames+1; i++){ +- if(s->input_picture[i]==NULL || s->input_picture[i]->b_frame_score - 1 > s->mb_num/s->avctx->b_sensitivity) break; ++ for (i = 0; i < s->max_b_frames + 1; i++) { ++ if (s->input_picture[i] == NULL || ++ s->input_picture[i]->b_frame_score - 1 > ++ s->mb_num / s->avctx->b_sensitivity) ++ break; + } + +- b_frames= FFMAX(0, i-1); ++ b_frames = FFMAX(0, i - 1); + + /* reset scores */ +- for(i=0; iinput_picture[i]->b_frame_score=0; ++ for (i = 0; i < b_frames + 1; i++) { ++ s->input_picture[i]->b_frame_score = 0; + } +- }else if(s->avctx->b_frame_strategy==2){ +- b_frames= estimate_best_b_count(s); +- }else{ ++ } else if (s->avctx->b_frame_strategy == 2) { ++ b_frames = estimate_best_b_count(s); ++ } else { + av_log(s->avctx, AV_LOG_ERROR, "illegal b frame strategy\n"); +- b_frames=0; ++ b_frames = 0; + } + + emms_c(); +-//static int b_count=0; +-//b_count+= b_frames; +-//av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); +- +- for(i= b_frames - 1; i>=0; i--){ +- int type= s->input_picture[i]->pict_type; +- if(type && type != FF_B_TYPE) +- b_frames= i; +- } +- if(s->input_picture[b_frames]->pict_type == FF_B_TYPE && b_frames == s->max_b_frames){ +- av_log(s->avctx, AV_LOG_ERROR, "warning, too many b frames in a row\n"); +- } +- +- if(s->picture_in_gop_number + b_frames >= s->gop_size){ +- if((s->flags2 & CODEC_FLAG2_STRICT_GOP) && s->gop_size > s->picture_in_gop_number){ +- b_frames= s->gop_size - s->picture_in_gop_number - 1; +- }else{ +- if(s->flags & CODEC_FLAG_CLOSED_GOP) +- b_frames=0; +- s->input_picture[b_frames]->pict_type= FF_I_TYPE; +- } +- } +- +- if( (s->flags & CODEC_FLAG_CLOSED_GOP) +- && b_frames +- && s->input_picture[b_frames]->pict_type== FF_I_TYPE) ++ //static int b_count = 0; ++ //b_count += b_frames; ++ //av_log(s->avctx, AV_LOG_DEBUG, "b_frames: %d\n", b_count); ++ ++ for (i = b_frames - 1; i >= 0; i--) { ++ int type = s->input_picture[i]->f.pict_type; ++ if (type && type != AV_PICTURE_TYPE_B) ++ b_frames = i; ++ } ++ if (s->input_picture[b_frames]->f.pict_type == AV_PICTURE_TYPE_B && ++ b_frames == s->max_b_frames) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "warning, too many b frames in a row\n"); ++ } ++ ++ if (s->picture_in_gop_number + b_frames >= s->gop_size) { ++ if ((s->flags2 & CODEC_FLAG2_STRICT_GOP) && ++ s->gop_size > s->picture_in_gop_number) { ++ b_frames = s->gop_size - s->picture_in_gop_number - 1; ++ } else { ++ if (s->flags & CODEC_FLAG_CLOSED_GOP) ++ b_frames = 0; ++ s->input_picture[b_frames]->f.pict_type = AV_PICTURE_TYPE_I; ++ } ++ } ++ ++ if ((s->flags & CODEC_FLAG_CLOSED_GOP) && b_frames && ++ s->input_picture[b_frames]->f.pict_type == AV_PICTURE_TYPE_I) + b_frames--; + +- s->reordered_input_picture[0]= s->input_picture[b_frames]; +- if(s->reordered_input_picture[0]->pict_type != FF_I_TYPE) +- s->reordered_input_picture[0]->pict_type= FF_P_TYPE; +- s->reordered_input_picture[0]->coded_picture_number= s->coded_picture_number++; +- for(i=0; ireordered_input_picture[i+1]= s->input_picture[i]; +- s->reordered_input_picture[i+1]->pict_type= FF_B_TYPE; +- s->reordered_input_picture[i+1]->coded_picture_number= s->coded_picture_number++; ++ s->reordered_input_picture[0] = s->input_picture[b_frames]; ++ if (s->reordered_input_picture[0]->f.pict_type != AV_PICTURE_TYPE_I) ++ s->reordered_input_picture[0]->f.pict_type = AV_PICTURE_TYPE_P; ++ s->reordered_input_picture[0]->f.coded_picture_number = ++ s->coded_picture_number++; ++ for (i = 0; i < b_frames; i++) { ++ s->reordered_input_picture[i + 1] = s->input_picture[i]; ++ s->reordered_input_picture[i + 1]->f.pict_type = ++ AV_PICTURE_TYPE_B; ++ s->reordered_input_picture[i + 1]->f.coded_picture_number = ++ s->coded_picture_number++; + } + } + } + no_output_pic: +- if(s->reordered_input_picture[0]){ +- s->reordered_input_picture[0]->reference= s->reordered_input_picture[0]->pict_type!=FF_B_TYPE ? 3 : 0; ++ if (s->reordered_input_picture[0]) { ++ s->reordered_input_picture[0]->f.reference = ++ s->reordered_input_picture[0]->f.pict_type != ++ AV_PICTURE_TYPE_B ? 3 : 0; + + ff_copy_picture(&s->new_picture, s->reordered_input_picture[0]); + +- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_SHARED || s->avctx->rc_buffer_size){ +- // input is a shared pix, so we can't modifiy it -> alloc a new one & ensure that the shared one is reuseable ++ if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_SHARED || ++ s->avctx->rc_buffer_size) { ++ // input is a shared pix, so we can't modifiy it -> alloc a new ++ // one & ensure that the shared one is reuseable ++ ++ Picture *pic; ++ int i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ return i; ++ pic = &s->picture[i]; + +- int i= ff_find_unused_picture(s, 0); +- Picture *pic= &s->picture[i]; +- +- pic->reference = s->reordered_input_picture[0]->reference; +- if(ff_alloc_picture(s, pic, 0) < 0){ ++ pic->f.reference = s->reordered_input_picture[0]->f.reference; ++ if (ff_alloc_picture(s, pic, 0) < 0) { + return -1; + } + + /* mark us unused / free shared pic */ +- if(s->reordered_input_picture[0]->type == FF_BUFFER_TYPE_INTERNAL) +- s->avctx->release_buffer(s->avctx, (AVFrame*)s->reordered_input_picture[0]); +- for(i=0; i<4; i++) +- s->reordered_input_picture[0]->data[i]= NULL; +- s->reordered_input_picture[0]->type= 0; ++ if (s->reordered_input_picture[0]->f.type == FF_BUFFER_TYPE_INTERNAL) ++ s->avctx->release_buffer(s->avctx, ++ (AVFrame *) s->reordered_input_picture[0]); ++ for (i = 0; i < 4; i++) ++ s->reordered_input_picture[0]->f.data[i] = NULL; ++ s->reordered_input_picture[0]->f.type = 0; + +- copy_picture_attributes(s, (AVFrame*)pic, (AVFrame*)s->reordered_input_picture[0]); ++ copy_picture_attributes(s, (AVFrame *) pic, ++ (AVFrame *) s->reordered_input_picture[0]); + +- s->current_picture_ptr= pic; +- }else{ ++ s->current_picture_ptr = pic; ++ } else { + // input is not a shared pix -> reuse buffer for current_pix + +- assert( s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_USER +- || s->reordered_input_picture[0]->type==FF_BUFFER_TYPE_INTERNAL); +- +- s->current_picture_ptr= s->reordered_input_picture[0]; +- for(i=0; i<4; i++){ +- s->new_picture.data[i]+= INPLACE_OFFSET; ++ assert(s->reordered_input_picture[0]->f.type == ++ FF_BUFFER_TYPE_USER || ++ s->reordered_input_picture[0]->f.type == ++ FF_BUFFER_TYPE_INTERNAL); ++ ++ s->current_picture_ptr = s->reordered_input_picture[0]; ++ for (i = 0; i < 4; i++) { ++ s->new_picture.f.data[i] += INPLACE_OFFSET; + } + } + ff_copy_picture(&s->current_picture, s->current_picture_ptr); + +- s->picture_number= s->new_picture.display_picture_number; +-//printf("dpn:%d\n", s->picture_number); +- }else{ +- memset(&s->new_picture, 0, sizeof(Picture)); ++ s->picture_number = s->new_picture.f.display_picture_number; ++ //printf("dpn:%d\n", s->picture_number); ++ } else { ++ memset(&s->new_picture, 0, sizeof(Picture)); + } + return 0; + } +@@ -1237,33 +1443,35 @@ + unsigned char *buf, int buf_size, void *data) + { + MpegEncContext *s = avctx->priv_data; +- AVFrame *pic_arg = data; ++ AVFrame *pic_arg = data; + int i, stuffing_count; ++ int context_count = s->slice_context_count; + +- for(i=0; ithread_count; i++){ +- int start_y= s->thread_context[i]->start_mb_y; +- int end_y= s->thread_context[i]-> end_mb_y; +- int h= s->mb_height; +- uint8_t *start= buf + (size_t)(((int64_t) buf_size)*start_y/h); +- uint8_t *end = buf + (size_t)(((int64_t) buf_size)* end_y/h); ++ for (i = 0; i < context_count; i++) { ++ int start_y = s->thread_context[i]->start_mb_y; ++ int end_y = s->thread_context[i]-> end_mb_y; ++ int h = s->mb_height; ++ uint8_t *start = buf + (size_t)(((int64_t) buf_size) * start_y / h); ++ uint8_t *end = buf + (size_t)(((int64_t) buf_size) * end_y / h); + + init_put_bits(&s->thread_context[i]->pb, start, end - start); + } + + s->picture_in_gop_number++; + +- if(load_input_picture(s, pic_arg) < 0) ++ if (load_input_picture(s, pic_arg) < 0) + return -1; + +- if(select_input_picture(s) < 0){ ++ if (select_input_picture(s) < 0) { + return -1; + } + + /* output? */ +- if(s->new_picture.data[0]){ +- s->pict_type= s->new_picture.pict_type; +-//emms_c(); +-//printf("qs:%f %f %d\n", s->new_picture.quality, s->current_picture.quality, s->qscale); ++ if (s->new_picture.f.data[0]) { ++ s->pict_type = s->new_picture.f.pict_type; ++ //emms_c(); ++ //printf("qs:%f %f %d\n", s->new_picture.quality, ++ // s->current_picture.quality, s->qscale); + MPV_frame_start(s, avctx); + vbv_retry: + if (encode_picture(s, s->picture_number) < 0) +@@ -1275,7 +1483,8 @@ + avctx->i_tex_bits = s->i_tex_bits; + avctx->p_tex_bits = s->p_tex_bits; + avctx->i_count = s->i_count; +- avctx->p_count = s->mb_num - s->i_count - s->skip_count; //FIXME f/b_count in avctx ++ // FIXME f/b_count in avctx ++ avctx->p_count = s->mb_num - s->i_count - s->skip_count; + avctx->skip_count = s->skip_count; + + MPV_frame_end(s); +@@ -1283,29 +1492,37 @@ + if (CONFIG_MJPEG_ENCODER && s->out_format == FMT_MJPEG) + ff_mjpeg_encode_picture_trailer(s); + +- if(avctx->rc_buffer_size){ +- RateControlContext *rcc= &s->rc_context; +- int max_size= rcc->buffer_index * avctx->rc_max_available_vbv_use; +- +- if(put_bits_count(&s->pb) > max_size && s->lambda < s->avctx->lmax){ +- s->next_lambda= FFMAX(s->lambda+1, s->lambda*(s->qscale+1) / s->qscale); +- if(s->adaptive_quant){ ++ if (avctx->rc_buffer_size) { ++ RateControlContext *rcc = &s->rc_context; ++ int max_size = rcc->buffer_index * avctx->rc_max_available_vbv_use; ++ ++ if (put_bits_count(&s->pb) > max_size && ++ s->lambda < s->avctx->lmax) { ++ s->next_lambda = FFMAX(s->lambda + 1, s->lambda * ++ (s->qscale + 1) / s->qscale); ++ if (s->adaptive_quant) { + int i; +- for(i=0; imb_height*s->mb_stride; i++) +- s->lambda_table[i]= FFMAX(s->lambda_table[i]+1, s->lambda_table[i]*(s->qscale+1) / s->qscale); +- } +- s->mb_skipped = 0; //done in MPV_frame_start() +- if(s->pict_type==FF_P_TYPE){ //done in encode_picture() so we must undo it +- if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) ++ for (i = 0; i < s->mb_height * s->mb_stride; i++) ++ s->lambda_table[i] = ++ FFMAX(s->lambda_table[i] + 1, ++ s->lambda_table[i] * (s->qscale + 1) / ++ s->qscale); ++ } ++ s->mb_skipped = 0; // done in MPV_frame_start() ++ // done in encode_picture() so we must undo it ++ if (s->pict_type == AV_PICTURE_TYPE_P) { ++ if (s->flipflop_rounding || ++ s->codec_id == CODEC_ID_H263P || ++ s->codec_id == CODEC_ID_MPEG4) + s->no_rounding ^= 1; + } +- if(s->pict_type!=FF_B_TYPE){ +- s->time_base= s->last_time_base; +- s->last_non_b_time= s->time - s->pp_time; +- } +-// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); +- for(i=0; ithread_count; i++){ +- PutBitContext *pb= &s->thread_context[i]->pb; ++ if (s->pict_type != AV_PICTURE_TYPE_B) { ++ s->time_base = s->last_time_base; ++ s->last_non_b_time = s->time - s->pp_time; ++ } ++ //av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); ++ for (i = 0; i < context_count; i++) { ++ PutBitContext *pb = &s->thread_context[i]->pb; + init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); + } + goto vbv_retry; +@@ -1314,30 +1531,33 @@ + assert(s->avctx->rc_max_rate); + } + +- if(s->flags&CODEC_FLAG_PASS1) ++ if (s->flags & CODEC_FLAG_PASS1) + ff_write_pass1_stats(s); + +- for(i=0; i<4; i++){ +- s->current_picture_ptr->error[i]= s->current_picture.error[i]; +- avctx->error[i] += s->current_picture_ptr->error[i]; ++ for (i = 0; i < 4; i++) { ++ s->current_picture_ptr->f.error[i] = s->current_picture.f.error[i]; ++ avctx->error[i] += s->current_picture_ptr->f.error[i]; + } + +- if(s->flags&CODEC_FLAG_PASS1) +- assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + avctx->i_tex_bits + avctx->p_tex_bits == put_bits_count(&s->pb)); ++ if (s->flags & CODEC_FLAG_PASS1) ++ assert(avctx->header_bits + avctx->mv_bits + avctx->misc_bits + ++ avctx->i_tex_bits + avctx->p_tex_bits == ++ put_bits_count(&s->pb)); + flush_put_bits(&s->pb); + s->frame_bits = put_bits_count(&s->pb); + +- stuffing_count= ff_vbv_update(s, s->frame_bits); +- if(stuffing_count){ +- if(s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb)>>3) < stuffing_count + 50){ ++ stuffing_count = ff_vbv_update(s, s->frame_bits); ++ if (stuffing_count) { ++ if (s->pb.buf_end - s->pb.buf - (put_bits_count(&s->pb) >> 3) < ++ stuffing_count + 50) { + av_log(s->avctx, AV_LOG_ERROR, "stuffing too large\n"); + return -1; + } + +- switch(s->codec_id){ ++ switch (s->codec_id) { + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: +- while(stuffing_count--){ ++ while (stuffing_count--) { + put_bits(&s->pb, 8, 0); + } + break; +@@ -1345,7 +1565,7 @@ + put_bits(&s->pb, 16, 0); + put_bits(&s->pb, 16, 0x1C3); + stuffing_count -= 4; +- while(stuffing_count--){ ++ while (stuffing_count--) { + put_bits(&s->pb, 8, 0xFF); + } + break; +@@ -1357,244 +1577,281 @@ + } + + /* update mpeg1/2 vbv_delay for CBR */ +- if(s->avctx->rc_max_rate && s->avctx->rc_min_rate == s->avctx->rc_max_rate && s->out_format == FMT_MPEG1 +- && 90000LL * (avctx->rc_buffer_size-1) <= s->avctx->rc_max_rate*0xFFFFLL){ ++ if (s->avctx->rc_max_rate && ++ s->avctx->rc_min_rate == s->avctx->rc_max_rate && ++ s->out_format == FMT_MPEG1 && ++ 90000LL * (avctx->rc_buffer_size - 1) <= ++ s->avctx->rc_max_rate * 0xFFFFLL) { + int vbv_delay, min_delay; +- double inbits = s->avctx->rc_max_rate*av_q2d(s->avctx->time_base); +- int minbits= s->frame_bits - 8*(s->vbv_delay_ptr - s->pb.buf - 1); +- double bits = s->rc_context.buffer_index + minbits - inbits; +- +- if(bits<0) +- av_log(s->avctx, AV_LOG_ERROR, "Internal error, negative bits\n"); +- +- assert(s->repeat_first_field==0); +- +- vbv_delay= bits * 90000 / s->avctx->rc_max_rate; +- min_delay= (minbits * 90000LL + s->avctx->rc_max_rate - 1)/ s->avctx->rc_max_rate; ++ double inbits = s->avctx->rc_max_rate * ++ av_q2d(s->avctx->time_base); ++ int minbits = s->frame_bits - 8 * ++ (s->vbv_delay_ptr - s->pb.buf - 1); ++ double bits = s->rc_context.buffer_index + minbits - inbits; ++ ++ if (bits < 0) ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Internal error, negative bits\n"); ++ ++ assert(s->repeat_first_field == 0); ++ ++ vbv_delay = bits * 90000 / s->avctx->rc_max_rate; ++ min_delay = (minbits * 90000LL + s->avctx->rc_max_rate - 1) / ++ s->avctx->rc_max_rate; + +- vbv_delay= FFMAX(vbv_delay, min_delay); ++ vbv_delay = FFMAX(vbv_delay, min_delay); + + assert(vbv_delay < 0xFFFF); + + s->vbv_delay_ptr[0] &= 0xF8; +- s->vbv_delay_ptr[0] |= vbv_delay>>13; +- s->vbv_delay_ptr[1] = vbv_delay>>5; ++ s->vbv_delay_ptr[0] |= vbv_delay >> 13; ++ s->vbv_delay_ptr[1] = vbv_delay >> 5; + s->vbv_delay_ptr[2] &= 0x07; +- s->vbv_delay_ptr[2] |= vbv_delay<<3; ++ s->vbv_delay_ptr[2] |= vbv_delay << 3; ++ avctx->vbv_delay = vbv_delay * 300; + } +- s->total_bits += s->frame_bits; ++ s->total_bits += s->frame_bits; + avctx->frame_bits = s->frame_bits; +- }else{ ++ } else { + assert((put_bits_ptr(&s->pb) == s->pb.buf)); +- s->frame_bits=0; ++ s->frame_bits = 0; + } +- assert((s->frame_bits&7)==0); ++ assert((s->frame_bits & 7) == 0); + +- return s->frame_bits/8; ++ return s->frame_bits / 8; + } + +-static inline void dct_single_coeff_elimination(MpegEncContext *s, int n, int threshold) ++static inline void dct_single_coeff_elimination(MpegEncContext *s, ++ int n, int threshold) + { +- static const char tab[64]= +- {3,2,2,1,1,1,1,1, +- 1,1,1,1,1,1,1,1, +- 1,1,1,1,1,1,1,1, +- 0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0, +- 0,0,0,0,0,0,0,0}; +- int score=0; +- int run=0; ++ static const char tab[64] = { ++ 3, 2, 2, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0, ++ 0, 0, 0, 0, 0, 0, 0, 0 ++ }; ++ int score = 0; ++ int run = 0; + int i; +- DCTELEM *block= s->block[n]; +- const int last_index= s->block_last_index[n]; ++ DCTELEM *block = s->block[n]; ++ const int last_index = s->block_last_index[n]; + int skip_dc; + +- if(threshold<0){ +- skip_dc=0; +- threshold= -threshold; +- }else +- skip_dc=1; ++ if (threshold < 0) { ++ skip_dc = 0; ++ threshold = -threshold; ++ } else ++ skip_dc = 1; + + /* Are all we could set to zero already zero? */ +- if(last_index<=skip_dc - 1) return; ++ if (last_index <= skip_dc - 1) ++ return; + +- for(i=0; i<=last_index; i++){ ++ for (i = 0; i <= last_index; i++) { + const int j = s->intra_scantable.permutated[i]; + const int level = FFABS(block[j]); +- if(level==1){ +- if(skip_dc && i==0) continue; +- score+= tab[run]; +- run=0; +- }else if(level>1){ ++ if (level == 1) { ++ if (skip_dc && i == 0) ++ continue; ++ score += tab[run]; ++ run = 0; ++ } else if (level > 1) { + return; +- }else{ ++ } else { + run++; + } + } +- if(score >= threshold) return; +- for(i=skip_dc; i<=last_index; i++){ ++ if (score >= threshold) ++ return; ++ for (i = skip_dc; i <= last_index; i++) { + const int j = s->intra_scantable.permutated[i]; +- block[j]=0; ++ block[j] = 0; + } +- if(block[0]) s->block_last_index[n]= 0; +- else s->block_last_index[n]= -1; ++ if (block[0]) ++ s->block_last_index[n] = 0; ++ else ++ s->block_last_index[n] = -1; + } + +-static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, int last_index) ++static inline void clip_coeffs(MpegEncContext *s, DCTELEM *block, ++ int last_index) + { + int i; +- const int maxlevel= s->max_qcoeff; +- const int minlevel= s->min_qcoeff; +- int overflow=0; ++ const int maxlevel = s->max_qcoeff; ++ const int minlevel = s->min_qcoeff; ++ int overflow = 0; + +- if(s->mb_intra){ +- i=1; //skip clipping of intra dc +- }else +- i=0; ++ if (s->mb_intra) { ++ i = 1; // skip clipping of intra dc ++ } else ++ i = 0; + +- for(;i<=last_index; i++){ +- const int j= s->intra_scantable.permutated[i]; ++ for (; i <= last_index; i++) { ++ const int j = s->intra_scantable.permutated[i]; + int level = block[j]; + +- if (level>maxlevel){ +- level=maxlevel; ++ if (level > maxlevel) { ++ level = maxlevel; + overflow++; +- }else if(levelavctx->mb_decision == FF_MB_DECISION_SIMPLE) +- av_log(s->avctx, AV_LOG_INFO, "warning, clipping %d dct coefficients to %d..%d\n", overflow, minlevel, maxlevel); ++ if (overflow && s->avctx->mb_decision == FF_MB_DECISION_SIMPLE) ++ av_log(s->avctx, AV_LOG_INFO, ++ "warning, clipping %d dct coefficients to %d..%d\n", ++ overflow, minlevel, maxlevel); + } + +-static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride){ ++static void get_visual_weight(int16_t *weight, uint8_t *ptr, int stride) ++{ + int x, y; +-//FIXME optimize +- for(y=0; y<8; y++){ +- for(x=0; x<8; x++){ ++ // FIXME optimize ++ for (y = 0; y < 8; y++) { ++ for (x = 0; x < 8; x++) { + int x2, y2; +- int sum=0; +- int sqr=0; +- int count=0; +- +- for(y2= FFMAX(y-1, 0); y2 < FFMIN(8, y+2); y2++){ +- for(x2= FFMAX(x-1, 0); x2 < FFMIN(8, x+2); x2++){ +- int v= ptr[x2 + y2*stride]; ++ int sum = 0; ++ int sqr = 0; ++ int count = 0; ++ ++ for (y2 = FFMAX(y - 1, 0); y2 < FFMIN(8, y + 2); y2++) { ++ for (x2= FFMAX(x - 1, 0); x2 < FFMIN(8, x + 2); x2++) { ++ int v = ptr[x2 + y2 * stride]; + sum += v; +- sqr += v*v; ++ sqr += v * v; + count++; + } + } +- weight[x + 8*y]= (36*ff_sqrt(count*sqr - sum*sum)) / count; ++ weight[x + 8 * y]= (36 * ff_sqrt(count * sqr - sum * sum)) / count; + } + } + } + +-static av_always_inline void encode_mb_internal(MpegEncContext *s, int motion_x, int motion_y, int mb_block_height, int mb_block_count) ++static av_always_inline void encode_mb_internal(MpegEncContext *s, ++ int motion_x, int motion_y, ++ int mb_block_height, ++ int mb_block_count) + { + int16_t weight[8][64]; + DCTELEM orig[8][64]; +- const int mb_x= s->mb_x; +- const int mb_y= s->mb_y; ++ const int mb_x = s->mb_x; ++ const int mb_y = s->mb_y; + int i; + int skip_dct[8]; +- int dct_offset = s->linesize*8; //default for progressive frames ++ int dct_offset = s->linesize * 8; // default for progressive frames + uint8_t *ptr_y, *ptr_cb, *ptr_cr; + int wrap_y, wrap_c; + +- for(i=0; iskipdct; ++ for (i = 0; i < mb_block_count; i++) ++ skip_dct[i] = s->skipdct; + +- if(s->adaptive_quant){ +- const int last_qp= s->qscale; +- const int mb_xy= mb_x + mb_y*s->mb_stride; ++ if (s->adaptive_quant) { ++ const int last_qp = s->qscale; ++ const int mb_xy = mb_x + mb_y * s->mb_stride; + +- s->lambda= s->lambda_table[mb_xy]; ++ s->lambda = s->lambda_table[mb_xy]; + update_qscale(s); + +- if(!(s->flags&CODEC_FLAG_QP_RD)){ +- s->qscale= s->current_picture_ptr->qscale_table[mb_xy]; +- s->dquant= s->qscale - last_qp; +- +- if(s->out_format==FMT_H263){ +- s->dquant= av_clip(s->dquant, -2, 2); +- +- if(s->codec_id==CODEC_ID_MPEG4){ +- if(!s->mb_intra){ +- if(s->pict_type == FF_B_TYPE){ +- if(s->dquant&1 || s->mv_dir&MV_DIRECT) +- s->dquant= 0; ++ if (!(s->flags & CODEC_FLAG_QP_RD)) { ++ s->qscale = s->current_picture_ptr->f.qscale_table[mb_xy]; ++ s->dquant = s->qscale - last_qp; ++ ++ if (s->out_format == FMT_H263) { ++ s->dquant = av_clip(s->dquant, -2, 2); ++ ++ if (s->codec_id == CODEC_ID_MPEG4) { ++ if (!s->mb_intra) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { ++ if (s->dquant & 1 || s->mv_dir & MV_DIRECT) ++ s->dquant = 0; + } +- if(s->mv_type==MV_TYPE_8X8) +- s->dquant=0; ++ if (s->mv_type == MV_TYPE_8X8) ++ s->dquant = 0; + } + } + } + } + ff_set_qscale(s, last_qp + s->dquant); +- }else if(s->flags&CODEC_FLAG_QP_RD) ++ } else if (s->flags & CODEC_FLAG_QP_RD) + ff_set_qscale(s, s->qscale + s->dquant); + + wrap_y = s->linesize; + wrap_c = s->uvlinesize; +- ptr_y = s->new_picture.data[0] + (mb_y * 16 * wrap_y) + mb_x * 16; +- ptr_cb = s->new_picture.data[1] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; +- ptr_cr = s->new_picture.data[2] + (mb_y * mb_block_height * wrap_c) + mb_x * 8; +- +- if(mb_x*16+16 > s->width || mb_y*16+16 > s->height){ +- uint8_t *ebuf= s->edge_emu_buffer + 32; +- s->dsp.emulated_edge_mc(ebuf , ptr_y , wrap_y,16,16,mb_x*16,mb_y*16, s->width , s->height); +- ptr_y= ebuf; +- s->dsp.emulated_edge_mc(ebuf+18*wrap_y , ptr_cb, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); +- ptr_cb= ebuf+18*wrap_y; +- s->dsp.emulated_edge_mc(ebuf+18*wrap_y+8, ptr_cr, wrap_c, 8, mb_block_height, mb_x*8, mb_y*8, s->width>>1, s->height>>1); +- ptr_cr= ebuf+18*wrap_y+8; ++ ptr_y = s->new_picture.f.data[0] + ++ (mb_y * 16 * wrap_y) + mb_x * 16; ++ ptr_cb = s->new_picture.f.data[1] + ++ (mb_y * mb_block_height * wrap_c) + mb_x * 8; ++ ptr_cr = s->new_picture.f.data[2] + ++ (mb_y * mb_block_height * wrap_c) + mb_x * 8; ++ ++ if((mb_x*16+16 > s->width || mb_y*16+16 > s->height) && s->codec_id != CODEC_ID_AMV){ ++ uint8_t *ebuf = s->edge_emu_buffer + 32; ++ s->dsp.emulated_edge_mc(ebuf, ptr_y, wrap_y, 16, 16, mb_x * 16, ++ mb_y * 16, s->width, s->height); ++ ptr_y = ebuf; ++ s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y, ptr_cb, wrap_c, 8, ++ mb_block_height, mb_x * 8, mb_y * 8, ++ s->width >> 1, s->height >> 1); ++ ptr_cb = ebuf + 18 * wrap_y; ++ s->dsp.emulated_edge_mc(ebuf + 18 * wrap_y + 8, ptr_cr, wrap_c, 8, ++ mb_block_height, mb_x * 8, mb_y * 8, ++ s->width >> 1, s->height >> 1); ++ ptr_cr = ebuf + 18 * wrap_y + 8; + } + + if (s->mb_intra) { +- if(s->flags&CODEC_FLAG_INTERLACED_DCT){ ++ if (s->flags & CODEC_FLAG_INTERLACED_DCT) { + int progressive_score, interlaced_score; + +- s->interlaced_dct=0; +- progressive_score= s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y, 8) +- +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y*8, NULL, wrap_y, 8) - 400; +- +- if(progressive_score > 0){ +- interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y , NULL, wrap_y*2, 8) +- +s->dsp.ildct_cmp[4](s, ptr_y + wrap_y , NULL, wrap_y*2, 8); +- if(progressive_score > interlaced_score){ +- s->interlaced_dct=1; ++ s->interlaced_dct = 0; ++ progressive_score = s->dsp.ildct_cmp[4](s, ptr_y, ++ NULL, wrap_y, 8) + ++ s->dsp.ildct_cmp[4](s, ptr_y + wrap_y * 8, ++ NULL, wrap_y, 8) - 400; ++ ++ if (progressive_score > 0) { ++ interlaced_score = s->dsp.ildct_cmp[4](s, ptr_y, ++ NULL, wrap_y * 2, 8) + ++ s->dsp.ildct_cmp[4](s, ptr_y + wrap_y, ++ NULL, wrap_y * 2, 8); ++ if (progressive_score > interlaced_score) { ++ s->interlaced_dct = 1; + +- dct_offset= wrap_y; +- wrap_y<<=1; ++ dct_offset = wrap_y; ++ wrap_y <<= 1; + if (s->chroma_format == CHROMA_422) +- wrap_c<<=1; ++ wrap_c <<= 1; + } + } + } + +- s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); +- s->dsp.get_pixels(s->block[1], ptr_y + 8, wrap_y); +- s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); +- s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8, wrap_y); ++ s->dsp.get_pixels(s->block[0], ptr_y , wrap_y); ++ s->dsp.get_pixels(s->block[1], ptr_y + 8 , wrap_y); ++ s->dsp.get_pixels(s->block[2], ptr_y + dct_offset , wrap_y); ++ s->dsp.get_pixels(s->block[3], ptr_y + dct_offset + 8 , wrap_y); + +- if(s->flags&CODEC_FLAG_GRAY){ +- skip_dct[4]= 1; +- skip_dct[5]= 1; +- }else{ ++ if (s->flags & CODEC_FLAG_GRAY) { ++ skip_dct[4] = 1; ++ skip_dct[5] = 1; ++ } else { + s->dsp.get_pixels(s->block[4], ptr_cb, wrap_c); + s->dsp.get_pixels(s->block[5], ptr_cr, wrap_c); +- if(!s->chroma_y_shift){ /* 422 */ +- s->dsp.get_pixels(s->block[6], ptr_cb + (dct_offset>>1), wrap_c); +- s->dsp.get_pixels(s->block[7], ptr_cr + (dct_offset>>1), wrap_c); ++ if (!s->chroma_y_shift) { /* 422 */ ++ s->dsp.get_pixels(s->block[6], ++ ptr_cb + (dct_offset >> 1), wrap_c); ++ s->dsp.get_pixels(s->block[7], ++ ptr_cr + (dct_offset >> 1), wrap_c); + } + } +- }else{ ++ } else { + op_pixels_func (*op_pix)[4]; + qpel_mc_func (*op_qpix)[16]; + uint8_t *dest_y, *dest_cb, *dest_cr; +@@ -1603,146 +1860,197 @@ + dest_cb = s->dest[1]; + dest_cr = s->dest[2]; + +- if ((!s->no_rounding) || s->pict_type==FF_B_TYPE){ +- op_pix = s->dsp.put_pixels_tab; +- op_qpix= s->dsp.put_qpel_pixels_tab; +- }else{ +- op_pix = s->dsp.put_no_rnd_pixels_tab; +- op_qpix= s->dsp.put_no_rnd_qpel_pixels_tab; ++ if ((!s->no_rounding) || s->pict_type == AV_PICTURE_TYPE_B) { ++ op_pix = s->dsp.put_pixels_tab; ++ op_qpix = s->dsp.put_qpel_pixels_tab; ++ } else { ++ op_pix = s->dsp.put_no_rnd_pixels_tab; ++ op_qpix = s->dsp.put_no_rnd_qpel_pixels_tab; + } + + if (s->mv_dir & MV_DIR_FORWARD) { +- MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.data, op_pix, op_qpix); +- op_pix = s->dsp.avg_pixels_tab; +- op_qpix= s->dsp.avg_qpel_pixels_tab; ++ MPV_motion(s, dest_y, dest_cb, dest_cr, 0, s->last_picture.f.data, ++ op_pix, op_qpix); ++ op_pix = s->dsp.avg_pixels_tab; ++ op_qpix = s->dsp.avg_qpel_pixels_tab; + } + if (s->mv_dir & MV_DIR_BACKWARD) { +- MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.data, op_pix, op_qpix); ++ MPV_motion(s, dest_y, dest_cb, dest_cr, 1, s->next_picture.f.data, ++ op_pix, op_qpix); + } + +- if(s->flags&CODEC_FLAG_INTERLACED_DCT){ ++ if (s->flags & CODEC_FLAG_INTERLACED_DCT) { + int progressive_score, interlaced_score; + +- s->interlaced_dct=0; +- progressive_score= s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y, 8) +- +s->dsp.ildct_cmp[0](s, dest_y + wrap_y*8, ptr_y + wrap_y*8, wrap_y, 8) - 400; +- +- if(s->avctx->ildct_cmp == FF_CMP_VSSE) progressive_score -= 400; ++ s->interlaced_dct = 0; ++ progressive_score = s->dsp.ildct_cmp[0](s, dest_y, ++ ptr_y, wrap_y, ++ 8) + ++ s->dsp.ildct_cmp[0](s, dest_y + wrap_y * 8, ++ ptr_y + wrap_y * 8, wrap_y, ++ 8) - 400; ++ ++ if (s->avctx->ildct_cmp == FF_CMP_VSSE) ++ progressive_score -= 400; ++ ++ if (progressive_score > 0) { ++ interlaced_score = s->dsp.ildct_cmp[0](s, dest_y, ++ ptr_y, ++ wrap_y * 2, 8) + ++ s->dsp.ildct_cmp[0](s, dest_y + wrap_y, ++ ptr_y + wrap_y, ++ wrap_y * 2, 8); + +- if(progressive_score>0){ +- interlaced_score = s->dsp.ildct_cmp[0](s, dest_y , ptr_y , wrap_y*2, 8) +- +s->dsp.ildct_cmp[0](s, dest_y + wrap_y , ptr_y + wrap_y , wrap_y*2, 8); ++ if (progressive_score > interlaced_score) { ++ s->interlaced_dct = 1; + +- if(progressive_score > interlaced_score){ +- s->interlaced_dct=1; +- +- dct_offset= wrap_y; +- wrap_y<<=1; ++ dct_offset = wrap_y; ++ wrap_y <<= 1; + if (s->chroma_format == CHROMA_422) +- wrap_c<<=1; ++ wrap_c <<= 1; + } + } + } + +- s->dsp.diff_pixels(s->block[0], ptr_y , dest_y , wrap_y); +- s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); +- s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset , dest_y + dct_offset , wrap_y); +- s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, dest_y + dct_offset + 8, wrap_y); ++ s->dsp.diff_pixels(s->block[0], ptr_y, dest_y, wrap_y); ++ s->dsp.diff_pixels(s->block[1], ptr_y + 8, dest_y + 8, wrap_y); ++ s->dsp.diff_pixels(s->block[2], ptr_y + dct_offset, ++ dest_y + dct_offset, wrap_y); ++ s->dsp.diff_pixels(s->block[3], ptr_y + dct_offset + 8, ++ dest_y + dct_offset + 8, wrap_y); + +- if(s->flags&CODEC_FLAG_GRAY){ +- skip_dct[4]= 1; +- skip_dct[5]= 1; +- }else{ ++ if (s->flags & CODEC_FLAG_GRAY) { ++ skip_dct[4] = 1; ++ skip_dct[5] = 1; ++ } else { + s->dsp.diff_pixels(s->block[4], ptr_cb, dest_cb, wrap_c); + s->dsp.diff_pixels(s->block[5], ptr_cr, dest_cr, wrap_c); +- if(!s->chroma_y_shift){ /* 422 */ +- s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset>>1), dest_cb + (dct_offset>>1), wrap_c); +- s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset>>1), dest_cr + (dct_offset>>1), wrap_c); ++ if (!s->chroma_y_shift) { /* 422 */ ++ s->dsp.diff_pixels(s->block[6], ptr_cb + (dct_offset >> 1), ++ dest_cb + (dct_offset >> 1), wrap_c); ++ s->dsp.diff_pixels(s->block[7], ptr_cr + (dct_offset >> 1), ++ dest_cr + (dct_offset >> 1), wrap_c); + } + } + /* pre quantization */ +- if(s->current_picture.mc_mb_var[s->mb_stride*mb_y+ mb_x]<2*s->qscale*s->qscale){ +- //FIXME optimize +- if(s->dsp.sad[1](NULL, ptr_y , dest_y , wrap_y, 8) < 20*s->qscale) skip_dct[0]= 1; +- if(s->dsp.sad[1](NULL, ptr_y + 8, dest_y + 8, wrap_y, 8) < 20*s->qscale) skip_dct[1]= 1; +- if(s->dsp.sad[1](NULL, ptr_y +dct_offset , dest_y +dct_offset , wrap_y, 8) < 20*s->qscale) skip_dct[2]= 1; +- if(s->dsp.sad[1](NULL, ptr_y +dct_offset+ 8, dest_y +dct_offset+ 8, wrap_y, 8) < 20*s->qscale) skip_dct[3]= 1; +- if(s->dsp.sad[1](NULL, ptr_cb , dest_cb , wrap_c, 8) < 20*s->qscale) skip_dct[4]= 1; +- if(s->dsp.sad[1](NULL, ptr_cr , dest_cr , wrap_c, 8) < 20*s->qscale) skip_dct[5]= 1; +- if(!s->chroma_y_shift){ /* 422 */ +- if(s->dsp.sad[1](NULL, ptr_cb +(dct_offset>>1), dest_cb +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[6]= 1; +- if(s->dsp.sad[1](NULL, ptr_cr +(dct_offset>>1), dest_cr +(dct_offset>>1), wrap_c, 8) < 20*s->qscale) skip_dct[7]= 1; ++ if (s->current_picture.mc_mb_var[s->mb_stride * mb_y + mb_x] < ++ 2 * s->qscale * s->qscale) { ++ // FIXME optimize ++ if (s->dsp.sad[1](NULL, ptr_y , dest_y, ++ wrap_y, 8) < 20 * s->qscale) ++ skip_dct[0] = 1; ++ if (s->dsp.sad[1](NULL, ptr_y + 8, ++ dest_y + 8, wrap_y, 8) < 20 * s->qscale) ++ skip_dct[1] = 1; ++ if (s->dsp.sad[1](NULL, ptr_y + dct_offset, ++ dest_y + dct_offset, wrap_y, 8) < 20 * s->qscale) ++ skip_dct[2] = 1; ++ if (s->dsp.sad[1](NULL, ptr_y + dct_offset + 8, ++ dest_y + dct_offset + 8, ++ wrap_y, 8) < 20 * s->qscale) ++ skip_dct[3] = 1; ++ if (s->dsp.sad[1](NULL, ptr_cb, dest_cb, ++ wrap_c, 8) < 20 * s->qscale) ++ skip_dct[4] = 1; ++ if (s->dsp.sad[1](NULL, ptr_cr, dest_cr, ++ wrap_c, 8) < 20 * s->qscale) ++ skip_dct[5] = 1; ++ if (!s->chroma_y_shift) { /* 422 */ ++ if (s->dsp.sad[1](NULL, ptr_cb + (dct_offset >> 1), ++ dest_cb + (dct_offset >> 1), ++ wrap_c, 8) < 20 * s->qscale) ++ skip_dct[6] = 1; ++ if (s->dsp.sad[1](NULL, ptr_cr + (dct_offset >> 1), ++ dest_cr + (dct_offset >> 1), ++ wrap_c, 8) < 20 * s->qscale) ++ skip_dct[7] = 1; + } + } + } + +- if(s->avctx->quantizer_noise_shaping){ +- if(!skip_dct[0]) get_visual_weight(weight[0], ptr_y , wrap_y); +- if(!skip_dct[1]) get_visual_weight(weight[1], ptr_y + 8, wrap_y); +- if(!skip_dct[2]) get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y); +- if(!skip_dct[3]) get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); +- if(!skip_dct[4]) get_visual_weight(weight[4], ptr_cb , wrap_c); +- if(!skip_dct[5]) get_visual_weight(weight[5], ptr_cr , wrap_c); +- if(!s->chroma_y_shift){ /* 422 */ +- if(!skip_dct[6]) get_visual_weight(weight[6], ptr_cb + (dct_offset>>1), wrap_c); +- if(!skip_dct[7]) get_visual_weight(weight[7], ptr_cr + (dct_offset>>1), wrap_c); ++ if (s->avctx->quantizer_noise_shaping) { ++ if (!skip_dct[0]) ++ get_visual_weight(weight[0], ptr_y , wrap_y); ++ if (!skip_dct[1]) ++ get_visual_weight(weight[1], ptr_y + 8, wrap_y); ++ if (!skip_dct[2]) ++ get_visual_weight(weight[2], ptr_y + dct_offset , wrap_y); ++ if (!skip_dct[3]) ++ get_visual_weight(weight[3], ptr_y + dct_offset + 8, wrap_y); ++ if (!skip_dct[4]) ++ get_visual_weight(weight[4], ptr_cb , wrap_c); ++ if (!skip_dct[5]) ++ get_visual_weight(weight[5], ptr_cr , wrap_c); ++ if (!s->chroma_y_shift) { /* 422 */ ++ if (!skip_dct[6]) ++ get_visual_weight(weight[6], ptr_cb + (dct_offset >> 1), ++ wrap_c); ++ if (!skip_dct[7]) ++ get_visual_weight(weight[7], ptr_cr + (dct_offset >> 1), ++ wrap_c); + } +- memcpy(orig[0], s->block[0], sizeof(DCTELEM)*64*mb_block_count); ++ memcpy(orig[0], s->block[0], sizeof(DCTELEM) * 64 * mb_block_count); + } + + /* DCT & quantize */ +- assert(s->out_format!=FMT_MJPEG || s->qscale==8); ++ assert(s->out_format != FMT_MJPEG || s->qscale == 8); + { +- for(i=0;iblock_last_index[i] = s->dct_quantize(s, s->block[i], i, s->qscale, &overflow); +- // FIXME we could decide to change to quantizer instead of clipping +- // JS: I don't think that would be a good idea it could lower quality instead +- // of improve it. Just INTRADC clipping deserves changes in quantizer +- if (overflow) clip_coeffs(s, s->block[i], s->block_last_index[i]); +- }else +- s->block_last_index[i]= -1; +- } +- if(s->avctx->quantizer_noise_shaping){ +- for(i=0;iblock_last_index[i] = dct_quantize_refine(s, s->block[i], weight[i], orig[i], i, s->qscale); ++ // FIXME we could decide to change to quantizer instead of ++ // clipping ++ // JS: I don't think that would be a good idea it could lower ++ // quality instead of improve it. Just INTRADC clipping ++ // deserves changes in quantizer ++ if (overflow) ++ clip_coeffs(s, s->block[i], s->block_last_index[i]); ++ } else ++ s->block_last_index[i] = -1; ++ } ++ if (s->avctx->quantizer_noise_shaping) { ++ for (i = 0; i < mb_block_count; i++) { ++ if (!skip_dct[i]) { ++ s->block_last_index[i] = ++ dct_quantize_refine(s, s->block[i], weight[i], ++ orig[i], i, s->qscale); + } + } + } + +- if(s->luma_elim_threshold && !s->mb_intra) +- for(i=0; i<4; i++) ++ if (s->luma_elim_threshold && !s->mb_intra) ++ for (i = 0; i < 4; i++) + dct_single_coeff_elimination(s, i, s->luma_elim_threshold); +- if(s->chroma_elim_threshold && !s->mb_intra) +- for(i=4; ichroma_elim_threshold && !s->mb_intra) ++ for (i = 4; i < mb_block_count; i++) + dct_single_coeff_elimination(s, i, s->chroma_elim_threshold); + +- if(s->flags & CODEC_FLAG_CBP_RD){ +- for(i=0;iblock_last_index[i] == -1) +- s->coded_score[i]= INT_MAX/256; ++ if (s->flags & CODEC_FLAG_CBP_RD) { ++ for (i = 0; i < mb_block_count; i++) { ++ if (s->block_last_index[i] == -1) ++ s->coded_score[i] = INT_MAX / 256; + } + } + } + +- if((s->flags&CODEC_FLAG_GRAY) && s->mb_intra){ +- s->block_last_index[4]= +- s->block_last_index[5]= 0; +- s->block[4][0]= +- s->block[5][0]= (1024 + s->c_dc_scale/2)/ s->c_dc_scale; ++ if ((s->flags & CODEC_FLAG_GRAY) && s->mb_intra) { ++ s->block_last_index[4] = ++ s->block_last_index[5] = 0; ++ s->block[4][0] = ++ s->block[5][0] = (1024 + s->c_dc_scale / 2) / s->c_dc_scale; + } + +- //non c quantize code returns incorrect block_last_index FIXME +- if(s->alternate_scan && s->dct_quantize != dct_quantize_c){ +- for(i=0; ialternate_scan && s->dct_quantize != dct_quantize_c) { ++ for (i = 0; i < mb_block_count; i++) { + int j; +- if(s->block_last_index[i]>0){ +- for(j=63; j>0; j--){ +- if(s->block[i][ s->intra_scantable.permutated[j] ]) break; ++ if (s->block_last_index[i] > 0) { ++ for (j = 63; j > 0; j--) { ++ if (s->block[i][s->intra_scantable.permutated[j]]) ++ break; + } +- s->block_last_index[i]= j; ++ s->block_last_index[i] = j; + } + } + } +@@ -1781,6 +2089,7 @@ + h263_encode_mb(s, s->block, motion_x, motion_y); + break; + case CODEC_ID_MJPEG: ++ case CODEC_ID_AMV: + if (CONFIG_MJPEG_ENCODER) + ff_mjpeg_encode_mb(s, s->block); + break; +@@ -1798,12 +2107,12 @@ + static inline void copy_context_before_encode(MpegEncContext *d, MpegEncContext *s, int type){ + int i; + +- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? ++ memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster than a loop? + + /* mpeg1 */ + d->mb_skip_run= s->mb_skip_run; + for(i=0; i<3; i++) +- d->last_dc[i]= s->last_dc[i]; ++ d->last_dc[i] = s->last_dc[i]; + + /* statistics */ + d->mv_bits= s->mv_bits; +@@ -1827,12 +2136,12 @@ + int i; + + memcpy(d->mv, s->mv, 2*4*2*sizeof(int)); +- memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster then a loop? ++ memcpy(d->last_mv, s->last_mv, 2*2*2*sizeof(int)); //FIXME is memcpy faster than a loop? + + /* mpeg1 */ + d->mb_skip_run= s->mb_skip_run; + for(i=0; i<3; i++) +- d->last_dc[i]= s->last_dc[i]; ++ d->last_dc[i] = s->last_dc[i]; + + /* statistics */ + d->mv_bits= s->mv_bits; +@@ -1943,18 +2252,18 @@ + + if(w==16 && h==16) + if(s->avctx->mb_cmp == FF_CMP_NSSE){ +- return s->dsp.nsse[0](s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) +- +s->dsp.nsse[1](s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) +- +s->dsp.nsse[1](s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); ++ return s->dsp.nsse[0](s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) ++ +s->dsp.nsse[1](s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) ++ +s->dsp.nsse[1](s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + }else{ +- return s->dsp.sse[0](NULL, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) +- +s->dsp.sse[1](NULL, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) +- +s->dsp.sse[1](NULL, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); ++ return s->dsp.sse[0](NULL, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], s->linesize, 16) ++ +s->dsp.sse[1](NULL, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], s->uvlinesize, 8) ++ +s->dsp.sse[1](NULL, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], s->uvlinesize, 8); + } + else +- return sse(s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) +- +sse(s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) +- +sse(s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize); ++ return sse(s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, s->dest[0], w, h, s->linesize) ++ +sse(s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[1], w>>1, h>>1, s->uvlinesize) ++ +sse(s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*8,s->dest[2], w>>1, h>>1, s->uvlinesize); + } + + static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){ +@@ -1993,7 +2302,7 @@ + s->block_index[3]+=2; + + /* compute motion vector & mb_type and store in context */ +- if(s->pict_type==FF_B_TYPE) ++ if(s->pict_type==AV_PICTURE_TYPE_B) + ff_estimate_b_frame_motion(s, s->mb_x, s->mb_y); + else + ff_estimate_p_frame_motion(s, s->mb_x, s->mb_y); +@@ -2013,11 +2322,11 @@ + for(mb_x=0; mb_x < s->mb_width; mb_x++) { + int xx = mb_x * 16; + int yy = mb_y * 16; +- uint8_t *pix = s->new_picture.data[0] + (yy * s->linesize) + xx; ++ uint8_t *pix = s->new_picture.f.data[0] + (yy * s->linesize) + xx; + int varc; + int sum = s->dsp.pix_sum(pix, s->linesize); + +- varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)(sum*sum))>>8) + 500 + 128)>>8; ++ varc = (s->dsp.pix_norm1(pix, s->linesize) - (((unsigned)sum*sum)>>8) + 500 + 128)>>8; + + s->current_picture.mb_var [s->mb_stride * mb_y + mb_x] = varc; + s->current_picture.mb_mean[s->mb_stride * mb_y + mb_x] = (sum+128)>>8; +@@ -2038,7 +2347,7 @@ + ff_mjpeg_encode_stuffing(&s->pb); + } + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + flush_put_bits(&s->pb); + + if((s->flags&CODEC_FLAG_PASS1) && !s->partitioned_frame) +@@ -2080,7 +2389,12 @@ + /* note: quant matrix value (8) is implied here */ + s->last_dc[i] = 128 << s->intra_dc_precision; + +- s->current_picture.error[i] = 0; ++ s->current_picture.f.error[i] = 0; ++ } ++ if(s->codec_id==CODEC_ID_AMV){ ++ s->last_dc[0] = 128*8/13; ++ s->last_dc[1] = 128*8/14; ++ s->last_dc[2] = 128*8/14; + } + s->mb_skip_run = 0; + memset(s->last_mv, 0, sizeof(s->last_mv)); +@@ -2181,9 +2495,7 @@ + int d= 100 / s->avctx->error_rate; + if(r % d == 0){ + current_packet_size=0; +-#ifndef ALT_BITSTREAM_WRITER + s->pb.buf_ptr= s->ptr_lastgob; +-#endif + assert(put_bits_ptr(&s->pb) == s->ptr_lastgob); + } + } +@@ -2283,8 +2595,8 @@ + s->mv_type = MV_TYPE_8X8; + s->mb_intra= 0; + for(i=0; i<4; i++){ +- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; +- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; ++ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0]; ++ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1]; + } + encode_mb_hq(s, &backup_s, &best_s, CANDIDATE_MB_TYPE_INTER4V, pb, pb2, tex_pb, + &dmin, &next_block, 0, 0); +@@ -2391,7 +2703,7 @@ + s->mv[1][0][0] = best_s.mv[1][0][0]; + s->mv[1][0][1] = best_s.mv[1][0][1]; + +- qpi = s->pict_type == FF_B_TYPE ? 2 : 0; ++ qpi = s->pict_type == AV_PICTURE_TYPE_B ? 2 : 0; + for(; qpi<4; qpi++){ + int dquant= dquant_tab[qpi]; + qp= last_qp + dquant; +@@ -2470,30 +2782,30 @@ + } + } + +- s->current_picture.qscale_table[xy]= best_s.qscale; ++ s->current_picture.f.qscale_table[xy] = best_s.qscale; + + copy_context_after_encode(s, &best_s, -1); + + pb_bits_count= put_bits_count(&s->pb); + flush_put_bits(&s->pb); +- ff_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); ++ avpriv_copy_bits(&backup_s.pb, bit_buf[next_block^1], pb_bits_count); + s->pb= backup_s.pb; + + if(s->data_partitioning){ + pb2_bits_count= put_bits_count(&s->pb2); + flush_put_bits(&s->pb2); +- ff_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); ++ avpriv_copy_bits(&backup_s.pb2, bit_buf2[next_block^1], pb2_bits_count); + s->pb2= backup_s.pb2; + + tex_pb_bits_count= put_bits_count(&s->tex_pb); + flush_put_bits(&s->tex_pb); +- ff_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); ++ avpriv_copy_bits(&backup_s.tex_pb, bit_buf_tex[next_block^1], tex_pb_bits_count); + s->tex_pb= backup_s.tex_pb; + } + s->last_bits= put_bits_count(&s->pb); + + if (CONFIG_H263_ENCODER && +- s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE) ++ s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) + ff_h263_update_motion_val(s); + + if(next_block==0){ //FIXME 16 vs linesize16 +@@ -2537,8 +2849,8 @@ + s->mv_type = MV_TYPE_8X8; + s->mb_intra= 0; + for(i=0; i<4; i++){ +- s->mv[0][i][0] = s->current_picture.motion_val[0][s->block_index[i]][0]; +- s->mv[0][i][1] = s->current_picture.motion_val[0][s->block_index[i]][1]; ++ s->mv[0][i][0] = s->current_picture.f.motion_val[0][s->block_index[i]][0]; ++ s->mv[0][i][1] = s->current_picture.f.motion_val[0][s->block_index[i]][1]; + } + break; + case CANDIDATE_MB_TYPE_DIRECT: +@@ -2620,7 +2932,7 @@ + s->last_mv_dir = s->mv_dir; + + if (CONFIG_H263_ENCODER && +- s->out_format == FMT_H263 && s->pict_type!=FF_B_TYPE) ++ s->out_format == FMT_H263 && s->pict_type!=AV_PICTURE_TYPE_B) + ff_h263_update_motion_val(s); + + MPV_decode_mb(s, s->block); +@@ -2639,14 +2951,14 @@ + if(s->mb_x*16 + 16 > s->width ) w= s->width - s->mb_x*16; + if(s->mb_y*16 + 16 > s->height) h= s->height- s->mb_y*16; + +- s->current_picture.error[0] += sse( +- s, s->new_picture.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, ++ s->current_picture.f.error[0] += sse( ++ s, s->new_picture.f.data[0] + s->mb_x*16 + s->mb_y*s->linesize*16, + s->dest[0], w, h, s->linesize); +- s->current_picture.error[1] += sse( +- s, s->new_picture.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, ++ s->current_picture.f.error[1] += sse( ++ s, s->new_picture.f.data[1] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, + s->dest[1], w>>1, h>>s->chroma_y_shift, s->uvlinesize); +- s->current_picture.error[2] += sse( +- s, s->new_picture.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, ++ s->current_picture.f.error[2] += sse( ++ s, s->new_picture.f.data[2] + s->mb_x*8 + s->mb_y*s->uvlinesize*chr_h, + s->dest[2], w>>1, h>>s->chroma_y_shift, s->uvlinesize); + } + if(s->loop_filter){ +@@ -2658,7 +2970,7 @@ + } + + //not beautiful here but we must write it before flushing so it has to be here +- if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == FF_I_TYPE) ++ if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version && s->msmpeg4_version<4 && s->pict_type == AV_PICTURE_TYPE_I) + msmpeg4_encode_ext_header(s); + + write_slice_end(s); +@@ -2697,9 +3009,9 @@ + MERGE(misc_bits); + MERGE(error_count); + MERGE(padding_bug_score); +- MERGE(current_picture.error[0]); +- MERGE(current_picture.error[1]); +- MERGE(current_picture.error[2]); ++ MERGE(current_picture.f.error[0]); ++ MERGE(current_picture.f.error[1]); ++ MERGE(current_picture.f.error[2]); + + if(dst->avctx->noise_reduction){ + for(i=0; i<64; i++){ +@@ -2710,19 +3022,19 @@ + + assert(put_bits_count(&src->pb) % 8 ==0); + assert(put_bits_count(&dst->pb) % 8 ==0); +- ff_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); ++ avpriv_copy_bits(&dst->pb, src->pb.buf, put_bits_count(&src->pb)); + flush_put_bits(&dst->pb); + } + + static int estimate_qp(MpegEncContext *s, int dry_run){ + if (s->next_lambda){ +- s->current_picture_ptr->quality= +- s->current_picture.quality = s->next_lambda; ++ s->current_picture_ptr->f.quality = ++ s->current_picture.f.quality = s->next_lambda; + if(!dry_run) s->next_lambda= 0; + } else if (!s->fixed_qscale) { +- s->current_picture_ptr->quality= +- s->current_picture.quality = ff_rate_estimate_qscale(s, dry_run); +- if (s->current_picture.quality < 0) ++ s->current_picture_ptr->f.quality = ++ s->current_picture.f.quality = ff_rate_estimate_qscale(s, dry_run); ++ if (s->current_picture.f.quality < 0) + return -1; + } + +@@ -2745,7 +3057,7 @@ + s->lambda= s->lambda_table[0]; + //FIXME broken + }else +- s->lambda= s->current_picture.quality; ++ s->lambda = s->current_picture.f.quality; + //printf("%d %d\n", s->avctx->global_quality, s->current_picture.quality); + update_qscale(s); + return 0; +@@ -2753,10 +3065,10 @@ + + /* must be called before writing the header */ + static void set_frame_distances(MpegEncContext * s){ +- assert(s->current_picture_ptr->pts != AV_NOPTS_VALUE); +- s->time= s->current_picture_ptr->pts*s->avctx->time_base.num; ++ assert(s->current_picture_ptr->f.pts != AV_NOPTS_VALUE); ++ s->time = s->current_picture_ptr->f.pts * s->avctx->time_base.num; + +- if(s->pict_type==FF_B_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_B){ + s->pb_time= s->pp_time - (s->last_non_b_time - s->time); + assert(s->pb_time > 0 && s->pb_time < s->pp_time); + }else{ +@@ -2770,6 +3082,7 @@ + { + int i; + int bits; ++ int context_count = s->slice_context_count; + + s->picture_number = picture_number; + +@@ -2779,7 +3092,7 @@ + + /* we need to initialize some time vars before we can encode b-frames */ + // RAL: Condition added for MPEG1VIDEO +- if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->h263_msmpeg4)) ++ if (s->codec_id == CODEC_ID_MPEG1VIDEO || s->codec_id == CODEC_ID_MPEG2VIDEO || (s->h263_pred && !s->msmpeg4_version)) + set_frame_distances(s); + if(CONFIG_MPEG4_ENCODER && s->codec_id == CODEC_ID_MPEG4) + ff_set_mpeg4_time(s); +@@ -2788,10 +3101,10 @@ + + // s->lambda= s->current_picture_ptr->quality; //FIXME qscale / ... stuff for ME rate distortion + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + if(s->msmpeg4_version >= 3) s->no_rounding=1; + else s->no_rounding=0; +- }else if(s->pict_type!=FF_B_TYPE){ ++ }else if(s->pict_type!=AV_PICTURE_TYPE_B){ + if(s->flipflop_rounding || s->codec_id == CODEC_ID_H263P || s->codec_id == CODEC_ID_MPEG4) + s->no_rounding ^= 1; + } +@@ -2801,15 +3114,22 @@ + return -1; + ff_get_2pass_fcode(s); + }else if(!(s->flags & CODEC_FLAG_QSCALE)){ +- if(s->pict_type==FF_B_TYPE) ++ if(s->pict_type==AV_PICTURE_TYPE_B) + s->lambda= s->last_lambda_for[s->pict_type]; + else + s->lambda= s->last_lambda_for[s->last_non_b_pict_type]; + update_qscale(s); + } + ++ if(s->codec_id != CODEC_ID_AMV){ ++ if(s->q_chroma_intra_matrix != s->q_intra_matrix ) av_freep(&s->q_chroma_intra_matrix); ++ if(s->q_chroma_intra_matrix16 != s->q_intra_matrix16) av_freep(&s->q_chroma_intra_matrix16); ++ s->q_chroma_intra_matrix = s->q_intra_matrix; ++ s->q_chroma_intra_matrix16 = s->q_intra_matrix16; ++ } ++ + s->mb_intra=0; //for the rate distortion & bit compare functions +- for(i=1; iavctx->thread_count; i++){ ++ for(i=1; ithread_context[i], s); + } + +@@ -2817,42 +3137,42 @@ + return -1; + + /* Estimate motion for every MB */ +- if(s->pict_type != FF_I_TYPE){ ++ if(s->pict_type != AV_PICTURE_TYPE_I){ + s->lambda = (s->lambda * s->avctx->me_penalty_compensation + 128)>>8; + s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; +- if(s->pict_type != FF_B_TYPE && s->avctx->me_threshold==0){ +- if((s->avctx->pre_me && s->last_non_b_pict_type==FF_I_TYPE) || s->avctx->pre_me==2){ +- s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); ++ if(s->pict_type != AV_PICTURE_TYPE_B && s->avctx->me_threshold==0){ ++ if((s->avctx->pre_me && s->last_non_b_pict_type==AV_PICTURE_TYPE_I) || s->avctx->pre_me==2){ ++ s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + } + } + +- s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); +- }else /* if(s->pict_type == FF_I_TYPE) */{ ++ s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); ++ }else /* if(s->pict_type == AV_PICTURE_TYPE_I) */{ + /* I-Frame */ + for(i=0; imb_stride*s->mb_height; i++) + s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; + + if(!s->fixed_qscale){ + /* finding spatial complexity for I-frame rate control */ +- s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); ++ s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); + } + } +- for(i=1; iavctx->thread_count; i++){ ++ for(i=1; ithread_context[i]); + } + s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; + s->current_picture. mb_var_sum= s->current_picture_ptr-> mb_var_sum= s->me. mb_var_sum_temp; + emms_c(); + +- if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == FF_P_TYPE){ +- s->pict_type= FF_I_TYPE; ++ if(s->me.scene_change_score > s->avctx->scenechange_threshold && s->pict_type == AV_PICTURE_TYPE_P){ ++ s->pict_type= AV_PICTURE_TYPE_I; + for(i=0; imb_stride*s->mb_height; i++) + s->mb_type[i]= CANDIDATE_MB_TYPE_INTRA; + //printf("Scene change detected, encoding as I Frame %d %d\n", s->current_picture.mb_var_sum, s->current_picture.mc_mb_var_sum); + } + + if(!s->umvplus){ +- if(s->pict_type==FF_P_TYPE || s->pict_type==FF_S_TYPE) { ++ if(s->pict_type==AV_PICTURE_TYPE_P || s->pict_type==AV_PICTURE_TYPE_S) { + s->f_code= ff_get_best_fcode(s, s->p_mv_table, CANDIDATE_MB_TYPE_INTER); + + if(s->flags & CODEC_FLAG_INTERLACED_ME){ +@@ -2874,7 +3194,7 @@ + } + } + +- if(s->pict_type==FF_B_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_B){ + int a, b; + + a = ff_get_best_fcode(s, s->b_forw_mv_table, CANDIDATE_MB_TYPE_FORWARD); +@@ -2908,7 +3228,7 @@ + if (estimate_qp(s, 0) < 0) + return -1; + +- if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==FF_I_TYPE && !(s->flags & CODEC_FLAG_QSCALE)) ++ if(s->qscale < 3 && s->max_qcoeff<=128 && s->pict_type==AV_PICTURE_TYPE_I && !(s->flags & CODEC_FLAG_QSCALE)) + s->qscale= 3; //reduce clipping problems + + if (s->out_format == FMT_MJPEG) { +@@ -2925,14 +3245,33 @@ + s->intra_matrix, s->intra_quant_bias, 8, 8, 1); + s->qscale= 8; + } ++ if(s->codec_id == CODEC_ID_AMV){ ++ static const uint8_t y[32]={13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13}; ++ static const uint8_t c[32]={14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14}; ++ for(i=1;i<64;i++){ ++ int j= s->dsp.idct_permutation[ff_zigzag_direct[i]]; ++ ++ s->intra_matrix[j] = sp5x_quant_table[5*2+0][i]; ++ s->chroma_intra_matrix[j] = sp5x_quant_table[5*2+1][i]; ++ } ++ s->y_dc_scale_table= y; ++ s->c_dc_scale_table= c; ++ s->intra_matrix[0] = 13; ++ s->chroma_intra_matrix[0] = 14; ++ ff_convert_matrix(&s->dsp, s->q_intra_matrix, s->q_intra_matrix16, ++ s->intra_matrix, s->intra_quant_bias, 8, 8, 1); ++ ff_convert_matrix(&s->dsp, s->q_chroma_intra_matrix, s->q_chroma_intra_matrix16, ++ s->chroma_intra_matrix, s->intra_quant_bias, 8, 8, 1); ++ s->qscale= 8; ++ } + + //FIXME var duplication +- s->current_picture_ptr->key_frame= +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; //FIXME pic_ptr +- s->current_picture_ptr->pict_type= +- s->current_picture.pict_type= s->pict_type; ++ s->current_picture_ptr->f.key_frame = ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; //FIXME pic_ptr ++ s->current_picture_ptr->f.pict_type = ++ s->current_picture.f.pict_type = s->pict_type; + +- if(s->current_picture.key_frame) ++ if (s->current_picture.f.key_frame) + s->picture_in_gop_number=0; + + s->last_bits= put_bits_count(&s->pb); +@@ -2948,7 +3287,7 @@ + case FMT_H263: + if (CONFIG_WMV2_ENCODER && s->codec_id == CODEC_ID_WMV2) + ff_wmv2_encode_picture_header(s, picture_number); +- else if (CONFIG_MSMPEG4_ENCODER && s->h263_msmpeg4) ++ else if (CONFIG_MSMPEG4_ENCODER && s->msmpeg4_version) + msmpeg4_encode_picture_header(s, picture_number); + else if (CONFIG_MPEG4_ENCODER && s->h263_pred) + mpeg4_encode_picture_header(s, picture_number); +@@ -2973,11 +3312,11 @@ + bits= put_bits_count(&s->pb); + s->header_bits= bits - s->last_bits; + +- for(i=1; iavctx->thread_count; i++){ ++ for(i=1; ithread_context[i], s); + } +- s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); +- for(i=1; iavctx->thread_count; i++){ ++ s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*)); ++ for(i=1; ithread_context[i]); + } + emms_c(); +@@ -3059,7 +3398,7 @@ + block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; +- qmat = s->q_intra_matrix[qscale]; ++ qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; + if(s->mpeg_quant || s->out_format == FMT_MPEG1) + bias= 1<<(QMAT_SHIFT-1); + length = s->intra_ac_vlc_length; +@@ -3730,7 +4069,7 @@ + block[0] = (block[0] + (q >> 1)) / q; + start_i = 1; + last_non_zero = 0; +- qmat = s->q_intra_matrix[qscale]; ++ qmat = n < 4 ? s->q_intra_matrix[qscale] : s->q_chroma_intra_matrix[qscale]; + bias= s->intra_quant_bias<<(QMAT_SHIFT - QUANT_BIAS_SHIFT); + } else { + start_i = 0; +@@ -3779,74 +4118,94 @@ + return last_non_zero; + } + ++#define OFFSET(x) offsetof(MpegEncContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption h263_options[] = { ++ { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "structured_slices","Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, ++ { NULL }, ++}; ++ ++static const AVClass h263_class = { ++ .class_name = "H.263 encoder", ++ .item_name = av_default_item_name, ++ .option = h263_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_h263_encoder = { +- "h263", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H263, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "h263", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H263, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("H.263 / H.263-1996"), ++ .priv_class = &h263_class, + }; + +-AVCodec ff_h263p_encoder = { +- "h263p", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_H263P, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, +- .long_name= NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"), ++static const AVOption h263p_options[] = { ++ { "umv", "Use unlimited motion vectors.", OFFSET(umvplus), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "aiv", "Use alternative inter VLC.", OFFSET(alt_inter_vlc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "obmc", "use overlapped block motion compensation.", OFFSET(obmc), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { "structured_slices", "Write slice start position at every GOB header instead of just GOB number.", OFFSET(h263_slice_structured), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE}, ++ { NULL }, ++}; ++static const AVClass h263p_class = { ++ .class_name = "H.263p encoder", ++ .item_name = av_default_item_name, ++ .option = h263p_options, ++ .version = LIBAVUTIL_VERSION_INT, + }; + +-AVCodec ff_msmpeg4v1_encoder = { +- "msmpeg4v1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V1, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++AVCodec ff_h263p_encoder = { ++ .name = "h263p", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H263P, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, ++ .capabilities = CODEC_CAP_SLICE_THREADS, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, +- .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"), ++ .long_name= NULL_IF_CONFIG_SMALL("H.263+ / H.263-1998 / H.263 version 2"), ++ .priv_class = &h263p_class, + }; + + AVCodec ff_msmpeg4v2_encoder = { +- "msmpeg4v2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V2, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "msmpeg4v2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V2, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), + }; + + AVCodec ff_msmpeg4v3_encoder = { +- "msmpeg4", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V3, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "msmpeg4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V3, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), + }; + + AVCodec ff_wmv1_encoder = { +- "wmv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV1, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "wmv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.h 2012-05-14 14:08:54.054334347 +0200 +@@ -28,6 +28,7 @@ + #ifndef AVCODEC_MPEGVIDEO_H + #define AVCODEC_MPEGVIDEO_H + ++#include "avcodec.h" + #include "dsputil.h" + #include "get_bits.h" + #include "put_bits.h" +@@ -35,6 +36,7 @@ + #include "parser.h" + #include "mpeg12data.h" + #include "rl.h" ++#include "timecode.h" + + #define FRAME_SKIPPED 100 ///< return value for header parsers if frame is not coded + +@@ -76,16 +78,19 @@ + #define EXT_START_CODE 0x000001b5 + #define USER_START_CODE 0x000001b2 + ++struct MpegEncContext; ++ + /** + * Picture. + */ + typedef struct Picture{ +- FF_COMMON_FRAME ++ struct AVFrame f; + + /** + * halfpel luma planes. + */ + uint8_t *interpolated[3]; ++ int8_t *qscale_table_base; + int16_t (*motion_val_base[2])[2]; + uint32_t *mb_type_base; + #define MB_TYPE_INTRA MB_TYPE_INTRA4x4 //default mb_type if there is just one type +@@ -120,9 +125,11 @@ + int pic_id; /**< h264 pic_num (short -> no wrap version of pic_num, + pic_num & max_pic_num; long -> long_pic_num) */ + int long_ref; ///< 1->long term reference 0->short term reference +- int ref_poc[2][2][16]; ///< h264 POCs of the frames used as reference (FIXME need per slice) ++ int ref_poc[2][2][32]; ///< h264 POCs of the frames/fields used as reference (FIXME need per slice) + int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice) + int mbaff; ///< h264 1 -> MBAFF frame 0-> not MBAFF ++ int field_picture; ///< whether or not the picture was encoded in seperate fields ++ int sync; ///< has been decoded after a keyframe + + int mb_var_sum; ///< sum of MB variance for current frame + int mc_mb_var_sum; ///< motion compensated MB variance for current frame +@@ -131,10 +138,9 @@ + uint8_t *mb_mean; ///< Table for MB luminance + int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decision FIXME remove + int b_frame_score; /* */ ++ struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture + } Picture; + +-struct MpegEncContext; +- + /** + * Motion estimation context. + */ +@@ -150,9 +156,9 @@ + int best_bits; + uint32_t *map; ///< map to avoid duplicate evaluations + uint32_t *score_map; ///< map to store the scores +- int map_generation; ++ unsigned map_generation; + int pre_penalty_factor; +- int penalty_factor; /*!< an estimate of the bits required to ++ int penalty_factor; /**< an estimate of the bits required to + code a given mv value, e.g. (1,0) takes + more bits than (0,0). We have to + estimate whether any reduction in +@@ -195,6 +201,7 @@ + * MpegEncContext. + */ + typedef struct MpegEncContext { ++ AVClass *class; + struct AVCodecContext *avctx; + /* the following parameters must be initialized before encoding */ + int width, height;///< picture size. must be a multiple of 16 +@@ -207,7 +214,6 @@ + + /* the following codec id fields are deprecated in favor of codec_id */ + int h263_plus; ///< h263 plus headers +- int h263_msmpeg4; ///< generate MSMPEG4 compatible stream (deprecated, use msmpeg4_version instead) + int h263_flv; ///< use flv h263 header + + enum CodecID codec_id; /* see CODEC_ID_xxx */ +@@ -230,8 +236,6 @@ + int coded_picture_number; ///< used to set pic->coded_picture_number, should not be used for/by anything else + int picture_number; //FIXME remove, unclear definition + int picture_in_gop_number; ///< 0-> first pic in gop, ... +- int b_frames_since_non_b; ///< used for encoding, relative to not yet reordered input +- int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video() + int mb_width, mb_height; ///< number of MBs horizontally & vertically + int mb_stride; ///< mb_width+1 used for some arrays to allow simple addressing of left & top MBs without sig11 + int b8_stride; ///< 2*mb_width+1 used for some 8x8 block arrays to allow simple addressing +@@ -258,12 +262,15 @@ + /* WARNING: changes above this line require updates to hardcoded + * offsets used in asm. */ + ++ int64_t user_specified_pts;///< last non zero pts from AVFrame which was passed into avcodec_encode_video() ++ + /** bit output */ + PutBitContext pb; + + int start_mb_y; ///< start mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) + int end_mb_y; ///< end mb_y of this thread (so current thread should process start_mb_y <= row < end_mb_y) + struct MpegEncContext *thread_context[MAX_THREADS]; ++ int slice_context_count; ///< number of used thread_contexts + + /** + * copy of the previous picture structure. +@@ -292,11 +299,12 @@ + Picture *last_picture_ptr; ///< pointer to the previous picture. + Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) + Picture *current_picture_ptr; ///< pointer to the current picture +- uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization ++ int picture_count; ///< number of allocated pictures (MAX_PICTURE_COUNT * avctx->thread_count) ++ int picture_range_start, picture_range_end; ///< the part of picture that this context can allocate in ++ uint8_t *visualization_buffer[3]; ///< temporary buffer vor MV visualization + int last_dc[3]; ///< last DC values for MPEG1 + int16_t *dc_val_base; + int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous +- int16_t dc_cache[4*5]; + const uint8_t *y_dc_scale_table; ///< qscale -> y_dc_scale table + const uint8_t *c_dc_scale_table; ///< qscale -> c_dc_scale table + const uint8_t *chroma_qscale_table; ///< qscale -> chroma_qscale (h263) +@@ -304,16 +312,13 @@ + uint8_t *coded_block; ///< used for coded block pattern prediction (msmpeg4v3, wmv1) + int16_t (*ac_val_base)[16]; + int16_t (*ac_val[3])[16]; ///< used for for mpeg4 AC prediction, all 3 arrays must be continuous +- uint8_t *prev_pict_types; ///< previous picture types in bitstream order, used for mb skip +-#define PREV_PICT_TYPES_BUFFER_SIZE 256 + int mb_skipped; ///< MUST BE SET only during DECODING + uint8_t *mbskip_table; /**< used to avoid copy if macroblock skipped (for black regions for example) + and used for b-frame encoding & decoding (contains skip table of next P Frame) */ + uint8_t *mbintra_table; ///< used to avoid setting {ac, dc, cbp}-pred stuff to zero on inter MB decoding + uint8_t *cbp_table; ///< used to store cbp, ac_pred for partitioned decoding + uint8_t *pred_dir_table; ///< used to store pred_dir for partitioned decoding +- uint8_t *allocated_edge_emu_buffer; +- uint8_t *edge_emu_buffer; ///< points into the middle of allocated_edge_emu_buffer ++ uint8_t *edge_emu_buffer; ///< temporary buffer for if MVs point to out-of-frame data + uint8_t *rd_scratchpad; ///< scratchpad for rate distortion mb decision + uint8_t *obmc_scratchpad; + uint8_t *b_scratchpad; ///< scratchpad used for writing into write only buffers +@@ -326,7 +331,7 @@ + int adaptive_quant; ///< use adaptive quantization + int dquant; ///< qscale difference to prev qscale + int closed_gop; ///< MPEG1/2 GOP is closed +- int pict_type; ///< FF_I_TYPE, FF_P_TYPE, FF_B_TYPE, ... ++ int pict_type; ///< AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ... + int last_pict_type; //FIXME removes + int last_non_b_pict_type; ///< used for mpeg4 gmc b-frames & ratecontrol + int dropable; +@@ -337,7 +342,6 @@ + /* motion compensation */ + int unrestricted_mv; ///< mv can point outside of the coded picture + int h263_long_vectors; ///< use horrible h263v1 long vector mode +- int decode; ///< if 0 then decoding will be skipped (for encoding b frames for example) + + DSPContext dsp; ///< pointers for accelerated dsp functions + int f_code; ///< forward MV resolution +@@ -387,9 +391,6 @@ + int no_rounding; /**< apply no rounding to motion compensation (MPEG4, msmpeg4, ...) + for b-frames rounding mode is always 0 */ + +- int hurry_up; /**< when set to 1 during decoding, b frames will be skipped +- when set to 2 idct/dequant will be skipped too */ +- + /* macroblock layer */ + int mb_x, mb_y; + int mb_skip_run; +@@ -435,16 +436,17 @@ + uint8_t *inter_ac_vlc_length; + uint8_t *inter_ac_vlc_last_length; + uint8_t *luma_dc_vlc_length; +- uint8_t *chroma_dc_vlc_length; + #define UNI_AC_ENC_INDEX(run,level) ((run)*128 + (level)) + + int coded_score[8]; + + /** precomputed matrix (combine qscale and DCT renorm) */ + int (*q_intra_matrix)[64]; ++ int (*q_chroma_intra_matrix)[64]; + int (*q_inter_matrix)[64]; + /** identical to the above but for MMX & these are not permutated, second 64 entries are bias*/ + uint16_t (*q_intra_matrix16)[2][64]; ++ uint16_t (*q_chroma_intra_matrix16)[2][64]; + uint16_t (*q_inter_matrix16)[2][64]; + + /* noise reduction */ +@@ -455,7 +457,6 @@ + void *opaque; ///< private data for the user + + /* bit rate control */ +- int64_t wanted_bits; + int64_t total_bits; + int frame_bits; ///< bits used for the current frame + int next_lambda; ///< next lambda used for retrying to encode a frame +@@ -474,23 +475,25 @@ + int last_bits; ///< temp var used for calculating the above vars + + /* error concealment / resync */ +- int error_count; ++ int error_count, error_occurred; + uint8_t *error_status_table; ///< table of the error status of each MB + #define VP_START 1 ///< current MB is the first after a resync marker +-#define AC_ERROR 2 +-#define DC_ERROR 4 +-#define MV_ERROR 8 +-#define AC_END 16 +-#define DC_END 32 +-#define MV_END 64 +-//FIXME some prefix? ++#define ER_AC_ERROR 2 ++#define ER_DC_ERROR 4 ++#define ER_MV_ERROR 8 ++#define ER_AC_END 16 ++#define ER_DC_END 32 ++#define ER_MV_END 64 ++ ++#define ER_MB_ERROR (ER_AC_ERROR|ER_DC_ERROR|ER_MV_ERROR) ++#define ER_MB_END (ER_AC_END|ER_DC_END|ER_MV_END) + + int resync_mb_x; ///< x position of last resync marker + int resync_mb_y; ///< y position of last resync marker + GetBitContext last_resync_gb; ///< used to search for the next resync marker + int mb_num_left; ///< number of MBs left in this video packet (for partitioned Slices only) + int next_p_frame_damaged; ///< set if the next p frame is damaged, to avoid showing trashed b frames +- int error_recognition; ++ int err_recognition; + + ParseContext parse_context; + +@@ -640,10 +643,14 @@ + int interlaced_dct; + int first_slice; + int first_field; ///< is 1 for the first field of a field picture 0 otherwise ++ int drop_frame_timecode; ///< timecode is in drop frame format. ++ int scan_offset; ///< reserve space for SVCD scan offset user data. + + /* RTP specific */ + int rtp_mode; + ++ struct ff_timecode tc; ++ + uint8_t *ptr_lastgob; + int swap_uv; //vcr2 codec is an MPEG-2 variant with U and V swapped + DCTELEM (*pblocks[12])[64]; +@@ -681,6 +688,10 @@ + void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block); + } MpegEncContext; + ++#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \ ++ (pic >= old_ctx->picture && pic < old_ctx->picture+old_ctx->picture_count ?\ ++ &new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\ ++ : NULL) + + void MPV_decode_defaults(MpegEncContext *s); + int MPV_common_init(MpegEncContext *s); +@@ -703,10 +714,14 @@ + void ff_mpeg_flush(AVCodecContext *avctx); + void ff_print_debug_info(MpegEncContext *s, AVFrame *pict); + void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix); ++void ff_release_unused_pictures(MpegEncContext *s, int remove_current); + int ff_find_unused_picture(MpegEncContext *s, int shared); + void ff_denoise_dct(MpegEncContext *s, DCTELEM *block); + void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); +-const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); ++int MPV_lowest_referenced_row(MpegEncContext *s, int dir); ++void MPV_report_decode_progress(MpegEncContext *s); ++int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); ++const uint8_t *avpriv_mpv_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); + void ff_set_qscale(MpegEncContext * s, int qscale); + + void ff_er_frame_start(MpegEncContext *s); +@@ -721,8 +736,8 @@ + void ff_copy_picture(Picture *dst, Picture *src); + + /** +- * allocates a Picture +- * The pixels are allocated/set by calling get_buffer() if shared=0 ++ * Allocate a Picture. ++ * The pixels are allocated/set by calling get_buffer() if shared = 0. + */ + int ff_alloc_picture(MpegEncContext *s, Picture *pic, int shared); + +@@ -834,4 +849,3 @@ + int motion_x, int motion_y); + + #endif /* AVCODEC_MPEGVIDEO_H */ +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_parser.c 2012-05-14 14:08:54.069334649 +0200 +@@ -32,7 +32,7 @@ + uint32_t start_code; + int frame_rate_index, ext_type, bytes_left; + int frame_rate_ext_n, frame_rate_ext_d; +- int picture_structure, top_field_first, repeat_first_field, progressive_frame; ++ int top_field_first, repeat_first_field, progressive_frame; + int horiz_size_ext, vert_size_ext, bit_rate_ext; + int did_set_size=0; + //FIXME replace the crap with get_bits() +@@ -40,7 +40,7 @@ + + while (buf < buf_end) { + start_code= -1; +- buf= ff_find_start_code(buf, buf_end, &start_code); ++ buf= avpriv_mpv_find_start_code(buf, buf_end, &start_code); + bytes_left = buf_end - buf; + switch(start_code) { + case PICTURE_START_CODE: +@@ -57,8 +57,8 @@ + did_set_size=1; + } + frame_rate_index = buf[3] & 0xf; +- pc->frame_rate.den = avctx->time_base.den = ff_frame_rate_tab[frame_rate_index].num; +- pc->frame_rate.num = avctx->time_base.num = ff_frame_rate_tab[frame_rate_index].den; ++ pc->frame_rate.den = avctx->time_base.den = avpriv_frame_rate_tab[frame_rate_index].num; ++ pc->frame_rate.num = avctx->time_base.num = avpriv_frame_rate_tab[frame_rate_index].den; + avctx->bit_rate = ((buf[4]<<10) | (buf[5]<<2) | (buf[6]>>6))*400; + avctx->codec_id = CODEC_ID_MPEG1VIDEO; + avctx->sub_id = 1; +@@ -91,7 +91,6 @@ + break; + case 0x8: /* picture coding extension */ + if (bytes_left >= 5) { +- picture_structure = buf[2]&3; + top_field_first = buf[3] & (1 << 7); + repeat_first_field = buf[3] & (1 << 1); + progressive_frame = buf[4] & (1 << 7); +@@ -152,10 +151,8 @@ + to have the full timing information. The time take by this + function should be negligible for uncorrupted streams */ + mpegvideo_extract_headers(s, avctx, buf, buf_size); +-#if 0 +- printf("pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", +- s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict); +-#endif ++ av_dlog(NULL, "pict_type=%d frame_rate=%0.3f repeat_pict=%d\n", ++ s->pict_type, (double)avctx->time_base.den / avctx->time_base.num, s->repeat_pict); + + *poutbuf = buf; + *poutbuf_size = buf_size; +@@ -167,20 +164,22 @@ + { + int i; + uint32_t state= -1; ++ int found=0; + + for(i=0; i= 0x100) ++ if(state == 0x1B3){ ++ found=1; ++ }else if(found && state != 0x1B5 && state < 0x200 && state >= 0x100) + return i-3; + } + return 0; + } + + AVCodecParser ff_mpegvideo_parser = { +- { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, +- sizeof(ParseContext1), +- NULL, +- mpegvideo_parse, +- ff_parse1_close, +- mpegvideo_split, ++ .codec_ids = { CODEC_ID_MPEG1VIDEO, CODEC_ID_MPEG2VIDEO }, ++ .priv_data_size = sizeof(ParseContext1), ++ .parser_parse = mpegvideo_parse, ++ .parser_close = ff_parse1_close, ++ .split = mpegvideo_split, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_xvmc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_xvmc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mpegvideo_xvmc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo_xvmc.c 2012-05-14 14:08:54.069334649 +0200 +@@ -41,7 +41,7 @@ + */ + void ff_xvmc_init_block(MpegEncContext *s) + { +- struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.data[2]; ++ struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; + assert(render && render->xvmc_id == AV_XVMC_ID); + + s->block = (DCTELEM (*)[64])(render->data_blocks + render->next_free_data_block_num * 64); +@@ -73,7 +73,7 @@ + */ + int ff_xvmc_field_start(MpegEncContext *s, AVCodecContext *avctx) + { +- struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.data[2]; ++ struct xvmc_pix_fmt *last, *next, *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; + const int mb_block_count = 4 + (1 << s->chroma_format); + + assert(avctx); +@@ -110,18 +110,18 @@ + render->p_past_surface = NULL; + + switch(s->pict_type) { +- case FF_I_TYPE: ++ case AV_PICTURE_TYPE_I: + return 0; // no prediction from other frames +- case FF_B_TYPE: +- next = (struct xvmc_pix_fmt*)s->next_picture.data[2]; ++ case AV_PICTURE_TYPE_B: ++ next = (struct xvmc_pix_fmt*)s->next_picture.f.data[2]; + if (!next) + return -1; + if (next->xvmc_id != AV_XVMC_ID) + return -1; + render->p_future_surface = next->p_surface; + // no return here, going to set forward prediction +- case FF_P_TYPE: +- last = (struct xvmc_pix_fmt*)s->last_picture.data[2]; ++ case AV_PICTURE_TYPE_P: ++ last = (struct xvmc_pix_fmt*)s->last_picture.f.data[2]; + if (!last) + last = render; // predict second field from the first + if (last->xvmc_id != AV_XVMC_ID) +@@ -141,7 +141,7 @@ + */ + void ff_xvmc_field_end(MpegEncContext *s) + { +- struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.data[2]; ++ struct xvmc_pix_fmt *render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; + assert(render); + + if (render->filled_mv_blocks_num > 0) +@@ -179,10 +179,10 @@ + + // Do I need to export quant when I could not perform postprocessing? + // Anyway, it doesn't hurt. +- s->current_picture.qscale_table[mb_xy] = s->qscale; ++ s->current_picture.f.qscale_table[mb_xy] = s->qscale; + + // start of XVMC-specific code +- render = (struct xvmc_pix_fmt*)s->current_picture.data[2]; ++ render = (struct xvmc_pix_fmt*)s->current_picture.f.data[2]; + assert(render); + assert(render->xvmc_id == AV_XVMC_ID); + assert(render->mv_blocks); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqc.c 2012-05-14 14:08:54.070334669 +0200 +@@ -0,0 +1,108 @@ ++/* ++ * MQ-coder encoder and decoder common functions ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * MQ-coder ecoder and decoder common functions ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "mqc.h" ++ ++typedef struct { ++ uint16_t qe; ++ uint8_t nmps; ++ uint8_t nlps; ++ uint8_t sw; ++} MqcCxState; ++ ++const static MqcCxState cx_states[47] = { ++ {0x5601, 1, 1, 1}, ++ {0x3401, 2, 6, 0}, ++ {0x1801, 3, 9, 0}, ++ {0x0AC1, 4, 12, 0}, ++ {0x0521, 5, 29, 0}, ++ {0x0221, 38, 33, 0}, ++ {0x5601, 7, 6, 1}, ++ {0x5401, 8, 14, 0}, ++ {0x4801, 9, 14, 0}, ++ {0x3801, 10, 14, 0}, ++ {0x3001, 11, 17, 0}, ++ {0x2401, 12, 18, 0}, ++ {0x1C01, 13, 20, 0}, ++ {0x1601, 29, 21, 0}, ++ {0x5601, 15, 14, 1}, ++ {0x5401, 16, 14, 0}, ++ {0x5101, 17, 15, 0}, ++ {0x4801, 18, 16, 0}, ++ {0x3801, 19, 17, 0}, ++ {0x3401, 20, 18, 0}, ++ {0x3001, 21, 19, 0}, ++ {0x2801, 22, 19, 0}, ++ {0x2401, 23, 20, 0}, ++ {0x2201, 24, 21, 0}, ++ {0x1C01, 25, 22, 0}, ++ {0x1801, 26, 23, 0}, ++ {0x1601, 27, 24, 0}, ++ {0x1401, 28, 25, 0}, ++ {0x1201, 29, 26, 0}, ++ {0x1101, 30, 27, 0}, ++ {0x0AC1, 31, 28, 0}, ++ {0x09C1, 32, 29, 0}, ++ {0x08A1, 33, 30, 0}, ++ {0x0521, 34, 31, 0}, ++ {0x0441, 35, 32, 0}, ++ {0x02A1, 36, 33, 0}, ++ {0x0221, 37, 34, 0}, ++ {0x0141, 38, 35, 0}, ++ {0x0111, 39, 36, 0}, ++ {0x0085, 40, 37, 0}, ++ {0x0049, 41, 38, 0}, ++ {0x0025, 42, 39, 0}, ++ {0x0015, 43, 40, 0}, ++ {0x0009, 44, 41, 0}, ++ {0x0005, 45, 42, 0}, ++ {0x0001, 45, 43, 0}, ++ {0x5601, 46, 46, 0} ++}; ++ ++uint16_t ff_mqc_qe [2*47]; ++uint8_t ff_mqc_nlps[2*47]; ++uint8_t ff_mqc_nmps[2*47]; ++ ++void ff_mqc_init_contexts(MqcState *mqc) ++{ ++ int i; ++ memset(mqc->cx_states, 0, sizeof(mqc->cx_states)); ++ mqc->cx_states[MQC_CX_UNI] = 2 * 46; ++ mqc->cx_states[MQC_CX_RL] = 2 * 3; ++ mqc->cx_states[0] = 2 * 4; ++ ++ for (i = 0; i < 47; i++){ ++ ff_mqc_qe[2*i ] = ++ ff_mqc_qe[2*i+1] = cx_states[i].qe; ++ ++ ff_mqc_nlps[2*i ] = 2*cx_states[i].nlps + cx_states[i].sw; ++ ff_mqc_nlps[2*i+1] = 2*cx_states[i].nlps + 1 - cx_states[i].sw; ++ ff_mqc_nmps[2*i ] = 2*cx_states[i].nmps; ++ ff_mqc_nmps[2*i+1] = 2*cx_states[i].nmps + 1; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqcdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqcdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqcdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqcdec.c 2012-05-14 14:08:54.071334689 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * MQ-coder decoder ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * MQ-coder decoder ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "mqc.h" ++ ++static void bytein(MqcState *mqc) ++{ ++ if (*mqc->bp == 0xff){ ++ if (*(mqc->bp+1) > 0x8f) ++ mqc->c++; ++ else{ ++ mqc->bp++; ++ mqc->c += 2 + 0xfe00 - (*mqc->bp << 9); ++ } ++ } else{ ++ mqc->bp++; ++ mqc->c += 1 + 0xff00 - (*mqc->bp << 8); ++ } ++} ++ ++static int exchange(MqcState *mqc, uint8_t *cxstate, int lps) ++{ ++ int d; ++ if ((mqc->a < ff_mqc_qe[*cxstate]) ^ (!lps)){ ++ if (lps) ++ mqc->a = ff_mqc_qe[*cxstate]; ++ d = *cxstate & 1; ++ *cxstate = ff_mqc_nmps[*cxstate]; ++ } else{ ++ if (lps) ++ mqc->a = ff_mqc_qe[*cxstate]; ++ d = 1 - (*cxstate & 1); ++ *cxstate = ff_mqc_nlps[*cxstate]; ++ } ++ // renormd: ++ do{ ++ if (!(mqc->c & 0xff)){ ++ mqc->c -= 0x100; ++ bytein(mqc); ++ } ++ mqc->a += mqc->a; ++ mqc->c += mqc->c; ++ } while (!(mqc->a & 0x8000)); ++ return d; ++} ++ ++void ff_mqc_initdec(MqcState *mqc, uint8_t *bp) ++{ ++ ff_mqc_init_contexts(mqc); ++ mqc->bp = bp; ++ mqc->c = (*mqc->bp ^ 0xff) << 16; ++ bytein(mqc); ++ mqc->c = mqc->c << 7; ++ mqc->a = 0x8000; ++} ++ ++int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate) ++{ ++ mqc->a -= ff_mqc_qe[*cxstate]; ++ if ((mqc->c >> 16) < mqc->a){ ++ if (mqc->a & 0x8000) ++ return *cxstate & 1; ++ else ++ return exchange(mqc, cxstate, 0); ++ } else { ++ mqc->c -= mqc->a << 16; ++ return exchange(mqc, cxstate, 1); ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqcenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqcenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqcenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqcenc.c 2012-05-14 14:08:54.072334709 +0200 +@@ -0,0 +1,119 @@ ++/* ++ * MQ-coder encoder ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * MQ-coder encoder ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "mqc.h" ++ ++static void byteout(MqcState *mqc) ++{ ++retry: ++ if (*mqc->bp == 0xff){ ++ mqc->bp++; ++ *mqc->bp = mqc->c >> 20; ++ mqc->c &= 0xfffff; ++ mqc->ct = 7; ++ } else if ((mqc->c & 0x8000000)){ ++ (*mqc->bp)++; ++ mqc->c &= 0x7ffffff; ++ goto retry; ++ } else{ ++ mqc->bp++; ++ *mqc->bp = mqc->c >> 19; ++ mqc->c &= 0x7ffff; ++ mqc->ct = 8; ++ } ++} ++ ++static void renorme(MqcState *mqc) ++{ ++ do{ ++ mqc->a += mqc->a; ++ mqc->c += mqc->c; ++ if (!--mqc->ct) ++ byteout(mqc); ++ } while (!(mqc->a & 0x8000)); ++} ++ ++static void setbits(MqcState *mqc) ++{ ++ int tmp = mqc->c + mqc->a; ++ mqc->c |= 0xffff; ++ if (mqc->c >= tmp) ++ mqc->c -= 0x8000; ++} ++ ++void ff_mqc_initenc(MqcState *mqc, uint8_t *bp) ++{ ++ ff_mqc_init_contexts(mqc); ++ mqc->a = 0x8000; ++ mqc->c = 0; ++ mqc->bp = bp-1; ++ mqc->bpstart = bp; ++ mqc->ct = 12 + (*mqc->bp == 0xff); ++} ++ ++void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d) ++{ ++ int qe; ++ ++ qe = ff_mqc_qe[*cxstate]; ++ mqc->a -= qe; ++ if ((*cxstate & 1) == d){ ++ if (!(mqc->a & 0x8000)){ ++ if (mqc->a < qe) ++ mqc->a = qe; ++ else ++ mqc->c += qe; ++ *cxstate = ff_mqc_nmps[*cxstate]; ++ renorme(mqc); ++ } else ++ mqc->c += qe; ++ } else{ ++ if (mqc->a < qe) ++ mqc->c += qe; ++ else ++ mqc->a = qe; ++ *cxstate = ff_mqc_nlps[*cxstate]; ++ renorme(mqc); ++ } ++} ++ ++int ff_mqc_length(MqcState *mqc) ++{ ++ return mqc->bp - mqc->bpstart; ++} ++ ++int ff_mqc_flush(MqcState *mqc) ++{ ++ setbits(mqc); ++ mqc->c = mqc->c << mqc->ct; ++ byteout(mqc); ++ mqc->c = mqc->c << mqc->ct; ++ byteout(mqc); ++ if (*mqc->bp != 0xff) ++ mqc->bp++; ++ return mqc->bp - mqc->bpstart; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mqc.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mqc.h 2012-05-14 14:08:54.071334689 +0200 +@@ -0,0 +1,75 @@ ++/* ++ * MQ-coder ++ * Copyright (c) 2007 Kamil Nowosad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_MQC_H ++#define AVCODEC_MQC_H ++ ++/** ++ * MQ-coder ++ * @file ++ * @author Kamil Nowosad ++ */ ++ ++#include "avcodec.h" ++ ++#define MQC_CX_UNI 17 ++#define MQC_CX_RL 18 ++ ++extern uint16_t ff_mqc_qe[2*47]; ++extern uint8_t ff_mqc_nlps[2*47]; ++extern uint8_t ff_mqc_nmps[2*47]; ++ ++typedef struct { ++ uint8_t *bp, *bpstart; ++ unsigned int a; ++ unsigned int c; ++ unsigned int ct; ++ uint8_t cx_states[19]; ++} MqcState; ++ ++/* encoder */ ++ ++/** initialize the encoder */ ++void ff_mqc_initenc(MqcState *mqc, uint8_t *bp); ++ ++/** code bit d with context cx */ ++void ff_mqc_encode(MqcState *mqc, uint8_t *cxstate, int d); ++ ++/** number of encoded bytes */ ++int ff_mqc_length(MqcState *mqc); ++ ++/** flush the encoder [returns number of bytes encoded] */ ++int ff_mqc_flush(MqcState *mqc); ++ ++/* decoder */ ++ ++/** initialize the decoder */ ++void ff_mqc_initdec(MqcState *mqc, uint8_t *bp); ++ ++/** returns decoded bit with context cx */ ++int ff_mqc_decode(MqcState *mqc, uint8_t *cxstate); ++ ++/* common */ ++ ++/** initialize the contexts */ ++void ff_mqc_init_contexts(MqcState *mqc); ++ ++#endif /* AVCODEC_MQC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msgsmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msgsmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msgsmdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msgsmdec.c 2012-05-14 14:08:54.072334709 +0200 +@@ -19,9 +19,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "msgsmdec.h" ++#include "gsm.h" + #include "gsmdec_template.c" + + int ff_msgsm_decode_block(AVCodecContext *avctx, int16_t *samples, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msgsmdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msgsmdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msgsmdec.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msgsmdec.h 2012-05-14 14:08:54.073334729 +0200 +@@ -19,12 +19,12 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef MSGSMDEC_H +-#define MSGSMDEC_H ++#ifndef AVCODEC_MSGSMDEC_H ++#define AVCODEC_MSGSMDEC_H + + #include "avcodec.h" + + int ff_msgsm_decode_block(AVCodecContext *avctx, int16_t *samples, + const uint8_t *buf); + +-#endif ++#endif /* AVCODEC_MSGSMDEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4.c 2012-05-14 14:08:54.076334789 +0200 +@@ -1,5 +1,5 @@ + /* +- * MSMPEG4 backend for ffmpeg encoder and decoder ++ * MSMPEG4 backend for encoder and decoder + * Copyright (c) 2001 Fabrice Bellard + * Copyright (c) 2002-2004 Michael Niedermayer + * +@@ -24,7 +24,7 @@ + + /** + * @file +- * MSMPEG4 backend for ffmpeg encoder and decoder. ++ * MSMPEG4 backend for encoder and decoder + */ + + #include "avcodec.h" +@@ -62,10 +62,6 @@ + /* vc1 externs */ + extern const uint8_t wmv3_dc_scale_table[32]; + +-#ifdef DEBUG +-int frame_count = 0; +-#endif +- + #include "msmpeg4data.h" + + #if CONFIG_ENCODERS //strangely gcc includes this even if it is not referenced +@@ -270,7 +266,7 @@ + + for(i=0; iac_stats[1][0][level][run][last]; + int intra_chroma_count= s->ac_stats[1][1][level][run][last]; + +- if(s->pict_type==FF_I_TYPE){ ++ if(s->pict_type==AV_PICTURE_TYPE_I){ + size += intra_luma_count *rl_length[i ][level][run][last]; + chroma_size+= intra_chroma_count*rl_length[i+3][level][run][last]; + }else{ +@@ -333,7 +329,7 @@ + // printf("type:%d, best:%d, qp:%d, var:%d, mcvar:%d, size:%d //\n", + // s->pict_type, best, s->qscale, s->mb_var_sum, s->mc_mb_var_sum, best_size); + +- if(s->pict_type==FF_P_TYPE) chroma_best= best; ++ if(s->pict_type==AV_PICTURE_TYPE_P) chroma_best= best; + + memset(s->ac_stats, 0, sizeof(int)*(MAX_LEVEL+1)*(MAX_RUN+1)*2*2*2); + +@@ -342,7 +338,7 @@ + + if(s->pict_type != s->last_non_b_pict_type){ + s->rl_table_index= 2; +- if(s->pict_type==FF_I_TYPE) ++ if(s->pict_type==AV_PICTURE_TYPE_I) + s->rl_chroma_table_index= 1; + else + s->rl_chroma_table_index= 2; +@@ -355,7 +351,7 @@ + { + find_best_tables(s); + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + put_bits(&s->pb, 2, s->pict_type - 1); + + put_bits(&s->pb, 5, s->qscale); +@@ -369,10 +365,10 @@ + s->use_skip_mb_code = 1; /* only if P frame */ + s->per_mb_rl_table = 0; + if(s->msmpeg4_version==4) +- s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==FF_P_TYPE); ++ s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=II_BITRATE && s->pict_type==AV_PICTURE_TYPE_P); + //printf("%d %d %d %d %d\n", s->pict_type, s->bit_rate, s->inter_intra_pred, s->width, s->height); + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + s->slice_height= s->mb_height/1; + put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height); + +@@ -617,13 +613,9 @@ + } + coded_cbp |= val << (5 - i); + } +-#if 0 +- if (coded_cbp) +- printf("cbp=%x %x\n", cbp, coded_cbp); +-#endif + + if(s->msmpeg4_version<=2){ +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + put_bits(&s->pb, + v2_intra_cbpc[cbp&3][1], v2_intra_cbpc[cbp&3][0]); + } else { +@@ -638,7 +630,7 @@ + ff_h263_cbpy_tab[cbp>>2][1], + ff_h263_cbpy_tab[cbp>>2][0]); + }else{ +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + put_bits(&s->pb, + ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); + } else { +@@ -784,10 +776,10 @@ + }else{ + if(n<4){ + wrap= s->linesize; +- dest= s->current_picture.data[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8; ++ dest= s->current_picture.f.data[0] + (((n >> 1) + 2*s->mb_y) * 8* wrap ) + ((n & 1) + 2*s->mb_x) * 8; + }else{ + wrap= s->uvlinesize; +- dest= s->current_picture.data[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8; ++ dest= s->current_picture.f.data[n - 3] + (s->mb_y * 8 * wrap) + s->mb_x * 8; + } + if(s->mb_x==0) a= (1024 + (scale>>1))/scale; + else a= get_dc(dest-8, wrap, scale*8); +@@ -850,22 +842,14 @@ + int pred, extquant; + int extrabits = 0; + +- if(s->msmpeg4_version==1){ +- int32_t *dc_val; +- pred = msmpeg4v1_pred_dc(s, n, &dc_val); +- +- /* update predictor */ +- *dc_val= level; +- }else{ +- int16_t *dc_val; +- pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); ++ int16_t *dc_val; ++ pred = msmpeg4_pred_dc(s, n, &dc_val, dir_ptr); + +- /* update predictor */ +- if (n < 4) { +- *dc_val = level * s->y_dc_scale; +- } else { +- *dc_val = level * s->c_dc_scale; +- } ++ /* update predictor */ ++ if (n < 4) { ++ *dc_val = level * s->y_dc_scale; ++ } else { ++ *dc_val = level * s->c_dc_scale; + } + + /* do the prediction */ +@@ -985,10 +969,9 @@ + if(level<=MAX_LEVEL && run<=MAX_RUN){ + s->ac_stats[s->mb_intra][n>3][level][run][last]++; + } +-#if 0 +-else +- s->ac_stats[s->mb_intra][n>3][40][63][0]++; //esc3 like +-#endif ++ ++ s->ac_stats[s->mb_intra][n > 3][40][63][0]++; //esc3 like ++ + code = get_rl_index(rl, last, run, level); + put_bits(&s->pb, rl->table_vlc[code][1], rl->table_vlc[code][0]); + if (code == rl->n) { +@@ -1099,7 +1082,7 @@ + { + int cbp, code, i; + +- if (s->pict_type == FF_P_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { + if (s->use_skip_mb_code) { + if (get_bits1(&s->gb)) { + /* skip mb */ +@@ -1166,7 +1149,7 @@ + } else{ + s->ac_pred = 0; + cbp|= get_vlc2(&s->gb, ff_h263_cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors +- if(s->pict_type==FF_P_TYPE) cbp^=0x3C; ++ if(s->pict_type==AV_PICTURE_TYPE_P) cbp^=0x3C; + } + } + +@@ -1185,9 +1168,9 @@ + { + int cbp, code, i; + uint8_t *coded_val; +- uint32_t * const mb_type_ptr= &s->current_picture.mb_type[ s->mb_x + s->mb_y*s->mb_stride ]; ++ uint32_t * const mb_type_ptr = &s->current_picture.f.mb_type[s->mb_x + s->mb_y*s->mb_stride]; + +- if (s->pict_type == FF_P_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { + if (s->use_skip_mb_code) { + if (get_bits1(&s->gb)) { + /* skip mb */ +@@ -1279,7 +1262,8 @@ + int i; + MVTable *mv; + +- ff_h263_decode_init(avctx); ++ if (ff_h263_decode_init(avctx) < 0) ++ return -1; + + common_init(s); + +@@ -1383,17 +1367,6 @@ + { + int code; + +-#if 0 +-{ +-int i; +-for(i=0; igb.size_in_bits; i++) +- av_log(s->avctx, AV_LOG_DEBUG, "%d", get_bits1(&s->gb)); +-// get_bits1(&s->gb); +-av_log(s->avctx, AV_LOG_DEBUG, "END\n"); +-return -1; +-} +-#endif +- + if(s->msmpeg4_version==1){ + int start_code = get_bits_long(&s->gb, 32); + if(start_code!=0x00000100){ +@@ -1405,15 +1378,15 @@ + } + + s->pict_type = get_bits(&s->gb, 2) + 1; +- if (s->pict_type != FF_I_TYPE && +- s->pict_type != FF_P_TYPE){ ++ if (s->pict_type != AV_PICTURE_TYPE_I && ++ s->pict_type != AV_PICTURE_TYPE_P){ + av_log(s->avctx, AV_LOG_ERROR, "invalid picture type\n"); + return -1; + } + #if 0 + { + static int had_i=0; +- if(s->pict_type == FF_I_TYPE) had_i=1; ++ if(s->pict_type == AV_PICTURE_TYPE_I) had_i=1; + if(!had_i) return -1; + } + #endif +@@ -1423,7 +1396,7 @@ + return -1; + } + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + code = get_bits(&s->gb, 5); + if(s->msmpeg4_version==1){ + if(code==0 || code>s->mb_height){ +@@ -1551,9 +1524,7 @@ + /* the alt_bitstream reader could read over the end so we need to check it */ + if(left>=length && leftgb, 5); ++ skip_bits(&s->gb, 5); /* fps */ + s->bit_rate= get_bits(&s->gb, 11)*1024; + if(s->msmpeg4_version>=3) + s->flipflop_rounding= get_bits1(&s->gb); +@@ -1720,7 +1691,7 @@ + if(s->msmpeg4_version<=3){ + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); +- level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8); ++ level= SHOW_SBITS(re, &s->gb, 8); + SKIP_COUNTER(re, &s->gb, 1+6+8); + }else{ + int sign; +@@ -1839,7 +1810,7 @@ + i-= 192; + if(i&(~63)){ + const int left= get_bits_left(&s->gb); +- if(((i+192 == 64 && level/qmul==-1) || s->error_recognition<=1) && left>=0){ ++ if(((i+192 == 64 && level/qmul==-1) || !(s->err_recognition&(AV_EF_BITSTREAM|AV_EF_COMPLIANT))) && left>=0){ + av_log(s->avctx, AV_LOG_ERROR, "ignoring overflow at %d %d\n", s->mb_x, s->mb_y); + break; + }else{ +@@ -1909,60 +1880,56 @@ + } + + AVCodec ff_msmpeg4v1_decoder = { +- "msmpeg4v1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V1, +- sizeof(MpegEncContext), +- ff_msmpeg4_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "msmpeg4v1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_msmpeg4_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 1"), + .pix_fmts= ff_pixfmt_list_420, + }; + + AVCodec ff_msmpeg4v2_decoder = { +- "msmpeg4v2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V2, +- sizeof(MpegEncContext), +- ff_msmpeg4_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "msmpeg4v2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V2, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_msmpeg4_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 2"), + .pix_fmts= ff_pixfmt_list_420, + }; + + AVCodec ff_msmpeg4v3_decoder = { +- "msmpeg4", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSMPEG4V3, +- sizeof(MpegEncContext), +- ff_msmpeg4_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "msmpeg4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSMPEG4V3, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_msmpeg4_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2 Microsoft variant version 3"), + .pix_fmts= ff_pixfmt_list_420, + }; + + AVCodec ff_wmv1_decoder = { +- "wmv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV1, +- sizeof(MpegEncContext), +- ff_msmpeg4_decode_init, +- NULL, +- ff_h263_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, ++ .name = "wmv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = ff_msmpeg4_decode_init, ++ .close = ff_h263_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .max_lowres= 3, + .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 7"), + .pix_fmts= ff_pixfmt_list_420, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4data.c 2012-05-14 14:08:54.078334829 +0200 +@@ -1,5 +1,5 @@ + /* +- * MSMPEG4 backend for ffmpeg encoder and decoder ++ * MSMPEG4 backend for encoder and decoder + * copyright (c) 2001 Fabrice Bellard + * copyright (c) 2002-2004 Michael Niedermayer + * +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4data.h 2012-05-14 14:08:54.078334829 +0200 +@@ -1,5 +1,5 @@ + /* +- * MSMPEG4 backend for ffmpeg encoder and decoder ++ * MSMPEG4 backend for encoder and decoder + * copyright (c) 2001 Fabrice Bellard + * copyright (c) 2002-2004 Michael Niedermayer + * +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msmpeg4.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msmpeg4.h 2012-05-14 14:08:54.076334789 +0200 +@@ -1,5 +1,5 @@ + /* +- * MSMPEG4 backend for ffmpeg encoder and decoder ++ * MSMPEG4 backend for encoder and decoder + * copyright (c) 2007 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -19,10 +19,6 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/** +- * @file +- */ +- + #ifndef AVCODEC_MSMPEG4_H + #define AVCODEC_MSMPEG4_H + +@@ -54,8 +50,7 @@ + CONFIG_MSMPEG4V3_DECODER || \ + CONFIG_WMV2_DECODER || \ + CONFIG_VC1_DECODER) +-#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V1_ENCODER || \ +- CONFIG_MSMPEG4V2_ENCODER || \ ++#define CONFIG_MSMPEG4_ENCODER (CONFIG_MSMPEG4V2_ENCODER || \ + CONFIG_MSMPEG4V3_ENCODER || \ + CONFIG_WMV2_ENCODER) + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msrle.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msrle.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msrle.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msrle.c 2012-05-14 14:08:54.079334849 +0200 +@@ -1,5 +1,5 @@ + /* +- * Micrsoft RLE Video Decoder ++ * Microsoft RLE video decoder + * Copyright (C) 2003 the ffmpeg project + * + * This file is part of FFmpeg. +@@ -21,14 +21,11 @@ + + /** + * @file +- * MS RLE Video Decoder by Mike Melanson (melanson@pcisys.net) ++ * MS RLE video decoder by Mike Melanson (melanson@pcisys.net) + * For more information about the MS RLE format, visit: + * http://www.pcisys.net/~melanson/codecs/ + * + * The MS RLE decoder outputs PAL8 colorspace data. +- * +- * Note that this decoder expects the palette colors from the end of the +- * BITMAPINFO header passed through palctrl. + */ + + #include +@@ -46,6 +43,7 @@ + const unsigned char *buf; + int size; + ++ uint32_t pal[256]; + } MsrleContext; + + static av_cold int msrle_decode_init(AVCodecContext *avctx) +@@ -55,6 +53,9 @@ + s->avctx = avctx; + + switch (avctx->bits_per_coded_sample) { ++ case 1: ++ avctx->pix_fmt = PIX_FMT_MONOWHITE; ++ break; + case 4: + case 8: + avctx->pix_fmt = PIX_FMT_PAL8; +@@ -67,6 +68,7 @@ + return -1; + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -84,25 +86,28 @@ + s->buf = buf; + s->size = buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + +- if (s->avctx->palctrl) { +- /* make the palette available */ +- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (s->avctx->palctrl->palette_changed) { ++ if (avctx->bits_per_coded_sample > 1 && avctx->bits_per_coded_sample <= 8) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ ++ if (pal) { + s->frame.palette_has_changed = 1; +- s->avctx->palctrl->palette_changed = 0; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); + } ++ ++ /* make the palette available */ ++ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + } + + /* FIXME how to correctly detect RLE ??? */ + if (avctx->height * istride == avpkt->size) { /* assume uncompressed */ +- int linesize = avctx->width * avctx->bits_per_coded_sample / 8; ++ int linesize = (avctx->width * avctx->bits_per_coded_sample + 7) / 8; + uint8_t *ptr = s->frame.data[0]; + uint8_t *buf = avpkt->data + (avctx->height-1)*istride; + int i, j; +@@ -144,14 +149,13 @@ + } + + AVCodec ff_msrle_decoder = { +- "msrle", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSRLE, +- sizeof(MsrleContext), +- msrle_decode_init, +- NULL, +- msrle_decode_end, +- msrle_decode_frame, +- CODEC_CAP_DR1, ++ .name = "msrle", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSRLE, ++ .priv_data_size = sizeof(MsrleContext), ++ .init = msrle_decode_init, ++ .close = msrle_decode_end, ++ .decode = msrle_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("Microsoft RLE"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msrledec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msrledec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msrledec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msrledec.c 2012-05-14 14:08:54.080334869 +0200 +@@ -138,9 +138,9 @@ + uint32_t av_uninit(pix32); + unsigned int width= FFABS(pic->linesize[0]) / (depth >> 3); + +- output = pic->data[0] + (avctx->height - 1) * pic->linesize[0]; +- output_end = pic->data[0] + (avctx->height) * pic->linesize[0]; +- while(src < data + srcsize) { ++ output = pic->data[0] + (avctx->height - 1) * pic->linesize[0]; ++ output_end = pic->data[0] + avctx->height * pic->linesize[0]; ++ while(src + 1 < data + srcsize) { + p1 = *src++; + if(p1 == 0) { //Escape code + p2 = *src++; +@@ -172,6 +172,10 @@ + src += p2 * (depth >> 3); + continue; + } ++ if(data + srcsize - src < p2 * (depth >> 3)){ ++ av_log(avctx, AV_LOG_ERROR, "Copy beyond input buffer\n"); ++ return -1; ++ } + if ((depth == 8) || (depth == 24)) { + for(i = 0; i < p2 * (depth >> 3); i++) { + *output++ = *src++; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msvideo1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msvideo1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msvideo1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msvideo1.c 2012-05-14 14:08:54.081334890 +0200 +@@ -25,9 +25,6 @@ + * For more information about the MS Video-1 format, visit: + * http://www.pcisys.net/~melanson/codecs/ + * +- * This decoder outputs either PAL8 or RGB555 data, depending on the +- * whether a RGB palette was passed through palctrl; +- * if it's present, then the data is PAL8; RGB555 otherwise. + */ + + #include +@@ -55,6 +52,7 @@ + + int mode_8bit; /* if it's not 8-bit, it's 16-bit */ + ++ uint32_t pal[256]; + } Msvideo1Context; + + static av_cold int msvideo1_decode_init(AVCodecContext *avctx) +@@ -64,7 +62,7 @@ + s->avctx = avctx; + + /* figure out the colorspace based on the presence of a palette */ +- if (s->avctx->palctrl) { ++ if (s->avctx->bits_per_coded_sample == 8) { + s->mode_8bit = 1; + avctx->pix_fmt = PIX_FMT_PAL8; + } else { +@@ -72,6 +70,7 @@ + avctx->pix_fmt = PIX_FMT_RGB555; + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -173,13 +172,8 @@ + } + + /* make the palette available on the way out */ +- if (s->avctx->pix_fmt == PIX_FMT_PAL8) { +- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (s->avctx->palctrl->palette_changed) { +- s->frame.palette_has_changed = 1; +- s->avctx->palctrl->palette_changed = 0; +- } +- } ++ if (s->avctx->pix_fmt == PIX_FMT_PAL8) ++ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + } + + static void msvideo1_decode_16bit(Msvideo1Context *s) +@@ -302,13 +296,22 @@ + s->buf = buf; + s->size = buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + ++ if (s->mode_8bit) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ ++ if (pal) { ++ memcpy(s->pal, pal, AVPALETTE_SIZE); ++ s->frame.palette_has_changed = 1; ++ } ++ } ++ + if (s->mode_8bit) + msvideo1_decode_8bit(s); + else +@@ -332,14 +335,13 @@ + } + + AVCodec ff_msvideo1_decoder = { +- "msvideo1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_MSVIDEO1, +- sizeof(Msvideo1Context), +- msvideo1_decode_init, +- NULL, +- msvideo1_decode_end, +- msvideo1_decode_frame, +- CODEC_CAP_DR1, ++ .name = "msvideo1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSVIDEO1, ++ .priv_data_size = sizeof(Msvideo1Context), ++ .init = msvideo1_decode_init, ++ .close = msvideo1_decode_end, ++ .decode = msvideo1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("Microsoft Video 1"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msvideo1enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msvideo1enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/msvideo1enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/msvideo1enc.c 2012-05-14 14:08:54.082334910 +0200 +@@ -0,0 +1,302 @@ ++/* ++ * Microsoft Video-1 Encoder ++ * Copyright (c) 2009 Konstantin Shishkov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Microsoft Video-1 encoder ++ */ ++ ++#include "avcodec.h" ++#include "bytestream.h" ++#include "libavutil/lfg.h" ++#include "elbg.h" ++#include "libavutil/imgutils.h" ++/** ++ * Encoder context ++ */ ++typedef struct Msvideo1EncContext { ++ AVCodecContext *avctx; ++ AVFrame pic; ++ AVLFG rnd; ++ uint8_t *prev; ++ ++ int block[16*3]; ++ int block2[16*3]; ++ int codebook[8*3]; ++ int codebook2[8*3]; ++ int output[16*3]; ++ int output2[16*3]; ++ int avg[3]; ++ int bestpos; ++ int keyint; ++} Msvideo1EncContext; ++ ++enum MSV1Mode{ ++ MODE_SKIP = 0, ++ MODE_FILL, ++ MODE_2COL, ++ MODE_8COL, ++}; ++ ++#define SKIP_PREFIX 0x8400 ++#define SKIPS_MAX 0x0FFF ++#define MKRGB555(in, off) ((in[off] << 10) | (in[off + 1] << 5) | (in[off + 2])) ++ ++static const int remap[16] = { 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15 }; ++ ++static int encode_frame(AVCodecContext *avctx, uint8_t *buf, int buf_size, void *data) ++{ ++ Msvideo1EncContext * const c = avctx->priv_data; ++ AVFrame *pict = data; ++ AVFrame * const p = &c->pic; ++ uint16_t *src; ++ uint8_t *prevptr; ++ uint8_t *dst = buf; ++ int keyframe = 1; ++ int no_skips = 1; ++ int i, j, k, x, y; ++ int skips = 0; ++ ++ *p = *pict; ++ if(!c->prev) ++ c->prev = av_malloc(avctx->width * 3 * (avctx->height + 3)); ++ prevptr = c->prev + avctx->width * 3 * (FFALIGN(avctx->height, 4) - 1); ++ src = (uint16_t*)(p->data[0] + p->linesize[0]*(FFALIGN(avctx->height, 4) - 1)); ++ if(c->keyint >= avctx->keyint_min) ++ keyframe = 1; ++ ++ p->quality = 24; ++ ++ for(y = 0; y < avctx->height; y += 4){ ++ for(x = 0; x < avctx->width; x += 4){ ++ int bestmode = MODE_SKIP; ++ int bestscore = INT_MAX; ++ int flags = 0; ++ int score; ++ ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ uint16_t val = src[x + i - j*p->linesize[0]/2]; ++ for(k = 0; k < 3; k++){ ++ c->block[(i + j*4)*3 + k] = ++ c->block2[remap[i + j*4]*3 + k] = (val >> (10-k*5)) & 0x1F; ++ } ++ } ++ } ++ if(!keyframe){ ++ bestscore = 0; ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4*3; i++){ ++ int t = prevptr[x*3 + i + j*p->linesize[0]] - c->block[i + j*4*3]; ++ bestscore += t*t; ++ } ++ } ++ bestscore /= p->quality; ++ } ++ // try to find optimal value to fill whole 4x4 block ++ score = 0; ++ ff_init_elbg(c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd); ++ ff_do_elbg (c->block, 3, 16, c->avg, 1, 1, c->output, &c->rnd); ++ if(c->avg[0] == 1) // red component = 1 will be written as skip code ++ c->avg[0] = 0; ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ for(k = 0; k < 3; k++){ ++ int t = c->avg[k] - c->block[(i+j*4)*3+k]; ++ score += t*t; ++ } ++ } ++ } ++ score /= p->quality; ++ score += 2; ++ if(score < bestscore){ ++ bestscore = score; ++ bestmode = MODE_FILL; ++ } ++ // search for optimal filling of 2-color block ++ score = 0; ++ ff_init_elbg(c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd); ++ ff_do_elbg (c->block, 3, 16, c->codebook, 2, 1, c->output, &c->rnd); ++ // last output value should be always 1, swap codebooks if needed ++ if(!c->output[15]){ ++ for(i = 0; i < 3; i++) ++ FFSWAP(uint8_t, c->codebook[i], c->codebook[i+3]); ++ for(i = 0; i < 16; i++) ++ c->output[i] ^= 1; ++ } ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ for(k = 0; k < 3; k++){ ++ int t = c->codebook[c->output[i+j*4]*3 + k] - c->block[i*3+k+j*4*3]; ++ score += t*t; ++ } ++ } ++ } ++ score /= p->quality; ++ score += 6; ++ if(score < bestscore){ ++ bestscore = score; ++ bestmode = MODE_2COL; ++ } ++ // search for optimal filling of 2-color 2x2 subblocks ++ score = 0; ++ for(i = 0; i < 4; i++){ ++ ff_init_elbg(c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd); ++ ff_do_elbg (c->block2 + i*4*3, 3, 4, c->codebook2 + i*2*3, 2, 1, c->output2 + i*4, &c->rnd); ++ } ++ // last value should be always 1, swap codebooks if needed ++ if(!c->output2[15]){ ++ for(i = 0; i < 3; i++) ++ FFSWAP(uint8_t, c->codebook2[i+18], c->codebook2[i+21]); ++ for(i = 12; i < 16; i++) ++ c->output2[i] ^= 1; ++ } ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ for(k = 0; k < 3; k++){ ++ int t = c->codebook2[(c->output2[remap[i+j*4]] + (i&2) + (j&2)*2)*3+k] - c->block[i*3+k + j*4*3]; ++ score += t*t; ++ } ++ } ++ } ++ score /= p->quality; ++ score += 18; ++ if(score < bestscore){ ++ bestscore = score; ++ bestmode = MODE_8COL; ++ } ++ ++ if(bestmode == MODE_SKIP){ ++ skips++; ++ no_skips = 0; ++ } ++ if((bestmode != MODE_SKIP && skips) || skips == SKIPS_MAX){ ++ bytestream_put_le16(&dst, skips | SKIP_PREFIX); ++ skips = 0; ++ } ++ ++ switch(bestmode){ ++ case MODE_FILL: ++ bytestream_put_le16(&dst, MKRGB555(c->avg,0) | 0x8000); ++ for(j = 0; j < 4; j++) ++ for(i = 0; i < 4; i++) ++ for(k = 0; k < 3; k++) ++ prevptr[i*3 + k - j*3*avctx->width] = c->avg[k]; ++ break; ++ case MODE_2COL: ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ flags |= (c->output[i + j*4]^1) << (i + j*4); ++ for(k = 0; k < 3; k++) ++ prevptr[i*3 + k - j*3*avctx->width] = c->codebook[c->output[i + j*4]*3 + k]; ++ } ++ } ++ bytestream_put_le16(&dst, flags); ++ bytestream_put_le16(&dst, MKRGB555(c->codebook, 0)); ++ bytestream_put_le16(&dst, MKRGB555(c->codebook, 3)); ++ break; ++ case MODE_8COL: ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++){ ++ flags |= (c->output2[remap[i + j*4]]^1) << (i + j*4); ++ for(k = 0; k < 3; k++) ++ prevptr[i*3 + k - j*3*avctx->width] = c->codebook2[(c->output2[remap[i+j*4]] + (i&2) + (j&2)*2)*3 + k]; ++ } ++ } ++ bytestream_put_le16(&dst, flags); ++ bytestream_put_le16(&dst, MKRGB555(c->codebook2, 0) | 0x8000); ++ for(i = 3; i < 24; i += 3) ++ bytestream_put_le16(&dst, MKRGB555(c->codebook2, i)); ++ break; ++ } ++ } ++ src -= p->linesize[0] << 1; ++ prevptr -= avctx->width * 3 * 4; ++ } ++ if(skips) ++ bytestream_put_le16(&dst, skips | SKIP_PREFIX); ++ //EOF ++ bytestream_put_byte(&dst, 0); ++ bytestream_put_byte(&dst, 0); ++ ++ if(no_skips) ++ keyframe = 1; ++ if(keyframe) ++ c->keyint = 0; ++ else ++ c->keyint++; ++ p->pict_type= keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; ++ p->key_frame= keyframe; ++ ++ return dst - buf; ++} ++ ++ ++/** ++ * init encoder ++ */ ++static av_cold int encode_init(AVCodecContext *avctx) ++{ ++ Msvideo1EncContext * const c = avctx->priv_data; ++ ++ c->avctx = avctx; ++ if (av_image_check_size(avctx->width, avctx->height, 0, avctx) < 0) { ++ return -1; ++ } ++ if((avctx->width&3) || (avctx->height&3)){ ++ av_log(avctx, AV_LOG_ERROR, "width and height must be multiplies of 4\n"); ++ return -1; ++ } ++ ++ avcodec_get_frame_defaults(&c->pic); ++ avctx->coded_frame = (AVFrame*)&c->pic; ++ ++ c->keyint = avctx->keyint_min; ++ av_lfg_init(&c->rnd, 1); ++ ++ return 0; ++} ++ ++ ++ ++/** ++ * Uninit encoder ++ */ ++static av_cold int encode_end(AVCodecContext *avctx) ++{ ++ Msvideo1EncContext * const c = avctx->priv_data; ++ ++ av_freep(&c->prev); ++ ++ return 0; ++} ++ ++AVCodec ff_msvideo1_encoder = { ++ .name = "msvideo1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MSVIDEO1, ++ .priv_data_size = sizeof(Msvideo1EncContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB555, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Microsoft Video-1"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mxpegdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mxpegdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/mxpegdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/mxpegdec.c 2012-05-14 14:08:54.083334930 +0200 +@@ -0,0 +1,343 @@ ++/* ++ * MxPEG decoder ++ * Copyright (c) 2011 Anatoly Nenashev ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++ ++/** ++ * @file ++ * MxPEG decoder ++ */ ++ ++#include "mjpeg.h" ++#include "mjpegdec.h" ++ ++typedef struct MXpegDecodeContext { ++ MJpegDecodeContext jpg; ++ AVFrame picture[2]; /* pictures array */ ++ int picture_index; /* index of current picture */ ++ int got_sof_data; /* true if SOF data successfully parsed */ ++ int got_mxm_bitmask; /* true if MXM bitmask available */ ++ uint8_t *mxm_bitmask; /* bitmask buffer */ ++ unsigned bitmask_size; /* size of bitmask */ ++ int has_complete_frame; /* true if has complete frame */ ++ uint8_t *completion_bitmask; /* completion bitmask of macroblocks */ ++ unsigned mb_width, mb_height; /* size of picture in MB's from MXM header */ ++} MXpegDecodeContext; ++ ++static av_cold int mxpeg_decode_init(AVCodecContext *avctx) ++{ ++ MXpegDecodeContext *s = avctx->priv_data; ++ ++ s->picture[0].reference = s->picture[1].reference = 3; ++ s->jpg.picture_ptr = &s->picture[0]; ++ return ff_mjpeg_decode_init(avctx); ++} ++ ++static int mxpeg_decode_app(MXpegDecodeContext *s, ++ const uint8_t *buf_ptr, int buf_size) ++{ ++ int len; ++ if (buf_size < 2) ++ return 0; ++ len = AV_RB16(buf_ptr); ++ skip_bits(&s->jpg.gb, 8*FFMIN(len,buf_size)); ++ ++ return 0; ++} ++ ++static int mxpeg_decode_mxm(MXpegDecodeContext *s, ++ const uint8_t *buf_ptr, int buf_size) ++{ ++ unsigned bitmask_size, mb_count; ++ int i; ++ ++ s->mb_width = AV_RL16(buf_ptr+4); ++ s->mb_height = AV_RL16(buf_ptr+6); ++ mb_count = s->mb_width * s->mb_height; ++ ++ bitmask_size = (mb_count + 7) >> 3; ++ if (bitmask_size > buf_size - 12) { ++ av_log(s->jpg.avctx, AV_LOG_ERROR, ++ "MXM bitmask is not complete\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (s->bitmask_size != bitmask_size) { ++ s->bitmask_size = 0; ++ av_freep(&s->mxm_bitmask); ++ s->mxm_bitmask = av_malloc(bitmask_size); ++ if (!s->mxm_bitmask) { ++ av_log(s->jpg.avctx, AV_LOG_ERROR, ++ "MXM bitmask memory allocation error\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ av_freep(&s->completion_bitmask); ++ s->completion_bitmask = av_mallocz(bitmask_size); ++ if (!s->completion_bitmask) { ++ av_log(s->jpg.avctx, AV_LOG_ERROR, ++ "Completion bitmask memory allocation error\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ s->bitmask_size = bitmask_size; ++ } ++ ++ memcpy(s->mxm_bitmask, buf_ptr + 12, bitmask_size); ++ s->got_mxm_bitmask = 1; ++ ++ if (!s->has_complete_frame) { ++ uint8_t completion_check = 0xFF; ++ for (i = 0; i < bitmask_size; ++i) { ++ s->completion_bitmask[i] |= s->mxm_bitmask[i]; ++ completion_check &= s->completion_bitmask[i]; ++ } ++ s->has_complete_frame = !(completion_check ^ 0xFF); ++ } ++ ++ return 0; ++} ++ ++static int mxpeg_decode_com(MXpegDecodeContext *s, ++ const uint8_t *buf_ptr, int buf_size) ++{ ++ int len, ret = 0; ++ if (buf_size < 2) ++ return 0; ++ len = AV_RB16(buf_ptr); ++ if (len > 14 && len <= buf_size && !strncmp(buf_ptr + 2, "MXM", 3)) { ++ ret = mxpeg_decode_mxm(s, buf_ptr + 2, len - 2); ++ } ++ skip_bits(&s->jpg.gb, 8*FFMIN(len,buf_size)); ++ ++ return ret; ++} ++ ++static int mxpeg_check_dimensions(MXpegDecodeContext *s, MJpegDecodeContext *jpg, ++ AVFrame *reference_ptr) ++{ ++ if ((jpg->width + 0x0F)>>4 != s->mb_width || ++ (jpg->height + 0x0F)>>4 != s->mb_height) { ++ av_log(jpg->avctx, AV_LOG_ERROR, ++ "Picture dimensions stored in SOF and MXM mismatch\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (reference_ptr->data[0]) { ++ int i; ++ for (i = 0; i < MAX_COMPONENTS; ++i) { ++ if ( (!reference_ptr->data[i] ^ !jpg->picture_ptr->data[i]) || ++ reference_ptr->linesize[i] != jpg->picture_ptr->linesize[i]) { ++ av_log(jpg->avctx, AV_LOG_ERROR, ++ "Dimensions of current and reference picture mismatch\n"); ++ return AVERROR(EINVAL); ++ } ++ } ++ } ++ ++ return 0; ++} ++ ++static int mxpeg_decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ MXpegDecodeContext *s = avctx->priv_data; ++ MJpegDecodeContext *jpg = &s->jpg; ++ const uint8_t *buf_end, *buf_ptr; ++ const uint8_t *unescaped_buf_ptr; ++ int unescaped_buf_size; ++ int start_code; ++ AVFrame *picture = data; ++ int ret; ++ ++ buf_ptr = buf; ++ buf_end = buf + buf_size; ++ jpg->got_picture = 0; ++ s->got_mxm_bitmask = 0; ++ while (buf_ptr < buf_end) { ++ start_code = ff_mjpeg_find_marker(jpg, &buf_ptr, buf_end, ++ &unescaped_buf_ptr, &unescaped_buf_size); ++ if (start_code < 0) ++ goto the_end; ++ { ++ init_get_bits(&jpg->gb, unescaped_buf_ptr, unescaped_buf_size*8); ++ ++ if (start_code >= APP0 && start_code <= APP15) { ++ mxpeg_decode_app(s, unescaped_buf_ptr, unescaped_buf_size); ++ } ++ ++ switch (start_code) { ++ case SOI: ++ if (jpg->got_picture) //emulating EOI ++ goto the_end; ++ break; ++ case EOI: ++ goto the_end; ++ case DQT: ++ ret = ff_mjpeg_decode_dqt(jpg); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "quantization table decode error\n"); ++ return ret; ++ } ++ break; ++ case DHT: ++ ret = ff_mjpeg_decode_dht(jpg); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "huffman table decode error\n"); ++ return ret; ++ } ++ break; ++ case COM: ++ ret = mxpeg_decode_com(s, unescaped_buf_ptr, ++ unescaped_buf_size); ++ if (ret < 0) ++ return ret; ++ break; ++ case SOF0: ++ s->got_sof_data = 0; ++ ret = ff_mjpeg_decode_sof(jpg); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, ++ "SOF data decode error\n"); ++ return ret; ++ } ++ if (jpg->interlaced) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Interlaced mode not supported in MxPEG\n"); ++ return AVERROR(EINVAL); ++ } ++ s->got_sof_data = 1; ++ break; ++ case SOS: ++ if (!s->got_sof_data) { ++ av_log(avctx, AV_LOG_WARNING, ++ "Can not process SOS without SOF data, skipping\n"); ++ break; ++ } ++ if (!jpg->got_picture) { ++ if (jpg->first_picture) { ++ av_log(avctx, AV_LOG_WARNING, ++ "First picture has no SOF, skipping\n"); ++ break; ++ } ++ if (!s->got_mxm_bitmask){ ++ av_log(avctx, AV_LOG_WARNING, ++ "Non-key frame has no MXM, skipping\n"); ++ break; ++ } ++ /* use stored SOF data to allocate current picture */ ++ if (jpg->picture_ptr->data[0]) ++ avctx->release_buffer(avctx, jpg->picture_ptr); ++ if (avctx->get_buffer(avctx, jpg->picture_ptr) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return AVERROR(ENOMEM); ++ } ++ jpg->picture_ptr->pict_type = AV_PICTURE_TYPE_P; ++ jpg->picture_ptr->key_frame = 0; ++ jpg->got_picture = 1; ++ } else { ++ jpg->picture_ptr->pict_type = AV_PICTURE_TYPE_I; ++ jpg->picture_ptr->key_frame = 1; ++ } ++ ++ if (s->got_mxm_bitmask) { ++ AVFrame *reference_ptr = &s->picture[s->picture_index ^ 1]; ++ if (mxpeg_check_dimensions(s, jpg, reference_ptr) < 0) ++ break; ++ ++ /* allocate dummy reference picture if needed */ ++ if (!reference_ptr->data[0] && ++ avctx->get_buffer(avctx, reference_ptr) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ ret = ff_mjpeg_decode_sos(jpg, s->mxm_bitmask, reference_ptr); ++ if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) ++ return ret; ++ } else { ++ ret = ff_mjpeg_decode_sos(jpg, NULL, NULL); ++ if (ret < 0 && (avctx->err_recognition & AV_EF_EXPLODE)) ++ return ret; ++ } ++ ++ break; ++ } ++ ++ buf_ptr += (get_bits_count(&jpg->gb)+7) >> 3; ++ } ++ ++ } ++ ++the_end: ++ if (jpg->got_picture) { ++ *data_size = sizeof(AVFrame); ++ *picture = *jpg->picture_ptr; ++ s->picture_index ^= 1; ++ jpg->picture_ptr = &s->picture[s->picture_index]; ++ ++ if (!s->has_complete_frame) { ++ if (!s->got_mxm_bitmask) ++ s->has_complete_frame = 1; ++ else ++ *data_size = 0; ++ } ++ } ++ ++ return buf_ptr - buf; ++} ++ ++static av_cold int mxpeg_decode_end(AVCodecContext *avctx) ++{ ++ MXpegDecodeContext *s = avctx->priv_data; ++ MJpegDecodeContext *jpg = &s->jpg; ++ int i; ++ ++ jpg->picture_ptr = NULL; ++ ff_mjpeg_decode_end(avctx); ++ ++ for (i = 0; i < 2; ++i) { ++ if (s->picture[i].data[0]) ++ avctx->release_buffer(avctx, &s->picture[i]); ++ } ++ ++ av_freep(&s->mxm_bitmask); ++ av_freep(&s->completion_bitmask); ++ ++ return 0; ++} ++ ++AVCodec ff_mxpeg_decoder = { ++ .name = "mxpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("Mobotix MxPEG video"), ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MXPEG, ++ .priv_data_size = sizeof(MXpegDecodeContext), ++ .init = mxpeg_decode_init, ++ .close = mxpeg_decode_end, ++ .decode = mxpeg_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .max_lowres = 3 ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoser.c 2012-05-14 14:08:54.084334950 +0200 +@@ -35,7 +35,7 @@ + #include "avcodec.h" + #include "dsputil.h" + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + const float ff_nelly_dequantization_table[127] = { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoserdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoserdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoserdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoserdec.c 2012-05-14 14:08:54.086334990 +0200 +@@ -34,46 +34,31 @@ + #include "nellymoser.h" + #include "libavutil/lfg.h" + #include "libavutil/random_seed.h" +-#include "libavcore/audioconvert.h" ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "dsputil.h" + #include "fft.h" + #include "fmtconvert.h" ++#include "sinewin.h" + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + + typedef struct NellyMoserDecodeContext { + AVCodecContext* avctx; +- DECLARE_ALIGNED(16, float,float_buf)[NELLY_SAMPLES]; +- float state[128]; ++ AVFrame frame; ++ float *float_buf; ++ DECLARE_ALIGNED(16, float, state)[NELLY_BUF_LEN]; + AVLFG random_state; + GetBitContext gb; + float scale_bias; + DSPContext dsp; + FFTContext imdct_ctx; + FmtConvertContext fmt_conv; +- DECLARE_ALIGNED(16, float,imdct_out)[NELLY_BUF_LEN * 2]; ++ DECLARE_ALIGNED(32, float, imdct_out)[NELLY_BUF_LEN * 2]; + } NellyMoserDecodeContext; + +-static void overlap_and_window(NellyMoserDecodeContext *s, float *state, float *audio, float *a_in) +-{ +- int bot, top; +- +- bot = 0; +- top = NELLY_BUF_LEN-1; +- +- while (bot < NELLY_BUF_LEN) { +- audio[bot] = a_in [bot]*ff_sine_128[bot] +- +state[bot]*ff_sine_128[top]; +- +- bot++; +- top--; +- } +- memcpy(state, a_in + NELLY_BUF_LEN, sizeof(float)*NELLY_BUF_LEN); +-} +- + static void nelly_decode_block(NellyMoserDecodeContext *s, + const unsigned char block[NELLY_BLOCK_LEN], + float audio[NELLY_SAMPLES]) +@@ -121,10 +106,12 @@ + memset(&aptr[NELLY_FILL_LEN], 0, + (NELLY_BUF_LEN - NELLY_FILL_LEN) * sizeof(float)); + +- ff_imdct_calc(&s->imdct_ctx, s->imdct_out, aptr); ++ s->imdct_ctx.imdct_calc(&s->imdct_ctx, s->imdct_out, aptr); + /* XXX: overlapping and windowing should be part of a more + generic imdct function */ +- overlap_and_window(s, s->state, aptr, s->imdct_out); ++ s->dsp.vector_fmul_reverse(s->state, s->state, ff_sine_128, NELLY_BUF_LEN); ++ s->dsp.vector_fmul_add(aptr, s->imdct_out, ff_sine_128, s->state, NELLY_BUF_LEN); ++ memcpy(s->state, s->imdct_out + NELLY_BUF_LEN, sizeof(float)*NELLY_BUF_LEN); + } + } + +@@ -136,38 +123,55 @@ + ff_mdct_init(&s->imdct_ctx, 8, 1, 1.0); + + dsputil_init(&s->dsp, avctx); +- ff_fmt_convert_init(&s->fmt_conv, avctx); + +- s->scale_bias = 1.0/(1*8); ++ if (avctx->request_sample_fmt == AV_SAMPLE_FMT_FLT) { ++ s->scale_bias = 1.0/(32768*8); ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ } else { ++ s->scale_bias = 1.0/(1*8); ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ff_fmt_convert_init(&s->fmt_conv, avctx); ++ s->float_buf = av_mallocz(NELLY_SAMPLES * sizeof(*s->float_buf)); ++ if (!s->float_buf) { ++ av_log(avctx, AV_LOG_ERROR, "error allocating float buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ } + + /* Generate overlap window */ + if (!ff_sine_128[127]) + ff_init_ff_sine_windows(7); + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; + avctx->channel_layout = AV_CH_LAYOUT_MONO; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +-static int decode_tag(AVCodecContext * avctx, +- void *data, int *data_size, +- AVPacket *avpkt) { ++static int decode_tag(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ + const uint8_t *buf = avpkt->data; ++ const uint8_t *side=av_packet_get_side_data(avpkt, 'F', NULL); + int buf_size = avpkt->size; + NellyMoserDecodeContext *s = avctx->priv_data; +- int blocks, i; +- int16_t* samples; +- *data_size = 0; +- samples = (int16_t*)data; +- +- if (buf_size < avctx->block_align) +- return buf_size; +- +- if (buf_size % 64) { +- av_log(avctx, AV_LOG_ERROR, "Tag size %d.\n", buf_size); +- return buf_size; ++ int blocks, i, ret; ++ int16_t *samples_s16; ++ float *samples_flt; ++ ++ blocks = buf_size / NELLY_BLOCK_LEN; ++ ++ if (blocks <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (buf_size % NELLY_BLOCK_LEN) { ++ av_log(avctx, AV_LOG_WARNING, "Leftover bytes: %d.\n", ++ buf_size % NELLY_BLOCK_LEN); + } +- blocks = buf_size / 64; + /* Normal numbers of blocks for sample rates: + * 8000 Hz - 1 + * 11025 Hz - 2 +@@ -175,32 +179,57 @@ + * 22050 Hz - 4 + * 44100 Hz - 8 + */ ++ if(side && blocks>1 && avctx->sample_rate%11025==0 && (1<<((side[0]>>2)&3)) == blocks) ++ avctx->sample_rate= 11025*(blocks/2); ++ ++ /* get output buffer */ ++ s->frame.nb_samples = NELLY_SAMPLES * blocks; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples_s16 = (int16_t *)s->frame.data[0]; ++ samples_flt = (float *)s->frame.data[0]; + + for (i=0 ; ifloat_buf); +- s->fmt_conv.float_to_int16(&samples[i*NELLY_SAMPLES], s->float_buf, NELLY_SAMPLES); +- *data_size += NELLY_SAMPLES*sizeof(int16_t); ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { ++ nelly_decode_block(s, buf, samples_flt); ++ samples_flt += NELLY_SAMPLES; ++ } else { ++ nelly_decode_block(s, buf, s->float_buf); ++ s->fmt_conv.float_to_int16(samples_s16, s->float_buf, NELLY_SAMPLES); ++ samples_s16 += NELLY_SAMPLES; ++ } ++ buf += NELLY_BLOCK_LEN; + } + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return buf_size; + } + + static av_cold int decode_end(AVCodecContext * avctx) { + NellyMoserDecodeContext *s = avctx->priv_data; + ++ av_freep(&s->float_buf); + ff_mdct_end(&s->imdct_ctx); ++ + return 0; + } + + AVCodec ff_nellymoser_decoder = { +- "nellymoser", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_NELLYMOSER, +- sizeof(NellyMoserDecodeContext), +- decode_init, +- NULL, +- decode_end, +- decode_tag, ++ .name = "nellymoser", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_NELLYMOSER, ++ .priv_data_size = sizeof(NellyMoserDecodeContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_tag, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_PARAM_CHANGE, + .long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"), ++ .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLT, ++ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoserenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoserenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoserenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoserenc.c 2012-05-14 14:08:54.087335010 +0200 +@@ -35,10 +35,12 @@ + * http://wiki.multimedia.cx/index.php?title=Nellymoser + */ + ++#include "libavutil/mathematics.h" + #include "nellymoser.h" + #include "avcodec.h" + #include "dsputil.h" + #include "fft.h" ++#include "sinewin.h" + + #define BITSTREAM_WRITER_LE + #include "put_bits.h" +@@ -54,9 +56,9 @@ + int have_saved; + DSPContext dsp; + FFTContext mdct_ctx; +- DECLARE_ALIGNED(16, float, mdct_out)[NELLY_SAMPLES]; +- DECLARE_ALIGNED(16, float, in_buff)[NELLY_SAMPLES]; +- DECLARE_ALIGNED(16, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer ++ DECLARE_ALIGNED(32, float, mdct_out)[NELLY_SAMPLES]; ++ DECLARE_ALIGNED(32, float, in_buff)[NELLY_SAMPLES]; ++ DECLARE_ALIGNED(32, float, buf)[2][3 * NELLY_BUF_LEN]; ///< sample buffer + float (*opt )[NELLY_BANDS]; + uint8_t (*path)[NELLY_BANDS]; + } NellyMoserEncodeContext; +@@ -116,13 +118,13 @@ + s->dsp.vector_fmul(s->in_buff, s->buf[s->bufsel], ff_sine_128, NELLY_BUF_LEN); + s->dsp.vector_fmul_reverse(s->in_buff + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN, ff_sine_128, + NELLY_BUF_LEN); +- ff_mdct_calc(&s->mdct_ctx, s->mdct_out, s->in_buff); ++ s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out, s->in_buff); + + s->dsp.vector_fmul(s->buf[s->bufsel] + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN, + ff_sine_128, NELLY_BUF_LEN); + s->dsp.vector_fmul_reverse(s->buf[s->bufsel] + 2 * NELLY_BUF_LEN, s->buf[1 - s->bufsel], ff_sine_128, + NELLY_BUF_LEN); +- ff_mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN); ++ s->mdct_ctx.mdct_calc(&s->mdct_ctx, s->mdct_out + NELLY_BUF_LEN, s->buf[s->bufsel] + NELLY_BUF_LEN); + } + + static av_cold int encode_init(AVCodecContext *avctx) +@@ -145,7 +147,7 @@ + + avctx->frame_size = NELLY_SAMPLES; + s->avctx = avctx; +- ff_mdct_init(&s->mdct_ctx, 8, 0, 1.0); ++ ff_mdct_init(&s->mdct_ctx, 8, 0, 32768.0); + dsputil_init(&s->dsp, avctx); + + /* Generate overlap window */ +@@ -351,17 +353,15 @@ + static int encode_frame(AVCodecContext *avctx, uint8_t *frame, int buf_size, void *data) + { + NellyMoserEncodeContext *s = avctx->priv_data; +- const int16_t *samples = data; ++ const float *samples = data; + int i; + + if (s->last_frame) + return 0; + + if (data) { +- for (i = 0; i < avctx->frame_size; i++) { +- s->buf[s->bufsel][i] = samples[i]; +- } +- for (; i < NELLY_SAMPLES; i++) { ++ memcpy(s->buf[s->bufsel], samples, avctx->frame_size * sizeof(*samples)); ++ for (i = avctx->frame_size; i < NELLY_SAMPLES; i++) { + s->buf[s->bufsel][i] = 0; + } + s->bufsel = 1 - s->bufsel; +@@ -392,5 +392,5 @@ + .close = encode_end, + .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY, + .long_name = NULL_IF_CONFIG_SMALL("Nellymoser Asao"), +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoser.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoser.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nellymoser.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nellymoser.h 2012-05-14 14:08:54.085334970 +0200 +@@ -54,4 +54,4 @@ + + void ff_nelly_get_sample_bits(const float *buf, int *bits); + +-#endif ++#endif /* AVCODEC_NELLYMOSER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/nuv.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/nuv.c 2012-05-14 14:08:54.088335030 +0200 +@@ -20,10 +20,11 @@ + */ + #include + #include ++#include + + #include "libavutil/bswap.h" + #include "libavutil/lzo.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "dsputil.h" + #include "rtjpeg.h" +@@ -63,11 +64,11 @@ + }; + + /** +- * \brief copy frame data from buffer to AVFrame, handling stride. +- * \param f destination AVFrame +- * \param src source buffer, does not use any line-stride +- * \param width width of the video frame +- * \param height height of the video frame ++ * @brief copy frame data from buffer to AVFrame, handling stride. ++ * @param f destination AVFrame ++ * @param src source buffer, does not use any line-stride ++ * @param width width of the video frame ++ * @param height height of the video frame + */ + static void copy_frame(AVFrame *f, const uint8_t *src, + int width, int height) { +@@ -77,7 +78,7 @@ + } + + /** +- * \brief extract quantization tables from codec data into our context ++ * @brief extract quantization tables from codec data into our context + */ + static int get_quant(AVCodecContext *avctx, NuvContext *c, + const uint8_t *buf, int size) { +@@ -94,7 +95,7 @@ + } + + /** +- * \brief set quantization tables from a quality value ++ * @brief set quantization tables from a quality value + */ + static void get_quant_quality(NuvContext *c, int quality) { + int i; +@@ -107,24 +108,28 @@ + + static int codec_reinit(AVCodecContext *avctx, int width, int height, int quality) { + NuvContext *c = avctx->priv_data; +- width = (width + 1) & ~1; +- height = (height + 1) & ~1; ++ width = FFALIGN(width, 2); ++ height = FFALIGN(height, 2); + if (quality >= 0) + get_quant_quality(c, quality); + if (width != c->width || height != c->height) { +- if (av_image_check_size(height, width, 0, avctx) < 0) +- return 0; ++ // also reserve space for a possible additional header ++ int buf_size = 24 + height * width * 3 / 2 + AV_LZO_OUTPUT_PADDING; ++ if (av_image_check_size(height, width, 0, avctx) < 0 || ++ buf_size > INT_MAX/8) ++ return -1; + avctx->width = c->width = width; + avctx->height = c->height = height; +- av_fast_malloc(&c->decomp_buf, &c->decomp_size, c->height * c->width * 3 / 2); ++ av_fast_malloc(&c->decomp_buf, &c->decomp_size, buf_size); + if (!c->decomp_buf) { + av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); +- return 0; ++ return AVERROR(ENOMEM); + } + rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); ++ return 1; + } else if (quality != c->quality) + rtjpeg_decode_init(&c->rtj, &c->dsp, c->width, c->height, c->lq, c->cq); +- return 1; ++ return 0; + } + + static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, +@@ -135,6 +140,7 @@ + AVFrame *picture = data; + int orig_size = buf_size; + int keyframe; ++ int size_change = 0; + int result; + enum {NUV_UNCOMPRESSED = '0', NUV_RTJPEG = '1', + NUV_RTJPEG_IN_LZO = '2', NUV_LZO = '3', +@@ -172,32 +178,40 @@ + default: + keyframe = 1; break; + } ++retry: + // skip rest of the frameheader. + buf = &buf[12]; + buf_size -= 12; + if (comptype == NUV_RTJPEG_IN_LZO || comptype == NUV_LZO) { +- int outlen = c->decomp_size, inlen = buf_size; ++ int outlen = c->decomp_size - AV_LZO_OUTPUT_PADDING, inlen = buf_size; + if (av_lzo1x_decode(c->decomp_buf, &outlen, buf, &inlen)) + av_log(avctx, AV_LOG_ERROR, "error during lzo decompression\n"); + buf = c->decomp_buf; +- buf_size = c->decomp_size; ++ buf_size = c->decomp_size - AV_LZO_OUTPUT_PADDING - outlen; + } + if (c->codec_frameheader) { +- int w, h, q; +- if (buf_size < 12) { +- av_log(avctx, AV_LOG_ERROR, "invalid nuv video frame\n"); +- return -1; ++ int w, h, q, res; ++ if (buf[0] != 'V' || buf_size < 12) { ++ av_log(avctx, AV_LOG_ERROR, "invalid nuv video frame (wrong codec_tag?)\n"); ++ return AVERROR_INVALIDDATA; + } + w = AV_RL16(&buf[6]); + h = AV_RL16(&buf[8]); + q = buf[10]; +- if (!codec_reinit(avctx, w, h, q)) +- return -1; ++ res = codec_reinit(avctx, w, h, q); ++ if (res < 0) ++ return res; ++ if (res) { ++ buf = avpkt->data; ++ buf_size = avpkt->size; ++ size_change = 1; ++ goto retry; ++ } + buf = &buf[12]; + buf_size -= 12; + } + +- if (keyframe && c->pic.data[0]) ++ if ((size_change || keyframe) && c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + c->pic.reference = 3; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_READABLE | +@@ -208,7 +222,7 @@ + return -1; + } + +- c->pic.pict_type = keyframe ? FF_I_TYPE : FF_P_TYPE; ++ c->pic.pict_type = keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + c->pic.key_frame = keyframe; + // decompress/copy/whatever data + switch (comptype) { +@@ -259,7 +273,7 @@ + if (avctx->extradata_size) + get_quant(avctx, c, avctx->extradata, avctx->extradata_size); + dsputil_init(&c->dsp, avctx); +- if (!codec_reinit(avctx, avctx->width, avctx->height, -1)) ++ if (codec_reinit(avctx, avctx->width, avctx->height, -1) < 0) + return 1; + return 0; + } +@@ -273,15 +287,14 @@ + } + + AVCodec ff_nuv_decoder = { +- "nuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_NUV, +- sizeof(NuvContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "nuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_NUV, ++ .priv_data_size = sizeof(NuvContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("NuppelVideo/RTJPEG"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/opt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/opt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/opt.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/opt.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,89 +0,0 @@ +-/* +- * AVOptions ABI compatibility wrapper +- * Copyright (c) 2010 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include "avcodec.h" +-#include "opt.h" +- +-#if LIBAVCODEC_VERSION_MAJOR < 53 && CONFIG_SHARED && HAVE_SYMVER +- +-FF_SYMVER(const AVOption *, av_find_opt, (void *obj, const char *name, const char *unit, int mask, int flags), "LIBAVCODEC_52"){ +- return av_find_opt(obj, name, unit, mask, flags); +-} +-FF_SYMVER(int, av_set_string3, (void *obj, const char *name, const char *val, int alloc, const AVOption **o_out), "LIBAVCODEC_52"){ +- return av_set_string3(obj, name, val, alloc, o_out); +-} +-FF_SYMVER(const AVOption *, av_set_double, (void *obj, const char *name, double n), "LIBAVCODEC_52"){ +- return av_set_double(obj, name, n); +-} +-FF_SYMVER(const AVOption *, av_set_q, (void *obj, const char *name, AVRational n), "LIBAVCODEC_52"){ +- return av_set_q(obj, name, n); +-} +-FF_SYMVER(const AVOption *, av_set_int, (void *obj, const char *name, int64_t n), "LIBAVCODEC_52"){ +- return av_set_int(obj, name, n); +-} +-FF_SYMVER(double, av_get_double, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){ +- return av_get_double(obj, name, o_out); +-} +-FF_SYMVER(AVRational, av_get_q, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){ +- return av_get_q(obj, name, o_out); +-} +-FF_SYMVER(int64_t, av_get_int, (void *obj, const char *name, const AVOption **o_out), "LIBAVCODEC_52"){ +- return av_get_int(obj, name, o_out); +-} +-FF_SYMVER(const char *, av_get_string, (void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len), "LIBAVCODEC_52"){ +- return av_get_string(obj, name, o_out, buf, buf_len); +-} +-FF_SYMVER(const AVOption *, av_next_option, (void *obj, const AVOption *last), "LIBAVCODEC_52"){ +- return av_next_option(obj, last); +-} +-FF_SYMVER(int, av_opt_show2, (void *obj, void *av_log_obj, int req_flags, int rej_flags), "LIBAVCODEC_52"){ +- return av_opt_show2(obj, av_log_obj, req_flags, rej_flags); +-} +-FF_SYMVER(void, av_opt_set_defaults, (void *s), "LIBAVCODEC_52"){ +- return av_opt_set_defaults(s); +-} +-FF_SYMVER(void, av_opt_set_defaults2, (void *s, int mask, int flags), "LIBAVCODEC_52"){ +- return av_opt_set_defaults2(s, mask, flags); +-} +-#endif +- +-#if FF_API_SET_STRING_OLD +-const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc){ +- const AVOption *o; +- if (av_set_string3(obj, name, val, alloc, &o) < 0) +- return NULL; +- return o; +-} +- +-const AVOption *av_set_string(void *obj, const char *name, const char *val){ +- const AVOption *o; +- if (av_set_string3(obj, name, val, 0, &o) < 0) +- return NULL; +- return o; +-} +-#endif +- +-#if FF_API_OPT_SHOW +-int av_opt_show(void *obj, void *av_log_obj){ +- return av_opt_show2(obj, av_log_obj, +- AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); +-} +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/opt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/opt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/opt.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/opt.h 2012-05-14 14:08:54.089335051 +0200 +@@ -1,55 +1,34 @@ + /* +- * AVOptions +- * copyright (c) 2005 Michael Niedermayer ++ * This file is part of Libav. + * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or ++ * Libav is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * +- * FFmpeg is distributed in the hope that it will be useful, ++ * Libav 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software ++ * License along with Libav; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef AVCODEC_OPT_H +-#define AVCODEC_OPT_H +- + /** + * @file +- * AVOptions ++ * This header is provided for compatibility only and will be removed ++ * on next major bump + */ + +-#include "libavutil/rational.h" +-#include "avcodec.h" +-#include "libavutil/opt.h" ++#ifndef AVCODEC_OPT_H ++#define AVCODEC_OPT_H + +-#if FF_API_SET_STRING_OLD +-/** +- * @see av_set_string2() +- */ +-attribute_deprecated const AVOption *av_set_string(void *obj, const char *name, const char *val); ++#include "libavcodec/version.h" + +-/** +- * @return a pointer to the AVOption corresponding to the field set or +- * NULL if no matching AVOption exists, or if the value val is not +- * valid +- * @see av_set_string3() +- */ +-attribute_deprecated const AVOption *av_set_string2(void *obj, const char *name, const char *val, int alloc); +-#endif +-#if FF_API_OPT_SHOW +-/** +- * @deprecated Use av_opt_show2() instead. +- */ +-attribute_deprecated int av_opt_show(void *obj, void *av_log_obj); ++#if FF_API_OPT_H ++#include "libavutil/opt.h" + #endif + + #endif /* AVCODEC_OPT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/options.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/options.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/options.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/options.c 2012-05-14 14:08:54.095335171 +0200 +@@ -25,6 +25,8 @@ + */ + + #include "avcodec.h" ++#include "internal.h" ++#include "libavutil/avassert.h" + #include "libavutil/opt.h" + #include /* FLT_MIN, FLT_MAX */ + +@@ -37,6 +39,30 @@ + return "NULL"; + } + ++static void *codec_child_next(void *obj, void *prev) ++{ ++ AVCodecContext *s = obj; ++ if (!prev && s->codec && s->codec->priv_class && s->priv_data) ++ return s->priv_data; ++ return NULL; ++} ++ ++static const AVClass *codec_child_class_next(const AVClass *prev) ++{ ++ AVCodec *c = NULL; ++ ++ /* find the codec that corresponds to prev */ ++ while (prev && (c = av_codec_next(c))) ++ if (c->priv_class == prev) ++ break; ++ ++ /* find next codec with priv options */ ++ while (c = av_codec_next(c)) ++ if (c->priv_class) ++ return c->priv_class; ++ return NULL; ++} ++ + #define OFFSET(x) offsetof(AVCodecContext,x) + #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C + //these names are too long to be readable +@@ -49,388 +75,463 @@ + #define AV_CODEC_DEFAULT_BITRATE 200*1000 + + static const AVOption options[]={ +-{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E}, +-{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E}, +-{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E}, +-{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, 0, UINT_MAX, V|A|E|D, "flags"}, +-{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"}, +-{"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"}, +-{"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"}, +-{"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"}, +-{"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"}, +-{"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"}, +-{"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"}, +-{"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"}, +-{"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"}, +-{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"}, +-{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"}, +-{"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"}, +-{"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"}, +-{"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"}, +-{"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"}, +-{"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"}, +-{"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"}, +-{"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"}, +-{"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D|E, "flags"}, +-{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"}, +-{"global_header", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, V|A|E, "flags"}, +-{"bitexact", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"}, +-{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"}, +-{"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"}, +-{"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"}, +-{"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"}, +-{"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"}, +-{"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"}, +-{"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"}, +-{"scan_offset", "will reserve space for svcd scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"}, +-{"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"}, +-{"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"local_header", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"me_method", "set motion estimation method", OFFSET(me_method), FF_OPT_TYPE_INT, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method"}, +-{"zero", "zero motion estimation (fastest)", 0, FF_OPT_TYPE_CONST, ME_ZERO, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"full", "full motion estimation (slowest)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"epzs", "EPZS motion estimation (default)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"esa", "esa motion estimation (alias for full)", 0, FF_OPT_TYPE_CONST, ME_FULL, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"tesa", "tesa motion estimation", 0, FF_OPT_TYPE_CONST, ME_TESA, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"dia", "dia motion estimation (alias for epzs)", 0, FF_OPT_TYPE_CONST, ME_EPZS, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"log", "log motion estimation", 0, FF_OPT_TYPE_CONST, ME_LOG, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"phods", "phods motion estimation", 0, FF_OPT_TYPE_CONST, ME_PHODS, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"x1", "X1 motion estimation", 0, FF_OPT_TYPE_CONST, ME_X1, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"hex", "hex motion estimation", 0, FF_OPT_TYPE_CONST, ME_HEX, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"umh", "umh motion estimation", 0, FF_OPT_TYPE_CONST, ME_UMH, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"iter", "iter motion estimation", 0, FF_OPT_TYPE_CONST, ME_ITER, INT_MIN, INT_MAX, V|E, "me_method" }, +-{"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX}, +-{"g", "set the group of picture size", OFFSET(gop_size), FF_OPT_TYPE_INT, 12, INT_MIN, INT_MAX, V|E}, +-{"rate_emu", "frame rate emulation", OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"ac", "set number of audio channels", OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E}, +-{"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|E}, +-{"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-{"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-#endif +-{"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), FF_OPT_TYPE_FLOAT, 0.5, -FLT_MAX, FLT_MAX, V|E}, +-{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), FF_OPT_TYPE_FLOAT, 0.5, 0, FLT_MAX, V|E}, +-{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), FF_OPT_TYPE_INT, 2, 0, 63, V|E}, +-{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), FF_OPT_TYPE_INT, 31, 0, 63, V|E}, +-{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), FF_OPT_TYPE_INT, 3, INT_MIN, INT_MAX, V|E}, +-{"bf", "use 'frames' B frames", OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, 0, FF_MAX_B_FRAMES, V|E}, +-{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E}, +-{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, +-{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, +-{"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, +-{"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), FF_OPT_TYPE_FLAGS, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"}, +-{"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"}, +-{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"}, +-{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"}, +-{"ump4", "(autodetected if fourcc==UMP4)", 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"}, +-{"no_padding", "padding bug (autodetected)", 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"}, +-{"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"}, +-{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"}, +-{"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"}, +-{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"}, +-{"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"}, +-{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"}, +-{"edge", "edge padding bug (autodetected per fourcc/version)", 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"}, +-{"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"}, +-{"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"}, +-{"ms", "workaround various bugs in microsofts broken decoders", 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"}, +-{"trunc", "trancated frames", 0, FF_OPT_TYPE_CONST,FF_BUG_TRUNCATED, INT_MIN, INT_MAX, V|D, "bug"}, +-{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|D|E, "strict"}, +-{"very", "strictly conform to a older more strict version of the spec or reference software", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"}, +-{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|D|E, "strict"}, +-{"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|D|E, "strict"}, +-#if FF_API_INOFFICIAL +-{"inofficial", "allow unofficial extensions (deprecated - use unofficial)", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_UNOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"}, +-#endif +-{"unofficial", "allow unofficial extensions", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_UNOFFICIAL, INT_MIN, INT_MAX, V|D|E, "strict"}, +-{"experimental", "allow non standardized experimental things", 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|D|E, "strict"}, +-{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, 1.25, -FLT_MAX, FLT_MAX, V|E}, +-{"er", "set error detection aggressivity", OFFSET(error_recognition), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, A|V|D, "er"}, +-{"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"}, +-{"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"}, +-{"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"}, +-{"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"}, +-{"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX}, +-{"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX}, +-{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 99, V|E}, +-{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E}, +-{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"rc_eq", "set rate control equation", OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E}, +-{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, A|V|E}, +-{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, 1.0, -FLT_MAX, FLT_MAX, V|E}, +-{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, -0.8, -FLT_MAX, FLT_MAX, V|E}, +-{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, 0.0, -FLT_MAX, FLT_MAX, V|E}, +-{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E}, +-{"dct", "DCT algorithm", OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"}, +-{"auto", "autoselect a good one (default)", 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"}, +-{"fastint", "fast integer", 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"}, +-{"int", "accurate integer", 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"}, +-{"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"}, +-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"}, +-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"}, +-{"faan", "floating point AAN DCT", 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"}, +-{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E}, +-{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E}, +-{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E}, +-{"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E}, +-{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, -FLT_MAX, FLT_MAX, V|E}, +-{"idct", "select IDCT implementation", OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"}, +-{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simplearmv5te", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV5TE, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simplearmv6", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARMV6, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simpleneon", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLENEON, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"simplealpha", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEALPHA, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"}, +-{"faani", "floating point AAN IDCT", 0, FF_OPT_TYPE_CONST, FF_IDCT_FAAN, INT_MIN, INT_MAX, V|D|E, "idct"}, +-{"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"ec", "set error concealment strategy", OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"}, +-{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"}, +-{"deblock", "use strong deblock filter for damaged MBs", 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"}, +-{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"}, +-{"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"}, +-{"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"}, +-{"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"}, +-{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E}, +-{"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"}, +-{"pict", "picture info", 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"}, +-{"rc", "rate control", 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"}, +-{"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"}, +-{"mb_type", "macroblock (MB) type", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"}, +-{"qp", "per-block quantization parameter (QP)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"}, +-{"mv", "motion vector", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"}, +-{"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"}, +-{"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"}, +-{"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"}, +-{"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"}, +-{"er", "error recognition", 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"}, +-{"mmco", "memory management control operations (H.264)", 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"}, +-{"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"}, +-{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"}, +-{"vis_mb_type", "visualize block types", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"}, +-{"buffers", "picture buffer allocations", 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUFFERS, INT_MIN, INT_MAX, V|D, "debug"}, +-{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"}, +-{"pf", "forward predicted MVs of P-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"}, +-{"bf", "forward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"}, +-{"bb", "backward predicted MVs of B-frames", 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"}, +-{"mb_qmin", "obsolete, use qmin", OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"mb_qmax", "obsolete, use qmax", OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"preme", "pre motion estimation", OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"sad", "sum of absolute differences, fast (default)", 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"sse", "sum of squared errors", 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"satd", "sum of absolute Hadamard transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"dct", "sum of absolute DCT transformed differences", 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"bit", "number of bits needed for the block", 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"rd", "rate distortion optimal, slow", 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"zero", "0", 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"vsad", "sum of absolute vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"vsse", "sum of squared vertical differences", 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"nsse", "noise preserving sum of squared differences", 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), AV_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE }, INT_MIN, INT_MAX, A|V|E}, ++{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), AV_OPT_TYPE_INT, {.dbl = 128*1000 }, INT_MIN, INT_MAX, A|E}, ++{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), AV_OPT_TYPE_INT, {.dbl = AV_CODEC_DEFAULT_BITRATE*20 }, 1, INT_MAX, V|E}, ++{"flags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, UINT_MAX, V|A|E|D, "flags"}, ++{"mv4", "use four motion vector by macroblock (mpeg4)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_4MV }, INT_MIN, INT_MAX, V|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"obmc", "use overlapped block motion compensation (h263+)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_OBMC }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"qpel", "use 1/4 pel motion compensation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QPEL }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"loop", "use loop filter", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOOP_FILTER }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"qscale", "use fixed qscale", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QSCALE }, INT_MIN, INT_MAX, 0, "flags"}, ++{"gmc", "use gmc", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GMC }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"mv0", "always try a mb with mv=<0,0>", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_MV0 }, INT_MIN, INT_MAX, V|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"part", "use data partitioning", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PART }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"input_preserved", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INPUT_PRESERVED }, INT_MIN, INT_MAX, 0, "flags"}, ++{"pass1", "use internal 2pass ratecontrol in first pass mode", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS1 }, INT_MIN, INT_MAX, 0, "flags"}, ++{"pass2", "use internal 2pass ratecontrol in second pass mode", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PASS2 }, INT_MIN, INT_MAX, 0, "flags"}, ++#if FF_API_MJPEG_GLOBAL_OPTS ++{"extern_huff", "use external huffman table (for mjpeg)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EXTERN_HUFF }, INT_MIN, INT_MAX, 0, "flags"}, ++#endif ++{"gray", "only decode/encode grayscale", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GRAY }, INT_MIN, INT_MAX, V|E|D, "flags"}, ++{"emu_edge", "don't draw edges", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_EMU_EDGE }, INT_MIN, INT_MAX, 0, "flags"}, ++{"psnr", "error[?] variables will be set during encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_PSNR }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"truncated", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_TRUNCATED }, INT_MIN, INT_MAX, 0, "flags"}, ++{"naq", "normalize adaptive quantization", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_NORMALIZE_AQP }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"ildct", "use interlaced dct", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_DCT }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"low_delay", "force low delay", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_LOW_DELAY }, INT_MIN, INT_MAX, V|D|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_ALT_SCAN }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"global_header", "place global headers in extradata instead of every keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_GLOBAL_HEADER }, INT_MIN, INT_MAX, V|A|E, "flags"}, ++{"bitexact", "use only bitexact stuff (except (i)dct)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_BITEXACT }, INT_MIN, INT_MAX, A|V|S|D|E, "flags"}, ++{"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_AC_PRED }, INT_MIN, INT_MAX, V|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"umv", "use unlimited motion vectors", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_UMV }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"cbp", "use rate distortion optimization for cbp", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CBP_RD }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"qprd", "use rate distortion optimization for qp selection", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_QP_RD }, INT_MIN, INT_MAX, V|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"aiv", "h263 alternative inter vlc", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_AIV }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"slice", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_H263P_SLICE_STRUCT }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"ilme", "interlaced motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_INTERLACED_ME }, INT_MIN, INT_MAX, V|E, "flags"}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"scan_offset", "will reserve space for svcd scan offset user data", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_SVCD_SCAN_OFFSET }, INT_MIN, INT_MAX, V|E, "flags"}, ++#endif ++{"cgop", "closed gop", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG_CLOSED_GOP }, INT_MIN, INT_MAX, V|E, "flags"}, ++{"fast", "allow non spec compliant speedup tricks", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FAST }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"sgop", "strictly enforce gop size", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_STRICT_GOP }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"noout", "skip bitstream encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NO_OUTPUT }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"local_header", "place global headers at every keyframe instead of in extradata", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_LOCAL_HEADER }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"showall", "Show all frames before the first keyframe", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SHOW_ALL }, INT_MIN, INT_MAX, V|D, "flags2"}, ++{"sub_id", NULL, OFFSET(sub_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"me_method", "set motion estimation method", OFFSET(me_method), AV_OPT_TYPE_INT, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method"}, ++{"zero", "zero motion estimation (fastest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_ZERO }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"full", "full motion estimation (slowest)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"epzs", "EPZS motion estimation (default)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"esa", "esa motion estimation (alias for full)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_FULL }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"tesa", "tesa motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_TESA }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"dia", "dia motion estimation (alias for epzs)", 0, AV_OPT_TYPE_CONST, {.dbl = ME_EPZS }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"log", "log motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_LOG }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"phods", "phods motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_PHODS }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"x1", "X1 motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_X1 }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"hex", "hex motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_HEX }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"umh", "umh motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_UMH }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"iter", "iter motion estimation", 0, AV_OPT_TYPE_CONST, {.dbl = ME_ITER }, INT_MIN, INT_MAX, V|E, "me_method" }, ++{"extradata_size", NULL, OFFSET(extradata_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"time_base", NULL, OFFSET(time_base), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, INT_MIN, INT_MAX}, ++{"g", "set the group of picture size", OFFSET(gop_size), AV_OPT_TYPE_INT, {.dbl = 12 }, INT_MIN, INT_MAX, V|E}, ++{"ar", "set audio sampling rate (in Hz)", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E}, ++{"ac", "set number of audio channels", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|D|E}, ++{"cutoff", "set cutoff bandwidth", OFFSET(cutoff), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E}, ++{"frame_size", NULL, OFFSET(frame_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|E}, ++{"frame_number", NULL, OFFSET(frame_number), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"delay", NULL, OFFSET(delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"qcomp", "video quantizer scale compression (VBR)", OFFSET(qcompress), AV_OPT_TYPE_FLOAT, {.dbl = 0.5 }, -FLT_MAX, FLT_MAX, V|E}, ++{"qblur", "video quantizer scale blur (VBR)", OFFSET(qblur), AV_OPT_TYPE_FLOAT, {.dbl = 0.5 }, -1, FLT_MAX, V|E}, ++{"qmin", "min video quantizer scale (VBR)", OFFSET(qmin), AV_OPT_TYPE_INT, {.dbl = 2 }, -1, 69, V|E}, ++{"qmax", "max video quantizer scale (VBR)", OFFSET(qmax), AV_OPT_TYPE_INT, {.dbl = 31 }, -1, 69, V|E}, ++{"qdiff", "max difference between the quantizer scale (VBR)", OFFSET(max_qdiff), AV_OPT_TYPE_INT, {.dbl = 3 }, INT_MIN, INT_MAX, V|E}, ++{"bf", "use 'frames' B frames", OFFSET(max_b_frames), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -1, FF_MAX_B_FRAMES, V|E}, ++{"b_qfactor", "qp factor between p and b frames", OFFSET(b_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E}, ++{"rc_strategy", "ratecontrol method", OFFSET(rc_strategy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"b_strategy", "strategy to choose between I/P/B-frames", OFFSET(b_frame_strategy), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, ++#if FF_API_X264_GLOBAL_OPTS ++{"wpredp", "weighted prediction analysis method", OFFSET(weighted_p_pred), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, ++#endif ++{"ps", "rtp payload size in bytes", OFFSET(rtp_payload_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"mv_bits", NULL, OFFSET(mv_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"header_bits", NULL, OFFSET(header_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"i_tex_bits", NULL, OFFSET(i_tex_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"p_tex_bits", NULL, OFFSET(p_tex_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"i_count", NULL, OFFSET(i_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"p_count", NULL, OFFSET(p_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"skip_count", NULL, OFFSET(skip_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"misc_bits", NULL, OFFSET(misc_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"frame_bits", NULL, OFFSET(frame_bits), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"codec_tag", NULL, OFFSET(codec_tag), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"bug", "workaround not auto detected encoder bugs", OFFSET(workaround_bugs), AV_OPT_TYPE_FLAGS, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"autodetect", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AUTODETECT }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"old_msmpeg4", "some old lavc generated msmpeg4v3 files (no autodetection)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_OLD_MSMPEG4 }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"xvid_ilace", "Xvid interlacing bug (autodetected if fourcc==XVIX)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_XVID_ILACE }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"ump4", "(autodetected if fourcc==UMP4)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_UMP4 }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"no_padding", "padding bug (autodetected)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_NO_PADDING }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"amv", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AMV }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"ac_vlc", "illegal vlc bug (autodetected per fourcc)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_AC_VLC }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"qpel_chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"std_qpel", "old standard qpel (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_STD_QPEL }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"qpel_chroma2", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_QPEL_CHROMA2 }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"direct_blocksize", "direct-qpel-blocksize bug (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DIRECT_BLOCKSIZE }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"edge", "edge padding bug (autodetected per fourcc/version)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_EDGE }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"hpel_chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_HPEL_CHROMA }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"dc_clip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_DC_CLIP }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"ms", "workaround various bugs in microsofts broken decoders", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_MS }, INT_MIN, INT_MAX, V|D, "bug"}, ++{"trunc", "trancated frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_BUG_TRUNCATED}, INT_MIN, INT_MAX, V|D, "bug"}, ++{"lelim", "single coefficient elimination threshold for luminance (negative values also consider dc coefficient)", OFFSET(luma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"celim", "single coefficient elimination threshold for chrominance (negative values also consider dc coefficient)", OFFSET(chroma_elim_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"strict", "how strictly to follow the standards", OFFSET(strict_std_compliance), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|D|E, "strict"}, ++{"very", "strictly conform to a older more strict version of the spec or reference software", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_VERY_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"}, ++{"strict", "strictly conform to all the things in the spec no matter what consequences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_STRICT }, INT_MIN, INT_MAX, V|D|E, "strict"}, ++{"normal", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_NORMAL }, INT_MIN, INT_MAX, V|D|E, "strict"}, ++{"unofficial", "allow unofficial extensions", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_UNOFFICIAL }, INT_MIN, INT_MAX, V|D|E, "strict"}, ++{"experimental", "allow non standardized experimental things", 0, AV_OPT_TYPE_CONST, {.dbl = FF_COMPLIANCE_EXPERIMENTAL }, INT_MIN, INT_MAX, V|D|E, "strict"}, ++{"b_qoffset", "qp offset between P and B frames", OFFSET(b_quant_offset), AV_OPT_TYPE_FLOAT, {.dbl = 1.25 }, -FLT_MAX, FLT_MAX, V|E}, ++#if FF_API_ER ++{"er", "set error detection aggressivity", OFFSET(error_recognition), AV_OPT_TYPE_INT, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "er"}, ++{"careful", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_CAREFUL }, INT_MIN, INT_MAX, V|D, "er"}, ++{"compliant", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_COMPLIANT }, INT_MIN, INT_MAX, V|D, "er"}, ++{"aggressive", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"}, ++{"very_aggressive", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_VERY_AGGRESSIVE }, INT_MIN, INT_MAX, V|D, "er"}, ++{"explode", "abort decoding on error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_ER_EXPLODE }, INT_MIN, INT_MAX, V|D, "er"}, ++#endif /* FF_API_ER */ ++{"err_detect", "set error detection flags", OFFSET(err_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"bitstream", "detect bitstream specification deviations", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BUFFER }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_EXPLODE }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"careful", "consider things that violate the spec and have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CAREFUL }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, A|V|D, "err_detect"}, ++{"has_b_frames", NULL, OFFSET(has_b_frames), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"block_align", NULL, OFFSET(block_align), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++#if FF_API_PARSE_FRAME ++{"parse_only", NULL, OFFSET(parse_only), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++#endif ++{"mpeg_quant", "use MPEG quantizers instead of H.263", OFFSET(mpeg_quant), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"stats_out", NULL, OFFSET(stats_out), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX}, ++{"stats_in", NULL, OFFSET(stats_in), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX}, ++{"qsquish", "how to keep quantizer between qmin and qmax (0 = clip, 1 = use differentiable function)", OFFSET(rc_qsquish), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 99, V|E}, ++{"rc_qmod_amp", "experimental quantizer modulation", OFFSET(rc_qmod_amp), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E}, ++{"rc_qmod_freq", "experimental quantizer modulation", OFFSET(rc_qmod_freq), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"rc_override_count", NULL, OFFSET(rc_override_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"rc_eq", "set rate control equation", OFFSET(rc_eq), AV_OPT_TYPE_STRING, {.str = NULL}, CHAR_MIN, CHAR_MAX, V|E}, ++{"maxrate", "set max video bitrate tolerance (in bits/s)", OFFSET(rc_max_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"minrate", "set min video bitrate tolerance (in bits/s)", OFFSET(rc_min_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"bufsize", "set ratecontrol buffer size (in bits)", OFFSET(rc_buffer_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, A|V|E}, ++{"rc_buf_aggressivity", "currently useless", OFFSET(rc_buffer_aggressivity), AV_OPT_TYPE_FLOAT, {.dbl = 1.0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"i_qfactor", "qp factor between P and I frames", OFFSET(i_quant_factor), AV_OPT_TYPE_FLOAT, {.dbl = -0.8 }, -FLT_MAX, FLT_MAX, V|E}, ++{"i_qoffset", "qp offset between P and I frames", OFFSET(i_quant_offset), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"rc_init_cplx", "initial complexity for 1-pass encoding", OFFSET(rc_initial_cplx), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E}, ++{"dct", "DCT algorithm", OFFSET(dct_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E, "dct"}, ++{"auto", "autoselect a good one (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_AUTO }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"fastint", "fast integer", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_FASTINT }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"int", "accurate integer", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_INT }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"mmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_MMX }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"mlib", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_MLIB }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"altivec", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_ALTIVEC }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"faan", "floating point AAN DCT", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DCT_FAAN }, INT_MIN, INT_MAX, V|E, "dct"}, ++{"lumi_mask", "compresses bright areas stronger than medium ones", OFFSET(lumi_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"p_mask", "inter masking", OFFSET(p_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"dark_mask", "compresses dark areas stronger than medium ones", OFFSET(dark_masking), AV_OPT_TYPE_FLOAT, {.dbl = 0 }, -FLT_MAX, FLT_MAX, V|E}, ++{"idct", "select IDCT implementation", OFFSET(idct_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|E|D, "idct"}, ++{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_AUTO }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"int", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_INT }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simple", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLE }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simplemmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEMMX }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"libmpeg2mmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_LIBMPEG2MMX }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"ps2", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_PS2 }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"mlib", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_MLIB }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"arm", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_ARM }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"altivec", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_ALTIVEC }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"sh4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SH4 }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simplearm", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARM }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simplearmv5te", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV5TE }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simplearmv6", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEARMV6 }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simpleneon", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLENEON }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"simplealpha", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_SIMPLEALPHA }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"h264", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_H264 }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"vp3", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_VP3 }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"ipp", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_IPP }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"xvidmmx", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_XVIDMMX }, INT_MIN, INT_MAX, V|E|D, "idct"}, ++{"faani", "floating point AAN IDCT", 0, AV_OPT_TYPE_CONST, {.dbl = FF_IDCT_FAAN }, INT_MIN, INT_MAX, V|D|E, "idct"}, ++{"slice_count", NULL, OFFSET(slice_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"ec", "set error concealment strategy", OFFSET(error_concealment), AV_OPT_TYPE_FLAGS, {.dbl = 3 }, INT_MIN, INT_MAX, V|D, "ec"}, ++{"guess_mvs", "iterative motion vector (MV) search (slow)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_EC_GUESS_MVS }, INT_MIN, INT_MAX, V|D, "ec"}, ++{"deblock", "use strong deblock filter for damaged MBs", 0, AV_OPT_TYPE_CONST, {.dbl = FF_EC_DEBLOCK }, INT_MIN, INT_MAX, V|D, "ec"}, ++{"bits_per_coded_sample", NULL, OFFSET(bits_per_coded_sample), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"pred", "prediction method", OFFSET(prediction_method), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "pred"}, ++{"left", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_LEFT }, INT_MIN, INT_MAX, V|E, "pred"}, ++{"plane", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_PLANE }, INT_MIN, INT_MAX, V|E, "pred"}, ++{"median", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PRED_MEDIAN }, INT_MIN, INT_MAX, V|E, "pred"}, ++{"aspect", "sample aspect ratio", OFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0}, 0, 10, V|E}, ++{"debug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, V|A|S|E|D, "debug"}, ++{"pict", "picture info", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PICT_INFO }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"rc", "rate control", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_RC }, INT_MIN, INT_MAX, V|E, "debug"}, ++{"bitstream", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BITSTREAM }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"mb_type", "macroblock (MB) type", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"qp", "per-block quantization parameter (QP)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_QP }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"mv", "motion vector", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MV }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"dct_coeff", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_DCT_COEFF }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"skip", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_SKIP }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"startcode", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_STARTCODE }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"pts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_PTS }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"er", "error recognition", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_ER }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"mmco", "memory management control operations (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_MMCO }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"bugs", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUGS }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"vis_qp", "visualize quantization parameter (QP), lower QP are tinted greener", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_QP }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"vis_mb_type", "visualize block types", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MB_TYPE }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"buffers", "picture buffer allocations", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_BUFFERS }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"thread_ops", "threading operations", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_THREADS }, INT_MIN, INT_MAX, V|D, "debug"}, ++{"vismv", "visualize motion vectors (MVs)", OFFSET(debug_mv), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, V|D, "debug_mv"}, ++{"pf", "forward predicted MVs of P-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_P_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"}, ++{"bf", "forward predicted MVs of B-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_FOR }, INT_MIN, INT_MAX, V|D, "debug_mv"}, ++{"bb", "backward predicted MVs of B-frames", 0, AV_OPT_TYPE_CONST, {.dbl = FF_DEBUG_VIS_MV_B_BACK }, INT_MIN, INT_MAX, V|D, "debug_mv"}, ++{"cmp", "full pel me compare function", OFFSET(me_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"mbcmp", "macroblock compare function", OFFSET(mb_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), AV_OPT_TYPE_INT, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"dia_size", "diamond type & size for motion estimation", OFFSET(dia_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"last_pred", "amount of motion predictors from the previous frame", OFFSET(last_predictor_count), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"preme", "pre motion estimation", OFFSET(pre_me), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"sad", "sum of absolute differences, fast (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SAD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"sse", "sum of squared errors", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SSE }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"satd", "sum of absolute Hadamard transformed differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_SATD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"dct", "sum of absolute DCT transformed differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_DCT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"psnr", "sum of squared quantization errors (avoid, low quality)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_PSNR }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"bit", "number of bits needed for the block", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_BIT }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"rd", "rate distortion optimal, slow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_RD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"zero", "0", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_ZERO }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"vsad", "sum of absolute vertical differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_VSAD }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"vsse", "sum of squared vertical differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_VSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"nsse", "noise preserving sum of squared differences", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_NSSE }, INT_MIN, INT_MAX, V|E, "cmp_func"}, + #if CONFIG_SNOW_ENCODER +-{"w53", "5/3 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"w97", "9/7 wavelet, only used in snow", 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"w53", "5/3 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_W53 }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"w97", "9/7 wavelet, only used in snow", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_W97 }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++#endif ++{"dctmax", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"chroma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_CMP_CHROMA }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), AV_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E}, ++{"dtg_active_format", NULL, OFFSET(dtg_active_format), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"ibias", "intra quant bias", OFFSET(intra_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E}, ++{"pbias", "inter quant bias", OFFSET(inter_quant_bias), AV_OPT_TYPE_INT, {.dbl = FF_DEFAULT_QUANT_BIAS }, INT_MIN, INT_MAX, V|E}, ++{"color_table_id", NULL, OFFSET(color_table_id), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"global_quality", NULL, OFFSET(global_quality), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E}, ++{"coder", NULL, OFFSET(coder_type), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"vlc", "variable length coder / huffman coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_VLC }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"ac", "arithmetic coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_AC }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"raw", "raw (no encoding)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RAW }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"rle", "run-length coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_RLE }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"deflate", "deflate-based coder", 0, AV_OPT_TYPE_CONST, {.dbl = FF_CODER_TYPE_DEFLATE }, INT_MIN, INT_MAX, V|E, "coder"}, ++{"context", "context model", OFFSET(context_model), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"slice_flags", NULL, OFFSET(slice_flags), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "mbd"}, ++{"simple", "use mbcmp (default)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_SIMPLE }, INT_MIN, INT_MAX, V|E, "mbd"}, ++{"bits", "use fewest bits", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_BITS }, INT_MIN, INT_MAX, V|E, "mbd"}, ++{"rd", "use best rate distortion", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MB_DECISION_RD }, INT_MIN, INT_MAX, V|E, "mbd"}, ++{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), AV_OPT_TYPE_INT, {.dbl = 2*FF_QP2LAMBDA }, 0, INT_MAX, V|E}, ++{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), AV_OPT_TYPE_INT, {.dbl = 31*FF_QP2LAMBDA }, 0, INT_MAX, V|E}, ++{"nr", "noise reduction", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"inter_threshold", NULL, OFFSET(inter_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++#if FF_API_X264_GLOBAL_OPTS ++#define X264_DEFAULTS CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_PSY|CODEC_FLAG2_MBTREE ++#else ++#define X264_DEFAULTS 0 ++#endif ++#if FF_API_LAME_GLOBAL_OPTS ++#define LAME_DEFAULTS CODEC_FLAG2_BIT_RESERVOIR ++#else ++#define LAME_DEFAULTS 0 ++#endif ++{"flags2", NULL, OFFSET(flags2), AV_OPT_TYPE_FLAGS, {.dbl = X264_DEFAULTS|LAME_DEFAULTS }, 0, UINT_MAX, V|A|E|D, "flags2"}, ++{"error", NULL, OFFSET(error_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++#if FF_API_ANTIALIAS_ALGO ++{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D, "aa"}, ++{"auto", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_AUTO }, INT_MIN, INT_MAX, V|D, "aa"}, ++{"fastint", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_FASTINT }, INT_MIN, INT_MAX, V|D, "aa"}, ++{"int", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_INT }, INT_MIN, INT_MAX, V|D, "aa"}, ++{"float", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_AA_FLOAT }, INT_MIN, INT_MAX, V|D, "aa"}, ++#endif ++{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"threads", NULL, OFFSET(thread_count), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, INT_MAX, V|E|D, "threads"}, ++{"auto", "detect a good number of threads", 0, AV_OPT_TYPE_CONST, {.dbl = 0 }, INT_MIN, INT_MAX, V|E|D, "threads"}, ++{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX, V|E}, ++{"nssew", "nsse weight", OFFSET(nsse_weight), AV_OPT_TYPE_INT, {.dbl = 8 }, INT_MIN, INT_MAX, V|E}, ++{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D}, ++{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|D}, ++{"profile", NULL, OFFSET(profile), AV_OPT_TYPE_INT, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"}, ++{"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "profile"}, ++{"aac_main", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_MAIN }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"aac_low", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LOW }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"aac_ssr", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_SSR }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"aac_ltp", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_AAC_LTP }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"dts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"dts_es", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_ES }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"dts_96_24", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_96_24 }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"dts_hd_hra", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_HRA }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"dts_hd_ma", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_PROFILE_DTS_HD_MA }, INT_MIN, INT_MAX, A|E, "profile"}, ++{"level", NULL, OFFSET(level), AV_OPT_TYPE_INT, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"}, ++{"unknown", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_LEVEL_UNKNOWN }, INT_MIN, INT_MAX, V|A|E, "level"}, ++{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|A|D}, ++{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), AV_OPT_TYPE_INT, {.dbl = FF_CMP_DCTMAX }, INT_MIN, INT_MAX, V|E, "cmp_func"}, ++{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, -FLT_MAX, FLT_MAX, V|E}, ++{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), AV_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 2 }, 1, FF_LAMBDA_MAX, V|E}, ++{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), AV_OPT_TYPE_INT, {.dbl = FF_QP2LAMBDA * 31 }, 1, FF_LAMBDA_MAX, V|E}, ++{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), AV_OPT_TYPE_INT, {.dbl = 256 }, INT_MIN, INT_MAX, V|E}, ++{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"skip_idct" , NULL, OFFSET(skip_idct) , AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"skip_frame" , NULL, OFFSET(skip_frame) , AV_OPT_TYPE_INT, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"none" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONE }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"default" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_DEFAULT }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"noref" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONREF }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"bidir" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_BIDIR }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"nokey" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_NONKEY }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"all" , NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AVDISCARD_ALL }, INT_MIN, INT_MAX, V|D, "avdiscard"}, ++{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), AV_OPT_TYPE_INT, {.dbl = 1 }, 0, 4, V|E}, ++{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, 10, V|E}, ++#if FF_API_X264_GLOBAL_OPTS ++{"crf", "enables constant quality mode, and selects the quality (x264/VP8)", OFFSET(crf), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 63, V|E}, ++{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, ++#endif ++{"keyint_min", "minimum interval between IDR-frames", OFFSET(keyint_min), AV_OPT_TYPE_INT, {.dbl = 25 }, INT_MIN, INT_MAX, V|E}, ++{"refs", "reference frames to consider for motion compensation", OFFSET(refs), AV_OPT_TYPE_INT, {.dbl = 1 }, INT_MIN, INT_MAX, V|E}, ++{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++#if FF_API_X264_GLOBAL_OPTS ++{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E}, ++#endif ++{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|A|E}, ++#if FF_API_X264_GLOBAL_OPTS ++{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, V|E}, ++{"bpyramid", "allows B-frames to be used as references for predicting", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BPYRAMID }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"wpred", "weighted biprediction for b-frames (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_WPRED }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MIXED_REFS }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"dct8x8", "high profile 8x8 transform (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_8X8DCT }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"fastpskip", "fast pskip (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_FASTPSKIP }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"aud", "access unit delimiters (H.264)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_AUD }, INT_MIN, INT_MAX, V|E, "flags2"}, ++#endif ++{"skiprd", "RD optimal MB level residual skipping", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SKIP_RD }, INT_MIN, INT_MAX, V|E, "flags2"}, ++#if FF_API_X264_GLOBAL_OPTS ++{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E}, ++{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E}, ++{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, -6, 6, V|E}, ++{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, V|E, "partitions"}, ++{"parti4x4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_I4X4 }, INT_MIN, INT_MAX, V|E, "partitions"}, ++{"parti8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_I8X8 }, INT_MIN, INT_MAX, V|E, "partitions"}, ++{"partp4x4", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_P4X4 }, INT_MIN, INT_MAX, V|E, "partitions"}, ++{"partp8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_P8X8 }, INT_MIN, INT_MAX, V|E, "partitions"}, ++{"partb8x8", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = X264_PART_B8X8 }, INT_MIN, INT_MAX, V|E, "partitions"}, ++#endif ++{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), AV_OPT_TYPE_INT, {.dbl = 6 }, 0, INT_MAX, V|E}, ++{"mv0_threshold", NULL, OFFSET(mv0_threshold), AV_OPT_TYPE_INT, {.dbl = 256 }, 0, INT_MAX, V|E}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"ivlc", "intra vlc table", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_VLC }, INT_MIN, INT_MAX, V|E, "flags2"}, ++#endif ++{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), AV_OPT_TYPE_INT, {.dbl = 40 }, 1, INT_MAX, V|E}, ++{"compression_level", NULL, OFFSET(compression_level), AV_OPT_TYPE_INT, {.dbl = FF_COMPRESSION_DEFAULT }, INT_MIN, INT_MAX, V|A|E}, ++{"min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++{"max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++#if FF_API_FLAC_GLOBAL_OPTS ++{"lpc_coeff_precision", "deprecated, use flac-specific options", OFFSET(lpc_coeff_precision), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|E}, ++{"prediction_order_method", "deprecated, use flac-specific options", OFFSET(prediction_order_method), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++{"min_partition_order", "deprecated, use flac-specific options", OFFSET(min_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++{"max_partition_order", "deprecated, use flac-specific options", OFFSET(max_partition_order), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++#endif ++{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), AV_OPT_TYPE_INT64, {.dbl = 0 }, 0, INT64_MAX, V|E}, ++#if FF_API_MPEGVIDEO_GLOBAL_OPTS ++{"drop_frame_timecode", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_DROP_FRAME_TIMECODE }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"non_linear_q", "use non linear quantizer", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_NON_LINEAR_QUANT }, INT_MIN, INT_MAX, V|E, "flags2"}, ++#endif ++#if FF_API_REQUEST_CHANNELS ++{"request_channels", "set desired number of audio channels", OFFSET(request_channels), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, A|D}, + #endif +-{"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"pre_dia_size", "diamond type & size for motion estimation pre-pass", OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E}, +-{"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"me_range", "limit motion vectors range (1023 for DivX player)", OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"ibias", "intra quant bias", OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E}, +-{"pbias", "inter quant bias", OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, FF_DEFAULT_QUANT_BIAS, INT_MIN, INT_MAX, V|E}, +-{"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"}, +-{"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"}, +-{"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"}, +-{"raw", "raw (no encoding)", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RAW, INT_MIN, INT_MAX, V|E, "coder"}, +-{"rle", "run-length coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_RLE, INT_MIN, INT_MAX, V|E, "coder"}, +-{"deflate", "deflate-based coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_DEFLATE, INT_MIN, INT_MAX, V|E, "coder"}, +-{"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"mbd", "macroblock decision algorithm (high quality mode)", OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"}, +-{"simple", "use mbcmp (default)", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"}, +-{"bits", "use fewest bits", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"}, +-{"rd", "use best rate distortion", 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"}, +-{"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"sc_threshold", "scene change threshold", OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"lmin", "min lagrange factor (VBR)", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E}, +-{"lmax", "max lagrange factor (VBR)", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E}, +-{"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"rc_init_occupancy", "number of bits which should be loaded into the rc buffer before decoding starts", OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, CODEC_FLAG2_FASTPSKIP|CODEC_FLAG2_BIT_RESERVOIR|CODEC_FLAG2_PSY|CODEC_FLAG2_MBTREE, 0, UINT_MAX, V|A|E|D, "flags2"}, +-{"error", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"antialias", "MP3 antialias algorithm", OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"}, +-{"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"}, +-{"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"}, +-{"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"}, +-{"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"}, +-{"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"threads", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E|D}, +-{"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"mb_threshold", "macroblock threshold", OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"dc", "intra_dc_precision", OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E}, +-{"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E}, +-{"skip_top", "number of macroblock rows at the top which are skipped", OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, +-{"skip_bottom", "number of macroblock rows at the bottom which are skipped", OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D}, +-{"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"}, +-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"}, +-{"aac_main", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_MAIN, INT_MIN, INT_MAX, A|E, "profile"}, +-{"aac_low", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LOW, INT_MIN, INT_MAX, A|E, "profile"}, +-{"aac_ssr", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_SSR, INT_MIN, INT_MAX, A|E, "profile"}, +-{"aac_ltp", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_AAC_LTP, INT_MIN, INT_MAX, A|E, "profile"}, +-{"dts", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_DTS, INT_MIN, INT_MAX, A|E, "profile"}, +-{"dts_es", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_DTS_ES, INT_MIN, INT_MAX, A|E, "profile"}, +-{"dts_96_24", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_DTS_96_24, INT_MIN, INT_MAX, A|E, "profile"}, +-{"dts_hd_hra", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_DTS_HD_HRA, INT_MIN, INT_MAX, A|E, "profile"}, +-{"dts_hd_ma", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_DTS_HD_MA, INT_MIN, INT_MAX, A|E, "profile"}, +-{"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"}, +-{"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"}, +-{"lowres", "decode at 1= 1/2, 2=1/4, 3=1/8 resolutions", OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|A|D}, +-{"skip_threshold", "frame skip threshold", OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"skip_factor", "frame skip factor", OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"skip_exp", "frame skip exponent", OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"}, +-{"border_mask", "increases the quantizer for macroblocks close to borders", OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, -FLT_MAX, FLT_MAX, V|E}, +-{"mblmin", "min macroblock lagrange factor (VBR)", OFFSET(mb_lmin), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 2, 1, FF_LAMBDA_MAX, V|E}, +-{"mblmax", "max macroblock lagrange factor (VBR)", OFFSET(mb_lmax), FF_OPT_TYPE_INT, FF_QP2LAMBDA * 31, 1, FF_LAMBDA_MAX, V|E}, +-{"mepc", "motion estimation bitrate penalty compensation (1.0 = 256)", OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, 256, INT_MIN, INT_MAX, V|E}, +-{"skip_loop_filter", NULL, OFFSET(skip_loop_filter), FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"skip_idct" , NULL, OFFSET(skip_idct) , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"skip_frame" , NULL, OFFSET(skip_frame) , FF_OPT_TYPE_INT, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"none" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONE , INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"default" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_DEFAULT, INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"noref" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONREF , INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"bidir" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_BIDIR , INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"nokey" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_NONKEY , INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"all" , NULL, 0, FF_OPT_TYPE_CONST, AVDISCARD_ALL , INT_MIN, INT_MAX, V|D, "avdiscard"}, +-{"bidir_refine", "refine the two motion vectors used in bidirectional macroblocks", OFFSET(bidir_refine), FF_OPT_TYPE_INT, 1, 0, 4, V|E}, +-{"brd_scale", "downscales frames for dynamic B-frame decision", OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E}, +-{"crf", "enables constant quality mode, and selects the quality (x264)", OFFSET(crf), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E}, +-{"cqp", "constant quantization parameter rate control method", OFFSET(cqp), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, V|E}, +-{"keyint_min", "minimum interval between IDR-frames (x264)", OFFSET(keyint_min), FF_OPT_TYPE_INT, 25, INT_MIN, INT_MAX, V|E}, +-{"refs", "reference frames to consider for motion compensation (Snow)", OFFSET(refs), FF_OPT_TYPE_INT, 1, INT_MIN, INT_MAX, V|E}, +-{"chromaoffset", "chroma qp offset from luma", OFFSET(chromaoffset), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"bframebias", "influences how often B-frames are used", OFFSET(bframebias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E}, +-{"trellis", "rate-distortion optimal quantization", OFFSET(trellis), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E}, +-{"directpred", "direct mv prediction mode - 0 (none), 1 (spatial), 2 (temporal), 3 (auto)", OFFSET(directpred), FF_OPT_TYPE_INT, 2, INT_MIN, INT_MAX, V|E}, +-{"bpyramid", "allows B-frames to be used as references for predicting", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BPYRAMID, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"wpred", "weighted biprediction for b-frames (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_WPRED, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"mixed_refs", "one reference per partition, as opposed to one reference per macroblock", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MIXED_REFS, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"dct8x8", "high profile 8x8 transform (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_8X8DCT, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"fastpskip", "fast pskip (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FASTPSKIP, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"aud", "access unit delimiters (H.264)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_AUD, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"skiprd", "RD optimal MB level residual skipping", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SKIP_RD, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"complexityblur", "reduce fluctuations in qp (before curve compression)", OFFSET(complexityblur), FF_OPT_TYPE_FLOAT, 20.0, FLT_MIN, FLT_MAX, V|E}, +-{"deblockalpha", "in-loop deblocking filter alphac0 parameter", OFFSET(deblockalpha), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E}, +-{"deblockbeta", "in-loop deblocking filter beta parameter", OFFSET(deblockbeta), FF_OPT_TYPE_INT, DEFAULT, -6, 6, V|E}, +-{"partitions", "macroblock subpartition sizes to consider", OFFSET(partitions), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"parti4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I4X4, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"parti8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_I8X8, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"partp4x4", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P4X4, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"partp8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_P8X8, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"partb8x8", NULL, 0, FF_OPT_TYPE_CONST, X264_PART_B8X8, INT_MIN, INT_MAX, V|E, "partitions"}, +-{"sc_factor", "multiplied by qscale for each frame and added to scene_change_score", OFFSET(scenechange_factor), FF_OPT_TYPE_INT, 6, 0, INT_MAX, V|E}, +-{"mv0_threshold", NULL, OFFSET(mv0_threshold), FF_OPT_TYPE_INT, 256, 0, INT_MAX, V|E}, +-{"ivlc", "intra vlc table", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_VLC, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"b_sensitivity", "adjusts sensitivity of b_frame_strategy 1", OFFSET(b_sensitivity), FF_OPT_TYPE_INT, 40, 1, INT_MAX, V|E}, +-{"compression_level", NULL, OFFSET(compression_level), FF_OPT_TYPE_INT, FF_COMPRESSION_DEFAULT, INT_MIN, INT_MAX, V|A|E}, +-#if FF_API_USE_LPC +-{"use_lpc", "sets whether to use LPC mode (FLAC)", OFFSET(use_lpc), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-#endif +-{"lpc_coeff_precision", "LPC coefficient precision (FLAC)", OFFSET(lpc_coeff_precision), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|E}, +-{"min_prediction_order", NULL, OFFSET(min_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"max_prediction_order", NULL, OFFSET(max_prediction_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"prediction_order_method", "search method for selecting prediction order", OFFSET(prediction_order_method), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"min_partition_order", NULL, OFFSET(min_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"max_partition_order", NULL, OFFSET(max_partition_order), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"timecode_frame_start", "GOP timecode frame start number, in non drop frame format", OFFSET(timecode_frame_start), FF_OPT_TYPE_INT64, 0, 0, INT64_MAX, V|E}, +-{"drop_frame_timecode", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_DROP_FRAME_TIMECODE, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"non_linear_q", "use non linear quantizer", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NON_LINEAR_QUANT, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"request_channels", "set desired number of audio channels", OFFSET(request_channels), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, A|D}, +-{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), FF_OPT_TYPE_FLOAT, 1.0, 0.0, 1.0, A|D}, +-{"reservoir", "use bit reservoir", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_BIT_RESERVOIR, INT_MIN, INT_MAX, A|E, "flags2"}, +-{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_MBTREE, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX}, +-{"channel_layout", NULL, OFFSET(channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|E|D, "channel_layout"}, +-{"request_channel_layout", NULL, OFFSET(request_channel_layout), FF_OPT_TYPE_INT64, DEFAULT, 0, INT64_MAX, A|D, "request_channel_layout"}, +-{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), FF_OPT_TYPE_FLOAT, 1.0/3, 0.0, FLT_MAX, V|E}, +-{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), FF_OPT_TYPE_FLOAT, 3, 0.0, FLT_MAX, V|E}, +-{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), FF_OPT_TYPE_INT, 1, 1, INT_MAX, A|V|E|D}, +-{"color_primaries", NULL, OFFSET(color_primaries), FF_OPT_TYPE_INT, AVCOL_PRI_UNSPECIFIED, 1, AVCOL_PRI_NB-1, V|E|D}, +-{"color_trc", NULL, OFFSET(color_trc), FF_OPT_TYPE_INT, AVCOL_TRC_UNSPECIFIED, 1, AVCOL_TRC_NB-1, V|E|D}, +-{"colorspace", NULL, OFFSET(colorspace), FF_OPT_TYPE_INT, AVCOL_SPC_UNSPECIFIED, 1, AVCOL_SPC_NB-1, V|E|D}, +-{"color_range", NULL, OFFSET(color_range), FF_OPT_TYPE_INT, AVCOL_RANGE_UNSPECIFIED, 0, AVCOL_RANGE_NB-1, V|E|D}, +-{"chroma_sample_location", NULL, OFFSET(chroma_sample_location), FF_OPT_TYPE_INT, AVCHROMA_LOC_UNSPECIFIED, 0, AVCHROMA_LOC_NB-1, V|E|D}, +-{"psy", "use psycho visual optimization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_PSY, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E}, +-{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), FF_OPT_TYPE_FLOAT, 0, 0, FLT_MAX, V|E}, +-{"aq_mode", "specify aq method", OFFSET(aq_mode), FF_OPT_TYPE_INT, 1, 0, INT_MAX, V|E}, +-{"aq_strength", "specify aq strength", OFFSET(aq_strength), FF_OPT_TYPE_FLOAT, 1.0, 0, FLT_MAX, V|E}, +-{"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), FF_OPT_TYPE_INT, 40, 0, INT_MAX, V|E}, +-{"ssim", "ssim will be calculated during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_SSIM, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_INTRA_REFRESH, INT_MIN, INT_MAX, V|E, "flags2"}, +-{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), FF_OPT_TYPE_FLOAT, DEFAULT, 0, 51, V|E}, +-{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX }, +-{"lpc_type", "specify LPC algorithm", OFFSET(lpc_type), FF_OPT_TYPE_INT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E}, +-{"none", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_NONE, INT_MIN, INT_MAX, A|E, "lpc_type"}, +-{"fixed", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_FIXED, INT_MIN, INT_MAX, A|E, "lpc_type"}, +-{"levinson", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_LEVINSON, INT_MIN, INT_MAX, A|E, "lpc_type"}, +-{"cholesky", NULL, 0, FF_OPT_TYPE_CONST, AV_LPC_TYPE_CHOLESKY, INT_MIN, INT_MAX, A|E, "lpc_type"}, +-{"lpc_passes", "number of passes to use for Cholesky factorization during LPC analysis", OFFSET(lpc_passes), FF_OPT_TYPE_INT, -1, INT_MIN, INT_MAX, A|E}, +-{"slices", "number of slices, used in parallelized decoding", OFFSET(slices), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|E}, ++#if FF_API_DRC_SCALE ++{"drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 0.0 }, 0.0, 1.0, A|D}, ++#endif ++#if FF_API_LAME_GLOBAL_OPTS ++{"reservoir", "use bit reservoir", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_BIT_RESERVOIR }, INT_MIN, INT_MAX, A|E, "flags2"}, ++#endif ++#if FF_API_X264_GLOBAL_OPTS ++{"mbtree", "use macroblock tree ratecontrol (x264 only)", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_MBTREE }, INT_MIN, INT_MAX, V|E, "flags2"}, ++#endif ++{"bits_per_raw_sample", NULL, OFFSET(bits_per_raw_sample), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, INT_MIN, INT_MAX}, ++{"channel_layout", NULL, OFFSET(channel_layout), AV_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|E|D, "channel_layout"}, ++{"request_channel_layout", NULL, OFFSET(request_channel_layout), AV_OPT_TYPE_INT64, {.dbl = DEFAULT }, 0, INT64_MAX, A|D, "request_channel_layout"}, ++{"rc_max_vbv_use", NULL, OFFSET(rc_max_available_vbv_use), AV_OPT_TYPE_FLOAT, {.dbl = 1.0/3 }, 0.0, FLT_MAX, V|E}, ++{"rc_min_vbv_use", NULL, OFFSET(rc_min_vbv_overflow_use), AV_OPT_TYPE_FLOAT, {.dbl = 3 }, 0.0, FLT_MAX, V|E}, ++{"ticks_per_frame", NULL, OFFSET(ticks_per_frame), AV_OPT_TYPE_INT, {.dbl = 1 }, 1, INT_MAX, A|V|E|D}, ++{"color_primaries", NULL, OFFSET(color_primaries), AV_OPT_TYPE_INT, {.dbl = AVCOL_PRI_UNSPECIFIED }, 1, AVCOL_PRI_NB-1, V|E|D}, ++{"color_trc", NULL, OFFSET(color_trc), AV_OPT_TYPE_INT, {.dbl = AVCOL_TRC_UNSPECIFIED }, 1, AVCOL_TRC_NB-1, V|E|D}, ++{"colorspace", NULL, OFFSET(colorspace), AV_OPT_TYPE_INT, {.dbl = AVCOL_SPC_UNSPECIFIED }, 1, AVCOL_SPC_NB-1, V|E|D}, ++{"color_range", NULL, OFFSET(color_range), AV_OPT_TYPE_INT, {.dbl = AVCOL_RANGE_UNSPECIFIED }, 0, AVCOL_RANGE_NB-1, V|E|D}, ++{"chroma_sample_location", NULL, OFFSET(chroma_sample_location), AV_OPT_TYPE_INT, {.dbl = AVCHROMA_LOC_UNSPECIFIED }, 0, AVCHROMA_LOC_NB-1, V|E|D}, ++#if FF_API_X264_GLOBAL_OPTS ++{"psy", "use psycho visual optimization", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_PSY }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"psy_rd", "specify psycho visual strength", OFFSET(psy_rd), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, ++{"psy_trellis", "specify psycho visual trellis", OFFSET(psy_trellis), AV_OPT_TYPE_FLOAT, {.dbl = -1 }, -1, FLT_MAX, V|E}, ++{"aq_mode", "specify aq method", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, ++{"aq_strength", "specify aq strength", OFFSET(aq_strength), AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1, FLT_MAX, V|E}, ++{"rc_lookahead", "specify number of frames to look ahead for frametype", OFFSET(rc_lookahead), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, INT_MAX, V|E}, ++{"ssim", "ssim will be calculated during encoding", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_SSIM }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"intra_refresh", "use periodic insertion of intra blocks instead of keyframes", 0, AV_OPT_TYPE_CONST, {.dbl = CODEC_FLAG2_INTRA_REFRESH }, INT_MIN, INT_MAX, V|E, "flags2"}, ++{"crf_max", "in crf mode, prevents vbv from lowering quality beyond this point", OFFSET(crf_max), AV_OPT_TYPE_FLOAT, {.dbl = DEFAULT }, 0, 51, V|E}, ++#endif ++{"log_level_offset", "set the log level offset", OFFSET(log_level_offset), AV_OPT_TYPE_INT, {.dbl = 0 }, INT_MIN, INT_MAX }, ++#if FF_API_FLAC_GLOBAL_OPTS ++{"lpc_type", "deprecated, use flac-specific options", OFFSET(lpc_type), AV_OPT_TYPE_INT, {.dbl = AV_LPC_TYPE_DEFAULT }, AV_LPC_TYPE_DEFAULT, AV_LPC_TYPE_NB-1, A|E}, ++{"none", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_NONE }, INT_MIN, INT_MAX, A|E, "lpc_type"}, ++{"fixed", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_FIXED }, INT_MIN, INT_MAX, A|E, "lpc_type"}, ++{"levinson", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_LEVINSON }, INT_MIN, INT_MAX, A|E, "lpc_type"}, ++{"cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = AV_LPC_TYPE_CHOLESKY }, INT_MIN, INT_MAX, A|E, "lpc_type"}, ++{"lpc_passes", "deprecated, use flac-specific options", OFFSET(lpc_passes), AV_OPT_TYPE_INT, {.dbl = -1 }, INT_MIN, INT_MAX, A|E}, ++#endif ++{"slices", "number of slices, used in parallelized encoding", OFFSET(slices), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, V|E}, ++{"thread_type", "select multithreading type", OFFSET(thread_type), AV_OPT_TYPE_FLAGS, {.dbl = FF_THREAD_SLICE|FF_THREAD_FRAME }, 0, INT_MAX, V|E|D, "thread_type"}, ++{"slice", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_THREAD_SLICE }, INT_MIN, INT_MAX, V|E|D, "thread_type"}, ++{"frame", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_THREAD_FRAME }, INT_MIN, INT_MAX, V|E|D, "thread_type"}, ++{"audio_service_type", "audio service type", OFFSET(audio_service_type), AV_OPT_TYPE_INT, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, 0, AV_AUDIO_SERVICE_TYPE_NB-1, A|E, "audio_service_type"}, ++{"ma", "Main Audio Service", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_MAIN }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"ef", "Effects", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EFFECTS }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"vi", "Visually Impaired", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"hi", "Hearing Impaired", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"di", "Dialogue", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_DIALOGUE }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"co", "Commentary", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_COMMENTARY }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"em", "Emergency", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_EMERGENCY }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"vo", "Voice Over", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_VOICE_OVER }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"ka", "Karaoke", 0, AV_OPT_TYPE_CONST, {.dbl = AV_AUDIO_SERVICE_TYPE_KARAOKE }, INT_MIN, INT_MAX, A|E, "audio_service_type"}, ++{"request_sample_fmt", "sample format audio decoders should prefer", OFFSET(request_sample_fmt), AV_OPT_TYPE_INT, {.dbl = AV_SAMPLE_FMT_NONE }, AV_SAMPLE_FMT_NONE, AV_SAMPLE_FMT_NB-1, A|D, "request_sample_fmt"}, ++{"u8" , "8-bit unsigned integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_U8 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"}, ++{"s16", "16-bit signed integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S16 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"}, ++{"s32", "32-bit signed integer", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_S32 }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"}, ++{"flt", "32-bit float", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_FLT }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"}, ++{"dbl", "64-bit double", 0, AV_OPT_TYPE_CONST, {.dbl = AV_SAMPLE_FMT_DBL }, INT_MIN, INT_MAX, A|D, "request_sample_fmt"}, + {NULL}, + }; + +@@ -441,40 +542,52 @@ + #undef D + #undef DEFAULT + +-static const AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options, LIBAVUTIL_VERSION_INT, OFFSET(log_level_offset) }; ++static const AVClass av_codec_context_class = { ++ .class_name = "AVCodecContext", ++ .item_name = context_to_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++ .log_level_offset_offset = OFFSET(log_level_offset), ++ .child_next = codec_child_next, ++ .child_class_next = codec_child_class_next, ++}; + ++#if FF_API_ALLOC_CONTEXT + void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType codec_type){ ++ AVCodec c= {0}; ++ c.type= codec_type; ++ avcodec_get_context_defaults3(s, &c); ++} ++#endif ++ ++int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){ + int flags=0; + memset(s, 0, sizeof(AVCodecContext)); + +- s->av_class= &av_codec_context_class; ++ s->av_class = &av_codec_context_class; + +- s->codec_type = codec_type; +- if(codec_type == AVMEDIA_TYPE_AUDIO) ++ s->codec_type = codec ? codec->type : AVMEDIA_TYPE_UNKNOWN; ++ if(s->codec_type == AVMEDIA_TYPE_AUDIO) + flags= AV_OPT_FLAG_AUDIO_PARAM; +- else if(codec_type == AVMEDIA_TYPE_VIDEO) ++ else if(s->codec_type == AVMEDIA_TYPE_VIDEO) + flags= AV_OPT_FLAG_VIDEO_PARAM; +- else if(codec_type == AVMEDIA_TYPE_SUBTITLE) ++ else if(s->codec_type == AVMEDIA_TYPE_SUBTITLE) + flags= AV_OPT_FLAG_SUBTITLE_PARAM; + av_opt_set_defaults2(s, flags, flags); + +- s->time_base= (AVRational){0,1}; +- s->get_buffer= avcodec_default_get_buffer; +- s->release_buffer= avcodec_default_release_buffer; +- s->get_format= avcodec_default_get_format; +- s->execute= avcodec_default_execute; +- s->execute2= avcodec_default_execute2; +- s->sample_aspect_ratio= (AVRational){0,1}; +- s->pix_fmt= PIX_FMT_NONE; +- s->sample_fmt= AV_SAMPLE_FMT_NONE; +- +- s->palctrl = NULL; +- s->reget_buffer= avcodec_default_reget_buffer; +- s->reordered_opaque= AV_NOPTS_VALUE; +-} ++ s->time_base = (AVRational){0,1}; ++ s->get_buffer = avcodec_default_get_buffer; ++ s->release_buffer = avcodec_default_release_buffer; ++ s->get_format = avcodec_default_get_format; ++ s->execute = avcodec_default_execute; ++ s->execute2 = avcodec_default_execute2; ++ s->sample_aspect_ratio = (AVRational){0,1}; ++ s->pix_fmt = PIX_FMT_NONE; ++ s->sample_fmt = AV_SAMPLE_FMT_NONE; ++ s->timecode_frame_start = -1; + +-int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec){ +- avcodec_get_context_defaults2(s, codec ? codec->type : AVMEDIA_TYPE_UNKNOWN); ++ s->reget_buffer = avcodec_default_reget_buffer; ++ s->reordered_opaque = AV_NOPTS_VALUE; + if(codec && codec->priv_data_size){ + if(!s->priv_data){ + s->priv_data= av_mallocz(codec->priv_data_size); +@@ -483,10 +596,19 @@ + } + } + if(codec->priv_class){ +- *(AVClass**)s->priv_data= codec->priv_class; ++ *(const AVClass**)s->priv_data = codec->priv_class; + av_opt_set_defaults(s->priv_data); + } + } ++ if (codec && codec->defaults) { ++ int ret; ++ const AVCodecDefault *d = codec->defaults; ++ while (d->key) { ++ ret = av_opt_set(s, d->key, d->value, 0); ++ av_assert0(ret >= 0); ++ d++; ++ } ++ } + return 0; + } + +@@ -503,6 +625,7 @@ + return avctx; + } + ++#if FF_API_ALLOC_CONTEXT + AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){ + AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); + +@@ -520,10 +643,11 @@ + AVCodecContext *avcodec_alloc_context(void){ + return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN); + } ++#endif + + int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src) + { +- if (dest->codec) { // check that the dest context is uninitialized ++ if (avcodec_is_open(dest)) { // check that the dest context is uninitialized + av_log(dest, AV_LOG_ERROR, + "Tried to copy AVCodecContext %p into already-initialized %p\n", + src, dest); +@@ -534,11 +658,10 @@ + /* set values specific to opened codecs back to their default state */ + dest->priv_data = NULL; + dest->codec = NULL; +- dest->palctrl = NULL; + dest->slice_offset = NULL; +- dest->internal_buffer = NULL; + dest->hwaccel = NULL; + dest->thread_opaque = NULL; ++ dest->internal = NULL; + + /* reallocate values that should be allocated separately */ + dest->rc_eq = NULL; +@@ -578,3 +701,32 @@ + av_freep(&dest->rc_eq); + return AVERROR(ENOMEM); + } ++ ++const AVClass *avcodec_get_class(void) ++{ ++ return &av_codec_context_class; ++} ++ ++#define FOFFSET(x) offsetof(AVFrame,x) ++ ++static const AVOption frame_options[]={ ++{"best_effort_timestamp", "", FOFFSET(best_effort_timestamp), AV_OPT_TYPE_INT64, {.dbl = AV_NOPTS_VALUE }, INT64_MIN, INT64_MAX, 0}, ++{"pkt_pos", "", FOFFSET(pkt_pos), AV_OPT_TYPE_INT64, {.dbl = -1 }, INT64_MIN, INT64_MAX, 0}, ++{"sample_aspect_ratio", "", FOFFSET(sample_aspect_ratio), AV_OPT_TYPE_RATIONAL, {.dbl = 0 }, 0, INT_MAX, 0}, ++{"width", "", FOFFSET(width), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0}, ++{"height", "", FOFFSET(height), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, 0}, ++{"format", "", FOFFSET(format), AV_OPT_TYPE_INT, {.dbl = -1 }, 0, INT_MAX, 0}, ++{NULL}, ++}; ++ ++static const AVClass av_frame_class = { ++ .class_name = "AVFrame", ++ .item_name = NULL, ++ .option = frame_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++const AVClass *avcodec_get_frame_class(void) ++{ ++ return &av_frame_class; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/os2threads.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/os2threads.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/os2threads.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/os2threads.h 2012-05-14 14:08:54.096335191 +0200 +@@ -0,0 +1,162 @@ ++/* ++ * Copyright (c) 2011 KO Myung-Hun ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * os2threads to pthreads wrapper ++ */ ++ ++#ifndef AVCODEC_OS2PTHREADS_H ++#define AVCODEC_OS2PTHREADS_H ++ ++#define INCL_DOS ++#include ++ ++#undef __STRICT_ANSI__ /* for _beginthread() */ ++#include ++ ++typedef TID pthread_t; ++typedef void pthread_attr_t; ++ ++typedef HMTX pthread_mutex_t; ++typedef void pthread_mutexattr_t; ++ ++typedef struct { ++ HEV event_sem; ++ int wait_count; ++} pthread_cond_t; ++ ++typedef void pthread_condattr_t; ++ ++struct thread_arg { ++ void *(*start_routine)(void *); ++ void *arg; ++}; ++ ++static void thread_entry(void *arg) ++{ ++ struct thread_arg *thread_arg = arg; ++ ++ thread_arg->start_routine(thread_arg->arg); ++ ++ av_free(thread_arg); ++} ++ ++static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg) ++{ ++ struct thread_arg *thread_arg; ++ ++ thread_arg = av_mallocz(sizeof(struct thread_arg)); ++ ++ thread_arg->start_routine = start_routine; ++ thread_arg->arg = arg; ++ ++ *thread = _beginthread(thread_entry, NULL, 256 * 1024, thread_arg); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_join(pthread_t thread, void **value_ptr) ++{ ++ DosWaitThread((PTID)&thread, DCWW_WAIT); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr) ++{ ++ DosCreateMutexSem(NULL, (PHMTX)mutex, 0, FALSE); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex) ++{ ++ DosCloseMutexSem(*(PHMTX)mutex); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex) ++{ ++ DosRequestMutexSem(*(PHMTX)mutex, SEM_INDEFINITE_WAIT); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex) ++{ ++ DosReleaseMutexSem(*(PHMTX)mutex); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr) ++{ ++ DosCreateEventSem(NULL, &cond->event_sem, DCE_POSTONE, FALSE); ++ ++ cond->wait_count = 0; ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond) ++{ ++ DosCloseEventSem(cond->event_sem); ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_cond_signal(pthread_cond_t *cond) ++{ ++ if (cond->wait_count > 0) { ++ DosPostEventSem(cond->event_sem); ++ ++ cond->wait_count--; ++ } ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond) ++{ ++ while (cond->wait_count > 0) { ++ DosPostEventSem(cond->event_sem); ++ ++ cond->wait_count--; ++ } ++ ++ return 0; ++} ++ ++static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) ++{ ++ cond->wait_count++; ++ ++ pthread_mutex_unlock(mutex); ++ ++ DosWaitEventSem(cond->event_sem, SEM_INDEFINITE_WAIT); ++ ++ pthread_mutex_lock(mutex); ++ ++ return 0; ++} ++ ++#endif /* AVCODEC_OS2PTHREADS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pamenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pamenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pamenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pamenc.c 2012-05-14 14:08:54.097335212 +0200 +@@ -20,7 +20,6 @@ + */ + + #include "avcodec.h" +-#include "bytestream.h" + #include "pnm.h" + + +@@ -40,7 +39,7 @@ + } + + *p = *pict; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + + s->bytestream_start = +@@ -50,7 +49,7 @@ + h = avctx->height; + w = avctx->width; + switch (avctx->pix_fmt) { +- case PIX_FMT_MONOWHITE: ++ case PIX_FMT_MONOBLACK: + n = (w + 7) >> 3; + depth = 1; + maxval = 1; +@@ -62,39 +61,58 @@ + maxval = 255; + tuple_type = "GRAYSCALE"; + break; ++ case PIX_FMT_GRAY16BE: ++ n = w * 2; ++ depth = 1; ++ maxval = 0xFFFF; ++ tuple_type = "GRAYSCALE"; ++ break; ++ case PIX_FMT_GRAY8A: ++ n = w * 2; ++ depth = 2; ++ maxval = 255; ++ tuple_type = "GRAYSCALE_ALPHA"; ++ break; + case PIX_FMT_RGB24: + n = w * 3; + depth = 3; + maxval = 255; + tuple_type = "RGB"; + break; +- case PIX_FMT_RGB32: ++ case PIX_FMT_RGBA: + n = w * 4; + depth = 4; + maxval = 255; + tuple_type = "RGB_ALPHA"; + break; ++ case PIX_FMT_RGB48BE: ++ n = w * 6; ++ depth = 3; ++ maxval = 0xFFFF; ++ tuple_type = "RGB"; ++ break; ++ case PIX_FMT_RGBA64BE: ++ n = w * 8; ++ depth = 4; ++ maxval = 0xFFFF; ++ tuple_type = "RGB_ALPHA"; ++ break; + default: + return -1; + } + snprintf(s->bytestream, s->bytestream_end - s->bytestream, +- "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLETYPE %s\nENDHDR\n", ++ "P7\nWIDTH %d\nHEIGHT %d\nDEPTH %d\nMAXVAL %d\nTUPLTYPE %s\nENDHDR\n", + w, h, depth, maxval, tuple_type); + s->bytestream += strlen(s->bytestream); + + ptr = p->data[0]; + linesize = p->linesize[0]; + +- if (avctx->pix_fmt == PIX_FMT_RGB32) { ++ if (avctx->pix_fmt == PIX_FMT_MONOBLACK){ + int j; +- unsigned int v; +- + for (i = 0; i < h; i++) { +- for (j = 0; j < w; j++) { +- v = ((uint32_t *)ptr)[j]; +- bytestream_put_be24(&s->bytestream, v); +- *s->bytestream++ = v >> 24; +- } ++ for (j = 0; j < w; j++) ++ *s->bytestream++ = ptr[j >> 3] >> (7 - j & 7) & 1; + ptr += linesize; + } + } else { +@@ -109,12 +127,12 @@ + + + AVCodec ff_pam_encoder = { +- "pam", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PAM, +- sizeof(PNMContext), +- ff_pnm_init, +- pam_encode_frame, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE}, ++ .name = "pam", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PAM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .encode = pam_encode_frame, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_RGB48BE, PIX_FMT_RGBA64BE, PIX_FMT_GRAY8, PIX_FMT_GRAY8A, PIX_FMT_GRAY16BE, PIX_FMT_MONOBLACK, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/parser.c 2012-05-14 14:08:54.098335232 +0200 +@@ -72,7 +72,7 @@ + } + } + s->fetch_timestamp=1; +- s->pict_type = FF_I_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_I; + s->key_frame = -1; + s->convergence_duration = 0; + s->dts_sync_point = INT_MIN; +@@ -105,41 +105,6 @@ + } + } + +-/** +- * +- * @param buf input +- * @param buf_size input length, to signal EOF, this should be 0 (so that the last frame can be output) +- * @param pts input presentation timestamp +- * @param dts input decoding timestamp +- * @param poutbuf will contain a pointer to the first byte of the output frame +- * @param poutbuf_size will contain the length of the output frame +- * @return the number of bytes of the input bitstream used +- * +- * Example: +- * @code +- * while(in_len){ +- * len = av_parser_parse(myparser, AVCodecContext, &data, &size, +- * in_data, in_len, +- * pts, dts); +- * in_data += len; +- * in_len -= len; +- * +- * if(size) +- * decode_frame(data, size); +- * } +- * @endcode +- * +- * @deprecated Use av_parser_parse2() instead. +- */ +-int av_parser_parse(AVCodecParserContext *s, +- AVCodecContext *avctx, +- uint8_t **poutbuf, int *poutbuf_size, +- const uint8_t *buf, int buf_size, +- int64_t pts, int64_t dts) +-{ +- return av_parser_parse2(s, avctx, poutbuf, poutbuf_size, buf, buf_size, pts, dts, AV_NOPTS_VALUE); +-} +- + int av_parser_parse2(AVCodecParserContext *s, + AVCodecContext *avctx, + uint8_t **poutbuf, int *poutbuf_size, +@@ -221,7 +186,7 @@ + *poutbuf_size= buf_size; + if(avctx->extradata){ + if( (keyframe && (avctx->flags2 & CODEC_FLAG2_LOCAL_HEADER)) +- /*||(s->pict_type != FF_I_TYPE && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/ ++ /*||(s->pict_type != AV_PICTURE_TYPE_I && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_NOKEY))*/ + /*||(? && (s->flags & PARSER_FLAG_DUMP_EXTRADATA_AT_BEGIN)*/){ + int size= buf_size + avctx->extradata_size; + *poutbuf_size= size; +@@ -249,17 +214,16 @@ + /*****************************************************/ + + /** +- * combines the (truncated) bitstream to a complete frame ++ * Combine the (truncated) bitstream to a complete frame. + * @return -1 if no complete frame could be created, AVERROR(ENOMEM) if there was a memory allocation error + */ + int ff_combine_frame(ParseContext *pc, int next, const uint8_t **buf, int *buf_size) + { +-#if 0 + if(pc->overread){ +- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); +- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); ++ av_dlog(NULL, "overread %d, state:%X next:%d index:%d o_index:%d\n", ++ pc->overread, pc->state, next, pc->index, pc->overread_index); ++ av_dlog(NULL, "%X %X %X %X\n", (*buf)[0], (*buf)[1], (*buf)[2], (*buf)[3]); + } +-#endif + + /* Copy overread bytes from last frame into buffer. */ + for(; pc->overread>0; pc->overread--){ +@@ -307,12 +271,11 @@ + pc->overread++; + } + +-#if 0 + if(pc->overread){ +- printf("overread %d, state:%X next:%d index:%d o_index:%d\n", pc->overread, pc->state, next, pc->index, pc->overread_index); +- printf("%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); ++ av_dlog(NULL, "overread %d, state:%X next:%d index:%d o_index:%d\n", ++ pc->overread, pc->state, next, pc->index, pc->overread_index); ++ av_dlog(NULL, "%X %X %X %X\n", (*buf)[0], (*buf)[1],(*buf)[2],(*buf)[3]); + } +-#endif + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm.c 2012-05-14 14:08:54.101335292 +0200 +@@ -27,13 +27,14 @@ + #include "avcodec.h" + #include "libavutil/common.h" /* for av_reverse */ + #include "bytestream.h" ++#include "internal.h" + #include "pcm_tablegen.h" + + #define MAX_CHANNELS 64 + + static av_cold int pcm_encode_init(AVCodecContext *avctx) + { +- avctx->frame_size = 1; ++ avctx->frame_size = 0; + switch(avctx->codec->id) { + case CODEC_ID_PCM_ALAW: + pcm_alaw_tableinit(); +@@ -71,16 +72,16 @@ + * @param offset Sample value offset + */ + #define ENCODE(type, endian, src, dst, n, shift, offset) \ +- samples_##type = (type*)src; \ ++ samples_##type = (const type*) src; \ + for(;n>0;n--) { \ + register type v = (*samples_##type++ >> shift) + offset; \ + bytestream_put_##endian(&dst, v); \ + } + +-static int pcm_encode_frame(AVCodecContext *avctx, +- unsigned char *frame, int buf_size, void *data) ++static int pcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, ++ const AVFrame *frame, int *got_packet_ptr) + { +- int n, sample_size, v; ++ int n, sample_size, v, ret; + const short *samples; + unsigned char *dst; + const uint8_t *srcu8; +@@ -91,14 +92,14 @@ + const uint32_t *samples_uint32_t; + + sample_size = av_get_bits_per_sample(avctx->codec->id)/8; +- n = buf_size / sample_size; +- samples = data; +- dst = frame; ++ n = frame->nb_samples * avctx->channels; ++ samples = (const short *)frame->data[0]; + +- if (avctx->sample_fmt!=avctx->codec->sample_fmts[0]) { +- av_log(avctx, AV_LOG_ERROR, "invalid sample_fmt\n"); +- return -1; ++ if ((ret = ff_alloc_packet(avpkt, n * sample_size))) { ++ av_log(avctx, AV_LOG_ERROR, "Error getting output packet\n"); ++ return ret; + } ++ dst = avpkt->data; + + switch(avctx->codec->id) { + case CODEC_ID_PCM_U32LE: +@@ -135,7 +136,7 @@ + ENCODE(uint16_t, be16, samples, dst, n, 0, 0x8000) + break; + case CODEC_ID_PCM_S8: +- srcu8= data; ++ srcu8 = frame->data[0]; + for(;n>0;n--) { + v = *srcu8++; + *dst++ = v - 128; +@@ -176,14 +177,6 @@ + memcpy(dst, samples, n*sample_size); + dst += n*sample_size; + break; +- case CODEC_ID_PCM_ZORK: +- for(;n>0;n--) { +- v= *samples++ >> 8; +- if(v<0) v = -v; +- else v+= 128; +- *dst++ = v; +- } +- break; + case CODEC_ID_PCM_ALAW: + for(;n>0;n--) { + v = *samples++; +@@ -199,12 +192,14 @@ + default: + return -1; + } +- //avctx->frame_size = (dst - frame) / (sample_size * avctx->channels); + +- return dst - frame; ++ avpkt->size = frame->nb_samples * avctx->channels * sample_size; ++ *got_packet_ptr = 1; ++ return 0; + } + + typedef struct PCMDecode { ++ AVFrame frame; + short table[256]; + } PCMDecode; + +@@ -213,6 +208,11 @@ + PCMDecode *s = avctx->priv_data; + int i; + ++ if (avctx->channels <= 0 || avctx->channels > MAX_CHANNELS) { ++ av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n"); ++ return AVERROR(EINVAL); ++ } ++ + switch(avctx->codec->id) { + case CODEC_ID_PCM_ALAW: + for(i=0;i<256;i++) +@@ -231,12 +231,15 @@ + if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) + avctx->bits_per_raw_sample = av_get_bits_per_sample(avctx->codec->id); + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + + /** + * Read PCM samples macro +- * @param type Datatype of native machine format ++ * @param size Data size of native machine format + * @param endian bytestream_get_xxx() endian suffix + * @param src Source pointer (variable name) + * @param dst Destination pointer (variable name) +@@ -244,53 +247,43 @@ + * @param shift Bitshift (bits) + * @param offset Sample value offset + */ +-#define DECODE(type, endian, src, dst, n, shift, offset) \ +- dst_##type = (type*)dst; \ ++#define DECODE(size, endian, src, dst, n, shift, offset) \ + for(;n>0;n--) { \ +- register type v = bytestream_get_##endian(&src); \ +- *dst_##type++ = (v - offset) << shift; \ +- } \ +- dst = (short*)dst_##type; +- +-static int pcm_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++ uint##size##_t v = bytestream_get_##endian(&src); \ ++ AV_WN##size##A(dst, (v - offset) << shift); \ ++ dst += size / 8; \ ++ } ++ ++static int pcm_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; ++ const uint8_t *src = avpkt->data; + int buf_size = avpkt->size; + PCMDecode *s = avctx->priv_data; +- int sample_size, c, n, i; +- short *samples; +- const uint8_t *src, *src8, *src2[MAX_CHANNELS]; +- uint8_t *dstu8; +- int16_t *dst_int16_t; ++ int sample_size, c, n, ret, samples_per_block; ++ uint8_t *samples; + int32_t *dst_int32_t; +- int64_t *dst_int64_t; +- uint16_t *dst_uint16_t; +- uint32_t *dst_uint32_t; +- +- samples = data; +- src = buf; +- +- if (avctx->sample_fmt!=avctx->codec->sample_fmts[0]) { +- av_log(avctx, AV_LOG_ERROR, "invalid sample_fmt\n"); +- return -1; +- } +- +- if(avctx->channels <= 0 || avctx->channels > MAX_CHANNELS){ +- av_log(avctx, AV_LOG_ERROR, "PCM channels out of bounds\n"); +- return -1; +- } + + sample_size = av_get_bits_per_sample(avctx->codec_id)/8; + + /* av_get_bits_per_sample returns 0 for CODEC_ID_PCM_DVD */ +- if (CODEC_ID_PCM_DVD == avctx->codec_id) ++ samples_per_block = 1; ++ if (CODEC_ID_PCM_DVD == avctx->codec_id) { ++ if (avctx->bits_per_coded_sample != 20 && ++ avctx->bits_per_coded_sample != 24) { ++ av_log(avctx, AV_LOG_ERROR, ++ "PCM DVD unsupported sample depth %i\n", ++ avctx->bits_per_coded_sample); ++ return AVERROR(EINVAL); ++ } + /* 2 samples are interleaved per block in PCM_DVD */ ++ samples_per_block = 2; + sample_size = avctx->bits_per_coded_sample * 2 / 8; +- else if (avctx->codec_id == CODEC_ID_PCM_LXF) ++ } else if (avctx->codec_id == CODEC_ID_PCM_LXF) { + /* we process 40-bit blocks per channel for LXF */ ++ samples_per_block = 2; + sample_size = 5; ++ } + + if (sample_size == 0) { + av_log(avctx, AV_LOG_ERROR, "Invalid sample_size\n"); +@@ -307,70 +300,78 @@ + buf_size -= buf_size % n; + } + +- buf_size= FFMIN(buf_size, *data_size/2); +- *data_size=0; +- + n = buf_size/sample_size; + ++ /* get output buffer */ ++ s->frame.nb_samples = n * samples_per_block / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = s->frame.data[0]; ++ + switch(avctx->codec->id) { + case CODEC_ID_PCM_U32LE: +- DECODE(uint32_t, le32, src, samples, n, 0, 0x80000000) ++ DECODE(32, le32, src, samples, n, 0, 0x80000000) + break; + case CODEC_ID_PCM_U32BE: +- DECODE(uint32_t, be32, src, samples, n, 0, 0x80000000) ++ DECODE(32, be32, src, samples, n, 0, 0x80000000) + break; + case CODEC_ID_PCM_S24LE: +- DECODE(int32_t, le24, src, samples, n, 8, 0) ++ DECODE(32, le24, src, samples, n, 8, 0) + break; + case CODEC_ID_PCM_S24BE: +- DECODE(int32_t, be24, src, samples, n, 8, 0) ++ DECODE(32, be24, src, samples, n, 8, 0) + break; + case CODEC_ID_PCM_U24LE: +- DECODE(uint32_t, le24, src, samples, n, 8, 0x800000) ++ DECODE(32, le24, src, samples, n, 8, 0x800000) + break; + case CODEC_ID_PCM_U24BE: +- DECODE(uint32_t, be24, src, samples, n, 8, 0x800000) ++ DECODE(32, be24, src, samples, n, 8, 0x800000) + break; + case CODEC_ID_PCM_S24DAUD: + for(;n>0;n--) { + uint32_t v = bytestream_get_be24(&src); + v >>= 4; // sync flags are here +- *samples++ = av_reverse[(v >> 8) & 0xff] + +- (av_reverse[v & 0xff] << 8); ++ AV_WN16A(samples, av_reverse[(v >> 8) & 0xff] + ++ (av_reverse[v & 0xff] << 8)); ++ samples += 2; + } + break; + case CODEC_ID_PCM_S16LE_PLANAR: ++ { ++ const uint8_t *src2[MAX_CHANNELS]; + n /= avctx->channels; + for(c=0;cchannels;c++) + src2[c] = &src[c*n*2]; + for(;n>0;n--) +- for(c=0;cchannels;c++) +- *samples++ = bytestream_get_le16(&src2[c]); +- src = src2[avctx->channels-1]; ++ for(c=0;cchannels;c++) { ++ AV_WN16A(samples, bytestream_get_le16(&src2[c])); ++ samples += 2; ++ } + break; ++ } + case CODEC_ID_PCM_U16LE: +- DECODE(uint16_t, le16, src, samples, n, 0, 0x8000) ++ DECODE(16, le16, src, samples, n, 0, 0x8000) + break; + case CODEC_ID_PCM_U16BE: +- DECODE(uint16_t, be16, src, samples, n, 0, 0x8000) ++ DECODE(16, be16, src, samples, n, 0, 0x8000) + break; + case CODEC_ID_PCM_S8: +- dstu8= (uint8_t*)samples; + for(;n>0;n--) { +- *dstu8++ = *src++ + 128; ++ *samples++ = *src++ + 128; + } +- samples= (short*)dstu8; + break; + #if HAVE_BIGENDIAN + case CODEC_ID_PCM_F64LE: +- DECODE(int64_t, le64, src, samples, n, 0, 0) ++ DECODE(64, le64, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_S32LE: + case CODEC_ID_PCM_F32LE: +- DECODE(int32_t, le32, src, samples, n, 0, 0) ++ DECODE(32, le32, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_S16LE: +- DECODE(int16_t, le16, src, samples, n, 0, 0) ++ DECODE(16, le16, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_F64BE: + case CODEC_ID_PCM_F32BE: +@@ -378,14 +379,14 @@ + case CODEC_ID_PCM_S16BE: + #else + case CODEC_ID_PCM_F64BE: +- DECODE(int64_t, be64, src, samples, n, 0, 0) ++ DECODE(64, be64, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_F32BE: + case CODEC_ID_PCM_S32BE: +- DECODE(int32_t, be32, src, samples, n, 0, 0) ++ DECODE(32, be32, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_S16BE: +- DECODE(int16_t, be16, src, samples, n, 0, 0) ++ DECODE(16, be16, src, samples, n, 0, 0) + break; + case CODEC_ID_PCM_F64LE: + case CODEC_ID_PCM_F32LE: +@@ -394,25 +395,26 @@ + #endif /* HAVE_BIGENDIAN */ + case CODEC_ID_PCM_U8: + memcpy(samples, src, n*sample_size); +- src += n*sample_size; +- samples = (short*)((uint8_t*)data + n*sample_size); + break; + case CODEC_ID_PCM_ZORK: +- for(;n>0;n--) { +- int x= *src++; +- if(x&128) x-= 128; +- else x = -x; +- *samples++ = x << 8; ++ for (; n > 0; n--) { ++ int v = *src++; ++ if (v < 128) ++ v = 128 - v; ++ *samples++ = v; + } + break; + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_MULAW: + for(;n>0;n--) { +- *samples++ = s->table[*src++]; ++ AV_WN16A(samples, s->table[*src++]); ++ samples += 2; + } + break; + case CODEC_ID_PCM_DVD: +- dst_int32_t = data; ++ { ++ const uint8_t *src8; ++ dst_int32_t = (int32_t *)s->frame.data[0]; + n /= avctx->channels; + switch (avctx->bits_per_coded_sample) { + case 20: +@@ -437,15 +439,14 @@ + src = src8; + } + break; +- default: +- av_log(avctx, AV_LOG_ERROR, "PCM DVD unsupported sample depth\n"); +- return -1; +- break; + } +- samples = (short *) dst_int32_t; + break; ++ } + case CODEC_ID_PCM_LXF: +- dst_int32_t = data; ++ { ++ int i; ++ const uint8_t *src8; ++ dst_int32_t = (int32_t *)s->frame.data[0]; + n /= avctx->channels; + //unpack and de-planerize + for (i = 0; i < n; i++) { +@@ -461,14 +462,16 @@ + ((src8[2] & 0xF0) << 8) | (src8[4] << 4) | (src8[3] >> 4); + } + } +- src += n * avctx->channels * 5; +- samples = (short *) dst_int32_t; + break; ++ } + default: + return -1; + } +- *data_size = (uint8_t *)samples - (uint8_t *)data; +- return src - buf; ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return buf_size; + } + + #if CONFIG_ENCODERS +@@ -478,11 +481,12 @@ + .type = AVMEDIA_TYPE_AUDIO, \ + .id = id_, \ + .init = pcm_encode_init, \ +- .encode = pcm_encode_frame, \ ++ .encode2 = pcm_encode_frame, \ + .close = pcm_encode_close, \ ++ .capabilities = CODEC_CAP_VARIABLE_FRAME_SIZE, \ + .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \ + .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ +-}; ++} + #else + #define PCM_ENCODER(id,sample_fmt_,name,long_name_) + #endif +@@ -496,15 +500,16 @@ + .priv_data_size = sizeof(PCMDecode), \ + .init = pcm_decode_init, \ + .decode = pcm_decode_frame, \ ++ .capabilities = CODEC_CAP_DR1, \ + .sample_fmts = (const enum AVSampleFormat[]){sample_fmt_,AV_SAMPLE_FMT_NONE}, \ + .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ +-}; ++} + #else + #define PCM_DECODER(id,sample_fmt_,name,long_name_) + #endif + + #define PCM_CODEC(id, sample_fmt_, name, long_name_) \ +- PCM_ENCODER(id,sample_fmt_,name,long_name_) PCM_DECODER(id,sample_fmt_,name,long_name_) ++ PCM_ENCODER(id,sample_fmt_,name,long_name_); PCM_DECODER(id,sample_fmt_,name,long_name_) + + /* Note: Do not forget to add new entries to the Makefile as well. */ + PCM_CODEC (CODEC_ID_PCM_ALAW, AV_SAMPLE_FMT_S16, pcm_alaw, "PCM A-law"); +@@ -531,4 +536,4 @@ + PCM_CODEC (CODEC_ID_PCM_U24LE, AV_SAMPLE_FMT_S32, pcm_u24le, "PCM unsigned 24-bit little-endian"); + PCM_CODEC (CODEC_ID_PCM_U32BE, AV_SAMPLE_FMT_S32, pcm_u32be, "PCM unsigned 32-bit big-endian"); + PCM_CODEC (CODEC_ID_PCM_U32LE, AV_SAMPLE_FMT_S32, pcm_u32le, "PCM unsigned 32-bit little-endian"); +-PCM_CODEC (CODEC_ID_PCM_ZORK, AV_SAMPLE_FMT_S16, pcm_zork, "PCM Zork"); ++PCM_DECODER(CODEC_ID_PCM_ZORK, AV_SAMPLE_FMT_U8, pcm_zork, "PCM Zork"); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm-mpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm-mpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm-mpeg.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm-mpeg.c 2012-05-14 14:08:54.099335252 +0200 +@@ -24,7 +24,7 @@ + * PCM codecs for encodings found in MPEG streams (DVD/Blu-ray) + */ + +-#include "libavcore/audioconvert.h" ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "bytestream.h" + +@@ -75,6 +75,8 @@ + } + avctx->sample_fmt = avctx->bits_per_coded_sample == 16 ? AV_SAMPLE_FMT_S16 : + AV_SAMPLE_FMT_S32; ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) ++ avctx->bits_per_raw_sample = avctx->bits_per_coded_sample; + + /* get the sample rate. Not all values are known or exist. */ + switch (header[2] & 0x0f) { +@@ -119,17 +121,30 @@ + return 0; + } + +-static int pcm_bluray_decode_frame(AVCodecContext *avctx, +- void *data, +- int *data_size, +- AVPacket *avpkt) ++typedef struct PCMBRDecode { ++ AVFrame frame; ++} PCMBRDecode; ++ ++static av_cold int pcm_bluray_decode_init(AVCodecContext * avctx) ++{ ++ PCMBRDecode *s = avctx->priv_data; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ ++ return 0; ++} ++ ++static int pcm_bluray_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *src = avpkt->data; + int buf_size = avpkt->size; ++ PCMBRDecode *s = avctx->priv_data; + int num_source_channels, channel, retval; +- int sample_size, samples, output_size; +- int16_t *dst16 = data; +- int32_t *dst32 = data; ++ int sample_size, samples; ++ int16_t *dst16; ++ int32_t *dst32; + + if (buf_size < 4) { + av_log(avctx, AV_LOG_ERROR, "PCM packet too small\n"); +@@ -143,18 +158,17 @@ + + /* There's always an even number of channels in the source */ + num_source_channels = FFALIGN(avctx->channels, 2); +- sample_size = (num_source_channels * avctx->bits_per_coded_sample) >> 3; ++ sample_size = (num_source_channels * (avctx->sample_fmt == AV_SAMPLE_FMT_S16 ? 16 : 24)) >> 3; + samples = buf_size / sample_size; + +- output_size = samples * avctx->channels * +- (avctx->sample_fmt == AV_SAMPLE_FMT_S32 ? 4 : 2); +- if (output_size > *data_size) { +- av_log(avctx, AV_LOG_ERROR, +- "Insufficient output buffer space (%d bytes, needed %d bytes)\n", +- *data_size, output_size); +- return -1; ++ /* get output buffer */ ++ s->frame.nb_samples = samples; ++ if ((retval = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return retval; + } +- *data_size = output_size; ++ dst16 = (int16_t *)s->frame.data[0]; ++ dst32 = (int32_t *)s->frame.data[0]; + + if (samples) { + switch (avctx->channel_layout) { +@@ -165,7 +179,7 @@ + samples *= num_source_channels; + if (AV_SAMPLE_FMT_S16 == avctx->sample_fmt) { + #if HAVE_BIGENDIAN +- memcpy(dst16, src, output_size); ++ memcpy(dst16, src, buf_size); + #else + do { + *dst16++ = bytestream_get_be16(&src); +@@ -289,22 +303,24 @@ + } + } + ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + retval = src - avpkt->data; + if (avctx->debug & FF_DEBUG_BITSTREAM) + av_dlog(avctx, "pcm_bluray_decode_frame: decoded %d -> %d bytes\n", +- retval, *data_size); ++ retval, buf_size); + return retval; + } + + AVCodec ff_pcm_bluray_decoder = { +- "pcm_bluray", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_PCM_BLURAY, +- 0, +- NULL, +- NULL, +- NULL, +- pcm_bluray_decode_frame, ++ .name = "pcm_bluray", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_PCM_BLURAY, ++ .priv_data_size = sizeof(PCMBRDecode), ++ .init = pcm_bluray_decode_init, ++ .decode = pcm_bluray_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, + AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PCM signed 16|20|24-bit big-endian for Blu-ray media"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcm_tablegen.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcm_tablegen.h 2012-05-14 14:08:54.101335292 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef PCM_TABLEGEN_H +-#define PCM_TABLEGEN_H ++#ifndef AVCODEC_PCM_TABLEGEN_H ++#define AVCODEC_PCM_TABLEGEN_H + + #include + #include "libavutil/attributes.h" +@@ -116,4 +116,4 @@ + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* PCM_TABLEGEN_H */ ++#endif /* AVCODEC_PCM_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcx.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcx.c 2012-05-14 14:08:54.102335312 +0200 +@@ -22,7 +22,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + #include "get_bits.h" +@@ -71,7 +71,7 @@ + unsigned int i; + + for (i=0; ipict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + + ptr = p->data[0]; + stride = p->linesize[0]; +@@ -224,6 +224,9 @@ + + if (nplanes == 1 && bits_per_pixel == 8) { + pcx_palette(&buf, (uint32_t *) p->data[1], 256); ++ } else if (bits_per_pixel * nplanes == 1) { ++ AV_WN32A(p->data[1] , 0xFF000000); ++ AV_WN32A(p->data[1]+4, 0xFFFFFFFF); + } else if (bits_per_pixel < 8) { + const uint8_t *palette = bufstart+16; + pcx_palette(&palette, (uint32_t *) p->data[1], 16); +@@ -248,15 +251,13 @@ + } + + AVCodec ff_pcx_decoder = { +- "pcx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PCX, +- sizeof(PCXContext), +- pcx_init, +- NULL, +- pcx_end, +- pcx_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "pcx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PCX, ++ .priv_data_size = sizeof(PCXContext), ++ .init = pcx_init, ++ .close = pcx_end, ++ .decode = pcx_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("PC Paintbrush PCX image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcxenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcxenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pcxenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pcxenc.c 2012-05-14 14:08:54.103335332 +0200 +@@ -20,14 +20,15 @@ + */ + + /** +- * PCX image encoder + * @file ++ * PCX image encoder + * @author Daniel Verkamp +- * @sa http://www.qzx.com/pc-gpe/pcx.txt ++ * @see http://www.qzx.com/pc-gpe/pcx.txt + */ + + #include "avcodec.h" + #include "bytestream.h" ++#include "libavutil/imgutils.h" + + typedef struct PCXContext { + AVFrame picture; +@@ -105,10 +106,11 @@ + + int bpp, nplanes, i, y, line_bytes, written; + const uint32_t *pal = NULL; ++ uint32_t palette256[256]; + const uint8_t *src; + + *pict = *(AVFrame *)data; +- pict->pict_type = FF_I_TYPE; ++ pict->pict_type = AV_PICTURE_TYPE_I; + pict->key_frame = 1; + + if (avctx->width > 65535 || avctx->height > 65535) { +@@ -126,6 +128,11 @@ + case PIX_FMT_RGB4_BYTE: + case PIX_FMT_BGR4_BYTE: + case PIX_FMT_GRAY8: ++ bpp = 8; ++ nplanes = 1; ++ ff_set_systematic_pal2(palette256, avctx->pix_fmt); ++ pal = palette256; ++ break; + case PIX_FMT_PAL8: + bpp = 8; + nplanes = 1; +@@ -190,13 +197,12 @@ + } + + AVCodec ff_pcx_encoder = { +- "pcx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PCX, +- sizeof(PCXContext), +- pcx_encode_init, +- pcx_encode_frame, +- NULL, ++ .name = "pcx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PCX, ++ .priv_data_size = sizeof(PCXContext), ++ .init = pcx_encode_init, ++ .encode = pcx_encode_frame, + .pix_fmts = (const enum PixelFormat[]){ + PIX_FMT_RGB24, + PIX_FMT_RGB8, PIX_FMT_BGR8, PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, PIX_FMT_GRAY8, PIX_FMT_PAL8, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pgssubdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pgssubdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pgssubdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pgssubdec.c 2012-05-14 14:08:54.105335372 +0200 +@@ -28,9 +28,7 @@ + #include "dsputil.h" + #include "bytestream.h" + #include "libavutil/colorspace.h" +-#include "libavcore/imgutils.h" +- +-//#define DEBUG_PACKET_CONTENTS ++#include "libavutil/imgutils.h" + + #define RGBA(r,g,b,a) (((a) << 24) | ((r) << 16) | ((g) << 8) | (b)) + +@@ -42,11 +40,16 @@ + DISPLAY_SEGMENT = 0x80, + }; + +-typedef struct PGSSubPresentation { ++typedef struct PGSSubPictureReference { + int x; + int y; +- int id_number; +- int object_number; ++ int picture_id; ++} PGSSubPictureReference; ++ ++typedef struct PGSSubPresentation { ++ int id_number; ++ int object_count; ++ PGSSubPictureReference *objects; + } PGSSubPresentation; + + typedef struct PGSSubPicture { +@@ -60,22 +63,29 @@ + typedef struct PGSSubContext { + PGSSubPresentation presentation; + uint32_t clut[256]; +- PGSSubPicture picture; ++ PGSSubPicture pictures[UINT16_MAX]; + } PGSSubContext; + + static av_cold int init_decoder(AVCodecContext *avctx) + { +- avctx->pix_fmt = PIX_FMT_PAL8; ++ avctx->pix_fmt = PIX_FMT_PAL8; + + return 0; + } + + static av_cold int close_decoder(AVCodecContext *avctx) + { ++ uint16_t picture; ++ + PGSSubContext *ctx = avctx->priv_data; + +- av_freep(&ctx->picture.rle); +- ctx->picture.rle_buffer_size = 0; ++ av_freep(&ctx->presentation.objects); ++ ctx->presentation.object_count = 0; ++ ++ for (picture = 0; picture < UINT16_MAX; ++picture) { ++ av_freep(&ctx->pictures[picture].rle); ++ ctx->pictures[picture].rle_buffer_size = 0; ++ } + + return 0; + } +@@ -90,7 +100,7 @@ + * @param buf pointer to the RLE data to process + * @param buf_size size of the RLE data to process + */ +-static int decode_rle(AVCodecContext *avctx, AVSubtitle *sub, ++static int decode_rle(AVCodecContext *avctx, AVSubtitle *sub, int rect, + const uint8_t *buf, unsigned int buf_size) + { + const uint8_t *rle_bitmap_end; +@@ -98,15 +108,15 @@ + + rle_bitmap_end = buf + buf_size; + +- sub->rects[0]->pict.data[0] = av_malloc(sub->rects[0]->w * sub->rects[0]->h); ++ sub->rects[rect]->pict.data[0] = av_malloc(sub->rects[rect]->w * sub->rects[rect]->h); + +- if (!sub->rects[0]->pict.data[0]) ++ if (!sub->rects[rect]->pict.data[0]) + return -1; + + pixel_count = 0; + line_count = 0; + +- while (buf < rle_bitmap_end && line_count < sub->rects[0]->h) { ++ while (buf < rle_bitmap_end && line_count < sub->rects[rect]->h) { + uint8_t flags, color; + int run; + +@@ -121,27 +131,27 @@ + color = flags & 0x80 ? bytestream_get_byte(&buf) : 0; + } + +- if (run > 0 && pixel_count + run <= sub->rects[0]->w * sub->rects[0]->h) { +- memset(sub->rects[0]->pict.data[0] + pixel_count, color, run); ++ if (run > 0 && pixel_count + run <= sub->rects[rect]->w * sub->rects[rect]->h) { ++ memset(sub->rects[rect]->pict.data[0] + pixel_count, color, run); + pixel_count += run; + } else if (!run) { + /* + * New Line. Check if correct pixels decoded, if not display warning + * and adjust bitmap pointer to correct new line position. + */ +- if (pixel_count % sub->rects[0]->w > 0) ++ if (pixel_count % sub->rects[rect]->w > 0) + av_log(avctx, AV_LOG_ERROR, "Decoded %d pixels, when line should be %d pixels\n", +- pixel_count % sub->rects[0]->w, sub->rects[0]->w); ++ pixel_count % sub->rects[rect]->w, sub->rects[rect]->w); + line_count++; + } + } + +- if (pixel_count < sub->rects[0]->w * sub->rects[0]->h) { ++ if (pixel_count < sub->rects[rect]->w * sub->rects[rect]->h) { + av_log(avctx, AV_LOG_ERROR, "Insufficient RLE data for subtitle\n"); + return -1; + } + +- av_dlog(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, sub->rects[0]->w * sub->rects[0]->h); ++ av_dlog(avctx, "Pixel Count = %d, Area = %d\n", pixel_count, sub->rects[rect]->w * sub->rects[rect]->h); + + return 0; + } +@@ -164,25 +174,28 @@ + + uint8_t sequence_desc; + unsigned int rle_bitmap_len, width, height; ++ uint16_t picture_id; + + if (buf_size <= 4) + return -1; + buf_size -= 4; + +- /* skip 3 unknown bytes: Object ID (2 bytes), Version Number */ +- buf += 3; ++ picture_id = bytestream_get_be16(&buf); ++ ++ /* skip 1 unknown byte: Version Number */ ++ buf++; + + /* Read the Sequence Description to determine if start of RLE data or appended to previous RLE */ + sequence_desc = bytestream_get_byte(&buf); + + if (!(sequence_desc & 0x80)) { + /* Additional RLE data */ +- if (buf_size > ctx->picture.rle_remaining_len) ++ if (buf_size > ctx->pictures[picture_id].rle_remaining_len) + return -1; + +- memcpy(ctx->picture.rle + ctx->picture.rle_data_len, buf, buf_size); +- ctx->picture.rle_data_len += buf_size; +- ctx->picture.rle_remaining_len -= buf_size; ++ memcpy(ctx->pictures[picture_id].rle + ctx->pictures[picture_id].rle_data_len, buf, buf_size); ++ ctx->pictures[picture_id].rle_data_len += buf_size; ++ ctx->pictures[picture_id].rle_remaining_len -= buf_size; + + return 0; + } +@@ -200,21 +213,21 @@ + + /* Make sure the bitmap is not too large */ + if (avctx->width < width || avctx->height < height) { +- av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger then video.\n"); ++ av_log(avctx, AV_LOG_ERROR, "Bitmap dimensions larger than video.\n"); + return -1; + } + +- ctx->picture.w = width; +- ctx->picture.h = height; ++ ctx->pictures[picture_id].w = width; ++ ctx->pictures[picture_id].h = height; + +- av_fast_malloc(&ctx->picture.rle, &ctx->picture.rle_buffer_size, rle_bitmap_len); ++ av_fast_malloc(&ctx->pictures[picture_id].rle, &ctx->pictures[picture_id].rle_buffer_size, rle_bitmap_len); + +- if (!ctx->picture.rle) ++ if (!ctx->pictures[picture_id].rle) + return -1; + +- memcpy(ctx->picture.rle, buf, buf_size); +- ctx->picture.rle_data_len = buf_size; +- ctx->picture.rle_remaining_len = rle_bitmap_len - buf_size; ++ memcpy(ctx->pictures[picture_id].rle, buf, buf_size); ++ ctx->pictures[picture_id].rle_data_len = buf_size; ++ ctx->pictures[picture_id].rle_remaining_len = rle_bitmap_len - buf_size; + + return 0; + } +@@ -246,8 +259,8 @@ + while (buf < buf_end) { + color_id = bytestream_get_byte(&buf); + y = bytestream_get_byte(&buf); +- cb = bytestream_get_byte(&buf); + cr = bytestream_get_byte(&buf); ++ cb = bytestream_get_byte(&buf); + alpha = bytestream_get_byte(&buf); + + YUV_TO_RGB1(cb, cr); +@@ -277,11 +290,11 @@ + { + PGSSubContext *ctx = avctx->priv_data; + +- int x, y; +- + int w = bytestream_get_be16(&buf); + int h = bytestream_get_be16(&buf); + ++ uint16_t object_index; ++ + av_dlog(avctx, "Video Dimensions %dx%d\n", + w, h); + if (av_image_check_size(w, h, 0, avctx) >= 0) +@@ -300,34 +313,48 @@ + */ + buf += 3; + +- ctx->presentation.object_number = bytestream_get_byte(&buf); +- if (!ctx->presentation.object_number) ++ ctx->presentation.object_count = bytestream_get_byte(&buf); ++ if (!ctx->presentation.object_count) + return; + +- /* +- * Skip 4 bytes of unknown: +- * object_id_ref (2 bytes), +- * window_id_ref, +- * composition_flag (0x80 - object cropped, 0x40 - object forced) +- */ +- buf += 4; +- +- x = bytestream_get_be16(&buf); +- y = bytestream_get_be16(&buf); +- +- /* TODO If cropping, cropping_x, cropping_y, cropping_width, cropping_height (all 2 bytes).*/ +- +- av_dlog(avctx, "Subtitle Placement x=%d, y=%d\n", x, y); ++ /* Verify that enough bytes are remaining for all of the objects. */ ++ buf_size -= 11; ++ if (buf_size < ctx->presentation.object_count * 8) { ++ ctx->presentation.object_count = 0; ++ return; ++ } + +- if (x > avctx->width || y > avctx->height) { +- av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n", +- x, y, avctx->width, avctx->height); +- x = 0; y = 0; ++ av_freep(&ctx->presentation.objects); ++ ctx->presentation.objects = av_malloc(sizeof(PGSSubPictureReference) * ctx->presentation.object_count); ++ if (!ctx->presentation.objects) { ++ ctx->presentation.object_count = 0; ++ return; + } + +- /* Fill in dimensions */ +- ctx->presentation.x = x; +- ctx->presentation.y = y; ++ for (object_index = 0; object_index < ctx->presentation.object_count; ++object_index) { ++ PGSSubPictureReference *reference = &ctx->presentation.objects[object_index]; ++ reference->picture_id = bytestream_get_be16(&buf); ++ ++ /* ++ * Skip 2 bytes of unknown: ++ * window_id_ref, ++ * composition_flag (0x80 - object cropped, 0x40 - object forced) ++ */ ++ buf += 2; ++ ++ reference->x = bytestream_get_be16(&buf); ++ reference->y = bytestream_get_be16(&buf); ++ ++ /* TODO If cropping, cropping_x, cropping_y, cropping_width, cropping_height (all 2 bytes).*/ ++ av_dlog(avctx, "Subtitle Placement ID=%d, x=%d, y=%d\n", reference->picture_id, reference->x, reference->y); ++ ++ if (reference->x > avctx->width || reference->y > avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, "Subtitle out of video bounds. x = %d, y = %d, video width = %d, video height = %d.\n", ++ reference->x, reference->y, avctx->width, avctx->height); ++ reference->x = 0; ++ reference->y = 0; ++ } ++ } + } + + /** +@@ -351,46 +378,52 @@ + AVSubtitle *sub = data; + PGSSubContext *ctx = avctx->priv_data; + ++ uint16_t rect; ++ + /* + * The end display time is a timeout value and is only reached +- * if the next subtitle is later then timeout or subtitle has ++ * if the next subtitle is later than timeout or subtitle has + * not been cleared by a subsequent empty display command. + */ + + memset(sub, 0, sizeof(*sub)); +- // Blank if last object_number was 0. +- // Note that this may be wrong for more complex subtitles. +- if (!ctx->presentation.object_number) ++ ++ // Blank if last object_count was 0. ++ if (!ctx->presentation.object_count) + return 1; ++ + sub->start_display_time = 0; + sub->end_display_time = 20000; + sub->format = 0; + +- sub->rects = av_mallocz(sizeof(*sub->rects)); +- sub->rects[0] = av_mallocz(sizeof(*sub->rects[0])); +- sub->num_rects = 1; +- +- sub->rects[0]->x = ctx->presentation.x; +- sub->rects[0]->y = ctx->presentation.y; +- sub->rects[0]->w = ctx->picture.w; +- sub->rects[0]->h = ctx->picture.h; +- sub->rects[0]->type = SUBTITLE_BITMAP; +- +- /* Process bitmap */ +- sub->rects[0]->pict.linesize[0] = ctx->picture.w; +- +- if (ctx->picture.rle) { +- if (ctx->picture.rle_remaining_len) +- av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n", +- ctx->picture.rle_data_len, ctx->picture.rle_remaining_len); +- if(decode_rle(avctx, sub, ctx->picture.rle, ctx->picture.rle_data_len) < 0) +- return 0; +- } +- /* Allocate memory for colors */ +- sub->rects[0]->nb_colors = 256; +- sub->rects[0]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); ++ sub->num_rects = ctx->presentation.object_count; ++ sub->rects = av_mallocz(sizeof(*sub->rects) * sub->num_rects); ++ ++ for (rect = 0; rect < sub->num_rects; ++rect) { ++ uint16_t picture_id = ctx->presentation.objects[rect].picture_id; ++ sub->rects[rect] = av_mallocz(sizeof(*sub->rects[rect])); ++ sub->rects[rect]->x = ctx->presentation.objects[rect].x; ++ sub->rects[rect]->y = ctx->presentation.objects[rect].y; ++ sub->rects[rect]->w = ctx->pictures[picture_id].w; ++ sub->rects[rect]->h = ctx->pictures[picture_id].h; ++ sub->rects[rect]->type = SUBTITLE_BITMAP; ++ ++ /* Process bitmap */ ++ sub->rects[rect]->pict.linesize[0] = ctx->pictures[picture_id].w; ++ if (ctx->pictures[picture_id].rle) { ++ if (ctx->pictures[picture_id].rle_remaining_len) ++ av_log(avctx, AV_LOG_ERROR, "RLE data length %u is %u bytes shorter than expected\n", ++ ctx->pictures[picture_id].rle_data_len, ctx->pictures[picture_id].rle_remaining_len); ++ if (decode_rle(avctx, sub, rect, ctx->pictures[picture_id].rle, ctx->pictures[picture_id].rle_data_len) < 0) ++ return 0; ++ } ++ ++ /* Allocate memory for colors */ ++ sub->rects[rect]->nb_colors = 256; ++ sub->rects[rect]->pict.data[1] = av_mallocz(AVPALETTE_SIZE); + +- memcpy(sub->rects[0]->pict.data[1], ctx->clut, sub->rects[0]->nb_colors * sizeof(uint32_t)); ++ memcpy(sub->rects[rect]->pict.data[1], ctx->clut, sub->rects[rect]->nb_colors * sizeof(uint32_t)); ++ } + + return 1; + } +@@ -404,21 +437,18 @@ + const uint8_t *buf_end; + uint8_t segment_type; + int segment_length; +- +-#ifdef DEBUG_PACKET_CONTENTS + int i; + +- av_log(avctx, AV_LOG_INFO, "PGS sub packet:\n"); ++ av_dlog(avctx, "PGS sub packet:\n"); + + for (i = 0; i < buf_size; i++) { +- av_log(avctx, AV_LOG_INFO, "%02x ", buf[i]); ++ av_dlog(avctx, "%02x ", buf[i]); + if (i % 16 == 15) +- av_log(avctx, AV_LOG_INFO, "\n"); ++ av_dlog(avctx, "\n"); + } + + if (i & 15) +- av_log(avctx, AV_LOG_INFO, "\n"); +-#endif ++ av_dlog(avctx, "\n"); + + *data_size = 0; + +@@ -474,13 +504,12 @@ + } + + AVCodec ff_pgssub_decoder = { +- "pgssub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_HDMV_PGS_SUBTITLE, +- sizeof(PGSSubContext), +- init_decoder, +- NULL, +- close_decoder, +- decode, ++ .name = "pgssub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_HDMV_PGS_SUBTITLE, ++ .priv_data_size = sizeof(PGSSubContext), ++ .init = init_decoder, ++ .close = close_decoder, ++ .decode = decode, + .long_name = NULL_IF_CONFIG_SMALL("HDMV Presentation Graphic Stream subtitles"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pictordec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pictordec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pictordec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pictordec.c 2012-05-14 14:08:54.106335393 +0200 +@@ -24,7 +24,7 @@ + * Pictor/PC Paint decoder + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + #include "cga_data.h" +@@ -33,6 +33,7 @@ + AVFrame frame; + int width, height; + int nb_planes; ++ GetByteContext g; + } PicContext; + + static void picmemset_8bpp(PicContext *s, int value, int run, int *x, int *y) +@@ -55,7 +56,8 @@ + } + } + +-static void picmemset(PicContext *s, int value, int run, int *x, int *y, int *plane, int bits_per_plane) ++static void picmemset(PicContext *s, int value, int run, ++ int *x, int *y, int *plane, int bits_per_plane) + { + uint8_t *d; + int shift = *plane * bits_per_plane; +@@ -94,39 +96,48 @@ + [5] = { 0, 11, 12, 15 }, // mode5, high intensity + }; + ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ PicContext *s = avctx->priv_data; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ return 0; ++} ++ + static int decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) + { + PicContext *s = avctx->priv_data; +- int buf_size = avpkt->size; +- const uint8_t *buf = avpkt->data; +- const uint8_t *buf_end = avpkt->data + buf_size; + uint32_t *palette; +- int bits_per_plane, bpp, etype, esize, npal; +- int i, x, y, plane; ++ int bits_per_plane, bpp, etype, esize, npal, pos_after_pal; ++ int i, x, y, plane, tmp; + +- if (buf_size < 11) ++ bytestream2_init(&s->g, avpkt->data, avpkt->size); ++ ++ if (bytestream2_get_bytes_left(&s->g) < 11) + return AVERROR_INVALIDDATA; + +- if (bytestream_get_le16(&buf) != 0x1234) ++ if (bytestream2_get_le16u(&s->g) != 0x1234) + return AVERROR_INVALIDDATA; +- s->width = bytestream_get_le16(&buf); +- s->height = bytestream_get_le16(&buf); +- buf += 4; +- bits_per_plane = *buf & 0xF; +- s->nb_planes = (*buf++ >> 4) + 1; +- bpp = s->nb_planes ? bits_per_plane*s->nb_planes : bits_per_plane; ++ ++ s->width = bytestream2_get_le16u(&s->g); ++ s->height = bytestream2_get_le16u(&s->g); ++ bytestream2_skip(&s->g, 4); ++ tmp = bytestream2_get_byteu(&s->g); ++ bits_per_plane = tmp & 0xF; ++ s->nb_planes = (tmp >> 4) + 1; ++ bpp = bits_per_plane * s->nb_planes; + if (bits_per_plane > 8 || bpp < 1 || bpp > 32) { +- av_log_ask_for_sample(s, "unsupported bit depth\n"); ++ av_log_ask_for_sample(avctx, "unsupported bit depth\n"); + return AVERROR_INVALIDDATA; + } + +- if (*buf == 0xFF) { +- buf += 2; +- etype = bytestream_get_le16(&buf); +- esize = bytestream_get_le16(&buf); +- if (buf_end - buf < esize) ++ if (bytestream2_peek_byte(&s->g) == 0xFF || bpp == 8) { ++ bytestream2_skip(&s->g, 2); ++ etype = bytestream2_get_le16(&s->g); ++ esize = bytestream2_get_le16(&s->g); ++ if (bytestream2_get_bytes_left(&s->g) < esize) + return AVERROR_INVALIDDATA; + } else { + etype = -1; +@@ -148,32 +159,39 @@ + return -1; + } + memset(s->frame.data[0], 0, s->height * s->frame.linesize[0]); +- s->frame.pict_type = FF_I_TYPE; ++ s->frame.pict_type = AV_PICTURE_TYPE_I; + s->frame.palette_has_changed = 1; + ++ pos_after_pal = bytestream2_tell(&s->g) + esize; + palette = (uint32_t*)s->frame.data[1]; +- if (etype == 1 && esize > 1 && *buf < 6) { +- int idx = *buf; ++ if (etype == 1 && esize > 1 && bytestream2_peek_byte(&s->g) < 6) { ++ int idx = bytestream2_get_byte(&s->g); + npal = 4; + for (i = 0; i < npal; i++) + palette[i] = ff_cga_palette[ cga_mode45_index[idx][i] ]; + } else if (etype == 2) { + npal = FFMIN(esize, 16); +- for (i = 0; i < npal; i++) +- palette[i] = ff_cga_palette[ FFMIN(buf[i], 16)]; ++ for (i = 0; i < npal; i++) { ++ int pal_idx = bytestream2_get_byte(&s->g); ++ palette[i] = ff_cga_palette[FFMIN(pal_idx, 16)]; ++ } + } else if (etype == 3) { + npal = FFMIN(esize, 16); +- for (i = 0; i < npal; i++) +- palette[i] = ff_ega_palette[ FFMIN(buf[i], 63)]; ++ for (i = 0; i < npal; i++) { ++ int pal_idx = bytestream2_get_byte(&s->g); ++ palette[i] = ff_ega_palette[FFMIN(pal_idx, 63)]; ++ } + } else if (etype == 4 || etype == 5) { + npal = FFMIN(esize / 3, 256); +- for (i = 0; i < npal; i++) +- palette[i] = AV_RB24(buf + i*3) << 2; ++ for (i = 0; i < npal; i++) { ++ palette[i] = bytestream2_get_be24(&s->g) << 2; ++ palette[i] |= 0xFFU << 24 | palette[i] >> 6 & 0x30303; ++ } + } else { + if (bpp == 1) { + npal = 2; +- palette[0] = 0x000000; +- palette[1] = 0xFFFFFF; ++ palette[0] = 0xFF000000; ++ palette[1] = 0xFFFFFFFF; + } else if (bpp == 2) { + npal = 4; + for (i = 0; i < npal; i++) +@@ -185,48 +203,54 @@ + } + // fill remaining palette entries + memset(palette + npal, 0, AVPALETTE_SIZE - npal * 4); +- buf += esize; ++ // skip remaining palette bytes ++ bytestream2_seek(&s->g, pos_after_pal, SEEK_SET); + +- +- x = 0; + y = s->height - 1; +- plane = 0; +- if (bytestream_get_le16(&buf)) { +- while (buf_end - buf >= 6) { +- const uint8_t *buf_pend = buf + FFMIN(AV_RL16(buf), buf_end - buf); +- //ignore uncompressed block size reported at buf[2] +- int marker = buf[4]; +- buf += 5; ++ if (bytestream2_get_le16(&s->g)) { ++ x = 0; ++ plane = 0; ++ while (y >= 0 && bytestream2_get_bytes_left(&s->g) >= 6) { ++ int stop_size, marker, t1, t2; ++ ++ t1 = bytestream2_get_bytes_left(&s->g); ++ t2 = bytestream2_get_le16(&s->g); ++ stop_size = t1 - FFMIN(t1, t2); ++ // ignore uncompressed block size ++ bytestream2_skip(&s->g, 2); ++ marker = bytestream2_get_byte(&s->g); + +- while (plane < s->nb_planes && buf_pend - buf >= 1) { ++ while (plane < s->nb_planes && y >= 0 && ++ bytestream2_get_bytes_left(&s->g) > stop_size) { + int run = 1; +- int val = *buf++; ++ int val = bytestream2_get_byte(&s->g); + if (val == marker) { +- run = *buf++; ++ run = bytestream2_get_byte(&s->g); + if (run == 0) +- run = bytestream_get_le16(&buf); +- val = *buf++; ++ run = bytestream2_get_le16(&s->g); ++ val = bytestream2_get_byte(&s->g); + } +- if (buf > buf_end) ++ if (!bytestream2_get_bytes_left(&s->g)) + break; + + if (bits_per_plane == 8) { + picmemset_8bpp(s, val, run, &x, &y); +- if (y < 0) +- break; + } else { + picmemset(s, val, run, &x, &y, &plane, bits_per_plane); + } + } + } + } else { +- av_log_ask_for_sample(s, "uncompressed image\n"); +- return buf_size; ++ while (y >= 0 && bytestream2_get_bytes_left(&s->g) > 0) { ++ memcpy(s->frame.data[0] + y * s->frame.linesize[0], s->g.buffer, FFMIN(avctx->width, bytestream2_get_bytes_left(&s->g))); ++ bytestream2_skip(&s->g, avctx->width); ++ y--; ++ } + } + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = s->frame; +- return buf_size; ++ return avpkt->size; + } + + static av_cold int decode_end(AVCodecContext *avctx) +@@ -238,14 +262,13 @@ + } + + AVCodec ff_pictor_decoder = { +- "pictor", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PICTOR, +- sizeof(PicContext), +- NULL, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "pictor", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PICTOR, ++ .priv_data_size = sizeof(PicContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Pictor/PC Paint"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/png.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/png.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/png.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/png.c 2012-05-14 14:08:54.107335414 +0200 +@@ -19,7 +19,6 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avcodec.h" +-#include "bytestream.h" + #include "png.h" + + const uint8_t ff_pngsig[8] = {137, 80, 78, 71, 13, 10, 26, 10}; +@@ -42,7 +41,7 @@ + + /* Mask to determine which pixels are valid in a pass */ + const uint8_t ff_png_pass_mask[NB_PASSES] = { +- 0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff ++ 0x01, 0x01, 0x11, 0x11, 0x55, 0x55, 0xff, + }; + + void *ff_png_zalloc(void *opaque, unsigned int items, unsigned int size) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pngdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pngdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pngdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pngdec.c 2012-05-14 14:08:54.109335454 +0200 +@@ -18,57 +18,23 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +-#include "libavcore/imgutils.h" ++ ++//#define DEBUG ++ ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + #include "png.h" +-#include "dsputil.h" + + /* TODO: +- * - add 2, 4 and 16 bit depth support ++ * - add 16 bit depth support + */ + + #include + +-//#define DEBUG +- +-typedef struct PNGDecContext { +- DSPContext dsp; +- +- const uint8_t *bytestream; +- const uint8_t *bytestream_start; +- const uint8_t *bytestream_end; +- AVFrame picture1, picture2; +- AVFrame *current_picture, *last_picture; +- +- int state; +- int width, height; +- int bit_depth; +- int color_type; +- int compression_type; +- int interlace_type; +- int filter_type; +- int channels; +- int bits_per_pixel; +- int bpp; +- +- uint8_t *image_buf; +- int image_linesize; +- uint32_t palette[256]; +- uint8_t *crow_buf; +- uint8_t *last_row; +- uint8_t *tmp_row; +- int pass; +- int crow_size; /* compressed row size (include filter type) */ +- int row_size; /* decompressed row size */ +- int pass_row_size; /* decompress row size of the current pass */ +- int y; +- z_stream zstream; +-} PNGDecContext; +- + /* Mask to determine which y pixels can be written in a pass */ + static const uint8_t png_pass_dsp_ymask[NB_PASSES] = { +- 0xff, 0xff, 0x0f, 0xcc, 0x33, 0xff, 0x55, ++ 0xff, 0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, + }; + + /* Mask to determine which pixels to overwrite while displaying */ +@@ -91,35 +57,50 @@ + dsp_mask = png_pass_dsp_mask[pass]; + switch(bits_per_pixel) { + case 1: +- /* we must initialize the line to zero before writing to it */ +- if (pass == 0) +- memset(dst, 0, (width + 7) >> 3); + src_x = 0; + for(x = 0; x < width; x++) { + j = (x & 7); + if ((dsp_mask << j) & 0x80) { + b = (src[src_x >> 3] >> (7 - (src_x & 7))) & 1; ++ dst[x >> 3] &= 0xFF7F>>j; + dst[x >> 3] |= b << (7 - j); + } + if ((mask << j) & 0x80) + src_x++; + } + break; ++ case 2: ++ src_x = 0; ++ for(x = 0; x < width; x++) { ++ int j2 = 2*(x&3); ++ j = (x & 7); ++ if ((dsp_mask << j) & 0x80) { ++ b = (src[src_x >> 2] >> (6 - 2*(src_x & 3))) & 3; ++ dst[x >> 2] &= 0xFF3F>>j2; ++ dst[x >> 2] |= b << (6 - j2); ++ } ++ if ((mask << j) & 0x80) ++ src_x++; ++ } ++ break; ++ case 4: ++ src_x = 0; ++ for(x = 0; x < width; x++) { ++ int j2 = 4*(x&1); ++ j = (x & 7); ++ if ((dsp_mask << j) & 0x80) { ++ b = (src[src_x >> 1] >> (4 - 4*(src_x & 1))) & 15; ++ dst[x >> 1] &= 0xFF0F>>j2; ++ dst[x >> 1] |= b << (4 - j2); ++ } ++ if ((mask << j) & 0x80) ++ src_x++; ++ } ++ break; + default: + bpp = bits_per_pixel >> 3; + d = dst; + s = src; +- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- for(x = 0; x < width; x++) { +- j = x & 7; +- if ((dsp_mask << j) & 0x80) { +- *(uint32_t *)d = (s[3] << 24) | (s[0] << 16) | (s[1] << 8) | s[2]; +- } +- d += bpp; +- if ((mask << j) & 0x80) +- s += bpp; +- } +- } else { + for(x = 0; x < width; x++) { + j = x & 7; + if ((dsp_mask << j) & 0x80) { +@@ -129,12 +110,27 @@ + if ((mask << j) & 0x80) + s += bpp; + } +- } + break; + } + } + +-void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp) ++// 0x7f7f7f7f or 0x7f7f7f7f7f7f7f7f or whatever, depending on the cpu's native arithmetic size ++#define pb_7f (~0UL/255 * 0x7f) ++#define pb_80 (~0UL/255 * 0x80) ++ ++static void add_bytes_l2_c(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) ++{ ++ long i; ++ for(i=0; i<=w-sizeof(long); i+=sizeof(long)){ ++ long a = *(long*)(src1+i); ++ long b = *(long*)(src2+i); ++ *(long*)(dst+i) = ((a&pb_7f) + (b&pb_7f)) ^ ((a^b)&pb_80); ++ } ++ for(; iadd_bytes_l2(dst, src, last, size); ++ s->add_bytes_l2(dst, src, last, size); + break; + case PNG_FILTER_VALUE_AVG: + for(i = 0; i < bpp; i++) { +@@ -232,13 +228,13 @@ + p = last[i]; + dst[i] = p + src[i]; + } +- if(bpp > 1 && size > 4) { ++ if(bpp > 2 && size > 4) { + // would write off the end of the array if we let it process the last pixel with bpp=3 + int w = bpp==4 ? size : size-3; +- dsp->add_png_paeth_prediction(dst+i, src+i, last+i, w-i, bpp); ++ s->add_paeth_prediction(dst+i, src+i, last+i, w-i, bpp); + i = w; + } +- ff_add_png_paeth_prediction(dst+i, src+i, last+i, size-i, bpp); ++ add_paeth_prediction_c(dst+i, src+i, last+i, size-i, bpp); + break; + } + } +@@ -257,7 +253,10 @@ + r = (r+g)&0xff; + b = (b+g)&0xff; + } +- *(uint32_t *)dst = (a << 24) | (r << 16) | (g << 8) | b; ++ dst[0] = r; ++ dst[1] = g; ++ dst[2] = b; ++ dst[3] = a; + dst += 4; + src += 4; + } +@@ -268,7 +267,7 @@ + if(loco) + convert_to_rgb32_loco(dst, src, width, 1); + else +- convert_to_rgb32_loco(dst, src, width, 0); ++ memcpy(dst, src, width * 4); + } + + static void deloco_rgb24(uint8_t *dst, int size) +@@ -291,7 +290,7 @@ + ptr = s->image_buf + s->image_linesize * s->y; + /* need to swap bytes correctly for RGB_ALPHA */ + if (s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, ++ png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, + s->last_row, s->row_size, s->bpp); + convert_to_rgb32(ptr, s->tmp_row, s->width, s->filter_type == PNG_FILTER_TYPE_LOCO); + FFSWAP(uint8_t*, s->last_row, s->tmp_row); +@@ -302,7 +301,7 @@ + else + last_row = ptr - s->image_linesize; + +- png_filter_row(&s->dsp, ptr, s->crow_buf[0], s->crow_buf + 1, ++ png_filter_row(s, ptr, s->crow_buf[0], s->crow_buf + 1, + last_row, s->row_size, s->bpp); + } + /* loco lags by 1 row so that it doesn't interfere with top prediction */ +@@ -325,18 +324,18 @@ + wait for the next one */ + if (got_line) + break; +- png_filter_row(&s->dsp, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, ++ png_filter_row(s, s->tmp_row, s->crow_buf[0], s->crow_buf + 1, + s->last_row, s->pass_row_size, s->bpp); + FFSWAP(uint8_t*, s->last_row, s->tmp_row); + got_line = 1; + } + if ((png_pass_dsp_ymask[s->pass] << (s->y & 7)) & 0x80) { +- /* NOTE: RGB32 is handled directly in png_put_interlaced_row */ + png_put_interlaced_row(ptr, s->width, s->bits_per_pixel, s->pass, + s->color_type, s->last_row); + } + s->y++; + if (s->y == s->height) { ++ memset(s->last_row, 0, s->row_size); + for(;;) { + if (s->pass == NB_PASSES - 1) { + s->state |= PNG_ALLIMAGE; +@@ -362,12 +361,9 @@ + static int png_decode_idat(PNGDecContext *s, int length) + { + int ret; +- s->zstream.avail_in = length; +- s->zstream.next_in = s->bytestream; +- s->bytestream += length; +- +- if(s->bytestream > s->bytestream_end) +- return -1; ++ s->zstream.avail_in = FFMIN(length, bytestream2_get_bytes_left(&s->gb)); ++ s->zstream.next_in = s->gb.buffer; ++ bytestream2_skip(&s->gb, length); + + /* decode one line if possible */ + while (s->zstream.avail_in > 0) { +@@ -397,21 +393,19 @@ + AVFrame *p; + uint8_t *crow_buf_base = NULL; + uint32_t tag, length; +- int ret, crc; ++ int ret; + + FFSWAP(AVFrame *, s->current_picture, s->last_picture); + avctx->coded_frame= s->current_picture; + p = s->current_picture; + +- s->bytestream_start= +- s->bytestream= buf; +- s->bytestream_end= buf + buf_size; +- + /* check signature */ +- if (memcmp(s->bytestream, ff_pngsig, 8) != 0 && +- memcmp(s->bytestream, ff_mngsig, 8) != 0) ++ if (buf_size < 8 || ++ memcmp(buf, ff_pngsig, 8) != 0 && ++ memcmp(buf, ff_mngsig, 8) != 0) + return -1; +- s->bytestream+= 8; ++ ++ bytestream2_init(&s->gb, buf + 8, buf_size - 8); + s->y= + s->state=0; + // memset(s, 0, sizeof(PNGDecContext)); +@@ -423,15 +417,14 @@ + if (ret != Z_OK) + return -1; + for(;;) { +- int tag32; +- if (s->bytestream >= s->bytestream_end) ++ if (bytestream2_get_bytes_left(&s->gb) <= 0) + goto fail; +- length = bytestream_get_be32(&s->bytestream); ++ length = bytestream2_get_be32(&s->gb); + if (length > 0x7fffffff) + goto fail; +- tag32 = bytestream_get_be32(&s->bytestream); +- tag = av_bswap32(tag32); +- av_dlog(avctx, "png: tag=%c%c%c%c length=%u\n", ++ tag = bytestream2_get_le32(&s->gb); ++ if (avctx->debug & FF_DEBUG_STARTCODE) ++ av_log(avctx, AV_LOG_DEBUG, "png: tag=%c%c%c%c length=%u\n", + (tag & 0xff), + ((tag >> 8) & 0xff), + ((tag >> 16) & 0xff), +@@ -440,20 +433,21 @@ + case MKTAG('I', 'H', 'D', 'R'): + if (length != 13) + goto fail; +- s->width = bytestream_get_be32(&s->bytestream); +- s->height = bytestream_get_be32(&s->bytestream); ++ s->width = bytestream2_get_be32(&s->gb); ++ s->height = bytestream2_get_be32(&s->gb); + if(av_image_check_size(s->width, s->height, 0, avctx)){ + s->width= s->height= 0; + goto fail; + } +- s->bit_depth = *s->bytestream++; +- s->color_type = *s->bytestream++; +- s->compression_type = *s->bytestream++; +- s->filter_type = *s->bytestream++; +- s->interlace_type = *s->bytestream++; +- crc = bytestream_get_be32(&s->bytestream); ++ s->bit_depth = bytestream2_get_byte(&s->gb); ++ s->color_type = bytestream2_get_byte(&s->gb); ++ s->compression_type = bytestream2_get_byte(&s->gb); ++ s->filter_type = bytestream2_get_byte(&s->gb); ++ s->interlace_type = bytestream2_get_byte(&s->gb); ++ bytestream2_skip(&s->gb, 4); /* crc */ + s->state |= PNG_IHDR; +- av_dlog(avctx, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n", ++ if (avctx->debug & FF_DEBUG_PICT_INFO) ++ av_log(avctx, AV_LOG_DEBUG, "width=%d height=%d depth=%d color_type=%d compression_type=%d filter_type=%d interlace_type=%d\n", + s->width, s->height, s->bit_depth, s->color_type, + s->compression_type, s->filter_type, s->interlace_type); + break; +@@ -475,7 +469,7 @@ + avctx->pix_fmt = PIX_FMT_RGB24; + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- avctx->pix_fmt = PIX_FMT_RGB32; ++ avctx->pix_fmt = PIX_FMT_RGBA; + } else if (s->bit_depth == 8 && + s->color_type == PNG_COLOR_TYPE_GRAY) { + avctx->pix_fmt = PIX_FMT_GRAY8; +@@ -485,25 +479,28 @@ + } else if (s->bit_depth == 16 && + s->color_type == PNG_COLOR_TYPE_RGB) { + avctx->pix_fmt = PIX_FMT_RGB48BE; +- } else if (s->bit_depth == 1 && +- s->color_type == PNG_COLOR_TYPE_GRAY) { +- avctx->pix_fmt = PIX_FMT_MONOBLACK; + } else if (s->color_type == PNG_COLOR_TYPE_PALETTE) { + avctx->pix_fmt = PIX_FMT_PAL8; +- } else if (s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { +- avctx->pix_fmt = PIX_FMT_Y400A; ++ } else if (s->bit_depth == 1) { ++ avctx->pix_fmt = PIX_FMT_MONOBLACK; ++ } else if (s->bit_depth == 8 && ++ s->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) { ++ avctx->pix_fmt = PIX_FMT_GRAY8A; + } else { ++ av_log(avctx, AV_LOG_ERROR, "unsupported bit depth %d " ++ "and color type %d\n", ++ s->bit_depth, s->color_type); + goto fail; + } + if(p->data[0]) + avctx->release_buffer(avctx, p); + +- p->reference= 0; ++ p->reference= 3; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto fail; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + p->interlaced_frame = !!s->interlace_type; + +@@ -522,7 +519,7 @@ + s->image_buf = p->data[0]; + s->image_linesize = p->linesize[0]; + /* copy the palette if needed */ +- if (s->color_type == PNG_COLOR_TYPE_PALETTE) ++ if (avctx->pix_fmt == PIX_FMT_PAL8) + memcpy(p->data[1], s->palette, 256 * sizeof(uint32_t)); + /* empty row is used if differencing to the first row */ + s->last_row = av_mallocz(s->row_size); +@@ -547,8 +544,7 @@ + s->state |= PNG_IDAT; + if (png_decode_idat(s, length) < 0) + goto fail; +- /* skip crc */ +- crc = bytestream_get_be32(&s->bytestream); ++ bytestream2_skip(&s->gb, 4); /* crc */ + break; + case MKTAG('P', 'L', 'T', 'E'): + { +@@ -559,16 +555,16 @@ + /* read the palette */ + n = length / 3; + for(i=0;ibytestream++; +- g = *s->bytestream++; +- b = *s->bytestream++; ++ r = bytestream2_get_byte(&s->gb); ++ g = bytestream2_get_byte(&s->gb); ++ b = bytestream2_get_byte(&s->gb); + s->palette[i] = (0xff << 24) | (r << 16) | (g << 8) | b; + } + for(;i<256;i++) { + s->palette[i] = (0xff << 24); + } + s->state |= PNG_PLTE; +- crc = bytestream_get_be32(&s->bytestream); ++ bytestream2_skip(&s->gb, 4); /* crc */ + } + break; + case MKTAG('t', 'R', 'N', 'S'): +@@ -581,25 +577,68 @@ + !(s->state & PNG_PLTE)) + goto skip_tag; + for(i=0;ibytestream++; ++ v = bytestream2_get_byte(&s->gb); + s->palette[i] = (s->palette[i] & 0x00ffffff) | (v << 24); + } +- crc = bytestream_get_be32(&s->bytestream); ++ bytestream2_skip(&s->gb, 4); /* crc */ + } + break; + case MKTAG('I', 'E', 'N', 'D'): + if (!(s->state & PNG_ALLIMAGE)) + goto fail; +- crc = bytestream_get_be32(&s->bytestream); ++ bytestream2_skip(&s->gb, 4); /* crc */ + goto exit_loop; + default: + /* skip tag */ + skip_tag: +- s->bytestream += length + 4; ++ bytestream2_skip(&s->gb, length + 4); + break; + } + } + exit_loop: ++ ++ if(s->bits_per_pixel == 1 && s->color_type == PNG_COLOR_TYPE_PALETTE){ ++ int i, j; ++ uint8_t *pd = s->current_picture->data[0]; ++ for(j=0; j < s->height; j++) { ++ for(i=s->width/8-1; i>=0; i--) { ++ pd[8*i+7]= pd[i] &1; ++ pd[8*i+6]= (pd[i]>>1)&1; ++ pd[8*i+5]= (pd[i]>>2)&1; ++ pd[8*i+4]= (pd[i]>>3)&1; ++ pd[8*i+3]= (pd[i]>>4)&1; ++ pd[8*i+2]= (pd[i]>>5)&1; ++ pd[8*i+1]= (pd[i]>>6)&1; ++ pd[8*i+0]= pd[i]>>7; ++ } ++ pd += s->image_linesize; ++ } ++ } ++ if(s->bits_per_pixel == 2){ ++ int i, j; ++ uint8_t *pd = s->current_picture->data[0]; ++ for(j=0; j < s->height; j++) { ++ for(i=s->width/4-1; i>=0; i--) { ++ pd[4*i+3]= pd[i] &3; ++ pd[4*i+2]= (pd[i]>>2)&3; ++ pd[4*i+1]= (pd[i]>>4)&3; ++ pd[4*i+0]= pd[i]>>6; ++ } ++ pd += s->image_linesize; ++ } ++ } ++ if(s->bits_per_pixel == 4){ ++ int i, j; ++ uint8_t *pd = s->current_picture->data[0]; ++ for(j=0; j < s->height; j++) { ++ for(i=s->width/2-1; i>=0; i--) { ++ pd[2*i+1]= pd[i]&15; ++ pd[2*i+0]= pd[i]>>4; ++ } ++ pd += s->image_linesize; ++ } ++ } ++ + /* handle p-frames only if a predecessor frame is available */ + if(s->last_picture->data[0] != NULL) { + if(!(avpkt->flags & AV_PKT_FLAG_KEY)) { +@@ -620,7 +659,7 @@ + *picture= *s->current_picture; + *data_size = sizeof(AVFrame); + +- ret = s->bytestream - s->bytestream_start; ++ ret = bytestream2_tell(&s->gb); + the_end: + inflateEnd(&s->zstream); + av_free(crow_buf_base); +@@ -633,14 +672,23 @@ + goto the_end; + } + +-static av_cold int png_dec_init(AVCodecContext *avctx){ ++static av_cold int png_dec_init(AVCodecContext *avctx) ++{ + PNGDecContext *s = avctx->priv_data; + + s->current_picture = &s->picture1; + s->last_picture = &s->picture2; + avcodec_get_frame_defaults(&s->picture1); + avcodec_get_frame_defaults(&s->picture2); +- dsputil_init(&s->dsp, avctx); ++ ++#if HAVE_MMX ++ ff_png_init_mmx(s); ++#endif ++ ++ if (!s->add_paeth_prediction) ++ s->add_paeth_prediction = add_paeth_prediction_c; ++ if (!s->add_bytes_l2) ++ s->add_bytes_l2 = add_bytes_l2_c; + + return 0; + } +@@ -658,16 +706,13 @@ + } + + AVCodec ff_png_decoder = { +- "png", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PNG, +- sizeof(PNGDecContext), +- png_dec_init, +- NULL, +- png_dec_end, +- decode_frame, +- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, +- NULL, +- .max_lowres = 5, ++ .name = "png", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PNG, ++ .priv_data_size = sizeof(PNGDecContext), ++ .init = png_dec_init, ++ .close = png_dec_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, + .long_name = NULL_IF_CONFIG_SMALL("PNG image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pngenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pngenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pngenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pngenc.c 2012-05-14 14:08:54.111335494 +0200 +@@ -172,23 +172,6 @@ + } + } + +-static void convert_from_rgb32(uint8_t *dst, const uint8_t *src, int width) +-{ +- uint8_t *d; +- int j; +- unsigned int v; +- +- d = dst; +- for(j = 0; j < width; j++) { +- v = ((const uint32_t *)src)[j]; +- d[0] = v >> 16; +- d[1] = v >> 8; +- d[2] = v; +- d[3] = v >> 24; +- d += 4; +- } +-} +- + static void png_write_chunk(uint8_t **f, uint32_t tag, + const uint8_t *buf, int length) + { +@@ -239,11 +222,10 @@ + uint8_t *ptr, *top; + uint8_t *crow_base = NULL, *crow_buf, *crow; + uint8_t *progressive_buf = NULL; +- uint8_t *rgba_buf = NULL; + uint8_t *top_buf = NULL; + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + s->bytestream_start= +@@ -252,7 +234,15 @@ + + is_progressive = !!(avctx->flags & CODEC_FLAG_INTERLACED_DCT); + switch(avctx->pix_fmt) { +- case PIX_FMT_RGB32: ++ case PIX_FMT_RGBA64BE: ++ bit_depth = 16; ++ color_type = PNG_COLOR_TYPE_RGB_ALPHA; ++ break; ++ case PIX_FMT_RGB48BE: ++ bit_depth = 16; ++ color_type = PNG_COLOR_TYPE_RGB; ++ break; ++ case PIX_FMT_RGBA: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + break; +@@ -260,10 +250,18 @@ + bit_depth = 8; + color_type = PNG_COLOR_TYPE_RGB; + break; ++ case PIX_FMT_GRAY16BE: ++ bit_depth = 16; ++ color_type = PNG_COLOR_TYPE_GRAY; ++ break; + case PIX_FMT_GRAY8: + bit_depth = 8; + color_type = PNG_COLOR_TYPE_GRAY; + break; ++ case PIX_FMT_GRAY8A: ++ bit_depth = 8; ++ color_type = PNG_COLOR_TYPE_GRAY_ALPHA; ++ break; + case PIX_FMT_MONOBLACK: + bit_depth = 1; + color_type = PNG_COLOR_TYPE_GRAY; +@@ -297,12 +295,7 @@ + if (!progressive_buf) + goto fail; + } +- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- rgba_buf = av_malloc(row_size + 1); +- if (!rgba_buf) +- goto fail; +- } +- if (is_progressive || color_type == PNG_COLOR_TYPE_RGB_ALPHA) { ++ if (is_progressive) { + top_buf = av_malloc(row_size + 1); + if (!top_buf) + goto fail; +@@ -336,7 +329,7 @@ + for(i = 0; i < 256; i++) { + v = palette[i]; + alpha = v >> 24; +- if (alpha && alpha != 0xff) ++ if (alpha != 0xff) + has_alpha = 1; + *alpha_ptr++ = alpha; + bytestream_put_be24(&ptr, v); +@@ -363,10 +356,6 @@ + if ((ff_png_pass_ymask[pass] << (y & 7)) & 0x80) { + ptr = p->data[0] + y * p->linesize[0]; + FFSWAP(uint8_t*, progressive_buf, top_buf); +- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- convert_from_rgb32(rgba_buf, ptr, avctx->width); +- ptr = rgba_buf; +- } + png_get_interlaced_row(progressive_buf, pass_row_size, + bits_per_pixel, pass, + ptr, avctx->width); +@@ -381,11 +370,6 @@ + top = NULL; + for(y = 0; y < avctx->height; y++) { + ptr = p->data[0] + y * p->linesize[0]; +- if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { +- FFSWAP(uint8_t*, rgba_buf, top_buf); +- convert_from_rgb32(rgba_buf, ptr, avctx->width); +- ptr = rgba_buf; +- } + crow = png_choose_filter(s, crow_buf, ptr, top, row_size, bits_per_pixel>>3); + png_write_row(s, crow, row_size + 1); + top = ptr; +@@ -413,7 +397,6 @@ + the_end: + av_free(crow_base); + av_free(progressive_buf); +- av_free(rgba_buf); + av_free(top_buf); + deflateEnd(&s->zstream); + return ret; +@@ -437,13 +420,17 @@ + } + + AVCodec ff_png_encoder = { +- "png", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PNG, +- sizeof(PNGEncContext), +- png_enc_init, +- encode_frame, +- NULL, //encode_end, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_PAL8, PIX_FMT_GRAY8, PIX_FMT_MONOBLACK, PIX_FMT_NONE}, ++ .name = "png", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PNG, ++ .priv_data_size = sizeof(PNGEncContext), ++ .init = png_enc_init, ++ .encode = encode_frame, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, ++ PIX_FMT_RGB48BE, PIX_FMT_RGBA64BE, ++ PIX_FMT_PAL8, ++ PIX_FMT_GRAY8, PIX_FMT_GRAY8A, ++ PIX_FMT_GRAY16BE, ++ PIX_FMT_MONOBLACK, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("PNG image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/png.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/png.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/png.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/png.h 2012-05-14 14:08:54.107335414 +0200 +@@ -23,6 +23,10 @@ + #define AVCODEC_PNG_H + + #include ++#include ++ ++#include "avcodec.h" ++#include "bytestream.h" + + #define PNG_COLOR_MASK_PALETTE 1 + #define PNG_COLOR_MASK_COLOR 2 +@@ -69,4 +73,39 @@ + + void ff_add_png_paeth_prediction(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); + ++typedef struct PNGDecContext { ++ GetByteContext gb; ++ AVFrame picture1, picture2; ++ AVFrame *current_picture, *last_picture; ++ ++ int state; ++ int width, height; ++ int bit_depth; ++ int color_type; ++ int compression_type; ++ int interlace_type; ++ int filter_type; ++ int channels; ++ int bits_per_pixel; ++ int bpp; ++ ++ uint8_t *image_buf; ++ int image_linesize; ++ uint32_t palette[256]; ++ uint8_t *crow_buf; ++ uint8_t *last_row; ++ uint8_t *tmp_row; ++ int pass; ++ int crow_size; /* compressed row size (include filter type) */ ++ int row_size; /* decompressed row size */ ++ int pass_row_size; /* decompress row size of the current pass */ ++ int y; ++ z_stream zstream; ++ ++ void (*add_bytes_l2)(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w); ++ void (*add_paeth_prediction)(uint8_t *dst, uint8_t *src, uint8_t *top, int w, int bpp); ++} PNGDecContext; ++ ++void ff_png_init_mmx(PNGDecContext *s); ++ + #endif /* AVCODEC_PNG_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnm.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnm.c 2012-05-14 14:08:54.111335494 +0200 +@@ -19,7 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "pnm.h" + +@@ -93,7 +93,9 @@ + } else if (!strcmp(buf1, "MAXVAL")) { + pnm_get(s, buf1, sizeof(buf1)); + maxval = strtol(buf1, NULL, 10); +- } else if (!strcmp(buf1, "TUPLETYPE")) { ++ } else if (!strcmp(buf1, "TUPLTYPE") || ++ /* libavcodec used to write invalid files */ ++ !strcmp(buf1, "TUPLETYPE")) { + pnm_get(s, tuple_type, sizeof(tuple_type)); + } else if (!strcmp(buf1, "ENDHDR")) { + break; +@@ -107,21 +109,30 @@ + + avctx->width = w; + avctx->height = h; ++ s->maxval = maxval; + if (depth == 1) { +- if (maxval == 1) ++ if (maxval == 1) { + avctx->pix_fmt = PIX_FMT_MONOWHITE; +- else ++ } else if (maxval == 255) { + avctx->pix_fmt = PIX_FMT_GRAY8; ++ } else { ++ avctx->pix_fmt = PIX_FMT_GRAY16BE; ++ } ++ } else if (depth == 2) { ++ if (maxval == 255) ++ avctx->pix_fmt = PIX_FMT_GRAY8A; + } else if (depth == 3) { + if (maxval < 256) { + avctx->pix_fmt = PIX_FMT_RGB24; + } else { +- av_log(avctx, AV_LOG_ERROR, "16-bit components are only supported for grayscale\n"); +- avctx->pix_fmt = PIX_FMT_NONE; +- return -1; ++ avctx->pix_fmt = PIX_FMT_RGB48BE; + } + } else if (depth == 4) { +- avctx->pix_fmt = PIX_FMT_RGB32; ++ if (maxval < 256) { ++ avctx->pix_fmt = PIX_FMT_RGBA; ++ } else { ++ avctx->pix_fmt = PIX_FMT_RGBA64BE; ++ } + } else { + return -1; + } +@@ -135,7 +146,7 @@ + return -1; + pnm_get(s, buf1, sizeof(buf1)); + avctx->height = atoi(buf1); +- if(av_image_check_size(avctx->width, avctx->height, 0, avctx)) ++ if(avctx->height <= 0 || av_image_check_size(avctx->width, avctx->height, 0, avctx)) + return -1; + if (avctx->pix_fmt != PIX_FMT_MONOWHITE) { + pnm_get(s, buf1, sizeof(buf1)); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnmdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnmdec.c 2012-05-14 14:08:54.113335534 +0200 +@@ -20,7 +20,6 @@ + */ + + #include "avcodec.h" +-#include "bytestream.h" + #include "put_bits.h" + #include "pnm.h" + +@@ -33,7 +32,7 @@ + PNMContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = (AVFrame*)&s->picture; +- int i, j, n, linesize, h, upgrade = 0; ++ int i, j, n, linesize, h, upgrade = 0, is_mono = 0; + unsigned char *ptr; + int components, sample_len; + +@@ -52,17 +51,27 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + + switch (avctx->pix_fmt) { + default: + return -1; ++ case PIX_FMT_RGBA64BE: ++ n = avctx->width * 8; ++ components=4; ++ sample_len=16; ++ goto do_read; + case PIX_FMT_RGB48BE: + n = avctx->width * 6; + components=3; + sample_len=16; + goto do_read; ++ case PIX_FMT_RGBA: ++ n = avctx->width * 4; ++ components=4; ++ sample_len=8; ++ goto do_read; + case PIX_FMT_RGB24: + n = avctx->width * 3; + components=3; +@@ -75,6 +84,11 @@ + if (s->maxval < 255) + upgrade = 1; + goto do_read; ++ case PIX_FMT_GRAY8A: ++ n = avctx->width * 2; ++ components=2; ++ sample_len=8; ++ goto do_read; + case PIX_FMT_GRAY16BE: + case PIX_FMT_GRAY16LE: + n = avctx->width * 2; +@@ -88,6 +102,7 @@ + n = (avctx->width + 7) >> 3; + components=1; + sample_len=1; ++ is_mono = 1; + do_read: + ptr = p->data[0]; + linesize = p->linesize[0]; +@@ -104,10 +119,16 @@ + s->bytestream++; + if(s->bytestream >= s->bytestream_end) + return -1; +- do{ +- v= 10*v + c; +- c= (*s->bytestream++) - '0'; +- }while(c <= 9); ++ if (is_mono) { ++ /* read a single digit */ ++ v = (*s->bytestream++) - '0'; ++ } else { ++ /* read a sequence of digits */ ++ do { ++ v = 10*v + c; ++ c = (*s->bytestream++) - '0'; ++ } while (c <= 9); ++ } + put_bits(&pb, sample_len, (((1<maxval>>1))/s->maxval); + } + flush_put_bits(&pb); +@@ -161,24 +182,6 @@ + } + } + break; +- case PIX_FMT_RGB32: +- ptr = p->data[0]; +- linesize = p->linesize[0]; +- if (s->bytestream + avctx->width * avctx->height * 4 > s->bytestream_end) +- return -1; +- for (i = 0; i < avctx->height; i++) { +- int j, r, g, b, a; +- +- for (j = 0; j < avctx->width; j++) { +- r = *s->bytestream++; +- g = *s->bytestream++; +- b = *s->bytestream++; +- a = *s->bytestream++; +- ((uint32_t *)ptr)[j] = (a << 24) | (r << 16) | (g << 8) | b; +- } +- ptr += linesize; +- } +- break; + } + *picture = *(AVFrame*)&s->picture; + *data_size = sizeof(AVPicture); +@@ -189,85 +192,75 @@ + + #if CONFIG_PGM_DECODER + AVCodec ff_pgm_decoder = { +- "pgm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PGM, +- sizeof(PNMContext), +- ff_pnm_init, +- NULL, +- ff_pnm_end, +- pnm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "pgm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PGM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .close = ff_pnm_end, ++ .decode = pnm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, +- .max_lowres = 5, + .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), + }; + #endif + + #if CONFIG_PGMYUV_DECODER + AVCodec ff_pgmyuv_decoder = { +- "pgmyuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PGMYUV, +- sizeof(PNMContext), +- ff_pnm_init, +- NULL, +- ff_pnm_end, +- pnm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "pgmyuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PGMYUV, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .close = ff_pnm_end, ++ .decode = pnm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, +- .max_lowres = 5, + .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), + }; + #endif + + #if CONFIG_PPM_DECODER + AVCodec ff_ppm_decoder = { +- "ppm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PPM, +- sizeof(PNMContext), +- ff_pnm_init, +- NULL, +- ff_pnm_end, +- pnm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "ppm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PPM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .close = ff_pnm_end, ++ .decode = pnm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, +- .max_lowres = 5, + .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), + }; + #endif + + #if CONFIG_PBM_DECODER + AVCodec ff_pbm_decoder = { +- "pbm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PBM, +- sizeof(PNMContext), +- ff_pnm_init, +- NULL, +- ff_pnm_end, +- pnm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "pbm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PBM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .close = ff_pnm_end, ++ .decode = pnm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, +- .max_lowres = 5, + .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), + }; + #endif + + #if CONFIG_PAM_DECODER + AVCodec ff_pam_decoder = { +- "pam", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PAM, +- sizeof(PNMContext), +- ff_pnm_init, +- NULL, +- ff_pnm_end, +- pnm_decode_frame, +- CODEC_CAP_DR1, ++ .name = "pam", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PAM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .close = ff_pnm_end, ++ .decode = pnm_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB32, PIX_FMT_GRAY8, PIX_FMT_MONOWHITE, PIX_FMT_NONE}, +- .max_lowres = 5, + .long_name = NULL_IF_CONFIG_SMALL("PAM (Portable AnyMap) image"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnmenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnmenc.c 2012-05-14 14:08:54.114335554 +0200 +@@ -20,7 +20,6 @@ + */ + + #include "avcodec.h" +-#include "bytestream.h" + #include "pnm.h" + + +@@ -39,7 +38,7 @@ + } + + *p = *pict; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + + s->bytestream_start = +@@ -114,12 +113,12 @@ + + #if CONFIG_PGM_ENCODER + AVCodec ff_pgm_encoder = { +- "pgm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PGM, +- sizeof(PNMContext), +- ff_pnm_init, +- pnm_encode_frame, ++ .name = "pgm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PGM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .encode = pnm_encode_frame, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_GRAY8, PIX_FMT_GRAY16BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), + }; +@@ -127,12 +126,12 @@ + + #if CONFIG_PGMYUV_ENCODER + AVCodec ff_pgmyuv_encoder = { +- "pgmyuv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PGMYUV, +- sizeof(PNMContext), +- ff_pnm_init, +- pnm_encode_frame, ++ .name = "pgmyuv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PGMYUV, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .encode = pnm_encode_frame, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), + }; +@@ -140,12 +139,12 @@ + + #if CONFIG_PPM_ENCODER + AVCodec ff_ppm_encoder = { +- "ppm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PPM, +- sizeof(PNMContext), +- ff_pnm_init, +- pnm_encode_frame, ++ .name = "ppm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PPM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .encode = pnm_encode_frame, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB48BE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), + }; +@@ -153,12 +152,12 @@ + + #if CONFIG_PBM_ENCODER + AVCodec ff_pbm_encoder = { +- "pbm", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PBM, +- sizeof(PNMContext), +- ff_pnm_init, +- pnm_encode_frame, ++ .name = "pbm", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PBM, ++ .priv_data_size = sizeof(PNMContext), ++ .init = ff_pnm_init, ++ .encode = pnm_encode_frame, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_MONOWHITE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnm_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnm_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pnm_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pnm_parser.c 2012-05-14 14:08:54.112335514 +0200 +@@ -84,9 +84,9 @@ + } + + AVCodecParser ff_pnm_parser = { +- { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, CODEC_ID_PBM, CODEC_ID_PAM}, +- sizeof(ParseContext), +- NULL, +- pnm_parse, +- ff_parse_close, ++ .codec_ids = { CODEC_ID_PGM, CODEC_ID_PGMYUV, CODEC_ID_PPM, ++ CODEC_ID_PBM, CODEC_ID_PAM }, ++ .priv_data_size = sizeof(ParseContext), ++ .parser_parse = pnm_parse, ++ .parser_close = ff_parse_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/asm.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/asm.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/asm.S 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/asm.S 2012-05-14 14:08:54.115335574 +0200 +@@ -44,10 +44,13 @@ + L(\name): + .endm + +-.macro movrel rd, sym ++.macro movrel rd, sym, gp + ld \rd, \sym@got(r2) + .endm + ++.macro get_got rd ++.endm ++ + #else /* ARCH_PPC64 */ + + #define PTR .int +@@ -65,15 +68,25 @@ + \name: + .endm + +-.macro movrel rd, sym ++.macro movrel rd, sym, gp + #if CONFIG_PIC +- lwz \rd, \sym@got(r2) ++ lwz \rd, \sym@got(\gp) + #else + lis \rd, \sym@ha + la \rd, \sym@l(\rd) + #endif + .endm + ++.macro get_got rd ++#if CONFIG_PIC ++ bcl 20, 31, .Lgot\@ ++.Lgot\@: ++ mflr \rd ++ addis \rd, \rd, _GLOBAL_OFFSET_TABLE_ - .Lgot\@@ha ++ addi \rd, \rd, _GLOBAL_OFFSET_TABLE_ - .Lgot\@@l ++#endif ++.endm ++ + #endif /* ARCH_PPC64 */ + + #if HAVE_IBM_ASM +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.c 2012-05-14 14:08:54.117335614 +0200 +@@ -627,16 +627,6 @@ + // it's faster than -funroll-loops, but using + // -funroll-loops w/ this is bad - 74 cycles again. + // all this is on a 7450, tuning for the 7450 +-#if 0 +- for (i = 0; i < h; i++) { +- pixelsv1 = vec_ld(0, pixels); +- pixelsv2 = vec_ld(16, pixels); +- vec_st(vec_perm(pixelsv1, pixelsv2, perm), +- 0, block); +- pixels+=line_size; +- block +=line_size; +- } +-#else + for (i = 0; i < h; i += 4) { + pixelsv1 = vec_ld( 0, pixels); + pixelsv2 = vec_ld(15, pixels); +@@ -657,7 +647,6 @@ + pixels+=line_size_4; + block +=line_size_4; + } +-#endif + } + + /* next one assumes that ((line_size % 16) == 0) */ +@@ -1384,6 +1373,8 @@ + + void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx) + { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ + c->pix_abs[0][1] = sad16_x2_altivec; + c->pix_abs[0][2] = sad16_y2_altivec; + c->pix_abs[0][3] = sad16_xy2_altivec; +@@ -1396,9 +1387,10 @@ + c->sse[0]= sse16_altivec; + c->pix_sum = pix_sum_altivec; + c->diff_pixels = diff_pixels_altivec; ++ c->add_bytes= add_bytes_altivec; ++ if (!high_bit_depth) { + c->get_pixels = get_pixels_altivec; + c->clear_block = clear_block_altivec; +- c->add_bytes= add_bytes_altivec; + c->put_pixels_tab[0][0] = put_pixels16_altivec; + /* the two functions do the same thing, so use the same code */ + c->put_no_rnd_pixels_tab[0][0] = put_pixels16_altivec; +@@ -1409,6 +1401,7 @@ + c->put_no_rnd_pixels_tab[1][3] = put_no_rnd_pixels8_xy2_altivec; + c->put_pixels_tab[0][3] = put_pixels16_xy2_altivec; + c->put_no_rnd_pixels_tab[0][3] = put_no_rnd_pixels16_xy2_altivec; ++ } + + c->hadamard8_diff[0] = hadamard8_diff16_altivec; + c->hadamard8_diff[1] = hadamard8_diff8x8_altivec; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_altivec.h 2012-05-14 14:08:54.117335614 +0200 +@@ -43,7 +43,6 @@ + void dsputil_h264_init_ppc(DSPContext* c, AVCodecContext *avctx); + + void dsputil_init_altivec(DSPContext* c, AVCodecContext *avctx); +-void vc1dsp_init_altivec(DSPContext* c, AVCodecContext *avctx); + void float_init_altivec(DSPContext* c, AVCodecContext *avctx); + void int_init_altivec(DSPContext* c, AVCodecContext *avctx); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_ppc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_ppc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/dsputil_ppc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/dsputil_ppc.c 2012-05-14 14:08:54.118335634 +0200 +@@ -48,7 +48,6 @@ + { + register int misal = ((unsigned long)blocks & 0x00000010); + register int i = 0; +-#if 1 + if (misal) { + ((unsigned long*)blocks)[0] = 0L; + ((unsigned long*)blocks)[1] = 0L; +@@ -66,9 +65,6 @@ + ((unsigned long*)blocks)[191] = 0L; + i += 16; + } +-#else +- memset(blocks, 0, sizeof(DCTELEM)*6*64); +-#endif + } + + /* same as above, when dcbzl clear a whole 128B cache line +@@ -78,7 +74,6 @@ + { + register int misal = ((unsigned long)blocks & 0x0000007f); + register int i = 0; +-#if 1 + if (misal) { + // we could probably also optimize this case, + // but there's not much point as the machines +@@ -89,9 +84,6 @@ + for ( ; i < sizeof(DCTELEM)*6*64 ; i += 128) { + __asm__ volatile("dcbzl %0,%1" : : "b" (blocks), "r" (i) : "memory"); + } +-#else +- memset(blocks, 0, sizeof(DCTELEM)*6*64); +-#endif + } + #else + static void clear_blocks_dcbz128_ppc(DCTELEM *blocks) +@@ -153,8 +145,19 @@ + + void dsputil_init_ppc(DSPContext* c, AVCodecContext *avctx) + { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ int mm_flags = av_get_cpu_flags(); ++ ++ if (avctx->dsp_mask) { ++ if (avctx->dsp_mask & AV_CPU_FLAG_FORCE) ++ mm_flags |= (avctx->dsp_mask & 0xffff); ++ else ++ mm_flags &= ~(avctx->dsp_mask & 0xffff); ++ } ++ + // Common optimizations whether AltiVec is available or not + c->prefetch = prefetch_ppc; ++ if (!high_bit_depth) { + switch (check_dcbzl_effect()) { + case 32: + c->clear_blocks = clear_blocks_dcbz32_ppc; +@@ -165,26 +168,26 @@ + default: + break; + } ++ } + + #if HAVE_ALTIVEC + if(CONFIG_H264_DECODER) dsputil_h264_init_ppc(c, avctx); + +- if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { ++ if (mm_flags & AV_CPU_FLAG_ALTIVEC) { + dsputil_init_altivec(c, avctx); +- if(CONFIG_VC1_DECODER) +- vc1dsp_init_altivec(c, avctx); + float_init_altivec(c, avctx); + int_init_altivec(c, avctx); + c->gmc1 = gmc1_altivec; + + #if CONFIG_ENCODERS +- if (avctx->dct_algo == FF_DCT_AUTO || +- avctx->dct_algo == FF_DCT_ALTIVEC) { ++ if (avctx->bits_per_raw_sample <= 8 && ++ (avctx->dct_algo == FF_DCT_AUTO || ++ avctx->dct_algo == FF_DCT_ALTIVEC)) { + c->fdct = fdct_altivec; + } + #endif //CONFIG_ENCODERS + +- if (avctx->lowres==0) { ++ if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) { + if ((avctx->idct_algo == FF_IDCT_AUTO) || + (avctx->idct_algo == FF_IDCT_ALTIVEC)) { + c->idct_put = idct_put_altivec; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fdct_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fdct_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fdct_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fdct_altivec.c 2012-05-14 14:08:54.119335654 +0200 +@@ -265,7 +265,6 @@ + * conversion to vector float. The following code section takes advantage + * of this. + */ +-#if 1 + /* fdct rows {{{ */ + x0 = ((vector float)vec_add(vs16(b00), vs16(b70))); + x7 = ((vector float)vec_sub(vs16(b00), vs16(b70))); +@@ -389,29 +388,6 @@ + b31 = vec_add(b31, x2); + b11 = vec_add(b11, x3); + /* }}} */ +-#else +- /* convert to float {{{ */ +-#define CTF(n) \ +- vs32(b##n##1) = vec_unpackl(vs16(b##n##0)); \ +- vs32(b##n##0) = vec_unpackh(vs16(b##n##0)); \ +- b##n##1 = vec_ctf(vs32(b##n##1), 0); \ +- b##n##0 = vec_ctf(vs32(b##n##0), 0); \ +- +- CTF(0); +- CTF(1); +- CTF(2); +- CTF(3); +- CTF(4); +- CTF(5); +- CTF(6); +- CTF(7); +- +-#undef CTF +- /* }}} */ +- +- FDCTROW(b00, b10, b20, b30, b40, b50, b60, b70); +- FDCTROW(b01, b11, b21, b31, b41, b51, b61, b71); +-#endif + + + /* 8x8 matrix transpose (vector float[8][2]) {{{ */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fft_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fft_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fft_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fft_altivec.c 2012-05-14 14:08:54.119335654 +0200 +@@ -122,7 +122,7 @@ + int n = 1 << s->mdct_bits; + int n4 = n >> 2; + int n16 = n >> 4; +- vec_u32 sign = {1<<31,1<<31,1<<31,1<<31}; ++ vec_u32 sign = {1U<<31,1U<<31,1U<<31,1U<<31}; + vec_u32 *p0 = (vec_u32*)(output+n4); + vec_u32 *p1 = (vec_u32*)(output+n4*3); + +@@ -141,7 +141,9 @@ + { + #if HAVE_GNU_AS + s->fft_calc = ff_fft_calc_interleave_altivec; +- s->imdct_calc = ff_imdct_calc_altivec; +- s->imdct_half = ff_imdct_half_altivec; ++ if (s->mdct_bits >= 5) { ++ s->imdct_calc = ff_imdct_calc_altivec; ++ s->imdct_half = ff_imdct_half_altivec; ++ } + #endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fft_altivec_s.S xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fft_altivec_s.S +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fft_altivec_s.S 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fft_altivec_s.S 2012-05-14 14:08:54.120335674 +0200 +@@ -353,6 +353,7 @@ + mflr r0 + stp r0, 2*PS(r1) + stpu r1, -(160+16*PS)(r1) ++ get_got r11 + addi r6, r1, 16*PS + stvm r6, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29 + mfvrsave r0 +@@ -360,14 +361,14 @@ + li r6, 0xfffffffc + mtvrsave r6 + +- movrel r6, fft_data ++ movrel r6, fft_data, r11 + lvm r6, v14, v15, v16, v17, v18, v19, v20, v21 + lvm r6, v22, v23, v24, v25, v26, v27, v28, v29 + + li r9, 16 +- movrel r12, X(ff_cos_tabs) ++ movrel r12, X(ff_cos_tabs), r11 + +- movrel r6, fft_dispatch_tab\interleave\()_altivec ++ movrel r6, fft_dispatch_tab\interleave\()_altivec, r11 + lwz r3, 0(r3) + subi r3, r3, 2 + slwi r3, r3, 2+ARCH_PPC64 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fmtconvert_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fmtconvert_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/fmtconvert_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/fmtconvert_altivec.c 2012-05-14 14:08:54.121335694 +0200 +@@ -132,7 +132,7 @@ + } + } + +-void ff_fmt_convert_init_ppc(FmtConvertContext *c, AVCodecContext *avctx) ++void ff_fmt_convert_init_altivec(FmtConvertContext *c, AVCodecContext *avctx) + { + c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_altivec; + if(!(avctx->flags & CODEC_FLAG_BITEXACT)) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/h264_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/h264_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/h264_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/h264_altivec.c 2012-05-14 14:08:54.123335736 +0200 +@@ -32,7 +32,6 @@ + + #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC + #define PREFIX_h264_chroma_mc8_altivec put_h264_chroma_mc8_altivec +-#define PREFIX_no_rnd_vc1_chroma_mc8_altivec put_no_rnd_vc1_chroma_mc8_altivec + #define PREFIX_h264_chroma_mc8_num altivec_put_h264_chroma_mc8_num + #define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec + #define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num +@@ -43,7 +42,6 @@ + #include "h264_template_altivec.c" + #undef OP_U8_ALTIVEC + #undef PREFIX_h264_chroma_mc8_altivec +-#undef PREFIX_no_rnd_vc1_chroma_mc8_altivec + #undef PREFIX_h264_chroma_mc8_num + #undef PREFIX_h264_qpel16_h_lowpass_altivec + #undef PREFIX_h264_qpel16_h_lowpass_num +@@ -54,7 +52,6 @@ + + #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC + #define PREFIX_h264_chroma_mc8_altivec avg_h264_chroma_mc8_altivec +-#define PREFIX_no_rnd_vc1_chroma_mc8_altivec avg_no_rnd_vc1_chroma_mc8_altivec + #define PREFIX_h264_chroma_mc8_num altivec_avg_h264_chroma_mc8_num + #define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec + #define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num +@@ -65,7 +62,6 @@ + #include "h264_template_altivec.c" + #undef OP_U8_ALTIVEC + #undef PREFIX_h264_chroma_mc8_altivec +-#undef PREFIX_no_rnd_vc1_chroma_mc8_altivec + #undef PREFIX_h264_chroma_mc8_num + #undef PREFIX_h264_qpel16_h_lowpass_altivec + #undef PREFIX_h264_qpel16_h_lowpass_num +@@ -531,7 +527,7 @@ + h264_idct_dc_add_internal(dst, block, stride, 8); + } + +-static void ff_h264_idct_add16_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ ++static void ff_h264_idct_add16_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ + int i; + for(i=0; i<16; i++){ + int nnz = nnzc[ scan8[i] ]; +@@ -542,7 +538,7 @@ + } + } + +-static void ff_h264_idct_add16intra_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ ++static void ff_h264_idct_add16intra_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ + int i; + for(i=0; i<16; i++){ + if(nnzc[ scan8[i] ]) ff_h264_idct_add_altivec(dst + block_offset[i], block + i*16, stride); +@@ -550,7 +546,7 @@ + } + } + +-static void ff_h264_idct8_add4_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ ++static void ff_h264_idct8_add4_altivec(uint8_t *dst, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ + int i; + for(i=0; i<16; i+=4){ + int nnz = nnzc[ scan8[i] ]; +@@ -561,13 +557,15 @@ + } + } + +-static void ff_h264_idct_add8_altivec(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[6*8]){ +- int i; +- for(i=16; i<16+8; i++){ +- if(nnzc[ scan8[i] ]) +- ff_h264_idct_add_altivec(dest[(i&4)>>2] + block_offset[i], block + i*16, stride); +- else if(block[i*16]) +- h264_idct_dc_add_altivec(dest[(i&4)>>2] + block_offset[i], block + i*16, stride); ++static void ff_h264_idct_add8_altivec(uint8_t **dest, const int *block_offset, DCTELEM *block, int stride, const uint8_t nnzc[15*8]){ ++ int i, j; ++ for (j = 1; j < 3; j++) { ++ for(i = j * 16; i < j * 16 + 4; i++){ ++ if(nnzc[ scan8[i] ]) ++ ff_h264_idct_add_altivec(dest[j-1] + block_offset[i], block + i*16, stride); ++ else if(block[i*16]) ++ h264_idct_dc_add_altivec(dest[j-1] + block_offset[i], block + i*16, stride); ++ } + } + } + +@@ -618,8 +616,8 @@ + *(dst_int+15*int_dst_stride) = *(src_int + 15); + } + +-/** \brief performs a 6x16 transpose of data in src, and stores it to dst +- \todo FIXME: see if we can't spare some vec_lvsl() by them factorizing ++/** @brief performs a 6x16 transpose of data in src, and stores it to dst ++ @todo FIXME: see if we can't spare some vec_lvsl() by them factorizing + out of unaligned_load() */ + #define readAndTranspose16x6(src, src_stride, r8, r9, r10, r11, r12, r13) {\ + register vec_u8 r0 = unaligned_load(0, src); \ +@@ -845,7 +843,8 @@ + } + + static av_always_inline +-void weight_h264_WxH_altivec(uint8_t *block, int stride, int log2_denom, int weight, int offset, int w, int h) ++void weight_h264_W_altivec(uint8_t *block, int stride, int height, ++ int log2_denom, int weight, int offset, int w) + { + int y, aligned; + vec_u8 vblock; +@@ -866,7 +865,7 @@ + voffset = vec_splat(vtemp, 5); + aligned = !((unsigned long)block & 0xf); + +- for (y=0; ybits_per_raw_sample > 8; + + if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { ++ if (!high_bit_depth) { + c->put_h264_chroma_pixels_tab[0] = put_h264_chroma_mc8_altivec; + c->avg_h264_chroma_pixels_tab[0] = avg_h264_chroma_mc8_altivec; +- c->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_altivec; +- c->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_altivec; + + #define dspfunc(PFX, IDX, NUM) \ + c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \ +@@ -998,13 +996,16 @@ + dspfunc(avg_h264_qpel, 0, 16); + #undef dspfunc + } ++ } + } + +-void ff_h264dsp_init_ppc(H264DSPContext *c) ++void ff_h264dsp_init_ppc(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) + { + if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) { ++ if (bit_depth == 8) { + c->h264_idct_add = ff_h264_idct_add_altivec; +- c->h264_idct_add8 = ff_h264_idct_add8_altivec; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_altivec; + c->h264_idct_add16 = ff_h264_idct_add16_altivec; + c->h264_idct_add16intra = ff_h264_idct_add16intra_altivec; + c->h264_idct_dc_add= h264_idct_dc_add_altivec; +@@ -1014,15 +1015,10 @@ + c->h264_v_loop_filter_luma= h264_v_loop_filter_luma_altivec; + c->h264_h_loop_filter_luma= h264_h_loop_filter_luma_altivec; + +- c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels16x16_altivec; +- c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels16x8_altivec; +- c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels8x16_altivec; +- c->weight_h264_pixels_tab[3] = ff_weight_h264_pixels8x8_altivec; +- c->weight_h264_pixels_tab[4] = ff_weight_h264_pixels8x4_altivec; +- c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels16x16_altivec; +- c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels16x8_altivec; +- c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels8x16_altivec; +- c->biweight_h264_pixels_tab[3] = ff_biweight_h264_pixels8x8_altivec; +- c->biweight_h264_pixels_tab[4] = ff_biweight_h264_pixels8x4_altivec; ++ c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels16_altivec; ++ c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels8_altivec; ++ c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels16_altivec; ++ c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels8_altivec; ++ } + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/h264_template_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/h264_template_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/h264_template_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/h264_template_altivec.c 2012-05-14 14:08:54.124335756 +0200 +@@ -18,8 +18,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-//#define DEBUG_ALIGNMENT +-#ifdef DEBUG_ALIGNMENT ++#ifdef DEBUG + #define ASSERT_ALIGNED(ptr) assert(((unsigned long)ptr&0x0000000F)); + #else + #define ASSERT_ALIGNED(ptr) ; +@@ -75,6 +74,7 @@ + #define noop(a) a + #define add28(a) vec_add(v28ss, a) + ++#ifdef PREFIX_h264_chroma_mc8_altivec + static void PREFIX_h264_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, + int stride, int h, int x, int y) { + DECLARE_ALIGNED(16, signed int, ABCD)[4] = +@@ -201,8 +201,10 @@ + } + } + } ++#endif + + /* this code assume that stride % 16 == 0 */ ++#ifdef PREFIX_no_rnd_vc1_chroma_mc8_altivec + static void PREFIX_no_rnd_vc1_chroma_mc8_altivec(uint8_t * dst, uint8_t * src, int stride, int h, int x, int y) { + DECLARE_ALIGNED(16, signed int, ABCD)[4] = + {((8 - x) * (8 - y)), +@@ -284,12 +286,14 @@ + } + } + } ++#endif + + #undef noop + #undef add28 + #undef CHROMA_MC8_ALTIVEC_CORE + + /* this code assume stride % 16 == 0 */ ++#ifdef PREFIX_h264_qpel16_h_lowpass_altivec + static void PREFIX_h264_qpel16_h_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) { + register int i; + +@@ -427,8 +431,10 @@ + dst += dstStride; + } + } ++#endif + + /* this code assume stride % 16 == 0 */ ++#ifdef PREFIX_h264_qpel16_v_lowpass_altivec + static void PREFIX_h264_qpel16_v_lowpass_altivec(uint8_t * dst, uint8_t * src, int dstStride, int srcStride) { + register int i; + +@@ -533,8 +539,10 @@ + dst += dstStride; + } + } ++#endif + + /* this code assume stride % 16 == 0 *and* tmp is properly aligned */ ++#ifdef PREFIX_h264_qpel16_hv_lowpass_altivec + static void PREFIX_h264_qpel16_hv_lowpass_altivec(uint8_t * dst, int16_t * tmp, uint8_t * src, int dstStride, int tmpStride, int srcStride) { + register int i; + LOAD_ZERO; +@@ -765,3 +773,4 @@ + dst += dstStride; + } + } ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/Makefile 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/Makefile 2012-05-14 14:08:54.114335554 +0200 +@@ -7,11 +7,7 @@ + ALTIVEC-OBJS-$(CONFIG_VP6_DECODER) += ppc/vp3dsp_altivec.o + ALTIVEC-OBJS-$(CONFIG_VP8_DECODER) += ppc/vp8dsp_altivec.o + +-ALTIVEC-OBJS-$(CONFIG_MP1FLOAT_DECODER) += ppc/mpegaudiodec_altivec.o +-ALTIVEC-OBJS-$(CONFIG_MP2FLOAT_DECODER) += ppc/mpegaudiodec_altivec.o +-ALTIVEC-OBJS-$(CONFIG_MP3FLOAT_DECODER) += ppc/mpegaudiodec_altivec.o +-ALTIVEC-OBJS-$(CONFIG_MP3ON4FLOAT_DECODER) += ppc/mpegaudiodec_altivec.o +-ALTIVEC-OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += ppc/mpegaudiodec_altivec.o ++ALTIVEC-OBJS-$(CONFIG_MPEGAUDIODSP) += ppc/mpegaudiodec_altivec.o + + FFT-OBJS-$(HAVE_GNU_AS) += ppc/fft_altivec_s.o \ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/mpegaudiodec_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/mpegaudiodec_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/mpegaudiodec_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/mpegaudiodec_altivec.c 2012-05-14 14:08:54.124335756 +0200 +@@ -21,9 +21,8 @@ + + #include "dsputil_altivec.h" + #include "util_altivec.h" +- +-#define CONFIG_FLOAT 1 +-#include "libavcodec/mpegaudio.h" ++#include "libavcodec/dsputil.h" ++#include "libavcodec/mpegaudiodsp.h" + + #define MACS(rt, ra, rb) rt+=(ra)*(rb) + #define MLSS(rt, ra, rb) rt-=(ra)*(rb) +@@ -124,7 +123,7 @@ + *out = sum; + } + +-void ff_mpegaudiodec_init_altivec(MPADecodeContext *s) ++void ff_mpadsp_init_altivec(MPADSPContext *s) + { +- s->apply_window_mp3 = apply_window_mp3; ++ s->apply_window_float = apply_window_mp3; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/mpegvideo_altivec.c 2012-05-14 14:08:54.126335796 +0200 +@@ -267,11 +267,16 @@ + baseVector = vec_cts(vec_splat(row0, 0), 0); + vec_ste(baseVector, 0, &oldBaseValue); + +- qmat = (vector signed int*)s->q_intra_matrix[qscale]; +- biasAddr = &(s->intra_quant_bias); ++ if(n<4){ ++ qmat = (vector signed int*)s->q_intra_matrix[qscale]; ++ biasAddr = &s->intra_quant_bias; ++ }else{ ++ qmat = (vector signed int*)s->q_chroma_intra_matrix[qscale]; ++ biasAddr = &s->intra_quant_bias; ++ } + } else { + qmat = (vector signed int*)s->q_inter_matrix[qscale]; +- biasAddr = &(s->inter_quant_bias); ++ biasAddr = &s->inter_quant_bias; + } + + // Load the bias vector (We add 0.5 to the bias so that we're +@@ -361,8 +366,8 @@ + vector signed int max_q_int, min_q_int; + vector signed short max_q, min_q; + +- LOAD4(max_q_int, &(s->max_qcoeff)); +- LOAD4(min_q_int, &(s->min_qcoeff)); ++ LOAD4(max_q_int, &s->max_qcoeff); ++ LOAD4(min_q_int, &s->min_qcoeff); + + max_q = vec_pack(max_q_int, max_q_int); + min_q = vec_pack(min_q_int, min_q_int); +@@ -515,21 +520,6 @@ + qaddv = vec_splat((vec_s16)vec_lde(0, &qadd8), 0); + nqaddv = vec_sub(vczero, qaddv); + +-#if 0 // block *is* 16 bytes-aligned, it seems. +- // first make sure block[j] is 16 bytes-aligned +- for(j = 0; (j <= nCoeffs) && ((((unsigned long)block) + (j << 1)) & 0x0000000F) ; j++) { +- level = block[j]; +- if (level) { +- if (level < 0) { +- level = level * qmul - qadd; +- } else { +- level = level * qmul + qadd; +- } +- block[j] = level; +- } +- } +-#endif +- + // vectorize all the 16 bytes-aligned blocks + // of 8 elements + for(; (j + 7) <= nCoeffs ; j+=8) { +@@ -573,15 +563,6 @@ + { + if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) return; + +- if (s->avctx->lowres==0) { +- if ((s->avctx->idct_algo == FF_IDCT_AUTO) || +- (s->avctx->idct_algo == FF_IDCT_ALTIVEC)) { +- s->dsp.idct_put = idct_put_altivec; +- s->dsp.idct_add = idct_add_altivec; +- s->dsp.idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; +- } +- } +- + // Test to make sure that the dct required alignments are met. + if ((((long)(s->q_intra_matrix) & 0x0f) != 0) || + (((long)(s->q_inter_matrix) & 0x0f) != 0)) { +@@ -599,9 +580,6 @@ + + if ((s->avctx->dct_algo == FF_DCT_AUTO) || + (s->avctx->dct_algo == FF_DCT_ALTIVEC)) { +-#if 0 /* seems to cause trouble under some circumstances */ +- s->dct_quantize = dct_quantize_altivec; +-#endif + s->dct_unquantize_h263_intra = dct_unquantize_h263_altivec; + s->dct_unquantize_h263_inter = dct_unquantize_h263_altivec; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/util_altivec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/util_altivec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/util_altivec.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/util_altivec.h 2012-05-14 14:08:54.126335796 +0200 +@@ -94,7 +94,7 @@ + } while (0) + + +-/** \brief loads unaligned vector \a *src with offset \a offset ++/** @brief loads unaligned vector @a *src with offset @a offset + and returns it */ + static inline vector unsigned char unaligned_load(int offset, uint8_t *src) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/vc1dsp_altivec.c 2012-05-14 14:08:54.127335816 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "libavcodec/dsputil.h" ++#include "libavcodec/vc1dsp.h" + + #include "util_altivec.h" + #include "dsputil_altivec.h" +@@ -144,7 +145,6 @@ + const vector signed int vec_1s = vec_splat_s32(1); + const vector unsigned int vec_1 = vec_splat_u32(1); + +- + src0 = vec_ld( 0, block); + src1 = vec_ld( 16, block); + src2 = vec_ld( 32, block); +@@ -154,7 +154,6 @@ + src6 = vec_ld( 96, block); + src7 = vec_ld(112, block); + +- TRANSPOSE8(src0, src1, src2, src3, src4, src5, src6, src7); + s0 = vec_unpackl(src0); + s1 = vec_unpackl(src1); + s2 = vec_unpackl(src2); +@@ -322,8 +321,28 @@ + ADD (dest, src3, perm1) + } + ++#define PUT_OP_U8_ALTIVEC(d, s, dst) d = s ++#define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s) ++ ++#define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC ++#define PREFIX_no_rnd_vc1_chroma_mc8_altivec put_no_rnd_vc1_chroma_mc8_altivec ++#include "h264_template_altivec.c" ++#undef OP_U8_ALTIVEC ++#undef PREFIX_no_rnd_vc1_chroma_mc8_altivec ++ ++#define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC ++#define PREFIX_no_rnd_vc1_chroma_mc8_altivec avg_no_rnd_vc1_chroma_mc8_altivec ++#include "h264_template_altivec.c" ++#undef OP_U8_ALTIVEC ++#undef PREFIX_no_rnd_vc1_chroma_mc8_altivec ++ ++void ff_vc1dsp_init_altivec(VC1DSPContext* dsp) ++{ ++ if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) ++ return; + +-void vc1dsp_init_altivec(DSPContext* dsp, AVCodecContext *avctx) { + dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_altivec; + dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_altivec; ++ dsp->put_no_rnd_vc1_chroma_pixels_tab[0] = put_no_rnd_vc1_chroma_mc8_altivec; ++ dsp->avg_no_rnd_vc1_chroma_pixels_tab[0] = avg_no_rnd_vc1_chroma_mc8_altivec; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/vp8dsp_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/vp8dsp_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ppc/vp8dsp_altivec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ppc/vp8dsp_altivec.c 2012-05-14 14:08:54.128335836 +0200 +@@ -56,8 +56,8 @@ + vec_s8 filter_outerl = vec_sld(filter_outerh, filter_outerh, 2) + + #define FILTER_H(dstv, off) \ +- a = vec_ld((off)-2, src); \ +- b = vec_ld((off)-2+15, src); \ ++ a = vec_ld((off)-is6tap-1, src); \ ++ b = vec_ld((off)-is6tap-1+15, src); \ + \ + pixh = vec_perm(a, b, permh##off); \ + pixl = vec_perm(a, b, perml##off); \ +@@ -86,13 +86,15 @@ + vec_s16 f16h, f16l; + vec_s32 filth, filtl; + +- vec_u8 perm_inner = { 1,2,3,4, 2,3,4,5, 3,4,5,6, 4,5,6,7 }; ++ vec_u8 perm_inner6 = { 1,2,3,4, 2,3,4,5, 3,4,5,6, 4,5,6,7 }; ++ vec_u8 perm_inner4 = { 0,1,2,3, 1,2,3,4, 2,3,4,5, 3,4,5,6 }; ++ vec_u8 perm_inner = is6tap ? perm_inner6 : perm_inner4; + vec_u8 perm_outer = { 4,9, 0,5, 5,10, 1,6, 6,11, 2,7, 7,12, 3,8 }; + vec_s32 c64 = vec_sl(vec_splat_s32(1), vec_splat_u32(6)); + vec_u16 c7 = vec_splat_u16(7); + +- align_vec0 = vec_lvsl( -2, src); +- align_vec8 = vec_lvsl(8-2, src); ++ align_vec0 = vec_lvsl( -is6tap-1, src); ++ align_vec8 = vec_lvsl(8-is6tap-1, src); + + permh0 = vec_perm(align_vec0, align_vec0, perm_inner); + permh8 = vec_perm(align_vec8, align_vec8, perm_inner); +@@ -239,8 +241,13 @@ + static void put_vp8_epel ## WIDTH ## _h ## HTAPS ## v ## VTAPS ## _altivec(uint8_t *dst, int stride, uint8_t *src, int s, int h, int mx, int my) \ + { \ + DECLARE_ALIGNED(16, uint8_t, tmp)[(2*WIDTH+5)*16]; \ +- put_vp8_epel ## WIDTH ## _h ## HTAPS ## _altivec(tmp, 16, src-2*stride, stride, h+5, mx, my); \ +- put_vp8_epel ## WIDTH ## _v ## VTAPS ## _altivec(dst, stride, tmp+2*16, 16, h, mx, my); \ ++ if (VTAPS == 6) { \ ++ put_vp8_epel ## WIDTH ## _h ## HTAPS ## _altivec(tmp, 16, src-2*stride, stride, h+5, mx, my); \ ++ put_vp8_epel ## WIDTH ## _v ## VTAPS ## _altivec(dst, stride, tmp+2*16, 16, h, mx, my); \ ++ } else { \ ++ put_vp8_epel ## WIDTH ## _h ## HTAPS ## _altivec(tmp, 16, src-stride, stride, h+4, mx, my); \ ++ put_vp8_epel ## WIDTH ## _v ## VTAPS ## _altivec(dst, stride, tmp+16, 16, h, mx, my); \ ++ } \ + } + + EPEL_FUNCS(16,6) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec2.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec2.c 2012-05-14 14:08:54.130335876 +0200 +@@ -0,0 +1,594 @@ ++/* ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * Copyright (c) 2010-2011 Elvis Presley ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'acpo' (Proxy), 'ap4h' (4444) ++ */ ++ ++//#define DEBUG ++ ++#define LONG_BITSTREAM_READER ++ ++#include "avcodec.h" ++#include "get_bits.h" ++#include "simple_idct.h" ++#include "proresdec.h" ++ ++static void permute(uint8_t *dst, const uint8_t *src, const uint8_t permutation[64]) ++{ ++ int i; ++ for (i = 0; i < 64; i++) ++ dst[i] = permutation[src[i]]; ++} ++ ++static const uint8_t progressive_scan[64] = { ++ 0, 1, 8, 9, 2, 3, 10, 11, ++ 16, 17, 24, 25, 18, 19, 26, 27, ++ 4, 5, 12, 20, 13, 6, 7, 14, ++ 21, 28, 29, 22, 15, 23, 30, 31, ++ 32, 33, 40, 48, 41, 34, 35, 42, ++ 49, 56, 57, 50, 43, 36, 37, 44, ++ 51, 58, 59, 52, 45, 38, 39, 46, ++ 53, 60, 61, 54, 47, 55, 62, 63 ++}; ++ ++static const uint8_t interlaced_scan[64] = { ++ 0, 8, 1, 9, 16, 24, 17, 25, ++ 2, 10, 3, 11, 18, 26, 19, 27, ++ 32, 40, 33, 34, 41, 48, 56, 49, ++ 42, 35, 43, 50, 57, 58, 51, 59, ++ 4, 12, 5, 6, 13, 20, 28, 21, ++ 14, 7, 15, 22, 29, 36, 44, 37, ++ 30, 23, 31, 38, 45, 52, 60, 53, ++ 46, 39, 47, 54, 61, 62, 55, 63, ++}; ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ uint8_t idct_permutation[64]; ++ ++ avctx->bits_per_raw_sample = 10; ++ ++ dsputil_init(&ctx->dsp, avctx); ++ ff_proresdsp_init(&ctx->prodsp, avctx); ++ ++ avctx->coded_frame = &ctx->frame; ++ ctx->frame.type = AV_PICTURE_TYPE_I; ++ ctx->frame.key_frame = 1; ++ ++ ff_init_scantable_permutation(idct_permutation, ++ ctx->prodsp.idct_permutation_type); ++ ++ permute(ctx->progressive_scan, progressive_scan, idct_permutation); ++ permute(ctx->interlaced_scan, interlaced_scan, idct_permutation); ++ ++ return 0; ++} ++ ++static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, ++ const int data_size, AVCodecContext *avctx) ++{ ++ int hdr_size, width, height, flags; ++ int version; ++ const uint8_t *ptr; ++ ++ hdr_size = AV_RB16(buf); ++ av_dlog(avctx, "header size %d\n", hdr_size); ++ if (hdr_size > data_size) { ++ av_log(avctx, AV_LOG_ERROR, "error, wrong header size\n"); ++ return -1; ++ } ++ ++ version = AV_RB16(buf + 2); ++ av_dlog(avctx, "%.4s version %d\n", buf+4, version); ++ if (version > 1) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported version: %d\n", version); ++ return -1; ++ } ++ ++ width = AV_RB16(buf + 8); ++ height = AV_RB16(buf + 10); ++ if (width != avctx->width || height != avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, "picture resolution change: %dx%d -> %dx%d\n", ++ avctx->width, avctx->height, width, height); ++ return -1; ++ } ++ ++ ctx->frame_type = (buf[12] >> 2) & 3; ++ ++ av_dlog(avctx, "frame type %d\n", ctx->frame_type); ++ ++ if (ctx->frame_type == 0) { ++ ctx->scan = ctx->progressive_scan; // permuted ++ } else { ++ ctx->scan = ctx->interlaced_scan; // permuted ++ ctx->frame.interlaced_frame = 1; ++ ctx->frame.top_field_first = ctx->frame_type == 1; ++ } ++ ++ avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? PIX_FMT_YUV444P10 : PIX_FMT_YUV422P10; ++ ++ ptr = buf + 20; ++ flags = buf[19]; ++ av_dlog(avctx, "flags %x\n", flags); ++ ++ if (flags & 2) { ++ permute(ctx->qmat_luma, ctx->prodsp.idct_permutation, ptr); ++ ptr += 64; ++ } else { ++ memset(ctx->qmat_luma, 4, 64); ++ } ++ ++ if (flags & 1) { ++ permute(ctx->qmat_chroma, ctx->prodsp.idct_permutation, ptr); ++ } else { ++ memset(ctx->qmat_chroma, 4, 64); ++ } ++ ++ return hdr_size; ++} ++ ++static int decode_picture_header(AVCodecContext *avctx, const uint8_t *buf, const int buf_size) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ int i, hdr_size, slice_count; ++ unsigned pic_data_size; ++ int log2_slice_mb_width, log2_slice_mb_height; ++ int slice_mb_count, mb_x, mb_y; ++ const uint8_t *data_ptr, *index_ptr; ++ ++ hdr_size = buf[0] >> 3; ++ if (hdr_size < 8 || hdr_size > buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "error, wrong picture header size\n"); ++ return -1; ++ } ++ ++ pic_data_size = AV_RB32(buf + 1); ++ if (pic_data_size > buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "error, wrong picture data size\n"); ++ return -1; ++ } ++ ++ log2_slice_mb_width = buf[7] >> 4; ++ log2_slice_mb_height = buf[7] & 0xF; ++ if (log2_slice_mb_width > 3 || log2_slice_mb_height) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported slice resolution: %dx%d\n", ++ 1 << log2_slice_mb_width, 1 << log2_slice_mb_height); ++ return -1; ++ } ++ ++ ctx->mb_width = (avctx->width + 15) >> 4; ++ if (ctx->frame_type) ++ ctx->mb_height = (avctx->height + 31) >> 5; ++ else ++ ctx->mb_height = (avctx->height + 15) >> 4; ++ ++ slice_count = AV_RB16(buf + 5); ++ ++ if (ctx->slice_count != slice_count || !ctx->slices) { ++ av_freep(&ctx->slices); ++ ctx->slices = av_mallocz(slice_count * sizeof(*ctx->slices)); ++ if (!ctx->slices) ++ return AVERROR(ENOMEM); ++ ctx->slice_count = slice_count; ++ } ++ ++ if (!slice_count) ++ return AVERROR(EINVAL); ++ ++ if (hdr_size + slice_count*2 > buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "error, wrong slice count\n"); ++ return -1; ++ } ++ ++ // parse slice information ++ index_ptr = buf + hdr_size; ++ data_ptr = index_ptr + slice_count*2; ++ ++ slice_mb_count = 1 << log2_slice_mb_width; ++ mb_x = 0; ++ mb_y = 0; ++ ++ for (i = 0; i < slice_count; i++) { ++ SliceContext *slice = &ctx->slices[i]; ++ ++ slice->data = data_ptr; ++ data_ptr += AV_RB16(index_ptr + i*2); ++ ++ while (ctx->mb_width - mb_x < slice_mb_count) ++ slice_mb_count >>= 1; ++ ++ slice->mb_x = mb_x; ++ slice->mb_y = mb_y; ++ slice->mb_count = slice_mb_count; ++ slice->data_size = data_ptr - slice->data; ++ ++ if (slice->data_size < 6) { ++ av_log(avctx, AV_LOG_ERROR, "error, wrong slice data size\n"); ++ return -1; ++ } ++ ++ mb_x += slice_mb_count; ++ if (mb_x == ctx->mb_width) { ++ slice_mb_count = 1 << log2_slice_mb_width; ++ mb_x = 0; ++ mb_y++; ++ } ++ if (data_ptr > buf + buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "error, slice out of bounds\n"); ++ return -1; ++ } ++ } ++ ++ if (mb_x || mb_y != ctx->mb_height) { ++ av_log(avctx, AV_LOG_ERROR, "error wrong mb count y %d h %d\n", ++ mb_y, ctx->mb_height); ++ return -1; ++ } ++ ++ return pic_data_size; ++} ++ ++#define DECODE_CODEWORD(val, codebook) \ ++ do { \ ++ unsigned int rice_order, exp_order, switch_bits; \ ++ unsigned int q, buf, bits; \ ++ \ ++ UPDATE_CACHE(re, gb); \ ++ buf = GET_CACHE(re, gb); \ ++ \ ++ /* number of bits to switch between rice and exp golomb */ \ ++ switch_bits = codebook & 3; \ ++ rice_order = codebook >> 5; \ ++ exp_order = (codebook >> 2) & 7; \ ++ \ ++ q = 31 - av_log2(buf); \ ++ \ ++ if (q > switch_bits) { /* exp golomb */ \ ++ bits = exp_order - switch_bits + (q<<1); \ ++ val = SHOW_UBITS(re, gb, bits) - (1 << exp_order) + \ ++ ((switch_bits + 1) << rice_order); \ ++ SKIP_BITS(re, gb, bits); \ ++ } else if (rice_order) { \ ++ SKIP_BITS(re, gb, q+1); \ ++ val = (q << rice_order) + SHOW_UBITS(re, gb, rice_order); \ ++ SKIP_BITS(re, gb, rice_order); \ ++ } else { \ ++ val = q; \ ++ SKIP_BITS(re, gb, q+1); \ ++ } \ ++ } while (0) ++ ++#define TOSIGNED(x) (((x) >> 1) ^ (-((x) & 1))) ++ ++#define FIRST_DC_CB 0xB8 ++ ++static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}; ++ ++static av_always_inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, ++ int blocks_per_slice) ++{ ++ DCTELEM prev_dc; ++ int code, i, sign; ++ ++ OPEN_READER(re, gb); ++ ++ DECODE_CODEWORD(code, FIRST_DC_CB); ++ prev_dc = TOSIGNED(code); ++ out[0] = prev_dc; ++ ++ out += 64; // dc coeff for the next block ++ ++ code = 5; ++ sign = 0; ++ for (i = 1; i < blocks_per_slice; i++, out += 64) { ++ DECODE_CODEWORD(code, dc_codebook[FFMIN(code, 6U)]); ++ if(code) sign ^= -(code & 1); ++ else sign = 0; ++ prev_dc += (((code + 1) >> 1) ^ sign) - sign; ++ out[0] = prev_dc; ++ } ++ CLOSE_READER(re, gb); ++} ++ ++// adaptive codebook switching lut according to previous run/level values ++static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C }; ++static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, 0x28, 0x28, 0x28, 0x4C }; ++ ++static av_always_inline void decode_ac_coeffs(AVCodecContext *avctx, GetBitContext *gb, ++ DCTELEM *out, int blocks_per_slice) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ int block_mask, sign; ++ unsigned pos, run, level; ++ int max_coeffs, i, bits_left; ++ int log2_block_count = av_log2(blocks_per_slice); ++ ++ OPEN_READER(re, gb); ++ UPDATE_CACHE(re, gb); \ ++ run = 4; ++ level = 2; ++ ++ max_coeffs = 64 << log2_block_count; ++ block_mask = blocks_per_slice - 1; ++ ++ for (pos = block_mask;;) { ++ bits_left = gb->size_in_bits - re_index; ++ if (!bits_left || (bits_left < 32 && !SHOW_UBITS(re, gb, bits_left))) ++ break; ++ ++ DECODE_CODEWORD(run, run_to_cb[FFMIN(run, 15)]); ++ pos += run + 1; ++ if (pos >= max_coeffs) { ++ av_log(avctx, AV_LOG_ERROR, "ac tex damaged %d, %d\n", pos, max_coeffs); ++ return; ++ } ++ ++ DECODE_CODEWORD(level, lev_to_cb[FFMIN(level, 9)]); ++ level += 1; ++ ++ i = pos >> log2_block_count; ++ ++ sign = SHOW_SBITS(re, gb, 1); ++ SKIP_BITS(re, gb, 1); ++ out[((pos & block_mask) << 6) + ctx->scan[i]] = ((level ^ sign) - sign); ++ } ++ ++ CLOSE_READER(re, gb); ++} ++ ++static void decode_slice_luma(AVCodecContext *avctx, SliceContext *slice, ++ uint8_t *dst, int dst_stride, ++ const uint8_t *buf, unsigned buf_size, ++ const int16_t *qmat) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]); ++ DCTELEM *block; ++ GetBitContext gb; ++ int i, blocks_per_slice = slice->mb_count<<2; ++ ++ for (i = 0; i < blocks_per_slice; i++) ++ ctx->dsp.clear_block(blocks+(i<<6)); ++ ++ init_get_bits(&gb, buf, buf_size << 3); ++ ++ decode_dc_coeffs(&gb, blocks, blocks_per_slice); ++ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice); ++ ++ block = blocks; ++ for (i = 0; i < slice->mb_count; i++) { ++ ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat); ++ ctx->prodsp.idct_put(dst+16, dst_stride, block+(1<<6), qmat); ++ ctx->prodsp.idct_put(dst+8*dst_stride, dst_stride, block+(2<<6), qmat); ++ ctx->prodsp.idct_put(dst+8*dst_stride+16, dst_stride, block+(3<<6), qmat); ++ block += 4*64; ++ dst += 32; ++ } ++} ++ ++static void decode_slice_chroma(AVCodecContext *avctx, SliceContext *slice, ++ uint8_t *dst, int dst_stride, ++ const uint8_t *buf, unsigned buf_size, ++ const int16_t *qmat, int log2_blocks_per_mb) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ LOCAL_ALIGNED_16(DCTELEM, blocks, [8*4*64]); ++ DCTELEM *block; ++ GetBitContext gb; ++ int i, j, blocks_per_slice = slice->mb_count << log2_blocks_per_mb; ++ ++ for (i = 0; i < blocks_per_slice; i++) ++ ctx->dsp.clear_block(blocks+(i<<6)); ++ ++ init_get_bits(&gb, buf, buf_size << 3); ++ ++ decode_dc_coeffs(&gb, blocks, blocks_per_slice); ++ decode_ac_coeffs(avctx, &gb, blocks, blocks_per_slice); ++ ++ block = blocks; ++ for (i = 0; i < slice->mb_count; i++) { ++ for (j = 0; j < log2_blocks_per_mb; j++) { ++ ctx->prodsp.idct_put(dst, dst_stride, block+(0<<6), qmat); ++ ctx->prodsp.idct_put(dst+8*dst_stride, dst_stride, block+(1<<6), qmat); ++ block += 2*64; ++ dst += 16; ++ } ++ } ++} ++ ++static int decode_slice_thread(AVCodecContext *avctx, void *arg, int jobnr, int threadnr) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ SliceContext *slice = &ctx->slices[jobnr]; ++ const uint8_t *buf = slice->data; ++ AVFrame *pic = avctx->coded_frame; ++ int i, hdr_size, qscale, log2_chroma_blocks_per_mb; ++ int luma_stride, chroma_stride; ++ int y_data_size, u_data_size, v_data_size; ++ uint8_t *dest_y, *dest_u, *dest_v; ++ int16_t qmat_luma_scaled[64]; ++ int16_t qmat_chroma_scaled[64]; ++ int mb_x_shift; ++ ++ //av_log(avctx, AV_LOG_INFO, "slice %d mb width %d mb x %d y %d\n", ++ // jobnr, slice->mb_count, slice->mb_x, slice->mb_y); ++ ++ // slice header ++ hdr_size = buf[0] >> 3; ++ qscale = av_clip(buf[1], 1, 224); ++ qscale = qscale > 128 ? qscale - 96 << 2: qscale; ++ y_data_size = AV_RB16(buf + 2); ++ u_data_size = AV_RB16(buf + 4); ++ v_data_size = slice->data_size - y_data_size - u_data_size - hdr_size; ++ if (hdr_size > 7) v_data_size = AV_RB16(buf + 6); ++ ++ if (y_data_size < 0 || u_data_size < 0 || v_data_size < 0 ++ || hdr_size+y_data_size+u_data_size+v_data_size > slice->data_size){ ++ av_log(avctx, AV_LOG_ERROR, "invalid plane data size\n"); ++ return -1; ++ } ++ ++ buf += hdr_size; ++ ++ for (i = 0; i < 64; i++) { ++ qmat_luma_scaled [i] = ctx->qmat_luma [i] * qscale; ++ qmat_chroma_scaled[i] = ctx->qmat_chroma[i] * qscale; ++ } ++ ++ if (ctx->frame_type == 0) { ++ luma_stride = pic->linesize[0]; ++ chroma_stride = pic->linesize[1]; ++ } else { ++ luma_stride = pic->linesize[0] << 1; ++ chroma_stride = pic->linesize[1] << 1; ++ } ++ ++ if (avctx->pix_fmt == PIX_FMT_YUV444P10) { ++ mb_x_shift = 5; ++ log2_chroma_blocks_per_mb = 2; ++ } else { ++ mb_x_shift = 4; ++ log2_chroma_blocks_per_mb = 1; ++ } ++ ++ dest_y = pic->data[0] + (slice->mb_y << 4) * luma_stride + (slice->mb_x << 5); ++ dest_u = pic->data[1] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift); ++ dest_v = pic->data[2] + (slice->mb_y << 4) * chroma_stride + (slice->mb_x << mb_x_shift); ++ ++ if (ctx->frame_type && ctx->first_field ^ ctx->frame.top_field_first) { ++ dest_y += pic->linesize[0]; ++ dest_u += pic->linesize[1]; ++ dest_v += pic->linesize[2]; ++ } ++ ++ decode_slice_luma(avctx, slice, dest_y, luma_stride, ++ buf, y_data_size, qmat_luma_scaled); ++ ++ if (!(avctx->flags & CODEC_FLAG_GRAY)) { ++ decode_slice_chroma(avctx, slice, dest_u, chroma_stride, ++ buf + y_data_size, u_data_size, ++ qmat_chroma_scaled, log2_chroma_blocks_per_mb); ++ decode_slice_chroma(avctx, slice, dest_v, chroma_stride, ++ buf + y_data_size + u_data_size, v_data_size, ++ qmat_chroma_scaled, log2_chroma_blocks_per_mb); ++ } ++ ++ return 0; ++} ++ ++static int decode_picture(AVCodecContext *avctx) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ int i, threads_ret[ctx->slice_count]; ++ ++ avctx->execute2(avctx, decode_slice_thread, NULL, threads_ret, ctx->slice_count); ++ ++ for (i = 0; i < ctx->slice_count; i++) ++ if (threads_ret[i] < 0) ++ return threads_ret[i]; ++ ++ return 0; ++} ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ AVFrame *frame = avctx->coded_frame; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int frame_hdr_size, pic_size; ++ ++ if (buf_size < 28 || AV_RL32(buf + 4) != AV_RL32("icpf")) { ++ av_log(avctx, AV_LOG_ERROR, "invalid frame header\n"); ++ return -1; ++ } ++ ++ ctx->first_field = 1; ++ ++ buf += 8; ++ buf_size -= 8; ++ ++ frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx); ++ if (frame_hdr_size < 0) ++ return -1; ++ ++ buf += frame_hdr_size; ++ buf_size -= frame_hdr_size; ++ ++ if (frame->data[0]) ++ avctx->release_buffer(avctx, frame); ++ ++ if (avctx->get_buffer(avctx, frame) < 0) ++ return -1; ++ ++ decode_picture: ++ pic_size = decode_picture_header(avctx, buf, buf_size); ++ if (pic_size < 0) { ++ av_log(avctx, AV_LOG_ERROR, "error decoding picture header\n"); ++ return -1; ++ } ++ ++ if (decode_picture(avctx)) { ++ av_log(avctx, AV_LOG_ERROR, "error decoding picture\n"); ++ return -1; ++ } ++ ++ buf += pic_size; ++ buf_size -= pic_size; ++ ++ if (ctx->frame_type && buf_size > 0 && ctx->first_field) { ++ ctx->first_field = 0; ++ goto decode_picture; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = *frame; ++ ++ return avpkt->size; ++} ++ ++static av_cold int decode_close(AVCodecContext *avctx) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ ++ AVFrame *frame = avctx->coded_frame; ++ if (frame->data[0]) ++ avctx->release_buffer(avctx, frame); ++ av_freep(&ctx->slices); ++ ++ return 0; ++} ++ ++AVCodec ff_prores_decoder = { ++ .name = "prores", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PRORES, ++ .priv_data_size = sizeof(ProresContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .long_name = NULL_IF_CONFIG_SMALL("ProRes"), ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec.h 2012-05-14 14:08:54.128335836 +0200 +@@ -0,0 +1,53 @@ ++/* ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * Copyright (c) 2010-2011 Elvis Presley ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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; ++ * version 2 of the License. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_PRORESDEC_H ++#define AVCODEC_PRORESDEC_H ++ ++#include "dsputil.h" ++#include "proresdsp.h" ++ ++typedef struct { ++ const uint8_t *data; ++ unsigned mb_x; ++ unsigned mb_y; ++ unsigned mb_count; ++ unsigned data_size; ++} SliceContext; ++ ++typedef struct { ++ DSPContext dsp; ++ ProresDSPContext prodsp; ++ AVFrame frame; ++ int frame_type; ///< 0 = progressive, 1 = tff, 2 = bff ++ uint8_t qmat_luma[64]; ++ uint8_t qmat_chroma[64]; ++ SliceContext *slices; ++ int slice_count; ///< number of slices in the current picture ++ unsigned mb_width; ///< width of the current picture in mb ++ unsigned mb_height; ///< height of the current picture in mb ++ uint8_t progressive_scan[64]; ++ uint8_t interlaced_scan[64]; ++ const uint8_t *scan; ++ int first_field; ++} ProresContext; ++ ++#endif /* AVCODEC_PRORESDEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec_lgpl.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec_lgpl.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdec_lgpl.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdec_lgpl.c 2012-05-14 14:08:54.132335916 +0200 +@@ -0,0 +1,706 @@ ++/* ++ * Apple ProRes compatible decoder ++ * ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * This is a decoder for Apple ProRes 422 SD/HQ/LT/Proxy and ProRes 4444. ++ * It is used for storing and editing high definition video data in Apple's Final Cut Pro. ++ * ++ * @see http://wiki.multimedia.cx/index.php?title=Apple_ProRes ++ */ ++ ++#define LONG_BITSTREAM_READER // some ProRes vlc codes require up to 28 bits to be read at once ++ ++#include ++ ++#include "libavutil/intmath.h" ++#include "avcodec.h" ++#include "proresdsp.h" ++#include "get_bits.h" ++ ++typedef struct { ++ const uint8_t *index; ///< pointers to the data of this slice ++ int slice_num; ++ int x_pos, y_pos; ++ int slice_width; ++ DECLARE_ALIGNED(16, DCTELEM, blocks[8 * 4 * 64]); ++} ProresThreadData; ++ ++typedef struct { ++ ProresDSPContext dsp; ++ AVFrame picture; ++ ScanTable scantable; ++ int scantable_type; ///< -1 = uninitialized, 0 = progressive, 1/2 = interlaced ++ ++ int frame_type; ///< 0 = progressive, 1 = top-field first, 2 = bottom-field first ++ int pic_format; ///< 2 = 422, 3 = 444 ++ uint8_t qmat_luma[64]; ///< dequantization matrix for luma ++ uint8_t qmat_chroma[64]; ///< dequantization matrix for chroma ++ int qmat_changed; ///< 1 - global quantization matrices changed ++ int prev_slice_sf; ///< scalefactor of the previous decoded slice ++ DECLARE_ALIGNED(16, int16_t, qmat_luma_scaled[64]); ++ DECLARE_ALIGNED(16, int16_t, qmat_chroma_scaled[64]); ++ int total_slices; ///< total number of slices in a picture ++ ProresThreadData *slice_data; ++ int pic_num; ++ int chroma_factor; ++ int mb_chroma_factor; ++ int num_chroma_blocks; ///< number of chrominance blocks in a macroblock ++ int num_x_slices; ++ int num_y_slices; ++ int slice_width_factor; ++ int slice_height_factor; ++ int num_x_mbs; ++ int num_y_mbs; ++ int alpha_info; ++} ProresContext; ++ ++ ++static const uint8_t progressive_scan[64] = { ++ 0, 1, 8, 9, 2, 3, 10, 11, ++ 16, 17, 24, 25, 18, 19, 26, 27, ++ 4, 5, 12, 20, 13, 6, 7, 14, ++ 21, 28, 29, 22, 15, 23, 30, 31, ++ 32, 33, 40, 48, 41, 34, 35, 42, ++ 49, 56, 57, 50, 43, 36, 37, 44, ++ 51, 58, 59, 52, 45, 38, 39, 46, ++ 53, 60, 61, 54, 47, 55, 62, 63 ++}; ++ ++static const uint8_t interlaced_scan[64] = { ++ 0, 8, 1, 9, 16, 24, 17, 25, ++ 2, 10, 3, 11, 18, 26, 19, 27, ++ 32, 40, 33, 34, 41, 48, 56, 49, ++ 42, 35, 43, 50, 57, 58, 51, 59, ++ 4, 12, 5, 6, 13, 20, 28, 21, ++ 14, 7, 15, 22, 29, 36, 44, 37, ++ 30, 23, 31, 38, 45, 52, 60, 53, ++ 46, 39, 47, 54, 61, 62, 55, 63 ++}; ++ ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ ++ ctx->total_slices = 0; ++ ctx->slice_data = NULL; ++ ++ avctx->bits_per_raw_sample = PRORES_BITS_PER_SAMPLE; ++ ff_proresdsp_init(&ctx->dsp, avctx); ++ ++ avctx->coded_frame = &ctx->picture; ++ avcodec_get_frame_defaults(&ctx->picture); ++ ctx->picture.type = AV_PICTURE_TYPE_I; ++ ctx->picture.key_frame = 1; ++ ++ ctx->scantable_type = -1; // set scantable type to uninitialized ++ memset(ctx->qmat_luma, 4, 64); ++ memset(ctx->qmat_chroma, 4, 64); ++ ctx->prev_slice_sf = 0; ++ ++ return 0; ++} ++ ++ ++static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, ++ const int data_size, AVCodecContext *avctx) ++{ ++ int hdr_size, version, width, height, flags; ++ const uint8_t *ptr; ++ ++ hdr_size = AV_RB16(buf); ++ if (hdr_size > data_size) { ++ av_log(avctx, AV_LOG_ERROR, "frame data too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ version = AV_RB16(buf + 2); ++ if (version >= 2) { ++ av_log(avctx, AV_LOG_ERROR, ++ "unsupported header version: %d\n", version); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ width = AV_RB16(buf + 8); ++ height = AV_RB16(buf + 10); ++ if (width != avctx->width || height != avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, ++ "picture dimension changed: old: %d x %d, new: %d x %d\n", ++ avctx->width, avctx->height, width, height); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->frame_type = (buf[12] >> 2) & 3; ++ if (ctx->frame_type > 2) { ++ av_log(avctx, AV_LOG_ERROR, ++ "unsupported frame type: %d\n", ctx->frame_type); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->chroma_factor = (buf[12] >> 6) & 3; ++ ctx->mb_chroma_factor = ctx->chroma_factor + 2; ++ ctx->num_chroma_blocks = (1 << ctx->chroma_factor) >> 1; ++ switch (ctx->chroma_factor) { ++ case 2: ++ avctx->pix_fmt = PIX_FMT_YUV422P10; ++ break; ++ case 3: ++ avctx->pix_fmt = PIX_FMT_YUV444P10; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, ++ "unsupported picture format: %d\n", ctx->pic_format); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (ctx->scantable_type != ctx->frame_type) { ++ if (!ctx->frame_type) ++ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ++ progressive_scan); ++ else ++ ff_init_scantable(ctx->dsp.idct_permutation, &ctx->scantable, ++ interlaced_scan); ++ ctx->scantable_type = ctx->frame_type; ++ } ++ ++ if (ctx->frame_type) { /* if interlaced */ ++ ctx->picture.interlaced_frame = 1; ++ ctx->picture.top_field_first = ctx->frame_type & 1; ++ } ++ ++ ctx->alpha_info = buf[17] & 0xf; ++ if (ctx->alpha_info) ++ av_log_missing_feature(avctx, "alpha channel", 0); ++ ++ ctx->qmat_changed = 0; ++ ptr = buf + 20; ++ flags = buf[19]; ++ if (flags & 2) { ++ if (ptr - buf > hdr_size - 64) { ++ av_log(avctx, AV_LOG_ERROR, "header data too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (memcmp(ctx->qmat_luma, ptr, 64)) { ++ memcpy(ctx->qmat_luma, ptr, 64); ++ ctx->qmat_changed = 1; ++ } ++ ptr += 64; ++ } else { ++ memset(ctx->qmat_luma, 4, 64); ++ ctx->qmat_changed = 1; ++ } ++ ++ if (flags & 1) { ++ if (ptr - buf > hdr_size - 64) { ++ av_log(avctx, AV_LOG_ERROR, "header data too small\n"); ++ return -1; ++ } ++ if (memcmp(ctx->qmat_chroma, ptr, 64)) { ++ memcpy(ctx->qmat_chroma, ptr, 64); ++ ctx->qmat_changed = 1; ++ } ++ } else { ++ memset(ctx->qmat_chroma, 4, 64); ++ ctx->qmat_changed = 1; ++ } ++ ++ return hdr_size; ++} ++ ++ ++static int decode_picture_header(ProresContext *ctx, const uint8_t *buf, ++ const int data_size, AVCodecContext *avctx) ++{ ++ int i, hdr_size, pic_data_size, num_slices; ++ int slice_width_factor, slice_height_factor; ++ int remainder, num_x_slices; ++ const uint8_t *data_ptr, *index_ptr; ++ ++ hdr_size = data_size > 0 ? buf[0] >> 3 : 0; ++ if (hdr_size < 8 || hdr_size > data_size) { ++ av_log(avctx, AV_LOG_ERROR, "picture header too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ pic_data_size = AV_RB32(buf + 1); ++ if (pic_data_size > data_size) { ++ av_log(avctx, AV_LOG_ERROR, "picture data too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ slice_width_factor = buf[7] >> 4; ++ slice_height_factor = buf[7] & 0xF; ++ if (slice_width_factor > 3 || slice_height_factor) { ++ av_log(avctx, AV_LOG_ERROR, ++ "unsupported slice dimension: %d x %d\n", ++ 1 << slice_width_factor, 1 << slice_height_factor); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ctx->slice_width_factor = slice_width_factor; ++ ctx->slice_height_factor = slice_height_factor; ++ ++ ctx->num_x_mbs = (avctx->width + 15) >> 4; ++ ctx->num_y_mbs = (avctx->height + ++ (1 << (4 + ctx->picture.interlaced_frame)) - 1) >> ++ (4 + ctx->picture.interlaced_frame); ++ ++ remainder = ctx->num_x_mbs & ((1 << slice_width_factor) - 1); ++ num_x_slices = (ctx->num_x_mbs >> slice_width_factor) + (remainder & 1) + ++ ((remainder >> 1) & 1) + ((remainder >> 2) & 1); ++ ++ num_slices = num_x_slices * ctx->num_y_mbs; ++ if (num_slices != AV_RB16(buf + 5)) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of slices\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (ctx->total_slices != num_slices) { ++ av_freep(&ctx->slice_data); ++ ctx->slice_data = av_malloc((num_slices + 1) * sizeof(ctx->slice_data[0])); ++ if (!ctx->slice_data) ++ return AVERROR(ENOMEM); ++ ctx->total_slices = num_slices; ++ } ++ ++ if (hdr_size + num_slices * 2 > data_size) { ++ av_log(avctx, AV_LOG_ERROR, "slice table too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* parse slice table allowing quick access to the slice data */ ++ index_ptr = buf + hdr_size; ++ data_ptr = index_ptr + num_slices * 2; ++ ++ for (i = 0; i < num_slices; i++) { ++ ctx->slice_data[i].index = data_ptr; ++ data_ptr += AV_RB16(index_ptr + i * 2); ++ } ++ ctx->slice_data[i].index = data_ptr; ++ ++ if (data_ptr > buf + data_size) { ++ av_log(avctx, AV_LOG_ERROR, "out of slice data\n"); ++ return -1; ++ } ++ ++ return pic_data_size; ++} ++ ++ ++/** ++ * Read an unsigned rice/exp golomb codeword. ++ */ ++static inline int decode_vlc_codeword(GetBitContext *gb, uint8_t codebook) ++{ ++ unsigned int rice_order, exp_order, switch_bits; ++ unsigned int buf, code; ++ int log, prefix_len, len; ++ ++ OPEN_READER(re, gb); ++ UPDATE_CACHE(re, gb); ++ buf = GET_CACHE(re, gb); ++ ++ /* number of prefix bits to switch between Rice and expGolomb */ ++ switch_bits = (codebook & 3) + 1; ++ rice_order = codebook >> 5; /* rice code order */ ++ exp_order = (codebook >> 2) & 7; /* exp golomb code order */ ++ ++ log = 31 - av_log2(buf); /* count prefix bits (zeroes) */ ++ ++ if (log < switch_bits) { /* ok, we got a rice code */ ++ if (!rice_order) { ++ /* shortcut for faster decoding of rice codes without remainder */ ++ code = log; ++ LAST_SKIP_BITS(re, gb, log + 1); ++ } else { ++ prefix_len = log + 1; ++ code = (log << rice_order) + NEG_USR32(buf << prefix_len, rice_order); ++ LAST_SKIP_BITS(re, gb, prefix_len + rice_order); ++ } ++ } else { /* otherwise we got a exp golomb code */ ++ len = (log << 1) - switch_bits + exp_order + 1; ++ code = NEG_USR32(buf, len) - (1 << exp_order) + (switch_bits << rice_order); ++ LAST_SKIP_BITS(re, gb, len); ++ } ++ ++ CLOSE_READER(re, gb); ++ ++ return code; ++} ++ ++#define LSB2SIGN(x) (-((x) & 1)) ++#define TOSIGNED(x) (((x) >> 1) ^ LSB2SIGN(x)) ++ ++#define FIRST_DC_CB 0xB8 // rice_order = 5, exp_golomb_order = 6, switch_bits = 0 ++ ++static uint8_t dc_codebook[4] = { ++ 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 ++ 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 ++ 0x4D, // rice_order = 2, exp_golomb_order = 3, switch_bits = 1 ++ 0x70 // rice_order = 3, exp_golomb_order = 4, switch_bits = 0 ++}; ++ ++ ++/** ++ * Decode DC coefficients for all blocks in a slice. ++ */ ++static inline void decode_dc_coeffs(GetBitContext *gb, DCTELEM *out, ++ int nblocks) ++{ ++ DCTELEM prev_dc; ++ int i, sign; ++ int16_t delta; ++ unsigned int code; ++ ++ code = decode_vlc_codeword(gb, FIRST_DC_CB); ++ out[0] = prev_dc = TOSIGNED(code); ++ ++ out += 64; /* move to the DC coeff of the next block */ ++ delta = 3; ++ ++ for (i = 1; i < nblocks; i++, out += 64) { ++ code = decode_vlc_codeword(gb, dc_codebook[FFMIN(FFABS(delta), 3)]); ++ ++ sign = -(((delta >> 15) & 1) ^ (code & 1)); ++ delta = (((code + 1) >> 1) ^ sign) - sign; ++ prev_dc += delta; ++ out[0] = prev_dc; ++ } ++} ++ ++ ++static uint8_t ac_codebook[7] = { ++ 0x04, // rice_order = 0, exp_golomb_order = 1, switch_bits = 0 ++ 0x28, // rice_order = 1, exp_golomb_order = 2, switch_bits = 0 ++ 0x4C, // rice_order = 2, exp_golomb_order = 3, switch_bits = 0 ++ 0x05, // rice_order = 0, exp_golomb_order = 1, switch_bits = 1 ++ 0x29, // rice_order = 1, exp_golomb_order = 2, switch_bits = 1 ++ 0x06, // rice_order = 0, exp_golomb_order = 1, switch_bits = 2 ++ 0x0A, // rice_order = 0, exp_golomb_order = 2, switch_bits = 2 ++}; ++ ++/** ++ * Lookup tables for adaptive switching between codebooks ++ * according with previous run/level value. ++ */ ++static uint8_t run_to_cb_index[16] = ++ { 5, 5, 3, 3, 0, 4, 4, 4, 4, 1, 1, 1, 1, 1, 1, 2 }; ++ ++static uint8_t lev_to_cb_index[10] = { 0, 6, 3, 5, 0, 1, 1, 1, 1, 2 }; ++ ++ ++/** ++ * Decode AC coefficients for all blocks in a slice. ++ */ ++static inline void decode_ac_coeffs(GetBitContext *gb, DCTELEM *out, ++ int blocks_per_slice, ++ int plane_size_factor, ++ const uint8_t *scan) ++{ ++ int pos, block_mask, run, level, sign, run_cb_index, lev_cb_index; ++ int max_coeffs, bits_left; ++ ++ /* set initial prediction values */ ++ run = 4; ++ level = 2; ++ ++ max_coeffs = blocks_per_slice << 6; ++ block_mask = blocks_per_slice - 1; ++ ++ for (pos = blocks_per_slice - 1; pos < max_coeffs;) { ++ run_cb_index = run_to_cb_index[FFMIN(run, 15)]; ++ lev_cb_index = lev_to_cb_index[FFMIN(level, 9)]; ++ ++ bits_left = get_bits_left(gb); ++ if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left))) ++ return; ++ ++ run = decode_vlc_codeword(gb, ac_codebook[run_cb_index]); ++ ++ bits_left = get_bits_left(gb); ++ if (bits_left <= 0 || (bits_left <= 8 && !show_bits(gb, bits_left))) ++ return; ++ ++ level = decode_vlc_codeword(gb, ac_codebook[lev_cb_index]) + 1; ++ ++ pos += run + 1; ++ if (pos >= max_coeffs) ++ break; ++ ++ sign = get_sbits(gb, 1); ++ out[((pos & block_mask) << 6) + scan[pos >> plane_size_factor]] = ++ (level ^ sign) - sign; ++ } ++} ++ ++ ++/** ++ * Decode a slice plane (luma or chroma). ++ */ ++static void decode_slice_plane(ProresContext *ctx, ProresThreadData *td, ++ const uint8_t *buf, ++ int data_size, uint16_t *out_ptr, ++ int linesize, int mbs_per_slice, ++ int blocks_per_mb, int plane_size_factor, ++ const int16_t *qmat) ++{ ++ GetBitContext gb; ++ DCTELEM *block_ptr; ++ int mb_num, blocks_per_slice; ++ ++ blocks_per_slice = mbs_per_slice * blocks_per_mb; ++ ++ memset(td->blocks, 0, 8 * 4 * 64 * sizeof(*td->blocks)); ++ ++ init_get_bits(&gb, buf, data_size << 3); ++ ++ decode_dc_coeffs(&gb, td->blocks, blocks_per_slice); ++ ++ decode_ac_coeffs(&gb, td->blocks, blocks_per_slice, ++ plane_size_factor, ctx->scantable.permutated); ++ ++ /* inverse quantization, inverse transform and output */ ++ block_ptr = td->blocks; ++ ++ for (mb_num = 0; mb_num < mbs_per_slice; mb_num++, out_ptr += blocks_per_mb * 4) { ++ ctx->dsp.idct_put(out_ptr, linesize, block_ptr, qmat); ++ block_ptr += 64; ++ if (blocks_per_mb > 2) { ++ ctx->dsp.idct_put(out_ptr + 8, linesize, block_ptr, qmat); ++ block_ptr += 64; ++ } ++ ctx->dsp.idct_put(out_ptr + linesize * 4, linesize, block_ptr, qmat); ++ block_ptr += 64; ++ if (blocks_per_mb > 2) { ++ ctx->dsp.idct_put(out_ptr + linesize * 4 + 8, linesize, block_ptr, qmat); ++ block_ptr += 64; ++ } ++ } ++} ++ ++ ++static int decode_slice(AVCodecContext *avctx, void *tdata) ++{ ++ ProresThreadData *td = tdata; ++ ProresContext *ctx = avctx->priv_data; ++ int mb_x_pos = td->x_pos; ++ int mb_y_pos = td->y_pos; ++ int pic_num = ctx->pic_num; ++ int slice_num = td->slice_num; ++ int mbs_per_slice = td->slice_width; ++ const uint8_t *buf; ++ uint8_t *y_data, *u_data, *v_data; ++ AVFrame *pic = avctx->coded_frame; ++ int i, sf, slice_width_factor; ++ int slice_data_size, hdr_size, y_data_size, u_data_size, v_data_size; ++ int y_linesize, u_linesize, v_linesize; ++ ++ buf = ctx->slice_data[slice_num].index; ++ slice_data_size = ctx->slice_data[slice_num + 1].index - buf; ++ ++ slice_width_factor = av_log2(mbs_per_slice); ++ ++ y_data = pic->data[0]; ++ u_data = pic->data[1]; ++ v_data = pic->data[2]; ++ y_linesize = pic->linesize[0]; ++ u_linesize = pic->linesize[1]; ++ v_linesize = pic->linesize[2]; ++ ++ if (pic->interlaced_frame) { ++ if (!(pic_num ^ pic->top_field_first)) { ++ y_data += y_linesize; ++ u_data += u_linesize; ++ v_data += v_linesize; ++ } ++ y_linesize <<= 1; ++ u_linesize <<= 1; ++ v_linesize <<= 1; ++ } ++ ++ if (slice_data_size < 6) { ++ av_log(avctx, AV_LOG_ERROR, "slice data too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* parse slice header */ ++ hdr_size = buf[0] >> 3; ++ y_data_size = AV_RB16(buf + 2); ++ u_data_size = AV_RB16(buf + 4); ++ v_data_size = hdr_size > 7 ? AV_RB16(buf + 6) : ++ slice_data_size - y_data_size - u_data_size - hdr_size; ++ ++ if (hdr_size + y_data_size + u_data_size + v_data_size > slice_data_size || ++ v_data_size < 0 || hdr_size < 6) { ++ av_log(avctx, AV_LOG_ERROR, "invalid data size\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ sf = av_clip(buf[1], 1, 224); ++ sf = sf > 128 ? (sf - 96) << 2 : sf; ++ ++ /* scale quantization matrixes according with slice's scale factor */ ++ /* TODO: this can be SIMD-optimized a lot */ ++ if (ctx->qmat_changed || sf != ctx->prev_slice_sf) { ++ ctx->prev_slice_sf = sf; ++ for (i = 0; i < 64; i++) { ++ ctx->qmat_luma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_luma[i] * sf; ++ ctx->qmat_chroma_scaled[ctx->dsp.idct_permutation[i]] = ctx->qmat_chroma[i] * sf; ++ } ++ } ++ ++ /* decode luma plane */ ++ decode_slice_plane(ctx, td, buf + hdr_size, y_data_size, ++ (uint16_t*) (y_data + (mb_y_pos << 4) * y_linesize + ++ (mb_x_pos << 5)), y_linesize, ++ mbs_per_slice, 4, slice_width_factor + 2, ++ ctx->qmat_luma_scaled); ++ ++ /* decode U chroma plane */ ++ decode_slice_plane(ctx, td, buf + hdr_size + y_data_size, u_data_size, ++ (uint16_t*) (u_data + (mb_y_pos << 4) * u_linesize + ++ (mb_x_pos << ctx->mb_chroma_factor)), ++ u_linesize, mbs_per_slice, ctx->num_chroma_blocks, ++ slice_width_factor + ctx->chroma_factor - 1, ++ ctx->qmat_chroma_scaled); ++ ++ /* decode V chroma plane */ ++ decode_slice_plane(ctx, td, buf + hdr_size + y_data_size + u_data_size, ++ v_data_size, ++ (uint16_t*) (v_data + (mb_y_pos << 4) * v_linesize + ++ (mb_x_pos << ctx->mb_chroma_factor)), ++ v_linesize, mbs_per_slice, ctx->num_chroma_blocks, ++ slice_width_factor + ctx->chroma_factor - 1, ++ ctx->qmat_chroma_scaled); ++ ++ return 0; ++} ++ ++ ++static int decode_picture(ProresContext *ctx, int pic_num, ++ AVCodecContext *avctx) ++{ ++ int slice_num, slice_width, x_pos, y_pos; ++ ++ slice_num = 0; ++ ++ ctx->pic_num = pic_num; ++ for (y_pos = 0; y_pos < ctx->num_y_mbs; y_pos++) { ++ slice_width = 1 << ctx->slice_width_factor; ++ ++ for (x_pos = 0; x_pos < ctx->num_x_mbs && slice_width; ++ x_pos += slice_width) { ++ while (ctx->num_x_mbs - x_pos < slice_width) ++ slice_width >>= 1; ++ ++ ctx->slice_data[slice_num].slice_num = slice_num; ++ ctx->slice_data[slice_num].x_pos = x_pos; ++ ctx->slice_data[slice_num].y_pos = y_pos; ++ ctx->slice_data[slice_num].slice_width = slice_width; ++ ++ slice_num++; ++ } ++ } ++ ++ return avctx->execute(avctx, decode_slice, ++ ctx->slice_data, NULL, slice_num, ++ sizeof(ctx->slice_data[0])); ++} ++ ++ ++#define FRAME_ID MKBETAG('i', 'c', 'p', 'f') ++#define MOVE_DATA_PTR(nbytes) buf += (nbytes); buf_size -= (nbytes) ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ AVFrame *picture = avctx->coded_frame; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int frame_hdr_size, pic_num, pic_data_size; ++ ++ /* check frame atom container */ ++ if (buf_size < 28 || buf_size < AV_RB32(buf) || ++ AV_RB32(buf + 4) != FRAME_ID) { ++ av_log(avctx, AV_LOG_ERROR, "invalid frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ MOVE_DATA_PTR(8); ++ ++ frame_hdr_size = decode_frame_header(ctx, buf, buf_size, avctx); ++ if (frame_hdr_size < 0) ++ return AVERROR_INVALIDDATA; ++ ++ MOVE_DATA_PTR(frame_hdr_size); ++ ++ if (picture->data[0]) ++ avctx->release_buffer(avctx, picture); ++ ++ picture->reference = 0; ++ if (avctx->get_buffer(avctx, picture) < 0) ++ return -1; ++ ++ for (pic_num = 0; ctx->picture.interlaced_frame - pic_num + 1; pic_num++) { ++ pic_data_size = decode_picture_header(ctx, buf, buf_size, avctx); ++ if (pic_data_size < 0) ++ return AVERROR_INVALIDDATA; ++ ++ if (decode_picture(ctx, pic_num, avctx)) ++ return -1; ++ ++ MOVE_DATA_PTR(pic_data_size); ++ } ++ ++ *data_size = sizeof(AVPicture); ++ *(AVFrame*) data = *avctx->coded_frame; ++ ++ return avpkt->size; ++} ++ ++ ++static av_cold int decode_close(AVCodecContext *avctx) ++{ ++ ProresContext *ctx = avctx->priv_data; ++ ++ if (ctx->picture.data[0]) ++ avctx->release_buffer(avctx, &ctx->picture); ++ ++ av_freep(&ctx->slice_data); ++ ++ return 0; ++} ++ ++ ++AVCodec ff_prores_lgpl_decoder = { ++ .name = "prores_lgpl", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PRORES, ++ .priv_data_size = sizeof(ProresContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_SLICE_THREADS, ++ .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes (iCodec Pro)") ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdsp.c 2012-05-14 14:08:54.132335916 +0200 +@@ -0,0 +1,63 @@ ++/* ++ * Apple ProRes compatible decoder ++ * ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "proresdsp.h" ++#include "simple_idct.h" ++ ++#define BIAS (1 << (PRORES_BITS_PER_SAMPLE - 1)) ///< bias value for converting signed pixels into unsigned ones ++#define CLIP_MIN (1 << (PRORES_BITS_PER_SAMPLE - 8)) ///< minimum value for clipping resulting pixels ++#define CLIP_MAX (1 << PRORES_BITS_PER_SAMPLE) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels ++ ++#define CLIP_AND_BIAS(x) (av_clip((x) + BIAS, CLIP_MIN, CLIP_MAX)) ++ ++/** ++ * Add bias value, clamp and output pixels of a slice ++ */ ++static void put_pixels(uint16_t *dst, int stride, const DCTELEM *in) ++{ ++ int x, y, src_offset, dst_offset; ++ ++ for (y = 0, dst_offset = 0; y < 8; y++, dst_offset += stride) { ++ for (x = 0; x < 8; x++) { ++ src_offset = (y << 3) + x; ++ ++ dst[dst_offset + x] = CLIP_AND_BIAS(in[src_offset]); ++ } ++ } ++} ++ ++static void prores_idct_put_c(uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat) ++{ ++ ff_prores_idct(block, qmat); ++ put_pixels(out, linesize >> 1, block); ++} ++ ++void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx) ++{ ++ dsp->idct_put = prores_idct_put_c; ++ dsp->idct_permutation_type = FF_NO_IDCT_PERM; ++ ++ if (HAVE_MMX) ff_proresdsp_x86_init(dsp, avctx); ++ ++ ff_init_scantable_permutation(dsp->idct_permutation, ++ dsp->idct_permutation_type); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresdsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresdsp.h 2012-05-14 14:08:54.133335936 +0200 +@@ -0,0 +1,40 @@ ++/* ++ * Apple ProRes compatible decoder ++ * ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_PRORESDSP_H ++#define AVCODEC_PRORESDSP_H ++ ++#include "dsputil.h" ++ ++#define PRORES_BITS_PER_SAMPLE 10 ///< output precision of prores decoder ++ ++typedef struct { ++ int idct_permutation_type; ++ uint8_t idct_permutation[64]; ++ void (* idct_put) (uint16_t *out, int linesize, DCTELEM *block, const int16_t *qmat); ++} ProresDSPContext; ++ ++void ff_proresdsp_init(ProresDSPContext *dsp, AVCodecContext *avctx); ++ ++void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx); ++ ++#endif /* AVCODEC_PRORESDSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/proresenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/proresenc.c 2012-05-14 14:08:54.135335976 +0200 +@@ -0,0 +1,598 @@ ++/* ++ * Apple ProRes encoder ++ * ++ * Copyright (c) 2011 Anatoliy Wasserman ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file libavcodec/proresenc.c ++ * Known FOURCCs: 'apch' (HQ), 'apcn' (SD), 'apcs' (LT), 'acpo' (Proxy) ++ */ ++ ++#include "avcodec.h" ++#include "put_bits.h" ++#include "bytestream.h" ++#include "dsputil.h" ++ ++#define DEFAULT_SLICE_MB_WIDTH 8 ++ ++#define FF_PROFILE_PRORES_PROXY 0 ++#define FF_PROFILE_PRORES_LT 1 ++#define FF_PROFILE_PRORES_STANDARD 2 ++#define FF_PROFILE_PRORES_HQ 3 ++ ++static const AVProfile profiles[] = { ++ { FF_PROFILE_PRORES_PROXY, "apco"}, ++ { FF_PROFILE_PRORES_LT, "apcs"}, ++ { FF_PROFILE_PRORES_STANDARD, "apcn"}, ++ { FF_PROFILE_PRORES_HQ, "apch"}, ++ { FF_PROFILE_UNKNOWN } ++}; ++ ++static const int qp_start_table[4] = { 4, 1, 1, 1 }; ++static const int qp_end_table[4] = { 8, 9, 6, 6 }; ++static const int bitrate_table[5] = { 1000, 2100, 3500, 5400 }; ++ ++static const uint8_t progressive_scan[64] = { ++ 0, 1, 8, 9, 2, 3, 10, 11, ++ 16, 17, 24, 25, 18, 19, 26, 27, ++ 4, 5, 12, 20, 13, 6, 7, 14, ++ 21, 28, 29, 22, 15, 23, 30, 31, ++ 32, 33, 40, 48, 41, 34, 35, 42, ++ 49, 56, 57, 50, 43, 36, 37, 44, ++ 51, 58, 59, 52, 45, 38, 39, 46, ++ 53, 60, 61, 54, 47, 55, 62, 63 ++}; ++ ++static const uint8_t QMAT_LUMA[4][64] = { ++ { ++ 4, 7, 9, 11, 13, 14, 15, 63, ++ 7, 7, 11, 12, 14, 15, 63, 63, ++ 9, 11, 13, 14, 15, 63, 63, 63, ++ 11, 11, 13, 14, 63, 63, 63, 63, ++ 11, 13, 14, 63, 63, 63, 63, 63, ++ 13, 14, 63, 63, 63, 63, 63, 63, ++ 13, 63, 63, 63, 63, 63, 63, 63, ++ 63, 63, 63, 63, 63, 63, 63, 63 ++ }, { ++ 4, 5, 6, 7, 9, 11, 13, 15, ++ 5, 5, 7, 8, 11, 13, 15, 17, ++ 6, 7, 9, 11, 13, 15, 15, 17, ++ 7, 7, 9, 11, 13, 15, 17, 19, ++ 7, 9, 11, 13, 14, 16, 19, 23, ++ 9, 11, 13, 14, 16, 19, 23, 29, ++ 9, 11, 13, 15, 17, 21, 28, 35, ++ 11, 13, 16, 17, 21, 28, 35, 41 ++ }, { ++ 4, 4, 5, 5, 6, 7, 7, 9, ++ 4, 4, 5, 6, 7, 7, 9, 9, ++ 5, 5, 6, 7, 7, 9, 9, 10, ++ 5, 5, 6, 7, 7, 9, 9, 10, ++ 5, 6, 7, 7, 8, 9, 10, 12, ++ 6, 7, 7, 8, 9, 10, 12, 15, ++ 6, 7, 7, 9, 10, 11, 14, 17, ++ 7, 7, 9, 10, 11, 14, 17, 21 ++ }, { ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 5, ++ 4, 4, 4, 4, 4, 4, 5, 5, ++ 4, 4, 4, 4, 4, 5, 5, 6, ++ 4, 4, 4, 4, 5, 5, 6, 7, ++ 4, 4, 4, 4, 5, 6, 7, 7 ++ } ++}; ++ ++static const uint8_t QMAT_CHROMA[4][64] = { ++ { ++ 4, 7, 9, 11, 13, 14, 63, 63, ++ 7, 7, 11, 12, 14, 63, 63, 63, ++ 9, 11, 13, 14, 63, 63, 63, 63, ++ 11, 11, 13, 14, 63, 63, 63, 63, ++ 11, 13, 14, 63, 63, 63, 63, 63, ++ 13, 14, 63, 63, 63, 63, 63, 63, ++ 13, 63, 63, 63, 63, 63, 63, 63, ++ 63, 63, 63, 63, 63, 63, 63, 63 ++ }, { ++ 4, 5, 6, 7, 9, 11, 13, 15, ++ 5, 5, 7, 8, 11, 13, 15, 17, ++ 6, 7, 9, 11, 13, 15, 15, 17, ++ 7, 7, 9, 11, 13, 15, 17, 19, ++ 7, 9, 11, 13, 14, 16, 19, 23, ++ 9, 11, 13, 14, 16, 19, 23, 29, ++ 9, 11, 13, 15, 17, 21, 28, 35, ++ 11, 13, 16, 17, 21, 28, 35, 41 ++ }, { ++ 4, 4, 5, 5, 6, 7, 7, 9, ++ 4, 4, 5, 6, 7, 7, 9, 9, ++ 5, 5, 6, 7, 7, 9, 9, 10, ++ 5, 5, 6, 7, 7, 9, 9, 10, ++ 5, 6, 7, 7, 8, 9, 10, 12, ++ 6, 7, 7, 8, 9, 10, 12, 15, ++ 6, 7, 7, 9, 10, 11, 14, 17, ++ 7, 7, 9, 10, 11, 14, 17, 21 ++ }, { ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 4, ++ 4, 4, 4, 4, 4, 4, 4, 5, ++ 4, 4, 4, 4, 4, 4, 5, 5, ++ 4, 4, 4, 4, 4, 5, 5, 6, ++ 4, 4, 4, 4, 5, 5, 6, 7, ++ 4, 4, 4, 4, 5, 6, 7, 7 ++ } ++}; ++ ++ ++typedef struct { ++ uint8_t* fill_y; ++ uint8_t* fill_u; ++ uint8_t* fill_v; ++ ++ int qmat_luma[16][64]; ++ int qmat_chroma[16][64]; ++} ProresContext; ++ ++static void encode_codeword(PutBitContext *pb, int val, int codebook) ++{ ++ unsigned int rice_order, exp_order, switch_bits, first_exp, exp, zeros, ++ mask; ++ ++ /* number of bits to switch between rice and exp golomb */ ++ switch_bits = codebook & 3; ++ rice_order = codebook >> 5; ++ exp_order = (codebook >> 2) & 7; ++ ++ first_exp = ((switch_bits + 1) << rice_order); ++ ++ if (val >= first_exp) { /* exp golomb */ ++ val -= first_exp; ++ val += (1 << exp_order); ++ exp = av_log2(val); ++ zeros = exp - exp_order + switch_bits + 1; ++ put_bits(pb, zeros, 0); ++ put_bits(pb, 1, 1); ++ put_bits(pb, exp, val); ++ } else if (rice_order) { ++ mask = (1 << rice_order) - 1; ++ put_bits(pb, (val >> rice_order), 0); ++ put_bits(pb, 1, 1); ++ put_bits(pb, rice_order, val & mask); ++ } else { ++ put_bits(pb, val, 0); ++ put_bits(pb, 1, 1); ++ } ++} ++ ++#define QSCALE(qmat,ind,val) ((val) / (qmat[ind])) ++#define TO_GOLOMB(val) ((val << 1) ^ (val >> 31)) ++#define DIFF_SIGN(val, sign) ((val >> 31) ^ sign) ++#define IS_NEGATIVE(val) (((val >> 31) ^ -1) + 1) ++#define TO_GOLOMB2(val,sign) (val==0 ? 0 : (val << 1) + sign) ++ ++static av_always_inline int get_level(int val) ++{ ++ int sign = (val >> 31); ++ return (val ^ sign) - sign; ++} ++ ++#define FIRST_DC_CB 0xB8 ++ ++static const uint8_t dc_codebook[7] = { 0x04, 0x28, 0x28, 0x4D, 0x4D, 0x70, 0x70}; ++ ++static void encode_dc_coeffs(PutBitContext *pb, DCTELEM *in, ++ int blocks_per_slice, int *qmat) ++{ ++ int prev_dc, code; ++ int i, sign, idx; ++ int new_dc, delta, diff_sign, new_code; ++ ++ prev_dc = QSCALE(qmat, 0, in[0] - 16384); ++ code = TO_GOLOMB(prev_dc); ++ encode_codeword(pb, code, FIRST_DC_CB); ++ ++ code = 5; sign = 0; idx = 64; ++ for (i = 1; i < blocks_per_slice; i++, idx += 64) { ++ new_dc = QSCALE(qmat, 0, in[idx] - 16384); ++ delta = new_dc - prev_dc; ++ diff_sign = DIFF_SIGN(delta, sign); ++ new_code = TO_GOLOMB2(get_level(delta), diff_sign); ++ ++ encode_codeword(pb, new_code, dc_codebook[FFMIN(code, 6)]); ++ ++ code = new_code; ++ sign = delta >> 31; ++ prev_dc = new_dc; ++ } ++} ++ ++static const uint8_t run_to_cb[16] = { 0x06, 0x06, 0x05, 0x05, 0x04, 0x29, ++ 0x29, 0x29, 0x29, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x4C }; ++static const uint8_t lev_to_cb[10] = { 0x04, 0x0A, 0x05, 0x06, 0x04, 0x28, ++ 0x28, 0x28, 0x28, 0x4C }; ++ ++static void encode_ac_coeffs(AVCodecContext *avctx, PutBitContext *pb, ++ DCTELEM *in, int blocks_per_slice, int *qmat) ++{ ++ int prev_run = 4; ++ int prev_level = 2; ++ ++ int run = 0, level, code, i, j; ++ for (i = 1; i < 64; i++) { ++ int indp = progressive_scan[i]; ++ for (j = 0; j < blocks_per_slice; j++) { ++ int val = QSCALE(qmat, indp, in[(j << 6) + indp]); ++ if (val) { ++ encode_codeword(pb, run, run_to_cb[FFMIN(prev_run, 15)]); ++ ++ prev_run = run; ++ run = 0; ++ level = get_level(val); ++ code = level - 1; ++ ++ encode_codeword(pb, code, lev_to_cb[FFMIN(prev_level, 9)]); ++ ++ prev_level = level; ++ ++ put_bits(pb, 1, IS_NEGATIVE(val)); ++ } else { ++ ++run; ++ } ++ } ++ } ++} ++ ++static void get(uint8_t *pixels, int stride, DCTELEM* block) ++{ ++ int16_t *p = (int16_t*)pixels; ++ int i, j; ++ ++ stride >>= 1; ++ for (i = 0; i < 8; i++) { ++ for (j = 0; j < 8; j++) { ++ block[j] = p[j]; ++ } ++ p += stride; ++ block += 8; ++ } ++} ++ ++static void fdct_get(uint8_t *pixels, int stride, DCTELEM* block) ++{ ++ get(pixels, stride, block); ++ ff_jpeg_fdct_islow_10(block); ++} ++ ++static int encode_slice_plane(AVCodecContext *avctx, int mb_count, ++ uint8_t *src, int src_stride, uint8_t *buf, unsigned buf_size, ++ int *qmat, int chroma) ++{ ++ DECLARE_ALIGNED(16, DCTELEM, blocks)[DEFAULT_SLICE_MB_WIDTH << 8], *block; ++ int i, blocks_per_slice; ++ PutBitContext pb; ++ ++ block = blocks; ++ for (i = 0; i < mb_count; i++) { ++ fdct_get(src, src_stride, block + (0 << 6)); ++ fdct_get(src + 8 * src_stride, src_stride, block + ((2 - chroma) << 6)); ++ if (!chroma) { ++ fdct_get(src + 16, src_stride, block + (1 << 6)); ++ fdct_get(src + 16 + 8 * src_stride, src_stride, block + (3 << 6)); ++ } ++ ++ block += (256 >> chroma); ++ src += (32 >> chroma); ++ } ++ ++ blocks_per_slice = mb_count << (2 - chroma); ++ init_put_bits(&pb, buf, buf_size << 3); ++ ++ encode_dc_coeffs(&pb, blocks, blocks_per_slice, qmat); ++ encode_ac_coeffs(avctx, &pb, blocks, blocks_per_slice, qmat); ++ ++ flush_put_bits(&pb); ++ return put_bits_ptr(&pb) - pb.buf; ++} ++ ++static av_always_inline unsigned encode_slice_data(AVCodecContext *avctx, ++ uint8_t *dest_y, uint8_t *dest_u, uint8_t *dest_v, int luma_stride, ++ int chroma_stride, unsigned mb_count, uint8_t *buf, unsigned data_size, ++ unsigned* y_data_size, unsigned* u_data_size, unsigned* v_data_size, ++ int qp) ++{ ++ ProresContext* ctx = avctx->priv_data; ++ ++ *y_data_size = encode_slice_plane(avctx, mb_count, dest_y, luma_stride, ++ buf, data_size, ctx->qmat_luma[qp - 1], 0); ++ ++ if (!(avctx->flags & CODEC_FLAG_GRAY)) { ++ *u_data_size = encode_slice_plane(avctx, mb_count, dest_u, ++ chroma_stride, buf + *y_data_size, data_size - *y_data_size, ++ ctx->qmat_chroma[qp - 1], 1); ++ ++ *v_data_size = encode_slice_plane(avctx, mb_count, dest_v, ++ chroma_stride, buf + *y_data_size + *u_data_size, ++ data_size - *y_data_size - *u_data_size, ++ ctx->qmat_chroma[qp - 1], 1); ++ } ++ ++ return *y_data_size + *u_data_size + *v_data_size; ++} ++ ++static void subimage_with_fill(uint16_t *src, unsigned x, unsigned y, ++ unsigned stride, unsigned width, unsigned height, uint16_t *dst, ++ unsigned dst_width, unsigned dst_height) ++{ ++ ++ int box_width = FFMIN(width - x, dst_width); ++ int box_height = FFMIN(height - y, dst_height); ++ int i, j, src_stride = stride >> 1; ++ uint16_t last_pix, *last_line; ++ ++ src += y * src_stride + x; ++ for (i = 0; i < box_height; ++i) { ++ for (j = 0; j < box_width; ++j) { ++ dst[j] = src[j]; ++ } ++ last_pix = dst[j - 1]; ++ for (; j < dst_width; j++) ++ dst[j] = last_pix; ++ src += src_stride; ++ dst += dst_width; ++ } ++ last_line = dst - dst_width; ++ for (; i < dst_height; i++) { ++ for (j = 0; j < dst_width; ++j) { ++ dst[j] = last_line[j]; ++ } ++ dst += dst_width; ++ } ++} ++ ++static int encode_slice(AVCodecContext *avctx, AVFrame *pic, int mb_x, ++ int mb_y, unsigned mb_count, uint8_t *buf, unsigned data_size, ++ int unsafe, int *qp) ++{ ++ int luma_stride, chroma_stride; ++ int hdr_size = 6, slice_size; ++ uint8_t *dest_y, *dest_u, *dest_v; ++ unsigned y_data_size = 0, u_data_size = 0, v_data_size = 0; ++ ProresContext* ctx = avctx->priv_data; ++ int tgt_bits = (mb_count * bitrate_table[avctx->profile]) >> 2; ++ int low_bytes = (tgt_bits - (tgt_bits >> 3)) >> 3; // 12% bitrate fluctuation ++ int high_bytes = (tgt_bits + (tgt_bits >> 3)) >> 3; ++ ++ luma_stride = pic->linesize[0]; ++ chroma_stride = pic->linesize[1]; ++ ++ dest_y = pic->data[0] + (mb_y << 4) * luma_stride + (mb_x << 5); ++ dest_u = pic->data[1] + (mb_y << 4) * chroma_stride + (mb_x << 4); ++ dest_v = pic->data[2] + (mb_y << 4) * chroma_stride + (mb_x << 4); ++ ++ if (unsafe) { ++ ++ subimage_with_fill((uint16_t *) pic->data[0], mb_x << 4, mb_y << 4, ++ luma_stride, avctx->width, avctx->height, ++ (uint16_t *) ctx->fill_y, mb_count << 4, 16); ++ subimage_with_fill((uint16_t *) pic->data[1], mb_x << 3, mb_y << 4, ++ chroma_stride, avctx->width >> 1, avctx->height, ++ (uint16_t *) ctx->fill_u, mb_count << 3, 16); ++ subimage_with_fill((uint16_t *) pic->data[2], mb_x << 3, mb_y << 4, ++ chroma_stride, avctx->width >> 1, avctx->height, ++ (uint16_t *) ctx->fill_v, mb_count << 3, 16); ++ ++ encode_slice_data(avctx, ctx->fill_y, ctx->fill_u, ctx->fill_v, ++ mb_count << 5, mb_count << 4, mb_count, buf + hdr_size, ++ data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size, ++ *qp); ++ } else { ++ slice_size = encode_slice_data(avctx, dest_y, dest_u, dest_v, ++ luma_stride, chroma_stride, mb_count, buf + hdr_size, ++ data_size - hdr_size, &y_data_size, &u_data_size, &v_data_size, ++ *qp); ++ ++ if (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]) { ++ do { ++ *qp += 1; ++ slice_size = encode_slice_data(avctx, dest_y, dest_u, dest_v, ++ luma_stride, chroma_stride, mb_count, buf + hdr_size, ++ data_size - hdr_size, &y_data_size, &u_data_size, ++ &v_data_size, *qp); ++ } while (slice_size > high_bytes && *qp < qp_end_table[avctx->profile]); ++ } else if (slice_size < low_bytes && *qp ++ > qp_start_table[avctx->profile]) { ++ do { ++ *qp -= 1; ++ slice_size = encode_slice_data(avctx, dest_y, dest_u, dest_v, ++ luma_stride, chroma_stride, mb_count, buf + hdr_size, ++ data_size - hdr_size, &y_data_size, &u_data_size, ++ &v_data_size, *qp); ++ } while (slice_size < low_bytes && *qp > qp_start_table[avctx->profile]); ++ } ++ } ++ ++ buf[0] = hdr_size << 3; ++ buf[1] = *qp; ++ AV_WB16(buf + 2, y_data_size); ++ AV_WB16(buf + 4, u_data_size); ++ ++ return hdr_size + y_data_size + u_data_size + v_data_size; ++} ++ ++static int prores_encode_picture(AVCodecContext *avctx, AVFrame *pic, ++ uint8_t *buf, const int buf_size) ++{ ++ int mb_width = (avctx->width + 15) >> 4; ++ int mb_height = (avctx->height + 15) >> 4; ++ int hdr_size, sl_size, i; ++ int mb_y, sl_data_size, qp; ++ int unsafe_bot, unsafe_right; ++ uint8_t *sl_data, *sl_data_sizes; ++ int slice_per_line = 0, rem = mb_width; ++ ++ for (i = av_log2(DEFAULT_SLICE_MB_WIDTH); i >= 0; --i) { ++ slice_per_line += rem >> i; ++ rem &= (1 << i) - 1; ++ } ++ ++ qp = qp_start_table[avctx->profile]; ++ hdr_size = 8; sl_data_size = buf_size - hdr_size; ++ sl_data_sizes = buf + hdr_size; ++ sl_data = sl_data_sizes + (slice_per_line * mb_height * 2); ++ for (mb_y = 0; mb_y < mb_height; mb_y++) { ++ int mb_x = 0; ++ int slice_mb_count = DEFAULT_SLICE_MB_WIDTH; ++ while (mb_x < mb_width) { ++ while (mb_width - mb_x < slice_mb_count) ++ slice_mb_count >>= 1; ++ ++ unsafe_bot = (avctx->height & 0xf) && (mb_y == mb_height - 1); ++ unsafe_right = (avctx->width & 0xf) && (mb_x + slice_mb_count == mb_width); ++ ++ sl_size = encode_slice(avctx, pic, mb_x, mb_y, slice_mb_count, ++ sl_data, sl_data_size, unsafe_bot || unsafe_right, &qp); ++ ++ bytestream_put_be16(&sl_data_sizes, sl_size); ++ sl_data += sl_size; ++ sl_data_size -= sl_size; ++ mb_x += slice_mb_count; ++ } ++ } ++ ++ buf[0] = hdr_size << 3; ++ AV_WB32(buf + 1, sl_data - buf); ++ AV_WB16(buf + 5, slice_per_line * mb_height); ++ buf[7] = av_log2(DEFAULT_SLICE_MB_WIDTH) << 4; ++ ++ return sl_data - buf; ++} ++ ++static int prores_encode_frame(AVCodecContext *avctx, unsigned char *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ ++ int header_size = 148; ++ int pic_size = prores_encode_picture(avctx, pic, buf + header_size + 8, ++ buf_size - header_size - 8); ++ ++ bytestream_put_be32(&buf, pic_size + 8 + header_size); ++ bytestream_put_buffer(&buf, "icpf", 4); ++ ++ bytestream_put_be16(&buf, header_size); ++ bytestream_put_be16(&buf, 0); ++ bytestream_put_buffer(&buf, "fmpg", 4); ++ bytestream_put_be16(&buf, avctx->width); ++ bytestream_put_be16(&buf, avctx->height); ++ *buf++ = 0x83; // {10}(422){00}{00}(frame){11} ++ *buf++ = 0; ++ *buf++ = 2; ++ *buf++ = 2; ++ *buf++ = 6; ++ *buf++ = 32; ++ *buf++ = 0; ++ *buf++ = 3; ++ ++ bytestream_put_buffer(&buf, QMAT_LUMA[avctx->profile], 64); ++ bytestream_put_buffer(&buf, QMAT_CHROMA[avctx->profile], 64); ++ ++ return pic_size + 8 + header_size; ++} ++ ++static void scale_mat(const uint8_t* src, int* dst, int scale) ++{ ++ int i; ++ for (i = 0; i < 64; i++) ++ dst[i] = src[i] * scale; ++} ++ ++static av_cold int prores_encode_init(AVCodecContext *avctx) ++{ ++ int i; ++ ProresContext* ctx = avctx->priv_data; ++ ++ if (avctx->pix_fmt != PIX_FMT_YUV422P10) { ++ av_log(avctx, AV_LOG_ERROR, "need YUV422P10\n"); ++ return -1; ++ } ++ if (avctx->width & 0x1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "frame width needs to be multiple of 2\n"); ++ return -1; ++ } ++ ++ if ((avctx->height & 0xf) || (avctx->width & 0xf)) { ++ ctx->fill_y = av_malloc(4 * (DEFAULT_SLICE_MB_WIDTH << 8)); ++ if (!ctx->fill_y) ++ return AVERROR(ENOMEM); ++ ctx->fill_u = ctx->fill_y + (DEFAULT_SLICE_MB_WIDTH << 9); ++ ctx->fill_v = ctx->fill_u + (DEFAULT_SLICE_MB_WIDTH << 8); ++ } ++ ++ if (avctx->profile == FF_PROFILE_UNKNOWN) { ++ avctx->profile = FF_PROFILE_PRORES_STANDARD; ++ av_log(avctx, AV_LOG_INFO, ++ "encoding with ProRes standard (apcn) profile\n"); ++ ++ } else if (avctx->profile < FF_PROFILE_PRORES_PROXY ++ || avctx->profile > FF_PROFILE_PRORES_HQ) { ++ av_log( ++ avctx, ++ AV_LOG_ERROR, ++ "unknown profile %d, use [0 - apco, 1 - apcs, 2 - apcn (default), 3 - apch]\n", ++ avctx->profile); ++ return -1; ++ } ++ ++ avctx->codec_tag = AV_RL32((const uint8_t*)profiles[avctx->profile].name); ++ ++ for (i = 1; i <= 16; i++) { ++ scale_mat(QMAT_LUMA[avctx->profile] , ctx->qmat_luma[i - 1] , i); ++ scale_mat(QMAT_CHROMA[avctx->profile], ctx->qmat_chroma[i - 1], i); ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ return 0; ++} ++ ++static av_cold int prores_encode_close(AVCodecContext *avctx) ++{ ++ ProresContext* ctx = avctx->priv_data; ++ av_freep(&avctx->coded_frame); ++ av_freep(&ctx->fill_y); ++ ++ return 0; ++} ++ ++AVCodec ff_prores_encoder = { ++ .name = "prores", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PRORES, ++ .priv_data_size = sizeof(ProresContext), ++ .init = prores_encode_init, ++ .close = prores_encode_close, ++ .encode = prores_encode_frame, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P10, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Apple ProRes"), ++ .profiles = profiles ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ps2/dsputil_mmi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ps2/dsputil_mmi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ps2/dsputil_mmi.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ps2/dsputil_mmi.c 2012-05-14 14:08:54.135335976 +0200 +@@ -142,7 +142,9 @@ + void dsputil_init_mmi(DSPContext* c, AVCodecContext *avctx) + { + const int idct_algo= avctx->idct_algo; ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; + ++ if (!high_bit_depth) { + c->clear_blocks = clear_blocks_mmi; + + c->put_pixels_tab[1][0] = put_pixels8_mmi; +@@ -152,8 +154,10 @@ + c->put_no_rnd_pixels_tab[0][0] = put_pixels16_mmi; + + c->get_pixels = get_pixels_mmi; ++ } + +- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2){ ++ if (avctx->bits_per_raw_sample <= 8 && ++ (idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_PS2)) { + c->idct_put= ff_mmi_idct_put; + c->idct_add= ff_mmi_idct_add; + c->idct = ff_mmi_idct; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/psymodel.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/psymodel.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/psymodel.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/psymodel.c 2012-05-14 14:08:54.136335996 +0200 +@@ -25,16 +25,31 @@ + + extern const FFPsyModel ff_aac_psy_model; + +-av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, +- int num_lens, +- const uint8_t **bands, const int* num_bands) ++av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, ++ const uint8_t **bands, const int* num_bands, ++ int num_groups, const uint8_t *group_map) + { ++ int i, j, k = 0; ++ + ctx->avctx = avctx; +- ctx->psy_bands = av_mallocz(sizeof(FFPsyBand) * PSY_MAX_BANDS * avctx->channels); ++ ctx->ch = av_mallocz(sizeof(ctx->ch[0]) * avctx->channels * 2); ++ ctx->group = av_mallocz(sizeof(ctx->group[0]) * num_groups); + ctx->bands = av_malloc (sizeof(ctx->bands[0]) * num_lens); + ctx->num_bands = av_malloc (sizeof(ctx->num_bands[0]) * num_lens); + memcpy(ctx->bands, bands, sizeof(ctx->bands[0]) * num_lens); + memcpy(ctx->num_bands, num_bands, sizeof(ctx->num_bands[0]) * num_lens); ++ ++ /* assign channels to groups (with virtual channels for coupling) */ ++ for (i = 0; i < num_groups; i++) { ++ /* NOTE: Add 1 to handle the AAC chan_config without modification. ++ * This has the side effect of allowing an array of 0s to map ++ * to one channel per group. ++ */ ++ ctx->group[i].num_ch = group_map[i] + 1; ++ for (j = 0; j < ctx->group[i].num_ch * 2; j++) ++ ctx->group[i].ch[j] = &ctx->ch[k++]; ++ } ++ + switch (ctx->avctx->codec_id) { + case CODEC_ID_AAC: + ctx->model = &ff_aac_psy_model; +@@ -45,17 +60,14 @@ + return 0; + } + +-FFPsyWindowInfo ff_psy_suggest_window(FFPsyContext *ctx, +- const int16_t *audio, const int16_t *la, +- int channel, int prev_type) ++FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel) + { +- return ctx->model->window(ctx, audio, la, channel, prev_type); +-} ++ int i = 0, ch = 0; + +-void ff_psy_set_band_info(FFPsyContext *ctx, int channel, +- const float *coeffs, const FFPsyWindowInfo *wi) +-{ +- ctx->model->analyze(ctx, channel, coeffs, wi); ++ while (ch <= channel) ++ ch += ctx->group[i++].num_ch; ++ ++ return &ctx->group[i-1]; + } + + av_cold void ff_psy_end(FFPsyContext *ctx) +@@ -64,7 +76,8 @@ + ctx->model->end(ctx); + av_freep(&ctx->bands); + av_freep(&ctx->num_bands); +- av_freep(&ctx->psy_bands); ++ av_freep(&ctx->group); ++ av_freep(&ctx->ch); + } + + typedef struct FFPsyPreprocessContext{ +@@ -99,20 +112,15 @@ + return ctx; + } + +-void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, +- const int16_t *audio, int16_t *dest, +- int tag, int channels) ++void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels) + { +- int ch, i; ++ int ch; ++ int frame_size = ctx->avctx->frame_size; ++ + if (ctx->fstate) { + for (ch = 0; ch < channels; ch++) +- ff_iir_filter(ctx->fcoeffs, ctx->fstate[tag+ch], ctx->avctx->frame_size, +- audio + ch, ctx->avctx->channels, +- dest + ch, ctx->avctx->channels); +- } else { +- for (ch = 0; ch < channels; ch++) +- for (i = 0; i < ctx->avctx->frame_size; i++) +- dest[i*ctx->avctx->channels + ch] = audio[i*ctx->avctx->channels + ch]; ++ ff_iir_filter_flt(ctx->fcoeffs, ctx->fstate[ch], frame_size, ++ &audio[ch][frame_size], 1, &audio[ch][frame_size], 1); + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/psymodel.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/psymodel.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/psymodel.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/psymodel.h 2012-05-14 14:08:54.137336017 +0200 +@@ -26,6 +26,8 @@ + + /** maximum possible number of bands */ + #define PSY_MAX_BANDS 128 ++/** maximum number of channels */ ++#define PSY_MAX_CHANS 20 + + /** + * single band psychoacoustic information +@@ -39,6 +41,23 @@ + } FFPsyBand; + + /** ++ * single channel psychoacoustic information ++ */ ++typedef struct FFPsyChannel { ++ FFPsyBand psy_bands[PSY_MAX_BANDS]; ///< channel bands information ++ float entropy; ///< total PE for this channel ++} FFPsyChannel; ++ ++/** ++ * psychoacoustic information for an arbitrary group of channels ++ */ ++typedef struct FFPsyChannelGroup { ++ FFPsyChannel *ch[PSY_MAX_CHANS]; ///< pointers to the individual channels in the group ++ uint8_t num_ch; ///< number of channels in this group ++ uint8_t coupling[PSY_MAX_BANDS]; ///< allow coupling for this band in the group ++} FFPsyChannelGroup; ++ ++/** + * windowing related information + */ + typedef struct FFPsyWindowInfo { +@@ -56,12 +75,19 @@ + AVCodecContext *avctx; ///< encoder context + const struct FFPsyModel *model; ///< encoder-specific model functions + +- FFPsyBand *psy_bands; ///< frame bands information ++ FFPsyChannel *ch; ///< single channel information ++ FFPsyChannelGroup *group; ///< channel group information ++ int num_groups; ///< number of channel groups + + uint8_t **bands; ///< scalefactor band sizes for possible frame sizes + int *num_bands; ///< number of scalefactor bands for possible frame sizes + int num_lens; ///< number of scalefactor band sets + ++ struct { ++ int size; ///< size of the bitresevoir in bits ++ int bits; ///< number of bits used in the bitresevoir ++ } bitres; ++ + void* model_priv_data; ///< psychoacoustic model implementation private data + } FFPsyContext; + +@@ -71,8 +97,30 @@ + typedef struct FFPsyModel { + const char *name; + int (*init) (FFPsyContext *apc); +- FFPsyWindowInfo (*window)(FFPsyContext *ctx, const int16_t *audio, const int16_t *la, int channel, int prev_type); +- void (*analyze)(FFPsyContext *ctx, int channel, const float *coeffs, const FFPsyWindowInfo *wi); ++ ++ /** ++ * Suggest window sequence for channel. ++ * ++ * @param ctx model context ++ * @param audio samples for the current frame ++ * @param la lookahead samples (NULL when unavailable) ++ * @param channel number of channel element to analyze ++ * @param prev_type previous window type ++ * ++ * @return suggested window information in a structure ++ */ ++ FFPsyWindowInfo (*window)(FFPsyContext *ctx, const float *audio, const float *la, int channel, int prev_type); ++ ++ /** ++ * Perform psychoacoustic analysis and set band info (threshold, energy) for a group of channels. ++ * ++ * @param ctx model context ++ * @param channel channel number of the first channel in the group to perform analysis on ++ * @param coeffs array of pointers to the transformed coefficients ++ * @param wi window information for the channels in the group ++ */ ++ void (*analyze)(FFPsyContext *ctx, int channel, const float **coeffs, const FFPsyWindowInfo *wi); ++ + void (*end) (FFPsyContext *apc); + } FFPsyModel; + +@@ -84,39 +132,24 @@ + * @param num_lens number of possible frame lengths + * @param bands scalefactor band lengths for all frame lengths + * @param num_bands number of scalefactor bands for all frame lengths ++ * @param num_groups number of channel groups ++ * @param group_map array with # of channels in group - 1, for each group + * + * @return zero if successful, a negative value if not + */ +-av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, +- int num_lens, +- const uint8_t **bands, const int* num_bands); ++av_cold int ff_psy_init(FFPsyContext *ctx, AVCodecContext *avctx, int num_lens, ++ const uint8_t **bands, const int* num_bands, ++ int num_groups, const uint8_t *group_map); + + /** +- * Suggest window sequence for channel. ++ * Determine what group a channel belongs to. + * +- * @param ctx model context +- * @param audio samples for the current frame +- * @param la lookahead samples (NULL when unavailable) +- * @param channel number of channel element to analyze +- * @param prev_type previous window type ++ * @param ctx psymodel context ++ * @param channel channel to locate the group for + * +- * @return suggested window information in a structure ++ * @return pointer to the FFPsyChannelGroup this channel belongs to + */ +-FFPsyWindowInfo ff_psy_suggest_window(FFPsyContext *ctx, +- const int16_t *audio, const int16_t *la, +- int channel, int prev_type); +- +- +-/** +- * Perform psychoacoustic analysis and set band info (threshold, energy). +- * +- * @param ctx model context +- * @param channel audio channel number +- * @param coeffs pointer to the transformed coefficients +- * @param wi window information +- */ +-void ff_psy_set_band_info(FFPsyContext *ctx, int channel, const float *coeffs, +- const FFPsyWindowInfo *wi); ++FFPsyChannelGroup *ff_psy_find_group(FFPsyContext *ctx, int channel); + + /** + * Cleanup model context at the end. +@@ -141,14 +174,10 @@ + * Preprocess several channel in audio frame in order to compress it better. + * + * @param ctx preprocessing context +- * @param audio samples to preprocess +- * @param dest place to put filtered samples +- * @param tag channel number +- * @param channels number of channel to preprocess (some additional work may be done on stereo pair) +- */ +-void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, +- const int16_t *audio, int16_t *dest, +- int tag, int channels); ++ * @param audio samples to be filtered (in place) ++ * @param channels number of channel to preprocess ++ */ ++void ff_psy_preprocess(struct FFPsyPreprocessContext *ctx, float **audio, int channels); + + /** + * Cleanup audio preprocessing module. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pthread.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pthread.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/pthread.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/pthread.c 2012-05-14 14:08:54.140336077 +0200 +@@ -1,5 +1,6 @@ + /* + * Copyright (c) 2004 Roman Shaposhnik ++ * Copyright (c) 2008 Alexander Strange (astrange@ithinksw.com) + * + * Many thanks to Steven M. Schultz for providing clever ideas and + * to Michael Niedermayer for writing initial +@@ -21,9 +22,45 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +-#include ++ ++/** ++ * @file ++ * Multithreading support functions ++ * @see doc/multithreading.txt ++ */ ++ ++#include "config.h" ++ ++#if HAVE_SCHED_GETAFFINITY ++#define _GNU_SOURCE ++#include ++#endif ++#if HAVE_GETPROCESSAFFINITYMASK ++#include ++#endif ++#if HAVE_SYSCTL ++#if HAVE_SYS_PARAM_H ++#include ++#endif ++#include ++#include ++#include ++#endif ++#if HAVE_SYSCONF ++#include ++#endif + + #include "avcodec.h" ++#include "internal.h" ++#include "thread.h" ++ ++#if HAVE_PTHREADS ++#include ++#elif HAVE_W32THREADS ++#include "w32pthreads.h" ++#elif HAVE_OS2THREADS ++#include "os2threads.h" ++#endif + + typedef int (action_func)(AVCodecContext *c, void *arg); + typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr); +@@ -45,6 +82,122 @@ + int done; + } ThreadContext; + ++/// Max number of frame buffers that can be allocated when using frame threads. ++#define MAX_BUFFERS (32+1) ++ ++/** ++ * Context used by codec threads and stored in their AVCodecContext thread_opaque. ++ */ ++typedef struct PerThreadContext { ++ struct FrameThreadContext *parent; ++ ++ pthread_t thread; ++ int thread_init; ++ pthread_cond_t input_cond; ///< Used to wait for a new packet from the main thread. ++ pthread_cond_t progress_cond; ///< Used by child threads to wait for progress to change. ++ pthread_cond_t output_cond; ///< Used by the main thread to wait for frames to finish. ++ ++ pthread_mutex_t mutex; ///< Mutex used to protect the contents of the PerThreadContext. ++ pthread_mutex_t progress_mutex; ///< Mutex used to protect frame progress values and progress_cond. ++ ++ AVCodecContext *avctx; ///< Context used to decode packets passed to this thread. ++ ++ AVPacket avpkt; ///< Input packet (for decoding) or output (for encoding). ++ int allocated_buf_size; ///< Size allocated for avpkt.data ++ ++ AVFrame frame; ///< Output frame (for decoding) or input (for encoding). ++ int got_frame; ///< The output of got_picture_ptr from the last avcodec_decode_video() call. ++ int result; ///< The result of the last codec decode/encode() call. ++ ++ enum { ++ STATE_INPUT_READY, ///< Set when the thread is awaiting a packet. ++ STATE_SETTING_UP, ///< Set before the codec has called ff_thread_finish_setup(). ++ STATE_GET_BUFFER, /**< ++ * Set when the codec calls get_buffer(). ++ * State is returned to STATE_SETTING_UP afterwards. ++ */ ++ STATE_SETUP_FINISHED ///< Set after the codec has called ff_thread_finish_setup(). ++ } state; ++ ++ /** ++ * Array of frames passed to ff_thread_release_buffer(). ++ * Frames are released after all threads referencing them are finished. ++ */ ++ AVFrame released_buffers[MAX_BUFFERS]; ++ int num_released_buffers; ++ ++ /** ++ * Array of progress values used by ff_thread_get_buffer(). ++ */ ++ int progress[MAX_BUFFERS][2]; ++ uint8_t progress_used[MAX_BUFFERS]; ++ ++ AVFrame *requested_frame; ///< AVFrame the codec passed to get_buffer() ++} PerThreadContext; ++ ++/** ++ * Context stored in the client AVCodecContext thread_opaque. ++ */ ++typedef struct FrameThreadContext { ++ PerThreadContext *threads; ///< The contexts for each thread. ++ PerThreadContext *prev_thread; ///< The last thread submit_packet() was called on. ++ ++ pthread_mutex_t buffer_mutex; ///< Mutex used to protect get/release_buffer(). ++ ++ int next_decoding; ///< The next context to submit a packet to. ++ int next_finished; ///< The next context to return output from. ++ ++ int delaying; /**< ++ * Set for the first N packets, where N is the number of threads. ++ * While it is set, ff_thread_en/decode_frame won't return any results. ++ */ ++ ++ int die; ///< Set when threads should exit. ++} FrameThreadContext; ++ ++ ++/* H264 slice threading seems to be buggy with more than 16 threads, ++ * limit the number of threads to 16 for automatic detection */ ++#define MAX_AUTO_THREADS 16 ++ ++static int get_logical_cpus(AVCodecContext *avctx) ++{ ++ int ret, nb_cpus = 1; ++#if HAVE_SCHED_GETAFFINITY && defined(CPU_COUNT) ++ cpu_set_t cpuset; ++ ++ CPU_ZERO(&cpuset); ++ ++ ret = sched_getaffinity(0, sizeof(cpuset), &cpuset); ++ if (!ret) { ++ nb_cpus = CPU_COUNT(&cpuset); ++ } ++#elif HAVE_GETPROCESSAFFINITYMASK ++ DWORD_PTR proc_aff, sys_aff; ++ ret = GetProcessAffinityMask(GetCurrentProcess(), &proc_aff, &sys_aff); ++ if (ret) ++ nb_cpus = av_popcount64(proc_aff); ++#elif HAVE_SYSCTL && defined(HW_NCPU) ++ int mib[2] = { CTL_HW, HW_NCPU }; ++ size_t len = sizeof(nb_cpus); ++ ++ ret = sysctl(mib, 2, &nb_cpus, &len, NULL, 0); ++ if (ret == -1) ++ nb_cpus = 0; ++#elif HAVE_SYSCONF && defined(_SC_NPROC_ONLN) ++ nb_cpus = sysconf(_SC_NPROC_ONLN); ++#elif HAVE_SYSCONF && defined(_SC_NPROCESSORS_ONLN) ++ nb_cpus = sysconf(_SC_NPROCESSORS_ONLN); ++#endif ++ av_log(avctx, AV_LOG_DEBUG, "detected %d logical cores\n", nb_cpus); ++ ++ if (avctx->height) ++ nb_cpus = FFMIN(nb_cpus, (avctx->height+15)/16); ++ ++ return nb_cpus; ++} ++ ++ + static void* attribute_align_arg worker(void *v) + { + AVCodecContext *avctx = v; +@@ -84,7 +237,7 @@ + pthread_mutex_unlock(&c->current_job_lock); + } + +-void avcodec_thread_free(AVCodecContext *avctx) ++static void thread_free(AVCodecContext *avctx) + { + ThreadContext *c = avctx->thread_opaque; + int i; +@@ -109,6 +262,9 @@ + ThreadContext *c= avctx->thread_opaque; + int dummy_ret; + ++ if (!(avctx->active_thread_type&FF_THREAD_SLICE) || avctx->thread_count <= 1) ++ return avcodec_default_execute(avctx, func, arg, ret, job_count, job_size); ++ + if (job_count <= 0) + return 0; + +@@ -140,15 +296,25 @@ + return avcodec_thread_execute(avctx, NULL, arg, ret, job_count, 0); + } + +-int avcodec_thread_init(AVCodecContext *avctx, int thread_count) ++static int thread_init(AVCodecContext *avctx) + { + int i; + ThreadContext *c; ++ int thread_count = avctx->thread_count; + +- avctx->thread_count = thread_count; ++ if (!thread_count) { ++ int nb_cpus = get_logical_cpus(avctx); ++ // use number of cores + 1 as thread count if there is more than one ++ if (nb_cpus > 1) ++ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); ++ else ++ thread_count = avctx->thread_count = 1; ++ } + +- if (thread_count <= 1) ++ if (thread_count <= 1) { ++ avctx->active_thread_type = 0; + return 0; ++ } + + c = av_mallocz(sizeof(ThreadContext)); + if (!c) +@@ -173,7 +339,7 @@ + if(pthread_create(&c->workers[i], NULL, worker, avctx)) { + avctx->thread_count = i; + pthread_mutex_unlock(&c->current_job_lock); +- avcodec_thread_free(avctx); ++ ff_thread_free(avctx); + return -1; + } + } +@@ -184,3 +350,722 @@ + avctx->execute2 = avcodec_thread_execute2; + return 0; + } ++ ++/** ++ * Codec worker thread. ++ * ++ * Automatically calls ff_thread_finish_setup() if the codec does ++ * not provide an update_thread_context method, or if the codec returns ++ * before calling it. ++ */ ++static attribute_align_arg void *frame_worker_thread(void *arg) ++{ ++ PerThreadContext *p = arg; ++ FrameThreadContext *fctx = p->parent; ++ AVCodecContext *avctx = p->avctx; ++ AVCodec *codec = avctx->codec; ++ ++ while (1) { ++ int i; ++ if (p->state == STATE_INPUT_READY && !fctx->die) { ++ pthread_mutex_lock(&p->mutex); ++ while (p->state == STATE_INPUT_READY && !fctx->die) ++ pthread_cond_wait(&p->input_cond, &p->mutex); ++ pthread_mutex_unlock(&p->mutex); ++ } ++ ++ if (fctx->die) break; ++ ++ if (!codec->update_thread_context && (avctx->thread_safe_callbacks || avctx->get_buffer == avcodec_default_get_buffer)) ++ ff_thread_finish_setup(avctx); ++ ++ pthread_mutex_lock(&p->mutex); ++ avcodec_get_frame_defaults(&p->frame); ++ p->got_frame = 0; ++ p->result = codec->decode(avctx, &p->frame, &p->got_frame, &p->avpkt); ++ ++ if (p->state == STATE_SETTING_UP) ff_thread_finish_setup(avctx); ++ ++ p->state = STATE_INPUT_READY; ++ ++ pthread_mutex_lock(&p->progress_mutex); ++ for (i = 0; i < MAX_BUFFERS; i++) ++ if (p->progress_used[i] && (p->got_frame || p->result<0 || avctx->codec_id != CODEC_ID_H264)) { ++ p->progress[i][0] = INT_MAX; ++ p->progress[i][1] = INT_MAX; ++ } ++ pthread_cond_broadcast(&p->progress_cond); ++ pthread_cond_signal(&p->output_cond); ++ pthread_mutex_unlock(&p->progress_mutex); ++ ++ pthread_mutex_unlock(&p->mutex); ++ } ++ ++ return NULL; ++} ++ ++/** ++ * Update the next thread's AVCodecContext with values from the reference thread's context. ++ * ++ * @param dst The destination context. ++ * @param src The source context. ++ * @param for_user 0 if the destination is a codec thread, 1 if the destination is the user's thread ++ */ ++static int update_context_from_thread(AVCodecContext *dst, AVCodecContext *src, int for_user) ++{ ++ int err = 0; ++ ++ if (dst != src) { ++ dst->sub_id = src->sub_id; ++ dst->time_base = src->time_base; ++ dst->width = src->width; ++ dst->height = src->height; ++ dst->pix_fmt = src->pix_fmt; ++ ++ dst->coded_width = src->coded_width; ++ dst->coded_height = src->coded_height; ++ ++ dst->has_b_frames = src->has_b_frames; ++ dst->idct_algo = src->idct_algo; ++ ++ dst->bits_per_coded_sample = src->bits_per_coded_sample; ++ dst->sample_aspect_ratio = src->sample_aspect_ratio; ++ dst->dtg_active_format = src->dtg_active_format; ++ ++ dst->profile = src->profile; ++ dst->level = src->level; ++ ++ dst->bits_per_raw_sample = src->bits_per_raw_sample; ++ dst->ticks_per_frame = src->ticks_per_frame; ++ dst->color_primaries = src->color_primaries; ++ ++ dst->color_trc = src->color_trc; ++ dst->colorspace = src->colorspace; ++ dst->color_range = src->color_range; ++ dst->chroma_sample_location = src->chroma_sample_location; ++ } ++ ++ if (for_user) { ++ dst->delay = src->thread_count - 1; ++ dst->coded_frame = src->coded_frame; ++ } else { ++ if (dst->codec->update_thread_context) ++ err = dst->codec->update_thread_context(dst, src); ++ } ++ ++ return err; ++} ++ ++/** ++ * Update the next thread's AVCodecContext with values set by the user. ++ * ++ * @param dst The destination context. ++ * @param src The source context. ++ * @return 0 on success, negative error code on failure ++ */ ++static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src) ++{ ++#define copy_fields(s, e) memcpy(&dst->s, &src->s, (char*)&dst->e - (char*)&dst->s); ++ dst->flags = src->flags; ++ ++ dst->draw_horiz_band= src->draw_horiz_band; ++ dst->get_buffer = src->get_buffer; ++ dst->release_buffer = src->release_buffer; ++ ++ dst->opaque = src->opaque; ++ dst->dsp_mask = src->dsp_mask; ++ dst->debug = src->debug; ++ dst->debug_mv = src->debug_mv; ++ ++ dst->slice_flags = src->slice_flags; ++ dst->flags2 = src->flags2; ++ ++ copy_fields(skip_loop_filter, bidir_refine); ++ ++ dst->frame_number = src->frame_number; ++ dst->reordered_opaque = src->reordered_opaque; ++ dst->thread_safe_callbacks = src->thread_safe_callbacks; ++ ++ if (src->slice_count && src->slice_offset) { ++ if (dst->slice_count < src->slice_count) { ++ int *tmp = av_realloc(dst->slice_offset, src->slice_count * ++ sizeof(*dst->slice_offset)); ++ if (!tmp) { ++ av_free(dst->slice_offset); ++ return AVERROR(ENOMEM); ++ } ++ dst->slice_offset = tmp; ++ } ++ memcpy(dst->slice_offset, src->slice_offset, ++ src->slice_count * sizeof(*dst->slice_offset)); ++ } ++ dst->slice_count = src->slice_count; ++ return 0; ++#undef copy_fields ++} ++ ++static void free_progress(AVFrame *f) ++{ ++ PerThreadContext *p = f->owner->thread_opaque; ++ int *progress = f->thread_opaque; ++ ++ p->progress_used[(progress - p->progress[0]) / 2] = 0; ++} ++ ++/// Releases the buffers that this decoding thread was the last user of. ++static void release_delayed_buffers(PerThreadContext *p) ++{ ++ FrameThreadContext *fctx = p->parent; ++ ++ while (p->num_released_buffers > 0) { ++ AVFrame *f; ++ ++ pthread_mutex_lock(&fctx->buffer_mutex); ++ f = &p->released_buffers[--p->num_released_buffers]; ++ free_progress(f); ++ f->thread_opaque = NULL; ++ ++ f->owner->release_buffer(f->owner, f); ++ pthread_mutex_unlock(&fctx->buffer_mutex); ++ } ++} ++ ++static int submit_packet(PerThreadContext *p, AVPacket *avpkt) ++{ ++ FrameThreadContext *fctx = p->parent; ++ PerThreadContext *prev_thread = fctx->prev_thread; ++ AVCodec *codec = p->avctx->codec; ++ uint8_t *buf = p->avpkt.data; ++ ++ if (!avpkt->size && !(codec->capabilities & CODEC_CAP_DELAY)) return 0; ++ ++ pthread_mutex_lock(&p->mutex); ++ ++ release_delayed_buffers(p); ++ ++ if (prev_thread) { ++ int err; ++ if (prev_thread->state == STATE_SETTING_UP) { ++ pthread_mutex_lock(&prev_thread->progress_mutex); ++ while (prev_thread->state == STATE_SETTING_UP) ++ pthread_cond_wait(&prev_thread->progress_cond, &prev_thread->progress_mutex); ++ pthread_mutex_unlock(&prev_thread->progress_mutex); ++ } ++ ++ err = update_context_from_thread(p->avctx, prev_thread->avctx, 0); ++ if (err) { ++ pthread_mutex_unlock(&p->mutex); ++ return err; ++ } ++ } ++ ++ av_fast_malloc(&buf, &p->allocated_buf_size, avpkt->size + FF_INPUT_BUFFER_PADDING_SIZE); ++ p->avpkt = *avpkt; ++ p->avpkt.data = buf; ++ memcpy(buf, avpkt->data, avpkt->size); ++ memset(buf + avpkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); ++ ++ p->state = STATE_SETTING_UP; ++ pthread_cond_signal(&p->input_cond); ++ pthread_mutex_unlock(&p->mutex); ++ ++ /* ++ * If the client doesn't have a thread-safe get_buffer(), ++ * then decoding threads call back to the main thread, ++ * and it calls back to the client here. ++ */ ++ ++ if (!p->avctx->thread_safe_callbacks && ++ p->avctx->get_buffer != avcodec_default_get_buffer) { ++ while (p->state != STATE_SETUP_FINISHED && p->state != STATE_INPUT_READY) { ++ pthread_mutex_lock(&p->progress_mutex); ++ while (p->state == STATE_SETTING_UP) ++ pthread_cond_wait(&p->progress_cond, &p->progress_mutex); ++ ++ if (p->state == STATE_GET_BUFFER) { ++ p->result = p->avctx->get_buffer(p->avctx, p->requested_frame); ++ p->state = STATE_SETTING_UP; ++ pthread_cond_signal(&p->progress_cond); ++ } ++ pthread_mutex_unlock(&p->progress_mutex); ++ } ++ } ++ ++ fctx->prev_thread = p; ++ fctx->next_decoding++; ++ ++ return 0; ++} ++ ++int ff_thread_decode_frame(AVCodecContext *avctx, ++ AVFrame *picture, int *got_picture_ptr, ++ AVPacket *avpkt) ++{ ++ FrameThreadContext *fctx = avctx->thread_opaque; ++ int finished = fctx->next_finished; ++ PerThreadContext *p; ++ int err; ++ ++ /* ++ * Submit a packet to the next decoding thread. ++ */ ++ ++ p = &fctx->threads[fctx->next_decoding]; ++ err = update_context_from_user(p->avctx, avctx); ++ if (err) return err; ++ err = submit_packet(p, avpkt); ++ if (err) return err; ++ ++ /* ++ * If we're still receiving the initial packets, don't return a frame. ++ */ ++ ++ if (fctx->delaying && avpkt->size) { ++ if (fctx->next_decoding >= (avctx->thread_count-1)) fctx->delaying = 0; ++ ++ *got_picture_ptr=0; ++ return avpkt->size; ++ } ++ ++ /* ++ * Return the next available frame from the oldest thread. ++ * If we're at the end of the stream, then we have to skip threads that ++ * didn't output a frame, because we don't want to accidentally signal ++ * EOF (avpkt->size == 0 && *got_picture_ptr == 0). ++ */ ++ ++ do { ++ p = &fctx->threads[finished++]; ++ ++ if (p->state != STATE_INPUT_READY) { ++ pthread_mutex_lock(&p->progress_mutex); ++ while (p->state != STATE_INPUT_READY) ++ pthread_cond_wait(&p->output_cond, &p->progress_mutex); ++ pthread_mutex_unlock(&p->progress_mutex); ++ } ++ ++ *picture = p->frame; ++ *got_picture_ptr = p->got_frame; ++ picture->pkt_dts = p->avpkt.dts; ++ picture->sample_aspect_ratio = avctx->sample_aspect_ratio; ++ picture->width = avctx->width; ++ picture->height = avctx->height; ++ picture->format = avctx->pix_fmt; ++ ++ /* ++ * A later call with avkpt->size == 0 may loop over all threads, ++ * including this one, searching for a frame to return before being ++ * stopped by the "finished != fctx->next_finished" condition. ++ * Make sure we don't mistakenly return the same frame again. ++ */ ++ p->got_frame = 0; ++ ++ if (finished >= avctx->thread_count) finished = 0; ++ } while (!avpkt->size && !*got_picture_ptr && finished != fctx->next_finished); ++ ++ update_context_from_thread(avctx, p->avctx, 1); ++ ++ if (fctx->next_decoding >= avctx->thread_count) fctx->next_decoding = 0; ++ ++ fctx->next_finished = finished; ++ ++ /* return the size of the consumed packet if no error occurred */ ++ return (p->result >= 0) ? avpkt->size : p->result; ++} ++ ++void ff_thread_report_progress(AVFrame *f, int n, int field) ++{ ++ PerThreadContext *p; ++ int *progress = f->thread_opaque; ++ ++ if (!progress || progress[field] >= n) return; ++ ++ p = f->owner->thread_opaque; ++ ++ if (f->owner->debug&FF_DEBUG_THREADS) ++ av_log(f->owner, AV_LOG_DEBUG, "%p finished %d field %d\n", progress, n, field); ++ ++ pthread_mutex_lock(&p->progress_mutex); ++ progress[field] = n; ++ pthread_cond_broadcast(&p->progress_cond); ++ pthread_mutex_unlock(&p->progress_mutex); ++} ++ ++void ff_thread_await_progress(AVFrame *f, int n, int field) ++{ ++ PerThreadContext *p; ++ int *progress = f->thread_opaque; ++ ++ if (!progress || progress[field] >= n) return; ++ ++ p = f->owner->thread_opaque; ++ ++ if (f->owner->debug&FF_DEBUG_THREADS) ++ av_log(f->owner, AV_LOG_DEBUG, "thread awaiting %d field %d from %p\n", n, field, progress); ++ ++ pthread_mutex_lock(&p->progress_mutex); ++ while (progress[field] < n) ++ pthread_cond_wait(&p->progress_cond, &p->progress_mutex); ++ pthread_mutex_unlock(&p->progress_mutex); ++} ++ ++void ff_thread_finish_setup(AVCodecContext *avctx) { ++ PerThreadContext *p = avctx->thread_opaque; ++ ++ if (!(avctx->active_thread_type&FF_THREAD_FRAME)) return; ++ ++ if(p->state == STATE_SETUP_FINISHED){ ++ av_log(avctx, AV_LOG_WARNING, "Multiple ff_thread_finish_setup() calls\n"); ++ } ++ ++ pthread_mutex_lock(&p->progress_mutex); ++ p->state = STATE_SETUP_FINISHED; ++ pthread_cond_broadcast(&p->progress_cond); ++ pthread_mutex_unlock(&p->progress_mutex); ++} ++ ++/// Waits for all threads to finish. ++static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count) ++{ ++ int i; ++ ++ for (i = 0; i < thread_count; i++) { ++ PerThreadContext *p = &fctx->threads[i]; ++ ++ if (p->state != STATE_INPUT_READY) { ++ pthread_mutex_lock(&p->progress_mutex); ++ while (p->state != STATE_INPUT_READY) ++ pthread_cond_wait(&p->output_cond, &p->progress_mutex); ++ pthread_mutex_unlock(&p->progress_mutex); ++ } ++ p->got_frame = 0; ++ } ++} ++ ++static void frame_thread_free(AVCodecContext *avctx, int thread_count) ++{ ++ FrameThreadContext *fctx = avctx->thread_opaque; ++ AVCodec *codec = avctx->codec; ++ int i; ++ ++ park_frame_worker_threads(fctx, thread_count); ++ ++ if (fctx->prev_thread && fctx->prev_thread != fctx->threads) ++ update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0); ++ ++ fctx->die = 1; ++ ++ for (i = 0; i < thread_count; i++) { ++ PerThreadContext *p = &fctx->threads[i]; ++ ++ pthread_mutex_lock(&p->mutex); ++ pthread_cond_signal(&p->input_cond); ++ pthread_mutex_unlock(&p->mutex); ++ ++ if (p->thread_init) ++ pthread_join(p->thread, NULL); ++ p->thread_init=0; ++ ++ if (codec->close) ++ codec->close(p->avctx); ++ ++ avctx->codec = NULL; ++ ++ release_delayed_buffers(p); ++ } ++ ++ for (i = 0; i < thread_count; i++) { ++ PerThreadContext *p = &fctx->threads[i]; ++ ++ avcodec_default_free_buffers(p->avctx); ++ ++ pthread_mutex_destroy(&p->mutex); ++ pthread_mutex_destroy(&p->progress_mutex); ++ pthread_cond_destroy(&p->input_cond); ++ pthread_cond_destroy(&p->progress_cond); ++ pthread_cond_destroy(&p->output_cond); ++ av_freep(&p->avpkt.data); ++ ++ if (i) { ++ av_freep(&p->avctx->priv_data); ++ av_freep(&p->avctx->internal); ++ av_freep(&p->avctx->slice_offset); ++ } ++ ++ av_freep(&p->avctx); ++ } ++ ++ av_freep(&fctx->threads); ++ pthread_mutex_destroy(&fctx->buffer_mutex); ++ av_freep(&avctx->thread_opaque); ++} ++ ++static int frame_thread_init(AVCodecContext *avctx) ++{ ++ int thread_count = avctx->thread_count; ++ AVCodec *codec = avctx->codec; ++ AVCodecContext *src = avctx; ++ FrameThreadContext *fctx; ++ int i, err = 0; ++ ++ if (!thread_count) { ++ int nb_cpus = get_logical_cpus(avctx); ++ if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) || avctx->debug_mv) ++ nb_cpus = 1; ++ // use number of cores + 1 as thread count if there is more than one ++ if (nb_cpus > 1) ++ thread_count = avctx->thread_count = FFMIN(nb_cpus + 1, MAX_AUTO_THREADS); ++ else ++ thread_count = avctx->thread_count = 1; ++ } ++ ++ if (thread_count <= 1) { ++ avctx->active_thread_type = 0; ++ return 0; ++ } ++ ++ avctx->thread_opaque = fctx = av_mallocz(sizeof(FrameThreadContext)); ++ ++ fctx->threads = av_mallocz(sizeof(PerThreadContext) * thread_count); ++ pthread_mutex_init(&fctx->buffer_mutex, NULL); ++ fctx->delaying = 1; ++ ++ for (i = 0; i < thread_count; i++) { ++ AVCodecContext *copy = av_malloc(sizeof(AVCodecContext)); ++ PerThreadContext *p = &fctx->threads[i]; ++ ++ pthread_mutex_init(&p->mutex, NULL); ++ pthread_mutex_init(&p->progress_mutex, NULL); ++ pthread_cond_init(&p->input_cond, NULL); ++ pthread_cond_init(&p->progress_cond, NULL); ++ pthread_cond_init(&p->output_cond, NULL); ++ ++ p->parent = fctx; ++ p->avctx = copy; ++ ++ if (!copy) { ++ err = AVERROR(ENOMEM); ++ goto error; ++ } ++ ++ *copy = *src; ++ copy->thread_opaque = p; ++ copy->pkt = &p->avpkt; ++ ++ if (!i) { ++ src = copy; ++ ++ if (codec->init) ++ err = codec->init(copy); ++ ++ update_context_from_thread(avctx, copy, 1); ++ } else { ++ copy->priv_data = av_malloc(codec->priv_data_size); ++ if (!copy->priv_data) { ++ err = AVERROR(ENOMEM); ++ goto error; ++ } ++ memcpy(copy->priv_data, src->priv_data, codec->priv_data_size); ++ copy->internal = av_malloc(sizeof(AVCodecInternal)); ++ if (!copy->internal) { ++ err = AVERROR(ENOMEM); ++ goto error; ++ } ++ *copy->internal = *src->internal; ++ copy->internal->is_copy = 1; ++ ++ if (codec->init_thread_copy) ++ err = codec->init_thread_copy(copy); ++ } ++ ++ if (err) goto error; ++ ++ p->thread_init= !pthread_create(&p->thread, NULL, frame_worker_thread, p); ++ if(!p->thread_init) ++ goto error; ++ } ++ ++ return 0; ++ ++error: ++ frame_thread_free(avctx, i+1); ++ ++ return err; ++} ++ ++void ff_thread_flush(AVCodecContext *avctx) ++{ ++ FrameThreadContext *fctx = avctx->thread_opaque; ++ ++ if (!avctx->thread_opaque) return; ++ ++ park_frame_worker_threads(fctx, avctx->thread_count); ++ if (fctx->prev_thread) { ++ if (fctx->prev_thread != &fctx->threads[0]) ++ update_context_from_thread(fctx->threads[0].avctx, fctx->prev_thread->avctx, 0); ++ if (avctx->codec->flush) ++ avctx->codec->flush(fctx->threads[0].avctx); ++ } ++ ++ fctx->next_decoding = fctx->next_finished = 0; ++ fctx->delaying = 1; ++ fctx->prev_thread = NULL; ++} ++ ++static int *allocate_progress(PerThreadContext *p) ++{ ++ int i; ++ ++ for (i = 0; i < MAX_BUFFERS; i++) ++ if (!p->progress_used[i]) break; ++ ++ if (i == MAX_BUFFERS) { ++ av_log(p->avctx, AV_LOG_ERROR, "allocate_progress() overflow\n"); ++ return NULL; ++ } ++ ++ p->progress_used[i] = 1; ++ ++ return p->progress[i]; ++} ++ ++int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f) ++{ ++ PerThreadContext *p = avctx->thread_opaque; ++ int *progress, err; ++ ++ f->owner = avctx; ++ ++ ff_init_buffer_info(avctx, f); ++ ++ if (!(avctx->active_thread_type&FF_THREAD_FRAME)) { ++ f->thread_opaque = NULL; ++ return avctx->get_buffer(avctx, f); ++ } ++ ++ if (p->state != STATE_SETTING_UP && ++ (avctx->codec->update_thread_context || (!avctx->thread_safe_callbacks && ++ avctx->get_buffer != avcodec_default_get_buffer))) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() cannot be called after ff_thread_finish_setup()\n"); ++ return -1; ++ } ++ ++ pthread_mutex_lock(&p->parent->buffer_mutex); ++ f->thread_opaque = progress = allocate_progress(p); ++ ++ if (!progress) { ++ pthread_mutex_unlock(&p->parent->buffer_mutex); ++ return -1; ++ } ++ ++ progress[0] = ++ progress[1] = -1; ++ ++ if (avctx->thread_safe_callbacks || ++ avctx->get_buffer == avcodec_default_get_buffer) { ++ err = avctx->get_buffer(avctx, f); ++ } else { ++ p->requested_frame = f; ++ p->state = STATE_GET_BUFFER; ++ pthread_mutex_lock(&p->progress_mutex); ++ pthread_cond_broadcast(&p->progress_cond); ++ ++ while (p->state != STATE_SETTING_UP) ++ pthread_cond_wait(&p->progress_cond, &p->progress_mutex); ++ ++ err = p->result; ++ ++ pthread_mutex_unlock(&p->progress_mutex); ++ ++ if (!avctx->codec->update_thread_context) ++ ff_thread_finish_setup(avctx); ++ } ++ ++ pthread_mutex_unlock(&p->parent->buffer_mutex); ++ ++ return err; ++} ++ ++void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f) ++{ ++ PerThreadContext *p = avctx->thread_opaque; ++ FrameThreadContext *fctx; ++ ++ if (!(avctx->active_thread_type&FF_THREAD_FRAME)) { ++ avctx->release_buffer(avctx, f); ++ return; ++ } ++ ++ if (p->num_released_buffers >= MAX_BUFFERS) { ++ av_log(p->avctx, AV_LOG_ERROR, "too many thread_release_buffer calls!\n"); ++ return; ++ } ++ ++ if(avctx->debug & FF_DEBUG_BUFFERS) ++ av_log(avctx, AV_LOG_DEBUG, "thread_release_buffer called on pic %p\n", f); ++ ++ fctx = p->parent; ++ pthread_mutex_lock(&fctx->buffer_mutex); ++ p->released_buffers[p->num_released_buffers++] = *f; ++ pthread_mutex_unlock(&fctx->buffer_mutex); ++ memset(f->data, 0, sizeof(f->data)); ++} ++ ++/** ++ * Set the threading algorithms used. ++ * ++ * Threading requires more than one thread. ++ * Frame threading requires entire frames to be passed to the codec, ++ * and introduces extra decoding delay, so is incompatible with low_delay. ++ * ++ * @param avctx The context. ++ */ ++static void validate_thread_parameters(AVCodecContext *avctx) ++{ ++ int frame_threading_supported = (avctx->codec->capabilities & CODEC_CAP_FRAME_THREADS) ++ && !(avctx->flags & CODEC_FLAG_TRUNCATED) ++ && !(avctx->flags & CODEC_FLAG_LOW_DELAY) ++ && !(avctx->flags2 & CODEC_FLAG2_CHUNKS); ++ if (avctx->thread_count == 1) { ++ avctx->active_thread_type = 0; ++ } else if (frame_threading_supported && (avctx->thread_type & FF_THREAD_FRAME)) { ++ avctx->active_thread_type = FF_THREAD_FRAME; ++ } else if (avctx->codec->capabilities & CODEC_CAP_SLICE_THREADS && ++ avctx->thread_type & FF_THREAD_SLICE) { ++ avctx->active_thread_type = FF_THREAD_SLICE; ++ } else if (!(avctx->codec->capabilities & CODEC_CAP_AUTO_THREADS)) { ++ avctx->thread_count = 1; ++ avctx->active_thread_type = 0; ++ } ++} ++ ++int ff_thread_init(AVCodecContext *avctx) ++{ ++ if (avctx->thread_opaque) { ++ av_log(avctx, AV_LOG_ERROR, "avcodec_thread_init is ignored after avcodec_open\n"); ++ return -1; ++ } ++ ++#if HAVE_W32THREADS ++ w32thread_init(); ++#endif ++ ++ if (avctx->codec) { ++ validate_thread_parameters(avctx); ++ ++ if (avctx->active_thread_type&FF_THREAD_SLICE) ++ return thread_init(avctx); ++ else if (avctx->active_thread_type&FF_THREAD_FRAME) ++ return frame_thread_init(avctx); ++ } ++ ++ return 0; ++} ++ ++void ff_thread_free(AVCodecContext *avctx) ++{ ++ if (avctx->active_thread_type&FF_THREAD_FRAME) ++ frame_thread_free(avctx, avctx->thread_count); ++ else ++ thread_free(avctx); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ptx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ptx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ptx.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ptx.c 2012-05-14 14:08:54.141336097 +0200 +@@ -20,7 +20,7 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + typedef struct PTXContext { +@@ -39,26 +39,31 @@ + static int ptx_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) { + const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + PTXContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + unsigned int offset, w, h, y, stride, bytes_per_pixel; + uint8_t *ptr; + ++ if (buf_end - buf < 14) ++ return AVERROR_INVALIDDATA; + offset = AV_RL16(buf); + w = AV_RL16(buf+8); + h = AV_RL16(buf+10); + bytes_per_pixel = AV_RL16(buf+12) >> 3; + + if (bytes_per_pixel != 2) { +- av_log(avctx, AV_LOG_ERROR, "image format is not rgb15, please report on ffmpeg-users mailing list\n"); ++ av_log_ask_for_sample(avctx, "Image format is not RGB15.\n"); + return -1; + } + + avctx->pix_fmt = PIX_FMT_RGB555; + ++ if (buf_end - buf < offset) ++ return AVERROR_INVALIDDATA; + if (offset != 0x2c) +- av_log(avctx, AV_LOG_WARNING, "offset != 0x2c, untested due to lack of sample files\n"); ++ av_log_ask_for_sample(avctx, "offset != 0x2c\n"); + + buf += offset; + +@@ -74,12 +79,12 @@ + return -1; + } + +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + + ptr = p->data[0]; + stride = p->linesize[0]; + +- for (y=0; y= w * bytes_per_pixel; y++) { + #if HAVE_BIGENDIAN + unsigned int x; + for (x=0; xpicture; + *data_size = sizeof(AVPicture); + ++ if (y < h) { ++ av_log(avctx, AV_LOG_WARNING, "incomplete packet\n"); ++ return avpkt->size; ++ } ++ + return offset + w*h*bytes_per_pixel; + } + +@@ -107,15 +117,13 @@ + } + + AVCodec ff_ptx_decoder = { +- "ptx", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_PTX, +- sizeof(PTXContext), +- ptx_init, +- NULL, +- ptx_end, +- ptx_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "ptx", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_PTX, ++ .priv_data_size = sizeof(PTXContext), ++ .init = ptx_init, ++ .close = ptx_end, ++ .decode = ptx_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("V.Flash PTX image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/put_bits.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/put_bits.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/put_bits.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/put_bits.h 2012-05-14 14:08:54.142336117 +0200 +@@ -34,20 +34,12 @@ + #include "libavutil/intreadwrite.h" + #include "libavutil/log.h" + #include "mathops.h" ++#include "config.h" + +-//#define ALT_BITSTREAM_WRITER +-//#define ALIGNED_BITSTREAM_WRITER +- +-/* buf and buf_end must be present and used by every alternative writer. */ + typedef struct PutBitContext { +-#ifdef ALT_BITSTREAM_WRITER +- uint8_t *buf, *buf_end; +- int index; +-#else + uint32_t bit_buf; + int bit_left; + uint8_t *buf, *buf_ptr, *buf_end; +-#endif + int size_in_bits; + } PutBitContext; + +@@ -67,15 +59,9 @@ + s->size_in_bits= 8*buffer_size; + s->buf = buffer; + s->buf_end = s->buf + buffer_size; +-#ifdef ALT_BITSTREAM_WRITER +- s->index=0; +- ((uint32_t*)(s->buf))[0]=0; +-// memset(buffer, 0, buffer_size); +-#else + s->buf_ptr = s->buf; + s->bit_left=32; + s->bit_buf=0; +-#endif + } + + /** +@@ -83,11 +69,7 @@ + */ + static inline int put_bits_count(PutBitContext *s) + { +-#ifdef ALT_BITSTREAM_WRITER +- return s->index; +-#else + return (s->buf_ptr - s->buf) * 8 + 32 - s->bit_left; +-#endif + } + + /** +@@ -95,11 +77,9 @@ + */ + static inline void flush_put_bits(PutBitContext *s) + { +-#ifdef ALT_BITSTREAM_WRITER +- align_put_bits(s); +-#else + #ifndef BITSTREAM_WRITER_LE +- s->bit_buf<<= s->bit_left; ++ if (s->bit_left < 32) ++ s->bit_buf<<= s->bit_left; + #endif + while (s->bit_left < 32) { + /* XXX: should test end of buffer */ +@@ -114,18 +94,17 @@ + } + s->bit_left=32; + s->bit_buf=0; +-#endif + } + +-#if defined(ALT_BITSTREAM_WRITER) || defined(BITSTREAM_WRITER_LE) +-#define align_put_bits align_put_bits_unsupported_here ++#ifdef BITSTREAM_WRITER_LE ++#define avpriv_align_put_bits align_put_bits_unsupported_here + #define ff_put_string ff_put_string_unsupported_here +-#define ff_copy_bits ff_copy_bits_unsupported_here ++#define avpriv_copy_bits avpriv_copy_bits_unsupported_here + #else + /** + * Pad the bitstream with zeros up to the next byte boundary. + */ +-void align_put_bits(PutBitContext *s); ++void avpriv_align_put_bits(PutBitContext *s); + + /** + * Put the string string in the bitstream. +@@ -139,7 +118,7 @@ + * + * @param length the number of bits of src to copy + */ +-void ff_copy_bits(PutBitContext *pb, const uint8_t *src, int length); ++void avpriv_copy_bits(PutBitContext *pb, const uint8_t *src, int length); + #endif + + /** +@@ -147,7 +126,6 @@ + * Use put_bits32 to write 32 bits. + */ + static inline void put_bits(PutBitContext *s, int n, unsigned int value) +-#ifndef ALT_BITSTREAM_WRITER + { + unsigned int bit_buf; + int bit_left; +@@ -163,12 +141,7 @@ + #ifdef BITSTREAM_WRITER_LE + bit_buf |= value << (32 - bit_left); + if (n >= bit_left) { +-#if !HAVE_FAST_UNALIGNED +- if (3 & (intptr_t) s->buf_ptr) { +- AV_WL32(s->buf_ptr, bit_buf); +- } else +-#endif +- *(uint32_t *)s->buf_ptr = av_le2ne32(bit_buf); ++ AV_WL32(s->buf_ptr, bit_buf); + s->buf_ptr+=4; + bit_buf = (bit_left==32)?0:value >> bit_left; + bit_left+=32; +@@ -181,12 +154,7 @@ + } else { + bit_buf<<=bit_left; + bit_buf |= value >> (n - bit_left); +-#if !HAVE_FAST_UNALIGNED +- if (3 & (intptr_t) s->buf_ptr) { +- AV_WB32(s->buf_ptr, bit_buf); +- } else +-#endif +- *(uint32_t *)s->buf_ptr = av_be2ne32(bit_buf); ++ AV_WB32(s->buf_ptr, bit_buf); + //printf("bitbuf = %08x\n", bit_buf); + s->buf_ptr+=4; + bit_left+=32 - n; +@@ -197,70 +165,6 @@ + s->bit_buf = bit_buf; + s->bit_left = bit_left; + } +-#else /* ALT_BITSTREAM_WRITER defined */ +-{ +-# ifdef ALIGNED_BITSTREAM_WRITER +-# if ARCH_X86 +- __asm__ volatile( +- "movl %0, %%ecx \n\t" +- "xorl %%eax, %%eax \n\t" +- "shrdl %%cl, %1, %%eax \n\t" +- "shrl %%cl, %1 \n\t" +- "movl %0, %%ecx \n\t" +- "shrl $3, %%ecx \n\t" +- "andl $0xFFFFFFFC, %%ecx \n\t" +- "bswapl %1 \n\t" +- "orl %1, (%2, %%ecx) \n\t" +- "bswapl %%eax \n\t" +- "addl %3, %0 \n\t" +- "movl %%eax, 4(%2, %%ecx) \n\t" +- : "=&r" (s->index), "=&r" (value) +- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value<<(-n)) +- : "%eax", "%ecx" +- ); +-# else +- int index= s->index; +- uint32_t *ptr= ((uint32_t *)s->buf)+(index>>5); +- +- value<<= 32-n; +- +- ptr[0] |= av_be2ne32(value>>(index&31)); +- ptr[1] = av_be2ne32(value<<(32-(index&31))); +-//if(n>24) printf("%d %d\n", n, value); +- index+= n; +- s->index= index; +-# endif +-# else //ALIGNED_BITSTREAM_WRITER +-# if ARCH_X86 +- __asm__ volatile( +- "movl $7, %%ecx \n\t" +- "andl %0, %%ecx \n\t" +- "addl %3, %%ecx \n\t" +- "negl %%ecx \n\t" +- "shll %%cl, %1 \n\t" +- "bswapl %1 \n\t" +- "movl %0, %%ecx \n\t" +- "shrl $3, %%ecx \n\t" +- "orl %1, (%%ecx, %2) \n\t" +- "addl %3, %0 \n\t" +- "movl $0, 4(%%ecx, %2) \n\t" +- : "=&r" (s->index), "=&r" (value) +- : "r" (s->buf), "r" (n), "0" (s->index), "1" (value) +- : "%ecx" +- ); +-# else +- int index= s->index; +- uint32_t *ptr= (uint32_t*)(((uint8_t *)s->buf)+(index>>3)); +- +- ptr[0] |= av_be2ne32(value<<(32-n-(index&7) )); +- ptr[1] = 0; +-//if(n>24) printf("%d %d\n", n, value); +- index+= n; +- s->index= index; +-# endif +-# endif //!ALIGNED_BITSTREAM_WRITER +-} +-#endif + + static inline void put_sbits(PutBitContext *pb, int n, int32_t value) + { +@@ -291,11 +195,7 @@ + */ + static inline uint8_t* put_bits_ptr(PutBitContext *s) + { +-#ifdef ALT_BITSTREAM_WRITER +- return s->buf + (s->index>>3); +-#else + return s->buf_ptr; +-#endif + } + + /** +@@ -305,13 +205,8 @@ + static inline void skip_put_bytes(PutBitContext *s, int n) + { + assert((put_bits_count(s)&7)==0); +-#ifdef ALT_BITSTREAM_WRITER +- FIXME may need some cleaning of the buffer +- s->index += n<<3; +-#else + assert(s->bit_left==32); + s->buf_ptr += n; +-#endif + } + + /** +@@ -321,13 +216,9 @@ + */ + static inline void skip_put_bits(PutBitContext *s, int n) + { +-#ifdef ALT_BITSTREAM_WRITER +- s->index += n; +-#else + s->bit_left -= n; + s->buf_ptr-= 4*(s->bit_left>>5); + s->bit_left &= 31; +-#endif + } + + /** +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qcelpdata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qcelpdata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qcelpdata.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qcelpdata.h 2012-05-14 14:08:54.143336137 +0200 +@@ -38,18 +38,18 @@ + * QCELP unpacked data frame + */ + typedef struct { +-/// @defgroup qcelp_codebook_parameters QCELP excitation codebook parameters ++/// @name QCELP excitation codebook parameters + /// @{ +- uint8_t cbsign[16]; ///!< sign of the codebook gain for each codebook subframe +- uint8_t cbgain[16]; ///!< unsigned codebook gain for each codebook subframe +- uint8_t cindex[16]; ///!< codebook index for each codebook subframe ++ uint8_t cbsign[16]; ///< sign of the codebook gain for each codebook subframe ++ uint8_t cbgain[16]; ///< unsigned codebook gain for each codebook subframe ++ uint8_t cindex[16]; ///< codebook index for each codebook subframe + /// @} + +-/// @defgroup qcelp_pitch_parameters QCELP pitch prediction parameters ++/// @name QCELP pitch prediction parameters + /// @{ +- uint8_t plag[4]; ///!< pitch lag for each pitch subframe +- uint8_t pfrac[4]; ///!< fractional pitch lag for each pitch subframe +- uint8_t pgain[4]; ///!< pitch gain for each pitch subframe ++ uint8_t plag[4]; ///< pitch lag for each pitch subframe ++ uint8_t pfrac[4]; ///< fractional pitch lag for each pitch subframe ++ uint8_t pgain[4]; ///< pitch gain for each pitch subframe + /// @} + + /** +@@ -74,9 +74,9 @@ + static const float qcelp_hammsinc_table[4] = { -0.006822, 0.041249, -0.143459, 0.588863}; + + typedef struct { +- uint8_t index; /*!< index into the QCELPContext structure */ +- uint8_t bitpos; /*!< position of the lowest bit in the value's byte */ +- uint8_t bitlen; /*!< number of bits to read */ ++ uint8_t index; /**< index into the QCELPContext structure */ ++ uint8_t bitpos; /**< position of the lowest bit in the value's byte */ ++ uint8_t bitlen; /**< number of bits to read */ + } QCELPBitmap; + + #define QCELP_OF(variable, bit, len) {offsetof(QCELPFrame, variable), bit, len} +@@ -266,7 +266,7 @@ + * the QCELPContext + */ + static const QCELPBitmap * const qcelp_unpacking_bitmaps_per_rate[5] = { +- NULL, ///!< for SILENCE rate ++ NULL, ///< for SILENCE rate + qcelp_rate_octave_bitmap, + qcelp_rate_quarter_bitmap, + qcelp_rate_half_bitmap, +@@ -274,7 +274,7 @@ + }; + + static const uint16_t qcelp_unpacking_bitmaps_lengths[5] = { +- 0, ///!< for SILENCE rate ++ 0, ///< for SILENCE rate + FF_ARRAY_ELEMS(qcelp_rate_octave_bitmap), + FF_ARRAY_ELEMS(qcelp_rate_quarter_bitmap), + FF_ARRAY_ELEMS(qcelp_rate_half_bitmap), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qcelpdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qcelpdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qcelpdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qcelpdec.c 2012-05-14 14:08:54.146336198 +0200 +@@ -44,9 +44,8 @@ + #undef NDEBUG + #include + +-typedef enum +-{ +- I_F_Q = -1, /*!< insufficient frame quality */ ++typedef enum { ++ I_F_Q = -1, /**< insufficient frame quality */ + SILENCE, + RATE_OCTAVE, + RATE_QUARTER, +@@ -54,16 +53,16 @@ + RATE_FULL + } qcelp_packet_rate; + +-typedef struct +-{ ++typedef struct { ++ AVFrame avframe; + GetBitContext gb; + qcelp_packet_rate bitrate; +- QCELPFrame frame; /*!< unpacked data frame */ ++ QCELPFrame frame; /**< unpacked data frame */ + + uint8_t erasure_count; +- uint8_t octave_count; /*!< count the consecutive RATE_OCTAVE frames */ ++ uint8_t octave_count; /**< count the consecutive RATE_OCTAVE frames */ + float prev_lspf[10]; +- float predictor_lspf[10];/*!< LSP predictor for RATE_OCTAVE and I_F_Q */ ++ float predictor_lspf[10];/**< LSP predictor for RATE_OCTAVE and I_F_Q */ + float pitch_synthesis_filter_mem[303]; + float pitch_pre_filter_mem[303]; + float rnd_fir_filter_mem[180]; +@@ -94,8 +93,11 @@ + + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + +- for(i=0; i<10; i++) +- q->prev_lspf[i] = (i+1)/11.; ++ for (i = 0; i < 10; i++) ++ q->prev_lspf[i] = (i + 1) / 11.; ++ ++ avcodec_get_frame_defaults(&q->avframe); ++ avctx->coded_frame = &q->avframe; + + return 0; + } +@@ -117,79 +119,70 @@ + float tmp_lspf, smooth, erasure_coeff; + const float *predictors; + +- if(q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) +- { +- predictors = (q->prev_bitrate != RATE_OCTAVE && +- q->prev_bitrate != I_F_Q ? +- q->prev_lspf : q->predictor_lspf); ++ if (q->bitrate == RATE_OCTAVE || q->bitrate == I_F_Q) { ++ predictors = q->prev_bitrate != RATE_OCTAVE && ++ q->prev_bitrate != I_F_Q ? q->prev_lspf ++ : q->predictor_lspf; + +- if(q->bitrate == RATE_OCTAVE) +- { ++ if (q->bitrate == RATE_OCTAVE) { + q->octave_count++; + +- for(i=0; i<10; i++) +- { ++ for (i = 0; i < 10; i++) { + q->predictor_lspf[i] = + lspf[i] = (q->frame.lspv[i] ? QCELP_LSP_SPREAD_FACTOR +- : -QCELP_LSP_SPREAD_FACTOR) +- + predictors[i] * QCELP_LSP_OCTAVE_PREDICTOR +- + (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR)/11); +- } +- smooth = (q->octave_count < 10 ? .875 : 0.1); +- }else +- { ++ : -QCELP_LSP_SPREAD_FACTOR) + ++ predictors[i] * QCELP_LSP_OCTAVE_PREDICTOR + ++ (i + 1) * ((1 - QCELP_LSP_OCTAVE_PREDICTOR) / 11); ++ } ++ smooth = q->octave_count < 10 ? .875 : 0.1; ++ } else { + erasure_coeff = QCELP_LSP_OCTAVE_PREDICTOR; + + assert(q->bitrate == I_F_Q); + +- if(q->erasure_count > 1) +- erasure_coeff *= (q->erasure_count < 4 ? 0.9 : 0.7); ++ if (q->erasure_count > 1) ++ erasure_coeff *= q->erasure_count < 4 ? 0.9 : 0.7; + +- for(i=0; i<10; i++) +- { ++ for (i = 0; i < 10; i++) { + q->predictor_lspf[i] = +- lspf[i] = (i + 1) * ( 1 - erasure_coeff)/11 +- + erasure_coeff * predictors[i]; ++ lspf[i] = (i + 1) * (1 - erasure_coeff) / 11 + ++ erasure_coeff * predictors[i]; + } + smooth = 0.125; + } + + // Check the stability of the LSP frequencies. + lspf[0] = FFMAX(lspf[0], QCELP_LSP_SPREAD_FACTOR); +- for(i=1; i<10; i++) +- lspf[i] = FFMAX(lspf[i], (lspf[i-1] + QCELP_LSP_SPREAD_FACTOR)); ++ for (i = 1; i < 10; i++) ++ lspf[i] = FFMAX(lspf[i], lspf[i - 1] + QCELP_LSP_SPREAD_FACTOR); + +- lspf[9] = FFMIN(lspf[9], (1.0 - QCELP_LSP_SPREAD_FACTOR)); +- for(i=9; i>0; i--) +- lspf[i-1] = FFMIN(lspf[i-1], (lspf[i] - QCELP_LSP_SPREAD_FACTOR)); ++ lspf[9] = FFMIN(lspf[9], 1.0 - QCELP_LSP_SPREAD_FACTOR); ++ for (i = 9; i > 0; i--) ++ lspf[i - 1] = FFMIN(lspf[i - 1], lspf[i] - QCELP_LSP_SPREAD_FACTOR); + + // Low-pass filter the LSP frequencies. +- ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10); +- }else +- { ++ ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0 - smooth, 10); ++ } else { + q->octave_count = 0; + + tmp_lspf = 0.; +- for(i=0; i<5 ; i++) +- { +- lspf[2*i+0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001; +- lspf[2*i+1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001; ++ for (i = 0; i < 5; i++) { ++ lspf[2 * i + 0] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][0] * 0.0001; ++ lspf[2 * i + 1] = tmp_lspf += qcelp_lspvq[i][q->frame.lspv[i]][1] * 0.0001; + } + + // Check for badly received packets. +- if(q->bitrate == RATE_QUARTER) +- { +- if(lspf[9] <= .70 || lspf[9] >= .97) ++ if (q->bitrate == RATE_QUARTER) { ++ if (lspf[9] <= .70 || lspf[9] >= .97) + return -1; +- for(i=3; i<10; i++) +- if(fabs(lspf[i] - lspf[i-2]) < .08) ++ for (i = 3; i < 10; i++) ++ if (fabs(lspf[i] - lspf[i - 2]) < .08) + return -1; +- }else +- { +- if(lspf[9] <= .66 || lspf[9] >= .985) ++ } else { ++ if (lspf[9] <= .66 || lspf[9] >= .985) + return -1; +- for(i=4; i<10; i++) +- if (fabs(lspf[i] - lspf[i-4]) < .0931) ++ for (i = 4; i < 10; i++) ++ if (fabs(lspf[i] - lspf[i - 4]) < .0931) + return -1; + } + } +@@ -204,82 +197,72 @@ + * + * TIA/EIA/IS-733 2.4.6.2 + */ +-static void decode_gain_and_index(QCELPContext *q, +- float *gain) { +- int i, subframes_count, g1[16]; ++static void decode_gain_and_index(QCELPContext *q, float *gain) ++{ ++ int i, subframes_count, g1[16]; + float slope; + +- if(q->bitrate >= RATE_QUARTER) +- { +- switch(q->bitrate) +- { +- case RATE_FULL: subframes_count = 16; break; +- case RATE_HALF: subframes_count = 4; break; +- default: subframes_count = 5; ++ if (q->bitrate >= RATE_QUARTER) { ++ switch (q->bitrate) { ++ case RATE_FULL: subframes_count = 16; break; ++ case RATE_HALF: subframes_count = 4; break; ++ default: subframes_count = 5; + } +- for(i=0; iframe.cbgain[i]; +- if(q->bitrate == RATE_FULL && !((i+1) & 3)) +- { +- g1[i] += av_clip((g1[i-1] + g1[i-2] + g1[i-3]) / 3 - 6, 0, 32); ++ if (q->bitrate == RATE_FULL && !((i + 1) & 3)) { ++ g1[i] += av_clip((g1[i - 1] + g1[i - 2] + g1[i - 3]) / 3 - 6, 0, 32); + } + + gain[i] = qcelp_g12ga[g1[i]]; + +- if(q->frame.cbsign[i]) +- { ++ if (q->frame.cbsign[i]) { + gain[i] = -gain[i]; +- q->frame.cindex[i] = (q->frame.cindex[i]-89) & 127; ++ q->frame.cindex[i] = (q->frame.cindex[i] - 89) & 127; + } + } + +- q->prev_g1[0] = g1[i-2]; +- q->prev_g1[1] = g1[i-1]; +- q->last_codebook_gain = qcelp_g12ga[g1[i-1]]; ++ q->prev_g1[0] = g1[i - 2]; ++ q->prev_g1[1] = g1[i - 1]; ++ q->last_codebook_gain = qcelp_g12ga[g1[i - 1]]; + +- if(q->bitrate == RATE_QUARTER) +- { ++ if (q->bitrate == RATE_QUARTER) { + // Provide smoothing of the unvoiced excitation energy. +- gain[7] = gain[4]; +- gain[6] = 0.4*gain[3] + 0.6*gain[4]; +- gain[5] = gain[3]; +- gain[4] = 0.8*gain[2] + 0.2*gain[3]; +- gain[3] = 0.2*gain[1] + 0.8*gain[2]; +- gain[2] = gain[1]; +- gain[1] = 0.6*gain[0] + 0.4*gain[1]; +- } +- }else if (q->bitrate != SILENCE) +- { +- if(q->bitrate == RATE_OCTAVE) +- { +- g1[0] = 2 * q->frame.cbgain[0] +- + av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54); ++ gain[7] = gain[4]; ++ gain[6] = 0.4 * gain[3] + 0.6 * gain[4]; ++ gain[5] = gain[3]; ++ gain[4] = 0.8 * gain[2] + 0.2 * gain[3]; ++ gain[3] = 0.2 * gain[1] + 0.8 * gain[2]; ++ gain[2] = gain[1]; ++ gain[1] = 0.6 * gain[0] + 0.4 * gain[1]; ++ } ++ } else if (q->bitrate != SILENCE) { ++ if (q->bitrate == RATE_OCTAVE) { ++ g1[0] = 2 * q->frame.cbgain[0] + ++ av_clip((q->prev_g1[0] + q->prev_g1[1]) / 2 - 5, 0, 54); + subframes_count = 8; +- }else +- { ++ } else { + assert(q->bitrate == I_F_Q); + + g1[0] = q->prev_g1[1]; +- switch(q->erasure_count) +- { +- case 1 : break; +- case 2 : g1[0] -= 1; break; +- case 3 : g1[0] -= 2; break; +- default: g1[0] -= 6; ++ switch (q->erasure_count) { ++ case 1 : break; ++ case 2 : g1[0] -= 1; break; ++ case 3 : g1[0] -= 2; break; ++ default: g1[0] -= 6; + } +- if(g1[0] < 0) ++ if (g1[0] < 0) + g1[0] = 0; + subframes_count = 4; + } + // This interpolation is done to produce smoother background noise. +- slope = 0.5*(qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count; +- for(i=1; i<=subframes_count; i++) +- gain[i-1] = q->last_codebook_gain + slope * i; +- +- q->last_codebook_gain = gain[i-2]; +- q->prev_g1[0] = q->prev_g1[1]; +- q->prev_g1[1] = g1[0]; ++ slope = 0.5 * (qcelp_g12ga[g1[0]] - q->last_codebook_gain) / subframes_count; ++ for (i = 1; i <= subframes_count; i++) ++ gain[i - 1] = q->last_codebook_gain + slope * i; ++ ++ q->last_codebook_gain = gain[i - 2]; ++ q->prev_g1[0] = q->prev_g1[1]; ++ q->prev_g1[1] = g1[0]; + } + } + +@@ -294,14 +277,13 @@ + */ + static int codebook_sanity_check_for_rate_quarter(const uint8_t *cbgain) + { +- int i, diff, prev_diff=0; ++ int i, diff, prev_diff = 0; + +- for(i=1; i<5; i++) +- { ++ for (i = 1; i < 5; i++) { + diff = cbgain[i] - cbgain[i-1]; +- if(FFABS(diff) > 10) ++ if (FFABS(diff) > 10) + return -1; +- else if(FFABS(diff - prev_diff) > 12) ++ else if (FFABS(diff - prev_diff) > 12) + return -1; + prev_diff = diff; + } +@@ -332,81 +314,74 @@ + static void compute_svector(QCELPContext *q, const float *gain, + float *cdn_vector) + { +- int i, j, k; ++ int i, j, k; + uint16_t cbseed, cindex; +- float *rnd, tmp_gain, fir_filter_value; ++ float *rnd, tmp_gain, fir_filter_value; + +- switch(q->bitrate) +- { +- case RATE_FULL: +- for(i=0; i<16; i++) +- { +- tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; +- cindex = -q->frame.cindex[i]; +- for(j=0; j<10; j++) +- *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cindex++ & 127]; +- } ++ switch (q->bitrate) { ++ case RATE_FULL: ++ for (i = 0; i < 16; i++) { ++ tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; ++ cindex = -q->frame.cindex[i]; ++ for (j = 0; j < 10; j++) ++ *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cindex++ & 127]; ++ } + break; +- case RATE_HALF: +- for(i=0; i<4; i++) +- { +- tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO; +- cindex = -q->frame.cindex[i]; +- for (j = 0; j < 40; j++) ++ case RATE_HALF: ++ for (i = 0; i < 4; i++) { ++ tmp_gain = gain[i] * QCELP_RATE_HALF_CODEBOOK_RATIO; ++ cindex = -q->frame.cindex[i]; ++ for (j = 0; j < 40; j++) + *cdn_vector++ = tmp_gain * qcelp_rate_half_codebook[cindex++ & 127]; +- } ++ } + break; +- case RATE_QUARTER: +- cbseed = (0x0003 & q->frame.lspv[4])<<14 | +- (0x003F & q->frame.lspv[3])<< 8 | +- (0x0060 & q->frame.lspv[2])<< 1 | +- (0x0007 & q->frame.lspv[1])<< 3 | +- (0x0038 & q->frame.lspv[0])>> 3 ; +- rnd = q->rnd_fir_filter_mem + 20; +- for(i=0; i<8; i++) +- { +- tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); +- for(k=0; k<20; k++) +- { +- cbseed = 521 * cbseed + 259; +- *rnd = (int16_t)cbseed; ++ case RATE_QUARTER: ++ cbseed = (0x0003 & q->frame.lspv[4]) << 14 | ++ (0x003F & q->frame.lspv[3]) << 8 | ++ (0x0060 & q->frame.lspv[2]) << 1 | ++ (0x0007 & q->frame.lspv[1]) << 3 | ++ (0x0038 & q->frame.lspv[0]) >> 3; ++ rnd = q->rnd_fir_filter_mem + 20; ++ for (i = 0; i < 8; i++) { ++ tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); ++ for (k = 0; k < 20; k++) { ++ cbseed = 521 * cbseed + 259; ++ *rnd = (int16_t) cbseed; + + // FIR filter +- fir_filter_value = 0.0; +- for(j=0; j<10; j++) +- fir_filter_value += qcelp_rnd_fir_coefs[j ] +- * (rnd[-j ] + rnd[-20+j]); +- +- fir_filter_value += qcelp_rnd_fir_coefs[10] * rnd[-10]; +- *cdn_vector++ = tmp_gain * fir_filter_value; +- rnd++; +- } ++ fir_filter_value = 0.0; ++ for (j = 0; j < 10; j++) ++ fir_filter_value += qcelp_rnd_fir_coefs[j] * ++ (rnd[-j] + rnd[-20+j]); ++ ++ fir_filter_value += qcelp_rnd_fir_coefs[10] * rnd[-10]; ++ *cdn_vector++ = tmp_gain * fir_filter_value; ++ rnd++; + } +- memcpy(q->rnd_fir_filter_mem, q->rnd_fir_filter_mem + 160, 20 * sizeof(float)); ++ } ++ memcpy(q->rnd_fir_filter_mem, q->rnd_fir_filter_mem + 160, ++ 20 * sizeof(float)); + break; +- case RATE_OCTAVE: +- cbseed = q->first16bits; +- for(i=0; i<8; i++) +- { +- tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); +- for(j=0; j<20; j++) +- { +- cbseed = 521 * cbseed + 259; +- *cdn_vector++ = tmp_gain * (int16_t)cbseed; +- } ++ case RATE_OCTAVE: ++ cbseed = q->first16bits; ++ for (i = 0; i < 8; i++) { ++ tmp_gain = gain[i] * (QCELP_SQRT1887 / 32768.0); ++ for (j = 0; j < 20; j++) { ++ cbseed = 521 * cbseed + 259; ++ *cdn_vector++ = tmp_gain * (int16_t) cbseed; + } ++ } + break; +- case I_F_Q: +- cbseed = -44; // random codebook index +- for(i=0; i<4; i++) +- { +- tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; +- for(j=0; j<40; j++) +- *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127]; +- } ++ case I_F_Q: ++ cbseed = -44; // random codebook index ++ for (i = 0; i < 4; i++) { ++ tmp_gain = gain[i] * QCELP_RATE_FULL_CODEBOOK_RATIO; ++ for (j = 0; j < 40; j++) ++ *cdn_vector++ = tmp_gain * qcelp_rate_full_codebook[cbseed++ & 127]; ++ } + break; +- case SILENCE: +- memset(cdn_vector, 0, 160 * sizeof(float)); ++ case SILENCE: ++ memset(cdn_vector, 0, 160 * sizeof(float)); + break; + } + } +@@ -420,8 +395,7 @@ + * + * TIA/EIA/IS-733 2.4.8.3, 2.4.8.6 + */ +-static void apply_gain_ctrl(float *v_out, const float *v_ref, +- const float *v_in) ++static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in) + { + int i; + +@@ -453,24 +427,20 @@ + const float gain[4], const uint8_t *lag, + const uint8_t pfrac[4]) + { +- int i, j; +- float *v_lag, *v_out; ++ int i, j; ++ float *v_lag, *v_out; + const float *v_len; + + v_out = memory + 143; // Output vector starts at memory[143]. + +- for(i=0; i<4; i++) +- { +- if(gain[i]) +- { ++ for (i = 0; i < 4; i++) { ++ if (gain[i]) { + v_lag = memory + 143 + 40 * i - lag[i]; +- for(v_len=v_in+40; v_inbitrate >= RATE_HALF || +- q->bitrate == SILENCE || +- (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) +- { +- +- if(q->bitrate >= RATE_HALF) +- { ++ if (q->bitrate >= RATE_HALF || q->bitrate == SILENCE || ++ (q->bitrate == I_F_Q && (q->prev_bitrate >= RATE_HALF))) { + ++ if (q->bitrate >= RATE_HALF) { + // Compute gain & lag for the whole frame. +- for(i=0; i<4; i++) +- { ++ for (i = 0; i < 4; i++) { + q->pitch_gain[i] = q->frame.plag[i] ? (q->frame.pgain[i] + 1) * 0.25 : 0.0; + + q->pitch_lag[i] = q->frame.plag[i] + 16; + } +- }else +- { ++ } else { + float max_pitch_gain; + +- if (q->bitrate == I_F_Q) +- { ++ if (q->bitrate == I_F_Q) { + if (q->erasure_count < 3) + max_pitch_gain = 0.9 - 0.3 * (q->erasure_count - 1); + else + max_pitch_gain = 0.0; +- }else +- { ++ } else { + assert(q->bitrate == SILENCE); + max_pitch_gain = 1.0; + } +- for(i=0; i<4; i++) ++ for (i = 0; i < 4; i++) + q->pitch_gain[i] = FFMIN(q->pitch_gain[i], max_pitch_gain); + + memset(q->frame.pfrac, 0, sizeof(q->frame.pfrac)); +@@ -544,19 +505,17 @@ + q->pitch_lag, q->frame.pfrac); + + // pitch prefilter update +- for(i=0; i<4; i++) ++ for (i = 0; i < 4; i++) + q->pitch_gain[i] = 0.5 * FFMIN(q->pitch_gain[i], 1.0); + +- v_pre_filtered = do_pitchfilter(q->pitch_pre_filter_mem, +- v_synthesis_filtered, +- q->pitch_gain, q->pitch_lag, +- q->frame.pfrac); ++ v_pre_filtered = do_pitchfilter(q->pitch_pre_filter_mem, ++ v_synthesis_filtered, ++ q->pitch_gain, q->pitch_lag, ++ q->frame.pfrac); + + apply_gain_ctrl(cdn_vector, v_synthesis_filtered, v_pre_filtered); +- }else +- { +- memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17, +- 143 * sizeof(float)); ++ } else { ++ memcpy(q->pitch_synthesis_filter_mem, cdn_vector + 17, 143 * sizeof(float)); + memcpy(q->pitch_pre_filter_mem, cdn_vector + 17, 143 * sizeof(float)); + memset(q->pitch_gain, 0, sizeof(q->pitch_gain)); + memset(q->pitch_lag, 0, sizeof(q->pitch_lag)); +@@ -579,16 +538,15 @@ + { + double lsp[10]; + double bandwidth_expansion_coeff = QCELP_BANDWIDTH_EXPANSION_COEFF; +- int i; ++ int i; + +- for (i=0; i<10; i++) ++ for (i = 0; i < 10; i++) + lsp[i] = cos(M_PI * lspf[i]); + + ff_acelp_lspd2lpc(lsp, lpc, 5); + +- for (i=0; i<10; i++) +- { +- lpc[i] *= bandwidth_expansion_coeff; ++ for (i = 0; i < 10; i++) { ++ lpc[i] *= bandwidth_expansion_coeff; + bandwidth_expansion_coeff *= QCELP_BANDWIDTH_EXPANSION_COEFF; + } + } +@@ -610,34 +568,32 @@ + float interpolated_lspf[10]; + float weight; + +- if(q->bitrate >= RATE_QUARTER) ++ if (q->bitrate >= RATE_QUARTER) + weight = 0.25 * (subframe_num + 1); +- else if(q->bitrate == RATE_OCTAVE && !subframe_num) ++ else if (q->bitrate == RATE_OCTAVE && !subframe_num) + weight = 0.625; + else + weight = 1.0; + +- if(weight != 1.0) +- { ++ if (weight != 1.0) { + ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf, + weight, 1.0 - weight, 10); + lspf2lpc(interpolated_lspf, lpc); +- }else if(q->bitrate >= RATE_QUARTER || +- (q->bitrate == I_F_Q && !subframe_num)) ++ } else if (q->bitrate >= RATE_QUARTER || ++ (q->bitrate == I_F_Q && !subframe_num)) + lspf2lpc(curr_lspf, lpc); +- else if(q->bitrate == SILENCE && !subframe_num) ++ else if (q->bitrate == SILENCE && !subframe_num) + lspf2lpc(q->prev_lspf, lpc); + } + + static qcelp_packet_rate buf_size2bitrate(const int buf_size) + { +- switch(buf_size) +- { +- case 35: return RATE_FULL; +- case 17: return RATE_HALF; +- case 8: return RATE_QUARTER; +- case 4: return RATE_OCTAVE; +- case 1: return SILENCE; ++ switch (buf_size) { ++ case 35: return RATE_FULL; ++ case 17: return RATE_HALF; ++ case 8: return RATE_QUARTER; ++ case 4: return RATE_OCTAVE; ++ case 1: return SILENCE; + } + + return I_F_Q; +@@ -655,39 +611,34 @@ + * + * TIA/EIA/IS-733 2.4.8.7.1 + */ +-static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, const int buf_size, +- const uint8_t **buf) ++static qcelp_packet_rate determine_bitrate(AVCodecContext *avctx, ++ const int buf_size, ++ const uint8_t **buf) + { + qcelp_packet_rate bitrate; + +- if((bitrate = buf_size2bitrate(buf_size)) >= 0) +- { +- if(bitrate > **buf) +- { ++ if ((bitrate = buf_size2bitrate(buf_size)) >= 0) { ++ if (bitrate > **buf) { + QCELPContext *q = avctx->priv_data; +- if (!q->warned_buf_mismatch_bitrate) +- { ++ if (!q->warned_buf_mismatch_bitrate) { + av_log(avctx, AV_LOG_WARNING, + "Claimed bitrate and buffer size mismatch.\n"); + q->warned_buf_mismatch_bitrate = 1; + } + bitrate = **buf; +- }else if(bitrate < **buf) +- { ++ } else if (bitrate < **buf) { + av_log(avctx, AV_LOG_ERROR, + "Buffer is too small for the claimed bitrate.\n"); + return I_F_Q; + } + (*buf)++; +- }else if((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) +- { ++ } else if ((bitrate = buf_size2bitrate(buf_size + 1)) >= 0) { + av_log(avctx, AV_LOG_WARNING, + "Bitrate byte is missing, guessing the bitrate from packet size.\n"); +- }else ++ } else + return I_F_Q; + +- if(bitrate == SILENCE) +- { ++ if (bitrate == SILENCE) { + //FIXME: Remove experimental warning when tested with samples. + av_log_ask_for_sample(avctx, "'Blank frame handling is experimental."); + } +@@ -697,8 +648,8 @@ + static void warn_insufficient_frame_quality(AVCodecContext *avctx, + const char *message) + { +- av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", avctx->frame_number, +- message); ++ av_log(avctx, AV_LOG_WARNING, "Frame #%d, IFQ: %s\n", ++ avctx->frame_number, message); + } + + static void postfilter(QCELPContext *q, float *samples, float *lpc) +@@ -720,75 +671,76 @@ + + ff_celp_lp_zero_synthesis_filterf(zero_out, lpc_s, + q->formant_mem + 10, 160, 10); +- memcpy(pole_out, q->postfilter_synth_mem, sizeof(float) * 10); ++ memcpy(pole_out, q->postfilter_synth_mem, sizeof(float) * 10); + ff_celp_lp_synthesis_filterf(pole_out + 10, lpc_p, zero_out, 160, 10); + memcpy(q->postfilter_synth_mem, pole_out + 160, sizeof(float) * 10); + + ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160); + + ff_adaptive_gain_control(samples, pole_out + 10, +- ff_dot_productf(q->formant_mem + 10, q->formant_mem + 10, 160), +- 160, 0.9375, &q->postfilter_agc_mem); ++ ff_dot_productf(q->formant_mem + 10, ++ q->formant_mem + 10, 160), ++ 160, 0.9375, &q->postfilter_agc_mem); + } + +-static int qcelp_decode_frame(AVCodecContext *avctx, void *data, int *data_size, +- AVPacket *avpkt) ++static int qcelp_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- QCELPContext *q = avctx->priv_data; +- float *outbuffer = data; +- int i; ++ int buf_size = avpkt->size; ++ QCELPContext *q = avctx->priv_data; ++ float *outbuffer; ++ int i, ret; + float quantized_lspf[10], lpc[10]; + float gain[16]; + float *formant_mem; + +- if((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) +- { ++ /* get output buffer */ ++ q->avframe.nb_samples = 160; ++ if ((ret = avctx->get_buffer(avctx, &q->avframe)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ outbuffer = (float *)q->avframe.data[0]; ++ ++ if ((q->bitrate = determine_bitrate(avctx, buf_size, &buf)) == I_F_Q) { + warn_insufficient_frame_quality(avctx, "bitrate cannot be determined."); + goto erasure; + } + +- if(q->bitrate == RATE_OCTAVE && +- (q->first16bits = AV_RB16(buf)) == 0xFFFF) +- { ++ if (q->bitrate == RATE_OCTAVE && ++ (q->first16bits = AV_RB16(buf)) == 0xFFFF) { + warn_insufficient_frame_quality(avctx, "Bitrate is 1/8 and first 16 bits are on."); + goto erasure; + } + +- if(q->bitrate > SILENCE) +- { ++ if (q->bitrate > SILENCE) { + const QCELPBitmap *bitmaps = qcelp_unpacking_bitmaps_per_rate[q->bitrate]; +- const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate] +- + qcelp_unpacking_bitmaps_lengths[q->bitrate]; +- uint8_t *unpacked_data = (uint8_t *)&q->frame; ++ const QCELPBitmap *bitmaps_end = qcelp_unpacking_bitmaps_per_rate[q->bitrate] + ++ qcelp_unpacking_bitmaps_lengths[q->bitrate]; ++ uint8_t *unpacked_data = (uint8_t *)&q->frame; + +- init_get_bits(&q->gb, buf, 8*buf_size); ++ init_get_bits(&q->gb, buf, 8 * buf_size); + + memset(&q->frame, 0, sizeof(QCELPFrame)); + +- for(; bitmaps < bitmaps_end; bitmaps++) ++ for (; bitmaps < bitmaps_end; bitmaps++) + unpacked_data[bitmaps->index] |= get_bits(&q->gb, bitmaps->bitlen) << bitmaps->bitpos; + + // Check for erasures/blanks on rates 1, 1/4 and 1/8. +- if(q->frame.reserved) +- { ++ if (q->frame.reserved) { + warn_insufficient_frame_quality(avctx, "Wrong data in reserved frame area."); + goto erasure; + } +- if(q->bitrate == RATE_QUARTER && +- codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) +- { ++ if (q->bitrate == RATE_QUARTER && ++ codebook_sanity_check_for_rate_quarter(q->frame.cbgain)) { + warn_insufficient_frame_quality(avctx, "Codebook gain sanity check failed."); + goto erasure; + } + +- if(q->bitrate >= RATE_HALF) +- { +- for(i=0; i<4; i++) +- { +- if(q->frame.pfrac[i] && q->frame.plag[i] >= 124) +- { ++ if (q->bitrate >= RATE_HALF) { ++ for (i = 0; i < 4; i++) { ++ if (q->frame.pfrac[i] && q->frame.plag[i] >= 124) { + warn_insufficient_frame_quality(avctx, "Cannot initialize pitch filter."); + goto erasure; + } +@@ -799,17 +751,14 @@ + decode_gain_and_index(q, gain); + compute_svector(q, gain, outbuffer); + +- if(decode_lspf(q, quantized_lspf) < 0) +- { ++ if (decode_lspf(q, quantized_lspf) < 0) { + warn_insufficient_frame_quality(avctx, "Badly received packets in frame."); + goto erasure; + } + +- + apply_pitch_filters(q, outbuffer); + +- if(q->bitrate == I_F_Q) +- { ++ if (q->bitrate == I_F_Q) { + erasure: + q->bitrate = I_F_Q; + q->erasure_count++; +@@ -817,15 +766,13 @@ + compute_svector(q, gain, outbuffer); + decode_lspf(q, quantized_lspf); + apply_pitch_filters(q, outbuffer); +- }else ++ } else + q->erasure_count = 0; + + formant_mem = q->formant_mem + 10; +- for(i=0; i<4; i++) +- { ++ for (i = 0; i < 4; i++) { + interpolate_lpc(q, quantized_lspf, lpc, i); +- ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40, +- 10); ++ ff_celp_lp_synthesis_filterf(formant_mem, lpc, outbuffer + i * 40, 40, 10); + formant_mem += 40; + } + +@@ -835,20 +782,21 @@ + memcpy(q->formant_mem, q->formant_mem + 160, 10 * sizeof(float)); + + memcpy(q->prev_lspf, quantized_lspf, sizeof(q->prev_lspf)); +- q->prev_bitrate = q->bitrate; ++ q->prev_bitrate = q->bitrate; + +- *data_size = 160 * sizeof(*outbuffer); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = q->avframe; + +- return *data_size; ++ return buf_size; + } + +-AVCodec ff_qcelp_decoder = +-{ +- .name = "qcelp", +- .type = AVMEDIA_TYPE_AUDIO, +- .id = CODEC_ID_QCELP, +- .init = qcelp_decode_init, +- .decode = qcelp_decode_frame, ++AVCodec ff_qcelp_decoder = { ++ .name = "qcelp", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_QCELP, ++ .init = qcelp_decode_init, ++ .decode = qcelp_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .priv_data_size = sizeof(QCELPContext), +- .long_name = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"), ++ .long_name = NULL_IF_CONFIG_SMALL("QCELP / PureVoice"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdm2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdm2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdm2.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdm2.c 2012-05-14 14:08:54.148336238 +0200 +@@ -26,6 +26,7 @@ + * @file + * QDM2 decoder + * @author Ewald Snel, Benjamin Larsson, Alex Beregszaszi, Roberto Togni ++ * + * The decoder is not perfect yet, there are still some distortions + * especially on files encoded with 16 or 8 subbands. + */ +@@ -34,11 +35,12 @@ + #include + #include + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "get_bits.h" + #include "dsputil.h" +-#include "fft.h" ++#include "rdft.h" ++#include "mpegaudiodsp.h" + #include "mpegaudio.h" + + #include "qdm2data.h" +@@ -75,6 +77,7 @@ + #define SAMPLES_NEEDED_2(why) \ + av_log (NULL,AV_LOG_INFO,"This file triggers some missing code. Please contact the developers.\nPosition: %s\n",why); + ++#define QDM2_MAX_FRAME_SIZE 512 + + typedef int8_t sb_int8_array[2][30][64]; + +@@ -120,13 +123,15 @@ + } FFTCoefficient; + + typedef struct { +- DECLARE_ALIGNED(16, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; ++ DECLARE_ALIGNED(32, QDM2Complex, complex)[MPA_MAX_CHANNELS][256]; + } QDM2FFT; + + /** + * QDM2 decoder context + */ + typedef struct { ++ AVFrame frame; ++ + /// Parameters from codec header, do not change during playback + int nb_channels; ///< number of channels + int channels; ///< number of channels +@@ -167,12 +172,14 @@ + /// I/O data + const uint8_t *compressed_data; + int compressed_size; +- float output_buffer[1024]; ++ float output_buffer[QDM2_MAX_FRAME_SIZE * MPA_MAX_CHANNELS * 2]; + + /// Synthesis filter +- DECLARE_ALIGNED(16, MPA_INT, synth_buf)[MPA_MAX_CHANNELS][512*2]; ++ MPADSPContext mpadsp; ++ DECLARE_ALIGNED(32, float, synth_buf)[MPA_MAX_CHANNELS][512*2]; + int synth_buf_offset[MPA_MAX_CHANNELS]; +- DECLARE_ALIGNED(16, int32_t, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT]; ++ DECLARE_ALIGNED(32, float, sb_samples)[MPA_MAX_CHANNELS][128][SBLIMIT]; ++ DECLARE_ALIGNED(32, float, samples)[MPA_MAX_CHANNELS * MPA_FRAME_SIZE]; + + /// Mixed temporary data used in decoding + float tone_level[MPA_MAX_CHANNELS][30][64]; +@@ -329,11 +336,6 @@ + } + } + +- +-/* for floating point to fixed point conversion */ +-static const float f2i_scale = (float) (1 << (FRAC_BITS - 15)); +- +- + static int qdm2_get_vlc (GetBitContext *gb, VLC *vlc, int flag, int depth) + { + int value; +@@ -482,8 +484,8 @@ + + for (ch = 0; ch < q->nb_channels; ch++) + for (j = 0; j < 64; j++) { +- q->sb_samples[ch][j * 2][sb] = (int32_t)(f2i_scale * SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j] + .5); +- q->sb_samples[ch][j * 2 + 1][sb] = (int32_t)(f2i_scale * SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j] + .5); ++ q->sb_samples[ch][j * 2][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j]; ++ q->sb_samples[ch][j * 2 + 1][sb] = SB_DITHERING_NOISE(sb,q->noise_idx) * q->tone_level[ch][sb][j]; + } + } + +@@ -923,11 +925,11 @@ + for (chs = 0; chs < q->nb_channels; chs++) + for (k = 0; k < run; k++) + if ((j + k) < 128) +- q->sb_samples[chs][j + k][sb] = (int32_t)(f2i_scale * q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs] + .5); ++ q->sb_samples[chs][j + k][sb] = q->tone_level[chs][sb][((j + k)/2)] * tmp[k][chs]; + } else { + for (k = 0; k < run; k++) + if ((j + k) < 128) +- q->sb_samples[ch][j + k][sb] = (int32_t)(f2i_scale * q->tone_level[ch][sb][(j + k)/2] * samples[k] + .5); ++ q->sb_samples[ch][j + k][sb] = q->tone_level[ch][sb][(j + k)/2] * samples[k]; + } + + j += run; +@@ -1329,7 +1331,7 @@ + local_int_10 = 1 << (q->group_order - duration - 1); + offset = 1; + +- while (1) { ++ while (get_bits_left(gb)>0) { + if (q->superblocktype_2_3) { + while ((n = qdm2_get_vlc(gb, &vlc_tab_fft_tone_offset[local_int_8], 1, 2)) < 2) { + offset = 1; +@@ -1355,6 +1357,8 @@ + return; + + local_int_14 = (offset >> local_int_8); ++ if (local_int_14 >= FF_ARRAY_ELEMS(fft_level_index_table)) ++ return; + + if (q->nb_channels > 1) { + channel = get_bits1(gb); +@@ -1588,7 +1592,7 @@ + int i; + q->fft.complex[channel][0].re *= 2.0f; + q->fft.complex[channel][0].im = 0.0f; +- ff_rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); ++ q->rdft_ctx.rdft_calc(&q->rdft_ctx, (FFTSample *)q->fft.complex[channel]); + /* add samples to output buffer */ + for (i = 0; i < ((q->fft_frame_size + 15) & ~15); i++) + q->output_buffer[q->channels * i + channel] += ((float *) q->fft.complex[channel])[i] * gain; +@@ -1601,7 +1605,6 @@ + */ + static void qdm2_synthesis_filter (QDM2Context *q, int index) + { +- OUT_INT samples[MPA_MAX_CHANNELS * MPA_FRAME_SIZE]; + int i, k, ch, sb_used, sub_sampling, dither_state = 0; + + /* copy sb_samples */ +@@ -1613,11 +1616,12 @@ + q->sb_samples[ch][(8 * index) + i][k] = 0; + + for (ch = 0; ch < q->nb_channels; ch++) { +- OUT_INT *samples_ptr = samples + ch; ++ float *samples_ptr = q->samples + ch; + + for (i = 0; i < 8; i++) { +- ff_mpa_synth_filter(q->synth_buf[ch], &(q->synth_buf_offset[ch]), +- ff_mpa_synth_window, &dither_state, ++ ff_mpa_synth_filter_float(&q->mpadsp, ++ q->synth_buf[ch], &(q->synth_buf_offset[ch]), ++ ff_mpa_synth_window_float, &dither_state, + samples_ptr, q->nb_channels, + q->sb_samples[ch][(8 * index) + i]); + samples_ptr += 32 * q->nb_channels; +@@ -1629,7 +1633,7 @@ + + for (ch = 0; ch < q->channels; ch++) + for (i = 0; i < q->frame_size; i++) +- q->output_buffer[q->channels * i + ch] += (float)(samples[q->nb_channels * sub_sampling * i + ch] >> (sizeof(OUT_INT)*8-16)); ++ q->output_buffer[q->channels * i + ch] += (1 << 23) * q->samples[q->nb_channels * sub_sampling * i + ch]; + } + + +@@ -1646,7 +1650,7 @@ + initialized = 1; + + qdm2_init_vlc(); +- ff_mpa_synth_init(ff_mpa_synth_window); ++ ff_mpa_synth_init_float(ff_mpa_synth_window_float); + softclip_table_init(); + rnd_table_init(); + init_noise_samples(); +@@ -1799,6 +1803,8 @@ + + avctx->channels = s->nb_channels = s->channels = AV_RB32(extradata); + extradata += 4; ++ if (s->channels > MPA_MAX_CHANNELS) ++ return AVERROR_INVALIDDATA; + + avctx->sample_rate = AV_RB32(extradata); + extradata += 4; +@@ -1813,6 +1819,10 @@ + extradata += 4; + + s->checksum_size = AV_RB32(extradata); ++ if (s->checksum_size >= 1U << 28) { ++ av_log(avctx, AV_LOG_ERROR, "data block size too large (%u)\n", s->checksum_size); ++ return AVERROR_INVALIDDATA; ++ } + + s->fft_order = av_log2(s->fft_size) + 1; + s->fft_frame_size = 2 * s->fft_size; // complex has two floats +@@ -1821,6 +1831,9 @@ + s->group_order = av_log2(s->group_size) + 1; + s->frame_size = s->group_size / 16; // 16 iterations per super block + ++ if (s->frame_size > QDM2_MAX_FRAME_SIZE) ++ return AVERROR_INVALIDDATA; ++ + s->sub_sampling = s->fft_order - 7; + s->frequency_range = 255 / (1 << (2 - s->sub_sampling)); + +@@ -1863,11 +1876,15 @@ + } + + ff_rdft_init(&s->rdft_ctx, s->fft_order, IDFT_C2R); ++ ff_mpadsp_init(&s->mpadsp); + + qdm2_init(s); + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + // dump_context(s); + return 0; + } +@@ -1888,6 +1905,9 @@ + int ch, i; + const int frame_size = (q->frame_size * q->channels); + ++ if((unsigned)frame_size > FF_ARRAY_ELEMS(q->output_buffer)/2) ++ return -1; ++ + /* select input buffer */ + q->compressed_data = in; + q->compressed_size = q->checksum_size; +@@ -1945,23 +1965,27 @@ + } + + +-static int qdm2_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int qdm2_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + QDM2Context *s = avctx->priv_data; +- int16_t *out = data; +- int i; ++ int16_t *out; ++ int i, ret; + + if(!buf) + return 0; + if(buf_size < s->checksum_size) + return -1; + +- av_log(avctx, AV_LOG_DEBUG, "decode(%d): %p[%d] -> %p[%d]\n", +- buf_size, buf, s->checksum_size, data, *data_size); ++ /* get output buffer */ ++ s->frame.nb_samples = 16 * s->frame_size; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out = (int16_t *)s->frame.data[0]; + + for (i = 0; i < 16; i++) { + if (qdm2_decode(s, buf, out) < 0) +@@ -1969,7 +1993,8 @@ + out += s->channels * s->frame_size; + } + +- *data_size = (uint8_t*)out - (uint8_t*)data; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + + return s->checksum_size; + } +@@ -1983,5 +2008,6 @@ + .init = qdm2_decode_init, + .close = qdm2_decode_close, + .decode = qdm2_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("QDesign Music Codec 2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdm2_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdm2_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdm2_tablegen.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdm2_tablegen.h 2012-05-14 14:08:54.149336258 +0200 +@@ -20,8 +20,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef QDM2_TABLEGEN_H +-#define QDM2_TABLEGEN_H ++#ifndef AVCODEC_QDM2_TABLEGEN_H ++#define AVCODEC_QDM2_TABLEGEN_H + + #include + #include +@@ -90,7 +90,7 @@ + + static av_cold void init_noise_samples(void) { + int i; +- int random_seed = 0; ++ unsigned random_seed = 0; + float delta = 1.0 / 16384.0; + for (i = 0; i < 128;i++) { + random_seed = random_seed * 214013 + 2531011; +@@ -99,4 +99,4 @@ + } + #endif /* CONFIG_HARDCODED_TABLES */ + +-#endif /* QDM2_TABLEGEN_H */ ++#endif /* AVCODEC_QDM2_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdrw.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdrw.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qdrw.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qdrw.c 2012-05-14 14:08:54.150336278 +0200 +@@ -37,6 +37,7 @@ + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + int buf_size = avpkt->size; + QdrawContext * const a = avctx->priv_data; + AVFrame * const p= (AVFrame*)&a->pic; +@@ -54,11 +55,13 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + outdata = a->pic.data[0]; + ++ if (buf_end - buf < 0x68 + 4) ++ return AVERROR_INVALIDDATA; + buf += 0x68; /* jump to palette */ + colors = AV_RB32(buf); + buf += 4; +@@ -67,6 +70,8 @@ + av_log(avctx, AV_LOG_ERROR, "Error color count - %i(0x%X)\n", colors, colors); + return -1; + } ++ if (buf_end - buf < (colors + 1) * 8) ++ return AVERROR_INVALIDDATA; + + pal = (uint32_t*)p->data[1]; + for (i = 0; i <= colors; i++) { +@@ -85,10 +90,12 @@ + buf++; + b = *buf++; + buf++; +- pal[idx] = (r << 16) | (g << 8) | b; ++ pal[idx] = 0xFF << 24 | r << 16 | g << 8 | b; + } + p->palette_has_changed = 1; + ++ if (buf_end - buf < 18) ++ return AVERROR_INVALIDDATA; + buf += 18; /* skip unneeded data */ + for (i = 0; i < avctx->height; i++) { + int size, left, code, pix; +@@ -100,6 +107,9 @@ + out = outdata; + size = AV_RB16(buf); /* size of packed line */ + buf += 2; ++ if (buf_end - buf < size) ++ return AVERROR_INVALIDDATA; ++ + left = size; + next = buf + size; + while (left > 0) { +@@ -115,6 +125,8 @@ + } else { /* copy */ + if ((out + code) > (outdata + a->pic.linesize[0])) + break; ++ if (buf_end - buf < code + 1) ++ return AVERROR_INVALIDDATA; + memcpy(out, buf, code + 1); + out += code + 1; + buf += code + 1; +@@ -133,8 +145,9 @@ + } + + static av_cold int decode_init(AVCodecContext *avctx){ +-// QdrawContext * const a = avctx->priv_data; ++ QdrawContext * const a = avctx->priv_data; + ++ avcodec_get_frame_defaults(&a->pic); + avctx->pix_fmt= PIX_FMT_PAL8; + + return 0; +@@ -151,14 +164,13 @@ + } + + AVCodec ff_qdraw_decoder = { +- "qdraw", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_QDRAW, +- sizeof(QdrawContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "qdraw", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_QDRAW, ++ .priv_data_size = sizeof(QdrawContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Apple QuickDraw"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qpeg.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qpeg.c 2012-05-14 14:08:54.151336298 +0200 +@@ -28,11 +28,11 @@ + + typedef struct QpegContext{ + AVCodecContext *avctx; +- AVFrame pic; +- uint8_t *refdata; ++ AVFrame pic, ref; ++ uint32_t pal[256]; + } QpegContext; + +-static void qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, ++static int qpeg_decode_intra(const uint8_t *src, uint8_t *dst, int size, + int stride, int width, int height) + { + int i; +@@ -94,6 +94,8 @@ + } + } else { + size -= copy; ++ if (size<0) ++ return AVERROR_INVALIDDATA; + for(i = 0; i < copy; i++) { + dst[filled++] = *src++; + if (filled >= width) { +@@ -106,6 +108,7 @@ + } + } + } ++ return 0; + } + + static const int qpeg_table_h[16] = +@@ -123,9 +126,12 @@ + int filled = 0; + int orig_height; + ++ if(!refdata) ++ refdata= dst; ++ + /* copy prev frame */ + for(i = 0; i < height; i++) +- memcpy(refdata + (i * width), dst + (i * stride), width); ++ memcpy(dst + (i * stride), refdata + (i * stride), width); + + orig_height = height; + height--; +@@ -171,10 +177,10 @@ + me_x, me_y, me_w, me_h, filled, height); + else { + /* do motion compensation */ +- me_plane = refdata + (filled + me_x) + (height - me_y) * width; ++ me_plane = refdata + (filled + me_x) + (height - me_y) * stride; + for(j = 0; j < me_h; j++) { + for(i = 0; i < me_w; i++) +- dst[filled + i - (j * stride)] = me_plane[i - (j * width)]; ++ dst[filled + i - (j * stride)] = me_plane[i - (j * stride)]; + } + } + } +@@ -197,6 +203,8 @@ + filled = 0; + dst -= stride; + height--; ++ if(height < 0) ++ break; + } + } + } else if(code >= 0xC0) { /* copy code: 0xC0..0xDF */ +@@ -208,6 +216,8 @@ + filled = 0; + dst -= stride; + height--; ++ if(height < 0) ++ break; + } + } + size -= code + 1; +@@ -253,32 +263,38 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + QpegContext * const a = avctx->priv_data; +- AVFrame * const p= (AVFrame*)&a->pic; ++ AVFrame * p= (AVFrame*)&a->pic; ++ AVFrame * ref= (AVFrame*)&a->ref; + uint8_t* outdata; +- int delta; ++ int delta, ret = 0; ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); + +- if(p->data[0]) +- avctx->release_buffer(avctx, p); ++ if(ref->data[0]) ++ avctx->release_buffer(avctx, ref); ++ FFSWAP(AVFrame, *ref, *p); + +- p->reference= 0; ++ p->reference= 3; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + outdata = a->pic.data[0]; + if(buf[0x85] == 0x10) { +- qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height); ++ ret = qpeg_decode_intra(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height); + } else { + delta = buf[0x85]; +- qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->refdata); ++ qpeg_decode_inter(buf+0x86, outdata, buf_size - 0x86, a->pic.linesize[0], avctx->width, avctx->height, delta, buf + 4, a->ref.data[0]); + } + ++ if (ret<0) ++ return ret; ++ + /* make the palette available on the way out */ +- memcpy(a->pic.data[1], a->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (a->avctx->palctrl->palette_changed) { ++ if (pal) { + a->pic.palette_has_changed = 1; +- a->avctx->palctrl->palette_changed = 0; ++ memcpy(a->pal, pal, AVPALETTE_SIZE); + } ++ memcpy(a->pic.data[1], a->pal, AVPALETTE_SIZE); + + *data_size = sizeof(AVFrame); + *(AVFrame*)data = a->pic; +@@ -289,13 +305,10 @@ + static av_cold int decode_init(AVCodecContext *avctx){ + QpegContext * const a = avctx->priv_data; + +- if (!avctx->palctrl) { +- av_log(avctx, AV_LOG_FATAL, "Missing required palette via palctrl\n"); +- return -1; +- } ++ avcodec_get_frame_defaults(&a->pic); ++ avcodec_get_frame_defaults(&a->ref); + a->avctx = avctx; + avctx->pix_fmt= PIX_FMT_PAL8; +- a->refdata = av_malloc(avctx->width * avctx->height); + + return 0; + } +@@ -303,23 +316,24 @@ + static av_cold int decode_end(AVCodecContext *avctx){ + QpegContext * const a = avctx->priv_data; + AVFrame * const p= (AVFrame*)&a->pic; ++ AVFrame * const ref= (AVFrame*)&a->ref; + + if(p->data[0]) + avctx->release_buffer(avctx, p); ++ if(ref->data[0]) ++ avctx->release_buffer(avctx, ref); + +- av_free(a->refdata); + return 0; + } + + AVCodec ff_qpeg_decoder = { +- "qpeg", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_QPEG, +- sizeof(QpegContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "qpeg", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_QPEG, ++ .priv_data_size = sizeof(QpegContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Q-team QPEG"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qtrle.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qtrle.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qtrle.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qtrle.c 2012-05-14 14:08:54.152336318 +0200 +@@ -46,6 +46,7 @@ + const unsigned char *buf; + int size; + ++ uint32_t pal[256]; + } QtrleContext; + + #define CHECK_STREAM_PTR(n) \ +@@ -71,6 +72,15 @@ + unsigned char *rgb = s->frame.data[0]; + int pixel_limit = s->frame.linesize[0] * s->avctx->height; + int skip; ++ /* skip & 0x80 appears to mean 'start a new line', which can be interpreted ++ * as 'go to next line' during the decoding of a frame but is 'go to first ++ * line' at the beginning. Since we always interpret it as 'go to next line' ++ * in the decoding loop (which makes code simpler/faster), the first line ++ * would not be counted, so we count one more. ++ * See: https://ffmpeg.org/trac/ffmpeg/ticket/226 ++ * In the following decoding loop, row_ptr will be the position of the ++ * _next_ row. */ ++ lines_to_change++; + + while (lines_to_change) { + CHECK_STREAM_PTR(2); +@@ -80,12 +90,15 @@ + break; + if(skip & 0x80) { + lines_to_change--; +- row_ptr += row_inc; + pixel_ptr = row_ptr + 2 * (skip & 0x7f); ++ row_ptr += row_inc; + } else + pixel_ptr += 2 * skip; + CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + ++ if(rle_code == -1) ++ continue; ++ + if (rle_code < 0) { + /* decode the run length code */ + rle_code = -rle_code; +@@ -126,6 +139,7 @@ + while (lines_to_change--) { + CHECK_STREAM_PTR(2); + pixel_ptr = row_ptr + (num_pixels * (s->buf[stream_ptr++] - 1)); ++ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + + while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { + if (rle_code == 0) { +@@ -182,6 +196,7 @@ + while (lines_to_change--) { + CHECK_STREAM_PTR(2); + pixel_ptr = row_ptr + (4 * (s->buf[stream_ptr++] - 1)); ++ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + + while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { + if (rle_code == 0) { +@@ -235,6 +250,7 @@ + while (lines_to_change--) { + CHECK_STREAM_PTR(2); + pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 2; ++ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + + while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { + if (rle_code == 0) { +@@ -284,6 +300,7 @@ + while (lines_to_change--) { + CHECK_STREAM_PTR(2); + pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 3; ++ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + + while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { + if (rle_code == 0) { +@@ -327,7 +344,6 @@ + int rle_code; + int pixel_ptr; + int row_inc = s->frame.linesize[0]; +- unsigned char a, r, g, b; + unsigned int argb; + unsigned char *rgb = s->frame.data[0]; + int pixel_limit = s->frame.linesize[0] * s->avctx->height; +@@ -335,6 +351,7 @@ + while (lines_to_change--) { + CHECK_STREAM_PTR(2); + pixel_ptr = row_ptr + (s->buf[stream_ptr++] - 1) * 4; ++ CHECK_PIXEL_PTR(0); /* make sure pixel_ptr is positive */ + + while ((rle_code = (signed char)s->buf[stream_ptr++]) != -1) { + if (rle_code == 0) { +@@ -346,16 +363,13 @@ + /* decode the run length code */ + rle_code = -rle_code; + CHECK_STREAM_PTR(4); +- a = s->buf[stream_ptr++]; +- r = s->buf[stream_ptr++]; +- g = s->buf[stream_ptr++]; +- b = s->buf[stream_ptr++]; +- argb = (a << 24) | (r << 16) | (g << 8) | (b << 0); ++ argb = AV_RB32(s->buf + stream_ptr); ++ stream_ptr += 4; + + CHECK_PIXEL_PTR(rle_code * 4); + + while (rle_code--) { +- *(unsigned int *)(&rgb[pixel_ptr]) = argb; ++ AV_WN32A(rgb + pixel_ptr, argb); + pixel_ptr += 4; + } + } else { +@@ -364,13 +378,10 @@ + + /* copy pixels directly to output */ + while (rle_code--) { +- a = s->buf[stream_ptr++]; +- r = s->buf[stream_ptr++]; +- g = s->buf[stream_ptr++]; +- b = s->buf[stream_ptr++]; +- argb = (a << 24) | (r << 16) | (g << 8) | (b << 0); +- *(unsigned int *)(&rgb[pixel_ptr]) = argb; +- pixel_ptr += 4; ++ argb = AV_RB32(s->buf + stream_ptr); ++ AV_WN32A(rgb + pixel_ptr, argb); ++ stream_ptr += 4; ++ pixel_ptr += 4; + } + } + } +@@ -413,9 +424,10 @@ + default: + av_log (avctx, AV_LOG_ERROR, "Unsupported colorspace: %d bits/sample?\n", + avctx->bits_per_coded_sample); +- break; ++ return AVERROR_INVALIDDATA; + } + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -435,7 +447,7 @@ + s->buf = buf; + s->size = buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { +@@ -462,6 +474,8 @@ + stream_ptr += 4; + height = AV_RB16(&s->buf[stream_ptr]); + stream_ptr += 4; ++ if (height > s->avctx->height - start_line) ++ goto done; + } else { + start_line = 0; + height = s->avctx->height; +@@ -511,12 +525,15 @@ + } + + if(has_palette) { +- /* make the palette available on the way out */ +- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (s->avctx->palctrl->palette_changed) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ ++ if (pal) { + s->frame.palette_has_changed = 1; +- s->avctx->palctrl->palette_changed = 0; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); + } ++ ++ /* make the palette available on the way out */ ++ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + } + + done: +@@ -538,15 +555,14 @@ + } + + AVCodec ff_qtrle_decoder = { +- "qtrle", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_QTRLE, +- sizeof(QtrleContext), +- qtrle_decode_init, +- NULL, +- qtrle_decode_end, +- qtrle_decode_frame, +- CODEC_CAP_DR1, ++ .name = "qtrle", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_QTRLE, ++ .priv_data_size = sizeof(QtrleContext), ++ .init = qtrle_decode_init, ++ .close = qtrle_decode_end, ++ .decode = qtrle_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qtrleenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qtrleenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/qtrleenc.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/qtrleenc.c 2012-05-14 14:08:54.153336339 +0200 +@@ -22,7 +22,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "bytestream.h" + +@@ -39,6 +39,7 @@ + int pixel_size; + AVPicture previous_frame; + unsigned int max_buf_size; ++ int logical_width; + /** + * This array will contain at ith position the value of the best RLE code + * if the line started at pixel i +@@ -67,8 +68,13 @@ + return -1; + } + s->avctx=avctx; ++ s->logical_width=avctx->width; + + switch (avctx->pix_fmt) { ++ case PIX_FMT_GRAY8: ++ s->logical_width = avctx->width / 4; ++ s->pixel_size = 4; ++ break; + case PIX_FMT_RGB555BE: + s->pixel_size = 2; + break; +@@ -82,11 +88,11 @@ + av_log(avctx, AV_LOG_ERROR, "Unsupported colorspace.\n"); + break; + } +- avctx->bits_per_coded_sample = s->pixel_size*8; ++ avctx->bits_per_coded_sample = avctx->pix_fmt == PIX_FMT_GRAY8 ? 40 : s->pixel_size*8; + +- s->rlecode_table = av_mallocz(s->avctx->width); +- s->skip_table = av_mallocz(s->avctx->width); +- s->length_table = av_mallocz((s->avctx->width + 1)*sizeof(int)); ++ s->rlecode_table = av_mallocz(s->logical_width); ++ s->skip_table = av_mallocz(s->logical_width); ++ s->length_table = av_mallocz((s->logical_width + 1)*sizeof(int)); + if (!s->skip_table || !s->length_table || !s->rlecode_table) { + av_log(avctx, AV_LOG_ERROR, "Error allocating memory.\n"); + return -1; +@@ -96,10 +102,10 @@ + return -1; + } + +- s->max_buf_size = s->avctx->width*s->avctx->height*s->pixel_size /* image base material */ +- + 15 /* header + footer */ +- + s->avctx->height*2 /* skip code+rle end */ +- + s->avctx->width/MAX_RLE_BULK + 1 /* rle codes */; ++ s->max_buf_size = s->logical_width*s->avctx->height*s->pixel_size /* image base material */ ++ + 15 /* header + footer */ ++ + s->avctx->height*2 /* skip code+rle end */ ++ + s->logical_width/MAX_RLE_BULK + 1 /* rle codes */; + avctx->coded_frame = &s->frame; + return 0; + } +@@ -109,7 +115,7 @@ + */ + static void qtrle_encode_line(QtrleEncContext *s, AVFrame *p, int line, uint8_t **buf) + { +- int width=s->avctx->width; ++ int width=s->logical_width; + int i; + signed char rlecode; + +@@ -224,12 +230,28 @@ + } + else if (rlecode > 0) { + /* bulk copy */ +- bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size); ++ if (s->avctx->pix_fmt == PIX_FMT_GRAY8) { ++ int j; ++ // QT grayscale colorspace has 0=white and 255=black, we will ++ // ignore the palette that is included in the AVFrame because ++ // PIX_FMT_GRAY8 has defined color mapping ++ for (j = 0; j < rlecode*s->pixel_size; ++j) ++ bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff); ++ } else { ++ bytestream_put_buffer(buf, this_line + i*s->pixel_size, rlecode*s->pixel_size); ++ } + i += rlecode; + } + else { + /* repeat the bits */ +- bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size); ++ if (s->avctx->pix_fmt == PIX_FMT_GRAY8) { ++ int j; ++ // QT grayscale colorspace has 0=white and 255=black, ... ++ for (j = 0; j < s->pixel_size; ++j) ++ bytestream_put_byte(buf, *(this_line + i*s->pixel_size + j) ^ 0xff); ++ } else { ++ bytestream_put_buffer(buf, this_line + i*s->pixel_size, s->pixel_size); ++ } + i -= rlecode; + } + } +@@ -245,7 +267,7 @@ + uint8_t *orig_buf = buf; + + if (!s->frame.key_frame) { +- unsigned line_size = s->avctx->width * s->pixel_size; ++ unsigned line_size = s->logical_width * s->pixel_size; + for (start_line = 0; start_line < s->avctx->height; start_line++) + if (memcmp(p->data[0] + start_line*p->linesize[0], + s->previous_frame.data[0] + start_line*s->previous_frame.linesize[0], +@@ -295,11 +317,11 @@ + + if (avctx->gop_size == 0 || (s->avctx->frame_number % avctx->gop_size) == 0) { + /* I-Frame */ +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + } else { + /* P-Frame */ +- p->pict_type = FF_P_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_P; + p->key_frame = 0; + } + +@@ -322,13 +344,13 @@ + } + + AVCodec ff_qtrle_encoder = { +- "qtrle", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_QTRLE, +- sizeof(QtrleEncContext), +- qtrle_encode_init, +- qtrle_encode_frame, +- qtrle_encode_end, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_NONE}, ++ .name = "qtrle", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_QTRLE, ++ .priv_data_size = sizeof(QtrleEncContext), ++ .init = qtrle_encode_init, ++ .encode = qtrle_encode_frame, ++ .close = qtrle_encode_end, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGB555BE, PIX_FMT_ARGB, PIX_FMT_GRAY8, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("QuickTime Animation (RLE) video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/r210dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/r210dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/r210dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/r210dec.c 2012-05-14 14:08:54.154336359 +0200 +@@ -54,15 +54,20 @@ + if (avctx->get_buffer(avctx, pic) < 0) + return -1; + +- pic->pict_type = FF_I_TYPE; ++ pic->pict_type = AV_PICTURE_TYPE_I; + pic->key_frame = 1; + dst_line = pic->data[0]; + + for (h = 0; h < avctx->height; h++) { + uint16_t *dst = (uint16_t *)dst_line; + for (w = 0; w < avctx->width; w++) { +- uint32_t pixel = av_be2ne32(*src++); ++ uint32_t pixel; + uint16_t r, g, b; ++ if (avctx->codec_id==CODEC_ID_AVRP) { ++ pixel = av_le2ne32(*src++); ++ } else { ++ pixel = av_be2ne32(*src++); ++ } + if (avctx->codec_id==CODEC_ID_R210) { + b = pixel << 6; + g = (pixel >> 4) & 0xffc0; +@@ -98,29 +103,37 @@ + + #if CONFIG_R210_DECODER + AVCodec ff_r210_decoder = { +- "r210", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_R210, +- 0, +- decode_init, +- NULL, +- decode_close, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "r210", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_R210, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), + }; + #endif + #if CONFIG_R10K_DECODER + AVCodec ff_r10k_decoder = { +- "r10k", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_R10K, +- 0, +- decode_init, +- NULL, +- decode_close, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "r10k", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_R10K, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), + }; + #endif ++#if CONFIG_AVRP_DECODER ++AVCodec ff_avrp_decoder = { ++ .name = "avrp", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AVRP, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"), ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/r210enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/r210enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/r210enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/r210enc.c 2012-05-14 14:08:54.155336379 +0200 +@@ -0,0 +1,120 @@ ++/* ++ * R210 encoder ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "bytestream.h" ++ ++static av_cold int encode_init(AVCodecContext *avctx) ++{ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++static int encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ int i, j; ++ int aligned_width = FFALIGN(avctx->width, 64); ++ uint8_t *src_line; ++ uint8_t *dst = buf; ++ ++ if (buf_size < 4 * aligned_width * avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->reference = 0; ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ src_line = pic->data[0]; ++ ++ for (i = 0; i < avctx->height; i++) { ++ uint16_t *src = (uint16_t *)src_line; ++ for (j = 0; j < avctx->width; j++) { ++ uint32_t pixel; ++ uint16_t r = *src++ >> 6; ++ uint16_t g = *src++ >> 6; ++ uint16_t b = *src++ >> 4; ++ if (avctx->codec_id == CODEC_ID_R210) ++ pixel = (r << 20) | (g << 10) | b >> 2; ++ else ++ pixel = (r << 22) | (g << 12) | b; ++ if (avctx->codec_id == CODEC_ID_AVRP) ++ bytestream_put_le32(&dst, pixel); ++ else ++ bytestream_put_be32(&dst, pixel); ++ } ++ dst += aligned_width - avctx->width; ++ src_line += pic->linesize[0]; ++ } ++ ++ return 4 * aligned_width * avctx->height; ++} ++ ++static av_cold int encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++#if CONFIG_R210_ENCODER ++AVCodec ff_r210_encoder = { ++ .name = "r210", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_R210, ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_close, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed RGB 10-bit"), ++}; ++#endif ++#if CONFIG_R10K_ENCODER ++AVCodec ff_r10k_encoder = { ++ .name = "r10k", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_R10K, ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_close, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("AJA Kona 10-bit RGB Codec"), ++}; ++#endif ++#if CONFIG_AVRP_ENCODER ++AVCodec ff_avrp_encoder = { ++ .name = "avrp", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AVRP, ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_close, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_RGB48, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Avid 1:1 10-bit RGB Packer"), ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144.c 2012-05-14 14:08:54.157336419 +0200 +@@ -1544,22 +1544,22 @@ + int ff_eval_refl(int *refl, const int16_t *coefs, AVCodecContext *avctx) + { + int b, i, j; +- int buffer1[10]; +- int buffer2[10]; ++ int buffer1[LPC_ORDER]; ++ int buffer2[LPC_ORDER]; + int *bp1 = buffer1; + int *bp2 = buffer2; + +- for (i=0; i < 10; i++) ++ for (i=0; i < LPC_ORDER; i++) + buffer2[i] = coefs[i]; + +- refl[9] = bp2[9]; ++ refl[LPC_ORDER-1] = bp2[LPC_ORDER-1]; + +- if ((unsigned) bp2[9] + 0x1000 > 0x1fff) { ++ if ((unsigned) bp2[LPC_ORDER-1] + 0x1000 > 0x1fff) { + av_log(avctx, AV_LOG_ERROR, "Overflow. Broken sample?\n"); + return 1; + } + +- for (i=8; i >= 0; i--) { ++ for (i = LPC_ORDER-2; i >= 0; i--) { + b = 0x1000-((bp2[i+1] * bp2[i+1]) >> 12); + + if (!b) +@@ -1584,12 +1584,12 @@ + */ + void ff_eval_coefs(int *coefs, const int *refl) + { +- int buffer[10]; ++ int buffer[LPC_ORDER]; + int *b1 = buffer; + int *b2 = coefs; + int i, j; + +- for (i=0; i < 10; i++) { ++ for (i=0; i < LPC_ORDER; i++) { + b1[i] = refl[i] << 4; + + for (j=0; j < i; j++) +@@ -1598,7 +1598,7 @@ + FFSWAP(int *, b1, b2); + } + +- for (i=0; i < 10; i++) ++ for (i=0; i < LPC_ORDER; i++) + coefs[i] >>= 4; + } + +@@ -1606,7 +1606,7 @@ + { + int i; + +- for (i=0; i < 10; i++) ++ for (i = 0; i < LPC_ORDER; i++) + *out++ = *inp++; + } + +@@ -1629,9 +1629,9 @@ + { + int i; + unsigned int res = 0x10000; +- int b = 10; ++ int b = LPC_ORDER; + +- for (i=0; i < 10; i++) { ++ for (i = 0; i < LPC_ORDER; i++) { + res = (((0x1000000 - data[i]*data[i]) >> 12) * res) >> 12; + + if (res == 0) +@@ -1648,13 +1648,13 @@ + + int ff_interp(RA144Context *ractx, int16_t *out, int a, int copyold, int energy) + { +- int work[10]; ++ int work[LPC_ORDER]; + int b = NBLOCKS - a; + int i; + + // Interpolate block coefficients from the this frame's forth block and + // last frame's forth block. +- for (i=0; i<10; i++) ++ for (i = 0; i < LPC_ORDER; i++) + out[i] = (a * ractx->lpc_coef[0][i] + b * ractx->lpc_coef[1][i])>> 2; + + if (ff_eval_refl(work, out, ractx->avctx)) { +@@ -1690,7 +1690,7 @@ + int cba_idx, int cb1_idx, int cb2_idx, + int gval, int gain) + { +- uint16_t buffer_a[40]; ++ uint16_t buffer_a[BLOCKSIZE]; + uint16_t *block; + int m[3]; + +@@ -1711,10 +1711,10 @@ + ff_add_wav(block, gain, cba_idx, m, cba_idx? buffer_a: NULL, + ff_cb1_vects[cb1_idx], ff_cb2_vects[cb2_idx]); + +- memcpy(ractx->curr_sblock, ractx->curr_sblock + 40, +- 10*sizeof(*ractx->curr_sblock)); ++ memcpy(ractx->curr_sblock, ractx->curr_sblock + BLOCKSIZE, ++ LPC_ORDER*sizeof(*ractx->curr_sblock)); + +- if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + 10, lpc_coefs, +- block, BLOCKSIZE, 10, 1, 0xfff)) +- memset(ractx->curr_sblock, 0, 50*sizeof(*ractx->curr_sblock)); ++ if (ff_celp_lp_synthesis_filter(ractx->curr_sblock + LPC_ORDER, lpc_coefs, ++ block, BLOCKSIZE, LPC_ORDER, 1, 0, 0xfff)) ++ memset(ractx->curr_sblock, 0, (LPC_ORDER+BLOCKSIZE)*sizeof(*ractx->curr_sblock)); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144dec.c 2012-05-14 14:08:54.158336439 +0200 +@@ -38,6 +38,10 @@ + ractx->lpc_coef[1] = ractx->lpc_tables[1]; + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&ractx->frame); ++ avctx->coded_frame = &ractx->frame; ++ + return 0; + } + +@@ -54,34 +58,40 @@ + } + + /** Uncompress one block (20 bytes -> 160*2 bytes). */ +-static int ra144_decode_frame(AVCodecContext * avctx, void *vdata, +- int *data_size, AVPacket *avpkt) ++static int ra144_decode_frame(AVCodecContext * avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; +- unsigned int refl_rms[4]; // RMS of the reflection coefficients +- uint16_t block_coefs[4][10]; // LPC coefficients of each sub-block +- unsigned int lpc_refl[10]; // LPC reflection coefficients of the frame ++ static const uint8_t sizes[LPC_ORDER] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; ++ unsigned int refl_rms[NBLOCKS]; // RMS of the reflection coefficients ++ uint16_t block_coefs[NBLOCKS][LPC_ORDER]; // LPC coefficients of each sub-block ++ unsigned int lpc_refl[LPC_ORDER]; // LPC reflection coefficients of the frame + int i, j; +- int16_t *data = vdata; ++ int ret; ++ int16_t *samples; + unsigned int energy; + + RA144Context *ractx = avctx->priv_data; + GetBitContext gb; + +- if (*data_size < 2*160) +- return -1; ++ /* get output buffer */ ++ ractx->frame.nb_samples = NBLOCKS * BLOCKSIZE; ++ if ((ret = avctx->get_buffer(avctx, &ractx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)ractx->frame.data[0]; + +- if(buf_size < 20) { ++ if(buf_size < FRAMESIZE) { + av_log(avctx, AV_LOG_ERROR, + "Frame too small (%d bytes). Truncated file?\n", buf_size); +- *data_size = 0; ++ *got_frame_ptr = 0; + return buf_size; + } +- init_get_bits(&gb, buf, 20 * 8); ++ init_get_bits(&gb, buf, FRAMESIZE * 8); + +- for (i=0; i<10; i++) ++ for (i = 0; i < LPC_ORDER; i++) + lpc_refl[i] = ff_lpc_refl_cb[i][get_bits(&gb, sizes[i])]; + + ff_eval_coefs(ractx->lpc_coef[0], lpc_refl); +@@ -98,11 +108,11 @@ + + ff_int_to_int16(block_coefs[3], ractx->lpc_coef[0]); + +- for (i=0; i < 4; i++) { ++ for (i=0; i < NBLOCKS; i++) { + do_output_subblock(ractx, block_coefs[i], refl_rms[i], &gb); + + for (j=0; j < BLOCKSIZE; j++) +- *data++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2); ++ *samples++ = av_clip_int16(ractx->curr_sblock[j + 10] << 2); + } + + ractx->old_energy = energy; +@@ -110,19 +120,19 @@ + + FFSWAP(unsigned int *, ractx->lpc_coef[0], ractx->lpc_coef[1]); + +- *data_size = 2*160; +- return 20; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ractx->frame; ++ ++ return FRAMESIZE; + } + +-AVCodec ff_ra_144_decoder = +-{ +- "real_144", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_RA_144, +- sizeof(RA144Context), +- ra144_decode_init, +- NULL, +- NULL, +- ra144_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"), ++AVCodec ff_ra_144_decoder = { ++ .name = "real_144", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_RA_144, ++ .priv_data_size = sizeof(RA144Context), ++ .init = ra144_decode_init, ++ .decode = ra144_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144enc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144enc.c 2012-05-14 14:08:54.159336459 +0200 +@@ -54,7 +54,7 @@ + ractx->lpc_coef[1] = ractx->lpc_tables[1]; + ractx->avctx = avctx; + ret = ff_lpc_init(&ractx->lpc_ctx, avctx->frame_size, LPC_ORDER, +- AV_LPC_TYPE_LEVINSON); ++ FF_LPC_TYPE_LEVINSON); + return ret; + } + +@@ -214,7 +214,7 @@ + ff_celp_lp_synthesis_filterf(work, coefs, exc, BLOCKSIZE, LPC_ORDER); + for (i = 0; i < BLOCKSIZE; i++) + data[i] -= best_gain * work[i]; +- return (best_vect - BLOCKSIZE / 2 + 1); ++ return best_vect - BLOCKSIZE / 2 + 1; + } + + +@@ -461,7 +461,7 @@ + 32)]; + + ff_lpc_calc_coefs(&ractx->lpc_ctx, lpc_data, NBLOCKS * BLOCKSIZE, LPC_ORDER, +- LPC_ORDER, 16, lpc_coefs, shift, AV_LPC_TYPE_LEVINSON, ++ LPC_ORDER, 16, lpc_coefs, shift, FF_LPC_TYPE_LEVINSON, + 0, ORDER_METHOD_EST, 12, 0); + for (i = 0; i < LPC_ORDER; i++) + block_coefs[NBLOCKS - 1][i] = -(lpc_coefs[LPC_ORDER - 1][i] << +@@ -477,7 +477,10 @@ + * The filter is unstable: use the coefficients of the previous frame. + */ + ff_int_to_int16(block_coefs[NBLOCKS - 1], ractx->lpc_coef[1]); +- ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx); ++ if (ff_eval_refl(lpc_refl, block_coefs[NBLOCKS - 1], avctx)) { ++ /* the filter is still unstable. set reflection coeffs to zero. */ ++ memset(lpc_refl, 0, sizeof(lpc_refl)); ++ } + } + init_put_bits(&pb, frame, buf_size); + for (i = 0; i < LPC_ORDER; i++) { +@@ -508,14 +511,15 @@ + } + + +-AVCodec ff_ra_144_encoder = +-{ +- "real_144", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_RA_144, +- sizeof(RA144Context), +- ra144_encode_init, +- ra144_encode_frame, +- ra144_encode_close, +- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K) encoder"), ++AVCodec ff_ra_144_encoder = { ++ .name = "real_144", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_RA_144, ++ .priv_data_size = sizeof(RA144Context), ++ .init = ra144_encode_init, ++ .encode = ra144_encode_frame, ++ .close = ra144_encode_close, ++ .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 1.0 (14.4K) encoder"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra144.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra144.h 2012-05-14 14:08:54.157336419 +0200 +@@ -34,6 +34,7 @@ + + typedef struct { + AVCodecContext *avctx; ++ AVFrame frame; + LPCContext lpc_ctx; + + unsigned int old_energy; ///< previous frame energy +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra288.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra288.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra288.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra288.c 2012-05-14 14:08:54.160336479 +0200 +@@ -20,20 +20,26 @@ + */ + + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "ra288.h" + #include "lpc.h" + #include "celp_math.h" + #include "celp_filters.h" ++#include "dsputil.h" + + #define MAX_BACKWARD_FILTER_ORDER 36 + #define MAX_BACKWARD_FILTER_LEN 40 + #define MAX_BACKWARD_FILTER_NONREC 35 + ++#define RA288_BLOCK_SIZE 5 ++#define RA288_BLOCKS_PER_FRAME 32 ++ + typedef struct { +- float sp_lpc[36]; ///< LPC coefficients for speech data (spec: A) +- float gain_lpc[10]; ///< LPC coefficients for gain (spec: GB) ++ AVFrame frame; ++ DSPContext dsp; ++ DECLARE_ALIGNED(16, float, sp_lpc)[FFALIGN(36, 8)]; ///< LPC coefficients for speech data (spec: A) ++ DECLARE_ALIGNED(16, float, gain_lpc)[FFALIGN(10, 8)]; ///< LPC coefficients for gain (spec: GB) + + /** speech data history (spec: SB). + * Its first 70 coefficients are updated only at backward filtering. +@@ -54,14 +60,14 @@ + + static av_cold int ra288_decode_init(AVCodecContext *avctx) + { ++ RA288Context *ractx = avctx->priv_data; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; +- return 0; +-} ++ dsputil_init(&ractx->dsp, avctx); + +-static void apply_window(float *tgt, const float *m1, const float *m2, int n) +-{ +- while (n--) +- *tgt++ = *m1++ * *m2++; ++ avcodec_get_frame_defaults(&ractx->frame); ++ avctx->coded_frame = &ractx->frame; ++ ++ return 0; + } + + static void convolve(float *tgt, const float *src, int len, int n) +@@ -96,14 +102,14 @@ + for (i=0; i < 5; i++) + buffer[i] = codetable[cb_coef][i] * sumsum; + +- sum = ff_dot_productf(buffer, buffer, 5) * ((1<<24)/5.); ++ sum = ff_dot_productf(buffer, buffer, 5); + +- sum = FFMAX(sum, 1); ++ sum = FFMAX(sum, 5. / (1<<24)); + + /* shift and store */ + memmove(gain_block, gain_block + 1, 9 * sizeof(*gain_block)); + +- gain_block[9] = 10 * log10(sum) - 32; ++ gain_block[9] = 10 * log10(sum) + (10*log10(((1<<24)/5.)) - 32); + + ff_celp_lp_synthesis_filterf(block, ractx->sp_lpc, buffer, 5, 36); + } +@@ -120,15 +126,18 @@ + * @param out2 pointer to the recursive part of the output + * @param window pointer to the windowing function table + */ +-static void do_hybrid_window(int order, int n, int non_rec, float *out, ++static void do_hybrid_window(RA288Context *ractx, ++ int order, int n, int non_rec, float *out, + float *hist, float *out2, const float *window) + { + int i; + float buffer1[MAX_BACKWARD_FILTER_ORDER + 1]; + float buffer2[MAX_BACKWARD_FILTER_ORDER + 1]; +- float work[MAX_BACKWARD_FILTER_ORDER + MAX_BACKWARD_FILTER_LEN + MAX_BACKWARD_FILTER_NONREC]; ++ LOCAL_ALIGNED_16(float, work, [FFALIGN(MAX_BACKWARD_FILTER_ORDER + ++ MAX_BACKWARD_FILTER_LEN + ++ MAX_BACKWARD_FILTER_NONREC, 8)]); + +- apply_window(work, window, hist, order + n + non_rec); ++ ractx->dsp.vector_fmul(work, window, hist, FFALIGN(order + n + non_rec, 8)); + + convolve(buffer1, work + order , n , order); + convolve(buffer2, work + order + n, non_rec, order); +@@ -145,27 +154,28 @@ + /** + * Backward synthesis filter, find the LPC coefficients from past speech data. + */ +-static void backward_filter(float *hist, float *rec, const float *window, ++static void backward_filter(RA288Context *ractx, ++ float *hist, float *rec, const float *window, + float *lpc, const float *tab, + int order, int n, int non_rec, int move_size) + { + float temp[MAX_BACKWARD_FILTER_ORDER+1]; + +- do_hybrid_window(order, n, non_rec, temp, hist, rec, window); ++ do_hybrid_window(ractx, order, n, non_rec, temp, hist, rec, window); + + if (!compute_lpc_coefs(temp, order, lpc, 0, 1, 1)) +- apply_window(lpc, lpc, tab, order); ++ ractx->dsp.vector_fmul(lpc, lpc, tab, FFALIGN(order, 8)); + + memmove(hist, hist + n, move_size*sizeof(*hist)); + } + + static int ra288_decode_frame(AVCodecContext * avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; +- float *out = data; +- int i, j; ++ float *out; ++ int i, ret; + RA288Context *ractx = avctx->priv_data; + GetBitContext gb; + +@@ -173,45 +183,50 @@ + av_log(avctx, AV_LOG_ERROR, + "Error! Input buffer is too small [%d<%d]\n", + buf_size, avctx->block_align); +- return 0; ++ return AVERROR_INVALIDDATA; + } + +- if (*data_size < 32*5*4) +- return -1; ++ /* get output buffer */ ++ ractx->frame.nb_samples = RA288_BLOCK_SIZE * RA288_BLOCKS_PER_FRAME; ++ if ((ret = avctx->get_buffer(avctx, &ractx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out = (float *)ractx->frame.data[0]; + + init_get_bits(&gb, buf, avctx->block_align * 8); + +- for (i=0; i < 32; i++) { ++ for (i=0; i < RA288_BLOCKS_PER_FRAME; i++) { + float gain = amptable[get_bits(&gb, 3)]; + int cb_coef = get_bits(&gb, 6 + (i&1)); + + decode(ractx, gain, cb_coef); + +- for (j=0; j < 5; j++) +- *(out++) = ractx->sp_hist[70 + 36 + j]; ++ memcpy(out, &ractx->sp_hist[70 + 36], RA288_BLOCK_SIZE * sizeof(*out)); ++ out += RA288_BLOCK_SIZE; + + if ((i & 7) == 3) { +- backward_filter(ractx->sp_hist, ractx->sp_rec, syn_window, ++ backward_filter(ractx, ractx->sp_hist, ractx->sp_rec, syn_window, + ractx->sp_lpc, syn_bw_tab, 36, 40, 35, 70); + +- backward_filter(ractx->gain_hist, ractx->gain_rec, gain_window, ++ backward_filter(ractx, ractx->gain_hist, ractx->gain_rec, gain_window, + ractx->gain_lpc, gain_bw_tab, 10, 8, 20, 28); + } + } + +- *data_size = (char *)out - (char *)data; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ractx->frame; ++ + return avctx->block_align; + } + +-AVCodec ff_ra_288_decoder = +-{ +- "real_288", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_RA_288, +- sizeof(RA288Context), +- ra288_decode_init, +- NULL, +- NULL, +- ra288_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("RealAudio 2.0 (28.8K)"), ++AVCodec ff_ra_288_decoder = { ++ .name = "real_288", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_RA_288, ++ .priv_data_size = sizeof(RA288Context), ++ .init = ra288_decode_init, ++ .decode = ra288_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("RealAudio 2.0 (28.8K)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra288.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra288.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ra288.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ra288.h 2012-05-14 14:08:54.161336500 +0200 +@@ -23,6 +23,7 @@ + #define AVCODEC_RA288_H + + #include ++#include "dsputil.h" + + static const float amptable[8]={ + 0.515625, 0.90234375, 1.57910156, 2.76342773, +@@ -96,7 +97,7 @@ + { 3746, -606, 53, -269, -3301}, { 606, 2018, -1316, 4064, 398} + }; + +-static const float syn_window[111]={ ++DECLARE_ALIGNED(16, static const float, syn_window)[FFALIGN(111, 8)]={ + 0.576690972, 0.580838025, 0.585013986, 0.589219987, 0.59345597, 0.597723007, + 0.602020264, 0.606384277, 0.610748291, 0.615142822, 0.619598389, 0.624084473, + 0.628570557, 0.633117676, 0.637695313, 0.642272949, 0.646911621, 0.651580811, +@@ -118,7 +119,7 @@ + 0.142852783, 0.0954284668,0.0477600098 + }; + +-static const float gain_window[38]={ ++DECLARE_ALIGNED(16, static const float, gain_window)[FFALIGN(38, 8)]={ + 0.505699992, 0.524200022, 0.54339999, 0.563300014, 0.583953857, 0.60534668, + 0.627502441, 0.650482178, 0.674316406, 0.699005127, 0.724578857, 0.75112915, + 0.778625488, 0.807128906, 0.836669922, 0.86730957, 0.899078369, 0.932006836, +@@ -129,7 +130,7 @@ + }; + + /** synthesis bandwidth broadening table */ +-static const float syn_bw_tab[36]={ ++DECLARE_ALIGNED(16, static const float, syn_bw_tab)[FFALIGN(36, 8)] = { + 0.98828125, 0.976699829, 0.965254128, 0.953942537, 0.942763507, 0.931715488, + 0.920796931, 0.910006344, 0.899342179, 0.888803005, 0.878387332, 0.868093729, + 0.857920766, 0.847867012, 0.837931097, 0.828111589, 0.818407178, 0.808816493, +@@ -139,7 +140,7 @@ + }; + + /** gain bandwidth broadening table */ +-static const float gain_bw_tab[10]={ ++DECLARE_ALIGNED(16, static const float, gain_bw_tab)[FFALIGN(10, 8)] = { + 0.90625, 0.821289063, 0.74432373, 0.674499512, 0.61126709, + 0.553955078, 0.50201416, 0.454956055, 0.41229248, 0.373657227 + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ratecontrol.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ratecontrol.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ratecontrol.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ratecontrol.c 2012-05-14 14:08:54.163336541 +0200 +@@ -44,9 +44,9 @@ + + void ff_write_pass1_stats(MpegEncContext *s){ + snprintf(s->avctx->stats_out, 256, "in:%d out:%d type:%d q:%d itex:%d ptex:%d mv:%d misc:%d fcode:%d bcode:%d mc-var:%d var:%d icount:%d skipcount:%d hbits:%d;\n", +- s->current_picture_ptr->display_picture_number, s->current_picture_ptr->coded_picture_number, s->pict_type, +- s->current_picture.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits, +- s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits); ++ s->current_picture_ptr->f.display_picture_number, s->current_picture_ptr->f.coded_picture_number, s->pict_type, ++ s->current_picture.f.quality, s->i_tex_bits, s->p_tex_bits, s->mv_bits, s->misc_bits, ++ s->f_code, s->b_code, s->current_picture.mc_mb_var_sum, s->current_picture.mb_var_sum, s->i_count, s->skip_count, s->header_bits); + } + + static inline double qp2bits(RateControlEntry *rce, double qp){ +@@ -125,6 +125,8 @@ + rcc->last_qscale_for[i]=FF_QP2LAMBDA * 5; + } + rcc->buffer_index= s->avctx->rc_initial_buffer_occupancy; ++ if (!rcc->buffer_index) ++ rcc->buffer_index = s->avctx->rc_buffer_size * 3 / 4; + + if(s->flags&CODEC_FLAG_PASS2){ + int i; +@@ -144,7 +146,7 @@ + /* init all to skipped p frames (with b frames we might have a not encoded frame at the end FIXME) */ + for(i=0; inum_entries; i++){ + RateControlEntry *rce= &rcc->entry[i]; +- rce->pict_type= rce->new_pict_type=FF_P_TYPE; ++ rce->pict_type= rce->new_pict_type=AV_PICTURE_TYPE_P; + rce->qscale= rce->new_qscale=FF_QP2LAMBDA * 2; + rce->misc_bits= s->mb_num + 10; + rce->mb_var_sum= s->mb_num*100; +@@ -211,9 +213,9 @@ + double bits= s->avctx->rc_initial_cplx * (i/10000.0 + 1.0)*s->mb_num; + RateControlEntry rce; + +- if (i%((s->gop_size+3)/4)==0) rce.pict_type= FF_I_TYPE; +- else if(i%(s->max_b_frames+1)) rce.pict_type= FF_B_TYPE; +- else rce.pict_type= FF_P_TYPE; ++ if (i%((s->gop_size+3)/4)==0) rce.pict_type= AV_PICTURE_TYPE_I; ++ else if(i%(s->max_b_frames+1)) rce.pict_type= AV_PICTURE_TYPE_B; ++ else rce.pict_type= AV_PICTURE_TYPE_P; + + rce.new_pict_type= rce.pict_type; + rce.mc_mb_var_sum= bits*s->mb_num/100000; +@@ -223,7 +225,7 @@ + rce.b_code = 1; + rce.misc_bits= 1; + +- if(s->pict_type== FF_I_TYPE){ ++ if(s->pict_type== AV_PICTURE_TYPE_I){ + rce.i_count = s->mb_num; + rce.i_tex_bits= bits; + rce.p_tex_bits= 0; +@@ -300,7 +302,7 @@ + } + + /** +- * modifies the bitrate curve from pass1 for one frame ++ * Modify the bitrate curve from pass1 for one frame. + */ + static double get_qscale(MpegEncContext *s, RateControlEntry *rce, double rate_factor, int frame_num){ + RateControlContext *rcc= &s->rc_context; +@@ -317,23 +319,23 @@ + rce->p_tex_bits*rce->qscale, + (rce->i_tex_bits + rce->p_tex_bits)*(double)rce->qscale, + rce->mv_bits/mb_num, +- rce->pict_type == FF_B_TYPE ? (rce->f_code + rce->b_code)*0.5 : rce->f_code, ++ rce->pict_type == AV_PICTURE_TYPE_B ? (rce->f_code + rce->b_code)*0.5 : rce->f_code, + rce->i_count/mb_num, + rce->mc_mb_var_sum/mb_num, + rce->mb_var_sum/mb_num, +- rce->pict_type == FF_I_TYPE, +- rce->pict_type == FF_P_TYPE, +- rce->pict_type == FF_B_TYPE, ++ rce->pict_type == AV_PICTURE_TYPE_I, ++ rce->pict_type == AV_PICTURE_TYPE_P, ++ rce->pict_type == AV_PICTURE_TYPE_B, + rcc->qscale_sum[pict_type] / (double)rcc->frame_count[pict_type], + a->qcompress, +-/* rcc->last_qscale_for[FF_I_TYPE], +- rcc->last_qscale_for[FF_P_TYPE], +- rcc->last_qscale_for[FF_B_TYPE], ++/* rcc->last_qscale_for[AV_PICTURE_TYPE_I], ++ rcc->last_qscale_for[AV_PICTURE_TYPE_P], ++ rcc->last_qscale_for[AV_PICTURE_TYPE_B], + rcc->next_non_b_qscale,*/ +- rcc->i_cplx_sum[FF_I_TYPE] / (double)rcc->frame_count[FF_I_TYPE], +- rcc->i_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE], +- rcc->p_cplx_sum[FF_P_TYPE] / (double)rcc->frame_count[FF_P_TYPE], +- rcc->p_cplx_sum[FF_B_TYPE] / (double)rcc->frame_count[FF_B_TYPE], ++ rcc->i_cplx_sum[AV_PICTURE_TYPE_I] / (double)rcc->frame_count[AV_PICTURE_TYPE_I], ++ rcc->i_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P], ++ rcc->p_cplx_sum[AV_PICTURE_TYPE_P] / (double)rcc->frame_count[AV_PICTURE_TYPE_P], ++ rcc->p_cplx_sum[AV_PICTURE_TYPE_B] / (double)rcc->frame_count[AV_PICTURE_TYPE_B], + (rcc->i_cplx_sum[pict_type] + rcc->p_cplx_sum[pict_type]) / (double)rcc->frame_count[pict_type], + 0 + }; +@@ -364,9 +366,9 @@ + q= bits2qp(rce, bits); + + /* I/B difference */ +- if (pict_type==FF_I_TYPE && s->avctx->i_quant_factor<0.0) ++ if (pict_type==AV_PICTURE_TYPE_I && s->avctx->i_quant_factor<0.0) + q= -q*s->avctx->i_quant_factor + s->avctx->i_quant_offset; +- else if(pict_type==FF_B_TYPE && s->avctx->b_quant_factor<0.0) ++ else if(pict_type==AV_PICTURE_TYPE_B && s->avctx->b_quant_factor<0.0) + q= -q*s->avctx->b_quant_factor + s->avctx->b_quant_offset; + if(q<1) q=1; + +@@ -377,17 +379,17 @@ + RateControlContext *rcc= &s->rc_context; + AVCodecContext *a= s->avctx; + const int pict_type= rce->new_pict_type; +- const double last_p_q = rcc->last_qscale_for[FF_P_TYPE]; ++ const double last_p_q = rcc->last_qscale_for[AV_PICTURE_TYPE_P]; + const double last_non_b_q= rcc->last_qscale_for[rcc->last_non_b_pict_type]; + +- if (pict_type==FF_I_TYPE && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==FF_P_TYPE)) ++ if (pict_type==AV_PICTURE_TYPE_I && (a->i_quant_factor>0.0 || rcc->last_non_b_pict_type==AV_PICTURE_TYPE_P)) + q= last_p_q *FFABS(a->i_quant_factor) + a->i_quant_offset; +- else if(pict_type==FF_B_TYPE && a->b_quant_factor>0.0) ++ else if(pict_type==AV_PICTURE_TYPE_B && a->b_quant_factor>0.0) + q= last_non_b_q* a->b_quant_factor + a->b_quant_offset; + if(q<1) q=1; + + /* last qscale / qdiff stuff */ +- if(rcc->last_non_b_pict_type==pict_type || pict_type!=FF_I_TYPE){ ++ if(rcc->last_non_b_pict_type==pict_type || pict_type!=AV_PICTURE_TYPE_I){ + double last_q= rcc->last_qscale_for[pict_type]; + const int maxdiff= FF_QP2LAMBDA * a->max_qdiff; + +@@ -397,14 +399,14 @@ + + rcc->last_qscale_for[pict_type]= q; //Note we cannot do that after blurring + +- if(pict_type!=FF_B_TYPE) ++ if(pict_type!=AV_PICTURE_TYPE_B) + rcc->last_non_b_pict_type= pict_type; + + return q; + } + + /** +- * gets the qmin & qmax for pict_type ++ * Get the qmin & qmax for pict_type. + */ + static void get_qminmax(int *qmin_ret, int *qmax_ret, MpegEncContext *s, int pict_type){ + int qmin= s->avctx->lmin; +@@ -412,10 +414,10 @@ + + assert(qmin <= qmax); + +- if(pict_type==FF_B_TYPE){ ++ if(pict_type==AV_PICTURE_TYPE_B){ + qmin= (int)(qmin*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5); + qmax= (int)(qmax*FFABS(s->avctx->b_quant_factor)+s->avctx->b_quant_offset + 0.5); +- }else if(pict_type==FF_I_TYPE){ ++ }else if(pict_type==AV_PICTURE_TYPE_I){ + qmin= (int)(qmin*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5); + qmax= (int)(qmax*FFABS(s->avctx->i_quant_factor)+s->avctx->i_quant_offset + 0.5); + } +@@ -441,7 +443,7 @@ + get_qminmax(&qmin, &qmax, s, pict_type); + + /* modulation */ +- if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==FF_P_TYPE) ++ if(s->avctx->rc_qmod_freq && frame_num%s->avctx->rc_qmod_freq==0 && pict_type==AV_PICTURE_TYPE_P) + q*= s->avctx->rc_qmod_amp; + + //printf("q:%f\n", q); +@@ -537,8 +539,8 @@ + const float border_masking = s->avctx->border_masking; + float bits_sum= 0.0; + float cplx_sum= 0.0; +- float cplx_tab[s->mb_num]; +- float bits_tab[s->mb_num]; ++ float *cplx_tab = av_malloc(s->mb_num * sizeof(*cplx_tab)); ++ float *bits_tab = av_malloc(s->mb_num * sizeof(*bits_tab)); + const int qmin= s->avctx->mb_lmin; + const int qmax= s->avctx->mb_lmax; + Picture * const pic= &s->current_picture; +@@ -639,6 +641,9 @@ + //printf("%2d%3d ", intq, ff_sqrt(s->mc_mb_var[i])); + s->lambda_table[mb_xy]= intq; + } ++ ++ av_free(cplx_tab); ++ av_free(bits_tab); + } + + void ff_get_2pass_fcode(MpegEncContext *s){ +@@ -684,7 +689,7 @@ + //printf("input_pic_num:%d pic_num:%d frame_rate:%d\n", s->input_picture_number, s->picture_number, s->frame_rate); + /* update predictors */ + if(picture_number>2 && !dry_run){ +- const int last_var= s->last_pict_type == FF_I_TYPE ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum; ++ const int last_var= s->last_pict_type == AV_PICTURE_TYPE_I ? rcc->last_mb_var_sum : rcc->last_mc_mb_var_sum; + update_predictor(&rcc->pred[s->last_pict_type], rcc->last_qscale, sqrt(last_var), s->frame_bits); + } + +@@ -699,29 +704,29 @@ + + //FIXME add a dts field to AVFrame and ensure its set and use it here instead of reordering + //but the reordering is simpler for now until h.264 b pyramid must be handeld +- if(s->pict_type == FF_B_TYPE || s->low_delay) ++ if(s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) + dts_pic= s->current_picture_ptr; + else + dts_pic= s->last_picture_ptr; + + //if(dts_pic) +-// av_log(NULL, AV_LOG_ERROR, "%Ld %Ld %Ld %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); ++// av_log(NULL, AV_LOG_ERROR, "%"PRId64" %"PRId64" %"PRId64" %d\n", s->current_picture_ptr->pts, s->user_specified_pts, dts_pic->pts, picture_number); + +- if(!dts_pic || dts_pic->pts == AV_NOPTS_VALUE) ++ if (!dts_pic || dts_pic->f.pts == AV_NOPTS_VALUE) + wanted_bits= (uint64_t)(s->bit_rate*(double)picture_number/fps); + else +- wanted_bits= (uint64_t)(s->bit_rate*(double)dts_pic->pts/fps); ++ wanted_bits = (uint64_t)(s->bit_rate*(double)dts_pic->f.pts / fps); + } + + diff= s->total_bits - wanted_bits; + br_compensation= (a->bit_rate_tolerance - diff)/a->bit_rate_tolerance; + if(br_compensation<=0.0) br_compensation=0.001; + +- var= pict_type == FF_I_TYPE ? pic->mb_var_sum : pic->mc_mb_var_sum; ++ var= pict_type == AV_PICTURE_TYPE_I ? pic->mb_var_sum : pic->mc_mb_var_sum; + + short_term_q = 0; /* avoid warning */ + if(s->flags&CODEC_FLAG_PASS2){ +- if(pict_type!=FF_I_TYPE) ++ if(pict_type!=AV_PICTURE_TYPE_I) + assert(pict_type == rce->new_pict_type); + + q= rce->new_qscale / br_compensation; +@@ -737,7 +742,7 @@ + rce->misc_bits= 1; + + bits= predict_size(&rcc->pred[pict_type], rce->qscale, sqrt(var)); +- if(pict_type== FF_I_TYPE){ ++ if(pict_type== AV_PICTURE_TYPE_I){ + rce->i_count = s->mb_num; + rce->i_tex_bits= bits; + rce->p_tex_bits= 0; +@@ -767,7 +772,7 @@ + //printf("%f ", q); + assert(q>0.0); + +- if(pict_type==FF_P_TYPE || s->intra_only){ //FIXME type dependent blur like in 2-pass ++ if(pict_type==AV_PICTURE_TYPE_P || s->intra_only){ //FIXME type dependent blur like in 2-pass + rcc->short_term_qsum*=a->qblur; + rcc->short_term_qcount*=a->qblur; + +@@ -788,7 +793,7 @@ + + if(s->avctx->debug&FF_DEBUG_RC){ + av_log(s->avctx, AV_LOG_DEBUG, "%c qp:%d<%2.1f<%d %d want:%d total:%d comp:%f st_q:%2.2f size:%d var:%d/%d br:%d fps:%d\n", +- av_get_pict_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000, ++ av_get_picture_type_char(pict_type), qmin, q, qmax, picture_number, (int)wanted_bits/1000, (int)s->total_bits/1000, + br_compensation, short_term_q, s->frame_bits, pic->mb_var_sum, pic->mc_mb_var_sum, s->bit_rate/1000, (int)fps + ); + } +@@ -806,14 +811,6 @@ + rcc->last_mc_mb_var_sum= pic->mc_mb_var_sum; + rcc->last_mb_var_sum= pic->mb_var_sum; + } +-#if 0 +-{ +- static int mvsum=0, texsum=0; +- mvsum += s->mv_bits; +- texsum += s->i_tex_bits + s->p_tex_bits; +- printf("%d %d//\n\n", mvsum, texsum); +-} +-#endif + return q; + } + +@@ -850,7 +847,7 @@ + complexity[rce->new_pict_type]+= (rce->i_tex_bits+ rce->p_tex_bits)*(double)rce->qscale; + const_bits[rce->new_pict_type]+= rce->mv_bits + rce->misc_bits; + } +- all_const_bits= const_bits[FF_I_TYPE] + const_bits[FF_P_TYPE] + const_bits[FF_B_TYPE]; ++ all_const_bits= const_bits[AV_PICTURE_TYPE_I] + const_bits[AV_PICTURE_TYPE_P] + const_bits[AV_PICTURE_TYPE_B]; + + if(all_available_bits < all_const_bits){ + av_log(s->avctx, AV_LOG_ERROR, "requested bitrate is too low\n"); +@@ -869,11 +866,19 @@ + + /* find qscale */ + for(i=0; inum_entries; i++){ ++ RateControlEntry *rce= &rcc->entry[i]; + qscale[i]= get_qscale(s, &rcc->entry[i], rate_factor, i); ++ rcc->last_qscale_for[rce->pict_type] = qscale[i]; + } + assert(filter_size%2==1); + + /* fixed I/B QP relative to P mode */ ++ for(i=FFMAX(0, rcc->num_entries-300); inum_entries; i++){ ++ RateControlEntry *rce= &rcc->entry[i]; ++ ++ qscale[i]= get_diff_limited_q(s, rce, qscale[i]); ++ } ++ + for(i=rcc->num_entries-1; i>=0; i--){ + RateControlEntry *rce= &rcc->entry[i]; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/raw.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/raw.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/raw.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/raw.c 2012-05-14 14:08:54.164336561 +0200 +@@ -36,6 +36,7 @@ + { PIX_FMT_YUV411P, MKTAG('Y', '4', '1', 'B') }, + { PIX_FMT_YUV422P, MKTAG('Y', '4', '2', 'B') }, + { PIX_FMT_YUV422P, MKTAG('P', '4', '2', '2') }, ++ { PIX_FMT_YUV422P, MKTAG('Y', 'V', '1', '6') }, + /* yuvjXXX formats are deprecated hacks specific to libav*, + they are identical to yuvXXX */ + { PIX_FMT_YUVJ420P, MKTAG('I', '4', '2', '0') }, /* Planar formats */ +@@ -44,7 +45,7 @@ + { PIX_FMT_YUVJ422P, MKTAG('Y', '4', '2', 'B') }, + { PIX_FMT_YUVJ422P, MKTAG('P', '4', '2', '2') }, + { PIX_FMT_GRAY8, MKTAG('Y', '8', '0', '0') }, +- { PIX_FMT_GRAY8, MKTAG(' ', ' ', 'Y', '8') }, ++ { PIX_FMT_GRAY8, MKTAG('Y', '8', ' ', ' ') }, + + { PIX_FMT_YUYV422, MKTAG('Y', 'U', 'Y', '2') }, /* Packed formats */ + { PIX_FMT_YUYV422, MKTAG('Y', '4', '2', '2') }, +@@ -61,6 +62,8 @@ + { PIX_FMT_UYVY422, MKTAG('A', 'V', '1', 'x') }, /* Avid 1:1x */ + { PIX_FMT_UYVY422, MKTAG('A', 'V', 'u', 'p') }, + { PIX_FMT_UYVY422, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */ ++ { PIX_FMT_UYVY422, MKTAG('a', 'u', 'v', '2') }, ++ { PIX_FMT_UYVY422, MKTAG('c', 'y', 'u', 'v') }, /* CYUV is also Creative YUV */ + { PIX_FMT_UYYVYY411, MKTAG('Y', '4', '1', '1') }, + { PIX_FMT_GRAY8, MKTAG('G', 'R', 'E', 'Y') }, + { PIX_FMT_NV12, MKTAG('N', 'V', '1', '2') }, +@@ -102,8 +105,16 @@ + { PIX_FMT_BGR4_BYTE,MKTAG('R', '4', 'B', 'Y') }, + { PIX_FMT_RGB48LE, MKTAG('R', 'G', 'B', 48 ) }, + { PIX_FMT_RGB48BE, MKTAG( 48, 'R', 'G', 'B') }, ++ { PIX_FMT_BGR48LE, MKTAG('B', 'G', 'R', 48 ) }, ++ { PIX_FMT_BGR48BE, MKTAG( 48, 'B', 'G', 'R') }, + { PIX_FMT_GRAY16LE, MKTAG('Y', '1', 0 , 16 ) }, + { PIX_FMT_GRAY16BE, MKTAG(16 , 0 , '1', 'Y') }, ++ { PIX_FMT_YUV420P10LE, MKTAG('Y', '3', 11 , 10 ) }, ++ { PIX_FMT_YUV420P10BE, MKTAG(10 , 11 , '3', 'Y') }, ++ { PIX_FMT_YUV422P10LE, MKTAG('Y', '3', 10 , 10 ) }, ++ { PIX_FMT_YUV422P10BE, MKTAG(10 , 10 , '3', 'Y') }, ++ { PIX_FMT_YUV444P10LE, MKTAG('Y', '3', 0 , 10 ) }, ++ { PIX_FMT_YUV444P10BE, MKTAG(10 , 0 , '3', 'Y') }, + { PIX_FMT_YUV420P16LE, MKTAG('Y', '3', 11 , 16 ) }, + { PIX_FMT_YUV420P16BE, MKTAG(16 , 11 , '3', 'Y') }, + { PIX_FMT_YUV422P16LE, MKTAG('Y', '3', 10 , 16 ) }, +@@ -111,7 +122,7 @@ + { PIX_FMT_YUV444P16LE, MKTAG('Y', '3', 0 , 16 ) }, + { PIX_FMT_YUV444P16BE, MKTAG(16 , 0 , '3', 'Y') }, + { PIX_FMT_YUVA420P, MKTAG('Y', '4', 11 , 8 ) }, +- { PIX_FMT_Y400A, MKTAG('Y', '2', 0 , 8 ) }, ++ { PIX_FMT_GRAY8A, MKTAG('Y', '2', 0 , 8 ) }, + + /* quicktime */ + { PIX_FMT_UYVY422, MKTAG('2', 'v', 'u', 'y') }, +@@ -119,7 +130,7 @@ + { PIX_FMT_UYVY422, MKTAG('A', 'V', 'U', 'I') }, /* FIXME merge both fields */ + { PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', '2') }, + { PIX_FMT_YUYV422, MKTAG('y', 'u', 'v', 's') }, +- { PIX_FMT_PAL8, MKTAG('W', 'R', 'A', 'W') }, ++ { PIX_FMT_YUYV422, MKTAG('D', 'V', 'O', 'O') }, /* Digital Voodoo SD 8 Bit */ + { PIX_FMT_RGB555LE,MKTAG('L', '5', '5', '5') }, + { PIX_FMT_RGB565LE,MKTAG('L', '5', '6', '5') }, + { PIX_FMT_RGB565BE,MKTAG('B', '5', '6', '5') }, +@@ -132,6 +143,7 @@ + + /* special */ + { PIX_FMT_RGB565LE,MKTAG( 3 , 0 , 0 , 0 ) }, /* flipped RGB565LE */ ++ { PIX_FMT_YUV444P, MKTAG('Y', 'V', '2', '4') }, /* YUV444P, swapped UV */ + + { PIX_FMT_NONE, 0 }, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rawdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rawdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rawdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rawdec.c 2012-05-14 14:08:54.166336601 +0200 +@@ -28,25 +28,35 @@ + #include "imgconvert.h" + #include "raw.h" + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/internal.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/opt.h" + + typedef struct RawVideoContext { ++ AVClass *av_class; + uint32_t palette[AVPALETTE_COUNT]; + unsigned char * buffer; /* block of memory for holding one frame */ + int length; /* number of bytes in buffer */ + int flip; + AVFrame pic; ///< AVCodecContext.coded_frame ++ int tff; + } RawVideoContext; + ++static const AVOption options[]={ ++{"top", "top field first", offsetof(RawVideoContext, tff), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM|AV_OPT_FLAG_VIDEO_PARAM}, ++{NULL} ++}; ++static const AVClass class = { "rawdec", NULL, options, LIBAVUTIL_VERSION_INT }; ++ + static const PixelFormatTag pix_fmt_bps_avi[] = { ++ { PIX_FMT_MONOWHITE, 1 }, ++ { PIX_FMT_PAL8, 2 }, + { PIX_FMT_PAL8, 4 }, + { PIX_FMT_PAL8, 8 }, + { PIX_FMT_RGB444, 12 }, + { PIX_FMT_RGB555, 15 }, + { PIX_FMT_RGB555, 16 }, + { PIX_FMT_BGR24, 24 }, +- { PIX_FMT_RGB32, 32 }, ++ { PIX_FMT_BGRA, 32 }, + { PIX_FMT_NONE, 0 }, + }; + +@@ -60,10 +70,11 @@ + { PIX_FMT_RGB555BE, 16 }, + { PIX_FMT_RGB24, 24 }, + { PIX_FMT_ARGB, 32 }, ++ { PIX_FMT_MONOWHITE,33 }, + { PIX_FMT_NONE, 0 }, + }; + +-static enum PixelFormat find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc) ++enum PixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc) + { + while (tags->pix_fmt >= 0) { + if (tags->fourcc == fourcc) +@@ -78,28 +89,38 @@ + RawVideoContext *context = avctx->priv_data; + + if (avctx->codec_tag == MKTAG('r','a','w',' ')) +- avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_mov, avctx->bits_per_coded_sample); ++ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_mov, avctx->bits_per_coded_sample); ++ else if (avctx->codec_tag == MKTAG('W','R','A','W')) ++ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); + else if (avctx->codec_tag) +- avctx->pix_fmt = find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); ++ avctx->pix_fmt = ff_find_pix_fmt(ff_raw_pix_fmt_tags, avctx->codec_tag); + else if (avctx->pix_fmt == PIX_FMT_NONE && avctx->bits_per_coded_sample) +- avctx->pix_fmt = find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); ++ avctx->pix_fmt = ff_find_pix_fmt(pix_fmt_bps_avi, avctx->bits_per_coded_sample); ++ ++ if (avctx->pix_fmt == PIX_FMT_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "Pixel format was not specified and cannot be detected\n"); ++ return AVERROR(EINVAL); ++ } + + ff_set_systematic_pal2(context->palette, avctx->pix_fmt); +- context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); + if((avctx->bits_per_coded_sample == 4 || avctx->bits_per_coded_sample == 2) && + avctx->pix_fmt==PIX_FMT_PAL8 && + (!avctx->codec_tag || avctx->codec_tag == MKTAG('r','a','w',' '))){ ++ context->length = avpicture_get_size(avctx->pix_fmt, FFALIGN(avctx->width, 16), avctx->height); + context->buffer = av_malloc(context->length); + if (!context->buffer) + return -1; ++ } else { ++ context->length = avpicture_get_size(avctx->pix_fmt, avctx->width, avctx->height); + } +- context->pic.pict_type = FF_I_TYPE; ++ context->pic.pict_type = AV_PICTURE_TYPE_I; + context->pic.key_frame = 1; + + avctx->coded_frame= &context->pic; + + if((avctx->extradata_size >= 9 && !memcmp(avctx->extradata + avctx->extradata_size - 9, "BottomUp", 9)) || +- avctx->codec_tag == MKTAG( 3 , 0 , 0 , 0 )) ++ avctx->codec_tag == MKTAG('c','y','u','v') || ++ avctx->codec_tag == MKTAG(3, 0, 0, 0) || avctx->codec_tag == MKTAG('W','R','A','W')) + context->flip=1; + + return 0; +@@ -116,15 +137,26 @@ + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; ++ int linesize_align = 4; + RawVideoContext *context = avctx->priv_data; + + AVFrame * frame = (AVFrame *) data; + AVPicture * picture = (AVPicture *) data; + ++ frame->pict_type = avctx->coded_frame->pict_type; + frame->interlaced_frame = avctx->coded_frame->interlaced_frame; + frame->top_field_first = avctx->coded_frame->top_field_first; + frame->reordered_opaque = avctx->reordered_opaque; + frame->pkt_pts = avctx->pkt->pts; ++ frame->pkt_pos = avctx->pkt->pos; ++ ++ if(context->tff>=0){ ++ frame->interlaced_frame = 1; ++ frame->top_field_first = context->tff; ++ } ++ ++ if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) ++ return -1; + + //2bpp and 4bpp raw in avi and mov (yes this is ugly ...) + if (context->buffer) { +@@ -136,13 +168,16 @@ + dst[2*i+0]= buf[i]>>4; + dst[2*i+1]= buf[i]&15; + } +- } else ++ linesize_align = 8; ++ } else { + for(i=0; 4*i+3 < buf_size; i++){ + dst[4*i+0]= buf[i]>>6; + dst[4*i+1]= buf[i]>>4&3; + dst[4*i+2]= buf[i]>>2&3; + dst[4*i+3]= buf[i] &3; + } ++ linesize_align = 16; ++ } + buf= dst; + } + +@@ -150,26 +185,36 @@ + avctx->codec_tag == MKTAG('A', 'V', 'u', 'p')) + buf += buf_size - context->length; + +- if(buf_size < context->length - (avctx->pix_fmt==PIX_FMT_PAL8 ? 256*4 : 0)) +- return -1; +- + avpicture_fill(picture, buf, avctx->pix_fmt, avctx->width, avctx->height); + if((avctx->pix_fmt==PIX_FMT_PAL8 && buf_size < context->length) || + (avctx->pix_fmt!=PIX_FMT_PAL8 && + (av_pix_fmt_descriptors[avctx->pix_fmt].flags & PIX_FMT_PAL))){ + frame->data[1]= context->palette; + } +- if (avctx->palctrl && avctx->palctrl->palette_changed) { +- memcpy(frame->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); +- avctx->palctrl->palette_changed = 0; ++ if (avctx->pix_fmt == PIX_FMT_PAL8) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ ++ if (pal) { ++ memcpy(frame->data[1], pal, AVPALETTE_SIZE); ++ frame->palette_has_changed = 1; ++ } + } +- if(avctx->pix_fmt==PIX_FMT_BGR24 && ((frame->linesize[0]+3)&~3)*avctx->height <= buf_size) +- frame->linesize[0] = (frame->linesize[0]+3)&~3; ++ if((avctx->pix_fmt==PIX_FMT_BGR24 || ++ avctx->pix_fmt==PIX_FMT_GRAY8 || ++ avctx->pix_fmt==PIX_FMT_RGB555LE || ++ avctx->pix_fmt==PIX_FMT_RGB555BE || ++ avctx->pix_fmt==PIX_FMT_RGB565LE || ++ avctx->pix_fmt==PIX_FMT_MONOWHITE || ++ avctx->pix_fmt==PIX_FMT_PAL8) && ++ FFALIGN(frame->linesize[0], linesize_align)*avctx->height <= buf_size) ++ frame->linesize[0] = FFALIGN(frame->linesize[0], linesize_align); + + if(context->flip) + flip(avctx, picture); + + if ( avctx->codec_tag == MKTAG('Y', 'V', '1', '2') ++ || avctx->codec_tag == MKTAG('Y', 'V', '1', '6') ++ || avctx->codec_tag == MKTAG('Y', 'V', '2', '4') + || avctx->codec_tag == MKTAG('Y', 'V', 'U', '9')) + FFSWAP(uint8_t *, picture->data[1], picture->data[2]); + +@@ -197,13 +242,13 @@ + } + + AVCodec ff_rawvideo_decoder = { +- "rawvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RAWVIDEO, +- sizeof(RawVideoContext), +- raw_init_decoder, +- NULL, +- raw_close_decoder, +- raw_decode, ++ .name = "rawvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RAWVIDEO, ++ .priv_data_size = sizeof(RawVideoContext), ++ .init = raw_init_decoder, ++ .close = raw_close_decoder, ++ .decode = raw_decode, + .long_name = NULL_IF_CONFIG_SMALL("raw video"), ++ .priv_class= &class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rawenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rawenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rawenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rawenc.c 2012-05-14 14:08:54.166336601 +0200 +@@ -32,7 +32,7 @@ + static av_cold int raw_init_encoder(AVCodecContext *avctx) + { + avctx->coded_frame = (AVFrame *)avctx->priv_data; +- avctx->coded_frame->pict_type = FF_I_TYPE; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + avctx->coded_frame->key_frame = 1; + avctx->bits_per_coded_sample = av_get_bits_per_pixel(&av_pix_fmt_descriptors[avctx->pix_fmt]); + if(!avctx->codec_tag) +@@ -56,11 +56,11 @@ + } + + AVCodec ff_rawvideo_encoder = { +- "rawvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RAWVIDEO, +- sizeof(AVFrame), +- raw_init_encoder, +- raw_encode, ++ .name = "rawvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RAWVIDEO, ++ .priv_data_size = sizeof(AVFrame), ++ .init = raw_init_encoder, ++ .encode = raw_encode, + .long_name = NULL_IF_CONFIG_SMALL("raw video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/raw.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/raw.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/raw.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/raw.h 2012-05-14 14:08:54.165336581 +0200 +@@ -35,5 +35,6 @@ + } PixelFormatTag; + + extern const PixelFormatTag ff_raw_pix_fmt_tags[]; ++enum PixelFormat ff_find_pix_fmt(const PixelFormatTag *tags, unsigned int fourcc); + + #endif /* AVCODEC_RAW_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rdft.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rdft.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rdft.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rdft.c 2012-05-14 14:08:54.167336621 +0200 +@@ -21,7 +21,7 @@ + #include + #include + #include "libavutil/mathematics.h" +-#include "fft.h" ++#include "rdft.h" + + /** + * @file +@@ -65,8 +65,8 @@ + const FFTSample *tsin = s->tsin; + + if (!s->inverse) { +- ff_fft_permute(&s->fft, (FFTComplex*)data); +- ff_fft_calc(&s->fft, (FFTComplex*)data); ++ s->fft.fft_permute(&s->fft, (FFTComplex*)data); ++ s->fft.fft_calc(&s->fft, (FFTComplex*)data); + } + /* i=0 is a special case because of packing, the DC term is real, so we + are going to throw the N/2 term (also real) in with it. */ +@@ -91,8 +91,8 @@ + if (s->inverse) { + data[0] *= k1; + data[1] *= k1; +- ff_fft_permute(&s->fft, (FFTComplex*)data); +- ff_fft_calc(&s->fft, (FFTComplex*)data); ++ s->fft.fft_permute(&s->fft, (FFTComplex*)data); ++ s->fft.fft_calc(&s->fft, (FFTComplex*)data); + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rdft.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rdft.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rdft.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rdft.h 2012-05-14 14:08:54.168336641 +0200 +@@ -0,0 +1,74 @@ ++/* ++ * (I)RDFT transforms ++ * Copyright (c) 2009 Alex Converse ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_RDFT_H ++#define AVCODEC_RDFT_H ++ ++#include "config.h" ++#include "fft.h" ++ ++#if CONFIG_HARDCODED_TABLES ++# define SINTABLE_CONST const ++#else ++# define SINTABLE_CONST ++#endif ++ ++#define SINTABLE(size) \ ++ SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2] ++ ++extern SINTABLE(16); ++extern SINTABLE(32); ++extern SINTABLE(64); ++extern SINTABLE(128); ++extern SINTABLE(256); ++extern SINTABLE(512); ++extern SINTABLE(1024); ++extern SINTABLE(2048); ++extern SINTABLE(4096); ++extern SINTABLE(8192); ++extern SINTABLE(16384); ++extern SINTABLE(32768); ++extern SINTABLE(65536); ++ ++struct RDFTContext { ++ int nbits; ++ int inverse; ++ int sign_convention; ++ ++ /* pre/post rotation tables */ ++ const FFTSample *tcos; ++ SINTABLE_CONST FFTSample *tsin; ++ FFTContext fft; ++ void (*rdft_calc)(struct RDFTContext *s, FFTSample *z); ++}; ++ ++/** ++ * Set up a real FFT. ++ * @param nbits log2 of the length of the input array ++ * @param trans the type of transform ++ */ ++int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans); ++void ff_rdft_end(RDFTContext *s); ++ ++void ff_rdft_init_arm(RDFTContext *s); ++ ++ ++#endif /* AVCODEC_RDFT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/resample2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/resample2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/resample2.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/resample2.c 2012-05-14 14:08:54.170336681 +0200 +@@ -90,7 +90,7 @@ + } + + /** +- * builds a polyphase filterbank. ++ * Build a polyphase filterbank. + * @param factor resampling factor + * @param scale wanted sum of coefficients for each filter + * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16 +@@ -207,8 +207,10 @@ + memcpy(&c->filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM)); + c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1]; + +- c->src_incr= out_rate; +- c->ideal_dst_incr= c->dst_incr= in_rate * phase_count; ++ if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2)) ++ goto error; ++ c->ideal_dst_incr= c->dst_incr; ++ + c->index= -phase_count*((c->filter_length-1)/2); + + return c; +@@ -246,10 +248,9 @@ + dst[dst_index] = src[index2>>32]; + index2 += incr; + } +- frac += dst_index * dst_incr_frac; + index += dst_index * dst_incr; +- index += frac / c->src_incr; +- frac %= c->src_incr; ++ index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr; ++ frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr; + }else{ + for(dst_index=0; dst_index < dst_size; dst_index++){ + FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/resample.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/resample.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/resample.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/resample.c 2012-05-14 14:08:54.169336661 +0200 +@@ -27,7 +27,9 @@ + #include "avcodec.h" + #include "audioconvert.h" + #include "libavutil/opt.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/samplefmt.h" ++ ++#define MAX_CHANNELS 8 + + struct AVResampleContext; + +@@ -37,20 +39,22 @@ + } + + static const AVOption options[] = {{NULL}}; +-static const AVClass audioresample_context_class = { "ReSampleContext", context_to_name, options, LIBAVUTIL_VERSION_INT }; ++static const AVClass audioresample_context_class = { ++ "ReSampleContext", context_to_name, options, LIBAVUTIL_VERSION_INT ++}; + + struct ReSampleContext { + struct AVResampleContext *resample_context; +- short *temp[2]; ++ short *temp[MAX_CHANNELS]; + int temp_len; + float ratio; + /* channel convert */ + int input_channels, output_channels, filter_channels; + AVAudioConvert *convert_ctx[2]; + enum AVSampleFormat sample_fmt[2]; ///< input and output sample format +- unsigned sample_size[2]; ///< size of one sample in sample_fmt +- short *buffer[2]; ///< buffers used for conversion to S16 +- unsigned buffer_size[2]; ///< sizes of allocated buffers ++ unsigned sample_size[2]; ///< size of one sample in sample_fmt ++ short *buffer[2]; ///< buffers used for conversion to S16 ++ unsigned buffer_size[2]; ///< sizes of allocated buffers + }; + + /* n1: number of samples */ +@@ -104,44 +108,93 @@ + } + } + +-/* XXX: should use more abstract 'N' channels system */ +-static void stereo_split(short *output1, short *output2, short *input, int n) ++/* ++5.1 to stereo input: [fl, fr, c, lfe, rl, rr] ++- Left = front_left + rear_gain * rear_left + center_gain * center ++- Right = front_right + rear_gain * rear_right + center_gain * center ++Where rear_gain is usually around 0.5-1.0 and ++ center_gain is almost always 0.7 (-3 dB) ++*/ ++static void surround_to_stereo(short **output, short *input, int channels, int samples) + { + int i; ++ short l, r; ++ ++ for (i = 0; i < samples; i++) { ++ int fl,fr,c,rl,rr; ++ fl = input[0]; ++ fr = input[1]; ++ c = input[2]; ++ // lfe = input[3]; ++ rl = input[4]; ++ rr = input[5]; ++ ++ l = av_clip_int16(fl + (0.5 * rl) + (0.7 * c)); ++ r = av_clip_int16(fr + (0.5 * rr) + (0.7 * c)); ++ ++ /* output l & r. */ ++ *output[0]++ = l; ++ *output[1]++ = r; + +- for(i=0;i 2) +- { +- av_log(NULL, AV_LOG_ERROR, "Resampling with input channels greater than 2 unsupported.\n"); ++ if (input_channels > MAX_CHANNELS) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Resampling with input channels greater than %d is unsupported.\n", ++ MAX_CHANNELS); ++ return NULL; ++ } ++ if (!(supported_resampling[input_channels-1] & (1<<(output_channels-1)))) { ++ int i; ++ av_log(NULL, AV_LOG_ERROR, "Unsupported audio resampling. Allowed " ++ "output channels for %d input channel%s", input_channels, ++ input_channels > 1 ? "s:" : ":"); ++ for (i = 0; i < MAX_CHANNELS; i++) ++ if (supported_resampling[input_channels-1] & (1<ratio = (float)output_rate / (float)input_rate; + +@@ -173,10 +237,10 @@ + if (s->output_channels < s->filter_channels) + s->filter_channels = s->output_channels; + +- s->sample_fmt [0] = sample_fmt_in; +- s->sample_fmt [1] = sample_fmt_out; +- s->sample_size[0] = av_get_bits_per_sample_fmt(s->sample_fmt[0])>>3; +- s->sample_size[1] = av_get_bits_per_sample_fmt(s->sample_fmt[1])>>3; ++ s->sample_fmt[0] = sample_fmt_in; ++ s->sample_fmt[1] = sample_fmt_out; ++ s->sample_size[0] = av_get_bytes_per_sample(s->sample_fmt[0]); ++ s->sample_size[1] = av_get_bytes_per_sample(s->sample_fmt[1]); + + if (s->sample_fmt[0] != AV_SAMPLE_FMT_S16) { + if (!(s->convert_ctx[0] = av_audio_convert_alloc(AV_SAMPLE_FMT_S16, 1, +@@ -201,42 +265,23 @@ + } + } + +-/* +- * AC-3 output is the only case where filter_channels could be greater than 2. +- * input channels can't be greater than 2, so resample the 2 channels and then +- * expand to 6 channels after the resampling. +- */ +- if(s->filter_channels>2) +- s->filter_channels = 2; +- +-#define TAPS 16 +- s->resample_context= av_resample_init(output_rate, input_rate, +- filter_length, log2_phase_count, linear, cutoff); ++ s->resample_context = av_resample_init(output_rate, input_rate, ++ filter_length, log2_phase_count, ++ linear, cutoff); + + *(const AVClass**)s->resample_context = &audioresample_context_class; + + return s; + } + +-#if FF_API_AUDIO_OLD +-ReSampleContext *audio_resample_init(int output_channels, int input_channels, +- int output_rate, int input_rate) +-{ +- return av_audio_resample_init(output_channels, input_channels, +- output_rate, input_rate, +- AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16, +- TAPS, 10, 0, 0.8); +-} +-#endif +- + /* resample audio. 'nb_samples' is the number of input samples */ + /* XXX: optimize it ! */ + int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples) + { + int i, nb_samples1; +- short *bufin[2]; +- short *bufout[2]; +- short *buftmp2[2], *buftmp3[2]; ++ short *bufin[MAX_CHANNELS]; ++ short *bufout[MAX_CHANNELS]; ++ short *buftmp2[MAX_CHANNELS], *buftmp3[MAX_CHANNELS]; + short *output_bak = NULL; + int lenout; + +@@ -251,7 +296,7 @@ + int ostride[1] = { 2 }; + const void *ibuf[1] = { input }; + void *obuf[1]; +- unsigned input_size = nb_samples*s->input_channels*2; ++ unsigned input_size = nb_samples * s->input_channels * 2; + + if (!s->buffer_size[0] || s->buffer_size[0] < input_size) { + av_free(s->buffer[0]); +@@ -266,22 +311,23 @@ + obuf[0] = s->buffer[0]; + + if (av_audio_convert(s->convert_ctx[0], obuf, ostride, +- ibuf, istride, nb_samples*s->input_channels) < 0) { +- av_log(s->resample_context, AV_LOG_ERROR, "Audio sample format conversion failed\n"); ++ ibuf, istride, nb_samples * s->input_channels) < 0) { ++ av_log(s->resample_context, AV_LOG_ERROR, ++ "Audio sample format conversion failed\n"); + return 0; + } + +- input = s->buffer[0]; ++ input = s->buffer[0]; + } + +- lenout= 4*nb_samples * s->ratio + 16; ++ lenout= 2*s->output_channels*nb_samples * s->ratio + 16; + + if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) { + output_bak = output; + +- if (!s->buffer_size[1] || s->buffer_size[1] < lenout) { ++ if (!s->buffer_size[1] || s->buffer_size[1] < 2*lenout) { + av_free(s->buffer[1]); +- s->buffer_size[1] = lenout; ++ s->buffer_size[1] = 2*lenout; + s->buffer[1] = av_malloc(s->buffer_size[1]); + if (!s->buffer[1]) { + av_log(s->resample_context, AV_LOG_ERROR, "Could not allocate buffer\n"); +@@ -293,52 +339,55 @@ + } + + /* XXX: move those malloc to resample init code */ +- for(i=0; ifilter_channels; i++){ +- bufin[i]= av_malloc( (nb_samples + s->temp_len) * sizeof(short) ); ++ for (i = 0; i < s->filter_channels; i++) { ++ bufin[i] = av_malloc((nb_samples + s->temp_len) * sizeof(short)); + memcpy(bufin[i], s->temp[i], s->temp_len * sizeof(short)); + buftmp2[i] = bufin[i] + s->temp_len; ++ bufout[i] = av_malloc(lenout * sizeof(short)); + } + +- /* make some zoom to avoid round pb */ +- bufout[0]= av_malloc( lenout * sizeof(short) ); +- bufout[1]= av_malloc( lenout * sizeof(short) ); +- +- if (s->input_channels == 2 && +- s->output_channels == 1) { ++ if (s->input_channels == 2 && s->output_channels == 1) { + buftmp3[0] = output; + stereo_to_mono(buftmp2[0], input, nb_samples); + } else if (s->output_channels >= 2 && s->input_channels == 1) { + buftmp3[0] = bufout[0]; +- memcpy(buftmp2[0], input, nb_samples*sizeof(short)); +- } else if (s->output_channels >= 2) { ++ memcpy(buftmp2[0], input, nb_samples * sizeof(short)); ++ } else if (s->input_channels == 6 && s->output_channels ==2) { + buftmp3[0] = bufout[0]; + buftmp3[1] = bufout[1]; +- stereo_split(buftmp2[0], buftmp2[1], input, nb_samples); ++ surround_to_stereo(buftmp2, input, s->input_channels, nb_samples); ++ } else if (s->output_channels >= s->input_channels && s->input_channels >= 2) { ++ for (i = 0; i < s->input_channels; i++) { ++ buftmp3[i] = bufout[i]; ++ } ++ deinterleave(buftmp2, input, s->input_channels, nb_samples); + } else { + buftmp3[0] = output; +- memcpy(buftmp2[0], input, nb_samples*sizeof(short)); ++ memcpy(buftmp2[0], input, nb_samples * sizeof(short)); + } + + nb_samples += s->temp_len; + + /* resample each channel */ + nb_samples1 = 0; /* avoid warning */ +- for(i=0;ifilter_channels;i++) { ++ for (i = 0; i < s->filter_channels; i++) { + int consumed; +- int is_last= i+1 == s->filter_channels; ++ int is_last = i + 1 == s->filter_channels; + +- nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], &consumed, nb_samples, lenout, is_last); +- s->temp_len= nb_samples - consumed; +- s->temp[i]= av_realloc(s->temp[i], s->temp_len*sizeof(short)); +- memcpy(s->temp[i], bufin[i] + consumed, s->temp_len*sizeof(short)); ++ nb_samples1 = av_resample(s->resample_context, buftmp3[i], bufin[i], ++ &consumed, nb_samples, lenout, is_last); ++ s->temp_len = nb_samples - consumed; ++ s->temp[i] = av_realloc(s->temp[i], s->temp_len * sizeof(short)); ++ memcpy(s->temp[i], bufin[i] + consumed, s->temp_len * sizeof(short)); + } + + if (s->output_channels == 2 && s->input_channels == 1) { + mono_to_stereo(output, buftmp3[0], nb_samples1); +- } else if (s->output_channels == 2) { +- stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); +- } else if (s->output_channels == 6) { ++ } else if (s->output_channels == 6 && s->input_channels == 2) { + ac3_5p1_mux(output, buftmp3[0], buftmp3[1], nb_samples1); ++ } else if ((s->output_channels == s->input_channels && s->input_channels >= 2) || ++ (s->output_channels == 2 && s->input_channels == 6)) { ++ interleave(output, buftmp3, s->output_channels, nb_samples1); + } + + if (s->sample_fmt[1] != AV_SAMPLE_FMT_S16) { +@@ -348,25 +397,27 @@ + void *obuf[1] = { output_bak }; + + if (av_audio_convert(s->convert_ctx[1], obuf, ostride, +- ibuf, istride, nb_samples1*s->output_channels) < 0) { +- av_log(s->resample_context, AV_LOG_ERROR, "Audio sample format convertion failed\n"); ++ ibuf, istride, nb_samples1 * s->output_channels) < 0) { ++ av_log(s->resample_context, AV_LOG_ERROR, ++ "Audio sample format convertion failed\n"); + return 0; + } + } + +- for(i=0; ifilter_channels; i++) ++ for (i = 0; i < s->filter_channels; i++) { + av_free(bufin[i]); ++ av_free(bufout[i]); ++ } + +- av_free(bufout[0]); +- av_free(bufout[1]); + return nb_samples1; + } + + void audio_resample_close(ReSampleContext *s) + { ++ int i; + av_resample_close(s->resample_context); +- av_freep(&s->temp[0]); +- av_freep(&s->temp[1]); ++ for (i = 0; i < s->filter_channels; i++) ++ av_freep(&s->temp[i]); + av_freep(&s->buffer[0]); + av_freep(&s->buffer[1]); + av_audio_convert_free(s->convert_ctx[0]); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rl2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rl2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rl2.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rl2.c 2012-05-14 14:08:54.171336701 +0200 +@@ -20,11 +20,10 @@ + */ + + /** +- * RL2 Video Decoder + * @file ++ * RL2 Video Decoder + * @author Sascha Sommer (saschasommer@freenet.de) +- * For more information about the RL2 format, visit: +- * http://wiki.multimedia.cx/index.php?title=RL2 ++ * @see http://wiki.multimedia.cx/index.php?title=RL2 + */ + + #include +@@ -134,6 +133,7 @@ + int i; + s->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&s->frame); + + /** parse extra data */ + if(!avctx->extradata || avctx->extradata_size < EXTRADATA1_SIZE){ +@@ -152,7 +152,7 @@ + + /** initialize palette */ + for(i=0;ipalette[i] = AV_RB24(&avctx->extradata[6 + i * 3]); ++ s->palette[i] = 0xFF << 24 | AV_RB24(&avctx->extradata[6 + i * 3]); + + /** decode background frame if present */ + back_size = avctx->extradata_size - EXTRADATA1_SIZE; +@@ -220,15 +220,14 @@ + + + AVCodec ff_rl2_decoder = { +- "rl2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RL2, +- sizeof(Rl2Context), +- rl2_decode_init, +- NULL, +- rl2_decode_end, +- rl2_decode_frame, +- CODEC_CAP_DR1, ++ .name = "rl2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RL2, ++ .priv_data_size = sizeof(Rl2Context), ++ .init = rl2_decode_init, ++ .close = rl2_decode_end, ++ .decode = rl2_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("RL2 video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqaudioenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqaudioenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqaudioenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqaudioenc.c 2012-05-14 14:08:54.171336701 +0200 +@@ -154,14 +154,13 @@ + } + + AVCodec ff_roq_dpcm_encoder = { +- "roq_dpcm", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_ROQ_DPCM, +- sizeof(ROQDPCMContext), +- roq_dpcm_encode_init, +- roq_dpcm_encode_frame, +- roq_dpcm_encode_close, +- NULL, ++ .name = "roq_dpcm", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_ROQ_DPCM, ++ .priv_data_size = sizeof(ROQDPCMContext), ++ .init = roq_dpcm_encode_init, ++ .encode = roq_dpcm_encode_frame, ++ .close = roq_dpcm_encode_close, + .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("id RoQ DPCM"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideodec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideodec.c 2012-05-14 14:08:54.173336741 +0200 +@@ -38,16 +38,15 @@ + unsigned int chunk_id = 0, chunk_arg = 0; + unsigned long chunk_size = 0; + int i, j, k, nv1, nv2, vqflg = 0, vqflg_pos = -1; +- int vqid, bpos, xpos, ypos, xp, yp, x, y, mx, my; ++ int vqid, xpos, ypos, xp, yp, x, y, mx, my; + int frame_stats[2][4] = {{0},{0}}; + roq_qcell *qcell; +- const unsigned char *buf = ri->buf; +- const unsigned char *buf_end = ri->buf + ri->size; ++ int64_t chunk_start; + +- while (buf < buf_end) { +- chunk_id = bytestream_get_le16(&buf); +- chunk_size = bytestream_get_le32(&buf); +- chunk_arg = bytestream_get_le16(&buf); ++ while (bytestream2_get_bytes_left(&ri->gb) > 0) { ++ chunk_id = bytestream2_get_le16(&ri->gb); ++ chunk_size = bytestream2_get_le32(&ri->gb); ++ chunk_arg = bytestream2_get_le16(&ri->gb); + + if(chunk_id == RoQ_QUAD_VQ) + break; +@@ -57,25 +56,36 @@ + if((nv2 = chunk_arg & 0xff) == 0 && nv1 * 6 < chunk_size) + nv2 = 256; + for(i = 0; i < nv1; i++) { +- ri->cb2x2[i].y[0] = *buf++; +- ri->cb2x2[i].y[1] = *buf++; +- ri->cb2x2[i].y[2] = *buf++; +- ri->cb2x2[i].y[3] = *buf++; +- ri->cb2x2[i].u = *buf++; +- ri->cb2x2[i].v = *buf++; ++ ri->cb2x2[i].y[0] = bytestream2_get_byte(&ri->gb); ++ ri->cb2x2[i].y[1] = bytestream2_get_byte(&ri->gb); ++ ri->cb2x2[i].y[2] = bytestream2_get_byte(&ri->gb); ++ ri->cb2x2[i].y[3] = bytestream2_get_byte(&ri->gb); ++ ri->cb2x2[i].u = bytestream2_get_byte(&ri->gb); ++ ri->cb2x2[i].v = bytestream2_get_byte(&ri->gb); + } + for(i = 0; i < nv2; i++) + for(j = 0; j < 4; j++) +- ri->cb4x4[i].idx[j] = *buf++; ++ ri->cb4x4[i].idx[j] = bytestream2_get_byte(&ri->gb); + } + } + +- bpos = xpos = ypos = 0; +- while(bpos < chunk_size) { ++ chunk_start = bytestream2_tell(&ri->gb); ++ xpos = ypos = 0; ++ ++ if (chunk_size > bytestream2_get_bytes_left(&ri->gb)) { ++ av_log(ri->avctx, AV_LOG_ERROR, "Chunk does not fit in input buffer\n"); ++ chunk_size = bytestream2_get_bytes_left(&ri->gb); ++ } ++ ++ while (bytestream2_tell(&ri->gb) < chunk_start + chunk_size) { + for (yp = ypos; yp < ypos + 16; yp += 8) + for (xp = xpos; xp < xpos + 16; xp += 8) { ++ if (bytestream2_tell(&ri->gb) >= chunk_start + chunk_size) { ++ av_log(ri->avctx, AV_LOG_ERROR, "Input buffer too small\n"); ++ return; ++ } + if (vqflg_pos < 0) { +- vqflg = buf[bpos++]; vqflg |= (buf[bpos++] << 8); ++ vqflg = bytestream2_get_le16(&ri->gb); + vqflg_pos = 7; + } + vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; +@@ -85,13 +95,15 @@ + switch(vqid) { + case RoQ_ID_MOT: + break; +- case RoQ_ID_FCC: +- mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8)); +- my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg); ++ case RoQ_ID_FCC: { ++ int byte = bytestream2_get_byte(&ri->gb); ++ mx = 8 - (byte >> 4) - ((signed char) (chunk_arg >> 8)); ++ my = 8 - (byte & 0xf) - ((signed char) chunk_arg); + ff_apply_motion_8x8(ri, xp, yp, mx, my); + break; ++ } + case RoQ_ID_SLD: +- qcell = ri->cb4x4 + buf[bpos++]; ++ qcell = ri->cb4x4 + bytestream2_get_byte(&ri->gb); + ff_apply_vector_4x4(ri, xp, yp, ri->cb2x2 + qcell->idx[0]); + ff_apply_vector_4x4(ri, xp+4, yp, ri->cb2x2 + qcell->idx[1]); + ff_apply_vector_4x4(ri, xp, yp+4, ri->cb2x2 + qcell->idx[2]); +@@ -103,9 +115,12 @@ + if(k & 0x01) x += 4; + if(k & 0x02) y += 4; + ++ if (bytestream2_tell(&ri->gb) >= chunk_start + chunk_size) { ++ av_log(ri->avctx, AV_LOG_ERROR, "Input buffer too small\n"); ++ return; ++ } + if (vqflg_pos < 0) { +- vqflg = buf[bpos++]; +- vqflg |= (buf[bpos++] << 8); ++ vqflg = bytestream2_get_le16(&ri->gb); + vqflg_pos = 7; + } + vqid = (vqflg >> (vqflg_pos * 2)) & 0x3; +@@ -114,24 +129,25 @@ + switch(vqid) { + case RoQ_ID_MOT: + break; +- case RoQ_ID_FCC: +- mx = 8 - (buf[bpos] >> 4) - ((signed char) (chunk_arg >> 8)); +- my = 8 - (buf[bpos++] & 0xf) - ((signed char) chunk_arg); ++ case RoQ_ID_FCC: { ++ int byte = bytestream2_get_byte(&ri->gb); ++ mx = 8 - (byte >> 4) - ((signed char) (chunk_arg >> 8)); ++ my = 8 - (byte & 0xf) - ((signed char) chunk_arg); + ff_apply_motion_4x4(ri, x, y, mx, my); + break; ++ } + case RoQ_ID_SLD: +- qcell = ri->cb4x4 + buf[bpos++]; ++ qcell = ri->cb4x4 + bytestream2_get_byte(&ri->gb); + ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + qcell->idx[0]); + ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + qcell->idx[1]); + ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + qcell->idx[2]); + ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + qcell->idx[3]); + break; + case RoQ_ID_CCC: +- ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + buf[bpos]); +- ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + buf[bpos+1]); +- ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + buf[bpos+2]); +- ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + buf[bpos+3]); +- bpos += 4; ++ ff_apply_vector_2x2(ri, x, y, ri->cb2x2 + bytestream2_get_byte(&ri->gb)); ++ ff_apply_vector_2x2(ri, x+2, y, ri->cb2x2 + bytestream2_get_byte(&ri->gb)); ++ ff_apply_vector_2x2(ri, x, y+2, ri->cb2x2 + bytestream2_get_byte(&ri->gb)); ++ ff_apply_vector_2x2(ri, x+2, y+2, ri->cb2x2 + bytestream2_get_byte(&ri->gb)); + break; + } + } +@@ -159,6 +175,8 @@ + s->avctx = avctx; + s->width = avctx->width; + s->height = avctx->height; ++ avcodec_get_frame_defaults(&s->frames[0]); ++ avcodec_get_frame_defaults(&s->frames[1]); + s->last_frame = &s->frames[0]; + s->current_frame = &s->frames[1]; + avctx->pix_fmt = PIX_FMT_YUV444P; +@@ -175,6 +193,7 @@ + RoqContext *s = avctx->priv_data; + int copy= !s->current_frame->data[0]; + ++ s->current_frame->reference = 3; + if (avctx->reget_buffer(avctx, s->current_frame)) { + av_log(avctx, AV_LOG_ERROR, " RoQ: get_buffer() failed\n"); + return -1; +@@ -184,8 +203,7 @@ + av_picture_copy((AVPicture*)s->current_frame, (AVPicture*)s->last_frame, + avctx->pix_fmt, avctx->width, avctx->height); + +- s->buf = buf; +- s->size = buf_size; ++ bytestream2_init(&s->gb, buf, buf_size); + roqvideo_decode_frame(s); + + *data_size = sizeof(AVFrame); +@@ -211,14 +229,13 @@ + } + + AVCodec ff_roq_decoder = { +- "roqvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ROQ, +- sizeof(RoqContext), +- roq_decode_init, +- NULL, +- roq_decode_end, +- roq_decode_frame, +- CODEC_CAP_DR1, ++ .name = "roqvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ROQ, ++ .priv_data_size = sizeof(RoqContext), ++ .init = roq_decode_init, ++ .close = roq_decode_end, ++ .decode = roq_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideoenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideoenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideoenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideoenc.c 2012-05-14 14:08:54.174336761 +0200 +@@ -898,9 +898,20 @@ + for (i=0; iwidth*enc->height/64; i++) + gather_data_for_cel(tempData->cel_evals + i, enc, tempData); + +- /* Quake 3 can't handle chunks bigger than 65536 bytes */ +- if (tempData->mainChunkSize/8 > 65536) { +- enc->lambda *= .8; ++ /* Quake 3 can't handle chunks bigger than 65535 bytes */ ++ if (tempData->mainChunkSize/8 > 65535) { ++ av_log(enc->avctx, AV_LOG_ERROR, ++ "Warning, generated a frame too big (%d > 65535), " ++ "try using a smaller qscale value.\n", ++ tempData->mainChunkSize/8); ++ enc->lambda *= 1.5; ++ tempData->mainChunkSize = 0; ++ memset(tempData->used_option, 0, sizeof(tempData->used_option)); ++ memset(tempData->codebooks.usedCB4, 0, ++ sizeof(tempData->codebooks.usedCB4)); ++ memset(tempData->codebooks.usedCB2, 0, ++ sizeof(tempData->codebooks.usedCB2)); ++ + goto retry_encode; + } + +@@ -1054,16 +1065,15 @@ + return 0; + } + +-AVCodec ff_roq_encoder = +-{ +- "roqvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ROQ, +- sizeof(RoqContext), +- roq_encode_init, +- roq_encode_frame, +- roq_encode_end, ++AVCodec ff_roq_encoder = { ++ .name = "roqvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ROQ, ++ .priv_data_size = sizeof(RoqContext), ++ .init = roq_encode_init, ++ .encode = roq_encode_frame, ++ .close = roq_encode_end, + .supported_framerates = (const AVRational[]){{30,1}, {0,0}}, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV444P, PIX_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("id RoQ video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideo.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideo.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/roqvideo.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/roqvideo.h 2012-05-14 14:08:54.172336721 +0200 +@@ -24,6 +24,7 @@ + + #include "libavutil/lfg.h" + #include "avcodec.h" ++#include "bytestream.h" + #include "dsputil.h" + + typedef struct { +@@ -53,8 +54,7 @@ + roq_cell cb2x2[256]; + roq_qcell cb4x4[256]; + +- const unsigned char *buf; +- int size; ++ GetByteContext gb; + int width, height; + + /* Encoder only data */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rpza.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rpza.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rpza.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rpza.c 2012-05-14 14:08:54.175336781 +0200 +@@ -30,8 +30,8 @@ + * Note that this decoder reads big endian RGB555 pixel values from the + * bytestream, arranges them in the host's endian order, and outputs + * them to the final rendered map in the same host endian order. This is +- * intended behavior as the ffmpeg documentation states that RGB555 pixels +- * shall be stored in native CPU endianness. ++ * intended behavior as the libavcodec documentation states that RGB555 ++ * pixels shall be stored in native CPU endianness. + */ + + #include +@@ -183,6 +183,8 @@ + color4[1] |= ((11 * ta + 21 * tb) >> 5); + color4[2] |= ((21 * ta + 11 * tb) >> 5); + ++ if (s->size - stream_ptr < n_blocks * 4) ++ return; + while (n_blocks--) { + block_ptr = row_ptr + pixel_ptr; + for (pixel_y = 0; pixel_y < 4; pixel_y++) { +@@ -200,6 +202,8 @@ + + /* Fill block with 16 colors */ + case 0x00: ++ if (s->size - stream_ptr < 16) ++ return; + block_ptr = row_ptr + pixel_ptr; + for (pixel_y = 0; pixel_y < 4; pixel_y++) { + for (pixel_x = 0; pixel_x < 4; pixel_x++){ +@@ -233,6 +237,7 @@ + s->avctx = avctx; + avctx->pix_fmt = PIX_FMT_RGB555; + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -249,7 +254,7 @@ + s->buf = buf; + s->size = buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -276,14 +281,13 @@ + } + + AVCodec ff_rpza_decoder = { +- "rpza", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RPZA, +- sizeof(RpzaContext), +- rpza_decode_init, +- NULL, +- rpza_decode_end, +- rpza_decode_frame, +- CODEC_CAP_DR1, ++ .name = "rpza", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RPZA, ++ .priv_data_size = sizeof(RpzaContext), ++ .init = rpza_decode_init, ++ .close = rpza_decode_end, ++ .decode = rpza_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("QuickTime video (RPZA)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rtjpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rtjpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rtjpeg.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rtjpeg.c 2012-05-14 14:08:54.176336801 +0200 +@@ -27,18 +27,18 @@ + i = scan[coeff--]; \ + block[i] = (c) * quant[i]; + +-//! aligns the bitstream to the give power of two ++/// aligns the bitstream to the given power of two + #define ALIGN(a) \ + n = (-get_bits_count(gb)) & (a - 1); \ + if (n) {skip_bits(gb, n);} + + /** +- * \brief read one block from stream +- * \param gb contains stream data +- * \param block where data is written to +- * \param scan array containing the mapping stream address -> block position +- * \param quant quantization factors +- * \return 0 means the block is not coded, < 0 means an error occurred. ++ * @brief read one block from stream ++ * @param gb contains stream data ++ * @param block where data is written to ++ * @param scan array containing the mapping stream address -> block position ++ * @param quant quantization factors ++ * @return 0 means the block is not coded, < 0 means an error occurred. + * + * Note: GetBitContext is used to make the code simpler, since all data is + * aligned this could be done faster in a different way, e.g. as it is done +@@ -56,7 +56,7 @@ + + // number of non-zero coefficients + coeff = get_bits(gb, 6); +- if (get_bits_count(gb) + (coeff << 1) >= gb->size_in_bits) ++ if (get_bits_left(gb) < (coeff << 1)) + return -1; + + // normally we would only need to clear the (63 - coeff) last values, +@@ -73,7 +73,7 @@ + + // 4 bits per coefficient + ALIGN(4); +- if (get_bits_count(gb) + (coeff << 2) >= gb->size_in_bits) ++ if (get_bits_left(gb) < (coeff << 2)) + return -1; + while (coeff) { + ac = get_sbits(gb, 4); +@@ -84,7 +84,7 @@ + + // 8 bits per coefficient + ALIGN(8); +- if (get_bits_count(gb) + (coeff << 3) >= gb->size_in_bits) ++ if (get_bits_left(gb) < (coeff << 3)) + return -1; + while (coeff) { + ac = get_sbits(gb, 8); +@@ -96,13 +96,13 @@ + } + + /** +- * \brief decode one rtjpeg YUV420 frame +- * \param c context, must be initialized via rtjpeg_decode_init +- * \param f AVFrame to place decoded frame into. If parts of the frame ++ * @brief decode one rtjpeg YUV420 frame ++ * @param c context, must be initialized via rtjpeg_decode_init ++ * @param f AVFrame to place decoded frame into. If parts of the frame + * are not coded they are left unchanged, so consider initializing it +- * \param buf buffer containing input data +- * \param buf_size length of input data in bytes +- * \return number of bytes consumed from the input buffer ++ * @param buf buffer containing input data ++ * @param buf_size length of input data in bytes ++ * @return number of bytes consumed from the input buffer + */ + int rtjpeg_decode_frame_yuv420(RTJpegContext *c, AVFrame *f, + const uint8_t *buf, int buf_size) { +@@ -114,24 +114,25 @@ + init_get_bits(&gb, buf, buf_size * 8); + for (y = 0; y < h; y++) { + for (x = 0; x < w; x++) { ++#define BLOCK(quant, dst, stride) do { \ ++ int res = get_block(&gb, block, c->scan, quant); \ ++ if (res < 0) \ ++ return res; \ ++ if (res > 0) \ ++ c->dsp->idct_put(dst, stride, block); \ ++} while (0) + DCTELEM *block = c->block; +- if (get_block(&gb, block, c->scan, c->lquant) > 0) +- c->dsp->idct_put(y1, f->linesize[0], block); ++ BLOCK(c->lquant, y1, f->linesize[0]); + y1 += 8; +- if (get_block(&gb, block, c->scan, c->lquant) > 0) +- c->dsp->idct_put(y1, f->linesize[0], block); ++ BLOCK(c->lquant, y1, f->linesize[0]); + y1 += 8; +- if (get_block(&gb, block, c->scan, c->lquant) > 0) +- c->dsp->idct_put(y2, f->linesize[0], block); ++ BLOCK(c->lquant, y2, f->linesize[0]); + y2 += 8; +- if (get_block(&gb, block, c->scan, c->lquant) > 0) +- c->dsp->idct_put(y2, f->linesize[0], block); ++ BLOCK(c->lquant, y2, f->linesize[0]); + y2 += 8; +- if (get_block(&gb, block, c->scan, c->cquant) > 0) +- c->dsp->idct_put(u, f->linesize[1], block); ++ BLOCK(c->cquant, u, f->linesize[1]); + u += 8; +- if (get_block(&gb, block, c->scan, c->cquant) > 0) +- c->dsp->idct_put(v, f->linesize[2], block); ++ BLOCK(c->cquant, v, f->linesize[2]); + v += 8; + } + y1 += 2 * 8 * (f->linesize[0] - w); +@@ -143,15 +144,15 @@ + } + + /** +- * \brief initialize an RTJpegContext, may be called multiple times +- * \param c context to initialize +- * \param dsp specifies the idct to use for decoding +- * \param width width of image, will be rounded down to the nearest multiple ++ * @brief initialize an RTJpegContext, may be called multiple times ++ * @param c context to initialize ++ * @param dsp specifies the idct to use for decoding ++ * @param width width of image, will be rounded down to the nearest multiple + * of 16 for decoding +- * \param height height of image, will be rounded down to the nearest multiple ++ * @param height height of image, will be rounded down to the nearest multiple + * of 16 for decoding +- * \param lquant luma quantization table to use +- * \param cquant chroma quantization table to use ++ * @param lquant luma quantization table to use ++ * @param cquant chroma quantization table to use + */ + void rtjpeg_decode_init(RTJpegContext *c, DSPContext *dsp, + int width, int height, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv10.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv10.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv10.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv10.c 2012-05-14 14:08:54.178336843 +0200 +@@ -25,7 +25,7 @@ + * RV10/RV20 decoder + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" +@@ -34,6 +34,10 @@ + + //#define DEBUG + ++#define RV_GET_MAJOR_VER(x) ((x) >> 28) ++#define RV_GET_MINOR_VER(x) (((x) >> 20) & 0xFF) ++#define RV_GET_MICRO_VER(x) (((x) >> 12) & 0xFF) ++ + #define DC_VLC_BITS 14 //FIXME find a better solution + + static const uint16_t rv_lum_code[256] = +@@ -235,14 +239,14 @@ + /* read RV 1.0 compatible frame header */ + static int rv10_decode_picture_header(MpegEncContext *s) + { +- int mb_count, pb_frame, marker, unk, mb_xy; ++ int mb_count, pb_frame, marker, mb_xy; + + marker = get_bits1(&s->gb); + + if (get_bits1(&s->gb)) +- s->pict_type = FF_P_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_P; + else +- s->pict_type = FF_I_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_I; + if(!marker) av_log(s->avctx, AV_LOG_ERROR, "marker missing\n"); + pb_frame = get_bits1(&s->gb); + +@@ -259,7 +263,7 @@ + return -1; + } + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + if (s->rv10_version == 3) { + /* specific MPEG like DC coding not used */ + s->last_dc[0] = get_bits(&s->gb, 8); +@@ -282,7 +286,7 @@ + s->mb_y = 0; + mb_count = s->mb_width * s->mb_height; + } +- unk= get_bits(&s->gb, 3); /* ignored */ ++ skip_bits(&s->gb, 3); /* ignored */ + s->f_code = 1; + s->unrestricted_mv = 1; + +@@ -292,6 +296,7 @@ + static int rv20_decode_picture_header(MpegEncContext *s) + { + int seq, mb_pos, i; ++ int rpr_bits; + + #if 0 + GetBitContext gb= s->gb; +@@ -310,31 +315,24 @@ + av_log(s->avctx, AV_LOG_DEBUG, "\n"); + #endif + +- if(s->avctx->sub_id == 0x30202002 || s->avctx->sub_id == 0x30203002){ +- if (get_bits(&s->gb, 3)){ +- av_log(s->avctx, AV_LOG_ERROR, "unknown triplet set\n"); +- return -1; +- } +- } +- + i= get_bits(&s->gb, 2); + switch(i){ +- case 0: s->pict_type= FF_I_TYPE; break; +- case 1: s->pict_type= FF_I_TYPE; break; //hmm ... +- case 2: s->pict_type= FF_P_TYPE; break; +- case 3: s->pict_type= FF_B_TYPE; break; ++ case 0: s->pict_type= AV_PICTURE_TYPE_I; break; ++ case 1: s->pict_type= AV_PICTURE_TYPE_I; break; //hmm ... ++ case 2: s->pict_type= AV_PICTURE_TYPE_P; break; ++ case 3: s->pict_type= AV_PICTURE_TYPE_B; break; + default: + av_log(s->avctx, AV_LOG_ERROR, "unknown frame type\n"); + return -1; + } + +- if(s->last_picture_ptr==NULL && s->pict_type==FF_B_TYPE){ ++ if(s->last_picture_ptr==NULL && s->pict_type==AV_PICTURE_TYPE_B){ + av_log(s->avctx, AV_LOG_ERROR, "early B pix\n"); + return -1; + } + + if (get_bits1(&s->gb)){ +- av_log(s->avctx, AV_LOG_ERROR, "unknown bit set\n"); ++ av_log(s->avctx, AV_LOG_ERROR, "reserved bit set\n"); + return -1; + } + +@@ -343,23 +341,21 @@ + av_log(s->avctx, AV_LOG_ERROR, "error, qscale:0\n"); + return -1; + } +- if(s->avctx->sub_id == 0x30203002){ +- if (get_bits1(&s->gb)){ +- av_log(s->avctx, AV_LOG_ERROR, "unknown bit2 set\n"); +- return -1; +- } +- } + +- if(s->avctx->has_b_frames){ +- int f, new_w, new_h; +- int v= s->avctx->extradata_size >= 4 ? 7&((uint8_t*)s->avctx->extradata)[1] : 0; ++ if(RV_GET_MINOR_VER(s->avctx->sub_id) >= 2) ++ s->loop_filter = get_bits1(&s->gb); + +- if (get_bits1(&s->gb)){ +- av_log(s->avctx, AV_LOG_ERROR, "unknown bit3 set\n"); +- } +- seq= get_bits(&s->gb, 13)<<2; ++ if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1) ++ seq = get_bits(&s->gb, 8) << 7; ++ else ++ seq = get_bits(&s->gb, 13) << 2; ++ ++ rpr_bits = s->avctx->extradata[1] & 7; ++ if(rpr_bits){ ++ int f, new_w, new_h; ++ rpr_bits = FFMIN((rpr_bits >> 1) + 1, 3); + +- f= get_bits(&s->gb, av_log2(v)+1); ++ f = get_bits(&s->gb, rpr_bits); + + if(f){ + new_w= 4*((uint8_t*)s->avctx->extradata)[6+2*f]; +@@ -381,25 +377,19 @@ + } + + if(s->avctx->debug & FF_DEBUG_PICT_INFO){ +- av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, v); ++ av_log(s->avctx, AV_LOG_DEBUG, "F %d/%d\n", f, rpr_bits); + } +- }else{ +- seq= get_bits(&s->gb, 8)*128; +- } ++ } else if (av_image_check_size(s->width, s->height, 0, s->avctx) < 0) ++ return AVERROR_INVALIDDATA; ++ ++ mb_pos = ff_h263_decode_mba(s); + +-// if(s->avctx->sub_id <= 0x20201002){ //0x20201002 definitely needs this +- mb_pos= ff_h263_decode_mba(s); +-/* }else{ +- mb_pos= get_bits(&s->gb, av_log2(s->mb_num-1)+1); +- s->mb_x= mb_pos % s->mb_width; +- s->mb_y= mb_pos / s->mb_width; +- }*/ + //av_log(s->avctx, AV_LOG_DEBUG, "%d\n", seq); + seq |= s->time &~0x7FFF; + if(seq - s->time > 0x4000) seq -= 0x8000; + if(seq - s->time < -0x4000) seq += 0x8000; + if(seq != s->time){ +- if(s->pict_type!=FF_B_TYPE){ ++ if(s->pict_type!=AV_PICTURE_TYPE_B){ + s->time= seq; + s->pp_time= s->time - s->last_non_b_time; + s->last_non_b_time= s->time; +@@ -420,9 +410,12 @@ + av_log(s->avctx, AV_LOG_DEBUG, "\n");*/ + s->no_rounding= get_bits1(&s->gb); + ++ if(RV_GET_MINOR_VER(s->avctx->sub_id) <= 1 && s->pict_type == AV_PICTURE_TYPE_B) ++ skip_bits(&s->gb, 5); // binary decoder reads 3+2 bits here but they don't seem to be used ++ + s->f_code = 1; + s->unrestricted_mv = 1; +- s->h263_aic= s->pict_type == FF_I_TYPE; ++ s->h263_aic= s->pict_type == AV_PICTURE_TYPE_I; + // s->alt_inter_vlc=1; + // s->obmc=1; + // s->umvplus=1; +@@ -435,7 +428,7 @@ + seq, s->mb_x, s->mb_y, s->pict_type, s->qscale, s->no_rounding); + } + +- assert(s->pict_type != FF_B_TYPE || !s->low_delay); ++ assert(s->pict_type != AV_PICTURE_TYPE_B || !s->low_delay); + + return s->mb_width*s->mb_height - mb_pos; + } +@@ -444,6 +437,7 @@ + { + MpegEncContext *s = avctx->priv_data; + static int done=0; ++ int major_ver, minor_ver, micro_ver; + + if (avctx->extradata_size < 8) { + av_log(avctx, AV_LOG_ERROR, "Extradata is too small.\n"); +@@ -462,32 +456,27 @@ + s->h263_long_vectors= ((uint8_t*)avctx->extradata)[3] & 1; + avctx->sub_id= AV_RB32((uint8_t*)avctx->extradata + 4); + +- if (avctx->sub_id == 0x10000000) { +- s->rv10_version= 0; +- s->low_delay=1; +- } else if (avctx->sub_id == 0x10001000) { +- s->rv10_version= 3; +- s->low_delay=1; +- } else if (avctx->sub_id == 0x10002000) { +- s->rv10_version= 3; +- s->low_delay=1; +- s->obmc=1; +- } else if (avctx->sub_id == 0x10003000) { +- s->rv10_version= 3; +- s->low_delay=1; +- } else if (avctx->sub_id == 0x10003001) { +- s->rv10_version= 3; +- s->low_delay=1; +- } else if ( avctx->sub_id == 0x20001000 +- || (avctx->sub_id >= 0x20100000 && avctx->sub_id < 0x201a0000)) { +- s->low_delay=1; +- } else if ( avctx->sub_id == 0x30202002 +- || avctx->sub_id == 0x30203002 +- || (avctx->sub_id >= 0x20200002 && avctx->sub_id < 0x20300000)) { +- s->low_delay=0; +- s->avctx->has_b_frames=1; +- } else ++ major_ver = RV_GET_MAJOR_VER(avctx->sub_id); ++ minor_ver = RV_GET_MINOR_VER(avctx->sub_id); ++ micro_ver = RV_GET_MICRO_VER(avctx->sub_id); ++ ++ s->low_delay = 1; ++ switch (major_ver) { ++ case 1: ++ s->rv10_version = micro_ver ? 3 : 1; ++ s->obmc = micro_ver == 2; ++ break; ++ case 2: ++ if (minor_ver >= 2) { ++ s->low_delay = 0; ++ s->avctx->has_b_frames = 1; ++ } ++ break; ++ default: + av_log(s->avctx, AV_LOG_ERROR, "unknown header %X\n", avctx->sub_id); ++ av_log_missing_feature(avctx, "RV1/2 version", 1); ++ return AVERROR_PATCHWELCOME; ++ } + + if(avctx->debug & FF_DEBUG_PICT_INFO){ + av_log(avctx, AV_LOG_DEBUG, "ver:%X ver0:%X\n", avctx->sub_id, avctx->extradata_size >= 4 ? ((uint32_t*)avctx->extradata)[0] : -1); +@@ -526,9 +515,10 @@ + const uint8_t *buf, int buf_size, int buf_size2) + { + MpegEncContext *s = avctx->priv_data; +- int mb_count, mb_pos, left, start_mb_x; ++ int mb_count, mb_pos, left, start_mb_x, active_bits_size; + +- init_get_bits(&s->gb, buf, buf_size*8); ++ active_bits_size = buf_size * 8; ++ init_get_bits(&s->gb, buf, FFMAX(buf_size, buf_size2) * 8); + if(s->codec_id ==CODEC_ID_RV10) + mb_count = rv10_decode_picture_header(s); + else +@@ -559,8 +549,14 @@ + if(MPV_frame_start(s, avctx) < 0) + return -1; + ff_er_frame_start(s); ++ } else { ++ if (s->current_picture_ptr->f.pict_type != s->pict_type) { ++ av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); ++ return -1; ++ } + } + ++ + av_dlog(avctx, "qscale=%d\n", s->qscale); + + /* default quantization values */ +@@ -606,17 +602,30 @@ + s->mv_type = MV_TYPE_16X16; + ret=ff_h263_decode_mb(s, s->block); + +- if (ret != SLICE_ERROR && s->gb.size_in_bits < get_bits_count(&s->gb) && 8*buf_size2 >= get_bits_count(&s->gb)){ +- av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", s->gb.size_in_bits, 8*buf_size2); +- s->gb.size_in_bits= 8*buf_size2; ++ // Repeat the slice end check from ff_h263_decode_mb with our active ++ // bitstream size ++ if (ret != SLICE_ERROR) { ++ int v = show_bits(&s->gb, 16); ++ ++ if (get_bits_count(&s->gb) + 16 > active_bits_size) ++ v >>= get_bits_count(&s->gb) + 16 - active_bits_size; ++ ++ if (!v) ++ ret = SLICE_END; ++ } ++ if (ret != SLICE_ERROR && active_bits_size < get_bits_count(&s->gb) && ++ 8 * buf_size2 >= get_bits_count(&s->gb)) { ++ active_bits_size = buf_size2 * 8; ++ av_log(avctx, AV_LOG_DEBUG, "update size from %d to %d\n", ++ 8 * buf_size, active_bits_size); + ret= SLICE_OK; + } + +- if (ret == SLICE_ERROR || s->gb.size_in_bits < get_bits_count(&s->gb)) { ++ if (ret == SLICE_ERROR || active_bits_size < get_bits_count(&s->gb)) { + av_log(s->avctx, AV_LOG_ERROR, "ERROR at MB %d %d\n", s->mb_x, s->mb_y); + return -1; + } +- if(s->pict_type != FF_B_TYPE) ++ if(s->pict_type != AV_PICTURE_TYPE_B) + ff_h263_update_motion_val(s); + MPV_decode_mb(s, s->block); + if(s->loop_filter) +@@ -632,9 +641,9 @@ + if(ret == SLICE_END) break; + } + +- ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); ++ ff_er_add_slice(s, start_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + +- return s->gb.size_in_bits; ++ return active_bits_size; + } + + static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) +@@ -656,6 +665,8 @@ + const uint8_t *slices_hdr = NULL; + + av_dlog(avctx, "*****frame %d size=%d\n", avctx->frame_number, buf_size); ++ s->flags = avctx->flags; ++ s->flags2 = avctx->flags2; + + /* no supplementary picture */ + if (buf_size == 0) { +@@ -664,15 +675,22 @@ + + if(!avctx->slice_count){ + slice_count = (*buf++) + 1; ++ buf_size--; + slices_hdr = buf + 4; + buf += 8 * slice_count; ++ buf_size -= 8 * slice_count; ++ if (buf_size <= 0) ++ return AVERROR_INVALIDDATA; + }else + slice_count = avctx->slice_count; + + for(i=0; i= buf_size) ++ return AVERROR_INVALIDDATA; ++ + if(i+1 == slice_count) + size= buf_size - offset; + else +@@ -683,6 +701,10 @@ + else + size2= get_slice_offset(avctx, slices_hdr, i+2) - offset; + ++ if (size <= 0 || size2 <= 0 || ++ offset + FFMAX(size, size2) > buf_size) ++ return AVERROR_INVALIDDATA; ++ + if(rv10_decode_packet(avctx, buf+offset, size, size2) > 8*size) + i++; + } +@@ -691,7 +713,7 @@ + ff_er_frame_end(s); + MPV_frame_end(s); + +- if (s->pict_type == FF_B_TYPE || s->low_delay) { ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { + *pict= *(AVFrame*)s->current_picture_ptr; + } else if (s->last_picture_ptr != NULL) { + *pict= *(AVFrame*)s->last_picture_ptr; +@@ -704,34 +726,32 @@ + s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...) + } + +- return buf_size; ++ return avpkt->size; + } + + AVCodec ff_rv10_decoder = { +- "rv10", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV10, +- sizeof(MpegEncContext), +- rv10_decode_init, +- NULL, +- rv10_decode_end, +- rv10_decode_frame, +- CODEC_CAP_DR1, ++ .name = "rv10", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV10, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = rv10_decode_init, ++ .close = rv10_decode_end, ++ .decode = rv10_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("RealVideo 1.0"), + .pix_fmts= ff_pixfmt_list_420, + }; + + AVCodec ff_rv20_decoder = { +- "rv20", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV20, +- sizeof(MpegEncContext), +- rv10_decode_init, +- NULL, +- rv10_decode_end, +- rv10_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .name = "rv20", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV20, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = rv10_decode_init, ++ .close = rv10_decode_end, ++ .decode = rv10_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, + .flush= ff_mpeg_flush, + .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("RealVideo 2.0"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv10enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv10enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv10enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv10enc.c 2012-05-14 14:08:54.179336863 +0200 +@@ -32,17 +32,17 @@ + { + int full_frame= 0; + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + + put_bits(&s->pb, 1, 1); /* marker */ + +- put_bits(&s->pb, 1, (s->pict_type == FF_P_TYPE)); ++ put_bits(&s->pb, 1, (s->pict_type == AV_PICTURE_TYPE_P)); + + put_bits(&s->pb, 1, 0); /* not PB frame */ + + put_bits(&s->pb, 5, s->qscale); + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + /* specific MPEG like DC coding not used */ + } + /* if multiple packets per frame are sent, the position at which +@@ -57,13 +57,13 @@ + } + + AVCodec ff_rv10_encoder = { +- "rv10", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV10, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "rv10", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV10, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("RealVideo 1.0"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv20enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv20enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv20enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv20enc.c 2012-05-14 14:08:54.180336883 +0200 +@@ -47,7 +47,7 @@ + assert(s->modified_quant==1); + assert(s->loop_filter==1); + +- s->h263_aic= s->pict_type == FF_I_TYPE; ++ s->h263_aic= s->pict_type == AV_PICTURE_TYPE_I; + if(s->h263_aic){ + s->y_dc_scale_table= + s->c_dc_scale_table= ff_aic_dc_scale_table; +@@ -58,13 +58,13 @@ + } + + AVCodec ff_rv20_encoder = { +- "rv20", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV20, +- sizeof(MpegEncContext), +- MPV_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "rv20", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV20, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = MPV_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("RealVideo 2.0"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv30.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv30.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv30.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv30.c 2012-05-14 14:08:54.181336903 +0200 +@@ -51,6 +51,11 @@ + skip_bits1(gb); + si->pts = get_bits(gb, 13); + rpr = get_bits(gb, r->rpr); ++ if (r->s.avctx->extradata_size < 8 + rpr*2) { ++ av_log(r->s.avctx, AV_LOG_WARNING, ++ "Extradata does not contain selected resolution\n"); ++ rpr = 0; ++ } + if(rpr){ + w = r->s.avctx->extradata[6 + rpr*2] << 2; + h = r->s.avctx->extradata[7 + rpr*2] << 2; +@@ -74,7 +79,7 @@ + for(i = 0; i < 4; i++, dst += r->intra_types_stride - 4){ + for(j = 0; j < 4; j+= 2){ + int code = svq3_get_ue_golomb(gb) << 1; +- if(code >= 81*2){ ++ if(code >= 81U*2U){ + av_log(r->s.avctx, AV_LOG_ERROR, "Incorrect intra prediction code\n"); + return -1; + } +@@ -103,7 +108,7 @@ + GetBitContext *gb = &s->gb; + int code = svq3_get_ue_golomb(gb); + +- if(code > 11){ ++ if(code > 11U){ + av_log(s->avctx, AV_LOG_ERROR, "Incorrect MB type code\n"); + return -1; + } +@@ -111,7 +116,7 @@ + av_log(s->avctx, AV_LOG_ERROR, "dquant needed\n"); + code -= 6; + } +- if(s->pict_type != FF_B_TYPE) ++ if(s->pict_type != AV_PICTURE_TYPE_B) + return rv30_p_types[code]; + else + return rv30_b_types[code]; +@@ -142,7 +147,7 @@ + + mb_pos = row * s->mb_stride; + for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ +- int mbtype = s->current_picture_ptr->mb_type[mb_pos]; ++ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; + if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) + r->deblock_coefs[mb_pos] = 0xFFFF; + if(IS_INTRA(mbtype)) +@@ -154,11 +159,11 @@ + */ + mb_pos = row * s->mb_stride; + for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ +- cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]]; ++ cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos]]; + if(mb_x) +- left_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - 1]]; ++ left_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos - 1]]; + for(j = 0; j < 16; j += 4){ +- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize + 4 * !mb_x; ++ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize + 4 * !mb_x; + for(i = !mb_x; i < 4; i++, Y += 4){ + int ij = i + j; + loc_lim = 0; +@@ -178,7 +183,7 @@ + if(mb_x) + left_cbp = (r->cbp_chroma[mb_pos - 1] >> (k*4)) & 0xF; + for(j = 0; j < 8; j += 4){ +- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize + 4 * !mb_x; ++ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j) * s->uvlinesize + 4 * !mb_x; + for(i = !mb_x; i < 2; i++, C += 4){ + int ij = i + (j >> 1); + loc_lim = 0; +@@ -196,11 +201,11 @@ + } + mb_pos = row * s->mb_stride; + for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ +- cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos]]; ++ cur_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos]]; + if(row) +- top_lim = rv30_loop_filt_lim[s->current_picture_ptr->qscale_table[mb_pos - s->mb_stride]]; ++ top_lim = rv30_loop_filt_lim[s->current_picture_ptr->f.qscale_table[mb_pos - s->mb_stride]]; + for(j = 4*!row; j < 16; j += 4){ +- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize; ++ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; + for(i = 0; i < 4; i++, Y += 4){ + int ij = i + j; + loc_lim = 0; +@@ -220,7 +225,7 @@ + if(row) + top_cbp = (r->cbp_chroma[mb_pos - s->mb_stride] >> (k*4)) & 0xF; + for(j = 4*!row; j < 8; j += 4){ +- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize; ++ C = s->current_picture_ptr->f.data[k+1] + mb_x*8 + (row*8 + j) * s->uvlinesize; + for(i = 0; i < 2; i++, C += 4){ + int ij = i + (j >> 1); + loc_lim = 0; +@@ -267,16 +272,17 @@ + } + + AVCodec ff_rv30_decoder = { +- "rv30", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV30, +- sizeof(RV34DecContext), +- rv30_decode_init, +- NULL, +- ff_rv34_decode_end, +- ff_rv34_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, +- .flush = ff_mpeg_flush, +- .long_name = NULL_IF_CONFIG_SMALL("RealVideo 3.0"), +- .pix_fmts= ff_pixfmt_list_420, ++ .name = "rv30", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV30, ++ .priv_data_size = sizeof(RV34DecContext), ++ .init = rv30_decode_init, ++ .close = ff_rv34_decode_end, ++ .decode = ff_rv34_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS, ++ .flush = ff_mpeg_flush, ++ .long_name = NULL_IF_CONFIG_SMALL("RealVideo 3.0"), ++ .pix_fmts = ff_pixfmt_list_420, ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv30dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv30dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv30dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv30dsp.c 2012-05-14 14:08:54.182336923 +0200 +@@ -26,13 +26,14 @@ + + #include "avcodec.h" + #include "dsputil.h" ++#include "rv34dsp.h" + + #define RV30_LOWPASS(OPNAME, OP) \ + static av_unused void OPNAME ## rv30_tpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, const int C1, const int C2){\ +- const int h=8;\ ++ const int h = 8;\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + int i;\ +- for(i=0; i>4);\ + OP(dst[1], (-(src[ 0]+src[3]) + src[1]*C1 + src[2]*C2 + 8)>>4);\ +@@ -42,28 +43,28 @@ + OP(dst[5], (-(src[ 4]+src[7]) + src[5]*C1 + src[6]*C2 + 8)>>4);\ + OP(dst[6], (-(src[ 5]+src[8]) + src[6]*C1 + src[7]*C2 + 8)>>4);\ + OP(dst[7], (-(src[ 6]+src[9]) + src[7]*C1 + src[8]*C2 + 8)>>4);\ +- dst+=dstStride;\ +- src+=srcStride;\ ++ dst += dstStride;\ ++ src += srcStride;\ + }\ + }\ + \ + static void OPNAME ## rv30_tpel8_v_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, const int C1, const int C2){\ +- const int w=8;\ ++ const int w = 8;\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + int i;\ +- for(i=0; i>4);\ + OP(dst[1*dstStride], (-(src0+src3) + src1*C1 + src2*C2 + 8)>>4);\ + OP(dst[2*dstStride], (-(src1+src4) + src2*C1 + src3*C2 + 8)>>4);\ +@@ -251,41 +252,49 @@ + RV30_MC(avg_, 8) + RV30_MC(avg_, 16) + +-av_cold void ff_rv30dsp_init(DSPContext* c, AVCodecContext *avctx) { +- c->put_rv30_tpel_pixels_tab[0][ 0] = c->put_h264_qpel_pixels_tab[0][0]; +- c->put_rv30_tpel_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c; +- c->put_rv30_tpel_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c; +- c->put_rv30_tpel_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c; +- c->put_rv30_tpel_pixels_tab[0][ 5] = put_rv30_tpel16_mc11_c; +- c->put_rv30_tpel_pixels_tab[0][ 6] = put_rv30_tpel16_mc21_c; +- c->put_rv30_tpel_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c; +- c->put_rv30_tpel_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c; +- c->put_rv30_tpel_pixels_tab[0][10] = put_rv30_tpel16_mc22_c; +- c->avg_rv30_tpel_pixels_tab[0][ 0] = c->avg_h264_qpel_pixels_tab[0][0]; +- c->avg_rv30_tpel_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c; +- c->avg_rv30_tpel_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c; +- c->avg_rv30_tpel_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c; +- c->avg_rv30_tpel_pixels_tab[0][ 5] = avg_rv30_tpel16_mc11_c; +- c->avg_rv30_tpel_pixels_tab[0][ 6] = avg_rv30_tpel16_mc21_c; +- c->avg_rv30_tpel_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c; +- c->avg_rv30_tpel_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c; +- c->avg_rv30_tpel_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c; +- c->put_rv30_tpel_pixels_tab[1][ 0] = c->put_h264_qpel_pixels_tab[1][0]; +- c->put_rv30_tpel_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c; +- c->put_rv30_tpel_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c; +- c->put_rv30_tpel_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c; +- c->put_rv30_tpel_pixels_tab[1][ 5] = put_rv30_tpel8_mc11_c; +- c->put_rv30_tpel_pixels_tab[1][ 6] = put_rv30_tpel8_mc21_c; +- c->put_rv30_tpel_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c; +- c->put_rv30_tpel_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c; +- c->put_rv30_tpel_pixels_tab[1][10] = put_rv30_tpel8_mc22_c; +- c->avg_rv30_tpel_pixels_tab[1][ 0] = c->avg_h264_qpel_pixels_tab[1][0]; +- c->avg_rv30_tpel_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c; +- c->avg_rv30_tpel_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c; +- c->avg_rv30_tpel_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c; +- c->avg_rv30_tpel_pixels_tab[1][ 5] = avg_rv30_tpel8_mc11_c; +- c->avg_rv30_tpel_pixels_tab[1][ 6] = avg_rv30_tpel8_mc21_c; +- c->avg_rv30_tpel_pixels_tab[1][ 8] = avg_rv30_tpel8_mc02_c; +- c->avg_rv30_tpel_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c; +- c->avg_rv30_tpel_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c; ++av_cold void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp) { ++ ++ ff_rv34dsp_init(c, dsp); ++ ++ c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0]; ++ c->put_pixels_tab[0][ 1] = put_rv30_tpel16_mc10_c; ++ c->put_pixels_tab[0][ 2] = put_rv30_tpel16_mc20_c; ++ c->put_pixels_tab[0][ 4] = put_rv30_tpel16_mc01_c; ++ c->put_pixels_tab[0][ 5] = put_rv30_tpel16_mc11_c; ++ c->put_pixels_tab[0][ 6] = put_rv30_tpel16_mc21_c; ++ c->put_pixels_tab[0][ 8] = put_rv30_tpel16_mc02_c; ++ c->put_pixels_tab[0][ 9] = put_rv30_tpel16_mc12_c; ++ c->put_pixels_tab[0][10] = put_rv30_tpel16_mc22_c; ++ c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0]; ++ c->avg_pixels_tab[0][ 1] = avg_rv30_tpel16_mc10_c; ++ c->avg_pixels_tab[0][ 2] = avg_rv30_tpel16_mc20_c; ++ c->avg_pixels_tab[0][ 4] = avg_rv30_tpel16_mc01_c; ++ c->avg_pixels_tab[0][ 5] = avg_rv30_tpel16_mc11_c; ++ c->avg_pixels_tab[0][ 6] = avg_rv30_tpel16_mc21_c; ++ c->avg_pixels_tab[0][ 8] = avg_rv30_tpel16_mc02_c; ++ c->avg_pixels_tab[0][ 9] = avg_rv30_tpel16_mc12_c; ++ c->avg_pixels_tab[0][10] = avg_rv30_tpel16_mc22_c; ++ c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0]; ++ c->put_pixels_tab[1][ 1] = put_rv30_tpel8_mc10_c; ++ c->put_pixels_tab[1][ 2] = put_rv30_tpel8_mc20_c; ++ c->put_pixels_tab[1][ 4] = put_rv30_tpel8_mc01_c; ++ c->put_pixels_tab[1][ 5] = put_rv30_tpel8_mc11_c; ++ c->put_pixels_tab[1][ 6] = put_rv30_tpel8_mc21_c; ++ c->put_pixels_tab[1][ 8] = put_rv30_tpel8_mc02_c; ++ c->put_pixels_tab[1][ 9] = put_rv30_tpel8_mc12_c; ++ c->put_pixels_tab[1][10] = put_rv30_tpel8_mc22_c; ++ c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0]; ++ c->avg_pixels_tab[1][ 1] = avg_rv30_tpel8_mc10_c; ++ c->avg_pixels_tab[1][ 2] = avg_rv30_tpel8_mc20_c; ++ c->avg_pixels_tab[1][ 4] = avg_rv30_tpel8_mc01_c; ++ c->avg_pixels_tab[1][ 5] = avg_rv30_tpel8_mc11_c; ++ c->avg_pixels_tab[1][ 6] = avg_rv30_tpel8_mc21_c; ++ c->avg_pixels_tab[1][ 8] = avg_rv30_tpel8_mc02_c; ++ c->avg_pixels_tab[1][ 9] = avg_rv30_tpel8_mc12_c; ++ c->avg_pixels_tab[1][10] = avg_rv30_tpel8_mc22_c; ++ ++ c->put_chroma_pixels_tab[0] = dsp->put_h264_chroma_pixels_tab[0]; ++ c->put_chroma_pixels_tab[1] = dsp->put_h264_chroma_pixels_tab[1]; ++ c->avg_chroma_pixels_tab[0] = dsp->avg_h264_chroma_pixels_tab[0]; ++ c->avg_chroma_pixels_tab[1] = dsp->avg_h264_chroma_pixels_tab[1]; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34.c 2012-05-14 14:08:54.188337043 +0200 +@@ -24,12 +24,16 @@ + * RV30/40 decoder common data + */ + ++#include "libavutil/internal.h" ++ + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" + #include "golomb.h" ++#include "internal.h" + #include "mathops.h" + #include "rectangle.h" ++#include "thread.h" + + #include "rv34vlc.h" + #include "rv34data.h" +@@ -62,8 +66,10 @@ + + static RV34VLC intra_vlcs[NUM_INTRA_TABLES], inter_vlcs[NUM_INTER_TABLES]; + ++static int rv34_decode_mv(RV34DecContext *r, int block_type); ++ + /** +- * @defgroup vlc RV30/40 VLC generating functions ++ * @name RV30/40 VLC generating functions + * @{ + */ + +@@ -169,84 +175,8 @@ + + /** @} */ // vlc group + +- +-/** +- * @defgroup transform RV30/40 inverse transform functions +- * @{ +- */ +- +-static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block) +-{ +- int i; +- +- for(i=0; i<4; i++){ +- const int z0= 13*(block[i+8*0] + block[i+8*2]); +- const int z1= 13*(block[i+8*0] - block[i+8*2]); +- const int z2= 7* block[i+8*1] - 17*block[i+8*3]; +- const int z3= 17* block[i+8*1] + 7*block[i+8*3]; +- +- temp[4*i+0]= z0+z3; +- temp[4*i+1]= z1+z2; +- temp[4*i+2]= z1-z2; +- temp[4*i+3]= z0-z3; +- } +-} +- +-/** +- * Real Video 3.0/4.0 inverse transform +- * Code is almost the same as in SVQ3, only scaling is different. +- */ +-static void rv34_inv_transform(DCTELEM *block){ +- int temp[16]; +- int i; +- +- rv34_row_transform(temp, block); +- +- for(i=0; i<4; i++){ +- const int z0= 13*(temp[4*0+i] + temp[4*2+i]) + 0x200; +- const int z1= 13*(temp[4*0+i] - temp[4*2+i]) + 0x200; +- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i]; +- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i]; +- +- block[i*8+0]= (z0 + z3)>>10; +- block[i*8+1]= (z1 + z2)>>10; +- block[i*8+2]= (z1 - z2)>>10; +- block[i*8+3]= (z0 - z3)>>10; +- } +- +-} +- +-/** +- * RealVideo 3.0/4.0 inverse transform for DC block +- * +- * Code is almost the same as rv34_inv_transform() +- * but final coefficients are multiplied by 1.5 and have no rounding. +- */ +-static void rv34_inv_transform_noround(DCTELEM *block){ +- int temp[16]; +- int i; +- +- rv34_row_transform(temp, block); +- +- for(i=0; i<4; i++){ +- const int z0= 13*(temp[4*0+i] + temp[4*2+i]); +- const int z1= 13*(temp[4*0+i] - temp[4*2+i]); +- const int z2= 7* temp[4*1+i] - 17*temp[4*3+i]; +- const int z3= 17* temp[4*1+i] + 7*temp[4*3+i]; +- +- block[i*8+0]= ((z0 + z3)*3)>>11; +- block[i*8+1]= ((z1 + z2)*3)>>11; +- block[i*8+2]= ((z1 - z2)*3)>>11; +- block[i*8+3]= ((z0 - z3)*3)>>11; +- } +- +-} +- +-/** @} */ // transform +- +- + /** +- * @defgroup block RV30/40 4x4 block decoding functions ++ * @name RV30/40 4x4 block decoding functions + * @{ + */ + +@@ -274,7 +204,7 @@ + } + + for(i = 0; i < 4; i++){ +- t = modulo_three_table[code][i]; ++ t = (modulo_three_table[code] >> (6 - 2*i)) & 3; + if(t == 1) + cbp |= cbp_masks[get_bits1(gb)] << i; + if(t == 2) +@@ -286,7 +216,7 @@ + /** + * Get one coefficient value from the bistream and store it. + */ +-static inline void decode_coeff(DCTELEM *dst, int coef, int esc, GetBitContext *gb, VLC* vlc) ++static inline void decode_coeff(DCTELEM *dst, int coef, int esc, GetBitContext *gb, VLC* vlc, int q) + { + if(coef){ + if(coef == esc){ +@@ -299,30 +229,51 @@ + } + if(get_bits1(gb)) + coef = -coef; +- *dst = coef; ++ *dst = (coef*q + 8) >> 4; + } + } + + /** + * Decode 2x2 subblock of coefficients. + */ +-static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc) ++static inline void decode_subblock(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc, int q) ++{ ++ int flags = modulo_three_table[code]; ++ ++ decode_coeff( dst+0*4+0, (flags >> 6) , 3, gb, vlc, q); ++ if(is_block2){ ++ decode_coeff(dst+1*4+0, (flags >> 4) & 3, 2, gb, vlc, q); ++ decode_coeff(dst+0*4+1, (flags >> 2) & 3, 2, gb, vlc, q); ++ }else{ ++ decode_coeff(dst+0*4+1, (flags >> 4) & 3, 2, gb, vlc, q); ++ decode_coeff(dst+1*4+0, (flags >> 2) & 3, 2, gb, vlc, q); ++ } ++ decode_coeff( dst+1*4+1, (flags >> 0) & 3, 2, gb, vlc, q); ++} ++ ++/** ++ * Decode a single coefficient. ++ */ ++static inline void decode_subblock1(DCTELEM *dst, int code, GetBitContext *gb, VLC *vlc, int q) ++{ ++ int coeff = modulo_three_table[code] >> 6; ++ decode_coeff(dst, coeff, 3, gb, vlc, q); ++} ++ ++static inline void decode_subblock3(DCTELEM *dst, int code, const int is_block2, GetBitContext *gb, VLC *vlc, ++ int q_dc, int q_ac1, int q_ac2) + { +- int coeffs[4]; ++ int flags = modulo_three_table[code]; + +- coeffs[0] = modulo_three_table[code][0]; +- coeffs[1] = modulo_three_table[code][1]; +- coeffs[2] = modulo_three_table[code][2]; +- coeffs[3] = modulo_three_table[code][3]; +- decode_coeff(dst , coeffs[0], 3, gb, vlc); ++ decode_coeff( dst+0*4+0, (flags >> 6) , 3, gb, vlc, q_dc); + if(is_block2){ +- decode_coeff(dst+8, coeffs[1], 2, gb, vlc); +- decode_coeff(dst+1, coeffs[2], 2, gb, vlc); ++ decode_coeff(dst+1*4+0, (flags >> 4) & 3, 2, gb, vlc, q_ac1); ++ decode_coeff(dst+0*4+1, (flags >> 2) & 3, 2, gb, vlc, q_ac1); + }else{ +- decode_coeff(dst+1, coeffs[1], 2, gb, vlc); +- decode_coeff(dst+8, coeffs[2], 2, gb, vlc); ++ decode_coeff(dst+0*4+1, (flags >> 4) & 3, 2, gb, vlc, q_ac1); ++ decode_coeff(dst+1*4+0, (flags >> 2) & 3, 2, gb, vlc, q_ac1); + } +- decode_coeff(dst+9, coeffs[3], 2, gb, vlc); ++ decode_coeff( dst+1*4+1, (flags >> 0) & 3, 2, gb, vlc, q_ac2); + } + + /** +@@ -336,64 +287,42 @@ + * o--o + */ + +-static inline void rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc) ++static inline int rv34_decode_block(DCTELEM *dst, GetBitContext *gb, RV34VLC *rvlc, int fc, int sc, int q_dc, int q_ac1, int q_ac2) + { +- int code, pattern; ++ int code, pattern, has_ac = 1; + + code = get_vlc2(gb, rvlc->first_pattern[fc].table, 9, 2); + + pattern = code & 0x7; + + code >>= 3; +- decode_subblock(dst, code, 0, gb, &rvlc->coefficient); ++ ++ if (modulo_three_table[code] & 0x3F) { ++ decode_subblock3(dst, code, 0, gb, &rvlc->coefficient, q_dc, q_ac1, q_ac2); ++ } else { ++ decode_subblock1(dst, code, gb, &rvlc->coefficient, q_dc); ++ if (!pattern) ++ return 0; ++ has_ac = 0; ++ } + + if(pattern & 4){ + code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2); +- decode_subblock(dst + 2, code, 0, gb, &rvlc->coefficient); ++ decode_subblock(dst + 4*0+2, code, 0, gb, &rvlc->coefficient, q_ac2); + } + if(pattern & 2){ // Looks like coefficients 1 and 2 are swapped for this block + code = get_vlc2(gb, rvlc->second_pattern[sc].table, 9, 2); +- decode_subblock(dst + 8*2, code, 1, gb, &rvlc->coefficient); ++ decode_subblock(dst + 4*2+0, code, 1, gb, &rvlc->coefficient, q_ac2); + } + if(pattern & 1){ + code = get_vlc2(gb, rvlc->third_pattern[sc].table, 9, 2); +- decode_subblock(dst + 8*2+2, code, 0, gb, &rvlc->coefficient); ++ decode_subblock(dst + 4*2+2, code, 0, gb, &rvlc->coefficient, q_ac2); + } +- +-} +- +-/** +- * Dequantize ordinary 4x4 block. +- * @todo optimize +- */ +-static inline void rv34_dequant4x4(DCTELEM *block, int Qdc, int Q) +-{ +- int i, j; +- +- block[0] = (block[0] * Qdc + 8) >> 4; +- for(i = 0; i < 4; i++) +- for(j = !i; j < 4; j++) +- block[j + i*8] = (block[j + i*8] * Q + 8) >> 4; +-} +- +-/** +- * Dequantize 4x4 block of DC values for 16x16 macroblock. +- * @todo optimize +- */ +-static inline void rv34_dequant4x4_16x16(DCTELEM *block, int Qdc, int Q) +-{ +- int i; +- +- for(i = 0; i < 3; i++) +- block[rv34_dezigzag[i]] = (block[rv34_dezigzag[i]] * Qdc + 8) >> 4; +- for(; i < 16; i++) +- block[rv34_dezigzag[i]] = (block[rv34_dezigzag[i]] * Q + 8) >> 4; ++ return has_ac || pattern; + } +-/** @} */ //block functions +- + + /** +- * @defgroup rv3040_bitstream RV30/40 bitstream parsing ++ * @name RV30/40 bitstream parsing + * @{ + */ + +@@ -422,20 +351,101 @@ + } + + /** +- * Decode quantizer difference and return modified quantizer. ++ * Decode intra macroblock header and return CBP in case of success, -1 otherwise. + */ +-static inline int rv34_decode_dquant(GetBitContext *gb, int quant) ++static int rv34_decode_intra_mb_header(RV34DecContext *r, int8_t *intra_types) + { +- if(get_bits1(gb)) +- return rv34_dquant_tab[get_bits1(gb)][quant]; +- else +- return get_bits(gb, 5); ++ MpegEncContext *s = &r->s; ++ GetBitContext *gb = &s->gb; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ int t; ++ ++ r->is16 = get_bits1(gb); ++ if(r->is16){ ++ s->current_picture_ptr->f.mb_type[mb_pos] = MB_TYPE_INTRA16x16; ++ r->block_type = RV34_MB_TYPE_INTRA16x16; ++ t = get_bits(gb, 2); ++ fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0])); ++ r->luma_vlc = 2; ++ }else{ ++ if(!r->rv30){ ++ if(!get_bits1(gb)) ++ av_log(s->avctx, AV_LOG_ERROR, "Need DQUANT\n"); ++ } ++ s->current_picture_ptr->f.mb_type[mb_pos] = MB_TYPE_INTRA; ++ r->block_type = RV34_MB_TYPE_INTRA; ++ if(r->decode_intra_types(r, gb, intra_types) < 0) ++ return -1; ++ r->luma_vlc = 1; ++ } ++ ++ r->chroma_vlc = 0; ++ r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); ++ ++ return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); ++} ++ ++/** ++ * Decode inter macroblock header and return CBP in case of success, -1 otherwise. ++ */ ++static int rv34_decode_inter_mb_header(RV34DecContext *r, int8_t *intra_types) ++{ ++ MpegEncContext *s = &r->s; ++ GetBitContext *gb = &s->gb; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ int i, t; ++ ++ r->block_type = r->decode_mb_info(r); ++ if(r->block_type == -1) ++ return -1; ++ s->current_picture_ptr->f.mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type]; ++ r->mb_type[mb_pos] = r->block_type; ++ if(r->block_type == RV34_MB_SKIP){ ++ if(s->pict_type == AV_PICTURE_TYPE_P) ++ r->mb_type[mb_pos] = RV34_MB_P_16x16; ++ if(s->pict_type == AV_PICTURE_TYPE_B) ++ r->mb_type[mb_pos] = RV34_MB_B_DIRECT; ++ } ++ r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->f.mb_type[mb_pos]); ++ rv34_decode_mv(r, r->block_type); ++ if(r->block_type == RV34_MB_SKIP){ ++ fill_rectangle(intra_types, 4, 4, r->intra_types_stride, 0, sizeof(intra_types[0])); ++ return 0; ++ } ++ r->chroma_vlc = 1; ++ r->luma_vlc = 0; ++ ++ if(IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos])){ ++ if(r->is16){ ++ t = get_bits(gb, 2); ++ fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0])); ++ r->luma_vlc = 2; ++ }else{ ++ if(r->decode_intra_types(r, gb, intra_types) < 0) ++ return -1; ++ r->luma_vlc = 1; ++ } ++ r->chroma_vlc = 0; ++ r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); ++ }else{ ++ for(i = 0; i < 16; i++) ++ intra_types[(i & 3) + (i>>2) * r->intra_types_stride] = 0; ++ r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); ++ if(r->mb_type[mb_pos] == RV34_MB_P_MIX16x16){ ++ r->is16 = 1; ++ r->chroma_vlc = 1; ++ r->luma_vlc = 2; ++ r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); ++ } ++ } ++ ++ return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); + } + + /** @} */ //bitstream functions + + /** +- * @defgroup mv motion vector related code (prediction, reconstruction, motion compensation) ++ * @name motion vector related code (prediction, reconstruction, motion compensation) + * @{ + */ + +@@ -470,27 +480,27 @@ + c_off = -1; + + if(r->avail_cache[avail_index - 1]){ +- A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0]; +- A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1]; ++ A[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-1][0]; ++ A[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-1][1]; + } + if(r->avail_cache[avail_index - 4]){ +- B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0]; +- B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1]; ++ B[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride][0]; ++ B[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride][1]; + }else{ + B[0] = A[0]; + B[1] = A[1]; + } + if(!r->avail_cache[avail_index - 4 + c_off]){ + if(r->avail_cache[avail_index - 4] && (r->avail_cache[avail_index - 1] || r->rv30)){ +- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0]; +- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1]; ++ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride-1][0]; ++ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride-1][1]; + }else{ + C[0] = A[0]; + C[1] = A[1]; + } + }else{ +- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][0]; +- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+c_off][1]; ++ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride+c_off][0]; ++ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos-s->b8_stride+c_off][1]; + } + mx = mid_pred(A[0], B[0], C[0]); + my = mid_pred(A[1], B[1], C[1]); +@@ -498,8 +508,8 @@ + my += r->dmv[dmv_no][1]; + for(j = 0; j < part_sizes_h[block_type]; j++){ + for(i = 0; i < part_sizes_w[block_type]; i++){ +- s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx; +- s->current_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][1] = my; ++ s->current_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][0] = mx; ++ s->current_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][1] = my; + } + } + } +@@ -511,12 +521,8 @@ + */ + static int calc_add_mv(RV34DecContext *r, int dir, int val) + { +- int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts); +- int dist = dir ? -GET_PTS_DIFF(r->next_pts, r->cur_pts) : GET_PTS_DIFF(r->cur_pts, r->last_pts); +- int mul; ++ int mul = dir ? -r->weight2 : r->weight1; + +- if(!refdist) return 0; +- mul = (dist << 14) / refdist; + return (val * mul + 0x2000) >> 14; + } + +@@ -554,28 +560,28 @@ + int i, j; + Picture *cur_pic = s->current_picture_ptr; + const int mask = dir ? MB_TYPE_L1 : MB_TYPE_L0; +- int type = cur_pic->mb_type[mb_pos]; ++ int type = cur_pic->f.mb_type[mb_pos]; + + memset(A, 0, sizeof(A)); + memset(B, 0, sizeof(B)); + memset(C, 0, sizeof(C)); + if((r->avail_cache[6-1] & type) & mask){ +- A[0] = cur_pic->motion_val[dir][mv_pos - 1][0]; +- A[1] = cur_pic->motion_val[dir][mv_pos - 1][1]; ++ A[0] = cur_pic->f.motion_val[dir][mv_pos - 1][0]; ++ A[1] = cur_pic->f.motion_val[dir][mv_pos - 1][1]; + has_A = 1; + } + if((r->avail_cache[6-4] & type) & mask){ +- B[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][0]; +- B[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride][1]; ++ B[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride][0]; ++ B[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride][1]; + has_B = 1; + } + if(r->avail_cache[6-4] && (r->avail_cache[6-2] & type) & mask){ +- C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][0]; +- C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride + 2][1]; ++ C[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride + 2][0]; ++ C[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride + 2][1]; + has_C = 1; + }else if((s->mb_x+1) == s->mb_width && (r->avail_cache[6-5] & type) & mask){ +- C[0] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][0]; +- C[1] = cur_pic->motion_val[dir][mv_pos - s->b8_stride - 1][1]; ++ C[0] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride - 1][0]; ++ C[1] = cur_pic->f.motion_val[dir][mv_pos - s->b8_stride - 1][1]; + has_C = 1; + } + +@@ -586,12 +592,12 @@ + + for(j = 0; j < 2; j++){ + for(i = 0; i < 2; i++){ +- cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx; +- cur_pic->motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my; ++ cur_pic->f.motion_val[dir][mv_pos + i + j*s->b8_stride][0] = mx; ++ cur_pic->f.motion_val[dir][mv_pos + i + j*s->b8_stride][1] = my; + } + } + if(block_type == RV34_MB_B_BACKWARD || block_type == RV34_MB_B_FORWARD){ +- ZERO8x2(cur_pic->motion_val[!dir][mv_pos], s->b8_stride); ++ ZERO8x2(cur_pic->f.motion_val[!dir][mv_pos], s->b8_stride); + } + } + +@@ -608,27 +614,27 @@ + int avail_index = avail_indexes[0]; + + if(r->avail_cache[avail_index - 1]){ +- A[0] = s->current_picture_ptr->motion_val[0][mv_pos-1][0]; +- A[1] = s->current_picture_ptr->motion_val[0][mv_pos-1][1]; ++ A[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - 1][0]; ++ A[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - 1][1]; + } + if(r->avail_cache[avail_index - 4]){ +- B[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][0]; +- B[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride][1]; ++ B[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride][0]; ++ B[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride][1]; + }else{ + B[0] = A[0]; + B[1] = A[1]; + } + if(!r->avail_cache[avail_index - 4 + 2]){ + if(r->avail_cache[avail_index - 4] && (r->avail_cache[avail_index - 1])){ +- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][0]; +- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride-1][1]; ++ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride - 1][0]; ++ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride - 1][1]; + }else{ + C[0] = A[0]; + C[1] = A[1]; + } + }else{ +- C[0] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+2][0]; +- C[1] = s->current_picture_ptr->motion_val[0][mv_pos-s->b8_stride+2][1]; ++ C[0] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride + 2][0]; ++ C[1] = s->current_picture_ptr->f.motion_val[0][mv_pos - s->b8_stride + 2][1]; + } + mx = mid_pred(A[0], B[0], C[0]); + my = mid_pred(A[1], B[1], C[1]); +@@ -637,8 +643,8 @@ + for(j = 0; j < 2; j++){ + for(i = 0; i < 2; i++){ + for(k = 0; k < 2; k++){ +- s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][0] = mx; +- s->current_picture_ptr->motion_val[k][mv_pos + i + j*s->b8_stride][1] = my; ++ s->current_picture_ptr->f.motion_val[k][mv_pos + i + j*s->b8_stride][0] = mx; ++ s->current_picture_ptr->f.motion_val[k][mv_pos + i + j*s->b8_stride][1] = my; + } + } + } +@@ -664,7 +670,7 @@ + static inline void rv34_mc(RV34DecContext *r, const int block_type, + const int xoff, const int yoff, int mv_off, + const int width, const int height, int dir, +- const int thirdpel, ++ const int thirdpel, int weighted, + qpel_mc_func (*qpel_mc)[16], + h264_chroma_mc_func (*chroma_mc)) + { +@@ -676,24 +682,24 @@ + + if(thirdpel){ + int chroma_mx, chroma_my; +- mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24); +- my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24); +- lx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + (3 << 24)) % 3; +- ly = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + (3 << 24)) % 3; +- chroma_mx = (s->current_picture_ptr->motion_val[dir][mv_pos][0] + 1) >> 1; +- chroma_my = (s->current_picture_ptr->motion_val[dir][mv_pos][1] + 1) >> 1; ++ mx = (s->current_picture_ptr->f.motion_val[dir][mv_pos][0] + (3 << 24)) / 3 - (1 << 24); ++ my = (s->current_picture_ptr->f.motion_val[dir][mv_pos][1] + (3 << 24)) / 3 - (1 << 24); ++ lx = (s->current_picture_ptr->f.motion_val[dir][mv_pos][0] + (3 << 24)) % 3; ++ ly = (s->current_picture_ptr->f.motion_val[dir][mv_pos][1] + (3 << 24)) % 3; ++ chroma_mx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] / 2; ++ chroma_my = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] / 2; + umx = (chroma_mx + (3 << 24)) / 3 - (1 << 24); + umy = (chroma_my + (3 << 24)) / 3 - (1 << 24); + uvmx = chroma_coeffs[(chroma_mx + (3 << 24)) % 3]; + uvmy = chroma_coeffs[(chroma_my + (3 << 24)) % 3]; + }else{ + int cx, cy; +- mx = s->current_picture_ptr->motion_val[dir][mv_pos][0] >> 2; +- my = s->current_picture_ptr->motion_val[dir][mv_pos][1] >> 2; +- lx = s->current_picture_ptr->motion_val[dir][mv_pos][0] & 3; +- ly = s->current_picture_ptr->motion_val[dir][mv_pos][1] & 3; +- cx = s->current_picture_ptr->motion_val[dir][mv_pos][0] / 2; +- cy = s->current_picture_ptr->motion_val[dir][mv_pos][1] / 2; ++ mx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] >> 2; ++ my = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] >> 2; ++ lx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] & 3; ++ ly = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] & 3; ++ cx = s->current_picture_ptr->f.motion_val[dir][mv_pos][0] / 2; ++ cy = s->current_picture_ptr->f.motion_val[dir][mv_pos][1] / 2; + umx = cx >> 2; + umy = cy >> 2; + uvmx = (cx & 3) << 1; +@@ -702,10 +708,18 @@ + if(uvmx == 6 && uvmy == 6) + uvmx = uvmy = 4; + } ++ ++ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) { ++ /* wait for the referenced mb row to be finished */ ++ int mb_row = s->mb_y + ((yoff + my + 5 + 8 * height) >> 4); ++ AVFrame *f = dir ? &s->next_picture_ptr->f : &s->last_picture_ptr->f; ++ ff_thread_await_progress(f, mb_row, 0); ++ } ++ + dxy = ly*4 + lx; +- srcY = dir ? s->next_picture_ptr->data[0] : s->last_picture_ptr->data[0]; +- srcU = dir ? s->next_picture_ptr->data[1] : s->last_picture_ptr->data[1]; +- srcV = dir ? s->next_picture_ptr->data[2] : s->last_picture_ptr->data[2]; ++ srcY = dir ? s->next_picture_ptr->f.data[0] : s->last_picture_ptr->f.data[0]; ++ srcU = dir ? s->next_picture_ptr->f.data[1] : s->last_picture_ptr->f.data[1]; ++ srcV = dir ? s->next_picture_ptr->f.data[2] : s->last_picture_ptr->f.data[2]; + src_x = s->mb_x * 16 + xoff + mx; + src_y = s->mb_y * 16 + yoff + my; + uvsrc_x = s->mb_x * 8 + (xoff >> 1) + umx; +@@ -713,9 +727,10 @@ + srcY += src_y * s->linesize + src_x; + srcU += uvsrc_y * s->uvlinesize + uvsrc_x; + srcV += uvsrc_y * s->uvlinesize + uvsrc_x; +- if( (unsigned)(src_x - !!lx*2) > s->h_edge_pos - !!lx*2 - (width <<3) - 4 +- || (unsigned)(src_y - !!ly*2) > s->v_edge_pos - !!ly*2 - (height<<3) - 4){ +- uint8_t *uvbuf= s->edge_emu_buffer + 22 * s->linesize; ++ if(s->h_edge_pos - (width << 3) < 6 || s->v_edge_pos - (height << 3) < 6 || ++ (unsigned)(src_x - !!lx*2) > s->h_edge_pos - !!lx*2 - (width <<3) - 4 || ++ (unsigned)(src_y - !!ly*2) > s->v_edge_pos - !!ly*2 - (height<<3) - 4) { ++ uint8_t *uvbuf = s->edge_emu_buffer + 22 * s->linesize; + + srcY -= 2 + 2*s->linesize; + s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, (width<<3)+6, (height<<3)+6, +@@ -728,9 +743,15 @@ + srcU = uvbuf; + srcV = uvbuf + 16; + } +- Y = s->dest[0] + xoff + yoff *s->linesize; +- U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; +- V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; ++ if(!weighted){ ++ Y = s->dest[0] + xoff + yoff *s->linesize; ++ U = s->dest[1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; ++ V = s->dest[2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; ++ }else{ ++ Y = r->tmp_b_block_y [dir] + xoff + yoff *s->linesize; ++ U = r->tmp_b_block_uv[dir*2] + (xoff>>1) + (yoff>>1)*s->uvlinesize; ++ V = r->tmp_b_block_uv[dir*2+1] + (xoff>>1) + (yoff>>1)*s->uvlinesize; ++ } + + if(block_type == RV34_MB_P_16x8){ + qpel_mc[1][dxy](Y, srcY, s->linesize); +@@ -751,43 +772,70 @@ + const int xoff, const int yoff, int mv_off, + const int width, const int height, int dir) + { +- rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30, +- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab +- : r->s.dsp.put_rv40_qpel_pixels_tab, +- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab +- : r->s.dsp.put_rv40_chroma_pixels_tab); ++ rv34_mc(r, block_type, xoff, yoff, mv_off, width, height, dir, r->rv30, 0, ++ r->rdsp.put_pixels_tab, ++ r->rdsp.put_chroma_pixels_tab); ++} ++ ++static void rv4_weight(RV34DecContext *r) ++{ ++ r->rdsp.rv40_weight_pixels_tab[0](r->s.dest[0], ++ r->tmp_b_block_y[0], ++ r->tmp_b_block_y[1], ++ r->weight1, ++ r->weight2, ++ r->s.linesize); ++ r->rdsp.rv40_weight_pixels_tab[1](r->s.dest[1], ++ r->tmp_b_block_uv[0], ++ r->tmp_b_block_uv[2], ++ r->weight1, ++ r->weight2, ++ r->s.uvlinesize); ++ r->rdsp.rv40_weight_pixels_tab[1](r->s.dest[2], ++ r->tmp_b_block_uv[1], ++ r->tmp_b_block_uv[3], ++ r->weight1, ++ r->weight2, ++ r->s.uvlinesize); + } + + static void rv34_mc_2mv(RV34DecContext *r, const int block_type) + { +- rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30, +- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab +- : r->s.dsp.put_rv40_qpel_pixels_tab, +- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab +- : r->s.dsp.put_rv40_chroma_pixels_tab); +- rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, +- r->rv30 ? r->s.dsp.avg_rv30_tpel_pixels_tab +- : r->s.dsp.avg_rv40_qpel_pixels_tab, +- r->rv30 ? r->s.dsp.avg_h264_chroma_pixels_tab +- : r->s.dsp.avg_rv40_chroma_pixels_tab); ++ int weighted = !r->rv30 && block_type != RV34_MB_B_BIDIR && r->weight1 != 8192; ++ ++ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 0, r->rv30, weighted, ++ r->rdsp.put_pixels_tab, ++ r->rdsp.put_chroma_pixels_tab); ++ if(!weighted){ ++ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 0, ++ r->rdsp.avg_pixels_tab, ++ r->rdsp.avg_chroma_pixels_tab); ++ }else{ ++ rv34_mc(r, block_type, 0, 0, 0, 2, 2, 1, r->rv30, 1, ++ r->rdsp.put_pixels_tab, ++ r->rdsp.put_chroma_pixels_tab); ++ rv4_weight(r); ++ } + } + + static void rv34_mc_2mv_skip(RV34DecContext *r) + { + int i, j; ++ int weighted = !r->rv30 && r->weight1 != 8192; ++ + for(j = 0; j < 2; j++) + for(i = 0; i < 2; i++){ + rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 0, r->rv30, +- r->rv30 ? r->s.dsp.put_rv30_tpel_pixels_tab +- : r->s.dsp.put_rv40_qpel_pixels_tab, +- r->rv30 ? r->s.dsp.put_h264_chroma_pixels_tab +- : r->s.dsp.put_rv40_chroma_pixels_tab); ++ weighted, ++ r->rdsp.put_pixels_tab, ++ r->rdsp.put_chroma_pixels_tab); + rv34_mc(r, RV34_MB_P_8x8, i*8, j*8, i+j*r->s.b8_stride, 1, 1, 1, r->rv30, +- r->rv30 ? r->s.dsp.avg_rv30_tpel_pixels_tab +- : r->s.dsp.avg_rv40_qpel_pixels_tab, +- r->rv30 ? r->s.dsp.avg_h264_chroma_pixels_tab +- : r->s.dsp.avg_rv40_chroma_pixels_tab); ++ weighted, ++ weighted ? r->rdsp.put_pixels_tab : r->rdsp.avg_pixels_tab, ++ weighted ? r->rdsp.put_chroma_pixels_tab : r->rdsp.avg_chroma_pixels_tab); + } ++ if(weighted) ++ rv4_weight(r); + } + + /** number of motion vectors in each macroblock type */ +@@ -813,31 +861,35 @@ + switch(block_type){ + case RV34_MB_TYPE_INTRA: + case RV34_MB_TYPE_INTRA16x16: +- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ++ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); + return 0; + case RV34_MB_SKIP: +- if(s->pict_type == FF_P_TYPE){ +- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ++ if(s->pict_type == AV_PICTURE_TYPE_P){ ++ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); + rv34_mc_1mv (r, block_type, 0, 0, 0, 2, 2, 0); + break; + } + case RV34_MB_B_DIRECT: + //surprisingly, it uses motion scheme from next reference frame +- next_bt = s->next_picture_ptr->mb_type[s->mb_x + s->mb_y * s->mb_stride]; ++ /* wait for the current mb row to be finished */ ++ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) ++ ff_thread_await_progress(&s->next_picture_ptr->f, FFMAX(0, s->mb_y-1), 0); ++ ++ next_bt = s->next_picture_ptr->f.mb_type[s->mb_x + s->mb_y * s->mb_stride]; + if(IS_INTRA(next_bt) || IS_SKIP(next_bt)){ +- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); +- ZERO8x2(s->current_picture_ptr->motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ++ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ++ ZERO8x2(s->current_picture_ptr->f.motion_val[1][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); + }else + for(j = 0; j < 2; j++) + for(i = 0; i < 2; i++) + for(k = 0; k < 2; k++) + for(l = 0; l < 2; l++) +- s->current_picture_ptr->motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->motion_val[0][mv_pos + i + j*s->b8_stride][k]); ++ s->current_picture_ptr->f.motion_val[l][mv_pos + i + j*s->b8_stride][k] = calc_add_mv(r, l, s->next_picture_ptr->f.motion_val[0][mv_pos + i + j*s->b8_stride][k]); + if(!(IS_16X8(next_bt) || IS_8X16(next_bt) || IS_8X8(next_bt))) //we can use whole macroblock MC + rv34_mc_2mv(r, block_type); + else + rv34_mc_2mv_skip(r); +- ZERO8x2(s->current_picture_ptr->motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); ++ ZERO8x2(s->current_picture_ptr->f.motion_val[0][s->mb_x * 2 + s->mb_y * 2 * s->b8_stride], s->b8_stride); + break; + case RV34_MB_P_16x16: + case RV34_MB_P_MIX16x16: +@@ -885,7 +937,7 @@ + /** @} */ // mv group + + /** +- * @defgroup recons Macroblock reconstruction functions ++ * @name Macroblock reconstruction functions + * @{ + */ + /** mapping of RV30/40 intra prediction types to standard H.264 types */ +@@ -923,21 +975,12 @@ + if(itype == VERT_LEFT_PRED) itype = VERT_LEFT_PRED_RV40_NODOWN; + } + if(!right && up){ +- topleft = dst[-stride + 3] * 0x01010101; ++ topleft = dst[-stride + 3] * 0x01010101u; + prev = (uint8_t*)&topleft; + } + r->h.pred4x4[itype](dst, prev, stride); + } + +-/** add_pixels_clamped for 4x4 block */ +-static void rv34_add_4x4_block(uint8_t *dst, int stride, DCTELEM block[64], int off) +-{ +- int x, y; +- for(y = 0; y < 4; y++) +- for(x = 0; x < 4; x++) +- dst[x + y*stride] = av_clip_uint8(dst[x + y*stride] + block[off + x+y*8]); +-} +- + static inline int adjust_pred16(int itype, int up, int left) + { + if(!up && !left) +@@ -954,15 +997,35 @@ + return itype; + } + +-static void rv34_output_macroblock(RV34DecContext *r, int8_t *intra_types, int cbp, int is16) ++static inline void rv34_process_block(RV34DecContext *r, ++ uint8_t *pdst, int stride, ++ int fc, int sc, int q_dc, int q_ac) + { + MpegEncContext *s = &r->s; +- DSPContext *dsp = &s->dsp; +- int i, j; +- uint8_t *Y, *U, *V; +- int itype; +- int avail[6*8] = {0}; +- int idx; ++ DCTELEM *ptr = s->block[0]; ++ int has_ac = rv34_decode_block(ptr, &s->gb, r->cur_vlcs, ++ fc, sc, q_dc, q_ac, q_ac); ++ if(has_ac){ ++ r->rdsp.rv34_idct_add(pdst, stride, ptr); ++ }else{ ++ r->rdsp.rv34_idct_dc_add(pdst, stride, ptr[0]); ++ ptr[0] = 0; ++ } ++} ++ ++static void rv34_output_i16x16(RV34DecContext *r, int8_t *intra_types, int cbp) ++{ ++ LOCAL_ALIGNED_16(DCTELEM, block16, [16]); ++ MpegEncContext *s = &r->s; ++ GetBitContext *gb = &s->gb; ++ int q_dc = rv34_qscale_tab[ r->luma_dc_quant_i[s->qscale] ], ++ q_ac = rv34_qscale_tab[s->qscale]; ++ uint8_t *dst = s->dest[0]; ++ DCTELEM *ptr = s->block[0]; ++ int avail[6*8] = {0}; ++ int i, j, itype, has_ac; ++ ++ memset(block16, 0, 16 * sizeof(*block16)); + + // Set neighbour information. + if(r->avail_cache[1]) +@@ -978,151 +1041,118 @@ + if(r->avail_cache[9]) + avail[24] = avail[32] = 1; + +- Y = s->dest[0]; +- U = s->dest[1]; +- V = s->dest[2]; +- if(!is16){ +- for(j = 0; j < 4; j++){ +- idx = 9 + j*8; +- for(i = 0; i < 4; i++, cbp >>= 1, Y += 4, idx++){ +- rv34_pred_4x4_block(r, Y, s->linesize, ittrans[intra_types[i]], avail[idx-8], avail[idx-1], avail[idx+7], avail[idx-7]); +- avail[idx] = 1; +- if(cbp & 1) +- rv34_add_4x4_block(Y, s->linesize, s->block[(i>>1)+(j&2)], (i&1)*4+(j&1)*32); +- } +- Y += s->linesize * 4 - 4*4; +- intra_types += r->intra_types_stride; +- } +- intra_types -= r->intra_types_stride * 4; +- fill_rectangle(r->avail_cache + 6, 2, 2, 4, 0, 4); +- for(j = 0; j < 2; j++){ +- idx = 6 + j*4; +- for(i = 0; i < 2; i++, cbp >>= 1, idx++){ +- rv34_pred_4x4_block(r, U + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); +- rv34_pred_4x4_block(r, V + i*4 + j*4*s->uvlinesize, s->uvlinesize, ittrans[intra_types[i*2+j*2*r->intra_types_stride]], r->avail_cache[idx-4], r->avail_cache[idx-1], !i && !j, r->avail_cache[idx-3]); +- r->avail_cache[idx] = 1; +- if(cbp & 0x01) +- rv34_add_4x4_block(U + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[4], i*4+j*32); +- if(cbp & 0x10) +- rv34_add_4x4_block(V + i*4 + j*4*s->uvlinesize, s->uvlinesize, s->block[5], i*4+j*32); +- } ++ has_ac = rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0, q_dc, q_dc, q_ac); ++ if(has_ac) ++ r->rdsp.rv34_inv_transform(block16); ++ else ++ r->rdsp.rv34_inv_transform_dc(block16); ++ ++ itype = ittrans16[intra_types[0]]; ++ itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); ++ r->h.pred16x16[itype](dst, s->linesize); ++ ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++, cbp >>= 1){ ++ int dc = block16[i + j*4]; ++ ++ if(cbp & 1){ ++ has_ac = rv34_decode_block(ptr, gb, r->cur_vlcs, r->luma_vlc, 0, q_ac, q_ac, q_ac); ++ }else ++ has_ac = 0; ++ ++ if(has_ac){ ++ ptr[0] = dc; ++ r->rdsp.rv34_idct_add(dst+4*i, s->linesize, ptr); ++ }else ++ r->rdsp.rv34_idct_dc_add(dst+4*i, s->linesize, dc); + } +- }else{ +- itype = ittrans16[intra_types[0]]; +- itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); +- r->h.pred16x16[itype](Y, s->linesize); +- dsp->add_pixels_clamped(s->block[0], Y, s->linesize); +- dsp->add_pixels_clamped(s->block[1], Y + 8, s->linesize); +- Y += s->linesize * 8; +- dsp->add_pixels_clamped(s->block[2], Y, s->linesize); +- dsp->add_pixels_clamped(s->block[3], Y + 8, s->linesize); + +- itype = ittrans16[intra_types[0]]; +- if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; +- itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); +- r->h.pred8x8[itype](U, s->uvlinesize); +- dsp->add_pixels_clamped(s->block[4], U, s->uvlinesize); +- r->h.pred8x8[itype](V, s->uvlinesize); +- dsp->add_pixels_clamped(s->block[5], V, s->uvlinesize); ++ dst += 4*s->linesize; + } +-} + +-/** @} */ // recons group ++ itype = ittrans16[intra_types[0]]; ++ if(itype == PLANE_PRED8x8) itype = DC_PRED8x8; ++ itype = adjust_pred16(itype, r->avail_cache[6-4], r->avail_cache[6-1]); + +-/** +- * @addtogroup bitstream +- * Decode macroblock header and return CBP in case of success, -1 otherwise. +- */ +-static int rv34_decode_mb_header(RV34DecContext *r, int8_t *intra_types) +-{ +- MpegEncContext *s = &r->s; +- GetBitContext *gb = &s->gb; +- int mb_pos = s->mb_x + s->mb_y * s->mb_stride; +- int i, t; ++ q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; ++ q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; + +- if(!r->si.type){ +- r->is16 = get_bits1(gb); +- if(!r->is16 && !r->rv30){ +- if(!get_bits1(gb)) +- av_log(s->avctx, AV_LOG_ERROR, "Need DQUANT\n"); +- } +- s->current_picture_ptr->mb_type[mb_pos] = r->is16 ? MB_TYPE_INTRA16x16 : MB_TYPE_INTRA; +- r->block_type = r->is16 ? RV34_MB_TYPE_INTRA16x16 : RV34_MB_TYPE_INTRA; +- }else{ +- r->block_type = r->decode_mb_info(r); +- if(r->block_type == -1) +- return -1; +- s->current_picture_ptr->mb_type[mb_pos] = rv34_mb_type_to_lavc[r->block_type]; +- r->mb_type[mb_pos] = r->block_type; +- if(r->block_type == RV34_MB_SKIP){ +- if(s->pict_type == FF_P_TYPE) +- r->mb_type[mb_pos] = RV34_MB_P_16x16; +- if(s->pict_type == FF_B_TYPE) +- r->mb_type[mb_pos] = RV34_MB_B_DIRECT; +- } +- r->is16 = !!IS_INTRA16x16(s->current_picture_ptr->mb_type[mb_pos]); +- rv34_decode_mv(r, r->block_type); +- if(r->block_type == RV34_MB_SKIP){ +- fill_rectangle(intra_types, 4, 4, r->intra_types_stride, 0, sizeof(intra_types[0])); +- return 0; ++ for(j = 1; j < 3; j++){ ++ dst = s->dest[j]; ++ r->h.pred8x8[itype](dst, s->uvlinesize); ++ for(i = 0; i < 4; i++, cbp >>= 1){ ++ uint8_t *pdst; ++ if(!(cbp & 1)) continue; ++ pdst = dst + (i&1)*4 + (i&2)*2*s->uvlinesize; ++ ++ rv34_process_block(r, pdst, s->uvlinesize, ++ r->chroma_vlc, 1, q_dc, q_ac); + } +- r->chroma_vlc = 1; +- r->luma_vlc = 0; + } +- if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])){ +- if(r->is16){ +- t = get_bits(gb, 2); +- fill_rectangle(intra_types, 4, 4, r->intra_types_stride, t, sizeof(intra_types[0])); +- r->luma_vlc = 2; +- }else{ +- if(r->decode_intra_types(r, gb, intra_types) < 0) +- return -1; +- r->luma_vlc = 1; +- } +- r->chroma_vlc = 0; +- r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); +- }else{ +- for(i = 0; i < 16; i++) +- intra_types[(i & 3) + (i>>2) * r->intra_types_stride] = 0; +- r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); +- if(r->mb_type[mb_pos] == RV34_MB_P_MIX16x16){ +- r->is16 = 1; +- r->chroma_vlc = 1; +- r->luma_vlc = 2; +- r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 0); ++} ++ ++static void rv34_output_intra(RV34DecContext *r, int8_t *intra_types, int cbp) ++{ ++ MpegEncContext *s = &r->s; ++ uint8_t *dst = s->dest[0]; ++ int avail[6*8] = {0}; ++ int i, j, k; ++ int idx, q_ac, q_dc; ++ ++ // Set neighbour information. ++ if(r->avail_cache[1]) ++ avail[0] = 1; ++ if(r->avail_cache[2]) ++ avail[1] = avail[2] = 1; ++ if(r->avail_cache[3]) ++ avail[3] = avail[4] = 1; ++ if(r->avail_cache[4]) ++ avail[5] = 1; ++ if(r->avail_cache[5]) ++ avail[8] = avail[16] = 1; ++ if(r->avail_cache[9]) ++ avail[24] = avail[32] = 1; ++ ++ q_ac = rv34_qscale_tab[s->qscale]; ++ for(j = 0; j < 4; j++){ ++ idx = 9 + j*8; ++ for(i = 0; i < 4; i++, cbp >>= 1, dst += 4, idx++){ ++ rv34_pred_4x4_block(r, dst, s->linesize, ittrans[intra_types[i]], avail[idx-8], avail[idx-1], avail[idx+7], avail[idx-7]); ++ avail[idx] = 1; ++ if(!(cbp & 1)) continue; ++ ++ rv34_process_block(r, dst, s->linesize, ++ r->luma_vlc, 0, q_ac, q_ac); + } ++ dst += s->linesize * 4 - 4*4; ++ intra_types += r->intra_types_stride; + } + +- return rv34_decode_cbp(gb, r->cur_vlcs, r->is16); +-} ++ intra_types -= r->intra_types_stride * 4; + +-/** +- * @addtogroup recons +- * @{ +- */ +-/** +- * mask for retrieving all bits in coded block pattern +- * corresponding to one 8x8 block +- */ +-#define LUMA_CBP_BLOCK_MASK 0x33 ++ q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; ++ q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; + +-#define U_CBP_MASK 0x0F0000 +-#define V_CBP_MASK 0xF00000 ++ for(k = 0; k < 2; k++){ ++ dst = s->dest[1+k]; ++ fill_rectangle(r->avail_cache + 6, 2, 2, 4, 0, 4); + ++ for(j = 0; j < 2; j++){ ++ int* acache = r->avail_cache + 6 + j*4; ++ for(i = 0; i < 2; i++, cbp >>= 1, acache++){ ++ int itype = ittrans[intra_types[i*2+j*2*r->intra_types_stride]]; ++ rv34_pred_4x4_block(r, dst+4*i, s->uvlinesize, itype, acache[-4], acache[-1], !i && !j, acache[-3]); ++ acache[0] = 1; + +-static void rv34_apply_differences(RV34DecContext *r, int cbp) +-{ +- static const int shifts[4] = { 0, 2, 8, 10 }; +- MpegEncContext *s = &r->s; +- int i; ++ if(!(cbp&1)) continue; + +- for(i = 0; i < 4; i++) +- if((cbp & (LUMA_CBP_BLOCK_MASK << shifts[i])) || r->block_type == RV34_MB_P_MIX16x16) +- s->dsp.add_pixels_clamped(s->block[i], s->dest[0] + (i & 1)*8 + (i&2)*4*s->linesize, s->linesize); +- if(cbp & U_CBP_MASK) +- s->dsp.add_pixels_clamped(s->block[4], s->dest[1], s->uvlinesize); +- if(cbp & V_CBP_MASK) +- s->dsp.add_pixels_clamped(s->block[5], s->dest[2], s->uvlinesize); ++ rv34_process_block(r, dst + 4*i, s->uvlinesize, ++ r->chroma_vlc, 1, q_dc, q_ac); ++ } ++ ++ dst += 4*s->uvlinesize; ++ } ++ } + } + + static int is_mv_diff_gt_3(int16_t (*motion_val)[2], int step) +@@ -1142,7 +1172,7 @@ + MpegEncContext *s = &r->s; + int hmvmask = 0, vmvmask = 0, i, j; + int midx = s->mb_x * 2 + s->mb_y * 2 * s->b8_stride; +- int16_t (*motion_val)[2] = &s->current_picture_ptr->motion_val[0][midx]; ++ int16_t (*motion_val)[2] = &s->current_picture_ptr->f.motion_val[0][midx]; + for(j = 0; j < 16; j += 8){ + for(i = 0; i < 2; i++){ + if(is_mv_diff_gt_3(motion_val + i, 1)) +@@ -1167,16 +1197,17 @@ + return hmvmask | vmvmask; + } + +-static int rv34_decode_macroblock(RV34DecContext *r, int8_t *intra_types) ++static int rv34_decode_inter_macroblock(RV34DecContext *r, int8_t *intra_types) + { +- MpegEncContext *s = &r->s; +- GetBitContext *gb = &s->gb; ++ MpegEncContext *s = &r->s; ++ GetBitContext *gb = &s->gb; ++ uint8_t *dst = s->dest[0]; ++ DCTELEM *ptr = s->block[0]; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + int cbp, cbp2; +- int i, blknum, blkoff; +- DCTELEM block16[64]; +- int luma_dc_quant; ++ int q_dc, q_ac, has_ac; ++ int i, j; + int dist; +- int mb_pos = s->mb_x + s->mb_y * s->mb_stride; + + // Calculate which neighbours are available. Maybe it's worth optimizing too. + memset(r->avail_cache, 0, sizeof(r->avail_cache)); +@@ -1184,62 +1215,133 @@ + dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; + if(s->mb_x && dist) + r->avail_cache[5] = +- r->avail_cache[9] = s->current_picture_ptr->mb_type[mb_pos - 1]; ++ r->avail_cache[9] = s->current_picture_ptr->f.mb_type[mb_pos - 1]; + if(dist >= s->mb_width) + r->avail_cache[2] = +- r->avail_cache[3] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride]; ++ r->avail_cache[3] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride]; + if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) +- r->avail_cache[4] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride + 1]; ++ r->avail_cache[4] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride + 1]; + if(s->mb_x && dist > s->mb_width) +- r->avail_cache[1] = s->current_picture_ptr->mb_type[mb_pos - s->mb_stride - 1]; ++ r->avail_cache[1] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride - 1]; + + s->qscale = r->si.quant; +- cbp = cbp2 = rv34_decode_mb_header(r, intra_types); ++ cbp = cbp2 = rv34_decode_inter_mb_header(r, intra_types); + r->cbp_luma [mb_pos] = cbp; + r->cbp_chroma[mb_pos] = cbp >> 16; +- if(s->pict_type == FF_I_TYPE) +- r->deblock_coefs[mb_pos] = 0xFFFF; +- else +- r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos]; +- s->current_picture_ptr->qscale_table[mb_pos] = s->qscale; ++ r->deblock_coefs[mb_pos] = rv34_set_deblock_coef(r) | r->cbp_luma[mb_pos]; ++ s->current_picture_ptr->f.qscale_table[mb_pos] = s->qscale; + + if(cbp == -1) + return -1; + +- luma_dc_quant = r->block_type == RV34_MB_P_MIX16x16 ? r->luma_dc_quant_p[s->qscale] : r->luma_dc_quant_i[s->qscale]; +- if(r->is16){ +- memset(block16, 0, sizeof(block16)); +- rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0); +- rv34_dequant4x4_16x16(block16, rv34_qscale_tab[luma_dc_quant],rv34_qscale_tab[s->qscale]); +- rv34_inv_transform_noround(block16); +- } +- +- for(i = 0; i < 16; i++, cbp >>= 1){ +- if(!r->is16 && !(cbp & 1)) continue; +- blknum = ((i & 2) >> 1) + ((i & 8) >> 2); +- blkoff = ((i & 1) << 2) + ((i & 4) << 3); +- if(cbp & 1) +- rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->luma_vlc, 0); +- rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[s->qscale],rv34_qscale_tab[s->qscale]); +- if(r->is16) //FIXME: optimize +- s->block[blknum][blkoff] = block16[(i & 3) | ((i & 0xC) << 1)]; +- rv34_inv_transform(s->block[blknum] + blkoff); ++ if (IS_INTRA(s->current_picture_ptr->f.mb_type[mb_pos])){ ++ if(r->is16) rv34_output_i16x16(r, intra_types, cbp); ++ else rv34_output_intra(r, intra_types, cbp); ++ return 0; + } +- if(r->block_type == RV34_MB_P_MIX16x16) ++ ++ if(r->is16){ ++ // Only for RV34_MB_P_MIX16x16 ++ LOCAL_ALIGNED_16(DCTELEM, block16, [16]); ++ memset(block16, 0, 16 * sizeof(*block16)); ++ q_dc = rv34_qscale_tab[ r->luma_dc_quant_p[s->qscale] ]; ++ q_ac = rv34_qscale_tab[s->qscale]; ++ if (rv34_decode_block(block16, gb, r->cur_vlcs, 3, 0, q_dc, q_dc, q_ac)) ++ r->rdsp.rv34_inv_transform(block16); ++ else ++ r->rdsp.rv34_inv_transform_dc(block16); ++ ++ q_ac = rv34_qscale_tab[s->qscale]; ++ ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++, cbp >>= 1){ ++ int dc = block16[i + j*4]; ++ ++ if(cbp & 1){ ++ has_ac = rv34_decode_block(ptr, gb, r->cur_vlcs, r->luma_vlc, 0, q_ac, q_ac, q_ac); ++ }else ++ has_ac = 0; ++ ++ if(has_ac){ ++ ptr[0] = dc; ++ r->rdsp.rv34_idct_add(dst+4*i, s->linesize, ptr); ++ }else ++ r->rdsp.rv34_idct_dc_add(dst+4*i, s->linesize, dc); ++ } ++ ++ dst += 4*s->linesize; ++ } ++ + r->cur_vlcs = choose_vlc_set(r->si.quant, r->si.vlc_set, 1); +- for(; i < 24; i++, cbp >>= 1){ +- if(!(cbp & 1)) continue; +- blknum = ((i & 4) >> 2) + 4; +- blkoff = ((i & 1) << 2) + ((i & 2) << 4); +- rv34_decode_block(s->block[blknum] + blkoff, gb, r->cur_vlcs, r->chroma_vlc, 1); +- rv34_dequant4x4(s->block[blknum] + blkoff, rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]],rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]); +- rv34_inv_transform(s->block[blknum] + blkoff); ++ }else{ ++ q_ac = rv34_qscale_tab[s->qscale]; ++ ++ for(j = 0; j < 4; j++){ ++ for(i = 0; i < 4; i++, cbp >>= 1){ ++ if(!(cbp & 1)) continue; ++ ++ rv34_process_block(r, dst + 4*i, s->linesize, ++ r->luma_vlc, 0, q_ac, q_ac); ++ } ++ dst += 4*s->linesize; ++ } ++ } ++ ++ q_dc = rv34_qscale_tab[rv34_chroma_quant[1][s->qscale]]; ++ q_ac = rv34_qscale_tab[rv34_chroma_quant[0][s->qscale]]; ++ ++ for(j = 1; j < 3; j++){ ++ dst = s->dest[j]; ++ for(i = 0; i < 4; i++, cbp >>= 1){ ++ uint8_t *pdst; ++ if(!(cbp & 1)) continue; ++ pdst = dst + (i&1)*4 + (i&2)*2*s->uvlinesize; ++ ++ rv34_process_block(r, pdst, s->uvlinesize, ++ r->chroma_vlc, 1, q_dc, q_ac); ++ } ++ } ++ ++ return 0; ++} ++ ++static int rv34_decode_intra_macroblock(RV34DecContext *r, int8_t *intra_types) ++{ ++ MpegEncContext *s = &r->s; ++ int cbp, dist; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ ++ // Calculate which neighbours are available. Maybe it's worth optimizing too. ++ memset(r->avail_cache, 0, sizeof(r->avail_cache)); ++ fill_rectangle(r->avail_cache + 6, 2, 2, 4, 1, 4); ++ dist = (s->mb_x - s->resync_mb_x) + (s->mb_y - s->resync_mb_y) * s->mb_width; ++ if(s->mb_x && dist) ++ r->avail_cache[5] = ++ r->avail_cache[9] = s->current_picture_ptr->f.mb_type[mb_pos - 1]; ++ if(dist >= s->mb_width) ++ r->avail_cache[2] = ++ r->avail_cache[3] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride]; ++ if(((s->mb_x+1) < s->mb_width) && dist >= s->mb_width - 1) ++ r->avail_cache[4] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride + 1]; ++ if(s->mb_x && dist > s->mb_width) ++ r->avail_cache[1] = s->current_picture_ptr->f.mb_type[mb_pos - s->mb_stride - 1]; ++ ++ s->qscale = r->si.quant; ++ cbp = rv34_decode_intra_mb_header(r, intra_types); ++ r->cbp_luma [mb_pos] = cbp; ++ r->cbp_chroma[mb_pos] = cbp >> 16; ++ r->deblock_coefs[mb_pos] = 0xFFFF; ++ s->current_picture_ptr->f.qscale_table[mb_pos] = s->qscale; ++ ++ if(cbp == -1) ++ return -1; ++ ++ if(r->is16){ ++ rv34_output_i16x16(r, intra_types, cbp); ++ return 0; + } +- if(IS_INTRA(s->current_picture_ptr->mb_type[mb_pos])) +- rv34_output_macroblock(r, intra_types, cbp2, r->is16); +- else +- rv34_apply_differences(r, cbp2); + ++ rv34_output_intra(r, intra_types, cbp); + return 0; + } + +@@ -1252,21 +1354,59 @@ + return 1; + if(r->s.mb_skip_run > 1) + return 0; +- bits = r->bits - get_bits_count(&s->gb); ++ bits = get_bits_left(&s->gb); + if(bits < 0 || (bits < 8 && !show_bits(&s->gb, bits))) + return 1; + return 0; + } + +-static inline int slice_compare(SliceInfo *si1, SliceInfo *si2) ++ ++static void rv34_decoder_free(RV34DecContext *r) ++{ ++ av_freep(&r->intra_types_hist); ++ r->intra_types = NULL; ++ av_freep(&r->tmp_b_block_base); ++ av_freep(&r->mb_type); ++ av_freep(&r->cbp_luma); ++ av_freep(&r->cbp_chroma); ++ av_freep(&r->deblock_coefs); ++} ++ ++ ++static int rv34_decoder_alloc(RV34DecContext *r) ++{ ++ r->intra_types_stride = r->s.mb_width * 4 + 4; ++ ++ r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * ++ sizeof(*r->cbp_chroma)); ++ r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * ++ sizeof(*r->cbp_luma)); ++ r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * ++ sizeof(*r->deblock_coefs)); ++ r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * ++ sizeof(*r->intra_types_hist)); ++ r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * ++ sizeof(*r->mb_type)); ++ ++ if (!(r->cbp_chroma && r->cbp_luma && r->deblock_coefs && ++ r->intra_types_hist && r->mb_type)) { ++ rv34_decoder_free(r); ++ return AVERROR(ENOMEM); ++ } ++ ++ r->intra_types = r->intra_types_hist + r->intra_types_stride * 4; ++ ++ return 0; ++} ++ ++ ++static int rv34_decoder_realloc(RV34DecContext *r) + { +- return si1->type != si2->type || +- si1->start >= si2->start || +- si1->width != si2->width || +- si1->height != si2->height|| +- si1->pts != si2->pts; ++ rv34_decoder_free(r); ++ return rv34_decoder_alloc(r); + } + ++ + static int rv34_decode_slice(RV34DecContext *r, int end, const uint8_t* buf, int buf_size) + { + MpegEncContext *s = &r->s; +@@ -1282,37 +1422,67 @@ + } + + if ((s->mb_x == 0 && s->mb_y == 0) || s->current_picture_ptr==NULL) { +- if(s->width != r->si.width || s->height != r->si.height){ +- av_log(s->avctx, AV_LOG_DEBUG, "Changing dimensions to %dx%d\n", r->si.width,r->si.height); ++ if (s->width != r->si.width || s->height != r->si.height) { ++ int err; ++ ++ av_log(s->avctx, AV_LOG_WARNING, "Changing dimensions to %dx%d\n", ++ r->si.width, r->si.height); + MPV_common_end(s); + s->width = r->si.width; + s->height = r->si.height; + avcodec_set_dimensions(s->avctx, s->width, s->height); +- if(MPV_common_init(s) < 0) +- return -1; +- r->intra_types_stride = s->mb_width*4 + 4; +- r->intra_types_hist = av_realloc(r->intra_types_hist, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist)); +- r->intra_types = r->intra_types_hist + r->intra_types_stride * 4; +- r->mb_type = av_realloc(r->mb_type, r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); +- r->cbp_luma = av_realloc(r->cbp_luma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); +- r->cbp_chroma = av_realloc(r->cbp_chroma, r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); +- r->deblock_coefs = av_realloc(r->deblock_coefs, r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); ++ if ((err = MPV_common_init(s)) < 0) ++ return err; ++ if ((err = rv34_decoder_realloc(r)) < 0) ++ return err; + } +- s->pict_type = r->si.type ? r->si.type : FF_I_TYPE; ++ s->pict_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I; + if(MPV_frame_start(s, s->avctx) < 0) + return -1; + ff_er_frame_start(s); ++ if (!r->tmp_b_block_base) { ++ int i; ++ ++ r->tmp_b_block_base = av_malloc(s->linesize * 48); ++ for (i = 0; i < 2; i++) ++ r->tmp_b_block_y[i] = r->tmp_b_block_base + i * 16 * s->linesize; ++ for (i = 0; i < 4; i++) ++ r->tmp_b_block_uv[i] = r->tmp_b_block_base + 32 * s->linesize ++ + (i >> 1) * 8 * s->uvlinesize + (i & 1) * 16; ++ } + r->cur_pts = r->si.pts; +- if(s->pict_type != FF_B_TYPE){ ++ if(s->pict_type != AV_PICTURE_TYPE_B){ + r->last_pts = r->next_pts; + r->next_pts = r->cur_pts; ++ }else{ ++ int refdist = GET_PTS_DIFF(r->next_pts, r->last_pts); ++ int dist0 = GET_PTS_DIFF(r->cur_pts, r->last_pts); ++ int dist1 = GET_PTS_DIFF(r->next_pts, r->cur_pts); ++ ++ if(!refdist){ ++ r->weight1 = r->weight2 = 8192; ++ }else{ ++ r->weight1 = (dist0 << 14) / refdist; ++ r->weight2 = (dist1 << 14) / refdist; ++ } + } + s->mb_x = s->mb_y = 0; ++ ff_thread_finish_setup(s->avctx); ++ } else { ++ int slice_type = r->si.type ? r->si.type : AV_PICTURE_TYPE_I; ++ ++ if (slice_type != s->pict_type) { ++ av_log(s->avctx, AV_LOG_ERROR, "Slice type mismatch\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (s->width != r->si.width || s->height != r->si.height) { ++ av_log(s->avctx, AV_LOG_ERROR, "Size mismatch\n"); ++ return AVERROR_INVALIDDATA; ++ } + } + + r->si.end = end; + s->qscale = r->si.quant; +- r->bits = buf_size*8; + s->mb_num_left = r->si.end - r->si.start; + r->s.mb_skip_run = 0; + +@@ -1324,16 +1494,19 @@ + } + memset(r->intra_types_hist, -1, r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist)); + s->first_slice_line = 1; +- s->resync_mb_x= s->mb_x; +- s->resync_mb_y= s->mb_y; ++ s->resync_mb_x = s->mb_x; ++ s->resync_mb_y = s->mb_y; + + ff_init_block_index(s); + while(!check_slice_end(r, s)) { + ff_update_block_index(s); +- s->dsp.clear_blocks(s->block[0]); + +- if(rv34_decode_macroblock(r, r->intra_types + s->mb_x * 4 + 4) < 0){ +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_ERROR|DC_ERROR|MV_ERROR); ++ if(r->si.type) ++ res = rv34_decode_inter_macroblock(r, r->intra_types + s->mb_x * 4 + 4); ++ else ++ res = rv34_decode_intra_macroblock(r, r->intra_types + s->mb_x * 4 + 4); ++ if(res < 0){ ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_ERROR); + return -1; + } + if (++s->mb_x == s->mb_width) { +@@ -1346,12 +1519,17 @@ + + if(r->loop_filter && s->mb_y >= 2) + r->loop_filter(r, s->mb_y - 2); ++ ++ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) ++ ff_thread_report_progress(&s->current_picture_ptr->f, ++ s->mb_y - 2, 0); ++ + } + if(s->mb_x == s->resync_mb_x) + s->first_slice_line=0; + s->mb_num_left--; + } +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END|DC_END|MV_END); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_MB_END); + + return s->mb_y == s->mb_height; + } +@@ -1365,13 +1543,14 @@ + { + RV34DecContext *r = avctx->priv_data; + MpegEncContext *s = &r->s; ++ int ret; + + MPV_decode_defaults(s); +- s->avctx= avctx; ++ s->avctx = avctx; + s->out_format = FMT_H263; +- s->codec_id= avctx->codec_id; ++ s->codec_id = avctx->codec_id; + +- s->width = avctx->width; ++ s->width = avctx->width; + s->height = avctx->height; + + r->s.avctx = avctx; +@@ -1381,20 +1560,22 @@ + avctx->has_b_frames = 1; + s->low_delay = 0; + +- if (MPV_common_init(s) < 0) +- return -1; +- +- ff_h264_pred_init(&r->h, CODEC_ID_RV40); ++ if ((ret = MPV_common_init(s)) < 0) ++ return ret; + +- r->intra_types_stride = 4*s->mb_stride + 4; +- r->intra_types_hist = av_malloc(r->intra_types_stride * 4 * 2 * sizeof(*r->intra_types_hist)); +- r->intra_types = r->intra_types_hist + r->intra_types_stride * 4; ++ ff_h264_pred_init(&r->h, CODEC_ID_RV40, 8, 1); + +- r->mb_type = av_mallocz(r->s.mb_stride * r->s.mb_height * sizeof(*r->mb_type)); ++#if CONFIG_RV30_DECODER ++ if (avctx->codec_id == CODEC_ID_RV30) ++ ff_rv30dsp_init(&r->rdsp, &r->s.dsp); ++#endif ++#if CONFIG_RV40_DECODER ++ if (avctx->codec_id == CODEC_ID_RV40) ++ ff_rv40dsp_init(&r->rdsp, &r->s.dsp); ++#endif + +- r->cbp_luma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_luma)); +- r->cbp_chroma = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->cbp_chroma)); +- r->deblock_coefs = av_malloc(r->s.mb_stride * r->s.mb_height * sizeof(*r->deblock_coefs)); ++ if ((ret = rv34_decoder_alloc(r)) < 0) ++ return ret; + + if(!intra_vlcs[0].cbppattern[0].bits) + rv34_init_tables(); +@@ -1402,6 +1583,58 @@ + return 0; + } + ++int ff_rv34_decode_init_thread_copy(AVCodecContext *avctx) ++{ ++ int err; ++ RV34DecContext *r = avctx->priv_data; ++ ++ r->s.avctx = avctx; ++ ++ if (avctx->internal->is_copy) { ++ r->tmp_b_block_base = NULL; ++ if ((err = MPV_common_init(&r->s)) < 0) ++ return err; ++ if ((err = rv34_decoder_alloc(r)) < 0) ++ return err; ++ } ++ return 0; ++} ++ ++int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) ++{ ++ RV34DecContext *r = dst->priv_data, *r1 = src->priv_data; ++ MpegEncContext * const s = &r->s, * const s1 = &r1->s; ++ int err; ++ ++ if (dst == src || !s1->context_initialized) ++ return 0; ++ ++ if (s->height != s1->height || s->width != s1->width) { ++ MPV_common_end(s); ++ s->height = s1->height; ++ s->width = s1->width; ++ if ((err = MPV_common_init(s)) < 0) ++ return err; ++ if ((err = rv34_decoder_realloc(r)) < 0) ++ return err; ++ } ++ ++ if ((err = ff_mpeg_update_thread_context(dst, src))) ++ return err; ++ ++ r->cur_pts = r1->cur_pts; ++ r->last_pts = r1->last_pts; ++ r->next_pts = r1->next_pts; ++ ++ memset(&r->si, 0, sizeof(r->si)); ++ ++ /* necessary since it is it the condition checked for in decode_slice ++ * to call MPV_frame_start. cmp. comment at the end of decode_frame */ ++ s->current_picture_ptr = NULL; ++ ++ return 0; ++} ++ + static int get_slice_offset(AVCodecContext *avctx, const uint8_t *buf, int n) + { + if(avctx->slice_count) return avctx->slice_offset[n]; +@@ -1427,8 +1660,8 @@ + if (buf_size == 0) { + /* special case for last picture */ + if (s->low_delay==0 && s->next_picture_ptr) { +- *pict= *(AVFrame*)s->next_picture_ptr; +- s->next_picture_ptr= NULL; ++ *pict = *(AVFrame*)s->next_picture_ptr; ++ s->next_picture_ptr = NULL; + + *data_size = sizeof(AVFrame); + } +@@ -1439,46 +1672,48 @@ + slice_count = (*buf++) + 1; + slices_hdr = buf + 4; + buf += 8 * slice_count; ++ buf_size -= 1 + 8 * slice_count; + }else + slice_count = avctx->slice_count; + + //parse first slice header to check whether this frame can be decoded +- if(get_slice_offset(avctx, slices_hdr, 0) > buf_size){ +- av_log(avctx, AV_LOG_ERROR, "Slice offset is greater than frame size\n"); ++ if(get_slice_offset(avctx, slices_hdr, 0) < 0 || ++ get_slice_offset(avctx, slices_hdr, 0) > buf_size){ ++ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); + return -1; + } +- init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), buf_size-get_slice_offset(avctx, slices_hdr, 0)); ++ init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, 0), (buf_size-get_slice_offset(avctx, slices_hdr, 0))*8); + if(r->parse_slice_header(r, &r->s.gb, &si) < 0 || si.start){ + av_log(avctx, AV_LOG_ERROR, "First slice header is incorrect\n"); + return -1; + } +- if((!s->last_picture_ptr || !s->last_picture_ptr->data[0]) && si.type == FF_B_TYPE) ++ if ((!s->last_picture_ptr || !s->last_picture_ptr->f.data[0]) && si.type == AV_PICTURE_TYPE_B) + return -1; +- /* skip b frames if we are in a hurry */ +- if(avctx->hurry_up && si.type==FF_B_TYPE) return buf_size; +- if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==FF_B_TYPE) +- || (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=FF_I_TYPE) ++ if( (avctx->skip_frame >= AVDISCARD_NONREF && si.type==AV_PICTURE_TYPE_B) ++ || (avctx->skip_frame >= AVDISCARD_NONKEY && si.type!=AV_PICTURE_TYPE_I) + || avctx->skip_frame >= AVDISCARD_ALL) +- return buf_size; +- /* skip everything if we are in a hurry>=5 */ +- if(avctx->hurry_up>=5) +- return buf_size; ++ return avpkt->size; + +- for(i=0; i buf_size){ +- av_log(avctx, AV_LOG_ERROR, "Slice offset is greater than frame size\n"); ++ if(offset < 0 || offset > buf_size){ ++ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); + break; + } + + r->si.end = s->mb_width * s->mb_height; + if(i+1 < slice_count){ ++ if (get_slice_offset(avctx, slices_hdr, i+1) < 0 || ++ get_slice_offset(avctx, slices_hdr, i+1) > buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "Slice offset is invalid\n"); ++ break; ++ } + init_get_bits(&s->gb, buf+get_slice_offset(avctx, slices_hdr, i+1), (buf_size-get_slice_offset(avctx, slices_hdr, i+1))*8); + if(r->parse_slice_header(r, &r->s.gb, &si) < 0){ + if(i+2 < slice_count) +@@ -1488,30 +1723,38 @@ + }else + r->si.end = si.start; + } ++ if (size < 0 || size > buf_size - offset) { ++ av_log(avctx, AV_LOG_ERROR, "Slice size is invalid\n"); ++ break; ++ } + last = rv34_decode_slice(r, r->si.end, buf + offset, size); + s->mb_num_left = r->s.mb_x + r->s.mb_y*r->s.mb_width - r->si.start; + if(last) + break; + } + +- if(last){ ++ if(last && s->current_picture_ptr){ + if(r->loop_filter) + r->loop_filter(r, s->mb_height - 1); + ff_er_frame_end(s); + MPV_frame_end(s); +- if (s->pict_type == FF_B_TYPE || s->low_delay) { +- *pict= *(AVFrame*)s->current_picture_ptr; ++ ++ if (HAVE_THREADS && (s->avctx->active_thread_type & FF_THREAD_FRAME)) ++ ff_thread_report_progress(&s->current_picture_ptr->f, INT_MAX, 0); ++ ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { ++ *pict = *(AVFrame*)s->current_picture_ptr; + } else if (s->last_picture_ptr != NULL) { +- *pict= *(AVFrame*)s->last_picture_ptr; ++ *pict = *(AVFrame*)s->last_picture_ptr; + } + + if(s->last_picture_ptr || s->low_delay){ + *data_size = sizeof(AVFrame); + ff_print_debug_info(s, pict); + } +- s->current_picture_ptr= NULL; //so we can detect if frame_end wasnt called (find some nicer solution...) ++ s->current_picture_ptr = NULL; //so we can detect if frame_end wasnt called (find some nicer solution...) + } +- return buf_size; ++ return avpkt->size; + } + + av_cold int ff_rv34_decode_end(AVCodecContext *avctx) +@@ -1519,13 +1762,7 @@ + RV34DecContext *r = avctx->priv_data; + + MPV_common_end(&r->s); +- +- av_freep(&r->intra_types_hist); +- r->intra_types = NULL; +- av_freep(&r->mb_type); +- av_freep(&r->cbp_luma); +- av_freep(&r->cbp_chroma); +- av_freep(&r->deblock_coefs); ++ rv34_decoder_free(r); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34data.h 2012-05-14 14:08:54.190337083 +0200 +@@ -50,34 +50,22 @@ + * A lot of four-tuples in RV40 are represented as c0*27+c1*9+c2*3+c3. + * This table allows conversion from a value back to a vector. + */ +-static const uint8_t modulo_three_table[108][4] = { +- { 0, 0, 0, 0 }, { 0, 0, 0, 1 }, { 0, 0, 0, 2 }, { 0, 0, 1, 0 }, +- { 0, 0, 1, 1 }, { 0, 0, 1, 2 }, { 0, 0, 2, 0 }, { 0, 0, 2, 1 }, +- { 0, 0, 2, 2 }, { 0, 1, 0, 0 }, { 0, 1, 0, 1 }, { 0, 1, 0, 2 }, +- { 0, 1, 1, 0 }, { 0, 1, 1, 1 }, { 0, 1, 1, 2 }, { 0, 1, 2, 0 }, +- { 0, 1, 2, 1 }, { 0, 1, 2, 2 }, { 0, 2, 0, 0 }, { 0, 2, 0, 1 }, +- { 0, 2, 0, 2 }, { 0, 2, 1, 0 }, { 0, 2, 1, 1 }, { 0, 2, 1, 2 }, +- { 0, 2, 2, 0 }, { 0, 2, 2, 1 }, { 0, 2, 2, 2 }, { 1, 0, 0, 0 }, +- { 1, 0, 0, 1 }, { 1, 0, 0, 2 }, { 1, 0, 1, 0 }, { 1, 0, 1, 1 }, +- { 1, 0, 1, 2 }, { 1, 0, 2, 0 }, { 1, 0, 2, 1 }, { 1, 0, 2, 2 }, +- { 1, 1, 0, 0 }, { 1, 1, 0, 1 }, { 1, 1, 0, 2 }, { 1, 1, 1, 0 }, +- { 1, 1, 1, 1 }, { 1, 1, 1, 2 }, { 1, 1, 2, 0 }, { 1, 1, 2, 1 }, +- { 1, 1, 2, 2 }, { 1, 2, 0, 0 }, { 1, 2, 0, 1 }, { 1, 2, 0, 2 }, +- { 1, 2, 1, 0 }, { 1, 2, 1, 1 }, { 1, 2, 1, 2 }, { 1, 2, 2, 0 }, +- { 1, 2, 2, 1 }, { 1, 2, 2, 2 }, { 2, 0, 0, 0 }, { 2, 0, 0, 1 }, +- { 2, 0, 0, 2 }, { 2, 0, 1, 0 }, { 2, 0, 1, 1 }, { 2, 0, 1, 2 }, +- { 2, 0, 2, 0 }, { 2, 0, 2, 1 }, { 2, 0, 2, 2 }, { 2, 1, 0, 0 }, +- { 2, 1, 0, 1 }, { 2, 1, 0, 2 }, { 2, 1, 1, 0 }, { 2, 1, 1, 1 }, +- { 2, 1, 1, 2 }, { 2, 1, 2, 0 }, { 2, 1, 2, 1 }, { 2, 1, 2, 2 }, +- { 2, 2, 0, 0 }, { 2, 2, 0, 1 }, { 2, 2, 0, 2 }, { 2, 2, 1, 0 }, +- { 2, 2, 1, 1 }, { 2, 2, 1, 2 }, { 2, 2, 2, 0 }, { 2, 2, 2, 1 }, +- { 2, 2, 2, 2 }, { 3, 0, 0, 0 }, { 3, 0, 0, 1 }, { 3, 0, 0, 2 }, +- { 3, 0, 1, 0 }, { 3, 0, 1, 1 }, { 3, 0, 1, 2 }, { 3, 0, 2, 0 }, +- { 3, 0, 2, 1 }, { 3, 0, 2, 2 }, { 3, 1, 0, 0 }, { 3, 1, 0, 1 }, +- { 3, 1, 0, 2 }, { 3, 1, 1, 0 }, { 3, 1, 1, 1 }, { 3, 1, 1, 2 }, +- { 3, 1, 2, 0 }, { 3, 1, 2, 1 }, { 3, 1, 2, 2 }, { 3, 2, 0, 0 }, +- { 3, 2, 0, 1 }, { 3, 2, 0, 2 }, { 3, 2, 1, 0 }, { 3, 2, 1, 1 }, +- { 3, 2, 1, 2 }, { 3, 2, 2, 0 }, { 3, 2, 2, 1 }, { 3, 2, 2, 2 }, ++static const uint8_t modulo_three_table[108] = { ++ 0x00, 0x01, 0x02, 0x04, 0x05, 0x06, 0x08, 0x09, 0x0A, ++ 0x10, 0x11, 0x12, 0x14, 0x15, 0x16, 0x18, 0x19, 0x1A, ++ 0x20, 0x21, 0x22, 0x24, 0x25, 0x26, 0x28, 0x29, 0x2A, ++ ++ 0x40, 0x41, 0x42, 0x44, 0x45, 0x46, 0x48, 0x49, 0x4A, ++ 0x50, 0x51, 0x52, 0x54, 0x55, 0x56, 0x58, 0x59, 0x5A, ++ 0x60, 0x61, 0x62, 0x64, 0x65, 0x66, 0x68, 0x69, 0x6A, ++ ++ 0x80, 0x81, 0x82, 0x84, 0x85, 0x86, 0x88, 0x89, 0x8A, ++ 0x90, 0x91, 0x92, 0x94, 0x95, 0x96, 0x98, 0x99, 0x9A, ++ 0xA0, 0xA1, 0xA2, 0xA4, 0xA5, 0xA6, 0xA8, 0xA9, 0xAA, ++ ++ 0xC0, 0xC1, 0xC2, 0xC4, 0xC5, 0xC6, 0xC8, 0xC9, 0xCA, ++ 0xD0, 0xD1, 0xD2, 0xD4, 0xD5, 0xD6, 0xD8, 0xD9, 0xDA, ++ 0xE0, 0xE1, 0xE2, 0xE4, 0xE5, 0xE6, 0xE8, 0xE9, 0xEA, + }; + + /** +@@ -101,16 +89,6 @@ + }; + + /** +- * 4x4 dezigzag pattern +- */ +-static const uint8_t rv34_dezigzag[16] = { +- 0, 1, 8, 16, +- 9, 2, 3, 10, +- 17, 24, 25, 18, +- 11, 19, 26, 27 +-}; +- +-/** + * tables used to translate a quantizer value into a VLC set for decoding + * The first table is used for intraframes. + */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34dsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34dsp.c 2012-05-14 14:08:54.191337103 +0200 +@@ -0,0 +1,141 @@ ++/* ++ * RV30/40 decoder common dsp functions ++ * Copyright (c) 2007 Mike Melanson, Konstantin Shishkov ++ * Copyright (c) 2011 Janne Grunau ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * RV30/40 decoder common dsp functions ++ */ ++#include "dsputil.h" ++#include "rv34dsp.h" ++ ++/** ++ * @name RV30/40 inverse transform functions ++ * @{ ++ */ ++ ++static av_always_inline void rv34_row_transform(int temp[16], DCTELEM *block) ++{ ++ int i; ++ ++ for(i = 0; i < 4; i++){ ++ const int z0 = 13*(block[i+4*0] + block[i+4*2]); ++ const int z1 = 13*(block[i+4*0] - block[i+4*2]); ++ const int z2 = 7* block[i+4*1] - 17*block[i+4*3]; ++ const int z3 = 17* block[i+4*1] + 7*block[i+4*3]; ++ ++ temp[4*i+0] = z0 + z3; ++ temp[4*i+1] = z1 + z2; ++ temp[4*i+2] = z1 - z2; ++ temp[4*i+3] = z0 - z3; ++ } ++} ++ ++/** ++ * Real Video 3.0/4.0 inverse transform + sample reconstruction ++ * Code is almost the same as in SVQ3, only scaling is different. ++ */ ++static void rv34_idct_add_c(uint8_t *dst, int stride, DCTELEM *block){ ++ int temp[16]; ++ int i; ++ ++ rv34_row_transform(temp, block); ++ memset(block, 0, 16*sizeof(DCTELEM)); ++ ++ for(i = 0; i < 4; i++){ ++ const int z0 = 13*(temp[4*0+i] + temp[4*2+i]) + 0x200; ++ const int z1 = 13*(temp[4*0+i] - temp[4*2+i]) + 0x200; ++ const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i]; ++ const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i]; ++ ++ dst[0] = av_clip_uint8( dst[0] + ( (z0 + z3) >> 10 ) ); ++ dst[1] = av_clip_uint8( dst[1] + ( (z1 + z2) >> 10 ) ); ++ dst[2] = av_clip_uint8( dst[2] + ( (z1 - z2) >> 10 ) ); ++ dst[3] = av_clip_uint8( dst[3] + ( (z0 - z3) >> 10 ) ); ++ ++ dst += stride; ++ } ++} ++ ++/** ++ * RealVideo 3.0/4.0 inverse transform for DC block ++ * ++ * Code is almost the same as rv34_inv_transform() ++ * but final coefficients are multiplied by 1.5 and have no rounding. ++ */ ++static void rv34_inv_transform_noround_c(DCTELEM *block){ ++ int temp[16]; ++ int i; ++ ++ rv34_row_transform(temp, block); ++ ++ for(i = 0; i < 4; i++){ ++ const int z0 = 13*(temp[4*0+i] + temp[4*2+i]); ++ const int z1 = 13*(temp[4*0+i] - temp[4*2+i]); ++ const int z2 = 7* temp[4*1+i] - 17*temp[4*3+i]; ++ const int z3 = 17* temp[4*1+i] + 7*temp[4*3+i]; ++ ++ block[i*4+0] = ((z0 + z3) * 3) >> 11; ++ block[i*4+1] = ((z1 + z2) * 3) >> 11; ++ block[i*4+2] = ((z1 - z2) * 3) >> 11; ++ block[i*4+3] = ((z0 - z3) * 3) >> 11; ++ } ++} ++ ++static void rv34_idct_dc_add_c(uint8_t *dst, int stride, int dc) ++{ ++ int i, j; ++ ++ dc = (13*13*dc + 0x200) >> 10; ++ for (i = 0; i < 4; i++) ++ { ++ for (j = 0; j < 4; j++) ++ dst[j] = av_clip_uint8( dst[j] + dc ); ++ ++ dst += stride; ++ } ++} ++ ++static void rv34_inv_transform_dc_noround_c(DCTELEM *block) ++{ ++ DCTELEM dc = (13 * 13 * 3 * block[0]) >> 11; ++ int i, j; ++ ++ for (i = 0; i < 4; i++, block += 4) ++ for (j = 0; j < 4; j++) ++ block[j] = dc; ++} ++ ++/** @} */ // transform ++ ++ ++av_cold void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp) { ++ c->rv34_inv_transform = rv34_inv_transform_noround_c; ++ c->rv34_inv_transform_dc = rv34_inv_transform_dc_noround_c; ++ ++ c->rv34_idct_add = rv34_idct_add_c; ++ c->rv34_idct_dc_add = rv34_idct_dc_add_c; ++ ++ if (HAVE_NEON) ++ ff_rv34dsp_init_neon(c, dsp); ++ if (HAVE_MMX) ++ ff_rv34dsp_init_x86(c, dsp); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34dsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34dsp.h 2012-05-14 14:08:54.192337124 +0200 +@@ -0,0 +1,81 @@ ++/* ++ * RV30/40 decoder motion compensation functions ++ * Copyright (c) 2008 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * RV30/40 decoder motion compensation functions ++ */ ++ ++#ifndef AVCODEC_RV34DSP_H ++#define AVCODEC_RV34DSP_H ++ ++#include "dsputil.h" ++ ++typedef void (*rv40_weight_func)(uint8_t *dst/*align width (8 or 16)*/, ++ uint8_t *src1/*align width (8 or 16)*/, ++ uint8_t *src2/*align width (8 or 16)*/, ++ int w1, int w2, int stride); ++ ++typedef void (*rv34_inv_transform_func)(DCTELEM *block); ++ ++typedef void (*rv34_idct_add_func)(uint8_t *dst, int stride, DCTELEM *block); ++typedef void (*rv34_idct_dc_add_func)(uint8_t *dst, int stride, ++ int dc); ++ ++typedef void (*rv40_weak_loop_filter_func)(uint8_t *src, int stride, ++ int filter_p1, int filter_q1, ++ int alpha, int beta, ++ int lims, int lim_q1, int lim_p1); ++ ++typedef void (*rv40_strong_loop_filter_func)(uint8_t *src, int stride, ++ int alpha, int lims, ++ int dmode, int chroma); ++ ++typedef int (*rv40_loop_filter_strength_func)(uint8_t *src, int stride, ++ int beta, int beta2, int edge, ++ int *p1, int *q1); ++ ++typedef struct RV34DSPContext { ++ qpel_mc_func put_pixels_tab[4][16]; ++ qpel_mc_func avg_pixels_tab[4][16]; ++ h264_chroma_mc_func put_chroma_pixels_tab[3]; ++ h264_chroma_mc_func avg_chroma_pixels_tab[3]; ++ rv40_weight_func rv40_weight_pixels_tab[2]; ++ rv34_inv_transform_func rv34_inv_transform; ++ rv34_inv_transform_func rv34_inv_transform_dc; ++ rv34_idct_add_func rv34_idct_add; ++ rv34_idct_dc_add_func rv34_idct_dc_add; ++ rv40_weak_loop_filter_func rv40_weak_loop_filter[2]; ++ rv40_strong_loop_filter_func rv40_strong_loop_filter[2]; ++ rv40_loop_filter_strength_func rv40_loop_filter_strength[2]; ++} RV34DSPContext; ++ ++void ff_rv30dsp_init(RV34DSPContext *c, DSPContext* dsp); ++void ff_rv34dsp_init(RV34DSPContext *c, DSPContext* dsp); ++void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp); ++ ++void ff_rv34dsp_init_neon(RV34DSPContext *c, DSPContext *dsp); ++void ff_rv34dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); ++ ++void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp); ++void ff_rv40dsp_init_neon(RV34DSPContext *c, DSPContext *dsp); ++ ++#endif /* AVCODEC_RV34DSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34.h 2012-05-14 14:08:54.189337063 +0200 +@@ -32,6 +32,7 @@ + #include "mpegvideo.h" + + #include "h264pred.h" ++#include "rv34dsp.h" + + #define MB_TYPE_SEPARATE_DC 0x01000000 + #define IS_SEPARATE_DC(a) ((a) & MB_TYPE_SEPARATE_DC) +@@ -83,6 +84,7 @@ + /** decoder context */ + typedef struct RV34DecContext{ + MpegEncContext s; ++ RV34DSPContext rdsp; + int8_t *intra_types_hist;///< old block types, used for prediction + int8_t *intra_types; ///< block types + int intra_types_stride;///< block types array stride +@@ -90,7 +92,6 @@ + const uint8_t *luma_dc_quant_p;///< luma subblock DC quantizer for interframes + + RV34VLC *cur_vlcs; ///< VLC set used for current frame decoding +- int bits; ///< slice size in bits + H264PredContext h; ///< functions for 4x4 and 16x16 intra block prediction + SliceInfo si; ///< current slice information + +@@ -105,6 +106,7 @@ + int rpr; ///< one field size in RV30 slice header + + int cur_pts, last_pts, next_pts; ++ int weight1, weight2; ///< B frame distance fractions (0.14) used in motion compensation + + uint16_t *cbp_luma; ///< CBP values for luma subblocks + uint8_t *cbp_chroma; ///< CBP values for chroma subblocks +@@ -113,6 +115,11 @@ + /** 8x8 block available flags (for MV prediction) */ + DECLARE_ALIGNED(8, uint32_t, avail_cache)[3*4]; + ++ /** temporary blocks for RV4 weighted MC */ ++ uint8_t *tmp_b_block_y[2]; ++ uint8_t *tmp_b_block_uv[4]; ++ uint8_t *tmp_b_block_base; ++ + int (*parse_slice_header)(struct RV34DecContext *r, GetBitContext *gb, SliceInfo *si); + int (*decode_mb_info)(struct RV34DecContext *r); + int (*decode_intra_types)(struct RV34DecContext *r, GetBitContext *gb, int8_t *dst); +@@ -126,5 +133,7 @@ + int ff_rv34_decode_init(AVCodecContext *avctx); + int ff_rv34_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt); + int ff_rv34_decode_end(AVCodecContext *avctx); ++int ff_rv34_decode_init_thread_copy(AVCodecContext *avctx); ++int ff_rv34_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src); + + #endif /* AVCODEC_RV34_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv34_parser.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv34_parser.c 2012-05-14 14:08:54.189337063 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * RV30/40 parser ++ * Copyright (c) 2011 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * RV30/40 parser ++ */ ++ ++#include "parser.h" ++#include "libavutil/intreadwrite.h" ++ ++typedef struct { ++ ParseContext pc; ++ int64_t key_dts; ++ int key_pts; ++} RV34ParseContext; ++ ++static const int rv_to_av_frame_type[4] = { ++ AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_I, AV_PICTURE_TYPE_P, AV_PICTURE_TYPE_B, ++}; ++ ++static int rv34_parse(AVCodecParserContext *s, ++ AVCodecContext *avctx, ++ const uint8_t **poutbuf, int *poutbuf_size, ++ const uint8_t *buf, int buf_size) ++{ ++ RV34ParseContext *pc = s->priv_data; ++ int type, pts, hdr; ++ ++ if (buf_size < 13 + *buf * 8) { ++ *poutbuf = buf; ++ *poutbuf_size = buf_size; ++ return buf_size; ++ } ++ ++ hdr = AV_RB32(buf + 9 + *buf * 8); ++ if (avctx->codec_id == CODEC_ID_RV30) { ++ type = (hdr >> 27) & 3; ++ pts = (hdr >> 7) & 0x1FFF; ++ } else { ++ type = (hdr >> 29) & 3; ++ pts = (hdr >> 6) & 0x1FFF; ++ } ++ ++ if (type != 3 && s->pts != AV_NOPTS_VALUE) { ++ pc->key_dts = s->pts; ++ pc->key_pts = pts; ++ } else { ++ if (type != 3) ++ s->pts = pc->key_dts + ((pts - pc->key_pts) & 0x1FFF); ++ else ++ s->pts = pc->key_dts - ((pc->key_pts - pts) & 0x1FFF); ++ } ++ s->pict_type = rv_to_av_frame_type[type]; ++ ++ *poutbuf = buf; ++ *poutbuf_size = buf_size; ++ return buf_size; ++} ++ ++#if CONFIG_RV30_PARSER ++AVCodecParser ff_rv30_parser = { ++ .codec_ids = { CODEC_ID_RV30 }, ++ .priv_data_size = sizeof(RV34ParseContext), ++ .parser_parse = rv34_parse, ++}; ++#endif ++ ++#if CONFIG_RV40_PARSER ++AVCodecParser ff_rv40_parser = { ++ .codec_ids = { CODEC_ID_RV40 }, ++ .priv_data_size = sizeof(RV34ParseContext), ++ .parser_parse = rv34_parse, ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40.c 2012-05-14 14:08:54.194337164 +0200 +@@ -24,7 +24,7 @@ + * RV40 decoder + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + #include "avcodec.h" + #include "dsputil.h" +@@ -231,8 +231,11 @@ + int blocks[RV34_MB_TYPES] = {0}; + int count = 0; + +- if(!r->s.mb_skip_run) ++ if(!r->s.mb_skip_run) { + r->s.mb_skip_run = svq3_get_ue_golomb(gb) + 1; ++ if(r->s.mb_skip_run > (unsigned)s->mb_num) ++ return -1; ++ } + + if(--r->s.mb_skip_run) + return RV34_MB_SKIP; +@@ -253,7 +256,7 @@ + prev_type = i; + } + } +- if(s->pict_type == FF_P_TYPE){ ++ if(s->pict_type == AV_PICTURE_TYPE_P){ + prev_type = block_num_to_ptype_vlc_num[prev_type]; + q = get_vlc2(gb, ptype_vlc[prev_type].table, PTYPE_VLC_BITS, 1); + if(q < PBTYPE_ESCAPE) +@@ -271,148 +274,6 @@ + return 0; + } + +-#define CLIP_SYMM(a, b) av_clip(a, -(b), b) +-/** +- * weaker deblocking very similar to the one described in 4.4.2 of JVT-A003r1 +- */ +-static inline void rv40_weak_loop_filter(uint8_t *src, const int step, +- const int filter_p1, const int filter_q1, +- const int alpha, const int beta, +- const int lim_p0q0, +- const int lim_q1, const int lim_p1, +- const int diff_p1p0, const int diff_q1q0, +- const int diff_p1p2, const int diff_q1q2) +-{ +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- int t, u, diff; +- +- t = src[0*step] - src[-1*step]; +- if(!t) +- return; +- u = (alpha * FFABS(t)) >> 7; +- if(u > 3 - (filter_p1 && filter_q1)) +- return; +- +- t <<= 2; +- if(filter_p1 && filter_q1) +- t += src[-2*step] - src[1*step]; +- diff = CLIP_SYMM((t + 4) >> 3, lim_p0q0); +- src[-1*step] = cm[src[-1*step] + diff]; +- src[ 0*step] = cm[src[ 0*step] - diff]; +- if(FFABS(diff_p1p2) <= beta && filter_p1){ +- t = (diff_p1p0 + diff_p1p2 - diff) >> 1; +- src[-2*step] = cm[src[-2*step] - CLIP_SYMM(t, lim_p1)]; +- } +- if(FFABS(diff_q1q2) <= beta && filter_q1){ +- t = (diff_q1q0 + diff_q1q2 + diff) >> 1; +- src[ 1*step] = cm[src[ 1*step] - CLIP_SYMM(t, lim_q1)]; +- } +-} +- +-static av_always_inline void rv40_adaptive_loop_filter(uint8_t *src, const int step, +- const int stride, const int dmode, +- const int lim_q1, const int lim_p1, +- const int alpha, +- const int beta, const int beta2, +- const int chroma, const int edge) +-{ +- int diff_p1p0[4], diff_q1q0[4], diff_p1p2[4], diff_q1q2[4]; +- int sum_p1p0 = 0, sum_q1q0 = 0, sum_p1p2 = 0, sum_q1q2 = 0; +- uint8_t *ptr; +- int flag_strong0 = 1, flag_strong1 = 1; +- int filter_p1, filter_q1; +- int i; +- int lims; +- +- for(i = 0, ptr = src; i < 4; i++, ptr += stride){ +- diff_p1p0[i] = ptr[-2*step] - ptr[-1*step]; +- diff_q1q0[i] = ptr[ 1*step] - ptr[ 0*step]; +- sum_p1p0 += diff_p1p0[i]; +- sum_q1q0 += diff_q1q0[i]; +- } +- filter_p1 = FFABS(sum_p1p0) < (beta<<2); +- filter_q1 = FFABS(sum_q1q0) < (beta<<2); +- if(!filter_p1 && !filter_q1) +- return; +- +- for(i = 0, ptr = src; i < 4; i++, ptr += stride){ +- diff_p1p2[i] = ptr[-2*step] - ptr[-3*step]; +- diff_q1q2[i] = ptr[ 1*step] - ptr[ 2*step]; +- sum_p1p2 += diff_p1p2[i]; +- sum_q1q2 += diff_q1q2[i]; +- } +- +- if(edge){ +- flag_strong0 = filter_p1 && (FFABS(sum_p1p2) < beta2); +- flag_strong1 = filter_q1 && (FFABS(sum_q1q2) < beta2); +- }else{ +- flag_strong0 = flag_strong1 = 0; +- } +- +- lims = filter_p1 + filter_q1 + ((lim_q1 + lim_p1) >> 1) + 1; +- if(flag_strong0 && flag_strong1){ /* strong filtering */ +- for(i = 0; i < 4; i++, src += stride){ +- int sflag, p0, q0, p1, q1; +- int t = src[0*step] - src[-1*step]; +- +- if(!t) continue; +- sflag = (alpha * FFABS(t)) >> 7; +- if(sflag > 1) continue; +- +- p0 = (25*src[-3*step] + 26*src[-2*step] +- + 26*src[-1*step] +- + 26*src[ 0*step] + 25*src[ 1*step] + rv40_dither_l[dmode + i]) >> 7; +- q0 = (25*src[-2*step] + 26*src[-1*step] +- + 26*src[ 0*step] +- + 26*src[ 1*step] + 25*src[ 2*step] + rv40_dither_r[dmode + i]) >> 7; +- if(sflag){ +- p0 = av_clip(p0, src[-1*step] - lims, src[-1*step] + lims); +- q0 = av_clip(q0, src[ 0*step] - lims, src[ 0*step] + lims); +- } +- p1 = (25*src[-4*step] + 26*src[-3*step] +- + 26*src[-2*step] +- + 26*p0 + 25*src[ 0*step] + rv40_dither_l[dmode + i]) >> 7; +- q1 = (25*src[-1*step] + 26*q0 +- + 26*src[ 1*step] +- + 26*src[ 2*step] + 25*src[ 3*step] + rv40_dither_r[dmode + i]) >> 7; +- if(sflag){ +- p1 = av_clip(p1, src[-2*step] - lims, src[-2*step] + lims); +- q1 = av_clip(q1, src[ 1*step] - lims, src[ 1*step] + lims); +- } +- src[-2*step] = p1; +- src[-1*step] = p0; +- src[ 0*step] = q0; +- src[ 1*step] = q1; +- if(!chroma){ +- src[-3*step] = (25*src[-1*step] + 26*src[-2*step] + 51*src[-3*step] + 26*src[-4*step] + 64) >> 7; +- src[ 2*step] = (25*src[ 0*step] + 26*src[ 1*step] + 51*src[ 2*step] + 26*src[ 3*step] + 64) >> 7; +- } +- } +- }else if(filter_p1 && filter_q1){ +- for(i = 0; i < 4; i++, src += stride) +- rv40_weak_loop_filter(src, step, 1, 1, alpha, beta, lims, lim_q1, lim_p1, +- diff_p1p0[i], diff_q1q0[i], diff_p1p2[i], diff_q1q2[i]); +- }else{ +- for(i = 0; i < 4; i++, src += stride) +- rv40_weak_loop_filter(src, step, filter_p1, filter_q1, +- alpha, beta, lims>>1, lim_q1>>1, lim_p1>>1, +- diff_p1p0[i], diff_q1q0[i], diff_p1p2[i], diff_q1q2[i]); +- } +-} +- +-static void rv40_v_loop_filter(uint8_t *src, int stride, int dmode, +- int lim_q1, int lim_p1, +- int alpha, int beta, int beta2, int chroma, int edge){ +- rv40_adaptive_loop_filter(src, 1, stride, dmode, lim_q1, lim_p1, +- alpha, beta, beta2, chroma, edge); +-} +-static void rv40_h_loop_filter(uint8_t *src, int stride, int dmode, +- int lim_q1, int lim_p1, +- int alpha, int beta, int beta2, int chroma, int edge){ +- rv40_adaptive_loop_filter(src, stride, 1, dmode, lim_q1, lim_p1, +- alpha, beta, beta2, chroma, edge); +-} +- + enum RV40BlockPos{ + POS_CUR, + POS_TOP, +@@ -436,6 +297,34 @@ + static const int neighbour_offs_x[4] = { 0, 0, -1, 0 }; + static const int neighbour_offs_y[4] = { 0, -1, 0, 1 }; + ++static void rv40_adaptive_loop_filter(RV34DSPContext *rdsp, ++ uint8_t *src, int stride, int dmode, ++ int lim_q1, int lim_p1, ++ int alpha, int beta, int beta2, ++ int chroma, int edge, int dir) ++{ ++ int filter_p1, filter_q1; ++ int strong; ++ int lims; ++ ++ strong = rdsp->rv40_loop_filter_strength[dir](src, stride, beta, beta2, ++ edge, &filter_p1, &filter_q1); ++ ++ lims = filter_p1 + filter_q1 + ((lim_q1 + lim_p1) >> 1) + 1; ++ ++ if (strong) { ++ rdsp->rv40_strong_loop_filter[dir](src, stride, alpha, ++ lims, dmode, chroma); ++ } else if (filter_p1 & filter_q1) { ++ rdsp->rv40_weak_loop_filter[dir](src, stride, 1, 1, alpha, beta, ++ lims, lim_q1, lim_p1); ++ } else if (filter_p1 | filter_q1) { ++ rdsp->rv40_weak_loop_filter[dir](src, stride, filter_p1, filter_q1, ++ alpha, beta, lims >> 1, lim_q1 >> 1, ++ lim_p1 >> 1); ++ } ++} ++ + /** + * RV40 loop filtering function + */ +@@ -475,7 +364,7 @@ + + mb_pos = row * s->mb_stride; + for(mb_x = 0; mb_x < s->mb_width; mb_x++, mb_pos++){ +- int mbtype = s->current_picture_ptr->mb_type[mb_pos]; ++ int mbtype = s->current_picture_ptr->f.mb_type[mb_pos]; + if(IS_INTRA(mbtype) || IS_SEPARATE_DC(mbtype)) + r->cbp_luma [mb_pos] = r->deblock_coefs[mb_pos] = 0xFFFF; + if(IS_INTRA(mbtype)) +@@ -489,7 +378,7 @@ + int avail[4]; + int y_to_deblock, c_to_deblock[2]; + +- q = s->current_picture_ptr->qscale_table[mb_pos]; ++ q = s->current_picture_ptr->f.qscale_table[mb_pos]; + alpha = rv40_alpha_tab[q]; + beta = rv40_beta_tab [q]; + betaY = betaC = beta * 3; +@@ -504,7 +393,7 @@ + if(avail[i]){ + int pos = mb_pos + neighbour_offs_x[i] + neighbour_offs_y[i]*s->mb_stride; + mvmasks[i] = r->deblock_coefs[pos]; +- mbtype [i] = s->current_picture_ptr->mb_type[pos]; ++ mbtype [i] = s->current_picture_ptr->f.mb_type[pos]; + cbp [i] = r->cbp_luma[pos]; + uvcbp[i][0] = r->cbp_chroma[pos] & 0xF; + uvcbp[i][1] = r->cbp_chroma[pos] >> 4; +@@ -563,7 +452,7 @@ + } + + for(j = 0; j < 16; j += 4){ +- Y = s->current_picture_ptr->data[0] + mb_x*16 + (row*16 + j) * s->linesize; ++ Y = s->current_picture_ptr->f.data[0] + mb_x*16 + (row*16 + j) * s->linesize; + for(i = 0; i < 4; i++, Y += 4){ + int ij = i + j; + int clip_cur = y_to_deblock & (MASK_CUR << ij) ? clip[POS_CUR] : 0; +@@ -572,10 +461,11 @@ + // if bottom block is coded then we can filter its top edge + // (or bottom edge of this block, which is the same) + if(y_h_deblock & (MASK_BOTTOM << ij)){ +- rv40_h_loop_filter(Y+4*s->linesize, s->linesize, dither, +- y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, +- clip_cur, +- alpha, beta, betaY, 0, 0); ++ rv40_adaptive_loop_filter(&r->rdsp, Y+4*s->linesize, ++ s->linesize, dither, ++ y_to_deblock & (MASK_BOTTOM << ij) ? clip[POS_CUR] : 0, ++ clip_cur, alpha, beta, betaY, ++ 0, 0, 0); + } + // filter left block edge in ordinary mode (with low filtering strength) + if(y_v_deblock & (MASK_CUR << ij) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ +@@ -583,64 +473,64 @@ + clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; + else + clip_left = y_to_deblock & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; +- rv40_v_loop_filter(Y, s->linesize, dither, +- clip_cur, +- clip_left, +- alpha, beta, betaY, 0, 0); ++ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, ++ clip_cur, ++ clip_left, ++ alpha, beta, betaY, 0, 0, 1); + } + // filter top edge of the current macroblock when filtering strength is high + if(!j && y_h_deblock & (MASK_CUR << i) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ +- rv40_h_loop_filter(Y, s->linesize, dither, ++ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, + clip_cur, + mvmasks[POS_TOP] & (MASK_TOP << i) ? clip[POS_TOP] : 0, +- alpha, beta, betaY, 0, 1); ++ alpha, beta, betaY, 0, 1, 0); + } + // filter left block edge in edge mode (with high filtering strength) + if(y_v_deblock & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ + clip_left = mvmasks[POS_LEFT] & (MASK_RIGHT << j) ? clip[POS_LEFT] : 0; +- rv40_v_loop_filter(Y, s->linesize, dither, ++ rv40_adaptive_loop_filter(&r->rdsp, Y, s->linesize, dither, + clip_cur, + clip_left, +- alpha, beta, betaY, 0, 1); ++ alpha, beta, betaY, 0, 1, 1); + } + } + } + for(k = 0; k < 2; k++){ + for(j = 0; j < 2; j++){ +- C = s->current_picture_ptr->data[k+1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; ++ C = s->current_picture_ptr->f.data[k + 1] + mb_x*8 + (row*8 + j*4) * s->uvlinesize; + for(i = 0; i < 2; i++, C += 4){ + int ij = i + j*2; + int clip_cur = c_to_deblock[k] & (MASK_CUR << ij) ? clip[POS_CUR] : 0; + if(c_h_deblock[k] & (MASK_CUR << (ij+2))){ + int clip_bot = c_to_deblock[k] & (MASK_CUR << (ij+2)) ? clip[POS_CUR] : 0; +- rv40_h_loop_filter(C+4*s->uvlinesize, s->uvlinesize, i*8, ++ rv40_adaptive_loop_filter(&r->rdsp, C+4*s->uvlinesize, s->uvlinesize, i*8, + clip_bot, + clip_cur, +- alpha, beta, betaC, 1, 0); ++ alpha, beta, betaC, 1, 0, 0); + } + if((c_v_deblock[k] & (MASK_CUR << ij)) && (i || !(mb_strong[POS_CUR] || mb_strong[POS_LEFT]))){ + if(!i) + clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; + else + clip_left = c_to_deblock[k] & (MASK_CUR << (ij-1)) ? clip[POS_CUR] : 0; +- rv40_v_loop_filter(C, s->uvlinesize, j*8, ++ rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, + clip_cur, + clip_left, +- alpha, beta, betaC, 1, 0); ++ alpha, beta, betaC, 1, 0, 1); + } + if(!j && c_h_deblock[k] & (MASK_CUR << ij) && (mb_strong[POS_CUR] || mb_strong[POS_TOP])){ + int clip_top = uvcbp[POS_TOP][k] & (MASK_CUR << (ij+2)) ? clip[POS_TOP] : 0; +- rv40_h_loop_filter(C, s->uvlinesize, i*8, ++ rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, i*8, + clip_cur, + clip_top, +- alpha, beta, betaC, 1, 1); ++ alpha, beta, betaC, 1, 1, 0); + } + if(c_v_deblock[k] & (MASK_CUR << ij) && !i && (mb_strong[POS_CUR] || mb_strong[POS_LEFT])){ + clip_left = uvcbp[POS_LEFT][k] & (MASK_CUR << (2*j+1)) ? clip[POS_LEFT] : 0; +- rv40_v_loop_filter(C, s->uvlinesize, j*8, ++ rv40_adaptive_loop_filter(&r->rdsp, C, s->uvlinesize, j*8, + clip_cur, + clip_left, +- alpha, beta, betaC, 1, 1); ++ alpha, beta, betaC, 1, 1, 1); + } + } + } +@@ -669,16 +559,17 @@ + } + + AVCodec ff_rv40_decoder = { +- "rv40", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_RV40, +- sizeof(RV34DecContext), +- rv40_decode_init, +- NULL, +- ff_rv34_decode_end, +- ff_rv34_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, +- .flush = ff_mpeg_flush, +- .long_name = NULL_IF_CONFIG_SMALL("RealVideo 4.0"), +- .pix_fmts= ff_pixfmt_list_420, ++ .name = "rv40", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_RV40, ++ .priv_data_size = sizeof(RV34DecContext), ++ .init = rv40_decode_init, ++ .close = ff_rv34_decode_end, ++ .decode = ff_rv34_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS, ++ .flush = ff_mpeg_flush, ++ .long_name = NULL_IF_CONFIG_SMALL("RealVideo 4.0"), ++ .pix_fmts = ff_pixfmt_list_420, ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(ff_rv34_decode_update_thread_context), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40data.h 2012-05-14 14:08:54.194337164 +0200 +@@ -65,23 +65,9 @@ + }; + + /** +- * @defgroup loopfilter coefficients used by the RV40 loop filter ++ * @name Coefficients used by the RV40 loop filter + * @{ + */ +-/** +- * dither values for deblocking filter - left/top values +- */ +-static const uint8_t rv40_dither_l[16] = { +- 0x40, 0x50, 0x20, 0x60, 0x30, 0x50, 0x40, 0x30, +- 0x50, 0x40, 0x50, 0x30, 0x60, 0x20, 0x50, 0x40 +-}; +-/** +- * dither values for deblocking filter - right/bottom values +- */ +-static const uint8_t rv40_dither_r[16] = { +- 0x40, 0x30, 0x60, 0x20, 0x50, 0x30, 0x30, 0x40, +- 0x40, 0x40, 0x50, 0x30, 0x20, 0x60, 0x30, 0x40 +-}; + + /** alpha parameter for RV40 loop filter - almost the same as in JVT-A003r1 */ + static const uint8_t rv40_alpha_tab[32] = { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/rv40dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/rv40dsp.c 2012-05-14 14:08:54.197337224 +0200 +@@ -26,13 +26,14 @@ + + #include "avcodec.h" + #include "dsputil.h" ++#include "rv34dsp.h" + + #define RV40_LOWPASS(OPNAME, OP) \ + static av_unused void OPNAME ## rv40_qpel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,\ + const int h, const int C1, const int C2, const int SHIFT){\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + int i;\ +- for(i=0; i> SHIFT);\ + OP(dst[1], (src[-1] + src[ 4] - 5*(src[ 0]+src[3]) + src[1]*C1 + src[2]*C2 + (1<<(SHIFT-1))) >> SHIFT);\ +@@ -42,8 +43,8 @@ + OP(dst[5], (src[ 3] + src[ 8] - 5*(src[ 4]+src[7]) + src[5]*C1 + src[6]*C2 + (1<<(SHIFT-1))) >> SHIFT);\ + OP(dst[6], (src[ 4] + src[ 9] - 5*(src[ 5]+src[8]) + src[6]*C1 + src[7]*C2 + (1<<(SHIFT-1))) >> SHIFT);\ + OP(dst[7], (src[ 5] + src[10] - 5*(src[ 6]+src[9]) + src[7]*C1 + src[8]*C2 + (1<<(SHIFT-1))) >> SHIFT);\ +- dst+=dstStride;\ +- src+=srcStride;\ ++ dst += dstStride;\ ++ src += srcStride;\ + }\ + }\ + \ +@@ -51,21 +52,21 @@ + const int w, const int C1, const int C2, const int SHIFT){\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ + int i;\ +- for(i=0; i> SHIFT);\ + OP(dst[1*dstStride], (srcA + src4 - 5*(src0+src3) + src1*C1 + src2*C2 + (1<<(SHIFT-1))) >> SHIFT);\ + OP(dst[2*dstStride], (src0 + src5 - 5*(src1+src4) + src2*C1 + src3*C2 + (1<<(SHIFT-1))) >> SHIFT);\ +@@ -105,10 +106,6 @@ + OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 52, 20, 6);\ + }\ + \ +-static void OPNAME ## rv40_qpel ## SIZE ## _mc20_c(uint8_t *dst, uint8_t *src, int stride){\ +- OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 20, 20, 5);\ +-}\ +-\ + static void OPNAME ## rv40_qpel ## SIZE ## _mc30_c(uint8_t *dst, uint8_t *src, int stride){\ + OPNAME ## rv40_qpel ## SIZE ## _h_lowpass(dst, src, stride, stride, SIZE, 20, 52, 6);\ + }\ +@@ -119,46 +116,42 @@ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc11_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\ + }\ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc21_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\ + }\ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc31_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 52, 6);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 52, 20, 6);\ + }\ + \ +-static void OPNAME ## rv40_qpel ## SIZE ## _mc02_c(uint8_t *dst, uint8_t *src, int stride){\ +- OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, src, stride, stride, SIZE, 20, 20, 5);\ +-}\ +-\ + static void OPNAME ## rv40_qpel ## SIZE ## _mc12_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\ + }\ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc22_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\ + }\ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc32_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 52, 6);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 20, 5);\ + }\ +@@ -169,14 +162,14 @@ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc13_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 52, 20, 6);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 52, 6);\ + }\ + \ + static void OPNAME ## rv40_qpel ## SIZE ## _mc23_c(uint8_t *dst, uint8_t *src, int stride){\ + uint8_t full[SIZE*(SIZE+5)];\ +- uint8_t * const full_mid= full + SIZE*2;\ ++ uint8_t * const full_mid = full + SIZE*2;\ + put_rv40_qpel ## SIZE ## _h_lowpass(full, src - 2*stride, SIZE, stride, SIZE+5, 20, 20, 5);\ + OPNAME ## rv40_qpel ## SIZE ## _v_lowpass(dst, full_mid, stride, SIZE, SIZE, 20, 52, 6);\ + }\ +@@ -205,50 +198,50 @@ + + #define RV40_CHROMA_MC(OPNAME, OP)\ + static void OPNAME ## rv40_chroma_mc4_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){\ +- const int A=(8-x)*(8-y);\ +- const int B=( x)*(8-y);\ +- const int C=(8-x)*( y);\ +- const int D=( x)*( y);\ ++ const int A = (8-x) * (8-y);\ ++ const int B = ( x) * (8-y);\ ++ const int C = (8-x) * ( y);\ ++ const int D = ( x) * ( y);\ + int i;\ + int bias = rv40_bias[y>>1][x>>1];\ + \ + assert(x<8 && y<8 && x>=0 && y>=0);\ + \ + if(D){\ +- for(i=0; i>1][x>>1];\ + \ + assert(x<8 && y<8 && x>=0 && y>=0);\ + \ + if(D){\ +- for(i=0; iput_rv40_qpel_pixels_tab[0][ 0] = c->put_h264_qpel_pixels_tab[0][0]; +- c->put_rv40_qpel_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c; +- c->put_rv40_qpel_pixels_tab[0][ 2] = put_rv40_qpel16_mc20_c; +- c->put_rv40_qpel_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c; +- c->put_rv40_qpel_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c; +- c->put_rv40_qpel_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c; +- c->put_rv40_qpel_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c; +- c->put_rv40_qpel_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c; +- c->put_rv40_qpel_pixels_tab[0][ 8] = put_rv40_qpel16_mc02_c; +- c->put_rv40_qpel_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c; +- c->put_rv40_qpel_pixels_tab[0][10] = put_rv40_qpel16_mc22_c; +- c->put_rv40_qpel_pixels_tab[0][11] = put_rv40_qpel16_mc32_c; +- c->put_rv40_qpel_pixels_tab[0][12] = put_rv40_qpel16_mc03_c; +- c->put_rv40_qpel_pixels_tab[0][13] = put_rv40_qpel16_mc13_c; +- c->put_rv40_qpel_pixels_tab[0][14] = put_rv40_qpel16_mc23_c; +- c->avg_rv40_qpel_pixels_tab[0][ 0] = c->avg_h264_qpel_pixels_tab[0][0]; +- c->avg_rv40_qpel_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c; +- c->avg_rv40_qpel_pixels_tab[0][ 2] = avg_rv40_qpel16_mc20_c; +- c->avg_rv40_qpel_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c; +- c->avg_rv40_qpel_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c; +- c->avg_rv40_qpel_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c; +- c->avg_rv40_qpel_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c; +- c->avg_rv40_qpel_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c; +- c->avg_rv40_qpel_pixels_tab[0][ 8] = avg_rv40_qpel16_mc02_c; +- c->avg_rv40_qpel_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c; +- c->avg_rv40_qpel_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c; +- c->avg_rv40_qpel_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c; +- c->avg_rv40_qpel_pixels_tab[0][12] = avg_rv40_qpel16_mc03_c; +- c->avg_rv40_qpel_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c; +- c->avg_rv40_qpel_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c; +- c->put_rv40_qpel_pixels_tab[1][ 0] = c->put_h264_qpel_pixels_tab[1][0]; +- c->put_rv40_qpel_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c; +- c->put_rv40_qpel_pixels_tab[1][ 2] = put_rv40_qpel8_mc20_c; +- c->put_rv40_qpel_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c; +- c->put_rv40_qpel_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c; +- c->put_rv40_qpel_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c; +- c->put_rv40_qpel_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c; +- c->put_rv40_qpel_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c; +- c->put_rv40_qpel_pixels_tab[1][ 8] = put_rv40_qpel8_mc02_c; +- c->put_rv40_qpel_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c; +- c->put_rv40_qpel_pixels_tab[1][10] = put_rv40_qpel8_mc22_c; +- c->put_rv40_qpel_pixels_tab[1][11] = put_rv40_qpel8_mc32_c; +- c->put_rv40_qpel_pixels_tab[1][12] = put_rv40_qpel8_mc03_c; +- c->put_rv40_qpel_pixels_tab[1][13] = put_rv40_qpel8_mc13_c; +- c->put_rv40_qpel_pixels_tab[1][14] = put_rv40_qpel8_mc23_c; +- c->avg_rv40_qpel_pixels_tab[1][ 0] = c->avg_h264_qpel_pixels_tab[1][0]; +- c->avg_rv40_qpel_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c; +- c->avg_rv40_qpel_pixels_tab[1][ 2] = avg_rv40_qpel8_mc20_c; +- c->avg_rv40_qpel_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c; +- c->avg_rv40_qpel_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c; +- c->avg_rv40_qpel_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c; +- c->avg_rv40_qpel_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c; +- c->avg_rv40_qpel_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c; +- c->avg_rv40_qpel_pixels_tab[1][ 8] = avg_rv40_qpel8_mc02_c; +- c->avg_rv40_qpel_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c; +- c->avg_rv40_qpel_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c; +- c->avg_rv40_qpel_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c; +- c->avg_rv40_qpel_pixels_tab[1][12] = avg_rv40_qpel8_mc03_c; +- c->avg_rv40_qpel_pixels_tab[1][13] = avg_rv40_qpel8_mc13_c; +- c->avg_rv40_qpel_pixels_tab[1][14] = avg_rv40_qpel8_mc23_c; +- +- c->put_rv40_chroma_pixels_tab[0]= put_rv40_chroma_mc8_c; +- c->put_rv40_chroma_pixels_tab[1]= put_rv40_chroma_mc4_c; +- c->avg_rv40_chroma_pixels_tab[0]= avg_rv40_chroma_mc8_c; +- c->avg_rv40_chroma_pixels_tab[1]= avg_rv40_chroma_mc4_c; ++#define RV40_WEIGHT_FUNC(size) \ ++static void rv40_weight_func_ ## size (uint8_t *dst, uint8_t *src1, uint8_t *src2, int w1, int w2, int stride)\ ++{\ ++ int i, j;\ ++\ ++ for (j = 0; j < size; j++) {\ ++ for (i = 0; i < size; i++)\ ++ dst[i] = (((w2 * src1[i]) >> 9) + ((w1 * src2[i]) >> 9) + 0x10) >> 5;\ ++ src1 += stride;\ ++ src2 += stride;\ ++ dst += stride;\ ++ }\ ++} ++ ++RV40_WEIGHT_FUNC(16) ++RV40_WEIGHT_FUNC(8) ++ ++/** ++ * dither values for deblocking filter - left/top values ++ */ ++static const uint8_t rv40_dither_l[16] = { ++ 0x40, 0x50, 0x20, 0x60, 0x30, 0x50, 0x40, 0x30, ++ 0x50, 0x40, 0x50, 0x30, 0x60, 0x20, 0x50, 0x40 ++}; ++ ++/** ++ * dither values for deblocking filter - right/bottom values ++ */ ++static const uint8_t rv40_dither_r[16] = { ++ 0x40, 0x30, 0x60, 0x20, 0x50, 0x30, 0x30, 0x40, ++ 0x40, 0x40, 0x50, 0x30, 0x20, 0x60, 0x30, 0x40 ++}; ++ ++#define CLIP_SYMM(a, b) av_clip(a, -(b), b) ++/** ++ * weaker deblocking very similar to the one described in 4.4.2 of JVT-A003r1 ++ */ ++static av_always_inline void rv40_weak_loop_filter(uint8_t *src, ++ const int step, ++ const int stride, ++ const int filter_p1, ++ const int filter_q1, ++ const int alpha, ++ const int beta, ++ const int lim_p0q0, ++ const int lim_q1, ++ const int lim_p1) ++{ ++ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; ++ int i, t, u, diff; ++ ++ for (i = 0; i < 4; i++, src += stride) { ++ int diff_p1p0 = src[-2*step] - src[-1*step]; ++ int diff_q1q0 = src[ 1*step] - src[ 0*step]; ++ int diff_p1p2 = src[-2*step] - src[-3*step]; ++ int diff_q1q2 = src[ 1*step] - src[ 2*step]; ++ ++ t = src[0*step] - src[-1*step]; ++ if (!t) ++ continue; ++ ++ u = (alpha * FFABS(t)) >> 7; ++ if (u > 3 - (filter_p1 && filter_q1)) ++ continue; ++ ++ t <<= 2; ++ if (filter_p1 && filter_q1) ++ t += src[-2*step] - src[1*step]; ++ ++ diff = CLIP_SYMM((t + 4) >> 3, lim_p0q0); ++ src[-1*step] = cm[src[-1*step] + diff]; ++ src[ 0*step] = cm[src[ 0*step] - diff]; ++ ++ if (filter_p1 && FFABS(diff_p1p2) <= beta) { ++ t = (diff_p1p0 + diff_p1p2 - diff) >> 1; ++ src[-2*step] = cm[src[-2*step] - CLIP_SYMM(t, lim_p1)]; ++ } ++ ++ if (filter_q1 && FFABS(diff_q1q2) <= beta) { ++ t = (diff_q1q0 + diff_q1q2 + diff) >> 1; ++ src[ 1*step] = cm[src[ 1*step] - CLIP_SYMM(t, lim_q1)]; ++ } ++ } ++} ++ ++static void rv40_h_weak_loop_filter(uint8_t *src, const int stride, ++ const int filter_p1, const int filter_q1, ++ const int alpha, const int beta, ++ const int lim_p0q0, const int lim_q1, ++ const int lim_p1) ++{ ++ rv40_weak_loop_filter(src, stride, 1, filter_p1, filter_q1, ++ alpha, beta, lim_p0q0, lim_q1, lim_p1); ++} ++ ++static void rv40_v_weak_loop_filter(uint8_t *src, const int stride, ++ const int filter_p1, const int filter_q1, ++ const int alpha, const int beta, ++ const int lim_p0q0, const int lim_q1, ++ const int lim_p1) ++{ ++ rv40_weak_loop_filter(src, 1, stride, filter_p1, filter_q1, ++ alpha, beta, lim_p0q0, lim_q1, lim_p1); ++} ++ ++static av_always_inline void rv40_strong_loop_filter(uint8_t *src, ++ const int step, ++ const int stride, ++ const int alpha, ++ const int lims, ++ const int dmode, ++ const int chroma) ++{ ++ int i; ++ ++ for(i = 0; i < 4; i++, src += stride){ ++ int sflag, p0, q0, p1, q1; ++ int t = src[0*step] - src[-1*step]; ++ ++ if (!t) ++ continue; ++ ++ sflag = (alpha * FFABS(t)) >> 7; ++ if (sflag > 1) ++ continue; ++ ++ p0 = (25*src[-3*step] + 26*src[-2*step] + 26*src[-1*step] + ++ 26*src[ 0*step] + 25*src[ 1*step] + ++ rv40_dither_l[dmode + i]) >> 7; ++ ++ q0 = (25*src[-2*step] + 26*src[-1*step] + 26*src[ 0*step] + ++ 26*src[ 1*step] + 25*src[ 2*step] + ++ rv40_dither_r[dmode + i]) >> 7; ++ ++ if (sflag) { ++ p0 = av_clip(p0, src[-1*step] - lims, src[-1*step] + lims); ++ q0 = av_clip(q0, src[ 0*step] - lims, src[ 0*step] + lims); ++ } ++ ++ p1 = (25*src[-4*step] + 26*src[-3*step] + 26*src[-2*step] + 26*p0 + ++ 25*src[ 0*step] + rv40_dither_l[dmode + i]) >> 7; ++ q1 = (25*src[-1*step] + 26*q0 + 26*src[ 1*step] + 26*src[ 2*step] + ++ 25*src[ 3*step] + rv40_dither_r[dmode + i]) >> 7; ++ ++ if (sflag) { ++ p1 = av_clip(p1, src[-2*step] - lims, src[-2*step] + lims); ++ q1 = av_clip(q1, src[ 1*step] - lims, src[ 1*step] + lims); ++ } ++ ++ src[-2*step] = p1; ++ src[-1*step] = p0; ++ src[ 0*step] = q0; ++ src[ 1*step] = q1; ++ ++ if(!chroma){ ++ src[-3*step] = (25*src[-1*step] + 26*src[-2*step] + ++ 51*src[-3*step] + 26*src[-4*step] + 64) >> 7; ++ src[ 2*step] = (25*src[ 0*step] + 26*src[ 1*step] + ++ 51*src[ 2*step] + 26*src[ 3*step] + 64) >> 7; ++ } ++ } ++} ++ ++static void rv40_h_strong_loop_filter(uint8_t *src, const int stride, ++ const int alpha, const int lims, ++ const int dmode, const int chroma) ++{ ++ rv40_strong_loop_filter(src, stride, 1, alpha, lims, dmode, chroma); ++} ++ ++static void rv40_v_strong_loop_filter(uint8_t *src, const int stride, ++ const int alpha, const int lims, ++ const int dmode, const int chroma) ++{ ++ rv40_strong_loop_filter(src, 1, stride, alpha, lims, dmode, chroma); ++} ++ ++static av_always_inline int rv40_loop_filter_strength(uint8_t *src, ++ int step, int stride, ++ int beta, int beta2, ++ int edge, ++ int *p1, int *q1) ++{ ++ int sum_p1p0 = 0, sum_q1q0 = 0, sum_p1p2 = 0, sum_q1q2 = 0; ++ int strong0 = 0, strong1 = 0; ++ uint8_t *ptr; ++ int i; ++ ++ for (i = 0, ptr = src; i < 4; i++, ptr += stride) { ++ sum_p1p0 += ptr[-2*step] - ptr[-1*step]; ++ sum_q1q0 += ptr[ 1*step] - ptr[ 0*step]; ++ } ++ ++ *p1 = FFABS(sum_p1p0) < (beta << 2); ++ *q1 = FFABS(sum_q1q0) < (beta << 2); ++ ++ if(!*p1 && !*q1) ++ return 0; ++ ++ if (!edge) ++ return 0; ++ ++ for (i = 0, ptr = src; i < 4; i++, ptr += stride) { ++ sum_p1p2 += ptr[-2*step] - ptr[-3*step]; ++ sum_q1q2 += ptr[ 1*step] - ptr[ 2*step]; ++ } ++ ++ strong0 = *p1 && (FFABS(sum_p1p2) < beta2); ++ strong1 = *q1 && (FFABS(sum_q1q2) < beta2); ++ ++ return strong0 && strong1; ++} ++ ++static int rv40_h_loop_filter_strength(uint8_t *src, int stride, ++ int beta, int beta2, int edge, ++ int *p1, int *q1) ++{ ++ return rv40_loop_filter_strength(src, stride, 1, beta, beta2, edge, p1, q1); ++} ++ ++static int rv40_v_loop_filter_strength(uint8_t *src, int stride, ++ int beta, int beta2, int edge, ++ int *p1, int *q1) ++{ ++ return rv40_loop_filter_strength(src, 1, stride, beta, beta2, edge, p1, q1); ++} ++ ++av_cold void ff_rv40dsp_init(RV34DSPContext *c, DSPContext* dsp) { ++ ++ ff_rv34dsp_init(c, dsp); ++ ++ c->put_pixels_tab[0][ 0] = dsp->put_h264_qpel_pixels_tab[0][0]; ++ c->put_pixels_tab[0][ 1] = put_rv40_qpel16_mc10_c; ++ c->put_pixels_tab[0][ 2] = dsp->put_h264_qpel_pixels_tab[0][2]; ++ c->put_pixels_tab[0][ 3] = put_rv40_qpel16_mc30_c; ++ c->put_pixels_tab[0][ 4] = put_rv40_qpel16_mc01_c; ++ c->put_pixels_tab[0][ 5] = put_rv40_qpel16_mc11_c; ++ c->put_pixels_tab[0][ 6] = put_rv40_qpel16_mc21_c; ++ c->put_pixels_tab[0][ 7] = put_rv40_qpel16_mc31_c; ++ c->put_pixels_tab[0][ 8] = dsp->put_h264_qpel_pixels_tab[0][8]; ++ c->put_pixels_tab[0][ 9] = put_rv40_qpel16_mc12_c; ++ c->put_pixels_tab[0][10] = put_rv40_qpel16_mc22_c; ++ c->put_pixels_tab[0][11] = put_rv40_qpel16_mc32_c; ++ c->put_pixels_tab[0][12] = put_rv40_qpel16_mc03_c; ++ c->put_pixels_tab[0][13] = put_rv40_qpel16_mc13_c; ++ c->put_pixels_tab[0][14] = put_rv40_qpel16_mc23_c; ++ c->put_pixels_tab[0][15] = ff_put_rv40_qpel16_mc33_c; ++ c->avg_pixels_tab[0][ 0] = dsp->avg_h264_qpel_pixels_tab[0][0]; ++ c->avg_pixels_tab[0][ 1] = avg_rv40_qpel16_mc10_c; ++ c->avg_pixels_tab[0][ 2] = dsp->avg_h264_qpel_pixels_tab[0][2]; ++ c->avg_pixels_tab[0][ 3] = avg_rv40_qpel16_mc30_c; ++ c->avg_pixels_tab[0][ 4] = avg_rv40_qpel16_mc01_c; ++ c->avg_pixels_tab[0][ 5] = avg_rv40_qpel16_mc11_c; ++ c->avg_pixels_tab[0][ 6] = avg_rv40_qpel16_mc21_c; ++ c->avg_pixels_tab[0][ 7] = avg_rv40_qpel16_mc31_c; ++ c->avg_pixels_tab[0][ 8] = dsp->avg_h264_qpel_pixels_tab[0][8]; ++ c->avg_pixels_tab[0][ 9] = avg_rv40_qpel16_mc12_c; ++ c->avg_pixels_tab[0][10] = avg_rv40_qpel16_mc22_c; ++ c->avg_pixels_tab[0][11] = avg_rv40_qpel16_mc32_c; ++ c->avg_pixels_tab[0][12] = avg_rv40_qpel16_mc03_c; ++ c->avg_pixels_tab[0][13] = avg_rv40_qpel16_mc13_c; ++ c->avg_pixels_tab[0][14] = avg_rv40_qpel16_mc23_c; ++ c->avg_pixels_tab[0][15] = ff_avg_rv40_qpel16_mc33_c; ++ c->put_pixels_tab[1][ 0] = dsp->put_h264_qpel_pixels_tab[1][0]; ++ c->put_pixels_tab[1][ 1] = put_rv40_qpel8_mc10_c; ++ c->put_pixels_tab[1][ 2] = dsp->put_h264_qpel_pixels_tab[1][2]; ++ c->put_pixels_tab[1][ 3] = put_rv40_qpel8_mc30_c; ++ c->put_pixels_tab[1][ 4] = put_rv40_qpel8_mc01_c; ++ c->put_pixels_tab[1][ 5] = put_rv40_qpel8_mc11_c; ++ c->put_pixels_tab[1][ 6] = put_rv40_qpel8_mc21_c; ++ c->put_pixels_tab[1][ 7] = put_rv40_qpel8_mc31_c; ++ c->put_pixels_tab[1][ 8] = dsp->put_h264_qpel_pixels_tab[1][8]; ++ c->put_pixels_tab[1][ 9] = put_rv40_qpel8_mc12_c; ++ c->put_pixels_tab[1][10] = put_rv40_qpel8_mc22_c; ++ c->put_pixels_tab[1][11] = put_rv40_qpel8_mc32_c; ++ c->put_pixels_tab[1][12] = put_rv40_qpel8_mc03_c; ++ c->put_pixels_tab[1][13] = put_rv40_qpel8_mc13_c; ++ c->put_pixels_tab[1][14] = put_rv40_qpel8_mc23_c; ++ c->put_pixels_tab[1][15] = ff_put_rv40_qpel8_mc33_c; ++ c->avg_pixels_tab[1][ 0] = dsp->avg_h264_qpel_pixels_tab[1][0]; ++ c->avg_pixels_tab[1][ 1] = avg_rv40_qpel8_mc10_c; ++ c->avg_pixels_tab[1][ 2] = dsp->avg_h264_qpel_pixels_tab[1][2]; ++ c->avg_pixels_tab[1][ 3] = avg_rv40_qpel8_mc30_c; ++ c->avg_pixels_tab[1][ 4] = avg_rv40_qpel8_mc01_c; ++ c->avg_pixels_tab[1][ 5] = avg_rv40_qpel8_mc11_c; ++ c->avg_pixels_tab[1][ 6] = avg_rv40_qpel8_mc21_c; ++ c->avg_pixels_tab[1][ 7] = avg_rv40_qpel8_mc31_c; ++ c->avg_pixels_tab[1][ 8] = dsp->avg_h264_qpel_pixels_tab[1][8]; ++ c->avg_pixels_tab[1][ 9] = avg_rv40_qpel8_mc12_c; ++ c->avg_pixels_tab[1][10] = avg_rv40_qpel8_mc22_c; ++ c->avg_pixels_tab[1][11] = avg_rv40_qpel8_mc32_c; ++ c->avg_pixels_tab[1][12] = avg_rv40_qpel8_mc03_c; ++ c->avg_pixels_tab[1][13] = avg_rv40_qpel8_mc13_c; ++ c->avg_pixels_tab[1][14] = avg_rv40_qpel8_mc23_c; ++ c->avg_pixels_tab[1][15] = ff_avg_rv40_qpel8_mc33_c; ++ ++ c->put_chroma_pixels_tab[0] = put_rv40_chroma_mc8_c; ++ c->put_chroma_pixels_tab[1] = put_rv40_chroma_mc4_c; ++ c->avg_chroma_pixels_tab[0] = avg_rv40_chroma_mc8_c; ++ c->avg_chroma_pixels_tab[1] = avg_rv40_chroma_mc4_c; ++ ++ c->rv40_weight_pixels_tab[0] = rv40_weight_func_16; ++ c->rv40_weight_pixels_tab[1] = rv40_weight_func_8; ++ ++ c->rv40_weak_loop_filter[0] = rv40_h_weak_loop_filter; ++ c->rv40_weak_loop_filter[1] = rv40_v_weak_loop_filter; ++ c->rv40_strong_loop_filter[0] = rv40_h_strong_loop_filter; ++ c->rv40_strong_loop_filter[1] = rv40_v_strong_loop_filter; ++ c->rv40_loop_filter_strength[0] = rv40_h_loop_filter_strength; ++ c->rv40_loop_filter_strength[1] = rv40_v_loop_filter_strength; ++ ++ if (HAVE_MMX) ++ ff_rv40dsp_init_x86(c, dsp); ++ if (HAVE_NEON) ++ ff_rv40dsp_init_neon(c, dsp); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s302m.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s302m.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s302m.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s302m.c 2012-05-14 14:08:54.197337224 +0200 +@@ -0,0 +1,175 @@ ++/* ++ * SMPTE 302M decoder ++ * Copyright (c) 2008 Laurent Aimar ++ * Copyright (c) 2009 Baptiste Coudurier ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++ ++#define AES3_HEADER_LEN 4 ++ ++typedef struct S302MDecodeContext { ++ AVFrame frame; ++} S302MDecodeContext; ++ ++static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t *buf, ++ int buf_size) ++{ ++ uint32_t h; ++ int frame_size, channels, bits; ++ ++ if (buf_size <= AES3_HEADER_LEN) { ++ av_log(avctx, AV_LOG_ERROR, "frame is too short\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* ++ * AES3 header : ++ * size: 16 ++ * number channels 2 ++ * channel_id 8 ++ * bits per samples 2 ++ * alignments 4 ++ */ ++ ++ h = AV_RB32(buf); ++ frame_size = (h >> 16) & 0xffff; ++ channels = ((h >> 14) & 0x0003) * 2 + 2; ++ bits = ((h >> 4) & 0x0003) * 4 + 16; ++ ++ if (AES3_HEADER_LEN + frame_size != buf_size || bits > 24) { ++ av_log(avctx, AV_LOG_ERROR, "frame has invalid header\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* Set output properties */ ++ avctx->bits_per_coded_sample = bits; ++ if (bits > 16) ++ avctx->sample_fmt = AV_SAMPLE_FMT_S32; ++ else ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avctx->channels = channels; ++ switch(channels) { ++ case 2: ++ avctx->channel_layout = AV_CH_LAYOUT_STEREO; ++ break; ++ case 4: ++ avctx->channel_layout = AV_CH_LAYOUT_QUAD; ++ break; ++ case 8: ++ avctx->channel_layout = AV_CH_LAYOUT_5POINT1_BACK | AV_CH_LAYOUT_STEREO_DOWNMIX; ++ } ++ avctx->sample_rate = 48000; ++ avctx->bit_rate = 48000 * avctx->channels * (avctx->bits_per_coded_sample + 4) + ++ 32 * (48000 / (buf_size * 8 / ++ (avctx->channels * ++ (avctx->bits_per_coded_sample + 4)))); ++ ++ return frame_size; ++} ++ ++static int s302m_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ S302MDecodeContext *s = avctx->priv_data; ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int block_size, ret; ++ ++ int frame_size = s302m_parse_frame_header(avctx, buf, buf_size); ++ if (frame_size < 0) ++ return frame_size; ++ ++ buf_size -= AES3_HEADER_LEN; ++ buf += AES3_HEADER_LEN; ++ ++ /* get output buffer */ ++ block_size = (avctx->bits_per_coded_sample + 4) / 4; ++ s->frame.nb_samples = 2 * (buf_size / block_size) / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ buf_size = (s->frame.nb_samples * avctx->channels / 2) * block_size; ++ ++ if (avctx->bits_per_coded_sample == 24) { ++ uint32_t *o = (uint32_t *)s->frame.data[0]; ++ for (; buf_size > 6; buf_size -= 7) { ++ *o++ = (av_reverse[buf[2]] << 24) | ++ (av_reverse[buf[1]] << 16) | ++ (av_reverse[buf[0]] << 8); ++ *o++ = (av_reverse[buf[6] & 0xf0] << 28) | ++ (av_reverse[buf[5]] << 20) | ++ (av_reverse[buf[4]] << 12) | ++ (av_reverse[buf[3] & 0x0f] << 4); ++ buf += 7; ++ } ++ } else if (avctx->bits_per_coded_sample == 20) { ++ uint32_t *o = (uint32_t *)s->frame.data[0]; ++ for (; buf_size > 5; buf_size -= 6) { ++ *o++ = (av_reverse[buf[2] & 0xf0] << 28) | ++ (av_reverse[buf[1]] << 20) | ++ (av_reverse[buf[0]] << 12); ++ *o++ = (av_reverse[buf[5] & 0xf0] << 28) | ++ (av_reverse[buf[4]] << 20) | ++ (av_reverse[buf[3]] << 12); ++ buf += 6; ++ } ++ } else { ++ uint16_t *o = (uint16_t *)s->frame.data[0]; ++ for (; buf_size > 4; buf_size -= 5) { ++ *o++ = (av_reverse[buf[1]] << 8) | ++ av_reverse[buf[0]]; ++ *o++ = (av_reverse[buf[4] & 0xf0] << 12) | ++ (av_reverse[buf[3]] << 4) | ++ (av_reverse[buf[2]] >> 4); ++ buf += 5; ++ } ++ } ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return avpkt->size; ++} ++ ++static int s302m_decode_init(AVCodecContext *avctx) ++{ ++ S302MDecodeContext *s = avctx->priv_data; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ ++ return 0; ++} ++ ++ ++AVCodec ff_s302m_decoder = { ++ .name = "s302m", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_S302M, ++ .priv_data_size = sizeof(S302MDecodeContext), ++ .init = s302m_decode_init, ++ .decode = s302m_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("SMPTE 302M"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s3tc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s3tc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s3tc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s3tc.c 2012-05-14 14:08:54.198337244 +0200 +@@ -28,7 +28,7 @@ + static inline void dxt1_decode_pixels(const uint8_t *s, uint32_t *d, + unsigned int qstride, unsigned int flag, + uint64_t alpha) { +- unsigned int x, y, c0, c1, a = (!flag * 255) << 24; ++ unsigned int x, y, c0, c1, a = (!flag * 255u) << 24; + unsigned int rb0, rb1, rb2, rb3, g0, g1, g2, g3; + uint32_t colors[4], pixels; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s3tc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s3tc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/s3tc.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/s3tc.h 2012-05-14 14:08:54.199337264 +0200 +@@ -29,8 +29,8 @@ + + /** + * Decode DXT1 encoded data to RGB32 +- * @param *src source buffer, has to be aligned on a 4-byte boundary +- * @param *dst destination buffer ++ * @param src source buffer, has to be aligned on a 4-byte boundary ++ * @param dst destination buffer + * @param w width of output image + * @param h height of output image + * @param stride line size of output image +@@ -40,8 +40,8 @@ + const unsigned int stride); + /** + * Decode DXT3 encoded data to RGB32 +- * @param *src source buffer, has to be aligned on a 4-byte boundary +- * @param *dst destination buffer ++ * @param src source buffer, has to be aligned on a 4-byte boundary ++ * @param dst destination buffer + * @param w width of output image + * @param h height of output image + * @param stride line size of output image +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sbr.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sbr.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sbr.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sbr.h 2012-05-14 14:08:54.199337264 +0200 +@@ -42,7 +42,7 @@ + uint8_t bs_xover_band; + + /** +- * @defgroup bs_header_extra_1 Variables associated with bs_header_extra_1 ++ * @name Variables associated with bs_header_extra_1 + * @{ + */ + uint8_t bs_freq_scale; +@@ -58,7 +58,7 @@ + */ + typedef struct { + /** +- * @defgroup aac_bitstream Main bitstream data variables ++ * @name Main bitstream data variables + * @{ + */ + unsigned bs_frame_class; +@@ -74,7 +74,7 @@ + /** @} */ + + /** +- * @defgroup state State variables ++ * @name State variables + * @{ + */ + DECLARE_ALIGNED(16, float, synthesis_filterbank_samples)[SBR_SYNTHESIS_BUF_SIZE]; +@@ -116,7 +116,7 @@ + SpectrumParameters spectrum_params; + int bs_amp_res_header; + /** +- * @defgroup bs_header_extra_2 variables associated with bs_header_extra_2 ++ * @name Variables associated with bs_header_extra_2 + * @{ + */ + unsigned bs_limiter_bands; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sgidec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sgidec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sgidec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sgidec.c 2012-05-14 14:08:54.200337285 +0200 +@@ -19,7 +19,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/avassert.h" + #include "avcodec.h" + #include "bytestream.h" + #include "sgi.h" +@@ -31,26 +32,27 @@ + unsigned int depth; + unsigned int bytes_per_channel; + int linesize; ++ GetByteContext g; + } SgiState; + + /** + * Expand an RLE row into a channel. +- * @param in_buf input buffer +- * @param in_end end of input buffer ++ * @param s the current image state + * @param out_buf Points to one line after the output buffer. + * @param out_end end of line in output buffer + * @param pixelstride pixel stride of input buffer + * @return size of output in bytes, -1 if buffer overflows + */ +-static int expand_rle_row(const uint8_t *in_buf, const uint8_t* in_end, +- unsigned char *out_buf, uint8_t* out_end, int pixelstride) ++static int expand_rle_row(SgiState *s, uint8_t *out_buf, ++ uint8_t *out_end, int pixelstride) + { + unsigned char pixel, count; + unsigned char *orig = out_buf; + + while (1) { +- if(in_buf + 1 > in_end) return -1; +- pixel = bytestream_get_byte(&in_buf); ++ if (bytestream2_get_bytes_left(&s->g) < 1) ++ return AVERROR_INVALIDDATA; ++ pixel = bytestream2_get_byteu(&s->g); + if (!(count = (pixel & 0x7f))) { + return (out_buf - orig) / pixelstride; + } +@@ -60,11 +62,11 @@ + + if (pixel & 0x80) { + while (count--) { +- *out_buf = bytestream_get_byte(&in_buf); ++ *out_buf = bytestream2_get_byte(&s->g); + out_buf += pixelstride; + } + } else { +- pixel = bytestream_get_byte(&in_buf); ++ pixel = bytestream2_get_byte(&s->g); + + while (count--) { + *out_buf = pixel; +@@ -77,37 +79,32 @@ + /** + * Read a run length encoded SGI image. + * @param out_buf output buffer +- * @param in_buf input buffer +- * @param in_end end of input buffer + * @param s the current image state + * @return 0 if no error, else return error number. + */ +-static int read_rle_sgi(unsigned char* out_buf, const uint8_t *in_buf, +- const uint8_t *in_end, SgiState* s) ++static int read_rle_sgi(uint8_t *out_buf, SgiState *s) + { + uint8_t *dest_row; + unsigned int len = s->height * s->depth * 4; +- const uint8_t *start_table = in_buf; ++ GetByteContext g_table = s->g; + unsigned int y, z; + unsigned int start_offset; + + /* size of RLE offset and length tables */ +- if(len * 2 > in_end - in_buf) { ++ if (len * 2 > bytestream2_get_bytes_left(&s->g)) { + return AVERROR_INVALIDDATA; + } + +- in_buf -= SGI_HEADER_SIZE; + for (z = 0; z < s->depth; z++) { + dest_row = out_buf; + for (y = 0; y < s->height; y++) { + dest_row -= s->linesize; +- start_offset = bytestream_get_be32(&start_table); +- if(start_offset > in_end - in_buf) { ++ start_offset = bytestream2_get_be32(&g_table); ++ bytestream2_seek(&s->g, start_offset, SEEK_SET); ++ if (expand_rle_row(s, dest_row + z, dest_row + FFABS(s->linesize), ++ s->depth) != s->width) { + return AVERROR_INVALIDDATA; + } +- if (expand_rle_row(in_buf + start_offset, in_end, dest_row + z, +- dest_row + FFABS(s->linesize), s->depth) != s->width) +- return AVERROR_INVALIDDATA; + } + } + return 0; +@@ -117,32 +114,37 @@ + * Read an uncompressed SGI image. + * @param out_buf output buffer + * @param out_end end ofoutput buffer +- * @param in_buf input buffer +- * @param in_end end of input buffer + * @param s the current image state + * @return 0 if read success, otherwise return -1. + */ + static int read_uncompressed_sgi(unsigned char* out_buf, uint8_t* out_end, +- const uint8_t *in_buf, const uint8_t *in_end, SgiState* s) ++ SgiState *s) + { + int x, y, z; +- const uint8_t *ptr; + unsigned int offset = s->height * s->width * s->bytes_per_channel; ++ GetByteContext gp[4]; + + /* Test buffer size. */ +- if (offset * s->depth > in_end - in_buf) { +- return -1; ++ if (offset * s->depth > bytestream2_get_bytes_left(&s->g)) ++ return AVERROR_INVALIDDATA; ++ ++ /* Create a reader for each plane */ ++ for (z = 0; z < s->depth; z++) { ++ gp[z] = s->g; ++ bytestream2_skip(&gp[z], z * offset); + } + + for (y = s->height - 1; y >= 0; y--) { + out_end = out_buf + (y * s->linesize); +- for (x = s->width; x > 0; x--) { +- ptr = in_buf += s->bytes_per_channel; +- for(z = 0; z < s->depth; z ++) { +- memcpy(out_end, ptr, s->bytes_per_channel); +- out_end += s->bytes_per_channel; +- ptr += offset; +- } ++ if (s->bytes_per_channel == 1) { ++ for (x = s->width; x > 0; x--) ++ for (z = 0; z < s->depth; z++) ++ *out_end++ = bytestream2_get_byteu(&gp[z]); ++ } else { ++ uint16_t *out16 = (uint16_t *)out_end; ++ for (x = s->width; x > 0; x--) ++ for (z = 0; z < s->depth; z++) ++ *out16++ = bytestream2_get_ne16u(&gp[z]); + } + } + return 0; +@@ -152,33 +154,31 @@ + void *data, int *data_size, + AVPacket *avpkt) + { +- const uint8_t *in_buf = avpkt->data; +- int buf_size = avpkt->size; + SgiState *s = avctx->priv_data; + AVFrame *picture = data; + AVFrame *p = &s->picture; +- const uint8_t *in_end = in_buf + buf_size; + unsigned int dimension, rle; + int ret = 0; + uint8_t *out_buf, *out_end; + +- if (buf_size < SGI_HEADER_SIZE){ +- av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", buf_size); +- return -1; ++ bytestream2_init(&s->g, avpkt->data, avpkt->size); ++ if (bytestream2_get_bytes_left(&s->g) < SGI_HEADER_SIZE) { ++ av_log(avctx, AV_LOG_ERROR, "buf_size too small (%d)\n", avpkt->size); ++ return AVERROR_INVALIDDATA; + } + + /* Test for SGI magic. */ +- if (bytestream_get_be16(&in_buf) != SGI_MAGIC) { ++ if (bytestream2_get_be16(&s->g) != SGI_MAGIC) { + av_log(avctx, AV_LOG_ERROR, "bad magic number\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- rle = bytestream_get_byte(&in_buf); +- s->bytes_per_channel = bytestream_get_byte(&in_buf); +- dimension = bytestream_get_be16(&in_buf); +- s->width = bytestream_get_be16(&in_buf); +- s->height = bytestream_get_be16(&in_buf); +- s->depth = bytestream_get_be16(&in_buf); ++ rle = bytestream2_get_byte(&s->g); ++ s->bytes_per_channel = bytestream2_get_byte(&s->g); ++ dimension = bytestream2_get_be16(&s->g); ++ s->width = bytestream2_get_be16(&s->g); ++ s->height = bytestream2_get_be16(&s->g); ++ s->depth = bytestream2_get_be16(&s->g); + + if (s->bytes_per_channel != 1 && (s->bytes_per_channel != 2 || rle)) { + av_log(avctx, AV_LOG_ERROR, "wrong channel number\n"); +@@ -195,8 +195,8 @@ + avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_GRAY16BE : PIX_FMT_GRAY8; + } else if (s->depth == SGI_RGB) { + avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_RGB48BE : PIX_FMT_RGB24; +- } else if (s->depth == SGI_RGBA && s->bytes_per_channel == 1) { +- avctx->pix_fmt = PIX_FMT_RGBA; ++ } else if (s->depth == SGI_RGBA) { ++ avctx->pix_fmt = s->bytes_per_channel == 2 ? PIX_FMT_RGBA64BE : PIX_FMT_RGBA; + } else { + av_log(avctx, AV_LOG_ERROR, "wrong picture format\n"); + return -1; +@@ -215,7 +215,7 @@ + return -1; + } + +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + out_buf = p->data[0]; + +@@ -224,19 +224,19 @@ + s->linesize = p->linesize[0]; + + /* Skip header. */ +- in_buf += SGI_HEADER_SIZE - 12; ++ bytestream2_seek(&s->g, SGI_HEADER_SIZE, SEEK_SET); + if (rle) { +- ret = read_rle_sgi(out_end, in_buf, in_end, s); ++ ret = read_rle_sgi(out_end, s); + } else { +- ret = read_uncompressed_sgi(out_buf, out_end, in_buf, in_end, s); ++ ret = read_uncompressed_sgi(out_buf, out_end, s); + } + + if (ret == 0) { + *picture = s->picture; + *data_size = sizeof(AVPicture); +- return buf_size; ++ return avpkt->size; + } else { +- return -1; ++ return ret; + } + } + +@@ -260,14 +260,13 @@ + } + + AVCodec ff_sgi_decoder = { +- "sgi", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SGI, +- sizeof(SgiState), +- sgi_init, +- NULL, +- sgi_end, +- decode_frame, ++ .name = "sgi", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SGI, ++ .priv_data_size = sizeof(SgiState), ++ .init = sgi_init, ++ .close = sgi_end, ++ .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("SGI image"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sgienc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sgienc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sgienc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sgienc.c 2012-05-14 14:08:54.201337305 +0200 +@@ -48,15 +48,18 @@ + AVFrame * const p = &s->picture; + uint8_t *offsettab, *lengthtab, *in_buf, *encode_buf; + int x, y, z, length, tablesize; +- unsigned int width, height, depth, dimension; ++ unsigned int width, height, depth, dimension, bytes_per_channel, pixmax, put_be; + unsigned char *orig_buf = buf, *end_buf = buf + buf_size; + + *p = *(AVFrame*)data; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + + width = avctx->width; + height = avctx->height; ++ bytes_per_channel = 1; ++ pixmax = 0xFF; ++ put_be = HAVE_BIGENDIAN; + + switch (avctx->pix_fmt) { + case PIX_FMT_GRAY8: +@@ -71,6 +74,33 @@ + dimension = SGI_MULTI_CHAN; + depth = SGI_RGBA; + break; ++ case PIX_FMT_GRAY16LE: ++ put_be = !HAVE_BIGENDIAN; ++ case PIX_FMT_GRAY16BE: ++ avctx->coder_type = FF_CODER_TYPE_RAW; ++ bytes_per_channel = 2; ++ pixmax = 0xFFFF; ++ dimension = SGI_SINGLE_CHAN; ++ depth = SGI_GRAYSCALE; ++ break; ++ case PIX_FMT_RGB48LE: ++ put_be = !HAVE_BIGENDIAN; ++ case PIX_FMT_RGB48BE: ++ avctx->coder_type = FF_CODER_TYPE_RAW; ++ bytes_per_channel = 2; ++ pixmax = 0xFFFF; ++ dimension = SGI_MULTI_CHAN; ++ depth = SGI_RGB; ++ break; ++ case PIX_FMT_RGBA64LE: ++ put_be = !HAVE_BIGENDIAN; ++ case PIX_FMT_RGBA64BE: ++ avctx->coder_type = FF_CODER_TYPE_RAW; ++ bytes_per_channel = 2; ++ pixmax = 0xFFFF; ++ dimension = SGI_MULTI_CHAN; ++ depth = SGI_RGBA; ++ break; + default: + return AVERROR_INVALIDDATA; + } +@@ -86,15 +116,14 @@ + /* Encode header. */ + bytestream_put_be16(&buf, SGI_MAGIC); + bytestream_put_byte(&buf, avctx->coder_type != FF_CODER_TYPE_RAW); /* RLE 1 - VERBATIM 0*/ +- bytestream_put_byte(&buf, 1); /* bytes_per_channel */ ++ bytestream_put_byte(&buf, bytes_per_channel); + bytestream_put_be16(&buf, dimension); + bytestream_put_be16(&buf, width); + bytestream_put_be16(&buf, height); + bytestream_put_be16(&buf, depth); + +- /* The rest are constant in this implementation. */ + bytestream_put_be32(&buf, 0L); /* pixmin */ +- bytestream_put_be32(&buf, 255L); /* pixmax */ ++ bytestream_put_be32(&buf, pixmax); + bytestream_put_be32(&buf, 0L); /* dummy */ + + /* name */ +@@ -144,11 +173,19 @@ + av_free(encode_buf); + } else { + for (z = 0; z < depth; z++) { +- in_buf = p->data[0] + p->linesize[0] * (height - 1) + z; ++ in_buf = p->data[0] + p->linesize[0] * (height - 1) + z * bytes_per_channel; + + for (y = 0; y < height; y++) { + for (x = 0; x < width * depth; x += depth) ++ if (bytes_per_channel == 1) { + bytestream_put_byte(&buf, in_buf[x]); ++ } else { ++ if (put_be) { ++ bytestream_put_be16(&buf, ((uint16_t *)in_buf)[x]); ++ } else { ++ bytestream_put_le16(&buf, ((uint16_t *)in_buf)[x]); ++ } ++ } + + in_buf -= p->linesize[0]; + } +@@ -160,13 +197,16 @@ + } + + AVCodec ff_sgi_encoder = { +- "sgi", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SGI, +- sizeof(SgiContext), +- encode_init, +- encode_frame, +- NULL, +- .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, PIX_FMT_GRAY8, PIX_FMT_NONE}, ++ .name = "sgi", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SGI, ++ .priv_data_size = sizeof(SgiContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .pix_fmts= (const enum PixelFormat[]){PIX_FMT_RGB24, PIX_FMT_RGBA, ++ PIX_FMT_RGB48LE, PIX_FMT_RGB48BE, ++ PIX_FMT_RGBA64LE, PIX_FMT_RGBA64BE, ++ PIX_FMT_GRAY16LE, PIX_FMT_GRAY16BE, ++ PIX_FMT_GRAY8, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("SGI image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_align.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_align.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_align.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_align.c 2012-05-14 14:08:54.202337325 +0200 +@@ -333,6 +333,9 @@ + + void dsputil_init_align(DSPContext* c, AVCodecContext *avctx) + { ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; ++ ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = put_rnd_pixels16_o; + c->put_pixels_tab[0][1] = put_rnd_pixels16_x; + c->put_pixels_tab[0][2] = put_rnd_pixels16_y; +@@ -368,6 +371,7 @@ + c->avg_no_rnd_pixels_tab[1][1] = avg_no_rnd_pixels8_x; + c->avg_no_rnd_pixels_tab[1][2] = avg_no_rnd_pixels8_y; + c->avg_no_rnd_pixels_tab[1][3] = avg_no_rnd_pixels8_xy; ++ } + + #ifdef QPEL + +@@ -401,20 +405,24 @@ + dspfunc(avg_qpel, 1, 8); + /* dspfunc(avg_no_rnd_qpel, 1, 8); */ + ++ if (!high_bit_depth) { + dspfunc(put_h264_qpel, 0, 16); + dspfunc(put_h264_qpel, 1, 8); + dspfunc(put_h264_qpel, 2, 4); + dspfunc(avg_h264_qpel, 0, 16); + dspfunc(avg_h264_qpel, 1, 8); + dspfunc(avg_h264_qpel, 2, 4); ++ } + + #undef dspfunc ++ if (!high_bit_depth) { + c->put_h264_chroma_pixels_tab[0]= put_h264_chroma_mc8_sh4; + c->put_h264_chroma_pixels_tab[1]= put_h264_chroma_mc4_sh4; + c->put_h264_chroma_pixels_tab[2]= put_h264_chroma_mc2_sh4; + c->avg_h264_chroma_pixels_tab[0]= avg_h264_chroma_mc8_sh4; + c->avg_h264_chroma_pixels_tab[1]= avg_h264_chroma_mc4_sh4; + c->avg_h264_chroma_pixels_tab[2]= avg_h264_chroma_mc2_sh4; ++ } + + c->put_mspel_pixels_tab[0]= put_mspel8_mc00_sh4; + c->put_mspel_pixels_tab[1]= put_mspel8_mc10_sh4; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.c 2012-05-14 14:08:54.203337345 +0200 +@@ -92,10 +92,13 @@ + void dsputil_init_sh4(DSPContext* c, AVCodecContext *avctx) + { + const int idct_algo= avctx->idct_algo; ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; + dsputil_init_align(c,avctx); + ++ if (!high_bit_depth) + c->clear_blocks = clear_blocks_sh4; +- if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SH4){ ++ if (avctx->bits_per_raw_sample <= 8 && ++ (idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SH4)) { + c->idct_put = idct_put; + c->idct_add = idct_add; + c->idct = idct_sh4; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/dsputil_sh4.h 2012-05-14 14:08:54.203337345 +0200 +@@ -25,4 +25,4 @@ + void idct_sh4(DCTELEM *block); + void dsputil_init_align(DSPContext* c, AVCodecContext *avctx); + +-#endif ++#endif /* AVCODEC_SH4_DSPUTIL_SH4_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/idct_sh4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/idct_sh4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/idct_sh4.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/idct_sh4.c 2012-05-14 14:08:54.204337365 +0200 +@@ -54,8 +54,6 @@ + #undef c6 + #undef c7 + +-#if 1 +- + #define load_matrix(table) \ + do { \ + const float *t = table; \ +@@ -84,52 +82,11 @@ + register float fr2 __asm__("fr2"); \ + register float fr3 __asm__("fr3") + +-#else +- +-/* generic C code for check */ +- +-static void ftrv_(const float xf[],float fv[]) +-{ +- float f0,f1,f2,f3; +- f0 = fv[0]; +- f1 = fv[1]; +- f2 = fv[2]; +- f3 = fv[3]; +- fv[0] = xf[0]*f0 + xf[4]*f1 + xf[ 8]*f2 + xf[12]*f3; +- fv[1] = xf[1]*f0 + xf[5]*f1 + xf[ 9]*f2 + xf[13]*f3; +- fv[2] = xf[2]*f0 + xf[6]*f1 + xf[10]*f2 + xf[14]*f3; +- fv[3] = xf[3]*f0 + xf[7]*f1 + xf[11]*f2 + xf[15]*f3; +-} +- +-static void load_matrix_(float xf[],const float table[]) +-{ +- int i; +- for(i=0;i<16;i++) xf[i]=table[i]; +-} +- +-#define ftrv() ftrv_(xf,fv) +-#define load_matrix(table) load_matrix_(xf,table) +- +-#define DEFREG \ +- float fv[4],xf[16] +- +-#define fr0 fv[0] +-#define fr1 fv[1] +-#define fr2 fv[2] +-#define fr3 fv[3] +- +-#endif +- +-#if 1 + #define DESCALE(x,n) (x)*(1.0f/(1<<(n))) +-#else +-#define DESCALE(x,n) (((int)(x)+(1<<(n-1)))>>(n)) +-#endif + + /* this code work worse on gcc cvs. 3.2.3 work fine */ + + +-#if 1 + //optimized + + void idct_sh4(DCTELEM *block) +@@ -252,111 +209,3 @@ + + fp_single_leave(fpscr); + } +-#else +-void idct_sh4(DCTELEM *block) +-{ +- DEFREG; +- +- int i; +- float tblock[8*8],*fblock; +- +- /* row */ +- +- /* even part */ +- load_matrix(even_table); +- +- fblock = tblock; +- i = 8; +- do { +- fr0 = block[0]; +- fr1 = block[2]; +- fr2 = block[4]; +- fr3 = block[6]; +- block+=8; +- ftrv(); +- fblock[0] = fr0; +- fblock[2] = fr1; +- fblock[4] = fr2; +- fblock[6] = fr3; +- fblock+=8; +- } while(--i); +- block-=8*8; +- fblock-=8*8; +- +- load_matrix(odd_table); +- +- i = 8; +- +- do { +- float t0,t1,t2,t3; +- fr0 = block[1]; +- fr1 = block[3]; +- fr2 = block[5]; +- fr3 = block[7]; +- block+=8; +- ftrv(); +- t0 = fblock[0]; +- t1 = fblock[2]; +- t2 = fblock[4]; +- t3 = fblock[6]; +- fblock[0] = t0 + fr0; +- fblock[7] = t0 - fr0; +- fblock[1] = t1 + fr1; +- fblock[6] = t1 - fr1; +- fblock[2] = t2 + fr2; +- fblock[5] = t2 - fr2; +- fblock[3] = t3 + fr3; +- fblock[4] = t3 - fr3; +- fblock+=8; +- } while(--i); +- block-=8*8; +- fblock-=8*8; +- +- /* col */ +- +- /* even part */ +- load_matrix(even_table); +- +- i = 8; +- +- do { +- fr0 = fblock[8*0]; +- fr1 = fblock[8*2]; +- fr2 = fblock[8*4]; +- fr3 = fblock[8*6]; +- ftrv(); +- fblock[8*0] = fr0; +- fblock[8*2] = fr1; +- fblock[8*4] = fr2; +- fblock[8*6] = fr3; +- fblock++; +- } while(--i); +- fblock-=8; +- +- load_matrix(odd_table); +- +- i=8; +- do { +- float t0,t1,t2,t3; +- fr0 = fblock[8*1]; +- fr1 = fblock[8*3]; +- fr2 = fblock[8*5]; +- fr3 = fblock[8*7]; +- ftrv(); +- t0 = fblock[8*0]; +- t1 = fblock[8*2]; +- t2 = fblock[8*4]; +- t3 = fblock[8*6]; +- fblock++; +- block[8*0] = DESCALE(t0 + fr0,3); +- block[8*7] = DESCALE(t0 - fr0,3); +- block[8*1] = DESCALE(t1 + fr1,3); +- block[8*6] = DESCALE(t1 - fr1,3); +- block[8*2] = DESCALE(t2 + fr2,3); +- block[8*5] = DESCALE(t2 - fr2,3); +- block[8*3] = DESCALE(t3 + fr3,3); +- block[8*4] = DESCALE(t3 - fr3,3); +- block++; +- } while(--i); +-} +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/qpel.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/qpel.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sh4/qpel.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sh4/qpel.c 2012-05-14 14:08:54.206337405 +0200 +@@ -897,7 +897,6 @@ + #undef op_put + #undef op_put_no_rnd + +-#if 1 + #define H264_LOWPASS(OPNAME, OP, OP2) \ + static inline void OPNAME ## h264_qpel_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride,int w,int h){\ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP;\ +@@ -1298,7 +1297,6 @@ + #undef op_put + #undef op2_avg + #undef op2_put +-#endif + + static void wmv2_mspel8_h_lowpass(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int h){ + uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/shorten.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/shorten.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/shorten.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/shorten.c 2012-05-14 14:08:54.208337445 +0200 +@@ -26,9 +26,9 @@ + * + */ + +-#define DEBUG + #include + #include "avcodec.h" ++#include "bytestream.h" + #include "get_bits.h" + #include "golomb.h" + +@@ -70,18 +70,23 @@ + #define FN_ZERO 8 + #define FN_VERBATIM 9 + ++/** indicates if the FN_* command is audio or non-audio */ ++static const uint8_t is_audio_command[10] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 }; ++ + #define VERBATIM_CKSIZE_SIZE 5 + #define VERBATIM_BYTE_SIZE 8 + #define CANONICAL_HEADER_SIZE 44 + + typedef struct ShortenContext { + AVCodecContext *avctx; ++ AVFrame frame; + GetBitContext gb; + + int min_framesize, max_framesize; + int channels; + + int32_t *decoded[MAX_CHANNELS]; ++ int32_t *decoded_base[MAX_CHANNELS]; + int32_t *offset[MAX_CHANNELS]; + int *coeffs; + uint8_t *bitstream; +@@ -99,6 +104,8 @@ + int blocksize; + int bitindex; + int32_t lpcqoffset; ++ int got_header; ++ int got_quit_command; + } ShortenContext; + + static av_cold int shorten_decode_init(AVCodecContext * avctx) +@@ -107,6 +114,9 @@ + s->avctx = avctx; + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -114,6 +124,7 @@ + { + int i, chan; + int *coeffs; ++ void *tmp_ptr; + + for (chan=0; chanchannels; chan++) { + if(FFMAX(1, s->nmean) >= UINT_MAX/sizeof(int32_t)){ +@@ -125,12 +136,19 @@ + return -1; + } + +- s->offset[chan] = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); +- +- s->decoded[chan] = av_realloc(s->decoded[chan], sizeof(int32_t)*(s->blocksize + s->nwrap)); ++ tmp_ptr = av_realloc(s->offset[chan], sizeof(int32_t)*FFMAX(1, s->nmean)); ++ if (!tmp_ptr) ++ return AVERROR(ENOMEM); ++ s->offset[chan] = tmp_ptr; ++ ++ tmp_ptr = av_realloc(s->decoded_base[chan], (s->blocksize + s->nwrap) * ++ sizeof(s->decoded_base[0][0])); ++ if (!tmp_ptr) ++ return AVERROR(ENOMEM); ++ s->decoded_base[chan] = tmp_ptr; + for (i=0; inwrap; i++) +- s->decoded[chan][i] = 0; +- s->decoded[chan] += s->nwrap; ++ s->decoded_base[chan][i] = 0; ++ s->decoded[chan] = s->decoded_base[chan] + s->nwrap; + } + + coeffs = av_realloc(s->coeffs, s->nwrap * sizeof(*s->coeffs)); +@@ -156,11 +174,11 @@ + + if (s->bitshift != 0) + for (i = 0; i < s->blocksize; i++) +- buffer[s->nwrap + i] <<= s->bitshift; ++ buffer[i] <<= s->bitshift; + } + + +-static void init_offset(ShortenContext *s) ++static int init_offset(ShortenContext *s) + { + int32_t mean = 0; + int chan, i; +@@ -174,56 +192,48 @@ + break; + default: + av_log(s->avctx, AV_LOG_ERROR, "unknown audio type"); +- abort(); ++ return AVERROR_INVALIDDATA; + } + + for (chan = 0; chan < s->channels; chan++) + for (i = 0; i < nblock; i++) + s->offset[chan][i] = mean; ++ return 0; + } + +-static inline int get_le32(GetBitContext *gb) +-{ +- return av_bswap32(get_bits_long(gb, 32)); +-} +- +-static inline short get_le16(GetBitContext *gb) +-{ +- return av_bswap16(get_bits_long(gb, 16)); +-} +- +-static int decode_wave_header(AVCodecContext *avctx, uint8_t *header, int header_size) ++static int decode_wave_header(AVCodecContext *avctx, const uint8_t *header, ++ int header_size) + { +- GetBitContext hb; + int len; +- int chunk_size; + short wave_format; ++ const uint8_t *end= header + header_size; + +- init_get_bits(&hb, header, header_size*8); +- if (get_le32(&hb) != MKTAG('R','I','F','F')) { ++ if (bytestream_get_le32(&header) != MKTAG('R','I','F','F')) { + av_log(avctx, AV_LOG_ERROR, "missing RIFF tag\n"); + return -1; + } + +- chunk_size = get_le32(&hb); ++ header += 4; /* chunk size */; + +- if (get_le32(&hb) != MKTAG('W','A','V','E')) { ++ if (bytestream_get_le32(&header) != MKTAG('W','A','V','E')) { + av_log(avctx, AV_LOG_ERROR, "missing WAVE tag\n"); + return -1; + } + +- while (get_le32(&hb) != MKTAG('f','m','t',' ')) { +- len = get_le32(&hb); +- skip_bits(&hb, 8*len); ++ while (bytestream_get_le32(&header) != MKTAG('f','m','t',' ')) { ++ len = bytestream_get_le32(&header); ++ if(len<0 || end - header - 8 < len) ++ return AVERROR_INVALIDDATA; ++ header += len; + } +- len = get_le32(&hb); ++ len = bytestream_get_le32(&header); + + if (len < 16) { + av_log(avctx, AV_LOG_ERROR, "fmt chunk was too short\n"); + return -1; + } + +- wave_format = get_le16(&hb); ++ wave_format = bytestream_get_le16(&header); + + switch (wave_format) { + case WAVE_FORMAT_PCM: +@@ -233,11 +243,11 @@ + return -1; + } + +- avctx->channels = get_le16(&hb); +- avctx->sample_rate = get_le32(&hb); +- avctx->bit_rate = get_le32(&hb) * 8; +- avctx->block_align = get_le16(&hb); +- avctx->bits_per_coded_sample = get_le16(&hb); ++ header += 2; // skip channels (already got from shorten header) ++ avctx->sample_rate = bytestream_get_le32(&header); ++ header += 4; // skip bit rate (represents original uncompressed bit rate) ++ header += 2; // skip block align (not needed) ++ avctx->bits_per_coded_sample = bytestream_get_le16(&header); + + if (avctx->bits_per_coded_sample != 16) { + av_log(avctx, AV_LOG_ERROR, "unsupported number of bits per sample\n"); +@@ -251,258 +261,342 @@ + return 0; + } + +-static int16_t * interleave_buffer(int16_t *samples, int nchan, int blocksize, int32_t **buffer) { ++static void interleave_buffer(int16_t *samples, int nchan, int blocksize, ++ int32_t **buffer) ++{ + int i, chan; + for (i=0; icoeffs; ++ int pred_order, sum, qshift, init_sum, i, j; ++ const int *coeffs; + +- for (i=0; igb, LPCQUANT); ++ if (command == FN_QLPC) { ++ /* read/validate prediction order */ ++ pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); ++ if (pred_order > s->nwrap) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid pred_order %d\n", pred_order); ++ return AVERROR(EINVAL); ++ } ++ /* read LPC coefficients */ ++ for (i=0; icoeffs[i] = get_sr_golomb_shorten(&s->gb, LPCQUANT); ++ coeffs = s->coeffs; ++ ++ qshift = LPCQUANT; ++ } else { ++ /* fixed LPC coeffs */ ++ pred_order = command; ++ coeffs = fixed_coeffs[pred_order-1]; ++ qshift = 0; ++ } ++ ++ /* subtract offset from previous samples to use in prediction */ ++ if (command == FN_QLPC && coffset) ++ for (i = -pred_order; i < 0; i++) ++ s->decoded[channel][i] -= coffset; + ++ /* decode residual and do LPC prediction */ ++ init_sum = pred_order ? (command == FN_QLPC ? s->lpcqoffset : 0) : coffset; + for (i=0; i < s->blocksize; i++) { +- sum = s->lpcqoffset; ++ sum = init_sum; + for (j=0; jdecoded[channel][i-j-1]; +- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> LPCQUANT); ++ s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + (sum >> qshift); + } ++ ++ /* add offset to current samples */ ++ if (command == FN_QLPC && coffset) ++ for (i = 0; i < s->blocksize; i++) ++ s->decoded[channel][i] += coffset; ++ ++ return 0; + } + ++static int read_header(ShortenContext *s) ++{ ++ int i, ret; ++ int maxnlpc = 0; ++ /* shorten signature */ ++ if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { ++ av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); ++ return -1; ++ } ++ ++ s->lpcqoffset = 0; ++ s->blocksize = DEFAULT_BLOCK_SIZE; ++ s->nmean = -1; ++ s->version = get_bits(&s->gb, 8); ++ s->internal_ftype = get_uint(s, TYPESIZE); ++ ++ s->channels = get_uint(s, CHANSIZE); ++ if (s->channels > MAX_CHANNELS) { ++ av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); ++ return -1; ++ } ++ s->avctx->channels = s->channels; ++ ++ /* get blocksize if version > 0 */ ++ if (s->version > 0) { ++ int skip_bytes, blocksize; ++ ++ blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); ++ if (!blocksize || blocksize > MAX_BLOCKSIZE) { ++ av_log(s->avctx, AV_LOG_ERROR, "invalid or unsupported block size: %d\n", ++ blocksize); ++ return AVERROR(EINVAL); ++ } ++ s->blocksize = blocksize; ++ ++ maxnlpc = get_uint(s, LPCQSIZE); ++ s->nmean = get_uint(s, 0); + +-static int shorten_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++ skip_bytes = get_uint(s, NSKIPSIZE); ++ for (i=0; igb, 8); ++ } ++ } ++ s->nwrap = FFMAX(NWRAP, maxnlpc); ++ ++ if ((ret = allocate_buffers(s)) < 0) ++ return ret; ++ ++ if ((ret = init_offset(s)) < 0) ++ return ret; ++ ++ if (s->version > 1) ++ s->lpcqoffset = V2LPCQOFFSET; ++ ++ if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { ++ av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); ++ return -1; ++ } ++ ++ s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); ++ if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { ++ av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); ++ return -1; ++ } ++ ++ for (i=0; iheader_size; i++) ++ s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); ++ ++ if (decode_wave_header(s->avctx, s->header, s->header_size) < 0) ++ return -1; ++ ++ s->cur_chan = 0; ++ s->bitshift = 0; ++ ++ s->got_header = 1; ++ ++ return 0; ++} ++ ++static int shorten_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + ShortenContext *s = avctx->priv_data; + int i, input_buf_size = 0; +- int16_t *samples = data; ++ int ret; ++ ++ /* allocate internal bitstream buffer */ + if(s->max_framesize == 0){ ++ void *tmp_ptr; + s->max_framesize= 1024; // should hopefully be enough for the first header +- s->bitstream= av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, s->max_framesize); ++ tmp_ptr = av_fast_realloc(s->bitstream, &s->allocated_bitstream_size, ++ s->max_framesize); ++ if (!tmp_ptr) { ++ av_log(avctx, AV_LOG_ERROR, "error allocating bitstream buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ s->bitstream = tmp_ptr; + } + ++ /* append current packet data to bitstream buffer */ + if(1 && s->max_framesize){//FIXME truncated + buf_size= FFMIN(buf_size, s->max_framesize - s->bitstream_size); + input_buf_size= buf_size; + + if(s->bitstream_index + s->bitstream_size + buf_size > s->allocated_bitstream_size){ +- // printf("memmove\n"); + memmove(s->bitstream, &s->bitstream[s->bitstream_index], s->bitstream_size); + s->bitstream_index=0; + } +- memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); ++ if (buf) ++ memcpy(&s->bitstream[s->bitstream_index + s->bitstream_size], buf, buf_size); + buf= &s->bitstream[s->bitstream_index]; + buf_size += s->bitstream_size; + s->bitstream_size= buf_size; + +- if(buf_size < s->max_framesize){ +- //av_dlog(avctx, "wanna more data ... %d\n", buf_size); +- *data_size = 0; ++ /* do not decode until buffer has at least max_framesize bytes or ++ the end of the file has been reached */ ++ if (buf_size < s->max_framesize && avpkt->data) { ++ *got_frame_ptr = 0; + return input_buf_size; + } + } ++ /* init and position bitstream reader */ + init_get_bits(&s->gb, buf, buf_size*8); + skip_bits(&s->gb, s->bitindex); +- if (!s->blocksize) +- { +- int maxnlpc = 0; +- /* shorten signature */ +- if (get_bits_long(&s->gb, 32) != AV_RB32("ajkg")) { +- av_log(s->avctx, AV_LOG_ERROR, "missing shorten magic 'ajkg'\n"); +- return -1; +- } + +- s->lpcqoffset = 0; +- s->blocksize = DEFAULT_BLOCK_SIZE; +- s->channels = 1; +- s->nmean = -1; +- s->version = get_bits(&s->gb, 8); +- s->internal_ftype = get_uint(s, TYPESIZE); +- +- s->channels = get_uint(s, CHANSIZE); +- if (s->channels > MAX_CHANNELS) { +- av_log(s->avctx, AV_LOG_ERROR, "too many channels: %d\n", s->channels); +- return -1; +- } +- +- /* get blocksize if version > 0 */ +- if (s->version > 0) { +- int skip_bytes; +- s->blocksize = get_uint(s, av_log2(DEFAULT_BLOCK_SIZE)); +- maxnlpc = get_uint(s, LPCQSIZE); +- s->nmean = get_uint(s, 0); +- +- skip_bytes = get_uint(s, NSKIPSIZE); +- for (i=0; igb, 8); +- } +- } +- s->nwrap = FFMAX(NWRAP, maxnlpc); +- +- if (allocate_buffers(s)) +- return -1; +- +- init_offset(s); +- +- if (s->version > 1) +- s->lpcqoffset = V2LPCQOFFSET; ++ /* process header or next subblock */ ++ if (!s->got_header) { ++ if ((ret = read_header(s)) < 0) ++ return ret; ++ *got_frame_ptr = 0; ++ goto finish_frame; ++ } ++ ++ /* if quit command was read previously, don't decode anything */ ++ if (s->got_quit_command) { ++ *got_frame_ptr = 0; ++ return avpkt->size; ++ } + +- if (get_ur_golomb_shorten(&s->gb, FNSIZE) != FN_VERBATIM) { +- av_log(s->avctx, AV_LOG_ERROR, "missing verbatim section at beginning of stream\n"); +- return -1; +- } ++ s->cur_chan = 0; ++ while (s->cur_chan < s->channels) { ++ int cmd; ++ int len; + +- s->header_size = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); +- if (s->header_size >= OUT_BUFFER_SIZE || s->header_size < CANONICAL_HEADER_SIZE) { +- av_log(s->avctx, AV_LOG_ERROR, "header is wrong size: %d\n", s->header_size); +- return -1; ++ if (get_bits_left(&s->gb) < 3+FNSIZE) { ++ *got_frame_ptr = 0; ++ break; + } + +- for (i=0; iheader_size; i++) +- s->header[i] = (char)get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); +- +- if (decode_wave_header(avctx, s->header, s->header_size) < 0) +- return -1; +- +- s->cur_chan = 0; +- s->bitshift = 0; +- } +- else +- { +- int cmd; +- int len; + cmd = get_ur_golomb_shorten(&s->gb, FNSIZE); +- switch (cmd) { +- case FN_ZERO: +- case FN_DIFF0: +- case FN_DIFF1: +- case FN_DIFF2: +- case FN_DIFF3: +- case FN_QLPC: +- { +- int residual_size = 0; +- int channel = s->cur_chan; +- int32_t coffset; +- if (cmd != FN_ZERO) { +- residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); +- /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ +- if (s->version == 0) +- residual_size--; +- } + +- if (s->nmean == 0) +- coffset = s->offset[channel][0]; +- else { +- int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; +- for (i=0; inmean; i++) +- sum += s->offset[channel][i]; +- coffset = sum / s->nmean; +- if (s->version >= 2) +- coffset >>= FFMIN(1, s->bitshift); +- } +- switch (cmd) { +- case FN_ZERO: +- for (i=0; iblocksize; i++) +- s->decoded[channel][i] = 0; +- break; +- case FN_DIFF0: +- for (i=0; iblocksize; i++) +- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + coffset; +- break; +- case FN_DIFF1: +- for (i=0; iblocksize; i++) +- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + s->decoded[channel][i - 1]; +- break; +- case FN_DIFF2: +- for (i=0; iblocksize; i++) +- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 2*s->decoded[channel][i-1] +- - s->decoded[channel][i-2]; +- break; +- case FN_DIFF3: +- for (i=0; iblocksize; i++) +- s->decoded[channel][i] = get_sr_golomb_shorten(&s->gb, residual_size) + 3*s->decoded[channel][i-1] +- - 3*s->decoded[channel][i-2] +- + s->decoded[channel][i-3]; +- break; +- case FN_QLPC: +- { +- int pred_order = get_ur_golomb_shorten(&s->gb, LPCQSIZE); +- if (pred_order > s->nwrap) { +- av_log(avctx, AV_LOG_ERROR, +- "invalid pred_order %d\n", +- pred_order); +- return -1; +- } +- for (i=0; idecoded[channel][i - pred_order] -= coffset; +- decode_subframe_lpc(s, channel, residual_size, pred_order); +- if (coffset != 0) +- for (i=0; i < s->blocksize; i++) +- s->decoded[channel][i] += coffset; +- } ++ if (cmd > FN_VERBATIM) { ++ av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); ++ *got_frame_ptr = 0; ++ break; ++ } ++ ++ if (!is_audio_command[cmd]) { ++ /* process non-audio command */ ++ switch (cmd) { ++ case FN_VERBATIM: ++ len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); ++ while (len--) { ++ get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); + } +- if (s->nmean > 0) { +- int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; +- for (i=0; iblocksize; i++) +- sum += s->decoded[channel][i]; +- +- for (i=1; inmean; i++) +- s->offset[channel][i-1] = s->offset[channel][i]; +- +- if (s->version < 2) +- s->offset[channel][s->nmean - 1] = sum / s->blocksize; +- else +- s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; ++ break; ++ case FN_BITSHIFT: ++ s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); ++ break; ++ case FN_BLOCKSIZE: { ++ int blocksize = get_uint(s, av_log2(s->blocksize)); ++ if (blocksize > s->blocksize) { ++ av_log(avctx, AV_LOG_ERROR, "Increasing block size is not supported\n"); ++ return AVERROR_PATCHWELCOME; + } +- for (i=-s->nwrap; i<0; i++) +- s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; +- +- fix_bitshift(s, s->decoded[channel]); +- +- s->cur_chan++; +- if (s->cur_chan == s->channels) { +- samples = interleave_buffer(samples, s->channels, s->blocksize, s->decoded); +- s->cur_chan = 0; +- goto frame_done; ++ if (!blocksize || blocksize > MAX_BLOCKSIZE) { ++ av_log(avctx, AV_LOG_ERROR, "invalid or unsupported " ++ "block size: %d\n", blocksize); ++ return AVERROR(EINVAL); + } ++ s->blocksize = blocksize; + break; + } ++ case FN_QUIT: ++ s->got_quit_command = 1; ++ break; ++ } ++ if (cmd == FN_BLOCKSIZE || cmd == FN_QUIT) { ++ *got_frame_ptr = 0; + break; +- case FN_VERBATIM: +- len = get_ur_golomb_shorten(&s->gb, VERBATIM_CKSIZE_SIZE); +- while (len--) { +- get_ur_golomb_shorten(&s->gb, VERBATIM_BYTE_SIZE); ++ } ++ } else { ++ /* process audio command */ ++ int residual_size = 0; ++ int channel = s->cur_chan; ++ int32_t coffset; ++ ++ /* get Rice code for residual decoding */ ++ if (cmd != FN_ZERO) { ++ residual_size = get_ur_golomb_shorten(&s->gb, ENERGYSIZE); ++ /* this is a hack as version 0 differed in defintion of get_sr_golomb_shorten */ ++ if (s->version == 0) ++ residual_size--; ++ } ++ ++ /* calculate sample offset using means from previous blocks */ ++ if (s->nmean == 0) ++ coffset = s->offset[channel][0]; ++ else { ++ int32_t sum = (s->version < 2) ? 0 : s->nmean / 2; ++ for (i=0; inmean; i++) ++ sum += s->offset[channel][i]; ++ coffset = sum / s->nmean; ++ if (s->version >= 2) ++ coffset >>= FFMIN(1, s->bitshift); ++ } ++ ++ /* decode samples for this channel */ ++ if (cmd == FN_ZERO) { ++ for (i=0; iblocksize; i++) ++ s->decoded[channel][i] = 0; ++ } else { ++ if ((ret = decode_subframe_lpc(s, cmd, channel, residual_size, coffset)) < 0) ++ return ret; ++ } ++ ++ /* update means with info from the current block */ ++ if (s->nmean > 0) { ++ int32_t sum = (s->version < 2) ? 0 : s->blocksize / 2; ++ for (i=0; iblocksize; i++) ++ sum += s->decoded[channel][i]; ++ ++ for (i=1; inmean; i++) ++ s->offset[channel][i-1] = s->offset[channel][i]; ++ ++ if (s->version < 2) ++ s->offset[channel][s->nmean - 1] = sum / s->blocksize; ++ else ++ s->offset[channel][s->nmean - 1] = (sum / s->blocksize) << s->bitshift; ++ } ++ ++ /* copy wrap samples for use with next block */ ++ for (i=-s->nwrap; i<0; i++) ++ s->decoded[channel][i] = s->decoded[channel][i + s->blocksize]; ++ ++ /* shift samples to add in unused zero bits which were removed ++ during encoding */ ++ fix_bitshift(s, s->decoded[channel]); ++ ++ /* if this is the last channel in the block, output the samples */ ++ s->cur_chan++; ++ if (s->cur_chan == s->channels) { ++ /* get output buffer */ ++ s->frame.nb_samples = s->blocksize; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } +- break; +- case FN_BITSHIFT: +- s->bitshift = get_ur_golomb_shorten(&s->gb, BITSHIFTSIZE); +- break; +- case FN_BLOCKSIZE: +- s->blocksize = get_uint(s, av_log2(s->blocksize)); +- break; +- case FN_QUIT: +- *data_size = 0; +- return buf_size; +- break; +- default: +- av_log(avctx, AV_LOG_ERROR, "unknown shorten function %d\n", cmd); +- return -1; +- break; ++ /* interleave output */ ++ interleave_buffer((int16_t *)s->frame.data[0], s->channels, ++ s->blocksize, s->decoded); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ } + } + } +-frame_done: +- *data_size = (int8_t *)samples - (int8_t *)data; ++ if (s->cur_chan < s->channels) ++ *got_frame_ptr = 0; + +- // s->last_blocksize = s->blocksize; ++finish_frame: + s->bitindex = get_bits_count(&s->gb) - 8*((get_bits_count(&s->gb))/8); + i= (get_bits_count(&s->gb))/8; + if (i > buf_size) { +@@ -525,31 +619,24 @@ + int i; + + for (i = 0; i < s->channels; i++) { +- s->decoded[i] -= s->nwrap; +- av_freep(&s->decoded[i]); ++ s->decoded[i] = NULL; ++ av_freep(&s->decoded_base[i]); + av_freep(&s->offset[i]); + } + av_freep(&s->bitstream); + av_freep(&s->coeffs); +- return 0; +-} + +-static void shorten_flush(AVCodecContext *avctx){ +- ShortenContext *s = avctx->priv_data; +- +- s->bitstream_size= +- s->bitstream_index= 0; ++ return 0; + } + + AVCodec ff_shorten_decoder = { +- "shorten", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SHORTEN, +- sizeof(ShortenContext), +- shorten_decode_init, +- NULL, +- shorten_decode_close, +- shorten_decode_frame, +- .flush= shorten_flush, ++ .name = "shorten", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SHORTEN, ++ .priv_data_size = sizeof(ShortenContext), ++ .init = shorten_decode_init, ++ .close = shorten_decode_close, ++ .decode = shorten_decode_frame, ++ .capabilities = CODEC_CAP_DELAY | CODEC_CAP_DR1, + .long_name= NULL_IF_CONFIG_SMALL("Shorten"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct.c 2012-05-14 14:08:54.210337487 +0200 +@@ -25,378 +25,19 @@ + * simpleidct in C. + */ + +-/* +- based upon some outcommented c code from mpeg2dec (idct_mmx.c +- written by Aaron Holtzman ) +- */ ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "dsputil.h" + #include "mathops.h" + #include "simple_idct.h" + +-#if 0 +-#define W1 2841 /* 2048*sqrt (2)*cos (1*pi/16) */ +-#define W2 2676 /* 2048*sqrt (2)*cos (2*pi/16) */ +-#define W3 2408 /* 2048*sqrt (2)*cos (3*pi/16) */ +-#define W4 2048 /* 2048*sqrt (2)*cos (4*pi/16) */ +-#define W5 1609 /* 2048*sqrt (2)*cos (5*pi/16) */ +-#define W6 1108 /* 2048*sqrt (2)*cos (6*pi/16) */ +-#define W7 565 /* 2048*sqrt (2)*cos (7*pi/16) */ +-#define ROW_SHIFT 8 +-#define COL_SHIFT 17 +-#else +-#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#define ROW_SHIFT 11 +-#define COL_SHIFT 20 // 6 +-#endif +- +-static inline void idctRowCondDC (DCTELEM * row) +-{ +- int a0, a1, a2, a3, b0, b1, b2, b3; +-#if HAVE_FAST_64BIT +- uint64_t temp; +-#else +- uint32_t temp; +-#endif +- +-#if HAVE_FAST_64BIT +-#if HAVE_BIGENDIAN +-#define ROW0_MASK 0xffff000000000000LL +-#else +-#define ROW0_MASK 0xffffLL +-#endif +- if(sizeof(DCTELEM)==2){ +- if ( ((((uint64_t *)row)[0] & ~ROW0_MASK) | +- ((uint64_t *)row)[1]) == 0) { +- temp = (row[0] << 3) & 0xffff; +- temp += temp << 16; +- temp += temp << 32; +- ((uint64_t *)row)[0] = temp; +- ((uint64_t *)row)[1] = temp; +- return; +- } +- }else{ +- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) { +- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3; +- return; +- } +- } +-#else +- if(sizeof(DCTELEM)==2){ +- if (!(((uint32_t*)row)[1] | +- ((uint32_t*)row)[2] | +- ((uint32_t*)row)[3] | +- row[1])) { +- temp = (row[0] << 3) & 0xffff; +- temp += temp << 16; +- ((uint32_t*)row)[0]=((uint32_t*)row)[1] = +- ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp; +- return; +- } +- }else{ +- if (!(row[1]|row[2]|row[3]|row[4]|row[5]|row[6]|row[7])) { +- row[0]=row[1]=row[2]=row[3]=row[4]=row[5]=row[6]=row[7]= row[0] << 3; +- return; +- } +- } +-#endif +- +- a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1)); +- a1 = a0; +- a2 = a0; +- a3 = a0; +- +- /* no need to optimize : gcc does it */ +- a0 += W2 * row[2]; +- a1 += W6 * row[2]; +- a2 -= W6 * row[2]; +- a3 -= W2 * row[2]; +- +- b0 = MUL16(W1, row[1]); +- MAC16(b0, W3, row[3]); +- b1 = MUL16(W3, row[1]); +- MAC16(b1, -W7, row[3]); +- b2 = MUL16(W5, row[1]); +- MAC16(b2, -W1, row[3]); +- b3 = MUL16(W7, row[1]); +- MAC16(b3, -W5, row[3]); +- +-#if HAVE_FAST_64BIT +- temp = ((uint64_t*)row)[1]; +-#else +- temp = ((uint32_t*)row)[2] | ((uint32_t*)row)[3]; +-#endif +- if (temp != 0) { +- a0 += W4*row[4] + W6*row[6]; +- a1 += - W4*row[4] - W2*row[6]; +- a2 += - W4*row[4] + W2*row[6]; +- a3 += W4*row[4] - W6*row[6]; +- +- MAC16(b0, W5, row[5]); +- MAC16(b0, W7, row[7]); +- +- MAC16(b1, -W1, row[5]); +- MAC16(b1, -W5, row[7]); +- +- MAC16(b2, W7, row[5]); +- MAC16(b2, W3, row[7]); +- +- MAC16(b3, W3, row[5]); +- MAC16(b3, -W1, row[7]); +- } +- +- row[0] = (a0 + b0) >> ROW_SHIFT; +- row[7] = (a0 - b0) >> ROW_SHIFT; +- row[1] = (a1 + b1) >> ROW_SHIFT; +- row[6] = (a1 - b1) >> ROW_SHIFT; +- row[2] = (a2 + b2) >> ROW_SHIFT; +- row[5] = (a2 - b2) >> ROW_SHIFT; +- row[3] = (a3 + b3) >> ROW_SHIFT; +- row[4] = (a3 - b3) >> ROW_SHIFT; +-} +- +-static inline void idctSparseColPut (uint8_t *dest, int line_size, +- DCTELEM * col) +-{ +- int a0, a1, a2, a3, b0, b1, b2, b3; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- /* XXX: I did that only to give same values as previous code */ +- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); +- a1 = a0; +- a2 = a0; +- a3 = a0; +- +- a0 += + W2*col[8*2]; +- a1 += + W6*col[8*2]; +- a2 += - W6*col[8*2]; +- a3 += - W2*col[8*2]; +- +- b0 = MUL16(W1, col[8*1]); +- b1 = MUL16(W3, col[8*1]); +- b2 = MUL16(W5, col[8*1]); +- b3 = MUL16(W7, col[8*1]); +- +- MAC16(b0, + W3, col[8*3]); +- MAC16(b1, - W7, col[8*3]); +- MAC16(b2, - W1, col[8*3]); +- MAC16(b3, - W5, col[8*3]); +- +- if(col[8*4]){ +- a0 += + W4*col[8*4]; +- a1 += - W4*col[8*4]; +- a2 += - W4*col[8*4]; +- a3 += + W4*col[8*4]; +- } +- +- if (col[8*5]) { +- MAC16(b0, + W5, col[8*5]); +- MAC16(b1, - W1, col[8*5]); +- MAC16(b2, + W7, col[8*5]); +- MAC16(b3, + W3, col[8*5]); +- } +- +- if(col[8*6]){ +- a0 += + W6*col[8*6]; +- a1 += - W2*col[8*6]; +- a2 += + W2*col[8*6]; +- a3 += - W6*col[8*6]; +- } +- +- if (col[8*7]) { +- MAC16(b0, + W7, col[8*7]); +- MAC16(b1, - W5, col[8*7]); +- MAC16(b2, + W3, col[8*7]); +- MAC16(b3, - W1, col[8*7]); +- } +- +- dest[0] = cm[(a0 + b0) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a1 + b1) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a2 + b2) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a3 + b3) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a3 - b3) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a2 - b2) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a1 - b1) >> COL_SHIFT]; +- dest += line_size; +- dest[0] = cm[(a0 - b0) >> COL_SHIFT]; +-} +- +-static inline void idctSparseColAdd (uint8_t *dest, int line_size, +- DCTELEM * col) +-{ +- int a0, a1, a2, a3, b0, b1, b2, b3; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- +- /* XXX: I did that only to give same values as previous code */ +- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); +- a1 = a0; +- a2 = a0; +- a3 = a0; +- +- a0 += + W2*col[8*2]; +- a1 += + W6*col[8*2]; +- a2 += - W6*col[8*2]; +- a3 += - W2*col[8*2]; +- +- b0 = MUL16(W1, col[8*1]); +- b1 = MUL16(W3, col[8*1]); +- b2 = MUL16(W5, col[8*1]); +- b3 = MUL16(W7, col[8*1]); +- +- MAC16(b0, + W3, col[8*3]); +- MAC16(b1, - W7, col[8*3]); +- MAC16(b2, - W1, col[8*3]); +- MAC16(b3, - W5, col[8*3]); +- +- if(col[8*4]){ +- a0 += + W4*col[8*4]; +- a1 += - W4*col[8*4]; +- a2 += - W4*col[8*4]; +- a3 += + W4*col[8*4]; +- } +- +- if (col[8*5]) { +- MAC16(b0, + W5, col[8*5]); +- MAC16(b1, - W1, col[8*5]); +- MAC16(b2, + W7, col[8*5]); +- MAC16(b3, + W3, col[8*5]); +- } +- +- if(col[8*6]){ +- a0 += + W6*col[8*6]; +- a1 += - W2*col[8*6]; +- a2 += + W2*col[8*6]; +- a3 += - W6*col[8*6]; +- } +- +- if (col[8*7]) { +- MAC16(b0, + W7, col[8*7]); +- MAC16(b1, - W5, col[8*7]); +- MAC16(b2, + W3, col[8*7]); +- MAC16(b3, - W1, col[8*7]); +- } +- +- dest[0] = cm[dest[0] + ((a0 + b0) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a1 + b1) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a2 + b2) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a3 + b3) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a3 - b3) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a2 - b2) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a1 - b1) >> COL_SHIFT)]; +- dest += line_size; +- dest[0] = cm[dest[0] + ((a0 - b0) >> COL_SHIFT)]; +-} +- +-static inline void idctSparseCol (DCTELEM * col) +-{ +- int a0, a1, a2, a3, b0, b1, b2, b3; +- +- /* XXX: I did that only to give same values as previous code */ +- a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); +- a1 = a0; +- a2 = a0; +- a3 = a0; +- +- a0 += + W2*col[8*2]; +- a1 += + W6*col[8*2]; +- a2 += - W6*col[8*2]; +- a3 += - W2*col[8*2]; +- +- b0 = MUL16(W1, col[8*1]); +- b1 = MUL16(W3, col[8*1]); +- b2 = MUL16(W5, col[8*1]); +- b3 = MUL16(W7, col[8*1]); +- +- MAC16(b0, + W3, col[8*3]); +- MAC16(b1, - W7, col[8*3]); +- MAC16(b2, - W1, col[8*3]); +- MAC16(b3, - W5, col[8*3]); +- +- if(col[8*4]){ +- a0 += + W4*col[8*4]; +- a1 += - W4*col[8*4]; +- a2 += - W4*col[8*4]; +- a3 += + W4*col[8*4]; +- } +- +- if (col[8*5]) { +- MAC16(b0, + W5, col[8*5]); +- MAC16(b1, - W1, col[8*5]); +- MAC16(b2, + W7, col[8*5]); +- MAC16(b3, + W3, col[8*5]); +- } +- +- if(col[8*6]){ +- a0 += + W6*col[8*6]; +- a1 += - W2*col[8*6]; +- a2 += + W2*col[8*6]; +- a3 += - W6*col[8*6]; +- } +- +- if (col[8*7]) { +- MAC16(b0, + W7, col[8*7]); +- MAC16(b1, - W5, col[8*7]); +- MAC16(b2, + W3, col[8*7]); +- MAC16(b3, - W1, col[8*7]); +- } +- +- col[0 ] = ((a0 + b0) >> COL_SHIFT); +- col[8 ] = ((a1 + b1) >> COL_SHIFT); +- col[16] = ((a2 + b2) >> COL_SHIFT); +- col[24] = ((a3 + b3) >> COL_SHIFT); +- col[32] = ((a3 - b3) >> COL_SHIFT); +- col[40] = ((a2 - b2) >> COL_SHIFT); +- col[48] = ((a1 - b1) >> COL_SHIFT); +- col[56] = ((a0 - b0) >> COL_SHIFT); +-} +- +-void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block) +-{ +- int i; +- for(i=0; i<8; i++) +- idctRowCondDC(block + i*8); +- +- for(i=0; i<8; i++) +- idctSparseColPut(dest + i, line_size, block + i); +-} +- +-void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block) +-{ +- int i; +- for(i=0; i<8; i++) +- idctRowCondDC(block + i*8); +- +- for(i=0; i<8; i++) +- idctSparseColAdd(dest + i, line_size, block + i); +-} +- +-void ff_simple_idct(DCTELEM *block) +-{ +- int i; +- for(i=0; i<8; i++) +- idctRowCondDC(block + i*8); +- +- for(i=0; i<8; i++) +- idctSparseCol(block + i); +-} ++#define BIT_DEPTH 8 ++#include "simple_idct_template.c" ++#undef BIT_DEPTH ++ ++#define BIT_DEPTH 10 ++#include "simple_idct_template.c" ++#undef BIT_DEPTH + + /* 2x4x8 idct */ + +@@ -412,7 +53,6 @@ + static inline void idct4col_put(uint8_t *dest, int line_size, const DCTELEM *col) + { + int c0, c1, c2, c3, a0, a1, a2, a3; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + a0 = col[8*0]; + a1 = col[8*2]; +@@ -422,13 +62,13 @@ + c2 = ((a0 - a2) << (CN_SHIFT - 1)) + (1 << (C_SHIFT - 1)); + c1 = a1 * C1 + a3 * C2; + c3 = a1 * C2 - a3 * C1; +- dest[0] = cm[(c0 + c1) >> C_SHIFT]; ++ dest[0] = av_clip_uint8((c0 + c1) >> C_SHIFT); + dest += line_size; +- dest[0] = cm[(c2 + c3) >> C_SHIFT]; ++ dest[0] = av_clip_uint8((c2 + c3) >> C_SHIFT); + dest += line_size; +- dest[0] = cm[(c2 - c3) >> C_SHIFT]; ++ dest[0] = av_clip_uint8((c2 - c3) >> C_SHIFT); + dest += line_size; +- dest[0] = cm[(c0 - c1) >> C_SHIFT]; ++ dest[0] = av_clip_uint8((c0 - c1) >> C_SHIFT); + } + + #define BF(k) \ +@@ -467,7 +107,7 @@ + + /* IDCT8 on each line */ + for(i=0; i<8; i++) { +- idctRowCondDC(block + i*8); ++ idctRowCondDC_8(block + i*8, 0); + } + + /* IDCT4 and store */ +@@ -492,7 +132,6 @@ + static inline void idct4col_add(uint8_t *dest, int line_size, const DCTELEM *col) + { + int c0, c1, c2, c3, a0, a1, a2, a3; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + a0 = col[8*0]; + a1 = col[8*1]; +@@ -502,13 +141,13 @@ + c2 = (a0 - a2)*C3 + (1 << (C_SHIFT - 1)); + c1 = a1 * C1 + a3 * C2; + c3 = a1 * C2 - a3 * C1; +- dest[0] = cm[dest[0] + ((c0 + c1) >> C_SHIFT)]; ++ dest[0] = av_clip_uint8(dest[0] + ((c0 + c1) >> C_SHIFT)); + dest += line_size; +- dest[0] = cm[dest[0] + ((c2 + c3) >> C_SHIFT)]; ++ dest[0] = av_clip_uint8(dest[0] + ((c2 + c3) >> C_SHIFT)); + dest += line_size; +- dest[0] = cm[dest[0] + ((c2 - c3) >> C_SHIFT)]; ++ dest[0] = av_clip_uint8(dest[0] + ((c2 - c3) >> C_SHIFT)); + dest += line_size; +- dest[0] = cm[dest[0] + ((c0 - c1) >> C_SHIFT)]; ++ dest[0] = av_clip_uint8(dest[0] + ((c0 - c1) >> C_SHIFT)); + } + + #define RN_SHIFT 15 +@@ -520,7 +159,6 @@ + static inline void idct4row(DCTELEM *row) + { + int c0, c1, c2, c3, a0, a1, a2, a3; +- //const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + a0 = row[0]; + a1 = row[1]; +@@ -542,7 +180,7 @@ + + /* IDCT8 on each line */ + for(i=0; i<4; i++) { +- idctRowCondDC(block + i*8); ++ idctRowCondDC_8(block + i*8, 0); + } + + /* IDCT4 and store */ +@@ -562,7 +200,7 @@ + + /* IDCT8 and store */ + for(i=0; i<4; i++){ +- idctSparseColAdd(dest + i, line_size, block + i); ++ idctSparseColAdd_8(dest + i, line_size, block + i); + } + } + +@@ -580,3 +218,17 @@ + idct4col_add(dest + i, line_size, block + i); + } + } ++ ++void ff_prores_idct(DCTELEM *block, const int16_t *qmat) ++{ ++ int i; ++ ++ for (i = 0; i < 64; i++) ++ block[i] *= qmat[i]; ++ ++ for (i = 0; i < 8; i++) ++ idctRowCondDC_10(block + i*8, 2); ++ ++ for (i = 0; i < 8; i++) ++ idctSparseCol_10(block + i); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct.h 2012-05-14 14:08:54.211337507 +0200 +@@ -31,12 +31,23 @@ + #include + #include "dsputil.h" + +-void ff_simple_idct_put(uint8_t *dest, int line_size, DCTELEM *block); +-void ff_simple_idct_add(uint8_t *dest, int line_size, DCTELEM *block); ++void ff_simple_idct_put_8(uint8_t *dest, int line_size, DCTELEM *block); ++void ff_simple_idct_add_8(uint8_t *dest, int line_size, DCTELEM *block); ++void ff_simple_idct_8(DCTELEM *block); ++ ++void ff_simple_idct_put_10(uint8_t *dest, int line_size, DCTELEM *block); ++void ff_simple_idct_add_10(uint8_t *dest, int line_size, DCTELEM *block); ++void ff_simple_idct_10(DCTELEM *block); ++/** ++ * Special version of ff_simple_idct_10() which does dequantization ++ * and scales by a factor of 2 more between the two IDCTs to account ++ * for larger scale of input coefficients. ++ */ ++void ff_prores_idct(DCTELEM *block, const int16_t *qmat); ++ + void ff_simple_idct_mmx(int16_t *block); + void ff_simple_idct_add_mmx(uint8_t *dest, int line_size, int16_t *block); + void ff_simple_idct_put_mmx(uint8_t *dest, int line_size, int16_t *block); +-void ff_simple_idct(DCTELEM *block); + + void ff_simple_idct248_put(uint8_t *dest, int line_size, DCTELEM *block); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/simple_idct_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/simple_idct_template.c 2012-05-14 14:08:54.212337527 +0200 +@@ -0,0 +1,324 @@ ++/* ++ * Simple IDCT ++ * ++ * Copyright (c) 2001 Michael Niedermayer ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * simpleidct in C. ++ */ ++ ++/* ++ based upon some outcommented c code from mpeg2dec (idct_mmx.c ++ written by Aaron Holtzman ) ++ */ ++ ++#include "bit_depth_template.c" ++ ++#undef W1 ++#undef W2 ++#undef W3 ++#undef W4 ++#undef W5 ++#undef W6 ++#undef W7 ++#undef ROW_SHIFT ++#undef COL_SHIFT ++#undef DC_SHIFT ++#undef MUL ++#undef MAC ++ ++#if BIT_DEPTH == 8 ++ ++#define W1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++#define W7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 ++ ++#define ROW_SHIFT 11 ++#define COL_SHIFT 20 ++#define DC_SHIFT 3 ++ ++#define MUL(a, b) MUL16(a, b) ++#define MAC(a, b, c) MAC16(a, b, c) ++ ++#elif BIT_DEPTH == 10 ++ ++#define W1 90901 ++#define W2 85627 ++#define W3 77062 ++#define W4 65535 ++#define W5 51491 ++#define W6 35468 ++#define W7 18081 ++ ++#define ROW_SHIFT 15 ++#define COL_SHIFT 20 ++#define DC_SHIFT 1 ++ ++#define MUL(a, b) ((a) * (b)) ++#define MAC(a, b, c) ((a) += (b) * (c)) ++ ++#else ++ ++#error "Unsupported bitdepth" ++ ++#endif ++ ++static inline void FUNC(idctRowCondDC)(DCTELEM *row, int extra_shift) ++{ ++ int a0, a1, a2, a3, b0, b1, b2, b3; ++ ++#if HAVE_FAST_64BIT ++#define ROW0_MASK (0xffffLL << 48 * HAVE_BIGENDIAN) ++ if (((((uint64_t *)row)[0] & ~ROW0_MASK) | ((uint64_t *)row)[1]) == 0) { ++ uint64_t temp; ++ if (DC_SHIFT - extra_shift > 0) { ++ temp = (row[0] << (DC_SHIFT - extra_shift)) & 0xffff; ++ } else { ++ temp = (row[0] >> (extra_shift - DC_SHIFT)) & 0xffff; ++ } ++ temp += temp << 16; ++ temp += temp << 32; ++ ((uint64_t *)row)[0] = temp; ++ ((uint64_t *)row)[1] = temp; ++ return; ++ } ++#else ++ if (!(((uint32_t*)row)[1] | ++ ((uint32_t*)row)[2] | ++ ((uint32_t*)row)[3] | ++ row[1])) { ++ uint32_t temp; ++ if (DC_SHIFT - extra_shift > 0) { ++ temp = (row[0] << (DC_SHIFT - extra_shift)) & 0xffff; ++ } else { ++ temp = (row[0] >> (extra_shift - DC_SHIFT)) & 0xffff; ++ } ++ temp += temp << 16; ++ ((uint32_t*)row)[0]=((uint32_t*)row)[1] = ++ ((uint32_t*)row)[2]=((uint32_t*)row)[3] = temp; ++ return; ++ } ++#endif ++ ++ a0 = (W4 * row[0]) + (1 << (ROW_SHIFT - 1)); ++ a1 = a0; ++ a2 = a0; ++ a3 = a0; ++ ++ a0 += W2 * row[2]; ++ a1 += W6 * row[2]; ++ a2 -= W6 * row[2]; ++ a3 -= W2 * row[2]; ++ ++ b0 = MUL(W1, row[1]); ++ MAC(b0, W3, row[3]); ++ b1 = MUL(W3, row[1]); ++ MAC(b1, -W7, row[3]); ++ b2 = MUL(W5, row[1]); ++ MAC(b2, -W1, row[3]); ++ b3 = MUL(W7, row[1]); ++ MAC(b3, -W5, row[3]); ++ ++ if (AV_RN64A(row + 4)) { ++ a0 += W4*row[4] + W6*row[6]; ++ a1 += - W4*row[4] - W2*row[6]; ++ a2 += - W4*row[4] + W2*row[6]; ++ a3 += W4*row[4] - W6*row[6]; ++ ++ MAC(b0, W5, row[5]); ++ MAC(b0, W7, row[7]); ++ ++ MAC(b1, -W1, row[5]); ++ MAC(b1, -W5, row[7]); ++ ++ MAC(b2, W7, row[5]); ++ MAC(b2, W3, row[7]); ++ ++ MAC(b3, W3, row[5]); ++ MAC(b3, -W1, row[7]); ++ } ++ ++ row[0] = (a0 + b0) >> (ROW_SHIFT + extra_shift); ++ row[7] = (a0 - b0) >> (ROW_SHIFT + extra_shift); ++ row[1] = (a1 + b1) >> (ROW_SHIFT + extra_shift); ++ row[6] = (a1 - b1) >> (ROW_SHIFT + extra_shift); ++ row[2] = (a2 + b2) >> (ROW_SHIFT + extra_shift); ++ row[5] = (a2 - b2) >> (ROW_SHIFT + extra_shift); ++ row[3] = (a3 + b3) >> (ROW_SHIFT + extra_shift); ++ row[4] = (a3 - b3) >> (ROW_SHIFT + extra_shift); ++} ++ ++#define IDCT_COLS do { \ ++ a0 = W4 * (col[8*0] + ((1<<(COL_SHIFT-1))/W4)); \ ++ a1 = a0; \ ++ a2 = a0; \ ++ a3 = a0; \ ++ \ ++ a0 += W2*col[8*2]; \ ++ a1 += W6*col[8*2]; \ ++ a2 += -W6*col[8*2]; \ ++ a3 += -W2*col[8*2]; \ ++ \ ++ b0 = MUL(W1, col[8*1]); \ ++ b1 = MUL(W3, col[8*1]); \ ++ b2 = MUL(W5, col[8*1]); \ ++ b3 = MUL(W7, col[8*1]); \ ++ \ ++ MAC(b0, W3, col[8*3]); \ ++ MAC(b1, -W7, col[8*3]); \ ++ MAC(b2, -W1, col[8*3]); \ ++ MAC(b3, -W5, col[8*3]); \ ++ \ ++ if (col[8*4]) { \ ++ a0 += W4*col[8*4]; \ ++ a1 += -W4*col[8*4]; \ ++ a2 += -W4*col[8*4]; \ ++ a3 += W4*col[8*4]; \ ++ } \ ++ \ ++ if (col[8*5]) { \ ++ MAC(b0, W5, col[8*5]); \ ++ MAC(b1, -W1, col[8*5]); \ ++ MAC(b2, W7, col[8*5]); \ ++ MAC(b3, W3, col[8*5]); \ ++ } \ ++ \ ++ if (col[8*6]) { \ ++ a0 += W6*col[8*6]; \ ++ a1 += -W2*col[8*6]; \ ++ a2 += W2*col[8*6]; \ ++ a3 += -W6*col[8*6]; \ ++ } \ ++ \ ++ if (col[8*7]) { \ ++ MAC(b0, W7, col[8*7]); \ ++ MAC(b1, -W5, col[8*7]); \ ++ MAC(b2, W3, col[8*7]); \ ++ MAC(b3, -W1, col[8*7]); \ ++ } \ ++ } while (0) ++ ++static inline void FUNC(idctSparseColPut)(pixel *dest, int line_size, ++ DCTELEM *col) ++{ ++ int a0, a1, a2, a3, b0, b1, b2, b3; ++ ++ IDCT_COLS; ++ ++ dest[0] = av_clip_pixel((a0 + b0) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a1 + b1) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a2 + b2) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a3 + b3) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a3 - b3) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a2 - b2) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a1 - b1) >> COL_SHIFT); ++ dest += line_size; ++ dest[0] = av_clip_pixel((a0 - b0) >> COL_SHIFT); ++} ++ ++static inline void FUNC(idctSparseColAdd)(pixel *dest, int line_size, ++ DCTELEM *col) ++{ ++ int a0, a1, a2, a3, b0, b1, b2, b3; ++ ++ IDCT_COLS; ++ ++ dest[0] = av_clip_pixel(dest[0] + ((a0 + b0) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a1 + b1) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a2 + b2) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a3 + b3) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a3 - b3) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a2 - b2) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a1 - b1) >> COL_SHIFT)); ++ dest += line_size; ++ dest[0] = av_clip_pixel(dest[0] + ((a0 - b0) >> COL_SHIFT)); ++} ++ ++static inline void FUNC(idctSparseCol)(DCTELEM *col) ++{ ++ int a0, a1, a2, a3, b0, b1, b2, b3; ++ ++ IDCT_COLS; ++ ++ col[0 ] = ((a0 + b0) >> COL_SHIFT); ++ col[8 ] = ((a1 + b1) >> COL_SHIFT); ++ col[16] = ((a2 + b2) >> COL_SHIFT); ++ col[24] = ((a3 + b3) >> COL_SHIFT); ++ col[32] = ((a3 - b3) >> COL_SHIFT); ++ col[40] = ((a2 - b2) >> COL_SHIFT); ++ col[48] = ((a1 - b1) >> COL_SHIFT); ++ col[56] = ((a0 - b0) >> COL_SHIFT); ++} ++ ++void FUNC(ff_simple_idct_put)(uint8_t *dest_, int line_size, DCTELEM *block) ++{ ++ pixel *dest = (pixel *)dest_; ++ int i; ++ ++ line_size /= sizeof(pixel); ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctRowCondDC)(block + i*8, 0); ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctSparseColPut)(dest + i, line_size, block + i); ++} ++ ++void FUNC(ff_simple_idct_add)(uint8_t *dest_, int line_size, DCTELEM *block) ++{ ++ pixel *dest = (pixel *)dest_; ++ int i; ++ ++ line_size /= sizeof(pixel); ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctRowCondDC)(block + i*8, 0); ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctSparseColAdd)(dest + i, line_size, block + i); ++} ++ ++void FUNC(ff_simple_idct)(DCTELEM *block) ++{ ++ int i; ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctRowCondDC)(block + i*8, 0); ++ ++ for (i = 0; i < 8; i++) ++ FUNC(idctSparseCol)(block + i); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin.c 2012-05-14 14:08:54.212337527 +0200 +@@ -0,0 +1,20 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "sinewin.h" ++#include "sinewin_tablegen.h" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin.h 2012-05-14 14:08:54.213337547 +0200 +@@ -0,0 +1,59 @@ ++/* ++ * Copyright (c) 2008 Robert Swain ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_SINEWIN_H ++#define AVCODEC_SINEWIN_H ++ ++#include "config.h" ++#include "libavutil/mem.h" ++ ++#if CONFIG_HARDCODED_TABLES ++# define SINETABLE_CONST const ++#else ++# define SINETABLE_CONST ++#endif ++ ++#define SINETABLE(size) \ ++ SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size] ++ ++/** ++ * Generate a sine window. ++ * @param window pointer to half window ++ * @param n size of half window ++ */ ++void ff_sine_window_init(float *window, int n); ++ ++/** ++ * initialize the specified entry of ff_sine_windows ++ */ ++void ff_init_ff_sine_windows(int index); ++ ++extern SINETABLE( 32); ++extern SINETABLE( 64); ++extern SINETABLE( 128); ++extern SINETABLE( 256); ++extern SINETABLE( 512); ++extern SINETABLE(1024); ++extern SINETABLE(2048); ++extern SINETABLE(4096); ++ ++extern SINETABLE_CONST float * const ff_sine_windows[13]; ++ ++#endif /* AVCODEC_SINEWIN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin_tablegen.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin_tablegen.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin_tablegen.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin_tablegen.c 2012-05-14 14:08:54.214337567 +0200 +@@ -0,0 +1,49 @@ ++/* ++ * Generate a header file for hardcoded sine windows ++ * ++ * Copyright (c) 2009 Reimar Döffinger ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#define CONFIG_HARDCODED_TABLES 0 ++#define SINETABLE_CONST ++#define SINETABLE(size) \ ++ float ff_sine_##size[size] ++#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) ++#ifndef M_PI ++#define M_PI 3.14159265358979323846 ++#endif ++#include "sinewin_tablegen.h" ++#include "tableprint.h" ++ ++int main(void) ++{ ++ int i; ++ ++ write_fileheader(); ++ ++ for (i = 5; i <= 12; i++) { ++ ff_init_ff_sine_windows(i); ++ printf("SINETABLE(%4i) = {\n", 1 << i); ++ write_float_array(ff_sine_windows[i], 1 << i); ++ printf("};\n"); ++ } ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin_tablegen.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin_tablegen.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sinewin_tablegen.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sinewin_tablegen.h 2012-05-14 14:08:54.214337567 +0200 +@@ -0,0 +1,65 @@ ++/* ++ * Header file for hardcoded sine windows ++ * ++ * Copyright (c) 2009 Reimar Döffinger ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_SINEWIN_TABLEGEN_H ++#define AVCODEC_SINEWIN_TABLEGEN_H ++ ++#include ++// do not use libavutil/libm.h since this is compiled both ++// for the host and the target and config.h is only valid for the target ++#include ++#include "libavutil/attributes.h" ++ ++#if !CONFIG_HARDCODED_TABLES ++SINETABLE( 32); ++SINETABLE( 64); ++SINETABLE( 128); ++SINETABLE( 256); ++SINETABLE( 512); ++SINETABLE(1024); ++SINETABLE(2048); ++SINETABLE(4096); ++#else ++#include "libavcodec/sinewin_tables.h" ++#endif ++ ++SINETABLE_CONST float * const ff_sine_windows[] = { ++ NULL, NULL, NULL, NULL, NULL, // unused ++ ff_sine_32 , ff_sine_64 , ++ ff_sine_128, ff_sine_256, ff_sine_512, ff_sine_1024, ff_sine_2048, ff_sine_4096 ++}; ++ ++// Generate a sine window. ++av_cold void ff_sine_window_init(float *window, int n) { ++ int i; ++ for(i = 0; i < n; i++) ++ window[i] = sinf((i + 0.5) * (M_PI / (2.0 * n))); ++} ++ ++av_cold void ff_init_ff_sine_windows(int index) { ++ assert(index >= 0 && index < FF_ARRAY_ELEMS(ff_sine_windows)); ++#if !CONFIG_HARDCODED_TABLES ++ ff_sine_window_init(ff_sine_windows[index], 1 << index); ++#endif ++} ++ ++#endif /* AVCODEC_SINEWIN_TABLEGEN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sipr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sipr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sipr.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sipr.c 2012-05-14 14:08:54.216337607 +0200 +@@ -23,10 +23,11 @@ + + #include + #include ++#include + + #include "libavutil/mathematics.h" + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "dsputil.h" + +@@ -193,14 +194,16 @@ + { + int i, j; + +- parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits); ++ if (p->ma_predictor_bits) ++ parms->ma_pred_switch = get_bits(pgb, p->ma_predictor_bits); + + for (i = 0; i < 5; i++) + parms->vq_indexes[i] = get_bits(pgb, p->vq_indexes_bits[i]); + + for (i = 0; i < p->subframe_count; i++) { + parms->pitch_delay[i] = get_bits(pgb, p->pitch_delay_bits[i]); +- parms->gp_index[i] = get_bits(pgb, p->gp_index_bits); ++ if (p->gp_index_bits) ++ parms->gp_index[i] = get_bits(pgb, p->gp_index_bits); + + for (j = 0; j < p->number_of_fc_indexes; j++) + parms->fc_indexes[i][j] = get_bits(pgb, p->fc_index_bits[j]); +@@ -461,7 +464,7 @@ + memcpy(ctx->postfilter_syn5k0, ctx->postfilter_syn5k0 + frame_size, + LP_FILTER_ORDER*sizeof(float)); + } +- memcpy(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL, ++ memmove(ctx->excitation, excitation - PITCH_DELAY_MAX - L_INTERPOL, + (PITCH_DELAY_MAX + L_INTERPOL) * sizeof(float)); + + ff_acelp_apply_order_2_transfer_function(out_data, synth, +@@ -477,15 +480,27 @@ + SiprContext *ctx = avctx->priv_data; + int i; + +- if (avctx->bit_rate > 12200) ctx->mode = MODE_16k; +- else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5; +- else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5; +- else ctx->mode = MODE_5k0; ++ switch (avctx->block_align) { ++ case 20: ctx->mode = MODE_16k; break; ++ case 19: ctx->mode = MODE_8k5; break; ++ case 29: ctx->mode = MODE_6k5; break; ++ case 37: ctx->mode = MODE_5k0; break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Invalid block_align: %d\n", avctx->block_align); ++ if (avctx->bit_rate > 12200) ctx->mode = MODE_16k; ++ else if (avctx->bit_rate > 7500 ) ctx->mode = MODE_8k5; ++ else if (avctx->bit_rate > 5750 ) ctx->mode = MODE_6k5; ++ else ctx->mode = MODE_5k0; ++ } + + av_log(avctx, AV_LOG_DEBUG, "Mode: %s\n", modes[ctx->mode].mode_name); + +- if (ctx->mode == MODE_16k) ++ if (ctx->mode == MODE_16k) { + ff_sipr_init_16k(ctx); ++ ctx->decode_frame = ff_sipr_decode_frame_16k; ++ } else { ++ ctx->decode_frame = decode_frame; ++ } + + for (i = 0; i < LP_FILTER_ORDER; i++) + ctx->lsp_history[i] = cos((i+1) * M_PI / (LP_FILTER_ORDER + 1)); +@@ -495,68 +510,64 @@ + + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + +- dsputil_init(&ctx->dsp, avctx); ++ avcodec_get_frame_defaults(&ctx->frame); ++ avctx->coded_frame = &ctx->frame; + + return 0; + } + +-static int sipr_decode_frame(AVCodecContext *avctx, void *datap, +- int *data_size, AVPacket *avpkt) ++static int sipr_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + SiprContext *ctx = avctx->priv_data; + const uint8_t *buf=avpkt->data; + SiprParameters parm; + const SiprModeParam *mode_par = &modes[ctx->mode]; + GetBitContext gb; +- float *data = datap; ++ float *samples; + int subframe_size = ctx->mode == MODE_16k ? L_SUBFR_16k : SUBFR_SIZE; +- int i; ++ int i, ret; + + ctx->avctx = avctx; + if (avpkt->size < (mode_par->bits_per_frame >> 3)) { + av_log(avctx, AV_LOG_ERROR, + "Error processing packet: packet size (%d) too small\n", + avpkt->size); +- +- *data_size = 0; + return -1; + } +- if (*data_size < subframe_size * mode_par->subframe_count * sizeof(float)) { +- av_log(avctx, AV_LOG_ERROR, +- "Error processing packet: output buffer (%d) too small\n", +- *data_size); + +- *data_size = 0; +- return -1; ++ /* get output buffer */ ++ ctx->frame.nb_samples = mode_par->frames_per_packet * subframe_size * ++ mode_par->subframe_count; ++ if ((ret = avctx->get_buffer(avctx, &ctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } ++ samples = (float *)ctx->frame.data[0]; + + init_get_bits(&gb, buf, mode_par->bits_per_frame); + + for (i = 0; i < mode_par->frames_per_packet; i++) { + decode_parameters(&parm, &gb, mode_par); + +- if (ctx->mode == MODE_16k) +- ff_sipr_decode_frame_16k(ctx, &parm, data); +- else +- decode_frame(ctx, &parm, data); ++ ctx->decode_frame(ctx, &parm, samples); + +- data += subframe_size * mode_par->subframe_count; ++ samples += subframe_size * mode_par->subframe_count; + } + +- *data_size = mode_par->frames_per_packet * subframe_size * +- mode_par->subframe_count * sizeof(float); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = ctx->frame; + + return mode_par->bits_per_frame >> 3; + } + + AVCodec ff_sipr_decoder = { +- "sipr", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SIPR, +- sizeof(SiprContext), +- sipr_decoder_init, +- NULL, +- NULL, +- sipr_decode_frame, ++ .name = "sipr", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SIPR, ++ .priv_data_size = sizeof(SiprContext), ++ .init = sipr_decoder_init, ++ .decode = sipr_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("RealAudio SIPR / ACELP.NET"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sipr.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sipr.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sipr.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sipr.h 2012-05-14 14:08:54.216337607 +0200 +@@ -53,9 +53,18 @@ + MODE_COUNT + } SiprMode; + +-typedef struct { ++typedef struct SiprParameters { ++ int ma_pred_switch; ///< switched moving average predictor ++ int vq_indexes[5]; ++ int pitch_delay[5]; ///< pitch delay ++ int gp_index[5]; ///< adaptive-codebook gain indexes ++ int16_t fc_indexes[5][10]; ///< fixed-codebook indexes ++ int gc_index[5]; ///< fixed-codebook gain indexes ++} SiprParameters; ++ ++typedef struct SiprContext { + AVCodecContext *avctx; +- DSPContext dsp; ++ AVFrame frame; + + SiprMode mode; + +@@ -86,16 +95,10 @@ + float mem_preemph[LP_FILTER_ORDER_16k]; + float synth[LP_FILTER_ORDER_16k]; + double lsp_history_16k[16]; +-} SiprContext; + +-typedef struct { +- int ma_pred_switch; ///< switched moving average predictor +- int vq_indexes[5]; +- int pitch_delay[5]; ///< pitch delay +- int gp_index[5]; ///< adaptive-codebook gain indexes +- int16_t fc_indexes[5][10]; ///< fixed-codebook indexes +- int gc_index[5]; ///< fixed-codebook gain indexes +-} SiprParameters; ++ void (*decode_frame)(struct SiprContext *ctx, SiprParameters *params, ++ float *out_data); ++} SiprContext; + + extern const float ff_pow_0_5[16]; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/smacker.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/smacker.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/smacker.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/smacker.c 2012-05-14 14:08:54.218337647 +0200 +@@ -32,8 +32,10 @@ + #include + + #include "avcodec.h" ++#include "libavutil/audioconvert.h" ++#include "mathops.h" + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + #include "bytestream.h" + +@@ -126,18 +128,20 @@ + */ + static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx) + { ++ if (hc->current + 1 >= hc->length) { ++ av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n"); ++ return -1; ++ } + if(!get_bits1(gb)){ //Leaf + int val, i1, i2, b1, b2; +- if(hc->current >= hc->length){ +- av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n"); +- return -1; +- } + b1 = get_bits_count(gb); +- i1 = get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3); ++ i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0; + b1 = get_bits_count(gb) - b1; + b2 = get_bits_count(gb); +- i2 = get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3); ++ i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0; + b2 = get_bits_count(gb) - b2; ++ if (i1 < 0 || i2 < 0) ++ return -1; + val = ctx->recode1[i1] | (ctx->recode2[i2] << 8); + if(val == ctx->escapes[0]) { + ctx->last[0] = hc->current; +@@ -153,7 +157,7 @@ + hc->values[hc->current++] = val; + return 1; + } else { //Node +- int r = 0, t; ++ int r = 0, r_new, t; + + t = hc->current++; + r = smacker_decode_bigtree(gb, hc, ctx); +@@ -161,8 +165,10 @@ + return r; + hc->values[t] = SMK_NODE | r; + r++; +- r += smacker_decode_bigtree(gb, hc, ctx); +- return r; ++ r_new = smacker_decode_bigtree(gb, hc, ctx); ++ if (r_new < 0) ++ return r_new; ++ return r + r_new; + } + } + +@@ -177,6 +183,7 @@ + VLC vlc[2]; + int escapes[3]; + DBCtx ctx; ++ int err = 0; + + if(size >= UINT_MAX>>4){ // (((size + 3) >> 2) + 3) << 2 must not overflow + av_log(smk->avctx, AV_LOG_ERROR, "size too large\n"); +@@ -250,11 +257,17 @@ + huff.current = 0; + huff.values = av_mallocz(huff.length * sizeof(int)); + +- smacker_decode_bigtree(gb, &huff, &ctx); ++ if (smacker_decode_bigtree(gb, &huff, &ctx) < 0) ++ err = -1; + skip_bits1(gb); + if(ctx.last[0] == -1) ctx.last[0] = huff.current++; + if(ctx.last[1] == -1) ctx.last[1] = huff.current++; + if(ctx.last[2] == -1) ctx.last[2] = huff.current++; ++ if(huff.current > huff.length){ ++ ctx.last[0] = ctx.last[1] = ctx.last[2] = 1; ++ av_log(smk->avctx, AV_LOG_ERROR, "bigtree damaged\n"); ++ return -1; ++ } + + *recodes = huff.values; + +@@ -269,7 +282,7 @@ + av_free(tmp2.lengths); + av_free(tmp2.values); + +- return 0; ++ return err; + } + + static int decode_header_trees(SmackVContext *smk) { +@@ -289,7 +302,8 @@ + smk->mmap_tbl[0] = 0; + smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1; + } else { +- smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size); ++ if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size)) ++ return -1; + } + if(!get_bits1(&gb)) { + av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n"); +@@ -297,7 +311,8 @@ + smk->mclr_tbl[0] = 0; + smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1; + } else { +- smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size); ++ if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size)) ++ return -1; + } + if(!get_bits1(&gb)) { + av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n"); +@@ -305,7 +320,8 @@ + smk->full_tbl[0] = 0; + smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1; + } else { +- smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size); ++ if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size)) ++ return -1; + } + if(!get_bits1(&gb)) { + av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n"); +@@ -313,7 +329,8 @@ + smk->type_tbl[0] = 0; + smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1; + } else { +- smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size); ++ if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size)) ++ return -1; + } + + return 0; +@@ -359,10 +376,8 @@ + + if(buf_size <= 769) + return 0; +- if(smk->pic.data[0]) +- avctx->release_buffer(avctx, &smk->pic); + +- smk->pic.reference = 1; ++ smk->pic.reference = 3; + smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if(avctx->reget_buffer(avctx, &smk->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +@@ -374,13 +389,13 @@ + smk->pic.palette_has_changed = buf[0] & 1; + smk->pic.key_frame = !!(buf[0] & 2); + if(smk->pic.key_frame) +- smk->pic.pict_type = FF_I_TYPE; ++ smk->pic.pict_type = AV_PICTURE_TYPE_I; + else +- smk->pic.pict_type = FF_P_TYPE; ++ smk->pic.pict_type = AV_PICTURE_TYPE_P; + + buf++; + for(i = 0; i < 256; i++) +- *pal++ = bytestream_get_be24(&buf); ++ *pal++ = 0xFF << 24 | bytestream_get_be24(&buf); + buf_size -= 769; + + last_reset(smk->mmap_tbl, smk->mmap_last); +@@ -516,6 +531,7 @@ + + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&c->pic); + + /* decode huffman trees from extradata */ + if(avctx->extradata_size < 16){ +@@ -523,8 +539,8 @@ + return -1; + } + +- decode_header_trees(c); +- ++ if (decode_header_trees(c)) ++ return -1; + + return 0; + } +@@ -552,46 +568,80 @@ + } + + ++typedef struct SmackerAudioContext { ++ AVFrame frame; ++} SmackerAudioContext; ++ + static av_cold int smka_decode_init(AVCodecContext *avctx) + { +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ SmackerAudioContext *s = avctx->priv_data; ++ ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO; + avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + + /** + * Decode Smacker audio data + */ +-static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) ++static int smka_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { ++ SmackerAudioContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + GetBitContext gb; + HuffContext h[4]; + VLC vlc[4]; +- int16_t *samples = data; +- int8_t *samples8 = data; ++ int16_t *samples; ++ uint8_t *samples8; + int val; +- int i, res; ++ int i, res, ret; + int unp_size; + int bits, stereo; + int pred[2] = {0, 0}; + ++ if (buf_size <= 4) { ++ av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ + unp_size = AV_RL32(buf); + + init_get_bits(&gb, buf + 4, (buf_size - 4) * 8); + + if(!get_bits1(&gb)){ + av_log(avctx, AV_LOG_INFO, "Sound: no data\n"); +- *data_size = 0; ++ *got_frame_ptr = 0; + return 1; + } + stereo = get_bits1(&gb); + bits = get_bits1(&gb); +- if (unp_size & 0xC0000000 || unp_size > *data_size) { +- av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); +- return -1; ++ if (stereo ^ (avctx->channels != 1)) { ++ av_log(avctx, AV_LOG_ERROR, "channels mismatch\n"); ++ return AVERROR(EINVAL); ++ } ++ if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) { ++ av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = unp_size / (avctx->channels * (bits + 1)); ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; + } ++ samples = (int16_t *)s->frame.data[0]; ++ samples8 = s->frame.data[0]; + + memset(vlc, 0, sizeof(VLC) * 4); + memset(h, 0, sizeof(HuffContext) * 4); +@@ -619,9 +669,11 @@ + if(bits) { //decode 16-bit data + for(i = stereo; i >= 0; i--) + pred[i] = av_bswap16(get_bits(&gb, 16)); +- for(i = 0; i < stereo; i++) ++ for(i = 0; i <= stereo; i++) + *samples++ = pred[i]; +- for(i = 0; i < unp_size / 2; i++) { ++ for(; i < unp_size / 2; i++) { ++ if(get_bits_left(&gb)<0) ++ return -1; + if(i & stereo) { + if(vlc[2].table) + res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3); +@@ -633,8 +685,8 @@ + else + res = 0; + val |= h[3].values[res] << 8; +- pred[1] += (int16_t)val; +- *samples++ = pred[1]; ++ pred[1] += sign_extend(val, 16); ++ *samples++ = av_clip_int16(pred[1]); + } else { + if(vlc[0].table) + res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3); +@@ -646,30 +698,32 @@ + else + res = 0; + val |= h[1].values[res] << 8; +- pred[0] += val; +- *samples++ = pred[0]; ++ pred[0] += sign_extend(val, 16); ++ *samples++ = av_clip_int16(pred[0]); + } + } + } else { //8-bit data + for(i = stereo; i >= 0; i--) + pred[i] = get_bits(&gb, 8); +- for(i = 0; i < stereo; i++) ++ for(i = 0; i <= stereo; i++) + *samples8++ = pred[i]; +- for(i = 0; i < unp_size; i++) { ++ for(; i < unp_size; i++) { ++ if(get_bits_left(&gb)<0) ++ return -1; + if(i & stereo){ + if(vlc[1].table) + res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3); + else + res = 0; +- pred[1] += (int8_t)h[1].values[res]; +- *samples8++ = pred[1]; ++ pred[1] += sign_extend(h[1].values[res], 8); ++ *samples8++ = av_clip_uint8(pred[1]); + } else { + if(vlc[0].table) + res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3); + else + res = 0; +- pred[0] += (int8_t)h[0].values[res]; +- *samples8++ = pred[0]; ++ pred[0] += sign_extend(h[0].values[res], 8); ++ *samples8++ = av_clip_uint8(pred[0]); + } + } + } +@@ -677,40 +731,37 @@ + for(i = 0; i < 4; i++) { + if(vlc[i].table) + free_vlc(&vlc[i]); +- if(h[i].bits) +- av_free(h[i].bits); +- if(h[i].lengths) +- av_free(h[i].lengths); +- if(h[i].values) +- av_free(h[i].values); ++ av_free(h[i].bits); ++ av_free(h[i].lengths); ++ av_free(h[i].values); + } + +- *data_size = unp_size; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return buf_size; + } + + AVCodec ff_smacker_decoder = { +- "smackvid", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SMACKVIDEO, +- sizeof(SmackVContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "smackvid", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SMACKVIDEO, ++ .priv_data_size = sizeof(SmackVContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Smacker video"), + }; + + AVCodec ff_smackaud_decoder = { +- "smackaud", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SMACKAUDIO, +- 0, +- smka_decode_init, +- NULL, +- NULL, +- smka_decode_frame, ++ .name = "smackaud", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SMACKAUDIO, ++ .priv_data_size = sizeof(SmackerAudioContext), ++ .init = smka_decode_init, ++ .decode = smka_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Smacker audio"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/smc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/smc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/smc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/smc.c 2012-05-14 14:08:54.220337687 +0200 +@@ -34,6 +34,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "bytestream.h" + + #define CPAIR 2 + #define CQUAD 4 +@@ -46,18 +47,18 @@ + AVCodecContext *avctx; + AVFrame frame; + +- const unsigned char *buf; +- int size; ++ GetByteContext gb; + + /* SMC color tables */ + unsigned char color_pairs[COLORS_PER_TABLE * CPAIR]; + unsigned char color_quads[COLORS_PER_TABLE * CQUAD]; + unsigned char color_octets[COLORS_PER_TABLE * COCTET]; + ++ uint32_t pal[256]; + } SmcContext; + + #define GET_BLOCK_COUNT() \ +- (opcode & 0x10) ? (1 + s->buf[stream_ptr++]) : 1 + (opcode & 0x0F); ++ (opcode & 0x10) ? (1 + bytestream2_get_byte(&s->gb)) : 1 + (opcode & 0x0F); + + #define ADVANCE_BLOCK() \ + { \ +@@ -81,8 +82,8 @@ + int height = s->avctx->height; + int stride = s->frame.linesize[0]; + int i; +- int stream_ptr = 0; + int chunk_size; ++ int buf_size = (int) (s->gb.buffer_end - s->gb.buffer_start); + unsigned char opcode; + int n_blocks; + unsigned int color_flags; +@@ -110,30 +111,20 @@ + int color_octet_index = 0; + + /* make the palette available */ +- memcpy(s->frame.data[1], s->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (s->avctx->palctrl->palette_changed) { +- s->frame.palette_has_changed = 1; +- s->avctx->palctrl->palette_changed = 0; +- } ++ memcpy(s->frame.data[1], s->pal, AVPALETTE_SIZE); + +- chunk_size = AV_RB32(&s->buf[stream_ptr]) & 0x00FFFFFF; +- stream_ptr += 4; +- if (chunk_size != s->size) ++ bytestream2_skip(&s->gb, 1); ++ chunk_size = bytestream2_get_be24(&s->gb); ++ if (chunk_size != buf_size) + av_log(s->avctx, AV_LOG_INFO, "warning: MOV chunk size != encoded chunk size (%d != %d); using MOV chunk size\n", +- chunk_size, s->size); ++ chunk_size, buf_size); + +- chunk_size = s->size; ++ chunk_size = buf_size; + total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4); + + /* traverse through the blocks */ + while (total_blocks) { + /* sanity checks */ +- /* make sure stream ptr hasn't gone out of bounds */ +- if (stream_ptr > chunk_size) { +- av_log(s->avctx, AV_LOG_INFO, "SMC decoder just went out of bounds (stream ptr = %d, chunk size = %d)\n", +- stream_ptr, chunk_size); +- return; +- } + /* make sure the row pointer hasn't gone wild */ + if (row_ptr >= image_size) { + av_log(s->avctx, AV_LOG_INFO, "SMC decoder just went out of bounds (row ptr = %d, height = %d)\n", +@@ -141,7 +132,7 @@ + return; + } + +- opcode = s->buf[stream_ptr++]; ++ opcode = bytestream2_get_byte(&s->gb); + switch (opcode & 0xF0) { + /* skip n blocks */ + case 0x00: +@@ -161,7 +152,7 @@ + if ((row_ptr == 0) && (pixel_ptr == 0)) { + av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but no blocks rendered yet\n", + opcode & 0xF0); +- break; ++ return; + } + + /* figure out where the previous block started */ +@@ -195,7 +186,7 @@ + if ((row_ptr == 0) && (pixel_ptr < 2 * 4)) { + av_log(s->avctx, AV_LOG_INFO, "encountered repeat block opcode (%02X) but not enough blocks rendered yet\n", + opcode & 0xF0); +- break; ++ return; + } + + /* figure out where the previous 2 blocks started */ +@@ -236,7 +227,7 @@ + case 0x60: + case 0x70: + n_blocks = GET_BLOCK_COUNT(); +- pixel = s->buf[stream_ptr++]; ++ pixel = bytestream2_get_byte(&s->gb); + + while (n_blocks--) { + block_ptr = row_ptr + pixel_ptr; +@@ -260,7 +251,7 @@ + /* fetch the next 2 colors from bytestream and store in next + * available entry in the color pair table */ + for (i = 0; i < CPAIR; i++) { +- pixel = s->buf[stream_ptr++]; ++ pixel = bytestream2_get_byte(&s->gb); + color_table_index = CPAIR * color_pair_index + i; + s->color_pairs[color_table_index] = pixel; + } +@@ -271,11 +262,10 @@ + if (color_pair_index == COLORS_PER_TABLE) + color_pair_index = 0; + } else +- color_table_index = CPAIR * s->buf[stream_ptr++]; ++ color_table_index = CPAIR * bytestream2_get_byte(&s->gb); + + while (n_blocks--) { +- color_flags = AV_RB16(&s->buf[stream_ptr]); +- stream_ptr += 2; ++ color_flags = bytestream2_get_be16(&s->gb); + flag_mask = 0x8000; + block_ptr = row_ptr + pixel_ptr; + for (pixel_y = 0; pixel_y < 4; pixel_y++) { +@@ -303,7 +293,7 @@ + /* fetch the next 4 colors from bytestream and store in next + * available entry in the color quad table */ + for (i = 0; i < CQUAD; i++) { +- pixel = s->buf[stream_ptr++]; ++ pixel = bytestream2_get_byte(&s->gb); + color_table_index = CQUAD * color_quad_index + i; + s->color_quads[color_table_index] = pixel; + } +@@ -314,11 +304,10 @@ + if (color_quad_index == COLORS_PER_TABLE) + color_quad_index = 0; + } else +- color_table_index = CQUAD * s->buf[stream_ptr++]; ++ color_table_index = CQUAD * bytestream2_get_byte(&s->gb); + + while (n_blocks--) { +- color_flags = AV_RB32(&s->buf[stream_ptr]); +- stream_ptr += 4; ++ color_flags = bytestream2_get_be32(&s->gb); + /* flag mask actually acts as a bit shift count here */ + flag_mask = 30; + block_ptr = row_ptr + pixel_ptr; +@@ -345,7 +334,7 @@ + /* fetch the next 8 colors from bytestream and store in next + * available entry in the color octet table */ + for (i = 0; i < COCTET; i++) { +- pixel = s->buf[stream_ptr++]; ++ pixel = bytestream2_get_byte(&s->gb); + color_table_index = COCTET * color_octet_index + i; + s->color_octets[color_table_index] = pixel; + } +@@ -356,7 +345,7 @@ + if (color_octet_index == COLORS_PER_TABLE) + color_octet_index = 0; + } else +- color_table_index = COCTET * s->buf[stream_ptr++]; ++ color_table_index = COCTET * bytestream2_get_byte(&s->gb); + + while (n_blocks--) { + /* +@@ -366,15 +355,12 @@ + flags_a = xx012456, flags_b = xx89A37B + */ + /* build the color flags */ +- color_flags_a = +- ((AV_RB16(s->buf + stream_ptr ) & 0xFFF0) << 8) | +- (AV_RB16(s->buf + stream_ptr + 2) >> 4); +- color_flags_b = +- ((AV_RB16(s->buf + stream_ptr + 4) & 0xFFF0) << 8) | +- ((s->buf[stream_ptr + 1] & 0x0F) << 8) | +- ((s->buf[stream_ptr + 3] & 0x0F) << 4) | +- (s->buf[stream_ptr + 5] & 0x0F); +- stream_ptr += 6; ++ int val1 = bytestream2_get_be16(&s->gb); ++ int val2 = bytestream2_get_be16(&s->gb); ++ int val3 = bytestream2_get_be16(&s->gb); ++ color_flags_a = ((val1 & 0xFFF0) << 8) | (val2 >> 4); ++ color_flags_b = ((val3 & 0xFFF0) << 8) | ++ ((val1 & 0x0F) << 8) | ((val2 & 0x0F) << 4) | (val3 & 0x0F); + + color_flags = color_flags_a; + /* flag mask actually acts as a bit shift count here */ +@@ -406,7 +392,7 @@ + block_ptr = row_ptr + pixel_ptr; + for (pixel_y = 0; pixel_y < 4; pixel_y++) { + for (pixel_x = 0; pixel_x < 4; pixel_x++) { +- pixels[block_ptr++] = s->buf[stream_ptr++]; ++ pixels[block_ptr++] = bytestream2_get_byte(&s->gb); + } + block_ptr += row_inc; + } +@@ -415,10 +401,12 @@ + break; + + case 0xF0: +- av_log(s->avctx, AV_LOG_INFO, "0xF0 opcode seen in SMC chunk (contact the developers)\n"); ++ av_log_missing_feature(s->avctx, "0xF0 opcode", 1); + break; + } + } ++ ++ return; + } + + static av_cold int smc_decode_init(AVCodecContext *avctx) +@@ -428,6 +416,7 @@ + s->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -440,11 +429,11 @@ + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + SmcContext *s = avctx->priv_data; ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); + +- s->buf = buf; +- s->size = buf_size; ++ bytestream2_init(&s->gb, buf, buf_size); + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | + FF_BUFFER_HINTS_REUSABLE | FF_BUFFER_HINTS_READABLE; + if (avctx->reget_buffer(avctx, &s->frame)) { +@@ -452,6 +441,11 @@ + return -1; + } + ++ if (pal) { ++ s->frame.palette_has_changed = 1; ++ memcpy(s->pal, pal, AVPALETTE_SIZE); ++ } ++ + smc_decode_stream(s); + + *data_size = sizeof(AVFrame); +@@ -472,14 +466,13 @@ + } + + AVCodec ff_smc_decoder = { +- "smc", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SMC, +- sizeof(SmcContext), +- smc_decode_init, +- NULL, +- smc_decode_end, +- smc_decode_frame, +- CODEC_CAP_DR1, ++ .name = "smc", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SMC, ++ .priv_data_size = sizeof(SmcContext), ++ .init = smc_decode_init, ++ .close = smc_decode_end, ++ .decode = smc_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("QuickTime Graphics (SMC)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snow.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snow.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snow.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snow.c 2012-05-14 14:08:54.230337889 +0200 +@@ -19,751 +19,56 @@ + */ + + #include "libavutil/intmath.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + #include "avcodec.h" + #include "dsputil.h" + #include "dwt.h" + #include "snow.h" ++#include "snowdata.h" + + #include "rangecoder.h" + #include "mathops.h" +- +-#include "mpegvideo.h" + #include "h263.h" + + #undef NDEBUG + #include + +-static const int8_t quant3[256]={ +- 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, +-}; +-static const int8_t quant3b[256]={ +- 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +- 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +--1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, +-}; +-static const int8_t quant3bA[256]={ +- 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +- 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, +-}; +-static const int8_t quant5[256]={ +- 0, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1,-1, +-}; +-static const int8_t quant7[256]={ +- 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, +- 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2, +--2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-2,-1,-1, +-}; +-static const int8_t quant9[256]={ +- 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, +- 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3, +--3,-3,-3,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-2,-1,-1, +-}; +-static const int8_t quant11[256]={ +- 0, 1, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, +- 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-4,-4, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4,-4, +--4,-4,-4,-4,-4,-3,-3,-3,-3,-3,-3,-3,-2,-2,-2,-1, +-}; +-static const int8_t quant13[256]={ +- 0, 1, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, +- 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, +- 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +- 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6, +--6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-6,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5,-5, +--4,-4,-4,-4,-4,-4,-4,-4,-4,-3,-3,-3,-3,-2,-2,-1, +-}; +- +-#if 0 //64*cubic +-static const uint8_t obmc32[1024]={ +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, +- 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, +- 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, +- 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, +- 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, +- 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, +- 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, +- 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, +- 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, +- 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, +- 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, +- 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, +- 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, +- 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, +- 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, +- 1, 8, 16, 32, 48, 72, 92,116,140,164,184,208,224,240,248,255,255,248,240,224,208,184,164,140,116, 92, 72, 48, 32, 16, 8, 1, +- 0, 4, 16, 32, 48, 68, 88,112,136,160,180,204,220,232,244,248,248,244,232,220,204,180,160,136,112, 88, 68, 48, 32, 16, 4, 0, +- 0, 8, 16, 28, 48, 64, 88,108,132,152,176,192,208,224,232,240,240,232,224,208,192,176,152,132,108, 88, 64, 48, 28, 16, 8, 0, +- 0, 4, 16, 28, 44, 60, 80,100,124,144,164,180,196,208,220,224,224,220,208,196,180,164,144,124,100, 80, 60, 44, 28, 16, 4, 0, +- 0, 4, 12, 24, 40, 56, 76, 92,112,132,152,168,180,192,204,208,208,204,192,180,168,152,132,112, 92, 76, 56, 40, 24, 12, 4, 0, +- 0, 4, 12, 24, 36, 48, 68, 84,100,120,136,152,164,176,180,184,184,180,176,164,152,136,120,100, 84, 68, 48, 36, 24, 12, 4, 0, +- 0, 4, 12, 20, 32, 44, 60, 76, 88,104,120,132,144,152,160,164,164,160,152,144,132,120,104, 88, 76, 60, 44, 32, 20, 12, 4, 0, +- 0, 4, 8, 16, 28, 40, 52, 64, 76, 88,100,112,124,132,136,140,140,136,132,124,112,100, 88, 76, 64, 52, 40, 28, 16, 8, 4, 0, +- 0, 4, 8, 16, 24, 32, 40, 52, 64, 76, 84, 92,100,108,112,116,116,112,108,100, 92, 84, 76, 64, 52, 40, 32, 24, 16, 8, 4, 0, +- 0, 4, 4, 12, 16, 24, 32, 40, 52, 60, 68, 76, 80, 88, 88, 92, 92, 88, 88, 80, 76, 68, 60, 52, 40, 32, 24, 16, 12, 4, 4, 0, +- 0, 4, 4, 8, 12, 20, 24, 32, 40, 44, 52, 56, 60, 64, 68, 72, 72, 68, 64, 60, 56, 52, 44, 40, 32, 24, 20, 12, 8, 4, 4, 0, +- 0, 0, 4, 8, 8, 12, 16, 24, 28, 32, 36, 40, 44, 48, 48, 48, 48, 48, 48, 44, 40, 36, 32, 28, 24, 16, 12, 8, 8, 4, 0, 0, +- 0, 0, 4, 4, 8, 8, 12, 16, 16, 20, 24, 24, 28, 28, 32, 32, 32, 32, 28, 28, 24, 24, 20, 16, 16, 12, 8, 8, 4, 4, 0, 0, +- 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 16, 16, 16, 16, 16, 16, 16, 16, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, +- 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-//error:0.000022 +-}; +-static const uint8_t obmc16[256]={ +- 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, +- 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, +- 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, +- 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, +- 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, +- 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, +- 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, +- 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, +- 4, 24, 60,104,152,196,228,248,248,228,196,152,104, 60, 24, 4, +- 4, 20, 52, 96,136,180,212,228,228,212,180,136, 96, 52, 20, 4, +- 0, 20, 44, 80,116,152,180,196,196,180,152,116, 80, 44, 20, 0, +- 0, 16, 36, 60, 92,116,136,152,152,136,116, 92, 60, 36, 16, 0, +- 0, 8, 24, 44, 60, 80, 96,104,104, 96, 80, 60, 44, 24, 8, 0, +- 0, 4, 16, 24, 36, 44, 52, 60, 60, 52, 44, 36, 24, 16, 4, 0, +- 0, 4, 4, 8, 16, 20, 20, 24, 24, 20, 20, 16, 8, 4, 4, 0, +- 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, +-//error:0.000033 +-}; +-#elif 1 // 64*linear +-static const uint8_t obmc32[1024]={ +- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, +- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, +- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, +- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, +- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, +- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, +- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, +- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, +- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, +- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, +- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, +- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, +- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, +- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, +- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, +- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, +- 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, +- 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, +- 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, +- 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, +- 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, +- 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, +- 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, +- 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, +- 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, +- 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, +- 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, +- 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, +- 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, +- 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, +- 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, +- 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, +- //error:0.000020 +-}; +-static const uint8_t obmc16[256]={ +- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, +- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, +- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, +- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, +- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, +- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, +- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, +- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, +- 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, +- 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, +- 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, +- 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, +- 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, +- 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, +- 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, +- 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, +-//error:0.000015 +-}; +-#else //64*cos +-static const uint8_t obmc32[1024]={ +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, +- 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, +- 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, +- 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, +- 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, +- 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, +- 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, +- 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, +- 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, +- 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, +- 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, +- 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, +- 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, +- 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, +- 1, 4, 16, 28, 48, 68, 92,116,140,164,188,208,228,240,252,255,255,252,240,228,208,188,164,140,116, 92, 68, 48, 28, 16, 4, 1, +- 0, 4, 16, 28, 48, 68, 88,112,136,160,184,204,224,236,244,252,252,244,236,224,204,184,160,136,112, 88, 68, 48, 28, 16, 4, 0, +- 0, 4, 12, 28, 44, 64, 84,108,132,156,176,196,212,228,236,240,240,236,228,212,196,176,156,132,108, 84, 64, 44, 28, 12, 4, 0, +- 0, 4, 12, 24, 44, 60, 80,104,124,148,168,184,200,212,224,228,228,224,212,200,184,168,148,124,104, 80, 60, 44, 24, 12, 4, 0, +- 0, 4, 12, 24, 36, 56, 76, 96,116,136,152,172,184,196,204,208,208,204,196,184,172,152,136,116, 96, 76, 56, 36, 24, 12, 4, 0, +- 0, 4, 12, 20, 36, 48, 68, 84,104,120,140,152,168,176,184,188,188,184,176,168,152,140,120,104, 84, 68, 48, 36, 20, 12, 4, 0, +- 0, 4, 12, 20, 28, 44, 60, 76, 92,104,120,136,148,156,160,164,164,160,156,148,136,120,104, 92, 76, 60, 44, 28, 20, 12, 4, 0, +- 0, 4, 8, 16, 24, 36, 48, 64, 76, 92,104,116,124,132,136,140,140,136,132,124,116,104, 92, 76, 64, 48, 36, 24, 16, 8, 4, 0, +- 0, 4, 8, 12, 20, 32, 40, 52, 64, 76, 84, 96,104,108,112,116,116,112,108,104, 96, 84, 76, 64, 52, 40, 32, 20, 12, 8, 4, 0, +- 0, 4, 4, 8, 16, 24, 32, 40, 48, 60, 68, 76, 80, 84, 88, 92, 92, 88, 84, 80, 76, 68, 60, 48, 40, 32, 24, 16, 8, 4, 4, 0, +- 0, 0, 4, 8, 12, 20, 24, 32, 36, 44, 48, 56, 60, 64, 68, 68, 68, 68, 64, 60, 56, 48, 44, 36, 32, 24, 20, 12, 8, 4, 0, 0, +- 0, 0, 4, 4, 8, 12, 16, 20, 24, 28, 36, 40, 44, 44, 48, 48, 48, 48, 44, 44, 40, 36, 28, 24, 20, 16, 12, 8, 4, 4, 0, 0, +- 0, 0, 4, 4, 4, 8, 8, 12, 16, 20, 20, 24, 28, 28, 28, 28, 28, 28, 28, 28, 24, 20, 20, 16, 12, 8, 8, 4, 4, 4, 0, 0, +- 0, 0, 0, 4, 4, 4, 4, 8, 8, 12, 12, 12, 12, 16, 16, 16, 16, 16, 16, 12, 12, 12, 12, 8, 8, 4, 4, 4, 4, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 4, 4, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +-//error:0.000022 +-}; +-static const uint8_t obmc16[256]={ +- 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, +- 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, +- 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, +- 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, +- 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, +- 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, +- 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, +- 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, +- 0, 20, 56,104,152,196,232,252,252,232,196,152,104, 56, 20, 0, +- 4, 20, 52, 96,140,184,216,232,232,216,184,140, 96, 52, 20, 4, +- 4, 16, 44, 80,120,156,184,196,196,184,156,120, 80, 44, 16, 4, +- 0, 12, 32, 64, 92,120,140,152,152,140,120, 92, 64, 32, 12, 0, +- 0, 8, 24, 40, 60, 80, 96,104,104, 96, 80, 60, 40, 24, 8, 0, +- 0, 4, 12, 24, 32, 44, 52, 56, 56, 52, 44, 32, 24, 12, 4, 0, +- 0, 0, 4, 8, 12, 16, 20, 20, 20, 20, 16, 12, 8, 4, 0, 0, +- 0, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, +-//error:0.000022 +-}; +-#endif /* 0 */ +- +-//linear *64 +-static const uint8_t obmc8[64]={ +- 4, 12, 20, 28, 28, 20, 12, 4, +- 12, 36, 60, 84, 84, 60, 36, 12, +- 20, 60,100,140,140,100, 60, 20, +- 28, 84,140,196,196,140, 84, 28, +- 28, 84,140,196,196,140, 84, 28, +- 20, 60,100,140,140,100, 60, 20, +- 12, 36, 60, 84, 84, 60, 36, 12, +- 4, 12, 20, 28, 28, 20, 12, 4, +-//error:0.000000 +-}; +- +-//linear *64 +-static const uint8_t obmc4[16]={ +- 16, 48, 48, 16, +- 48,144,144, 48, +- 48,144,144, 48, +- 16, 48, 48, 16, +-//error:0.000000 +-}; +- +-static const uint8_t * const obmc_tab[4]={ +- obmc32, obmc16, obmc8, obmc4 +-}; +- +-static int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES]; +- +-typedef struct BlockNode{ +- int16_t mx; +- int16_t my; +- uint8_t ref; +- uint8_t color[3]; +- uint8_t type; +-//#define TYPE_SPLIT 1 +-#define BLOCK_INTRA 1 +-#define BLOCK_OPT 2 +-//#define TYPE_NOCOLOR 4 +- uint8_t level; //FIXME merge into type? +-}BlockNode; +- +-static const BlockNode null_block= { //FIXME add border maybe +- .color= {128,128,128}, +- .mx= 0, +- .my= 0, +- .ref= 0, +- .type= 0, +- .level= 0, +-}; +- +-#define LOG2_MB_SIZE 4 +-#define MB_SIZE (1<=el; i--){ +- put_rac(c, state+22+9, (a>>i)&1); //22..31 +- } +- for(; i>=0; i--){ +- put_rac(c, state+22+i, (a>>i)&1); //22..31 +- } +- +- if(is_signed) +- put_rac(c, state+11 + el, v < 0); //11..21 +-#else +- +- put_rac(c, state+0, 0); +- if(e<=9){ +- for(i=0; i=0; i--){ +- put_rac(c, state+22+i, (a>>i)&1); //22..31 +- } +- +- if(is_signed) +- put_rac(c, state+11 + e, v < 0); //11..21 +- }else{ +- for(i=0; i=0; i--){ +- put_rac(c, state+22+FFMIN(i,9), (a>>i)&1); //22..31 +- } +- +- if(is_signed) +- put_rac(c, state+11 + 10, v < 0); //11..21 +- } +-#endif /* 1 */ +- }else{ +- put_rac(c, state+0, 1); +- } +-} +- +-static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){ +- if(get_rac(c, state+0)) +- return 0; +- else{ +- int i, e, a; +- e= 0; +- while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10 +- e++; +- } +- +- a= 1; +- for(i=e-1; i>=0; i--){ +- a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31 +- } +- +- e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10))); //11..21 +- return (a^e)-e; +- } +-} +- +-static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){ +- int i; +- int r= log2>=0 ? 1<=0); +- assert(log2>=-4); +- +- while(v >= r){ +- put_rac(c, state+4+log2, 1); +- v -= r; +- log2++; +- if(log2>0) r+=r; +- } +- put_rac(c, state+4+log2, 0); +- +- for(i=log2-1; i>=0; i--){ +- put_rac(c, state+31-i, (v>>i)&1); +- } +-} +- +-static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ +- int i; +- int r= log2>=0 ? 1<=-4); +- +- while(get_rac(c, state+4+log2)){ +- v+= r; +- log2++; +- if(log2>0) r+=r; +- } +- +- for(i=log2-1; i>=0; i--){ +- v+= get_rac(c, state+31-i)<width; +- const int h= b->height; +- int x,y; +- +- int run, runs; +- x_and_coeff *xc= b->x_coeff; +- x_and_coeff *prev_xc= NULL; +- x_and_coeff *prev2_xc= xc; +- x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; +- x_and_coeff *prev_parent_xc= parent_xc; +- +- runs= get_symbol2(&s->c, b->state[30], 0); +- if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); +- else run= INT_MAX; +- +- for(y=0; yx == 0){ +- rt= prev_xc->coeff; +- } +- for(x=0; xx <= x) +- prev_xc++; +- if(prev_xc->x == x + 1) +- rt= prev_xc->coeff; +- else +- rt=0; +- } +- if(parent_xc){ +- if(x>>1 > parent_xc->x){ +- parent_xc++; +- } +- if(x>>1 == parent_xc->x){ +- p= parent_xc->coeff; +- } +- } +- if(/*ll|*/l|lt|t|rt|p){ +- int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); +- +- v=get_rac(&s->c, &b->state[0][context]); +- if(v){ +- v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); +- v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]); +- +- xc->x=x; +- (xc++)->coeff= v; +- } +- }else{ +- if(!run){ +- if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); +- else run= INT_MAX; +- v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); +- v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); ++void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, ++ int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ ++ int y, x; ++ IDWTELEM * dst; ++ for(y=0; y>1); ++ const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); ++ const uint8_t *obmc4= obmc3+ (obmc_stride>>1); ++ dst = slice_buffer_get_line(sb, src_y + y); ++ for(x=0; xx=x; +- (xc++)->coeff= v; +- }else{ +- int max_run; +- run--; +- v=0; +- +- if(y) max_run= FFMIN(run, prev_xc->x - x - 2); +- else max_run= FFMIN(run, w-x-1); +- if(parent_xc) +- max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); +- x+= max_run; +- run-= max_run; +- } ++ v <<= 8 - LOG2_OBMC_MAX; ++ if(FRAC_BITS != 8){ ++ v >>= 8 - FRAC_BITS; + } +- } +- (xc++)->x= w+1; //end marker +- prev_xc= prev2_xc; +- prev2_xc= xc; +- +- if(parent_xc){ +- if(y&1){ +- while(parent_xc->x != parent->width+1) +- parent_xc++; +- parent_xc++; +- prev_parent_xc= parent_xc; ++ if(add){ ++ v += dst[x + src_x]; ++ v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; ++ if(v&(~255)) v= ~(v>>31); ++ dst8[x + y*src_stride] = v; + }else{ +- parent_xc= prev_parent_xc; ++ dst[x + src_x] -= v; + } + } + } +- +- (xc++)->x= w+1; //end marker +-} +- +-static inline void decode_subband_slice_buffered(SnowContext *s, SubBand *b, slice_buffer * sb, int start_y, int h, int save_state[1]){ +- const int w= b->width; +- int y; +- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); +- int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); +- int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; +- int new_index = 0; +- +- if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){ +- qadd= 0; +- qmul= 1<stride_line + b->buf_y_offset) + b->buf_x_offset; +- memset(line, 0, b->width*sizeof(IDWTELEM)); +- v = b->x_coeff[new_index].coeff; +- x = b->x_coeff[new_index++].x; +- while(x < w){ +- register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT; +- register int u= -(v&1); +- line[x] = (t^u) - u; +- +- v = b->x_coeff[new_index].coeff; +- x = b->x_coeff[new_index++].x; +- } +- } +- +- /* Save our variables for the next slice. */ +- save_state[0] = new_index; +- +- return; + } + +-static void reset_contexts(SnowContext *s){ //FIXME better initial contexts ++void ff_snow_reset_contexts(SnowContext *s){ //FIXME better initial contexts + int plane_index, level, orientation; + + for(plane_index=0; plane_index<3; plane_index++){ +@@ -777,7 +82,7 @@ + memset(s->block_state, MID_STATE, sizeof(s->block_state)); + } + +-static int alloc_blocks(SnowContext *s){ ++int ff_snow_alloc_blocks(SnowContext *s){ + int w= -((-s->avctx->width )>>LOG2_MB_SIZE); + int h= -((-s->avctx->height)>>LOG2_MB_SIZE); + +@@ -789,137 +94,15 @@ + return 0; + } + +-static inline void copy_rac_state(RangeCoder *d, RangeCoder *s){ +- uint8_t *bytestream= d->bytestream; +- uint8_t *bytestream_start= d->bytestream_start; +- *d= *s; +- d->bytestream= bytestream; +- d->bytestream_start= bytestream_start; +-} +- +-static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ +- const int w= s->b_width << s->block_max_depth; +- const int rem_depth= s->block_max_depth - level; +- const int index= (x + y*w) << rem_depth; +- const int block_w= 1<block[index + i + j*w]= block; +- } +- } +-} +- +-static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){ +- const int offset[3]= { +- y*c-> stride + x, +- ((y*c->uvstride + x)>>1), +- ((y*c->uvstride + x)>>1), +- }; ++static void init_qexp(void){ + int i; +- for(i=0; i<3; i++){ +- c->src[0][i]= src [i]; +- c->ref[0][i]= ref [i] + offset[i]; +- } +- assert(!ref_index); +-} +- +-static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref, +- const BlockNode *left, const BlockNode *top, const BlockNode *tr){ +- if(s->ref_frames == 1){ +- *mx = mid_pred(left->mx, top->mx, tr->mx); +- *my = mid_pred(left->my, top->my, tr->my); +- }else{ +- const int *scale = scale_mv_ref[ref]; +- *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8, +- (top ->mx * scale[top ->ref] + 128) >>8, +- (tr ->mx * scale[tr ->ref] + 128) >>8); +- *my = mid_pred((left->my * scale[left->ref] + 128) >>8, +- (top ->my * scale[top ->ref] + 128) >>8, +- (tr ->my * scale[tr ->ref] + 128) >>8); +- } +-} +- +-static av_always_inline int same_block(BlockNode *a, BlockNode *b){ +- if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ +- return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); +- }else{ +- return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA)); +- } +-} +- +-static void decode_q_branch(SnowContext *s, int level, int x, int y){ +- const int w= s->b_width << s->block_max_depth; +- const int rem_depth= s->block_max_depth - level; +- const int index= (x + y*w) << rem_depth; +- int trx= (x+1)<block[index-1] : &null_block; +- const BlockNode *top = y ? &s->block[index-w] : &null_block; +- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; +- const BlockNode *tr = y && trxblock[index-w+(1<level + 2*top->level + tl->level + tr->level; +- +- if(s->keyframe){ +- set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA); +- return; +- } +- +- if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){ +- int type, mx, my; +- int l = left->color[0]; +- int cb= left->color[1]; +- int cr= left->color[2]; +- int ref = 0; +- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); +- int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx)); +- int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my)); +- +- type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0; +- +- if(type){ +- pred_mv(s, &mx, &my, 0, left, top, tr); +- l += get_symbol(&s->c, &s->block_state[32], 1); +- cb+= get_symbol(&s->c, &s->block_state[64], 1); +- cr+= get_symbol(&s->c, &s->block_state[96], 1); +- }else{ +- if(s->ref_frames > 1) +- ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0); +- pred_mv(s, &mx, &my, ref, left, top, tr); +- mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1); +- my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1); +- } +- set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type); +- }else{ +- decode_q_branch(s, level+1, 2*x+0, 2*y+0); +- decode_q_branch(s, level+1, 2*x+1, 2*y+0); +- decode_q_branch(s, level+1, 2*x+0, 2*y+1); +- decode_q_branch(s, level+1, 2*x+1, 2*y+1); +- } +-} ++ double v=128; + +-static void decode_blocks(SnowContext *s){ +- int x, y; +- int w= s->b_width; +- int h= s->b_height; +- +- for(y=0; ytype & BLOCK_INTRA){ + int x, y; +- const int color = block->color[plane_index]; +- const int color4= color*0x01010101; ++ const unsigned color = block->color[plane_index]; ++ const unsigned color4 = color*0x01010101; + if(b_w==32){ + for(y=0; y < b_h; y++){ + *(uint32_t*)&dst[0 + y*stride]= color4; +@@ -1199,530 +367,71 @@ + } + } + +-void ff_snow_inner_add_yblock(const uint8_t *obmc, const int obmc_stride, uint8_t * * block, int b_w, int b_h, +- int src_x, int src_y, int src_stride, slice_buffer * sb, int add, uint8_t * dst8){ +- int y, x; +- IDWTELEM * dst; +- for(y=0; y>1); +- const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); +- const uint8_t *obmc4= obmc3+ (obmc_stride>>1); +- dst = slice_buffer_get_line(sb, src_y + y); +- for(x=0; x>= 8 - FRAC_BITS; +- } +- if(add){ +- v += dst[x + src_x]; +- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; +- if(v&(~255)) v= ~(v>>31); +- dst8[x + y*src_stride] = v; +- }else{ +- dst[x + src_x] -= v; +- } +- } +- } ++#define mca(dx,dy,b_w)\ ++static void mc_block_hpel ## dx ## dy ## b_w(uint8_t *dst, const uint8_t *src, int stride, int h){\ ++ assert(h==b_w);\ ++ mc_block(NULL, dst, src-(HTAPS_MAX/2-1)-(HTAPS_MAX/2-1)*stride, stride, b_w, b_w, dx, dy);\ + } + +-//FIXME name cleanup (b_w, block_w, b_width stuff) +-static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ +- const int b_width = s->b_width << s->block_max_depth; +- const int b_height= s->b_height << s->block_max_depth; +- const int b_stride= b_width; +- BlockNode *lt= &s->block[b_x + b_y*b_stride]; +- BlockNode *rt= lt+1; +- BlockNode *lb= lt+b_stride; +- BlockNode *rb= lb+1; +- uint8_t *block[4]; +- int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride; +- uint8_t *tmp = s->scratchbuf; +- uint8_t *ptmp; +- int x,y; +- +- if(b_x<0){ +- lt= rt; +- lb= rb; +- }else if(b_x + 1 >= b_width){ +- rt= lt; +- rb= lb; +- } +- if(b_y<0){ +- lt= lb; +- rt= rb; +- }else if(b_y + 1 >= b_height){ +- lb= lt; +- rb= rt; +- } ++mca( 0, 0,16) ++mca( 8, 0,16) ++mca( 0, 8,16) ++mca( 8, 8,16) ++mca( 0, 0,8) ++mca( 8, 0,8) ++mca( 0, 8,8) ++mca( 8, 8,8) + +- if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 +- obmc -= src_x; +- b_w += src_x; +- if(!sliced && !offset_dst) +- dst -= src_x; +- src_x=0; +- }else if(src_x + b_w > w){ +- b_w = w - src_x; +- } +- if(src_y<0){ +- obmc -= src_y*obmc_stride; +- b_h += src_y; +- if(!sliced && !offset_dst) +- dst -= src_y*dst_stride; +- src_y=0; +- }else if(src_y + b_h> h){ +- b_h = h - src_y; +- } ++av_cold int ff_snow_common_init(AVCodecContext *avctx){ ++ SnowContext *s = avctx->priv_data; ++ int width, height; ++ int i, j; + +- if(b_w<=0 || b_h<=0) return; ++ s->avctx= avctx; ++ s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe + +- assert(src_stride > 2*MB_SIZE + 5); ++ dsputil_init(&s->dsp, avctx); ++ ff_dwt_init(&s->dwt); + +- if(!sliced && offset_dst) +- dst += src_x + src_y*dst_stride; +- dst8+= src_x + src_y*src_stride; +-// src += src_x + src_y*src_stride; +- +- ptmp= tmp + 3*tmp_step; +- block[0]= ptmp; +- ptmp+=tmp_step; +- pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h); ++#define mcf(dx,dy)\ ++ s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ ++ s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ ++ s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ ++ s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ ++ s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ ++ s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; + +- if(same_block(lt, rt)){ +- block[1]= block[0]; +- }else{ +- block[1]= ptmp; +- ptmp+=tmp_step; +- pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h); +- } ++ mcf( 0, 0) ++ mcf( 4, 0) ++ mcf( 8, 0) ++ mcf(12, 0) ++ mcf( 0, 4) ++ mcf( 4, 4) ++ mcf( 8, 4) ++ mcf(12, 4) ++ mcf( 0, 8) ++ mcf( 4, 8) ++ mcf( 8, 8) ++ mcf(12, 8) ++ mcf( 0,12) ++ mcf( 4,12) ++ mcf( 8,12) ++ mcf(12,12) + +- if(same_block(lt, lb)){ +- block[2]= block[0]; +- }else if(same_block(rt, lb)){ +- block[2]= block[1]; +- }else{ +- block[2]= ptmp; +- ptmp+=tmp_step; +- pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h); +- } +- +- if(same_block(lt, rb) ){ +- block[3]= block[0]; +- }else if(same_block(rt, rb)){ +- block[3]= block[1]; +- }else if(same_block(lb, rb)){ +- block[3]= block[2]; +- }else{ +- block[3]= ptmp; +- pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h); +- } +-#if 0 +- for(y=0; y>1); +- for(x=0; x>1); +- for(x=0; x>1); +- uint8_t *obmc4= obmc3+ (obmc_stride>>1); +- for(x=0; xdwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); +- }else{ +- for(y=0; y>1); +- const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); +- const uint8_t *obmc4= obmc3+ (obmc_stride>>1); +- for(x=0; x>= 8 - FRAC_BITS; +- } +- if(add){ +- v += dst[x + y*dst_stride]; +- v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; +- if(v&(~255)) v= ~(v>>31); +- dst8[x + y*src_stride] = v; +- }else{ +- dst[x + y*dst_stride] -= v; +- } +- } +- } +- } +-#endif /* 0 */ +-} +- +-static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){ +- Plane *p= &s->plane[plane_index]; +- const int mb_w= s->b_width << s->block_max_depth; +- const int mb_h= s->b_height << s->block_max_depth; +- int x, y, mb_x; +- int block_size = MB_SIZE >> s->block_max_depth; +- int block_w = plane_index ? block_size/2 : block_size; +- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; +- int obmc_stride= plane_index ? block_size : 2*block_size; +- int ref_stride= s->current_picture.linesize[plane_index]; +- uint8_t *dst8= s->current_picture.data[plane_index]; +- int w= p->width; +- int h= p->height; +- +- if(s->keyframe || (s->avctx->debug&512)){ +- if(mb_y==mb_h) +- return; +- +- if(add){ +- for(y=block_w*mb_y; yline[y]; +- for(x=0; x>= FRAC_BITS; +- if(v&(~255)) v= ~(v>>31); +- dst8[x + y*ref_stride]= v; +- } +- } +- }else{ +- for(y=block_w*mb_y; yline[y]; +- for(x=0; xplane[plane_index]; +- const int mb_w= s->b_width << s->block_max_depth; +- const int mb_h= s->b_height << s->block_max_depth; +- int x, y, mb_x; +- int block_size = MB_SIZE >> s->block_max_depth; +- int block_w = plane_index ? block_size/2 : block_size; +- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; +- const int obmc_stride= plane_index ? block_size : 2*block_size; +- int ref_stride= s->current_picture.linesize[plane_index]; +- uint8_t *dst8= s->current_picture.data[plane_index]; +- int w= p->width; +- int h= p->height; +- +- if(s->keyframe || (s->avctx->debug&512)){ +- if(mb_y==mb_h) +- return; +- +- if(add){ +- for(y=block_w*mb_y; y>= FRAC_BITS; +- if(v&(~255)) v= ~(v>>31); +- dst8[x + y*ref_stride]= v; +- } +- } +- }else{ +- for(y=block_w*mb_y; yb_height << s->block_max_depth; +- int mb_y; +- for(mb_y=0; mb_y<=mb_h; mb_y++) +- predict_slice(s, buf, plane_index, add, mb_y); +-} +- +-static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ +- const int w= b->width; +- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); +- const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); +- const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; +- int x,y; +- +- if(s->qlog == LOSSLESS_QLOG) return; +- +- for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; +- for(x=0; x>(QEXPSHIFT)); //FIXME try different bias +- }else if(i>0){ +- line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); +- } +- } +- } +-} +- +-static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ +- const int w= b->width; +- int x,y; +- +- IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning +- IDWTELEM * prev; +- +- if (start_y != 0) +- line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; +- +- for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; +- for(x=0; xspatial_decomposition_count; level++){ +- for(orientation=level ? 1:0; orientation<4; orientation++){ +- int q; +- if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; +- else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; +- else q= get_symbol(&s->c, s->header_state, 1); +- s->plane[plane_index].band[level][orientation].qlog= q; +- } +- } +- } +-} +- +-#define GET_S(dst, check) \ +- tmp= get_symbol(&s->c, s->header_state, 0);\ +- if(!(check)){\ +- av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ +- return -1;\ +- }\ +- dst= tmp; +- +-static int decode_header(SnowContext *s){ +- int plane_index, tmp; +- uint8_t kstate[32]; +- +- memset(kstate, MID_STATE, sizeof(kstate)); +- +- s->keyframe= get_rac(&s->c, kstate); +- if(s->keyframe || s->always_reset){ +- reset_contexts(s); +- s->spatial_decomposition_type= +- s->qlog= +- s->qbias= +- s->mv_scale= +- s->block_max_depth= 0; +- } +- if(s->keyframe){ +- GET_S(s->version, tmp <= 0U) +- s->always_reset= get_rac(&s->c, s->header_state); +- s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); +- s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); +- GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) +- s->colorspace_type= get_symbol(&s->c, s->header_state, 0); +- s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); +- s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); +- s->spatial_scalability= get_rac(&s->c, s->header_state); +-// s->rate_scalability= get_rac(&s->c, s->header_state); +- GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) +- s->max_ref_frames++; +- +- decode_qlogs(s); +- } +- +- if(!s->keyframe){ +- if(get_rac(&s->c, s->header_state)){ +- for(plane_index=0; plane_index<2; plane_index++){ +- int htaps, i, sum=0; +- Plane *p= &s->plane[plane_index]; +- p->diag_mc= get_rac(&s->c, s->header_state); +- htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; +- if((unsigned)htaps > HTAPS_MAX || htaps==0) +- return -1; +- p->htaps= htaps; +- for(i= htaps/2; i; i--){ +- p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); +- sum += p->hcoeff[i]; +- } +- p->hcoeff[0]= 32-sum; +- } +- s->plane[2].diag_mc= s->plane[1].diag_mc; +- s->plane[2].htaps = s->plane[1].htaps; +- memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); +- } +- if(get_rac(&s->c, s->header_state)){ +- GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) +- decode_qlogs(s); +- } +- } +- +- s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); +- if(s->spatial_decomposition_type > 1U){ +- av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); +- return -1; +- } +- if(FFMIN(s->avctx-> width>>s->chroma_h_shift, +- s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ +- av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); +- return -1; +- } +- +- s->qlog += get_symbol(&s->c, s->header_state, 1); +- s->mv_scale += get_symbol(&s->c, s->header_state, 1); +- s->qbias += get_symbol(&s->c, s->header_state, 1); +- s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); +- if(s->block_max_depth > 1 || s->block_max_depth < 0){ +- av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); +- s->block_max_depth= 0; +- return -1; +- } +- +- return 0; +-} +- +-static void init_qexp(void){ +- int i; +- double v=128; +- +- for(i=0; ipriv_data; +- int width, height; +- int i, j; +- +- s->avctx= avctx; +- s->max_ref_frames=1; //just make sure its not an invalid value in case of no initial keyframe +- +- dsputil_init(&s->dsp, avctx); +- ff_dwt_init(&s->dwt); +- +-#define mcf(dx,dy)\ +- s->dsp.put_qpel_pixels_tab [0][dy+dx/4]=\ +- s->dsp.put_no_rnd_qpel_pixels_tab[0][dy+dx/4]=\ +- s->dsp.put_h264_qpel_pixels_tab[0][dy+dx/4];\ +- s->dsp.put_qpel_pixels_tab [1][dy+dx/4]=\ +- s->dsp.put_no_rnd_qpel_pixels_tab[1][dy+dx/4]=\ +- s->dsp.put_h264_qpel_pixels_tab[1][dy+dx/4]; +- +- mcf( 0, 0) +- mcf( 4, 0) +- mcf( 8, 0) +- mcf(12, 0) +- mcf( 0, 4) +- mcf( 4, 4) +- mcf( 8, 4) +- mcf(12, 4) +- mcf( 0, 8) +- mcf( 4, 8) +- mcf( 8, 8) +- mcf(12, 8) +- mcf( 0,12) +- mcf( 4,12) +- mcf( 8,12) +- mcf(12,12) +- +-#define mcfh(dx,dy)\ +- s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ +- s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ +- mc_block_hpel ## dx ## dy ## 16;\ +- s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ +- s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ +- mc_block_hpel ## dx ## dy ## 8; ++#define mcfh(dx,dy)\ ++ s->dsp.put_pixels_tab [0][dy/4+dx/8]=\ ++ s->dsp.put_no_rnd_pixels_tab[0][dy/4+dx/8]=\ ++ mc_block_hpel ## dx ## dy ## 16;\ ++ s->dsp.put_pixels_tab [1][dy/4+dx/8]=\ ++ s->dsp.put_no_rnd_pixels_tab[1][dy/4+dx/8]=\ ++ mc_block_hpel ## dx ## dy ## 8; + + mcfh(0, 0) + mcfh(8, 0) + mcfh(0, 8) + mcfh(8, 8) + +- if(!qexp[0]) +- init_qexp(); ++ init_qexp(); + + // dec += FFMAX(s->chroma_h_shift, s->chroma_v_shift); + +@@ -1742,7 +451,7 @@ + return 0; + } + +-static int common_init_after_header(AVCodecContext *avctx){ ++int ff_snow_common_init_after_header(AVCodecContext *avctx) { + SnowContext *s = avctx->priv_data; + int plane_index, level, orientation; + +@@ -1795,130 +504,11 @@ + return 0; + } + +-#define QUANTIZE2 0 +- +-#if QUANTIZE2==1 +-#define Q2_STEP 8 +- +-static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ +- SubBand *b= &p->band[level][orientation]; +- int x, y; +- int xo=0; +- int yo=0; +- int step= 1 << (s->spatial_decomposition_count - level); +- +- if(orientation&1) +- xo= step>>1; +- if(orientation&2) +- yo= step>>1; +- +- //FIXME bias for nonzero ? +- //FIXME optimize +- memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); +- for(y=0; yheight; y++){ +- for(x=0; xwidth; x++){ +- int sx= (x-xo + step/2) / step / Q2_STEP; +- int sy= (y-yo + step/2) / step / Q2_STEP; +- int v= r0[x + y*p->width] - r1[x + y*p->width]; +- assert(sx>=0 && sy>=0 && sx < score_stride); +- v= ((v+8)>>4)<<4; +- score[sx + sy*score_stride] += v*v; +- assert(score[sx + sy*score_stride] >= 0); +- } +- } +-} +- +-static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ +- int level, orientation; +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); +- +- dequantize(s, b, dst, b->stride); +- } +- } +-} +- +-static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ +- int level, orientation, ys, xs, x, y, pass; +- IDWTELEM best_dequant[height * stride]; +- IDWTELEM idwt2_buffer[height * stride]; +- const int score_stride= (width + 10)/Q2_STEP; +- int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size +- int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size +- int threshold= (s->m.lambda * s->m.lambda) >> 6; +- +- //FIXME pass the copy cleanly ? +- +-// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); +- ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); +- DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); +- assert(src == b->buf); // code does not depend on this but it is true currently +- +- quantize(s, b, dst, src, b->stride, s->qbias); +- } +- } +- for(pass=0; pass<1; pass++){ +- if(s->qbias == 0) //keyframe +- continue; +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); +- IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); +- +- for(ys= 0; ysspatial_decomposition_count); +- find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); +- memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); +- for(y=ys; yheight; y+= Q2_STEP){ +- for(x=xs; xwidth; x+= Q2_STEP){ +- if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; +- if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; +- //FIXME try more than just -- +- } +- } +- dequantize_all(s, p, idwt2_buffer, width, height); +- ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); +- find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); +- for(y=ys; yheight; y+= Q2_STEP){ +- for(x=xs; xwidth; x+= Q2_STEP){ +- int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; +- if(score[score_idx] <= best_score[score_idx] + threshold){ +- best_score[score_idx]= score[score_idx]; +- if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; +- if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; +- //FIXME copy instead +- } +- } +- } +- } +- } +- } +- } +- } +- memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end +-} +- +-#endif /* QUANTIZE2==1 */ +- + #define USE_HALFPEL_PLANE 0 + + static void halfpel_interpol(SnowContext *s, uint8_t *halfpel[4][4], AVFrame *frame){ + int p,x,y; + +- assert(!(s->avctx->flags & CODEC_FLAG_EMU_EDGE)); +- + for(p=0; p<3; p++){ + int is_chroma= !!p; + int w= s->avctx->width >>is_chroma; +@@ -1926,9 +516,9 @@ + int ls= frame->linesize[p]; + uint8_t *src= frame->data[p]; + +- halfpel[1][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); +- halfpel[2][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); +- halfpel[3][p]= (uint8_t*)av_malloc(ls * (h+2*EDGE_WIDTH)) + EDGE_WIDTH*(1+ls); ++ halfpel[1][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); ++ halfpel[2][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); ++ halfpel[3][p] = (uint8_t*) av_malloc(ls * (h + 2 * EDGE_WIDTH)) + EDGE_WIDTH * (1 + ls); + + halfpel[0][p]= src; + for(y=0; ypriv_data; + int i; + +@@ -1970,18 +561,24 @@ + } + } + +-static int frame_start(SnowContext *s){ ++int ff_snow_frame_start(SnowContext *s){ + AVFrame tmp; + int w= s->avctx->width; //FIXME round up to x16 ? + int h= s->avctx->height; + +- if(s->current_picture.data[0]){ +- s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); +- s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); +- s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); ++ if (s->current_picture.data[0] && !(s->avctx->flags&CODEC_FLAG_EMU_EDGE)) { ++ s->dsp.draw_edges(s->current_picture.data[0], ++ s->current_picture.linesize[0], w , h , ++ EDGE_WIDTH , EDGE_WIDTH , EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(s->current_picture.data[1], ++ s->current_picture.linesize[1], w>>1, h>>1, ++ EDGE_WIDTH/2, EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM); ++ s->dsp.draw_edges(s->current_picture.data[2], ++ s->current_picture.linesize[2], w>>1, h>>1, ++ EDGE_WIDTH/2, EDGE_WIDTH/2, EDGE_TOP | EDGE_BOTTOM); + } + +- release_buffer(s->avctx); ++ ff_snow_release_buffer(s->avctx); + + tmp= s->last_picture[s->max_ref_frames-1]; + memmove(s->last_picture+1, s->last_picture, (s->max_ref_frames-1)*sizeof(AVFrame)); +@@ -2005,7 +602,7 @@ + } + } + +- s->current_picture.reference= 1; ++ s->current_picture.reference= 3; + if(s->avctx->get_buffer(s->avctx, &s->current_picture) < 0){ + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; +@@ -2016,7 +613,8 @@ + return 0; + } + +-static av_cold void common_end(SnowContext *s){ ++av_cold void ff_snow_common_end(SnowContext *s) ++{ + int plane_index, level, orientation, i; + + av_freep(&s->spatial_dwt_buffer); +@@ -2053,2097 +651,3 @@ + s->avctx->release_buffer(s->avctx, &s->current_picture); + } + +-static av_cold int decode_init(AVCodecContext *avctx) +-{ +- avctx->pix_fmt= PIX_FMT_YUV420P; +- +- common_init(avctx); +- +- return 0; +-} +- +-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt){ +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- SnowContext *s = avctx->priv_data; +- RangeCoder * const c= &s->c; +- int bytes_read; +- AVFrame *picture = data; +- int level, orientation, plane_index; +- +- ff_init_range_decoder(c, buf, buf_size); +- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); +- +- s->current_picture.pict_type= FF_I_TYPE; //FIXME I vs. P +- if(decode_header(s)<0) +- return -1; +- common_init_after_header(avctx); +- +- // realloc slice buffer for the case that spatial_decomposition_count changed +- ff_slice_buffer_destroy(&s->sb); +- ff_slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); +- +- for(plane_index=0; plane_index<3; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 +- && p->hcoeff[1]==-10 +- && p->hcoeff[2]==2; +- } +- +- alloc_blocks(s); +- +- if(frame_start(s) < 0) +- return -1; +- //keyframe flag duplication mess FIXME +- if(avctx->debug&FF_DEBUG_PICT_INFO) +- av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); +- +- decode_blocks(s); +- +- for(plane_index=0; plane_index<3; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- int w= p->width; +- int h= p->height; +- int x, y; +- int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ +- +- if(s->avctx->debug&2048){ +- memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); +- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); +- +- for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; +- s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; +- } +- } +- } +- +- { +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- unpack_coeffs(s, b, b->parent, orientation); +- } +- } +- } +- +- { +- const int mb_h= s->b_height << s->block_max_depth; +- const int block_size = MB_SIZE >> s->block_max_depth; +- const int block_w = plane_index ? block_size/2 : block_size; +- int mb_y; +- DWTCompose cs[MAX_DECOMPOSITIONS]; +- int yd=0, yq=0; +- int y; +- int end_y; +- +- ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); +- for(mb_y=0; mb_y<=mb_h; mb_y++){ +- +- int slice_starty = block_w*mb_y; +- int slice_h = block_w*(mb_y+1); +- if (!(s->keyframe || s->avctx->debug&512)){ +- slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); +- slice_h -= (block_w >> 1); +- } +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- int start_y; +- int end_y; +- int our_mb_start = mb_y; +- int our_mb_end = (mb_y + 1); +- const int extra= 3; +- start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); +- end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); +- if (!(s->keyframe || s->avctx->debug&512)){ +- start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); +- end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); +- } +- start_y = FFMIN(b->height, start_y); +- end_y = FFMIN(b->height, end_y); +- +- if (start_y != end_y){ +- if (orientation == 0){ +- SubBand * correlate_band = &p->band[0][0]; +- int correlate_end_y = FFMIN(b->height, end_y + 1); +- int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); +- decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); +- correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); +- dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); +- } +- else +- decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); +- } +- } +- } +- +- for(; yddwt, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); +- } +- +- if(s->qlog == LOSSLESS_QLOG){ +- for(; yqsb, yq); +- for(x=0; xsb, s->spatial_idwt_buffer, plane_index, 1, mb_y); +- +- y = FFMIN(p->height, slice_starty); +- end_y = FFMIN(p->height, slice_h); +- while(y < end_y) +- ff_slice_buffer_release(&s->sb, y++); +- } +- +- ff_slice_buffer_flush(&s->sb); +- } +- +- } +- +- emms_c(); +- +- release_buffer(avctx); +- +- if(!(s->avctx->debug&2048)) +- *picture= s->current_picture; +- else +- *picture= s->mconly_picture; +- +- *data_size = sizeof(AVFrame); +- +- bytes_read= c->bytestream - c->bytestream_start; +- if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME +- +- return bytes_read; +-} +- +-static av_cold int decode_end(AVCodecContext *avctx) +-{ +- SnowContext *s = avctx->priv_data; +- +- ff_slice_buffer_destroy(&s->sb); +- +- common_end(s); +- +- return 0; +-} +- +-AVCodec ff_snow_decoder = { +- "snow", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SNOW, +- sizeof(SnowContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("Snow"), +-}; +- +-#if CONFIG_SNOW_ENCODER +-static av_cold int encode_init(AVCodecContext *avctx) +-{ +- SnowContext *s = avctx->priv_data; +- int plane_index; +- +- if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ +- av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" +- "Use vstrict=-2 / -strict -2 to use it anyway.\n"); +- return -1; +- } +- +- if(avctx->prediction_method == DWT_97 +- && (avctx->flags & CODEC_FLAG_QSCALE) +- && avctx->global_quality == 0){ +- av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); +- return -1; +- } +- +- s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type +- +- s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; +- s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; +- +- for(plane_index=0; plane_index<3; plane_index++){ +- s->plane[plane_index].diag_mc= 1; +- s->plane[plane_index].htaps= 6; +- s->plane[plane_index].hcoeff[0]= 40; +- s->plane[plane_index].hcoeff[1]= -10; +- s->plane[plane_index].hcoeff[2]= 2; +- s->plane[plane_index].fast_mc= 1; +- } +- +- common_init(avctx); +- alloc_blocks(s); +- +- s->version=0; +- +- s->m.avctx = avctx; +- s->m.flags = avctx->flags; +- s->m.bit_rate= avctx->bit_rate; +- +- s->m.me.temp = +- s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); +- s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); +- s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); +- s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); +- h263_encode_init(&s->m); //mv_penalty +- +- s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); +- +- if(avctx->flags&CODEC_FLAG_PASS1){ +- if(!avctx->stats_out) +- avctx->stats_out = av_mallocz(256); +- } +- if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ +- if(ff_rate_control_init(&s->m) < 0) +- return -1; +- } +- s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); +- +- avctx->coded_frame= &s->current_picture; +- switch(avctx->pix_fmt){ +-// case PIX_FMT_YUV444P: +-// case PIX_FMT_YUV422P: +- case PIX_FMT_YUV420P: +- case PIX_FMT_GRAY8: +-// case PIX_FMT_YUV411P: +-// case PIX_FMT_YUV410P: +- s->colorspace_type= 0; +- break; +-/* case PIX_FMT_RGB32: +- s->colorspace= 1; +- break;*/ +- default: +- av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); +- return -1; +- } +-// avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); +- s->chroma_h_shift= 1; +- s->chroma_v_shift= 1; +- +- ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); +- ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); +- +- s->avctx->get_buffer(s->avctx, &s->input_picture); +- +- if(s->avctx->me_method == ME_ITER){ +- int i; +- int size= s->b_width * s->b_height << 2*s->block_max_depth; +- for(i=0; imax_ref_frames; i++){ +- s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); +- s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); +- } +- } +- +- return 0; +-} +- +-//near copy & paste from dsputil, FIXME +-static int pix_sum(uint8_t * pix, int line_size, int w) +-{ +- int s, i, j; +- +- s = 0; +- for (i = 0; i < w; i++) { +- for (j = 0; j < w; j++) { +- s += pix[0]; +- pix ++; +- } +- pix += line_size - w; +- } +- return s; +-} +- +-//near copy & paste from dsputil, FIXME +-static int pix_norm1(uint8_t * pix, int line_size, int w) +-{ +- int s, i, j; +- uint32_t *sq = ff_squareTbl + 256; +- +- s = 0; +- for (i = 0; i < w; i++) { +- for (j = 0; j < w; j ++) { +- s += sq[pix[0]]; +- pix ++; +- } +- pix += line_size - w; +- } +- return s; +-} +- +-//FIXME copy&paste +-#define P_LEFT P[1] +-#define P_TOP P[2] +-#define P_TOPRIGHT P[3] +-#define P_MEDIAN P[4] +-#define P_MV1 P[9] +-#define FLAG_QPEL 1 //must be 1 +- +-static int encode_q_branch(SnowContext *s, int level, int x, int y){ +- uint8_t p_buffer[1024]; +- uint8_t i_buffer[1024]; +- uint8_t p_state[sizeof(s->block_state)]; +- uint8_t i_state[sizeof(s->block_state)]; +- RangeCoder pc, ic; +- uint8_t *pbbak= s->c.bytestream; +- uint8_t *pbbak_start= s->c.bytestream_start; +- int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; +- const int w= s->b_width << s->block_max_depth; +- const int h= s->b_height << s->block_max_depth; +- const int rem_depth= s->block_max_depth - level; +- const int index= (x + y*w) << rem_depth; +- const int block_w= 1<<(LOG2_MB_SIZE - level); +- int trx= (x+1)<block[index-1] : &null_block; +- const BlockNode *top = y ? &s->block[index-w] : &null_block; +- const BlockNode *right = trxblock[index+1] : &null_block; +- const BlockNode *bottom= tryblock[index+w] : &null_block; +- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; +- const BlockNode *tr = y && trxblock[index-w+(1<color[0]; +- int pcb= left->color[1]; +- int pcr= left->color[2]; +- int pmx, pmy; +- int mx=0, my=0; +- int l,cr,cb; +- const int stride= s->current_picture.linesize[0]; +- const int uvstride= s->current_picture.linesize[1]; +- uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, +- s->input_picture.data[1] + (x + y*uvstride)*block_w/2, +- s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; +- int P[10][2]; +- int16_t last_mv[3][2]; +- int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused +- const int shift= 1+qpel; +- MotionEstContext *c= &s->m.me; +- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); +- int mx_context= av_log2(2*FFABS(left->mx - top->mx)); +- int my_context= av_log2(2*FFABS(left->my - top->my)); +- int s_context= 2*left->level + 2*top->level + tl->level + tr->level; +- int ref, best_ref, ref_score, ref_mx, ref_my; +- +- assert(sizeof(s->block_state) >= 256); +- if(s->keyframe){ +- set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); +- return 0; +- } +- +-// clip predictors / edge ? +- +- P_LEFT[0]= left->mx; +- P_LEFT[1]= left->my; +- P_TOP [0]= top->mx; +- P_TOP [1]= top->my; +- P_TOPRIGHT[0]= tr->mx; +- P_TOPRIGHT[1]= tr->my; +- +- last_mv[0][0]= s->block[index].mx; +- last_mv[0][1]= s->block[index].my; +- last_mv[1][0]= right->mx; +- last_mv[1][1]= right->my; +- last_mv[2][0]= bottom->mx; +- last_mv[2][1]= bottom->my; +- +- s->m.mb_stride=2; +- s->m.mb_x= +- s->m.mb_y= 0; +- c->skip= 0; +- +- assert(c-> stride == stride); +- assert(c->uvstride == uvstride); +- +- c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); +- c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); +- c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); +- c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; +- +- c->xmin = - x*block_w - 16+3; +- c->ymin = - y*block_w - 16+3; +- c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; +- c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; +- +- if(P_LEFT[0] > (c->xmax<xmax< (c->ymax<ymax< (c->xmax<xmax< (c->ymax<ymax<xmin<xmin< (c->xmax<xmax< (c->ymax<ymax<pred_x= P_LEFT[0]; +- c->pred_y= P_LEFT[1]; +- } else { +- c->pred_x = P_MEDIAN[0]; +- c->pred_y = P_MEDIAN[1]; +- } +- +- score= INT_MAX; +- best_ref= 0; +- for(ref=0; refref_frames; ref++){ +- init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); +- +- ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, +- (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); +- +- assert(ref_mx >= c->xmin); +- assert(ref_mx <= c->xmax); +- assert(ref_my >= c->ymin); +- assert(ref_my <= c->ymax); +- +- ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); +- ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); +- ref_score+= 2*av_log2(2*ref)*c->penalty_factor; +- if(s->ref_mvs[ref]){ +- s->ref_mvs[ref][index][0]= ref_mx; +- s->ref_mvs[ref][index][1]= ref_my; +- s->ref_scores[ref][index]= ref_score; +- } +- if(score > ref_score){ +- score= ref_score; +- best_ref= ref; +- mx= ref_mx; +- my= ref_my; +- } +- } +- //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 +- +- // subpel search +- base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); +- pc= s->c; +- pc.bytestream_start= +- pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo +- memcpy(p_state, s->block_state, sizeof(s->block_state)); +- +- if(level!=s->block_max_depth) +- put_rac(&pc, &p_state[4 + s_context], 1); +- put_rac(&pc, &p_state[1 + left->type + top->type], 0); +- if(s->ref_frames > 1) +- put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); +- pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); +- put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); +- put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); +- p_len= pc.bytestream - pc.bytestream_start; +- score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; +- +- block_s= block_w*block_w; +- sum = pix_sum(current_data[0], stride, block_w); +- l= (sum + block_s/2)/block_s; +- iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; +- +- block_s= block_w*block_w>>2; +- sum = pix_sum(current_data[1], uvstride, block_w>>1); +- cb= (sum + block_s/2)/block_s; +-// iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; +- sum = pix_sum(current_data[2], uvstride, block_w>>1); +- cr= (sum + block_s/2)/block_s; +-// iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; +- +- ic= s->c; +- ic.bytestream_start= +- ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo +- memcpy(i_state, s->block_state, sizeof(s->block_state)); +- if(level!=s->block_max_depth) +- put_rac(&ic, &i_state[4 + s_context], 1); +- put_rac(&ic, &i_state[1 + left->type + top->type], 1); +- put_symbol(&ic, &i_state[32], l-pl , 1); +- put_symbol(&ic, &i_state[64], cb-pcb, 1); +- put_symbol(&ic, &i_state[96], cr-pcr, 1); +- i_len= ic.bytestream - ic.bytestream_start; +- iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; +- +-// assert(score==256*256*256*64-1); +- assert(iscore < 255*255*256 + s->lambda2*10); +- assert(iscore >= 0); +- assert(l>=0 && l<=255); +- assert(pl>=0 && pl<=255); +- +- if(level==0){ +- int varc= iscore >> 8; +- int vard= score >> 8; +- if (vard <= 64 || vard < varc) +- c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); +- else +- c->scene_change_score+= s->m.qscale; +- } +- +- if(level!=s->block_max_depth){ +- put_rac(&s->c, &s->block_state[4 + s_context], 0); +- score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); +- score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); +- score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); +- score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); +- score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead +- +- if(score2 < score && score2 < iscore) +- return score2; +- } +- +- if(iscore < score){ +- pred_mv(s, &pmx, &pmy, 0, left, top, tr); +- memcpy(pbbak, i_buffer, i_len); +- s->c= ic; +- s->c.bytestream_start= pbbak_start; +- s->c.bytestream= pbbak + i_len; +- set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); +- memcpy(s->block_state, i_state, sizeof(s->block_state)); +- return iscore; +- }else{ +- memcpy(pbbak, p_buffer, p_len); +- s->c= pc; +- s->c.bytestream_start= pbbak_start; +- s->c.bytestream= pbbak + p_len; +- set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); +- memcpy(s->block_state, p_state, sizeof(s->block_state)); +- return score; +- } +-} +- +-static void encode_q_branch2(SnowContext *s, int level, int x, int y){ +- const int w= s->b_width << s->block_max_depth; +- const int rem_depth= s->block_max_depth - level; +- const int index= (x + y*w) << rem_depth; +- int trx= (x+1)<block[index]; +- const BlockNode *left = x ? &s->block[index-1] : &null_block; +- const BlockNode *top = y ? &s->block[index-w] : &null_block; +- const BlockNode *tl = y && x ? &s->block[index-w-1] : left; +- const BlockNode *tr = y && trxblock[index-w+(1<color[0]; +- int pcb= left->color[1]; +- int pcr= left->color[2]; +- int pmx, pmy; +- int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); +- int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; +- int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; +- int s_context= 2*left->level + 2*top->level + tl->level + tr->level; +- +- if(s->keyframe){ +- set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); +- return; +- } +- +- if(level!=s->block_max_depth){ +- if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ +- put_rac(&s->c, &s->block_state[4 + s_context], 1); +- }else{ +- put_rac(&s->c, &s->block_state[4 + s_context], 0); +- encode_q_branch2(s, level+1, 2*x+0, 2*y+0); +- encode_q_branch2(s, level+1, 2*x+1, 2*y+0); +- encode_q_branch2(s, level+1, 2*x+0, 2*y+1); +- encode_q_branch2(s, level+1, 2*x+1, 2*y+1); +- return; +- } +- } +- if(b->type & BLOCK_INTRA){ +- pred_mv(s, &pmx, &pmy, 0, left, top, tr); +- put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); +- put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); +- put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); +- put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); +- set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); +- }else{ +- pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); +- put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); +- if(s->ref_frames > 1) +- put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); +- put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); +- put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); +- set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); +- } +-} +- +-static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ +- int i, x2, y2; +- Plane *p= &s->plane[plane_index]; +- const int block_size = MB_SIZE >> s->block_max_depth; +- const int block_w = plane_index ? block_size/2 : block_size; +- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; +- const int obmc_stride= plane_index ? block_size : 2*block_size; +- const int ref_stride= s->current_picture.linesize[plane_index]; +- uint8_t *src= s-> input_picture.data[plane_index]; +- IDWTELEM *dst= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned +- const int b_stride = s->b_width << s->block_max_depth; +- const int w= p->width; +- const int h= p->height; +- int index= mb_x + mb_y*b_stride; +- BlockNode *b= &s->block[index]; +- BlockNode backup= *b; +- int ab=0; +- int aa=0; +- +- b->type|= BLOCK_INTRA; +- b->color[plane_index]= 0; +- memset(dst, 0, obmc_stride*obmc_stride*sizeof(IDWTELEM)); +- +- for(i=0; i<4; i++){ +- int mb_x2= mb_x + (i &1) - 1; +- int mb_y2= mb_y + (i>>1) - 1; +- int x= block_w*mb_x2 + block_w/2; +- int y= block_w*mb_y2 + block_w/2; +- +- add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc, +- x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index); +- +- for(y2= FFMAX(y, 0); y2h) obmc_v += obmc[index - block_w*obmc_stride]; +- if(x+block_w>w) obmc_v += obmc[index - block_w]; +- //FIXME precalculate this or simplify it somehow else +- +- d = -dst[index] + (1<<(FRAC_BITS-1)); +- dst[index] = d; +- ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; +- aa += obmc_v * obmc_v; //FIXME precalculate this +- } +- } +- } +- *b= backup; +- +- return av_clip(((ab<b_width << s->block_max_depth; +- const int b_height = s->b_height<< s->block_max_depth; +- int index= x + y*b_stride; +- const BlockNode *b = &s->block[index]; +- const BlockNode *left = x ? &s->block[index-1] : &null_block; +- const BlockNode *top = y ? &s->block[index-b_stride] : &null_block; +- const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left; +- const BlockNode *tr = y && x+wblock[index-b_stride+w] : tl; +- int dmx, dmy; +-// int mx_context= av_log2(2*FFABS(left->mx - top->mx)); +-// int my_context= av_log2(2*FFABS(left->my - top->my)); +- +- if(x<0 || x>=b_stride || y>=b_height) +- return 0; +-/* +-1 0 0 +-01X 1-2 1 +-001XX 3-6 2-3 +-0001XXX 7-14 4-7 +-00001XXXX 15-30 8-15 +-*/ +-//FIXME try accurate rate +-//FIXME intra and inter predictors if surrounding blocks are not the same type +- if(b->type & BLOCK_INTRA){ +- return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) +- + av_log2(2*FFABS(left->color[1] - b->color[1])) +- + av_log2(2*FFABS(left->color[2] - b->color[2]))); +- }else{ +- pred_mv(s, &dmx, &dmy, b->ref, left, top, tr); +- dmx-= b->mx; +- dmy-= b->my; +- return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda +- + av_log2(2*FFABS(dmy)) +- + av_log2(2*b->ref)); +- } +-} +- +-static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){ +- Plane *p= &s->plane[plane_index]; +- const int block_size = MB_SIZE >> s->block_max_depth; +- const int block_w = plane_index ? block_size/2 : block_size; +- const int obmc_stride= plane_index ? block_size : 2*block_size; +- const int ref_stride= s->current_picture.linesize[plane_index]; +- uint8_t *dst= s->current_picture.data[plane_index]; +- uint8_t *src= s-> input_picture.data[plane_index]; +- IDWTELEM *pred= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; +- uint8_t *cur = s->scratchbuf; +- uint8_t tmp[ref_stride*(2*MB_SIZE+HTAPS_MAX-1)]; +- const int b_stride = s->b_width << s->block_max_depth; +- const int b_height = s->b_height<< s->block_max_depth; +- const int w= p->width; +- const int h= p->height; +- int distortion; +- int rate= 0; +- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); +- int sx= block_w*mb_x - block_w/2; +- int sy= block_w*mb_y - block_w/2; +- int x0= FFMAX(0,-sx); +- int y0= FFMAX(0,-sy); +- int x1= FFMIN(block_w*2, w-sx); +- int y1= FFMIN(block_w*2, h-sy); +- int i,x,y; +- +- pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h); +- +- for(y=y0; y= LOG2_OBMC_MAX +- int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX); +-#else +- int v = (cur1[x] * obmc1[x] + (1<<(LOG2_OBMC_MAX - FRAC_BITS-1))) >> (LOG2_OBMC_MAX - FRAC_BITS); +-#endif +- v = (v + pred1[x]) >> FRAC_BITS; +- if(v&(~255)) v= ~(v>>31); +- dst1[x] = v; +- } +- } +- +- /* copy the regions where obmc[] = (uint8_t)256 */ +- if(LOG2_OBMC_MAX == 8 +- && (mb_x == 0 || mb_x == b_stride-1) +- && (mb_y == 0 || mb_y == b_height-1)){ +- if(mb_x == 0) +- x1 = block_w; +- else +- x0 = block_w; +- if(mb_y == 0) +- y1 = block_w; +- else +- y0 = block_w; +- for(y=y0; yavctx->me_cmp == FF_CMP_W97) +- distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); +- else if(s->avctx->me_cmp == FF_CMP_W53) +- distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); +- else{ +- distortion = 0; +- for(i=0; i<4; i++){ +- int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride; +- distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16); +- } +- } +- }else{ +- assert(block_w==8); +- distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); +- } +- +- if(plane_index==0){ +- for(i=0; i<4; i++){ +-/* ..RRr +- * .RXx. +- * rxx.. +- */ +- rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1); +- } +- if(mb_x == b_stride-2) +- rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1); +- } +- return distortion + rate*penalty_factor; +-} +- +-static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ +- int i, y2; +- Plane *p= &s->plane[plane_index]; +- const int block_size = MB_SIZE >> s->block_max_depth; +- const int block_w = plane_index ? block_size/2 : block_size; +- const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; +- const int obmc_stride= plane_index ? block_size : 2*block_size; +- const int ref_stride= s->current_picture.linesize[plane_index]; +- uint8_t *dst= s->current_picture.data[plane_index]; +- uint8_t *src= s-> input_picture.data[plane_index]; +- //FIXME zero_dst is const but add_yblock changes dst if add is 0 (this is never the case for dst=zero_dst +- // const has only been removed from zero_dst to suppress a warning +- static IDWTELEM zero_dst[4096]; //FIXME +- const int b_stride = s->b_width << s->block_max_depth; +- const int w= p->width; +- const int h= p->height; +- int distortion= 0; +- int rate= 0; +- const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); +- +- for(i=0; i<9; i++){ +- int mb_x2= mb_x + (i%3) - 1; +- int mb_y2= mb_y + (i/3) - 1; +- int x= block_w*mb_x2 + block_w/2; +- int y= block_w*mb_y2 + block_w/2; +- +- add_yblock(s, 0, NULL, zero_dst, dst, obmc, +- x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index); +- +- //FIXME find a cleaner/simpler way to skip the outside stuff +- for(y2= y; y2<0; y2++) +- memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); +- for(y2= h; y2 w){ +- for(y2= y; y2dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w); +- } +- +- if(plane_index==0){ +- BlockNode *b= &s->block[mb_x+mb_y*b_stride]; +- int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1); +- +-/* ..RRRr +- * .RXXx. +- * .RXXx. +- * rxxx. +- */ +- if(merged) +- rate = get_block_bits(s, mb_x, mb_y, 2); +- for(i=merged?4:0; i<9; i++){ +- static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}}; +- rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1); +- } +- } +- return distortion + rate*penalty_factor; +-} +- +-static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ +- const int w= b->width; +- const int h= b->height; +- int x, y; +- +- if(1){ +- int run=0; +- int runs[w*h]; +- int run_index=0; +- int max_index; +- +- for(y=0; y 1){ +- if(orientation==1) ll= src[y + (x-2)*stride]; +- else ll= src[x - 2 + y*stride]; +- }*/ +- } +- if(parent){ +- int px= x>>1; +- int py= y>>1; +- if(pxparent->width && pyparent->height) +- p= parent[px + py*2*stride]; +- } +- if(!(/*ll|*/l|lt|t|rt|p)){ +- if(v){ +- runs[run_index++]= run; +- run=0; +- }else{ +- run++; +- } +- } +- } +- } +- max_index= run_index; +- runs[run_index++]= run; +- run_index=0; +- run= runs[run_index++]; +- +- put_symbol2(&s->c, b->state[30], max_index, 0); +- if(run_index <= max_index) +- put_symbol2(&s->c, b->state[1], run, 3); +- +- for(y=0; yc.bytestream_end - s->c.bytestream < w*40){ +- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); +- return -1; +- } +- for(x=0; x 1){ +- if(orientation==1) ll= src[y + (x-2)*stride]; +- else ll= src[x - 2 + y*stride]; +- }*/ +- } +- if(parent){ +- int px= x>>1; +- int py= y>>1; +- if(pxparent->width && pyparent->height) +- p= parent[px + py*2*stride]; +- } +- if(/*ll|*/l|lt|t|rt|p){ +- int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); +- +- put_rac(&s->c, &b->state[0][context], !!v); +- }else{ +- if(!run){ +- run= runs[run_index++]; +- +- if(run_index <= max_index) +- put_symbol2(&s->c, b->state[1], run, 3); +- assert(v); +- }else{ +- run--; +- assert(!v); +- } +- } +- if(v){ +- int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); +- int l2= 2*FFABS(l) + (l<0); +- int t2= 2*FFABS(t) + (t<0); +- +- put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); +- put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0); +- } +- } +- } +- } +- return 0; +-} +- +-static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ +-// encode_subband_qtree(s, b, src, parent, stride, orientation); +-// encode_subband_z0run(s, b, src, parent, stride, orientation); +- return encode_subband_c0run(s, b, src, parent, stride, orientation); +-// encode_subband_dzr(s, b, src, parent, stride, orientation); +-} +- +-static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, const uint8_t *obmc_edged, int *best_rd){ +- const int b_stride= s->b_width << s->block_max_depth; +- BlockNode *block= &s->block[mb_x + mb_y * b_stride]; +- BlockNode backup= *block; +- int rd, index, value; +- +- assert(mb_x>=0 && mb_y>=0); +- assert(mb_xcolor[0] = p[0]; +- block->color[1] = p[1]; +- block->color[2] = p[2]; +- block->type |= BLOCK_INTRA; +- }else{ +- index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1); +- value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12); +- if(s->me_cache[index] == value) +- return 0; +- s->me_cache[index]= value; +- +- block->mx= p[0]; +- block->my= p[1]; +- block->type &= ~BLOCK_INTRA; +- } +- +- rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged); +- +-//FIXME chroma +- if(rd < *best_rd){ +- *best_rd= rd; +- return 1; +- }else{ +- *block= backup; +- return 0; +- } +-} +- +-/* special case for int[2] args we discard afterwards, +- * fixes compilation problem with gcc 2.95 */ +-static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ +- int p[2] = {p0, p1}; +- return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); +-} +- +-static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){ +- const int b_stride= s->b_width << s->block_max_depth; +- BlockNode *block= &s->block[mb_x + mb_y * b_stride]; +- BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]}; +- int rd, index, value; +- +- assert(mb_x>=0 && mb_y>=0); +- assert(mb_xme_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); +- if(s->me_cache[index] == value) +- return 0; +- s->me_cache[index]= value; +- +- block->mx= p0; +- block->my= p1; +- block->ref= ref; +- block->type &= ~BLOCK_INTRA; +- block[1]= block[b_stride]= block[b_stride+1]= *block; +- +- rd= get_4block_rd(s, mb_x, mb_y, 0); +- +-//FIXME chroma +- if(rd < *best_rd){ +- *best_rd= rd; +- return 1; +- }else{ +- block[0]= backup[0]; +- block[1]= backup[1]; +- block[b_stride]= backup[2]; +- block[b_stride+1]= backup[3]; +- return 0; +- } +-} +- +-static void iterative_me(SnowContext *s){ +- int pass, mb_x, mb_y; +- const int b_width = s->b_width << s->block_max_depth; +- const int b_height= s->b_height << s->block_max_depth; +- const int b_stride= b_width; +- int color[3]; +- +- { +- RangeCoder r = s->c; +- uint8_t state[sizeof(s->block_state)]; +- memcpy(state, s->block_state, sizeof(s->block_state)); +- for(mb_y= 0; mb_yb_height; mb_y++) +- for(mb_x= 0; mb_xb_width; mb_x++) +- encode_q_branch(s, 0, mb_x, mb_y); +- s->c = r; +- memcpy(s->block_state, state, sizeof(s->block_state)); +- } +- +- for(pass=0; pass<25; pass++){ +- int change= 0; +- +- for(mb_y= 0; mb_yblock[index]; +- BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL; +- BlockNode *lb = mb_x ? &s->block[index -1] : NULL; +- BlockNode *rb = mb_x+1block[index +1] : NULL; +- BlockNode *bb = mb_y+1block[index+b_stride ] : NULL; +- BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL; +- BlockNode *trb= mb_x+1block[index-b_stride+1] : NULL; +- BlockNode *blb= mb_x && mb_y+1block[index+b_stride-1] : NULL; +- BlockNode *brb= mb_x+1block[index+b_stride+1] : NULL; +- const int b_w= (MB_SIZE >> s->block_max_depth); +- uint8_t obmc_edged[b_w*2][b_w*2]; +- +- if(pass && (block->type & BLOCK_OPT)) +- continue; +- block->type |= BLOCK_OPT; +- +- backup= *block; +- +- if(!s->me_cache_generation) +- memset(s->me_cache, 0, sizeof(s->me_cache)); +- s->me_cache_generation += 1<<22; +- +- //FIXME precalculate +- { +- int x, y; +- memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); +- if(mb_x==0) +- for(y=0; y input_picture.data[0]; +- uint8_t *dst= s->current_picture.data[0]; +- const int stride= s->current_picture.linesize[0]; +- const int block_w= MB_SIZE >> s->block_max_depth; +- const int sx= block_w*mb_x - block_w/2; +- const int sy= block_w*mb_y - block_w/2; +- const int w= s->plane[0].width; +- const int h= s->plane[0].height; +- int y; +- +- for(y=sy; y<0; y++) +- memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); +- for(y=h; y w){ +- for(y=sy; y 0 && (block->type&BLOCK_INTRA)){ +- int color0[3]= {block->color[0], block->color[1], block->color[2]}; +- check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd); +- }else +- check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd); +- +- ref_b= *block; +- ref_rd= best_rd; +- for(ref=0; ref < s->ref_frames; ref++){ +- int16_t (*mvr)[2]= &s->ref_mvs[ref][index]; +- if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold +- continue; +- block->ref= ref; +- best_rd= INT_MAX; +- +- check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd); +- check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd); +- if(tb) +- check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd); +- if(lb) +- check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd); +- if(rb) +- check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); +- if(bb) +- check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); +- +- /* fullpel ME */ +- //FIXME avoid subpel interpolation / round to nearest integer +- do{ +- dia_change=0; +- for(i=0; iavctx->dia_size, 1); i++){ +- for(j=0; jmx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); +- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); +- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); +- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); +- } +- } +- }while(dia_change); +- /* subpel ME */ +- do{ +- static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; +- dia_change=0; +- for(i=0; i<8; i++) +- dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd); +- }while(dia_change); +- //FIXME or try the standard 2 pass qpel or similar +- +- mvr[0][0]= block->mx; +- mvr[0][1]= block->my; +- if(ref_rd > best_rd){ +- ref_rd= best_rd; +- ref_b= *block; +- } +- } +- best_rd= ref_rd; +- *block= ref_b; +-#if 1 +- check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd); +- //FIXME RD style color selection +-#endif +- if(!same_block(block, &backup)){ +- if(tb ) tb ->type &= ~BLOCK_OPT; +- if(lb ) lb ->type &= ~BLOCK_OPT; +- if(rb ) rb ->type &= ~BLOCK_OPT; +- if(bb ) bb ->type &= ~BLOCK_OPT; +- if(tlb) tlb->type &= ~BLOCK_OPT; +- if(trb) trb->type &= ~BLOCK_OPT; +- if(blb) blb->type &= ~BLOCK_OPT; +- if(brb) brb->type &= ~BLOCK_OPT; +- change ++; +- } +- } +- } +- av_log(s->avctx, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); +- if(!change) +- break; +- } +- +- if(s->block_max_depth == 1){ +- int change= 0; +- for(mb_y= 0; mb_yblock[index]; +- b[1]= b[0]+1; +- b[2]= b[0]+b_stride; +- b[3]= b[2]+1; +- if(same_block(b[0], b[1]) && +- same_block(b[0], b[2]) && +- same_block(b[0], b[3])) +- continue; +- +- if(!s->me_cache_generation) +- memset(s->me_cache, 0, sizeof(s->me_cache)); +- s->me_cache_generation += 1<<22; +- +- init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0); +- +- //FIXME more multiref search? +- check_4block_inter(s, mb_x, mb_y, +- (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2, +- (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd); +- +- for(i=0; i<4; i++) +- if(!(b[i]->type&BLOCK_INTRA)) +- check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); +- +- if(init_rd != best_rd) +- change++; +- } +- } +- av_log(s->avctx, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); +- } +-} +- +-static void encode_blocks(SnowContext *s, int search){ +- int x, y; +- int w= s->b_width; +- int h= s->b_height; +- +- if(s->avctx->me_method == ME_ITER && !s->keyframe && search) +- iterative_me(s); +- +- for(y=0; yc.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit +- av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); +- return; +- } +- for(x=0; xavctx->me_method == ME_ITER || !search) +- encode_q_branch2(s, 0, x, y); +- else +- encode_q_branch (s, 0, x, y); +- } +- } +-} +- +-static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias){ +- const int w= b->width; +- const int h= b->height; +- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); +- const int qmul= qexp[qlog&(QROOT-1)]<<((qlog>>QSHIFT) + ENCODER_EXTRA_BITS); +- int x,y, thres1, thres2; +- +- if(s->qlog == LOSSLESS_QLOG){ +- for(y=0; y>3; +- thres1= ((qmul - bias)>>QEXPSHIFT) - 1; +- thres2= 2*thres1; +- +- if(!bias){ +- for(y=0; y thres2){ +- if(i>=0){ +- i<<= QEXPSHIFT; +- i/= qmul; //FIXME optimize +- dst[x + y*stride]= i; +- }else{ +- i= -i; +- i<<= QEXPSHIFT; +- i/= qmul; //FIXME optimize +- dst[x + y*stride]= -i; +- } +- }else +- dst[x + y*stride]= 0; +- } +- } +- }else{ +- for(y=0; y thres2){ +- if(i>=0){ +- i<<= QEXPSHIFT; +- i= (i + bias) / qmul; //FIXME optimize +- dst[x + y*stride]= i; +- }else{ +- i= -i; +- i<<= QEXPSHIFT; +- i= (i + bias) / qmul; //FIXME optimize +- dst[x + y*stride]= -i; +- } +- }else +- dst[x + y*stride]= 0; +- } +- } +- } +-} +- +-static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ +- const int w= b->width; +- const int h= b->height; +- const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); +- const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); +- const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; +- int x,y; +- +- if(s->qlog == LOSSLESS_QLOG) return; +- +- for(y=0; y>(QEXPSHIFT)); //FIXME try different bias +- }else if(i>0){ +- src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT)); +- } +- } +- } +-} +- +-static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ +- const int w= b->width; +- const int h= b->height; +- int x,y; +- +- for(y=h-1; y>=0; y--){ +- for(x=w-1; x>=0; x--){ +- int i= x + y*stride; +- +- if(x){ +- if(use_median){ +- if(y && x+1width; +- const int h= b->height; +- int x,y; +- +- for(y=0; yspatial_decomposition_count; level++){ +- for(orientation=level ? 1:0; orientation<4; orientation++){ +- if(orientation==2) continue; +- put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); +- } +- } +- } +-} +- +-static void encode_header(SnowContext *s){ +- int plane_index, i; +- uint8_t kstate[32]; +- +- memset(kstate, MID_STATE, sizeof(kstate)); +- +- put_rac(&s->c, kstate, s->keyframe); +- if(s->keyframe || s->always_reset){ +- reset_contexts(s); +- s->last_spatial_decomposition_type= +- s->last_qlog= +- s->last_qbias= +- s->last_mv_scale= +- s->last_block_max_depth= 0; +- for(plane_index=0; plane_index<2; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- p->last_htaps=0; +- p->last_diag_mc=0; +- memset(p->last_hcoeff, 0, sizeof(p->last_hcoeff)); +- } +- } +- if(s->keyframe){ +- put_symbol(&s->c, s->header_state, s->version, 0); +- put_rac(&s->c, s->header_state, s->always_reset); +- put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); +- put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); +- put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); +- put_symbol(&s->c, s->header_state, s->colorspace_type, 0); +- put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); +- put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0); +- put_rac(&s->c, s->header_state, s->spatial_scalability); +-// put_rac(&s->c, s->header_state, s->rate_scalability); +- put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0); +- +- encode_qlogs(s); +- } +- +- if(!s->keyframe){ +- int update_mc=0; +- for(plane_index=0; plane_index<2; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- update_mc |= p->last_htaps != p->htaps; +- update_mc |= p->last_diag_mc != p->diag_mc; +- update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); +- } +- put_rac(&s->c, s->header_state, update_mc); +- if(update_mc){ +- for(plane_index=0; plane_index<2; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- put_rac(&s->c, s->header_state, p->diag_mc); +- put_symbol(&s->c, s->header_state, p->htaps/2-1, 0); +- for(i= p->htaps/2; i; i--) +- put_symbol(&s->c, s->header_state, FFABS(p->hcoeff[i]), 0); +- } +- } +- if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ +- put_rac(&s->c, s->header_state, 1); +- put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); +- encode_qlogs(s); +- }else +- put_rac(&s->c, s->header_state, 0); +- } +- +- put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); +- put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); +- put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); +- put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); +- put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); +- +-} +- +-static void update_last_header_values(SnowContext *s){ +- int plane_index; +- +- if(!s->keyframe){ +- for(plane_index=0; plane_index<2; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- p->last_diag_mc= p->diag_mc; +- p->last_htaps = p->htaps; +- memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); +- } +- } +- +- s->last_spatial_decomposition_type = s->spatial_decomposition_type; +- s->last_qlog = s->qlog; +- s->last_qbias = s->qbias; +- s->last_mv_scale = s->mv_scale; +- s->last_block_max_depth = s->block_max_depth; +- s->last_spatial_decomposition_count = s->spatial_decomposition_count; +-} +- +-static int qscale2qlog(int qscale){ +- return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2)) +- + 61*QROOT/8; //<64 >60 +-} +- +-static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) +-{ +- /* Estimate the frame's complexity as a sum of weighted dwt coefficients. +- * FIXME we know exact mv bits at this point, +- * but ratecontrol isn't set up to include them. */ +- uint32_t coef_sum= 0; +- int level, orientation, delta_qlog; +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &s->plane[0].band[level][orientation]; +- IDWTELEM *buf= b->ibuf; +- const int w= b->width; +- const int h= b->height; +- const int stride= b->stride; +- const int qlog= av_clip(2*QROOT + b->qlog, 0, QROOT*16); +- const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); +- const int qdiv= (1<<16)/qmul; +- int x, y; +- //FIXME this is ugly +- for(y=0; ybuf[x+y*stride]; +- if(orientation==0) +- decorrelate(s, b, buf, stride, 1, 0); +- for(y=0; y> 16; +- } +- } +- +- /* ugly, ratecontrol just takes a sqrt again */ +- coef_sum = (uint64_t)coef_sum * coef_sum >> 16; +- assert(coef_sum < INT_MAX); +- +- if(pict->pict_type == FF_I_TYPE){ +- s->m.current_picture.mb_var_sum= coef_sum; +- s->m.current_picture.mc_mb_var_sum= 0; +- }else{ +- s->m.current_picture.mc_mb_var_sum= coef_sum; +- s->m.current_picture.mb_var_sum= 0; +- } +- +- pict->quality= ff_rate_estimate_qscale(&s->m, 1); +- if (pict->quality < 0) +- return INT_MIN; +- s->lambda= pict->quality * 3/2; +- delta_qlog= qscale2qlog(pict->quality) - s->qlog; +- s->qlog+= delta_qlog; +- return delta_qlog; +-} +- +-static void calculate_visual_weight(SnowContext *s, Plane *p){ +- int width = p->width; +- int height= p->height; +- int level, orientation, x, y; +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- IDWTELEM *ibuf= b->ibuf; +- int64_t error=0; +- +- memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height); +- ibuf[b->width/2 + b->height/2*b->stride]= 256*16; +- ff_spatial_idwt(s->spatial_idwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); +- for(y=0; yspatial_idwt_buffer[x + y*width]*16; +- error += d*d; +- } +- } +- +- b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); +- } +- } +-} +- +-static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ +- SnowContext *s = avctx->priv_data; +- RangeCoder * const c= &s->c; +- AVFrame *pict = data; +- const int width= s->avctx->width; +- const int height= s->avctx->height; +- int level, orientation, plane_index, i, y; +- uint8_t rc_header_bak[sizeof(s->header_state)]; +- uint8_t rc_block_bak[sizeof(s->block_state)]; +- +- ff_init_range_encoder(c, buf, buf_size); +- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); +- +- for(i=0; i<3; i++){ +- int shift= !!i; +- for(y=0; y<(height>>shift); y++) +- memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]], +- &pict->data[i][y * pict->linesize[i]], +- width>>shift); +- } +- s->new_picture = *pict; +- +- s->m.picture_number= avctx->frame_number; +- if(avctx->flags&CODEC_FLAG_PASS2){ +- s->m.pict_type = +- pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type; +- s->keyframe= pict->pict_type==FF_I_TYPE; +- if(!(avctx->flags&CODEC_FLAG_QSCALE)) { +- pict->quality= ff_rate_estimate_qscale(&s->m, 0); +- if (pict->quality < 0) +- return -1; +- } +- }else{ +- s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; +- s->m.pict_type= +- pict->pict_type= s->keyframe ? FF_I_TYPE : FF_P_TYPE; +- } +- +- if(s->pass1_rc && avctx->frame_number == 0) +- pict->quality= 2*FF_QP2LAMBDA; +- if(pict->quality){ +- s->qlog= qscale2qlog(pict->quality); +- s->lambda = pict->quality * 3/2; +- } +- if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ +- s->qlog= LOSSLESS_QLOG; +- s->lambda = 0; +- }//else keep previous frame's qlog until after motion estimation +- +- frame_start(s); +- +- s->m.current_picture_ptr= &s->m.current_picture; +- s->m.last_picture.pts= s->m.current_picture.pts; +- s->m.current_picture.pts= pict->pts; +- if(pict->pict_type == FF_P_TYPE){ +- int block_width = (width +15)>>4; +- int block_height= (height+15)>>4; +- int stride= s->current_picture.linesize[0]; +- +- assert(s->current_picture.data[0]); +- assert(s->last_picture[0].data[0]); +- +- s->m.avctx= s->avctx; +- s->m.current_picture.data[0]= s->current_picture.data[0]; +- s->m. last_picture.data[0]= s->last_picture[0].data[0]; +- s->m. new_picture.data[0]= s-> input_picture.data[0]; +- s->m. last_picture_ptr= &s->m. last_picture; +- s->m.linesize= +- s->m. last_picture.linesize[0]= +- s->m. new_picture.linesize[0]= +- s->m.current_picture.linesize[0]= stride; +- s->m.uvlinesize= s->current_picture.linesize[1]; +- s->m.width = width; +- s->m.height= height; +- s->m.mb_width = block_width; +- s->m.mb_height= block_height; +- s->m.mb_stride= s->m.mb_width+1; +- s->m.b8_stride= 2*s->m.mb_width+1; +- s->m.f_code=1; +- s->m.pict_type= pict->pict_type; +- s->m.me_method= s->avctx->me_method; +- s->m.me.scene_change_score=0; +- s->m.flags= s->avctx->flags; +- s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; +- s->m.out_format= FMT_H263; +- s->m.unrestricted_mv= 1; +- +- s->m.lambda = s->lambda; +- s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); +- s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; +- +- s->m.dsp= s->dsp; //move +- ff_init_me(&s->m); +- s->dsp= s->m.dsp; +- } +- +- if(s->pass1_rc){ +- memcpy(rc_header_bak, s->header_state, sizeof(s->header_state)); +- memcpy(rc_block_bak, s->block_state, sizeof(s->block_state)); +- } +- +-redo_frame: +- +- if(pict->pict_type == FF_I_TYPE) +- s->spatial_decomposition_count= 5; +- else +- s->spatial_decomposition_count= 5; +- +- s->m.pict_type = pict->pict_type; +- s->qbias= pict->pict_type == FF_P_TYPE ? 2 : 0; +- +- common_init_after_header(avctx); +- +- if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ +- for(plane_index=0; plane_index<3; plane_index++){ +- calculate_visual_weight(s, &s->plane[plane_index]); +- } +- } +- +- encode_header(s); +- s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); +- encode_blocks(s, 1); +- s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits; +- +- for(plane_index=0; plane_index<3; plane_index++){ +- Plane *p= &s->plane[plane_index]; +- int w= p->width; +- int h= p->height; +- int x, y; +-// int bits= put_bits_count(&s->c.pb); +- +- if(!(avctx->flags2 & CODEC_FLAG2_MEMC_ONLY)){ +- //FIXME optimize +- if(pict->data[plane_index]) //FIXME gray hack +- for(y=0; yspatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<spatial_idwt_buffer, plane_index, 0); +- +- if( plane_index==0 +- && pict->pict_type == FF_P_TYPE +- && !(avctx->flags&CODEC_FLAG_PASS2) +- && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ +- ff_init_range_encoder(c, buf, buf_size); +- ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); +- pict->pict_type= FF_I_TYPE; +- s->keyframe=1; +- s->current_picture.key_frame=1; +- goto redo_frame; +- } +- +- if(s->qlog == LOSSLESS_QLOG){ +- for(y=0; yspatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; +- } +- } +- }else{ +- for(y=0; yspatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); +- else*/ +- ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); +- +- if(s->pass1_rc && plane_index==0){ +- int delta_qlog = ratecontrol_1pass(s, pict); +- if (delta_qlog <= INT_MIN) +- return -1; +- if(delta_qlog){ +- //reordering qlog in the bitstream would eliminate this reset +- ff_init_range_encoder(c, buf, buf_size); +- memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); +- memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); +- encode_header(s); +- encode_blocks(s, 0); +- } +- } +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- +- if(!QUANTIZE2) +- quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); +- if(orientation==0) +- decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == FF_P_TYPE, 0); +- encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); +- assert(b->parent==NULL || b->parent->stride == b->stride*2); +- if(orientation==0) +- correlate(s, b, b->ibuf, b->stride, 1, 0); +- } +- } +- +- for(level=0; levelspatial_decomposition_count; level++){ +- for(orientation=level ? 1 : 0; orientation<4; orientation++){ +- SubBand *b= &p->band[level][orientation]; +- +- dequantize(s, b, b->ibuf, b->stride); +- } +- } +- +- ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); +- if(s->qlog == LOSSLESS_QLOG){ +- for(y=0; yspatial_idwt_buffer[y*w + x]<<=FRAC_BITS; +- } +- } +- } +- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); +- }else{ +- //ME/MC only +- if(pict->pict_type == FF_I_TYPE){ +- for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= +- pict->data[plane_index][y*pict->linesize[plane_index] + x]; +- } +- } +- }else{ +- memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); +- predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); +- } +- } +- if(s->avctx->flags&CODEC_FLAG_PSNR){ +- int64_t error= 0; +- +- if(pict->data[plane_index]) //FIXME gray hack +- for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; +- error += d*d; +- } +- } +- s->avctx->error[plane_index] += error; +- s->current_picture.error[plane_index] = error; +- } +- +- } +- +- update_last_header_values(s); +- +- release_buffer(avctx); +- +- s->current_picture.coded_picture_number = avctx->frame_number; +- s->current_picture.pict_type = pict->pict_type; +- s->current_picture.quality = pict->quality; +- s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); +- s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; +- s->m.current_picture.display_picture_number = +- s->m.current_picture.coded_picture_number = avctx->frame_number; +- s->m.current_picture.quality = pict->quality; +- s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); +- if(s->pass1_rc) +- if (ff_rate_estimate_qscale(&s->m, 0) < 0) +- return -1; +- if(avctx->flags&CODEC_FLAG_PASS1) +- ff_write_pass1_stats(&s->m); +- s->m.last_pict_type = s->m.pict_type; +- avctx->frame_bits = s->m.frame_bits; +- avctx->mv_bits = s->m.mv_bits; +- avctx->misc_bits = s->m.misc_bits; +- avctx->p_tex_bits = s->m.p_tex_bits; +- +- emms_c(); +- +- return ff_rac_terminate(c); +-} +- +-static av_cold int encode_end(AVCodecContext *avctx) +-{ +- SnowContext *s = avctx->priv_data; +- +- common_end(s); +- if (s->input_picture.data[0]) +- avctx->release_buffer(avctx, &s->input_picture); +- av_free(avctx->stats_out); +- +- return 0; +-} +- +-AVCodec ff_snow_encoder = { +- "snow", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SNOW, +- sizeof(SnowContext), +- encode_init, +- encode_frame, +- encode_end, +- .long_name = NULL_IF_CONFIG_SMALL("Snow"), +-}; +-#endif +- +- +-#ifdef TEST +-#undef malloc +-#undef free +-#undef printf +- +-#include "libavutil/lfg.h" +- +-int main(void){ +- int width=256; +- int height=256; +- int buffer[2][width*height]; +- SnowContext s; +- int i; +- AVLFG prng; +- s.spatial_decomposition_count=6; +- s.spatial_decomposition_type=1; +- +- av_lfg_init(&prng, 1); +- +- printf("testing 5/3 DWT\n"); +- for(i=0; i20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]); +- +-#if 0 +- printf("testing AC coder\n"); +- memset(s.header_state, 0, sizeof(s.header_state)); +- ff_init_range_encoder(&s.c, buffer[0], 256*256); +- ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); +- +- for(i=-256; i<256; i++){ +- put_symbol(&s.c, s.header_state, i*i*i/3*FFABS(i), 1); +- } +- ff_rac_terminate(&s.c); +- +- memset(s.header_state, 0, sizeof(s.header_state)); +- ff_init_range_decoder(&s.c, buffer[0], 256*256); +- ff_init_cabac_states(&s.c, ff_h264_lps_range, ff_h264_mps_state, ff_h264_lps_state, 64); +- +- for(i=-256; i<256; i++){ +- int j; +- j= get_symbol(&s.c, s.header_state, 1); +- if(j!=i*i*i/3*FFABS(i)) printf("fsck: %d != %d\n", i, j); +- } +-#endif +- { +- int level, orientation, x, y; +- int64_t errors[8][4]; +- int64_t g=0; +- +- memset(errors, 0, sizeof(errors)); +- s.spatial_decomposition_count=3; +- s.spatial_decomposition_type=0; +- for(level=0; level> (s.spatial_decomposition_count-level); +- int h= height >> (s.spatial_decomposition_count-level); +- int stride= width << (s.spatial_decomposition_count-level); +- DWTELEM *buf= buffer[0]; +- int64_t error=0; +- +- if(orientation&1) buf+=w; +- if(orientation>1) buf+=stride>>1; +- +- memset(buffer[0], 0, sizeof(int)*width*height); +- buf[w/2 + h/2*stride]= 256*256; +- ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); +- for(y=0; y> (s.spatial_decomposition_count-level); +- //int h= height >> (s.spatial_decomposition_count-level); +- int stride= width << (s.spatial_decomposition_count-level); +- DWTELEM *buf= buffer[0]; +- int64_t error=0; +- +- buf+=w; +- buf+=stride>>1; +- +- memset(buffer[0], 0, sizeof(int)*width*height); +-#if 1 +- for(y=0; y ++ * Copyright (C) 2006 Robert Edele ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_SNOWDATA_H ++#define AVCODEC_SNOWDATA_H ++ ++#include "snow.h" ++ ++static const uint8_t obmc32[1024]={ ++ 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, ++ 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, ++ 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, ++ 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, ++ 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, ++ 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, ++ 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, ++ 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, ++ 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, ++ 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, ++ 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, ++ 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, ++ 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, ++ 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, ++ 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, ++ 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, ++ 8, 24, 40, 56, 68, 84,100,116,132,148,164,180,192,208,224,240,240,224,208,192,180,164,148,132,116,100, 84, 68, 56, 40, 24, 8, ++ 8, 20, 36, 52, 64, 80, 96,108,124,136,152,168,180,196,212,224,224,212,196,180,168,152,136,124,108, 96, 80, 64, 52, 36, 20, 8, ++ 8, 20, 32, 48, 60, 76, 88,100,116,128,140,156,168,184,196,208,208,196,184,168,156,140,128,116,100, 88, 76, 60, 48, 32, 20, 8, ++ 8, 20, 32, 44, 56, 68, 80, 92,108,120,132,144,156,168,180,192,192,180,168,156,144,132,120,108, 92, 80, 68, 56, 44, 32, 20, 8, ++ 4, 16, 28, 40, 52, 64, 76, 88, 96,108,120,132,144,156,168,180,180,168,156,144,132,120,108, 96, 88, 76, 64, 52, 40, 28, 16, 4, ++ 4, 16, 28, 36, 48, 56, 68, 80, 88,100,112,120,132,140,152,164,164,152,140,132,120,112,100, 88, 80, 68, 56, 48, 36, 28, 16, 4, ++ 4, 16, 24, 32, 44, 52, 60, 72, 80, 92,100,108,120,128,136,148,148,136,128,120,108,100, 92, 80, 72, 60, 52, 44, 32, 24, 16, 4, ++ 4, 12, 20, 28, 40, 48, 56, 64, 72, 80, 88, 96,108,116,124,132,132,124,116,108, 96, 88, 80, 72, 64, 56, 48, 40, 28, 20, 12, 4, ++ 4, 12, 20, 28, 32, 40, 48, 56, 64, 72, 80, 88, 92,100,108,116,116,108,100, 92, 88, 80, 72, 64, 56, 48, 40, 32, 28, 20, 12, 4, ++ 4, 8, 16, 24, 28, 36, 44, 48, 56, 60, 68, 76, 80, 88, 96,100,100, 96, 88, 80, 76, 68, 60, 56, 48, 44, 36, 28, 24, 16, 8, 4, ++ 4, 8, 12, 20, 24, 32, 36, 40, 48, 52, 56, 64, 68, 76, 80, 84, 84, 80, 76, 68, 64, 56, 52, 48, 40, 36, 32, 24, 20, 12, 8, 4, ++ 4, 8, 12, 16, 20, 24, 28, 32, 40, 44, 48, 52, 56, 60, 64, 68, 68, 64, 60, 56, 52, 48, 44, 40, 32, 28, 24, 20, 16, 12, 8, 4, ++ 0, 4, 8, 12, 16, 20, 24, 28, 28, 32, 36, 40, 44, 48, 52, 56, 56, 52, 48, 44, 40, 36, 32, 28, 28, 24, 20, 16, 12, 8, 4, 0, ++ 0, 4, 8, 8, 12, 12, 16, 20, 20, 24, 28, 28, 32, 32, 36, 40, 40, 36, 32, 32, 28, 28, 24, 20, 20, 16, 12, 12, 8, 8, 4, 0, ++ 0, 4, 4, 4, 8, 8, 8, 12, 12, 16, 16, 16, 20, 20, 20, 24, 24, 20, 20, 20, 16, 16, 16, 12, 12, 8, 8, 8, 4, 4, 4, 0, ++ 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, ++ //error:0.000020 ++}; ++static const uint8_t obmc16[256]={ ++ 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, ++ 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, ++ 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, ++ 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, ++ 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, ++ 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, ++ 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, ++ 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, ++ 16, 44, 76,104,136,164,196,224,224,196,164,136,104, 76, 44, 16, ++ 12, 40, 64, 92,116,144,168,196,196,168,144,116, 92, 64, 40, 12, ++ 12, 32, 56, 76,100,120,144,164,164,144,120,100, 76, 56, 32, 12, ++ 8, 28, 44, 64, 80,100,116,136,136,116,100, 80, 64, 44, 28, 8, ++ 8, 20, 36, 48, 64, 76, 92,104,104, 92, 76, 64, 48, 36, 20, 8, ++ 4, 16, 24, 36, 44, 56, 64, 76, 76, 64, 56, 44, 36, 24, 16, 4, ++ 4, 8, 16, 20, 28, 32, 40, 44, 44, 40, 32, 28, 20, 16, 8, 4, ++ 0, 4, 4, 8, 8, 12, 12, 16, 16, 12, 12, 8, 8, 4, 4, 0, ++//error:0.000015 ++}; ++ ++//linear *64 ++static const uint8_t obmc8[64]={ ++ 4, 12, 20, 28, 28, 20, 12, 4, ++ 12, 36, 60, 84, 84, 60, 36, 12, ++ 20, 60,100,140,140,100, 60, 20, ++ 28, 84,140,196,196,140, 84, 28, ++ 28, 84,140,196,196,140, 84, 28, ++ 20, 60,100,140,140,100, 60, 20, ++ 12, 36, 60, 84, 84, 60, 36, 12, ++ 4, 12, 20, 28, 28, 20, 12, 4, ++//error:0.000000 ++}; ++ ++//linear *64 ++static const uint8_t obmc4[16]={ ++ 16, 48, 48, 16, ++ 48,144,144, 48, ++ 48,144,144, 48, ++ 16, 48, 48, 16, ++//error:0.000000 ++}; ++ ++const int8_t quant3bA[256]={ ++ 0, 0, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++ 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, 1,-1, ++}; ++ ++const uint8_t * const obmc_tab[4]= { ++ obmc32, obmc16, obmc8, obmc4 ++}; ++ ++/* runtime generated tables */ ++uint8_t qexp[QROOT]; ++int scale_mv_ref[MAX_REF_FRAMES][MAX_REF_FRAMES]; ++ ++ ++#endif /* AVCODEC_SNOW_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snowdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snowdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snowdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snowdec.c 2012-05-14 14:08:54.234337969 +0200 +@@ -0,0 +1,563 @@ ++/* ++ * Copyright (C) 2004 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intmath.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "avcodec.h" ++#include "dsputil.h" ++#include "dwt.h" ++#include "snow.h" ++ ++#include "rangecoder.h" ++#include "mathops.h" ++ ++#include "mpegvideo.h" ++#include "h263.h" ++ ++#undef NDEBUG ++#include ++ ++static av_always_inline void predict_slice_buffered(SnowContext *s, slice_buffer * sb, IDWTELEM * old_buffer, int plane_index, int add, int mb_y){ ++ Plane *p= &s->plane[plane_index]; ++ const int mb_w= s->b_width << s->block_max_depth; ++ const int mb_h= s->b_height << s->block_max_depth; ++ int x, y, mb_x; ++ int block_size = MB_SIZE >> s->block_max_depth; ++ int block_w = plane_index ? block_size/2 : block_size; ++ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; ++ int obmc_stride= plane_index ? block_size : 2*block_size; ++ int ref_stride= s->current_picture.linesize[plane_index]; ++ uint8_t *dst8= s->current_picture.data[plane_index]; ++ int w= p->width; ++ int h= p->height; ++ ++ if(s->keyframe || (s->avctx->debug&512)){ ++ if(mb_y==mb_h) ++ return; ++ ++ if(add){ ++ for(y=block_w*mb_y; yline[y]; ++ for(x=0; x>= FRAC_BITS; ++ if(v&(~255)) v= ~(v>>31); ++ dst8[x + y*ref_stride]= v; ++ } ++ } ++ }else{ ++ for(y=block_w*mb_y; yline[y]; ++ for(x=0; xwidth; ++ int y; ++ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); ++ int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); ++ int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; ++ int new_index = 0; ++ ++ if(b->ibuf == s->spatial_idwt_buffer || s->qlog == LOSSLESS_QLOG){ ++ qadd= 0; ++ qmul= 1<stride_line + b->buf_y_offset) + b->buf_x_offset; ++ memset(line, 0, b->width*sizeof(IDWTELEM)); ++ v = b->x_coeff[new_index].coeff; ++ x = b->x_coeff[new_index++].x; ++ while(x < w){ ++ register int t= ( (v>>1)*qmul + qadd)>>QEXPSHIFT; ++ register int u= -(v&1); ++ line[x] = (t^u) - u; ++ ++ v = b->x_coeff[new_index].coeff; ++ x = b->x_coeff[new_index++].x; ++ } ++ } ++ ++ /* Save our variables for the next slice. */ ++ save_state[0] = new_index; ++ ++ return; ++} ++ ++static int decode_q_branch(SnowContext *s, int level, int x, int y){ ++ const int w= s->b_width << s->block_max_depth; ++ const int rem_depth= s->block_max_depth - level; ++ const int index= (x + y*w) << rem_depth; ++ int trx= (x+1)<block[index-1] : &null_block; ++ const BlockNode *top = y ? &s->block[index-w] : &null_block; ++ const BlockNode *tl = y && x ? &s->block[index-w-1] : left; ++ const BlockNode *tr = y && trxblock[index-w+(1<level + 2*top->level + tl->level + tr->level; ++ int res; ++ ++ if(s->keyframe){ ++ set_blocks(s, level, x, y, null_block.color[0], null_block.color[1], null_block.color[2], null_block.mx, null_block.my, null_block.ref, BLOCK_INTRA); ++ return 0; ++ } ++ ++ if(level==s->block_max_depth || get_rac(&s->c, &s->block_state[4 + s_context])){ ++ int type, mx, my; ++ int l = left->color[0]; ++ int cb= left->color[1]; ++ int cr= left->color[2]; ++ int ref = 0; ++ int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); ++ int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 0*av_log2(2*FFABS(tr->mx - top->mx)); ++ int my_context= av_log2(2*FFABS(left->my - top->my)) + 0*av_log2(2*FFABS(tr->my - top->my)); ++ ++ type= get_rac(&s->c, &s->block_state[1 + left->type + top->type]) ? BLOCK_INTRA : 0; ++ ++ if(type){ ++ pred_mv(s, &mx, &my, 0, left, top, tr); ++ l += get_symbol(&s->c, &s->block_state[32], 1); ++ cb+= get_symbol(&s->c, &s->block_state[64], 1); ++ cr+= get_symbol(&s->c, &s->block_state[96], 1); ++ }else{ ++ if(s->ref_frames > 1) ++ ref= get_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], 0); ++ if (ref >= s->ref_frames) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid ref\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ pred_mv(s, &mx, &my, ref, left, top, tr); ++ mx+= get_symbol(&s->c, &s->block_state[128 + 32*(mx_context + 16*!!ref)], 1); ++ my+= get_symbol(&s->c, &s->block_state[128 + 32*(my_context + 16*!!ref)], 1); ++ } ++ set_blocks(s, level, x, y, l, cb, cr, mx, my, ref, type); ++ }else{ ++ if ((res = decode_q_branch(s, level+1, 2*x+0, 2*y+0)) < 0 || ++ (res = decode_q_branch(s, level+1, 2*x+1, 2*y+0)) < 0 || ++ (res = decode_q_branch(s, level+1, 2*x+0, 2*y+1)) < 0 || ++ (res = decode_q_branch(s, level+1, 2*x+1, 2*y+1)) < 0) ++ return res; ++ } ++ return 0; ++} ++ ++static void dequantize_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int start_y, int end_y){ ++ const int w= b->width; ++ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); ++ const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); ++ const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; ++ int x,y; ++ ++ if(s->qlog == LOSSLESS_QLOG) return; ++ ++ for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; ++ for(x=0; x>(QEXPSHIFT)); //FIXME try different bias ++ }else if(i>0){ ++ line[x]= (( i*qmul + qadd)>>(QEXPSHIFT)); ++ } ++ } ++ } ++} ++ ++static void correlate_slice_buffered(SnowContext *s, slice_buffer * sb, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median, int start_y, int end_y){ ++ const int w= b->width; ++ int x,y; ++ ++ IDWTELEM * line=0; // silence silly "could be used without having been initialized" warning ++ IDWTELEM * prev; ++ ++ if (start_y != 0) ++ line = slice_buffer_get_line(sb, ((start_y - 1) * b->stride_line) + b->buf_y_offset) + b->buf_x_offset; ++ ++ for(y=start_y; ystride_line) + b->buf_y_offset) + b->buf_x_offset; ++ for(x=0; xspatial_decomposition_count; level++){ ++ for(orientation=level ? 1:0; orientation<4; orientation++){ ++ int q; ++ if (plane_index==2) q= s->plane[1].band[level][orientation].qlog; ++ else if(orientation==2) q= s->plane[plane_index].band[level][1].qlog; ++ else q= get_symbol(&s->c, s->header_state, 1); ++ s->plane[plane_index].band[level][orientation].qlog= q; ++ } ++ } ++ } ++} ++ ++#define GET_S(dst, check) \ ++ tmp= get_symbol(&s->c, s->header_state, 0);\ ++ if(!(check)){\ ++ av_log(s->avctx, AV_LOG_ERROR, "Error " #dst " is %d\n", tmp);\ ++ return -1;\ ++ }\ ++ dst= tmp; ++ ++static int decode_header(SnowContext *s){ ++ int plane_index, tmp; ++ uint8_t kstate[32]; ++ ++ memset(kstate, MID_STATE, sizeof(kstate)); ++ ++ s->keyframe= get_rac(&s->c, kstate); ++ if(s->keyframe || s->always_reset){ ++ ff_snow_reset_contexts(s); ++ s->spatial_decomposition_type= ++ s->qlog= ++ s->qbias= ++ s->mv_scale= ++ s->block_max_depth= 0; ++ } ++ if(s->keyframe){ ++ GET_S(s->version, tmp <= 0U) ++ s->always_reset= get_rac(&s->c, s->header_state); ++ s->temporal_decomposition_type= get_symbol(&s->c, s->header_state, 0); ++ s->temporal_decomposition_count= get_symbol(&s->c, s->header_state, 0); ++ GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) ++ s->colorspace_type= get_symbol(&s->c, s->header_state, 0); ++ s->chroma_h_shift= get_symbol(&s->c, s->header_state, 0); ++ s->chroma_v_shift= get_symbol(&s->c, s->header_state, 0); ++ s->spatial_scalability= get_rac(&s->c, s->header_state); ++// s->rate_scalability= get_rac(&s->c, s->header_state); ++ GET_S(s->max_ref_frames, tmp < (unsigned)MAX_REF_FRAMES) ++ s->max_ref_frames++; ++ ++ decode_qlogs(s); ++ } ++ ++ if(!s->keyframe){ ++ if(get_rac(&s->c, s->header_state)){ ++ for(plane_index=0; plane_index<2; plane_index++){ ++ int htaps, i, sum=0; ++ Plane *p= &s->plane[plane_index]; ++ p->diag_mc= get_rac(&s->c, s->header_state); ++ htaps= get_symbol(&s->c, s->header_state, 0)*2 + 2; ++ if((unsigned)htaps > HTAPS_MAX || htaps==0) ++ return -1; ++ p->htaps= htaps; ++ for(i= htaps/2; i; i--){ ++ p->hcoeff[i]= get_symbol(&s->c, s->header_state, 0) * (1-2*(i&1)); ++ sum += p->hcoeff[i]; ++ } ++ p->hcoeff[0]= 32-sum; ++ } ++ s->plane[2].diag_mc= s->plane[1].diag_mc; ++ s->plane[2].htaps = s->plane[1].htaps; ++ memcpy(s->plane[2].hcoeff, s->plane[1].hcoeff, sizeof(s->plane[1].hcoeff)); ++ } ++ if(get_rac(&s->c, s->header_state)){ ++ GET_S(s->spatial_decomposition_count, 0 < tmp && tmp <= MAX_DECOMPOSITIONS) ++ decode_qlogs(s); ++ } ++ } ++ ++ s->spatial_decomposition_type+= get_symbol(&s->c, s->header_state, 1); ++ if(s->spatial_decomposition_type > 1U){ ++ av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_type %d not supported", s->spatial_decomposition_type); ++ return -1; ++ } ++ if(FFMIN(s->avctx-> width>>s->chroma_h_shift, ++ s->avctx->height>>s->chroma_v_shift) >> (s->spatial_decomposition_count-1) <= 0){ ++ av_log(s->avctx, AV_LOG_ERROR, "spatial_decomposition_count %d too large for size", s->spatial_decomposition_count); ++ return -1; ++ } ++ ++ if (s->chroma_h_shift != 1 || s->chroma_v_shift != 1) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid chroma shift\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ s->qlog += get_symbol(&s->c, s->header_state, 1); ++ s->mv_scale += get_symbol(&s->c, s->header_state, 1); ++ s->qbias += get_symbol(&s->c, s->header_state, 1); ++ s->block_max_depth+= get_symbol(&s->c, s->header_state, 1); ++ if(s->block_max_depth > 1 || s->block_max_depth < 0){ ++ av_log(s->avctx, AV_LOG_ERROR, "block_max_depth= %d is too large", s->block_max_depth); ++ s->block_max_depth= 0; ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt= PIX_FMT_YUV420P; ++ ++ ff_snow_common_init(avctx); ++ ++ return 0; ++} ++ ++static int decode_blocks(SnowContext *s){ ++ int x, y; ++ int w= s->b_width; ++ int h= s->b_height; ++ int res; ++ ++ for(y=0; ydata; ++ int buf_size = avpkt->size; ++ SnowContext *s = avctx->priv_data; ++ RangeCoder * const c= &s->c; ++ int bytes_read; ++ AVFrame *picture = data; ++ int level, orientation, plane_index; ++ int res; ++ ++ ff_init_range_decoder(c, buf, buf_size); ++ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); ++ ++ s->current_picture.pict_type= AV_PICTURE_TYPE_I; //FIXME I vs. P ++ if(decode_header(s)<0) ++ return -1; ++ ff_snow_common_init_after_header(avctx); ++ ++ // realloc slice buffer for the case that spatial_decomposition_count changed ++ ff_slice_buffer_destroy(&s->sb); ++ ff_slice_buffer_init(&s->sb, s->plane[0].height, (MB_SIZE >> s->block_max_depth) + s->spatial_decomposition_count * 8 + 1, s->plane[0].width, s->spatial_idwt_buffer); ++ ++ for(plane_index=0; plane_index<3; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ p->fast_mc= p->diag_mc && p->htaps==6 && p->hcoeff[0]==40 ++ && p->hcoeff[1]==-10 ++ && p->hcoeff[2]==2; ++ } ++ ++ ff_snow_alloc_blocks(s); ++ ++ if(ff_snow_frame_start(s) < 0) ++ return -1; ++ //keyframe flag duplication mess FIXME ++ if(avctx->debug&FF_DEBUG_PICT_INFO) ++ av_log(avctx, AV_LOG_ERROR, "keyframe:%d qlog:%d\n", s->keyframe, s->qlog); ++ ++ if ((res = decode_blocks(s)) < 0) ++ return res; ++ ++ for(plane_index=0; plane_index<3; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ int w= p->width; ++ int h= p->height; ++ int x, y; ++ int decode_state[MAX_DECOMPOSITIONS][4][1]; /* Stored state info for unpack_coeffs. 1 variable per instance. */ ++ ++ if(s->avctx->debug&2048){ ++ memset(s->spatial_dwt_buffer, 0, sizeof(DWTELEM)*w*h); ++ predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); ++ ++ for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]; ++ s->mconly_picture.data[plane_index][y*s->mconly_picture.linesize[plane_index] + x]= v; ++ } ++ } ++ } ++ ++ { ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ unpack_coeffs(s, b, b->parent, orientation); ++ } ++ } ++ } ++ ++ { ++ const int mb_h= s->b_height << s->block_max_depth; ++ const int block_size = MB_SIZE >> s->block_max_depth; ++ const int block_w = plane_index ? block_size/2 : block_size; ++ int mb_y; ++ DWTCompose cs[MAX_DECOMPOSITIONS]; ++ int yd=0, yq=0; ++ int y; ++ int end_y; ++ ++ ff_spatial_idwt_buffered_init(cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count); ++ for(mb_y=0; mb_y<=mb_h; mb_y++){ ++ ++ int slice_starty = block_w*mb_y; ++ int slice_h = block_w*(mb_y+1); ++ if (!(s->keyframe || s->avctx->debug&512)){ ++ slice_starty = FFMAX(0, slice_starty - (block_w >> 1)); ++ slice_h -= (block_w >> 1); ++ } ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ int start_y; ++ int end_y; ++ int our_mb_start = mb_y; ++ int our_mb_end = (mb_y + 1); ++ const int extra= 3; ++ start_y = (mb_y ? ((block_w * our_mb_start) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra: 0); ++ end_y = (((block_w * our_mb_end) >> (s->spatial_decomposition_count - level)) + s->spatial_decomposition_count - level + extra); ++ if (!(s->keyframe || s->avctx->debug&512)){ ++ start_y = FFMAX(0, start_y - (block_w >> (1+s->spatial_decomposition_count - level))); ++ end_y = FFMAX(0, end_y - (block_w >> (1+s->spatial_decomposition_count - level))); ++ } ++ start_y = FFMIN(b->height, start_y); ++ end_y = FFMIN(b->height, end_y); ++ ++ if (start_y != end_y){ ++ if (orientation == 0){ ++ SubBand * correlate_band = &p->band[0][0]; ++ int correlate_end_y = FFMIN(b->height, end_y + 1); ++ int correlate_start_y = FFMIN(b->height, (start_y ? start_y + 1 : 0)); ++ decode_subband_slice_buffered(s, correlate_band, &s->sb, correlate_start_y, correlate_end_y, decode_state[0][0]); ++ correlate_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, 1, 0, correlate_start_y, correlate_end_y); ++ dequantize_slice_buffered(s, &s->sb, correlate_band, correlate_band->ibuf, correlate_band->stride, start_y, end_y); ++ } ++ else ++ decode_subband_slice_buffered(s, b, &s->sb, start_y, end_y, decode_state[level][orientation]); ++ } ++ } ++ } ++ ++ for(; yddwt, cs, &s->sb, w, h, 1, s->spatial_decomposition_type, s->spatial_decomposition_count, yd); ++ } ++ ++ if(s->qlog == LOSSLESS_QLOG){ ++ for(; yqsb, yq); ++ for(x=0; xsb, s->spatial_idwt_buffer, plane_index, 1, mb_y); ++ ++ y = FFMIN(p->height, slice_starty); ++ end_y = FFMIN(p->height, slice_h); ++ while(y < end_y) ++ ff_slice_buffer_release(&s->sb, y++); ++ } ++ ++ ff_slice_buffer_flush(&s->sb); ++ } ++ ++ } ++ ++ emms_c(); ++ ++ ff_snow_release_buffer(avctx); ++ ++ if(!(s->avctx->debug&2048)) ++ *picture= s->current_picture; ++ else ++ *picture= s->mconly_picture; ++ ++ *data_size = sizeof(AVFrame); ++ ++ bytes_read= c->bytestream - c->bytestream_start; ++ if(bytes_read ==0) av_log(s->avctx, AV_LOG_ERROR, "error at end of frame\n"); //FIXME ++ ++ return bytes_read; ++} ++ ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ SnowContext *s = avctx->priv_data; ++ ++ ff_slice_buffer_destroy(&s->sb); ++ ++ ff_snow_common_end(s); ++ ++ return 0; ++} ++ ++AVCodec ff_snow_decoder = { ++ .name = "snow", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SNOW, ++ .priv_data_size = sizeof(SnowContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 /*| CODEC_CAP_DRAW_HORIZ_BAND*/, ++ .long_name = NULL_IF_CONFIG_SMALL("Snow"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snowenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snowenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/snowenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/snowenc.c 2012-05-14 14:08:54.239338069 +0200 +@@ -0,0 +1,2038 @@ ++/* ++ * Copyright (C) 2004 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intmath.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "avcodec.h" ++#include "dsputil.h" ++#include "dwt.h" ++#include "snow.h" ++ ++#include "rangecoder.h" ++#include "mathops.h" ++ ++#include "mpegvideo.h" ++#include "h263.h" ++ ++#undef NDEBUG ++#include ++ ++#define QUANTIZE2 0 ++ ++#if QUANTIZE2==1 ++#define Q2_STEP 8 ++ ++static void find_sse(SnowContext *s, Plane *p, int *score, int score_stride, IDWTELEM *r0, IDWTELEM *r1, int level, int orientation){ ++ SubBand *b= &p->band[level][orientation]; ++ int x, y; ++ int xo=0; ++ int yo=0; ++ int step= 1 << (s->spatial_decomposition_count - level); ++ ++ if(orientation&1) ++ xo= step>>1; ++ if(orientation&2) ++ yo= step>>1; ++ ++ //FIXME bias for nonzero ? ++ //FIXME optimize ++ memset(score, 0, sizeof(*score)*score_stride*((p->height + Q2_STEP-1)/Q2_STEP)); ++ for(y=0; yheight; y++){ ++ for(x=0; xwidth; x++){ ++ int sx= (x-xo + step/2) / step / Q2_STEP; ++ int sy= (y-yo + step/2) / step / Q2_STEP; ++ int v= r0[x + y*p->width] - r1[x + y*p->width]; ++ assert(sx>=0 && sy>=0 && sx < score_stride); ++ v= ((v+8)>>4)<<4; ++ score[sx + sy*score_stride] += v*v; ++ assert(score[sx + sy*score_stride] >= 0); ++ } ++ } ++} ++ ++static void dequantize_all(SnowContext *s, Plane *p, IDWTELEM *buffer, int width, int height){ ++ int level, orientation; ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ IDWTELEM *dst= buffer + (b->ibuf - s->spatial_idwt_buffer); ++ ++ dequantize(s, b, dst, b->stride); ++ } ++ } ++} ++ ++static void dwt_quantize(SnowContext *s, Plane *p, DWTELEM *buffer, int width, int height, int stride, int type){ ++ int level, orientation, ys, xs, x, y, pass; ++ IDWTELEM best_dequant[height * stride]; ++ IDWTELEM idwt2_buffer[height * stride]; ++ const int score_stride= (width + 10)/Q2_STEP; ++ int best_score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size ++ int score[(width + 10)/Q2_STEP * (height + 10)/Q2_STEP]; //FIXME size ++ int threshold= (s->m.lambda * s->m.lambda) >> 6; ++ ++ //FIXME pass the copy cleanly ? ++ ++// memcpy(dwt_buffer, buffer, height * stride * sizeof(DWTELEM)); ++ ff_spatial_dwt(buffer, width, height, stride, type, s->spatial_decomposition_count); ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ IDWTELEM *dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); ++ DWTELEM *src= buffer + (b-> buf - s->spatial_dwt_buffer); ++ assert(src == b->buf); // code does not depend on this but it is true currently ++ ++ quantize(s, b, dst, src, b->stride, s->qbias); ++ } ++ } ++ for(pass=0; pass<1; pass++){ ++ if(s->qbias == 0) //keyframe ++ continue; ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ IDWTELEM *dst= idwt2_buffer + (b->ibuf - s->spatial_idwt_buffer); ++ IDWTELEM *best_dst= best_dequant + (b->ibuf - s->spatial_idwt_buffer); ++ ++ for(ys= 0; ysspatial_decomposition_count); ++ find_sse(s, p, best_score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); ++ memcpy(idwt2_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); ++ for(y=ys; yheight; y+= Q2_STEP){ ++ for(x=xs; xwidth; x+= Q2_STEP){ ++ if(dst[x + y*b->stride]<0) dst[x + y*b->stride]++; ++ if(dst[x + y*b->stride]>0) dst[x + y*b->stride]--; ++ //FIXME try more than just -- ++ } ++ } ++ dequantize_all(s, p, idwt2_buffer, width, height); ++ ff_spatial_idwt(idwt2_buffer, width, height, stride, type, s->spatial_decomposition_count); ++ find_sse(s, p, score, score_stride, idwt2_buffer, s->spatial_idwt_buffer, level, orientation); ++ for(y=ys; yheight; y+= Q2_STEP){ ++ for(x=xs; xwidth; x+= Q2_STEP){ ++ int score_idx= x/Q2_STEP + (y/Q2_STEP)*score_stride; ++ if(score[score_idx] <= best_score[score_idx] + threshold){ ++ best_score[score_idx]= score[score_idx]; ++ if(best_dst[x + y*b->stride]<0) best_dst[x + y*b->stride]++; ++ if(best_dst[x + y*b->stride]>0) best_dst[x + y*b->stride]--; ++ //FIXME copy instead ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ memcpy(s->spatial_idwt_buffer, best_dequant, height * stride * sizeof(IDWTELEM)); //FIXME work with that directly instead of copy at the end ++} ++ ++#endif /* QUANTIZE2==1 */ ++ ++#if CONFIG_SNOW_ENCODER ++static av_cold int encode_init(AVCodecContext *avctx) ++{ ++ SnowContext *s = avctx->priv_data; ++ int plane_index; ++ ++ if(avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL){ ++ av_log(avctx, AV_LOG_ERROR, "This codec is under development, files encoded with it may not be decodable with future versions!!!\n" ++ "Use vstrict=-2 / -strict -2 to use it anyway.\n"); ++ return -1; ++ } ++ ++ if(avctx->prediction_method == DWT_97 ++ && (avctx->flags & CODEC_FLAG_QSCALE) ++ && avctx->global_quality == 0){ ++ av_log(avctx, AV_LOG_ERROR, "The 9/7 wavelet is incompatible with lossless mode.\n"); ++ return -1; ++ } ++ ++ s->spatial_decomposition_type= avctx->prediction_method; //FIXME add decorrelator type r transform_type ++ ++ s->mv_scale = (avctx->flags & CODEC_FLAG_QPEL) ? 2 : 4; ++ s->block_max_depth= (avctx->flags & CODEC_FLAG_4MV ) ? 1 : 0; ++ ++ for(plane_index=0; plane_index<3; plane_index++){ ++ s->plane[plane_index].diag_mc= 1; ++ s->plane[plane_index].htaps= 6; ++ s->plane[plane_index].hcoeff[0]= 40; ++ s->plane[plane_index].hcoeff[1]= -10; ++ s->plane[plane_index].hcoeff[2]= 2; ++ s->plane[plane_index].fast_mc= 1; ++ } ++ ++ ff_snow_common_init(avctx); ++ ff_snow_alloc_blocks(s); ++ ++ s->version=0; ++ ++ s->m.avctx = avctx; ++ s->m.flags = avctx->flags; ++ s->m.bit_rate= avctx->bit_rate; ++ ++ s->m.me.temp = ++ s->m.me.scratchpad= av_mallocz((avctx->width+64)*2*16*2*sizeof(uint8_t)); ++ s->m.me.map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); ++ s->m.me.score_map = av_mallocz(ME_MAP_SIZE*sizeof(uint32_t)); ++ s->m.obmc_scratchpad= av_mallocz(MB_SIZE*MB_SIZE*12*sizeof(uint32_t)); ++ h263_encode_init(&s->m); //mv_penalty ++ ++ s->max_ref_frames = FFMAX(FFMIN(avctx->refs, MAX_REF_FRAMES), 1); ++ ++ if(avctx->flags&CODEC_FLAG_PASS1){ ++ if(!avctx->stats_out) ++ avctx->stats_out = av_mallocz(256); ++ } ++ if((avctx->flags&CODEC_FLAG_PASS2) || !(avctx->flags&CODEC_FLAG_QSCALE)){ ++ if(ff_rate_control_init(&s->m) < 0) ++ return -1; ++ } ++ s->pass1_rc= !(avctx->flags & (CODEC_FLAG_QSCALE|CODEC_FLAG_PASS2)); ++ ++ avctx->coded_frame= &s->current_picture; ++ switch(avctx->pix_fmt){ ++// case PIX_FMT_YUV444P: ++// case PIX_FMT_YUV422P: ++ case PIX_FMT_YUV420P: ++// case PIX_FMT_GRAY8: ++// case PIX_FMT_YUV411P: ++// case PIX_FMT_YUV410P: ++ s->colorspace_type= 0; ++ break; ++/* case PIX_FMT_RGB32: ++ s->colorspace= 1; ++ break;*/ ++ default: ++ av_log(avctx, AV_LOG_ERROR, "pixel format not supported\n"); ++ return -1; ++ } ++// avcodec_get_chroma_sub_sample(avctx->pix_fmt, &s->chroma_h_shift, &s->chroma_v_shift); ++ s->chroma_h_shift= 1; ++ s->chroma_v_shift= 1; ++ ++ ff_set_cmp(&s->dsp, s->dsp.me_cmp, s->avctx->me_cmp); ++ ff_set_cmp(&s->dsp, s->dsp.me_sub_cmp, s->avctx->me_sub_cmp); ++ ++ s->avctx->get_buffer(s->avctx, &s->input_picture); ++ ++ if(s->avctx->me_method == ME_ITER){ ++ int i; ++ int size= s->b_width * s->b_height << 2*s->block_max_depth; ++ for(i=0; imax_ref_frames; i++){ ++ s->ref_mvs[i]= av_mallocz(size*sizeof(int16_t[2])); ++ s->ref_scores[i]= av_mallocz(size*sizeof(uint32_t)); ++ } ++ } ++ ++ return 0; ++} ++ ++//near copy & paste from dsputil, FIXME ++static int pix_sum(uint8_t * pix, int line_size, int w) ++{ ++ int s, i, j; ++ ++ s = 0; ++ for (i = 0; i < w; i++) { ++ for (j = 0; j < w; j++) { ++ s += pix[0]; ++ pix ++; ++ } ++ pix += line_size - w; ++ } ++ return s; ++} ++ ++//near copy & paste from dsputil, FIXME ++static int pix_norm1(uint8_t * pix, int line_size, int w) ++{ ++ int s, i, j; ++ uint32_t *sq = ff_squareTbl + 256; ++ ++ s = 0; ++ for (i = 0; i < w; i++) { ++ for (j = 0; j < w; j ++) { ++ s += sq[pix[0]]; ++ pix ++; ++ } ++ pix += line_size - w; ++ } ++ return s; ++} ++ ++//FIXME copy&paste ++#define P_LEFT P[1] ++#define P_TOP P[2] ++#define P_TOPRIGHT P[3] ++#define P_MEDIAN P[4] ++#define P_MV1 P[9] ++#define FLAG_QPEL 1 //must be 1 ++ ++static int encode_q_branch(SnowContext *s, int level, int x, int y){ ++ uint8_t p_buffer[1024]; ++ uint8_t i_buffer[1024]; ++ uint8_t p_state[sizeof(s->block_state)]; ++ uint8_t i_state[sizeof(s->block_state)]; ++ RangeCoder pc, ic; ++ uint8_t *pbbak= s->c.bytestream; ++ uint8_t *pbbak_start= s->c.bytestream_start; ++ int score, score2, iscore, i_len, p_len, block_s, sum, base_bits; ++ const int w= s->b_width << s->block_max_depth; ++ const int h= s->b_height << s->block_max_depth; ++ const int rem_depth= s->block_max_depth - level; ++ const int index= (x + y*w) << rem_depth; ++ const int block_w= 1<<(LOG2_MB_SIZE - level); ++ int trx= (x+1)<block[index-1] : &null_block; ++ const BlockNode *top = y ? &s->block[index-w] : &null_block; ++ const BlockNode *right = trxblock[index+1] : &null_block; ++ const BlockNode *bottom= tryblock[index+w] : &null_block; ++ const BlockNode *tl = y && x ? &s->block[index-w-1] : left; ++ const BlockNode *tr = y && trxblock[index-w+(1<color[0]; ++ int pcb= left->color[1]; ++ int pcr= left->color[2]; ++ int pmx, pmy; ++ int mx=0, my=0; ++ int l,cr,cb; ++ const int stride= s->current_picture.linesize[0]; ++ const int uvstride= s->current_picture.linesize[1]; ++ uint8_t *current_data[3]= { s->input_picture.data[0] + (x + y* stride)*block_w, ++ s->input_picture.data[1] + (x + y*uvstride)*block_w/2, ++ s->input_picture.data[2] + (x + y*uvstride)*block_w/2}; ++ int P[10][2]; ++ int16_t last_mv[3][2]; ++ int qpel= !!(s->avctx->flags & CODEC_FLAG_QPEL); //unused ++ const int shift= 1+qpel; ++ MotionEstContext *c= &s->m.me; ++ int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); ++ int mx_context= av_log2(2*FFABS(left->mx - top->mx)); ++ int my_context= av_log2(2*FFABS(left->my - top->my)); ++ int s_context= 2*left->level + 2*top->level + tl->level + tr->level; ++ int ref, best_ref, ref_score, ref_mx, ref_my; ++ ++ assert(sizeof(s->block_state) >= 256); ++ if(s->keyframe){ ++ set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); ++ return 0; ++ } ++ ++// clip predictors / edge ? ++ ++ P_LEFT[0]= left->mx; ++ P_LEFT[1]= left->my; ++ P_TOP [0]= top->mx; ++ P_TOP [1]= top->my; ++ P_TOPRIGHT[0]= tr->mx; ++ P_TOPRIGHT[1]= tr->my; ++ ++ last_mv[0][0]= s->block[index].mx; ++ last_mv[0][1]= s->block[index].my; ++ last_mv[1][0]= right->mx; ++ last_mv[1][1]= right->my; ++ last_mv[2][0]= bottom->mx; ++ last_mv[2][1]= bottom->my; ++ ++ s->m.mb_stride=2; ++ s->m.mb_x= ++ s->m.mb_y= 0; ++ c->skip= 0; ++ ++ assert(c-> stride == stride); ++ assert(c->uvstride == uvstride); ++ ++ c->penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_cmp); ++ c->sub_penalty_factor= get_penalty_factor(s->lambda, s->lambda2, c->avctx->me_sub_cmp); ++ c->mb_penalty_factor = get_penalty_factor(s->lambda, s->lambda2, c->avctx->mb_cmp); ++ c->current_mv_penalty= c->mv_penalty[s->m.f_code=1] + MAX_MV; ++ ++ c->xmin = - x*block_w - 16+3; ++ c->ymin = - y*block_w - 16+3; ++ c->xmax = - (x+1)*block_w + (w<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; ++ c->ymax = - (y+1)*block_w + (h<<(LOG2_MB_SIZE - s->block_max_depth)) + 16-3; ++ ++ if(P_LEFT[0] > (c->xmax<xmax< (c->ymax<ymax< (c->xmax<xmax< (c->ymax<ymax<xmin<xmin< (c->xmax<xmax< (c->ymax<ymax<pred_x= P_LEFT[0]; ++ c->pred_y= P_LEFT[1]; ++ } else { ++ c->pred_x = P_MEDIAN[0]; ++ c->pred_y = P_MEDIAN[1]; ++ } ++ ++ score= INT_MAX; ++ best_ref= 0; ++ for(ref=0; refref_frames; ref++){ ++ init_ref(c, current_data, s->last_picture[ref].data, NULL, block_w*x, block_w*y, 0); ++ ++ ref_score= ff_epzs_motion_search(&s->m, &ref_mx, &ref_my, P, 0, /*ref_index*/ 0, last_mv, ++ (1<<16)>>shift, level-LOG2_MB_SIZE+4, block_w); ++ ++ assert(ref_mx >= c->xmin); ++ assert(ref_mx <= c->xmax); ++ assert(ref_my >= c->ymin); ++ assert(ref_my <= c->ymax); ++ ++ ref_score= c->sub_motion_search(&s->m, &ref_mx, &ref_my, ref_score, 0, 0, level-LOG2_MB_SIZE+4, block_w); ++ ref_score= ff_get_mb_score(&s->m, ref_mx, ref_my, 0, 0, level-LOG2_MB_SIZE+4, block_w, 0); ++ ref_score+= 2*av_log2(2*ref)*c->penalty_factor; ++ if(s->ref_mvs[ref]){ ++ s->ref_mvs[ref][index][0]= ref_mx; ++ s->ref_mvs[ref][index][1]= ref_my; ++ s->ref_scores[ref][index]= ref_score; ++ } ++ if(score > ref_score){ ++ score= ref_score; ++ best_ref= ref; ++ mx= ref_mx; ++ my= ref_my; ++ } ++ } ++ //FIXME if mb_cmp != SSE then intra cannot be compared currently and mb_penalty vs. lambda2 ++ ++ // subpel search ++ base_bits= get_rac_count(&s->c) - 8*(s->c.bytestream - s->c.bytestream_start); ++ pc= s->c; ++ pc.bytestream_start= ++ pc.bytestream= p_buffer; //FIXME end/start? and at the other stoo ++ memcpy(p_state, s->block_state, sizeof(s->block_state)); ++ ++ if(level!=s->block_max_depth) ++ put_rac(&pc, &p_state[4 + s_context], 1); ++ put_rac(&pc, &p_state[1 + left->type + top->type], 0); ++ if(s->ref_frames > 1) ++ put_symbol(&pc, &p_state[128 + 1024 + 32*ref_context], best_ref, 0); ++ pred_mv(s, &pmx, &pmy, best_ref, left, top, tr); ++ put_symbol(&pc, &p_state[128 + 32*(mx_context + 16*!!best_ref)], mx - pmx, 1); ++ put_symbol(&pc, &p_state[128 + 32*(my_context + 16*!!best_ref)], my - pmy, 1); ++ p_len= pc.bytestream - pc.bytestream_start; ++ score += (s->lambda2*(get_rac_count(&pc)-base_bits))>>FF_LAMBDA_SHIFT; ++ ++ block_s= block_w*block_w; ++ sum = pix_sum(current_data[0], stride, block_w); ++ l= (sum + block_s/2)/block_s; ++ iscore = pix_norm1(current_data[0], stride, block_w) - 2*l*sum + l*l*block_s; ++ ++ block_s= block_w*block_w>>2; ++ sum = pix_sum(current_data[1], uvstride, block_w>>1); ++ cb= (sum + block_s/2)/block_s; ++// iscore += pix_norm1(¤t_mb[1][0], uvstride, block_w>>1) - 2*cb*sum + cb*cb*block_s; ++ sum = pix_sum(current_data[2], uvstride, block_w>>1); ++ cr= (sum + block_s/2)/block_s; ++// iscore += pix_norm1(¤t_mb[2][0], uvstride, block_w>>1) - 2*cr*sum + cr*cr*block_s; ++ ++ ic= s->c; ++ ic.bytestream_start= ++ ic.bytestream= i_buffer; //FIXME end/start? and at the other stoo ++ memcpy(i_state, s->block_state, sizeof(s->block_state)); ++ if(level!=s->block_max_depth) ++ put_rac(&ic, &i_state[4 + s_context], 1); ++ put_rac(&ic, &i_state[1 + left->type + top->type], 1); ++ put_symbol(&ic, &i_state[32], l-pl , 1); ++ put_symbol(&ic, &i_state[64], cb-pcb, 1); ++ put_symbol(&ic, &i_state[96], cr-pcr, 1); ++ i_len= ic.bytestream - ic.bytestream_start; ++ iscore += (s->lambda2*(get_rac_count(&ic)-base_bits))>>FF_LAMBDA_SHIFT; ++ ++// assert(score==256*256*256*64-1); ++ assert(iscore < 255*255*256 + s->lambda2*10); ++ assert(iscore >= 0); ++ assert(l>=0 && l<=255); ++ assert(pl>=0 && pl<=255); ++ ++ if(level==0){ ++ int varc= iscore >> 8; ++ int vard= score >> 8; ++ if (vard <= 64 || vard < varc) ++ c->scene_change_score+= ff_sqrt(vard) - ff_sqrt(varc); ++ else ++ c->scene_change_score+= s->m.qscale; ++ } ++ ++ if(level!=s->block_max_depth){ ++ put_rac(&s->c, &s->block_state[4 + s_context], 0); ++ score2 = encode_q_branch(s, level+1, 2*x+0, 2*y+0); ++ score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+0); ++ score2+= encode_q_branch(s, level+1, 2*x+0, 2*y+1); ++ score2+= encode_q_branch(s, level+1, 2*x+1, 2*y+1); ++ score2+= s->lambda2>>FF_LAMBDA_SHIFT; //FIXME exact split overhead ++ ++ if(score2 < score && score2 < iscore) ++ return score2; ++ } ++ ++ if(iscore < score){ ++ pred_mv(s, &pmx, &pmy, 0, left, top, tr); ++ memcpy(pbbak, i_buffer, i_len); ++ s->c= ic; ++ s->c.bytestream_start= pbbak_start; ++ s->c.bytestream= pbbak + i_len; ++ set_blocks(s, level, x, y, l, cb, cr, pmx, pmy, 0, BLOCK_INTRA); ++ memcpy(s->block_state, i_state, sizeof(s->block_state)); ++ return iscore; ++ }else{ ++ memcpy(pbbak, p_buffer, p_len); ++ s->c= pc; ++ s->c.bytestream_start= pbbak_start; ++ s->c.bytestream= pbbak + p_len; ++ set_blocks(s, level, x, y, pl, pcb, pcr, mx, my, best_ref, 0); ++ memcpy(s->block_state, p_state, sizeof(s->block_state)); ++ return score; ++ } ++} ++ ++static void encode_q_branch2(SnowContext *s, int level, int x, int y){ ++ const int w= s->b_width << s->block_max_depth; ++ const int rem_depth= s->block_max_depth - level; ++ const int index= (x + y*w) << rem_depth; ++ int trx= (x+1)<block[index]; ++ const BlockNode *left = x ? &s->block[index-1] : &null_block; ++ const BlockNode *top = y ? &s->block[index-w] : &null_block; ++ const BlockNode *tl = y && x ? &s->block[index-w-1] : left; ++ const BlockNode *tr = y && trxblock[index-w+(1<color[0]; ++ int pcb= left->color[1]; ++ int pcr= left->color[2]; ++ int pmx, pmy; ++ int ref_context= av_log2(2*left->ref) + av_log2(2*top->ref); ++ int mx_context= av_log2(2*FFABS(left->mx - top->mx)) + 16*!!b->ref; ++ int my_context= av_log2(2*FFABS(left->my - top->my)) + 16*!!b->ref; ++ int s_context= 2*left->level + 2*top->level + tl->level + tr->level; ++ ++ if(s->keyframe){ ++ set_blocks(s, level, x, y, pl, pcb, pcr, 0, 0, 0, BLOCK_INTRA); ++ return; ++ } ++ ++ if(level!=s->block_max_depth){ ++ if(same_block(b,b+1) && same_block(b,b+w) && same_block(b,b+w+1)){ ++ put_rac(&s->c, &s->block_state[4 + s_context], 1); ++ }else{ ++ put_rac(&s->c, &s->block_state[4 + s_context], 0); ++ encode_q_branch2(s, level+1, 2*x+0, 2*y+0); ++ encode_q_branch2(s, level+1, 2*x+1, 2*y+0); ++ encode_q_branch2(s, level+1, 2*x+0, 2*y+1); ++ encode_q_branch2(s, level+1, 2*x+1, 2*y+1); ++ return; ++ } ++ } ++ if(b->type & BLOCK_INTRA){ ++ pred_mv(s, &pmx, &pmy, 0, left, top, tr); ++ put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 1); ++ put_symbol(&s->c, &s->block_state[32], b->color[0]-pl , 1); ++ put_symbol(&s->c, &s->block_state[64], b->color[1]-pcb, 1); ++ put_symbol(&s->c, &s->block_state[96], b->color[2]-pcr, 1); ++ set_blocks(s, level, x, y, b->color[0], b->color[1], b->color[2], pmx, pmy, 0, BLOCK_INTRA); ++ }else{ ++ pred_mv(s, &pmx, &pmy, b->ref, left, top, tr); ++ put_rac(&s->c, &s->block_state[1 + (left->type&1) + (top->type&1)], 0); ++ if(s->ref_frames > 1) ++ put_symbol(&s->c, &s->block_state[128 + 1024 + 32*ref_context], b->ref, 0); ++ put_symbol(&s->c, &s->block_state[128 + 32*mx_context], b->mx - pmx, 1); ++ put_symbol(&s->c, &s->block_state[128 + 32*my_context], b->my - pmy, 1); ++ set_blocks(s, level, x, y, pl, pcb, pcr, b->mx, b->my, b->ref, 0); ++ } ++} ++ ++static int get_dc(SnowContext *s, int mb_x, int mb_y, int plane_index){ ++ int i, x2, y2; ++ Plane *p= &s->plane[plane_index]; ++ const int block_size = MB_SIZE >> s->block_max_depth; ++ const int block_w = plane_index ? block_size/2 : block_size; ++ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; ++ const int obmc_stride= plane_index ? block_size : 2*block_size; ++ const int ref_stride= s->current_picture.linesize[plane_index]; ++ uint8_t *src= s-> input_picture.data[plane_index]; ++ IDWTELEM *dst= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; //FIXME change to unsigned ++ const int b_stride = s->b_width << s->block_max_depth; ++ const int w= p->width; ++ const int h= p->height; ++ int index= mb_x + mb_y*b_stride; ++ BlockNode *b= &s->block[index]; ++ BlockNode backup= *b; ++ int ab=0; ++ int aa=0; ++ ++ b->type|= BLOCK_INTRA; ++ b->color[plane_index]= 0; ++ memset(dst, 0, obmc_stride*obmc_stride*sizeof(IDWTELEM)); ++ ++ for(i=0; i<4; i++){ ++ int mb_x2= mb_x + (i &1) - 1; ++ int mb_y2= mb_y + (i>>1) - 1; ++ int x= block_w*mb_x2 + block_w/2; ++ int y= block_w*mb_y2 + block_w/2; ++ ++ add_yblock(s, 0, NULL, dst + ((i&1)+(i>>1)*obmc_stride)*block_w, NULL, obmc, ++ x, y, block_w, block_w, w, h, obmc_stride, ref_stride, obmc_stride, mb_x2, mb_y2, 0, 0, plane_index); ++ ++ for(y2= FFMAX(y, 0); y2h) obmc_v += obmc[index - block_w*obmc_stride]; ++ if(x+block_w>w) obmc_v += obmc[index - block_w]; ++ //FIXME precalculate this or simplify it somehow else ++ ++ d = -dst[index] + (1<<(FRAC_BITS-1)); ++ dst[index] = d; ++ ab += (src[x2 + y2*ref_stride] - (d>>FRAC_BITS)) * obmc_v; ++ aa += obmc_v * obmc_v; //FIXME precalculate this ++ } ++ } ++ } ++ *b= backup; ++ ++ return av_clip(((ab<b_width << s->block_max_depth; ++ const int b_height = s->b_height<< s->block_max_depth; ++ int index= x + y*b_stride; ++ const BlockNode *b = &s->block[index]; ++ const BlockNode *left = x ? &s->block[index-1] : &null_block; ++ const BlockNode *top = y ? &s->block[index-b_stride] : &null_block; ++ const BlockNode *tl = y && x ? &s->block[index-b_stride-1] : left; ++ const BlockNode *tr = y && x+wblock[index-b_stride+w] : tl; ++ int dmx, dmy; ++// int mx_context= av_log2(2*FFABS(left->mx - top->mx)); ++// int my_context= av_log2(2*FFABS(left->my - top->my)); ++ ++ if(x<0 || x>=b_stride || y>=b_height) ++ return 0; ++/* ++1 0 0 ++01X 1-2 1 ++001XX 3-6 2-3 ++0001XXX 7-14 4-7 ++00001XXXX 15-30 8-15 ++*/ ++//FIXME try accurate rate ++//FIXME intra and inter predictors if surrounding blocks are not the same type ++ if(b->type & BLOCK_INTRA){ ++ return 3+2*( av_log2(2*FFABS(left->color[0] - b->color[0])) ++ + av_log2(2*FFABS(left->color[1] - b->color[1])) ++ + av_log2(2*FFABS(left->color[2] - b->color[2]))); ++ }else{ ++ pred_mv(s, &dmx, &dmy, b->ref, left, top, tr); ++ dmx-= b->mx; ++ dmy-= b->my; ++ return 2*(1 + av_log2(2*FFABS(dmx)) //FIXME kill the 2* can be merged in lambda ++ + av_log2(2*FFABS(dmy)) ++ + av_log2(2*b->ref)); ++ } ++} ++ ++static int get_block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index, const uint8_t *obmc_edged){ ++ Plane *p= &s->plane[plane_index]; ++ const int block_size = MB_SIZE >> s->block_max_depth; ++ const int block_w = plane_index ? block_size/2 : block_size; ++ const int obmc_stride= plane_index ? block_size : 2*block_size; ++ const int ref_stride= s->current_picture.linesize[plane_index]; ++ uint8_t *dst= s->current_picture.data[plane_index]; ++ uint8_t *src= s-> input_picture.data[plane_index]; ++ IDWTELEM *pred= (IDWTELEM*)s->m.obmc_scratchpad + plane_index*block_size*block_size*4; ++ uint8_t *cur = s->scratchbuf; ++ uint8_t tmp[ref_stride*(2*MB_SIZE+HTAPS_MAX-1)]; ++ const int b_stride = s->b_width << s->block_max_depth; ++ const int b_height = s->b_height<< s->block_max_depth; ++ const int w= p->width; ++ const int h= p->height; ++ int distortion; ++ int rate= 0; ++ const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); ++ int sx= block_w*mb_x - block_w/2; ++ int sy= block_w*mb_y - block_w/2; ++ int x0= FFMAX(0,-sx); ++ int y0= FFMAX(0,-sy); ++ int x1= FFMIN(block_w*2, w-sx); ++ int y1= FFMIN(block_w*2, h-sy); ++ int i,x,y; ++ ++ ff_snow_pred_block(s, cur, tmp, ref_stride, sx, sy, block_w*2, block_w*2, &s->block[mb_x + mb_y*b_stride], plane_index, w, h); ++ ++ for(y=y0; y= LOG2_OBMC_MAX ++ int v = (cur1[x] * obmc1[x]) << (FRAC_BITS - LOG2_OBMC_MAX); ++#else ++ int v = (cur1[x] * obmc1[x] + (1<<(LOG2_OBMC_MAX - FRAC_BITS-1))) >> (LOG2_OBMC_MAX - FRAC_BITS); ++#endif ++ v = (v + pred1[x]) >> FRAC_BITS; ++ if(v&(~255)) v= ~(v>>31); ++ dst1[x] = v; ++ } ++ } ++ ++ /* copy the regions where obmc[] = (uint8_t)256 */ ++ if(LOG2_OBMC_MAX == 8 ++ && (mb_x == 0 || mb_x == b_stride-1) ++ && (mb_y == 0 || mb_y == b_height-1)){ ++ if(mb_x == 0) ++ x1 = block_w; ++ else ++ x0 = block_w; ++ if(mb_y == 0) ++ y1 = block_w; ++ else ++ y0 = block_w; ++ for(y=y0; yavctx->me_cmp == FF_CMP_W97) ++ distortion = ff_w97_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); ++ else if(s->avctx->me_cmp == FF_CMP_W53) ++ distortion = ff_w53_32_c(&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, 32); ++ else{ ++ distortion = 0; ++ for(i=0; i<4; i++){ ++ int off = sx+16*(i&1) + (sy+16*(i>>1))*ref_stride; ++ distortion += s->dsp.me_cmp[0](&s->m, src + off, dst + off, ref_stride, 16); ++ } ++ } ++ }else{ ++ assert(block_w==8); ++ distortion = s->dsp.me_cmp[0](&s->m, src + sx + sy*ref_stride, dst + sx + sy*ref_stride, ref_stride, block_w*2); ++ } ++ ++ if(plane_index==0){ ++ for(i=0; i<4; i++){ ++/* ..RRr ++ * .RXx. ++ * rxx.. ++ */ ++ rate += get_block_bits(s, mb_x + (i&1) - (i>>1), mb_y + (i>>1), 1); ++ } ++ if(mb_x == b_stride-2) ++ rate += get_block_bits(s, mb_x + 1, mb_y + 1, 1); ++ } ++ return distortion + rate*penalty_factor; ++} ++ ++static int get_4block_rd(SnowContext *s, int mb_x, int mb_y, int plane_index){ ++ int i, y2; ++ Plane *p= &s->plane[plane_index]; ++ const int block_size = MB_SIZE >> s->block_max_depth; ++ const int block_w = plane_index ? block_size/2 : block_size; ++ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; ++ const int obmc_stride= plane_index ? block_size : 2*block_size; ++ const int ref_stride= s->current_picture.linesize[plane_index]; ++ uint8_t *dst= s->current_picture.data[plane_index]; ++ uint8_t *src= s-> input_picture.data[plane_index]; ++ //FIXME zero_dst is const but add_yblock changes dst if add is 0 (this is never the case for dst=zero_dst ++ // const has only been removed from zero_dst to suppress a warning ++ static IDWTELEM zero_dst[4096]; //FIXME ++ const int b_stride = s->b_width << s->block_max_depth; ++ const int w= p->width; ++ const int h= p->height; ++ int distortion= 0; ++ int rate= 0; ++ const int penalty_factor= get_penalty_factor(s->lambda, s->lambda2, s->avctx->me_cmp); ++ ++ for(i=0; i<9; i++){ ++ int mb_x2= mb_x + (i%3) - 1; ++ int mb_y2= mb_y + (i/3) - 1; ++ int x= block_w*mb_x2 + block_w/2; ++ int y= block_w*mb_y2 + block_w/2; ++ ++ add_yblock(s, 0, NULL, zero_dst, dst, obmc, ++ x, y, block_w, block_w, w, h, /*dst_stride*/0, ref_stride, obmc_stride, mb_x2, mb_y2, 1, 1, plane_index); ++ ++ //FIXME find a cleaner/simpler way to skip the outside stuff ++ for(y2= y; y2<0; y2++) ++ memcpy(dst + x + y2*ref_stride, src + x + y2*ref_stride, block_w); ++ for(y2= h; y2 w){ ++ for(y2= y; y2dsp.me_cmp[block_w==8](&s->m, src + x + y*ref_stride, dst + x + y*ref_stride, ref_stride, block_w); ++ } ++ ++ if(plane_index==0){ ++ BlockNode *b= &s->block[mb_x+mb_y*b_stride]; ++ int merged= same_block(b,b+1) && same_block(b,b+b_stride) && same_block(b,b+b_stride+1); ++ ++/* ..RRRr ++ * .RXXx. ++ * .RXXx. ++ * rxxx. ++ */ ++ if(merged) ++ rate = get_block_bits(s, mb_x, mb_y, 2); ++ for(i=merged?4:0; i<9; i++){ ++ static const int dxy[9][2] = {{0,0},{1,0},{0,1},{1,1},{2,0},{2,1},{-1,2},{0,2},{1,2}}; ++ rate += get_block_bits(s, mb_x + dxy[i][0], mb_y + dxy[i][1], 1); ++ } ++ } ++ return distortion + rate*penalty_factor; ++} ++ ++static int encode_subband_c0run(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ ++ const int w= b->width; ++ const int h= b->height; ++ int x, y; ++ ++ if(1){ ++ int run=0; ++ int runs[w*h]; ++ int run_index=0; ++ int max_index; ++ ++ for(y=0; y 1){ ++ if(orientation==1) ll= src[y + (x-2)*stride]; ++ else ll= src[x - 2 + y*stride]; ++ }*/ ++ } ++ if(parent){ ++ int px= x>>1; ++ int py= y>>1; ++ if(pxparent->width && pyparent->height) ++ p= parent[px + py*2*stride]; ++ } ++ if(!(/*ll|*/l|lt|t|rt|p)){ ++ if(v){ ++ runs[run_index++]= run; ++ run=0; ++ }else{ ++ run++; ++ } ++ } ++ } ++ } ++ max_index= run_index; ++ runs[run_index++]= run; ++ run_index=0; ++ run= runs[run_index++]; ++ ++ put_symbol2(&s->c, b->state[30], max_index, 0); ++ if(run_index <= max_index) ++ put_symbol2(&s->c, b->state[1], run, 3); ++ ++ for(y=0; yc.bytestream_end - s->c.bytestream < w*40){ ++ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); ++ return -1; ++ } ++ for(x=0; x 1){ ++ if(orientation==1) ll= src[y + (x-2)*stride]; ++ else ll= src[x - 2 + y*stride]; ++ }*/ ++ } ++ if(parent){ ++ int px= x>>1; ++ int py= y>>1; ++ if(pxparent->width && pyparent->height) ++ p= parent[px + py*2*stride]; ++ } ++ if(/*ll|*/l|lt|t|rt|p){ ++ int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); ++ ++ put_rac(&s->c, &b->state[0][context], !!v); ++ }else{ ++ if(!run){ ++ run= runs[run_index++]; ++ ++ if(run_index <= max_index) ++ put_symbol2(&s->c, b->state[1], run, 3); ++ assert(v); ++ }else{ ++ run--; ++ assert(!v); ++ } ++ } ++ if(v){ ++ int context= av_log2(/*FFABS(ll) + */3*FFABS(l) + FFABS(lt) + 2*FFABS(t) + FFABS(rt) + FFABS(p)); ++ int l2= 2*FFABS(l) + (l<0); ++ int t2= 2*FFABS(t) + (t<0); ++ ++ put_symbol2(&s->c, b->state[context + 2], FFABS(v)-1, context-4); ++ put_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l2&0xFF] + 3*quant3bA[t2&0xFF]], v<0); ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++static int encode_subband(SnowContext *s, SubBand *b, IDWTELEM *src, IDWTELEM *parent, int stride, int orientation){ ++// encode_subband_qtree(s, b, src, parent, stride, orientation); ++// encode_subband_z0run(s, b, src, parent, stride, orientation); ++ return encode_subband_c0run(s, b, src, parent, stride, orientation); ++// encode_subband_dzr(s, b, src, parent, stride, orientation); ++} ++ ++static av_always_inline int check_block(SnowContext *s, int mb_x, int mb_y, int p[3], int intra, const uint8_t *obmc_edged, int *best_rd){ ++ const int b_stride= s->b_width << s->block_max_depth; ++ BlockNode *block= &s->block[mb_x + mb_y * b_stride]; ++ BlockNode backup= *block; ++ unsigned value; ++ int rd, index; ++ ++ assert(mb_x>=0 && mb_y>=0); ++ assert(mb_xcolor[0] = p[0]; ++ block->color[1] = p[1]; ++ block->color[2] = p[2]; ++ block->type |= BLOCK_INTRA; ++ }else{ ++ index= (p[0] + 31*p[1]) & (ME_CACHE_SIZE-1); ++ value= s->me_cache_generation + (p[0]>>10) + (p[1]<<6) + (block->ref<<12); ++ if(s->me_cache[index] == value) ++ return 0; ++ s->me_cache[index]= value; ++ ++ block->mx= p[0]; ++ block->my= p[1]; ++ block->type &= ~BLOCK_INTRA; ++ } ++ ++ rd= get_block_rd(s, mb_x, mb_y, 0, obmc_edged); ++ ++//FIXME chroma ++ if(rd < *best_rd){ ++ *best_rd= rd; ++ return 1; ++ }else{ ++ *block= backup; ++ return 0; ++ } ++} ++ ++/* special case for int[2] args we discard afterwards, ++ * fixes compilation problem with gcc 2.95 */ ++static av_always_inline int check_block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, const uint8_t *obmc_edged, int *best_rd){ ++ int p[2] = {p0, p1}; ++ return check_block(s, mb_x, mb_y, p, 0, obmc_edged, best_rd); ++} ++ ++static av_always_inline int check_4block_inter(SnowContext *s, int mb_x, int mb_y, int p0, int p1, int ref, int *best_rd){ ++ const int b_stride= s->b_width << s->block_max_depth; ++ BlockNode *block= &s->block[mb_x + mb_y * b_stride]; ++ BlockNode backup[4]= {block[0], block[1], block[b_stride], block[b_stride+1]}; ++ unsigned value; ++ int rd, index; ++ ++ assert(mb_x>=0 && mb_y>=0); ++ assert(mb_xme_cache_generation + (p0>>10) + (p1<<6) + (block->ref<<12); ++ if(s->me_cache[index] == value) ++ return 0; ++ s->me_cache[index]= value; ++ ++ block->mx= p0; ++ block->my= p1; ++ block->ref= ref; ++ block->type &= ~BLOCK_INTRA; ++ block[1]= block[b_stride]= block[b_stride+1]= *block; ++ ++ rd= get_4block_rd(s, mb_x, mb_y, 0); ++ ++//FIXME chroma ++ if(rd < *best_rd){ ++ *best_rd= rd; ++ return 1; ++ }else{ ++ block[0]= backup[0]; ++ block[1]= backup[1]; ++ block[b_stride]= backup[2]; ++ block[b_stride+1]= backup[3]; ++ return 0; ++ } ++} ++ ++static void iterative_me(SnowContext *s){ ++ int pass, mb_x, mb_y; ++ const int b_width = s->b_width << s->block_max_depth; ++ const int b_height= s->b_height << s->block_max_depth; ++ const int b_stride= b_width; ++ int color[3]; ++ ++ { ++ RangeCoder r = s->c; ++ uint8_t state[sizeof(s->block_state)]; ++ memcpy(state, s->block_state, sizeof(s->block_state)); ++ for(mb_y= 0; mb_yb_height; mb_y++) ++ for(mb_x= 0; mb_xb_width; mb_x++) ++ encode_q_branch(s, 0, mb_x, mb_y); ++ s->c = r; ++ memcpy(s->block_state, state, sizeof(s->block_state)); ++ } ++ ++ for(pass=0; pass<25; pass++){ ++ int change= 0; ++ ++ for(mb_y= 0; mb_yblock[index]; ++ BlockNode *tb = mb_y ? &s->block[index-b_stride ] : NULL; ++ BlockNode *lb = mb_x ? &s->block[index -1] : NULL; ++ BlockNode *rb = mb_x+1block[index +1] : NULL; ++ BlockNode *bb = mb_y+1block[index+b_stride ] : NULL; ++ BlockNode *tlb= mb_x && mb_y ? &s->block[index-b_stride-1] : NULL; ++ BlockNode *trb= mb_x+1block[index-b_stride+1] : NULL; ++ BlockNode *blb= mb_x && mb_y+1block[index+b_stride-1] : NULL; ++ BlockNode *brb= mb_x+1block[index+b_stride+1] : NULL; ++ const int b_w= (MB_SIZE >> s->block_max_depth); ++ uint8_t obmc_edged[b_w*2][b_w*2]; ++ ++ if(pass && (block->type & BLOCK_OPT)) ++ continue; ++ block->type |= BLOCK_OPT; ++ ++ backup= *block; ++ ++ if(!s->me_cache_generation) ++ memset(s->me_cache, 0, sizeof(s->me_cache)); ++ s->me_cache_generation += 1<<22; ++ ++ //FIXME precalculate ++ { ++ int x, y; ++ memcpy(obmc_edged, obmc_tab[s->block_max_depth], b_w*b_w*4); ++ if(mb_x==0) ++ for(y=0; y input_picture.data[0]; ++ uint8_t *dst= s->current_picture.data[0]; ++ const int stride= s->current_picture.linesize[0]; ++ const int block_w= MB_SIZE >> s->block_max_depth; ++ const int sx= block_w*mb_x - block_w/2; ++ const int sy= block_w*mb_y - block_w/2; ++ const int w= s->plane[0].width; ++ const int h= s->plane[0].height; ++ int y; ++ ++ for(y=sy; y<0; y++) ++ memcpy(dst + sx + y*stride, src + sx + y*stride, block_w*2); ++ for(y=h; y w){ ++ for(y=sy; y 0 && (block->type&BLOCK_INTRA)){ ++ int color0[3]= {block->color[0], block->color[1], block->color[2]}; ++ check_block(s, mb_x, mb_y, color0, 1, *obmc_edged, &best_rd); ++ }else ++ check_block_inter(s, mb_x, mb_y, block->mx, block->my, *obmc_edged, &best_rd); ++ ++ ref_b= *block; ++ ref_rd= best_rd; ++ for(ref=0; ref < s->ref_frames; ref++){ ++ int16_t (*mvr)[2]= &s->ref_mvs[ref][index]; ++ if(s->ref_scores[ref][index] > s->ref_scores[ref_b.ref][index]*3/2) //FIXME tune threshold ++ continue; ++ block->ref= ref; ++ best_rd= INT_MAX; ++ ++ check_block_inter(s, mb_x, mb_y, mvr[0][0], mvr[0][1], *obmc_edged, &best_rd); ++ check_block_inter(s, mb_x, mb_y, 0, 0, *obmc_edged, &best_rd); ++ if(tb) ++ check_block_inter(s, mb_x, mb_y, mvr[-b_stride][0], mvr[-b_stride][1], *obmc_edged, &best_rd); ++ if(lb) ++ check_block_inter(s, mb_x, mb_y, mvr[-1][0], mvr[-1][1], *obmc_edged, &best_rd); ++ if(rb) ++ check_block_inter(s, mb_x, mb_y, mvr[1][0], mvr[1][1], *obmc_edged, &best_rd); ++ if(bb) ++ check_block_inter(s, mb_x, mb_y, mvr[b_stride][0], mvr[b_stride][1], *obmc_edged, &best_rd); ++ ++ /* fullpel ME */ ++ //FIXME avoid subpel interpolation / round to nearest integer ++ do{ ++ dia_change=0; ++ for(i=0; iavctx->dia_size, 1); i++){ ++ for(j=0; jmx+4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); ++ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); ++ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+4*(i-j), block->my-(4*j), *obmc_edged, &best_rd); ++ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx-4*(i-j), block->my+(4*j), *obmc_edged, &best_rd); ++ } ++ } ++ }while(dia_change); ++ /* subpel ME */ ++ do{ ++ static const int square[8][2]= {{+1, 0},{-1, 0},{ 0,+1},{ 0,-1},{+1,+1},{-1,-1},{+1,-1},{-1,+1},}; ++ dia_change=0; ++ for(i=0; i<8; i++) ++ dia_change |= check_block_inter(s, mb_x, mb_y, block->mx+square[i][0], block->my+square[i][1], *obmc_edged, &best_rd); ++ }while(dia_change); ++ //FIXME or try the standard 2 pass qpel or similar ++ ++ mvr[0][0]= block->mx; ++ mvr[0][1]= block->my; ++ if(ref_rd > best_rd){ ++ ref_rd= best_rd; ++ ref_b= *block; ++ } ++ } ++ best_rd= ref_rd; ++ *block= ref_b; ++ check_block(s, mb_x, mb_y, color, 1, *obmc_edged, &best_rd); ++ //FIXME RD style color selection ++ if(!same_block(block, &backup)){ ++ if(tb ) tb ->type &= ~BLOCK_OPT; ++ if(lb ) lb ->type &= ~BLOCK_OPT; ++ if(rb ) rb ->type &= ~BLOCK_OPT; ++ if(bb ) bb ->type &= ~BLOCK_OPT; ++ if(tlb) tlb->type &= ~BLOCK_OPT; ++ if(trb) trb->type &= ~BLOCK_OPT; ++ if(blb) blb->type &= ~BLOCK_OPT; ++ if(brb) brb->type &= ~BLOCK_OPT; ++ change ++; ++ } ++ } ++ } ++ av_log(s->avctx, AV_LOG_ERROR, "pass:%d changed:%d\n", pass, change); ++ if(!change) ++ break; ++ } ++ ++ if(s->block_max_depth == 1){ ++ int change= 0; ++ for(mb_y= 0; mb_yblock[index]; ++ b[1]= b[0]+1; ++ b[2]= b[0]+b_stride; ++ b[3]= b[2]+1; ++ if(same_block(b[0], b[1]) && ++ same_block(b[0], b[2]) && ++ same_block(b[0], b[3])) ++ continue; ++ ++ if(!s->me_cache_generation) ++ memset(s->me_cache, 0, sizeof(s->me_cache)); ++ s->me_cache_generation += 1<<22; ++ ++ init_rd= best_rd= get_4block_rd(s, mb_x, mb_y, 0); ++ ++ //FIXME more multiref search? ++ check_4block_inter(s, mb_x, mb_y, ++ (b[0]->mx + b[1]->mx + b[2]->mx + b[3]->mx + 2) >> 2, ++ (b[0]->my + b[1]->my + b[2]->my + b[3]->my + 2) >> 2, 0, &best_rd); ++ ++ for(i=0; i<4; i++) ++ if(!(b[i]->type&BLOCK_INTRA)) ++ check_4block_inter(s, mb_x, mb_y, b[i]->mx, b[i]->my, b[i]->ref, &best_rd); ++ ++ if(init_rd != best_rd) ++ change++; ++ } ++ } ++ av_log(s->avctx, AV_LOG_ERROR, "pass:4mv changed:%d\n", change*4); ++ } ++} ++ ++static void encode_blocks(SnowContext *s, int search){ ++ int x, y; ++ int w= s->b_width; ++ int h= s->b_height; ++ ++ if(s->avctx->me_method == ME_ITER && !s->keyframe && search) ++ iterative_me(s); ++ ++ for(y=0; yc.bytestream_end - s->c.bytestream < w*MB_SIZE*MB_SIZE*3){ //FIXME nicer limit ++ av_log(s->avctx, AV_LOG_ERROR, "encoded frame too large\n"); ++ return; ++ } ++ for(x=0; xavctx->me_method == ME_ITER || !search) ++ encode_q_branch2(s, 0, x, y); ++ else ++ encode_q_branch (s, 0, x, y); ++ } ++ } ++} ++ ++static void quantize(SnowContext *s, SubBand *b, IDWTELEM *dst, DWTELEM *src, int stride, int bias){ ++ const int w= b->width; ++ const int h= b->height; ++ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); ++ const int qmul= qexp[qlog&(QROOT-1)]<<((qlog>>QSHIFT) + ENCODER_EXTRA_BITS); ++ int x,y, thres1, thres2; ++ ++ if(s->qlog == LOSSLESS_QLOG){ ++ for(y=0; y>3; ++ thres1= ((qmul - bias)>>QEXPSHIFT) - 1; ++ thres2= 2*thres1; ++ ++ if(!bias){ ++ for(y=0; y thres2){ ++ if(i>=0){ ++ i<<= QEXPSHIFT; ++ i/= qmul; //FIXME optimize ++ dst[x + y*stride]= i; ++ }else{ ++ i= -i; ++ i<<= QEXPSHIFT; ++ i/= qmul; //FIXME optimize ++ dst[x + y*stride]= -i; ++ } ++ }else ++ dst[x + y*stride]= 0; ++ } ++ } ++ }else{ ++ for(y=0; y thres2){ ++ if(i>=0){ ++ i<<= QEXPSHIFT; ++ i= (i + bias) / qmul; //FIXME optimize ++ dst[x + y*stride]= i; ++ }else{ ++ i= -i; ++ i<<= QEXPSHIFT; ++ i= (i + bias) / qmul; //FIXME optimize ++ dst[x + y*stride]= -i; ++ } ++ }else ++ dst[x + y*stride]= 0; ++ } ++ } ++ } ++} ++ ++static void dequantize(SnowContext *s, SubBand *b, IDWTELEM *src, int stride){ ++ const int w= b->width; ++ const int h= b->height; ++ const int qlog= av_clip(s->qlog + b->qlog, 0, QROOT*16); ++ const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); ++ const int qadd= (s->qbias*qmul)>>QBIAS_SHIFT; ++ int x,y; ++ ++ if(s->qlog == LOSSLESS_QLOG) return; ++ ++ for(y=0; y>(QEXPSHIFT)); //FIXME try different bias ++ }else if(i>0){ ++ src[x + y*stride]= (( i*qmul + qadd)>>(QEXPSHIFT)); ++ } ++ } ++ } ++} ++ ++static void decorrelate(SnowContext *s, SubBand *b, IDWTELEM *src, int stride, int inverse, int use_median){ ++ const int w= b->width; ++ const int h= b->height; ++ int x,y; ++ ++ for(y=h-1; y>=0; y--){ ++ for(x=w-1; x>=0; x--){ ++ int i= x + y*stride; ++ ++ if(x){ ++ if(use_median){ ++ if(y && x+1width; ++ const int h= b->height; ++ int x,y; ++ ++ for(y=0; yspatial_decomposition_count; level++){ ++ for(orientation=level ? 1:0; orientation<4; orientation++){ ++ if(orientation==2) continue; ++ put_symbol(&s->c, s->header_state, s->plane[plane_index].band[level][orientation].qlog, 1); ++ } ++ } ++ } ++} ++ ++static void encode_header(SnowContext *s){ ++ int plane_index, i; ++ uint8_t kstate[32]; ++ ++ memset(kstate, MID_STATE, sizeof(kstate)); ++ ++ put_rac(&s->c, kstate, s->keyframe); ++ if(s->keyframe || s->always_reset){ ++ ff_snow_reset_contexts(s); ++ s->last_spatial_decomposition_type= ++ s->last_qlog= ++ s->last_qbias= ++ s->last_mv_scale= ++ s->last_block_max_depth= 0; ++ for(plane_index=0; plane_index<2; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ p->last_htaps=0; ++ p->last_diag_mc=0; ++ memset(p->last_hcoeff, 0, sizeof(p->last_hcoeff)); ++ } ++ } ++ if(s->keyframe){ ++ put_symbol(&s->c, s->header_state, s->version, 0); ++ put_rac(&s->c, s->header_state, s->always_reset); ++ put_symbol(&s->c, s->header_state, s->temporal_decomposition_type, 0); ++ put_symbol(&s->c, s->header_state, s->temporal_decomposition_count, 0); ++ put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); ++ put_symbol(&s->c, s->header_state, s->colorspace_type, 0); ++ put_symbol(&s->c, s->header_state, s->chroma_h_shift, 0); ++ put_symbol(&s->c, s->header_state, s->chroma_v_shift, 0); ++ put_rac(&s->c, s->header_state, s->spatial_scalability); ++// put_rac(&s->c, s->header_state, s->rate_scalability); ++ put_symbol(&s->c, s->header_state, s->max_ref_frames-1, 0); ++ ++ encode_qlogs(s); ++ } ++ ++ if(!s->keyframe){ ++ int update_mc=0; ++ for(plane_index=0; plane_index<2; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ update_mc |= p->last_htaps != p->htaps; ++ update_mc |= p->last_diag_mc != p->diag_mc; ++ update_mc |= !!memcmp(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); ++ } ++ put_rac(&s->c, s->header_state, update_mc); ++ if(update_mc){ ++ for(plane_index=0; plane_index<2; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ put_rac(&s->c, s->header_state, p->diag_mc); ++ put_symbol(&s->c, s->header_state, p->htaps/2-1, 0); ++ for(i= p->htaps/2; i; i--) ++ put_symbol(&s->c, s->header_state, FFABS(p->hcoeff[i]), 0); ++ } ++ } ++ if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ ++ put_rac(&s->c, s->header_state, 1); ++ put_symbol(&s->c, s->header_state, s->spatial_decomposition_count, 0); ++ encode_qlogs(s); ++ }else ++ put_rac(&s->c, s->header_state, 0); ++ } ++ ++ put_symbol(&s->c, s->header_state, s->spatial_decomposition_type - s->last_spatial_decomposition_type, 1); ++ put_symbol(&s->c, s->header_state, s->qlog - s->last_qlog , 1); ++ put_symbol(&s->c, s->header_state, s->mv_scale - s->last_mv_scale, 1); ++ put_symbol(&s->c, s->header_state, s->qbias - s->last_qbias , 1); ++ put_symbol(&s->c, s->header_state, s->block_max_depth - s->last_block_max_depth, 1); ++ ++} ++ ++static void update_last_header_values(SnowContext *s){ ++ int plane_index; ++ ++ if(!s->keyframe){ ++ for(plane_index=0; plane_index<2; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ p->last_diag_mc= p->diag_mc; ++ p->last_htaps = p->htaps; ++ memcpy(p->last_hcoeff, p->hcoeff, sizeof(p->hcoeff)); ++ } ++ } ++ ++ s->last_spatial_decomposition_type = s->spatial_decomposition_type; ++ s->last_qlog = s->qlog; ++ s->last_qbias = s->qbias; ++ s->last_mv_scale = s->mv_scale; ++ s->last_block_max_depth = s->block_max_depth; ++ s->last_spatial_decomposition_count = s->spatial_decomposition_count; ++} ++ ++static int qscale2qlog(int qscale){ ++ return rint(QROOT*log(qscale / (float)FF_QP2LAMBDA)/log(2)) ++ + 61*QROOT/8; ///< 64 > 60 ++} ++ ++static int ratecontrol_1pass(SnowContext *s, AVFrame *pict) ++{ ++ /* Estimate the frame's complexity as a sum of weighted dwt coefficients. ++ * FIXME we know exact mv bits at this point, ++ * but ratecontrol isn't set up to include them. */ ++ uint32_t coef_sum= 0; ++ int level, orientation, delta_qlog; ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &s->plane[0].band[level][orientation]; ++ IDWTELEM *buf= b->ibuf; ++ const int w= b->width; ++ const int h= b->height; ++ const int stride= b->stride; ++ const int qlog= av_clip(2*QROOT + b->qlog, 0, QROOT*16); ++ const int qmul= qexp[qlog&(QROOT-1)]<<(qlog>>QSHIFT); ++ const int qdiv= (1<<16)/qmul; ++ int x, y; ++ //FIXME this is ugly ++ for(y=0; ybuf[x+y*stride]; ++ if(orientation==0) ++ decorrelate(s, b, buf, stride, 1, 0); ++ for(y=0; y> 16; ++ } ++ } ++ ++ /* ugly, ratecontrol just takes a sqrt again */ ++ coef_sum = (uint64_t)coef_sum * coef_sum >> 16; ++ assert(coef_sum < INT_MAX); ++ ++ if(pict->pict_type == AV_PICTURE_TYPE_I){ ++ s->m.current_picture.mb_var_sum= coef_sum; ++ s->m.current_picture.mc_mb_var_sum= 0; ++ }else{ ++ s->m.current_picture.mc_mb_var_sum= coef_sum; ++ s->m.current_picture.mb_var_sum= 0; ++ } ++ ++ pict->quality= ff_rate_estimate_qscale(&s->m, 1); ++ if (pict->quality < 0) ++ return INT_MIN; ++ s->lambda= pict->quality * 3/2; ++ delta_qlog= qscale2qlog(pict->quality) - s->qlog; ++ s->qlog+= delta_qlog; ++ return delta_qlog; ++} ++ ++static void calculate_visual_weight(SnowContext *s, Plane *p){ ++ int width = p->width; ++ int height= p->height; ++ int level, orientation, x, y; ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ IDWTELEM *ibuf= b->ibuf; ++ int64_t error=0; ++ ++ memset(s->spatial_idwt_buffer, 0, sizeof(*s->spatial_idwt_buffer)*width*height); ++ ibuf[b->width/2 + b->height/2*b->stride]= 256*16; ++ ff_spatial_idwt(s->spatial_idwt_buffer, width, height, width, s->spatial_decomposition_type, s->spatial_decomposition_count); ++ for(y=0; yspatial_idwt_buffer[x + y*width]*16; ++ error += d*d; ++ } ++ } ++ ++ b->qlog= (int)(log(352256.0/sqrt(error)) / log(pow(2.0, 1.0/QROOT))+0.5); ++ } ++ } ++} ++ ++static int encode_frame(AVCodecContext *avctx, unsigned char *buf, int buf_size, void *data){ ++ SnowContext *s = avctx->priv_data; ++ RangeCoder * const c= &s->c; ++ AVFrame *pict = data; ++ const int width= s->avctx->width; ++ const int height= s->avctx->height; ++ int level, orientation, plane_index, i, y; ++ uint8_t rc_header_bak[sizeof(s->header_state)]; ++ uint8_t rc_block_bak[sizeof(s->block_state)]; ++ ++ ff_init_range_encoder(c, buf, buf_size); ++ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); ++ ++ for(i=0; i<3; i++){ ++ int shift= !!i; ++ for(y=0; y<(height>>shift); y++) ++ memcpy(&s->input_picture.data[i][y * s->input_picture.linesize[i]], ++ &pict->data[i][y * pict->linesize[i]], ++ width>>shift); ++ } ++ s->new_picture = *pict; ++ ++ s->m.picture_number= avctx->frame_number; ++ if(avctx->flags&CODEC_FLAG_PASS2){ ++ s->m.pict_type = ++ pict->pict_type= s->m.rc_context.entry[avctx->frame_number].new_pict_type; ++ s->keyframe= pict->pict_type==AV_PICTURE_TYPE_I; ++ if(!(avctx->flags&CODEC_FLAG_QSCALE)) { ++ pict->quality= ff_rate_estimate_qscale(&s->m, 0); ++ if (pict->quality < 0) ++ return -1; ++ } ++ }else{ ++ s->keyframe= avctx->gop_size==0 || avctx->frame_number % avctx->gop_size == 0; ++ s->m.pict_type= ++ pict->pict_type= s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; ++ } ++ ++ if(s->pass1_rc && avctx->frame_number == 0) ++ pict->quality= 2*FF_QP2LAMBDA; ++ if(pict->quality){ ++ s->qlog= qscale2qlog(pict->quality); ++ s->lambda = pict->quality * 3/2; ++ } ++ if(s->qlog < 0 || (!pict->quality && (avctx->flags & CODEC_FLAG_QSCALE))){ ++ s->qlog= LOSSLESS_QLOG; ++ s->lambda = 0; ++ }//else keep previous frame's qlog until after motion estimation ++ ++ ff_snow_frame_start(s); ++ ++ s->m.current_picture_ptr= &s->m.current_picture; ++ s->m.last_picture.f.pts = s->m.current_picture.f.pts; ++ s->m.current_picture.f.pts = pict->pts; ++ if(pict->pict_type == AV_PICTURE_TYPE_P){ ++ int block_width = (width +15)>>4; ++ int block_height= (height+15)>>4; ++ int stride= s->current_picture.linesize[0]; ++ ++ assert(s->current_picture.data[0]); ++ assert(s->last_picture[0].data[0]); ++ ++ s->m.avctx= s->avctx; ++ s->m.current_picture.f.data[0] = s->current_picture.data[0]; ++ s->m. last_picture.f.data[0] = s->last_picture[0].data[0]; ++ s->m. new_picture.f.data[0] = s-> input_picture.data[0]; ++ s->m. last_picture_ptr= &s->m. last_picture; ++ s->m.linesize= ++ s->m. last_picture.f.linesize[0] = ++ s->m. new_picture.f.linesize[0] = ++ s->m.current_picture.f.linesize[0] = stride; ++ s->m.uvlinesize= s->current_picture.linesize[1]; ++ s->m.width = width; ++ s->m.height= height; ++ s->m.mb_width = block_width; ++ s->m.mb_height= block_height; ++ s->m.mb_stride= s->m.mb_width+1; ++ s->m.b8_stride= 2*s->m.mb_width+1; ++ s->m.f_code=1; ++ s->m.pict_type= pict->pict_type; ++ s->m.me_method= s->avctx->me_method; ++ s->m.me.scene_change_score=0; ++ s->m.flags= s->avctx->flags; ++ s->m.quarter_sample= (s->avctx->flags & CODEC_FLAG_QPEL)!=0; ++ s->m.out_format= FMT_H263; ++ s->m.unrestricted_mv= 1; ++ ++ s->m.lambda = s->lambda; ++ s->m.qscale= (s->m.lambda*139 + FF_LAMBDA_SCALE*64) >> (FF_LAMBDA_SHIFT + 7); ++ s->lambda2= s->m.lambda2= (s->m.lambda*s->m.lambda + FF_LAMBDA_SCALE/2) >> FF_LAMBDA_SHIFT; ++ ++ s->m.dsp= s->dsp; //move ++ ff_init_me(&s->m); ++ s->dsp= s->m.dsp; ++ } ++ ++ if(s->pass1_rc){ ++ memcpy(rc_header_bak, s->header_state, sizeof(s->header_state)); ++ memcpy(rc_block_bak, s->block_state, sizeof(s->block_state)); ++ } ++ ++redo_frame: ++ ++ if(pict->pict_type == AV_PICTURE_TYPE_I) ++ s->spatial_decomposition_count= 5; ++ else ++ s->spatial_decomposition_count= 5; ++ ++ s->m.pict_type = pict->pict_type; ++ s->qbias= pict->pict_type == AV_PICTURE_TYPE_P ? 2 : 0; ++ ++ ff_snow_common_init_after_header(avctx); ++ ++ if(s->last_spatial_decomposition_count != s->spatial_decomposition_count){ ++ for(plane_index=0; plane_index<3; plane_index++){ ++ calculate_visual_weight(s, &s->plane[plane_index]); ++ } ++ } ++ ++ encode_header(s); ++ s->m.misc_bits = 8*(s->c.bytestream - s->c.bytestream_start); ++ encode_blocks(s, 1); ++ s->m.mv_bits = 8*(s->c.bytestream - s->c.bytestream_start) - s->m.misc_bits; ++ ++ for(plane_index=0; plane_index<3; plane_index++){ ++ Plane *p= &s->plane[plane_index]; ++ int w= p->width; ++ int h= p->height; ++ int x, y; ++// int bits= put_bits_count(&s->c.pb); ++ ++ if (!s->memc_only) { ++ //FIXME optimize ++ if(pict->data[plane_index]) //FIXME gray hack ++ for(y=0; yspatial_idwt_buffer[y*w + x]= pict->data[plane_index][y*pict->linesize[plane_index] + x]<spatial_idwt_buffer, plane_index, 0); ++ ++ if( plane_index==0 ++ && pict->pict_type == AV_PICTURE_TYPE_P ++ && !(avctx->flags&CODEC_FLAG_PASS2) ++ && s->m.me.scene_change_score > s->avctx->scenechange_threshold){ ++ ff_init_range_encoder(c, buf, buf_size); ++ ff_build_rac_states(c, 0.05*(1LL<<32), 256-8); ++ pict->pict_type= AV_PICTURE_TYPE_I; ++ s->keyframe=1; ++ s->current_picture.key_frame=1; ++ goto redo_frame; ++ } ++ ++ if(s->qlog == LOSSLESS_QLOG){ ++ for(y=0; yspatial_dwt_buffer[y*w + x]= (s->spatial_idwt_buffer[y*w + x] + (1<<(FRAC_BITS-1))-1)>>FRAC_BITS; ++ } ++ } ++ }else{ ++ for(y=0; yspatial_dwt_buffer[y*w + x]=s->spatial_idwt_buffer[y*w + x]<spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type); ++ else*/ ++ ff_spatial_dwt(s->spatial_dwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); ++ ++ if(s->pass1_rc && plane_index==0){ ++ int delta_qlog = ratecontrol_1pass(s, pict); ++ if (delta_qlog <= INT_MIN) ++ return -1; ++ if(delta_qlog){ ++ //reordering qlog in the bitstream would eliminate this reset ++ ff_init_range_encoder(c, buf, buf_size); ++ memcpy(s->header_state, rc_header_bak, sizeof(s->header_state)); ++ memcpy(s->block_state, rc_block_bak, sizeof(s->block_state)); ++ encode_header(s); ++ encode_blocks(s, 0); ++ } ++ } ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ ++ if(!QUANTIZE2) ++ quantize(s, b, b->ibuf, b->buf, b->stride, s->qbias); ++ if(orientation==0) ++ decorrelate(s, b, b->ibuf, b->stride, pict->pict_type == AV_PICTURE_TYPE_P, 0); ++ encode_subband(s, b, b->ibuf, b->parent ? b->parent->ibuf : NULL, b->stride, orientation); ++ assert(b->parent==NULL || b->parent->stride == b->stride*2); ++ if(orientation==0) ++ correlate(s, b, b->ibuf, b->stride, 1, 0); ++ } ++ } ++ ++ for(level=0; levelspatial_decomposition_count; level++){ ++ for(orientation=level ? 1 : 0; orientation<4; orientation++){ ++ SubBand *b= &p->band[level][orientation]; ++ ++ dequantize(s, b, b->ibuf, b->stride); ++ } ++ } ++ ++ ff_spatial_idwt(s->spatial_idwt_buffer, w, h, w, s->spatial_decomposition_type, s->spatial_decomposition_count); ++ if(s->qlog == LOSSLESS_QLOG){ ++ for(y=0; yspatial_idwt_buffer[y*w + x]<<=FRAC_BITS; ++ } ++ } ++ } ++ predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); ++ }else{ ++ //ME/MC only ++ if(pict->pict_type == AV_PICTURE_TYPE_I){ ++ for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x]= ++ pict->data[plane_index][y*pict->linesize[plane_index] + x]; ++ } ++ } ++ }else{ ++ memset(s->spatial_idwt_buffer, 0, sizeof(IDWTELEM)*w*h); ++ predict_plane(s, s->spatial_idwt_buffer, plane_index, 1); ++ } ++ } ++ if(s->avctx->flags&CODEC_FLAG_PSNR){ ++ int64_t error= 0; ++ ++ if(pict->data[plane_index]) //FIXME gray hack ++ for(y=0; ycurrent_picture.data[plane_index][y*s->current_picture.linesize[plane_index] + x] - pict->data[plane_index][y*pict->linesize[plane_index] + x]; ++ error += d*d; ++ } ++ } ++ s->avctx->error[plane_index] += error; ++ s->current_picture.error[plane_index] = error; ++ } ++ ++ } ++ ++ update_last_header_values(s); ++ ++ ff_snow_release_buffer(avctx); ++ ++ s->current_picture.coded_picture_number = avctx->frame_number; ++ s->current_picture.pict_type = pict->pict_type; ++ s->current_picture.quality = pict->quality; ++ s->m.frame_bits = 8*(s->c.bytestream - s->c.bytestream_start); ++ s->m.p_tex_bits = s->m.frame_bits - s->m.misc_bits - s->m.mv_bits; ++ s->m.current_picture.f.display_picture_number = ++ s->m.current_picture.f.coded_picture_number = avctx->frame_number; ++ s->m.current_picture.f.quality = pict->quality; ++ s->m.total_bits += 8*(s->c.bytestream - s->c.bytestream_start); ++ if(s->pass1_rc) ++ if (ff_rate_estimate_qscale(&s->m, 0) < 0) ++ return -1; ++ if(avctx->flags&CODEC_FLAG_PASS1) ++ ff_write_pass1_stats(&s->m); ++ s->m.last_pict_type = s->m.pict_type; ++ avctx->frame_bits = s->m.frame_bits; ++ avctx->mv_bits = s->m.mv_bits; ++ avctx->misc_bits = s->m.misc_bits; ++ avctx->p_tex_bits = s->m.p_tex_bits; ++ ++ emms_c(); ++ ++ return ff_rac_terminate(c); ++} ++ ++static av_cold int encode_end(AVCodecContext *avctx) ++{ ++ SnowContext *s = avctx->priv_data; ++ ++ ff_snow_common_end(s); ++ if (s->input_picture.data[0]) ++ avctx->release_buffer(avctx, &s->input_picture); ++ av_free(avctx->stats_out); ++ ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(SnowContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "memc_only", "Only do ME/MC (I frames -> ref, P frame -> ME+MC).", OFFSET(memc_only), AV_OPT_TYPE_INT, { 0 }, 0, 1, VE }, ++ { NULL }, ++}; ++ ++static const AVClass snowenc_class = { ++ .class_name = "snow encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVCodec ff_snow_encoder = { ++ .name = "snow", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SNOW, ++ .priv_data_size = sizeof(SnowContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, ++ .long_name = NULL_IF_CONFIG_SMALL("Snow"), ++ .priv_class = &snowenc_class, ++}; ++#endif ++ ++ ++#ifdef TEST ++#undef malloc ++#undef free ++#undef printf ++ ++#include "libavutil/lfg.h" ++#include "libavutil/mathematics.h" ++ ++int main(void){ ++ int width=256; ++ int height=256; ++ int buffer[2][width*height]; ++ SnowContext s; ++ int i; ++ AVLFG prng; ++ s.spatial_decomposition_count=6; ++ s.spatial_decomposition_type=1; ++ ++ av_lfg_init(&prng, 1); ++ ++ printf("testing 5/3 DWT\n"); ++ for(i=0; i20) printf("fsck: %6d %12d %7d\n",i, buffer[0][i], buffer[1][i]); ++ ++ { ++ int level, orientation, x, y; ++ int64_t errors[8][4]; ++ int64_t g=0; ++ ++ memset(errors, 0, sizeof(errors)); ++ s.spatial_decomposition_count=3; ++ s.spatial_decomposition_type=0; ++ for(level=0; level> (s.spatial_decomposition_count-level); ++ int h= height >> (s.spatial_decomposition_count-level); ++ int stride= width << (s.spatial_decomposition_count-level); ++ DWTELEM *buf= buffer[0]; ++ int64_t error=0; ++ ++ if(orientation&1) buf+=w; ++ if(orientation>1) buf+=stride>>1; ++ ++ memset(buffer[0], 0, sizeof(int)*width*height); ++ buf[w/2 + h/2*stride]= 256*256; ++ ff_spatial_idwt(buffer[0], width, height, width, s.spatial_decomposition_type, s.spatial_decomposition_count); ++ for(y=0; y> (s.spatial_decomposition_count-level); ++ //int h= height >> (s.spatial_decomposition_count-level); ++ int stride= width << (s.spatial_decomposition_count-level); ++ DWTELEM *buf= buffer[0]; ++ int64_t error=0; ++ ++ buf+=w; ++ buf+=stride>>1; ++ ++ memset(buffer[0], 0, sizeof(int)*width*height); ++ for(y=0; yb_width << s->block_max_depth; ++ const int rem_depth= s->block_max_depth - level; ++ const int index= (x + y*w) << rem_depth; ++ const int block_w= 1<block[index + i + j*w]= block; ++ } ++ } ++} ++ ++static inline void pred_mv(SnowContext *s, int *mx, int *my, int ref, ++ const BlockNode *left, const BlockNode *top, const BlockNode *tr){ ++ if(s->ref_frames == 1){ ++ *mx = mid_pred(left->mx, top->mx, tr->mx); ++ *my = mid_pred(left->my, top->my, tr->my); ++ }else{ ++ const int *scale = scale_mv_ref[ref]; ++ *mx = mid_pred((left->mx * scale[left->ref] + 128) >>8, ++ (top ->mx * scale[top ->ref] + 128) >>8, ++ (tr ->mx * scale[tr ->ref] + 128) >>8); ++ *my = mid_pred((left->my * scale[left->ref] + 128) >>8, ++ (top ->my * scale[top ->ref] + 128) >>8, ++ (tr ->my * scale[tr ->ref] + 128) >>8); ++ } ++} ++ ++static av_always_inline int same_block(BlockNode *a, BlockNode *b){ ++ if((a->type&BLOCK_INTRA) && (b->type&BLOCK_INTRA)){ ++ return !((a->color[0] - b->color[0]) | (a->color[1] - b->color[1]) | (a->color[2] - b->color[2])); ++ }else{ ++ return !((a->mx - b->mx) | (a->my - b->my) | (a->ref - b->ref) | ((a->type ^ b->type)&BLOCK_INTRA)); ++ } ++} ++ ++//FIXME name cleanup (b_w, block_w, b_width stuff) ++//XXX should we really inline it? ++static av_always_inline void add_yblock(SnowContext *s, int sliced, slice_buffer *sb, IDWTELEM *dst, uint8_t *dst8, const uint8_t *obmc, int src_x, int src_y, int b_w, int b_h, int w, int h, int dst_stride, int src_stride, int obmc_stride, int b_x, int b_y, int add, int offset_dst, int plane_index){ ++ const int b_width = s->b_width << s->block_max_depth; ++ const int b_height= s->b_height << s->block_max_depth; ++ const int b_stride= b_width; ++ BlockNode *lt= &s->block[b_x + b_y*b_stride]; ++ BlockNode *rt= lt+1; ++ BlockNode *lb= lt+b_stride; ++ BlockNode *rb= lb+1; ++ uint8_t *block[4]; ++ int tmp_step= src_stride >= 7*MB_SIZE ? MB_SIZE : MB_SIZE*src_stride; ++ uint8_t *tmp = s->scratchbuf; ++ uint8_t *ptmp; ++ int x,y; ++ ++ if(b_x<0){ ++ lt= rt; ++ lb= rb; ++ }else if(b_x + 1 >= b_width){ ++ rt= lt; ++ rb= lb; ++ } ++ if(b_y<0){ ++ lt= lb; ++ rt= rb; ++ }else if(b_y + 1 >= b_height){ ++ lb= lt; ++ rb= rt; ++ } ++ ++ if(src_x<0){ //FIXME merge with prev & always round internal width up to *16 ++ obmc -= src_x; ++ b_w += src_x; ++ if(!sliced && !offset_dst) ++ dst -= src_x; ++ src_x=0; ++ }else if(src_x + b_w > w){ ++ b_w = w - src_x; ++ } ++ if(src_y<0){ ++ obmc -= src_y*obmc_stride; ++ b_h += src_y; ++ if(!sliced && !offset_dst) ++ dst -= src_y*dst_stride; ++ src_y=0; ++ }else if(src_y + b_h> h){ ++ b_h = h - src_y; ++ } ++ ++ if(b_w<=0 || b_h<=0) return; ++ ++ assert(src_stride > 2*MB_SIZE + 5); ++ ++ if(!sliced && offset_dst) ++ dst += src_x + src_y*dst_stride; ++ dst8+= src_x + src_y*src_stride; ++// src += src_x + src_y*src_stride; ++ ++ ptmp= tmp + 3*tmp_step; ++ block[0]= ptmp; ++ ptmp+=tmp_step; ++ ff_snow_pred_block(s, block[0], tmp, src_stride, src_x, src_y, b_w, b_h, lt, plane_index, w, h); ++ ++ if(same_block(lt, rt)){ ++ block[1]= block[0]; ++ }else{ ++ block[1]= ptmp; ++ ptmp+=tmp_step; ++ ff_snow_pred_block(s, block[1], tmp, src_stride, src_x, src_y, b_w, b_h, rt, plane_index, w, h); ++ } ++ ++ if(same_block(lt, lb)){ ++ block[2]= block[0]; ++ }else if(same_block(rt, lb)){ ++ block[2]= block[1]; ++ }else{ ++ block[2]= ptmp; ++ ptmp+=tmp_step; ++ ff_snow_pred_block(s, block[2], tmp, src_stride, src_x, src_y, b_w, b_h, lb, plane_index, w, h); ++ } ++ ++ if(same_block(lt, rb) ){ ++ block[3]= block[0]; ++ }else if(same_block(rt, rb)){ ++ block[3]= block[1]; ++ }else if(same_block(lb, rb)){ ++ block[3]= block[2]; ++ }else{ ++ block[3]= ptmp; ++ ff_snow_pred_block(s, block[3], tmp, src_stride, src_x, src_y, b_w, b_h, rb, plane_index, w, h); ++ } ++ if(sliced){ ++ s->dwt.inner_add_yblock(obmc, obmc_stride, block, b_w, b_h, src_x,src_y, src_stride, sb, add, dst8); ++ }else{ ++ for(y=0; y>1); ++ const uint8_t *obmc3= obmc1+ obmc_stride*(obmc_stride>>1); ++ const uint8_t *obmc4= obmc3+ (obmc_stride>>1); ++ for(x=0; x>= 8 - FRAC_BITS; ++ } ++ if(add){ ++ v += dst[x + y*dst_stride]; ++ v = (v + (1<<(FRAC_BITS-1))) >> FRAC_BITS; ++ if(v&(~255)) v= ~(v>>31); ++ dst8[x + y*src_stride] = v; ++ }else{ ++ dst[x + y*dst_stride] -= v; ++ } ++ } ++ } ++ } ++} ++ ++static av_always_inline void predict_slice(SnowContext *s, IDWTELEM *buf, int plane_index, int add, int mb_y){ ++ Plane *p= &s->plane[plane_index]; ++ const int mb_w= s->b_width << s->block_max_depth; ++ const int mb_h= s->b_height << s->block_max_depth; ++ int x, y, mb_x; ++ int block_size = MB_SIZE >> s->block_max_depth; ++ int block_w = plane_index ? block_size/2 : block_size; ++ const uint8_t *obmc = plane_index ? obmc_tab[s->block_max_depth+1] : obmc_tab[s->block_max_depth]; ++ const int obmc_stride= plane_index ? block_size : 2*block_size; ++ int ref_stride= s->current_picture.linesize[plane_index]; ++ uint8_t *dst8= s->current_picture.data[plane_index]; ++ int w= p->width; ++ int h= p->height; ++ ++ if(s->keyframe || (s->avctx->debug&512)){ ++ if(mb_y==mb_h) ++ return; ++ ++ if(add){ ++ for(y=block_w*mb_y; y>= FRAC_BITS; ++ if(v&(~255)) v= ~(v>>31); ++ dst8[x + y*ref_stride]= v; ++ } ++ } ++ }else{ ++ for(y=block_w*mb_y; yb_height << s->block_max_depth; ++ int mb_y; ++ for(mb_y=0; mb_y<=mb_h; mb_y++) ++ predict_slice(s, buf, plane_index, add, mb_y); ++} ++ ++static inline void set_blocks(SnowContext *s, int level, int x, int y, int l, int cb, int cr, int mx, int my, int ref, int type){ ++ const int w= s->b_width << s->block_max_depth; ++ const int rem_depth= s->block_max_depth - level; ++ const int index= (x + y*w) << rem_depth; ++ const int block_w= 1<block[index + i + j*w]= block; ++ } ++ } ++} ++ ++static inline void init_ref(MotionEstContext *c, uint8_t *src[3], uint8_t *ref[3], uint8_t *ref2[3], int x, int y, int ref_index){ ++ const int offset[3]= { ++ y*c-> stride + x, ++ ((y*c->uvstride + x)>>1), ++ ((y*c->uvstride + x)>>1), ++ }; ++ int i; ++ for(i=0; i<3; i++){ ++ c->src[0][i]= src [i]; ++ c->ref[0][i]= ref [i] + offset[i]; ++ } ++ assert(!ref_index); ++} ++ ++ ++/* bitstream functions */ ++ ++extern const int8_t quant3bA[256]; ++ ++#define QEXPSHIFT (7-FRAC_BITS+8) //FIXME try to change this to 0 ++ ++static inline void put_symbol(RangeCoder *c, uint8_t *state, int v, int is_signed){ ++ int i; ++ ++ if(v){ ++ const int a= FFABS(v); ++ const int e= av_log2(a); ++ const int el= FFMIN(e, 10); ++ put_rac(c, state+0, 0); ++ ++ for(i=0; i=el; i--){ ++ put_rac(c, state+22+9, (a>>i)&1); //22..31 ++ } ++ for(; i>=0; i--){ ++ put_rac(c, state+22+i, (a>>i)&1); //22..31 ++ } ++ ++ if(is_signed) ++ put_rac(c, state+11 + el, v < 0); //11..21 ++ }else{ ++ put_rac(c, state+0, 1); ++ } ++} ++ ++static inline int get_symbol(RangeCoder *c, uint8_t *state, int is_signed){ ++ if(get_rac(c, state+0)) ++ return 0; ++ else{ ++ int i, e, a; ++ e= 0; ++ while(get_rac(c, state+1 + FFMIN(e,9))){ //1..10 ++ e++; ++ } ++ ++ a= 1; ++ for(i=e-1; i>=0; i--){ ++ a += a + get_rac(c, state+22 + FFMIN(i,9)); //22..31 ++ } ++ ++ e= -(is_signed && get_rac(c, state+11 + FFMIN(e,10))); //11..21 ++ return (a^e)-e; ++ } ++} ++ ++static inline void put_symbol2(RangeCoder *c, uint8_t *state, int v, int log2){ ++ int i; ++ int r= log2>=0 ? 1<=0); ++ assert(log2>=-4); ++ ++ while(v >= r){ ++ put_rac(c, state+4+log2, 1); ++ v -= r; ++ log2++; ++ if(log2>0) r+=r; ++ } ++ put_rac(c, state+4+log2, 0); ++ ++ for(i=log2-1; i>=0; i--){ ++ put_rac(c, state+31-i, (v>>i)&1); ++ } ++} ++ ++static inline int get_symbol2(RangeCoder *c, uint8_t *state, int log2){ ++ int i; ++ int r= log2>=0 ? 1<=-4); ++ ++ while(get_rac(c, state+4+log2)){ ++ v+= r; ++ log2++; ++ if(log2>0) r+=r; ++ } ++ ++ for(i=log2-1; i>=0; i--){ ++ v+= get_rac(c, state+31-i)<width; ++ const int h= b->height; ++ int x,y; ++ ++ int run, runs; ++ x_and_coeff *xc= b->x_coeff; ++ x_and_coeff *prev_xc= NULL; ++ x_and_coeff *prev2_xc= xc; ++ x_and_coeff *parent_xc= parent ? parent->x_coeff : NULL; ++ x_and_coeff *prev_parent_xc= parent_xc; ++ ++ runs= get_symbol2(&s->c, b->state[30], 0); ++ if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); ++ else run= INT_MAX; ++ ++ for(y=0; yx == 0){ ++ rt= prev_xc->coeff; ++ } ++ for(x=0; xx <= x) ++ prev_xc++; ++ if(prev_xc->x == x + 1) ++ rt= prev_xc->coeff; ++ else ++ rt=0; ++ } ++ if(parent_xc){ ++ if(x>>1 > parent_xc->x){ ++ parent_xc++; ++ } ++ if(x>>1 == parent_xc->x){ ++ p= parent_xc->coeff; ++ } ++ } ++ if(/*ll|*/l|lt|t|rt|p){ ++ int context= av_log2(/*FFABS(ll) + */3*(l>>1) + (lt>>1) + (t&~1) + (rt>>1) + (p>>1)); ++ ++ v=get_rac(&s->c, &b->state[0][context]); ++ if(v){ ++ v= 2*(get_symbol2(&s->c, b->state[context + 2], context-4) + 1); ++ v+=get_rac(&s->c, &b->state[0][16 + 1 + 3 + quant3bA[l&0xFF] + 3*quant3bA[t&0xFF]]); ++ ++ xc->x=x; ++ (xc++)->coeff= v; ++ } ++ }else{ ++ if(!run){ ++ if(runs-- > 0) run= get_symbol2(&s->c, b->state[1], 3); ++ else run= INT_MAX; ++ v= 2*(get_symbol2(&s->c, b->state[0 + 2], 0-4) + 1); ++ v+=get_rac(&s->c, &b->state[0][16 + 1 + 3]); ++ ++ xc->x=x; ++ (xc++)->coeff= v; ++ }else{ ++ int max_run; ++ run--; ++ v=0; ++ ++ if(y) max_run= FFMIN(run, prev_xc->x - x - 2); ++ else max_run= FFMIN(run, w-x-1); ++ if(parent_xc) ++ max_run= FFMIN(max_run, 2*parent_xc->x - x - 1); ++ x+= max_run; ++ run-= max_run; ++ } ++ } ++ } ++ (xc++)->x= w+1; //end marker ++ prev_xc= prev2_xc; ++ prev2_xc= xc; ++ ++ if(parent_xc){ ++ if(y&1){ ++ while(parent_xc->x != parent->width+1) ++ parent_xc++; ++ parent_xc++; ++ prev_parent_xc= parent_xc; ++ }else{ ++ parent_xc= prev_parent_xc; ++ } ++ } ++ } ++ ++ (xc++)->x= w+1; //end marker ++} ++ + #endif /* AVCODEC_SNOW_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sonic.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sonic.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sonic.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sonic.c 2012-05-14 14:08:54.241338110 +0200 +@@ -44,6 +44,7 @@ + #define RIGHT_SIDE 2 + + typedef struct SonicContext { ++ AVFrame frame; + int lossless, decorrelation; + + int num_taps, downsampling; +@@ -757,6 +758,9 @@ + s->channels = avctx->channels; + s->samplerate = avctx->sample_rate; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + if (!avctx->extradata) + { + av_log(avctx, AV_LOG_ERROR, "No mandatory headers present\n"); +@@ -796,7 +800,7 @@ + if (get_bits1(&gb)) // XXX FIXME + av_log(avctx, AV_LOG_INFO, "Custom quant table\n"); + +- s->block_align = (int)(2048.0*(s->samplerate/44100))/s->downsampling; ++ s->block_align = (int)(2048.0*s->samplerate/44100)/s->downsampling; + s->frame_size = s->channels*s->block_align*s->downsampling; + // avctx->frame_size = s->block_align; + +@@ -848,18 +852,25 @@ + } + + static int sonic_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, ++ void *data, int *got_frame_ptr, + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + SonicContext *s = avctx->priv_data; + GetBitContext gb; +- int i, quant, ch, j; +- short *samples = data; ++ int i, quant, ch, j, ret; ++ short *samples; + + if (buf_size == 0) return 0; + ++ s->frame.nb_samples = s->frame_size; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = s->frame.data[0]; ++ + // av_log(NULL, AV_LOG_INFO, "buf_size: %d\n", buf_size); + + init_get_bits(&gb, buf, buf_size*8); +@@ -930,48 +941,47 @@ + + align_get_bits(&gb); + +- *data_size = s->frame_size * 2; ++ *got_frame_ptr = 1; ++ *(AVFrame*)data = s->frame; + + return (get_bits_count(&gb)+7)/8; + } + + AVCodec ff_sonic_decoder = { +- "sonic", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SONIC, +- sizeof(SonicContext), +- sonic_decode_init, +- NULL, +- sonic_decode_close, +- sonic_decode_frame, ++ .name = "sonic", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SONIC, ++ .priv_data_size = sizeof(SonicContext), ++ .init = sonic_decode_init, ++ .close = sonic_decode_close, ++ .decode = sonic_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Sonic"), + }; + #endif /* CONFIG_SONIC_DECODER */ + + #if CONFIG_SONIC_ENCODER + AVCodec ff_sonic_encoder = { +- "sonic", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SONIC, +- sizeof(SonicContext), +- sonic_encode_init, +- sonic_encode_frame, +- sonic_encode_close, +- NULL, ++ .name = "sonic", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SONIC, ++ .priv_data_size = sizeof(SonicContext), ++ .init = sonic_encode_init, ++ .encode = sonic_encode_frame, ++ .close = sonic_encode_close, + .long_name = NULL_IF_CONFIG_SMALL("Sonic"), + }; + #endif + + #if CONFIG_SONIC_LS_ENCODER + AVCodec ff_sonic_ls_encoder = { +- "sonicls", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_SONIC_LS, +- sizeof(SonicContext), +- sonic_encode_init, +- sonic_encode_frame, +- sonic_encode_close, +- NULL, ++ .name = "sonicls", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_SONIC_LS, ++ .priv_data_size = sizeof(SonicContext), ++ .init = sonic_encode_init, ++ .encode = sonic_encode_frame, ++ .close = sonic_encode_close, + .long_name = NULL_IF_CONFIG_SMALL("Sonic lossless"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sp5xdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sp5xdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sp5xdec.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sp5xdec.c 2012-05-14 14:08:54.243338150 +0200 +@@ -38,15 +38,12 @@ + int buf_size = avpkt->size; + AVPacket avpkt_recoded; + const int qscale = 5; +- const uint8_t *buf_ptr; + uint8_t *recoded; + int i = 0, j = 0; + + if (!avctx->width || !avctx->height) + return -1; + +- buf_ptr = buf; +- + recoded = av_mallocz(buf_size + 1024); + if (!recoded) + return -1; +@@ -86,7 +83,6 @@ + recoded[j++] = 0xFF; + recoded[j++] = 0xD9; + +- avctx->flags &= ~CODEC_FLAG_EMU_EDGE; + av_init_packet(&avpkt_recoded); + avpkt_recoded.data = recoded; + avpkt_recoded.size = j; +@@ -98,29 +94,25 @@ + } + + AVCodec ff_sp5x_decoder = { +- "sp5x", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SP5X, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- sp5x_decode_frame, +- CODEC_CAP_DR1, +- NULL, +- .max_lowres = 5, ++ .name = "sp5x", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SP5X, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = sp5x_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .max_lowres = 3, + .long_name = NULL_IF_CONFIG_SMALL("Sunplus JPEG (SP5X)"), + }; + + AVCodec ff_amv_decoder = { +- "amv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_AMV, +- sizeof(MJpegDecodeContext), +- ff_mjpeg_decode_init, +- NULL, +- ff_mjpeg_decode_end, +- sp5x_decode_frame, +- CODEC_CAP_DR1, ++ .name = "amv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_AMV, ++ .priv_data_size = sizeof(MJpegDecodeContext), ++ .init = ff_mjpeg_decode_init, ++ .close = ff_mjpeg_decode_end, ++ .decode = sp5x_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("AMV Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sp5x.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sp5x.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sp5x.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sp5x.h 2012-05-14 14:08:54.242338130 +0200 +@@ -235,100 +235,4 @@ + 124,124,124,124,124,124,124,124,124,124,124,124,124,124,124,124 } + }; + +-#if 0 +-/* 4NF-M, not ZigZag */ +-static const uint8_t sp5x_quant_table_orig[18][64] = +-{ +- /* index 0, Q50 */ +- { 16, 11, 10, 16, 24, 40, 51, 61, 12, 12, 14, 19, 26, 58, 60, 55, +- 14, 13, 16, 24, 40, 57, 69, 56, 14, 17, 22, 29, 51, 87, 80, 62, +- 18, 22, 37, 56, 68,109,103, 77, 24, 35, 55, 64, 81,104,113, 92, +- 49, 64, 78, 87,103,121,120,101, 72, 92, 95, 98,112,100,103, 99 }, +- { 17, 18, 24, 47, 99, 99, 99, 99, 18, 21, 26, 66, 99, 99, 99, 99, +- 24, 26, 56, 99, 99, 99, 99, 99, 47, 66, 99, 99, 99, 99, 99, 99, +- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, +- 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99 }, +- +- /* index 1, Q70 */ +- { 10, 7, 6, 10, 14, 24, 31, 37, 7, 7, 8, 11, 16, 35, 36, 33, +- 8, 8, 10, 14, 24, 34, 41, 34, 8, 10, 13, 17, 31, 52, 48, 37, +- 11, 13, 22, 34, 41, 65, 62, 46, 14, 21, 33, 38, 49, 62, 68, 55, +- 29, 38, 47, 52, 62, 73, 72, 61, 43, 55, 57, 59, 67, 60, 62, 59 }, +- { 10, 11, 14, 28, 59, 59, 59, 59, 11, 13, 16, 40, 59, 59, 59, 59, +- 14, 16, 34, 59, 59, 59, 59, 59, 28, 40, 59, 59, 59, 59, 59, 59, +- 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, +- 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59, 59 }, +- +- /* index 2, Q80 */ +- { 6, 4, 4, 6, 10, 16, 20, 24, 5, 5, 6, 8, 10, 23, 24, 22, +- 6, 5, 6, 10, 16, 23, 28, 22, 6, 7, 9, 12, 20, 35, 32, 25, +- 7, 9, 15, 22, 27, 44, 41, 31, 10, 14, 22, 26, 32, 42, 45, 37, +- 20, 26, 31, 35, 41, 48, 48, 40, 29, 37, 38, 39, 45, 40, 41, 40 }, +- { 7, 7, 10, 19, 40, 40, 40, 40, 7, 8, 10, 26, 40, 40, 40, 40, +- 10, 10, 22, 40, 40, 40, 40, 40, 19, 26, 40, 40, 40, 40, 40, 40, +- 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, +- 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40 }, +- +- /* index 3, Q85 */ +- { 5, 3, 3, 5, 7, 12, 15, 18, 4, 4, 4, 6, 8, 17, 18, 17, +- 4, 4, 5, 7, 12, 17, 21, 17, 4, 5, 7, 9, 15, 26, 24, 19, +- 5, 7, 11, 17, 20, 33, 31, 23, 7, 11, 17, 19, 24, 31, 34, 28, +- 15, 19, 23, 26, 31, 36, 36, 30, 22, 28, 29, 29, 34, 30, 31, 30 }, +- { 5, 5, 7, 14, 30, 30, 30, 30, 5, 6, 8, 20, 30, 30, 30, 30, +- 7, 8, 17, 30, 30, 30, 30, 30, 14, 20, 30, 30, 30, 30, 30, 30, +- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, +- 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 }, +- +- /* index 4, Q90 */ +- { 3, 2, 2, 3, 5, 8, 10, 12, 2, 2, 3, 4, 5, 12, 12, 11, +- 3, 3, 3, 5, 8, 11, 14, 11, 3, 3, 4, 6, 10, 17, 16, 12, +- 4, 4, 7, 11, 14, 22, 21, 15, 5, 7, 11, 13, 16, 21, 23, 18, +- 10, 13, 16, 17, 21, 24, 24, 20, 14, 18, 19, 20, 22, 20, 21, 20 }, +- { 3, 4, 5, 9, 20, 20, 20, 20, 4, 4, 5, 13, 20, 20, 20, 20, +- 5, 5, 11, 20, 20, 20, 20, 20, 9, 13, 20, 20, 20, 20, 20, 20, +- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, +- 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20 }, +- +- /* index 5, Q60 */ +- { 13, 9, 8, 13, 19, 32, 41, 49, 10, 10, 11, 15, 21, 46, 48, 44, +- 11, 10, 13, 19, 32, 46, 55, 45, 11, 14, 18, 23, 41, 70, 64, 50, +- 14, 18, 30, 45, 54, 87, 82, 62, 19, 28, 44, 51, 65, 83, 90, 74, +- 39, 51, 62, 70, 82, 97, 96, 81, 58, 74, 76, 78, 90, 80, 82, 79 }, +- { 14, 14, 19, 38, 79, 79, 79, 79, 14, 17, 21, 53, 79, 79, 79, 79, +- 19, 21, 45, 79, 79, 79, 79, 79, 38, 53, 79, 79, 79, 79, 79, 79, +- 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, +- 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79, 79 }, +- +- /* index 6, Q25 */ +- { 32, 22, 20, 32, 48, 80,102,122, 24, 24, 28, 38, 52,116,120,110, +- 28, 26, 32, 48, 80,114,138,112, 28, 34, 44, 58,102,174,160,124, +- 36, 44, 74,112,136,218,206,154, 48, 70,110,128,162,208,226,184, +- 98,128,156,174,206,242,240,202,144,184,190,196,224,200,206,198 }, +- { 34, 36, 48, 94,198,198,198,198, 36, 42, 52,132,198,198,198,198, +- 48, 52,112,198,198,198,198,198, 94,132,198,198,198,198,198,198, +- 198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198, +- 198,198,198,198,198,198,198,198,198,198,198,198,198,198,198,198 }, +- +- /* index 7, Q95 */ +- { 2, 1, 1, 2, 2, 4, 5, 6, 1, 1, 1, 2, 3, 6, 6, 6, +- 1, 1, 2, 2, 4, 6, 7, 6, 1, 2, 2, 3, 5, 9, 8, 6, +- 2, 2, 4, 6, 7, 11, 10, 8, 2, 4, 6, 6, 8, 10, 11, 9, +- 5, 6, 8, 9, 10, 12, 12, 10, 7, 9, 10, 10, 11, 10, 10, 10 }, +- { 2, 2, 2, 5, 10, 10, 10, 10, 2, 2, 3, 7, 10, 10, 10, 10, +- 2, 3, 6, 10, 10, 10, 10, 10, 5, 7, 10, 10, 10, 10, 10, 10, +- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, +- 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 }, +- +- /* index 8, Q93 */ +- { 2, 2, 1, 2, 3, 6, 7, 9, 2, 2, 2, 3, 4, 8, 8, 8, +- 2, 2, 2, 3, 6, 8, 10, 8, 2, 2, 3, 4, 7, 12, 11, 9, +- 3, 3, 5, 8, 10, 15, 14, 11, 3, 5, 8, 9, 11, 15, 16, 13, +- 7, 9, 11, 12, 14, 17, 17, 14, 10, 13, 13, 14, 16, 14, 14, 14 }, +- { 2, 3, 3, 7, 14, 14, 14, 14, 3, 3, 4, 9, 14, 14, 14, 14, +- 3, 4, 8, 14, 14, 14, 14, 14, 7, 9, 14, 14, 14, 14, 14, 14, +- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, +- 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14 } +-}; +-#endif +- + #endif /* AVCODEC_SP5X_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sparc/dsputil_vis.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sparc/dsputil_vis.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sparc/dsputil_vis.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sparc/dsputil_vis.c 2012-05-14 14:08:54.245338190 +0200 +@@ -19,7 +19,7 @@ + */ + + /* The *no_round* functions have been added by James A. Morrison, 2003,2004. +- The vis code from libmpeg2 was adapted for ffmpeg by James A. Morrison. ++ The vis code from libmpeg2 was adapted for libavcodec by James A. Morrison. + */ + + #include "config.h" +@@ -3953,15 +3953,18 @@ + { + /* VIS-specific optimizations */ + int accel = vis_level (); ++ const int high_bit_depth = avctx->bits_per_raw_sample > 8; + + if (accel & ACCEL_SPARC_VIS) { +- if(avctx->idct_algo==FF_IDCT_SIMPLEVIS){ ++ if (avctx->bits_per_raw_sample <= 8 && ++ avctx->idct_algo == FF_IDCT_SIMPLEVIS) { + c->idct_put = ff_simple_idct_put_vis; + c->idct_add = ff_simple_idct_add_vis; + c->idct = ff_simple_idct_vis; + c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; + } + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = MC_put_o_16_vis; + c->put_pixels_tab[0][1] = MC_put_x_16_vis; + c->put_pixels_tab[0][2] = MC_put_y_16_vis; +@@ -4001,5 +4004,6 @@ + c->avg_no_rnd_pixels_tab[1][1] = MC_avg_no_round_x_8_vis; + c->avg_no_rnd_pixels_tab[1][2] = MC_avg_no_round_y_8_vis; + c->avg_no_rnd_pixels_tab[1][3] = MC_avg_no_round_xy_8_vis; ++ } + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sparc/dsputil_vis.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sparc/dsputil_vis.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sparc/dsputil_vis.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sparc/dsputil_vis.h 2012-05-14 14:08:54.246338210 +0200 +@@ -26,4 +26,4 @@ + void ff_simple_idct_add_vis(uint8_t *dest, int line_size, DCTELEM *data); + void ff_simple_idct_vis(DCTELEM *data); + +-#endif ++#endif /* AVCODEC_SPARC_DSPUTIL_VIS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/srtdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/srtdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/srtdec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/srtdec.c 2012-05-14 14:08:54.247338230 +0200 +@@ -20,7 +20,7 @@ + */ + + #include "libavutil/avstring.h" +-#include "libavcore/parseutils.h" ++#include "libavutil/parseutils.h" + #include "avcodec.h" + #include "ass.h" + +@@ -94,7 +94,7 @@ + break; + case '<': + tag_close = in[1] == '/'; +- if (sscanf(in+tag_close+1, "%128[^>]>%n%c", buffer, &len,&c) >= 2) { ++ if (sscanf(in+tag_close+1, "%127[^>]>%n%c", buffer, &len,&c) >= 2) { + if ((param = strchr(buffer, ' '))) + *param++ = 0; + if ((!tag_close && sptr < FF_ARRAY_ELEMS(stack)) || +@@ -110,7 +110,7 @@ + for (j=sptr-2; j>=0; j--) + if (stack[j].param[i][0]) { + out += snprintf(out, out_end-out, +- stack[j].param[i]); ++ "%s", stack[j].param[i]); + break; + } + } else { +@@ -146,7 +146,7 @@ + for (i=0; isize <= 0) + return avpkt->size; + +- ff_ass_init(sub); +- + while (ptr < end && *ptr) { + ptr = read_ts(ptr, &ts_start, &ts_end, &x1, &y1, &x2, &y2); + if (!ptr) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/srtenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/srtenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/srtenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/srtenc.c 2012-05-14 14:08:54.248338251 +0200 +@@ -0,0 +1,301 @@ ++/* ++ * SubRip subtitle encoder ++ * Copyright (c) 2010 Aurelien Jacobs ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "avcodec.h" ++#include "libavutil/avstring.h" ++#include "ass_split.h" ++#include "ass.h" ++ ++ ++#define SRT_STACK_SIZE 64 ++ ++typedef struct { ++ AVCodecContext *avctx; ++ ASSSplitContext *ass_ctx; ++ char buffer[2048]; ++ char *ptr; ++ char *end; ++ char *dialog_start; ++ int count; ++ char stack[SRT_STACK_SIZE]; ++ int stack_ptr; ++ int alignment_applied; ++} SRTContext; ++ ++ ++#ifdef __GNUC__ ++__attribute__ ((__format__ (__printf__, 2, 3))) ++#endif ++static void srt_print(SRTContext *s, const char *str, ...) ++{ ++ va_list vargs; ++ va_start(vargs, str); ++ s->ptr += vsnprintf(s->ptr, s->end - s->ptr, str, vargs); ++ va_end(vargs); ++} ++ ++static int srt_stack_push(SRTContext *s, const char c) ++{ ++ if (s->stack_ptr >= SRT_STACK_SIZE) ++ return -1; ++ s->stack[s->stack_ptr++] = c; ++ return 0; ++} ++ ++static char srt_stack_pop(SRTContext *s) ++{ ++ if (s->stack_ptr <= 0) ++ return 0; ++ return s->stack[--s->stack_ptr]; ++} ++ ++static int srt_stack_find(SRTContext *s, const char c) ++{ ++ int i; ++ for (i = s->stack_ptr-1; i >= 0; i--) ++ if (s->stack[i] == c) ++ break; ++ return i; ++} ++ ++static void srt_close_tag(SRTContext *s, char tag) ++{ ++ srt_print(s, "", tag, tag == 'f' ? "ont" : ""); ++} ++ ++static void srt_stack_push_pop(SRTContext *s, const char c, int close) ++{ ++ if (close) { ++ int i = c ? srt_stack_find(s, c) : 0; ++ if (i < 0) ++ return; ++ while (s->stack_ptr != i) ++ srt_close_tag(s, srt_stack_pop(s)); ++ } else if (srt_stack_push(s, c) < 0) ++ av_log(s->avctx, AV_LOG_ERROR, "tag stack overflow\n"); ++} ++ ++static void srt_style_apply(SRTContext *s, const char *style) ++{ ++ ASSStyle *st = ass_style_get(s->ass_ctx, style); ++ if (st) { ++ int c = st->primary_color & 0xFFFFFF; ++ if (st->font_name && strcmp(st->font_name, ASS_DEFAULT_FONT) || ++ st->font_size != ASS_DEFAULT_FONT_SIZE || ++ c != ASS_DEFAULT_COLOR) { ++ srt_print(s, "font_name && strcmp(st->font_name, ASS_DEFAULT_FONT)) ++ srt_print(s, " face=\"%s\"", st->font_name); ++ if (st->font_size != ASS_DEFAULT_FONT_SIZE) ++ srt_print(s, " size=\"%d\"", st->font_size); ++ if (c != ASS_DEFAULT_COLOR) ++ srt_print(s, " color=\"#%06x\"", ++ (c & 0xFF0000) >> 16 | c & 0xFF00 | (c & 0xFF) << 16); ++ srt_print(s, ">"); ++ srt_stack_push(s, 'f'); ++ } ++ if (st->bold != ASS_DEFAULT_BOLD) { ++ srt_print(s, ""); ++ srt_stack_push(s, 'b'); ++ } ++ if (st->italic != ASS_DEFAULT_ITALIC) { ++ srt_print(s, ""); ++ srt_stack_push(s, 'i'); ++ } ++ if (st->underline != ASS_DEFAULT_UNDERLINE) { ++ srt_print(s, ""); ++ srt_stack_push(s, 'u'); ++ } ++ if (st->alignment != ASS_DEFAULT_ALIGNMENT) { ++ srt_print(s, "{\\an%d}", st->alignment); ++ s->alignment_applied = 1; ++ } ++ } ++} ++ ++ ++static av_cold int srt_encode_init(AVCodecContext *avctx) ++{ ++ SRTContext *s = avctx->priv_data; ++ s->avctx = avctx; ++ s->ass_ctx = ff_ass_split(avctx->subtitle_header); ++ return s->ass_ctx ? 0 : AVERROR_INVALIDDATA; ++} ++ ++static void srt_text_cb(void *priv, const char *text, int len) ++{ ++ SRTContext *s = priv; ++ av_strlcpy(s->ptr, text, FFMIN(s->end-s->ptr, len+1)); ++ s->ptr += len; ++} ++ ++static void srt_new_line_cb(void *priv, int forced) ++{ ++ srt_print(priv, "\r\n"); ++} ++ ++static void srt_style_cb(void *priv, char style, int close) ++{ ++ srt_stack_push_pop(priv, style, close); ++ if (!close) ++ srt_print(priv, "<%c>", style); ++} ++ ++static void srt_color_cb(void *priv, unsigned int color, unsigned int color_id) ++{ ++ if (color_id > 1) ++ return; ++ srt_stack_push_pop(priv, 'f', color == 0xFFFFFFFF); ++ if (color != 0xFFFFFFFF) ++ srt_print(priv, "", ++ (color & 0xFF0000) >> 16 | color & 0xFF00 | (color & 0xFF) << 16); ++} ++ ++static void srt_font_name_cb(void *priv, const char *name) ++{ ++ srt_stack_push_pop(priv, 'f', !name); ++ if (name) ++ srt_print(priv, "", name); ++} ++ ++static void srt_font_size_cb(void *priv, int size) ++{ ++ srt_stack_push_pop(priv, 'f', size < 0); ++ if (size >= 0) ++ srt_print(priv, "", size); ++} ++ ++static void srt_alignment_cb(void *priv, int alignment) ++{ ++ SRTContext *s = priv; ++ if (!s->alignment_applied && alignment >= 0) { ++ srt_print(s, "{\\an%d}", alignment); ++ s->alignment_applied = 1; ++ } ++} ++ ++static void srt_cancel_overrides_cb(void *priv, const char *style) ++{ ++ srt_stack_push_pop(priv, 0, 1); ++ srt_style_apply(priv, style); ++} ++ ++static void srt_move_cb(void *priv, int x1, int y1, int x2, int y2, ++ int t1, int t2) ++{ ++ SRTContext *s = priv; ++ char buffer[32]; ++ int len = snprintf(buffer, sizeof(buffer), ++ " X1:%03u X2:%03u Y1:%03u Y2:%03u", x1, x2, y1, y2); ++ if (s->end - s->ptr > len) { ++ memmove(s->dialog_start+len, s->dialog_start, s->ptr-s->dialog_start+1); ++ memcpy(s->dialog_start, buffer, len); ++ s->ptr += len; ++ } ++} ++ ++static void srt_end_cb(void *priv) ++{ ++ srt_stack_push_pop(priv, 0, 1); ++ srt_print(priv, "\r\n\r\n"); ++} ++ ++static const ASSCodesCallbacks srt_callbacks = { ++ .text = srt_text_cb, ++ .new_line = srt_new_line_cb, ++ .style = srt_style_cb, ++ .color = srt_color_cb, ++ .font_name = srt_font_name_cb, ++ .font_size = srt_font_size_cb, ++ .alignment = srt_alignment_cb, ++ .cancel_overrides = srt_cancel_overrides_cb, ++ .move = srt_move_cb, ++ .end = srt_end_cb, ++}; ++ ++static int srt_encode_frame(AVCodecContext *avctx, ++ unsigned char *buf, int bufsize, void *data) ++{ ++ SRTContext *s = avctx->priv_data; ++ AVSubtitle *sub = data; ++ ASSDialog *dialog; ++ int i, len, num; ++ ++ s->ptr = s->buffer; ++ s->end = s->ptr + sizeof(s->buffer); ++ ++ for (i=0; inum_rects; i++) { ++ ++ if (sub->rects[i]->type != SUBTITLE_ASS) { ++ av_log(avctx, AV_LOG_ERROR, "Only SUBTITLE_ASS type supported.\n"); ++ return AVERROR(ENOSYS); ++ } ++ ++ dialog = ff_ass_split_dialog(s->ass_ctx, sub->rects[i]->ass, 0, &num); ++ for (; dialog && num--; dialog++) { ++ int sh, sm, ss, sc = 10 * dialog->start; ++ int eh, em, es, ec = 10 * dialog->end; ++ sh = sc/3600000; sc -= 3600000*sh; ++ sm = sc/ 60000; sc -= 60000*sm; ++ ss = sc/ 1000; sc -= 1000*ss; ++ eh = ec/3600000; ec -= 3600000*eh; ++ em = ec/ 60000; ec -= 60000*em; ++ es = ec/ 1000; ec -= 1000*es; ++ srt_print(s,"%d\r\n%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\r\n", ++ ++s->count, sh, sm, ss, sc, eh, em, es, ec); ++ s->alignment_applied = 0; ++ s->dialog_start = s->ptr - 2; ++ srt_style_apply(s, dialog->style); ++ ff_ass_split_override_codes(&srt_callbacks, s, dialog->text); ++ } ++ } ++ ++ if (s->ptr == s->buffer) ++ return 0; ++ ++ len = av_strlcpy(buf, s->buffer, bufsize); ++ ++ if (len > bufsize-1) { ++ av_log(avctx, AV_LOG_ERROR, "Buffer too small for ASS event.\n"); ++ return -1; ++ } ++ ++ return len; ++} ++ ++static int srt_encode_close(AVCodecContext *avctx) ++{ ++ SRTContext *s = avctx->priv_data; ++ ff_ass_split_free(s->ass_ctx); ++ return 0; ++} ++ ++AVCodec ff_srt_encoder = { ++ .name = "srt", ++ .long_name = NULL_IF_CONFIG_SMALL("SubRip subtitle"), ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_SRT, ++ .priv_data_size = sizeof(SRTContext), ++ .init = srt_encode_init, ++ .encode = srt_encode_frame, ++ .close = srt_encode_close, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sunrast.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sunrast.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/sunrast.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/sunrast.c 2012-05-14 14:08:54.249338271 +0200 +@@ -20,7 +20,7 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + #define RT_OLD 0 +@@ -46,13 +46,17 @@ + static int sunrast_decode_frame(AVCodecContext *avctx, void *data, + int *data_size, AVPacket *avpkt) { + const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + SUNRASTContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; + unsigned int w, h, depth, type, maptype, maplength, stride, x, y, len, alen; +- uint8_t *ptr; ++ uint8_t *ptr, *ptr2 = NULL; + const uint8_t *bufstart = buf; + ++ if (avpkt->size < 32) ++ return AVERROR_INVALIDDATA; ++ + if (AV_RB32(buf) != 0x59a66a95) { + av_log(avctx, AV_LOG_ERROR, "this is not sunras encoded data\n"); + return -1; +@@ -64,32 +68,42 @@ + type = AV_RB32(buf+20); + maptype = AV_RB32(buf+24); + maplength = AV_RB32(buf+28); ++ buf += 32; + +- if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) { +- av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); +- return -1; +- } + if (type > RT_FORMAT_IFF) { + av_log(avctx, AV_LOG_ERROR, "invalid (compression) type\n"); + return -1; + } ++ if (av_image_check_size(w, h, 0, avctx)) { ++ av_log(avctx, AV_LOG_ERROR, "invalid image size\n"); ++ return -1; ++ } + if (maptype & ~1) { + av_log(avctx, AV_LOG_ERROR, "invalid colormap type\n"); + return -1; + } + +- buf += 32; ++ if (type == RT_FORMAT_TIFF || type == RT_FORMAT_IFF) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported (compression) type\n"); ++ return -1; ++ } + + switch (depth) { + case 1: +- avctx->pix_fmt = PIX_FMT_MONOWHITE; ++ avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_MONOWHITE; ++ break; ++ case 4: ++ avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_NONE; + break; + case 8: +- avctx->pix_fmt = PIX_FMT_PAL8; ++ avctx->pix_fmt = maplength ? PIX_FMT_PAL8 : PIX_FMT_GRAY8; + break; + case 24: + avctx->pix_fmt = (type == RT_FORMAT_RGB) ? PIX_FMT_RGB24 : PIX_FMT_BGR24; + break; ++ case 32: ++ avctx->pix_fmt = (type == RT_FORMAT_RGB) ? PIX_FMT_RGB0 : PIX_FMT_BGR0; ++ break; + default: + av_log(avctx, AV_LOG_ERROR, "invalid depth\n"); + return -1; +@@ -98,8 +112,6 @@ + if (p->data[0]) + avctx->release_buffer(avctx, p); + +- if (av_image_check_size(w, h, 0, avctx)) +- return -1; + if (w != avctx->width || h != avctx->height) + avcodec_set_dimensions(avctx, w, h); + if (avctx->get_buffer(avctx, p) < 0) { +@@ -107,12 +119,15 @@ + return -1; + } + +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; ++ ++ if (buf_end - buf < maplength) ++ return AVERROR_INVALIDDATA; + +- if (depth != 8 && maplength) { ++ if (depth > 8 && maplength) { + av_log(avctx, AV_LOG_WARNING, "useless colormap found or file is corrupted, trying to recover\n"); + +- } else if (depth == 8) { ++ } else if (maplength) { + unsigned int len = maplength / 3; + + if (!maplength) { +@@ -126,13 +141,20 @@ + + ptr = p->data[1]; + for (x=0; x> 3) * depth; ++ } else { + ptr = p->data[0]; + stride = p->linesize[0]; ++ } + + /* scanlines are aligned on 16 bit boundaries */ + len = (depth * w + 7) >> 3; +@@ -143,8 +165,11 @@ + uint8_t *end = ptr + h*stride; + + x = 0; +- while (ptr != end) { ++ while (ptr != end && buf < buf_end) { + run = 1; ++ if (buf_end - buf < 1) ++ return AVERROR_INVALIDDATA; ++ + if ((value = *buf++) == 0x80) { + run = *buf++ + 1; + if (run != 1) +@@ -163,11 +188,37 @@ + } + } else { + for (y=0; ypix_fmt == PIX_FMT_PAL8 && depth < 8) { ++ uint8_t *ptr_free = ptr2; ++ ptr = p->data[0]; ++ for (y=0; y> 3) * depth; x++) { ++ if (depth == 1) { ++ ptr[8*x] = ptr2[x] >> 7; ++ ptr[8*x+1] = ptr2[x] >> 6 & 1; ++ ptr[8*x+2] = ptr2[x] >> 5 & 1; ++ ptr[8*x+3] = ptr2[x] >> 4 & 1; ++ ptr[8*x+4] = ptr2[x] >> 3 & 1; ++ ptr[8*x+5] = ptr2[x] >> 2 & 1; ++ ptr[8*x+6] = ptr2[x] >> 1 & 1; ++ ptr[8*x+7] = ptr2[x] & 1; ++ } else { ++ ptr[2*x] = ptr2[x] >> 4; ++ ptr[2*x+1] = ptr2[x] & 0xF; ++ } ++ } ++ ptr += p->linesize[0]; ++ ptr2 += (w + 15 >> 3) * depth; ++ } ++ av_freep(&ptr_free); ++ } + + *picture = s->picture; + *data_size = sizeof(AVFrame); +@@ -185,15 +236,13 @@ + } + + AVCodec ff_sunrast_decoder = { +- "sunrast", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SUNRAST, +- sizeof(SUNRASTContext), +- sunrast_init, +- NULL, +- sunrast_end, +- sunrast_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "sunrast", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SUNRAST, ++ .priv_data_size = sizeof(SUNRASTContext), ++ .init = sunrast_init, ++ .close = sunrast_end, ++ .decode = sunrast_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Sun Rasterfile image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq1dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq1dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq1dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq1dec.c 2012-05-14 14:08:54.251338311 +0200 +@@ -33,7 +33,6 @@ + */ + + +-//#define DEBUG_SVQ1 + #include "avcodec.h" + #include "dsputil.h" + #include "mpegvideo.h" +@@ -142,7 +141,7 @@ + break;\ + /* add child nodes */\ + list[n++] = list[i];\ +- list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\ ++ list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level >> 1) + 1));\ + } + + #define SVQ1_ADD_CODEBOOK()\ +@@ -196,13 +195,14 @@ + + #define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\ + codebook = (const uint32_t *) cbook[level];\ +- bit_cache = get_bits (bitbuf, 4*stages);\ ++ if (stages > 0)\ ++ bit_cache = get_bits (bitbuf, 4*stages);\ + /* calculate codebook entries for this vector */\ + for (j=0; j < stages; j++) {\ + entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\ + }\ + mean -= (stages * 128);\ +- n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); ++ n4 = (mean << 16) + mean; + + static int svq1_decode_block_intra (GetBitContext *bitbuf, uint8_t *pixels, int pitch ) { + uint32_t bit_cache; +@@ -238,9 +238,9 @@ + } + + if ((stages > 0) && (level >= 4)) { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level); +-#endif ++ av_dlog(NULL, ++ "Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n", ++ stages, level); + return -1; /* invalid vector */ + } + +@@ -288,9 +288,9 @@ + if (stages == -1) continue; /* skip vector */ + + if ((stages > 0) && (level >= 4)) { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level); +-#endif ++ av_dlog(NULL, ++ "Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n", ++ stages, level); + return -1; /* invalid vector */ + } + +@@ -318,9 +318,9 @@ + + /* add median of motion vector predictors and clip result */ + if (i == 1) +- mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; ++ mv->y = sign_extend(diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y), 6); + else +- mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; ++ mv->x = sign_extend(diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x), 6); + } + + return 0; +@@ -378,13 +378,6 @@ + if(x + (mv.x >> 1)<0) + mv.x= 0; + +-#if 0 +- int w= (s->width+15)&~15; +- int h= (s->height+15)&~15; +- if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h) +- av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mv.x >> 1), y + (mv.y >> 1)); +-#endif +- + src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; + dst = current; + +@@ -461,12 +454,6 @@ + if(x + (mvx >> 1)<0) + mvx= 0; + +-#if 0 +- int w= (s->width+15)&~15; +- int h= (s->height+15)&~15; +- if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h) +- av_log(s->avctx, AV_LOG_INFO, "%d %d %d %d\n", x, y, x + (mvx >> 1), y + (mvy >> 1)); +-#endif + src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch]; + dst = current; + +@@ -512,9 +499,7 @@ + + if (result != 0) + { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_block %i\n",result); +-#endif ++ av_dlog(s->avctx, "Error in svq1_motion_inter_block %i\n", result); + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); +@@ -525,9 +510,7 @@ + + if (result != 0) + { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_motion_inter_4v_block %i\n",result); +-#endif ++ av_dlog(s->avctx, "Error in svq1_motion_inter_4v_block %i\n", result); + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); +@@ -567,16 +550,15 @@ + + static int svq1_decode_frame_header (GetBitContext *bitbuf,MpegEncContext *s) { + int frame_size_code; +- int temporal_reference; + +- temporal_reference = get_bits (bitbuf, 8); ++ skip_bits(bitbuf, 8); /* temporal_reference */ + + /* frame type */ + s->pict_type= get_bits (bitbuf, 2)+1; + if(s->pict_type==4) + return -1; + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + + /* unknown fields */ + if (s->f_code == 0x50 || s->f_code == 0x60) { +@@ -674,19 +656,17 @@ + + if (result != 0) + { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_frame_header %i\n",result); +-#endif ++ av_dlog(s->avctx, "Error in svq1_decode_frame_header %i\n",result); + return result; + } ++ avcodec_set_dimensions(avctx, s->width, s->height); + + //FIXME this avoids some confusion for "B frames" without 2 references + //this should be removed after libavcodec can handle more flexible picture types & ordering +- if(s->pict_type==FF_B_TYPE && s->last_picture_ptr==NULL) return buf_size; ++ if(s->pict_type==AV_PICTURE_TYPE_B && s->last_picture_ptr==NULL) return buf_size; + +- if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return buf_size; +- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) +- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) ++ if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==AV_PICTURE_TYPE_B) ++ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=AV_PICTURE_TYPE_I) + || avctx->skip_frame >= AVDISCARD_ALL) + return buf_size; + +@@ -711,24 +691,22 @@ + linesize= s->uvlinesize; + } + +- current = s->current_picture.data[i]; ++ current = s->current_picture.f.data[i]; + +- if(s->pict_type==FF_B_TYPE){ +- previous = s->next_picture.data[i]; ++ if(s->pict_type==AV_PICTURE_TYPE_B){ ++ previous = s->next_picture.f.data[i]; + }else{ +- previous = s->last_picture.data[i]; ++ previous = s->last_picture.f.data[i]; + } + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + /* keyframe */ + for (y=0; y < height; y+=16) { + for (x=0; x < width; x+=16) { + result = svq1_decode_block_intra (&s->gb, ¤t[x], linesize); + if (result != 0) + { +-//#ifdef DEBUG_SVQ1 + av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_block %i (keyframe)\n",result); +-//#endif + goto err; + } + } +@@ -744,9 +722,7 @@ + linesize, pmv, x, y); + if (result != 0) + { +-#ifdef DEBUG_SVQ1 +- av_log(s->avctx, AV_LOG_INFO, "Error in svq1_decode_delta_block %i\n",result); +-#endif ++ av_dlog(s->avctx, "Error in svq1_decode_delta_block %i\n",result); + goto err; + } + } +@@ -834,15 +810,14 @@ + + + AVCodec ff_svq1_decoder = { +- "svq1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SVQ1, +- sizeof(MpegEncContext), +- svq1_decode_init, +- NULL, +- svq1_decode_end, +- svq1_decode_frame, +- CODEC_CAP_DR1, ++ .name = "svq1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SVQ1, ++ .priv_data_size = sizeof(MpegEncContext), ++ .init = svq1_decode_init, ++ .close = svq1_decode_end, ++ .decode = svq1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .flush= ff_mpeg_flush, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq1enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq1enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq1enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq1enc.c 2012-05-14 14:08:54.252338331 +0200 +@@ -86,7 +86,7 @@ + /* frame type */ + put_bits(&s->pb, 2, frame_type - 1); + +- if (frame_type == FF_I_TYPE) { ++ if (frame_type == AV_PICTURE_TYPE_I) { + + /* no checksum since frame code is 0x20 */ + +@@ -113,10 +113,6 @@ + #define QUALITY_THRESHOLD 100 + #define THRESHOLD_MULTIPLIER 0.6 + +-#if HAVE_ALTIVEC +-#undef vector +-#endif +- + static int encode_block(SVQ1Context *s, uint8_t *src, uint8_t *ref, uint8_t *decoded, int stride, int level, int threshold, int lambda, int intra){ + int count, y, x, i, j, split, best_mean, best_score, best_count; + int best_vector[6]; +@@ -160,7 +156,7 @@ + } + + best_count=0; +- best_score -= ((block_sum[0]*block_sum[0])>>(level+3)); ++ best_score -= (int)(((unsigned)block_sum[0]*block_sum[0])>>(level+3)); + best_mean= (block_sum[0] + (size>>1)) >> (level+3); + + if(level<4){ +@@ -280,15 +276,15 @@ + block_width = (width + 15) / 16; + block_height = (height + 15) / 16; + +- if(s->picture.pict_type == FF_P_TYPE){ ++ if(s->picture.pict_type == AV_PICTURE_TYPE_P){ + s->m.avctx= s->avctx; + s->m.current_picture_ptr= &s->m.current_picture; + s->m.last_picture_ptr = &s->m.last_picture; +- s->m.last_picture.data[0]= ref_plane; ++ s->m.last_picture.f.data[0] = ref_plane; + s->m.linesize= +- s->m.last_picture.linesize[0]= +- s->m.new_picture.linesize[0]= +- s->m.current_picture.linesize[0]= stride; ++ s->m.last_picture.f.linesize[0] = ++ s->m.new_picture.f.linesize[0] = ++ s->m.current_picture.f.linesize[0] = stride; + s->m.width= width; + s->m.height= height; + s->m.mb_width= block_width; +@@ -318,9 +314,9 @@ + s->m.current_picture.mb_mean= (uint8_t *)s->dummy; + s->m.current_picture.mb_var= (uint16_t*)s->dummy; + s->m.current_picture.mc_mb_var= (uint16_t*)s->dummy; +- s->m.current_picture.mb_type= s->dummy; ++ s->m.current_picture.f.mb_type = s->dummy; + +- s->m.current_picture.motion_val[0]= s->motion_val8[plane] + 2; ++ s->m.current_picture.f.motion_val[0] = s->motion_val8[plane] + 2; + s->m.p_mv_table= s->motion_val16[plane] + s->m.mb_stride + 1; + s->m.dsp= s->dsp; //move + ff_init_me(&s->m); +@@ -328,7 +324,7 @@ + s->m.me.dia_size= s->avctx->dia_size; + s->m.first_slice_line=1; + for (y = 0; y < block_height; y++) { +- s->m.new_picture.data[0]= src - y*16*stride; //ugly ++ s->m.new_picture.f.data[0] = src - y*16*stride; //ugly + s->m.mb_y= y; + + for(i=0; i<16 && i + 16*ym); + ff_update_block_index(&s->m); + +- if(s->picture.pict_type == FF_I_TYPE || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){ ++ if(s->picture.pict_type == AV_PICTURE_TYPE_I || (s->m.mb_type[x + y*s->m.mb_stride]&CANDIDATE_MB_TYPE_INTRA)){ + for(i=0; i<6; i++){ + init_put_bits(&s->reorder_pb[i], reorder_buffer[0][i], 7*32); + } +- if(s->picture.pict_type == FF_P_TYPE){ ++ if(s->picture.pict_type == AV_PICTURE_TYPE_P){ + const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTRA]; + put_bits(&s->reorder_pb[5], vlc[1], vlc[0]); + score[0]= vlc[1]*lambda; +@@ -401,7 +397,7 @@ + + best=0; + +- if(s->picture.pict_type == FF_P_TYPE){ ++ if(s->picture.pict_type == AV_PICTURE_TYPE_P){ + const uint8_t *vlc= ff_svq1_block_type_vlc[SVQ1_BLOCK_INTER]; + int mx, my, pred_x, pred_y, dxy; + int16_t *motion_ptr; +@@ -461,7 +457,7 @@ + s->rd_total += score[best]; + + for(i=5; i>=0; i--){ +- ff_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); ++ avpriv_copy_bits(&s->pb, reorder_buffer[best][i], count[best][i]); + } + if(best==0){ + s->dsp.put_pixels_tab[0][0](decoded, temp, stride, 16); +@@ -528,8 +524,8 @@ + init_put_bits(&s->pb, buf, buf_size); + + *p = *pict; +- p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? FF_P_TYPE : FF_I_TYPE; +- p->key_frame = p->pict_type == FF_I_TYPE; ++ p->pict_type = avctx->gop_size && avctx->frame_number % avctx->gop_size ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; ++ p->key_frame = p->pict_type == AV_PICTURE_TYPE_I; + + svq1_write_header(s, p->pict_type); + for(i=0; i<3; i++){ +@@ -540,7 +536,7 @@ + return -1; + } + +-// align_put_bits(&s->pb); ++// avpriv_align_put_bits(&s->pb); + while(put_bits_count(&s->pb) & 31) + put_bits(&s->pb, 1, 0); + +@@ -567,19 +563,23 @@ + av_freep(&s->motion_val8[i]); + av_freep(&s->motion_val16[i]); + } ++ if(s->current_picture.data[0]) ++ avctx->release_buffer(avctx, &s->current_picture); ++ if(s->last_picture.data[0]) ++ avctx->release_buffer(avctx, &s->last_picture); + + return 0; + } + + + AVCodec ff_svq1_encoder = { +- "svq1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SVQ1, +- sizeof(SVQ1Context), +- svq1_encode_init, +- svq1_encode_frame, +- svq1_encode_end, ++ .name = "svq1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SVQ1, ++ .priv_data_size = sizeof(SVQ1Context), ++ .init = svq1_encode_init, ++ .encode = svq1_encode_frame, ++ .close = svq1_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV410P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 1 / Sorenson Video 1 / SVQ1"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/svq3.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/svq3.c 2012-05-14 14:08:54.255338391 +0200 +@@ -63,6 +63,17 @@ + * svq3 decoder. + */ + ++typedef struct { ++ H264Context h; ++ int halfpel_flag; ++ int thirdpel_flag; ++ int unknown_flag; ++ int next_slice_index; ++ uint32_t watermark_key; ++ uint8_t *buf; ++ int buf_size; ++} SVQ3Context; ++ + #define FULLPEL_MODE 1 + #define HALFPEL_MODE 2 + #define THIRDPEL_MODE 3 +@@ -164,7 +175,6 @@ + { + const int qmul = svq3_dequant_coeff[qp]; + int i; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + if (dc) { + dc = 13*13*((dc == 1) ? 1538*block[0] : ((qmul*(block[0] >> 3)) / 2)); +@@ -190,10 +200,10 @@ + const int z3 = 17* block[i + 4*1] + 7*block[i + 4*3]; + const int rr = (dc + 0x80000); + +- dst[i + stride*0] = cm[ dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ]; +- dst[i + stride*1] = cm[ dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ]; +- dst[i + stride*2] = cm[ dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ]; +- dst[i + stride*3] = cm[ dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ]; ++ dst[i + stride*0] = av_clip_uint8( dst[i + stride*0] + (((z0 + z3)*qmul + rr) >> 20) ); ++ dst[i + stride*1] = av_clip_uint8( dst[i + stride*1] + (((z1 + z2)*qmul + rr) >> 20) ); ++ dst[i + stride*2] = av_clip_uint8( dst[i + stride*2] + (((z1 - z2)*qmul + rr) >> 20) ); ++ dst[i + stride*3] = av_clip_uint8( dst[i + stride*3] + (((z0 - z3)*qmul + rr) >> 20) ); + } + } + +@@ -210,7 +220,7 @@ + for (limit = (16 >> intra); index < 16; index = limit, limit += 8) { + for (; (vlc = svq3_get_ue_golomb(gb)) != 0; index++) { + +- if (vlc == INVALID_VLC) ++ if (vlc < 0) + return -1; + + sign = (vlc & 0x1) - 1; +@@ -228,7 +238,7 @@ + level = ((vlc + 9) >> 2) - run; + } + } else { +- if (vlc < 16) { ++ if (vlc < 16U) { + run = svq3_dct_tables[intra][vlc].run; + level = svq3_dct_tables[intra][vlc].level; + } else if (intra) { +@@ -279,8 +289,8 @@ + } + + /* form component predictions */ +- dest = s->current_picture.data[0] + x + y*s->linesize; +- src = pic->data[0] + mx + my*s->linesize; ++ dest = s->current_picture.f.data[0] + x + y*s->linesize; ++ src = pic->f.data[0] + mx + my*s->linesize; + + if (emu) { + s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->linesize, (width + 1), (height + 1), +@@ -300,8 +310,8 @@ + blocksize++; + + for (i = 1; i < 3; i++) { +- dest = s->current_picture.data[i] + (x >> 1) + (y >> 1)*s->uvlinesize; +- src = pic->data[i] + mx + my*s->uvlinesize; ++ dest = s->current_picture.f.data[i] + (x >> 1) + (y >> 1) * s->uvlinesize; ++ src = pic->f.data[i] + mx + my * s->uvlinesize; + + if (emu) { + s->dsp.emulated_edge_mc(s->edge_emu_buffer, src, s->uvlinesize, (width + 1), (height + 1), +@@ -338,8 +348,8 @@ + if (mode != PREDICT_MODE) { + pred_motion(h, k, (part_width >> 2), dir, 1, &mx, &my); + } else { +- mx = s->next_picture.motion_val[0][b_xy][0]<<1; +- my = s->next_picture.motion_val[0][b_xy][1]<<1; ++ mx = s->next_picture.f.motion_val[0][b_xy][0] << 1; ++ my = s->next_picture.f.motion_val[0][b_xy][1] << 1; + + if (dir == 0) { + mx = ((mx * h->frame_num_offset) / h->prev_frame_num_offset + 1) >> 1; +@@ -416,15 +426,18 @@ + } + + /* write back motion vectors */ +- fill_rectangle(s->current_picture.motion_val[dir][b_xy], part_width>>2, part_height>>2, h->b_stride, pack16to32(mx,my), 4); ++ fill_rectangle(s->current_picture.f.motion_val[dir][b_xy], ++ part_width >> 2, part_height >> 2, h->b_stride, ++ pack16to32(mx, my), 4); + } + } + + return 0; + } + +-static int svq3_decode_mb(H264Context *h, unsigned int mb_type) ++static int svq3_decode_mb(SVQ3Context *svq3, unsigned int mb_type) + { ++ H264Context *h = &svq3->h; + int i, j, k, m, dir, mode; + int cbp = 0; + uint32_t vlc; +@@ -438,16 +451,16 @@ + h->topright_samples_available = 0xFFFF; + + if (mb_type == 0) { /* SKIP */ +- if (s->pict_type == FF_P_TYPE || s->next_picture.mb_type[mb_xy] == -1) { ++ if (s->pict_type == AV_PICTURE_TYPE_P || s->next_picture.f.mb_type[mb_xy] == -1) { + svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 0, 0); + +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + svq3_mc_dir_part(s, 16*s->mb_x, 16*s->mb_y, 16, 16, 0, 0, 0, 0, 1, 1); + } + + mb_type = MB_TYPE_SKIP; + } else { +- mb_type = FFMIN(s->next_picture.mb_type[mb_xy], 6); ++ mb_type = FFMIN(s->next_picture.f.mb_type[mb_xy], 6); + if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 0, 0) < 0) + return -1; + if (svq3_mc_dir(h, mb_type, PREDICT_MODE, 1, 1) < 0) +@@ -456,9 +469,9 @@ + mb_type = MB_TYPE_16x16; + } + } else if (mb_type < 8) { /* INTER */ +- if (h->thirdpel_flag && h->halfpel_flag == !get_bits1 (&s->gb)) { ++ if (svq3->thirdpel_flag && svq3->halfpel_flag == !get_bits1 (&s->gb)) { + mode = THIRDPEL_MODE; +- } else if (h->halfpel_flag && h->thirdpel_flag == !get_bits1 (&s->gb)) { ++ } else if (svq3->halfpel_flag && svq3->thirdpel_flag == !get_bits1 (&s->gb)) { + mode = HALFPEL_MODE; + } else { + mode = FULLPEL_MODE; +@@ -476,7 +489,7 @@ + for (m = 0; m < 2; m++) { + if (s->mb_x > 0 && h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - 1]+6] != -1) { + for (i = 0; i < 4; i++) { +- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - 1 + i*h->b_stride]; ++ *(uint32_t *) h->mv_cache[m][scan8[0] - 1 + i*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - 1 + i*h->b_stride]; + } + } else { + for (i = 0; i < 4; i++) { +@@ -484,39 +497,39 @@ + } + } + if (s->mb_y > 0) { +- memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t)); ++ memcpy(h->mv_cache[m][scan8[0] - 1*8], s->current_picture.f.motion_val[m][b_xy - h->b_stride], 4*2*sizeof(int16_t)); + memset(&h->ref_cache[m][scan8[0] - 1*8], (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride]] == -1) ? PART_NOT_AVAILABLE : 1, 4); + + if (s->mb_x < (s->mb_width - 1)) { +- *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride + 4]; ++ *(uint32_t *) h->mv_cache[m][scan8[0] + 4 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride + 4]; + h->ref_cache[m][scan8[0] + 4 - 1*8] = + (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride + 1]+6] == -1 || + h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride ] ] == -1) ? PART_NOT_AVAILABLE : 1; + }else + h->ref_cache[m][scan8[0] + 4 - 1*8] = PART_NOT_AVAILABLE; + if (s->mb_x > 0) { +- *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.motion_val[m][b_xy - h->b_stride - 1]; ++ *(uint32_t *) h->mv_cache[m][scan8[0] - 1 - 1*8] = *(uint32_t *) s->current_picture.f.motion_val[m][b_xy - h->b_stride - 1]; + h->ref_cache[m][scan8[0] - 1 - 1*8] = (h->intra4x4_pred_mode[h->mb2br_xy[mb_xy - s->mb_stride - 1]+3] == -1) ? PART_NOT_AVAILABLE : 1; + }else + h->ref_cache[m][scan8[0] - 1 - 1*8] = PART_NOT_AVAILABLE; + }else + memset(&h->ref_cache[m][scan8[0] - 1*8 - 1], PART_NOT_AVAILABLE, 8); + +- if (s->pict_type != FF_B_TYPE) ++ if (s->pict_type != AV_PICTURE_TYPE_B) + break; + } + + /* decode motion vector(s) and form prediction(s) */ +- if (s->pict_type == FF_P_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_P) { + if (svq3_mc_dir(h, (mb_type - 1), mode, 0, 0) < 0) + return -1; +- } else { /* FF_B_TYPE */ ++ } else { /* AV_PICTURE_TYPE_B */ + if (mb_type != 2) { + if (svq3_mc_dir(h, 0, mode, 0, 0) < 0) + return -1; + } else { + for (i = 0; i < 4; i++) { +- memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); ++ memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); + } + } + if (mb_type != 1) { +@@ -524,7 +537,7 @@ + return -1; + } else { + for (i = 0; i < 4; i++) { +- memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); ++ memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); + } + } + } +@@ -557,7 +570,7 @@ + for (i = 0; i < 16; i+=2) { + vlc = svq3_get_ue_golomb(&s->gb); + +- if (vlc >= 25){ ++ if (vlc >= 25U){ + av_log(h->s.avctx, AV_LOG_ERROR, "luma prediction:%d\n", vlc); + return -1; + } +@@ -579,7 +592,7 @@ + } + } + +- ff_h264_write_back_intra_pred_mode(h); ++ write_back_intra_pred_mode(h); + + if (mb_type == 8) { + ff_h264_check_intra4x4_pred_mode(h); +@@ -600,7 +613,7 @@ + dir = i_mb_type_info[mb_type - 8].pred_mode; + dir = (dir >> 1) ^ 3*(dir & 1) ^ 1; + +- if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir)) == -1){ ++ if ((h->intra16x16_pred_mode = ff_h264_check_intra_pred_mode(h, dir, 0)) == -1){ + av_log(h->s.avctx, AV_LOG_ERROR, "check_intra_pred_mode = -1\n"); + return -1; + } +@@ -609,43 +622,44 @@ + mb_type = MB_TYPE_INTRA16x16; + } + +- if (!IS_INTER(mb_type) && s->pict_type != FF_I_TYPE) { ++ if (!IS_INTER(mb_type) && s->pict_type != AV_PICTURE_TYPE_I) { + for (i = 0; i < 4; i++) { +- memset(s->current_picture.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); ++ memset(s->current_picture.f.motion_val[0][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); + } +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + for (i = 0; i < 4; i++) { +- memset(s->current_picture.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); ++ memset(s->current_picture.f.motion_val[1][b_xy + i*h->b_stride], 0, 4*2*sizeof(int16_t)); + } + } + } + if (!IS_INTRA4x4(mb_type)) { + memset(h->intra4x4_pred_mode+h->mb2br_xy[mb_xy], DC_PRED, 8); + } +- if (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE) { +- memset(h->non_zero_count_cache + 8, 0, 4*9*sizeof(uint8_t)); +- s->dsp.clear_blocks(h->mb); ++ if (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B) { ++ memset(h->non_zero_count_cache + 8, 0, 14*8*sizeof(uint8_t)); ++ s->dsp.clear_blocks(h->mb+ 0); ++ s->dsp.clear_blocks(h->mb+384); + } + +- if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == FF_B_TYPE)) { +- if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48){ ++ if (!IS_INTRA16x16(mb_type) && (!IS_SKIP(mb_type) || s->pict_type == AV_PICTURE_TYPE_B)) { ++ if ((vlc = svq3_get_ue_golomb(&s->gb)) >= 48U){ + av_log(h->s.avctx, AV_LOG_ERROR, "cbp_vlc=%d\n", vlc); + return -1; + } + + cbp = IS_INTRA(mb_type) ? golomb_to_intra4x4_cbp[vlc] : golomb_to_inter_cbp[vlc]; + } +- if (IS_INTRA16x16(mb_type) || (s->pict_type != FF_I_TYPE && s->adaptive_quant && cbp)) { ++ if (IS_INTRA16x16(mb_type) || (s->pict_type != AV_PICTURE_TYPE_I && s->adaptive_quant && cbp)) { + s->qscale += svq3_get_se_golomb(&s->gb); + +- if (s->qscale > 31){ ++ if (s->qscale > 31u){ + av_log(h->s.avctx, AV_LOG_ERROR, "qscale:%d\n", s->qscale); + return -1; + } + } + if (IS_INTRA16x16(mb_type)) { +- AV_ZERO128(h->mb_luma_dc+0); +- AV_ZERO128(h->mb_luma_dc+8); ++ AV_ZERO128(h->mb_luma_dc[0]+0); ++ AV_ZERO128(h->mb_luma_dc[0]+8); + if (svq3_decode_block(&s->gb, h->mb_luma_dc, 0, 1)){ + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding intra luma dc\n"); + return -1; +@@ -671,20 +685,23 @@ + } + + if ((cbp & 0x30)) { +- for (i = 0; i < 2; ++i) { +- if (svq3_decode_block(&s->gb, &h->mb[16*(16 + 4*i)], 0, 3)){ ++ for (i = 1; i < 3; ++i) { ++ if (svq3_decode_block(&s->gb, &h->mb[16*16*i], 0, 3)){ + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma dc block\n"); + return -1; + } + } + + if ((cbp & 0x20)) { +- for (i = 0; i < 8; i++) { +- h->non_zero_count_cache[ scan8[16+i] ] = 1; +- +- if (svq3_decode_block(&s->gb, &h->mb[16*(16 + i)], 1, 1)){ +- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n"); +- return -1; ++ for (i = 1; i < 3; i++) { ++ for (j = 0; j < 4; j++) { ++ k = 16*i + j; ++ h->non_zero_count_cache[ scan8[k] ] = 1; ++ ++ if (svq3_decode_block(&s->gb, &h->mb[16*k], 1, 1)){ ++ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding chroma ac block\n"); ++ return -1; ++ } + } + } + } +@@ -692,18 +709,20 @@ + } + + h->cbp= cbp; +- s->current_picture.mb_type[mb_xy] = mb_type; ++ s->current_picture.f.mb_type[mb_xy] = mb_type; + + if (IS_INTRA(mb_type)) { +- h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8); ++ h->chroma_pred_mode = ff_h264_check_intra_pred_mode(h, DC_PRED8x8, 1); + } + + return 0; + } + +-static int svq3_decode_slice_header(H264Context *h) ++static int svq3_decode_slice_header(AVCodecContext *avctx) + { +- MpegEncContext *const s = (MpegEncContext *) h; ++ SVQ3Context *svq3 = avctx->priv_data; ++ H264Context *h = &svq3->h; ++ MpegEncContext *s = &h->s; + const int mb_xy = h->mb_xy; + int i, header; + +@@ -711,24 +730,24 @@ + + if (((header & 0x9F) != 1 && (header & 0x9F) != 2) || (header & 0x60) == 0) { + /* TODO: what? */ +- av_log(h->s.avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header); ++ av_log(avctx, AV_LOG_ERROR, "unsupported slice header (%02X)\n", header); + return -1; + } else { + int length = (header >> 5) & 3; + +- h->next_slice_index = get_bits_count(&s->gb) + 8*show_bits(&s->gb, 8*length) + 8*length; ++ svq3->next_slice_index = get_bits_count(&s->gb) + 8*show_bits(&s->gb, 8*length) + 8*length; + +- if (h->next_slice_index > s->gb.size_in_bits) { +- av_log(h->s.avctx, AV_LOG_ERROR, "slice after bitstream end\n"); ++ if (svq3->next_slice_index > s->gb.size_in_bits) { ++ av_log(avctx, AV_LOG_ERROR, "slice after bitstream end\n"); + return -1; + } + +- s->gb.size_in_bits = h->next_slice_index - 8*(length - 1); ++ s->gb.size_in_bits = svq3->next_slice_index - 8*(length - 1); + skip_bits(&s->gb, 8); + +- if (h->svq3_watermark_key) { ++ if (svq3->watermark_key) { + uint32_t header = AV_RL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1]); +- AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ h->svq3_watermark_key); ++ AV_WL32(&s->gb.buffer[(get_bits_count(&s->gb)>>3)+1], header ^ svq3->watermark_key); + } + if (length > 0) { + memcpy((uint8_t *) &s->gb.buffer[get_bits_count(&s->gb) >> 3], +@@ -737,7 +756,7 @@ + skip_bits_long(&s->gb, 0); + } + +- if ((i = svq3_get_ue_golomb(&s->gb)) == INVALID_VLC || i >= 3){ ++ if ((i = svq3_get_ue_golomb(&s->gb)) >= 3U){ + av_log(h->s.avctx, AV_LOG_ERROR, "illegal slice type %d \n", i); + return -1; + } +@@ -759,7 +778,7 @@ + /* unknown fields */ + skip_bits1(&s->gb); + +- if (h->unknown_svq3_flag) { ++ if (svq3->unknown_flag) { + skip_bits1(&s->gb); + } + +@@ -788,11 +807,14 @@ + + static av_cold int svq3_decode_init(AVCodecContext *avctx) + { +- MpegEncContext *const s = avctx->priv_data; +- H264Context *const h = avctx->priv_data; ++ SVQ3Context *svq3 = avctx->priv_data; ++ H264Context *h = &svq3->h; ++ MpegEncContext *s = &h->s; + int m; + unsigned char *extradata; ++ unsigned char *extradata_end; + unsigned int size; ++ int marker_found = 0; + + if (ff_h264_decode_init(avctx) < 0) + return -1; +@@ -804,35 +826,35 @@ + avctx->pix_fmt = avctx->codec->pix_fmts[0]; + + if (!s->context_initialized) { +- s->width = avctx->width; +- s->height = avctx->height; +- h->halfpel_flag = 1; +- h->thirdpel_flag = 1; +- h->unknown_svq3_flag = 0; +- h->chroma_qp[0] = h->chroma_qp[1] = 4; ++ h->chroma_qp[0] = h->chroma_qp[1] = 4; + +- if (MPV_common_init(s) < 0) +- return -1; ++ svq3->halfpel_flag = 1; ++ svq3->thirdpel_flag = 1; ++ svq3->unknown_flag = 0; + +- h->b_stride = 4*s->mb_width; +- +- ff_h264_alloc_tables(h); + + /* prowl for the "SEQH" marker in the extradata */ + extradata = (unsigned char *)avctx->extradata; +- for (m = 0; m < avctx->extradata_size; m++) { +- if (!memcmp(extradata, "SEQH", 4)) +- break; +- extradata++; ++ extradata_end = avctx->extradata + avctx->extradata_size; ++ if (extradata) { ++ for (m = 0; m + 8 < avctx->extradata_size; m++) { ++ if (!memcmp(extradata, "SEQH", 4)) { ++ marker_found = 1; ++ break; ++ } ++ extradata++; ++ } + } + + /* if a match was found, parse the extra data */ +- if (extradata && !memcmp(extradata, "SEQH", 4)) { ++ if (marker_found) { + + GetBitContext gb; + int frame_size_code; + + size = AV_RB32(&extradata[4]); ++ if (size > extradata_end - extradata - 8) ++ return AVERROR_INVALIDDATA; + init_get_bits(&gb, extradata + 8, size*8); + + /* 'frame size code' and optional 'width, height' */ +@@ -851,8 +873,8 @@ + break; + } + +- h->halfpel_flag = get_bits1(&gb); +- h->thirdpel_flag = get_bits1(&gb); ++ svq3->halfpel_flag = get_bits1(&gb); ++ svq3->thirdpel_flag = get_bits1(&gb); + + /* unknown fields */ + skip_bits1(&gb); +@@ -869,9 +891,9 @@ + skip_bits(&gb, 8); + } + +- h->unknown_svq3_flag = get_bits1(&gb); ++ svq3->unknown_flag = get_bits1(&gb); + avctx->has_b_frames = !s->low_delay; +- if (h->unknown_svq3_flag) { ++ if (svq3->unknown_flag) { + #if CONFIG_ZLIB + unsigned watermark_width = svq3_get_ue_golomb(&gb); + unsigned watermark_height = svq3_get_ue_golomb(&gb); +@@ -894,9 +916,9 @@ + av_free(buf); + return -1; + } +- h->svq3_watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0); +- h->svq3_watermark_key = h->svq3_watermark_key << 16 | h->svq3_watermark_key; +- av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", h->svq3_watermark_key); ++ svq3->watermark_key = ff_svq1_packet_checksum(buf, buf_len, 0); ++ svq3->watermark_key = svq3->watermark_key << 16 | svq3->watermark_key; ++ av_log(avctx, AV_LOG_DEBUG, "watermark key %#x\n", svq3->watermark_key); + av_free(buf); + #else + av_log(avctx, AV_LOG_ERROR, "this svq3 file contains watermark which need zlib support compiled in\n"); +@@ -904,6 +926,19 @@ + #endif + } + } ++ ++ s->width = avctx->width; ++ s->height = avctx->height; ++ ++ if (MPV_common_init(s) < 0) ++ return -1; ++ ++ h->b_stride = 4*s->mb_width; ++ ++ if (ff_h264_alloc_tables(h) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "svq3 memory allocation failed\n"); ++ return AVERROR(ENOMEM); ++ } + } + + return 0; +@@ -913,11 +948,12 @@ + void *data, int *data_size, + AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; ++ SVQ3Context *svq3 = avctx->priv_data; ++ H264Context *h = &svq3->h; ++ MpegEncContext *s = &h->s; + int buf_size = avpkt->size; +- MpegEncContext *const s = avctx->priv_data; +- H264Context *const h = avctx->priv_data; +- int m, mb_type; ++ int m, mb_type, left; ++ uint8_t *buf; + + /* special case for last picture */ + if (buf_size == 0) { +@@ -929,11 +965,22 @@ + return 0; + } + +- init_get_bits (&s->gb, buf, 8*buf_size); +- + s->mb_x = s->mb_y = h->mb_xy = 0; + +- if (svq3_decode_slice_header(h)) ++ if (svq3->watermark_key) { ++ av_fast_malloc(&svq3->buf, &svq3->buf_size, ++ buf_size+FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!svq3->buf) ++ return AVERROR(ENOMEM); ++ memcpy(svq3->buf, avpkt->data, buf_size); ++ buf = svq3->buf; ++ } else { ++ buf = avpkt->data; ++ } ++ ++ init_get_bits(&s->gb, buf, 8*buf_size); ++ ++ if (svq3_decode_slice_header(avctx)) + return -1; + + s->pict_type = h->slice_type; +@@ -941,30 +988,24 @@ + + if (avctx->debug&FF_DEBUG_PICT_INFO){ + av_log(h->s.avctx, AV_LOG_DEBUG, "%c hpel:%d, tpel:%d aqp:%d qp:%d, slice_num:%02X\n", +- av_get_pict_type_char(s->pict_type), h->halfpel_flag, h->thirdpel_flag, ++ av_get_picture_type_char(s->pict_type), svq3->halfpel_flag, svq3->thirdpel_flag, + s->adaptive_quant, s->qscale, h->slice_num); + } + +- /* for hurry_up == 5 */ +- s->current_picture.pict_type = s->pict_type; +- s->current_picture.key_frame = (s->pict_type == FF_I_TYPE); ++ /* for skipping the frame */ ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = (s->pict_type == AV_PICTURE_TYPE_I); + + /* Skip B-frames if we do not have reference frames. */ +- if (s->last_picture_ptr == NULL && s->pict_type == FF_B_TYPE) +- return 0; +- /* Skip B-frames if we are in a hurry. */ +- if (avctx->hurry_up && s->pict_type == FF_B_TYPE) +- return 0; +- /* Skip everything if we are in a hurry >= 5. */ +- if (avctx->hurry_up >= 5) ++ if (s->last_picture_ptr == NULL && s->pict_type == AV_PICTURE_TYPE_B) + return 0; +- if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == FF_B_TYPE) +- ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != FF_I_TYPE) ++ if ( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) ++ ||(avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) + || avctx->skip_frame >= AVDISCARD_ALL) + return 0; + + if (s->next_p_frame_damaged) { +- if (s->pict_type == FF_B_TYPE) ++ if (s->pict_type == AV_PICTURE_TYPE_B) + return 0; + else + s->next_p_frame_damaged = 0; +@@ -973,7 +1014,7 @@ + if (ff_h264_frame_start(h) < 0) + return -1; + +- if (s->pict_type == FF_B_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) { + h->frame_num_offset = (h->slice_num - h->prev_frame_num); + + if (h->frame_num_offset < 0) { +@@ -1011,10 +1052,10 @@ + if ( (get_bits_count(&s->gb) + 7) >= s->gb.size_in_bits && + ((get_bits_count(&s->gb) & 7) == 0 || show_bits(&s->gb, (-get_bits_count(&s->gb) & 7)) == 0)) { + +- skip_bits(&s->gb, h->next_slice_index - get_bits_count(&s->gb)); ++ skip_bits(&s->gb, svq3->next_slice_index - get_bits_count(&s->gb)); + s->gb.size_in_bits = 8*buf_size; + +- if (svq3_decode_slice_header(h)) ++ if (svq3_decode_slice_header(avctx)) + return -1; + + /* TODO: support s->mb_skip_run */ +@@ -1022,12 +1063,12 @@ + + mb_type = svq3_get_ue_golomb(&s->gb); + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + mb_type += 8; +- } else if (s->pict_type == FF_B_TYPE && mb_type >= 4) { ++ } else if (s->pict_type == AV_PICTURE_TYPE_B && mb_type >= 4) { + mb_type += 4; + } +- if (mb_type > 33 || svq3_decode_mb(h, mb_type)) { ++ if ((unsigned)mb_type > 33 || svq3_decode_mb(svq3, mb_type)) { + av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d\n", s->mb_x, s->mb_y); + return -1; + } +@@ -1036,18 +1077,30 @@ + ff_h264_hl_decode_mb (h); + } + +- if (s->pict_type != FF_B_TYPE && !s->low_delay) { +- s->current_picture.mb_type[s->mb_x + s->mb_y*s->mb_stride] = +- (s->pict_type == FF_P_TYPE && mb_type < 8) ? (mb_type - 1) : -1; ++ if (s->pict_type != AV_PICTURE_TYPE_B && !s->low_delay) { ++ s->current_picture.f.mb_type[s->mb_x + s->mb_y * s->mb_stride] = ++ (s->pict_type == AV_PICTURE_TYPE_P && mb_type < 8) ? (mb_type - 1) : -1; + } + } + + ff_draw_horiz_band(s, 16*s->mb_y, 16); + } + ++ left = buf_size*8 - get_bits_count(&s->gb); ++ ++ if (s->mb_y != s->mb_height || s->mb_x != s->mb_width) { ++ av_log(avctx, AV_LOG_INFO, "frame num %d incomplete pic x %d y %d left %d\n", avctx->frame_number, s->mb_y, s->mb_x, left); ++ //av_hex_dump(stderr, buf+buf_size-8, 8); ++ } ++ ++ if (left < 0) { ++ av_log(avctx, AV_LOG_ERROR, "frame num %d left %d\n", avctx->frame_number, left); ++ return -1; ++ } ++ + MPV_frame_end(s); + +- if (s->pict_type == FF_B_TYPE || s->low_delay) { ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { + *(AVFrame *) data = *(AVFrame *) &s->current_picture; + } else { + *(AVFrame *) data = *(AVFrame *) &s->last_picture; +@@ -1061,17 +1114,31 @@ + return buf_size; + } + ++static int svq3_decode_end(AVCodecContext *avctx) ++{ ++ SVQ3Context *svq3 = avctx->priv_data; ++ H264Context *h = &svq3->h; ++ MpegEncContext *s = &h->s; ++ ++ ff_h264_free_context(h); ++ ++ MPV_common_end(s); ++ ++ av_freep(&svq3->buf); ++ svq3->buf_size = 0; ++ ++ return 0; ++} + + AVCodec ff_svq3_decoder = { +- "svq3", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_SVQ3, +- sizeof(H264Context), +- svq3_decode_init, +- NULL, +- ff_h264_decode_end, +- svq3_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .name = "svq3", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_SVQ3, ++ .priv_data_size = sizeof(SVQ3Context), ++ .init = svq3_decode_init, ++ .close = svq3_decode_end, ++ .decode = svq3_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_DELAY, + .long_name = NULL_IF_CONFIG_SMALL("Sorenson Vector Quantizer 3 / Sorenson Video 3 / SVQ3"), + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUVJ420P, PIX_FMT_NONE}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/synth_filter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/synth_filter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/synth_filter.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/synth_filter.c 2012-05-14 14:08:54.256338412 +0200 +@@ -29,7 +29,7 @@ + float *synth_buf= synth_buf_ptr + *synth_buf_offset; + int i, j; + +- ff_imdct_half(imdct, synth_buf, in); ++ imdct->imdct_half(imdct, synth_buf, in); + + for (i = 0; i < 16; i++){ + float a= synth_buf2[i ]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tableprint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tableprint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tableprint.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tableprint.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,41 +0,0 @@ +-/* +- * Generate a file for hardcoded tables +- * +- * Copyright (c) 2009 Reimar Döffinger +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +-#include +-#include "tableprint.h" +- +-WRITE_1D_FUNC(int8_t, "%3"PRIi8, 15) +-WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15) +-WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7) +-WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7) +-WRITE_1D_FUNC(float, "%.18e", 3) +- +-WRITE_2D_FUNC(int8_t) +-WRITE_2D_FUNC(uint8_t) +-WRITE_2D_FUNC(uint32_t) +-WRITE_2D_FUNC(float) +- +-void write_fileheader(void) { +- printf("/* This file was generated by libavcodec/tableprint */\n"); +- printf("#include \n"); +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tableprint.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tableprint.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tableprint.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tableprint.h 2012-05-14 14:08:54.257338432 +0200 +@@ -23,8 +23,9 @@ + #ifndef AVCODEC_TABLEPRINT_H + #define AVCODEC_TABLEPRINT_H + +-#include ++#include + #include ++ + #include "libavutil/common.h" + + #define WRITE_1D_FUNC_ARGV(type, linebrk, fmtstr, ...)\ +@@ -55,9 +56,9 @@ + } + + /** +- * \defgroup printfuncs Predefined functions for printing tables ++ * @name Predefined functions for printing tables + * +- * \{ ++ * @{ + */ + void write_int8_t_array (const int8_t *, int); + void write_uint8_t_array (const uint8_t *, int); +@@ -68,10 +69,7 @@ + void write_uint8_t_2d_array (const void *, int, int); + void write_uint32_t_2d_array(const void *, int, int); + void write_float_2d_array (const void *, int, int); +-/** \} */ // end of printfuncs group +- +-/** Write a standard file header */ +-void write_fileheader(void); ++/** @} */ // end of printfuncs group + + #define WRITE_ARRAY(prefix, type, name) \ + do { \ +@@ -92,4 +90,22 @@ + printf("};\n"); \ + } while(0) + ++ ++WRITE_1D_FUNC(int8_t, "%3"PRIi8, 15) ++WRITE_1D_FUNC(uint8_t, "0x%02"PRIx8, 15) ++WRITE_1D_FUNC(uint16_t, "0x%08"PRIx16, 7) ++WRITE_1D_FUNC(uint32_t, "0x%08"PRIx32, 7) ++WRITE_1D_FUNC(float, "%.18e", 3) ++ ++WRITE_2D_FUNC(int8_t) ++WRITE_2D_FUNC(uint8_t) ++WRITE_2D_FUNC(uint32_t) ++WRITE_2D_FUNC(float) ++ ++static inline void write_fileheader(void) ++{ ++ printf("/* This file was automatically generated. */\n"); ++ printf("#include \n"); ++} ++ + #endif /* AVCODEC_TABLEPRINT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targa.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targa.c 2012-05-14 14:08:54.258338452 +0200 +@@ -20,8 +20,9 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" ++#include "bytestream.h" + #include "targa.h" + + typedef struct TargaContext { +@@ -33,22 +34,35 @@ + int compression_type; + } TargaContext; + +-static void targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, uint8_t *dst, int w, int h, int stride, int bpp) ++#define CHECK_BUFFER_SIZE(buf, buf_end, needed, where) \ ++ if(needed > buf_end - buf){ \ ++ av_log(avctx, AV_LOG_ERROR, "Problem: unexpected end of data while reading " where "\n"); \ ++ return -1; \ ++ } \ ++ ++static int targa_decode_rle(AVCodecContext *avctx, TargaContext *s, const uint8_t *src, int src_size, uint8_t *dst, int w, int h, int stride, int bpp) + { + int i, x, y; + int depth = (bpp + 1) >> 3; + int type, count; + int diff; ++ const uint8_t *src_end = src + src_size; + + diff = stride - w * depth; + x = y = 0; + while(y < h){ ++ CHECK_BUFFER_SIZE(src, src_end, 1, "image type"); + type = *src++; + count = (type & 0x7F) + 1; + type &= 0x80; + if((x + count > w) && (x + count + 1 > (h - y) * w)){ + av_log(avctx, AV_LOG_ERROR, "Packet went out of bounds: position (%i,%i) size %i\n", x, y, count); +- return; ++ return -1; ++ } ++ if(type){ ++ CHECK_BUFFER_SIZE(src, src_end, depth, "image data"); ++ }else{ ++ CHECK_BUFFER_SIZE(src, src_end, count * depth, "image data"); + } + for(i = 0; i < count; i++){ + switch(depth){ +@@ -56,7 +70,7 @@ + *dst = *src; + break; + case 2: +- *((uint16_t*)dst) = AV_RL16(src); ++ AV_WN16A(dst, AV_RN16A(src)); + break; + case 3: + dst[0] = src[0]; +@@ -64,7 +78,7 @@ + dst[2] = src[2]; + break; + case 4: +- *((uint32_t*)dst) = AV_RL32(src); ++ AV_WN32A(dst, AV_RN32A(src)); + break; + } + dst += depth; +@@ -81,6 +95,7 @@ + if(type) + src += depth; + } ++ return src_size; + } + + static int decode_frame(AVCodecContext *avctx, +@@ -88,29 +103,36 @@ + AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + TargaContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p= (AVFrame*)&s->picture; + uint8_t *dst; + int stride; +- int idlen, pal, compr, x, y, w, h, bpp, flags; ++ int idlen, pal, compr, y, w, h, bpp, flags; + int first_clr, colors, csize; + + /* parse image header */ ++ CHECK_BUFFER_SIZE(buf, buf_end, 18, "header"); + idlen = *buf++; + pal = *buf++; + compr = *buf++; +- first_clr = AV_RL16(buf); buf += 2; +- colors = AV_RL16(buf); buf += 2; ++ first_clr = bytestream_get_le16(&buf); ++ colors = bytestream_get_le16(&buf); + csize = *buf++; +- x = AV_RL16(buf); buf += 2; +- y = AV_RL16(buf); buf += 2; +- w = AV_RL16(buf); buf += 2; +- h = AV_RL16(buf); buf += 2; ++ if (!pal && (first_clr || colors || csize)) { ++ av_log(avctx, AV_LOG_WARNING, "File without colormap has colormap information set.\n"); ++ // specification says we should ignore those value in this case ++ first_clr = colors = csize = 0; ++ } ++ buf += 2; /* x */ ++ y = bytestream_get_le16(&buf); ++ w = bytestream_get_le16(&buf); ++ h = bytestream_get_le16(&buf); + bpp = *buf++; + flags = *buf++; + //skip identifier if any ++ CHECK_BUFFER_SIZE(buf, buf_end, idlen, "identifiers"); + buf += idlen; + s->bpp = bpp; + s->width = w; +@@ -120,16 +142,14 @@ + avctx->pix_fmt = ((compr & (~TGA_RLE)) == TGA_BW) ? PIX_FMT_GRAY8 : PIX_FMT_PAL8; + break; + case 15: +- avctx->pix_fmt = PIX_FMT_RGB555; +- break; + case 16: +- avctx->pix_fmt = PIX_FMT_RGB555; ++ avctx->pix_fmt = PIX_FMT_RGB555LE; + break; + case 24: + avctx->pix_fmt = PIX_FMT_BGR24; + break; + case 32: +- avctx->pix_fmt = PIX_FMT_RGB32; ++ avctx->pix_fmt = PIX_FMT_BGRA; + break; + default: + av_log(avctx, AV_LOG_ERROR, "Bit depth %i is not supported\n", s->bpp); +@@ -155,32 +175,46 @@ + stride = -p->linesize[0]; + } + +- if(avctx->pix_fmt == PIX_FMT_PAL8 && avctx->palctrl){ +- memcpy(p->data[1], avctx->palctrl->palette, AVPALETTE_SIZE); +- if(avctx->palctrl->palette_changed){ +- p->palette_has_changed = 1; +- avctx->palctrl->palette_changed = 0; +- } +- } + if(colors){ ++ int pal_size, pal_sample_size; + if((colors + first_clr) > 256){ + av_log(avctx, AV_LOG_ERROR, "Incorrect palette: %i colors with offset %i\n", colors, first_clr); + return -1; + } +- if(csize != 24){ ++ switch (csize) { ++ case 24: pal_sample_size = 3; break; ++ case 16: ++ case 15: pal_sample_size = 2; break; ++ default: + av_log(avctx, AV_LOG_ERROR, "Palette entry size %i bits is not supported\n", csize); + return -1; + } ++ pal_size = colors * pal_sample_size; ++ CHECK_BUFFER_SIZE(buf, buf_end, pal_size, "color table"); + if(avctx->pix_fmt != PIX_FMT_PAL8)//should not occur but skip palette anyway +- buf += colors * ((csize + 1) >> 3); ++ buf += pal_size; + else{ +- int r, g, b, t; +- int32_t *pal = ((int32_t*)p->data[1]) + first_clr; +- for(t = 0; t < colors; t++){ +- r = *buf++; +- g = *buf++; +- b = *buf++; +- *pal++ = (b << 16) | (g << 8) | r; ++ int t; ++ uint32_t *pal = ((uint32_t *)p->data[1]) + first_clr; ++ ++ switch (pal_sample_size) { ++ case 3: ++ /* RGB24 */ ++ for (t = 0; t < colors; t++) ++ *pal++ = (0xffU<<24) | bytestream_get_le24(&buf); ++ break; ++ case 2: ++ /* RGB555 */ ++ for (t = 0; t < colors; t++) { ++ uint32_t v = bytestream_get_le16(&buf); ++ v = ((v & 0x7C00) << 9) | ++ ((v & 0x03E0) << 6) | ++ ((v & 0x001F) << 3); ++ /* left bit replication */ ++ v |= (v & 0xE0E0E0U) >> 5; ++ *pal++ = (0xffU<<24) | v; ++ } ++ break; + } + p->palette_has_changed = 1; + } +@@ -188,25 +222,42 @@ + if((compr & (~TGA_RLE)) == TGA_NODATA) + memset(p->data[0], 0, p->linesize[0] * s->height); + else{ +- if(compr & TGA_RLE) +- targa_decode_rle(avctx, s, buf, dst, avctx->width, avctx->height, stride, bpp); +- else{ ++ if(compr & TGA_RLE){ ++ int res = targa_decode_rle(avctx, s, buf, buf_end - buf, dst, avctx->width, avctx->height, stride, bpp); ++ if (res < 0) ++ return -1; ++ buf += res; ++ }else{ ++ size_t img_size = s->width * ((s->bpp + 1) >> 3); ++ CHECK_BUFFER_SIZE(buf, buf_end, img_size, "image data"); + for(y = 0; y < s->height; y++){ +-#if HAVE_BIGENDIAN +- if((s->bpp + 1) >> 3 == 2){ +- uint16_t *dst16 = (uint16_t*)dst; +- for(x = 0; x < s->width; x++) +- dst16[x] = AV_RL16(buf + x * 2); +- }else if((s->bpp + 1) >> 3 == 4){ +- uint32_t *dst32 = (uint32_t*)dst; +- for(x = 0; x < s->width; x++) +- dst32[x] = AV_RL32(buf + x * 4); +- }else +-#endif +- memcpy(dst, buf, s->width * ((s->bpp + 1) >> 3)); ++ memcpy(dst, buf, img_size); + + dst += stride; +- buf += s->width * ((s->bpp + 1) >> 3); ++ buf += img_size; ++ } ++ } ++ } ++ if(flags & 0x10){ // right-to-left, needs horizontal flip ++ int x; ++ for(y = 0; y < s->height; y++){ ++ void *line = &p->data[0][y * p->linesize[0]]; ++ for(x = 0; x < s->width >> 1; x++){ ++ switch(s->bpp){ ++ case 32: ++ FFSWAP(uint32_t, ((uint32_t *)line)[x], ((uint32_t *)line)[s->width - x - 1]); ++ break; ++ case 24: ++ FFSWAP(uint8_t, ((uint8_t *)line)[3 * x ], ((uint8_t *)line)[3 * s->width - 3 * x - 3]); ++ FFSWAP(uint8_t, ((uint8_t *)line)[3 * x + 1], ((uint8_t *)line)[3 * s->width - 3 * x - 2]); ++ FFSWAP(uint8_t, ((uint8_t *)line)[3 * x + 2], ((uint8_t *)line)[3 * s->width - 3 * x - 1]); ++ break; ++ case 16: ++ FFSWAP(uint16_t, ((uint16_t *)line)[x], ((uint16_t *)line)[s->width - x - 1]); ++ break; ++ case 8: ++ FFSWAP(uint8_t, ((uint8_t *)line)[x], ((uint8_t *)line)[s->width - x - 1]); ++ } + } + } + } +@@ -214,7 +265,7 @@ + *picture= *(AVFrame*)&s->picture; + *data_size = sizeof(AVPicture); + +- return buf_size; ++ return avpkt->size; + } + + static av_cold int targa_init(AVCodecContext *avctx){ +@@ -236,15 +287,13 @@ + } + + AVCodec ff_targa_decoder = { +- "targa", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TARGA, +- sizeof(TargaContext), +- targa_init, +- NULL, +- targa_end, +- decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "targa", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TARGA, ++ .priv_data_size = sizeof(TargaContext), ++ .init = targa_init, ++ .close = targa_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Truevision Targa image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targaenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targaenc.c 2012-05-14 14:08:54.260338492 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/pixdesc.h" + #include "avcodec.h" + #include "rle.h" + #include "targa.h" +@@ -90,7 +91,7 @@ + return AVERROR(EINVAL); + } + +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + /* zero out the header and only set applicable fields */ +@@ -119,7 +120,7 @@ + break; + default: + av_log(avctx, AV_LOG_ERROR, "Pixel format '%s' not supported.\n", +- avcodec_get_pix_fmt_name(avctx->pix_fmt)); ++ av_get_pix_fmt_name(avctx->pix_fmt)); + return AVERROR(EINVAL); + } + bpp = outbuf[16] >> 3; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targa.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targa.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/targa.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/targa.h 2012-05-14 14:08:54.259338472 +0200 +@@ -16,6 +16,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#ifndef AVCODEC_TARGA_H ++#define AVCODEC_TARGA_H ++ + /** + * @file + * targa file common definitions +@@ -34,3 +37,5 @@ + TGA_BW = 3, // black & white or grayscale + TGA_RLE = 8, // flag pointing that data is RLE-coded + }; ++ ++#endif /* AVCODEC_TARGA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/thread.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/thread.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/thread.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/thread.h 2012-05-14 14:08:54.260338492 +0200 +@@ -0,0 +1,116 @@ ++/* ++ * Copyright (c) 2008 Alexander Strange ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Multithreading support functions ++ * @author Alexander Strange ++ */ ++ ++#ifndef AVCODEC_THREAD_H ++#define AVCODEC_THREAD_H ++ ++#include "config.h" ++#include "avcodec.h" ++ ++/** ++ * Wait for decoding threads to finish and reset internal state. ++ * Called by avcodec_flush_buffers(). ++ * ++ * @param avctx The context. ++ */ ++void ff_thread_flush(AVCodecContext *avctx); ++ ++/** ++ * Submit a new frame to a decoding thread. ++ * Returns the next available frame in picture. *got_picture_ptr ++ * will be 0 if none is available. ++ * The return value on success is the size of the consumed packet for ++ * compatiblity with avcodec_decode_video2(). This means the decoder ++ * has to consume the full packet. ++ * ++ * Parameters are the same as avcodec_decode_video2(). ++ */ ++int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, ++ int *got_picture_ptr, AVPacket *avpkt); ++ ++/** ++ * If the codec defines update_thread_context(), call this ++ * when they are ready for the next thread to start decoding ++ * the next frame. After calling it, do not change any variables ++ * read by the update_thread_context() method, or call ff_thread_get_buffer(). ++ * ++ * @param avctx The context. ++ */ ++void ff_thread_finish_setup(AVCodecContext *avctx); ++ ++/** ++ * Notify later decoding threads when part of their reference picture is ready. ++ * Call this when some part of the picture is finished decoding. ++ * Later calls with lower values of progress have no effect. ++ * ++ * @param f The picture being decoded. ++ * @param progress Value, in arbitrary units, of how much of the picture has decoded. ++ * @param field The field being decoded, for field-picture codecs. ++ * 0 for top field or frame pictures, 1 for bottom field. ++ */ ++void ff_thread_report_progress(AVFrame *f, int progress, int field); ++ ++/** ++ * Wait for earlier decoding threads to finish reference pictures. ++ * Call this before accessing some part of a picture, with a given ++ * value for progress, and it will return after the responsible decoding ++ * thread calls ff_thread_report_progress() with the same or ++ * higher value for progress. ++ * ++ * @param f The picture being referenced. ++ * @param progress Value, in arbitrary units, to wait for. ++ * @param field The field being referenced, for field-picture codecs. ++ * 0 for top field or frame pictures, 1 for bottom field. ++ */ ++void ff_thread_await_progress(AVFrame *f, int progress, int field); ++ ++/** ++ * Wrapper around get_buffer() for frame-multithreaded codecs. ++ * Call this function instead of avctx->get_buffer(f). ++ * Cannot be called after the codec has called ff_thread_finish_setup(). ++ * ++ * @param avctx The current context. ++ * @param f The frame to write into. ++ */ ++int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f); ++ ++/** ++ * Wrapper around release_buffer() frame-for multithreaded codecs. ++ * Call this function instead of avctx->release_buffer(f). ++ * The AVFrame will be copied and the actual release_buffer() call ++ * will be performed later. The contents of data pointed to by the ++ * AVFrame should not be changed until ff_thread_get_buffer() is called ++ * on it. ++ * ++ * @param avctx The current context. ++ * @param f The picture being released. ++ */ ++void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f); ++ ++int ff_thread_init(AVCodecContext *s); ++void ff_thread_free(AVCodecContext *s); ++ ++#endif /* AVCODEC_THREAD_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiertexseqv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiertexseqv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiertexseqv.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiertexseqv.c 2012-05-14 14:08:54.262338532 +0200 +@@ -25,7 +25,7 @@ + */ + + #include "avcodec.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + + +@@ -35,15 +35,19 @@ + } SeqVideoContext; + + +-static const unsigned char *seq_unpack_rle_block(const unsigned char *src, unsigned char *dst, int dst_size) ++static const unsigned char *seq_unpack_rle_block(const unsigned char *src, ++ const unsigned char *src_end, ++ unsigned char *dst, int dst_size) + { + int i, len, sz; + GetBitContext gb; + int code_table[64]; + +- /* get the rle codes (at most 64 bytes) */ +- init_get_bits(&gb, src, 64 * 8); ++ /* get the rle codes */ ++ init_get_bits(&gb, src, (src_end - src) * 8); + for (i = 0, sz = 0; i < 64 && sz < dst_size; i++) { ++ if (get_bits_left(&gb) < 4) ++ return NULL; + code_table[i] = get_sbits(&gb, 4); + sz += FFABS(code_table[i]); + } +@@ -54,8 +58,12 @@ + len = code_table[i]; + if (len < 0) { + len = -len; ++ if (src_end - src < 1) ++ return NULL; + memset(dst, *src++, FFMIN(len, dst_size)); + } else { ++ if (src_end - src < len) ++ return NULL; + memcpy(dst, src, FFMIN(len, dst_size)); + src += len; + } +@@ -65,25 +73,30 @@ + return src; + } + +-static const unsigned char *seq_decode_op1(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) ++static const unsigned char *seq_decode_op1(SeqVideoContext *seq, ++ const unsigned char *src, ++ const unsigned char *src_end, ++ unsigned char *dst) + { + const unsigned char *color_table; + int b, i, len, bits; + GetBitContext gb; + unsigned char block[8 * 8]; + ++ if (src_end - src < 1) ++ return NULL; + len = *src++; + if (len & 0x80) { + switch (len & 3) { + case 1: +- src = seq_unpack_rle_block(src, block, sizeof(block)); ++ src = seq_unpack_rle_block(src, src_end, block, sizeof(block)); + for (b = 0; b < 8; b++) { + memcpy(dst, &block[b * 8], 8); + dst += seq->frame.linesize[0]; + } + break; + case 2: +- src = seq_unpack_rle_block(src, block, sizeof(block)); ++ src = seq_unpack_rle_block(src, src_end, block, sizeof(block)); + for (i = 0; i < 8; i++) { + for (b = 0; b < 8; b++) + dst[b * seq->frame.linesize[0]] = block[i * 8 + b]; +@@ -92,9 +105,13 @@ + break; + } + } else { ++ if (len <= 0) ++ return NULL; ++ bits = ff_log2_tab[len - 1] + 1; ++ if (src_end - src < len + 8 * bits) ++ return NULL; + color_table = src; + src += len; +- bits = ff_log2_tab[len - 1] + 1; + init_get_bits(&gb, src, bits * 8 * 8); src += bits * 8; + for (b = 0; b < 8; b++) { + for (i = 0; i < 8; i++) +@@ -106,10 +123,16 @@ + return src; + } + +-static const unsigned char *seq_decode_op2(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) ++static const unsigned char *seq_decode_op2(SeqVideoContext *seq, ++ const unsigned char *src, ++ const unsigned char *src_end, ++ unsigned char *dst) + { + int i; + ++ if (src_end - src < 8 * 8) ++ return NULL; ++ + for (i = 0; i < 8; i++) { + memcpy(dst, src, 8); + src += 8; +@@ -119,11 +142,16 @@ + return src; + } + +-static const unsigned char *seq_decode_op3(SeqVideoContext *seq, const unsigned char *src, unsigned char *dst) ++static const unsigned char *seq_decode_op3(SeqVideoContext *seq, ++ const unsigned char *src, ++ const unsigned char *src_end, ++ unsigned char *dst) + { + int pos, offset; + + do { ++ if (src_end - src < 2) ++ return NULL; + pos = *src++; + offset = ((pos >> 3) & 7) * seq->frame.linesize[0] + (pos & 7); + dst[offset] = *src++; +@@ -132,8 +160,9 @@ + return src; + } + +-static void seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size) ++static int seqvideo_decode(SeqVideoContext *seq, const unsigned char *data, int data_size) + { ++ const unsigned char *data_end = data + data_size; + GetBitContext gb; + int flags, i, j, x, y, op; + unsigned char c[3]; +@@ -144,15 +173,19 @@ + + if (flags & 1) { + palette = (uint32_t *)seq->frame.data[1]; ++ if (data_end - data < 256 * 3) ++ return AVERROR_INVALIDDATA; + for (i = 0; i < 256; i++) { + for (j = 0; j < 3; j++, data++) + c[j] = (*data << 2) | (*data >> 4); +- palette[i] = AV_RB24(c); ++ palette[i] = 0xFF << 24 | AV_RB24(c); + } + seq->frame.palette_has_changed = 1; + } + + if (flags & 2) { ++ if (data_end - data < 128) ++ return AVERROR_INVALIDDATA; + init_get_bits(&gb, data, 128 * 8); data += 128; + for (y = 0; y < 128; y += 8) + for (x = 0; x < 256; x += 8) { +@@ -160,17 +193,20 @@ + op = get_bits(&gb, 2); + switch (op) { + case 1: +- data = seq_decode_op1(seq, data, dst); ++ data = seq_decode_op1(seq, data, data_end, dst); + break; + case 2: +- data = seq_decode_op2(seq, data, dst); ++ data = seq_decode_op2(seq, data, data_end, dst); + break; + case 3: +- data = seq_decode_op3(seq, data, dst); ++ data = seq_decode_op3(seq, data, data_end, dst); + break; + } ++ if (!data) ++ return AVERROR_INVALIDDATA; + } + } ++ return 0; + } + + static av_cold int seqvideo_decode_init(AVCodecContext *avctx) +@@ -180,6 +216,7 @@ + seq->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&seq->frame); + seq->frame.data[0] = NULL; + + return 0; +@@ -194,14 +231,15 @@ + + SeqVideoContext *seq = avctx->priv_data; + +- seq->frame.reference = 1; ++ seq->frame.reference = 3; + seq->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &seq->frame)) { + av_log(seq->avctx, AV_LOG_ERROR, "tiertexseqvideo: reget_buffer() failed\n"); + return -1; + } + +- seqvideo_decode(seq, buf, buf_size); ++ if (seqvideo_decode(seq, buf, buf_size)) ++ return AVERROR_INVALIDDATA; + + *data_size = sizeof(AVFrame); + *(AVFrame *)data = seq->frame; +@@ -220,14 +258,13 @@ + } + + AVCodec ff_tiertexseqvideo_decoder = { +- "tiertexseqvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TIERTEXSEQVIDEO, +- sizeof(SeqVideoContext), +- seqvideo_decode_init, +- NULL, +- seqvideo_decode_end, +- seqvideo_decode_frame, +- CODEC_CAP_DR1, ++ .name = "tiertexseqvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TIERTEXSEQVIDEO, ++ .priv_data_size = sizeof(SeqVideoContext), ++ .init = seqvideo_decode_init, ++ .close = seqvideo_decode_end, ++ .decode = seqvideo_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiff.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiff.c 2012-05-14 14:08:54.264338573 +0200 +@@ -1,5 +1,4 @@ + /* +- * TIFF image decoder + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. +@@ -20,10 +19,11 @@ + */ + + /** +- * TIFF image decoder + * @file ++ * TIFF image decoder + * @author Konstantin Shishkov + */ ++ + #include "avcodec.h" + #if CONFIG_ZLIB + #include +@@ -33,16 +33,18 @@ + #include "faxcompr.h" + #include "libavutil/common.h" + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + typedef struct TiffContext { + AVCodecContext *avctx; + AVFrame picture; + + int width, height; +- unsigned int bpp; ++ unsigned int bpp, bppcount; ++ uint32_t palette[256]; ++ int palette_is_set; + int le; +- int compr; ++ enum TiffCompr compr; + int invert; + int fax_opts; + int predictor; +@@ -56,24 +58,24 @@ + LZWState *lzw; + } TiffContext; + +-static int tget_short(const uint8_t **p, int le){ +- int v = le ? AV_RL16(*p) : AV_RB16(*p); ++static unsigned tget_short(const uint8_t **p, int le) { ++ unsigned v = le ? AV_RL16(*p) : AV_RB16(*p); + *p += 2; + return v; + } + +-static int tget_long(const uint8_t **p, int le){ +- int v = le ? AV_RL32(*p) : AV_RB32(*p); ++static unsigned tget_long(const uint8_t **p, int le) { ++ unsigned v = le ? AV_RL32(*p) : AV_RB32(*p); + *p += 4; + return v; + } + +-static int tget(const uint8_t **p, int type, int le){ ++static unsigned tget(const uint8_t **p, int type, int le) { + switch(type){ + case TIFF_BYTE : return *(*p)++; + case TIFF_SHORT: return tget_short(p, le); + case TIFF_LONG : return tget_long (p, le); +- default : return -1; ++ default : return UINT_MAX; + } + } + +@@ -100,10 +102,50 @@ + } + #endif + ++static void av_always_inline horizontal_fill(unsigned int bpp, uint8_t* dst, ++ int usePtr, const uint8_t *src, ++ uint8_t c, int width, int offset) ++{ ++ switch (bpp) { ++ case 1: ++ while (--width >= 0) { ++ dst[(width+offset)*8+7] = (usePtr ? src[width] : c) & 0x1; ++ dst[(width+offset)*8+6] = (usePtr ? src[width] : c) >> 1 & 0x1; ++ dst[(width+offset)*8+5] = (usePtr ? src[width] : c) >> 2 & 0x1; ++ dst[(width+offset)*8+4] = (usePtr ? src[width] : c) >> 3 & 0x1; ++ dst[(width+offset)*8+3] = (usePtr ? src[width] : c) >> 4 & 0x1; ++ dst[(width+offset)*8+2] = (usePtr ? src[width] : c) >> 5 & 0x1; ++ dst[(width+offset)*8+1] = (usePtr ? src[width] : c) >> 6 & 0x1; ++ dst[(width+offset)*8+0] = (usePtr ? src[width] : c) >> 7; ++ } ++ break; ++ case 2: ++ while (--width >= 0) { ++ dst[(width+offset)*4+3] = (usePtr ? src[width] : c) & 0x3; ++ dst[(width+offset)*4+2] = (usePtr ? src[width] : c) >> 2 & 0x3; ++ dst[(width+offset)*4+1] = (usePtr ? src[width] : c) >> 4 & 0x3; ++ dst[(width+offset)*4+0] = (usePtr ? src[width] : c) >> 6; ++ } ++ break; ++ case 4: ++ while (--width >= 0) { ++ dst[(width+offset)*2+1] = (usePtr ? src[width] : c) & 0xF; ++ dst[(width+offset)*2+0] = (usePtr ? src[width] : c) >> 4; ++ } ++ break; ++ default: ++ if (usePtr) { ++ memcpy(dst + offset, src, width); ++ } else { ++ memset(dst + offset, c, width); ++ } ++ } ++} ++ + static int tiff_unpack_strip(TiffContext *s, uint8_t* dst, int stride, const uint8_t *src, int size, int lines){ + int c, line, pixels, code; + const uint8_t *ssrc = src; +- int width = s->width * s->bpp >> 3; ++ int width = ((s->width * s->bpp) + 7) >> 3; + #if CONFIG_ZLIB + uint8_t *zbuf; unsigned long outlen; + +@@ -119,7 +161,11 @@ + } + src = zbuf; + for(line = 0; line < lines; line++){ +- memcpy(dst, src, width); ++ if(s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8){ ++ horizontal_fill(s->bpp, dst, 1, src, 0, width, 0); ++ }else{ ++ memcpy(dst, src, width); ++ } + dst += stride; + src += width; + } +@@ -160,6 +206,11 @@ + ret = ff_ccitt_unpack(s->avctx, src2, size, dst, lines, stride, s->compr, s->fax_opts); + break; + } ++ if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8) ++ for (line = 0; line < lines; line++) { ++ horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0); ++ dst += stride; ++ } + av_free(src2); + return ret; + } +@@ -170,7 +221,16 @@ + } + switch(s->compr){ + case TIFF_RAW: +- memcpy(dst, src, width); ++ if (ssrc + size - src < width) ++ return AVERROR_INVALIDDATA; ++ if (!s->fill_order) { ++ horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), ++ dst, 1, src, 0, width, 0); ++ } else { ++ int i; ++ for (i = 0; i < width; i++) ++ dst[i] = av_reverse[src[i]]; ++ } + src += width; + break; + case TIFF_PACKBITS: +@@ -182,7 +242,8 @@ + av_log(s->avctx, AV_LOG_ERROR, "Copy went out of bounds\n"); + return -1; + } +- memcpy(dst + pixels, src, code); ++ horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), ++ dst, 1, src, 0, code, pixels); + src += code; + pixels += code; + }else if(code != -128){ // -127..-1 +@@ -192,7 +253,8 @@ + return -1; + } + c = *src++; +- memset(dst + pixels, c, code); ++ horizontal_fill(s->bpp * (s->avctx->pix_fmt == PIX_FMT_PAL8), ++ dst, 0, NULL, c, code, pixels); + pixels += code; + } + } +@@ -203,6 +265,8 @@ + av_log(s->avctx, AV_LOG_ERROR, "Decoded only %i bytes of %i\n", pixels, width); + return -1; + } ++ if (s->bpp < 8 && s->avctx->pix_fmt == PIX_FMT_PAL8) ++ horizontal_fill(s->bpp, dst, 1, dst, 0, width, 0); + break; + } + dst += stride; +@@ -210,19 +274,89 @@ + return 0; + } + ++static int init_image(TiffContext *s) ++{ ++ int i, ret; ++ uint32_t *pal; ++ ++ switch (s->bpp * 10 + s->bppcount) { ++ case 11: ++ if (!s->palette_is_set) { ++ s->avctx->pix_fmt = PIX_FMT_MONOBLACK; ++ break; ++ } ++ case 21: ++ case 41: ++ case 81: ++ s->avctx->pix_fmt = PIX_FMT_PAL8; ++ break; ++ case 243: ++ s->avctx->pix_fmt = PIX_FMT_RGB24; ++ break; ++ case 161: ++ s->avctx->pix_fmt = PIX_FMT_GRAY16BE; ++ break; ++ case 162: ++ s->avctx->pix_fmt = PIX_FMT_GRAY8A; ++ break; ++ case 324: ++ s->avctx->pix_fmt = PIX_FMT_RGBA; ++ break; ++ case 483: ++ s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE; ++ break; ++ case 644: ++ s->avctx->pix_fmt = s->le ? PIX_FMT_RGBA64LE : PIX_FMT_RGBA64BE; ++ break; ++ default: ++ av_log(s->avctx, AV_LOG_ERROR, ++ "This format is not supported (bpp=%d, bppcount=%d)\n", ++ s->bpp, s->bppcount); ++ return AVERROR_INVALIDDATA; ++ } ++ if (s->width != s->avctx->width || s->height != s->avctx->height) { ++ if ((ret = av_image_check_size(s->width, s->height, 0, s->avctx)) < 0) ++ return ret; ++ avcodec_set_dimensions(s->avctx, s->width, s->height); ++ } ++ if (s->picture.data[0]) ++ s->avctx->release_buffer(s->avctx, &s->picture); ++ if ((ret = s->avctx->get_buffer(s->avctx, &s->picture)) < 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ if (s->avctx->pix_fmt == PIX_FMT_PAL8) { ++ if (s->palette_is_set) { ++ memcpy(s->picture.data[1], s->palette, sizeof(s->palette)); ++ } else { ++ /* make default grayscale pal */ ++ pal = (uint32_t *) s->picture.data[1]; ++ for (i = 0; i < 1<bpp; i++) ++ pal[i] = 0xFF << 24 | i * 255 / ((1<bpp) - 1) * 0x010101; ++ } ++ } ++ return 0; ++} + + static int tiff_decode_tag(TiffContext *s, const uint8_t *start, const uint8_t *buf, const uint8_t *end_buf) + { +- int tag, type, count, off, value = 0; ++ unsigned tag, type, count, off, value = 0; + int i, j; + uint32_t *pal; + const uint8_t *rp, *gp, *bp; + ++ if (end_buf - buf < 12) ++ return -1; + tag = tget_short(&buf, s->le); + type = tget_short(&buf, s->le); + count = tget_long(&buf, s->le); + off = tget_long(&buf, s->le); + ++ if (type == 0 || type >= FF_ARRAY_ELEMS(type_sizes)) { ++ av_log(s->avctx, AV_LOG_DEBUG, "Unknown tiff type (%u) encountered\n", type); ++ return 0; ++ } ++ + if(count == 1){ + switch(type){ + case TIFF_BYTE: +@@ -241,13 +375,15 @@ + break; + } + default: +- value = -1; ++ value = UINT_MAX; ++ buf = start + off; ++ } ++ } else { ++ if (count <= 4 && type_sizes[type] * count <= 4) { ++ buf -= 4; ++ } else { + buf = start + off; + } +- }else if(type_sizes[type] * count <= 4){ +- buf -= 4; +- }else{ +- buf = start + off; + } + + if(buf && (buf < start || buf > end_buf)){ +@@ -263,6 +399,7 @@ + s->height = value; + break; + case TIFF_BPP: ++ s->bppcount = count; + if(count > 4){ + av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count); + return -1; +@@ -276,52 +413,22 @@ + case TIFF_SHORT: + case TIFF_LONG: + s->bpp = 0; +- for(i = 0; i < count; i++) s->bpp += tget(&buf, type, s->le); ++ for(i = 0; i < count && buf < end_buf; i++) s->bpp += tget(&buf, type, s->le); + break; + default: + s->bpp = -1; + } + } +- switch(s->bpp*10 + count){ +- case 11: +- s->avctx->pix_fmt = PIX_FMT_MONOBLACK; +- break; +- case 81: +- s->avctx->pix_fmt = PIX_FMT_PAL8; +- break; +- case 243: +- s->avctx->pix_fmt = PIX_FMT_RGB24; +- break; +- case 161: +- s->avctx->pix_fmt = PIX_FMT_GRAY16BE; +- break; +- case 324: +- s->avctx->pix_fmt = PIX_FMT_RGBA; +- break; +- case 483: +- s->avctx->pix_fmt = s->le ? PIX_FMT_RGB48LE : PIX_FMT_RGB48BE; +- break; +- default: +- av_log(s->avctx, AV_LOG_ERROR, "This format is not supported (bpp=%d, %d components)\n", s->bpp, count); +- return -1; +- } +- if(s->width != s->avctx->width || s->height != s->avctx->height){ +- if(av_image_check_size(s->width, s->height, 0, s->avctx)) +- return -1; +- avcodec_set_dimensions(s->avctx, s->width, s->height); +- } +- if(s->picture.data[0]) +- s->avctx->release_buffer(s->avctx, &s->picture); +- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; +- } +- if(s->bpp == 8){ +- /* make default grayscale pal */ +- pal = (uint32_t *) s->picture.data[1]; +- for(i = 0; i < 256; i++) +- pal[i] = i * 0x010101; +- } ++ break; ++ case TIFF_SAMPLES_PER_PIXEL: ++ if (count != 1) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Samples per pixel requires a single value, many provided\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (s->bppcount == 1) ++ s->bpp *= value; ++ s->bppcount = value; + break; + case TIFF_COMPR: + s->compr = value; +@@ -354,7 +461,7 @@ + } + break; + case TIFF_ROWSPERSTRIP: +- if(type == TIFF_LONG && value == -1) ++ if (type == TIFF_LONG && value == UINT_MAX) + value = s->avctx->height; + if(value < 1){ + av_log(s->avctx, AV_LOG_ERROR, "Incorrect value of rows per strip\n"); +@@ -391,6 +498,13 @@ + return -1; + } + break; ++ case TIFF_TILE_BYTE_COUNTS: ++ case TIFF_TILE_LENGTH: ++ case TIFF_TILE_OFFSETS: ++ case TIFF_TILE_WIDTH: ++ av_log(s->avctx, AV_LOG_ERROR, "Tiled images are not supported\n"); ++ return AVERROR_PATCHWELCOME; ++ break; + case TIFF_PREDICTOR: + s->predictor = value; + break; +@@ -418,22 +532,22 @@ + s->fill_order = value - 1; + break; + case TIFF_PAL: +- if(s->avctx->pix_fmt != PIX_FMT_PAL8){ +- av_log(s->avctx, AV_LOG_ERROR, "Palette met but this is not palettized format\n"); +- return -1; +- } +- pal = (uint32_t *) s->picture.data[1]; ++ pal = (uint32_t *) s->palette; + off = type_sizes[type]; ++ if (count / 3 > 256 || end_buf - buf < count / 3 * off * 3) ++ return -1; + rp = buf; + gp = buf + count / 3 * off; + bp = buf + count / 3 * off * 2; + off = (type_sizes[type] - 1) << 3; + for(i = 0; i < count / 3; i++){ +- j = (tget(&rp, type, s->le) >> off) << 16; ++ j = 0xff << 24; ++ j |= (tget(&rp, type, s->le) >> off) << 16; + j |= (tget(&gp, type, s->le) >> off) << 8; + j |= tget(&bp, type, s->le) >> off; + pal[i] = j; + } ++ s->palette_is_set = 1; + break; + case TIFF_PLANAR: + if(value == 2){ +@@ -449,6 +563,8 @@ + if(s->compr == TIFF_G4) + s->fax_opts = value; + break; ++ default: ++ av_log(s->avctx, AV_LOG_DEBUG, "Unknown or unsupported tag %d/0X%0X\n", tag, tag); + } + return 0; + } +@@ -463,12 +579,16 @@ + AVFrame *picture = data; + AVFrame * const p= (AVFrame*)&s->picture; + const uint8_t *orig_buf = buf, *end_buf = buf + buf_size; +- int id, le, off; ++ unsigned off; ++ int id, le, ret; + int i, j, entries; +- int stride, soff, ssize; ++ int stride; ++ unsigned soff, ssize; + uint8_t *dst; + + //parse image header ++ if (end_buf - buf < 8) ++ return AVERROR_INVALIDDATA; + id = AV_RL16(buf); buf += 2; + if(id == 0x4949) le = 1; + else if(id == 0x4D4D) le = 0; +@@ -486,11 +606,13 @@ + av_log(avctx, AV_LOG_ERROR, "The answer to life, universe and everything is not correct!\n"); + return -1; + } ++ // Reset these pointers so we can tell if they were set this frame ++ s->stripsizes = s->stripdata = NULL; + /* parse image file directory */ + off = tget_long(&buf, le); +- if(orig_buf + off + 14 >= end_buf){ ++ if (off >= UINT_MAX - 14 || end_buf - orig_buf < off + 14) { + av_log(avctx, AV_LOG_ERROR, "IFD offset is greater than image size\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + buf = orig_buf + off; + entries = tget_short(&buf, le); +@@ -504,21 +626,9 @@ + return -1; + } + /* now we have the data and may start decoding */ +- if(!p->data[0]){ +- s->bpp = 1; +- avctx->pix_fmt = PIX_FMT_MONOBLACK; +- if(s->width != s->avctx->width || s->height != s->avctx->height){ +- if(av_image_check_size(s->width, s->height, 0, s->avctx)) +- return -1; +- avcodec_set_dimensions(s->avctx, s->width, s->height); +- } +- if(s->picture.data[0]) +- s->avctx->release_buffer(s->avctx, &s->picture); +- if(s->avctx->get_buffer(s->avctx, &s->picture) < 0){ +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- return -1; +- } +- } ++ if ((ret = init_image(s)) < 0) ++ return ret; ++ + if(s->strips == 1 && !s->stripsize){ + av_log(avctx, AV_LOG_WARNING, "Image data size missing\n"); + s->stripsize = buf_size - s->stripoff; +@@ -526,23 +636,23 @@ + stride = p->linesize[0]; + dst = p->data[0]; + for(i = 0; i < s->height; i += s->rps){ +- if(s->stripsizes) ++ if(s->stripsizes) { ++ if (s->stripsizes >= end_buf) ++ return AVERROR_INVALIDDATA; + ssize = tget(&s->stripsizes, s->sstype, s->le); +- else ++ } else + ssize = s->stripsize; + +- if (ssize > buf_size) { +- av_log(avctx, AV_LOG_ERROR, "Buffer size is smaller than strip size\n"); +- return -1; +- } +- + if(s->stripdata){ ++ if (s->stripdata >= end_buf) ++ return AVERROR_INVALIDDATA; + soff = tget(&s->stripdata, s->sot, s->le); + }else + soff = s->stripoff; +- if (soff < 0) { +- av_log(avctx, AV_LOG_ERROR, "Invalid stripoff: %d\n", soff); +- return AVERROR(EINVAL); ++ ++ if (soff > buf_size || ssize > buf_size - soff) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid strip size/offset\n"); ++ return -1; + } + if(tiff_unpack_strip(s, dst, stride, orig_buf + soff, ssize, FFMIN(s->rps, s->height - i)) < 0) + break; +@@ -552,22 +662,35 @@ + dst = p->data[0]; + soff = s->bpp >> 3; + ssize = s->width * soff; +- for(i = 0; i < s->height; i++) { +- for(j = soff; j < ssize; j++) +- dst[j] += dst[j - soff]; +- dst += stride; ++ if (s->avctx->pix_fmt == PIX_FMT_RGB48LE || ++ s->avctx->pix_fmt == PIX_FMT_RGBA64LE) { ++ for (i = 0; i < s->height; i++) { ++ for (j = soff; j < ssize; j += 2) ++ AV_WL16(dst + j, AV_RL16(dst + j) + AV_RL16(dst + j - soff)); ++ dst += stride; ++ } ++ } else if (s->avctx->pix_fmt == PIX_FMT_RGB48BE || ++ s->avctx->pix_fmt == PIX_FMT_RGBA64BE) { ++ for (i = 0; i < s->height; i++) { ++ for (j = soff; j < ssize; j += 2) ++ AV_WB16(dst + j, AV_RB16(dst + j) + AV_RB16(dst + j - soff)); ++ dst += stride; ++ } ++ } else { ++ for(i = 0; i < s->height; i++) { ++ for(j = soff; j < ssize; j++) ++ dst[j] += dst[j - soff]; ++ dst += stride; ++ } + } + } + + if(s->invert){ +- uint8_t *src; +- int j; +- +- src = s->picture.data[0]; +- for(j = 0; j < s->height; j++){ +- for(i = 0; i < s->picture.linesize[0]; i++) +- src[i] = 255 - src[i]; +- src += s->picture.linesize[0]; ++ dst = s->picture.data[0]; ++ for(i = 0; i < s->height; i++){ ++ for(j = 0; j < s->picture.linesize[0]; j++) ++ dst[j] = (s->avctx->pix_fmt == PIX_FMT_PAL8 ? (1<bpp) - 1 : 255) - dst[j]; ++ dst += s->picture.linesize[0]; + } + } + *picture= *(AVFrame*)&s->picture; +@@ -601,15 +724,13 @@ + } + + AVCodec ff_tiff_decoder = { +- "tiff", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TIFF, +- sizeof(TiffContext), +- tiff_init, +- NULL, +- tiff_end, +- decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "tiff", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TIFF, ++ .priv_data_size = sizeof(TiffContext), ++ .init = tiff_init, ++ .close = tiff_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiffenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiffenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiffenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiffenc.c 2012-05-14 14:08:54.266338614 +0200 +@@ -20,14 +20,19 @@ + */ + + /** +- * TIFF image encoder + * @file ++ * TIFF image encoder + * @author Bartlomiej Wolowiec + */ ++ ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ + #include "avcodec.h" + #if CONFIG_ZLIB + #include + #endif ++#include "libavutil/opt.h" + #include "bytestream.h" + #include "tiff.h" + #include "rle.h" +@@ -42,6 +47,7 @@ + }; + + typedef struct TiffEncoderContext { ++ AVClass *class; ///< for private options + AVCodecContext *avctx; + AVFrame picture; + +@@ -60,6 +66,7 @@ + int buf_size; ///< buffer size + uint16_t subsampling[2]; ///< YUV subsampling factors + struct LZWEncodeState *lzws; ///< LZW Encode state ++ uint32_t dpi; ///< image resolution in DPI + } TiffEncoderContext; + + +@@ -209,23 +216,28 @@ + uint32_t *strip_sizes = NULL; + uint32_t *strip_offsets = NULL; + int bytes_per_row; +- uint32_t res[2] = { 72, 1 }; // image resolution (72/1) +- static const uint16_t bpp_tab[] = { 8, 8, 8, 8 }; ++ uint32_t res[2] = { s->dpi, 1 }; // image resolution (72/1) ++ uint16_t bpp_tab[] = { 8, 8, 8, 8 }; + int ret = -1; + int is_yuv = 0; + uint8_t *yuv_line = NULL; + int shift_h, shift_v; + ++ s->avctx = avctx; + s->buf_start = buf; + s->buf = &ptr; + s->buf_size = buf_size; + + *p = *pict; +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + p->key_frame = 1; + avctx->coded_frame= &s->picture; + +- s->compr = TIFF_PACKBITS; ++#if FF_API_TIFFENC_COMPLEVEL ++ if (avctx->compression_level != FF_COMPRESSION_DEFAULT) ++ av_log(avctx, AV_LOG_WARNING, "Using compression_level to set compression " ++ "algorithm is deprecated. Please use the compression_algo private " ++ "option instead.\n"); + if (avctx->compression_level == 0) { + s->compr = TIFF_RAW; + } else if(avctx->compression_level == 2) { +@@ -235,6 +247,7 @@ + s->compr = TIFF_DEFLATE; + #endif + } ++#endif + + s->width = avctx->width; + s->height = avctx->height; +@@ -242,6 +255,26 @@ + s->subsampling[1] = 1; + + switch (avctx->pix_fmt) { ++ case PIX_FMT_RGBA64LE: ++ s->bpp = 64; ++ s->photometric_interpretation = 2; ++ bpp_tab[0] = 16; ++ bpp_tab[1] = 16; ++ bpp_tab[2] = 16; ++ bpp_tab[3] = 16; ++ break; ++ case PIX_FMT_RGB48LE: ++ s->bpp = 48; ++ s->photometric_interpretation = 2; ++ bpp_tab[0] = 16; ++ bpp_tab[1] = 16; ++ bpp_tab[2] = 16; ++ bpp_tab[3] = 16; ++ break; ++ case PIX_FMT_RGBA: ++ s->bpp = 32; ++ s->photometric_interpretation = 2; ++ break; + case PIX_FMT_RGB24: + s->bpp = 24; + s->photometric_interpretation = 2; +@@ -255,12 +288,10 @@ + s->photometric_interpretation = 3; + break; + case PIX_FMT_MONOBLACK: +- s->bpp = 1; +- s->photometric_interpretation = 1; +- break; + case PIX_FMT_MONOWHITE: + s->bpp = 1; +- s->photometric_interpretation = 0; ++ s->photometric_interpretation = avctx->pix_fmt == PIX_FMT_MONOBLACK; ++ bpp_tab[0] = 1; + break; + case PIX_FMT_YUV420P: + case PIX_FMT_YUV422P: +@@ -282,7 +313,7 @@ + return -1; + } + if (!is_yuv) +- s->bpp_tab_size = (s->bpp >> 3); ++ s->bpp_tab_size = (s->bpp >= 48) ? ((s->bpp + 7) >> 4):((s->bpp + 7) >> 3); + + if (s->compr == TIFF_DEFLATE || s->compr == TIFF_ADOBE_DEFLATE || s->compr == TIFF_LZW) + //best choose for DEFLATE +@@ -442,23 +473,40 @@ + return ret; + } + ++#define OFFSET(x) offsetof(TiffEncoderContext, x) ++#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ {"dpi", "set the image resolution (in dpi)", OFFSET(dpi), AV_OPT_TYPE_INT, {.dbl = 72}, 1, 0x10000, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_ENCODING_PARAM}, ++ { "compression_algo", NULL, OFFSET(compr), AV_OPT_TYPE_INT, {TIFF_PACKBITS}, TIFF_RAW, TIFF_DEFLATE, VE, "compression_algo" }, ++ { "packbits", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_PACKBITS}, 0, 0, VE, "compression_algo" }, ++ { "raw", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_RAW}, 0, 0, VE, "compression_algo" }, ++ { "lzw", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_LZW}, 0, 0, VE, "compression_algo" }, ++#if CONFIG_ZLIB ++ { "deflate", NULL, 0, AV_OPT_TYPE_CONST, {TIFF_DEFLATE}, 0, 0, VE, "compression_algo" }, ++#endif ++ { NULL }, ++}; ++ ++static const AVClass tiffenc_class = { ++ .class_name = "TIFF encoder", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_tiff_encoder = { +- "tiff", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TIFF, +- sizeof(TiffEncoderContext), +- NULL, +- encode_frame, +- NULL, +- NULL, +- 0, +- NULL, ++ .name = "tiff", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TIFF, ++ .priv_data_size = sizeof(TiffEncoderContext), ++ .encode = encode_frame, + .pix_fmts = + (const enum PixelFormat[]) {PIX_FMT_RGB24, PIX_FMT_PAL8, PIX_FMT_GRAY8, + PIX_FMT_MONOBLACK, PIX_FMT_MONOWHITE, + PIX_FMT_YUV420P, PIX_FMT_YUV422P, + PIX_FMT_YUV444P, PIX_FMT_YUV410P, +- PIX_FMT_YUV411P, +- PIX_FMT_NONE}, ++ PIX_FMT_YUV411P, PIX_FMT_RGB48LE, ++ PIX_FMT_RGBA, PIX_FMT_RGBA64LE, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("TIFF image"), ++ .priv_class = &tiffenc_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiff.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiff.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tiff.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tiff.h 2012-05-14 14:08:54.264338573 +0200 +@@ -1,5 +1,4 @@ + /* +- * TIFF tables + * Copyright (c) 2006 Konstantin Shishkov + * + * This file is part of FFmpeg. +@@ -20,10 +19,14 @@ + */ + + /** +- * TIFF tables + * @file ++ * TIFF tables ++ * ++ * For more information about the TIFF format, check the official docs at: ++ * http://partners.adobe.com/public/developer/tiff/index.html + * @author Konstantin Shishkov + */ ++ + #ifndef AVCODEC_TIFF_H + #define AVCODEC_TIFF_H + +@@ -53,6 +56,10 @@ + TIFF_SOFTWARE_NAME = 0x131, + TIFF_PREDICTOR = 0x13D, + TIFF_PAL = 0x140, ++ TIFF_TILE_WIDTH = 0x142, ++ TIFF_TILE_LENGTH = 0x143, ++ TIFF_TILE_OFFSETS = 0x144, ++ TIFF_TILE_BYTE_COUNTS = 0x145, + TIFF_YCBCR_COEFFICIENTS = 0x211, + TIFF_YCBCR_SUBSAMPLING = 0x212, + TIFF_YCBCR_POSITIONING = 0x213, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/timecode.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/timecode.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/timecode.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/timecode.c 2012-05-14 14:08:54.267338634 +0200 +@@ -0,0 +1,146 @@ ++/* ++ * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier ++ * Copyright (C) 2011 Smartjog S.A.S, Clément BÅ“sch ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Timecode helpers ++ */ ++ ++#include ++#include "timecode.h" ++#include "libavutil/log.h" ++ ++int avpriv_framenum_to_drop_timecode(int frame_num) ++{ ++ /* only works for NTSC 29.97 */ ++ int d = frame_num / 17982; ++ int m = frame_num % 17982; ++ //if (m < 2) m += 2; /* not needed since -2,-1 / 1798 in C returns 0 */ ++ return frame_num + 18 * d + 2 * ((m - 2) / 1798); ++} ++ ++uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop) ++{ ++ return (0 << 31) | // color frame flag ++ (drop << 30) | // drop frame flag ++ ( ((frame % fps) / 10) << 28) | // tens of frames ++ ( ((frame % fps) % 10) << 24) | // units of frames ++ (0 << 23) | // field phase (NTSC), b0 (PAL) ++ ((((frame / fps) % 60) / 10) << 20) | // tens of seconds ++ ((((frame / fps) % 60) % 10) << 16) | // units of seconds ++ (0 << 15) | // b0 (NTSC), b2 (PAL) ++ ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes ++ ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes ++ (0 << 7) | // b1 ++ (0 << 6) | // b2 (NTSC), field phase (PAL) ++ ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours ++ ( (frame / (fps * 3600) % 24)) % 10; // units of hours ++} ++ ++int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop) ++{ ++ int fps; ++ ++ if (!rate.num || !rate.den) { ++ av_log(avcl, AV_LOG_ERROR, "Timecode frame rate must be specified\n"); ++ return -1; ++ } ++ fps = (rate.num + rate.den/2) / rate.den; ++ if (drop && fps != 30) { ++ av_log(avcl, AV_LOG_ERROR, "Drop frame is only allowed with 30000/1001 FPS\n"); ++ return -2; ++ } ++ switch (fps) { ++ case 24: ++ case 25: ++ case 30: return 0; ++ ++ default: ++ av_log(avcl, AV_LOG_ERROR, "Timecode frame rate not supported\n"); ++ return -3; ++ } ++} ++ ++char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame) ++{ ++ int frame_num = tc->start + frame; ++ int fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den; ++ int hh, mm, ss, ff, neg = 0; ++ ++ if (tc->drop) ++ frame_num = avpriv_framenum_to_drop_timecode(frame_num); ++ if (frame_num < 0) { ++ frame_num = -frame_num; ++ neg = 1; ++ } ++ ff = frame_num % fps; ++ ss = frame_num / fps % 60; ++ mm = frame_num / (fps*60) % 60; ++ hh = frame_num / (fps*3600); ++ snprintf(buf, 16, "%s%02d:%02d:%02d%c%02d", ++ neg ? "-" : "", ++ hh, mm, ss, tc->drop ? ';' : ':', ff); ++ return buf; ++} ++ ++int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc) ++{ ++ int hh, mm, ss, ff, fps, ret; ++ char c; ++ ++ if (sscanf(tc->str, "%d:%d:%d%c%d", &hh, &mm, &ss, &c, &ff) != 5) { ++ av_log(avcl, AV_LOG_ERROR, "unable to parse timecode, " ++ "syntax: hh:mm:ss[:;.]ff\n"); ++ return -1; ++ } ++ ++ tc->drop = c != ':'; // drop if ';', '.', ... ++ ++ ret = avpriv_check_timecode_rate(avcl, tc->rate, tc->drop); ++ if (ret < 0) ++ return ret; ++ ++ fps = (tc->rate.num + tc->rate.den/2) / tc->rate.den; ++ tc->start = (hh*3600 + mm*60 + ss) * fps + ff; ++ ++ if (tc->drop) { /* adjust frame number */ ++ int tmins = 60*hh + mm; ++ tc->start -= 2 * (tmins - tmins/10); ++ } ++ return 0; ++} ++ ++#if FF_API_OLD_TIMECODE ++int ff_framenum_to_drop_timecode(int frame_num) ++{ ++ return avpriv_framenum_to_drop_timecode(frame_num); ++} ++ ++uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop) ++{ ++ return avpriv_framenum_to_smpte_timecode(frame, fps, drop); ++} ++ ++int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc) ++{ ++ return avpriv_init_smpte_timecode(avcl, tc); ++} ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/timecode.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/timecode.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/timecode.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/timecode.h 2012-05-14 14:08:54.267338634 +0200 +@@ -0,0 +1,102 @@ ++/* ++ * Copyright (C) 2006 Smartjog S.A.S, Baptiste Coudurier ++ * Copyright (C) 2011 Smartjog S.A.S, Clément BÅ“sch ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Timecode helpers header ++ */ ++ ++#ifndef AVCODEC_TIMECODE_H ++#define AVCODEC_TIMECODE_H ++ ++#include ++#include "avcodec.h" ++#include "libavutil/rational.h" ++ ++#define TIMECODE_OPT(ctx, flags) \ ++ "timecode", "set timecode value following hh:mm:ss[:;.]ff format, " \ ++ "use ';' or '.' before frame number for drop frame", \ ++ offsetof(ctx, tc.str), \ ++ AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX, flags ++ ++struct ff_timecode { ++ char *str; ///< string following the hh:mm:ss[:;.]ff format ++ int start; ///< timecode frame start ++ int drop; ///< drop flag (1 if drop, else 0) ++ AVRational rate; ///< Frame rate in rational form ++}; ++ ++/** ++ * @brief Adjust frame number for NTSC drop frame time code ++ * @param frame_num Actual frame number to adjust ++ * @return Adjusted frame number ++ * @warning Adjustment is only valid in NTSC 29.97 ++ */ ++int avpriv_framenum_to_drop_timecode(int frame_num); ++ ++/** ++ * @brief Convert frame id (timecode) to SMPTE 12M binary representation ++ * @param frame Frame number ++ * @param fps Frame rate ++ * @param drop Drop flag ++ * @return The actual binary representation ++ */ ++uint32_t avpriv_framenum_to_smpte_timecode(unsigned frame, int fps, int drop); ++ ++/** ++ * @brief Load timecode string in buf ++ * @param buf Destination buffer ++ * @param tc Timecode struct pointer ++ * @param frame Frame id (timecode frame is computed with tc->start+frame) ++ * @return a pointer to the buf parameter ++ * @note timecode representation can be a negative timecode and have ++ * more than 24 hours. ++ * @note buf must have enough space to store the timecode representation: 16 ++ * bytes is the minimum required size. ++ */ ++char *avpriv_timecode_to_string(char *buf, const struct ff_timecode *tc, unsigned frame); ++ ++/** ++ * Check if timecode rate is valid and consistent with the drop flag. ++ * ++ * @return 0 on success, negative value on failure ++ */ ++int avpriv_check_timecode_rate(void *avcl, AVRational rate, int drop); ++ ++/** ++ * Parse SMTPE 12M time representation (hh:mm:ss[:;.]ff). str and rate fields ++ * from tc struct must be set. ++ * ++ * @param avcl A pointer to an arbitrary struct of which the first field is a ++ * pointer to an AVClass struct (used for av_log). ++ * @param tc Timecode struct pointer ++ * @return 0 on success, negative value on failure ++ * @warning Adjustement is only valid in NTSC 29.97 ++ */ ++int avpriv_init_smpte_timecode(void *avcl, struct ff_timecode *tc); ++ ++#if FF_API_OLD_TIMECODE ++attribute_deprecated int ff_framenum_to_drop_timecode(int frame_num); ++attribute_deprecated uint32_t ff_framenum_to_smtpe_timecode(unsigned frame, int fps, int drop); ++attribute_deprecated int ff_init_smtpe_timecode(void *avcl, struct ff_timecode *tc); ++#endif ++ ++#endif /* AVCODEC_TIMECODE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tmv.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tmv.c 2012-05-14 14:08:54.268338654 +0200 +@@ -20,10 +20,10 @@ + */ + + /** +- * 8088flex TMV video decoder + * @file ++ * 8088flex TMV video decoder + * @author Daniel Verkamp +- * @sa http://www.oldskool.org/pc/8088_Corruption ++ * @see http://www.oldskool.org/pc/8088_Corruption + */ + + #include "avcodec.h" +@@ -59,7 +59,7 @@ + return -1; + } + +- tmv->pic.pict_type = FF_I_TYPE; ++ tmv->pic.pict_type = AV_PICTURE_TYPE_I; + tmv->pic.key_frame = 1; + dst = tmv->pic.data[0]; + +@@ -82,6 +82,14 @@ + return avpkt->size; + } + ++static av_cold int tmv_decode_init(AVCodecContext *avctx) ++{ ++ TMVContext *tmv = avctx->priv_data; ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&tmv->pic); ++ return 0; ++} ++ + static av_cold int tmv_decode_close(AVCodecContext *avctx) + { + TMVContext *tmv = avctx->priv_data; +@@ -97,6 +105,7 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_TMV, + .priv_data_size = sizeof(TMVContext), ++ .init = tmv_decode_init, + .close = tmv_decode_close, + .decode = tmv_decode_frame, + .capabilities = CODEC_CAP_DR1, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion1.c 2012-05-14 14:08:54.269338674 +0200 +@@ -35,7 +35,7 @@ + + #include "avcodec.h" + #include "dsputil.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + #include "truemotion1data.h" + +@@ -353,7 +353,7 @@ + s->flags = FLAG_KEYFRAME; + + if (s->flags & FLAG_SPRITE) { +- av_log(s->avctx, AV_LOG_INFO, "SPRITE frame found, please report the sample to the developers\n"); ++ av_log_ask_for_sample(s->avctx, "SPRITE frame found.\n"); + /* FIXME header.width, height, xoffset and yoffset aren't initialized */ + #if 0 + s->w = header.width; +@@ -370,7 +370,7 @@ + if ((s->w < 213) && (s->h >= 176)) + { + s->flags |= FLAG_INTERPOLATED; +- av_log(s->avctx, AV_LOG_INFO, "INTERPOLATION selected, please report the sample to the developers\n"); ++ av_log_ask_for_sample(s->avctx, "INTERPOLATION selected.\n"); + } + } + } +@@ -474,6 +474,7 @@ + // else + // avctx->pix_fmt = PIX_FMT_RGB555; + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + /* there is a vertical predictor for each pixel in a line; each vertical +@@ -858,7 +859,7 @@ + if (truemotion1_decode_header(s) == -1) + return -1; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | + FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if (avctx->reget_buffer(avctx, &s->frame) < 0) { +@@ -892,14 +893,13 @@ + } + + AVCodec ff_truemotion1_decoder = { +- "truemotion1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TRUEMOTION1, +- sizeof(TrueMotion1Context), +- truemotion1_decode_init, +- NULL, +- truemotion1_decode_end, +- truemotion1_decode_frame, +- CODEC_CAP_DR1, ++ .name = "truemotion1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TRUEMOTION1, ++ .priv_data_size = sizeof(TrueMotion1Context), ++ .init = truemotion1_decode_init, ++ .close = truemotion1_decode_end, ++ .decode = truemotion1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 1.0"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion1data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion1data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion1data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion1data.h 2012-05-14 14:08:54.270338694 +0200 +@@ -2,9 +2,9 @@ + * Duck Truemotion v1 Decoding Tables + * + * Data in this file was originally part of VpVision from On2 which is +- * distributed under the GNU GPL. It is redistributed with ffmpeg under the +- * GNU LGPL using the common understanding that data tables necessary for +- * decoding algorithms are not necessarily licensable. ++ * distributed under the GNU GPL. It is redistributed with libavcodec under ++ * the GNU LGPL using the common understanding that data tables necessary ++ * for decoding algorithms are not necessarily copyrightable. + * + * This file is part of FFmpeg. + * +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truemotion2.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truemotion2.c 2012-05-14 14:08:54.272338734 +0200 +@@ -44,6 +44,9 @@ + GetBitContext gb; + DSPContext dsp; + ++ uint8_t *buffer; ++ int buffer_size; ++ + /* TM2 streams */ + int *tokens[TM2_NUM_STREAMS]; + int tok_lens[TM2_NUM_STREAMS]; +@@ -132,7 +135,7 @@ + huff.val_bits, huff.max_bits); + return -1; + } +- if((huff.nodes < 0) || (huff.nodes > 0x10000)) { ++ if((huff.nodes <= 0) || (huff.nodes > 0x10000)) { + av_log(ctx->avctx, AV_LOG_ERROR, "Incorrect number of Huffman tree nodes: %i\n", huff.nodes); + return -1; + } +@@ -185,8 +188,7 @@ + + static void tm2_free_codes(TM2Codes *code) + { +- if(code->recode) +- av_free(code->recode); ++ av_free(code->recode); + if(code->vlc.table) + free_vlc(&code->vlc); + } +@@ -202,7 +204,6 @@ + { + uint32_t magic; + const uint8_t *obuf; +- int length; + + obuf = buf; + +@@ -213,19 +214,6 @@ + /* av_log (ctx->avctx, AV_LOG_ERROR, "TM2 old header: not implemented (yet)\n"); */ + return 40; + } else if(magic == 0x00000101) { /* new header */ +- int w, h, size, flags, xr, yr; +- +- length = AV_RL32(buf); +- buf += 4; +- +- init_get_bits(&ctx->gb, buf, 32 * 8); +- size = get_bits_long(&ctx->gb, 31); +- h = get_bits(&ctx->gb, 15); +- w = get_bits(&ctx->gb, 15); +- flags = get_bits_long(&ctx->gb, 31); +- yr = get_bits(&ctx->gb, 9); +- xr = get_bits(&ctx->gb, 9); +- + return 40; + } else { + av_log (ctx->avctx, AV_LOG_ERROR, "Not a TM2 header: 0x%08X\n", magic); +@@ -287,6 +275,8 @@ + len = AV_RB32(buf); buf += 4; cur += 4; + } + if(len > 0) { ++ if (skip <= cur) ++ return -1; + init_get_bits(&ctx->gb, buf, (skip - cur) * 8); + if(tm2_read_deltas(ctx, stream_id) == -1) + return -1; +@@ -301,6 +291,8 @@ + buf += 4; cur += 4; + buf += 4; cur += 4; /* unused by decoder */ + ++ if (skip <= cur) ++ return -1; + init_get_bits(&ctx->gb, buf, (skip - cur) * 8); + if(tm2_build_huff_table(ctx, &codes) == -1) + return -1; +@@ -318,6 +310,8 @@ + ctx->tok_lens[stream_id] = toks; + len = AV_RB32(buf); buf += 4; cur += 4; + if(len > 0) { ++ if (skip <= cur) ++ return -1; + init_get_bits(&ctx->gb, buf, (skip - cur) * 8); + for(i = 0; i < toks; i++) { + if (get_bits_left(&ctx->gb) <= 0) { +@@ -775,47 +769,42 @@ + TM2Context * const l = avctx->priv_data; + AVFrame * const p= (AVFrame*)&l->pic; + int i, skip, t; +- uint8_t *swbuf; + +- swbuf = av_malloc(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); +- if(!swbuf){ ++ av_fast_padded_malloc(&l->buffer, &l->buffer_size, buf_size); ++ if(!l->buffer){ + av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n"); + return -1; + } +- p->reference = 1; ++ p->reference = 3; + p->buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if(avctx->reget_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- av_free(swbuf); + return -1; + } + +- l->dsp.bswap_buf((uint32_t*)swbuf, (const uint32_t*)buf, buf_size >> 2); +- skip = tm2_read_header(l, swbuf); ++ l->dsp.bswap_buf((uint32_t*)l->buffer, (const uint32_t*)buf, buf_size >> 2); ++ skip = tm2_read_header(l, l->buffer); + + if(skip == -1){ +- av_free(swbuf); + return -1; + } + + for(i = 0; i < TM2_NUM_STREAMS; i++){ +- t = tm2_read_stream(l, swbuf + skip, tm2_stream_order[i], buf_size); ++ t = tm2_read_stream(l, l->buffer + skip, tm2_stream_order[i], buf_size); + if(t == -1){ +- av_free(swbuf); + return -1; + } + skip += t; + } + p->key_frame = tm2_decode_blocks(l, p); + if(p->key_frame) +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + else +- p->pict_type = FF_P_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_P; + + l->cur = !l->cur; + *data_size = sizeof(AVFrame); + *(AVFrame*)data = l->pic; +- av_free(swbuf); + + return buf_size; + } +@@ -832,6 +821,7 @@ + l->avctx = avctx; + l->pic.data[0]=NULL; + avctx->pix_fmt = PIX_FMT_BGR24; ++ avcodec_get_frame_defaults(&l->pic); + + dsputil_init(&l->dsp, avctx); + +@@ -859,13 +849,10 @@ + AVFrame *pic = &l->pic; + int i; + +- if(l->last) +- av_free(l->last); +- if(l->clast) +- av_free(l->clast); ++ av_free(l->last); ++ av_free(l->clast); + for(i = 0; i < TM2_NUM_STREAMS; i++) +- if(l->tokens[i]) +- av_free(l->tokens[i]); ++ av_free(l->tokens[i]); + if(l->Y1){ + av_free(l->Y1); + av_free(l->U1); +@@ -874,6 +861,8 @@ + av_free(l->U2); + av_free(l->V2); + } ++ av_freep(&l->buffer); ++ l->buffer_size = 0; + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); +@@ -882,14 +871,13 @@ + } + + AVCodec ff_truemotion2_decoder = { +- "truemotion2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TRUEMOTION2, +- sizeof(TM2Context), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "truemotion2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TRUEMOTION2, ++ .priv_data_size = sizeof(TM2Context), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Duck TrueMotion 2.0"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truespeech.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truespeech.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/truespeech.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/truespeech.c 2012-05-14 14:08:54.273338754 +0200 +@@ -21,6 +21,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avcodec.h" ++#include "dsputil.h" ++#include "get_bits.h" + + #include "truespeech_data.h" + /** +@@ -32,14 +34,17 @@ + * TrueSpeech decoder context + */ + typedef struct { ++ AVFrame frame; ++ DSPContext dsp; + /* input data */ +- int16_t vector[8]; //< input vector: 5/5/4/4/4/3/3/3 +- int offset1[2]; //< 8-bit value, used in one copying offset +- int offset2[4]; //< 7-bit value, encodes offsets for copying and for two-point filter +- int pulseoff[4]; //< 4-bit offset of pulse values block +- int pulsepos[4]; //< 27-bit variable, encodes 7 pulse positions +- int pulseval[4]; //< 7x2-bit pulse values +- int flag; //< 1-bit flag, shows how to choose filters ++ uint8_t buffer[32]; ++ int16_t vector[8]; ///< input vector: 5/5/4/4/4/3/3/3 ++ int offset1[2]; ///< 8-bit value, used in one copying offset ++ int offset2[4]; ///< 7-bit value, encodes offsets for copying and for two-point filter ++ int pulseoff[4]; ///< 4-bit offset of pulse values block ++ int pulsepos[4]; ///< 27-bit variable, encodes 7 pulse positions ++ int pulseval[4]; ///< 7x2-bit pulse values ++ int flag; ///< 1-bit flag, shows how to choose filters + /* temporary data */ + int filtbuf[146]; // some big vector used for storing filters + int prevfilt[8]; // filter from previous frame +@@ -54,100 +59,69 @@ + + static av_cold int truespeech_decode_init(AVCodecContext * avctx) + { +-// TSContext *c = avctx->priv_data; ++ TSContext *c = avctx->priv_data; ++ ++ if (avctx->channels != 1) { ++ av_log_ask_for_sample(avctx, "Unsupported channel count: %d\n", avctx->channels); ++ return AVERROR(EINVAL); ++ } + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ dsputil_init(&c->dsp, avctx); ++ ++ avcodec_get_frame_defaults(&c->frame); ++ avctx->coded_frame = &c->frame; ++ + return 0; + } + + static void truespeech_read_frame(TSContext *dec, const uint8_t *input) + { +- uint32_t t; +- +- /* first dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->flag = t & 1; +- +- dec->vector[0] = ts_codebook[0][(t >> 1) & 0x1F]; +- dec->vector[1] = ts_codebook[1][(t >> 6) & 0x1F]; +- dec->vector[2] = ts_codebook[2][(t >> 11) & 0xF]; +- dec->vector[3] = ts_codebook[3][(t >> 15) & 0xF]; +- dec->vector[4] = ts_codebook[4][(t >> 19) & 0xF]; +- dec->vector[5] = ts_codebook[5][(t >> 23) & 0x7]; +- dec->vector[6] = ts_codebook[6][(t >> 26) & 0x7]; +- dec->vector[7] = ts_codebook[7][(t >> 29) & 0x7]; +- +- /* second dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->offset2[0] = (t >> 0) & 0x7F; +- dec->offset2[1] = (t >> 7) & 0x7F; +- dec->offset2[2] = (t >> 14) & 0x7F; +- dec->offset2[3] = (t >> 21) & 0x7F; +- +- dec->offset1[0] = ((t >> 28) & 0xF) << 4; +- +- /* third dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulseval[0] = (t >> 0) & 0x3FFF; +- dec->pulseval[1] = (t >> 14) & 0x3FFF; +- +- dec->offset1[1] = (t >> 28) & 0x0F; +- +- /* fourth dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulseval[2] = (t >> 0) & 0x3FFF; +- dec->pulseval[3] = (t >> 14) & 0x3FFF; +- +- dec->offset1[1] |= ((t >> 28) & 0x0F) << 4; +- +- /* fifth dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulsepos[0] = (t >> 4) & 0x7FFFFFF; ++ GetBitContext gb; + +- dec->pulseoff[0] = (t >> 0) & 0xF; +- +- dec->offset1[0] |= (t >> 31) & 1; +- +- /* sixth dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulsepos[1] = (t >> 4) & 0x7FFFFFF; +- +- dec->pulseoff[1] = (t >> 0) & 0xF; +- +- dec->offset1[0] |= ((t >> 31) & 1) << 1; +- +- /* seventh dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulsepos[2] = (t >> 4) & 0x7FFFFFF; +- +- dec->pulseoff[2] = (t >> 0) & 0xF; +- +- dec->offset1[0] |= ((t >> 31) & 1) << 2; +- +- /* eighth dword */ +- t = AV_RL32(input); +- input += 4; +- +- dec->pulsepos[3] = (t >> 4) & 0x7FFFFFF; +- +- dec->pulseoff[3] = (t >> 0) & 0xF; +- +- dec->offset1[0] |= ((t >> 31) & 1) << 3; ++ dec->dsp.bswap_buf((uint32_t *)dec->buffer, (const uint32_t *)input, 8); ++ init_get_bits(&gb, dec->buffer, 32 * 8); + ++ dec->vector[7] = ts_codebook[7][get_bits(&gb, 3)]; ++ dec->vector[6] = ts_codebook[6][get_bits(&gb, 3)]; ++ dec->vector[5] = ts_codebook[5][get_bits(&gb, 3)]; ++ dec->vector[4] = ts_codebook[4][get_bits(&gb, 4)]; ++ dec->vector[3] = ts_codebook[3][get_bits(&gb, 4)]; ++ dec->vector[2] = ts_codebook[2][get_bits(&gb, 4)]; ++ dec->vector[1] = ts_codebook[1][get_bits(&gb, 5)]; ++ dec->vector[0] = ts_codebook[0][get_bits(&gb, 5)]; ++ dec->flag = get_bits1(&gb); ++ ++ dec->offset1[0] = get_bits(&gb, 4) << 4; ++ dec->offset2[3] = get_bits(&gb, 7); ++ dec->offset2[2] = get_bits(&gb, 7); ++ dec->offset2[1] = get_bits(&gb, 7); ++ dec->offset2[0] = get_bits(&gb, 7); ++ ++ dec->offset1[1] = get_bits(&gb, 4); ++ dec->pulseval[1] = get_bits(&gb, 14); ++ dec->pulseval[0] = get_bits(&gb, 14); ++ ++ dec->offset1[1] |= get_bits(&gb, 4) << 4; ++ dec->pulseval[3] = get_bits(&gb, 14); ++ dec->pulseval[2] = get_bits(&gb, 14); ++ ++ dec->offset1[0] |= get_bits1(&gb); ++ dec->pulsepos[0] = get_bits_long(&gb, 27); ++ dec->pulseoff[0] = get_bits(&gb, 4); ++ ++ dec->offset1[0] |= get_bits1(&gb) << 1; ++ dec->pulsepos[1] = get_bits_long(&gb, 27); ++ dec->pulseoff[1] = get_bits(&gb, 4); ++ ++ dec->offset1[0] |= get_bits1(&gb) << 2; ++ dec->pulsepos[2] = get_bits_long(&gb, 27); ++ dec->pulseoff[2] = get_bits(&gb, 4); ++ ++ dec->offset1[0] |= get_bits1(&gb) << 3; ++ dec->pulsepos[3] = get_bits_long(&gb, 27); ++ dec->pulseoff[3] = get_bits(&gb, 4); + } + + static void truespeech_correlate_filter(TSContext *dec) +@@ -157,7 +131,7 @@ + + for(i = 0; i < 8; i++){ + if(i > 0){ +- memcpy(tmp, dec->cvector, i * 2); ++ memcpy(tmp, dec->cvector, i * sizeof(*tmp)); + for(j = 0; j < i; j++) + dec->cvector[j] = ((tmp[i - j - 1] * dec->vector[i]) + + (dec->cvector[j] << 15) + 0x4000) >> 15; +@@ -199,12 +173,13 @@ + + t = dec->offset2[quart]; + if(t == 127){ +- memset(dec->newvec, 0, 60 * 2); ++ memset(dec->newvec, 0, 60 * sizeof(*dec->newvec)); + return; + } + for(i = 0; i < 146; i++) + tmp[i] = dec->filtbuf[i]; + off = (t / 25) + dec->offset1[quart >> 1] + 18; ++ off = av_clip(off, 0, 145); + ptr0 = tmp + 145 - off; + ptr1 = tmp + 146; + filter = (const int16_t*)ts_order2_coeffs + (t % 25) * 2; +@@ -224,7 +199,7 @@ + int16_t *ptr2; + int coef; + +- memset(out, 0, 60 * 2); ++ memset(out, 0, 60 * sizeof(*out)); + for(i = 0; i < 7; i++) { + t = dec->pulseval[quart] & 3; + dec->pulseval[quart] >>= 2; +@@ -263,8 +238,7 @@ + { + int i; + +- for(i = 0; i < 86; i++) +- dec->filtbuf[i] = dec->filtbuf[i + 60]; ++ memmove(dec->filtbuf, &dec->filtbuf[60], 86 * sizeof(*dec->filtbuf)); + for(i = 0; i < 60; i++){ + dec->filtbuf[i + 86] = out[i] + dec->newvec[i] - (dec->newvec[i] >> 3); + out[i] += dec->newvec[i]; +@@ -330,65 +304,66 @@ + c->prevfilt[i] = c->cvector[i]; + } + +-static int truespeech_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int truespeech_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + TSContext *c = avctx->priv_data; + + int i, j; +- short *samples = data; +- int consumed = 0; +- int16_t out_buf[240]; +- int iterations; ++ int16_t *samples; ++ int iterations, ret; + +- if (!buf_size) +- return 0; ++ iterations = buf_size / 32; + +- if (buf_size < 32) { ++ if (!iterations) { + av_log(avctx, AV_LOG_ERROR, + "Too small input buffer (%d bytes), need at least 32 bytes\n", buf_size); + return -1; + } +- iterations = FFMIN(buf_size / 32, *data_size / 480); ++ ++ /* get output buffer */ ++ c->frame.nb_samples = iterations * 240; ++ if ((ret = avctx->get_buffer(avctx, &c->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)c->frame.data[0]; ++ ++ memset(samples, 0, iterations * 240 * sizeof(*samples)); ++ + for(j = 0; j < iterations; j++) { +- truespeech_read_frame(c, buf + consumed); +- consumed += 32; ++ truespeech_read_frame(c, buf); ++ buf += 32; + + truespeech_correlate_filter(c); + truespeech_filters_merge(c); + +- memset(out_buf, 0, 240 * 2); + for(i = 0; i < 4; i++) { + truespeech_apply_twopoint_filter(c, i); +- truespeech_place_pulses(c, out_buf + i * 60, i); +- truespeech_update_filters(c, out_buf + i * 60, i); +- truespeech_synth(c, out_buf + i * 60, i); ++ truespeech_place_pulses (c, samples, i); ++ truespeech_update_filters(c, samples, i); ++ truespeech_synth (c, samples, i); ++ samples += 60; + } + + truespeech_save_prevvec(c); +- +- /* finally output decoded frame */ +- for(i = 0; i < 240; i++) +- *samples++ = out_buf[i]; +- + } + +- *data_size = consumed * 15; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = c->frame; + +- return consumed; ++ return buf_size; + } + + AVCodec ff_truespeech_decoder = { +- "truespeech", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_TRUESPEECH, +- sizeof(TSContext), +- truespeech_decode_init, +- NULL, +- NULL, +- truespeech_decode_frame, ++ .name = "truespeech", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_TRUESPEECH, ++ .priv_data_size = sizeof(TSContext), ++ .init = truespeech_decode_init, ++ .decode = truespeech_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("DSP Group TrueSpeech"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tscc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tscc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tscc.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tscc.c 2012-05-14 14:08:54.274338774 +0200 +@@ -60,6 +60,8 @@ + unsigned char* decomp_buf; + int height; + z_stream zstream; ++ ++ uint32_t pal[256]; + } CamtasiaContext; + + /* +@@ -73,23 +75,20 @@ + int buf_size = avpkt->size; + CamtasiaContext * const c = avctx->priv_data; + const unsigned char *encoded = buf; +- unsigned char *outptr; + int zret; // Zlib return code + int len = buf_size; + + if(c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + +- c->pic.reference = 1; ++ c->pic.reference = 3; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; + if(avctx->get_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + +- outptr = c->pic.data[0]; // Output image pointer +- +- zret = inflateReset(&(c->zstream)); ++ zret = inflateReset(&c->zstream); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate reset error: %d\n", zret); + return -1; +@@ -98,7 +97,7 @@ + c->zstream.avail_in = len; + c->zstream.next_out = c->decomp_buf; + c->zstream.avail_out = c->decomp_size; +- zret = inflate(&(c->zstream), Z_FINISH); ++ zret = inflate(&c->zstream, Z_FINISH); + // Z_DATA_ERROR means empty picture + if ((zret != Z_OK) && (zret != Z_STREAM_END) && (zret != Z_DATA_ERROR)) { + av_log(avctx, AV_LOG_ERROR, "Inflate error: %d\n", zret); +@@ -111,11 +110,13 @@ + + /* make the palette available on the way out */ + if (c->avctx->pix_fmt == PIX_FMT_PAL8) { +- memcpy(c->pic.data[1], c->avctx->palctrl->palette, AVPALETTE_SIZE); +- if (c->avctx->palctrl->palette_changed) { ++ const uint8_t *pal = av_packet_get_side_data(avpkt, AV_PKT_DATA_PALETTE, NULL); ++ ++ if (pal) { + c->pic.palette_has_changed = 1; +- c->avctx->palctrl->palette_changed = 0; ++ memcpy(c->pal, pal, AVPALETTE_SIZE); + } ++ memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); + } + + *data_size = sizeof(AVFrame); +@@ -141,8 +142,9 @@ + + c->height = avctx->height; + ++ avcodec_get_frame_defaults(&c->pic); + // Needed if zlib unused or init aborted before inflateInit +- memset(&(c->zstream), 0, sizeof(z_stream)); ++ memset(&c->zstream, 0, sizeof(z_stream)); + switch(avctx->bits_per_coded_sample){ + case 8: avctx->pix_fmt = PIX_FMT_PAL8; break; + case 16: avctx->pix_fmt = PIX_FMT_RGB555; break; +@@ -154,7 +156,7 @@ + return -1; + } + c->bpp = avctx->bits_per_coded_sample; +- // buffer size for RLE 'best' case when 2-byte code preceeds each pixel and there may be padding after it too ++ // buffer size for RLE 'best' case when 2-byte code precedes each pixel and there may be padding after it too + c->decomp_size = (((avctx->width * c->bpp + 7) >> 3) + 3 * avctx->width + 2) * avctx->height + 2; + + /* Allocate decompression buffer */ +@@ -168,7 +170,7 @@ + c->zstream.zalloc = Z_NULL; + c->zstream.zfree = Z_NULL; + c->zstream.opaque = Z_NULL; +- zret = inflateInit(&(c->zstream)); ++ zret = inflateInit(&c->zstream); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return 1; +@@ -192,21 +194,20 @@ + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); +- inflateEnd(&(c->zstream)); ++ inflateEnd(&c->zstream); + + return 0; + } + + AVCodec ff_tscc_decoder = { +- "camtasia", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TSCC, +- sizeof(CamtasiaContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, +- .long_name = NULL_IF_CONFIG_SMALL("TechSmith Screen Capture Codec"), ++ .name = "camtasia", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TSCC, ++ .priv_data_size = sizeof(CamtasiaContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("TechSmith Screen Capture Codec"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tta.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tta.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/tta.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/tta.c 2012-05-14 14:08:54.276338814 +0200 +@@ -22,19 +22,19 @@ + /** + * @file + * TTA (The Lossless True Audio) decoder +- * (www.true-audio.com or tta.corecodec.org) ++ * @see http://www.true-audio.com/ ++ * @see http://tta.corecodec.org/ + * @author Alex Beregszaszi +- * + */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + //#define DEBUG + #include + #include "avcodec.h" + #include "get_bits.h" + +-#define FORMAT_INT 1 +-#define FORMAT_FLOAT 3 ++#define FORMAT_SIMPLE 1 ++#define FORMAT_ENCRYPTED 2 + + #define MAX_ORDER 16 + typedef struct TTAFilter { +@@ -56,9 +56,10 @@ + + typedef struct TTAContext { + AVCodecContext *avctx; ++ AVFrame frame; + GetBitContext gb; + +- int flags, channels, bps, is_float, data_length; ++ int format, channels, bps, data_length; + int frame_length, last_frame_length, total_frames; + + int32_t *decode_buffer; +@@ -66,23 +67,6 @@ + TTAChannel *ch_ctx; + } TTAContext; + +-#if 0 +-static inline int shift_1(int i) +-{ +- if (i < 32) +- return 1 << i; +- else +- return 0x80000000; // 16 << 31 +-} +- +-static inline int shift_16(int i) +-{ +- if (i < 28) +- return 16 << i; +- else +- return 0x80000000; // 16 << 27 +-} +-#else + static const uint32_t shift_1[] = { + 0x00000001, 0x00000002, 0x00000004, 0x00000008, + 0x00000010, 0x00000020, 0x00000040, 0x00000080, +@@ -97,7 +81,6 @@ + }; + + static const uint32_t * const shift_16 = shift_1 + 4; +-#endif + + static const int32_t ttafilter_configs[4][2] = { + {10, 1}, +@@ -200,11 +183,21 @@ + int ret = 0; + + // count ones +- while(get_bits1(gb)) ++ while (get_bits_left(gb) > 0 && get_bits1(gb)) + ret++; + return ret; + } + ++static const int64_t tta_channel_layouts[7] = { ++ AV_CH_LAYOUT_STEREO, ++ AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, ++ AV_CH_LAYOUT_QUAD, ++ 0, ++ AV_CH_LAYOUT_5POINT1_BACK, ++ AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER, ++ AV_CH_LAYOUT_7POINT1_WIDE ++}; ++ + static av_cold int tta_decode_init(AVCodecContext * avctx) + { + TTAContext *s = avctx->priv_data; +@@ -216,60 +209,67 @@ + if (avctx->extradata_size < 30) + return -1; + +- init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size); ++ init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8); + if (show_bits_long(&s->gb, 32) == AV_RL32("TTA1")) + { + /* signature */ + skip_bits(&s->gb, 32); +-// if (get_bits_long(&s->gb, 32) != av_bswap32(AV_RL32("TTA1"))) { +-// av_log(s->avctx, AV_LOG_ERROR, "Missing magic\n"); +-// return -1; +-// } +- +- s->flags = get_bits(&s->gb, 16); +- if (s->flags != 1 && s->flags != 3) +- { +- av_log(s->avctx, AV_LOG_ERROR, "Invalid flags\n"); ++ ++ s->format = get_bits(&s->gb, 16); ++ if (s->format > 2) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid format\n"); + return -1; + } +- s->is_float = (s->flags == FORMAT_FLOAT); ++ if (s->format == FORMAT_ENCRYPTED) { ++ av_log_missing_feature(s->avctx, "Encrypted TTA", 0); ++ return AVERROR(EINVAL); ++ } + avctx->channels = s->channels = get_bits(&s->gb, 16); ++ if (s->channels > 1 && s->channels < 9) ++ avctx->channel_layout = tta_channel_layouts[s->channels-2]; + avctx->bits_per_coded_sample = get_bits(&s->gb, 16); + s->bps = (avctx->bits_per_coded_sample + 7) / 8; + avctx->sample_rate = get_bits_long(&s->gb, 32); +- if(avctx->sample_rate > 1000000){ //prevent FRAME_TIME * avctx->sample_rate from overflowing and sanity check +- av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n"); +- return -1; +- } + s->data_length = get_bits_long(&s->gb, 32); + skip_bits(&s->gb, 32); // CRC32 of header + +- if (s->is_float) +- { +- avctx->sample_fmt = AV_SAMPLE_FMT_FLT; +- av_log(s->avctx, AV_LOG_ERROR, "Unsupported sample format. Please contact the developers.\n"); +- return -1; ++ if (s->channels == 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid number of channels\n"); ++ return AVERROR_INVALIDDATA; ++ } else if (avctx->sample_rate == 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid samplerate\n"); ++ return AVERROR_INVALIDDATA; + } +- else switch(s->bps) { +-// case 1: avctx->sample_fmt = AV_SAMPLE_FMT_U8; break; +- case 2: avctx->sample_fmt = AV_SAMPLE_FMT_S16; break; +-// case 3: avctx->sample_fmt = AV_SAMPLE_FMT_S24; break; +- case 4: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break; +- default: +- av_log(s->avctx, AV_LOG_ERROR, "Invalid/unsupported sample format. Please contact the developers.\n"); +- return -1; ++ ++ switch(s->bps) { ++ case 1: avctx->sample_fmt = AV_SAMPLE_FMT_U8; break; ++ case 2: ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ avctx->bits_per_raw_sample = 16; ++ break; ++ case 3: ++ avctx->sample_fmt = AV_SAMPLE_FMT_S32; ++ avctx->bits_per_raw_sample = 24; ++ break; ++ //case 4: avctx->sample_fmt = AV_SAMPLE_FMT_S32; break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Invalid/unsupported sample format.\n"); ++ return AVERROR_INVALIDDATA; + } + +- // FIXME: horribly broken, but directly from reference source +-#define FRAME_TIME 1.04489795918367346939 +- s->frame_length = (int)(FRAME_TIME * avctx->sample_rate); ++ // prevent overflow ++ if (avctx->sample_rate > 0x7FFFFF) { ++ av_log(avctx, AV_LOG_ERROR, "sample_rate too large\n"); ++ return AVERROR(EINVAL); ++ } ++ s->frame_length = 256 * avctx->sample_rate / 245; + + s->last_frame_length = s->data_length % s->frame_length; + s->total_frames = s->data_length / s->frame_length + + (s->last_frame_length ? 1 : 0); + +- av_log(s->avctx, AV_LOG_DEBUG, "flags: %x chans: %d bps: %d rate: %d block: %d\n", +- s->flags, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate, ++ av_log(s->avctx, AV_LOG_DEBUG, "format: %d chans: %d bps: %d rate: %d block: %d\n", ++ s->format, avctx->channels, avctx->bits_per_coded_sample, avctx->sample_rate, + avctx->block_align); + av_log(s->avctx, AV_LOG_DEBUG, "data_length: %d frame_length: %d last: %d total: %d\n", + s->data_length, s->frame_length, s->last_frame_length, s->total_frames); +@@ -285,185 +285,187 @@ + } + + s->decode_buffer = av_mallocz(sizeof(int32_t)*s->frame_length*s->channels); ++ if (!s->decode_buffer) ++ return AVERROR(ENOMEM); + s->ch_ctx = av_malloc(avctx->channels * sizeof(*s->ch_ctx)); +- if (!s->ch_ctx) ++ if (!s->ch_ctx) { ++ av_freep(&s->decode_buffer); + return AVERROR(ENOMEM); ++ } + } else { + av_log(avctx, AV_LOG_ERROR, "Wrong extradata present\n"); + return -1; + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +-static int tta_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int tta_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + TTAContext *s = avctx->priv_data; +- int i; ++ int i, ret; ++ int cur_chan = 0, framelen = s->frame_length; ++ int32_t *p; + + init_get_bits(&s->gb, buf, buf_size*8); +- { +- int cur_chan = 0, framelen = s->frame_length; +- int32_t *p; + +- if (*data_size < (framelen * s->channels * 2)) { +- av_log(avctx, AV_LOG_ERROR, "Output buffer size is too small.\n"); +- return -1; ++ // FIXME: seeking ++ s->total_frames--; ++ if (!s->total_frames && s->last_frame_length) ++ framelen = s->last_frame_length; ++ ++ /* get output buffer */ ++ s->frame.nb_samples = framelen; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ // decode directly to output buffer for 24-bit sample format ++ if (s->bps == 3) ++ s->decode_buffer = (int32_t *)s->frame.data[0]; ++ ++ // init per channel states ++ for (i = 0; i < s->channels; i++) { ++ s->ch_ctx[i].predictor = 0; ++ ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1][0], ttafilter_configs[s->bps-1][1]); ++ rice_init(&s->ch_ctx[i].rice, 10, 10); ++ } ++ ++ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) { ++ int32_t *predictor = &s->ch_ctx[cur_chan].predictor; ++ TTAFilter *filter = &s->ch_ctx[cur_chan].filter; ++ TTARice *rice = &s->ch_ctx[cur_chan].rice; ++ uint32_t unary, depth, k; ++ int32_t value; ++ ++ unary = tta_get_unary(&s->gb); ++ ++ if (unary == 0) { ++ depth = 0; ++ k = rice->k0; ++ } else { ++ depth = 1; ++ k = rice->k1; ++ unary--; + } +- // FIXME: seeking +- s->total_frames--; +- if (!s->total_frames && s->last_frame_length) +- framelen = s->last_frame_length; +- +- // init per channel states +- for (i = 0; i < s->channels; i++) { +- s->ch_ctx[i].predictor = 0; +- ttafilter_init(&s->ch_ctx[i].filter, ttafilter_configs[s->bps-1][0], ttafilter_configs[s->bps-1][1]); +- rice_init(&s->ch_ctx[i].rice, 10, 10); +- } +- +- for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) { +- int32_t *predictor = &s->ch_ctx[cur_chan].predictor; +- TTAFilter *filter = &s->ch_ctx[cur_chan].filter; +- TTARice *rice = &s->ch_ctx[cur_chan].rice; +- uint32_t unary, depth, k; +- int32_t value; +- +- unary = tta_get_unary(&s->gb); +- +- if (unary == 0) { +- depth = 0; +- k = rice->k0; +- } else { +- depth = 1; +- k = rice->k1; +- unary--; +- } + +- if (get_bits_left(&s->gb) < k) +- return -1; ++ if (get_bits_left(&s->gb) < k) ++ return -1; + +- if (k) { +- if (k > MIN_CACHE_BITS) +- return -1; +- value = (unary << k) + get_bits(&s->gb, k); +- } else +- value = unary; +- +- // FIXME: copy paste from original +- switch (depth) { +- case 1: +- rice->sum1 += value - (rice->sum1 >> 4); +- if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) +- rice->k1--; +- else if(rice->sum1 > shift_16[rice->k1 + 1]) +- rice->k1++; +- value += shift_1[rice->k0]; +- default: +- rice->sum0 += value - (rice->sum0 >> 4); +- if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) +- rice->k0--; +- else if(rice->sum0 > shift_16[rice->k0 + 1]) +- rice->k0++; +- } ++ if (k) { ++ if (k > MIN_CACHE_BITS) ++ return -1; ++ value = (unary << k) + get_bits(&s->gb, k); ++ } else ++ value = unary; ++ ++ // FIXME: copy paste from original ++ switch (depth) { ++ case 1: ++ rice->sum1 += value - (rice->sum1 >> 4); ++ if (rice->k1 > 0 && rice->sum1 < shift_16[rice->k1]) ++ rice->k1--; ++ else if(rice->sum1 > shift_16[rice->k1 + 1]) ++ rice->k1++; ++ value += shift_1[rice->k0]; ++ default: ++ rice->sum0 += value - (rice->sum0 >> 4); ++ if (rice->k0 > 0 && rice->sum0 < shift_16[rice->k0]) ++ rice->k0--; ++ else if(rice->sum0 > shift_16[rice->k0 + 1]) ++ rice->k0++; ++ } + +- // extract coded value ++ // extract coded value + #define UNFOLD(x) (((x)&1) ? (++(x)>>1) : (-(x)>>1)) +- *p = UNFOLD(value); ++ *p = UNFOLD(value); + +- // run hybrid filter +- ttafilter_process(filter, p, 0); ++ // run hybrid filter ++ ttafilter_process(filter, p, 0); + +- // fixed order prediction ++ // fixed order prediction + #define PRED(x, k) (int32_t)((((uint64_t)x << k) - x) >> k) +- switch (s->bps) { +- case 1: *p += PRED(*predictor, 4); break; +- case 2: +- case 3: *p += PRED(*predictor, 5); break; +- case 4: *p += *predictor; break; +- } +- *predictor = *p; +- +-#if 0 +- // extract 32bit float from last two int samples +- if (s->is_float && ((p - data) & 1)) { +- uint32_t neg = *p & 0x80000000; +- uint32_t hi = *(p - 1); +- uint32_t lo = abs(*p) - 1; +- +- hi += (hi || lo) ? 0x3f80 : 0; +- // SWAP16: swap all the 16 bits +- *(p - 1) = (hi << 16) | SWAP16(lo) | neg; +- } +-#endif +- +- /*if ((get_bits_count(&s->gb)+7)/8 > buf_size) +- { +- av_log(NULL, AV_LOG_INFO, "overread!!\n"); +- break; +- }*/ ++ switch (s->bps) { ++ case 1: *p += PRED(*predictor, 4); break; ++ case 2: ++ case 3: *p += PRED(*predictor, 5); break; ++ case 4: *p += *predictor; break; ++ } ++ *predictor = *p; + +- // flip channels +- if (cur_chan < (s->channels-1)) +- cur_chan++; +- else { +- // decorrelate in case of stereo integer +- if (!s->is_float && (s->channels > 1)) { +- int32_t *r = p - 1; +- for (*p += *r / 2; r > p - s->channels; r--) +- *r = *(r + 1) - *r; +- } +- cur_chan = 0; ++ // flip channels ++ if (cur_chan < (s->channels-1)) ++ cur_chan++; ++ else { ++ // decorrelate in case of stereo integer ++ if (s->channels > 1) { ++ int32_t *r = p - 1; ++ for (*p += *r / 2; r > p - s->channels; r--) ++ *r = *(r + 1) - *r; + } ++ cur_chan = 0; + } ++ } + +- if (get_bits_left(&s->gb) < 32) +- return -1; +- skip_bits(&s->gb, 32); // frame crc ++ if (get_bits_left(&s->gb) < 32) ++ return -1; ++ skip_bits(&s->gb, 32); // frame crc + + // convert to output buffer + switch(s->bps) { ++ case 1: { ++ uint8_t *samples = (uint8_t *)s->frame.data[0]; ++ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) ++ *samples++ = *p + 0x80; ++ break; ++ } + case 2: { +- uint16_t *samples = data; +- for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) { +-// *samples++ = (unsigned char)*p; +-// *samples++ = (unsigned char)(*p >> 8); ++ uint16_t *samples = (int16_t *)s->frame.data[0]; ++ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) + *samples++ = *p; +- } +- *data_size = (uint8_t *)samples - (uint8_t *)data; + break; + } +- default: +- av_log(s->avctx, AV_LOG_ERROR, "Error, only 16bit samples supported!\n"); ++ case 3: { ++ // shift samples for 24-bit sample format ++ int32_t *samples = (int32_t *)s->frame.data[0]; ++ for (p = s->decode_buffer; p < s->decode_buffer + (framelen * s->channels); p++) ++ *samples++ <<= 8; ++ // reset decode buffer ++ s->decode_buffer = NULL; ++ break; ++ } + } +- } + +-// return get_bits_count(&s->gb)+7)/8; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return buf_size; + } + + static av_cold int tta_decode_close(AVCodecContext *avctx) { + TTAContext *s = avctx->priv_data; + +- if (s->decode_buffer) +- av_free(s->decode_buffer); ++ av_free(s->decode_buffer); + av_freep(&s->ch_ctx); + + return 0; + } + + AVCodec ff_tta_decoder = { +- "tta", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_TTA, +- sizeof(TTAContext), +- tta_decode_init, +- NULL, +- tta_decode_close, +- tta_decode_frame, ++ .name = "tta", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_TTA, ++ .priv_data_size = sizeof(TTAContext), ++ .init = tta_decode_init, ++ .close = tta_decode_close, ++ .decode = tta_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("True Audio (TTA)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/twinvq.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/twinvq.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/twinvq.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/twinvq.c 2012-05-14 14:08:54.278338854 +0200 +@@ -24,6 +24,7 @@ + #include "dsputil.h" + #include "fft.h" + #include "lsp.h" ++#include "sinewin.h" + + #include + #include +@@ -173,6 +174,7 @@ + + typedef struct TwinContext { + AVCodecContext *avctx; ++ AVFrame frame; + DSPContext dsp; + FFTContext mdct_ctx[3]; + +@@ -194,6 +196,7 @@ + float *curr_frame; ///< non-interleaved output + float *prev_frame; ///< non-interleaved previous frame + int last_block_pos[2]; ++ int discarded_packets; + + float *cos_tabs[3]; + +@@ -233,7 +236,7 @@ + * be a multiple of four. + * @return the LPC value + * +- * @todo reuse code from vorbis_dec.c: vorbis_floor0_decode ++ * @todo reuse code from Vorbis decoder: vorbis_floor0_decode + */ + static float eval_lpc_spectrum(const float *lsp, float cos_val, int order) + { +@@ -410,7 +413,7 @@ + * a*b == 200 and the nearest integer is ill-defined, use a table to emulate + * the following broken float-based implementation used by the binary decoder: + * +- * \code ++ * @code + * static int very_broken_op(int a, int b) + * { + * static float test; // Ugh, force gcc to do the division first... +@@ -418,7 +421,7 @@ + * test = a/400.; + * return b * test + 0.5; + * } +- * \endcode ++ * @endcode + * + * @note if this function is replaced by just ROUNDED_DIV(a*b,400.), the stddev + * between the original file (before encoding with Yamaha encoder) and the +@@ -608,6 +611,7 @@ + static void imdct_and_window(TwinContext *tctx, enum FrameType ftype, int wtype, + float *in, float *prev, int ch) + { ++ FFTContext *mdct = &tctx->mdct_ctx[ftype]; + const ModeTab *mtab = tctx->mtab; + int bsize = mtab->size / mtab->fmode[ftype].sub; + int size = mtab->size; +@@ -640,7 +644,7 @@ + + wsize = types_sizes[wtype_to_wsize[sub_wtype]]; + +- ff_imdct_half(&tctx->mdct_ctx[ftype], buf1 + bsize*j, in + bsize*j); ++ mdct->imdct_half(mdct, buf1 + bsize*j, in + bsize*j); + + tctx->dsp.vector_fmul_window(out2, + prev_buf + (bsize-wsize)/2, +@@ -663,8 +667,9 @@ + float *out) + { + const ModeTab *mtab = tctx->mtab; ++ int size1, size2; + float *prev_buf = tctx->prev_frame + tctx->last_block_pos[0]; +- int i, j; ++ int i; + + for (i = 0; i < tctx->avctx->channels; i++) { + imdct_and_window(tctx, ftype, wtype, +@@ -673,27 +678,27 @@ + i); + } + ++ if (!out) ++ return; ++ ++ size2 = tctx->last_block_pos[0]; ++ size1 = mtab->size - size2; + if (tctx->avctx->channels == 2) { +- for (i = 0; i < mtab->size - tctx->last_block_pos[0]; i++) { +- float f1 = prev_buf[ i]; +- float f2 = prev_buf[2*mtab->size + i]; +- out[2*i ] = f1 + f2; +- out[2*i + 1] = f1 - f2; +- } +- for (j = 0; i < mtab->size; j++,i++) { +- float f1 = tctx->curr_frame[ j]; +- float f2 = tctx->curr_frame[2*mtab->size + j]; +- out[2*i ] = f1 + f2; +- out[2*i + 1] = f1 - f2; +- } ++ tctx->dsp.butterflies_float_interleave(out, prev_buf, ++ &prev_buf[2*mtab->size], ++ size1); ++ ++ out += 2 * size1; ++ ++ tctx->dsp.butterflies_float_interleave(out, tctx->curr_frame, ++ &tctx->curr_frame[2*mtab->size], ++ size2); + } else { +- memcpy(out, prev_buf, +- (mtab->size - tctx->last_block_pos[0]) * sizeof(*out)); ++ memcpy(out, prev_buf, size1 * sizeof(*out)); + +- out += mtab->size - tctx->last_block_pos[0]; ++ out += size1; + +- memcpy(out, tctx->curr_frame, +- (tctx->last_block_pos[0]) * sizeof(*out)); ++ memcpy(out, tctx->curr_frame, size2 * sizeof(*out)); + } + + } +@@ -811,16 +816,16 @@ + } + + static int twin_decode_frame(AVCodecContext * avctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + TwinContext *tctx = avctx->priv_data; + GetBitContext gb; + const ModeTab *mtab = tctx->mtab; +- float *out = data; ++ float *out = NULL; + enum FrameType ftype; +- int window_type; ++ int window_type, ret; + static const enum FrameType wtype_to_ftype_table[] = { + FT_LONG, FT_LONG, FT_SHORT, FT_LONG, + FT_MEDIUM, FT_LONG, FT_LONG, FT_MEDIUM, FT_MEDIUM +@@ -829,8 +834,17 @@ + if (buf_size*8 < avctx->bit_rate*mtab->size/avctx->sample_rate + 8) { + av_log(avctx, AV_LOG_ERROR, + "Frame too small (%d bytes). Truncated file?\n", buf_size); +- *data_size = 0; +- return buf_size; ++ return AVERROR(EINVAL); ++ } ++ ++ /* get output buffer */ ++ if (tctx->discarded_packets >= 2) { ++ tctx->frame.nb_samples = mtab->size; ++ if ((ret = avctx->get_buffer(avctx, &tctx->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ out = (float *)tctx->frame.data[0]; + } + + init_get_bits(&gb, buf, buf_size * 8); +@@ -850,12 +864,14 @@ + + FFSWAP(float*, tctx->curr_frame, tctx->prev_frame); + +- if (tctx->avctx->frame_number < 2) { +- *data_size=0; ++ if (tctx->discarded_packets < 2) { ++ tctx->discarded_packets++; ++ *got_frame_ptr = 0; + return buf_size; + } + +- *data_size = mtab->size*avctx->channels*4; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = tctx->frame; + + return buf_size; + } +@@ -863,9 +879,9 @@ + /** + * Init IMDCT and windowing tables + */ +-static av_cold void init_mdct_win(TwinContext *tctx) ++static av_cold int init_mdct_win(TwinContext *tctx) + { +- int i,j; ++ int i, j, ret; + const ModeTab *mtab = tctx->mtab; + int size_s = mtab->size / mtab->fmode[FT_SHORT].sub; + int size_m = mtab->size / mtab->fmode[FT_MEDIUM].sub; +@@ -874,20 +890,29 @@ + + for (i = 0; i < 3; i++) { + int bsize = tctx->mtab->size/tctx->mtab->fmode[i].sub; +- ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1, +- -sqrt(norm/bsize) / (1<<15)); +- } +- +- tctx->tmp_buf = av_malloc(mtab->size * sizeof(*tctx->tmp_buf)); +- +- tctx->spectrum = av_malloc(2*mtab->size*channels*sizeof(float)); +- tctx->curr_frame = av_malloc(2*mtab->size*channels*sizeof(float)); +- tctx->prev_frame = av_malloc(2*mtab->size*channels*sizeof(float)); ++ if ((ret = ff_mdct_init(&tctx->mdct_ctx[i], av_log2(bsize) + 1, 1, ++ -sqrt(norm/bsize) / (1<<15)))) ++ return ret; ++ } ++ ++ FF_ALLOC_OR_GOTO(tctx->avctx, tctx->tmp_buf, ++ mtab->size * sizeof(*tctx->tmp_buf), alloc_fail); ++ ++ FF_ALLOC_OR_GOTO(tctx->avctx, tctx->spectrum, ++ 2 * mtab->size * channels * sizeof(*tctx->spectrum), ++ alloc_fail); ++ FF_ALLOC_OR_GOTO(tctx->avctx, tctx->curr_frame, ++ 2 * mtab->size * channels * sizeof(*tctx->curr_frame), ++ alloc_fail); ++ FF_ALLOC_OR_GOTO(tctx->avctx, tctx->prev_frame, ++ 2 * mtab->size * channels * sizeof(*tctx->prev_frame), ++ alloc_fail); + + for (i = 0; i < 3; i++) { + int m = 4*mtab->size/mtab->fmode[i].sub; + double freq = 2*M_PI/m; +- tctx->cos_tabs[i] = av_malloc((m/4)*sizeof(*tctx->cos_tabs)); ++ FF_ALLOC_OR_GOTO(tctx->avctx, tctx->cos_tabs[i], ++ (m / 4) * sizeof(*tctx->cos_tabs[i]), alloc_fail); + + for (j = 0; j <= m/8; j++) + tctx->cos_tabs[i][j] = cos((2*j + 1)*freq); +@@ -899,6 +924,10 @@ + ff_init_ff_sine_windows(av_log2(size_m)); + ff_init_ff_sine_windows(av_log2(size_s/2)); + ff_init_ff_sine_windows(av_log2(mtab->size)); ++ ++ return 0; ++alloc_fail: ++ return AVERROR(ENOMEM); + } + + /** +@@ -936,14 +965,14 @@ + /** + * Interpret the input data as in the following table: + * +- * \verbatim ++ * @verbatim + * + * abcdefgh + * ijklmnop + * qrstuvw + * x123456 + * +- * \endverbatim ++ * @endverbatim + * + * and transpose it, giving the output + * aiqxbjr1cks2dlt3emu4fvn5gow6hp +@@ -1060,20 +1089,54 @@ + construct_perm_table(tctx, frametype); + } + ++static av_cold int twin_decode_close(AVCodecContext *avctx) ++{ ++ TwinContext *tctx = avctx->priv_data; ++ int i; ++ ++ for (i = 0; i < 3; i++) { ++ ff_mdct_end(&tctx->mdct_ctx[i]); ++ av_free(tctx->cos_tabs[i]); ++ } ++ ++ ++ av_free(tctx->curr_frame); ++ av_free(tctx->spectrum); ++ av_free(tctx->prev_frame); ++ av_free(tctx->tmp_buf); ++ ++ return 0; ++} ++ + static av_cold int twin_decode_init(AVCodecContext *avctx) + { ++ int ret; + TwinContext *tctx = avctx->priv_data; +- int isampf = avctx->sample_rate/1000; +- int ibps = avctx->bit_rate/(1000 * avctx->channels); ++ int isampf, ibps; + + tctx->avctx = avctx; + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; + ++ if (!avctx->extradata || avctx->extradata_size < 12) { ++ av_log(avctx, AV_LOG_ERROR, "Missing or incomplete extradata\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ avctx->channels = AV_RB32(avctx->extradata ) + 1; ++ avctx->bit_rate = AV_RB32(avctx->extradata + 4) * 1000; ++ isampf = AV_RB32(avctx->extradata + 8); ++ switch (isampf) { ++ case 44: avctx->sample_rate = 44100; break; ++ case 22: avctx->sample_rate = 22050; break; ++ case 11: avctx->sample_rate = 11025; break; ++ default: avctx->sample_rate = isampf * 1000; break; ++ } ++ + if (avctx->channels > CHANNELS_MAX) { + av_log(avctx, AV_LOG_ERROR, "Unsupported number of channels: %i\n", + avctx->channels); + return -1; + } ++ ibps = avctx->bit_rate / (1000 * avctx->channels); + + switch ((isampf << 8) + ibps) { + case (8 <<8) + 8: tctx->mtab = &mode_08_08; break; +@@ -1091,42 +1154,29 @@ + } + + dsputil_init(&tctx->dsp, avctx); +- init_mdct_win(tctx); ++ if ((ret = init_mdct_win(tctx))) { ++ av_log(avctx, AV_LOG_ERROR, "Error initializing MDCT\n"); ++ twin_decode_close(avctx); ++ return ret; ++ } + init_bitstream_params(tctx); + + memset_float(tctx->bark_hist[0][0], 0.1, FF_ARRAY_ELEMS(tctx->bark_hist)); + +- return 0; +-} +- +-static av_cold int twin_decode_close(AVCodecContext *avctx) +-{ +- TwinContext *tctx = avctx->priv_data; +- int i; +- +- for (i = 0; i < 3; i++) { +- ff_mdct_end(&tctx->mdct_ctx[i]); +- av_free(tctx->cos_tabs[i]); +- } +- +- +- av_free(tctx->curr_frame); +- av_free(tctx->spectrum); +- av_free(tctx->prev_frame); +- av_free(tctx->tmp_buf); ++ avcodec_get_frame_defaults(&tctx->frame); ++ avctx->coded_frame = &tctx->frame; + + return 0; + } + +-AVCodec ff_twinvq_decoder = +-{ +- "twinvq", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_TWINVQ, +- sizeof(TwinContext), +- twin_decode_init, +- NULL, +- twin_decode_close, +- twin_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"), ++AVCodec ff_twinvq_decoder = { ++ .name = "twinvq", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_TWINVQ, ++ .priv_data_size = sizeof(TwinContext), ++ .init = twin_decode_init, ++ .close = twin_decode_close, ++ .decode = twin_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("VQF TwinVQ"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/txd.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/txd.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/txd.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/txd.c 2012-05-14 14:08:54.279338874 +0200 +@@ -22,7 +22,8 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "bytestream.h" + #include "avcodec.h" + #include "s3tc.h" + +@@ -42,6 +43,7 @@ + static int txd_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) { + const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end = avpkt->data + avpkt->size; + TXDContext * const s = avctx->priv_data; + AVFrame *picture = data; + AVFrame * const p = &s->picture; +@@ -52,6 +54,8 @@ + const uint32_t *palette = (const uint32_t *)(cur + 88); + uint32_t *pal; + ++ if (buf_end - cur < 92) ++ return AVERROR_INVALIDDATA; + version = AV_RL32(cur); + d3d_format = AV_RL32(cur+76); + w = AV_RL16(cur+80); +@@ -69,6 +73,8 @@ + + if (depth == 8) { + avctx->pix_fmt = PIX_FMT_PAL8; ++ if (buf_end - cur < 1024) ++ return AVERROR_INVALIDDATA; + cur += 1024; + } else if (depth == 16 || depth == 32) + avctx->pix_fmt = PIX_FMT_RGB32; +@@ -89,7 +95,7 @@ + return -1; + } + +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + + ptr = p->data[0]; + stride = p->linesize[0]; +@@ -100,6 +106,8 @@ + v = AV_RB32(palette+y); + pal[y] = (v>>8) + (v<<24); + } ++ if (buf_end - cur < w * h) ++ return AVERROR_INVALIDDATA; + for (y=0; y 1; mipmap_count--) +- cur += AV_RL32(cur) + 4; ++ for (; mipmap_count > 1 && buf_end - cur >= 4; mipmap_count--) { ++ uint32_t length = bytestream_get_le32(&cur); ++ if (buf_end - cur < length) ++ break; ++ cur += length; ++ } + + *picture = s->picture; + *data_size = sizeof(AVPicture); +@@ -156,15 +175,13 @@ + } + + AVCodec ff_txd_decoder = { +- "txd", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_TXD, +- sizeof(TXDContext), +- txd_init, +- NULL, +- txd_end, +- txd_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "txd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_TXD, ++ .priv_data_size = sizeof(TXDContext), ++ .init = txd_init, ++ .close = txd_end, ++ .decode = txd_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Renderware TXD (TeXture Dictionary) image"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ulti.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ulti.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ulti.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ulti.c 2012-05-14 14:08:54.280338895 +0200 +@@ -38,6 +38,7 @@ + int width, height, blocks; + AVFrame frame; + const uint8_t *ulti_codebook; ++ GetByteContext gb; + } UltimotionDecodeContext; + + static av_cold int ulti_decode_init(AVCodecContext *avctx) +@@ -49,6 +50,7 @@ + s->height = avctx->height; + s->blocks = (s->width / 8) * (s->height / 8); + avctx->pix_fmt = PIX_FMT_YUV410P; ++ avcodec_get_frame_defaults(&s->frame); + avctx->coded_frame = (AVFrame*) &s->frame; + s->ulti_codebook = ulti_codebook; + +@@ -224,26 +226,27 @@ + int skip; + int tmp; + +- if(s->frame.data[0]) +- avctx->release_buffer(avctx, &s->frame); +- +- s->frame.reference = 1; ++ s->frame.reference = 3; + s->frame.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; +- if(avctx->get_buffer(avctx, &s->frame) < 0) { +- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ if (avctx->reget_buffer(avctx, &s->frame) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); + return -1; + } + ++ bytestream2_init(&s->gb, buf, buf_size); ++ + while(!done) { + int idx; + if(blocks >= s->blocks || y >= s->height) + break;//all blocks decoded + +- idx = *buf++; ++ if (bytestream2_get_bytes_left(&s->gb) < 1) ++ goto err; ++ idx = bytestream2_get_byteu(&s->gb); + if((idx & 0xF8) == 0x70) { + switch(idx) { + case 0x70: //change modifier +- modifier = *buf++; ++ modifier = bytestream2_get_byte(&s->gb); + if(modifier>1) + av_log(avctx, AV_LOG_INFO, "warning: modifier must be 0 or 1, got %i\n", modifier); + break; +@@ -257,7 +260,7 @@ + done = 1; + break; + case 0x74: //skip some blocks +- skip = *buf++; ++ skip = bytestream2_get_byte(&s->gb); + if ((blocks + skip) >= s->blocks) + break; + blocks += skip; +@@ -283,20 +286,22 @@ + chroma = 0; + } else { + cf = 0; +- if (idx) +- chroma = *buf++; ++ if (idx) { ++ chroma = bytestream2_get_byte(&s->gb); ++ } + } + for (i = 0; i < 4; i++) { // for every subblock + code = (idx >> (6 - i*2)) & 3; //extract 2 bits + if(!code) //skip subblock + continue; +- if(cf) +- chroma = *buf++; ++ if(cf) { ++ chroma = bytestream2_get_byte(&s->gb); ++ } + tx = x + block_coords[i * 2]; + ty = y + block_coords[(i * 2) + 1]; + switch(code) { + case 1: +- tmp = *buf++; ++ tmp = bytestream2_get_byte(&s->gb); + + angle = angle_by_index[(tmp >> 6) & 0x3]; + +@@ -316,7 +321,7 @@ + + case 2: + if (modifier) { // unpack four luma samples +- tmp = bytestream_get_be24(&buf); ++ tmp = bytestream2_get_be24(&s->gb); + + Y[0] = (tmp >> 18) & 0x3F; + Y[1] = (tmp >> 12) & 0x3F; +@@ -324,7 +329,7 @@ + Y[3] = tmp & 0x3F; + angle = 16; + } else { // retrieve luma samples from codebook +- tmp = bytestream_get_be16(&buf); ++ tmp = bytestream2_get_be16(&s->gb); + + angle = (tmp >> 12) & 0xF; + tmp &= 0xFFF; +@@ -340,25 +345,27 @@ + if (modifier) { // all 16 luma samples + uint8_t Luma[16]; + +- tmp = bytestream_get_be24(&buf); ++ if (bytestream2_get_bytes_left(&s->gb) < 12) ++ goto err; ++ tmp = bytestream2_get_be24u(&s->gb); + Luma[0] = (tmp >> 18) & 0x3F; + Luma[1] = (tmp >> 12) & 0x3F; + Luma[2] = (tmp >> 6) & 0x3F; + Luma[3] = tmp & 0x3F; + +- tmp = bytestream_get_be24(&buf); ++ tmp = bytestream2_get_be24u(&s->gb); + Luma[4] = (tmp >> 18) & 0x3F; + Luma[5] = (tmp >> 12) & 0x3F; + Luma[6] = (tmp >> 6) & 0x3F; + Luma[7] = tmp & 0x3F; + +- tmp = bytestream_get_be24(&buf); ++ tmp = bytestream2_get_be24u(&s->gb); + Luma[8] = (tmp >> 18) & 0x3F; + Luma[9] = (tmp >> 12) & 0x3F; + Luma[10] = (tmp >> 6) & 0x3F; + Luma[11] = tmp & 0x3F; + +- tmp = bytestream_get_be24(&buf); ++ tmp = bytestream2_get_be24u(&s->gb); + Luma[12] = (tmp >> 18) & 0x3F; + Luma[13] = (tmp >> 12) & 0x3F; + Luma[14] = (tmp >> 6) & 0x3F; +@@ -366,21 +373,23 @@ + + ulti_convert_yuv(&s->frame, tx, ty, Luma, chroma); + } else { +- tmp = *buf++; ++ if (bytestream2_get_bytes_left(&s->gb) < 4) ++ goto err; ++ tmp = bytestream2_get_byteu(&s->gb); + if(tmp & 0x80) { + angle = (tmp >> 4) & 0x7; +- tmp = (tmp << 8) + *buf++; ++ tmp = (tmp << 8) + bytestream2_get_byteu(&s->gb); + Y[0] = (tmp >> 6) & 0x3F; + Y[1] = tmp & 0x3F; +- Y[2] = (*buf++) & 0x3F; +- Y[3] = (*buf++) & 0x3F; ++ Y[2] = bytestream2_get_byteu(&s->gb) & 0x3F; ++ Y[3] = bytestream2_get_byteu(&s->gb) & 0x3F; + ulti_grad(&s->frame, tx, ty, Y, chroma, angle); //draw block + } else { // some patterns + int f0, f1; +- f0 = *buf++; ++ f0 = bytestream2_get_byteu(&s->gb); + f1 = tmp; +- Y[0] = (*buf++) & 0x3F; +- Y[1] = (*buf++) & 0x3F; ++ Y[0] = bytestream2_get_byteu(&s->gb) & 0x3F; ++ Y[1] = bytestream2_get_byteu(&s->gb) & 0x3F; + ulti_pattern(&s->frame, tx, ty, f1, f0, Y[0], Y[1], chroma); + } + } +@@ -402,19 +411,22 @@ + *(AVFrame*)data= s->frame; + + return buf_size; ++ ++err: ++ av_log(avctx, AV_LOG_ERROR, ++ "Insufficient data\n"); ++ return AVERROR_INVALIDDATA; + } + + AVCodec ff_ulti_decoder = { +- "ultimotion", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ULTI, +- sizeof(UltimotionDecodeContext), +- ulti_decode_init, +- NULL, +- ulti_decode_end, +- ulti_decode_frame, +- CODEC_CAP_DR1, +- NULL, ++ .name = "ultimotion", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ULTI, ++ .priv_data_size = sizeof(UltimotionDecodeContext), ++ .init = ulti_decode_init, ++ .close = ulti_decode_end, ++ .decode = ulti_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("IBM UltiMotion"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/utils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/utils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/utils.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/utils.c 2012-05-14 14:08:54.286339016 +0200 +@@ -25,20 +25,24 @@ + * utils. + */ + ++#include "libavutil/avassert.h" + #include "libavutil/avstring.h" +-#include "libavutil/integer.h" + #include "libavutil/crc.h" ++#include "libavutil/mathematics.h" + #include "libavutil/pixdesc.h" +-#include "libavcore/audioconvert.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/internal.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/samplefmt.h" ++#include "libavutil/dict.h" ++#include "libavutil/avassert.h" + #include "avcodec.h" + #include "dsputil.h" + #include "libavutil/opt.h" + #include "imgconvert.h" ++#include "thread.h" + #include "audioconvert.h" + #include "internal.h" ++#include "bytestream.h" + #include + #include + #include +@@ -47,8 +51,9 @@ + static int volatile entangled_thread_counter=0; + static int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op); + static void *codec_mutex; ++static void *avformat_mutex; + +-void *av_fast_realloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size) ++void *av_fast_realloc(void *ptr, unsigned int *size, size_t min_size) + { + if(min_size < *size) + return ptr; +@@ -64,16 +69,34 @@ + return ptr; + } + +-void av_fast_malloc(void *ptr, unsigned int *size, FF_INTERNALC_MEM_TYPE min_size) ++static inline int ff_fast_malloc(void *ptr, unsigned int *size, size_t min_size, int zero_realloc) + { + void **p = ptr; + if (min_size < *size) +- return; ++ return 0; + min_size= FFMAX(17*min_size/16 + 32, min_size); + av_free(*p); +- *p = av_malloc(min_size); ++ *p = zero_realloc ? av_mallocz(min_size) : av_malloc(min_size); + if (!*p) min_size = 0; + *size= min_size; ++ return 1; ++} ++ ++void av_fast_malloc(void *ptr, unsigned int *size, size_t min_size) ++{ ++ ff_fast_malloc(ptr, size, min_size, 0); ++} ++ ++void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size) ++{ ++ uint8_t **p = ptr; ++ if (min_size > SIZE_MAX - FF_INPUT_BUFFER_PADDING_SIZE) { ++ *p = NULL; ++ *size = 0; ++ return; ++ } ++ if (!ff_fast_malloc(p, size, min_size + FF_INPUT_BUFFER_PADDING_SIZE, 1)) ++ memset(*p + min_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + } + + /* encoder management */ +@@ -84,6 +107,30 @@ + else return first_avcodec; + } + ++#if !FF_API_AVCODEC_INIT ++static ++#endif ++void avcodec_init(void) ++{ ++ static int initialized = 0; ++ ++ if (initialized != 0) ++ return; ++ initialized = 1; ++ ++ dsputil_static_init(); ++} ++ ++static av_always_inline int codec_is_encoder(AVCodec *codec) ++{ ++ return codec && (codec->encode || codec->encode2); ++} ++ ++static av_always_inline int codec_is_decoder(AVCodec *codec) ++{ ++ return codec && codec->decode; ++} ++ + void avcodec_register(AVCodec *codec) + { + AVCodec **p; +@@ -92,14 +139,10 @@ + while (*p != NULL) p = &(*p)->next; + *p = codec; + codec->next = NULL; +-} + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-void register_avcodec(AVCodec *codec) +-{ +- avcodec_register(codec); ++ if (codec->init_static_data) ++ codec->init_static_data(codec); + } +-#endif + + unsigned avcodec_get_edge_width(void) + { +@@ -113,18 +156,12 @@ + s->height= -((-height)>>s->lowres); + } + +-typedef struct InternalBuffer{ +- int last_pic_num; +- uint8_t *base[4]; +- uint8_t *data[4]; +- int linesize[4]; +- int width, height; +- enum PixelFormat pix_fmt; +-}InternalBuffer; +- +-#define INTERNAL_BUFFER_SIZE 32 ++#define INTERNAL_BUFFER_SIZE (32+1) + +-void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){ ++void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, ++ int linesize_align[AV_NUM_DATA_POINTERS]) ++{ ++ int i; + int w_align= 1; + int h_align= 1; + +@@ -135,6 +172,7 @@ + case PIX_FMT_YUV422P: + case PIX_FMT_YUV440P: + case PIX_FMT_YUV444P: ++ case PIX_FMT_GBRP: + case PIX_FMT_GRAY8: + case PIX_FMT_GRAY16BE: + case PIX_FMT_GRAY16LE: +@@ -143,10 +181,24 @@ + case PIX_FMT_YUVJ440P: + case PIX_FMT_YUVJ444P: + case PIX_FMT_YUVA420P: +- w_align= 16; //FIXME check for non mpeg style codecs and use less alignment +- h_align= 16; +- if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP || s->codec_id == CODEC_ID_H264) +- h_align= 32; // interlaced is rounded up to 2 MBs ++ case PIX_FMT_YUV420P9LE: ++ case PIX_FMT_YUV420P9BE: ++ case PIX_FMT_YUV420P10LE: ++ case PIX_FMT_YUV420P10BE: ++ case PIX_FMT_YUV422P9LE: ++ case PIX_FMT_YUV422P9BE: ++ case PIX_FMT_YUV422P10LE: ++ case PIX_FMT_YUV422P10BE: ++ case PIX_FMT_YUV444P9LE: ++ case PIX_FMT_YUV444P9BE: ++ case PIX_FMT_YUV444P10LE: ++ case PIX_FMT_YUV444P10BE: ++ case PIX_FMT_GBRP9LE: ++ case PIX_FMT_GBRP9BE: ++ case PIX_FMT_GBRP10LE: ++ case PIX_FMT_GBRP10BE: ++ w_align = 16; //FIXME assume 16 pixel per macroblock ++ h_align = 16 * 2; // interlaced needs 2 macroblocks height + break; + case PIX_FMT_YUV411P: + case PIX_FMT_UYYVYY411: +@@ -183,16 +235,18 @@ + break; + } + ++ if(s->codec_id == CODEC_ID_IFF_ILBM || s->codec_id == CODEC_ID_IFF_BYTERUN1){ ++ w_align= FFMAX(w_align, 8); ++ } ++ + *width = FFALIGN(*width , w_align); + *height= FFALIGN(*height, h_align); + if(s->codec_id == CODEC_ID_H264 || s->lowres) + *height+=2; // some of the optimized chroma MC reads one line too much + // which is also done in mpeg decoders with lowres > 0 + +- linesize_align[0] = +- linesize_align[1] = +- linesize_align[2] = +- linesize_align[3] = STRIDE_ALIGN; ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) ++ linesize_align[i] = STRIDE_ALIGN; + //STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes + //we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the + //picture size unneccessarily in some cases. The solution here is not +@@ -200,17 +254,16 @@ + #if HAVE_MMX + if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 || + s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F || +- s->codec_id == CODEC_ID_VP6A) { +- linesize_align[0] = +- linesize_align[1] = +- linesize_align[2] = 16; ++ s->codec_id == CODEC_ID_VP6A || s->codec_id == CODEC_ID_DIRAC) { ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) ++ linesize_align[i] = 16; + } + #endif + } + + void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ + int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w; +- int linesize_align[4]; ++ int linesize_align[AV_NUM_DATA_POINTERS]; + int align; + avcodec_align_dimensions2(s, width, height, linesize_align); + align = FFMAX(linesize_align[0], linesize_align[3]); +@@ -220,63 +273,191 @@ + *width=FFALIGN(*width, align); + } + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ +- return av_image_check_size(w, h, 0, av_log_ctx); ++void ff_init_buffer_info(AVCodecContext *s, AVFrame *pic) ++{ ++ if (s->pkt) { ++ pic->pkt_pts = s->pkt->pts; ++ pic->pkt_pos = s->pkt->pos; ++ } else { ++ pic->pkt_pts = AV_NOPTS_VALUE; ++ pic->pkt_pos = -1; ++ } ++ pic->reordered_opaque= s->reordered_opaque; ++ pic->sample_aspect_ratio = s->sample_aspect_ratio; ++ pic->width = s->width; ++ pic->height = s->height; ++ pic->format = s->pix_fmt; ++} ++ ++int avcodec_fill_audio_frame(AVFrame *frame, int nb_channels, ++ enum AVSampleFormat sample_fmt, const uint8_t *buf, ++ int buf_size, int align) ++{ ++ int ch, planar, needed_size, ret = 0; ++ ++ needed_size = av_samples_get_buffer_size(NULL, nb_channels, ++ frame->nb_samples, sample_fmt, ++ align); ++ if (buf_size < needed_size) ++ return AVERROR(EINVAL); ++ ++ planar = av_sample_fmt_is_planar(sample_fmt); ++ if (planar && nb_channels > AV_NUM_DATA_POINTERS) { ++ if (!(frame->extended_data = av_mallocz(nb_channels * ++ sizeof(*frame->extended_data)))) ++ return AVERROR(ENOMEM); ++ } else { ++ frame->extended_data = frame->data; ++ } ++ ++ if ((ret = av_samples_fill_arrays(frame->extended_data, &frame->linesize[0], ++ buf, nb_channels, frame->nb_samples, ++ sample_fmt, align)) < 0) { ++ if (frame->extended_data != frame->data) ++ av_freep(&frame->extended_data); ++ return ret; ++ } ++ if (frame->extended_data != frame->data) { ++ for (ch = 0; ch < AV_NUM_DATA_POINTERS; ch++) ++ frame->data[ch] = frame->extended_data[ch]; ++ } ++ ++ return ret; ++} ++ ++static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) ++{ ++ AVCodecInternal *avci = avctx->internal; ++ InternalBuffer *buf; ++ int buf_size, ret; ++ ++ buf_size = av_samples_get_buffer_size(NULL, avctx->channels, ++ frame->nb_samples, avctx->sample_fmt, ++ 32); ++ if (buf_size < 0) ++ return AVERROR(EINVAL); ++ ++ /* allocate InternalBuffer if needed */ ++ if (!avci->buffer) { ++ avci->buffer = av_mallocz(sizeof(InternalBuffer)); ++ if (!avci->buffer) ++ return AVERROR(ENOMEM); ++ } ++ buf = avci->buffer; ++ ++ /* if there is a previously-used internal buffer, check its size and ++ channel count to see if we can reuse it */ ++ if (buf->extended_data) { ++ /* if current buffer is too small, free it */ ++ if (buf->extended_data[0] && buf_size > buf->audio_data_size) { ++ av_free(buf->extended_data[0]); ++ if (buf->extended_data != buf->data) ++ av_freep(&buf->extended_data); ++ buf->extended_data = NULL; ++ buf->data[0] = NULL; ++ } ++ /* if number of channels has changed, reset and/or free extended data ++ pointers but leave data buffer in buf->data[0] for reuse */ ++ if (buf->nb_channels != avctx->channels) { ++ if (buf->extended_data != buf->data) ++ av_free(buf->extended_data); ++ buf->extended_data = NULL; ++ } ++ } ++ ++ /* if there is no previous buffer or the previous buffer cannot be used ++ as-is, allocate a new buffer and/or rearrange the channel pointers */ ++ if (!buf->extended_data) { ++ if (!buf->data[0]) { ++ if (!(buf->data[0] = av_mallocz(buf_size))) ++ return AVERROR(ENOMEM); ++ buf->audio_data_size = buf_size; ++ } ++ if ((ret = avcodec_fill_audio_frame(frame, avctx->channels, ++ avctx->sample_fmt, buf->data[0], ++ buf->audio_data_size, 32))) ++ return ret; ++ ++ if (frame->extended_data == frame->data) ++ buf->extended_data = buf->data; ++ else ++ buf->extended_data = frame->extended_data; ++ memcpy(buf->data, frame->data, sizeof(frame->data)); ++ buf->linesize[0] = frame->linesize[0]; ++ buf->nb_channels = avctx->channels; ++ } else { ++ /* copy InternalBuffer info to the AVFrame */ ++ frame->extended_data = buf->extended_data; ++ frame->linesize[0] = buf->linesize[0]; ++ memcpy(frame->data, buf->data, sizeof(frame->data)); ++ } ++ ++ frame->type = FF_BUFFER_TYPE_INTERNAL; ++ ++ if (avctx->pkt) { ++ frame->pkt_pts = avctx->pkt->pts; ++ frame->pkt_pos = avctx->pkt->pos; ++ } else { ++ frame->pkt_pts = AV_NOPTS_VALUE; ++ frame->pkt_pos = -1; ++ } ++ ++ frame->reordered_opaque = avctx->reordered_opaque; ++ ++ if (avctx->debug & FF_DEBUG_BUFFERS) ++ av_log(avctx, AV_LOG_DEBUG, "default_get_buffer called on frame %p, " ++ "internal audio buffer used\n", frame); ++ ++ return 0; + } +-#endif + +-int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ ++static int video_get_buffer(AVCodecContext *s, AVFrame *pic) ++{ + int i; + int w= s->width; + int h= s->height; + InternalBuffer *buf; +- int *picture_number; ++ AVCodecInternal *avci = s->internal; + + if(pic->data[0]!=NULL) { + av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n"); + return -1; + } +- if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) { +- av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n"); ++ if(avci->buffer_count >= INTERNAL_BUFFER_SIZE) { ++ av_log(s, AV_LOG_ERROR, "buffer_count overflow (missing release_buffer?)\n"); + return -1; + } + + if(av_image_check_size(w, h, 0, s)) + return -1; + +- if(s->internal_buffer==NULL){ +- s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer)); ++ if (!avci->buffer) { ++ avci->buffer = av_mallocz((INTERNAL_BUFFER_SIZE+1) * ++ sizeof(InternalBuffer)); + } +-#if 0 +- s->internal_buffer= av_fast_realloc( +- s->internal_buffer, +- &s->internal_buffer_size, +- sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ +- ); +-#endif + +- buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; +- picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack +- (*picture_number)++; ++ buf = &avci->buffer[avci->buffer_count]; + + if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){ +- for(i=0; i<4; i++){ ++ if(s->active_thread_type&FF_THREAD_FRAME) { ++ av_log_missing_feature(s, "Width/height changing with frame threads is", 0); ++ return -1; ++ } ++ ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { + av_freep(&buf->base[i]); + buf->data[i]= NULL; + } + } + +- if(buf->base[0]){ +- pic->age= *picture_number - buf->last_pic_num; +- buf->last_pic_num= *picture_number; +- }else{ ++ if (!buf->base[0]) { + int h_chroma_shift, v_chroma_shift; + int size[4] = {0}; + int tmpsize; + int unaligned; + AVPicture picture; +- int stride_align[4]; ++ int stride_align[AV_NUM_DATA_POINTERS]; ++ const int pixel_size = av_pix_fmt_descriptors[s->pix_fmt].comp[0].step_minus1+1; + + avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); + +@@ -308,7 +489,6 @@ + size[i] = picture.data[i+1] - picture.data[i]; + size[i] = tmpsize - (picture.data[i] - picture.data[0]); + +- buf->last_pic_num= -256*256*256*64; + memset(buf->base, 0, sizeof(buf->base)); + memset(buf->data, 0, sizeof(buf->data)); + +@@ -326,67 +506,110 @@ + if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2]) + buf->data[i] = buf->base[i]; + else +- buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]); ++ buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (pixel_size*EDGE_WIDTH>>h_shift), stride_align[i]); ++ } ++ for (; i < AV_NUM_DATA_POINTERS; i++) { ++ buf->base[i] = buf->data[i] = NULL; ++ buf->linesize[i] = 0; + } + if(size[1] && !size[2]) + ff_set_systematic_pal2((uint32_t*)buf->data[1], s->pix_fmt); + buf->width = s->width; + buf->height = s->height; + buf->pix_fmt= s->pix_fmt; +- pic->age= 256*256*256*64; + } + pic->type= FF_BUFFER_TYPE_INTERNAL; + +- for(i=0; i<4; i++){ ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { + pic->base[i]= buf->base[i]; + pic->data[i]= buf->data[i]; + pic->linesize[i]= buf->linesize[i]; + } +- s->internal_buffer_count++; ++ pic->extended_data = pic->data; ++ avci->buffer_count++; + +- if(s->pkt) pic->pkt_pts= s->pkt->pts; +- else pic->pkt_pts= AV_NOPTS_VALUE; ++ if (s->pkt) { ++ pic->pkt_pts = s->pkt->pts; ++ pic->pkt_pos = s->pkt->pos; ++ } else { ++ pic->pkt_pts = AV_NOPTS_VALUE; ++ pic->pkt_pos = -1; ++ } + pic->reordered_opaque= s->reordered_opaque; ++ pic->sample_aspect_ratio = s->sample_aspect_ratio; ++ pic->width = s->width; ++ pic->height = s->height; ++ pic->format = s->pix_fmt; + + if(s->debug&FF_DEBUG_BUFFERS) +- av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); ++ av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d " ++ "buffers used\n", pic, avci->buffer_count); + + return 0; + } + ++int avcodec_default_get_buffer(AVCodecContext *avctx, AVFrame *frame) ++{ ++ switch (avctx->codec_type) { ++ case AVMEDIA_TYPE_VIDEO: ++ return video_get_buffer(avctx, frame); ++ case AVMEDIA_TYPE_AUDIO: ++ return audio_get_buffer(avctx, frame); ++ default: ++ return -1; ++ } ++} ++ + void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ + int i; + InternalBuffer *buf, *last; ++ AVCodecInternal *avci = s->internal; ++ ++ assert(s->codec_type == AVMEDIA_TYPE_VIDEO); + + assert(pic->type==FF_BUFFER_TYPE_INTERNAL); +- assert(s->internal_buffer_count); ++ assert(avci->buffer_count); + +- buf = NULL; /* avoids warning */ +- for(i=0; iinternal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize +- buf= &((InternalBuffer*)s->internal_buffer)[i]; +- if(buf->data[0] == pic->data[0]) +- break; +- } +- assert(i < s->internal_buffer_count); +- s->internal_buffer_count--; +- last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; ++ if (avci->buffer) { ++ buf = NULL; /* avoids warning */ ++ for (i = 0; i < avci->buffer_count; i++) { //just 3-5 checks so is not worth to optimize ++ buf = &avci->buffer[i]; ++ if (buf->data[0] == pic->data[0]) ++ break; ++ } ++ assert(i < avci->buffer_count); ++ avci->buffer_count--; ++ last = &avci->buffer[avci->buffer_count]; + +- FFSWAP(InternalBuffer, *buf, *last); ++ if (buf != last) ++ FFSWAP(InternalBuffer, *buf, *last); ++ } + +- for(i=0; i<4; i++){ ++ for (i = 0; i < AV_NUM_DATA_POINTERS; i++) { + pic->data[i]=NULL; + // pic->base[i]=NULL; + } + //printf("R%X\n", pic->opaque); + + if(s->debug&FF_DEBUG_BUFFERS) +- av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count); ++ av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d " ++ "buffers used\n", pic, avci->buffer_count); + } + + int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ + AVFrame temp_pic; + int i; + ++ assert(s->codec_type == AVMEDIA_TYPE_VIDEO); ++ ++ if (pic->data[0] && (pic->width != s->width || pic->height != s->height || pic->format != s->pix_fmt)) { ++ av_log(s, AV_LOG_WARNING, "Picture changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s in reget buffer()\n", ++ pic->width, pic->height, av_get_pix_fmt_name(pic->format), s->width, s->height, av_get_pix_fmt_name(s->pix_fmt)); ++ s->release_buffer(s, pic); ++ } ++ ++ ff_init_buffer_info(s, pic); ++ + /* If no picture return a new buffer */ + if(pic->data[0] == NULL) { + /* We will copy from buffer, so must be readable */ +@@ -396,7 +619,6 @@ + + /* If internal buffer type return the same buffer */ + if(pic->type == FF_BUFFER_TYPE_INTERNAL) { +- pic->reordered_opaque= s->reordered_opaque; + return 0; + } + +@@ -404,7 +626,7 @@ + * Not internal type and reget_buffer not overridden, emulate cr buffer + */ + temp_pic = *pic; +- for(i = 0; i < 4; i++) ++ for(i = 0; i < AV_NUM_DATA_POINTERS; i++) + pic->data[i] = pic->base[i] = NULL; + pic->opaque = NULL; + /* Allocate new frame */ +@@ -446,8 +668,11 @@ + void avcodec_get_frame_defaults(AVFrame *pic){ + memset(pic, 0, sizeof(AVFrame)); + +- pic->pts= AV_NOPTS_VALUE; ++ pic->pts = pic->pkt_dts = pic->pkt_pts = pic->best_effort_timestamp = AV_NOPTS_VALUE; ++ pic->pkt_pos = -1; + pic->key_frame= 1; ++ pic->sample_aspect_ratio = (AVRational){0, 1}; ++ pic->format = -1; /* unknown */ + } + + AVFrame *avcodec_alloc_frame(void){ +@@ -460,9 +685,44 @@ + return pic; + } + ++static void avcodec_get_subtitle_defaults(AVSubtitle *sub) ++{ ++ memset(sub, 0, sizeof(*sub)); ++ sub->pts = AV_NOPTS_VALUE; ++} ++ ++#if FF_API_AVCODEC_OPEN + int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) + { +- int ret= -1; ++ return avcodec_open2(avctx, codec, NULL); ++} ++#endif ++ ++int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVDictionary **options) ++{ ++ int ret = 0; ++ AVDictionary *tmp = NULL; ++ ++ if (avcodec_is_open(avctx)) ++ return 0; ++ ++ if ((!codec && !avctx->codec)) { ++ av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n"); ++ return AVERROR(EINVAL); ++ } ++ if ((codec && avctx->codec && codec != avctx->codec)) { ++ av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, " ++ "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name); ++ return AVERROR(EINVAL); ++ } ++ if (!codec) ++ codec = avctx->codec; ++ ++ if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) ++ return AVERROR(EINVAL); ++ ++ if (options) ++ av_dict_copy(&tmp, *options, 0); + + /* If there is a user-supplied mutex locking routine, call it. */ + if (ff_lockmgr_cb) { +@@ -473,11 +733,15 @@ + entangled_thread_counter++; + if(entangled_thread_counter != 1){ + av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); ++ ret = -1; + goto end; + } + +- if(avctx->codec || !codec) ++ avctx->internal = av_mallocz(sizeof(AVCodecInternal)); ++ if (!avctx->internal) { ++ ret = AVERROR(ENOMEM); + goto end; ++ } + + if (codec->priv_data_size > 0) { + if(!avctx->priv_data){ +@@ -486,19 +750,33 @@ + ret = AVERROR(ENOMEM); + goto end; + } +- if(codec->priv_class){ //this can be droped once all user apps use avcodec_get_context_defaults3() ++ if (codec->priv_class) { + *(AVClass**)avctx->priv_data= codec->priv_class; + av_opt_set_defaults(avctx->priv_data); + } + } ++ if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, &tmp)) < 0) ++ goto free_and_end; + } else { + avctx->priv_data = NULL; + } ++ if ((ret = av_opt_set_dict(avctx, &tmp)) < 0) ++ goto free_and_end; ++ ++ if (codec->capabilities & CODEC_CAP_EXPERIMENTAL) ++ if (avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { ++ av_log(avctx, AV_LOG_ERROR, "Codec is experimental but experimental codecs are not enabled, see -strict -2\n"); ++ ret = -1; ++ goto free_and_end; ++ } + ++ //We only call avcodec_set_dimensions() for non h264 codecs so as not to overwrite previously setup dimensions ++ if(!( avctx->coded_width && avctx->coded_height && avctx->width && avctx->height && avctx->codec_id == CODEC_ID_H264)){ + if(avctx->coded_width && avctx->coded_height) + avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); + else if(avctx->width && avctx->height) + avcodec_set_dimensions(avctx, avctx->width, avctx->height); ++ } + + if ((avctx->coded_width || avctx->coded_height || avctx->width || avctx->height) + && ( av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx) < 0 +@@ -509,7 +787,7 @@ + + /* if the decoder init function was already called previously, + free the already allocated subtitle_header before overwriting it */ +- if (codec->decode) ++ if (codec_is_decoder(codec)) + av_freep(&avctx->subtitle_header); + + #define SANE_NB_CHANNELS 128U +@@ -527,21 +805,110 @@ + if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type + && avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) { + av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n"); ++ ret = AVERROR(EINVAL); + goto free_and_end; + } + avctx->frame_number = 0; +- if (avctx->codec->max_lowres < avctx->lowres) { ++#if FF_API_ER ++ ++ av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition separate: %d; %X\n", ++ avctx->error_recognition, avctx->err_recognition); ++ switch(avctx->error_recognition){ ++ case FF_ER_EXPLODE : avctx->err_recognition |= AV_EF_EXPLODE | AV_EF_COMPLIANT | AV_EF_CAREFUL; ++ break; ++ case FF_ER_VERY_AGGRESSIVE: ++ case FF_ER_AGGRESSIVE : avctx->err_recognition |= AV_EF_AGGRESSIVE; ++ case FF_ER_COMPLIANT : avctx->err_recognition |= AV_EF_COMPLIANT; ++ case FF_ER_CAREFUL : avctx->err_recognition |= AV_EF_CAREFUL; ++ } ++ ++ av_log(avctx, AV_LOG_DEBUG, "err{or,}_recognition combined: %d; %X\n", ++ avctx->error_recognition, avctx->err_recognition); ++#endif ++ ++ if (avctx->codec_type == AVMEDIA_TYPE_AUDIO && ++ (!avctx->time_base.num || !avctx->time_base.den)) { ++ avctx->time_base.num = 1; ++ avctx->time_base.den = avctx->sample_rate; ++ } ++ ++ if (!HAVE_THREADS) ++ av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n"); ++ ++ if (HAVE_THREADS && !avctx->thread_opaque) { ++ ret = ff_thread_init(avctx); ++ if (ret < 0) { ++ goto free_and_end; ++ } ++ } ++ if (!HAVE_THREADS && !(codec->capabilities & CODEC_CAP_AUTO_THREADS)) ++ avctx->thread_count = 1; ++ ++ if (avctx->codec->max_lowres < avctx->lowres || avctx->lowres < 0) { + av_log(avctx, AV_LOG_ERROR, "The maximum value for lowres supported by the decoder is %d\n", + avctx->codec->max_lowres); ++ ret = AVERROR(EINVAL); + goto free_and_end; + } ++ if (codec_is_encoder(avctx->codec)) { ++ int i; ++ if (avctx->codec->sample_fmts) { ++ for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) ++ if (avctx->sample_fmt == avctx->codec->sample_fmts[i]) ++ break; ++ if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "Specified sample_fmt is not supported.\n"); ++ ret = AVERROR(EINVAL); ++ goto free_and_end; ++ } ++ } ++ if (avctx->codec->supported_samplerates) { ++ for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++) ++ if (avctx->sample_rate == avctx->codec->supported_samplerates[i]) ++ break; ++ if (avctx->codec->supported_samplerates[i] == 0) { ++ av_log(avctx, AV_LOG_ERROR, "Specified sample_rate is not supported\n"); ++ ret = AVERROR(EINVAL); ++ goto free_and_end; ++ } ++ } ++ if (avctx->codec->channel_layouts) { ++ if (!avctx->channel_layout) { ++ av_log(avctx, AV_LOG_WARNING, "channel_layout not specified\n"); ++ } else { ++ for (i = 0; avctx->codec->channel_layouts[i] != 0; i++) ++ if (avctx->channel_layout == avctx->codec->channel_layouts[i]) ++ break; ++ if (avctx->codec->channel_layouts[i] == 0) { ++ av_log(avctx, AV_LOG_ERROR, "Specified channel_layout is not supported\n"); ++ ret = AVERROR(EINVAL); ++ goto free_and_end; ++ } ++ } ++ } ++ if (avctx->channel_layout && avctx->channels) { ++ if (av_get_channel_layout_nb_channels(avctx->channel_layout) != avctx->channels) { ++ av_log(avctx, AV_LOG_ERROR, "channel layout does not match number of channels\n"); ++ ret = AVERROR(EINVAL); ++ goto free_and_end; ++ } ++ } else if (avctx->channel_layout) { ++ avctx->channels = av_get_channel_layout_nb_channels(avctx->channel_layout); ++ } ++ } ++ ++ avctx->pts_correction_num_faulty_pts = ++ avctx->pts_correction_num_faulty_dts = 0; ++ avctx->pts_correction_last_pts = ++ avctx->pts_correction_last_dts = INT64_MIN; + +- if(avctx->codec->init){ ++ if(avctx->codec->init && !(avctx->active_thread_type&FF_THREAD_FRAME)){ + ret = avctx->codec->init(avctx); + if (ret < 0) { + goto free_and_end; + } + } ++ + ret=0; + end: + entangled_thread_counter--; +@@ -550,27 +917,234 @@ + if (ff_lockmgr_cb) { + (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); + } ++ if (options) { ++ av_dict_free(options); ++ *options = tmp; ++ } ++ + return ret; + free_and_end: ++ av_dict_free(&tmp); + av_freep(&avctx->priv_data); ++ av_freep(&avctx->internal); + avctx->codec= NULL; + goto end; + } + +-int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, +- const short *samples) ++int ff_alloc_packet(AVPacket *avpkt, int size) + { +- if(buf_size < FF_MIN_BUFFER_SIZE && 0){ +- av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n"); +- return -1; ++ if (size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) ++ return AVERROR(EINVAL); ++ ++ if (avpkt->data) { ++ uint8_t *pkt_data; ++ int pkt_size; ++ ++ if (avpkt->size < size) ++ return AVERROR(EINVAL); ++ ++ pkt_data = avpkt->data; ++ pkt_size = avpkt->size; ++ av_init_packet(avpkt); ++ avpkt->data = pkt_data; ++ avpkt->size = pkt_size; ++ return 0; ++ } else { ++ return av_new_packet(avpkt, size); + } +- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){ +- int ret = avctx->codec->encode(avctx, buf, buf_size, samples); +- avctx->frame_number++; +- return ret; +- }else ++} ++ ++int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, ++ AVPacket *avpkt, ++ const AVFrame *frame, ++ int *got_packet_ptr) ++{ ++ int ret; ++ int user_packet = !!avpkt->data; ++ int nb_samples; ++ ++ if (!(avctx->codec->capabilities & CODEC_CAP_DELAY) && !frame) { ++ av_init_packet(avpkt); ++ avpkt->size = 0; + return 0; ++ } ++ ++ /* check for valid frame size */ ++ if (frame) { ++ nb_samples = frame->nb_samples; ++ if (avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) { ++ if (nb_samples > avctx->frame_size) ++ return AVERROR(EINVAL); ++ } else if (!(avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE)) { ++ if (nb_samples != avctx->frame_size) ++ return AVERROR(EINVAL); ++ } ++ } else { ++ nb_samples = avctx->frame_size; ++ } ++ ++ if (avctx->codec->encode2) { ++ *got_packet_ptr = 0; ++ ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr); ++ if (!ret && *got_packet_ptr && ++ !(avctx->codec->capabilities & CODEC_CAP_DELAY)) { ++ avpkt->pts = frame->pts; ++ avpkt->duration = av_rescale_q(frame->nb_samples, ++ (AVRational){ 1, avctx->sample_rate }, ++ avctx->time_base); ++ } ++ } else { ++ /* for compatibility with encoders not supporting encode2(), we need to ++ allocate a packet buffer if the user has not provided one or check ++ the size otherwise */ ++ int fs_tmp = 0; ++ int buf_size = avpkt->size; ++ if (!user_packet) { ++ if (avctx->codec->capabilities & CODEC_CAP_VARIABLE_FRAME_SIZE) { ++ av_assert0(av_get_bits_per_sample(avctx->codec_id) != 0); ++ if (!frame) ++ return AVERROR(EINVAL); ++ buf_size = nb_samples * avctx->channels * ++ av_get_bits_per_sample(avctx->codec_id) / 8; ++ } else { ++ /* this is a guess as to the required size. ++ if an encoder needs more than this, it should probably ++ implement encode2() */ ++ buf_size = 2 * avctx->frame_size * avctx->channels * ++ av_get_bytes_per_sample(avctx->sample_fmt); ++ buf_size += FF_MIN_BUFFER_SIZE; ++ } ++ } ++ if ((ret = ff_alloc_packet(avpkt, buf_size))) ++ return ret; ++ ++ /* Encoders using AVCodec.encode() that support ++ CODEC_CAP_SMALL_LAST_FRAME require avctx->frame_size to be set to ++ the smaller size when encoding the last frame. ++ This code can be removed once all encoders supporting ++ CODEC_CAP_SMALL_LAST_FRAME use encode2() */ ++ if ((avctx->codec->capabilities & CODEC_CAP_SMALL_LAST_FRAME) && ++ nb_samples < avctx->frame_size) { ++ fs_tmp = avctx->frame_size; ++ avctx->frame_size = nb_samples; ++ } ++ ++ /* encode the frame */ ++ ret = avctx->codec->encode(avctx, avpkt->data, avpkt->size, ++ frame ? frame->data[0] : NULL); ++ if (ret >= 0) { ++ if (!ret) { ++ /* no output. if the packet data was allocated by libavcodec, ++ free it */ ++ if (!user_packet) ++ av_freep(&avpkt->data); ++ } else { ++ if (avctx->coded_frame) ++ avpkt->pts = avctx->coded_frame->pts; ++ /* Set duration for final small packet. This can be removed ++ once all encoders supporting CODEC_CAP_SMALL_LAST_FRAME use ++ encode2() */ ++ if (fs_tmp) { ++ avpkt->duration = av_rescale_q(avctx->frame_size, ++ (AVRational){ 1, avctx->sample_rate }, ++ avctx->time_base); ++ } ++ } ++ avpkt->size = ret; ++ *got_packet_ptr = (ret > 0); ++ ret = 0; ++ } ++ ++ if (fs_tmp) ++ avctx->frame_size = fs_tmp; ++ } ++ if (!ret) ++ avctx->frame_number++; ++ ++ /* NOTE: if we add any audio encoders which output non-keyframe packets, ++ this needs to be moved to the encoders, but for now we can do it ++ here to simplify things */ ++ avpkt->flags |= AV_PKT_FLAG_KEY; ++ ++ return ret; ++} ++ ++#if FF_API_OLD_DECODE_AUDIO ++int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, ++ uint8_t *buf, int buf_size, ++ const short *samples) ++{ ++ AVPacket pkt; ++ AVFrame frame0; ++ AVFrame *frame; ++ int ret, samples_size, got_packet; ++ ++ av_init_packet(&pkt); ++ pkt.data = buf; ++ pkt.size = buf_size; ++ ++ if (samples) { ++ frame = &frame0; ++ avcodec_get_frame_defaults(frame); ++ ++ if (avctx->frame_size) { ++ frame->nb_samples = avctx->frame_size; ++ } else { ++ /* if frame_size is not set, the number of samples must be ++ calculated from the buffer size */ ++ int64_t nb_samples; ++ if (!av_get_bits_per_sample(avctx->codec_id)) { ++ av_log(avctx, AV_LOG_ERROR, "avcodec_encode_audio() does not " ++ "support this codec\n"); ++ return AVERROR(EINVAL); ++ } ++ nb_samples = (int64_t)buf_size * 8 / ++ (av_get_bits_per_sample(avctx->codec_id) * ++ avctx->channels); ++ if (nb_samples >= INT_MAX) ++ return AVERROR(EINVAL); ++ frame->nb_samples = nb_samples; ++ } ++ ++ /* it is assumed that the samples buffer is large enough based on the ++ relevant parameters */ ++ samples_size = av_samples_get_buffer_size(NULL, avctx->channels, ++ frame->nb_samples, ++ avctx->sample_fmt, 1); ++ if ((ret = avcodec_fill_audio_frame(frame, avctx->channels, ++ avctx->sample_fmt, ++ samples, samples_size, 1))) ++ return ret; ++ ++ /* fabricate frame pts from sample count. ++ this is needed because the avcodec_encode_audio() API does not have ++ a way for the user to provide pts */ ++ if(avctx->sample_rate && avctx->time_base.num) ++ frame->pts = av_rescale_q(avctx->internal->sample_count, ++ (AVRational){ 1, avctx->sample_rate }, ++ avctx->time_base); ++ else ++ frame->pts = AV_NOPTS_VALUE; ++ avctx->internal->sample_count += frame->nb_samples; ++ } else { ++ frame = NULL; ++ } ++ ++ got_packet = 0; ++ ret = avcodec_encode_audio2(avctx, &pkt, frame, &got_packet); ++ if (!ret && got_packet && avctx->coded_frame) { ++ avctx->coded_frame->pts = pkt.pts; ++ avctx->coded_frame->key_frame = !!(pkt.flags & AV_PKT_FLAG_KEY); ++ } ++ /* free any side data since we cannot return it */ ++ ff_packet_free_side_data(&pkt); ++ ++ if (frame && frame->extended_data != frame->data) ++ av_freep(&frame->extended_data); ++ ++ return ret ? ret : pkt.size; + } ++#endif + + int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, + const AVFrame *pict) +@@ -599,113 +1173,219 @@ + av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n"); + return -1; + } +- if(sub->num_rects == 0 || !sub->rects) +- return -1; ++ + ret = avctx->codec->encode(avctx, buf, buf_size, sub); + avctx->frame_number++; + return ret; + } + +-#if FF_API_VIDEO_OLD +-int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, +- int *got_picture_ptr, +- const uint8_t *buf, int buf_size) ++/** ++ * Attempt to guess proper monotonic timestamps for decoded video frames ++ * which might have incorrect times. Input timestamps may wrap around, in ++ * which case the output will as well. ++ * ++ * @param pts the pts field of the decoded AVPacket, as passed through ++ * AVFrame.pkt_pts ++ * @param dts the dts field of the decoded AVPacket ++ * @return one of the input values, may be AV_NOPTS_VALUE ++ */ ++static int64_t guess_correct_pts(AVCodecContext *ctx, ++ int64_t reordered_pts, int64_t dts) + { +- AVPacket avpkt; +- av_init_packet(&avpkt); +- avpkt.data = buf; +- avpkt.size = buf_size; +- // HACK for CorePNG to decode as normal PNG by default +- avpkt.flags = AV_PKT_FLAG_KEY; ++ int64_t pts = AV_NOPTS_VALUE; ++ ++ if (dts != AV_NOPTS_VALUE) { ++ ctx->pts_correction_num_faulty_dts += dts <= ctx->pts_correction_last_dts; ++ ctx->pts_correction_last_dts = dts; ++ } ++ if (reordered_pts != AV_NOPTS_VALUE) { ++ ctx->pts_correction_num_faulty_pts += reordered_pts <= ctx->pts_correction_last_pts; ++ ctx->pts_correction_last_pts = reordered_pts; ++ } ++ if ((ctx->pts_correction_num_faulty_pts<=ctx->pts_correction_num_faulty_dts || dts == AV_NOPTS_VALUE) ++ && reordered_pts != AV_NOPTS_VALUE) ++ pts = reordered_pts; ++ else ++ pts = dts; + +- return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt); ++ return pts; ++} ++ ++static void apply_param_change(AVCodecContext *avctx, AVPacket *avpkt) ++{ ++ int size = 0; ++ const uint8_t *data; ++ uint32_t flags; ++ ++ if (!(avctx->codec->capabilities & CODEC_CAP_PARAM_CHANGE)) ++ return; ++ ++ data = av_packet_get_side_data(avpkt, AV_PKT_DATA_PARAM_CHANGE, &size); ++ if (!data || size < 4) ++ return; ++ flags = bytestream_get_le32(&data); ++ size -= 4; ++ if (size < 4) /* Required for any of the changes */ ++ return; ++ if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) { ++ avctx->channels = bytestream_get_le32(&data); ++ size -= 4; ++ } ++ if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) { ++ if (size < 8) ++ return; ++ avctx->channel_layout = bytestream_get_le64(&data); ++ size -= 8; ++ } ++ if (size < 4) ++ return; ++ if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) { ++ avctx->sample_rate = bytestream_get_le32(&data); ++ size -= 4; ++ } ++ if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) { ++ if (size < 8) ++ return; ++ avctx->width = bytestream_get_le32(&data); ++ avctx->height = bytestream_get_le32(&data); ++ avcodec_set_dimensions(avctx, avctx->width, avctx->height); ++ size -= 8; ++ } + } +-#endif + + int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture, + int *got_picture_ptr, +- AVPacket *avpkt) ++ const AVPacket *avpkt) + { + int ret; ++ // copy to ensure we do not change avpkt ++ AVPacket tmp = *avpkt; + + *got_picture_ptr= 0; + if((avctx->coded_width||avctx->coded_height) && av_image_check_size(avctx->coded_width, avctx->coded_height, 0, avctx)) + return -1; + +- avctx->pkt = avpkt; ++ if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size || (avctx->active_thread_type&FF_THREAD_FRAME)){ ++ int did_split = av_packet_split_side_data(&tmp); ++ apply_param_change(avctx, &tmp); ++ avctx->pkt = &tmp; ++ if (HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) ++ ret = ff_thread_decode_frame(avctx, picture, got_picture_ptr, ++ &tmp); ++ else { ++ ret = avctx->codec->decode(avctx, picture, got_picture_ptr, ++ &tmp); ++ picture->pkt_dts= avpkt->dts; + +- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){ +- ret = avctx->codec->decode(avctx, picture, got_picture_ptr, +- avpkt); ++ if(!avctx->has_b_frames){ ++ picture->pkt_pos= avpkt->pos; ++ } ++ //FIXME these should be under if(!avctx->has_b_frames) ++ if (!picture->sample_aspect_ratio.num) ++ picture->sample_aspect_ratio = avctx->sample_aspect_ratio; ++ if (!picture->width) ++ picture->width = avctx->width; ++ if (!picture->height) ++ picture->height = avctx->height; ++ if (picture->format == PIX_FMT_NONE) ++ picture->format = avctx->pix_fmt; ++ } + + emms_c(); //needed to avoid an emms_c() call before every return; + +- picture->pkt_dts= avpkt->dts; ++ avctx->pkt = NULL; ++ if (did_split) ++ ff_packet_free_side_data(&tmp); + +- if (*got_picture_ptr) ++ if (*got_picture_ptr){ + avctx->frame_number++; ++ picture->best_effort_timestamp = guess_correct_pts(avctx, ++ picture->pkt_pts, ++ picture->pkt_dts); ++ } + }else + ret= 0; + + return ret; + } + +-#if FF_API_AUDIO_OLD +-int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples, +- int *frame_size_ptr, +- const uint8_t *buf, int buf_size) +-{ +- AVPacket avpkt; +- av_init_packet(&avpkt); +- avpkt.data = buf; +- avpkt.size = buf_size; +- +- return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt); +-} +-#endif +- ++#if FF_API_OLD_DECODE_AUDIO + int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples, + int *frame_size_ptr, + AVPacket *avpkt) + { +- int ret; +- +- avctx->pkt = avpkt; ++ AVFrame frame; ++ int ret, got_frame = 0; + +- if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){ +- //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough +- if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){ +- av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n"); +- return -1; +- } +- if(*frame_size_ptr < FF_MIN_BUFFER_SIZE || +- *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){ +- av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr); +- return -1; ++ if (avctx->get_buffer != avcodec_default_get_buffer) { ++ av_log(avctx, AV_LOG_ERROR, "Custom get_buffer() for use with" ++ "avcodec_decode_audio3() detected. Overriding with avcodec_default_get_buffer\n"); ++ av_log(avctx, AV_LOG_ERROR, "Please port your application to " ++ "avcodec_decode_audio4()\n"); ++ avctx->get_buffer = avcodec_default_get_buffer; ++ avctx->release_buffer = avcodec_default_release_buffer; ++ } ++ ++ ret = avcodec_decode_audio4(avctx, &frame, &got_frame, avpkt); ++ ++ if (ret >= 0 && got_frame) { ++ int ch, plane_size; ++ int planar = av_sample_fmt_is_planar(avctx->sample_fmt); ++ int data_size = av_samples_get_buffer_size(&plane_size, avctx->channels, ++ frame.nb_samples, ++ avctx->sample_fmt, 1); ++ if (*frame_size_ptr < data_size) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer size is too small for " ++ "the current frame (%d < %d)\n", *frame_size_ptr, data_size); ++ return AVERROR(EINVAL); + } + +- ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt); +- avctx->frame_number++; +- }else{ +- ret= 0; +- *frame_size_ptr=0; ++ memcpy(samples, frame.extended_data[0], plane_size); ++ ++ if (planar && avctx->channels > 1) { ++ uint8_t *out = ((uint8_t *)samples) + plane_size; ++ for (ch = 1; ch < avctx->channels; ch++) { ++ memcpy(out, frame.extended_data[ch], plane_size); ++ out += plane_size; ++ } ++ } ++ *frame_size_ptr = data_size; ++ } else { ++ *frame_size_ptr = 0; + } + return ret; + } ++#endif + +-#if FF_API_SUBTITLE_OLD +-int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, +- int *got_sub_ptr, +- const uint8_t *buf, int buf_size) ++int attribute_align_arg avcodec_decode_audio4(AVCodecContext *avctx, ++ AVFrame *frame, ++ int *got_frame_ptr, ++ AVPacket *avpkt) + { +- AVPacket avpkt; +- av_init_packet(&avpkt); +- avpkt.data = buf; +- avpkt.size = buf_size; ++ int ret = 0; ++ ++ *got_frame_ptr = 0; ++ ++ if (!avpkt->data && avpkt->size) { ++ av_log(avctx, AV_LOG_ERROR, "invalid packet: NULL data, size != 0\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if ((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size) { ++ av_packet_split_side_data(avpkt); ++ apply_param_change(avctx, avpkt); + +- return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt); ++ avctx->pkt = avpkt; ++ ret = avctx->codec->decode(avctx, frame, got_frame_ptr, avpkt); ++ if (ret >= 0 && *got_frame_ptr) { ++ avctx->frame_number++; ++ frame->pkt_dts = avpkt->dts; ++ if (frame->format == AV_SAMPLE_FMT_NONE) ++ frame->format = avctx->sample_fmt; ++ } ++ } ++ return ret; + } +-#endif + + int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub, + int *got_sub_ptr, +@@ -715,6 +1395,7 @@ + + avctx->pkt = avpkt; + *got_sub_ptr = 0; ++ avcodec_get_subtitle_defaults(sub); + ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt); + if (*got_sub_ptr) + avctx->frame_number++; +@@ -756,16 +1437,24 @@ + return -1; + } + +- if (HAVE_THREADS && avctx->thread_opaque) +- avcodec_thread_free(avctx); +- if (avctx->codec && avctx->codec->close) +- avctx->codec->close(avctx); +- avcodec_default_free_buffers(avctx); +- avctx->coded_frame = NULL; ++ if (avcodec_is_open(avctx)) { ++ if (HAVE_THREADS && avctx->thread_opaque) ++ ff_thread_free(avctx); ++ if (avctx->codec && avctx->codec->close) ++ avctx->codec->close(avctx); ++ avcodec_default_free_buffers(avctx); ++ avctx->coded_frame = NULL; ++ av_freep(&avctx->internal); ++ } ++ ++ if (avctx->priv_data && avctx->codec && avctx->codec->priv_class) ++ av_opt_free(avctx->priv_data); ++ av_opt_free(avctx); + av_freep(&avctx->priv_data); +- if(avctx->codec && avctx->codec->encode) ++ if (codec_is_encoder(avctx->codec)) + av_freep(&avctx->extradata); + avctx->codec = NULL; ++ avctx->active_thread_type = 0; + entangled_thread_counter--; + + /* Release any user-supplied mutex. */ +@@ -775,12 +1464,23 @@ + return 0; + } + ++static enum CodecID remap_deprecated_codec_id(enum CodecID id) ++{ ++ switch(id){ ++ case CODEC_ID_G723_1_DEPRECATED : return CODEC_ID_G723_1; ++ case CODEC_ID_G729_DEPRECATED : return CODEC_ID_G729; ++ case CODEC_ID_UTVIDEO_DEPRECATED: return CODEC_ID_UTVIDEO; ++ default : return id; ++ } ++} ++ + AVCodec *avcodec_find_encoder(enum CodecID id) + { + AVCodec *p, *experimental=NULL; + p = first_avcodec; ++ id= remap_deprecated_codec_id(id); + while (p) { +- if (p->encode != NULL && p->id == id) { ++ if (codec_is_encoder(p) && p->id == id) { + if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) { + experimental = p; + } else +@@ -798,7 +1498,7 @@ + return NULL; + p = first_avcodec; + while (p) { +- if (p->encode != NULL && strcmp(name,p->name) == 0) ++ if (codec_is_encoder(p) && strcmp(name,p->name) == 0) + return p; + p = p->next; + } +@@ -807,14 +1507,19 @@ + + AVCodec *avcodec_find_decoder(enum CodecID id) + { +- AVCodec *p; ++ AVCodec *p, *experimental=NULL; + p = first_avcodec; ++ id= remap_deprecated_codec_id(id); + while (p) { +- if (p->decode != NULL && p->id == id) +- return p; ++ if (codec_is_decoder(p) && p->id == id) { ++ if (p->capabilities & CODEC_CAP_EXPERIMENTAL && !experimental) { ++ experimental = p; ++ } else ++ return p; ++ } + p = p->next; + } +- return NULL; ++ return experimental; + } + + AVCodec *avcodec_find_decoder_by_name(const char *name) +@@ -824,7 +1529,7 @@ + return NULL; + p = first_avcodec; + while (p) { +- if (p->decode != NULL && strcmp(name,p->name) == 0) ++ if (codec_is_decoder(p) && strcmp(name,p->name) == 0) + return p; + p = p->next; + } +@@ -854,6 +1559,25 @@ + return bit_rate; + } + ++const char *avcodec_get_name(enum CodecID id) ++{ ++ AVCodec *codec; ++ ++#if !CONFIG_SMALL ++ switch (id) { ++#include "libavcodec/codec_names.h" ++ } ++ av_log(NULL, AV_LOG_WARNING, "Codec 0x%x is not in the full list.\n", id); ++#endif ++ codec = avcodec_find_decoder(id); ++ if (codec) ++ return codec->name; ++ codec = avcodec_find_encoder(id); ++ if (codec) ++ return codec->name; ++ return "unknown_codec"; ++} ++ + size_t av_get_codec_tag_string(char *buf, size_t buf_size, unsigned int codec_tag) + { + int i, len, ret = 0; +@@ -871,47 +1595,41 @@ + + void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) + { ++ const char *codec_type; + const char *codec_name; + const char *profile = NULL; + AVCodec *p; +- char buf1[32]; + int bitrate; + AVRational display_aspect_ratio; + +- if (encode) +- p = avcodec_find_encoder(enc->codec_id); +- else +- p = avcodec_find_decoder(enc->codec_id); ++ if (!buf || buf_size <= 0) ++ return; ++ codec_type = av_get_media_type_string(enc->codec_type); ++ codec_name = avcodec_get_name(enc->codec_id); ++ if (enc->profile != FF_PROFILE_UNKNOWN) { ++ p = encode ? avcodec_find_encoder(enc->codec_id) : ++ avcodec_find_decoder(enc->codec_id); ++ if (p) ++ profile = av_get_profile_name(p, enc->profile); ++ } + +- if (p) { +- codec_name = p->name; +- profile = av_get_profile_name(p, enc->profile); +- } else if (enc->codec_id == CODEC_ID_MPEG2TS) { +- /* fake mpeg2 transport stream codec (currently not +- registered) */ +- codec_name = "mpeg2ts"; +- } else if (enc->codec_name[0] != '\0') { +- codec_name = enc->codec_name; +- } else { +- /* output avi tags */ ++ snprintf(buf, buf_size, "%s: %s%s", codec_type ? codec_type : "unknown", ++ codec_name, enc->mb_decision ? " (hq)" : ""); ++ buf[0] ^= 'a' ^ 'A'; /* first letter in uppercase */ ++ if (profile) ++ snprintf(buf + strlen(buf), buf_size - strlen(buf), " (%s)", profile); ++ if (enc->codec_tag) { + char tag_buf[32]; + av_get_codec_tag_string(tag_buf, sizeof(tag_buf), enc->codec_tag); +- snprintf(buf1, sizeof(buf1), "%s / 0x%04X", tag_buf, enc->codec_tag); +- codec_name = buf1; ++ snprintf(buf + strlen(buf), buf_size - strlen(buf), ++ " (%s / 0x%04X)", tag_buf, enc->codec_tag); + } +- + switch(enc->codec_type) { + case AVMEDIA_TYPE_VIDEO: +- snprintf(buf, buf_size, +- "Video: %s%s", +- codec_name, enc->mb_decision ? " (hq)" : ""); +- if (profile) +- snprintf(buf + strlen(buf), buf_size - strlen(buf), +- " (%s)", profile); + if (enc->pix_fmt != PIX_FMT_NONE) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", %s", +- avcodec_get_pix_fmt_name(enc->pix_fmt)); ++ av_get_pix_fmt_name(enc->pix_fmt)); + } + if (enc->width) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), +@@ -923,7 +1641,7 @@ + enc->height*enc->sample_aspect_ratio.den, + 1024*1024); + snprintf(buf + strlen(buf), buf_size - strlen(buf), +- " [PAR %d:%d DAR %d:%d]", ++ " [SAR %d:%d DAR %d:%d]", + enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den, + display_aspect_ratio.num, display_aspect_ratio.den); + } +@@ -940,12 +1658,6 @@ + } + break; + case AVMEDIA_TYPE_AUDIO: +- snprintf(buf, buf_size, +- "Audio: %s", +- codec_name); +- if (profile) +- snprintf(buf + strlen(buf), buf_size - strlen(buf), +- " (%s)", profile); + if (enc->sample_rate) { + snprintf(buf + strlen(buf), buf_size - strlen(buf), + ", %d Hz", enc->sample_rate); +@@ -957,17 +1669,7 @@ + ", %s", av_get_sample_fmt_name(enc->sample_fmt)); + } + break; +- case AVMEDIA_TYPE_DATA: +- snprintf(buf, buf_size, "Data: %s", codec_name); +- break; +- case AVMEDIA_TYPE_SUBTITLE: +- snprintf(buf, buf_size, "Subtitle: %s", codec_name); +- break; +- case AVMEDIA_TYPE_ATTACHMENT: +- snprintf(buf, buf_size, "Attachment: %s", codec_name); +- break; + default: +- snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); + return; + } + if (encode) { +@@ -1000,6 +1702,13 @@ + + unsigned avcodec_version( void ) + { ++ av_assert0(CODEC_ID_V410==164); ++ av_assert0(CODEC_ID_PCM_S8_PLANAR==65563); ++ av_assert0(CODEC_ID_ADPCM_G722==69660); ++ av_assert0(CODEC_ID_BMV_AUDIO==86071); ++ av_assert0(CODEC_ID_SRT==94216); ++ av_assert0(LIBAVCODEC_VERSION_MICRO >= 100); ++ + return LIBAVCODEC_VERSION_INT; + } + +@@ -1014,55 +1723,74 @@ + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; + } + +-void avcodec_init(void) +-{ +- static int initialized = 0; +- +- if (initialized != 0) +- return; +- initialized = 1; +- +- dsputil_static_init(); +-} +- + void avcodec_flush_buffers(AVCodecContext *avctx) + { +- if(avctx->codec->flush) ++ if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_FRAME) ++ ff_thread_flush(avctx); ++ else if(avctx->codec->flush) + avctx->codec->flush(avctx); + } + +-void avcodec_default_free_buffers(AVCodecContext *s){ ++static void video_free_buffers(AVCodecContext *s) ++{ ++ AVCodecInternal *avci = s->internal; + int i, j; + +- if(s->internal_buffer==NULL) return; ++ if (!avci->buffer) ++ return; + +- if (s->internal_buffer_count) +- av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count); ++ if (avci->buffer_count) ++ av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", ++ avci->buffer_count); + for(i=0; iinternal_buffer)[i]; ++ InternalBuffer *buf = &avci->buffer[i]; + for(j=0; j<4; j++){ + av_freep(&buf->base[j]); + buf->data[j]= NULL; + } + } +- av_freep(&s->internal_buffer); ++ av_freep(&avci->buffer); + +- s->internal_buffer_count=0; ++ avci->buffer_count=0; + } + +-char av_get_pict_type_char(int pict_type){ +- switch(pict_type){ +- case FF_I_TYPE: return 'I'; +- case FF_P_TYPE: return 'P'; +- case FF_B_TYPE: return 'B'; +- case FF_S_TYPE: return 'S'; +- case FF_SI_TYPE:return 'i'; +- case FF_SP_TYPE:return 'p'; +- case FF_BI_TYPE:return 'b'; +- default: return '?'; ++static void audio_free_buffers(AVCodecContext *avctx) ++{ ++ AVCodecInternal *avci = avctx->internal; ++ InternalBuffer *buf; ++ ++ if (!avci->buffer) ++ return; ++ buf = avci->buffer; ++ ++ if (buf->extended_data) { ++ av_free(buf->extended_data[0]); ++ if (buf->extended_data != buf->data) ++ av_freep(&buf->extended_data); + } ++ av_freep(&avci->buffer); + } + ++void avcodec_default_free_buffers(AVCodecContext *avctx) ++{ ++ switch (avctx->codec_type) { ++ case AVMEDIA_TYPE_VIDEO: ++ video_free_buffers(avctx); ++ break; ++ case AVMEDIA_TYPE_AUDIO: ++ audio_free_buffers(avctx); ++ break; ++ default: ++ break; ++ } ++} ++ ++#if FF_API_OLD_FF_PICT_TYPES ++char av_get_pict_type_char(int pict_type){ ++ return av_get_picture_type_char(pict_type); ++} ++#endif ++ + int av_get_bits_per_sample(enum CodecID codec_id){ + switch(codec_id){ + case CODEC_ID_ADPCM_SBPRO_2: +@@ -1071,9 +1799,13 @@ + return 3; + case CODEC_ID_ADPCM_SBPRO_4: + case CODEC_ID_ADPCM_CT: ++ case CODEC_ID_ADPCM_IMA_APC: + case CODEC_ID_ADPCM_IMA_WAV: ++ case CODEC_ID_ADPCM_IMA_QT: ++ case CODEC_ID_ADPCM_SWF: + case CODEC_ID_ADPCM_MS: + case CODEC_ID_ADPCM_YAMAHA: ++ case CODEC_ID_ADPCM_G722: + return 4; + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_MULAW: +@@ -1110,13 +1842,12 @@ + + #if FF_API_OLD_SAMPLE_FMT + int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { +- return av_get_bits_per_sample_fmt(sample_fmt); ++ return av_get_bytes_per_sample(sample_fmt) << 3; + } + #endif + + #if !HAVE_THREADS +-int avcodec_thread_init(AVCodecContext *s, int thread_count){ +- s->thread_count = thread_count; ++int ff_thread_init(AVCodecContext *s){ + return -1; + } + #endif +@@ -1135,20 +1866,6 @@ + return n; + } + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-#include "libavcore/parseutils.h" +- +-int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str) +-{ +- return av_parse_video_size(width_ptr, height_ptr, str); +-} +- +-int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg) +-{ +- return av_parse_video_rate(frame_rate, arg); +-} +-#endif +- + int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){ + int i; + for(i=0; i>8 )&0xFF)<<8 ) + + (toupper((x>>16)&0xFF)<<16) + + (toupper((x>>24)&0xFF)<<24); + } ++ ++#if !HAVE_THREADS ++ ++int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f) ++{ ++ f->owner = avctx; ++ ++ ff_init_buffer_info(avctx, f); ++ ++ return avctx->get_buffer(avctx, f); ++} ++ ++void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f) ++{ ++ f->owner->release_buffer(f->owner, f); ++} ++ ++void ff_thread_finish_setup(AVCodecContext *avctx) ++{ ++} ++ ++void ff_thread_report_progress(AVFrame *f, int progress, int field) ++{ ++} ++ ++void ff_thread_await_progress(AVFrame *f, int progress, int field) ++{ ++} ++ ++#endif ++ ++#if FF_API_THREAD_INIT ++int avcodec_thread_init(AVCodecContext *s, int thread_count) ++{ ++ s->thread_count = thread_count; ++ return ff_thread_init(s); ++} ++#endif ++ ++enum AVMediaType avcodec_get_type(enum CodecID codec_id) ++{ ++ AVCodec *c= avcodec_find_decoder(codec_id); ++ if(!c) ++ c= avcodec_find_encoder(codec_id); ++ if(c) ++ return c->type; ++ ++ if (codec_id <= CODEC_ID_NONE) ++ return AVMEDIA_TYPE_UNKNOWN; ++ else if (codec_id < CODEC_ID_FIRST_AUDIO) ++ return AVMEDIA_TYPE_VIDEO; ++ else if (codec_id < CODEC_ID_FIRST_SUBTITLE) ++ return AVMEDIA_TYPE_AUDIO; ++ else if (codec_id < CODEC_ID_FIRST_UNKNOWN) ++ return AVMEDIA_TYPE_SUBTITLE; ++ ++ return AVMEDIA_TYPE_UNKNOWN; ++} ++ ++int avcodec_is_open(AVCodecContext *s) ++{ ++ return !!s->internal; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/utvideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/utvideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/utvideo.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/utvideo.c 2012-05-14 14:08:54.288339056 +0200 +@@ -0,0 +1,581 @@ ++/* ++ * Ut Video decoder ++ * Copyright (c) 2011 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Ut Video decoder ++ */ ++ ++#include ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++#include "bytestream.h" ++#include "get_bits.h" ++#include "dsputil.h" ++#include "thread.h" ++ ++enum { ++ PRED_NONE = 0, ++ PRED_LEFT, ++ PRED_GRADIENT, ++ PRED_MEDIAN, ++}; ++ ++typedef struct UtvideoContext { ++ AVCodecContext *avctx; ++ AVFrame pic; ++ DSPContext dsp; ++ ++ uint32_t frame_info_size, flags, frame_info; ++ int planes; ++ int slices; ++ int compression; ++ int interlaced; ++ int frame_pred; ++ ++ uint8_t *slice_bits; ++ int slice_bits_size; ++} UtvideoContext; ++ ++typedef struct HuffEntry { ++ uint8_t sym; ++ uint8_t len; ++} HuffEntry; ++ ++static int huff_cmp(const void *a, const void *b) ++{ ++ const HuffEntry *aa = a, *bb = b; ++ return (aa->len - bb->len)*256 + aa->sym - bb->sym; ++} ++ ++static int build_huff(const uint8_t *src, VLC *vlc, int *fsym) ++{ ++ int i; ++ HuffEntry he[256]; ++ int last; ++ uint32_t codes[256]; ++ uint8_t bits[256]; ++ uint8_t syms[256]; ++ uint32_t code; ++ ++ *fsym = -1; ++ for (i = 0; i < 256; i++) { ++ he[i].sym = i; ++ he[i].len = *src++; ++ } ++ qsort(he, 256, sizeof(*he), huff_cmp); ++ ++ if (!he[0].len) { ++ *fsym = he[0].sym; ++ return 0; ++ } ++ if (he[0].len > 32) ++ return -1; ++ ++ last = 255; ++ while (he[last].len == 255 && last) ++ last--; ++ ++ code = 1; ++ for (i = last; i >= 0; i--) { ++ codes[i] = code >> (32 - he[i].len); ++ bits[i] = he[i].len; ++ syms[i] = he[i].sym; ++ code += 0x80000000u >> (he[i].len - 1); ++ } ++ ++ return init_vlc_sparse(vlc, FFMIN(he[last].len, 9), last + 1, ++ bits, sizeof(*bits), sizeof(*bits), ++ codes, sizeof(*codes), sizeof(*codes), ++ syms, sizeof(*syms), sizeof(*syms), 0); ++} ++ ++static int decode_plane(UtvideoContext *c, int plane_no, ++ uint8_t *dst, int step, int stride, ++ int width, int height, ++ const uint8_t *src, int src_size, int use_pred) ++{ ++ int i, j, slice, pix; ++ int sstart, send; ++ VLC vlc; ++ GetBitContext gb; ++ int prev, fsym; ++ const int cmask = ~(!plane_no && c->avctx->pix_fmt == PIX_FMT_YUV420P); ++ ++ if (build_huff(src, &vlc, &fsym)) { ++ av_log(c->avctx, AV_LOG_ERROR, "Cannot build Huffman codes\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (fsym >= 0) { // build_huff reported a symbol to fill slices with ++ send = 0; ++ for (slice = 0; slice < c->slices; slice++) { ++ uint8_t *dest; ++ ++ sstart = send; ++ send = (height * (slice + 1) / c->slices) & cmask; ++ dest = dst + sstart * stride; ++ ++ prev = 0x80; ++ for (j = sstart; j < send; j++) { ++ for (i = 0; i < width * step; i += step) { ++ pix = fsym; ++ if (use_pred) { ++ prev += pix; ++ pix = prev; ++ } ++ dest[i] = pix; ++ } ++ dest += stride; ++ } ++ } ++ return 0; ++ } ++ ++ src += 256; ++ src_size -= 256; ++ ++ send = 0; ++ for (slice = 0; slice < c->slices; slice++) { ++ uint8_t *dest; ++ int slice_data_start, slice_data_end, slice_size; ++ ++ sstart = send; ++ send = (height * (slice + 1) / c->slices) & cmask; ++ dest = dst + sstart * stride; ++ ++ // slice offset and size validation was done earlier ++ slice_data_start = slice ? AV_RL32(src + slice * 4 - 4) : 0; ++ slice_data_end = AV_RL32(src + slice * 4); ++ slice_size = slice_data_end - slice_data_start; ++ ++ if (!slice_size) { ++ for (j = sstart; j < send; j++) { ++ for (i = 0; i < width * step; i += step) ++ dest[i] = 0x80; ++ dest += stride; ++ } ++ continue; ++ } ++ ++ memcpy(c->slice_bits, src + slice_data_start + c->slices * 4, slice_size); ++ memset(c->slice_bits + slice_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); ++ c->dsp.bswap_buf((uint32_t*)c->slice_bits, (uint32_t*)c->slice_bits, ++ (slice_data_end - slice_data_start + 3) >> 2); ++ init_get_bits(&gb, c->slice_bits, slice_size * 8); ++ ++ prev = 0x80; ++ for (j = sstart; j < send; j++) { ++ for (i = 0; i < width * step; i += step) { ++ if (get_bits_left(&gb) <= 0) { ++ av_log(c->avctx, AV_LOG_ERROR, "Slice decoding ran out of bits\n"); ++ goto fail; ++ } ++ pix = get_vlc2(&gb, vlc.table, vlc.bits, 4); ++ if (pix < 0) { ++ av_log(c->avctx, AV_LOG_ERROR, "Decoding error\n"); ++ goto fail; ++ } ++ if (use_pred) { ++ prev += pix; ++ pix = prev; ++ } ++ dest[i] = pix; ++ } ++ dest += stride; ++ } ++ if (get_bits_left(&gb) > 32) ++ av_log(c->avctx, AV_LOG_WARNING, "%d bits left after decoding slice\n", ++ get_bits_left(&gb)); ++ } ++ ++ free_vlc(&vlc); ++ ++ return 0; ++fail: ++ free_vlc(&vlc); ++ return AVERROR_INVALIDDATA; ++} ++ ++static const int rgb_order[4] = { 1, 2, 0, 3 }; ++ ++static void restore_rgb_planes(uint8_t *src, int step, int stride, int width, int height) ++{ ++ int i, j; ++ uint8_t r, g, b; ++ ++ for (j = 0; j < height; j++) { ++ for (i = 0; i < width * step; i += step) { ++ r = src[i]; ++ g = src[i + 1]; ++ b = src[i + 2]; ++ src[i] = r + g - 0x80; ++ src[i + 2] = b + g - 0x80; ++ } ++ src += stride; ++ } ++} ++ ++static void restore_median(uint8_t *src, int step, int stride, ++ int width, int height, int slices, int rmode) ++{ ++ int i, j, slice; ++ int A, B, C; ++ uint8_t *bsrc; ++ int slice_start, slice_height; ++ const int cmask = ~rmode; ++ ++ for (slice = 0; slice < slices; slice++) { ++ slice_start = ((slice * height) / slices) & cmask; ++ slice_height = ((((slice + 1) * height) / slices) & cmask) - slice_start; ++ ++ bsrc = src + slice_start * stride; ++ ++ // first line - left neighbour prediction ++ bsrc[0] += 0x80; ++ A = bsrc[0]; ++ for (i = step; i < width * step; i += step) { ++ bsrc[i] += A; ++ A = bsrc[i]; ++ } ++ bsrc += stride; ++ if (slice_height == 1) ++ continue; ++ // second line - first element has top predition, the rest uses median ++ C = bsrc[-stride]; ++ bsrc[0] += C; ++ A = bsrc[0]; ++ for (i = step; i < width * step; i += step) { ++ B = bsrc[i - stride]; ++ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[i]; ++ } ++ bsrc += stride; ++ // the rest of lines use continuous median prediction ++ for (j = 2; j < slice_height; j++) { ++ for (i = 0; i < width * step; i += step) { ++ B = bsrc[i - stride]; ++ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[i]; ++ } ++ bsrc += stride; ++ } ++ } ++} ++ ++/* UtVideo interlaced mode treats every two lines as a single one, ++ * so restoring function should take care of possible padding between ++ * two parts of the same "line". ++ */ ++static void restore_median_il(uint8_t *src, int step, int stride, ++ int width, int height, int slices, int rmode) ++{ ++ int i, j, slice; ++ int A, B, C; ++ uint8_t *bsrc; ++ int slice_start, slice_height; ++ const int cmask = ~(rmode ? 3 : 1); ++ const int stride2 = stride << 1; ++ ++ for (slice = 0; slice < slices; slice++) { ++ slice_start = ((slice * height) / slices) & cmask; ++ slice_height = ((((slice + 1) * height) / slices) & cmask) - slice_start; ++ slice_height >>= 1; ++ ++ bsrc = src + slice_start * stride; ++ ++ // first line - left neighbour prediction ++ bsrc[0] += 0x80; ++ A = bsrc[0]; ++ for (i = step; i < width * step; i += step) { ++ bsrc[i] += A; ++ A = bsrc[i]; ++ } ++ for (i = 0; i < width * step; i += step) { ++ bsrc[stride + i] += A; ++ A = bsrc[stride + i]; ++ } ++ bsrc += stride2; ++ if (slice_height == 1) ++ continue; ++ // second line - first element has top predition, the rest uses median ++ C = bsrc[-stride2]; ++ bsrc[0] += C; ++ A = bsrc[0]; ++ for (i = step; i < width * step; i += step) { ++ B = bsrc[i - stride2]; ++ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[i]; ++ } ++ for (i = 0; i < width * step; i += step) { ++ B = bsrc[i - stride]; ++ bsrc[stride + i] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[stride + i]; ++ } ++ bsrc += stride2; ++ // the rest of lines use continuous median prediction ++ for (j = 2; j < slice_height; j++) { ++ for (i = 0; i < width * step; i += step) { ++ B = bsrc[i - stride2]; ++ bsrc[i] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[i]; ++ } ++ for (i = 0; i < width * step; i += step) { ++ B = bsrc[i - stride]; ++ bsrc[i + stride] += mid_pred(A, B, (uint8_t)(A + B - C)); ++ C = B; ++ A = bsrc[i + stride]; ++ } ++ bsrc += stride2; ++ } ++ } ++} ++ ++static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) ++{ ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ const uint8_t *buf_end = buf + buf_size; ++ UtvideoContext *c = avctx->priv_data; ++ const uint8_t *ptr; ++ int i, j; ++ const uint8_t *plane_start[5]; ++ int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size; ++ int ret; ++ ++ if (c->pic.data[0]) ++ ff_thread_release_buffer(avctx, &c->pic); ++ ++ c->pic.reference = 3; ++ c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; ++ if ((ret = ff_thread_get_buffer(avctx, &c->pic)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ ff_thread_finish_setup(avctx); ++ ++ /* parse plane structure to retrieve frame flags and validate slice offsets */ ++ ptr = buf; ++ for (i = 0; i < c->planes; i++) { ++ plane_start[i] = ptr; ++ if (buf_end - ptr < 256 + 4 * c->slices) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ptr += 256; ++ slice_start = 0; ++ slice_end = 0; ++ for (j = 0; j < c->slices; j++) { ++ slice_end = bytestream_get_le32(&ptr); ++ slice_size = slice_end - slice_start; ++ if (slice_size < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ slice_start = slice_end; ++ max_slice_size = FFMAX(max_slice_size, slice_size); ++ } ++ plane_size = slice_end; ++ if (buf_end - ptr < plane_size) { ++ av_log(avctx, AV_LOG_ERROR, "Plane size is bigger than available data\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ptr += plane_size; ++ } ++ plane_start[c->planes] = ptr; ++ if (buf_end - ptr < c->frame_info_size) { ++ av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ c->frame_info = AV_RL32(ptr); ++ av_log(avctx, AV_LOG_DEBUG, "frame information flags %X\n", c->frame_info); ++ ++ c->frame_pred = (c->frame_info >> 8) & 3; ++ ++ if (c->frame_pred == PRED_GRADIENT) { ++ av_log_ask_for_sample(avctx, "Frame uses gradient prediction\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ av_fast_malloc(&c->slice_bits, &c->slice_bits_size, ++ max_slice_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ ++ if (!c->slice_bits) { ++ av_log(avctx, AV_LOG_ERROR, "Cannot allocate temporary buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ switch (c->avctx->pix_fmt) { ++ case PIX_FMT_RGB24: ++ case PIX_FMT_RGBA: ++ for (i = 0; i < c->planes; i++) { ++ ret = decode_plane(c, i, c->pic.data[0] + rgb_order[i], c->planes, ++ c->pic.linesize[0], avctx->width, avctx->height, ++ plane_start[i], plane_start[i + 1] - plane_start[i], ++ c->frame_pred == PRED_LEFT); ++ if (ret) ++ return ret; ++ if (c->frame_pred == PRED_MEDIAN) ++ restore_median(c->pic.data[0] + rgb_order[i], c->planes, ++ c->pic.linesize[0], avctx->width, avctx->height, ++ c->slices, 0); ++ } ++ restore_rgb_planes(c->pic.data[0], c->planes, c->pic.linesize[0], ++ avctx->width, avctx->height); ++ break; ++ case PIX_FMT_YUV420P: ++ for (i = 0; i < 3; i++) { ++ ret = decode_plane(c, i, c->pic.data[i], 1, ++ c->pic.linesize[i], avctx->width >> !!i, avctx->height >> !!i, ++ plane_start[i], plane_start[i + 1] - plane_start[i], ++ c->frame_pred == PRED_LEFT); ++ if (ret) ++ return ret; ++ if (c->frame_pred == PRED_MEDIAN) { ++ if (!c->interlaced) { ++ restore_median(c->pic.data[i], 1, c->pic.linesize[i], ++ avctx->width >> !!i, avctx->height >> !!i, ++ c->slices, !i); ++ } else { ++ restore_median_il(c->pic.data[i], 1, c->pic.linesize[i], ++ avctx->width >> !!i, ++ avctx->height >> !!i, ++ c->slices, !i); ++ } ++ } ++ } ++ break; ++ case PIX_FMT_YUV422P: ++ for (i = 0; i < 3; i++) { ++ ret = decode_plane(c, i, c->pic.data[i], 1, ++ c->pic.linesize[i], avctx->width >> !!i, avctx->height, ++ plane_start[i], plane_start[i + 1] - plane_start[i], ++ c->frame_pred == PRED_LEFT); ++ if (ret) ++ return ret; ++ if (c->frame_pred == PRED_MEDIAN) { ++ if (!c->interlaced) { ++ restore_median(c->pic.data[i], 1, c->pic.linesize[i], ++ avctx->width >> !!i, avctx->height, ++ c->slices, 0); ++ } else { ++ restore_median_il(c->pic.data[i], 1, c->pic.linesize[i], ++ avctx->width >> !!i, avctx->height, ++ c->slices, 0); ++ } ++ } ++ } ++ break; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = c->pic; ++ ++ /* always report that the buffer was completely consumed */ ++ return buf_size; ++} ++ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ UtvideoContext * const c = avctx->priv_data; ++ ++ c->avctx = avctx; ++ ++ dsputil_init(&c->dsp, avctx); ++ ++ if (avctx->extradata_size < 16) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient extradata size %d, should be at least 16\n", ++ avctx->extradata_size); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ av_log(avctx, AV_LOG_DEBUG, "Encoder version %d.%d.%d.%d\n", ++ avctx->extradata[3], avctx->extradata[2], ++ avctx->extradata[1], avctx->extradata[0]); ++ av_log(avctx, AV_LOG_DEBUG, "Original format %X\n", AV_RB32(avctx->extradata + 4)); ++ c->frame_info_size = AV_RL32(avctx->extradata + 8); ++ c->flags = AV_RL32(avctx->extradata + 12); ++ ++ if (c->frame_info_size != 4) ++ av_log_ask_for_sample(avctx, "Frame info is not 4 bytes\n"); ++ av_log(avctx, AV_LOG_DEBUG, "Encoding parameters %08X\n", c->flags); ++ c->slices = (c->flags >> 24) + 1; ++ c->compression = c->flags & 1; ++ c->interlaced = c->flags & 0x800; ++ ++ c->slice_bits_size = 0; ++ ++ switch (avctx->codec_tag) { ++ case MKTAG('U', 'L', 'R', 'G'): ++ c->planes = 3; ++ avctx->pix_fmt = PIX_FMT_RGB24; ++ break; ++ case MKTAG('U', 'L', 'R', 'A'): ++ c->planes = 4; ++ avctx->pix_fmt = PIX_FMT_RGBA; ++ break; ++ case MKTAG('U', 'L', 'Y', '0'): ++ c->planes = 3; ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ break; ++ case MKTAG('U', 'L', 'Y', '2'): ++ c->planes = 3; ++ avctx->pix_fmt = PIX_FMT_YUV422P; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Unknown Ut Video FOURCC provided (%08X)\n", ++ avctx->codec_tag); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ return 0; ++} ++ ++static av_cold int decode_end(AVCodecContext *avctx) ++{ ++ UtvideoContext * const c = avctx->priv_data; ++ ++ if (c->pic.data[0]) ++ ff_thread_release_buffer(avctx, &c->pic); ++ ++ av_freep(&c->slice_bits); ++ ++ return 0; ++} ++ ++AVCodec ff_utvideo_decoder = { ++ .name = "utvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_UTVIDEO, ++ .priv_data_size = sizeof(UtvideoContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, ++ .long_name = NULL_IF_CONFIG_SMALL("Ut Video"), ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210dec.c 2012-05-14 14:08:54.289339076 +0200 +@@ -22,31 +22,74 @@ + */ + + #include "avcodec.h" ++#include "v210dec.h" + #include "libavutil/bswap.h" + ++#define READ_PIXELS(a, b, c) \ ++ do { \ ++ val = av_le2ne32(*src++); \ ++ *a++ = val & 0x3FF; \ ++ *b++ = (val >> 10) & 0x3FF; \ ++ *c++ = (val >> 20) & 0x3FF; \ ++ } while (0) ++ ++static void v210_planar_unpack_c(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width) ++{ ++ uint32_t val; ++ int i; ++ ++ for( i = 0; i < width-5; i += 6 ){ ++ READ_PIXELS(u, y, v); ++ READ_PIXELS(y, u, y); ++ READ_PIXELS(v, y, u); ++ READ_PIXELS(y, v, y); ++ } ++} ++ + static av_cold int decode_init(AVCodecContext *avctx) + { ++ V210DecContext *s = avctx->priv_data; ++ + if (avctx->width & 1) { + av_log(avctx, AV_LOG_ERROR, "v210 needs even width\n"); + return -1; + } +- avctx->pix_fmt = PIX_FMT_YUV422P16; ++ avctx->pix_fmt = PIX_FMT_YUV422P10; + avctx->bits_per_raw_sample = 10; + + avctx->coded_frame = avcodec_alloc_frame(); + ++ s->unpack_frame = v210_planar_unpack_c; ++ ++ if (HAVE_MMX) ++ v210_x86_init(s); ++ + return 0; + } + + static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) + { +- int h, w; ++ V210DecContext *s = avctx->priv_data; ++ ++ int h, w, stride, aligned_input; + AVFrame *pic = avctx->coded_frame; + const uint8_t *psrc = avpkt->data; + uint16_t *y, *u, *v; +- int aligned_width = ((avctx->width + 47) / 48) * 48; +- int stride = aligned_width * 8 / 3; ++ ++ if (s->custom_stride ) ++ stride = s->custom_stride; ++ else { ++ int aligned_width = ((avctx->width + 47) / 48) * 48; ++ stride = aligned_width * 8 / 3; ++ } ++ ++ aligned_input = !((uintptr_t)psrc & 0xf) && !(stride & 0xf); ++ if (aligned_input != s->aligned_input) { ++ s->aligned_input = aligned_input; ++ if (HAVE_MMX) ++ v210_x86_init(s); ++ } + + if (pic->data[0]) + avctx->release_buffer(avctx, pic); +@@ -63,39 +106,34 @@ + y = (uint16_t*)pic->data[0]; + u = (uint16_t*)pic->data[1]; + v = (uint16_t*)pic->data[2]; +- pic->pict_type = FF_I_TYPE; ++ pic->pict_type = AV_PICTURE_TYPE_I; + pic->key_frame = 1; + +-#define READ_PIXELS(a, b, c) \ +- do { \ +- val = av_le2ne32(*src++); \ +- *a++ = val << 6; \ +- *b++ = (val >> 4) & 0xFFC0; \ +- *c++ = (val >> 14) & 0xFFC0; \ +- } while (0) +- + for (h = 0; h < avctx->height; h++) { + const uint32_t *src = (const uint32_t*)psrc; + uint32_t val; +- for (w = 0; w < avctx->width - 5; w += 6) { +- READ_PIXELS(u, y, v); +- READ_PIXELS(y, u, y); +- READ_PIXELS(v, y, u); +- READ_PIXELS(y, v, y); +- } ++ ++ w = (avctx->width / 6) * 6; ++ s->unpack_frame(src, y, u, v, w); ++ ++ y += w; ++ u += w >> 1; ++ v += w >> 1; ++ src += (w << 1) / 3; ++ + if (w < avctx->width - 1) { + READ_PIXELS(u, y, v); + + val = av_le2ne32(*src++); +- *y++ = val << 6; +- } +- if (w < avctx->width - 3) { +- *u++ = (val >> 4) & 0xFFC0; +- *y++ = (val >> 14) & 0xFFC0; +- +- val = av_le2ne32(*src++); +- *v++ = val << 6; +- *y++ = (val >> 4) & 0xFFC0; ++ *y++ = val & 0x3FF; ++ if (w < avctx->width - 3) { ++ *u++ = (val >> 10) & 0x3FF; ++ *y++ = (val >> 20) & 0x3FF; ++ ++ val = av_le2ne32(*src++); ++ *v++ = val & 0x3FF; ++ *y++ = (val >> 10) & 0x3FF; ++ } + } + + psrc += stride; +@@ -120,15 +158,29 @@ + return 0; + } + ++#define V210DEC_FLAGS AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM ++static const AVOption v210dec_options[] = { ++ {"custom_stride", "Custom V210 stride", offsetof(V210DecContext, custom_stride), FF_OPT_TYPE_INT, ++ {.dbl = 0}, INT_MIN, INT_MAX, V210DEC_FLAGS}, ++ {NULL} ++}; ++ ++static const AVClass v210dec_class = { ++ "V210 Decoder", ++ av_default_item_name, ++ v210dec_options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ + AVCodec ff_v210_decoder = { +- "v210", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_V210, +- 0, +- decode_init, +- NULL, +- decode_close, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "v210", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V210, ++ .priv_data_size = sizeof(V210DecContext), ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"), ++ .priv_class = &v210dec_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210dec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210dec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210dec.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210dec.h 2012-05-14 14:08:54.289339076 +0200 +@@ -0,0 +1,34 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_V210DEC_H ++#define AVCODEC_V210DEC_H ++ ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ ++typedef struct { ++ AVClass *av_class; ++ int custom_stride; ++ int aligned_input; ++ void (*unpack_frame)(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width); ++} V210DecContext; ++ ++void v210_x86_init(V210DecContext *s); ++ ++#endif /* AVCODEC_V210DEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210enc.c 2012-05-14 14:08:54.290339096 +0200 +@@ -22,7 +22,7 @@ + */ + + #include "avcodec.h" +-#include "libavcodec/bytestream.h" ++#include "bytestream.h" + + static av_cold int encode_init(AVCodecContext *avctx) + { +@@ -31,8 +31,8 @@ + return -1; + } + +- if (avctx->pix_fmt != PIX_FMT_YUV422P16) { +- av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P16\n"); ++ if (avctx->pix_fmt != PIX_FMT_YUV422P10) { ++ av_log(avctx, AV_LOG_ERROR, "v210 needs YUV422P10\n"); + return -1; + } + +@@ -43,7 +43,7 @@ + avctx->coded_frame = avcodec_alloc_frame(); + + avctx->coded_frame->key_frame = 1; +- avctx->coded_frame->pict_type = FF_I_TYPE; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; + + return 0; + } +@@ -66,11 +66,13 @@ + return -1; + } + ++#define CLIP(v) av_clip(v, 4, 1019) ++ + #define WRITE_PIXELS(a, b, c) \ + do { \ +- val = (*a++ >> 6) | \ +- ((*b++ & 0xFFC0) << 4); \ +- val|= (*c++ & 0xFFC0) << 14; \ ++ val = CLIP(*a++); \ ++ val |= (CLIP(*b++) << 10) | \ ++ (CLIP(*c++) << 20); \ + bytestream_put_le32(&p, val); \ + } while (0) + +@@ -85,18 +87,16 @@ + if (w < avctx->width - 1) { + WRITE_PIXELS(u, y, v); + +- val = *y++ >> 6; ++ val = CLIP(*y++); + if (w == avctx->width - 2) + bytestream_put_le32(&p, val); +- } +- if (w < avctx->width - 3) { +- val |=((*u++ & 0xFFC0) << 4) | +- ((*y++ & 0xFFC0) << 14); +- bytestream_put_le32(&p, val); +- +- val = (*v++ >> 6) | +- (*y++ & 0xFFC0) << 4; +- bytestream_put_le32(&p, val); ++ if (w < avctx->width - 3) { ++ val |= (CLIP(*u++) << 10) | (CLIP(*y++) << 20); ++ bytestream_put_le32(&p, val); ++ ++ val = CLIP(*v++) | (CLIP(*y++) << 10); ++ bytestream_put_le32(&p, val); ++ } + } + + pdst += stride; +@@ -118,13 +118,12 @@ + } + + AVCodec ff_v210_encoder = { +- "v210", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_V210, +- 0, +- encode_init, +- encode_frame, +- encode_close, +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P16, PIX_FMT_NONE}, ++ .name = "v210", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V210, ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_close, ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_YUV422P10, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210x.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210x.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v210x.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v210x.c 2012-05-14 14:08:54.291339116 +0200 +@@ -52,7 +52,7 @@ + } + + if(avpkt->size > avctx->width * avctx->height * 8 / 3){ +- av_log(avctx, AV_LOG_ERROR, "Probably padded data, need sample!\n"); ++ av_log_ask_for_sample(avctx, "Probably padded data\n"); + } + + pic->reference= 0; +@@ -63,7 +63,7 @@ + udst= (uint16_t *)pic->data[1]; + vdst= (uint16_t *)pic->data[2]; + yend= ydst + width; +- pic->pict_type= FF_I_TYPE; ++ pic->pict_type= AV_PICTURE_TYPE_I; + pic->key_frame= 1; + + for(;;){ +@@ -133,14 +133,12 @@ + } + + AVCodec ff_v210x_decoder = { +- "v210x", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_V210X, +- 0, +- decode_init, +- NULL, +- decode_close, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "v210x", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V210X, ++ .init = decode_init, ++ .close = decode_close, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:2:2 10-bit"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v308dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v308dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v308dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v308dec.c 2012-05-14 14:08:54.292339136 +0200 +@@ -0,0 +1,108 @@ ++/* ++ * v308 decoder ++ * Copyright (c) 2011 Carl Eugen Hoyos ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++static av_cold int v308_decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV444P; ++ ++ if (avctx->width & 1) ++ av_log(avctx, AV_LOG_WARNING, "v308 requires width to be even.\n"); ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int v308_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ AVFrame *pic = avctx->coded_frame; ++ const uint8_t *src = avpkt->data; ++ uint8_t *y, *u, *v; ++ int i, j; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ if (avpkt->size < 3 * avctx->height * avctx->width) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ pic->reference = 0; ++ ++ if (avctx->get_buffer(avctx, pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ pic->key_frame = 1; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = pic->data[0]; ++ u = pic->data[1]; ++ v = pic->data[2]; ++ ++ for (i = 0; i < avctx->height; i++) { ++ for (j = 0; j < avctx->width; j++) { ++ v[j] = *src++; ++ y[j] = *src++; ++ u[j] = *src++; ++ } ++ ++ y += pic->linesize[0]; ++ u += pic->linesize[1]; ++ v += pic->linesize[2]; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int v308_decode_close(AVCodecContext *avctx) ++{ ++ if (avctx->coded_frame->data[0]) ++ avctx->release_buffer(avctx, avctx->coded_frame); ++ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_v308_decoder = { ++ .name = "v308", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V308, ++ .init = v308_decode_init, ++ .decode = v308_decode_frame, ++ .close = v308_decode_close, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v308enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v308enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v308enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v308enc.c 2012-05-14 14:08:54.292339136 +0200 +@@ -0,0 +1,96 @@ ++/* ++ * v308 encoder ++ * ++ * Copyright (c) 2011 Carl Eugen Hoyos ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++ ++static av_cold int v308_encode_init(AVCodecContext *avctx) ++{ ++ if (avctx->width & 1) { ++ av_log(avctx, AV_LOG_ERROR, "v308 requires width to be even.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int v308_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ uint8_t *dst = buf; ++ uint8_t *y, *u, *v; ++ int i, j; ++ int output_size = 0; ++ ++ if (buf_size < avctx->width * avctx->height * 3) { ++ av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->reference = 0; ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = pic->data[0]; ++ u = pic->data[1]; ++ v = pic->data[2]; ++ ++ for (i = 0; i < avctx->height; i++) { ++ for (j = 0; j < avctx->width; j++) { ++ *dst++ = v[j]; ++ *dst++ = y[j]; ++ *dst++ = u[j]; ++ output_size += 3; ++ } ++ y += pic->linesize[0]; ++ u += pic->linesize[1]; ++ v += pic->linesize[2]; ++ } ++ ++ return output_size; ++} ++ ++static av_cold int v308_encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_v308_encoder = { ++ .name = "v308", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V308, ++ .init = v308_encode_init, ++ .encode = v308_encode_frame, ++ .close = v308_encode_close, ++ .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:4:4"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v410dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v410dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v410dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v410dec.c 2012-05-14 14:08:54.293339156 +0200 +@@ -0,0 +1,117 @@ ++/* ++ * v410 decoder ++ * ++ * Copyright (c) 2011 Derek Buitenhuis ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++ ++static av_cold int v410_decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV444P10; ++ avctx->bits_per_raw_sample = 10; ++ ++ if (avctx->width & 1) { ++ av_log(avctx, AV_LOG_WARNING, "v410 requires width to be even.\n"); ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int v410_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ AVFrame *pic = avctx->coded_frame; ++ uint8_t *src = avpkt->data; ++ uint16_t *y, *u, *v; ++ uint32_t val; ++ int i, j; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ if (avpkt->size < 4 * avctx->height * avctx->width) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ pic->reference = 0; ++ ++ if (avctx->get_buffer(avctx, pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ pic->key_frame = 1; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = (uint16_t *)pic->data[0]; ++ u = (uint16_t *)pic->data[1]; ++ v = (uint16_t *)pic->data[2]; ++ ++ for (i = 0; i < avctx->height; i++) { ++ for (j = 0; j < avctx->width; j++) { ++ val = AV_RL32(src); ++ ++ u[j] = (val >> 2) & 0x3FF; ++ y[j] = (val >> 12) & 0x3FF; ++ v[j] = (val >> 22); ++ ++ src += 4; ++ } ++ ++ y += pic->linesize[0] >> 1; ++ u += pic->linesize[1] >> 1; ++ v += pic->linesize[2] >> 1; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int v410_decode_close(AVCodecContext *avctx) ++{ ++ if (avctx->coded_frame->data[0]) ++ avctx->release_buffer(avctx, avctx->coded_frame); ++ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_v410_decoder = { ++ .name = "v410", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V410, ++ .init = v410_decode_init, ++ .decode = v410_decode_frame, ++ .close = v410_decode_close, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v410enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v410enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/v410enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/v410enc.c 2012-05-14 14:08:54.293339156 +0200 +@@ -0,0 +1,99 @@ ++/* ++ * v410 encoder ++ * ++ * Copyright (c) 2011 Derek Buitenhuis ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avcodec.h" ++ ++static av_cold int v410_encode_init(AVCodecContext *avctx) ++{ ++ if (avctx->width & 1) { ++ av_log(avctx, AV_LOG_ERROR, "v410 requires width to be even.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int v410_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ uint8_t *dst = buf; ++ uint16_t *y, *u, *v; ++ uint32_t val; ++ int i, j; ++ int output_size = 0; ++ ++ if (buf_size < avctx->width * avctx->height * 4) { ++ av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->reference = 0; ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = (uint16_t *)pic->data[0]; ++ u = (uint16_t *)pic->data[1]; ++ v = (uint16_t *)pic->data[2]; ++ ++ for (i = 0; i < avctx->height; i++) { ++ for (j = 0; j < avctx->width; j++) { ++ val = u[j] << 2; ++ val |= y[j] << 12; ++ val |= (uint32_t) v[j] << 22; ++ AV_WL32(dst, val); ++ dst += 4; ++ output_size += 4; ++ } ++ y += pic->linesize[0] >> 1; ++ u += pic->linesize[1] >> 1; ++ v += pic->linesize[2] >> 1; ++ } ++ ++ return output_size; ++} ++ ++static av_cold int v410_encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_v410_encoder = { ++ .name = "v410", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_V410, ++ .init = v410_encode_init, ++ .encode = v410_encode_frame, ++ .close = v410_encode_close, ++ .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV444P10, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed 4:4:4 10-bit"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi.c 2012-05-14 14:08:54.294339176 +0200 +@@ -24,7 +24,7 @@ + #include "vaapi_internal.h" + + /** +- * \addtogroup VAAPI_Decoding ++ * @addtogroup VAAPI_Decoding + * + * @{ + */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi.h 2012-05-14 14:08:54.294339176 +0200 +@@ -27,8 +27,8 @@ + #include + + /** +- * \defgroup VAAPI_Decoding VA API Decoding +- * \ingroup Decoder ++ * @defgroup VAAPI_Decoding VA API Decoding ++ * @ingroup Decoder + * @{ + */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_h264.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_h264.c 2012-05-14 14:08:54.295339197 +0200 +@@ -23,9 +23,10 @@ + #include "vaapi_internal.h" + #include "h264.h" + +-/** @file +- * This file implements the glue code between FFmpeg's and VA API's +- * structures for H.264 decoding. ++/** ++ * @file ++ * This file implements the glue code between FFmpeg's and VA API's ++ * structures for H.264 decoding. + */ + + /** +@@ -54,7 +55,8 @@ + int pic_structure) + { + if (pic_structure == 0) +- pic_structure = pic->reference; ++ pic_structure = pic->f.reference; ++ pic_structure &= PICT_FRAME; /* PICT_TOP_FIELD|PICT_BOTTOM_FIELD */ + + va_pic->picture_id = ff_vaapi_get_surface_id(pic); + va_pic->frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num; +@@ -62,7 +64,7 @@ + va_pic->flags = 0; + if (pic_structure != PICT_FRAME) + va_pic->flags |= (pic_structure & PICT_TOP_FIELD) ? VA_PICTURE_H264_TOP_FIELD : VA_PICTURE_H264_BOTTOM_FIELD; +- if (pic->reference) ++ if (pic->f.reference) + va_pic->flags |= pic->long_ref ? VA_PICTURE_H264_LONG_TERM_REFERENCE : VA_PICTURE_H264_SHORT_TERM_REFERENCE; + + va_pic->TopFieldOrderCnt = 0; +@@ -132,13 +134,13 @@ + + for (i = 0; i < h->short_ref_count; i++) { + Picture * const pic = h->short_ref[i]; +- if (pic && pic->reference && dpb_add(&dpb, pic) < 0) ++ if (pic && pic->f.reference && dpb_add(&dpb, pic) < 0) + return -1; + } + + for (i = 0; i < 16; i++) { + Picture * const pic = h->long_ref[i]; +- if (pic && pic->reference && dpb_add(&dpb, pic) < 0) ++ if (pic && pic->f.reference && dpb_add(&dpb, pic) < 0) + return -1; + } + return 0; +@@ -158,7 +160,7 @@ + { + unsigned int i, n = 0; + for (i = 0; i < ref_count; i++) +- if (ref_list[i].reference) ++ if (ref_list[i].f.reference) + fill_vaapi_pic(&RefPicList[n++], &ref_list[i], 0); + + for (; n < 32; n++) +@@ -280,7 +282,8 @@ + if (!iq_matrix) + return -1; + memcpy(iq_matrix->ScalingList4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->ScalingList4x4)); +- memcpy(iq_matrix->ScalingList8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->ScalingList8x8)); ++ memcpy(iq_matrix->ScalingList8x8[0], h->pps.scaling_matrix8[0], sizeof(iq_matrix->ScalingList8x8[0])); ++ memcpy(iq_matrix->ScalingList8x8[1], h->pps.scaling_matrix8[3], sizeof(iq_matrix->ScalingList8x8[0])); + return 0; + } + +@@ -311,7 +314,7 @@ + slice_param->slice_data_bit_offset = get_bits_count(&h->s.gb) + 8; /* bit buffer started beyond nal_unit_type */ + slice_param->first_mb_in_slice = (s->mb_y >> FIELD_OR_MBAFF_PICTURE) * s->mb_width + s->mb_x; + slice_param->slice_type = ff_h264_get_slice_type(h); +- slice_param->direct_spatial_mv_pred_flag = h->slice_type == FF_B_TYPE ? h->direct_spatial_mv_pred : 0; ++ slice_param->direct_spatial_mv_pred_flag = h->slice_type == AV_PICTURE_TYPE_B ? h->direct_spatial_mv_pred : 0; + slice_param->num_ref_idx_l0_active_minus1 = h->list_count > 0 ? h->ref_count[0] - 1 : 0; + slice_param->num_ref_idx_l1_active_minus1 = h->list_count > 1 ? h->ref_count[1] - 1 : 0; + slice_param->cabac_init_idc = h->cabac_init_idc; +@@ -339,9 +342,7 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .end_frame = end_frame, + .decode_slice = decode_slice, +- .priv_data_size = 0, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_internal.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_internal.h 2012-05-14 14:08:54.296339217 +0200 +@@ -30,7 +30,7 @@ + #include "mpegvideo.h" + + /** +- * \addtogroup VAAPI_Decoding ++ * @addtogroup VAAPI_Decoding + * + * @{ + */ +@@ -38,7 +38,7 @@ + /** Extract VASurfaceID from a Picture */ + static inline VASurfaceID ff_vaapi_get_surface_id(Picture *pic) + { +- return (uintptr_t)pic->data[3]; ++ return (uintptr_t)pic->f.data[3]; + } + + /** Common AVHWAccel.end_frame() implementation */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_mpeg2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_mpeg2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_mpeg2.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_mpeg2.c 2012-05-14 14:08:54.297339237 +0200 +@@ -26,8 +26,8 @@ + /** Reconstruct bitstream f_code */ + static inline int mpeg2_get_f_code(MpegEncContext *s) + { +- return ((s->mpeg_f_code[0][0] << 12) | (s->mpeg_f_code[0][1] << 8) | +- (s->mpeg_f_code[1][0] << 4) | s->mpeg_f_code[1][1]); ++ return (s->mpeg_f_code[0][0] << 12) | (s->mpeg_f_code[0][1] << 8) | ++ (s->mpeg_f_code[1][0] << 4) | s->mpeg_f_code[1][1]; + } + + /** Determine frame start: first field for field picture or frame picture */ +@@ -72,10 +72,10 @@ + pic_param->picture_coding_extension.bits.is_first_field = mpeg2_get_is_frame_start(s); + + switch (s->pict_type) { +- case FF_B_TYPE: ++ case AV_PICTURE_TYPE_B: + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); + // fall-through +- case FF_P_TYPE: ++ case AV_PICTURE_TYPE_P: + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); + break; + } +@@ -143,9 +143,7 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_MPEG2VIDEO, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = vaapi_mpeg2_start_frame, + .end_frame = vaapi_mpeg2_end_frame, + .decode_slice = vaapi_mpeg2_decode_slice, +- .priv_data_size = 0, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_mpeg4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_mpeg4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_mpeg4.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_mpeg4.c 2012-05-14 14:08:54.298339257 +0200 +@@ -78,8 +78,8 @@ + } + pic_param->quant_precision = s->quant_precision; + pic_param->vop_fields.value = 0; /* reset all bits */ +- pic_param->vop_fields.bits.vop_coding_type = s->pict_type - FF_I_TYPE; +- pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == FF_B_TYPE ? s->next_picture.pict_type - FF_I_TYPE : 0; ++ pic_param->vop_fields.bits.vop_coding_type = s->pict_type - AV_PICTURE_TYPE_I; ++ pic_param->vop_fields.bits.backward_reference_vop_coding_type = s->pict_type == AV_PICTURE_TYPE_B ? s->next_picture.f.pict_type - AV_PICTURE_TYPE_I : 0; + pic_param->vop_fields.bits.vop_rounding_type = s->no_rounding; + pic_param->vop_fields.bits.intra_dc_vlc_thr = mpeg4_get_intra_dc_vlc_thr(s); + pic_param->vop_fields.bits.top_field_first = s->top_field_first; +@@ -92,13 +92,13 @@ + pic_param->TRB = s->pb_time; + pic_param->TRD = s->pp_time; + +- if (s->pict_type == FF_B_TYPE) ++ if (s->pict_type == AV_PICTURE_TYPE_B) + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); +- if (s->pict_type != FF_I_TYPE) ++ if (s->pict_type != AV_PICTURE_TYPE_I) + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); + + /* Fill in VAIQMatrixBufferMPEG4 */ +- /* Only the first inverse quantisation method uses the weighthing matrices */ ++ /* Only the first inverse quantisation method uses the weighting matrices */ + if (pic_param->vol_fields.bits.quant_type) { + iq_matrix = ff_vaapi_alloc_iq_matrix(vactx, sizeof(VAIQMatrixBufferMPEG4)); + if (!iq_matrix) +@@ -155,11 +155,9 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_MPEG4, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = vaapi_mpeg4_start_frame, + .end_frame = vaapi_mpeg4_end_frame, + .decode_slice = vaapi_mpeg4_decode_slice, +- .priv_data_size = 0, + }; + #endif + +@@ -169,10 +167,8 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H263, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = vaapi_mpeg4_start_frame, + .end_frame = vaapi_mpeg4_end_frame, + .decode_slice = vaapi_mpeg4_decode_slice, +- .priv_data_size = 0, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_vc1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_vc1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vaapi_vc1.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vaapi_vc1.c 2012-05-14 14:08:54.299339277 +0200 +@@ -42,10 +42,10 @@ + { + if (v->mv_type_is_raw) + return 0; +- return (v->s.pict_type == FF_P_TYPE && +- (v->mv_mode == MV_PMODE_MIXED_MV || +- (v->mv_mode == MV_PMODE_INTENSITY_COMP && +- v->mv_mode2 == MV_PMODE_MIXED_MV))); ++ return v->s.pict_type == AV_PICTURE_TYPE_P && ++ (v->mv_mode == MV_PMODE_MIXED_MV || ++ (v->mv_mode == MV_PMODE_INTENSITY_COMP && ++ v->mv_mode2 == MV_PMODE_MIXED_MV)); + } + + /** Check whether the SKIPMB bitplane is present */ +@@ -53,8 +53,8 @@ + { + if (v->skip_is_raw) + return 0; +- return (v->s.pict_type == FF_P_TYPE || +- (v->s.pict_type == FF_B_TYPE && !v->bi_type)); ++ return v->s.pict_type == AV_PICTURE_TYPE_P || ++ (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type); + } + + /** Check whether the DIRECTMB bitplane is present */ +@@ -62,7 +62,7 @@ + { + if (v->dmb_is_raw) + return 0; +- return v->s.pict_type == FF_B_TYPE && !v->bi_type; ++ return v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type; + } + + /** Check whether the ACPRED bitplane is present */ +@@ -70,9 +70,9 @@ + { + if (v->acpred_is_raw) + return 0; +- return (v->profile == PROFILE_ADVANCED && +- (v->s.pict_type == FF_I_TYPE || +- (v->s.pict_type == FF_B_TYPE && v->bi_type))); ++ return v->profile == PROFILE_ADVANCED && ++ (v->s.pict_type == AV_PICTURE_TYPE_I || ++ (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type)); + } + + /** Check whether the OVERFLAGS bitplane is present */ +@@ -80,11 +80,11 @@ + { + if (v->overflg_is_raw) + return 0; +- return (v->profile == PROFILE_ADVANCED && +- (v->s.pict_type == FF_I_TYPE || +- (v->s.pict_type == FF_B_TYPE && v->bi_type)) && +- (v->overlap && v->pq <= 8) && +- v->condover == CONDOVER_SELECT); ++ return v->profile == PROFILE_ADVANCED && ++ (v->s.pict_type == AV_PICTURE_TYPE_I || ++ (v->s.pict_type == AV_PICTURE_TYPE_B && v->bi_type)) && ++ (v->overlap && v->pq <= 8) && ++ v->condover == CONDOVER_SELECT; + } + + /** Reconstruct bitstream PTYPE (7.1.1.4, index into Table-35) */ +@@ -92,9 +92,9 @@ + { + MpegEncContext * const s = &v->s; + switch (s->pict_type) { +- case FF_I_TYPE: return 0; +- case FF_P_TYPE: return v->p_frame_skipped ? 4 : 1; +- case FF_B_TYPE: return v->bi_type ? 3 : 2; ++ case AV_PICTURE_TYPE_I: return 0; ++ case AV_PICTURE_TYPE_P: return v->p_frame_skipped ? 4 : 1; ++ case AV_PICTURE_TYPE_B: return v->bi_type ? 3 : 2; + } + return 0; + } +@@ -102,8 +102,8 @@ + /** Reconstruct bitstream MVMODE (7.1.1.32) */ + static inline VAMvModeVC1 vc1_get_MVMODE(VC1Context *v) + { +- if (v->s.pict_type == FF_P_TYPE || +- (v->s.pict_type == FF_B_TYPE && !v->bi_type)) ++ if (v->s.pict_type == AV_PICTURE_TYPE_P || ++ (v->s.pict_type == AV_PICTURE_TYPE_B && !v->bi_type)) + return get_VAMvModeVC1(v->mv_mode); + return 0; + } +@@ -111,7 +111,7 @@ + /** Reconstruct bitstream MVMODE2 (7.1.1.33) */ + static inline VAMvModeVC1 vc1_get_MVMODE2(VC1Context *v) + { +- if (v->s.pict_type == FF_P_TYPE && v->mv_mode == MV_PMODE_INTENSITY_COMP) ++ if (v->s.pict_type == AV_PICTURE_TYPE_P && v->mv_mode == MV_PMODE_INTENSITY_COMP) + return get_VAMvModeVC1(v->mv_mode2); + return 0; + } +@@ -257,10 +257,10 @@ + pic_param->transform_fields.bits.intra_transform_dc_table = v->s.dc_table_index; + + switch (s->pict_type) { +- case FF_B_TYPE: ++ case AV_PICTURE_TYPE_B: + pic_param->backward_reference_picture = ff_vaapi_get_surface_id(&s->next_picture); + // fall-through +- case FF_P_TYPE: ++ case AV_PICTURE_TYPE_P: + pic_param->forward_reference_picture = ff_vaapi_get_surface_id(&s->last_picture); + break; + } +@@ -271,12 +271,12 @@ + int x, y, n; + + switch (s->pict_type) { +- case FF_P_TYPE: ++ case AV_PICTURE_TYPE_P: + ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; + ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; + ff_bp[2] = pic_param->bitplane_present.flags.bp_mv_type_mb ? v->mv_type_mb_plane : NULL; + break; +- case FF_B_TYPE: ++ case AV_PICTURE_TYPE_B: + if (!v->bi_type) { + ff_bp[0] = pic_param->bitplane_present.flags.bp_direct_mb ? v->direct_mb_plane : NULL; + ff_bp[1] = pic_param->bitplane_present.flags.bp_skip_mb ? s->mbskip_table : NULL; +@@ -284,7 +284,7 @@ + break; + } + /* fall-through (BI-type) */ +- case FF_I_TYPE: ++ case AV_PICTURE_TYPE_I: + ff_bp[0] = NULL; /* XXX: interlaced frame (FIELDTX plane) */ + ff_bp[1] = pic_param->bitplane_present.flags.bp_ac_pred ? v->acpred_plane : NULL; + ff_bp[2] = pic_param->bitplane_present.flags.bp_overflags ? v->over_flags_plane : NULL; +@@ -346,11 +346,9 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_WMV3, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = vaapi_vc1_start_frame, + .end_frame = vaapi_vc1_end_frame, + .decode_slice = vaapi_vc1_decode_slice, +- .priv_data_size = 0, + }; + #endif + +@@ -359,9 +357,7 @@ + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_VC1, + .pix_fmt = PIX_FMT_VAAPI_VLD, +- .capabilities = 0, + .start_frame = vaapi_vc1_start_frame, + .end_frame = vaapi_vc1_end_frame, + .decode_slice = vaapi_vc1_decode_slice, +- .priv_data_size = 0, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vb.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vb.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vb.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vb.c 2012-05-14 14:08:54.300339297 +0200 +@@ -44,7 +44,7 @@ + + uint8_t *frame, *prev_frame; + uint32_t pal[AVPALETTE_COUNT]; +- const uint8_t *stream; ++ GetByteContext stream; + } VBDecContext; + + static const uint16_t vb_patterns[64] = { +@@ -62,8 +62,8 @@ + { + int start, size, i; + +- start = bytestream_get_byte(&c->stream); +- size = (bytestream_get_byte(&c->stream) - 1) & 0xFF; ++ start = bytestream2_get_byte(&c->stream); ++ size = (bytestream2_get_byte(&c->stream) - 1) & 0xFF; + if(start + size > 255){ + av_log(c->avctx, AV_LOG_ERROR, "Palette change runs beyond entry 256\n"); + return; +@@ -73,7 +73,7 @@ + return; + } + for(i = start; i <= start + size; i++) +- c->pal[i] = bytestream_get_be24(&c->stream); ++ c->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&c->stream); + } + + static inline int check_pixel(uint8_t *buf, uint8_t *start, uint8_t *end) +@@ -86,10 +86,10 @@ + return buf >= start && (buf + 4) <= end; + } + +-static int vb_decode_framedata(VBDecContext *c, const uint8_t *buf, int data_size, int offset) ++static int vb_decode_framedata(VBDecContext *c, int offset) + { ++ GetByteContext g; + uint8_t *prev, *cur; +- const uint8_t* data_end = buf + data_size; + int blk, blocks, t, blk2; + int blocktypes = 0; + int x, y, a, b; +@@ -98,6 +98,8 @@ + uint8_t *pstart = c->prev_frame; + uint8_t *pend = c->prev_frame + width*c->avctx->height; + ++ g = c->stream; ++ + prev = c->prev_frame + offset; + cur = c->frame; + +@@ -105,11 +107,7 @@ + blk2 = 0; + for(blk = 0; blk < blocks; blk++){ + if(!(blk & 3)) { +- if(buf >= data_end){ +- av_log(c->avctx, AV_LOG_ERROR, "Data pointer out of bounds\n"); +- return -1; +- } +- blocktypes = bytestream_get_byte(&buf); ++ blocktypes = bytestream2_get_byte(&g); + } + switch(blocktypes & 0xC0){ + case 0x00: //skip +@@ -120,15 +118,14 @@ + memset(cur + y*width, 0, 4); + break; + case 0x40: +- t = bytestream_get_byte(&buf); ++ t = bytestream2_get_byte(&g); + if(!t){ //raw block +- if(buf + 16 > data_end){ ++ if (bytestream2_get_bytes_left(&g) < 16) { + av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); + return -1; + } + for(y = 0; y < 4; y++) +- memcpy(cur + y*width, buf + y*4, 4); +- buf += 16; ++ bytestream2_get_buffer(&g, cur + y * width, 4); + }else{ // motion compensation + x = ((t & 0xF)^8) - 8; + y = ((t >> 4) ^8) - 8; +@@ -141,22 +138,18 @@ + } + break; + case 0x80: // fill +- t = bytestream_get_byte(&buf); ++ t = bytestream2_get_byte(&g); + for(y = 0; y < 4; y++) + memset(cur + y*width, t, 4); + break; + case 0xC0: // pattern fill +- if(buf + 2 > data_end){ +- av_log(c->avctx, AV_LOG_ERROR, "Insufficient data\n"); +- return -1; +- } +- t = bytestream_get_byte(&buf); ++ t = bytestream2_get_byte(&g); + pattype = t >> 6; + pattern = vb_patterns[t & 0x3F]; + switch(pattype){ + case 0: +- a = bytestream_get_byte(&buf); +- b = bytestream_get_byte(&buf); ++ a = bytestream2_get_byte(&g); ++ b = bytestream2_get_byte(&g); + for(y = 0; y < 4; y++) + for(x = 0; x < 4; x++, pattern >>= 1) + cur[x + y*width] = (pattern & 1) ? b : a; +@@ -164,7 +157,7 @@ + case 1: + pattern = ~pattern; + case 2: +- a = bytestream_get_byte(&buf); ++ a = bytestream2_get_byte(&g); + for(y = 0; y < 4; y++) + for(x = 0; x < 4; x++, pattern >>= 1) + if(pattern & 1 && check_pixel(prev + x + y*width, pstart, pend)) +@@ -193,52 +186,42 @@ + + static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) + { +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; + VBDecContext * const c = avctx->priv_data; + uint8_t *outptr, *srcptr; + int i, j; + int flags; + uint32_t size; +- int rest = buf_size; + int offset = 0; + ++ bytestream2_init(&c->stream, avpkt->data, avpkt->size); ++ + if(c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); +- c->pic.reference = 1; ++ c->pic.reference = 3; + if(avctx->get_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } + +- c->stream = buf; +- flags = bytestream_get_le16(&c->stream); +- rest -= 2; ++ flags = bytestream2_get_le16(&c->stream); + + if(flags & VB_HAS_GMC){ +- i = (int16_t)bytestream_get_le16(&c->stream); +- j = (int16_t)bytestream_get_le16(&c->stream); ++ i = (int16_t)bytestream2_get_le16(&c->stream); ++ j = (int16_t)bytestream2_get_le16(&c->stream); + offset = i + j * avctx->width; +- rest -= 4; + } + if(flags & VB_HAS_VIDEO){ +- size = bytestream_get_le32(&c->stream); +- if(size > rest){ +- av_log(avctx, AV_LOG_ERROR, "Frame size is too big\n"); ++ size = bytestream2_get_le32(&c->stream); ++ if(size > bytestream2_get_bytes_left(&c->stream)+4 || size<4){ ++ av_log(avctx, AV_LOG_ERROR, "Frame size invalid\n"); + return -1; + } +- vb_decode_framedata(c, c->stream, size, offset); +- c->stream += size - 4; +- rest -= size; ++ vb_decode_framedata(c, offset); ++ bytestream2_skip(&c->stream, size - 4); + } + if(flags & VB_HAS_PALETTE){ +- size = bytestream_get_le32(&c->stream); +- if(size > rest){ +- av_log(avctx, AV_LOG_ERROR, "Palette size is too big\n"); +- return -1; +- } ++ size = bytestream2_get_le32(&c->stream); + vb_decode_palette(c, size); +- rest -= size; + } + + memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); +@@ -259,7 +242,7 @@ + *(AVFrame*)data = c->pic; + + /* always report that the buffer was completely consumed */ +- return buf_size; ++ return avpkt->size; + } + + static av_cold int decode_init(AVCodecContext *avctx) +@@ -268,6 +251,7 @@ + + c->avctx = avctx; + avctx->pix_fmt = PIX_FMT_PAL8; ++ avcodec_get_frame_defaults(&c->pic); + + c->frame = av_mallocz(avctx->width * avctx->height); + c->prev_frame = av_mallocz(avctx->width * avctx->height); +@@ -288,14 +272,13 @@ + } + + AVCodec ff_vb_decoder = { +- "vb", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VB, +- sizeof(VBDecContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, ++ .name = "vb", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VB, ++ .priv_data_size = sizeof(VBDecContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Beam Software VB"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vble.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vble.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vble.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vble.c 2012-05-14 14:08:54.301339317 +0200 +@@ -0,0 +1,228 @@ ++/* ++ * VBLE Decoder ++ * Copyright (c) 2011 Derek Buitenhuis ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * VBLE Decoder ++ */ ++ ++#define BITSTREAM_READER_LE ++ ++#include "avcodec.h" ++#include "dsputil.h" ++#include "get_bits.h" ++ ++typedef struct { ++ AVCodecContext *avctx; ++ DSPContext dsp; ++ ++ int size; ++ uint8_t *val; ///< This array first holds the lengths of vlc symbols and then their value. ++} VBLEContext; ++ ++static int vble_unpack(VBLEContext *ctx, GetBitContext *gb) ++{ ++ int i; ++ int allbits = 0; ++ static const uint8_t LUT[256] = { ++ 8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0, ++ }; ++ ++ /* Read all the lengths in first */ ++ for (i = 0; i < ctx->size; i++) { ++ /* At most we need to read 9 bits total to get indices up to 8 */ ++ int val = show_bits(gb, 8); ++ ++ // read reverse unary ++ if (val) { ++ val = LUT[val]; ++ skip_bits(gb, val + 1); ++ ctx->val[i] = val; ++ } else { ++ skip_bits(gb, 8); ++ if (!get_bits1(gb)) ++ return -1; ++ ctx->val[i] = 8; ++ } ++ allbits += ctx->val[i]; ++ } ++ ++ /* Check we have enough bits left */ ++ if (get_bits_left(gb) < allbits) ++ return -1; ++ return 0; ++} ++ ++static void vble_restore_plane(VBLEContext *ctx, GetBitContext *gb, int plane, ++ int offset, int width, int height) ++{ ++ AVFrame *pic = ctx->avctx->coded_frame; ++ uint8_t *dst = pic->data[plane]; ++ uint8_t *val = ctx->val + offset; ++ int stride = pic->linesize[plane]; ++ int i, j, left, left_top; ++ ++ for (i = 0; i < height; i++) { ++ for (j = 0; j < width; j++) { ++ /* get_bits can't take a length of 0 */ ++ if (val[j]) { ++ int v = (1 << val[j]) + get_bits(gb, val[j]) - 1; ++ val[j] = (v >> 1) ^ -(v & 1); ++ } ++ } ++ if (i) { ++ left = 0; ++ left_top = dst[-stride]; ++ ctx->dsp.add_hfyu_median_prediction(dst, dst-stride, val, width, &left, &left_top); ++ } else { ++ dst[0] = val[0]; ++ for (j = 1; j < width; j++) ++ dst[j] = val[j] + dst[j - 1]; ++ } ++ dst += stride; ++ val += width; ++ } ++} ++ ++static int vble_decode_frame(AVCodecContext *avctx, void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ VBLEContext *ctx = avctx->priv_data; ++ AVFrame *pic = avctx->coded_frame; ++ GetBitContext gb; ++ const uint8_t *src = avpkt->data; ++ int version; ++ int offset = 0; ++ int width_uv = avctx->width / 2, height_uv = avctx->height / 2; ++ ++ pic->reference = 0; ++ ++ /* Clear buffer if need be */ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ /* Allocate buffer */ ++ if (avctx->get_buffer(avctx, pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ /* Set flags */ ++ pic->key_frame = 1; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ ++ /* Version should always be 1 */ ++ version = AV_RL32(src); ++ ++ if (version != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported VBLE Version: %d\n", version); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ init_get_bits(&gb, src + 4, (avpkt->size - 4) * 8); ++ ++ /* Unpack */ ++ if (vble_unpack(ctx, &gb) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid Code\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* Restore planes. Should be almost identical to Huffyuv's. */ ++ vble_restore_plane(ctx, &gb, 0, offset, avctx->width, avctx->height); ++ ++ /* Chroma */ ++ if (!(ctx->avctx->flags & CODEC_FLAG_GRAY)) { ++ offset += avctx->width * avctx->height; ++ vble_restore_plane(ctx, &gb, 1, offset, width_uv, height_uv); ++ ++ offset += width_uv * height_uv; ++ vble_restore_plane(ctx, &gb, 2, offset, width_uv, height_uv); ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int vble_decode_close(AVCodecContext *avctx) ++{ ++ VBLEContext *ctx = avctx->priv_data; ++ AVFrame *pic = avctx->coded_frame; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ av_freep(&avctx->coded_frame); ++ av_freep(&ctx->val); ++ ++ return 0; ++} ++ ++static av_cold int vble_decode_init(AVCodecContext *avctx) ++{ ++ VBLEContext *ctx = avctx->priv_data; ++ ++ /* Stash for later use */ ++ ctx->avctx = avctx; ++ dsputil_init(&ctx->dsp, avctx); ++ ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ avctx->bits_per_raw_sample = 8; ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ ctx->size = avpicture_get_size(avctx->pix_fmt, ++ avctx->width, avctx->height); ++ ++ ctx->val = av_malloc(ctx->size * sizeof(*ctx->val)); ++ ++ if (!ctx->val) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate values buffer.\n"); ++ vble_decode_close(avctx); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++AVCodec ff_vble_decoder = { ++ .name = "vble", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VBLE, ++ .priv_data_size = sizeof(VBLEContext), ++ .init = vble_decode_init, ++ .close = vble_decode_close, ++ .decode = vble_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("VBLE Lossless Codec"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1.c 2012-05-14 14:08:54.306339418 +0200 +@@ -1,5 +1,6 @@ + /* + * VC-1 and WMV3 decoder common code ++ * Copyright (c) 2011 Mashiat Sarker Shakkhar + * Copyright (c) 2006-2007 Konstantin Shishkov + * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer + * +@@ -25,6 +26,7 @@ + * VC-1 and WMV3 decoder common code + * + */ ++ + #include "internal.h" + #include "dsputil.h" + #include "avcodec.h" +@@ -40,7 +42,7 @@ + + /***********************************************************************/ + /** +- * @defgroup vc1bitplane VC-1 Bitplane decoding ++ * @name VC-1 Bitplane decoding + * @see 8.7, p56 + * @{ + */ +@@ -66,14 +68,16 @@ + * @param[in] height Height of this buffer + * @param[in] stride of this buffer + */ +-static void decode_rowskip(uint8_t* plane, int width, int height, int stride, GetBitContext *gb){ ++static void decode_rowskip(uint8_t* plane, int width, int height, int stride, ++ GetBitContext *gb) ++{ + int x, y; + +- for (y=0; ys.mb_width; +- height = v->s.mb_height; ++ width = v->s.mb_width; ++ height = v->s.mb_height >> v->field_mode; + stride = v->s.mb_stride; + invert = get_bits1(gb); + imode = get_vlc2(gb, ff_vc1_imode_vlc.table, VC1_IMODE_VLC_BITS, 1); + + *raw_flag = 0; +- switch (imode) +- { ++ switch (imode) { + case IMODE_RAW: + //Data is actually read in the MB layer (same for all tests == "raw") + *raw_flag = 1; //invert ignored + return invert; + case IMODE_DIFF2: + case IMODE_NORM2: +- if ((height * width) & 1) +- { ++ if ((height * width) & 1) { + *planep++ = get_bits1(gb); +- offset = 1; ++ offset = 1; + } +- else offset = 0; ++ else ++ offset = 0; + // decode bitplane as one long line + for (y = offset; y < height * width; y += 2) { + code = get_vlc2(gb, ff_vc1_norm2_vlc.table, VC1_NORM2_VLC_BITS, 1); + *planep++ = code & 1; + offset++; +- if(offset == width) { +- offset = 0; ++ if (offset == width) { ++ offset = 0; + planep += stride - width; + } + *planep++ = code >> 1; + offset++; +- if(offset == width) { +- offset = 0; ++ if (offset == width) { ++ offset = 0; + planep += stride - width; + } + } + break; + case IMODE_DIFF6: + case IMODE_NORM6: +- if(!(height % 3) && (width % 3)) { // use 2x3 decoding +- for(y = 0; y < height; y+= 3) { +- for(x = width & 1; x < width; x += 2) { ++ if (!(height % 3) && (width % 3)) { // use 2x3 decoding ++ for (y = 0; y < height; y += 3) { ++ for (x = width & 1; x < width; x += 2) { + code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); +- if(code < 0){ ++ if (code < 0) { + av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); + return -1; + } +- planep[x + 0] = (code >> 0) & 1; +- planep[x + 1] = (code >> 1) & 1; +- planep[x + 0 + stride] = (code >> 2) & 1; +- planep[x + 1 + stride] = (code >> 3) & 1; ++ planep[x + 0] = (code >> 0) & 1; ++ planep[x + 1] = (code >> 1) & 1; ++ planep[x + 0 + stride] = (code >> 2) & 1; ++ planep[x + 1 + stride] = (code >> 3) & 1; + planep[x + 0 + stride * 2] = (code >> 4) & 1; + planep[x + 1 + stride * 2] = (code >> 5) & 1; + } + planep += stride * 3; + } +- if(width & 1) decode_colskip(data, 1, height, stride, &v->s.gb); ++ if (width & 1) ++ decode_colskip(data, 1, height, stride, &v->s.gb); + } else { // 3x2 + planep += (height & 1) * stride; +- for(y = height & 1; y < height; y += 2) { +- for(x = width % 3; x < width; x += 3) { ++ for (y = height & 1; y < height; y += 2) { ++ for (x = width % 3; x < width; x += 3) { + code = get_vlc2(gb, ff_vc1_norm6_vlc.table, VC1_NORM6_VLC_BITS, 2); +- if(code < 0){ ++ if (code < 0) { + av_log(v->s.avctx, AV_LOG_DEBUG, "invalid NORM-6 VLC\n"); + return -1; + } +- planep[x + 0] = (code >> 0) & 1; +- planep[x + 1] = (code >> 1) & 1; +- planep[x + 2] = (code >> 2) & 1; ++ planep[x + 0] = (code >> 0) & 1; ++ planep[x + 1] = (code >> 1) & 1; ++ planep[x + 2] = (code >> 2) & 1; + planep[x + 0 + stride] = (code >> 3) & 1; + planep[x + 1 + stride] = (code >> 4) & 1; + planep[x + 2 + stride] = (code >> 5) & 1; +@@ -192,8 +198,10 @@ + planep += stride * 2; + } + x = width % 3; +- if(x) decode_colskip(data , x, height , stride, &v->s.gb); +- if(height & 1) decode_rowskip(data+x, width - x, 1, stride, &v->s.gb); ++ if (x) ++ decode_colskip(data, x, height, stride, &v->s.gb); ++ if (height & 1) ++ decode_rowskip(data + x, width - x, 1, stride, &v->s.gb); + } + break; + case IMODE_ROWSKIP: +@@ -202,33 +210,30 @@ + case IMODE_COLSKIP: + decode_colskip(data, width, height, stride, &v->s.gb); + break; +- default: break; ++ default: ++ break; + } + + /* Applying diff operator */ +- if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) +- { ++ if (imode == IMODE_DIFF2 || imode == IMODE_DIFF6) { + planep = data; + planep[0] ^= invert; +- for (x=1; xdquant == 2) +- { ++ if (v->dquant == 2) { + pqdiff = get_bits(gb, 3); +- if (pqdiff == 7) v->altpq = get_bits(gb, 5); +- else v->altpq = v->pq + pqdiff + 1; +- } +- else +- { ++ if (pqdiff == 7) ++ v->altpq = get_bits(gb, 5); ++ else ++ v->altpq = v->pq + pqdiff + 1; ++ } else { + v->dquantfrm = get_bits1(gb); +- if ( v->dquantfrm ) +- { ++ if (v->dquantfrm) { + v->dqprofile = get_bits(gb, 2); +- switch (v->dqprofile) +- { ++ switch (v->dqprofile) { + case DQPROFILE_SINGLE_EDGE: + case DQPROFILE_DOUBLE_EDGES: + v->dqsbedge = get_bits(gb, 2); + break; + case DQPROFILE_ALL_MBS: + v->dqbilevel = get_bits1(gb); +- if(!v->dqbilevel) ++ if (!v->dqbilevel) + v->halfpq = 0; +- default: break; //Forbidden ? ++ default: ++ break; //Forbidden ? + } +- if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) +- { ++ if (v->dqbilevel || v->dqprofile != DQPROFILE_ALL_MBS) { + pqdiff = get_bits(gb, 3); +- if (pqdiff == 7) v->altpq = get_bits(gb, 5); +- else v->altpq = v->pq + pqdiff + 1; ++ if (pqdiff == 7) ++ v->altpq = get_bits(gb, 5); ++ else ++ v->altpq = v->pq + pqdiff + 1; + } + } + } +@@ -291,80 +295,69 @@ + { + av_log(avctx, AV_LOG_DEBUG, "Header: %0X\n", show_bits(gb, 32)); + v->profile = get_bits(gb, 2); +- if (v->profile == PROFILE_COMPLEX) +- { +- av_log(avctx, AV_LOG_ERROR, "WMV3 Complex Profile is not fully supported\n"); ++ if (v->profile == PROFILE_COMPLEX) { ++ av_log(avctx, AV_LOG_WARNING, "WMV3 Complex Profile is not fully supported\n"); + } + +- if (v->profile == PROFILE_ADVANCED) +- { ++ if (v->profile == PROFILE_ADVANCED) { + v->zz_8x4 = ff_vc1_adv_progressive_8x4_zz; + v->zz_4x8 = ff_vc1_adv_progressive_4x8_zz; + return decode_sequence_header_adv(v, gb); +- } +- else +- { ++ } else { + v->zz_8x4 = wmv2_scantableA; + v->zz_4x8 = wmv2_scantableB; + v->res_y411 = get_bits1(gb); + v->res_sprite = get_bits1(gb); +- if (v->res_y411) +- { ++ if (v->res_y411) { + av_log(avctx, AV_LOG_ERROR, + "Old interlaced mode is not supported\n"); + return -1; + } +- if (v->res_sprite) { +- av_log(avctx, AV_LOG_ERROR, "WMVP is not fully supported\n"); +- } + } + + // (fps-2)/4 (->30) + v->frmrtq_postproc = get_bits(gb, 3); //common + // (bitrate-32kbps)/64kbps + v->bitrtq_postproc = get_bits(gb, 5); //common +- v->s.loop_filter = get_bits1(gb); //common +- if(v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) +- { ++ v->s.loop_filter = get_bits1(gb); //common ++ if (v->s.loop_filter == 1 && v->profile == PROFILE_SIMPLE) { + av_log(avctx, AV_LOG_ERROR, + "LOOPFILTER shall not be enabled in Simple Profile\n"); + } +- if(v->s.avctx->skip_loop_filter >= AVDISCARD_ALL) ++ if (v->s.avctx->skip_loop_filter >= AVDISCARD_ALL) + v->s.loop_filter = 0; + +- v->res_x8 = get_bits1(gb); //reserved +- v->multires = get_bits1(gb); +- v->res_fasttx = get_bits1(gb); +- if (!v->res_fasttx) +- { +- v->s.dsp.vc1_inv_trans_8x8 = ff_simple_idct; +- v->s.dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add; +- v->s.dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add; +- v->s.dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add; +- v->s.dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add; +- v->s.dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add; +- v->s.dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add; +- v->s.dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add; ++ v->res_x8 = get_bits1(gb); //reserved ++ v->multires = get_bits1(gb); ++ v->res_fasttx = get_bits1(gb); ++ if (!v->res_fasttx) { ++ v->vc1dsp.vc1_inv_trans_8x8 = ff_simple_idct_8; ++ v->vc1dsp.vc1_inv_trans_8x4 = ff_simple_idct84_add; ++ v->vc1dsp.vc1_inv_trans_4x8 = ff_simple_idct48_add; ++ v->vc1dsp.vc1_inv_trans_4x4 = ff_simple_idct44_add; ++ v->vc1dsp.vc1_inv_trans_8x8_dc = ff_simple_idct_add_8; ++ v->vc1dsp.vc1_inv_trans_8x4_dc = ff_simple_idct84_add; ++ v->vc1dsp.vc1_inv_trans_4x8_dc = ff_simple_idct48_add; ++ v->vc1dsp.vc1_inv_trans_4x4_dc = ff_simple_idct44_add; + } + +- v->fastuvmc = get_bits1(gb); //common +- if (!v->profile && !v->fastuvmc) +- { ++ v->fastuvmc = get_bits1(gb); //common ++ if (!v->profile && !v->fastuvmc) { + av_log(avctx, AV_LOG_ERROR, + "FASTUVMC unavailable in Simple Profile\n"); + return -1; + } +- v->extended_mv = get_bits1(gb); //common ++ v->extended_mv = get_bits1(gb); //common + if (!v->profile && v->extended_mv) + { + av_log(avctx, AV_LOG_ERROR, + "Extended MVs unavailable in Simple Profile\n"); + return -1; + } +- v->dquant = get_bits(gb, 2); //common +- v->vstransform = get_bits1(gb); //common ++ v->dquant = get_bits(gb, 2); //common ++ v->vstransform = get_bits1(gb); //common + +- v->res_transtab = get_bits1(gb); ++ v->res_transtab = get_bits1(gb); + if (v->res_transtab) + { + av_log(avctx, AV_LOG_ERROR, +@@ -372,12 +365,11 @@ + return -1; + } + +- v->overlap = get_bits1(gb); //common ++ v->overlap = get_bits1(gb); //common + + v->s.resync_marker = get_bits1(gb); +- v->rangered = get_bits1(gb); +- if (v->rangered && v->profile == PROFILE_SIMPLE) +- { ++ v->rangered = get_bits1(gb); ++ if (v->rangered && v->profile == PROFILE_SIMPLE) { + av_log(avctx, AV_LOG_INFO, + "RANGERED should be set to 0 in Simple Profile\n"); + } +@@ -388,8 +380,9 @@ + v->finterpflag = get_bits1(gb); //common + + if (v->res_sprite) { +- v->s.avctx->width = v->s.avctx->coded_width = get_bits(gb, 11); +- v->s.avctx->height = v->s.avctx->coded_height = get_bits(gb, 11); ++ int w = get_bits(gb, 11); ++ int h = get_bits(gb, 11); ++ avcodec_set_dimensions(v->s.avctx, w, h); + skip_bits(gb, 5); //frame rate + v->res_x8 = get_bits1(gb); + if (get_bits1(gb)) { // something to do with DC VLC selection +@@ -401,8 +394,7 @@ + } else { + v->res_rtm_flag = get_bits1(gb); //reserved + } +- if (!v->res_rtm_flag) +- { ++ if (!v->res_rtm_flag) { + // av_log(avctx, AV_LOG_ERROR, + // "0 for reserved RES_RTM_FLAG is forbidden\n"); + av_log(avctx, AV_LOG_ERROR, +@@ -410,116 +402,122 @@ + //return -1; + } + //TODO: figure out what they mean (always 0x402F) +- if(!v->res_fasttx) skip_bits(gb, 16); ++ if (!v->res_fasttx) ++ skip_bits(gb, 16); + av_log(avctx, AV_LOG_DEBUG, +- "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" +- "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n" +- "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n" +- "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n", +- v->profile, v->frmrtq_postproc, v->bitrtq_postproc, +- v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv, +- v->rangered, v->vstransform, v->overlap, v->s.resync_marker, +- v->dquant, v->quantizer_mode, avctx->max_b_frames +- ); ++ "Profile %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" ++ "LoopFilter=%i, MultiRes=%i, FastUVMC=%i, Extended MV=%i\n" ++ "Rangered=%i, VSTransform=%i, Overlap=%i, SyncMarker=%i\n" ++ "DQuant=%i, Quantizer mode=%i, Max B frames=%i\n", ++ v->profile, v->frmrtq_postproc, v->bitrtq_postproc, ++ v->s.loop_filter, v->multires, v->fastuvmc, v->extended_mv, ++ v->rangered, v->vstransform, v->overlap, v->s.resync_marker, ++ v->dquant, v->quantizer_mode, avctx->max_b_frames); + return 0; + } + + static int decode_sequence_header_adv(VC1Context *v, GetBitContext *gb) + { ++ int w, h; + v->res_rtm_flag = 1; + v->level = get_bits(gb, 3); +- if(v->level >= 5) +- { ++ if (v->level >= 5) { + av_log(v->s.avctx, AV_LOG_ERROR, "Reserved LEVEL %i\n",v->level); + } + v->chromaformat = get_bits(gb, 2); +- if (v->chromaformat != 1) +- { ++ if (v->chromaformat != 1) { + av_log(v->s.avctx, AV_LOG_ERROR, + "Only 4:2:0 chroma format supported\n"); + return -1; + } + + // (fps-2)/4 (->30) +- v->frmrtq_postproc = get_bits(gb, 3); //common ++ v->frmrtq_postproc = get_bits(gb, 3); //common + // (bitrate-32kbps)/64kbps +- v->bitrtq_postproc = get_bits(gb, 5); //common +- v->postprocflag = get_bits1(gb); //common ++ v->bitrtq_postproc = get_bits(gb, 5); //common ++ v->postprocflag = get_bits1(gb); //common + +- v->s.avctx->coded_width = (get_bits(gb, 12) + 1) << 1; +- v->s.avctx->coded_height = (get_bits(gb, 12) + 1) << 1; +- v->s.avctx->width = v->s.avctx->coded_width; +- v->s.avctx->height = v->s.avctx->coded_height; +- v->broadcast = get_bits1(gb); +- v->interlace = get_bits1(gb); +- v->tfcntrflag = get_bits1(gb); +- v->finterpflag = get_bits1(gb); ++ w = (get_bits(gb, 12) + 1) << 1; ++ h = (get_bits(gb, 12) + 1) << 1; ++ avcodec_set_dimensions(v->s.avctx, w, h); ++ v->broadcast = get_bits1(gb); ++ v->interlace = get_bits1(gb); ++ v->tfcntrflag = get_bits1(gb); ++ v->finterpflag = get_bits1(gb); + skip_bits1(gb); // reserved + +- v->s.h_edge_pos = v->s.avctx->coded_width; +- v->s.v_edge_pos = v->s.avctx->coded_height; +- + av_log(v->s.avctx, AV_LOG_DEBUG, +- "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" +- "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n" +- "TFCTRflag=%i, FINTERPflag=%i\n", +- v->level, v->frmrtq_postproc, v->bitrtq_postproc, +- v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace, +- v->tfcntrflag, v->finterpflag +- ); ++ "Advanced Profile level %i:\nfrmrtq_postproc=%i, bitrtq_postproc=%i\n" ++ "LoopFilter=%i, ChromaFormat=%i, Pulldown=%i, Interlace: %i\n" ++ "TFCTRflag=%i, FINTERPflag=%i\n", ++ v->level, v->frmrtq_postproc, v->bitrtq_postproc, ++ v->s.loop_filter, v->chromaformat, v->broadcast, v->interlace, ++ v->tfcntrflag, v->finterpflag); + + v->psf = get_bits1(gb); +- if(v->psf) { //PsF, 6.1.13 ++ if (v->psf) { //PsF, 6.1.13 + av_log(v->s.avctx, AV_LOG_ERROR, "Progressive Segmented Frame mode: not supported (yet)\n"); + return -1; + } + v->s.max_b_frames = v->s.avctx->max_b_frames = 7; +- if(get_bits1(gb)) { //Display Info - decoding is not affected by it ++ if (get_bits1(gb)) { //Display Info - decoding is not affected by it + int w, h, ar = 0; + av_log(v->s.avctx, AV_LOG_DEBUG, "Display extended info:\n"); +- v->s.avctx->width = w = get_bits(gb, 14) + 1; +- v->s.avctx->height = h = get_bits(gb, 14) + 1; ++ w = get_bits(gb, 14) + 1; ++ h = get_bits(gb, 14) + 1; + av_log(v->s.avctx, AV_LOG_DEBUG, "Display dimensions: %ix%i\n", w, h); +- if(get_bits1(gb)) ++ if (get_bits1(gb)) + ar = get_bits(gb, 4); +- if(ar && ar < 14){ ++ if (ar && ar < 14) { + v->s.avctx->sample_aspect_ratio = ff_vc1_pixel_aspect[ar]; +- }else if(ar == 15){ +- w = get_bits(gb, 8); +- h = get_bits(gb, 8); ++ } else if (ar == 15) { ++ w = get_bits(gb, 8) + 1; ++ h = get_bits(gb, 8) + 1; + v->s.avctx->sample_aspect_ratio = (AVRational){w, h}; +- } +- av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", v->s.avctx->sample_aspect_ratio.num, v->s.avctx->sample_aspect_ratio.den); ++ } else { ++ av_reduce(&v->s.avctx->sample_aspect_ratio.num, ++ &v->s.avctx->sample_aspect_ratio.den, ++ v->s.avctx->height * w, ++ v->s.avctx->width * h, ++ 1 << 30); ++ } ++ av_log(v->s.avctx, AV_LOG_DEBUG, "Aspect: %i:%i\n", ++ v->s.avctx->sample_aspect_ratio.num, ++ v->s.avctx->sample_aspect_ratio.den); + +- if(get_bits1(gb)){ //framerate stuff +- if(get_bits1(gb)) { ++ if (get_bits1(gb)) { //framerate stuff ++ if (get_bits1(gb)) { + v->s.avctx->time_base.num = 32; + v->s.avctx->time_base.den = get_bits(gb, 16) + 1; + } else { + int nr, dr; + nr = get_bits(gb, 8); + dr = get_bits(gb, 4); +- if(nr && nr < 8 && dr && dr < 3){ ++ if (nr && nr < 8 && dr && dr < 3) { + v->s.avctx->time_base.num = ff_vc1_fps_dr[dr - 1]; + v->s.avctx->time_base.den = ff_vc1_fps_nr[nr - 1] * 1000; + } + } ++ if (v->broadcast) { // Pulldown may be present ++ v->s.avctx->time_base.den *= 2; ++ v->s.avctx->ticks_per_frame = 2; ++ } + } + +- if(get_bits1(gb)){ +- v->color_prim = get_bits(gb, 8); ++ if (get_bits1(gb)) { ++ v->color_prim = get_bits(gb, 8); + v->transfer_char = get_bits(gb, 8); +- v->matrix_coef = get_bits(gb, 8); ++ v->matrix_coef = get_bits(gb, 8); + } + } + + v->hrd_param_flag = get_bits1(gb); +- if(v->hrd_param_flag) { ++ if (v->hrd_param_flag) { + int i; + v->hrd_num_leaky_buckets = get_bits(gb, 5); + skip_bits(gb, 4); //bitrate exponent + skip_bits(gb, 4); //buffer size exponent +- for(i = 0; i < v->hrd_num_leaky_buckets; i++) { ++ for (i = 0; i < v->hrd_num_leaky_buckets; i++) { + skip_bits(gb, 16); //hrd_rate[n] + skip_bits(gb, 16); //hrd_buffer[n] + } +@@ -532,45 +530,46 @@ + int i; + + av_log(avctx, AV_LOG_DEBUG, "Entry point: %08X\n", show_bits_long(gb, 32)); +- v->broken_link = get_bits1(gb); +- v->closed_entry = get_bits1(gb); +- v->panscanflag = get_bits1(gb); +- v->refdist_flag = get_bits1(gb); +- v->s.loop_filter = get_bits1(gb); +- v->fastuvmc = get_bits1(gb); +- v->extended_mv = get_bits1(gb); +- v->dquant = get_bits(gb, 2); +- v->vstransform = get_bits1(gb); +- v->overlap = get_bits1(gb); ++ v->broken_link = get_bits1(gb); ++ v->closed_entry = get_bits1(gb); ++ v->panscanflag = get_bits1(gb); ++ v->refdist_flag = get_bits1(gb); ++ v->s.loop_filter = get_bits1(gb); ++ v->fastuvmc = get_bits1(gb); ++ v->extended_mv = get_bits1(gb); ++ v->dquant = get_bits(gb, 2); ++ v->vstransform = get_bits1(gb); ++ v->overlap = get_bits1(gb); + v->quantizer_mode = get_bits(gb, 2); + +- if(v->hrd_param_flag){ +- for(i = 0; i < v->hrd_num_leaky_buckets; i++) { ++ if (v->hrd_param_flag) { ++ for (i = 0; i < v->hrd_num_leaky_buckets; i++) { + skip_bits(gb, 8); //hrd_full[n] + } + } + + if(get_bits1(gb)){ +- avctx->coded_width = (get_bits(gb, 12)+1)<<1; +- avctx->coded_height = (get_bits(gb, 12)+1)<<1; ++ int w = (get_bits(gb, 12)+1)<<1; ++ int h = (get_bits(gb, 12)+1)<<1; ++ avcodec_set_dimensions(avctx, w, h); + } +- if(v->extended_mv) ++ if (v->extended_mv) + v->extended_dmv = get_bits1(gb); +- if((v->range_mapy_flag = get_bits1(gb))) { ++ if ((v->range_mapy_flag = get_bits1(gb))) { + av_log(avctx, AV_LOG_ERROR, "Luma scaling is not supported, expect wrong picture\n"); + v->range_mapy = get_bits(gb, 3); + } +- if((v->range_mapuv_flag = get_bits1(gb))) { ++ if ((v->range_mapuv_flag = get_bits1(gb))) { + av_log(avctx, AV_LOG_ERROR, "Chroma scaling is not supported, expect wrong picture\n"); + v->range_mapuv = get_bits(gb, 3); + } + + av_log(avctx, AV_LOG_DEBUG, "Entry point info:\n" +- "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n" +- "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n" +- "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n", +- v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter, +- v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode); ++ "BrokenLink=%i, ClosedEntry=%i, PanscanFlag=%i\n" ++ "RefDist=%i, Postproc=%i, FastUVMC=%i, ExtMV=%i\n" ++ "DQuant=%i, VSTransform=%i, Overlap=%i, Qmode=%i\n", ++ v->broken_link, v->closed_entry, v->panscanflag, v->refdist_flag, v->s.loop_filter, ++ v->fastuvmc, v->extended_mv, v->dquant, v->vstransform, v->overlap, v->quantizer_mode); + + return 0; + } +@@ -579,44 +578,48 @@ + { + int pqindex, lowquant, status; + +- if(v->res_sprite) { +- skip_bits(gb, 2); //not yet deciphered +- } +- if(v->finterpflag) v->interpfrm = get_bits1(gb); ++ if (v->finterpflag) ++ v->interpfrm = get_bits1(gb); + skip_bits(gb, 2); //framecnt unused + v->rangeredfrm = 0; +- if (v->rangered) v->rangeredfrm = get_bits1(gb); ++ if (v->rangered) ++ v->rangeredfrm = get_bits1(gb); + v->s.pict_type = get_bits1(gb); + if (v->s.avctx->max_b_frames) { + if (!v->s.pict_type) { +- if (get_bits1(gb)) v->s.pict_type = FF_I_TYPE; +- else v->s.pict_type = FF_B_TYPE; +- } else v->s.pict_type = FF_P_TYPE; +- } else v->s.pict_type = v->s.pict_type ? FF_P_TYPE : FF_I_TYPE; ++ if (get_bits1(gb)) ++ v->s.pict_type = AV_PICTURE_TYPE_I; ++ else ++ v->s.pict_type = AV_PICTURE_TYPE_B; ++ } else ++ v->s.pict_type = AV_PICTURE_TYPE_P; ++ } else ++ v->s.pict_type = v->s.pict_type ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; + + v->bi_type = 0; +- if(v->s.pict_type == FF_B_TYPE) { ++ if (v->s.pict_type == AV_PICTURE_TYPE_B) { + v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); +- v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; +- if(v->bfraction == 0) { +- v->s.pict_type = FF_BI_TYPE; ++ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; ++ if (v->bfraction == 0) { ++ v->s.pict_type = AV_PICTURE_TYPE_BI; + } + } +- if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) + skip_bits(gb, 7); // skip buffer fullness + +- if(v->parse_only) ++ if (v->parse_only) + return 0; + + /* calculate RND */ +- if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) + v->rnd = 1; +- if(v->s.pict_type == FF_P_TYPE) ++ if (v->s.pict_type == AV_PICTURE_TYPE_P) + v->rnd ^= 1; + + /* Quantizer stuff */ + pqindex = get_bits(gb, 5); +- if(!pqindex) return -1; ++ if (!pqindex) ++ return -1; + if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) + v->pq = ff_vc1_pquant_table[0][pqindex]; + else +@@ -628,63 +631,69 @@ + if (v->quantizer_mode == QUANT_NON_UNIFORM) + v->pquantizer = 0; + v->pqindex = pqindex; +- if (pqindex < 9) v->halfpq = get_bits1(gb); +- else v->halfpq = 0; ++ if (pqindex < 9) ++ v->halfpq = get_bits1(gb); ++ else ++ v->halfpq = 0; + if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) + v->pquantizer = get_bits1(gb); + v->dquantfrm = 0; +- if (v->extended_mv == 1) v->mvrange = get_unary(gb, 0, 3); ++ if (v->extended_mv == 1) ++ v->mvrange = get_unary(gb, 0, 3); + v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 + v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 + v->range_x = 1 << (v->k_x - 1); + v->range_y = 1 << (v->k_y - 1); +- if (v->multires && v->s.pict_type != FF_B_TYPE) v->respic = get_bits(gb, 2); ++ if (v->multires && v->s.pict_type != AV_PICTURE_TYPE_B) ++ v->respic = get_bits(gb, 2); + +- if(v->res_x8 && (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE)){ ++ if (v->res_x8 && (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI)) { + v->x8_type = get_bits1(gb); +- }else v->x8_type = 0; ++ } else ++ v->x8_type = 0; + //av_log(v->s.avctx, AV_LOG_INFO, "%c Frame: QP=[%i]%i (+%i/2) %i\n", +-// (v->s.pict_type == FF_P_TYPE) ? 'P' : ((v->s.pict_type == FF_I_TYPE) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm); ++// (v->s.pict_type == AV_PICTURE_TYPE_P) ? 'P' : ((v->s.pict_type == AV_PICTURE_TYPE_I) ? 'I' : 'B'), pqindex, v->pq, v->halfpq, v->rangeredfrm); + +- if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0; ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) ++ v->use_ic = 0; + +- switch(v->s.pict_type) { +- case FF_P_TYPE: +- if (v->pq < 5) v->tt_index = 0; +- else if(v->pq < 13) v->tt_index = 1; +- else v->tt_index = 2; ++ switch (v->s.pict_type) { ++ case AV_PICTURE_TYPE_P: ++ if (v->pq < 5) v->tt_index = 0; ++ else if (v->pq < 13) v->tt_index = 1; ++ else v->tt_index = 2; + + lowquant = (v->pq > 12) ? 0 : 1; + v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; +- if (v->mv_mode == MV_PMODE_INTENSITY_COMP) +- { ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + int scale, shift, i; + v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)]; + v->lumscale = get_bits(gb, 6); + v->lumshift = get_bits(gb, 6); +- v->use_ic = 1; ++ v->use_ic = 1; + /* fill lookup tables for intensity compensation */ +- if(!v->lumscale) { ++ if (!v->lumscale) { + scale = -64; + shift = (255 - v->lumshift * 2) << 6; +- if(v->lumshift > 31) ++ if (v->lumshift > 31) + shift += 128 << 6; + } else { + scale = v->lumscale + 32; +- if(v->lumshift > 31) ++ if (v->lumshift > 31) + shift = (v->lumshift - 64) << 6; + else + shift = v->lumshift << 6; + } +- for(i = 0; i < 256; i++) { +- v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); ++ for (i = 0; i < 256; i++) { ++ v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); + v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); + } + } +- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) ++ v->qs_last = v->s.quarter_sample; ++ if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) + v->s.quarter_sample = 0; +- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { +- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) ++ else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) + v->s.quarter_sample = 0; + else + v->s.quarter_sample = 1; +@@ -692,12 +701,12 @@ + v->s.quarter_sample = 1; + v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); + +- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && +- v->mv_mode2 == MV_PMODE_MIXED_MV) +- || v->mv_mode == MV_PMODE_MIXED_MV) +- { ++ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && ++ v->mv_mode2 == MV_PMODE_MIXED_MV) || ++ v->mv_mode == MV_PMODE_MIXED_MV) { + status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " + "Imode: %i, Invert: %i\n", status>>1, status&1); + } else { +@@ -705,7 +714,8 @@ + memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height); + } + status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " + "Imode: %i, Invert: %i\n", status>>1, status&1); + +@@ -713,18 +723,15 @@ + v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables + v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + +- if (v->dquant) +- { ++ if (v->dquant) { + av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); + vop_dquant_decoding(v); + } + + v->ttfrm = 0; //FIXME Is that so ? +- if (v->vstransform) +- { ++ if (v->vstransform) { + v->ttmbf = get_bits1(gb); +- if (v->ttmbf) +- { ++ if (v->ttmbf) { + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; + } + } else { +@@ -732,39 +739,39 @@ + v->ttfrm = TT_8X8; + } + break; +- case FF_B_TYPE: +- if (v->pq < 5) v->tt_index = 0; +- else if(v->pq < 13) v->tt_index = 1; +- else v->tt_index = 2; ++ case AV_PICTURE_TYPE_B: ++ if (v->pq < 5) v->tt_index = 0; ++ else if (v->pq < 13) v->tt_index = 1; ++ else v->tt_index = 2; + +- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; ++ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; ++ v->qs_last = v->s.quarter_sample; + v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV); +- v->s.mspel = v->s.quarter_sample; ++ v->s.mspel = v->s.quarter_sample; + + status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: " + "Imode: %i, Invert: %i\n", status>>1, status&1); + status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " + "Imode: %i, Invert: %i\n", status>>1, status&1); + + v->s.mv_table_index = get_bits(gb, 2); +- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; ++ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; + +- if (v->dquant) +- { ++ if (v->dquant) { + av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); + vop_dquant_decoding(v); + } + + v->ttfrm = 0; +- if (v->vstransform) +- { ++ if (v->vstransform) { + v->ttmbf = get_bits1(gb); +- if (v->ttmbf) +- { ++ if (v->ttmbf) { + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; + } + } else { +@@ -774,84 +781,161 @@ + break; + } + +- if(!v->x8_type) +- { ++ if (!v->x8_type) { + /* AC Syntax */ + v->c_ac_table_index = decode012(gb); +- if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) +- { ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) { + v->y_ac_table_index = decode012(gb); + } + /* DC Syntax */ + v->s.dc_table_index = get_bits1(gb); + } + +- if(v->s.pict_type == FF_BI_TYPE) { +- v->s.pict_type = FF_B_TYPE; +- v->bi_type = 1; ++ if (v->s.pict_type == AV_PICTURE_TYPE_BI) { ++ v->s.pict_type = AV_PICTURE_TYPE_B; ++ v->bi_type = 1; + } + return 0; + } + ++/* fill lookup tables for intensity compensation */ ++#define INIT_LUT(lumscale, lumshift, luty, lutuv) \ ++ if (!lumscale) { \ ++ scale = -64; \ ++ shift = (255 - lumshift * 2) << 6; \ ++ if (lumshift > 31) \ ++ shift += 128 << 6; \ ++ } else { \ ++ scale = lumscale + 32; \ ++ if (lumshift > 31) \ ++ shift = (lumshift - 64) << 6; \ ++ else \ ++ shift = lumshift << 6; \ ++ } \ ++ for (i = 0; i < 256; i++) { \ ++ luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); \ ++ lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); \ ++ } ++ + int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext* gb) + { + int pqindex, lowquant; + int status; ++ int mbmodetab, imvtab, icbptab, twomvbptab, fourmvbptab; /* useful only for debugging */ ++ int scale, shift, i; /* for initializing LUT for intensity compensation */ + ++ v->numref=0; + v->p_frame_skipped = 0; ++ if (v->second_field) { ++ if(v->fcm!=2 || v->field_mode!=1) ++ return -1; ++ v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; ++ if (v->fptype & 4) ++ v->s.pict_type = (v->fptype & 1) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; ++ v->s.current_picture_ptr->f.pict_type = v->s.pict_type; ++ if (!v->pic_header_flag) ++ goto parse_common_info; ++ } + +- if(v->interlace){ ++ v->field_mode = 0; ++ if (v->interlace) { + v->fcm = decode012(gb); +- if(v->fcm){ +- if(!v->warn_interlaced++) +- av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced frames/fields support is not implemented\n"); +- return -1; ++ if (v->fcm) { ++ if (v->fcm == ILACE_FIELD) ++ v->field_mode = 1; ++ if (!v->warn_interlaced++) ++ av_log(v->s.avctx, AV_LOG_ERROR, ++ "Interlaced frames/fields support is incomplete\n"); + } ++ } else { ++ v->fcm = PROGRESSIVE; + } +- switch(get_unary(gb, 0, 4)) { +- case 0: +- v->s.pict_type = FF_P_TYPE; +- break; +- case 1: +- v->s.pict_type = FF_B_TYPE; +- break; +- case 2: +- v->s.pict_type = FF_I_TYPE; +- break; +- case 3: +- v->s.pict_type = FF_BI_TYPE; +- break; +- case 4: +- v->s.pict_type = FF_P_TYPE; // skipped pic +- v->p_frame_skipped = 1; +- return 0; ++ ++ if (v->field_mode) { ++ v->fptype = get_bits(gb, 3); ++ v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; ++ if (v->fptype & 4) // B-picture ++ v->s.pict_type = (v->fptype & 2) ? AV_PICTURE_TYPE_BI : AV_PICTURE_TYPE_B; ++ } else { ++ switch (get_unary(gb, 0, 4)) { ++ case 0: ++ v->s.pict_type = AV_PICTURE_TYPE_P; ++ break; ++ case 1: ++ v->s.pict_type = AV_PICTURE_TYPE_B; ++ break; ++ case 2: ++ v->s.pict_type = AV_PICTURE_TYPE_I; ++ break; ++ case 3: ++ v->s.pict_type = AV_PICTURE_TYPE_BI; ++ break; ++ case 4: ++ v->s.pict_type = AV_PICTURE_TYPE_P; // skipped pic ++ v->p_frame_skipped = 1; ++ break; ++ } + } +- if(v->tfcntrflag) ++ if (v->tfcntrflag) + skip_bits(gb, 8); +- if(v->broadcast) { +- if(!v->interlace || v->psf) { ++ if (v->broadcast) { ++ if (!v->interlace || v->psf) { + v->rptfrm = get_bits(gb, 2); + } else { + v->tff = get_bits1(gb); +- v->rptfrm = get_bits1(gb); ++ v->rff = get_bits1(gb); + } + } +- if(v->panscanflag) { ++ if (v->panscanflag) { ++ av_log_missing_feature(v->s.avctx, "Pan-scan", 0); + //... + } ++ if (v->p_frame_skipped) { ++ return 0; ++ } + v->rnd = get_bits1(gb); +- if(v->interlace) ++ if (v->interlace) + v->uvsamp = get_bits1(gb); +- if(v->finterpflag) v->interpfrm = get_bits1(gb); +- if(v->s.pict_type == FF_B_TYPE) { +- v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); +- v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; +- if(v->bfraction == 0) { +- v->s.pict_type = FF_BI_TYPE; /* XXX: should not happen here */ ++ if(!ff_vc1_bfraction_vlc.table) ++ return 0; //parsing only, vlc tables havnt been allocated ++ if (v->field_mode) { ++ if (!v->refdist_flag) ++ v->refdist = 0; ++ else { ++ if ((v->s.pict_type != AV_PICTURE_TYPE_B) ++ && (v->s.pict_type != AV_PICTURE_TYPE_BI)) { ++ v->refdist = get_bits(gb, 2); ++ if (v->refdist == 3) ++ v->refdist += get_unary(gb, 0, 16); ++ } else { ++ v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); ++ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; ++ v->frfd = (v->bfraction * v->refdist) >> 8; ++ v->brfd = v->refdist - v->frfd - 1; ++ if (v->brfd < 0) ++ v->brfd = 0; ++ } ++ } ++ goto parse_common_info; ++ } ++ if (v->fcm == PROGRESSIVE) { ++ if (v->finterpflag) ++ v->interpfrm = get_bits1(gb); ++ if (v->s.pict_type == AV_PICTURE_TYPE_B) { ++ v->bfraction_lut_index = get_vlc2(gb, ff_vc1_bfraction_vlc.table, VC1_BFRACTION_VLC_BITS, 1); ++ v->bfraction = ff_vc1_bfraction_lut[v->bfraction_lut_index]; ++ if (v->bfraction == 0) { ++ v->s.pict_type = AV_PICTURE_TYPE_BI; /* XXX: should not happen here */ ++ } + } + } ++ ++ parse_common_info: ++ if (v->field_mode) ++ v->cur_field_type = !(v->tff ^ v->second_field); + pqindex = get_bits(gb, 5); +- if(!pqindex) return -1; ++ if (!pqindex) ++ return -1; + v->pqindex = pqindex; + if (v->quantizer_mode == QUANT_FRAME_IMPLICIT) + v->pq = ff_vc1_pquant_table[0][pqindex]; +@@ -864,118 +948,193 @@ + if (v->quantizer_mode == QUANT_NON_UNIFORM) + v->pquantizer = 0; + v->pqindex = pqindex; +- if (pqindex < 9) v->halfpq = get_bits1(gb); +- else v->halfpq = 0; ++ if (pqindex < 9) ++ v->halfpq = get_bits1(gb); ++ else ++ v->halfpq = 0; + if (v->quantizer_mode == QUANT_FRAME_EXPLICIT) + v->pquantizer = get_bits1(gb); +- if(v->postprocflag) ++ if (v->postprocflag) + v->postproc = get_bits(gb, 2); + +- if(v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_P_TYPE) v->use_ic = 0; ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_P) ++ v->use_ic = 0; + +- if(v->parse_only) ++ if (v->parse_only) + return 0; + +- switch(v->s.pict_type) { +- case FF_I_TYPE: +- case FF_BI_TYPE: ++ switch (v->s.pict_type) { ++ case AV_PICTURE_TYPE_I: ++ case AV_PICTURE_TYPE_BI: ++ if (v->fcm == ILACE_FRAME) { //interlace frame picture ++ status = bitplane_decoding(v->fieldtx_plane, &v->fieldtx_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "FIELDTX plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ } + status = bitplane_decoding(v->acpred_plane, &v->acpred_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "ACPRED plane encoding: " +- "Imode: %i, Invert: %i\n", status>>1, status&1); ++ "Imode: %i, Invert: %i\n", status>>1, status&1); + v->condover = CONDOVER_NONE; +- if(v->overlap && v->pq <= 8) { ++ if (v->overlap && v->pq <= 8) { + v->condover = decode012(gb); +- if(v->condover == CONDOVER_SELECT) { ++ if (v->condover == CONDOVER_SELECT) { + status = bitplane_decoding(v->over_flags_plane, &v->overflg_is_raw, v); +- if (status < 0) return -1; ++ if (status < 0) ++ return -1; + av_log(v->s.avctx, AV_LOG_DEBUG, "CONDOVER plane encoding: " +- "Imode: %i, Invert: %i\n", status>>1, status&1); ++ "Imode: %i, Invert: %i\n", status>>1, status&1); + } + } + break; +- case FF_P_TYPE: +- if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); +- else v->mvrange = 0; ++ case AV_PICTURE_TYPE_P: ++ if (v->field_mode) { ++ v->numref = get_bits1(gb); ++ if (!v->numref) { ++ v->reffield = get_bits1(gb); ++ v->ref_field_type[0] = v->reffield ^ !v->cur_field_type; ++ } ++ } ++ if (v->extended_mv) ++ v->mvrange = get_unary(gb, 0, 3); ++ else ++ v->mvrange = 0; ++ if (v->interlace) { ++ if (v->extended_dmv) ++ v->dmvrange = get_unary(gb, 0, 3); ++ else ++ v->dmvrange = 0; ++ if (v->fcm == ILACE_FRAME) { // interlaced frame picture ++ v->fourmvswitch = get_bits1(gb); ++ v->intcomp = get_bits1(gb); ++ if (v->intcomp) { ++ v->lumscale = get_bits(gb, 6); ++ v->lumshift = get_bits(gb, 6); ++ INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv); ++ } ++ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); ++ av_log(v->s.avctx, AV_LOG_DEBUG, "SKIPMB plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ mbmodetab = get_bits(gb, 2); ++ if (v->fourmvswitch) ++ v->mbmode_vlc = &ff_vc1_intfr_4mv_mbmode_vlc[mbmodetab]; ++ else ++ v->mbmode_vlc = &ff_vc1_intfr_non4mv_mbmode_vlc[mbmodetab]; ++ imvtab = get_bits(gb, 2); ++ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab]; ++ // interlaced p-picture cbpcy range is [1, 63] ++ icbptab = get_bits(gb, 3); ++ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; ++ twomvbptab = get_bits(gb, 2); ++ v->twomvbp_vlc = &ff_vc1_2mv_block_pattern_vlc[twomvbptab]; ++ if (v->fourmvswitch) { ++ fourmvbptab = get_bits(gb, 2); ++ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; ++ } ++ } ++ } + v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 + v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 + v->range_x = 1 << (v->k_x - 1); + v->range_y = 1 << (v->k_y - 1); + +- if (v->pq < 5) v->tt_index = 0; +- else if(v->pq < 13) v->tt_index = 1; +- else v->tt_index = 2; +- +- lowquant = (v->pq > 12) ? 0 : 1; +- v->mv_mode = ff_vc1_mv_pmode_table[lowquant][get_unary(gb, 1, 4)]; +- if (v->mv_mode == MV_PMODE_INTENSITY_COMP) +- { +- int scale, shift, i; +- v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][get_unary(gb, 1, 3)]; +- v->lumscale = get_bits(gb, 6); +- v->lumshift = get_bits(gb, 6); +- /* fill lookup tables for intensity compensation */ +- if(!v->lumscale) { +- scale = -64; +- shift = (255 - v->lumshift * 2) << 6; +- if(v->lumshift > 31) +- shift += 128 << 6; +- } else { +- scale = v->lumscale + 32; +- if(v->lumshift > 31) +- shift = (v->lumshift - 64) << 6; +- else +- shift = v->lumshift << 6; +- } +- for(i = 0; i < 256; i++) { +- v->luty[i] = av_clip_uint8((scale * i + shift + 32) >> 6); +- v->lutuv[i] = av_clip_uint8((scale * (i - 128) + 128*64 + 32) >> 6); ++ if (v->pq < 5) ++ v->tt_index = 0; ++ else if (v->pq < 13) ++ v->tt_index = 1; ++ else ++ v->tt_index = 2; ++ if (v->fcm != ILACE_FRAME) { ++ int mvmode; ++ mvmode = get_unary(gb, 1, 4); ++ lowquant = (v->pq > 12) ? 0 : 1; ++ v->mv_mode = ff_vc1_mv_pmode_table[lowquant][mvmode]; ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ int mvmode2; ++ mvmode2 = get_unary(gb, 1, 3); ++ v->mv_mode2 = ff_vc1_mv_pmode_table2[lowquant][mvmode2]; ++ if (v->field_mode) ++ v->intcompfield = decode210(gb); ++ v->lumscale = get_bits(gb, 6); ++ v->lumshift = get_bits(gb, 6); ++ INIT_LUT(v->lumscale, v->lumshift, v->luty, v->lutuv); ++ if ((v->field_mode) && !v->intcompfield) { ++ v->lumscale2 = get_bits(gb, 6); ++ v->lumshift2 = get_bits(gb, 6); ++ INIT_LUT(v->lumscale2, v->lumshift2, v->luty2, v->lutuv2); ++ } ++ v->use_ic = 1; + } +- v->use_ic = 1; +- } +- if(v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) +- v->s.quarter_sample = 0; +- else if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { +- if(v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) ++ v->qs_last = v->s.quarter_sample; ++ if (v->mv_mode == MV_PMODE_1MV_HPEL || v->mv_mode == MV_PMODE_1MV_HPEL_BILIN) + v->s.quarter_sample = 0; +- else ++ else if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ if (v->mv_mode2 == MV_PMODE_1MV_HPEL || v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN) ++ v->s.quarter_sample = 0; ++ else ++ v->s.quarter_sample = 1; ++ } else + v->s.quarter_sample = 1; +- } else +- v->s.quarter_sample = 1; +- v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || (v->mv_mode == MV_PMODE_INTENSITY_COMP && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); +- +- if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && ++ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN ++ || (v->mv_mode == MV_PMODE_INTENSITY_COMP ++ && v->mv_mode2 == MV_PMODE_1MV_HPEL_BILIN)); ++ } ++ if (v->fcm == PROGRESSIVE) { // progressive ++ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && + v->mv_mode2 == MV_PMODE_MIXED_MV) +- || v->mv_mode == MV_PMODE_MIXED_MV) +- { +- status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v); +- if (status < 0) return -1; +- av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " ++ || v->mv_mode == MV_PMODE_MIXED_MV) { ++ status = bitplane_decoding(v->mv_type_mb_plane, &v->mv_type_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "MB MV Type plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ } else { ++ v->mv_type_is_raw = 0; ++ memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height); ++ } ++ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " + "Imode: %i, Invert: %i\n", status>>1, status&1); +- } else { +- v->mv_type_is_raw = 0; +- memset(v->mv_type_mb_plane, 0, v->s.mb_stride * v->s.mb_height); +- } +- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); +- if (status < 0) return -1; +- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " +- "Imode: %i, Invert: %i\n", status>>1, status&1); + +- /* Hopefully this is correct for P frames */ +- v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables +- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; +- if (v->dquant) +- { ++ /* Hopefully this is correct for P frames */ ++ v->s.mv_table_index = get_bits(gb, 2); //but using ff_vc1_ tables ++ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; ++ } else if (v->fcm == ILACE_FRAME) { // frame interlaced ++ v->qs_last = v->s.quarter_sample; ++ v->s.quarter_sample = 1; ++ v->s.mspel = 1; ++ } else { // field interlaced ++ mbmodetab = get_bits(gb, 3); ++ imvtab = get_bits(gb, 2 + v->numref); ++ if (!v->numref) ++ v->imv_vlc = &ff_vc1_1ref_mvdata_vlc[imvtab]; ++ else ++ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab]; ++ icbptab = get_bits(gb, 3); ++ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; ++ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP && ++ v->mv_mode2 == MV_PMODE_MIXED_MV) || v->mv_mode == MV_PMODE_MIXED_MV) { ++ fourmvbptab = get_bits(gb, 2); ++ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; ++ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab]; ++ } else { ++ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab]; ++ } ++ } ++ if (v->dquant) { + av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); + vop_dquant_decoding(v); + } + + v->ttfrm = 0; //FIXME Is that so ? +- if (v->vstransform) +- { ++ if (v->vstransform) { + v->ttmbf = get_bits1(gb); +- if (v->ttmbf) +- { ++ if (v->ttmbf) { + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; + } + } else { +@@ -983,46 +1142,85 @@ + v->ttfrm = TT_8X8; + } + break; +- case FF_B_TYPE: +- if (v->extended_mv) v->mvrange = get_unary(gb, 0, 3); +- else v->mvrange = 0; +- v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 +- v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 ++ case AV_PICTURE_TYPE_B: ++ // TODO: implement interlaced frame B picture decoding ++ if (v->fcm == ILACE_FRAME) ++ return -1; ++ if (v->extended_mv) ++ v->mvrange = get_unary(gb, 0, 3); ++ else ++ v->mvrange = 0; ++ v->k_x = v->mvrange + 9 + (v->mvrange >> 1); //k_x can be 9 10 12 13 ++ v->k_y = v->mvrange + 8; //k_y can be 8 9 10 11 + v->range_x = 1 << (v->k_x - 1); + v->range_y = 1 << (v->k_y - 1); + +- if (v->pq < 5) v->tt_index = 0; +- else if(v->pq < 13) v->tt_index = 1; +- else v->tt_index = 2; +- +- v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; +- v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV); +- v->s.mspel = v->s.quarter_sample; +- +- status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v); +- if (status < 0) return -1; +- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: " +- "Imode: %i, Invert: %i\n", status>>1, status&1); +- status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); +- if (status < 0) return -1; +- av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " +- "Imode: %i, Invert: %i\n", status>>1, status&1); ++ if (v->pq < 5) ++ v->tt_index = 0; ++ else if (v->pq < 13) ++ v->tt_index = 1; ++ else ++ v->tt_index = 2; + +- v->s.mv_table_index = get_bits(gb, 2); +- v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; ++ if (v->field_mode) { ++ int mvmode; ++ av_log(v->s.avctx, AV_LOG_ERROR, "B Fields do not work currently\n"); ++ return -1; ++ if (v->extended_dmv) ++ v->dmvrange = get_unary(gb, 0, 3); ++ mvmode = get_unary(gb, 1, 3); ++ lowquant = (v->pq > 12) ? 0 : 1; ++ v->mv_mode = ff_vc1_mv_pmode_table2[lowquant][mvmode]; ++ v->qs_last = v->s.quarter_sample; ++ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV || v->mv_mode == MV_PMODE_MIXED_MV); ++ v->s.mspel = !(v->mv_mode == MV_PMODE_1MV_HPEL_BILIN || v->mv_mode == MV_PMODE_1MV_HPEL); ++ status = bitplane_decoding(v->forward_mb_plane, &v->fmb_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Forward Type plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ mbmodetab = get_bits(gb, 3); ++ if (v->mv_mode == MV_PMODE_MIXED_MV) ++ v->mbmode_vlc = &ff_vc1_if_mmv_mbmode_vlc[mbmodetab]; ++ else ++ v->mbmode_vlc = &ff_vc1_if_1mv_mbmode_vlc[mbmodetab]; ++ imvtab = get_bits(gb, 3); ++ v->imv_vlc = &ff_vc1_2ref_mvdata_vlc[imvtab]; ++ icbptab = get_bits(gb, 3); ++ v->cbpcy_vlc = &ff_vc1_icbpcy_vlc[icbptab]; ++ if (v->mv_mode == MV_PMODE_MIXED_MV) { ++ fourmvbptab = get_bits(gb, 2); ++ v->fourmvbp_vlc = &ff_vc1_4mv_block_pattern_vlc[fourmvbptab]; ++ } ++ v->numref = 1; // interlaced field B pictures are always 2-ref ++ } else { ++ v->mv_mode = get_bits1(gb) ? MV_PMODE_1MV : MV_PMODE_1MV_HPEL_BILIN; ++ v->qs_last = v->s.quarter_sample; ++ v->s.quarter_sample = (v->mv_mode == MV_PMODE_1MV); ++ v->s.mspel = v->s.quarter_sample; ++ status = bitplane_decoding(v->direct_mb_plane, &v->dmb_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Direct Type plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ status = bitplane_decoding(v->s.mbskip_table, &v->skip_is_raw, v); ++ if (status < 0) ++ return -1; ++ av_log(v->s.avctx, AV_LOG_DEBUG, "MB Skip plane encoding: " ++ "Imode: %i, Invert: %i\n", status>>1, status&1); ++ v->s.mv_table_index = get_bits(gb, 2); ++ v->cbpcy_vlc = &ff_vc1_cbpcy_p_vlc[get_bits(gb, 2)]; ++ } + +- if (v->dquant) +- { ++ if (v->dquant) { + av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); + vop_dquant_decoding(v); + } + + v->ttfrm = 0; +- if (v->vstransform) +- { ++ if (v->vstransform) { + v->ttmbf = get_bits1(gb); +- if (v->ttmbf) +- { ++ if (v->ttmbf) { + v->ttfrm = ff_vc1_ttfrm_to_tt[get_bits(gb, 2)]; + } + } else { +@@ -1034,20 +1232,20 @@ + + /* AC Syntax */ + v->c_ac_table_index = decode012(gb); +- if (v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) +- { ++ if (v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) { + v->y_ac_table_index = decode012(gb); + } + /* DC Syntax */ + v->s.dc_table_index = get_bits1(gb); +- if ((v->s.pict_type == FF_I_TYPE || v->s.pict_type == FF_BI_TYPE) && v->dquant) { ++ if ((v->s.pict_type == AV_PICTURE_TYPE_I || v->s.pict_type == AV_PICTURE_TYPE_BI) ++ && v->dquant) { + av_log(v->s.avctx, AV_LOG_DEBUG, "VOP DQuant info\n"); + vop_dquant_decoding(v); + } + + v->bi_type = 0; +- if(v->s.pict_type == FF_BI_TYPE) { +- v->s.pict_type = FF_B_TYPE; ++ if (v->s.pict_type == AV_PICTURE_TYPE_BI) { ++ v->s.pict_type = AV_PICTURE_TYPE_B; + v->bi_type = 1; + } + return 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1data.c 2012-05-14 14:08:54.312339539 +0200 +@@ -1,5 +1,6 @@ + /* + * VC-1 and WMV3 decoder ++ * copyright (c) 2011 Mashiat Sarker Shakkhar + * copyright (c) 2006 Konstantin Shishkov + * (c) 2005 anonymous, Alex Beregszaszi, Michael Niedermayer + * +@@ -31,38 +32,70 @@ + + /** Table for conversion between TTBLK and TTMB */ + const int ff_vc1_ttblk_to_tt[3][8] = { +- { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT }, +- { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP }, +- { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP } ++ { TT_8X4, TT_4X8, TT_8X8, TT_4X4, TT_8X4_TOP, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT }, ++ { TT_8X8, TT_4X8_RIGHT, TT_4X8_LEFT, TT_4X4, TT_8X4, TT_4X8, TT_8X4_BOTTOM, TT_8X4_TOP }, ++ { TT_8X8, TT_4X8, TT_4X4, TT_8X4_BOTTOM, TT_4X8_RIGHT, TT_4X8_LEFT, TT_8X4, TT_8X4_TOP } + }; + + const int ff_vc1_ttfrm_to_tt[4] = { TT_8X8, TT_8X4, TT_4X8, TT_4X4 }; + + /** MV P mode - the 5th element is only used for mode 1 */ + const uint8_t ff_vc1_mv_pmode_table[2][5] = { +- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV }, +- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN } ++ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_MIXED_MV }, ++ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_INTENSITY_COMP, MV_PMODE_1MV_HPEL_BILIN } + }; + const uint8_t ff_vc1_mv_pmode_table2[2][4] = { +- { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV }, +- { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN } ++ { MV_PMODE_1MV_HPEL_BILIN, MV_PMODE_1MV, MV_PMODE_1MV_HPEL, MV_PMODE_MIXED_MV }, ++ { MV_PMODE_1MV, MV_PMODE_MIXED_MV, MV_PMODE_1MV_HPEL, MV_PMODE_1MV_HPEL_BILIN } ++}; ++ ++/* MBMODE table for interlaced frame P-picture */ ++const uint8_t ff_vc1_mbmode_intfrp[2][15][4] = { ++ { /* 1: 4-MV, 0: non-4-MV */ ++ /* Type, FIELDTX, 1-MV Differential present, Residuals (CBP) present */ ++ /* Table 164 - Table 167 */ ++ { MV_PMODE_INTFR_1MV , 0, 1, 1 }, ++ { MV_PMODE_INTFR_1MV , 1, 1, 1 }, ++ { MV_PMODE_INTFR_1MV , 0, 1, 0 }, ++ { MV_PMODE_INTFR_1MV , 0, 0, 1 }, ++ { MV_PMODE_INTFR_1MV , 1, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 1, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 0 }, ++ { MV_PMODE_INTFR_INTRA , 0, 0, 0 } ++ }, ++ { ++ /* Table 160 - Table 163 */ ++ { MV_PMODE_INTFR_1MV , 0, 1, 1 }, ++ { MV_PMODE_INTFR_1MV , 1, 1, 1 }, ++ { MV_PMODE_INTFR_1MV , 0, 1, 0 }, ++ { MV_PMODE_INTFR_1MV , 0, 0, 1 }, ++ { MV_PMODE_INTFR_1MV , 1, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 1, 0, 1 }, ++ { MV_PMODE_INTFR_2MV_FIELD, 0, 0, 0 }, ++ { MV_PMODE_INTFR_4MV , 0, 0, 1 }, ++ { MV_PMODE_INTFR_4MV , 1, 0, 1 }, ++ { MV_PMODE_INTFR_4MV , 0, 0, 0 }, ++ { MV_PMODE_INTFR_4MV_FIELD, 0, 0, 1 }, ++ { MV_PMODE_INTFR_4MV_FIELD, 1, 0, 1 }, ++ { MV_PMODE_INTFR_4MV_FIELD, 0, 0, 0 }, ++ { MV_PMODE_INTFR_INTRA , 0, 0, 0 } ++ } + }; + + const int ff_vc1_fps_nr[5] = { 24, 25, 30, 50, 60 }, +- ff_vc1_fps_dr[2] = { 1000, 1001 }; ++ ff_vc1_fps_dr[2] = { 1000, 1001 }; + const uint8_t ff_vc1_pquant_table[3][32] = { +- { /* Implicit quantizer */ +- 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, +- 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 +- }, +- { /* Explicit quantizer, pquantizer uniform */ +- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +- 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 +- }, +- { /* Explicit quantizer, pquantizer non-uniform */ +- 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, +- 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 +- } ++ /* Implicit quantizer */ ++ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 6, 7, 8, 9, 10, 11, 12, ++ 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 29, 31 }, ++ /* Explicit quantizer, pquantizer uniform */ ++ { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, ++ 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 }, ++ /* Explicit quantizer, pquantizer non-uniform */ ++ { 0, 1, 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, ++ 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 29, 31 } + }; + + /** @name VC-1 VLC tables and defines +@@ -84,38 +117,57 @@ + VLC ff_vc1_mv_diff_vlc[4]; + #define VC1_CBPCY_P_VLC_BITS 9 //14 + VLC ff_vc1_cbpcy_p_vlc[4]; ++#define VC1_ICBPCY_VLC_BITS 9 ++VLC ff_vc1_icbpcy_vlc[8]; + #define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6 + VLC ff_vc1_4mv_block_pattern_vlc[4]; ++#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3 ++VLC ff_vc1_2mv_block_pattern_vlc[4]; + #define VC1_TTBLK_VLC_BITS 5 + VLC ff_vc1_ttblk_vlc[3]; + #define VC1_SUBBLKPAT_VLC_BITS 6 + VLC ff_vc1_subblkpat_vlc[3]; ++#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9 ++VLC ff_vc1_intfr_4mv_mbmode_vlc[4]; ++#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6 ++VLC ff_vc1_intfr_non4mv_mbmode_vlc[4]; ++#define VC1_IF_MMV_MBMODE_VLC_BITS 5 ++VLC ff_vc1_if_mmv_mbmode_vlc[8]; ++#define VC1_IF_1MV_MBMODE_VLC_BITS 5 ++VLC ff_vc1_if_1mv_mbmode_vlc[8]; ++#define VC1_1REF_MVDATA_VLC_BITS 9 ++VLC ff_vc1_1ref_mvdata_vlc[4]; ++#define VC1_2REF_MVDATA_VLC_BITS 9 ++VLC ff_vc1_2ref_mvdata_vlc[8]; + + VLC ff_vc1_ac_coeff_table[8]; ++ ++#define VC1_IF_MBMODE_VLC_BITS 5 // as a placeholder for VC1_IF_MMV_MBMODE_VLC_BITS ++ // or VC1_IF_1MV_MBMODE_VLC_BITS since they are the same + //@} + + +-#if B_FRACTION_DEN==840 //original bfraction from vc9data.h, not conforming to standard ++#if B_FRACTION_DEN == 840 // original bfraction from vc9data.h, not conforming to standard + /* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */ + const int16_t ff_vc1_bfraction_lut[23] = { +- 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/, +- 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/, +- 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/, +- 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/, +- 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/, +- 525 /*5/8*/, 735 /*7/8*/, +- -1 /*inv.*/, 0 /*BI fm*/ ++ 420 /*1/2*/, 280 /*1/3*/, 560 /*2/3*/, 210 /*1/4*/, ++ 630 /*3/4*/, 168 /*1/5*/, 336 /*2/5*/, ++ 504 /*3/5*/, 672 /*4/5*/, 140 /*1/6*/, 700 /*5/6*/, ++ 120 /*1/7*/, 240 /*2/7*/, 360 /*3/7*/, 480 /*4/7*/, ++ 600 /*5/7*/, 720 /*6/7*/, 105 /*1/8*/, 315 /*3/8*/, ++ 525 /*5/8*/, 735 /*7/8*/, ++ -1 /*inv.*/, 0 /*BI fm*/ + }; + #else + /* pre-computed scales for all bfractions and base=256 */ + const int16_t ff_vc1_bfraction_lut[23] = { +- 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/, +- 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/, +- 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/, +- 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/, +- 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/, +- 160 /*5/8*/, 224 /*7/8*/, +- -1 /*inv.*/, 0 /*BI fm*/ ++ 128 /*1/2*/, 85 /*1/3*/, 170 /*2/3*/, 64 /*1/4*/, ++ 192 /*3/4*/, 51 /*1/5*/, 102 /*2/5*/, ++ 153 /*3/5*/, 204 /*4/5*/, 43 /*1/6*/, 215 /*5/6*/, ++ 37 /*1/7*/, 74 /*2/7*/, 111 /*3/7*/, 148 /*4/7*/, ++ 185 /*5/7*/, 222 /*6/7*/, 32 /*1/8*/, 96 /*3/8*/, ++ 160 /*5/8*/, 224 /*7/8*/, ++ -1 /*inv.*/, 0 /*BI fm*/ + }; + #endif + +@@ -129,154 +181,477 @@ + 7, 7 + }; + const uint8_t ff_vc1_bfraction_codes[23] = { +- 0, 1, 2, 3, +- 4, 5, 6, +- 112, 113, 114, 115, +- 116, 117, 118, 119, +- 120, 121, 122, 123, +- 124, 125, +- 126, 127 ++ 0, 1, 2, 3, ++ 4, 5, 6, ++ 112, 113, 114, 115, ++ 116, 117, 118, 119, ++ 120, 121, 122, 123, ++ 124, 125, ++ 126, 127 + }; + + //Same as H.264 +-const AVRational ff_vc1_pixel_aspect[16]={ +- {0, 1}, +- {1, 1}, +- {12, 11}, +- {10, 11}, +- {16, 11}, +- {40, 33}, +- {24, 11}, +- {20, 11}, +- {32, 11}, +- {80, 33}, +- {18, 11}, +- {15, 11}, +- {64, 33}, +- {160, 99}, +- {0, 1}, +- {0, 1} ++const AVRational ff_vc1_pixel_aspect[16] = { ++ { 0, 1 }, ++ { 1, 1 }, ++ { 12, 11 }, ++ { 10, 11 }, ++ { 16, 11 }, ++ { 40, 33 }, ++ { 24, 11 }, ++ { 20, 11 }, ++ { 32, 11 }, ++ { 80, 33 }, ++ { 18, 11 }, ++ { 15, 11 }, ++ { 64, 33 }, ++ { 160, 99 }, ++ { 0, 1 }, ++ { 0, 1 } + }; + + /* BitPlane IMODE - such a small table... */ + const uint8_t ff_vc1_imode_codes[7] = { +- 0, 2, 1, 3, 1, 2, 3 ++ 0, 2, 1, 3, 1, 2, 3 + }; + const uint8_t ff_vc1_imode_bits[7] = { +- 4, 2, 3, 2, 4, 3, 3 ++ 4, 2, 3, 2, 4, 3, 3 + }; + + /* Normal-2 imode */ + const uint8_t ff_vc1_norm2_codes[4] = { +- 0, 4, 5, 3 ++ 0, 4, 5, 3 + }; + const uint8_t ff_vc1_norm2_bits[4] = { +- 1, 3, 3, 2 ++ 1, 3, 3, 2 + }; + + const uint16_t ff_vc1_norm6_codes[64] = { +-0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E, +-0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037, +-0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036, +-0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007, ++ 0x001, 0x002, 0x003, 0x000, 0x004, 0x001, 0x002, 0x047, 0x005, 0x003, 0x004, 0x04B, 0x005, 0x04D, 0x04E, 0x30E, ++ 0x006, 0x006, 0x007, 0x053, 0x008, 0x055, 0x056, 0x30D, 0x009, 0x059, 0x05A, 0x30C, 0x05C, 0x30B, 0x30A, 0x037, ++ 0x007, 0x00A, 0x00B, 0x043, 0x00C, 0x045, 0x046, 0x309, 0x00D, 0x049, 0x04A, 0x308, 0x04C, 0x307, 0x306, 0x036, ++ 0x00E, 0x051, 0x052, 0x305, 0x054, 0x304, 0x303, 0x035, 0x058, 0x302, 0x301, 0x034, 0x300, 0x033, 0x032, 0x007, + }; + + const uint8_t ff_vc1_norm6_bits[64] = { +- 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13, +- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, +- 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, +- 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6, +-}; +-#if 0 +-/* Normal-6 imode */ +-const uint8_t ff_vc1_norm6_spec[64][5] = { +-{ 0, 1, 1 }, +-{ 1, 2, 4 }, +-{ 2, 3, 4 }, +-{ 3, 0, 8 }, +-{ 4, 4, 4 }, +-{ 5, 1, 8 }, +-{ 6, 2, 8 }, +-{ 7, 2, 5, 7, 5 }, +-{ 8, 5, 4 }, +-{ 9, 3, 8 }, +-{10, 4, 8 }, +-{11, 2, 5, 11, 5 }, +-{12, 5, 8 }, +-{13, 2, 5, 13, 5 }, +-{14, 2, 5, 14, 5 }, +-{15, 3, 5, 14, 8 }, +-{16, 6, 4 }, +-{17, 6, 8 }, +-{18, 7, 8 }, +-{19, 2, 5, 19, 5 }, +-{20, 8, 8 }, +-{21, 2, 5, 21, 5 }, +-{22, 2, 5, 22, 5 }, +-{23, 3, 5, 13, 8 }, +-{24, 9, 8 }, +-{25, 2, 5, 25, 5 }, +-{26, 2, 5, 26, 5 }, +-{27, 3, 5, 12, 8 }, +-{28, 2, 5, 28, 5 }, +-{29, 3, 5, 11, 8 }, +-{30, 3, 5, 10, 8 }, +-{31, 3, 5, 7, 4 }, +-{32, 7, 4 }, +-{33, 10, 8 }, +-{34, 11, 8 }, +-{35, 2, 5, 3, 5 }, +-{36, 12, 8 }, +-{37, 2, 5, 5, 5 }, +-{38, 2, 5, 6, 5 }, +-{39, 3, 5, 9, 8 }, +-{40, 13, 8 }, +-{41, 2, 5, 9, 5 }, +-{42, 2, 5, 10, 5 }, +-{43, 3, 5, 8, 8 }, +-{44, 2, 5, 12, 5 }, +-{45, 3, 5, 7, 8 }, +-{46, 3, 5, 6, 8 }, +-{47, 3, 5, 6, 4 }, +-{48, 14, 8 }, +-{49, 2, 5, 17, 5 }, +-{50, 2, 5, 18, 5 }, +-{51, 3, 5, 5, 8 }, +-{52, 2, 5, 20, 5 }, +-{53, 3, 5, 4, 8 }, +-{54, 3, 5, 3, 8 }, +-{55, 3, 5, 5, 4 }, +-{56, 2, 5, 24, 5 }, +-{57, 3, 5, 2, 8 }, +-{58, 3, 5, 1, 8 }, +-{59, 3, 5, 4, 4 }, +-{60, 3, 5, 0, 8 }, +-{61, 3, 5, 3, 4 }, +-{62, 3, 5, 2, 4 }, +-{63, 3, 5, 1, 1 }, ++ 1, 4, 4, 8, 4, 8, 8, 10, 4, 8, 8, 10, 8, 10, 10, 13, ++ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, ++ 4, 8, 8, 10, 8, 10, 10, 13, 8, 10, 10, 13, 10, 13, 13, 9, ++ 8, 10, 10, 13, 10, 13, 13, 9, 10, 13, 13, 9, 13, 9, 9, 6, + }; +-#endif + + /* 4MV Block pattern VLC tables */ + const uint8_t ff_vc1_4mv_block_pattern_codes[4][16] = { +- { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2}, +- { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0}, +- { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0}, +- { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10} ++ { 14, 58, 59, 25, 12, 26, 15, 15, 13, 24, 27, 0, 28, 1, 2, 2 }, ++ { 8, 18, 19, 4, 20, 5, 30, 11, 21, 31, 6, 12, 7, 13, 14, 0 }, ++ { 15, 6, 7, 2, 8, 3, 28, 9, 10, 29, 4, 11, 5, 12, 13, 0 }, ++ { 0, 11, 12, 4, 13, 5, 30, 16, 14, 31, 6, 17, 7, 18, 19, 10 } + }; + const uint8_t ff_vc1_4mv_block_pattern_bits[4][16] = { +- { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2}, +- { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2}, +- { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3}, +- { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4} ++ { 5, 6, 6, 5, 5, 5, 5, 4, 5, 5, 5, 3, 5, 3, 3, 2 }, ++ { 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4, 4, 4, 4, 4, 2 }, ++ { 4, 4, 4, 4, 4, 4, 5, 4, 4, 5, 4, 4, 4, 4, 4, 3 }, ++ { 2, 4, 4, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 4 } ++}; ++ ++/* 2MV Block pattern VLC tables */ ++const uint8_t ff_vc1_2mv_block_pattern_codes[4][4] = { ++ { 2, 1, 0, 3 }, { 1, 0, 2, 3 }, { 2, 0, 3, 1 }, { 1, 3, 2, 0 } ++}; ++ ++const uint8_t ff_vc1_2mv_block_pattern_bits[4][4] = { ++ { 2, 2, 2, 2 }, { 1, 2, 3, 3 }, { 3, 2, 3, 1 }, { 1, 3, 3, 2 } ++}; ++ ++/* Interlaced frame picture 4MV MBMODE VLC tables (p. 246, p. 360) */ ++const uint16_t ff_vc1_intfr_4mv_mbmode_codes[4][15] = { ++ { 22, 17, 0, 47, 32, 10, 1, 3, 67, 133, 132, 92, 19, 93, 18 }, ++ { 3, 45, 0, 7, 23, 6, 1, 2, 10, 39, 44, 8, 18, 77, 76 }, ++ { 15, 6, 28, 9, 41, 6, 2, 15, 14, 8, 40, 29, 0, 21, 11 }, ++ { 7, 198, 1, 2, 193, 13, 25, 0, 97, 1599, 98, 398, 798, 192, 1598 } ++}; ++ ++const uint8_t ff_vc1_intfr_4mv_mbmode_bits[4][15] = { ++ { 5, 5, 2, 6, 6, 4, 2, 2, 7, 8, 8, 7, 5, 7, 5 }, ++ { 3, 6, 3, 3, 5, 3, 3, 3, 4, 6, 6, 4, 5, 7, 7 }, ++ { 4, 3, 5, 5, 7, 4, 2, 5, 5, 5, 7, 5, 2, 6, 5 }, ++ { 4, 9, 1, 3, 9, 5, 6, 2, 8, 12, 8, 10, 11, 9, 12 } ++}; ++ ++/* Interlaced frame picture NON-4MV MBMODE VLC tables (p. 363) */ ++const uint8_t ff_vc1_intfr_non4mv_mbmode_codes[4][9] = { ++ { 9, 22, 0, 17, 16, 10, 1, 3, 23 }, ++ { 7, 0, 5, 2, 1, 1, 6, 3, 4 }, ++ { 1, 0, 10, 23, 44, 8, 3, 9, 45 }, ++ { 7, 97, 1, 2, 49, 13, 25, 0, 96 } ++}; ++ ++const uint8_t ff_vc1_intfr_non4mv_mbmode_bits[4][9] = { ++ { 4, 5, 2, 5, 5, 4, 2, 2, 5 }, ++ { 3, 4, 6, 2, 3, 2, 3, 5, 6 }, ++ { 2, 2, 4, 5, 6, 4, 2, 4, 6 }, ++ { 4, 8, 1, 3, 7, 5, 6, 2, 8 } ++}; ++ ++/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */ ++/* mixed-MV */ ++const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8] = { ++ { 16, 17, 3, 3, 0, 5, 9, 2 }, ++ { 8, 9, 3, 6, 7, 0, 5, 2 }, ++ { 16, 17, 5, 3, 0, 3, 9, 2 }, ++ { 56, 57, 15, 4, 5, 6, 29, 0 }, ++ { 52, 53, 27, 14, 15, 2, 12, 0 }, ++ { 56, 57, 29, 5, 6, 0, 15, 4 }, ++ { 16, 17, 6, 7, 0, 1, 9, 5 }, ++ { 56, 57, 0, 5, 6, 29, 4, 15 } ++}; ++const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8] = { ++ { 6, 6, 2, 3, 2, 4, 5, 2 }, ++ { 5, 5, 3, 3, 3, 2, 4, 2 }, ++ { 6, 6, 4, 3, 2, 2, 5, 2 }, ++ { 6, 6, 4, 3, 3, 3, 5, 1 }, ++ { 6, 6, 5, 4, 4, 2, 4, 1 }, ++ { 6, 6, 5, 3, 3, 1, 4, 3 }, ++ { 5, 5, 3, 3, 2, 2, 4, 3 }, ++ { 6, 6, 1, 3, 3, 5, 3, 4 } ++}; ++/* 1MV */ ++const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6] = { ++ { 0, 1, 1, 1, 1, 1 }, ++ { 0, 1, 1, 1, 1, 1 }, ++ { 16, 17, 3, 0, 9, 5 }, ++ { 20, 21, 3, 11, 0, 4 }, ++ { 4, 5, 2, 3, 3, 0 }, ++ { 4, 5, 3, 2, 0, 3 }, ++ { 0, 1, 1, 1, 1, 1 }, ++ { 16, 17, 9, 5, 3, 0 } ++}; ++const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6] = { ++ { 5, 5, 1, 3, 2, 4 }, ++ { 5, 5, 1, 2, 3, 4 }, ++ { 5, 5, 2, 1, 4, 3 }, ++ { 5, 5, 2, 4, 1, 3 }, ++ { 4, 4, 2, 3, 2, 2 }, ++ { 4, 4, 3, 2, 2, 2 }, ++ { 5, 5, 3, 4, 1, 2 }, ++ { 5, 5, 4, 3, 2, 1 } ++}; ++ ++/* Interlaced frame/field picture MVDATA VLC tables */ ++ ++/* 1-reference tables */ ++const uint32_t ff_vc1_1ref_mvdata_codes[4][72] = { /* uint32_t may be too big */ ++ { ++ 0x00005, 0x0000C, 0x0001E, 0x00012, 0x0000C, 0x00034, 0x00075, 0x00070, ++ 0x00000, 0x00008, 0x0001B, 0x00008, 0x0001D, 0x0007C, 0x000D6, 0x001DE, ++ 0x001AF, 0x00005, 0x0001B, 0x00026, 0x0001E, 0x00012, 0x00076, 0x0004D, ++ 0x001F6, 0x001F4, 0x00039, 0x0007F, 0x00027, 0x0006A, 0x00071, 0x00035, ++ 0x00071, 0x00068, 0x001DC, 0x00027, 0x00073, 0x000FF, 0x000E8, 0x000E9, ++ 0x0007E, 0x001F9, 0x001F5, 0x001FD, 0x0003E, 0x001CA, 0x003F9, 0x0004C, ++ 0x00069, 0x001FA, 0x001DF, 0x001F7, 0x00070, 0x001DD, 0x00E4D, 0x00727, ++ 0x00392, 0x001C8, 0x001CB, 0x003F8, 0x001AE, 0x001F8, 0x001FB, 0x0E4CE, ++ 0x0E4CF, 0x07260, 0x07261, 0x07262, 0x07263, 0x07264, 0x07265, 0x07266 ++ }, ++ { ++ 0x00007, 0x00001, 0x00007, 0x00016, 0x00001, 0x00045, 0x00018, 0x002B6, ++ 0x00006, 0x00004, 0x00017, 0x00010, 0x00029, 0x0002C, 0x0015A, 0x00066, ++ 0x0019E, 0x00009, 0x00028, 0x00017, 0x00000, 0x0002A, 0x00004, 0x0005B, ++ 0x000B5, 0x000CE, 0x00006, 0x00044, 0x0000F, 0x00046, 0x0000E, 0x000AC, ++ 0x00032, 0x00037, 0x011EB, 0x0000A, 0x0001A, 0x0011F, 0x00016, 0x00014, ++ 0x0002B, 0x00168, 0x00055, 0x023D5, 0x00057, 0x0002F, 0x00036, 0x0002E, ++ 0x00169, 0x00054, 0x0047B, 0x0019F, 0x02B7D, 0x0008E, 0x00ADE, 0x00479, ++ 0x0056E, 0x008F4, 0x015BF, 0x00478, 0x023D4, 0x0ADF1, 0x056F9, 0xADF0E, ++ 0xADF0F, 0x56F80, 0x56F81, 0x56F82, 0x56F83, 0x56F84, 0x56F85, 0x56F86 ++ }, ++ { ++ 0x00002, 0x00006, 0x00007, 0x0000D, 0x00007, 0x00030, 0x000FF, 0x001F0, ++ 0x00002, 0x00000, 0x00005, 0x00019, 0x0001E, 0x00007, 0x00063, 0x000FD, ++ 0x00023, 0x0000E, 0x0001B, 0x0001A, 0x00006, 0x00009, 0x00018, 0x000C5, ++ 0x00033, 0x001F1, 0x00002, 0x003FB, 0x001F3, 0x00022, 0x001FC, 0x00042, ++ 0x00623, 0x00083, 0x00620, 0x0007D, 0x00040, 0x00043, 0x003E4, 0x003E5, ++ 0x00191, 0x00FE9, 0x00105, 0x00208, 0x000FC, 0x00624, 0x00622, 0x00190, ++ 0x00626, 0x007F5, 0x00C4B, 0x01FD0, 0x0104D, 0x00065, 0x00C42, 0x000C9, ++ 0x00627, 0x00C43, 0x00C4A, 0x0104E, 0x01FD1, 0x0104F, 0x00412, 0x104CE, ++ 0x104CF, 0x08260, 0x08261, 0x08262, 0x08263, 0x08264, 0x08265, 0x08266 ++ }, ++ { ++ 0x0000D, 0x00001, 0x00004, 0x00000, 0x00017, 0x00005, 0x0007F, 0x0004D, ++ 0x00003, 0x00011, 0x0003E, 0x0003B, 0x00017, 0x00067, 0x0004A, 0x000C3, ++ 0x000F2, 0x0000A, 0x0002C, 0x00032, 0x0003D, 0x00015, 0x00028, 0x00093, ++ 0x000CC, 0x00096, 0x00003, 0x00075, 0x00020, 0x0002D, 0x00021, 0x00029, ++ 0x00090, 0x001D0, 0x001FB, 0x0001C, 0x0004C, 0x00060, 0x00009, 0x00008, ++ 0x0002D, 0x0009F, 0x001FA, 0x0013D, 0x00031, 0x000FC, 0x00058, 0x00092, ++ 0x000F0, 0x000F1, 0x000CD, 0x00185, 0x00165, 0x0004E, 0x00091, 0x000E9, ++ 0x00184, 0x001D1, 0x001E6, 0x00097, 0x001E7, 0x000B3, 0x0013C, 0x0164E, ++ 0x0164F, 0x00B20, 0x00B21, 0x00B22, 0x00B23, 0x00B24, 0x00B25, 0x00B26 ++ } ++}; ++ ++const uint8_t ff_vc1_1ref_mvdata_bits[4][72] = { ++ { ++ 3, 4, 5, 5, 5, 6, 7, 7, 2, 4, 5, 5, 6, 7, 8, 9, 9, 4, ++ 6, 6, 6, 6, 7, 8, 9, 9, 6, 8, 7, 7, 7, 7, 8, 8, 9, 6, ++ 8, 8, 8, 8, 8, 9, 9, 9, 7, 10, 10, 8, 8, 9, 9, 9, 8, 9, ++ 13, 12, 11, 10, 10, 10, 9, 9, 9, 17, 17, 16, 16, 16, 16, 16, 16, 16 ++ }, ++ { ++ 3, 3, 4, 5, 5, 7, 8, 10, 3, 4, 5, 5, 6, 7, 9, 10, 12, 4, ++ 6, 6, 5, 6, 6, 8, 9, 11, 4, 7, 7, 7, 7, 8, 9, 9, 13, 5, ++ 8, 9, 8, 8, 9, 10, 10, 14, 7, 9, 9, 9, 10, 10, 11, 12, 14, 8, ++ 12, 11, 11, 12, 13, 11, 14, 16, 15, 20, 20, 19, 19, 19, 19, 19, 19, 19 ++ }, ++ { ++ 3, 4, 4, 4, 5, 6, 8, 9, 2, 4, 5, 5, 5, 6, 7, 8, 8, 4, ++ 7, 7, 6, 6, 7, 8, 8, 9, 5, 10, 9, 8, 9, 9, 11, 10, 11, 7, ++ 9, 9, 10, 10, 11, 12, 11, 12, 8, 11, 11, 11, 11, 11, 12, 13, 15, 9, ++ 12, 10, 11, 12, 12, 15, 13, 15, 13, 19, 19, 18, 18, 18, 18, 18, 18, 18 ++ }, ++ { ++ 4, 4, 4, 4, 5, 5, 7, 7, 3, 5, 6, 6, 6, 7, 7, 8, 8, 4, ++ 6, 6, 6, 6, 7, 8, 8, 8, 4, 7, 6, 6, 6, 7, 8, 9, 9, 5, ++ 7, 7, 6, 6, 7, 8, 9, 9, 6, 8, 8, 8, 8, 8, 8, 9, 10, 7, ++ 8, 8, 9, 9, 9, 8, 9, 9, 9, 14, 14, 13, 13, 13, 13, 13, 13, 13 ++ } + }; + +-const uint8_t wmv3_dc_scale_table[32]={ +- 0, 2, 4, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13,14,14,15,15,16,16,17,17,18,18,19,19,20,20,21,21 ++/* 2-reference tables */ ++const uint32_t ff_vc1_2ref_mvdata_codes[8][126] = { /* table 132 - table 139 */ ++ { ++ 0x0000C, 0x0001C, 0x0000B, 0x00000, 0x0000E, 0x0002A, 0x00050, 0x00368, ++ 0x00002, 0x0001A, 0x00004, 0x0003A, 0x0001D, 0x0006C, 0x000EF, 0x001BC, ++ 0x0015F, 0x0000F, 0x00003, 0x0001C, 0x0000D, 0x0000B, 0x0003E, 0x000A7, ++ 0x00146, 0x00199, 0x00006, 0x0001F, 0x00004, 0x0003C, 0x00007, 0x001BE, ++ 0x0008B, 0x0002C, 0x007B3, 0x00005, 0x000DB, 0x00056, 0x000EC, 0x00052, ++ 0x001BD, 0x00078, 0x000CF, 0x00573, 0x00009, 0x00023, 0x000ED, 0x00018, ++ 0x00006, 0x00044, 0x000F5, 0x00079, 0x006D2, 0x0006E, 0x0002B, 0x0015D, ++ 0x00017, 0x0037F, 0x00144, 0x000CE, 0x00028, 0x000AB, 0x00010, 0x001B5, ++ 0x000F7, 0x000A6, 0x0007B, 0x00028, 0x001ED, 0x001E9, 0x006FD, 0x00004, ++ 0x000F5, 0x00029, 0x0028A, 0x0028B, 0x0028F, 0x00DF9, 0x00335, 0x01E85, ++ 0x000EE, 0x002BD, 0x0002B, 0x003D8, 0x003D1, 0x00198, 0x001E9, 0x0051D, ++ 0x000B4, 0x0003F, 0x00455, 0x0022B, 0x00229, 0x00451, 0x00578, 0x007B2, ++ 0x00570, 0x00155, 0x00032, 0x003D0, 0x00054, 0x006D3, 0x00571, 0x00454, ++ 0x00334, 0x01BF1, 0x000B7, 0x00029, 0x01E84, 0x0016C, 0x0019B, 0x01BF0, ++ 0x00579, 0x00F43, 0x000B5, 0x008A1, 0x0002A, 0x0016D, 0x008A0, 0x007A0, ++ 0x003D1, 0x00AE5, 0x00154, 0x00AE4, 0x00A39, 0x00A38 ++ }, ++ { ++ 0x00003, 0x00009, 0x00016, 0x00010, 0x000D7, 0x00335, 0x00574, 0x00555, ++ 0x00000, 0x0001D, 0x00009, 0x00017, 0x0002C, 0x000AD, 0x00374, 0x006B3, ++ 0x00577, 0x0000F, 0x00018, 0x0000A, 0x0002E, 0x00022, 0x0017C, 0x00E7B, ++ 0x01B89, 0x015D8, 0x00008, 0x00034, 0x0006D, 0x00023, 0x001C2, 0x00376, ++ 0x002D3, 0x01C4A, 0x0330A, 0x00014, 0x0006A, 0x00072, 0x0006C, 0x000E3, ++ 0x0019B, 0x0073F, 0x01CF0, 0x00B41, 0x00032, 0x000E6, 0x000E0, 0x000CF, ++ 0x000AB, 0x0019C, 0x002AB, 0x00E2B, 0x015D9, 0x0006F, 0x001C3, 0x000AF, ++ 0x000BF, 0x000AC, 0x0017D, 0x006E3, 0x00E29, 0x01984, 0x00054, 0x000B5, ++ 0x0017A, 0x001AD, 0x00199, 0x00178, 0x00358, 0x002D2, 0x01C4B, 0x0005B, ++ 0x002A8, 0x00331, 0x00388, 0x0038B, 0x00370, 0x00713, 0x00CC3, 0x01CF1, ++ 0x001B9, 0x005EF, 0x00738, 0x002F2, 0x0033B, 0x002B9, 0x006EB, 0x00570, ++ 0x00E24, 0x0039D, 0x005A2, 0x005A3, 0x00E7D, 0x005EE, 0x00739, 0x00554, ++ 0x00AA5, 0x00AA4, 0x00377, 0x01CF5, 0x00BCE, 0x00E79, 0x00660, 0x00674, ++ 0x006EA, 0x00E7C, 0x00D65, 0x002F6, 0x015DA, 0x01B88, 0x005A1, 0x01CF4, ++ 0x005E6, 0x00E28, 0x00575, 0x00D64, 0x00334, 0x0330B, 0x015DB, 0x00B40, ++ 0x00BCF, 0x00DC5, 0x00E2A, 0x00675, 0x00571, 0x00553 ++ }, ++ { ++ 0x00004, 0x00002, 0x00010, 0x00003, 0x00017, 0x00045, 0x0003E, 0x0007E, ++ 0x00003, 0x00002, 0x00028, 0x0001E, 0x00015, 0x00047, 0x00002, 0x0014D, ++ 0x00060, 0x0000B, 0x00026, 0x00024, 0x00014, 0x00032, 0x0006F, 0x000C3, ++ 0x00531, 0x006E5, 0x00015, 0x0003F, 0x0002D, 0x00001, 0x0013E, 0x000DD, ++ 0x000F6, 0x00305, 0x00331, 0x0000E, 0x00003, 0x00034, 0x00033, 0x0001A, ++ 0x0014A, 0x000C5, 0x000F4, 0x006E4, 0x00001, 0x0003C, 0x0007D, 0x0008D, ++ 0x0009D, 0x00031, 0x0006E, 0x00296, 0x000CD, 0x00025, 0x00149, 0x00032, ++ 0x00089, 0x00036, 0x00088, 0x0006F, 0x00003, 0x0031D, 0x0000E, 0x001AA, ++ 0x0027E, 0x00061, 0x0014E, 0x0014F, 0x00067, 0x000FF, 0x00183, 0x00036, ++ 0x00357, 0x000F5, 0x000C6, 0x000C2, 0x00299, 0x00119, 0x00231, 0x00350, ++ 0x0002C, 0x0018F, 0x00530, 0x00297, 0x00004, 0x001B8, 0x000C0, 0x0027A, ++ 0x00311, 0x0009C, 0x00621, 0x00199, 0x0031C, 0x000F7, 0x003E3, 0x00356, ++ 0x00189, 0x00005, 0x0006B, 0x008C2, 0x00330, 0x004FF, 0x004F0, 0x00351, ++ 0x004F2, 0x001F2, 0x00373, 0x00000, 0x00C41, 0x008C3, 0x009EC, 0x003E2, ++ 0x00304, 0x004F7, 0x004F1, 0x001F0, 0x00148, 0x00C40, 0x009ED, 0x008C0, ++ 0x008C1, 0x004F3, 0x004FE, 0x000FE, 0x001F3, 0x001A9 ++ }, ++ { ++ 0x00000, 0x00004, 0x0002F, 0x00052, 0x00010, 0x000AD, 0x0050B, 0x00190, ++ 0x00003, 0x00016, 0x00007, 0x0000D, 0x000BB, 0x00173, 0x000C9, 0x0050F, ++ 0x0172C, 0x00003, 0x00011, 0x00005, 0x00043, 0x00023, 0x0004B, 0x0032E, ++ 0x02E5B, 0x00482, 0x00009, 0x0002A, 0x00014, 0x0002A, 0x00108, 0x005CA, ++ 0x0065A, 0x02136, 0x02132, 0x0000B, 0x00013, 0x00041, 0x000B8, 0x00174, ++ 0x00100, 0x014DA, 0x0404E, 0x01437, 0x0002B, 0x00085, 0x000A7, 0x000A0, ++ 0x0014C, 0x0029A, 0x0032C, 0x02133, 0x0142A, 0x00051, 0x00284, 0x000AC, ++ 0x00102, 0x00045, 0x00044, 0x0081B, 0x0065E, 0x00CB7, 0x00018, 0x0050C, ++ 0x00212, 0x002E4, 0x00203, 0x00094, 0x00122, 0x0081A, 0x00655, 0x00033, ++ 0x002BA, 0x00246, 0x00242, 0x00A6E, 0x0040C, 0x00808, 0x02134, 0x0404F, ++ 0x00175, 0x00405, 0x00247, 0x0012A, 0x00A14, 0x002BB, 0x00191, 0x0084F, ++ 0x01438, 0x000AF, 0x00B97, 0x00483, 0x0143B, 0x0032B, 0x00243, 0x0142B, ++ 0x00958, 0x029BF, 0x00049, 0x00A6C, 0x014DB, 0x004AD, 0x014DE, 0x0084E, ++ 0x01434, 0x00257, 0x02E5A, 0x00207, 0x01435, 0x01439, 0x00CB6, 0x0143A, ++ 0x00194, 0x00654, 0x02135, 0x0537C, 0x0015C, 0x00240, 0x01012, 0x0537D, ++ 0x00959, 0x01098, 0x01436, 0x0065F, 0x02026, 0x02137 ++ }, ++ { ++ 0x00005, 0x00019, 0x00016, 0x00011, 0x0003E, 0x0005E, 0x000EF, 0x000E2, ++ 0x00000, 0x00039, 0x0002B, 0x00026, 0x00028, 0x00012, 0x000C2, 0x000ED, ++ 0x0011D, 0x0000D, 0x00031, 0x0002A, 0x00025, 0x00020, 0x0005C, 0x001ED, ++ 0x0024D, 0x00770, 0x00006, 0x0007A, 0x00060, 0x0004F, 0x00048, 0x00039, ++ 0x00186, 0x00213, 0x00EC6, 0x0000F, 0x00026, 0x0005F, 0x00075, 0x00070, ++ 0x00027, 0x001DB, 0x003C6, 0x0078F, 0x0003F, 0x000A6, 0x000F0, 0x0003A, ++ 0x00052, 0x0004E, 0x000E3, 0x001D9, 0x0030F, 0x00010, 0x001DD, 0x000A7, ++ 0x000F7, 0x00022, 0x00092, 0x003C4, 0x002EF, 0x00762, 0x00079, 0x0008F, ++ 0x001DA, 0x00087, 0x000E8, 0x000BA, 0x00176, 0x000EE, 0x003B0, 0x00085, ++ 0x00119, 0x0030E, 0x00108, 0x001D2, 0x0010C, 0x00773, 0x00424, 0x00434, ++ 0x00071, 0x005DD, 0x001C1, 0x003A7, 0x00127, 0x0008D, 0x0021B, 0x007B2, ++ 0x001DF, 0x003D8, 0x00764, 0x00EE4, 0x003B3, 0x0074D, 0x001D8, 0x005DC, ++ 0x0084A, 0x00499, 0x003C5, 0x01D8E, 0x00765, 0x00435, 0x00771, 0x001C2, ++ 0x00118, 0x003BC, 0x00381, 0x00387, 0x07B33, 0x01097, 0x01096, 0x01ECD, ++ 0x00E99, 0x00F1C, 0x00F1D, 0x00EE5, 0x0011C, 0x07B32, 0x03D98, 0x01D8F, ++ 0x00E98, 0x00F67, 0x003BD, 0x00380, 0x00498, 0x00386 ++ }, ++ { ++ 0x0000D, 0x00010, 0x0002E, 0x00039, 0x0000D, 0x00074, 0x000ED, 0x000B6, ++ 0x00001, 0x00002, 0x00000, 0x00030, 0x00029, 0x00070, 0x000F3, 0x0008C, ++ 0x00166, 0x00009, 0x00033, 0x00078, 0x00006, 0x000C4, 0x0000B, 0x00163, ++ 0x000CC, 0x005BE, 0x0001F, 0x0002F, 0x00064, 0x00018, 0x000C6, 0x0000A, ++ 0x00162, 0x002C0, 0x00EF3, 0x00007, 0x0000F, 0x000E3, 0x000CA, 0x000B2, ++ 0x0018F, 0x003AE, 0x0075F, 0x00C51, 0x00015, 0x00047, 0x000EE, 0x000E2, ++ 0x000EA, 0x00009, 0x0016A, 0x002C3, 0x0059D, 0x0003D, 0x00008, 0x001D9, ++ 0x00032, 0x0000E, 0x0016E, 0x0032C, 0x0065B, 0x0196B, 0x00002, 0x0000F, ++ 0x001D8, 0x0008D, 0x000B4, 0x001E4, 0x00067, 0x00317, 0x00794, 0x00022, ++ 0x003BE, 0x00315, 0x00034, 0x00037, 0x002DE, 0x0006C, 0x00EFE, 0x0066C, ++ 0x00028, 0x003CB, 0x003AC, 0x00035, 0x0016B, 0x003BD, 0x002C1, 0x0062C, ++ 0x01DFE, 0x0000E, 0x0059E, 0x005BF, 0x000DA, 0x00629, 0x00584, 0x00EB7, ++ 0x00B0A, 0x0066D, 0x0000C, 0x0077E, 0x0059C, 0x00778, 0x0075E, 0x0075A, ++ 0x0062D, 0x00337, 0x00334, 0x00197, 0x01E57, 0x01DE4, 0x0196A, 0x01E56, ++ 0x00C50, 0x00B3F, 0x01E54, 0x00B0B, 0x0018E, 0x001B6, 0x01E55, 0x00CB4, ++ 0x00B3E, 0x00EB6, 0x01DE5, 0x01DFF, 0x00335, 0x001B7 ++ }, ++ { ++ 0x00001, 0x0000B, 0x00019, 0x0006F, 0x0002A, 0x00075, 0x007EB, 0x00163, ++ 0x00001, 0x0000E, 0x0001A, 0x0003E, 0x0001C, 0x0002D, 0x00164, 0x007EC, ++ 0x00165, 0x00004, 0x00006, 0x00036, 0x0007F, 0x000AE, 0x00158, 0x0015C, ++ 0x0056D, 0xFD510, 0x00000, 0x00004, 0x0007B, 0x000F3, 0x0003B, 0x007ED, ++ 0x002B3, 0x002CC, 0x0056E, 0x00018, 0x0003E, 0x00017, 0x0001E, 0x000AF, ++ 0x003F7, 0x0056F, 0x002CD, 0xFD511, 0x00014, 0x000AD, 0x000AA, 0x00014, ++ 0x000A8, 0x00153, 0x000E8, 0x001FE, 0x00DCF, 0x00078, 0x001B8, 0x00152, ++ 0x000FE, 0x002B1, 0x0015D, 0x00160, 0xFD512, 0xFD513, 0x0007A, 0x002B0, ++ 0x001E5, 0x000E9, 0x000FC, 0x006E6, 0x00DC8, 0x00584, 0xFD514, 0x000AB, ++ 0x00DDE, 0x00159, 0x003F4, 0x00DC9, 0x00DCA, 0x001FA, 0xFD515, 0xFD516, ++ 0x000FC, 0x001FF, 0x001E4, 0x000AF, 0x0015A, 0x00167, 0x00DCB, 0x00585, ++ 0xFD517, 0x003F7, 0x03F55, 0xFD518, 0x00DDC, 0x00586, 0x03F56, 0xFD519, ++ 0x03F57, 0xFD51A, 0x001BA, 0x00587, 0x00588, 0x00DDF, 0x002B2, 0xFD51B, ++ 0x00DCE, 0x003F6, 0xFD51C, 0x00FD4, 0xFD51D, 0xFD51E, 0xFD51F, 0x7EA80, ++ 0x7EA81, 0x0056C, 0x7EA82, 0x7EA83, 0x00376, 0x00589, 0x0058A, 0x7EA84, ++ 0x7EA85, 0x00DDD, 0x7EA86, 0x7EA87, 0x0058B, 0x07EA9 ++ }, ++ { ++ 0x00003, 0x0000E, 0x0000F, 0x0007E, 0x00062, 0x000C6, 0x00CD9, 0x0063E, ++ 0x00002, 0x00002, 0x00000, 0x00018, 0x0000C, 0x00069, 0x00039, 0x00707, ++ 0x00C7E, 0x00002, 0x0000D, 0x0001B, 0x0000F, 0x0019A, 0x00647, 0x01A37, ++ 0x346C4, 0x0346D, 0x00001, 0x0001E, 0x0007F, 0x0000A, 0x000E1, 0x00661, ++ 0x00CE4, 0x346C5, 0x346C6, 0x0001D, 0x00030, 0x0000D, 0x000CB, 0x00199, ++ 0x00320, 0x0008E, 0x0652E, 0x346C7, 0x0003E, 0x00039, 0x00035, 0x00033, ++ 0x0019F, 0x001C0, 0x00CDA, 0x346C8, 0x346C9, 0x0000B, 0x000D0, 0x0019E, ++ 0x00022, 0x00038, 0x0018E, 0x0031E, 0x03294, 0x0023C, 0x00032, 0x00012, ++ 0x00013, 0x00071, 0x0019D, 0x00020, 0x00C87, 0x00CC0, 0x346CA, 0x00338, ++ 0x00653, 0x001A2, 0x0032A, 0x00322, 0x00CE7, 0x00084, 0x0011F, 0x346CB, ++ 0x00325, 0x00649, 0x0032B, 0x00077, 0x00648, 0x00642, 0x00C86, 0x00C8C, ++ 0x346CC, 0x0003A, 0x019B7, 0x00043, 0x00327, 0x0008C, 0x0008D, 0x00C8D, ++ 0x346CD, 0x346CE, 0x00337, 0x00CE5, 0x00085, 0x00326, 0x00347, 0x00CA4, ++ 0x00C7F, 0x00D1A, 0x346CF, 0x00328, 0x1A360, 0x1A361, 0x00CD8, 0x0068C, ++ 0x03295, 0x03296, 0x0652F, 0x066D8, 0x00331, 0x00706, 0x0023D, 0x00076, ++ 0x00CC1, 0x00382, 0x00CE6, 0x066D9, 0x066DA, 0x066DB ++ } ++}; ++ ++const uint8_t ff_vc1_2ref_mvdata_bits[8][126] = { ++ { ++ 4, 5, 5, 5, 6, 7, 8, 10, 2, 5, 5, 6, 6, 7, 8, 9, ++ 10, 4, 5, 6, 6, 7, 8, 9, 10, 11, 4, 6, 6, 7, 7, 9, ++ 9, 10, 12, 5, 8, 8, 8, 8, 9, 9, 10, 12, 5, 7, 8, 7, ++ 7, 8, 9, 9, 11, 7, 9, 10, 9, 10, 10, 10, 10, 12, 6, 9, ++ 9, 9, 9, 9, 10, 10, 11, 7, 10, 10, 11, 11, 11, 12, 12, 14, ++ 8, 11, 10, 11, 11, 11, 11, 12, 12, 8, 12, 11, 11, 12, 12, 12, ++ 12, 13, 8, 12, 11, 11, 12, 12, 12, 13, 12, 9, 14, 13, 11, 13, ++ 12, 13, 12, 13, 9, 13, 13, 12, 12, 13, 13, 13, 13, 13 ++ }, ++ { ++ 3, 4, 5, 6, 8, 10, 11, 11, 2, 5, 5, 6, 7, 8, 10, 11, ++ 11, 4, 5, 5, 6, 7, 9, 12, 13, 13, 4, 6, 7, 7, 9, 10, ++ 11, 13, 14, 5, 7, 7, 7, 8, 9, 11, 13, 13, 6, 8, 8, 8, ++ 8, 9, 10, 12, 13, 7, 9, 8, 8, 8, 9, 11, 12, 13, 7, 9, ++ 9, 9, 9, 9, 10, 11, 13, 8, 10, 10, 10, 10, 10, 11, 12, 13, ++ 9, 11, 11, 10, 10, 10, 11, 11, 12, 10, 12, 12, 12, 11, 11, 11, ++ 12, 12, 10, 13, 12, 12, 11, 11, 11, 12, 12, 10, 13, 13, 12, 13, ++ 11, 12, 11, 12, 10, 14, 13, 13, 12, 12, 12, 11, 11, 11 ++ }, ++ { ++ 4, 4, 5, 5, 6, 7, 8, 9, 2, 5, 6, 6, 6, 7, 7, 9, ++ 9, 4, 6, 6, 6, 7, 8, 9, 11, 12, 5, 7, 7, 7, 9, 9, ++ 10, 11, 12, 5, 7, 7, 7, 7, 9, 9, 10, 12, 5, 8, 8, 8, ++ 8, 8, 9, 10, 10, 6, 9, 8, 8, 8, 8, 9, 9, 11, 6, 10, ++ 10, 9, 9, 9, 9, 10, 10, 7, 11, 10, 9, 9, 10, 9, 10, 11, ++ 7, 10, 11, 10, 10, 10, 9, 10, 11, 8, 12, 11, 11, 10, 11, 11, ++ 10, 10, 8, 12, 12, 11, 11, 11, 11, 10, 11, 8, 13, 12, 12, 11, ++ 11, 11, 11, 10, 9, 13, 12, 12, 12, 11, 11, 10, 10, 10 ++ }, ++ { ++ 3, 4, 6, 7, 7, 9, 11, 11, 2, 5, 5, 6, 8, 9, 10, 11, ++ 13, 3, 5, 5, 7, 8, 9, 12, 14, 13, 4, 6, 6, 7, 9, 11, ++ 13, 14, 14, 5, 7, 7, 8, 9, 9, 13, 15, 13, 6, 8, 8, 8, ++ 9, 10, 12, 14, 13, 7, 10, 9, 9, 9, 9, 12, 13, 14, 7, 11, ++ 10, 10, 10, 10, 11, 12, 13, 8, 11, 12, 12, 12, 11, 12, 14, 15, ++ 9, 11, 12, 11, 12, 11, 11, 12, 13, 9, 12, 13, 13, 12, 12, 13, ++ 14, 14, 9, 12, 13, 13, 13, 12, 13, 12, 14, 10, 13, 13, 14, 13, ++ 11, 13, 14, 15, 10, 12, 13, 15, 14, 13, 13, 13, 14, 14 ++ }, ++ { ++ 4, 5, 5, 5, 6, 7, 8, 8, 2, 6, 6, 6, 6, 6, 8, 9, ++ 10, 4, 6, 6, 6, 6, 7, 9, 10, 11, 4, 7, 7, 7, 7, 7, ++ 9, 10, 12, 5, 7, 7, 7, 7, 7, 9, 10, 11, 6, 8, 8, 7, ++ 7, 7, 8, 9, 10, 6, 9, 8, 8, 7, 8, 10, 10, 11, 7, 9, ++ 9, 8, 8, 8, 9, 9, 10, 8, 10, 10, 9, 9, 9, 11, 11, 11, ++ 8, 11, 10, 10, 9, 9, 10, 11, 10, 10, 12, 12, 11, 11, 10, 11, ++ 12, 11, 10, 13, 12, 11, 11, 10, 10, 11, 11, 11, 15, 13, 13, 13, ++ 12, 12, 12, 12, 10, 15, 14, 13, 12, 12, 11, 11, 11, 11 ++ }, ++ { ++ 4, 5, 6, 6, 6, 7, 8, 8, 2, 4, 5, 6, 6, 7, 8, 8, ++ 9, 4, 6, 7, 7, 8, 8, 9, 10, 11, 5, 6, 7, 7, 8, 8, ++ 9, 10, 12, 5, 7, 8, 8, 8, 9, 10, 11, 12, 5, 7, 8, 8, ++ 8, 8, 9, 10, 11, 6, 8, 9, 8, 8, 9, 10, 11, 13, 5, 8, ++ 9, 8, 8, 9, 9, 10, 11, 6, 10, 10, 9, 9, 10, 10, 12, 13, ++ 6, 10, 10, 9, 9, 10, 10, 11, 13, 7, 11, 11, 11, 11, 11, 12, ++ 12, 13, 7, 11, 11, 11, 11, 11, 11, 12, 12, 9, 13, 13, 13, 13, ++ 12, 12, 13, 12, 9, 12, 13, 12, 12, 12, 13, 13, 12, 12 ++ }, ++ { ++ 3, 5, 6, 8, 9, 10, 12, 12, 1, 5, 6, 7, 8, 9, 12, 12, ++ 12, 4, 6, 7, 8, 9, 12, 12, 14, 21, 4, 6, 8, 9, 9, 12, ++ 13, 13, 14, 6, 9, 8, 8, 9, 13, 14, 13, 21, 6, 9, 9, 8, ++ 9, 10, 11, 12, 13, 8, 10, 10, 11, 11, 12, 12, 21, 21, 8, 11, ++ 10, 11, 11, 12, 13, 14, 21, 9, 13, 10, 11, 13, 13, 12, 21, 21, ++ 9, 12, 10, 11, 12, 12, 13, 14, 21, 11, 15, 21, 13, 14, 15, 21, ++ 15, 21, 10, 14, 14, 13, 13, 21, 13, 13, 21, 13, 21, 21, 21, 20, ++ 20, 14, 20, 20, 11, 14, 14, 20, 20, 13, 20, 20, 14, 16 ++ }, ++ { ++ 2, 5, 6, 8, 9, 10, 13, 13, 2, 4, 5, 6, 8, 9, 10, 13, ++ 14, 3, 5, 7, 8, 10, 12, 15, 20, 16, 4, 6, 8, 8, 10, 12, ++ 13, 20, 20, 7, 8, 8, 9, 10, 11, 12, 16, 20, 7, 8, 8, 8, ++ 10, 11, 13, 20, 20, 8, 10, 10, 10, 10, 11, 12, 15, 14, 8, 9, ++ 9, 9, 10, 10, 13, 13, 20, 11, 12, 11, 11, 11, 13, 12, 13, 20, ++ 11, 12, 11, 11, 12, 12, 13, 13, 20, 10, 14, 11, 11, 12, 12, 13, ++ 20, 20, 11, 13, 12, 11, 12, 13, 14, 14, 20, 11, 19, 19, 13, 13, ++ 15, 15, 16, 16, 11, 13, 14, 11, 13, 12, 13, 16, 16, 16 ++ } ++}; ++ ++const uint8_t wmv3_dc_scale_table[32] = { ++ 0, 2, 4, 8, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, ++ 14, 14, 15, 15, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21 + }; + + /* P-Picture CBPCY VLC tables */ +-#if 1 // Looks like original tables are not conforming to standard at all. Are they used for old WMV? ++// Looks like original tables are not conforming to standard at all. Are they used for old WMV? + const uint16_t ff_vc1_cbpcy_p_codes[4][64] = { + { + 0, 6, 15, 13, 13, 11, 3, 13, 5, 8, 49, 10, 12, 114, 102, 119, +@@ -330,60 +705,141 @@ + 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8 + } + }; +-#else +-const uint16_t ff_vc1_cbpcy_p_codes[4][64] = { ++ ++/* Interlaced CBPCY VLC tables (Table 124 - Table 131) */ ++const uint16_t ff_vc1_icbpcy_p_codes[8][63] = { + { +- 0, 1, 1, 4, 5, 1, 12, 4, 13, 14, 10, 11, 12, 7, 13, 2, +- 15, 1, 96, 1, 49, 97, 2, 100, 3, 4, 5, 101, 102, 52, 53, 4, +- 6, 7, 54, 103, 8, 9, 10, 110, 11, 12, 111, 56, 114, 58, 115, 5, +- 13, 7, 8, 9, 10, 11, 12, 30, 13, 14, 15, 118, 119, 62, 63, 3 ++ 0x2F1A, 0x2F1B, 0x178C, 0x0090, 0x02A8, 0x02A9, 0x0BC7, 0x0091, ++ 0x02AA, 0x02AB, 0x05E0, 0x004A, 0x0096, 0x0097, 0x00BD, 0x0092, ++ 0x02AC, 0x02AD, 0x05E1, 0x0098, 0x0132, 0x0133, 0x0179, 0x0134, ++ 0x026A, 0x026B, 0x02FC, 0x004E, 0x0040, 0x0041, 0x002B, 0x0093, ++ 0x02AE, 0x02AF, 0x05E2, 0x0136, 0x026E, 0x026F, 0x02FD, 0x009E, ++ 0x013E, 0x013F, 0x017F, 0x0050, 0x0042, 0x0043, 0x002C, 0x0051, ++ 0x00A4, 0x00A5, 0x00BE, 0x0053, 0x0044, 0x0045, 0x002D, 0x0054, ++ 0x0046, 0x0047, 0x002E, 0x0003, 0x0000, 0x0001, 0x0001 ++ }, ++ { ++ 0x0041, 0x0042, 0x0100, 0x0043, 0x0088, 0x0089, 0x0101, 0x0045, ++ 0x008C, 0x008D, 0x0102, 0x0010, 0x0022, 0x0023, 0x0024, 0x0047, ++ 0x0010, 0x0011, 0x0103, 0x0025, 0x0058, 0x0059, 0x005A, 0x005B, ++ 0x005A, 0x005B, 0x005C, 0x000C, 0x0030, 0x0031, 0x0019, 0x0009, ++ 0x0014, 0x0015, 0x002C, 0x005C, 0x005D, 0x005E, 0x005F, 0x0026, ++ 0x005D, 0x005E, 0x005F, 0x000D, 0x0034, 0x0035, 0x001B, 0x0014, ++ 0x0027, 0x002A, 0x002B, 0x000E, 0x0038, 0x0039, 0x001D, 0x000F, ++ 0x003C, 0x003D, 0x001F, 0x0005, 0x0009, 0x0000, 0x0003 ++ }, ++ { ++ 0x0032, 0x0033, 0x001A, 0x0026, 0x00E4, 0x00E5, 0x01E6, 0x0027, ++ 0x00E6, 0x00E7, 0x01E7, 0x000E, 0x0063, 0x006C, 0x0077, 0x0028, ++ 0x00E8, 0x00E9, 0x01E8, 0x007B, 0x00DA, 0x00DB, 0x00EC, 0x00F5, ++ 0x01B8, 0x01B9, 0x01DA, 0x0021, 0x004B, 0x0054, 0x002B, 0x0029, ++ 0x00EA, 0x00EB, 0x01E9, 0x004A, 0x01BA, 0x01BB, 0x01DB, 0x0020, ++ 0x00DE, 0x00DF, 0x00F2, 0x0022, 0x0055, 0x0058, 0x002D, 0x000F, ++ 0x0070, 0x0071, 0x0078, 0x0023, 0x0059, 0x005C, 0x002F, 0x0024, ++ 0x005D, 0x0062, 0x0030, 0x0002, 0x001F, 0x0006, 0x0000 ++ }, ++ { ++ 0x0028, 0x0029, 0x009D, 0x0000, 0x01EA, 0x01EB, 0x01EC, 0x0001, ++ 0x01ED, 0x01EE, 0x01EF, 0x0005, 0x00F0, 0x00F1, 0x003B, 0x0002, ++ 0x01F0, 0x01F1, 0x01F2, 0x003F, 0x015C, 0x015D, 0x0099, 0x0010, ++ 0x03D0, 0x03D1, 0x0130, 0x000F, 0x009E, 0x009F, 0x00FB, 0x0003, ++ 0x01F3, 0x01F4, 0x01F5, 0x0011, 0x03D2, 0x03D3, 0x0131, 0x0009, ++ 0x015E, 0x015F, 0x009C, 0x0010, 0x00A8, 0x00A9, 0x0038, 0x0006, ++ 0x00F2, 0x00F3, 0x004D, 0x0011, 0x00AA, 0x00AB, 0x0039, 0x0012, ++ 0x00AC, 0x00AD, 0x003A, 0x0006, 0x0016, 0x0017, 0x000E ++ }, ++ { ++ 0x003C, 0x003D, 0x001F, 0x000A, 0x0061, 0x0062, 0x0002, 0x000B, ++ 0x0063, 0x0064, 0x0003, 0x0007, 0x0003, 0x0004, 0x000B, 0x000C, ++ 0x0065, 0x0066, 0x0004, 0x0012, 0x000A, 0x000B, 0x0014, 0x001B, ++ 0x0018, 0x0019, 0x0034, 0x002C, 0x0067, 0x0068, 0x0035, 0x000D, ++ 0x0069, 0x006C, 0x0005, 0x0060, 0x001A, 0x001B, 0x0035, 0x0013, ++ 0x000E, 0x000F, 0x0015, 0x002D, 0x006D, 0x006E, 0x0038, 0x0008, ++ 0x0008, 0x0009, 0x000C, 0x002E, 0x006F, 0x0072, 0x003A, 0x002F, ++ 0x0073, 0x0000, 0x003B, 0x0007, 0x0014, 0x0015, 0x0004 ++ }, ++ { ++ 0x0038, 0x0039, 0x009D, 0x000A, 0x0091, 0x0092, 0x0093, 0x000B, ++ 0x0094, 0x0095, 0x0096, 0x0003, 0x00EE, 0x00EF, 0x0036, 0x000C, ++ 0x0097, 0x0098, 0x0099, 0x0008, 0x01E4, 0x01E5, 0x006A, 0x0018, ++ 0x03CC, 0x03CD, 0x00D6, 0x000E, 0x009E, 0x009F, 0x00F5, 0x000D, ++ 0x009A, 0x009B, 0x009C, 0x0019, 0x03CE, 0x03CF, 0x00D7, 0x0009, ++ 0x01E8, 0x01E9, 0x0090, 0x000F, 0x00E8, 0x00E9, 0x00F6, 0x0005, ++ 0x00F0, 0x00F1, 0x0037, 0x0010, 0x00EA, 0x00EB, 0x00F7, 0x0011, ++ 0x00EC, 0x00ED, 0x0034, 0x0000, 0x003E, 0x003F, 0x0002 ++ }, ++ { ++ 0x003C, 0x003D, 0x01CF, 0x0000, 0x00BF, 0x00E0, 0x01FC, 0x0001, ++ 0x00E1, 0x00E2, 0x01FD, 0x0009, 0x01F1, 0x01F2, 0x01F3, 0x0002, ++ 0x00E3, 0x00E4, 0x01FE, 0x0011, 0x03EE, 0x03EF, 0x03F0, 0x0021, ++ 0x07E2, 0x07E3, 0x07E4, 0x0018, 0x03F7, 0x03FE, 0x03FF, 0x0003, ++ 0x00E5, 0x00E6, 0x0080, 0x002E, 0x07E5, 0x07E6, 0x07E7, 0x0016, ++ 0x03F4, 0x03F5, 0x03F6, 0x0019, 0x0102, 0x0103, 0x0104, 0x000A, ++ 0x01F4, 0x01F5, 0x01F6, 0x001A, 0x0105, 0x0106, 0x0107, 0x001B, ++ 0x0178, 0x0179, 0x01CE, 0x001D, 0x00BD, 0x00BE, 0x01F0 ++ }, ++ { ++ 0x0003, 0x0004, 0x01B6, 0x0004, 0x002E, 0x002F, 0x000E, 0x0005, ++ 0x0030, 0x0031, 0x000F, 0x0003, 0x000A, 0x000B, 0x0014, 0x0006, ++ 0x0032, 0x0033, 0x0010, 0x0005, 0x0030, 0x0031, 0x0032, 0x0009, ++ 0x0066, 0x0067, 0x0068, 0x001D, 0x01B7, 0x01B8, 0x01B9, 0x0007, ++ 0x0034, 0x0035, 0x0011, 0x0016, 0x0069, 0x006A, 0x006B, 0x000A, ++ 0x0036, 0x0037, 0x00D8, 0x001E, 0x01BA, 0x01BB, 0x01BC, 0x0004, ++ 0x0015, 0x0016, 0x0017, 0x001F, 0x01BD, 0x01BE, 0x01BF, 0x0000, ++ 0x0010, 0x0011, 0x0012, 0x001C, 0x00D9, 0x00DA, 0x0013 ++ } ++}; ++ ++const uint8_t ff_vc1_icbpcy_p_bits[8][63] = { ++ { ++ 15, 15, 14, 9, 11, 11, 13, 9, 11, 11, 12, 8, 9, 9, 9, 9, ++ 11, 11, 12, 9, 10, 10, 10, 10, 11, 11, 11, 8, 8, 8, 7, 9, ++ 11, 11, 12, 10, 11, 11, 11, 9, 10, 10, 10, 8, 8, 8, 7, 8, ++ 9, 9, 9, 8, 8, 8, 7, 8, 8, 8, 7, 3, 3, 3, 1 + }, + { +- 0, 1, 2, 1, 3, 1, 16, 17, 5, 18, 12, 19, 13, 1, 28, 58, +- 1, 1, 1, 2, 3, 2, 3, 236, 237, 4, 5, 238, 6, 7, 239, 8, +- 9, 240, 10, 11, 121, 122, 12, 13, 14, 15, 241, 246, 16, 17, 124, 63, +- 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 247, 125 ++ 7, 7, 9, 7, 8, 8, 9, 7, 8, 8, 9, 6, 7, 7, 7, 7, ++ 7, 7, 9, 7, 8, 8, 8, 8, 9, 9, 9, 6, 7, 7, 6, 6, ++ 7, 7, 8, 8, 9, 9, 9, 7, 8, 8, 8, 6, 7, 7, 6, 6, ++ 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 3, 4, 3, 2 + }, + { +- 0, 1, 2, 3, 2, 3, 1, 4, 5, 24, 7, 13, 16, 17, 9, 5, +- 25, 1, 1, 1, 2, 3, 96, 194, 1, 2, 98, 99, 195, 200, 101, 26, +- 201, 102, 412, 413, 414, 54, 220, 111, 221, 3, 224, 113, 225, 114, 230, 29, +- 231, 415, 240, 4, 241, 484, 5, 243, 3, 244, 245, 485, 492, 493, 247, 31 ++ 6, 6, 5, 6, 8, 8, 9, 6, 8, 8, 9, 5, 7, 7, 7, 6, ++ 8, 8, 9, 7, 8, 8, 8, 8, 9, 9, 9, 6, 7, 7, 6, 6, ++ 8, 8, 9, 7, 9, 9, 9, 6, 8, 8, 8, 6, 7, 7, 6, 5, ++ 7, 7, 7, 6, 7, 7, 6, 6, 7, 7, 6, 3, 5, 4, 2 + }, + { +- 0, 1, 1, 1, 2, 2, 3, 4, 3, 5, 6, 7, 8, 9, 10, 11, +- 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +- 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, +- 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 28, 29, 30, 31 +- } +-}; +-const uint8_t ff_vc1_cbpcy_p_bits[4][64] = { ++ 6, 6, 8, 4, 9, 9, 9, 4, 9, 9, 9, 4, 8, 8, 7, 4, ++ 9, 9, 9, 6, 9, 9, 8, 6, 10, 10, 9, 5, 8, 8, 8, 4, ++ 9, 9, 9, 6, 10, 10, 9, 5, 9, 9, 8, 5, 8, 8, 7, 4, ++ 8, 8, 7, 5, 8, 8, 7, 5, 8, 8, 7, 3, 5, 5, 4 ++ }, + { +- 13, 6, 5, 6, 6, 7, 7, 5, 7, 7, 6, 6, 6, 5, 6, 3, +- 7, 8, 8, 13, 7, 8, 13, 8, 13, 13, 13, 8, 8, 7, 7, 3, +- 13, 13, 7, 8, 13, 13, 13, 8, 13, 13, 8, 7, 8, 7, 8, 3, +- 13, 12, 12, 12, 12, 12, 12, 6, 12, 12, 12, 8, 8, 7, 7, 2 ++ 6, 6, 5, 5, 7, 7, 7, 5, 7, 7, 7, 5, 6, 6, 6, 5, ++ 7, 7, 7, 6, 7, 7, 7, 7, 8, 8, 8, 6, 7, 7, 6, 5, ++ 7, 7, 7, 7, 8, 8, 8, 6, 7, 7, 7, 6, 7, 7, 6, 5, ++ 6, 6, 6, 6, 7, 7, 6, 6, 7, 6, 6, 4, 5, 5, 3 + }, + { +- 14, 3, 3, 5, 3, 4, 5, 5, 3, 5, 4, 5, 4, 6, 5, 6, +- 8, 14, 13, 8, 8, 13, 13, 8, 8, 13, 13, 8, 13, 13, 8, 13, +- 13, 8, 13, 13, 7, 7, 13, 13, 13, 13, 8, 8, 13, 13, 7, 6, +- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 8, 7 ++ 6, 6, 8, 4, 8, 8, 8, 4, 8, 8, 8, 4, 8, 8, 7, 4, ++ 8, 8, 8, 5, 9, 9, 8, 6, 10, 10, 9, 5, 8, 8, 8, 4, ++ 8, 8, 8, 6, 10, 10, 9, 5, 9, 9, 8, 5, 8, 8, 8, 4, ++ 8, 8, 7, 5, 8, 8, 8, 5, 8, 8, 7, 3, 6, 6, 4 + }, + { +- 13, 5, 5, 5, 4, 4, 6, 4, 4, 6, 4, 5, 5, 5, 4, 3, +- 6, 8, 10, 9, 8, 8, 7, 8, 13, 13, 7, 7, 8, 8, 7, 5, +- 8, 7, 9, 9, 9, 6, 8, 7, 8, 13, 8, 7, 8, 7, 8, 5, +- 8, 9, 8, 13, 8, 9, 13, 8, 12, 8, 8, 9, 9, 9, 8, 5 ++ 6, 6, 9, 3, 8, 8, 9, 3, 8, 8, 9, 4, 9, 9, 9, 3, ++ 8, 8, 9, 5, 10, 10, 10, 6, 11, 11, 11, 5, 10, 10, 10, 3, ++ 8, 8, 8, 6, 11, 11, 11, 5, 10, 10, 10, 5, 9, 9, 9, 4, ++ 9, 9, 9, 5, 9, 9, 9, 5, 9, 9, 9, 5, 8, 8, 9 + }, + { +- 9, 2, 3, 9, 2, 9, 9, 9, 2, 9, 9, 9, 9, 9, 9, 9, +- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, +- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, +- 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8 ++ 6, 6, 10, 3, 7, 7, 7, 3, 7, 7, 7, 4, 8, 8, 8, 3, ++ 7, 7, 7, 5, 9, 9, 9, 6, 10, 10, 10, 6, 10, 10, 10, 3, ++ 7, 7, 7, 6, 10, 10, 10, 5, 9, 9, 9, 6, 10, 10, 10, 4, ++ 8, 8, 8, 6, 10, 10, 10, 5, 9, 9, 9, 6, 9, 9, 9 + } + }; +-#endif + + /* MacroBlock Transform Type: 7.1.3.11, p89 + * 8x8:B +@@ -455,26 +911,26 @@ + + /* TTBLK (Transform Type per Block) tables */ + const uint8_t ff_vc1_ttblk_codes[3][8] = { +- { 0, 1, 3, 5, 16, 17, 18, 19}, +- { 3, 0, 1, 2, 3, 5, 8, 9}, +- { 1, 0, 1, 4, 6, 7, 10, 11} ++ { 0, 1, 3, 5, 16, 17, 18, 19 }, ++ { 3, 0, 1, 2, 3, 5, 8, 9 }, ++ { 1, 0, 1, 4, 6, 7, 10, 11 } + }; + const uint8_t ff_vc1_ttblk_bits[3][8] = { +- { 2, 2, 2, 3, 5, 5, 5, 5}, +- { 2, 3, 3, 3, 3, 3, 4, 4}, +- { 2, 3, 3, 3, 3, 3, 4, 4} ++ { 2, 2, 2, 3, 5, 5, 5, 5 }, ++ { 2, 3, 3, 3, 3, 3, 4, 4 }, ++ { 2, 3, 3, 3, 3, 3, 4, 4 } + }; + + /* SUBBLKPAT tables, p93-94, reordered */ + const uint8_t ff_vc1_subblkpat_codes[3][15] = { +- { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1}, +- { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1}, +- { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15} ++ { 14, 12, 7, 11, 9, 26, 2, 10, 27, 8, 0, 6, 1, 15, 1 }, ++ { 14, 0, 8, 15, 10, 4, 23, 13, 5, 9, 25, 3, 24, 22, 1 }, ++ { 5, 6, 2, 2, 8, 0, 28, 3, 1, 3, 29, 1, 19, 18, 15 } + }; + const uint8_t ff_vc1_subblkpat_bits[3][15] = { +- { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1}, +- { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2}, +- { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4} ++ { 5, 5, 5, 5, 5, 6, 4, 5, 6, 5, 4, 5, 4, 5, 1}, ++ { 4, 3, 4, 4, 4, 5, 5, 4, 5, 4, 5, 4, 5, 5, 2}, ++ { 3, 3, 4, 3, 4, 5, 5, 3, 5, 4, 5, 4, 5, 5, 4} + }; + + /* MV differential tables, p265 */ +@@ -563,83 +1019,113 @@ + /* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */ + + /* Table 232 */ +-const int8_t ff_vc1_simple_progressive_4x4_zz [16] = +-{ +- 0, 8, 16, 1, +- 9, 24, 17, 2, +- 10, 18, 25, 3, +- 11, 26, 19, 27 +-}; +- +-const int8_t ff_vc1_adv_progressive_8x4_zz [32] = /* Table 233 */ +-{ +- 0, 8, 1, 16, 2, 9, 10, 3, +- 24, 17, 4, 11, 18, 12, 5, 19, +- 25, 13, 20, 26, 27, 6, 21, 28, +- 14, 22, 29, 7, 30, 15, 23, 31 +-}; +- +-const int8_t ff_vc1_adv_progressive_4x8_zz [32] = /* Table 234 */ +-{ +- 0, 1, 8, 2, +- 9, 16, 17, 24, +- 10, 32, 25, 18, +- 40, 3, 33, 26, +- 48, 11, 56, 41, +- 34, 49, 57, 42, +- 19, 50, 27, 58, +- 35, 43, 51, 59 +-}; +- +-const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = /* Table 235 */ +-{ +- 0, 8, 1, 16, 24, 9, 2, 32, +- 40, 48, 56, 17, 10, 3, 25, 18, +- 11, 4, 33, 41, 49, 57, 26, 34, +- 42, 50, 58, 19, 12, 5, 27, 20, +- 13, 6, 35, 28, 21, 14, 7, 15, +- 22, 29, 36, 43, 51, 59, 60, 52, +- 44, 37, 30, 23, 31, 38, 45, 53, +- 61, 62, 54, 46, 39, 47, 55, 63 +-}; +- +-const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = /* Table 236 */ +-{ +- 0, 8, 16, 24, 1, 9, 2, 17, +- 25, 10, 3, 18, 26, 4, 11, 19, +- 12, 5, 13, 20, 27, 6, 21, 28, +- 14, 22, 29, 7, 30, 15, 23, 31 +-}; +- +-const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = /* Table 237 */ +-{ +- 0, 1, 2, 8, +- 16, 9, 24, 17, +- 10, 3, 32, 40, +- 48, 56, 25, 18, +- 33, 26, 41, 34, +- 49, 57, 11, 42, +- 19, 50, 27, 58, +- 35, 43, 51, 59 +-}; +- +-const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = /* Table 238 */ +-{ +- 0, 8, 16, 24, +- 1, 9, 17, 2, +- 25, 10, 18, 3, +- 26, 11, 19, 27 ++const int8_t ff_vc1_simple_progressive_4x4_zz [16] = { ++ 0, 8, 16, 1, ++ 9, 24, 17, 2, ++ 10, 18, 25, 3, ++ 11, 26, 19, 27 ++}; ++ ++const int8_t ff_vc1_adv_progressive_8x4_zz [32] = { /* Table 233 */ ++ 0, 8, 1, 16, 2, 9, 10, 3, ++ 24, 17, 4, 11, 18, 12, 5, 19, ++ 25, 13, 20, 26, 27, 6, 21, 28, ++ 14, 22, 29, 7, 30, 15, 23, 31 ++}; ++ ++const int8_t ff_vc1_adv_progressive_4x8_zz [32] = { /* Table 234 */ ++ 0, 1, 8, 2, ++ 9, 16, 17, 24, ++ 10, 32, 25, 18, ++ 40, 3, 33, 26, ++ 48, 11, 56, 41, ++ 34, 49, 57, 42, ++ 19, 50, 27, 58, ++ 35, 43, 51, 59 ++}; ++ ++const int8_t ff_vc1_adv_interlaced_8x8_zz [64] = { /* Table 235 */ ++ 0, 8, 1, 16, 24, 9, 2, 32, ++ 40, 48, 56, 17, 10, 3, 25, 18, ++ 11, 4, 33, 41, 49, 57, 26, 34, ++ 42, 50, 58, 19, 12, 5, 27, 20, ++ 13, 6, 35, 28, 21, 14, 7, 15, ++ 22, 29, 36, 43, 51, 59, 60, 52, ++ 44, 37, 30, 23, 31, 38, 45, 53, ++ 61, 62, 54, 46, 39, 47, 55, 63 ++}; ++ ++const int8_t ff_vc1_adv_interlaced_8x4_zz [32] = { /* Table 236 */ ++ 0, 8, 16, 24, 1, 9, 2, 17, ++ 25, 10, 3, 18, 26, 4, 11, 19, ++ 12, 5, 13, 20, 27, 6, 21, 28, ++ 14, 22, 29, 7, 30, 15, 23, 31 ++}; ++ ++const int8_t ff_vc1_adv_interlaced_4x8_zz [32] = { /* Table 237 */ ++ 0, 1, 2, 8, ++ 16, 9, 24, 17, ++ 10, 3, 32, 40, ++ 48, 56, 25, 18, ++ 33, 26, 41, 34, ++ 49, 57, 11, 42, ++ 19, 50, 27, 58, ++ 35, 43, 51, 59 ++}; ++ ++const int8_t ff_vc1_adv_interlaced_4x4_zz [16] = { /* Table 238 */ ++ 0, 8, 16, 24, ++ 1, 9, 17, 2, ++ 25, 10, 18, 3, ++ 26, 11, 19, 27 + }; + + + /* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */ + const int32_t ff_vc1_dqscale[63] = { +-0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000, +- 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000, +- 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB, +- 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000, +- 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A, +- 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555, +- 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249, +- 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000 ++ 0x40000, 0x20000, 0x15555, 0x10000, 0xCCCD, 0xAAAB, 0x9249, 0x8000, ++ 0x71C7, 0x6666, 0x5D17, 0x5555, 0x4EC5, 0x4925, 0x4444, 0x4000, ++ 0x3C3C, 0x38E4, 0x35E5, 0x3333, 0x30C3, 0x2E8C, 0x2C86, 0x2AAB, ++ 0x28F6, 0x2762, 0x25ED, 0x2492, 0x234F, 0x2222, 0x2108, 0x2000, ++ 0x1F08, 0x1E1E, 0x1D42, 0x1C72, 0x1BAD, 0x1AF3, 0x1A42, 0x199A, ++ 0x18FA, 0x1862, 0x17D0, 0x1746, 0x16C1, 0x1643, 0x15CA, 0x1555, ++ 0x14E6, 0x147B, 0x1414, 0x13B1, 0x1352, 0x12F7, 0x129E, 0x1249, ++ 0x11F7, 0x11A8, 0x115B, 0x1111, 0x10C9, 0x1084, 0x1000 ++}; ++ ++/* P Interlaced field picture MV predictor scaling values (Table 114) */ ++const uint16_t vc1_field_mvpred_scales[2][7][4] = { ++// Refdist: ++// 0 1 2 3 or greater ++ { // current field is first ++ { 128, 192, 213, 224 }, // SCALEOPP ++ { 512, 341, 307, 293 }, // SCALESAME1 ++ { 219, 236, 242, 245 }, // SCALESAME2 ++ { 32, 48, 53, 56 }, // SCALEZONE1_X ++ { 8, 12, 13, 14 }, // SCALEZONE1_Y ++ { 37, 20, 14, 11 }, // ZONE1OFFSET_X ++ { 10, 5, 4, 3 } // ZONE1OFFSET_Y ++ }, ++ { // current field is second ++ { 128, 64, 43, 32 }, // SCALEOPP ++ { 512, 1024, 1536, 2048 }, // SCALESAME1 ++ { 219, 204, 200, 198 }, // SCALESAME2 ++ { 32, 16, 11, 8 }, // SCALEZONE1_X ++ { 8, 4, 3, 2 }, // SCALEZONE1_Y ++ { 37, 52, 56, 58 }, // ZONE1OFFSET_X ++ { 10, 13, 14, 15 } // ZONE1OFFSET_Y ++ } ++}; ++ ++/* B Interlaced field picture backward MV predictor scaling values for first field (Table 115) */ ++const uint16_t vc1_b_field_mvpred_scales[7][4] = { ++ // BRFD: ++ // 0 1 2 3 or greater ++ { 171, 205, 219, 228 }, // SCALESAME ++ { 384, 320, 299, 288 }, // SCALEOPP1 ++ { 230, 239, 244, 246 }, // SCALEOPP2 ++ { 43, 51, 55, 57 }, // SCALEZONE1_X ++ { 11, 13, 14, 14 }, // SCALEZONE1_Y ++ { 26, 17, 12, 10 }, // ZONE1OFFSET_X ++ { 7, 4, 3, 3 } // ZONE1OFFSET_Y + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1data.h 2012-05-14 14:08:54.313339559 +0200 +@@ -44,6 +44,9 @@ + extern const int ff_vc1_fps_nr[5], ff_vc1_fps_dr[2]; + extern const uint8_t ff_vc1_pquant_table[3][32]; + ++/* MBMODE table for interlaced frame P-picture */ ++extern const uint8_t ff_vc1_mbmode_intfrp[2][15][4]; ++ + /** @name VC-1 VLC tables and defines + * @todo TODO move this into the context + */ +@@ -63,31 +66,40 @@ + extern VLC ff_vc1_mv_diff_vlc[4]; + #define VC1_CBPCY_P_VLC_BITS 9 //14 + extern VLC ff_vc1_cbpcy_p_vlc[4]; ++#define VC1_ICBPCY_VLC_BITS 9 ++extern VLC ff_vc1_icbpcy_vlc[8]; + #define VC1_4MV_BLOCK_PATTERN_VLC_BITS 6 + extern VLC ff_vc1_4mv_block_pattern_vlc[4]; ++#define VC1_2MV_BLOCK_PATTERN_VLC_BITS 3 ++extern VLC ff_vc1_2mv_block_pattern_vlc[4]; + #define VC1_TTBLK_VLC_BITS 5 + extern VLC ff_vc1_ttblk_vlc[3]; + #define VC1_SUBBLKPAT_VLC_BITS 6 + extern VLC ff_vc1_subblkpat_vlc[3]; ++#define VC1_INTFR_4MV_MBMODE_VLC_BITS 9 ++extern VLC ff_vc1_intfr_4mv_mbmode_vlc[4]; ++#define VC1_INTFR_NON4MV_MBMODE_VLC_BITS 6 ++extern VLC ff_vc1_intfr_non4mv_mbmode_vlc[4]; ++#define VC1_IF_MMV_MBMODE_VLC_BITS 5 ++extern VLC ff_vc1_if_mmv_mbmode_vlc[8]; ++#define VC1_IF_1MV_MBMODE_VLC_BITS 5 ++extern VLC ff_vc1_if_1mv_mbmode_vlc[8]; ++#define VC1_1REF_MVDATA_VLC_BITS 9 ++extern VLC ff_vc1_1ref_mvdata_vlc[4]; ++#define VC1_2REF_MVDATA_VLC_BITS 9 ++extern VLC ff_vc1_2ref_mvdata_vlc[8]; + + extern VLC ff_vc1_ac_coeff_table[8]; ++ ++#define VC1_IF_MBMODE_VLC_BITS 5 + //@} + + +-#if 0 //original bfraction from vc9data.h, not conforming to standard +-/* Denominator used for ff_vc1_bfraction_lut */ +-#define B_FRACTION_DEN 840 +- +-/* bfraction is fractional, we scale to the GCD 3*5*7*8 = 840 */ +-extern const int16_t ff_vc1_bfraction_lut[23]; +-#else + /* Denominator used for ff_vc1_bfraction_lut */ + #define B_FRACTION_DEN 256 + + /* pre-computed scales for all bfractions and base=256 */ + extern const int16_t ff_vc1_bfraction_lut[23]; +-#endif +- + extern const uint8_t ff_vc1_bfraction_bits[23]; + extern const uint8_t ff_vc1_bfraction_codes[23]; + +@@ -110,12 +122,20 @@ + extern const uint8_t ff_vc1_4mv_block_pattern_codes[4][16]; + extern const uint8_t ff_vc1_4mv_block_pattern_bits[4][16]; + ++/* 2MV Block pattern VLC tables */ ++extern const uint8_t ff_vc1_2mv_block_pattern_codes[4][4]; ++extern const uint8_t ff_vc1_2mv_block_pattern_bits[4][4]; ++ + extern const uint8_t wmv3_dc_scale_table[32]; + + /* P-Picture CBPCY VLC tables */ + extern const uint16_t ff_vc1_cbpcy_p_codes[4][64]; + extern const uint8_t ff_vc1_cbpcy_p_bits[4][64]; + ++/* Interlaced CBPCY VLC tables (Table 124 - Table 131) */ ++extern const uint16_t ff_vc1_icbpcy_p_codes[8][63]; ++extern const uint8_t ff_vc1_icbpcy_p_bits[8][63]; ++ + /* MacroBlock Transform Type: 7.1.3.11, p89 + * 8x8:B + * 8x4:B:btm 8x4:B:top 8x4:B:both, +@@ -140,6 +160,26 @@ + extern const uint16_t ff_vc1_mv_diff_codes[4][73]; + extern const uint8_t ff_vc1_mv_diff_bits[4][73]; + ++/* Interlaced frame picture MBMODE VLC tables (p. 246, p. 360) */ ++extern const uint16_t ff_vc1_intfr_4mv_mbmode_codes[4][15]; ++extern const uint8_t ff_vc1_intfr_4mv_mbmode_bits[4][15]; ++extern const uint8_t ff_vc1_intfr_non4mv_mbmode_codes[4][9]; ++extern const uint8_t ff_vc1_intfr_non4mv_mbmode_bits[4][9]; ++ ++/* Interlaced field picture MBMODE VLC tables (p. 356 - 11.4.1, 11.4.2) */ ++extern const uint8_t ff_vc1_if_mmv_mbmode_codes[8][8]; ++extern const uint8_t ff_vc1_if_mmv_mbmode_bits[8][8]; ++extern const uint8_t ff_vc1_if_1mv_mbmode_codes[8][6]; ++extern const uint8_t ff_vc1_if_1mv_mbmode_bits[8][6]; ++ ++/* Interlaced frame/field picture MVDATA VLC tables */ ++/* 1-reference tables */ ++extern const uint32_t ff_vc1_1ref_mvdata_codes[4][72]; ++extern const uint8_t ff_vc1_1ref_mvdata_bits[4][72]; ++/* 2-reference tables */ ++extern const uint32_t ff_vc1_2ref_mvdata_codes[8][126]; ++extern const uint8_t ff_vc1_2ref_mvdata_bits[8][126]; ++ + /* DC differentials low+hi-mo, p217 are the same as in msmpeg4data .h */ + + /* Scantables/ZZ scan are at 11.9 (p262) and 8.1.1.12 (p10) */ +@@ -150,8 +190,14 @@ + extern const int8_t ff_vc1_adv_interlaced_8x4_zz [32]; + extern const int8_t ff_vc1_adv_interlaced_4x8_zz [32]; + extern const int8_t ff_vc1_adv_interlaced_4x4_zz [16]; ++extern const int8_t ff_vc1_intra_horz_8x8_zz [64]; ++extern const int8_t ff_vc1_intra_vert_8x8_zz [64]; + + /* DQScale as specified in 8.1.3.9 - almost identical to 0x40000/i */ + extern const int32_t ff_vc1_dqscale[63]; + ++/* P Interlaced field picture MV predictor scaling values (Table 114) */ ++extern const uint16_t vc1_field_mvpred_scales[2][7][4]; ++/* B Interlaced field picture backward MV predictor scaling values for first field (Table 115) */ ++extern const uint16_t vc1_b_field_mvpred_scales[7][4]; + #endif /* AVCODEC_VC1DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dec.c 2012-05-14 14:08:54.333339961 +0200 +@@ -1,5 +1,6 @@ + /* + * VC-1 and WMV3 decoder ++ * Copyright (c) 2011 Mashiat Sarker Shakkhar + * Copyright (c) 2006-2007 Konstantin Shishkov + * Partly based on vc9.c (c) 2005 Anonymous, Alex Beregszaszi, Michael Niedermayer + * +@@ -23,8 +24,8 @@ + /** + * @file + * VC-1 and WMV3 decoder +- * + */ ++ + #include "internal.h" + #include "dsputil.h" + #include "avcodec.h" +@@ -45,91 +46,148 @@ + #define MB_INTRA_VLC_BITS 9 + #define DC_VLC_BITS 9 + #define AC_VLC_BITS 9 +-static const uint16_t table_mb_intra[64][2]; + + + static const uint16_t vlc_offs[] = { +- 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436, +- 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8620, +- 9262, 10202, 10756, 11310, 12228, 15078 ++ 0, 520, 552, 616, 1128, 1160, 1224, 1740, 1772, 1836, 1900, 2436, ++ 2986, 3050, 3610, 4154, 4218, 4746, 5326, 5390, 5902, 6554, 7658, 8342, ++ 9304, 9988, 10630, 11234, 12174, 13006, 13560, 14232, 14786, 15432, 16350, 17522, ++ 20372, 21818, 22330, 22394, 23166, 23678, 23742, 24820, 25332, 25396, 26460, 26980, ++ 27048, 27592, 27600, 27608, 27616, 27624, 28224, 28258, 28290, 28802, 28834, 28866, ++ 29378, 29412, 29444, 29960, 29994, 30026, 30538, 30572, 30604, 31120, 31154, 31186, ++ 31714, 31746, 31778, 32306, 32340, 32372 + }; + ++// offset tables for interlaced picture MVDATA decoding ++static const int offset_table1[9] = { 0, 1, 2, 4, 8, 16, 32, 64, 128 }; ++static const int offset_table2[9] = { 0, 1, 3, 7, 15, 31, 63, 127, 255 }; ++ + /** + * Init VC-1 specific tables and VC1Context members + * @param v The VC1Context to initialize + * @return Status + */ +-static int vc1_init_common(VC1Context *v) ++int ff_vc1_init_common(VC1Context *v) + { + static int done = 0; + int i = 0; +- static VLC_TYPE vlc_table[15078][2]; ++ static VLC_TYPE vlc_table[32372][2]; + + v->hrd_rate = v->hrd_buffer = NULL; + + /* VLC tables */ +- if(!done) +- { ++ if (!done) { + INIT_VLC_STATIC(&ff_vc1_bfraction_vlc, VC1_BFRACTION_VLC_BITS, 23, +- ff_vc1_bfraction_bits, 1, 1, +- ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS); ++ ff_vc1_bfraction_bits, 1, 1, ++ ff_vc1_bfraction_codes, 1, 1, 1 << VC1_BFRACTION_VLC_BITS); + INIT_VLC_STATIC(&ff_vc1_norm2_vlc, VC1_NORM2_VLC_BITS, 4, +- ff_vc1_norm2_bits, 1, 1, +- ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS); ++ ff_vc1_norm2_bits, 1, 1, ++ ff_vc1_norm2_codes, 1, 1, 1 << VC1_NORM2_VLC_BITS); + INIT_VLC_STATIC(&ff_vc1_norm6_vlc, VC1_NORM6_VLC_BITS, 64, +- ff_vc1_norm6_bits, 1, 1, +- ff_vc1_norm6_codes, 2, 2, 556); ++ ff_vc1_norm6_bits, 1, 1, ++ ff_vc1_norm6_codes, 2, 2, 556); + INIT_VLC_STATIC(&ff_vc1_imode_vlc, VC1_IMODE_VLC_BITS, 7, +- ff_vc1_imode_bits, 1, 1, +- ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS); +- for (i=0; i<3; i++) +- { +- ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i*3+0]]; +- ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i*3+1] - vlc_offs[i*3+0]; ++ ff_vc1_imode_bits, 1, 1, ++ ff_vc1_imode_codes, 1, 1, 1 << VC1_IMODE_VLC_BITS); ++ for (i = 0; i < 3; i++) { ++ ff_vc1_ttmb_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 0]]; ++ ff_vc1_ttmb_vlc[i].table_allocated = vlc_offs[i * 3 + 1] - vlc_offs[i * 3 + 0]; + init_vlc(&ff_vc1_ttmb_vlc[i], VC1_TTMB_VLC_BITS, 16, + ff_vc1_ttmb_bits[i], 1, 1, + ff_vc1_ttmb_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); +- ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i*3+1]]; +- ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i*3+2] - vlc_offs[i*3+1]; ++ ff_vc1_ttblk_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 1]]; ++ ff_vc1_ttblk_vlc[i].table_allocated = vlc_offs[i * 3 + 2] - vlc_offs[i * 3 + 1]; + init_vlc(&ff_vc1_ttblk_vlc[i], VC1_TTBLK_VLC_BITS, 8, + ff_vc1_ttblk_bits[i], 1, 1, + ff_vc1_ttblk_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); +- ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i*3+2]]; +- ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i*3+3] - vlc_offs[i*3+2]; ++ ff_vc1_subblkpat_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 2]]; ++ ff_vc1_subblkpat_vlc[i].table_allocated = vlc_offs[i * 3 + 3] - vlc_offs[i * 3 + 2]; + init_vlc(&ff_vc1_subblkpat_vlc[i], VC1_SUBBLKPAT_VLC_BITS, 15, + ff_vc1_subblkpat_bits[i], 1, 1, + ff_vc1_subblkpat_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + } +- for(i=0; i<4; i++) +- { +- ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i*3+9]]; +- ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i*3+10] - vlc_offs[i*3+9]; ++ for (i = 0; i < 4; i++) { ++ ff_vc1_4mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 9]]; ++ ff_vc1_4mv_block_pattern_vlc[i].table_allocated = vlc_offs[i * 3 + 10] - vlc_offs[i * 3 + 9]; + init_vlc(&ff_vc1_4mv_block_pattern_vlc[i], VC1_4MV_BLOCK_PATTERN_VLC_BITS, 16, + ff_vc1_4mv_block_pattern_bits[i], 1, 1, + ff_vc1_4mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); +- ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i*3+10]]; +- ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i*3+11] - vlc_offs[i*3+10]; ++ ff_vc1_cbpcy_p_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 10]]; ++ ff_vc1_cbpcy_p_vlc[i].table_allocated = vlc_offs[i * 3 + 11] - vlc_offs[i * 3 + 10]; + init_vlc(&ff_vc1_cbpcy_p_vlc[i], VC1_CBPCY_P_VLC_BITS, 64, + ff_vc1_cbpcy_p_bits[i], 1, 1, + ff_vc1_cbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); +- ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i*3+11]]; +- ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i*3+12] - vlc_offs[i*3+11]; ++ ff_vc1_mv_diff_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 11]]; ++ ff_vc1_mv_diff_vlc[i].table_allocated = vlc_offs[i * 3 + 12] - vlc_offs[i * 3 + 11]; + init_vlc(&ff_vc1_mv_diff_vlc[i], VC1_MV_DIFF_VLC_BITS, 73, + ff_vc1_mv_diff_bits[i], 1, 1, + ff_vc1_mv_diff_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); + } +- for(i=0; i<8; i++){ +- ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i+21]]; +- ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i+22] - vlc_offs[i+21]; ++ for (i = 0; i < 8; i++) { ++ ff_vc1_ac_coeff_table[i].table = &vlc_table[vlc_offs[i * 2 + 21]]; ++ ff_vc1_ac_coeff_table[i].table_allocated = vlc_offs[i * 2 + 22] - vlc_offs[i * 2 + 21]; + init_vlc(&ff_vc1_ac_coeff_table[i], AC_VLC_BITS, vc1_ac_sizes[i], + &vc1_ac_tables[i][0][1], 8, 4, + &vc1_ac_tables[i][0][0], 8, 4, INIT_VLC_USE_NEW_STATIC); ++ /* initialize interlaced MVDATA tables (2-Ref) */ ++ ff_vc1_2ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 2 + 22]]; ++ ff_vc1_2ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 2 + 23] - vlc_offs[i * 2 + 22]; ++ init_vlc(&ff_vc1_2ref_mvdata_vlc[i], VC1_2REF_MVDATA_VLC_BITS, 126, ++ ff_vc1_2ref_mvdata_bits[i], 1, 1, ++ ff_vc1_2ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC); ++ } ++ for (i = 0; i < 4; i++) { ++ /* initialize 4MV MBMODE VLC tables for interlaced frame P picture */ ++ ff_vc1_intfr_4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 37]]; ++ ff_vc1_intfr_4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 38] - vlc_offs[i * 3 + 37]; ++ init_vlc(&ff_vc1_intfr_4mv_mbmode_vlc[i], VC1_INTFR_4MV_MBMODE_VLC_BITS, 15, ++ ff_vc1_intfr_4mv_mbmode_bits[i], 1, 1, ++ ff_vc1_intfr_4mv_mbmode_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); ++ /* initialize NON-4MV MBMODE VLC tables for the same */ ++ ff_vc1_intfr_non4mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 38]]; ++ ff_vc1_intfr_non4mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 39] - vlc_offs[i * 3 + 38]; ++ init_vlc(&ff_vc1_intfr_non4mv_mbmode_vlc[i], VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 9, ++ ff_vc1_intfr_non4mv_mbmode_bits[i], 1, 1, ++ ff_vc1_intfr_non4mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ++ /* initialize interlaced MVDATA tables (1-Ref) */ ++ ff_vc1_1ref_mvdata_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 39]]; ++ ff_vc1_1ref_mvdata_vlc[i].table_allocated = vlc_offs[i * 3 + 40] - vlc_offs[i * 3 + 39]; ++ init_vlc(&ff_vc1_1ref_mvdata_vlc[i], VC1_1REF_MVDATA_VLC_BITS, 72, ++ ff_vc1_1ref_mvdata_bits[i], 1, 1, ++ ff_vc1_1ref_mvdata_codes[i], 4, 4, INIT_VLC_USE_NEW_STATIC); ++ } ++ for (i = 0; i < 4; i++) { ++ /* Initialize 2MV Block pattern VLC tables */ ++ ff_vc1_2mv_block_pattern_vlc[i].table = &vlc_table[vlc_offs[i + 49]]; ++ ff_vc1_2mv_block_pattern_vlc[i].table_allocated = vlc_offs[i + 50] - vlc_offs[i + 49]; ++ init_vlc(&ff_vc1_2mv_block_pattern_vlc[i], VC1_2MV_BLOCK_PATTERN_VLC_BITS, 4, ++ ff_vc1_2mv_block_pattern_bits[i], 1, 1, ++ ff_vc1_2mv_block_pattern_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ++ } ++ for (i = 0; i < 8; i++) { ++ /* Initialize interlaced CBPCY VLC tables (Table 124 - Table 131) */ ++ ff_vc1_icbpcy_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 53]]; ++ ff_vc1_icbpcy_vlc[i].table_allocated = vlc_offs[i * 3 + 54] - vlc_offs[i * 3 + 53]; ++ init_vlc(&ff_vc1_icbpcy_vlc[i], VC1_ICBPCY_VLC_BITS, 63, ++ ff_vc1_icbpcy_p_bits[i], 1, 1, ++ ff_vc1_icbpcy_p_codes[i], 2, 2, INIT_VLC_USE_NEW_STATIC); ++ /* Initialize interlaced field picture MBMODE VLC tables */ ++ ff_vc1_if_mmv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 54]]; ++ ff_vc1_if_mmv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 55] - vlc_offs[i * 3 + 54]; ++ init_vlc(&ff_vc1_if_mmv_mbmode_vlc[i], VC1_IF_MMV_MBMODE_VLC_BITS, 8, ++ ff_vc1_if_mmv_mbmode_bits[i], 1, 1, ++ ff_vc1_if_mmv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); ++ ff_vc1_if_1mv_mbmode_vlc[i].table = &vlc_table[vlc_offs[i * 3 + 55]]; ++ ff_vc1_if_1mv_mbmode_vlc[i].table_allocated = vlc_offs[i * 3 + 56] - vlc_offs[i * 3 + 55]; ++ init_vlc(&ff_vc1_if_1mv_mbmode_vlc[i], VC1_IF_1MV_MBMODE_VLC_BITS, 6, ++ ff_vc1_if_1mv_mbmode_bits[i], 1, 1, ++ ff_vc1_if_1mv_mbmode_codes[i], 1, 1, INIT_VLC_USE_NEW_STATIC); + } + done = 1; + } + + /* Other defaults */ +- v->pq = -1; ++ v->pq = -1; + v->mvrange = 0; /* 7.1.1.18, p80 */ + + return 0; +@@ -137,7 +195,7 @@ + + /***********************************************************************/ + /** +- * @defgroup vc1bitplane VC-1 Bitplane decoding ++ * @name VC-1 Bitplane decoding + * @see 8.7, p56 + * @{ + */ +@@ -160,62 +218,252 @@ + + /** @} */ //Bitplane group + +-static void vc1_loop_filter_iblk(MpegEncContext *s, int pq) ++static void vc1_put_signed_blocks_clamped(VC1Context *v) + { ++ MpegEncContext *s = &v->s; ++ int topleft_mb_pos, top_mb_pos; ++ int stride_y, fieldtx; ++ int v_dist; ++ ++ /* The put pixels loop is always one MB row behind the decoding loop, ++ * because we can only put pixels when overlap filtering is done, and ++ * for filtering of the bottom edge of a MB, we need the next MB row ++ * present as well. ++ * Within the row, the put pixels loop is also one MB col behind the ++ * decoding loop. The reason for this is again, because for filtering ++ * of the right MB edge, we need the next MB present. */ ++ if (!s->first_slice_line) { ++ if (s->mb_x) { ++ topleft_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x - 1; ++ fieldtx = v->fieldtx_plane[topleft_mb_pos]; ++ stride_y = s->linesize << fieldtx; ++ v_dist = (16 - fieldtx) >> (fieldtx == 0); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][0], ++ s->dest[0] - 16 * s->linesize - 16, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][1], ++ s->dest[0] - 16 * s->linesize - 8, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][2], ++ s->dest[0] - v_dist * s->linesize - 16, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][3], ++ s->dest[0] - v_dist * s->linesize - 8, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][4], ++ s->dest[1] - 8 * s->uvlinesize - 8, ++ s->uvlinesize); ++ s->dsp.put_signed_pixels_clamped(v->block[v->topleft_blk_idx][5], ++ s->dest[2] - 8 * s->uvlinesize - 8, ++ s->uvlinesize); ++ } ++ if (s->mb_x == s->mb_width - 1) { ++ top_mb_pos = (s->mb_y - 1) * s->mb_stride + s->mb_x; ++ fieldtx = v->fieldtx_plane[top_mb_pos]; ++ stride_y = s->linesize << fieldtx; ++ v_dist = fieldtx ? 15 : 8; ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][0], ++ s->dest[0] - 16 * s->linesize, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][1], ++ s->dest[0] - 16 * s->linesize + 8, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][2], ++ s->dest[0] - v_dist * s->linesize, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][3], ++ s->dest[0] - v_dist * s->linesize + 8, ++ stride_y); ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][4], ++ s->dest[1] - 8 * s->uvlinesize, ++ s->uvlinesize); ++ s->dsp.put_signed_pixels_clamped(v->block[v->top_blk_idx][5], ++ s->dest[2] - 8 * s->uvlinesize, ++ s->uvlinesize); ++ } ++ } ++ ++#define inc_blk_idx(idx) do { \ ++ idx++; \ ++ if (idx >= v->n_allocated_blks) \ ++ idx = 0; \ ++ } while (0) ++ ++ inc_blk_idx(v->topleft_blk_idx); ++ inc_blk_idx(v->top_blk_idx); ++ inc_blk_idx(v->left_blk_idx); ++ inc_blk_idx(v->cur_blk_idx); ++} ++ ++static void vc1_loop_filter_iblk(VC1Context *v, int pq) ++{ ++ MpegEncContext *s = &v->s; + int j; + if (!s->first_slice_line) { +- s->dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq); ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0], s->linesize, pq); + if (s->mb_x) +- s->dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize, s->linesize, pq); +- s->dsp.vc1_h_loop_filter16(s->dest[0] - 16*s->linesize+8, s->linesize, pq); +- for(j = 0; j < 2; j++){ +- s->dsp.vc1_v_loop_filter8(s->dest[j+1], s->uvlinesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq); ++ for (j = 0; j < 2; j++) { ++ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1], s->uvlinesize, pq); + if (s->mb_x) +- s->dsp.vc1_h_loop_filter8(s->dest[j+1]-8*s->uvlinesize, s->uvlinesize, pq); ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq); + } + } +- s->dsp.vc1_v_loop_filter16(s->dest[0] + 8*s->linesize, s->linesize, pq); ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] + 8 * s->linesize, s->linesize, pq); + +- if (s->mb_y == s->mb_height-1) { ++ if (s->mb_y == s->end_mb_y - 1) { + if (s->mb_x) { +- s->dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq); +- s->dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq); +- s->dsp.vc1_h_loop_filter8(s->dest[2], s->uvlinesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0], s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[1], s->uvlinesize, pq); ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[2], s->uvlinesize, pq); + } +- s->dsp.vc1_h_loop_filter16(s->dest[0] + 8, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] + 8, s->linesize, pq); + } + } + +-/** Put block onto picture +- */ +-static void vc1_put_block(VC1Context *v, DCTELEM block[6][64]) ++static void vc1_loop_filter_iblk_delayed(VC1Context *v, int pq) + { +- uint8_t *Y; +- int ys, us, vs; +- DSPContext *dsp = &v->s.dsp; ++ MpegEncContext *s = &v->s; ++ int j; + +- if(v->rangeredfrm) { +- int i, j, k; +- for(k = 0; k < 6; k++) +- for(j = 0; j < 8; j++) +- for(i = 0; i < 8; i++) +- block[k][i + j*8] = ((block[k][i + j*8] - 128) << 1) + 128; +- +- } +- ys = v->s.current_picture.linesize[0]; +- us = v->s.current_picture.linesize[1]; +- vs = v->s.current_picture.linesize[2]; +- Y = v->s.dest[0]; +- +- dsp->put_pixels_clamped(block[0], Y, ys); +- dsp->put_pixels_clamped(block[1], Y + 8, ys); +- Y += ys * 8; +- dsp->put_pixels_clamped(block[2], Y, ys); +- dsp->put_pixels_clamped(block[3], Y + 8, ys); +- +- if(!(v->s.flags & CODEC_FLAG_GRAY)) { +- dsp->put_pixels_clamped(block[4], v->s.dest[1], us); +- dsp->put_pixels_clamped(block[5], v->s.dest[2], vs); ++ /* The loopfilter runs 1 row and 1 column behind the overlap filter, which ++ * means it runs two rows/cols behind the decoding loop. */ ++ if (!s->first_slice_line) { ++ if (s->mb_x) { ++ if (s->mb_y >= s->start_mb_y + 2) { ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq); ++ ++ if (s->mb_x >= 2) ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 16, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize - 8, s->linesize, pq); ++ for (j = 0; j < 2; j++) { ++ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq); ++ if (s->mb_x >= 2) { ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize - 8, s->uvlinesize, pq); ++ } ++ } ++ } ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize - 16, s->linesize, pq); ++ } ++ ++ if (s->mb_x == s->mb_width - 1) { ++ if (s->mb_y >= s->start_mb_y + 2) { ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq); ++ ++ if (s->mb_x) ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 32 * s->linesize + 8, s->linesize, pq); ++ for (j = 0; j < 2; j++) { ++ v->vc1dsp.vc1_v_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq); ++ if (s->mb_x >= 2) { ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 16 * s->uvlinesize, s->uvlinesize, pq); ++ } ++ } ++ } ++ v->vc1dsp.vc1_v_loop_filter16(s->dest[0] - 8 * s->linesize, s->linesize, pq); ++ } ++ ++ if (s->mb_y == s->end_mb_y) { ++ if (s->mb_x) { ++ if (s->mb_x >= 2) ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 16, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize - 8, s->linesize, pq); ++ if (s->mb_x >= 2) { ++ for (j = 0; j < 2; j++) { ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize - 8, s->uvlinesize, pq); ++ } ++ } ++ } ++ ++ if (s->mb_x == s->mb_width - 1) { ++ if (s->mb_x) ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize, s->linesize, pq); ++ v->vc1dsp.vc1_h_loop_filter16(s->dest[0] - 16 * s->linesize + 8, s->linesize, pq); ++ if (s->mb_x) { ++ for (j = 0; j < 2; j++) { ++ v->vc1dsp.vc1_h_loop_filter8(s->dest[j + 1] - 8 * s->uvlinesize, s->uvlinesize, pq); ++ } ++ } ++ } ++ } ++ } ++} ++ ++static void vc1_smooth_overlap_filter_iblk(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ int mb_pos; ++ ++ if (v->condover == CONDOVER_NONE) ++ return; ++ ++ mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ ++ /* Within a MB, the horizontal overlap always runs before the vertical. ++ * To accomplish that, we run the H on left and internal borders of the ++ * currently decoded MB. Then, we wait for the next overlap iteration ++ * to do H overlap on the right edge of this MB, before moving over and ++ * running the V overlap. Therefore, the V overlap makes us trail by one ++ * MB col and the H overlap filter makes us trail by one MB row. This ++ * is reflected in the time at which we run the put_pixels loop. */ ++ if (v->condover == CONDOVER_ALL || v->pq >= 9 || v->over_flags_plane[mb_pos]) { ++ if (s->mb_x && (v->condover == CONDOVER_ALL || v->pq >= 9 || ++ v->over_flags_plane[mb_pos - 1])) { ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][1], ++ v->block[v->cur_blk_idx][0]); ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][3], ++ v->block[v->cur_blk_idx][2]); ++ if (!(s->flags & CODEC_FLAG_GRAY)) { ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][4], ++ v->block[v->cur_blk_idx][4]); ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->left_blk_idx][5], ++ v->block[v->cur_blk_idx][5]); ++ } ++ } ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][0], ++ v->block[v->cur_blk_idx][1]); ++ v->vc1dsp.vc1_h_s_overlap(v->block[v->cur_blk_idx][2], ++ v->block[v->cur_blk_idx][3]); ++ ++ if (s->mb_x == s->mb_width - 1) { ++ if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 || ++ v->over_flags_plane[mb_pos - s->mb_stride])) { ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][2], ++ v->block[v->cur_blk_idx][0]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][3], ++ v->block[v->cur_blk_idx][1]); ++ if (!(s->flags & CODEC_FLAG_GRAY)) { ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][4], ++ v->block[v->cur_blk_idx][4]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->top_blk_idx][5], ++ v->block[v->cur_blk_idx][5]); ++ } ++ } ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][0], ++ v->block[v->cur_blk_idx][2]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->cur_blk_idx][1], ++ v->block[v->cur_blk_idx][3]); ++ } ++ } ++ if (s->mb_x && (v->condover == CONDOVER_ALL || v->over_flags_plane[mb_pos - 1])) { ++ if (!s->first_slice_line && (v->condover == CONDOVER_ALL || v->pq >= 9 || ++ v->over_flags_plane[mb_pos - s->mb_stride - 1])) { ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][2], ++ v->block[v->left_blk_idx][0]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][3], ++ v->block[v->left_blk_idx][1]); ++ if (!(s->flags & CODEC_FLAG_GRAY)) { ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][4], ++ v->block[v->left_blk_idx][4]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->topleft_blk_idx][5], ++ v->block[v->left_blk_idx][5]); ++ } ++ } ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][0], ++ v->block[v->left_blk_idx][2]); ++ v->vc1dsp.vc1_v_s_overlap(v->block[v->left_blk_idx][1], ++ v->block[v->left_blk_idx][3]); + } + } + +@@ -225,372 +473,687 @@ + static void vc1_mc_1mv(VC1Context *v, int dir) + { + MpegEncContext *s = &v->s; +- DSPContext *dsp = &v->s.dsp; ++ DSPContext *dsp = &v->s.dsp; + uint8_t *srcY, *srcU, *srcV; + int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; ++ int off, off_uv; ++ int v_edge_pos = s->v_edge_pos >> v->field_mode; + +- if(!v->s.last_picture.data[0])return; ++ if ((!v->field_mode || ++ (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) && ++ !v->s.last_picture.f.data[0]) ++ return; + + mx = s->mv[dir][0][0]; + my = s->mv[dir][0][1]; + + // store motion vectors for further use in B frames +- if(s->pict_type == FF_P_TYPE) { +- s->current_picture.motion_val[1][s->block_index[0]][0] = mx; +- s->current_picture.motion_val[1][s->block_index[0]][1] = my; ++ if (s->pict_type == AV_PICTURE_TYPE_P) { ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = mx; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = my; + } ++ + uvmx = (mx + ((mx & 3) == 3)) >> 1; + uvmy = (my + ((my & 3) == 3)) >> 1; +- if(v->fastuvmc) { +- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1)); +- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1)); +- } +- if(!dir) { +- srcY = s->last_picture.data[0]; +- srcU = s->last_picture.data[1]; +- srcV = s->last_picture.data[2]; +- } else { +- srcY = s->next_picture.data[0]; +- srcU = s->next_picture.data[1]; +- srcV = s->next_picture.data[2]; ++ v->luma_mv[s->mb_x][0] = uvmx; ++ v->luma_mv[s->mb_x][1] = uvmy; ++ ++ if (v->field_mode && ++ v->cur_field_type != v->ref_field_type[dir]) { ++ my = my - 2 + 4 * v->cur_field_type; ++ uvmy = uvmy - 2 + 4 * v->cur_field_type; ++ } ++ ++ // fastuvmc shall be ignored for interlaced frame picture ++ if (v->fastuvmc && (v->fcm != ILACE_FRAME)) { ++ uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1)); ++ uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1)); ++ } ++ if (v->field_mode) { // interlaced field picture ++ if (!dir) { ++ if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field) { ++ srcY = s->current_picture.f.data[0]; ++ srcU = s->current_picture.f.data[1]; ++ srcV = s->current_picture.f.data[2]; ++ } else { ++ srcY = s->last_picture.f.data[0]; ++ srcU = s->last_picture.f.data[1]; ++ srcV = s->last_picture.f.data[2]; ++ } ++ } else { ++ srcY = s->next_picture.f.data[0]; ++ srcU = s->next_picture.f.data[1]; ++ srcV = s->next_picture.f.data[2]; ++ } ++ } else { ++ if (!dir) { ++ srcY = s->last_picture.f.data[0]; ++ srcU = s->last_picture.f.data[1]; ++ srcV = s->last_picture.f.data[2]; ++ } else { ++ srcY = s->next_picture.f.data[0]; ++ srcU = s->next_picture.f.data[1]; ++ srcV = s->next_picture.f.data[2]; ++ } + } + +- src_x = s->mb_x * 16 + (mx >> 2); +- src_y = s->mb_y * 16 + (my >> 2); +- uvsrc_x = s->mb_x * 8 + (uvmx >> 2); +- uvsrc_y = s->mb_y * 8 + (uvmy >> 2); ++ src_x = s->mb_x * 16 + (mx >> 2); ++ src_y = s->mb_y * 16 + (my >> 2); ++ uvsrc_x = s->mb_x * 8 + (uvmx >> 2); ++ uvsrc_y = s->mb_y * 8 + (uvmy >> 2); + +- if(v->profile != PROFILE_ADVANCED){ ++ if (v->profile != PROFILE_ADVANCED) { + src_x = av_clip( src_x, -16, s->mb_width * 16); + src_y = av_clip( src_y, -16, s->mb_height * 16); + uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); + uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); +- }else{ ++ } else { + src_x = av_clip( src_x, -17, s->avctx->coded_width); + src_y = av_clip( src_y, -18, s->avctx->coded_height + 1); + uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); + uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); + } + +- srcY += src_y * s->linesize + src_x; ++ srcY += src_y * s->linesize + src_x; + srcU += uvsrc_y * s->uvlinesize + uvsrc_x; + srcV += uvsrc_y * s->uvlinesize + uvsrc_x; + ++ if (v->field_mode && v->ref_field_type[dir]) { ++ srcY += s->current_picture_ptr->f.linesize[0]; ++ srcU += s->current_picture_ptr->f.linesize[1]; ++ srcV += s->current_picture_ptr->f.linesize[2]; ++ } ++ + /* for grayscale we should not try to read from unknown area */ +- if(s->flags & CODEC_FLAG_GRAY) { ++ if (s->flags & CODEC_FLAG_GRAY) { + srcU = s->edge_emu_buffer + 18 * s->linesize; + srcV = s->edge_emu_buffer + 18 * s->linesize; + } + +- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) +- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3 +- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){ +- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize; ++ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) ++ || s->h_edge_pos < 22 || v_edge_pos < 22 ++ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel * 3 ++ || (unsigned)(src_y - s->mspel) > v_edge_pos - (my&3) - 16 - s->mspel * 3) { ++ uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; + + srcY -= s->mspel * (1 + s->linesize); +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2, +- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, ++ 17 + s->mspel * 2, 17 + s->mspel * 2, ++ src_x - s->mspel, src_y - s->mspel, ++ s->h_edge_pos, v_edge_pos); + srcY = s->edge_emu_buffer; +- s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); +- s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1, ++ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1, ++ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); + srcU = uvbuf; + srcV = uvbuf + 16; + /* if we deal with range reduction we need to scale source blocks */ +- if(v->rangeredfrm) { ++ if (v->rangeredfrm) { + int i, j; + uint8_t *src, *src2; + + src = srcY; +- for(j = 0; j < 17 + s->mspel*2; j++) { +- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128; ++ for (j = 0; j < 17 + s->mspel * 2; j++) { ++ for (i = 0; i < 17 + s->mspel * 2; i++) ++ src[i] = ((src[i] - 128) >> 1) + 128; + src += s->linesize; + } +- src = srcU; src2 = srcV; +- for(j = 0; j < 9; j++) { +- for(i = 0; i < 9; i++) { +- src[i] = ((src[i] - 128) >> 1) + 128; ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 9; j++) { ++ for (i = 0; i < 9; i++) { ++ src[i] = ((src[i] - 128) >> 1) + 128; + src2[i] = ((src2[i] - 128) >> 1) + 128; + } +- src += s->uvlinesize; ++ src += s->uvlinesize; + src2 += s->uvlinesize; + } + } + /* if we deal with intensity compensation we need to scale source blocks */ +- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + int i, j; + uint8_t *src, *src2; + + src = srcY; +- for(j = 0; j < 17 + s->mspel*2; j++) { +- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = v->luty[src[i]]; ++ for (j = 0; j < 17 + s->mspel * 2; j++) { ++ for (i = 0; i < 17 + s->mspel * 2; i++) ++ src[i] = v->luty[src[i]]; + src += s->linesize; + } +- src = srcU; src2 = srcV; +- for(j = 0; j < 9; j++) { +- for(i = 0; i < 9; i++) { +- src[i] = v->lutuv[src[i]]; ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 9; j++) { ++ for (i = 0; i < 9; i++) { ++ src[i] = v->lutuv[src[i]]; + src2[i] = v->lutuv[src2[i]]; + } +- src += s->uvlinesize; ++ src += s->uvlinesize; + src2 += s->uvlinesize; + } + } + srcY += s->mspel * (1 + s->linesize); + } + +- if(s->mspel) { ++ if (v->field_mode && v->second_field) { ++ off = s->current_picture_ptr->f.linesize[0]; ++ off_uv = s->current_picture_ptr->f.linesize[1]; ++ } else { ++ off = 0; ++ off_uv = 0; ++ } ++ if (s->mspel) { + dxy = ((my & 3) << 2) | (mx & 3); +- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd); +- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd); ++ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd); ++ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd); + srcY += s->linesize * 8; +- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd); +- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd); ++ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd); ++ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd); + } else { // hpel mc - always used for luma + dxy = (my & 2) | ((mx & 2) >> 1); +- +- if(!v->rnd) +- dsp->put_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16); ++ if (!v->rnd) ++ dsp->put_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16); + else +- dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16); ++ dsp->put_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16); + } + +- if(s->flags & CODEC_FLAG_GRAY) return; ++ if (s->flags & CODEC_FLAG_GRAY) return; + /* Chroma MC always uses qpel bilinear */ +- uvmx = (uvmx&3)<<1; +- uvmy = (uvmy&3)<<1; +- if(!v->rnd){ +- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); +- }else{ +- dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); ++ uvmx = (uvmx & 3) << 1; ++ uvmy = (uvmy & 3) << 1; ++ if (!v->rnd) { ++ dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); ++ } else { ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); ++ } ++} ++ ++static inline int median4(int a, int b, int c, int d) ++{ ++ if (a < b) { ++ if (c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2; ++ else return (FFMIN(b, c) + FFMAX(a, d)) / 2; ++ } else { ++ if (c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2; ++ else return (FFMIN(a, c) + FFMAX(b, d)) / 2; + } + } + + /** Do motion compensation for 4-MV macroblock - luminance block + */ +-static void vc1_mc_4mv_luma(VC1Context *v, int n) ++static void vc1_mc_4mv_luma(VC1Context *v, int n, int dir) + { + MpegEncContext *s = &v->s; + DSPContext *dsp = &v->s.dsp; + uint8_t *srcY; + int dxy, mx, my, src_x, src_y; + int off; ++ int fieldmv = (v->fcm == ILACE_FRAME) ? v->blk_mv_type[s->block_index[n]] : 0; ++ int v_edge_pos = s->v_edge_pos >> v->field_mode; + +- if(!v->s.last_picture.data[0])return; +- mx = s->mv[0][n][0]; +- my = s->mv[0][n][1]; +- srcY = s->last_picture.data[0]; ++ if ((!v->field_mode || ++ (v->ref_field_type[dir] == 1 && v->cur_field_type == 1)) && ++ !v->s.last_picture.f.data[0]) ++ return; + +- off = s->linesize * 4 * (n&2) + (n&1) * 8; ++ mx = s->mv[dir][n][0]; ++ my = s->mv[dir][n][1]; + +- src_x = s->mb_x * 16 + (n&1) * 8 + (mx >> 2); +- src_y = s->mb_y * 16 + (n&2) * 4 + (my >> 2); ++ if (!dir) { ++ if (v->field_mode) { ++ if ((v->cur_field_type != v->ref_field_type[dir]) && v->second_field) ++ srcY = s->current_picture.f.data[0]; ++ else ++ srcY = s->last_picture.f.data[0]; ++ } else ++ srcY = s->last_picture.f.data[0]; ++ } else ++ srcY = s->next_picture.f.data[0]; + +- if(v->profile != PROFILE_ADVANCED){ +- src_x = av_clip( src_x, -16, s->mb_width * 16); +- src_y = av_clip( src_y, -16, s->mb_height * 16); +- }else{ +- src_x = av_clip( src_x, -17, s->avctx->coded_width); +- src_y = av_clip( src_y, -18, s->avctx->coded_height + 1); ++ if (v->field_mode) { ++ if (v->cur_field_type != v->ref_field_type[dir]) ++ my = my - 2 + 4 * v->cur_field_type; ++ } ++ ++ if (s->pict_type == AV_PICTURE_TYPE_P && n == 3 && v->field_mode) { ++ int same_count = 0, opp_count = 0, k; ++ int chosen_mv[2][4][2], f; ++ int tx, ty; ++ for (k = 0; k < 4; k++) { ++ f = v->mv_f[0][s->block_index[k] + v->blocks_off]; ++ chosen_mv[f][f ? opp_count : same_count][0] = s->mv[0][k][0]; ++ chosen_mv[f][f ? opp_count : same_count][1] = s->mv[0][k][1]; ++ opp_count += f; ++ same_count += 1 - f; ++ } ++ f = opp_count > same_count; ++ switch (f ? opp_count : same_count) { ++ case 4: ++ tx = median4(chosen_mv[f][0][0], chosen_mv[f][1][0], ++ chosen_mv[f][2][0], chosen_mv[f][3][0]); ++ ty = median4(chosen_mv[f][0][1], chosen_mv[f][1][1], ++ chosen_mv[f][2][1], chosen_mv[f][3][1]); ++ break; ++ case 3: ++ tx = mid_pred(chosen_mv[f][0][0], chosen_mv[f][1][0], chosen_mv[f][2][0]); ++ ty = mid_pred(chosen_mv[f][0][1], chosen_mv[f][1][1], chosen_mv[f][2][1]); ++ break; ++ case 2: ++ tx = (chosen_mv[f][0][0] + chosen_mv[f][1][0]) / 2; ++ ty = (chosen_mv[f][0][1] + chosen_mv[f][1][1]) / 2; ++ break; ++ } ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty; ++ for (k = 0; k < 4; k++) ++ v->mv_f[1][s->block_index[k] + v->blocks_off] = f; ++ } ++ ++ if (v->fcm == ILACE_FRAME) { // not sure if needed for other types of picture ++ int qx, qy; ++ int width = s->avctx->coded_width; ++ int height = s->avctx->coded_height >> 1; ++ qx = (s->mb_x * 16) + (mx >> 2); ++ qy = (s->mb_y * 8) + (my >> 3); ++ ++ if (qx < -17) ++ mx -= 4 * (qx + 17); ++ else if (qx > width) ++ mx -= 4 * (qx - width); ++ if (qy < -18) ++ my -= 8 * (qy + 18); ++ else if (qy > height + 1) ++ my -= 8 * (qy - height - 1); ++ } ++ ++ if ((v->fcm == ILACE_FRAME) && fieldmv) ++ off = ((n > 1) ? s->linesize : 0) + (n & 1) * 8; ++ else ++ off = s->linesize * 4 * (n & 2) + (n & 1) * 8; ++ if (v->field_mode && v->second_field) ++ off += s->current_picture_ptr->f.linesize[0]; ++ ++ src_x = s->mb_x * 16 + (n & 1) * 8 + (mx >> 2); ++ if (!fieldmv) ++ src_y = s->mb_y * 16 + (n & 2) * 4 + (my >> 2); ++ else ++ src_y = s->mb_y * 16 + ((n > 1) ? 1 : 0) + (my >> 2); ++ ++ if (v->profile != PROFILE_ADVANCED) { ++ src_x = av_clip(src_x, -16, s->mb_width * 16); ++ src_y = av_clip(src_y, -16, s->mb_height * 16); ++ } else { ++ src_x = av_clip(src_x, -17, s->avctx->coded_width); ++ if (v->fcm == ILACE_FRAME) { ++ if (src_y & 1) ++ src_y = av_clip(src_y, -17, s->avctx->coded_height + 1); ++ else ++ src_y = av_clip(src_y, -18, s->avctx->coded_height); ++ } else { ++ src_y = av_clip(src_y, -18, s->avctx->coded_height + 1); ++ } + } + + srcY += src_y * s->linesize + src_x; ++ if (v->field_mode && v->ref_field_type[dir]) ++ srcY += s->current_picture_ptr->f.linesize[0]; + +- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) +- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 8 - s->mspel*2 +- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 8 - s->mspel*2){ +- srcY -= s->mspel * (1 + s->linesize); +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 9+s->mspel*2, 9+s->mspel*2, +- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos); ++ if (fieldmv && !(src_y & 1)) ++ v_edge_pos--; ++ if (fieldmv && (src_y & 1) && src_y < 4) ++ src_y--; ++ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) ++ || s->h_edge_pos < 13 || v_edge_pos < 23 ++ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 8 - s->mspel * 2 ++ || (unsigned)(src_y - (s->mspel << fieldmv)) > v_edge_pos - (my & 3) - ((8 + s->mspel * 2) << fieldmv)) { ++ srcY -= s->mspel * (1 + (s->linesize << fieldmv)); ++ /* check emulate edge stride and offset */ ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, ++ 9 + s->mspel * 2, (9 + s->mspel * 2) << fieldmv, ++ src_x - s->mspel, src_y - (s->mspel << fieldmv), ++ s->h_edge_pos, v_edge_pos); + srcY = s->edge_emu_buffer; + /* if we deal with range reduction we need to scale source blocks */ +- if(v->rangeredfrm) { ++ if (v->rangeredfrm) { + int i, j; + uint8_t *src; + + src = srcY; +- for(j = 0; j < 9 + s->mspel*2; j++) { +- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128; +- src += s->linesize; ++ for (j = 0; j < 9 + s->mspel * 2; j++) { ++ for (i = 0; i < 9 + s->mspel * 2; i++) ++ src[i] = ((src[i] - 128) >> 1) + 128; ++ src += s->linesize << fieldmv; + } + } + /* if we deal with intensity compensation we need to scale source blocks */ +- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + int i, j; + uint8_t *src; + + src = srcY; +- for(j = 0; j < 9 + s->mspel*2; j++) { +- for(i = 0; i < 9 + s->mspel*2; i++) src[i] = v->luty[src[i]]; +- src += s->linesize; ++ for (j = 0; j < 9 + s->mspel * 2; j++) { ++ for (i = 0; i < 9 + s->mspel * 2; i++) ++ src[i] = v->luty[src[i]]; ++ src += s->linesize << fieldmv; + } + } +- srcY += s->mspel * (1 + s->linesize); ++ srcY += s->mspel * (1 + (s->linesize << fieldmv)); + } + +- if(s->mspel) { ++ if (s->mspel) { + dxy = ((my & 3) << 2) | (mx & 3); +- dsp->put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize, v->rnd); ++ v->vc1dsp.put_vc1_mspel_pixels_tab[dxy](s->dest[0] + off, srcY, s->linesize << fieldmv, v->rnd); + } else { // hpel mc - always used for luma + dxy = (my & 2) | ((mx & 2) >> 1); +- if(!v->rnd) ++ if (!v->rnd) + dsp->put_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8); + else + dsp->put_no_rnd_pixels_tab[1][dxy](s->dest[0] + off, srcY, s->linesize, 8); + } + } + +-static inline int median4(int a, int b, int c, int d) ++static av_always_inline int get_chroma_mv(int *mvx, int *mvy, int *a, int flag, int *tx, int *ty) + { +- if(a < b) { +- if(c < d) return (FFMIN(b, d) + FFMAX(a, c)) / 2; +- else return (FFMIN(b, c) + FFMAX(a, d)) / 2; ++ int idx, i; ++ static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; ++ ++ idx = ((a[3] != flag) << 3) ++ | ((a[2] != flag) << 2) ++ | ((a[1] != flag) << 1) ++ | (a[0] != flag); ++ if (!idx) { ++ *tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]); ++ *ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]); ++ return 4; ++ } else if (count[idx] == 1) { ++ switch (idx) { ++ case 0x1: ++ *tx = mid_pred(mvx[1], mvx[2], mvx[3]); ++ *ty = mid_pred(mvy[1], mvy[2], mvy[3]); ++ return 3; ++ case 0x2: ++ *tx = mid_pred(mvx[0], mvx[2], mvx[3]); ++ *ty = mid_pred(mvy[0], mvy[2], mvy[3]); ++ return 3; ++ case 0x4: ++ *tx = mid_pred(mvx[0], mvx[1], mvx[3]); ++ *ty = mid_pred(mvy[0], mvy[1], mvy[3]); ++ return 3; ++ case 0x8: ++ *tx = mid_pred(mvx[0], mvx[1], mvx[2]); ++ *ty = mid_pred(mvy[0], mvy[1], mvy[2]); ++ return 3; ++ } ++ } else if (count[idx] == 2) { ++ int t1 = 0, t2 = 0; ++ for (i = 0; i < 3; i++) ++ if (!a[i]) { ++ t1 = i; ++ break; ++ } ++ for (i = t1 + 1; i < 4; i++) ++ if (!a[i]) { ++ t2 = i; ++ break; ++ } ++ *tx = (mvx[t1] + mvx[t2]) / 2; ++ *ty = (mvy[t1] + mvy[t2]) / 2; ++ return 2; + } else { +- if(c < d) return (FFMIN(a, d) + FFMAX(b, c)) / 2; +- else return (FFMIN(a, c) + FFMAX(b, d)) / 2; ++ return 0; + } ++ return -1; + } + +- + /** Do motion compensation for 4-MV macroblock - both chroma blocks + */ +-static void vc1_mc_4mv_chroma(VC1Context *v) ++static void vc1_mc_4mv_chroma(VC1Context *v, int dir) + { + MpegEncContext *s = &v->s; +- DSPContext *dsp = &v->s.dsp; ++ DSPContext *dsp = &v->s.dsp; + uint8_t *srcU, *srcV; + int uvmx, uvmy, uvsrc_x, uvsrc_y; +- int i, idx, tx = 0, ty = 0; +- int mvx[4], mvy[4], intra[4]; +- static const int count[16] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4}; ++ int k, tx = 0, ty = 0; ++ int mvx[4], mvy[4], intra[4], mv_f[4]; ++ int valid_count; ++ int chroma_ref_type = v->cur_field_type, off = 0; ++ int v_edge_pos = s->v_edge_pos >> v->field_mode; + +- if(!v->s.last_picture.data[0])return; +- if(s->flags & CODEC_FLAG_GRAY) return; ++ if (!v->field_mode && !v->s.last_picture.f.data[0]) ++ return; ++ if (s->flags & CODEC_FLAG_GRAY) ++ return; + +- for(i = 0; i < 4; i++) { +- mvx[i] = s->mv[0][i][0]; +- mvy[i] = s->mv[0][i][1]; +- intra[i] = v->mb_type[0][s->block_index[i]]; ++ for (k = 0; k < 4; k++) { ++ mvx[k] = s->mv[dir][k][0]; ++ mvy[k] = s->mv[dir][k][1]; ++ intra[k] = v->mb_type[0][s->block_index[k]]; ++ if (v->field_mode) ++ mv_f[k] = v->mv_f[dir][s->block_index[k] + v->blocks_off]; + } + + /* calculate chroma MV vector from four luma MVs */ +- idx = (intra[3] << 3) | (intra[2] << 2) | (intra[1] << 1) | intra[0]; +- if(!idx) { // all blocks are inter +- tx = median4(mvx[0], mvx[1], mvx[2], mvx[3]); +- ty = median4(mvy[0], mvy[1], mvy[2], mvy[3]); +- } else if(count[idx] == 1) { // 3 inter blocks +- switch(idx) { +- case 0x1: +- tx = mid_pred(mvx[1], mvx[2], mvx[3]); +- ty = mid_pred(mvy[1], mvy[2], mvy[3]); +- break; +- case 0x2: +- tx = mid_pred(mvx[0], mvx[2], mvx[3]); +- ty = mid_pred(mvy[0], mvy[2], mvy[3]); +- break; +- case 0x4: +- tx = mid_pred(mvx[0], mvx[1], mvx[3]); +- ty = mid_pred(mvy[0], mvy[1], mvy[3]); +- break; +- case 0x8: +- tx = mid_pred(mvx[0], mvx[1], mvx[2]); +- ty = mid_pred(mvy[0], mvy[1], mvy[2]); +- break; ++ if (!v->field_mode || (v->field_mode && !v->numref)) { ++ valid_count = get_chroma_mv(mvx, mvy, intra, 0, &tx, &ty); ++ if (!valid_count) { ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0; ++ v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0; ++ return; //no need to do MC for intra blocks + } +- } else if(count[idx] == 2) { +- int t1 = 0, t2 = 0; +- for(i=0; i<3;i++) if(!intra[i]) {t1 = i; break;} +- for(i= t1+1; i<4; i++)if(!intra[i]) {t2 = i; break;} +- tx = (mvx[t1] + mvx[t2]) / 2; +- ty = (mvy[t1] + mvy[t2]) / 2; +- } else { +- s->current_picture.motion_val[1][s->block_index[0]][0] = 0; +- s->current_picture.motion_val[1][s->block_index[0]][1] = 0; +- return; //no need to do MC for inter blocks +- } +- +- s->current_picture.motion_val[1][s->block_index[0]][0] = tx; +- s->current_picture.motion_val[1][s->block_index[0]][1] = ty; +- uvmx = (tx + ((tx&3) == 3)) >> 1; +- uvmy = (ty + ((ty&3) == 3)) >> 1; +- if(v->fastuvmc) { +- uvmx = uvmx + ((uvmx<0)?(uvmx&1):-(uvmx&1)); +- uvmy = uvmy + ((uvmy<0)?(uvmy&1):-(uvmy&1)); ++ } else { ++ int dominant = 0; ++ if (mv_f[0] + mv_f[1] + mv_f[2] + mv_f[3] > 2) ++ dominant = 1; ++ valid_count = get_chroma_mv(mvx, mvy, mv_f, dominant, &tx, &ty); ++ if (dominant) ++ chroma_ref_type = !v->cur_field_type; + } ++ if (v->field_mode && chroma_ref_type == 1 && v->cur_field_type == 1 && !v->s.last_picture.f.data[0]) ++ return; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = tx; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = ty; ++ uvmx = (tx + ((tx & 3) == 3)) >> 1; ++ uvmy = (ty + ((ty & 3) == 3)) >> 1; ++ ++ v->luma_mv[s->mb_x][0] = uvmx; ++ v->luma_mv[s->mb_x][1] = uvmy; ++ ++ if (v->fastuvmc) { ++ uvmx = uvmx + ((uvmx < 0) ? (uvmx & 1) : -(uvmx & 1)); ++ uvmy = uvmy + ((uvmy < 0) ? (uvmy & 1) : -(uvmy & 1)); ++ } ++ // Field conversion bias ++ if (v->cur_field_type != chroma_ref_type) ++ uvmy += 2 - 4 * chroma_ref_type; + + uvsrc_x = s->mb_x * 8 + (uvmx >> 2); + uvsrc_y = s->mb_y * 8 + (uvmy >> 2); + +- if(v->profile != PROFILE_ADVANCED){ +- uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); +- uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); +- }else{ +- uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); +- uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); ++ if (v->profile != PROFILE_ADVANCED) { ++ uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); ++ uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); ++ } else { ++ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); ++ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); + } + +- srcU = s->last_picture.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; +- srcV = s->last_picture.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; +- if(v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) +- || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9 +- || (unsigned)uvsrc_y > (s->v_edge_pos >> 1) - 9){ +- s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); +- s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ++ if (!dir) { ++ if (v->field_mode) { ++ if ((v->cur_field_type != chroma_ref_type) && v->cur_field_type) { ++ srcU = s->current_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ srcV = s->current_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ } else { ++ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ } ++ } else { ++ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ } ++ } else { ++ srcU = s->next_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ srcV = s->next_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ } ++ ++ if (v->field_mode) { ++ if (chroma_ref_type) { ++ srcU += s->current_picture_ptr->f.linesize[1]; ++ srcV += s->current_picture_ptr->f.linesize[2]; ++ } ++ off = v->second_field ? s->current_picture_ptr->f.linesize[1] : 0; ++ } ++ ++ if (v->rangeredfrm || (v->mv_mode == MV_PMODE_INTENSITY_COMP) ++ || s->h_edge_pos < 18 || v_edge_pos < 18 ++ || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 9 ++ || (unsigned)uvsrc_y > (v_edge_pos >> 1) - 9) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer , srcU, s->uvlinesize, ++ 8 + 1, 8 + 1, uvsrc_x, uvsrc_y, ++ s->h_edge_pos >> 1, v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, ++ 8 + 1, 8 + 1, uvsrc_x, uvsrc_y, ++ s->h_edge_pos >> 1, v_edge_pos >> 1); + srcU = s->edge_emu_buffer; + srcV = s->edge_emu_buffer + 16; + + /* if we deal with range reduction we need to scale source blocks */ +- if(v->rangeredfrm) { ++ if (v->rangeredfrm) { + int i, j; + uint8_t *src, *src2; + +- src = srcU; src2 = srcV; +- for(j = 0; j < 9; j++) { +- for(i = 0; i < 9; i++) { +- src[i] = ((src[i] - 128) >> 1) + 128; ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 9; j++) { ++ for (i = 0; i < 9; i++) { ++ src[i] = ((src[i] - 128) >> 1) + 128; + src2[i] = ((src2[i] - 128) >> 1) + 128; + } +- src += s->uvlinesize; ++ src += s->uvlinesize; + src2 += s->uvlinesize; + } + } + /* if we deal with intensity compensation we need to scale source blocks */ +- if(v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { + int i, j; + uint8_t *src, *src2; + +- src = srcU; src2 = srcV; +- for(j = 0; j < 9; j++) { +- for(i = 0; i < 9; i++) { +- src[i] = v->lutuv[src[i]]; ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 9; j++) { ++ for (i = 0; i < 9; i++) { ++ src[i] = v->lutuv[src[i]]; + src2[i] = v->lutuv[src2[i]]; + } +- src += s->uvlinesize; ++ src += s->uvlinesize; + src2 += s->uvlinesize; + } + } + } + + /* Chroma MC always uses qpel bilinear */ +- uvmx = (uvmx&3)<<1; +- uvmy = (uvmy&3)<<1; +- if(!v->rnd){ +- dsp->put_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->put_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); +- }else{ +- dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); ++ uvmx = (uvmx & 3) << 1; ++ uvmy = (uvmy & 3) << 1; ++ if (!v->rnd) { ++ dsp->put_h264_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ dsp->put_h264_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy); ++ } else { ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off, srcV, s->uvlinesize, 8, uvmx, uvmy); ++ } ++} ++ ++/** Do motion compensation for 4-MV field chroma macroblock (both U and V) ++ */ ++static void vc1_mc_4mv_chroma4(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ DSPContext *dsp = &v->s.dsp; ++ uint8_t *srcU, *srcV; ++ int uvsrc_x, uvsrc_y; ++ int uvmx_field[4], uvmy_field[4]; ++ int i, off, tx, ty; ++ int fieldmv = v->blk_mv_type[s->block_index[0]]; ++ static const int s_rndtblfield[16] = { 0, 0, 1, 2, 4, 4, 5, 6, 2, 2, 3, 8, 6, 6, 7, 12 }; ++ int v_dist = fieldmv ? 1 : 4; // vertical offset for lower sub-blocks ++ int v_edge_pos = s->v_edge_pos >> 1; ++ ++ if (!v->s.last_picture.f.data[0]) ++ return; ++ if (s->flags & CODEC_FLAG_GRAY) ++ return; ++ ++ for (i = 0; i < 4; i++) { ++ tx = s->mv[0][i][0]; ++ uvmx_field[i] = (tx + ((tx & 3) == 3)) >> 1; ++ ty = s->mv[0][i][1]; ++ if (fieldmv) ++ uvmy_field[i] = (ty >> 4) * 8 + s_rndtblfield[ty & 0xF]; ++ else ++ uvmy_field[i] = (ty + ((ty & 3) == 3)) >> 1; ++ } ++ ++ for (i = 0; i < 4; i++) { ++ off = (i & 1) * 4 + ((i & 2) ? v_dist * s->uvlinesize : 0); ++ uvsrc_x = s->mb_x * 8 + (i & 1) * 4 + (uvmx_field[i] >> 2); ++ uvsrc_y = s->mb_y * 8 + ((i & 2) ? v_dist : 0) + (uvmy_field[i] >> 2); ++ // FIXME: implement proper pull-back (see vc1cropmv.c, vc1CROPMV_ChromaPullBack()) ++ uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); ++ uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); ++ srcU = s->last_picture.f.data[1] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ srcV = s->last_picture.f.data[2] + uvsrc_y * s->uvlinesize + uvsrc_x; ++ uvmx_field[i] = (uvmx_field[i] & 3) << 1; ++ uvmy_field[i] = (uvmy_field[i] & 3) << 1; ++ ++ if (fieldmv && !(uvsrc_y & 1)) ++ v_edge_pos--; ++ if (fieldmv && (uvsrc_y & 1) && uvsrc_y < 2) ++ uvsrc_y--; ++ if ((v->mv_mode == MV_PMODE_INTENSITY_COMP) ++ || s->h_edge_pos < 10 || v_edge_pos < (5 << fieldmv) ++ || (unsigned)uvsrc_x > (s->h_edge_pos >> 1) - 5 ++ || (unsigned)uvsrc_y > v_edge_pos - (5 << fieldmv)) { ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcU, s->uvlinesize, ++ 5, (5 << fieldmv), uvsrc_x, uvsrc_y, ++ s->h_edge_pos >> 1, v_edge_pos); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer + 16, srcV, s->uvlinesize, ++ 5, (5 << fieldmv), uvsrc_x, uvsrc_y, ++ s->h_edge_pos >> 1, v_edge_pos); ++ srcU = s->edge_emu_buffer; ++ srcV = s->edge_emu_buffer + 16; ++ ++ /* if we deal with intensity compensation we need to scale source blocks */ ++ if (v->mv_mode == MV_PMODE_INTENSITY_COMP) { ++ int i, j; ++ uint8_t *src, *src2; ++ ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 5; j++) { ++ for (i = 0; i < 5; i++) { ++ src[i] = v->lutuv[src[i]]; ++ src2[i] = v->lutuv[src2[i]]; ++ } ++ src += s->uvlinesize << 1; ++ src2 += s->uvlinesize << 1; ++ } ++ } ++ } ++ if (!v->rnd) { ++ dsp->put_h264_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); ++ dsp->put_h264_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); ++ } else { ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[1] + off, srcU, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); ++ v->vc1dsp.put_no_rnd_vc1_chroma_pixels_tab[1](s->dest[2] + off, srcV, s->uvlinesize << fieldmv, 4, uvmx_field[i], uvmy_field[i]); ++ } + } + } + + /***********************************************************************/ + /** +- * @defgroup vc1block VC-1 Block-level functions ++ * @name VC-1 Block-level functions + * @see 7.1.4, p91 and 8.1.1.7, p(1)04 + * @{ + */ +@@ -600,37 +1163,34 @@ + * @brief Get macroblock-level quantizer scale + */ + #define GET_MQUANT() \ +- if (v->dquantfrm) \ +- { \ +- int edges = 0; \ +- if (v->dqprofile == DQPROFILE_ALL_MBS) \ +- { \ +- if (v->dqbilevel) \ +- { \ +- mquant = (get_bits1(gb)) ? v->altpq : v->pq; \ +- } \ +- else \ +- { \ +- mqdiff = get_bits(gb, 3); \ +- if (mqdiff != 7) mquant = v->pq + mqdiff; \ +- else mquant = get_bits(gb, 5); \ +- } \ +- } \ +- if(v->dqprofile == DQPROFILE_SINGLE_EDGE) \ +- edges = 1 << v->dqsbedge; \ +- else if(v->dqprofile == DQPROFILE_DOUBLE_EDGES) \ +- edges = (3 << v->dqsbedge) % 15; \ +- else if(v->dqprofile == DQPROFILE_FOUR_EDGES) \ +- edges = 15; \ +- if((edges&1) && !s->mb_x) \ +- mquant = v->altpq; \ +- if((edges&2) && s->first_slice_line) \ +- mquant = v->altpq; \ +- if((edges&4) && s->mb_x == (s->mb_width - 1)) \ +- mquant = v->altpq; \ +- if((edges&8) && s->mb_y == (s->mb_height - 1)) \ +- mquant = v->altpq; \ +- } ++ if (v->dquantfrm) { \ ++ int edges = 0; \ ++ if (v->dqprofile == DQPROFILE_ALL_MBS) { \ ++ if (v->dqbilevel) { \ ++ mquant = (get_bits1(gb)) ? v->altpq : v->pq; \ ++ } else { \ ++ mqdiff = get_bits(gb, 3); \ ++ if (mqdiff != 7) \ ++ mquant = v->pq + mqdiff; \ ++ else \ ++ mquant = get_bits(gb, 5); \ ++ } \ ++ } \ ++ if (v->dqprofile == DQPROFILE_SINGLE_EDGE) \ ++ edges = 1 << v->dqsbedge; \ ++ else if (v->dqprofile == DQPROFILE_DOUBLE_EDGES) \ ++ edges = (3 << v->dqsbedge) % 15; \ ++ else if (v->dqprofile == DQPROFILE_FOUR_EDGES) \ ++ edges = 15; \ ++ if ((edges&1) && !s->mb_x) \ ++ mquant = v->altpq; \ ++ if ((edges&2) && s->first_slice_line) \ ++ mquant = v->altpq; \ ++ if ((edges&4) && s->mb_x == (s->mb_width - 1)) \ ++ mquant = v->altpq; \ ++ if ((edges&8) && s->mb_y == (s->mb_height - 1)) \ ++ mquant = v->altpq; \ ++ } + + /** + * @def GET_MVDATA(_dmv_x, _dmv_y) +@@ -639,94 +1199,346 @@ + * @param _dmv_x Horizontal differential for decoded MV + * @param _dmv_y Vertical differential for decoded MV + */ +-#define GET_MVDATA(_dmv_x, _dmv_y) \ +- index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table,\ +- VC1_MV_DIFF_VLC_BITS, 2); \ +- if (index > 36) \ +- { \ +- mb_has_coeffs = 1; \ +- index -= 37; \ +- } \ +- else mb_has_coeffs = 0; \ +- s->mb_intra = 0; \ +- if (!index) { _dmv_x = _dmv_y = 0; } \ +- else if (index == 35) \ +- { \ +- _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \ +- _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \ +- } \ +- else if (index == 36) \ +- { \ +- _dmv_x = 0; \ +- _dmv_y = 0; \ +- s->mb_intra = 1; \ +- } \ +- else \ +- { \ +- index1 = index%6; \ +- if (!s->quarter_sample && index1 == 5) val = 1; \ +- else val = 0; \ +- if(size_table[index1] - val > 0) \ +- val = get_bits(gb, size_table[index1] - val); \ +- else val = 0; \ +- sign = 0 - (val&1); \ +- _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ +- \ +- index1 = index/6; \ +- if (!s->quarter_sample && index1 == 5) val = 1; \ +- else val = 0; \ +- if(size_table[index1] - val > 0) \ +- val = get_bits(gb, size_table[index1] - val); \ +- else val = 0; \ +- sign = 0 - (val&1); \ +- _dmv_y = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ +- } ++#define GET_MVDATA(_dmv_x, _dmv_y) \ ++ index = 1 + get_vlc2(gb, ff_vc1_mv_diff_vlc[s->mv_table_index].table, \ ++ VC1_MV_DIFF_VLC_BITS, 2); \ ++ if (index > 36) { \ ++ mb_has_coeffs = 1; \ ++ index -= 37; \ ++ } else \ ++ mb_has_coeffs = 0; \ ++ s->mb_intra = 0; \ ++ if (!index) { \ ++ _dmv_x = _dmv_y = 0; \ ++ } else if (index == 35) { \ ++ _dmv_x = get_bits(gb, v->k_x - 1 + s->quarter_sample); \ ++ _dmv_y = get_bits(gb, v->k_y - 1 + s->quarter_sample); \ ++ } else if (index == 36) { \ ++ _dmv_x = 0; \ ++ _dmv_y = 0; \ ++ s->mb_intra = 1; \ ++ } else { \ ++ index1 = index % 6; \ ++ if (!s->quarter_sample && index1 == 5) val = 1; \ ++ else val = 0; \ ++ if (size_table[index1] - val > 0) \ ++ val = get_bits(gb, size_table[index1] - val); \ ++ else val = 0; \ ++ sign = 0 - (val&1); \ ++ _dmv_x = (sign ^ ((val>>1) + offset_table[index1])) - sign; \ ++ \ ++ index1 = index / 6; \ ++ if (!s->quarter_sample && index1 == 5) val = 1; \ ++ else val = 0; \ ++ if (size_table[index1] - val > 0) \ ++ val = get_bits(gb, size_table[index1] - val); \ ++ else val = 0; \ ++ sign = 0 - (val & 1); \ ++ _dmv_y = (sign ^ ((val >> 1) + offset_table[index1])) - sign; \ ++ } ++ ++static av_always_inline void get_mvdata_interlaced(VC1Context *v, int *dmv_x, ++ int *dmv_y, int *pred_flag) ++{ ++ int index, index1; ++ int extend_x = 0, extend_y = 0; ++ GetBitContext *gb = &v->s.gb; ++ int bits, esc; ++ int val, sign; ++ const int* offs_tab; ++ ++ if (v->numref) { ++ bits = VC1_2REF_MVDATA_VLC_BITS; ++ esc = 125; ++ } else { ++ bits = VC1_1REF_MVDATA_VLC_BITS; ++ esc = 71; ++ } ++ switch (v->dmvrange) { ++ case 1: ++ extend_x = 1; ++ break; ++ case 2: ++ extend_y = 1; ++ break; ++ case 3: ++ extend_x = extend_y = 1; ++ break; ++ } ++ index = get_vlc2(gb, v->imv_vlc->table, bits, 3); ++ if (index == esc) { ++ *dmv_x = get_bits(gb, v->k_x); ++ *dmv_y = get_bits(gb, v->k_y); ++ if (v->numref) { ++ *pred_flag = *dmv_y & 1; ++ *dmv_y = (*dmv_y + *pred_flag) >> 1; ++ } ++ } ++ else { ++ if (extend_x) ++ offs_tab = offset_table2; ++ else ++ offs_tab = offset_table1; ++ index1 = (index + 1) % 9; ++ if (index1 != 0) { ++ val = get_bits(gb, index1 + extend_x); ++ sign = 0 -(val & 1); ++ *dmv_x = (sign ^ ((val >> 1) + offs_tab[index1])) - sign; ++ } else ++ *dmv_x = 0; ++ if (extend_y) ++ offs_tab = offset_table2; ++ else ++ offs_tab = offset_table1; ++ index1 = (index + 1) / 9; ++ if (index1 > v->numref) { ++ val = get_bits(gb, (index1 + (extend_y << v->numref)) >> v->numref); ++ sign = 0 - (val & 1); ++ *dmv_y = (sign ^ ((val >> 1) + offs_tab[index1 >> v->numref])) - sign; ++ } else ++ *dmv_y = 0; ++ if (v->numref) ++ *pred_flag = index1 & 1; ++ } ++} ++ ++static av_always_inline int scaleforsame_x(VC1Context *v, int n /* MV */, int dir) ++{ ++ int scaledvalue, refdist; ++ int scalesame1, scalesame2; ++ int scalezone1_x, zone1offset_x; ++ int table_index = dir ^ v->second_field; ++ ++ if (v->s.pict_type != AV_PICTURE_TYPE_B) ++ refdist = v->refdist; ++ else ++ refdist = dir ? v->brfd : v->frfd; ++ if (refdist > 3) ++ refdist = 3; ++ scalesame1 = vc1_field_mvpred_scales[table_index][1][refdist]; ++ scalesame2 = vc1_field_mvpred_scales[table_index][2][refdist]; ++ scalezone1_x = vc1_field_mvpred_scales[table_index][3][refdist]; ++ zone1offset_x = vc1_field_mvpred_scales[table_index][5][refdist]; ++ ++ if (FFABS(n) > 255) ++ scaledvalue = n; ++ else { ++ if (FFABS(n) < scalezone1_x) ++ scaledvalue = (n * scalesame1) >> 8; ++ else { ++ if (n < 0) ++ scaledvalue = ((n * scalesame2) >> 8) - zone1offset_x; ++ else ++ scaledvalue = ((n * scalesame2) >> 8) + zone1offset_x; ++ } ++ } ++ return av_clip(scaledvalue, -v->range_x, v->range_x - 1); ++} ++ ++static av_always_inline int scaleforsame_y(VC1Context *v, int i, int n /* MV */, int dir) ++{ ++ int scaledvalue, refdist; ++ int scalesame1, scalesame2; ++ int scalezone1_y, zone1offset_y; ++ int table_index = dir ^ v->second_field; ++ ++ if (v->s.pict_type != AV_PICTURE_TYPE_B) ++ refdist = v->refdist; ++ else ++ refdist = dir ? v->brfd : v->frfd; ++ if (refdist > 3) ++ refdist = 3; ++ scalesame1 = vc1_field_mvpred_scales[table_index][1][refdist]; ++ scalesame2 = vc1_field_mvpred_scales[table_index][2][refdist]; ++ scalezone1_y = vc1_field_mvpred_scales[table_index][4][refdist]; ++ zone1offset_y = vc1_field_mvpred_scales[table_index][6][refdist]; ++ ++ if (FFABS(n) > 63) ++ scaledvalue = n; ++ else { ++ if (FFABS(n) < scalezone1_y) ++ scaledvalue = (n * scalesame1) >> 8; ++ else { ++ if (n < 0) ++ scaledvalue = ((n * scalesame2) >> 8) - zone1offset_y; ++ else ++ scaledvalue = ((n * scalesame2) >> 8) + zone1offset_y; ++ } ++ } ++ ++ if (v->cur_field_type && !v->ref_field_type[dir]) ++ return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2); ++ else ++ return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1); ++} ++ ++static av_always_inline int scaleforopp_x(VC1Context *v, int n /* MV */) ++{ ++ int scalezone1_x, zone1offset_x; ++ int scaleopp1, scaleopp2, brfd; ++ int scaledvalue; ++ ++ brfd = FFMIN(v->brfd, 3); ++ scalezone1_x = vc1_b_field_mvpred_scales[3][brfd]; ++ zone1offset_x = vc1_b_field_mvpred_scales[5][brfd]; ++ scaleopp1 = vc1_b_field_mvpred_scales[1][brfd]; ++ scaleopp2 = vc1_b_field_mvpred_scales[2][brfd]; ++ ++ if (FFABS(n) > 255) ++ scaledvalue = n; ++ else { ++ if (FFABS(n) < scalezone1_x) ++ scaledvalue = (n * scaleopp1) >> 8; ++ else { ++ if (n < 0) ++ scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_x; ++ else ++ scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_x; ++ } ++ } ++ return av_clip(scaledvalue, -v->range_x, v->range_x - 1); ++} ++ ++static av_always_inline int scaleforopp_y(VC1Context *v, int n /* MV */, int dir) ++{ ++ int scalezone1_y, zone1offset_y; ++ int scaleopp1, scaleopp2, brfd; ++ int scaledvalue; ++ ++ brfd = FFMIN(v->brfd, 3); ++ scalezone1_y = vc1_b_field_mvpred_scales[4][brfd]; ++ zone1offset_y = vc1_b_field_mvpred_scales[6][brfd]; ++ scaleopp1 = vc1_b_field_mvpred_scales[1][brfd]; ++ scaleopp2 = vc1_b_field_mvpred_scales[2][brfd]; ++ ++ if (FFABS(n) > 63) ++ scaledvalue = n; ++ else { ++ if (FFABS(n) < scalezone1_y) ++ scaledvalue = (n * scaleopp1) >> 8; ++ else { ++ if (n < 0) ++ scaledvalue = ((n * scaleopp2) >> 8) - zone1offset_y; ++ else ++ scaledvalue = ((n * scaleopp2) >> 8) + zone1offset_y; ++ } ++ } ++ if (v->cur_field_type && !v->ref_field_type[dir]) { ++ return av_clip(scaledvalue, -v->range_y / 2 + 1, v->range_y / 2); ++ } else { ++ return av_clip(scaledvalue, -v->range_y / 2, v->range_y / 2 - 1); ++ } ++} ++ ++static av_always_inline int scaleforsame(VC1Context *v, int i, int n /* MV */, ++ int dim, int dir) ++{ ++ int brfd, scalesame; ++ int hpel = 1 - v->s.quarter_sample; ++ ++ n >>= hpel; ++ if (v->s.pict_type != AV_PICTURE_TYPE_B || v->second_field || !dir) { ++ if (dim) ++ n = scaleforsame_y(v, i, n, dir) << hpel; ++ else ++ n = scaleforsame_x(v, n, dir) << hpel; ++ return n; ++ } ++ brfd = FFMIN(v->brfd, 3); ++ scalesame = vc1_b_field_mvpred_scales[0][brfd]; ++ ++ n = (n * scalesame >> 8) << hpel; ++ return n; ++} ++ ++static av_always_inline int scaleforopp(VC1Context *v, int n /* MV */, ++ int dim, int dir) ++{ ++ int refdist, scaleopp; ++ int hpel = 1 - v->s.quarter_sample; ++ ++ n >>= hpel; ++ if (v->s.pict_type == AV_PICTURE_TYPE_B && !v->second_field && dir == 1) { ++ if (dim) ++ n = scaleforopp_y(v, n, dir) << hpel; ++ else ++ n = scaleforopp_x(v, n) << hpel; ++ return n; ++ } ++ if (v->s.pict_type != AV_PICTURE_TYPE_B) ++ refdist = FFMIN(v->refdist, 3); ++ else ++ refdist = dir ? v->brfd : v->frfd; ++ scaleopp = vc1_field_mvpred_scales[dir ^ v->second_field][0][refdist]; ++ ++ n = (n * scaleopp >> 8) << hpel; ++ return n; ++} + + /** Predict and set motion vector + */ +-static inline void vc1_pred_mv(MpegEncContext *s, int n, int dmv_x, int dmv_y, int mv1, int r_x, int r_y, uint8_t* is_intra) ++static inline void vc1_pred_mv(VC1Context *v, int n, int dmv_x, int dmv_y, ++ int mv1, int r_x, int r_y, uint8_t* is_intra, ++ int pred_flag, int dir) + { ++ MpegEncContext *s = &v->s; + int xy, wrap, off = 0; + int16_t *A, *B, *C; + int px, py; + int sum; +- ++ int mixedmv_pic, num_samefield = 0, num_oppfield = 0; ++ int opposit, a_f, b_f, c_f; ++ int16_t field_predA[2]; ++ int16_t field_predB[2]; ++ int16_t field_predC[2]; ++ int a_valid, b_valid, c_valid; ++ int hybridmv_thresh, y_bias = 0; ++ ++ if (v->mv_mode == MV_PMODE_MIXED_MV || ++ ((v->mv_mode == MV_PMODE_INTENSITY_COMP) && (v->mv_mode2 == MV_PMODE_MIXED_MV))) ++ mixedmv_pic = 1; ++ else ++ mixedmv_pic = 0; + /* scale MV difference to be quad-pel */ + dmv_x <<= 1 - s->quarter_sample; + dmv_y <<= 1 - s->quarter_sample; + + wrap = s->b8_stride; +- xy = s->block_index[n]; ++ xy = s->block_index[n]; + +- if(s->mb_intra){ +- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = 0; +- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = 0; +- s->current_picture.motion_val[1][xy][0] = 0; +- s->current_picture.motion_val[1][xy][1] = 0; +- if(mv1) { /* duplicate motion data for 1-MV block */ +- s->current_picture.motion_val[0][xy + 1][0] = 0; +- s->current_picture.motion_val[0][xy + 1][1] = 0; +- s->current_picture.motion_val[0][xy + wrap][0] = 0; +- s->current_picture.motion_val[0][xy + wrap][1] = 0; +- s->current_picture.motion_val[0][xy + wrap + 1][0] = 0; +- s->current_picture.motion_val[0][xy + wrap + 1][1] = 0; +- s->current_picture.motion_val[1][xy + 1][0] = 0; +- s->current_picture.motion_val[1][xy + 1][1] = 0; +- s->current_picture.motion_val[1][xy + wrap][0] = 0; +- s->current_picture.motion_val[1][xy + wrap][1] = 0; +- s->current_picture.motion_val[1][xy + wrap + 1][0] = 0; +- s->current_picture.motion_val[1][xy + wrap + 1][1] = 0; ++ if (s->mb_intra) { ++ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = 0; ++ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = 0; ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0; ++ if (mv1) { /* duplicate motion data for 1-MV block */ ++ s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[0][xy + 1 + v->blocks_off][1] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + v->blocks_off][1] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + 1 + v->blocks_off][1] = 0; ++ v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0; ++ s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][xy + 1 + v->blocks_off][1] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap][0] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap + v->blocks_off][1] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap + 1 + v->blocks_off][1] = 0; + } + return; + } + +- C = s->current_picture.motion_val[0][xy - 1]; +- A = s->current_picture.motion_val[0][xy - wrap]; +- if(mv1) +- off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2; +- else { ++ C = s->current_picture.f.motion_val[dir][xy - 1 + v->blocks_off]; ++ A = s->current_picture.f.motion_val[dir][xy - wrap + v->blocks_off]; ++ if (mv1) { ++ if (v->field_mode && mixedmv_pic) ++ off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; ++ else ++ off = (s->mb_x == (s->mb_width - 1)) ? -1 : 2; ++ } else { + //in 4-MV mode different blocks have different B predictor position +- switch(n){ ++ switch (n) { + case 0: + off = (s->mb_x > 0) ? -1 : 1; + break; +@@ -740,79 +1552,404 @@ + off = -1; + } + } +- B = s->current_picture.motion_val[0][xy - wrap + off]; ++ B = s->current_picture.f.motion_val[dir][xy - wrap + off + v->blocks_off]; + +- if(!s->first_slice_line || (n==2 || n==3)) { // predictor A is not out of bounds +- if(s->mb_width == 1) { +- px = A[0]; +- py = A[1]; +- } else { +- px = mid_pred(A[0], B[0], C[0]); +- py = mid_pred(A[1], B[1], C[1]); ++ a_valid = !s->first_slice_line || (n == 2 || n == 3); ++ b_valid = a_valid && (s->mb_width > 1); ++ c_valid = s->mb_x || (n == 1 || n == 3); ++ if (v->field_mode) { ++ a_valid = a_valid && !is_intra[xy - wrap]; ++ b_valid = b_valid && !is_intra[xy - wrap + off]; ++ c_valid = c_valid && !is_intra[xy - 1]; ++ } ++ ++ if (a_valid) { ++ a_f = v->mv_f[dir][xy - wrap + v->blocks_off]; ++ num_oppfield += a_f; ++ num_samefield += 1 - a_f; ++ field_predA[0] = A[0]; ++ field_predA[1] = A[1]; ++ } else { ++ field_predA[0] = field_predA[1] = 0; ++ a_f = 0; ++ } ++ if (b_valid) { ++ b_f = v->mv_f[dir][xy - wrap + off + v->blocks_off]; ++ num_oppfield += b_f; ++ num_samefield += 1 - b_f; ++ field_predB[0] = B[0]; ++ field_predB[1] = B[1]; ++ } else { ++ field_predB[0] = field_predB[1] = 0; ++ b_f = 0; ++ } ++ if (c_valid) { ++ c_f = v->mv_f[dir][xy - 1 + v->blocks_off]; ++ num_oppfield += c_f; ++ num_samefield += 1 - c_f; ++ field_predC[0] = C[0]; ++ field_predC[1] = C[1]; ++ } else { ++ field_predC[0] = field_predC[1] = 0; ++ c_f = 0; ++ } ++ ++ if (v->field_mode) { ++ if (num_samefield <= num_oppfield) ++ opposit = 1 - pred_flag; ++ else ++ opposit = pred_flag; ++ } else ++ opposit = 0; ++ if (opposit) { ++ if (a_valid && !a_f) { ++ field_predA[0] = scaleforopp(v, field_predA[0], 0, dir); ++ field_predA[1] = scaleforopp(v, field_predA[1], 1, dir); ++ } ++ if (b_valid && !b_f) { ++ field_predB[0] = scaleforopp(v, field_predB[0], 0, dir); ++ field_predB[1] = scaleforopp(v, field_predB[1], 1, dir); ++ } ++ if (c_valid && !c_f) { ++ field_predC[0] = scaleforopp(v, field_predC[0], 0, dir); ++ field_predC[1] = scaleforopp(v, field_predC[1], 1, dir); + } +- } else if(s->mb_x || (n==1 || n==3)) { // predictor C is not out of bounds +- px = C[0]; +- py = C[1]; ++ v->mv_f[dir][xy + v->blocks_off] = 1; ++ v->ref_field_type[dir] = !v->cur_field_type; + } else { +- px = py = 0; ++ if (a_valid && a_f) { ++ field_predA[0] = scaleforsame(v, n, field_predA[0], 0, dir); ++ field_predA[1] = scaleforsame(v, n, field_predA[1], 1, dir); ++ } ++ if (b_valid && b_f) { ++ field_predB[0] = scaleforsame(v, n, field_predB[0], 0, dir); ++ field_predB[1] = scaleforsame(v, n, field_predB[1], 1, dir); ++ } ++ if (c_valid && c_f) { ++ field_predC[0] = scaleforsame(v, n, field_predC[0], 0, dir); ++ field_predC[1] = scaleforsame(v, n, field_predC[1], 1, dir); ++ } ++ v->mv_f[dir][xy + v->blocks_off] = 0; ++ v->ref_field_type[dir] = v->cur_field_type; ++ } ++ ++ if (a_valid) { ++ px = field_predA[0]; ++ py = field_predA[1]; ++ } else if (c_valid) { ++ px = field_predC[0]; ++ py = field_predC[1]; ++ } else if (b_valid) { ++ px = field_predB[0]; ++ py = field_predB[1]; ++ } else { ++ px = 0; ++ py = 0; ++ } ++ ++ if (num_samefield + num_oppfield > 1) { ++ px = mid_pred(field_predA[0], field_predB[0], field_predC[0]); ++ py = mid_pred(field_predA[1], field_predB[1], field_predC[1]); + } ++ + /* Pullback MV as specified in 8.3.5.3.4 */ +- { ++ if (!v->field_mode) { + int qx, qy, X, Y; +- qx = (s->mb_x << 6) + ((n==1 || n==3) ? 32 : 0); +- qy = (s->mb_y << 6) + ((n==2 || n==3) ? 32 : 0); +- X = (s->mb_width << 6) - 4; +- Y = (s->mb_height << 6) - 4; +- if(mv1) { +- if(qx + px < -60) px = -60 - qx; +- if(qy + py < -60) py = -60 - qy; +- } else { +- if(qx + px < -28) px = -28 - qx; +- if(qy + py < -28) py = -28 - qy; +- } +- if(qx + px > X) px = X - qx; +- if(qy + py > Y) py = Y - qy; +- } +- /* Calculate hybrid prediction as specified in 8.3.5.3.5 */ +- if((!s->first_slice_line || (n==2 || n==3)) && (s->mb_x || (n==1 || n==3))) { +- if(is_intra[xy - wrap]) +- sum = FFABS(px) + FFABS(py); +- else +- sum = FFABS(px - A[0]) + FFABS(py - A[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { +- px = A[0]; +- py = A[1]; +- } else { +- px = C[0]; +- py = C[1]; +- } ++ qx = (s->mb_x << 6) + ((n == 1 || n == 3) ? 32 : 0); ++ qy = (s->mb_y << 6) + ((n == 2 || n == 3) ? 32 : 0); ++ X = (s->mb_width << 6) - 4; ++ Y = (s->mb_height << 6) - 4; ++ if (mv1) { ++ if (qx + px < -60) px = -60 - qx; ++ if (qy + py < -60) py = -60 - qy; + } else { +- if(is_intra[xy - 1]) ++ if (qx + px < -28) px = -28 - qx; ++ if (qy + py < -28) py = -28 - qy; ++ } ++ if (qx + px > X) px = X - qx; ++ if (qy + py > Y) py = Y - qy; ++ } ++ ++ if (!v->field_mode || s->pict_type != AV_PICTURE_TYPE_B) { ++ /* Calculate hybrid prediction as specified in 8.3.5.3.5 (also 10.3.5.4.3.5) */ ++ hybridmv_thresh = 32; ++ if (a_valid && c_valid) { ++ if (is_intra[xy - wrap]) + sum = FFABS(px) + FFABS(py); + else +- sum = FFABS(px - C[0]) + FFABS(py - C[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { ++ sum = FFABS(px - field_predA[0]) + FFABS(py - field_predA[1]); ++ if (sum > hybridmv_thresh) { ++ if (get_bits1(&s->gb)) { // read HYBRIDPRED bit ++ px = field_predA[0]; ++ py = field_predA[1]; ++ } else { ++ px = field_predC[0]; ++ py = field_predC[1]; ++ } ++ } else { ++ if (is_intra[xy - 1]) ++ sum = FFABS(px) + FFABS(py); ++ else ++ sum = FFABS(px - field_predC[0]) + FFABS(py - field_predC[1]); ++ if (sum > hybridmv_thresh) { ++ if (get_bits1(&s->gb)) { ++ px = field_predA[0]; ++ py = field_predA[1]; ++ } else { ++ px = field_predC[0]; ++ py = field_predC[1]; ++ } ++ } ++ } ++ } ++ } ++ ++ if (v->field_mode && !s->quarter_sample) { ++ r_x <<= 1; ++ r_y <<= 1; ++ } ++ if (v->field_mode && v->numref) ++ r_y >>= 1; ++ if (v->field_mode && v->cur_field_type && v->ref_field_type[dir] == 0) ++ y_bias = 1; ++ /* store MV using signed modulus of MV range defined in 4.11 */ ++ s->mv[dir][n][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x; ++ s->mv[dir][n][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1] = ((py + dmv_y + r_y - y_bias) & ((r_y << 1) - 1)) - r_y + y_bias; ++ if (mv1) { /* duplicate motion data for 1-MV block */ ++ s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; ++ s->current_picture.f.motion_val[dir][xy + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; ++ s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; ++ s->current_picture.f.motion_val[dir][xy + wrap + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; ++ s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][0] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][0]; ++ s->current_picture.f.motion_val[dir][xy + wrap + 1 + v->blocks_off][1] = s->current_picture.f.motion_val[dir][xy + v->blocks_off][1]; ++ v->mv_f[dir][xy + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off]; ++ v->mv_f[dir][xy + wrap + v->blocks_off] = v->mv_f[dir][xy + wrap + 1 + v->blocks_off] = v->mv_f[dir][xy + v->blocks_off]; ++ } ++} ++ ++/** Predict and set motion vector for interlaced frame picture MBs ++ */ ++static inline void vc1_pred_mv_intfr(VC1Context *v, int n, int dmv_x, int dmv_y, ++ int mvn, int r_x, int r_y, uint8_t* is_intra) ++{ ++ MpegEncContext *s = &v->s; ++ int xy, wrap, off = 0; ++ int A[2], B[2], C[2]; ++ int px, py; ++ int a_valid = 0, b_valid = 0, c_valid = 0; ++ int field_a, field_b, field_c; // 0: same, 1: opposit ++ int total_valid, num_samefield, num_oppfield; ++ int pos_c, pos_b, n_adj; ++ ++ wrap = s->b8_stride; ++ xy = s->block_index[n]; ++ ++ if (s->mb_intra) { ++ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = 0; ++ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = 0; ++ s->current_picture.f.motion_val[1][xy][0] = 0; ++ s->current_picture.f.motion_val[1][xy][1] = 0; ++ if (mvn == 1) { /* duplicate motion data for 1-MV block */ ++ s->current_picture.f.motion_val[0][xy + 1][0] = 0; ++ s->current_picture.f.motion_val[0][xy + 1][1] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap][0] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap][1] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + 1][0] = 0; ++ s->current_picture.f.motion_val[0][xy + wrap + 1][1] = 0; ++ v->luma_mv[s->mb_x][0] = v->luma_mv[s->mb_x][1] = 0; ++ s->current_picture.f.motion_val[1][xy + 1][0] = 0; ++ s->current_picture.f.motion_val[1][xy + 1][1] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap][0] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap][1] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap + 1][0] = 0; ++ s->current_picture.f.motion_val[1][xy + wrap + 1][1] = 0; ++ } ++ return; ++ } ++ ++ off = ((n == 0) || (n == 1)) ? 1 : -1; ++ /* predict A */ ++ if (s->mb_x || (n == 1) || (n == 3)) { ++ if ((v->blk_mv_type[xy]) // current block (MB) has a field MV ++ || (!v->blk_mv_type[xy] && !v->blk_mv_type[xy - 1])) { // or both have frame MV ++ A[0] = s->current_picture.f.motion_val[0][xy - 1][0]; ++ A[1] = s->current_picture.f.motion_val[0][xy - 1][1]; ++ a_valid = 1; ++ } else { // current block has frame mv and cand. has field MV (so average) ++ A[0] = (s->current_picture.f.motion_val[0][xy - 1][0] ++ + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][0] + 1) >> 1; ++ A[1] = (s->current_picture.f.motion_val[0][xy - 1][1] ++ + s->current_picture.f.motion_val[0][xy - 1 + off * wrap][1] + 1) >> 1; ++ a_valid = 1; ++ } ++ if (!(n & 1) && v->is_intra[s->mb_x - 1]) { ++ a_valid = 0; ++ A[0] = A[1] = 0; ++ } ++ } else ++ A[0] = A[1] = 0; ++ /* Predict B and C */ ++ B[0] = B[1] = C[0] = C[1] = 0; ++ if (n == 0 || n == 1 || v->blk_mv_type[xy]) { ++ if (!s->first_slice_line) { ++ if (!v->is_intra[s->mb_x - s->mb_stride]) { ++ b_valid = 1; ++ n_adj = n | 2; ++ pos_b = s->block_index[n_adj] - 2 * wrap; ++ if (v->blk_mv_type[pos_b] && v->blk_mv_type[xy]) { ++ n_adj = (n & 2) | (n & 1); ++ } ++ B[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][0]; ++ B[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap][1]; ++ if (v->blk_mv_type[pos_b] && !v->blk_mv_type[xy]) { ++ B[0] = (B[0] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][0] + 1) >> 1; ++ B[1] = (B[1] + s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap][1] + 1) >> 1; ++ } ++ } ++ if (s->mb_width > 1) { ++ if (!v->is_intra[s->mb_x - s->mb_stride + 1]) { ++ c_valid = 1; ++ n_adj = 2; ++ pos_c = s->block_index[2] - 2 * wrap + 2; ++ if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) { ++ n_adj = n & 2; ++ } ++ C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][0]; ++ C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap + 2][1]; ++ if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) { ++ C[0] = (1 + C[0] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][0])) >> 1; ++ C[1] = (1 + C[1] + (s->current_picture.f.motion_val[0][s->block_index[n_adj ^ 2] - 2 * wrap + 2][1])) >> 1; ++ } ++ if (s->mb_x == s->mb_width - 1) { ++ if (!v->is_intra[s->mb_x - s->mb_stride - 1]) { ++ c_valid = 1; ++ n_adj = 3; ++ pos_c = s->block_index[3] - 2 * wrap - 2; ++ if (v->blk_mv_type[pos_c] && v->blk_mv_type[xy]) { ++ n_adj = n | 1; ++ } ++ C[0] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][0]; ++ C[1] = s->current_picture.f.motion_val[0][s->block_index[n_adj] - 2 * wrap - 2][1]; ++ if (v->blk_mv_type[pos_c] && !v->blk_mv_type[xy]) { ++ C[0] = (1 + C[0] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][0]) >> 1; ++ C[1] = (1 + C[1] + s->current_picture.f.motion_val[0][s->block_index[1] - 2 * wrap - 2][1]) >> 1; ++ } ++ } else ++ c_valid = 0; ++ } ++ } ++ } ++ } ++ } else { ++ pos_b = s->block_index[1]; ++ b_valid = 1; ++ B[0] = s->current_picture.f.motion_val[0][pos_b][0]; ++ B[1] = s->current_picture.f.motion_val[0][pos_b][1]; ++ pos_c = s->block_index[0]; ++ c_valid = 1; ++ C[0] = s->current_picture.f.motion_val[0][pos_c][0]; ++ C[1] = s->current_picture.f.motion_val[0][pos_c][1]; ++ } ++ ++ total_valid = a_valid + b_valid + c_valid; ++ // check if predictor A is out of bounds ++ if (!s->mb_x && !(n == 1 || n == 3)) { ++ A[0] = A[1] = 0; ++ } ++ // check if predictor B is out of bounds ++ if ((s->first_slice_line && v->blk_mv_type[xy]) || (s->first_slice_line && !(n & 2))) { ++ B[0] = B[1] = C[0] = C[1] = 0; ++ } ++ if (!v->blk_mv_type[xy]) { ++ if (s->mb_width == 1) { ++ px = B[0]; ++ py = B[1]; ++ } else { ++ if (total_valid >= 2) { ++ px = mid_pred(A[0], B[0], C[0]); ++ py = mid_pred(A[1], B[1], C[1]); ++ } else if (total_valid) { ++ if (a_valid) { px = A[0]; py = A[1]; } ++ if (b_valid) { px = B[0]; py = B[1]; } ++ if (c_valid) { px = C[0]; py = C[1]; } ++ } else ++ px = py = 0; ++ } ++ } else { ++ if (a_valid) ++ field_a = (A[1] & 4) ? 1 : 0; ++ else ++ field_a = 0; ++ if (b_valid) ++ field_b = (B[1] & 4) ? 1 : 0; ++ else ++ field_b = 0; ++ if (c_valid) ++ field_c = (C[1] & 4) ? 1 : 0; ++ else ++ field_c = 0; ++ ++ num_oppfield = field_a + field_b + field_c; ++ num_samefield = total_valid - num_oppfield; ++ if (total_valid == 3) { ++ if ((num_samefield == 3) || (num_oppfield == 3)) { ++ px = mid_pred(A[0], B[0], C[0]); ++ py = mid_pred(A[1], B[1], C[1]); ++ } else if (num_samefield >= num_oppfield) { ++ /* take one MV from same field set depending on priority ++ the check for B may not be necessary */ ++ px = !field_a ? A[0] : B[0]; ++ py = !field_a ? A[1] : B[1]; ++ } else { ++ px = field_a ? A[0] : B[0]; ++ py = field_a ? A[1] : B[1]; ++ } ++ } else if (total_valid == 2) { ++ if (num_samefield >= num_oppfield) { ++ if (!field_a && a_valid) { + px = A[0]; + py = A[1]; +- } else { ++ } else if (!field_b && b_valid) { ++ px = B[0]; ++ py = B[1]; ++ } else if (c_valid) { ++ px = C[0]; ++ py = C[1]; ++ } else px = py = 0; ++ } else { ++ if (field_a && a_valid) { ++ px = A[0]; ++ py = A[1]; ++ } else if (field_b && b_valid) { ++ px = B[0]; ++ py = B[1]; ++ } else if (c_valid) { + px = C[0]; + py = C[1]; + } + } +- } ++ } else if (total_valid == 1) { ++ px = (a_valid) ? A[0] : ((b_valid) ? B[0] : C[0]); ++ py = (a_valid) ? A[1] : ((b_valid) ? B[1] : C[1]); ++ } else ++ px = py = 0; + } ++ + /* store MV using signed modulus of MV range defined in 4.11 */ +- s->mv[0][n][0] = s->current_picture.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x; +- s->mv[0][n][1] = s->current_picture.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y; +- if(mv1) { /* duplicate motion data for 1-MV block */ +- s->current_picture.motion_val[0][xy + 1][0] = s->current_picture.motion_val[0][xy][0]; +- s->current_picture.motion_val[0][xy + 1][1] = s->current_picture.motion_val[0][xy][1]; +- s->current_picture.motion_val[0][xy + wrap][0] = s->current_picture.motion_val[0][xy][0]; +- s->current_picture.motion_val[0][xy + wrap][1] = s->current_picture.motion_val[0][xy][1]; +- s->current_picture.motion_val[0][xy + wrap + 1][0] = s->current_picture.motion_val[0][xy][0]; +- s->current_picture.motion_val[0][xy + wrap + 1][1] = s->current_picture.motion_val[0][xy][1]; ++ s->mv[0][n][0] = s->current_picture.f.motion_val[0][xy][0] = ((px + dmv_x + r_x) & ((r_x << 1) - 1)) - r_x; ++ s->mv[0][n][1] = s->current_picture.f.motion_val[0][xy][1] = ((py + dmv_y + r_y) & ((r_y << 1) - 1)) - r_y; ++ if (mvn == 1) { /* duplicate motion data for 1-MV block */ ++ s->current_picture.f.motion_val[0][xy + 1 ][0] = s->current_picture.f.motion_val[0][xy][0]; ++ s->current_picture.f.motion_val[0][xy + 1 ][1] = s->current_picture.f.motion_val[0][xy][1]; ++ s->current_picture.f.motion_val[0][xy + wrap ][0] = s->current_picture.f.motion_val[0][xy][0]; ++ s->current_picture.f.motion_val[0][xy + wrap ][1] = s->current_picture.f.motion_val[0][xy][1]; ++ s->current_picture.f.motion_val[0][xy + wrap + 1][0] = s->current_picture.f.motion_val[0][xy][0]; ++ s->current_picture.f.motion_val[0][xy + wrap + 1][1] = s->current_picture.f.motion_val[0][xy][1]; ++ } else if (mvn == 2) { /* duplicate motion data for 2-Field MV block */ ++ s->current_picture.f.motion_val[0][xy + 1][0] = s->current_picture.f.motion_val[0][xy][0]; ++ s->current_picture.f.motion_val[0][xy + 1][1] = s->current_picture.f.motion_val[0][xy][1]; ++ s->mv[0][n + 1][0] = s->mv[0][n][0]; ++ s->mv[0][n + 1][1] = s->mv[0][n][1]; + } + } + +@@ -824,112 +1961,138 @@ + DSPContext *dsp = &v->s.dsp; + uint8_t *srcY, *srcU, *srcV; + int dxy, mx, my, uvmx, uvmy, src_x, src_y, uvsrc_x, uvsrc_y; ++ int off, off_uv; ++ int v_edge_pos = s->v_edge_pos >> v->field_mode; + +- if(!v->s.next_picture.data[0])return; ++ if (!v->field_mode && !v->s.next_picture.f.data[0]) ++ return; + +- mx = s->mv[1][0][0]; +- my = s->mv[1][0][1]; ++ mx = s->mv[1][0][0]; ++ my = s->mv[1][0][1]; + uvmx = (mx + ((mx & 3) == 3)) >> 1; + uvmy = (my + ((my & 3) == 3)) >> 1; +- if(v->fastuvmc) { +- uvmx = uvmx + ((uvmx<0)?-(uvmx&1):(uvmx&1)); +- uvmy = uvmy + ((uvmy<0)?-(uvmy&1):(uvmy&1)); +- } +- srcY = s->next_picture.data[0]; +- srcU = s->next_picture.data[1]; +- srcV = s->next_picture.data[2]; +- +- src_x = s->mb_x * 16 + (mx >> 2); +- src_y = s->mb_y * 16 + (my >> 2); +- uvsrc_x = s->mb_x * 8 + (uvmx >> 2); +- uvsrc_y = s->mb_y * 8 + (uvmy >> 2); ++ if (v->field_mode) { ++ if (v->cur_field_type != v->ref_field_type[1]) ++ my = my - 2 + 4 * v->cur_field_type; ++ uvmy = uvmy - 2 + 4 * v->cur_field_type; ++ } ++ if (v->fastuvmc) { ++ uvmx = uvmx + ((uvmx < 0) ? -(uvmx & 1) : (uvmx & 1)); ++ uvmy = uvmy + ((uvmy < 0) ? -(uvmy & 1) : (uvmy & 1)); ++ } ++ srcY = s->next_picture.f.data[0]; ++ srcU = s->next_picture.f.data[1]; ++ srcV = s->next_picture.f.data[2]; ++ ++ src_x = s->mb_x * 16 + (mx >> 2); ++ src_y = s->mb_y * 16 + (my >> 2); ++ uvsrc_x = s->mb_x * 8 + (uvmx >> 2); ++ uvsrc_y = s->mb_y * 8 + (uvmy >> 2); + +- if(v->profile != PROFILE_ADVANCED){ ++ if (v->profile != PROFILE_ADVANCED) { + src_x = av_clip( src_x, -16, s->mb_width * 16); + src_y = av_clip( src_y, -16, s->mb_height * 16); + uvsrc_x = av_clip(uvsrc_x, -8, s->mb_width * 8); + uvsrc_y = av_clip(uvsrc_y, -8, s->mb_height * 8); +- }else{ ++ } else { + src_x = av_clip( src_x, -17, s->avctx->coded_width); + src_y = av_clip( src_y, -18, s->avctx->coded_height + 1); + uvsrc_x = av_clip(uvsrc_x, -8, s->avctx->coded_width >> 1); + uvsrc_y = av_clip(uvsrc_y, -8, s->avctx->coded_height >> 1); + } + +- srcY += src_y * s->linesize + src_x; ++ srcY += src_y * s->linesize + src_x; + srcU += uvsrc_y * s->uvlinesize + uvsrc_x; + srcV += uvsrc_y * s->uvlinesize + uvsrc_x; + ++ if (v->field_mode && v->ref_field_type[1]) { ++ srcY += s->current_picture_ptr->f.linesize[0]; ++ srcU += s->current_picture_ptr->f.linesize[1]; ++ srcV += s->current_picture_ptr->f.linesize[2]; ++ } ++ + /* for grayscale we should not try to read from unknown area */ +- if(s->flags & CODEC_FLAG_GRAY) { ++ if (s->flags & CODEC_FLAG_GRAY) { + srcU = s->edge_emu_buffer + 18 * s->linesize; + srcV = s->edge_emu_buffer + 18 * s->linesize; + } + +- if(v->rangeredfrm +- || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx&3) - 16 - s->mspel*3 +- || (unsigned)(src_y - s->mspel) > s->v_edge_pos - (my&3) - 16 - s->mspel*3){ +- uint8_t *uvbuf= s->edge_emu_buffer + 19 * s->linesize; ++ if (v->rangeredfrm || s->h_edge_pos < 22 || v_edge_pos < 22 ++ || (unsigned)(src_x - s->mspel) > s->h_edge_pos - (mx & 3) - 16 - s->mspel * 3 ++ || (unsigned)(src_y - s->mspel) > v_edge_pos - (my & 3) - 16 - s->mspel * 3) { ++ uint8_t *uvbuf = s->edge_emu_buffer + 19 * s->linesize; + + srcY -= s->mspel * (1 + s->linesize); +- s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, 17+s->mspel*2, 17+s->mspel*2, +- src_x - s->mspel, src_y - s->mspel, s->h_edge_pos, s->v_edge_pos); ++ s->dsp.emulated_edge_mc(s->edge_emu_buffer, srcY, s->linesize, ++ 17 + s->mspel * 2, 17 + s->mspel * 2, ++ src_x - s->mspel, src_y - s->mspel, ++ s->h_edge_pos, v_edge_pos); + srcY = s->edge_emu_buffer; +- s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); +- s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8+1, 8+1, +- uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, s->v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(uvbuf , srcU, s->uvlinesize, 8 + 1, 8 + 1, ++ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); ++ s->dsp.emulated_edge_mc(uvbuf + 16, srcV, s->uvlinesize, 8 + 1, 8 + 1, ++ uvsrc_x, uvsrc_y, s->h_edge_pos >> 1, v_edge_pos >> 1); + srcU = uvbuf; + srcV = uvbuf + 16; + /* if we deal with range reduction we need to scale source blocks */ +- if(v->rangeredfrm) { ++ if (v->rangeredfrm) { + int i, j; + uint8_t *src, *src2; + + src = srcY; +- for(j = 0; j < 17 + s->mspel*2; j++) { +- for(i = 0; i < 17 + s->mspel*2; i++) src[i] = ((src[i] - 128) >> 1) + 128; ++ for (j = 0; j < 17 + s->mspel * 2; j++) { ++ for (i = 0; i < 17 + s->mspel * 2; i++) ++ src[i] = ((src[i] - 128) >> 1) + 128; + src += s->linesize; + } +- src = srcU; src2 = srcV; +- for(j = 0; j < 9; j++) { +- for(i = 0; i < 9; i++) { +- src[i] = ((src[i] - 128) >> 1) + 128; ++ src = srcU; ++ src2 = srcV; ++ for (j = 0; j < 9; j++) { ++ for (i = 0; i < 9; i++) { ++ src[i] = ((src[i] - 128) >> 1) + 128; + src2[i] = ((src2[i] - 128) >> 1) + 128; + } +- src += s->uvlinesize; ++ src += s->uvlinesize; + src2 += s->uvlinesize; + } + } + srcY += s->mspel * (1 + s->linesize); + } + +- if(s->mspel) { ++ if (v->field_mode && v->second_field) { ++ off = s->current_picture_ptr->f.linesize[0]; ++ off_uv = s->current_picture_ptr->f.linesize[1]; ++ } else { ++ off = 0; ++ off_uv = 0; ++ } ++ ++ if (s->mspel) { + dxy = ((my & 3) << 2) | (mx & 3); +- dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] , srcY , s->linesize, v->rnd); +- dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8, srcY + 8, s->linesize, v->rnd); ++ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off , srcY , s->linesize, v->rnd); ++ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8, srcY + 8, s->linesize, v->rnd); + srcY += s->linesize * 8; +- dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize , srcY , s->linesize, v->rnd); +- dsp->avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd); ++ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize , srcY , s->linesize, v->rnd); ++ v->vc1dsp.avg_vc1_mspel_pixels_tab[dxy](s->dest[0] + off + 8 * s->linesize + 8, srcY + 8, s->linesize, v->rnd); + } else { // hpel mc + dxy = (my & 2) | ((mx & 2) >> 1); + +- if(!v->rnd) +- dsp->avg_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16); ++ if (!v->rnd) ++ dsp->avg_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16); + else +- dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0], srcY, s->linesize, 16); ++ dsp->avg_no_rnd_pixels_tab[0][dxy](s->dest[0] + off, srcY, s->linesize, 16); + } + +- if(s->flags & CODEC_FLAG_GRAY) return; ++ if (s->flags & CODEC_FLAG_GRAY) return; + /* Chroma MC always uses qpel blilinear */ +- uvmx = (uvmx&3)<<1; +- uvmy = (uvmy&3)<<1; +- if(!v->rnd){ +- dsp->avg_h264_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->avg_h264_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); +- }else{ +- dsp->avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1], srcU, s->uvlinesize, 8, uvmx, uvmy); +- dsp->avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2], srcV, s->uvlinesize, 8, uvmx, uvmy); ++ uvmx = (uvmx & 3) << 1; ++ uvmy = (uvmy & 3) << 1; ++ if (!v->rnd) { ++ dsp->avg_h264_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ dsp->avg_h264_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); ++ } else { ++ v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[1] + off_uv, srcU, s->uvlinesize, 8, uvmx, uvmy); ++ v->vc1dsp.avg_no_rnd_vc1_chroma_pixels_tab[0](s->dest[2] + off_uv, srcV, s->uvlinesize, 8, uvmx, uvmy); + } + } + +@@ -938,47 +2101,67 @@ + int n = bfrac; + + #if B_FRACTION_DEN==256 +- if(inv) ++ if (inv) + n -= 256; +- if(!qs) ++ if (!qs) + return 2 * ((value * n + 255) >> 9); + return (value * n + 128) >> 8; + #else +- if(inv) ++ if (inv) + n -= B_FRACTION_DEN; +- if(!qs) ++ if (!qs) + return 2 * ((value * n + B_FRACTION_DEN - 1) / (2 * B_FRACTION_DEN)); + return (value * n + B_FRACTION_DEN/2) / B_FRACTION_DEN; + #endif + } + ++static av_always_inline int scale_mv_intfi(int value, int bfrac, int inv, ++ int qs, int qs_last) ++{ ++ int n = bfrac; ++ ++ if (inv) ++ n -= 256; ++ n <<= !qs_last; ++ if (!qs) ++ return (value * n + 255) >> 9; ++ else ++ return (value * n + 128) >> 8; ++} ++ + /** Reconstruct motion vector for B-frame and do motion compensation + */ +-static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mode) ++static inline void vc1_b_mc(VC1Context *v, int dmv_x[2], int dmv_y[2], ++ int direct, int mode) + { +- if(v->use_ic) { ++ if (v->use_ic) { + v->mv_mode2 = v->mv_mode; +- v->mv_mode = MV_PMODE_INTENSITY_COMP; ++ v->mv_mode = MV_PMODE_INTENSITY_COMP; + } +- if(direct) { ++ if (direct) { + vc1_mc_1mv(v, 0); + vc1_interp_mc(v); +- if(v->use_ic) v->mv_mode = v->mv_mode2; ++ if (v->use_ic) ++ v->mv_mode = v->mv_mode2; + return; + } +- if(mode == BMV_TYPE_INTERPOLATED) { ++ if (mode == BMV_TYPE_INTERPOLATED) { + vc1_mc_1mv(v, 0); + vc1_interp_mc(v); +- if(v->use_ic) v->mv_mode = v->mv_mode2; ++ if (v->use_ic) ++ v->mv_mode = v->mv_mode2; + return; + } + +- if(v->use_ic && (mode == BMV_TYPE_BACKWARD)) v->mv_mode = v->mv_mode2; ++ if (v->use_ic && (mode == BMV_TYPE_BACKWARD)) ++ v->mv_mode = v->mv_mode2; + vc1_mc_1mv(v, (mode == BMV_TYPE_BACKWARD)); +- if(v->use_ic) v->mv_mode = v->mv_mode2; ++ if (v->use_ic) ++ v->mv_mode = v->mv_mode2; + } + +-static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], int direct, int mvtype) ++static inline void vc1_pred_b_mv(VC1Context *v, int dmv_x[2], int dmv_y[2], ++ int direct, int mvtype) + { + MpegEncContext *s = &v->s; + int xy, wrap, off = 0; +@@ -999,47 +2182,49 @@ + wrap = s->b8_stride; + xy = s->block_index[0]; + +- if(s->mb_intra) { +- s->current_picture.motion_val[0][xy][0] = +- s->current_picture.motion_val[0][xy][1] = +- s->current_picture.motion_val[1][xy][0] = +- s->current_picture.motion_val[1][xy][1] = 0; ++ if (s->mb_intra) { ++ s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = ++ s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = 0; + return; + } +- s->mv[0][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample); +- s->mv[0][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample); +- s->mv[1][0][0] = scale_mv(s->next_picture.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample); +- s->mv[1][0][1] = scale_mv(s->next_picture.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample); +- +- /* Pullback predicted motion vectors as specified in 8.4.5.4 */ +- s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); +- s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); +- s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); +- s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); +- if(direct) { +- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0]; +- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1]; +- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0]; +- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1]; ++ if (!v->field_mode) { ++ s->mv[0][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 0, s->quarter_sample); ++ s->mv[0][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 0, s->quarter_sample); ++ s->mv[1][0][0] = scale_mv(s->next_picture.f.motion_val[1][xy][0], v->bfraction, 1, s->quarter_sample); ++ s->mv[1][0][1] = scale_mv(s->next_picture.f.motion_val[1][xy][1], v->bfraction, 1, s->quarter_sample); ++ ++ /* Pullback predicted motion vectors as specified in 8.4.5.4 */ ++ s->mv[0][0][0] = av_clip(s->mv[0][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); ++ s->mv[0][0][1] = av_clip(s->mv[0][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); ++ s->mv[1][0][0] = av_clip(s->mv[1][0][0], -60 - (s->mb_x << 6), (s->mb_width << 6) - 4 - (s->mb_x << 6)); ++ s->mv[1][0][1] = av_clip(s->mv[1][0][1], -60 - (s->mb_y << 6), (s->mb_height << 6) - 4 - (s->mb_y << 6)); ++ } ++ if (direct) { ++ s->current_picture.f.motion_val[0][xy + v->blocks_off][0] = s->mv[0][0][0]; ++ s->current_picture.f.motion_val[0][xy + v->blocks_off][1] = s->mv[0][0][1]; ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][0] = s->mv[1][0][0]; ++ s->current_picture.f.motion_val[1][xy + v->blocks_off][1] = s->mv[1][0][1]; + return; + } + +- if((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) { +- C = s->current_picture.motion_val[0][xy - 2]; +- A = s->current_picture.motion_val[0][xy - wrap*2]; ++ if ((mvtype == BMV_TYPE_FORWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) { ++ C = s->current_picture.f.motion_val[0][xy - 2]; ++ A = s->current_picture.f.motion_val[0][xy - wrap * 2]; + off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; +- B = s->current_picture.motion_val[0][xy - wrap*2 + off]; ++ B = s->current_picture.f.motion_val[0][xy - wrap * 2 + off]; + +- if(!s->mb_x) C[0] = C[1] = 0; +- if(!s->first_slice_line) { // predictor A is not out of bounds +- if(s->mb_width == 1) { ++ if (!s->mb_x) C[0] = C[1] = 0; ++ if (!s->first_slice_line) { // predictor A is not out of bounds ++ if (s->mb_width == 1) { + px = A[0]; + py = A[1]; + } else { + px = mid_pred(A[0], B[0], C[0]); + py = mid_pred(A[1], B[1], C[1]); + } +- } else if(s->mb_x) { // predictor C is not out of bounds ++ } else if (s->mb_x) { // predictor C is not out of bounds + px = C[0]; + py = C[1]; + } else { +@@ -1048,34 +2233,34 @@ + /* Pullback MV as specified in 8.3.5.3.4 */ + { + int qx, qy, X, Y; +- if(v->profile < PROFILE_ADVANCED) { ++ if (v->profile < PROFILE_ADVANCED) { + qx = (s->mb_x << 5); + qy = (s->mb_y << 5); +- X = (s->mb_width << 5) - 4; +- Y = (s->mb_height << 5) - 4; +- if(qx + px < -28) px = -28 - qx; +- if(qy + py < -28) py = -28 - qy; +- if(qx + px > X) px = X - qx; +- if(qy + py > Y) py = Y - qy; ++ X = (s->mb_width << 5) - 4; ++ Y = (s->mb_height << 5) - 4; ++ if (qx + px < -28) px = -28 - qx; ++ if (qy + py < -28) py = -28 - qy; ++ if (qx + px > X) px = X - qx; ++ if (qy + py > Y) py = Y - qy; + } else { + qx = (s->mb_x << 6); + qy = (s->mb_y << 6); +- X = (s->mb_width << 6) - 4; +- Y = (s->mb_height << 6) - 4; +- if(qx + px < -60) px = -60 - qx; +- if(qy + py < -60) py = -60 - qy; +- if(qx + px > X) px = X - qx; +- if(qy + py > Y) py = Y - qy; ++ X = (s->mb_width << 6) - 4; ++ Y = (s->mb_height << 6) - 4; ++ if (qx + px < -60) px = -60 - qx; ++ if (qy + py < -60) py = -60 - qy; ++ if (qx + px > X) px = X - qx; ++ if (qy + py > Y) py = Y - qy; + } + } + /* Calculate hybrid prediction as specified in 8.3.5.3.5 */ +- if(0 && !s->first_slice_line && s->mb_x) { +- if(is_intra[xy - wrap]) ++ if (0 && !s->first_slice_line && s->mb_x) { ++ if (is_intra[xy - wrap]) + sum = FFABS(px) + FFABS(py); + else + sum = FFABS(px - A[0]) + FFABS(py - A[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { ++ if (sum > 32) { ++ if (get_bits1(&s->gb)) { + px = A[0]; + py = A[1]; + } else { +@@ -1083,12 +2268,12 @@ + py = C[1]; + } + } else { +- if(is_intra[xy - 2]) ++ if (is_intra[xy - 2]) + sum = FFABS(px) + FFABS(py); + else + sum = FFABS(px - C[0]) + FFABS(py - C[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { ++ if (sum > 32) { ++ if (get_bits1(&s->gb)) { + px = A[0]; + py = A[1]; + } else { +@@ -1102,22 +2287,23 @@ + s->mv[0][0][0] = ((px + dmv_x[0] + r_x) & ((r_x << 1) - 1)) - r_x; + s->mv[0][0][1] = ((py + dmv_y[0] + r_y) & ((r_y << 1) - 1)) - r_y; + } +- if((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) { +- C = s->current_picture.motion_val[1][xy - 2]; +- A = s->current_picture.motion_val[1][xy - wrap*2]; ++ if ((mvtype == BMV_TYPE_BACKWARD) || (mvtype == BMV_TYPE_INTERPOLATED)) { ++ C = s->current_picture.f.motion_val[1][xy - 2]; ++ A = s->current_picture.f.motion_val[1][xy - wrap * 2]; + off = (s->mb_x == (s->mb_width - 1)) ? -2 : 2; +- B = s->current_picture.motion_val[1][xy - wrap*2 + off]; ++ B = s->current_picture.f.motion_val[1][xy - wrap * 2 + off]; + +- if(!s->mb_x) C[0] = C[1] = 0; +- if(!s->first_slice_line) { // predictor A is not out of bounds +- if(s->mb_width == 1) { ++ if (!s->mb_x) ++ C[0] = C[1] = 0; ++ if (!s->first_slice_line) { // predictor A is not out of bounds ++ if (s->mb_width == 1) { + px = A[0]; + py = A[1]; + } else { + px = mid_pred(A[0], B[0], C[0]); + py = mid_pred(A[1], B[1], C[1]); + } +- } else if(s->mb_x) { // predictor C is not out of bounds ++ } else if (s->mb_x) { // predictor C is not out of bounds + px = C[0]; + py = C[1]; + } else { +@@ -1126,34 +2312,34 @@ + /* Pullback MV as specified in 8.3.5.3.4 */ + { + int qx, qy, X, Y; +- if(v->profile < PROFILE_ADVANCED) { ++ if (v->profile < PROFILE_ADVANCED) { + qx = (s->mb_x << 5); + qy = (s->mb_y << 5); +- X = (s->mb_width << 5) - 4; +- Y = (s->mb_height << 5) - 4; +- if(qx + px < -28) px = -28 - qx; +- if(qy + py < -28) py = -28 - qy; +- if(qx + px > X) px = X - qx; +- if(qy + py > Y) py = Y - qy; ++ X = (s->mb_width << 5) - 4; ++ Y = (s->mb_height << 5) - 4; ++ if (qx + px < -28) px = -28 - qx; ++ if (qy + py < -28) py = -28 - qy; ++ if (qx + px > X) px = X - qx; ++ if (qy + py > Y) py = Y - qy; + } else { + qx = (s->mb_x << 6); + qy = (s->mb_y << 6); +- X = (s->mb_width << 6) - 4; +- Y = (s->mb_height << 6) - 4; +- if(qx + px < -60) px = -60 - qx; +- if(qy + py < -60) py = -60 - qy; +- if(qx + px > X) px = X - qx; +- if(qy + py > Y) py = Y - qy; ++ X = (s->mb_width << 6) - 4; ++ Y = (s->mb_height << 6) - 4; ++ if (qx + px < -60) px = -60 - qx; ++ if (qy + py < -60) py = -60 - qy; ++ if (qx + px > X) px = X - qx; ++ if (qy + py > Y) py = Y - qy; + } + } + /* Calculate hybrid prediction as specified in 8.3.5.3.5 */ +- if(0 && !s->first_slice_line && s->mb_x) { +- if(is_intra[xy - wrap]) ++ if (0 && !s->first_slice_line && s->mb_x) { ++ if (is_intra[xy - wrap]) + sum = FFABS(px) + FFABS(py); + else + sum = FFABS(px - A[0]) + FFABS(py - A[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { ++ if (sum > 32) { ++ if (get_bits1(&s->gb)) { + px = A[0]; + py = A[1]; + } else { +@@ -1161,12 +2347,12 @@ + py = C[1]; + } + } else { +- if(is_intra[xy - 2]) ++ if (is_intra[xy - 2]) + sum = FFABS(px) + FFABS(py); + else + sum = FFABS(px - C[0]) + FFABS(py - C[1]); +- if(sum > 32) { +- if(get_bits1(&s->gb)) { ++ if (sum > 32) { ++ if (get_bits1(&s->gb)) { + px = A[0]; + py = A[1]; + } else { +@@ -1181,10 +2367,67 @@ + s->mv[1][0][0] = ((px + dmv_x[1] + r_x) & ((r_x << 1) - 1)) - r_x; + s->mv[1][0][1] = ((py + dmv_y[1] + r_y) & ((r_y << 1) - 1)) - r_y; + } +- s->current_picture.motion_val[0][xy][0] = s->mv[0][0][0]; +- s->current_picture.motion_val[0][xy][1] = s->mv[0][0][1]; +- s->current_picture.motion_val[1][xy][0] = s->mv[1][0][0]; +- s->current_picture.motion_val[1][xy][1] = s->mv[1][0][1]; ++ s->current_picture.f.motion_val[0][xy][0] = s->mv[0][0][0]; ++ s->current_picture.f.motion_val[0][xy][1] = s->mv[0][0][1]; ++ s->current_picture.f.motion_val[1][xy][0] = s->mv[1][0][0]; ++ s->current_picture.f.motion_val[1][xy][1] = s->mv[1][0][1]; ++} ++ ++static inline void vc1_pred_b_mv_intfi(VC1Context *v, int n, int *dmv_x, int *dmv_y, int mv1, int *pred_flag) ++{ ++ int dir = (v->bmvtype == BMV_TYPE_BACKWARD) ? 1 : 0; ++ MpegEncContext *s = &v->s; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ ++ if (v->bmvtype == BMV_TYPE_DIRECT) { ++ int total_opp, k, f; ++ if (s->next_picture.f.mb_type[mb_pos + v->mb_off] != MB_TYPE_INTRA) { ++ s->mv[0][0][0] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0], ++ v->bfraction, 0, s->quarter_sample, v->qs_last); ++ s->mv[0][0][1] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1], ++ v->bfraction, 0, s->quarter_sample, v->qs_last); ++ s->mv[1][0][0] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0], ++ v->bfraction, 1, s->quarter_sample, v->qs_last); ++ s->mv[1][0][1] = scale_mv_intfi(s->next_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1], ++ v->bfraction, 1, s->quarter_sample, v->qs_last); ++ ++ total_opp = v->mv_f_next[0][s->block_index[0] + v->blocks_off] ++ + v->mv_f_next[0][s->block_index[1] + v->blocks_off] ++ + v->mv_f_next[0][s->block_index[2] + v->blocks_off] ++ + v->mv_f_next[0][s->block_index[3] + v->blocks_off]; ++ f = (total_opp > 2) ? 1 : 0; ++ } else { ++ s->mv[0][0][0] = s->mv[0][0][1] = 0; ++ s->mv[1][0][0] = s->mv[1][0][1] = 0; ++ f = 0; ++ } ++ v->ref_field_type[0] = v->ref_field_type[1] = v->cur_field_type ^ f; ++ for (k = 0; k < 4; k++) { ++ s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][0] = s->mv[0][0][0]; ++ s->current_picture.f.motion_val[0][s->block_index[k] + v->blocks_off][1] = s->mv[0][0][1]; ++ s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][0] = s->mv[1][0][0]; ++ s->current_picture.f.motion_val[1][s->block_index[k] + v->blocks_off][1] = s->mv[1][0][1]; ++ v->mv_f[0][s->block_index[k] + v->blocks_off] = f; ++ v->mv_f[1][s->block_index[k] + v->blocks_off] = f; ++ } ++ return; ++ } ++ if (v->bmvtype == BMV_TYPE_INTERPOLATED) { ++ vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0); ++ vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1); ++ return; ++ } ++ if (dir) { // backward ++ vc1_pred_mv(v, n, dmv_x[1], dmv_y[1], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[1], 1); ++ if (n == 3 || mv1) { ++ vc1_pred_mv(v, 0, dmv_x[0], dmv_y[0], 1, v->range_x, v->range_y, v->mb_type[0], 0, 0); ++ } ++ } else { // forward ++ vc1_pred_mv(v, n, dmv_x[0], dmv_y[0], mv1, v->range_x, v->range_y, v->mb_type[0], pred_flag[0], 0); ++ if (n == 3 || mv1) { ++ vc1_pred_mv(v, 0, dmv_x[1], dmv_y[1], 1, v->range_x, v->range_y, v->mb_type[0], 0, 1); ++ } ++ } + } + + /** Get predicted DC value for I-frames only +@@ -1197,23 +2440,23 @@ + * @param dir_ptr Prediction direction for use in AC prediction + */ + static inline int vc1_i_pred_dc(MpegEncContext *s, int overlap, int pq, int n, +- int16_t **dc_val_ptr, int *dir_ptr) ++ int16_t **dc_val_ptr, int *dir_ptr) + { + int a, b, c, wrap, pred, scale; + int16_t *dc_val; + static const uint16_t dcpred[32] = { +- -1, 1024, 512, 341, 256, 205, 171, 146, 128, +- 114, 102, 93, 85, 79, 73, 68, 64, +- 60, 57, 54, 51, 49, 47, 45, 43, +- 41, 39, 38, 37, 35, 34, 33 ++ -1, 1024, 512, 341, 256, 205, 171, 146, 128, ++ 114, 102, 93, 85, 79, 73, 68, 64, ++ 60, 57, 54, 51, 49, 47, 45, 43, ++ 41, 39, 38, 37, 35, 34, 33 + }; + + /* find prediction - wmv3_dc_scale always used here in fact */ +- if (n < 4) scale = s->y_dc_scale; +- else scale = s->c_dc_scale; ++ if (n < 4) scale = s->y_dc_scale; ++ else scale = s->c_dc_scale; + +- wrap = s->block_wrap[n]; +- dc_val= s->dc_val[0] + s->block_index[n]; ++ wrap = s->block_wrap[n]; ++ dc_val = s->dc_val[0] + s->block_index[n]; + + /* B A + * C X +@@ -1222,25 +2465,26 @@ + b = dc_val[ - 1 - wrap]; + a = dc_val[ - wrap]; + +- if (pq < 9 || !overlap) +- { ++ if (pq < 9 || !overlap) { + /* Set outer values */ +- if (s->first_slice_line && (n!=2 && n!=3)) b=a=dcpred[scale]; +- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=dcpred[scale]; +- } +- else +- { ++ if (s->first_slice_line && (n != 2 && n != 3)) ++ b = a = dcpred[scale]; ++ if (s->mb_x == 0 && (n != 1 && n != 3)) ++ b = c = dcpred[scale]; ++ } else { + /* Set outer values */ +- if (s->first_slice_line && (n!=2 && n!=3)) b=a=0; +- if (s->mb_x == 0 && (n!=1 && n!=3)) b=c=0; ++ if (s->first_slice_line && (n != 2 && n != 3)) ++ b = a = 0; ++ if (s->mb_x == 0 && (n != 1 && n != 3)) ++ b = c = 0; + } + + if (abs(a - b) <= abs(b - c)) { +- pred = c; +- *dir_ptr = 1;//left ++ pred = c; ++ *dir_ptr = 1; // left + } else { +- pred = a; +- *dir_ptr = 0;//top ++ pred = a; ++ *dir_ptr = 0; // top + } + + /* update predictor */ +@@ -1270,7 +2514,7 @@ + int q1, q2 = 0; + + wrap = s->block_wrap[n]; +- dc_val= s->dc_val[0] + s->block_index[n]; ++ dc_val = s->dc_val[0] + s->block_index[n]; + + /* B A + * C X +@@ -1279,43 +2523,45 @@ + b = dc_val[ - 1 - wrap]; + a = dc_val[ - wrap]; + /* scale predictors if needed */ +- q1 = s->current_picture.qscale_table[mb_pos]; +- if(c_avail && (n!= 1 && n!=3)) { +- q2 = s->current_picture.qscale_table[mb_pos - 1]; +- if(q2 && q2 != q1) ++ q1 = s->current_picture.f.qscale_table[mb_pos]; ++ if (c_avail && (n != 1 && n != 3)) { ++ q2 = s->current_picture.f.qscale_table[mb_pos - 1]; ++ if (q2 && q2 != q1) + c = (c * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + } +- if(a_avail && (n!= 2 && n!=3)) { +- q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride]; +- if(q2 && q2 != q1) ++ if (a_avail && (n != 2 && n != 3)) { ++ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride]; ++ if (q2 && q2 != q1) + a = (a * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + } +- if(a_avail && c_avail && (n!=3)) { ++ if (a_avail && c_avail && (n != 3)) { + int off = mb_pos; +- if(n != 1) off--; +- if(n != 2) off -= s->mb_stride; +- q2 = s->current_picture.qscale_table[off]; +- if(q2 && q2 != q1) ++ if (n != 1) ++ off--; ++ if (n != 2) ++ off -= s->mb_stride; ++ q2 = s->current_picture.f.qscale_table[off]; ++ if (q2 && q2 != q1) + b = (b * s->y_dc_scale_table[q2] * ff_vc1_dqscale[s->y_dc_scale_table[q1] - 1] + 0x20000) >> 18; + } + +- if(a_avail && c_avail) { +- if(abs(a - b) <= abs(b - c)) { +- pred = c; +- *dir_ptr = 1;//left ++ if (a_avail && c_avail) { ++ if (abs(a - b) <= abs(b - c)) { ++ pred = c; ++ *dir_ptr = 1; // left + } else { +- pred = a; +- *dir_ptr = 0;//top ++ pred = a; ++ *dir_ptr = 0; // top + } +- } else if(a_avail) { +- pred = a; +- *dir_ptr = 0;//top +- } else if(c_avail) { +- pred = c; +- *dir_ptr = 1;//left ++ } else if (a_avail) { ++ pred = a; ++ *dir_ptr = 0; // top ++ } else if (c_avail) { ++ pred = c; ++ *dir_ptr = 1; // left + } else { +- pred = 0; +- *dir_ptr = 1;//left ++ pred = 0; ++ *dir_ptr = 1; // left + } + + /* update predictor */ +@@ -1326,16 +2572,17 @@ + /** @} */ // Block group + + /** +- * @defgroup vc1_std_mb VC1 Macroblock-level functions in Simple/Main Profiles ++ * @name VC1 Macroblock-level functions in Simple/Main Profiles + * @see 7.1.4, p91 and 8.1.1.7, p(1)04 + * @{ + */ + +-static inline int vc1_coded_block_pred(MpegEncContext * s, int n, uint8_t **coded_block_ptr) ++static inline int vc1_coded_block_pred(MpegEncContext * s, int n, ++ uint8_t **coded_block_ptr) + { + int xy, wrap, pred, a, b, c; + +- xy = s->block_index[n]; ++ xy = s->block_index[n]; + wrap = s->b8_stride; + + /* B C +@@ -1366,61 +2613,62 @@ + * @param codingset set of VLC to decode data + * @see 8.1.3.4 + */ +-static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, int *value, int codingset) ++static void vc1_decode_ac_coeff(VC1Context *v, int *last, int *skip, ++ int *value, int codingset) + { + GetBitContext *gb = &v->s.gb; + int index, escape, run = 0, level = 0, lst = 0; + + index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); + if (index != vc1_ac_sizes[codingset] - 1) { +- run = vc1_index_decode_table[codingset][index][0]; ++ run = vc1_index_decode_table[codingset][index][0]; + level = vc1_index_decode_table[codingset][index][1]; +- lst = index >= vc1_last_decode_table[codingset]; +- if(get_bits1(gb)) ++ lst = index >= vc1_last_decode_table[codingset] || get_bits_left(gb) < 0; ++ if (get_bits1(gb)) + level = -level; + } else { + escape = decode210(gb); + if (escape != 2) { + index = get_vlc2(gb, ff_vc1_ac_coeff_table[codingset].table, AC_VLC_BITS, 3); +- run = vc1_index_decode_table[codingset][index][0]; ++ run = vc1_index_decode_table[codingset][index][0]; + level = vc1_index_decode_table[codingset][index][1]; +- lst = index >= vc1_last_decode_table[codingset]; +- if(escape == 0) { +- if(lst) ++ lst = index >= vc1_last_decode_table[codingset]; ++ if (escape == 0) { ++ if (lst) + level += vc1_last_delta_level_table[codingset][run]; + else + level += vc1_delta_level_table[codingset][run]; + } else { +- if(lst) ++ if (lst) + run += vc1_last_delta_run_table[codingset][level] + 1; + else + run += vc1_delta_run_table[codingset][level] + 1; + } +- if(get_bits1(gb)) ++ if (get_bits1(gb)) + level = -level; + } else { + int sign; + lst = get_bits1(gb); +- if(v->s.esc3_level_length == 0) { +- if(v->pq < 8 || v->dquantfrm) { // table 59 ++ if (v->s.esc3_level_length == 0) { ++ if (v->pq < 8 || v->dquantfrm) { // table 59 + v->s.esc3_level_length = get_bits(gb, 3); +- if(!v->s.esc3_level_length) ++ if (!v->s.esc3_level_length) + v->s.esc3_level_length = get_bits(gb, 2) + 8; +- } else { //table 60 ++ } else { // table 60 + v->s.esc3_level_length = get_unary(gb, 1, 6) + 2; + } + v->s.esc3_run_length = 3 + get_bits(gb, 2); + } +- run = get_bits(gb, v->s.esc3_run_length); +- sign = get_bits1(gb); ++ run = get_bits(gb, v->s.esc3_run_length); ++ sign = get_bits1(gb); + level = get_bits(gb, v->s.esc3_level_length); +- if(sign) ++ if (sign) + level = -level; + } + } + +- *last = lst; +- *skip = run; ++ *last = lst; ++ *skip = run; + *value = level; + } + +@@ -1431,7 +2679,8 @@ + * @param coded are AC coeffs present or not + * @param codingset set of VLC to decode data + */ +-static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset) ++static int vc1_decode_i_block(VC1Context *v, DCTELEM block[64], int n, ++ int coded, int codingset) + { + GetBitContext *gb = &v->s.gb; + MpegEncContext *s = &v->s; +@@ -1447,25 +2696,21 @@ + } else { + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); + } +- if (dcdiff < 0){ ++ if (dcdiff < 0) { + av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n"); + return -1; + } +- if (dcdiff) +- { +- if (dcdiff == 119 /* ESC index value */) +- { ++ if (dcdiff) { ++ if (dcdiff == 119 /* ESC index value */) { + /* TODO: Optimize */ +- if (v->pq == 1) dcdiff = get_bits(gb, 10); ++ if (v->pq == 1) dcdiff = get_bits(gb, 10); + else if (v->pq == 2) dcdiff = get_bits(gb, 9); +- else dcdiff = get_bits(gb, 8); +- } +- else +- { ++ else dcdiff = get_bits(gb, 8); ++ } else { + if (v->pq == 1) +- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; ++ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3; + else if (v->pq == 2) +- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; ++ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1; + } + if (get_bits1(gb)) + dcdiff = -dcdiff; +@@ -1486,7 +2731,7 @@ + goto not_coded; + } + +- //AC Decoding ++ // AC Decoding + i = 1; + + { +@@ -1497,88 +2742,88 @@ + + scale = v->pq * 2 + v->halfpq; + +- if(v->s.ac_pred) { +- if(!dc_pred_dir) +- zz_table = wmv1_scantable[2]; ++ if (v->s.ac_pred) { ++ if (!dc_pred_dir) ++ zz_table = v->zz_8x8[2]; + else +- zz_table = wmv1_scantable[3]; ++ zz_table = v->zz_8x8[3]; + } else +- zz_table = wmv1_scantable[1]; ++ zz_table = v->zz_8x8[1]; + +- ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ++ ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val2 = ac_val; +- if(dc_pred_dir) //left ++ if (dc_pred_dir) // left + ac_val -= 16; +- else //top ++ else // top + ac_val -= 16 * s->block_wrap[n]; + + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); + i += skip; +- if(i > 63) ++ if (i > 63) + break; + block[zz_table[i++]] = value; + } + + /* apply AC prediction if needed */ +- if(s->ac_pred) { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) +- block[k << 3] += ac_val[k]; +- } else { //top +- for(k = 1; k < 8; k++) +- block[k] += ac_val[k + 8]; ++ if (s->ac_pred) { ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) ++ block[k << v->left_blk_sh] += ac_val[k]; ++ } else { // top ++ for (k = 1; k < 8; k++) ++ block[k << v->top_blk_sh] += ac_val[k + 8]; + } + } + /* save AC coeffs for further prediction */ +- for(k = 1; k < 8; k++) { +- ac_val2[k] = block[k << 3]; +- ac_val2[k + 8] = block[k]; ++ for (k = 1; k < 8; k++) { ++ ac_val2[k] = block[k << v->left_blk_sh]; ++ ac_val2[k + 8] = block[k << v->top_blk_sh]; + } + + /* scale AC coeffs */ +- for(k = 1; k < 64; k++) +- if(block[k]) { ++ for (k = 1; k < 64; k++) ++ if (block[k]) { + block[k] *= scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[k] += (block[k] < 0) ? -v->pq : v->pq; + } + +- if(s->ac_pred) i = 63; ++ if (s->ac_pred) i = 63; + } + + not_coded: +- if(!coded) { ++ if (!coded) { + int k, scale; +- ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ++ ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val2 = ac_val; + + i = 0; + scale = v->pq * 2 + v->halfpq; + memset(ac_val2, 0, 16 * 2); +- if(dc_pred_dir) {//left ++ if (dc_pred_dir) { // left + ac_val -= 16; +- if(s->ac_pred) ++ if (s->ac_pred) + memcpy(ac_val2, ac_val, 8 * 2); +- } else {//top ++ } else { // top + ac_val -= 16 * s->block_wrap[n]; +- if(s->ac_pred) ++ if (s->ac_pred) + memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); + } + + /* apply AC prediction if needed */ +- if(s->ac_pred) { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) { +- block[k << 3] = ac_val[k] * scale; +- if(!v->pquantizer && block[k << 3]) +- block[k << 3] += (block[k << 3] < 0) ? -v->pq : v->pq; +- } +- } else { //top +- for(k = 1; k < 8; k++) { +- block[k] = ac_val[k + 8] * scale; +- if(!v->pquantizer && block[k]) +- block[k] += (block[k] < 0) ? -v->pq : v->pq; ++ if (s->ac_pred) { ++ if (dc_pred_dir) { //left ++ for (k = 1; k < 8; k++) { ++ block[k << v->left_blk_sh] = ac_val[k] * scale; ++ if (!v->pquantizer && block[k << v->left_blk_sh]) ++ block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -v->pq : v->pq; ++ } ++ } else { // top ++ for (k = 1; k < 8; k++) { ++ block[k << v->top_blk_sh] = ac_val[k + 8] * scale; ++ if (!v->pquantizer && block[k << v->top_blk_sh]) ++ block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -v->pq : v->pq; + } + } + i = 63; +@@ -1597,7 +2842,8 @@ + * @param codingset set of VLC to decode data + * @param mquant quantizer value for this macroblock + */ +-static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, int coded, int codingset, int mquant) ++static int vc1_decode_i_block_adv(VC1Context *v, DCTELEM block[64], int n, ++ int coded, int codingset, int mquant) + { + GetBitContext *gb = &v->s.gb; + MpegEncContext *s = &v->s; +@@ -1618,25 +2864,21 @@ + } else { + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); + } +- if (dcdiff < 0){ ++ if (dcdiff < 0) { + av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n"); + return -1; + } +- if (dcdiff) +- { +- if (dcdiff == 119 /* ESC index value */) +- { ++ if (dcdiff) { ++ if (dcdiff == 119 /* ESC index value */) { + /* TODO: Optimize */ +- if (mquant == 1) dcdiff = get_bits(gb, 10); ++ if (mquant == 1) dcdiff = get_bits(gb, 10); + else if (mquant == 2) dcdiff = get_bits(gb, 9); +- else dcdiff = get_bits(gb, 8); +- } +- else +- { ++ else dcdiff = get_bits(gb, 8); ++ } else { + if (mquant == 1) +- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; ++ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3; + else if (mquant == 2) +- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; ++ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1; + } + if (get_bits1(gb)) + dcdiff = -dcdiff; +@@ -1657,123 +2899,137 @@ + i = 1; + + /* check if AC is needed at all */ +- if(!a_avail && !c_avail) use_pred = 0; +- ac_val = s->ac_val[0][0] + s->block_index[n] * 16; ++ if (!a_avail && !c_avail) ++ use_pred = 0; ++ ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val2 = ac_val; + + scale = mquant * 2 + ((mquant == v->pq) ? v->halfpq : 0); + +- if(dc_pred_dir) //left ++ if (dc_pred_dir) // left + ac_val -= 16; +- else //top ++ else // top + ac_val -= 16 * s->block_wrap[n]; + +- q1 = s->current_picture.qscale_table[mb_pos]; +- if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1]; +- if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride]; +- if(dc_pred_dir && n==1) q2 = q1; +- if(!dc_pred_dir && n==2) q2 = q1; +- if(n==3) q2 = q1; ++ q1 = s->current_picture.f.qscale_table[mb_pos]; ++ if ( dc_pred_dir && c_avail && mb_pos) ++ q2 = s->current_picture.f.qscale_table[mb_pos - 1]; ++ if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) ++ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride]; ++ if ( dc_pred_dir && n == 1) ++ q2 = q1; ++ if (!dc_pred_dir && n == 2) ++ q2 = q1; ++ if (n == 3) ++ q2 = q1; + +- if(coded) { ++ if (coded) { + int last = 0, skip, value; + const uint8_t *zz_table; + int k; + +- if(v->s.ac_pred) { +- if(!dc_pred_dir) +- zz_table = wmv1_scantable[2]; ++ if (v->s.ac_pred) { ++ if (!use_pred && v->fcm == ILACE_FRAME) { ++ zz_table = v->zzi_8x8; ++ } else { ++ if (!dc_pred_dir) // top ++ zz_table = v->zz_8x8[2]; ++ else // left ++ zz_table = v->zz_8x8[3]; ++ } ++ } else { ++ if (v->fcm != ILACE_FRAME) ++ zz_table = v->zz_8x8[1]; + else +- zz_table = wmv1_scantable[3]; +- } else +- zz_table = wmv1_scantable[1]; ++ zz_table = v->zzi_8x8; ++ } + + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); + i += skip; +- if(i > 63) ++ if (i > 63) + break; + block[zz_table[i++]] = value; + } + + /* apply AC prediction if needed */ +- if(use_pred) { ++ if (use_pred) { + /* scale predictors if needed*/ +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; + +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) +- block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; +- } else { //top +- for(k = 1; k < 8; k++) +- block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) ++ block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; ++ } else { // top ++ for (k = 1; k < 8; k++) ++ block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } else { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) +- block[k << 3] += ac_val[k]; ++ if (dc_pred_dir) { //left ++ for (k = 1; k < 8; k++) ++ block[k << v->left_blk_sh] += ac_val[k]; + } else { //top +- for(k = 1; k < 8; k++) +- block[k] += ac_val[k + 8]; ++ for (k = 1; k < 8; k++) ++ block[k << v->top_blk_sh] += ac_val[k + 8]; + } + } + } + /* save AC coeffs for further prediction */ +- for(k = 1; k < 8; k++) { +- ac_val2[k] = block[k << 3]; +- ac_val2[k + 8] = block[k]; ++ for (k = 1; k < 8; k++) { ++ ac_val2[k ] = block[k << v->left_blk_sh]; ++ ac_val2[k + 8] = block[k << v->top_blk_sh]; + } + + /* scale AC coeffs */ +- for(k = 1; k < 64; k++) +- if(block[k]) { ++ for (k = 1; k < 64; k++) ++ if (block[k]) { + block[k] *= scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[k] += (block[k] < 0) ? -mquant : mquant; + } + +- if(use_pred) i = 63; ++ if (use_pred) i = 63; + } else { // no AC coeffs + int k; + + memset(ac_val2, 0, 16 * 2); +- if(dc_pred_dir) {//left +- if(use_pred) { ++ if (dc_pred_dir) { // left ++ if (use_pred) { + memcpy(ac_val2, ac_val, 8 * 2); +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; +- for(k = 1; k < 8; k++) ++ for (k = 1; k < 8; k++) + ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } +- } else {//top +- if(use_pred) { ++ } else { // top ++ if (use_pred) { + memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; +- for(k = 1; k < 8; k++) ++ for (k = 1; k < 8; k++) + ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } + } + + /* apply AC prediction if needed */ +- if(use_pred) { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) { +- block[k << 3] = ac_val2[k] * scale; +- if(!v->pquantizer && block[k << 3]) +- block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant; +- } +- } else { //top +- for(k = 1; k < 8; k++) { +- block[k] = ac_val2[k + 8] * scale; +- if(!v->pquantizer && block[k]) +- block[k] += (block[k] < 0) ? -mquant : mquant; ++ if (use_pred) { ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) { ++ block[k << v->left_blk_sh] = ac_val2[k] * scale; ++ if (!v->pquantizer && block[k << v->left_blk_sh]) ++ block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant; ++ } ++ } else { // top ++ for (k = 1; k < 8; k++) { ++ block[k << v->top_blk_sh] = ac_val2[k + 8] * scale; ++ if (!v->pquantizer && block[k << v->top_blk_sh]) ++ block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant; + } + } + i = 63; +@@ -1792,7 +3048,8 @@ + * @param mquant block quantizer + * @param codingset set of VLC to decode data + */ +-static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, int coded, int mquant, int codingset) ++static int vc1_decode_intra_block(VC1Context *v, DCTELEM block[64], int n, ++ int coded, int mquant, int codingset) + { + GetBitContext *gb = &v->s.gb; + MpegEncContext *s = &v->s; +@@ -1810,7 +3067,7 @@ + s->dsp.clear_block(block); + + /* XXX: Guard against dumb values of mquant */ +- mquant = (mquant < 1) ? 0 : ( (mquant>31) ? 31 : mquant ); ++ mquant = (mquant < 1) ? 0 : ((mquant > 31) ? 31 : mquant); + + /* Set DC scale - y and c use the same */ + s->y_dc_scale = s->y_dc_scale_table[mquant]; +@@ -1822,25 +3079,21 @@ + } else { + dcdiff = get_vlc2(&s->gb, ff_msmp4_dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); + } +- if (dcdiff < 0){ ++ if (dcdiff < 0) { + av_log(s->avctx, AV_LOG_ERROR, "Illegal DC VLC\n"); + return -1; + } +- if (dcdiff) +- { +- if (dcdiff == 119 /* ESC index value */) +- { ++ if (dcdiff) { ++ if (dcdiff == 119 /* ESC index value */) { + /* TODO: Optimize */ +- if (mquant == 1) dcdiff = get_bits(gb, 10); ++ if (mquant == 1) dcdiff = get_bits(gb, 10); + else if (mquant == 2) dcdiff = get_bits(gb, 9); +- else dcdiff = get_bits(gb, 8); +- } +- else +- { ++ else dcdiff = get_bits(gb, 8); ++ } else { + if (mquant == 1) +- dcdiff = (dcdiff<<2) + get_bits(gb, 2) - 3; ++ dcdiff = (dcdiff << 2) + get_bits(gb, 2) - 3; + else if (mquant == 2) +- dcdiff = (dcdiff<<1) + get_bits1(gb) - 1; ++ dcdiff = (dcdiff << 1) + get_bits1(gb) - 1; + } + if (get_bits1(gb)) + dcdiff = -dcdiff; +@@ -1862,119 +3115,131 @@ + i = 1; + + /* check if AC is needed at all and adjust direction if needed */ +- if(!a_avail) dc_pred_dir = 1; +- if(!c_avail) dc_pred_dir = 0; +- if(!a_avail && !c_avail) use_pred = 0; ++ if (!a_avail) dc_pred_dir = 1; ++ if (!c_avail) dc_pred_dir = 0; ++ if (!a_avail && !c_avail) use_pred = 0; + ac_val = s->ac_val[0][0] + s->block_index[n] * 16; + ac_val2 = ac_val; + + scale = mquant * 2 + v->halfpq; + +- if(dc_pred_dir) //left ++ if (dc_pred_dir) //left + ac_val -= 16; + else //top + ac_val -= 16 * s->block_wrap[n]; + +- q1 = s->current_picture.qscale_table[mb_pos]; +- if(dc_pred_dir && c_avail && mb_pos) q2 = s->current_picture.qscale_table[mb_pos - 1]; +- if(!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) q2 = s->current_picture.qscale_table[mb_pos - s->mb_stride]; +- if(dc_pred_dir && n==1) q2 = q1; +- if(!dc_pred_dir && n==2) q2 = q1; +- if(n==3) q2 = q1; ++ q1 = s->current_picture.f.qscale_table[mb_pos]; ++ if (dc_pred_dir && c_avail && mb_pos) ++ q2 = s->current_picture.f.qscale_table[mb_pos - 1]; ++ if (!dc_pred_dir && a_avail && mb_pos >= s->mb_stride) ++ q2 = s->current_picture.f.qscale_table[mb_pos - s->mb_stride]; ++ if ( dc_pred_dir && n == 1) ++ q2 = q1; ++ if (!dc_pred_dir && n == 2) ++ q2 = q1; ++ if (n == 3) q2 = q1; + +- if(coded) { ++ if (coded) { + int last = 0, skip, value; +- const uint8_t *zz_table; + int k; + +- zz_table = wmv1_scantable[0]; +- + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, codingset); + i += skip; +- if(i > 63) ++ if (i > 63) + break; +- block[zz_table[i++]] = value; ++ if (v->fcm == PROGRESSIVE) ++ block[v->zz_8x8[0][i++]] = value; ++ else { ++ if (use_pred && (v->fcm == ILACE_FRAME)) { ++ if (!dc_pred_dir) // top ++ block[v->zz_8x8[2][i++]] = value; ++ else // left ++ block[v->zz_8x8[3][i++]] = value; ++ } else { ++ block[v->zzi_8x8[i++]] = value; ++ } ++ } + } + + /* apply AC prediction if needed */ +- if(use_pred) { ++ if (use_pred) { + /* scale predictors if needed*/ +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; + +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) +- block[k << 3] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) ++ block[k << v->left_blk_sh] += (ac_val[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } else { //top +- for(k = 1; k < 8; k++) +- block[k] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; ++ for (k = 1; k < 8; k++) ++ block[k << v->top_blk_sh] += (ac_val[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } else { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) +- block[k << 3] += ac_val[k]; +- } else { //top +- for(k = 1; k < 8; k++) +- block[k] += ac_val[k + 8]; ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) ++ block[k << v->left_blk_sh] += ac_val[k]; ++ } else { // top ++ for (k = 1; k < 8; k++) ++ block[k << v->top_blk_sh] += ac_val[k + 8]; + } + } + } + /* save AC coeffs for further prediction */ +- for(k = 1; k < 8; k++) { +- ac_val2[k] = block[k << 3]; +- ac_val2[k + 8] = block[k]; ++ for (k = 1; k < 8; k++) { ++ ac_val2[k ] = block[k << v->left_blk_sh]; ++ ac_val2[k + 8] = block[k << v->top_blk_sh]; + } + + /* scale AC coeffs */ +- for(k = 1; k < 64; k++) +- if(block[k]) { ++ for (k = 1; k < 64; k++) ++ if (block[k]) { + block[k] *= scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[k] += (block[k] < 0) ? -mquant : mquant; + } + +- if(use_pred) i = 63; ++ if (use_pred) i = 63; + } else { // no AC coeffs + int k; + + memset(ac_val2, 0, 16 * 2); +- if(dc_pred_dir) {//left +- if(use_pred) { ++ if (dc_pred_dir) { // left ++ if (use_pred) { + memcpy(ac_val2, ac_val, 8 * 2); +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; +- for(k = 1; k < 8; k++) ++ for (k = 1; k < 8; k++) + ac_val2[k] = (ac_val2[k] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } +- } else {//top +- if(use_pred) { ++ } else { // top ++ if (use_pred) { + memcpy(ac_val2 + 8, ac_val + 8, 8 * 2); +- if(q2 && q1!=q2) { ++ if (q2 && q1 != q2) { + q1 = q1 * 2 + ((q1 == v->pq) ? v->halfpq : 0) - 1; + q2 = q2 * 2 + ((q2 == v->pq) ? v->halfpq : 0) - 1; +- for(k = 1; k < 8; k++) ++ for (k = 1; k < 8; k++) + ac_val2[k + 8] = (ac_val2[k + 8] * q2 * ff_vc1_dqscale[q1 - 1] + 0x20000) >> 18; + } + } + } + + /* apply AC prediction if needed */ +- if(use_pred) { +- if(dc_pred_dir) { //left +- for(k = 1; k < 8; k++) { +- block[k << 3] = ac_val2[k] * scale; +- if(!v->pquantizer && block[k << 3]) +- block[k << 3] += (block[k << 3] < 0) ? -mquant : mquant; +- } +- } else { //top +- for(k = 1; k < 8; k++) { +- block[k] = ac_val2[k + 8] * scale; +- if(!v->pquantizer && block[k]) +- block[k] += (block[k] < 0) ? -mquant : mquant; ++ if (use_pred) { ++ if (dc_pred_dir) { // left ++ for (k = 1; k < 8; k++) { ++ block[k << v->left_blk_sh] = ac_val2[k] * scale; ++ if (!v->pquantizer && block[k << v->left_blk_sh]) ++ block[k << v->left_blk_sh] += (block[k << v->left_blk_sh] < 0) ? -mquant : mquant; ++ } ++ } else { // top ++ for (k = 1; k < 8; k++) { ++ block[k << v->top_blk_sh] = ac_val2[k + 8] * scale; ++ if (!v->pquantizer && block[k << v->top_blk_sh]) ++ block[k << v->top_blk_sh] += (block[k << v->top_blk_sh] < 0) ? -mquant : mquant; + } + } + i = 63; +@@ -1987,8 +3252,10 @@ + + /** Decode P block + */ +-static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, int mquant, int ttmb, int first_block, +- uint8_t *dst, int linesize, int skip_block, int apply_filter, int cbp_top, int cbp_left) ++static int vc1_decode_p_block(VC1Context *v, DCTELEM block[64], int n, ++ int mquant, int ttmb, int first_block, ++ uint8_t *dst, int linesize, int skip_block, ++ int *ttmb_out) + { + MpegEncContext *s = &v->s; + GetBitContext *gb = &s->gb; +@@ -2000,144 +3267,145 @@ + + s->dsp.clear_block(block); + +- if(ttmb == -1) { ++ if (ttmb == -1) { + ttblk = ff_vc1_ttblk_to_tt[v->tt_index][get_vlc2(gb, ff_vc1_ttblk_vlc[v->tt_index].table, VC1_TTBLK_VLC_BITS, 1)]; + } +- if(ttblk == TT_4X4) { ++ if (ttblk == TT_4X4) { + subblkpat = ~(get_vlc2(gb, ff_vc1_subblkpat_vlc[v->tt_index].table, VC1_SUBBLKPAT_VLC_BITS, 1) + 1); + } +- if((ttblk != TT_8X8 && ttblk != TT_4X4) ++ if ((ttblk != TT_8X8 && ttblk != TT_4X4) + && ((v->ttmbf || (ttmb != -1 && (ttmb & 8) && !first_block)) + || (!v->res_rtm_flag && !first_block))) { + subblkpat = decode012(gb); +- if(subblkpat) subblkpat ^= 3; //swap decoded pattern bits +- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ttblk = TT_8X4; +- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ttblk = TT_4X8; ++ if (subblkpat) ++ subblkpat ^= 3; // swap decoded pattern bits ++ if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) ++ ttblk = TT_8X4; ++ if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) ++ ttblk = TT_4X8; + } + scale = 2 * mquant + ((v->pq == mquant) ? v->halfpq : 0); + + // convert transforms like 8X4_TOP to generic TT and SUBBLKPAT +- if(ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) { ++ if (ttblk == TT_8X4_TOP || ttblk == TT_8X4_BOTTOM) { + subblkpat = 2 - (ttblk == TT_8X4_TOP); +- ttblk = TT_8X4; ++ ttblk = TT_8X4; + } +- if(ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) { ++ if (ttblk == TT_4X8_RIGHT || ttblk == TT_4X8_LEFT) { + subblkpat = 2 - (ttblk == TT_4X8_LEFT); +- ttblk = TT_4X8; ++ ttblk = TT_4X8; + } +- switch(ttblk) { ++ switch (ttblk) { + case TT_8X8: +- pat = 0xF; +- i = 0; ++ pat = 0xF; ++ i = 0; + last = 0; + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2); + i += skip; +- if(i > 63) ++ if (i > 63) + break; +- idx = wmv1_scantable[0][i++]; ++ if (!v->fcm) ++ idx = v->zz_8x8[0][i++]; ++ else ++ idx = v->zzi_8x8[i++]; + block[idx] = value * scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[idx] += (block[idx] < 0) ? -mquant : mquant; + } +- if(!skip_block){ +- if(i==1) +- s->dsp.vc1_inv_trans_8x8_dc(dst, linesize, block); +- else{ +- s->dsp.vc1_inv_trans_8x8(block); ++ if (!skip_block) { ++ if (i == 1) ++ v->vc1dsp.vc1_inv_trans_8x8_dc(dst, linesize, block); ++ else { ++ v->vc1dsp.vc1_inv_trans_8x8(block); + s->dsp.add_pixels_clamped(block, dst, linesize); + } +- if(apply_filter && cbp_top & 0xC) +- s->dsp.vc1_v_loop_filter8(dst, linesize, v->pq); +- if(apply_filter && cbp_left & 0xA) +- s->dsp.vc1_h_loop_filter8(dst, linesize, v->pq); + } + break; + case TT_4X4: + pat = ~subblkpat & 0xF; +- for(j = 0; j < 4; j++) { ++ for (j = 0; j < 4; j++) { + last = subblkpat & (1 << (3 - j)); +- i = 0; +- off = (j & 1) * 4 + (j & 2) * 16; ++ i = 0; ++ off = (j & 1) * 4 + (j & 2) * 16; + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2); + i += skip; +- if(i > 15) ++ if (i > 15) + break; +- idx = ff_vc1_simple_progressive_4x4_zz[i++]; ++ if (!v->fcm) ++ idx = ff_vc1_simple_progressive_4x4_zz[i++]; ++ else ++ idx = ff_vc1_adv_interlaced_4x4_zz[i++]; + block[idx + off] = value * scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[idx + off] += (block[idx + off] < 0) ? -mquant : mquant; + } +- if(!(subblkpat & (1 << (3 - j))) && !skip_block){ +- if(i==1) +- s->dsp.vc1_inv_trans_4x4_dc(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off); ++ if (!(subblkpat & (1 << (3 - j))) && !skip_block) { ++ if (i == 1) ++ v->vc1dsp.vc1_inv_trans_4x4_dc(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off); + else +- s->dsp.vc1_inv_trans_4x4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, block + off); +- if(apply_filter && (j&2 ? pat & (1<<(j-2)) : (cbp_top & (1 << (j + 2))))) +- s->dsp.vc1_v_loop_filter4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, v->pq); +- if(apply_filter && (j&1 ? pat & (1<<(j-1)) : (cbp_left & (1 << (j + 1))))) +- s->dsp.vc1_h_loop_filter4(dst + (j&1)*4 + (j&2)*2*linesize, linesize, v->pq); ++ v->vc1dsp.vc1_inv_trans_4x4(dst + (j & 1) * 4 + (j & 2) * 2 * linesize, linesize, block + off); + } + } + break; + case TT_8X4: +- pat = ~((subblkpat & 2)*6 + (subblkpat & 1)*3) & 0xF; +- for(j = 0; j < 2; j++) { ++ pat = ~((subblkpat & 2) * 6 + (subblkpat & 1) * 3) & 0xF; ++ for (j = 0; j < 2; j++) { + last = subblkpat & (1 << (1 - j)); +- i = 0; +- off = j * 32; ++ i = 0; ++ off = j * 32; + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2); + i += skip; +- if(i > 31) ++ if (i > 31) + break; +- idx = v->zz_8x4[i++]+off; ++ if (!v->fcm) ++ idx = v->zz_8x4[i++] + off; ++ else ++ idx = ff_vc1_adv_interlaced_8x4_zz[i++] + off; + block[idx] = value * scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[idx] += (block[idx] < 0) ? -mquant : mquant; + } +- if(!(subblkpat & (1 << (1 - j))) && !skip_block){ +- if(i==1) +- s->dsp.vc1_inv_trans_8x4_dc(dst + j*4*linesize, linesize, block + off); ++ if (!(subblkpat & (1 << (1 - j))) && !skip_block) { ++ if (i == 1) ++ v->vc1dsp.vc1_inv_trans_8x4_dc(dst + j * 4 * linesize, linesize, block + off); + else +- s->dsp.vc1_inv_trans_8x4(dst + j*4*linesize, linesize, block + off); +- if(apply_filter && j ? pat & 0x3 : (cbp_top & 0xC)) +- s->dsp.vc1_v_loop_filter8(dst + j*4*linesize, linesize, v->pq); +- if(apply_filter && cbp_left & (2 << j)) +- s->dsp.vc1_h_loop_filter4(dst + j*4*linesize, linesize, v->pq); ++ v->vc1dsp.vc1_inv_trans_8x4(dst + j * 4 * linesize, linesize, block + off); + } + } + break; + case TT_4X8: +- pat = ~(subblkpat*5) & 0xF; +- for(j = 0; j < 2; j++) { ++ pat = ~(subblkpat * 5) & 0xF; ++ for (j = 0; j < 2; j++) { + last = subblkpat & (1 << (1 - j)); +- i = 0; +- off = j * 4; ++ i = 0; ++ off = j * 4; + while (!last) { + vc1_decode_ac_coeff(v, &last, &skip, &value, v->codingset2); + i += skip; +- if(i > 31) ++ if (i > 31) + break; +- idx = v->zz_4x8[i++]+off; ++ if (!v->fcm) ++ idx = v->zz_4x8[i++] + off; ++ else ++ idx = ff_vc1_adv_interlaced_4x8_zz[i++] + off; + block[idx] = value * scale; +- if(!v->pquantizer) ++ if (!v->pquantizer) + block[idx] += (block[idx] < 0) ? -mquant : mquant; + } +- if(!(subblkpat & (1 << (1 - j))) && !skip_block){ +- if(i==1) +- s->dsp.vc1_inv_trans_4x8_dc(dst + j*4, linesize, block + off); ++ if (!(subblkpat & (1 << (1 - j))) && !skip_block) { ++ if (i == 1) ++ v->vc1dsp.vc1_inv_trans_4x8_dc(dst + j * 4, linesize, block + off); + else +- s->dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off); +- if(apply_filter && cbp_top & (2 << j)) +- s->dsp.vc1_v_loop_filter4(dst + j*4, linesize, v->pq); +- if(apply_filter && j ? pat & 0x5 : (cbp_left & 0xA)) +- s->dsp.vc1_h_loop_filter8(dst + j*4, linesize, v->pq); ++ v->vc1dsp.vc1_inv_trans_4x8(dst + j*4, linesize, block + off); + } + } + break; + } ++ if (ttmb_out) ++ *ttmb_out |= ttblk << (n * 4); + return pat; + } + +@@ -2146,7 +3414,156 @@ + static const int size_table [6] = { 0, 2, 3, 4, 5, 8 }; + static const int offset_table[6] = { 0, 1, 3, 7, 15, 31 }; + +-/** Decode one P-frame MB (in Simple/Main profile) ++static av_always_inline void vc1_apply_p_v_loop_filter(VC1Context *v, int block_num) ++{ ++ MpegEncContext *s = &v->s; ++ int mb_cbp = v->cbp[s->mb_x - s->mb_stride], ++ block_cbp = mb_cbp >> (block_num * 4), bottom_cbp, ++ mb_is_intra = v->is_intra[s->mb_x - s->mb_stride], ++ block_is_intra = mb_is_intra >> (block_num * 4), bottom_is_intra; ++ int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk; ++ uint8_t *dst; ++ ++ if (block_num > 3) { ++ dst = s->dest[block_num - 3]; ++ } else { ++ dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 8) * linesize; ++ } ++ if (s->mb_y != s->end_mb_y || block_num < 2) { ++ int16_t (*mv)[2]; ++ int mv_stride; ++ ++ if (block_num > 3) { ++ bottom_cbp = v->cbp[s->mb_x] >> (block_num * 4); ++ bottom_is_intra = v->is_intra[s->mb_x] >> (block_num * 4); ++ mv = &v->luma_mv[s->mb_x - s->mb_stride]; ++ mv_stride = s->mb_stride; ++ } else { ++ bottom_cbp = (block_num < 2) ? (mb_cbp >> ((block_num + 2) * 4)) ++ : (v->cbp[s->mb_x] >> ((block_num - 2) * 4)); ++ bottom_is_intra = (block_num < 2) ? (mb_is_intra >> ((block_num + 2) * 4)) ++ : (v->is_intra[s->mb_x] >> ((block_num - 2) * 4)); ++ mv_stride = s->b8_stride; ++ mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - 2 * mv_stride]; ++ } ++ ++ if (bottom_is_intra & 1 || block_is_intra & 1 || ++ mv[0][0] != mv[mv_stride][0] || mv[0][1] != mv[mv_stride][1]) { ++ v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); ++ } else { ++ idx = ((bottom_cbp >> 2) | block_cbp) & 3; ++ if (idx == 3) { ++ v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); ++ } else if (idx) { ++ if (idx == 1) ++ v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq); ++ else ++ v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq); ++ } ++ } ++ } ++ ++ dst -= 4 * linesize; ++ ttblk = (v->ttblk[s->mb_x - s->mb_stride] >> (block_num * 4)) & 0xF; ++ if (ttblk == TT_4X4 || ttblk == TT_8X4) { ++ idx = (block_cbp | (block_cbp >> 2)) & 3; ++ if (idx == 3) { ++ v->vc1dsp.vc1_v_loop_filter8(dst, linesize, v->pq); ++ } else if (idx) { ++ if (idx == 1) ++ v->vc1dsp.vc1_v_loop_filter4(dst + 4, linesize, v->pq); ++ else ++ v->vc1dsp.vc1_v_loop_filter4(dst, linesize, v->pq); ++ } ++ } ++} ++ ++static av_always_inline void vc1_apply_p_h_loop_filter(VC1Context *v, int block_num) ++{ ++ MpegEncContext *s = &v->s; ++ int mb_cbp = v->cbp[s->mb_x - 1 - s->mb_stride], ++ block_cbp = mb_cbp >> (block_num * 4), right_cbp, ++ mb_is_intra = v->is_intra[s->mb_x - 1 - s->mb_stride], ++ block_is_intra = mb_is_intra >> (block_num * 4), right_is_intra; ++ int idx, linesize = block_num > 3 ? s->uvlinesize : s->linesize, ttblk; ++ uint8_t *dst; ++ ++ if (block_num > 3) { ++ dst = s->dest[block_num - 3] - 8 * linesize; ++ } else { ++ dst = s->dest[0] + (block_num & 1) * 8 + ((block_num & 2) * 4 - 16) * linesize - 8; ++ } ++ ++ if (s->mb_x != s->mb_width || !(block_num & 5)) { ++ int16_t (*mv)[2]; ++ ++ if (block_num > 3) { ++ right_cbp = v->cbp[s->mb_x - s->mb_stride] >> (block_num * 4); ++ right_is_intra = v->is_intra[s->mb_x - s->mb_stride] >> (block_num * 4); ++ mv = &v->luma_mv[s->mb_x - s->mb_stride - 1]; ++ } else { ++ right_cbp = (block_num & 1) ? (v->cbp[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) ++ : (mb_cbp >> ((block_num + 1) * 4)); ++ right_is_intra = (block_num & 1) ? (v->is_intra[s->mb_x - s->mb_stride] >> ((block_num - 1) * 4)) ++ : (mb_is_intra >> ((block_num + 1) * 4)); ++ mv = &s->current_picture.f.motion_val[0][s->block_index[block_num] - s->b8_stride * 2 - 2]; ++ } ++ if (block_is_intra & 1 || right_is_intra & 1 || mv[0][0] != mv[1][0] || mv[0][1] != mv[1][1]) { ++ v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq); ++ } else { ++ idx = ((right_cbp >> 1) | block_cbp) & 5; // FIXME check ++ if (idx == 5) { ++ v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq); ++ } else if (idx) { ++ if (idx == 1) ++ v->vc1dsp.vc1_h_loop_filter4(dst + 4 * linesize, linesize, v->pq); ++ else ++ v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq); ++ } ++ } ++ } ++ ++ dst -= 4; ++ ttblk = (v->ttblk[s->mb_x - s->mb_stride - 1] >> (block_num * 4)) & 0xf; ++ if (ttblk == TT_4X4 || ttblk == TT_4X8) { ++ idx = (block_cbp | (block_cbp >> 1)) & 5; ++ if (idx == 5) { ++ v->vc1dsp.vc1_h_loop_filter8(dst, linesize, v->pq); ++ } else if (idx) { ++ if (idx == 1) ++ v->vc1dsp.vc1_h_loop_filter4(dst + linesize * 4, linesize, v->pq); ++ else ++ v->vc1dsp.vc1_h_loop_filter4(dst, linesize, v->pq); ++ } ++ } ++} ++ ++static void vc1_apply_p_loop_filter(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ int i; ++ ++ for (i = 0; i < 6; i++) { ++ vc1_apply_p_v_loop_filter(v, i); ++ } ++ ++ /* V always precedes H, therefore we run H one MB before V; ++ * at the end of a row, we catch up to complete the row */ ++ if (s->mb_x) { ++ for (i = 0; i < 6; i++) { ++ vc1_apply_p_h_loop_filter(v, i); ++ } ++ if (s->mb_x == s->mb_width - 1) { ++ s->mb_x++; ++ ff_update_block_index(s); ++ for (i = 0; i < 6; i++) { ++ vc1_apply_p_h_loop_filter(v, i); ++ } ++ } ++ } ++} ++ ++/** Decode one P-frame MB + */ + static int vc1_decode_p_mb(VC1Context *v) + { +@@ -2165,10 +3582,9 @@ + int first_block = 1; + int dst_idx, off; + int skipped, fourmv; +- int block_cbp = 0, pat; +- int apply_loop_filter; ++ int block_cbp = 0, pat, block_tt = 0, block_intra = 0; + +- mquant = v->pq; /* Loosy initialization */ ++ mquant = v->pq; /* lossy initialization */ + + if (v->mv_type_is_raw) + fourmv = get_bits1(gb); +@@ -2179,263 +3595,541 @@ + else + skipped = v->s.mbskip_table[mb_pos]; + +- apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY); +- if (!fourmv) /* 1MV mode */ +- { +- if (!skipped) +- { ++ if (!fourmv) { /* 1MV mode */ ++ if (!skipped) { + GET_MVDATA(dmv_x, dmv_y); + + if (s->mb_intra) { +- s->current_picture.motion_val[1][s->block_index[0]][0] = 0; +- s->current_picture.motion_val[1][s->block_index[0]][1] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; + } +- s->current_picture.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16; +- vc1_pred_mv(s, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]); ++ s->current_picture.f.mb_type[mb_pos] = s->mb_intra ? MB_TYPE_INTRA : MB_TYPE_16x16; ++ vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0); + + /* FIXME Set DC val for inter block ? */ +- if (s->mb_intra && !mb_has_coeffs) +- { ++ if (s->mb_intra && !mb_has_coeffs) { + GET_MQUANT(); + s->ac_pred = get_bits1(gb); +- cbp = 0; +- } +- else if (mb_has_coeffs) +- { +- if (s->mb_intra) s->ac_pred = get_bits1(gb); ++ cbp = 0; ++ } else if (mb_has_coeffs) { ++ if (s->mb_intra) ++ s->ac_pred = get_bits1(gb); + cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); + GET_MQUANT(); +- } +- else +- { ++ } else { + mquant = v->pq; +- cbp = 0; ++ cbp = 0; + } +- s->current_picture.qscale_table[mb_pos] = mquant; ++ s->current_picture.f.qscale_table[mb_pos] = mquant; + + if (!v->ttmbf && !s->mb_intra && mb_has_coeffs) + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, + VC1_TTMB_VLC_BITS, 2); +- if(!s->mb_intra) vc1_mc_1mv(v, 0); ++ if (!s->mb_intra) vc1_mc_1mv(v, 0); + dst_idx = 0; +- for (i=0; i<6; i++) +- { ++ for (i = 0; i < 6; i++) { + s->dc_val[0][s->block_index[i]] = 0; + dst_idx += i >> 2; + val = ((cbp >> (5 - i)) & 1); + off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); + v->mb_type[0][s->block_index[i]] = s->mb_intra; +- if(s->mb_intra) { ++ if (s->mb_intra) { + /* check if prediction blocks A and C are available */ + v->a_avail = v->c_avail = 0; +- if(i == 2 || i == 3 || !s->first_slice_line) ++ if (i == 2 || i == 3 || !s->first_slice_line) + v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; +- if(i == 1 || i == 3 || s->mb_x) ++ if (i == 1 || i == 3 || s->mb_x) + v->c_avail = v->mb_type[0][s->block_index[i] - 1]; + +- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset); +- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; +- s->dsp.vc1_inv_trans_8x8(s->block[i]); +- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; ++ vc1_decode_intra_block(v, s->block[i], i, val, mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[i][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- if(v->pq >= 9 && v->overlap) { +- if(v->c_avail) +- s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- if(v->a_avail) +- s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- } +- if(apply_loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){ +- int left_cbp, top_cbp; +- if(i & 4){ +- left_cbp = v->cbp[s->mb_x - 1] >> (i * 4); +- top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4); +- }else{ +- left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4)); +- top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4)); +- } +- if(left_cbp & 0xC) +- s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- if(top_cbp & 0xA) +- s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- } +- block_cbp |= 0xF << (i << 2); +- } else if(val) { +- int left_cbp = 0, top_cbp = 0, filter = 0; +- if(apply_loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){ +- filter = 1; +- if(i & 4){ +- left_cbp = v->cbp[s->mb_x - 1] >> (i * 4); +- top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4); +- }else{ +- left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4)); +- top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4)); +- } +- if(left_cbp & 0xC) +- s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- if(top_cbp & 0xA) +- s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); ++ if (v->pq >= 9 && v->overlap) { ++ if (v->c_avail) ++ v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); ++ if (v->a_avail) ++ v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); + } +- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp); ++ block_cbp |= 0xF << (i << 2); ++ block_intra |= 1 << i; ++ } else if (val) { ++ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, ++ s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize, ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt); + block_cbp |= pat << (i << 2); +- if(!v->ttmbf && ttmb < 8) ttmb = -1; ++ if (!v->ttmbf && ttmb < 8) ++ ttmb = -1; + first_block = 0; + } + } +- } +- else //Skipped +- { ++ } else { // skipped + s->mb_intra = 0; +- for(i = 0; i < 6; i++) { ++ for (i = 0; i < 6; i++) { + v->mb_type[0][s->block_index[i]] = 0; +- s->dc_val[0][s->block_index[i]] = 0; ++ s->dc_val[0][s->block_index[i]] = 0; + } +- s->current_picture.mb_type[mb_pos] = MB_TYPE_SKIP; +- s->current_picture.qscale_table[mb_pos] = 0; +- vc1_pred_mv(s, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]); ++ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP; ++ s->current_picture.f.qscale_table[mb_pos] = 0; ++ vc1_pred_mv(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0], 0, 0); + vc1_mc_1mv(v, 0); +- return 0; + } +- } //1MV mode +- else //4MV mode +- { +- if (!skipped /* unskipped MB */) +- { ++ } else { // 4MV mode ++ if (!skipped /* unskipped MB */) { + int intra_count = 0, coded_inter = 0; + int is_intra[6], is_coded[6]; + /* Get CBPCY */ + cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); +- for (i=0; i<6; i++) +- { ++ for (i = 0; i < 6; i++) { + val = ((cbp >> (5 - i)) & 1); + s->dc_val[0][s->block_index[i]] = 0; +- s->mb_intra = 0; +- if(i < 4) { ++ s->mb_intra = 0; ++ if (i < 4) { + dmv_x = dmv_y = 0; +- s->mb_intra = 0; ++ s->mb_intra = 0; + mb_has_coeffs = 0; +- if(val) { ++ if (val) { + GET_MVDATA(dmv_x, dmv_y); + } +- vc1_pred_mv(s, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]); +- if(!s->mb_intra) vc1_mc_4mv_luma(v, i); ++ vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0); ++ if (!s->mb_intra) ++ vc1_mc_4mv_luma(v, i, 0); + intra_count += s->mb_intra; +- is_intra[i] = s->mb_intra; +- is_coded[i] = mb_has_coeffs; ++ is_intra[i] = s->mb_intra; ++ is_coded[i] = mb_has_coeffs; + } +- if(i&4){ ++ if (i & 4) { + is_intra[i] = (intra_count >= 3); + is_coded[i] = val; + } +- if(i == 4) vc1_mc_4mv_chroma(v); ++ if (i == 4) ++ vc1_mc_4mv_chroma(v, 0); + v->mb_type[0][s->block_index[i]] = is_intra[i]; +- if(!coded_inter) coded_inter = !is_intra[i] & is_coded[i]; ++ if (!coded_inter) ++ coded_inter = !is_intra[i] & is_coded[i]; + } + // if there are no coded blocks then don't do anything more +- if(!intra_count && !coded_inter) return 0; + dst_idx = 0; ++ if (!intra_count && !coded_inter) ++ goto end; + GET_MQUANT(); +- s->current_picture.qscale_table[mb_pos] = mquant; ++ s->current_picture.f.qscale_table[mb_pos] = mquant; + /* test if block is intra and has pred */ + { + int intrapred = 0; +- for(i=0; i<6; i++) +- if(is_intra[i]) { +- if(((!s->first_slice_line || (i==2 || i==3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]]) +- || ((s->mb_x || (i==1 || i==3)) && v->mb_type[0][s->block_index[i] - 1])) { ++ for (i = 0; i < 6; i++) ++ if (is_intra[i]) { ++ if (((!s->first_slice_line || (i == 2 || i == 3)) && v->mb_type[0][s->block_index[i] - s->block_wrap[i]]) ++ || ((s->mb_x || (i == 1 || i == 3)) && v->mb_type[0][s->block_index[i] - 1])) { + intrapred = 1; + break; + } + } +- if(intrapred)s->ac_pred = get_bits1(gb); +- else s->ac_pred = 0; ++ if (intrapred) ++ s->ac_pred = get_bits1(gb); ++ else ++ s->ac_pred = 0; + } + if (!v->ttmbf && coded_inter) + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); +- for (i=0; i<6; i++) +- { +- dst_idx += i >> 2; +- off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); ++ for (i = 0; i < 6; i++) { ++ dst_idx += i >> 2; ++ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); + s->mb_intra = is_intra[i]; + if (is_intra[i]) { + /* check if prediction blocks A and C are available */ + v->a_avail = v->c_avail = 0; +- if(i == 2 || i == 3 || !s->first_slice_line) ++ if (i == 2 || i == 3 || !s->first_slice_line) + v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; +- if(i == 1 || i == 3 || s->mb_x) ++ if (i == 1 || i == 3 || s->mb_x) + v->c_avail = v->mb_type[0][s->block_index[i] - 1]; + +- vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, (i&4)?v->codingset2:v->codingset); +- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; +- s->dsp.vc1_inv_trans_8x8(s->block[i]); +- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; +- s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize); +- if(v->pq >= 9 && v->overlap) { +- if(v->c_avail) +- s->dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- if(v->a_avail) +- s->dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- } +- if(v->s.loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){ +- int left_cbp, top_cbp; +- if(i & 4){ +- left_cbp = v->cbp[s->mb_x - 1] >> (i * 4); +- top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4); +- }else{ +- left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4)); +- top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4)); +- } +- if(left_cbp & 0xC) +- s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- if(top_cbp & 0xA) +- s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- } +- block_cbp |= 0xF << (i << 2); +- } else if(is_coded[i]) { +- int left_cbp = 0, top_cbp = 0, filter = 0; +- if(v->s.loop_filter && s->mb_x && s->mb_x != (s->mb_width - 1) && s->mb_y && s->mb_y != (s->mb_height - 1)){ +- filter = 1; +- if(i & 4){ +- left_cbp = v->cbp[s->mb_x - 1] >> (i * 4); +- top_cbp = v->cbp[s->mb_x - s->mb_stride] >> (i * 4); +- }else{ +- left_cbp = (i & 1) ? (cbp >> ((i-1)*4)) : (v->cbp[s->mb_x - 1] >> ((i+1)*4)); +- top_cbp = (i & 2) ? (cbp >> ((i-2)*4)) : (v->cbp[s->mb_x - s->mb_stride] >> ((i+2)*4)); +- } +- if(left_cbp & 0xC) +- s->dsp.vc1_v_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); +- if(top_cbp & 0xA) +- s->dsp.vc1_h_loop_filter8(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize, v->pq); ++ vc1_decode_intra_block(v, s->block[i], i, is_coded[i], mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[i][j] <<= 1; ++ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : s->linesize); ++ if (v->pq >= 9 && v->overlap) { ++ if (v->c_avail) ++ v->vc1dsp.vc1_h_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); ++ if (v->a_avail) ++ v->vc1dsp.vc1_v_overlap(s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); + } +- pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), filter, left_cbp, top_cbp); ++ block_cbp |= 0xF << (i << 2); ++ block_intra |= 1 << i; ++ } else if (is_coded[i]) { ++ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, ++ first_block, s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : s->linesize, ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), ++ &block_tt); + block_cbp |= pat << (i << 2); +- if(!v->ttmbf && ttmb < 8) ttmb = -1; ++ if (!v->ttmbf && ttmb < 8) ++ ttmb = -1; + first_block = 0; + } + } +- return 0; +- } +- else //Skipped MB +- { +- s->mb_intra = 0; +- s->current_picture.qscale_table[mb_pos] = 0; +- for (i=0; i<6; i++) { ++ } else { // skipped MB ++ s->mb_intra = 0; ++ s->current_picture.f.qscale_table[mb_pos] = 0; ++ for (i = 0; i < 6; i++) { + v->mb_type[0][s->block_index[i]] = 0; ++ s->dc_val[0][s->block_index[i]] = 0; ++ } ++ for (i = 0; i < 4; i++) { ++ vc1_pred_mv(v, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0], 0, 0); ++ vc1_mc_4mv_luma(v, i, 0); ++ } ++ vc1_mc_4mv_chroma(v, 0); ++ s->current_picture.f.qscale_table[mb_pos] = 0; ++ } ++ } ++end: ++ v->cbp[s->mb_x] = block_cbp; ++ v->ttblk[s->mb_x] = block_tt; ++ v->is_intra[s->mb_x] = block_intra; ++ ++ return 0; ++} ++ ++/* Decode one macroblock in an interlaced frame p picture */ ++ ++static int vc1_decode_p_mb_intfr(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ GetBitContext *gb = &s->gb; ++ int i; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ int cbp = 0; /* cbp decoding stuff */ ++ int mqdiff, mquant; /* MB quantization */ ++ int ttmb = v->ttfrm; /* MB Transform type */ ++ ++ int mb_has_coeffs = 1; /* last_flag */ ++ int dmv_x, dmv_y; /* Differential MV components */ ++ int val; /* temp value */ ++ int first_block = 1; ++ int dst_idx, off; ++ int skipped, fourmv = 0, twomv = 0; ++ int block_cbp = 0, pat, block_tt = 0; ++ int idx_mbmode = 0, mvbp; ++ int stride_y, fieldtx; ++ ++ mquant = v->pq; /* Loosy initialization */ ++ ++ if (v->skip_is_raw) ++ skipped = get_bits1(gb); ++ else ++ skipped = v->s.mbskip_table[mb_pos]; ++ if (!skipped) { ++ if (v->fourmvswitch) ++ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_4MV_MBMODE_VLC_BITS, 2); // try getting this done ++ else ++ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_INTFR_NON4MV_MBMODE_VLC_BITS, 2); // in a single line ++ switch (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0]) { ++ /* store the motion vector type in a flag (useful later) */ ++ case MV_PMODE_INTFR_4MV: ++ fourmv = 1; ++ v->blk_mv_type[s->block_index[0]] = 0; ++ v->blk_mv_type[s->block_index[1]] = 0; ++ v->blk_mv_type[s->block_index[2]] = 0; ++ v->blk_mv_type[s->block_index[3]] = 0; ++ break; ++ case MV_PMODE_INTFR_4MV_FIELD: ++ fourmv = 1; ++ v->blk_mv_type[s->block_index[0]] = 1; ++ v->blk_mv_type[s->block_index[1]] = 1; ++ v->blk_mv_type[s->block_index[2]] = 1; ++ v->blk_mv_type[s->block_index[3]] = 1; ++ break; ++ case MV_PMODE_INTFR_2MV_FIELD: ++ twomv = 1; ++ v->blk_mv_type[s->block_index[0]] = 1; ++ v->blk_mv_type[s->block_index[1]] = 1; ++ v->blk_mv_type[s->block_index[2]] = 1; ++ v->blk_mv_type[s->block_index[3]] = 1; ++ break; ++ case MV_PMODE_INTFR_1MV: ++ v->blk_mv_type[s->block_index[0]] = 0; ++ v->blk_mv_type[s->block_index[1]] = 0; ++ v->blk_mv_type[s->block_index[2]] = 0; ++ v->blk_mv_type[s->block_index[3]] = 0; ++ break; ++ } ++ if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_INTRA) { // intra MB ++ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; ++ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA; ++ s->mb_intra = v->is_intra[s->mb_x] = 1; ++ for (i = 0; i < 6; i++) ++ v->mb_type[0][s->block_index[i]] = 1; ++ fieldtx = v->fieldtx_plane[mb_pos] = get_bits1(gb); ++ mb_has_coeffs = get_bits1(gb); ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); ++ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb); ++ GET_MQUANT(); ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ /* Set DC scale - y and c use the same (not sure if necessary here) */ ++ s->y_dc_scale = s->y_dc_scale_table[mquant]; ++ s->c_dc_scale = s->c_dc_scale_table[mquant]; ++ dst_idx = 0; ++ for (i = 0; i < 6; i++) { + s->dc_val[0][s->block_index[i]] = 0; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ v->mb_type[0][s->block_index[i]] = s->mb_intra; ++ v->a_avail = v->c_avail = 0; ++ if (i == 2 || i == 3 || !s->first_slice_line) ++ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; ++ if (i == 1 || i == 3 || s->mb_x) ++ v->c_avail = v->mb_type[0][s->block_index[i] - 1]; ++ ++ vc1_decode_intra_block(v, s->block[i], i, val, mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ if (i < 4) { ++ stride_y = s->linesize << fieldtx; ++ off = (fieldtx) ? ((i & 1) * 8) + ((i & 2) >> 1) * s->linesize : (i & 1) * 8 + 4 * (i & 2) * s->linesize; ++ } else { ++ stride_y = s->uvlinesize; ++ off = 0; ++ } ++ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, stride_y); ++ //TODO: loop filter + } +- for (i=0; i<4; i++) +- { +- vc1_pred_mv(s, i, 0, 0, 0, v->range_x, v->range_y, v->mb_type[0]); +- vc1_mc_4mv_luma(v, i); ++ ++ } else { // inter MB ++ mb_has_coeffs = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][3]; ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); ++ if (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_2MV_FIELD) { ++ v->twomvbp = get_vlc2(gb, v->twomvbp_vlc->table, VC1_2MV_BLOCK_PATTERN_VLC_BITS, 1); ++ } else { ++ if ((ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV) ++ || (ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][0] == MV_PMODE_INTFR_4MV_FIELD)) { ++ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1); ++ } ++ } ++ s->mb_intra = v->is_intra[s->mb_x] = 0; ++ for (i = 0; i < 6; i++) ++ v->mb_type[0][s->block_index[i]] = 0; ++ fieldtx = v->fieldtx_plane[mb_pos] = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][1]; ++ /* for all motion vector read MVDATA and motion compensate each block */ ++ dst_idx = 0; ++ if (fourmv) { ++ mvbp = v->fourmvbp; ++ for (i = 0; i < 6; i++) { ++ if (i < 4) { ++ dmv_x = dmv_y = 0; ++ val = ((mvbp >> (3 - i)) & 1); ++ if (val) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0); ++ } ++ vc1_pred_mv_intfr(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0]); ++ vc1_mc_4mv_luma(v, i, 0); ++ } else if (i == 4) { ++ vc1_mc_4mv_chroma4(v); ++ } ++ } ++ } else if (twomv) { ++ mvbp = v->twomvbp; ++ dmv_x = dmv_y = 0; ++ if (mvbp & 2) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0); ++ } ++ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]); ++ vc1_mc_4mv_luma(v, 0, 0); ++ vc1_mc_4mv_luma(v, 1, 0); ++ dmv_x = dmv_y = 0; ++ if (mvbp & 1) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0); ++ } ++ vc1_pred_mv_intfr(v, 2, dmv_x, dmv_y, 2, v->range_x, v->range_y, v->mb_type[0]); ++ vc1_mc_4mv_luma(v, 2, 0); ++ vc1_mc_4mv_luma(v, 3, 0); ++ vc1_mc_4mv_chroma4(v); ++ } else { ++ mvbp = ff_vc1_mbmode_intfrp[v->fourmvswitch][idx_mbmode][2]; ++ if (mvbp) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, 0); ++ } ++ vc1_pred_mv_intfr(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0]); ++ vc1_mc_1mv(v, 0); ++ } ++ if (cbp) ++ GET_MQUANT(); // p. 227 ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ if (!v->ttmbf && cbp) ++ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); ++ for (i = 0; i < 6; i++) { ++ s->dc_val[0][s->block_index[i]] = 0; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ if (!fieldtx) ++ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); ++ else ++ off = (i & 4) ? 0 : ((i & 1) * 8 + ((i > 1) * s->linesize)); ++ if (val) { ++ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, ++ first_block, s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : (s->linesize << fieldtx), ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), &block_tt); ++ block_cbp |= pat << (i << 2); ++ if (!v->ttmbf && ttmb < 8) ++ ttmb = -1; ++ first_block = 0; ++ } + } +- vc1_mc_4mv_chroma(v); +- s->current_picture.qscale_table[mb_pos] = 0; +- return 0; + } ++ } else { // skipped ++ s->mb_intra = v->is_intra[s->mb_x] = 0; ++ for (i = 0; i < 6; i++) { ++ v->mb_type[0][s->block_index[i]] = 0; ++ s->dc_val[0][s->block_index[i]] = 0; ++ } ++ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_SKIP; ++ s->current_picture.f.qscale_table[mb_pos] = 0; ++ v->blk_mv_type[s->block_index[0]] = 0; ++ v->blk_mv_type[s->block_index[1]] = 0; ++ v->blk_mv_type[s->block_index[2]] = 0; ++ v->blk_mv_type[s->block_index[3]] = 0; ++ vc1_pred_mv_intfr(v, 0, 0, 0, 1, v->range_x, v->range_y, v->mb_type[0]); ++ vc1_mc_1mv(v, 0); + } +- v->cbp[s->mb_x] = block_cbp; ++ if (s->mb_x == s->mb_width - 1) ++ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0])*s->mb_stride); ++ return 0; ++} + +- /* Should never happen */ +- return -1; ++static int vc1_decode_p_mb_intfi(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ GetBitContext *gb = &s->gb; ++ int i; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ int cbp = 0; /* cbp decoding stuff */ ++ int mqdiff, mquant; /* MB quantization */ ++ int ttmb = v->ttfrm; /* MB Transform type */ ++ ++ int mb_has_coeffs = 1; /* last_flag */ ++ int dmv_x, dmv_y; /* Differential MV components */ ++ int val; /* temp values */ ++ int first_block = 1; ++ int dst_idx, off; ++ int pred_flag; ++ int block_cbp = 0, pat, block_tt = 0; ++ int idx_mbmode = 0; ++ ++ mquant = v->pq; /* Loosy initialization */ ++ ++ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2); ++ if (idx_mbmode <= 1) { // intra MB ++ s->mb_intra = v->is_intra[s->mb_x] = 1; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0; ++ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA; ++ GET_MQUANT(); ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ /* Set DC scale - y and c use the same (not sure if necessary here) */ ++ s->y_dc_scale = s->y_dc_scale_table[mquant]; ++ s->c_dc_scale = s->c_dc_scale_table[mquant]; ++ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb); ++ mb_has_coeffs = idx_mbmode & 1; ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2); ++ dst_idx = 0; ++ for (i = 0; i < 6; i++) { ++ s->dc_val[0][s->block_index[i]] = 0; ++ v->mb_type[0][s->block_index[i]] = 1; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ v->a_avail = v->c_avail = 0; ++ if (i == 2 || i == 3 || !s->first_slice_line) ++ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; ++ if (i == 1 || i == 3 || s->mb_x) ++ v->c_avail = v->mb_type[0][s->block_index[i] - 1]; ++ ++ vc1_decode_intra_block(v, s->block[i], i, val, mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); ++ off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0; ++ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); ++ // TODO: loop filter ++ } ++ } else { ++ s->mb_intra = v->is_intra[s->mb_x] = 0; ++ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16; ++ for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0; ++ if (idx_mbmode <= 5) { // 1-MV ++ dmv_x = dmv_y = 0; ++ if (idx_mbmode & 1) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag); ++ } ++ vc1_pred_mv(v, 0, dmv_x, dmv_y, 1, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0); ++ vc1_mc_1mv(v, 0); ++ mb_has_coeffs = !(idx_mbmode & 2); ++ } else { // 4-MV ++ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1); ++ for (i = 0; i < 6; i++) { ++ if (i < 4) { ++ dmv_x = dmv_y = pred_flag = 0; ++ val = ((v->fourmvbp >> (3 - i)) & 1); ++ if (val) { ++ get_mvdata_interlaced(v, &dmv_x, &dmv_y, &pred_flag); ++ } ++ vc1_pred_mv(v, i, dmv_x, dmv_y, 0, v->range_x, v->range_y, v->mb_type[0], pred_flag, 0); ++ vc1_mc_4mv_luma(v, i, 0); ++ } else if (i == 4) ++ vc1_mc_4mv_chroma(v, 0); ++ } ++ mb_has_coeffs = idx_mbmode & 1; ++ } ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); ++ if (cbp) { ++ GET_MQUANT(); ++ } ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ if (!v->ttmbf && cbp) { ++ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); ++ } ++ dst_idx = 0; ++ for (i = 0; i < 6; i++) { ++ s->dc_val[0][s->block_index[i]] = 0; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize; ++ if (v->second_field) ++ off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]; ++ if (val) { ++ pat = vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, ++ first_block, s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : s->linesize, ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), ++ &block_tt); ++ block_cbp |= pat << (i << 2); ++ if (!v->ttmbf && ttmb < 8) ttmb = -1; ++ first_block = 0; ++ } ++ } ++ } ++ if (s->mb_x == s->mb_width - 1) ++ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride); ++ return 0; + } + + /** Decode one B-frame MB (in Main profile) +@@ -2458,7 +4152,7 @@ + int dmv_x[2], dmv_y[2]; + int bmvtype = BMV_TYPE_BACKWARD; + +- mquant = v->pq; /* Loosy initialization */ ++ mquant = v->pq; /* lossy initialization */ + s->mb_intra = 0; + + if (v->dmb_is_raw) +@@ -2471,11 +4165,11 @@ + skipped = v->s.mbskip_table[mb_pos]; + + dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0; +- for(i = 0; i < 6; i++) { ++ for (i = 0; i < 6; i++) { + v->mb_type[0][s->block_index[i]] = 0; +- s->dc_val[0][s->block_index[i]] = 0; ++ s->dc_val[0][s->block_index[i]] = 0; + } +- s->current_picture.qscale_table[mb_pos] = 0; ++ s->current_picture.f.qscale_table[mb_pos] = 0; + + if (!direct) { + if (!skipped) { +@@ -2483,9 +4177,9 @@ + dmv_x[1] = dmv_x[0]; + dmv_y[1] = dmv_y[0]; + } +- if(skipped || !s->mb_intra) { ++ if (skipped || !s->mb_intra) { + bmvtype = decode012(gb); +- switch(bmvtype) { ++ switch (bmvtype) { + case 0: + bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_BACKWARD : BMV_TYPE_FORWARD; + break; +@@ -2493,16 +4187,17 @@ + bmvtype = (v->bfraction >= (B_FRACTION_DEN/2)) ? BMV_TYPE_FORWARD : BMV_TYPE_BACKWARD; + break; + case 2: +- bmvtype = BMV_TYPE_INTERPOLATED; ++ bmvtype = BMV_TYPE_INTERPOLATED; + dmv_x[0] = dmv_y[0] = 0; + } + } + } +- for(i = 0; i < 6; i++) ++ for (i = 0; i < 6; i++) + v->mb_type[0][s->block_index[i]] = s->mb_intra; + + if (skipped) { +- if(direct) bmvtype = BMV_TYPE_INTERPOLATED; ++ if (direct) ++ bmvtype = BMV_TYPE_INTERPOLATED; + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); + vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); + return; +@@ -2511,29 +4206,29 @@ + cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); + GET_MQUANT(); + s->mb_intra = 0; +- s->current_picture.qscale_table[mb_pos] = mquant; +- if(!v->ttmbf) ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ if (!v->ttmbf) + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); + dmv_x[0] = dmv_y[0] = dmv_x[1] = dmv_y[1] = 0; + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); + vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); + } else { +- if(!mb_has_coeffs && !s->mb_intra) { ++ if (!mb_has_coeffs && !s->mb_intra) { + /* no coded blocks - effectively skipped */ + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); + vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); + return; + } +- if(s->mb_intra && !mb_has_coeffs) { ++ if (s->mb_intra && !mb_has_coeffs) { + GET_MQUANT(); +- s->current_picture.qscale_table[mb_pos] = mquant; ++ s->current_picture.f.qscale_table[mb_pos] = mquant; + s->ac_pred = get_bits1(gb); + cbp = 0; + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); + } else { +- if(bmvtype == BMV_TYPE_INTERPOLATED) { ++ if (bmvtype == BMV_TYPE_INTERPOLATED) { + GET_MVDATA(dmv_x[0], dmv_y[0]); +- if(!mb_has_coeffs) { ++ if (!mb_has_coeffs) { + /* interpolated skipped block */ + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); + vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); +@@ -2541,47 +4236,210 @@ + } + } + vc1_pred_b_mv(v, dmv_x, dmv_y, direct, bmvtype); +- if(!s->mb_intra) { ++ if (!s->mb_intra) { + vc1_b_mc(v, dmv_x, dmv_y, direct, bmvtype); + } +- if(s->mb_intra) ++ if (s->mb_intra) + s->ac_pred = get_bits1(gb); + cbp = get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); + GET_MQUANT(); +- s->current_picture.qscale_table[mb_pos] = mquant; +- if(!v->ttmbf && !s->mb_intra && mb_has_coeffs) ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ if (!v->ttmbf && !s->mb_intra && mb_has_coeffs) + ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); + } + } + dst_idx = 0; +- for (i=0; i<6; i++) +- { ++ for (i = 0; i < 6; i++) { + s->dc_val[0][s->block_index[i]] = 0; + dst_idx += i >> 2; + val = ((cbp >> (5 - i)) & 1); + off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); + v->mb_type[0][s->block_index[i]] = s->mb_intra; +- if(s->mb_intra) { ++ if (s->mb_intra) { + /* check if prediction blocks A and C are available */ + v->a_avail = v->c_avail = 0; +- if(i == 2 || i == 3 || !s->first_slice_line) ++ if (i == 2 || i == 3 || !s->first_slice_line) + v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; +- if(i == 1 || i == 3 || s->mb_x) ++ if (i == 1 || i == 3 || s->mb_x) + v->c_avail = v->mb_type[0][s->block_index[i] - 1]; + +- vc1_decode_intra_block(v, s->block[i], i, val, mquant, (i&4)?v->codingset2:v->codingset); +- if((i>3) && (s->flags & CODEC_FLAG_GRAY)) continue; +- s->dsp.vc1_inv_trans_8x8(s->block[i]); +- if(v->rangeredfrm) for(j = 0; j < 64; j++) s->block[i][j] <<= 1; ++ vc1_decode_intra_block(v, s->block[i], i, val, mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[i][j] <<= 1; + s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, i & 4 ? s->uvlinesize : s->linesize); +- } else if(val) { +- vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, first_block, s->dest[dst_idx] + off, (i&4)?s->uvlinesize:s->linesize, (i&4) && (s->flags & CODEC_FLAG_GRAY), 0, 0, 0); +- if(!v->ttmbf && ttmb < 8) ttmb = -1; ++ } else if (val) { ++ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, ++ first_block, s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : s->linesize, ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL); ++ if (!v->ttmbf && ttmb < 8) ++ ttmb = -1; + first_block = 0; + } + } + } + ++/** Decode one B-frame MB (in interlaced field B picture) ++ */ ++static void vc1_decode_b_mb_intfi(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ GetBitContext *gb = &s->gb; ++ int i, j; ++ int mb_pos = s->mb_x + s->mb_y * s->mb_stride; ++ int cbp = 0; /* cbp decoding stuff */ ++ int mqdiff, mquant; /* MB quantization */ ++ int ttmb = v->ttfrm; /* MB Transform type */ ++ int mb_has_coeffs = 0; /* last_flag */ ++ int val; /* temp value */ ++ int first_block = 1; ++ int dst_idx, off; ++ int fwd; ++ int dmv_x[2], dmv_y[2], pred_flag[2]; ++ int bmvtype = BMV_TYPE_BACKWARD; ++ int idx_mbmode, interpmvp; ++ ++ mquant = v->pq; /* Loosy initialization */ ++ s->mb_intra = 0; ++ ++ idx_mbmode = get_vlc2(gb, v->mbmode_vlc->table, VC1_IF_MBMODE_VLC_BITS, 2); ++ if (idx_mbmode <= 1) { // intra MB ++ s->mb_intra = v->is_intra[s->mb_x] = 1; ++ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; ++ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA; ++ GET_MQUANT(); ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ /* Set DC scale - y and c use the same (not sure if necessary here) */ ++ s->y_dc_scale = s->y_dc_scale_table[mquant]; ++ s->c_dc_scale = s->c_dc_scale_table[mquant]; ++ v->s.ac_pred = v->acpred_plane[mb_pos] = get_bits1(gb); ++ mb_has_coeffs = idx_mbmode & 1; ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_ICBPCY_VLC_BITS, 2); ++ dst_idx = 0; ++ for (i = 0; i < 6; i++) { ++ s->dc_val[0][s->block_index[i]] = 0; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ v->mb_type[0][s->block_index[i]] = s->mb_intra; ++ v->a_avail = v->c_avail = 0; ++ if (i == 2 || i == 3 || !s->first_slice_line) ++ v->a_avail = v->mb_type[0][s->block_index[i] - s->block_wrap[i]]; ++ if (i == 1 || i == 3 || s->mb_x) ++ v->c_avail = v->mb_type[0][s->block_index[i] - 1]; ++ ++ vc1_decode_intra_block(v, s->block[i], i, val, mquant, ++ (i & 4) ? v->codingset2 : v->codingset); ++ if ((i>3) && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[i]); ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[i][j] <<= 1; ++ off = (i & 4) ? 0 : ((i & 1) * 8 + (i & 2) * 4 * s->linesize); ++ off += v->second_field ? ((i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]) : 0; ++ s->dsp.put_signed_pixels_clamped(s->block[i], s->dest[dst_idx] + off, (i & 4) ? s->uvlinesize : s->linesize); ++ // TODO: yet to perform loop filter ++ } ++ } else { ++ s->mb_intra = v->is_intra[s->mb_x] = 0; ++ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_16x16; ++ for (i = 0; i < 6; i++) v->mb_type[0][s->block_index[i]] = 0; ++ if (v->fmb_is_raw) ++ fwd = v->forward_mb_plane[mb_pos] = get_bits1(gb); ++ else ++ fwd = v->forward_mb_plane[mb_pos]; ++ if (idx_mbmode <= 5) { // 1-MV ++ dmv_x[0] = dmv_x[1] = dmv_y[0] = dmv_y[1] = 0; ++ pred_flag[0] = pred_flag[1] = 0; ++ if (fwd) ++ bmvtype = BMV_TYPE_FORWARD; ++ else { ++ bmvtype = decode012(gb); ++ switch (bmvtype) { ++ case 0: ++ bmvtype = BMV_TYPE_BACKWARD; ++ break; ++ case 1: ++ bmvtype = BMV_TYPE_DIRECT; ++ break; ++ case 2: ++ bmvtype = BMV_TYPE_INTERPOLATED; ++ interpmvp = get_bits1(gb); ++ } ++ } ++ v->bmvtype = bmvtype; ++ if (bmvtype != BMV_TYPE_DIRECT && idx_mbmode & 1) { ++ get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], &dmv_y[bmvtype == BMV_TYPE_BACKWARD], &pred_flag[bmvtype == BMV_TYPE_BACKWARD]); ++ } ++ if (bmvtype == BMV_TYPE_INTERPOLATED && interpmvp) { ++ get_mvdata_interlaced(v, &dmv_x[1], &dmv_y[1], &pred_flag[1]); ++ } ++ if (bmvtype == BMV_TYPE_DIRECT) { ++ dmv_x[0] = dmv_y[0] = pred_flag[0] = 0; ++ dmv_x[1] = dmv_y[1] = pred_flag[0] = 0; ++ } ++ vc1_pred_b_mv_intfi(v, 0, dmv_x, dmv_y, 1, pred_flag); ++ vc1_b_mc(v, dmv_x, dmv_y, (bmvtype == BMV_TYPE_DIRECT), bmvtype); ++ mb_has_coeffs = !(idx_mbmode & 2); ++ } else { // 4-MV ++ if (fwd) ++ bmvtype = BMV_TYPE_FORWARD; ++ v->bmvtype = bmvtype; ++ v->fourmvbp = get_vlc2(gb, v->fourmvbp_vlc->table, VC1_4MV_BLOCK_PATTERN_VLC_BITS, 1); ++ for (i = 0; i < 6; i++) { ++ if (i < 4) { ++ dmv_x[0] = dmv_y[0] = pred_flag[0] = 0; ++ dmv_x[1] = dmv_y[1] = pred_flag[1] = 0; ++ val = ((v->fourmvbp >> (3 - i)) & 1); ++ if (val) { ++ get_mvdata_interlaced(v, &dmv_x[bmvtype == BMV_TYPE_BACKWARD], ++ &dmv_y[bmvtype == BMV_TYPE_BACKWARD], ++ &pred_flag[bmvtype == BMV_TYPE_BACKWARD]); ++ } ++ vc1_pred_b_mv_intfi(v, i, dmv_x, dmv_y, 0, pred_flag); ++ vc1_mc_4mv_luma(v, i, bmvtype == BMV_TYPE_BACKWARD); ++ } else if (i == 4) ++ vc1_mc_4mv_chroma(v, bmvtype == BMV_TYPE_BACKWARD); ++ } ++ mb_has_coeffs = idx_mbmode & 1; ++ } ++ if (mb_has_coeffs) ++ cbp = 1 + get_vlc2(&v->s.gb, v->cbpcy_vlc->table, VC1_CBPCY_P_VLC_BITS, 2); ++ if (cbp) { ++ GET_MQUANT(); ++ } ++ s->current_picture.f.qscale_table[mb_pos] = mquant; ++ if (!v->ttmbf && cbp) { ++ ttmb = get_vlc2(gb, ff_vc1_ttmb_vlc[v->tt_index].table, VC1_TTMB_VLC_BITS, 2); ++ } ++ dst_idx = 0; ++ for (i = 0; i < 6; i++) { ++ s->dc_val[0][s->block_index[i]] = 0; ++ dst_idx += i >> 2; ++ val = ((cbp >> (5 - i)) & 1); ++ off = (i & 4) ? 0 : (i & 1) * 8 + (i & 2) * 4 * s->linesize; ++ if (v->second_field) ++ off += (i & 4) ? s->current_picture_ptr->f.linesize[1] : s->current_picture_ptr->f.linesize[0]; ++ if (val) { ++ vc1_decode_p_block(v, s->block[i], i, mquant, ttmb, ++ first_block, s->dest[dst_idx] + off, ++ (i & 4) ? s->uvlinesize : s->linesize, ++ (i & 4) && (s->flags & CODEC_FLAG_GRAY), NULL); ++ if (!v->ttmbf && ttmb < 8) ++ ttmb = -1; ++ first_block = 0; ++ } ++ } ++ } ++} ++ + /** Decode blocks of I-frame + */ + static void vc1_decode_i_blocks(VC1Context *v) +@@ -2593,7 +4451,7 @@ + int mb_pos; + + /* select codingmode used for VLC tables selection */ +- switch(v->y_ac_table_index){ ++ switch (v->y_ac_table_index) { + case 0: + v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA; + break; +@@ -2605,7 +4463,7 @@ + break; + } + +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER; + break; +@@ -2623,101 +4481,117 @@ + + //do frame decode + s->mb_x = s->mb_y = 0; +- s->mb_intra = 1; ++ s->mb_intra = 1; + s->first_slice_line = 1; +- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { ++ for (s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { + s->mb_x = 0; + ff_init_block_index(s); +- for(; s->mb_x < s->mb_width; s->mb_x++) { ++ for (; s->mb_x < s->mb_width; s->mb_x++) { ++ uint8_t *dst[6]; + ff_update_block_index(s); ++ dst[0] = s->dest[0]; ++ dst[1] = dst[0] + 8; ++ dst[2] = s->dest[0] + s->linesize * 8; ++ dst[3] = dst[2] + 8; ++ dst[4] = s->dest[1]; ++ dst[5] = s->dest[2]; + s->dsp.clear_blocks(s->block[0]); + mb_pos = s->mb_x + s->mb_y * s->mb_width; +- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA; +- s->current_picture.qscale_table[mb_pos] = v->pq; +- s->current_picture.motion_val[1][s->block_index[0]][0] = 0; +- s->current_picture.motion_val[1][s->block_index[0]][1] = 0; ++ s->current_picture.f.mb_type[mb_pos] = MB_TYPE_INTRA; ++ s->current_picture.f.qscale_table[mb_pos] = v->pq; ++ s->current_picture.f.motion_val[1][s->block_index[0]][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0]][1] = 0; + + // do actual MB decoding and displaying + cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); + v->s.ac_pred = get_bits1(&v->s.gb); + +- for(k = 0; k < 6; k++) { ++ for (k = 0; k < 6; k++) { + val = ((cbp >> (5 - k)) & 1); + + if (k < 4) { +- int pred = vc1_coded_block_pred(&v->s, k, &coded_val); +- val = val ^ pred; ++ int pred = vc1_coded_block_pred(&v->s, k, &coded_val); ++ val = val ^ pred; + *coded_val = val; + } + cbp |= val << (5 - k); + +- vc1_decode_i_block(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2); ++ vc1_decode_i_block(v, s->block[k], k, val, (k < 4) ? v->codingset : v->codingset2); + +- s->dsp.vc1_inv_trans_8x8(s->block[k]); +- if(v->pq >= 9 && v->overlap) { +- for(j = 0; j < 64; j++) s->block[k][j] += 128; ++ if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(s->block[k]); ++ if (v->pq >= 9 && v->overlap) { ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[k][j] <<= 1; ++ s->dsp.put_signed_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); ++ } else { ++ if (v->rangeredfrm) ++ for (j = 0; j < 64; j++) ++ s->block[k][j] = (s->block[k][j] - 64) << 1; ++ s->dsp.put_pixels_clamped(s->block[k], dst[k], k & 4 ? s->uvlinesize : s->linesize); + } + } + +- vc1_put_block(v, s->block); +- if(v->pq >= 9 && v->overlap) { +- if(s->mb_x) { +- s->dsp.vc1_h_overlap(s->dest[0], s->linesize); +- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize); +- if(!(s->flags & CODEC_FLAG_GRAY)) { +- s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize); +- s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize); ++ if (v->pq >= 9 && v->overlap) { ++ if (s->mb_x) { ++ v->vc1dsp.vc1_h_overlap(s->dest[0], s->linesize); ++ v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize); ++ if (!(s->flags & CODEC_FLAG_GRAY)) { ++ v->vc1dsp.vc1_h_overlap(s->dest[1], s->uvlinesize); ++ v->vc1dsp.vc1_h_overlap(s->dest[2], s->uvlinesize); + } + } +- s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize); +- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); +- if(!s->first_slice_line) { +- s->dsp.vc1_v_overlap(s->dest[0], s->linesize); +- s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize); +- if(!(s->flags & CODEC_FLAG_GRAY)) { +- s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize); +- s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize); ++ v->vc1dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize); ++ v->vc1dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); ++ if (!s->first_slice_line) { ++ v->vc1dsp.vc1_v_overlap(s->dest[0], s->linesize); ++ v->vc1dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize); ++ if (!(s->flags & CODEC_FLAG_GRAY)) { ++ v->vc1dsp.vc1_v_overlap(s->dest[1], s->uvlinesize); ++ v->vc1dsp.vc1_v_overlap(s->dest[2], s->uvlinesize); + } + } +- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize); +- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); ++ v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize); ++ v->vc1dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); + } +- if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq); ++ if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); + +- if(get_bits_count(&s->gb) > v->bits) { +- ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); +- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); ++ if (get_bits_count(&s->gb) > v->bits) { ++ ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, ER_MB_ERROR); ++ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", ++ get_bits_count(&s->gb), v->bits); + return; + } + } + if (!v->s.loop_filter) + ff_draw_horiz_band(s, s->mb_y * 16, 16); + else if (s->mb_y) +- ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); ++ ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16); + + s->first_slice_line = 0; + } + if (v->s.loop_filter) +- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); +- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); ++ ff_draw_horiz_band(s, (s->mb_height - 1) * 16, 16); ++ ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, ER_MB_END); + } + + /** Decode blocks of I-frame for advanced profile + */ + static void vc1_decode_i_blocks_adv(VC1Context *v) + { +- int k, j; ++ int k; + MpegEncContext *s = &v->s; + int cbp, val; + uint8_t *coded_val; + int mb_pos; + int mquant = v->pq; + int mqdiff; +- int overlap; + GetBitContext *gb = &s->gb; + + /* select codingmode used for VLC tables selection */ +- switch(v->y_ac_table_index){ ++ switch (v->y_ac_table_index) { + case 0: + v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA; + break; +@@ -2729,7 +4603,7 @@ + break; + } + +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER; + break; +@@ -2741,90 +4615,78 @@ + break; + } + +- //do frame decode +- s->mb_x = s->mb_y = 0; +- s->mb_intra = 1; ++ // do frame decode ++ s->mb_x = s->mb_y = 0; ++ s->mb_intra = 1; + s->first_slice_line = 1; +- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { ++ s->mb_y = s->start_mb_y; ++ if (s->start_mb_y) { ++ s->mb_x = 0; ++ ff_init_block_index(s); ++ memset(&s->coded_block[s->block_index[0] - s->b8_stride], 0, ++ (1 + s->b8_stride) * sizeof(*s->coded_block)); ++ } ++ for (; s->mb_y < s->end_mb_y; s->mb_y++) { + s->mb_x = 0; + ff_init_block_index(s); +- for(;s->mb_x < s->mb_width; s->mb_x++) { ++ for (;s->mb_x < s->mb_width; s->mb_x++) { ++ DCTELEM (*block)[64] = v->block[v->cur_blk_idx]; + ff_update_block_index(s); +- s->dsp.clear_blocks(s->block[0]); ++ s->dsp.clear_blocks(block[0]); + mb_pos = s->mb_x + s->mb_y * s->mb_stride; +- s->current_picture.mb_type[mb_pos] = MB_TYPE_INTRA; +- s->current_picture.motion_val[1][s->block_index[0]][0] = 0; +- s->current_picture.motion_val[1][s->block_index[0]][1] = 0; ++ s->current_picture.f.mb_type[mb_pos + v->mb_off] = MB_TYPE_INTRA; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][0] = 0; ++ s->current_picture.f.motion_val[1][s->block_index[0] + v->blocks_off][1] = 0; + + // do actual MB decoding and displaying ++ if (v->fieldtx_is_raw) ++ v->fieldtx_plane[mb_pos] = get_bits1(&v->s.gb); + cbp = get_vlc2(&v->s.gb, ff_msmp4_mb_i_vlc.table, MB_INTRA_VLC_BITS, 2); +- if(v->acpred_is_raw) ++ if ( v->acpred_is_raw) + v->s.ac_pred = get_bits1(&v->s.gb); + else + v->s.ac_pred = v->acpred_plane[mb_pos]; + +- if(v->condover == CONDOVER_SELECT) { +- if(v->overflg_is_raw) +- overlap = get_bits1(&v->s.gb); +- else +- overlap = v->over_flags_plane[mb_pos]; +- } else +- overlap = (v->condover == CONDOVER_ALL); ++ if (v->condover == CONDOVER_SELECT && v->overflg_is_raw) ++ v->over_flags_plane[mb_pos] = get_bits1(&v->s.gb); + + GET_MQUANT(); + +- s->current_picture.qscale_table[mb_pos] = mquant; ++ s->current_picture.f.qscale_table[mb_pos] = mquant; + /* Set DC scale - y and c use the same */ + s->y_dc_scale = s->y_dc_scale_table[mquant]; + s->c_dc_scale = s->c_dc_scale_table[mquant]; + +- for(k = 0; k < 6; k++) { ++ for (k = 0; k < 6; k++) { + val = ((cbp >> (5 - k)) & 1); + + if (k < 4) { +- int pred = vc1_coded_block_pred(&v->s, k, &coded_val); +- val = val ^ pred; ++ int pred = vc1_coded_block_pred(&v->s, k, &coded_val); ++ val = val ^ pred; + *coded_val = val; + } + cbp |= val << (5 - k); + +- v->a_avail = !s->first_slice_line || (k==2 || k==3); +- v->c_avail = !!s->mb_x || (k==1 || k==3); ++ v->a_avail = !s->first_slice_line || (k == 2 || k == 3); ++ v->c_avail = !!s->mb_x || (k == 1 || k == 3); + +- vc1_decode_i_block_adv(v, s->block[k], k, val, (k<4)? v->codingset : v->codingset2, mquant); +- +- s->dsp.vc1_inv_trans_8x8(s->block[k]); +- for(j = 0; j < 64; j++) s->block[k][j] += 128; +- } +- +- vc1_put_block(v, s->block); +- if(overlap) { +- if(s->mb_x) { +- s->dsp.vc1_h_overlap(s->dest[0], s->linesize); +- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize, s->linesize); +- if(!(s->flags & CODEC_FLAG_GRAY)) { +- s->dsp.vc1_h_overlap(s->dest[1], s->uvlinesize); +- s->dsp.vc1_h_overlap(s->dest[2], s->uvlinesize); +- } +- } +- s->dsp.vc1_h_overlap(s->dest[0] + 8, s->linesize); +- s->dsp.vc1_h_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); +- if(!s->first_slice_line) { +- s->dsp.vc1_v_overlap(s->dest[0], s->linesize); +- s->dsp.vc1_v_overlap(s->dest[0] + 8, s->linesize); +- if(!(s->flags & CODEC_FLAG_GRAY)) { +- s->dsp.vc1_v_overlap(s->dest[1], s->uvlinesize); +- s->dsp.vc1_v_overlap(s->dest[2], s->uvlinesize); +- } +- } +- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize, s->linesize); +- s->dsp.vc1_v_overlap(s->dest[0] + 8 * s->linesize + 8, s->linesize); +- } +- if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq); ++ vc1_decode_i_block_adv(v, block[k], k, val, ++ (k < 4) ? v->codingset : v->codingset2, mquant); + +- if(get_bits_count(&s->gb) > v->bits) { +- ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); +- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", get_bits_count(&s->gb), v->bits); ++ if (k > 3 && (s->flags & CODEC_FLAG_GRAY)) ++ continue; ++ v->vc1dsp.vc1_inv_trans_8x8(block[k]); ++ } ++ ++ vc1_smooth_overlap_filter_iblk(v); ++ vc1_put_signed_blocks_clamped(v); ++ if (v->s.loop_filter) vc1_loop_filter_iblk_delayed(v, v->pq); ++ ++ if (get_bits_count(&s->gb) > v->bits) { ++ // TODO: may need modification to handle slice coding ++ ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); ++ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i\n", ++ get_bits_count(&s->gb), v->bits); + return; + } + } +@@ -2834,17 +4696,29 @@ + ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); + s->first_slice_line = 0; + } ++ ++ /* raw bottom MB row */ ++ s->mb_x = 0; ++ ff_init_block_index(s); ++ for (;s->mb_x < s->mb_width; s->mb_x++) { ++ ff_update_block_index(s); ++ vc1_put_signed_blocks_clamped(v); ++ if (v->s.loop_filter) ++ vc1_loop_filter_iblk_delayed(v, v->pq); ++ } + if (v->s.loop_filter) +- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); +- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); ++ ff_draw_horiz_band(s, (s->end_mb_y-1)*16, 16); ++ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, ++ (s->end_mb_y << v->field_mode) - 1, ER_MB_END); + } + + static void vc1_decode_p_blocks(VC1Context *v) + { + MpegEncContext *s = &v->s; ++ int apply_loop_filter; + + /* select codingmode used for VLC tables selection */ +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA; + break; +@@ -2856,7 +4730,7 @@ + break; + } + +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER; + break; +@@ -2868,26 +4742,49 @@ + break; + } + ++ apply_loop_filter = s->loop_filter && !(s->avctx->skip_loop_filter >= AVDISCARD_NONKEY); + s->first_slice_line = 1; + memset(v->cbp_base, 0, sizeof(v->cbp_base[0])*2*s->mb_stride); +- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { ++ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { + s->mb_x = 0; + ff_init_block_index(s); +- for(; s->mb_x < s->mb_width; s->mb_x++) { ++ for (; s->mb_x < s->mb_width; s->mb_x++) { + ff_update_block_index(s); + +- vc1_decode_p_mb(v); +- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { +- ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); +- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); ++ if (v->fcm == ILACE_FIELD) ++ vc1_decode_p_mb_intfi(v); ++ else if (v->fcm == ILACE_FRAME) ++ vc1_decode_p_mb_intfr(v); ++ else vc1_decode_p_mb(v); ++ if (s->mb_y != s->start_mb_y && apply_loop_filter && v->fcm == PROGRESSIVE) ++ vc1_apply_p_loop_filter(v); ++ if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { ++ // TODO: may need modification to handle slice coding ++ ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); ++ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", ++ get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y); + return; + } + } +- memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0])*s->mb_stride); +- ff_draw_horiz_band(s, s->mb_y * 16, 16); ++ memmove(v->cbp_base, v->cbp, sizeof(v->cbp_base[0]) * s->mb_stride); ++ memmove(v->ttblk_base, v->ttblk, sizeof(v->ttblk_base[0]) * s->mb_stride); ++ memmove(v->is_intra_base, v->is_intra, sizeof(v->is_intra_base[0]) * s->mb_stride); ++ memmove(v->luma_mv_base, v->luma_mv, sizeof(v->luma_mv_base[0]) * s->mb_stride); ++ if (s->mb_y != s->start_mb_y) ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16); + s->first_slice_line = 0; + } +- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); ++ if (apply_loop_filter) { ++ s->mb_x = 0; ++ ff_init_block_index(s); ++ for (; s->mb_x < s->mb_width; s->mb_x++) { ++ ff_update_block_index(s); ++ vc1_apply_p_loop_filter(v); ++ } ++ } ++ if (s->end_mb_y >= s->start_mb_y) ++ ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16); ++ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, ++ (s->end_mb_y << v->field_mode) - 1, ER_MB_END); + } + + static void vc1_decode_b_blocks(VC1Context *v) +@@ -2895,7 +4792,7 @@ + MpegEncContext *s = &v->s; + + /* select codingmode used for VLC tables selection */ +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset = (v->pqindex <= 8) ? CS_HIGH_RATE_INTRA : CS_LOW_MOT_INTRA; + break; +@@ -2907,7 +4804,7 @@ + break; + } + +- switch(v->c_ac_table_index){ ++ switch (v->c_ac_table_index) { + case 0: + v->codingset2 = (v->pqindex <= 8) ? CS_HIGH_RATE_INTER : CS_LOW_MOT_INTER; + break; +@@ -2920,84 +4817,432 @@ + } + + s->first_slice_line = 1; +- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { ++ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { + s->mb_x = 0; + ff_init_block_index(s); +- for(; s->mb_x < s->mb_width; s->mb_x++) { ++ for (; s->mb_x < s->mb_width; s->mb_x++) { + ff_update_block_index(s); + +- vc1_decode_b_mb(v); +- if(get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { +- ff_er_add_slice(s, 0, 0, s->mb_x, s->mb_y, (AC_END|DC_END|MV_END)); +- av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", get_bits_count(&s->gb), v->bits,s->mb_x,s->mb_y); ++ if (v->fcm == ILACE_FIELD) ++ vc1_decode_b_mb_intfi(v); ++ else ++ vc1_decode_b_mb(v); ++ if (get_bits_count(&s->gb) > v->bits || get_bits_count(&s->gb) < 0) { ++ // TODO: may need modification to handle slice coding ++ ff_er_add_slice(s, 0, s->start_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR); ++ av_log(s->avctx, AV_LOG_ERROR, "Bits overconsumption: %i > %i at %ix%i\n", ++ get_bits_count(&s->gb), v->bits, s->mb_x, s->mb_y); + return; + } +- if(v->s.loop_filter) vc1_loop_filter_iblk(s, v->pq); ++ if (v->s.loop_filter) vc1_loop_filter_iblk(v, v->pq); + } + if (!v->s.loop_filter) + ff_draw_horiz_band(s, s->mb_y * 16, 16); + else if (s->mb_y) +- ff_draw_horiz_band(s, (s->mb_y-1) * 16, 16); ++ ff_draw_horiz_band(s, (s->mb_y - 1) * 16, 16); + s->first_slice_line = 0; + } + if (v->s.loop_filter) +- ff_draw_horiz_band(s, (s->mb_height-1)*16, 16); +- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); ++ ff_draw_horiz_band(s, (s->end_mb_y - 1) * 16, 16); ++ ff_er_add_slice(s, 0, s->start_mb_y << v->field_mode, s->mb_width - 1, ++ (s->end_mb_y << v->field_mode) - 1, ER_MB_END); + } + + static void vc1_decode_skip_blocks(VC1Context *v) + { + MpegEncContext *s = &v->s; + +- ff_er_add_slice(s, 0, 0, s->mb_width - 1, s->mb_height - 1, (AC_END|DC_END|MV_END)); ++ ff_er_add_slice(s, 0, s->start_mb_y, s->mb_width - 1, s->end_mb_y - 1, ER_MB_END); + s->first_slice_line = 1; +- for(s->mb_y = 0; s->mb_y < s->mb_height; s->mb_y++) { ++ for (s->mb_y = s->start_mb_y; s->mb_y < s->end_mb_y; s->mb_y++) { + s->mb_x = 0; + ff_init_block_index(s); + ff_update_block_index(s); +- memcpy(s->dest[0], s->last_picture.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16); +- memcpy(s->dest[1], s->last_picture.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); +- memcpy(s->dest[2], s->last_picture.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); ++ memcpy(s->dest[0], s->last_picture.f.data[0] + s->mb_y * 16 * s->linesize, s->linesize * 16); ++ memcpy(s->dest[1], s->last_picture.f.data[1] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); ++ memcpy(s->dest[2], s->last_picture.f.data[2] + s->mb_y * 8 * s->uvlinesize, s->uvlinesize * 8); + ff_draw_horiz_band(s, s->mb_y * 16, 16); + s->first_slice_line = 0; + } +- s->pict_type = FF_P_TYPE; ++ s->pict_type = AV_PICTURE_TYPE_P; + } + + static void vc1_decode_blocks(VC1Context *v) + { + + v->s.esc3_level_length = 0; +- if(v->x8_type){ +- ff_intrax8_decode_picture(&v->x8, 2*v->pq+v->halfpq, v->pq*(!v->pquantizer) ); +- }else{ +- +- switch(v->s.pict_type) { +- case FF_I_TYPE: +- if(v->profile == PROFILE_ADVANCED) ++ if (v->x8_type) { ++ ff_intrax8_decode_picture(&v->x8, 2*v->pq + v->halfpq, v->pq * !v->pquantizer); ++ } else { ++ v->cur_blk_idx = 0; ++ v->left_blk_idx = -1; ++ v->topleft_blk_idx = 1; ++ v->top_blk_idx = 2; ++ switch (v->s.pict_type) { ++ case AV_PICTURE_TYPE_I: ++ if (v->profile == PROFILE_ADVANCED) + vc1_decode_i_blocks_adv(v); + else + vc1_decode_i_blocks(v); + break; +- case FF_P_TYPE: +- if(v->p_frame_skipped) ++ case AV_PICTURE_TYPE_P: ++ if (v->p_frame_skipped) + vc1_decode_skip_blocks(v); + else + vc1_decode_p_blocks(v); + break; +- case FF_B_TYPE: +- if(v->bi_type){ +- if(v->profile == PROFILE_ADVANCED) ++ case AV_PICTURE_TYPE_B: ++ if (v->bi_type) { ++ if (v->profile == PROFILE_ADVANCED) + vc1_decode_i_blocks_adv(v); + else + vc1_decode_i_blocks(v); +- }else ++ } else + vc1_decode_b_blocks(v); + break; + } + } + } + ++#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER ++ ++typedef struct { ++ /** ++ * Transform coefficients for both sprites in 16.16 fixed point format, ++ * in the order they appear in the bitstream: ++ * x scale ++ * rotation 1 (unused) ++ * x offset ++ * rotation 2 (unused) ++ * y scale ++ * y offset ++ * alpha ++ */ ++ int coefs[2][7]; ++ ++ int effect_type, effect_flag; ++ int effect_pcount1, effect_pcount2; ///< amount of effect parameters stored in effect_params ++ int effect_params1[15], effect_params2[10]; ///< effect parameters in 16.16 fixed point format ++} SpriteData; ++ ++static inline int get_fp_val(GetBitContext* gb) ++{ ++ return (get_bits_long(gb, 30) - (1 << 29)) << 1; ++} ++ ++static void vc1_sprite_parse_transform(GetBitContext* gb, int c[7]) ++{ ++ c[1] = c[3] = 0; ++ ++ switch (get_bits(gb, 2)) { ++ case 0: ++ c[0] = 1 << 16; ++ c[2] = get_fp_val(gb); ++ c[4] = 1 << 16; ++ break; ++ case 1: ++ c[0] = c[4] = get_fp_val(gb); ++ c[2] = get_fp_val(gb); ++ break; ++ case 2: ++ c[0] = get_fp_val(gb); ++ c[2] = get_fp_val(gb); ++ c[4] = get_fp_val(gb); ++ break; ++ case 3: ++ c[0] = get_fp_val(gb); ++ c[1] = get_fp_val(gb); ++ c[2] = get_fp_val(gb); ++ c[3] = get_fp_val(gb); ++ c[4] = get_fp_val(gb); ++ break; ++ } ++ c[5] = get_fp_val(gb); ++ if (get_bits1(gb)) ++ c[6] = get_fp_val(gb); ++ else ++ c[6] = 1 << 16; ++} ++ ++static void vc1_parse_sprites(VC1Context *v, GetBitContext* gb, SpriteData* sd) ++{ ++ AVCodecContext *avctx = v->s.avctx; ++ int sprite, i; ++ ++ for (sprite = 0; sprite <= v->two_sprites; sprite++) { ++ vc1_sprite_parse_transform(gb, sd->coefs[sprite]); ++ if (sd->coefs[sprite][1] || sd->coefs[sprite][3]) ++ av_log_ask_for_sample(avctx, "Rotation coefficients are not zero"); ++ av_log(avctx, AV_LOG_DEBUG, sprite ? "S2:" : "S1:"); ++ for (i = 0; i < 7; i++) ++ av_log(avctx, AV_LOG_DEBUG, " %d.%.3d", ++ sd->coefs[sprite][i] / (1<<16), ++ (abs(sd->coefs[sprite][i]) & 0xFFFF) * 1000 / (1 << 16)); ++ av_log(avctx, AV_LOG_DEBUG, "\n"); ++ } ++ ++ skip_bits(gb, 2); ++ if (sd->effect_type = get_bits_long(gb, 30)) { ++ switch (sd->effect_pcount1 = get_bits(gb, 4)) { ++ case 7: ++ vc1_sprite_parse_transform(gb, sd->effect_params1); ++ break; ++ case 14: ++ vc1_sprite_parse_transform(gb, sd->effect_params1); ++ vc1_sprite_parse_transform(gb, sd->effect_params1 + 7); ++ break; ++ default: ++ for (i = 0; i < sd->effect_pcount1; i++) ++ sd->effect_params1[i] = get_fp_val(gb); ++ } ++ if (sd->effect_type != 13 || sd->effect_params1[0] != sd->coefs[0][6]) { ++ // effect 13 is simple alpha blending and matches the opacity above ++ av_log(avctx, AV_LOG_DEBUG, "Effect: %d; params: ", sd->effect_type); ++ for (i = 0; i < sd->effect_pcount1; i++) ++ av_log(avctx, AV_LOG_DEBUG, " %d.%.2d", ++ sd->effect_params1[i] / (1 << 16), ++ (abs(sd->effect_params1[i]) & 0xFFFF) * 1000 / (1 << 16)); ++ av_log(avctx, AV_LOG_DEBUG, "\n"); ++ } ++ ++ sd->effect_pcount2 = get_bits(gb, 16); ++ if (sd->effect_pcount2 > 10) { ++ av_log(avctx, AV_LOG_ERROR, "Too many effect parameters\n"); ++ return; ++ } else if (sd->effect_pcount2) { ++ i = -1; ++ av_log(avctx, AV_LOG_DEBUG, "Effect params 2: "); ++ while (++i < sd->effect_pcount2) { ++ sd->effect_params2[i] = get_fp_val(gb); ++ av_log(avctx, AV_LOG_DEBUG, " %d.%.2d", ++ sd->effect_params2[i] / (1 << 16), ++ (abs(sd->effect_params2[i]) & 0xFFFF) * 1000 / (1 << 16)); ++ } ++ av_log(avctx, AV_LOG_DEBUG, "\n"); ++ } ++ } ++ if (sd->effect_flag = get_bits1(gb)) ++ av_log(avctx, AV_LOG_DEBUG, "Effect flag set\n"); ++ ++ if (get_bits_count(gb) >= gb->size_in_bits + ++ (avctx->codec_id == CODEC_ID_WMV3IMAGE ? 64 : 0)) ++ av_log(avctx, AV_LOG_ERROR, "Buffer overrun\n"); ++ if (get_bits_count(gb) < gb->size_in_bits - 8) ++ av_log(avctx, AV_LOG_WARNING, "Buffer not fully read\n"); ++} ++ ++static void vc1_draw_sprites(VC1Context *v, SpriteData* sd) ++{ ++ int i, plane, row, sprite; ++ int sr_cache[2][2] = { { -1, -1 }, { -1, -1 } }; ++ uint8_t* src_h[2][2]; ++ int xoff[2], xadv[2], yoff[2], yadv[2], alpha; ++ int ysub[2]; ++ MpegEncContext *s = &v->s; ++ ++ for (i = 0; i < 2; i++) { ++ xoff[i] = av_clip(sd->coefs[i][2], 0, v->sprite_width-1 << 16); ++ xadv[i] = sd->coefs[i][0]; ++ if (xadv[i] != 1<<16 || (v->sprite_width << 16) - (v->output_width << 16) - xoff[i]) ++ xadv[i] = av_clip(xadv[i], 0, ((v->sprite_width<<16) - xoff[i] - 1) / v->output_width); ++ ++ yoff[i] = av_clip(sd->coefs[i][5], 0, v->sprite_height-1 << 16); ++ yadv[i] = av_clip(sd->coefs[i][4], 0, ((v->sprite_height << 16) - yoff[i]) / v->output_height); ++ } ++ alpha = av_clip(sd->coefs[1][6], 0, (1<<16) - 1); ++ ++ for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) { ++ int width = v->output_width>>!!plane; ++ ++ for (row = 0; row < v->output_height>>!!plane; row++) { ++ uint8_t *dst = v->sprite_output_frame.data[plane] + ++ v->sprite_output_frame.linesize[plane] * row; ++ ++ for (sprite = 0; sprite <= v->two_sprites; sprite++) { ++ uint8_t *iplane = s->current_picture.f.data[plane]; ++ int iline = s->current_picture.f.linesize[plane]; ++ int ycoord = yoff[sprite] + yadv[sprite] * row; ++ int yline = ycoord >> 16; ++ ysub[sprite] = ycoord & 0xFFFF; ++ if (sprite) { ++ iplane = s->last_picture.f.data[plane]; ++ iline = s->last_picture.f.linesize[plane]; ++ } ++ if (!(xoff[sprite] & 0xFFFF) && xadv[sprite] == 1 << 16) { ++ src_h[sprite][0] = iplane + (xoff[sprite] >> 16) + yline * iline; ++ if (ysub[sprite]) ++ src_h[sprite][1] = iplane + (xoff[sprite] >> 16) + (yline + 1) * iline; ++ } else { ++ if (sr_cache[sprite][0] != yline) { ++ if (sr_cache[sprite][1] == yline) { ++ FFSWAP(uint8_t*, v->sr_rows[sprite][0], v->sr_rows[sprite][1]); ++ FFSWAP(int, sr_cache[sprite][0], sr_cache[sprite][1]); ++ } else { ++ v->vc1dsp.sprite_h(v->sr_rows[sprite][0], iplane + yline * iline, xoff[sprite], xadv[sprite], width); ++ sr_cache[sprite][0] = yline; ++ } ++ } ++ if (ysub[sprite] && sr_cache[sprite][1] != yline + 1) { ++ v->vc1dsp.sprite_h(v->sr_rows[sprite][1], iplane + (yline + 1) * iline, xoff[sprite], xadv[sprite], width); ++ sr_cache[sprite][1] = yline + 1; ++ } ++ src_h[sprite][0] = v->sr_rows[sprite][0]; ++ src_h[sprite][1] = v->sr_rows[sprite][1]; ++ } ++ } ++ ++ if (!v->two_sprites) { ++ if (ysub[0]) { ++ v->vc1dsp.sprite_v_single(dst, src_h[0][0], src_h[0][1], ysub[0], width); ++ } else { ++ memcpy(dst, src_h[0][0], width); ++ } ++ } else { ++ if (ysub[0] && ysub[1]) { ++ v->vc1dsp.sprite_v_double_twoscale(dst, src_h[0][0], src_h[0][1], ysub[0], ++ src_h[1][0], src_h[1][1], ysub[1], alpha, width); ++ } else if (ysub[0]) { ++ v->vc1dsp.sprite_v_double_onescale(dst, src_h[0][0], src_h[0][1], ysub[0], ++ src_h[1][0], alpha, width); ++ } else if (ysub[1]) { ++ v->vc1dsp.sprite_v_double_onescale(dst, src_h[1][0], src_h[1][1], ysub[1], ++ src_h[0][0], (1<<16)-1-alpha, width); ++ } else { ++ v->vc1dsp.sprite_v_double_noscale(dst, src_h[0][0], src_h[1][0], alpha, width); ++ } ++ } ++ } ++ ++ if (!plane) { ++ for (i = 0; i < 2; i++) { ++ xoff[i] >>= 1; ++ yoff[i] >>= 1; ++ } ++ } ++ ++ } ++} ++ ++ ++static int vc1_decode_sprites(VC1Context *v, GetBitContext* gb) ++{ ++ MpegEncContext *s = &v->s; ++ AVCodecContext *avctx = s->avctx; ++ SpriteData sd; ++ ++ vc1_parse_sprites(v, gb, &sd); ++ ++ if (!s->current_picture.f.data[0]) { ++ av_log(avctx, AV_LOG_ERROR, "Got no sprites\n"); ++ return -1; ++ } ++ ++ if (v->two_sprites && (!s->last_picture_ptr || !s->last_picture.f.data[0])) { ++ av_log(avctx, AV_LOG_WARNING, "Need two sprites, only got one\n"); ++ v->two_sprites = 0; ++ } ++ ++ if (v->sprite_output_frame.data[0]) ++ avctx->release_buffer(avctx, &v->sprite_output_frame); ++ ++ v->sprite_output_frame.buffer_hints = FF_BUFFER_HINTS_VALID; ++ v->sprite_output_frame.reference = 0; ++ if (avctx->get_buffer(avctx, &v->sprite_output_frame) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return -1; ++ } ++ ++ vc1_draw_sprites(v, &sd); ++ ++ return 0; ++} ++ ++static void vc1_sprite_flush(AVCodecContext *avctx) ++{ ++ VC1Context *v = avctx->priv_data; ++ MpegEncContext *s = &v->s; ++ AVFrame *f = &s->current_picture.f; ++ int plane, i; ++ ++ /* Windows Media Image codecs have a convergence interval of two keyframes. ++ Since we can't enforce it, clear to black the missing sprite. This is ++ wrong but it looks better than doing nothing. */ ++ ++ if (f->data[0]) ++ for (plane = 0; plane < (s->flags&CODEC_FLAG_GRAY ? 1 : 3); plane++) ++ for (i = 0; i < v->sprite_height>>!!plane; i++) ++ memset(f->data[plane] + i * f->linesize[plane], ++ plane ? 128 : 0, f->linesize[plane]); ++} ++ ++#endif ++ ++static av_cold int vc1_decode_init_alloc_tables(VC1Context *v) ++{ ++ MpegEncContext *s = &v->s; ++ int i; ++ ++ /* Allocate mb bitplanes */ ++ v->mv_type_mb_plane = av_malloc (s->mb_stride * s->mb_height); ++ v->direct_mb_plane = av_malloc (s->mb_stride * s->mb_height); ++ v->forward_mb_plane = av_malloc (s->mb_stride * s->mb_height); ++ v->fieldtx_plane = av_mallocz(s->mb_stride * s->mb_height); ++ v->acpred_plane = av_malloc (s->mb_stride * s->mb_height); ++ v->over_flags_plane = av_malloc (s->mb_stride * s->mb_height); ++ ++ v->n_allocated_blks = s->mb_width + 2; ++ v->block = av_malloc(sizeof(*v->block) * v->n_allocated_blks); ++ v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride); ++ v->cbp = v->cbp_base + s->mb_stride; ++ v->ttblk_base = av_malloc(sizeof(v->ttblk_base[0]) * 2 * s->mb_stride); ++ v->ttblk = v->ttblk_base + s->mb_stride; ++ v->is_intra_base = av_mallocz(sizeof(v->is_intra_base[0]) * 2 * s->mb_stride); ++ v->is_intra = v->is_intra_base + s->mb_stride; ++ v->luma_mv_base = av_malloc(sizeof(v->luma_mv_base[0]) * 2 * s->mb_stride); ++ v->luma_mv = v->luma_mv_base + s->mb_stride; ++ ++ /* allocate block type info in that way so it could be used with s->block_index[] */ ++ v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); ++ v->mb_type[0] = v->mb_type_base + s->b8_stride + 1; ++ v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1; ++ v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1); ++ ++ /* allocate memory to store block level MV info */ ++ v->blk_mv_type_base = av_mallocz( s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); ++ v->blk_mv_type = v->blk_mv_type_base + s->b8_stride + 1; ++ v->mv_f_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); ++ v->mv_f[0] = v->mv_f_base + s->b8_stride + 1; ++ v->mv_f[1] = v->mv_f[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); ++ v->mv_f_last_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); ++ v->mv_f_last[0] = v->mv_f_last_base + s->b8_stride + 1; ++ v->mv_f_last[1] = v->mv_f_last[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); ++ v->mv_f_next_base = av_mallocz(2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); ++ v->mv_f_next[0] = v->mv_f_next_base + s->b8_stride + 1; ++ v->mv_f_next[1] = v->mv_f_next[0] + (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); ++ ++ /* Init coded blocks info */ ++ if (v->profile == PROFILE_ADVANCED) { ++// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0) ++// return -1; ++// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0) ++// return -1; ++ } ++ ++ ff_intrax8_common_init(&v->x8,s); ++ ++ if (s->avctx->codec_id == CODEC_ID_WMV3IMAGE || s->avctx->codec_id == CODEC_ID_VC1IMAGE) { ++ for (i = 0; i < 4; i++) ++ if (!(v->sr_rows[i >> 1][i & 1] = av_malloc(v->output_width))) return -1; ++ } ++ ++ if (!v->mv_type_mb_plane || !v->direct_mb_plane || !v->acpred_plane || !v->over_flags_plane || ++ !v->block || !v->cbp_base || !v->ttblk_base || !v->is_intra_base || !v->luma_mv_base || ++ !v->mb_type_base) ++ return -1; ++ ++ return 0; ++} ++ + /** Initialize a VC1/WMV3 decoder + * @todo TODO: Handle VC-1 IDUs (Transport level?) + * @todo TODO: Decypher remaining bits in extra_data +@@ -3007,8 +5252,14 @@ + VC1Context *v = avctx->priv_data; + MpegEncContext *s = &v->s; + GetBitContext gb; ++ int i; ++ ++ /* save the container output size for WMImage */ ++ v->output_width = avctx->width; ++ v->output_height = avctx->height; + +- if (!avctx->extradata_size || !avctx->extradata) return -1; ++ if (!avctx->extradata_size || !avctx->extradata) ++ return -1; + if (!(avctx->flags & CODEC_FLAG_GRAY)) + avctx->pix_fmt = avctx->get_format(avctx, avctx->codec->pix_fmts); + else +@@ -3016,20 +5267,17 @@ + avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt); + v->s.avctx = avctx; + avctx->flags |= CODEC_FLAG_EMU_EDGE; +- v->s.flags |= CODEC_FLAG_EMU_EDGE; ++ v->s.flags |= CODEC_FLAG_EMU_EDGE; + +- if(avctx->idct_algo==FF_IDCT_AUTO){ +- avctx->idct_algo=FF_IDCT_WMV2; ++ if (avctx->idct_algo == FF_IDCT_AUTO) { ++ avctx->idct_algo = FF_IDCT_WMV2; + } + +- if(ff_msmpeg4_decode_init(avctx) < 0) ++ if (ff_vc1_init_common(v) < 0) + return -1; +- if (vc1_init_common(v) < 0) return -1; ++ ff_vc1dsp_init(&v->vc1dsp); + +- avctx->coded_width = avctx->width; +- avctx->coded_height = avctx->height; +- if (avctx->codec_id == CODEC_ID_WMV3) +- { ++ if (avctx->codec_id == CODEC_ID_WMV3 || avctx->codec_id == CODEC_ID_WMV3IMAGE) { + int count = 0; + + // looks like WMV3 has a sequence header stored in the extradata +@@ -3043,16 +5291,13 @@ + return -1; + + count = avctx->extradata_size*8 - get_bits_count(&gb); +- if (count>0) +- { ++ if (count > 0) { + av_log(avctx, AV_LOG_INFO, "Extra data: %i bits left, value: %X\n", + count, get_bits(&gb, count)); +- } +- else if (count < 0) +- { ++ } else if (count < 0) { + av_log(avctx, AV_LOG_INFO, "Read %i bits in overflow\n", -count); + } +- } else { // VC1/WVC1 ++ } else { // VC1/WVC1/WVP2 + const uint8_t *start = avctx->extradata; + uint8_t *end = avctx->extradata + avctx->extradata_size; + const uint8_t *next; +@@ -3060,30 +5305,31 @@ + uint8_t *buf2 = NULL; + int seq_initialized = 0, ep_initialized = 0; + +- if(avctx->extradata_size < 16) { ++ if (avctx->extradata_size < 16) { + av_log(avctx, AV_LOG_ERROR, "Extradata size too small: %i\n", avctx->extradata_size); + return -1; + } + +- buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ buf2 = av_mallocz(avctx->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + start = find_next_marker(start, end); // in WVC1 extradata first byte is its size, but can be 0 in mkv +- next = start; +- for(; next < end; start = next){ ++ next = start; ++ for (; next < end; start = next) { + next = find_next_marker(start + 4, end); + size = next - start - 4; +- if(size <= 0) continue; ++ if (size <= 0) ++ continue; + buf2_size = vc1_unescape_buffer(start + 4, size, buf2); + init_get_bits(&gb, buf2, buf2_size * 8); +- switch(AV_RB32(start)){ ++ switch (AV_RB32(start)) { + case VC1_CODE_SEQHDR: +- if(vc1_decode_sequence_header(avctx, v, &gb) < 0){ ++ if (vc1_decode_sequence_header(avctx, v, &gb) < 0) { + av_free(buf2); + return -1; + } + seq_initialized = 1; + break; + case VC1_CODE_ENTRYPOINT: +- if(vc1_decode_entry_point(avctx, v, &gb) < 0){ ++ if (vc1_decode_entry_point(avctx, v, &gb) < 0) { + av_free(buf2); + return -1; + } +@@ -3092,42 +5338,88 @@ + } + } + av_free(buf2); +- if(!seq_initialized || !ep_initialized){ ++ if (!seq_initialized || !ep_initialized) { + av_log(avctx, AV_LOG_ERROR, "Incomplete extradata\n"); + return -1; + } ++ v->res_sprite = (avctx->codec_tag == MKTAG('W','V','P','2')); + } +- avctx->has_b_frames= !!(avctx->max_b_frames); +- s->low_delay = !avctx->has_b_frames; +- +- s->mb_width = (avctx->coded_width+15)>>4; +- s->mb_height = (avctx->coded_height+15)>>4; + +- /* Allocate mb bitplanes */ +- v->mv_type_mb_plane = av_malloc(s->mb_stride * s->mb_height); +- v->direct_mb_plane = av_malloc(s->mb_stride * s->mb_height); +- v->acpred_plane = av_malloc(s->mb_stride * s->mb_height); +- v->over_flags_plane = av_malloc(s->mb_stride * s->mb_height); ++ avctx->profile = v->profile; ++ if (v->profile == PROFILE_ADVANCED) ++ avctx->level = v->level; + +- v->cbp_base = av_malloc(sizeof(v->cbp_base[0]) * 2 * s->mb_stride); +- v->cbp = v->cbp_base + s->mb_stride; ++ avctx->has_b_frames = !!avctx->max_b_frames; + +- /* allocate block type info in that way so it could be used with s->block_index[] */ +- v->mb_type_base = av_malloc(s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2); +- v->mb_type[0] = v->mb_type_base + s->b8_stride + 1; +- v->mb_type[1] = v->mb_type_base + s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride + 1; +- v->mb_type[2] = v->mb_type[1] + s->mb_stride * (s->mb_height + 1); ++ s->mb_width = (avctx->coded_width + 15) >> 4; ++ s->mb_height = (avctx->coded_height + 15) >> 4; + +- /* Init coded blocks info */ +- if (v->profile == PROFILE_ADVANCED) +- { +-// if (alloc_bitplane(&v->over_flags_plane, s->mb_width, s->mb_height) < 0) +-// return -1; +-// if (alloc_bitplane(&v->ac_pred_plane, s->mb_width, s->mb_height) < 0) +-// return -1; ++ if (v->profile == PROFILE_ADVANCED || v->res_fasttx) { ++ for (i = 0; i < 64; i++) { ++#define transpose(x) ((x >> 3) | ((x & 7) << 3)) ++ v->zz_8x8[0][i] = transpose(wmv1_scantable[0][i]); ++ v->zz_8x8[1][i] = transpose(wmv1_scantable[1][i]); ++ v->zz_8x8[2][i] = transpose(wmv1_scantable[2][i]); ++ v->zz_8x8[3][i] = transpose(wmv1_scantable[3][i]); ++ v->zzi_8x8[i] = transpose(ff_vc1_adv_interlaced_8x8_zz[i]); ++ } ++ v->left_blk_sh = 0; ++ v->top_blk_sh = 3; ++ } else { ++ memcpy(v->zz_8x8, wmv1_scantable, 4*64); ++ v->left_blk_sh = 3; ++ v->top_blk_sh = 0; ++ } ++ ++ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { ++ v->sprite_width = avctx->coded_width; ++ v->sprite_height = avctx->coded_height; ++ ++ avctx->coded_width = avctx->width = v->output_width; ++ avctx->coded_height = avctx->height = v->output_height; ++ ++ // prevent 16.16 overflows ++ if (v->sprite_width > 1 << 14 || ++ v->sprite_height > 1 << 14 || ++ v->output_width > 1 << 14 || ++ v->output_height > 1 << 14) return -1; + } ++ return 0; ++} + +- ff_intrax8_common_init(&v->x8,s); ++/** Close a VC1/WMV3 decoder ++ * @warning Initial try at using MpegEncContext stuff ++ */ ++static av_cold int vc1_decode_end(AVCodecContext *avctx) ++{ ++ VC1Context *v = avctx->priv_data; ++ int i; ++ ++ if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) ++ && v->sprite_output_frame.data[0]) ++ avctx->release_buffer(avctx, &v->sprite_output_frame); ++ for (i = 0; i < 4; i++) ++ av_freep(&v->sr_rows[i >> 1][i & 1]); ++ av_freep(&v->hrd_rate); ++ av_freep(&v->hrd_buffer); ++ MPV_common_end(&v->s); ++ av_freep(&v->mv_type_mb_plane); ++ av_freep(&v->direct_mb_plane); ++ av_freep(&v->forward_mb_plane); ++ av_freep(&v->fieldtx_plane); ++ av_freep(&v->acpred_plane); ++ av_freep(&v->over_flags_plane); ++ av_freep(&v->mb_type_base); ++ av_freep(&v->blk_mv_type_base); ++ av_freep(&v->mv_f_base); ++ av_freep(&v->mv_f_last_base); ++ av_freep(&v->mv_f_next_base); ++ av_freep(&v->block); ++ av_freep(&v->cbp_base); ++ av_freep(&v->ttblk_base); ++ av_freep(&v->is_intra_base); // FIXME use v->mb_type[] ++ av_freep(&v->luma_mv_base); ++ ff_intrax8_common_end(&v->x8); + return 0; + } + +@@ -3135,24 +5427,32 @@ + /** Decode a VC1/WMV3 frame + * @todo TODO: Handle VC-1 IDUs (Transport level?) + */ +-static int vc1_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int vc1_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; ++ int buf_size = avpkt->size, n_slices = 0, i; + VC1Context *v = avctx->priv_data; + MpegEncContext *s = &v->s; + AVFrame *pict = data; + uint8_t *buf2 = NULL; + const uint8_t *buf_start = buf; ++ int mb_height, n_slices1=-1; ++ struct { ++ uint8_t *buf; ++ GetBitContext gb; ++ int mby_start; ++ } *slices = NULL, *tmp; ++ ++ if(s->flags & CODEC_FLAG_LOW_DELAY) ++ s->low_delay = 1; + + /* no supplementary picture */ +- if (buf_size == 0) { ++ if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == VC1_CODE_ENDOFSEQ)) { + /* special case for last picture */ +- if (s->low_delay==0 && s->next_picture_ptr) { +- *pict= *(AVFrame*)s->next_picture_ptr; +- s->next_picture_ptr= NULL; ++ if (s->low_delay == 0 && s->next_picture_ptr) { ++ *pict = *(AVFrame*)s->next_picture_ptr; ++ s->next_picture_ptr = NULL; + + *data_size = sizeof(AVFrame); + } +@@ -3160,14 +5460,7 @@ + return 0; + } + +- /* We need to set current_picture_ptr before reading the header, +- * otherwise we cannot store anything in there. */ +- if(s->current_picture_ptr==NULL || s->current_picture_ptr->data[0]){ +- int i= ff_find_unused_picture(s, 0); +- s->current_picture_ptr= &s->picture[i]; +- } +- +- if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU){ ++ if (s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) { + if (v->profile < PROFILE_ADVANCED) + avctx->pix_fmt = PIX_FMT_VDPAU_WMV3; + else +@@ -3175,238 +5468,421 @@ + } + + //for advanced profile we may need to parse and unescape data +- if (avctx->codec_id == CODEC_ID_VC1) { ++ if (avctx->codec_id == CODEC_ID_VC1 || avctx->codec_id == CODEC_ID_VC1IMAGE) { + int buf_size2 = 0; + buf2 = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); + +- if(IS_MARKER(AV_RB32(buf))){ /* frame starts with marker and needs to be parsed */ ++ if (IS_MARKER(AV_RB32(buf))) { /* frame starts with marker and needs to be parsed */ + const uint8_t *start, *end, *next; + int size; + + next = buf; +- for(start = buf, end = buf + buf_size; next < end; start = next){ ++ for (start = buf, end = buf + buf_size; next < end; start = next) { + next = find_next_marker(start + 4, end); + size = next - start - 4; +- if(size <= 0) continue; +- switch(AV_RB32(start)){ ++ if (size <= 0) continue; ++ switch (AV_RB32(start)) { + case VC1_CODE_FRAME: + if (avctx->hwaccel || + s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + buf_start = start; + buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); + break; ++ case VC1_CODE_FIELD: { ++ int buf_size3; ++ slices = av_realloc(slices, sizeof(*slices) * (n_slices+1)); ++ if (!slices) ++ goto err; ++ slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!slices[n_slices].buf) ++ goto err; ++ buf_size3 = vc1_unescape_buffer(start + 4, size, ++ slices[n_slices].buf); ++ init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, ++ buf_size3 << 3); ++ /* assuming that the field marker is at the exact middle, ++ hope it's correct */ ++ slices[n_slices].mby_start = s->mb_height >> 1; ++ n_slices1 = n_slices - 1; // index of the last slice of the first field ++ n_slices++; ++ break; ++ } + case VC1_CODE_ENTRYPOINT: /* it should be before frame data */ + buf_size2 = vc1_unescape_buffer(start + 4, size, buf2); +- init_get_bits(&s->gb, buf2, buf_size2*8); ++ init_get_bits(&s->gb, buf2, buf_size2 * 8); + vc1_decode_entry_point(avctx, v, &s->gb); + break; +- case VC1_CODE_SLICE: +- av_log(avctx, AV_LOG_ERROR, "Sliced decoding is not implemented (yet)\n"); +- av_free(buf2); +- return -1; ++ case VC1_CODE_SLICE: { ++ int buf_size3; ++ slices = av_realloc(slices, sizeof(*slices) * (n_slices+1)); ++ if (!slices) ++ goto err; ++ slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!slices[n_slices].buf) ++ goto err; ++ buf_size3 = vc1_unescape_buffer(start + 4, size, ++ slices[n_slices].buf); ++ init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, ++ buf_size3 << 3); ++ slices[n_slices].mby_start = get_bits(&slices[n_slices].gb, 9); ++ n_slices++; ++ break; ++ } + } + } +- }else if(v->interlace && ((buf[0] & 0xC0) == 0xC0)){ /* WVC1 interlaced stores both fields divided by marker */ ++ } else if (v->interlace && ((buf[0] & 0xC0) == 0xC0)) { /* WVC1 interlaced stores both fields divided by marker */ + const uint8_t *divider; ++ int buf_size3; + + divider = find_next_marker(buf, buf + buf_size); +- if((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD){ ++ if ((divider == (buf + buf_size)) || AV_RB32(divider) != VC1_CODE_FIELD) { + av_log(avctx, AV_LOG_ERROR, "Error in WVC1 interlaced frame\n"); +- av_free(buf2); +- return -1; ++ goto err; ++ } else { // found field marker, unescape second field ++ tmp = av_realloc(slices, sizeof(*slices) * (n_slices+1)); ++ if (!tmp) ++ goto err; ++ slices = tmp; ++ slices[n_slices].buf = av_mallocz(buf_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!slices[n_slices].buf) ++ goto err; ++ buf_size3 = vc1_unescape_buffer(divider + 4, buf + buf_size - divider - 4, slices[n_slices].buf); ++ init_get_bits(&slices[n_slices].gb, slices[n_slices].buf, ++ buf_size3 << 3); ++ slices[n_slices].mby_start = s->mb_height >> 1; ++ n_slices1 = n_slices - 1; ++ n_slices++; + } +- + buf_size2 = vc1_unescape_buffer(buf, divider - buf, buf2); +- // TODO +- if(!v->warn_interlaced++) +- av_log(v->s.avctx, AV_LOG_ERROR, "Interlaced WVC1 support is not implemented\n"); +- av_free(buf2);return -1; +- }else{ ++ } else { + buf_size2 = vc1_unescape_buffer(buf, buf_size, buf2); + } + init_get_bits(&s->gb, buf2, buf_size2*8); + } else + init_get_bits(&s->gb, buf, buf_size*8); +- // do parse frame header +- if(v->profile < PROFILE_ADVANCED) { +- if(vc1_parse_frame_header(v, &s->gb) == -1) { +- av_free(buf2); ++ ++ if (v->res_sprite) { ++ v->new_sprite = !get_bits1(&s->gb); ++ v->two_sprites = get_bits1(&s->gb); ++ /* res_sprite means a Windows Media Image stream, CODEC_ID_*IMAGE means ++ we're using the sprite compositor. These are intentionally kept separate ++ so you can get the raw sprites by using the wmv3 decoder for WMVP or ++ the vc1 one for WVP2 */ ++ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { ++ if (v->new_sprite) { ++ // switch AVCodecContext parameters to those of the sprites ++ avctx->width = avctx->coded_width = v->sprite_width; ++ avctx->height = avctx->coded_height = v->sprite_height; ++ } else { ++ goto image; ++ } ++ } ++ } ++ ++ if (s->context_initialized && ++ (s->width != avctx->coded_width || ++ s->height != avctx->coded_height)) { ++ vc1_decode_end(avctx); ++ } ++ ++ if (!s->context_initialized) { ++ if (ff_msmpeg4_decode_init(avctx) < 0 || vc1_decode_init_alloc_tables(v) < 0) + return -1; ++ ++ s->low_delay = !avctx->has_b_frames || v->res_sprite; ++ ++ if (v->profile == PROFILE_ADVANCED) { ++ s->h_edge_pos = avctx->coded_width; ++ s->v_edge_pos = avctx->coded_height; ++ } ++ } ++ ++ /* We need to set current_picture_ptr before reading the header, ++ * otherwise we cannot store anything in there. */ ++ if (s->current_picture_ptr == NULL || s->current_picture_ptr->f.data[0]) { ++ int i = ff_find_unused_picture(s, 0); ++ if (i < 0) ++ goto err; ++ s->current_picture_ptr = &s->picture[i]; ++ } ++ ++ // do parse frame header ++ v->pic_header_flag = 0; ++ if (v->profile < PROFILE_ADVANCED) { ++ if (vc1_parse_frame_header(v, &s->gb) == -1) { ++ goto err; + } + } else { +- if(vc1_parse_frame_header_adv(v, &s->gb) == -1) { +- av_free(buf2); +- return -1; ++ if (vc1_parse_frame_header_adv(v, &s->gb) == -1) { ++ goto err; + } + } + +- if(v->res_sprite && (s->pict_type!=FF_I_TYPE)){ +- av_free(buf2); +- return -1; ++ if ((avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) ++ && s->pict_type != AV_PICTURE_TYPE_I) { ++ av_log(v->s.avctx, AV_LOG_ERROR, "Sprite decoder: expected I-frame\n"); ++ goto err; ++ } ++ ++ // process pulldown flags ++ s->current_picture_ptr->f.repeat_pict = 0; ++ // Pulldown flags are only valid when 'broadcast' has been set. ++ // So ticks_per_frame will be 2 ++ if (v->rff) { ++ // repeat field ++ s->current_picture_ptr->f.repeat_pict = 1; ++ } else if (v->rptfrm) { ++ // repeat frames ++ s->current_picture_ptr->f.repeat_pict = v->rptfrm * 2; + } + +- // for hurry_up==5 +- s->current_picture.pict_type= s->pict_type; +- s->current_picture.key_frame= s->pict_type == FF_I_TYPE; ++ // for skipping the frame ++ s->current_picture.f.pict_type = s->pict_type; ++ s->current_picture.f.key_frame = s->pict_type == AV_PICTURE_TYPE_I; + + /* skip B-frames if we don't have reference frames */ +- if(s->last_picture_ptr==NULL && (s->pict_type==FF_B_TYPE || s->dropable)){ +- av_free(buf2); +- return -1;//buf_size; +- } +- /* skip b frames if we are in a hurry */ +- if(avctx->hurry_up && s->pict_type==FF_B_TYPE) return -1;//buf_size; +- if( (avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type==FF_B_TYPE) +- || (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type!=FF_I_TYPE) +- || avctx->skip_frame >= AVDISCARD_ALL) { +- av_free(buf2); +- return buf_size; ++ if (s->last_picture_ptr == NULL && (s->pict_type == AV_PICTURE_TYPE_B || s->dropable)) { ++ goto err; + } +- /* skip everything if we are in a hurry>=5 */ +- if(avctx->hurry_up>=5) { +- av_free(buf2); +- return -1;//buf_size; ++ if ((avctx->skip_frame >= AVDISCARD_NONREF && s->pict_type == AV_PICTURE_TYPE_B) || ++ (avctx->skip_frame >= AVDISCARD_NONKEY && s->pict_type != AV_PICTURE_TYPE_I) || ++ avctx->skip_frame >= AVDISCARD_ALL) { ++ goto end; + } + +- if(s->next_p_frame_damaged){ +- if(s->pict_type==FF_B_TYPE) +- return buf_size; ++ if (s->next_p_frame_damaged) { ++ if (s->pict_type == AV_PICTURE_TYPE_B) ++ goto end; + else +- s->next_p_frame_damaged=0; ++ s->next_p_frame_damaged = 0; + } + +- if(MPV_frame_start(s, avctx) < 0) { +- av_free(buf2); +- return -1; ++ if (MPV_frame_start(s, avctx) < 0) { ++ goto err; + } + +- s->me.qpel_put= s->dsp.put_qpel_pixels_tab; +- s->me.qpel_avg= s->dsp.avg_qpel_pixels_tab; ++ s->me.qpel_put = s->dsp.put_qpel_pixels_tab; ++ s->me.qpel_avg = s->dsp.avg_qpel_pixels_tab; + + if ((CONFIG_VC1_VDPAU_DECODER) + &&s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) + ff_vdpau_vc1_decode_picture(s, buf_start, (buf + buf_size) - buf_start); + else if (avctx->hwaccel) { + if (avctx->hwaccel->start_frame(avctx, buf, buf_size) < 0) +- return -1; ++ goto err; + if (avctx->hwaccel->decode_slice(avctx, buf_start, (buf + buf_size) - buf_start) < 0) +- return -1; ++ goto err; + if (avctx->hwaccel->end_frame(avctx) < 0) +- return -1; ++ goto err; + } else { + ff_er_frame_start(s); + + v->bits = buf_size * 8; +- vc1_decode_blocks(v); +-//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), buf_size*8); +-// if(get_bits_count(&s->gb) > buf_size * 8) ++ if (v->field_mode) { ++ uint8_t *tmp[2]; ++ s->current_picture.f.linesize[0] <<= 1; ++ s->current_picture.f.linesize[1] <<= 1; ++ s->current_picture.f.linesize[2] <<= 1; ++ s->linesize <<= 1; ++ s->uvlinesize <<= 1; ++ tmp[0] = v->mv_f_last[0]; ++ tmp[1] = v->mv_f_last[1]; ++ v->mv_f_last[0] = v->mv_f_next[0]; ++ v->mv_f_last[1] = v->mv_f_next[1]; ++ v->mv_f_next[0] = v->mv_f[0]; ++ v->mv_f_next[1] = v->mv_f[1]; ++ v->mv_f[0] = tmp[0]; ++ v->mv_f[1] = tmp[1]; ++ } ++ mb_height = s->mb_height >> v->field_mode; ++ for (i = 0; i <= n_slices; i++) { ++ if (i > 0 && slices[i - 1].mby_start >= mb_height) { ++ v->second_field = 1; ++ v->blocks_off = s->mb_width * s->mb_height << 1; ++ v->mb_off = s->mb_stride * s->mb_height >> 1; ++ } else { ++ v->second_field = 0; ++ v->blocks_off = 0; ++ v->mb_off = 0; ++ } ++ if (i) { ++ v->pic_header_flag = 0; ++ if (v->field_mode && i == n_slices1 + 2) ++ vc1_parse_frame_header_adv(v, &s->gb); ++ else if (get_bits1(&s->gb)) { ++ v->pic_header_flag = 1; ++ vc1_parse_frame_header_adv(v, &s->gb); ++ } ++ } ++ s->start_mb_y = (i == 0) ? 0 : FFMAX(0, slices[i-1].mby_start % mb_height); ++ if (!v->field_mode || v->second_field) ++ s->end_mb_y = (i == n_slices ) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height); ++ else ++ s->end_mb_y = (i <= n_slices1 + 1) ? mb_height : FFMIN(mb_height, slices[i].mby_start % mb_height); ++ vc1_decode_blocks(v); ++ if (i != n_slices) ++ s->gb = slices[i].gb; ++ } ++ if (v->field_mode) { ++ v->second_field = 0; ++ if (s->pict_type == AV_PICTURE_TYPE_B) { ++ memcpy(v->mv_f_base, v->mv_f_next_base, ++ 2 * (s->b8_stride * (s->mb_height * 2 + 1) + s->mb_stride * (s->mb_height + 1) * 2)); ++ } ++ s->current_picture.f.linesize[0] >>= 1; ++ s->current_picture.f.linesize[1] >>= 1; ++ s->current_picture.f.linesize[2] >>= 1; ++ s->linesize >>= 1; ++ s->uvlinesize >>= 1; ++ } ++//av_log(s->avctx, AV_LOG_INFO, "Consumed %i/%i bits\n", get_bits_count(&s->gb), s->gb.size_in_bits); ++// if (get_bits_count(&s->gb) > buf_size * 8) + // return -1; ++ if(s->error_occurred && s->pict_type == AV_PICTURE_TYPE_B) ++ goto err; + ff_er_frame_end(s); + } + + MPV_frame_end(s); + +-assert(s->current_picture.pict_type == s->current_picture_ptr->pict_type); +-assert(s->current_picture.pict_type == s->pict_type); +- if (s->pict_type == FF_B_TYPE || s->low_delay) { +- *pict= *(AVFrame*)s->current_picture_ptr; +- } else if (s->last_picture_ptr != NULL) { +- *pict= *(AVFrame*)s->last_picture_ptr; +- } +- +- if(s->last_picture_ptr || s->low_delay){ ++ if (avctx->codec_id == CODEC_ID_WMV3IMAGE || avctx->codec_id == CODEC_ID_VC1IMAGE) { ++image: ++ avctx->width = avctx->coded_width = v->output_width; ++ avctx->height = avctx->coded_height = v->output_height; ++ if (avctx->skip_frame >= AVDISCARD_NONREF) ++ goto end; ++#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER ++ if (vc1_decode_sprites(v, &s->gb)) ++ goto err; ++#endif ++ *pict = v->sprite_output_frame; + *data_size = sizeof(AVFrame); +- ff_print_debug_info(s, pict); ++ } else { ++ if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) { ++ *pict = *(AVFrame*)s->current_picture_ptr; ++ } else if (s->last_picture_ptr != NULL) { ++ *pict = *(AVFrame*)s->last_picture_ptr; ++ } ++ if (s->last_picture_ptr || s->low_delay) { ++ *data_size = sizeof(AVFrame); ++ ff_print_debug_info(s, pict); ++ } + } + ++end: + av_free(buf2); ++ for (i = 0; i < n_slices; i++) ++ av_free(slices[i].buf); ++ av_free(slices); + return buf_size; +-} +- +- +-/** Close a VC1/WMV3 decoder +- * @warning Initial try at using MpegEncContext stuff +- */ +-static av_cold int vc1_decode_end(AVCodecContext *avctx) +-{ +- VC1Context *v = avctx->priv_data; + +- av_freep(&v->hrd_rate); +- av_freep(&v->hrd_buffer); +- MPV_common_end(&v->s); +- av_freep(&v->mv_type_mb_plane); +- av_freep(&v->direct_mb_plane); +- av_freep(&v->acpred_plane); +- av_freep(&v->over_flags_plane); +- av_freep(&v->mb_type_base); +- av_freep(&v->cbp_base); +- ff_intrax8_common_end(&v->x8); +- return 0; ++err: ++ av_free(buf2); ++ for (i = 0; i < n_slices; i++) ++ av_free(slices[i].buf); ++ av_free(slices); ++ return -1; + } + + ++static const AVProfile profiles[] = { ++ { FF_PROFILE_VC1_SIMPLE, "Simple" }, ++ { FF_PROFILE_VC1_MAIN, "Main" }, ++ { FF_PROFILE_VC1_COMPLEX, "Complex" }, ++ { FF_PROFILE_VC1_ADVANCED, "Advanced" }, ++ { FF_PROFILE_UNKNOWN }, ++}; ++ + AVCodec ff_vc1_decoder = { +- "vc1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VC1, +- sizeof(VC1Context), +- vc1_decode_init, +- NULL, +- vc1_decode_end, +- vc1_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"), +- .pix_fmts = ff_hwaccel_pixfmt_list_420 ++ .name = "vc1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VC1, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1"), ++ .pix_fmts = ff_hwaccel_pixfmt_list_420, ++ .profiles = NULL_IF_CONFIG_SMALL(profiles) + }; + + #if CONFIG_WMV3_DECODER + AVCodec ff_wmv3_decoder = { +- "wmv3", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV3, +- sizeof(VC1Context), +- vc1_decode_init, +- NULL, +- vc1_decode_end, +- vc1_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"), +- .pix_fmts = ff_hwaccel_pixfmt_list_420 ++ .name = "wmv3", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV3, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9"), ++ .pix_fmts = ff_hwaccel_pixfmt_list_420, ++ .profiles = NULL_IF_CONFIG_SMALL(profiles) + }; + #endif + + #if CONFIG_WMV3_VDPAU_DECODER + AVCodec ff_wmv3_vdpau_decoder = { +- "wmv3_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV3, +- sizeof(VC1Context), +- vc1_decode_init, +- NULL, +- vc1_decode_end, +- vc1_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"), +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE} ++ .name = "wmv3_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV3, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 VDPAU"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_WMV3, PIX_FMT_NONE}, ++ .profiles = NULL_IF_CONFIG_SMALL(profiles) + }; + #endif + + #if CONFIG_VC1_VDPAU_DECODER + AVCodec ff_vc1_vdpau_decoder = { +- "vc1_vdpau", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VC1, +- sizeof(VC1Context), +- vc1_decode_init, +- NULL, +- vc1_decode_end, +- vc1_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, +- NULL, +- .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"), +- .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE} ++ .name = "vc1_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VC1, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, ++ .long_name = NULL_IF_CONFIG_SMALL("SMPTE VC-1 VDPAU"), ++ .pix_fmts = (const enum PixelFormat[]){PIX_FMT_VDPAU_VC1, PIX_FMT_NONE}, ++ .profiles = NULL_IF_CONFIG_SMALL(profiles) ++}; ++#endif ++ ++#if CONFIG_WMV3IMAGE_DECODER ++AVCodec ff_wmv3image_decoder = { ++ .name = "wmv3image", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV3IMAGE, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .flush = vc1_sprite_flush, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image"), ++ .pix_fmts = ff_pixfmt_list_420 ++}; ++#endif ++ ++#if CONFIG_VC1IMAGE_DECODER ++AVCodec ff_vc1image_decoder = { ++ .name = "vc1image", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VC1IMAGE, ++ .priv_data_size = sizeof(VC1Context), ++ .init = vc1_decode_init, ++ .close = vc1_decode_end, ++ .decode = vc1_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .flush = vc1_sprite_flush, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 9 Image v2"), ++ .pix_fmts = ff_pixfmt_list_420 + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dsp.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dsp.c 2012-05-14 14:08:54.340340103 +0200 +@@ -25,7 +25,7 @@ + * + */ + +-#include "dsputil.h" ++#include "vc1dsp.h" + + + /** Apply overlap transform to horizontal edge +@@ -78,6 +78,58 @@ + } + } + ++static void vc1_v_s_overlap_c(DCTELEM *top, DCTELEM *bottom) ++{ ++ int i; ++ int a, b, c, d; ++ int d1, d2; ++ int rnd1 = 4, rnd2 = 3; ++ for(i = 0; i < 8; i++) { ++ a = top[48]; ++ b = top[56]; ++ c = bottom[0]; ++ d = bottom[8]; ++ d1 = a - d; ++ d2 = a - d + b - c; ++ ++ top[48] = ((a << 3) - d1 + rnd1) >> 3; ++ top[56] = ((b << 3) - d2 + rnd2) >> 3; ++ bottom[0] = ((c << 3) + d2 + rnd1) >> 3; ++ bottom[8] = ((d << 3) + d1 + rnd2) >> 3; ++ ++ bottom++; ++ top++; ++ rnd2 = 7 - rnd2; ++ rnd1 = 7 - rnd1; ++ } ++} ++ ++static void vc1_h_s_overlap_c(DCTELEM *left, DCTELEM *right) ++{ ++ int i; ++ int a, b, c, d; ++ int d1, d2; ++ int rnd1 = 4, rnd2 = 3; ++ for(i = 0; i < 8; i++) { ++ a = left[6]; ++ b = left[7]; ++ c = right[0]; ++ d = right[1]; ++ d1 = a - d; ++ d2 = a - d + b - c; ++ ++ left[6] = ((a << 3) - d1 + rnd1) >> 3; ++ left[7] = ((b << 3) - d2 + rnd2) >> 3; ++ right[0] = ((c << 3) + d2 + rnd1) >> 3; ++ right[1] = ((d << 3) + d1 + rnd2) >> 3; ++ ++ right += 8; ++ left += 8; ++ rnd2 = 7 - rnd2; ++ rnd1 = 7 - rnd1; ++ } ++} ++ + /** + * VC-1 in-loop deblocking filter for one line + * @param src source block type +@@ -87,8 +139,6 @@ + * @see 8.6 + */ + static av_always_inline int vc1_filter_line(uint8_t* src, int stride, int pq){ +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +- + int a0 = (2*(src[-2*stride] - src[ 1*stride]) - 5*(src[-1*stride] - src[ 0*stride]) + 4) >> 3; + int a0_sign = a0 >> 31; /* Store sign */ + a0 = (a0 ^ a0_sign) - a0_sign; /* a0 = FFABS(a0); */ +@@ -111,8 +161,8 @@ + else{ + d = FFMIN(d, clip); + d = (d ^ d_sign) - d_sign; /* Restore sign */ +- src[-1*stride] = cm[src[-1*stride] - d]; +- src[ 0*stride] = cm[src[ 0*stride] + d]; ++ src[-1*stride] = av_clip_uint8(src[-1*stride] - d); ++ src[ 0*stride] = av_clip_uint8(src[ 0*stride] + d); + } + return 1; + } +@@ -182,19 +232,17 @@ + { + int i; + int dc = block[0]; +- const uint8_t *cm; + dc = (3 * dc + 1) >> 1; + dc = (3 * dc + 16) >> 5; +- cm = ff_cropTbl + MAX_NEG_CROP + dc; + for(i = 0; i < 8; i++){ +- dest[0] = cm[dest[0]]; +- dest[1] = cm[dest[1]]; +- dest[2] = cm[dest[2]]; +- dest[3] = cm[dest[3]]; +- dest[4] = cm[dest[4]]; +- dest[5] = cm[dest[5]]; +- dest[6] = cm[dest[6]]; +- dest[7] = cm[dest[7]]; ++ dest[0] = av_clip_uint8(dest[0] + dc); ++ dest[1] = av_clip_uint8(dest[1] + dc); ++ dest[2] = av_clip_uint8(dest[2] + dc); ++ dest[3] = av_clip_uint8(dest[3] + dc); ++ dest[4] = av_clip_uint8(dest[4] + dc); ++ dest[5] = av_clip_uint8(dest[5] + dc); ++ dest[6] = av_clip_uint8(dest[6] + dc); ++ dest[7] = av_clip_uint8(dest[7] + dc); + dest += linesize; + } + } +@@ -203,25 +251,25 @@ + { + int i; + register int t1,t2,t3,t4,t5,t6,t7,t8; +- DCTELEM *src, *dst; ++ DCTELEM *src, *dst, temp[64]; + + src = block; +- dst = block; ++ dst = temp; + for(i = 0; i < 8; i++){ +- t1 = 12 * (src[0] + src[4]) + 4; +- t2 = 12 * (src[0] - src[4]) + 4; +- t3 = 16 * src[2] + 6 * src[6]; +- t4 = 6 * src[2] - 16 * src[6]; ++ t1 = 12 * (src[ 0] + src[32]) + 4; ++ t2 = 12 * (src[ 0] - src[32]) + 4; ++ t3 = 16 * src[16] + 6 * src[48]; ++ t4 = 6 * src[16] - 16 * src[48]; + + t5 = t1 + t3; + t6 = t2 + t4; + t7 = t2 - t4; + t8 = t1 - t3; + +- t1 = 16 * src[1] + 15 * src[3] + 9 * src[5] + 4 * src[7]; +- t2 = 15 * src[1] - 4 * src[3] - 16 * src[5] - 9 * src[7]; +- t3 = 9 * src[1] - 16 * src[3] + 4 * src[5] + 15 * src[7]; +- t4 = 4 * src[1] - 9 * src[3] + 15 * src[5] - 16 * src[7]; ++ t1 = 16 * src[ 8] + 15 * src[24] + 9 * src[40] + 4 * src[56]; ++ t2 = 15 * src[ 8] - 4 * src[24] - 16 * src[40] - 9 * src[56]; ++ t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; ++ t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; + + dst[0] = (t5 + t1) >> 3; + dst[1] = (t6 + t2) >> 3; +@@ -232,11 +280,11 @@ + dst[6] = (t6 - t2) >> 3; + dst[7] = (t5 - t1) >> 3; + +- src += 8; ++ src += 1; + dst += 8; + } + +- src = block; ++ src = temp; + dst = block; + for(i = 0; i < 8; i++){ + t1 = 12 * (src[ 0] + src[32]) + 64; +@@ -274,19 +322,17 @@ + { + int i; + int dc = block[0]; +- const uint8_t *cm; + dc = ( 3 * dc + 1) >> 1; + dc = (17 * dc + 64) >> 7; +- cm = ff_cropTbl + MAX_NEG_CROP + dc; + for(i = 0; i < 4; i++){ +- dest[0] = cm[dest[0]]; +- dest[1] = cm[dest[1]]; +- dest[2] = cm[dest[2]]; +- dest[3] = cm[dest[3]]; +- dest[4] = cm[dest[4]]; +- dest[5] = cm[dest[5]]; +- dest[6] = cm[dest[6]]; +- dest[7] = cm[dest[7]]; ++ dest[0] = av_clip_uint8(dest[0] + dc); ++ dest[1] = av_clip_uint8(dest[1] + dc); ++ dest[2] = av_clip_uint8(dest[2] + dc); ++ dest[3] = av_clip_uint8(dest[3] + dc); ++ dest[4] = av_clip_uint8(dest[4] + dc); ++ dest[5] = av_clip_uint8(dest[5] + dc); ++ dest[6] = av_clip_uint8(dest[6] + dc); ++ dest[7] = av_clip_uint8(dest[7] + dc); + dest += linesize; + } + } +@@ -296,7 +342,6 @@ + int i; + register int t1,t2,t3,t4,t5,t6,t7,t8; + DCTELEM *src, *dst; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + src = block; + dst = block; +@@ -336,10 +381,10 @@ + t3 = 22 * src[ 8] + 10 * src[24]; + t4 = 22 * src[24] - 10 * src[ 8]; + +- dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)]; +- dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)]; +- dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)]; +- dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)]; ++ dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7)); ++ dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7)); ++ dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7)); ++ dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7)); + + src ++; + dest++; +@@ -352,15 +397,13 @@ + { + int i; + int dc = block[0]; +- const uint8_t *cm; + dc = (17 * dc + 4) >> 3; + dc = (12 * dc + 64) >> 7; +- cm = ff_cropTbl + MAX_NEG_CROP + dc; + for(i = 0; i < 8; i++){ +- dest[0] = cm[dest[0]]; +- dest[1] = cm[dest[1]]; +- dest[2] = cm[dest[2]]; +- dest[3] = cm[dest[3]]; ++ dest[0] = av_clip_uint8(dest[0] + dc); ++ dest[1] = av_clip_uint8(dest[1] + dc); ++ dest[2] = av_clip_uint8(dest[2] + dc); ++ dest[3] = av_clip_uint8(dest[3] + dc); + dest += linesize; + } + } +@@ -370,7 +413,6 @@ + int i; + register int t1,t2,t3,t4,t5,t6,t7,t8; + DCTELEM *src, *dst; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + src = block; + dst = block; +@@ -406,14 +448,14 @@ + t3 = 9 * src[ 8] - 16 * src[24] + 4 * src[40] + 15 * src[56]; + t4 = 4 * src[ 8] - 9 * src[24] + 15 * src[40] - 16 * src[56]; + +- dest[0*linesize] = cm[dest[0*linesize] + ((t5 + t1) >> 7)]; +- dest[1*linesize] = cm[dest[1*linesize] + ((t6 + t2) >> 7)]; +- dest[2*linesize] = cm[dest[2*linesize] + ((t7 + t3) >> 7)]; +- dest[3*linesize] = cm[dest[3*linesize] + ((t8 + t4) >> 7)]; +- dest[4*linesize] = cm[dest[4*linesize] + ((t8 - t4 + 1) >> 7)]; +- dest[5*linesize] = cm[dest[5*linesize] + ((t7 - t3 + 1) >> 7)]; +- dest[6*linesize] = cm[dest[6*linesize] + ((t6 - t2 + 1) >> 7)]; +- dest[7*linesize] = cm[dest[7*linesize] + ((t5 - t1 + 1) >> 7)]; ++ dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t5 + t1) >> 7)); ++ dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t6 + t2) >> 7)); ++ dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t7 + t3) >> 7)); ++ dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t8 + t4) >> 7)); ++ dest[4*linesize] = av_clip_uint8(dest[4*linesize] + ((t8 - t4 + 1) >> 7)); ++ dest[5*linesize] = av_clip_uint8(dest[5*linesize] + ((t7 - t3 + 1) >> 7)); ++ dest[6*linesize] = av_clip_uint8(dest[6*linesize] + ((t6 - t2 + 1) >> 7)); ++ dest[7*linesize] = av_clip_uint8(dest[7*linesize] + ((t5 - t1 + 1) >> 7)); + + src ++; + dest++; +@@ -426,15 +468,13 @@ + { + int i; + int dc = block[0]; +- const uint8_t *cm; + dc = (17 * dc + 4) >> 3; + dc = (17 * dc + 64) >> 7; +- cm = ff_cropTbl + MAX_NEG_CROP + dc; + for(i = 0; i < 4; i++){ +- dest[0] = cm[dest[0]]; +- dest[1] = cm[dest[1]]; +- dest[2] = cm[dest[2]]; +- dest[3] = cm[dest[3]]; ++ dest[0] = av_clip_uint8(dest[0] + dc); ++ dest[1] = av_clip_uint8(dest[1] + dc); ++ dest[2] = av_clip_uint8(dest[2] + dc); ++ dest[3] = av_clip_uint8(dest[3] + dc); + dest += linesize; + } + } +@@ -444,7 +484,6 @@ + int i; + register int t1,t2,t3,t4; + DCTELEM *src, *dst; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + src = block; + dst = block; +@@ -470,10 +509,10 @@ + t3 = 22 * src[ 8] + 10 * src[24]; + t4 = 22 * src[24] - 10 * src[ 8]; + +- dest[0*linesize] = cm[dest[0*linesize] + ((t1 + t3) >> 7)]; +- dest[1*linesize] = cm[dest[1*linesize] + ((t2 - t4) >> 7)]; +- dest[2*linesize] = cm[dest[2*linesize] + ((t2 + t4) >> 7)]; +- dest[3*linesize] = cm[dest[3*linesize] + ((t1 - t3) >> 7)]; ++ dest[0*linesize] = av_clip_uint8(dest[0*linesize] + ((t1 + t3) >> 7)); ++ dest[1*linesize] = av_clip_uint8(dest[1*linesize] + ((t2 - t4) >> 7)); ++ dest[2*linesize] = av_clip_uint8(dest[2*linesize] + ((t2 + t4) >> 7)); ++ dest[3*linesize] = av_clip_uint8(dest[3*linesize] + ((t1 - t3) >> 7)); + + src ++; + dest++; +@@ -498,8 +537,8 @@ + return 0; /* should not occur */ \ + } + +-VC1_MSPEL_FILTER_16B(ver, uint8_t); +-VC1_MSPEL_FILTER_16B(hor, int16_t); ++VC1_MSPEL_FILTER_16B(ver, uint8_t) ++VC1_MSPEL_FILTER_16B(hor, int16_t) + + + /** Filter used to interpolate fractional pel values +@@ -612,7 +651,136 @@ + PUT_VC1_MSPEL(2, 3) + PUT_VC1_MSPEL(3, 3) + +-av_cold void ff_vc1dsp_init(DSPContext* dsp, AVCodecContext *avctx) { ++static void put_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ ++ const int A=(8-x)*(8-y); ++ const int B=( x)*(8-y); ++ const int C=(8-x)*( y); ++ const int D=( x)*( y); ++ int i; ++ ++ assert(x<8 && y<8 && x>=0 && y>=0); ++ ++ for(i=0; i> 6; ++ dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; ++ dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; ++ dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; ++ dst[4] = (A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6; ++ dst[5] = (A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6; ++ dst[6] = (A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6; ++ dst[7] = (A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6; ++ dst+= stride; ++ src+= stride; ++ } ++} ++ ++static void put_no_rnd_vc1_chroma_mc4_c(uint8_t *dst, uint8_t *src, int stride, int h, int x, int y){ ++ const int A=(8-x)*(8-y); ++ const int B=( x)*(8-y); ++ const int C=(8-x)*( y); ++ const int D=( x)*( y); ++ int i; ++ ++ assert(x<8 && y<8 && x>=0 && y>=0); ++ ++ for(i=0; i> 6; ++ dst[1] = (A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6; ++ dst[2] = (A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6; ++ dst[3] = (A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6; ++ dst+= stride; ++ src+= stride; ++ } ++} ++ ++#define avg2(a,b) ((a+b+1)>>1) ++static void avg_no_rnd_vc1_chroma_mc8_c(uint8_t *dst/*align 8*/, uint8_t *src/*align 1*/, int stride, int h, int x, int y){ ++ const int A=(8-x)*(8-y); ++ const int B=( x)*(8-y); ++ const int C=(8-x)*( y); ++ const int D=( x)*( y); ++ int i; ++ ++ assert(x<8 && y<8 && x>=0 && y>=0); ++ ++ for(i=0; i> 6)); ++ dst[1] = avg2(dst[1], ((A*src[1] + B*src[2] + C*src[stride+1] + D*src[stride+2] + 32 - 4) >> 6)); ++ dst[2] = avg2(dst[2], ((A*src[2] + B*src[3] + C*src[stride+2] + D*src[stride+3] + 32 - 4) >> 6)); ++ dst[3] = avg2(dst[3], ((A*src[3] + B*src[4] + C*src[stride+3] + D*src[stride+4] + 32 - 4) >> 6)); ++ dst[4] = avg2(dst[4], ((A*src[4] + B*src[5] + C*src[stride+4] + D*src[stride+5] + 32 - 4) >> 6)); ++ dst[5] = avg2(dst[5], ((A*src[5] + B*src[6] + C*src[stride+5] + D*src[stride+6] + 32 - 4) >> 6)); ++ dst[6] = avg2(dst[6], ((A*src[6] + B*src[7] + C*src[stride+6] + D*src[stride+7] + 32 - 4) >> 6)); ++ dst[7] = avg2(dst[7], ((A*src[7] + B*src[8] + C*src[stride+7] + D*src[stride+8] + 32 - 4) >> 6)); ++ dst+= stride; ++ src+= stride; ++ } ++} ++ ++#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER ++ ++static void sprite_h_c(uint8_t *dst, const uint8_t *src, int offset, int advance, int count) ++{ ++ while (count--) { ++ int a = src[(offset >> 16) ]; ++ int b = src[(offset >> 16) + 1]; ++ *dst++ = a + ((b - a) * (offset&0xFFFF) >> 16); ++ offset += advance; ++ } ++} ++ ++static av_always_inline void sprite_v_template(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, ++ int two_sprites, const uint8_t *src2a, const uint8_t *src2b, int offset2, ++ int alpha, int scaled, int width) ++{ ++ int a1, b1, a2, b2; ++ while (width--) { ++ a1 = *src1a++; ++ if (scaled) { ++ b1 = *src1b++; ++ a1 = a1 + ((b1 - a1) * offset1 >> 16); ++ } ++ if (two_sprites) { ++ a2 = *src2a++; ++ if (scaled > 1) { ++ b2 = *src2b++; ++ a2 = a2 + ((b2 - a2) * offset2 >> 16); ++ } ++ a1 = a1 + ((a2 - a1) * alpha >> 16); ++ } ++ *dst++ = a1; ++ } ++} ++ ++static void sprite_v_single_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width) ++{ ++ sprite_v_template(dst, src1a, src1b, offset, 0, NULL, NULL, 0, 0, 1, width); ++} ++ ++static void sprite_v_double_noscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width) ++{ ++ sprite_v_template(dst, src1a, NULL, 0, 1, src2a, NULL, 0, alpha, 0, width); ++} ++ ++static void sprite_v_double_onescale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, ++ const uint8_t *src2a, int alpha, int width) ++{ ++ sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, NULL, 0, alpha, 1, width); ++} ++ ++static void sprite_v_double_twoscale_c(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, ++ const uint8_t *src2a, const uint8_t *src2b, int offset2, ++ int alpha, int width) ++{ ++ sprite_v_template(dst, src1a, src1b, offset1, 1, src2a, src2b, offset2, alpha, 2, width); ++} ++ ++#endif ++ ++av_cold void ff_vc1dsp_init(VC1DSPContext* dsp) { + dsp->vc1_inv_trans_8x8 = vc1_inv_trans_8x8_c; + dsp->vc1_inv_trans_4x8 = vc1_inv_trans_4x8_c; + dsp->vc1_inv_trans_8x4 = vc1_inv_trans_8x4_c; +@@ -623,6 +791,8 @@ + dsp->vc1_inv_trans_4x4_dc = vc1_inv_trans_4x4_dc_c; + dsp->vc1_h_overlap = vc1_h_overlap_c; + dsp->vc1_v_overlap = vc1_v_overlap_c; ++ dsp->vc1_h_s_overlap = vc1_h_s_overlap_c; ++ dsp->vc1_v_s_overlap = vc1_v_s_overlap_c; + dsp->vc1_v_loop_filter4 = vc1_v_loop_filter4_c; + dsp->vc1_h_loop_filter4 = vc1_h_loop_filter4_c; + dsp->vc1_v_loop_filter8 = vc1_v_loop_filter8_c; +@@ -663,4 +833,21 @@ + dsp->avg_vc1_mspel_pixels_tab[13] = avg_vc1_mspel_mc13_c; + dsp->avg_vc1_mspel_pixels_tab[14] = avg_vc1_mspel_mc23_c; + dsp->avg_vc1_mspel_pixels_tab[15] = avg_vc1_mspel_mc33_c; ++ ++ dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= put_no_rnd_vc1_chroma_mc8_c; ++ dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= avg_no_rnd_vc1_chroma_mc8_c; ++ dsp->put_no_rnd_vc1_chroma_pixels_tab[1] = put_no_rnd_vc1_chroma_mc4_c; ++ ++#if CONFIG_WMV3IMAGE_DECODER || CONFIG_VC1IMAGE_DECODER ++ dsp->sprite_h = sprite_h_c; ++ dsp->sprite_v_single = sprite_v_single_c; ++ dsp->sprite_v_double_noscale = sprite_v_double_noscale_c; ++ dsp->sprite_v_double_onescale = sprite_v_double_onescale_c; ++ dsp->sprite_v_double_twoscale = sprite_v_double_twoscale_c; ++#endif ++ ++ if (HAVE_ALTIVEC) ++ ff_vc1dsp_init_altivec(dsp); ++ if (HAVE_MMX) ++ ff_vc1dsp_init_mmx(dsp); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1dsp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1dsp.h 2012-05-14 14:08:54.341340123 +0200 +@@ -0,0 +1,79 @@ ++/* ++ * VC-1 and WMV3 decoder - DSP functions ++ * Copyright (c) 2006 Konstantin Shishkov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * VC-1 and WMV3 decoder ++ * ++ */ ++ ++#ifndef AVCODEC_VC1DSP_H ++#define AVCODEC_VC1DSP_H ++ ++#include "dsputil.h" ++ ++typedef struct VC1DSPContext { ++ /* vc1 functions */ ++ void (*vc1_inv_trans_8x8)(DCTELEM *b); ++ void (*vc1_inv_trans_8x4)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_4x8)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_4x4)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_8x8_dc)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_8x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_4x8_dc)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_inv_trans_4x4_dc)(uint8_t *dest, int line_size, DCTELEM *block); ++ void (*vc1_v_overlap)(uint8_t *src, int stride); ++ void (*vc1_h_overlap)(uint8_t *src, int stride); ++ void (*vc1_v_s_overlap)(DCTELEM *top, DCTELEM *bottom); ++ void (*vc1_h_s_overlap)(DCTELEM *left, DCTELEM *right); ++ void (*vc1_v_loop_filter4)(uint8_t *src, int stride, int pq); ++ void (*vc1_h_loop_filter4)(uint8_t *src, int stride, int pq); ++ void (*vc1_v_loop_filter8)(uint8_t *src, int stride, int pq); ++ void (*vc1_h_loop_filter8)(uint8_t *src, int stride, int pq); ++ void (*vc1_v_loop_filter16)(uint8_t *src, int stride, int pq); ++ void (*vc1_h_loop_filter16)(uint8_t *src, int stride, int pq); ++ ++ /* put 8x8 block with bicubic interpolation and quarterpel precision ++ * last argument is actually round value instead of height ++ */ ++ op_pixels_func put_vc1_mspel_pixels_tab[16]; ++ op_pixels_func avg_vc1_mspel_pixels_tab[16]; ++ ++ /* This is really one func used in VC-1 decoding */ ++ h264_chroma_mc_func put_no_rnd_vc1_chroma_pixels_tab[3]; ++ h264_chroma_mc_func avg_no_rnd_vc1_chroma_pixels_tab[3]; ++ ++ /* Windows Media Image functions */ ++ void (*sprite_h)(uint8_t *dst, const uint8_t *src, int offset, int advance, int count); ++ void (*sprite_v_single)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset, int width); ++ void (*sprite_v_double_noscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src2a, int alpha, int width); ++ void (*sprite_v_double_onescale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, ++ const uint8_t *src2a, int alpha, int width); ++ void (*sprite_v_double_twoscale)(uint8_t *dst, const uint8_t *src1a, const uint8_t *src1b, int offset1, ++ const uint8_t *src2a, const uint8_t *src2b, int offset2, ++ int alpha, int width); ++} VC1DSPContext; ++ ++void ff_vc1dsp_init(VC1DSPContext* c); ++void ff_vc1dsp_init_altivec(VC1DSPContext* c); ++void ff_vc1dsp_init_mmx(VC1DSPContext* dsp); ++ ++#endif /* AVCODEC_VC1DSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1.h 2012-05-14 14:08:54.308339458 +0200 +@@ -26,10 +26,11 @@ + #include "avcodec.h" + #include "mpegvideo.h" + #include "intrax8.h" ++#include "vc1dsp.h" + + /** Markers used in VC-1 AP frame data */ + //@{ +-enum VC1Code{ ++enum VC1Code { + VC1_CODE_RES0 = 0x00000100, + VC1_CODE_ENDOFSEQ = 0x0000010A, + VC1_CODE_SLICE, +@@ -104,12 +105,25 @@ + }; + //@} + ++/** MBMODE for interlaced frame P-picture */ ++//@{ ++enum MBModesIntfr { ++ MV_PMODE_INTFR_1MV, ++ MV_PMODE_INTFR_2MV_FIELD, ++ MV_PMODE_INTFR_2MV, ++ MV_PMODE_INTFR_4MV_FIELD, ++ MV_PMODE_INTFR_4MV, ++ MV_PMODE_INTFR_INTRA, ++}; ++//@} ++ + /** @name MV types for B frames */ + //@{ + enum BMVTypes { + BMV_TYPE_BACKWARD, + BMV_TYPE_FORWARD, +- BMV_TYPE_INTERPOLATED ++ BMV_TYPE_INTERPOLATED, ++ BMV_TYPE_DIRECT + }; + //@} + +@@ -119,10 +133,10 @@ + TT_8X8, + TT_8X4_BOTTOM, + TT_8X4_TOP, +- TT_8X4, //Both halves ++ TT_8X4, // both halves + TT_4X8_RIGHT, + TT_4X8_LEFT, +- TT_4X8, //Both halves ++ TT_4X8, // both halves + TT_4X4 + }; + //@} +@@ -147,6 +161,16 @@ + }; + //@} + ++/** ++ * FCM Frame Coding Mode ++ * @note some content might be marked interlaced ++ * but have fcm set to 0 as well (e.g. HD-DVD) ++ */ ++enum FrameCodingMode { ++ PROGRESSIVE = 0, ///< in the bitstream is reported as 00b ++ ILACE_FRAME, ///< in the bitstream is reported as 10b ++ ILACE_FIELD ///< in the bitstream is reported as 11b ++}; + + /** The VC1 Context + * @todo Change size wherever another size is more efficient +@@ -155,6 +179,7 @@ + typedef struct VC1Context{ + MpegEncContext s; + IntraX8Context x8; ++ VC1DSPContext vc1dsp; + + int bits; + +@@ -209,14 +234,16 @@ + + /** Frame decoding info for all profiles */ + //@{ +- uint8_t mv_mode; ///< MV coding monde +- uint8_t mv_mode2; ///< Secondary MV coding mode (B frames) +- int k_x; ///< Number of bits for MVs (depends on MV range) +- int k_y; ///< Number of bits for MVs (depends on MV range) +- int range_x, range_y; ///< MV range +- uint8_t pq, altpq; ///< Current/alternate frame quantizer scale +- const uint8_t* zz_8x4;///< Zigzag scan table for TT_8x4 coding mode +- const uint8_t* zz_4x8;///< Zigzag scan table for TT_4x8 coding mode ++ uint8_t mv_mode; ///< MV coding monde ++ uint8_t mv_mode2; ///< Secondary MV coding mode (B frames) ++ int k_x; ///< Number of bits for MVs (depends on MV range) ++ int k_y; ///< Number of bits for MVs (depends on MV range) ++ int range_x, range_y; ///< MV range ++ uint8_t pq, altpq; ///< Current/alternate frame quantizer scale ++ uint8_t zz_8x8[4][64]; ///< Zigzag table for TT_8x8, permuted for IDCT ++ int left_blk_sh, top_blk_sh; ///< Either 3 or 0, positions of l/t in blk[] ++ const uint8_t* zz_8x4; ///< Zigzag scan table for TT_8x4 coding mode ++ const uint8_t* zz_4x8; ///< Zigzag scan table for TT_4x8 coding mode + /** pquant parameters */ + //@{ + uint8_t dquantfrm; +@@ -228,15 +255,15 @@ + * @see 8.1.1.10, p(1)10 + */ + //@{ +- int c_ac_table_index; ///< Chroma index from ACFRM element +- int y_ac_table_index; ///< Luma index from AC2FRM element ++ int c_ac_table_index; ///< Chroma index from ACFRM element ++ int y_ac_table_index; ///< Luma index from AC2FRM element + //@} +- int ttfrm; ///< Transform type info present at frame level +- uint8_t ttmbf; ///< Transform type flag +- uint8_t ttblk4x4; ///< Value of ttblk which indicates a 4x4 transform +- int codingset; ///< index of current table set from 11.8 to use for luma block decoding +- int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding +- int pqindex; ///< raw pqindex used in coding set selection ++ int ttfrm; ///< Transform type info present at frame level ++ uint8_t ttmbf; ///< Transform type flag ++ int *ttblk_base, *ttblk; ///< Transform type at the block level ++ int codingset; ///< index of current table set from 11.8 to use for luma block decoding ++ int codingset2; ///< index of current table set from 11.8 to use for chroma block decoding ++ int pqindex; ///< raw pqindex used in coding set selection + int a_avail, c_avail; + uint8_t *mb_type_base, *mb_type[3]; + +@@ -256,28 +283,30 @@ + * -# 2 -> [-512, 511.f] x [-128, 127.f] + * -# 3 -> [-1024, 1023.f] x [-256, 255.f] + */ +- uint8_t mvrange; +- uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use +- VLC *cbpcy_vlc; ///< CBPCY VLC table +- int tt_index; ///< Index for Transform Type tables +- uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV) +- uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs +- int mv_type_is_raw; ///< mv type mb plane is not coded +- int dmb_is_raw; ///< direct mb plane is raw +- int skip_is_raw; ///< skip mb plane is not coded +- uint8_t luty[256], lutuv[256]; // lookup tables used for intensity compensation +- int use_ic; ///< use intensity compensation in B-frames +- int rnd; ///< rounding control ++ uint8_t mvrange; ///< Extended MV range flag ++ uint8_t pquantizer; ///< Uniform (over sequence) quantizer in use ++ VLC *cbpcy_vlc; ///< CBPCY VLC table ++ int tt_index; ///< Index for Transform Type tables (to decode TTMB) ++ uint8_t* mv_type_mb_plane; ///< bitplane for mv_type == (4MV) ++ uint8_t* direct_mb_plane; ///< bitplane for "direct" MBs ++ uint8_t* forward_mb_plane; ///< bitplane for "forward" MBs ++ int mv_type_is_raw; ///< mv type mb plane is not coded ++ int dmb_is_raw; ///< direct mb plane is raw ++ int fmb_is_raw; ///< forward mb plane is raw ++ int skip_is_raw; ///< skip mb plane is not coded ++ uint8_t luty[256], lutuv[256]; ///< lookup tables used for intensity compensation ++ int use_ic; ///< use intensity compensation in B-frames ++ int rnd; ///< rounding control + + /** Frame decoding info for S/M profiles only */ + //@{ +- uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128) ++ uint8_t rangeredfrm; ///< out_sample = CLIP((in_sample-128)*2+128) + uint8_t interpfrm; + //@} + + /** Frame decoding info for Advanced profile */ + //@{ +- uint8_t fcm; ///< 0->Progressive, 2->Frame-Interlace, 3->Field-Interlace ++ enum FrameCodingMode fcm; + uint8_t numpanscanwin; + uint8_t tfcntr; + uint8_t rptfrm, tff, rff; +@@ -303,16 +332,67 @@ + uint8_t range_mapuv; + //@} + ++ /** Frame decoding info for interlaced picture */ ++ uint8_t dmvrange; ///< Extended differential MV range flag ++ int fourmvswitch; ++ int intcomp; ++ uint8_t lumscale2; ///< for interlaced field P picture ++ uint8_t lumshift2; ++ uint8_t luty2[256], lutuv2[256]; // lookup tables used for intensity compensation ++ VLC* mbmode_vlc; ++ VLC* imv_vlc; ++ VLC* twomvbp_vlc; ++ VLC* fourmvbp_vlc; ++ uint8_t twomvbp; ++ uint8_t fourmvbp; ++ uint8_t* fieldtx_plane; ++ int fieldtx_is_raw; ++ int8_t zzi_8x8[64]; ++ uint8_t *blk_mv_type_base, *blk_mv_type; ///< 0: frame MV, 1: field MV (interlaced frame) ++ uint8_t *mv_f_base, *mv_f[2]; ///< 0: MV obtained from same field, 1: opposite field ++ uint8_t *mv_f_last_base, *mv_f_last[2]; ++ uint8_t *mv_f_next_base, *mv_f_next[2]; ++ int field_mode; ///< 1 for interlaced field pictures ++ int fptype; ++ int second_field; ++ int refdist; ///< distance of the current picture from reference ++ int numref; ///< number of past field pictures used as reference ++ // 0 corresponds to 1 and 1 corresponds to 2 references ++ int reffield; ///< if numref = 0 (1 reference) then reffield decides which ++ // field to use among the two fields from previous frame ++ int intcompfield; ///< which of the two fields to be intensity compensated ++ // 0: both fields, 1: bottom field, 2: top field ++ int cur_field_type; ///< 0: top, 1: bottom ++ int ref_field_type[2]; ///< forward and backward reference field type (top or bottom) ++ int blocks_off, mb_off; ++ int qs_last; ///< if qpel has been used in the previous (tr.) picture ++ int bmvtype; ++ int frfd, brfd; ///< reference frame distance (forward or backward) ++ int pic_header_flag; ++ ++ /** Frame decoding info for sprite modes */ ++ //@{ ++ int new_sprite; ++ int two_sprites; ++ AVFrame sprite_output_frame; ++ int output_width, output_height, sprite_width, sprite_height; ++ uint8_t* sr_rows[2][2]; ///< Sprite resizer line cache ++ //@} ++ + int p_frame_skipped; + int bi_type; + int x8_type; + ++ DCTELEM (*block)[6][64]; ++ int n_allocated_blks, cur_blk_idx, left_blk_idx, topleft_blk_idx, top_blk_idx; + uint32_t *cbp_base, *cbp; +- uint8_t bfraction_lut_index;///< Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[]) +- uint8_t broken_link; ///< Broken link flag (BROKEN_LINK syntax element) +- uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element) ++ uint8_t *is_intra_base, *is_intra; ++ int16_t (*luma_mv_base)[2], (*luma_mv)[2]; ++ uint8_t bfraction_lut_index; ///< Index for BFRACTION value (see Table 40, reproduced into ff_vc1_bfraction_lut[]) ++ uint8_t broken_link; ///< Broken link flag (BROKEN_LINK syntax element) ++ uint8_t closed_entry; ///< Closed entry point flag (CLOSED_ENTRY syntax element) + +- int parse_only; ///< Context is used within parser ++ int parse_only; ///< Context is used within parser + + int warn_interlaced; + } VC1Context; +@@ -324,11 +404,12 @@ + { + uint32_t mrk = 0xFFFFFFFF; + +- if(end-src < 4) return end; +- while(src < end){ ++ if (end-src < 4) ++ return end; ++ while (src < end) { + mrk = (mrk << 8) | *src++; +- if(IS_MARKER(mrk)) +- return src-4; ++ if (IS_MARKER(mrk)) ++ return src - 4; + } + return end; + } +@@ -337,12 +418,13 @@ + { + int dsize = 0, i; + +- if(size < 4){ +- for(dsize = 0; dsize < size; dsize++) *dst++ = *src++; ++ if (size < 4) { ++ for (dsize = 0; dsize < size; dsize++) ++ *dst++ = *src++; + return size; + } +- for(i = 0; i < size; i++, src++) { +- if(src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) { ++ for (i = 0; i < size; i++, src++) { ++ if (src[0] == 3 && i >= 2 && !src[-1] && !src[-2] && i < size-1 && src[1] < 4) { + dst[dsize++] = src[1]; + src++; + i++; +@@ -365,5 +447,6 @@ + + int vc1_parse_frame_header (VC1Context *v, GetBitContext *gb); + int vc1_parse_frame_header_adv(VC1Context *v, GetBitContext *gb); ++int ff_vc1_init_common(VC1Context *v); + + #endif /* AVCODEC_VC1_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vc1_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vc1_parser.c 2012-05-14 14:08:54.308339458 +0200 +@@ -45,6 +45,7 @@ + vpc->v.s.avctx = avctx; + vpc->v.parse_only = 1; + next = buf; ++ s->repeat_pict = 0; + + for(start = buf, end = buf + buf_size; next < end; start = next){ + int buf2_size, size; +@@ -67,12 +68,26 @@ + else + vc1_parse_frame_header_adv(&vpc->v, &gb); + +- /* keep FF_BI_TYPE internal to VC1 */ +- if (vpc->v.s.pict_type == FF_BI_TYPE) +- s->pict_type = FF_B_TYPE; ++ /* keep AV_PICTURE_TYPE_BI internal to VC1 */ ++ if (vpc->v.s.pict_type == AV_PICTURE_TYPE_BI) ++ s->pict_type = AV_PICTURE_TYPE_B; + else + s->pict_type = vpc->v.s.pict_type; + ++ if (avctx->ticks_per_frame > 1){ ++ // process pulldown flags ++ s->repeat_pict = 1; ++ // Pulldown flags are only valid when 'broadcast' has been set. ++ // So ticks_per_frame will be 2 ++ if (vpc->v.rff){ ++ // repeat field ++ s->repeat_pict = 2; ++ }else if (vpc->v.rptfrm){ ++ // repeat frames ++ s->repeat_pict = vpc->v.rptfrm * 2 + 1; ++ } ++ } ++ + break; + } + } +@@ -81,7 +96,7 @@ + } + + /** +- * finds the end of the current frame in the bitstream. ++ * Find the end of the current frame in the bitstream. + * @return the position of the first byte of the next frame, or -1 + */ + static int vc1_find_frame_end(ParseContext *pc, const uint8_t *buf, +@@ -169,11 +184,18 @@ + return 0; + } + ++static int vc1_parse_init(AVCodecParserContext *s) ++{ ++ VC1ParseContext *vpc = s->priv_data; ++ vpc->v.s.slice_context_count = 1; ++ return ff_vc1_init_common(&vpc->v); ++} ++ + AVCodecParser ff_vc1_parser = { +- { CODEC_ID_VC1 }, +- sizeof(VC1ParseContext), +- NULL, +- vc1_parse, +- ff_parse1_close, +- vc1_split, ++ .codec_ids = { CODEC_ID_VC1 }, ++ .priv_data_size = sizeof(VC1ParseContext), ++ .parser_init = vc1_parse_init, ++ .parser_parse = vc1_parse, ++ .parser_close = ff_parse1_close, ++ .split = vc1_split, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vcr1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vcr1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vcr1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vcr1.c 2012-05-14 14:08:54.341340123 +0200 +@@ -56,12 +56,17 @@ + if(p->data[0]) + avctx->release_buffer(avctx, p); + ++ if(buf_size < 16 + avctx->height + avctx->width*avctx->height*5/8){ ++ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n"); ++ return AVERROR(EINVAL); ++ } ++ + p->reference= 0; + if(avctx->get_buffer(avctx, p) < 0){ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + for(i=0; i<16; i++){ +@@ -114,8 +119,6 @@ + *picture= *(AVFrame*)&a->picture; + *data_size = sizeof(AVPicture); + +- emms_c(); +- + return buf_size; + } + +@@ -127,12 +130,10 @@ + int size; + + *p = *pict; +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + +- emms_c(); +- +- align_put_bits(&a->pb); ++ avpriv_align_put_bits(&a->pb); + while(get_bit_count(&a->pb)&31) + put_bits(&a->pb, 8, 0); + +@@ -146,6 +147,7 @@ + VCR1Context * const a = avctx->priv_data; + + avctx->coded_frame= (AVFrame*)&a->picture; ++ avcodec_get_frame_defaults(&a->picture); + a->avctx= avctx; + } + +@@ -177,27 +179,25 @@ + #endif + + AVCodec ff_vcr1_decoder = { +- "vcr1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VCR1, +- sizeof(VCR1Context), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "vcr1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VCR1, ++ .priv_data_size = sizeof(VCR1Context), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"), + }; + + #if CONFIG_VCR1_ENCODER + AVCodec ff_vcr1_encoder = { +- "vcr1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VCR1, +- sizeof(VCR1Context), +- encode_init, +- encode_frame, +- //encode_end, ++ .name = "vcr1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VCR1, ++ .priv_data_size = sizeof(VCR1Context), ++ .init = encode_init, ++ .encode = encode_frame, + .long_name = NULL_IF_CONFIG_SMALL("ATI VCR1"), + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda.c 2012-05-14 14:08:54.342340143 +0200 +@@ -0,0 +1,275 @@ ++/* ++ * VDA HW acceleration. ++ * ++ * copyright (c) 2011 Sebastien Zwickert ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "libavutil/avutil.h" ++#include "vda_internal.h" ++ ++/* Helper to create a dictionary according to the given pts. */ ++static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts) ++{ ++ CFStringRef key = CFSTR("FF_VDA_DECODER_PTS_KEY"); ++ CFNumberRef value = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt64Type, &i_pts); ++ CFDictionaryRef user_info = CFDictionaryCreate(kCFAllocatorDefault, ++ (const void **)&key, ++ (const void **)&value, ++ 1, ++ &kCFTypeDictionaryKeyCallBacks, ++ &kCFTypeDictionaryValueCallBacks); ++ CFRelease(value); ++ return user_info; ++} ++ ++/* Helper to retrieve the pts from the given dictionary. */ ++static int64_t vda_pts_from_dictionary(CFDictionaryRef user_info) ++{ ++ CFNumberRef pts; ++ int64_t outValue = 0; ++ ++ if (!user_info) ++ return 0; ++ ++ pts = CFDictionaryGetValue(user_info, CFSTR("FF_VDA_DECODER_PTS_KEY")); ++ ++ if (pts) ++ CFNumberGetValue(pts, kCFNumberSInt64Type, &outValue); ++ ++ return outValue; ++} ++ ++/* Removes and releases all frames from the queue. */ ++static void vda_clear_queue(struct vda_context *vda_ctx) ++{ ++ vda_frame *top_frame; ++ ++ pthread_mutex_lock(&vda_ctx->queue_mutex); ++ ++ while (vda_ctx->queue) { ++ top_frame = vda_ctx->queue; ++ vda_ctx->queue = top_frame->next_frame; ++ ff_vda_release_vda_frame(top_frame); ++ } ++ ++ pthread_mutex_unlock(&vda_ctx->queue_mutex); ++} ++ ++ ++/* Decoder callback that adds the vda frame to the queue in display order. */ ++static void vda_decoder_callback (void *vda_hw_ctx, ++ CFDictionaryRef user_info, ++ OSStatus status, ++ uint32_t infoFlags, ++ CVImageBufferRef image_buffer) ++{ ++ struct vda_context *vda_ctx = (struct vda_context*)vda_hw_ctx; ++ vda_frame *new_frame; ++ vda_frame *queue_walker; ++ ++ if (!image_buffer) ++ return; ++ ++ if (vda_ctx->cv_pix_fmt_type != CVPixelBufferGetPixelFormatType(image_buffer)) ++ return; ++ ++ new_frame = av_mallocz(sizeof(vda_frame)); ++ if (!new_frame) ++ return; ++ ++ new_frame->next_frame = NULL; ++ new_frame->cv_buffer = CVPixelBufferRetain(image_buffer); ++ new_frame->pts = vda_pts_from_dictionary(user_info); ++ ++ pthread_mutex_lock(&vda_ctx->queue_mutex); ++ ++ queue_walker = vda_ctx->queue; ++ ++ if (!queue_walker || (new_frame->pts < queue_walker->pts)) { ++ /* we have an empty queue, or this frame earlier than the current queue head */ ++ new_frame->next_frame = queue_walker; ++ vda_ctx->queue = new_frame; ++ } else { ++ /* walk the queue and insert this frame where it belongs in display order */ ++ vda_frame *next_frame; ++ ++ while (1) { ++ next_frame = queue_walker->next_frame; ++ ++ if (!next_frame || (new_frame->pts < next_frame->pts)) { ++ new_frame->next_frame = next_frame; ++ queue_walker->next_frame = new_frame; ++ break; ++ } ++ queue_walker = next_frame; ++ } ++ } ++ ++ pthread_mutex_unlock(&vda_ctx->queue_mutex); ++} ++ ++int ff_vda_create_decoder(struct vda_context *vda_ctx, ++ uint8_t *extradata, ++ int extradata_size) ++{ ++ OSStatus status = kVDADecoderNoErr; ++ CFNumberRef height; ++ CFNumberRef width; ++ CFNumberRef format; ++ CFDataRef avc_data; ++ CFMutableDictionaryRef config_info; ++ CFMutableDictionaryRef buffer_attributes; ++ CFMutableDictionaryRef io_surface_properties; ++ CFNumberRef cv_pix_fmt; ++ ++ vda_ctx->bitstream = NULL; ++ vda_ctx->ref_size = 0; ++ ++ pthread_mutex_init(&vda_ctx->queue_mutex, NULL); ++ ++ if (extradata[4]==0xFE) { ++ // convert 3 byte NAL sizes to 4 byte ++ extradata[4] = 0xFF; ++ } ++ ++ config_info = CFDictionaryCreateMutable(kCFAllocatorDefault, ++ 4, ++ &kCFTypeDictionaryKeyCallBacks, ++ &kCFTypeDictionaryValueCallBacks); ++ ++ height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->height); ++ width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->width); ++ format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type, &vda_ctx->format); ++ avc_data = CFDataCreate(kCFAllocatorDefault, extradata, extradata_size); ++ ++ CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height); ++ CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width); ++ CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat, format); ++ CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData, avc_data); ++ ++ buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault, ++ 2, ++ &kCFTypeDictionaryKeyCallBacks, ++ &kCFTypeDictionaryValueCallBacks); ++ io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault, ++ 0, ++ &kCFTypeDictionaryKeyCallBacks, ++ &kCFTypeDictionaryValueCallBacks); ++ cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault, ++ kCFNumberSInt32Type, ++ &vda_ctx->cv_pix_fmt_type); ++ CFDictionarySetValue(buffer_attributes, ++ kCVPixelBufferPixelFormatTypeKey, ++ cv_pix_fmt); ++ CFDictionarySetValue(buffer_attributes, ++ kCVPixelBufferIOSurfacePropertiesKey, ++ io_surface_properties); ++ ++ status = VDADecoderCreate(config_info, ++ buffer_attributes, ++ (VDADecoderOutputCallback *)vda_decoder_callback, ++ vda_ctx, ++ &vda_ctx->decoder); ++ ++ CFRelease(height); ++ CFRelease(width); ++ CFRelease(format); ++ CFRelease(avc_data); ++ CFRelease(config_info); ++ CFRelease(io_surface_properties); ++ CFRelease(cv_pix_fmt); ++ CFRelease(buffer_attributes); ++ ++ if (kVDADecoderNoErr != status) ++ return status; ++ ++ return 0; ++} ++ ++int ff_vda_destroy_decoder(struct vda_context *vda_ctx) ++{ ++ OSStatus status = kVDADecoderNoErr; ++ ++ if (vda_ctx->decoder) ++ status = VDADecoderDestroy(vda_ctx->decoder); ++ ++ vda_clear_queue(vda_ctx); ++ ++ pthread_mutex_destroy(&vda_ctx->queue_mutex); ++ ++ if (vda_ctx->bitstream) ++ av_freep(&vda_ctx->bitstream); ++ ++ if (kVDADecoderNoErr != status) ++ return status; ++ ++ return 0; ++} ++ ++vda_frame *ff_vda_queue_pop(struct vda_context *vda_ctx) ++{ ++ vda_frame *top_frame; ++ ++ if (!vda_ctx->queue) ++ return NULL; ++ ++ pthread_mutex_lock(&vda_ctx->queue_mutex); ++ top_frame = vda_ctx->queue; ++ vda_ctx->queue = top_frame->next_frame; ++ pthread_mutex_unlock(&vda_ctx->queue_mutex); ++ ++ return top_frame; ++} ++ ++void ff_vda_release_vda_frame(vda_frame *frame) ++{ ++ if (frame) { ++ CVPixelBufferRelease(frame->cv_buffer); ++ av_freep(&frame); ++ } ++} ++ ++int ff_vda_decoder_decode(struct vda_context *vda_ctx, ++ uint8_t *bitstream, ++ int bitstream_size, ++ int64_t frame_pts) ++{ ++ OSStatus status = kVDADecoderNoErr; ++ CFDictionaryRef user_info; ++ CFDataRef coded_frame; ++ ++ coded_frame = CFDataCreate(kCFAllocatorDefault, bitstream, bitstream_size); ++ user_info = vda_dictionary_with_pts(frame_pts); ++ ++ status = VDADecoderDecode(vda_ctx->decoder, 0, coded_frame, user_info); ++ ++ CFRelease(user_info); ++ CFRelease(coded_frame); ++ ++ if (kVDADecoderNoErr != status) ++ return status; ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda.h 2012-05-14 14:08:54.343340163 +0200 +@@ -0,0 +1,168 @@ ++/* ++ * VDA HW acceleration ++ * ++ * copyright (c) 2011 Sebastien Zwickert ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_VDA_H ++#define AVCODEC_VDA_H ++ ++#include ++#include ++ ++// emmintrin.h is unable to compile with -std=c99 -Werror=missing-prototypes ++// http://openradar.appspot.com/8026390 ++#undef __GNUC_STDC_INLINE__ ++ ++#define Picture QuickdrawPicture ++#include ++#undef Picture ++ ++/** ++ * This structure is used to store a decoded frame information and data. ++ */ ++typedef struct { ++ /** ++ * The PTS of the frame. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ int64_t pts; ++ ++ /** ++ * The CoreVideo buffer that contains the decoded data. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ CVPixelBufferRef cv_buffer; ++ ++ /** ++ * A pointer to the next frame. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ struct vda_frame *next_frame; ++} vda_frame; ++ ++/** ++ * This structure is used to provide the necessary configurations and data ++ * to the VDA FFmpeg HWAccel implementation. ++ * ++ * The application must make it available as AVCodecContext.hwaccel_context. ++ */ ++struct vda_context { ++ /** ++ * VDA decoder object. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ VDADecoder decoder; ++ ++ /** ++ * VDA frames queue ordered by presentation timestamp. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ vda_frame *queue; ++ ++ /** ++ * Mutex for locking queue operations. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ pthread_mutex_t queue_mutex; ++ ++ /** ++ * The frame width. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by user. ++ */ ++ int width; ++ ++ /** ++ * The frame height. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by user. ++ */ ++ int height; ++ ++ /** ++ * The frame format. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by user. ++ */ ++ int format; ++ ++ /** ++ * The pixel format for output image buffers. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by user. ++ */ ++ OSType cv_pix_fmt_type; ++ ++ /** ++ * The current bitstream buffer. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ uint8_t *bitstream; ++ ++ /** ++ * The current size of the bitstream. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ int bitstream_size; ++ ++ /** ++ * The reference size used for fast reallocation. ++ * ++ * - encoding: unused ++ * - decoding: Set/Unset by libavcodec. ++ */ ++ int ref_size; ++}; ++ ++/** Create the video decoder. */ ++int ff_vda_create_decoder(struct vda_context *vda_ctx, ++ uint8_t *extradata, ++ int extradata_size); ++ ++/** Destroy the video decoder. */ ++int ff_vda_destroy_decoder(struct vda_context *vda_ctx); ++ ++/** Return the top frame of the queue. */ ++vda_frame *ff_vda_queue_pop(struct vda_context *vda_ctx); ++ ++/** Release the given frame. */ ++void ff_vda_release_vda_frame(vda_frame *frame); ++ ++#endif /* AVCODEC_VDA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda_h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda_h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda_h264.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda_h264.c 2012-05-14 14:08:54.344340183 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * VDA H264 HW acceleration. ++ * ++ * copyright (c) 2011 Sebastien Zwickert ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "h264.h" ++#include "vda_internal.h" ++ ++static int start_frame(AVCodecContext *avctx, ++ av_unused const uint8_t *buffer, ++ av_unused uint32_t size) ++{ ++ struct vda_context *vda_ctx = avctx->hwaccel_context; ++ ++ if (!vda_ctx->decoder) ++ return -1; ++ ++ vda_ctx->bitstream_size = 0; ++ ++ return 0; ++} ++ ++static int decode_slice(AVCodecContext *avctx, ++ const uint8_t *buffer, ++ uint32_t size) ++{ ++ struct vda_context *vda_ctx = avctx->hwaccel_context; ++ void *tmp; ++ ++ if (!vda_ctx->decoder) ++ return -1; ++ ++ tmp = av_fast_realloc(vda_ctx->bitstream, &vda_ctx->ref_size, vda_ctx->bitstream_size+size+4); ++ if (!tmp) ++ return AVERROR(ENOMEM); ++ ++ vda_ctx->bitstream = tmp; ++ ++ AV_WB32(vda_ctx->bitstream+vda_ctx->bitstream_size, size); ++ memcpy(vda_ctx->bitstream+vda_ctx->bitstream_size+4, buffer, size); ++ ++ vda_ctx->bitstream_size += size + 4; ++ ++ return 0; ++} ++ ++static int end_frame(AVCodecContext *avctx) ++{ ++ H264Context *h = avctx->priv_data; ++ struct vda_context *vda_ctx = avctx->hwaccel_context; ++ AVFrame *frame = &h->s.current_picture_ptr->f; ++ int status; ++ ++ if (!vda_ctx->decoder || !vda_ctx->bitstream) ++ return -1; ++ ++ status = ff_vda_decoder_decode(vda_ctx, vda_ctx->bitstream, ++ vda_ctx->bitstream_size, ++ frame->reordered_opaque); ++ ++ if (status) ++ av_log(avctx, AV_LOG_ERROR, "Failed to decode frame (%d)\n", status); ++ ++ return status; ++} ++ ++AVHWAccel ff_h264_vda_hwaccel = { ++ .name = "h264_vda", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .pix_fmt = PIX_FMT_VDA_VLD, ++ .start_frame = start_frame, ++ .decode_slice = decode_slice, ++ .end_frame = end_frame, ++ .priv_data_size = 0, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vda_internal.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vda_internal.h 2012-05-14 14:08:54.345340203 +0200 +@@ -0,0 +1,42 @@ ++/* ++ * VDA HW acceleration ++ * ++ * copyright (c) 2011 Sebastien Zwickert ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_VDA_INTERNAL_H ++#define AVCODEC_VDA_INTERNAL_H ++ ++#include "vda.h" ++ ++/** ++ * \addtogroup VDA_Decoding ++ * ++ * @{ ++ */ ++ ++/** Send frame data to the hardware decoder. */ ++int ff_vda_decoder_decode(struct vda_context *vda_ctx, ++ uint8_t *bitstream, ++ int bitstream_size, ++ int64_t frame_pts); ++ ++/* @} */ ++ ++#endif /* AVCODEC_VDA_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vdpau.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vdpau.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vdpau.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vdpau.c 2012-05-14 14:08:54.346340223 +0200 +@@ -33,7 +33,7 @@ + #include "vdpau_internal.h" + + /** +- * \addtogroup VDPAU_Decoding ++ * @addtogroup VDPAU_Decoding + * + * @{ + */ +@@ -46,7 +46,7 @@ + Picture *pic; + int i, list, pic_frame_idx; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + rf = &render->info.h264.referenceFrames[0]; +@@ -58,11 +58,11 @@ + + for (i = 0; i < ls; ++i) { + pic = lp[i]; +- if (!pic || !pic->reference) ++ if (!pic || !pic->f.reference) + continue; + pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num; + +- render_ref = (struct vdpau_render_state *)pic->data[0]; ++ render_ref = (struct vdpau_render_state *)pic->f.data[0]; + assert(render_ref); + + rf2 = &render->info.h264.referenceFrames[0]; +@@ -76,8 +76,8 @@ + ++rf2; + } + if (rf2 != rf) { +- rf2->top_is_reference |= (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; +- rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; ++ rf2->top_is_reference |= (pic->f.reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; ++ rf2->bottom_is_reference |= (pic->f.reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; + continue; + } + +@@ -86,8 +86,8 @@ + + rf->surface = render_ref->surface; + rf->is_long_term = pic->long_ref; +- rf->top_is_reference = (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; +- rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; ++ rf->top_is_reference = (pic->f.reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; ++ rf->bottom_is_reference = (pic->f.reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; + rf->field_order_cnt[0] = pic->field_poc[0]; + rf->field_order_cnt[1] = pic->field_poc[1]; + rf->frame_idx = pic_frame_idx; +@@ -112,7 +112,7 @@ + { + struct vdpau_render_state *render; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + render->bitstream_buffers= av_fast_realloc( +@@ -133,7 +133,7 @@ + struct vdpau_render_state *render; + int i; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + for (i = 0; i < 2; ++i) { +@@ -151,14 +151,14 @@ + H264Context *h = s->avctx->priv_data; + struct vdpau_render_state *render; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + render->info.h264.slice_count = h->slice_num; + if (render->info.h264.slice_count < 1) + return; + +- render->info.h264.is_reference = (s->current_picture_ptr->reference & 3) ? VDP_TRUE : VDP_FALSE; ++ render->info.h264.is_reference = (s->current_picture_ptr->f.reference & 3) ? VDP_TRUE : VDP_FALSE; + render->info.h264.field_pic_flag = s->picture_structure != PICT_FRAME; + render->info.h264.bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD; + render->info.h264.num_ref_frames = h->sps.ref_frame_count; +@@ -183,7 +183,8 @@ + render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; + render->info.h264.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present; + memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4)); +- memcpy(render->info.h264.scaling_lists_8x8, h->pps.scaling_matrix8, sizeof(render->info.h264.scaling_lists_8x8)); ++ memcpy(render->info.h264.scaling_lists_8x8[0], h->pps.scaling_matrix8[0], sizeof(render->info.h264.scaling_lists_8x8[0])); ++ memcpy(render->info.h264.scaling_lists_8x8[1], h->pps.scaling_matrix8[3], sizeof(render->info.h264.scaling_lists_8x8[0])); + + ff_draw_horiz_band(s, 0, s->avctx->height); + render->bitstream_buffers_used = 0; +@@ -197,7 +198,7 @@ + + if (!s->current_picture_ptr) return; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + /* fill VdpPictureInfoMPEG1Or2 struct */ +@@ -225,13 +226,13 @@ + render->info.mpeg.backward_reference = VDP_INVALID_HANDLE; + + switch(s->pict_type){ +- case FF_B_TYPE: +- next = (struct vdpau_render_state *)s->next_picture.data[0]; ++ case AV_PICTURE_TYPE_B: ++ next = (struct vdpau_render_state *)s->next_picture.f.data[0]; + assert(next); + render->info.mpeg.backward_reference = next->surface; + // no return here, going to set forward prediction +- case FF_P_TYPE: +- last = (struct vdpau_render_state *)s->last_picture.data[0]; ++ case AV_PICTURE_TYPE_P: ++ last = (struct vdpau_render_state *)s->last_picture.f.data[0]; + if (!last) // FIXME: Does this test make sense? + last = render; // predict second field from the first + render->info.mpeg.forward_reference = last->surface; +@@ -252,7 +253,7 @@ + VC1Context *v = s->avctx->priv_data; + struct vdpau_render_state *render, *last, *next; + +- render = (struct vdpau_render_state *)s->current_picture.data[0]; ++ render = (struct vdpau_render_state *)s->current_picture.f.data[0]; + assert(render); + + /* fill LvPictureInfoVC1 struct */ +@@ -295,13 +296,13 @@ + render->info.vc1.picture_type = s->pict_type - 1 + s->pict_type / 3; + + switch(s->pict_type){ +- case FF_B_TYPE: +- next = (struct vdpau_render_state *)s->next_picture.data[0]; ++ case AV_PICTURE_TYPE_B: ++ next = (struct vdpau_render_state *)s->next_picture.f.data[0]; + assert(next); + render->info.vc1.backward_reference = next->surface; + // no break here, going to set forward prediction +- case FF_P_TYPE: +- last = (struct vdpau_render_state *)s->last_picture.data[0]; ++ case AV_PICTURE_TYPE_P: ++ last = (struct vdpau_render_state *)s->last_picture.f.data[0]; + if (!last) // FIXME: Does this test make sense? + last = render; // predict second field from the first + render->info.vc1.forward_reference = last->surface; +@@ -324,7 +325,7 @@ + + if (!s->current_picture_ptr) return; + +- render = (struct vdpau_render_state *)s->current_picture_ptr->data[0]; ++ render = (struct vdpau_render_state *)s->current_picture_ptr->f.data[0]; + assert(render); + + /* fill VdpPictureInfoMPEG4Part2 struct */ +@@ -352,14 +353,14 @@ + render->info.mpeg4.backward_reference = VDP_INVALID_HANDLE; + + switch (s->pict_type) { +- case FF_B_TYPE: +- next = (struct vdpau_render_state *)s->next_picture.data[0]; ++ case AV_PICTURE_TYPE_B: ++ next = (struct vdpau_render_state *)s->next_picture.f.data[0]; + assert(next); + render->info.mpeg4.backward_reference = next->surface; + render->info.mpeg4.vop_coding_type = 2; + // no break here, going to set forward prediction +- case FF_P_TYPE: +- last = (struct vdpau_render_state *)s->last_picture.data[0]; ++ case AV_PICTURE_TYPE_P: ++ last = (struct vdpau_render_state *)s->last_picture.f.data[0]; + assert(last); + render->info.mpeg4.forward_reference = last->surface; + } +@@ -371,4 +372,40 @@ + } + #endif + ++// Only dummy functions for now ++static int vdpau_mpeg2_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) ++{ ++ return 0; ++} ++ ++static int vdpau_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) ++{ ++ return 0; ++} ++ ++static int vdpau_mpeg2_end_frame(AVCodecContext *avctx) ++{ ++ return 0; ++} ++ ++AVHWAccel ff_mpeg1_vdpau_hwaccel = { ++ .name = "mpeg1_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG1VIDEO, ++ .pix_fmt = PIX_FMT_VDPAU_MPEG1, ++ .start_frame = vdpau_mpeg2_start_frame, ++ .end_frame = vdpau_mpeg2_end_frame, ++ .decode_slice = vdpau_mpeg2_decode_slice, ++}; ++ ++AVHWAccel ff_mpeg2_vdpau_hwaccel = { ++ .name = "mpeg2_vdpau", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .pix_fmt = PIX_FMT_VDPAU_MPEG2, ++ .start_frame = vdpau_mpeg2_start_frame, ++ .end_frame = vdpau_mpeg2_end_frame, ++ .decode_slice = vdpau_mpeg2_decode_slice, ++}; ++ + /* @}*/ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vdpau.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vdpau.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vdpau.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vdpau.h 2012-05-14 14:08:54.350340303 +0200 +@@ -25,7 +25,7 @@ + #define AVCODEC_VDPAU_H + + /** +- * \defgroup Decoder VDPAU Decoder and Renderer ++ * @defgroup Decoder VDPAU Decoder and Renderer + * + * VDPAU hardware acceleration has two modules + * - VDPAU decoding +@@ -38,25 +38,25 @@ + * and rendering (API calls) are done as part of the VDPAU + * presentation (vo_vdpau.c) module. + * +- * \defgroup VDPAU_Decoding VDPAU Decoding +- * \ingroup Decoder ++ * @defgroup VDPAU_Decoding VDPAU Decoding ++ * @ingroup Decoder + * @{ + */ + + #include + #include + +-/** \brief The videoSurface is used for rendering. */ ++/** @brief The videoSurface is used for rendering. */ + #define FF_VDPAU_STATE_USED_FOR_RENDER 1 + + /** +- * \brief The videoSurface is needed for reference/prediction. ++ * @brief The videoSurface is needed for reference/prediction. + * The codec manipulates this. + */ + #define FF_VDPAU_STATE_USED_FOR_REFERENCE 2 + + /** +- * \brief This structure is used as a callback between the FFmpeg ++ * @brief This structure is used as a callback between the FFmpeg + * decoder (vd_) and presentation (vo_) module. + * This is used for defining a video frame containing surface, + * picture parameter, bitstream information etc which are passed +@@ -67,6 +67,13 @@ + + int state; ///< Holds FF_VDPAU_STATE_* values. + ++ /** Describe size/location of the compressed video data. ++ Set to 0 when freeing bitstream_buffers. */ ++ int bitstream_buffers_allocated; ++ int bitstream_buffers_used; ++ /** The user is responsible for freeing this buffer using av_freep(). */ ++ VdpBitstreamBuffer *bitstream_buffers; ++ + /** picture parameter information for all supported codecs */ + union VdpPictureInfo { + VdpPictureInfoH264 h264; +@@ -76,13 +83,6 @@ + VdpPictureInfoMPEG4Part2 mpeg4; + #endif + } info; +- +- /** Describe size/location of the compressed video data. +- Set to 0 when freeing bitstream_buffers. */ +- int bitstream_buffers_allocated; +- int bitstream_buffers_used; +- /** The user is responsible for freeing this buffer using av_freep(). */ +- VdpBitstreamBuffer *bitstream_buffers; + }; + + /* @}*/ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/version.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/version.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/version.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/version.h 2012-05-14 14:08:54.351340324 +0200 +@@ -0,0 +1,130 @@ ++/* ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_VERSION_H ++#define AVCODEC_VERSION_H ++ ++#define LIBAVCODEC_VERSION_MAJOR 53 ++#define LIBAVCODEC_VERSION_MINOR 61 ++#define LIBAVCODEC_VERSION_MICRO 100 ++ ++#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ ++ LIBAVCODEC_VERSION_MINOR, \ ++ LIBAVCODEC_VERSION_MICRO) ++#define LIBAVCODEC_VERSION AV_VERSION(LIBAVCODEC_VERSION_MAJOR, \ ++ LIBAVCODEC_VERSION_MINOR, \ ++ LIBAVCODEC_VERSION_MICRO) ++#define LIBAVCODEC_BUILD LIBAVCODEC_VERSION_INT ++ ++#define LIBAVCODEC_IDENT "Lavc" AV_STRINGIFY(LIBAVCODEC_VERSION) ++ ++/** ++ * Those FF_API_* defines are not part of public API. ++ * They may change, break or disappear at any time. ++ */ ++#ifndef FF_API_PALETTE_CONTROL ++#define FF_API_PALETTE_CONTROL (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_SAMPLE_FMT ++#define FF_API_OLD_SAMPLE_FMT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_AUDIOCONVERT ++#define FF_API_OLD_AUDIOCONVERT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_ANTIALIAS_ALGO ++#define FF_API_ANTIALIAS_ALGO (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_REQUEST_CHANNELS ++#define FF_API_REQUEST_CHANNELS (LIBAVCODEC_VERSION_MAJOR < 55) ++#endif ++#ifndef FF_API_OPT_H ++#define FF_API_OPT_H (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_THREAD_INIT ++#define FF_API_THREAD_INIT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_FF_PICT_TYPES ++#define FF_API_OLD_FF_PICT_TYPES (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_FLAC_GLOBAL_OPTS ++#define FF_API_FLAC_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_GET_PIX_FMT_NAME ++#define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_ALLOC_CONTEXT ++#define FF_API_ALLOC_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_AVCODEC_OPEN ++#define FF_API_AVCODEC_OPEN (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_DRC_SCALE ++#define FF_API_DRC_SCALE (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_ER ++#define FF_API_ER (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_AVCODEC_INIT ++#define FF_API_AVCODEC_INIT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_X264_GLOBAL_OPTS ++#define FF_API_X264_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_MPEGVIDEO_GLOBAL_OPTS ++#define FF_API_MPEGVIDEO_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_LAME_GLOBAL_OPTS ++#define FF_API_LAME_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_SNOW_GLOBAL_OPTS ++#define FF_API_SNOW_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_MJPEG_GLOBAL_OPTS ++#define FF_API_MJPEG_GLOBAL_OPTS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_GET_ALPHA_INFO ++#define FF_API_GET_ALPHA_INFO (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_PARSE_FRAME ++#define FF_API_PARSE_FRAME (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_INTERNAL_CONTEXT ++#define FF_API_INTERNAL_CONTEXT (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_TIFFENC_COMPLEVEL ++#define FF_API_TIFFENC_COMPLEVEL (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_DATA_POINTERS ++#define FF_API_DATA_POINTERS (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_DECODE_AUDIO ++#define FF_API_OLD_DECODE_AUDIO (LIBAVCODEC_VERSION_MAJOR < 55) ++#endif ++#ifndef FF_API_OLD_TIMECODE ++#define FF_API_OLD_TIMECODE (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++ ++#ifndef FF_API_AVFRAME_AGE ++#define FF_API_AVFRAME_AGE (LIBAVCODEC_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_ENCODE_AUDIO ++#define FF_API_OLD_ENCODE_AUDIO (LIBAVCODEC_VERSION_MAJOR < 55) ++#endif ++ ++#endif /* AVCODEC_VERSION_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vmdav.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vmdav.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vmdav.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vmdav.c 2012-05-14 14:08:54.353340364 +0200 +@@ -72,9 +72,11 @@ + #define QUEUE_SIZE 0x1000 + #define QUEUE_MASK 0x0FFF + +-static void lz_unpack(const unsigned char *src, unsigned char *dest, int dest_len) ++static void lz_unpack(const unsigned char *src, int src_len, ++ unsigned char *dest, int dest_len) + { + const unsigned char *s; ++ const unsigned char *s_end; + unsigned char *d; + unsigned char *d_end; + unsigned char queue[QUEUE_SIZE]; +@@ -87,8 +89,12 @@ + unsigned int i, j; + + s = src; ++ s_end = src + src_len; + d = dest; + d_end = d + dest_len; ++ ++ if (s_end - s < 8) ++ return; + dataleft = AV_RL32(s); + s += 4; + memset(queue, 0x20, QUEUE_SIZE); +@@ -101,10 +107,10 @@ + speclen = 100; /* no speclen */ + } + +- while (dataleft > 0) { ++ while (s_end - s > 0 && dataleft > 0) { + tag = *s++; + if ((tag == 0xFF) && (dataleft > 8)) { +- if (d + 8 > d_end) ++ if (d_end - d < 8 || s_end - s < 8) + return; + for (i = 0; i < 8; i++) { + queue[qpos++] = *d++ = *s++; +@@ -116,18 +122,23 @@ + if (dataleft == 0) + break; + if (tag & 0x01) { +- if (d + 1 > d_end) ++ if (d_end - d < 1 || s_end - s < 1) + return; + queue[qpos++] = *d++ = *s++; + qpos &= QUEUE_MASK; + dataleft--; + } else { ++ if (s_end - s < 2) ++ return; + chainofs = *s++; + chainofs |= ((*s & 0xF0) << 4); + chainlen = (*s++ & 0x0F) + 3; +- if (chainlen == speclen) ++ if (chainlen == speclen) { ++ if (s_end - s < 1) ++ return; + chainlen = *s++ + 0xF + 3; +- if (d + chainlen > d_end) ++ } ++ if (d_end - d < chainlen) + return; + for (j = 0; j < chainlen; j++) { + *d = queue[chainofs++ & QUEUE_MASK]; +@@ -142,32 +153,39 @@ + } + } + +-static int rle_unpack(const unsigned char *src, unsigned char *dest, +- int src_len, int dest_len) ++static int rle_unpack(const unsigned char *src, int src_len, int src_count, ++ unsigned char *dest, int dest_len) + { + const unsigned char *ps; ++ const unsigned char *ps_end; + unsigned char *pd; + int i, l; + unsigned char *dest_end = dest + dest_len; + + ps = src; ++ ps_end = src + src_len; + pd = dest; +- if (src_len & 1) ++ if (src_count & 1) { ++ if (ps_end - ps < 1) ++ return 0; + *pd++ = *ps++; ++ } + +- src_len >>= 1; ++ src_count >>= 1; + i = 0; + do { ++ if (ps_end - ps < 1) ++ break; + l = *ps++; + if (l & 0x80) { + l = (l & 0x7F) * 2; +- if (pd + l > dest_end) ++ if (dest_end - pd < l || ps_end - ps < l) + return ps - src; + memcpy(pd, ps, l); + ps += l; + pd += l; + } else { +- if (pd + i > dest_end) ++ if (dest_end - pd < i || ps_end - ps < 2) + return ps - src; + for (i = 0; i < l; i++) { + *pd++ = ps[0]; +@@ -176,7 +194,7 @@ + ps += 2; + } + i += l; +- } while (i < src_len); ++ } while (i < src_count); + + return ps - src; + } +@@ -189,8 +207,10 @@ + + /* point to the start of the encoded data */ + const unsigned char *p = s->buf + 16; ++ const unsigned char *p_end = s->buf + s->size; + + const unsigned char *pb; ++ const unsigned char *pb_end; + unsigned char meth; + unsigned char *dp; /* pointer to current frame */ + unsigned char *pp; /* pointer to previous frame */ +@@ -199,12 +219,21 @@ + + int frame_x, frame_y; + int frame_width, frame_height; +- int dp_size; + + frame_x = AV_RL16(&s->buf[6]); + frame_y = AV_RL16(&s->buf[8]); + frame_width = AV_RL16(&s->buf[10]) - frame_x + 1; + frame_height = AV_RL16(&s->buf[12]) - frame_y + 1; ++ if (frame_x < 0 || frame_width < 0 || ++ frame_x >= s->avctx->width || ++ frame_width > s->avctx->width || ++ frame_x + frame_width > s->avctx->width) ++ return; ++ if (frame_y < 0 || frame_height < 0 || ++ frame_y >= s->avctx->height || ++ frame_height > s->avctx->height || ++ frame_y + frame_height > s->avctx->height) ++ return; + + if ((frame_width == s->avctx->width && frame_height == s->avctx->height) && + (frame_x || frame_y)) { +@@ -217,8 +246,9 @@ + + /* if only a certain region will be updated, copy the entire previous + * frame before the decode */ +- if (frame_x || frame_y || (frame_width != s->avctx->width) || +- (frame_height != s->avctx->height)) { ++ if (s->prev_frame.data[0] && ++ (frame_x || frame_y || (frame_width != s->avctx->width) || ++ (frame_height != s->avctx->height))) { + + memcpy(s->frame.data[0], s->prev_frame.data[0], + s->avctx->height * s->frame.linesize[0]); +@@ -226,45 +256,50 @@ + + /* check if there is a new palette */ + if (s->buf[15] & 0x02) { ++ if (p_end - p < 2 + 3 * PALETTE_COUNT) ++ return; + p += 2; + palette32 = (unsigned int *)s->palette; + for (i = 0; i < PALETTE_COUNT; i++) { + r = *p++ * 4; + g = *p++ * 4; + b = *p++ * 4; +- palette32[i] = (r << 16) | (g << 8) | (b); ++ palette32[i] = 0xFF << 24 | r << 16 | g << 8 | b; ++ palette32[i] |= palette32[i] >> 6 & 0x30303; + } +- s->size -= (256 * 3 + 2); + } +- if (s->size >= 0) { ++ if (p < p_end) { + /* originally UnpackFrame in VAG's code */ + pb = p; ++ pb_end = p_end; + meth = *pb++; + if (meth & 0x80) { +- lz_unpack(pb, s->unpack_buffer, s->unpack_buffer_size); ++ lz_unpack(pb, p_end - pb, s->unpack_buffer, s->unpack_buffer_size); + meth &= 0x7F; + pb = s->unpack_buffer; ++ pb_end = s->unpack_buffer + s->unpack_buffer_size; + } + + dp = &s->frame.data[0][frame_y * s->frame.linesize[0] + frame_x]; +- dp_size = s->frame.linesize[0] * s->avctx->height; + pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x]; + switch (meth) { + case 1: + for (i = 0; i < frame_height; i++) { + ofs = 0; + do { ++ if (pb_end - pb < 1) ++ return; + len = *pb++; + if (len & 0x80) { + len = (len & 0x7F) + 1; +- if (ofs + len > frame_width) ++ if (ofs + len > frame_width || pb_end - pb < len) + return; + memcpy(&dp[ofs], pb, len); + pb += len; + ofs += len; + } else { + /* interframe pixel copy */ +- if (ofs + len + 1 > frame_width) ++ if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) + return; + memcpy(&dp[ofs], &pp[ofs], len + 1); + ofs += len + 1; +@@ -282,6 +317,8 @@ + + case 2: + for (i = 0; i < frame_height; i++) { ++ if (pb_end -pb < frame_width) ++ return; + memcpy(dp, pb, frame_width); + pb += frame_width; + dp += s->frame.linesize[0]; +@@ -293,18 +330,25 @@ + for (i = 0; i < frame_height; i++) { + ofs = 0; + do { ++ if (pb_end - pb < 1) ++ return; + len = *pb++; + if (len & 0x80) { + len = (len & 0x7F) + 1; ++ if (pb_end - pb < 1) ++ return; + if (*pb++ == 0xFF) +- len = rle_unpack(pb, &dp[ofs], len, frame_width - ofs); +- else ++ len = rle_unpack(pb, pb_end - pb, len, &dp[ofs], frame_width - ofs); ++ else { ++ if (pb_end - pb < len) ++ return; + memcpy(&dp[ofs], pb, len); ++ } + pb += len; + ofs += len; + } else { + /* interframe pixel copy */ +- if (ofs + len + 1 > frame_width) ++ if (ofs + len + 1 > frame_width || !s->prev_frame.data[0]) + return; + memcpy(&dp[ofs], &pp[ofs], len + 1); + ofs += len + 1; +@@ -358,6 +402,9 @@ + palette32[i] = (r << 16) | (g << 8) | (b); + } + ++ avcodec_get_frame_defaults(&s->frame); ++ avcodec_get_frame_defaults(&s->prev_frame); ++ + return 0; + } + +@@ -375,7 +422,7 @@ + if (buf_size < 16) + return buf_size; + +- s->frame.reference = 1; ++ s->frame.reference = 3; + if (avctx->get_buffer(avctx, &s->frame)) { + av_log(s->avctx, AV_LOG_ERROR, "VMD Video: get_buffer() failed\n"); + return -1; +@@ -414,12 +461,14 @@ + * Audio Decoder + */ + ++#define BLOCK_TYPE_AUDIO 1 ++#define BLOCK_TYPE_INITIAL 2 ++#define BLOCK_TYPE_SILENCE 3 ++ + typedef struct VmdAudioContext { +- AVCodecContext *avctx; +- int channels; +- int bits; +- int block_align; +- int predictors[2]; ++ AVFrame frame; ++ int out_bps; ++ int chunk_size; + } VmdAudioContext; + + static const uint16_t vmdaudio_table[128] = { +@@ -442,122 +491,150 @@ + { + VmdAudioContext *s = avctx->priv_data; + +- s->avctx = avctx; +- s->channels = avctx->channels; +- s->bits = avctx->bits_per_coded_sample; +- s->block_align = avctx->block_align; +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- +- av_log(s->avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, block align = %d, sample rate = %d\n", +- s->channels, s->bits, s->block_align, avctx->sample_rate); ++ if (avctx->channels < 1 || avctx->channels > 2) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ if (avctx->block_align < 1) { ++ av_log(avctx, AV_LOG_ERROR, "invalid block align\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (avctx->bits_per_coded_sample == 16) ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ else ++ avctx->sample_fmt = AV_SAMPLE_FMT_U8; ++ s->out_bps = av_get_bytes_per_sample(avctx->sample_fmt); ++ ++ s->chunk_size = avctx->block_align + avctx->channels * (s->out_bps == 2); ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ ++ av_log(avctx, AV_LOG_DEBUG, "%d channels, %d bits/sample, " ++ "block align = %d, sample rate = %d\n", ++ avctx->channels, avctx->bits_per_coded_sample, avctx->block_align, ++ avctx->sample_rate); + + return 0; + } + +-static void vmdaudio_decode_audio(VmdAudioContext *s, unsigned char *data, +- const uint8_t *buf, int buf_size, int stereo) ++static void decode_audio_s16(int16_t *out, const uint8_t *buf, int buf_size, ++ int channels) + { +- int i; +- int chan = 0; +- int16_t *out = (int16_t*)data; +- +- for(i = 0; i < buf_size; i++) { +- if(buf[i] & 0x80) +- s->predictors[chan] -= vmdaudio_table[buf[i] & 0x7F]; ++ int ch; ++ const uint8_t *buf_end = buf + buf_size; ++ int predictor[2]; ++ int st = channels - 1; ++ ++ /* decode initial raw sample */ ++ for (ch = 0; ch < channels; ch++) { ++ predictor[ch] = (int16_t)AV_RL16(buf); ++ buf += 2; ++ *out++ = predictor[ch]; ++ } ++ ++ /* decode DPCM samples */ ++ ch = 0; ++ while (buf < buf_end) { ++ uint8_t b = *buf++; ++ if (b & 0x80) ++ predictor[ch] -= vmdaudio_table[b & 0x7F]; + else +- s->predictors[chan] += vmdaudio_table[buf[i]]; +- s->predictors[chan] = av_clip_int16(s->predictors[chan]); +- out[i] = s->predictors[chan]; +- chan ^= stereo; ++ predictor[ch] += vmdaudio_table[b]; ++ predictor[ch] = av_clip_int16(predictor[ch]); ++ *out++ = predictor[ch]; ++ ch ^= st; + } + } + +-static int vmdaudio_loadsound(VmdAudioContext *s, unsigned char *data, +- const uint8_t *buf, int silence, int data_size) ++static int vmdaudio_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { +- int bytes_decoded = 0; +- int i; ++ const uint8_t *buf = avpkt->data; ++ const uint8_t *buf_end; ++ int buf_size = avpkt->size; ++ VmdAudioContext *s = avctx->priv_data; ++ int block_type, silent_chunks, audio_chunks; ++ int ret; ++ uint8_t *output_samples_u8; ++ int16_t *output_samples_s16; ++ ++ if (buf_size < 16) { ++ av_log(avctx, AV_LOG_WARNING, "skipping small junk packet\n"); ++ *got_frame_ptr = 0; ++ return buf_size; ++ } + +-// if (silence) +-// av_log(s->avctx, AV_LOG_INFO, "silent block!\n"); +- if (s->channels == 2) { +- +- /* stereo handling */ +- if (silence) { +- memset(data, 0, data_size * 2); ++ block_type = buf[6]; ++ if (block_type < BLOCK_TYPE_AUDIO || block_type > BLOCK_TYPE_SILENCE) { ++ av_log(avctx, AV_LOG_ERROR, "unknown block type: %d\n", block_type); ++ return AVERROR(EINVAL); ++ } ++ buf += 16; ++ buf_size -= 16; ++ ++ /* get number of silent chunks */ ++ silent_chunks = 0; ++ if (block_type == BLOCK_TYPE_INITIAL) { ++ uint32_t flags; ++ if (buf_size < 4) { ++ av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ flags = AV_RB32(buf); ++ silent_chunks = av_popcount(flags); ++ buf += 4; ++ buf_size -= 4; ++ } else if (block_type == BLOCK_TYPE_SILENCE) { ++ silent_chunks = 1; ++ buf_size = 0; // should already be zero but set it just to be sure ++ } ++ ++ /* ensure output buffer is large enough */ ++ audio_chunks = buf_size / s->chunk_size; ++ ++ /* get output buffer */ ++ s->frame.nb_samples = ((silent_chunks + audio_chunks) * avctx->block_align) / avctx->channels; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ output_samples_u8 = s->frame.data[0]; ++ output_samples_s16 = (int16_t *)s->frame.data[0]; ++ ++ /* decode silent chunks */ ++ if (silent_chunks > 0) { ++ int silent_size = avctx->block_align * silent_chunks; ++ if (s->out_bps == 2) { ++ memset(output_samples_s16, 0x00, silent_size * 2); ++ output_samples_s16 += silent_size; + } else { +- if (s->bits == 16) +- vmdaudio_decode_audio(s, data, buf, data_size, 1); +- else { +- /* copy the data but convert it to signed */ +- for (i = 0; i < data_size; i++){ +- *data++ = buf[i] + 0x80; +- *data++ = buf[i] + 0x80; +- } +- } ++ memset(output_samples_u8, 0x80, silent_size); ++ output_samples_u8 += silent_size; + } +- } else { +- bytes_decoded = data_size * 2; ++ } + +- /* mono handling */ +- if (silence) { +- memset(data, 0, data_size * 2); +- } else { +- if (s->bits == 16) { +- vmdaudio_decode_audio(s, data, buf, data_size, 0); ++ /* decode audio chunks */ ++ if (audio_chunks > 0) { ++ buf_end = buf + buf_size; ++ while ( buf_end - buf >= s->chunk_size) { ++ if (s->out_bps == 2) { ++ decode_audio_s16(output_samples_s16, buf, s->chunk_size, ++ avctx->channels); ++ output_samples_s16 += avctx->block_align; + } else { +- /* copy the data but convert it to signed */ +- for (i = 0; i < data_size; i++){ +- *data++ = buf[i] + 0x80; +- *data++ = buf[i] + 0x80; +- } ++ memcpy(output_samples_u8, buf, s->chunk_size); ++ output_samples_u8 += avctx->block_align; + } ++ buf += s->chunk_size; + } + } + +- return data_size * 2; +-} ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + +-static int vmdaudio_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) +-{ +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- VmdAudioContext *s = avctx->priv_data; +- unsigned char *output_samples = (unsigned char *)data; +- +- /* point to the start of the encoded data */ +- const unsigned char *p = buf + 16; +- +- if (buf_size < 16) +- return buf_size; +- +- if (buf[6] == 1) { +- /* the chunk contains audio */ +- *data_size = vmdaudio_loadsound(s, output_samples, p, 0, buf_size - 16); +- } else if (buf[6] == 2) { +- /* initial chunk, may contain audio and silence */ +- uint32_t flags = AV_RB32(p); +- int raw_block_size = s->block_align * s->bits / 8; +- int silent_chunks; +- if(flags == 0xFFFFFFFF) +- silent_chunks = 32; +- else +- silent_chunks = av_log2(flags + 1); +- if(*data_size < (s->block_align*silent_chunks + buf_size - 20) * 2) +- return -1; +- *data_size = 0; +- memset(output_samples, 0, raw_block_size * silent_chunks); +- output_samples += raw_block_size * silent_chunks; +- *data_size = raw_block_size * silent_chunks; +- *data_size += vmdaudio_loadsound(s, output_samples, p + 4, 0, buf_size - 20); +- } else if (buf[6] == 3) { +- /* silent chunk */ +- *data_size = vmdaudio_loadsound(s, output_samples, p, 1, 0); +- } +- +- return buf_size; ++ return avpkt->size; + } + + +@@ -566,26 +643,24 @@ + */ + + AVCodec ff_vmdvideo_decoder = { +- "vmdvideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VMDVIDEO, +- sizeof(VmdVideoContext), +- vmdvideo_decode_init, +- NULL, +- vmdvideo_decode_end, +- vmdvideo_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vmdvideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VMDVIDEO, ++ .priv_data_size = sizeof(VmdVideoContext), ++ .init = vmdvideo_decode_init, ++ .close = vmdvideo_decode_end, ++ .decode = vmdvideo_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD video"), + }; + + AVCodec ff_vmdaudio_decoder = { +- "vmdaudio", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_VMDAUDIO, +- sizeof(VmdAudioContext), +- vmdaudio_decode_init, +- NULL, +- NULL, +- vmdaudio_decode_frame, ++ .name = "vmdaudio", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_VMDAUDIO, ++ .priv_data_size = sizeof(VmdAudioContext), ++ .init = vmdaudio_decode_init, ++ .decode = vmdaudio_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD audio"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vmnc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vmnc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vmnc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vmnc.c 2012-05-14 14:08:54.354340384 +0200 +@@ -293,7 +293,7 @@ + const uint8_t *src = buf; + int dx, dy, w, h, depth, enc, chunks, res, size_left; + +- c->pic.reference = 1; ++ c->pic.reference = 3; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE; + if(avctx->reget_buffer(avctx, &c->pic) < 0){ + av_log(avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); +@@ -301,7 +301,7 @@ + } + + c->pic.key_frame = 0; +- c->pic.pict_type = FF_P_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_P; + + //restore screen after cursor + if(c->screendta) { +@@ -374,7 +374,7 @@ + break; + case MAGIC_WMVi: // ServerInitialization struct + c->pic.key_frame = 1; +- c->pic.pict_type = FF_I_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_I; + depth = *src++; + if(depth != c->bpp) { + av_log(avctx, AV_LOG_INFO, "Depth mismatch. Container %i bpp, Frame data: %i bpp\n", c->bpp, depth); +@@ -470,6 +470,7 @@ + + c->bpp = avctx->bits_per_coded_sample; + c->bpp2 = c->bpp/8; ++ avcodec_get_frame_defaults(&c->pic); + + switch(c->bpp){ + case 8: +@@ -483,6 +484,7 @@ + break; + default: + av_log(avctx, AV_LOG_ERROR, "Unsupported bitdepth %i\n", c->bpp); ++ return AVERROR_INVALIDDATA; + } + + return 0; +@@ -509,15 +511,14 @@ + } + + AVCodec ff_vmnc_decoder = { +- "vmnc", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VMNC, +- sizeof(VmncContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "vmnc", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VMNC, ++ .priv_data_size = sizeof(VmncContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("VMware Screen Codec / VMware Video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis.c 2012-05-14 14:08:54.355340404 +0200 +@@ -20,10 +20,13 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#undef V_DEBUG +-//#define V_DEBUG ++/** ++ * @file ++ * Common code for Vorbis I encoder and decoder ++ * @author Denes Balatoni ( dbalatoni programozo hu ) ++ */ + +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "avcodec.h" + #include "get_bits.h" + +@@ -51,16 +54,13 @@ + // the two bits[p] > 32 checks should be redundant, all calling code should + // already ensure that, but since it allows overwriting the stack it seems + // reasonable to check redundantly. +-int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num) ++int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num) + { +- uint_fast32_t exit_at_level[33] = { +- 404, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, +- 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; ++ uint32_t exit_at_level[33] = { 404 }; + +- uint_fast8_t i, j; +- uint_fast32_t code, p; ++ unsigned i, j, p, code; + +-#ifdef V_DEBUG ++#ifdef DEBUG + GetBitContext gb; + #endif + +@@ -77,9 +77,9 @@ + for (i = 0; i < bits[p]; ++i) + exit_at_level[i+1] = 1 << i; + +-#ifdef V_DEBUG +- av_log(NULL, AV_LOG_INFO, " %d. of %d code len %d code %d - ", p, num, bits[p], codes[p]); +- init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); ++#ifdef DEBUG ++ av_log(NULL, AV_LOG_INFO, " %u. of %u code len %d code %d - ", p, num, bits[p], codes[p]); ++ init_get_bits(&gb, (uint8_t *)&codes[p], bits[p]); + for (i = 0; i < bits[p]; ++i) + av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); + av_log(NULL, AV_LOG_INFO, "\n"); +@@ -105,9 +105,9 @@ + exit_at_level[j] = code + (1 << (j - 1)); + codes[p] = code; + +-#ifdef V_DEBUG ++#ifdef DEBUG + av_log(NULL, AV_LOG_INFO, " %d. code len %d code %d - ", p, bits[p], codes[p]); +- init_get_bits(&gb, (uint_fast8_t *)&codes[p], bits[p]); ++ init_get_bits(&gb, (uint8_t *)&codes[p], bits[p]); + for (i = 0; i < bits[p]; ++i) + av_log(NULL, AV_LOG_INFO, "%s", get_bits1(&gb) ? "1" : "0"); + av_log(NULL, AV_LOG_INFO, "\n"); +@@ -156,7 +156,7 @@ + } + } + +-static inline void render_line_unrolled(intptr_t x, intptr_t y, int x1, ++static inline void render_line_unrolled(intptr_t x, int y, int x1, + intptr_t sy, int ady, int adx, + float *buf) + { +@@ -168,14 +168,14 @@ + if (err >= 0) { + err += ady - adx; + y += sy; +- buf[x++] = ff_vorbis_floor1_inverse_db_table[y]; ++ buf[x++] = ff_vorbis_floor1_inverse_db_table[av_clip_uint8(y)]; + } +- buf[x] = ff_vorbis_floor1_inverse_db_table[y]; ++ buf[x] = ff_vorbis_floor1_inverse_db_table[av_clip_uint8(y)]; + } + if (x <= 0) { + if (err + ady >= 0) + y += sy; +- buf[x] = ff_vorbis_floor1_inverse_db_table[y]; ++ buf[x] = ff_vorbis_floor1_inverse_db_table[av_clip_uint8(y)]; + } + } + +@@ -185,14 +185,14 @@ + int adx = x1 - x0; + int ady = FFABS(dy); + int sy = dy < 0 ? -1 : 1; +- buf[x0] = ff_vorbis_floor1_inverse_db_table[y0]; ++ buf[x0] = ff_vorbis_floor1_inverse_db_table[av_clip_uint8(y0)]; + if (ady*2 <= adx) { // optimized common case + render_line_unrolled(x0, y0, x1, sy, ady, adx, buf); + } else { +- int base = dy / adx; +- int x = x0; +- int y = y0; +- int err = -adx; ++ int base = dy / adx; ++ int x = x0; ++ int y = y0; ++ int err = -adx; + ady -= FFABS(base) * adx; + while (++x < x1) { + y += base; +@@ -201,13 +201,13 @@ + err -= adx; + y += sy; + } +- buf[x] = ff_vorbis_floor1_inverse_db_table[y]; ++ buf[x] = ff_vorbis_floor1_inverse_db_table[av_clip_uint8(y)]; + } + } + } + + void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, +- uint_fast16_t *y_list, int *flag, ++ uint16_t *y_list, int *flag, + int multiplier, float *out, int samples) + { + int lx, ly, i; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_data.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_data.c 2012-05-14 14:08:54.358340464 +0200 +@@ -20,6 +20,7 @@ + + #include "dsputil.h" + #include "vorbis.h" ++#include "libavutil/audioconvert.h" + + const uint8_t ff_vorbis_channel_layout_offsets[8][8] = { + { 0 }, +@@ -43,15 +44,15 @@ + { 0, 2, 1, 6, 7, 4, 5, 3 }, + }; + +-const int64_t ff_vorbis_channel_layouts[9] = { +- CH_LAYOUT_MONO, +- CH_LAYOUT_STEREO, +- CH_LAYOUT_SURROUND, +- CH_LAYOUT_QUAD, +- CH_LAYOUT_5POINT0_BACK, +- CH_LAYOUT_5POINT1_BACK, +- CH_LAYOUT_5POINT1|CH_BACK_CENTER, +- CH_LAYOUT_7POINT1, ++const uint64_t ff_vorbis_channel_layouts[9] = { ++ AV_CH_LAYOUT_MONO, ++ AV_CH_LAYOUT_STEREO, ++ AV_CH_LAYOUT_SURROUND, ++ AV_CH_LAYOUT_QUAD, ++ AV_CH_LAYOUT_5POINT0_BACK, ++ AV_CH_LAYOUT_5POINT1_BACK, ++ AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER, ++ AV_CH_LAYOUT_7POINT1, + 0 + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_dec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_dec.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,1672 +0,0 @@ +-/** +- * @file +- * Vorbis I decoder +- * @author Denes Balatoni ( dbalatoni programozo hu ) +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#undef V_DEBUG +-//#define V_DEBUG +-//#define AV_DEBUG(...) av_log(NULL, AV_LOG_INFO, __VA_ARGS__) +- +-#include +- +-#define ALT_BITSTREAM_READER_LE +-#include "avcodec.h" +-#include "get_bits.h" +-#include "dsputil.h" +-#include "fft.h" +-#include "fmtconvert.h" +- +-#include "vorbis.h" +-#include "xiph.h" +- +-#define V_NB_BITS 8 +-#define V_NB_BITS2 11 +-#define V_MAX_VLCS (1 << 16) +-#define V_MAX_PARTITIONS (1 << 20) +- +-#ifndef V_DEBUG +-#define AV_DEBUG(...) +-#endif +- +-#undef NDEBUG +-#include +- +-typedef struct { +- uint_fast8_t dimensions; +- uint_fast8_t lookup_type; +- uint_fast8_t maxdepth; +- VLC vlc; +- float *codevectors; +- unsigned int nb_bits; +-} vorbis_codebook; +- +-typedef union vorbis_floor_u vorbis_floor_data; +-typedef struct vorbis_floor0_s vorbis_floor0; +-typedef struct vorbis_floor1_s vorbis_floor1; +-struct vorbis_context_s; +-typedef +-int (* vorbis_floor_decode_func) +- (struct vorbis_context_s *, vorbis_floor_data *, float *); +-typedef struct { +- uint_fast8_t floor_type; +- vorbis_floor_decode_func decode; +- union vorbis_floor_u { +- struct vorbis_floor0_s { +- uint_fast8_t order; +- uint_fast16_t rate; +- uint_fast16_t bark_map_size; +- int_fast32_t *map[2]; +- uint_fast32_t map_size[2]; +- uint_fast8_t amplitude_bits; +- uint_fast8_t amplitude_offset; +- uint_fast8_t num_books; +- uint_fast8_t *book_list; +- float *lsp; +- } t0; +- struct vorbis_floor1_s { +- uint_fast8_t partitions; +- uint8_t partition_class[32]; +- uint_fast8_t class_dimensions[16]; +- uint_fast8_t class_subclasses[16]; +- uint_fast8_t class_masterbook[16]; +- int_fast16_t subclass_books[16][8]; +- uint_fast8_t multiplier; +- uint_fast16_t x_list_dim; +- vorbis_floor1_entry *list; +- } t1; +- } data; +-} vorbis_floor; +- +-typedef struct { +- uint_fast16_t type; +- uint_fast32_t begin; +- uint_fast32_t end; +- unsigned partition_size; +- uint_fast8_t classifications; +- uint_fast8_t classbook; +- int_fast16_t books[64][8]; +- uint_fast8_t maxpass; +- uint_fast16_t ptns_to_read; +- uint8_t *classifs; +-} vorbis_residue; +- +-typedef struct { +- uint_fast8_t submaps; +- uint_fast16_t coupling_steps; +- uint_fast8_t *magnitude; +- uint_fast8_t *angle; +- uint_fast8_t *mux; +- uint_fast8_t submap_floor[16]; +- uint_fast8_t submap_residue[16]; +-} vorbis_mapping; +- +-typedef struct { +- uint_fast8_t blockflag; +- uint_fast16_t windowtype; +- uint_fast16_t transformtype; +- uint_fast8_t mapping; +-} vorbis_mode; +- +-typedef struct vorbis_context_s { +- AVCodecContext *avccontext; +- GetBitContext gb; +- DSPContext dsp; +- FmtConvertContext fmt_conv; +- +- FFTContext mdct[2]; +- uint_fast8_t first_frame; +- uint_fast32_t version; +- uint_fast8_t audio_channels; +- uint_fast32_t audio_samplerate; +- uint_fast32_t bitrate_maximum; +- uint_fast32_t bitrate_nominal; +- uint_fast32_t bitrate_minimum; +- uint_fast32_t blocksize[2]; +- const float *win[2]; +- uint_fast16_t codebook_count; +- vorbis_codebook *codebooks; +- uint_fast8_t floor_count; +- vorbis_floor *floors; +- uint_fast8_t residue_count; +- vorbis_residue *residues; +- uint_fast8_t mapping_count; +- vorbis_mapping *mappings; +- uint_fast8_t mode_count; +- vorbis_mode *modes; +- uint_fast8_t mode_number; // mode number for the current packet +- uint_fast8_t previous_window; +- float *channel_residues; +- float *channel_floors; +- float *saved; +- float scale_bias; // for float->int conversion +-} vorbis_context; +- +-/* Helper functions */ +- +-#define BARK(x) \ +- (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x)) +- +-static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n"; +-#define VALIDATE_INDEX(idx, limit) \ +- if (idx >= limit) {\ +- av_log(vc->avccontext, AV_LOG_ERROR,\ +- idx_err_str,\ +- (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\ +- return -1;\ +- } +-#define GET_VALIDATED_INDEX(idx, bits, limit) \ +- {\ +- idx = get_bits(gb, bits);\ +- VALIDATE_INDEX(idx, limit)\ +- } +- +-static float vorbisfloat2float(uint_fast32_t val) +-{ +- double mant = val & 0x1fffff; +- long exp = (val & 0x7fe00000L) >> 21; +- if (val & 0x80000000) +- mant = -mant; +- return ldexp(mant, exp - 20 - 768); +-} +- +- +-// Free all allocated memory ----------------------------------------- +- +-static void vorbis_free(vorbis_context *vc) +-{ +- int_fast16_t i; +- +- av_freep(&vc->channel_residues); +- av_freep(&vc->channel_floors); +- av_freep(&vc->saved); +- +- for (i = 0; i < vc->residue_count; i++) +- av_free(vc->residues[i].classifs); +- av_freep(&vc->residues); +- av_freep(&vc->modes); +- +- ff_mdct_end(&vc->mdct[0]); +- ff_mdct_end(&vc->mdct[1]); +- +- for (i = 0; i < vc->codebook_count; ++i) { +- av_free(vc->codebooks[i].codevectors); +- free_vlc(&vc->codebooks[i].vlc); +- } +- av_freep(&vc->codebooks); +- +- for (i = 0; i < vc->floor_count; ++i) { +- if (vc->floors[i].floor_type == 0) { +- av_free(vc->floors[i].data.t0.map[0]); +- av_free(vc->floors[i].data.t0.map[1]); +- av_free(vc->floors[i].data.t0.book_list); +- av_free(vc->floors[i].data.t0.lsp); +- } else { +- av_free(vc->floors[i].data.t1.list); +- } +- } +- av_freep(&vc->floors); +- +- for (i = 0; i < vc->mapping_count; ++i) { +- av_free(vc->mappings[i].magnitude); +- av_free(vc->mappings[i].angle); +- av_free(vc->mappings[i].mux); +- } +- av_freep(&vc->mappings); +-} +- +-// Parse setup header ------------------------------------------------- +- +-// Process codebooks part +- +-static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) +-{ +- uint_fast16_t cb; +- uint8_t *tmp_vlc_bits; +- uint32_t *tmp_vlc_codes; +- GetBitContext *gb = &vc->gb; +- uint_fast16_t *codebook_multiplicands; +- +- vc->codebook_count = get_bits(gb, 8) + 1; +- +- AV_DEBUG(" Codebooks: %d \n", vc->codebook_count); +- +- vc->codebooks = av_mallocz(vc->codebook_count * sizeof(vorbis_codebook)); +- tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(uint8_t)); +- tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(uint32_t)); +- codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands)); +- +- for (cb = 0; cb < vc->codebook_count; ++cb) { +- vorbis_codebook *codebook_setup = &vc->codebooks[cb]; +- uint_fast8_t ordered; +- uint_fast32_t t, used_entries = 0; +- uint_fast32_t entries; +- +- AV_DEBUG(" %d. Codebook \n", cb); +- +- if (get_bits(gb, 24) != 0x564342) { +- av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook setup data corrupt. \n", cb); +- goto error; +- } +- +- codebook_setup->dimensions=get_bits(gb, 16); +- if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook's dimension is invalid (%d). \n", cb, codebook_setup->dimensions); +- goto error; +- } +- entries = get_bits(gb, 24); +- if (entries > V_MAX_VLCS) { +- av_log(vc->avccontext, AV_LOG_ERROR, " %"PRIdFAST16". Codebook has too many entries (%"PRIdFAST32"). \n", cb, entries); +- goto error; +- } +- +- ordered = get_bits1(gb); +- +- AV_DEBUG(" codebook_dimensions %d, codebook_entries %d \n", codebook_setup->dimensions, entries); +- +- if (!ordered) { +- uint_fast16_t ce; +- uint_fast8_t flag; +- uint_fast8_t sparse = get_bits1(gb); +- +- AV_DEBUG(" not ordered \n"); +- +- if (sparse) { +- AV_DEBUG(" sparse \n"); +- +- used_entries = 0; +- for (ce = 0; ce < entries; ++ce) { +- flag = get_bits1(gb); +- if (flag) { +- tmp_vlc_bits[ce] = get_bits(gb, 5) + 1; +- ++used_entries; +- } else +- tmp_vlc_bits[ce] = 0; +- } +- } else { +- AV_DEBUG(" not sparse \n"); +- +- used_entries = entries; +- for (ce = 0; ce < entries; ++ce) +- tmp_vlc_bits[ce] = get_bits(gb, 5) + 1; +- } +- } else { +- uint_fast16_t current_entry = 0; +- uint_fast8_t current_length = get_bits(gb, 5)+1; +- +- AV_DEBUG(" ordered, current length: %d \n", current_length); //FIXME +- +- used_entries = entries; +- for (; current_entry < used_entries && current_length <= 32; ++current_length) { +- uint_fast16_t i, number; +- +- AV_DEBUG(" number bits: %d ", ilog(entries - current_entry)); +- +- number = get_bits(gb, ilog(entries - current_entry)); +- +- AV_DEBUG(" number: %d \n", number); +- +- for (i = current_entry; i < number+current_entry; ++i) +- if (i < used_entries) +- tmp_vlc_bits[i] = current_length; +- +- current_entry+=number; +- } +- if (current_entry>used_entries) { +- av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n"); +- goto error; +- } +- } +- +- codebook_setup->lookup_type = get_bits(gb, 4); +- +- AV_DEBUG(" lookup type: %d : %s \n", codebook_setup->lookup_type, codebook_setup->lookup_type ? "vq" : "no lookup"); +- +-// If the codebook is used for (inverse) VQ, calculate codevectors. +- +- if (codebook_setup->lookup_type == 1) { +- uint_fast16_t i, j, k; +- uint_fast16_t codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions); +- +- float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32)); +- float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32)); +- uint_fast8_t codebook_value_bits = get_bits(gb, 4)+1; +- uint_fast8_t codebook_sequence_p = get_bits1(gb); +- +- AV_DEBUG(" We expect %d numbers for building the codevectors. \n", codebook_lookup_values); +- AV_DEBUG(" delta %f minmum %f \n", codebook_delta_value, codebook_minimum_value); +- +- for (i = 0; i < codebook_lookup_values; ++i) { +- codebook_multiplicands[i] = get_bits(gb, codebook_value_bits); +- +- AV_DEBUG(" multiplicands*delta+minmum : %e \n", (float)codebook_multiplicands[i]*codebook_delta_value+codebook_minimum_value); +- AV_DEBUG(" multiplicand %d \n", codebook_multiplicands[i]); +- } +- +-// Weed out unused vlcs and build codevector vector +- codebook_setup->codevectors = used_entries ? av_mallocz(used_entries*codebook_setup->dimensions * sizeof(float)) : NULL; +- for (j = 0, i = 0; i < entries; ++i) { +- uint_fast8_t dim = codebook_setup->dimensions; +- +- if (tmp_vlc_bits[i]) { +- float last = 0.0; +- uint_fast32_t lookup_offset = i; +- +-#ifdef V_DEBUG +- av_log(vc->avccontext, AV_LOG_INFO, "Lookup offset %d ,", i); +-#endif +- +- for (k = 0; k < dim; ++k) { +- uint_fast32_t multiplicand_offset = lookup_offset % codebook_lookup_values; +- codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last; +- if (codebook_sequence_p) +- last = codebook_setup->codevectors[j * dim + k]; +- lookup_offset/=codebook_lookup_values; +- } +- tmp_vlc_bits[j] = tmp_vlc_bits[i]; +- +-#ifdef V_DEBUG +- av_log(vc->avccontext, AV_LOG_INFO, "real lookup offset %d, vector: ", j); +- for (k = 0; k < dim; ++k) +- av_log(vc->avccontext, AV_LOG_INFO, " %f ", codebook_setup->codevectors[j * dim + k]); +- av_log(vc->avccontext, AV_LOG_INFO, "\n"); +-#endif +- +- ++j; +- } +- } +- if (j != used_entries) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n"); +- goto error; +- } +- entries = used_entries; +- } else if (codebook_setup->lookup_type >= 2) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n"); +- goto error; +- } +- +-// Initialize VLC table +- if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n"); +- goto error; +- } +- codebook_setup->maxdepth = 0; +- for (t = 0; t < entries; ++t) +- if (tmp_vlc_bits[t] >= codebook_setup->maxdepth) +- codebook_setup->maxdepth = tmp_vlc_bits[t]; +- +- if (codebook_setup->maxdepth > 3 * V_NB_BITS) +- codebook_setup->nb_bits = V_NB_BITS2; +- else +- codebook_setup->nb_bits = V_NB_BITS; +- +- codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits; +- +- if (init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), sizeof(*tmp_vlc_bits), tmp_vlc_codes, sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), INIT_VLC_LE)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n"); +- goto error; +- } +- } +- +- av_free(tmp_vlc_bits); +- av_free(tmp_vlc_codes); +- av_free(codebook_multiplicands); +- return 0; +- +-// Error: +-error: +- av_free(tmp_vlc_bits); +- av_free(tmp_vlc_codes); +- av_free(codebook_multiplicands); +- return -1; +-} +- +-// Process time domain transforms part (unused in Vorbis I) +- +-static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t i; +- uint_fast8_t vorbis_time_count = get_bits(gb, 6) + 1; +- +- for (i = 0; i < vorbis_time_count; ++i) { +- uint_fast16_t vorbis_tdtransform = get_bits(gb, 16); +- +- AV_DEBUG(" Vorbis time domain transform %d: %d \n", vorbis_time_count, vorbis_tdtransform); +- +- if (vorbis_tdtransform) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n"); +- return -1; +- } +- } +- return 0; +-} +- +-// Process floors part +- +-static int vorbis_floor0_decode(vorbis_context *vc, +- vorbis_floor_data *vfu, float *vec); +-static void create_map(vorbis_context *vc, uint_fast8_t floor_number); +-static int vorbis_floor1_decode(vorbis_context *vc, +- vorbis_floor_data *vfu, float *vec); +-static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- int i,j,k; +- +- vc->floor_count = get_bits(gb, 6) + 1; +- +- vc->floors = av_mallocz(vc->floor_count * sizeof(vorbis_floor)); +- +- for (i = 0; i < vc->floor_count; ++i) { +- vorbis_floor *floor_setup = &vc->floors[i]; +- +- floor_setup->floor_type = get_bits(gb, 16); +- +- AV_DEBUG(" %d. floor type %d \n", i, floor_setup->floor_type); +- +- if (floor_setup->floor_type == 1) { +- int maximum_class = -1; +- uint_fast8_t rangebits; +- uint_fast32_t rangemax; +- uint_fast16_t floor1_values = 2; +- +- floor_setup->decode = vorbis_floor1_decode; +- +- floor_setup->data.t1.partitions = get_bits(gb, 5); +- +- AV_DEBUG(" %d.floor: %d partitions \n", i, floor_setup->data.t1.partitions); +- +- for (j = 0; j < floor_setup->data.t1.partitions; ++j) { +- floor_setup->data.t1.partition_class[j] = get_bits(gb, 4); +- if (floor_setup->data.t1.partition_class[j] > maximum_class) +- maximum_class = floor_setup->data.t1.partition_class[j]; +- +- AV_DEBUG(" %d. floor %d partition class %d \n", i, j, floor_setup->data.t1.partition_class[j]); +- +- } +- +- AV_DEBUG(" maximum class %d \n", maximum_class); +- +- for (j = 0; j <= maximum_class; ++j) { +- floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1; +- floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2); +- +- AV_DEBUG(" %d floor %d class dim: %d subclasses %d \n", i, j, floor_setup->data.t1.class_dimensions[j], floor_setup->data.t1.class_subclasses[j]); +- +- if (floor_setup->data.t1.class_subclasses[j]) { +- GET_VALIDATED_INDEX(floor_setup->data.t1.class_masterbook[j], 8, vc->codebook_count) +- +- AV_DEBUG(" masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]); +- } +- +- for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) { +- int16_t bits = get_bits(gb, 8) - 1; +- if (bits != -1) +- VALIDATE_INDEX(bits, vc->codebook_count) +- floor_setup->data.t1.subclass_books[j][k] = bits; +- +- AV_DEBUG(" book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]); +- } +- } +- +- floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1; +- floor_setup->data.t1.x_list_dim = 2; +- +- for (j = 0; j < floor_setup->data.t1.partitions; ++j) +- floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; +- +- floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim * sizeof(vorbis_floor1_entry)); +- +- +- rangebits = get_bits(gb, 4); +- rangemax = (1 << rangebits); +- if (rangemax > vc->blocksize[1] / 2) { +- av_log(vc->avccontext, AV_LOG_ERROR, +- "Floor value is too large for blocksize: %d (%d)\n", +- rangemax, vc->blocksize[1] / 2); +- return -1; +- } +- floor_setup->data.t1.list[0].x = 0; +- floor_setup->data.t1.list[1].x = rangemax; +- +- for (j = 0; j < floor_setup->data.t1.partitions; ++j) { +- for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) { +- floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits); +- +- AV_DEBUG(" %d. floor1 Y coord. %d \n", floor1_values, floor_setup->data.t1.list[floor1_values].x); +- } +- } +- +-// Precalculate order of x coordinates - needed for decode +- ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); +- } else if (floor_setup->floor_type == 0) { +- uint_fast8_t max_codebook_dim = 0; +- +- floor_setup->decode = vorbis_floor0_decode; +- +- floor_setup->data.t0.order = get_bits(gb, 8); +- floor_setup->data.t0.rate = get_bits(gb, 16); +- floor_setup->data.t0.bark_map_size = get_bits(gb, 16); +- floor_setup->data.t0.amplitude_bits = get_bits(gb, 6); +- /* zero would result in a div by zero later * +- * 2^0 - 1 == 0 */ +- if (floor_setup->data.t0.amplitude_bits == 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, +- "Floor 0 amplitude bits is 0.\n"); +- return -1; +- } +- floor_setup->data.t0.amplitude_offset = get_bits(gb, 8); +- floor_setup->data.t0.num_books = get_bits(gb, 4) + 1; +- +- /* allocate mem for booklist */ +- floor_setup->data.t0.book_list = +- av_malloc(floor_setup->data.t0.num_books); +- if (!floor_setup->data.t0.book_list) +- return -1; +- /* read book indexes */ +- { +- int idx; +- uint_fast8_t book_idx; +- for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { +- GET_VALIDATED_INDEX(book_idx, 8, vc->codebook_count) +- floor_setup->data.t0.book_list[idx] = book_idx; +- if (vc->codebooks[book_idx].dimensions > max_codebook_dim) +- max_codebook_dim = vc->codebooks[book_idx].dimensions; +- } +- } +- +- create_map(vc, i); +- +- /* allocate mem for lsp coefficients */ +- { +- /* codebook dim is for padding if codebook dim doesn't * +- * divide order+1 then we need to read more data */ +- floor_setup->data.t0.lsp = +- av_malloc((floor_setup->data.t0.order+1 + max_codebook_dim) +- * sizeof(float)); +- if (!floor_setup->data.t0.lsp) +- return -1; +- } +- +-#ifdef V_DEBUG /* debug output parsed headers */ +- AV_DEBUG("floor0 order: %u\n", floor_setup->data.t0.order); +- AV_DEBUG("floor0 rate: %u\n", floor_setup->data.t0.rate); +- AV_DEBUG("floor0 bark map size: %u\n", +- floor_setup->data.t0.bark_map_size); +- AV_DEBUG("floor0 amplitude bits: %u\n", +- floor_setup->data.t0.amplitude_bits); +- AV_DEBUG("floor0 amplitude offset: %u\n", +- floor_setup->data.t0.amplitude_offset); +- AV_DEBUG("floor0 number of books: %u\n", +- floor_setup->data.t0.num_books); +- AV_DEBUG("floor0 book list pointer: %p\n", +- floor_setup->data.t0.book_list); +- { +- int idx; +- for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { +- AV_DEBUG(" Book %d: %u\n", +- idx+1, +- floor_setup->data.t0.book_list[idx]); +- } +- } +-#endif +- } else { +- av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n"); +- return -1; +- } +- } +- return 0; +-} +- +-// Process residues part +- +-static int vorbis_parse_setup_hdr_residues(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t i, j, k; +- +- vc->residue_count = get_bits(gb, 6)+1; +- vc->residues = av_mallocz(vc->residue_count * sizeof(vorbis_residue)); +- +- AV_DEBUG(" There are %d residues. \n", vc->residue_count); +- +- for (i = 0; i < vc->residue_count; ++i) { +- vorbis_residue *res_setup = &vc->residues[i]; +- uint_fast8_t cascade[64]; +- uint_fast8_t high_bits; +- uint_fast8_t low_bits; +- +- res_setup->type = get_bits(gb, 16); +- +- AV_DEBUG(" %d. residue type %d \n", i, res_setup->type); +- +- res_setup->begin = get_bits(gb, 24); +- res_setup->end = get_bits(gb, 24); +- res_setup->partition_size = get_bits(gb, 24) + 1; +- /* Validations to prevent a buffer overflow later. */ +- if (res_setup->begin>res_setup->end || +- res_setup->end > vc->avccontext->channels * vc->blocksize[1] / 2 || +- (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) { +- av_log(vc->avccontext, AV_LOG_ERROR, "partition out of bounds: type, begin, end, size, blocksize: %"PRIdFAST16", %"PRIdFAST32", %"PRIdFAST32", %u, %"PRIdFAST32"\n", res_setup->type, res_setup->begin, res_setup->end, res_setup->partition_size, vc->blocksize[1] / 2); +- return -1; +- } +- +- res_setup->classifications = get_bits(gb, 6) + 1; +- GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count) +- +- res_setup->ptns_to_read = +- (res_setup->end - res_setup->begin) / res_setup->partition_size; +- res_setup->classifs = av_malloc(res_setup->ptns_to_read * +- vc->audio_channels * +- sizeof(*res_setup->classifs)); +- if (!res_setup->classifs) +- return AVERROR(ENOMEM); +- +- AV_DEBUG(" begin %d end %d part.size %d classif.s %d classbook %d \n", res_setup->begin, res_setup->end, res_setup->partition_size, +- res_setup->classifications, res_setup->classbook); +- +- for (j = 0; j < res_setup->classifications; ++j) { +- high_bits = 0; +- low_bits = get_bits(gb, 3); +- if (get_bits1(gb)) +- high_bits = get_bits(gb, 5); +- cascade[j] = (high_bits << 3) + low_bits; +- +- AV_DEBUG(" %d class casscade depth: %d \n", j, ilog(cascade[j])); +- } +- +- res_setup->maxpass = 0; +- for (j = 0; j < res_setup->classifications; ++j) { +- for (k = 0; k < 8; ++k) { +- if (cascade[j]&(1 << k)) { +- GET_VALIDATED_INDEX(res_setup->books[j][k], 8, vc->codebook_count) +- +- AV_DEBUG(" %d class casscade depth %d book: %d \n", j, k, res_setup->books[j][k]); +- +- if (k>res_setup->maxpass) +- res_setup->maxpass = k; +- } else { +- res_setup->books[j][k] = -1; +- } +- } +- } +- } +- return 0; +-} +- +-// Process mappings part +- +-static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t i, j; +- +- vc->mapping_count = get_bits(gb, 6)+1; +- vc->mappings = av_mallocz(vc->mapping_count * sizeof(vorbis_mapping)); +- +- AV_DEBUG(" There are %d mappings. \n", vc->mapping_count); +- +- for (i = 0; i < vc->mapping_count; ++i) { +- vorbis_mapping *mapping_setup = &vc->mappings[i]; +- +- if (get_bits(gb, 16)) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n"); +- return -1; +- } +- if (get_bits1(gb)) { +- mapping_setup->submaps = get_bits(gb, 4) + 1; +- } else { +- mapping_setup->submaps = 1; +- } +- +- if (get_bits1(gb)) { +- mapping_setup->coupling_steps = get_bits(gb, 8) + 1; +- mapping_setup->magnitude = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); +- mapping_setup->angle = av_mallocz(mapping_setup->coupling_steps * sizeof(uint_fast8_t)); +- for (j = 0; j < mapping_setup->coupling_steps; ++j) { +- GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels) +- GET_VALIDATED_INDEX(mapping_setup->angle[j], ilog(vc->audio_channels - 1), vc->audio_channels) +- } +- } else { +- mapping_setup->coupling_steps = 0; +- } +- +- AV_DEBUG(" %d mapping coupling steps: %d \n", i, mapping_setup->coupling_steps); +- +- if (get_bits(gb, 2)) { +- av_log(vc->avccontext, AV_LOG_ERROR, "%d. mapping setup data invalid. \n", i); +- return -1; // following spec. +- } +- +- if (mapping_setup->submaps>1) { +- mapping_setup->mux = av_mallocz(vc->audio_channels * sizeof(uint_fast8_t)); +- for (j = 0; j < vc->audio_channels; ++j) +- mapping_setup->mux[j] = get_bits(gb, 4); +- } +- +- for (j = 0; j < mapping_setup->submaps; ++j) { +- skip_bits(gb, 8); // FIXME check? +- GET_VALIDATED_INDEX(mapping_setup->submap_floor[j], 8, vc->floor_count) +- GET_VALIDATED_INDEX(mapping_setup->submap_residue[j], 8, vc->residue_count) +- +- AV_DEBUG(" %d mapping %d submap : floor %d, residue %d \n", i, j, mapping_setup->submap_floor[j], mapping_setup->submap_residue[j]); +- } +- } +- return 0; +-} +- +-// Process modes part +- +-static void create_map(vorbis_context *vc, uint_fast8_t floor_number) +-{ +- vorbis_floor *floors = vc->floors; +- vorbis_floor0 *vf; +- int idx; +- int_fast8_t blockflag; +- int_fast32_t *map; +- int_fast32_t n; //TODO: could theoretically be smaller? +- +- for (blockflag = 0; blockflag < 2; ++blockflag) { +- n = vc->blocksize[blockflag] / 2; +- floors[floor_number].data.t0.map[blockflag] = +- av_malloc((n+1) * sizeof(int_fast32_t)); // n + sentinel +- +- map = floors[floor_number].data.t0.map[blockflag]; +- vf = &floors[floor_number].data.t0; +- +- for (idx = 0; idx < n; ++idx) { +- map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) * +- ((vf->bark_map_size) / +- BARK(vf->rate / 2.0f))); +- if (vf->bark_map_size-1 < map[idx]) +- map[idx] = vf->bark_map_size - 1; +- } +- map[n] = -1; +- vf->map_size[blockflag] = n; +- } +- +-# ifdef V_DEBUG +- for (idx = 0; idx <= n; ++idx) { +- AV_DEBUG("floor0 map: map at pos %d is %d\n", +- idx, map[idx]); +- } +-# endif +-} +- +-static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t i; +- +- vc->mode_count = get_bits(gb, 6) + 1; +- vc->modes = av_mallocz(vc->mode_count * sizeof(vorbis_mode)); +- +- AV_DEBUG(" There are %d modes.\n", vc->mode_count); +- +- for (i = 0; i < vc->mode_count; ++i) { +- vorbis_mode *mode_setup = &vc->modes[i]; +- +- mode_setup->blockflag = get_bits1(gb); +- mode_setup->windowtype = get_bits(gb, 16); //FIXME check +- mode_setup->transformtype = get_bits(gb, 16); //FIXME check +- GET_VALIDATED_INDEX(mode_setup->mapping, 8, vc->mapping_count); +- +- AV_DEBUG(" %d mode: blockflag %d, windowtype %d, transformtype %d, mapping %d \n", i, mode_setup->blockflag, mode_setup->windowtype, mode_setup->transformtype, mode_setup->mapping); +- } +- return 0; +-} +- +-// Process the whole setup header using the functions above +- +-static int vorbis_parse_setup_hdr(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- +- if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || +- (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || +- (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n"); +- return -1; +- } +- +- if (vorbis_parse_setup_hdr_codebooks(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n"); +- return -2; +- } +- if (vorbis_parse_setup_hdr_tdtransforms(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n"); +- return -3; +- } +- if (vorbis_parse_setup_hdr_floors(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n"); +- return -4; +- } +- if (vorbis_parse_setup_hdr_residues(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n"); +- return -5; +- } +- if (vorbis_parse_setup_hdr_mappings(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n"); +- return -6; +- } +- if (vorbis_parse_setup_hdr_modes(vc)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n"); +- return -7; +- } +- if (!get_bits1(gb)) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n"); +- return -8; // framing flag bit unset error +- } +- +- return 0; +-} +- +-// Process the identification header +- +-static int vorbis_parse_id_hdr(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t bl0, bl1; +- +- if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || +- (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || +- (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n"); +- return -1; +- } +- +- vc->version = get_bits_long(gb, 32); //FIXME check 0 +- vc->audio_channels = get_bits(gb, 8); +- if (vc->audio_channels <= 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n"); +- return -1; +- } +- vc->audio_samplerate = get_bits_long(gb, 32); +- if (vc->audio_samplerate <= 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n"); +- return -1; +- } +- vc->bitrate_maximum = get_bits_long(gb, 32); +- vc->bitrate_nominal = get_bits_long(gb, 32); +- vc->bitrate_minimum = get_bits_long(gb, 32); +- bl0 = get_bits(gb, 4); +- bl1 = get_bits(gb, 4); +- vc->blocksize[0] = (1 << bl0); +- vc->blocksize[1] = (1 << bl1); +- if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); +- return -3; +- } +- // output format int16 +- if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes " +- "output packets too large.\n"); +- return -4; +- } +- vc->win[0] = ff_vorbis_vwin[bl0 - 6]; +- vc->win[1] = ff_vorbis_vwin[bl1 - 6]; +- +- if ((get_bits1(gb)) == 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n"); +- return -2; +- } +- +- vc->channel_residues = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float)); +- vc->channel_floors = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(float)); +- vc->saved = av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(float)); +- vc->previous_window = 0; +- +- ff_mdct_init(&vc->mdct[0], bl0, 1, -vc->scale_bias); +- ff_mdct_init(&vc->mdct[1], bl1, 1, -vc->scale_bias); +- +- AV_DEBUG(" vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", +- vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); +- +-/* +- BLK = vc->blocksize[0]; +- for (i = 0; i < BLK / 2; ++i) { +- vc->win[0][i] = sin(0.5*3.14159265358*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))); +- } +-*/ +- +- return 0; +-} +- +-// Process the extradata using the functions above (identification header, setup header) +- +-static av_cold int vorbis_decode_init(AVCodecContext *avccontext) +-{ +- vorbis_context *vc = avccontext->priv_data ; +- uint8_t *headers = avccontext->extradata; +- int headers_len = avccontext->extradata_size; +- uint8_t *header_start[3]; +- int header_len[3]; +- GetBitContext *gb = &(vc->gb); +- int hdr_type; +- +- vc->avccontext = avccontext; +- dsputil_init(&vc->dsp, avccontext); +- ff_fmt_convert_init(&vc->fmt_conv, avccontext); +- +- vc->scale_bias = 32768.0f; +- +- if (!headers_len) { +- av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n"); +- return -1; +- } +- +- if (ff_split_xiph_headers(headers, headers_len, 30, header_start, header_len) < 0) { +- av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); +- return -1; +- } +- +- init_get_bits(gb, header_start[0], header_len[0]*8); +- hdr_type = get_bits(gb, 8); +- if (hdr_type != 1) { +- av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); +- return -1; +- } +- if (vorbis_parse_id_hdr(vc)) { +- av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n"); +- vorbis_free(vc); +- return -1; +- } +- +- init_get_bits(gb, header_start[2], header_len[2]*8); +- hdr_type = get_bits(gb, 8); +- if (hdr_type != 5) { +- av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); +- vorbis_free(vc); +- return -1; +- } +- if (vorbis_parse_setup_hdr(vc)) { +- av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n"); +- vorbis_free(vc); +- return -1; +- } +- +- if (vc->audio_channels > 8) +- avccontext->channel_layout = 0; +- else +- avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1]; +- +- avccontext->channels = vc->audio_channels; +- avccontext->sample_rate = vc->audio_samplerate; +- avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2; +- avccontext->sample_fmt = AV_SAMPLE_FMT_S16; +- +- return 0 ; +-} +- +-// Decode audiopackets ------------------------------------------------- +- +-// Read and decode floor +- +-static int vorbis_floor0_decode(vorbis_context *vc, +- vorbis_floor_data *vfu, float *vec) +-{ +- vorbis_floor0 *vf = &vfu->t0; +- float *lsp = vf->lsp; +- uint_fast32_t amplitude; +- uint_fast32_t book_idx; +- uint_fast8_t blockflag = vc->modes[vc->mode_number].blockflag; +- +- amplitude = get_bits(&vc->gb, vf->amplitude_bits); +- if (amplitude > 0) { +- float last = 0; +- uint_fast16_t lsp_len = 0; +- uint_fast16_t idx; +- vorbis_codebook codebook; +- +- book_idx = get_bits(&vc->gb, ilog(vf->num_books)); +- if (book_idx >= vf->num_books) { +- av_log(vc->avccontext, AV_LOG_ERROR, +- "floor0 dec: booknumber too high!\n"); +- book_idx = 0; +- //FIXME: look above +- } +- AV_DEBUG("floor0 dec: booknumber: %u\n", book_idx); +- codebook = vc->codebooks[vf->book_list[book_idx]]; +- /* Invalid codebook! */ +- if (!codebook.codevectors) +- return -1; +- +- while (lsp_lenorder) { +- int vec_off; +- +- AV_DEBUG("floor0 dec: book dimension: %d\n", codebook.dimensions); +- AV_DEBUG("floor0 dec: maximum depth: %d\n", codebook.maxdepth); +- /* read temp vector */ +- vec_off = get_vlc2(&vc->gb, codebook.vlc.table, +- codebook.nb_bits, codebook.maxdepth) +- * codebook.dimensions; +- AV_DEBUG("floor0 dec: vector offset: %d\n", vec_off); +- /* copy each vector component and add last to it */ +- for (idx = 0; idx < codebook.dimensions; ++idx) +- lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last; +- last = lsp[lsp_len+idx-1]; /* set last to last vector component */ +- +- lsp_len += codebook.dimensions; +- } +-#ifdef V_DEBUG +- /* DEBUG: output lsp coeffs */ +- { +- int idx; +- for (idx = 0; idx < lsp_len; ++idx) +- AV_DEBUG("floor0 dec: coeff at %d is %f\n", idx, lsp[idx]); +- } +-#endif +- +- /* synthesize floor output vector */ +- { +- int i; +- int order = vf->order; +- float wstep = M_PI / vf->bark_map_size; +- +- for (i = 0; i < order; i++) +- lsp[i] = 2.0f * cos(lsp[i]); +- +- AV_DEBUG("floor0 synth: map_size = %d; m = %d; wstep = %f\n", +- vf->map_size, order, wstep); +- +- i = 0; +- while (i < vf->map_size[blockflag]) { +- int j, iter_cond = vf->map[blockflag][i]; +- float p = 0.5f; +- float q = 0.5f; +- float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times +- +- /* similar part for the q and p products */ +- for (j = 0; j + 1 < order; j += 2) { +- q *= lsp[j] - two_cos_w; +- p *= lsp[j + 1] - two_cos_w; +- } +- if (j == order) { // even order +- p *= p * (2.0f - two_cos_w); +- q *= q * (2.0f + two_cos_w); +- } else { // odd order +- q *= two_cos_w-lsp[j]; // one more time for q +- +- /* final step and square */ +- p *= p * (4.f - two_cos_w * two_cos_w); +- q *= q; +- } +- +- /* calculate linear floor value */ +- { +- q = exp((((amplitude*vf->amplitude_offset) / +- (((1 << vf->amplitude_bits) - 1) * sqrt(p + q))) +- - vf->amplitude_offset) * .11512925f); +- } +- +- /* fill vector */ +- do { +- vec[i] = q; ++i; +- } while (vf->map[blockflag][i] == iter_cond); +- } +- } +- } else { +- /* this channel is unused */ +- return 1; +- } +- +- AV_DEBUG(" Floor0 decoded\n"); +- +- return 0; +-} +- +-static int vorbis_floor1_decode(vorbis_context *vc, +- vorbis_floor_data *vfu, float *vec) +-{ +- vorbis_floor1 *vf = &vfu->t1; +- GetBitContext *gb = &vc->gb; +- uint_fast16_t range_v[4] = { 256, 128, 86, 64 }; +- uint_fast16_t range = range_v[vf->multiplier-1]; +- uint_fast16_t floor1_Y[258]; +- uint_fast16_t floor1_Y_final[258]; +- int floor1_flag[258]; +- uint_fast8_t class_; +- uint_fast8_t cdim; +- uint_fast8_t cbits; +- uint_fast8_t csub; +- uint_fast8_t cval; +- int_fast16_t book; +- uint_fast16_t offset; +- uint_fast16_t i,j; +- int_fast16_t adx, ady, dy, off, predicted; +- int_fast32_t err; +- +- +- if (!get_bits1(gb)) // silence +- return 1; +- +-// Read values (or differences) for the floor's points +- +- floor1_Y[0] = get_bits(gb, ilog(range - 1)); +- floor1_Y[1] = get_bits(gb, ilog(range - 1)); +- +- AV_DEBUG("floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]); +- +- offset = 2; +- for (i = 0; i < vf->partitions; ++i) { +- class_ = vf->partition_class[i]; +- cdim = vf->class_dimensions[class_]; +- cbits = vf->class_subclasses[class_]; +- csub = (1 << cbits) - 1; +- cval = 0; +- +- AV_DEBUG("Cbits %d \n", cbits); +- +- if (cbits) // this reads all subclasses for this partition's class +- cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[class_]].vlc.table, +- vc->codebooks[vf->class_masterbook[class_]].nb_bits, 3); +- +- for (j = 0; j < cdim; ++j) { +- book = vf->subclass_books[class_][cval & csub]; +- +- AV_DEBUG("book %d Cbits %d cval %d bits:%d \n", book, cbits, cval, get_bits_count(gb)); +- +- cval = cval >> cbits; +- if (book > -1) { +- floor1_Y[offset+j] = get_vlc2(gb, vc->codebooks[book].vlc.table, +- vc->codebooks[book].nb_bits, 3); +- } else { +- floor1_Y[offset+j] = 0; +- } +- +- AV_DEBUG(" floor(%d) = %d \n", vf->list[offset+j].x, floor1_Y[offset+j]); +- } +- offset+=cdim; +- } +- +-// Amplitude calculation from the differences +- +- floor1_flag[0] = 1; +- floor1_flag[1] = 1; +- floor1_Y_final[0] = floor1_Y[0]; +- floor1_Y_final[1] = floor1_Y[1]; +- +- for (i = 2; i < vf->x_list_dim; ++i) { +- uint_fast16_t val, highroom, lowroom, room; +- uint_fast16_t high_neigh_offs; +- uint_fast16_t low_neigh_offs; +- +- low_neigh_offs = vf->list[i].low; +- high_neigh_offs = vf->list[i].high; +- dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs]; // render_point begin +- adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x; +- ady = FFABS(dy); +- err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x); +- off = err / adx; +- if (dy < 0) { +- predicted = floor1_Y_final[low_neigh_offs] - off; +- } else { +- predicted = floor1_Y_final[low_neigh_offs] + off; +- } // render_point end +- +- val = floor1_Y[i]; +- highroom = range-predicted; +- lowroom = predicted; +- if (highroom < lowroom) { +- room = highroom * 2; +- } else { +- room = lowroom * 2; // SPEC mispelling +- } +- if (val) { +- floor1_flag[low_neigh_offs] = 1; +- floor1_flag[high_neigh_offs] = 1; +- floor1_flag[i] = 1; +- if (val >= room) { +- if (highroom > lowroom) { +- floor1_Y_final[i] = val - lowroom + predicted; +- } else { +- floor1_Y_final[i] = predicted - val + highroom - 1; +- } +- } else { +- if (val & 1) { +- floor1_Y_final[i] = predicted - (val + 1) / 2; +- } else { +- floor1_Y_final[i] = predicted + val / 2; +- } +- } +- } else { +- floor1_flag[i] = 0; +- floor1_Y_final[i] = predicted; +- } +- +- AV_DEBUG(" Decoded floor(%d) = %d / val %d \n", vf->list[i].x, floor1_Y_final[i], val); +- } +- +-// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? +- +- ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x); +- +- AV_DEBUG(" Floor decoded\n"); +- +- return 0; +-} +- +-// Read and decode residue +- +-static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, +- vorbis_residue *vr, +- uint_fast8_t ch, +- uint_fast8_t *do_not_decode, +- float *vec, +- uint_fast16_t vlen, +- int vr_type) +-{ +- GetBitContext *gb = &vc->gb; +- uint_fast8_t c_p_c = vc->codebooks[vr->classbook].dimensions; +- uint_fast16_t ptns_to_read = vr->ptns_to_read; +- uint8_t *classifs = vr->classifs; +- uint_fast8_t pass; +- uint_fast8_t ch_used; +- uint_fast8_t i,j,l; +- uint_fast16_t k; +- +- if (vr_type == 2) { +- for (j = 1; j < ch; ++j) +- do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input +- if (do_not_decode[0]) +- return 0; +- ch_used = 1; +- } else { +- ch_used = ch; +- } +- +- AV_DEBUG(" residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c); +- +- for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE? +- uint_fast16_t voffset; +- uint_fast16_t partition_count; +- uint_fast16_t j_times_ptns_to_read; +- +- voffset = vr->begin; +- for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error +- if (!pass) { +- uint_fast32_t inverse_class = ff_inverse[vr->classifications]; +- for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { +- if (!do_not_decode[j]) { +- uint_fast32_t temp = get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, +- vc->codebooks[vr->classbook].nb_bits, 3); +- +- AV_DEBUG("Classword: %d \n", temp); +- +- assert(vr->classifications > 1 && temp <= 65536); //needed for inverse[] +- for (i = 0; i < c_p_c; ++i) { +- uint_fast32_t temp2; +- +- temp2 = (((uint_fast64_t)temp) * inverse_class) >> 32; +- if (partition_count + c_p_c - 1 - i < ptns_to_read) +- classifs[j_times_ptns_to_read + partition_count + c_p_c - 1 - i] = temp - temp2 * vr->classifications; +- temp = temp2; +- } +- } +- j_times_ptns_to_read += ptns_to_read; +- } +- } +- for (i = 0; (i < c_p_c) && (partition_count < ptns_to_read); ++i) { +- for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { +- uint_fast16_t voffs; +- +- if (!do_not_decode[j]) { +- uint_fast8_t vqclass = classifs[j_times_ptns_to_read+partition_count]; +- int_fast16_t vqbook = vr->books[vqclass][pass]; +- +- if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) { +- uint_fast16_t coffs; +- unsigned dim = vc->codebooks[vqbook].dimensions; // not uint_fast8_t: 64bit is slower here on amd64 +- uint_fast16_t step = dim == 1 ? vr->partition_size +- : FASTDIV(vr->partition_size, dim); +- vorbis_codebook codebook = vc->codebooks[vqbook]; +- +- if (vr_type == 0) { +- +- voffs = voffset+j*vlen; +- for (k = 0; k < step; ++k) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; +- for (l = 0; l < dim; ++l) +- vec[voffs + k + l * step] += codebook.codevectors[coffs + l]; // FPMATH +- } +- } else if (vr_type == 1) { +- voffs = voffset + j * vlen; +- for (k = 0; k < step; ++k) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; +- for (l = 0; l < dim; ++l, ++voffs) { +- vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH +- +- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d \n", pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs); +- } +- } +- } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized +- voffs = voffset >> 1; +- +- if (dim == 2) { +- for (k = 0; k < step; ++k) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2; +- vec[voffs + k ] += codebook.codevectors[coffs ]; // FPMATH +- vec[voffs + k + vlen] += codebook.codevectors[coffs + 1]; // FPMATH +- } +- } else if (dim == 4) { +- for (k = 0; k < step; ++k, voffs += 2) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 4; +- vec[voffs ] += codebook.codevectors[coffs ]; // FPMATH +- vec[voffs + 1 ] += codebook.codevectors[coffs + 2]; // FPMATH +- vec[voffs + vlen ] += codebook.codevectors[coffs + 1]; // FPMATH +- vec[voffs + vlen + 1] += codebook.codevectors[coffs + 3]; // FPMATH +- } +- } else +- for (k = 0; k < step; ++k) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; +- for (l = 0; l < dim; l += 2, voffs++) { +- vec[voffs ] += codebook.codevectors[coffs + l ]; // FPMATH +- vec[voffs + vlen] += codebook.codevectors[coffs + l + 1]; // FPMATH +- +- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset / ch + (voffs % ch) * vlen, vec[voffset / ch + (voffs % ch) * vlen], codebook.codevectors[coffs + l], coffs, l); +- } +- } +- +- } else if (vr_type == 2) { +- voffs = voffset; +- +- for (k = 0; k < step; ++k) { +- coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; +- for (l = 0; l < dim; ++l, ++voffs) { +- vec[voffs / ch + (voffs % ch) * vlen] += codebook.codevectors[coffs + l]; // FPMATH FIXME use if and counter instead of / and % +- +- AV_DEBUG(" pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", pass, voffset / ch + (voffs % ch) * vlen, vec[voffset / ch + (voffs % ch) * vlen], codebook.codevectors[coffs + l], coffs, l); +- } +- } +- } +- } +- } +- j_times_ptns_to_read += ptns_to_read; +- } +- ++partition_count; +- voffset += vr->partition_size; +- } +- } +- } +- return 0; +-} +- +-static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, +- uint_fast8_t ch, +- uint_fast8_t *do_not_decode, +- float *vec, uint_fast16_t vlen) +-{ +- if (vr->type == 2) +- return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 2); +- else if (vr->type == 1) +- return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 1); +- else if (vr->type == 0) +- return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, 0); +- else { +- av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); +- return -1; +- } +-} +- +-void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) +-{ +- int i; +- for (i = 0; i < blocksize; i++) { +- if (mag[i] > 0.0) { +- if (ang[i] > 0.0) { +- ang[i] = mag[i] - ang[i]; +- } else { +- float temp = ang[i]; +- ang[i] = mag[i]; +- mag[i] += temp; +- } +- } else { +- if (ang[i] > 0.0) { +- ang[i] += mag[i]; +- } else { +- float temp = ang[i]; +- ang[i] = mag[i]; +- mag[i] -= temp; +- } +- } +- } +-} +- +-// Decode the audio packet using the functions above +- +-static int vorbis_parse_audio_packet(vorbis_context *vc) +-{ +- GetBitContext *gb = &vc->gb; +- +- uint_fast8_t previous_window = vc->previous_window; +- uint_fast8_t mode_number; +- uint_fast8_t blockflag; +- uint_fast16_t blocksize; +- int_fast32_t i,j; +- uint_fast8_t no_residue[255]; +- uint_fast8_t do_not_decode[255]; +- vorbis_mapping *mapping; +- float *ch_res_ptr = vc->channel_residues; +- float *ch_floor_ptr = vc->channel_floors; +- uint_fast8_t res_chan[255]; +- uint_fast8_t res_num = 0; +- int_fast16_t retlen = 0; +- +- if (get_bits1(gb)) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); +- return -1; // packet type not audio +- } +- +- if (vc->mode_count == 1) { +- mode_number = 0; +- } else { +- GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count) +- } +- vc->mode_number = mode_number; +- mapping = &vc->mappings[vc->modes[mode_number].mapping]; +- +- AV_DEBUG(" Mode number: %d , mapping: %d , blocktype %d \n", mode_number, vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); +- +- blockflag = vc->modes[mode_number].blockflag; +- blocksize = vc->blocksize[blockflag]; +- if (blockflag) +- skip_bits(gb, 2); // previous_window, next_window +- +- memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? +- memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * blocksize / 2); //FIXME can this be removed ? +- +-// Decode floor +- +- for (i = 0; i < vc->audio_channels; ++i) { +- vorbis_floor *floor; +- int ret; +- if (mapping->submaps > 1) { +- floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]]; +- } else { +- floor = &vc->floors[mapping->submap_floor[0]]; +- } +- +- ret = floor->decode(vc, &floor->data, ch_floor_ptr); +- +- if (ret < 0) { +- av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n"); +- return -1; +- } +- no_residue[i] = ret; +- ch_floor_ptr += blocksize / 2; +- } +- +-// Nonzero vector propagate +- +- for (i = mapping->coupling_steps - 1; i >= 0; --i) { +- if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { +- no_residue[mapping->magnitude[i]] = 0; +- no_residue[mapping->angle[i]] = 0; +- } +- } +- +-// Decode residue +- +- for (i = 0; i < mapping->submaps; ++i) { +- vorbis_residue *residue; +- uint_fast8_t ch = 0; +- +- for (j = 0; j < vc->audio_channels; ++j) { +- if ((mapping->submaps == 1) || (i == mapping->mux[j])) { +- res_chan[j] = res_num; +- if (no_residue[j]) { +- do_not_decode[ch] = 1; +- } else { +- do_not_decode[ch] = 0; +- } +- ++ch; +- ++res_num; +- } +- } +- residue = &vc->residues[mapping->submap_residue[i]]; +- vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, blocksize/2); +- +- ch_res_ptr += ch * blocksize / 2; +- } +- +-// Inverse coupling +- +- for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed +- float *mag, *ang; +- +- mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2; +- ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2; +- vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2); +- } +- +-// Dotproduct, MDCT +- +- for (j = vc->audio_channels-1;j >= 0; j--) { +- ch_floor_ptr = vc->channel_floors + j * blocksize / 2; +- ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2; +- vc->dsp.vector_fmul(ch_floor_ptr, ch_floor_ptr, ch_res_ptr, blocksize / 2); +- ff_imdct_half(&vc->mdct[blockflag], ch_res_ptr, ch_floor_ptr); +- } +- +-// Overlap/add, save data for next overlapping FPMATH +- +- retlen = (blocksize + vc->blocksize[previous_window]) / 4; +- for (j = 0; j < vc->audio_channels; j++) { +- uint_fast16_t bs0 = vc->blocksize[0]; +- uint_fast16_t bs1 = vc->blocksize[1]; +- float *residue = vc->channel_residues + res_chan[j] * blocksize / 2; +- float *saved = vc->saved + j * bs1 / 4; +- float *ret = vc->channel_floors + j * retlen; +- float *buf = residue; +- const float *win = vc->win[blockflag & previous_window]; +- +- if (blockflag == previous_window) { +- vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4); +- } else if (blockflag > previous_window) { +- vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4); +- memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float)); +- } else { +- memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float)); +- vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4); +- } +- memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float)); +- } +- +- vc->previous_window = blockflag; +- return retlen; +-} +- +-// Return the decoded audio packet through the standard api +- +-static int vorbis_decode_frame(AVCodecContext *avccontext, +- void *data, int *data_size, +- AVPacket *avpkt) +-{ +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- vorbis_context *vc = avccontext->priv_data ; +- GetBitContext *gb = &(vc->gb); +- const float *channel_ptrs[255]; +- int i; +- +- int_fast16_t len; +- +- if (!buf_size) +- return 0; +- +- AV_DEBUG("packet length %d \n", buf_size); +- +- init_get_bits(gb, buf, buf_size*8); +- +- len = vorbis_parse_audio_packet(vc); +- +- if (len <= 0) { +- *data_size = 0; +- return buf_size; +- } +- +- if (!vc->first_frame) { +- vc->first_frame = 1; +- *data_size = 0; +- return buf_size ; +- } +- +- AV_DEBUG("parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", get_bits_count(gb)/8, get_bits_count(gb)%8, len); +- +- if (vc->audio_channels > 8) { +- for (i = 0; i < vc->audio_channels; i++) +- channel_ptrs[i] = vc->channel_floors + i * len; +- } else { +- for (i = 0; i < vc->audio_channels; i++) +- channel_ptrs[i] = vc->channel_floors + +- len * ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i]; +- } +- +- vc->fmt_conv.float_to_int16_interleave(data, channel_ptrs, len, +- vc->audio_channels); +- *data_size = len * 2 * vc->audio_channels; +- +- return buf_size ; +-} +- +-// Close decoder +- +-static av_cold int vorbis_decode_close(AVCodecContext *avccontext) +-{ +- vorbis_context *vc = avccontext->priv_data; +- +- vorbis_free(vc); +- +- return 0 ; +-} +- +-AVCodec ff_vorbis_decoder = { +- "vorbis", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_VORBIS, +- sizeof(vorbis_context), +- vorbis_decode_init, +- NULL, +- vorbis_decode_close, +- vorbis_decode_frame, +- .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), +- .channel_layouts = ff_vorbis_channel_layouts, +-}; +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbisdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbisdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbisdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbisdec.c 2012-05-14 14:08:54.371340726 +0200 +@@ -0,0 +1,1728 @@ ++/** ++ * @file ++ * Vorbis I decoder ++ * @author Denes Balatoni ( dbalatoni programozo hu ) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Vorbis I decoder ++ * @author Denes Balatoni ( dbalatoni programozo hu ) ++ */ ++ ++#include ++#include ++ ++#define BITSTREAM_READER_LE ++#include "avcodec.h" ++#include "get_bits.h" ++#include "dsputil.h" ++#include "fft.h" ++#include "fmtconvert.h" ++ ++#include "vorbis.h" ++#include "xiph.h" ++ ++#define V_NB_BITS 8 ++#define V_NB_BITS2 11 ++#define V_MAX_VLCS (1 << 16) ++#define V_MAX_PARTITIONS (1 << 20) ++ ++#undef NDEBUG ++#include ++ ++typedef struct { ++ uint8_t dimensions; ++ uint8_t lookup_type; ++ uint8_t maxdepth; ++ VLC vlc; ++ float *codevectors; ++ unsigned int nb_bits; ++} vorbis_codebook; ++ ++typedef union vorbis_floor_u vorbis_floor_data; ++typedef struct vorbis_floor0_s vorbis_floor0; ++typedef struct vorbis_floor1_s vorbis_floor1; ++struct vorbis_context_s; ++typedef ++int (* vorbis_floor_decode_func) ++ (struct vorbis_context_s *, vorbis_floor_data *, float *); ++typedef struct { ++ uint8_t floor_type; ++ vorbis_floor_decode_func decode; ++ union vorbis_floor_u { ++ struct vorbis_floor0_s { ++ uint8_t order; ++ uint16_t rate; ++ uint16_t bark_map_size; ++ int32_t *map[2]; ++ uint32_t map_size[2]; ++ uint8_t amplitude_bits; ++ uint8_t amplitude_offset; ++ uint8_t num_books; ++ uint8_t *book_list; ++ float *lsp; ++ } t0; ++ struct vorbis_floor1_s { ++ uint8_t partitions; ++ uint8_t partition_class[32]; ++ uint8_t class_dimensions[16]; ++ uint8_t class_subclasses[16]; ++ uint8_t class_masterbook[16]; ++ int16_t subclass_books[16][8]; ++ uint8_t multiplier; ++ uint16_t x_list_dim; ++ vorbis_floor1_entry *list; ++ } t1; ++ } data; ++} vorbis_floor; ++ ++typedef struct { ++ uint16_t type; ++ uint32_t begin; ++ uint32_t end; ++ unsigned partition_size; ++ uint8_t classifications; ++ uint8_t classbook; ++ int16_t books[64][8]; ++ uint8_t maxpass; ++ uint16_t ptns_to_read; ++ uint8_t *classifs; ++} vorbis_residue; ++ ++typedef struct { ++ uint8_t submaps; ++ uint16_t coupling_steps; ++ uint8_t *magnitude; ++ uint8_t *angle; ++ uint8_t *mux; ++ uint8_t submap_floor[16]; ++ uint8_t submap_residue[16]; ++} vorbis_mapping; ++ ++typedef struct { ++ uint8_t blockflag; ++ uint16_t windowtype; ++ uint16_t transformtype; ++ uint8_t mapping; ++} vorbis_mode; ++ ++typedef struct vorbis_context_s { ++ AVCodecContext *avccontext; ++ AVFrame frame; ++ GetBitContext gb; ++ DSPContext dsp; ++ FmtConvertContext fmt_conv; ++ ++ FFTContext mdct[2]; ++ uint8_t first_frame; ++ uint32_t version; ++ uint8_t audio_channels; ++ uint32_t audio_samplerate; ++ uint32_t bitrate_maximum; ++ uint32_t bitrate_nominal; ++ uint32_t bitrate_minimum; ++ uint32_t blocksize[2]; ++ const float *win[2]; ++ uint16_t codebook_count; ++ vorbis_codebook *codebooks; ++ uint8_t floor_count; ++ vorbis_floor *floors; ++ uint8_t residue_count; ++ vorbis_residue *residues; ++ uint8_t mapping_count; ++ vorbis_mapping *mappings; ++ uint8_t mode_count; ++ vorbis_mode *modes; ++ uint8_t mode_number; // mode number for the current packet ++ uint8_t previous_window; ++ float *channel_residues; ++ float *channel_floors; ++ float *saved; ++ float scale_bias; // for float->int conversion ++} vorbis_context; ++ ++/* Helper functions */ ++ ++#define BARK(x) \ ++ (13.1f * atan(0.00074f * (x)) + 2.24f * atan(1.85e-8f * (x) * (x)) + 1e-4f * (x)) ++ ++static const char idx_err_str[] = "Index value %d out of range (0 - %d) for %s at %s:%i\n"; ++#define VALIDATE_INDEX(idx, limit) \ ++ if (idx >= limit) {\ ++ av_log(vc->avccontext, AV_LOG_ERROR,\ ++ idx_err_str,\ ++ (int)(idx), (int)(limit - 1), #idx, __FILE__, __LINE__);\ ++ return AVERROR_INVALIDDATA;\ ++ } ++#define GET_VALIDATED_INDEX(idx, bits, limit) \ ++ {\ ++ idx = get_bits(gb, bits);\ ++ VALIDATE_INDEX(idx, limit)\ ++ } ++ ++static float vorbisfloat2float(unsigned val) ++{ ++ double mant = val & 0x1fffff; ++ long exp = (val & 0x7fe00000L) >> 21; ++ if (val & 0x80000000) ++ mant = -mant; ++ return ldexp(mant, exp - 20 - 768); ++} ++ ++ ++// Free all allocated memory ----------------------------------------- ++ ++static void vorbis_free(vorbis_context *vc) ++{ ++ int i; ++ ++ av_freep(&vc->channel_residues); ++ av_freep(&vc->channel_floors); ++ av_freep(&vc->saved); ++ ++ for (i = 0; i < vc->residue_count; i++) ++ av_free(vc->residues[i].classifs); ++ av_freep(&vc->residues); ++ av_freep(&vc->modes); ++ ++ ff_mdct_end(&vc->mdct[0]); ++ ff_mdct_end(&vc->mdct[1]); ++ ++ for (i = 0; i < vc->codebook_count; ++i) { ++ av_free(vc->codebooks[i].codevectors); ++ free_vlc(&vc->codebooks[i].vlc); ++ } ++ av_freep(&vc->codebooks); ++ ++ for (i = 0; i < vc->floor_count; ++i) { ++ if (vc->floors[i].floor_type == 0) { ++ av_free(vc->floors[i].data.t0.map[0]); ++ av_free(vc->floors[i].data.t0.map[1]); ++ av_free(vc->floors[i].data.t0.book_list); ++ av_free(vc->floors[i].data.t0.lsp); ++ } else { ++ av_free(vc->floors[i].data.t1.list); ++ } ++ } ++ av_freep(&vc->floors); ++ ++ for (i = 0; i < vc->mapping_count; ++i) { ++ av_free(vc->mappings[i].magnitude); ++ av_free(vc->mappings[i].angle); ++ av_free(vc->mappings[i].mux); ++ } ++ av_freep(&vc->mappings); ++} ++ ++// Parse setup header ------------------------------------------------- ++ ++// Process codebooks part ++ ++static int vorbis_parse_setup_hdr_codebooks(vorbis_context *vc) ++{ ++ unsigned cb; ++ uint8_t *tmp_vlc_bits; ++ uint32_t *tmp_vlc_codes; ++ GetBitContext *gb = &vc->gb; ++ uint16_t *codebook_multiplicands; ++ int ret = 0; ++ ++ vc->codebook_count = get_bits(gb, 8) + 1; ++ ++ av_dlog(NULL, " Codebooks: %d \n", vc->codebook_count); ++ ++ vc->codebooks = av_mallocz(vc->codebook_count * sizeof(*vc->codebooks)); ++ tmp_vlc_bits = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_bits)); ++ tmp_vlc_codes = av_mallocz(V_MAX_VLCS * sizeof(*tmp_vlc_codes)); ++ codebook_multiplicands = av_malloc(V_MAX_VLCS * sizeof(*codebook_multiplicands)); ++ ++ for (cb = 0; cb < vc->codebook_count; ++cb) { ++ vorbis_codebook *codebook_setup = &vc->codebooks[cb]; ++ unsigned ordered, t, entries, used_entries = 0; ++ ++ av_dlog(NULL, " %u. Codebook\n", cb); ++ ++ if (get_bits(gb, 24) != 0x564342) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ " %u. Codebook setup data corrupt.\n", cb); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ ++ codebook_setup->dimensions=get_bits(gb, 16); ++ if (codebook_setup->dimensions > 16 || codebook_setup->dimensions == 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ " %u. Codebook's dimension is invalid (%d).\n", ++ cb, codebook_setup->dimensions); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ entries = get_bits(gb, 24); ++ if (entries > V_MAX_VLCS) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ " %u. Codebook has too many entries (%u).\n", ++ cb, entries); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ ++ ordered = get_bits1(gb); ++ ++ av_dlog(NULL, " codebook_dimensions %d, codebook_entries %u\n", ++ codebook_setup->dimensions, entries); ++ ++ if (!ordered) { ++ unsigned ce, flag; ++ unsigned sparse = get_bits1(gb); ++ ++ av_dlog(NULL, " not ordered \n"); ++ ++ if (sparse) { ++ av_dlog(NULL, " sparse \n"); ++ ++ used_entries = 0; ++ for (ce = 0; ce < entries; ++ce) { ++ flag = get_bits1(gb); ++ if (flag) { ++ tmp_vlc_bits[ce] = get_bits(gb, 5) + 1; ++ ++used_entries; ++ } else ++ tmp_vlc_bits[ce] = 0; ++ } ++ } else { ++ av_dlog(NULL, " not sparse \n"); ++ ++ used_entries = entries; ++ for (ce = 0; ce < entries; ++ce) ++ tmp_vlc_bits[ce] = get_bits(gb, 5) + 1; ++ } ++ } else { ++ unsigned current_entry = 0; ++ unsigned current_length = get_bits(gb, 5) + 1; ++ ++ av_dlog(NULL, " ordered, current length: %u\n", current_length); //FIXME ++ ++ used_entries = entries; ++ for (; current_entry < used_entries && current_length <= 32; ++current_length) { ++ unsigned i, number; ++ ++ av_dlog(NULL, " number bits: %u ", ilog(entries - current_entry)); ++ ++ number = get_bits(gb, ilog(entries - current_entry)); ++ ++ av_dlog(NULL, " number: %u\n", number); ++ ++ for (i = current_entry; i < number+current_entry; ++i) ++ if (i < used_entries) ++ tmp_vlc_bits[i] = current_length; ++ ++ current_entry+=number; ++ } ++ if (current_entry>used_entries) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " More codelengths than codes in codebook. \n"); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ } ++ ++ codebook_setup->lookup_type = get_bits(gb, 4); ++ ++ av_dlog(NULL, " lookup type: %d : %s \n", codebook_setup->lookup_type, ++ codebook_setup->lookup_type ? "vq" : "no lookup"); ++ ++// If the codebook is used for (inverse) VQ, calculate codevectors. ++ ++ if (codebook_setup->lookup_type == 1) { ++ unsigned i, j, k; ++ unsigned codebook_lookup_values = ff_vorbis_nth_root(entries, codebook_setup->dimensions); ++ ++ float codebook_minimum_value = vorbisfloat2float(get_bits_long(gb, 32)); ++ float codebook_delta_value = vorbisfloat2float(get_bits_long(gb, 32)); ++ unsigned codebook_value_bits = get_bits(gb, 4) + 1; ++ unsigned codebook_sequence_p = get_bits1(gb); ++ ++ av_dlog(NULL, " We expect %d numbers for building the codevectors. \n", ++ codebook_lookup_values); ++ av_dlog(NULL, " delta %f minmum %f \n", ++ codebook_delta_value, codebook_minimum_value); ++ ++ for (i = 0; i < codebook_lookup_values; ++i) { ++ codebook_multiplicands[i] = get_bits(gb, codebook_value_bits); ++ ++ av_dlog(NULL, " multiplicands*delta+minmum : %e \n", ++ (float)codebook_multiplicands[i] * codebook_delta_value + codebook_minimum_value); ++ av_dlog(NULL, " multiplicand %u\n", codebook_multiplicands[i]); ++ } ++ ++// Weed out unused vlcs and build codevector vector ++ codebook_setup->codevectors = used_entries ? av_mallocz(used_entries * ++ codebook_setup->dimensions * ++ sizeof(*codebook_setup->codevectors)) ++ : NULL; ++ for (j = 0, i = 0; i < entries; ++i) { ++ unsigned dim = codebook_setup->dimensions; ++ ++ if (tmp_vlc_bits[i]) { ++ float last = 0.0; ++ unsigned lookup_offset = i; ++ ++ av_dlog(vc->avccontext, "Lookup offset %u ,", i); ++ ++ for (k = 0; k < dim; ++k) { ++ unsigned multiplicand_offset = lookup_offset % codebook_lookup_values; ++ codebook_setup->codevectors[j * dim + k] = codebook_multiplicands[multiplicand_offset] * codebook_delta_value + codebook_minimum_value + last; ++ if (codebook_sequence_p) ++ last = codebook_setup->codevectors[j * dim + k]; ++ lookup_offset/=codebook_lookup_values; ++ } ++ tmp_vlc_bits[j] = tmp_vlc_bits[i]; ++ ++ av_dlog(vc->avccontext, "real lookup offset %u, vector: ", j); ++ for (k = 0; k < dim; ++k) ++ av_dlog(vc->avccontext, " %f ", ++ codebook_setup->codevectors[j * dim + k]); ++ av_dlog(vc->avccontext, "\n"); ++ ++ ++j; ++ } ++ } ++ if (j != used_entries) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Bug in codevector vector building code. \n"); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ entries = used_entries; ++ } else if (codebook_setup->lookup_type >= 2) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Codebook lookup type not supported. \n"); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ ++// Initialize VLC table ++ if (ff_vorbis_len2vlc(tmp_vlc_bits, tmp_vlc_codes, entries)) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Invalid code lengths while generating vlcs. \n"); ++ ret = AVERROR_INVALIDDATA; ++ goto error; ++ } ++ codebook_setup->maxdepth = 0; ++ for (t = 0; t < entries; ++t) ++ if (tmp_vlc_bits[t] >= codebook_setup->maxdepth) ++ codebook_setup->maxdepth = tmp_vlc_bits[t]; ++ ++ if (codebook_setup->maxdepth > 3 * V_NB_BITS) ++ codebook_setup->nb_bits = V_NB_BITS2; ++ else ++ codebook_setup->nb_bits = V_NB_BITS; ++ ++ codebook_setup->maxdepth = (codebook_setup->maxdepth+codebook_setup->nb_bits - 1) / codebook_setup->nb_bits; ++ ++ if ((ret = init_vlc(&codebook_setup->vlc, codebook_setup->nb_bits, ++ entries, tmp_vlc_bits, sizeof(*tmp_vlc_bits), ++ sizeof(*tmp_vlc_bits), tmp_vlc_codes, ++ sizeof(*tmp_vlc_codes), sizeof(*tmp_vlc_codes), ++ INIT_VLC_LE))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Error generating vlc tables. \n"); ++ goto error; ++ } ++ } ++ ++ av_free(tmp_vlc_bits); ++ av_free(tmp_vlc_codes); ++ av_free(codebook_multiplicands); ++ return 0; ++ ++// Error: ++error: ++ av_free(tmp_vlc_bits); ++ av_free(tmp_vlc_codes); ++ av_free(codebook_multiplicands); ++ return ret; ++} ++ ++// Process time domain transforms part (unused in Vorbis I) ++ ++static int vorbis_parse_setup_hdr_tdtransforms(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned i, vorbis_time_count = get_bits(gb, 6) + 1; ++ ++ for (i = 0; i < vorbis_time_count; ++i) { ++ unsigned vorbis_tdtransform = get_bits(gb, 16); ++ ++ av_dlog(NULL, " Vorbis time domain transform %u: %u\n", ++ vorbis_time_count, vorbis_tdtransform); ++ ++ if (vorbis_tdtransform) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis time domain transform data nonzero. \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ return 0; ++} ++ ++// Process floors part ++ ++static int vorbis_floor0_decode(vorbis_context *vc, ++ vorbis_floor_data *vfu, float *vec); ++static void create_map(vorbis_context *vc, unsigned floor_number); ++static int vorbis_floor1_decode(vorbis_context *vc, ++ vorbis_floor_data *vfu, float *vec); ++static int vorbis_parse_setup_hdr_floors(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ int i,j,k; ++ ++ vc->floor_count = get_bits(gb, 6) + 1; ++ ++ vc->floors = av_mallocz(vc->floor_count * sizeof(*vc->floors)); ++ ++ for (i = 0; i < vc->floor_count; ++i) { ++ vorbis_floor *floor_setup = &vc->floors[i]; ++ ++ floor_setup->floor_type = get_bits(gb, 16); ++ ++ av_dlog(NULL, " %d. floor type %d \n", i, floor_setup->floor_type); ++ ++ if (floor_setup->floor_type == 1) { ++ int maximum_class = -1; ++ unsigned rangebits, rangemax, floor1_values = 2; ++ ++ floor_setup->decode = vorbis_floor1_decode; ++ ++ floor_setup->data.t1.partitions = get_bits(gb, 5); ++ ++ av_dlog(NULL, " %d.floor: %d partitions \n", ++ i, floor_setup->data.t1.partitions); ++ ++ for (j = 0; j < floor_setup->data.t1.partitions; ++j) { ++ floor_setup->data.t1.partition_class[j] = get_bits(gb, 4); ++ if (floor_setup->data.t1.partition_class[j] > maximum_class) ++ maximum_class = floor_setup->data.t1.partition_class[j]; ++ ++ av_dlog(NULL, " %d. floor %d partition class %d \n", ++ i, j, floor_setup->data.t1.partition_class[j]); ++ ++ } ++ ++ av_dlog(NULL, " maximum class %d \n", maximum_class); ++ ++ for (j = 0; j <= maximum_class; ++j) { ++ floor_setup->data.t1.class_dimensions[j] = get_bits(gb, 3) + 1; ++ floor_setup->data.t1.class_subclasses[j] = get_bits(gb, 2); ++ ++ av_dlog(NULL, " %d floor %d class dim: %d subclasses %d \n", i, j, ++ floor_setup->data.t1.class_dimensions[j], ++ floor_setup->data.t1.class_subclasses[j]); ++ ++ if (floor_setup->data.t1.class_subclasses[j]) { ++ GET_VALIDATED_INDEX(floor_setup->data.t1.class_masterbook[j], 8, vc->codebook_count) ++ ++ av_dlog(NULL, " masterbook: %d \n", floor_setup->data.t1.class_masterbook[j]); ++ } ++ ++ for (k = 0; k < (1 << floor_setup->data.t1.class_subclasses[j]); ++k) { ++ int16_t bits = get_bits(gb, 8) - 1; ++ if (bits != -1) ++ VALIDATE_INDEX(bits, vc->codebook_count) ++ floor_setup->data.t1.subclass_books[j][k] = bits; ++ ++ av_dlog(NULL, " book %d. : %d \n", k, floor_setup->data.t1.subclass_books[j][k]); ++ } ++ } ++ ++ floor_setup->data.t1.multiplier = get_bits(gb, 2) + 1; ++ floor_setup->data.t1.x_list_dim = 2; ++ ++ for (j = 0; j < floor_setup->data.t1.partitions; ++j) ++ floor_setup->data.t1.x_list_dim+=floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++ ++ floor_setup->data.t1.list = av_mallocz(floor_setup->data.t1.x_list_dim * ++ sizeof(*floor_setup->data.t1.list)); ++ ++ ++ rangebits = get_bits(gb, 4); ++ rangemax = (1 << rangebits); ++ if (rangemax > vc->blocksize[1] / 2) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ "Floor value is too large for blocksize: %u (%"PRIu32")\n", ++ rangemax, vc->blocksize[1] / 2); ++ return AVERROR_INVALIDDATA; ++ } ++ floor_setup->data.t1.list[0].x = 0; ++ floor_setup->data.t1.list[1].x = rangemax; ++ ++ for (j = 0; j < floor_setup->data.t1.partitions; ++j) { ++ for (k = 0; k < floor_setup->data.t1.class_dimensions[floor_setup->data.t1.partition_class[j]]; ++k, ++floor1_values) { ++ floor_setup->data.t1.list[floor1_values].x = get_bits(gb, rangebits); ++ ++ av_dlog(NULL, " %u. floor1 Y coord. %d\n", floor1_values, ++ floor_setup->data.t1.list[floor1_values].x); ++ } ++ } ++ ++// Precalculate order of x coordinates - needed for decode ++ ff_vorbis_ready_floor1_list(floor_setup->data.t1.list, floor_setup->data.t1.x_list_dim); ++ ++ for (j=1; jdata.t1.x_list_dim; j++) { ++ if ( floor_setup->data.t1.list[ floor_setup->data.t1.list[j-1].sort ].x ++ == floor_setup->data.t1.list[ floor_setup->data.t1.list[j ].sort ].x) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Non unique x values in floor type 1\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ } else if (floor_setup->floor_type == 0) { ++ unsigned max_codebook_dim = 0; ++ ++ floor_setup->decode = vorbis_floor0_decode; ++ ++ floor_setup->data.t0.order = get_bits(gb, 8); ++ floor_setup->data.t0.rate = get_bits(gb, 16); ++ floor_setup->data.t0.bark_map_size = get_bits(gb, 16); ++ floor_setup->data.t0.amplitude_bits = get_bits(gb, 6); ++ /* zero would result in a div by zero later * ++ * 2^0 - 1 == 0 */ ++ if (floor_setup->data.t0.amplitude_bits == 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ "Floor 0 amplitude bits is 0.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ floor_setup->data.t0.amplitude_offset = get_bits(gb, 8); ++ floor_setup->data.t0.num_books = get_bits(gb, 4) + 1; ++ ++ /* allocate mem for booklist */ ++ floor_setup->data.t0.book_list = ++ av_malloc(floor_setup->data.t0.num_books); ++ if (!floor_setup->data.t0.book_list) ++ return AVERROR(ENOMEM); ++ /* read book indexes */ ++ { ++ int idx; ++ unsigned book_idx; ++ for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { ++ GET_VALIDATED_INDEX(book_idx, 8, vc->codebook_count) ++ floor_setup->data.t0.book_list[idx] = book_idx; ++ if (vc->codebooks[book_idx].dimensions > max_codebook_dim) ++ max_codebook_dim = vc->codebooks[book_idx].dimensions; ++ } ++ } ++ ++ create_map(vc, i); ++ ++ /* codebook dim is for padding if codebook dim doesn't * ++ * divide order+1 then we need to read more data */ ++ floor_setup->data.t0.lsp = ++ av_malloc((floor_setup->data.t0.order + 1 + max_codebook_dim) ++ * sizeof(*floor_setup->data.t0.lsp)); ++ if (!floor_setup->data.t0.lsp) ++ return AVERROR(ENOMEM); ++ ++ /* debug output parsed headers */ ++ av_dlog(NULL, "floor0 order: %u\n", floor_setup->data.t0.order); ++ av_dlog(NULL, "floor0 rate: %u\n", floor_setup->data.t0.rate); ++ av_dlog(NULL, "floor0 bark map size: %u\n", ++ floor_setup->data.t0.bark_map_size); ++ av_dlog(NULL, "floor0 amplitude bits: %u\n", ++ floor_setup->data.t0.amplitude_bits); ++ av_dlog(NULL, "floor0 amplitude offset: %u\n", ++ floor_setup->data.t0.amplitude_offset); ++ av_dlog(NULL, "floor0 number of books: %u\n", ++ floor_setup->data.t0.num_books); ++ av_dlog(NULL, "floor0 book list pointer: %p\n", ++ floor_setup->data.t0.book_list); ++ { ++ int idx; ++ for (idx = 0; idx < floor_setup->data.t0.num_books; ++idx) { ++ av_dlog(NULL, " Book %d: %u\n", idx + 1, ++ floor_setup->data.t0.book_list[idx]); ++ } ++ } ++ } else { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Invalid floor type!\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ return 0; ++} ++ ++// Process residues part ++ ++static int vorbis_parse_setup_hdr_residues(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned i, j, k; ++ ++ vc->residue_count = get_bits(gb, 6)+1; ++ vc->residues = av_mallocz(vc->residue_count * sizeof(*vc->residues)); ++ ++ av_dlog(NULL, " There are %d residues. \n", vc->residue_count); ++ ++ for (i = 0; i < vc->residue_count; ++i) { ++ vorbis_residue *res_setup = &vc->residues[i]; ++ uint8_t cascade[64]; ++ unsigned high_bits, low_bits; ++ ++ res_setup->type = get_bits(gb, 16); ++ ++ av_dlog(NULL, " %u. residue type %d\n", i, res_setup->type); ++ ++ res_setup->begin = get_bits(gb, 24); ++ res_setup->end = get_bits(gb, 24); ++ res_setup->partition_size = get_bits(gb, 24) + 1; ++ /* Validations to prevent a buffer overflow later. */ ++ if (res_setup->begin>res_setup->end || ++ res_setup->end > (res_setup->type == 2 ? vc->avccontext->channels : 1) * vc->blocksize[1] / 2 || ++ (res_setup->end-res_setup->begin) / res_setup->partition_size > V_MAX_PARTITIONS) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ "partition out of bounds: type, begin, end, size, blocksize: %"PRIu16", %"PRIu32", %"PRIu32", %u, %"PRIu32"\n", ++ res_setup->type, res_setup->begin, res_setup->end, ++ res_setup->partition_size, vc->blocksize[1] / 2); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ res_setup->classifications = get_bits(gb, 6) + 1; ++ GET_VALIDATED_INDEX(res_setup->classbook, 8, vc->codebook_count) ++ ++ res_setup->ptns_to_read = ++ (res_setup->end - res_setup->begin) / res_setup->partition_size; ++ res_setup->classifs = av_malloc(res_setup->ptns_to_read * ++ vc->audio_channels * ++ sizeof(*res_setup->classifs)); ++ if (!res_setup->classifs) ++ return AVERROR(ENOMEM); ++ ++ av_dlog(NULL, " begin %d end %d part.size %d classif.s %d classbook %d \n", ++ res_setup->begin, res_setup->end, res_setup->partition_size, ++ res_setup->classifications, res_setup->classbook); ++ ++ for (j = 0; j < res_setup->classifications; ++j) { ++ high_bits = 0; ++ low_bits = get_bits(gb, 3); ++ if (get_bits1(gb)) ++ high_bits = get_bits(gb, 5); ++ cascade[j] = (high_bits << 3) + low_bits; ++ ++ av_dlog(NULL, " %u class cascade depth: %d\n", j, ilog(cascade[j])); ++ } ++ ++ res_setup->maxpass = 0; ++ for (j = 0; j < res_setup->classifications; ++j) { ++ for (k = 0; k < 8; ++k) { ++ if (cascade[j]&(1 << k)) { ++ GET_VALIDATED_INDEX(res_setup->books[j][k], 8, vc->codebook_count) ++ ++ av_dlog(NULL, " %u class cascade depth %u book: %d\n", ++ j, k, res_setup->books[j][k]); ++ ++ if (k>res_setup->maxpass) ++ res_setup->maxpass = k; ++ } else { ++ res_setup->books[j][k] = -1; ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++// Process mappings part ++ ++static int vorbis_parse_setup_hdr_mappings(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned i, j; ++ ++ vc->mapping_count = get_bits(gb, 6)+1; ++ vc->mappings = av_mallocz(vc->mapping_count * sizeof(*vc->mappings)); ++ ++ av_dlog(NULL, " There are %d mappings. \n", vc->mapping_count); ++ ++ for (i = 0; i < vc->mapping_count; ++i) { ++ vorbis_mapping *mapping_setup = &vc->mappings[i]; ++ ++ if (get_bits(gb, 16)) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Other mappings than type 0 are not compliant with the Vorbis I specification. \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (get_bits1(gb)) { ++ mapping_setup->submaps = get_bits(gb, 4) + 1; ++ } else { ++ mapping_setup->submaps = 1; ++ } ++ ++ if (get_bits1(gb)) { ++ mapping_setup->coupling_steps = get_bits(gb, 8) + 1; ++ mapping_setup->magnitude = av_mallocz(mapping_setup->coupling_steps * ++ sizeof(*mapping_setup->magnitude)); ++ mapping_setup->angle = av_mallocz(mapping_setup->coupling_steps * ++ sizeof(*mapping_setup->angle)); ++ for (j = 0; j < mapping_setup->coupling_steps; ++j) { ++ GET_VALIDATED_INDEX(mapping_setup->magnitude[j], ilog(vc->audio_channels - 1), vc->audio_channels) ++ GET_VALIDATED_INDEX(mapping_setup->angle[j], ilog(vc->audio_channels - 1), vc->audio_channels) ++ } ++ } else { ++ mapping_setup->coupling_steps = 0; ++ } ++ ++ av_dlog(NULL, " %u mapping coupling steps: %d\n", ++ i, mapping_setup->coupling_steps); ++ ++ if (get_bits(gb, 2)) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "%u. mapping setup data invalid.\n", i); ++ return AVERROR_INVALIDDATA; // following spec. ++ } ++ ++ if (mapping_setup->submaps>1) { ++ mapping_setup->mux = av_mallocz(vc->audio_channels * ++ sizeof(*mapping_setup->mux)); ++ for (j = 0; j < vc->audio_channels; ++j) ++ mapping_setup->mux[j] = get_bits(gb, 4); ++ } ++ ++ for (j = 0; j < mapping_setup->submaps; ++j) { ++ skip_bits(gb, 8); // FIXME check? ++ GET_VALIDATED_INDEX(mapping_setup->submap_floor[j], 8, vc->floor_count) ++ GET_VALIDATED_INDEX(mapping_setup->submap_residue[j], 8, vc->residue_count) ++ ++ av_dlog(NULL, " %u mapping %u submap : floor %d, residue %d\n", i, j, ++ mapping_setup->submap_floor[j], ++ mapping_setup->submap_residue[j]); ++ } ++ } ++ return 0; ++} ++ ++// Process modes part ++ ++static void create_map(vorbis_context *vc, unsigned floor_number) ++{ ++ vorbis_floor *floors = vc->floors; ++ vorbis_floor0 *vf; ++ int idx; ++ int blockflag, n; ++ int32_t *map; ++ ++ for (blockflag = 0; blockflag < 2; ++blockflag) { ++ n = vc->blocksize[blockflag] / 2; ++ floors[floor_number].data.t0.map[blockflag] = ++ av_malloc((n + 1) * sizeof(int32_t)); // n + sentinel ++ ++ map = floors[floor_number].data.t0.map[blockflag]; ++ vf = &floors[floor_number].data.t0; ++ ++ for (idx = 0; idx < n; ++idx) { ++ map[idx] = floor(BARK((vf->rate * idx) / (2.0f * n)) * ++ (vf->bark_map_size / BARK(vf->rate / 2.0f))); ++ if (vf->bark_map_size-1 < map[idx]) ++ map[idx] = vf->bark_map_size - 1; ++ } ++ map[n] = -1; ++ vf->map_size[blockflag] = n; ++ } ++ ++ for (idx = 0; idx <= n; ++idx) { ++ av_dlog(NULL, "floor0 map: map at pos %d is %d\n", idx, map[idx]); ++ } ++} ++ ++static int vorbis_parse_setup_hdr_modes(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned i; ++ ++ vc->mode_count = get_bits(gb, 6) + 1; ++ vc->modes = av_mallocz(vc->mode_count * sizeof(*vc->modes)); ++ ++ av_dlog(NULL, " There are %d modes.\n", vc->mode_count); ++ ++ for (i = 0; i < vc->mode_count; ++i) { ++ vorbis_mode *mode_setup = &vc->modes[i]; ++ ++ mode_setup->blockflag = get_bits1(gb); ++ mode_setup->windowtype = get_bits(gb, 16); //FIXME check ++ mode_setup->transformtype = get_bits(gb, 16); //FIXME check ++ GET_VALIDATED_INDEX(mode_setup->mapping, 8, vc->mapping_count); ++ ++ av_dlog(NULL, " %u mode: blockflag %d, windowtype %d, transformtype %d, mapping %d\n", ++ i, mode_setup->blockflag, mode_setup->windowtype, ++ mode_setup->transformtype, mode_setup->mapping); ++ } ++ return 0; ++} ++ ++// Process the whole setup header using the functions above ++ ++static int vorbis_parse_setup_hdr(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ int ret; ++ ++ if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || ++ (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || ++ (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (no vorbis signature). \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((ret = vorbis_parse_setup_hdr_codebooks(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (codebooks). \n"); ++ return ret; ++ } ++ if ((ret = vorbis_parse_setup_hdr_tdtransforms(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (time domain transforms). \n"); ++ return ret; ++ } ++ if ((ret = vorbis_parse_setup_hdr_floors(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (floors). \n"); ++ return ret; ++ } ++ if ((ret = vorbis_parse_setup_hdr_residues(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (residues). \n"); ++ return ret; ++ } ++ if ((ret = vorbis_parse_setup_hdr_mappings(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (mappings). \n"); ++ return ret; ++ } ++ if ((ret = vorbis_parse_setup_hdr_modes(vc))) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (modes). \n"); ++ return ret; ++ } ++ if (!get_bits1(gb)) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis setup header packet corrupt (framing flag). \n"); ++ return AVERROR_INVALIDDATA; // framing flag bit unset error ++ } ++ ++ return 0; ++} ++ ++// Process the identification header ++ ++static int vorbis_parse_id_hdr(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned bl0, bl1; ++ ++ if ((get_bits(gb, 8) != 'v') || (get_bits(gb, 8) != 'o') || ++ (get_bits(gb, 8) != 'r') || (get_bits(gb, 8) != 'b') || ++ (get_bits(gb, 8) != 'i') || (get_bits(gb, 8) != 's')) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (no vorbis signature). \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ vc->version = get_bits_long(gb, 32); //FIXME check 0 ++ vc->audio_channels = get_bits(gb, 8); ++ if (vc->audio_channels <= 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Invalid number of channels\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ vc->audio_samplerate = get_bits_long(gb, 32); ++ if (vc->audio_samplerate <= 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Invalid samplerate\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ vc->bitrate_maximum = get_bits_long(gb, 32); ++ vc->bitrate_nominal = get_bits_long(gb, 32); ++ vc->bitrate_minimum = get_bits_long(gb, 32); ++ bl0 = get_bits(gb, 4); ++ bl1 = get_bits(gb, 4); ++ if (bl0 > 13 || bl0 < 6 || bl1 > 13 || bl1 < 6 || bl1 < bl0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ vc->blocksize[0] = (1 << bl0); ++ vc->blocksize[1] = (1 << bl1); ++ vc->win[0] = ff_vorbis_vwin[bl0 - 6]; ++ vc->win[1] = ff_vorbis_vwin[bl1 - 6]; ++ ++ if ((get_bits1(gb)) == 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (framing flag not set). \n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ vc->channel_residues = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(*vc->channel_residues)); ++ vc->channel_floors = av_malloc((vc->blocksize[1] / 2) * vc->audio_channels * sizeof(*vc->channel_floors)); ++ vc->saved = av_mallocz((vc->blocksize[1] / 4) * vc->audio_channels * sizeof(*vc->saved)); ++ vc->previous_window = 0; ++ ++ ff_mdct_init(&vc->mdct[0], bl0, 1, -vc->scale_bias); ++ ff_mdct_init(&vc->mdct[1], bl1, 1, -vc->scale_bias); ++ ++ av_dlog(NULL, " vorbis version %d \n audio_channels %d \n audio_samplerate %d \n bitrate_max %d \n bitrate_nom %d \n bitrate_min %d \n blk_0 %d blk_1 %d \n ", ++ vc->version, vc->audio_channels, vc->audio_samplerate, vc->bitrate_maximum, vc->bitrate_nominal, vc->bitrate_minimum, vc->blocksize[0], vc->blocksize[1]); ++ ++/* ++ BLK = vc->blocksize[0]; ++ for (i = 0; i < BLK / 2; ++i) { ++ vc->win[0][i] = sin(0.5*3.14159265358*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))*(sin(((float)i + 0.5) / (float)BLK*3.14159265358))); ++ } ++*/ ++ ++ return 0; ++} ++ ++// Process the extradata using the functions above (identification header, setup header) ++ ++static av_cold int vorbis_decode_init(AVCodecContext *avccontext) ++{ ++ vorbis_context *vc = avccontext->priv_data; ++ uint8_t *headers = avccontext->extradata; ++ int headers_len = avccontext->extradata_size; ++ uint8_t *header_start[3]; ++ int header_len[3]; ++ GetBitContext *gb = &vc->gb; ++ int hdr_type, ret; ++ ++ vc->avccontext = avccontext; ++ dsputil_init(&vc->dsp, avccontext); ++ ff_fmt_convert_init(&vc->fmt_conv, avccontext); ++ ++ if (avccontext->request_sample_fmt == AV_SAMPLE_FMT_FLT) { ++ avccontext->sample_fmt = AV_SAMPLE_FMT_FLT; ++ vc->scale_bias = 1.0f; ++ } else { ++ avccontext->sample_fmt = AV_SAMPLE_FMT_S16; ++ vc->scale_bias = 32768.0f; ++ } ++ ++ if (!headers_len) { ++ av_log(avccontext, AV_LOG_ERROR, "Extradata missing.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((ret = avpriv_split_xiph_headers(headers, headers_len, 30, header_start, header_len)) < 0) { ++ av_log(avccontext, AV_LOG_ERROR, "Extradata corrupt.\n"); ++ return ret; ++ } ++ ++ init_get_bits(gb, header_start[0], header_len[0]*8); ++ hdr_type = get_bits(gb, 8); ++ if (hdr_type != 1) { ++ av_log(avccontext, AV_LOG_ERROR, "First header is not the id header.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if ((ret = vorbis_parse_id_hdr(vc))) { ++ av_log(avccontext, AV_LOG_ERROR, "Id header corrupt.\n"); ++ vorbis_free(vc); ++ return ret; ++ } ++ ++ init_get_bits(gb, header_start[2], header_len[2]*8); ++ hdr_type = get_bits(gb, 8); ++ if (hdr_type != 5) { ++ av_log(avccontext, AV_LOG_ERROR, "Third header is not the setup header.\n"); ++ vorbis_free(vc); ++ return AVERROR_INVALIDDATA; ++ } ++ if ((ret = vorbis_parse_setup_hdr(vc))) { ++ av_log(avccontext, AV_LOG_ERROR, "Setup header corrupt.\n"); ++ vorbis_free(vc); ++ return ret; ++ } ++ ++ if (vc->audio_channels > 8) ++ avccontext->channel_layout = 0; ++ else ++ avccontext->channel_layout = ff_vorbis_channel_layouts[vc->audio_channels - 1]; ++ ++ avccontext->channels = vc->audio_channels; ++ avccontext->sample_rate = vc->audio_samplerate; ++ avccontext->frame_size = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2; ++ ++ avcodec_get_frame_defaults(&vc->frame); ++ avccontext->coded_frame = &vc->frame; ++ ++ return 0; ++} ++ ++// Decode audiopackets ------------------------------------------------- ++ ++// Read and decode floor ++ ++static int vorbis_floor0_decode(vorbis_context *vc, ++ vorbis_floor_data *vfu, float *vec) ++{ ++ vorbis_floor0 *vf = &vfu->t0; ++ float *lsp = vf->lsp; ++ unsigned amplitude, book_idx; ++ unsigned blockflag = vc->modes[vc->mode_number].blockflag; ++ ++ amplitude = get_bits(&vc->gb, vf->amplitude_bits); ++ if (amplitude > 0) { ++ float last = 0; ++ unsigned idx, lsp_len = 0; ++ vorbis_codebook codebook; ++ ++ book_idx = get_bits(&vc->gb, ilog(vf->num_books)); ++ if (book_idx >= vf->num_books) { ++ av_log(vc->avccontext, AV_LOG_ERROR, ++ "floor0 dec: booknumber too high!\n"); ++ book_idx = 0; ++ } ++ av_dlog(NULL, "floor0 dec: booknumber: %u\n", book_idx); ++ codebook = vc->codebooks[vf->book_list[book_idx]]; ++ /* Invalid codebook! */ ++ if (!codebook.codevectors) ++ return AVERROR_INVALIDDATA; ++ ++ while (lsp_lenorder) { ++ int vec_off; ++ ++ av_dlog(NULL, "floor0 dec: book dimension: %d\n", codebook.dimensions); ++ av_dlog(NULL, "floor0 dec: maximum depth: %d\n", codebook.maxdepth); ++ /* read temp vector */ ++ vec_off = get_vlc2(&vc->gb, codebook.vlc.table, ++ codebook.nb_bits, codebook.maxdepth) ++ * codebook.dimensions; ++ av_dlog(NULL, "floor0 dec: vector offset: %d\n", vec_off); ++ /* copy each vector component and add last to it */ ++ for (idx = 0; idx < codebook.dimensions; ++idx) ++ lsp[lsp_len+idx] = codebook.codevectors[vec_off+idx] + last; ++ last = lsp[lsp_len+idx-1]; /* set last to last vector component */ ++ ++ lsp_len += codebook.dimensions; ++ } ++ /* DEBUG: output lsp coeffs */ ++ { ++ int idx; ++ for (idx = 0; idx < lsp_len; ++idx) ++ av_dlog(NULL, "floor0 dec: coeff at %d is %f\n", idx, lsp[idx]); ++ } ++ ++ /* synthesize floor output vector */ ++ { ++ int i; ++ int order = vf->order; ++ float wstep = M_PI / vf->bark_map_size; ++ ++ for (i = 0; i < order; i++) ++ lsp[i] = 2.0f * cos(lsp[i]); ++ ++ av_dlog(NULL, "floor0 synth: map_size = %"PRIu32"; m = %d; wstep = %f\n", ++ vf->map_size[blockflag], order, wstep); ++ ++ i = 0; ++ while (i < vf->map_size[blockflag]) { ++ int j, iter_cond = vf->map[blockflag][i]; ++ float p = 0.5f; ++ float q = 0.5f; ++ float two_cos_w = 2.0f * cos(wstep * iter_cond); // needed all times ++ ++ /* similar part for the q and p products */ ++ for (j = 0; j + 1 < order; j += 2) { ++ q *= lsp[j] - two_cos_w; ++ p *= lsp[j + 1] - two_cos_w; ++ } ++ if (j == order) { // even order ++ p *= p * (2.0f - two_cos_w); ++ q *= q * (2.0f + two_cos_w); ++ } else { // odd order ++ q *= two_cos_w-lsp[j]; // one more time for q ++ ++ /* final step and square */ ++ p *= p * (4.f - two_cos_w * two_cos_w); ++ q *= q; ++ } ++ ++ /* calculate linear floor value */ ++ q = exp((((amplitude*vf->amplitude_offset) / ++ (((1 << vf->amplitude_bits) - 1) * sqrt(p + q))) ++ - vf->amplitude_offset) * .11512925f); ++ ++ /* fill vector */ ++ do { ++ vec[i] = q; ++i; ++ } while (vf->map[blockflag][i] == iter_cond); ++ } ++ } ++ } else { ++ /* this channel is unused */ ++ return 1; ++ } ++ ++ av_dlog(NULL, " Floor0 decoded\n"); ++ ++ return 0; ++} ++ ++static int vorbis_floor1_decode(vorbis_context *vc, ++ vorbis_floor_data *vfu, float *vec) ++{ ++ vorbis_floor1 *vf = &vfu->t1; ++ GetBitContext *gb = &vc->gb; ++ uint16_t range_v[4] = { 256, 128, 86, 64 }; ++ unsigned range = range_v[vf->multiplier - 1]; ++ uint16_t floor1_Y[258]; ++ uint16_t floor1_Y_final[258]; ++ int floor1_flag[258]; ++ unsigned partition_class, cdim, cbits, csub, cval, offset, i, j; ++ int book, adx, ady, dy, off, predicted, err; ++ ++ ++ if (!get_bits1(gb)) // silence ++ return 1; ++ ++// Read values (or differences) for the floor's points ++ ++ floor1_Y[0] = get_bits(gb, ilog(range - 1)); ++ floor1_Y[1] = get_bits(gb, ilog(range - 1)); ++ ++ av_dlog(NULL, "floor 0 Y %d floor 1 Y %d \n", floor1_Y[0], floor1_Y[1]); ++ ++ offset = 2; ++ for (i = 0; i < vf->partitions; ++i) { ++ partition_class = vf->partition_class[i]; ++ cdim = vf->class_dimensions[partition_class]; ++ cbits = vf->class_subclasses[partition_class]; ++ csub = (1 << cbits) - 1; ++ cval = 0; ++ ++ av_dlog(NULL, "Cbits %u\n", cbits); ++ ++ if (cbits) // this reads all subclasses for this partition's class ++ cval = get_vlc2(gb, vc->codebooks[vf->class_masterbook[partition_class]].vlc.table, ++ vc->codebooks[vf->class_masterbook[partition_class]].nb_bits, 3); ++ ++ for (j = 0; j < cdim; ++j) { ++ book = vf->subclass_books[partition_class][cval & csub]; ++ ++ av_dlog(NULL, "book %d Cbits %u cval %u bits:%d\n", ++ book, cbits, cval, get_bits_count(gb)); ++ ++ cval = cval >> cbits; ++ if (book > -1) { ++ floor1_Y[offset+j] = get_vlc2(gb, vc->codebooks[book].vlc.table, ++ vc->codebooks[book].nb_bits, 3); ++ } else { ++ floor1_Y[offset+j] = 0; ++ } ++ ++ av_dlog(NULL, " floor(%d) = %d \n", ++ vf->list[offset+j].x, floor1_Y[offset+j]); ++ } ++ offset+=cdim; ++ } ++ ++// Amplitude calculation from the differences ++ ++ floor1_flag[0] = 1; ++ floor1_flag[1] = 1; ++ floor1_Y_final[0] = floor1_Y[0]; ++ floor1_Y_final[1] = floor1_Y[1]; ++ ++ for (i = 2; i < vf->x_list_dim; ++i) { ++ unsigned val, highroom, lowroom, room, high_neigh_offs, low_neigh_offs; ++ ++ low_neigh_offs = vf->list[i].low; ++ high_neigh_offs = vf->list[i].high; ++ dy = floor1_Y_final[high_neigh_offs] - floor1_Y_final[low_neigh_offs]; // render_point begin ++ adx = vf->list[high_neigh_offs].x - vf->list[low_neigh_offs].x; ++ ady = FFABS(dy); ++ err = ady * (vf->list[i].x - vf->list[low_neigh_offs].x); ++ off = err / adx; ++ if (dy < 0) { ++ predicted = floor1_Y_final[low_neigh_offs] - off; ++ } else { ++ predicted = floor1_Y_final[low_neigh_offs] + off; ++ } // render_point end ++ ++ val = floor1_Y[i]; ++ highroom = range-predicted; ++ lowroom = predicted; ++ if (highroom < lowroom) { ++ room = highroom * 2; ++ } else { ++ room = lowroom * 2; // SPEC mispelling ++ } ++ if (val) { ++ floor1_flag[low_neigh_offs] = 1; ++ floor1_flag[high_neigh_offs] = 1; ++ floor1_flag[i] = 1; ++ if (val >= room) { ++ if (highroom > lowroom) { ++ floor1_Y_final[i] = av_clip_uint16(val - lowroom + predicted); ++ } else { ++ floor1_Y_final[i] = av_clip_uint16(predicted - val + highroom - 1); ++ } ++ } else { ++ if (val & 1) { ++ floor1_Y_final[i] = av_clip_uint16(predicted - (val + 1) / 2); ++ } else { ++ floor1_Y_final[i] = av_clip_uint16(predicted + val / 2); ++ } ++ } ++ } else { ++ floor1_flag[i] = 0; ++ floor1_Y_final[i] = av_clip_uint16(predicted); ++ } ++ ++ av_dlog(NULL, " Decoded floor(%d) = %u / val %u\n", ++ vf->list[i].x, floor1_Y_final[i], val); ++ } ++ ++// Curve synth - connect the calculated dots and convert from dB scale FIXME optimize ? ++ ++ ff_vorbis_floor1_render_list(vf->list, vf->x_list_dim, floor1_Y_final, floor1_flag, vf->multiplier, vec, vf->list[1].x); ++ ++ av_dlog(NULL, " Floor decoded\n"); ++ ++ return 0; ++} ++ ++// Read and decode residue ++ ++static av_always_inline int vorbis_residue_decode_internal(vorbis_context *vc, ++ vorbis_residue *vr, ++ unsigned ch, ++ uint8_t *do_not_decode, ++ float *vec, ++ unsigned vlen, ++ unsigned ch_left, ++ int vr_type) ++{ ++ GetBitContext *gb = &vc->gb; ++ unsigned c_p_c = vc->codebooks[vr->classbook].dimensions; ++ unsigned ptns_to_read = vr->ptns_to_read; ++ uint8_t *classifs = vr->classifs; ++ unsigned pass, ch_used, i, j, k, l; ++ unsigned max_output = (ch - 1) * vlen; ++ ++ if (vr_type == 2) { ++ for (j = 1; j < ch; ++j) ++ do_not_decode[0] &= do_not_decode[j]; // FIXME - clobbering input ++ if (do_not_decode[0]) ++ return 0; ++ ch_used = 1; ++ max_output += vr->end / ch; ++ } else { ++ ch_used = ch; ++ max_output += vr->end; ++ } ++ ++ if (max_output > ch_left * vlen) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Insufficient output buffer\n"); ++ return -1; ++ } ++ ++ av_dlog(NULL, " residue type 0/1/2 decode begin, ch: %d cpc %d \n", ch, c_p_c); ++ ++ for (pass = 0; pass <= vr->maxpass; ++pass) { // FIXME OPTIMIZE? ++ uint16_t voffset, partition_count, j_times_ptns_to_read; ++ ++ voffset = vr->begin; ++ for (partition_count = 0; partition_count < ptns_to_read;) { // SPEC error ++ if (!pass) { ++ unsigned inverse_class = ff_inverse[vr->classifications]; ++ for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { ++ if (!do_not_decode[j]) { ++ unsigned temp = get_vlc2(gb, vc->codebooks[vr->classbook].vlc.table, ++ vc->codebooks[vr->classbook].nb_bits, 3); ++ ++ av_dlog(NULL, "Classword: %u\n", temp); ++ ++ assert(vr->classifications > 1 && temp <= 65536); //needed for inverse[] ++ for (i = 0; i < c_p_c; ++i) { ++ unsigned temp2; ++ ++ temp2 = (((uint64_t)temp) * inverse_class) >> 32; ++ if (partition_count + c_p_c - 1 - i < ptns_to_read) ++ classifs[j_times_ptns_to_read + partition_count + c_p_c - 1 - i] = temp - temp2 * vr->classifications; ++ temp = temp2; ++ } ++ } ++ j_times_ptns_to_read += ptns_to_read; ++ } ++ } ++ for (i = 0; (i < c_p_c) && (partition_count < ptns_to_read); ++i) { ++ for (j_times_ptns_to_read = 0, j = 0; j < ch_used; ++j) { ++ unsigned voffs; ++ ++ if (!do_not_decode[j]) { ++ unsigned vqclass = classifs[j_times_ptns_to_read + partition_count]; ++ int vqbook = vr->books[vqclass][pass]; ++ ++ if (vqbook >= 0 && vc->codebooks[vqbook].codevectors) { ++ unsigned coffs; ++ unsigned dim = vc->codebooks[vqbook].dimensions; ++ unsigned step = dim == 1 ? vr->partition_size ++ : FASTDIV(vr->partition_size, dim); ++ vorbis_codebook codebook = vc->codebooks[vqbook]; ++ ++ if (vr_type == 0) { ++ ++ voffs = voffset+j*vlen; ++ for (k = 0; k < step; ++k) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; ++ for (l = 0; l < dim; ++l) ++ vec[voffs + k + l * step] += codebook.codevectors[coffs + l]; // FPMATH ++ } ++ } else if (vr_type == 1) { ++ voffs = voffset + j * vlen; ++ for (k = 0; k < step; ++k) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; ++ for (l = 0; l < dim; ++l, ++voffs) { ++ vec[voffs]+=codebook.codevectors[coffs+l]; // FPMATH ++ ++ av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d \n", ++ pass, voffs, vec[voffs], codebook.codevectors[coffs+l], coffs); ++ } ++ } ++ } else if (vr_type == 2 && ch == 2 && (voffset & 1) == 0 && (dim & 1) == 0) { // most frequent case optimized ++ voffs = voffset >> 1; ++ ++ if (dim == 2) { ++ for (k = 0; k < step; ++k) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 2; ++ vec[voffs + k ] += codebook.codevectors[coffs ]; // FPMATH ++ vec[voffs + k + vlen] += codebook.codevectors[coffs + 1]; // FPMATH ++ } ++ } else if (dim == 4) { ++ for (k = 0; k < step; ++k, voffs += 2) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * 4; ++ vec[voffs ] += codebook.codevectors[coffs ]; // FPMATH ++ vec[voffs + 1 ] += codebook.codevectors[coffs + 2]; // FPMATH ++ vec[voffs + vlen ] += codebook.codevectors[coffs + 1]; // FPMATH ++ vec[voffs + vlen + 1] += codebook.codevectors[coffs + 3]; // FPMATH ++ } ++ } else ++ for (k = 0; k < step; ++k) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; ++ for (l = 0; l < dim; l += 2, voffs++) { ++ vec[voffs ] += codebook.codevectors[coffs + l ]; // FPMATH ++ vec[voffs + vlen] += codebook.codevectors[coffs + l + 1]; // FPMATH ++ ++ av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", ++ pass, voffset / ch + (voffs % ch) * vlen, ++ vec[voffset / ch + (voffs % ch) * vlen], ++ codebook.codevectors[coffs + l], coffs, l); ++ } ++ } ++ ++ } else if (vr_type == 2) { ++ voffs = voffset; ++ ++ for (k = 0; k < step; ++k) { ++ coffs = get_vlc2(gb, codebook.vlc.table, codebook.nb_bits, 3) * dim; ++ for (l = 0; l < dim; ++l, ++voffs) { ++ vec[voffs / ch + (voffs % ch) * vlen] += codebook.codevectors[coffs + l]; // FPMATH FIXME use if and counter instead of / and % ++ ++ av_dlog(NULL, " pass %d offs: %d curr: %f change: %f cv offs.: %d+%d \n", ++ pass, voffset / ch + (voffs % ch) * vlen, ++ vec[voffset / ch + (voffs % ch) * vlen], ++ codebook.codevectors[coffs + l], coffs, l); ++ } ++ } ++ } ++ } ++ } ++ j_times_ptns_to_read += ptns_to_read; ++ } ++ ++partition_count; ++ voffset += vr->partition_size; ++ } ++ } ++ } ++ return 0; ++} ++ ++static inline int vorbis_residue_decode(vorbis_context *vc, vorbis_residue *vr, ++ unsigned ch, ++ uint8_t *do_not_decode, ++ float *vec, unsigned vlen, ++ unsigned ch_left) ++{ ++ if (vr->type == 2) ++ return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 2); ++ else if (vr->type == 1) ++ return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 1); ++ else if (vr->type == 0) ++ return vorbis_residue_decode_internal(vc, vr, ch, do_not_decode, vec, vlen, ch_left, 0); ++ else { ++ av_log(vc->avccontext, AV_LOG_ERROR, " Invalid residue type while residue decode?! \n"); ++ return AVERROR_INVALIDDATA; ++ } ++} ++ ++void vorbis_inverse_coupling(float *mag, float *ang, int blocksize) ++{ ++ int i; ++ for (i = 0; i < blocksize; i++) { ++ if (mag[i] > 0.0) { ++ if (ang[i] > 0.0) { ++ ang[i] = mag[i] - ang[i]; ++ } else { ++ float temp = ang[i]; ++ ang[i] = mag[i]; ++ mag[i] += temp; ++ } ++ } else { ++ if (ang[i] > 0.0) { ++ ang[i] += mag[i]; ++ } else { ++ float temp = ang[i]; ++ ang[i] = mag[i]; ++ mag[i] -= temp; ++ } ++ } ++ } ++} ++ ++// Decode the audio packet using the functions above ++ ++static int vorbis_parse_audio_packet(vorbis_context *vc) ++{ ++ GetBitContext *gb = &vc->gb; ++ FFTContext *mdct; ++ unsigned previous_window = vc->previous_window; ++ unsigned mode_number, blockflag, blocksize; ++ int i, j; ++ uint8_t no_residue[255]; ++ uint8_t do_not_decode[255]; ++ vorbis_mapping *mapping; ++ float *ch_res_ptr = vc->channel_residues; ++ float *ch_floor_ptr = vc->channel_floors; ++ uint8_t res_chan[255]; ++ unsigned res_num = 0; ++ int retlen = 0; ++ unsigned ch_left = vc->audio_channels; ++ unsigned vlen; ++ ++ if (get_bits1(gb)) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Not a Vorbis I audio packet.\n"); ++ return AVERROR_INVALIDDATA; // packet type not audio ++ } ++ ++ if (vc->mode_count == 1) { ++ mode_number = 0; ++ } else { ++ GET_VALIDATED_INDEX(mode_number, ilog(vc->mode_count-1), vc->mode_count) ++ } ++ vc->mode_number = mode_number; ++ mapping = &vc->mappings[vc->modes[mode_number].mapping]; ++ ++ av_dlog(NULL, " Mode number: %u , mapping: %d , blocktype %d\n", mode_number, ++ vc->modes[mode_number].mapping, vc->modes[mode_number].blockflag); ++ ++ blockflag = vc->modes[mode_number].blockflag; ++ blocksize = vc->blocksize[blockflag]; ++ vlen = blocksize / 2; ++ if (blockflag) ++ skip_bits(gb, 2); // previous_window, next_window ++ ++ memset(ch_res_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ? ++ memset(ch_floor_ptr, 0, sizeof(float) * vc->audio_channels * vlen); //FIXME can this be removed ? ++ ++// Decode floor ++ ++ for (i = 0; i < vc->audio_channels; ++i) { ++ vorbis_floor *floor; ++ int ret; ++ if (mapping->submaps > 1) { ++ floor = &vc->floors[mapping->submap_floor[mapping->mux[i]]]; ++ } else { ++ floor = &vc->floors[mapping->submap_floor[0]]; ++ } ++ ++ ret = floor->decode(vc, &floor->data, ch_floor_ptr); ++ ++ if (ret < 0) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Invalid codebook in vorbis_floor_decode.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ no_residue[i] = ret; ++ ch_floor_ptr += vlen; ++ } ++ ++// Nonzero vector propagate ++ ++ for (i = mapping->coupling_steps - 1; i >= 0; --i) { ++ if (!(no_residue[mapping->magnitude[i]] & no_residue[mapping->angle[i]])) { ++ no_residue[mapping->magnitude[i]] = 0; ++ no_residue[mapping->angle[i]] = 0; ++ } ++ } ++ ++// Decode residue ++ ++ for (i = 0; i < mapping->submaps; ++i) { ++ vorbis_residue *residue; ++ unsigned ch = 0; ++ int ret; ++ ++ for (j = 0; j < vc->audio_channels; ++j) { ++ if ((mapping->submaps == 1) || (i == mapping->mux[j])) { ++ res_chan[j] = res_num; ++ if (no_residue[j]) { ++ do_not_decode[ch] = 1; ++ } else { ++ do_not_decode[ch] = 0; ++ } ++ ++ch; ++ ++res_num; ++ } ++ } ++ residue = &vc->residues[mapping->submap_residue[i]]; ++ if (ch_left < ch) { ++ av_log(vc->avccontext, AV_LOG_ERROR, "Too many channels in vorbis_floor_decode.\n"); ++ return -1; ++ } ++ if (ch) { ++ ret = vorbis_residue_decode(vc, residue, ch, do_not_decode, ch_res_ptr, vlen, ch_left); ++ if (ret < 0) ++ return ret; ++ } ++ ++ ch_res_ptr += ch * vlen; ++ ch_left -= ch; ++ } ++ ++// Inverse coupling ++ ++ for (i = mapping->coupling_steps - 1; i >= 0; --i) { //warning: i has to be signed ++ float *mag, *ang; ++ ++ mag = vc->channel_residues+res_chan[mapping->magnitude[i]] * blocksize / 2; ++ ang = vc->channel_residues+res_chan[mapping->angle[i]] * blocksize / 2; ++ vc->dsp.vorbis_inverse_coupling(mag, ang, blocksize / 2); ++ } ++ ++// Dotproduct, MDCT ++ ++ mdct = &vc->mdct[blockflag]; ++ ++ for (j = vc->audio_channels-1;j >= 0; j--) { ++ ch_floor_ptr = vc->channel_floors + j * blocksize / 2; ++ ch_res_ptr = vc->channel_residues + res_chan[j] * blocksize / 2; ++ vc->dsp.vector_fmul(ch_floor_ptr, ch_floor_ptr, ch_res_ptr, blocksize / 2); ++ mdct->imdct_half(mdct, ch_res_ptr, ch_floor_ptr); ++ } ++ ++// Overlap/add, save data for next overlapping FPMATH ++ ++ retlen = (blocksize + vc->blocksize[previous_window]) / 4; ++ for (j = 0; j < vc->audio_channels; j++) { ++ unsigned bs0 = vc->blocksize[0]; ++ unsigned bs1 = vc->blocksize[1]; ++ float *residue = vc->channel_residues + res_chan[j] * blocksize / 2; ++ float *saved = vc->saved + j * bs1 / 4; ++ float *ret = vc->channel_floors + j * retlen; ++ float *buf = residue; ++ const float *win = vc->win[blockflag & previous_window]; ++ ++ if (blockflag == previous_window) { ++ vc->dsp.vector_fmul_window(ret, saved, buf, win, blocksize / 4); ++ } else if (blockflag > previous_window) { ++ vc->dsp.vector_fmul_window(ret, saved, buf, win, bs0 / 4); ++ memcpy(ret+bs0/2, buf+bs0/4, ((bs1-bs0)/4) * sizeof(float)); ++ } else { ++ memcpy(ret, saved, ((bs1 - bs0) / 4) * sizeof(float)); ++ vc->dsp.vector_fmul_window(ret + (bs1 - bs0) / 4, saved + (bs1 - bs0) / 4, buf, win, bs0 / 4); ++ } ++ memcpy(saved, buf + blocksize / 4, blocksize / 4 * sizeof(float)); ++ } ++ ++ vc->previous_window = blockflag; ++ return retlen; ++} ++ ++// Return the decoded audio packet through the standard api ++ ++static int vorbis_decode_frame(AVCodecContext *avccontext, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ const uint8_t *buf = avpkt->data; ++ int buf_size = avpkt->size; ++ vorbis_context *vc = avccontext->priv_data; ++ GetBitContext *gb = &vc->gb; ++ const float *channel_ptrs[255]; ++ int i, len, ret; ++ ++ av_dlog(NULL, "packet length %d \n", buf_size); ++ ++ init_get_bits(gb, buf, buf_size*8); ++ ++ if ((len = vorbis_parse_audio_packet(vc)) <= 0) ++ return len; ++ ++ if (!vc->first_frame) { ++ vc->first_frame = 1; ++ *got_frame_ptr = 0; ++ return buf_size; ++ } ++ ++ av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n", ++ get_bits_count(gb) / 8, get_bits_count(gb) % 8, len); ++ ++ /* get output buffer */ ++ vc->frame.nb_samples = len; ++ if ((ret = avccontext->get_buffer(avccontext, &vc->frame)) < 0) { ++ av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ if (vc->audio_channels > 8) { ++ for (i = 0; i < vc->audio_channels; i++) ++ channel_ptrs[i] = vc->channel_floors + i * len; ++ } else { ++ for (i = 0; i < vc->audio_channels; i++) ++ channel_ptrs[i] = vc->channel_floors + ++ len * ff_vorbis_channel_layout_offsets[vc->audio_channels - 1][i]; ++ } ++ ++ if (avccontext->sample_fmt == AV_SAMPLE_FMT_FLT) ++ vc->fmt_conv.float_interleave((float *)vc->frame.data[0], channel_ptrs, ++ len, vc->audio_channels); ++ else ++ vc->fmt_conv.float_to_int16_interleave((int16_t *)vc->frame.data[0], ++ channel_ptrs, len, ++ vc->audio_channels); ++ ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = vc->frame; ++ ++ return buf_size; ++} ++ ++// Close decoder ++ ++static av_cold int vorbis_decode_close(AVCodecContext *avccontext) ++{ ++ vorbis_context *vc = avccontext->priv_data; ++ ++ vorbis_free(vc); ++ ++ return 0; ++} ++ ++AVCodec ff_vorbis_decoder = { ++ .name = "vorbis", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_VORBIS, ++ .priv_data_size = sizeof(vorbis_context), ++ .init = vorbis_decode_init, ++ .close = vorbis_decode_close, ++ .decode = vorbis_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), ++ .channel_layouts = ff_vorbis_channel_layouts, ++ .sample_fmts = (const enum AVSampleFormat[]) { ++ AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE ++ }, ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_enc.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,1116 +0,0 @@ +-/* +- * copyright (c) 2006 Oded Shimon +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * Native Vorbis encoder. +- * @author Oded Shimon +- */ +- +-#include +-#include "avcodec.h" +-#include "dsputil.h" +-#include "fft.h" +-#include "vorbis.h" +-#include "vorbis_enc_data.h" +- +-#define BITSTREAM_WRITER_LE +-#include "put_bits.h" +- +-#undef NDEBUG +-#include +- +-typedef struct { +- int nentries; +- uint8_t *lens; +- uint32_t *codewords; +- int ndimentions; +- float min; +- float delta; +- int seq_p; +- int lookup; +- int *quantlist; +- float *dimentions; +- float *pow2; +-} vorbis_enc_codebook; +- +-typedef struct { +- int dim; +- int subclass; +- int masterbook; +- int *books; +-} vorbis_enc_floor_class; +- +-typedef struct { +- int partitions; +- int *partition_to_class; +- int nclasses; +- vorbis_enc_floor_class *classes; +- int multiplier; +- int rangebits; +- int values; +- vorbis_floor1_entry *list; +-} vorbis_enc_floor; +- +-typedef struct { +- int type; +- int begin; +- int end; +- int partition_size; +- int classifications; +- int classbook; +- int8_t (*books)[8]; +- float (*maxes)[2]; +-} vorbis_enc_residue; +- +-typedef struct { +- int submaps; +- int *mux; +- int *floor; +- int *residue; +- int coupling_steps; +- int *magnitude; +- int *angle; +-} vorbis_enc_mapping; +- +-typedef struct { +- int blockflag; +- int mapping; +-} vorbis_enc_mode; +- +-typedef struct { +- int channels; +- int sample_rate; +- int log2_blocksize[2]; +- FFTContext mdct[2]; +- const float *win[2]; +- int have_saved; +- float *saved; +- float *samples; +- float *floor; // also used for tmp values for mdct +- float *coeffs; // also used for residue after floor +- float quality; +- +- int ncodebooks; +- vorbis_enc_codebook *codebooks; +- +- int nfloors; +- vorbis_enc_floor *floors; +- +- int nresidues; +- vorbis_enc_residue *residues; +- +- int nmappings; +- vorbis_enc_mapping *mappings; +- +- int nmodes; +- vorbis_enc_mode *modes; +- +- int64_t sample_count; +-} vorbis_enc_context; +- +-#define MAX_CHANNELS 2 +-#define MAX_CODEBOOK_DIM 8 +- +-#define MAX_FLOOR_CLASS_DIM 4 +-#define NUM_FLOOR_PARTITIONS 8 +-#define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2) +- +-#define RESIDUE_SIZE 1600 +-#define RESIDUE_PART_SIZE 32 +-#define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE) +- +-static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb, +- int entry) +-{ +- assert(entry >= 0); +- assert(entry < cb->nentries); +- assert(cb->lens[entry]); +- put_bits(pb, cb->lens[entry], cb->codewords[entry]); +-} +- +-static int cb_lookup_vals(int lookup, int dimentions, int entries) +-{ +- if (lookup == 1) +- return ff_vorbis_nth_root(entries, dimentions); +- else if (lookup == 2) +- return dimentions *entries; +- return 0; +-} +- +-static void ready_codebook(vorbis_enc_codebook *cb) +-{ +- int i; +- +- ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); +- +- if (!cb->lookup) { +- cb->pow2 = cb->dimentions = NULL; +- } else { +- int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); +- cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); +- cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); +- for (i = 0; i < cb->nentries; i++) { +- float last = 0; +- int j; +- int div = 1; +- for (j = 0; j < cb->ndimentions; j++) { +- int off; +- if (cb->lookup == 1) +- off = (i / div) % vals; // lookup type 1 +- else +- off = i * cb->ndimentions + j; // lookup type 2 +- +- cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta; +- if (cb->seq_p) +- last = cb->dimentions[i * cb->ndimentions + j]; +- cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j]; +- div *= vals; +- } +- cb->pow2[i] /= 2.; +- } +- } +-} +- +-static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) +-{ +- int i; +- assert(rc->type == 2); +- rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); +- for (i = 0; i < rc->classifications; i++) { +- int j; +- vorbis_enc_codebook * cb; +- for (j = 0; j < 8; j++) +- if (rc->books[i][j] != -1) +- break; +- if (j == 8) // zero +- continue; +- cb = &venc->codebooks[rc->books[i][j]]; +- assert(cb->ndimentions >= 2); +- assert(cb->lookup); +- +- for (j = 0; j < cb->nentries; j++) { +- float a; +- if (!cb->lens[j]) +- continue; +- a = fabs(cb->dimentions[j * cb->ndimentions]); +- if (a > rc->maxes[i][0]) +- rc->maxes[i][0] = a; +- a = fabs(cb->dimentions[j * cb->ndimentions + 1]); +- if (a > rc->maxes[i][1]) +- rc->maxes[i][1] = a; +- } +- } +- // small bias +- for (i = 0; i < rc->classifications; i++) { +- rc->maxes[i][0] += 0.8; +- rc->maxes[i][1] += 0.8; +- } +-} +- +-static void create_vorbis_context(vorbis_enc_context *venc, +- AVCodecContext *avccontext) +-{ +- vorbis_enc_floor *fc; +- vorbis_enc_residue *rc; +- vorbis_enc_mapping *mc; +- int i, book; +- +- venc->channels = avccontext->channels; +- venc->sample_rate = avccontext->sample_rate; +- venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; +- +- venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); +- venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); +- +- // codebook 0..14 - floor1 book, values 0..255 +- // codebook 15 residue masterbook +- // codebook 16..29 residue +- for (book = 0; book < venc->ncodebooks; book++) { +- vorbis_enc_codebook *cb = &venc->codebooks[book]; +- int vals; +- cb->ndimentions = cvectors[book].dim; +- cb->nentries = cvectors[book].real_len; +- cb->min = cvectors[book].min; +- cb->delta = cvectors[book].delta; +- cb->lookup = cvectors[book].lookup; +- cb->seq_p = 0; +- +- cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); +- cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); +- memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); +- memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); +- +- if (cb->lookup) { +- vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); +- cb->quantlist = av_malloc(sizeof(int) * vals); +- for (i = 0; i < vals; i++) +- cb->quantlist[i] = cvectors[book].quant[i]; +- } else { +- cb->quantlist = NULL; +- } +- ready_codebook(cb); +- } +- +- venc->nfloors = 1; +- venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); +- +- // just 1 floor +- fc = &venc->floors[0]; +- fc->partitions = NUM_FLOOR_PARTITIONS; +- fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); +- fc->nclasses = 0; +- for (i = 0; i < fc->partitions; i++) { +- static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; +- fc->partition_to_class[i] = a[i]; +- fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]); +- } +- fc->nclasses++; +- fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); +- for (i = 0; i < fc->nclasses; i++) { +- vorbis_enc_floor_class * c = &fc->classes[i]; +- int j, books; +- c->dim = floor_classes[i].dim; +- c->subclass = floor_classes[i].subclass; +- c->masterbook = floor_classes[i].masterbook; +- books = (1 << c->subclass); +- c->books = av_malloc(sizeof(int) * books); +- for (j = 0; j < books; j++) +- c->books[j] = floor_classes[i].nbooks[j]; +- } +- fc->multiplier = 2; +- fc->rangebits = venc->log2_blocksize[0] - 1; +- +- fc->values = 2; +- for (i = 0; i < fc->partitions; i++) +- fc->values += fc->classes[fc->partition_to_class[i]].dim; +- +- fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); +- fc->list[0].x = 0; +- fc->list[1].x = 1 << fc->rangebits; +- for (i = 2; i < fc->values; i++) { +- static const int a[] = { +- 93, 23,372, 6, 46,186,750, 14, 33, 65, +- 130,260,556, 3, 10, 18, 28, 39, 55, 79, +- 111,158,220,312,464,650,850 +- }; +- fc->list[i].x = a[i - 2]; +- } +- ff_vorbis_ready_floor1_list(fc->list, fc->values); +- +- venc->nresidues = 1; +- venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); +- +- // single residue +- rc = &venc->residues[0]; +- rc->type = 2; +- rc->begin = 0; +- rc->end = 1600; +- rc->partition_size = 32; +- rc->classifications = 10; +- rc->classbook = 15; +- rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); +- { +- static const int8_t a[10][8] = { +- { -1, -1, -1, -1, -1, -1, -1, -1, }, +- { -1, -1, 16, -1, -1, -1, -1, -1, }, +- { -1, -1, 17, -1, -1, -1, -1, -1, }, +- { -1, -1, 18, -1, -1, -1, -1, -1, }, +- { -1, -1, 19, -1, -1, -1, -1, -1, }, +- { -1, -1, 20, -1, -1, -1, -1, -1, }, +- { -1, -1, 21, -1, -1, -1, -1, -1, }, +- { 22, 23, -1, -1, -1, -1, -1, -1, }, +- { 24, 25, -1, -1, -1, -1, -1, -1, }, +- { 26, 27, 28, -1, -1, -1, -1, -1, }, +- }; +- memcpy(rc->books, a, sizeof a); +- } +- ready_residue(rc, venc); +- +- venc->nmappings = 1; +- venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); +- +- // single mapping +- mc = &venc->mappings[0]; +- mc->submaps = 1; +- mc->mux = av_malloc(sizeof(int) * venc->channels); +- for (i = 0; i < venc->channels; i++) +- mc->mux[i] = 0; +- mc->floor = av_malloc(sizeof(int) * mc->submaps); +- mc->residue = av_malloc(sizeof(int) * mc->submaps); +- for (i = 0; i < mc->submaps; i++) { +- mc->floor[i] = 0; +- mc->residue[i] = 0; +- } +- mc->coupling_steps = venc->channels == 2 ? 1 : 0; +- mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); +- mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); +- if (mc->coupling_steps) { +- mc->magnitude[0] = 0; +- mc->angle[0] = 1; +- } +- +- venc->nmodes = 1; +- venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); +- +- // single mode +- venc->modes[0].blockflag = 0; +- venc->modes[0].mapping = 0; +- +- venc->have_saved = 0; +- venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); +- venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); +- venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); +- venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); +- +- venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; +- venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; +- +- ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0); +- ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0); +-} +- +-static void put_float(PutBitContext *pb, float f) +-{ +- int exp, mant; +- uint32_t res = 0; +- mant = (int)ldexp(frexp(f, &exp), 20); +- exp += 788 - 20; +- if (mant < 0) { +- res |= (1 << 31); +- mant = -mant; +- } +- res |= mant | (exp << 21); +- put_bits32(pb, res); +-} +- +-static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb) +-{ +- int i; +- int ordered = 0; +- +- put_bits(pb, 24, 0x564342); //magic +- put_bits(pb, 16, cb->ndimentions); +- put_bits(pb, 24, cb->nentries); +- +- for (i = 1; i < cb->nentries; i++) +- if (cb->lens[i] < cb->lens[i-1]) +- break; +- if (i == cb->nentries) +- ordered = 1; +- +- put_bits(pb, 1, ordered); +- if (ordered) { +- int len = cb->lens[0]; +- put_bits(pb, 5, len - 1); +- i = 0; +- while (i < cb->nentries) { +- int j; +- for (j = 0; j+i < cb->nentries; j++) +- if (cb->lens[j+i] != len) +- break; +- put_bits(pb, ilog(cb->nentries - i), j); +- i += j; +- len++; +- } +- } else { +- int sparse = 0; +- for (i = 0; i < cb->nentries; i++) +- if (!cb->lens[i]) +- break; +- if (i != cb->nentries) +- sparse = 1; +- put_bits(pb, 1, sparse); +- +- for (i = 0; i < cb->nentries; i++) { +- if (sparse) +- put_bits(pb, 1, !!cb->lens[i]); +- if (cb->lens[i]) +- put_bits(pb, 5, cb->lens[i] - 1); +- } +- } +- +- put_bits(pb, 4, cb->lookup); +- if (cb->lookup) { +- int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); +- int bits = ilog(cb->quantlist[0]); +- +- for (i = 1; i < tmp; i++) +- bits = FFMAX(bits, ilog(cb->quantlist[i])); +- +- put_float(pb, cb->min); +- put_float(pb, cb->delta); +- +- put_bits(pb, 4, bits - 1); +- put_bits(pb, 1, cb->seq_p); +- +- for (i = 0; i < tmp; i++) +- put_bits(pb, bits, cb->quantlist[i]); +- } +-} +- +-static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc) +-{ +- int i; +- +- put_bits(pb, 16, 1); // type, only floor1 is supported +- +- put_bits(pb, 5, fc->partitions); +- +- for (i = 0; i < fc->partitions; i++) +- put_bits(pb, 4, fc->partition_to_class[i]); +- +- for (i = 0; i < fc->nclasses; i++) { +- int j, books; +- +- put_bits(pb, 3, fc->classes[i].dim - 1); +- put_bits(pb, 2, fc->classes[i].subclass); +- +- if (fc->classes[i].subclass) +- put_bits(pb, 8, fc->classes[i].masterbook); +- +- books = (1 << fc->classes[i].subclass); +- +- for (j = 0; j < books; j++) +- put_bits(pb, 8, fc->classes[i].books[j] + 1); +- } +- +- put_bits(pb, 2, fc->multiplier - 1); +- put_bits(pb, 4, fc->rangebits); +- +- for (i = 2; i < fc->values; i++) +- put_bits(pb, fc->rangebits, fc->list[i].x); +-} +- +-static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc) +-{ +- int i; +- +- put_bits(pb, 16, rc->type); +- +- put_bits(pb, 24, rc->begin); +- put_bits(pb, 24, rc->end); +- put_bits(pb, 24, rc->partition_size - 1); +- put_bits(pb, 6, rc->classifications - 1); +- put_bits(pb, 8, rc->classbook); +- +- for (i = 0; i < rc->classifications; i++) { +- int j, tmp = 0; +- for (j = 0; j < 8; j++) +- tmp |= (rc->books[i][j] != -1) << j; +- +- put_bits(pb, 3, tmp & 7); +- put_bits(pb, 1, tmp > 7); +- +- if (tmp > 7) +- put_bits(pb, 5, tmp >> 3); +- } +- +- for (i = 0; i < rc->classifications; i++) { +- int j; +- for (j = 0; j < 8; j++) +- if (rc->books[i][j] != -1) +- put_bits(pb, 8, rc->books[i][j]); +- } +-} +- +-static int put_main_header(vorbis_enc_context *venc, uint8_t **out) +-{ +- int i; +- PutBitContext pb; +- uint8_t buffer[50000] = {0}, *p = buffer; +- int buffer_len = sizeof buffer; +- int len, hlens[3]; +- +- // identification header +- init_put_bits(&pb, p, buffer_len); +- put_bits(&pb, 8, 1); //magic +- for (i = 0; "vorbis"[i]; i++) +- put_bits(&pb, 8, "vorbis"[i]); +- put_bits32(&pb, 0); // version +- put_bits(&pb, 8, venc->channels); +- put_bits32(&pb, venc->sample_rate); +- put_bits32(&pb, 0); // bitrate +- put_bits32(&pb, 0); // bitrate +- put_bits32(&pb, 0); // bitrate +- put_bits(&pb, 4, venc->log2_blocksize[0]); +- put_bits(&pb, 4, venc->log2_blocksize[1]); +- put_bits(&pb, 1, 1); // framing +- +- flush_put_bits(&pb); +- hlens[0] = put_bits_count(&pb) >> 3; +- buffer_len -= hlens[0]; +- p += hlens[0]; +- +- // comment header +- init_put_bits(&pb, p, buffer_len); +- put_bits(&pb, 8, 3); //magic +- for (i = 0; "vorbis"[i]; i++) +- put_bits(&pb, 8, "vorbis"[i]); +- put_bits32(&pb, 0); // vendor length TODO +- put_bits32(&pb, 0); // amount of comments +- put_bits(&pb, 1, 1); // framing +- +- flush_put_bits(&pb); +- hlens[1] = put_bits_count(&pb) >> 3; +- buffer_len -= hlens[1]; +- p += hlens[1]; +- +- // setup header +- init_put_bits(&pb, p, buffer_len); +- put_bits(&pb, 8, 5); //magic +- for (i = 0; "vorbis"[i]; i++) +- put_bits(&pb, 8, "vorbis"[i]); +- +- // codebooks +- put_bits(&pb, 8, venc->ncodebooks - 1); +- for (i = 0; i < venc->ncodebooks; i++) +- put_codebook_header(&pb, &venc->codebooks[i]); +- +- // time domain, reserved, zero +- put_bits(&pb, 6, 0); +- put_bits(&pb, 16, 0); +- +- // floors +- put_bits(&pb, 6, venc->nfloors - 1); +- for (i = 0; i < venc->nfloors; i++) +- put_floor_header(&pb, &venc->floors[i]); +- +- // residues +- put_bits(&pb, 6, venc->nresidues - 1); +- for (i = 0; i < venc->nresidues; i++) +- put_residue_header(&pb, &venc->residues[i]); +- +- // mappings +- put_bits(&pb, 6, venc->nmappings - 1); +- for (i = 0; i < venc->nmappings; i++) { +- vorbis_enc_mapping *mc = &venc->mappings[i]; +- int j; +- put_bits(&pb, 16, 0); // mapping type +- +- put_bits(&pb, 1, mc->submaps > 1); +- if (mc->submaps > 1) +- put_bits(&pb, 4, mc->submaps - 1); +- +- put_bits(&pb, 1, !!mc->coupling_steps); +- if (mc->coupling_steps) { +- put_bits(&pb, 8, mc->coupling_steps - 1); +- for (j = 0; j < mc->coupling_steps; j++) { +- put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]); +- put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]); +- } +- } +- +- put_bits(&pb, 2, 0); // reserved +- +- if (mc->submaps > 1) +- for (j = 0; j < venc->channels; j++) +- put_bits(&pb, 4, mc->mux[j]); +- +- for (j = 0; j < mc->submaps; j++) { +- put_bits(&pb, 8, 0); // reserved time configuration +- put_bits(&pb, 8, mc->floor[j]); +- put_bits(&pb, 8, mc->residue[j]); +- } +- } +- +- // modes +- put_bits(&pb, 6, venc->nmodes - 1); +- for (i = 0; i < venc->nmodes; i++) { +- put_bits(&pb, 1, venc->modes[i].blockflag); +- put_bits(&pb, 16, 0); // reserved window type +- put_bits(&pb, 16, 0); // reserved transform type +- put_bits(&pb, 8, venc->modes[i].mapping); +- } +- +- put_bits(&pb, 1, 1); // framing +- +- flush_put_bits(&pb); +- hlens[2] = put_bits_count(&pb) >> 3; +- +- len = hlens[0] + hlens[1] + hlens[2]; +- p = *out = av_mallocz(64 + len + len/255); +- +- *p++ = 2; +- p += av_xiphlacing(p, hlens[0]); +- p += av_xiphlacing(p, hlens[1]); +- buffer_len = 0; +- for (i = 0; i < 3; i++) { +- memcpy(p, buffer + buffer_len, hlens[i]); +- p += hlens[i]; +- buffer_len += hlens[i]; +- } +- +- return p - *out; +-} +- +-static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i) +-{ +- int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; +- int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; +- int j; +- float average = 0; +- +- for (j = begin; j < end; j++) +- average += fabs(coeffs[j]); +- return average / (end - begin); +-} +- +-static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc, +- float *coeffs, uint_fast16_t *posts, int samples) +-{ +- int range = 255 / fc->multiplier + 1; +- int i; +- float tot_average = 0.; +- float averages[MAX_FLOOR_VALUES]; +- for (i = 0; i < fc->values; i++) { +- averages[i] = get_floor_average(fc, coeffs, i); +- tot_average += averages[i]; +- } +- tot_average /= fc->values; +- tot_average /= venc->quality; +- +- for (i = 0; i < fc->values; i++) { +- int position = fc->list[fc->list[i].sort].x; +- float average = averages[i]; +- int j; +- +- average = sqrt(tot_average * average) * pow(1.25f, position*0.005f); // MAGIC! +- for (j = 0; j < range - 1; j++) +- if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) +- break; +- posts[fc->list[i].sort] = j; +- } +-} +- +-static int render_point(int x0, int y0, int x1, int y1, int x) +-{ +- return y0 + (x - x0) * (y1 - y0) / (x1 - x0); +-} +- +-static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc, +- PutBitContext *pb, uint_fast16_t *posts, +- float *floor, int samples) +-{ +- int range = 255 / fc->multiplier + 1; +- int coded[MAX_FLOOR_VALUES]; // first 2 values are unused +- int i, counter; +- +- put_bits(pb, 1, 1); // non zero +- put_bits(pb, ilog(range - 1), posts[0]); +- put_bits(pb, ilog(range - 1), posts[1]); +- coded[0] = coded[1] = 1; +- +- for (i = 2; i < fc->values; i++) { +- int predicted = render_point(fc->list[fc->list[i].low].x, +- posts[fc->list[i].low], +- fc->list[fc->list[i].high].x, +- posts[fc->list[i].high], +- fc->list[i].x); +- int highroom = range - predicted; +- int lowroom = predicted; +- int room = FFMIN(highroom, lowroom); +- if (predicted == posts[i]) { +- coded[i] = 0; // must be used later as flag! +- continue; +- } else { +- if (!coded[fc->list[i].low ]) +- coded[fc->list[i].low ] = -1; +- if (!coded[fc->list[i].high]) +- coded[fc->list[i].high] = -1; +- } +- if (posts[i] > predicted) { +- if (posts[i] - predicted > room) +- coded[i] = posts[i] - predicted + lowroom; +- else +- coded[i] = (posts[i] - predicted) << 1; +- } else { +- if (predicted - posts[i] > room) +- coded[i] = predicted - posts[i] + highroom - 1; +- else +- coded[i] = ((predicted - posts[i]) << 1) - 1; +- } +- } +- +- counter = 2; +- for (i = 0; i < fc->partitions; i++) { +- vorbis_enc_floor_class * c = &fc->classes[fc->partition_to_class[i]]; +- int k, cval = 0, csub = 1<subclass; +- if (c->subclass) { +- vorbis_enc_codebook * book = &venc->codebooks[c->masterbook]; +- int cshift = 0; +- for (k = 0; k < c->dim; k++) { +- int l; +- for (l = 0; l < csub; l++) { +- int maxval = 1; +- if (c->books[l] != -1) +- maxval = venc->codebooks[c->books[l]].nentries; +- // coded could be -1, but this still works, cause that is 0 +- if (coded[counter + k] < maxval) +- break; +- } +- assert(l != csub); +- cval |= l << cshift; +- cshift += c->subclass; +- } +- put_codeword(pb, book, cval); +- } +- for (k = 0; k < c->dim; k++) { +- int book = c->books[cval & (csub-1)]; +- int entry = coded[counter++]; +- cval >>= c->subclass; +- if (book == -1) +- continue; +- if (entry == -1) +- entry = 0; +- put_codeword(pb, &venc->codebooks[book], entry); +- } +- } +- +- ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, +- fc->multiplier, floor, samples); +-} +- +-static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb, +- float *num) +-{ +- int i, entry = -1; +- float distance = FLT_MAX; +- assert(book->dimentions); +- for (i = 0; i < book->nentries; i++) { +- float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i]; +- int j; +- if (!book->lens[i]) +- continue; +- for (j = 0; j < book->ndimentions; j++) +- d -= vec[j] * num[j]; +- if (distance > d) { +- entry = i; +- distance = d; +- } +- } +- put_codeword(pb, book, entry); +- return &book->dimentions[entry * book->ndimentions]; +-} +- +-static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc, +- PutBitContext *pb, float *coeffs, int samples, +- int real_ch) +-{ +- int pass, i, j, p, k; +- int psize = rc->partition_size; +- int partitions = (rc->end - rc->begin) / psize; +- int channels = (rc->type == 2) ? 1 : real_ch; +- int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS]; +- int classwords = venc->codebooks[rc->classbook].ndimentions; +- +- assert(rc->type == 2); +- assert(real_ch == 2); +- for (p = 0; p < partitions; p++) { +- float max1 = 0., max2 = 0.; +- int s = rc->begin + p * psize; +- for (k = s; k < s + psize; k += 2) { +- max1 = FFMAX(max1, fabs(coeffs[ k / real_ch])); +- max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch])); +- } +- +- for (i = 0; i < rc->classifications - 1; i++) +- if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) +- break; +- classes[0][p] = i; +- } +- +- for (pass = 0; pass < 8; pass++) { +- p = 0; +- while (p < partitions) { +- if (pass == 0) +- for (j = 0; j < channels; j++) { +- vorbis_enc_codebook * book = &venc->codebooks[rc->classbook]; +- int entry = 0; +- for (i = 0; i < classwords; i++) { +- entry *= rc->classifications; +- entry += classes[j][p + i]; +- } +- put_codeword(pb, book, entry); +- } +- for (i = 0; i < classwords && p < partitions; i++, p++) { +- for (j = 0; j < channels; j++) { +- int nbook = rc->books[classes[j][p]][pass]; +- vorbis_enc_codebook * book = &venc->codebooks[nbook]; +- float *buf = coeffs + samples*j + rc->begin + p*psize; +- if (nbook == -1) +- continue; +- +- assert(rc->type == 0 || rc->type == 2); +- assert(!(psize % book->ndimentions)); +- +- if (rc->type == 0) { +- for (k = 0; k < psize; k += book->ndimentions) { +- float *a = put_vector(book, pb, &buf[k]); +- int l; +- for (l = 0; l < book->ndimentions; l++) +- buf[k + l] -= a[l]; +- } +- } else { +- int s = rc->begin + p * psize, a1, b1; +- a1 = (s % real_ch) * samples; +- b1 = s / real_ch; +- s = real_ch * samples; +- for (k = 0; k < psize; k += book->ndimentions) { +- int dim, a2 = a1, b2 = b1; +- float vec[MAX_CODEBOOK_DIM], *pv = vec; +- for (dim = book->ndimentions; dim--; ) { +- *pv++ = coeffs[a2 + b2]; +- if ((a2 += samples) == s) { +- a2 = 0; +- b2++; +- } +- } +- pv = put_vector(book, pb, vec); +- for (dim = book->ndimentions; dim--; ) { +- coeffs[a1 + b1] -= *pv++; +- if ((a1 += samples) == s) { +- a1 = 0; +- b1++; +- } +- } +- } +- } +- } +- } +- } +- } +-} +- +-static int apply_window_and_mdct(vorbis_enc_context *venc, const signed short *audio, +- int samples) +-{ +- int i, j, channel; +- const float * win = venc->win[0]; +- int window_len = 1 << (venc->log2_blocksize[0] - 1); +- float n = (float)(1 << venc->log2_blocksize[0]) / 4.; +- // FIXME use dsp +- +- if (!venc->have_saved && !samples) +- return 0; +- +- if (venc->have_saved) { +- for (channel = 0; channel < venc->channels; channel++) +- memcpy(venc->samples + channel * window_len * 2, +- venc->saved + channel * window_len, sizeof(float) * window_len); +- } else { +- for (channel = 0; channel < venc->channels; channel++) +- memset(venc->samples + channel * window_len * 2, 0, +- sizeof(float) * window_len); +- } +- +- if (samples) { +- for (channel = 0; channel < venc->channels; channel++) { +- float * offset = venc->samples + channel*window_len*2 + window_len; +- j = channel; +- for (i = 0; i < samples; i++, j += venc->channels) +- offset[i] = audio[j] / 32768. / n * win[window_len - i - 1]; +- } +- } else { +- for (channel = 0; channel < venc->channels; channel++) +- memset(venc->samples + channel * window_len * 2 + window_len, +- 0, sizeof(float) * window_len); +- } +- +- for (channel = 0; channel < venc->channels; channel++) +- ff_mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len, +- venc->samples + channel * window_len * 2); +- +- if (samples) { +- for (channel = 0; channel < venc->channels; channel++) { +- float *offset = venc->saved + channel * window_len; +- j = channel; +- for (i = 0; i < samples; i++, j += venc->channels) +- offset[i] = audio[j] / 32768. / n * win[i]; +- } +- venc->have_saved = 1; +- } else { +- venc->have_saved = 0; +- } +- return 1; +-} +- +-static av_cold int vorbis_encode_init(AVCodecContext *avccontext) +-{ +- vorbis_enc_context *venc = avccontext->priv_data; +- +- if (avccontext->channels != 2) { +- av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); +- return -1; +- } +- +- create_vorbis_context(venc, avccontext); +- +- if (avccontext->flags & CODEC_FLAG_QSCALE) +- venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.; +- else +- venc->quality = 0.03; +- venc->quality *= venc->quality; +- +- avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); +- +- avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); +- +- avccontext->coded_frame = avcodec_alloc_frame(); +- avccontext->coded_frame->key_frame = 1; +- +- return 0; +-} +- +-static int vorbis_encode_frame(AVCodecContext *avccontext, +- unsigned char *packets, +- int buf_size, void *data) +-{ +- vorbis_enc_context *venc = avccontext->priv_data; +- const signed short *audio = data; +- int samples = data ? avccontext->frame_size : 0; +- vorbis_enc_mode *mode; +- vorbis_enc_mapping *mapping; +- PutBitContext pb; +- int i; +- +- if (!apply_window_and_mdct(venc, audio, samples)) +- return 0; +- samples = 1 << (venc->log2_blocksize[0] - 1); +- +- init_put_bits(&pb, packets, buf_size); +- +- put_bits(&pb, 1, 0); // magic bit +- +- put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode +- +- mode = &venc->modes[0]; +- mapping = &venc->mappings[mode->mapping]; +- if (mode->blockflag) { +- put_bits(&pb, 1, 0); +- put_bits(&pb, 1, 0); +- } +- +- for (i = 0; i < venc->channels; i++) { +- vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]]; +- uint_fast16_t posts[MAX_FLOOR_VALUES]; +- floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); +- floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); +- } +- +- for (i = 0; i < venc->channels * samples; i++) +- venc->coeffs[i] /= venc->floor[i]; +- +- for (i = 0; i < mapping->coupling_steps; i++) { +- float *mag = venc->coeffs + mapping->magnitude[i] * samples; +- float *ang = venc->coeffs + mapping->angle[i] * samples; +- int j; +- for (j = 0; j < samples; j++) { +- float a = ang[j]; +- ang[j] -= mag[j]; +- if (mag[j] > 0) +- ang[j] = -ang[j]; +- if (ang[j] < 0) +- mag[j] = a; +- } +- } +- +- residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], +- &pb, venc->coeffs, samples, venc->channels); +- +- avccontext->coded_frame->pts = venc->sample_count; +- venc->sample_count += avccontext->frame_size; +- flush_put_bits(&pb); +- return put_bits_count(&pb) >> 3; +-} +- +- +-static av_cold int vorbis_encode_close(AVCodecContext *avccontext) +-{ +- vorbis_enc_context *venc = avccontext->priv_data; +- int i; +- +- if (venc->codebooks) +- for (i = 0; i < venc->ncodebooks; i++) { +- av_freep(&venc->codebooks[i].lens); +- av_freep(&venc->codebooks[i].codewords); +- av_freep(&venc->codebooks[i].quantlist); +- av_freep(&venc->codebooks[i].dimentions); +- av_freep(&venc->codebooks[i].pow2); +- } +- av_freep(&venc->codebooks); +- +- if (venc->floors) +- for (i = 0; i < venc->nfloors; i++) { +- int j; +- if (venc->floors[i].classes) +- for (j = 0; j < venc->floors[i].nclasses; j++) +- av_freep(&venc->floors[i].classes[j].books); +- av_freep(&venc->floors[i].classes); +- av_freep(&venc->floors[i].partition_to_class); +- av_freep(&venc->floors[i].list); +- } +- av_freep(&venc->floors); +- +- if (venc->residues) +- for (i = 0; i < venc->nresidues; i++) { +- av_freep(&venc->residues[i].books); +- av_freep(&venc->residues[i].maxes); +- } +- av_freep(&venc->residues); +- +- if (venc->mappings) +- for (i = 0; i < venc->nmappings; i++) { +- av_freep(&venc->mappings[i].mux); +- av_freep(&venc->mappings[i].floor); +- av_freep(&venc->mappings[i].residue); +- av_freep(&venc->mappings[i].magnitude); +- av_freep(&venc->mappings[i].angle); +- } +- av_freep(&venc->mappings); +- +- av_freep(&venc->modes); +- +- av_freep(&venc->saved); +- av_freep(&venc->samples); +- av_freep(&venc->floor); +- av_freep(&venc->coeffs); +- +- ff_mdct_end(&venc->mdct[0]); +- ff_mdct_end(&venc->mdct[1]); +- +- av_freep(&avccontext->coded_frame); +- av_freep(&avccontext->extradata); +- +- return 0 ; +-} +- +-AVCodec ff_vorbis_encoder = { +- "vorbis", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_VORBIS, +- sizeof(vorbis_enc_context), +- vorbis_encode_init, +- vorbis_encode_frame, +- vorbis_encode_close, +- .capabilities= CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbisenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbisenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbisenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbisenc.c 2012-05-14 14:08:54.373340766 +0200 +@@ -0,0 +1,1116 @@ ++/* ++ * copyright (c) 2006 Oded Shimon ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Native Vorbis encoder. ++ * @author Oded Shimon ++ */ ++ ++#include ++#include "avcodec.h" ++#include "dsputil.h" ++#include "fft.h" ++#include "vorbis.h" ++#include "vorbis_enc_data.h" ++ ++#define BITSTREAM_WRITER_LE ++#include "put_bits.h" ++ ++#undef NDEBUG ++#include ++ ++typedef struct { ++ int nentries; ++ uint8_t *lens; ++ uint32_t *codewords; ++ int ndimentions; ++ float min; ++ float delta; ++ int seq_p; ++ int lookup; ++ int *quantlist; ++ float *dimentions; ++ float *pow2; ++} vorbis_enc_codebook; ++ ++typedef struct { ++ int dim; ++ int subclass; ++ int masterbook; ++ int *books; ++} vorbis_enc_floor_class; ++ ++typedef struct { ++ int partitions; ++ int *partition_to_class; ++ int nclasses; ++ vorbis_enc_floor_class *classes; ++ int multiplier; ++ int rangebits; ++ int values; ++ vorbis_floor1_entry *list; ++} vorbis_enc_floor; ++ ++typedef struct { ++ int type; ++ int begin; ++ int end; ++ int partition_size; ++ int classifications; ++ int classbook; ++ int8_t (*books)[8]; ++ float (*maxes)[2]; ++} vorbis_enc_residue; ++ ++typedef struct { ++ int submaps; ++ int *mux; ++ int *floor; ++ int *residue; ++ int coupling_steps; ++ int *magnitude; ++ int *angle; ++} vorbis_enc_mapping; ++ ++typedef struct { ++ int blockflag; ++ int mapping; ++} vorbis_enc_mode; ++ ++typedef struct { ++ int channels; ++ int sample_rate; ++ int log2_blocksize[2]; ++ FFTContext mdct[2]; ++ const float *win[2]; ++ int have_saved; ++ float *saved; ++ float *samples; ++ float *floor; // also used for tmp values for mdct ++ float *coeffs; // also used for residue after floor ++ float quality; ++ ++ int ncodebooks; ++ vorbis_enc_codebook *codebooks; ++ ++ int nfloors; ++ vorbis_enc_floor *floors; ++ ++ int nresidues; ++ vorbis_enc_residue *residues; ++ ++ int nmappings; ++ vorbis_enc_mapping *mappings; ++ ++ int nmodes; ++ vorbis_enc_mode *modes; ++ ++ int64_t sample_count; ++} vorbis_enc_context; ++ ++#define MAX_CHANNELS 2 ++#define MAX_CODEBOOK_DIM 8 ++ ++#define MAX_FLOOR_CLASS_DIM 4 ++#define NUM_FLOOR_PARTITIONS 8 ++#define MAX_FLOOR_VALUES (MAX_FLOOR_CLASS_DIM*NUM_FLOOR_PARTITIONS+2) ++ ++#define RESIDUE_SIZE 1600 ++#define RESIDUE_PART_SIZE 32 ++#define NUM_RESIDUE_PARTITIONS (RESIDUE_SIZE/RESIDUE_PART_SIZE) ++ ++static inline void put_codeword(PutBitContext *pb, vorbis_enc_codebook *cb, ++ int entry) ++{ ++ assert(entry >= 0); ++ assert(entry < cb->nentries); ++ assert(cb->lens[entry]); ++ put_bits(pb, cb->lens[entry], cb->codewords[entry]); ++} ++ ++static int cb_lookup_vals(int lookup, int dimentions, int entries) ++{ ++ if (lookup == 1) ++ return ff_vorbis_nth_root(entries, dimentions); ++ else if (lookup == 2) ++ return dimentions *entries; ++ return 0; ++} ++ ++static void ready_codebook(vorbis_enc_codebook *cb) ++{ ++ int i; ++ ++ ff_vorbis_len2vlc(cb->lens, cb->codewords, cb->nentries); ++ ++ if (!cb->lookup) { ++ cb->pow2 = cb->dimentions = NULL; ++ } else { ++ int vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); ++ cb->dimentions = av_malloc(sizeof(float) * cb->nentries * cb->ndimentions); ++ cb->pow2 = av_mallocz(sizeof(float) * cb->nentries); ++ for (i = 0; i < cb->nentries; i++) { ++ float last = 0; ++ int j; ++ int div = 1; ++ for (j = 0; j < cb->ndimentions; j++) { ++ int off; ++ if (cb->lookup == 1) ++ off = (i / div) % vals; // lookup type 1 ++ else ++ off = i * cb->ndimentions + j; // lookup type 2 ++ ++ cb->dimentions[i * cb->ndimentions + j] = last + cb->min + cb->quantlist[off] * cb->delta; ++ if (cb->seq_p) ++ last = cb->dimentions[i * cb->ndimentions + j]; ++ cb->pow2[i] += cb->dimentions[i * cb->ndimentions + j] * cb->dimentions[i * cb->ndimentions + j]; ++ div *= vals; ++ } ++ cb->pow2[i] /= 2.; ++ } ++ } ++} ++ ++static void ready_residue(vorbis_enc_residue *rc, vorbis_enc_context *venc) ++{ ++ int i; ++ assert(rc->type == 2); ++ rc->maxes = av_mallocz(sizeof(float[2]) * rc->classifications); ++ for (i = 0; i < rc->classifications; i++) { ++ int j; ++ vorbis_enc_codebook * cb; ++ for (j = 0; j < 8; j++) ++ if (rc->books[i][j] != -1) ++ break; ++ if (j == 8) // zero ++ continue; ++ cb = &venc->codebooks[rc->books[i][j]]; ++ assert(cb->ndimentions >= 2); ++ assert(cb->lookup); ++ ++ for (j = 0; j < cb->nentries; j++) { ++ float a; ++ if (!cb->lens[j]) ++ continue; ++ a = fabs(cb->dimentions[j * cb->ndimentions]); ++ if (a > rc->maxes[i][0]) ++ rc->maxes[i][0] = a; ++ a = fabs(cb->dimentions[j * cb->ndimentions + 1]); ++ if (a > rc->maxes[i][1]) ++ rc->maxes[i][1] = a; ++ } ++ } ++ // small bias ++ for (i = 0; i < rc->classifications; i++) { ++ rc->maxes[i][0] += 0.8; ++ rc->maxes[i][1] += 0.8; ++ } ++} ++ ++static void create_vorbis_context(vorbis_enc_context *venc, ++ AVCodecContext *avccontext) ++{ ++ vorbis_enc_floor *fc; ++ vorbis_enc_residue *rc; ++ vorbis_enc_mapping *mc; ++ int i, book; ++ ++ venc->channels = avccontext->channels; ++ venc->sample_rate = avccontext->sample_rate; ++ venc->log2_blocksize[0] = venc->log2_blocksize[1] = 11; ++ ++ venc->ncodebooks = FF_ARRAY_ELEMS(cvectors); ++ venc->codebooks = av_malloc(sizeof(vorbis_enc_codebook) * venc->ncodebooks); ++ ++ // codebook 0..14 - floor1 book, values 0..255 ++ // codebook 15 residue masterbook ++ // codebook 16..29 residue ++ for (book = 0; book < venc->ncodebooks; book++) { ++ vorbis_enc_codebook *cb = &venc->codebooks[book]; ++ int vals; ++ cb->ndimentions = cvectors[book].dim; ++ cb->nentries = cvectors[book].real_len; ++ cb->min = cvectors[book].min; ++ cb->delta = cvectors[book].delta; ++ cb->lookup = cvectors[book].lookup; ++ cb->seq_p = 0; ++ ++ cb->lens = av_malloc(sizeof(uint8_t) * cb->nentries); ++ cb->codewords = av_malloc(sizeof(uint32_t) * cb->nentries); ++ memcpy(cb->lens, cvectors[book].clens, cvectors[book].len); ++ memset(cb->lens + cvectors[book].len, 0, cb->nentries - cvectors[book].len); ++ ++ if (cb->lookup) { ++ vals = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); ++ cb->quantlist = av_malloc(sizeof(int) * vals); ++ for (i = 0; i < vals; i++) ++ cb->quantlist[i] = cvectors[book].quant[i]; ++ } else { ++ cb->quantlist = NULL; ++ } ++ ready_codebook(cb); ++ } ++ ++ venc->nfloors = 1; ++ venc->floors = av_malloc(sizeof(vorbis_enc_floor) * venc->nfloors); ++ ++ // just 1 floor ++ fc = &venc->floors[0]; ++ fc->partitions = NUM_FLOOR_PARTITIONS; ++ fc->partition_to_class = av_malloc(sizeof(int) * fc->partitions); ++ fc->nclasses = 0; ++ for (i = 0; i < fc->partitions; i++) { ++ static const int a[] = {0, 1, 2, 2, 3, 3, 4, 4}; ++ fc->partition_to_class[i] = a[i]; ++ fc->nclasses = FFMAX(fc->nclasses, fc->partition_to_class[i]); ++ } ++ fc->nclasses++; ++ fc->classes = av_malloc(sizeof(vorbis_enc_floor_class) * fc->nclasses); ++ for (i = 0; i < fc->nclasses; i++) { ++ vorbis_enc_floor_class * c = &fc->classes[i]; ++ int j, books; ++ c->dim = floor_classes[i].dim; ++ c->subclass = floor_classes[i].subclass; ++ c->masterbook = floor_classes[i].masterbook; ++ books = (1 << c->subclass); ++ c->books = av_malloc(sizeof(int) * books); ++ for (j = 0; j < books; j++) ++ c->books[j] = floor_classes[i].nbooks[j]; ++ } ++ fc->multiplier = 2; ++ fc->rangebits = venc->log2_blocksize[0] - 1; ++ ++ fc->values = 2; ++ for (i = 0; i < fc->partitions; i++) ++ fc->values += fc->classes[fc->partition_to_class[i]].dim; ++ ++ fc->list = av_malloc(sizeof(vorbis_floor1_entry) * fc->values); ++ fc->list[0].x = 0; ++ fc->list[1].x = 1 << fc->rangebits; ++ for (i = 2; i < fc->values; i++) { ++ static const int a[] = { ++ 93, 23,372, 6, 46,186,750, 14, 33, 65, ++ 130,260,556, 3, 10, 18, 28, 39, 55, 79, ++ 111,158,220,312,464,650,850 ++ }; ++ fc->list[i].x = a[i - 2]; ++ } ++ ff_vorbis_ready_floor1_list(fc->list, fc->values); ++ ++ venc->nresidues = 1; ++ venc->residues = av_malloc(sizeof(vorbis_enc_residue) * venc->nresidues); ++ ++ // single residue ++ rc = &venc->residues[0]; ++ rc->type = 2; ++ rc->begin = 0; ++ rc->end = 1600; ++ rc->partition_size = 32; ++ rc->classifications = 10; ++ rc->classbook = 15; ++ rc->books = av_malloc(sizeof(*rc->books) * rc->classifications); ++ { ++ static const int8_t a[10][8] = { ++ { -1, -1, -1, -1, -1, -1, -1, -1, }, ++ { -1, -1, 16, -1, -1, -1, -1, -1, }, ++ { -1, -1, 17, -1, -1, -1, -1, -1, }, ++ { -1, -1, 18, -1, -1, -1, -1, -1, }, ++ { -1, -1, 19, -1, -1, -1, -1, -1, }, ++ { -1, -1, 20, -1, -1, -1, -1, -1, }, ++ { -1, -1, 21, -1, -1, -1, -1, -1, }, ++ { 22, 23, -1, -1, -1, -1, -1, -1, }, ++ { 24, 25, -1, -1, -1, -1, -1, -1, }, ++ { 26, 27, 28, -1, -1, -1, -1, -1, }, ++ }; ++ memcpy(rc->books, a, sizeof a); ++ } ++ ready_residue(rc, venc); ++ ++ venc->nmappings = 1; ++ venc->mappings = av_malloc(sizeof(vorbis_enc_mapping) * venc->nmappings); ++ ++ // single mapping ++ mc = &venc->mappings[0]; ++ mc->submaps = 1; ++ mc->mux = av_malloc(sizeof(int) * venc->channels); ++ for (i = 0; i < venc->channels; i++) ++ mc->mux[i] = 0; ++ mc->floor = av_malloc(sizeof(int) * mc->submaps); ++ mc->residue = av_malloc(sizeof(int) * mc->submaps); ++ for (i = 0; i < mc->submaps; i++) { ++ mc->floor[i] = 0; ++ mc->residue[i] = 0; ++ } ++ mc->coupling_steps = venc->channels == 2 ? 1 : 0; ++ mc->magnitude = av_malloc(sizeof(int) * mc->coupling_steps); ++ mc->angle = av_malloc(sizeof(int) * mc->coupling_steps); ++ if (mc->coupling_steps) { ++ mc->magnitude[0] = 0; ++ mc->angle[0] = 1; ++ } ++ ++ venc->nmodes = 1; ++ venc->modes = av_malloc(sizeof(vorbis_enc_mode) * venc->nmodes); ++ ++ // single mode ++ venc->modes[0].blockflag = 0; ++ venc->modes[0].mapping = 0; ++ ++ venc->have_saved = 0; ++ venc->saved = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); ++ venc->samples = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1])); ++ venc->floor = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); ++ venc->coeffs = av_malloc(sizeof(float) * venc->channels * (1 << venc->log2_blocksize[1]) / 2); ++ ++ venc->win[0] = ff_vorbis_vwin[venc->log2_blocksize[0] - 6]; ++ venc->win[1] = ff_vorbis_vwin[venc->log2_blocksize[1] - 6]; ++ ++ ff_mdct_init(&venc->mdct[0], venc->log2_blocksize[0], 0, 1.0); ++ ff_mdct_init(&venc->mdct[1], venc->log2_blocksize[1], 0, 1.0); ++} ++ ++static void put_float(PutBitContext *pb, float f) ++{ ++ int exp, mant; ++ uint32_t res = 0; ++ mant = (int)ldexp(frexp(f, &exp), 20); ++ exp += 788 - 20; ++ if (mant < 0) { ++ res |= (1U << 31); ++ mant = -mant; ++ } ++ res |= mant | (exp << 21); ++ put_bits32(pb, res); ++} ++ ++static void put_codebook_header(PutBitContext *pb, vorbis_enc_codebook *cb) ++{ ++ int i; ++ int ordered = 0; ++ ++ put_bits(pb, 24, 0x564342); //magic ++ put_bits(pb, 16, cb->ndimentions); ++ put_bits(pb, 24, cb->nentries); ++ ++ for (i = 1; i < cb->nentries; i++) ++ if (cb->lens[i] < cb->lens[i-1]) ++ break; ++ if (i == cb->nentries) ++ ordered = 1; ++ ++ put_bits(pb, 1, ordered); ++ if (ordered) { ++ int len = cb->lens[0]; ++ put_bits(pb, 5, len - 1); ++ i = 0; ++ while (i < cb->nentries) { ++ int j; ++ for (j = 0; j+i < cb->nentries; j++) ++ if (cb->lens[j+i] != len) ++ break; ++ put_bits(pb, ilog(cb->nentries - i), j); ++ i += j; ++ len++; ++ } ++ } else { ++ int sparse = 0; ++ for (i = 0; i < cb->nentries; i++) ++ if (!cb->lens[i]) ++ break; ++ if (i != cb->nentries) ++ sparse = 1; ++ put_bits(pb, 1, sparse); ++ ++ for (i = 0; i < cb->nentries; i++) { ++ if (sparse) ++ put_bits(pb, 1, !!cb->lens[i]); ++ if (cb->lens[i]) ++ put_bits(pb, 5, cb->lens[i] - 1); ++ } ++ } ++ ++ put_bits(pb, 4, cb->lookup); ++ if (cb->lookup) { ++ int tmp = cb_lookup_vals(cb->lookup, cb->ndimentions, cb->nentries); ++ int bits = ilog(cb->quantlist[0]); ++ ++ for (i = 1; i < tmp; i++) ++ bits = FFMAX(bits, ilog(cb->quantlist[i])); ++ ++ put_float(pb, cb->min); ++ put_float(pb, cb->delta); ++ ++ put_bits(pb, 4, bits - 1); ++ put_bits(pb, 1, cb->seq_p); ++ ++ for (i = 0; i < tmp; i++) ++ put_bits(pb, bits, cb->quantlist[i]); ++ } ++} ++ ++static void put_floor_header(PutBitContext *pb, vorbis_enc_floor *fc) ++{ ++ int i; ++ ++ put_bits(pb, 16, 1); // type, only floor1 is supported ++ ++ put_bits(pb, 5, fc->partitions); ++ ++ for (i = 0; i < fc->partitions; i++) ++ put_bits(pb, 4, fc->partition_to_class[i]); ++ ++ for (i = 0; i < fc->nclasses; i++) { ++ int j, books; ++ ++ put_bits(pb, 3, fc->classes[i].dim - 1); ++ put_bits(pb, 2, fc->classes[i].subclass); ++ ++ if (fc->classes[i].subclass) ++ put_bits(pb, 8, fc->classes[i].masterbook); ++ ++ books = (1 << fc->classes[i].subclass); ++ ++ for (j = 0; j < books; j++) ++ put_bits(pb, 8, fc->classes[i].books[j] + 1); ++ } ++ ++ put_bits(pb, 2, fc->multiplier - 1); ++ put_bits(pb, 4, fc->rangebits); ++ ++ for (i = 2; i < fc->values; i++) ++ put_bits(pb, fc->rangebits, fc->list[i].x); ++} ++ ++static void put_residue_header(PutBitContext *pb, vorbis_enc_residue *rc) ++{ ++ int i; ++ ++ put_bits(pb, 16, rc->type); ++ ++ put_bits(pb, 24, rc->begin); ++ put_bits(pb, 24, rc->end); ++ put_bits(pb, 24, rc->partition_size - 1); ++ put_bits(pb, 6, rc->classifications - 1); ++ put_bits(pb, 8, rc->classbook); ++ ++ for (i = 0; i < rc->classifications; i++) { ++ int j, tmp = 0; ++ for (j = 0; j < 8; j++) ++ tmp |= (rc->books[i][j] != -1) << j; ++ ++ put_bits(pb, 3, tmp & 7); ++ put_bits(pb, 1, tmp > 7); ++ ++ if (tmp > 7) ++ put_bits(pb, 5, tmp >> 3); ++ } ++ ++ for (i = 0; i < rc->classifications; i++) { ++ int j; ++ for (j = 0; j < 8; j++) ++ if (rc->books[i][j] != -1) ++ put_bits(pb, 8, rc->books[i][j]); ++ } ++} ++ ++static int put_main_header(vorbis_enc_context *venc, uint8_t **out) ++{ ++ int i; ++ PutBitContext pb; ++ uint8_t buffer[50000] = {0}, *p = buffer; ++ int buffer_len = sizeof buffer; ++ int len, hlens[3]; ++ ++ // identification header ++ init_put_bits(&pb, p, buffer_len); ++ put_bits(&pb, 8, 1); //magic ++ for (i = 0; "vorbis"[i]; i++) ++ put_bits(&pb, 8, "vorbis"[i]); ++ put_bits32(&pb, 0); // version ++ put_bits(&pb, 8, venc->channels); ++ put_bits32(&pb, venc->sample_rate); ++ put_bits32(&pb, 0); // bitrate ++ put_bits32(&pb, 0); // bitrate ++ put_bits32(&pb, 0); // bitrate ++ put_bits(&pb, 4, venc->log2_blocksize[0]); ++ put_bits(&pb, 4, venc->log2_blocksize[1]); ++ put_bits(&pb, 1, 1); // framing ++ ++ flush_put_bits(&pb); ++ hlens[0] = put_bits_count(&pb) >> 3; ++ buffer_len -= hlens[0]; ++ p += hlens[0]; ++ ++ // comment header ++ init_put_bits(&pb, p, buffer_len); ++ put_bits(&pb, 8, 3); //magic ++ for (i = 0; "vorbis"[i]; i++) ++ put_bits(&pb, 8, "vorbis"[i]); ++ put_bits32(&pb, 0); // vendor length TODO ++ put_bits32(&pb, 0); // amount of comments ++ put_bits(&pb, 1, 1); // framing ++ ++ flush_put_bits(&pb); ++ hlens[1] = put_bits_count(&pb) >> 3; ++ buffer_len -= hlens[1]; ++ p += hlens[1]; ++ ++ // setup header ++ init_put_bits(&pb, p, buffer_len); ++ put_bits(&pb, 8, 5); //magic ++ for (i = 0; "vorbis"[i]; i++) ++ put_bits(&pb, 8, "vorbis"[i]); ++ ++ // codebooks ++ put_bits(&pb, 8, venc->ncodebooks - 1); ++ for (i = 0; i < venc->ncodebooks; i++) ++ put_codebook_header(&pb, &venc->codebooks[i]); ++ ++ // time domain, reserved, zero ++ put_bits(&pb, 6, 0); ++ put_bits(&pb, 16, 0); ++ ++ // floors ++ put_bits(&pb, 6, venc->nfloors - 1); ++ for (i = 0; i < venc->nfloors; i++) ++ put_floor_header(&pb, &venc->floors[i]); ++ ++ // residues ++ put_bits(&pb, 6, venc->nresidues - 1); ++ for (i = 0; i < venc->nresidues; i++) ++ put_residue_header(&pb, &venc->residues[i]); ++ ++ // mappings ++ put_bits(&pb, 6, venc->nmappings - 1); ++ for (i = 0; i < venc->nmappings; i++) { ++ vorbis_enc_mapping *mc = &venc->mappings[i]; ++ int j; ++ put_bits(&pb, 16, 0); // mapping type ++ ++ put_bits(&pb, 1, mc->submaps > 1); ++ if (mc->submaps > 1) ++ put_bits(&pb, 4, mc->submaps - 1); ++ ++ put_bits(&pb, 1, !!mc->coupling_steps); ++ if (mc->coupling_steps) { ++ put_bits(&pb, 8, mc->coupling_steps - 1); ++ for (j = 0; j < mc->coupling_steps; j++) { ++ put_bits(&pb, ilog(venc->channels - 1), mc->magnitude[j]); ++ put_bits(&pb, ilog(venc->channels - 1), mc->angle[j]); ++ } ++ } ++ ++ put_bits(&pb, 2, 0); // reserved ++ ++ if (mc->submaps > 1) ++ for (j = 0; j < venc->channels; j++) ++ put_bits(&pb, 4, mc->mux[j]); ++ ++ for (j = 0; j < mc->submaps; j++) { ++ put_bits(&pb, 8, 0); // reserved time configuration ++ put_bits(&pb, 8, mc->floor[j]); ++ put_bits(&pb, 8, mc->residue[j]); ++ } ++ } ++ ++ // modes ++ put_bits(&pb, 6, venc->nmodes - 1); ++ for (i = 0; i < venc->nmodes; i++) { ++ put_bits(&pb, 1, venc->modes[i].blockflag); ++ put_bits(&pb, 16, 0); // reserved window type ++ put_bits(&pb, 16, 0); // reserved transform type ++ put_bits(&pb, 8, venc->modes[i].mapping); ++ } ++ ++ put_bits(&pb, 1, 1); // framing ++ ++ flush_put_bits(&pb); ++ hlens[2] = put_bits_count(&pb) >> 3; ++ ++ len = hlens[0] + hlens[1] + hlens[2]; ++ p = *out = av_mallocz(64 + len + len/255); ++ ++ *p++ = 2; ++ p += av_xiphlacing(p, hlens[0]); ++ p += av_xiphlacing(p, hlens[1]); ++ buffer_len = 0; ++ for (i = 0; i < 3; i++) { ++ memcpy(p, buffer + buffer_len, hlens[i]); ++ p += hlens[i]; ++ buffer_len += hlens[i]; ++ } ++ ++ return p - *out; ++} ++ ++static float get_floor_average(vorbis_enc_floor * fc, float *coeffs, int i) ++{ ++ int begin = fc->list[fc->list[FFMAX(i-1, 0)].sort].x; ++ int end = fc->list[fc->list[FFMIN(i+1, fc->values - 1)].sort].x; ++ int j; ++ float average = 0; ++ ++ for (j = begin; j < end; j++) ++ average += fabs(coeffs[j]); ++ return average / (end - begin); ++} ++ ++static void floor_fit(vorbis_enc_context *venc, vorbis_enc_floor *fc, ++ float *coeffs, uint16_t *posts, int samples) ++{ ++ int range = 255 / fc->multiplier + 1; ++ int i; ++ float tot_average = 0.; ++ float averages[MAX_FLOOR_VALUES]; ++ for (i = 0; i < fc->values; i++) { ++ averages[i] = get_floor_average(fc, coeffs, i); ++ tot_average += averages[i]; ++ } ++ tot_average /= fc->values; ++ tot_average /= venc->quality; ++ ++ for (i = 0; i < fc->values; i++) { ++ int position = fc->list[fc->list[i].sort].x; ++ float average = averages[i]; ++ int j; ++ ++ average = sqrt(tot_average * average) * pow(1.25f, position*0.005f); // MAGIC! ++ for (j = 0; j < range - 1; j++) ++ if (ff_vorbis_floor1_inverse_db_table[j * fc->multiplier] > average) ++ break; ++ posts[fc->list[i].sort] = j; ++ } ++} ++ ++static int render_point(int x0, int y0, int x1, int y1, int x) ++{ ++ return y0 + (x - x0) * (y1 - y0) / (x1 - x0); ++} ++ ++static void floor_encode(vorbis_enc_context *venc, vorbis_enc_floor *fc, ++ PutBitContext *pb, uint16_t *posts, ++ float *floor, int samples) ++{ ++ int range = 255 / fc->multiplier + 1; ++ int coded[MAX_FLOOR_VALUES]; // first 2 values are unused ++ int i, counter; ++ ++ put_bits(pb, 1, 1); // non zero ++ put_bits(pb, ilog(range - 1), posts[0]); ++ put_bits(pb, ilog(range - 1), posts[1]); ++ coded[0] = coded[1] = 1; ++ ++ for (i = 2; i < fc->values; i++) { ++ int predicted = render_point(fc->list[fc->list[i].low].x, ++ posts[fc->list[i].low], ++ fc->list[fc->list[i].high].x, ++ posts[fc->list[i].high], ++ fc->list[i].x); ++ int highroom = range - predicted; ++ int lowroom = predicted; ++ int room = FFMIN(highroom, lowroom); ++ if (predicted == posts[i]) { ++ coded[i] = 0; // must be used later as flag! ++ continue; ++ } else { ++ if (!coded[fc->list[i].low ]) ++ coded[fc->list[i].low ] = -1; ++ if (!coded[fc->list[i].high]) ++ coded[fc->list[i].high] = -1; ++ } ++ if (posts[i] > predicted) { ++ if (posts[i] - predicted > room) ++ coded[i] = posts[i] - predicted + lowroom; ++ else ++ coded[i] = (posts[i] - predicted) << 1; ++ } else { ++ if (predicted - posts[i] > room) ++ coded[i] = predicted - posts[i] + highroom - 1; ++ else ++ coded[i] = ((predicted - posts[i]) << 1) - 1; ++ } ++ } ++ ++ counter = 2; ++ for (i = 0; i < fc->partitions; i++) { ++ vorbis_enc_floor_class * c = &fc->classes[fc->partition_to_class[i]]; ++ int k, cval = 0, csub = 1<subclass; ++ if (c->subclass) { ++ vorbis_enc_codebook * book = &venc->codebooks[c->masterbook]; ++ int cshift = 0; ++ for (k = 0; k < c->dim; k++) { ++ int l; ++ for (l = 0; l < csub; l++) { ++ int maxval = 1; ++ if (c->books[l] != -1) ++ maxval = venc->codebooks[c->books[l]].nentries; ++ // coded could be -1, but this still works, cause that is 0 ++ if (coded[counter + k] < maxval) ++ break; ++ } ++ assert(l != csub); ++ cval |= l << cshift; ++ cshift += c->subclass; ++ } ++ put_codeword(pb, book, cval); ++ } ++ for (k = 0; k < c->dim; k++) { ++ int book = c->books[cval & (csub-1)]; ++ int entry = coded[counter++]; ++ cval >>= c->subclass; ++ if (book == -1) ++ continue; ++ if (entry == -1) ++ entry = 0; ++ put_codeword(pb, &venc->codebooks[book], entry); ++ } ++ } ++ ++ ff_vorbis_floor1_render_list(fc->list, fc->values, posts, coded, ++ fc->multiplier, floor, samples); ++} ++ ++static float *put_vector(vorbis_enc_codebook *book, PutBitContext *pb, ++ float *num) ++{ ++ int i, entry = -1; ++ float distance = FLT_MAX; ++ assert(book->dimentions); ++ for (i = 0; i < book->nentries; i++) { ++ float * vec = book->dimentions + i * book->ndimentions, d = book->pow2[i]; ++ int j; ++ if (!book->lens[i]) ++ continue; ++ for (j = 0; j < book->ndimentions; j++) ++ d -= vec[j] * num[j]; ++ if (distance > d) { ++ entry = i; ++ distance = d; ++ } ++ } ++ put_codeword(pb, book, entry); ++ return &book->dimentions[entry * book->ndimentions]; ++} ++ ++static void residue_encode(vorbis_enc_context *venc, vorbis_enc_residue *rc, ++ PutBitContext *pb, float *coeffs, int samples, ++ int real_ch) ++{ ++ int pass, i, j, p, k; ++ int psize = rc->partition_size; ++ int partitions = (rc->end - rc->begin) / psize; ++ int channels = (rc->type == 2) ? 1 : real_ch; ++ int classes[MAX_CHANNELS][NUM_RESIDUE_PARTITIONS]; ++ int classwords = venc->codebooks[rc->classbook].ndimentions; ++ ++ assert(rc->type == 2); ++ assert(real_ch == 2); ++ for (p = 0; p < partitions; p++) { ++ float max1 = 0., max2 = 0.; ++ int s = rc->begin + p * psize; ++ for (k = s; k < s + psize; k += 2) { ++ max1 = FFMAX(max1, fabs(coeffs[ k / real_ch])); ++ max2 = FFMAX(max2, fabs(coeffs[samples + k / real_ch])); ++ } ++ ++ for (i = 0; i < rc->classifications - 1; i++) ++ if (max1 < rc->maxes[i][0] && max2 < rc->maxes[i][1]) ++ break; ++ classes[0][p] = i; ++ } ++ ++ for (pass = 0; pass < 8; pass++) { ++ p = 0; ++ while (p < partitions) { ++ if (pass == 0) ++ for (j = 0; j < channels; j++) { ++ vorbis_enc_codebook * book = &venc->codebooks[rc->classbook]; ++ int entry = 0; ++ for (i = 0; i < classwords; i++) { ++ entry *= rc->classifications; ++ entry += classes[j][p + i]; ++ } ++ put_codeword(pb, book, entry); ++ } ++ for (i = 0; i < classwords && p < partitions; i++, p++) { ++ for (j = 0; j < channels; j++) { ++ int nbook = rc->books[classes[j][p]][pass]; ++ vorbis_enc_codebook * book = &venc->codebooks[nbook]; ++ float *buf = coeffs + samples*j + rc->begin + p*psize; ++ if (nbook == -1) ++ continue; ++ ++ assert(rc->type == 0 || rc->type == 2); ++ assert(!(psize % book->ndimentions)); ++ ++ if (rc->type == 0) { ++ for (k = 0; k < psize; k += book->ndimentions) { ++ float *a = put_vector(book, pb, &buf[k]); ++ int l; ++ for (l = 0; l < book->ndimentions; l++) ++ buf[k + l] -= a[l]; ++ } ++ } else { ++ int s = rc->begin + p * psize, a1, b1; ++ a1 = (s % real_ch) * samples; ++ b1 = s / real_ch; ++ s = real_ch * samples; ++ for (k = 0; k < psize; k += book->ndimentions) { ++ int dim, a2 = a1, b2 = b1; ++ float vec[MAX_CODEBOOK_DIM], *pv = vec; ++ for (dim = book->ndimentions; dim--; ) { ++ *pv++ = coeffs[a2 + b2]; ++ if ((a2 += samples) == s) { ++ a2 = 0; ++ b2++; ++ } ++ } ++ pv = put_vector(book, pb, vec); ++ for (dim = book->ndimentions; dim--; ) { ++ coeffs[a1 + b1] -= *pv++; ++ if ((a1 += samples) == s) { ++ a1 = 0; ++ b1++; ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++ } ++} ++ ++static int apply_window_and_mdct(vorbis_enc_context *venc, const signed short *audio, ++ int samples) ++{ ++ int i, j, channel; ++ const float * win = venc->win[0]; ++ int window_len = 1 << (venc->log2_blocksize[0] - 1); ++ float n = (float)(1 << venc->log2_blocksize[0]) / 4.; ++ // FIXME use dsp ++ ++ if (!venc->have_saved && !samples) ++ return 0; ++ ++ if (venc->have_saved) { ++ for (channel = 0; channel < venc->channels; channel++) ++ memcpy(venc->samples + channel * window_len * 2, ++ venc->saved + channel * window_len, sizeof(float) * window_len); ++ } else { ++ for (channel = 0; channel < venc->channels; channel++) ++ memset(venc->samples + channel * window_len * 2, 0, ++ sizeof(float) * window_len); ++ } ++ ++ if (samples) { ++ for (channel = 0; channel < venc->channels; channel++) { ++ float * offset = venc->samples + channel*window_len*2 + window_len; ++ j = channel; ++ for (i = 0; i < samples; i++, j += venc->channels) ++ offset[i] = audio[j] / 32768. / n * win[window_len - i - 1]; ++ } ++ } else { ++ for (channel = 0; channel < venc->channels; channel++) ++ memset(venc->samples + channel * window_len * 2 + window_len, ++ 0, sizeof(float) * window_len); ++ } ++ ++ for (channel = 0; channel < venc->channels; channel++) ++ venc->mdct[0].mdct_calc(&venc->mdct[0], venc->coeffs + channel * window_len, ++ venc->samples + channel * window_len * 2); ++ ++ if (samples) { ++ for (channel = 0; channel < venc->channels; channel++) { ++ float *offset = venc->saved + channel * window_len; ++ j = channel; ++ for (i = 0; i < samples; i++, j += venc->channels) ++ offset[i] = audio[j] / 32768. / n * win[i]; ++ } ++ venc->have_saved = 1; ++ } else { ++ venc->have_saved = 0; ++ } ++ return 1; ++} ++ ++static av_cold int vorbis_encode_init(AVCodecContext *avccontext) ++{ ++ vorbis_enc_context *venc = avccontext->priv_data; ++ ++ if (avccontext->channels != 2) { ++ av_log(avccontext, AV_LOG_ERROR, "Current FFmpeg Vorbis encoder only supports 2 channels.\n"); ++ return -1; ++ } ++ ++ create_vorbis_context(venc, avccontext); ++ ++ if (avccontext->flags & CODEC_FLAG_QSCALE) ++ venc->quality = avccontext->global_quality / (float)FF_QP2LAMBDA / 10.; ++ else ++ venc->quality = 0.03; ++ venc->quality *= venc->quality; ++ ++ avccontext->extradata_size = put_main_header(venc, (uint8_t**)&avccontext->extradata); ++ ++ avccontext->frame_size = 1 << (venc->log2_blocksize[0] - 1); ++ ++ avccontext->coded_frame = avcodec_alloc_frame(); ++ avccontext->coded_frame->key_frame = 1; ++ ++ return 0; ++} ++ ++static int vorbis_encode_frame(AVCodecContext *avccontext, ++ unsigned char *packets, ++ int buf_size, void *data) ++{ ++ vorbis_enc_context *venc = avccontext->priv_data; ++ const signed short *audio = data; ++ int samples = data ? avccontext->frame_size : 0; ++ vorbis_enc_mode *mode; ++ vorbis_enc_mapping *mapping; ++ PutBitContext pb; ++ int i; ++ ++ if (!apply_window_and_mdct(venc, audio, samples)) ++ return 0; ++ samples = 1 << (venc->log2_blocksize[0] - 1); ++ ++ init_put_bits(&pb, packets, buf_size); ++ ++ put_bits(&pb, 1, 0); // magic bit ++ ++ put_bits(&pb, ilog(venc->nmodes - 1), 0); // 0 bits, the mode ++ ++ mode = &venc->modes[0]; ++ mapping = &venc->mappings[mode->mapping]; ++ if (mode->blockflag) { ++ put_bits(&pb, 1, 0); ++ put_bits(&pb, 1, 0); ++ } ++ ++ for (i = 0; i < venc->channels; i++) { ++ vorbis_enc_floor *fc = &venc->floors[mapping->floor[mapping->mux[i]]]; ++ uint16_t posts[MAX_FLOOR_VALUES]; ++ floor_fit(venc, fc, &venc->coeffs[i * samples], posts, samples); ++ floor_encode(venc, fc, &pb, posts, &venc->floor[i * samples], samples); ++ } ++ ++ for (i = 0; i < venc->channels * samples; i++) ++ venc->coeffs[i] /= venc->floor[i]; ++ ++ for (i = 0; i < mapping->coupling_steps; i++) { ++ float *mag = venc->coeffs + mapping->magnitude[i] * samples; ++ float *ang = venc->coeffs + mapping->angle[i] * samples; ++ int j; ++ for (j = 0; j < samples; j++) { ++ float a = ang[j]; ++ ang[j] -= mag[j]; ++ if (mag[j] > 0) ++ ang[j] = -ang[j]; ++ if (ang[j] < 0) ++ mag[j] = a; ++ } ++ } ++ ++ residue_encode(venc, &venc->residues[mapping->residue[mapping->mux[0]]], ++ &pb, venc->coeffs, samples, venc->channels); ++ ++ avccontext->coded_frame->pts = venc->sample_count; ++ venc->sample_count += avccontext->frame_size; ++ flush_put_bits(&pb); ++ return put_bits_count(&pb) >> 3; ++} ++ ++ ++static av_cold int vorbis_encode_close(AVCodecContext *avccontext) ++{ ++ vorbis_enc_context *venc = avccontext->priv_data; ++ int i; ++ ++ if (venc->codebooks) ++ for (i = 0; i < venc->ncodebooks; i++) { ++ av_freep(&venc->codebooks[i].lens); ++ av_freep(&venc->codebooks[i].codewords); ++ av_freep(&venc->codebooks[i].quantlist); ++ av_freep(&venc->codebooks[i].dimentions); ++ av_freep(&venc->codebooks[i].pow2); ++ } ++ av_freep(&venc->codebooks); ++ ++ if (venc->floors) ++ for (i = 0; i < venc->nfloors; i++) { ++ int j; ++ if (venc->floors[i].classes) ++ for (j = 0; j < venc->floors[i].nclasses; j++) ++ av_freep(&venc->floors[i].classes[j].books); ++ av_freep(&venc->floors[i].classes); ++ av_freep(&venc->floors[i].partition_to_class); ++ av_freep(&venc->floors[i].list); ++ } ++ av_freep(&venc->floors); ++ ++ if (venc->residues) ++ for (i = 0; i < venc->nresidues; i++) { ++ av_freep(&venc->residues[i].books); ++ av_freep(&venc->residues[i].maxes); ++ } ++ av_freep(&venc->residues); ++ ++ if (venc->mappings) ++ for (i = 0; i < venc->nmappings; i++) { ++ av_freep(&venc->mappings[i].mux); ++ av_freep(&venc->mappings[i].floor); ++ av_freep(&venc->mappings[i].residue); ++ av_freep(&venc->mappings[i].magnitude); ++ av_freep(&venc->mappings[i].angle); ++ } ++ av_freep(&venc->mappings); ++ ++ av_freep(&venc->modes); ++ ++ av_freep(&venc->saved); ++ av_freep(&venc->samples); ++ av_freep(&venc->floor); ++ av_freep(&venc->coeffs); ++ ++ ff_mdct_end(&venc->mdct[0]); ++ ff_mdct_end(&venc->mdct[1]); ++ ++ av_freep(&avccontext->coded_frame); ++ av_freep(&avccontext->extradata); ++ ++ return 0 ; ++} ++ ++AVCodec ff_vorbis_encoder = { ++ .name = "vorbis", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_VORBIS, ++ .priv_data_size = sizeof(vorbis_enc_context), ++ .init = vorbis_encode_init, ++ .encode = vorbis_encode_frame, ++ .close = vorbis_encode_close, ++ .capabilities= CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Vorbis"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_enc_data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_enc_data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis_enc_data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis_enc_data.h 2012-05-14 14:08:54.366340625 +0200 +@@ -492,13 +492,13 @@ + int dim; + int subclass; + int masterbook; +- const int *nbooks; ++ const int nbooks[4]; + } floor_classes[] = { +- { 3, 0, 0, (const int[]){ 4 } }, +- { 4, 1, 0, (const int[]){ 5, 6 } }, +- { 3, 1, 1, (const int[]){ 7, 8 } }, +- { 4, 2, 2, (const int[]){ -1, 9, 10, 11 } }, +- { 3, 2, 3, (const int[]){ -1, 12, 13, 14 } }, ++ { 3, 0, 0, { 4 } }, ++ { 4, 1, 0, { 5, 6 } }, ++ { 3, 1, 1, { 7, 8 } }, ++ { 4, 2, 2, { -1, 9, 10, 11 } }, ++ { 3, 2, 3, { -1, 12, 13, 14 } }, + }; + + #endif /* AVCODEC_VORBIS_ENC_DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vorbis.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vorbis.h 2012-05-14 14:08:54.356340424 +0200 +@@ -27,20 +27,20 @@ + extern const float * const ff_vorbis_vwin[8]; + extern const uint8_t ff_vorbis_channel_layout_offsets[8][8]; + extern const uint8_t ff_vorbis_encoding_channel_layout_offsets[8][8]; +-extern const int64_t ff_vorbis_channel_layouts[9]; ++extern const uint64_t ff_vorbis_channel_layouts[9]; + + typedef struct { +- uint_fast16_t x; +- uint_fast16_t sort; +- uint_fast16_t low; +- uint_fast16_t high; ++ uint16_t x; ++ uint16_t sort; ++ uint16_t low; ++ uint16_t high; + } vorbis_floor1_entry; + + void ff_vorbis_ready_floor1_list(vorbis_floor1_entry * list, int values); + unsigned int ff_vorbis_nth_root(unsigned int x, unsigned int n); // x^(1/n) +-int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, uint_fast32_t num); ++int ff_vorbis_len2vlc(uint8_t *bits, uint32_t *codes, unsigned num); + void ff_vorbis_floor1_render_list(vorbis_floor1_entry * list, int values, +- uint_fast16_t * y_list, int * flag, ++ uint16_t *y_list, int *flag, + int multiplier, float * out, int samples); + void vorbis_inverse_coupling(float *mag, float *ang, int blocksize); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3.c 2012-05-14 14:08:54.377340848 +0200 +@@ -33,18 +33,18 @@ + #include + #include + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" ++#include "internal.h" + #include "dsputil.h" + #include "get_bits.h" + + #include "vp3data.h" + #include "xiph.h" ++#include "thread.h" + + #define FRAGMENT_PIXELS 8 + +-static av_cold int vp3_decode_end(AVCodecContext *avctx); +- + //FIXME split things out into their own arrays + typedef struct Vp3Fragment { + int16_t dc; +@@ -224,7 +224,7 @@ + + /* these arrays need to be on 16-byte boundaries since SSE2 operations + * index into them */ +- DECLARE_ALIGNED(16, int16_t, qmat)[3][2][3][64]; //priv_data; ++ ++ if (s->golden_frame.data[0]) { ++ if (s->golden_frame.data[0] == s->last_frame.data[0]) ++ memset(&s->last_frame, 0, sizeof(AVFrame)); ++ if (s->current_frame.data[0] == s->golden_frame.data[0]) ++ memset(&s->current_frame, 0, sizeof(AVFrame)); ++ ff_thread_release_buffer(avctx, &s->golden_frame); ++ } ++ if (s->last_frame.data[0]) { ++ if (s->current_frame.data[0] == s->last_frame.data[0]) ++ memset(&s->current_frame, 0, sizeof(AVFrame)); ++ ff_thread_release_buffer(avctx, &s->last_frame); ++ } ++ if (s->current_frame.data[0]) ++ ff_thread_release_buffer(avctx, &s->current_frame); ++} ++ ++static av_cold int vp3_decode_end(AVCodecContext *avctx) ++{ ++ Vp3DecodeContext *s = avctx->priv_data; ++ int i; ++ ++ av_free(s->superblock_coding); ++ av_free(s->all_fragments); ++ av_free(s->coded_fragment_list[0]); ++ av_free(s->dct_tokens_base); ++ av_free(s->superblock_fragments); ++ av_free(s->macroblock_coding); ++ av_free(s->motion_val[0]); ++ av_free(s->motion_val[1]); ++ av_free(s->edge_emu_buffer); ++ ++ if (avctx->internal->is_copy) ++ return 0; ++ ++ for (i = 0; i < 16; i++) { ++ free_vlc(&s->dc_vlc[i]); ++ free_vlc(&s->ac_vlc_1[i]); ++ free_vlc(&s->ac_vlc_2[i]); ++ free_vlc(&s->ac_vlc_3[i]); ++ free_vlc(&s->ac_vlc_4[i]); ++ } ++ ++ free_vlc(&s->superblock_run_length_vlc); ++ free_vlc(&s->fragment_run_length_vlc); ++ free_vlc(&s->mode_code_vlc); ++ free_vlc(&s->motion_vector_vlc); ++ ++ /* release all frames */ ++ vp3_decode_flush(avctx); ++ ++ return 0; ++} ++ + /* + * This function sets up all of the various blocks mappings: + * superblocks <-> fragments, macroblocks <-> fragments, +@@ -324,8 +380,6 @@ + s->qmat[qpi][inter][plane][0] = s->qmat[0][inter][plane][0]; + } + } +- +- memset(s->qscale_table, (FFMAX(s->qmat[0][0][0][1], s->qmat[0][0][1][1])+8)/16, 512); //FIXME finetune + } + + /* +@@ -892,7 +946,7 @@ + /* decode a VLC into a token */ + token = get_vlc2(gb, vlc_table, 11, 3); + /* use the token to get a zero run, a coefficient, and an eob run */ +- if (token <= 6) { ++ if ((unsigned) token <= 6U) { + eob_run = eob_run_base[token]; + if (eob_run_get_bits[token]) + eob_run += get_bits(gb, eob_run_get_bits[token]); +@@ -910,7 +964,7 @@ + coeff_i += eob_run; + eob_run = 0; + } +- } else { ++ } else if (token >= 0) { + bits_to_get = coeff_get_bits[token]; + if (bits_to_get) + bits_to_get = get_bits(gb, bits_to_get); +@@ -944,6 +998,10 @@ + for (i = coeff_index+1; i <= coeff_index+zero_run; i++) + s->num_coded_frags[plane][i]--; + coeff_i++; ++ } else { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "Invalid token %d\n", token); ++ return -1; + } + } + +@@ -993,6 +1051,8 @@ + /* unpack the Y plane DC coefficients */ + residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_y_table], 0, + 0, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + + /* reverse prediction of the Y-plane DC coefficients */ + reverse_dc_prediction(s, 0, s->fragment_width[0], s->fragment_height[0]); +@@ -1000,8 +1060,12 @@ + /* unpack the C plane DC coefficients */ + residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, + 1, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + residual_eob_run = unpack_vlcs(s, gb, &s->dc_vlc[dc_c_table], 0, + 2, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + + /* reverse prediction of the C-plane DC coefficients */ + if (!(s->avctx->flags & CODEC_FLAG_GRAY)) +@@ -1038,11 +1102,17 @@ + for (i = 1; i <= 63; i++) { + residual_eob_run = unpack_vlcs(s, gb, y_tables[i], i, + 0, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + + residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i, + 1, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + residual_eob_run = unpack_vlcs(s, gb, c_tables[i], i, + 2, residual_eob_run); ++ if (residual_eob_run < 0) ++ return residual_eob_run; + } + + return 0; +@@ -1293,6 +1363,10 @@ + case 1: // zero run + s->dct_tokens[plane][i]++; + i += (token >> 2) & 0x7f; ++ if (i > 63) { ++ av_log(s->avctx, AV_LOG_ERROR, "Coefficient index overflow\n"); ++ return i; ++ } + block[perm[i]] = (token >> 9) * dequantizer[perm[i]]; + i++; + break; +@@ -1304,6 +1378,8 @@ + return i; + } + } while (i < 64); ++ // return value is expected to be a valid level ++ i--; + end: + // the actual DC+prediction is in the fragment structure + block[0] = frag->dc * s->qmat[0][inter][plane][0]; +@@ -1315,8 +1391,17 @@ + */ + static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y) + { +- int h, cy; +- int offset[4]; ++ int h, cy, i; ++ int offset[AV_NUM_DATA_POINTERS]; ++ ++ if (HAVE_THREADS && s->avctx->active_thread_type&FF_THREAD_FRAME) { ++ int y_flipped = s->flipped_image ? s->avctx->height-y : y; ++ ++ // At the end of the frame, report INT_MAX instead of the height of the frame. ++ // This makes the other threads' ff_thread_await_progress() calls cheaper, because ++ // they don't have to clip their values. ++ ff_thread_report_progress(&s->current_frame, y_flipped==s->avctx->height ? INT_MAX : y_flipped-1, 0); ++ } + + if(s->avctx->draw_horiz_band==NULL) + return; +@@ -1333,19 +1418,42 @@ + offset[0] = s->current_frame.linesize[0]*y; + offset[1] = s->current_frame.linesize[1]*cy; + offset[2] = s->current_frame.linesize[2]*cy; +- offset[3] = 0; ++ for (i = 3; i < AV_NUM_DATA_POINTERS; i++) ++ offset[i] = 0; + + emms_c(); + s->avctx->draw_horiz_band(s->avctx, &s->current_frame, offset, y, 3, h); + } + ++/** ++ * Wait for the reference frame of the current fragment. ++ * The progress value is in luma pixel rows. ++ */ ++static void await_reference_row(Vp3DecodeContext *s, Vp3Fragment *fragment, int motion_y, int y) ++{ ++ AVFrame *ref_frame; ++ int ref_row; ++ int border = motion_y&1; ++ ++ if (fragment->coding_method == MODE_USING_GOLDEN || ++ fragment->coding_method == MODE_GOLDEN_MV) ++ ref_frame = &s->golden_frame; ++ else ++ ref_frame = &s->last_frame; ++ ++ ref_row = y + (motion_y>>1); ++ ref_row = FFMAX(FFABS(ref_row), ref_row + 8 + border); ++ ++ ff_thread_await_progress(ref_frame, ref_row, 0); ++} ++ + /* + * Perform the final rendering for a particular slice of data. + * The slice number ranges from 0..(c_superblock_height - 1). + */ + static void render_slice(Vp3DecodeContext *s, int slice) + { +- int x, y, i, j; ++ int x, y, i, j, fragment; + LOCAL_ALIGNED_16(DCTELEM, block, [64]); + int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; + int motion_halfpel_index; +@@ -1371,15 +1479,12 @@ + int fragment_width = s->fragment_width[!!plane]; + int fragment_height = s->fragment_height[!!plane]; + int fragment_start = s->fragment_start[plane]; ++ int do_await = !plane && HAVE_THREADS && (s->avctx->active_thread_type&FF_THREAD_FRAME); + + if (!s->flipped_image) stride = -stride; + if (CONFIG_GRAY && plane && (s->avctx->flags & CODEC_FLAG_GRAY)) + continue; + +- +- if(FFABS(stride) > 2048) +- return; //various tables are fixed size +- + /* for each superblock row in the slice (both of them)... */ + for (; sb_y < slice_height; sb_y++) { + +@@ -1390,8 +1495,9 @@ + for (j = 0; j < 16; j++) { + x = 4*sb_x + hilbert_offset[j][0]; + y = 4*sb_y + hilbert_offset[j][1]; ++ fragment = y*fragment_width + x; + +- i = fragment_start + y*fragment_width + x; ++ i = fragment_start + fragment; + + // bounds check + if (x >= fragment_width || y >= fragment_height) +@@ -1399,6 +1505,9 @@ + + first_pixel = 8*y*stride + 8*x; + ++ if (do_await && s->all_fragments[i].coding_method != MODE_INTRA) ++ await_reference_row(s, &s->all_fragments[i], motion_val[fragment][1], (16*y) >> s->chroma_y_shift); ++ + /* transform if this block was coded */ + if (s->all_fragments[i].coding_method != MODE_COPY) { + if ((s->all_fragments[i].coding_method == MODE_USING_GOLDEN) || +@@ -1415,8 +1524,8 @@ + if ((s->all_fragments[i].coding_method > MODE_INTRA) && + (s->all_fragments[i].coding_method != MODE_USING_GOLDEN)) { + int src_x, src_y; +- motion_x = motion_val[y*fragment_width + x][0]; +- motion_y = motion_val[y*fragment_width + x][1]; ++ motion_x = motion_val[fragment][0]; ++ motion_y = motion_val[fragment][1]; + + src_x= (motion_x>>1) + 8*x; + src_y= (motion_y>>1) + 8*y; +@@ -1429,8 +1538,7 @@ + + if(src_x<0 || src_y<0 || src_x + 9 >= plane_width || src_y + 9 >= plane_height){ + uint8_t *temp= s->edge_emu_buffer; +- if(stride<0) temp -= 9*stride; +- else temp += 9*stride; ++ if(stride<0) temp -= 8*stride; + + s->dsp.emulated_edge_mc(temp, motion_source, stride, 9, 9, src_x, src_y, plane_width, plane_height); + motion_source= temp; +@@ -1510,9 +1618,38 @@ + vp3_draw_horiz_band(s, FFMIN((32 << s->chroma_y_shift) * (slice + 1) -16, s->height-16)); + } + +-/* +- * This is the ffmpeg/libavcodec API init function. +- */ ++/// Allocate tables for per-frame data in Vp3DecodeContext ++static av_cold int allocate_tables(AVCodecContext *avctx) ++{ ++ Vp3DecodeContext *s = avctx->priv_data; ++ int y_fragment_count, c_fragment_count; ++ ++ y_fragment_count = s->fragment_width[0] * s->fragment_height[0]; ++ c_fragment_count = s->fragment_width[1] * s->fragment_height[1]; ++ ++ s->superblock_coding = av_malloc(s->superblock_count); ++ s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); ++ s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int)); ++ s->dct_tokens_base = av_malloc(64*s->fragment_count * sizeof(*s->dct_tokens_base)); ++ s->motion_val[0] = av_malloc(y_fragment_count * sizeof(*s->motion_val[0])); ++ s->motion_val[1] = av_malloc(c_fragment_count * sizeof(*s->motion_val[1])); ++ ++ /* work out the block mapping tables */ ++ s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); ++ s->macroblock_coding = av_malloc(s->macroblock_count + 1); ++ ++ if (!s->superblock_coding || !s->all_fragments || !s->dct_tokens_base || ++ !s->coded_fragment_list[0] || !s->superblock_fragments || !s->macroblock_coding || ++ !s->motion_val[0] || !s->motion_val[1]) { ++ vp3_decode_end(avctx); ++ return -1; ++ } ++ ++ init_block_mapping(s); ++ ++ return 0; ++} ++ + static av_cold int vp3_decode_init(AVCodecContext *avctx) + { + Vp3DecodeContext *s = avctx->priv_data; +@@ -1559,7 +1696,6 @@ + s->superblock_count = s->y_superblock_count + (s->c_superblock_count * 2); + s->u_superblock_start = s->y_superblock_count; + s->v_superblock_start = s->u_superblock_start + s->c_superblock_count; +- s->superblock_coding = av_malloc(s->superblock_count); + + s->macroblock_width = (s->width + 15) / 16; + s->macroblock_height = (s->height + 15) / 16; +@@ -1577,18 +1713,6 @@ + s->fragment_start[1] = y_fragment_count; + s->fragment_start[2] = y_fragment_count + c_fragment_count; + +- s->all_fragments = av_malloc(s->fragment_count * sizeof(Vp3Fragment)); +- s->coded_fragment_list[0] = av_malloc(s->fragment_count * sizeof(int)); +- s->dct_tokens_base = av_malloc(64*s->fragment_count * sizeof(*s->dct_tokens_base)); +- s->motion_val[0] = av_malloc(y_fragment_count * sizeof(*s->motion_val[0])); +- s->motion_val[1] = av_malloc(c_fragment_count * sizeof(*s->motion_val[1])); +- +- if (!s->superblock_coding || !s->all_fragments || !s->dct_tokens_base || +- !s->coded_fragment_list[0] || !s->motion_val[0] || !s->motion_val[1]) { +- vp3_decode_end(avctx); +- return -1; +- } +- + if (!s->theora_tables) + { + for (i = 0; i < 64; i++) { +@@ -1688,31 +1812,95 @@ + &motion_vector_vlc_table[0][1], 2, 1, + &motion_vector_vlc_table[0][0], 2, 1, 0); + +- /* work out the block mapping tables */ +- s->superblock_fragments = av_malloc(s->superblock_count * 16 * sizeof(int)); +- s->macroblock_coding = av_malloc(s->macroblock_count + 1); +- if (!s->superblock_fragments || !s->macroblock_coding) { +- vp3_decode_end(avctx); +- return -1; +- } +- init_block_mapping(s); +- + for (i = 0; i < 3; i++) { + s->current_frame.data[i] = NULL; + s->last_frame.data[i] = NULL; + s->golden_frame.data[i] = NULL; + } + +- return 0; ++ return allocate_tables(avctx); + + vlc_fail: + av_log(avctx, AV_LOG_FATAL, "Invalid huffman table\n"); + return -1; + } + +-/* +- * This is the ffmpeg/libavcodec API frame decode function. +- */ ++/// Release and shuffle frames after decode finishes ++static void update_frames(AVCodecContext *avctx) ++{ ++ Vp3DecodeContext *s = avctx->priv_data; ++ ++ /* release the last frame, if it is allocated and if it is not the ++ * golden frame */ ++ if (s->last_frame.data[0] && s->last_frame.type != FF_BUFFER_TYPE_COPY) ++ ff_thread_release_buffer(avctx, &s->last_frame); ++ ++ /* shuffle frames (last = current) */ ++ s->last_frame= s->current_frame; ++ ++ if (s->keyframe) { ++ if (s->golden_frame.data[0]) ++ ff_thread_release_buffer(avctx, &s->golden_frame); ++ s->golden_frame = s->current_frame; ++ s->last_frame.type = FF_BUFFER_TYPE_COPY; ++ } ++ ++ s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ ++} ++ ++static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) ++{ ++ Vp3DecodeContext *s = dst->priv_data, *s1 = src->priv_data; ++ int qps_changed = 0, i, err; ++ ++#define copy_fields(to, from, start_field, end_field) memcpy(&to->start_field, &from->start_field, (char*)&to->end_field - (char*)&to->start_field) ++ ++ if (!s1->current_frame.data[0] ++ ||s->width != s1->width ++ ||s->height!= s1->height) { ++ if (s != s1) ++ copy_fields(s, s1, golden_frame, keyframe); ++ return -1; ++ } ++ ++ if (s != s1) { ++ // init tables if the first frame hasn't been decoded ++ if (!s->current_frame.data[0]) { ++ int y_fragment_count, c_fragment_count; ++ s->avctx = dst; ++ err = allocate_tables(dst); ++ if (err) ++ return err; ++ y_fragment_count = s->fragment_width[0] * s->fragment_height[0]; ++ c_fragment_count = s->fragment_width[1] * s->fragment_height[1]; ++ memcpy(s->motion_val[0], s1->motion_val[0], y_fragment_count * sizeof(*s->motion_val[0])); ++ memcpy(s->motion_val[1], s1->motion_val[1], c_fragment_count * sizeof(*s->motion_val[1])); ++ } ++ ++ // copy previous frame data ++ copy_fields(s, s1, golden_frame, dsp); ++ ++ // copy qscale data if necessary ++ for (i = 0; i < 3; i++) { ++ if (s->qps[i] != s1->qps[1]) { ++ qps_changed = 1; ++ memcpy(&s->qmat[i], &s1->qmat[i], sizeof(s->qmat[i])); ++ } ++ } ++ ++ if (s->qps[0] != s1->qps[0]) ++ memcpy(&s->bounding_values_array, &s1->bounding_values_array, sizeof(s->bounding_values_array)); ++ ++ if (qps_changed) ++ copy_fields(s, s1, qps, superblock_count); ++#undef copy_fields ++ } ++ ++ update_frames(dst); ++ ++ return 0; ++} ++ + static int vp3_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + AVPacket *avpkt) +@@ -1764,13 +1952,16 @@ + return buf_size; + + s->current_frame.reference = 3; +- s->current_frame.pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE; ++ s->current_frame.pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + s->current_frame.key_frame = s->keyframe; +- if (avctx->get_buffer(avctx, &s->current_frame) < 0) { ++ if (ff_thread_get_buffer(avctx, &s->current_frame) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto error; + } + ++ if (!s->edge_emu_buffer) ++ s->edge_emu_buffer = av_malloc(9*FFABS(s->current_frame.linesize[0])); ++ + if (s->keyframe) { + if (!s->theora) + { +@@ -1794,20 +1985,19 @@ + av_log(s->avctx, AV_LOG_WARNING, "vp3: first frame not a keyframe\n"); + + s->golden_frame.reference = 3; +- s->golden_frame.pict_type = FF_I_TYPE; +- if (avctx->get_buffer(avctx, &s->golden_frame) < 0) { ++ s->golden_frame.pict_type = AV_PICTURE_TYPE_I; ++ if (ff_thread_get_buffer(avctx, &s->golden_frame) < 0) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + goto error; + } + s->last_frame = s->golden_frame; + s->last_frame.type = FF_BUFFER_TYPE_COPY; ++ ff_thread_report_progress(&s->last_frame, INT_MAX, 0); + } + } + +- s->current_frame.qscale_table= s->qscale_table; //FIXME allocate individual tables per AVFrame +- s->current_frame.qstride= 0; +- + memset(s->all_fragments, 0, s->fragment_count * sizeof(Vp3Fragment)); ++ ff_thread_finish_setup(avctx); + + if (unpack_superblocks(s, &gb)){ + av_log(s->avctx, AV_LOG_ERROR, "error in unpack_superblocks\n"); +@@ -1852,70 +2042,18 @@ + *data_size=sizeof(AVFrame); + *(AVFrame*)data= s->current_frame; + +- /* release the last frame, if it is allocated and if it is not the +- * golden frame */ +- if (s->last_frame.data[0] && s->last_frame.type != FF_BUFFER_TYPE_COPY) +- avctx->release_buffer(avctx, &s->last_frame); +- +- /* shuffle frames (last = current) */ +- s->last_frame= s->current_frame; +- +- if (s->keyframe) { +- if (s->golden_frame.data[0]) +- avctx->release_buffer(avctx, &s->golden_frame); +- s->golden_frame = s->current_frame; +- s->last_frame.type = FF_BUFFER_TYPE_COPY; +- } +- +- s->current_frame.data[0]= NULL; /* ensure that we catch any access to this released frame */ ++ if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME)) ++ update_frames(avctx); + + return buf_size; + + error: +- if (s->current_frame.data[0]) +- avctx->release_buffer(avctx, &s->current_frame); +- return -1; +-} +- +-/* +- * This is the ffmpeg/libavcodec API module cleanup function. +- */ +-static av_cold int vp3_decode_end(AVCodecContext *avctx) +-{ +- Vp3DecodeContext *s = avctx->priv_data; +- int i; +- +- av_free(s->superblock_coding); +- av_free(s->all_fragments); +- av_free(s->coded_fragment_list[0]); +- av_free(s->dct_tokens_base); +- av_free(s->superblock_fragments); +- av_free(s->macroblock_coding); +- av_free(s->motion_val[0]); +- av_free(s->motion_val[1]); +- +- for (i = 0; i < 16; i++) { +- free_vlc(&s->dc_vlc[i]); +- free_vlc(&s->ac_vlc_1[i]); +- free_vlc(&s->ac_vlc_2[i]); +- free_vlc(&s->ac_vlc_3[i]); +- free_vlc(&s->ac_vlc_4[i]); +- } +- +- free_vlc(&s->superblock_run_length_vlc); +- free_vlc(&s->fragment_run_length_vlc); +- free_vlc(&s->mode_code_vlc); +- free_vlc(&s->motion_vector_vlc); ++ ff_thread_report_progress(&s->current_frame, INT_MAX, 0); + +- /* release all frames */ +- if (s->golden_frame.data[0]) +- avctx->release_buffer(avctx, &s->golden_frame); +- if (s->last_frame.data[0] && s->last_frame.type != FF_BUFFER_TYPE_COPY) +- avctx->release_buffer(avctx, &s->last_frame); +- /* no need to release the current_frame since it will always be pointing +- * to the same frame as either the golden or last frame */ ++ if (!HAVE_THREADS || !(s->avctx->active_thread_type&FF_THREAD_FRAME)) ++ avctx->release_buffer(avctx, &s->current_frame); + +- return 0; ++ return -1; + } + + static int read_huffman_tree(AVCodecContext *avctx, GetBitContext *gb) +@@ -1952,6 +2090,23 @@ + return 0; + } + ++static int vp3_init_thread_copy(AVCodecContext *avctx) ++{ ++ Vp3DecodeContext *s = avctx->priv_data; ++ ++ s->superblock_coding = NULL; ++ s->all_fragments = NULL; ++ s->coded_fragment_list[0] = NULL; ++ s->dct_tokens_base = NULL; ++ s->superblock_fragments = NULL; ++ s->macroblock_coding = NULL; ++ s->motion_val[0] = NULL; ++ s->motion_val[1] = NULL; ++ s->edge_emu_buffer = NULL; ++ ++ return 0; ++} ++ + #if CONFIG_THEORA_DECODER + static const enum PixelFormat theora_pix_fmts[4] = { + PIX_FMT_YUV420P, PIX_FMT_NONE, PIX_FMT_YUV422P, PIX_FMT_YUV444P +@@ -2167,7 +2322,7 @@ + return -1; + } + +- if (ff_split_xiph_headers(avctx->extradata, avctx->extradata_size, ++ if (avpriv_split_xiph_headers(avctx->extradata, avctx->extradata_size, + 42, header_start, header_len) < 0) { + av_log(avctx, AV_LOG_ERROR, "Corrupt extradata\n"); + return -1; +@@ -2214,30 +2369,32 @@ + } + + AVCodec ff_theora_decoder = { +- "theora", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_THEORA, +- sizeof(Vp3DecodeContext), +- theora_decode_init, +- NULL, +- vp3_decode_end, +- vp3_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, +- NULL, ++ .name = "theora", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_THEORA, ++ .priv_data_size = sizeof(Vp3DecodeContext), ++ .init = theora_decode_init, ++ .close = vp3_decode_end, ++ .decode = vp3_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS, ++ .flush = vp3_decode_flush, + .long_name = NULL_IF_CONFIG_SMALL("Theora"), ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context) + }; + #endif + + AVCodec ff_vp3_decoder = { +- "vp3", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP3, +- sizeof(Vp3DecodeContext), +- vp3_decode_init, +- NULL, +- vp3_decode_end, +- vp3_decode_frame, +- CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND, +- NULL, ++ .name = "vp3", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP3, ++ .priv_data_size = sizeof(Vp3DecodeContext), ++ .init = vp3_decode_init, ++ .close = vp3_decode_end, ++ .decode = vp3_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_FRAME_THREADS, ++ .flush = vp3_decode_flush, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP3"), ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp3_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(vp3_update_thread_context) + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3dsp.c 2012-05-14 14:08:54.434341994 +0200 +@@ -41,7 +41,6 @@ + static av_always_inline void idct(uint8_t *dst, int stride, int16_t *input, int type) + { + int16_t *ip = input; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + + int A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H; + int Ed, Gd, Add, Bdd, Fd, Hd; +@@ -147,29 +146,29 @@ + ip[5*8] = (Fd + Bdd ) >> 4; + ip[6*8] = (Fd - Bdd ) >> 4; + }else if(type==1){ +- dst[0*stride] = cm[(Gd + Cd ) >> 4]; +- dst[7*stride] = cm[(Gd - Cd ) >> 4]; ++ dst[0*stride] = av_clip_uint8((Gd + Cd ) >> 4); ++ dst[7*stride] = av_clip_uint8((Gd - Cd ) >> 4); + +- dst[1*stride] = cm[(Add + Hd ) >> 4]; +- dst[2*stride] = cm[(Add - Hd ) >> 4]; ++ dst[1*stride] = av_clip_uint8((Add + Hd ) >> 4); ++ dst[2*stride] = av_clip_uint8((Add - Hd ) >> 4); + +- dst[3*stride] = cm[(Ed + Dd ) >> 4]; +- dst[4*stride] = cm[(Ed - Dd ) >> 4]; ++ dst[3*stride] = av_clip_uint8((Ed + Dd ) >> 4); ++ dst[4*stride] = av_clip_uint8((Ed - Dd ) >> 4); + +- dst[5*stride] = cm[(Fd + Bdd ) >> 4]; +- dst[6*stride] = cm[(Fd - Bdd ) >> 4]; ++ dst[5*stride] = av_clip_uint8((Fd + Bdd ) >> 4); ++ dst[6*stride] = av_clip_uint8((Fd - Bdd ) >> 4); + }else{ +- dst[0*stride] = cm[dst[0*stride] + ((Gd + Cd ) >> 4)]; +- dst[7*stride] = cm[dst[7*stride] + ((Gd - Cd ) >> 4)]; ++ dst[0*stride] = av_clip_uint8(dst[0*stride] + ((Gd + Cd ) >> 4)); ++ dst[7*stride] = av_clip_uint8(dst[7*stride] + ((Gd - Cd ) >> 4)); + +- dst[1*stride] = cm[dst[1*stride] + ((Add + Hd ) >> 4)]; +- dst[2*stride] = cm[dst[2*stride] + ((Add - Hd ) >> 4)]; ++ dst[1*stride] = av_clip_uint8(dst[1*stride] + ((Add + Hd ) >> 4)); ++ dst[2*stride] = av_clip_uint8(dst[2*stride] + ((Add - Hd ) >> 4)); + +- dst[3*stride] = cm[dst[3*stride] + ((Ed + Dd ) >> 4)]; +- dst[4*stride] = cm[dst[4*stride] + ((Ed - Dd ) >> 4)]; ++ dst[3*stride] = av_clip_uint8(dst[3*stride] + ((Ed + Dd ) >> 4)); ++ dst[4*stride] = av_clip_uint8(dst[4*stride] + ((Ed - Dd ) >> 4)); + +- dst[5*stride] = cm[dst[5*stride] + ((Fd + Bdd ) >> 4)]; +- dst[6*stride] = cm[dst[6*stride] + ((Fd - Bdd ) >> 4)]; ++ dst[5*stride] = av_clip_uint8(dst[5*stride] + ((Fd + Bdd ) >> 4)); ++ dst[6*stride] = av_clip_uint8(dst[6*stride] + ((Fd - Bdd ) >> 4)); + } + + } else { +@@ -190,18 +189,18 @@ + dst[4*stride]= + dst[5*stride]= + dst[6*stride]= +- dst[7*stride]= cm[128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20)]; ++ dst[7*stride]= av_clip_uint8(128 + ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20)); + }else{ + if(ip[0*8]){ + int v= ((xC4S4 * ip[0*8] + (IdctAdjustBeforeShift<<16))>>20); +- dst[0*stride] = cm[dst[0*stride] + v]; +- dst[1*stride] = cm[dst[1*stride] + v]; +- dst[2*stride] = cm[dst[2*stride] + v]; +- dst[3*stride] = cm[dst[3*stride] + v]; +- dst[4*stride] = cm[dst[4*stride] + v]; +- dst[5*stride] = cm[dst[5*stride] + v]; +- dst[6*stride] = cm[dst[6*stride] + v]; +- dst[7*stride] = cm[dst[7*stride] + v]; ++ dst[0*stride] = av_clip_uint8(dst[0*stride] + v); ++ dst[1*stride] = av_clip_uint8(dst[1*stride] + v); ++ dst[2*stride] = av_clip_uint8(dst[2*stride] + v); ++ dst[3*stride] = av_clip_uint8(dst[3*stride] + v); ++ dst[4*stride] = av_clip_uint8(dst[4*stride] + v); ++ dst[5*stride] = av_clip_uint8(dst[5*stride] + v); ++ dst[6*stride] = av_clip_uint8(dst[6*stride] + v); ++ dst[7*stride] = av_clip_uint8(dst[7*stride] + v); + } + } + } +@@ -225,17 +224,16 @@ + + void ff_vp3_idct_dc_add_c(uint8_t *dest/*align 8*/, int line_size, const DCTELEM *block/*align 16*/){ + int i, dc = (block[0] + 15) >> 5; +- const uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + dc; + + for(i = 0; i < 8; i++){ +- dest[0] = cm[dest[0]]; +- dest[1] = cm[dest[1]]; +- dest[2] = cm[dest[2]]; +- dest[3] = cm[dest[3]]; +- dest[4] = cm[dest[4]]; +- dest[5] = cm[dest[5]]; +- dest[6] = cm[dest[6]]; +- dest[7] = cm[dest[7]]; ++ dest[0] = av_clip_uint8(dest[0] + dc); ++ dest[1] = av_clip_uint8(dest[1] + dc); ++ dest[2] = av_clip_uint8(dest[2] + dc); ++ dest[3] = av_clip_uint8(dest[3] + dc); ++ dest[4] = av_clip_uint8(dest[4] + dc); ++ dest[5] = av_clip_uint8(dest[5] + dc); ++ dest[6] = av_clip_uint8(dest[6] + dc); ++ dest[7] = av_clip_uint8(dest[7] + dc); + dest += line_size; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp3_parser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp3_parser.c 2012-05-14 14:08:54.378340868 +0200 +@@ -26,9 +26,9 @@ + const uint8_t *buf, int buf_size) + { + if(avctx->codec_id == CODEC_ID_THEORA) +- s->pict_type= (buf[0]&0x40) ? FF_P_TYPE : FF_I_TYPE; ++ s->pict_type= (buf[0]&0x40) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; + else +- s->pict_type= (buf[0]&0x80) ? FF_P_TYPE : FF_I_TYPE; ++ s->pict_type= (buf[0]&0x80) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; + + *poutbuf = buf; + *poutbuf_size = buf_size; +@@ -36,9 +36,7 @@ + } + + AVCodecParser ff_vp3_parser = { +- { CODEC_ID_THEORA, CODEC_ID_VP3, +- CODEC_ID_VP6, CODEC_ID_VP6F, CODEC_ID_VP6A }, +- 0, +- NULL, +- parse, ++ .codec_ids = { CODEC_ID_THEORA, CODEC_ID_VP3, CODEC_ID_VP6, ++ CODEC_ID_VP6F, CODEC_ID_VP6A }, ++ .parser_parse = parse, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56.c 2012-05-14 14:08:54.436342034 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 and VP6 compatible video decoder (common features) +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 and VP6 compatible video decoder (common features) ++ */ ++ + #include "avcodec.h" + #include "bytestream.h" + +@@ -399,6 +401,8 @@ + + frame_current = s->framep[VP56_FRAME_CURRENT]; + frame_ref = s->framep[ref_frame]; ++ if (mb_type != VP56_MB_INTRA && !frame_ref->data[0]) ++ return; + + ab = 6*is_alpha; + b_max = 6 - 2*is_alpha; +@@ -463,6 +467,7 @@ + s->mb_height = (avctx->coded_height+15) / 16; + + if (s->mb_width > 1000 || s->mb_height > 1000) { ++ avcodec_set_dimensions(avctx, 0, 0); + av_log(avctx, AV_LOG_ERROR, "picture too big\n"); + return -1; + } +@@ -511,8 +516,20 @@ + if (!res) + return -1; + ++ if (res == 2) { ++ int i; ++ for (i = 0; i < 4; i++) { ++ if (s->frames[i].data[0]) ++ avctx->release_buffer(avctx, &s->frames[i]); ++ } ++ if (is_alpha) { ++ avcodec_set_dimensions(avctx, 0, 0); ++ return -1; ++ } ++ } ++ + if (!is_alpha) { +- p->reference = 1; ++ p->reference = 3; + if (avctx->get_buffer(avctx, p) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; +@@ -526,18 +543,19 @@ + } + + if (p->key_frame) { +- p->pict_type = FF_I_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_I; + s->default_models_init(s); + for (block=0; blockmb_height*s->mb_width; block++) + s->macroblocks[block].type = VP56_MB_INTRA; + } else { +- p->pict_type = FF_P_TYPE; ++ p->pict_type = AV_PICTURE_TYPE_P; + vp56_parse_mb_type_models(s); + s->parse_vector_models(s); + s->mb_type = VP56_MB_INTER_NOVEC_PF; + } + +- s->parse_coeff_models(s); ++ if (s->parse_coeff_models(s)) ++ goto next; + + memset(s->prev_dc, 0, sizeof(s->prev_dc)); + s->prev_dc[1][VP56_FRAME_CURRENT] = 128; +@@ -601,6 +619,7 @@ + } + } + ++ next: + if (p->key_frame || golden_frame) { + if (s->framep[VP56_FRAME_GOLDEN]->data[0] && + s->framep[VP56_FRAME_GOLDEN] != s->framep[VP56_FRAME_GOLDEN2]) +@@ -653,8 +672,10 @@ + ff_vp56dsp_init(&s->vp56dsp, avctx->codec->id); + ff_init_scantable(s->dsp.idct_permutation, &s->scantable,ff_zigzag_direct); + +- for (i=0; i<4; i++) ++ for (i=0; i<4; i++) { + s->framep[i] = &s->frames[i]; ++ avcodec_get_frame_defaults(&s->frames[i]); ++ } + s->framep[VP56_FRAME_UNUSED] = s->framep[VP56_FRAME_GOLDEN]; + s->framep[VP56_FRAME_UNUSED2] = s->framep[VP56_FRAME_GOLDEN2]; + s->edge_emu_buffer_alloc = NULL; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56data.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56data.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56data.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56data.c 2012-05-14 14:08:54.438342074 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 and VP6 compatible video decoder (common data) +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 and VP6 compatible video decoder (common data) ++ */ ++ + #include "vp56data.h" + + const uint8_t vp56_b2p[] = { 0, 0, 0, 0, 1, 2, 3, 3, 3, 3 }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56data.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56data.h 2012-05-14 14:08:54.439342095 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 and VP6 compatible video decoder (common data) +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 and VP6 compatible video decoder (common data) ++ */ ++ + #ifndef AVCODEC_VP56DATA_H + #define AVCODEC_VP56DATA_H + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp56.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp56.h 2012-05-14 14:08:54.437342054 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 and VP6 compatible video decoder (common features) +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 and VP6 compatible video decoder (common features) ++ */ ++ + #ifndef AVCODEC_VP56_H + #define AVCODEC_VP56_H + +@@ -28,7 +30,6 @@ + #include "dsputil.h" + #include "get_bits.h" + #include "bytestream.h" +-#include "cabac.h" + #include "vp56dsp.h" + + typedef struct vp56_context VP56Context; +@@ -46,7 +47,7 @@ + typedef void (*VP56ParseCoeff)(VP56Context *s); + typedef void (*VP56DefaultModelsInit)(VP56Context *s); + typedef void (*VP56ParseVectorModels)(VP56Context *s); +-typedef void (*VP56ParseCoeffModels)(VP56Context *s); ++typedef int (*VP56ParseCoeffModels)(VP56Context *s); + typedef int (*VP56ParseHeader)(VP56Context *s, const uint8_t *buf, + int buf_size, int *golden_frame); + +@@ -201,7 +202,9 @@ + return code_word; + } + +-#if ARCH_X86 ++#if ARCH_ARM ++#include "arm/vp56_arith.h" ++#elif ARCH_X86 + #include "x86/vp56_arith.h" + #endif + +@@ -221,6 +224,7 @@ + } + #endif + ++#ifndef vp56_rac_get_prob_branchy + // branchy variant, to be used where there's a branch based on the bit decoded + static av_always_inline int vp56_rac_get_prob_branchy(VP56RangeCoder *c, int prob) + { +@@ -238,6 +242,7 @@ + c->code_word = code_word; + return 0; + } ++#endif + + static av_always_inline int vp56_rac_get(VP56RangeCoder *c) + { +@@ -328,15 +333,13 @@ + return -tree->val; + } + +-/** +- * This is identical to vp8_rac_get_tree except for the possibility of starting +- * on a node other than the root node, needed for coeff decode where this is +- * used to save a bit after a 0 token (by disallowing EOB to immediately follow.) +- */ +-static av_always_inline +-int vp8_rac_get_tree_with_offset(VP56RangeCoder *c, const int8_t (*tree)[2], +- const uint8_t *probs, int i) ++// how probabilities are associated with decisions is different I think ++// well, the new scheme fits in the old but this way has one fewer branches per decision ++static av_always_inline int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2], ++ const uint8_t *probs) + { ++ int i = 0; ++ + do { + i = tree[i][vp56_rac_get_prob(c, probs[i])]; + } while (i > 0); +@@ -344,15 +347,6 @@ + return -i; + } + +-// how probabilities are associated with decisions is different I think +-// well, the new scheme fits in the old but this way has one fewer branches per decision +-static av_always_inline +-int vp8_rac_get_tree(VP56RangeCoder *c, const int8_t (*tree)[2], +- const uint8_t *probs) +-{ +- return vp8_rac_get_tree_with_offset(c, tree, probs, 0); +-} +- + // DCTextra + static av_always_inline int vp8_rac_get_coeff(VP56RangeCoder *c, const uint8_t *prob) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp5.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp5.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp5.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp5.c 2012-05-14 14:08:54.435342014 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 compatible video decoder +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 compatible video decoder ++ */ ++ + #include + #include + +@@ -55,6 +57,11 @@ + } + rows = vp56_rac_gets(c, 8); /* number of stored macroblock rows */ + cols = vp56_rac_gets(c, 8); /* number of stored macroblock cols */ ++ if (!rows || !cols) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", ++ cols << 4, rows << 4); ++ return 0; ++ } + vp56_rac_gets(c, 8); /* number of displayed macroblock rows */ + vp56_rac_gets(c, 8); /* number of displayed macroblock cols */ + vp56_rac_gets(c, 2); +@@ -116,7 +123,7 @@ + model->vector_pdv[comp][node] = vp56_rac_gets_nn(c, 7); + } + +-static void vp5_parse_coeff_models(VP56Context *s) ++static int vp5_parse_coeff_models(VP56Context *s) + { + VP56RangeCoder *c = &s->c; + VP56Model *model = s->modelp; +@@ -160,6 +167,7 @@ + for (ctx=0; ctx<6; ctx++) + for (node=0; node<5; node++) + model->coeff_acct[pt][ct][cg][ctx][node] = av_clip(((model->coeff_ract[pt][ct][cg][node] * vp5_ract_lc[ct][cg][node][ctx][0] + 128) >> 8) + vp5_ract_lc[ct][cg][node][ctx][1], 1, 254); ++ return 0; + } + + static void vp5_parse_coeff(VP56Context *s) +@@ -182,7 +190,8 @@ + model1 = model->coeff_dccv[pt]; + model2 = model->coeff_dcct[pt][ctx]; + +- for (coeff_idx=0; coeff_idx<64; ) { ++ coeff_idx = 0; ++ for (;;) { + if (vp56_rac_get_prob(c, model2[0])) { + if (vp56_rac_get_prob(c, model2[2])) { + if (vp56_rac_get_prob(c, model2[3])) { +@@ -219,8 +228,11 @@ + ct = 0; + s->coeff_ctx[vp56_b6to4[b]][coeff_idx] = 0; + } ++ coeff_idx++; ++ if (coeff_idx >= 64) ++ break; + +- cg = vp5_coeff_groups[++coeff_idx]; ++ cg = vp5_coeff_groups[coeff_idx]; + ctx = s->coeff_ctx[vp56_b6to4[b]][coeff_idx]; + model1 = model->coeff_ract[pt][ct][cg]; + model2 = cg > 2 ? model1 : model->coeff_acct[pt][ct][cg][ctx]; +@@ -267,14 +279,13 @@ + } + + AVCodec ff_vp5_decoder = { +- "vp5", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP5, +- sizeof(VP56Context), +- vp5_decode_init, +- NULL, +- ff_vp56_free, +- ff_vp56_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vp5", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP5, ++ .priv_data_size = sizeof(VP56Context), ++ .init = vp5_decode_init, ++ .close = ff_vp56_free, ++ .decode = ff_vp56_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP5"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp5data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp5data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp5data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp5data.h 2012-05-14 14:08:54.440342116 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP5 compatible video decoder +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP5 compatible video decoder ++ */ ++ + #ifndef AVCODEC_VP5DATA_H + #define AVCODEC_VP5DATA_H + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6.c 2012-05-14 14:08:54.441342136 +0200 +@@ -1,13 +1,6 @@ +-/** +- * @file +- * VP6 compatible video decoder +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * +- * The VP6F decoder accepts an optional 1 byte extradata. It is composed of: +- * - upper 4bits: difference between encoded width and visible width +- * - lower 4bits: difference between encoded height and visible height +- * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or +@@ -25,6 +18,15 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP6 compatible video decoder ++ * ++ * The VP6F decoder accepts an optional 1 byte extradata. It is composed of: ++ * - upper 4 bits: difference between encoded width and visible width ++ * - lower 4 bits: difference between encoded height and visible height ++ */ ++ + #include + + #include "avcodec.h" +@@ -75,6 +77,10 @@ + cols = buf[3]; /* number of stored macroblock cols */ + /* buf[4] is number of displayed macroblock rows */ + /* buf[5] is number of displayed macroblock cols */ ++ if (!rows || !cols) { ++ av_log(s->avctx, AV_LOG_ERROR, "Invalid size %dx%d\n", cols << 4, rows << 4); ++ return 0; ++ } + + if (!s->macroblocks || /* first frame */ + 16*cols != s->avctx->coded_width || +@@ -95,7 +101,7 @@ + vrt_shift = 5; + s->sub_version = sub_version; + } else { +- if (!s->sub_version) ++ if (!s->sub_version || !s->avctx->coded_width || !s->avctx->coded_height) + return 0; + + if (separated_coeff || !s->filter_header) { +@@ -137,8 +143,11 @@ + if (coeff_offset) { + buf += coeff_offset; + buf_size -= coeff_offset; +- if (buf_size < 0) ++ if (buf_size < 0) { ++ if (s->framep[VP56_FRAME_CURRENT]->key_frame) ++ avcodec_set_dimensions(s->avctx, 0, 0); + return 0; ++ } + if (s->use_huffman) { + s->parse_coeff = vp6_parse_coeff_huffman; + init_get_bits(&s->gb, buf, buf_size<<3); +@@ -213,8 +222,8 @@ + return (a->count - b->count)*16 + (b->sym - a->sym); + } + +-static void vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], +- const uint8_t *map, unsigned size, VLC *vlc) ++static int vp6_build_huff_tree(VP56Context *s, uint8_t coeff_model[], ++ const uint8_t *map, unsigned size, VLC *vlc) + { + Node nodes[2*VP6_MAX_HUFF_SIZE], *tmp = &nodes[size]; + int a, b, i; +@@ -229,12 +238,12 @@ + } + + free_vlc(vlc); +- /* then build the huffman tree accodring to probabilities */ +- ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, +- FF_HUFFMAN_FLAG_HNODE_FIRST); ++ /* then build the huffman tree according to probabilities */ ++ return ff_huff_build_tree(s->avctx, vlc, size, nodes, vp6_huff_cmp, ++ FF_HUFFMAN_FLAG_HNODE_FIRST); + } + +-static void vp6_parse_coeff_models(VP56Context *s) ++static int vp6_parse_coeff_models(VP56Context *s) + { + VP56RangeCoder *c = &s->c; + VP56Model *model = s->modelp; +@@ -279,15 +288,18 @@ + + if (s->use_huffman) { + for (pt=0; pt<2; pt++) { +- vp6_build_huff_tree(s, model->coeff_dccv[pt], +- vp6_huff_coeff_map, 12, &s->dccv_vlc[pt]); +- vp6_build_huff_tree(s, model->coeff_runv[pt], +- vp6_huff_run_map, 9, &s->runv_vlc[pt]); ++ if (vp6_build_huff_tree(s, model->coeff_dccv[pt], ++ vp6_huff_coeff_map, 12, &s->dccv_vlc[pt])) ++ return -1; ++ if (vp6_build_huff_tree(s, model->coeff_runv[pt], ++ vp6_huff_run_map, 9, &s->runv_vlc[pt])) ++ return -1; + for (ct=0; ct<3; ct++) + for (cg = 0; cg < 6; cg++) +- vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], +- vp6_huff_coeff_map, 12, +- &s->ract_vlc[pt][ct][cg]); ++ if (vp6_build_huff_tree(s, model->coeff_ract[pt][ct][cg], ++ vp6_huff_coeff_map, 12, ++ &s->ract_vlc[pt][ct][cg])) ++ return -1; + } + memset(s->nb_null, 0, sizeof(s->nb_null)); + } else { +@@ -297,6 +309,7 @@ + for (node=0; node<5; node++) + model->coeff_dcct[pt][ctx][node] = av_clip(((model->coeff_dccv[pt][node] * vp6_dccv_lc[ctx][node][0] + 128) >> 8) + vp6_dccv_lc[ctx][node][1], 1, 255); + } ++ return 0; + } + + static void vp6_parse_vector_adjustment(VP56Context *s, VP56mv *vect) +@@ -367,14 +380,14 @@ + if (b > 3) pt = 1; + vlc_coeff = &s->dccv_vlc[pt]; + +- for (coeff_idx=0; coeff_idx<64; ) { ++ for (coeff_idx = 0;;) { + int run = 1; + if (coeff_idx<2 && s->nb_null[coeff_idx][pt]) { + s->nb_null[coeff_idx][pt]--; + if (coeff_idx) + break; + } else { +- if (get_bits_count(&s->gb) >= s->gb.size_in_bits) ++ if (get_bits_left(&s->gb) <= 0) + return; + coeff = get_vlc2(&s->gb, vlc_coeff->table, 9, 3); + if (coeff == 0) { +@@ -404,6 +417,8 @@ + } + } + coeff_idx+=run; ++ if (coeff_idx >= 64) ++ break; + cg = FFMIN(vp6_coeff_groups[coeff_idx], 3); + vlc_coeff = &s->ract_vlc[pt][ct][cg]; + } +@@ -431,7 +446,8 @@ + model1 = model->coeff_dccv[pt]; + model2 = model->coeff_dcct[pt][ctx]; + +- for (coeff_idx=0; coeff_idx<64; ) { ++ coeff_idx = 0; ++ for (;;) { + if ((coeff_idx>1 && ct==0) || vp56_rac_get_prob(c, model2[0])) { + /* parse a coeff */ + if (vp56_rac_get_prob(c, model2[2])) { +@@ -472,8 +488,10 @@ + run += vp56_rac_get_prob(c, model3[i+8]) << i; + } + } +- +- cg = vp6_coeff_groups[coeff_idx+=run]; ++ coeff_idx += run; ++ if (coeff_idx >= 64) ++ break; ++ cg = vp6_coeff_groups[coeff_idx]; + model1 = model2 = model->coeff_ract[pt][ct][cg]; + } + +@@ -607,42 +625,39 @@ + } + + AVCodec ff_vp6_decoder = { +- "vp6", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP6, +- sizeof(VP56Context), +- vp6_decode_init, +- NULL, +- vp6_decode_free, +- ff_vp56_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vp6", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP6, ++ .priv_data_size = sizeof(VP56Context), ++ .init = vp6_decode_init, ++ .close = vp6_decode_free, ++ .decode = ff_vp56_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP6"), + }; + + /* flash version, not flipped upside-down */ + AVCodec ff_vp6f_decoder = { +- "vp6f", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP6F, +- sizeof(VP56Context), +- vp6_decode_init, +- NULL, +- vp6_decode_free, +- ff_vp56_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vp6f", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP6F, ++ .priv_data_size = sizeof(VP56Context), ++ .init = vp6_decode_init, ++ .close = vp6_decode_free, ++ .decode = ff_vp56_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version)"), + }; + + /* flash version, not flipped upside-down, with alpha channel */ + AVCodec ff_vp6a_decoder = { +- "vp6a", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP6A, +- sizeof(VP56Context), +- vp6_decode_init, +- NULL, +- vp6_decode_free, +- ff_vp56_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vp6a", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP6A, ++ .priv_data_size = sizeof(VP56Context), ++ .init = vp6_decode_init, ++ .close = vp6_decode_free, ++ .decode = ff_vp56_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP6 (Flash version, with alpha channel)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6data.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6data.h 2012-05-14 14:08:54.442342156 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP6 compatible video decoder +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP6 compatible video decoder ++ */ ++ + #ifndef AVCODEC_VP6DATA_H + #define AVCODEC_VP6DATA_H + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp6dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp6dsp.c 2012-05-14 14:08:54.443342176 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * VP6 DSP-oriented functions +- * ++/* + * Copyright (C) 2006 Aurelien Jacobs + * + * This file is part of FFmpeg. +@@ -21,6 +18,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP6 DSP-oriented functions ++ */ ++ + #include "libavutil/common.h" + #include "vp56dsp.h" + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8.c 2012-05-14 14:08:54.449342296 +0200 +@@ -22,213 +22,101 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" +-#include "vp56.h" ++#include "internal.h" ++#include "vp8.h" + #include "vp8data.h" +-#include "vp8dsp.h" +-#include "h264pred.h" + #include "rectangle.h" ++#include "thread.h" + +-typedef struct { +- uint8_t filter_level; +- uint8_t inner_limit; +- uint8_t inner_filter; +-} VP8FilterStrength; +- +-typedef struct { +- uint8_t skip; +- // todo: make it possible to check for at least (i4x4 or split_mv) +- // in one op. are others needed? +- uint8_t mode; +- uint8_t ref_frame; +- uint8_t partitioning; +- VP56mv mv; +- VP56mv bmv[16]; +-} VP8Macroblock; +- +-typedef struct { +- AVCodecContext *avctx; +- DSPContext dsp; +- VP8DSPContext vp8dsp; +- H264PredContext hpc; +- vp8_mc_func put_pixels_tab[3][3][3]; +- AVFrame frames[4]; +- AVFrame *framep[4]; +- uint8_t *edge_emu_buffer; +- VP56RangeCoder c; ///< header context, includes mb modes and motion vectors +- int profile; +- +- int mb_width; /* number of horizontal MB */ +- int mb_height; /* number of vertical MB */ +- int linesize; +- int uvlinesize; +- +- int keyframe; +- int invisible; +- int update_last; ///< update VP56_FRAME_PREVIOUS with the current one +- int update_golden; ///< VP56_FRAME_NONE if not updated, or which frame to copy if so +- int update_altref; +- int deblock_filter; +- +- /** +- * If this flag is not set, all the probability updates +- * are discarded after this frame is decoded. +- */ +- int update_probabilities; +- +- /** +- * All coefficients are contained in separate arith coding contexts. +- * There can be 1, 2, 4, or 8 of these after the header context. +- */ +- int num_coeff_partitions; +- VP56RangeCoder coeff_partition[8]; +- +- VP8Macroblock *macroblocks; +- VP8Macroblock *macroblocks_base; +- VP8FilterStrength *filter_strength; +- +- uint8_t *intra4x4_pred_mode_top; +- uint8_t intra4x4_pred_mode_left[4]; +- uint8_t *segmentation_map; +- +- /** +- * Cache of the top row needed for intra prediction +- * 16 for luma, 8 for each chroma plane +- */ +- uint8_t (*top_border)[16+8+8]; +- +- /** +- * For coeff decode, we need to know whether the above block had non-zero +- * coefficients. This means for each macroblock, we need data for 4 luma +- * blocks, 2 u blocks, 2 v blocks, and the luma dc block, for a total of 9 +- * per macroblock. We keep the last row in top_nnz. +- */ +- uint8_t (*top_nnz)[9]; +- DECLARE_ALIGNED(8, uint8_t, left_nnz)[9]; +- +- /** +- * This is the index plus one of the last non-zero coeff +- * for each of the blocks in the current macroblock. +- * So, 0 -> no coeffs +- * 1 -> dc-only (special transform) +- * 2+-> full transform +- */ +- DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4]; +- DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16]; +- DECLARE_ALIGNED(16, DCTELEM, block_dc)[16]; +- uint8_t intra4x4_pred_mode_mb[16]; +- +- int chroma_pred_mode; ///< 8x8c pred mode of the current macroblock +- int segment; ///< segment of the current macroblock +- +- int mbskip_enabled; +- int sign_bias[4]; ///< one state [0, 1] per ref frame type +- int ref_count[3]; +- +- /** +- * Base parameters for segmentation, i.e. per-macroblock parameters. +- * These must be kept unchanged even if segmentation is not used for +- * a frame, since the values persist between interframes. +- */ +- struct { +- int enabled; +- int absolute_vals; +- int update_map; +- int8_t base_quant[4]; +- int8_t filter_level[4]; ///< base loop filter level +- } segmentation; +- +- /** +- * Macroblocks can have one of 4 different quants in a frame when +- * segmentation is enabled. +- * If segmentation is disabled, only the first segment's values are used. +- */ +- struct { +- // [0] - DC qmul [1] - AC qmul +- int16_t luma_qmul[2]; +- int16_t luma_dc_qmul[2]; ///< luma dc-only block quant +- int16_t chroma_qmul[2]; +- } qmat[4]; +- +- struct { +- int simple; +- int level; +- int sharpness; +- } filter; +- +- struct { +- int enabled; ///< whether each mb can have a different strength based on mode/ref +- +- /** +- * filter strength adjustment for the following macroblock modes: +- * [0] - i4x4 +- * [1] - zero mv +- * [2] - inter modes except for zero or split mv +- * [3] - split mv +- * i16x16 modes never have any adjustment +- */ +- int8_t mode[4]; +- +- /** +- * filter strength adjustment for macroblocks that reference: +- * [0] - intra / VP56_FRAME_CURRENT +- * [1] - VP56_FRAME_PREVIOUS +- * [2] - VP56_FRAME_GOLDEN +- * [3] - altref / VP56_FRAME_GOLDEN2 +- */ +- int8_t ref[4]; +- } lf_delta; +- +- /** +- * These are all of the updatable probabilities for binary decisions. +- * They are only implictly reset on keyframes, making it quite likely +- * for an interframe to desync if a prior frame's header was corrupt +- * or missing outright! +- */ +- struct { +- uint8_t segmentid[3]; +- uint8_t mbskip; +- uint8_t intra; +- uint8_t last; +- uint8_t golden; +- uint8_t pred16x16[4]; +- uint8_t pred8x8c[3]; +- /* Padded to allow overreads */ +- uint8_t token[4][17][3][NUM_DCT_TOKENS-1]; +- uint8_t mvc[2][19]; +- } prob[2]; +-} VP8Context; ++#if ARCH_ARM ++# include "arm/vp8.h" ++#endif + +-static void vp8_decode_flush(AVCodecContext *avctx) ++static void free_buffers(VP8Context *s) + { +- VP8Context *s = avctx->priv_data; +- int i; +- +- for (i = 0; i < 4; i++) +- if (s->frames[i].data[0]) +- avctx->release_buffer(avctx, &s->frames[i]); +- memset(s->framep, 0, sizeof(s->framep)); +- + av_freep(&s->macroblocks_base); + av_freep(&s->filter_strength); + av_freep(&s->intra4x4_pred_mode_top); + av_freep(&s->top_nnz); + av_freep(&s->edge_emu_buffer); + av_freep(&s->top_border); +- av_freep(&s->segmentation_map); + +- s->macroblocks = NULL; ++ s->macroblocks = NULL; ++} ++ ++static int vp8_alloc_frame(VP8Context *s, AVFrame *f) ++{ ++ int ret; ++ if ((ret = ff_thread_get_buffer(s->avctx, f)) < 0) ++ return ret; ++ if (s->num_maps_to_be_freed && !s->maps_are_invalid) { ++ f->ref_index[0] = s->segmentation_maps[--s->num_maps_to_be_freed]; ++ } else if (!(f->ref_index[0] = av_mallocz(s->mb_width * s->mb_height))) { ++ ff_thread_release_buffer(s->avctx, f); ++ return AVERROR(ENOMEM); ++ } ++ return 0; ++} ++ ++static void vp8_release_frame(VP8Context *s, AVFrame *f, int prefer_delayed_free, int can_direct_free) ++{ ++ if (f->ref_index[0]) { ++ if (prefer_delayed_free) { ++ /* Upon a size change, we want to free the maps but other threads may still ++ * be using them, so queue them. Upon a seek, all threads are inactive so ++ * we want to cache one to prevent re-allocation in the next decoding ++ * iteration, but the rest we can free directly. */ ++ int max_queued_maps = can_direct_free ? 1 : FF_ARRAY_ELEMS(s->segmentation_maps); ++ if (s->num_maps_to_be_freed < max_queued_maps) { ++ s->segmentation_maps[s->num_maps_to_be_freed++] = f->ref_index[0]; ++ } else if (can_direct_free) /* vp8_decode_flush(), but our queue is full */ { ++ av_free(f->ref_index[0]); ++ } /* else: MEMLEAK (should never happen, but better that than crash) */ ++ f->ref_index[0] = NULL; ++ } else /* vp8_decode_free() */ { ++ av_free(f->ref_index[0]); ++ } ++ } ++ ff_thread_release_buffer(s->avctx, f); ++} ++ ++static void vp8_decode_flush_impl(AVCodecContext *avctx, ++ int prefer_delayed_free, int can_direct_free, int free_mem) ++{ ++ VP8Context *s = avctx->priv_data; ++ int i; ++ ++ if (!avctx->internal->is_copy) { ++ for (i = 0; i < 5; i++) ++ if (s->frames[i].data[0]) ++ vp8_release_frame(s, &s->frames[i], prefer_delayed_free, can_direct_free); ++ } ++ memset(s->framep, 0, sizeof(s->framep)); ++ ++ if (free_mem) { ++ free_buffers(s); ++ s->maps_are_invalid = 1; ++ } ++} ++ ++static void vp8_decode_flush(AVCodecContext *avctx) ++{ ++ vp8_decode_flush_impl(avctx, 1, 1, 0); + } + + static int update_dimensions(VP8Context *s, int width, int height) + { +- if (av_image_check_size(width, height, 0, s->avctx)) +- return AVERROR_INVALIDDATA; ++ if (width != s->avctx->width || ++ height != s->avctx->height) { ++ if (av_image_check_size(width, height, 0, s->avctx)) ++ return AVERROR_INVALIDDATA; + +- vp8_decode_flush(s->avctx); ++ vp8_decode_flush_impl(s->avctx, 1, 0, 1); + +- avcodec_set_dimensions(s->avctx, width, height); ++ avcodec_set_dimensions(s->avctx, width, height); ++ } + + s->mb_width = (s->avctx->coded_width +15) / 16; + s->mb_height = (s->avctx->coded_height+15) / 16; +@@ -238,10 +126,9 @@ + s->intra4x4_pred_mode_top = av_mallocz(s->mb_width*4); + s->top_nnz = av_mallocz(s->mb_width*sizeof(*s->top_nnz)); + s->top_border = av_mallocz((s->mb_width+1)*sizeof(*s->top_border)); +- s->segmentation_map = av_mallocz(s->mb_width*s->mb_height); + + if (!s->macroblocks_base || !s->filter_strength || !s->intra4x4_pred_mode_top || +- !s->top_nnz || !s->top_border || !s->segmentation_map) ++ !s->top_nnz || !s->top_border) + return AVERROR(ENOMEM); + + s->macroblocks = s->macroblocks_base + 1; +@@ -278,7 +165,7 @@ + for (i = 0; i < 4; i++) + s->lf_delta.ref[i] = vp8_rac_get_sint(c, 6); + +- for (i = 0; i < 4; i++) ++ for (i = MODE_I4x4; i <= VP8_MVMODE_SPLIT; i++) + s->lf_delta.mode[i] = vp8_rac_get_sint(c, 6); + } + +@@ -328,12 +215,12 @@ + } else + base_qi = yac_qi; + +- s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + ydc_delta , 0, 127)]; +- s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi , 0, 127)]; +- s->qmat[i].luma_dc_qmul[0] = 2 * vp8_dc_qlookup[av_clip(base_qi + y2dc_delta, 0, 127)]; +- s->qmat[i].luma_dc_qmul[1] = 155 * vp8_ac_qlookup[av_clip(base_qi + y2ac_delta, 0, 127)] / 100; +- s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip(base_qi + uvdc_delta, 0, 127)]; +- s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip(base_qi + uvac_delta, 0, 127)]; ++ s->qmat[i].luma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + ydc_delta , 7)]; ++ s->qmat[i].luma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi , 7)]; ++ s->qmat[i].luma_dc_qmul[0] = 2 * vp8_dc_qlookup[av_clip_uintp2(base_qi + y2dc_delta, 7)]; ++ s->qmat[i].luma_dc_qmul[1] = 155 * vp8_ac_qlookup[av_clip_uintp2(base_qi + y2ac_delta, 7)] / 100; ++ s->qmat[i].chroma_qmul[0] = vp8_dc_qlookup[av_clip_uintp2(base_qi + uvdc_delta, 7)]; ++ s->qmat[i].chroma_qmul[1] = vp8_ac_qlookup[av_clip_uintp2(base_qi + uvac_delta, 7)]; + + s->qmat[i].luma_dc_qmul[1] = FFMAX(s->qmat[i].luma_dc_qmul[1], 8); + s->qmat[i].chroma_qmul[0] = FFMIN(s->qmat[i].chroma_qmul[0], 132); +@@ -435,7 +322,7 @@ + + if (!s->macroblocks_base || /* first frame */ + width != s->avctx->width || height != s->avctx->height) { +- if ((ret = update_dimensions(s, width, height) < 0)) ++ if ((ret = update_dimensions(s, width, height)) < 0) + return ret; + } + +@@ -517,76 +404,10 @@ + return 0; + } + +-static av_always_inline +-void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src, int mb_x, int mb_y) +-{ +-#define MARGIN (16 << 2) +- dst->x = av_clip(src->x, -((mb_x << 6) + MARGIN), +- ((s->mb_width - 1 - mb_x) << 6) + MARGIN); +- dst->y = av_clip(src->y, -((mb_y << 6) + MARGIN), +- ((s->mb_height - 1 - mb_y) << 6) + MARGIN); +-} +- +-static av_always_inline +-void find_near_mvs(VP8Context *s, VP8Macroblock *mb, +- VP56mv near[2], VP56mv *best, uint8_t cnt[4]) ++static av_always_inline void clamp_mv(VP8Context *s, VP56mv *dst, const VP56mv *src) + { +- VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, +- mb - 1 /* left */, +- mb + 1 /* top-left */ }; +- enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT }; +- VP56mv near_mv[4] = {{ 0 }}; +- enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; +- int idx = CNT_ZERO; +- int best_idx = CNT_ZERO; +- int cur_sign_bias = s->sign_bias[mb->ref_frame]; +- int *sign_bias = s->sign_bias; +- +- /* Process MB on top, left and top-left */ +- #define MV_EDGE_CHECK(n)\ +- {\ +- VP8Macroblock *edge = mb_edge[n];\ +- int edge_ref = edge->ref_frame;\ +- if (edge_ref != VP56_FRAME_CURRENT) {\ +- uint32_t mv = AV_RN32A(&edge->mv);\ +- if (mv) {\ +- if (cur_sign_bias != sign_bias[edge_ref]) {\ +- /* SWAR negate of the values in mv. */\ +- mv = ~mv;\ +- mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\ +- }\ +- if (!n || mv != AV_RN32A(&near_mv[idx]))\ +- AV_WN32A(&near_mv[++idx], mv);\ +- cnt[idx] += 1 + (n != 2);\ +- } else\ +- cnt[CNT_ZERO] += 1 + (n != 2);\ +- }\ +- } +- MV_EDGE_CHECK(0) +- MV_EDGE_CHECK(1) +- MV_EDGE_CHECK(2) +- +- /* If we have three distinct MVs, merge first and last if they're the same */ +- if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT])) +- cnt[CNT_NEAREST] += 1; +- +- cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) + +- (mb_edge[EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 + +- (mb_edge[EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT); +- +- /* Swap near and nearest if necessary */ +- if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) { +- FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]); +- FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]); +- } +- +- /* Choose the best mv out of 0,0 and the nearest mv */ +- if (cnt[CNT_NEAREST] >= cnt[CNT_ZERO]) +- best_idx = CNT_NEAREST; +- +- mb->mv = near_mv[best_idx]; +- near[0] = near_mv[CNT_NEAREST]; +- near[1] = near_mv[CNT_NEAR]; ++ dst->x = av_clip(src->x, s->mv_min.x, s->mv_max.x); ++ dst->y = av_clip(src->y, s->mv_min.y, s->mv_max.y); + } + + /** +@@ -699,6 +520,96 @@ + } + + static av_always_inline ++void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) ++{ ++ VP8Macroblock *mb_edge[3] = { mb + 2 /* top */, ++ mb - 1 /* left */, ++ mb + 1 /* top-left */ }; ++ enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; ++ enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT }; ++ int idx = CNT_ZERO; ++ int cur_sign_bias = s->sign_bias[mb->ref_frame]; ++ int8_t *sign_bias = s->sign_bias; ++ VP56mv near_mv[4]; ++ uint8_t cnt[4] = { 0 }; ++ VP56RangeCoder *c = &s->c; ++ ++ AV_ZERO32(&near_mv[0]); ++ AV_ZERO32(&near_mv[1]); ++ AV_ZERO32(&near_mv[2]); ++ ++ /* Process MB on top, left and top-left */ ++ #define MV_EDGE_CHECK(n)\ ++ {\ ++ VP8Macroblock *edge = mb_edge[n];\ ++ int edge_ref = edge->ref_frame;\ ++ if (edge_ref != VP56_FRAME_CURRENT) {\ ++ uint32_t mv = AV_RN32A(&edge->mv);\ ++ if (mv) {\ ++ if (cur_sign_bias != sign_bias[edge_ref]) {\ ++ /* SWAR negate of the values in mv. */\ ++ mv = ~mv;\ ++ mv = ((mv&0x7fff7fff) + 0x00010001) ^ (mv&0x80008000);\ ++ }\ ++ if (!n || mv != AV_RN32A(&near_mv[idx]))\ ++ AV_WN32A(&near_mv[++idx], mv);\ ++ cnt[idx] += 1 + (n != 2);\ ++ } else\ ++ cnt[CNT_ZERO] += 1 + (n != 2);\ ++ }\ ++ } ++ ++ MV_EDGE_CHECK(0) ++ MV_EDGE_CHECK(1) ++ MV_EDGE_CHECK(2) ++ ++ mb->partitioning = VP8_SPLITMVMODE_NONE; ++ if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_ZERO]][0])) { ++ mb->mode = VP8_MVMODE_MV; ++ ++ /* If we have three distinct MVs, merge first and last if they're the same */ ++ if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1 + VP8_EDGE_TOP]) == AV_RN32A(&near_mv[1 + VP8_EDGE_TOPLEFT])) ++ cnt[CNT_NEAREST] += 1; ++ ++ /* Swap near and nearest if necessary */ ++ if (cnt[CNT_NEAR] > cnt[CNT_NEAREST]) { ++ FFSWAP(uint8_t, cnt[CNT_NEAREST], cnt[CNT_NEAR]); ++ FFSWAP( VP56mv, near_mv[CNT_NEAREST], near_mv[CNT_NEAR]); ++ } ++ ++ if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAREST]][1])) { ++ if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_NEAR]][2])) { ++ ++ /* Choose the best mv out of 0,0 and the nearest mv */ ++ clamp_mv(s, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]); ++ cnt[CNT_SPLITMV] = ((mb_edge[VP8_EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) + ++ (mb_edge[VP8_EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 + ++ (mb_edge[VP8_EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT); ++ ++ if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) { ++ mb->mode = VP8_MVMODE_SPLIT; ++ mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1]; ++ } else { ++ mb->mv.y += read_mv_component(c, s->prob->mvc[0]); ++ mb->mv.x += read_mv_component(c, s->prob->mvc[1]); ++ mb->bmv[0] = mb->mv; ++ } ++ } else { ++ clamp_mv(s, &mb->mv, &near_mv[CNT_NEAR]); ++ mb->bmv[0] = mb->mv; ++ } ++ } else { ++ clamp_mv(s, &mb->mv, &near_mv[CNT_NEAREST]); ++ mb->bmv[0] = mb->mv; ++ } ++ } else { ++ mb->mode = VP8_MVMODE_ZERO; ++ AV_ZERO32(&mb->mv); ++ mb->bmv[0] = mb->mv; ++ } ++} ++ ++static av_always_inline + void decode_intra4x4_modes(VP8Context *s, VP56RangeCoder *c, + int mb_x, int keyframe) + { +@@ -724,12 +635,15 @@ + } + + static av_always_inline +-void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment) ++void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y, uint8_t *segment, uint8_t *ref) + { + VP56RangeCoder *c = &s->c; + +- if (s->segmentation.update_map) +- *segment = vp8_rac_get_tree(c, vp8_segmentid_tree, s->prob->segmentid); ++ if (s->segmentation.update_map) { ++ int bit = vp56_rac_get_prob(c, s->prob->segmentid[0]); ++ *segment = vp56_rac_get_prob(c, s->prob->segmentid[1+bit]) + 2*bit; ++ } else ++ *segment = ref ? *ref : *segment; + s->segment = *segment; + + mb->skip = s->mbskip_enabled ? vp56_rac_get_prob(c, s->prob->mbskip) : 0; +@@ -748,9 +662,6 @@ + s->chroma_pred_mode = vp8_rac_get_tree(c, vp8_pred8x8c_tree, vp8_pred8x8c_prob_intra); + mb->ref_frame = VP56_FRAME_CURRENT; + } else if (vp56_rac_get_prob_branchy(c, s->prob->intra)) { +- VP56mv near[2], best; +- uint8_t cnt[4] = { 0 }; +- + // inter MB, 16.2 + if (vp56_rac_get_prob_branchy(c, s->prob->last)) + mb->ref_frame = vp56_rac_get_prob(c, s->prob->golden) ? +@@ -760,36 +671,7 @@ + s->ref_count[mb->ref_frame-1]++; + + // motion vectors, 16.3 +- find_near_mvs(s, mb, near, &best, cnt); +- if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[0]][0])) { +- if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[1]][1])) { +- if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[2]][2])) { +- if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[3]][3])) { +- mb->mode = VP8_MVMODE_SPLIT; +- clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); +- mb->mv = mb->bmv[decode_splitmvs(s, c, mb) - 1]; +- } else { +- mb->mode = VP8_MVMODE_NEW; +- clamp_mv(s, &mb->mv, &mb->mv, mb_x, mb_y); +- mb->mv.y += read_mv_component(c, s->prob->mvc[0]); +- mb->mv.x += read_mv_component(c, s->prob->mvc[1]); +- } +- } else { +- mb->mode = VP8_MVMODE_NEAR; +- clamp_mv(s, &mb->mv, &near[1], mb_x, mb_y); +- } +- } else { +- mb->mode = VP8_MVMODE_NEAREST; +- clamp_mv(s, &mb->mv, &near[0], mb_x, mb_y); +- } +- } else { +- mb->mode = VP8_MVMODE_ZERO; +- AV_ZERO32(&mb->mv); +- } +- if (mb->mode != VP8_MVMODE_SPLIT) { +- mb->partitioning = VP8_SPLITMVMODE_NONE; +- mb->bmv[0] = mb->mv; +- } ++ decode_mvs(s, mb, mb_x, mb_y); + } else { + // intra MB, 16.1 + mb->mode = vp8_rac_get_tree(c, vp8_pred16x16_tree_inter, s->prob->pred16x16); +@@ -804,19 +686,18 @@ + } + } + ++#ifndef decode_block_coeffs_internal + /** + * @param c arithmetic bitstream reader context + * @param block destination for block coefficients + * @param probs probabilities to use when reading trees from the bitstream + * @param i initial coeff index, 0 unless a separate DC block is coded +- * @param zero_nhood the initial prediction context for number of surrounding +- * all-zero blocks (only left/top, so 0-2) + * @param qmul array holding the dc/ac dequant factor at position 0/1 + * @return 0 if no coeffs were decoded + * otherwise, the index of the last coeff decoded plus one + */ + static int decode_block_coeffs_internal(VP56RangeCoder *c, DCTELEM block[16], +- uint8_t probs[8][3][NUM_DCT_TOKENS-1], ++ uint8_t probs[16][3][NUM_DCT_TOKENS-1], + int i, uint8_t *token_prob, int16_t qmul[2]) + { + goto skip_eob; +@@ -857,7 +738,7 @@ + int b = vp56_rac_get_prob(c, token_prob[9+a]); + int cat = (a<<1) + b; + coeff = 3 + (8<avctx; +- int x, y, mode, nnz, tr; ++ int x, y, mode, nnz; ++ uint32_t tr; + + // for the first row, we need to run xchg_mb_border to init the top edge to 127 + // otherwise, skip it if we aren't going to deblock +@@ -1106,7 +1000,7 @@ + // from the top macroblock + if (!(!mb_y && avctx->flags & CODEC_FLAG_EMU_EDGE) && + mb_x == s->mb_width-1) { +- tr = tr_right[-1]*0x01010101; ++ tr = tr_right[-1]*0x01010101u; + tr_right = (uint8_t *)&tr; + } + +@@ -1201,12 +1095,11 @@ + }; + + /** +- * Generic MC function. ++ * luma MC function + * + * @param s VP8 decoding context +- * @param luma 1 for luma (Y) planes, 0 for chroma (Cb/Cr) planes + * @param dst target buffer for block data at block position +- * @param src reference picture buffer at origin (0, 0) ++ * @param ref reference picture buffer at origin (0, 0) + * @param mv motion vector (relative to block position) to get pixel data from + * @param x_off horizontal position of block from origin (0, 0) + * @param y_off vertical position of block from origin (0, 0) +@@ -1218,11 +1111,13 @@ + * @param mc_func motion compensation function pointers (bilinear or sixtap MC) + */ + static av_always_inline +-void vp8_mc_luma(VP8Context *s, uint8_t *dst, uint8_t *src, const VP56mv *mv, ++void vp8_mc_luma(VP8Context *s, uint8_t *dst, AVFrame *ref, const VP56mv *mv, + int x_off, int y_off, int block_w, int block_h, + int width, int height, int linesize, + vp8_mc_func mc_func[3][3]) + { ++ uint8_t *src = ref->data[0]; ++ + if (AV_RN32A(mv)) { + + int mx = (mv->x << 1)&7, mx_idx = subpel_idx[0][mx]; +@@ -1232,6 +1127,7 @@ + y_off += mv->y >> 2; + + // edge emulation ++ ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 4, 0); + src += y_off * linesize + x_off; + if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || + y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { +@@ -1241,16 +1137,37 @@ + src = s->edge_emu_buffer + mx_idx + linesize * my_idx; + } + mc_func[my_idx][mx_idx](dst, linesize, src, linesize, block_h, mx, my); +- } else ++ } else { ++ ff_thread_await_progress(ref, (3 + y_off + block_h) >> 4, 0); + mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0); ++ } + } + ++/** ++ * chroma MC function ++ * ++ * @param s VP8 decoding context ++ * @param dst1 target buffer for block data at block position (U plane) ++ * @param dst2 target buffer for block data at block position (V plane) ++ * @param ref reference picture buffer at origin (0, 0) ++ * @param mv motion vector (relative to block position) to get pixel data from ++ * @param x_off horizontal position of block from origin (0, 0) ++ * @param y_off vertical position of block from origin (0, 0) ++ * @param block_w width of block (16, 8 or 4) ++ * @param block_h height of block (always same as block_w) ++ * @param width width of src/dst plane data ++ * @param height height of src/dst plane data ++ * @param linesize size of a single line of plane data, including padding ++ * @param mc_func motion compensation function pointers (bilinear or sixtap MC) ++ */ + static av_always_inline +-void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, uint8_t *src1, +- uint8_t *src2, const VP56mv *mv, int x_off, int y_off, ++void vp8_mc_chroma(VP8Context *s, uint8_t *dst1, uint8_t *dst2, AVFrame *ref, ++ const VP56mv *mv, int x_off, int y_off, + int block_w, int block_h, int width, int height, int linesize, + vp8_mc_func mc_func[3][3]) + { ++ uint8_t *src1 = ref->data[1], *src2 = ref->data[2]; ++ + if (AV_RN32A(mv)) { + int mx = mv->x&7, mx_idx = subpel_idx[0][mx]; + int my = mv->y&7, my_idx = subpel_idx[0][my]; +@@ -1261,6 +1178,7 @@ + // edge emulation + src1 += y_off * linesize + x_off; + src2 += y_off * linesize + x_off; ++ ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0); + if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || + y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { + s->dsp.emulated_edge_mc(s->edge_emu_buffer, src1 - my_idx * linesize - mx_idx, linesize, +@@ -1279,6 +1197,7 @@ + mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my); + } + } else { ++ ff_thread_await_progress(ref, (3 + y_off + block_h) >> 3, 0); + mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0); + mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0); + } +@@ -1295,7 +1214,7 @@ + + /* Y */ + vp8_mc_luma(s, dst[0] + by_off * s->linesize + bx_off, +- ref_frame->data[0], mv, x_off + bx_off, y_off + by_off, ++ ref_frame, mv, x_off + bx_off, y_off + by_off, + block_w, block_h, width, height, s->linesize, + s->put_pixels_tab[block_w == 8]); + +@@ -1309,8 +1228,8 @@ + width >>= 1; height >>= 1; + block_w >>= 1; block_h >>= 1; + vp8_mc_chroma(s, dst[1] + by_off * s->uvlinesize + bx_off, +- dst[2] + by_off * s->uvlinesize + bx_off, ref_frame->data[1], +- ref_frame->data[2], &uvmv, x_off + bx_off, y_off + by_off, ++ dst[2] + by_off * s->uvlinesize + bx_off, ref_frame, ++ &uvmv, x_off + bx_off, y_off + by_off, + block_w, block_h, width, height, s->uvlinesize, + s->put_pixels_tab[1 + (block_w == 4)]); + } +@@ -1326,6 +1245,9 @@ + int my = (mb->mv.y>>2) + y_off; + uint8_t **src= s->framep[ref]->data; + int off= mx + (my + (mb_x&3)*4)*s->linesize + 64; ++ /* For threading, a ff_thread_await_progress here might be useful, but ++ * it actually slows down the decoder. Since a bad prefetch doesn't ++ * generate bad decoder output, we don't run it here. */ + s->dsp.prefetch(src[0]+off, s->linesize, 4); + off= (mx>>1) + ((my>>1) + (mb_x&7))*s->uvlinesize + 64; + s->dsp.prefetch(src[1]+off, src[2]-src[1], 2); +@@ -1357,7 +1279,7 @@ + for (y = 0; y < 4; y++) { + for (x = 0; x < 4; x++) { + vp8_mc_luma(s, dst[0] + 4*y*s->linesize + x*4, +- ref->data[0], &bmv[4*y + x], ++ ref, &bmv[4*y + x], + 4*x + x_off, 4*y + y_off, 4, 4, + width, height, s->linesize, + s->put_pixels_tab[2]); +@@ -1383,8 +1305,7 @@ + uvmv.y &= ~7; + } + vp8_mc_chroma(s, dst[1] + 4*y*s->uvlinesize + x*4, +- dst[2] + 4*y*s->uvlinesize + x*4, +- ref->data[1], ref->data[2], &uvmv, ++ dst[2] + 4*y*s->uvlinesize + x*4, ref, &uvmv, + 4*x + x_off, 4*y + y_off, 4, 4, + width, height, s->uvlinesize, + s->put_pixels_tab[2]); +@@ -1424,17 +1345,17 @@ + if (mb->mode != MODE_I4x4) { + uint8_t *y_dst = dst[0]; + for (y = 0; y < 4; y++) { +- uint32_t nnz4 = AV_RN32A(s->non_zero_count_cache[y]); ++ uint32_t nnz4 = AV_RL32(s->non_zero_count_cache[y]); + if (nnz4) { + if (nnz4&~0x01010101) { + for (x = 0; x < 4; x++) { +- int nnz = s->non_zero_count_cache[y][x]; +- if (nnz) { +- if (nnz == 1) +- s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, s->block[y][x], s->linesize); +- else +- s->vp8dsp.vp8_idct_add(y_dst+4*x, s->block[y][x], s->linesize); +- } ++ if ((uint8_t)nnz4 == 1) ++ s->vp8dsp.vp8_idct_dc_add(y_dst+4*x, s->block[y][x], s->linesize); ++ else if((uint8_t)nnz4 > 1) ++ s->vp8dsp.vp8_idct_add(y_dst+4*x, s->block[y][x], s->linesize); ++ nnz4 >>= 8; ++ if (!nnz4) ++ break; + } + } else { + s->vp8dsp.vp8_idct_dc_add4y(y_dst, s->block[y], s->linesize); +@@ -1445,19 +1366,19 @@ + } + + for (ch = 0; ch < 2; ch++) { +- uint32_t nnz4 = AV_RN32A(s->non_zero_count_cache[4+ch]); ++ uint32_t nnz4 = AV_RL32(s->non_zero_count_cache[4+ch]); + if (nnz4) { + uint8_t *ch_dst = dst[1+ch]; + if (nnz4&~0x01010101) { + for (y = 0; y < 2; y++) { + for (x = 0; x < 2; x++) { +- int nnz = s->non_zero_count_cache[4+ch][(y<<1)+x]; +- if (nnz) { +- if (nnz == 1) +- s->vp8dsp.vp8_idct_dc_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize); +- else +- s->vp8dsp.vp8_idct_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize); +- } ++ if ((uint8_t)nnz4 == 1) ++ s->vp8dsp.vp8_idct_dc_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize); ++ else if((uint8_t)nnz4 > 1) ++ s->vp8dsp.vp8_idct_add(ch_dst+4*x, s->block[4+ch][(y<<1)+x], s->uvlinesize); ++ nnz4 >>= 8; ++ if (!nnz4) ++ goto chroma_idct_end; + } + ch_dst += 4*s->uvlinesize; + } +@@ -1465,6 +1386,7 @@ + s->vp8dsp.vp8_idct_dc_add4uv(ch_dst, s->block[4+ch], s->uvlinesize); + } + } ++chroma_idct_end: ; + } + } + +@@ -1481,24 +1403,14 @@ + + if (s->lf_delta.enabled) { + filter_level += s->lf_delta.ref[mb->ref_frame]; +- +- if (mb->ref_frame == VP56_FRAME_CURRENT) { +- if (mb->mode == MODE_I4x4) +- filter_level += s->lf_delta.mode[0]; +- } else { +- if (mb->mode == VP8_MVMODE_ZERO) +- filter_level += s->lf_delta.mode[1]; +- else if (mb->mode == VP8_MVMODE_SPLIT) +- filter_level += s->lf_delta.mode[3]; +- else +- filter_level += s->lf_delta.mode[2]; +- } ++ filter_level += s->lf_delta.mode[mb->mode]; + } +- filter_level = av_clip(filter_level, 0, 63); ++ ++ filter_level = av_clip_uintp2(filter_level, 6); + + interior_limit = filter_level; + if (s->filter.sharpness) { +- interior_limit >>= s->filter.sharpness > 4 ? 2 : 1; ++ interior_limit >>= (s->filter.sharpness + 3) >> 2; + interior_limit = FFMIN(interior_limit, 9 - s->filter.sharpness); + } + interior_limit = FFMAX(interior_limit, 1); +@@ -1516,23 +1428,24 @@ + int inner_filter = f->inner_filter; + int linesize = s->linesize; + int uvlinesize = s->uvlinesize; ++ static const uint8_t hev_thresh_lut[2][64] = { ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, ++ 3, 3, 3, 3 }, ++ { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, ++ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ++ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, ++ 2, 2, 2, 2 } ++ }; + + if (!filter_level) + return; + +- mbedge_lim = 2*(filter_level+2) + inner_limit; +- bedge_lim = 2* filter_level + inner_limit; +- hev_thresh = filter_level >= 15; ++ bedge_lim = 2*filter_level + inner_limit; ++ mbedge_lim = bedge_lim + 4; + +- if (s->keyframe) { +- if (filter_level >= 40) +- hev_thresh = 2; +- } else { +- if (filter_level >= 40) +- hev_thresh = 3; +- else if (filter_level >= 20) +- hev_thresh = 2; +- } ++ hev_thresh = hev_thresh_lut[s->keyframe][filter_level]; + + if (mb_x) { + s->vp8dsp.vp8_h_loop_filter16y(dst[0], linesize, +@@ -1588,8 +1501,8 @@ + if (!filter_level) + return; + +- mbedge_lim = 2*(filter_level+2) + inner_limit; +- bedge_lim = 2* filter_level + inner_limit; ++ bedge_lim = 2*filter_level + inner_limit; ++ mbedge_lim = bedge_lim + 4; + + if (mb_x) + s->vp8dsp.vp8_h_loop_filter_simple(dst, linesize, mbedge_lim); +@@ -1608,13 +1521,13 @@ + } + } + +-static void filter_mb_row(VP8Context *s, int mb_y) ++static void filter_mb_row(VP8Context *s, AVFrame *curframe, int mb_y) + { + VP8FilterStrength *f = s->filter_strength; + uint8_t *dst[3] = { +- s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize, +- s->framep[VP56_FRAME_CURRENT]->data[1] + 8*mb_y*s->uvlinesize, +- s->framep[VP56_FRAME_CURRENT]->data[2] + 8*mb_y*s->uvlinesize ++ curframe->data[0] + 16*mb_y*s->linesize, ++ curframe->data[1] + 8*mb_y*s->uvlinesize, ++ curframe->data[2] + 8*mb_y*s->uvlinesize + }; + int mb_x; + +@@ -1627,10 +1540,10 @@ + } + } + +-static void filter_mb_row_simple(VP8Context *s, int mb_y) ++static void filter_mb_row_simple(VP8Context *s, AVFrame *curframe, int mb_y) + { + VP8FilterStrength *f = s->filter_strength; +- uint8_t *dst = s->framep[VP56_FRAME_CURRENT]->data[0] + 16*mb_y*s->linesize; ++ uint8_t *dst = curframe->data[0] + 16*mb_y*s->linesize; + int mb_x; + + for (mb_x = 0; mb_x < s->mb_width; mb_x++) { +@@ -1640,45 +1553,94 @@ + } + } + ++static void release_queued_segmaps(VP8Context *s, int is_close) ++{ ++ int leave_behind = is_close ? 0 : !s->maps_are_invalid; ++ while (s->num_maps_to_be_freed > leave_behind) ++ av_freep(&s->segmentation_maps[--s->num_maps_to_be_freed]); ++ s->maps_are_invalid = 0; ++} ++ ++/** ++ * Sets things up for skipping the current frame. ++ * In particular, removes it from the reference buffers. ++ */ ++static void skipframe_clear(VP8Context *s) ++{ ++ s->invisible = 1; ++ s->next_framep[VP56_FRAME_CURRENT] = NULL; ++ if (s->update_last) ++ s->next_framep[VP56_FRAME_PREVIOUS] = NULL; ++} ++ + static int vp8_decode_frame(AVCodecContext *avctx, void *data, int *data_size, + AVPacket *avpkt) + { + VP8Context *s = avctx->priv_data; + int ret, mb_x, mb_y, i, y, referenced; + enum AVDiscard skip_thresh; +- AVFrame *av_uninit(curframe); ++ AVFrame *av_uninit(curframe), *prev_frame; ++ ++ release_queued_segmaps(s, 0); + + if ((ret = decode_frame_header(s, avpkt->data, avpkt->size)) < 0) + return ret; + ++ prev_frame = s->framep[VP56_FRAME_CURRENT]; ++ + referenced = s->update_last || s->update_golden == VP56_FRAME_CURRENT + || s->update_altref == VP56_FRAME_CURRENT; + + skip_thresh = !referenced ? AVDISCARD_NONREF : + !s->keyframe ? AVDISCARD_NONKEY : AVDISCARD_ALL; + +- if (avctx->skip_frame >= skip_thresh) { +- s->invisible = 1; +- goto skip_decode; +- } + s->deblock_filter = s->filter.level && avctx->skip_loop_filter < skip_thresh; + +- for (i = 0; i < 4; i++) +- if (&s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] && ++ // release no longer referenced frames ++ for (i = 0; i < 5; i++) ++ if (s->frames[i].data[0] && ++ &s->frames[i] != prev_frame && ++ &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] && ++ &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] && ++ &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2]) ++ vp8_release_frame(s, &s->frames[i], 1, 0); ++ ++ // find a free buffer ++ for (i = 0; i < 5; i++) ++ if (&s->frames[i] != prev_frame && ++ &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] && + &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] && + &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2]) { + curframe = s->framep[VP56_FRAME_CURRENT] = &s->frames[i]; + break; + } +- if (curframe->data[0]) +- avctx->release_buffer(avctx, curframe); ++ if (i == 5) { ++ av_log(avctx, AV_LOG_FATAL, "Ran out of free frames!\n"); ++ abort(); ++ } + +- curframe->key_frame = s->keyframe; +- curframe->pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE; +- curframe->reference = referenced ? 3 : 0; +- if ((ret = avctx->get_buffer(avctx, curframe))) { +- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n"); +- return ret; ++ // check if golden and altref are swapped ++ if (s->update_altref != VP56_FRAME_NONE) { ++ s->next_framep[VP56_FRAME_GOLDEN2] = s->framep[s->update_altref]; ++ } else { ++ s->next_framep[VP56_FRAME_GOLDEN2] = s->framep[VP56_FRAME_GOLDEN2]; ++ } ++ if (s->update_golden != VP56_FRAME_NONE) { ++ s->next_framep[VP56_FRAME_GOLDEN] = s->framep[s->update_golden]; ++ } else { ++ s->next_framep[VP56_FRAME_GOLDEN] = s->framep[VP56_FRAME_GOLDEN]; ++ } ++ if (s->update_last) { ++ s->next_framep[VP56_FRAME_PREVIOUS] = curframe; ++ } else { ++ s->next_framep[VP56_FRAME_PREVIOUS] = s->framep[VP56_FRAME_PREVIOUS]; ++ } ++ s->next_framep[VP56_FRAME_CURRENT] = curframe; ++ ++ if (avctx->skip_frame >= skip_thresh) { ++ skipframe_clear(s); ++ ret = avpkt->size; ++ goto skip_decode; + } + + // Given that arithmetic probabilities are updated every frame, it's quite likely +@@ -1688,9 +1650,25 @@ + !s->framep[VP56_FRAME_GOLDEN] || + !s->framep[VP56_FRAME_GOLDEN2])) { + av_log(avctx, AV_LOG_WARNING, "Discarding interframe without a prior keyframe!\n"); +- return AVERROR_INVALIDDATA; ++ skipframe_clear(s); ++ ret = AVERROR_INVALIDDATA; ++ goto skip_decode; ++ } ++ ++ if (curframe->data[0]) ++ vp8_release_frame(s, curframe, 1, 0); ++ ++ curframe->key_frame = s->keyframe; ++ curframe->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; ++ curframe->reference = referenced ? 3 : 0; ++ if ((ret = vp8_alloc_frame(s, curframe))) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed!\n"); ++ skipframe_clear(s); ++ goto skip_decode; + } + ++ ff_thread_finish_setup(avctx); ++ + s->linesize = curframe->linesize[0]; + s->uvlinesize = curframe->linesize[1]; + +@@ -1711,6 +1689,10 @@ + if (s->keyframe) + memset(s->intra4x4_pred_mode_top, DC_PRED, s->mb_width*4); + ++#define MARGIN (16 << 2) ++ s->mv_min.y = -MARGIN; ++ s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN; ++ + for (mb_y = 0; mb_y < s->mb_height; mb_y++) { + VP56RangeCoder *c = &s->coeff_partition[mb_y & (s->num_coeff_partitions-1)]; + VP8Macroblock *mb = s->macroblocks + (s->mb_height - mb_y - 1)*2; +@@ -1734,12 +1716,18 @@ + s->top_border[0][15] = s->top_border[0][23] = s->top_border[0][31] = 129; + } + ++ s->mv_min.x = -MARGIN; ++ s->mv_max.x = ((s->mb_width - 1) << 6) + MARGIN; ++ if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map) ++ ff_thread_await_progress(prev_frame, mb_y, 0); ++ + for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) { + /* Prefetch the current frame, 4 MBs ahead */ + s->dsp.prefetch(dst[0] + (mb_x&3)*4*s->linesize + 64, s->linesize, 4); + s->dsp.prefetch(dst[1] + (mb_x&7)*s->uvlinesize + 64, dst[2] - dst[1], 2); + +- decode_mb_mode(s, mb, mb_x, mb_y, s->segmentation_map + mb_xy); ++ decode_mb_mode(s, mb, mb_x, mb_y, curframe->ref_index[0] + mb_xy, ++ prev_frame && prev_frame->ref_index[0] ? prev_frame->ref_index[0] + mb_xy : NULL); + + prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP56_FRAME_PREVIOUS); + +@@ -1774,51 +1762,37 @@ + dst[0] += 16; + dst[1] += 8; + dst[2] += 8; ++ s->mv_min.x -= 64; ++ s->mv_max.x -= 64; + } + if (s->deblock_filter) { + if (s->filter.simple) +- filter_mb_row_simple(s, mb_y); ++ filter_mb_row_simple(s, curframe, mb_y); + else +- filter_mb_row(s, mb_y); ++ filter_mb_row(s, curframe, mb_y); + } ++ s->mv_min.y -= 64; ++ s->mv_max.y -= 64; ++ ++ ff_thread_report_progress(curframe, mb_y, 0); + } + ++ ff_thread_report_progress(curframe, INT_MAX, 0); ++ ret = avpkt->size; + skip_decode: + // if future frames don't use the updated probabilities, + // reset them to the values we saved + if (!s->update_probabilities) + s->prob[0] = s->prob[1]; + +- // check if golden and altref are swapped +- if (s->update_altref == VP56_FRAME_GOLDEN && +- s->update_golden == VP56_FRAME_GOLDEN2) +- FFSWAP(AVFrame *, s->framep[VP56_FRAME_GOLDEN], s->framep[VP56_FRAME_GOLDEN2]); +- else { +- if (s->update_altref != VP56_FRAME_NONE) +- s->framep[VP56_FRAME_GOLDEN2] = s->framep[s->update_altref]; +- +- if (s->update_golden != VP56_FRAME_NONE) +- s->framep[VP56_FRAME_GOLDEN] = s->framep[s->update_golden]; +- } +- +- if (s->update_last) // move cur->prev +- s->framep[VP56_FRAME_PREVIOUS] = s->framep[VP56_FRAME_CURRENT]; +- +- // release no longer referenced frames +- for (i = 0; i < 4; i++) +- if (s->frames[i].data[0] && +- &s->frames[i] != s->framep[VP56_FRAME_CURRENT] && +- &s->frames[i] != s->framep[VP56_FRAME_PREVIOUS] && +- &s->frames[i] != s->framep[VP56_FRAME_GOLDEN] && +- &s->frames[i] != s->framep[VP56_FRAME_GOLDEN2]) +- avctx->release_buffer(avctx, &s->frames[i]); ++ memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4); + + if (!s->invisible) { +- *(AVFrame*)data = *s->framep[VP56_FRAME_CURRENT]; ++ *(AVFrame*)data = *curframe; + *data_size = sizeof(AVFrame); + } + +- return avpkt->size; ++ return ret; + } + + static av_cold int vp8_decode_init(AVCodecContext *avctx) +@@ -1829,7 +1803,7 @@ + avctx->pix_fmt = PIX_FMT_YUV420P; + + dsputil_init(&s->dsp, avctx); +- ff_h264_pred_init(&s->hpc, CODEC_ID_VP8); ++ ff_h264_pred_init(&s->hpc, CODEC_ID_VP8, 8, 1); + ff_vp8dsp_init(&s->vp8dsp); + + return 0; +@@ -1837,20 +1811,58 @@ + + static av_cold int vp8_decode_free(AVCodecContext *avctx) + { +- vp8_decode_flush(avctx); ++ vp8_decode_flush_impl(avctx, 0, 1, 1); ++ release_queued_segmaps(avctx->priv_data, 1); ++ return 0; ++} ++ ++static av_cold int vp8_decode_init_thread_copy(AVCodecContext *avctx) ++{ ++ VP8Context *s = avctx->priv_data; ++ ++ s->avctx = avctx; ++ ++ return 0; ++} ++ ++#define REBASE(pic) \ ++ pic ? pic - &s_src->frames[0] + &s->frames[0] : NULL ++ ++static int vp8_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) ++{ ++ VP8Context *s = dst->priv_data, *s_src = src->priv_data; ++ ++ if (s->macroblocks_base && ++ (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) { ++ free_buffers(s); ++ s->maps_are_invalid = 1; ++ } ++ ++ s->prob[0] = s_src->prob[!s_src->update_probabilities]; ++ s->segmentation = s_src->segmentation; ++ s->lf_delta = s_src->lf_delta; ++ memcpy(s->sign_bias, s_src->sign_bias, sizeof(s->sign_bias)); ++ ++ memcpy(&s->frames, &s_src->frames, sizeof(s->frames)); ++ s->framep[0] = REBASE(s_src->next_framep[0]); ++ s->framep[1] = REBASE(s_src->next_framep[1]); ++ s->framep[2] = REBASE(s_src->next_framep[2]); ++ s->framep[3] = REBASE(s_src->next_framep[3]); ++ + return 0; + } + + AVCodec ff_vp8_decoder = { +- "vp8", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VP8, +- sizeof(VP8Context), +- vp8_decode_init, +- NULL, +- vp8_decode_free, +- vp8_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vp8", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VP8, ++ .priv_data_size = sizeof(VP8Context), ++ .init = vp8_decode_init, ++ .close = vp8_decode_free, ++ .decode = vp8_decode_frame, ++ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS, + .flush = vp8_decode_flush, + .long_name = NULL_IF_CONFIG_SMALL("On2 VP8"), ++ .init_thread_copy = ONLY_IF_THREADS_ENABLED(vp8_decode_init_thread_copy), ++ .update_thread_context = ONLY_IF_THREADS_ENABLED(vp8_decode_update_thread_context), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8data.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8data.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8data.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8data.h 2012-05-14 14:08:54.455342417 +0200 +@@ -1,6 +1,4 @@ +-/** +- * VP8 compatible video decoder +- * ++/* + * Copyright (C) 2010 David Conrad + * Copyright (C) 2010 Ronald S. Bultje + * +@@ -21,48 +19,17 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-// TODO: move these #define and enum to a better header... +- +-#define VP8_MAX_QUANT 127 +- +-enum dct_token { +- DCT_0, +- DCT_1, +- DCT_2, +- DCT_3, +- DCT_4, +- DCT_CAT1, +- DCT_CAT2, +- DCT_CAT3, +- DCT_CAT4, +- DCT_CAT5, +- DCT_CAT6, +- DCT_EOB, ++/** ++ * @file ++ * VP8 compatible video decoder ++ */ + +- NUM_DCT_TOKENS +-}; ++#ifndef AVCODEC_VP8DATA_H ++#define AVCODEC_VP8DATA_H + ++#include "vp8.h" + #include "h264pred.h" + +-// used to signal 4x4 intra pred in luma MBs +-#define MODE_I4x4 4 +- +-enum inter_mvmode { +- VP8_MVMODE_NEAREST = MODE_I4x4 + 1, +- VP8_MVMODE_NEAR, +- VP8_MVMODE_ZERO, +- VP8_MVMODE_NEW, +- VP8_MVMODE_SPLIT +-}; +- +-enum inter_splitmvmode { +- VP8_SPLITMVMODE_16x8 = 0, ///< 2 16x8 blocks (vertical) +- VP8_SPLITMVMODE_8x16, ///< 2 8x16 blocks (horizontal) +- VP8_SPLITMVMODE_8x8, ///< 2x2 blocks of 8x8px each +- VP8_SPLITMVMODE_4x4, ///< 4x4 blocks of 4x4px each +- VP8_SPLITMVMODE_NONE, ///< (only used in prediction) no split MVs +-}; +- + static const uint8_t vp8_pred4x4_mode[] = + { + [DC_PRED8x8] = DC_PRED, +@@ -315,7 +282,7 @@ + static const uint8_t vp8_dct_cat6_prob[] = { 254, 254, 243, 230, 196, 177, 153, 140, 133, 130, 129, 0 }; + + // only used for cat3 and above; cat 1 and 2 are referenced directly +-static const uint8_t * const vp8_dct_cat_prob[] = ++const uint8_t * const ff_vp8_dct_cat_prob[] = + { + vp8_dct_cat3_prob, + vp8_dct_cat4_prob, +@@ -720,3 +687,5 @@ + 204, 170, 119, 235, 140, 230, 228, + 128, 130, 130, 74, 148, 180, 203, 236, 254, 254 } + }; ++ ++#endif /* AVCODEC_VP8DATA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8dsp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8dsp.c 2012-05-14 14:08:54.456342437 +0200 +@@ -1,6 +1,4 @@ +-/** +- * VP8 compatible video decoder +- * ++/* + * Copyright (C) 2010 David Conrad + * Copyright (C) 2010 Ronald S. Bultje + * +@@ -21,6 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP8 compatible video decoder ++ */ ++ + #include "dsputil.h" + #include "vp8dsp.h" + +@@ -77,7 +80,6 @@ + static void vp8_idct_add_c(uint8_t *dst, DCTELEM block[16], int stride) + { + int i, t0, t1, t2, t3; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; + DCTELEM tmp[16]; + + for (i = 0; i < 4; i++) { +@@ -102,10 +104,10 @@ + t2 = MUL_35468(tmp[1*4+i]) - MUL_20091(tmp[3*4+i]); + t3 = MUL_20091(tmp[1*4+i]) + MUL_35468(tmp[3*4+i]); + +- dst[0] = cm[dst[0] + ((t0 + t3 + 4) >> 3)]; +- dst[1] = cm[dst[1] + ((t1 + t2 + 4) >> 3)]; +- dst[2] = cm[dst[2] + ((t1 - t2 + 4) >> 3)]; +- dst[3] = cm[dst[3] + ((t0 - t3 + 4) >> 3)]; ++ dst[0] = av_clip_uint8(dst[0] + ((t0 + t3 + 4) >> 3)); ++ dst[1] = av_clip_uint8(dst[1] + ((t1 + t2 + 4) >> 3)); ++ dst[2] = av_clip_uint8(dst[2] + ((t1 - t2 + 4) >> 3)); ++ dst[3] = av_clip_uint8(dst[3] + ((t0 - t3 + 4) >> 3)); + dst += stride; + } + } +@@ -113,14 +115,13 @@ + static void vp8_idct_dc_add_c(uint8_t *dst, DCTELEM block[16], int stride) + { + int i, dc = (block[0] + 4) >> 3; +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP + dc; + block[0] = 0; + + for (i = 0; i < 4; i++) { +- dst[0] = cm[dst[0]]; +- dst[1] = cm[dst[1]]; +- dst[2] = cm[dst[2]]; +- dst[3] = cm[dst[3]]; ++ dst[0] = av_clip_uint8(dst[0] + dc); ++ dst[1] = av_clip_uint8(dst[1] + dc); ++ dst[2] = av_clip_uint8(dst[2] + dc); ++ dst[3] = av_clip_uint8(dst[3] + dc); + dst += stride; + } + } +@@ -523,4 +524,6 @@ + ff_vp8dsp_init_x86(dsp); + if (HAVE_ALTIVEC) + ff_vp8dsp_init_altivec(dsp); ++ if (ARCH_ARM) ++ ff_vp8dsp_init_arm(dsp); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8dsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8dsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8dsp.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8dsp.h 2012-05-14 14:08:54.457342457 +0200 +@@ -1,6 +1,4 @@ +-/** +- * VP8 compatible video decoder +- * ++/* + * Copyright (C) 2010 David Conrad + * Copyright (C) 2010 Ronald S. Bultje + * +@@ -21,6 +19,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * VP8 compatible video decoder ++ */ + + #ifndef AVCODEC_VP8DSP_H + #define AVCODEC_VP8DSP_H +@@ -79,5 +81,6 @@ + void ff_vp8dsp_init(VP8DSPContext *c); + void ff_vp8dsp_init_x86(VP8DSPContext *c); + void ff_vp8dsp_init_altivec(VP8DSPContext *c); ++void ff_vp8dsp_init_arm(VP8DSPContext *c); + + #endif /* AVCODEC_VP8DSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8.h 2012-05-14 14:08:54.453342376 +0200 +@@ -0,0 +1,251 @@ ++/** ++ * VP8 compatible video decoder ++ * ++ * Copyright (C) 2010 David Conrad ++ * Copyright (C) 2010 Ronald S. Bultje ++ * Copyright (C) 2010 Jason Garrett-Glaser ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_VP8_H ++#define AVCODEC_VP8_H ++ ++#include "vp56.h" ++#include "vp56data.h" ++#include "vp8dsp.h" ++#include "h264pred.h" ++ ++#define VP8_MAX_QUANT 127 ++ ++enum dct_token { ++ DCT_0, ++ DCT_1, ++ DCT_2, ++ DCT_3, ++ DCT_4, ++ DCT_CAT1, ++ DCT_CAT2, ++ DCT_CAT3, ++ DCT_CAT4, ++ DCT_CAT5, ++ DCT_CAT6, ++ DCT_EOB, ++ ++ NUM_DCT_TOKENS ++}; ++ ++// used to signal 4x4 intra pred in luma MBs ++#define MODE_I4x4 4 ++ ++enum inter_mvmode { ++ VP8_MVMODE_ZERO = MODE_I4x4 + 1, ++ VP8_MVMODE_MV, ++ VP8_MVMODE_SPLIT ++}; ++ ++enum inter_splitmvmode { ++ VP8_SPLITMVMODE_16x8 = 0, ///< 2 16x8 blocks (vertical) ++ VP8_SPLITMVMODE_8x16, ///< 2 8x16 blocks (horizontal) ++ VP8_SPLITMVMODE_8x8, ///< 2x2 blocks of 8x8px each ++ VP8_SPLITMVMODE_4x4, ///< 4x4 blocks of 4x4px each ++ VP8_SPLITMVMODE_NONE, ///< (only used in prediction) no split MVs ++}; ++ ++typedef struct { ++ uint8_t filter_level; ++ uint8_t inner_limit; ++ uint8_t inner_filter; ++} VP8FilterStrength; ++ ++typedef struct { ++ uint8_t skip; ++ // todo: make it possible to check for at least (i4x4 or split_mv) ++ // in one op. are others needed? ++ uint8_t mode; ++ uint8_t ref_frame; ++ uint8_t partitioning; ++ VP56mv mv; ++ VP56mv bmv[16]; ++} VP8Macroblock; ++ ++typedef struct { ++ AVCodecContext *avctx; ++ AVFrame *framep[4]; ++ AVFrame *next_framep[4]; ++ uint8_t *edge_emu_buffer; ++ ++ uint16_t mb_width; /* number of horizontal MB */ ++ uint16_t mb_height; /* number of vertical MB */ ++ int linesize; ++ int uvlinesize; ++ ++ uint8_t keyframe; ++ uint8_t deblock_filter; ++ uint8_t mbskip_enabled; ++ uint8_t segment; ///< segment of the current macroblock ++ uint8_t chroma_pred_mode; ///< 8x8c pred mode of the current macroblock ++ uint8_t profile; ++ VP56mv mv_min; ++ VP56mv mv_max; ++ ++ int8_t sign_bias[4]; ///< one state [0, 1] per ref frame type ++ int ref_count[3]; ++ ++ /** ++ * Base parameters for segmentation, i.e. per-macroblock parameters. ++ * These must be kept unchanged even if segmentation is not used for ++ * a frame, since the values persist between interframes. ++ */ ++ struct { ++ uint8_t enabled; ++ uint8_t absolute_vals; ++ uint8_t update_map; ++ int8_t base_quant[4]; ++ int8_t filter_level[4]; ///< base loop filter level ++ } segmentation; ++ ++ struct { ++ uint8_t simple; ++ uint8_t level; ++ uint8_t sharpness; ++ } filter; ++ ++ VP8Macroblock *macroblocks; ++ VP8FilterStrength *filter_strength; ++ ++ uint8_t *intra4x4_pred_mode_top; ++ uint8_t intra4x4_pred_mode_left[4]; ++ ++ /** ++ * Macroblocks can have one of 4 different quants in a frame when ++ * segmentation is enabled. ++ * If segmentation is disabled, only the first segment's values are used. ++ */ ++ struct { ++ // [0] - DC qmul [1] - AC qmul ++ int16_t luma_qmul[2]; ++ int16_t luma_dc_qmul[2]; ///< luma dc-only block quant ++ int16_t chroma_qmul[2]; ++ } qmat[4]; ++ ++ struct { ++ uint8_t enabled; ///< whether each mb can have a different strength based on mode/ref ++ ++ /** ++ * filter strength adjustment for the following macroblock modes: ++ * [0-3] - i16x16 (always zero) ++ * [4] - i4x4 ++ * [5] - zero mv ++ * [6] - inter modes except for zero or split mv ++ * [7] - split mv ++ * i16x16 modes never have any adjustment ++ */ ++ int8_t mode[VP8_MVMODE_SPLIT+1]; ++ ++ /** ++ * filter strength adjustment for macroblocks that reference: ++ * [0] - intra / VP56_FRAME_CURRENT ++ * [1] - VP56_FRAME_PREVIOUS ++ * [2] - VP56_FRAME_GOLDEN ++ * [3] - altref / VP56_FRAME_GOLDEN2 ++ */ ++ int8_t ref[4]; ++ } lf_delta; ++ ++ /** ++ * Cache of the top row needed for intra prediction ++ * 16 for luma, 8 for each chroma plane ++ */ ++ uint8_t (*top_border)[16+8+8]; ++ ++ /** ++ * For coeff decode, we need to know whether the above block had non-zero ++ * coefficients. This means for each macroblock, we need data for 4 luma ++ * blocks, 2 u blocks, 2 v blocks, and the luma dc block, for a total of 9 ++ * per macroblock. We keep the last row in top_nnz. ++ */ ++ uint8_t (*top_nnz)[9]; ++ DECLARE_ALIGNED(8, uint8_t, left_nnz)[9]; ++ ++ /** ++ * This is the index plus one of the last non-zero coeff ++ * for each of the blocks in the current macroblock. ++ * So, 0 -> no coeffs ++ * 1 -> dc-only (special transform) ++ * 2+-> full transform ++ */ ++ DECLARE_ALIGNED(16, uint8_t, non_zero_count_cache)[6][4]; ++ VP56RangeCoder c; ///< header context, includes mb modes and motion vectors ++ DECLARE_ALIGNED(16, DCTELEM, block)[6][4][16]; ++ DECLARE_ALIGNED(16, DCTELEM, block_dc)[16]; ++ uint8_t intra4x4_pred_mode_mb[16]; ++ ++ /** ++ * These are all of the updatable probabilities for binary decisions. ++ * They are only implictly reset on keyframes, making it quite likely ++ * for an interframe to desync if a prior frame's header was corrupt ++ * or missing outright! ++ */ ++ struct { ++ uint8_t segmentid[3]; ++ uint8_t mbskip; ++ uint8_t intra; ++ uint8_t last; ++ uint8_t golden; ++ uint8_t pred16x16[4]; ++ uint8_t pred8x8c[3]; ++ uint8_t token[4][16][3][NUM_DCT_TOKENS-1]; ++ uint8_t mvc[2][19]; ++ } prob[2]; ++ ++ VP8Macroblock *macroblocks_base; ++ int invisible; ++ int update_last; ///< update VP56_FRAME_PREVIOUS with the current one ++ int update_golden; ///< VP56_FRAME_NONE if not updated, or which frame to copy if so ++ int update_altref; ++ ++ /** ++ * If this flag is not set, all the probability updates ++ * are discarded after this frame is decoded. ++ */ ++ int update_probabilities; ++ ++ /** ++ * All coefficients are contained in separate arith coding contexts. ++ * There can be 1, 2, 4, or 8 of these after the header context. ++ */ ++ int num_coeff_partitions; ++ VP56RangeCoder coeff_partition[8]; ++ DSPContext dsp; ++ VP8DSPContext vp8dsp; ++ H264PredContext hpc; ++ vp8_mc_func put_pixels_tab[3][3][3]; ++ AVFrame frames[5]; ++ ++ /** ++ * A list of segmentation_map buffers that are to be free()'ed in ++ * the next decoding iteration. We can't free() them right away ++ * because the map may still be used by subsequent decoding threads. ++ * Unused if frame threading is off. ++ */ ++ uint8_t *segmentation_maps[5]; ++ int num_maps_to_be_freed; ++ int maps_are_invalid; ++} VP8Context; ++ ++#endif /* AVCODEC_VP8_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8_parser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8_parser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vp8_parser.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vp8_parser.c 2012-05-14 14:08:54.454342397 +0200 +@@ -25,7 +25,7 @@ + const uint8_t **poutbuf, int *poutbuf_size, + const uint8_t *buf, int buf_size) + { +- s->pict_type= (buf[0]&0x01) ? FF_P_TYPE : FF_I_TYPE; ++ s->pict_type= (buf[0]&0x01) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; + + *poutbuf = buf; + *poutbuf_size = buf_size; +@@ -33,8 +33,6 @@ + } + + AVCodecParser ff_vp8_parser = { +- { CODEC_ID_VP8 }, +- 0, +- NULL, +- parse, ++ .codec_ids = { CODEC_ID_VP8 }, ++ .parser_parse = parse, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vqavideo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vqavideo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/vqavideo.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/vqavideo.c 2012-05-14 14:08:54.459342497 +0200 +@@ -21,9 +21,9 @@ + + /** + * @file +- * VQA Video Decoder by Mike Melanson (melanson@pcisys.net) +- * For more information about the VQA format, visit: +- * http://wiki.multimedia.cx/index.php?title=VQA ++ * VQA Video Decoder ++ * @author Mike Melanson (melanson@pcisys.net) ++ * @see http://wiki.multimedia.cx/index.php?title=VQA + * + * The VQA video decoder outputs PAL8 or RGB555 colorspace data, depending + * on the type of data in the file. +@@ -68,7 +68,7 @@ + #include + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + + #define PALETTE_COUNT 256 +@@ -90,14 +90,6 @@ + #define CPLZ_TAG MKBETAG('C', 'P', 'L', 'Z') + #define VPTZ_TAG MKBETAG('V', 'P', 'T', 'Z') + +-#define VQA_DEBUG 0 +- +-#if VQA_DEBUG +-#define vqa_debug printf +-#else +-static inline void vqa_debug(const char *format, ...) { } +-#endif +- + typedef struct VqaContext { + + AVCodecContext *avctx; +@@ -146,6 +138,10 @@ + /* load up the VQA parameters from the header */ + vqa_header = (unsigned char *)s->avctx->extradata; + s->vqa_version = vqa_header[0]; ++ if (s->vqa_version < 1 || s->vqa_version > 3) { ++ av_log(s->avctx, AV_LOG_ERROR, " VQA video: unsupported version %d\n", s->vqa_version); ++ return -1; ++ } + s->width = AV_RL16(&vqa_header[6]); + s->height = AV_RL16(&vqa_header[8]); + if(av_image_check_size(s->width, s->height, 0, avctx)){ +@@ -187,6 +183,7 @@ + (s->height / s->vector_height) * 2; + s->decode_buffer = av_malloc(s->decode_buffer_size); + ++ avcodec_get_frame_defaults(&s->frame); + s->frame.data[0] = NULL; + + return 0; +@@ -212,7 +209,7 @@ + + while (src_index < src_size) { + +- vqa_debug(" opcode %02X: ", src[src_index]); ++ av_dlog(NULL, " opcode %02X: ", src[src_index]); + + /* 0x80 means that frame is finished */ + if (src[src_index] == 0x80) +@@ -231,8 +228,10 @@ + src_index += 2; + src_pos = AV_RL16(&src[src_index]); + src_index += 2; +- vqa_debug("(1) copy %X bytes from absolute pos %X\n", count, src_pos); ++ av_dlog(NULL, "(1) copy %X bytes from absolute pos %X\n", count, src_pos); + CHECK_COUNT(); ++ if (src_pos + count > dest_size) ++ return; + for (i = 0; i < count; i++) + dest[dest_index + i] = dest[src_pos + i]; + dest_index += count; +@@ -243,7 +242,7 @@ + count = AV_RL16(&src[src_index]); + src_index += 2; + color = src[src_index++]; +- vqa_debug("(2) set %X bytes to %02X\n", count, color); ++ av_dlog(NULL, "(2) set %X bytes to %02X\n", count, color); + CHECK_COUNT(); + memset(&dest[dest_index], color, count); + dest_index += count; +@@ -253,8 +252,10 @@ + count = (src[src_index++] & 0x3F) + 3; + src_pos = AV_RL16(&src[src_index]); + src_index += 2; +- vqa_debug("(3) copy %X bytes from absolute pos %X\n", count, src_pos); ++ av_dlog(NULL, "(3) copy %X bytes from absolute pos %X\n", count, src_pos); + CHECK_COUNT(); ++ if (src_pos + count > dest_size) ++ return; + for (i = 0; i < count; i++) + dest[dest_index + i] = dest[src_pos + i]; + dest_index += count; +@@ -262,7 +263,7 @@ + } else if (src[src_index] > 0x80) { + + count = src[src_index++] & 0x3F; +- vqa_debug("(4) copy %X bytes from source to dest\n", count); ++ av_dlog(NULL, "(4) copy %X bytes from source to dest\n", count); + CHECK_COUNT(); + memcpy(&dest[dest_index], &src[src_index], count); + src_index += count; +@@ -273,8 +274,10 @@ + count = ((src[src_index] & 0x70) >> 4) + 3; + src_pos = AV_RB16(&src[src_index]) & 0x0FFF; + src_index += 2; +- vqa_debug("(5) copy %X bytes from relpos %X\n", count, src_pos); ++ av_dlog(NULL, "(5) copy %X bytes from relpos %X\n", count, src_pos); + CHECK_COUNT(); ++ if (dest_index < src_pos) ++ return; + for (i = 0; i < count; i++) + dest[dest_index + i] = dest[dest_index - src_pos + i]; + dest_index += count; +@@ -319,10 +322,17 @@ + int hibytes = s->decode_buffer_size / 2; + + /* first, traverse through the frame and find the subchunks */ +- while (index < s->size) { ++ while (index + CHUNK_PREAMBLE_SIZE <= s->size) { ++ unsigned next_index; + + chunk_type = AV_RB32(&s->buf[index]); + chunk_size = AV_RB32(&s->buf[index + 4]); ++ byte_skip = chunk_size & 0x01; ++ next_index = index + CHUNK_PREAMBLE_SIZE + chunk_size + byte_skip; ++ if (next_index > s->size) { ++ av_log(s->avctx, AV_LOG_ERROR, "Dropping incomplete chunk\n"); ++ break; ++ } + + switch (chunk_type) { + +@@ -363,9 +373,7 @@ + chunk_type); + break; + } +- +- byte_skip = chunk_size & 0x01; +- index += (CHUNK_PREAMBLE_SIZE + chunk_size + byte_skip); ++ index = next_index; + } + + /* next, deal with the palette */ +@@ -399,7 +407,8 @@ + r = s->buf[cpl0_chunk++] * 4; + g = s->buf[cpl0_chunk++] * 4; + b = s->buf[cpl0_chunk++] * 4; +- s->palette[i] = (r << 16) | (g << 8) | (b); ++ s->palette[i] = 0xFF << 24 | r << 16 | g << 8 | b; ++ s->palette[i] |= s->palette[i] >> 6 & 0x30303; + } + } + +@@ -464,8 +473,6 @@ + switch (s->vqa_version) { + + case 1: +-/* still need sample media for this case (only one game, "Legend of +- * Kyrandia III : Malcolm's Revenge", is known to use this version) */ + lobyte = s->decode_buffer[lobytes * 2]; + hibyte = s->decode_buffer[(lobytes * 2) + 1]; + vector_index = ((hibyte << 8) | lobyte) >> 3; +@@ -610,14 +617,13 @@ + } + + AVCodec ff_vqa_decoder = { +- "vqavideo", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WS_VQA, +- sizeof(VqaContext), +- vqa_decode_init, +- NULL, +- vqa_decode_end, +- vqa_decode_frame, +- CODEC_CAP_DR1, ++ .name = "vqavideo", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WS_VQA, ++ .priv_data_size = sizeof(VqaContext), ++ .init = vqa_decode_init, ++ .close = vqa_decode_end, ++ .decode = vqa_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA (Vector Quantized Animation) video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/w32pthreads.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/w32pthreads.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/w32pthreads.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/w32pthreads.h 2012-05-14 14:08:54.460342517 +0200 +@@ -0,0 +1,268 @@ ++/* ++ * Copyright (C) 2010-2011 x264 project ++ * ++ * Authors: Steven Walters ++ * Pegasys Inc. ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * w32threads to pthreads wrapper ++ */ ++ ++#ifndef AVCODEC_W32PTHREADS_H ++#define AVCODEC_W32PTHREADS_H ++ ++/* Build up a pthread-like API using underlying Windows API. Have only static ++ * methods so as to not conflict with a potentially linked in pthread-win32 ++ * library. ++ * As most functions here are used without checking return values, ++ * only implement return values as necessary. */ ++ ++#define WIN32_LEAN_AND_MEAN ++#include ++#include ++ ++typedef struct { ++ void *handle; ++ void *(*func)(void* arg); ++ void *arg; ++ void *ret; ++} pthread_t; ++ ++/* the conditional variable api for windows 6.0+ uses critical sections and ++ * not mutexes */ ++typedef CRITICAL_SECTION pthread_mutex_t; ++ ++/* This is the CONDITIONAL_VARIABLE typedef for using Window's native ++ * conditional variables on kernels 6.0+. ++ * MinGW does not currently have this typedef. */ ++typedef struct { ++ void *ptr; ++} pthread_cond_t; ++ ++/* function pointers to conditional variable API on windows 6.0+ kernels */ ++static void (WINAPI *cond_broadcast)(pthread_cond_t *cond); ++static void (WINAPI *cond_init)(pthread_cond_t *cond); ++static void (WINAPI *cond_signal)(pthread_cond_t *cond); ++static BOOL (WINAPI *cond_wait)(pthread_cond_t *cond, pthread_mutex_t *mutex, ++ DWORD milliseconds); ++ ++static unsigned __stdcall attribute_align_arg win32thread_worker(void *arg) ++{ ++ pthread_t *h = arg; ++ h->ret = h->func(h->arg); ++ return 0; ++} ++ ++static int pthread_create(pthread_t *thread, const void *unused_attr, ++ void *(*start_routine)(void*), void *arg) ++{ ++ thread->func = start_routine; ++ thread->arg = arg; ++ thread->handle = (void*)_beginthreadex(NULL, 0, win32thread_worker, thread, ++ 0, NULL); ++ return !thread->handle; ++} ++ ++static void pthread_join(pthread_t thread, void **value_ptr) ++{ ++ DWORD ret = WaitForSingleObject(thread.handle, INFINITE); ++ if (ret != WAIT_OBJECT_0) ++ return; ++ if (value_ptr) ++ *value_ptr = thread.ret; ++ CloseHandle(thread.handle); ++} ++ ++static inline int pthread_mutex_init(pthread_mutex_t *m, void* attr) ++{ ++ InitializeCriticalSection(m); ++ return 0; ++} ++static inline int pthread_mutex_destroy(pthread_mutex_t *m) ++{ ++ DeleteCriticalSection(m); ++ return 0; ++} ++static inline int pthread_mutex_lock(pthread_mutex_t *m) ++{ ++ EnterCriticalSection(m); ++ return 0; ++} ++static inline int pthread_mutex_unlock(pthread_mutex_t *m) ++{ ++ LeaveCriticalSection(m); ++ return 0; ++} ++ ++/* for pre-Windows 6.0 platforms we need to define and use our own condition ++ * variable and api */ ++typedef struct { ++ pthread_mutex_t mtx_broadcast; ++ pthread_mutex_t mtx_waiter_count; ++ volatile int waiter_count; ++ HANDLE semaphore; ++ HANDLE waiters_done; ++ volatile int is_broadcast; ++} win32_cond_t; ++ ++static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr) ++{ ++ win32_cond_t *win32_cond = NULL; ++ if (cond_init) { ++ cond_init(cond); ++ return; ++ } ++ ++ /* non native condition variables */ ++ win32_cond = av_mallocz(sizeof(win32_cond_t)); ++ if (!win32_cond) ++ return; ++ cond->ptr = win32_cond; ++ win32_cond->semaphore = CreateSemaphore(NULL, 0, 0x7fffffff, NULL); ++ if (!win32_cond->semaphore) ++ return; ++ win32_cond->waiters_done = CreateEvent(NULL, TRUE, FALSE, NULL); ++ if (!win32_cond->waiters_done) ++ return; ++ ++ pthread_mutex_init(&win32_cond->mtx_waiter_count, NULL); ++ pthread_mutex_init(&win32_cond->mtx_broadcast, NULL); ++} ++ ++static void pthread_cond_destroy(pthread_cond_t *cond) ++{ ++ win32_cond_t *win32_cond = cond->ptr; ++ /* native condition variables do not destroy */ ++ if (cond_init) ++ return; ++ ++ /* non native condition variables */ ++ CloseHandle(win32_cond->semaphore); ++ CloseHandle(win32_cond->waiters_done); ++ pthread_mutex_destroy(&win32_cond->mtx_waiter_count); ++ pthread_mutex_destroy(&win32_cond->mtx_broadcast); ++ av_freep(&win32_cond); ++ cond->ptr = NULL; ++} ++ ++static void pthread_cond_broadcast(pthread_cond_t *cond) ++{ ++ win32_cond_t *win32_cond = cond->ptr; ++ int have_waiter; ++ ++ if (cond_broadcast) { ++ cond_broadcast(cond); ++ return; ++ } ++ ++ /* non native condition variables */ ++ pthread_mutex_lock(&win32_cond->mtx_broadcast); ++ pthread_mutex_lock(&win32_cond->mtx_waiter_count); ++ have_waiter = 0; ++ ++ if (win32_cond->waiter_count) { ++ win32_cond->is_broadcast = 1; ++ have_waiter = 1; ++ } ++ ++ if (have_waiter) { ++ ReleaseSemaphore(win32_cond->semaphore, win32_cond->waiter_count, NULL); ++ pthread_mutex_unlock(&win32_cond->mtx_waiter_count); ++ WaitForSingleObject(win32_cond->waiters_done, INFINITE); ++ ResetEvent(win32_cond->waiters_done); ++ win32_cond->is_broadcast = 0; ++ } else ++ pthread_mutex_unlock(&win32_cond->mtx_waiter_count); ++ pthread_mutex_unlock(&win32_cond->mtx_broadcast); ++} ++ ++static void pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) ++{ ++ win32_cond_t *win32_cond = cond->ptr; ++ int last_waiter; ++ if (cond_wait) { ++ cond_wait(cond, mutex, INFINITE); ++ return; ++ } ++ ++ /* non native condition variables */ ++ pthread_mutex_lock(&win32_cond->mtx_broadcast); ++ pthread_mutex_lock(&win32_cond->mtx_waiter_count); ++ win32_cond->waiter_count++; ++ pthread_mutex_unlock(&win32_cond->mtx_waiter_count); ++ pthread_mutex_unlock(&win32_cond->mtx_broadcast); ++ ++ // unlock the external mutex ++ pthread_mutex_unlock(mutex); ++ WaitForSingleObject(win32_cond->semaphore, INFINITE); ++ ++ pthread_mutex_lock(&win32_cond->mtx_waiter_count); ++ win32_cond->waiter_count--; ++ last_waiter = !win32_cond->waiter_count || !win32_cond->is_broadcast; ++ pthread_mutex_unlock(&win32_cond->mtx_waiter_count); ++ ++ if (last_waiter) ++ SetEvent(win32_cond->waiters_done); ++ ++ // lock the external mutex ++ return pthread_mutex_lock(mutex); ++} ++ ++static void pthread_cond_signal(pthread_cond_t *cond) ++{ ++ win32_cond_t *win32_cond = cond->ptr; ++ int have_waiter; ++ if (cond_signal) { ++ cond_signal(cond); ++ return; ++ } ++ ++ pthread_mutex_lock(&win32_cond->mtx_broadcast); ++ ++ /* non-native condition variables */ ++ pthread_mutex_lock(&win32_cond->mtx_waiter_count); ++ have_waiter = win32_cond->waiter_count; ++ pthread_mutex_unlock(&win32_cond->mtx_waiter_count); ++ ++ if (have_waiter) { ++ ReleaseSemaphore(win32_cond->semaphore, 1, NULL); ++ WaitForSingleObject(win32_cond->waiters_done, INFINITE); ++ ResetEvent(win32_cond->waiters_done); ++ } ++ ++ pthread_mutex_unlock(&win32_cond->mtx_broadcast); ++} ++ ++static void w32thread_init(void) ++{ ++ HANDLE kernel_dll = GetModuleHandle(TEXT("kernel32.dll")); ++ /* if one is available, then they should all be available */ ++ cond_init = ++ (void*)GetProcAddress(kernel_dll, "InitializeConditionVariable"); ++ cond_broadcast = ++ (void*)GetProcAddress(kernel_dll, "WakeAllConditionVariable"); ++ cond_signal = ++ (void*)GetProcAddress(kernel_dll, "WakeConditionVariable"); ++ cond_wait = ++ (void*)GetProcAddress(kernel_dll, "SleepConditionVariableCS"); ++} ++ ++#endif /* AVCODEC_W32PTHREADS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/w32thread.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/w32thread.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/w32thread.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/w32thread.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,170 +0,0 @@ +-/* +- * Copyright (c) 2004 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +-//#define DEBUG +- +-#include "avcodec.h" +- +-#define WIN32_LEAN_AND_MEAN +-#include +-#include +- +-typedef struct ThreadContext{ +- AVCodecContext *avctx; +- HANDLE thread; +- HANDLE work_sem; +- HANDLE job_sem; +- HANDLE done_sem; +- int (*func)(AVCodecContext *c, void *arg); +- int (*func2)(AVCodecContext *c, void *arg, int, int); +- void *arg; +- int argsize; +- int *jobnr; +- int *ret; +- int threadnr; +-}ThreadContext; +- +- +-static unsigned WINAPI attribute_align_arg thread_func(void *v){ +- ThreadContext *c= v; +- +- for(;;){ +- int ret, jobnr; +-//printf("thread_func %X enter wait\n", (int)v); fflush(stdout); +- WaitForSingleObject(c->work_sem, INFINITE); +- // avoid trying to access jobnr if we should quit +- if (!c->func && !c->func2) +- break; +- WaitForSingleObject(c->job_sem, INFINITE); +- jobnr = (*c->jobnr)++; +- ReleaseSemaphore(c->job_sem, 1, 0); +-//printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); +- if(c->func) +- ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize); +- else +- ret= c->func2(c->avctx, c->arg, jobnr, c->threadnr); +- if (c->ret) +- c->ret[jobnr] = ret; +-//printf("thread_func %X signal complete\n", (int)v); fflush(stdout); +- ReleaseSemaphore(c->done_sem, 1, 0); +- } +- +- return 0; +-} +- +-/** +- * Free what has been allocated by avcodec_thread_init(). +- * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. +- */ +-void avcodec_thread_free(AVCodecContext *s){ +- ThreadContext *c= s->thread_opaque; +- int i; +- +- for(i=0; ithread_count; i++){ +- +- c[i].func= NULL; +- c[i].func2= NULL; +- } +- ReleaseSemaphore(c[0].work_sem, s->thread_count, 0); +- for(i=0; ithread_count; i++){ +- WaitForSingleObject(c[i].thread, INFINITE); +- if(c[i].thread) CloseHandle(c[i].thread); +- } +- if(c[0].work_sem) CloseHandle(c[0].work_sem); +- if(c[0].job_sem) CloseHandle(c[0].job_sem); +- if(c[0].done_sem) CloseHandle(c[0].done_sem); +- +- av_freep(&s->thread_opaque); +-} +- +-static int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){ +- ThreadContext *c= s->thread_opaque; +- int i; +- int jobnr = 0; +- +- assert(s == c->avctx); +- +- /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ +- +- for(i=0; ithread_count; i++){ +- c[i].arg= arg; +- c[i].argsize= size; +- c[i].func= func; +- c[i].ret= ret; +- c[i].jobnr = &jobnr; +- } +- ReleaseSemaphore(c[0].work_sem, count, 0); +- for(i=0; ithread_opaque; +- int i; +- for(i=0; ithread_count; i++) +- c[i].func2 = func; +- avcodec_thread_execute(s, NULL, arg, ret, count, 0); +-} +- +-int avcodec_thread_init(AVCodecContext *s, int thread_count){ +- int i; +- ThreadContext *c; +- uint32_t threadid; +- +- s->thread_count= thread_count; +-av_log(NULL, AV_LOG_INFO, "[w32thread] thread count = %d\n", thread_count); +- if (thread_count <= 1) +- return 0; +- +- assert(!s->thread_opaque); +- c= av_mallocz(sizeof(ThreadContext)*thread_count); +- s->thread_opaque= c; +- if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) +- goto fail; +- if(!(c[0].job_sem = CreateSemaphore(NULL, 1, 1, NULL))) +- goto fail; +- if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) +- goto fail; +- +- for(i=0; iexecute= avcodec_thread_execute; +- s->execute2= avcodec_thread_execute2; +- +- return 0; +-fail: +- avcodec_thread_free(s); +- return -1; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wavpack.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wavpack.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wavpack.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wavpack.c 2012-05-14 14:08:54.465342618 +0200 +@@ -18,7 +18,10 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +-#define ALT_BITSTREAM_READER_LE ++ ++#define BITSTREAM_READER_LE ++ ++#include "libavutil/audioconvert.h" + #include "avcodec.h" + #include "get_bits.h" + #include "unary.h" +@@ -28,9 +31,9 @@ + * WavPack lossless audio decoder + */ + +-#define WV_MONO 0x00000004 +-#define WV_JOINT_STEREO 0x00000010 +-#define WV_FALSE_STEREO 0x40000000 ++#define WV_MONO 0x00000004 ++#define WV_JOINT_STEREO 0x00000010 ++#define WV_FALSE_STEREO 0x40000000 + + #define WV_HYBRID_MODE 0x00000008 + #define WV_HYBRID_SHAPE 0x00000008 +@@ -43,14 +46,14 @@ + #define WV_FLT_ZERO_SENT 0x08 + #define WV_FLT_ZERO_SIGN 0x10 + +-enum WP_ID_Flags{ ++enum WP_ID_Flags { + WP_IDF_MASK = 0x1F, + WP_IDF_IGNORE = 0x20, + WP_IDF_ODD = 0x40, + WP_IDF_LONG = 0x80 + }; + +-enum WP_ID{ ++enum WP_ID { + WP_ID_DUMMY = 0, + WP_ID_ENCINFO, + WP_ID_DECTERMS, +@@ -110,12 +113,11 @@ + int and, or, shift; + int post_shift; + int hybrid, hybrid_bitrate; ++ int hybrid_maxclip, hybrid_minclip; + int float_flag; + int float_shift; + int float_max_exp; + WvChannel ch[2]; +- int samples_left; +- int max_samples; + int pos; + SavedContext sc, extra_sc; + } WavpackFrameContext; +@@ -124,6 +126,7 @@ + + typedef struct WavpackContext { + AVCodecContext *avctx; ++ AVFrame frame; + + WavpackFrameContext *fdec[WV_MAX_FRAME_DECODERS]; + int fdec_num; +@@ -132,7 +135,6 @@ + int mkv_mode; + int block; + int samples; +- int samples_left; + int ch_offset; + } WavpackContext; + +@@ -179,7 +181,7 @@ + { + int res, neg = 0; + +- if(val < 0){ ++ if (val < 0) { + val = -val; + neg = 1; + } +@@ -194,13 +196,13 @@ + { + int bits; + +- if(!val) ++ if (!val) + return 0; +- if(val == 1) ++ if (val == 1) + return 256; + val += val >> 9; + bits = av_log2(val) + 1; +- if(bits < 9) ++ if (bits < 9) + return (bits << 8) + wp_log2_table[(val << (9 - bits)) & 0xFF]; + else + return (bits << 8) + wp_log2_table[(val >> (bits - 9)) & 0xFF]; +@@ -210,33 +212,35 @@ + + // macros for manipulating median values + #define GET_MED(n) ((c->median[n] >> 4) + 1) +-#define DEC_MED(n) c->median[n] -= ((c->median[n] + (128>>n) - 2) / (128>>n)) * 2 +-#define INC_MED(n) c->median[n] += ((c->median[n] + (128>>n)) / (128>>n)) * 5 ++#define DEC_MED(n) c->median[n] -= ((c->median[n] + (128 >> n) - 2) / (128 >> n)) * 2 ++#define INC_MED(n) c->median[n] += ((c->median[n] + (128 >> n) ) / (128 >> n)) * 5 + + // macros for applying weight + #define UPDATE_WEIGHT_CLIP(weight, delta, samples, in) \ +- if(samples && in){ \ +- if((samples ^ in) < 0){ \ +- weight -= delta; \ +- if(weight < -1024) weight = -1024; \ +- }else{ \ +- weight += delta; \ +- if(weight > 1024) weight = 1024; \ +- } \ +- } ++ if (samples && in) { \ ++ if ((samples ^ in) < 0) { \ ++ weight -= delta; \ ++ if (weight < -1024) \ ++ weight = -1024; \ ++ } else { \ ++ weight += delta; \ ++ if (weight > 1024) \ ++ weight = 1024; \ ++ } \ ++ } + + + static av_always_inline int get_tail(GetBitContext *gb, int k) + { + int p, e, res; + +- if(k<1)return 0; ++ if (k < 1) ++ return 0; + p = av_log2(k); + e = (1 << (p + 1)) - k - 1; + res = p ? get_bits(gb, p) : 0; +- if(res >= e){ +- res = (res<<1) - e + get_bits1(gb); +- } ++ if (res >= e) ++ res = (res << 1) - e + get_bits1(gb); + return res; + } + +@@ -244,37 +248,38 @@ + { + int i, br[2], sl[2]; + +- for(i = 0; i <= ctx->stereo_in; i++){ ++ for (i = 0; i <= ctx->stereo_in; i++) { + ctx->ch[i].bitrate_acc += ctx->ch[i].bitrate_delta; + br[i] = ctx->ch[i].bitrate_acc >> 16; + sl[i] = LEVEL_DECAY(ctx->ch[i].slow_level); + } +- if(ctx->stereo_in && ctx->hybrid_bitrate){ ++ if (ctx->stereo_in && ctx->hybrid_bitrate) { + int balance = (sl[1] - sl[0] + br[1] + 1) >> 1; +- if(balance > br[0]){ ++ if (balance > br[0]) { + br[1] = br[0] << 1; + br[0] = 0; +- }else if(-balance > br[0]){ ++ } else if (-balance > br[0]) { + br[0] <<= 1; + br[1] = 0; +- }else{ ++ } else { + br[1] = br[0] + balance; + br[0] = br[0] - balance; + } + } +- for(i = 0; i <= ctx->stereo_in; i++){ +- if(ctx->hybrid_bitrate){ +- if(sl[i] - br[i] > -0x100) ++ for (i = 0; i <= ctx->stereo_in; i++) { ++ if (ctx->hybrid_bitrate) { ++ if (sl[i] - br[i] > -0x100) + ctx->ch[i].error_limit = wp_exp2(sl[i] - br[i] + 0x100); + else + ctx->ch[i].error_limit = 0; +- }else{ ++ } else { + ctx->ch[i].error_limit = wp_exp2(br[i]); + } + } + } + +-static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, int channel, int *last) ++static int wv_get_value(WavpackFrameContext *ctx, GetBitContext *gb, ++ int channel, int *last) + { + int t, t2; + int sign, base, add, ret; +@@ -282,18 +287,26 @@ + + *last = 0; + +- if((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && !ctx->zero && !ctx->one){ +- if(ctx->zeroes){ ++ if ((ctx->ch[0].median[0] < 2U) && (ctx->ch[1].median[0] < 2U) && ++ !ctx->zero && !ctx->one) { ++ if (ctx->zeroes) { + ctx->zeroes--; +- if(ctx->zeroes){ ++ if (ctx->zeroes) { + c->slow_level -= LEVEL_DECAY(c->slow_level); + return 0; + } +- }else{ ++ } else { + t = get_unary_0_33(gb); +- if(t >= 2) t = get_bits(gb, t - 1) | (1 << (t-1)); ++ if (t >= 2) { ++ if (get_bits_left(gb) < t - 1) ++ goto error; ++ t = get_bits(gb, t - 1) | (1 << (t-1)); ++ } else { ++ if (get_bits_left(gb) < 0) ++ goto error; ++ } + ctx->zeroes = t; +- if(ctx->zeroes){ ++ if (ctx->zeroes) { + memset(ctx->ch[0].median, 0, sizeof(ctx->ch[0].median)); + memset(ctx->ch[1].median, 0, sizeof(ctx->ch[1].median)); + c->slow_level -= LEVEL_DECAY(c->slow_level); +@@ -302,95 +315,110 @@ + } + } + +- if(get_bits_count(gb) >= ctx->data_size){ +- *last = 1; +- return 0; +- } +- +- if(ctx->zero){ ++ if (ctx->zero) { + t = 0; + ctx->zero = 0; +- }else{ ++ } else { + t = get_unary_0_33(gb); +- if(get_bits_count(gb) >= ctx->data_size){ +- *last = 1; +- return 0; +- } +- if(t == 16) { ++ if (get_bits_left(gb) < 0) ++ goto error; ++ if (t == 16) { + t2 = get_unary_0_33(gb); +- if(t2 < 2) t += t2; +- else t += get_bits(gb, t2 - 1) | (1 << (t2 - 1)); ++ if (t2 < 2) { ++ if (get_bits_left(gb) < 0) ++ goto error; ++ t += t2; ++ } else { ++ if (get_bits_left(gb) < t2 - 1) ++ goto error; ++ t += get_bits(gb, t2 - 1) | (1 << (t2 - 1)); ++ } + } + +- if(ctx->one){ +- ctx->one = t&1; +- t = (t>>1) + 1; +- }else{ +- ctx->one = t&1; ++ if (ctx->one) { ++ ctx->one = t & 1; ++ t = (t >> 1) + 1; ++ } else { ++ ctx->one = t & 1; + t >>= 1; + } + ctx->zero = !ctx->one; + } + +- if(ctx->hybrid && !channel) ++ if (ctx->hybrid && !channel) + update_error_limit(ctx); + +- if(!t){ ++ if (!t) { + base = 0; +- add = GET_MED(0) - 1; ++ add = GET_MED(0) - 1; + DEC_MED(0); +- }else if(t == 1){ ++ } else if (t == 1) { + base = GET_MED(0); +- add = GET_MED(1) - 1; ++ add = GET_MED(1) - 1; + INC_MED(0); + DEC_MED(1); +- }else if(t == 2){ ++ } else if (t == 2) { + base = GET_MED(0) + GET_MED(1); +- add = GET_MED(2) - 1; ++ add = GET_MED(2) - 1; + INC_MED(0); + INC_MED(1); + DEC_MED(2); +- }else{ ++ } else { + base = GET_MED(0) + GET_MED(1) + GET_MED(2) * (t - 2); +- add = GET_MED(2) - 1; ++ add = GET_MED(2) - 1; + INC_MED(0); + INC_MED(1); + INC_MED(2); + } +- if(!c->error_limit){ ++ if (!c->error_limit) { + ret = base + get_tail(gb, add); +- }else{ +- int mid = (base*2 + add + 1) >> 1; +- while(add > c->error_limit){ +- if(get_bits1(gb)){ ++ if (get_bits_left(gb) <= 0) ++ goto error; ++ } else { ++ int mid = (base * 2 + add + 1) >> 1; ++ while (add > c->error_limit) { ++ if (get_bits_left(gb) <= 0) ++ goto error; ++ if (get_bits1(gb)) { + add -= (mid - base); + base = mid; +- }else ++ } else + add = mid - base - 1; +- mid = (base*2 + add + 1) >> 1; ++ mid = (base * 2 + add + 1) >> 1; + } + ret = mid; + } + sign = get_bits1(gb); +- if(ctx->hybrid_bitrate) ++ if (ctx->hybrid_bitrate) + c->slow_level += wp_log2(ret) - LEVEL_DECAY(c->slow_level); + return sign ? ~ret : ret; ++ ++error: ++ *last = 1; ++ return 0; + } + +-static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, int S) ++static inline int wv_get_value_integer(WavpackFrameContext *s, uint32_t *crc, ++ int S) + { + int bit; + +- if(s->extra_bits){ ++ if (s->extra_bits){ + S <<= s->extra_bits; + +- if(s->got_extra_bits){ ++ if (s->got_extra_bits && get_bits_left(&s->gb_extra_bits) >= s->extra_bits) { + S |= get_bits(&s->gb_extra_bits, s->extra_bits); +- *crc = *crc * 9 + (S&0xffff) * 3 + ((unsigned)S>>16); ++ *crc = *crc * 9 + (S & 0xffff) * 3 + ((unsigned)S >> 16); + } + } ++ + bit = (S & s->and) | s->or; +- return (((S + bit) << s->shift) - bit) << s->post_shift; ++ bit = ((S + bit) << s->shift) - bit; ++ ++ if (s->hybrid) ++ bit = av_clip(bit, s->hybrid_minclip, s->hybrid_maxclip); ++ ++ return bit << s->post_shift; + } + + static float wv_get_value_float(WavpackFrameContext *s, uint32_t *crc, int S) +@@ -403,58 +431,58 @@ + int sign; + int exp = s->float_max_exp; + +- if(s->got_extra_bits){ +- const int max_bits = 1 + 23 + 8 + 1; ++ if (s->got_extra_bits) { ++ const int max_bits = 1 + 23 + 8 + 1; + const int left_bits = get_bits_left(&s->gb_extra_bits); + +- if(left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits) ++ if (left_bits + 8 * FF_INPUT_BUFFER_PADDING_SIZE < max_bits) + return 0.0; + } + +- if(S){ ++ if (S) { + S <<= s->float_shift; + sign = S < 0; +- if(sign) ++ if (sign) + S = -S; +- if(S >= 0x1000000){ +- if(s->got_extra_bits && get_bits1(&s->gb_extra_bits)){ ++ if (S >= 0x1000000) { ++ if (s->got_extra_bits && get_bits1(&s->gb_extra_bits)) + S = get_bits(&s->gb_extra_bits, 23); +- }else{ ++ else + S = 0; +- } + exp = 255; +- }else if(exp){ ++ } else if (exp) { + int shift = 23 - av_log2(S); + exp = s->float_max_exp; +- if(exp <= shift){ ++ if (exp <= shift) + shift = --exp; +- } + exp -= shift; + +- if(shift){ ++ if (shift) { + S <<= shift; +- if((s->float_flag & WV_FLT_SHIFT_ONES) || +- (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) && get_bits1(&s->gb_extra_bits)) ){ ++ if ((s->float_flag & WV_FLT_SHIFT_ONES) || ++ (s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SAME) && ++ get_bits1(&s->gb_extra_bits))) { + S |= (1 << shift) - 1; +- } else if(s->got_extra_bits && (s->float_flag & WV_FLT_SHIFT_SENT)){ ++ } else if (s->got_extra_bits && ++ (s->float_flag & WV_FLT_SHIFT_SENT)) { + S |= get_bits(&s->gb_extra_bits, shift); + } + } +- }else{ ++ } else { + exp = s->float_max_exp; + } + S &= 0x7fffff; +- }else{ ++ } else { + sign = 0; + exp = 0; +- if(s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)){ +- if(get_bits1(&s->gb_extra_bits)){ ++ if (s->got_extra_bits && (s->float_flag & WV_FLT_ZERO_SENT)) { ++ if (get_bits1(&s->gb_extra_bits)) { + S = get_bits(&s->gb_extra_bits, 23); +- if(s->float_max_exp >= 25) ++ if (s->float_max_exp >= 25) + exp = get_bits(&s->gb_extra_bits, 8); + sign = get_bits1(&s->gb_extra_bits); +- }else{ +- if(s->float_flag & WV_FLT_ZERO_SIGN) ++ } else { ++ if (s->float_flag & WV_FLT_ZERO_SIGN) + sign = get_bits1(&s->gb_extra_bits); + } + } +@@ -472,7 +500,8 @@ + s->sc.crc = s->extra_sc.crc = 0xFFFFFFFF; + } + +-static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) ++static inline int wv_unpack_stereo(WavpackFrameContext *s, GetBitContext *gb, ++ void *dst, const int type) + { + int i, j, count = 0; + int last, t; +@@ -485,71 +514,72 @@ + float *dstfl = dst; + const int channel_pad = s->avctx->channels - 2; + +- if(s->samples_left == s->samples) +- s->one = s->zero = s->zeroes = 0; +- do{ ++ s->one = s->zero = s->zeroes = 0; ++ do { + L = wv_get_value(s, gb, 0, &last); +- if(last) break; ++ if (last) ++ break; + R = wv_get_value(s, gb, 1, &last); +- if(last) break; +- for(i = 0; i < s->terms; i++){ ++ if (last) ++ break; ++ for (i = 0; i < s->terms; i++) { + t = s->decorr[i].value; +- if(t > 0){ +- if(t > 8){ +- if(t & 1){ ++ if (t > 0) { ++ if (t > 8) { ++ if (t & 1) { + A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]; + B = 2 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]; +- }else{ ++ } else { + A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1; + B = (3 * s->decorr[i].samplesB[0] - s->decorr[i].samplesB[1]) >> 1; + } + s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0]; + s->decorr[i].samplesB[1] = s->decorr[i].samplesB[0]; + j = 0; +- }else{ ++ } else { + A = s->decorr[i].samplesA[pos]; + B = s->decorr[i].samplesB[pos]; + j = (pos + t) & 7; + } +- if(type != AV_SAMPLE_FMT_S16){ ++ if (type != AV_SAMPLE_FMT_S16) { + L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10); + R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10); +- }else{ ++ } else { + L2 = L + ((s->decorr[i].weightA * A + 512) >> 10); + R2 = R + ((s->decorr[i].weightB * B + 512) >> 10); + } +- if(A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; +- if(B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta; ++ if (A && L) s->decorr[i].weightA -= ((((L ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; ++ if (B && R) s->decorr[i].weightB -= ((((R ^ B) >> 30) & 2) - 1) * s->decorr[i].delta; + s->decorr[i].samplesA[j] = L = L2; + s->decorr[i].samplesB[j] = R = R2; +- }else if(t == -1){ +- if(type != AV_SAMPLE_FMT_S16) ++ } else if (t == -1) { ++ if (type != AV_SAMPLE_FMT_S16) + L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10); + else + L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10); + UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L); + L = L2; +- if(type != AV_SAMPLE_FMT_S16) ++ if (type != AV_SAMPLE_FMT_S16) + R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10); + else + R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10); + UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, L2, R); + R = R2; + s->decorr[i].samplesA[0] = R; +- }else{ +- if(type != AV_SAMPLE_FMT_S16) ++ } else { ++ if (type != AV_SAMPLE_FMT_S16) + R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10); + else + R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10); + UPDATE_WEIGHT_CLIP(s->decorr[i].weightB, s->decorr[i].delta, s->decorr[i].samplesB[0], R); + R = R2; + +- if(t == -3){ ++ if (t == -3) { + R2 = s->decorr[i].samplesA[0]; + s->decorr[i].samplesA[0] = R; + } + +- if(type != AV_SAMPLE_FMT_S16) ++ if (type != AV_SAMPLE_FMT_S16) + L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10); + else + L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10); +@@ -559,15 +589,15 @@ + } + } + pos = (pos + 1) & 7; +- if(s->joint) ++ if (s->joint) + L += (R -= (L >> 1)); + crc = (crc * 3 + L) * 3 + R; + +- if(type == AV_SAMPLE_FMT_FLT){ ++ if (type == AV_SAMPLE_FMT_FLT) { + *dstfl++ = wv_get_value_float(s, &crc_extra_bits, L); + *dstfl++ = wv_get_value_float(s, &crc_extra_bits, R); + dstfl += channel_pad; +- } else if(type == AV_SAMPLE_FMT_S32){ ++ } else if (type == AV_SAMPLE_FMT_S32) { + *dst32++ = wv_get_value_integer(s, &crc_extra_bits, L); + *dst32++ = wv_get_value_integer(s, &crc_extra_bits, R); + dst32 += channel_pad; +@@ -577,32 +607,23 @@ + dst16 += channel_pad; + } + count++; +- }while(!last && count < s->max_samples); ++ } while (!last && count < s->samples); + +- s->samples_left -= count; +- if(!s->samples_left){ +- if(crc != s->CRC){ +- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); +- return -1; +- } +- if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ +- av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); +- return -1; +- } +- wv_reset_saved_context(s); +- }else{ +- s->pos = pos; +- s->sc.crc = crc; +- s->sc.bits_used = get_bits_count(&s->gb); +- if(s->got_extra_bits){ +- s->extra_sc.crc = crc_extra_bits; +- s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits); +- } ++ wv_reset_saved_context(s); ++ if (crc != s->CRC) { ++ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); ++ return -1; ++ } ++ if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { ++ av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); ++ return -1; + } ++ + return count * 2; + } + +-static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, void *dst, const int type) ++static inline int wv_unpack_mono(WavpackFrameContext *s, GetBitContext *gb, ++ void *dst, const int type) + { + int i, j, count = 0; + int last, t; +@@ -615,79 +636,70 @@ + float *dstfl = dst; + const int channel_stride = s->avctx->channels; + +- if(s->samples_left == s->samples) +- s->one = s->zero = s->zeroes = 0; +- do{ ++ s->one = s->zero = s->zeroes = 0; ++ do { + T = wv_get_value(s, gb, 0, &last); + S = 0; +- if(last) break; +- for(i = 0; i < s->terms; i++){ ++ if (last) ++ break; ++ for (i = 0; i < s->terms; i++) { + t = s->decorr[i].value; +- if(t > 8){ +- if(t & 1) +- A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]; ++ if (t > 8) { ++ if (t & 1) ++ A = 2 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]; + else + A = (3 * s->decorr[i].samplesA[0] - s->decorr[i].samplesA[1]) >> 1; + s->decorr[i].samplesA[1] = s->decorr[i].samplesA[0]; + j = 0; +- }else{ ++ } else { + A = s->decorr[i].samplesA[pos]; + j = (pos + t) & 7; + } +- if(type != AV_SAMPLE_FMT_S16) ++ if (type != AV_SAMPLE_FMT_S16) + S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10); + else + S = T + ((s->decorr[i].weightA * A + 512) >> 10); +- if(A && T) s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; ++ if (A && T) ++ s->decorr[i].weightA -= ((((T ^ A) >> 30) & 2) - 1) * s->decorr[i].delta; + s->decorr[i].samplesA[j] = T = S; + } + pos = (pos + 1) & 7; + crc = crc * 3 + S; + +- if(type == AV_SAMPLE_FMT_FLT){ ++ if (type == AV_SAMPLE_FMT_FLT) { + *dstfl = wv_get_value_float(s, &crc_extra_bits, S); + dstfl += channel_stride; +- }else if(type == AV_SAMPLE_FMT_S32){ ++ } else if (type == AV_SAMPLE_FMT_S32) { + *dst32 = wv_get_value_integer(s, &crc_extra_bits, S); + dst32 += channel_stride; +- }else{ ++ } else { + *dst16 = wv_get_value_integer(s, &crc_extra_bits, S); + dst16 += channel_stride; + } + count++; +- }while(!last && count < s->max_samples); ++ } while (!last && count < s->samples); + +- s->samples_left -= count; +- if(!s->samples_left){ +- if(crc != s->CRC){ +- av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); +- return -1; +- } +- if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){ +- av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); +- return -1; +- } +- wv_reset_saved_context(s); +- }else{ +- s->pos = pos; +- s->sc.crc = crc; +- s->sc.bits_used = get_bits_count(&s->gb); +- if(s->got_extra_bits){ +- s->extra_sc.crc = crc_extra_bits; +- s->extra_sc.bits_used = get_bits_count(&s->gb_extra_bits); +- } ++ wv_reset_saved_context(s); ++ if (crc != s->CRC) { ++ av_log(s->avctx, AV_LOG_ERROR, "CRC error\n"); ++ return -1; ++ } ++ if (s->got_extra_bits && crc_extra_bits != s->crc_extra_bits) { ++ av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n"); ++ return -1; + } ++ + return count; + } + + static av_cold int wv_alloc_frame_context(WavpackContext *c) + { + +- if(c->fdec_num == WV_MAX_FRAME_DECODERS) ++ if (c->fdec_num == WV_MAX_FRAME_DECODERS) + return -1; + + c->fdec[c->fdec_num] = av_mallocz(sizeof(**c->fdec)); +- if(!c->fdec[c->fdec_num]) ++ if (!c->fdec[c->fdec_num]) + return -1; + c->fdec_num++; + c->fdec[c->fdec_num - 1]->avctx = c->avctx; +@@ -701,25 +713,29 @@ + WavpackContext *s = avctx->priv_data; + + s->avctx = avctx; +- if(avctx->bits_per_coded_sample <= 16) ++ if (avctx->bits_per_coded_sample <= 16) + avctx->sample_fmt = AV_SAMPLE_FMT_S16; + else + avctx->sample_fmt = AV_SAMPLE_FMT_S32; +- if(avctx->channels <= 2 && !avctx->channel_layout) +- avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO; ++ if (avctx->channels <= 2 && !avctx->channel_layout) ++ avctx->channel_layout = (avctx->channels == 2) ? AV_CH_LAYOUT_STEREO : ++ AV_CH_LAYOUT_MONO; + + s->multichannel = avctx->channels > 2; + /* lavf demuxer does not provide extradata, Matroska stores 0x403 + there, use this to detect decoding mode for multichannel */ + s->mkv_mode = 0; +- if(s->multichannel && avctx->extradata && avctx->extradata_size == 2){ ++ if (s->multichannel && avctx->extradata && avctx->extradata_size == 2) { + int ver = AV_RL16(avctx->extradata); +- if(ver >= 0x402 && ver <= 0x410) ++ if (ver >= 0x402 && ver <= 0x410) + s->mkv_mode = 1; + } + + s->fdec_num = 0; + ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -728,7 +744,7 @@ + WavpackContext *s = avctx->priv_data; + int i; + +- for(i = 0; i < s->fdec_num; i++) ++ for (i = 0; i < s->fdec_num; i++) + av_freep(&s->fdec[i]); + s->fdec_num = 0; + +@@ -736,117 +752,104 @@ + } + + static int wavpack_decode_block(AVCodecContext *avctx, int block_no, +- void *data, int *data_size, ++ void *data, int *got_frame_ptr, + const uint8_t *buf, int buf_size) + { + WavpackContext *wc = avctx->priv_data; + WavpackFrameContext *s; + void *samples = data; + int samplecount; +- int got_terms = 0, got_weights = 0, got_samples = 0, got_entropy = 0, got_bs = 0, got_float = 0; +- int got_hybrid = 0; +- const uint8_t* orig_buf = buf; +- const uint8_t* buf_end = buf + buf_size; ++ int got_terms = 0, got_weights = 0, got_samples = 0, ++ got_entropy = 0, got_bs = 0, got_float = 0, got_hybrid = 0; ++ const uint8_t *orig_buf = buf; ++ const uint8_t *buf_end = buf + buf_size; + int i, j, id, size, ssize, weights, t; +- int bpp, chan, chmask; ++ int bpp, chan, chmask, orig_bpp; + +- if (buf_size == 0){ +- *data_size = 0; ++ if (buf_size == 0) { ++ *got_frame_ptr = 0; + return 0; + } + +- if(block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0){ ++ if (block_no >= wc->fdec_num && wv_alloc_frame_context(wc) < 0) { + av_log(avctx, AV_LOG_ERROR, "Error creating frame decode context\n"); + return -1; + } + + s = wc->fdec[block_no]; +- if(!s){ ++ if (!s) { + av_log(avctx, AV_LOG_ERROR, "Context for block %d is not present\n", block_no); + return -1; + } + +- if(!s->samples_left){ +- memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); +- memset(s->ch, 0, sizeof(s->ch)); +- s->extra_bits = 0; +- s->and = s->or = s->shift = 0; +- s->got_extra_bits = 0; +- } ++ memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr)); ++ memset(s->ch, 0, sizeof(s->ch)); ++ s->extra_bits = 0; ++ s->and = s->or = s->shift = 0; ++ s->got_extra_bits = 0; + +- if(!wc->mkv_mode){ ++ if (!wc->mkv_mode) { + s->samples = AV_RL32(buf); buf += 4; +- if(!s->samples){ +- *data_size = 0; +- return buf_size; ++ if (!s->samples) { ++ *got_frame_ptr = 0; ++ return 0; + } +- }else{ ++ } else { + s->samples = wc->samples; + } + s->frame_flags = AV_RL32(buf); buf += 4; +- if(s->frame_flags&0x80){ +- bpp = sizeof(float); +- avctx->sample_fmt = AV_SAMPLE_FMT_FLT; +- } else if((s->frame_flags&0x03) <= 1){ +- bpp = 2; +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; +- } else { +- bpp = 4; +- avctx->sample_fmt = AV_SAMPLE_FMT_S32; +- } ++ bpp = av_get_bytes_per_sample(avctx->sample_fmt); + samples = (uint8_t*)samples + bpp * wc->ch_offset; ++ orig_bpp = ((s->frame_flags & 0x03) + 1) << 3; + +- s->stereo = !(s->frame_flags & WV_MONO); +- s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo; +- s->joint = s->frame_flags & WV_JOINT_STEREO; +- s->hybrid = s->frame_flags & WV_HYBRID_MODE; +- s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE; +- s->post_shift = 8 * (bpp-1-(s->frame_flags&0x03)) + ((s->frame_flags >> 13) & 0x1f); +- s->CRC = AV_RL32(buf); buf += 4; +- if(wc->mkv_mode) ++ s->stereo = !(s->frame_flags & WV_MONO); ++ s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo; ++ s->joint = s->frame_flags & WV_JOINT_STEREO; ++ s->hybrid = s->frame_flags & WV_HYBRID_MODE; ++ s->hybrid_bitrate = s->frame_flags & WV_HYBRID_BITRATE; ++ s->post_shift = bpp * 8 - orig_bpp + ((s->frame_flags >> 13) & 0x1f); ++ s->hybrid_maxclip = (( 1LL << (orig_bpp - 1)) - 1); ++ s->hybrid_minclip = ((-1LL << (orig_bpp - 1))); ++ s->CRC = AV_RL32(buf); buf += 4; ++ if (wc->mkv_mode) + buf += 4; //skip block size; + + wc->ch_offset += 1 + s->stereo; + +- s->max_samples = *data_size / (bpp * avctx->channels); +- s->max_samples = FFMIN(s->max_samples, s->samples); +- if(s->samples_left > 0){ +- s->max_samples = FFMIN(s->max_samples, s->samples_left); +- buf = buf_end; +- } +- + // parse metadata blocks +- while(buf < buf_end){ +- id = *buf++; ++ while (buf < buf_end) { ++ id = *buf++; + size = *buf++; +- if(id & WP_IDF_LONG) { ++ if (id & WP_IDF_LONG) { + size |= (*buf++) << 8; + size |= (*buf++) << 16; + } + size <<= 1; // size is specified in words + ssize = size; +- if(id & WP_IDF_ODD) size--; +- if(size < 0){ ++ if (id & WP_IDF_ODD) ++ size--; ++ if (size < 0) { + av_log(avctx, AV_LOG_ERROR, "Got incorrect block %02X with size %i\n", id, size); + break; + } +- if(buf + ssize > buf_end){ ++ if (buf + ssize > buf_end) { + av_log(avctx, AV_LOG_ERROR, "Block size %i is out of bounds\n", size); + break; + } +- if(id & WP_IDF_IGNORE){ ++ if (id & WP_IDF_IGNORE) { + buf += ssize; + continue; + } +- switch(id & WP_IDF_MASK){ ++ switch (id & WP_IDF_MASK) { + case WP_ID_DECTERMS: +- s->terms = size; +- if(s->terms > MAX_TERMS){ ++ if (size > MAX_TERMS) { + av_log(avctx, AV_LOG_ERROR, "Too many decorrelation terms\n"); ++ s->terms = 0; + buf += ssize; + continue; + } +- for(i = 0; i < s->terms; i++) { ++ s->terms = size; ++ for (i = 0; i < s->terms; i++) { + s->decorr[s->terms - i - 1].value = (*buf & 0x1F) - 5; + s->decorr[s->terms - i - 1].delta = *buf >> 5; + buf++; +@@ -854,54 +857,56 @@ + got_terms = 1; + break; + case WP_ID_DECWEIGHTS: +- if(!got_terms){ ++ if (!got_terms) { + av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n"); + continue; + } + weights = size >> s->stereo_in; +- if(weights > MAX_TERMS || weights > s->terms){ ++ if (weights > MAX_TERMS || weights > s->terms) { + av_log(avctx, AV_LOG_ERROR, "Too many decorrelation weights\n"); + buf += ssize; + continue; + } +- for(i = 0; i < weights; i++) { ++ for (i = 0; i < weights; i++) { + t = (int8_t)(*buf++); + s->decorr[s->terms - i - 1].weightA = t << 3; +- if(s->decorr[s->terms - i - 1].weightA > 0) +- s->decorr[s->terms - i - 1].weightA += (s->decorr[s->terms - i - 1].weightA + 64) >> 7; +- if(s->stereo_in){ ++ if (s->decorr[s->terms - i - 1].weightA > 0) ++ s->decorr[s->terms - i - 1].weightA += ++ (s->decorr[s->terms - i - 1].weightA + 64) >> 7; ++ if (s->stereo_in) { + t = (int8_t)(*buf++); + s->decorr[s->terms - i - 1].weightB = t << 3; +- if(s->decorr[s->terms - i - 1].weightB > 0) +- s->decorr[s->terms - i - 1].weightB += (s->decorr[s->terms - i - 1].weightB + 64) >> 7; ++ if (s->decorr[s->terms - i - 1].weightB > 0) ++ s->decorr[s->terms - i - 1].weightB += ++ (s->decorr[s->terms - i - 1].weightB + 64) >> 7; + } + } + got_weights = 1; + break; + case WP_ID_DECSAMPLES: +- if(!got_terms){ ++ if (!got_terms) { + av_log(avctx, AV_LOG_ERROR, "No decorrelation terms met\n"); + continue; + } + t = 0; +- for(i = s->terms - 1; (i >= 0) && (t < size); i--) { +- if(s->decorr[i].value > 8){ ++ for (i = s->terms - 1; (i >= 0) && (t < size); i--) { ++ if (s->decorr[i].value > 8) { + s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2; + s->decorr[i].samplesA[1] = wp_exp2(AV_RL16(buf)); buf += 2; +- if(s->stereo_in){ ++ if (s->stereo_in) { + s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2; + s->decorr[i].samplesB[1] = wp_exp2(AV_RL16(buf)); buf += 2; + t += 4; + } + t += 4; +- }else if(s->decorr[i].value < 0){ ++ } else if (s->decorr[i].value < 0) { + s->decorr[i].samplesA[0] = wp_exp2(AV_RL16(buf)); buf += 2; + s->decorr[i].samplesB[0] = wp_exp2(AV_RL16(buf)); buf += 2; + t += 4; +- }else{ +- for(j = 0; j < s->decorr[i].value; j++){ ++ } else { ++ for (j = 0; j < s->decorr[i].value; j++) { + s->decorr[i].samplesA[j] = wp_exp2(AV_RL16(buf)); buf += 2; +- if(s->stereo_in){ ++ if (s->stereo_in) { + s->decorr[i].samplesB[j] = wp_exp2(AV_RL16(buf)); buf += 2; + } + } +@@ -911,13 +916,14 @@ + got_samples = 1; + break; + case WP_ID_ENTROPY: +- if(size != 6 * (s->stereo_in + 1)){ +- av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, got %i", 6 * (s->stereo_in + 1), size); ++ if (size != 6 * (s->stereo_in + 1)) { ++ av_log(avctx, AV_LOG_ERROR, "Entropy vars size should be %i, " ++ "got %i", 6 * (s->stereo_in + 1), size); + buf += ssize; + continue; + } +- for(j = 0; j <= s->stereo_in; j++){ +- for(i = 0; i < 3; i++){ ++ for (j = 0; j <= s->stereo_in; j++) { ++ for (i = 0; i < 3; i++) { + s->ch[j].median[i] = wp_exp2(AV_RL16(buf)); + buf += 2; + } +@@ -925,56 +931,65 @@ + got_entropy = 1; + break; + case WP_ID_HYBRID: +- if(s->hybrid_bitrate){ +- for(i = 0; i <= s->stereo_in; i++){ ++ if (s->hybrid_bitrate) { ++ for (i = 0; i <= s->stereo_in; i++) { + s->ch[i].slow_level = wp_exp2(AV_RL16(buf)); + buf += 2; + size -= 2; + } + } +- for(i = 0; i < (s->stereo_in + 1); i++){ ++ for (i = 0; i < (s->stereo_in + 1); i++) { + s->ch[i].bitrate_acc = AV_RL16(buf) << 16; + buf += 2; + size -= 2; + } +- if(size > 0){ +- for(i = 0; i < (s->stereo_in + 1); i++){ ++ if (size > 0) { ++ for (i = 0; i < (s->stereo_in + 1); i++) { + s->ch[i].bitrate_delta = wp_exp2((int16_t)AV_RL16(buf)); + buf += 2; + } +- }else{ +- for(i = 0; i < (s->stereo_in + 1); i++) ++ } else { ++ for (i = 0; i < (s->stereo_in + 1); i++) + s->ch[i].bitrate_delta = 0; + } + got_hybrid = 1; + break; + case WP_ID_INT32INFO: +- if(size != 4){ ++ if (size != 4) { + av_log(avctx, AV_LOG_ERROR, "Invalid INT32INFO, size = %i, sent_bits = %i\n", size, *buf); + buf += ssize; + continue; + } +- if(buf[0]) ++ if (buf[0]) + s->extra_bits = buf[0]; +- else if(buf[1]) ++ else if (buf[1]) + s->shift = buf[1]; +- else if(buf[2]){ ++ else if (buf[2]){ + s->and = s->or = 1; + s->shift = buf[2]; +- }else if(buf[3]){ +- s->and = 1; ++ } else if(buf[3]) { ++ s->and = 1; + s->shift = buf[3]; + } ++ /* original WavPack decoder forces 32-bit lossy sound to be treated ++ * as 24-bit one in order to have proper clipping ++ */ ++ if (s->hybrid && bpp == 4 && s->post_shift < 8 && s->shift > 8) { ++ s->post_shift += 8; ++ s->shift -= 8; ++ s->hybrid_maxclip >>= 8; ++ s->hybrid_minclip >>= 8; ++ } + buf += 4; + break; + case WP_ID_FLOATINFO: +- if(size != 4){ ++ if (size != 4) { + av_log(avctx, AV_LOG_ERROR, "Invalid FLOATINFO, size = %i\n", size); + buf += ssize; + continue; + } +- s->float_flag = buf[0]; +- s->float_shift = buf[1]; ++ s->float_flag = buf[0]; ++ s->float_shift = buf[1]; + s->float_max_exp = buf[2]; + buf += 4; + got_float = 1; +@@ -988,8 +1003,9 @@ + got_bs = 1; + break; + case WP_ID_EXTRABITS: +- if(size <= 4){ +- av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n", size); ++ if (size <= 4) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid EXTRABITS, size = %i\n", ++ size); + buf += size; + continue; + } +@@ -1001,136 +1017,128 @@ + s->got_extra_bits = 1; + break; + case WP_ID_CHANINFO: +- if(size <= 1){ ++ if (size <= 1) { + av_log(avctx, AV_LOG_ERROR, "Insufficient channel information\n"); + return -1; + } + chan = *buf++; +- switch(size - 2){ +- case 0: +- chmask = *buf; +- break; +- case 1: +- chmask = AV_RL16(buf); +- break; +- case 2: +- chmask = AV_RL24(buf); +- break; +- case 3: +- chmask = AV_RL32(buf); +- break; ++ switch (size - 2) { ++ case 0: chmask = *buf; break; ++ case 1: chmask = AV_RL16(buf); break; ++ case 2: chmask = AV_RL24(buf); break; ++ case 3: chmask = AV_RL32(buf); break; + case 5: + chan |= (buf[1] & 0xF) << 8; + chmask = AV_RL24(buf + 2); + break; + default: +- av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size); +- chan = avctx->channels; ++ av_log(avctx, AV_LOG_ERROR, "Invalid channel info size %d\n", ++ size); ++ chan = avctx->channels; + chmask = avctx->channel_layout; + } +- if(chan != avctx->channels){ +- av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, decoder believes it's %d channels\n", +- chan, avctx->channels); ++ if (chan != avctx->channels) { ++ av_log(avctx, AV_LOG_ERROR, "Block reports total %d channels, " ++ "decoder believes it's %d channels\n", chan, ++ avctx->channels); + return -1; + } +- if(!avctx->channel_layout) ++ if (!avctx->channel_layout) + avctx->channel_layout = chmask; + buf += size - 1; + break; + default: + buf += size; + } +- if(id & WP_IDF_ODD) buf++; ++ if (id & WP_IDF_ODD) ++ buf++; + } +- if(!s->samples_left){ +- if(!got_terms){ +- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n"); +- return -1; +- } +- if(!got_weights){ +- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n"); +- return -1; +- } +- if(!got_samples){ +- av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n"); +- return -1; +- } +- if(!got_entropy){ +- av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n"); +- return -1; +- } +- if(s->hybrid && !got_hybrid){ +- av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n"); +- return -1; +- } +- if(!got_bs){ +- av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n"); +- return -1; +- } +- if(!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT){ +- av_log(avctx, AV_LOG_ERROR, "Float information not found\n"); +- return -1; +- } +- if(s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT){ +- const int size = get_bits_left(&s->gb_extra_bits); +- const int wanted = s->samples * s->extra_bits << s->stereo_in; +- if(size < wanted){ +- av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n"); +- s->got_extra_bits = 0; +- } +- } +- s->samples_left = s->samples; +- }else{ +- init_get_bits(&s->gb, orig_buf + s->sc.offset, s->sc.size); +- skip_bits_long(&s->gb, s->sc.bits_used); +- if(s->got_extra_bits){ +- init_get_bits(&s->gb_extra_bits, orig_buf + s->extra_sc.offset, +- s->extra_sc.size); +- skip_bits_long(&s->gb_extra_bits, s->extra_sc.bits_used); ++ ++ if (!got_terms) { ++ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n"); ++ return -1; ++ } ++ if (!got_weights) { ++ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n"); ++ return -1; ++ } ++ if (!got_samples) { ++ av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n"); ++ return -1; ++ } ++ if (!got_entropy) { ++ av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n"); ++ return -1; ++ } ++ if (s->hybrid && !got_hybrid) { ++ av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n"); ++ return -1; ++ } ++ if (!got_bs) { ++ av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n"); ++ return -1; ++ } ++ if (!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT) { ++ av_log(avctx, AV_LOG_ERROR, "Float information not found\n"); ++ return -1; ++ } ++ if (s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT) { ++ const int size = get_bits_left(&s->gb_extra_bits); ++ const int wanted = s->samples * s->extra_bits << s->stereo_in; ++ if (size < wanted) { ++ av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n"); ++ s->got_extra_bits = 0; + } + } + +- if(s->stereo_in){ +- if(avctx->sample_fmt == AV_SAMPLE_FMT_S16) ++ if (s->stereo_in) { ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) + samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S16); +- else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32) ++ else if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) + samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32); + else + samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT); ++ ++ if (samplecount < 0) ++ return -1; ++ + samplecount >>= 1; +- }else{ ++ } else { + const int channel_stride = avctx->channels; + +- if(avctx->sample_fmt == AV_SAMPLE_FMT_S16) ++ if (avctx->sample_fmt == AV_SAMPLE_FMT_S16) + samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S16); +- else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32) ++ else if (avctx->sample_fmt == AV_SAMPLE_FMT_S32) + samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S32); + else + samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT); + +- if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){ ++ if (samplecount < 0) ++ return -1; ++ ++ if (s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16) { + int16_t *dst = (int16_t*)samples + 1; + int16_t *src = (int16_t*)samples; + int cnt = samplecount; +- while(cnt--){ ++ while (cnt--) { + *dst = *src; + src += channel_stride; + dst += channel_stride; + } +- }else if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32){ ++ } else if (s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32) { + int32_t *dst = (int32_t*)samples + 1; + int32_t *src = (int32_t*)samples; + int cnt = samplecount; +- while(cnt--){ ++ while (cnt--) { + *dst = *src; + src += channel_stride; + dst += channel_stride; + } +- }else if(s->stereo){ ++ } else if (s->stereo) { + float *dst = (float*)samples + 1; + float *src = (float*)samples; + int cnt = samplecount; +- while(cnt--){ ++ while (cnt--) { + *dst = *src; + src += channel_stride; + dst += channel_stride; +@@ -1138,65 +1146,109 @@ + } + } + +- wc->samples_left = s->samples_left; ++ *got_frame_ptr = 1; + + return samplecount * bpp; + } + +-static int wavpack_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static void wavpack_decode_flush(AVCodecContext *avctx) + { + WavpackContext *s = avctx->priv_data; ++ int i; ++ ++ for (i = 0; i < s->fdec_num; i++) ++ wv_reset_saved_context(s->fdec[i]); ++} ++ ++static int wavpack_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) ++{ ++ WavpackContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- int frame_size; ++ int buf_size = avpkt->size; ++ int frame_size, ret, frame_flags; + int samplecount = 0; + +- s->block = 0; +- s->samples_left = 0; ++ s->block = 0; + s->ch_offset = 0; + +- if(s->mkv_mode){ +- s->samples = AV_RL32(buf); buf += 4; ++ /* determine number of samples */ ++ if (s->mkv_mode) { ++ s->samples = AV_RL32(buf); buf += 4; ++ frame_flags = AV_RL32(buf); ++ } else { ++ if (s->multichannel) { ++ s->samples = AV_RL32(buf + 4); ++ frame_flags = AV_RL32(buf + 8); ++ } else { ++ s->samples = AV_RL32(buf); ++ frame_flags = AV_RL32(buf + 4); ++ } + } +- while(buf_size > 0){ +- if(!s->multichannel){ ++ if (s->samples <= 0) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of samples: %d\n", ++ s->samples); ++ return AVERROR(EINVAL); ++ } ++ ++ if (frame_flags & 0x80) { ++ avctx->sample_fmt = AV_SAMPLE_FMT_FLT; ++ } else if ((frame_flags & 0x03) <= 1) { ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ } else { ++ avctx->sample_fmt = AV_SAMPLE_FMT_S32; ++ } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = s->samples; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ while (buf_size > 0) { ++ if (!s->multichannel) { + frame_size = buf_size; +- }else{ +- if(!s->mkv_mode){ ++ } else { ++ if (!s->mkv_mode) { + frame_size = AV_RL32(buf) - 12; buf += 4; buf_size -= 4; +- }else{ +- if(buf_size < 12) //MKV files can have zero flags after last block ++ } else { ++ if (buf_size < 12) //MKV files can have zero flags after last block + break; + frame_size = AV_RL32(buf + 8) + 12; + } + } +- if(frame_size < 0 || frame_size > buf_size){ +- av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d vs. %d bytes left)\n", +- s->block, frame_size, buf_size); ++ if (frame_size < 0 || frame_size > buf_size) { ++ av_log(avctx, AV_LOG_ERROR, "Block %d has invalid size (size %d " ++ "vs. %d bytes left)\n", s->block, frame_size, buf_size); ++ wavpack_decode_flush(avctx); + return -1; + } +- if((samplecount = wavpack_decode_block(avctx, s->block, data, +- data_size, buf, frame_size)) < 0) ++ if ((samplecount = wavpack_decode_block(avctx, s->block, ++ s->frame.data[0], got_frame_ptr, ++ buf, frame_size)) < 0) { ++ wavpack_decode_flush(avctx); + return -1; ++ } + s->block++; + buf += frame_size; buf_size -= frame_size; + } +- *data_size = samplecount * avctx->channels; + +- return s->samples_left > 0 ? 0 : avpkt->size; ++ if (*got_frame_ptr) ++ *(AVFrame *)data = s->frame; ++ ++ return avpkt->size; + } + + AVCodec ff_wavpack_decoder = { +- "wavpack", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WAVPACK, +- sizeof(WavpackContext), +- wavpack_decode_init, +- NULL, +- wavpack_decode_end, +- wavpack_decode_frame, +- .capabilities = CODEC_CAP_SUBFRAMES, +- .long_name = NULL_IF_CONFIG_SMALL("WavPack"), ++ .name = "wavpack", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WAVPACK, ++ .priv_data_size = sizeof(WavpackContext), ++ .init = wavpack_decode_init, ++ .close = wavpack_decode_end, ++ .decode = wavpack_decode_frame, ++ .flush = wavpack_decode_flush, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("WavPack"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wma.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wma.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wma.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wma.c 2012-05-14 14:08:54.466342638 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "avcodec.h" ++#include "sinewin.h" + #include "wma.h" + #include "wmadata.h" + +@@ -84,7 +85,7 @@ + } else if (sample_rate <= 22050 || + (sample_rate <= 32000 && version == 1)) { + frame_len_bits = 10; +- } else if (sample_rate <= 48000) { ++ } else if (sample_rate <= 48000 || version < 3) { + frame_len_bits = 11; + } else if (sample_rate <= 96000) { + frame_len_bits = 12; +@@ -136,6 +137,9 @@ + + /* compute MDCT block size */ + s->frame_len_bits = ff_wma_get_frame_len_bits(s->sample_rate, s->version, 0); ++ s->next_block_len_bits = s->frame_len_bits; ++ s->prev_block_len_bits = s->frame_len_bits; ++ s->block_len_bits = s->frame_len_bits; + + s->frame_len = 1 << s->frame_len_bits; + if (s->use_variable_block_len) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmadec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmadec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmadec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmadec.c 2012-05-14 14:08:54.472342759 +0200 +@@ -102,6 +102,18 @@ + s->use_bit_reservoir = flags2 & 0x0002; + s->use_variable_block_len = flags2 & 0x0004; + ++ if(avctx->codec->id == CODEC_ID_WMAV2 && avctx->extradata_size >= 8){ ++ if(AV_RL16(extradata+4)==0xd && s->use_variable_block_len){ ++ av_log(avctx, AV_LOG_WARNING, "Disabling use_variable_block_len, if this fails contact the ffmpeg developers and send us the file\n"); ++ s->use_variable_block_len= 0; // this fixes issue1503 ++ } ++ } ++ ++ if(avctx->channels > MAX_CHANNELS){ ++ av_log(avctx, AV_LOG_ERROR, "Invalid number of channels (%d)\n", avctx->channels); ++ return -1; ++ } ++ + if(ff_wma_init(avctx, flags2)<0) + return -1; + +@@ -124,6 +136,10 @@ + } + + avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -178,15 +194,6 @@ + s->lsp_pow_m_table2[i] = b - a; + b = a; + } +-#if 0 +- for(i=1;i<20;i++) { +- float v, r1, r2; +- v = 5.0 / i; +- r1 = pow_m1_4(s, v); +- r2 = pow(v,-0.25); +- printf("%f^-0.25=%f e=%f\n", v, r1, r2 - r1); +- } +-#endif + } + + /** +@@ -361,7 +368,7 @@ + } + /* NOTE: this offset is the same as MPEG4 AAC ! */ + last_exp += code - 60; +- if ((unsigned)last_exp + 60 > FF_ARRAY_ELEMS(pow_tab)) { ++ if ((unsigned)last_exp + 60 >= FF_ARRAY_ELEMS(pow_tab)) { + av_log(s->avctx, AV_LOG_ERROR, "Exponent out of range: %d\n", + last_exp); + return -1; +@@ -447,6 +454,7 @@ + int coef_nb_bits, total_gain; + int nb_coefs[MAX_CHANNELS]; + float mdct_norm; ++ FFTContext *mdct; + + #ifdef TRACE + tprintf(s->avctx, "***decode_block: %d:%d\n", s->frame_count - 1, s->block_num); +@@ -488,6 +496,11 @@ + s->block_len_bits = s->frame_len_bits; + } + ++ if (s->frame_len_bits - s->block_len_bits >= s->nb_block_sizes){ ++ av_log(s->avctx, AV_LOG_ERROR, "block_len_bits not initialized to a valid value\n"); ++ return -1; ++ } ++ + /* now check if the block length is coherent with the frame length */ + s->block_len = 1 << s->block_len_bits; + if ((s->block_pos + s->block_len) > s->frame_len){ +@@ -742,12 +755,14 @@ + } + + next: ++ mdct = &s->mdct_ctx[bsize]; ++ + for(ch = 0; ch < s->nb_channels; ch++) { + int n4, index; + + n4 = s->block_len / 2; + if(s->channel_coded[ch]){ +- ff_imdct_calc(&s->mdct_ctx[bsize], s->output, s->coefs[ch]); ++ mdct->imdct_calc(mdct, s->output, s->coefs[ch]); + }else if(!(s->ms_stereo && ch==1)) + memset(s->output, 0, sizeof(s->output)); + +@@ -803,14 +818,13 @@ + return 0; + } + +-static int wma_decode_superframe(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int wma_decode_superframe(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; + WMACodecContext *s = avctx->priv_data; +- int nb_frames, bit_offset, i, pos, len; ++ int nb_frames, bit_offset, i, pos, len, ret; + uint8_t *q; + int16_t *samples; + +@@ -820,25 +834,41 @@ + s->last_superframe_len = 0; + return 0; + } +- if (buf_size < s->block_align) +- return 0; +- buf_size = s->block_align; +- +- samples = data; ++ if (buf_size < s->block_align) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Input packet size too small (%d < %d)\n", ++ buf_size, s->block_align); ++ return AVERROR_INVALIDDATA; ++ } ++ if(s->block_align) ++ buf_size = s->block_align; + + init_get_bits(&s->gb, buf, buf_size*8); + + if (s->use_bit_reservoir) { + /* read super frame header */ + skip_bits(&s->gb, 4); /* super frame index */ +- nb_frames = get_bits(&s->gb, 4) - 1; ++ nb_frames = get_bits(&s->gb, 4) - (s->last_superframe_len <= 0); ++ } else { ++ nb_frames = 1; ++ } + +- if((nb_frames+1) * s->nb_channels * s->frame_len * sizeof(int16_t) > *data_size){ +- av_log(s->avctx, AV_LOG_ERROR, "Insufficient output space\n"); +- goto fail; +- } ++ /* get output buffer */ ++ s->frame.nb_samples = nb_frames * s->frame_len; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = (int16_t *)s->frame.data[0]; + ++ if (s->use_bit_reservoir) { + bit_offset = get_bits(&s->gb, s->byte_offset_bits + 3); ++ if (bit_offset > get_bits_left(&s->gb)) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid last frame bit offset %d > buf size %d (%d)\n", ++ bit_offset, get_bits_left(&s->gb), buf_size); ++ goto fail; ++ } + + if (s->last_superframe_len > 0) { + // printf("skip=%d\n", s->last_bitoffset); +@@ -855,9 +885,10 @@ + if (len > 0) { + *q++ = (get_bits)(&s->gb, len) << (8 - len); + } ++ memset(q, 0, FF_INPUT_BUFFER_PADDING_SIZE); + + /* XXX: bit_offset bits into last frame */ +- init_get_bits(&s->gb, s->last_superframe, MAX_CODED_SUPERFRAME_SIZE*8); ++ init_get_bits(&s->gb, s->last_superframe, s->last_superframe_len * 8 + bit_offset); + /* skip unused bits */ + if (s->last_bitoffset > 0) + skip_bits(&s->gb, s->last_bitoffset); +@@ -866,11 +897,14 @@ + if (wma_decode_frame(s, samples) < 0) + goto fail; + samples += s->nb_channels * s->frame_len; ++ nb_frames--; + } + + /* read each frame starting from bit_offset */ + pos = bit_offset + 4 + 4 + s->byte_offset_bits + 3; +- init_get_bits(&s->gb, buf + (pos >> 3), (MAX_CODED_SUPERFRAME_SIZE - (pos >> 3))*8); ++ if (pos >= MAX_CODED_SUPERFRAME_SIZE * 8 || pos > buf_size * 8) ++ return AVERROR_INVALIDDATA; ++ init_get_bits(&s->gb, buf + (pos >> 3), (buf_size - (pos >> 3))*8); + len = pos & 7; + if (len > 0) + skip_bits(&s->gb, len); +@@ -894,10 +928,6 @@ + s->last_superframe_len = len; + memcpy(s->last_superframe, buf + pos, len); + } else { +- if(s->nb_channels * s->frame_len * sizeof(int16_t) > *data_size){ +- av_log(s->avctx, AV_LOG_ERROR, "Insufficient output space\n"); +- goto fail; +- } + /* single frame decode */ + if (wma_decode_frame(s, samples) < 0) + goto fail; +@@ -906,8 +936,10 @@ + + //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d outbytes:%d eaten:%d\n", s->frame_len_bits, s->block_len_bits, s->frame_len, s->block_len, (int8_t *)samples - (int8_t *)data, s->block_align); + +- *data_size = (int8_t *)samples - (int8_t *)data; +- return s->block_align; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ ++ return buf_size; + fail: + /* when error, we reset the bit reservoir */ + s->last_superframe_len = 0; +@@ -922,30 +954,28 @@ + s->last_superframe_len= 0; + } + +-AVCodec ff_wmav1_decoder = +-{ +- "wmav1", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAV1, +- sizeof(WMACodecContext), +- wma_decode_init, +- NULL, +- ff_wma_end, +- wma_decode_superframe, +- .flush=flush, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), ++AVCodec ff_wmav1_decoder = { ++ .name = "wmav1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAV1, ++ .priv_data_size = sizeof(WMACodecContext), ++ .init = wma_decode_init, ++ .close = ff_wma_end, ++ .decode = wma_decode_superframe, ++ .flush = flush, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), + }; + +-AVCodec ff_wmav2_decoder = +-{ +- "wmav2", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAV2, +- sizeof(WMACodecContext), +- wma_decode_init, +- NULL, +- ff_wma_end, +- wma_decode_superframe, +- .flush=flush, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), ++AVCodec ff_wmav2_decoder = { ++ .name = "wmav2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAV2, ++ .priv_data_size = sizeof(WMACodecContext), ++ .init = wma_decode_init, ++ .close = ff_wma_end, ++ .decode = wma_decode_superframe, ++ .flush = flush, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmaenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmaenc.c 2012-05-14 14:08:54.473342779 +0200 +@@ -33,11 +33,23 @@ + + s->avctx = avctx; + +- if(avctx->channels > MAX_CHANNELS) +- return -1; +- +- if(avctx->bit_rate < 24*1000) +- return -1; ++ if(avctx->channels > MAX_CHANNELS) { ++ av_log(avctx, AV_LOG_ERROR, "too many channels: got %i, need %i or fewer", ++ avctx->channels, MAX_CHANNELS); ++ return AVERROR(EINVAL); ++ } ++ ++ if (avctx->sample_rate > 48000) { ++ av_log(avctx, AV_LOG_ERROR, "sample rate is too high: %d > 48kHz", ++ avctx->sample_rate); ++ return AVERROR(EINVAL); ++ } ++ ++ if(avctx->bit_rate < 24*1000) { ++ av_log(avctx, AV_LOG_ERROR, "bitrate too low: got %i, need 24000 or higher\n", ++ avctx->bit_rate); ++ return AVERROR(EINVAL); ++ } + + /* extract flag infos */ + flags1 = 0; +@@ -58,6 +70,8 @@ + s->use_exp_vlc = flags2 & 0x0001; + s->use_bit_reservoir = flags2 & 0x0002; + s->use_variable_block_len = flags2 & 0x0004; ++ if (avctx->channels == 2) ++ s->ms_stereo = 1; + + ff_wma_init(avctx, flags2); + +@@ -65,8 +79,12 @@ + for(i = 0; i < s->nb_block_sizes; i++) + ff_mdct_init(&s->mdct_ctx[i], s->frame_len_bits - i + 1, 0, 1.0); + +- avctx->block_align= +- s->block_align= avctx->bit_rate*(int64_t)s->frame_len / (avctx->sample_rate*8); ++ s->block_align = avctx->bit_rate * (int64_t)s->frame_len / ++ (avctx->sample_rate * 8); ++ s->block_align = FFMIN(s->block_align, MAX_CODED_SUPERFRAME_SIZE); ++ avctx->block_align = s->block_align; ++ avctx->bit_rate = avctx->block_align * 8LL * avctx->sample_rate / ++ s->frame_len; + //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", s->block_align, avctx->bit_rate, s->frame_len, avctx->sample_rate); + avctx->frame_size= s->frame_len; + +@@ -77,6 +95,7 @@ + static void apply_window_and_mdct(AVCodecContext * avctx, const signed short * audio, int len) { + WMACodecContext *s = avctx->priv_data; + int window_index= s->frame_len_bits - s->block_len_bits; ++ FFTContext *mdct = &s->mdct_ctx[window_index]; + int i, j, channel; + const float * win = s->windows[window_index]; + int window_len = 1 << s->block_len_bits; +@@ -89,7 +108,7 @@ + s->output[i+window_len] = audio[j] / n * win[window_len - i - 1]; + s->frame_out[channel][i] = audio[j] / n * win[i]; + } +- ff_mdct_calc(&s->mdct_ctx[window_index], s->coefs[channel], s->output); ++ mdct->mdct_calc(mdct, s->coefs[channel], s->output); + } + } + +@@ -174,7 +193,7 @@ + } + + if (s->nb_channels == 2) { +- put_bits(&s->pb, 1, s->ms_stereo= 1); ++ put_bits(&s->pb, 1, !!s->ms_stereo); + } + + for(ch = 0; ch < s->nb_channels; ch++) { +@@ -304,7 +323,7 @@ + put_bits(&s->pb, s->coef_vlcs[tindex]->huffbits[1], s->coef_vlcs[tindex]->huffcodes[1]); + } + if (s->version == 1 && s->nb_channels >= 2) { +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + } + } + return 0; +@@ -320,7 +339,7 @@ + return INT_MAX; + } + +- align_put_bits(&s->pb); ++ avpriv_align_put_bits(&s->pb); + + return put_bits_count(&s->pb)/8 - s->block_align; + } +@@ -348,6 +367,11 @@ + } + } + ++ if (buf_size < 2 * MAX_CODED_SUPERFRAME_SIZE) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer size is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ + #if 1 + total_gain= 128; + for(i=64; i; i>>=1){ +@@ -383,28 +407,26 @@ + return put_bits_ptr(&s->pb) - s->pb.buf; + } + +-AVCodec ff_wmav1_encoder = +-{ +- "wmav1", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAV1, +- sizeof(WMACodecContext), +- encode_init, +- encode_superframe, +- ff_wma_end, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), ++AVCodec ff_wmav1_encoder = { ++ .name = "wmav1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAV1, ++ .priv_data_size = sizeof(WMACodecContext), ++ .init = encode_init, ++ .encode = encode_superframe, ++ .close = ff_wma_end, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 1"), + }; + +-AVCodec ff_wmav2_encoder = +-{ +- "wmav2", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAV2, +- sizeof(WMACodecContext), +- encode_init, +- encode_superframe, +- ff_wma_end, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), ++AVCodec ff_wmav2_encoder = { ++ .name = "wmav2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAV2, ++ .priv_data_size = sizeof(WMACodecContext), ++ .init = encode_init, ++ .encode = encode_superframe, ++ .close = ff_wma_end, ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 2"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wma.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wma.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wma.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wma.h 2012-05-14 14:08:54.470342719 +0200 +@@ -65,6 +65,7 @@ + + typedef struct WMACodecContext { + AVCodecContext* avctx; ++ AVFrame frame; + GetBitContext gb; + PutBitContext pb; + int sample_rate; +@@ -113,17 +114,17 @@ + uint8_t ms_stereo; ///< true if mid/side stereo mode + uint8_t channel_coded[MAX_CHANNELS]; ///< true if channel is coded + int exponents_bsize[MAX_CHANNELS]; ///< log2 ratio frame/exp. length +- DECLARE_ALIGNED(16, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; ++ DECLARE_ALIGNED(32, float, exponents)[MAX_CHANNELS][BLOCK_MAX_SIZE]; + float max_exponent[MAX_CHANNELS]; + WMACoef coefs1[MAX_CHANNELS][BLOCK_MAX_SIZE]; +- DECLARE_ALIGNED(16, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; +- DECLARE_ALIGNED(16, FFTSample, output)[BLOCK_MAX_SIZE * 2]; ++ DECLARE_ALIGNED(32, float, coefs)[MAX_CHANNELS][BLOCK_MAX_SIZE]; ++ DECLARE_ALIGNED(32, FFTSample, output)[BLOCK_MAX_SIZE * 2]; + FFTContext mdct_ctx[BLOCK_NB_SIZES]; + float *windows[BLOCK_NB_SIZES]; + /* output buffer for one frame and the last for IMDCT windowing */ +- DECLARE_ALIGNED(16, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; ++ DECLARE_ALIGNED(32, float, frame_out)[MAX_CHANNELS][BLOCK_MAX_SIZE * 2]; + /* last frame info */ +- uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + 4]; /* padding added */ ++ uint8_t last_superframe[MAX_CODED_SUPERFRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE]; /* padding added */ + int last_bitoffset; + int last_superframe_len; + float noise_table[NOISE_TAB_SIZE]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmalosslessdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmalosslessdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmalosslessdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmalosslessdec.c 2012-05-14 14:08:54.478342880 +0200 +@@ -0,0 +1,1564 @@ ++/* ++ * Wmall compatible decoder ++ * Copyright (c) 2007 Baptiste Coudurier, Benjamin Larsson, Ulion ++ * Copyright (c) 2008 - 2011 Sascha Sommer, Benjamin Larsson ++ * Copyright (c) 2011 Andreas Öman ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * @brief wmall decoder implementation ++ * Wmall is an MDCT based codec comparable to wma standard or AAC. ++ * The decoding therefore consists of the following steps: ++ * - bitstream decoding ++ * - reconstruction of per-channel data ++ * - rescaling and inverse quantization ++ * - IMDCT ++ * - windowing and overlapp-add ++ * ++ * The compressed wmall bitstream is split into individual packets. ++ * Every such packet contains one or more wma frames. ++ * The compressed frames may have a variable length and frames may ++ * cross packet boundaries. ++ * Common to all wmall frames is the number of samples that are stored in ++ * a frame. ++ * The number of samples and a few other decode flags are stored ++ * as extradata that has to be passed to the decoder. ++ * ++ * The wmall frames themselves are again split into a variable number of ++ * subframes. Every subframe contains the data for 2^N time domain samples ++ * where N varies between 7 and 12. ++ * ++ * Example wmall bitstream (in samples): ++ * ++ * || packet 0 || packet 1 || packet 2 packets ++ * --------------------------------------------------- ++ * || frame 0 || frame 1 || frame 2 || frames ++ * --------------------------------------------------- ++ * || | | || | | | || || subframes of channel 0 ++ * --------------------------------------------------- ++ * || | | || | | | || || subframes of channel 1 ++ * --------------------------------------------------- ++ * ++ * The frame layouts for the individual channels of a wma frame does not need ++ * to be the same. ++ * ++ * However, if the offsets and lengths of several subframes of a frame are the ++ * same, the subframes of the channels can be grouped. ++ * Every group may then use special coding techniques like M/S stereo coding ++ * to improve the compression ratio. These channel transformations do not ++ * need to be applied to a whole subframe. Instead, they can also work on ++ * individual scale factor bands (see below). ++ * The coefficients that carry the audio signal in the frequency domain ++ * are transmitted as huffman-coded vectors with 4, 2 and 1 elements. ++ * In addition to that, the encoder can switch to a runlevel coding scheme ++ * by transmitting subframe_length / 128 zero coefficients. ++ * ++ * Before the audio signal can be converted to the time domain, the ++ * coefficients have to be rescaled and inverse quantized. ++ * A subframe is therefore split into several scale factor bands that get ++ * scaled individually. ++ * Scale factors are submitted for every frame but they might be shared ++ * between the subframes of a channel. Scale factors are initially DPCM-coded. ++ * Once scale factors are shared, the differences are transmitted as runlevel ++ * codes. ++ * Every subframe length and offset combination in the frame layout shares a ++ * common quantization factor that can be adjusted for every channel by a ++ * modifier. ++ * After the inverse quantization, the coefficients get processed by an IMDCT. ++ * The resulting values are then windowed with a sine window and the first half ++ * of the values are added to the second half of the output from the previous ++ * subframe in order to reconstruct the output samples. ++ */ ++ ++#include "avcodec.h" ++#include "internal.h" ++#include "get_bits.h" ++#include "put_bits.h" ++#include "dsputil.h" ++#include "wma.h" ++ ++/** current decoder limitations */ ++#define WMALL_MAX_CHANNELS 8 ///< max number of handled channels ++#define MAX_SUBFRAMES 32 ///< max number of subframes per channel ++#define MAX_BANDS 29 ///< max number of scale factor bands ++#define MAX_FRAMESIZE 32768 ///< maximum compressed frame size ++ ++#define WMALL_BLOCK_MIN_BITS 6 ///< log2 of min block size ++#define WMALL_BLOCK_MAX_BITS 12 ///< log2 of max block size ++#define WMALL_BLOCK_MAX_SIZE (1 << WMALL_BLOCK_MAX_BITS) ///< maximum block size ++#define WMALL_BLOCK_SIZES (WMALL_BLOCK_MAX_BITS - WMALL_BLOCK_MIN_BITS + 1) ///< possible block sizes ++ ++ ++#define VLCBITS 9 ++#define SCALEVLCBITS 8 ++#define VEC4MAXDEPTH ((HUFF_VEC4_MAXBITS+VLCBITS-1)/VLCBITS) ++#define VEC2MAXDEPTH ((HUFF_VEC2_MAXBITS+VLCBITS-1)/VLCBITS) ++#define VEC1MAXDEPTH ((HUFF_VEC1_MAXBITS+VLCBITS-1)/VLCBITS) ++#define SCALEMAXDEPTH ((HUFF_SCALE_MAXBITS+SCALEVLCBITS-1)/SCALEVLCBITS) ++#define SCALERLMAXDEPTH ((HUFF_SCALE_RL_MAXBITS+VLCBITS-1)/VLCBITS) ++ ++static float sin64[33]; ///< sinus table for decorrelation ++ ++/** ++ * @brief frame specific decoder context for a single channel ++ */ ++typedef struct { ++ int16_t prev_block_len; ///< length of the previous block ++ uint8_t transmit_coefs; ++ uint8_t num_subframes; ++ uint16_t subframe_len[MAX_SUBFRAMES]; ///< subframe length in samples ++ uint16_t subframe_offset[MAX_SUBFRAMES]; ///< subframe positions in the current frame ++ uint8_t cur_subframe; ///< current subframe number ++ uint16_t decoded_samples; ///< number of already processed samples ++ uint8_t grouped; ///< channel is part of a group ++ int quant_step; ///< quantization step for the current subframe ++ int8_t reuse_sf; ///< share scale factors between subframes ++ int8_t scale_factor_step; ///< scaling step for the current subframe ++ int max_scale_factor; ///< maximum scale factor for the current subframe ++ int saved_scale_factors[2][MAX_BANDS]; ///< resampled and (previously) transmitted scale factor values ++ int8_t scale_factor_idx; ///< index for the transmitted scale factor values (used for resampling) ++ int* scale_factors; ///< pointer to the scale factor values used for decoding ++ uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block ++ float* coeffs; ///< pointer to the subframe decode buffer ++ uint16_t num_vec_coeffs; ///< number of vector coded coefficients ++ DECLARE_ALIGNED(16, float, out)[WMALL_BLOCK_MAX_SIZE + WMALL_BLOCK_MAX_SIZE / 2]; ///< output buffer ++ int transient_counter; ///< number of transient samples from the beginning of transient zone ++} WmallChannelCtx; ++ ++/** ++ * @brief channel group for channel transformations ++ */ ++typedef struct { ++ uint8_t num_channels; ///< number of channels in the group ++ int8_t transform; ///< transform on / off ++ int8_t transform_band[MAX_BANDS]; ///< controls if the transform is enabled for a certain band ++ float decorrelation_matrix[WMALL_MAX_CHANNELS*WMALL_MAX_CHANNELS]; ++ float* channel_data[WMALL_MAX_CHANNELS]; ///< transformation coefficients ++} WmallChannelGrp; ++ ++/** ++ * @brief main decoder context ++ */ ++typedef struct WmallDecodeCtx { ++ /* generic decoder variables */ ++ AVCodecContext* avctx; ///< codec context for av_log ++ DSPContext dsp; ///< accelerated DSP functions ++ uint8_t frame_data[MAX_FRAMESIZE + ++ FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data ++ PutBitContext pb; ///< context for filling the frame_data buffer ++ FFTContext mdct_ctx[WMALL_BLOCK_SIZES]; ///< MDCT context per block size ++ DECLARE_ALIGNED(16, float, tmp)[WMALL_BLOCK_MAX_SIZE]; ///< IMDCT output buffer ++ float* windows[WMALL_BLOCK_SIZES]; ///< windows for the different block sizes ++ ++ /* frame size dependent frame information (set during initialization) */ ++ uint32_t decode_flags; ///< used compression features ++ uint8_t len_prefix; ///< frame is prefixed with its length ++ uint8_t dynamic_range_compression; ///< frame contains DRC data ++ uint8_t bits_per_sample; ///< integer audio sample size for the unscaled IMDCT output (used to scale to [-1.0, 1.0]) ++ uint16_t samples_per_frame; ///< number of samples to output ++ uint16_t log2_frame_size; ++ int8_t num_channels; ///< number of channels in the stream (same as AVCodecContext.num_channels) ++ int8_t lfe_channel; ///< lfe channel index ++ uint8_t max_num_subframes; ++ uint8_t subframe_len_bits; ///< number of bits used for the subframe length ++ uint8_t max_subframe_len_bit; ///< flag indicating that the subframe is of maximum size when the first subframe length bit is 1 ++ uint16_t min_samples_per_subframe; ++ int8_t num_sfb[WMALL_BLOCK_SIZES]; ///< scale factor bands per block size ++ int16_t sfb_offsets[WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor band offsets (multiples of 4) ++ int8_t sf_offsets[WMALL_BLOCK_SIZES][WMALL_BLOCK_SIZES][MAX_BANDS]; ///< scale factor resample matrix ++ int16_t subwoofer_cutoffs[WMALL_BLOCK_SIZES]; ///< subwoofer cutoff values ++ ++ /* packet decode state */ ++ GetBitContext pgb; ///< bitstream reader context for the packet ++ int next_packet_start; ///< start offset of the next wma packet in the demuxer packet ++ uint8_t packet_offset; ///< frame offset in the packet ++ uint8_t packet_sequence_number; ///< current packet number ++ int num_saved_bits; ///< saved number of bits ++ int frame_offset; ///< frame offset in the bit reservoir ++ int subframe_offset; ///< subframe offset in the bit reservoir ++ uint8_t packet_loss; ///< set in case of bitstream error ++ uint8_t packet_done; ///< set when a packet is fully decoded ++ ++ /* frame decode state */ ++ uint32_t frame_num; ///< current frame number (not used for decoding) ++ GetBitContext gb; ///< bitstream reader context ++ int buf_bit_size; ///< buffer size in bits ++ int16_t* samples_16; ///< current samplebuffer pointer (16-bit) ++ int16_t* samples_16_end; ///< maximum samplebuffer pointer ++ int16_t* samples_32; ///< current samplebuffer pointer (24-bit) ++ int16_t* samples_32_end; ///< maximum samplebuffer pointer ++ uint8_t drc_gain; ///< gain for the DRC tool ++ int8_t skip_frame; ///< skip output step ++ int8_t parsed_all_subframes; ///< all subframes decoded? ++ ++ /* subframe/block decode state */ ++ int16_t subframe_len; ///< current subframe length ++ int8_t channels_for_cur_subframe; ///< number of channels that contain the subframe ++ int8_t channel_indexes_for_cur_subframe[WMALL_MAX_CHANNELS]; ++ int8_t num_bands; ///< number of scale factor bands ++ int8_t transmit_num_vec_coeffs; ///< number of vector coded coefficients is part of the bitstream ++ int16_t* cur_sfb_offsets; ///< sfb offsets for the current block ++ uint8_t table_idx; ///< index for the num_sfb, sfb_offsets, sf_offsets and subwoofer_cutoffs tables ++ int8_t esc_len; ///< length of escaped coefficients ++ ++ uint8_t num_chgroups; ///< number of channel groups ++ WmallChannelGrp chgroup[WMALL_MAX_CHANNELS]; ///< channel group information ++ ++ WmallChannelCtx channel[WMALL_MAX_CHANNELS]; ///< per channel data ++ ++ // WMA lossless ++ ++ uint8_t do_arith_coding; ++ uint8_t do_ac_filter; ++ uint8_t do_inter_ch_decorr; ++ uint8_t do_mclms; ++ uint8_t do_lpc; ++ ++ int8_t acfilter_order; ++ int8_t acfilter_scaling; ++ int64_t acfilter_coeffs[16]; ++ int acfilter_prevvalues[2][16]; ++ ++ int8_t mclms_order; ++ int8_t mclms_scaling; ++ int16_t mclms_coeffs[128]; ++ int16_t mclms_coeffs_cur[4]; ++ int16_t mclms_prevvalues[64]; // FIXME: should be 32-bit / 16-bit depending on bit-depth ++ int16_t mclms_updates[64]; ++ int mclms_recent; ++ ++ int movave_scaling; ++ int quant_stepsize; ++ ++ struct { ++ int order; ++ int scaling; ++ int coefsend; ++ int bitsend; ++ int16_t coefs[256]; ++ int16_t lms_prevvalues[512]; // FIXME: see above ++ int16_t lms_updates[512]; // and here too ++ int recent; ++ } cdlms[2][9]; /* XXX: Here, 2 is the max. no. of channels allowed, ++ 9 is the maximum no. of filters per channel. ++ Question is, why 2 if WMALL_MAX_CHANNELS == 8 */ ++ ++ ++ int cdlms_ttl[2]; ++ ++ int bV3RTM; ++ ++ int is_channel_coded[2]; // XXX: same question as above applies here too (and below) ++ int update_speed[2]; ++ ++ int transient[2]; ++ int transient_pos[2]; ++ int seekable_tile; ++ ++ int ave_sum[2]; ++ ++ int channel_residues[2][2048]; ++ ++ ++ int lpc_coefs[2][40]; ++ int lpc_order; ++ int lpc_scaling; ++ int lpc_intbits; ++ ++ int channel_coeffs[2][2048]; // FIXME: should be 32-bit / 16-bit depending on bit-depth ++ ++} WmallDecodeCtx; ++ ++ ++#undef dprintf ++#define dprintf(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) ++ ++ ++static int num_logged_tiles = 0; ++static int num_logged_subframes = 0; ++static int num_lms_update_call = 0; ++ ++/** ++ *@brief helper function to print the most important members of the context ++ *@param s context ++ */ ++static void av_cold dump_context(WmallDecodeCtx *s) ++{ ++#define PRINT(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %d\n", a, b); ++#define PRINT_HEX(a, b) av_log(s->avctx, AV_LOG_DEBUG, " %s = %x\n", a, b); ++ ++ PRINT("ed sample bit depth", s->bits_per_sample); ++ PRINT_HEX("ed decode flags", s->decode_flags); ++ PRINT("samples per frame", s->samples_per_frame); ++ PRINT("log2 frame size", s->log2_frame_size); ++ PRINT("max num subframes", s->max_num_subframes); ++ PRINT("len prefix", s->len_prefix); ++ PRINT("num channels", s->num_channels); ++} ++ ++static void dump_int_buffer(uint8_t *buffer, int size, int length, int delimiter) ++{ ++ int i; ++ ++ for (i=0 ; ipriv_data; ++ int i; ++ ++ for (i = 0; i < WMALL_BLOCK_SIZES; i++) ++ ff_mdct_end(&s->mdct_ctx[i]); ++ ++ return 0; ++} ++ ++/** ++ *@brief Initialize the decoder. ++ *@param avctx codec context ++ *@return 0 on success, -1 otherwise ++ */ ++static av_cold int decode_init(AVCodecContext *avctx) ++{ ++ WmallDecodeCtx *s = avctx->priv_data; ++ uint8_t *edata_ptr = avctx->extradata; ++ unsigned int channel_mask; ++ int i; ++ int log2_max_num_subframes; ++ int num_possible_block_sizes; ++ ++ s->avctx = avctx; ++ dsputil_init(&s->dsp, avctx); ++ init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); ++ ++ if (avctx->extradata_size >= 18) { ++ s->decode_flags = AV_RL16(edata_ptr+14); ++ channel_mask = AV_RL32(edata_ptr+2); ++ s->bits_per_sample = AV_RL16(edata_ptr); ++ if (s->bits_per_sample == 16) ++ avctx->sample_fmt = AV_SAMPLE_FMT_S16; ++ else if (s->bits_per_sample == 24) ++ avctx->sample_fmt = AV_SAMPLE_FMT_S32; ++ else { ++ av_log(avctx, AV_LOG_ERROR, "Unknown bit-depth: %d\n", ++ s->bits_per_sample); ++ return AVERROR_INVALIDDATA; ++ } ++ /** dump the extradata */ ++ for (i = 0; i < avctx->extradata_size; i++) ++ dprintf(avctx, "[%x] ", avctx->extradata[i]); ++ dprintf(avctx, "\n"); ++ ++ } else { ++ av_log_ask_for_sample(avctx, "Unknown extradata size\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /** generic init */ ++ s->log2_frame_size = av_log2(avctx->block_align) + 4; ++ ++ /** frame info */ ++ s->skip_frame = 1; /* skip first frame */ ++ s->packet_loss = 1; ++ s->len_prefix = (s->decode_flags & 0x40); ++ ++ /** get frame len */ ++ s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate, ++ 3, s->decode_flags); ++ ++ /** init previous block len */ ++ for (i = 0; i < avctx->channels; i++) ++ s->channel[i].prev_block_len = s->samples_per_frame; ++ ++ /** subframe info */ ++ log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3); ++ s->max_num_subframes = 1 << log2_max_num_subframes; ++ s->max_subframe_len_bit = 0; ++ s->subframe_len_bits = av_log2(log2_max_num_subframes) + 1; ++ ++ num_possible_block_sizes = log2_max_num_subframes + 1; ++ s->min_samples_per_subframe = s->samples_per_frame / s->max_num_subframes; ++ s->dynamic_range_compression = (s->decode_flags & 0x80); ++ ++ s->bV3RTM = s->decode_flags & 0x100; ++ ++ if (s->max_num_subframes > MAX_SUBFRAMES) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of subframes %i\n", ++ s->max_num_subframes); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ s->num_channels = avctx->channels; ++ ++ /** extract lfe channel position */ ++ s->lfe_channel = -1; ++ ++ if (channel_mask & 8) { ++ unsigned int mask; ++ for (mask = 1; mask < 16; mask <<= 1) { ++ if (channel_mask & mask) ++ ++s->lfe_channel; ++ } ++ } ++ ++ if (s->num_channels < 0) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels); ++ return AVERROR_INVALIDDATA; ++ } else if (s->num_channels > WMALL_MAX_CHANNELS) { ++ av_log_ask_for_sample(avctx, "unsupported number of channels\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ avctx->channel_layout = channel_mask; ++ return 0; ++} ++ ++/** ++ *@brief Decode the subframe length. ++ *@param s context ++ *@param offset sample offset in the frame ++ *@return decoded subframe length on success, < 0 in case of an error ++ */ ++static int decode_subframe_length(WmallDecodeCtx *s, int offset) ++{ ++ int frame_len_ratio; ++ int subframe_len, len; ++ ++ /** no need to read from the bitstream when only one length is possible */ ++ if (offset == s->samples_per_frame - s->min_samples_per_subframe) ++ return s->min_samples_per_subframe; ++ ++ len = av_log2(s->max_num_subframes - 1) + 1; ++ frame_len_ratio = get_bits(&s->gb, len); ++ ++ subframe_len = s->min_samples_per_subframe * (frame_len_ratio + 1); ++ ++ /** sanity check the length */ ++ if (subframe_len < s->min_samples_per_subframe || ++ subframe_len > s->samples_per_frame) { ++ av_log(s->avctx, AV_LOG_ERROR, "broken frame: subframe_len %i\n", ++ subframe_len); ++ return AVERROR_INVALIDDATA; ++ } ++ return subframe_len; ++} ++ ++/** ++ *@brief Decode how the data in the frame is split into subframes. ++ * Every WMA frame contains the encoded data for a fixed number of ++ * samples per channel. The data for every channel might be split ++ * into several subframes. This function will reconstruct the list of ++ * subframes for every channel. ++ * ++ * If the subframes are not evenly split, the algorithm estimates the ++ * channels with the lowest number of total samples. ++ * Afterwards, for each of these channels a bit is read from the ++ * bitstream that indicates if the channel contains a subframe with the ++ * next subframe size that is going to be read from the bitstream or not. ++ * If a channel contains such a subframe, the subframe size gets added to ++ * the channel's subframe list. ++ * The algorithm repeats these steps until the frame is properly divided ++ * between the individual channels. ++ * ++ *@param s context ++ *@return 0 on success, < 0 in case of an error ++ */ ++static int decode_tilehdr(WmallDecodeCtx *s) ++{ ++ uint16_t num_samples[WMALL_MAX_CHANNELS]; /**< sum of samples for all currently known subframes of a channel */ ++ uint8_t contains_subframe[WMALL_MAX_CHANNELS]; /**< flag indicating if a channel contains the current subframe */ ++ int channels_for_cur_subframe = s->num_channels; /**< number of channels that contain the current subframe */ ++ int fixed_channel_layout = 0; /**< flag indicating that all channels use the same subfra2me offsets and sizes */ ++ int min_channel_len = 0; /**< smallest sum of samples (channels with this length will be processed first) */ ++ int c; ++ ++ /* Should never consume more than 3073 bits (256 iterations for the ++ * while loop when always the minimum amount of 128 samples is substracted ++ * from missing samples in the 8 channel case). ++ * 1 + BLOCK_MAX_SIZE * MAX_CHANNELS / BLOCK_MIN_SIZE * (MAX_CHANNELS + 4) ++ */ ++ ++ /** reset tiling information */ ++ for (c = 0; c < s->num_channels; c++) ++ s->channel[c].num_subframes = 0; ++ ++ memset(num_samples, 0, sizeof(num_samples)); ++ ++ if (s->max_num_subframes == 1 || get_bits1(&s->gb)) ++ fixed_channel_layout = 1; ++ ++ /** loop until the frame data is split between the subframes */ ++ do { ++ int subframe_len; ++ ++ /** check which channels contain the subframe */ ++ for (c = 0; c < s->num_channels; c++) { ++ if (num_samples[c] == min_channel_len) { ++ if (fixed_channel_layout || channels_for_cur_subframe == 1 || ++ (min_channel_len == s->samples_per_frame - s->min_samples_per_subframe)) { ++ contains_subframe[c] = 1; ++ } ++ else { ++ contains_subframe[c] = get_bits1(&s->gb); ++ } ++ } else ++ contains_subframe[c] = 0; ++ } ++ ++ /** get subframe length, subframe_len == 0 is not allowed */ ++ if ((subframe_len = decode_subframe_length(s, min_channel_len)) <= 0) ++ return AVERROR_INVALIDDATA; ++ /** add subframes to the individual channels and find new min_channel_len */ ++ min_channel_len += subframe_len; ++ for (c = 0; c < s->num_channels; c++) { ++ WmallChannelCtx* chan = &s->channel[c]; ++ ++ if (contains_subframe[c]) { ++ if (chan->num_subframes >= MAX_SUBFRAMES) { ++ av_log(s->avctx, AV_LOG_ERROR, ++ "broken frame: num subframes > 31\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ chan->subframe_len[chan->num_subframes] = subframe_len; ++ num_samples[c] += subframe_len; ++ ++chan->num_subframes; ++ if (num_samples[c] > s->samples_per_frame) { ++ av_log(s->avctx, AV_LOG_ERROR, "broken frame: " ++ "channel len(%d) > samples_per_frame(%d)\n", ++ num_samples[c], s->samples_per_frame); ++ return AVERROR_INVALIDDATA; ++ } ++ } else if (num_samples[c] <= min_channel_len) { ++ if (num_samples[c] < min_channel_len) { ++ channels_for_cur_subframe = 0; ++ min_channel_len = num_samples[c]; ++ } ++ ++channels_for_cur_subframe; ++ } ++ } ++ } while (min_channel_len < s->samples_per_frame); ++ ++ for (c = 0; c < s->num_channels; c++) { ++ int i; ++ int offset = 0; ++ for (i = 0; i < s->channel[c].num_subframes; i++) { ++ s->channel[c].subframe_offset[i] = offset; ++ offset += s->channel[c].subframe_len[i]; ++ } ++ } ++ ++ return 0; ++} ++ ++ ++static int my_log2(unsigned int i) ++{ ++ unsigned int iLog2 = 0; ++ while ((i >> iLog2) > 1) ++ iLog2++; ++ return iLog2; ++} ++ ++ ++/** ++ * ++ */ ++static void decode_ac_filter(WmallDecodeCtx *s) ++{ ++ int i; ++ s->acfilter_order = get_bits(&s->gb, 4) + 1; ++ s->acfilter_scaling = get_bits(&s->gb, 4); ++ ++ for(i = 0; i < s->acfilter_order; i++) { ++ s->acfilter_coeffs[i] = get_bits(&s->gb, s->acfilter_scaling) + 1; ++ } ++} ++ ++ ++/** ++ * ++ */ ++static void decode_mclms(WmallDecodeCtx *s) ++{ ++ s->mclms_order = (get_bits(&s->gb, 4) + 1) * 2; ++ s->mclms_scaling = get_bits(&s->gb, 4); ++ if(get_bits1(&s->gb)) { ++ // mclms_send_coef ++ int i; ++ int send_coef_bits; ++ int cbits = av_log2(s->mclms_scaling + 1); ++ assert(cbits == my_log2(s->mclms_scaling + 1)); ++ if(1 << cbits < s->mclms_scaling + 1) ++ cbits++; ++ ++ send_coef_bits = (cbits ? get_bits(&s->gb, cbits) : 0) + 2; ++ ++ for(i = 0; i < s->mclms_order * s->num_channels * s->num_channels; i++) { ++ s->mclms_coeffs[i] = get_bits(&s->gb, send_coef_bits); ++ } ++ ++ for(i = 0; i < s->num_channels; i++) { ++ int c; ++ for(c = 0; c < i; c++) { ++ s->mclms_coeffs_cur[i * s->num_channels + c] = get_bits(&s->gb, send_coef_bits); ++ } ++ } ++ } ++} ++ ++ ++/** ++ * ++ */ ++static void decode_cdlms(WmallDecodeCtx *s) ++{ ++ int c, i; ++ int cdlms_send_coef = get_bits1(&s->gb); ++ ++ for(c = 0; c < s->num_channels; c++) { ++ s->cdlms_ttl[c] = get_bits(&s->gb, 3) + 1; ++ for(i = 0; i < s->cdlms_ttl[c]; i++) { ++ s->cdlms[c][i].order = (get_bits(&s->gb, 7) + 1) * 8; ++ } ++ ++ for(i = 0; i < s->cdlms_ttl[c]; i++) { ++ s->cdlms[c][i].scaling = get_bits(&s->gb, 4); ++ } ++ ++ if(cdlms_send_coef) { ++ for(i = 0; i < s->cdlms_ttl[c]; i++) { ++ int cbits, shift_l, shift_r, j; ++ cbits = av_log2(s->cdlms[c][i].order); ++ if(1 << cbits < s->cdlms[c][i].order) ++ cbits++; ++ s->cdlms[c][i].coefsend = get_bits(&s->gb, cbits) + 1; ++ ++ cbits = av_log2(s->cdlms[c][i].scaling + 1); ++ if(1 << cbits < s->cdlms[c][i].scaling + 1) ++ cbits++; ++ ++ s->cdlms[c][i].bitsend = get_bits(&s->gb, cbits) + 2; ++ shift_l = 32 - s->cdlms[c][i].bitsend; ++ shift_r = 32 - 2 - s->cdlms[c][i].scaling; ++ for(j = 0; j < s->cdlms[c][i].coefsend; j++) { ++ s->cdlms[c][i].coefs[j] = ++ (get_bits(&s->gb, s->cdlms[c][i].bitsend) << shift_l) >> shift_r; ++ } ++ } ++ } ++ } ++} ++ ++/** ++ * ++ */ ++static int decode_channel_residues(WmallDecodeCtx *s, int ch, int tile_size) ++{ ++ int i = 0; ++ unsigned int ave_mean; ++ s->transient[ch] = get_bits1(&s->gb); ++ if(s->transient[ch]) { ++ s->transient_pos[ch] = get_bits(&s->gb, av_log2(tile_size)); ++ if (s->transient_pos[ch]) ++ s->transient[ch] = 0; ++ s->channel[ch].transient_counter = ++ FFMAX(s->channel[ch].transient_counter, s->samples_per_frame / 2); ++ } else if (s->channel[ch].transient_counter) ++ s->transient[ch] = 1; ++ ++ if(s->seekable_tile) { ++ ave_mean = get_bits(&s->gb, s->bits_per_sample); ++ s->ave_sum[ch] = ave_mean << (s->movave_scaling + 1); ++// s->ave_sum[ch] *= 2; ++ } ++ ++ if(s->seekable_tile) { ++ if(s->do_inter_ch_decorr) ++ s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample + 1); ++ else ++ s->channel_residues[ch][0] = get_sbits(&s->gb, s->bits_per_sample); ++ i++; ++ } ++ //av_log(0, 0, "%8d: ", num_logged_tiles++); ++ for(; i < tile_size; i++) { ++ int quo = 0, rem, rem_bits, residue; ++ while(get_bits1(&s->gb)) ++ quo++; ++ if(quo >= 32) ++ quo += get_bits_long(&s->gb, get_bits(&s->gb, 5) + 1); ++ ++ ave_mean = (s->ave_sum[ch] + (1 << s->movave_scaling)) >> (s->movave_scaling + 1); ++ rem_bits = av_ceil_log2(ave_mean); ++ rem = rem_bits ? get_bits(&s->gb, rem_bits) : 0; ++ residue = (quo << rem_bits) + rem; ++ ++ s->ave_sum[ch] = residue + s->ave_sum[ch] - (s->ave_sum[ch] >> s->movave_scaling); ++ ++ if(residue & 1) ++ residue = -(residue >> 1) - 1; ++ else ++ residue = residue >> 1; ++ s->channel_residues[ch][i] = residue; ++ } ++ //dump_int_buffer(s->channel_residues[ch], 4, tile_size, 16); ++ ++ return 0; ++ ++} ++ ++ ++/** ++ * ++ */ ++static void ++decode_lpc(WmallDecodeCtx *s) ++{ ++ int ch, i, cbits; ++ s->lpc_order = get_bits(&s->gb, 5) + 1; ++ s->lpc_scaling = get_bits(&s->gb, 4); ++ s->lpc_intbits = get_bits(&s->gb, 3) + 1; ++ cbits = s->lpc_scaling + s->lpc_intbits; ++ for(ch = 0; ch < s->num_channels; ch++) { ++ for(i = 0; i < s->lpc_order; i++) { ++ s->lpc_coefs[ch][i] = get_sbits(&s->gb, cbits); ++ } ++ } ++} ++ ++ ++static void clear_codec_buffers(WmallDecodeCtx *s) ++{ ++ int ich, ilms; ++ ++ memset(s->acfilter_coeffs , 0, 16 * sizeof(int)); ++ memset(s->acfilter_prevvalues, 0, 16 * 2 * sizeof(int)); // may be wrong ++ memset(s->lpc_coefs , 0, 40 * 2 * sizeof(int)); ++ ++ memset(s->mclms_coeffs , 0, 128 * sizeof(int16_t)); ++ memset(s->mclms_coeffs_cur, 0, 4 * sizeof(int16_t)); ++ memset(s->mclms_prevvalues, 0, 64 * sizeof(int)); ++ memset(s->mclms_updates , 0, 64 * sizeof(int16_t)); ++ ++ for (ich = 0; ich < s->num_channels; ich++) { ++ for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) { ++ memset(s->cdlms[ich][ilms].coefs , 0, 256 * sizeof(int16_t)); ++ memset(s->cdlms[ich][ilms].lms_prevvalues, 0, 512 * sizeof(int16_t)); ++ memset(s->cdlms[ich][ilms].lms_updates , 0, 512 * sizeof(int16_t)); ++ } ++ s->ave_sum[ich] = 0; ++ } ++} ++ ++/** ++ *@brief Resets filter parameters and transient area at new seekable tile ++ */ ++static void reset_codec(WmallDecodeCtx *s) ++{ ++ int ich, ilms; ++ s->mclms_recent = s->mclms_order * s->num_channels; ++ for (ich = 0; ich < s->num_channels; ich++) { ++ for (ilms = 0; ilms < s->cdlms_ttl[ich]; ilms++) ++ s->cdlms[ich][ilms].recent = s->cdlms[ich][ilms].order; ++ /* first sample of a seekable subframe is considered as the starting of ++ a transient area which is samples_per_frame samples long */ ++ s->channel[ich].transient_counter = s->samples_per_frame; ++ s->transient[ich] = 1; ++ s->transient_pos[ich] = 0; ++ } ++} ++ ++ ++ ++static void mclms_update(WmallDecodeCtx *s, int icoef, int *pred) ++{ ++ int i, j, ich; ++ int pred_error; ++ int order = s->mclms_order; ++ int num_channels = s->num_channels; ++ int range = 1 << (s->bits_per_sample - 1); ++ int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample ++ ++ for (ich = 0; ich < num_channels; ich++) { ++ pred_error = s->channel_residues[ich][icoef] - pred[ich]; ++ if (pred_error > 0) { ++ for (i = 0; i < order * num_channels; i++) ++ s->mclms_coeffs[i + ich * order * num_channels] += ++ s->mclms_updates[s->mclms_recent + i]; ++ for (j = 0; j < ich; j++) { ++ if (s->channel_residues[j][icoef] > 0) ++ s->mclms_coeffs_cur[ich * num_channels + j] += 1; ++ else if (s->channel_residues[j][icoef] < 0) ++ s->mclms_coeffs_cur[ich * num_channels + j] -= 1; ++ } ++ } else if (pred_error < 0) { ++ for (i = 0; i < order * num_channels; i++) ++ s->mclms_coeffs[i + ich * order * num_channels] -= ++ s->mclms_updates[s->mclms_recent + i]; ++ for (j = 0; j < ich; j++) { ++ if (s->channel_residues[j][icoef] > 0) ++ s->mclms_coeffs_cur[ich * num_channels + j] -= 1; ++ else if (s->channel_residues[j][icoef] < 0) ++ s->mclms_coeffs_cur[ich * num_channels + j] += 1; ++ } ++ } ++ } ++ ++ for (ich = num_channels - 1; ich >= 0; ich--) { ++ s->mclms_recent--; ++ s->mclms_prevvalues[s->mclms_recent] = s->channel_residues[ich][icoef]; ++ if (s->channel_residues[ich][icoef] > range - 1) ++ s->mclms_prevvalues[s->mclms_recent] = range - 1; ++ else if (s->channel_residues[ich][icoef] < -range) ++ s->mclms_prevvalues[s->mclms_recent] = -range; ++ ++ s->mclms_updates[s->mclms_recent] = 0; ++ if (s->channel_residues[ich][icoef] > 0) ++ s->mclms_updates[s->mclms_recent] = 1; ++ else if (s->channel_residues[ich][icoef] < 0) ++ s->mclms_updates[s->mclms_recent] = -1; ++ } ++ ++ if (s->mclms_recent == 0) { ++ memcpy(&s->mclms_prevvalues[order * num_channels], ++ s->mclms_prevvalues, ++ bps * order * num_channels); ++ memcpy(&s->mclms_updates[order * num_channels], ++ s->mclms_updates, ++ bps * order * num_channels); ++ s->mclms_recent = num_channels * order; ++ } ++} ++ ++static void mclms_predict(WmallDecodeCtx *s, int icoef, int *pred) ++{ ++ int ich, i; ++ int order = s->mclms_order; ++ int num_channels = s->num_channels; ++ ++ for (ich = 0; ich < num_channels; ich++) { ++ if (!s->is_channel_coded[ich]) ++ continue; ++ pred[ich] = 0; ++ for (i = 0; i < order * num_channels; i++) ++ pred[ich] += s->mclms_prevvalues[i + s->mclms_recent] * ++ s->mclms_coeffs[i + order * num_channels * ich]; ++ for (i = 0; i < ich; i++) ++ pred[ich] += s->channel_residues[i][icoef] * ++ s->mclms_coeffs_cur[i + num_channels * ich]; ++ pred[ich] += 1 << s->mclms_scaling - 1; ++ pred[ich] >>= s->mclms_scaling; ++ s->channel_residues[ich][icoef] += pred[ich]; ++ } ++} ++ ++static void revert_mclms(WmallDecodeCtx *s, int tile_size) ++{ ++ int icoef, pred[s->num_channels]; ++ for (icoef = 0; icoef < tile_size; icoef++) { ++ mclms_predict(s, icoef, pred); ++ mclms_update(s, icoef, pred); ++ } ++} ++ ++static int lms_predict(WmallDecodeCtx *s, int ich, int ilms) ++{ ++ int pred = 0; ++ int icoef; ++ int recent = s->cdlms[ich][ilms].recent; ++ ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ pred += s->cdlms[ich][ilms].coefs[icoef] * ++ s->cdlms[ich][ilms].lms_prevvalues[icoef + recent]; ++ ++ //pred += (1 << (s->cdlms[ich][ilms].scaling - 1)); ++ /* XXX: Table 29 has: ++ iPred >= cdlms[iCh][ilms].scaling; ++ seems to me like a missing > */ ++ //pred >>= s->cdlms[ich][ilms].scaling; ++ return pred; ++} ++ ++static void lms_update(WmallDecodeCtx *s, int ich, int ilms, int input, int residue) ++{ ++ int icoef; ++ int recent = s->cdlms[ich][ilms].recent; ++ int range = 1 << s->bits_per_sample - 1; ++ int bps = s->bits_per_sample > 16 ? 4 : 2; // bytes per sample ++ ++ if (residue < 0) { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].coefs[icoef] -= ++ s->cdlms[ich][ilms].lms_updates[icoef + recent]; ++ } else if (residue > 0) { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].coefs[icoef] += ++ s->cdlms[ich][ilms].lms_updates[icoef + recent]; /* spec mistakenly ++ dropped the recent */ ++ } ++ ++ if (recent) ++ recent--; ++ else { ++ /* XXX: This memcpy()s will probably fail if a fixed 32-bit buffer is used. ++ follow kshishkov's suggestion of using a union. */ ++ memcpy(&s->cdlms[ich][ilms].lms_prevvalues[s->cdlms[ich][ilms].order], ++ s->cdlms[ich][ilms].lms_prevvalues, ++ bps * s->cdlms[ich][ilms].order); ++ memcpy(&s->cdlms[ich][ilms].lms_updates[s->cdlms[ich][ilms].order], ++ s->cdlms[ich][ilms].lms_updates, ++ bps * s->cdlms[ich][ilms].order); ++ recent = s->cdlms[ich][ilms].order - 1; ++ } ++ ++ s->cdlms[ich][ilms].lms_prevvalues[recent] = av_clip(input, -range, range - 1); ++ if (!input) ++ s->cdlms[ich][ilms].lms_updates[recent] = 0; ++ else if (input < 0) ++ s->cdlms[ich][ilms].lms_updates[recent] = -s->update_speed[ich]; ++ else ++ s->cdlms[ich][ilms].lms_updates[recent] = s->update_speed[ich]; ++ ++ /* XXX: spec says: ++ cdlms[iCh][ilms].updates[iRecent + cdlms[iCh][ilms].order >> 4] >>= 2; ++ lms_updates[iCh][ilms][iRecent + cdlms[iCh][ilms].order >> 3] >>= 1; ++ ++ Questions is - are cdlms[iCh][ilms].updates[] and lms_updates[][][] two ++ seperate buffers? Here I've assumed that the two are same which makes ++ more sense to me. ++ */ ++ s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 4)] >>= 2; ++ s->cdlms[ich][ilms].lms_updates[recent + (s->cdlms[ich][ilms].order >> 3)] >>= 1; ++ s->cdlms[ich][ilms].recent = recent; ++} ++ ++static void use_high_update_speed(WmallDecodeCtx *s, int ich) ++{ ++ int ilms, recent, icoef; ++ for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) { ++ recent = s->cdlms[ich][ilms].recent; ++ if (s->update_speed[ich] == 16) ++ continue; ++ if (s->bV3RTM) { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].lms_updates[icoef + recent] *= 2; ++ } else { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].lms_updates[icoef] *= 2; ++ } ++ } ++ s->update_speed[ich] = 16; ++} ++ ++static void use_normal_update_speed(WmallDecodeCtx *s, int ich) ++{ ++ int ilms, recent, icoef; ++ for (ilms = s->cdlms_ttl[ich] - 1; ilms >= 0; ilms--) { ++ recent = s->cdlms[ich][ilms].recent; ++ if (s->update_speed[ich] == 8) ++ continue; ++ if (s->bV3RTM) { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].lms_updates[icoef + recent] /= 2; ++ } else { ++ for (icoef = 0; icoef < s->cdlms[ich][ilms].order; icoef++) ++ s->cdlms[ich][ilms].lms_updates[icoef] /= 2; ++ } ++ } ++ s->update_speed[ich] = 8; ++} ++ ++static void revert_cdlms(WmallDecodeCtx *s, int ch, int coef_begin, int coef_end) ++{ ++ int icoef; ++ int pred; ++ int ilms, num_lms; ++ int residue, input; ++ ++ num_lms = s->cdlms_ttl[ch]; ++ for (ilms = num_lms - 1; ilms >= 0; ilms--) { ++ //s->cdlms[ch][ilms].recent = s->cdlms[ch][ilms].order; ++ for (icoef = coef_begin; icoef < coef_end; icoef++) { ++ pred = 1 << (s->cdlms[ch][ilms].scaling - 1); ++ residue = s->channel_residues[ch][icoef]; ++ pred += lms_predict(s, ch, ilms); ++ input = residue + (pred >> s->cdlms[ch][ilms].scaling); ++ lms_update(s, ch, ilms, input, residue); ++ s->channel_residues[ch][icoef] = input; ++ } ++ } ++} ++ ++static void revert_inter_ch_decorr(WmallDecodeCtx *s, int tile_size) ++{ ++ int icoef; ++ if (s->num_channels != 2) ++ return; ++ else { ++ for (icoef = 0; icoef < tile_size; icoef++) { ++ s->channel_residues[0][icoef] -= s->channel_residues[1][icoef] >> 1; ++ s->channel_residues[1][icoef] += s->channel_residues[0][icoef]; ++ } ++ } ++} ++ ++static void revert_acfilter(WmallDecodeCtx *s, int tile_size) ++{ ++ int ich, icoef; ++ int pred; ++ int i, j; ++ int64_t *filter_coeffs = s->acfilter_coeffs; ++ int scaling = s->acfilter_scaling; ++ int order = s->acfilter_order; ++ ++ for (ich = 0; ich < s->num_channels; ich++) { ++ int *prevvalues = s->acfilter_prevvalues[ich]; ++ for (i = 0; i < order; i++) { ++ pred = 0; ++ for (j = 0; j < order; j++) { ++ if (i <= j) ++ pred += filter_coeffs[j] * prevvalues[j - i]; ++ else ++ pred += s->channel_residues[ich][i - j - 1] * filter_coeffs[j]; ++ } ++ pred >>= scaling; ++ s->channel_residues[ich][i] += pred; ++ } ++ for (i = order; i < tile_size; i++) { ++ pred = 0; ++ for (j = 0; j < order; j++) ++ pred += s->channel_residues[ich][i - j - 1] * filter_coeffs[j]; ++ pred >>= scaling; ++ s->channel_residues[ich][i] += pred; ++ } ++ for (j = 0; j < order; j++) ++ prevvalues[j] = s->channel_residues[ich][tile_size - j - 1]; ++ } ++} ++ ++/** ++ *@brief Decode a single subframe (block). ++ *@param s codec context ++ *@return 0 on success, < 0 when decoding failed ++ */ ++static int decode_subframe(WmallDecodeCtx *s) ++{ ++ int offset = s->samples_per_frame; ++ int subframe_len = s->samples_per_frame; ++ int i, j; ++ int total_samples = s->samples_per_frame * s->num_channels; ++ int rawpcm_tile; ++ int padding_zeroes; ++ ++ s->subframe_offset = get_bits_count(&s->gb); ++ ++ /** reset channel context and find the next block offset and size ++ == the next block of the channel with the smallest number of ++ decoded samples ++ */ ++ for (i = 0; i < s->num_channels; i++) { ++ s->channel[i].grouped = 0; ++ if (offset > s->channel[i].decoded_samples) { ++ offset = s->channel[i].decoded_samples; ++ subframe_len = ++ s->channel[i].subframe_len[s->channel[i].cur_subframe]; ++ } ++ } ++ ++ /** get a list of all channels that contain the estimated block */ ++ s->channels_for_cur_subframe = 0; ++ for (i = 0; i < s->num_channels; i++) { ++ const int cur_subframe = s->channel[i].cur_subframe; ++ /** substract already processed samples */ ++ total_samples -= s->channel[i].decoded_samples; ++ ++ /** and count if there are multiple subframes that match our profile */ ++ if (offset == s->channel[i].decoded_samples && ++ subframe_len == s->channel[i].subframe_len[cur_subframe]) { ++ total_samples -= s->channel[i].subframe_len[cur_subframe]; ++ s->channel[i].decoded_samples += ++ s->channel[i].subframe_len[cur_subframe]; ++ s->channel_indexes_for_cur_subframe[s->channels_for_cur_subframe] = i; ++ ++s->channels_for_cur_subframe; ++ } ++ } ++ ++ /** check if the frame will be complete after processing the ++ estimated block */ ++ if (!total_samples) ++ s->parsed_all_subframes = 1; ++ ++ ++ s->seekable_tile = get_bits1(&s->gb); ++ if(s->seekable_tile) { ++ clear_codec_buffers(s); ++ ++ s->do_arith_coding = get_bits1(&s->gb); ++ if(s->do_arith_coding) { ++ dprintf(s->avctx, "do_arith_coding == 1"); ++ abort(); ++ } ++ s->do_ac_filter = get_bits1(&s->gb); ++ s->do_inter_ch_decorr = get_bits1(&s->gb); ++ s->do_mclms = get_bits1(&s->gb); ++ ++ if(s->do_ac_filter) ++ decode_ac_filter(s); ++ ++ if(s->do_mclms) ++ decode_mclms(s); ++ ++ decode_cdlms(s); ++ s->movave_scaling = get_bits(&s->gb, 3); ++ s->quant_stepsize = get_bits(&s->gb, 8) + 1; ++ ++ reset_codec(s); ++ } ++ ++ rawpcm_tile = get_bits1(&s->gb); ++ ++ for(i = 0; i < s->num_channels; i++) { ++ s->is_channel_coded[i] = 1; ++ } ++ ++ if(!rawpcm_tile) { ++ ++ for(i = 0; i < s->num_channels; i++) { ++ s->is_channel_coded[i] = get_bits1(&s->gb); ++ } ++ ++ if(s->bV3RTM) { ++ // LPC ++ s->do_lpc = get_bits1(&s->gb); ++ if(s->do_lpc) { ++ decode_lpc(s); ++ } ++ } else { ++ s->do_lpc = 0; ++ } ++ } ++ ++ ++ if(get_bits1(&s->gb)) { ++ padding_zeroes = get_bits(&s->gb, 5); ++ } else { ++ padding_zeroes = 0; ++ } ++ ++ if(rawpcm_tile) { ++ ++ int bits = s->bits_per_sample - padding_zeroes; ++ dprintf(s->avctx, "RAWPCM %d bits per sample. total %d bits, remain=%d\n", bits, ++ bits * s->num_channels * subframe_len, get_bits_count(&s->gb)); ++ for(i = 0; i < s->num_channels; i++) { ++ for(j = 0; j < subframe_len; j++) { ++ s->channel_coeffs[i][j] = get_sbits(&s->gb, bits); ++// dprintf(s->avctx, "PCM[%d][%d] = 0x%04x\n", i, j, s->channel_coeffs[i][j]); ++ } ++ } ++ } else { ++ for(i = 0; i < s->num_channels; i++) ++ if(s->is_channel_coded[i]) { ++ decode_channel_residues(s, i, subframe_len); ++ if (s->seekable_tile) ++ use_high_update_speed(s, i); ++ else ++ use_normal_update_speed(s, i); ++ revert_cdlms(s, i, 0, subframe_len); ++ } ++ } ++ if (s->do_mclms) ++ revert_mclms(s, subframe_len); ++ if (s->do_inter_ch_decorr) ++ revert_inter_ch_decorr(s, subframe_len); ++ if(s->do_ac_filter) ++ revert_acfilter(s, subframe_len); ++ ++ /* Dequantize */ ++ if (s->quant_stepsize != 1) ++ for (i = 0; i < s->num_channels; i++) ++ for (j = 0; j < subframe_len; j++) ++ s->channel_residues[i][j] *= s->quant_stepsize; ++ ++ // Write to proper output buffer depending on bit-depth ++ for (i = 0; i < subframe_len; i++) ++ for (j = 0; j < s->num_channels; j++) { ++ if (s->bits_per_sample == 16) ++ *s->samples_16++ = (int16_t) s->channel_residues[j][i]; ++ else ++ *s->samples_32++ = s->channel_residues[j][i]; ++ } ++ ++ /** handled one subframe */ ++ ++ for (i = 0; i < s->channels_for_cur_subframe; i++) { ++ int c = s->channel_indexes_for_cur_subframe[i]; ++ if (s->channel[c].cur_subframe >= s->channel[c].num_subframes) { ++ av_log(s->avctx, AV_LOG_ERROR, "broken subframe\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++s->channel[c].cur_subframe; ++ } ++ num_logged_subframes++; ++ return 0; ++} ++ ++/** ++ *@brief Decode one WMA frame. ++ *@param s codec context ++ *@return 0 if the trailer bit indicates that this is the last frame, ++ * 1 if there are additional frames ++ */ ++static int decode_frame(WmallDecodeCtx *s) ++{ ++ GetBitContext* gb = &s->gb; ++ int more_frames = 0; ++ int len = 0; ++ int i; ++ int buffer_len; ++ ++ /** check for potential output buffer overflow */ ++ if (s->bits_per_sample == 16) ++ buffer_len = s->samples_16_end - s->samples_16; ++ else ++ buffer_len = s->samples_32_end - s->samples_32; ++ if (s->num_channels * s->samples_per_frame > buffer_len) { ++ /** return an error if no frame could be decoded at all */ ++ av_log(s->avctx, AV_LOG_ERROR, ++ "not enough space for the output samples\n"); ++ s->packet_loss = 1; ++ return 0; ++ } ++ ++ /** get frame length */ ++ if (s->len_prefix) ++ len = get_bits(gb, s->log2_frame_size); ++ ++ /** decode tile information */ ++ if (decode_tilehdr(s)) { ++ s->packet_loss = 1; ++ return 0; ++ } ++ ++ /** read drc info */ ++ if (s->dynamic_range_compression) { ++ s->drc_gain = get_bits(gb, 8); ++ } ++ ++ /** no idea what these are for, might be the number of samples ++ that need to be skipped at the beginning or end of a stream */ ++ if (get_bits1(gb)) { ++ int skip; ++ ++ /** usually true for the first frame */ ++ if (get_bits1(gb)) { ++ skip = get_bits(gb, av_log2(s->samples_per_frame * 2)); ++ dprintf(s->avctx, "start skip: %i\n", skip); ++ } ++ ++ /** sometimes true for the last frame */ ++ if (get_bits1(gb)) { ++ skip = get_bits(gb, av_log2(s->samples_per_frame * 2)); ++ dprintf(s->avctx, "end skip: %i\n", skip); ++ } ++ ++ } ++ ++ /** reset subframe states */ ++ s->parsed_all_subframes = 0; ++ for (i = 0; i < s->num_channels; i++) { ++ s->channel[i].decoded_samples = 0; ++ s->channel[i].cur_subframe = 0; ++ s->channel[i].reuse_sf = 0; ++ } ++ ++ /** decode all subframes */ ++ while (!s->parsed_all_subframes) { ++ if (decode_subframe(s) < 0) { ++ s->packet_loss = 1; ++ return 0; ++ } ++ } ++ ++ dprintf(s->avctx, "Frame done\n"); ++ ++ if (s->skip_frame) { ++ s->skip_frame = 0; ++ } ++ ++ if (s->len_prefix) { ++ if (len != (get_bits_count(gb) - s->frame_offset) + 2) { ++ /** FIXME: not sure if this is always an error */ ++ av_log(s->avctx, AV_LOG_ERROR, ++ "frame[%i] would have to skip %i bits\n", s->frame_num, ++ len - (get_bits_count(gb) - s->frame_offset) - 1); ++ s->packet_loss = 1; ++ return 0; ++ } ++ ++ /** skip the rest of the frame data */ ++ skip_bits_long(gb, len - (get_bits_count(gb) - s->frame_offset) - 1); ++ } else { ++/* ++ while (get_bits_count(gb) < s->num_saved_bits && get_bits1(gb) == 0) { ++ dprintf(s->avctx, "skip1\n"); ++ } ++*/ ++ } ++ ++ /** decode trailer bit */ ++ more_frames = get_bits1(gb); ++ ++s->frame_num; ++ return more_frames; ++} ++ ++/** ++ *@brief Calculate remaining input buffer length. ++ *@param s codec context ++ *@param gb bitstream reader context ++ *@return remaining size in bits ++ */ ++static int remaining_bits(WmallDecodeCtx *s, GetBitContext *gb) ++{ ++ return s->buf_bit_size - get_bits_count(gb); ++} ++ ++/** ++ *@brief Fill the bit reservoir with a (partial) frame. ++ *@param s codec context ++ *@param gb bitstream reader context ++ *@param len length of the partial frame ++ *@param append decides wether to reset the buffer or not ++ */ ++static void save_bits(WmallDecodeCtx *s, GetBitContext* gb, int len, ++ int append) ++{ ++ int buflen; ++ ++ /** when the frame data does not need to be concatenated, the input buffer ++ is resetted and additional bits from the previous frame are copyed ++ and skipped later so that a fast byte copy is possible */ ++ ++ if (!append) { ++ s->frame_offset = get_bits_count(gb) & 7; ++ s->num_saved_bits = s->frame_offset; ++ init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); ++ } ++ ++ buflen = (s->num_saved_bits + len + 8) >> 3; ++ ++ if (len <= 0 || buflen > MAX_FRAMESIZE) { ++ av_log_ask_for_sample(s->avctx, "input buffer too small\n"); ++ s->packet_loss = 1; ++ return; ++ } ++ ++ s->num_saved_bits += len; ++ if (!append) { ++ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), ++ s->num_saved_bits); ++ } else { ++ int align = 8 - (get_bits_count(gb) & 7); ++ align = FFMIN(align, len); ++ put_bits(&s->pb, align, get_bits(gb, align)); ++ len -= align; ++ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len); ++ } ++ skip_bits_long(gb, len); ++ ++ { ++ PutBitContext tmp = s->pb; ++ flush_put_bits(&tmp); ++ } ++ ++ init_get_bits(&s->gb, s->frame_data, s->num_saved_bits); ++ skip_bits(&s->gb, s->frame_offset); ++} ++ ++/** ++ *@brief Decode a single WMA packet. ++ *@param avctx codec context ++ *@param data the output buffer ++ *@param data_size number of bytes that were written to the output buffer ++ *@param avpkt input packet ++ *@return number of bytes that were read from the input buffer ++ */ ++static int decode_packet(AVCodecContext *avctx, ++ void *data, int *data_size, AVPacket* avpkt) ++{ ++ WmallDecodeCtx *s = avctx->priv_data; ++ GetBitContext* gb = &s->pgb; ++ const uint8_t* buf = avpkt->data; ++ int buf_size = avpkt->size; ++ int num_bits_prev_frame; ++ int packet_sequence_number; ++ ++ if (s->bits_per_sample == 16) { ++ s->samples_16 = (int16_t *) data; ++ s->samples_16_end = (int16_t *) ((int8_t*)data + *data_size); ++ } else { ++ s->samples_32 = (void *) data; ++ s->samples_32_end = (void *) ((int8_t*)data + *data_size); ++ } ++ *data_size = 0; ++ ++ if (s->packet_done || s->packet_loss) { ++ int seekable_frame_in_packet, spliced_packet; ++ s->packet_done = 0; ++ ++ /** sanity check for the buffer length */ ++ if (buf_size < avctx->block_align) ++ return 0; ++ ++ s->next_packet_start = buf_size - avctx->block_align; ++ buf_size = avctx->block_align; ++ s->buf_bit_size = buf_size << 3; ++ ++ /** parse packet header */ ++ init_get_bits(gb, buf, s->buf_bit_size); ++ packet_sequence_number = get_bits(gb, 4); ++ seekable_frame_in_packet = get_bits1(gb); ++ spliced_packet = get_bits1(gb); ++ ++ /** get number of bits that need to be added to the previous frame */ ++ num_bits_prev_frame = get_bits(gb, s->log2_frame_size); ++ ++ /** check for packet loss */ ++ if (!s->packet_loss && ++ ((s->packet_sequence_number + 1) & 0xF) != packet_sequence_number) { ++ s->packet_loss = 1; ++ av_log(avctx, AV_LOG_ERROR, "Packet loss detected! seq %x vs %x\n", ++ s->packet_sequence_number, packet_sequence_number); ++ } ++ s->packet_sequence_number = packet_sequence_number; ++ ++ if (num_bits_prev_frame > 0) { ++ int remaining_packet_bits = s->buf_bit_size - get_bits_count(gb); ++ if (num_bits_prev_frame >= remaining_packet_bits) { ++ num_bits_prev_frame = remaining_packet_bits; ++ s->packet_done = 1; ++ } ++ ++ /** append the previous frame data to the remaining data from the ++ previous packet to create a full frame */ ++ save_bits(s, gb, num_bits_prev_frame, 1); ++ ++ /** decode the cross packet frame if it is valid */ ++ if (!s->packet_loss) ++ decode_frame(s); ++ } else if (s->num_saved_bits - s->frame_offset) { ++ dprintf(avctx, "ignoring %x previously saved bits\n", ++ s->num_saved_bits - s->frame_offset); ++ } ++ ++ if (s->packet_loss) { ++ /** reset number of saved bits so that the decoder ++ does not start to decode incomplete frames in the ++ s->len_prefix == 0 case */ ++ s->num_saved_bits = 0; ++ s->packet_loss = 0; ++ } ++ ++ } else { ++ int frame_size; ++ ++ s->buf_bit_size = (avpkt->size - s->next_packet_start) << 3; ++ init_get_bits(gb, avpkt->data, s->buf_bit_size); ++ skip_bits(gb, s->packet_offset); ++ ++ if (s->len_prefix && remaining_bits(s, gb) > s->log2_frame_size && ++ (frame_size = show_bits(gb, s->log2_frame_size)) && ++ frame_size <= remaining_bits(s, gb)) { ++ save_bits(s, gb, frame_size, 0); ++ s->packet_done = !decode_frame(s); ++ } else if (!s->len_prefix ++ && s->num_saved_bits > get_bits_count(&s->gb)) { ++ /** when the frames do not have a length prefix, we don't know ++ the compressed length of the individual frames ++ however, we know what part of a new packet belongs to the ++ previous frame ++ therefore we save the incoming packet first, then we append ++ the "previous frame" data from the next packet so that ++ we get a buffer that only contains full frames */ ++ s->packet_done = !decode_frame(s); ++ } else { ++ s->packet_done = 1; ++ } ++ } ++ ++ if (s->packet_done && !s->packet_loss && ++ remaining_bits(s, gb) > 0) { ++ /** save the rest of the data so that it can be decoded ++ with the next packet */ ++ save_bits(s, gb, remaining_bits(s, gb), 0); ++ } ++ ++ if (s->bits_per_sample == 16) ++ *data_size = (int8_t *)s->samples_16 - (int8_t *)data; ++ else ++ *data_size = (int8_t *)s->samples_32 - (int8_t *)data; ++ s->packet_offset = get_bits_count(gb) & 7; ++ ++ return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; ++} ++ ++/** ++ *@brief Clear decoder buffers (for seeking). ++ *@param avctx codec context ++ */ ++static void flush(AVCodecContext *avctx) ++{ ++ WmallDecodeCtx *s = avctx->priv_data; ++ int i; ++ /** reset output buffer as a part of it is used during the windowing of a ++ new frame */ ++ for (i = 0; i < s->num_channels; i++) ++ memset(s->channel[i].out, 0, s->samples_per_frame * ++ sizeof(*s->channel[i].out)); ++ s->packet_loss = 1; ++} ++ ++ ++/** ++ *@brief wmall decoder ++ */ ++AVCodec ff_wmalossless_decoder = { ++ "wmalossless", ++ AVMEDIA_TYPE_AUDIO, ++ CODEC_ID_WMALOSSLESS, ++ sizeof(WmallDecodeCtx), ++ decode_init, ++ NULL, ++ decode_end, ++ decode_packet, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_EXPERIMENTAL, ++ .flush= flush, ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Lossless"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmaprodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmaprodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmaprodec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmaprodec.c 2012-05-14 14:08:54.480342921 +0200 +@@ -86,12 +86,16 @@ + * subframe in order to reconstruct the output samples. + */ + ++#include "libavutil/intfloat.h" ++#include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "internal.h" + #include "get_bits.h" + #include "put_bits.h" + #include "wmaprodata.h" + #include "dsputil.h" ++#include "fmtconvert.h" ++#include "sinewin.h" + #include "wma.h" + + /** current decoder limitations */ +@@ -144,7 +148,7 @@ + uint8_t table_idx; ///< index in sf_offsets for the scale factor reference block + float* coeffs; ///< pointer to the subframe decode buffer + uint16_t num_vec_coeffs; ///< number of vector coded coefficients +- DECLARE_ALIGNED(16, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer ++ DECLARE_ALIGNED(32, float, out)[WMAPRO_BLOCK_MAX_SIZE + WMAPRO_BLOCK_MAX_SIZE / 2]; ///< output buffer + } WMAProChannelCtx; + + /** +@@ -164,12 +168,14 @@ + typedef struct WMAProDecodeCtx { + /* generic decoder variables */ + AVCodecContext* avctx; ///< codec context for av_log ++ AVFrame frame; ///< AVFrame for decoded output + DSPContext dsp; ///< accelerated DSP functions ++ FmtConvertContext fmt_conv; + uint8_t frame_data[MAX_FRAMESIZE + + FF_INPUT_BUFFER_PADDING_SIZE];///< compressed frame data + PutBitContext pb; ///< context for filling the frame_data buffer + FFTContext mdct_ctx[WMAPRO_BLOCK_SIZES]; ///< MDCT context per block size +- DECLARE_ALIGNED(16, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer ++ DECLARE_ALIGNED(32, float, tmp)[WMAPRO_BLOCK_MAX_SIZE]; ///< IMDCT output buffer + float* windows[WMAPRO_BLOCK_SIZES]; ///< windows for the different block sizes + + /* frame size dependent frame information (set during initialization) */ +@@ -205,8 +211,6 @@ + uint32_t frame_num; ///< current frame number (not used for decoding) + GetBitContext gb; ///< bitstream reader context + int buf_bit_size; ///< buffer size in bits +- float* samples; ///< current samplebuffer pointer +- float* samples_end; ///< maximum samplebuffer pointer + uint8_t drc_gain; ///< gain for the DRC tool + int8_t skip_frame; ///< skip output step + int8_t parsed_all_subframes; ///< all subframes decoded? +@@ -278,6 +282,7 @@ + + s->avctx = avctx; + dsputil_init(&s->dsp, avctx); ++ ff_fmt_convert_init(&s->fmt_conv, avctx); + init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); + + avctx->sample_fmt = AV_SAMPLE_FMT_FLT; +@@ -308,10 +313,6 @@ + s->samples_per_frame = 1 << ff_wma_get_frame_len_bits(avctx->sample_rate, + 3, s->decode_flags); + +- /** init previous block len */ +- for (i = 0; i < avctx->channels; i++) +- s->channel[i].prev_block_len = s->samples_per_frame; +- + /** subframe info */ + log2_max_num_subframes = ((s->decode_flags & 0x38) >> 3); + s->max_num_subframes = 1 << log2_max_num_subframes; +@@ -331,6 +332,18 @@ + + s->num_channels = avctx->channels; + ++ if (s->num_channels < 0) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels); ++ return AVERROR_INVALIDDATA; ++ } else if (s->num_channels > WMAPRO_MAX_CHANNELS) { ++ av_log_ask_for_sample(avctx, "unsupported number of channels\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ /** init previous block len */ ++ for (i = 0; i < s->num_channels; i++) ++ s->channel[i].prev_block_len = s->samples_per_frame; ++ + /** extract lfe channel position */ + s->lfe_channel = -1; + +@@ -342,14 +355,6 @@ + } + } + +- if (s->num_channels < 0) { +- av_log(avctx, AV_LOG_ERROR, "invalid number of channels %d\n", s->num_channels); +- return AVERROR_INVALIDDATA; +- } else if (s->num_channels > WMAPRO_MAX_CHANNELS) { +- av_log_ask_for_sample(avctx, "unsupported number of channels\n"); +- return AVERROR_PATCHWELCOME; +- } +- + INIT_VLC_STATIC(&sf_vlc, SCALEVLCBITS, HUFF_SCALE_SIZE, + scale_huffbits, 1, 1, + scale_huffcodes, 2, 2, 616); +@@ -448,6 +453,10 @@ + dump_context(s); + + avctx->channel_layout = channel_mask; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; ++ + return 0; + } + +@@ -766,7 +775,7 @@ + /* Integers 0..15 as single-precision floats. The table saves a + costly int to float conversion, and storing the values as + integers allows fast sign-flipping. */ +- static const int fval_tab[16] = { ++ static const uint32_t fval_tab[16] = { + 0x00000000, 0x3f800000, 0x40000000, 0x40400000, + 0x40800000, 0x40a00000, 0x40c00000, 0x40e00000, + 0x41000000, 0x41100000, 0x41200000, 0x41300000, +@@ -798,7 +807,7 @@ + 4 vector coded large values) */ + while ((s->transmit_num_vec_coeffs || !rl_mode) && + (cur_coeff + 3 < ci->num_vec_coeffs)) { +- int vals[4]; ++ uint32_t vals[4]; + int i; + unsigned int idx; + +@@ -808,15 +817,15 @@ + for (i = 0; i < 4; i += 2) { + idx = get_vlc2(&s->gb, vec2_vlc.table, VLCBITS, VEC2MAXDEPTH); + if (idx == HUFF_VEC2_SIZE - 1) { +- int v0, v1; ++ uint32_t v0, v1; + v0 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); + if (v0 == HUFF_VEC1_SIZE - 1) + v0 += ff_wma_get_large_val(&s->gb); + v1 = get_vlc2(&s->gb, vec1_vlc.table, VLCBITS, VEC1MAXDEPTH); + if (v1 == HUFF_VEC1_SIZE - 1) + v1 += ff_wma_get_large_val(&s->gb); +- ((float*)vals)[i ] = v0; +- ((float*)vals)[i+1] = v1; ++ vals[i ] = av_float2int(v0); ++ vals[i+1] = av_float2int(v1); + } else { + vals[i] = fval_tab[symbol_to_vec2[idx] >> 4 ]; + vals[i+1] = fval_tab[symbol_to_vec2[idx] & 0xF]; +@@ -832,8 +841,8 @@ + /** decode sign */ + for (i = 0; i < 4; i++) { + if (vals[i]) { +- int sign = get_bits1(&s->gb) - 1; +- *(uint32_t*)&ci->coeffs[cur_coeff] = vals[i] ^ sign<<31; ++ uint32_t sign = get_bits1(&s->gb) - 1; ++ AV_WN32A(&ci->coeffs[cur_coeff], vals[i] ^ sign << 31); + num_zeros = 0; + } else { + ci->coeffs[cur_coeff] = 0; +@@ -1222,6 +1231,7 @@ + get_bits_count(&s->gb) - s->subframe_offset); + + if (transmit_coeffs) { ++ FFTContext *mdct = &s->mdct_ctx[av_log2(subframe_len) - WMAPRO_BLOCK_MIN_BITS]; + /** reconstruct the per channel data */ + inverse_channel_transform(s); + for (i = 0; i < s->channels_for_cur_subframe; i++) { +@@ -1246,9 +1256,8 @@ + quant, end - start); + } + +- /** apply imdct (ff_imdct_half == DCTIV with reverse) */ +- ff_imdct_half(&s->mdct_ctx[av_log2(subframe_len) - WMAPRO_BLOCK_MIN_BITS], +- s->channel[c].coeffs, s->tmp); ++ /** apply imdct (imdct_half == DCTIV with reverse) */ ++ mdct->imdct_half(mdct, s->channel[c].coeffs, s->tmp); + } + } + +@@ -1274,21 +1283,15 @@ + *@return 0 if the trailer bit indicates that this is the last frame, + * 1 if there are additional frames + */ +-static int decode_frame(WMAProDecodeCtx *s) ++static int decode_frame(WMAProDecodeCtx *s, int *got_frame_ptr) + { ++ AVCodecContext *avctx = s->avctx; + GetBitContext* gb = &s->gb; + int more_frames = 0; + int len = 0; +- int i; +- +- /** check for potential output buffer overflow */ +- if (s->num_channels * s->samples_per_frame > s->samples_end - s->samples) { +- /** return an error if no frame could be decoded at all */ +- av_log(s->avctx, AV_LOG_ERROR, +- "not enough space for the output samples\n"); +- s->packet_loss = 1; +- return 0; +- } ++ int i, ret; ++ const float *out_ptr[WMAPRO_MAX_CHANNELS]; ++ float *samples; + + /** get frame length */ + if (s->len_prefix) +@@ -1319,7 +1322,7 @@ + /** no idea what these are for, might be the number of samples + that need to be skipped at the beginning or end of a stream */ + if (get_bits1(gb)) { +- int skip; ++ int av_unused skip; + + /** usually true for the first frame */ + if (get_bits1(gb)) { +@@ -1354,19 +1357,22 @@ + } + } + ++ /* get output buffer */ ++ s->frame.nb_samples = s->samples_per_frame; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ s->packet_loss = 1; ++ return 0; ++ } ++ samples = (float *)s->frame.data[0]; ++ + /** interleave samples and write them to the output buffer */ +- for (i = 0; i < s->num_channels; i++) { +- float* ptr = s->samples + i; +- int incr = s->num_channels; +- float* iptr = s->channel[i].out; +- float* iend = iptr + s->samples_per_frame; +- +- // FIXME should create/use a DSP function here +- while (iptr < iend) { +- *ptr = *iptr++; +- ptr += incr; +- } ++ for (i = 0; i < s->num_channels; i++) ++ out_ptr[i] = s->channel[i].out; ++ s->fmt_conv.float_interleave(samples, out_ptr, s->samples_per_frame, ++ s->num_channels); + ++ for (i = 0; i < s->num_channels; i++) { + /** reuse second half of the IMDCT output for the next frame */ + memcpy(&s->channel[i].out[0], + &s->channel[i].out[s->samples_per_frame], +@@ -1375,8 +1381,10 @@ + + if (s->skip_frame) { + s->skip_frame = 0; +- } else +- s->samples += s->num_channels * s->samples_per_frame; ++ *got_frame_ptr = 0; ++ } else { ++ *got_frame_ptr = 1; ++ } + + if (s->len_prefix) { + if (len != (get_bits_count(gb) - s->frame_offset) + 2) { +@@ -1418,7 +1426,7 @@ + *@param s codec context + *@param gb bitstream reader context + *@param len length of the partial frame +- *@param append decides wether to reset the buffer or not ++ *@param append decides whether to reset the buffer or not + */ + static void save_bits(WMAProDecodeCtx *s, GetBitContext* gb, int len, + int append) +@@ -1435,7 +1443,7 @@ + init_put_bits(&s->pb, s->frame_data, MAX_FRAMESIZE); + } + +- buflen = (s->num_saved_bits + len + 8) >> 3; ++ buflen = (put_bits_count(&s->pb) + len + 8) >> 3; + + if (len <= 0 || buflen > MAX_FRAMESIZE) { + av_log_ask_for_sample(s->avctx, "input buffer too small\n"); +@@ -1445,14 +1453,14 @@ + + s->num_saved_bits += len; + if (!append) { +- ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), ++ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), + s->num_saved_bits); + } else { + int align = 8 - (get_bits_count(gb) & 7); + align = FFMIN(align, len); + put_bits(&s->pb, align, get_bits(gb, align)); + len -= align; +- ff_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len); ++ avpriv_copy_bits(&s->pb, gb->buffer + (get_bits_count(gb) >> 3), len); + } + skip_bits_long(gb, len); + +@@ -1473,8 +1481,8 @@ + *@param avpkt input packet + *@return number of bytes that were read from the input buffer + */ +-static int decode_packet(AVCodecContext *avctx, +- void *data, int *data_size, AVPacket* avpkt) ++static int decode_packet(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket* avpkt) + { + WMAProDecodeCtx *s = avctx->priv_data; + GetBitContext* gb = &s->pgb; +@@ -1483,9 +1491,7 @@ + int num_bits_prev_frame; + int packet_sequence_number; + +- s->samples = data; +- s->samples_end = (float*)((int8_t*)data + *data_size); +- *data_size = 0; ++ *got_frame_ptr = 0; + + if (s->packet_done || s->packet_loss) { + s->packet_done = 0; +@@ -1532,7 +1538,7 @@ + + /** decode the cross packet frame if it is valid */ + if (!s->packet_loss) +- decode_frame(s); ++ decode_frame(s, got_frame_ptr); + } else if (s->num_saved_bits - s->frame_offset) { + av_dlog(avctx, "ignoring %x previously saved bits\n", + s->num_saved_bits - s->frame_offset); +@@ -1555,7 +1561,7 @@ + (frame_size = show_bits(gb, s->log2_frame_size)) && + frame_size <= remaining_bits(s, gb)) { + save_bits(s, gb, frame_size, 0); +- s->packet_done = !decode_frame(s); ++ s->packet_done = !decode_frame(s, got_frame_ptr); + } else if (!s->len_prefix + && s->num_saved_bits > get_bits_count(&s->gb)) { + /** when the frames do not have a length prefix, we don't know +@@ -1565,7 +1571,7 @@ + therefore we save the incoming packet first, then we append + the "previous frame" data from the next packet so that + we get a buffer that only contains full frames */ +- s->packet_done = !decode_frame(s); ++ s->packet_done = !decode_frame(s, got_frame_ptr); + } else + s->packet_done = 1; + } +@@ -1577,10 +1583,14 @@ + save_bits(s, gb, remaining_bits(s, gb), 0); + } + +- *data_size = (int8_t *)s->samples - (int8_t *)data; + s->packet_offset = get_bits_count(gb) & 7; ++ if (s->packet_loss) ++ return AVERROR_INVALIDDATA; ++ ++ if (*got_frame_ptr) ++ *(AVFrame *)data = s->frame; + +- return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; ++ return get_bits_count(gb) >> 3; + } + + /** +@@ -1604,15 +1614,14 @@ + *@brief wmapro decoder + */ + AVCodec ff_wmapro_decoder = { +- "wmapro", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAPRO, +- sizeof(WMAProDecodeCtx), +- decode_init, +- NULL, +- decode_end, +- decode_packet, +- .capabilities = CODEC_CAP_SUBFRAMES, ++ .name = "wmapro", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAPRO, ++ .priv_data_size = sizeof(WMAProDecodeCtx), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_packet, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, + .flush= flush, + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio 9 Professional"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmavoice.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmavoice.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmavoice.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmavoice.c 2012-05-14 14:08:54.483342981 +0200 +@@ -25,6 +25,8 @@ + * @author Ronald S. Bultje + */ + ++#define UNCHECKED_BITSTREAM_READER 1 ++ + #include + #include "avcodec.h" + #include "get_bits.h" +@@ -36,8 +38,9 @@ + #include "acelp_filters.h" + #include "lsp.h" + #include "libavutil/lzo.h" +-#include "avfft.h" +-#include "fft.h" ++#include "dct.h" ++#include "rdft.h" ++#include "sinewin.h" + + #define MAX_BLOCKS 8 ///< maximum number of blocks per frame + #define MAX_LSPS 16 ///< maximum filter order +@@ -127,11 +130,10 @@ + */ + typedef struct { + /** +- * @defgroup struct_global Global values +- * Global values, specified in the stream header / extradata or used +- * all over. ++ * @name Global values specified in the stream header / extradata or used all over. + * @{ + */ ++ AVFrame frame; + GetBitContext gb; ///< packet bitreader. During decoder init, + ///< it contains the extradata from the + ///< demuxer. During decoding, it contains +@@ -181,14 +183,15 @@ + + /** + * @} +- * @defgroup struct_packet Packet values +- * Packet values, specified in the packet header or related to a packet. ++ * ++ * @name Packet values specified in the packet header or related to a packet. ++ * + * A packet is considered to be a single unit of data provided to this + * decoder by the demuxer. + * @{ + */ + int spillover_nbits; ///< number of bits of the previous packet's +- ///< last superframe preceeding this ++ ///< last superframe preceding this + ///< packet's first full superframe (useful + ///< for re-synchronization also) + int has_residual_lsps; ///< if set, superframes contain one set of +@@ -212,7 +215,8 @@ + + /** + * @} +- * @defgroup struct_frame Frame and superframe values ++ * ++ * @name Frame and superframe values + * Superframe and frame data - these can change from frame to frame, + * although some of them do in that case serve as a cache / history for + * the next frame or superframe. +@@ -255,7 +259,9 @@ + float synth_history[MAX_LSPS]; ///< see #excitation_history + /** + * @} +- * @defgroup post_filter Postfilter values ++ * ++ * @name Postfilter values ++ * + * Variables used for postfilter implementation, mostly history for + * smoothing and so on, and context variables for FFT/iFFT. + * @{ +@@ -274,11 +280,11 @@ + ///< by postfilter + float denoise_filter_cache[MAX_FRAMESIZE]; + int denoise_filter_cache_size; ///< samples in #denoise_filter_cache +- DECLARE_ALIGNED(16, float, tilted_lpcs_pf)[0x80]; ++ DECLARE_ALIGNED(32, float, tilted_lpcs_pf)[0x80]; + ///< aligned buffer for LPC tilting +- DECLARE_ALIGNED(16, float, denoise_coeffs_pf)[0x80]; ++ DECLARE_ALIGNED(32, float, denoise_coeffs_pf)[0x80]; + ///< aligned buffer for denoise coefficients +- DECLARE_ALIGNED(16, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; ++ DECLARE_ALIGNED(32, float, synth_filter_out_buf)[0x80 + MAX_LSPS_ALIGN16]; + ///< aligned buffer for postfilter speech + ///< synthesis + /** +@@ -314,7 +320,7 @@ + }; + int cntr[8], n, res; + +- memset(vbm_tree, 0xff, sizeof(vbm_tree)); ++ memset(vbm_tree, 0xff, sizeof(vbm_tree[0]) * 25); + memset(cntr, 0, sizeof(cntr)); + for (n = 0; n < 17; n++) { + res = get_bits(gb, 3); +@@ -398,6 +404,10 @@ + s->min_pitch_val = ((ctx->sample_rate << 8) / 400 + 50) >> 8; + s->max_pitch_val = ((ctx->sample_rate << 8) * 37 / 2000 + 50) >> 8; + pitch_range = s->max_pitch_val - s->min_pitch_val; ++ if (pitch_range <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid pitch range; broken extradata?\n"); ++ return -1; ++ } + s->pitch_nbits = av_ceil_log2(pitch_range); + s->last_pitch_val = 40; + s->last_acb_type = ACB_TYPE_NONE; +@@ -419,6 +429,10 @@ + s->block_conv_table[2] = (pitch_range * 44) >> 6; + s->block_conv_table[3] = s->max_pitch_val - 1; + s->block_delta_pitch_hrange = (pitch_range >> 3) & ~0xF; ++ if (s->block_delta_pitch_hrange <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid delta pitch hrange; broken extradata?\n"); ++ return -1; ++ } + s->block_delta_pitch_nbits = 1 + av_ceil_log2(s->block_delta_pitch_hrange); + s->block_pitch_range = s->block_conv_table[2] + + s->block_conv_table[3] + 1 + +@@ -427,11 +441,14 @@ + + ctx->sample_fmt = AV_SAMPLE_FMT_FLT; + ++ avcodec_get_frame_defaults(&s->frame); ++ ctx->coded_frame = &s->frame; ++ + return 0; + } + + /** +- * @defgroup postfilter Postfilter functions ++ * @name Postfilter functions + * Postfilter functions (gain control, wiener denoise filter, DC filter, + * kalman smoothening, plus surrounding code to wrap it) + * @{ +@@ -558,7 +575,7 @@ + int n, idx; + + /* Create frequency power spectrum of speech input (i.e. RDFT of LPCs) */ +- ff_rdft_calc(&s->rdft, lpcs); ++ s->rdft.rdft_calc(&s->rdft, lpcs); + #define log_range(var, assign) do { \ + float tmp = log10f(assign); var = tmp; \ + max = FFMAX(max, tmp); min = FFMIN(min, tmp); \ +@@ -601,8 +618,8 @@ + * is a sinus input) by doing a phase shift (in theory, H(sin())=cos()). + * Hilbert_Transform(RDFT(x)) = Laplace_Transform(x), which calculates the + * "moment" of the LPCs in this filter. */ +- ff_dct_calc(&s->dct, lpcs); +- ff_dct_calc(&s->dst, lpcs); ++ s->dct.dct_calc(&s->dct, lpcs); ++ s->dst.dct_calc(&s->dst, lpcs); + + /* Split out the coefficient indexes into phase/magnitude pairs */ + idx = 255 + av_clip(lpcs[64], -255, 255); +@@ -623,7 +640,7 @@ + coeffs[1] = last_coeff; + + /* move into real domain */ +- ff_rdft_calc(&s->irdft, coeffs); ++ s->irdft.rdft_calc(&s->irdft, coeffs); + + /* tilt correction and normalize scale */ + memset(&coeffs[remainder], 0, sizeof(coeffs[0]) * (128 - remainder)); +@@ -693,8 +710,8 @@ + /* apply coefficients (in frequency spectrum domain), i.e. complex + * number multiplication */ + memset(&synth_pf[size], 0, sizeof(synth_pf[0]) * (128 - size)); +- ff_rdft_calc(&s->rdft, synth_pf); +- ff_rdft_calc(&s->rdft, coeffs); ++ s->rdft.rdft_calc(&s->rdft, synth_pf); ++ s->rdft.rdft_calc(&s->rdft, coeffs); + synth_pf[0] *= coeffs[0]; + synth_pf[1] *= coeffs[1]; + for (n = 1; n < 64; n++) { +@@ -702,7 +719,7 @@ + synth_pf[n * 2] = v1 * coeffs[n * 2] - v2 * coeffs[n * 2 + 1]; + synth_pf[n * 2 + 1] = v2 * coeffs[n * 2] + v1 * coeffs[n * 2 + 1]; + } +- ff_rdft_calc(&s->irdft, synth_pf); ++ s->irdft.rdft_calc(&s->irdft, synth_pf); + } + + /* merge filter output with the history of previous runs */ +@@ -824,7 +841,7 @@ + } + + /** +- * @defgroup lsp_dequant LSP dequantization routines ++ * @name LSP dequantization routines + * LSP dequantization routines, for 10/16LSPs and independent/residual coding. + * @note we assume enough bits are available, caller should check. + * lsp10i() consumes 24 bits; lsp10r() consumes an additional 24 bits; +@@ -968,7 +985,7 @@ + + /** + * @} +- * @defgroup aw Pitch-adaptive window coding functions ++ * @name Pitch-adaptive window coding functions + * The next few functions are for pitch-adaptive window coding. + * @{ + */ +@@ -1074,7 +1091,7 @@ + int excl_range = s->aw_pulse_range; // always 16 or 24 + uint16_t *use_mask_ptr = &use_mask[idx >> 4]; + int first_sh = 16 - (idx & 15); +- *use_mask_ptr++ &= 0xFFFF << first_sh; ++ *use_mask_ptr++ &= 0xFFFFu << first_sh; + excl_range -= first_sh; + if (excl_range >= 16) { + *use_mask_ptr++ = 0; +@@ -1714,8 +1731,7 @@ + * @return 0 on success, <0 on error or 1 if there was not enough data to + * fully parse the superframe + */ +-static int synth_superframe(AVCodecContext *ctx, +- float *samples, int *data_size) ++static int synth_superframe(AVCodecContext *ctx, int *got_frame_ptr) + { + WMAVoiceContext *s = ctx->priv_data; + GetBitContext *gb = &s->gb, s_gb; +@@ -1725,6 +1741,7 @@ + wmavoice_mean_lsf16[s->lsp_def_mode] : wmavoice_mean_lsf10[s->lsp_def_mode]; + float excitation[MAX_SIGNAL_HISTORY + MAX_SFRAMESIZE + 12]; + float synth[MAX_LSPS + MAX_SFRAMESIZE]; ++ float *samples; + + memcpy(synth, s->synth_history, + s->lsps * sizeof(*synth)); +@@ -1737,7 +1754,10 @@ + s->sframe_cache_size = 0; + } + +- if ((res = check_bits_for_superframe(gb, s)) == 1) return 1; ++ if ((res = check_bits_for_superframe(gb, s)) == 1) { ++ *got_frame_ptr = 0; ++ return 1; ++ } + + /* First bit is speech/music bit, it differentiates between WMAVoice + * speech samples (the actual codec) and WMAVoice music samples, which +@@ -1778,7 +1798,16 @@ + stabilize_lsps(lsps[n], s->lsps); + } + +- /* Parse frames, optionally preceeded by per-frame (independent) LSPs. */ ++ /* get output buffer */ ++ s->frame.nb_samples = 480; ++ if ((res = ctx->get_buffer(ctx, &s->frame)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return res; ++ } ++ s->frame.nb_samples = n_samples; ++ samples = (float *)s->frame.data[0]; ++ ++ /* Parse frames, optionally preceded by per-frame (independent) LSPs. */ + for (n = 0; n < 3; n++) { + if (!s->has_residual_lsps) { + int m; +@@ -1797,8 +1826,10 @@ + &samples[n * MAX_FRAMESIZE], + lsps[n], n == 0 ? s->prev_lsps : lsps[n - 1], + &excitation[s->history_nsamples + n * MAX_FRAMESIZE], +- &synth[s->lsps + n * MAX_FRAMESIZE]))) ++ &synth[s->lsps + n * MAX_FRAMESIZE]))) { ++ *got_frame_ptr = 0; + return res; ++ } + } + + /* Statistics? FIXME - we don't check for length, a slight overrun +@@ -1809,8 +1840,7 @@ + skip_bits(gb, 10 * (res + 1)); + } + +- /* Specify nr. of output samples */ +- *data_size = n_samples * sizeof(float); ++ *got_frame_ptr = 1; + + /* Update history */ + memcpy(s->prev_lsps, lsps[2], +@@ -1861,7 +1891,7 @@ + * @param size size of the source data, in bytes + * @param gb bit I/O context specifying the current position in the source. + * data. This function might use this to align the bit position to +- * a whole-byte boundary before calling #ff_copy_bits() on aligned ++ * a whole-byte boundary before calling #avpriv_copy_bits() on aligned + * source data + * @param nbits the amount of bits to copy from source to target + * +@@ -1877,10 +1907,12 @@ + rmn_bits = rmn_bytes = get_bits_left(gb); + if (rmn_bits < nbits) + return; ++ if (nbits > pb->size_in_bits - put_bits_count(pb)) ++ return; + rmn_bits &= 7; rmn_bytes >>= 3; + if ((rmn_bits = FFMIN(rmn_bits, nbits)) > 0) + put_bits(pb, rmn_bits, get_bits(gb, rmn_bits)); +- ff_copy_bits(pb, data + size - rmn_bytes, ++ avpriv_copy_bits(pb, data + size - rmn_bytes, + FFMIN(nbits - rmn_bits, rmn_bytes << 3)); + } + +@@ -1896,28 +1928,22 @@ + * For more information about frames, see #synth_superframe(). + */ + static int wmavoice_decode_packet(AVCodecContext *ctx, void *data, +- int *data_size, AVPacket *avpkt) ++ int *got_frame_ptr, AVPacket *avpkt) + { + WMAVoiceContext *s = ctx->priv_data; + GetBitContext *gb = &s->gb; + int size, res, pos; + +- if (*data_size < 480 * sizeof(float)) { +- av_log(ctx, AV_LOG_ERROR, +- "Output buffer too small (%d given - %zu needed)\n", +- *data_size, 480 * sizeof(float)); +- return -1; +- } +- *data_size = 0; +- + /* Packets are sometimes a multiple of ctx->block_align, with a packet + * header at each ctx->block_align bytes. However, FFmpeg's ASF demuxer + * feeds us ASF packets, which may concatenate multiple "codec" packets + * in a single "muxer" packet, so we artificially emulate that by + * capping the packet size at ctx->block_align. */ + for (size = avpkt->size; size > ctx->block_align; size -= ctx->block_align); +- if (!size) ++ if (!size) { ++ *got_frame_ptr = 0; + return 0; ++ } + init_get_bits(&s->gb, avpkt->data, size << 3); + + /* size == ctx->block_align is used to indicate whether we are dealing with +@@ -1936,10 +1962,11 @@ + copy_bits(&s->pb, avpkt->data, size, gb, s->spillover_nbits); + flush_put_bits(&s->pb); + s->sframe_cache_size += s->spillover_nbits; +- if ((res = synth_superframe(ctx, data, data_size)) == 0 && +- *data_size > 0) { ++ if ((res = synth_superframe(ctx, got_frame_ptr)) == 0 && ++ *got_frame_ptr) { + cnt += s->spillover_nbits; + s->skip_bits_next = cnt & 7; ++ *(AVFrame *)data = s->frame; + return cnt >> 3; + } else + skip_bits_long (gb, s->spillover_nbits - cnt + +@@ -1954,11 +1981,12 @@ + s->sframe_cache_size = 0; + s->skip_bits_next = 0; + pos = get_bits_left(gb); +- if ((res = synth_superframe(ctx, data, data_size)) < 0) { ++ if ((res = synth_superframe(ctx, got_frame_ptr)) < 0) { + return res; +- } else if (*data_size > 0) { ++ } else if (*got_frame_ptr) { + int cnt = get_bits_count(gb); + s->skip_bits_next = cnt & 7; ++ *(AVFrame *)data = s->frame; + return cnt >> 3; + } else if ((s->sframe_cache_size = pos) > 0) { + /* rewind bit reader to start of last (incomplete) superframe... */ +@@ -2019,15 +2047,14 @@ + } + + AVCodec ff_wmavoice_decoder = { +- "wmavoice", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WMAVOICE, +- sizeof(WMAVoiceContext), +- wmavoice_decode_init, +- NULL, +- wmavoice_decode_end, +- wmavoice_decode_packet, +- CODEC_CAP_SUBFRAMES, ++ .name = "wmavoice", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WMAVOICE, ++ .priv_data_size = sizeof(WMAVoiceContext), ++ .init = wmavoice_decode_init, ++ .close = wmavoice_decode_end, ++ .decode = wmavoice_decode_packet, ++ .capabilities = CODEC_CAP_SUBFRAMES | CODEC_CAP_DR1, + .flush = wmavoice_flush, + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Audio Voice"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmv2dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmv2dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmv2dec.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmv2dec.c 2012-05-14 14:08:54.486343041 +0200 +@@ -32,7 +32,7 @@ + static void parse_mb_skip(Wmv2Context * w){ + int mb_x, mb_y; + MpegEncContext * const s= &w->s; +- uint32_t * const mb_type= s->current_picture_ptr->mb_type; ++ uint32_t * const mb_type = s->current_picture_ptr->f.mb_type; + + w->skip_type= get_bits(&s->gb, 2); + switch(w->skip_type){ +@@ -116,21 +116,11 @@ + Wmv2Context * const w= (Wmv2Context*)s; + int code; + +-#if 0 +-{ +-int i; +-for(i=0; igb.size*8; i++) +- printf("%d", get_bits1(&s->gb)); +-// get_bits1(&s->gb); +-printf("END\n"); +-return -1; +-} +-#endif + if(s->picture_number==0) + decode_ext_header(w); + + s->pict_type = get_bits1(&s->gb) + 1; +- if(s->pict_type == FF_I_TYPE){ ++ if(s->pict_type == AV_PICTURE_TYPE_I){ + code = get_bits(&s->gb, 7); + av_log(s->avctx, AV_LOG_DEBUG, "I7:%X/\n", code); + } +@@ -145,7 +135,7 @@ + { + Wmv2Context * const w= (Wmv2Context*)s; + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + if(w->j_type_bit) w->j_type= get_bits1(&s->gb); + else w->j_type= 0; //FIXME check + +@@ -267,11 +257,11 @@ + wrap = s->b8_stride; + xy = s->block_index[0]; + +- mot_val = s->current_picture.motion_val[0][xy]; ++ mot_val = s->current_picture.f.motion_val[0][xy]; + +- A = s->current_picture.motion_val[0][xy - 1]; +- B = s->current_picture.motion_val[0][xy - wrap]; +- C = s->current_picture.motion_val[0][xy + 2 - wrap]; ++ A = s->current_picture.f.motion_val[0][xy - 1]; ++ B = s->current_picture.f.motion_val[0][xy - wrap]; ++ C = s->current_picture.f.motion_val[0][xy + 2 - wrap]; + + if(s->mb_x && !s->first_slice_line && !s->mspel && w->top_left_mv_flag) + diff= FFMAX(FFABS(A[0] - B[0]), FFABS(A[1] - B[1])); +@@ -316,10 +306,6 @@ + + if(w->per_block_abt) + w->abt_type= decode012(&s->gb); +-#if 0 +- if(w->per_block_abt) +- printf("B%d", w->abt_type); +-#endif + w->abt_type_table[n]= w->abt_type; + + if(w->abt_type){ +@@ -356,8 +342,8 @@ + + if(w->j_type) return 0; + +- if (s->pict_type == FF_P_TYPE) { +- if(IS_SKIP(s->current_picture.mb_type[s->mb_y * s->mb_stride + s->mb_x])){ ++ if (s->pict_type == AV_PICTURE_TYPE_P) { ++ if (IS_SKIP(s->current_picture.f.mb_type[s->mb_y * s->mb_stride + s->mb_x])) { + /* skip mb */ + s->mb_intra = 0; + for(i=0;i<6;i++) +@@ -433,7 +419,7 @@ + } + } + } else { +-//if(s->pict_type==FF_P_TYPE) ++//if(s->pict_type==AV_PICTURE_TYPE_P) + // printf("%d%d ", s->inter_intra_pred, cbp); + //printf("I at %d %d %d %06X\n", s->mb_x, s->mb_y, ((cbp&3)? 1 : 0) +((cbp&0x3C)? 2 : 0), show_bits(&s->gb, 24)); + s->ac_pred = get_bits1(&s->gb); +@@ -485,16 +471,14 @@ + } + + AVCodec ff_wmv2_decoder = { +- "wmv2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV2, +- sizeof(Wmv2Context), +- wmv2_decode_init, +- NULL, +- wmv2_decode_end, +- ff_h263_decode_frame, +- CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, +- .max_lowres = 3, ++ .name = "wmv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV2, ++ .priv_data_size = sizeof(Wmv2Context), ++ .init = wmv2_decode_init, ++ .close = wmv2_decode_end, ++ .decode = ff_h263_decode_frame, ++ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Windows Media Video 8"), + .pix_fmts= ff_pixfmt_list_420, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmv2enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmv2enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wmv2enc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wmv2enc.c 2012-05-14 14:08:54.489343101 +0200 +@@ -72,7 +72,7 @@ + Wmv2Context * const w= (Wmv2Context*)s; + + put_bits(&s->pb, 1, s->pict_type - 1); +- if(s->pict_type == FF_I_TYPE){ ++ if(s->pict_type == AV_PICTURE_TYPE_I){ + put_bits(&s->pb, 7, 0); + } + put_bits(&s->pb, 5, s->qscale); +@@ -87,7 +87,7 @@ + + assert(s->flipflop_rounding); + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + assert(s->no_rounding==1); + if(w->j_type_bit) put_bits(&s->pb, 1, w->j_type); + +@@ -191,7 +191,7 @@ + coded_cbp |= val << (5 - i); + } + +- if (s->pict_type == FF_I_TYPE) { ++ if (s->pict_type == AV_PICTURE_TYPE_I) { + put_bits(&s->pb, + ff_msmp4_mb_i_table[coded_cbp][1], ff_msmp4_mb_i_table[coded_cbp][0]); + } else { +@@ -212,13 +212,13 @@ + } + + AVCodec ff_wmv2_encoder = { +- "wmv2", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WMV2, +- sizeof(Wmv2Context), +- wmv2_encode_init, +- MPV_encode_picture, +- MPV_encode_end, ++ .name = "wmv2", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV2, ++ .priv_data_size = sizeof(Wmv2Context), ++ .init = wmv2_encode_init, ++ .encode = MPV_encode_picture, ++ .close = MPV_encode_end, + .pix_fmts= (const enum PixelFormat[]){PIX_FMT_YUV420P, PIX_FMT_NONE}, + .long_name= NULL_IF_CONFIG_SMALL("Windows Media Video 8"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wnv1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wnv1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/wnv1.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/wnv1.c 2012-05-14 14:08:54.490343121 +0200 +@@ -96,11 +96,13 @@ + else { + l->shift = 8 - (buf[2] >> 4); + if (l->shift > 4) { +- av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4); ++ av_log_ask_for_sample(avctx, "Unknown WNV1 frame header value %i\n", ++ buf[2] >> 4); + l->shift = 4; + } + if (l->shift < 1) { +- av_log(avctx, AV_LOG_ERROR, "Unknown WNV1 frame header value %i, please upload file for study\n", buf[2] >> 4); ++ av_log_ask_for_sample(avctx, "Unknown WNV1 frame header value %i\n", ++ buf[2] >> 4); + l->shift = 1; + } + } +@@ -134,6 +136,7 @@ + + l->avctx = avctx; + avctx->pix_fmt = PIX_FMT_YUV422P; ++ avcodec_get_frame_defaults(&l->pic); + + code_vlc.table = code_table; + code_vlc.table_allocated = 1 << CODE_VLC_BITS; +@@ -155,14 +158,13 @@ + } + + AVCodec ff_wnv1_decoder = { +- "wnv1", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_WNV1, +- sizeof(WNV1Context), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "wnv1", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WNV1, ++ .priv_data_size = sizeof(WNV1Context), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Winnov WNV1"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ws-snd1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ws-snd1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/ws-snd1.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/ws-snd1.c 2012-05-14 14:08:54.491343141 +0200 +@@ -25,98 +25,133 @@ + + /** + * @file +- * Westwood SNDx codecs. ++ * Westwood SNDx codecs + * + * Reference documents about VQA format and its audio codecs + * can be found here: + * http://www.multimedia.cx + */ + +-static const int8_t ws_adpcm_2bit[] = { -2, -1, 0, 1}; + static const int8_t ws_adpcm_4bit[] = { + -9, -8, -6, -5, -4, -3, -2, -1, +- 0, 1, 2, 3, 4, 5, 6, 8 }; ++ 0, 1, 2, 3, 4, 5, 6, 8 ++}; + +-#define CLIP8(a) if(a>127)a=127;if(a<-128)a=-128; ++typedef struct WSSndContext { ++ AVFrame frame; ++} WSSndContext; + +-static av_cold int ws_snd_decode_init(AVCodecContext * avctx) ++static av_cold int ws_snd_decode_init(AVCodecContext *avctx) + { +-// WSSNDContext *c = avctx->priv_data; ++ WSSndContext *s = avctx->priv_data; ++ ++ if (avctx->channels != 1) { ++ av_log_ask_for_sample(avctx, "unsupported number of channels\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ avctx->sample_fmt = AV_SAMPLE_FMT_U8; ++ ++ avcodec_get_frame_defaults(&s->frame); ++ avctx->coded_frame = &s->frame; + +- avctx->sample_fmt = AV_SAMPLE_FMT_S16; + return 0; + } + +-static int ws_snd_decode_frame(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) ++static int ws_snd_decode_frame(AVCodecContext *avctx, void *data, ++ int *got_frame_ptr, AVPacket *avpkt) + { ++ WSSndContext *s = avctx->priv_data; + const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +-// WSSNDContext *c = avctx->priv_data; ++ int buf_size = avpkt->size; + +- int in_size, out_size; +- int sample = 0; +- int i; +- short *samples = data; ++ int in_size, out_size, ret; ++ int sample = 128; ++ uint8_t *samples; ++ uint8_t *samples_end; + + if (!buf_size) + return 0; + ++ if (buf_size < 4) { ++ av_log(avctx, AV_LOG_ERROR, "packet is too small\n"); ++ return AVERROR(EINVAL); ++ } ++ + out_size = AV_RL16(&buf[0]); +- *data_size = out_size * 2; +- in_size = AV_RL16(&buf[2]); ++ in_size = AV_RL16(&buf[2]); + buf += 4; + +- if (out_size > *data_size) { +- av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n"); +- return -1; +- } + if (in_size > buf_size) { + av_log(avctx, AV_LOG_ERROR, "Frame data is larger than input buffer\n"); + return -1; + } ++ ++ /* get output buffer */ ++ s->frame.nb_samples = out_size; ++ if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ samples = s->frame.data[0]; ++ samples_end = samples + out_size; ++ + if (in_size == out_size) { +- for (i = 0; i < out_size; i++) +- *samples++ = (*buf++ - 0x80) << 8; ++ memcpy(samples, buf, out_size); ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; + return buf_size; + } + +- while (out_size > 0) { +- int code; ++ while (samples < samples_end && buf - avpkt->data < buf_size) { ++ int code, smp, size; + uint8_t count; +- code = (*buf) >> 6; +- count = (*buf) & 0x3F; ++ code = *buf >> 6; ++ count = *buf & 0x3F; + buf++; +- switch(code) { ++ ++ /* make sure we don't write past the output buffer */ ++ switch (code) { ++ case 0: smp = 4*(count+1); break; ++ case 1: smp = 2*(count+1); break; ++ case 2: smp = (count & 0x20) ? 1 : count + 1; break; ++ default: smp = count + 1; break; ++ } ++ if (samples_end - samples < smp) ++ break; ++ ++ /* make sure we don't read past the input buffer */ ++ size = ((code == 2 && (count & 0x20)) || code == 3) ? 0 : count + 1; ++ if ((buf - avpkt->data) + size > buf_size) ++ break; ++ ++ switch (code) { + case 0: /* ADPCM 2-bit */ + for (count++; count > 0; count--) { + code = *buf++; +- sample += ws_adpcm_2bit[code & 0x3]; +- CLIP8(sample); +- *samples++ = sample << 8; +- sample += ws_adpcm_2bit[(code >> 2) & 0x3]; +- CLIP8(sample); +- *samples++ = sample << 8; +- sample += ws_adpcm_2bit[(code >> 4) & 0x3]; +- CLIP8(sample); +- *samples++ = sample << 8; +- sample += ws_adpcm_2bit[(code >> 6) & 0x3]; +- CLIP8(sample); +- *samples++ = sample << 8; +- out_size -= 4; ++ sample += ( code & 0x3) - 2; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; ++ sample += ((code >> 2) & 0x3) - 2; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; ++ sample += ((code >> 4) & 0x3) - 2; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; ++ sample += (code >> 6) - 2; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; + } + break; + case 1: /* ADPCM 4-bit */ + for (count++; count > 0; count--) { + code = *buf++; + sample += ws_adpcm_4bit[code & 0xF]; +- CLIP8(sample); +- *samples++ = sample << 8; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; + sample += ws_adpcm_4bit[code >> 4]; +- CLIP8(sample); +- *samples++ = sample << 8; +- out_size -= 2; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; + } + break; + case 2: /* no compression */ +@@ -125,35 +160,35 @@ + t = count; + t <<= 3; + sample += t >> 3; +- *samples++ = sample << 8; +- out_size--; ++ sample = av_clip_uint8(sample); ++ *samples++ = sample; + } else { /* copy */ +- for (count++; count > 0; count--) { +- *samples++ = (*buf++ - 0x80) << 8; +- out_size--; +- } +- sample = buf[-1] - 0x80; ++ memcpy(samples, buf, smp); ++ samples += smp; ++ buf += smp; ++ sample = buf[-1]; + } + break; + default: /* run */ +- for(count++; count > 0; count--) { +- *samples++ = sample << 8; +- out_size--; +- } ++ memset(samples, sample, smp); ++ samples += smp; + } + } + ++ s->frame.nb_samples = samples - s->frame.data[0]; ++ *got_frame_ptr = 1; ++ *(AVFrame *)data = s->frame; ++ + return buf_size; + } + + AVCodec ff_ws_snd1_decoder = { +- "ws_snd1", +- AVMEDIA_TYPE_AUDIO, +- CODEC_ID_WESTWOOD_SND1, +- 0, +- ws_snd_decode_init, +- NULL, +- NULL, +- ws_snd_decode_frame, ++ .name = "ws_snd1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .id = CODEC_ID_WESTWOOD_SND1, ++ .priv_data_size = sizeof(WSSndContext), ++ .init = ws_snd_decode_init, ++ .decode = ws_snd_decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Westwood Audio (SND1)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/ac3dsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/ac3dsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/ac3dsp.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/ac3dsp.asm 2012-05-14 14:08:54.493343181 +0200 +@@ -0,0 +1,445 @@ ++;***************************************************************************** ++;* x86-optimized AC-3 DSP utils ++;* Copyright (c) 2011 Justin Ruggles ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++; 16777216.0f - used in ff_float_to_fixed24() ++pf_1_24: times 4 dd 0x4B800000 ++ ++; used in ff_ac3_compute_mantissa_size() ++cextern ac3_bap_bits ++pw_bap_mul1: dw 21846, 21846, 0, 32768, 21846, 21846, 0, 32768 ++pw_bap_mul2: dw 5, 7, 0, 7, 5, 7, 0, 7 ++ ++; used in ff_ac3_extract_exponents() ++pd_1: times 4 dd 1 ++pd_151: times 4 dd 151 ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; void ff_ac3_exponent_min(uint8_t *exp, int num_reuse_blocks, int nb_coefs) ++;----------------------------------------------------------------------------- ++ ++%macro AC3_EXPONENT_MIN 1 ++cglobal ac3_exponent_min_%1, 3,4,2, exp, reuse_blks, expn, offset ++ shl reuse_blksq, 8 ++ jz .end ++ LOOP_ALIGN ++.nextexp: ++ mov offsetq, reuse_blksq ++ mova m0, [expq+offsetq] ++ sub offsetq, 256 ++ LOOP_ALIGN ++.nextblk: ++ PMINUB m0, [expq+offsetq], m1 ++ sub offsetq, 256 ++ jae .nextblk ++ mova [expq], m0 ++ add expq, mmsize ++ sub expnq, mmsize ++ jg .nextexp ++.end: ++ REP_RET ++%endmacro ++ ++%define PMINUB PMINUB_MMX ++%define LOOP_ALIGN ++INIT_MMX ++AC3_EXPONENT_MIN mmx ++%ifdef HAVE_MMX2 ++%define PMINUB PMINUB_MMXEXT ++%define LOOP_ALIGN ALIGN 16 ++AC3_EXPONENT_MIN mmxext ++%endif ++%ifdef HAVE_SSE ++INIT_XMM ++AC3_EXPONENT_MIN sse2 ++%endif ++%undef PMINUB ++%undef LOOP_ALIGN ++ ++;----------------------------------------------------------------------------- ++; int ff_ac3_max_msb_abs_int16(const int16_t *src, int len) ++; ++; This function uses 2 different methods to calculate a valid result. ++; 1) logical 'or' of abs of each element ++; This is used for ssse3 because of the pabsw instruction. ++; It is also used for mmx because of the lack of min/max instructions. ++; 2) calculate min/max for the array, then or(abs(min),abs(max)) ++; This is used for mmxext and sse2 because they have pminsw/pmaxsw. ++;----------------------------------------------------------------------------- ++ ++%macro AC3_MAX_MSB_ABS_INT16 2 ++cglobal ac3_max_msb_abs_int16_%1, 2,2,5, src, len ++ pxor m2, m2 ++ pxor m3, m3 ++.loop: ++%ifidn %2, min_max ++ mova m0, [srcq] ++ mova m1, [srcq+mmsize] ++ pminsw m2, m0 ++ pminsw m2, m1 ++ pmaxsw m3, m0 ++ pmaxsw m3, m1 ++%else ; or_abs ++%ifidn %1, mmx ++ mova m0, [srcq] ++ mova m1, [srcq+mmsize] ++ ABS2 m0, m1, m3, m4 ++%else ; ssse3 ++ ; using memory args is faster for ssse3 ++ pabsw m0, [srcq] ++ pabsw m1, [srcq+mmsize] ++%endif ++ por m2, m0 ++ por m2, m1 ++%endif ++ add srcq, mmsize*2 ++ sub lend, mmsize ++ ja .loop ++%ifidn %2, min_max ++ ABS2 m2, m3, m0, m1 ++ por m2, m3 ++%endif ++%ifidn mmsize, 16 ++ movhlps m0, m2 ++ por m2, m0 ++%endif ++ PSHUFLW m0, m2, 0xe ++ por m2, m0 ++ PSHUFLW m0, m2, 0x1 ++ por m2, m0 ++ movd eax, m2 ++ and eax, 0xFFFF ++ RET ++%endmacro ++ ++INIT_MMX ++%define ABS2 ABS2_MMX ++%define PSHUFLW pshufw ++AC3_MAX_MSB_ABS_INT16 mmx, or_abs ++%define ABS2 ABS2_MMX2 ++AC3_MAX_MSB_ABS_INT16 mmxext, min_max ++INIT_XMM ++%define PSHUFLW pshuflw ++AC3_MAX_MSB_ABS_INT16 sse2, min_max ++%define ABS2 ABS2_SSSE3 ++AC3_MAX_MSB_ABS_INT16 ssse3, or_abs ++ ++;----------------------------------------------------------------------------- ++; macro used for ff_ac3_lshift_int16() and ff_ac3_rshift_int32() ++;----------------------------------------------------------------------------- ++ ++%macro AC3_SHIFT 4 ; l/r, 16/32, shift instruction, instruction set ++cglobal ac3_%1shift_int%2_%4, 3,3,5, src, len, shift ++ movd m0, shiftd ++.loop: ++ mova m1, [srcq ] ++ mova m2, [srcq+mmsize ] ++ mova m3, [srcq+mmsize*2] ++ mova m4, [srcq+mmsize*3] ++ %3 m1, m0 ++ %3 m2, m0 ++ %3 m3, m0 ++ %3 m4, m0 ++ mova [srcq ], m1 ++ mova [srcq+mmsize ], m2 ++ mova [srcq+mmsize*2], m3 ++ mova [srcq+mmsize*3], m4 ++ add srcq, mmsize*4 ++ sub lend, mmsize*32/%2 ++ ja .loop ++.end: ++ REP_RET ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void ff_ac3_lshift_int16(int16_t *src, unsigned int len, unsigned int shift) ++;----------------------------------------------------------------------------- ++ ++INIT_MMX ++AC3_SHIFT l, 16, psllw, mmx ++INIT_XMM ++AC3_SHIFT l, 16, psllw, sse2 ++ ++;----------------------------------------------------------------------------- ++; void ff_ac3_rshift_int32(int32_t *src, unsigned int len, unsigned int shift) ++;----------------------------------------------------------------------------- ++ ++INIT_MMX ++AC3_SHIFT r, 32, psrad, mmx ++INIT_XMM ++AC3_SHIFT r, 32, psrad, sse2 ++ ++;----------------------------------------------------------------------------- ++; void ff_float_to_fixed24(int32_t *dst, const float *src, unsigned int len) ++;----------------------------------------------------------------------------- ++ ++; The 3DNow! version is not bit-identical because pf2id uses truncation rather ++; than round-to-nearest. ++INIT_MMX ++cglobal float_to_fixed24_3dnow, 3,3,0, dst, src, len ++ movq m0, [pf_1_24] ++.loop: ++ movq m1, [srcq ] ++ movq m2, [srcq+8 ] ++ movq m3, [srcq+16] ++ movq m4, [srcq+24] ++ pfmul m1, m0 ++ pfmul m2, m0 ++ pfmul m3, m0 ++ pfmul m4, m0 ++ pf2id m1, m1 ++ pf2id m2, m2 ++ pf2id m3, m3 ++ pf2id m4, m4 ++ movq [dstq ], m1 ++ movq [dstq+8 ], m2 ++ movq [dstq+16], m3 ++ movq [dstq+24], m4 ++ add srcq, 32 ++ add dstq, 32 ++ sub lend, 8 ++ ja .loop ++ REP_RET ++ ++INIT_XMM ++cglobal float_to_fixed24_sse, 3,3,3, dst, src, len ++ movaps m0, [pf_1_24] ++.loop: ++ movaps m1, [srcq ] ++ movaps m2, [srcq+16] ++ mulps m1, m0 ++ mulps m2, m0 ++ cvtps2pi mm0, m1 ++ movhlps m1, m1 ++ cvtps2pi mm1, m1 ++ cvtps2pi mm2, m2 ++ movhlps m2, m2 ++ cvtps2pi mm3, m2 ++ movq [dstq ], mm0 ++ movq [dstq+ 8], mm1 ++ movq [dstq+16], mm2 ++ movq [dstq+24], mm3 ++ add srcq, 32 ++ add dstq, 32 ++ sub lend, 8 ++ ja .loop ++ REP_RET ++ ++INIT_XMM ++cglobal float_to_fixed24_sse2, 3,3,9, dst, src, len ++ movaps m0, [pf_1_24] ++.loop: ++ movaps m1, [srcq ] ++ movaps m2, [srcq+16 ] ++ movaps m3, [srcq+32 ] ++ movaps m4, [srcq+48 ] ++%ifdef m8 ++ movaps m5, [srcq+64 ] ++ movaps m6, [srcq+80 ] ++ movaps m7, [srcq+96 ] ++ movaps m8, [srcq+112] ++%endif ++ mulps m1, m0 ++ mulps m2, m0 ++ mulps m3, m0 ++ mulps m4, m0 ++%ifdef m8 ++ mulps m5, m0 ++ mulps m6, m0 ++ mulps m7, m0 ++ mulps m8, m0 ++%endif ++ cvtps2dq m1, m1 ++ cvtps2dq m2, m2 ++ cvtps2dq m3, m3 ++ cvtps2dq m4, m4 ++%ifdef m8 ++ cvtps2dq m5, m5 ++ cvtps2dq m6, m6 ++ cvtps2dq m7, m7 ++ cvtps2dq m8, m8 ++%endif ++ movdqa [dstq ], m1 ++ movdqa [dstq+16 ], m2 ++ movdqa [dstq+32 ], m3 ++ movdqa [dstq+48 ], m4 ++%ifdef m8 ++ movdqa [dstq+64 ], m5 ++ movdqa [dstq+80 ], m6 ++ movdqa [dstq+96 ], m7 ++ movdqa [dstq+112], m8 ++ add srcq, 128 ++ add dstq, 128 ++ sub lenq, 32 ++%else ++ add srcq, 64 ++ add dstq, 64 ++ sub lenq, 16 ++%endif ++ ja .loop ++ REP_RET ++ ++;------------------------------------------------------------------------------ ++; int ff_ac3_compute_mantissa_size(uint16_t mant_cnt[6][16]) ++;------------------------------------------------------------------------------ ++ ++%macro PHADDD4 2 ; xmm src, xmm tmp ++ movhlps %2, %1 ++ paddd %1, %2 ++ pshufd %2, %1, 0x1 ++ paddd %1, %2 ++%endmacro ++ ++INIT_XMM ++cglobal ac3_compute_mantissa_size_sse2, 1,2,4, mant_cnt, sum ++ movdqa m0, [mant_cntq ] ++ movdqa m1, [mant_cntq+ 1*16] ++ paddw m0, [mant_cntq+ 2*16] ++ paddw m1, [mant_cntq+ 3*16] ++ paddw m0, [mant_cntq+ 4*16] ++ paddw m1, [mant_cntq+ 5*16] ++ paddw m0, [mant_cntq+ 6*16] ++ paddw m1, [mant_cntq+ 7*16] ++ paddw m0, [mant_cntq+ 8*16] ++ paddw m1, [mant_cntq+ 9*16] ++ paddw m0, [mant_cntq+10*16] ++ paddw m1, [mant_cntq+11*16] ++ pmaddwd m0, [ac3_bap_bits ] ++ pmaddwd m1, [ac3_bap_bits+16] ++ paddd m0, m1 ++ PHADDD4 m0, m1 ++ movd sumd, m0 ++ movdqa m3, [pw_bap_mul1] ++ movhpd m0, [mant_cntq +2] ++ movlpd m0, [mant_cntq+1*32+2] ++ movhpd m1, [mant_cntq+2*32+2] ++ movlpd m1, [mant_cntq+3*32+2] ++ movhpd m2, [mant_cntq+4*32+2] ++ movlpd m2, [mant_cntq+5*32+2] ++ pmulhuw m0, m3 ++ pmulhuw m1, m3 ++ pmulhuw m2, m3 ++ paddusw m0, m1 ++ paddusw m0, m2 ++ pmaddwd m0, [pw_bap_mul2] ++ PHADDD4 m0, m1 ++ movd eax, m0 ++ add eax, sumd ++ RET ++ ++;------------------------------------------------------------------------------ ++; void ff_ac3_extract_exponents(uint8_t *exp, int32_t *coef, int nb_coefs) ++;------------------------------------------------------------------------------ ++ ++%macro PABSD_MMX 2 ; src/dst, tmp ++ pxor %2, %2 ++ pcmpgtd %2, %1 ++ pxor %1, %2 ++ psubd %1, %2 ++%endmacro ++ ++%macro PABSD_SSSE3 1-2 ; src/dst, unused ++ pabsd %1, %1 ++%endmacro ++ ++%ifdef HAVE_AMD3DNOW ++INIT_MMX ++cglobal ac3_extract_exponents_3dnow, 3,3,0, exp, coef, len ++ add expq, lenq ++ lea coefq, [coefq+4*lenq] ++ neg lenq ++ movq m3, [pd_1] ++ movq m4, [pd_151] ++.loop: ++ movq m0, [coefq+4*lenq ] ++ movq m1, [coefq+4*lenq+8] ++ PABSD_MMX m0, m2 ++ PABSD_MMX m1, m2 ++ pslld m0, 1 ++ por m0, m3 ++ pi2fd m2, m0 ++ psrld m2, 23 ++ movq m0, m4 ++ psubd m0, m2 ++ pslld m1, 1 ++ por m1, m3 ++ pi2fd m2, m1 ++ psrld m2, 23 ++ movq m1, m4 ++ psubd m1, m2 ++ packssdw m0, m0 ++ packuswb m0, m0 ++ packssdw m1, m1 ++ packuswb m1, m1 ++ punpcklwd m0, m1 ++ movd [expq+lenq], m0 ++ add lenq, 4 ++ jl .loop ++ REP_RET ++%endif ++ ++%macro AC3_EXTRACT_EXPONENTS 1 ++cglobal ac3_extract_exponents_%1, 3,3,4, exp, coef, len ++ add expq, lenq ++ lea coefq, [coefq+4*lenq] ++ neg lenq ++ mova m2, [pd_1] ++ mova m3, [pd_151] ++.loop: ++ ; move 4 32-bit coefs to xmm0 ++ mova m0, [coefq+4*lenq] ++ ; absolute value ++ PABSD m0, m1 ++ ; convert to float and extract exponents ++ pslld m0, 1 ++ por m0, m2 ++ cvtdq2ps m1, m0 ++ psrld m1, 23 ++ mova m0, m3 ++ psubd m0, m1 ++ ; move the lowest byte in each of 4 dwords to the low dword ++ ; NOTE: We cannot just extract the low bytes with pshufb because the dword ++ ; result for 16777215 is -1 due to float inaccuracy. Using packuswb ++ ; clips this to 0, which is the correct exponent. ++ packssdw m0, m0 ++ packuswb m0, m0 ++ movd [expq+lenq], m0 ++ ++ add lenq, 4 ++ jl .loop ++ REP_RET ++%endmacro ++ ++%ifdef HAVE_SSE ++INIT_XMM ++%define PABSD PABSD_MMX ++AC3_EXTRACT_EXPONENTS sse2 ++%ifdef HAVE_SSSE3 ++%define PABSD PABSD_SSSE3 ++AC3_EXTRACT_EXPONENTS ssse3 ++%endif ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/ac3dsp_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/ac3dsp_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/ac3dsp_mmx.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/ac3dsp_mmx.c 2012-05-14 14:08:54.494343202 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * x86-optimized AC-3 DSP utils ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/x86_cpu.h" ++#include "dsputil_mmx.h" ++#include "libavcodec/ac3dsp.h" ++ ++extern void ff_ac3_exponent_min_mmx (uint8_t *exp, int num_reuse_blocks, int nb_coefs); ++extern void ff_ac3_exponent_min_mmxext(uint8_t *exp, int num_reuse_blocks, int nb_coefs); ++extern void ff_ac3_exponent_min_sse2 (uint8_t *exp, int num_reuse_blocks, int nb_coefs); ++ ++extern int ff_ac3_max_msb_abs_int16_mmx (const int16_t *src, int len); ++extern int ff_ac3_max_msb_abs_int16_mmxext(const int16_t *src, int len); ++extern int ff_ac3_max_msb_abs_int16_sse2 (const int16_t *src, int len); ++extern int ff_ac3_max_msb_abs_int16_ssse3 (const int16_t *src, int len); ++ ++extern void ff_ac3_lshift_int16_mmx (int16_t *src, unsigned int len, unsigned int shift); ++extern void ff_ac3_lshift_int16_sse2(int16_t *src, unsigned int len, unsigned int shift); ++ ++extern void ff_ac3_rshift_int32_mmx (int32_t *src, unsigned int len, unsigned int shift); ++extern void ff_ac3_rshift_int32_sse2(int32_t *src, unsigned int len, unsigned int shift); ++ ++extern void ff_float_to_fixed24_3dnow(int32_t *dst, const float *src, unsigned int len); ++extern void ff_float_to_fixed24_sse (int32_t *dst, const float *src, unsigned int len); ++extern void ff_float_to_fixed24_sse2 (int32_t *dst, const float *src, unsigned int len); ++ ++extern int ff_ac3_compute_mantissa_size_sse2(uint16_t mant_cnt[6][16]); ++ ++extern void ff_ac3_extract_exponents_3dnow(uint8_t *exp, int32_t *coef, int nb_coefs); ++extern void ff_ac3_extract_exponents_sse2 (uint8_t *exp, int32_t *coef, int nb_coefs); ++extern void ff_ac3_extract_exponents_ssse3(uint8_t *exp, int32_t *coef, int nb_coefs); ++ ++av_cold void ff_ac3dsp_init_x86(AC3DSPContext *c, int bit_exact) ++{ ++#if HAVE_YASM ++ int mm_flags = av_get_cpu_flags(); ++ ++ if (mm_flags & AV_CPU_FLAG_MMX) { ++ c->ac3_exponent_min = ff_ac3_exponent_min_mmx; ++ c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmx; ++ c->ac3_lshift_int16 = ff_ac3_lshift_int16_mmx; ++ c->ac3_rshift_int32 = ff_ac3_rshift_int32_mmx; ++ } ++ if (mm_flags & AV_CPU_FLAG_3DNOW && HAVE_AMD3DNOW) { ++ c->extract_exponents = ff_ac3_extract_exponents_3dnow; ++ if (!bit_exact) { ++ c->float_to_fixed24 = ff_float_to_fixed24_3dnow; ++ } ++ } ++ if (mm_flags & AV_CPU_FLAG_MMX2 && HAVE_MMX2) { ++ c->ac3_exponent_min = ff_ac3_exponent_min_mmxext; ++ c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_mmxext; ++ } ++ if (mm_flags & AV_CPU_FLAG_SSE && HAVE_SSE) { ++ c->float_to_fixed24 = ff_float_to_fixed24_sse; ++ } ++ if (mm_flags & AV_CPU_FLAG_SSE2 && HAVE_SSE) { ++ c->ac3_exponent_min = ff_ac3_exponent_min_sse2; ++ c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_sse2; ++ c->float_to_fixed24 = ff_float_to_fixed24_sse2; ++ c->compute_mantissa_size = ff_ac3_compute_mantissa_size_sse2; ++ c->extract_exponents = ff_ac3_extract_exponents_sse2; ++ if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) { ++ c->ac3_lshift_int16 = ff_ac3_lshift_int16_sse2; ++ c->ac3_rshift_int32 = ff_ac3_rshift_int32_sse2; ++ } ++ } ++ if (mm_flags & AV_CPU_FLAG_SSSE3 && HAVE_SSSE3) { ++ c->ac3_max_msb_abs_int16 = ff_ac3_max_msb_abs_int16_ssse3; ++ if (!(mm_flags & AV_CPU_FLAG_ATOM)) { ++ c->extract_exponents = ff_ac3_extract_exponents_ssse3; ++ } ++ } ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/cabac.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/cabac.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/cabac.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/cabac.h 2012-05-14 14:08:54.495343223 +0200 +@@ -0,0 +1,140 @@ ++/* ++ * Copyright (c) 2003 Michael Niedermayer ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_X86_CABAC_H ++#define AVCODEC_X86_CABAC_H ++ ++#include "libavcodec/cabac.h" ++#include "libavutil/attributes.h" ++#include "libavutil/x86_cpu.h" ++#include "config.h" ++ ++#if HAVE_FAST_CMOV ++#define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp)\ ++ "mov "tmp" , %%ecx \n\t"\ ++ "shl $17 , "tmp" \n\t"\ ++ "cmp "low" , "tmp" \n\t"\ ++ "cmova %%ecx , "range" \n\t"\ ++ "sbb %%ecx , %%ecx \n\t"\ ++ "and %%ecx , "tmp" \n\t"\ ++ "xor %%ecx , "ret" \n\t"\ ++ "sub "tmp" , "low" \n\t" ++#else /* HAVE_FAST_CMOV */ ++#define BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp)\ ++ "mov "tmp" , %%ecx \n\t"\ ++ "shl $17 , "tmp" \n\t"\ ++ "sub "low" , "tmp" \n\t"\ ++ "sar $31 , "tmp" \n\t" /*lps_mask*/\ ++ "sub %%ecx , "range" \n\t" /*RangeLPS - range*/\ ++ "and "tmp" , "range" \n\t" /*(RangeLPS - range)&lps_mask*/\ ++ "add %%ecx , "range" \n\t" /*new range*/\ ++ "shl $17 , %%ecx \n\t"\ ++ "and "tmp" , %%ecx \n\t"\ ++ "sub %%ecx , "low" \n\t"\ ++ "xor "tmp" , "ret" \n\t" ++#endif /* HAVE_FAST_CMOV */ ++ ++#define BRANCHLESS_GET_CABAC(ret, statep, low, lowword, range, tmp, tmpbyte, byte) \ ++ "movzbl "statep" , "ret" \n\t"\ ++ "mov "range" , "tmp" \n\t"\ ++ "and $0xC0 , "range" \n\t"\ ++ "movzbl "MANGLE(ff_h264_lps_range)"("ret", "range", 2), "range" \n\t"\ ++ "sub "range" , "tmp" \n\t"\ ++ BRANCHLESS_GET_CABAC_UPDATE(ret, statep, low, lowword, range, tmp) \ ++ "movzbl " MANGLE(ff_h264_norm_shift) "("range"), %%ecx \n\t"\ ++ "shl %%cl , "range" \n\t"\ ++ "movzbl "MANGLE(ff_h264_mlps_state)"+128("ret"), "tmp" \n\t"\ ++ "shl %%cl , "low" \n\t"\ ++ "mov "tmpbyte" , "statep" \n\t"\ ++ "test "lowword" , "lowword" \n\t"\ ++ " jnz 1f \n\t"\ ++ "mov "byte" , %%"REG_c" \n\t"\ ++ "add"OPSIZE" $2 , "byte" \n\t"\ ++ "movzwl (%%"REG_c") , "tmp" \n\t"\ ++ "lea -1("low") , %%ecx \n\t"\ ++ "xor "low" , %%ecx \n\t"\ ++ "shr $15 , %%ecx \n\t"\ ++ "bswap "tmp" \n\t"\ ++ "shr $15 , "tmp" \n\t"\ ++ "movzbl " MANGLE(ff_h264_norm_shift) "(%%ecx), %%ecx \n\t"\ ++ "sub $0xFFFF , "tmp" \n\t"\ ++ "neg %%ecx \n\t"\ ++ "add $7 , %%ecx \n\t"\ ++ "shl %%cl , "tmp" \n\t"\ ++ "add "tmp" , "low" \n\t"\ ++ "1: \n\t" ++ ++ ++#if HAVE_7REGS && !defined(BROKEN_RELOCATIONS) && !(defined(__i386) && defined(__clang__) && (__clang_major__<2 || (__clang_major__==2 && __clang_minor__<10)))\ ++ && !(defined(__i386) && !defined(__clang__) && defined(__llvm__) && __GNUC__==4 && __GNUC_MINOR__==2 && __GNUC_PATCHLEVEL__<=1) ++#define get_cabac_inline get_cabac_inline_x86 ++static av_always_inline int get_cabac_inline_x86(CABACContext *c, ++ uint8_t *const state) ++{ ++ int bit, tmp; ++ ++ __asm__ volatile( ++ BRANCHLESS_GET_CABAC("%0", "(%5)", "%1", "%w1", "%2", ++ "%3", "%b3", "%4") ++ :"=&r"(bit), "+&r"(c->low), "+&r"(c->range), "=&q"(tmp), ++ "+m"(c->bytestream) ++ :"r"(state) ++ : "%"REG_c, "memory" ++ ); ++ return bit & 1; ++} ++#endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */ ++ ++#define get_cabac_bypass_sign get_cabac_bypass_sign_x86 ++static av_always_inline int get_cabac_bypass_sign_x86(CABACContext *c, int val) ++{ ++ x86_reg tmp; ++ __asm__ volatile( ++ "movl %4, %k1 \n\t" ++ "movl %2, %%eax \n\t" ++ "shl $17, %k1 \n\t" ++ "add %%eax, %%eax \n\t" ++ "sub %k1, %%eax \n\t" ++ "cltd \n\t" ++ "and %%edx, %k1 \n\t" ++ "add %k1, %%eax \n\t" ++ "xor %%edx, %%ecx \n\t" ++ "sub %%edx, %%ecx \n\t" ++ "test %%ax, %%ax \n\t" ++ " jnz 1f \n\t" ++ "mov %3, %1 \n\t" ++ "subl $0xFFFF, %%eax \n\t" ++ "movzwl (%1), %%edx \n\t" ++ "bswap %%edx \n\t" ++ "shrl $15, %%edx \n\t" ++ "add $2, %1 \n\t" ++ "addl %%edx, %%eax \n\t" ++ "mov %1, %3 \n\t" ++ "1: \n\t" ++ "movl %%eax, %2 \n\t" ++ ++ :"+c"(val), "=&r"(tmp), "+m"(c->low), "+m"(c->bytestream) ++ :"m"(c->range) ++ : "%eax", "%edx" ++ ); ++ return val; ++} ++ ++#endif /* AVCODEC_X86_CABAC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dct32_sse.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dct32_sse.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dct32_sse.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dct32_sse.asm 2012-05-14 14:08:54.496343243 +0200 +@@ -0,0 +1,515 @@ ++;****************************************************************************** ++;* 32 point SSE-optimized DCT transform ++;* Copyright (c) 2010 Vitor Sessak ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA 32 ++ ++align 32 ++ps_cos_vec: dd 0.500603, 0.505471, 0.515447, 0.531043 ++ dd 0.553104, 0.582935, 0.622504, 0.674808 ++ dd -10.190008, -3.407609, -2.057781, -1.484165 ++ dd -1.169440, -0.972568, -0.839350, -0.744536 ++ dd 0.502419, 0.522499, 0.566944, 0.646822 ++ dd 0.788155, 1.060678, 1.722447, 5.101149 ++ dd 0.509796, 0.601345, 0.899976, 2.562916 ++ dd 0.509796, 0.601345, 0.899976, 2.562916 ++ dd 1.000000, 1.000000, 1.306563, 0.541196 ++ dd 1.000000, 1.000000, 1.306563, 0.541196 ++ dd 1.000000, 0.707107, 1.000000, -0.707107 ++ dd 1.000000, 0.707107, 1.000000, -0.707107 ++ dd 0.707107, 0.707107, 0.707107, 0.707107 ++ ++align 32 ++ps_p1p1m1m1: dd 0, 0, 0x80000000, 0x80000000, 0, 0, 0x80000000, 0x80000000 ++ ++%macro BUTTERFLY_SSE 4 ++ movaps %4, %1 ++ subps %1, %2 ++ addps %2, %4 ++ mulps %1, %3 ++%endmacro ++ ++%macro BUTTERFLY_AVX 4 ++ vsubps %4, %1, %2 ++ vaddps %2, %2, %1 ++ vmulps %1, %4, %3 ++%endmacro ++ ++%macro BUTTERFLY0_SSE 5 ++ movaps %4, %1 ++ shufps %1, %1, %5 ++ xorps %4, %2 ++ addps %1, %4 ++ mulps %1, %3 ++%endmacro ++ ++%macro BUTTERFLY0_SSE2 5 ++ pshufd %4, %1, %5 ++ xorps %1, %2 ++ addps %1, %4 ++ mulps %1, %3 ++%endmacro ++ ++%macro BUTTERFLY0_AVX 5 ++ vshufps %4, %1, %1, %5 ++ vxorps %1, %1, %2 ++ vaddps %4, %4, %1 ++ vmulps %1, %4, %3 ++%endmacro ++ ++%macro BUTTERFLY2 4 ++ BUTTERFLY0 %1, %2, %3, %4, 0x1b ++%endmacro ++ ++%macro BUTTERFLY3 4 ++ BUTTERFLY0 %1, %2, %3, %4, 0xb1 ++%endmacro ++ ++%macro BUTTERFLY3V 5 ++ movaps m%5, m%1 ++ addps m%1, m%2 ++ subps m%5, m%2 ++ SWAP %2, %5 ++ mulps m%2, [ps_cos_vec+192] ++ movaps m%5, m%3 ++ addps m%3, m%4 ++ subps m%4, m%5 ++ mulps m%4, [ps_cos_vec+192] ++%endmacro ++ ++%macro PASS6_AND_PERMUTE 0 ++ mov tmpd, [outq+4] ++ movss m7, [outq+72] ++ addss m7, [outq+76] ++ movss m3, [outq+56] ++ addss m3, [outq+60] ++ addss m4, m3 ++ movss m2, [outq+52] ++ addss m2, m3 ++ movss m3, [outq+104] ++ addss m3, [outq+108] ++ addss m1, m3 ++ addss m5, m4 ++ movss [outq+ 16], m1 ++ movss m1, [outq+100] ++ addss m1, m3 ++ movss m3, [outq+40] ++ movss [outq+ 48], m1 ++ addss m3, [outq+44] ++ movss m1, [outq+100] ++ addss m4, m3 ++ addss m3, m2 ++ addss m1, [outq+108] ++ movss [outq+ 40], m3 ++ addss m2, [outq+36] ++ movss m3, [outq+8] ++ movss [outq+ 56], m2 ++ addss m3, [outq+12] ++ movss [outq+ 32], m3 ++ movss m3, [outq+80] ++ movss [outq+ 8], m5 ++ movss [outq+ 80], m1 ++ movss m2, [outq+52] ++ movss m5, [outq+120] ++ addss m5, [outq+124] ++ movss m1, [outq+64] ++ addss m2, [outq+60] ++ addss m0, m5 ++ addss m5, [outq+116] ++ mov [outq+64], tmpd ++ addss m6, m0 ++ addss m1, m6 ++ mov tmpd, [outq+12] ++ mov [outq+ 96], tmpd ++ movss [outq+ 4], m1 ++ movss m1, [outq+24] ++ movss [outq+ 24], m4 ++ movss m4, [outq+88] ++ addss m4, [outq+92] ++ addss m3, m4 ++ addss m4, [outq+84] ++ mov tmpd, [outq+108] ++ addss m1, [outq+28] ++ addss m0, m1 ++ addss m1, m5 ++ addss m6, m3 ++ addss m3, m0 ++ addss m0, m7 ++ addss m5, [outq+20] ++ addss m7, m1 ++ movss [outq+ 12], m6 ++ mov [outq+112], tmpd ++ movss m6, [outq+28] ++ movss [outq+ 28], m0 ++ movss m0, [outq+36] ++ movss [outq+ 36], m7 ++ addss m1, m4 ++ movss m7, [outq+116] ++ addss m0, m2 ++ addss m7, [outq+124] ++ movss [outq+ 72], m0 ++ movss m0, [outq+44] ++ addss m2, m0 ++ movss [outq+ 44], m1 ++ movss [outq+ 88], m2 ++ addss m0, [outq+60] ++ mov tmpd, [outq+60] ++ mov [outq+120], tmpd ++ movss [outq+104], m0 ++ addss m4, m5 ++ addss m5, [outq+68] ++ movss [outq+52], m4 ++ movss [outq+60], m5 ++ movss m4, [outq+68] ++ movss m5, [outq+20] ++ movss [outq+ 20], m3 ++ addss m5, m7 ++ addss m7, m6 ++ addss m4, m5 ++ movss m2, [outq+84] ++ addss m2, [outq+92] ++ addss m5, m2 ++ movss [outq+ 68], m4 ++ addss m2, m7 ++ movss m4, [outq+76] ++ movss [outq+ 84], m2 ++ movss [outq+ 76], m5 ++ addss m7, m4 ++ addss m6, [outq+124] ++ addss m4, m6 ++ addss m6, [outq+92] ++ movss [outq+100], m4 ++ movss [outq+108], m6 ++ movss m6, [outq+92] ++ movss [outq+92], m7 ++ addss m6, [outq+124] ++ movss [outq+116], m6 ++%endmacro ++ ++%define BUTTERFLY BUTTERFLY_AVX ++%define BUTTERFLY0 BUTTERFLY0_AVX ++ ++INIT_YMM ++SECTION_TEXT ++%ifdef HAVE_AVX ++; void ff_dct32_float_avx(FFTSample *out, const FFTSample *in) ++cglobal dct32_float_avx, 2,3,8, out, in, tmp ++ ; pass 1 ++ vmovaps m4, [inq+0] ++ vinsertf128 m5, m5, [inq+96], 1 ++ vinsertf128 m5, m5, [inq+112], 0 ++ vshufps m5, m5, m5, 0x1b ++ BUTTERFLY m4, m5, [ps_cos_vec], m6 ++ ++ vmovaps m2, [inq+64] ++ vinsertf128 m6, m6, [inq+32], 1 ++ vinsertf128 m6, m6, [inq+48], 0 ++ vshufps m6, m6, m6, 0x1b ++ BUTTERFLY m2, m6, [ps_cos_vec+32], m0 ++ ++ ; pass 2 ++ ++ BUTTERFLY m5, m6, [ps_cos_vec+64], m0 ++ BUTTERFLY m4, m2, [ps_cos_vec+64], m7 ++ ++ ++ ; pass 3 ++ vperm2f128 m3, m6, m4, 0x31 ++ vperm2f128 m1, m6, m4, 0x20 ++ vshufps m3, m3, m3, 0x1b ++ ++ BUTTERFLY m1, m3, [ps_cos_vec+96], m6 ++ ++ ++ vperm2f128 m4, m5, m2, 0x20 ++ vperm2f128 m5, m5, m2, 0x31 ++ vshufps m5, m5, m5, 0x1b ++ ++ BUTTERFLY m4, m5, [ps_cos_vec+96], m6 ++ ++ ; pass 4 ++ vmovaps m6, [ps_p1p1m1m1+0] ++ vmovaps m2, [ps_cos_vec+128] ++ ++ BUTTERFLY2 m5, m6, m2, m7 ++ BUTTERFLY2 m4, m6, m2, m7 ++ BUTTERFLY2 m1, m6, m2, m7 ++ BUTTERFLY2 m3, m6, m2, m7 ++ ++ ++ ; pass 5 ++ vshufps m6, m6, m6, 0xcc ++ vmovaps m2, [ps_cos_vec+160] ++ ++ BUTTERFLY3 m5, m6, m2, m7 ++ BUTTERFLY3 m4, m6, m2, m7 ++ BUTTERFLY3 m1, m6, m2, m7 ++ BUTTERFLY3 m3, m6, m2, m7 ++ ++ vperm2f128 m6, m3, m3, 0x31 ++ vmovaps [outq], m3 ++ ++ vextractf128 [outq+64], m5, 1 ++ vextractf128 [outq+32], m5, 0 ++ ++ vextractf128 [outq+80], m4, 1 ++ vextractf128 [outq+48], m4, 0 ++ ++ vperm2f128 m0, m1, m1, 0x31 ++ vmovaps [outq+96], m1 ++ ++ vzeroupper ++ ++ ; pass 6, no SIMD... ++INIT_XMM ++ PASS6_AND_PERMUTE ++ RET ++%endif ++ ++%define BUTTERFLY BUTTERFLY_SSE ++%define BUTTERFLY0 BUTTERFLY0_SSE ++ ++%ifdef ARCH_X86_64 ++%define SPILL SWAP ++%define UNSPILL SWAP ++ ++%macro PASS5 0 ++ nop ; FIXME code alignment ++ SWAP 5, 8 ++ SWAP 4, 12 ++ SWAP 6, 14 ++ SWAP 7, 13 ++ SWAP 0, 15 ++ PERMUTE 9,10, 10,12, 11,14, 12,9, 13,11, 14,13 ++ TRANSPOSE4x4PS 8, 9, 10, 11, 0 ++ BUTTERFLY3V 8, 9, 10, 11, 0 ++ addps m10, m11 ++ TRANSPOSE4x4PS 12, 13, 14, 15, 0 ++ BUTTERFLY3V 12, 13, 14, 15, 0 ++ addps m14, m15 ++ addps m12, m14 ++ addps m14, m13 ++ addps m13, m15 ++%endmacro ++ ++%macro PASS6 0 ++ SWAP 9, 12 ++ SWAP 11, 14 ++ movss [outq+0x00], m8 ++ pshuflw m0, m8, 0xe ++ movss [outq+0x10], m9 ++ pshuflw m1, m9, 0xe ++ movss [outq+0x20], m10 ++ pshuflw m2, m10, 0xe ++ movss [outq+0x30], m11 ++ pshuflw m3, m11, 0xe ++ movss [outq+0x40], m12 ++ pshuflw m4, m12, 0xe ++ movss [outq+0x50], m13 ++ pshuflw m5, m13, 0xe ++ movss [outq+0x60], m14 ++ pshuflw m6, m14, 0xe ++ movaps [outq+0x70], m15 ++ pshuflw m7, m15, 0xe ++ addss m0, m1 ++ addss m1, m2 ++ movss [outq+0x08], m0 ++ addss m2, m3 ++ movss [outq+0x18], m1 ++ addss m3, m4 ++ movss [outq+0x28], m2 ++ addss m4, m5 ++ movss [outq+0x38], m3 ++ addss m5, m6 ++ movss [outq+0x48], m4 ++ addss m6, m7 ++ movss [outq+0x58], m5 ++ movss [outq+0x68], m6 ++ movss [outq+0x78], m7 ++ ++ PERMUTE 1,8, 3,9, 5,10, 7,11, 9,12, 11,13, 13,14, 8,1, 10,3, 12,5, 14,7 ++ movhlps m0, m1 ++ pshufd m1, m1, 3 ++ SWAP 0, 2, 4, 6, 8, 10, 12, 14 ++ SWAP 1, 3, 5, 7, 9, 11, 13, 15 ++%rep 7 ++ movhlps m0, m1 ++ pshufd m1, m1, 3 ++ addss m15, m1 ++ SWAP 0, 2, 4, 6, 8, 10, 12, 14 ++ SWAP 1, 3, 5, 7, 9, 11, 13, 15 ++%endrep ++%assign i 4 ++%rep 15 ++ addss m0, m1 ++ movss [outq+i], m0 ++ SWAP 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ++ %assign i i+8 ++%endrep ++%endmacro ++ ++%else ; ARCH_X86_32 ++%macro SPILL 2 ; xmm#, mempos ++ movaps [outq+(%2-8)*16], m%1 ++%endmacro ++%macro UNSPILL 2 ++ movaps m%1, [outq+(%2-8)*16] ++%endmacro ++ ++%define PASS6 PASS6_AND_PERMUTE ++%macro PASS5 0 ++ movaps m2, [ps_cos_vec+160] ++ shufps m3, m3, 0xcc ++ ++ BUTTERFLY3 m5, m3, m2, m1 ++ SPILL 5, 8 ++ ++ UNSPILL 1, 9 ++ BUTTERFLY3 m1, m3, m2, m5 ++ SPILL 1, 14 ++ ++ BUTTERFLY3 m4, m3, m2, m5 ++ SPILL 4, 12 ++ ++ BUTTERFLY3 m7, m3, m2, m5 ++ SPILL 7, 13 ++ ++ UNSPILL 5, 10 ++ BUTTERFLY3 m5, m3, m2, m7 ++ SPILL 5, 10 ++ ++ UNSPILL 4, 11 ++ BUTTERFLY3 m4, m3, m2, m7 ++ SPILL 4, 11 ++ ++ BUTTERFLY3 m6, m3, m2, m7 ++ SPILL 6, 9 ++ ++ BUTTERFLY3 m0, m3, m2, m7 ++ SPILL 0, 15 ++%endmacro ++%endif ++ ++ ++INIT_XMM ++%macro DCT32_FUNC 1 ++; void ff_dct32_float_sse(FFTSample *out, const FFTSample *in) ++cglobal dct32_float_%1, 2,3,16, out, in, tmp ++ ; pass 1 ++ ++ movaps m0, [inq+0] ++ LOAD_INV m1, [inq+112] ++ BUTTERFLY m0, m1, [ps_cos_vec], m3 ++ ++ movaps m7, [inq+64] ++ LOAD_INV m4, [inq+48] ++ BUTTERFLY m7, m4, [ps_cos_vec+32], m3 ++ ++ ; pass 2 ++ movaps m2, [ps_cos_vec+64] ++ BUTTERFLY m1, m4, m2, m3 ++ SPILL 1, 11 ++ SPILL 4, 8 ++ ++ ; pass 1 ++ movaps m1, [inq+16] ++ LOAD_INV m6, [inq+96] ++ BUTTERFLY m1, m6, [ps_cos_vec+16], m3 ++ ++ movaps m4, [inq+80] ++ LOAD_INV m5, [inq+32] ++ BUTTERFLY m4, m5, [ps_cos_vec+48], m3 ++ ++ ; pass 2 ++ BUTTERFLY m0, m7, m2, m3 ++ ++ movaps m2, [ps_cos_vec+80] ++ BUTTERFLY m6, m5, m2, m3 ++ ++ BUTTERFLY m1, m4, m2, m3 ++ ++ ; pass 3 ++ movaps m2, [ps_cos_vec+96] ++ shufps m1, m1, 0x1b ++ BUTTERFLY m0, m1, m2, m3 ++ SPILL 0, 15 ++ SPILL 1, 14 ++ ++ UNSPILL 0, 8 ++ shufps m5, m5, 0x1b ++ BUTTERFLY m0, m5, m2, m3 ++ ++ UNSPILL 1, 11 ++ shufps m6, m6, 0x1b ++ BUTTERFLY m1, m6, m2, m3 ++ SPILL 1, 11 ++ ++ shufps m4, m4, 0x1b ++ BUTTERFLY m7, m4, m2, m3 ++ ++ ; pass 4 ++ movaps m3, [ps_p1p1m1m1+0] ++ movaps m2, [ps_cos_vec+128] ++ ++ BUTTERFLY2 m5, m3, m2, m1 ++ ++ BUTTERFLY2 m0, m3, m2, m1 ++ SPILL 0, 9 ++ ++ BUTTERFLY2 m6, m3, m2, m1 ++ SPILL 6, 10 ++ ++ UNSPILL 0, 11 ++ BUTTERFLY2 m0, m3, m2, m1 ++ SPILL 0, 11 ++ ++ BUTTERFLY2 m4, m3, m2, m1 ++ ++ BUTTERFLY2 m7, m3, m2, m1 ++ ++ UNSPILL 6, 14 ++ BUTTERFLY2 m6, m3, m2, m1 ++ ++ UNSPILL 0, 15 ++ BUTTERFLY2 m0, m3, m2, m1 ++ ++ PASS5 ++ PASS6 ++ RET ++%endmacro ++ ++%macro LOAD_INV_SSE 2 ++ movaps %1, %2 ++ shufps %1, %1, 0x1b ++%endmacro ++ ++%define LOAD_INV LOAD_INV_SSE ++DCT32_FUNC sse ++ ++%macro LOAD_INV_SSE2 2 ++ pshufd %1, %2, 0x1b ++%endmacro ++ ++%define LOAD_INV LOAD_INV_SSE2 ++%define BUTTERFLY0 BUTTERFLY0_SSE2 ++DCT32_FUNC sse2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dct32_sse.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dct32_sse.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dct32_sse.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dct32_sse.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,296 +0,0 @@ +-/* +- * 32 point SSE-optimized DCT transform +- * Copyright (c) 2010 Vitor Sessak +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +- +-#include "libavutil/x86_cpu.h" +-#include "libavutil/mem.h" +-#include "libavcodec/dsputil.h" +-#include "fft.h" +- +-DECLARE_ALIGNED(16, static const float, b1)[] = { +- 0.500603, 0.505471, 0.515447, 0.531043, +- 0.553104, 0.582935, 0.622504, 0.674808, +- -1.169440, -0.972568, -0.839350, -0.744536, +- -10.190008, -3.407609, -2.057781, -1.484165, +- 0.502419, 0.522499, 0.566944, 0.646822, +- 0.788155, 1.060678, 1.722447, 5.101149, +- 0.509796, 0.601345, 0.899976, 2.562916, +- 1.000000, 1.000000, 1.306563, 0.541196, +- 1.000000, 0.707107, 1.000000, -0.707107 +-}; +- +-DECLARE_ALIGNED(16, static const int32_t, smask)[4] = { +- 0, 0, 0x80000000, 0x80000000 +-}; +- +-/* butterfly operator */ +-#define BUTTERFLY(a,b,c,tmp) \ +- "movaps %%" #a ", %%" #tmp " \n\t" \ +- "subps %%" #b ", %%" #a " \n\t" \ +- "addps %%" #tmp ", %%" #b " \n\t" \ +- "mulps " #c ", %%" #a " \n\t" +- +-///* Same as BUTTERFLY when vectors a and b overlap */ +-#define BUTTERFLY0(val, mask, cos, tmp, shuf) \ +- "movaps %%" #val ", %%" #tmp " \n\t" \ +- "shufps " #shuf ", %%" #val ",%%" #val " \n\t" \ +- "xorps %%" #mask ", %%" #tmp " \n\t" /* flip signs */ \ +- "addps %%" #tmp ", %%" #val " \n\t" \ +- "mulps %%" #cos ", %%" #val " \n\t" +- +-#define BUTTERFLY2(val, mask, cos, tmp) BUTTERFLY0(val, mask, cos, tmp, $0x1b) +-#define BUTTERFLY3(val, mask, cos, tmp) BUTTERFLY0(val, mask, cos, tmp, $0xb1) +- +-void ff_dct32_float_sse(FFTSample *out, const FFTSample *in) +-{ +- int32_t tmp1 = 0; +- __asm__ volatile( +- /* pass 1 */ +- +- "movaps (%4), %%xmm0 \n\t" +- "movaps 112(%4), %%xmm1 \n\t" +- "shufps $0x1b, %%xmm1, %%xmm1 \n\t" +- BUTTERFLY(xmm0, xmm1, (%2), xmm3) +- +- "movaps 64(%4), %%xmm7 \n\t" +- "movaps 48(%4), %%xmm4 \n\t" +- "shufps $0x1b, %%xmm4, %%xmm4 \n\t" +- BUTTERFLY(xmm7, xmm4, 48(%2), xmm3) +- +- +- /* pass 2 */ +- "movaps 64(%2), %%xmm2 \n\t" +- BUTTERFLY(xmm1, xmm4, %%xmm2, xmm3) +- "movaps %%xmm1, 48(%1) \n\t" +- "movaps %%xmm4, (%1) \n\t" +- +- /* pass 1 */ +- "movaps 16(%4), %%xmm1 \n\t" +- "movaps 96(%4), %%xmm6 \n\t" +- "shufps $0x1b, %%xmm6, %%xmm6 \n\t" +- BUTTERFLY(xmm1, xmm6, 16(%2), xmm3) +- +- "movaps 80(%4), %%xmm4 \n\t" +- "movaps 32(%4), %%xmm5 \n\t" +- "shufps $0x1b, %%xmm5, %%xmm5 \n\t" +- BUTTERFLY(xmm4, xmm5, 32(%2), xmm3) +- +- /* pass 2 */ +- BUTTERFLY(xmm0, xmm7, %%xmm2, xmm3) +- +- "movaps 80(%2), %%xmm2 \n\t" +- BUTTERFLY(xmm6, xmm5, %%xmm2, xmm3) +- +- BUTTERFLY(xmm1, xmm4, %%xmm2, xmm3) +- +- /* pass 3 */ +- "movaps 96(%2), %%xmm2 \n\t" +- "shufps $0x1b, %%xmm1, %%xmm1 \n\t" +- BUTTERFLY(xmm0, xmm1, %%xmm2, xmm3) +- "movaps %%xmm0, 112(%1) \n\t" +- "movaps %%xmm1, 96(%1) \n\t" +- +- "movaps 0(%1), %%xmm0 \n\t" +- "shufps $0x1b, %%xmm5, %%xmm5 \n\t" +- BUTTERFLY(xmm0, xmm5, %%xmm2, xmm3) +- +- "movaps 48(%1), %%xmm1 \n\t" +- "shufps $0x1b, %%xmm6, %%xmm6 \n\t" +- BUTTERFLY(xmm1, xmm6, %%xmm2, xmm3) +- "movaps %%xmm1, 48(%1) \n\t" +- +- "shufps $0x1b, %%xmm4, %%xmm4 \n\t" +- BUTTERFLY(xmm7, xmm4, %%xmm2, xmm3) +- +- /* pass 4 */ +- "movaps (%3), %%xmm3 \n\t" +- "movaps 112(%2), %%xmm2 \n\t" +- +- BUTTERFLY2(xmm5, xmm3, xmm2, xmm1) +- +- BUTTERFLY2(xmm0, xmm3, xmm2, xmm1) +- "movaps %%xmm0, 16(%1) \n\t" +- +- BUTTERFLY2(xmm6, xmm3, xmm2, xmm1) +- "movaps %%xmm6, 32(%1) \n\t" +- +- "movaps 48(%1), %%xmm0 \n\t" +- BUTTERFLY2(xmm0, xmm3, xmm2, xmm1) +- "movaps %%xmm0, 48(%1) \n\t" +- +- BUTTERFLY2(xmm4, xmm3, xmm2, xmm1) +- +- BUTTERFLY2(xmm7, xmm3, xmm2, xmm1) +- +- "movaps 96(%1), %%xmm6 \n\t" +- BUTTERFLY2(xmm6, xmm3, xmm2, xmm1) +- +- "movaps 112(%1), %%xmm0 \n\t" +- BUTTERFLY2(xmm0, xmm3, xmm2, xmm1) +- +- /* pass 5 */ +- "movaps 128(%2), %%xmm2 \n\t" +- "shufps $0xCC, %%xmm3,%%xmm3 \n\t" +- +- BUTTERFLY3(xmm5, xmm3, xmm2, xmm1) +- "movaps %%xmm5, (%1) \n\t" +- +- "movaps 16(%1), %%xmm1 \n\t" +- BUTTERFLY3(xmm1, xmm3, xmm2, xmm5) +- "movaps %%xmm1, 16(%1) \n\t" +- +- BUTTERFLY3(xmm4, xmm3, xmm2, xmm5) +- "movaps %%xmm4, 64(%1) \n\t" +- +- BUTTERFLY3(xmm7, xmm3, xmm2, xmm5) +- "movaps %%xmm7, 80(%1) \n\t" +- +- "movaps 32(%1), %%xmm5 \n\t" +- BUTTERFLY3(xmm5, xmm3, xmm2, xmm7) +- "movaps %%xmm5, 32(%1) \n\t" +- +- "movaps 48(%1), %%xmm4 \n\t" +- BUTTERFLY3(xmm4, xmm3, xmm2, xmm7) +- "movaps %%xmm4, 48(%1) \n\t" +- +- BUTTERFLY3(xmm6, xmm3, xmm2, xmm7) +- "movaps %%xmm6, 96(%1) \n\t" +- +- BUTTERFLY3(xmm0, xmm3, xmm2, xmm7) +- "movaps %%xmm0, 112(%1) \n\t" +- +- +- /* pass 6, no SIMD... */ +- "movss 56(%1), %%xmm3 \n\t" +- "movl 4(%1), %0 \n\t" +- "addss 60(%1), %%xmm3 \n\t" +- "movss 72(%1), %%xmm7 \n\t" +- "addss %%xmm3, %%xmm4 \n\t" +- "movss 52(%1), %%xmm2 \n\t" +- "addss %%xmm3, %%xmm2 \n\t" +- "movss 24(%1), %%xmm3 \n\t" +- "addss 28(%1), %%xmm3 \n\t" +- "addss 76(%1), %%xmm7 \n\t" +- "addss %%xmm3, %%xmm1 \n\t" +- "addss %%xmm4, %%xmm5 \n\t" +- "movss %%xmm1, 16(%1) \n\t" +- "movss 20(%1), %%xmm1 \n\t" +- "addss %%xmm3, %%xmm1 \n\t" +- "movss 40(%1), %%xmm3 \n\t" +- "movss %%xmm1, 48(%1) \n\t" +- "addss 44(%1), %%xmm3 \n\t" +- "movss 20(%1), %%xmm1 \n\t" +- "addss %%xmm3, %%xmm4 \n\t" +- "addss %%xmm2, %%xmm3 \n\t" +- "addss 28(%1), %%xmm1 \n\t" +- "movss %%xmm3, 40(%1) \n\t" +- "addss 36(%1), %%xmm2 \n\t" +- "movss 8(%1), %%xmm3 \n\t" +- "movss %%xmm2, 56(%1) \n\t" +- "addss 12(%1), %%xmm3 \n\t" +- "movss %%xmm5, 8(%1) \n\t" +- "movss %%xmm3, 32(%1) \n\t" +- "movss 52(%1), %%xmm2 \n\t" +- "movss 80(%1), %%xmm3 \n\t" +- "movss 120(%1), %%xmm5 \n\t" +- "movss %%xmm1, 80(%1) \n\t" +- "movss %%xmm4, 24(%1) \n\t" +- "addss 124(%1), %%xmm5 \n\t" +- "movss 64(%1), %%xmm1 \n\t" +- "addss 60(%1), %%xmm2 \n\t" +- "addss %%xmm5, %%xmm0 \n\t" +- "addss 116(%1), %%xmm5 \n\t" +- "movl %0, 64(%1) \n\t" +- "addss %%xmm0, %%xmm6 \n\t" +- "addss %%xmm6, %%xmm1 \n\t" +- "movl 12(%1), %0 \n\t" +- "movss %%xmm1, 4(%1) \n\t" +- "movss 88(%1), %%xmm1 \n\t" +- "movl %0, 96(%1) \n\t" +- "addss 92(%1), %%xmm1 \n\t" +- "movss 104(%1), %%xmm4 \n\t" +- "movl 28(%1), %0 \n\t" +- "addss 108(%1), %%xmm4 \n\t" +- "addss %%xmm4, %%xmm0 \n\t" +- "addss %%xmm1, %%xmm3 \n\t" +- "addss 84(%1), %%xmm1 \n\t" +- "addss %%xmm5, %%xmm4 \n\t" +- "addss %%xmm3, %%xmm6 \n\t" +- "addss %%xmm0, %%xmm3 \n\t" +- "addss %%xmm7, %%xmm0 \n\t" +- "addss 100(%1), %%xmm5 \n\t" +- "addss %%xmm4, %%xmm7 \n\t" +- "movl %0, 112(%1) \n\t" +- "movss %%xmm0, 28(%1) \n\t" +- "movss 36(%1), %%xmm0 \n\t" +- "movss %%xmm7, 36(%1) \n\t" +- "addss %%xmm1, %%xmm4 \n\t" +- "movss 116(%1), %%xmm7 \n\t" +- "addss %%xmm2, %%xmm0 \n\t" +- "addss 124(%1), %%xmm7 \n\t" +- "movss %%xmm0, 72(%1) \n\t" +- "movss 44(%1), %%xmm0 \n\t" +- "movss %%xmm6, 12(%1) \n\t" +- "movss %%xmm3, 20(%1) \n\t" +- "addss %%xmm0, %%xmm2 \n\t" +- "movss %%xmm4, 44(%1) \n\t" +- "movss %%xmm2, 88(%1) \n\t" +- "addss 60(%1), %%xmm0 \n\t" +- "movl 60(%1), %0 \n\t" +- "movl %0, 120(%1) \n\t" +- "movss %%xmm0, 104(%1) \n\t" +- "addss %%xmm5, %%xmm1 \n\t" +- "addss 68(%1), %%xmm5 \n\t" +- "movss %%xmm1, 52(%1) \n\t" +- "movss %%xmm5, 60(%1) \n\t" +- "movss 68(%1), %%xmm1 \n\t" +- "movss 100(%1), %%xmm5 \n\t" +- "addss %%xmm7, %%xmm5 \n\t" +- "addss 108(%1), %%xmm7 \n\t" +- "addss %%xmm5, %%xmm1 \n\t" +- "movss 84(%1), %%xmm2 \n\t" +- "addss 92(%1), %%xmm2 \n\t" +- "addss %%xmm2, %%xmm5 \n\t" +- "movss %%xmm1, 68(%1) \n\t" +- "addss %%xmm7, %%xmm2 \n\t" +- "movss 76(%1), %%xmm1 \n\t" +- "movss %%xmm2, 84(%1) \n\t" +- "movss %%xmm5, 76(%1) \n\t" +- "movss 108(%1), %%xmm2 \n\t" +- "addss %%xmm1, %%xmm7 \n\t" +- "addss 124(%1), %%xmm2 \n\t" +- "addss %%xmm2, %%xmm1 \n\t" +- "addss 92(%1), %%xmm2 \n\t" +- "movss %%xmm1, 100(%1) \n\t" +- "movss %%xmm2, 108(%1) \n\t" +- "movss 92(%1), %%xmm2 \n\t" +- "movss %%xmm7, 92(%1) \n\t" +- "addss 124(%1), %%xmm2 \n\t" +- "movss %%xmm2, 116(%1) \n\t" +- :"+&r"(tmp1) +- :"r"(out), "r"(b1), "r"(smask), "r"(in) +- :XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", +- "%xmm4", "%xmm5", "%xmm6", "%xmm7",) +- "memory" +- ); +-} +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/deinterlace.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/deinterlace.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/deinterlace.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/deinterlace.asm 2012-05-14 14:08:54.501343343 +0200 +@@ -17,11 +17,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION_RODATA + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.c 2012-05-14 14:08:54.502343363 +0200 +@@ -0,0 +1,95 @@ ++/* ++ * Copyright (C) 2010 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dsputil_mmx.h" ++#include "diracdsp_mmx.h" ++ ++void ff_put_rect_clamped_mmx(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height); ++void ff_put_rect_clamped_sse2(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height); ++void ff_put_signed_rect_clamped_mmx(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height); ++void ff_put_signed_rect_clamped_sse2(uint8_t *dst, int dst_stride, const int16_t *src, int src_stride, int width, int height); ++ ++#define HPEL_FILTER(MMSIZE, EXT) \ ++ void ff_dirac_hpel_filter_v_ ## EXT(uint8_t *, uint8_t *, int, int); \ ++ void ff_dirac_hpel_filter_h_ ## EXT(uint8_t *, uint8_t *, int); \ ++ \ ++ static void dirac_hpel_filter_ ## EXT(uint8_t *dsth, uint8_t *dstv, uint8_t *dstc, \ ++ uint8_t *src, int stride, int width, int height) \ ++ { \ ++ while( height-- ) \ ++ { \ ++ ff_dirac_hpel_filter_v_ ## EXT(dstv-MMSIZE, src-MMSIZE, stride, width+MMSIZE+5); \ ++ ff_dirac_hpel_filter_h_ ## EXT(dsth, src, width); \ ++ ff_dirac_hpel_filter_h_ ## EXT(dstc, dstv, width); \ ++ \ ++ dsth += stride; \ ++ dstv += stride; \ ++ dstc += stride; \ ++ src += stride; \ ++ } \ ++ } ++ ++#if !ARCH_X86_64 ++HPEL_FILTER(8, mmx) ++#endif ++HPEL_FILTER(16, sse2) ++ ++#define PIXFUNC(PFX, IDX, EXT) \ ++ /*MMXDISABLEDc->PFX ## _dirac_pixels_tab[0][IDX] = ff_ ## PFX ## _dirac_pixels8_ ## EXT;*/ \ ++ c->PFX ## _dirac_pixels_tab[1][IDX] = ff_ ## PFX ## _dirac_pixels16_ ## EXT; \ ++ c->PFX ## _dirac_pixels_tab[2][IDX] = ff_ ## PFX ## _dirac_pixels32_ ## EXT ++ ++void ff_diracdsp_init_mmx(DiracDSPContext* c) ++{ ++ int mm_flags = av_get_cpu_flags(); ++ ++#if HAVE_YASM ++ c->add_dirac_obmc[0] = ff_add_dirac_obmc8_mmx; ++#if !ARCH_X86_64 ++ c->add_dirac_obmc[1] = ff_add_dirac_obmc16_mmx; ++ c->add_dirac_obmc[2] = ff_add_dirac_obmc32_mmx; ++ c->dirac_hpel_filter = dirac_hpel_filter_mmx; ++ c->add_rect_clamped = ff_add_rect_clamped_mmx; ++ c->put_signed_rect_clamped = ff_put_signed_rect_clamped_mmx; ++#endif ++#endif ++ ++ PIXFUNC(put, 0, mmx); ++ PIXFUNC(avg, 0, mmx); ++ ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ PIXFUNC(avg, 0, mmx2); ++ } ++ ++ if (mm_flags & AV_CPU_FLAG_SSE2) { ++#if HAVE_YASM ++ c->dirac_hpel_filter = dirac_hpel_filter_sse2; ++ c->add_rect_clamped = ff_add_rect_clamped_sse2; ++ c->put_signed_rect_clamped = ff_put_signed_rect_clamped_sse2; ++ ++ c->add_dirac_obmc[1] = ff_add_dirac_obmc16_sse2; ++ c->add_dirac_obmc[2] = ff_add_dirac_obmc32_sse2; ++#endif ++ c->put_dirac_pixels_tab[1][0] = ff_put_dirac_pixels16_sse2; ++ c->avg_dirac_pixels_tab[1][0] = ff_avg_dirac_pixels16_sse2; ++ c->put_dirac_pixels_tab[2][0] = ff_put_dirac_pixels32_sse2; ++ c->avg_dirac_pixels_tab[2][0] = ff_avg_dirac_pixels32_sse2; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_mmx.h 2012-05-14 14:08:54.502343363 +0200 +@@ -0,0 +1,47 @@ ++/* ++ * Copyright (c) 2010 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_X86_DIRACDSP_H ++#define AVCODEC_X86_DIRACDSP_H ++ ++#include "libavcodec/diracdsp.h" ++ ++void ff_diracdsp_init_mmx(DiracDSPContext* c); ++ ++DECL_DIRAC_PIXOP(put, mmx); ++DECL_DIRAC_PIXOP(avg, mmx); ++DECL_DIRAC_PIXOP(avg, mmx2); ++ ++void ff_put_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++void ff_avg_dirac_pixels16_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++void ff_put_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++void ff_avg_dirac_pixels32_sse2(uint8_t *dst, const uint8_t *src[5], int stride, int h); ++ ++void ff_add_rect_clamped_mmx(uint8_t *, const uint16_t *, int, const int16_t *, int, int, int); ++void ff_add_rect_clamped_sse2(uint8_t *, const uint16_t *, int, const int16_t *, int, int, int); ++ ++void ff_add_dirac_obmc8_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++void ff_add_dirac_obmc16_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++void ff_add_dirac_obmc32_mmx(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++ ++void ff_add_dirac_obmc16_sse2(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++void ff_add_dirac_obmc32_sse2(uint16_t *dst, const uint8_t *src, int stride, const uint8_t *obmc_weight, int yblen); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_yasm.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_yasm.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/diracdsp_yasm.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/diracdsp_yasm.asm 2012-05-14 14:08:54.503343383 +0200 +@@ -0,0 +1,260 @@ ++;****************************************************************************** ++;* Copyright (c) 2010 David Conrad ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++ ++SECTION_RODATA ++pw_3: times 8 dw 3 ++pw_7: times 8 dw 7 ++pw_16: times 8 dw 16 ++pw_32: times 8 dw 32 ++pb_128: times 16 db 128 ++ ++section .text ++ ++%macro UNPACK_ADD 6 ++ mov%5 %1, %3 ++ mov%6 m5, %4 ++ mova m4, %1 ++ mova %2, m5 ++ punpcklbw %1, m7 ++ punpcklbw m5, m7 ++ punpckhbw m4, m7 ++ punpckhbw %2, m7 ++ paddw %1, m5 ++ paddw %2, m4 ++%endmacro ++ ++%macro HPEL_FILTER 1 ++; dirac_hpel_filter_v_sse2(uint8_t *dst, uint8_t *src, int stride, int width); ++cglobal dirac_hpel_filter_v_%1, 4,6,8, dst, src, stride, width, src0, stridex3 ++ mov src0q, srcq ++ lea stridex3q, [3*strideq] ++ sub src0q, stridex3q ++ pxor m7, m7 ++.loop: ++ ; 7*(src[0] + src[1]) ++ UNPACK_ADD m0, m1, [srcq], [srcq + strideq], a,a ++ pmullw m0, [pw_7] ++ pmullw m1, [pw_7] ++ ++ ; 3*( ... + src[-2] + src[3]) ++ UNPACK_ADD m2, m3, [src0q + strideq], [srcq + stridex3q], a,a ++ paddw m0, m2 ++ paddw m1, m3 ++ pmullw m0, [pw_3] ++ pmullw m1, [pw_3] ++ ++ ; ... - 7*(src[-1] + src[2]) ++ UNPACK_ADD m2, m3, [src0q + strideq*2], [srcq + strideq*2], a,a ++ pmullw m2, [pw_7] ++ pmullw m3, [pw_7] ++ psubw m0, m2 ++ psubw m1, m3 ++ ++ ; ... - (src[-3] + src[4]) ++ UNPACK_ADD m2, m3, [src0q], [srcq + strideq*4], a,a ++ psubw m0, m2 ++ psubw m1, m3 ++ ++ paddw m0, [pw_16] ++ paddw m1, [pw_16] ++ psraw m0, 5 ++ psraw m1, 5 ++ packuswb m0, m1 ++ mova [dstq], m0 ++ add dstq, mmsize ++ add srcq, mmsize ++ add src0q, mmsize ++ sub widthd, mmsize ++ jg .loop ++ RET ++ ++; dirac_hpel_filter_h_sse2(uint8_t *dst, uint8_t *src, int width); ++cglobal dirac_hpel_filter_h_%1, 3,3,8, dst, src, width ++ dec widthd ++ pxor m7, m7 ++ and widthd, ~(mmsize-1) ++.loop: ++ ; 7*(src[0] + src[1]) ++ UNPACK_ADD m0, m1, [srcq + widthq], [srcq + widthq + 1], u,u ++ pmullw m0, [pw_7] ++ pmullw m1, [pw_7] ++ ++ ; 3*( ... + src[-2] + src[3]) ++ UNPACK_ADD m2, m3, [srcq + widthq - 2], [srcq + widthq + 3], u,u ++ paddw m0, m2 ++ paddw m1, m3 ++ pmullw m0, [pw_3] ++ pmullw m1, [pw_3] ++ ++ ; ... - 7*(src[-1] + src[2]) ++ UNPACK_ADD m2, m3, [srcq + widthq - 1], [srcq + widthq + 2], u,u ++ pmullw m2, [pw_7] ++ pmullw m3, [pw_7] ++ psubw m0, m2 ++ psubw m1, m3 ++ ++ ; ... - (src[-3] + src[4]) ++ UNPACK_ADD m2, m3, [srcq + widthq - 3], [srcq + widthq + 4], u,u ++ psubw m0, m2 ++ psubw m1, m3 ++ ++ paddw m0, [pw_16] ++ paddw m1, [pw_16] ++ psraw m0, 5 ++ psraw m1, 5 ++ packuswb m0, m1 ++ mova [dstq + widthq], m0 ++ sub widthd, mmsize ++ jge .loop ++ RET ++%endmacro ++ ++%macro PUT_RECT 1 ++; void put_rect_clamped(uint8_t *dst, int dst_stride, int16_t *src, int src_stride, int width, int height) ++cglobal put_signed_rect_clamped_%1, 5,7,3, dst, dst_stride, src, src_stride, w, dst2, src2 ++ mova m0, [pb_128] ++ add wd, (mmsize-1) ++ and wd, ~(mmsize-1) ++ ++%ifdef ARCH_X86_64 ++ mov r10d, r5m ++ mov r11d, wd ++ %define wspill r11d ++ %define hd r10d ++%else ++ mov r4m, wd ++ %define wspill r4m ++ %define hd r5mp ++%endif ++ ++.loopy ++ lea src2q, [srcq+src_strideq*2] ++ lea dst2q, [dstq+dst_strideq] ++.loopx: ++ sub wd, mmsize ++ mova m1, [srcq +2*wq] ++ mova m2, [src2q+2*wq] ++ packsswb m1, [srcq +2*wq+mmsize] ++ packsswb m2, [src2q+2*wq+mmsize] ++ paddb m1, m0 ++ paddb m2, m0 ++ mova [dstq +wq], m1 ++ mova [dst2q+wq], m2 ++ jg .loopx ++ ++ lea srcq, [srcq+src_strideq*4] ++ lea dstq, [dstq+dst_strideq*2] ++ sub hd, 2 ++ mov wd, wspill ++ jg .loopy ++ RET ++%endm ++ ++%macro ADD_RECT 1 ++; void add_rect_clamped(uint8_t *dst, uint16_t *src, int stride, int16_t *idwt, int idwt_stride, int width, int height) ++cglobal add_rect_clamped_%1, 7,7,3, dst, src, stride, idwt, idwt_stride, w, h ++ mova m0, [pw_32] ++ add wd, (mmsize-1) ++ and wd, ~(mmsize-1) ++ ++%ifdef ARCH_X86_64 ++ mov r11d, wd ++ %define wspill r11d ++%else ++ mov r5m, wd ++ %define wspill r5m ++%endif ++ ++.loop: ++ sub wd, mmsize ++ movu m1, [srcq +2*wq] ; FIXME: ensure alignment ++ paddw m1, m0 ++ psraw m1, 6 ++ movu m2, [srcq +2*wq+mmsize] ; FIXME: ensure alignment ++ paddw m2, m0 ++ psraw m2, 6 ++ paddw m1, [idwtq+2*wq] ++ paddw m2, [idwtq+2*wq+mmsize] ++ packuswb m1, m2 ++ mova [dstq +wq], m1 ++ jg .loop ++ ++ lea srcq, [srcq + 2*strideq] ++ add dstq, strideq ++ lea idwtq, [idwtq+ 2*idwt_strideq] ++ sub hd, 1 ++ mov wd, wspill ++ jg .loop ++ RET ++%endm ++ ++%macro ADD_OBMC 2 ++; void add_obmc(uint16_t *dst, uint8_t *src, int stride, uint8_t *obmc_weight, int yblen) ++cglobal add_dirac_obmc%1_%2, 6,6,5, dst, src, stride, obmc, yblen ++ pxor m4, m4 ++.loop: ++%assign i 0 ++%rep %1 / mmsize ++ mova m0, [srcq+i] ++ mova m1, m0 ++ punpcklbw m0, m4 ++ punpckhbw m1, m4 ++ mova m2, [obmcq+i] ++ mova m3, m2 ++ punpcklbw m2, m4 ++ punpckhbw m3, m4 ++ pmullw m0, m2 ++ pmullw m1, m3 ++ movu m2, [dstq+2*i] ++ movu m3, [dstq+2*i+mmsize] ++ paddw m0, m2 ++ paddw m1, m3 ++ movu [dstq+2*i], m0 ++ movu [dstq+2*i+mmsize], m1 ++%assign i i+mmsize ++%endrep ++ lea srcq, [srcq+strideq] ++ lea dstq, [dstq+2*strideq] ++ add obmcq, 32 ++ sub yblend, 1 ++ jg .loop ++ RET ++%endm ++ ++INIT_MMX ++%ifndef ARCH_X86_64 ++PUT_RECT mmx ++ADD_RECT mmx ++ ++HPEL_FILTER mmx ++ADD_OBMC 32, mmx ++ADD_OBMC 16, mmx ++%endif ++ADD_OBMC 8, mmx ++ ++INIT_XMM ++PUT_RECT sse2 ++ADD_RECT sse2 ++ ++HPEL_FILTER sse2 ++ADD_OBMC 32, sse2 ++ADD_OBMC 16, sse2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dnxhd_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dnxhd_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dnxhd_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dnxhd_mmx.c 2012-05-14 14:08:54.504343403 +0200 +@@ -53,6 +53,7 @@ + void ff_dnxhd_init_mmx(DNXHDEncContext *ctx) + { + if (av_get_cpu_flags() & AV_CPU_FLAG_SSE2) { +- ctx->get_pixels_8x4_sym = get_pixels_8x4_sym_sse2; ++ if (ctx->cid_table->bit_depth == 8) ++ ctx->get_pixels_8x4_sym = get_pixels_8x4_sym_sse2; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputilenc_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputilenc_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputilenc_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputilenc_mmx.c 2012-05-14 14:08:54.513343584 +0200 +@@ -1098,10 +1098,12 @@ + void dsputilenc_init_mmx(DSPContext* c, AVCodecContext *avctx) + { + int mm_flags = av_get_cpu_flags(); ++ int bit_depth = avctx->bits_per_raw_sample; + + if (mm_flags & AV_CPU_FLAG_MMX) { + const int dct_algo = avctx->dct_algo; +- if(dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX){ ++ if (avctx->bits_per_raw_sample <= 8 && ++ (dct_algo==FF_DCT_AUTO || dct_algo==FF_DCT_MMX)) { + if(mm_flags & AV_CPU_FLAG_SSE2){ + c->fdct = ff_fdct_sse2; + }else if(mm_flags & AV_CPU_FLAG_MMX2){ +@@ -1111,7 +1113,8 @@ + } + } + +- c->get_pixels = get_pixels_mmx; ++ if (bit_depth <= 8) ++ c->get_pixels = get_pixels_mmx; + c->diff_pixels = diff_pixels_mmx; + c->pix_sum = pix_sum16_mmx; + +@@ -1158,7 +1161,8 @@ + } + + if(mm_flags & AV_CPU_FLAG_SSE2){ +- c->get_pixels = get_pixels_sse2; ++ if (bit_depth <= 8) ++ c->get_pixels = get_pixels_sse2; + c->sum_abs_dctelem= sum_abs_dctelem_sse2; + #if HAVE_YASM && HAVE_ALIGNED_STACK + c->hadamard8_diff[0]= ff_hadamard8_diff16_sse2; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputilenc_yasm.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputilenc_yasm.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputilenc_yasm.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputilenc_yasm.asm 2012-05-14 14:08:54.515343624 +0200 +@@ -18,11 +18,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;***************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION .text + +@@ -59,12 +59,12 @@ + %endmacro + + %macro HADAMARD8 0 +- SUMSUB_BADC m0, m1, m2, m3 +- SUMSUB_BADC m4, m5, m6, m7 +- SUMSUB_BADC m0, m2, m1, m3 +- SUMSUB_BADC m4, m6, m5, m7 +- SUMSUB_BADC m0, m4, m1, m5 +- SUMSUB_BADC m2, m6, m3, m7 ++ SUMSUB_BADC w, 0, 1, 2, 3 ++ SUMSUB_BADC w, 4, 5, 6, 7 ++ SUMSUB_BADC w, 0, 2, 1, 3 ++ SUMSUB_BADC w, 4, 6, 5, 7 ++ SUMSUB_BADC w, 0, 4, 1, 5 ++ SUMSUB_BADC w, 2, 6, 3, 7 + %endmacro + + %macro ABS1_SUM 3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_mmx.c 2012-05-14 14:08:54.509343504 +0200 +@@ -31,6 +31,7 @@ + #include "libavcodec/ac3dec.h" + #include "dsputil_mmx.h" + #include "idct_xvid.h" ++#include "diracdsp_mmx.h" + + //#undef NDEBUG + //#include +@@ -42,7 +43,8 @@ + DECLARE_ALIGNED(16, const uint64_t, ff_pdw_80000000)[2] = + {0x8000000080000000ULL, 0x8000000080000000ULL}; + +-DECLARE_ALIGNED(8, const uint64_t, ff_pw_1 ) = 0x0001000100010001ULL; ++DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1 ) = {0x0001000100010001ULL, 0x0001000100010001ULL}; ++DECLARE_ALIGNED(16, const xmm_reg, ff_pw_2 ) = {0x0002000200020002ULL, 0x0002000200020002ULL}; + DECLARE_ALIGNED(16, const xmm_reg, ff_pw_3 ) = {0x0003000300030003ULL, 0x0003000300030003ULL}; + DECLARE_ALIGNED(16, const xmm_reg, ff_pw_4 ) = {0x0004000400040004ULL, 0x0004000400040004ULL}; + DECLARE_ALIGNED(16, const xmm_reg, ff_pw_5 ) = {0x0005000500050005ULL, 0x0005000500050005ULL}; +@@ -63,6 +65,8 @@ + DECLARE_ALIGNED(8, const uint64_t, ff_pw_96 ) = 0x0060006000600060ULL; + DECLARE_ALIGNED(8, const uint64_t, ff_pw_128) = 0x0080008000800080ULL; + DECLARE_ALIGNED(8, const uint64_t, ff_pw_255) = 0x00ff00ff00ff00ffULL; ++DECLARE_ALIGNED(16, const xmm_reg, ff_pw_512) = {0x0200020002000200ULL, 0x0200020002000200ULL}; ++DECLARE_ALIGNED(16, const xmm_reg, ff_pw_1019)= {0x03FB03FB03FB03FBULL, 0x03FB03FB03FB03FBULL}; + + DECLARE_ALIGNED(16, const xmm_reg, ff_pb_0 ) = {0x0000000000000000ULL, 0x0000000000000000ULL}; + DECLARE_ALIGNED(16, const xmm_reg, ff_pb_1 ) = {0x0101010101010101ULL, 0x0101010101010101ULL}; +@@ -286,9 +290,6 @@ + :"memory"); + } + +-DECLARE_ASM_CONST(8, uint8_t, ff_vector128)[8] = +- { 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80 }; +- + #define put_signed_pixels_clamped_mmx_half(off) \ + "movq "#off"(%2), %%mm1 \n\t"\ + "movq 16+"#off"(%2), %%mm2 \n\t"\ +@@ -313,7 +314,7 @@ + x86_reg line_skip3; + + __asm__ volatile ( +- "movq "MANGLE(ff_vector128)", %%mm0 \n\t" ++ "movq "MANGLE(ff_pb_80)", %%mm0 \n\t" + "lea (%3, %3, 2), %1 \n\t" + put_signed_pixels_clamped_mmx_half(0) + "lea (%0, %3, 4), %0 \n\t" +@@ -458,12 +459,12 @@ + "movdqu (%1,%3), %%xmm1 \n\t" + "movdqu (%1,%3,2), %%xmm2 \n\t" + "movdqu (%1,%4), %%xmm3 \n\t" ++ "lea (%1,%3,4), %1 \n\t" + "movdqa %%xmm0, (%2) \n\t" + "movdqa %%xmm1, (%2,%3) \n\t" + "movdqa %%xmm2, (%2,%3,2) \n\t" + "movdqa %%xmm3, (%2,%4) \n\t" + "subl $4, %0 \n\t" +- "lea (%1,%3,4), %1 \n\t" + "lea (%2,%3,4), %2 \n\t" + "jnz 1b \n\t" + : "+g"(h), "+r" (pixels), "+r" (block) +@@ -480,6 +481,7 @@ + "movdqu (%1,%3), %%xmm1 \n\t" + "movdqu (%1,%3,2), %%xmm2 \n\t" + "movdqu (%1,%4), %%xmm3 \n\t" ++ "lea (%1,%3,4), %1 \n\t" + "pavgb (%2), %%xmm0 \n\t" + "pavgb (%2,%3), %%xmm1 \n\t" + "pavgb (%2,%3,2), %%xmm2 \n\t" +@@ -489,7 +491,6 @@ + "movdqa %%xmm2, (%2,%3,2) \n\t" + "movdqa %%xmm3, (%2,%4) \n\t" + "subl $4, %0 \n\t" +- "lea (%1,%3,4), %1 \n\t" + "lea (%2,%3,4), %2 \n\t" + "jnz 1b \n\t" + : "+g"(h), "+r" (pixels), "+r" (block) +@@ -582,29 +583,7 @@ + dst[i+0] += src[i+0]; + } + +-static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w){ +- x86_reg i=0; +- __asm__ volatile( +- "jmp 2f \n\t" +- "1: \n\t" +- "movq (%2, %0), %%mm0 \n\t" +- "movq 8(%2, %0), %%mm1 \n\t" +- "paddb (%3, %0), %%mm0 \n\t" +- "paddb 8(%3, %0), %%mm1 \n\t" +- "movq %%mm0, (%1, %0) \n\t" +- "movq %%mm1, 8(%1, %0) \n\t" +- "add $16, %0 \n\t" +- "2: \n\t" +- "cmp %4, %0 \n\t" +- " js 1b \n\t" +- : "+r" (i) +- : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15) +- ); +- for(; ibits_per_raw_sample > 8; ++ const int bit_depth = avctx->bits_per_raw_sample; + + if (avctx->dsp_mask) { + if (avctx->dsp_mask & AV_CPU_FLAG_FORCE) +@@ -2436,7 +2443,7 @@ + if (mm_flags & AV_CPU_FLAG_MMX) { + const int idct_algo= avctx->idct_algo; + +- if(avctx->lowres==0){ ++ if (avctx->lowres == 0 && avctx->bits_per_raw_sample <= 8) { + if(idct_algo==FF_IDCT_AUTO || idct_algo==FF_IDCT_SIMPLEMMX){ + c->idct_put= ff_simple_idct_put_mmx; + c->idct_add= ff_simple_idct_add_mmx; +@@ -2491,6 +2498,7 @@ + c->put_pixels_clamped = ff_put_pixels_clamped_mmx; + c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_mmx; + c->add_pixels_clamped = ff_add_pixels_clamped_mmx; ++ if (!high_bit_depth) { + c->clear_block = clear_block_mmx; + c->clear_blocks = clear_blocks_mmx; + if ((mm_flags & AV_CPU_FLAG_SSE) && +@@ -2499,6 +2507,7 @@ + c->clear_block = clear_block_sse; + c->clear_blocks = clear_blocks_sse; + } ++ } + + #define SET_HPEL_FUNCS(PFX, IDX, SIZE, CPU) \ + c->PFX ## _pixels_tab[IDX][0] = PFX ## _pixels ## SIZE ## _ ## CPU; \ +@@ -2506,6 +2515,7 @@ + c->PFX ## _pixels_tab[IDX][2] = PFX ## _pixels ## SIZE ## _y2_ ## CPU; \ + c->PFX ## _pixels_tab[IDX][3] = PFX ## _pixels ## SIZE ## _xy2_ ## CPU + ++ if (!high_bit_depth) { + SET_HPEL_FUNCS(put, 0, 16, mmx); + SET_HPEL_FUNCS(put_no_rnd, 0, 16, mmx); + SET_HPEL_FUNCS(avg, 0, 16, mmx); +@@ -2514,18 +2524,23 @@ + SET_HPEL_FUNCS(put_no_rnd, 1, 8, mmx); + SET_HPEL_FUNCS(avg, 1, 8, mmx); + SET_HPEL_FUNCS(avg_no_rnd, 1, 8, mmx); ++ } + + #if ARCH_X86_32 || !HAVE_YASM + c->gmc= gmc_mmx; + #endif + #if ARCH_X86_32 && HAVE_YASM ++ if (!high_bit_depth) + c->emulated_edge_mc = emulated_edge_mc_mmx; + #endif + + c->add_bytes= add_bytes_mmx; +- c->add_bytes_l2= add_bytes_l2_mmx; + +- c->draw_edges = draw_edges_mmx; ++ if (!high_bit_depth) ++ c->draw_edges = draw_edges_mmx; ++ ++ c->put_no_rnd_pixels_l2[0]= put_vp_no_rnd_pixels16_l2_mmx; ++ c->put_no_rnd_pixels_l2[1]= put_vp_no_rnd_pixels8_l2_mmx; + + if (CONFIG_H263_DECODER || CONFIG_H263_ENCODER) { + c->h263_v_loop_filter= h263_v_loop_filter_mmx; +@@ -2533,17 +2548,18 @@ + } + + #if HAVE_YASM ++ if (!high_bit_depth && CONFIG_H264CHROMA) { + c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_mmx_rnd; + c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_mmx; +- c->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_mmx_nornd; ++ } + +- c->put_rv40_chroma_pixels_tab[0]= ff_put_rv40_chroma_mc8_mmx; +- c->put_rv40_chroma_pixels_tab[1]= ff_put_rv40_chroma_mc4_mmx; ++ c->vector_clip_int32 = ff_vector_clip_int32_mmx; + #endif + + if (mm_flags & AV_CPU_FLAG_MMX2) { + c->prefetch = prefetch_mmx2; + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][1] = put_pixels16_x2_mmx2; + c->put_pixels_tab[0][2] = put_pixels16_y2_mmx2; + +@@ -2557,14 +2573,17 @@ + c->avg_pixels_tab[1][0] = avg_pixels8_mmx2; + c->avg_pixels_tab[1][1] = avg_pixels8_x2_mmx2; + c->avg_pixels_tab[1][2] = avg_pixels8_y2_mmx2; ++ } + + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ ++ if (!high_bit_depth) { + c->put_no_rnd_pixels_tab[0][1] = put_no_rnd_pixels16_x2_mmx2; + c->put_no_rnd_pixels_tab[0][2] = put_no_rnd_pixels16_y2_mmx2; + c->put_no_rnd_pixels_tab[1][1] = put_no_rnd_pixels8_x2_mmx2; + c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_mmx2; + c->avg_pixels_tab[0][3] = avg_pixels16_xy2_mmx2; + c->avg_pixels_tab[1][3] = avg_pixels8_xy2_mmx2; ++ } + + if (CONFIG_VP3_DECODER && HAVE_YASM) { + c->vp3_v_loop_filter= ff_vp3_v_loop_filter_mmx2; +@@ -2581,68 +2600,82 @@ + c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_mmx2; + } + +-#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU) \ +- c->PFX ## _pixels_tab[IDX][ 0] = PFX ## SIZE ## _mc00_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 1] = PFX ## SIZE ## _mc10_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 2] = PFX ## SIZE ## _mc20_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 3] = PFX ## SIZE ## _mc30_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 4] = PFX ## SIZE ## _mc01_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 5] = PFX ## SIZE ## _mc11_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 6] = PFX ## SIZE ## _mc21_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 7] = PFX ## SIZE ## _mc31_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 8] = PFX ## SIZE ## _mc02_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][ 9] = PFX ## SIZE ## _mc12_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][10] = PFX ## SIZE ## _mc22_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][11] = PFX ## SIZE ## _mc32_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][12] = PFX ## SIZE ## _mc03_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][13] = PFX ## SIZE ## _mc13_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][14] = PFX ## SIZE ## _mc23_ ## CPU; \ +- c->PFX ## _pixels_tab[IDX][15] = PFX ## SIZE ## _mc33_ ## CPU +- +- SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2); +- SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2); +- SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2); +- +- SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2); +- SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2); +- SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2); +- SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2); +- +- SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2); +- SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2); +- SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2); +- ++#define SET_QPEL_FUNCS(PFX, IDX, SIZE, CPU, PREFIX) \ ++ c->PFX ## _pixels_tab[IDX][ 0] = PREFIX ## PFX ## SIZE ## _mc00_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 1] = PREFIX ## PFX ## SIZE ## _mc10_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 2] = PREFIX ## PFX ## SIZE ## _mc20_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 3] = PREFIX ## PFX ## SIZE ## _mc30_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 4] = PREFIX ## PFX ## SIZE ## _mc01_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 5] = PREFIX ## PFX ## SIZE ## _mc11_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 6] = PREFIX ## PFX ## SIZE ## _mc21_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 7] = PREFIX ## PFX ## SIZE ## _mc31_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 8] = PREFIX ## PFX ## SIZE ## _mc02_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][ 9] = PREFIX ## PFX ## SIZE ## _mc12_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][10] = PREFIX ## PFX ## SIZE ## _mc22_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][11] = PREFIX ## PFX ## SIZE ## _mc32_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][12] = PREFIX ## PFX ## SIZE ## _mc03_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][13] = PREFIX ## PFX ## SIZE ## _mc13_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][14] = PREFIX ## PFX ## SIZE ## _mc23_ ## CPU; \ ++ c->PFX ## _pixels_tab[IDX][15] = PREFIX ## PFX ## SIZE ## _mc33_ ## CPU ++ ++ SET_QPEL_FUNCS(put_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(put_qpel, 1, 8, mmx2, ); ++ SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, mmx2, ); ++ SET_QPEL_FUNCS(avg_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(avg_qpel, 1, 8, mmx2, ); ++ ++ if (!high_bit_depth) { ++ SET_QPEL_FUNCS(put_h264_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(put_h264_qpel, 1, 8, mmx2, ); ++ SET_QPEL_FUNCS(put_h264_qpel, 2, 4, mmx2, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, mmx2, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, mmx2, ); ++ } ++ else if (bit_depth == 10) { + #if HAVE_YASM +- c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_mmx2; +- c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_mmx2; ++#if !ARCH_X86_64 ++ SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_mmxext, ff_); ++ SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_mmxext, ff_); ++ SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_mmxext, ff_); ++ SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_mmxext, ff_); ++#endif ++ SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 10_mmxext, ff_); ++ SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 10_mmxext, ff_); ++#endif ++ } + +- c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_mmx2_nornd; ++ SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, mmx2, ); ++ SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, mmx2, ); ++ SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, mmx2, ); + ++#if HAVE_YASM ++ if (!high_bit_depth && CONFIG_H264CHROMA) { + c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_mmx2_rnd; + c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_mmx2; + c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_mmx2; + c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_mmx2; ++ } ++ if (bit_depth == 10 && CONFIG_H264CHROMA) { ++ c->put_h264_chroma_pixels_tab[2]= ff_put_h264_chroma_mc2_10_mmxext; ++ c->avg_h264_chroma_pixels_tab[2]= ff_avg_h264_chroma_mc2_10_mmxext; ++ c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_10_mmxext; ++ c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_10_mmxext; ++ } + + c->add_hfyu_median_prediction = ff_add_hfyu_median_prediction_mmx2; + #endif +-#if HAVE_7REGS && HAVE_TEN_OPERANDS +- if( mm_flags&AV_CPU_FLAG_3DNOW ) ++#if HAVE_7REGS ++ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) + c->add_hfyu_median_prediction = add_hfyu_median_prediction_cmov; + #endif + +- if (CONFIG_VC1_DECODER) +- ff_vc1dsp_init_mmx(c, avctx); +- +- c->add_png_paeth_prediction= add_png_paeth_prediction_mmx2; +- } else if (mm_flags & AV_CPU_FLAG_3DNOW) { ++ } else if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) { + c->prefetch = prefetch_3dnow; + ++ if (!high_bit_depth) { + c->put_pixels_tab[0][1] = put_pixels16_x2_3dnow; + c->put_pixels_tab[0][2] = put_pixels16_y2_3dnow; + +@@ -2665,6 +2698,7 @@ + c->avg_pixels_tab[0][3] = avg_pixels16_xy2_3dnow; + c->avg_pixels_tab[1][3] = avg_pixels8_xy2_3dnow; + } ++ } + + if (CONFIG_VP3_DECODER + && (avctx->codec_id == CODEC_ID_VP3 || avctx->codec_id == CODEC_ID_THEORA)) { +@@ -2672,33 +2706,33 @@ + c->put_no_rnd_pixels_tab[1][2] = put_no_rnd_pixels8_y2_exact_3dnow; + } + +- SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow); +- SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow); +- SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow); +- +- SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow); +- SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow); +- SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow); +- SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow); +- +- SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow); +- SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow); +- SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow); ++ SET_QPEL_FUNCS(put_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(put_qpel, 1, 8, 3dnow, ); ++ SET_QPEL_FUNCS(put_no_rnd_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(put_no_rnd_qpel, 1, 8, 3dnow, ); ++ SET_QPEL_FUNCS(avg_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(avg_qpel, 1, 8, 3dnow, ); ++ ++ if (!high_bit_depth) { ++ SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 3dnow, ); ++ SET_QPEL_FUNCS(put_h264_qpel, 2, 4, 3dnow, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 3dnow, ); ++ SET_QPEL_FUNCS(avg_h264_qpel, 2, 4, 3dnow, ); ++ } ++ ++ SET_QPEL_FUNCS(put_2tap_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(put_2tap_qpel, 1, 8, 3dnow, ); ++ SET_QPEL_FUNCS(avg_2tap_qpel, 0, 16, 3dnow, ); ++ SET_QPEL_FUNCS(avg_2tap_qpel, 1, 8, 3dnow, ); + + #if HAVE_YASM ++ if (!high_bit_depth && CONFIG_H264CHROMA) { + c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_3dnow_rnd; + c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_3dnow; ++ } + +- c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_3dnow_nornd; +- +- c->avg_rv40_chroma_pixels_tab[0]= ff_avg_rv40_chroma_mc8_3dnow; +- c->avg_rv40_chroma_pixels_tab[1]= ff_avg_rv40_chroma_mc4_3dnow; + #endif + } + +@@ -2710,27 +2744,53 @@ + c->avg_h264_qpel_pixels_tab[1][x+y*4] = avg_h264_qpel8_mc##x##y##_##CPU; + if((mm_flags & AV_CPU_FLAG_SSE2) && !(mm_flags & AV_CPU_FLAG_3DNOW)){ + // these functions are slower than mmx on AMD, but faster on Intel ++ if (!high_bit_depth) { + c->put_pixels_tab[0][0] = put_pixels16_sse2; + c->put_no_rnd_pixels_tab[0][0] = put_pixels16_sse2; + c->avg_pixels_tab[0][0] = avg_pixels16_sse2; + H264_QPEL_FUNCS(0, 0, sse2); ++ } + } + if(mm_flags & AV_CPU_FLAG_SSE2){ +- H264_QPEL_FUNCS(0, 1, sse2); +- H264_QPEL_FUNCS(0, 2, sse2); +- H264_QPEL_FUNCS(0, 3, sse2); +- H264_QPEL_FUNCS(1, 1, sse2); +- H264_QPEL_FUNCS(1, 2, sse2); +- H264_QPEL_FUNCS(1, 3, sse2); +- H264_QPEL_FUNCS(2, 1, sse2); +- H264_QPEL_FUNCS(2, 2, sse2); +- H264_QPEL_FUNCS(2, 3, sse2); +- H264_QPEL_FUNCS(3, 1, sse2); +- H264_QPEL_FUNCS(3, 2, sse2); +- H264_QPEL_FUNCS(3, 3, sse2); ++ if (!high_bit_depth) { ++ H264_QPEL_FUNCS(0, 1, sse2); ++ H264_QPEL_FUNCS(0, 2, sse2); ++ H264_QPEL_FUNCS(0, 3, sse2); ++ H264_QPEL_FUNCS(1, 1, sse2); ++ H264_QPEL_FUNCS(1, 2, sse2); ++ H264_QPEL_FUNCS(1, 3, sse2); ++ H264_QPEL_FUNCS(2, 1, sse2); ++ H264_QPEL_FUNCS(2, 2, sse2); ++ H264_QPEL_FUNCS(2, 3, sse2); ++ H264_QPEL_FUNCS(3, 1, sse2); ++ H264_QPEL_FUNCS(3, 2, sse2); ++ H264_QPEL_FUNCS(3, 3, sse2); ++ } ++#if HAVE_YASM ++#define H264_QPEL_FUNCS_10(x, y, CPU)\ ++ c->put_h264_qpel_pixels_tab[0][x+y*4] = ff_put_h264_qpel16_mc##x##y##_10_##CPU;\ ++ c->put_h264_qpel_pixels_tab[1][x+y*4] = ff_put_h264_qpel8_mc##x##y##_10_##CPU;\ ++ c->avg_h264_qpel_pixels_tab[0][x+y*4] = ff_avg_h264_qpel16_mc##x##y##_10_##CPU;\ ++ c->avg_h264_qpel_pixels_tab[1][x+y*4] = ff_avg_h264_qpel8_mc##x##y##_10_##CPU; ++ if (bit_depth == 10) { ++ SET_QPEL_FUNCS(put_h264_qpel, 0, 16, 10_sse2, ff_); ++ SET_QPEL_FUNCS(put_h264_qpel, 1, 8, 10_sse2, ff_); ++ SET_QPEL_FUNCS(avg_h264_qpel, 0, 16, 10_sse2, ff_); ++ SET_QPEL_FUNCS(avg_h264_qpel, 1, 8, 10_sse2, ff_); ++ H264_QPEL_FUNCS_10(1, 0, sse2_cache64) ++ H264_QPEL_FUNCS_10(2, 0, sse2_cache64) ++ H264_QPEL_FUNCS_10(3, 0, sse2_cache64) ++ ++ if (CONFIG_H264CHROMA) { ++ c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_sse2; ++ c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_sse2; ++ } ++ } ++#endif + } + #if HAVE_SSSE3 + if(mm_flags & AV_CPU_FLAG_SSSE3){ ++ if (!high_bit_depth) { + H264_QPEL_FUNCS(1, 0, ssse3); + H264_QPEL_FUNCS(1, 1, ssse3); + H264_QPEL_FUNCS(1, 2, ssse3); +@@ -2743,14 +2803,19 @@ + H264_QPEL_FUNCS(3, 1, ssse3); + H264_QPEL_FUNCS(3, 2, ssse3); + H264_QPEL_FUNCS(3, 3, ssse3); +- c->add_png_paeth_prediction= add_png_paeth_prediction_ssse3; ++ } + #if HAVE_YASM +- c->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_ssse3_nornd; +- c->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_ssse3_nornd; ++ else if (bit_depth == 10) { ++ H264_QPEL_FUNCS_10(1, 0, ssse3_cache64) ++ H264_QPEL_FUNCS_10(2, 0, ssse3_cache64) ++ H264_QPEL_FUNCS_10(3, 0, ssse3_cache64) ++ } ++ if (!high_bit_depth && CONFIG_H264CHROMA) { + c->put_h264_chroma_pixels_tab[0]= ff_put_h264_chroma_mc8_ssse3_rnd; + c->avg_h264_chroma_pixels_tab[0]= ff_avg_h264_chroma_mc8_ssse3_rnd; + c->put_h264_chroma_pixels_tab[1]= ff_put_h264_chroma_mc4_ssse3; + c->avg_h264_chroma_pixels_tab[1]= ff_avg_h264_chroma_mc4_ssse3; ++ } + c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_ssse3; + if (mm_flags & AV_CPU_FLAG_SSE4) // not really sse4, just slow on Conroe + c->add_hfyu_left_prediction = ff_add_hfyu_left_prediction_sse4; +@@ -2758,11 +2823,11 @@ + } + #endif + +- if(mm_flags & AV_CPU_FLAG_3DNOW){ ++ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) { + c->vorbis_inverse_coupling = vorbis_inverse_coupling_3dnow; + c->vector_fmul = vector_fmul_3dnow; + } +- if(mm_flags & AV_CPU_FLAG_3DNOWEXT){ ++ if (HAVE_AMD3DNOWEXT && (mm_flags & AV_CPU_FLAG_3DNOWEXT)) { + c->vector_fmul_reverse = vector_fmul_reverse_3dnow2; + #if HAVE_6REGS + c->vector_fmul_window = vector_fmul_window_3dnow2; +@@ -2772,6 +2837,11 @@ + #if HAVE_YASM + c->scalarproduct_int16 = ff_scalarproduct_int16_mmx2; + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_mmx2; ++ if (avctx->flags & CODEC_FLAG_BITEXACT) { ++ c->apply_window_int16 = ff_apply_window_int16_mmxext_ba; ++ } else { ++ c->apply_window_int16 = ff_apply_window_int16_mmxext; ++ } + #endif + } + if(mm_flags & AV_CPU_FLAG_SSE){ +@@ -2786,58 +2856,71 @@ + c->vector_clipf = vector_clipf_sse; + #if HAVE_YASM + c->scalarproduct_float = ff_scalarproduct_float_sse; ++ c->butterflies_float_interleave = ff_butterflies_float_interleave_sse; ++ ++ if (!high_bit_depth) ++ c->emulated_edge_mc = emulated_edge_mc_sse; ++ c->gmc = gmc_sse; + #endif + } +- if(mm_flags & AV_CPU_FLAG_3DNOW) ++ if (HAVE_AMD3DNOW && (mm_flags & AV_CPU_FLAG_3DNOW)) + c->vector_fmul_add = vector_fmul_add_3dnow; // faster than sse + if(mm_flags & AV_CPU_FLAG_SSE2){ + #if HAVE_YASM + c->scalarproduct_int16 = ff_scalarproduct_int16_sse2; + c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_sse2; ++ if (mm_flags & AV_CPU_FLAG_ATOM) { ++ c->vector_clip_int32 = ff_vector_clip_int32_int_sse2; ++ } else { ++ c->vector_clip_int32 = ff_vector_clip_int32_sse2; ++ } ++ if (avctx->flags & CODEC_FLAG_BITEXACT) { ++ c->apply_window_int16 = ff_apply_window_int16_sse2_ba; ++ } else { ++ if (!(mm_flags & AV_CPU_FLAG_SSE2SLOW)) { ++ c->apply_window_int16 = ff_apply_window_int16_sse2; ++ } ++ } ++#endif ++ } ++ if (mm_flags & AV_CPU_FLAG_SSSE3) { ++#if HAVE_YASM ++ if (mm_flags & AV_CPU_FLAG_ATOM) { ++ c->apply_window_int16 = ff_apply_window_int16_ssse3_atom; ++ } else { ++ c->apply_window_int16 = ff_apply_window_int16_ssse3; ++ } ++ if (!(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW))) { // cachesplit ++ c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3; ++ } ++#endif ++ } + +- c->emulated_edge_mc = emulated_edge_mc_sse; +- c->gmc= gmc_sse; ++ if (mm_flags & AV_CPU_FLAG_SSE4 && HAVE_SSE) { ++#if HAVE_YASM ++ c->vector_clip_int32 = ff_vector_clip_int32_sse4; + #endif + } +- if((mm_flags & AV_CPU_FLAG_SSSE3) && !(mm_flags & (AV_CPU_FLAG_SSE42|AV_CPU_FLAG_3DNOW)) && HAVE_YASM) // cachesplit +- c->scalarproduct_and_madd_int16 = ff_scalarproduct_and_madd_int16_ssse3; ++ ++#if HAVE_AVX && HAVE_YASM ++ if (mm_flags & AV_CPU_FLAG_AVX) { ++ if (bit_depth == 10) { ++ //AVX implies !cache64. ++ //TODO: Port cache(32|64) detection from x264. ++ H264_QPEL_FUNCS_10(1, 0, sse2) ++ H264_QPEL_FUNCS_10(2, 0, sse2) ++ H264_QPEL_FUNCS_10(3, 0, sse2) ++ ++ if (CONFIG_H264CHROMA) { ++ c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_10_avx; ++ c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_10_avx; ++ } ++ } ++ c->butterflies_float_interleave = ff_butterflies_float_interleave_avx; ++ } ++#endif + } + + if (CONFIG_ENCODERS) + dsputilenc_init_mmx(c, avctx); +- +-#if 0 +- // for speed testing +- get_pixels = just_return; +- put_pixels_clamped = just_return; +- add_pixels_clamped = just_return; +- +- pix_abs16x16 = just_return; +- pix_abs16x16_x2 = just_return; +- pix_abs16x16_y2 = just_return; +- pix_abs16x16_xy2 = just_return; +- +- put_pixels_tab[0] = just_return; +- put_pixels_tab[1] = just_return; +- put_pixels_tab[2] = just_return; +- put_pixels_tab[3] = just_return; +- +- put_no_rnd_pixels_tab[0] = just_return; +- put_no_rnd_pixels_tab[1] = just_return; +- put_no_rnd_pixels_tab[2] = just_return; +- put_no_rnd_pixels_tab[3] = just_return; +- +- avg_pixels_tab[0] = just_return; +- avg_pixels_tab[1] = just_return; +- avg_pixels_tab[2] = just_return; +- avg_pixels_tab[3] = just_return; +- +- avg_no_rnd_pixels_tab[0] = just_return; +- avg_no_rnd_pixels_tab[1] = just_return; +- avg_no_rnd_pixels_tab[2] = just_return; +- avg_no_rnd_pixels_tab[3] = just_return; +- +- //av_fdct = just_return; +- //ff_idct = just_return; +-#endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_mmx.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_mmx.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_mmx.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_mmx.h 2012-05-14 14:08:54.510343524 +0200 +@@ -196,7 +196,6 @@ + void ff_put_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); + void ff_avg_cavs_qpel16_mc00_mmx2(uint8_t *dst, uint8_t *src, int stride); + +-void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx); + void ff_put_vc1_mspel_mc00_mmx(uint8_t *dst, const uint8_t *src, int stride, int rnd); + void ff_avg_vc1_mspel_mc00_mmx2(uint8_t *dst, const uint8_t *src, int stride, int rnd); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_yasm.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_yasm.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dsputil_yasm.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dsputil_yasm.asm 2012-05-14 14:08:54.512343564 +0200 +@@ -16,10 +16,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "x86util.asm" + + SECTION_RODATA + pb_f: times 16 db 15 +@@ -27,8 +28,10 @@ + pb_7: times 8 db 7 + pb_zzzz3333zzzzbbbb: db -1,-1,-1,-1,3,3,3,3,-1,-1,-1,-1,11,11,11,11 + pb_zz11zz55zz99zzdd: db -1,-1,1,1,-1,-1,5,5,-1,-1,9,9,-1,-1,13,13 ++pb_revwords: db 14, 15, 12, 13, 10, 11, 8, 9, 6, 7, 4, 5, 2, 3, 0, 1 ++pd_16384: times 4 dd 16384 + +-section .text align=16 ++SECTION_TEXT + + %macro SCALARPRODUCT 1 + ; int scalarproduct_int16(int16_t *v1, int16_t *v2, int order, int shift) +@@ -202,6 +205,130 @@ + RET + + ++;----------------------------------------------------------------------------- ++; void ff_apply_window_int16(int16_t *output, const int16_t *input, ++; const int16_t *window, unsigned int len) ++;----------------------------------------------------------------------------- ++ ++%macro REVERSE_WORDS_MMXEXT 1-2 ++ pshufw %1, %1, 0x1B ++%endmacro ++ ++%macro REVERSE_WORDS_SSE2 1-2 ++ pshuflw %1, %1, 0x1B ++ pshufhw %1, %1, 0x1B ++ pshufd %1, %1, 0x4E ++%endmacro ++ ++%macro REVERSE_WORDS_SSSE3 2 ++ pshufb %1, %2 ++%endmacro ++ ++; dst = (dst * src) >> 15 ++; pmulhw cuts off the bottom bit, so we have to lshift by 1 and add it back ++; in from the pmullw result. ++%macro MUL16FIXED_MMXEXT 3 ; dst, src, temp ++ mova %3, %1 ++ pmulhw %1, %2 ++ pmullw %3, %2 ++ psrlw %3, 15 ++ psllw %1, 1 ++ por %1, %3 ++%endmacro ++ ++; dst = ((dst * src) + (1<<14)) >> 15 ++%macro MUL16FIXED_SSSE3 3 ; dst, src, unused ++ pmulhrsw %1, %2 ++%endmacro ++ ++%macro APPLY_WINDOW_INT16 3 ; %1=instruction set, %2=mmxext/sse2 bit exact version, %3=has_ssse3 ++cglobal apply_window_int16_%1, 4,5,6, output, input, window, offset, offset2 ++ lea offset2q, [offsetq-mmsize] ++%if %2 ++ mova m5, [pd_16384] ++%elifidn %1, ssse3 ++ mova m5, [pb_revwords] ++ ALIGN 16 ++%endif ++.loop: ++%if %2 ++ ; This version expands 16-bit to 32-bit, multiplies by the window, ++ ; adds 16384 for rounding, right shifts 15, then repacks back to words to ++ ; save to the output. The window is reversed for the second half. ++ mova m3, [windowq+offset2q] ++ mova m4, [ inputq+offset2q] ++ pxor m0, m0 ++ punpcklwd m0, m3 ++ punpcklwd m1, m4 ++ pmaddwd m0, m1 ++ paddd m0, m5 ++ psrad m0, 15 ++ pxor m2, m2 ++ punpckhwd m2, m3 ++ punpckhwd m1, m4 ++ pmaddwd m2, m1 ++ paddd m2, m5 ++ psrad m2, 15 ++ packssdw m0, m2 ++ mova [outputq+offset2q], m0 ++ REVERSE_WORDS m3 ++ mova m4, [ inputq+offsetq] ++ pxor m0, m0 ++ punpcklwd m0, m3 ++ punpcklwd m1, m4 ++ pmaddwd m0, m1 ++ paddd m0, m5 ++ psrad m0, 15 ++ pxor m2, m2 ++ punpckhwd m2, m3 ++ punpckhwd m1, m4 ++ pmaddwd m2, m1 ++ paddd m2, m5 ++ psrad m2, 15 ++ packssdw m0, m2 ++ mova [outputq+offsetq], m0 ++%elif %3 ++ ; This version does the 16x16->16 multiplication in-place without expanding ++ ; to 32-bit. The ssse3 version is bit-identical. ++ mova m0, [windowq+offset2q] ++ mova m1, [ inputq+offset2q] ++ pmulhrsw m1, m0 ++ REVERSE_WORDS m0, m5 ++ pmulhrsw m0, [ inputq+offsetq ] ++ mova [outputq+offset2q], m1 ++ mova [outputq+offsetq ], m0 ++%else ++ ; This version does the 16x16->16 multiplication in-place without expanding ++ ; to 32-bit. The mmxext and sse2 versions do not use rounding, and ++ ; therefore are not bit-identical to the C version. ++ mova m0, [windowq+offset2q] ++ mova m1, [ inputq+offset2q] ++ mova m2, [ inputq+offsetq ] ++ MUL16FIXED m1, m0, m3 ++ REVERSE_WORDS m0 ++ MUL16FIXED m2, m0, m3 ++ mova [outputq+offset2q], m1 ++ mova [outputq+offsetq ], m2 ++%endif ++ add offsetd, mmsize ++ sub offset2d, mmsize ++ jae .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++%define REVERSE_WORDS REVERSE_WORDS_MMXEXT ++%define MUL16FIXED MUL16FIXED_MMXEXT ++APPLY_WINDOW_INT16 mmxext, 0, 0 ++APPLY_WINDOW_INT16 mmxext_ba, 1, 0 ++INIT_XMM ++%define REVERSE_WORDS REVERSE_WORDS_SSE2 ++APPLY_WINDOW_INT16 sse2, 0, 0 ++APPLY_WINDOW_INT16 sse2_ba, 1, 0 ++APPLY_WINDOW_INT16 ssse3_atom, 0, 1 ++%define REVERSE_WORDS REVERSE_WORDS_SSSE3 ++APPLY_WINDOW_INT16 ssse3, 0, 1 ++ + + ; void add_hfyu_median_prediction_mmx2(uint8_t *dst, const uint8_t *top, const uint8_t *diff, int w, int *left, int *left_top) + cglobal add_hfyu_median_prediction_mmx2, 6,6,0, dst, top, diff, w, left, left_top +@@ -370,14 +497,14 @@ + ; ... and then the same for left/right extend also. See below for loop + ; function implementations. Fast are fixed-width, slow is variable-width + +-%macro EMU_EDGE_FUNC 1 ++%macro EMU_EDGE_FUNC 0 + %ifdef ARCH_X86_64 + %define w_reg r10 +-cglobal emu_edge_core_%1, 6, 7, 1 ++cglobal emu_edge_core, 6, 7, 1 + mov r11, r5 ; save block_h + %else + %define w_reg r6 +-cglobal emu_edge_core_%1, 2, 7, 0 ++cglobal emu_edge_core, 2, 7, 0 + mov r4, r4m ; end_y + mov r5, r5m ; block_h + %endif +@@ -468,6 +595,11 @@ + %define valw ax + %define valw2 r10w + %define valw3 r3w ++%ifdef WIN64 ++%define valw4 r4w ++%else ; unix64 ++%define valw4 r3w ++%endif + %define vald eax + %else + %define vall bl +@@ -475,6 +607,7 @@ + %define valw bx + %define valw2 r6w + %define valw3 valw2 ++%define valw4 valw3 + %define vald ebx + %define stack_offset 0x14 + %endif +@@ -497,18 +630,18 @@ + ; - if (%2 & 3 == 3) fills 2 bytes into r6, and 1 into ebx + ; - else fills remaining bytes into ebx + ; writing data out is in the same way +-%macro READ_NUM_BYTES 3 ++%macro READ_NUM_BYTES 2 + %assign %%src_off 0 ; offset in source buffer + %assign %%smidx 0 ; mmx register idx + %assign %%sxidx 0 ; xmm register idx + +-%ifnidn %3, mmx ++%if cpuflag(sse) + %rep %2/16 +- movdqu xmm %+ %%sxidx, [r1+%%src_off] ++ movups xmm %+ %%sxidx, [r1+%%src_off] + %assign %%src_off %%src_off+16 + %assign %%sxidx %%sxidx+1 + %endrep ; %2/16 +-%endif ; !mmx ++%endif + + %ifdef ARCH_X86_64 + %if (%2-%%src_off) == 8 +@@ -537,21 +670,23 @@ + %elif (%2-%%src_off) == 3 + %ifidn %1, top + mov valw2, [r1+%%src_off] +-%else ; %1 != top ++%elifidn %1, body + mov valw3, [r1+%%src_off] ++%elifidn %1, bottom ++ mov valw4, [r1+%%src_off] + %endif ; %1 ==/!= top + mov vall, [r1+%%src_off+2] + %endif ; (%2-%%src_off) == 1/2/3 + %endmacro ; READ_NUM_BYTES + +-%macro WRITE_NUM_BYTES 3 ++%macro WRITE_NUM_BYTES 2 + %assign %%dst_off 0 ; offset in destination buffer + %assign %%dmidx 0 ; mmx register idx + %assign %%dxidx 0 ; xmm register idx + +-%ifnidn %3, mmx ++%if cpuflag(sse) + %rep %2/16 +- movdqu [r0+%%dst_off], xmm %+ %%dxidx ++ movups [r0+%%dst_off], xmm %+ %%dxidx + %assign %%dst_off %%dst_off+16 + %assign %%dxidx %%dxidx+1 + %endrep ; %2/16 +@@ -584,8 +719,10 @@ + %elif (%2-%%dst_off) == 3 + %ifidn %1, top + mov [r0+%%dst_off], valw2 +-%else ; %1 != top ++%elifidn %1, body + mov [r0+%%dst_off], valw3 ++%elifidn %1, bottom ++ mov [r0+%%dst_off], valw4 + %endif ; %1 ==/!= top + mov [r0+%%dst_off+2], vall + %endif ; (%2-%%dst_off) == 1/2/3 +@@ -597,7 +734,7 @@ + ; those out into the destination buffer + ; r0=buf,r1=src,r2=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h + ; r6(eax/64)/r3(ebx/32)=val_reg +-%macro VERTICAL_EXTEND 1 ++%macro VERTICAL_EXTEND 0 + %assign %%n 1 + %rep 22 + ALIGN 128 +@@ -610,12 +747,12 @@ + cmp dword r3m, 0 + je .emuedge_copy_body_ %+ %%n %+ _loop + %endif ; ARCH_X86_64/32 +- READ_NUM_BYTES top, %%n, %1 ; read bytes ++ READ_NUM_BYTES top, %%n ; read bytes + .emuedge_extend_top_ %+ %%n %+ _loop: ; do { +- WRITE_NUM_BYTES top, %%n, %1 ; write bytes ++ WRITE_NUM_BYTES top, %%n ; write bytes + add r0 , r2 ; dst += linesize + %ifdef ARCH_X86_64 +- dec r3 ++ dec r3d + %else ; ARCH_X86_32 + dec dword r3m + %endif ; ARCH_X86_64/32 +@@ -623,22 +760,22 @@ + + ; copy body pixels + .emuedge_copy_body_ %+ %%n %+ _loop: ; do { +- READ_NUM_BYTES body, %%n, %1 ; read bytes +- WRITE_NUM_BYTES body, %%n, %1 ; write bytes ++ READ_NUM_BYTES body, %%n ; read bytes ++ WRITE_NUM_BYTES body, %%n ; write bytes + add r0 , r2 ; dst += linesize + add r1 , r2 ; src += linesize +- dec r4 ++ dec r4d + jnz .emuedge_copy_body_ %+ %%n %+ _loop ; } while (--end_y) + + ; copy bottom pixels + test r5 , r5 ; if (!block_h) + jz .emuedge_v_extend_end_ %+ %%n ; goto end + sub r1 , r2 ; src -= linesize +- READ_NUM_BYTES bottom, %%n, %1 ; read bytes ++ READ_NUM_BYTES bottom, %%n ; read bytes + .emuedge_extend_bottom_ %+ %%n %+ _loop: ; do { +- WRITE_NUM_BYTES bottom, %%n, %1 ; write bytes ++ WRITE_NUM_BYTES bottom, %%n ; write bytes + add r0 , r2 ; dst += linesize +- dec r5 ++ dec r5d + jnz .emuedge_extend_bottom_ %+ %%n %+ _loop ; } while (--block_h) + + .emuedge_v_extend_end_ %+ %%n: +@@ -659,17 +796,17 @@ + ; lowest two bytes of the register (so val*0x0101), and are splatted + ; into each byte of mm0 as well if n_pixels >= 8 + +-%macro READ_V_PIXEL 3 ++%macro READ_V_PIXEL 2 + mov vall, %2 + mov valh, vall + %if %1 >= 8 + movd mm0, vald +-%ifidn %3, mmx ++%if cpuflag(mmx2) ++ pshufw mm0, mm0, 0 ++%else ; mmx + punpcklwd mm0, mm0 + punpckldq mm0, mm0 +-%else ; !mmx +- pshufw mm0, mm0, 0 +-%endif ; mmx ++%endif ; sse + %endif ; %1 >= 8 + %endmacro + +@@ -694,13 +831,13 @@ + %endmacro + + ; r0=buf+block_h*linesize, r1=start_x, r2=linesize, r5=block_h, r6/r3=val +-%macro LEFT_EXTEND 1 ++%macro LEFT_EXTEND 0 + %assign %%n 2 + %rep 11 + ALIGN 64 + .emuedge_extend_left_ %+ %%n: ; do { + sub r0, r2 ; dst -= linesize +- READ_V_PIXEL %%n, [r0+r1], %1 ; read pixels ++ READ_V_PIXEL %%n, [r0+r1] ; read pixels + WRITE_V_PIXEL %%n, r0 ; write pixels + dec r5 + jnz .emuedge_extend_left_ %+ %%n ; } while (--block_h) +@@ -714,19 +851,19 @@ + %endmacro ; LEFT_EXTEND + + ; r3/r0=buf+block_h*linesize, r2=linesize, r11/r5=block_h, r0/r6=end_x, r6/r3=val +-%macro RIGHT_EXTEND 1 ++%macro RIGHT_EXTEND 0 + %assign %%n 2 + %rep 11 + ALIGN 64 + .emuedge_extend_right_ %+ %%n: ; do { + %ifdef ARCH_X86_64 + sub r3, r2 ; dst -= linesize +- READ_V_PIXEL %%n, [r3+w_reg-1], %1 ; read pixels ++ READ_V_PIXEL %%n, [r3+w_reg-1] ; read pixels + WRITE_V_PIXEL %%n, r3+r4-%%n ; write pixels + dec r11 + %else ; ARCH_X86_32 + sub r0, r2 ; dst -= linesize +- READ_V_PIXEL %%n, [r0+w_reg-1], %1 ; read pixels ++ READ_V_PIXEL %%n, [r0+w_reg-1] ; read pixels + WRITE_V_PIXEL %%n, r0+r4-%%n ; write pixels + dec r5 + %endif ; ARCH_X86_64/32 +@@ -768,17 +905,17 @@ + .%1_skip_%4_px: + %endmacro + +-%macro V_COPY_ROW 3 ++%macro V_COPY_ROW 2 + %ifidn %1, bottom + sub r1, linesize + %endif + .%1_copy_loop: + xor cnt_reg, cnt_reg +-%ifidn %3, mmx ++%if notcpuflag(sse) + %define linesize r2m + V_COPY_NPX %1, mm0, movq, 8, 0xFFFFFFF8 +-%else ; !mmx +- V_COPY_NPX %1, xmm0, movdqu, 16, 0xFFFFFFF0 ++%else ; sse ++ V_COPY_NPX %1, xmm0, movups, 16, 0xFFFFFFF0 + %ifdef ARCH_X86_64 + %define linesize r2 + V_COPY_NPX %1, rax , mov, 8 +@@ -786,7 +923,7 @@ + %define linesize r2m + V_COPY_NPX %1, mm0, movq, 8 + %endif ; ARCH_X86_64/32 +-%endif ; mmx ++%endif ; sse + V_COPY_NPX %1, vald, mov, 4 + V_COPY_NPX %1, valw, mov, 2 + V_COPY_NPX %1, vall, mov, 1 +@@ -799,7 +936,7 @@ + jnz .%1_copy_loop + %endmacro + +-%macro SLOW_V_EXTEND 1 ++%macro SLOW_V_EXTEND 0 + .slow_v_extend_loop: + ; r0=buf,r1=src,r2(64)/r2m(32)=linesize,r3(64)/r3m(32)=start_x,r4=end_y,r5=block_h + ; r11(64)/r3(later-64)/r2(32)=cnt_reg,r6(64)/r3(32)=val_reg,r10(64)/r6(32)=w=end_x-start_x +@@ -808,16 +945,16 @@ + test r3, r3 + %define cnt_reg r11 + jz .do_body_copy ; if (!start_y) goto do_body_copy +- V_COPY_ROW top, r3, %1 ++ V_COPY_ROW top, r3 + %else + cmp dword r3m, 0 + %define cnt_reg r2 + je .do_body_copy ; if (!start_y) goto do_body_copy +- V_COPY_ROW top, dword r3m, %1 ++ V_COPY_ROW top, dword r3m + %endif + + .do_body_copy: +- V_COPY_ROW body, r4, %1 ++ V_COPY_ROW body, r4 + + %ifdef ARCH_X86_64 + pop r11 ; restore old value of block_h +@@ -829,7 +966,7 @@ + %else + jz .skip_bottom_extend + %endif +- V_COPY_ROW bottom, r5, %1 ++ V_COPY_ROW bottom, r5 + %ifdef ARCH_X86_32 + .skip_bottom_extend: + mov r2, r2m +@@ -837,12 +974,12 @@ + jmp .v_extend_end + %endmacro + +-%macro SLOW_LEFT_EXTEND 1 ++%macro SLOW_LEFT_EXTEND 0 + .slow_left_extend_loop: + ; r0=buf+block_h*linesize,r2=linesize,r6(64)/r3(32)=val,r5=block_h,r4=cntr,r10/r6=start_x + mov r4, 8 + sub r0, linesize +- READ_V_PIXEL 8, [r0+w_reg], %1 ++ READ_V_PIXEL 8, [r0+w_reg] + .left_extend_8px_loop: + movq [r0+r4-8], mm0 + add r4, 8 +@@ -865,7 +1002,7 @@ + jmp .right_extend + %endmacro + +-%macro SLOW_RIGHT_EXTEND 1 ++%macro SLOW_RIGHT_EXTEND 0 + .slow_right_extend_loop: + ; r3(64)/r0(32)=buf+block_h*linesize,r2=linesize,r4=block_w,r11(64)/r5(32)=block_h, + ; r10(64)/r6(32)=end_x,r6/r3=val,r1=cntr +@@ -878,7 +1015,7 @@ + %endif + lea r1, [r4-8] + sub buf_reg, linesize +- READ_V_PIXEL 8, [buf_reg+w_reg-1], %1 ++ READ_V_PIXEL 8, [buf_reg+w_reg-1] + .right_extend_8px_loop: + movq [buf_reg+r1], mm0 + sub r1, 8 +@@ -899,16 +1036,147 @@ + %endmacro + + %macro emu_edge 1 +-EMU_EDGE_FUNC %1 +-VERTICAL_EXTEND %1 +-LEFT_EXTEND %1 +-RIGHT_EXTEND %1 +-SLOW_V_EXTEND %1 +-SLOW_LEFT_EXTEND %1 +-SLOW_RIGHT_EXTEND %1 ++INIT_XMM %1 ++EMU_EDGE_FUNC ++VERTICAL_EXTEND ++LEFT_EXTEND ++RIGHT_EXTEND ++SLOW_V_EXTEND ++SLOW_LEFT_EXTEND ++SLOW_RIGHT_EXTEND + %endmacro + + emu_edge sse + %ifdef ARCH_X86_32 + emu_edge mmx + %endif ++ ++;----------------------------------------------------------------------------- ++; void ff_vector_clip_int32(int32_t *dst, const int32_t *src, int32_t min, ++; int32_t max, unsigned int len) ++;----------------------------------------------------------------------------- ++ ++; %1 = number of xmm registers used ++; %2 = number of inline load/process/store loops per asm loop ++; %3 = process 4*mmsize (%3=0) or 8*mmsize (%3=1) bytes per loop ++; %4 = CLIPD function takes min/max as float instead of int (CLIPD_SSE2) ++; %5 = suffix ++%macro VECTOR_CLIP_INT32 4-5 ++cglobal vector_clip_int32%5, 5,5,%2, dst, src, min, max, len ++%if %4 ++ cvtsi2ss m4, minm ++ cvtsi2ss m5, maxm ++%else ++ movd m4, minm ++ movd m5, maxm ++%endif ++ SPLATD m4 ++ SPLATD m5 ++.loop: ++%assign %%i 1 ++%rep %2 ++ mova m0, [srcq+mmsize*0*%%i] ++ mova m1, [srcq+mmsize*1*%%i] ++ mova m2, [srcq+mmsize*2*%%i] ++ mova m3, [srcq+mmsize*3*%%i] ++%if %3 ++ mova m7, [srcq+mmsize*4*%%i] ++ mova m8, [srcq+mmsize*5*%%i] ++ mova m9, [srcq+mmsize*6*%%i] ++ mova m10, [srcq+mmsize*7*%%i] ++%endif ++ CLIPD m0, m4, m5, m6 ++ CLIPD m1, m4, m5, m6 ++ CLIPD m2, m4, m5, m6 ++ CLIPD m3, m4, m5, m6 ++%if %3 ++ CLIPD m7, m4, m5, m6 ++ CLIPD m8, m4, m5, m6 ++ CLIPD m9, m4, m5, m6 ++ CLIPD m10, m4, m5, m6 ++%endif ++ mova [dstq+mmsize*0*%%i], m0 ++ mova [dstq+mmsize*1*%%i], m1 ++ mova [dstq+mmsize*2*%%i], m2 ++ mova [dstq+mmsize*3*%%i], m3 ++%if %3 ++ mova [dstq+mmsize*4*%%i], m7 ++ mova [dstq+mmsize*5*%%i], m8 ++ mova [dstq+mmsize*6*%%i], m9 ++ mova [dstq+mmsize*7*%%i], m10 ++%endif ++%assign %%i %%i+1 ++%endrep ++ add srcq, mmsize*4*(%2+%3) ++ add dstq, mmsize*4*(%2+%3) ++ sub lend, mmsize*(%2+%3) ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX mmx ++%define SPLATD SPLATD_MMX ++%define CLIPD CLIPD_MMX ++VECTOR_CLIP_INT32 0, 1, 0, 0 ++INIT_XMM sse2 ++%define SPLATD SPLATD_SSE2 ++VECTOR_CLIP_INT32 6, 1, 0, 0, _int ++%define CLIPD CLIPD_SSE2 ++VECTOR_CLIP_INT32 6, 2, 0, 1 ++INIT_XMM sse4 ++%define CLIPD CLIPD_SSE41 ++%ifdef m8 ++VECTOR_CLIP_INT32 11, 1, 1, 0 ++%else ++VECTOR_CLIP_INT32 6, 1, 0, 0 ++%endif ++ ++;----------------------------------------------------------------------------- ++; void ff_butterflies_float_interleave(float *dst, const float *src0, ++; const float *src1, int len); ++;----------------------------------------------------------------------------- ++ ++%macro BUTTERFLIES_FLOAT_INTERLEAVE 0 ++cglobal butterflies_float_interleave, 4,4,3, dst, src0, src1, len ++%ifdef ARCH_X86_64 ++ movsxd lenq, lend ++%endif ++ test lenq, lenq ++ jz .end ++ shl lenq, 2 ++ lea src0q, [src0q + lenq] ++ lea src1q, [src1q + lenq] ++ lea dstq, [ dstq + 2*lenq] ++ neg lenq ++.loop: ++ mova m0, [src0q + lenq] ++ mova m1, [src1q + lenq] ++ subps m2, m0, m1 ++ addps m0, m0, m1 ++ unpcklps m1, m0, m2 ++ unpckhps m0, m0, m2 ++%if cpuflag(avx) ++ vextractf128 [dstq + 2*lenq ], m1, 0 ++ vextractf128 [dstq + 2*lenq + 16], m0, 0 ++ vextractf128 [dstq + 2*lenq + 32], m1, 1 ++ vextractf128 [dstq + 2*lenq + 48], m0, 1 ++%else ++ mova [dstq + 2*lenq ], m1 ++ mova [dstq + 2*lenq + mmsize], m0 ++%endif ++ add lenq, mmsize ++ jl .loop ++%if mmsize == 32 ++ vzeroupper ++ RET ++%endif ++.end: ++ REP_RET ++%endmacro ++ ++INIT_XMM sse ++BUTTERFLIES_FLOAT_INTERLEAVE ++%ifdef HAVE_AVX ++INIT_YMM avx ++BUTTERFLIES_FLOAT_INTERLEAVE ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt.c 2012-05-14 14:08:54.517343665 +0200 +@@ -0,0 +1,202 @@ ++/* ++ * MMX optimized discrete wavelet transform ++ * Copyright (c) 2002-2004 Michael Niedermayer ++ * Copyright (c) 2010 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/x86_cpu.h" ++#include "dsputil_mmx.h" ++#include "dwt.h" ++ ++#define COMPOSE_VERTICAL(ext, align) \ ++void ff_vertical_compose53iL0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width); \ ++void ff_vertical_compose_dirac53iH0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width); \ ++void ff_vertical_compose_dd137iL0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width); \ ++void ff_vertical_compose_dd97iH0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, IDWTELEM *b3, IDWTELEM *b4, int width); \ ++void ff_vertical_compose_haar##ext(IDWTELEM *b0, IDWTELEM *b1, int width); \ ++void ff_horizontal_compose_haar0i##ext(IDWTELEM *b, IDWTELEM *tmp, int w);\ ++void ff_horizontal_compose_haar1i##ext(IDWTELEM *b, IDWTELEM *tmp, int w);\ ++\ ++static void vertical_compose53iL0##ext(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, int width) \ ++{ \ ++ int i, width_align = width&~(align-1); \ ++\ ++ for(i=width_align; i>1;\ ++ int x= w2 - (w2&(align-1));\ ++ ff_horizontal_compose_haar0i##ext(b, tmp, w);\ ++\ ++ for (; x < w2; x++) {\ ++ b[2*x ] = tmp[x];\ ++ b[2*x+1] = COMPOSE_HAARiH0(b[x+w2], tmp[x]);\ ++ }\ ++}\ ++static void horizontal_compose_haar1i##ext(IDWTELEM *b, IDWTELEM *tmp, int w)\ ++{\ ++ int w2= w>>1;\ ++ int x= w2 - (w2&(align-1));\ ++ ff_horizontal_compose_haar1i##ext(b, tmp, w);\ ++\ ++ for (; x < w2; x++) {\ ++ b[2*x ] = (tmp[x] + 1)>>1;\ ++ b[2*x+1] = (COMPOSE_HAARiH0(b[x+w2], tmp[x]) + 1)>>1;\ ++ }\ ++}\ ++\ ++ ++#if HAVE_YASM ++#if !ARCH_X86_64 ++COMPOSE_VERTICAL(_mmx, 4) ++#endif ++COMPOSE_VERTICAL(_sse2, 8) ++#endif ++ ++ ++void ff_horizontal_compose_dd97i_ssse3(IDWTELEM *b, IDWTELEM *tmp, int w); ++ ++static void horizontal_compose_dd97i_ssse3(IDWTELEM *b, IDWTELEM *tmp, int w) ++{ ++ int w2= w>>1; ++ int x= w2 - (w2&7); ++ ff_horizontal_compose_dd97i_ssse3(b, tmp, w); ++ ++ for (; x < w2; x++) { ++ b[2*x ] = (tmp[x] + 1)>>1; ++ b[2*x+1] = (COMPOSE_DD97iH0(tmp[x-1], tmp[x], b[x+w2], tmp[x+1], tmp[x+2]) + 1)>>1; ++ } ++} ++ ++void ff_spatial_idwt_init_mmx(DWTContext *d, enum dwt_type type) ++{ ++#if HAVE_YASM ++ int mm_flags = av_get_cpu_flags(); ++ ++#if !ARCH_X86_64 ++ if (!(mm_flags & AV_CPU_FLAG_MMX)) ++ return; ++ ++ switch (type) { ++ case DWT_DIRAC_DD9_7: ++ d->vertical_compose_l0 = vertical_compose53iL0_mmx; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0_mmx; ++ break; ++ case DWT_DIRAC_LEGALL5_3: ++ d->vertical_compose_l0 = vertical_compose53iL0_mmx; ++ d->vertical_compose_h0 = vertical_compose_dirac53iH0_mmx; ++ break; ++ case DWT_DIRAC_DD13_7: ++ d->vertical_compose_l0 = vertical_compose_dd137iL0_mmx; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0_mmx; ++ break; ++ case DWT_DIRAC_HAAR0: ++ d->vertical_compose = vertical_compose_haar_mmx; ++ d->horizontal_compose = horizontal_compose_haar0i_mmx; ++ break; ++ case DWT_DIRAC_HAAR1: ++ d->vertical_compose = vertical_compose_haar_mmx; ++ d->horizontal_compose = horizontal_compose_haar1i_mmx; ++ break; ++ } ++#endif ++ ++ if (!(mm_flags & AV_CPU_FLAG_SSE2)) ++ return; ++ ++ switch (type) { ++ case DWT_DIRAC_DD9_7: ++ d->vertical_compose_l0 = vertical_compose53iL0_sse2; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0_sse2; ++ break; ++ case DWT_DIRAC_LEGALL5_3: ++ d->vertical_compose_l0 = vertical_compose53iL0_sse2; ++ d->vertical_compose_h0 = vertical_compose_dirac53iH0_sse2; ++ break; ++ case DWT_DIRAC_DD13_7: ++ d->vertical_compose_l0 = vertical_compose_dd137iL0_sse2; ++ d->vertical_compose_h0 = vertical_compose_dd97iH0_sse2; ++ break; ++ case DWT_DIRAC_HAAR0: ++ d->vertical_compose = vertical_compose_haar_sse2; ++ d->horizontal_compose = horizontal_compose_haar0i_sse2; ++ break; ++ case DWT_DIRAC_HAAR1: ++ d->vertical_compose = vertical_compose_haar_sse2; ++ d->horizontal_compose = horizontal_compose_haar1i_sse2; ++ break; ++ } ++ ++ if (!(mm_flags & AV_CPU_FLAG_SSSE3)) ++ return; ++ ++ switch (type) { ++ case DWT_DIRAC_DD9_7: ++ d->horizontal_compose = horizontal_compose_dd97i_ssse3; ++ break; ++ } ++#endif // HAVE_YASM ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt.h 2012-05-14 14:08:54.517343665 +0200 +@@ -0,0 +1,30 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_X86_DWT_H ++#define AVCODEC_X86_DWT_H ++ ++#include "libavcodec/dwt.h" ++ ++void ff_horizontal_compose_dd97i_end_c(IDWTELEM *b, IDWTELEM *tmp, int w2, int x); ++void ff_horizontal_compose_haar1i_end_c(IDWTELEM *b, IDWTELEM *tmp, int w2, int x); ++void ff_horizontal_compose_haar0i_end_c(IDWTELEM *b, IDWTELEM *tmp, int w2, int x); ++ ++void ff_spatial_idwt_init_mmx(DWTContext *d, enum dwt_type type); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt_yasm.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt_yasm.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/dwt_yasm.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/dwt_yasm.asm 2012-05-14 14:08:54.518343685 +0200 +@@ -0,0 +1,291 @@ ++;****************************************************************************** ++;* MMX optimized discrete wavelet trasnform ++;* Copyright (c) 2010 David Conrad ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++ ++SECTION_RODATA ++pw_1: times 8 dw 1 ++pw_2: times 8 dw 2 ++pw_8: times 8 dw 8 ++pw_16: times 8 dw 16 ++pw_1991: times 4 dw 9,-1 ++ ++section .text ++ ++; %1 -= (%2 + %3 + 2)>>2 %4 is pw_2 ++%macro COMPOSE_53iL0 4 ++ paddw %2, %3 ++ paddw %2, %4 ++ psraw %2, 2 ++ psubw %1, %2 ++%endm ++ ++; m1 = %1 + (-m0 + 9*m1 + 9*%2 -%3 + 8)>>4 ++; if %4 is supplied, %1 is loaded unaligned from there ++; m2: clobbered m3: pw_8 m4: pw_1991 ++%macro COMPOSE_DD97iH0 3-4 ++ paddw m0, %3 ++ paddw m1, %2 ++ psubw m0, m3 ++ mova m2, m1 ++ punpcklwd m1, m0 ++ punpckhwd m2, m0 ++ pmaddwd m1, m4 ++ pmaddwd m2, m4 ++%if %0 > 3 ++ movu %1, %4 ++%endif ++ psrad m1, 4 ++ psrad m2, 4 ++ packssdw m1, m2 ++ paddw m1, %1 ++%endm ++ ++%macro COMPOSE_VERTICAL 1 ++; void vertical_compose53iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, ++; int width) ++cglobal vertical_compose53iL0_%1, 4,4,1, b0, b1, b2, width ++ mova m2, [pw_2] ++.loop: ++ sub widthd, mmsize/2 ++ mova m1, [b0q+2*widthq] ++ mova m0, [b1q+2*widthq] ++ COMPOSE_53iL0 m0, m1, [b2q+2*widthq], m2 ++ mova [b1q+2*widthq], m0 ++ jg .loop ++ REP_RET ++ ++; void vertical_compose_dirac53iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, ++; int width) ++cglobal vertical_compose_dirac53iH0_%1, 4,4,1, b0, b1, b2, width ++ mova m1, [pw_1] ++.loop: ++ sub widthd, mmsize/2 ++ mova m0, [b0q+2*widthq] ++ paddw m0, [b2q+2*widthq] ++ paddw m0, m1 ++ psraw m0, 1 ++ paddw m0, [b1q+2*widthq] ++ mova [b1q+2*widthq], m0 ++ jg .loop ++ REP_RET ++ ++; void vertical_compose_dd97iH0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, ++; IDWTELEM *b3, IDWTELEM *b4, int width) ++cglobal vertical_compose_dd97iH0_%1, 6,6,5, b0, b1, b2, b3, b4, width ++ mova m3, [pw_8] ++ mova m4, [pw_1991] ++.loop: ++ sub widthd, mmsize/2 ++ mova m0, [b0q+2*widthq] ++ mova m1, [b1q+2*widthq] ++ COMPOSE_DD97iH0 [b2q+2*widthq], [b3q+2*widthq], [b4q+2*widthq] ++ mova [b2q+2*widthq], m1 ++ jg .loop ++ REP_RET ++ ++; void vertical_compose_dd137iL0(IDWTELEM *b0, IDWTELEM *b1, IDWTELEM *b2, ++; IDWTELEM *b3, IDWTELEM *b4, int width) ++cglobal vertical_compose_dd137iL0_%1, 6,6,6, b0, b1, b2, b3, b4, width ++ mova m3, [pw_16] ++ mova m4, [pw_1991] ++.loop: ++ sub widthd, mmsize/2 ++ mova m0, [b0q+2*widthq] ++ mova m1, [b1q+2*widthq] ++ mova m5, [b2q+2*widthq] ++ paddw m0, [b4q+2*widthq] ++ paddw m1, [b3q+2*widthq] ++ psubw m0, m3 ++ mova m2, m1 ++ punpcklwd m1, m0 ++ punpckhwd m2, m0 ++ pmaddwd m1, m4 ++ pmaddwd m2, m4 ++ psrad m1, 5 ++ psrad m2, 5 ++ packssdw m1, m2 ++ psubw m5, m1 ++ mova [b2q+2*widthq], m5 ++ jg .loop ++ REP_RET ++ ++; void vertical_compose_haar(IDWTELEM *b0, IDWTELEM *b1, int width) ++cglobal vertical_compose_haar_%1, 3,4,3, b0, b1, width ++ mova m3, [pw_1] ++.loop: ++ sub widthd, mmsize/2 ++ mova m1, [b1q+2*widthq] ++ mova m0, [b0q+2*widthq] ++ mova m2, m1 ++ paddw m1, m3 ++ psraw m1, 1 ++ psubw m0, m1 ++ mova [b0q+2*widthq], m0 ++ paddw m2, m0 ++ mova [b1q+2*widthq], m2 ++ jg .loop ++ REP_RET ++%endmacro ++ ++; extend the left and right edges of the tmp array by %1 and %2 respectively ++%macro EDGE_EXTENSION 3 ++ mov %3, [tmpq] ++%assign %%i 1 ++%rep %1 ++ mov [tmpq-2*%%i], %3 ++ %assign %%i %%i+1 ++%endrep ++ mov %3, [tmpq+2*w2q-2] ++%assign %%i 0 ++%rep %2 ++ mov [tmpq+2*w2q+2*%%i], %3 ++ %assign %%i %%i+1 ++%endrep ++%endmacro ++ ++ ++%macro HAAR_HORIZONTAL 2 ++; void horizontal_compose_haari(IDWTELEM *b, IDWTELEM *tmp, int width) ++cglobal horizontal_compose_haar%2i_%1, 3,6,4, b, tmp, w, x, w2, b_w2 ++ mov w2d, wd ++ xor xq, xq ++ shr w2d, 1 ++ lea b_w2q, [bq+wq] ++ mova m3, [pw_1] ++.lowpass_loop: ++ movu m1, [b_w2q + 2*xq] ++ mova m0, [bq + 2*xq] ++ paddw m1, m3 ++ psraw m1, 1 ++ psubw m0, m1 ++ mova [tmpq + 2*xq], m0 ++ add xq, mmsize/2 ++ cmp xq, w2q ++ jl .lowpass_loop ++ ++ xor xq, xq ++ and w2q, ~(mmsize/2 - 1) ++ cmp w2q, mmsize/2 ++ jl .end ++ ++.highpass_loop: ++ movu m1, [b_w2q + 2*xq] ++ mova m0, [tmpq + 2*xq] ++ paddw m1, m0 ++ ++ ; shift and interleave ++%if %2 == 1 ++ paddw m0, m3 ++ paddw m1, m3 ++ psraw m0, 1 ++ psraw m1, 1 ++%endif ++ mova m2, m0 ++ punpcklwd m0, m1 ++ punpckhwd m2, m1 ++ mova [bq+4*xq], m0 ++ mova [bq+4*xq+mmsize], m2 ++ ++ add xq, mmsize/2 ++ cmp xq, w2q ++ jl .highpass_loop ++.end: ++ REP_RET ++%endmacro ++ ++ ++INIT_XMM ++; void horizontal_compose_dd97i(IDWTELEM *b, IDWTELEM *tmp, int width) ++cglobal horizontal_compose_dd97i_ssse3, 3,6,8, b, tmp, w, x, w2, b_w2 ++ mov w2d, wd ++ xor xd, xd ++ shr w2d, 1 ++ lea b_w2q, [bq+wq] ++ movu m4, [bq+wq] ++ mova m7, [pw_2] ++ pslldq m4, 14 ++.lowpass_loop: ++ movu m1, [b_w2q + 2*xq] ++ mova m0, [bq + 2*xq] ++ mova m2, m1 ++ palignr m1, m4, 14 ++ mova m4, m2 ++ COMPOSE_53iL0 m0, m1, m2, m7 ++ mova [tmpq + 2*xq], m0 ++ add xd, mmsize/2 ++ cmp xd, w2d ++ jl .lowpass_loop ++ ++ EDGE_EXTENSION 1, 2, xw ++ ; leave the last up to 7 (sse) or 3 (mmx) values for C ++ xor xd, xd ++ and w2d, ~(mmsize/2 - 1) ++ cmp w2d, mmsize/2 ++ jl .end ++ ++ mova m7, [tmpq-mmsize] ++ mova m0, [tmpq] ++ mova m5, [pw_1] ++ mova m3, [pw_8] ++ mova m4, [pw_1991] ++.highpass_loop: ++ mova m6, m0 ++ palignr m0, m7, 14 ++ mova m7, [tmpq + 2*xq + 16] ++ mova m1, m7 ++ mova m2, m7 ++ palignr m1, m6, 2 ++ palignr m2, m6, 4 ++ COMPOSE_DD97iH0 m0, m6, m2, [b_w2q + 2*xq] ++ mova m0, m7 ++ mova m7, m6 ++ ++ ; shift and interleave ++ paddw m6, m5 ++ paddw m1, m5 ++ psraw m6, 1 ++ psraw m1, 1 ++ mova m2, m6 ++ punpcklwd m6, m1 ++ punpckhwd m2, m1 ++ mova [bq+4*xq], m6 ++ mova [bq+4*xq+mmsize], m2 ++ ++ add xd, mmsize/2 ++ cmp xd, w2d ++ jl .highpass_loop ++.end: ++ REP_RET ++ ++ ++%ifndef ARCH_X86_64 ++INIT_MMX ++COMPOSE_VERTICAL mmx ++HAAR_HORIZONTAL mmx, 0 ++HAAR_HORIZONTAL mmx, 1 ++%endif ++ ++;;INIT_XMM ++INIT_XMM ++COMPOSE_VERTICAL sse2 ++HAAR_HORIZONTAL sse2, 0 ++HAAR_HORIZONTAL sse2, 1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fdct_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fdct_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fdct_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fdct_mmx.c 2012-05-14 14:08:54.521343745 +0200 +@@ -68,7 +68,7 @@ + + DECLARE_ALIGNED(8, static const int32_t, fdct_r_row)[2] = {RND_FRW_ROW, RND_FRW_ROW }; + +-static struct ++static const struct + { + DECLARE_ALIGNED(16, const int32_t, fdct_r_row_sse2)[4]; + } fdct_r_row_sse2 = +@@ -151,7 +151,7 @@ + 29692, -12299, 26722, -31521, + }; + +-static struct ++static const struct + { + DECLARE_ALIGNED(16, const int16_t, tab_frw_01234567_sse2)[256]; + } tab_frw_01234567_sse2 = +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_3dn2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_3dn2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_3dn2.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_3dn2.c 2012-05-14 14:08:54.523343785 +0200 +@@ -23,7 +23,7 @@ + #include "libavcodec/dsputil.h" + #include "fft.h" + +-DECLARE_ALIGNED(8, static const int, m1m1)[2] = { 1<<31, 1<<31 }; ++DECLARE_ALIGNED(8, static const unsigned int, m1m1)[2] = { 1U<<31, 1U<<31 }; + + #ifdef EMULATE_3DNOWEXT + #define PSWAPD(s,d)\ +@@ -70,7 +70,7 @@ + in1 = input; + in2 = input + n2 - 1; + #ifdef EMULATE_3DNOWEXT +- __asm__ volatile("movd %0, %%mm7" ::"r"(1<<31)); ++ __asm__ volatile("movd %0, %%mm7" ::"r"(1U<<31)); + #endif + for(k = 0; k < n4; k++) { + // FIXME a single block is faster, but gcc 2.95 and 3.4.x on 32bit can't compile it +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft.c 2012-05-14 14:08:54.522343765 +0200 +@@ -18,18 +18,27 @@ + + #include "libavutil/cpu.h" + #include "libavcodec/dsputil.h" ++#include "libavcodec/dct.h" + #include "fft.h" + + av_cold void ff_fft_init_mmx(FFTContext *s) + { + #if HAVE_YASM + int has_vectors = av_get_cpu_flags(); +- if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) { ++ if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX && s->nbits >= 5) { ++ /* AVX for SB */ ++ s->imdct_calc = ff_imdct_calc_sse; ++ s->imdct_half = ff_imdct_half_avx; ++ s->fft_permute = ff_fft_permute_sse; ++ s->fft_calc = ff_fft_calc_avx; ++ s->fft_permutation = FF_FFT_PERM_AVX; ++ } else if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) { + /* SSE for P3/P4/K8 */ + s->imdct_calc = ff_imdct_calc_sse; + s->imdct_half = ff_imdct_half_sse; + s->fft_permute = ff_fft_permute_sse; + s->fft_calc = ff_fft_calc_sse; ++ s->fft_permutation = FF_FFT_PERM_SWAP_LSBS; + } else if (has_vectors & AV_CPU_FLAG_3DNOWEXT && HAVE_AMD3DNOWEXT) { + /* 3DNowEx for K7 */ + s->imdct_calc = ff_imdct_calc_3dn2; +@@ -47,9 +56,15 @@ + #if CONFIG_DCT + av_cold void ff_dct_init_mmx(DCTContext *s) + { ++#if HAVE_YASM + int has_vectors = av_get_cpu_flags(); +- if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) ++ if (has_vectors & AV_CPU_FLAG_AVX && HAVE_AVX) ++ s->dct32 = ff_dct32_float_avx; ++ else if (has_vectors & AV_CPU_FLAG_SSE2 && HAVE_SSE) ++ s->dct32 = ff_dct32_float_sse2; ++ else if (has_vectors & AV_CPU_FLAG_SSE && HAVE_SSE) + s->dct32 = ff_dct32_float_sse; ++#endif + } + #endif + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft.h 2012-05-14 14:08:54.522343765 +0200 +@@ -22,6 +22,7 @@ + #include "libavcodec/fft.h" + + void ff_fft_permute_sse(FFTContext *s, FFTComplex *z); ++void ff_fft_calc_avx(FFTContext *s, FFTComplex *z); + void ff_fft_calc_sse(FFTContext *s, FFTComplex *z); + void ff_fft_calc_3dn(FFTContext *s, FFTComplex *z); + void ff_fft_calc_3dn2(FFTContext *s, FFTComplex *z); +@@ -32,6 +33,9 @@ + void ff_imdct_half_3dn2(FFTContext *s, FFTSample *output, const FFTSample *input); + void ff_imdct_calc_sse(FFTContext *s, FFTSample *output, const FFTSample *input); + void ff_imdct_half_sse(FFTContext *s, FFTSample *output, const FFTSample *input); ++void ff_imdct_half_avx(FFTContext *s, FFTSample *output, const FFTSample *input); + void ff_dct32_float_sse(FFTSample *out, const FFTSample *in); ++void ff_dct32_float_sse2(FFTSample *out, const FFTSample *in); ++void ff_dct32_float_avx(FFTSample *out, const FFTSample *in); + +-#endif ++#endif /* AVCODEC_X86_FFT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_mmx.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_mmx.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_mmx.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_mmx.asm 2012-05-14 14:08:54.525343826 +0200 +@@ -1,6 +1,7 @@ + ;****************************************************************************** + ;* FFT transform with SSE/3DNow optimizations + ;* Copyright (c) 2008 Loren Merritt ++;* Copyright (c) 2011 Vitor Sessak + ;* + ;* This algorithm (though not any of the implementation details) is + ;* based on libdjbfft by D. J. Bernstein. +@@ -19,7 +20,7 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + + ; These functions are not individually interchangeable with the C versions. +@@ -27,7 +28,7 @@ + ; in blocks as conventient to the vector size. + ; i.e. {4x real, 4x imaginary, 4x real, ...} (or 2x respectively) + +-%include "x86inc.asm" ++%include "libavutil/x86/x86inc.asm" + + %ifdef ARCH_X86_64 + %define pointer resq +@@ -49,8 +50,21 @@ + SECTION_RODATA + + %define M_SQRT1_2 0.70710678118654752440 +-ps_root2: times 4 dd M_SQRT1_2 +-ps_root2mppm: dd -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 ++%define M_COS_PI_1_8 0.923879532511287 ++%define M_COS_PI_3_8 0.38268343236509 ++ ++align 32 ++ps_cos16_1: dd 1.0, M_COS_PI_1_8, M_SQRT1_2, M_COS_PI_3_8, 1.0, M_COS_PI_1_8, M_SQRT1_2, M_COS_PI_3_8 ++ps_cos16_2: dd 0, M_COS_PI_3_8, M_SQRT1_2, M_COS_PI_1_8, 0, -M_COS_PI_3_8, -M_SQRT1_2, -M_COS_PI_1_8 ++ ++ps_root2: times 8 dd M_SQRT1_2 ++ps_root2mppm: dd -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2, -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 ++ps_p1p1m1p1: dd 0, 0, 1<<31, 0, 0, 0, 1<<31, 0 ++ ++perm1: dd 0x00, 0x02, 0x03, 0x01, 0x03, 0x00, 0x02, 0x01 ++perm2: dd 0x00, 0x01, 0x02, 0x03, 0x01, 0x00, 0x02, 0x03 ++ps_p1p1m1p1root2: dd 1.0, 1.0, -1.0, 1.0, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, M_SQRT1_2 ++ps_m1m1p1m1p1m1m1m1: dd 1<<31, 1<<31, 0, 1<<31, 0, 1<<31, 1<<31, 1<<31 + ps_m1p1: dd 1<<31, 0 + + %assign i 16 +@@ -71,7 +85,7 @@ + %1 + %endmacro + +-section .text align=16 ++SECTION_TEXT + + %macro T2_3DN 4 ; z0, z1, mem0, mem1 + mova %1, %3 +@@ -95,54 +109,80 @@ + SWAP %3, %6 + %endmacro + +-; in: %1={r0,i0,r1,i1} %2={r2,i2,r3,i3} +-; out: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} +-%macro T4_SSE 3 +- mova %3, %1 +- shufps %1, %2, 0x64 ; {r0,i0,r3,i2} +- shufps %3, %2, 0xce ; {r1,i1,r2,i3} +- mova %2, %1 +- addps %1, %3 ; {t1,t2,t6,t5} +- subps %2, %3 ; {t3,t4,t8,t7} +- mova %3, %1 +- shufps %1, %2, 0x44 ; {t1,t2,t3,t4} +- shufps %3, %2, 0xbe ; {t6,t5,t7,t8} +- mova %2, %1 +- addps %1, %3 ; {r0,i0,r1,i1} +- subps %2, %3 ; {r2,i2,r3,i3} +- mova %3, %1 +- shufps %1, %2, 0x88 ; {r0,r1,r2,r3} +- shufps %3, %2, 0xdd ; {i0,i1,i2,i3} +- SWAP %2, %3 ++; in: %1 = {r0,i0,r2,i2,r4,i4,r6,i6} ++; %2 = {r1,i1,r3,i3,r5,i5,r7,i7} ++; %3, %4, %5 tmp ++; out: %1 = {r0,r1,r2,r3,i0,i1,i2,i3} ++; %2 = {r4,r5,r6,r7,i4,i5,i6,i7} ++%macro T8_AVX 5 ++ vsubps %5, %1, %2 ; v = %1 - %2 ++ vaddps %3, %1, %2 ; w = %1 + %2 ++ vmulps %2, %5, [ps_p1p1m1p1root2] ; v *= vals1 ++ vpermilps %2, %2, [perm1] ++ vblendps %1, %2, %3, 0x33 ; q = {w1,w2,v4,v2,w5,w6,v7,v6} ++ vshufps %5, %3, %2, 0x4e ; r = {w3,w4,v1,v3,w7,w8,v8,v5} ++ vsubps %4, %5, %1 ; s = r - q ++ vaddps %1, %5, %1 ; u = r + q ++ vpermilps %1, %1, [perm2] ; k = {u1,u2,u3,u4,u6,u5,u7,u8} ++ vshufps %5, %4, %1, 0xbb ++ vshufps %3, %4, %1, 0xee ++ vperm2f128 %3, %3, %5, 0x13 ++ vxorps %4, %4, [ps_m1m1p1m1p1m1m1m1] ; s *= {1,1,-1,-1,1,-1,-1,-1} ++ vshufps %2, %1, %4, 0xdd ++ vshufps %1, %1, %4, 0x88 ++ vperm2f128 %4, %2, %1, 0x02 ; v = {k1,k3,s1,s3,k2,k4,s2,s4} ++ vperm2f128 %1, %1, %2, 0x13 ; w = {k6,k8,s6,s8,k5,k7,s5,s7} ++ vsubps %5, %1, %3 ++ vblendps %1, %5, %1, 0x55 ; w -= {0,s7,0,k7,0,s8,0,k8} ++ vsubps %2, %4, %1 ; %2 = v - w ++ vaddps %1, %4, %1 ; %1 = v + w + %endmacro + +-%macro T8_SSE 6 ; r0,i0,r1,i1,t0,t1 +- mova %5, %3 +- shufps %3, %4, 0x44 ; {r4,i4,r6,i6} +- shufps %5, %4, 0xee ; {r5,i5,r7,i7} +- mova %6, %3 +- subps %3, %5 ; {r5,i5,r7,i7} +- addps %6, %5 ; {t1,t2,t3,t4} +- mova %5, %3 +- shufps %5, %5, 0xb1 ; {i5,r5,i7,r7} +- mulps %3, [ps_root2mppm] ; {-r5,i5,r7,-i7} +- mulps %5, [ps_root2] +- addps %3, %5 ; {t8,t7,ta,t9} +- mova %5, %6 +- shufps %6, %3, 0x36 ; {t3,t2,t9,t8} +- shufps %5, %3, 0x9c ; {t1,t4,t7,ta} +- mova %3, %6 +- addps %6, %5 ; {t1,t2,t9,ta} +- subps %3, %5 ; {t6,t5,tc,tb} +- mova %5, %6 +- shufps %6, %3, 0xd8 ; {t1,t9,t5,tb} +- shufps %5, %3, 0x8d ; {t2,ta,t6,tc} +- mova %3, %1 +- mova %4, %2 +- addps %1, %6 ; {r0,r1,r2,r3} +- addps %2, %5 ; {i0,i1,i2,i3} +- subps %3, %6 ; {r4,r5,r6,r7} +- subps %4, %5 ; {i4,i5,i6,i7} ++; In SSE mode do one fft4 transforms ++; in: %1={r0,i0,r2,i2} %2={r1,i1,r3,i3} ++; out: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} ++; ++; In AVX mode do two fft4 transforms ++; in: %1={r0,i0,r2,i2,r4,i4,r6,i6} %2={r1,i1,r3,i3,r5,i5,r7,i7} ++; out: %1={r0,r1,r2,r3,r4,r5,r6,r7} %2={i0,i1,i2,i3,i4,i5,i6,i7} ++%macro T4_SSE 3 ++ subps %3, %1, %2 ; {t3,t4,-t8,t7} ++ addps %1, %1, %2 ; {t1,t2,t6,t5} ++ xorps %3, %3, [ps_p1p1m1p1] ++ shufps %2, %1, %3, 0xbe ; {t6,t5,t7,t8} ++ shufps %1, %1, %3, 0x44 ; {t1,t2,t3,t4} ++ subps %3, %1, %2 ; {r2,i2,r3,i3} ++ addps %1, %1, %2 ; {r0,i0,r1,i1} ++ shufps %2, %1, %3, 0xdd ; {i0,i1,i2,i3} ++ shufps %1, %1, %3, 0x88 ; {r0,r1,r2,r3} ++%endmacro ++ ++; In SSE mode do one FFT8 ++; in: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} %3={r4,i4,r6,i6} %4={r5,i5,r7,i7} ++; out: %1={r0,r1,r2,r3} %2={i0,i1,i2,i3} %1={r4,r5,r6,r7} %2={i4,i5,i6,i7} ++; ++; In AVX mode do two FFT8 ++; in: %1={r0,i0,r2,i2,r8, i8, r10,i10} %2={r1,i1,r3,i3,r9, i9, r11,i11} ++; %3={r4,i4,r6,i6,r12,i12,r14,i14} %4={r5,i5,r7,i7,r13,i13,r15,i15} ++; out: %1={r0,r1,r2,r3,r8, r9, r10,r11} %2={i0,i1,i2,i3,i8, i9, i10,i11} ++; %3={r4,r5,r6,r7,r12,r13,r14,r15} %4={i4,i5,i6,i7,i12,i13,i14,i15} ++%macro T8_SSE 6 ++ addps %6, %3, %4 ; {t1,t2,t3,t4} ++ subps %3, %3, %4 ; {r5,i5,r7,i7} ++ shufps %4, %3, %3, 0xb1 ; {i5,r5,i7,r7} ++ mulps %3, %3, [ps_root2mppm] ; {-r5,i5,r7,-i7} ++ mulps %4, %4, [ps_root2] ++ addps %3, %3, %4 ; {t8,t7,ta,t9} ++ shufps %4, %6, %3, 0x9c ; {t1,t4,t7,ta} ++ shufps %6, %6, %3, 0x36 ; {t3,t2,t9,t8} ++ subps %3, %6, %4 ; {t6,t5,tc,tb} ++ addps %6, %6, %4 ; {t1,t2,t9,ta} ++ shufps %5, %6, %3, 0x8d ; {t2,ta,t6,tc} ++ shufps %6, %6, %3, 0xd8 ; {t1,t9,t5,tb} ++ subps %3, %1, %6 ; {r4,r5,r6,r7} ++ addps %1, %1, %6 ; {r0,r1,r2,r3} ++ subps %4, %2, %5 ; {i4,i5,i6,i7} ++ addps %2, %2, %5 ; {i0,i1,i2,i3} + %endmacro + + ; scheduled for cpu-bound sizes +@@ -150,52 +190,44 @@ + IF%1 mova m4, Z(4) + IF%1 mova m5, Z(5) + mova m0, %2 ; wre +- mova m2, m4 + mova m1, %3 ; wim +- mova m3, m5 +- mulps m2, m0 ; r2*wre ++ mulps m2, m4, m0 ; r2*wre + IF%1 mova m6, Z2(6) +- mulps m3, m1 ; i2*wim ++ mulps m3, m5, m1 ; i2*wim + IF%1 mova m7, Z2(7) +- mulps m4, m1 ; r2*wim +- mulps m5, m0 ; i2*wre +- addps m2, m3 ; r2*wre + i2*wim +- mova m3, m1 +- mulps m1, m6 ; r3*wim +- subps m5, m4 ; i2*wre - r2*wim +- mova m4, m0 +- mulps m3, m7 ; i3*wim +- mulps m4, m6 ; r3*wre +- mulps m0, m7 ; i3*wre +- subps m4, m3 ; r3*wre - i3*wim ++ mulps m4, m4, m1 ; r2*wim ++ mulps m5, m5, m0 ; i2*wre ++ addps m2, m2, m3 ; r2*wre + i2*wim ++ mulps m3, m1, m7 ; i3*wim ++ subps m5, m5, m4 ; i2*wre - r2*wim ++ mulps m1, m1, m6 ; r3*wim ++ mulps m4, m0, m6 ; r3*wre ++ mulps m0, m0, m7 ; i3*wre ++ subps m4, m4, m3 ; r3*wre - i3*wim + mova m3, Z(0) +- addps m0, m1 ; i3*wre + r3*wim +- mova m1, m4 +- addps m4, m2 ; t5 +- subps m1, m2 ; t3 +- subps m3, m4 ; r2 +- addps m4, Z(0) ; r0 ++ addps m0, m0, m1 ; i3*wre + r3*wim ++ subps m1, m4, m2 ; t3 ++ addps m4, m4, m2 ; t5 ++ subps m3, m3, m4 ; r2 ++ addps m4, m4, Z(0) ; r0 + mova m6, Z(2) + mova Z(4), m3 + mova Z(0), m4 +- mova m3, m5 +- subps m5, m0 ; t4 +- mova m4, m6 +- subps m6, m5 ; r3 +- addps m5, m4 ; r1 +- mova Z2(6), m6 +- mova Z(2), m5 ++ subps m3, m5, m0 ; t4 ++ subps m4, m6, m3 ; r3 ++ addps m3, m3, m6 ; r1 ++ mova Z2(6), m4 ++ mova Z(2), m3 + mova m2, Z(3) +- addps m3, m0 ; t6 +- subps m2, m1 ; i3 ++ addps m3, m5, m0 ; t6 ++ subps m2, m2, m1 ; i3 + mova m7, Z(1) +- addps m1, Z(3) ; i1 ++ addps m1, m1, Z(3) ; i1 + mova Z2(7), m2 + mova Z(3), m1 +- mova m4, m7 +- subps m7, m3 ; i2 +- addps m3, m4 ; i0 +- mova Z(5), m7 ++ subps m4, m7, m3 ; i2 ++ addps m3, m3, m7 ; i0 ++ mova Z(5), m4 + mova Z(1), m3 + %endmacro + +@@ -203,77 +235,55 @@ + %macro PASS_BIG 1 ; (!interleave) + mova m4, Z(4) ; r2 + mova m5, Z(5) ; i2 +- mova m2, m4 + mova m0, [wq] ; wre +- mova m3, m5 + mova m1, [wq+o1q] ; wim +- mulps m2, m0 ; r2*wre ++ mulps m2, m4, m0 ; r2*wre + mova m6, Z2(6) ; r3 +- mulps m3, m1 ; i2*wim ++ mulps m3, m5, m1 ; i2*wim + mova m7, Z2(7) ; i3 +- mulps m4, m1 ; r2*wim +- mulps m5, m0 ; i2*wre +- addps m2, m3 ; r2*wre + i2*wim +- mova m3, m1 +- mulps m1, m6 ; r3*wim +- subps m5, m4 ; i2*wre - r2*wim +- mova m4, m0 +- mulps m3, m7 ; i3*wim +- mulps m4, m6 ; r3*wre +- mulps m0, m7 ; i3*wre +- subps m4, m3 ; r3*wre - i3*wim ++ mulps m4, m4, m1 ; r2*wim ++ mulps m5, m5, m0 ; i2*wre ++ addps m2, m2, m3 ; r2*wre + i2*wim ++ mulps m3, m1, m7 ; i3*wim ++ mulps m1, m1, m6 ; r3*wim ++ subps m5, m5, m4 ; i2*wre - r2*wim ++ mulps m4, m0, m6 ; r3*wre ++ mulps m0, m0, m7 ; i3*wre ++ subps m4, m4, m3 ; r3*wre - i3*wim + mova m3, Z(0) +- addps m0, m1 ; i3*wre + r3*wim +- mova m1, m4 +- addps m4, m2 ; t5 +- subps m1, m2 ; t3 +- subps m3, m4 ; r2 +- addps m4, Z(0) ; r0 ++ addps m0, m0, m1 ; i3*wre + r3*wim ++ subps m1, m4, m2 ; t3 ++ addps m4, m4, m2 ; t5 ++ subps m3, m3, m4 ; r2 ++ addps m4, m4, Z(0) ; r0 + mova m6, Z(2) + mova Z(4), m3 + mova Z(0), m4 +- mova m3, m5 +- subps m5, m0 ; t4 +- mova m4, m6 +- subps m6, m5 ; r3 +- addps m5, m4 ; r1 +-IF%1 mova Z2(6), m6 +-IF%1 mova Z(2), m5 ++ subps m3, m5, m0 ; t4 ++ subps m4, m6, m3 ; r3 ++ addps m3, m3, m6 ; r1 ++IF%1 mova Z2(6), m4 ++IF%1 mova Z(2), m3 + mova m2, Z(3) +- addps m3, m0 ; t6 +- subps m2, m1 ; i3 ++ addps m5, m5, m0 ; t6 ++ subps m2, m2, m1 ; i3 + mova m7, Z(1) +- addps m1, Z(3) ; i1 ++ addps m1, m1, Z(3) ; i1 + IF%1 mova Z2(7), m2 + IF%1 mova Z(3), m1 +- mova m4, m7 +- subps m7, m3 ; i2 +- addps m3, m4 ; i0 +-IF%1 mova Z(5), m7 +-IF%1 mova Z(1), m3 ++ subps m6, m7, m5 ; i2 ++ addps m5, m5, m7 ; i0 ++IF%1 mova Z(5), m6 ++IF%1 mova Z(1), m5 + %if %1==0 +- mova m4, m5 ; r1 +- mova m0, m6 ; r3 +- unpcklps m5, m1 +- unpckhps m4, m1 +- unpcklps m6, m2 +- unpckhps m0, m2 ++ INTERL m1, m3, m7, Z, 2 ++ INTERL m2, m4, m0, Z2, 6 ++ + mova m1, Z(0) + mova m2, Z(4) +- mova Z(2), m5 +- mova Z(3), m4 +- mova Z2(6), m6 +- mova Z2(7), m0 +- mova m5, m1 ; r0 +- mova m4, m2 ; r2 +- unpcklps m1, m3 +- unpckhps m5, m3 +- unpcklps m2, m7 +- unpckhps m4, m7 +- mova Z(0), m1 +- mova Z(1), m5 +- mova Z(4), m2 +- mova Z(5), m4 ++ ++ INTERL m5, m1, m3, Z, 0 ++ INTERL m6, m2, m7, Z, 4 + %endif + %endmacro + +@@ -283,13 +293,109 @@ + punpckhdq %3, %2 + %endmacro + +-INIT_XMM +-%define mova movaps +- + %define Z(x) [r0+mmsize*x] + %define Z2(x) [r0+mmsize*x] ++%define ZH(x) [r0+mmsize*x+mmsize/2] ++ ++INIT_YMM ++ ++%ifdef HAVE_AVX ++align 16 ++fft8_avx: ++ mova m0, Z(0) ++ mova m1, Z(1) ++ T8_AVX m0, m1, m2, m3, m4 ++ mova Z(0), m0 ++ mova Z(1), m1 ++ ret ++ ++ ++align 16 ++fft16_avx: ++ mova m2, Z(2) ++ mova m3, Z(3) ++ T4_SSE m2, m3, m7 ++ ++ mova m0, Z(0) ++ mova m1, Z(1) ++ T8_AVX m0, m1, m4, m5, m7 ++ ++ mova m4, [ps_cos16_1] ++ mova m5, [ps_cos16_2] ++ vmulps m6, m2, m4 ++ vmulps m7, m3, m5 ++ vaddps m7, m7, m6 ++ vmulps m2, m2, m5 ++ vmulps m3, m3, m4 ++ vsubps m3, m3, m2 ++ vblendps m2, m7, m3, 0xf0 ++ vperm2f128 m3, m7, m3, 0x21 ++ vaddps m4, m2, m3 ++ vsubps m2, m3, m2 ++ vperm2f128 m2, m2, m2, 0x01 ++ vsubps m3, m1, m2 ++ vaddps m1, m1, m2 ++ vsubps m5, m0, m4 ++ vaddps m0, m0, m4 ++ vextractf128 Z(0), m0, 0 ++ vextractf128 ZH(0), m1, 0 ++ vextractf128 Z(1), m0, 1 ++ vextractf128 ZH(1), m1, 1 ++ vextractf128 Z(2), m5, 0 ++ vextractf128 ZH(2), m3, 0 ++ vextractf128 Z(3), m5, 1 ++ vextractf128 ZH(3), m3, 1 ++ ret ++ ++align 16 ++fft32_avx: ++ call fft16_avx ++ ++ mova m0, Z(4) ++ mova m1, Z(5) ++ ++ T4_SSE m0, m1, m4 ++ ++ mova m2, Z(6) ++ mova m3, Z(7) ++ ++ T8_SSE m0, m1, m2, m3, m4, m6 ++ ; m0={r0,r1,r2,r3,r8, r9, r10,r11} m1={i0,i1,i2,i3,i8, i9, i10,i11} ++ ; m2={r4,r5,r6,r7,r12,r13,r14,r15} m3={i4,i5,i6,i7,i12,i13,i14,i15} ++ ++ vperm2f128 m4, m0, m2, 0x20 ++ vperm2f128 m5, m1, m3, 0x20 ++ vperm2f128 m6, m0, m2, 0x31 ++ vperm2f128 m7, m1, m3, 0x31 ++ ++ PASS_SMALL 0, [cos_32], [cos_32+32] ++ ++ ret ++ ++fft32_interleave_avx: ++ call fft32_avx ++ mov r2d, 32 ++.deint_loop: ++ mova m2, Z(0) ++ mova m3, Z(1) ++ vunpcklps m0, m2, m3 ++ vunpckhps m1, m2, m3 ++ vextractf128 Z(0), m0, 0 ++ vextractf128 ZH(0), m1, 0 ++ vextractf128 Z(1), m0, 1 ++ vextractf128 ZH(1), m1, 1 ++ add r0, mmsize*2 ++ sub r2d, mmsize/4 ++ jg .deint_loop ++ ret ++ ++%endif ++ ++INIT_XMM ++%define movdqa movaps + + align 16 ++fft4_avx: + fft4_sse: + mova m0, Z(0) + mova m1, Z(1) +@@ -408,6 +514,8 @@ + + %define Z(x) [zq + o1q*(x&6) + mmsize*(x&1)] + %define Z2(x) [zq + o3q + mmsize*(x&1)] ++%define ZH(x) [zq + o1q*(x&6) + mmsize*(x&1) + mmsize/2] ++%define Z2H(x) [zq + o3q + mmsize*(x&1) + mmsize/2] + + %macro DECL_PASS 2+ ; name, payload + align 16 +@@ -425,8 +533,36 @@ + rep ret + %endmacro + ++INIT_YMM ++ ++%ifdef HAVE_AVX ++%macro INTERL_AVX 5 ++ vunpckhps %3, %2, %1 ++ vunpcklps %2, %2, %1 ++ vextractf128 %4(%5), %2, 0 ++ vextractf128 %4 %+ H(%5), %3, 0 ++ vextractf128 %4(%5 + 1), %2, 1 ++ vextractf128 %4 %+ H(%5 + 1), %3, 1 ++%endmacro ++ ++%define INTERL INTERL_AVX ++ ++DECL_PASS pass_avx, PASS_BIG 1 ++DECL_PASS pass_interleave_avx, PASS_BIG 0 ++%endif ++ + INIT_XMM +-%define mova movaps ++ ++%macro INTERL_SSE 5 ++ mova %3, %2 ++ unpcklps %2, %1 ++ unpckhps %3, %1 ++ mova %4(%5), %2 ++ mova %4(%5+1), %3 ++%endmacro ++ ++%define INTERL INTERL_SSE ++ + DECL_PASS pass_sse, PASS_BIG 1 + DECL_PASS pass_interleave_sse, PASS_BIG 0 + +@@ -459,9 +595,12 @@ + + %macro DECL_FFT 2-3 ; nbits, cpu, suffix + %xdefine list_of_fft fft4%2 SECTION_REL, fft8%2 SECTION_REL +-%if %1==5 ++%if %1>=5 + %xdefine list_of_fft list_of_fft, fft16%2 SECTION_REL + %endif ++%if %1>=6 ++%xdefine list_of_fft list_of_fft, fft32%3%2 SECTION_REL ++%endif + + %assign n 1<<%1 + %rep 17-%1 +@@ -494,11 +633,21 @@ + ; The others pass args in registers and don't spill anything. + cglobal fft_dispatch%3%2, 2,5,8, z, nbits + FFT_DISPATCH %3%2, nbits ++%ifidn %2, _avx ++ vzeroupper ++%endif + RET + %endmacro ; DECL_FFT + ++%ifdef HAVE_AVX ++INIT_YMM ++DECL_FFT 6, _avx ++DECL_FFT 6, _avx, _interleave ++%endif ++INIT_XMM + DECL_FFT 5, _sse + DECL_FFT 5, _sse, _interleave ++INIT_MMX + DECL_FFT 4, _3dn + DECL_FFT 4, _3dn, _interleave + DECL_FFT 4, _3dn2 +@@ -535,21 +684,53 @@ + %endmacro + + %macro CMUL 6 ;j, xmm0, xmm1, 3, 4, 5 +- movaps xmm6, [%4+%1*2] +- movaps %2, [%4+%1*2+0x10] +- movaps %3, xmm6 +- movaps xmm7, %2 +- mulps xmm6, [%5+%1] +- mulps %2, [%6+%1] +- mulps %3, [%6+%1] +- mulps xmm7, [%5+%1] +- subps %2, xmm6 +- addps %3, xmm7 ++ mulps m6, %3, [%5+%1] ++ mulps m7, %2, [%5+%1] ++ mulps %2, %2, [%6+%1] ++ mulps %3, %3, [%6+%1] ++ subps %2, %2, m6 ++ addps %3, %3, m7 ++%endmacro ++ ++%macro POSROTATESHUF_AVX 5 ;j, k, z+n8, tcos+n8, tsin+n8 ++.post: ++ vmovaps ymm1, [%3+%1*2] ++ vmovaps ymm0, [%3+%1*2+0x20] ++ vmovaps ymm3, [%3+%2*2] ++ vmovaps ymm2, [%3+%2*2+0x20] ++ ++ CMUL %1, ymm0, ymm1, %3, %4, %5 ++ CMUL %2, ymm2, ymm3, %3, %4, %5 ++ vshufps ymm1, ymm1, ymm1, 0x1b ++ vshufps ymm3, ymm3, ymm3, 0x1b ++ vperm2f128 ymm1, ymm1, ymm1, 0x01 ++ vperm2f128 ymm3, ymm3, ymm3, 0x01 ++ vunpcklps ymm6, ymm2, ymm1 ++ vunpckhps ymm4, ymm2, ymm1 ++ vunpcklps ymm7, ymm0, ymm3 ++ vunpckhps ymm5, ymm0, ymm3 ++ ++ vextractf128 [%3+%1*2], ymm7, 0 ++ vextractf128 [%3+%1*2+0x10], ymm5, 0 ++ vextractf128 [%3+%1*2+0x20], ymm7, 1 ++ vextractf128 [%3+%1*2+0x30], ymm5, 1 ++ ++ vextractf128 [%3+%2*2], ymm6, 0 ++ vextractf128 [%3+%2*2+0x10], ymm4, 0 ++ vextractf128 [%3+%2*2+0x20], ymm6, 1 ++ vextractf128 [%3+%2*2+0x30], ymm4, 1 ++ sub %2, 0x20 ++ add %1, 0x20 ++ jl .post + %endmacro + + %macro POSROTATESHUF 5 ;j, k, z+n8, tcos+n8, tsin+n8 + .post: ++ movaps xmm1, [%3+%1*2] ++ movaps xmm0, [%3+%1*2+0x10] + CMUL %1, xmm0, xmm1, %3, %4, %5 ++ movaps xmm5, [%3+%2*2] ++ movaps xmm4, [%3+%2*2+0x10] + CMUL %2, xmm4, xmm5, %3, %4, %5 + shufps xmm1, xmm1, 0x1b + shufps xmm5, xmm5, 0x1b +@@ -568,7 +749,8 @@ + jl .post + %endmacro + +-cglobal imdct_half_sse, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample *input ++%macro DECL_IMDCT 2 ++cglobal imdct_half%1, 3,7,8; FFTContext *s, FFTSample *output, const FFTSample *input + %ifdef ARCH_X86_64 + %define rrevtab r10 + %define rtcos r11 +@@ -643,7 +825,7 @@ + mov r0, r1 + mov r1d, [r5+FFTContext.nbits] + +- FFT_DISPATCH _sse, r1 ++ FFT_DISPATCH %1, r1 + + mov r0d, [r5+FFTContext.mdctsize] + add r6, r0 +@@ -655,9 +837,9 @@ + mov rtsin, [esp+4] + %endif + neg r0 +- mov r1, -16 ++ mov r1, -mmsize + sub r1, r0 +- POSROTATESHUF r0, r1, r6, rtcos, rtsin ++ %2 r0, r1, r6, rtcos, rtsin + %ifdef ARCH_X86_64 + pop r14 + pop r13 +@@ -665,4 +847,16 @@ + %else + add esp, 12 + %endif ++%ifidn avx_enabled, 1 ++ vzeroupper ++%endif + RET ++%endmacro ++ ++DECL_IMDCT _sse, POSROTATESHUF ++ ++INIT_YMM ++ ++%ifdef HAVE_AVX ++DECL_IMDCT _avx, POSROTATESHUF_AVX ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_sse.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_sse.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fft_sse.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fft_sse.c 2012-05-14 14:08:54.526343846 +0200 +@@ -22,12 +22,21 @@ + #include "libavutil/x86_cpu.h" + #include "libavcodec/dsputil.h" + #include "fft.h" ++#include "config.h" + +-DECLARE_ASM_CONST(16, int, ff_m1m1m1m1)[4] = +- { 1 << 31, 1 << 31, 1 << 31, 1 << 31 }; ++DECLARE_ASM_CONST(16, unsigned int, ff_m1m1m1m1)[4] = ++ { 1U << 31, 1U << 31, 1U << 31, 1U << 31 }; + + void ff_fft_dispatch_sse(FFTComplex *z, int nbits); + void ff_fft_dispatch_interleave_sse(FFTComplex *z, int nbits); ++void ff_fft_dispatch_interleave_avx(FFTComplex *z, int nbits); ++ ++#if HAVE_AVX ++void ff_fft_calc_avx(FFTContext *s, FFTComplex *z) ++{ ++ ff_fft_dispatch_interleave_avx(z, s->nbits); ++} ++#endif + + void ff_fft_calc_sse(FFTContext *s, FFTComplex *z) + { +@@ -77,7 +86,7 @@ + long n = s->mdct_size; + long n4 = n >> 2; + +- ff_imdct_half_sse(s, output+n4, input); ++ s->imdct_half(s, output + n4, input); + + j = -n; + k = n-16; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fmtconvert.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fmtconvert.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fmtconvert.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fmtconvert.asm 2012-05-14 14:08:54.527343866 +0200 +@@ -16,12 +16,157 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_TEXT ++ ++;--------------------------------------------------------------------------------- ++; void int32_to_float_fmul_scalar(float *dst, const int *src, float mul, int len); ++;--------------------------------------------------------------------------------- ++%macro INT32_TO_FLOAT_FMUL_SCALAR 2 ++%ifdef UNIX64 ++cglobal int32_to_float_fmul_scalar_%1, 3,3,%2, dst, src, len ++%else ++cglobal int32_to_float_fmul_scalar_%1, 4,4,%2, dst, src, mul, len ++%endif ++%ifdef WIN64 ++ SWAP 0, 2 ++%elifdef ARCH_X86_32 ++ movss m0, mulm ++%endif ++ SPLATD m0 ++ shl lenq, 2 ++ add srcq, lenq ++ add dstq, lenq ++ neg lenq ++.loop: ++%ifidn %1, sse2 ++ cvtdq2ps m1, [srcq+lenq ] ++ cvtdq2ps m2, [srcq+lenq+16] ++%else ++ cvtpi2ps m1, [srcq+lenq ] ++ cvtpi2ps m3, [srcq+lenq+ 8] ++ cvtpi2ps m2, [srcq+lenq+16] ++ cvtpi2ps m4, [srcq+lenq+24] ++ movlhps m1, m3 ++ movlhps m2, m4 ++%endif ++ mulps m1, m0 ++ mulps m2, m0 ++ mova [dstq+lenq ], m1 ++ mova [dstq+lenq+16], m2 ++ add lenq, 32 ++ jl .loop ++ REP_RET ++%endmacro ++ ++INIT_XMM ++%define SPLATD SPLATD_SSE ++%define movdqa movaps ++INT32_TO_FLOAT_FMUL_SCALAR sse, 5 ++%undef movdqa ++%define SPLATD SPLATD_SSE2 ++INT32_TO_FLOAT_FMUL_SCALAR sse2, 3 ++%undef SPLATD ++ ++ ++;------------------------------------------------------------------------------ ++; void ff_float_to_int16(int16_t *dst, const float *src, long len); ++;------------------------------------------------------------------------------ ++%macro FLOAT_TO_INT16 2 ++cglobal float_to_int16_%1, 3,3,%2, dst, src, len ++ add lenq, lenq ++ lea srcq, [srcq+2*lenq] ++ add dstq, lenq ++ neg lenq ++.loop: ++%ifidn %1, sse2 ++ cvtps2dq m0, [srcq+2*lenq ] ++ cvtps2dq m1, [srcq+2*lenq+16] ++ packssdw m0, m1 ++ mova [dstq+lenq], m0 ++%else ++ cvtps2pi m0, [srcq+2*lenq ] ++ cvtps2pi m1, [srcq+2*lenq+ 8] ++ cvtps2pi m2, [srcq+2*lenq+16] ++ cvtps2pi m3, [srcq+2*lenq+24] ++ packssdw m0, m1 ++ packssdw m2, m3 ++ mova [dstq+lenq ], m0 ++ mova [dstq+lenq+8], m2 ++%endif ++ add lenq, 16 ++ js .loop ++%ifnidn %1, sse2 ++ emms ++%endif ++ REP_RET ++%endmacro ++ ++INIT_XMM ++FLOAT_TO_INT16 sse2, 2 ++INIT_MMX ++FLOAT_TO_INT16 sse, 0 ++%define cvtps2pi pf2id ++FLOAT_TO_INT16 3dnow, 0 ++%undef cvtps2pi ++ ++ ++;------------------------------------------------------------------------------- ++; void ff_float_to_int16_interleave2(int16_t *dst, const float **src, long len); ++;------------------------------------------------------------------------------- ++%macro FLOAT_TO_INT16_INTERLEAVE2 1 ++cglobal float_to_int16_interleave2_%1, 3,4,2, dst, src0, src1, len ++ lea lenq, [4*r2q] ++ mov src1q, [src0q+gprsize] ++ mov src0q, [src0q] ++ add dstq, lenq ++ add src0q, lenq ++ add src1q, lenq ++ neg lenq ++.loop: ++%ifidn %1, sse2 ++ cvtps2dq m0, [src0q+lenq] ++ cvtps2dq m1, [src1q+lenq] ++ packssdw m0, m1 ++ movhlps m1, m0 ++ punpcklwd m0, m1 ++ mova [dstq+lenq], m0 ++%else ++ cvtps2pi m0, [src0q+lenq ] ++ cvtps2pi m1, [src0q+lenq+8] ++ cvtps2pi m2, [src1q+lenq ] ++ cvtps2pi m3, [src1q+lenq+8] ++ packssdw m0, m1 ++ packssdw m2, m3 ++ mova m1, m0 ++ punpcklwd m0, m2 ++ punpckhwd m1, m2 ++ mova [dstq+lenq ], m0 ++ mova [dstq+lenq+8], m1 ++%endif ++ add lenq, 16 ++ js .loop ++%ifnidn %1, sse2 ++ emms ++%endif ++ REP_RET ++%endmacro ++ ++INIT_MMX ++%define cvtps2pi pf2id ++FLOAT_TO_INT16_INTERLEAVE2 3dnow ++%undef cvtps2pi ++%define movdqa movaps ++FLOAT_TO_INT16_INTERLEAVE2 sse ++%undef movdqa ++INIT_XMM ++FLOAT_TO_INT16_INTERLEAVE2 sse2 + +-section .text align=16 + + %macro PSWAPD_SSE 2 + pshufw %1, %2, 0x4e +@@ -89,3 +234,136 @@ + %undef pswapd + FLOAT_TO_INT16_INTERLEAVE6 3dn2 + %undef cvtps2pi ++ ++;----------------------------------------------------------------------------- ++; void ff_float_interleave6(float *dst, const float **src, unsigned int len); ++;----------------------------------------------------------------------------- ++ ++%macro FLOAT_INTERLEAVE6 2 ++cglobal float_interleave6_%1, 2,7,%2, dst, src, src1, src2, src3, src4, src5 ++%ifdef ARCH_X86_64 ++ %define lend r10d ++ mov lend, r2d ++%else ++ %define lend dword r2m ++%endif ++ mov src1q, [srcq+1*gprsize] ++ mov src2q, [srcq+2*gprsize] ++ mov src3q, [srcq+3*gprsize] ++ mov src4q, [srcq+4*gprsize] ++ mov src5q, [srcq+5*gprsize] ++ mov srcq, [srcq] ++ sub src1q, srcq ++ sub src2q, srcq ++ sub src3q, srcq ++ sub src4q, srcq ++ sub src5q, srcq ++.loop: ++%ifidn %1, sse ++ movaps m0, [srcq] ++ movaps m1, [srcq+src1q] ++ movaps m2, [srcq+src2q] ++ movaps m3, [srcq+src3q] ++ movaps m4, [srcq+src4q] ++ movaps m5, [srcq+src5q] ++ ++ SBUTTERFLYPS 0, 1, 6 ++ SBUTTERFLYPS 2, 3, 6 ++ SBUTTERFLYPS 4, 5, 6 ++ ++ movaps m6, m4 ++ shufps m4, m0, 0xe4 ++ movlhps m0, m2 ++ movhlps m6, m2 ++ movaps [dstq ], m0 ++ movaps [dstq+16], m4 ++ movaps [dstq+32], m6 ++ ++ movaps m6, m5 ++ shufps m5, m1, 0xe4 ++ movlhps m1, m3 ++ movhlps m6, m3 ++ movaps [dstq+48], m1 ++ movaps [dstq+64], m5 ++ movaps [dstq+80], m6 ++%else ; mmx ++ movq m0, [srcq] ++ movq m1, [srcq+src1q] ++ movq m2, [srcq+src2q] ++ movq m3, [srcq+src3q] ++ movq m4, [srcq+src4q] ++ movq m5, [srcq+src5q] ++ ++ SBUTTERFLY dq, 0, 1, 6 ++ SBUTTERFLY dq, 2, 3, 6 ++ SBUTTERFLY dq, 4, 5, 6 ++ movq [dstq ], m0 ++ movq [dstq+ 8], m2 ++ movq [dstq+16], m4 ++ movq [dstq+24], m1 ++ movq [dstq+32], m3 ++ movq [dstq+40], m5 ++%endif ++ add srcq, mmsize ++ add dstq, mmsize*6 ++ sub lend, mmsize/4 ++ jg .loop ++%ifidn %1, mmx ++ emms ++%endif ++ REP_RET ++%endmacro ++ ++INIT_MMX ++FLOAT_INTERLEAVE6 mmx, 0 ++INIT_XMM ++FLOAT_INTERLEAVE6 sse, 7 ++ ++;----------------------------------------------------------------------------- ++; void ff_float_interleave2(float *dst, const float **src, unsigned int len); ++;----------------------------------------------------------------------------- ++ ++%macro FLOAT_INTERLEAVE2 2 ++cglobal float_interleave2_%1, 3,4,%2, dst, src, len, src1 ++ mov src1q, [srcq+gprsize] ++ mov srcq, [srcq ] ++ sub src1q, srcq ++.loop ++ MOVPS m0, [srcq ] ++ MOVPS m1, [srcq+src1q ] ++ MOVPS m3, [srcq +mmsize] ++ MOVPS m4, [srcq+src1q+mmsize] ++ ++ MOVPS m2, m0 ++ PUNPCKLDQ m0, m1 ++ PUNPCKHDQ m2, m1 ++ ++ MOVPS m1, m3 ++ PUNPCKLDQ m3, m4 ++ PUNPCKHDQ m1, m4 ++ ++ MOVPS [dstq ], m0 ++ MOVPS [dstq+1*mmsize], m2 ++ MOVPS [dstq+2*mmsize], m3 ++ MOVPS [dstq+3*mmsize], m1 ++ ++ add srcq, mmsize*2 ++ add dstq, mmsize*4 ++ sub lend, mmsize/2 ++ jg .loop ++%ifidn %1, mmx ++ emms ++%endif ++ REP_RET ++%endmacro ++ ++INIT_MMX ++%define MOVPS movq ++%define PUNPCKLDQ punpckldq ++%define PUNPCKHDQ punpckhdq ++FLOAT_INTERLEAVE2 mmx, 0 ++INIT_XMM ++%define MOVPS movaps ++%define PUNPCKLDQ unpcklps ++%define PUNPCKHDQ unpckhps ++FLOAT_INTERLEAVE2 sse, 5 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fmtconvert_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fmtconvert_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/fmtconvert_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/fmtconvert_mmx.c 2012-05-14 14:08:54.529343906 +0200 +@@ -26,133 +26,32 @@ + #include "libavutil/x86_cpu.h" + #include "libavcodec/fmtconvert.h" + +-static void int32_to_float_fmul_scalar_sse(float *dst, const int *src, float mul, int len) +-{ +- x86_reg i = -4*len; +- __asm__ volatile( +- "movss %3, %%xmm4 \n" +- "shufps $0, %%xmm4, %%xmm4 \n" +- "1: \n" +- "cvtpi2ps (%2,%0), %%xmm0 \n" +- "cvtpi2ps 8(%2,%0), %%xmm1 \n" +- "cvtpi2ps 16(%2,%0), %%xmm2 \n" +- "cvtpi2ps 24(%2,%0), %%xmm3 \n" +- "movlhps %%xmm1, %%xmm0 \n" +- "movlhps %%xmm3, %%xmm2 \n" +- "mulps %%xmm4, %%xmm0 \n" +- "mulps %%xmm4, %%xmm2 \n" +- "movaps %%xmm0, (%1,%0) \n" +- "movaps %%xmm2, 16(%1,%0) \n" +- "add $32, %0 \n" +- "jl 1b \n" +- :"+r"(i) +- :"r"(dst+len), "r"(src+len), "m"(mul) +- ); +-} ++#if HAVE_YASM + +-static void int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len) +-{ +- x86_reg i = -4*len; +- __asm__ volatile( +- "movss %3, %%xmm4 \n" +- "shufps $0, %%xmm4, %%xmm4 \n" +- "1: \n" +- "cvtdq2ps (%2,%0), %%xmm0 \n" +- "cvtdq2ps 16(%2,%0), %%xmm1 \n" +- "mulps %%xmm4, %%xmm0 \n" +- "mulps %%xmm4, %%xmm1 \n" +- "movaps %%xmm0, (%1,%0) \n" +- "movaps %%xmm1, 16(%1,%0) \n" +- "add $32, %0 \n" +- "jl 1b \n" +- :"+r"(i) +- :"r"(dst+len), "r"(src+len), "m"(mul) +- ); +-} ++void ff_int32_to_float_fmul_scalar_sse (float *dst, const int *src, float mul, int len); ++void ff_int32_to_float_fmul_scalar_sse2(float *dst, const int *src, float mul, int len); + +-static void float_to_int16_3dnow(int16_t *dst, const float *src, long len){ +- x86_reg reglen = len; +- // not bit-exact: pf2id uses different rounding than C and SSE +- __asm__ volatile( +- "add %0 , %0 \n\t" +- "lea (%2,%0,2) , %2 \n\t" +- "add %0 , %1 \n\t" +- "neg %0 \n\t" +- "1: \n\t" +- "pf2id (%2,%0,2) , %%mm0 \n\t" +- "pf2id 8(%2,%0,2) , %%mm1 \n\t" +- "pf2id 16(%2,%0,2) , %%mm2 \n\t" +- "pf2id 24(%2,%0,2) , %%mm3 \n\t" +- "packssdw %%mm1 , %%mm0 \n\t" +- "packssdw %%mm3 , %%mm2 \n\t" +- "movq %%mm0 , (%1,%0) \n\t" +- "movq %%mm2 , 8(%1,%0) \n\t" +- "add $16 , %0 \n\t" +- " js 1b \n\t" +- "femms \n\t" +- :"+r"(reglen), "+r"(dst), "+r"(src) +- ); +-} +- +-static void float_to_int16_sse(int16_t *dst, const float *src, long len){ +- x86_reg reglen = len; +- __asm__ volatile( +- "add %0 , %0 \n\t" +- "lea (%2,%0,2) , %2 \n\t" +- "add %0 , %1 \n\t" +- "neg %0 \n\t" +- "1: \n\t" +- "cvtps2pi (%2,%0,2) , %%mm0 \n\t" +- "cvtps2pi 8(%2,%0,2) , %%mm1 \n\t" +- "cvtps2pi 16(%2,%0,2) , %%mm2 \n\t" +- "cvtps2pi 24(%2,%0,2) , %%mm3 \n\t" +- "packssdw %%mm1 , %%mm0 \n\t" +- "packssdw %%mm3 , %%mm2 \n\t" +- "movq %%mm0 , (%1,%0) \n\t" +- "movq %%mm2 , 8(%1,%0) \n\t" +- "add $16 , %0 \n\t" +- " js 1b \n\t" +- "emms \n\t" +- :"+r"(reglen), "+r"(dst), "+r"(src) +- ); +-} +- +-static void float_to_int16_sse2(int16_t *dst, const float *src, long len){ +- x86_reg reglen = len; +- __asm__ volatile( +- "add %0 , %0 \n\t" +- "lea (%2,%0,2) , %2 \n\t" +- "add %0 , %1 \n\t" +- "neg %0 \n\t" +- "1: \n\t" +- "cvtps2dq (%2,%0,2) , %%xmm0 \n\t" +- "cvtps2dq 16(%2,%0,2) , %%xmm1 \n\t" +- "packssdw %%xmm1 , %%xmm0 \n\t" +- "movdqa %%xmm0 , (%1,%0) \n\t" +- "add $16 , %0 \n\t" +- " js 1b \n\t" +- :"+r"(reglen), "+r"(dst), "+r"(src) +- ); +-} ++void ff_float_to_int16_3dnow(int16_t *dst, const float *src, long len); ++void ff_float_to_int16_sse (int16_t *dst, const float *src, long len); ++void ff_float_to_int16_sse2 (int16_t *dst, const float *src, long len); ++ ++void ff_float_to_int16_interleave2_3dnow(int16_t *dst, const float **src, long len); ++void ff_float_to_int16_interleave2_sse (int16_t *dst, const float **src, long len); ++void ff_float_to_int16_interleave2_sse2 (int16_t *dst, const float **src, long len); + + void ff_float_to_int16_interleave6_sse(int16_t *dst, const float **src, int len); + void ff_float_to_int16_interleave6_3dnow(int16_t *dst, const float **src, int len); + void ff_float_to_int16_interleave6_3dn2(int16_t *dst, const float **src, int len); + +-#if !HAVE_YASM +-#define ff_float_to_int16_interleave6_sse(a,b,c) float_to_int16_interleave_misc_sse(a,b,c,6) +-#define ff_float_to_int16_interleave6_3dnow(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6) +-#define ff_float_to_int16_interleave6_3dn2(a,b,c) float_to_int16_interleave_misc_3dnow(a,b,c,6) +-#endif + #define ff_float_to_int16_interleave6_sse2 ff_float_to_int16_interleave6_sse + +-#define FLOAT_TO_INT16_INTERLEAVE(cpu, body) \ ++#define FLOAT_TO_INT16_INTERLEAVE(cpu) \ + /* gcc pessimizes register allocation if this is in the same function as float_to_int16_interleave_sse2*/\ + static av_noinline void float_to_int16_interleave_misc_##cpu(int16_t *dst, const float **src, long len, int channels){\ + DECLARE_ALIGNED(16, int16_t, tmp)[len];\ + int i,j,c;\ + for(c=0; cfloat_interleave = float_interleave_mmx; + +- if(mm_flags & AV_CPU_FLAG_3DNOW){ ++ if (HAVE_AMD3DNOW && mm_flags & AV_CPU_FLAG_3DNOW) { + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ +- c->float_to_int16 = float_to_int16_3dnow; ++ c->float_to_int16 = ff_float_to_int16_3dnow; + c->float_to_int16_interleave = float_to_int16_interleave_3dnow; + } + } +- if(mm_flags & AV_CPU_FLAG_3DNOWEXT){ ++ if (HAVE_AMD3DNOWEXT && mm_flags & AV_CPU_FLAG_3DNOWEXT) { + if(!(avctx->flags & CODEC_FLAG_BITEXACT)){ + c->float_to_int16_interleave = float_to_int16_interleave_3dn2; + } + } +- if(mm_flags & AV_CPU_FLAG_SSE){ +- c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse; +- c->float_to_int16 = float_to_int16_sse; ++ if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE) { ++ c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse; ++ c->float_to_int16 = ff_float_to_int16_sse; + c->float_to_int16_interleave = float_to_int16_interleave_sse; ++ c->float_interleave = float_interleave_sse; + } +- if(mm_flags & AV_CPU_FLAG_SSE2){ +- c->int32_to_float_fmul_scalar = int32_to_float_fmul_scalar_sse2; +- c->float_to_int16 = float_to_int16_sse2; ++ if (HAVE_SSE && mm_flags & AV_CPU_FLAG_SSE2) { ++ c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_sse2; ++ c->float_to_int16 = ff_float_to_int16_sse2; + c->float_to_int16_interleave = float_to_int16_interleave_sse2; + } + } ++#endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_chromamc_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_chromamc_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_chromamc_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_chromamc_10bit.asm 2012-05-14 14:08:54.533343986 +0200 +@@ -0,0 +1,273 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 chroma MC code ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Daniel Kang ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA ++ ++cextern pw_4 ++cextern pw_8 ++cextern pw_32 ++cextern pw_64 ++ ++SECTION .text ++ ++ ++%macro MV0_PIXELS_MC8 0 ++ lea r4, [r2*3 ] ++ lea r5, [r2*4 ] ++.next4rows ++ movu m0, [r1 ] ++ movu m1, [r1+r2 ] ++ CHROMAMC_AVG m0, [r0 ] ++ CHROMAMC_AVG m1, [r0+r2 ] ++ mova [r0 ], m0 ++ mova [r0+r2 ], m1 ++ movu m0, [r1+r2*2] ++ movu m1, [r1+r4 ] ++ CHROMAMC_AVG m0, [r0+r2*2] ++ CHROMAMC_AVG m1, [r0+r4 ] ++ mova [r0+r2*2], m0 ++ mova [r0+r4 ], m1 ++ add r1, r5 ++ add r0, r5 ++ sub r3d, 4 ++ jne .next4rows ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void put/avg_h264_chroma_mc8(pixel *dst, pixel *src, int stride, int h, int mx, int my) ++;----------------------------------------------------------------------------- ++%macro CHROMA_MC8 2 ++; put/avg_h264_chroma_mc8_*(uint8_t *dst /*align 8*/, uint8_t *src /*align 1*/, ++; int stride, int h, int mx, int my) ++cglobal %1_h264_chroma_mc8_10_%2, 6,7,8 ++ movsxdifnidn r2, r2d ++ mov r6d, r5d ++ or r6d, r4d ++ jne .at_least_one_non_zero ++ ; mx == 0 AND my == 0 - no filter needed ++ MV0_PIXELS_MC8 ++ REP_RET ++ ++.at_least_one_non_zero ++ mov r6d, 2 ++ test r5d, r5d ++ je .x_interpolation ++ mov r6, r2 ; dxy = x ? 1 : stride ++ test r4d, r4d ++ jne .xy_interpolation ++.x_interpolation ++ ; mx == 0 XOR my == 0 - 1 dimensional filter only ++ or r4d, r5d ; x + y ++ movd m5, r4d ++ mova m4, [pw_8] ++ mova m6, [pw_4] ; mm6 = rnd >> 3 ++ SPLATW m5, m5 ; mm5 = B = x ++ psubw m4, m5 ; mm4 = A = 8-x ++ ++.next1drow ++ movu m0, [r1 ] ; mm0 = src[0..7] ++ movu m2, [r1+r6] ; mm2 = src[1..8] ++ ++ pmullw m0, m4 ; mm0 = A * src[0..7] ++ pmullw m2, m5 ; mm2 = B * src[1..8] ++ ++ paddw m0, m6 ++ paddw m0, m2 ++ psrlw m0, 3 ++ CHROMAMC_AVG m0, [r0] ++ mova [r0], m0 ; dst[0..7] = (A * src[0..7] + B * src[1..8] + (rnd >> 3)) >> 3 ++ ++ add r0, r2 ++ add r1, r2 ++ dec r3d ++ jne .next1drow ++ REP_RET ++ ++.xy_interpolation ; general case, bilinear ++ movd m4, r4m ; x ++ movd m6, r5m ; y ++ ++ SPLATW m4, m4 ; mm4 = x words ++ SPLATW m6, m6 ; mm6 = y words ++ psllw m5, m4, 3 ; mm5 = 8x ++ pmullw m4, m6 ; mm4 = x * y ++ psllw m6, 3 ; mm6 = 8y ++ paddw m1, m5, m6 ; mm7 = 8x+8y ++ mova m7, m4 ; DD = x * y ++ psubw m5, m4 ; mm5 = B = 8x - xy ++ psubw m6, m4 ; mm6 = C = 8y - xy ++ paddw m4, [pw_64] ++ psubw m4, m1 ; mm4 = A = xy - (8x+8y) + 64 ++ ++ movu m0, [r1 ] ; mm0 = src[0..7] ++ movu m1, [r1+2] ; mm1 = src[1..8] ++.next2drow ++ add r1, r2 ++ ++ pmullw m2, m0, m4 ++ pmullw m1, m5 ++ paddw m2, m1 ; mm2 = A * src[0..7] + B * src[1..8] ++ ++ movu m0, [r1] ++ movu m1, [r1+2] ++ pmullw m3, m0, m6 ++ paddw m2, m3 ; mm2 += C * src[0..7+strde] ++ pmullw m3, m1, m7 ++ paddw m2, m3 ; mm2 += D * src[1..8+strde] ++ ++ paddw m2, [pw_32] ++ psrlw m2, 6 ++ CHROMAMC_AVG m2, [r0] ++ mova [r0], m2 ; dst[0..7] = (mm2 + 32) >> 6 ++ ++ add r0, r2 ++ dec r3d ++ jne .next2drow ++ REP_RET ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void put/avg_h264_chroma_mc4(pixel *dst, pixel *src, int stride, int h, int mx, int my) ++;----------------------------------------------------------------------------- ++;TODO: xmm mc4 ++%macro MC4_OP 2 ++ movq %1, [r1 ] ++ movq m1, [r1+2] ++ add r1, r2 ++ pmullw %1, m4 ++ pmullw m1, m2 ++ paddw m1, %1 ++ mova %1, m1 ++ ++ pmullw %2, m5 ++ pmullw m1, m3 ++ paddw %2, [pw_32] ++ paddw m1, %2 ++ psrlw m1, 6 ++ CHROMAMC_AVG m1, %2, [r0] ++ movq [r0], m1 ++ add r0, r2 ++%endmacro ++ ++%macro CHROMA_MC4 2 ++cglobal %1_h264_chroma_mc4_10_%2, 6,6,7 ++ movsxdifnidn r2, r2d ++ movd m2, r4m ; x ++ movd m3, r5m ; y ++ mova m4, [pw_8] ++ mova m5, m4 ++ SPLATW m2, m2 ++ SPLATW m3, m3 ++ psubw m4, m2 ++ psubw m5, m3 ++ ++ movq m0, [r1 ] ++ movq m6, [r1+2] ++ add r1, r2 ++ pmullw m0, m4 ++ pmullw m6, m2 ++ paddw m6, m0 ++ ++.next2rows ++ MC4_OP m0, m6 ++ MC4_OP m6, m0 ++ sub r3d, 2 ++ jnz .next2rows ++ REP_RET ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void put/avg_h264_chroma_mc2(pixel *dst, pixel *src, int stride, int h, int mx, int my) ++;----------------------------------------------------------------------------- ++%macro CHROMA_MC2 2 ++cglobal %1_h264_chroma_mc2_10_%2, 6,7 ++ movsxdifnidn r2, r2d ++ mov r6d, r4d ++ shl r4d, 16 ++ sub r4d, r6d ++ add r4d, 8 ++ imul r5d, r4d ; x*y<<16 | y*(8-x) ++ shl r4d, 3 ++ sub r4d, r5d ; x*(8-y)<<16 | (8-x)*(8-y) ++ ++ movd m5, r4d ++ movd m6, r5d ++ punpckldq m5, m5 ; mm5 = {A,B,A,B} ++ punpckldq m6, m6 ; mm6 = {C,D,C,D} ++ pxor m7, m7 ++ pshufw m2, [r1], 0x94 ; mm0 = src[0,1,1,2] ++ ++.nextrow ++ add r1, r2 ++ movq m1, m2 ++ pmaddwd m1, m5 ; mm1 = A * src[0,1] + B * src[1,2] ++ pshufw m0, [r1], 0x94 ; mm0 = src[0,1,1,2] ++ movq m2, m0 ++ pmaddwd m0, m6 ++ paddw m1, [pw_32] ++ paddw m1, m0 ; mm1 += C * src[0,1] + D * src[1,2] ++ psrlw m1, 6 ++ packssdw m1, m7 ++ CHROMAMC_AVG m1, m3, [r0] ++ movd [r0], m1 ++ add r0, r2 ++ dec r3d ++ jnz .nextrow ++ REP_RET ++%endmacro ++ ++%macro NOTHING 2-3 ++%endmacro ++%macro AVG 2-3 ++%if %0==3 ++ movq %2, %3 ++%endif ++ PAVG %1, %2 ++%endmacro ++ ++%define CHROMAMC_AVG NOTHING ++INIT_XMM ++CHROMA_MC8 put, sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++CHROMA_MC8 put, avx ++%endif ++INIT_MMX ++CHROMA_MC4 put, mmxext ++CHROMA_MC2 put, mmxext ++ ++%define CHROMAMC_AVG AVG ++%define PAVG pavgw ++INIT_XMM ++CHROMA_MC8 avg, sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++CHROMA_MC8 avg, avx ++%endif ++INIT_MMX ++CHROMA_MC4 avg, mmxext ++CHROMA_MC2 avg, mmxext +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_chromamc.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_chromamc.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_chromamc.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_chromamc.asm 2012-05-14 14:08:54.530343926 +0200 +@@ -17,11 +17,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION_RODATA + +@@ -72,17 +72,17 @@ + .next4rows + movq mm0, [r1 ] + movq mm1, [r1+r2] ++ add r1, r4 + CHROMAMC_AVG mm0, [r0 ] + CHROMAMC_AVG mm1, [r0+r2] + movq [r0 ], mm0 + movq [r0+r2], mm1 + add r0, r4 +- add r1, r4 + movq mm0, [r1 ] + movq mm1, [r1+r2] ++ add r1, r4 + CHROMAMC_AVG mm0, [r0 ] + CHROMAMC_AVG mm1, [r0+r2] +- add r1, r4 + movq [r0 ], mm0 + movq [r0+r2], mm1 + add r0, r4 +@@ -472,8 +472,8 @@ + mov r6d, r4d + shl r4d, 8 + sub r4, r6 +- add r4, 8 ; x*288+8 = x<<8 | (8-x) + mov r6, 8 ++ add r4, 8 ; x*288+8 = x<<8 | (8-x) + sub r6d, r5d + imul r6, r4 ; (8-y)*(x*255+8) = (8-y)*x<<8 | (8-y)*(8-x) + imul r4d, r5d ; y *(x*255+8) = y *x<<8 | y *(8-x) +@@ -481,24 +481,23 @@ + movd m7, r6d + movd m6, r4d + movdqa m5, [rnd_2d_%2] ++ movq m0, [r1 ] ++ movq m1, [r1+1] + pshuflw m7, m7, 0 + pshuflw m6, m6, 0 ++ punpcklbw m0, m1 + movlhps m7, m7 + movlhps m6, m6 + +- movq m0, [r1 ] +- movq m1, [r1 +1] +- punpcklbw m0, m1 +- add r1, r2 + .next2rows +- movq m1, [r1 ] +- movq m2, [r1 +1] +- movq m3, [r1+r2 ] +- movq m4, [r1+r2+1] ++ movq m1, [r1+r2*1 ] ++ movq m2, [r1+r2*1+1] ++ movq m3, [r1+r2*2 ] ++ movq m4, [r1+r2*2+1] + lea r1, [r1+r2*2] + punpcklbw m1, m2 +- punpcklbw m3, m4 + movdqa m2, m1 ++ punpcklbw m3, m4 + movdqa m4, m3 + pmaddubsw m0, m7 + pmaddubsw m1, m6 +@@ -508,8 +507,8 @@ + paddw m2, m5 + paddw m1, m0 + paddw m3, m2 +- movdqa m0, m4 + psrlw m1, 6 ++ movdqa m0, m4 + psrlw m3, 6 + %ifidn %1, avg + movq m2, [r0 ] +@@ -576,6 +575,7 @@ + movq m1, [r1+r2 ] + movdqa m2, m1 + movq m3, [r1+r2*2] ++ lea r1, [r1+r2*2] + punpcklbw m0, m1 + punpcklbw m2, m3 + pmaddubsw m0, m7 +@@ -594,7 +594,6 @@ + movhps [r0+r2], m0 + sub r3d, 2 + lea r0, [r0+r2*2] +- lea r1, [r1+r2*2] + jg .next2yrows + REP_RET + %endmacro +@@ -607,8 +606,8 @@ + mov r6, r4 + shl r4d, 8 + sub r4d, r6d +- add r4d, 8 ; x*288+8 + mov r6, 8 ++ add r4d, 8 ; x*288+8 + sub r6d, r5d + imul r6d, r4d ; (8-y)*(x*255+8) = (8-y)*x<<8 | (8-y)*(8-x) + imul r4d, r5d ; y *(x*255+8) = y *x<<8 | y *(8-x) +@@ -616,17 +615,16 @@ + movd m7, r6d + movd m6, r4d + movq m5, [pw_32] ++ movd m0, [r1 ] + pshufw m7, m7, 0 ++ punpcklbw m0, [r1+1] + pshufw m6, m6, 0 + +- movd m0, [r1 ] +- punpcklbw m0, [r1 +1] +- add r1, r2 + .next2rows +- movd m1, [r1 ] +- movd m3, [r1+r2 ] +- punpcklbw m1, [r1 +1] +- punpcklbw m3, [r1+r2+1] ++ movd m1, [r1+r2*1 ] ++ movd m3, [r1+r2*2 ] ++ punpcklbw m1, [r1+r2*1+1] ++ punpcklbw m3, [r1+r2*2+1] + lea r1, [r1+r2*2] + movq m2, m1 + movq m4, m3 +@@ -638,8 +636,8 @@ + paddw m2, m5 + paddw m1, m0 + paddw m3, m2 +- movq m0, m4 + psrlw m1, 6 ++ movq m0, m4 + psrlw m3, 6 + packuswb m1, m1 + packuswb m3, m3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_deblock_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_deblock_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_deblock_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_deblock_10bit.asm 2012-05-14 14:08:54.538344088 +0200 +@@ -0,0 +1,925 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 deblocking code ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Oskar Arvidsson ++;* Loren Merritt ++;* Jason Garrett-Glaser ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++pw_pixel_max: times 8 dw ((1 << 10)-1) ++ ++SECTION .text ++ ++cextern pw_2 ++cextern pw_3 ++cextern pw_4 ++ ++; out: %4 = |%1-%2|-%3 ++; clobbers: %5 ++%macro ABS_SUB 5 ++ psubusw %5, %2, %1 ++ psubusw %4, %1, %2 ++ por %4, %5 ++ psubw %4, %3 ++%endmacro ++ ++; out: %4 = |%1-%2|<%3 ++%macro DIFF_LT 5 ++ psubusw %4, %2, %1 ++ psubusw %5, %1, %2 ++ por %5, %4 ; |%1-%2| ++ pxor %4, %4 ++ psubw %5, %3 ; |%1-%2|-%3 ++ pcmpgtw %4, %5 ; 0 > |%1-%2|-%3 ++%endmacro ++ ++%macro LOAD_AB 4 ++ movd %1, %3 ++ movd %2, %4 ++ SPLATW %1, %1 ++ SPLATW %2, %2 ++%endmacro ++ ++; in: %2=tc reg ++; out: %1=splatted tc ++%macro LOAD_TC 2 ++ movd %1, [%2] ++ punpcklbw %1, %1 ++%if mmsize == 8 ++ pshufw %1, %1, 0 ++%else ++ pshuflw %1, %1, 01010000b ++ pshufd %1, %1, 01010000b ++%endif ++ psraw %1, 6 ++%endmacro ++ ++; in: %1=p1, %2=p0, %3=q0, %4=q1 ++; %5=alpha, %6=beta, %7-%9=tmp ++; out: %7=mask ++%macro LOAD_MASK 9 ++ ABS_SUB %2, %3, %5, %8, %7 ; |p0-q0| - alpha ++ ABS_SUB %1, %2, %6, %9, %7 ; |p1-p0| - beta ++ pand %8, %9 ++ ABS_SUB %3, %4, %6, %9, %7 ; |q1-q0| - beta ++ pxor %7, %7 ++ pand %8, %9 ++ pcmpgtw %7, %8 ++%endmacro ++ ++; in: %1=p0, %2=q0, %3=p1, %4=q1, %5=mask, %6=tmp, %7=tmp ++; out: %1=p0', m2=q0' ++%macro DEBLOCK_P0_Q0 7 ++ psubw %3, %4 ++ pxor %7, %7 ++ paddw %3, [pw_4] ++ psubw %7, %5 ++ psubw %6, %2, %1 ++ psllw %6, 2 ++ paddw %3, %6 ++ psraw %3, 3 ++ mova %6, [pw_pixel_max] ++ CLIPW %3, %7, %5 ++ pxor %7, %7 ++ paddw %1, %3 ++ psubw %2, %3 ++ CLIPW %1, %7, %6 ++ CLIPW %2, %7, %6 ++%endmacro ++ ++; in: %1=x2, %2=x1, %3=p0, %4=q0 %5=mask&tc, %6=tmp ++%macro LUMA_Q1 6 ++ pavgw %6, %3, %4 ; (p0+q0+1)>>1 ++ paddw %1, %6 ++ pxor %6, %6 ++ psraw %1, 1 ++ psubw %6, %5 ++ psubw %1, %2 ++ CLIPW %1, %6, %5 ++ paddw %1, %2 ++%endmacro ++ ++%macro LUMA_DEBLOCK_ONE 3 ++ DIFF_LT m5, %1, bm, m4, m6 ++ pxor m6, m6 ++ mova %3, m4 ++ pcmpgtw m6, tcm ++ pand m4, tcm ++ pandn m6, m7 ++ pand m4, m6 ++ LUMA_Q1 m5, %2, m1, m2, m4, m6 ++%endmacro ++ ++%macro LUMA_H_STORE 2 ++%if mmsize == 8 ++ movq [r0-4], m0 ++ movq [r0+r1-4], m1 ++ movq [r0+r1*2-4], m2 ++ movq [r0+%2-4], m3 ++%else ++ movq [r0-4], m0 ++ movhps [r0+r1-4], m0 ++ movq [r0+r1*2-4], m1 ++ movhps [%1-4], m1 ++ movq [%1+r1-4], m2 ++ movhps [%1+r1*2-4], m2 ++ movq [%1+%2-4], m3 ++ movhps [%1+r1*4-4], m3 ++%endif ++%endmacro ++ ++%macro DEBLOCK_LUMA 1 ++;----------------------------------------------------------------------------- ++; void deblock_v_luma( uint16_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++;----------------------------------------------------------------------------- ++cglobal deblock_v_luma_10_%1, 5,5,8*(mmsize/16) ++ %assign pad 5*mmsize+12-(stack_offset&15) ++ %define tcm [rsp] ++ %define ms1 [rsp+mmsize] ++ %define ms2 [rsp+mmsize*2] ++ %define am [rsp+mmsize*3] ++ %define bm [rsp+mmsize*4] ++ SUB rsp, pad ++ shl r2d, 2 ++ shl r3d, 2 ++ LOAD_AB m4, m5, r2d, r3d ++ mov r3, 32/mmsize ++ mov r2, r0 ++ sub r0, r1 ++ mova am, m4 ++ sub r0, r1 ++ mova bm, m5 ++ sub r0, r1 ++.loop: ++ mova m0, [r0+r1] ++ mova m1, [r0+r1*2] ++ mova m2, [r2] ++ mova m3, [r2+r1] ++ ++ LOAD_MASK m0, m1, m2, m3, am, bm, m7, m4, m6 ++ LOAD_TC m6, r4 ++ mova tcm, m6 ++ ++ mova m5, [r0] ++ LUMA_DEBLOCK_ONE m1, m0, ms1 ++ mova [r0+r1], m5 ++ ++ mova m5, [r2+r1*2] ++ LUMA_DEBLOCK_ONE m2, m3, ms2 ++ mova [r2+r1], m5 ++ ++ pxor m5, m5 ++ mova m6, tcm ++ pcmpgtw m5, tcm ++ psubw m6, ms1 ++ pandn m5, m7 ++ psubw m6, ms2 ++ pand m5, m6 ++ DEBLOCK_P0_Q0 m1, m2, m0, m3, m5, m7, m6 ++ mova [r0+r1*2], m1 ++ mova [r2], m2 ++ ++ add r0, mmsize ++ add r2, mmsize ++ add r4, mmsize/8 ++ dec r3 ++ jg .loop ++ ADD rsp, pad ++ RET ++ ++cglobal deblock_h_luma_10_%1, 5,6,8*(mmsize/16) ++ %assign pad 7*mmsize+12-(stack_offset&15) ++ %define tcm [rsp] ++ %define ms1 [rsp+mmsize] ++ %define ms2 [rsp+mmsize*2] ++ %define p1m [rsp+mmsize*3] ++ %define p2m [rsp+mmsize*4] ++ %define am [rsp+mmsize*5] ++ %define bm [rsp+mmsize*6] ++ SUB rsp, pad ++ shl r2d, 2 ++ shl r3d, 2 ++ LOAD_AB m4, m5, r2d, r3d ++ mov r3, r1 ++ mova am, m4 ++ add r3, r1 ++ mov r5, 32/mmsize ++ mova bm, m5 ++ add r3, r1 ++%if mmsize == 16 ++ mov r2, r0 ++ add r2, r3 ++%endif ++.loop: ++%if mmsize == 8 ++ movq m2, [r0-8] ; y q2 q1 q0 ++ movq m7, [r0+0] ++ movq m5, [r0+r1-8] ++ movq m3, [r0+r1+0] ++ movq m0, [r0+r1*2-8] ++ movq m6, [r0+r1*2+0] ++ movq m1, [r0+r3-8] ++ TRANSPOSE4x4W 2, 5, 0, 1, 4 ++ SWAP 2, 7 ++ movq m7, [r0+r3] ++ TRANSPOSE4x4W 2, 3, 6, 7, 4 ++%else ++ movu m5, [r0-8] ; y q2 q1 q0 p0 p1 p2 x ++ movu m0, [r0+r1-8] ++ movu m2, [r0+r1*2-8] ++ movu m3, [r2-8] ++ TRANSPOSE4x4W 5, 0, 2, 3, 6 ++ mova tcm, m3 ++ ++ movu m4, [r2+r1-8] ++ movu m1, [r2+r1*2-8] ++ movu m3, [r2+r3-8] ++ movu m7, [r2+r1*4-8] ++ TRANSPOSE4x4W 4, 1, 3, 7, 6 ++ ++ mova m6, tcm ++ punpcklqdq m6, m7 ++ punpckhqdq m5, m4 ++ SBUTTERFLY qdq, 0, 1, 7 ++ SBUTTERFLY qdq, 2, 3, 7 ++%endif ++ ++ mova p2m, m6 ++ LOAD_MASK m0, m1, m2, m3, am, bm, m7, m4, m6 ++ LOAD_TC m6, r4 ++ mova tcm, m6 ++ ++ LUMA_DEBLOCK_ONE m1, m0, ms1 ++ mova p1m, m5 ++ ++ mova m5, p2m ++ LUMA_DEBLOCK_ONE m2, m3, ms2 ++ mova p2m, m5 ++ ++ pxor m5, m5 ++ mova m6, tcm ++ pcmpgtw m5, tcm ++ psubw m6, ms1 ++ pandn m5, m7 ++ psubw m6, ms2 ++ pand m5, m6 ++ DEBLOCK_P0_Q0 m1, m2, m0, m3, m5, m7, m6 ++ mova m0, p1m ++ mova m3, p2m ++ TRANSPOSE4x4W 0, 1, 2, 3, 4 ++ LUMA_H_STORE r2, r3 ++ ++ add r4, mmsize/8 ++ lea r0, [r0+r1*(mmsize/2)] ++ lea r2, [r2+r1*(mmsize/2)] ++ dec r5 ++ jg .loop ++ ADD rsp, pad ++ RET ++%endmacro ++ ++INIT_XMM ++%ifdef ARCH_X86_64 ++; in: m0=p1, m1=p0, m2=q0, m3=q1, m8=p2, m9=q2 ++; m12=alpha, m13=beta ++; out: m0=p1', m3=q1', m1=p0', m2=q0' ++; clobbers: m4, m5, m6, m7, m10, m11, m14 ++%macro DEBLOCK_LUMA_INTER_SSE2 0 ++ LOAD_MASK m0, m1, m2, m3, m12, m13, m7, m4, m6 ++ LOAD_TC m6, r4 ++ DIFF_LT m8, m1, m13, m10, m4 ++ DIFF_LT m9, m2, m13, m11, m4 ++ pand m6, m7 ++ ++ mova m14, m6 ++ pxor m4, m4 ++ pcmpgtw m6, m4 ++ pand m6, m14 ++ ++ mova m5, m10 ++ pand m5, m6 ++ LUMA_Q1 m8, m0, m1, m2, m5, m4 ++ ++ mova m5, m11 ++ pand m5, m6 ++ LUMA_Q1 m9, m3, m1, m2, m5, m4 ++ ++ pxor m4, m4 ++ psubw m6, m10 ++ pcmpgtw m4, m14 ++ pandn m4, m7 ++ psubw m6, m11 ++ pand m4, m6 ++ DEBLOCK_P0_Q0 m1, m2, m0, m3, m4, m5, m6 ++ ++ SWAP 0, 8 ++ SWAP 3, 9 ++%endmacro ++ ++%macro DEBLOCK_LUMA_64 1 ++cglobal deblock_v_luma_10_%1, 5,5,15 ++ %define p2 m8 ++ %define p1 m0 ++ %define p0 m1 ++ %define q0 m2 ++ %define q1 m3 ++ %define q2 m9 ++ %define mask0 m7 ++ %define mask1 m10 ++ %define mask2 m11 ++ shl r2d, 2 ++ shl r3d, 2 ++ LOAD_AB m12, m13, r2d, r3d ++ mov r2, r0 ++ sub r0, r1 ++ sub r0, r1 ++ sub r0, r1 ++ mov r3, 2 ++.loop: ++ mova p2, [r0] ++ mova p1, [r0+r1] ++ mova p0, [r0+r1*2] ++ mova q0, [r2] ++ mova q1, [r2+r1] ++ mova q2, [r2+r1*2] ++ DEBLOCK_LUMA_INTER_SSE2 ++ mova [r0+r1], p1 ++ mova [r0+r1*2], p0 ++ mova [r2], q0 ++ mova [r2+r1], q1 ++ add r0, mmsize ++ add r2, mmsize ++ add r4, 2 ++ dec r3 ++ jg .loop ++ REP_RET ++ ++cglobal deblock_h_luma_10_%1, 5,7,15 ++ shl r2d, 2 ++ shl r3d, 2 ++ LOAD_AB m12, m13, r2d, r3d ++ mov r2, r1 ++ add r2, r1 ++ add r2, r1 ++ mov r5, r0 ++ add r5, r2 ++ mov r6, 2 ++.loop: ++ movu m8, [r0-8] ; y q2 q1 q0 p0 p1 p2 x ++ movu m0, [r0+r1-8] ++ movu m2, [r0+r1*2-8] ++ movu m9, [r5-8] ++ movu m5, [r5+r1-8] ++ movu m1, [r5+r1*2-8] ++ movu m3, [r5+r2-8] ++ movu m7, [r5+r1*4-8] ++ ++ TRANSPOSE4x4W 8, 0, 2, 9, 10 ++ TRANSPOSE4x4W 5, 1, 3, 7, 10 ++ ++ punpckhqdq m8, m5 ++ SBUTTERFLY qdq, 0, 1, 10 ++ SBUTTERFLY qdq, 2, 3, 10 ++ punpcklqdq m9, m7 ++ ++ DEBLOCK_LUMA_INTER_SSE2 ++ ++ TRANSPOSE4x4W 0, 1, 2, 3, 4 ++ LUMA_H_STORE r5, r2 ++ add r4, 2 ++ lea r0, [r0+r1*8] ++ lea r5, [r5+r1*8] ++ dec r6 ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_XMM ++DEBLOCK_LUMA_64 sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA_64 avx ++%endif ++%endif ++ ++%macro SWAPMOVA 2 ++%ifid %1 ++ SWAP %1, %2 ++%else ++ mova %1, %2 ++%endif ++%endmacro ++ ++; in: t0-t2: tmp registers ++; %1=p0 %2=p1 %3=p2 %4=p3 %5=q0 %6=q1 %7=mask0 ++; %8=mask1p %9=2 %10=p0' %11=p1' %12=p2' ++%macro LUMA_INTRA_P012 12 ; p0..p3 in memory ++%ifdef ARCH_X86_64 ++ paddw t0, %3, %2 ++ mova t2, %4 ++ paddw t2, %3 ++%else ++ mova t0, %3 ++ mova t2, %4 ++ paddw t0, %2 ++ paddw t2, %3 ++%endif ++ paddw t0, %1 ++ paddw t2, t2 ++ paddw t0, %5 ++ paddw t2, %9 ++ paddw t0, %9 ; (p2 + p1 + p0 + q0 + 2) ++ paddw t2, t0 ; (2*p3 + 3*p2 + p1 + p0 + q0 + 4) ++ ++ psrlw t2, 3 ++ psrlw t1, t0, 2 ++ psubw t2, %3 ++ psubw t1, %2 ++ pand t2, %8 ++ pand t1, %8 ++ paddw t2, %3 ++ paddw t1, %2 ++ SWAPMOVA %11, t1 ++ ++ psubw t1, t0, %3 ++ paddw t0, t0 ++ psubw t1, %5 ++ psubw t0, %3 ++ paddw t1, %6 ++ paddw t1, %2 ++ paddw t0, %6 ++ psrlw t1, 2 ; (2*p1 + p0 + q1 + 2)/4 ++ psrlw t0, 3 ; (p2 + 2*p1 + 2*p0 + 2*q0 + q1 + 4)>>3 ++ ++ pxor t0, t1 ++ pxor t1, %1 ++ pand t0, %8 ++ pand t1, %7 ++ pxor t0, t1 ++ pxor t0, %1 ++ SWAPMOVA %10, t0 ++ SWAPMOVA %12, t2 ++%endmacro ++ ++%macro LUMA_INTRA_INIT 1 ++ %xdefine pad %1*mmsize+((gprsize*3) % mmsize)-(stack_offset&15) ++ %define t0 m4 ++ %define t1 m5 ++ %define t2 m6 ++ %define t3 m7 ++ %assign i 4 ++%rep %1 ++ CAT_XDEFINE t, i, [rsp+mmsize*(i-4)] ++ %assign i i+1 ++%endrep ++ SUB rsp, pad ++%endmacro ++ ++; in: %1-%3=tmp, %4=p2, %5=q2 ++%macro LUMA_INTRA_INTER 5 ++ LOAD_AB t0, t1, r2d, r3d ++ mova %1, t0 ++ LOAD_MASK m0, m1, m2, m3, %1, t1, t0, t2, t3 ++%ifdef ARCH_X86_64 ++ mova %2, t0 ; mask0 ++ psrlw t3, %1, 2 ++%else ++ mova t3, %1 ++ mova %2, t0 ; mask0 ++ psrlw t3, 2 ++%endif ++ paddw t3, [pw_2] ; alpha/4+2 ++ DIFF_LT m1, m2, t3, t2, t0 ; t2 = |p0-q0| < alpha/4+2 ++ pand t2, %2 ++ mova t3, %5 ; q2 ++ mova %1, t2 ; mask1 ++ DIFF_LT t3, m2, t1, t2, t0 ; t2 = |q2-q0| < beta ++ pand t2, %1 ++ mova t3, %4 ; p2 ++ mova %3, t2 ; mask1q ++ DIFF_LT t3, m1, t1, t2, t0 ; t2 = |p2-p0| < beta ++ pand t2, %1 ++ mova %1, t2 ; mask1p ++%endmacro ++ ++%macro LUMA_H_INTRA_LOAD 0 ++%if mmsize == 8 ++ movu t0, [r0-8] ++ movu t1, [r0+r1-8] ++ movu m0, [r0+r1*2-8] ++ movu m1, [r0+r4-8] ++ TRANSPOSE4x4W 4, 5, 0, 1, 2 ++ mova t4, t0 ; p3 ++ mova t5, t1 ; p2 ++ ++ movu m2, [r0] ++ movu m3, [r0+r1] ++ movu t0, [r0+r1*2] ++ movu t1, [r0+r4] ++ TRANSPOSE4x4W 2, 3, 4, 5, 6 ++ mova t6, t0 ; q2 ++ mova t7, t1 ; q3 ++%else ++ movu t0, [r0-8] ++ movu t1, [r0+r1-8] ++ movu m0, [r0+r1*2-8] ++ movu m1, [r0+r5-8] ++ movu m2, [r4-8] ++ movu m3, [r4+r1-8] ++ movu t2, [r4+r1*2-8] ++ movu t3, [r4+r5-8] ++ TRANSPOSE8x8W 4, 5, 0, 1, 2, 3, 6, 7, t4, t5 ++ mova t4, t0 ; p3 ++ mova t5, t1 ; p2 ++ mova t6, t2 ; q2 ++ mova t7, t3 ; q3 ++%endif ++%endmacro ++ ++; in: %1=q3 %2=q2' %3=q1' %4=q0' %5=p0' %6=p1' %7=p2' %8=p3 %9=tmp ++%macro LUMA_H_INTRA_STORE 9 ++%if mmsize == 8 ++ TRANSPOSE4x4W %1, %2, %3, %4, %9 ++ movq [r0-8], m%1 ++ movq [r0+r1-8], m%2 ++ movq [r0+r1*2-8], m%3 ++ movq [r0+r4-8], m%4 ++ movq m%1, %8 ++ TRANSPOSE4x4W %5, %6, %7, %1, %9 ++ movq [r0], m%5 ++ movq [r0+r1], m%6 ++ movq [r0+r1*2], m%7 ++ movq [r0+r4], m%1 ++%else ++ TRANSPOSE2x4x4W %1, %2, %3, %4, %9 ++ movq [r0-8], m%1 ++ movq [r0+r1-8], m%2 ++ movq [r0+r1*2-8], m%3 ++ movq [r0+r5-8], m%4 ++ movhps [r4-8], m%1 ++ movhps [r4+r1-8], m%2 ++ movhps [r4+r1*2-8], m%3 ++ movhps [r4+r5-8], m%4 ++%ifnum %8 ++ SWAP %1, %8 ++%else ++ mova m%1, %8 ++%endif ++ TRANSPOSE2x4x4W %5, %6, %7, %1, %9 ++ movq [r0], m%5 ++ movq [r0+r1], m%6 ++ movq [r0+r1*2], m%7 ++ movq [r0+r5], m%1 ++ movhps [r4], m%5 ++ movhps [r4+r1], m%6 ++ movhps [r4+r1*2], m%7 ++ movhps [r4+r5], m%1 ++%endif ++%endmacro ++ ++%ifdef ARCH_X86_64 ++;----------------------------------------------------------------------------- ++; void deblock_v_luma_intra( uint16_t *pix, int stride, int alpha, int beta ) ++;----------------------------------------------------------------------------- ++%macro DEBLOCK_LUMA_INTRA_64 1 ++cglobal deblock_v_luma_intra_10_%1, 4,7,16 ++ %define t0 m1 ++ %define t1 m2 ++ %define t2 m4 ++ %define p2 m8 ++ %define p1 m9 ++ %define p0 m10 ++ %define q0 m11 ++ %define q1 m12 ++ %define q2 m13 ++ %define aa m5 ++ %define bb m14 ++ lea r4, [r1*4] ++ lea r5, [r1*3] ; 3*stride ++ neg r4 ++ add r4, r0 ; pix-4*stride ++ mov r6, 2 ++ mova m0, [pw_2] ++ shl r2d, 2 ++ shl r3d, 2 ++ LOAD_AB aa, bb, r2d, r3d ++.loop ++ mova p2, [r4+r1] ++ mova p1, [r4+2*r1] ++ mova p0, [r4+r5] ++ mova q0, [r0] ++ mova q1, [r0+r1] ++ mova q2, [r0+2*r1] ++ ++ LOAD_MASK p1, p0, q0, q1, aa, bb, m3, t0, t1 ++ mova t2, aa ++ psrlw t2, 2 ++ paddw t2, m0 ; alpha/4+2 ++ DIFF_LT p0, q0, t2, m6, t0 ; m6 = |p0-q0| < alpha/4+2 ++ DIFF_LT p2, p0, bb, t1, t0 ; m7 = |p2-p0| < beta ++ DIFF_LT q2, q0, bb, m7, t0 ; t1 = |q2-q0| < beta ++ pand m6, m3 ++ pand m7, m6 ++ pand m6, t1 ++ LUMA_INTRA_P012 p0, p1, p2, [r4], q0, q1, m3, m6, m0, [r4+r5], [r4+2*r1], [r4+r1] ++ LUMA_INTRA_P012 q0, q1, q2, [r0+r5], p0, p1, m3, m7, m0, [r0], [r0+r1], [r0+2*r1] ++ add r0, mmsize ++ add r4, mmsize ++ dec r6 ++ jg .loop ++ REP_RET ++ ++;----------------------------------------------------------------------------- ++; void deblock_h_luma_intra( uint16_t *pix, int stride, int alpha, int beta ) ++;----------------------------------------------------------------------------- ++cglobal deblock_h_luma_intra_10_%1, 4,7,16 ++ %define t0 m15 ++ %define t1 m14 ++ %define t2 m2 ++ %define q3 m5 ++ %define q2 m8 ++ %define q1 m9 ++ %define q0 m10 ++ %define p0 m11 ++ %define p1 m12 ++ %define p2 m13 ++ %define p3 m4 ++ %define spill [rsp] ++ %assign pad 24-(stack_offset&15) ++ SUB rsp, pad ++ lea r4, [r1*4] ++ lea r5, [r1*3] ; 3*stride ++ add r4, r0 ; pix+4*stride ++ mov r6, 2 ++ mova m0, [pw_2] ++ shl r2d, 2 ++ shl r3d, 2 ++.loop ++ movu q3, [r0-8] ++ movu q2, [r0+r1-8] ++ movu q1, [r0+r1*2-8] ++ movu q0, [r0+r5-8] ++ movu p0, [r4-8] ++ movu p1, [r4+r1-8] ++ movu p2, [r4+r1*2-8] ++ movu p3, [r4+r5-8] ++ TRANSPOSE8x8W 5, 8, 9, 10, 11, 12, 13, 4, 1 ++ ++ LOAD_AB m1, m2, r2d, r3d ++ LOAD_MASK q1, q0, p0, p1, m1, m2, m3, t0, t1 ++ psrlw m1, 2 ++ paddw m1, m0 ; alpha/4+2 ++ DIFF_LT p0, q0, m1, m6, t0 ; m6 = |p0-q0| < alpha/4+2 ++ DIFF_LT q2, q0, m2, t1, t0 ; t1 = |q2-q0| < beta ++ DIFF_LT p0, p2, m2, m7, t0 ; m7 = |p2-p0| < beta ++ pand m6, m3 ++ pand m7, m6 ++ pand m6, t1 ++ ++ mova spill, q3 ++ LUMA_INTRA_P012 q0, q1, q2, q3, p0, p1, m3, m6, m0, m5, m1, q2 ++ LUMA_INTRA_P012 p0, p1, p2, p3, q0, q1, m3, m7, m0, p0, m6, p2 ++ mova m7, spill ++ ++ LUMA_H_INTRA_STORE 7, 8, 1, 5, 11, 6, 13, 4, 14 ++ ++ lea r0, [r0+r1*8] ++ lea r4, [r4+r1*8] ++ dec r6 ++ jg .loop ++ ADD rsp, pad ++ RET ++%endmacro ++ ++INIT_XMM ++DEBLOCK_LUMA_INTRA_64 sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA_INTRA_64 avx ++%endif ++ ++%endif ++ ++%macro DEBLOCK_LUMA_INTRA 1 ++;----------------------------------------------------------------------------- ++; void deblock_v_luma_intra( uint16_t *pix, int stride, int alpha, int beta ) ++;----------------------------------------------------------------------------- ++cglobal deblock_v_luma_intra_10_%1, 4,7,8*(mmsize/16) ++ LUMA_INTRA_INIT 3 ++ lea r4, [r1*4] ++ lea r5, [r1*3] ++ neg r4 ++ add r4, r0 ++ mov r6, 32/mmsize ++ shl r2d, 2 ++ shl r3d, 2 ++.loop: ++ mova m0, [r4+r1*2] ; p1 ++ mova m1, [r4+r5] ; p0 ++ mova m2, [r0] ; q0 ++ mova m3, [r0+r1] ; q1 ++ LUMA_INTRA_INTER t4, t5, t6, [r4+r1], [r0+r1*2] ++ LUMA_INTRA_P012 m1, m0, t3, [r4], m2, m3, t5, t4, [pw_2], [r4+r5], [r4+2*r1], [r4+r1] ++ mova t3, [r0+r1*2] ; q2 ++ LUMA_INTRA_P012 m2, m3, t3, [r0+r5], m1, m0, t5, t6, [pw_2], [r0], [r0+r1], [r0+2*r1] ++ add r0, mmsize ++ add r4, mmsize ++ dec r6 ++ jg .loop ++ ADD rsp, pad ++ RET ++ ++;----------------------------------------------------------------------------- ++; void deblock_h_luma_intra( uint16_t *pix, int stride, int alpha, int beta ) ++;----------------------------------------------------------------------------- ++cglobal deblock_h_luma_intra_10_%1, 4,7,8*(mmsize/16) ++ LUMA_INTRA_INIT 8 ++%if mmsize == 8 ++ lea r4, [r1*3] ++ mov r5, 32/mmsize ++%else ++ lea r4, [r1*4] ++ lea r5, [r1*3] ; 3*stride ++ add r4, r0 ; pix+4*stride ++ mov r6, 32/mmsize ++%endif ++ shl r2d, 2 ++ shl r3d, 2 ++.loop: ++ LUMA_H_INTRA_LOAD ++ LUMA_INTRA_INTER t8, t9, t10, t5, t6 ++ ++ LUMA_INTRA_P012 m1, m0, t3, t4, m2, m3, t9, t8, [pw_2], t8, t5, t11 ++ mova t3, t6 ; q2 ++ LUMA_INTRA_P012 m2, m3, t3, t7, m1, m0, t9, t10, [pw_2], m4, t6, m5 ++ ++ mova m2, t4 ++ mova m0, t11 ++ mova m1, t5 ++ mova m3, t8 ++ mova m6, t6 ++ ++ LUMA_H_INTRA_STORE 2, 0, 1, 3, 4, 6, 5, t7, 7 ++ ++ lea r0, [r0+r1*(mmsize/2)] ++%if mmsize == 8 ++ dec r5 ++%else ++ lea r4, [r4+r1*(mmsize/2)] ++ dec r6 ++%endif ++ jg .loop ++ ADD rsp, pad ++ RET ++%endmacro ++ ++%ifndef ARCH_X86_64 ++INIT_MMX ++DEBLOCK_LUMA mmxext ++DEBLOCK_LUMA_INTRA mmxext ++INIT_XMM ++DEBLOCK_LUMA sse2 ++DEBLOCK_LUMA_INTRA sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA avx ++DEBLOCK_LUMA_INTRA avx ++%endif ++%endif ++ ++; in: %1=p0, %2=q0, %3=p1, %4=q1, %5=mask, %6=tmp, %7=tmp ++; out: %1=p0', %2=q0' ++%macro CHROMA_DEBLOCK_P0_Q0_INTRA 7 ++ mova %6, [pw_2] ++ paddw %6, %3 ++ paddw %6, %4 ++ paddw %7, %6, %2 ++ paddw %6, %1 ++ paddw %6, %3 ++ paddw %7, %4 ++ psraw %6, 2 ++ psraw %7, 2 ++ psubw %6, %1 ++ psubw %7, %2 ++ pand %6, %5 ++ pand %7, %5 ++ paddw %1, %6 ++ paddw %2, %7 ++%endmacro ++ ++%macro CHROMA_V_LOAD 1 ++ mova m0, [r0] ; p1 ++ mova m1, [r0+r1] ; p0 ++ mova m2, [%1] ; q0 ++ mova m3, [%1+r1] ; q1 ++%endmacro ++ ++%macro CHROMA_V_STORE 0 ++ mova [r0+1*r1], m1 ++ mova [r0+2*r1], m2 ++%endmacro ++ ++%macro CHROMA_V_LOAD_TC 2 ++ movd %1, [%2] ++ punpcklbw %1, %1 ++ punpcklwd %1, %1 ++ psraw %1, 6 ++%endmacro ++ ++%macro DEBLOCK_CHROMA 1 ++;----------------------------------------------------------------------------- ++; void deblock_v_chroma( uint16_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++;----------------------------------------------------------------------------- ++cglobal deblock_v_chroma_10_%1, 5,7-(mmsize/16),8*(mmsize/16) ++ mov r5, r0 ++ sub r0, r1 ++ sub r0, r1 ++ shl r2d, 2 ++ shl r3d, 2 ++%if mmsize < 16 ++ mov r6, 16/mmsize ++.loop: ++%endif ++ CHROMA_V_LOAD r5 ++ LOAD_AB m4, m5, r2d, r3d ++ LOAD_MASK m0, m1, m2, m3, m4, m5, m7, m6, m4 ++ pxor m4, m4 ++ CHROMA_V_LOAD_TC m6, r4 ++ psubw m6, [pw_3] ++ pmaxsw m6, m4 ++ pand m7, m6 ++ DEBLOCK_P0_Q0 m1, m2, m0, m3, m7, m5, m6 ++ CHROMA_V_STORE ++%if mmsize < 16 ++ add r0, mmsize ++ add r5, mmsize ++ add r4, mmsize/4 ++ dec r6 ++ jg .loop ++ REP_RET ++%else ++ RET ++%endif ++ ++;----------------------------------------------------------------------------- ++; void deblock_v_chroma_intra( uint16_t *pix, int stride, int alpha, int beta ) ++;----------------------------------------------------------------------------- ++cglobal deblock_v_chroma_intra_10_%1, 4,6-(mmsize/16),8*(mmsize/16) ++ mov r4, r0 ++ sub r0, r1 ++ sub r0, r1 ++ shl r2d, 2 ++ shl r3d, 2 ++%if mmsize < 16 ++ mov r5, 16/mmsize ++.loop: ++%endif ++ CHROMA_V_LOAD r4 ++ LOAD_AB m4, m5, r2d, r3d ++ LOAD_MASK m0, m1, m2, m3, m4, m5, m7, m6, m4 ++ CHROMA_DEBLOCK_P0_Q0_INTRA m1, m2, m0, m3, m7, m5, m6 ++ CHROMA_V_STORE ++%if mmsize < 16 ++ add r0, mmsize ++ add r4, mmsize ++ dec r5 ++ jg .loop ++ REP_RET ++%else ++ RET ++%endif ++%endmacro ++ ++%ifndef ARCH_X86_64 ++INIT_MMX ++DEBLOCK_CHROMA mmxext ++%endif ++INIT_XMM ++DEBLOCK_CHROMA sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_CHROMA avx ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_deblock.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_deblock.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_deblock.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_deblock.asm 2012-05-14 14:08:54.536344048 +0200 +@@ -1,10 +1,11 @@ + ;***************************************************************************** +-;* MMX/SSE2-optimized H.264 deblocking code ++;* MMX/SSE2/AVX-optimized H.264 deblocking code + ;***************************************************************************** +-;* Copyright (C) 2005-2008 x264 project ++;* Copyright (C) 2005-2011 x264 project + ;* + ;* Authors: Loren Merritt + ;* Jason Garrett-Glaser ++;* Oskar Arvidsson + ;* + ;* This file is part of FFmpeg. + ;* +@@ -20,102 +21,100 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + +-SECTION_RODATA ++SECTION .text + + cextern pb_0 + cextern pb_1 + cextern pb_3 + cextern pb_A1 + +-SECTION .text +- + ; expands to [base],...,[base+7*stride] + %define PASS8ROWS(base, base3, stride, stride3) \ + [base], [base+stride], [base+stride*2], [base3], \ + [base3+stride], [base3+stride*2], [base3+stride3], [base3+stride*4] + +-; in: 8 rows of 4 bytes in %1..%8 ++%define PASS8ROWS(base, base3, stride, stride3, offset) \ ++ PASS8ROWS(base+offset, base3+offset, stride, stride3) ++ ++; in: 8 rows of 4 bytes in %4..%11 + ; out: 4 rows of 8 bytes in m0..m3 +-%macro TRANSPOSE4x8_LOAD 8 +- movd m0, %1 +- movd m2, %2 +- movd m1, %3 +- movd m3, %4 +- punpcklbw m0, m2 +- punpcklbw m1, m3 +- movq m2, m0 +- punpcklwd m0, m1 +- punpckhwd m2, m1 +- +- movd m4, %5 +- movd m6, %6 +- movd m5, %7 +- movd m7, %8 +- punpcklbw m4, m6 +- punpcklbw m5, m7 +- movq m6, m4 +- punpcklwd m4, m5 +- punpckhwd m6, m5 +- +- movq m1, m0 +- movq m3, m2 +- punpckldq m0, m4 +- punpckhdq m1, m4 +- punpckldq m2, m6 +- punpckhdq m3, m6 ++%macro TRANSPOSE4x8_LOAD 11 ++ movh m0, %4 ++ movh m2, %5 ++ movh m1, %6 ++ movh m3, %7 ++ punpckl%1 m0, m2 ++ punpckl%1 m1, m3 ++ mova m2, m0 ++ punpckl%2 m0, m1 ++ punpckh%2 m2, m1 ++ ++ movh m4, %8 ++ movh m6, %9 ++ movh m5, %10 ++ movh m7, %11 ++ punpckl%1 m4, m6 ++ punpckl%1 m5, m7 ++ mova m6, m4 ++ punpckl%2 m4, m5 ++ punpckh%2 m6, m5 ++ ++ punpckh%3 m1, m0, m4 ++ punpckh%3 m3, m2, m6 ++ punpckl%3 m0, m4 ++ punpckl%3 m2, m6 + %endmacro + + ; in: 4 rows of 8 bytes in m0..m3 + ; out: 8 rows of 4 bytes in %1..%8 +-%macro TRANSPOSE8x4_STORE 8 +- movq m4, m0 +- movq m5, m1 +- movq m6, m2 +- punpckhdq m4, m4 +- punpckhdq m5, m5 +- punpckhdq m6, m6 ++%macro TRANSPOSE8x4B_STORE 8 ++ punpckhdq m4, m0, m0 ++ punpckhdq m5, m1, m1 ++ punpckhdq m6, m2, m2 + + punpcklbw m0, m1 + punpcklbw m2, m3 +- movq m1, m0 +- punpcklwd m0, m2 +- punpckhwd m1, m2 +- movd %1, m0 +- punpckhdq m0, m0 +- movd %2, m0 +- movd %3, m1 ++ punpcklwd m1, m0, m2 ++ punpckhwd m0, m2 ++ movh %1, m1 + punpckhdq m1, m1 +- movd %4, m1 ++ movh %2, m1 ++ movh %3, m0 ++ punpckhdq m0, m0 ++ movh %4, m0 + + punpckhdq m3, m3 + punpcklbw m4, m5 + punpcklbw m6, m3 +- movq m5, m4 +- punpcklwd m4, m6 +- punpckhwd m5, m6 +- movd %5, m4 +- punpckhdq m4, m4 +- movd %6, m4 +- movd %7, m5 ++ punpcklwd m5, m4, m6 ++ punpckhwd m4, m6 ++ movh %5, m5 + punpckhdq m5, m5 +- movd %8, m5 ++ movh %6, m5 ++ movh %7, m4 ++ punpckhdq m4, m4 ++ movh %8, m4 ++%endmacro ++ ++%macro TRANSPOSE4x8B_LOAD 8 ++ TRANSPOSE4x8_LOAD bw, wd, dq, %1, %2, %3, %4, %5, %6, %7, %8 + %endmacro + + %macro SBUTTERFLY3 4 +- movq %4, %2 ++ punpckh%1 %4, %2, %3 + punpckl%1 %2, %3 +- punpckh%1 %4, %3 + %endmacro + + ; in: 8 rows of 8 (only the middle 6 pels are used) in %1..%8 + ; out: 6 rows of 8 in [%9+0*16] .. [%9+5*16] + %macro TRANSPOSE6x8_MEM 9 ++ RESET_MM_PERMUTATION + movq m0, %1 + movq m1, %2 + movq m2, %3 +@@ -123,30 +122,32 @@ + movq m4, %5 + movq m5, %6 + movq m6, %7 +- SBUTTERFLY3 bw, m0, m1, m7 +- SBUTTERFLY3 bw, m2, m3, m1 +- SBUTTERFLY3 bw, m4, m5, m3 +- movq [%9+0x10], m1 +- SBUTTERFLY3 bw, m6, %8, m5 +- SBUTTERFLY3 wd, m0, m2, m1 +- SBUTTERFLY3 wd, m4, m6, m2 ++ SBUTTERFLY bw, 0, 1, 7 ++ SBUTTERFLY bw, 2, 3, 7 ++ SBUTTERFLY bw, 4, 5, 7 ++ movq [%9+0x10], m3 ++ SBUTTERFLY3 bw, m6, %8, m7 ++ SBUTTERFLY wd, 0, 2, 3 ++ SBUTTERFLY wd, 4, 6, 3 + punpckhdq m0, m4 + movq [%9+0x00], m0 +- SBUTTERFLY3 wd, m7, [%9+0x10], m6 +- SBUTTERFLY3 wd, m3, m5, m4 +- SBUTTERFLY3 dq, m7, m3, m0 +- SBUTTERFLY3 dq, m1, m2, m5 +- punpckldq m6, m4 +- movq [%9+0x10], m1 +- movq [%9+0x20], m5 +- movq [%9+0x30], m7 +- movq [%9+0x40], m0 +- movq [%9+0x50], m6 ++ SBUTTERFLY3 wd, m1, [%9+0x10], m3 ++ SBUTTERFLY wd, 5, 7, 0 ++ SBUTTERFLY dq, 1, 5, 0 ++ SBUTTERFLY dq, 2, 6, 0 ++ punpckldq m3, m7 ++ movq [%9+0x10], m2 ++ movq [%9+0x20], m6 ++ movq [%9+0x30], m1 ++ movq [%9+0x40], m5 ++ movq [%9+0x50], m3 ++ RESET_MM_PERMUTATION + %endmacro + + ; in: 8 rows of 8 in %1..%8 + ; out: 8 rows of 8 in %9..%16 + %macro TRANSPOSE8x8_MEM 16 ++ RESET_MM_PERMUTATION + movq m0, %1 + movq m1, %2 + movq m2, %3 +@@ -154,38 +155,44 @@ + movq m4, %5 + movq m5, %6 + movq m6, %7 +- SBUTTERFLY3 bw, m0, m1, m7 +- SBUTTERFLY3 bw, m2, m3, m1 +- SBUTTERFLY3 bw, m4, m5, m3 +- SBUTTERFLY3 bw, m6, %8, m5 +- movq %9, m3 +- SBUTTERFLY3 wd, m0, m2, m3 +- SBUTTERFLY3 wd, m4, m6, m2 +- SBUTTERFLY3 wd, m7, m1, m6 +- movq %11, m2 +- movq m2, %9 +- SBUTTERFLY3 wd, m2, m5, m1 +- SBUTTERFLY3 dq, m0, m4, m5 +- SBUTTERFLY3 dq, m7, m2, m4 ++ SBUTTERFLY bw, 0, 1, 7 ++ SBUTTERFLY bw, 2, 3, 7 ++ SBUTTERFLY bw, 4, 5, 7 ++ SBUTTERFLY3 bw, m6, %8, m7 ++ movq %9, m5 ++ SBUTTERFLY wd, 0, 2, 5 ++ SBUTTERFLY wd, 4, 6, 5 ++ SBUTTERFLY wd, 1, 3, 5 ++ movq %11, m6 ++ movq m6, %9 ++ SBUTTERFLY wd, 6, 7, 5 ++ SBUTTERFLY dq, 0, 4, 5 ++ SBUTTERFLY dq, 1, 6, 5 + movq %9, m0 +- movq %10, m5 +- movq %13, m7 +- movq %14, m4 +- SBUTTERFLY3 dq, m3, %11, m0 +- SBUTTERFLY3 dq, m6, m1, m5 +- movq %11, m3 ++ movq %10, m4 ++ movq %13, m1 ++ movq %14, m6 ++ SBUTTERFLY3 dq, m2, %11, m0 ++ SBUTTERFLY dq, 3, 7, 4 ++ movq %11, m2 + movq %12, m0 +- movq %15, m6 +- movq %16, m5 ++ movq %15, m3 ++ movq %16, m7 ++ RESET_MM_PERMUTATION + %endmacro + + ; out: %4 = |%1-%2|>%3 + ; clobbers: %5 + %macro DIFF_GT 5 ++%if avx_enabled == 0 + mova %5, %2 + mova %4, %1 + psubusb %5, %1 + psubusb %4, %2 ++%else ++ psubusb %5, %2, %1 ++ psubusb %4, %1, %2 ++%endif + por %4, %5 + psubusb %4, %3 + %endmacro +@@ -193,32 +200,28 @@ + ; out: %4 = |%1-%2|>%3 + ; clobbers: %5 + %macro DIFF_GT2 5 ++%ifdef ARCH_X86_64 ++ psubusb %5, %2, %1 ++ psubusb %4, %1, %2 ++%else + mova %5, %2 + mova %4, %1 + psubusb %5, %1 + psubusb %4, %2 ++%endif + psubusb %5, %3 + psubusb %4, %3 + pcmpeqb %4, %5 + %endmacro + +-%macro SPLATW 1 +-%ifidn m0, xmm0 +- pshuflw %1, %1, 0 +- punpcklqdq %1, %1 +-%else +- pshufw %1, %1, 0 +-%endif +-%endmacro +- + ; in: m0=p1 m1=p0 m2=q0 m3=q1 %1=alpha-1 %2=beta-1 + ; out: m5=beta-1, m7=mask, %3=alpha-1 + ; clobbers: m4,m6 + %macro LOAD_MASK 2-3 + movd m4, %1 + movd m5, %2 +- SPLATW m4 +- SPLATW m5 ++ SPLATW m4, m4 ++ SPLATW m5, m5 + packuswb m4, m4 ; 16x alpha-1 + packuswb m5, m5 ; 16x beta-1 + %if %0>2 +@@ -237,18 +240,17 @@ + ; out: m1=p0' m2=q0' + ; clobbers: m0,3-6 + %macro DEBLOCK_P0_Q0 0 +- mova m5, m1 +- pxor m5, m2 ; p0^q0 +- pand m5, [pb_1] ; (p0^q0)&1 + pcmpeqb m4, m4 ++ pxor m5, m1, m2 ; p0^q0 + pxor m3, m4 ++ pand m5, [pb_1] ; (p0^q0)&1 + pavgb m3, m0 ; (p1 - q1 + 256)>>1 +- pavgb m3, [pb_3] ; (((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2 + pxor m4, m1 ++ pavgb m3, [pb_3] ; (((p1 - q1 + 256)>>1)+4)>>1 = 64+2+(p1-q1)>>2 + pavgb m4, m2 ; (q0 - p0 + 256)>>1 + pavgb m3, m5 +- paddusb m3, m4 ; d+128+33 + mova m6, [pb_A1] ++ paddusb m3, m4 ; d+128+33 + psubusb m6, m3 + psubusb m3, [pb_A1] + pminub m6, m7 +@@ -264,14 +266,12 @@ + ; out: [q1] = clip( (q2+((p0+q0+1)>>1))>>1, q1-tc0, q1+tc0 ) + ; clobbers: q2, tmp, tc0 + %macro LUMA_Q1 6 +- mova %6, m1 +- pavgb %6, m2 ++ pavgb %6, m1, m2 + pavgb %2, %6 ; avg(p2,avg(p0,q0)) + pxor %6, %3 + pand %6, [pb_1] ; (p2^avg(p0,q0))&1 + psubusb %2, %6 ; (p2+((p0+q0+1)>>1))>>1 +- mova %6, %1 +- psubusb %6, %5 ++ psubusb %6, %1, %5 + paddusb %5, %1 + pmaxub %2, %6 + pminub %2, %5 +@@ -280,10 +280,10 @@ + + %ifdef ARCH_X86_64 + ;----------------------------------------------------------------------------- +-; void x264_deblock_v_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void deblock_v_luma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- +-INIT_XMM +-cglobal x264_deblock_v_luma_sse2, 5,5,10 ++%macro DEBLOCK_LUMA 1 ++cglobal deblock_v_luma_8_%1, 5,5,10 + movd m8, [r4] ; tc0 + lea r4, [r1*3] + dec r2d ; alpha-1 +@@ -307,8 +307,7 @@ + movdqa m3, [r4] ; p2 + DIFF_GT2 m1, m3, m5, m6, m7 ; |p2-p0| > beta-1 + pand m6, m9 +- mova m7, m8 +- psubb m7, m6 ++ psubb m7, m8, m6 + pand m6, m8 + LUMA_Q1 m0, m3, [r4], [r4+r1], m6, m4 + +@@ -326,10 +325,10 @@ + RET + + ;----------------------------------------------------------------------------- +-; void x264_deblock_h_luma_sse2( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void deblock_h_luma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- + INIT_MMX +-cglobal x264_deblock_h_luma_sse2, 5,7 ++cglobal deblock_h_luma_8_%1, 5,7 + movsxd r10, r1d + lea r11, [r10+r10*2] + lea r6, [r0-4] +@@ -350,13 +349,13 @@ + + ; vertical filter + ; alpha, beta, tc0 are still in r2d, r3d, r4 +- ; don't backup r6, r5, r10, r11 because x264_deblock_v_luma_sse2 doesn't use them ++ ; don't backup r6, r5, r10, r11 because deblock_v_luma_sse2 doesn't use them + lea r0, [pix_tmp+0x30] + mov r1d, 0x10 + %ifdef WIN64 + mov [rsp+0x20], r4 + %endif +- call x264_deblock_v_luma_sse2 ++ call deblock_v_luma_8_%1 + + ; transpose 16x4 -> original space (only the middle 4 rows were changed by the filter) + add r6, 2 +@@ -365,7 +364,7 @@ + movq m1, [pix_tmp+0x28] + movq m2, [pix_tmp+0x38] + movq m3, [pix_tmp+0x48] +- TRANSPOSE8x4_STORE PASS8ROWS(r6, r5, r10, r11) ++ TRANSPOSE8x4B_STORE PASS8ROWS(r6, r5, r10, r11) + + shl r10, 3 + sub r6, r10 +@@ -375,7 +374,7 @@ + movq m1, [pix_tmp+0x20] + movq m2, [pix_tmp+0x30] + movq m3, [pix_tmp+0x40] +- TRANSPOSE8x4_STORE PASS8ROWS(r6, r5, r10, r11) ++ TRANSPOSE8x4B_STORE PASS8ROWS(r6, r5, r10, r11) + + %ifdef WIN64 + add rsp, 0x98 +@@ -383,14 +382,22 @@ + add rsp, 0x68 + %endif + RET ++%endmacro ++ ++INIT_XMM ++DEBLOCK_LUMA sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA avx ++%endif + + %else + + %macro DEBLOCK_LUMA 3 + ;----------------------------------------------------------------------------- +-; void x264_deblock_v8_luma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void deblock_v8_luma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_%2_luma_%1, 5,5 ++cglobal deblock_%2_luma_8_%1, 5,5 + lea r4, [r1*3] + dec r2 ; alpha-1 + neg r4 +@@ -406,31 +413,29 @@ + LOAD_MASK r2, r3 + + mov r3, r4mp ++ pcmpeqb m3, m3 + movd m4, [r3] ; tc0 + punpcklbw m4, m4 + punpcklbw m4, m4 ; tc = 4x tc0[3], 4x tc0[2], 4x tc0[1], 4x tc0[0] + mova [esp+%3], m4 ; tc +- pcmpeqb m3, m3 + pcmpgtb m4, m3 ++ mova m3, [r4] ; p2 + pand m4, m7 + mova [esp], m4 ; mask + +- mova m3, [r4] ; p2 + DIFF_GT2 m1, m3, m5, m6, m7 ; |p2-p0| > beta-1 + pand m6, m4 + pand m4, [esp+%3] ; tc +- mova m7, m4 +- psubb m7, m6 ++ psubb m7, m4, m6 + pand m6, m4 + LUMA_Q1 m0, m3, [r4], [r4+r1], m6, m4 + + mova m4, [r0+2*r1] ; q2 + DIFF_GT2 m2, m4, m5, m6, m3 ; |q2-q0| > beta-1 +- mova m5, [esp] ; mask +- pand m6, m5 ++ pand m6, [esp] ; mask + mova m5, [esp+%3] ; tc +- pand m5, m6 + psubb m7, m6 ++ pand m5, m6 + mova m3, [r0+r1] + LUMA_Q1 m3, m4, [r0+2*r1], [r0+r1], m5, m6 + +@@ -441,10 +446,10 @@ + RET + + ;----------------------------------------------------------------------------- +-; void x264_deblock_h_luma_mmxext( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void deblock_h_luma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- + INIT_MMX +-cglobal x264_deblock_h_luma_%1, 0,5 ++cglobal deblock_h_luma_8_%1, 0,5 + mov r0, r0mp + mov r3, r1m + lea r4, [r3*3] +@@ -467,24 +472,24 @@ + PUSH dword r2m + PUSH dword 16 + PUSH dword r0 +- call x264_deblock_%2_luma_%1 ++ call deblock_%2_luma_8_%1 + %ifidn %2, v8 + add dword [esp ], 8 ; pix_tmp+0x38 + add dword [esp+16], 2 ; tc0+2 +- call x264_deblock_%2_luma_%1 ++ call deblock_%2_luma_8_%1 + %endif + ADD esp, 20 + + ; transpose 16x4 -> original space (only the middle 4 rows were changed by the filter) + mov r0, r0mp + sub r0, 2 +- lea r1, [r0+r4] + + movq m0, [pix_tmp+0x10] + movq m1, [pix_tmp+0x20] ++ lea r1, [r0+r4] + movq m2, [pix_tmp+0x30] + movq m3, [pix_tmp+0x40] +- TRANSPOSE8x4_STORE PASS8ROWS(r0, r1, r3, r4) ++ TRANSPOSE8x4B_STORE PASS8ROWS(r0, r1, r3, r4) + + lea r0, [r0+r3*8] + lea r1, [r1+r3*8] +@@ -492,7 +497,7 @@ + movq m1, [pix_tmp+0x28] + movq m2, [pix_tmp+0x38] + movq m3, [pix_tmp+0x48] +- TRANSPOSE8x4_STORE PASS8ROWS(r0, r1, r3, r4) ++ TRANSPOSE8x4B_STORE PASS8ROWS(r0, r1, r3, r4) + + ADD esp, pad + RET +@@ -502,22 +507,36 @@ + DEBLOCK_LUMA mmxext, v8, 8 + INIT_XMM + DEBLOCK_LUMA sse2, v, 16 ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA avx, v, 16 ++%endif + + %endif ; ARCH + + + + %macro LUMA_INTRA_P012 4 ; p0..p3 in memory ++%ifdef ARCH_X86_64 ++ pavgb t0, p2, p1 ++ pavgb t1, p0, q0 ++%else + mova t0, p2 + mova t1, p0 + pavgb t0, p1 + pavgb t1, q0 ++%endif + pavgb t0, t1 ; ((p2+p1+1)/2 + (p0+q0+1)/2 + 1)/2 + mova t5, t1 ++%ifdef ARCH_X86_64 ++ paddb t2, p2, p1 ++ paddb t3, p0, q0 ++%else + mova t2, p2 + mova t3, p0 + paddb t2, p1 + paddb t3, q0 ++%endif + paddb t2, t3 + mova t3, t2 + mova t4, t2 +@@ -527,10 +546,15 @@ + pand t2, mpb_1 + psubb t0, t2 ; p1' = (p2+p1+p0+q0+2)/4; + ++%ifdef ARCH_X86_64 ++ pavgb t1, p2, q1 ++ psubb t2, p2, q1 ++%else + mova t1, p2 + mova t2, p2 + pavgb t1, q1 + psubb t2, q1 ++%endif + paddb t3, t3 + psubb t3, t2 ; p2+2*p1+2*p0+2*q0+q1 + pand t2, mpb_1 +@@ -543,10 +567,8 @@ + pand t3, mpb_1 + psubb t1, t3 ; p0'a = (p2+2*p1+2*p0+2*q0+q1+4)/8 + +- mova t3, p0 +- mova t2, p0 +- pxor t3, q1 +- pavgb t2, q1 ++ pxor t3, p0, q1 ++ pavgb t2, p0, q1 + pand t3, mpb_1 + psubb t2, t3 + pavgb t2, p1 ; p0'b = (2*p1+p0+q0+2)/4 +@@ -560,9 +582,8 @@ + mova %1, t1 ; store p0 + + mova t1, %4 ; p3 +- mova t2, t1 ++ paddb t2, t1, p2 + pavgb t1, p2 +- paddb t2, p2 + pavgb t1, t0 ; (p3+p2+1)/2 + (p2+p1+p0+q0+2)/4 + paddb t2, t2 + paddb t2, t4 ; 2*p3+3*p2+p1+p0+q0 +@@ -624,9 +645,9 @@ + %endif + + ;----------------------------------------------------------------------------- +-; void x264_deblock_v_luma_intra_sse2( uint8_t *pix, int stride, int alpha, int beta ) ++; void deblock_v_luma_intra( uint8_t *pix, int stride, int alpha, int beta ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_%2_luma_intra_%1, 4,6,16 ++cglobal deblock_%2_luma_intra_8_%1, 4,6,16 + %ifndef ARCH_X86_64 + sub esp, 0x60 + %endif +@@ -686,9 +707,9 @@ + INIT_MMX + %ifdef ARCH_X86_64 + ;----------------------------------------------------------------------------- +-; void x264_deblock_h_luma_intra_sse2( uint8_t *pix, int stride, int alpha, int beta ) ++; void deblock_h_luma_intra( uint8_t *pix, int stride, int alpha, int beta ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_h_luma_intra_%1, 4,7 ++cglobal deblock_h_luma_intra_8_%1, 4,7 + movsxd r10, r1d + lea r11, [r10*3] + lea r6, [r0-4] +@@ -704,7 +725,7 @@ + + lea r0, [pix_tmp+0x40] + mov r1, 0x10 +- call x264_deblock_v_luma_intra_%1 ++ call deblock_v_luma_intra_8_%1 + + ; transpose 16x6 -> original space (but we can't write only 6 pixels, so really 16x8) + lea r5, [r6+r11] +@@ -717,7 +738,7 @@ + add rsp, 0x88 + RET + %else +-cglobal x264_deblock_h_luma_intra_%1, 2,4 ++cglobal deblock_h_luma_intra_8_%1, 2,4 + lea r3, [r1*3] + sub r0, 4 + lea r2, [r0+r3] +@@ -736,10 +757,10 @@ + PUSH dword r2m + PUSH dword 16 + PUSH r0 +- call x264_deblock_%2_luma_intra_%1 ++ call deblock_%2_luma_intra_8_%1 + %ifidn %2, v8 + add dword [rsp], 8 ; pix_tmp+8 +- call x264_deblock_%2_luma_intra_%1 ++ call deblock_%2_luma_intra_8_%1 + %endif + ADD esp, 16 + +@@ -760,13 +781,15 @@ + + INIT_XMM + DEBLOCK_LUMA_INTRA sse2, v ++%ifdef HAVE_AVX ++INIT_AVX ++DEBLOCK_LUMA_INTRA avx , v ++%endif + %ifndef ARCH_X86_64 + INIT_MMX + DEBLOCK_LUMA_INTRA mmxext, v8 + %endif + +- +- + INIT_MMX + + %macro CHROMA_V_START 0 +@@ -790,23 +813,23 @@ + %define t6 r6 + + ;----------------------------------------------------------------------------- +-; void x264_deblock_v_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void ff_deblock_v_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_v_chroma_mmxext, 5,6 ++cglobal deblock_v_chroma_8_mmxext, 5,6 + CHROMA_V_START + movq m0, [t5] + movq m1, [t5+r1] + movq m2, [r0] + movq m3, [r0+r1] +- call x264_chroma_inter_body_mmxext ++ call ff_chroma_inter_body_mmxext + movq [t5+r1], m1 + movq [r0], m2 + RET + + ;----------------------------------------------------------------------------- +-; void x264_deblock_h_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) ++; void ff_deblock_h_chroma( uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0 ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_h_chroma_mmxext, 5,7 ++cglobal deblock_h_chroma_8_mmxext, 5,7 + %ifdef ARCH_X86_64 + %define buf0 [rsp-24] + %define buf1 [rsp-16] +@@ -815,17 +838,17 @@ + %define buf1 r2m + %endif + CHROMA_H_START +- TRANSPOSE4x8_LOAD PASS8ROWS(t5, r0, r1, t6) ++ TRANSPOSE4x8_LOAD bw, wd, dq, PASS8ROWS(t5, r0, r1, t6) + movq buf0, m0 + movq buf1, m3 +- call x264_chroma_inter_body_mmxext ++ call ff_chroma_inter_body_mmxext + movq m0, buf0 + movq m3, buf1 +- TRANSPOSE8x4_STORE PASS8ROWS(t5, r0, r1, t6) ++ TRANSPOSE8x4B_STORE PASS8ROWS(t5, r0, r1, t6) + RET + + ALIGN 16 +-x264_chroma_inter_body_mmxext: ++ff_chroma_inter_body_mmxext: + LOAD_MASK r2d, r3d + movd m6, [r4] ; tc0 + punpcklbw m6, m6 +@@ -850,31 +873,31 @@ + %define t6 r5 + + ;----------------------------------------------------------------------------- +-; void x264_deblock_v_chroma_intra( uint8_t *pix, int stride, int alpha, int beta ) ++; void ff_deblock_v_chroma_intra( uint8_t *pix, int stride, int alpha, int beta ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_v_chroma_intra_mmxext, 4,5 ++cglobal deblock_v_chroma_intra_8_mmxext, 4,5 + CHROMA_V_START + movq m0, [t5] + movq m1, [t5+r1] + movq m2, [r0] + movq m3, [r0+r1] +- call x264_chroma_intra_body_mmxext ++ call ff_chroma_intra_body_mmxext + movq [t5+r1], m1 + movq [r0], m2 + RET + + ;----------------------------------------------------------------------------- +-; void x264_deblock_h_chroma_intra( uint8_t *pix, int stride, int alpha, int beta ) ++; void ff_deblock_h_chroma_intra( uint8_t *pix, int stride, int alpha, int beta ) + ;----------------------------------------------------------------------------- +-cglobal x264_deblock_h_chroma_intra_mmxext, 4,6 ++cglobal deblock_h_chroma_intra_8_mmxext, 4,6 + CHROMA_H_START +- TRANSPOSE4x8_LOAD PASS8ROWS(t5, r0, r1, t6) +- call x264_chroma_intra_body_mmxext +- TRANSPOSE8x4_STORE PASS8ROWS(t5, r0, r1, t6) ++ TRANSPOSE4x8_LOAD bw, wd, dq, PASS8ROWS(t5, r0, r1, t6) ++ call ff_chroma_intra_body_mmxext ++ TRANSPOSE8x4B_STORE PASS8ROWS(t5, r0, r1, t6) + RET + + ALIGN 16 +-x264_chroma_intra_body_mmxext: ++ff_chroma_intra_body_mmxext: + LOAD_MASK r2d, r3d + movq m5, m1 + movq m6, m2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264dsp_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264dsp_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264dsp_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264dsp_mmx.c 2012-05-14 14:08:54.562344570 +0200 +@@ -27,38 +27,61 @@ + + /***********************************/ + /* IDCT */ ++#define IDCT_ADD_FUNC(NUM, DEPTH, OPT) \ ++void ff_h264_idct ## NUM ## _add_ ## DEPTH ## _ ## OPT (uint8_t *dst, int16_t *block, int stride); ++ ++IDCT_ADD_FUNC(, 8, mmx) ++IDCT_ADD_FUNC(, 10, sse2) ++IDCT_ADD_FUNC(_dc, 8, mmx2) ++IDCT_ADD_FUNC(_dc, 10, mmx2) ++IDCT_ADD_FUNC(8_dc, 8, mmx2) ++IDCT_ADD_FUNC(8_dc, 10, sse2) ++IDCT_ADD_FUNC(8, 8, mmx) ++IDCT_ADD_FUNC(8, 8, sse2) ++IDCT_ADD_FUNC(8, 10, sse2) ++#if HAVE_AVX ++IDCT_ADD_FUNC(, 10, avx) ++IDCT_ADD_FUNC(8_dc, 10, avx) ++IDCT_ADD_FUNC(8, 10, avx) ++#endif ++ ++ ++#define IDCT_ADD_REP_FUNC(NUM, REP, DEPTH, OPT) \ ++void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \ ++ (uint8_t *dst, const int *block_offset, \ ++ DCTELEM *block, int stride, const uint8_t nnzc[6*8]); ++ ++IDCT_ADD_REP_FUNC(8, 4, 8, mmx) ++IDCT_ADD_REP_FUNC(8, 4, 8, mmx2) ++IDCT_ADD_REP_FUNC(8, 4, 8, sse2) ++IDCT_ADD_REP_FUNC(8, 4, 10, sse2) ++IDCT_ADD_REP_FUNC(8, 4, 10, avx) ++IDCT_ADD_REP_FUNC(, 16, 8, mmx) ++IDCT_ADD_REP_FUNC(, 16, 8, mmx2) ++IDCT_ADD_REP_FUNC(, 16, 8, sse2) ++IDCT_ADD_REP_FUNC(, 16, 10, sse2) ++IDCT_ADD_REP_FUNC(, 16intra, 8, mmx) ++IDCT_ADD_REP_FUNC(, 16intra, 8, mmx2) ++IDCT_ADD_REP_FUNC(, 16intra, 8, sse2) ++IDCT_ADD_REP_FUNC(, 16intra, 10, sse2) ++#if HAVE_AVX ++IDCT_ADD_REP_FUNC(, 16, 10, avx) ++IDCT_ADD_REP_FUNC(, 16intra, 10, avx) ++#endif ++ ++ ++#define IDCT_ADD_REP_FUNC2(NUM, REP, DEPTH, OPT) \ ++void ff_h264_idct ## NUM ## _add ## REP ## _ ## DEPTH ## _ ## OPT \ ++ (uint8_t **dst, const int *block_offset, \ ++ DCTELEM *block, int stride, const uint8_t nnzc[6*8]); ++IDCT_ADD_REP_FUNC2(, 8, 8, mmx) ++IDCT_ADD_REP_FUNC2(, 8, 8, mmx2) ++IDCT_ADD_REP_FUNC2(, 8, 8, sse2) ++IDCT_ADD_REP_FUNC2(, 8, 10, sse2) ++#if HAVE_AVX ++IDCT_ADD_REP_FUNC2(, 8, 10, avx) ++#endif + +-void ff_h264_idct_add_mmx (uint8_t *dst, int16_t *block, int stride); +-void ff_h264_idct8_add_mmx (uint8_t *dst, int16_t *block, int stride); +-void ff_h264_idct8_add_sse2 (uint8_t *dst, int16_t *block, int stride); +-void ff_h264_idct_dc_add_mmx2 (uint8_t *dst, int16_t *block, int stride); +-void ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride); +- +-void ff_h264_idct_add16_mmx (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct8_add4_mmx (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add16_mmx2 (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add16intra_mmx (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add16intra_mmx2(uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct8_add4_mmx2 (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct8_add4_sse2 (uint8_t *dst, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add8_mmx (uint8_t **dest, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add8_mmx2 (uint8_t **dest, const int *block_offset, +- DCTELEM *block, int stride, const uint8_t nnzc[6*8]); +- +-void ff_h264_idct_add16_sse2 (uint8_t *dst, const int *block_offset, DCTELEM *block, +- int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add16intra_sse2(uint8_t *dst, const int *block_offset, DCTELEM *block, +- int stride, const uint8_t nnzc[6*8]); +-void ff_h264_idct_add8_sse2 (uint8_t **dest, const int *block_offset, DCTELEM *block, +- int stride, const uint8_t nnzc[6*8]); + void ff_h264_luma_dc_dequant_idct_mmx (DCTELEM *output, DCTELEM *input, int qmul); + void ff_h264_luma_dc_dequant_idct_sse2(DCTELEM *output, DCTELEM *input, int qmul); + +@@ -218,165 +241,274 @@ + ); + } + +-#define LF_FUNC(DIR, TYPE, OPT) \ +-void ff_x264_deblock_ ## DIR ## _ ## TYPE ## _ ## OPT (uint8_t *pix, int stride, \ +- int alpha, int beta, int8_t *tc0); +-#define LF_IFUNC(DIR, TYPE, OPT) \ +-void ff_x264_deblock_ ## DIR ## _ ## TYPE ## _ ## OPT (uint8_t *pix, int stride, \ +- int alpha, int beta); +- +-LF_FUNC (h, chroma, mmxext) +-LF_IFUNC(h, chroma_intra, mmxext) +-LF_FUNC (v, chroma, mmxext) +-LF_IFUNC(v, chroma_intra, mmxext) +- +-LF_FUNC (h, luma, mmxext) +-LF_IFUNC(h, luma_intra, mmxext) +-#if HAVE_YASM && ARCH_X86_32 +-LF_FUNC (v8, luma, mmxext) +-static void ff_x264_deblock_v_luma_mmxext(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) ++#define LF_FUNC(DIR, TYPE, DEPTH, OPT) \ ++void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *pix, int stride, \ ++ int alpha, int beta, int8_t *tc0); ++#define LF_IFUNC(DIR, TYPE, DEPTH, OPT) \ ++void ff_deblock_ ## DIR ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *pix, int stride, \ ++ int alpha, int beta); ++ ++#define LF_FUNCS(type, depth)\ ++LF_FUNC (h, chroma, depth, mmxext)\ ++LF_IFUNC(h, chroma_intra, depth, mmxext)\ ++LF_FUNC (v, chroma, depth, mmxext)\ ++LF_IFUNC(v, chroma_intra, depth, mmxext)\ ++LF_FUNC (h, luma, depth, mmxext)\ ++LF_IFUNC(h, luma_intra, depth, mmxext)\ ++LF_FUNC (h, luma, depth, sse2)\ ++LF_IFUNC(h, luma_intra, depth, sse2)\ ++LF_FUNC (v, luma, depth, sse2)\ ++LF_IFUNC(v, luma_intra, depth, sse2)\ ++LF_FUNC (h, chroma, depth, sse2)\ ++LF_IFUNC(h, chroma_intra, depth, sse2)\ ++LF_FUNC (v, chroma, depth, sse2)\ ++LF_IFUNC(v, chroma_intra, depth, sse2)\ ++LF_FUNC (h, luma, depth, avx)\ ++LF_IFUNC(h, luma_intra, depth, avx)\ ++LF_FUNC (v, luma, depth, avx)\ ++LF_IFUNC(v, luma_intra, depth, avx)\ ++LF_FUNC (h, chroma, depth, avx)\ ++LF_IFUNC(h, chroma_intra, depth, avx)\ ++LF_FUNC (v, chroma, depth, avx)\ ++LF_IFUNC(v, chroma_intra, depth, avx) ++ ++LF_FUNCS( uint8_t, 8) ++LF_FUNCS(uint16_t, 10) ++ ++#if ARCH_X86_32 ++LF_FUNC (v8, luma, 8, mmxext) ++static void ff_deblock_v_luma_8_mmxext(uint8_t *pix, int stride, int alpha, int beta, int8_t *tc0) + { + if((tc0[0] & tc0[1]) >= 0) +- ff_x264_deblock_v8_luma_mmxext(pix+0, stride, alpha, beta, tc0); ++ ff_deblock_v8_luma_8_mmxext(pix+0, stride, alpha, beta, tc0); + if((tc0[2] & tc0[3]) >= 0) +- ff_x264_deblock_v8_luma_mmxext(pix+8, stride, alpha, beta, tc0+2); ++ ff_deblock_v8_luma_8_mmxext(pix+8, stride, alpha, beta, tc0+2); + } +-LF_IFUNC(v8, luma_intra, mmxext) +-static void ff_x264_deblock_v_luma_intra_mmxext(uint8_t *pix, int stride, int alpha, int beta) ++LF_IFUNC(v8, luma_intra, 8, mmxext) ++static void ff_deblock_v_luma_intra_8_mmxext(uint8_t *pix, int stride, int alpha, int beta) + { +- ff_x264_deblock_v8_luma_intra_mmxext(pix+0, stride, alpha, beta); +- ff_x264_deblock_v8_luma_intra_mmxext(pix+8, stride, alpha, beta); ++ ff_deblock_v8_luma_intra_8_mmxext(pix+0, stride, alpha, beta); ++ ff_deblock_v8_luma_intra_8_mmxext(pix+8, stride, alpha, beta); + } +-#endif ++#endif /* ARCH_X86_32 */ + +-LF_FUNC (h, luma, sse2) +-LF_IFUNC(h, luma_intra, sse2) +-LF_FUNC (v, luma, sse2) +-LF_IFUNC(v, luma_intra, sse2) ++LF_FUNC (v, luma, 10, mmxext) ++LF_IFUNC(v, luma_intra, 10, mmxext) + + /***********************************/ + /* weighted prediction */ + +-#define H264_WEIGHT(W, H, OPT) \ +-void ff_h264_weight_ ## W ## x ## H ## _ ## OPT(uint8_t *dst, \ +- int stride, int log2_denom, int weight, int offset); +- +-#define H264_BIWEIGHT(W, H, OPT) \ +-void ff_h264_biweight_ ## W ## x ## H ## _ ## OPT(uint8_t *dst, \ +- uint8_t *src, int stride, int log2_denom, int weightd, \ ++#define H264_WEIGHT(W, OPT) \ ++void ff_h264_weight_ ## W ## _ ## OPT(uint8_t *dst, \ ++ int stride, int height, int log2_denom, int weight, int offset); ++ ++#define H264_BIWEIGHT(W, OPT) \ ++void ff_h264_biweight_ ## W ## _ ## OPT(uint8_t *dst, \ ++ uint8_t *src, int stride, int height, int log2_denom, int weightd, \ + int weights, int offset); + +-#define H264_BIWEIGHT_MMX(W,H) \ +-H264_WEIGHT (W, H, mmx2) \ +-H264_BIWEIGHT(W, H, mmx2) +- +-#define H264_BIWEIGHT_MMX_SSE(W,H) \ +-H264_BIWEIGHT_MMX(W, H) \ +-H264_WEIGHT (W, H, sse2) \ +-H264_BIWEIGHT (W, H, sse2) \ +-H264_BIWEIGHT (W, H, ssse3) +- +-H264_BIWEIGHT_MMX_SSE(16, 16) +-H264_BIWEIGHT_MMX_SSE(16, 8) +-H264_BIWEIGHT_MMX_SSE( 8, 16) +-H264_BIWEIGHT_MMX_SSE( 8, 8) +-H264_BIWEIGHT_MMX_SSE( 8, 4) +-H264_BIWEIGHT_MMX ( 4, 8) +-H264_BIWEIGHT_MMX ( 4, 4) +-H264_BIWEIGHT_MMX ( 4, 2) ++#define H264_BIWEIGHT_MMX(W) \ ++H264_WEIGHT (W, mmx2) \ ++H264_BIWEIGHT(W, mmx2) ++ ++#define H264_BIWEIGHT_MMX_SSE(W) \ ++H264_BIWEIGHT_MMX(W) \ ++H264_WEIGHT (W, sse2) \ ++H264_BIWEIGHT (W, sse2) \ ++H264_BIWEIGHT (W, ssse3) ++ ++H264_BIWEIGHT_MMX_SSE(16) ++H264_BIWEIGHT_MMX_SSE( 8) ++H264_BIWEIGHT_MMX ( 4) ++ ++#define H264_WEIGHT_10(W, DEPTH, OPT) \ ++void ff_h264_weight_ ## W ## _ ## DEPTH ## _ ## OPT(uint8_t *dst, \ ++ int stride, int height, int log2_denom, int weight, int offset); ++ ++#define H264_BIWEIGHT_10(W, DEPTH, OPT) \ ++void ff_h264_biweight_ ## W ## _ ## DEPTH ## _ ## OPT \ ++ (uint8_t *dst, uint8_t *src, int stride, int height, int log2_denom, \ ++ int weightd, int weights, int offset); ++ ++#define H264_BIWEIGHT_10_SSE(W, DEPTH) \ ++H264_WEIGHT_10 (W, DEPTH, sse2) \ ++H264_WEIGHT_10 (W, DEPTH, sse4) \ ++H264_BIWEIGHT_10(W, DEPTH, sse2) \ ++H264_BIWEIGHT_10(W, DEPTH, sse4) ++ ++H264_BIWEIGHT_10_SSE(16, 10) ++H264_BIWEIGHT_10_SSE( 8, 10) ++H264_BIWEIGHT_10_SSE( 4, 10) + +-void ff_h264dsp_init_x86(H264DSPContext *c) ++void ff_h264dsp_init_x86(H264DSPContext *c, const int bit_depth, const int chroma_format_idc) + { + int mm_flags = av_get_cpu_flags(); + +- if (mm_flags & AV_CPU_FLAG_MMX2) { ++ if (chroma_format_idc == 1 && mm_flags & AV_CPU_FLAG_MMX2) { + c->h264_loop_filter_strength= h264_loop_filter_strength_mmx2; + } ++ ++ if (bit_depth == 8) { + #if HAVE_YASM + if (mm_flags & AV_CPU_FLAG_MMX) { +- c->h264_idct_dc_add= +- c->h264_idct_add= ff_h264_idct_add_mmx; +- c->h264_idct8_dc_add= +- c->h264_idct8_add= ff_h264_idct8_add_mmx; +- +- c->h264_idct_add16 = ff_h264_idct_add16_mmx; +- c->h264_idct8_add4 = ff_h264_idct8_add4_mmx; +- c->h264_idct_add8 = ff_h264_idct_add8_mmx; +- c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx; ++ c->h264_idct_dc_add = ++ c->h264_idct_add = ff_h264_idct_add_8_mmx; ++ c->h264_idct8_dc_add = ++ c->h264_idct8_add = ff_h264_idct8_add_8_mmx; ++ ++ c->h264_idct_add16 = ff_h264_idct_add16_8_mmx; ++ c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_8_mmx; ++ c->h264_idct_add16intra = ff_h264_idct_add16intra_8_mmx; + c->h264_luma_dc_dequant_idct= ff_h264_luma_dc_dequant_idct_mmx; + + if (mm_flags & AV_CPU_FLAG_MMX2) { +- c->h264_idct_dc_add= ff_h264_idct_dc_add_mmx2; +- c->h264_idct8_dc_add= ff_h264_idct8_dc_add_mmx2; +- c->h264_idct_add16 = ff_h264_idct_add16_mmx2; +- c->h264_idct8_add4 = ff_h264_idct8_add4_mmx2; +- c->h264_idct_add8 = ff_h264_idct_add8_mmx2; +- c->h264_idct_add16intra= ff_h264_idct_add16intra_mmx2; +- +- c->h264_v_loop_filter_chroma= ff_x264_deblock_v_chroma_mmxext; +- c->h264_h_loop_filter_chroma= ff_x264_deblock_h_chroma_mmxext; +- c->h264_v_loop_filter_chroma_intra= ff_x264_deblock_v_chroma_intra_mmxext; +- c->h264_h_loop_filter_chroma_intra= ff_x264_deblock_h_chroma_intra_mmxext; ++ c->h264_idct_dc_add = ff_h264_idct_dc_add_8_mmx2; ++ c->h264_idct8_dc_add = ff_h264_idct8_dc_add_8_mmx2; ++ c->h264_idct_add16 = ff_h264_idct_add16_8_mmx2; ++ c->h264_idct8_add4 = ff_h264_idct8_add4_8_mmx2; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_8_mmx2; ++ c->h264_idct_add16intra= ff_h264_idct_add16intra_8_mmx2; ++ ++ c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_8_mmxext; ++ c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_8_mmxext; ++ if (chroma_format_idc == 1) { ++ c->h264_h_loop_filter_chroma= ff_deblock_h_chroma_8_mmxext; ++ c->h264_h_loop_filter_chroma_intra= ff_deblock_h_chroma_intra_8_mmxext; ++ } + #if ARCH_X86_32 +- c->h264_v_loop_filter_luma= ff_x264_deblock_v_luma_mmxext; +- c->h264_h_loop_filter_luma= ff_x264_deblock_h_luma_mmxext; +- c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_mmxext; +- c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_mmxext; +-#endif +- c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_mmx2; +- c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_mmx2; +- c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_mmx2; +- c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_mmx2; +- c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_mmx2; +- c->weight_h264_pixels_tab[5]= ff_h264_weight_4x8_mmx2; +- c->weight_h264_pixels_tab[6]= ff_h264_weight_4x4_mmx2; +- c->weight_h264_pixels_tab[7]= ff_h264_weight_4x2_mmx2; +- +- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_mmx2; +- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_mmx2; +- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_mmx2; +- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_mmx2; +- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_mmx2; +- c->biweight_h264_pixels_tab[5]= ff_h264_biweight_4x8_mmx2; +- c->biweight_h264_pixels_tab[6]= ff_h264_biweight_4x4_mmx2; +- c->biweight_h264_pixels_tab[7]= ff_h264_biweight_4x2_mmx2; ++ c->h264_v_loop_filter_luma= ff_deblock_v_luma_8_mmxext; ++ c->h264_h_loop_filter_luma= ff_deblock_h_luma_8_mmxext; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_mmxext; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_mmxext; ++#endif ++ c->weight_h264_pixels_tab[0]= ff_h264_weight_16_mmx2; ++ c->weight_h264_pixels_tab[1]= ff_h264_weight_8_mmx2; ++ c->weight_h264_pixels_tab[2]= ff_h264_weight_4_mmx2; ++ ++ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_mmx2; ++ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_mmx2; ++ c->biweight_h264_pixels_tab[2]= ff_h264_biweight_4_mmx2; + + if (mm_flags&AV_CPU_FLAG_SSE2) { +- c->h264_idct8_add = ff_h264_idct8_add_sse2; +- c->h264_idct8_add4= ff_h264_idct8_add4_sse2; ++ c->h264_idct8_add = ff_h264_idct8_add_8_sse2; ++ ++ c->h264_idct_add16 = ff_h264_idct_add16_8_sse2; ++ c->h264_idct8_add4 = ff_h264_idct8_add4_8_sse2; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_8_sse2; ++ c->h264_idct_add16intra = ff_h264_idct_add16intra_8_sse2; + c->h264_luma_dc_dequant_idct= ff_h264_luma_dc_dequant_idct_sse2; + +- c->weight_h264_pixels_tab[0]= ff_h264_weight_16x16_sse2; +- c->weight_h264_pixels_tab[1]= ff_h264_weight_16x8_sse2; +- c->weight_h264_pixels_tab[2]= ff_h264_weight_8x16_sse2; +- c->weight_h264_pixels_tab[3]= ff_h264_weight_8x8_sse2; +- c->weight_h264_pixels_tab[4]= ff_h264_weight_8x4_sse2; +- +- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_sse2; +- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_sse2; +- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_sse2; +- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_sse2; +- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_sse2; ++ c->weight_h264_pixels_tab[0]= ff_h264_weight_16_sse2; ++ c->weight_h264_pixels_tab[1]= ff_h264_weight_8_sse2; ++ ++ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_sse2; ++ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_sse2; + + #if HAVE_ALIGNED_STACK +- c->h264_v_loop_filter_luma = ff_x264_deblock_v_luma_sse2; +- c->h264_h_loop_filter_luma = ff_x264_deblock_h_luma_sse2; +- c->h264_v_loop_filter_luma_intra = ff_x264_deblock_v_luma_intra_sse2; +- c->h264_h_loop_filter_luma_intra = ff_x264_deblock_h_luma_intra_sse2; ++ c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_sse2; ++ c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_sse2; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_sse2; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_sse2; + #endif +- +- c->h264_idct_add16 = ff_h264_idct_add16_sse2; +- c->h264_idct_add8 = ff_h264_idct_add8_sse2; +- c->h264_idct_add16intra = ff_h264_idct_add16intra_sse2; + } + if (mm_flags&AV_CPU_FLAG_SSSE3) { +- c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16x16_ssse3; +- c->biweight_h264_pixels_tab[1]= ff_h264_biweight_16x8_ssse3; +- c->biweight_h264_pixels_tab[2]= ff_h264_biweight_8x16_ssse3; +- c->biweight_h264_pixels_tab[3]= ff_h264_biweight_8x8_ssse3; +- c->biweight_h264_pixels_tab[4]= ff_h264_biweight_8x4_ssse3; ++ c->biweight_h264_pixels_tab[0]= ff_h264_biweight_16_ssse3; ++ c->biweight_h264_pixels_tab[1]= ff_h264_biweight_8_ssse3; ++ } ++ if (HAVE_AVX && mm_flags&AV_CPU_FLAG_AVX) { ++#if HAVE_ALIGNED_STACK ++ c->h264_v_loop_filter_luma = ff_deblock_v_luma_8_avx; ++ c->h264_h_loop_filter_luma = ff_deblock_h_luma_8_avx; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_8_avx; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_8_avx; ++#endif ++ } ++ } ++ } ++#endif ++ } else if (bit_depth == 10) { ++#if HAVE_YASM ++ if (mm_flags & AV_CPU_FLAG_MMX) { ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++#if ARCH_X86_32 ++ c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_10_mmxext; ++ c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_10_mmxext; ++ c->h264_v_loop_filter_luma= ff_deblock_v_luma_10_mmxext; ++ c->h264_h_loop_filter_luma= ff_deblock_h_luma_10_mmxext; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_mmxext; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_mmxext; ++#endif ++ c->h264_idct_dc_add= ff_h264_idct_dc_add_10_mmx2; ++ if (mm_flags&AV_CPU_FLAG_SSE2) { ++ c->h264_idct_add = ff_h264_idct_add_10_sse2; ++ c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_sse2; ++ ++ c->h264_idct_add16 = ff_h264_idct_add16_10_sse2; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_10_sse2; ++ c->h264_idct_add16intra= ff_h264_idct_add16intra_10_sse2; ++#if HAVE_ALIGNED_STACK ++ c->h264_idct8_add = ff_h264_idct8_add_10_sse2; ++ c->h264_idct8_add4 = ff_h264_idct8_add4_10_sse2; ++#endif ++ ++ c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse2; ++ c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse2; ++ c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse2; ++ ++ c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse2; ++ c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse2; ++ c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse2; ++ ++ c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_10_sse2; ++ c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_10_sse2; ++#if HAVE_ALIGNED_STACK ++ c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_sse2; ++ c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_sse2; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_sse2; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_sse2; ++#endif + } ++ if (mm_flags&AV_CPU_FLAG_SSE4) { ++ c->weight_h264_pixels_tab[0] = ff_h264_weight_16_10_sse4; ++ c->weight_h264_pixels_tab[1] = ff_h264_weight_8_10_sse4; ++ c->weight_h264_pixels_tab[2] = ff_h264_weight_4_10_sse4; ++ ++ c->biweight_h264_pixels_tab[0] = ff_h264_biweight_16_10_sse4; ++ c->biweight_h264_pixels_tab[1] = ff_h264_biweight_8_10_sse4; ++ c->biweight_h264_pixels_tab[2] = ff_h264_biweight_4_10_sse4; ++ } ++#if HAVE_AVX ++ if (mm_flags&AV_CPU_FLAG_AVX) { ++ c->h264_idct_dc_add = ++ c->h264_idct_add = ff_h264_idct_add_10_avx; ++ c->h264_idct8_dc_add = ff_h264_idct8_dc_add_10_avx; ++ ++ c->h264_idct_add16 = ff_h264_idct_add16_10_avx; ++ if (chroma_format_idc == 1) ++ c->h264_idct_add8 = ff_h264_idct_add8_10_avx; ++ c->h264_idct_add16intra= ff_h264_idct_add16intra_10_avx; ++#if HAVE_ALIGNED_STACK ++ c->h264_idct8_add = ff_h264_idct8_add_10_avx; ++ c->h264_idct8_add4 = ff_h264_idct8_add4_10_avx; ++#endif ++ ++ c->h264_v_loop_filter_chroma= ff_deblock_v_chroma_10_avx; ++ c->h264_v_loop_filter_chroma_intra= ff_deblock_v_chroma_intra_10_avx; ++#if HAVE_ALIGNED_STACK ++ c->h264_v_loop_filter_luma = ff_deblock_v_luma_10_avx; ++ c->h264_h_loop_filter_luma = ff_deblock_h_luma_10_avx; ++ c->h264_v_loop_filter_luma_intra = ff_deblock_v_luma_intra_10_avx; ++ c->h264_h_loop_filter_luma_intra = ff_deblock_h_luma_intra_10_avx; ++#endif ++ } ++#endif /* HAVE_AVX */ + } + } + #endif ++ } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_i386.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_i386.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_i386.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_i386.h 2012-05-14 14:08:54.540344128 +0200 +@@ -29,125 +29,121 @@ + #ifndef AVCODEC_X86_H264_I386_H + #define AVCODEC_X86_H264_I386_H + ++#include ++ + #include "libavcodec/cabac.h" ++#include "cabac.h" + + //FIXME use some macros to avoid duplicating get_cabac (cannot be done yet + //as that would make optimization work hard) +-#if ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE && !defined(BROKEN_RELOCATIONS) ++#if HAVE_7REGS && !defined(BROKEN_RELOCATIONS) + static int decode_significance_x86(CABACContext *c, int max_coeff, + uint8_t *significant_coeff_ctx_base, +- int *index){ ++ int *index, x86_reg last_off){ + void *end= significant_coeff_ctx_base + max_coeff - 1; +- int minusstart= -(int)significant_coeff_ctx_base; +- int minusindex= 4-(int)index; +- int coeff_count; ++ int minusstart= -(intptr_t)significant_coeff_ctx_base; ++ int minusindex= 4-(intptr_t)index; ++ int bit; ++ x86_reg coeff_count; + __asm__ volatile( +- "movl "RANGE "(%3), %%esi \n\t" +- "movl "LOW "(%3), %%ebx \n\t" +- + "2: \n\t" + +- BRANCHLESS_GET_CABAC("%%edx", "%3", "(%1)", "%%ebx", +- "%%bx", "%%esi", "%%eax", "%%al") ++ BRANCHLESS_GET_CABAC("%4", "(%1)", "%3", ++ "%w3", "%5", "%k0", "%b0", "%6") + +- "test $1, %%edx \n\t" ++ "test $1, %4 \n\t" + " jz 3f \n\t" ++ "add %10, %1 \n\t" + +- BRANCHLESS_GET_CABAC("%%edx", "%3", "61(%1)", "%%ebx", +- "%%bx", "%%esi", "%%eax", "%%al") ++ BRANCHLESS_GET_CABAC("%4", "(%1)", "%3", ++ "%w3", "%5", "%k0", "%b0", "%6") + +- "mov %2, %%"REG_a" \n\t" +- "movl %4, %%ecx \n\t" ++ "sub %10, %1 \n\t" ++ "mov %2, %0 \n\t" ++ "movl %7, %%ecx \n\t" + "add %1, %%"REG_c" \n\t" +- "movl %%ecx, (%%"REG_a") \n\t" ++ "movl %%ecx, (%0) \n\t" + +- "test $1, %%edx \n\t" ++ "test $1, %4 \n\t" + " jnz 4f \n\t" + +- "add $4, %%"REG_a" \n\t" +- "mov %%"REG_a", %2 \n\t" ++ "add"OPSIZE" $4, %2 \n\t" + + "3: \n\t" + "add $1, %1 \n\t" +- "cmp %5, %1 \n\t" ++ "cmp %8, %1 \n\t" + " jb 2b \n\t" +- "mov %2, %%"REG_a" \n\t" +- "movl %4, %%ecx \n\t" ++ "mov %2, %0 \n\t" ++ "movl %7, %%ecx \n\t" + "add %1, %%"REG_c" \n\t" +- "movl %%ecx, (%%"REG_a") \n\t" ++ "movl %%ecx, (%0) \n\t" + "4: \n\t" +- "add %6, %%eax \n\t" +- "shr $2, %%eax \n\t" +- +- "movl %%esi, "RANGE "(%3) \n\t" +- "movl %%ebx, "LOW "(%3) \n\t" +- :"=&a"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index) +- :"r"(c), "m"(minusstart), "m"(end), "m"(minusindex) +- : "%"REG_c, "%ebx", "%edx", "%esi", "memory" ++ "add %9, %k0 \n\t" ++ "shr $2, %k0 \n\t" ++ :"=&q"(coeff_count), "+r"(significant_coeff_ctx_base), "+m"(index), ++ "+&r"(c->low), "=&r"(bit), "+&r"(c->range), ++ "+m"(c->bytestream) ++ :"m"(minusstart), "m"(end), "m"(minusindex), "m"(last_off) ++ : "%"REG_c, "memory" + ); + return coeff_count; + } + + static int decode_significance_8x8_x86(CABACContext *c, + uint8_t *significant_coeff_ctx_base, +- int *index, const uint8_t *sig_off){ +- int minusindex= 4-(int)index; +- int coeff_count; ++ int *index, uint8_t *last_coeff_ctx_base, const uint8_t *sig_off){ ++ int minusindex= 4-(intptr_t)index; ++ int bit; ++ x86_reg coeff_count; + x86_reg last=0; ++ x86_reg state; + __asm__ volatile( +- "movl "RANGE "(%3), %%esi \n\t" +- "movl "LOW "(%3), %%ebx \n\t" +- +- "mov %1, %%"REG_D" \n\t" ++ "mov %1, %6 \n\t" + "2: \n\t" + +- "mov %6, %%"REG_a" \n\t" +- "movzbl (%%"REG_a", %%"REG_D"), %%edi \n\t" +- "add %5, %%"REG_D" \n\t" ++ "mov %10, %0 \n\t" ++ "movzbl (%0, %6), %k6 \n\t" ++ "add %9, %6 \n\t" + +- BRANCHLESS_GET_CABAC("%%edx", "%3", "(%%"REG_D")", "%%ebx", +- "%%bx", "%%esi", "%%eax", "%%al") ++ BRANCHLESS_GET_CABAC("%4", "(%6)", "%3", ++ "%w3", "%5", "%k0", "%b0", "%7") + +- "mov %1, %%edi \n\t" +- "test $1, %%edx \n\t" ++ "mov %1, %k6 \n\t" ++ "test $1, %4 \n\t" + " jz 3f \n\t" + +- "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%%edi), %%edi\n\t" +- "add %5, %%"REG_D" \n\t" ++ "movzbl "MANGLE(last_coeff_flag_offset_8x8)"(%k6), %k6\n\t" ++ "add %11, %6 \n\t" + +- BRANCHLESS_GET_CABAC("%%edx", "%3", "15(%%"REG_D")", "%%ebx", +- "%%bx", "%%esi", "%%eax", "%%al") ++ BRANCHLESS_GET_CABAC("%4", "(%6)", "%3", ++ "%w3", "%5", "%k0", "%b0", "%7") + +- "mov %2, %%"REG_a" \n\t" +- "mov %1, %%edi \n\t" +- "movl %%edi, (%%"REG_a") \n\t" ++ "mov %2, %0 \n\t" ++ "mov %1, %k6 \n\t" ++ "movl %k6, (%0) \n\t" + +- "test $1, %%edx \n\t" ++ "test $1, %4 \n\t" + " jnz 4f \n\t" + +- "add $4, %%"REG_a" \n\t" +- "mov %%"REG_a", %2 \n\t" ++ "add"OPSIZE" $4, %2 \n\t" + + "3: \n\t" +- "addl $1, %%edi \n\t" +- "mov %%edi, %1 \n\t" +- "cmpl $63, %%edi \n\t" ++ "addl $1, %k6 \n\t" ++ "mov %k6, %1 \n\t" ++ "cmpl $63, %k6 \n\t" + " jb 2b \n\t" +- "mov %2, %%"REG_a" \n\t" +- "movl %%edi, (%%"REG_a") \n\t" ++ "mov %2, %0 \n\t" ++ "movl %k6, (%0) \n\t" + "4: \n\t" +- "addl %4, %%eax \n\t" +- "shr $2, %%eax \n\t" +- +- "movl %%esi, "RANGE "(%3) \n\t" +- "movl %%ebx, "LOW "(%3) \n\t" +- :"=&a"(coeff_count),"+m"(last), "+m"(index) +- :"r"(c), "m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off) +- : "%"REG_c, "%ebx", "%edx", "%esi", "%"REG_D, "memory" ++ "addl %8, %k0 \n\t" ++ "shr $2, %k0 \n\t" ++ :"=&q"(coeff_count),"+m"(last), "+m"(index), "+&r"(c->low), "=&r"(bit), ++ "+&r"(c->range), "=&r"(state), "+m"(c->bytestream) ++ :"m"(minusindex), "m"(significant_coeff_ctx_base), "m"(sig_off), "m"(last_coeff_ctx_base) ++ : "%"REG_c, "memory" + ); + return coeff_count; + } +-#endif /* ARCH_X86 && HAVE_7REGS && HAVE_EBX_AVAILABLE */ +- /* !defined(BROKEN_RELOCATIONS) */ ++#endif /* HAVE_7REGS && !defined(BROKEN_RELOCATIONS) */ + + #endif /* AVCODEC_X86_H264_I386_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_idct_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_idct_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_idct_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_idct_10bit.asm 2012-05-14 14:08:54.543344188 +0200 +@@ -0,0 +1,565 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 iDCT code ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Daniel Kang ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++pw_pixel_max: times 8 dw ((1 << 10)-1) ++pd_32: times 4 dd 32 ++scan8_mem: db 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 ++ db 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8 ++ db 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8 ++ db 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8 ++ db 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8 ++ db 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8 ++ db 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8 ++ db 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8 ++ db 4+11*8, 5+11*8, 4+12*8, 5+12*8 ++ db 6+11*8, 7+11*8, 6+12*8, 7+12*8 ++ db 4+13*8, 5+13*8, 4+14*8, 5+14*8 ++ db 6+13*8, 7+13*8, 6+14*8, 7+14*8 ++ ++%ifdef PIC ++%define scan8 r11 ++%else ++%define scan8 scan8_mem ++%endif ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; void h264_idct_add(pixel *dst, dctcoef *block, int stride) ++;----------------------------------------------------------------------------- ++%macro STORE_DIFFx2 6 ++ psrad %1, 6 ++ psrad %2, 6 ++ packssdw %1, %2 ++ movq %3, [%5] ++ movhps %3, [%5+%6] ++ paddsw %1, %3 ++ CLIPW %1, %4, [pw_pixel_max] ++ movq [%5], %1 ++ movhps [%5+%6], %1 ++%endmacro ++ ++%macro STORE_DIFF16 5 ++ psrad %1, 6 ++ psrad %2, 6 ++ packssdw %1, %2 ++ paddsw %1, [%5] ++ CLIPW %1, %3, %4 ++ mova [%5], %1 ++%endmacro ++ ++;dst, in, stride ++%macro IDCT4_ADD_10 3 ++ mova m0, [%2+ 0] ++ mova m1, [%2+16] ++ mova m2, [%2+32] ++ mova m3, [%2+48] ++ IDCT4_1D d,0,1,2,3,4,5 ++ TRANSPOSE4x4D 0,1,2,3,4 ++ paddd m0, [pd_32] ++ IDCT4_1D d,0,1,2,3,4,5 ++ pxor m5, m5 ++ STORE_DIFFx2 m0, m1, m4, m5, %1, %3 ++ lea %1, [%1+%3*2] ++ STORE_DIFFx2 m2, m3, m4, m5, %1, %3 ++%endmacro ++ ++%macro IDCT_ADD_10 1 ++cglobal h264_idct_add_10_%1, 3,3 ++ IDCT4_ADD_10 r0, r1, r2 ++ RET ++%endmacro ++ ++INIT_XMM ++IDCT_ADD_10 sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++IDCT_ADD_10 avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; h264_idct_add16(pixel *dst, const int *block_offset, dctcoef *block, int stride, const uint8_t nnzc[6*8]) ++;----------------------------------------------------------------------------- ++;;;;;;; NO FATE SAMPLES TRIGGER THIS ++%macro ADD4x4IDCT 1 ++add4x4_idct_%1: ++ add r5, r0 ++ mova m0, [r2+ 0] ++ mova m1, [r2+16] ++ mova m2, [r2+32] ++ mova m3, [r2+48] ++ IDCT4_1D d,0,1,2,3,4,5 ++ TRANSPOSE4x4D 0,1,2,3,4 ++ paddd m0, [pd_32] ++ IDCT4_1D d,0,1,2,3,4,5 ++ pxor m5, m5 ++ STORE_DIFFx2 m0, m1, m4, m5, r5, r3 ++ lea r5, [r5+r3*2] ++ STORE_DIFFx2 m2, m3, m4, m5, r5, r3 ++ ret ++%endmacro ++ ++INIT_XMM ++ALIGN 16 ++ADD4x4IDCT sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++ALIGN 16 ++ADD4x4IDCT avx ++%endif ++ ++%macro ADD16_OP 3 ++ cmp byte [r4+%3], 0 ++ jz .skipblock%2 ++ mov r5d, [r1+%2*4] ++ call add4x4_idct_%1 ++.skipblock%2: ++%if %2<15 ++ add r2, 64 ++%endif ++%endmacro ++ ++%macro IDCT_ADD16_10 1 ++cglobal h264_idct_add16_10_%1, 5,6 ++ ADD16_OP %1, 0, 4+1*8 ++ ADD16_OP %1, 1, 5+1*8 ++ ADD16_OP %1, 2, 4+2*8 ++ ADD16_OP %1, 3, 5+2*8 ++ ADD16_OP %1, 4, 6+1*8 ++ ADD16_OP %1, 5, 7+1*8 ++ ADD16_OP %1, 6, 6+2*8 ++ ADD16_OP %1, 7, 7+2*8 ++ ADD16_OP %1, 8, 4+3*8 ++ ADD16_OP %1, 9, 5+3*8 ++ ADD16_OP %1, 10, 4+4*8 ++ ADD16_OP %1, 11, 5+4*8 ++ ADD16_OP %1, 12, 6+3*8 ++ ADD16_OP %1, 13, 7+3*8 ++ ADD16_OP %1, 14, 6+4*8 ++ ADD16_OP %1, 15, 7+4*8 ++ REP_RET ++%endmacro ++ ++INIT_XMM ++IDCT_ADD16_10 sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++IDCT_ADD16_10 avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void h264_idct_dc_add(pixel *dst, dctcoef *block, int stride) ++;----------------------------------------------------------------------------- ++%macro IDCT_DC_ADD_OP_10 3 ++ pxor m5, m5 ++%if avx_enabled ++ paddw m1, m0, [%1+0 ] ++ paddw m2, m0, [%1+%2 ] ++ paddw m3, m0, [%1+%2*2] ++ paddw m4, m0, [%1+%3 ] ++%else ++ mova m1, [%1+0 ] ++ mova m2, [%1+%2 ] ++ mova m3, [%1+%2*2] ++ mova m4, [%1+%3 ] ++ paddw m1, m0 ++ paddw m2, m0 ++ paddw m3, m0 ++ paddw m4, m0 ++%endif ++ CLIPW m1, m5, m6 ++ CLIPW m2, m5, m6 ++ CLIPW m3, m5, m6 ++ CLIPW m4, m5, m6 ++ mova [%1+0 ], m1 ++ mova [%1+%2 ], m2 ++ mova [%1+%2*2], m3 ++ mova [%1+%3 ], m4 ++%endmacro ++ ++INIT_MMX ++cglobal h264_idct_dc_add_10_mmx2,3,3 ++ movd m0, [r1] ++ paddd m0, [pd_32] ++ psrad m0, 6 ++ lea r1, [r2*3] ++ pshufw m0, m0, 0 ++ mova m6, [pw_pixel_max] ++ IDCT_DC_ADD_OP_10 r0, r2, r1 ++ RET ++ ++;----------------------------------------------------------------------------- ++; void h264_idct8_dc_add(pixel *dst, dctcoef *block, int stride) ++;----------------------------------------------------------------------------- ++%macro IDCT8_DC_ADD 1 ++cglobal h264_idct8_dc_add_10_%1,3,3,7 ++ mov r1d, [r1] ++ add r1, 32 ++ sar r1, 6 ++ movd m0, r1d ++ lea r1, [r2*3] ++ SPLATW m0, m0, 0 ++ mova m6, [pw_pixel_max] ++ IDCT_DC_ADD_OP_10 r0, r2, r1 ++ lea r0, [r0+r2*4] ++ IDCT_DC_ADD_OP_10 r0, r2, r1 ++ RET ++%endmacro ++ ++INIT_XMM ++IDCT8_DC_ADD sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++IDCT8_DC_ADD avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; h264_idct_add16intra(pixel *dst, const int *block_offset, dctcoef *block, int stride, const uint8_t nnzc[6*8]) ++;----------------------------------------------------------------------------- ++%macro AC 2 ++.ac%2 ++ mov r5d, [r1+(%2+0)*4] ++ call add4x4_idct_%1 ++ mov r5d, [r1+(%2+1)*4] ++ add r2, 64 ++ call add4x4_idct_%1 ++ add r2, 64 ++ jmp .skipadd%2 ++%endmacro ++ ++%assign last_block 16 ++%macro ADD16_OP_INTRA 3 ++ cmp word [r4+%3], 0 ++ jnz .ac%2 ++ mov r5d, [r2+ 0] ++ or r5d, [r2+64] ++ jz .skipblock%2 ++ mov r5d, [r1+(%2+0)*4] ++ call idct_dc_add_%1 ++.skipblock%2: ++%if %2 01234567 ++%endmacro ++ ++%macro IDCT8_1D_FULL 1 ++ mova m7, [%1+112*2] ++ mova m6, [%1+ 96*2] ++ mova m5, [%1+ 80*2] ++ mova m3, [%1+ 48*2] ++ mova m2, [%1+ 32*2] ++ mova m1, [%1+ 16*2] ++ IDCT8_1D [%1], [%1+ 64*2] ++%endmacro ++ ++; %1=int16_t *block, %2=int16_t *dstblock ++%macro IDCT8_ADD_SSE_START 2 ++ IDCT8_1D_FULL %1 ++%ifdef ARCH_X86_64 ++ TRANSPOSE4x4D 0,1,2,3,8 ++ mova [%2 ], m0 ++ TRANSPOSE4x4D 4,5,6,7,8 ++ mova [%2+8*2], m4 ++%else ++ mova [%1], m7 ++ TRANSPOSE4x4D 0,1,2,3,7 ++ mova m7, [%1] ++ mova [%2 ], m0 ++ mova [%2+16*2], m1 ++ mova [%2+32*2], m2 ++ mova [%2+48*2], m3 ++ TRANSPOSE4x4D 4,5,6,7,3 ++ mova [%2+ 8*2], m4 ++ mova [%2+24*2], m5 ++ mova [%2+40*2], m6 ++ mova [%2+56*2], m7 ++%endif ++%endmacro ++ ++; %1=uint8_t *dst, %2=int16_t *block, %3=int stride ++%macro IDCT8_ADD_SSE_END 3 ++ IDCT8_1D_FULL %2 ++ mova [%2 ], m6 ++ mova [%2+16*2], m7 ++ ++ pxor m7, m7 ++ STORE_DIFFx2 m0, m1, m6, m7, %1, %3 ++ lea %1, [%1+%3*2] ++ STORE_DIFFx2 m2, m3, m6, m7, %1, %3 ++ mova m0, [%2 ] ++ mova m1, [%2+16*2] ++ lea %1, [%1+%3*2] ++ STORE_DIFFx2 m4, m5, m6, m7, %1, %3 ++ lea %1, [%1+%3*2] ++ STORE_DIFFx2 m0, m1, m6, m7, %1, %3 ++%endmacro ++ ++%macro IDCT8_ADD 1 ++cglobal h264_idct8_add_10_%1, 3,4,16 ++%ifndef UNIX64 ++ %assign pad 16-gprsize-(stack_offset&15) ++ sub rsp, pad ++ call h264_idct8_add1_10_%1 ++ add rsp, pad ++ RET ++%endif ++ ++ALIGN 16 ++; TODO: does not need to use stack ++h264_idct8_add1_10_%1: ++%assign pad 256+16-gprsize ++ sub rsp, pad ++ add dword [r1], 32 ++ ++%ifdef ARCH_X86_64 ++ IDCT8_ADD_SSE_START r1, rsp ++ SWAP 1, 9 ++ SWAP 2, 10 ++ SWAP 3, 11 ++ SWAP 5, 13 ++ SWAP 6, 14 ++ SWAP 7, 15 ++ IDCT8_ADD_SSE_START r1+16, rsp+128 ++ PERMUTE 1,9, 2,10, 3,11, 5,1, 6,2, 7,3, 9,13, 10,14, 11,15, 13,5, 14,6, 15,7 ++ IDCT8_1D [rsp], [rsp+128] ++ SWAP 0, 8 ++ SWAP 1, 9 ++ SWAP 2, 10 ++ SWAP 3, 11 ++ SWAP 4, 12 ++ SWAP 5, 13 ++ SWAP 6, 14 ++ SWAP 7, 15 ++ IDCT8_1D [rsp+16], [rsp+144] ++ psrad m8, 6 ++ psrad m0, 6 ++ packssdw m8, m0 ++ paddsw m8, [r0] ++ pxor m0, m0 ++ CLIPW m8, m0, [pw_pixel_max] ++ mova [r0], m8 ++ mova m8, [pw_pixel_max] ++ STORE_DIFF16 m9, m1, m0, m8, r0+r2 ++ lea r0, [r0+r2*2] ++ STORE_DIFF16 m10, m2, m0, m8, r0 ++ STORE_DIFF16 m11, m3, m0, m8, r0+r2 ++ lea r0, [r0+r2*2] ++ STORE_DIFF16 m12, m4, m0, m8, r0 ++ STORE_DIFF16 m13, m5, m0, m8, r0+r2 ++ lea r0, [r0+r2*2] ++ STORE_DIFF16 m14, m6, m0, m8, r0 ++ STORE_DIFF16 m15, m7, m0, m8, r0+r2 ++%else ++ IDCT8_ADD_SSE_START r1, rsp ++ IDCT8_ADD_SSE_START r1+16, rsp+128 ++ lea r3, [r0+8] ++ IDCT8_ADD_SSE_END r0, rsp, r2 ++ IDCT8_ADD_SSE_END r3, rsp+16, r2 ++%endif ; ARCH_X86_64 ++ ++ add rsp, pad ++ ret ++%endmacro ++ ++INIT_XMM ++IDCT8_ADD sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++IDCT8_ADD avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; h264_idct8_add4(pixel **dst, const int *block_offset, dctcoef *block, int stride, const uint8_t nnzc[6*8]) ++;----------------------------------------------------------------------------- ++;;;;;;; NO FATE SAMPLES TRIGGER THIS ++%macro IDCT8_ADD4_OP 3 ++ cmp byte [r4+%3], 0 ++ jz .skipblock%2 ++ mov r0d, [r6+%2*4] ++ add r0, r5 ++ call h264_idct8_add1_10_%1 ++.skipblock%2: ++%if %2<12 ++ add r1, 256 ++%endif ++%endmacro ++ ++%macro IDCT8_ADD4 1 ++cglobal h264_idct8_add4_10_%1, 0,7,16 ++ %assign pad 16-gprsize-(stack_offset&15) ++ SUB rsp, pad ++ mov r5, r0mp ++ mov r6, r1mp ++ mov r1, r2mp ++ mov r2d, r3m ++ movifnidn r4, r4mp ++ IDCT8_ADD4_OP %1, 0, 4+1*8 ++ IDCT8_ADD4_OP %1, 4, 6+1*8 ++ IDCT8_ADD4_OP %1, 8, 4+3*8 ++ IDCT8_ADD4_OP %1, 12, 6+3*8 ++ ADD rsp, pad ++ RET ++%endmacro ; IDCT8_ADD4 ++ ++INIT_XMM ++IDCT8_ADD4 sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++IDCT8_ADD4 avx ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_idct.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_idct.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_idct.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_idct.asm 2012-05-14 14:08:54.542344168 +0200 +@@ -23,23 +23,27 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;***************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION_RODATA + + ; FIXME this table is a duplicate from h264data.h, and will be removed once the tables from, h264 have been split +-scan8_mem: db 4+1*8, 5+1*8, 4+2*8, 5+2*8 +- db 6+1*8, 7+1*8, 6+2*8, 7+2*8 +- db 4+3*8, 5+3*8, 4+4*8, 5+4*8 +- db 6+3*8, 7+3*8, 6+4*8, 7+4*8 +- db 1+1*8, 2+1*8 +- db 1+2*8, 2+2*8 +- db 1+4*8, 2+4*8 +- db 1+5*8, 2+5*8 ++scan8_mem: db 4+ 1*8, 5+ 1*8, 4+ 2*8, 5+ 2*8 ++ db 6+ 1*8, 7+ 1*8, 6+ 2*8, 7+ 2*8 ++ db 4+ 3*8, 5+ 3*8, 4+ 4*8, 5+ 4*8 ++ db 6+ 3*8, 7+ 3*8, 6+ 4*8, 7+ 4*8 ++ db 4+ 6*8, 5+ 6*8, 4+ 7*8, 5+ 7*8 ++ db 6+ 6*8, 7+ 6*8, 6+ 7*8, 7+ 7*8 ++ db 4+ 8*8, 5+ 8*8, 4+ 9*8, 5+ 9*8 ++ db 6+ 8*8, 7+ 8*8, 6+ 9*8, 7+ 9*8 ++ db 4+11*8, 5+11*8, 4+12*8, 5+12*8 ++ db 6+11*8, 7+11*8, 6+12*8, 7+12*8 ++ db 4+13*8, 5+13*8, 4+14*8, 5+14*8 ++ db 6+13*8, 7+13*8, 6+14*8, 7+14*8 + %ifdef PIC + %define scan8 r11 + %else +@@ -59,11 +63,11 @@ + movq m2, [%2+16] + movq m3, [%2+24] + +- IDCT4_1D 0, 1, 2, 3, 4, 5 ++ IDCT4_1D w, 0, 1, 2, 3, 4, 5 + mova m6, [pw_32] + TRANSPOSE4x4W 0, 1, 2, 3, 4 + paddw m0, m6 +- IDCT4_1D 0, 1, 2, 3, 4, 5 ++ IDCT4_1D w, 0, 1, 2, 3, 4, 5 + pxor m7, m7 + + STORE_DIFFx2 m0, m1, m4, m5, m7, 6, %1, %3 +@@ -73,15 +77,15 @@ + + INIT_MMX + ; ff_h264_idct_add_mmx(uint8_t *dst, int16_t *block, int stride) +-cglobal h264_idct_add_mmx, 3, 3, 0 ++cglobal h264_idct_add_8_mmx, 3, 3, 0 + IDCT4_ADD r0, r1, r2 + RET + + %macro IDCT8_1D 2 +- mova m4, m5 + mova m0, m1 +- psraw m4, 1 + psraw m1, 1 ++ mova m4, m5 ++ psraw m4, 1 + paddw m4, m5 + paddw m1, m0 + paddw m4, m7 +@@ -91,16 +95,16 @@ + + psubw m0, m3 + psubw m5, m3 ++ psraw m3, 1 + paddw m0, m7 + psubw m5, m7 +- psraw m3, 1 + psraw m7, 1 + psubw m0, m3 + psubw m5, m7 + +- mova m3, m4 + mova m7, m1 + psraw m1, 2 ++ mova m3, m4 + psraw m3, 2 + paddw m3, m0 + psraw m0, 2 +@@ -109,23 +113,23 @@ + psubw m0, m4 + psubw m7, m5 + +- mova m4, m2 + mova m5, m6 +- psraw m4, 1 + psraw m6, 1 +- psubw m4, m5 ++ mova m4, m2 ++ psraw m4, 1 + paddw m6, m2 ++ psubw m4, m5 + + mova m2, %1 + mova m5, %2 +- SUMSUB_BA m5, m2 +- SUMSUB_BA m6, m5 +- SUMSUB_BA m4, m2 +- SUMSUB_BA m7, m6 +- SUMSUB_BA m0, m4 +- SUMSUB_BA m3, m2 +- SUMSUB_BA m1, m5 +- SWAP 7, 6, 4, 5, 2, 3, 1, 0 ; 70315246 -> 01234567 ++ SUMSUB_BA w, 5, 2 ++ SUMSUB_BA w, 6, 5 ++ SUMSUB_BA w, 4, 2 ++ SUMSUB_BA w, 7, 6 ++ SUMSUB_BA w, 0, 4 ++ SUMSUB_BA w, 3, 2 ++ SUMSUB_BA w, 1, 5 ++ SWAP 7, 6, 4, 5, 2, 3, 1, 0 ; 70315246 -> 01234567 + %endmacro + + %macro IDCT8_1D_FULL 1 +@@ -177,7 +181,7 @@ + + INIT_MMX + ; ff_h264_idct8_add_mmx(uint8_t *dst, int16_t *block, int stride) +-cglobal h264_idct8_add_mmx, 3, 4, 0 ++cglobal h264_idct8_add_8_mmx, 3, 4, 0 + %assign pad 128+4-(stack_offset&7) + SUB rsp, pad + +@@ -237,7 +241,7 @@ + + INIT_XMM + ; ff_h264_idct8_add_sse2(uint8_t *dst, int16_t *block, int stride) +-cglobal h264_idct8_add_sse2, 3, 4, 10 ++cglobal h264_idct8_add_8_sse2, 3, 4, 10 + IDCT8_ADD_SSE r0, r1, r2, r3 + RET + +@@ -261,7 +265,7 @@ + packuswb m1, m1 + %endmacro + +-%macro DC_ADD_MMX2_OP 3-4 ++%macro DC_ADD_MMX2_OP 4 + %1 m2, [%2 ] + %1 m3, [%2+%3 ] + %1 m4, [%2+%3*2] +@@ -282,13 +286,13 @@ + + INIT_MMX + ; ff_h264_idct_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride) +-cglobal h264_idct_dc_add_mmx2, 3, 3, 0 ++cglobal h264_idct_dc_add_8_mmx2, 3, 3, 0 + DC_ADD_MMX2_INIT r1, r2 + DC_ADD_MMX2_OP movh, r0, r2, r1 + RET + + ; ff_h264_idct8_dc_add_mmx2(uint8_t *dst, int16_t *block, int stride) +-cglobal h264_idct8_dc_add_mmx2, 3, 3, 0 ++cglobal h264_idct8_dc_add_8_mmx2, 3, 3, 0 + DC_ADD_MMX2_INIT r1, r2 + DC_ADD_MMX2_OP mova, r0, r2, r1 + lea r0, [r0+r2*4] +@@ -297,7 +301,7 @@ + + ; ff_h264_idct_add16_mmx(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16_mmx, 5, 7, 0 ++cglobal h264_idct_add16_8_mmx, 5, 7, 0 + xor r5, r5 + %ifdef PIC + lea r11, [scan8_mem] +@@ -319,7 +323,7 @@ + + ; ff_h264_idct8_add4_mmx(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct8_add4_mmx, 5, 7, 0 ++cglobal h264_idct8_add4_8_mmx, 5, 7, 0 + %assign pad 128+4-(stack_offset&7) + SUB rsp, pad + +@@ -333,7 +337,7 @@ + test r6, r6 + jz .skipblock + mov r6d, dword [r1+r5*4] +- lea r6, [r0+r6] ++ add r6, r0 + add word [r2], 32 + IDCT8_ADD_MMX_START r2 , rsp + IDCT8_ADD_MMX_START r2+8, rsp+64 +@@ -351,7 +355,7 @@ + + ; ff_h264_idct_add16_mmx2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16_mmx2, 5, 7, 0 ++cglobal h264_idct_add16_8_mmx2, 5, 7, 0 + xor r5, r5 + %ifdef PIC + lea r11, [scan8_mem] +@@ -387,7 +391,7 @@ + REP_RET + .no_dc + mov r6d, dword [r1+r5*4] +- lea r6, [r0+r6] ++ add r6, r0 + IDCT4_ADD r6, r2, r3 + .skipblock + inc r5 +@@ -398,7 +402,7 @@ + + ; ff_h264_idct_add16intra_mmx(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16intra_mmx, 5, 7, 0 ++cglobal h264_idct_add16intra_8_mmx, 5, 7, 0 + xor r5, r5 + %ifdef PIC + lea r11, [scan8_mem] +@@ -410,7 +414,7 @@ + test r6, r6 + jz .skipblock + mov r6d, dword [r1+r5*4] +- lea r6, [r0+r6] ++ add r6, r0 + IDCT4_ADD r6, r2, r3 + .skipblock + inc r5 +@@ -421,7 +425,7 @@ + + ; ff_h264_idct_add16intra_mmx2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16intra_mmx2, 5, 7, 0 ++cglobal h264_idct_add16intra_8_mmx2, 5, 7, 0 + xor r5, r5 + %ifdef PIC + lea r11, [scan8_mem] +@@ -452,7 +456,7 @@ + %define dst_regd r1d + %endif + mov dst_regd, dword [r1+r5*4] +- lea dst_reg, [r0+dst_reg] ++ add dst_reg, r0 + DC_ADD_MMX2_OP movh, dst_reg, r3, r6 + %ifndef ARCH_X86_64 + mov r1, r1m +@@ -466,7 +470,7 @@ + + ; ff_h264_idct8_add4_mmx2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct8_add4_mmx2, 5, 7, 0 ++cglobal h264_idct8_add4_8_mmx2, 5, 7, 0 + %assign pad 128+4-(stack_offset&7) + SUB rsp, pad + +@@ -509,7 +513,7 @@ + RET + .no_dc + mov r6d, dword [r1+r5*4] +- lea r6, [r0+r6] ++ add r6, r0 + add word [r2], 32 + IDCT8_ADD_MMX_START r2 , rsp + IDCT8_ADD_MMX_START r2+8, rsp+64 +@@ -529,7 +533,7 @@ + INIT_XMM + ; ff_h264_idct8_add4_sse2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct8_add4_sse2, 5, 7, 10 ++cglobal h264_idct8_add4_8_sse2, 5, 7, 10 + xor r5, r5 + %ifdef PIC + lea r11, [scan8_mem] +@@ -554,7 +558,7 @@ + %define dst_regd r1d + %endif + mov dst_regd, dword [r1+r5*4] +- lea dst_reg, [r0+dst_reg] ++ add dst_reg, r0 + DC_ADD_MMX2_OP mova, dst_reg, r3, r6 + lea dst_reg, [dst_reg+r3*4] + DC_ADD_MMX2_OP mova, dst_reg, r3, r6 +@@ -569,7 +573,7 @@ + .no_dc + INIT_XMM + mov dst_regd, dword [r1+r5*4] +- lea dst_reg, [r0+dst_reg] ++ add dst_reg, r0 + IDCT8_ADD_SSE dst_reg, r2, r3, r6 + %ifndef ARCH_X86_64 + mov r1, r1m +@@ -607,7 +611,7 @@ + + ; ff_h264_idct_add8_mmx(uint8_t **dest, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add8_mmx, 5, 7, 0 ++cglobal h264_idct_add8_8_mmx, 5, 7, 0 + mov r5, 16 + add r2, 512 + %ifdef PIC +@@ -617,6 +621,8 @@ + mov r10, r0 + %endif + call h264_idct_add8_mmx_plane ++ mov r5, 32 ++ add r2, 384 + %ifdef ARCH_X86_64 + add r10, gprsize + %else +@@ -668,7 +674,7 @@ + + ; ff_h264_idct_add8_mmx2(uint8_t **dest, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add8_mmx2, 5, 7, 0 ++cglobal h264_idct_add8_8_mmx2, 5, 7, 0 + mov r5, 16 + add r2, 512 + %ifdef ARCH_X86_64 +@@ -678,6 +684,8 @@ + lea r11, [scan8_mem] + %endif + call h264_idct_add8_mmx2_plane ++ mov r5, 32 ++ add r2, 384 + %ifdef ARCH_X86_64 + add r10, gprsize + %else +@@ -715,10 +723,10 @@ + movhps m1, [r2+40] + movhps m2, [r2+48] + movhps m3, [r2+56] +- IDCT4_1D 0,1,2,3,4,5 ++ IDCT4_1D w,0,1,2,3,4,5 + TRANSPOSE2x4x4W 0,1,2,3,4 + paddw m0, [pw_32] +- IDCT4_1D 0,1,2,3,4,5 ++ IDCT4_1D w,0,1,2,3,4,5 + pxor m7, m7 + STORE_DIFFx2 m0, m1, m4, m5, m7, 6, r0, r3 + lea r0, [r0+r3*2] +@@ -744,7 +752,7 @@ + + ; ff_h264_idct_add16_sse2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16_sse2, 5, 5, 8 ++cglobal h264_idct_add16_8_sse2, 5, 5, 8 + %ifdef ARCH_X86_64 + mov r10, r0 + %endif +@@ -791,7 +799,7 @@ + + ; ff_h264_idct_add16intra_sse2(uint8_t *dst, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add16intra_sse2, 5, 7, 8 ++cglobal h264_idct_add16intra_8_sse2, 5, 7, 8 + %ifdef ARCH_X86_64 + mov r10, r0 + %endif +@@ -810,12 +818,12 @@ + test r0, r0 + jz .try%1dc + %ifdef ARCH_X86_64 +- mov r0d, dword [r1+%1*8+64] ++ mov r0d, dword [r1+(%1&1)*8+64*(1+(%1>>1))] + add r0, [r10] + %else + mov r0, r0m + mov r0, [r0] +- add r0, dword [r1+%1*8+64] ++ add r0, dword [r1+(%1&1)*8+64*(1+(%1>>1))] + %endif + call x264_add8x4_idct_sse2 + jmp .cycle%1end +@@ -824,43 +832,45 @@ + or r0w, word [r2+32] + jz .cycle%1end + %ifdef ARCH_X86_64 +- mov r0d, dword [r1+%1*8+64] ++ mov r0d, dword [r1+(%1&1)*8+64*(1+(%1>>1))] + add r0, [r10] + %else + mov r0, r0m + mov r0, [r0] +- add r0, dword [r1+%1*8+64] ++ add r0, dword [r1+(%1&1)*8+64*(1+(%1>>1))] + %endif + call h264_idct_dc_add8_mmx2 + .cycle%1end +-%if %1 < 3 ++%if %1 == 1 ++ add r2, 384+64 ++%elif %1 < 3 + add r2, 64 + %endif + %endmacro + + ; ff_h264_idct_add8_sse2(uint8_t **dest, const int *block_offset, + ; DCTELEM *block, int stride, const uint8_t nnzc[6*8]) +-cglobal h264_idct_add8_sse2, 5, 7, 8 ++cglobal h264_idct_add8_8_sse2, 5, 7, 8 + add r2, 512 + %ifdef ARCH_X86_64 + mov r10, r0 + %endif +- add8_sse2_cycle 0, 0x09 +- add8_sse2_cycle 1, 0x11 ++ add8_sse2_cycle 0, 0x34 ++ add8_sse2_cycle 1, 0x3c + %ifdef ARCH_X86_64 + add r10, gprsize + %else + add r0mp, gprsize + %endif +- add8_sse2_cycle 2, 0x21 +- add8_sse2_cycle 3, 0x29 ++ add8_sse2_cycle 2, 0x5c ++ add8_sse2_cycle 3, 0x64 + RET + + ;void ff_h264_luma_dc_dequant_idct_mmx(DCTELEM *output, DCTELEM *input, int qmul) + + %macro WALSH4_1D 5 +- SUMSUB_BADC m%4, m%3, m%2, m%1, m%5 +- SUMSUB_BADC m%4, m%2, m%3, m%1, m%5 ++ SUMSUB_BADC w, %4, %3, %2, %1, %5 ++ SUMSUB_BADC w, %4, %2, %3, %1, %5 + SWAP %1, %4, %3 + %endmacro + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred_10bit.asm 2012-05-14 14:08:54.549344308 +0200 +@@ -0,0 +1,1208 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 intra prediction code ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Daniel Kang ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++cextern pw_16 ++cextern pw_8 ++cextern pw_4 ++cextern pw_2 ++cextern pw_1 ++ ++pw_m32101234: dw -3, -2, -1, 0, 1, 2, 3, 4 ++pw_m3: times 8 dw -3 ++pw_pixel_max: times 8 dw ((1 << 10)-1) ++pw_512: times 8 dw 512 ++pd_17: times 4 dd 17 ++pd_16: times 4 dd 16 ++ ++SECTION .text ++ ++; dest, left, right, src ++; output: %1 = (t[n-1] + t[n]*2 + t[n+1] + 2) >> 2 ++%macro PRED4x4_LOWPASS 4 ++ paddw %2, %3 ++ psrlw %2, 1 ++ pavgw %1, %4, %2 ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_down_right(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED4x4_DR 1 ++cglobal pred4x4_down_right_10_%1, 3,3 ++ sub r0, r2 ++ lea r1, [r0+r2*2] ++ movhps m1, [r1-8] ++ movhps m2, [r0+r2*1-8] ++ movhps m4, [r0-8] ++ punpckhwd m2, m4 ++ movq m3, [r0] ++ punpckhdq m1, m2 ++ PALIGNR m3, m1, 10, m1 ++ movhps m4, [r1+r2*1-8] ++ PALIGNR m0, m3, m4, 14, m4 ++ movhps m4, [r1+r2*2-8] ++ PALIGNR m2, m0, m4, 14, m4 ++ PRED4x4_LOWPASS m0, m2, m3, m0 ++ movq [r1+r2*2], m0 ++ psrldq m0, 2 ++ movq [r1+r2*1], m0 ++ psrldq m0, 2 ++ movq [r0+r2*2], m0 ++ psrldq m0, 2 ++ movq [r0+r2*1], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED4x4_DR sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED4x4_DR ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED4x4_DR avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_vertical_right(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED4x4_VR 1 ++cglobal pred4x4_vertical_right_10_%1, 3,3,6 ++ sub r0, r2 ++ lea r1, [r0+r2*2] ++ movq m5, [r0] ; ........t3t2t1t0 ++ movhps m1, [r0-8] ++ PALIGNR m0, m5, m1, 14, m1 ; ......t3t2t1t0lt ++ pavgw m5, m0 ++ movhps m1, [r0+r2*1-8] ++ PALIGNR m0, m1, 14, m1 ; ....t3t2t1t0ltl0 ++ movhps m2, [r0+r2*2-8] ++ PALIGNR m1, m0, m2, 14, m2 ; ..t3t2t1t0ltl0l1 ++ movhps m3, [r1+r2*1-8] ++ PALIGNR m2, m1, m3, 14, m3 ; t3t2t1t0ltl0l1l2 ++ PRED4x4_LOWPASS m1, m0, m2, m1 ++ pslldq m0, m1, 12 ++ psrldq m1, 4 ++ movq [r0+r2*1], m5 ++ movq [r0+r2*2], m1 ++ PALIGNR m5, m0, 14, m2 ++ pslldq m0, 2 ++ movq [r1+r2*1], m5 ++ PALIGNR m1, m0, 14, m0 ++ movq [r1+r2*2], m1 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED4x4_VR sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED4x4_VR ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED4x4_VR avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_horizontal_down(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED4x4_HD 1 ++cglobal pred4x4_horizontal_down_10_%1, 3,3 ++ sub r0, r2 ++ lea r1, [r0+r2*2] ++ movq m0, [r0-8] ; lt .. ++ movhps m0, [r0] ++ pslldq m0, 2 ; t2 t1 t0 lt .. .. .. .. ++ movq m1, [r1+r2*2-8] ; l3 ++ movq m3, [r1+r2*1-8] ++ punpcklwd m1, m3 ; l2 l3 ++ movq m2, [r0+r2*2-8] ; l1 ++ movq m3, [r0+r2*1-8] ++ punpcklwd m2, m3 ; l0 l1 ++ punpckhdq m1, m2 ; l0 l1 l2 l3 ++ punpckhqdq m1, m0 ; t2 t1 t0 lt l0 l1 l2 l3 ++ psrldq m0, m1, 4 ; .. .. t2 t1 t0 lt l0 l1 ++ psrldq m3, m1, 2 ; .. t2 t1 t0 lt l0 l1 l2 ++ pavgw m5, m1, m3 ++ PRED4x4_LOWPASS m3, m1, m0, m3 ++ punpcklwd m5, m3 ++ psrldq m3, 8 ++ PALIGNR m3, m5, 12, m4 ++ movq [r1+r2*2], m5 ++ movhps [r0+r2*2], m5 ++ psrldq m5, 4 ++ movq [r1+r2*1], m5 ++ movq [r0+r2*1], m3 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED4x4_HD sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED4x4_HD ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED4x4_HD avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_dc(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro HADDD 2 ; sum junk ++%if mmsize == 16 ++ movhlps %2, %1 ++ paddd %1, %2 ++ pshuflw %2, %1, 0xE ++ paddd %1, %2 ++%else ++ pshufw %2, %1, 0xE ++ paddd %1, %2 ++%endif ++%endmacro ++ ++%macro HADDW 2 ++ pmaddwd %1, [pw_1] ++ HADDD %1, %2 ++%endmacro ++ ++INIT_MMX ++cglobal pred4x4_dc_10_mmxext, 3,3 ++ sub r0, r2 ++ lea r1, [r0+r2*2] ++ movq m2, [r0+r2*1-8] ++ paddw m2, [r0+r2*2-8] ++ paddw m2, [r1+r2*1-8] ++ paddw m2, [r1+r2*2-8] ++ psrlq m2, 48 ++ movq m0, [r0] ++ HADDW m0, m1 ++ paddw m0, [pw_4] ++ paddw m0, m2 ++ psrlw m0, 3 ++ SPLATW m0, m0, 0 ++ movq [r0+r2*1], m0 ++ movq [r0+r2*2], m0 ++ movq [r1+r2*1], m0 ++ movq [r1+r2*2], m0 ++ RET ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_down_left(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED4x4_DL 1 ++cglobal pred4x4_down_left_10_%1, 3,3 ++ sub r0, r2 ++ movq m0, [r0] ++ movhps m0, [r1] ++ psrldq m2, m0, 2 ++ pslldq m3, m0, 2 ++ pshufhw m2, m2, 10100100b ++ PRED4x4_LOWPASS m0, m3, m2, m0 ++ lea r1, [r0+r2*2] ++ movhps [r1+r2*2], m0 ++ psrldq m0, 2 ++ movq [r0+r2*1], m0 ++ psrldq m0, 2 ++ movq [r0+r2*2], m0 ++ psrldq m0, 2 ++ movq [r1+r2*1], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++PRED4x4_DL sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED4x4_DL avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_vertical_left(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED4x4_VL 1 ++cglobal pred4x4_vertical_left_10_%1, 3,3 ++ sub r0, r2 ++ movu m1, [r0] ++ movhps m1, [r1] ++ psrldq m0, m1, 2 ++ psrldq m2, m1, 4 ++ pavgw m4, m0, m1 ++ PRED4x4_LOWPASS m0, m1, m2, m0 ++ lea r1, [r0+r2*2] ++ movq [r0+r2*1], m4 ++ movq [r0+r2*2], m0 ++ psrldq m4, 2 ++ psrldq m0, 2 ++ movq [r1+r2*1], m4 ++ movq [r1+r2*2], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++PRED4x4_VL sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED4x4_VL avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred4x4_horizontal_up(pixel *src, const pixel *topright, int stride) ++;----------------------------------------------------------------------------- ++INIT_MMX ++cglobal pred4x4_horizontal_up_10_mmxext, 3,3 ++ sub r0, r2 ++ lea r1, [r0+r2*2] ++ movq m0, [r0+r2*1-8] ++ punpckhwd m0, [r0+r2*2-8] ++ movq m1, [r1+r2*1-8] ++ punpckhwd m1, [r1+r2*2-8] ++ punpckhdq m0, m1 ++ pshufw m1, m1, 0xFF ++ movq [r1+r2*2], m1 ++ movd [r1+r2*1+4], m1 ++ pshufw m2, m0, 11111001b ++ movq m1, m2 ++ pavgw m2, m0 ++ ++ pshufw m5, m0, 11111110b ++ PRED4x4_LOWPASS m1, m0, m5, m1 ++ movq m6, m2 ++ punpcklwd m6, m1 ++ movq [r0+r2*1], m6 ++ psrlq m2, 16 ++ psrlq m1, 16 ++ punpcklwd m2, m1 ++ movq [r0+r2*2], m2 ++ psrlq m2, 32 ++ movd [r1+r2*1], m2 ++ RET ++ ++ ++ ++;----------------------------------------------------------------------------- ++; void pred8x8_vertical(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++INIT_XMM ++cglobal pred8x8_vertical_10_sse2, 2,2 ++ sub r0, r1 ++ mova m0, [r0] ++%rep 3 ++ mova [r0+r1*1], m0 ++ mova [r0+r1*2], m0 ++ lea r0, [r0+r1*2] ++%endrep ++ mova [r0+r1*1], m0 ++ mova [r0+r1*2], m0 ++ RET ++ ++;----------------------------------------------------------------------------- ++; void pred8x8_horizontal(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++INIT_XMM ++cglobal pred8x8_horizontal_10_sse2, 2,3 ++ mov r2d, 4 ++.loop: ++ movq m0, [r0+r1*0-8] ++ movq m1, [r0+r1*1-8] ++ pshuflw m0, m0, 0xff ++ pshuflw m1, m1, 0xff ++ punpcklqdq m0, m0 ++ punpcklqdq m1, m1 ++ mova [r0+r1*0], m0 ++ mova [r0+r1*1], m1 ++ lea r0, [r0+r1*2] ++ dec r2d ++ jg .loop ++ REP_RET ++ ++;----------------------------------------------------------------------------- ++; void predict_8x8_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MOV8 2-3 ++; sort of a hack, but it works ++%if mmsize==8 ++ movq [%1+0], %2 ++ movq [%1+8], %3 ++%else ++ movdqa [%1], %2 ++%endif ++%endmacro ++ ++%macro PRED8x8_DC 2 ++cglobal pred8x8_dc_10_%1, 2,6 ++ sub r0, r1 ++ pxor m4, m4 ++ movq m0, [r0+0] ++ movq m1, [r0+8] ++%if mmsize==16 ++ punpcklwd m0, m1 ++ movhlps m1, m0 ++ paddw m0, m1 ++%else ++ pshufw m2, m0, 00001110b ++ pshufw m3, m1, 00001110b ++ paddw m0, m2 ++ paddw m1, m3 ++ punpcklwd m0, m1 ++%endif ++ %2 m2, m0, 00001110b ++ paddw m0, m2 ++ ++ lea r5, [r1*3] ++ lea r4, [r0+r1*4] ++ movzx r2d, word [r0+r1*1-2] ++ movzx r3d, word [r0+r1*2-2] ++ add r2d, r3d ++ movzx r3d, word [r0+r5*1-2] ++ add r2d, r3d ++ movzx r3d, word [r4-2] ++ add r2d, r3d ++ movd m2, r2d ; s2 ++ ++ movzx r2d, word [r4+r1*1-2] ++ movzx r3d, word [r4+r1*2-2] ++ add r2d, r3d ++ movzx r3d, word [r4+r5*1-2] ++ add r2d, r3d ++ movzx r3d, word [r4+r1*4-2] ++ add r2d, r3d ++ movd m3, r2d ; s3 ++ ++ punpcklwd m2, m3 ++ punpckldq m0, m2 ; s0, s1, s2, s3 ++ %2 m3, m0, 11110110b ; s2, s1, s3, s3 ++ %2 m0, m0, 01110100b ; s0, s1, s3, s1 ++ paddw m0, m3 ++ psrlw m0, 2 ++ pavgw m0, m4 ; s0+s2, s1, s3, s1+s3 ++%if mmsize==16 ++ punpcklwd m0, m0 ++ pshufd m3, m0, 11111010b ++ punpckldq m0, m0 ++ SWAP 0,1 ++%else ++ pshufw m1, m0, 0x00 ++ pshufw m2, m0, 0x55 ++ pshufw m3, m0, 0xaa ++ pshufw m4, m0, 0xff ++%endif ++ MOV8 r0+r1*1, m1, m2 ++ MOV8 r0+r1*2, m1, m2 ++ MOV8 r0+r5*1, m1, m2 ++ MOV8 r0+r1*4, m1, m2 ++ MOV8 r4+r1*1, m3, m4 ++ MOV8 r4+r1*2, m3, m4 ++ MOV8 r4+r5*1, m3, m4 ++ MOV8 r4+r1*4, m3, m4 ++ RET ++%endmacro ++ ++INIT_MMX ++PRED8x8_DC mmxext, pshufw ++INIT_XMM ++PRED8x8_DC sse2 , pshuflw ++ ++;----------------------------------------------------------------------------- ++; void pred8x8_top_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++INIT_XMM ++cglobal pred8x8_top_dc_10_sse2, 2,4 ++ sub r0, r1 ++ mova m0, [r0] ++ pshuflw m1, m0, 0x4e ++ pshufhw m1, m1, 0x4e ++ paddw m0, m1 ++ pshuflw m1, m0, 0xb1 ++ pshufhw m1, m1, 0xb1 ++ paddw m0, m1 ++ lea r2, [r1*3] ++ lea r3, [r0+r1*4] ++ paddw m0, [pw_2] ++ psrlw m0, 2 ++ mova [r0+r1*1], m0 ++ mova [r0+r1*2], m0 ++ mova [r0+r2*1], m0 ++ mova [r0+r1*4], m0 ++ mova [r3+r1*1], m0 ++ mova [r3+r1*2], m0 ++ mova [r3+r2*1], m0 ++ mova [r3+r1*4], m0 ++ RET ++ ++;----------------------------------------------------------------------------- ++; void pred8x8_plane(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++INIT_XMM ++cglobal pred8x8_plane_10_sse2, 2,7,7 ++ sub r0, r1 ++ lea r2, [r1*3] ++ lea r3, [r0+r1*4] ++ mova m2, [r0] ++ pmaddwd m2, [pw_m32101234] ++ HADDD m2, m1 ++ movd m0, [r0-4] ++ psrld m0, 14 ++ psubw m2, m0 ; H ++ movd m0, [r3+r1*4-4] ++ movd m1, [r0+12] ++ paddw m0, m1 ++ psllw m0, 4 ; 16*(src[7*stride-1] + src[-stride+7]) ++ movzx r4d, word [r3+r1*1-2] ; src[4*stride-1] ++ movzx r5d, word [r0+r2*1-2] ; src[2*stride-1] ++ sub r4d, r5d ++ movzx r6d, word [r3+r1*2-2] ; src[5*stride-1] ++ movzx r5d, word [r0+r1*2-2] ; src[1*stride-1] ++ sub r6d, r5d ++ lea r4d, [r4+r6*2] ++ movzx r5d, word [r3+r2*1-2] ; src[6*stride-1] ++ movzx r6d, word [r0+r1*1-2] ; src[0*stride-1] ++ sub r5d, r6d ++ lea r5d, [r5*3] ++ add r4d, r5d ++ movzx r6d, word [r3+r1*4-2] ; src[7*stride-1] ++ movzx r5d, word [r0+r1*0-2] ; src[ -stride-1] ++ sub r6d, r5d ++ lea r4d, [r4+r6*4] ++ movd m3, r4d ; V ++ punpckldq m2, m3 ++ pmaddwd m2, [pd_17] ++ paddd m2, [pd_16] ++ psrad m2, 5 ; b, c ++ ++ mova m3, [pw_pixel_max] ++ pxor m1, m1 ++ SPLATW m0, m0, 1 ++ SPLATW m4, m2, 2 ++ SPLATW m2, m2, 0 ++ pmullw m2, [pw_m32101234] ; b ++ pmullw m5, m4, [pw_m3] ; c ++ paddw m5, [pw_16] ++ mov r2d, 8 ++ add r0, r1 ++.loop: ++ paddsw m6, m2, m5 ++ paddsw m6, m0 ++ psraw m6, 5 ++ CLIPW m6, m1, m3 ++ mova [r0], m6 ++ paddw m5, m4 ++ add r0, r1 ++ dec r2d ++ jg .loop ++ REP_RET ++ ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_128_dc(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_128_DC 1 ++cglobal pred8x8l_128_dc_10_%1, 4,4 ++ mova m0, [pw_512] ; (1<<(BIT_DEPTH-1)) ++ lea r1, [r3*3] ++ lea r2, [r0+r3*4] ++ MOV8 r0+r3*0, m0, m0 ++ MOV8 r0+r3*1, m0, m0 ++ MOV8 r0+r3*2, m0, m0 ++ MOV8 r0+r1*1, m0, m0 ++ MOV8 r2+r3*0, m0, m0 ++ MOV8 r2+r3*1, m0, m0 ++ MOV8 r2+r3*2, m0, m0 ++ MOV8 r2+r1*1, m0, m0 ++ RET ++%endmacro ++ ++INIT_MMX ++PRED8x8L_128_DC mmxext ++INIT_XMM ++PRED8x8L_128_DC sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_top_dc(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_TOP_DC 1 ++cglobal pred8x8l_top_dc_10_%1, 4,4,6 ++ sub r0, r3 ++ mova m0, [r0] ++ shr r1d, 14 ++ shr r2d, 13 ++ neg r1 ++ pslldq m1, m0, 2 ++ psrldq m2, m0, 2 ++ pinsrw m1, [r0+r1], 0 ++ pinsrw m2, [r0+r2+14], 7 ++ lea r1, [r3*3] ++ lea r2, [r0+r3*4] ++ PRED4x4_LOWPASS m0, m2, m1, m0 ++ HADDW m0, m1 ++ paddw m0, [pw_4] ++ psrlw m0, 3 ++ SPLATW m0, m0, 0 ++ mova [r0+r3*1], m0 ++ mova [r0+r3*2], m0 ++ mova [r0+r1*1], m0 ++ mova [r0+r3*4], m0 ++ mova [r2+r3*1], m0 ++ mova [r2+r3*2], m0 ++ mova [r2+r1*1], m0 ++ mova [r2+r3*4], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++PRED8x8L_TOP_DC sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_TOP_DC avx ++%endif ++ ++;----------------------------------------------------------------------------- ++;void pred8x8l_dc(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++;TODO: see if scalar is faster ++%macro PRED8x8L_DC 1 ++cglobal pred8x8l_dc_10_%1, 4,6,6 ++ sub r0, r3 ++ lea r4, [r0+r3*4] ++ lea r5, [r3*3] ++ mova m0, [r0+r3*2-16] ++ punpckhwd m0, [r0+r3*1-16] ++ mova m1, [r4+r3*0-16] ++ punpckhwd m1, [r0+r5*1-16] ++ punpckhdq m1, m0 ++ mova m2, [r4+r3*2-16] ++ punpckhwd m2, [r4+r3*1-16] ++ mova m3, [r4+r3*4-16] ++ punpckhwd m3, [r4+r5*1-16] ++ punpckhdq m3, m2 ++ punpckhqdq m3, m1 ++ mova m0, [r0] ++ shr r1d, 14 ++ shr r2d, 13 ++ neg r1 ++ pslldq m1, m0, 2 ++ psrldq m2, m0, 2 ++ pinsrw m1, [r0+r1], 0 ++ pinsrw m2, [r0+r2+14], 7 ++ not r1 ++ and r1, r3 ++ pslldq m4, m3, 2 ++ psrldq m5, m3, 2 ++ pshuflw m4, m4, 11100101b ++ pinsrw m5, [r0+r1-2], 7 ++ PRED4x4_LOWPASS m3, m4, m5, m3 ++ PRED4x4_LOWPASS m0, m2, m1, m0 ++ paddw m0, m3 ++ HADDW m0, m1 ++ paddw m0, [pw_8] ++ psrlw m0, 4 ++ SPLATW m0, m0 ++ mova [r0+r3*1], m0 ++ mova [r0+r3*2], m0 ++ mova [r0+r5*1], m0 ++ mova [r0+r3*4], m0 ++ mova [r4+r3*1], m0 ++ mova [r4+r3*2], m0 ++ mova [r4+r5*1], m0 ++ mova [r4+r3*4], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++PRED8x8L_DC sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_DC avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_vertical(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_VERTICAL 1 ++cglobal pred8x8l_vertical_10_%1, 4,4,6 ++ sub r0, r3 ++ mova m0, [r0] ++ shr r1d, 14 ++ shr r2d, 13 ++ neg r1 ++ pslldq m1, m0, 2 ++ psrldq m2, m0, 2 ++ pinsrw m1, [r0+r1], 0 ++ pinsrw m2, [r0+r2+14], 7 ++ lea r1, [r3*3] ++ lea r2, [r0+r3*4] ++ PRED4x4_LOWPASS m0, m2, m1, m0 ++ mova [r0+r3*1], m0 ++ mova [r0+r3*2], m0 ++ mova [r0+r1*1], m0 ++ mova [r0+r3*4], m0 ++ mova [r2+r3*1], m0 ++ mova [r2+r3*2], m0 ++ mova [r2+r1*1], m0 ++ mova [r2+r3*4], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++PRED8x8L_VERTICAL sse2 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_VERTICAL avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_horizontal(uint8_t *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_HORIZONTAL 1 ++cglobal pred8x8l_horizontal_10_%1, 4,4,5 ++ mova m0, [r0-16] ++ shr r1d, 14 ++ dec r1 ++ and r1, r3 ++ sub r1, r3 ++ punpckhwd m0, [r0+r1-16] ++ mova m1, [r0+r3*2-16] ++ punpckhwd m1, [r0+r3*1-16] ++ lea r2, [r0+r3*4] ++ lea r1, [r3*3] ++ punpckhdq m1, m0 ++ mova m2, [r2+r3*0-16] ++ punpckhwd m2, [r0+r1-16] ++ mova m3, [r2+r3*2-16] ++ punpckhwd m3, [r2+r3*1-16] ++ punpckhdq m3, m2 ++ punpckhqdq m3, m1 ++ PALIGNR m4, m3, [r2+r1-16], 14, m0 ++ pslldq m0, m4, 2 ++ pshuflw m0, m0, 11100101b ++ PRED4x4_LOWPASS m4, m3, m0, m4 ++ punpckhwd m3, m4, m4 ++ punpcklwd m4, m4 ++ pshufd m0, m3, 0xff ++ pshufd m1, m3, 0xaa ++ pshufd m2, m3, 0x55 ++ pshufd m3, m3, 0x00 ++ mova [r0+r3*0], m0 ++ mova [r0+r3*1], m1 ++ mova [r0+r3*2], m2 ++ mova [r0+r1*1], m3 ++ pshufd m0, m4, 0xff ++ pshufd m1, m4, 0xaa ++ pshufd m2, m4, 0x55 ++ pshufd m3, m4, 0x00 ++ mova [r2+r3*0], m0 ++ mova [r2+r3*1], m1 ++ mova [r2+r3*2], m2 ++ mova [r2+r1*1], m3 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED8x8L_HORIZONTAL sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED8x8L_HORIZONTAL ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_HORIZONTAL avx ++%endif ++ ++;----------------------------------------------------------------------------- ++;void pred8x8l_down_left(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_DOWN_LEFT 1 ++cglobal pred8x8l_down_left_10_%1, 4,4,7 ++ sub r0, r3 ++ mova m3, [r0] ++ shr r1d, 14 ++ neg r1 ++ shr r2d, 13 ++ pslldq m1, m3, 2 ++ psrldq m2, m3, 2 ++ pinsrw m1, [r0+r1], 0 ++ pinsrw m2, [r0+r2+14], 7 ++ PRED4x4_LOWPASS m6, m2, m1, m3 ++ jz .fix_tr ; flags from shr r2d ++ mova m1, [r0+16] ++ psrldq m5, m1, 2 ++ PALIGNR m2, m1, m3, 14, m3 ++ pshufhw m5, m5, 10100100b ++ PRED4x4_LOWPASS m1, m2, m5, m1 ++.do_topright: ++ lea r1, [r3*3] ++ psrldq m5, m1, 14 ++ lea r2, [r0+r3*4] ++ PALIGNR m2, m1, m6, 2, m0 ++ PALIGNR m3, m1, m6, 14, m0 ++ PALIGNR m5, m1, 2, m0 ++ pslldq m4, m6, 2 ++ PRED4x4_LOWPASS m6, m4, m2, m6 ++ PRED4x4_LOWPASS m1, m3, m5, m1 ++ mova [r2+r3*4], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r2+r1*1], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r2+r3*2], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r2+r3*1], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r3*4], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r1*1], m1 ++ PALIGNR m1, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r3*2], m1 ++ PALIGNR m1, m6, 14, m6 ++ mova [r0+r3*1], m1 ++ RET ++.fix_tr: ++ punpckhwd m3, m3 ++ pshufd m1, m3, 0xFF ++ jmp .do_topright ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED8x8L_DOWN_LEFT sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED8x8L_DOWN_LEFT ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_DOWN_LEFT avx ++%endif ++ ++;----------------------------------------------------------------------------- ++;void pred8x8l_down_right(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_DOWN_RIGHT 1 ++; standard forbids this when has_topleft is false ++; no need to check ++cglobal pred8x8l_down_right_10_%1, 4,5,8 ++ sub r0, r3 ++ lea r4, [r0+r3*4] ++ lea r1, [r3*3] ++ mova m0, [r0+r3*1-16] ++ punpckhwd m0, [r0+r3*0-16] ++ mova m1, [r0+r1*1-16] ++ punpckhwd m1, [r0+r3*2-16] ++ punpckhdq m1, m0 ++ mova m2, [r4+r3*1-16] ++ punpckhwd m2, [r4+r3*0-16] ++ mova m3, [r4+r1*1-16] ++ punpckhwd m3, [r4+r3*2-16] ++ punpckhdq m3, m2 ++ punpckhqdq m3, m1 ++ mova m0, [r4+r3*4-16] ++ mova m1, [r0] ++ PALIGNR m4, m3, m0, 14, m0 ++ PALIGNR m1, m3, 2, m2 ++ pslldq m0, m4, 2 ++ pshuflw m0, m0, 11100101b ++ PRED4x4_LOWPASS m6, m1, m4, m3 ++ PRED4x4_LOWPASS m4, m3, m0, m4 ++ mova m3, [r0] ++ shr r2d, 13 ++ pslldq m1, m3, 2 ++ psrldq m2, m3, 2 ++ pinsrw m1, [r0-2], 0 ++ pinsrw m2, [r0+r2+14], 7 ++ PRED4x4_LOWPASS m3, m2, m1, m3 ++ PALIGNR m2, m3, m6, 2, m0 ++ PALIGNR m5, m3, m6, 14, m0 ++ psrldq m7, m3, 2 ++ PRED4x4_LOWPASS m6, m4, m2, m6 ++ PRED4x4_LOWPASS m3, m5, m7, m3 ++ mova [r4+r3*4], m6 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r3*1], m3 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r3*2], m3 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r1*1], m3 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r0+r3*4], m3 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r4+r3*1], m3 ++ PALIGNR m3, m6, 14, m2 ++ pslldq m6, 2 ++ mova [r4+r3*2], m3 ++ PALIGNR m3, m6, 14, m6 ++ mova [r4+r1*1], m3 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED8x8L_DOWN_RIGHT sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED8x8L_DOWN_RIGHT ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_DOWN_RIGHT avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_vertical_right(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_VERTICAL_RIGHT 1 ++; likewise with 8x8l_down_right ++cglobal pred8x8l_vertical_right_10_%1, 4,5,7 ++ sub r0, r3 ++ lea r4, [r0+r3*4] ++ lea r1, [r3*3] ++ mova m0, [r0+r3*1-16] ++ punpckhwd m0, [r0+r3*0-16] ++ mova m1, [r0+r1*1-16] ++ punpckhwd m1, [r0+r3*2-16] ++ punpckhdq m1, m0 ++ mova m2, [r4+r3*1-16] ++ punpckhwd m2, [r4+r3*0-16] ++ mova m3, [r4+r1*1-16] ++ punpckhwd m3, [r4+r3*2-16] ++ punpckhdq m3, m2 ++ punpckhqdq m3, m1 ++ mova m0, [r4+r3*4-16] ++ mova m1, [r0] ++ PALIGNR m4, m3, m0, 14, m0 ++ PALIGNR m1, m3, 2, m2 ++ PRED4x4_LOWPASS m3, m1, m4, m3 ++ mova m2, [r0] ++ shr r2d, 13 ++ pslldq m1, m2, 2 ++ psrldq m5, m2, 2 ++ pinsrw m1, [r0-2], 0 ++ pinsrw m5, [r0+r2+14], 7 ++ PRED4x4_LOWPASS m2, m5, m1, m2 ++ PALIGNR m6, m2, m3, 12, m1 ++ PALIGNR m5, m2, m3, 14, m0 ++ PRED4x4_LOWPASS m0, m6, m2, m5 ++ pavgw m2, m5 ++ mova [r0+r3*2], m0 ++ mova [r0+r3*1], m2 ++ pslldq m6, m3, 4 ++ pslldq m1, m3, 2 ++ PRED4x4_LOWPASS m1, m3, m6, m1 ++ PALIGNR m2, m1, 14, m4 ++ mova [r0+r1*1], m2 ++ pslldq m1, 2 ++ PALIGNR m0, m1, 14, m3 ++ mova [r0+r3*4], m0 ++ pslldq m1, 2 ++ PALIGNR m2, m1, 14, m4 ++ mova [r4+r3*1], m2 ++ pslldq m1, 2 ++ PALIGNR m0, m1, 14, m3 ++ mova [r4+r3*2], m0 ++ pslldq m1, 2 ++ PALIGNR m2, m1, 14, m4 ++ mova [r4+r1*1], m2 ++ pslldq m1, 2 ++ PALIGNR m0, m1, 14, m1 ++ mova [r4+r3*4], m0 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED8x8L_VERTICAL_RIGHT sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED8x8L_VERTICAL_RIGHT ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_VERTICAL_RIGHT avx ++%endif ++ ++;----------------------------------------------------------------------------- ++; void pred8x8l_horizontal_up(pixel *src, int has_topleft, int has_topright, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED8x8L_HORIZONTAL_UP 1 ++cglobal pred8x8l_horizontal_up_10_%1, 4,4,6 ++ mova m0, [r0+r3*0-16] ++ punpckhwd m0, [r0+r3*1-16] ++ shr r1d, 14 ++ dec r1 ++ and r1, r3 ++ sub r1, r3 ++ mova m4, [r0+r1*1-16] ++ lea r1, [r3*3] ++ lea r2, [r0+r3*4] ++ mova m1, [r0+r3*2-16] ++ punpckhwd m1, [r0+r1*1-16] ++ punpckhdq m0, m1 ++ mova m2, [r2+r3*0-16] ++ punpckhwd m2, [r2+r3*1-16] ++ mova m3, [r2+r3*2-16] ++ punpckhwd m3, [r2+r1*1-16] ++ punpckhdq m2, m3 ++ punpckhqdq m0, m2 ++ PALIGNR m1, m0, m4, 14, m4 ++ psrldq m2, m0, 2 ++ pshufhw m2, m2, 10100100b ++ PRED4x4_LOWPASS m0, m1, m2, m0 ++ psrldq m1, m0, 2 ++ psrldq m2, m0, 4 ++ pshufhw m1, m1, 10100100b ++ pshufhw m2, m2, 01010100b ++ pavgw m4, m0, m1 ++ PRED4x4_LOWPASS m1, m2, m0, m1 ++ punpckhwd m5, m4, m1 ++ punpcklwd m4, m1 ++ mova [r2+r3*0], m5 ++ mova [r0+r3*0], m4 ++ pshufd m0, m5, 11111001b ++ pshufd m1, m5, 11111110b ++ pshufd m2, m5, 11111111b ++ mova [r2+r3*1], m0 ++ mova [r2+r3*2], m1 ++ mova [r2+r1*1], m2 ++ PALIGNR m2, m5, m4, 4, m0 ++ PALIGNR m3, m5, m4, 8, m1 ++ PALIGNR m5, m5, m4, 12, m4 ++ mova [r0+r3*1], m2 ++ mova [r0+r3*2], m3 ++ mova [r0+r1*1], m5 ++ RET ++%endmacro ++ ++INIT_XMM ++%define PALIGNR PALIGNR_MMX ++PRED8x8L_HORIZONTAL_UP sse2 ++%define PALIGNR PALIGNR_SSSE3 ++PRED8x8L_HORIZONTAL_UP ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++PRED8x8L_HORIZONTAL_UP avx ++%endif ++ ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_vertical(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MOV16 3-5 ++ mova [%1+ 0], %2 ++ mova [%1+mmsize], %3 ++%if mmsize==8 ++ mova [%1+ 16], %4 ++ mova [%1+ 24], %5 ++%endif ++%endmacro ++ ++%macro PRED16x16_VERTICAL 1 ++cglobal pred16x16_vertical_10_%1, 2,3 ++ sub r0, r1 ++ mov r2d, 8 ++ mova m0, [r0+ 0] ++ mova m1, [r0+mmsize] ++%if mmsize==8 ++ mova m2, [r0+16] ++ mova m3, [r0+24] ++%endif ++.loop: ++ MOV16 r0+r1*1, m0, m1, m2, m3 ++ MOV16 r0+r1*2, m0, m1, m2, m3 ++ lea r0, [r0+r1*2] ++ dec r2d ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_VERTICAL mmxext ++INIT_XMM ++PRED16x16_VERTICAL sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_horizontal(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED16x16_HORIZONTAL 1 ++cglobal pred16x16_horizontal_10_%1, 2,3 ++ mov r2d, 8 ++.vloop: ++ movd m0, [r0+r1*0-4] ++ movd m1, [r0+r1*1-4] ++ SPLATW m0, m0, 1 ++ SPLATW m1, m1, 1 ++ MOV16 r0+r1*0, m0, m0, m0, m0 ++ MOV16 r0+r1*1, m1, m1, m1, m1 ++ lea r0, [r0+r1*2] ++ dec r2d ++ jg .vloop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_HORIZONTAL mmxext ++INIT_XMM ++PRED16x16_HORIZONTAL sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED16x16_DC 1 ++cglobal pred16x16_dc_10_%1, 2,6 ++ mov r5, r0 ++ sub r0, r1 ++ mova m0, [r0+0] ++ paddw m0, [r0+mmsize] ++%if mmsize==8 ++ paddw m0, [r0+16] ++ paddw m0, [r0+24] ++%endif ++ HADDW m0, m2 ++ ++ lea r0, [r0+r1-2] ++ movzx r3d, word [r0] ++ movzx r4d, word [r0+r1] ++%rep 7 ++ lea r0, [r0+r1*2] ++ movzx r2d, word [r0] ++ add r3d, r2d ++ movzx r2d, word [r0+r1] ++ add r4d, r2d ++%endrep ++ lea r3d, [r3+r4+16] ++ ++ movd m1, r3d ++ paddw m0, m1 ++ psrlw m0, 5 ++ SPLATW m0, m0 ++ mov r3d, 8 ++.loop: ++ MOV16 r5+r1*0, m0, m0, m0, m0 ++ MOV16 r5+r1*1, m0, m0, m0, m0 ++ lea r5, [r5+r1*2] ++ dec r3d ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_DC mmxext ++INIT_XMM ++PRED16x16_DC sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_top_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED16x16_TOP_DC 1 ++cglobal pred16x16_top_dc_10_%1, 2,3 ++ sub r0, r1 ++ mova m0, [r0+0] ++ paddw m0, [r0+mmsize] ++%if mmsize==8 ++ paddw m0, [r0+16] ++ paddw m0, [r0+24] ++%endif ++ HADDW m0, m2 ++ ++ SPLATW m0, m0 ++ paddw m0, [pw_8] ++ psrlw m0, 4 ++ mov r2d, 8 ++.loop: ++ MOV16 r0+r1*1, m0, m0, m0, m0 ++ MOV16 r0+r1*2, m0, m0, m0, m0 ++ lea r0, [r0+r1*2] ++ dec r2d ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_TOP_DC mmxext ++INIT_XMM ++PRED16x16_TOP_DC sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_left_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED16x16_LEFT_DC 1 ++cglobal pred16x16_left_dc_10_%1, 2,6 ++ mov r5, r0 ++ ++ sub r0, 2 ++ movzx r3d, word [r0] ++ movzx r4d, word [r0+r1] ++%rep 7 ++ lea r0, [r0+r1*2] ++ movzx r2d, word [r0] ++ add r3d, r2d ++ movzx r2d, word [r0+r1] ++ add r4d, r2d ++%endrep ++ lea r3d, [r3+r4+8] ++ shr r3d, 4 ++ ++ movd m0, r3d ++ SPLATW m0, m0 ++ mov r3d, 8 ++.loop: ++ MOV16 r5+r1*0, m0, m0, m0, m0 ++ MOV16 r5+r1*1, m0, m0, m0, m0 ++ lea r5, [r5+r1*2] ++ dec r3d ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_LEFT_DC mmxext ++INIT_XMM ++PRED16x16_LEFT_DC sse2 ++ ++;----------------------------------------------------------------------------- ++; void pred16x16_128_dc(pixel *src, int stride) ++;----------------------------------------------------------------------------- ++%macro PRED16x16_128_DC 1 ++cglobal pred16x16_128_dc_10_%1, 2,3 ++ mova m0, [pw_512] ++ mov r2d, 8 ++.loop: ++ MOV16 r0+r1*0, m0, m0, m0, m0 ++ MOV16 r0+r1*1, m0, m0, m0, m0 ++ lea r0, [r0+r1*2] ++ dec r2d ++ jg .loop ++ REP_RET ++%endmacro ++ ++INIT_MMX ++PRED16x16_128_DC mmxext ++INIT_XMM ++PRED16x16_128_DC sse2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred.asm 2012-05-14 14:08:54.546344248 +0200 +@@ -19,11 +19,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION_RODATA + +@@ -836,7 +836,6 @@ + ;----------------------------------------------------------------------------- + ; void pred8x8_top_dc_mmxext(uint8_t *src, int stride) + ;----------------------------------------------------------------------------- +-%ifdef CONFIG_GPL + cglobal pred8x8_top_dc_mmxext, 2,5 + sub r0, r1 + movq mm0, [r0] +@@ -927,7 +926,6 @@ + movq [r4+r1*1], m1 + movq [r4+r1*2], m1 + RET +-%endif + + ;----------------------------------------------------------------------------- + ; void pred8x8_dc_rv40(uint8_t *src, int stride) +@@ -1083,7 +1081,6 @@ + ;----------------------------------------------------------------------------- + ; void pred8x8l_top_dc(uint8_t *src, int has_topleft, int has_topright, int stride) + ;----------------------------------------------------------------------------- +-%ifdef CONFIG_GPL + %macro PRED8x8L_TOP_DC 1 + cglobal pred8x8l_top_dc_%1, 4,4 + sub r0, r3 +@@ -2476,7 +2473,6 @@ + INIT_MMX + %define PALIGNR PALIGNR_SSSE3 + PRED8x8L_HORIZONTAL_DOWN ssse3 +-%endif + + ;----------------------------------------------------------------------------- + ; void pred4x4_dc_mmxext(uint8_t *src, const uint8_t *topright, int stride) +@@ -2608,7 +2604,6 @@ + ;----------------------------------------------------------------------------- + ; void pred4x4_down_left_mmxext(uint8_t *src, const uint8_t *topright, int stride) + ;----------------------------------------------------------------------------- +-%ifdef CONFIG_GPL + INIT_MMX + cglobal pred4x4_down_left_mmxext, 3,3 + sub r0, r2 +@@ -2616,12 +2611,11 @@ + punpckldq m1, [r1] + movq m2, m1 + movq m3, m1 +- movq m4, m1 + psllq m1, 8 + pxor m2, m1 + psrlq m2, 8 +- pxor m3, m2 +- PRED4x4_LOWPASS m0, m1, m3, m4, m5 ++ pxor m2, m3 ++ PRED4x4_LOWPASS m0, m1, m2, m3, m4 + lea r1, [r0+r2*2] + psrlq m0, 8 + movd [r0+r2*1], m0 +@@ -2786,4 +2780,3 @@ + psrlq m0, 8 + movh [r0+r2*1], m0 + RET +-%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred_init.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred_init.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_intrapred_init.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_intrapred_init.c 2012-05-14 14:08:54.554344410 +0200 +@@ -21,6 +21,78 @@ + #include "libavutil/cpu.h" + #include "libavcodec/h264pred.h" + ++#define PRED4x4(TYPE, DEPTH, OPT) \ ++void ff_pred4x4_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, const uint8_t *topright, int stride); ++ ++PRED4x4(dc, 10, mmxext) ++PRED4x4(down_left, 10, sse2) ++PRED4x4(down_left, 10, avx) ++PRED4x4(down_right, 10, sse2) ++PRED4x4(down_right, 10, ssse3) ++PRED4x4(down_right, 10, avx) ++PRED4x4(vertical_left, 10, sse2) ++PRED4x4(vertical_left, 10, avx) ++PRED4x4(vertical_right, 10, sse2) ++PRED4x4(vertical_right, 10, ssse3) ++PRED4x4(vertical_right, 10, avx) ++PRED4x4(horizontal_up, 10, mmxext) ++PRED4x4(horizontal_down, 10, sse2) ++PRED4x4(horizontal_down, 10, ssse3) ++PRED4x4(horizontal_down, 10, avx) ++ ++#define PRED8x8(TYPE, DEPTH, OPT) \ ++void ff_pred8x8_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int stride); ++ ++PRED8x8(dc, 10, mmxext) ++PRED8x8(dc, 10, sse2) ++PRED8x8(top_dc, 10, sse2) ++PRED8x8(plane, 10, sse2) ++PRED8x8(vertical, 10, sse2) ++PRED8x8(horizontal, 10, sse2) ++ ++#define PRED8x8L(TYPE, DEPTH, OPT)\ ++void ff_pred8x8l_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int has_topleft, int has_topright, int stride); ++ ++PRED8x8L(dc, 10, sse2) ++PRED8x8L(dc, 10, avx) ++PRED8x8L(128_dc, 10, mmxext) ++PRED8x8L(128_dc, 10, sse2) ++PRED8x8L(top_dc, 10, sse2) ++PRED8x8L(top_dc, 10, avx) ++PRED8x8L(vertical, 10, sse2) ++PRED8x8L(vertical, 10, avx) ++PRED8x8L(horizontal, 10, sse2) ++PRED8x8L(horizontal, 10, ssse3) ++PRED8x8L(horizontal, 10, avx) ++PRED8x8L(down_left, 10, sse2) ++PRED8x8L(down_left, 10, ssse3) ++PRED8x8L(down_left, 10, avx) ++PRED8x8L(down_right, 10, sse2) ++PRED8x8L(down_right, 10, ssse3) ++PRED8x8L(down_right, 10, avx) ++PRED8x8L(vertical_right, 10, sse2) ++PRED8x8L(vertical_right, 10, ssse3) ++PRED8x8L(vertical_right, 10, avx) ++PRED8x8L(horizontal_up, 10, sse2) ++PRED8x8L(horizontal_up, 10, ssse3) ++PRED8x8L(horizontal_up, 10, avx) ++ ++#define PRED16x16(TYPE, DEPTH, OPT)\ ++void ff_pred16x16_ ## TYPE ## _ ## DEPTH ## _ ## OPT (uint8_t *src, int stride); ++ ++PRED16x16(dc, 10, mmxext) ++PRED16x16(dc, 10, sse2) ++PRED16x16(top_dc, 10, mmxext) ++PRED16x16(top_dc, 10, sse2) ++PRED16x16(128_dc, 10, mmxext) ++PRED16x16(128_dc, 10, sse2) ++PRED16x16(left_dc, 10, mmxext) ++PRED16x16(left_dc, 10, sse2) ++PRED16x16(vertical, 10, mmxext) ++PRED16x16(vertical, 10, sse2) ++PRED16x16(horizontal, 10, mmxext) ++PRED16x16(horizontal, 10, sse2) ++ + void ff_pred16x16_vertical_mmx (uint8_t *src, int stride); + void ff_pred16x16_vertical_sse (uint8_t *src, int stride); + void ff_pred16x16_horizontal_mmx (uint8_t *src, int stride); +@@ -95,139 +167,223 @@ + void ff_pred4x4_tm_vp8_ssse3 (uint8_t *src, const uint8_t *topright, int stride); + void ff_pred4x4_vertical_vp8_mmxext(uint8_t *src, const uint8_t *topright, int stride); + +-void ff_h264_pred_init_x86(H264PredContext *h, int codec_id) ++void ff_h264_pred_init_x86(H264PredContext *h, int codec_id, const int bit_depth, const int chroma_format_idc) + { ++#if HAVE_YASM + int mm_flags = av_get_cpu_flags(); + +-#if HAVE_YASM +- if (mm_flags & AV_CPU_FLAG_MMX) { +- h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_mmx; +- h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmx; +- h->pred8x8 [VERT_PRED8x8] = ff_pred8x8_vertical_mmx; +- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx; +- if (codec_id == CODEC_ID_VP8) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_mmx; +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_mmx; +- h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmx; +- } else { +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx; +- if (codec_id == CODEC_ID_SVQ3) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_mmx; +- } else if (codec_id == CODEC_ID_RV40) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_mmx; ++ if (bit_depth == 8) { ++ if (mm_flags & AV_CPU_FLAG_MMX) { ++ h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_mmx; ++ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmx; ++ if (chroma_format_idc == 1) { ++ h->pred8x8 [VERT_PRED8x8 ] = ff_pred8x8_vertical_mmx; ++ h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmx; ++ } ++ if (codec_id == CODEC_ID_VP8) { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmx; ++ h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_mmx; ++ h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmx; + } else { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_mmx; ++ if (chroma_format_idc == 1) ++ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx; ++ if (codec_id == CODEC_ID_SVQ3) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_mmx; ++ } else if (codec_id == CODEC_ID_RV40) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_mmx; ++ } else { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_mmx; ++ } + } + } +- } + +- if (mm_flags & AV_CPU_FLAG_MMX2) { +- h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmxext; +- h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_mmxext; +- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext; +-#if CONFIG_GPL +- h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_mmxext; +- h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_mmxext; +- h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_mmxext; +- h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_mmxext; +- h->pred8x8l [DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_mmxext; +- h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_mmxext; +- h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_mmxext; +- h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_mmxext; +- h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_mmxext; +- h->pred4x4 [DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_mmxext; +- h->pred4x4 [VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_mmxext; +- h->pred4x4 [HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_mmxext; +-#endif +- h->pred4x4 [DC_PRED ] = ff_pred4x4_dc_mmxext; +-#if CONFIG_GPL +- if (codec_id == CODEC_ID_VP8 || codec_id == CODEC_ID_H264) +- h->pred4x4 [DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_mmxext; +- if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) +- h->pred4x4 [VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_mmxext; +- if (codec_id != CODEC_ID_RV40) { +- h->pred4x4 [HOR_UP_PRED ] = ff_pred4x4_horizontal_up_mmxext; +- } +- if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) { +- h->pred8x8 [TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_mmxext; +- h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_mmxext; +- } +-#endif +- if (codec_id == CODEC_ID_VP8) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_mmxext; +- h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_rv40_mmxext; +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_mmxext; +- h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmxext; +- h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_mmxext; +- } else { +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx2; +- if (codec_id == CODEC_ID_SVQ3) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_mmx2; +- } else if (codec_id == CODEC_ID_RV40) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_mmx2; ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_mmxext; ++ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_mmxext; ++ if (chroma_format_idc == 1) ++ h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_mmxext; ++ h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_mmxext; ++ h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_mmxext; ++ h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_mmxext; ++ h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_mmxext; ++ h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_mmxext; ++ h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_mmxext; ++ h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_mmxext; ++ h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_mmxext; ++ h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_mmxext; ++ h->pred4x4 [DIAG_DOWN_RIGHT_PRED ] = ff_pred4x4_down_right_mmxext; ++ h->pred4x4 [VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_mmxext; ++ h->pred4x4 [HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_mmxext; ++ h->pred4x4 [DC_PRED ] = ff_pred4x4_dc_mmxext; ++ if (codec_id == CODEC_ID_VP8 || codec_id == CODEC_ID_H264) { ++ h->pred4x4 [DIAG_DOWN_LEFT_PRED] = ff_pred4x4_down_left_mmxext; ++ } ++ if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) { ++ h->pred4x4 [VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_mmxext; ++ } ++ if (codec_id != CODEC_ID_RV40) { ++ h->pred4x4 [HOR_UP_PRED ] = ff_pred4x4_horizontal_up_mmxext; ++ } ++ if (codec_id == CODEC_ID_SVQ3 || codec_id == CODEC_ID_H264) { ++ if (chroma_format_idc == 1) { ++ h->pred8x8[TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_mmxext; ++ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_mmxext; ++ } ++ } ++ if (codec_id == CODEC_ID_VP8) { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_mmxext; ++ h->pred8x8 [DC_PRED8x8 ] = ff_pred8x8_dc_rv40_mmxext; ++ h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_mmxext; ++ h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_mmxext; ++ h->pred4x4 [VERT_PRED ] = ff_pred4x4_vertical_vp8_mmxext; + } else { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_mmx2; ++ if (chroma_format_idc == 1) ++ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_mmx2; ++ if (codec_id == CODEC_ID_SVQ3) { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_svq3_mmx2; ++ } else if (codec_id == CODEC_ID_RV40) { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_rv40_mmx2; ++ } else { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_plane_h264_mmx2; ++ } + } + } +- } + +- if (mm_flags & AV_CPU_FLAG_SSE) { +- h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_sse; +- } ++ if (mm_flags & AV_CPU_FLAG_SSE) { ++ h->pred16x16[VERT_PRED8x8] = ff_pred16x16_vertical_sse; ++ } + +- if (mm_flags & AV_CPU_FLAG_SSE2) { +- h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_sse2; +-#if CONFIG_GPL +- h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_sse2; +- h->pred8x8l [DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_sse2; +- h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_sse2; +- h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_sse2; +- h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_sse2; +-#endif +- if (codec_id == CODEC_ID_VP8) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_tm_vp8_sse2; +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_sse2; +- } else { +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_sse2; +- if (codec_id == CODEC_ID_SVQ3) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_sse2; +- } else if (codec_id == CODEC_ID_RV40) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_sse2; ++ if (mm_flags & AV_CPU_FLAG_SSE2) { ++ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_sse2; ++ h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_sse2; ++ h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_sse2; ++ h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_sse2; ++ h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_sse2; ++ h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_sse2; ++ if (codec_id == CODEC_ID_VP8) { ++ h->pred16x16[PLANE_PRED8x8 ] = ff_pred16x16_tm_vp8_sse2; ++ h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_sse2; + } else { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_sse2; ++ if (chroma_format_idc == 1) ++ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_sse2; ++ if (codec_id == CODEC_ID_SVQ3) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_sse2; ++ } else if (codec_id == CODEC_ID_RV40) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_sse2; ++ } else { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_sse2; ++ } + } + } +- } + +- if (mm_flags & AV_CPU_FLAG_SSSE3) { +- h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_ssse3; +- h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_ssse3; +- h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3; +-#if CONFIG_GPL +- h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_ssse3; +- h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_ssse3; +- h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_ssse3; +- h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_ssse3; +- h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_ssse3; +- h->pred8x8l [DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_ssse3; +- h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_ssse3; +- h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_ssse3; +- h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_ssse3; +- h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_ssse3; +-#endif +- if (codec_id == CODEC_ID_VP8) { +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_tm_vp8_ssse3; +- h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_ssse3; +- } else { +- h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_ssse3; +- if (codec_id == CODEC_ID_SVQ3) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_ssse3; +- } else if (codec_id == CODEC_ID_RV40) { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_ssse3; ++ if (mm_flags & AV_CPU_FLAG_SSSE3) { ++ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_ssse3; ++ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_ssse3; ++ if (chroma_format_idc == 1) ++ h->pred8x8 [HOR_PRED8x8 ] = ff_pred8x8_horizontal_ssse3; ++ h->pred8x8l [TOP_DC_PRED ] = ff_pred8x8l_top_dc_ssse3; ++ h->pred8x8l [DC_PRED ] = ff_pred8x8l_dc_ssse3; ++ h->pred8x8l [HOR_PRED ] = ff_pred8x8l_horizontal_ssse3; ++ h->pred8x8l [VERT_PRED ] = ff_pred8x8l_vertical_ssse3; ++ h->pred8x8l [DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_ssse3; ++ h->pred8x8l [DIAG_DOWN_RIGHT_PRED ] = ff_pred8x8l_down_right_ssse3; ++ h->pred8x8l [VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_ssse3; ++ h->pred8x8l [VERT_LEFT_PRED ] = ff_pred8x8l_vertical_left_ssse3; ++ h->pred8x8l [HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_ssse3; ++ h->pred8x8l [HOR_DOWN_PRED ] = ff_pred8x8l_horizontal_down_ssse3; ++ if (codec_id == CODEC_ID_VP8) { ++ h->pred8x8 [PLANE_PRED8x8 ] = ff_pred8x8_tm_vp8_ssse3; ++ h->pred4x4 [TM_VP8_PRED ] = ff_pred4x4_tm_vp8_ssse3; + } else { +- h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_ssse3; ++ if (chroma_format_idc == 1) ++ h->pred8x8 [PLANE_PRED8x8] = ff_pred8x8_plane_ssse3; ++ if (codec_id == CODEC_ID_SVQ3) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_svq3_ssse3; ++ } else if (codec_id == CODEC_ID_RV40) { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_rv40_ssse3; ++ } else { ++ h->pred16x16[PLANE_PRED8x8] = ff_pred16x16_plane_h264_ssse3; ++ } ++ } ++ } ++ } else if (bit_depth == 10) { ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ h->pred4x4[DC_PRED ] = ff_pred4x4_dc_10_mmxext; ++ h->pred4x4[HOR_UP_PRED ] = ff_pred4x4_horizontal_up_10_mmxext; ++ ++ if (chroma_format_idc == 1) ++ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_10_mmxext; ++ ++ h->pred8x8l[DC_128_PRED ] = ff_pred8x8l_128_dc_10_mmxext; ++ ++ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_10_mmxext; ++ h->pred16x16[TOP_DC_PRED8x8 ] = ff_pred16x16_top_dc_10_mmxext; ++ h->pred16x16[DC_128_PRED8x8 ] = ff_pred16x16_128_dc_10_mmxext; ++ h->pred16x16[LEFT_DC_PRED8x8 ] = ff_pred16x16_left_dc_10_mmxext; ++ h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_10_mmxext; ++ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_10_mmxext; ++ } ++ if (mm_flags & AV_CPU_FLAG_SSE2) { ++ h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_sse2; ++ h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_sse2; ++ h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_sse2; ++ h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_sse2; ++ h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_sse2; ++ ++ if (chroma_format_idc == 1) { ++ h->pred8x8[DC_PRED8x8 ] = ff_pred8x8_dc_10_sse2; ++ h->pred8x8[TOP_DC_PRED8x8 ] = ff_pred8x8_top_dc_10_sse2; ++ h->pred8x8[PLANE_PRED8x8 ] = ff_pred8x8_plane_10_sse2; ++ h->pred8x8[VERT_PRED8x8 ] = ff_pred8x8_vertical_10_sse2; ++ h->pred8x8[HOR_PRED8x8 ] = ff_pred8x8_horizontal_10_sse2; + } ++ ++ h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_sse2; ++ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_sse2; ++ h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_sse2; ++ h->pred8x8l[DC_128_PRED ] = ff_pred8x8l_128_dc_10_sse2; ++ h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_sse2; ++ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_sse2; ++ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_sse2; ++ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_sse2; ++ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_sse2; ++ ++ h->pred16x16[DC_PRED8x8 ] = ff_pred16x16_dc_10_sse2; ++ h->pred16x16[TOP_DC_PRED8x8 ] = ff_pred16x16_top_dc_10_sse2; ++ h->pred16x16[DC_128_PRED8x8 ] = ff_pred16x16_128_dc_10_sse2; ++ h->pred16x16[LEFT_DC_PRED8x8 ] = ff_pred16x16_left_dc_10_sse2; ++ h->pred16x16[VERT_PRED8x8 ] = ff_pred16x16_vertical_10_sse2; ++ h->pred16x16[HOR_PRED8x8 ] = ff_pred16x16_horizontal_10_sse2; ++ } ++ if (mm_flags & AV_CPU_FLAG_SSSE3) { ++ h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_ssse3; ++ h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_ssse3; ++ h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_ssse3; ++ ++ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_ssse3; ++ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_ssse3; ++ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_ssse3; ++ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_ssse3; ++ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_ssse3; ++ } ++#if HAVE_AVX ++ if (mm_flags & AV_CPU_FLAG_AVX) { ++ h->pred4x4[DIAG_DOWN_LEFT_PRED ] = ff_pred4x4_down_left_10_avx; ++ h->pred4x4[DIAG_DOWN_RIGHT_PRED] = ff_pred4x4_down_right_10_avx; ++ h->pred4x4[VERT_LEFT_PRED ] = ff_pred4x4_vertical_left_10_avx; ++ h->pred4x4[VERT_RIGHT_PRED ] = ff_pred4x4_vertical_right_10_avx; ++ h->pred4x4[HOR_DOWN_PRED ] = ff_pred4x4_horizontal_down_10_avx; ++ ++ h->pred8x8l[VERT_PRED ] = ff_pred8x8l_vertical_10_avx; ++ h->pred8x8l[HOR_PRED ] = ff_pred8x8l_horizontal_10_avx; ++ h->pred8x8l[DC_PRED ] = ff_pred8x8l_dc_10_avx; ++ h->pred8x8l[TOP_DC_PRED ] = ff_pred8x8l_top_dc_10_avx; ++ h->pred8x8l[DIAG_DOWN_RIGHT_PRED] = ff_pred8x8l_down_right_10_avx; ++ h->pred8x8l[DIAG_DOWN_LEFT_PRED ] = ff_pred8x8l_down_left_10_avx; ++ h->pred8x8l[VERT_RIGHT_PRED ] = ff_pred8x8l_vertical_right_10_avx; ++ h->pred8x8l[HOR_UP_PRED ] = ff_pred8x8l_horizontal_up_10_avx; + } ++#endif /* HAVE_AVX */ + } +-#endif ++#endif /* HAVE_YASM */ + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_qpel_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_qpel_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_qpel_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_qpel_10bit.asm 2012-05-14 14:08:54.556344450 +0200 +@@ -0,0 +1,891 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 qpel code ++;***************************************************************************** ++;* Copyright (C) 2011 x264 project ++;* ++;* Authors: Daniel Kang ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA 32 ++ ++cextern pw_16 ++cextern pw_1 ++cextern pb_0 ++ ++pw_pixel_max: times 8 dw ((1 << 10)-1) ++ ++pad10: times 8 dw 10*1023 ++pad20: times 8 dw 20*1023 ++pad30: times 8 dw 30*1023 ++depad: times 4 dd 32*20*1023 + 512 ++depad2: times 8 dw 20*1023 + 16*1022 + 16 ++unpad: times 8 dw 16*1022/32 ; needs to be mod 16 ++ ++tap1: times 4 dw 1, -5 ++tap2: times 4 dw 20, 20 ++tap3: times 4 dw -5, 1 ++pd_0f: times 4 dd 0xffff ++ ++SECTION .text ++ ++ ++%macro AVG_MOV 2 ++ pavgw %2, %1 ++ mova %1, %2 ++%endmacro ++ ++%macro ADDW 3 ++%if mmsize == 8 ++ paddw %1, %2 ++%else ++ movu %3, %2 ++ paddw %1, %3 ++%endif ++%endmacro ++ ++%macro FILT_H 4 ++ paddw %1, %4 ++ psubw %1, %2 ; a-b ++ psraw %1, 2 ; (a-b)/4 ++ psubw %1, %2 ; (a-b)/4-b ++ paddw %1, %3 ; (a-b)/4-b+c ++ psraw %1, 2 ; ((a-b)/4-b+c)/4 ++ paddw %1, %3 ; ((a-b)/4-b+c)/4+c = (a-5*b+20*c)/16 ++%endmacro ++ ++%macro PRELOAD_V 0 ++ lea r3, [r2*3] ++ sub r1, r3 ++ movu m0, [r1+r2] ++ movu m1, [r1+r2*2] ++ add r1, r3 ++ movu m2, [r1] ++ movu m3, [r1+r2] ++ movu m4, [r1+r2*2] ++ add r1, r3 ++%endmacro ++ ++%macro FILT_V 8 ++ movu %6, [r1] ++ paddw %1, %6 ++ mova %7, %2 ++ paddw %7, %5 ++ mova %8, %3 ++ paddw %8, %4 ++ FILT_H %1, %7, %8, [pw_16] ++ psraw %1, 1 ++ CLIPW %1, [pb_0], [pw_pixel_max] ++%endmacro ++ ++%macro MC 1 ++%define OP_MOV mova ++INIT_MMX ++%1 mmxext, put, 4 ++INIT_XMM ++%1 sse2 , put, 8 ++ ++%define OP_MOV AVG_MOV ++INIT_MMX ++%1 mmxext, avg, 4 ++INIT_XMM ++%1 sse2 , avg, 8 ++%endmacro ++ ++%macro MCAxA 8 ++%ifdef ARCH_X86_64 ++%ifnidn %1,mmxext ++MCAxA_OP %1,%2,%3,%4,%5,%6,%7,%8 ++%endif ++%else ++MCAxA_OP %1,%2,%3,%4,%5,%6,%7,%8 ++%endif ++%endmacro ++ ++%macro MCAxA_OP 8 ++cglobal %2_h264_qpel%5_%3_10_%1, %6,%7,%8 ++%ifdef ARCH_X86_32 ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ mov r0, r0m ++ mov r1, r1m ++ add r0, %4*2 ++ add r1, %4*2 ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ mov r0, r0m ++ mov r1, r1m ++ lea r0, [r0+r2*%4] ++ lea r1, [r1+r2*%4] ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ mov r0, r0m ++ mov r1, r1m ++ lea r0, [r0+r2*%4+%4*2] ++ lea r1, [r1+r2*%4+%4*2] ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ RET ++%else ; ARCH_X86_64 ++ mov r10, r0 ++ mov r11, r1 ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ lea r0, [r10+%4*2] ++ lea r1, [r11+%4*2] ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ lea r0, [r10+r2*%4] ++ lea r1, [r11+r2*%4] ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ lea r0, [r10+r2*%4+%4*2] ++ lea r1, [r11+r2*%4+%4*2] ++%ifndef UNIX64 ; fall through to function ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ RET ++%endif ++%endif ++%endmacro ++ ++;cpu, put/avg, mc, 4/8, ... ++%macro cglobal_mc 7 ++%assign i %4*2 ++MCAxA %1, %2, %3, %4, i, %5,%6,%7 ++ ++cglobal %2_h264_qpel%4_%3_10_%1, %5,%6,%7 ++%ifndef UNIX64 ; no prologue or epilogue for UNIX64 ++ call stub_%2_h264_qpel%4_%3_10_%1 ++ RET ++%endif ++ ++stub_%2_h264_qpel%4_%3_10_%1: ++%endmacro ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc00(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro COPY4 0 ++ movu m0, [r1 ] ++ OP_MOV [r0 ], m0 ++ movu m0, [r1+r2 ] ++ OP_MOV [r0+r2 ], m0 ++ movu m0, [r1+r2*2] ++ OP_MOV [r0+r2*2], m0 ++ movu m0, [r1+r3 ] ++ OP_MOV [r0+r3 ], m0 ++%endmacro ++ ++%macro MC00 1 ++INIT_MMX ++cglobal_mc mmxext, %1, mc00, 4, 3,4,0 ++ lea r3, [r2*3] ++ COPY4 ++ ret ++ ++INIT_XMM ++cglobal %1_h264_qpel8_mc00_10_sse2, 3,4 ++ lea r3, [r2*3] ++ COPY4 ++ lea r0, [r0+r2*4] ++ lea r1, [r1+r2*4] ++ COPY4 ++ RET ++ ++cglobal %1_h264_qpel16_mc00_10_sse2, 3,4 ++ mov r3d, 8 ++.loop: ++ movu m0, [r1 ] ++ movu m1, [r1 +16] ++ OP_MOV [r0 ], m0 ++ OP_MOV [r0 +16], m1 ++ movu m0, [r1+r2 ] ++ movu m1, [r1+r2+16] ++ OP_MOV [r0+r2 ], m0 ++ OP_MOV [r0+r2+16], m1 ++ lea r0, [r0+r2*2] ++ lea r1, [r1+r2*2] ++ dec r3d ++ jg .loop ++ REP_RET ++%endmacro ++ ++%define OP_MOV mova ++MC00 put ++ ++%define OP_MOV AVG_MOV ++MC00 avg ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc20(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC_CACHE 1 ++%define OP_MOV mova ++%define PALIGNR PALIGNR_MMX ++INIT_MMX ++%1 mmxext , put, 4 ++INIT_XMM ++%1 sse2_cache64 , put, 8 ++%define PALIGNR PALIGNR_SSSE3 ++%1 ssse3_cache64, put, 8 ++%1 sse2 , put, 8, 0 ++ ++%define OP_MOV AVG_MOV ++%define PALIGNR PALIGNR_MMX ++INIT_MMX ++%1 mmxext , avg, 4 ++INIT_XMM ++%1 sse2_cache64 , avg, 8 ++%define PALIGNR PALIGNR_SSSE3 ++%1 ssse3_cache64, avg, 8 ++%1 sse2 , avg, 8, 0 ++%endmacro ++ ++%macro MC20 3-4 ++cglobal_mc %1, %2, mc20, %3, 3,4,9 ++ mov r3d, %3 ++ mova m1, [pw_pixel_max] ++%if num_mmregs > 8 ++ mova m8, [pw_16] ++ %define p16 m8 ++%else ++ %define p16 [pw_16] ++%endif ++.nextrow ++%if %0 == 4 ++ movu m2, [r1-4] ++ movu m3, [r1-2] ++ movu m4, [r1+0] ++ ADDW m2, [r1+6], m5 ++ ADDW m3, [r1+4], m5 ++ ADDW m4, [r1+2], m5 ++%else ; movu is slow on these processors ++%if mmsize==16 ++ movu m2, [r1-4] ++ movu m0, [r1+6] ++ mova m6, m0 ++ psrldq m0, 6 ++ ++ paddw m6, m2 ++ PALIGNR m3, m0, m2, 2, m5 ++ PALIGNR m7, m0, m2, 8, m5 ++ paddw m3, m7 ++ PALIGNR m4, m0, m2, 4, m5 ++ PALIGNR m7, m0, m2, 6, m5 ++ paddw m4, m7 ++ SWAP 2, 6 ++%else ++ movu m2, [r1-4] ++ movu m6, [r1+4] ++ PALIGNR m3, m6, m2, 2, m5 ++ paddw m3, m6 ++ PALIGNR m4, m6, m2, 4, m5 ++ PALIGNR m7, m6, m2, 6, m5 ++ paddw m4, m7 ++ paddw m2, [r1+6] ++%endif ++%endif ++ ++ FILT_H m2, m3, m4, p16 ++ psraw m2, 1 ++ pxor m0, m0 ++ CLIPW m2, m0, m1 ++ OP_MOV [r0], m2 ++ add r0, r2 ++ add r1, r2 ++ dec r3d ++ jg .nextrow ++ rep ret ++%endmacro ++ ++MC_CACHE MC20 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc30(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC30 3-4 ++cglobal_mc %1, %2, mc30, %3, 3,5,9 ++ lea r4, [r1+2] ++ jmp stub_%2_h264_qpel%3_mc10_10_%1.body ++%endmacro ++ ++MC_CACHE MC30 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc10(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC10 3-4 ++cglobal_mc %1, %2, mc10, %3, 3,5,9 ++ mov r4, r1 ++.body ++ mov r3d, %3 ++ mova m1, [pw_pixel_max] ++%if num_mmregs > 8 ++ mova m8, [pw_16] ++ %define p16 m8 ++%else ++ %define p16 [pw_16] ++%endif ++.nextrow ++%if %0 == 4 ++ movu m2, [r1-4] ++ movu m3, [r1-2] ++ movu m4, [r1+0] ++ ADDW m2, [r1+6], m5 ++ ADDW m3, [r1+4], m5 ++ ADDW m4, [r1+2], m5 ++%else ; movu is slow on these processors ++%if mmsize==16 ++ movu m2, [r1-4] ++ movu m0, [r1+6] ++ mova m6, m0 ++ psrldq m0, 6 ++ ++ paddw m6, m2 ++ PALIGNR m3, m0, m2, 2, m5 ++ PALIGNR m7, m0, m2, 8, m5 ++ paddw m3, m7 ++ PALIGNR m4, m0, m2, 4, m5 ++ PALIGNR m7, m0, m2, 6, m5 ++ paddw m4, m7 ++ SWAP 2, 6 ++%else ++ movu m2, [r1-4] ++ movu m6, [r1+4] ++ PALIGNR m3, m6, m2, 2, m5 ++ paddw m3, m6 ++ PALIGNR m4, m6, m2, 4, m5 ++ PALIGNR m7, m6, m2, 6, m5 ++ paddw m4, m7 ++ paddw m2, [r1+6] ++%endif ++%endif ++ ++ FILT_H m2, m3, m4, p16 ++ psraw m2, 1 ++ pxor m0, m0 ++ CLIPW m2, m0, m1 ++ movu m3, [r4] ++ pavgw m2, m3 ++ OP_MOV [r0], m2 ++ add r0, r2 ++ add r1, r2 ++ add r4, r2 ++ dec r3d ++ jg .nextrow ++ rep ret ++%endmacro ++ ++MC_CACHE MC10 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc02(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro V_FILT 11 ++v_filt%9_%10_10_%11: ++ add r4, r2 ++.no_addr4: ++ FILT_V m0, m1, m2, m3, m4, m5, m6, m7 ++ add r1, r2 ++ add r0, r2 ++ ret ++%endmacro ++ ++INIT_MMX ++RESET_MM_PERMUTATION ++%assign i 0 ++%rep 4 ++V_FILT m0, m1, m2, m3, m4, m5, m6, m7, 4, i, mmxext ++SWAP 0,1,2,3,4,5 ++%assign i i+1 ++%endrep ++ ++INIT_XMM ++RESET_MM_PERMUTATION ++%assign i 0 ++%rep 6 ++V_FILT m0, m1, m2, m3, m4, m5, m6, m7, 8, i, sse2 ++SWAP 0,1,2,3,4,5 ++%assign i i+1 ++%endrep ++ ++%macro MC02 3 ++cglobal_mc %1, %2, mc02, %3, 3,4,8 ++ PRELOAD_V ++ ++ sub r0, r2 ++%assign j 0 ++%rep %3 ++ %assign i (j % 6) ++ call v_filt%3_ %+ i %+ _10_%1.no_addr4 ++ OP_MOV [r0], m0 ++ SWAP 0,1,2,3,4,5 ++ %assign j j+1 ++%endrep ++ ret ++%endmacro ++ ++MC MC02 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc01(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC01 3 ++cglobal_mc %1, %2, mc01, %3, 3,5,8 ++ mov r4, r1 ++.body ++ PRELOAD_V ++ ++ sub r4, r2 ++ sub r0, r2 ++%assign j 0 ++%rep %3 ++ %assign i (j % 6) ++ call v_filt%3_ %+ i %+ _10_%1 ++ movu m7, [r4] ++ pavgw m0, m7 ++ OP_MOV [r0], m0 ++ SWAP 0,1,2,3,4,5 ++ %assign j j+1 ++%endrep ++ ret ++%endmacro ++ ++MC MC01 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc03(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC03 3 ++cglobal_mc %1, %2, mc03, %3, 3,5,8 ++ lea r4, [r1+r2] ++ jmp stub_%2_h264_qpel%3_mc01_10_%1.body ++%endmacro ++ ++MC MC03 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc11(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro H_FILT_AVG 3-4 ++h_filt%2_%3_10_%1: ++;FILT_H with fewer registers and averaged with the FILT_V result ++;m6,m7 are tmp registers, m0 is the FILT_V result, the rest are to be used next in the next iteration ++;unfortunately I need three registers, so m5 will have to be re-read from memory ++ movu m5, [r4-4] ++ ADDW m5, [r4+6], m7 ++ movu m6, [r4-2] ++ ADDW m6, [r4+4], m7 ++ paddw m5, [pw_16] ++ psubw m5, m6 ; a-b ++ psraw m5, 2 ; (a-b)/4 ++ psubw m5, m6 ; (a-b)/4-b ++ movu m6, [r4+0] ++ ADDW m6, [r4+2], m7 ++ paddw m5, m6 ; (a-b)/4-b+c ++ psraw m5, 2 ; ((a-b)/4-b+c)/4 ++ paddw m5, m6 ; ((a-b)/4-b+c)/4+c = (a-5*b+20*c)/16 ++ psraw m5, 1 ++ CLIPW m5, [pb_0], [pw_pixel_max] ++;avg FILT_V, FILT_H ++ pavgw m0, m5 ++%if %0!=4 ++ movu m5, [r1+r5] ++%endif ++ ret ++%endmacro ++ ++INIT_MMX ++RESET_MM_PERMUTATION ++%assign i 0 ++%rep 3 ++H_FILT_AVG mmxext, 4, i ++SWAP 0,1,2,3,4,5 ++%assign i i+1 ++%endrep ++H_FILT_AVG mmxext, 4, i, 0 ++ ++INIT_XMM ++RESET_MM_PERMUTATION ++%assign i 0 ++%rep 6 ++%if i==1 ++H_FILT_AVG sse2, 8, i, 0 ++%else ++H_FILT_AVG sse2, 8, i ++%endif ++SWAP 0,1,2,3,4,5 ++%assign i i+1 ++%endrep ++ ++%macro MC11 3 ++; this REALLY needs x86_64 ++cglobal_mc %1, %2, mc11, %3, 3,6,8 ++ mov r4, r1 ++.body ++ PRELOAD_V ++ ++ sub r0, r2 ++ sub r4, r2 ++ mov r5, r2 ++ neg r5 ++%assign j 0 ++%rep %3 ++ %assign i (j % 6) ++ call v_filt%3_ %+ i %+ _10_%1 ++ call h_filt%3_ %+ i %+ _10_%1 ++%if %3==8 && i==1 ++ movu m5, [r1+r5] ++%endif ++ OP_MOV [r0], m0 ++ SWAP 0,1,2,3,4,5 ++ %assign j j+1 ++%endrep ++ ret ++%endmacro ++ ++MC MC11 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc31(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC31 3 ++cglobal_mc %1, %2, mc31, %3, 3,6,8 ++ mov r4, r1 ++ add r1, 2 ++ jmp stub_%2_h264_qpel%3_mc11_10_%1.body ++%endmacro ++ ++MC MC31 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc13(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC13 3 ++cglobal_mc %1, %2, mc13, %3, 3,7,12 ++ lea r4, [r1+r2] ++ jmp stub_%2_h264_qpel%3_mc11_10_%1.body ++%endmacro ++ ++MC MC13 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc33(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC33 3 ++cglobal_mc %1, %2, mc33, %3, 3,6,8 ++ lea r4, [r1+r2] ++ add r1, 2 ++ jmp stub_%2_h264_qpel%3_mc11_10_%1.body ++%endmacro ++ ++MC MC33 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc22(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro FILT_H2 3 ++ psubw %1, %2 ; a-b ++ psubw %2, %3 ; b-c ++ psllw %2, 2 ++ psubw %1, %2 ; a-5*b+4*c ++ psllw %3, 4 ++ paddw %1, %3 ; a-5*b+20*c ++%endmacro ++ ++%macro FILT_VNRD 8 ++ movu %6, [r1] ++ paddw %1, %6 ++ mova %7, %2 ++ paddw %7, %5 ++ mova %8, %3 ++ paddw %8, %4 ++ FILT_H2 %1, %7, %8 ++%endmacro ++ ++%macro HV 2 ++%ifidn %1,sse2 ++%define PAD 12 ++%define COUNT 2 ++%else ++%define PAD 4 ++%define COUNT 3 ++%endif ++put_hv%2_10_%1: ++ neg r2 ; This actually saves instructions ++ lea r1, [r1+r2*2-mmsize+PAD] ++ lea r4, [rsp+PAD+gprsize] ++ mov r3d, COUNT ++.v_loop: ++ movu m0, [r1] ++ sub r1, r2 ++ movu m1, [r1] ++ sub r1, r2 ++ movu m2, [r1] ++ sub r1, r2 ++ movu m3, [r1] ++ sub r1, r2 ++ movu m4, [r1] ++ sub r1, r2 ++%assign i 0 ++%rep %2-1 ++ FILT_VNRD m0, m1, m2, m3, m4, m5, m6, m7 ++ psubw m0, [pad20] ++ movu [r4+i*mmsize*3], m0 ++ sub r1, r2 ++ SWAP 0,1,2,3,4,5 ++%assign i i+1 ++%endrep ++ FILT_VNRD m0, m1, m2, m3, m4, m5, m6, m7 ++ psubw m0, [pad20] ++ movu [r4+i*mmsize*3], m0 ++ add r4, mmsize ++ lea r1, [r1+r2*8+mmsize] ++%if %2==8 ++ lea r1, [r1+r2*4] ++%endif ++ dec r3d ++ jg .v_loop ++ neg r2 ++ ret ++%endmacro ++ ++INIT_MMX ++HV mmxext, 4 ++INIT_XMM ++HV sse2 , 8 ++ ++%macro H_LOOP 2 ++%if num_mmregs > 8 ++ %define s1 m8 ++ %define s2 m9 ++ %define s3 m10 ++ %define d1 m11 ++%else ++ %define s1 [tap1] ++ %define s2 [tap2] ++ %define s3 [tap3] ++ %define d1 [depad] ++%endif ++h%2_loop_op_%1: ++ movu m1, [r1+mmsize-4] ++ movu m2, [r1+mmsize-2] ++ mova m3, [r1+mmsize+0] ++ movu m4, [r1+mmsize+2] ++ movu m5, [r1+mmsize+4] ++ movu m6, [r1+mmsize+6] ++%if num_mmregs > 8 ++ pmaddwd m1, s1 ++ pmaddwd m2, s1 ++ pmaddwd m3, s2 ++ pmaddwd m4, s2 ++ pmaddwd m5, s3 ++ pmaddwd m6, s3 ++ paddd m1, d1 ++ paddd m2, d1 ++%else ++ mova m0, s1 ++ pmaddwd m1, m0 ++ pmaddwd m2, m0 ++ mova m0, s2 ++ pmaddwd m3, m0 ++ pmaddwd m4, m0 ++ mova m0, s3 ++ pmaddwd m5, m0 ++ pmaddwd m6, m0 ++ mova m0, d1 ++ paddd m1, m0 ++ paddd m2, m0 ++%endif ++ paddd m3, m5 ++ paddd m4, m6 ++ paddd m1, m3 ++ paddd m2, m4 ++ psrad m1, 10 ++ psrad m2, 10 ++ pslld m2, 16 ++ pand m1, [pd_0f] ++ por m1, m2 ++%if num_mmregs <= 8 ++ pxor m0, m0 ++%endif ++ CLIPW m1, m0, m7 ++ add r1, mmsize*3 ++ ret ++%endmacro ++ ++INIT_MMX ++H_LOOP mmxext, 4 ++INIT_XMM ++H_LOOP sse2 , 8 ++ ++%macro MC22 3 ++cglobal_mc %1, %2, mc22, %3, 3,7,12 ++%define PAD mmsize*8*4*2 ; SIZE*16*4*sizeof(pixel) ++ mov r6, rsp ; backup stack pointer ++ and rsp, ~(mmsize-1) ; align stack ++ sub rsp, PAD ++ ++ call put_hv%3_10_%1 ++ ++ mov r3d, %3 ++ mova m7, [pw_pixel_max] ++%if num_mmregs > 8 ++ pxor m0, m0 ++ mova m8, [tap1] ++ mova m9, [tap2] ++ mova m10, [tap3] ++ mova m11, [depad] ++%endif ++ mov r1, rsp ++.h_loop: ++ call h%3_loop_op_%1 ++ ++ OP_MOV [r0], m1 ++ add r0, r2 ++ dec r3d ++ jg .h_loop ++ ++ mov rsp, r6 ; restore stack pointer ++ ret ++%endmacro ++ ++MC MC22 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc12(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC12 3 ++cglobal_mc %1, %2, mc12, %3, 3,7,12 ++%define PAD mmsize*8*4*2 ; SIZE*16*4*sizeof(pixel) ++ mov r6, rsp ; backup stack pointer ++ and rsp, ~(mmsize-1) ; align stack ++ sub rsp, PAD ++ ++ call put_hv%3_10_%1 ++ ++ xor r4d, r4d ++.body ++ mov r3d, %3 ++ pxor m0, m0 ++ mova m7, [pw_pixel_max] ++%if num_mmregs > 8 ++ mova m8, [tap1] ++ mova m9, [tap2] ++ mova m10, [tap3] ++ mova m11, [depad] ++%endif ++ mov r1, rsp ++.h_loop: ++ call h%3_loop_op_%1 ++ ++ movu m3, [r1+r4-2*mmsize] ; movu needed for mc32, etc ++ paddw m3, [depad2] ++ psrlw m3, 5 ++ psubw m3, [unpad] ++ CLIPW m3, m0, m7 ++ pavgw m1, m3 ++ ++ OP_MOV [r0], m1 ++ add r0, r2 ++ dec r3d ++ jg .h_loop ++ ++ mov rsp, r6 ; restore stack pointer ++ ret ++%endmacro ++ ++MC MC12 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc32(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC32 3 ++cglobal_mc %1, %2, mc32, %3, 3,7,12 ++%define PAD mmsize*8*3*2 ; SIZE*16*4*sizeof(pixel) ++ mov r6, rsp ; backup stack pointer ++ and rsp, ~(mmsize-1) ; align stack ++ sub rsp, PAD ++ ++ call put_hv%3_10_%1 ++ ++ mov r4d, 2 ; sizeof(pixel) ++ jmp stub_%2_h264_qpel%3_mc12_10_%1.body ++%endmacro ++ ++MC MC32 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc21(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro H_NRD 2 ++put_h%2_10_%1: ++ add rsp, gprsize ++ mov r3d, %2 ++ xor r4d, r4d ++ mova m6, [pad20] ++.nextrow ++ movu m2, [r5-4] ++ movu m3, [r5-2] ++ movu m4, [r5+0] ++ ADDW m2, [r5+6], m5 ++ ADDW m3, [r5+4], m5 ++ ADDW m4, [r5+2], m5 ++ ++ FILT_H2 m2, m3, m4 ++ psubw m2, m6 ++ mova [rsp+r4], m2 ++ add r4d, mmsize*3 ++ add r5, r2 ++ dec r3d ++ jg .nextrow ++ sub rsp, gprsize ++ ret ++%endmacro ++ ++INIT_MMX ++H_NRD mmxext, 4 ++INIT_XMM ++H_NRD sse2 , 8 ++ ++%macro MC21 3 ++cglobal_mc %1, %2, mc21, %3, 3,7,12 ++ mov r5, r1 ++.body ++%define PAD mmsize*8*3*2 ; SIZE*16*4*sizeof(pixel) ++ mov r6, rsp ; backup stack pointer ++ and rsp, ~(mmsize-1) ; align stack ++ ++ sub rsp, PAD ++ call put_h%3_10_%1 ++ ++ sub rsp, PAD ++ call put_hv%3_10_%1 ++ ++ mov r4d, PAD-mmsize ; H buffer ++ jmp stub_%2_h264_qpel%3_mc12_10_%1.body ++%endmacro ++ ++MC MC21 ++ ++;----------------------------------------------------------------------------- ++; void h264_qpel_mc23(uint8_t *dst, uint8_t *src, int stride) ++;----------------------------------------------------------------------------- ++%macro MC23 3 ++cglobal_mc %1, %2, mc23, %3, 3,7,12 ++ lea r5, [r1+r2] ++ jmp stub_%2_h264_qpel%3_mc21_10_%1.body ++%endmacro ++ ++MC MC23 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c 2012-05-14 14:08:54.558344490 +0200 +@@ -1,5 +1,6 @@ + /* + * Copyright (c) 2004-2005 Michael Niedermayer, Loren Merritt ++ * Copyright (c) 2011 Daniel Kang + * + * This file is part of FFmpeg. + * +@@ -1199,3 +1200,100 @@ + H264_MC_816(H264_MC_H, ssse3) + H264_MC_816(H264_MC_HV, ssse3) + #endif ++ ++ ++ ++//10bit ++#define LUMA_MC_OP(OP, NUM, DEPTH, TYPE, OPT) \ ++void ff_ ## OP ## _h264_qpel ## NUM ## _ ## TYPE ## _ ## DEPTH ## _ ## OPT \ ++ (uint8_t *dst, uint8_t *src, int stride); ++ ++#define LUMA_MC_ALL(DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(put, 4, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(avg, 4, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT) ++ ++#define LUMA_MC_816(DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(put, 8, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(avg, 8, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(put, 16, DEPTH, TYPE, OPT) \ ++ LUMA_MC_OP(avg, 16, DEPTH, TYPE, OPT) ++ ++LUMA_MC_ALL(10, mc00, mmxext) ++LUMA_MC_ALL(10, mc10, mmxext) ++LUMA_MC_ALL(10, mc20, mmxext) ++LUMA_MC_ALL(10, mc30, mmxext) ++LUMA_MC_ALL(10, mc01, mmxext) ++LUMA_MC_ALL(10, mc11, mmxext) ++LUMA_MC_ALL(10, mc21, mmxext) ++LUMA_MC_ALL(10, mc31, mmxext) ++LUMA_MC_ALL(10, mc02, mmxext) ++LUMA_MC_ALL(10, mc12, mmxext) ++LUMA_MC_ALL(10, mc22, mmxext) ++LUMA_MC_ALL(10, mc32, mmxext) ++LUMA_MC_ALL(10, mc03, mmxext) ++LUMA_MC_ALL(10, mc13, mmxext) ++LUMA_MC_ALL(10, mc23, mmxext) ++LUMA_MC_ALL(10, mc33, mmxext) ++ ++LUMA_MC_816(10, mc00, sse2) ++LUMA_MC_816(10, mc10, sse2) ++LUMA_MC_816(10, mc10, sse2_cache64) ++LUMA_MC_816(10, mc10, ssse3_cache64) ++LUMA_MC_816(10, mc20, sse2) ++LUMA_MC_816(10, mc20, sse2_cache64) ++LUMA_MC_816(10, mc20, ssse3_cache64) ++LUMA_MC_816(10, mc30, sse2) ++LUMA_MC_816(10, mc30, sse2_cache64) ++LUMA_MC_816(10, mc30, ssse3_cache64) ++LUMA_MC_816(10, mc01, sse2) ++LUMA_MC_816(10, mc11, sse2) ++LUMA_MC_816(10, mc21, sse2) ++LUMA_MC_816(10, mc31, sse2) ++LUMA_MC_816(10, mc02, sse2) ++LUMA_MC_816(10, mc12, sse2) ++LUMA_MC_816(10, mc22, sse2) ++LUMA_MC_816(10, mc32, sse2) ++LUMA_MC_816(10, mc03, sse2) ++LUMA_MC_816(10, mc13, sse2) ++LUMA_MC_816(10, mc23, sse2) ++LUMA_MC_816(10, mc33, sse2) ++ ++#define QPEL16_OPMC(OP, MC, MMX)\ ++void ff_ ## OP ## _h264_qpel16_ ## MC ## _10_ ## MMX(uint8_t *dst, uint8_t *src, int stride){\ ++ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\ ++ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\ ++ src += 8*stride;\ ++ dst += 8*stride;\ ++ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst , src , stride);\ ++ ff_ ## OP ## _h264_qpel8_ ## MC ## _10_ ## MMX(dst+16, src+16, stride);\ ++} ++ ++#define QPEL16_OP(MC, MMX)\ ++QPEL16_OPMC(put, MC, MMX)\ ++QPEL16_OPMC(avg, MC, MMX) ++ ++#define QPEL16(MMX)\ ++QPEL16_OP(mc00, MMX)\ ++QPEL16_OP(mc01, MMX)\ ++QPEL16_OP(mc02, MMX)\ ++QPEL16_OP(mc03, MMX)\ ++QPEL16_OP(mc10, MMX)\ ++QPEL16_OP(mc11, MMX)\ ++QPEL16_OP(mc12, MMX)\ ++QPEL16_OP(mc13, MMX)\ ++QPEL16_OP(mc20, MMX)\ ++QPEL16_OP(mc21, MMX)\ ++QPEL16_OP(mc22, MMX)\ ++QPEL16_OP(mc23, MMX)\ ++QPEL16_OP(mc30, MMX)\ ++QPEL16_OP(mc31, MMX)\ ++QPEL16_OP(mc32, MMX)\ ++QPEL16_OP(mc33, MMX) ++ ++#if ARCH_X86_32 && HAVE_YASM // ARCH_X86_64 implies sse2+ ++QPEL16(mmxext) ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_weight_10bit.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_weight_10bit.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/h264_weight_10bit.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/h264_weight_10bit.asm 2012-05-14 14:08:54.560344530 +0200 +@@ -0,0 +1,277 @@ ++;***************************************************************************** ++;* MMX/SSE2/AVX-optimized 10-bit H.264 weighted prediction code ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Daniel Kang ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA 32 ++ ++pw_pixel_max: times 8 dw ((1 << 10)-1) ++sq_1: dq 1 ++ dq 0 ++ ++cextern pw_1 ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; void h264_weight(uint8_t *dst, int stride, int height, int log2_denom, ++; int weight, int offset); ++;----------------------------------------------------------------------------- ++%macro WEIGHT_PROLOGUE 0 ++.prologue ++ PROLOGUE 0,6,8 ++ movifnidn r0, r0mp ++ movifnidn r1d, r1m ++ movifnidn r2d, r2m ++ movifnidn r4d, r4m ++ movifnidn r5d, r5m ++%endmacro ++ ++%macro WEIGHT_SETUP 1 ++ mova m0, [pw_1] ++ movd m2, r3m ++ pslld m0, m2 ; 1< + * + * This file is part of mpeg2dec, a free MPEG-2 video stream decoder. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/idct_sse2_xvid.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/idct_sse2_xvid.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/idct_sse2_xvid.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/idct_sse2_xvid.c 2012-05-14 14:08:54.565344631 +0200 +@@ -43,7 +43,7 @@ + #include "idct_xvid.h" + #include "dsputil_mmx.h" + +-/*! ++/** + * @file + * @brief SSE2 idct compatible with xvidmmx + */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/idct_xvid.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/idct_xvid.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/idct_xvid.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/idct_xvid.h 2012-05-14 14:08:54.566344651 +0200 +@@ -18,7 +18,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/*! ++/** + * @file + * header for Xvid IDCT functions + */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/imdct36_sse.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/imdct36_sse.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/imdct36_sse.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/imdct36_sse.asm 2012-05-14 14:08:54.567344671 +0200 +@@ -0,0 +1,725 @@ ++;****************************************************************************** ++;* 36 point SSE-optimized IMDCT transform ++;* Copyright (c) 2011 Vitor Sessak ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++align 16 ++ps_mask: dd 0, ~0, ~0, ~0 ++ps_mask2: dd 0, ~0, 0, ~0 ++ps_mask3: dd 0, 0, 0, ~0 ++ps_mask4: dd 0, ~0, 0, 0 ++ ++ps_val1: dd -0.5, -0.5, -0.8660254038, -0.8660254038 ++ps_val2: dd 1.0, 1.0, 0.8660254038, 0.8660254038 ++ps_val3: dd 0.1736481777, 0.1736481777, 0.3420201433, 0.3420201433 ++ps_val4: dd -0.7660444431, -0.7660444431, 0.8660254038, 0.8660254038 ++ps_val5: dd -0.9396926208, -0.9396926208, -0.9848077530, -0.9848077530 ++ps_val6: dd 0.5, 0.5, -0.6427876097, -0.6427876097 ++ps_val7: dd 1.0, 1.0, -0.6427876097, -0.6427876097 ++ ++ps_p1p1m1m1: dd 0, 0, 0x80000000, 0x80000000 ++ps_p1m1p1m1: dd 0, 0x80000000, 0, 0x80000000 ++ ++ps_cosh: dd 1.0, 0.50190991877167369479, 1.0, 5.73685662283492756461 ++ dd 1.0, 0.51763809020504152469, 1.0, 1.93185165257813657349 ++ dd 1.0, 0.55168895948124587824, -1.0, -1.18310079157624925896 ++ dd 1.0, 0.61038729438072803416, -1.0, -0.87172339781054900991 ++ dd 1.0, 0.70710678118654752439, 0.0, 0.0 ++ ++ps_cosh_sse3: dd 1.0, -0.50190991877167369479, 1.0, -5.73685662283492756461 ++ dd 1.0, -0.51763809020504152469, 1.0, -1.93185165257813657349 ++ dd 1.0, -0.55168895948124587824, -1.0, 1.18310079157624925896 ++ dd 1.0, -0.61038729438072803416, -1.0, 0.87172339781054900991 ++ dd 1.0, 0.70710678118654752439, 0.0, 0.0 ++ ++costabs: times 4 dd 0.98480773 ++ times 4 dd 0.93969262 ++ times 4 dd 0.86602539 ++ times 4 dd -0.76604444 ++ times 4 dd -0.64278764 ++ times 4 dd 0.50000000 ++ times 4 dd -0.50000000 ++ times 4 dd -0.34202015 ++ times 4 dd -0.17364818 ++ times 4 dd 0.50190992 ++ times 4 dd 0.51763808 ++ times 4 dd 0.55168896 ++ times 4 dd 0.61038726 ++ times 4 dd 0.70710677 ++ times 4 dd 0.87172341 ++ times 4 dd 1.18310082 ++ times 4 dd 1.93185163 ++ times 4 dd 5.73685646 ++ ++%define SBLIMIT 32 ++SECTION_TEXT ++ ++%macro PSHUFD 3 ++%if cpuflag(sse2) && notcpuflag(avx) ++ pshufd %1, %2, %3 ++%else ++ shufps %1, %2, %2, %3 ++%endif ++%endmacro ++ ++; input %2={x1,x2,x3,x4}, %3={y1,y2,y3,y4} ++; output %1={x3,x4,y1,y2} ++%macro BUILDINVHIGHLOW 3 ++%if cpuflag(avx) ++ shufps %1, %2, %3, 0x4e ++%else ++ movlhps %1, %3 ++ movhlps %1, %2 ++%endif ++%endmacro ++ ++; input %2={x1,x2,x3,x4}, %3={y1,y2,y3,y4} ++; output %1={x4,y1,y2,y3} ++%macro ROTLEFT 3 ++%if cpuflag(ssse3) ++ palignr %1, %3, %2, 12 ++%else ++ BUILDINVHIGHLOW %1, %2, %3 ++ shufps %1, %1, %3, 0x99 ++%endif ++%endmacro ++ ++%macro INVERTHL 2 ++%if cpuflag(sse2) ++ PSHUFD %1, %2, 0x4e ++%else ++ movhlps %1, %2 ++ movlhps %1, %2 ++%endif ++%endmacro ++ ++%macro BUTTERF 3 ++ INVERTHL %2, %1 ++ xorps %1, [ps_p1p1m1m1] ++ addps %1, %2 ++%if cpuflag(sse3) ++ mulps %1, %1, [ps_cosh_sse3 + %3] ++ PSHUFD %2, %1, 0xb1 ++ addsubps %1, %1, %2 ++%else ++ mulps %1, [ps_cosh + %3] ++ PSHUFD %2, %1, 0xb1 ++ xorps %1, [ps_p1m1p1m1] ++ addps %1, %2 ++%endif ++%endmacro ++ ++%macro STORE 4 ++ movhlps %2, %1 ++ movss [%3 ], %1 ++ movss [%3 + 2*%4], %2 ++ shufps %1, %1, 0xb1 ++ movss [%3 + %4], %1 ++ movhlps %2, %1 ++ movss [%3 + 3*%4], %2 ++%endmacro ++ ++%macro LOAD 4 ++ movlps %1, [%3 ] ++ movhps %1, [%3 + %4] ++ movlps %2, [%3 + 2*%4] ++ movhps %2, [%3 + 3*%4] ++ shufps %1, %2, 0x88 ++%endmacro ++ ++%macro LOADA64 2 ++%if cpuflag(avx) ++ movu %1, [%2] ++%else ++ movlps %1, [%2] ++ movhps %1, [%2 + 8] ++%endif ++%endmacro ++ ++%macro DEFINE_IMDCT 0 ++cglobal imdct36_float, 4,4,9, out, buf, in, win ++ ++ ; for(i=17;i>=1;i--) in[i] += in[i-1]; ++ LOADA64 m0, inq ++ LOADA64 m1, inq + 16 ++ ++ ROTLEFT m5, m0, m1 ++ ++ PSHUFD m6, m0, 0x93 ++ andps m6, m6, [ps_mask] ++ addps m0, m0, m6 ++ ++ LOADA64 m2, inq + 32 ++ ++ ROTLEFT m7, m1, m2 ++ ++ addps m1, m1, m5 ++ LOADA64 m3, inq + 48 ++ ++ ROTLEFT m5, m2, m3 ++ ++ xorps m4, m4, m4 ++ movlps m4, [inq+64] ++ BUILDINVHIGHLOW m6, m3, m4 ++ shufps m6, m6, m4, 0xa9 ++ ++ addps m4, m4, m6 ++ addps m2, m2, m7 ++ addps m3, m3, m5 ++ ++ ; for(i=17;i>=3;i-=2) in[i] += in[i-2]; ++ movlhps m5, m5, m0 ++ andps m5, m5, [ps_mask3] ++ ++ BUILDINVHIGHLOW m7, m0, m1 ++ andps m7, m7, [ps_mask2] ++ ++ addps m0, m0, m5 ++ ++ BUILDINVHIGHLOW m6, m1, m2 ++ andps m6, m6, [ps_mask2] ++ ++ addps m1, m1, m7 ++ ++ BUILDINVHIGHLOW m7, m2, m3 ++ andps m7, m7, [ps_mask2] ++ ++ addps m2, m2, m6 ++ ++ movhlps m6, m6, m3 ++ andps m6, m6, [ps_mask4] ++ ++ addps m3, m3, m7 ++ addps m4, m4, m6 ++ ++ ; Populate tmp[] ++ movlhps m6, m1, m5 ; zero out high values ++ subps m6, m6, m4 ++ ++ subps m5, m0, m3 ++ ++%ifdef ARCH_X86_64 ++ SWAP m5, m8 ++%endif ++ ++ mulps m7, m2, [ps_val1] ++ ++%ifdef ARCH_X86_64 ++ mulps m5, m8, [ps_val2] ++%else ++ mulps m5, m5, [ps_val2] ++%endif ++ addps m7, m7, m5 ++ ++ mulps m5, m6, [ps_val1] ++ subps m7, m7, m5 ++ ++%ifdef ARCH_X86_64 ++ SWAP m5, m8 ++%else ++ subps m5, m0, m3 ++%endif ++ ++ subps m5, m5, m6 ++ addps m5, m5, m2 ++ ++ shufps m6, m4, m3, 0xe4 ++ subps m6, m6, m2 ++ mulps m6, m6, [ps_val3] ++ ++ addps m4, m4, m1 ++ mulps m4, m4, [ps_val4] ++ ++ shufps m1, m1, m0, 0xe4 ++ addps m1, m1, m2 ++ mulps m1, m1, [ps_val5] ++ ++ mulps m3, m3, [ps_val6] ++ mulps m0, m0, [ps_val7] ++ addps m0, m0, m3 ++ ++ xorps m2, m1, [ps_p1p1m1m1] ++ subps m2, m2, m4 ++ addps m2, m2, m0 ++ ++ addps m3, m4, m0 ++ subps m3, m3, m6 ++ xorps m3, m3, [ps_p1p1m1m1] ++ ++ shufps m0, m0, m4, 0xe4 ++ subps m0, m0, m1 ++ addps m0, m0, m6 ++ ++ BUILDINVHIGHLOW m4, m2, m3 ++ shufps m3, m3, m2, 0x4e ++ ++ ; we have tmp = {SwAPLH(m0), SwAPLH(m7), m3, m4, m5} ++ ++ BUTTERF m0, m1, 0 ++ BUTTERF m7, m2, 16 ++ BUTTERF m3, m6, 32 ++ BUTTERF m4, m1, 48 ++ ++ mulps m5, m5, [ps_cosh + 64] ++ PSHUFD m1, m5, 0xe1 ++ xorps m5, m5, [ps_p1m1p1m1] ++ addps m5, m5, m1 ++ ++ ; permutates: ++ ; m0 0 1 2 3 => 2 6 10 14 m1 ++ ; m7 4 5 6 7 => 3 7 11 15 m2 ++ ; m3 8 9 10 11 => 17 13 9 5 m3 ++ ; m4 12 13 14 15 => 16 12 8 4 m5 ++ ; m5 16 17 xx xx => 0 1 xx xx m0 ++ ++ unpckhps m1, m0, m7 ++ unpckhps m6, m3, m4 ++ movhlps m2, m6, m1 ++ movlhps m1, m1, m6 ++ ++ unpcklps m5, m5, m4 ++ unpcklps m3, m3, m7 ++ movhlps m4, m3, m5 ++ movlhps m5, m5, m3 ++ SWAP m4, m3 ++ ; permutation done ++ ++ PSHUFD m6, m2, 0xb1 ++ movss m4, [bufq + 4*68] ++ movss m7, [bufq + 4*64] ++ unpcklps m7, m7, m4 ++ mulps m6, m6, [winq + 16*4] ++ addps m6, m6, m7 ++ movss [outq + 64*SBLIMIT], m6 ++ shufps m6, m6, m6, 0xb1 ++ movss [outq + 68*SBLIMIT], m6 ++ ++ mulps m6, m3, [winq + 4*4] ++ LOAD m4, m7, bufq + 4*16, 16 ++ addps m6, m6, m4 ++ STORE m6, m7, outq + 16*SBLIMIT, 4*SBLIMIT ++ ++ shufps m4, m0, m3, 0xb5 ++ mulps m4, m4, [winq + 8*4] ++ LOAD m7, m6, bufq + 4*32, 16 ++ addps m4, m4, m7 ++ STORE m4, m6, outq + 32*SBLIMIT, 4*SBLIMIT ++ ++ shufps m3, m3, m2, 0xb1 ++ mulps m3, m3, [winq + 12*4] ++ LOAD m7, m6, bufq + 4*48, 16 ++ addps m3, m3, m7 ++ STORE m3, m7, outq + 48*SBLIMIT, 4*SBLIMIT ++ ++ mulps m2, m2, [winq] ++ LOAD m6, m7, bufq, 16 ++ addps m2, m2, m6 ++ STORE m2, m7, outq, 4*SBLIMIT ++ ++ mulps m4, m1, [winq + 20*4] ++ STORE m4, m7, bufq, 16 ++ ++ mulps m3, m5, [winq + 24*4] ++ STORE m3, m7, bufq + 4*16, 16 ++ ++ shufps m0, m0, m5, 0xb0 ++ mulps m0, m0, [winq + 28*4] ++ STORE m0, m7, bufq + 4*32, 16 ++ ++ shufps m5, m5, m1, 0xb1 ++ mulps m5, m5, [winq + 32*4] ++ STORE m5, m7, bufq + 4*48, 16 ++ ++ shufps m1, m1, m1, 0xb1 ++ mulps m1, m1, [winq + 36*4] ++ movss [bufq + 4*64], m1 ++ shufps m1, m1, 0xb1 ++ movss [bufq + 4*68], m1 ++ RET ++%endmacro ++ ++INIT_XMM sse ++DEFINE_IMDCT ++ ++INIT_XMM sse2 ++DEFINE_IMDCT ++ ++INIT_XMM sse3 ++DEFINE_IMDCT ++ ++INIT_XMM ssse3 ++DEFINE_IMDCT ++ ++%ifdef HAVE_AVX ++INIT_XMM avx ++DEFINE_IMDCT ++%endif ++ ++INIT_XMM sse ++ ++%ifdef ARCH_X86_64 ++%define SPILL SWAP ++%define UNSPILL SWAP ++%define SPILLED(x) m %+ x ++%else ++%define SPILLED(x) [tmpq+(x-8)*16 + 32*4] ++%macro SPILL 2 ; xmm#, mempos ++ movaps SPILLED(%2), m%1 ++%endmacro ++%macro UNSPILL 2 ++ movaps m%1, SPILLED(%2) ++%endmacro ++%endif ++ ++%macro DEFINE_FOUR_IMDCT 0 ++cglobal four_imdct36_float, 5,5,8, out, buf, in, win, tmp ++ movlps m0, [inq+64] ++ movhps m0, [inq+64 + 72] ++ movlps m3, [inq+64 + 2*72] ++ movhps m3, [inq+64 + 3*72] ++ ++ shufps m5, m0, m3, 0xdd ++ shufps m0, m0, m3, 0x88 ++ ++ mova m1, [inq+48] ++ movu m6, [inq+48 + 72] ++ mova m7, [inq+48 + 2*72] ++ movu m3, [inq+48 + 3*72] ++ ++ TRANSPOSE4x4PS 1, 6, 7, 3, 4 ++ ++ addps m4, m6, m7 ++ mova [tmpq+4*28], m4 ++ ++ addps m7, m3 ++ addps m6, m1 ++ addps m3, m0 ++ addps m0, m5 ++ addps m0, m7 ++ addps m7, m6 ++ mova [tmpq+4*12], m7 ++ SPILL 3, 12 ++ ++ mova m4, [inq+32] ++ movu m5, [inq+32 + 72] ++ mova m2, [inq+32 + 2*72] ++ movu m7, [inq+32 + 3*72] ++ ++ TRANSPOSE4x4PS 4, 5, 2, 7, 3 ++ ++ addps m1, m7 ++ SPILL 1, 11 ++ ++ addps m3, m5, m2 ++ SPILL 3, 13 ++ ++ addps m7, m2 ++ addps m5, m4 ++ addps m6, m7 ++ mova [tmpq], m6 ++ addps m7, m5 ++ mova [tmpq+4*16], m7 ++ ++ mova m2, [inq+16] ++ movu m7, [inq+16 + 72] ++ mova m1, [inq+16 + 2*72] ++ movu m6, [inq+16 + 3*72] ++ ++ TRANSPOSE4x4PS 2, 7, 1, 6, 3 ++ ++ addps m4, m6 ++ addps m6, m1 ++ addps m1, m7 ++ addps m7, m2 ++ addps m5, m6 ++ SPILL 5, 15 ++ addps m6, m7 ++ mulps m6, [costabs + 16*2] ++ mova [tmpq+4*8], m6 ++ SPILL 1, 10 ++ SPILL 0, 14 ++ ++ mova m1, [inq] ++ movu m6, [inq + 72] ++ mova m3, [inq + 2*72] ++ movu m5, [inq + 3*72] ++ ++ TRANSPOSE4x4PS 1, 6, 3, 5, 0 ++ ++ addps m2, m5 ++ addps m5, m3 ++ addps m7, m5 ++ addps m3, m6 ++ addps m6, m1 ++ SPILL 7, 8 ++ addps m5, m6 ++ SPILL 6, 9 ++ addps m6, m4, SPILLED(12) ++ subps m6, m2 ++ UNSPILL 7, 11 ++ SPILL 5, 11 ++ subps m5, m1, m7 ++ mulps m7, [costabs + 16*5] ++ addps m7, m1 ++ mulps m0, m6, [costabs + 16*6] ++ addps m0, m5 ++ mova [tmpq+4*24], m0 ++ addps m6, m5 ++ mova [tmpq+4*4], m6 ++ addps m6, m4, m2 ++ mulps m6, [costabs + 16*1] ++ subps m4, SPILLED(12) ++ mulps m4, [costabs + 16*8] ++ addps m2, SPILLED(12) ++ mulps m2, [costabs + 16*3] ++ subps m5, m7, m6 ++ subps m5, m2 ++ addps m6, m7 ++ addps m6, m4 ++ addps m7, m2 ++ subps m7, m4 ++ mova [tmpq+4*20], m7 ++ mova m2, [tmpq+4*28] ++ mova [tmpq+4*28], m5 ++ UNSPILL 7, 13 ++ subps m5, m7, m2 ++ mulps m5, [costabs + 16*7] ++ UNSPILL 1, 10 ++ mulps m1, [costabs + 16*2] ++ addps m4, m3, m2 ++ mulps m4, [costabs + 16*4] ++ addps m2, m7 ++ addps m7, m3 ++ mulps m7, [costabs] ++ subps m3, m2 ++ mulps m3, [costabs + 16*2] ++ addps m2, m7, m5 ++ addps m2, m1 ++ SPILL 2, 10 ++ addps m7, m4 ++ subps m7, m1 ++ SPILL 7, 12 ++ subps m5, m4 ++ subps m5, m1 ++ UNSPILL 0, 14 ++ SPILL 5, 13 ++ addps m1, m0, SPILLED(15) ++ subps m1, SPILLED(8) ++ mova m4, [costabs + 16*5] ++ mulps m4, [tmpq] ++ UNSPILL 2, 9 ++ addps m4, m2 ++ subps m2, [tmpq] ++ mulps m5, m1, [costabs + 16*6] ++ addps m5, m2 ++ SPILL 5, 9 ++ addps m2, m1 ++ SPILL 2, 14 ++ UNSPILL 5, 15 ++ subps m7, m5, m0 ++ addps m5, SPILLED(8) ++ mulps m5, [costabs + 16*1] ++ mulps m7, [costabs + 16*8] ++ addps m0, SPILLED(8) ++ mulps m0, [costabs + 16*3] ++ subps m2, m4, m5 ++ subps m2, m0 ++ SPILL 2, 15 ++ addps m5, m4 ++ addps m5, m7 ++ addps m4, m0 ++ subps m4, m7 ++ SPILL 4, 8 ++ mova m7, [tmpq+4*16] ++ mova m2, [tmpq+4*12] ++ addps m0, m7, m2 ++ subps m0, SPILLED(11) ++ mulps m0, [costabs + 16*2] ++ addps m4, m7, SPILLED(11) ++ mulps m4, [costabs] ++ subps m7, m2 ++ mulps m7, [costabs + 16*7] ++ addps m2, SPILLED(11) ++ mulps m2, [costabs + 16*4] ++ addps m1, m7, [tmpq+4*8] ++ addps m1, m4 ++ addps m4, m2 ++ subps m4, [tmpq+4*8] ++ SPILL 4, 11 ++ subps m7, m2 ++ subps m7, [tmpq+4*8] ++ addps m4, m6, SPILLED(10) ++ subps m6, SPILLED(10) ++ addps m2, m5, m1 ++ mulps m2, [costabs + 16*9] ++ subps m5, m1 ++ mulps m5, [costabs + 16*17] ++ subps m1, m4, m2 ++ addps m4, m2 ++ mulps m2, m1, [winq+4*36] ++ addps m2, [bufq+4*36] ++ mova [outq+1152], m2 ++ mulps m1, [winq+4*32] ++ addps m1, [bufq+4*32] ++ mova [outq+1024], m1 ++ mulps m1, m4, [winq+4*116] ++ mova [bufq+4*36], m1 ++ mulps m4, [winq+4*112] ++ mova [bufq+4*32], m4 ++ addps m2, m6, m5 ++ subps m6, m5 ++ mulps m1, m6, [winq+4*68] ++ addps m1, [bufq+4*68] ++ mova [outq+2176], m1 ++ mulps m6, [winq] ++ addps m6, [bufq] ++ mova [outq], m6 ++ mulps m1, m2, [winq+4*148] ++ mova [bufq+4*68], m1 ++ mulps m2, [winq+4*80] ++ mova [bufq], m2 ++ addps m5, m3, [tmpq+4*24] ++ mova m2, [tmpq+4*24] ++ subps m2, m3 ++ mova m1, SPILLED(9) ++ subps m1, m0 ++ mulps m1, [costabs + 16*10] ++ addps m0, SPILLED(9) ++ mulps m0, [costabs + 16*16] ++ addps m6, m5, m1 ++ subps m5, m1 ++ mulps m3, m5, [winq+4*40] ++ addps m3, [bufq+4*40] ++ mova [outq+1280], m3 ++ mulps m5, [winq+4*28] ++ addps m5, [bufq+4*28] ++ mova [outq+896], m5 ++ mulps m1, m6, [winq+4*120] ++ mova [bufq+4*40], m1 ++ mulps m6, [winq+4*108] ++ mova [bufq+4*28], m6 ++ addps m1, m2, m0 ++ subps m2, m0 ++ mulps m5, m2, [winq+4*64] ++ addps m5, [bufq+4*64] ++ mova [outq+2048], m5 ++ mulps m2, [winq+4*4] ++ addps m2, [bufq+4*4] ++ mova [outq+128], m2 ++ mulps m0, m1, [winq+4*144] ++ mova [bufq+4*64], m0 ++ mulps m1, [winq+4*84] ++ mova [bufq+4*4], m1 ++ mova m1, [tmpq+4*28] ++ mova m5, m1 ++ addps m1, SPILLED(13) ++ subps m5, SPILLED(13) ++ UNSPILL 3, 15 ++ addps m2, m7, m3 ++ mulps m2, [costabs + 16*11] ++ subps m3, m7 ++ mulps m3, [costabs + 16*15] ++ addps m0, m2, m1 ++ subps m1, m2 ++ SWAP m0, m2 ++ mulps m6, m1, [winq+4*44] ++ addps m6, [bufq+4*44] ++ mova [outq+1408], m6 ++ mulps m1, [winq+4*24] ++ addps m1, [bufq+4*24] ++ mova [outq+768], m1 ++ mulps m0, m2, [winq+4*124] ++ mova [bufq+4*44], m0 ++ mulps m2, [winq+4*104] ++ mova [bufq+4*24], m2 ++ addps m0, m5, m3 ++ subps m5, m3 ++ mulps m1, m5, [winq+4*60] ++ addps m1, [bufq+4*60] ++ mova [outq+1920], m1 ++ mulps m5, [winq+4*8] ++ addps m5, [bufq+4*8] ++ mova [outq+256], m5 ++ mulps m1, m0, [winq+4*140] ++ mova [bufq+4*60], m1 ++ mulps m0, [winq+4*88] ++ mova [bufq+4*8], m0 ++ mova m1, [tmpq+4*20] ++ addps m1, SPILLED(12) ++ mova m2, [tmpq+4*20] ++ subps m2, SPILLED(12) ++ UNSPILL 7, 8 ++ subps m0, m7, SPILLED(11) ++ addps m7, SPILLED(11) ++ mulps m4, m7, [costabs + 16*12] ++ mulps m0, [costabs + 16*14] ++ addps m5, m1, m4 ++ subps m1, m4 ++ mulps m7, m1, [winq+4*48] ++ addps m7, [bufq+4*48] ++ mova [outq+1536], m7 ++ mulps m1, [winq+4*20] ++ addps m1, [bufq+4*20] ++ mova [outq+640], m1 ++ mulps m1, m5, [winq+4*128] ++ mova [bufq+4*48], m1 ++ mulps m5, [winq+4*100] ++ mova [bufq+4*20], m5 ++ addps m6, m2, m0 ++ subps m2, m0 ++ mulps m1, m2, [winq+4*56] ++ addps m1, [bufq+4*56] ++ mova [outq+1792], m1 ++ mulps m2, [winq+4*12] ++ addps m2, [bufq+4*12] ++ mova [outq+384], m2 ++ mulps m0, m6, [winq+4*136] ++ mova [bufq+4*56], m0 ++ mulps m6, [winq+4*92] ++ mova [bufq+4*12], m6 ++ UNSPILL 0, 14 ++ mulps m0, [costabs + 16*13] ++ mova m3, [tmpq+4*4] ++ addps m2, m0, m3 ++ subps m3, m0 ++ mulps m0, m3, [winq+4*52] ++ addps m0, [bufq+4*52] ++ mova [outq+1664], m0 ++ mulps m3, [winq+4*16] ++ addps m3, [bufq+4*16] ++ mova [outq+512], m3 ++ mulps m0, m2, [winq+4*132] ++ mova [bufq+4*52], m0 ++ mulps m2, [winq+4*96] ++ mova [bufq+4*16], m2 ++ RET ++%endmacro ++ ++INIT_XMM sse ++DEFINE_FOUR_IMDCT ++ ++%ifdef HAVE_AVX ++INIT_XMM avx ++DEFINE_FOUR_IMDCT ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/Makefile 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/Makefile 2012-05-14 14:08:54.492343161 +0200 +@@ -1,33 +1,60 @@ + OBJS-$(CONFIG_MLP_DECODER) += x86/mlpdsp.o + OBJS-$(CONFIG_TRUEHD_DECODER) += x86/mlpdsp.o + ++YASM-OBJS-$(CONFIG_DCT) += x86/dct32_sse.o ++ + YASM-OBJS-FFT-$(HAVE_AMD3DNOW) += x86/fft_3dn.o + YASM-OBJS-FFT-$(HAVE_AMD3DNOWEXT) += x86/fft_3dn2.o + YASM-OBJS-FFT-$(HAVE_SSE) += x86/fft_sse.o + YASM-OBJS-$(CONFIG_FFT) += x86/fft_mmx.o \ + $(YASM-OBJS-FFT-yes) + ++YASM-OBJS-$(CONFIG_DWT) += x86/dwt_yasm.o ++ ++YASM-OBJS-$(CONFIG_H264CHROMA) += x86/h264_chromamc.o \ ++ x86/h264_chromamc_10bit.o ++ + MMX-OBJS-$(CONFIG_H264DSP) += x86/h264dsp_mmx.o + YASM-OBJS-$(CONFIG_H264DSP) += x86/h264_deblock.o \ +- x86/h264_weight.o \ ++ x86/h264_deblock_10bit.o \ + x86/h264_idct.o \ ++ x86/h264_idct_10bit.o \ ++ x86/h264_weight.o \ ++ x86/h264_weight_10bit.o \ + +-YASM-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred.o ++YASM-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred.o \ ++ x86/h264_intrapred_10bit.o + MMX-OBJS-$(CONFIG_H264PRED) += x86/h264_intrapred_init.o + ++MMX-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp_init.o ++YASM-OBJS-$(CONFIG_RV30_DECODER) += x86/rv34dsp.o ++MMX-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp_init.o \ ++ x86/rv40dsp.o ++YASM-OBJS-$(CONFIG_RV40_DECODER) += x86/rv34dsp.o ++ + YASM-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_yasm.o + ++YASM-OBJS-$(CONFIG_DIRAC_DECODER) += x86/diracdsp_mmx.o x86/diracdsp_yasm.o ++ ++MMX-OBJS-$(CONFIG_AC3DSP) += x86/ac3dsp_mmx.o ++YASM-OBJS-$(CONFIG_AC3DSP) += x86/ac3dsp.o + MMX-OBJS-$(CONFIG_CAVS_DECODER) += x86/cavsdsp_mmx.o +-MMX-OBJS-$(CONFIG_MP1FLOAT_DECODER) += x86/mpegaudiodec_mmx.o +-MMX-OBJS-$(CONFIG_MP2FLOAT_DECODER) += x86/mpegaudiodec_mmx.o +-MMX-OBJS-$(CONFIG_MP3FLOAT_DECODER) += x86/mpegaudiodec_mmx.o +-MMX-OBJS-$(CONFIG_MP3ON4FLOAT_DECODER) += x86/mpegaudiodec_mmx.o +-MMX-OBJS-$(CONFIG_MP3ADUFLOAT_DECODER) += x86/mpegaudiodec_mmx.o ++MMX-OBJS-$(CONFIG_DNXHD_ENCODER) += x86/dnxhd_mmx.o ++MMX-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/mpegaudiodec_mmx.o ++YASM-OBJS-$(CONFIG_MPEGAUDIODSP) += x86/imdct36_sse.o ++MMX-OBJS-$(CONFIG_PNG_DECODER) += x86/png_mmx.o + MMX-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_mmx.o + YASM-OBJS-$(CONFIG_ENCODERS) += x86/dsputilenc_yasm.o + MMX-OBJS-$(CONFIG_GPL) += x86/idct_mmx.o + MMX-OBJS-$(CONFIG_LPC) += x86/lpc_mmx.o +-MMX-OBJS-$(CONFIG_DWT) += x86/snowdsp_mmx.o ++YASM-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp.o ++MMX-OBJS-$(CONFIG_PRORES_LGPL_DECODER) += x86/proresdsp-init.o ++YASM-OBJS-$(CONFIG_PRORES_DECODER) += x86/proresdsp.o ++MMX-OBJS-$(CONFIG_PRORES_DECODER) += x86/proresdsp-init.o ++MMX-OBJS-$(CONFIG_DWT) += x86/snowdsp_mmx.o \ ++ x86/dwt.o ++YASM-OBJS-$(CONFIG_V210_DECODER) += x86/v210.o ++MMX-OBJS-$(CONFIG_V210_DECODER) += x86/v210-init.o + MMX-OBJS-$(CONFIG_VC1_DECODER) += x86/vc1dsp_mmx.o + YASM-OBJS-$(CONFIG_VP3_DECODER) += x86/vp3dsp.o + YASM-OBJS-$(CONFIG_VP5_DECODER) += x86/vp3dsp.o +@@ -40,13 +67,12 @@ + MMX-OBJS-$(HAVE_YASM) += x86/dsputil_yasm.o \ + x86/deinterlace.o \ + x86/fmtconvert.o \ +- x86/h264_chromamc.o \ ++ x86/h264_qpel_10bit.o \ + $(YASM-OBJS-yes) + + MMX-OBJS-$(CONFIG_FFT) += x86/fft.o + +-OBJS-$(HAVE_MMX) += x86/dnxhd_mmx.o \ +- x86/dsputil_mmx.o \ ++OBJS-$(HAVE_MMX) += x86/dsputil_mmx.o \ + x86/fdct_mmx.o \ + x86/fmtconvert_mmx.o \ + x86/idct_mmx_xvid.o \ +@@ -55,4 +81,3 @@ + x86/mpegvideo_mmx.o \ + x86/simple_idct_mmx.o \ + +-MMX-OBJS-$(CONFIG_DCT) += x86/dct32_sse.o +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mathops.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mathops.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mathops.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mathops.h 2012-05-14 14:08:54.571344751 +0200 +@@ -26,24 +26,45 @@ + #include "libavutil/common.h" + + #if ARCH_X86_32 +-#define MULL(ra, rb, shift) \ +- ({ int rt, dummy; __asm__ (\ +- "imull %3 \n\t"\ +- "shrdl %4, %%edx, %%eax \n\t"\ +- : "=a"(rt), "=d"(dummy)\ +- : "a" ((int)(ra)), "rm" ((int)(rb)), "i"(shift));\ +- rt; }) +- +-#define MULH(ra, rb) \ +- ({ int rt, dummy;\ +- __asm__ ("imull %3\n\t" : "=d"(rt), "=a"(dummy): "a" ((int)(ra)), "rm" ((int)(rb)));\ +- rt; }) +- +-#define MUL64(ra, rb) \ +- ({ int64_t rt;\ +- __asm__ ("imull %2\n\t" : "=A"(rt) : "a" ((int)(ra)), "g" ((int)(rb)));\ +- rt; }) +-#endif ++ ++#define MULL MULL ++static av_always_inline av_const int MULL(int a, int b, unsigned shift) ++{ ++ int rt, dummy; ++ __asm__ ( ++ "imull %3 \n\t" ++ "shrdl %4, %%edx, %%eax \n\t" ++ :"=a"(rt), "=d"(dummy) ++ :"a"(a), "rm"(b), "ci"((uint8_t)shift) ++ ); ++ return rt; ++} ++ ++#define MULH MULH ++static av_always_inline av_const int MULH(int a, int b) ++{ ++ int rt, dummy; ++ __asm__ ( ++ "imull %3" ++ :"=d"(rt), "=a"(dummy) ++ :"a"(a), "rm"(b) ++ ); ++ return rt; ++} ++ ++#define MUL64 MUL64 ++static av_always_inline av_const int64_t MUL64(int a, int b) ++{ ++ int64_t rt; ++ __asm__ ( ++ "imull %2" ++ :"=A"(rt) ++ :"a"(a), "rm"(b) ++ ); ++ return rt; ++} ++ ++#endif /* ARCH_X86_32 */ + + #if HAVE_CMOV + /* median of 3 */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mlpdsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mlpdsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mlpdsp.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mlpdsp.c 2012-05-14 14:08:54.572344771 +0200 +@@ -23,7 +23,7 @@ + #include "libavcodec/dsputil.h" + #include "libavcodec/mlp.h" + +-#if HAVE_7REGS && HAVE_TEN_OPERANDS ++#if HAVE_7REGS + + extern void ff_mlp_firorder_8; + extern void ff_mlp_firorder_7; +@@ -171,11 +171,11 @@ + ); + } + +-#endif /* HAVE_7REGS && HAVE_TEN_OPERANDS */ ++#endif /* HAVE_7REGS */ + + void ff_mlp_init_x86(DSPContext* c, AVCodecContext *avctx) + { +-#if HAVE_7REGS && HAVE_TEN_OPERANDS ++#if HAVE_7REGS + c->mlp_filter_channel = mlp_filter_channel_x86; + #endif + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mpegaudiodec_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mpegaudiodec_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mpegaudiodec_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mpegaudiodec_mmx.c 2012-05-14 14:08:54.573344792 +0200 +@@ -21,9 +21,20 @@ + + #include "libavutil/cpu.h" + #include "libavutil/x86_cpu.h" ++#include "libavcodec/dsputil.h" ++#include "libavcodec/mpegaudiodsp.h" + +-#define CONFIG_FLOAT 1 +-#include "libavcodec/mpegaudio.h" ++void ff_imdct36_float_sse(float *out, float *buf, float *in, float *win); ++void ff_imdct36_float_sse2(float *out, float *buf, float *in, float *win); ++void ff_imdct36_float_sse3(float *out, float *buf, float *in, float *win); ++void ff_imdct36_float_ssse3(float *out, float *buf, float *in, float *win); ++void ff_imdct36_float_avx(float *out, float *buf, float *in, float *win); ++void ff_four_imdct36_float_sse(float *out, float *buf, float *in, float *win, ++ float *tmpbuf); ++void ff_four_imdct36_float_avx(float *out, float *buf, float *in, float *win, ++ float *tmpbuf); ++ ++DECLARE_ALIGNED(16, static float, mdct_win_sse)[2][4][4*40]; + + #define MACS(rt, ra, rb) rt+=(ra)*(rb) + #define MLSS(rt, ra, rb) rt-=(ra)*(rb) +@@ -148,11 +159,88 @@ + *out = sum; + } + +-void ff_mpegaudiodec_init_mmx(MPADecodeContext *s) ++ ++#define DECL_IMDCT_BLOCKS(CPU1, CPU2) \ ++static void imdct36_blocks_ ## CPU1(float *out, float *buf, float *in, \ ++ int count, int switch_point, int block_type) \ ++{ \ ++ int align_end = count - (count & 3); \ ++ int j; \ ++ for (j = 0; j < align_end; j+= 4) { \ ++ LOCAL_ALIGNED_16(float, tmpbuf, [1024]); \ ++ float *win = mdct_win_sse[switch_point && j < 4][block_type]; \ ++ /* apply window & overlap with previous buffer */ \ ++ \ ++ /* select window */ \ ++ ff_four_imdct36_float_ ## CPU2(out, buf, in, win, tmpbuf); \ ++ in += 4*18; \ ++ buf += 4*18; \ ++ out += 4; \ ++ } \ ++ for (; j < count; j++) { \ ++ /* apply window & overlap with previous buffer */ \ ++ \ ++ /* select window */ \ ++ int win_idx = (switch_point && j < 2) ? 0 : block_type; \ ++ float *win = ff_mdct_win_float[win_idx + (4 & -(j & 1))]; \ ++ \ ++ ff_imdct36_float_ ## CPU1(out, buf, in, win); \ ++ \ ++ in += 18; \ ++ buf++; \ ++ out++; \ ++ } \ ++} ++ ++#if HAVE_YASM ++#if HAVE_SSE ++DECL_IMDCT_BLOCKS(sse,sse) ++DECL_IMDCT_BLOCKS(sse2,sse) ++DECL_IMDCT_BLOCKS(sse3,sse) ++DECL_IMDCT_BLOCKS(ssse3,sse) ++#endif ++#if HAVE_AVX ++DECL_IMDCT_BLOCKS(avx,avx) ++#endif ++#endif ++ ++void ff_mpadsp_init_mmx(MPADSPContext *s) + { + int mm_flags = av_get_cpu_flags(); + ++ int i, j; ++ for (j = 0; j < 4; j++) { ++ for (i = 0; i < 40; i ++) { ++ mdct_win_sse[0][j][4*i ] = ff_mdct_win_float[j ][i]; ++ mdct_win_sse[0][j][4*i + 1] = ff_mdct_win_float[j + 4][i]; ++ mdct_win_sse[0][j][4*i + 2] = ff_mdct_win_float[j ][i]; ++ mdct_win_sse[0][j][4*i + 3] = ff_mdct_win_float[j + 4][i]; ++ mdct_win_sse[1][j][4*i ] = ff_mdct_win_float[0 ][i]; ++ mdct_win_sse[1][j][4*i + 1] = ff_mdct_win_float[4 ][i]; ++ mdct_win_sse[1][j][4*i + 2] = ff_mdct_win_float[j ][i]; ++ mdct_win_sse[1][j][4*i + 3] = ff_mdct_win_float[j + 4][i]; ++ } ++ } ++ + if (mm_flags & AV_CPU_FLAG_SSE2) { +- s->apply_window_mp3 = apply_window_mp3; ++ s->apply_window_float = apply_window_mp3; ++ } ++#if HAVE_YASM ++ if (0) { ++#if HAVE_AVX ++ } else if (mm_flags & AV_CPU_FLAG_AVX && HAVE_AVX) { ++ s->imdct36_blocks_float = imdct36_blocks_avx; ++#endif ++#if HAVE_SSE ++ } else if (mm_flags & AV_CPU_FLAG_SSSE3) { ++ s->imdct36_blocks_float = imdct36_blocks_ssse3; ++ } else if (mm_flags & AV_CPU_FLAG_SSE3) { ++ s->imdct36_blocks_float = imdct36_blocks_sse3; ++ } else if (mm_flags & AV_CPU_FLAG_SSE2) { ++ s->imdct36_blocks_float = imdct36_blocks_sse2; ++ } else if (mm_flags & AV_CPU_FLAG_SSE) { ++ s->imdct36_blocks_float = imdct36_blocks_sse; ++#endif /* HAVE_SSE */ + } ++#endif /* HAVE_YASM */ + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/mpegvideo_mmx_template.c 2012-05-14 14:08:54.574344812 +0200 +@@ -98,7 +98,7 @@ + x86_reg last_non_zero_p1; + int level=0, q; //=0 is because gcc says uninitialized ... + const uint16_t *qmat, *bias; +- DECLARE_ALIGNED(16, int16_t, temp_block)[64]; ++ LOCAL_ALIGNED_16(int16_t, temp_block, [64]); + + assert((7&(int)(&temp_block[0])) == 0); //did gcc align it correctly? + +@@ -110,28 +110,22 @@ + + if (s->mb_intra) { + int dummy; +- if (n < 4) ++ if (n < 4){ + q = s->y_dc_scale; +- else ++ bias = s->q_intra_matrix16[qscale][1]; ++ qmat = s->q_intra_matrix16[qscale][0]; ++ }else{ + q = s->c_dc_scale; ++ bias = s->q_chroma_intra_matrix16[qscale][1]; ++ qmat = s->q_chroma_intra_matrix16[qscale][0]; ++ } + /* note: block[0] is assumed to be positive */ + if (!s->h263_aic) { +-#if 1 + __asm__ volatile ( + "mul %%ecx \n\t" + : "=d" (level), "=a"(dummy) + : "a" ((block[0]>>2) + q), "c" (ff_inverse[q<<1]) + ); +-#else +- __asm__ volatile ( +- "xorl %%edx, %%edx \n\t" +- "divw %%cx \n\t" +- "movzwl %%ax, %%eax \n\t" +- : "=a" (level) +- : "a" ((block[0]>>2) + q), "c" (q<<1) +- : "%edx" +- ); +-#endif + } else + /* For AIC we skip quant/dequant of INTRADC */ + level = (block[0] + 4)>>3; +@@ -139,8 +133,6 @@ + block[0]=0; //avoid fake overflow + // temp_block[0] = (block[0] + (q >> 1)) / q; + last_non_zero_p1 = 1; +- bias = s->q_intra_matrix16[qscale][1]; +- qmat = s->q_intra_matrix16[qscale][0]; + } else { + last_non_zero_p1 = 0; + bias = s->q_inter_matrix16[qscale][1]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/png_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/png_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/png_mmx.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/png_mmx.c 2012-05-14 14:08:54.574344812 +0200 +@@ -0,0 +1,143 @@ ++/* ++ * MMX optimized PNG utils ++ * Copyright (c) 2008 Loren Merritt ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ * ++ */ ++ ++#include "libavutil/cpu.h" ++#include "libavutil/x86_cpu.h" ++#include "libavcodec/dsputil.h" ++#include "libavcodec/png.h" ++#include "dsputil_mmx.h" ++ ++//#undef NDEBUG ++//#include ++ ++static void add_bytes_l2_mmx(uint8_t *dst, uint8_t *src1, uint8_t *src2, int w) ++{ ++ x86_reg i=0; ++ __asm__ volatile( ++ "jmp 2f \n\t" ++ "1: \n\t" ++ "movq (%2, %0), %%mm0 \n\t" ++ "movq 8(%2, %0), %%mm1 \n\t" ++ "paddb (%3, %0), %%mm0 \n\t" ++ "paddb 8(%3, %0), %%mm1 \n\t" ++ "movq %%mm0, (%1, %0) \n\t" ++ "movq %%mm1, 8(%1, %0) \n\t" ++ "add $16, %0 \n\t" ++ "2: \n\t" ++ "cmp %4, %0 \n\t" ++ " js 1b \n\t" ++ : "+r" (i) ++ : "r"(dst), "r"(src1), "r"(src2), "r"((x86_reg)w-15) ++ ); ++ for(; i4) add_paeth_prediction_##cpu(dst+bpp/2, src+bpp/2, top+bpp/2, w-bpp/2, -bpp);\ ++ if(bpp<0) bpp=-bpp;\ ++ i= -bpp;\ ++ end = w-3;\ ++ __asm__ volatile(\ ++ "pxor %%mm7, %%mm7 \n"\ ++ "movd (%1,%0), %%mm0 \n"\ ++ "movd (%2,%0), %%mm1 \n"\ ++ "punpcklbw %%mm7, %%mm0 \n"\ ++ "punpcklbw %%mm7, %%mm1 \n"\ ++ "add %4, %0 \n"\ ++ "1: \n"\ ++ "movq %%mm1, %%mm2 \n"\ ++ "movd (%2,%0), %%mm1 \n"\ ++ "movq %%mm2, %%mm3 \n"\ ++ "punpcklbw %%mm7, %%mm1 \n"\ ++ "movq %%mm2, %%mm4 \n"\ ++ "psubw %%mm1, %%mm3 \n"\ ++ "psubw %%mm0, %%mm4 \n"\ ++ "movq %%mm3, %%mm5 \n"\ ++ "paddw %%mm4, %%mm5 \n"\ ++ abs3\ ++ "movq %%mm4, %%mm6 \n"\ ++ "pminsw %%mm5, %%mm6 \n"\ ++ "pcmpgtw %%mm6, %%mm3 \n"\ ++ "pcmpgtw %%mm5, %%mm4 \n"\ ++ "movq %%mm4, %%mm6 \n"\ ++ "pand %%mm3, %%mm4 \n"\ ++ "pandn %%mm3, %%mm6 \n"\ ++ "pandn %%mm0, %%mm3 \n"\ ++ "movd (%3,%0), %%mm0 \n"\ ++ "pand %%mm1, %%mm6 \n"\ ++ "pand %%mm4, %%mm2 \n"\ ++ "punpcklbw %%mm7, %%mm0 \n"\ ++ "paddw %%mm6, %%mm0 \n"\ ++ "paddw %%mm2, %%mm3 \n"\ ++ "paddw %%mm3, %%mm0 \n"\ ++ "pand %6 , %%mm0 \n"\ ++ "movq %%mm0, %%mm3 \n"\ ++ "packuswb %%mm3, %%mm3 \n"\ ++ "movd %%mm3, (%1,%0) \n"\ ++ "add %4, %0 \n"\ ++ "cmp %5, %0 \n"\ ++ "jle 1b \n"\ ++ :"+r"(i)\ ++ :"r"(dst), "r"(top), "r"(src), "r"((x86_reg)bpp), "g"(end),\ ++ "m"(ff_pw_255)\ ++ :"memory"\ ++ );\ ++} ++ ++#define ABS3_MMX2\ ++ "psubw %%mm5, %%mm7 \n"\ ++ "pmaxsw %%mm7, %%mm5 \n"\ ++ "pxor %%mm6, %%mm6 \n"\ ++ "pxor %%mm7, %%mm7 \n"\ ++ "psubw %%mm3, %%mm6 \n"\ ++ "psubw %%mm4, %%mm7 \n"\ ++ "pmaxsw %%mm6, %%mm3 \n"\ ++ "pmaxsw %%mm7, %%mm4 \n"\ ++ "pxor %%mm7, %%mm7 \n" ++ ++#define ABS3_SSSE3\ ++ "pabsw %%mm3, %%mm3 \n"\ ++ "pabsw %%mm4, %%mm4 \n"\ ++ "pabsw %%mm5, %%mm5 \n" ++ ++PAETH(mmx2, ABS3_MMX2) ++#if HAVE_SSSE3 ++PAETH(ssse3, ABS3_SSSE3) ++#endif ++ ++void ff_png_init_mmx(PNGDecContext *s) ++{ ++ int mm_flags = av_get_cpu_flags(); ++ ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ s->add_bytes_l2 = add_bytes_l2_mmx; ++ s->add_paeth_prediction = add_paeth_prediction_mmx2; ++#if HAVE_SSSE3 ++ if (mm_flags & AV_CPU_FLAG_SSSE3) ++ s->add_paeth_prediction = add_paeth_prediction_ssse3; ++#endif ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/proresdsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/proresdsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/proresdsp.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/proresdsp.asm 2012-05-14 14:08:54.576344852 +0200 +@@ -0,0 +1,314 @@ ++;****************************************************************************** ++;* x86-SIMD-optimized IDCT for prores ++;* this is identical to "simple" IDCT written by Michael Niedermayer ++;* except for the clip range ++;* ++;* Copyright (c) 2011 Ronald S. Bultje ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++%define W1sh2 22725 ; W1 = 90901 = 22725<<2 + 1 ++%define W2sh2 21407 ; W2 = 85627 = 21407<<2 - 1 ++%define W3sh2 19265 ; W3 = 77062 = 19265<<2 + 2 ++%define W4sh2 16384 ; W4 = 65535 = 16384<<2 - 1 ++%define W5sh2 12873 ; W5 = 51491 = 12873<<2 - 1 ++%define W6sh2 8867 ; W6 = 35468 = 8867<<2 ++%define W7sh2 4520 ; W7 = 18081 = 4520<<2 + 1 ++ ++%ifdef ARCH_X86_64 ++ ++SECTION_RODATA ++ ++w4_plus_w2: times 4 dw W4sh2, +W2sh2 ++w4_min_w2: times 4 dw W4sh2, -W2sh2 ++w4_plus_w6: times 4 dw W4sh2, +W6sh2 ++w4_min_w6: times 4 dw W4sh2, -W6sh2 ++w1_plus_w3: times 4 dw W1sh2, +W3sh2 ++w3_min_w1: times 4 dw W3sh2, -W1sh2 ++w7_plus_w3: times 4 dw W7sh2, +W3sh2 ++w3_min_w7: times 4 dw W3sh2, -W7sh2 ++w1_plus_w5: times 4 dw W1sh2, +W5sh2 ++w5_min_w1: times 4 dw W5sh2, -W1sh2 ++w5_plus_w7: times 4 dw W5sh2, +W7sh2 ++w7_min_w5: times 4 dw W7sh2, -W5sh2 ++pw_88: times 8 dw 0x2008 ++ ++cextern pw_1 ++cextern pw_4 ++cextern pw_512 ++cextern pw_1019 ++ ++section .text align=16 ++ ++; interleave data while maintaining source ++; %1=type, %2=dstlo, %3=dsthi, %4=src, %5=interleave ++%macro SBUTTERFLY3 5 ++ punpckl%1 m%2, m%4, m%5 ++ punpckh%1 m%3, m%4, m%5 ++%endmacro ++ ++; %1/%2=src1/dst1, %3/%4=dst2, %5/%6=src2, %7=shift ++; action: %3/%4 = %1/%2 - %5/%6; %1/%2 += %5/%6 ++; %1/%2/%3/%4 >>= %7; dword -> word (in %1/%3) ++%macro SUMSUB_SHPK 7 ++ psubd %3, %1, %5 ; { a0 - b0 }[0-3] ++ psubd %4, %2, %6 ; { a0 - b0 }[4-7] ++ paddd %1, %5 ; { a0 + b0 }[0-3] ++ paddd %2, %6 ; { a0 + b0 }[4-7] ++ psrad %1, %7 ++ psrad %2, %7 ++ psrad %3, %7 ++ psrad %4, %7 ++ packssdw %1, %2 ; row[0] ++ packssdw %3, %4 ; row[7] ++%endmacro ++ ++; %1 = row or col (for rounding variable) ++; %2 = number of bits to shift at the end ++; %3 = optimization ++%macro IDCT_1D 3 ++ ; a0 = (W4 * row[0]) + (1 << (15 - 1)); ++ ; a1 = a0; ++ ; a2 = a0; ++ ; a3 = a0; ++ ; a0 += W2 * row[2]; ++ ; a1 += W6 * row[2]; ++ ; a2 -= W6 * row[2]; ++ ; a3 -= W2 * row[2]; ++%ifidn %1, col ++ paddw m10,[pw_88] ++%endif ++%ifidn %1, row ++ paddw m10,[pw_1] ++%endif ++ SBUTTERFLY3 wd, 0, 1, 10, 8 ; { row[0], row[2] }[0-3]/[4-7] ++ pmaddwd m2, m0, [w4_plus_w6] ++ pmaddwd m3, m1, [w4_plus_w6] ++ pmaddwd m4, m0, [w4_min_w6] ++ pmaddwd m5, m1, [w4_min_w6] ++ pmaddwd m6, m0, [w4_min_w2] ++ pmaddwd m7, m1, [w4_min_w2] ++ pmaddwd m0, [w4_plus_w2] ++ pmaddwd m1, [w4_plus_w2] ++ ++ ; a0: -1*row[0]-1*row[2] ++ ; a1: -1*row[0] ++ ; a2: -1*row[0] ++ ; a3: -1*row[0]+1*row[2] ++ ++ ; a0 += W4*row[4] + W6*row[6]; i.e. -1*row[4] ++ ; a1 -= W4*row[4] + W2*row[6]; i.e. -1*row[4]-1*row[6] ++ ; a2 -= W4*row[4] - W2*row[6]; i.e. -1*row[4]+1*row[6] ++ ; a3 += W4*row[4] - W6*row[6]; i.e. -1*row[4] ++ SBUTTERFLY3 wd, 8, 9, 13, 12 ; { row[4], row[6] }[0-3]/[4-7] ++ pmaddwd m10, m8, [w4_plus_w6] ++ pmaddwd m11, m9, [w4_plus_w6] ++ paddd m0, m10 ; a0[0-3] ++ paddd m1, m11 ; a0[4-7] ++ pmaddwd m10, m8, [w4_min_w6] ++ pmaddwd m11, m9, [w4_min_w6] ++ paddd m6, m10 ; a3[0-3] ++ paddd m7, m11 ; a3[4-7] ++ pmaddwd m10, m8, [w4_min_w2] ++ pmaddwd m11, m9, [w4_min_w2] ++ pmaddwd m8, [w4_plus_w2] ++ pmaddwd m9, [w4_plus_w2] ++ psubd m4, m10 ; a2[0-3] intermediate ++ psubd m5, m11 ; a2[4-7] intermediate ++ psubd m2, m8 ; a1[0-3] intermediate ++ psubd m3, m9 ; a1[4-7] intermediate ++ ++ ; load/store ++ mova [r2+ 0], m0 ++ mova [r2+ 32], m2 ++ mova [r2+ 64], m4 ++ mova [r2+ 96], m6 ++ mova m10,[r2+ 16] ; { row[1] }[0-7] ++ mova m8, [r2+ 48] ; { row[3] }[0-7] ++ mova m13,[r2+ 80] ; { row[5] }[0-7] ++ mova m14,[r2+112] ; { row[7] }[0-7] ++ mova [r2+ 16], m1 ++ mova [r2+ 48], m3 ++ mova [r2+ 80], m5 ++ mova [r2+112], m7 ++%ifidn %1, row ++ pmullw m10,[r3+ 16] ++ pmullw m8, [r3+ 48] ++ pmullw m13,[r3+ 80] ++ pmullw m14,[r3+112] ++%endif ++ ++ ; b0 = MUL(W1, row[1]); ++ ; MAC(b0, W3, row[3]); ++ ; b1 = MUL(W3, row[1]); ++ ; MAC(b1, -W7, row[3]); ++ ; b2 = MUL(W5, row[1]); ++ ; MAC(b2, -W1, row[3]); ++ ; b3 = MUL(W7, row[1]); ++ ; MAC(b3, -W5, row[3]); ++ SBUTTERFLY3 wd, 0, 1, 10, 8 ; { row[1], row[3] }[0-3]/[4-7] ++ pmaddwd m2, m0, [w3_min_w7] ++ pmaddwd m3, m1, [w3_min_w7] ++ pmaddwd m4, m0, [w5_min_w1] ++ pmaddwd m5, m1, [w5_min_w1] ++ pmaddwd m6, m0, [w7_min_w5] ++ pmaddwd m7, m1, [w7_min_w5] ++ pmaddwd m0, [w1_plus_w3] ++ pmaddwd m1, [w1_plus_w3] ++ ++ ; b0: +1*row[1]+2*row[3] ++ ; b1: +2*row[1]-1*row[3] ++ ; b2: -1*row[1]-1*row[3] ++ ; b3: +1*row[1]+1*row[3] ++ ++ ; MAC(b0, W5, row[5]); ++ ; MAC(b0, W7, row[7]); ++ ; MAC(b1, -W1, row[5]); ++ ; MAC(b1, -W5, row[7]); ++ ; MAC(b2, W7, row[5]); ++ ; MAC(b2, W3, row[7]); ++ ; MAC(b3, W3, row[5]); ++ ; MAC(b3, -W1, row[7]); ++ SBUTTERFLY3 wd, 8, 9, 13, 14 ; { row[5], row[7] }[0-3]/[4-7] ++ ++ ; b0: -1*row[5]+1*row[7] ++ ; b1: -1*row[5]+1*row[7] ++ ; b2: +1*row[5]+2*row[7] ++ ; b3: +2*row[5]-1*row[7] ++ ++ pmaddwd m10, m8, [w1_plus_w5] ++ pmaddwd m11, m9, [w1_plus_w5] ++ pmaddwd m12, m8, [w5_plus_w7] ++ pmaddwd m13, m9, [w5_plus_w7] ++ psubd m2, m10 ; b1[0-3] ++ psubd m3, m11 ; b1[4-7] ++ paddd m0, m12 ; b0[0-3] ++ paddd m1, m13 ; b0[4-7] ++ pmaddwd m12, m8, [w7_plus_w3] ++ pmaddwd m13, m9, [w7_plus_w3] ++ pmaddwd m8, [w3_min_w1] ++ pmaddwd m9, [w3_min_w1] ++ paddd m4, m12 ; b2[0-3] ++ paddd m5, m13 ; b2[4-7] ++ paddd m6, m8 ; b3[0-3] ++ paddd m7, m9 ; b3[4-7] ++ ++ ; row[0] = (a0 + b0) >> 15; ++ ; row[7] = (a0 - b0) >> 15; ++ ; row[1] = (a1 + b1) >> 15; ++ ; row[6] = (a1 - b1) >> 15; ++ ; row[2] = (a2 + b2) >> 15; ++ ; row[5] = (a2 - b2) >> 15; ++ ; row[3] = (a3 + b3) >> 15; ++ ; row[4] = (a3 - b3) >> 15; ++ mova m8, [r2+ 0] ; a0[0-3] ++ mova m9, [r2+16] ; a0[4-7] ++ SUMSUB_SHPK m8, m9, m10, m11, m0, m1, %2 ++ mova m0, [r2+32] ; a1[0-3] ++ mova m1, [r2+48] ; a1[4-7] ++ SUMSUB_SHPK m0, m1, m9, m11, m2, m3, %2 ++ mova m1, [r2+64] ; a2[0-3] ++ mova m2, [r2+80] ; a2[4-7] ++ SUMSUB_SHPK m1, m2, m11, m3, m4, m5, %2 ++ mova m2, [r2+96] ; a3[0-3] ++ mova m3, [r2+112] ; a3[4-7] ++ SUMSUB_SHPK m2, m3, m4, m5, m6, m7, %2 ++%endmacro ++ ++; void prores_idct_put_10_(uint8_t *pixels, int stride, ++; DCTELEM *block, const int16_t *qmat); ++%macro idct_put_fn 2 ++cglobal prores_idct_put_10_%1, 4, 4, %2 ++ movsxd r1, r1d ++ pxor m15, m15 ; zero ++ ++ ; for (i = 0; i < 8; i++) ++ ; idctRowCondDC(block + i*8); ++ mova m10,[r2+ 0] ; { row[0] }[0-7] ++ mova m8, [r2+32] ; { row[2] }[0-7] ++ mova m13,[r2+64] ; { row[4] }[0-7] ++ mova m12,[r2+96] ; { row[6] }[0-7] ++ ++ pmullw m10,[r3+ 0] ++ pmullw m8, [r3+32] ++ pmullw m13,[r3+64] ++ pmullw m12,[r3+96] ++ ++ IDCT_1D row, 15, %1 ++ ++ ; transpose for second part of IDCT ++ TRANSPOSE8x8W 8, 0, 1, 2, 4, 11, 9, 10, 3 ++ mova [r2+ 16], m0 ++ mova [r2+ 48], m2 ++ mova [r2+ 80], m11 ++ mova [r2+112], m10 ++ SWAP 8, 10 ++ SWAP 1, 8 ++ SWAP 4, 13 ++ SWAP 9, 12 ++ ++ ; for (i = 0; i < 8; i++) ++ ; idctSparseColAdd(dest + i, line_size, block + i); ++ IDCT_1D col, 18, %1 ++ ++ ; clip/store ++ mova m3, [pw_4] ++ mova m5, [pw_1019] ++ pmaxsw m8, m3 ++ pmaxsw m0, m3 ++ pmaxsw m1, m3 ++ pmaxsw m2, m3 ++ pmaxsw m4, m3 ++ pmaxsw m11, m3 ++ pmaxsw m9, m3 ++ pmaxsw m10, m3 ++ pminsw m8, m5 ++ pminsw m0, m5 ++ pminsw m1, m5 ++ pminsw m2, m5 ++ pminsw m4, m5 ++ pminsw m11, m5 ++ pminsw m9, m5 ++ pminsw m10, m5 ++ ++ lea r2, [r1*3] ++ mova [r0 ], m8 ++ mova [r0+r1 ], m0 ++ mova [r0+r1*2], m1 ++ mova [r0+r2 ], m2 ++ lea r0, [r0+r1*4] ++ mova [r0 ], m4 ++ mova [r0+r1 ], m11 ++ mova [r0+r1*2], m9 ++ mova [r0+r2 ], m10 ++ RET ++%endmacro ++ ++INIT_XMM ++idct_put_fn sse2, 16 ++INIT_XMM ++idct_put_fn sse4, 16 ++%ifdef HAVE_AVX ++INIT_AVX ++idct_put_fn avx, 16 ++%endif ++ ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/proresdsp-init.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/proresdsp-init.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/proresdsp-init.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/proresdsp-init.c 2012-05-14 14:08:54.575344832 +0200 +@@ -0,0 +1,57 @@ ++/* ++ * Apple ProRes compatible decoder ++ * ++ * Copyright (c) 2010-2011 Maxim Poliakovski ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavcodec/proresdsp.h" ++ ++void ff_prores_idct_put_10_sse2(uint16_t *dst, int linesize, ++ DCTELEM *block, const int16_t *qmat); ++void ff_prores_idct_put_10_sse4(uint16_t *dst, int linesize, ++ DCTELEM *block, const int16_t *qmat); ++void ff_prores_idct_put_10_avx (uint16_t *dst, int linesize, ++ DCTELEM *block, const int16_t *qmat); ++ ++void ff_proresdsp_x86_init(ProresDSPContext *dsp, AVCodecContext *avctx) ++{ ++#if ARCH_X86_64 && HAVE_YASM ++ int flags = av_get_cpu_flags(); ++ ++ if(avctx->flags & CODEC_FLAG_BITEXACT) ++ return; ++ ++ if (flags & AV_CPU_FLAG_SSE2) { ++ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; ++ dsp->idct_put = ff_prores_idct_put_10_sse2; ++ } ++ ++ if (flags & AV_CPU_FLAG_SSE4) { ++ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; ++ dsp->idct_put = ff_prores_idct_put_10_sse4; ++ } ++ ++#if HAVE_AVX ++ if (flags & AV_CPU_FLAG_AVX) { ++ dsp->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM; ++ dsp->idct_put = ff_prores_idct_put_10_avx; ++ } ++#endif /* HAVE_AVX */ ++#endif /* ARCH_X86_64 && HAVE_YASM */ ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv34dsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv34dsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv34dsp.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv34dsp.asm 2012-05-14 14:08:54.577344872 +0200 +@@ -0,0 +1,118 @@ ++;****************************************************************************** ++;* MMX/SSE2-optimized functions for the RV30 and RV40 decoders ++;* Copyright (C) 2012 Christophe Gisquet ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION .text ++ ++%macro IDCT_DC_NOROUND 1 ++ imul %1, 13*13*3 ++ sar %1, 11 ++%endmacro ++ ++%macro IDCT_DC_ROUND 1 ++ imul %1, 13*13 ++ add %1, 0x200 ++ sar %1, 10 ++%endmacro ++ ++%macro rv34_idct 1 ++cglobal rv34_idct_%1_mmx2, 1, 2, 0 ++ movsx r1, word [r0] ++ IDCT_DC r1 ++ movd m0, r1d ++ pshufw m0, m0, 0 ++ movq [r0+ 0], m0 ++ movq [r0+ 8], m0 ++ movq [r0+16], m0 ++ movq [r0+24], m0 ++ REP_RET ++%endmacro ++ ++INIT_MMX ++%define IDCT_DC IDCT_DC_ROUND ++rv34_idct dc ++%define IDCT_DC IDCT_DC_NOROUND ++rv34_idct dc_noround ++ ++; ff_rv34_idct_dc_add_mmx(uint8_t *dst, int stride, int dc); ++cglobal rv34_idct_dc_add_mmx, 3, 3 ++ ; calculate DC ++ IDCT_DC_ROUND r2 ++ pxor m1, m1 ++ movd m0, r2d ++ psubw m1, m0 ++ packuswb m0, m0 ++ packuswb m1, m1 ++ punpcklbw m0, m0 ++ punpcklbw m1, m1 ++ punpcklwd m0, m0 ++ punpcklwd m1, m1 ++ ++ ; add DC ++ lea r2, [r0+r1*2] ++ movh m2, [r0] ++ movh m3, [r0+r1] ++ movh m4, [r2] ++ movh m5, [r2+r1] ++ paddusb m2, m0 ++ paddusb m3, m0 ++ paddusb m4, m0 ++ paddusb m5, m0 ++ psubusb m2, m1 ++ psubusb m3, m1 ++ psubusb m4, m1 ++ psubusb m5, m1 ++ movh [r0], m2 ++ movh [r0+r1], m3 ++ movh [r2], m4 ++ movh [r2+r1], m5 ++ RET ++ ++; ff_rv34_idct_dc_add_sse4(uint8_t *dst, int stride, int dc); ++INIT_XMM ++cglobal rv34_idct_dc_add_sse4, 3, 3, 6 ++ ; load data ++ IDCT_DC_ROUND r2 ++ pxor m1, m1 ++ ++ ; calculate DC ++ movd m0, r2d ++ lea r2, [r0+r1*2] ++ movd m2, [r0] ++ movd m3, [r0+r1] ++ pshuflw m0, m0, 0 ++ movd m4, [r2] ++ movd m5, [r2+r1] ++ punpcklqdq m0, m0 ++ punpckldq m2, m3 ++ punpckldq m4, m5 ++ punpcklbw m2, m1 ++ punpcklbw m4, m1 ++ paddw m2, m0 ++ paddw m4, m0 ++ packuswb m2, m4 ++ movd [r0], m2 ++ pextrd [r0+r1], m2, 1 ++ pextrd [r2], m2, 2 ++ pextrd [r2+r1], m2, 3 ++ RET +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv34dsp_init.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv34dsp_init.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv34dsp_init.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv34dsp_init.c 2012-05-14 14:08:54.577344872 +0200 +@@ -0,0 +1,45 @@ ++/* ++ * RV30/40 MMX/SSE2 optimizations ++ * Copyright (C) 2012 Christophe Gisquet ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/cpu.h" ++#include "libavutil/x86_cpu.h" ++#include "libavcodec/dsputil.h" ++#include "libavcodec/rv34dsp.h" ++ ++void ff_rv34_idct_dc_mmx2(DCTELEM *block); ++void ff_rv34_idct_dc_noround_mmx2(DCTELEM *block); ++void ff_rv34_idct_dc_add_mmx(uint8_t *dst, int stride, int dc); ++void ff_rv34_idct_dc_add_sse4(uint8_t *dst, int stride, int dc); ++ ++av_cold void ff_rv34dsp_init_x86(RV34DSPContext* c, DSPContext *dsp) ++{ ++#if HAVE_YASM ++ int mm_flags = av_get_cpu_flags(); ++ ++ if (mm_flags & AV_CPU_FLAG_MMX) ++ c->rv34_idct_dc_add = ff_rv34_idct_dc_add_mmx; ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ c->rv34_inv_transform_dc = ff_rv34_idct_dc_noround_mmx2; ++ } ++ if (mm_flags & AV_CPU_FLAG_SSE4) ++ c->rv34_idct_dc_add = ff_rv34_idct_dc_add_sse4; ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv40dsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv40dsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/rv40dsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/rv40dsp.c 2012-05-14 14:08:54.578344892 +0200 +@@ -0,0 +1,60 @@ ++/* ++ * RV40 decoder motion compensation functions x86-optimised ++ * Copyright (c) 2008 Konstantin Shishkov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * RV40 decoder motion compensation functions x86-optimised ++ */ ++ ++#include "libavcodec/rv34dsp.h" ++ ++void ff_put_rv40_chroma_mc8_mmx (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_rv40_chroma_mc8_mmx2 (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_rv40_chroma_mc8_3dnow(uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++ ++void ff_put_rv40_chroma_mc4_mmx (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_rv40_chroma_mc4_mmx2 (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_rv40_chroma_mc4_3dnow(uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++ ++void ff_rv40dsp_init_x86(RV34DSPContext *c, DSPContext *dsp) ++{ ++ av_unused int mm_flags = av_get_cpu_flags(); ++ ++#if HAVE_YASM ++ if (mm_flags & AV_CPU_FLAG_MMX) { ++ c->put_chroma_pixels_tab[0] = ff_put_rv40_chroma_mc8_mmx; ++ c->put_chroma_pixels_tab[1] = ff_put_rv40_chroma_mc4_mmx; ++ } ++ if (mm_flags & AV_CPU_FLAG_MMX2) { ++ c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_mmx2; ++ c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_mmx2; ++ } else if (mm_flags & AV_CPU_FLAG_3DNOW) { ++ c->avg_chroma_pixels_tab[0] = ff_avg_rv40_chroma_mc8_3dnow; ++ c->avg_chroma_pixels_tab[1] = ff_avg_rv40_chroma_mc4_3dnow; ++ } ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/simple_idct_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/simple_idct_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/simple_idct_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/simple_idct_mmx.c 2012-05-14 14:08:54.580344932 +0200 +@@ -37,11 +37,7 @@ + #define C1 22725 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 + #define C2 21407 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 + #define C3 19266 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#if 0 +-#define C4 16384 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-#else + #define C4 16383 //cos(i*M_PI/16)*sqrt(2)*(1<<14) - 0.5 +-#endif + #define C5 12873 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 + #define C6 8867 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 + #define C7 4520 //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +@@ -80,135 +76,6 @@ + C3, -C1, C3, -C1 + }; + +-#if 0 +-static void unused_var_killer(void) +-{ +- int a= wm1010 + d40000; +- temp[0]=a; +-} +- +-static void inline idctCol (int16_t * col, int16_t *input) +-{ +-#undef C0 +-#undef C1 +-#undef C2 +-#undef C3 +-#undef C4 +-#undef C5 +-#undef C6 +-#undef C7 +- int a0, a1, a2, a3, b0, b1, b2, b3; +- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +-/* +- if( !(col[8*1] | col[8*2] |col[8*3] |col[8*4] |col[8*5] |col[8*6] | col[8*7])) { +- col[8*0] = col[8*1] = col[8*2] = col[8*3] = col[8*4] = +- col[8*5] = col[8*6] = col[8*7] = col[8*0]<<3; +- return; +- }*/ +- +-col[8*0] = input[8*0 + 0]; +-col[8*1] = input[8*2 + 0]; +-col[8*2] = input[8*0 + 1]; +-col[8*3] = input[8*2 + 1]; +-col[8*4] = input[8*4 + 0]; +-col[8*5] = input[8*6 + 0]; +-col[8*6] = input[8*4 + 1]; +-col[8*7] = input[8*6 + 1]; +- +- a0 = C4*col[8*0] + C2*col[8*2] + C4*col[8*4] + C6*col[8*6] + (1<<(COL_SHIFT-1)); +- a1 = C4*col[8*0] + C6*col[8*2] - C4*col[8*4] - C2*col[8*6] + (1<<(COL_SHIFT-1)); +- a2 = C4*col[8*0] - C6*col[8*2] - C4*col[8*4] + C2*col[8*6] + (1<<(COL_SHIFT-1)); +- a3 = C4*col[8*0] - C2*col[8*2] + C4*col[8*4] - C6*col[8*6] + (1<<(COL_SHIFT-1)); +- +- b0 = C1*col[8*1] + C3*col[8*3] + C5*col[8*5] + C7*col[8*7]; +- b1 = C3*col[8*1] - C7*col[8*3] - C1*col[8*5] - C5*col[8*7]; +- b2 = C5*col[8*1] - C1*col[8*3] + C7*col[8*5] + C3*col[8*7]; +- b3 = C7*col[8*1] - C5*col[8*3] + C3*col[8*5] - C1*col[8*7]; +- +- col[8*0] = (a0 + b0) >> COL_SHIFT; +- col[8*1] = (a1 + b1) >> COL_SHIFT; +- col[8*2] = (a2 + b2) >> COL_SHIFT; +- col[8*3] = (a3 + b3) >> COL_SHIFT; +- col[8*4] = (a3 - b3) >> COL_SHIFT; +- col[8*5] = (a2 - b2) >> COL_SHIFT; +- col[8*6] = (a1 - b1) >> COL_SHIFT; +- col[8*7] = (a0 - b0) >> COL_SHIFT; +-} +- +-static void inline idctRow (int16_t * output, int16_t * input) +-{ +- int16_t row[8]; +- +- int a0, a1, a2, a3, b0, b1, b2, b3; +- const int C0 = 23170; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C1 = 22725; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C2 = 21407; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C3 = 19266; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C4 = 16383; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C5 = 12873; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C6 = 8867; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- const int C7 = 4520; //cos(i*M_PI/16)*sqrt(2)*(1<<14) + 0.5 +- +-row[0] = input[0]; +-row[2] = input[1]; +-row[4] = input[4]; +-row[6] = input[5]; +-row[1] = input[8]; +-row[3] = input[9]; +-row[5] = input[12]; +-row[7] = input[13]; +- +- if( !(row[1] | row[2] |row[3] |row[4] |row[5] |row[6] | row[7]) ) { +- row[0] = row[1] = row[2] = row[3] = row[4] = +- row[5] = row[6] = row[7] = row[0]<<3; +- output[0] = row[0]; +- output[2] = row[1]; +- output[4] = row[2]; +- output[6] = row[3]; +- output[8] = row[4]; +- output[10] = row[5]; +- output[12] = row[6]; +- output[14] = row[7]; +- return; +- } +- +- a0 = C4*row[0] + C2*row[2] + C4*row[4] + C6*row[6] + (1<<(ROW_SHIFT-1)); +- a1 = C4*row[0] + C6*row[2] - C4*row[4] - C2*row[6] + (1<<(ROW_SHIFT-1)); +- a2 = C4*row[0] - C6*row[2] - C4*row[4] + C2*row[6] + (1<<(ROW_SHIFT-1)); +- a3 = C4*row[0] - C2*row[2] + C4*row[4] - C6*row[6] + (1<<(ROW_SHIFT-1)); +- +- b0 = C1*row[1] + C3*row[3] + C5*row[5] + C7*row[7]; +- b1 = C3*row[1] - C7*row[3] - C1*row[5] - C5*row[7]; +- b2 = C5*row[1] - C1*row[3] + C7*row[5] + C3*row[7]; +- b3 = C7*row[1] - C5*row[3] + C3*row[5] - C1*row[7]; +- +- row[0] = (a0 + b0) >> ROW_SHIFT; +- row[1] = (a1 + b1) >> ROW_SHIFT; +- row[2] = (a2 + b2) >> ROW_SHIFT; +- row[3] = (a3 + b3) >> ROW_SHIFT; +- row[4] = (a3 - b3) >> ROW_SHIFT; +- row[5] = (a2 - b2) >> ROW_SHIFT; +- row[6] = (a1 - b1) >> ROW_SHIFT; +- row[7] = (a0 - b0) >> ROW_SHIFT; +- +- output[0] = row[0]; +- output[2] = row[1]; +- output[4] = row[2]; +- output[6] = row[3]; +- output[8] = row[4]; +- output[10] = row[5]; +- output[12] = row[6]; +- output[14] = row[7]; +-} +-#endif +- + static inline void idct(int16_t *block) + { + DECLARE_ALIGNED(8, int64_t, align_tmp)[16]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/snowdsp_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/snowdsp_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/snowdsp_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/snowdsp_mmx.c 2012-05-14 14:08:54.581344953 +0200 +@@ -675,14 +675,14 @@ + + #define snow_inner_add_yblock_sse2_end_8\ + "sal $1, %%"REG_c" \n\t"\ +- "add $"PTR_SIZE"*2, %1 \n\t"\ ++ "add"OPSIZE" $"PTR_SIZE"*2, %1 \n\t"\ + snow_inner_add_yblock_sse2_end_common1\ + "sar $1, %%"REG_c" \n\t"\ + "sub $2, %2 \n\t"\ + snow_inner_add_yblock_sse2_end_common2 + + #define snow_inner_add_yblock_sse2_end_16\ +- "add $"PTR_SIZE"*1, %1 \n\t"\ ++ "add"OPSIZE" $"PTR_SIZE"*1, %1 \n\t"\ + snow_inner_add_yblock_sse2_end_common1\ + "dec %2 \n\t"\ + snow_inner_add_yblock_sse2_end_common2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/v210.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/v210.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/v210.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/v210.asm 2012-05-14 14:08:54.582344973 +0200 +@@ -0,0 +1,89 @@ ++;****************************************************************************** ++;* V210 SIMD unpack ++;* Copyright (c) 2011 Loren Merritt ++;* Copyright (c) 2011 Kieran Kunhya ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" ++ ++SECTION_RODATA ++ ++v210_mask: times 4 dd 0x3ff ++v210_mult: dw 64,4,64,4,64,4,64,4 ++v210_luma_shuf: db 8,9,0,1,2,3,12,13,4,5,6,7,-1,-1,-1,-1 ++v210_chroma_shuf: db 0,1,8,9,6,7,-1,-1,2,3,4,5,12,13,-1,-1 ++ ++SECTION .text ++ ++%macro v210_planar_unpack 2 ++ ++; v210_planar_unpack(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width) ++cglobal v210_planar_unpack_%1_%2, 5, 5 ++ movsxdifnidn r4, r4d ++ lea r1, [r1+2*r4] ++ add r2, r4 ++ add r3, r4 ++ neg r4 ++ ++ mova m3, [v210_mult] ++ mova m4, [v210_mask] ++ mova m5, [v210_luma_shuf] ++ mova m6, [v210_chroma_shuf] ++.loop ++%ifidn %1, unaligned ++ movu m0, [r0] ++%else ++ mova m0, [r0] ++%endif ++ ++ pmullw m1, m0, m3 ++ psrld m0, 10 ++ psrlw m1, 6 ; u0 v0 y1 y2 v1 u2 y4 y5 ++ pand m0, m4 ; y0 __ u1 __ y3 __ v2 __ ++ ++ shufps m2, m1, m0, 0x8d ; y1 y2 y4 y5 y0 __ y3 __ ++ pshufb m2, m5 ; y0 y1 y2 y3 y4 y5 __ __ ++ movu [r1+2*r4], m2 ++ ++ shufps m1, m0, 0xd8 ; u0 v0 v1 u2 u1 __ v2 __ ++ pshufb m1, m6 ; u0 u1 u2 __ v0 v1 v2 __ ++ movq [r2+r4], m1 ++ movhps [r3+r4], m1 ++ ++ add r0, mmsize ++ add r4, 6 ++ jl .loop ++ ++ REP_RET ++%endmacro ++ ++INIT_XMM ++v210_planar_unpack unaligned, ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++v210_planar_unpack unaligned, avx ++%endif ++ ++INIT_XMM ++v210_planar_unpack aligned, ssse3 ++%ifdef HAVE_AVX ++INIT_AVX ++v210_planar_unpack aligned, avx ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/v210-init.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/v210-init.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/v210-init.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/v210-init.c 2012-05-14 14:08:54.581344953 +0200 +@@ -0,0 +1,48 @@ ++/* ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/cpu.h" ++#include "libavcodec/v210dec.h" ++ ++extern void ff_v210_planar_unpack_unaligned_ssse3(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width); ++extern void ff_v210_planar_unpack_unaligned_avx(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width); ++ ++extern void ff_v210_planar_unpack_aligned_ssse3(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width); ++extern void ff_v210_planar_unpack_aligned_avx(const uint32_t *src, uint16_t *y, uint16_t *u, uint16_t *v, int width); ++ ++av_cold void v210_x86_init(V210DecContext *s) ++{ ++ int cpu_flags = av_get_cpu_flags(); ++ ++#if HAVE_YASM ++ if (s->aligned_input) { ++ if (cpu_flags & AV_CPU_FLAG_SSSE3) ++ s->unpack_frame = ff_v210_planar_unpack_aligned_ssse3; ++ ++ if (HAVE_AVX && cpu_flags & AV_CPU_FLAG_AVX) ++ s->unpack_frame = ff_v210_planar_unpack_aligned_avx; ++ } ++ else { ++ if (cpu_flags & AV_CPU_FLAG_SSSE3) ++ s->unpack_frame = ff_v210_planar_unpack_unaligned_ssse3; ++ ++ if (HAVE_AVX && cpu_flags & AV_CPU_FLAG_AVX) ++ s->unpack_frame = ff_v210_planar_unpack_unaligned_avx; ++ } ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vc1dsp_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vc1dsp_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vc1dsp_mmx.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vc1dsp_mmx.c 2012-05-14 14:08:54.586345053 +0200 +@@ -28,6 +28,7 @@ + #include "libavutil/x86_cpu.h" + #include "libavcodec/dsputil.h" + #include "dsputil_mmx.h" ++#include "libavcodec/vc1dsp.h" + + #define OP_PUT(S,D) + #define OP_AVG(S,D) "pavgb " #S ", " #D " \n\t" +@@ -712,30 +713,45 @@ + ff_vc1_h_loop_filter8_sse4(src, stride, pq); + ff_vc1_h_loop_filter8_sse4(src+8*stride, stride, pq); + } ++ + #endif + +-void ff_vc1dsp_init_mmx(DSPContext* dsp, AVCodecContext *avctx) { ++void ff_put_vc1_chroma_mc8_mmx_nornd (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_vc1_chroma_mc8_mmx2_nornd (uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_vc1_chroma_mc8_3dnow_nornd(uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_put_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++void ff_avg_vc1_chroma_mc8_ssse3_nornd(uint8_t *dst, uint8_t *src, ++ int stride, int h, int x, int y); ++ ++void ff_vc1dsp_init_mmx(VC1DSPContext *dsp) ++{ + int mm_flags = av_get_cpu_flags(); + +- dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_mmx; +- dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_mmx; +- +- dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_mmx; +- dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_mmx; +- +- dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_mmx; +- dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_mmx; +- dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_mmx; +- +- dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_mmx; +- dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_mmx; +- dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_mmx; +- dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_mmx; ++ if (mm_flags & AV_CPU_FLAG_MMX) { ++ dsp->put_vc1_mspel_pixels_tab[ 0] = ff_put_vc1_mspel_mc00_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 4] = put_vc1_mspel_mc01_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 8] = put_vc1_mspel_mc02_mmx; ++ dsp->put_vc1_mspel_pixels_tab[12] = put_vc1_mspel_mc03_mmx; ++ ++ dsp->put_vc1_mspel_pixels_tab[ 1] = put_vc1_mspel_mc10_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 5] = put_vc1_mspel_mc11_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 9] = put_vc1_mspel_mc12_mmx; ++ dsp->put_vc1_mspel_pixels_tab[13] = put_vc1_mspel_mc13_mmx; ++ ++ dsp->put_vc1_mspel_pixels_tab[ 2] = put_vc1_mspel_mc20_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 6] = put_vc1_mspel_mc21_mmx; ++ dsp->put_vc1_mspel_pixels_tab[10] = put_vc1_mspel_mc22_mmx; ++ dsp->put_vc1_mspel_pixels_tab[14] = put_vc1_mspel_mc23_mmx; ++ ++ dsp->put_vc1_mspel_pixels_tab[ 3] = put_vc1_mspel_mc30_mmx; ++ dsp->put_vc1_mspel_pixels_tab[ 7] = put_vc1_mspel_mc31_mmx; ++ dsp->put_vc1_mspel_pixels_tab[11] = put_vc1_mspel_mc32_mmx; ++ dsp->put_vc1_mspel_pixels_tab[15] = put_vc1_mspel_mc33_mmx; ++ } + + if (mm_flags & AV_CPU_FLAG_MMX2){ + dsp->avg_vc1_mspel_pixels_tab[ 0] = ff_avg_vc1_mspel_mc00_mmx2; +@@ -775,11 +791,16 @@ + #if HAVE_YASM + if (mm_flags & AV_CPU_FLAG_MMX) { + ASSIGN_LF(mmx); ++ dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_mmx_nornd; + } + return; + if (mm_flags & AV_CPU_FLAG_MMX2) { + ASSIGN_LF(mmx2); ++ dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_mmx2_nornd; ++ } else if (mm_flags & AV_CPU_FLAG_3DNOW) { ++ dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_3dnow_nornd; + } ++ + if (mm_flags & AV_CPU_FLAG_SSE2) { + dsp->vc1_v_loop_filter8 = ff_vc1_v_loop_filter8_sse2; + dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse2; +@@ -788,6 +809,8 @@ + } + if (mm_flags & AV_CPU_FLAG_SSSE3) { + ASSIGN_LF(ssse3); ++ dsp->put_no_rnd_vc1_chroma_pixels_tab[0]= ff_put_vc1_chroma_mc8_ssse3_nornd; ++ dsp->avg_no_rnd_vc1_chroma_pixels_tab[0]= ff_avg_vc1_chroma_mc8_ssse3_nornd; + } + if (mm_flags & AV_CPU_FLAG_SSE4) { + dsp->vc1_h_loop_filter8 = ff_vc1_h_loop_filter8_sse4; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vc1dsp_yasm.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vc1dsp_yasm.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vc1dsp_yasm.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vc1dsp_yasm.asm 2012-05-14 14:08:54.587345073 +0200 +@@ -16,11 +16,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + cextern pw_4 + cextern pw_5 +@@ -227,7 +227,7 @@ + imul r2, 0x01010101 + %endmacro + +-; I dont know why the sign extension is needed... ++; I do not know why the sign extension is needed... + %macro PSIGNW_SRA_MMX 2 + psraw %2, 15 + PSIGNW_MMX %1, %2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp3dsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp3dsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp3dsp.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp3dsp.asm 2012-05-14 14:08:54.588345093 +0200 +@@ -16,11 +16,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + ; MMX-optimized functions cribbed from the original VP3 source code. + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp56dsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp56dsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp56dsp.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp56dsp.asm 2012-05-14 14:08:54.588345093 +0200 +@@ -17,11 +17,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + cextern pw_64 + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp8dsp.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp8dsp.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp8dsp.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp8dsp.asm 2012-05-14 14:08:54.591345155 +0200 +@@ -17,11 +17,11 @@ + ;* + ;* You should have received a copy of the GNU Lesser General Public + ;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + ;****************************************************************************** + +-%include "x86inc.asm" +-%include "x86util.asm" ++%include "libavutil/x86/x86inc.asm" ++%include "libavutil/x86/x86util.asm" + + SECTION_RODATA + +@@ -1106,10 +1106,10 @@ + ; %5/%6 are temporary registers + ; we assume m6/m7 have constant words 20091/17734 loaded in them + %macro VP8_IDCT_TRANSFORM4x4_1D 6 +- SUMSUB_BA m%3, m%1, m%5 ;t0, t1 ++ SUMSUB_BA w, %3, %1, %5 ;t0, t1 + VP8_MULTIPLY_SUMSUB m%2, m%4, m%5,m%6 ;t2, t3 +- SUMSUB_BA m%4, m%3, m%5 ;tmp0, tmp3 +- SUMSUB_BA m%2, m%1, m%5 ;tmp1, tmp2 ++ SUMSUB_BA w, %4, %3, %5 ;tmp0, tmp3 ++ SUMSUB_BA w, %2, %1, %5 ;tmp1, tmp2 + SWAP %4, %1 + SWAP %4, %3 + %endmacro +@@ -1181,8 +1181,8 @@ + %endmacro + + %macro HADAMARD4_1D 4 +- SUMSUB_BADC m%2, m%1, m%4, m%3 +- SUMSUB_BADC m%4, m%2, m%3, m%1 ++ SUMSUB_BADC w, %2, %1, %4, %3 ++ SUMSUB_BADC w, %4, %2, %3, %1 + SWAP %1, %4, %3 + %endmacro + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp8dsp-init.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp8dsp-init.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/vp8dsp-init.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/vp8dsp-init.c 2012-05-14 14:08:54.589345114 +0200 +@@ -283,9 +283,9 @@ + + av_cold void ff_vp8dsp_init_x86(VP8DSPContext* c) + { ++#if HAVE_YASM + int mm_flags = av_get_cpu_flags(); + +-#if HAVE_YASM + if (mm_flags & AV_CPU_FLAG_MMX) { + c->vp8_idct_dc_add = ff_vp8_idct_dc_add_mmx; + c->vp8_idct_dc_add4y = ff_vp8_idct_dc_add4y_mmx; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/x86inc.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/x86inc.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/x86inc.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/x86inc.asm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,647 +0,0 @@ +-;***************************************************************************** +-;* x86inc.asm +-;***************************************************************************** +-;* Copyright (C) 2005-2008 x264 project +-;* +-;* Authors: Loren Merritt +-;* Anton Mitrofanov +-;* +-;* Permission to use, copy, modify, and/or distribute this software for any +-;* purpose with or without fee is hereby granted, provided that the above +-;* copyright notice and this permission notice appear in all copies. +-;* +-;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES +-;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +-;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR +-;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES +-;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN +-;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF +-;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +-;***************************************************************************** +- +-; This is a header file for the x264ASM assembly language, which uses +-; NASM/YASM syntax combined with a large number of macros to provide easy +-; abstraction between different calling conventions (x86_32, win64, linux64). +-; It also has various other useful features to simplify writing the kind of +-; DSP functions that are most often used in x264. +- +-; Unlike the rest of x264, this file is available under an ISC license, as it +-; has significant usefulness outside of x264 and we want it to be available +-; to the largest audience possible. Of course, if you modify it for your own +-; purposes to add a new feature, we strongly encourage contributing a patch +-; as this feature might be useful for others as well. Send patches or ideas +-; to x264-devel@videolan.org . +- +-%define program_name ff +- +-%ifdef ARCH_X86_64 +- %ifidn __OUTPUT_FORMAT__,win32 +- %define WIN64 +- %else +- %define UNIX64 +- %endif +-%endif +- +-%ifdef PREFIX +- %define mangle(x) _ %+ x +-%else +- %define mangle(x) x +-%endif +- +-; FIXME: All of the 64bit asm functions that take a stride as an argument +-; via register, assume that the high dword of that register is filled with 0. +-; This is true in practice (since we never do any 64bit arithmetic on strides, +-; and x264's strides are all positive), but is not guaranteed by the ABI. +- +-; Name of the .rodata section. +-; Kludge: Something on OS X fails to align .rodata even given an align attribute, +-; so use a different read-only section. +-%macro SECTION_RODATA 0-1 16 +- %ifidn __OUTPUT_FORMAT__,macho64 +- SECTION .text align=%1 +- %elifidn __OUTPUT_FORMAT__,macho +- SECTION .text align=%1 +- fakegot: +- %else +- SECTION .rodata align=%1 +- %endif +-%endmacro +- +-%ifdef WIN64 +- %define PIC +-%elifndef ARCH_X86_64 +-; x86_32 doesn't require PIC. +-; Some distros prefer shared objects to be PIC, but nothing breaks if +-; the code contains a few textrels, so we'll skip that complexity. +- %undef PIC +-%endif +-%ifdef PIC +- default rel +-%endif +- +-; Macros to eliminate most code duplication between x86_32 and x86_64: +-; Currently this works only for leaf functions which load all their arguments +-; into registers at the start, and make no other use of the stack. Luckily that +-; covers most of x264's asm. +- +-; PROLOGUE: +-; %1 = number of arguments. loads them from stack if needed. +-; %2 = number of registers used. pushes callee-saved regs if needed. +-; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed. +-; %4 = list of names to define to registers +-; PROLOGUE can also be invoked by adding the same options to cglobal +- +-; e.g. +-; cglobal foo, 2,3,0, dst, src, tmp +-; declares a function (foo), taking two args (dst and src) and one local variable (tmp) +- +-; TODO Some functions can use some args directly from the stack. If they're the +-; last args then you can just not declare them, but if they're in the middle +-; we need more flexible macro. +- +-; RET: +-; Pops anything that was pushed by PROLOGUE +- +-; REP_RET: +-; Same, but if it doesn't pop anything it becomes a 2-byte ret, for athlons +-; which are slow when a normal ret follows a branch. +- +-; registers: +-; rN and rNq are the native-size register holding function argument N +-; rNd, rNw, rNb are dword, word, and byte size +-; rNm is the original location of arg N (a register or on the stack), dword +-; rNmp is native size +- +-%macro DECLARE_REG 6 +- %define r%1q %2 +- %define r%1d %3 +- %define r%1w %4 +- %define r%1b %5 +- %define r%1m %6 +- %ifid %6 ; i.e. it's a register +- %define r%1mp %2 +- %elifdef ARCH_X86_64 ; memory +- %define r%1mp qword %6 +- %else +- %define r%1mp dword %6 +- %endif +- %define r%1 %2 +-%endmacro +- +-%macro DECLARE_REG_SIZE 2 +- %define r%1q r%1 +- %define e%1q r%1 +- %define r%1d e%1 +- %define e%1d e%1 +- %define r%1w %1 +- %define e%1w %1 +- %define r%1b %2 +- %define e%1b %2 +-%ifndef ARCH_X86_64 +- %define r%1 e%1 +-%endif +-%endmacro +- +-DECLARE_REG_SIZE ax, al +-DECLARE_REG_SIZE bx, bl +-DECLARE_REG_SIZE cx, cl +-DECLARE_REG_SIZE dx, dl +-DECLARE_REG_SIZE si, sil +-DECLARE_REG_SIZE di, dil +-DECLARE_REG_SIZE bp, bpl +- +-; t# defines for when per-arch register allocation is more complex than just function arguments +- +-%macro DECLARE_REG_TMP 1-* +- %assign %%i 0 +- %rep %0 +- CAT_XDEFINE t, %%i, r%1 +- %assign %%i %%i+1 +- %rotate 1 +- %endrep +-%endmacro +- +-%macro DECLARE_REG_TMP_SIZE 0-* +- %rep %0 +- %define t%1q t%1 %+ q +- %define t%1d t%1 %+ d +- %define t%1w t%1 %+ w +- %define t%1b t%1 %+ b +- %rotate 1 +- %endrep +-%endmacro +- +-DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9 +- +-%ifdef ARCH_X86_64 +- %define gprsize 8 +-%else +- %define gprsize 4 +-%endif +- +-%macro PUSH 1 +- push %1 +- %assign stack_offset stack_offset+gprsize +-%endmacro +- +-%macro POP 1 +- pop %1 +- %assign stack_offset stack_offset-gprsize +-%endmacro +- +-%macro SUB 2 +- sub %1, %2 +- %ifidn %1, rsp +- %assign stack_offset stack_offset+(%2) +- %endif +-%endmacro +- +-%macro ADD 2 +- add %1, %2 +- %ifidn %1, rsp +- %assign stack_offset stack_offset-(%2) +- %endif +-%endmacro +- +-%macro movifnidn 2 +- %ifnidn %1, %2 +- mov %1, %2 +- %endif +-%endmacro +- +-%macro movsxdifnidn 2 +- %ifnidn %1, %2 +- movsxd %1, %2 +- %endif +-%endmacro +- +-%macro ASSERT 1 +- %if (%1) == 0 +- %error assert failed +- %endif +-%endmacro +- +-%macro DEFINE_ARGS 0-* +- %ifdef n_arg_names +- %assign %%i 0 +- %rep n_arg_names +- CAT_UNDEF arg_name %+ %%i, q +- CAT_UNDEF arg_name %+ %%i, d +- CAT_UNDEF arg_name %+ %%i, w +- CAT_UNDEF arg_name %+ %%i, b +- CAT_UNDEF arg_name %+ %%i, m +- CAT_UNDEF arg_name, %%i +- %assign %%i %%i+1 +- %endrep +- %endif +- +- %assign %%i 0 +- %rep %0 +- %xdefine %1q r %+ %%i %+ q +- %xdefine %1d r %+ %%i %+ d +- %xdefine %1w r %+ %%i %+ w +- %xdefine %1b r %+ %%i %+ b +- %xdefine %1m r %+ %%i %+ m +- CAT_XDEFINE arg_name, %%i, %1 +- %assign %%i %%i+1 +- %rotate 1 +- %endrep +- %assign n_arg_names %%i +-%endmacro +- +-%ifdef WIN64 ; Windows x64 ;================================================= +- +-DECLARE_REG 0, rcx, ecx, cx, cl, ecx +-DECLARE_REG 1, rdx, edx, dx, dl, edx +-DECLARE_REG 2, r8, r8d, r8w, r8b, r8d +-DECLARE_REG 3, r9, r9d, r9w, r9b, r9d +-DECLARE_REG 4, rdi, edi, di, dil, [rsp + stack_offset + 40] +-DECLARE_REG 5, rsi, esi, si, sil, [rsp + stack_offset + 48] +-DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 56] +-%define r7m [rsp + stack_offset + 64] +-%define r8m [rsp + stack_offset + 72] +- +-%macro LOAD_IF_USED 2 ; reg_id, number_of_args +- %if %1 < %2 +- mov r%1, [rsp + stack_offset + 8 + %1*8] +- %endif +-%endmacro +- +-%macro PROLOGUE 2-4+ 0 ; #args, #regs, #xmm_regs, arg_names... +- ASSERT %2 >= %1 +- %assign regs_used %2 +- ASSERT regs_used <= 7 +- %if regs_used > 4 +- push r4 +- push r5 +- %assign stack_offset stack_offset+16 +- %endif +- WIN64_SPILL_XMM %3 +- LOAD_IF_USED 4, %1 +- LOAD_IF_USED 5, %1 +- LOAD_IF_USED 6, %1 +- DEFINE_ARGS %4 +-%endmacro +- +-%macro WIN64_SPILL_XMM 1 +- %assign xmm_regs_used %1 +- ASSERT xmm_regs_used <= 16 +- %if xmm_regs_used > 6 +- sub rsp, (xmm_regs_used-6)*16+16 +- %assign stack_offset stack_offset+(xmm_regs_used-6)*16+16 +- %assign %%i xmm_regs_used +- %rep (xmm_regs_used-6) +- %assign %%i %%i-1 +- movdqa [rsp + (%%i-6)*16+8], xmm %+ %%i +- %endrep +- %endif +-%endmacro +- +-%macro WIN64_RESTORE_XMM_INTERNAL 1 +- %if xmm_regs_used > 6 +- %assign %%i xmm_regs_used +- %rep (xmm_regs_used-6) +- %assign %%i %%i-1 +- movdqa xmm %+ %%i, [%1 + (%%i-6)*16+8] +- %endrep +- add %1, (xmm_regs_used-6)*16+16 +- %endif +-%endmacro +- +-%macro WIN64_RESTORE_XMM 1 +- WIN64_RESTORE_XMM_INTERNAL %1 +- %assign stack_offset stack_offset-(xmm_regs_used-6)*16+16 +- %assign xmm_regs_used 0 +-%endmacro +- +-%macro RET 0 +- WIN64_RESTORE_XMM_INTERNAL rsp +- %if regs_used > 4 +- pop r5 +- pop r4 +- %endif +- ret +-%endmacro +- +-%macro REP_RET 0 +- %if regs_used > 4 || xmm_regs_used > 6 +- RET +- %else +- rep ret +- %endif +-%endmacro +- +-%elifdef ARCH_X86_64 ; *nix x64 ;============================================= +- +-DECLARE_REG 0, rdi, edi, di, dil, edi +-DECLARE_REG 1, rsi, esi, si, sil, esi +-DECLARE_REG 2, rdx, edx, dx, dl, edx +-DECLARE_REG 3, rcx, ecx, cx, cl, ecx +-DECLARE_REG 4, r8, r8d, r8w, r8b, r8d +-DECLARE_REG 5, r9, r9d, r9w, r9b, r9d +-DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 8] +-%define r7m [rsp + stack_offset + 16] +-%define r8m [rsp + stack_offset + 24] +- +-%macro LOAD_IF_USED 2 ; reg_id, number_of_args +- %if %1 < %2 +- mov r%1, [rsp - 40 + %1*8] +- %endif +-%endmacro +- +-%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names... +- ASSERT %2 >= %1 +- ASSERT %2 <= 7 +- LOAD_IF_USED 6, %1 +- DEFINE_ARGS %4 +-%endmacro +- +-%macro RET 0 +- ret +-%endmacro +- +-%macro REP_RET 0 +- rep ret +-%endmacro +- +-%else ; X86_32 ;============================================================== +- +-DECLARE_REG 0, eax, eax, ax, al, [esp + stack_offset + 4] +-DECLARE_REG 1, ecx, ecx, cx, cl, [esp + stack_offset + 8] +-DECLARE_REG 2, edx, edx, dx, dl, [esp + stack_offset + 12] +-DECLARE_REG 3, ebx, ebx, bx, bl, [esp + stack_offset + 16] +-DECLARE_REG 4, esi, esi, si, null, [esp + stack_offset + 20] +-DECLARE_REG 5, edi, edi, di, null, [esp + stack_offset + 24] +-DECLARE_REG 6, ebp, ebp, bp, null, [esp + stack_offset + 28] +-%define r7m [esp + stack_offset + 32] +-%define r8m [esp + stack_offset + 36] +-%define rsp esp +- +-%macro PUSH_IF_USED 1 ; reg_id +- %if %1 < regs_used +- push r%1 +- %assign stack_offset stack_offset+4 +- %endif +-%endmacro +- +-%macro POP_IF_USED 1 ; reg_id +- %if %1 < regs_used +- pop r%1 +- %endif +-%endmacro +- +-%macro LOAD_IF_USED 2 ; reg_id, number_of_args +- %if %1 < %2 +- mov r%1, [esp + stack_offset + 4 + %1*4] +- %endif +-%endmacro +- +-%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names... +- ASSERT %2 >= %1 +- %assign regs_used %2 +- ASSERT regs_used <= 7 +- PUSH_IF_USED 3 +- PUSH_IF_USED 4 +- PUSH_IF_USED 5 +- PUSH_IF_USED 6 +- LOAD_IF_USED 0, %1 +- LOAD_IF_USED 1, %1 +- LOAD_IF_USED 2, %1 +- LOAD_IF_USED 3, %1 +- LOAD_IF_USED 4, %1 +- LOAD_IF_USED 5, %1 +- LOAD_IF_USED 6, %1 +- DEFINE_ARGS %4 +-%endmacro +- +-%macro RET 0 +- POP_IF_USED 6 +- POP_IF_USED 5 +- POP_IF_USED 4 +- POP_IF_USED 3 +- ret +-%endmacro +- +-%macro REP_RET 0 +- %if regs_used > 3 +- RET +- %else +- rep ret +- %endif +-%endmacro +- +-%endif ;====================================================================== +- +-%ifndef WIN64 +-%macro WIN64_SPILL_XMM 1 +-%endmacro +-%macro WIN64_RESTORE_XMM 1 +-%endmacro +-%endif +- +- +- +-;============================================================================= +-; arch-independent part +-;============================================================================= +- +-%assign function_align 16 +- +-; Symbol prefix for C linkage +-%macro cglobal 1-2+ +- %xdefine %1 mangle(program_name %+ _ %+ %1) +- %xdefine %1.skip_prologue %1 %+ .skip_prologue +- %ifidn __OUTPUT_FORMAT__,elf +- global %1:function hidden +- %else +- global %1 +- %endif +- align function_align +- %1: +- RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer +- %assign stack_offset 0 +- %if %0 > 1 +- PROLOGUE %2 +- %endif +-%endmacro +- +-%macro cextern 1 +- %xdefine %1 mangle(program_name %+ _ %+ %1) +- extern %1 +-%endmacro +- +-;like cextern, but without the prefix +-%macro cextern_naked 1 +- %xdefine %1 mangle(%1) +- extern %1 +-%endmacro +- +-%macro const 2+ +- %xdefine %1 mangle(program_name %+ _ %+ %1) +- global %1 +- %1: %2 +-%endmacro +- +-; This is needed for ELF, otherwise the GNU linker assumes the stack is +-; executable by default. +-%ifidn __OUTPUT_FORMAT__,elf +-SECTION .note.GNU-stack noalloc noexec nowrite progbits +-%endif +- +-; merge mmx and sse* +- +-%macro CAT_XDEFINE 3 +- %xdefine %1%2 %3 +-%endmacro +- +-%macro CAT_UNDEF 2 +- %undef %1%2 +-%endmacro +- +-%macro INIT_MMX 0 +- %define RESET_MM_PERMUTATION INIT_MMX +- %define mmsize 8 +- %define num_mmregs 8 +- %define mova movq +- %define movu movq +- %define movh movd +- %define movnta movntq +- %assign %%i 0 +- %rep 8 +- CAT_XDEFINE m, %%i, mm %+ %%i +- CAT_XDEFINE nmm, %%i, %%i +- %assign %%i %%i+1 +- %endrep +- %rep 8 +- CAT_UNDEF m, %%i +- CAT_UNDEF nmm, %%i +- %assign %%i %%i+1 +- %endrep +-%endmacro +- +-%macro INIT_XMM 0 +- %define RESET_MM_PERMUTATION INIT_XMM +- %define mmsize 16 +- %define num_mmregs 8 +- %ifdef ARCH_X86_64 +- %define num_mmregs 16 +- %endif +- %define mova movdqa +- %define movu movdqu +- %define movh movq +- %define movnta movntdq +- %assign %%i 0 +- %rep num_mmregs +- CAT_XDEFINE m, %%i, xmm %+ %%i +- CAT_XDEFINE nxmm, %%i, %%i +- %assign %%i %%i+1 +- %endrep +-%endmacro +- +-INIT_MMX +- +-; I often want to use macros that permute their arguments. e.g. there's no +-; efficient way to implement butterfly or transpose or dct without swapping some +-; arguments. +-; +-; I would like to not have to manually keep track of the permutations: +-; If I insert a permutation in the middle of a function, it should automatically +-; change everything that follows. For more complex macros I may also have multiple +-; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations. +-; +-; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that +-; permutes its arguments. It's equivalent to exchanging the contents of the +-; registers, except that this way you exchange the register names instead, so it +-; doesn't cost any cycles. +- +-%macro PERMUTE 2-* ; takes a list of pairs to swap +-%rep %0/2 +- %xdefine tmp%2 m%2 +- %xdefine ntmp%2 nm%2 +- %rotate 2 +-%endrep +-%rep %0/2 +- %xdefine m%1 tmp%2 +- %xdefine nm%1 ntmp%2 +- %undef tmp%2 +- %undef ntmp%2 +- %rotate 2 +-%endrep +-%endmacro +- +-%macro SWAP 2-* ; swaps a single chain (sometimes more concise than pairs) +-%rep %0-1 +-%ifdef m%1 +- %xdefine tmp m%1 +- %xdefine m%1 m%2 +- %xdefine m%2 tmp +- CAT_XDEFINE n, m%1, %1 +- CAT_XDEFINE n, m%2, %2 +-%else +- ; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here. +- ; Be careful using this mode in nested macros though, as in some cases there may be +- ; other copies of m# that have already been dereferenced and don't get updated correctly. +- %xdefine %%n1 n %+ %1 +- %xdefine %%n2 n %+ %2 +- %xdefine tmp m %+ %%n1 +- CAT_XDEFINE m, %%n1, m %+ %%n2 +- CAT_XDEFINE m, %%n2, tmp +- CAT_XDEFINE n, m %+ %%n1, %%n1 +- CAT_XDEFINE n, m %+ %%n2, %%n2 +-%endif +- %undef tmp +- %rotate 1 +-%endrep +-%endmacro +- +-; If SAVE_MM_PERMUTATION is placed at the end of a function and given the +-; function name, then any later calls to that function will automatically +-; load the permutation, so values can be returned in mmregs. +-%macro SAVE_MM_PERMUTATION 1 ; name to save as +- %assign %%i 0 +- %rep num_mmregs +- CAT_XDEFINE %1_m, %%i, m %+ %%i +- %assign %%i %%i+1 +- %endrep +-%endmacro +- +-%macro LOAD_MM_PERMUTATION 1 ; name to load from +- %assign %%i 0 +- %rep num_mmregs +- CAT_XDEFINE m, %%i, %1_m %+ %%i +- CAT_XDEFINE n, m %+ %%i, %%i +- %assign %%i %%i+1 +- %endrep +-%endmacro +- +-%macro call 1 +- call %1 +- %ifdef %1_m0 +- LOAD_MM_PERMUTATION %1 +- %endif +-%endmacro +- +-; Substitutions that reduce instruction size but are functionally equivalent +-%macro add 2 +- %ifnum %2 +- %if %2==128 +- sub %1, -128 +- %else +- add %1, %2 +- %endif +- %else +- add %1, %2 +- %endif +-%endmacro +- +-%macro sub 2 +- %ifnum %2 +- %if %2==128 +- add %1, -128 +- %else +- sub %1, %2 +- %endif +- %else +- sub %1, %2 +- %endif +-%endmacro +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/x86util.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/x86util.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/x86/x86util.asm 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/x86/x86util.asm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,436 +0,0 @@ +-;***************************************************************************** +-;* x86util.asm +-;***************************************************************************** +-;* Copyright (C) 2008-2010 x264 project +-;* +-;* Authors: Loren Merritt +-;* Holger Lubitz +-;* +-;* This file is part of FFmpeg. +-;* +-;* FFmpeg is free software; you can redistribute it and/or +-;* modify it under the terms of the GNU Lesser General Public +-;* License as published by the Free Software Foundation; either +-;* version 2.1 of the License, or (at your option) any later version. +-;* +-;* FFmpeg 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 +-;* Lesser General Public License for more details. +-;* +-;* You should have received a copy of the GNU Lesser General Public +-;* License along with FFmpeg; if not, write to the Free Software +-;* 51, Inc., Foundation Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +-;****************************************************************************** +- +-%macro SBUTTERFLY 4 +- mova m%4, m%2 +- punpckl%1 m%2, m%3 +- punpckh%1 m%4, m%3 +- SWAP %3, %4 +-%endmacro +- +-%macro SBUTTERFLY2 4 +- mova m%4, m%2 +- punpckh%1 m%2, m%3 +- punpckl%1 m%4, m%3 +- SWAP %2, %4, %3 +-%endmacro +- +-%macro TRANSPOSE4x4B 5 +- SBUTTERFLY bw, %1, %2, %5 +- SBUTTERFLY bw, %3, %4, %5 +- SBUTTERFLY wd, %1, %3, %5 +- SBUTTERFLY wd, %2, %4, %5 +- SWAP %2, %3 +-%endmacro +- +-%macro TRANSPOSE4x4W 5 +- SBUTTERFLY wd, %1, %2, %5 +- SBUTTERFLY wd, %3, %4, %5 +- SBUTTERFLY dq, %1, %3, %5 +- SBUTTERFLY dq, %2, %4, %5 +- SWAP %2, %3 +-%endmacro +- +-%macro TRANSPOSE2x4x4W 5 +- SBUTTERFLY wd, %1, %2, %5 +- SBUTTERFLY wd, %3, %4, %5 +- SBUTTERFLY dq, %1, %3, %5 +- SBUTTERFLY dq, %2, %4, %5 +- SBUTTERFLY qdq, %1, %2, %5 +- SBUTTERFLY qdq, %3, %4, %5 +-%endmacro +- +-%macro TRANSPOSE4x4D 5 +- SBUTTERFLY dq, %1, %2, %5 +- SBUTTERFLY dq, %3, %4, %5 +- SBUTTERFLY qdq, %1, %3, %5 +- SBUTTERFLY qdq, %2, %4, %5 +- SWAP %2, %3 +-%endmacro +- +-%macro TRANSPOSE8x8W 9-11 +-%ifdef ARCH_X86_64 +- SBUTTERFLY wd, %1, %2, %9 +- SBUTTERFLY wd, %3, %4, %9 +- SBUTTERFLY wd, %5, %6, %9 +- SBUTTERFLY wd, %7, %8, %9 +- SBUTTERFLY dq, %1, %3, %9 +- SBUTTERFLY dq, %2, %4, %9 +- SBUTTERFLY dq, %5, %7, %9 +- SBUTTERFLY dq, %6, %8, %9 +- SBUTTERFLY qdq, %1, %5, %9 +- SBUTTERFLY qdq, %2, %6, %9 +- SBUTTERFLY qdq, %3, %7, %9 +- SBUTTERFLY qdq, %4, %8, %9 +- SWAP %2, %5 +- SWAP %4, %7 +-%else +-; in: m0..m7, unless %11 in which case m6 is in %9 +-; out: m0..m7, unless %11 in which case m4 is in %10 +-; spills into %9 and %10 +-%if %0<11 +- movdqa %9, m%7 +-%endif +- SBUTTERFLY wd, %1, %2, %7 +- movdqa %10, m%2 +- movdqa m%7, %9 +- SBUTTERFLY wd, %3, %4, %2 +- SBUTTERFLY wd, %5, %6, %2 +- SBUTTERFLY wd, %7, %8, %2 +- SBUTTERFLY dq, %1, %3, %2 +- movdqa %9, m%3 +- movdqa m%2, %10 +- SBUTTERFLY dq, %2, %4, %3 +- SBUTTERFLY dq, %5, %7, %3 +- SBUTTERFLY dq, %6, %8, %3 +- SBUTTERFLY qdq, %1, %5, %3 +- SBUTTERFLY qdq, %2, %6, %3 +- movdqa %10, m%2 +- movdqa m%3, %9 +- SBUTTERFLY qdq, %3, %7, %2 +- SBUTTERFLY qdq, %4, %8, %2 +- SWAP %2, %5 +- SWAP %4, %7 +-%if %0<11 +- movdqa m%5, %10 +-%endif +-%endif +-%endmacro +- +-; PABSW macros assume %1 != %2, while ABS1/2 macros work in-place +-%macro PABSW_MMX 2 +- pxor %1, %1 +- pcmpgtw %1, %2 +- pxor %2, %1 +- psubw %2, %1 +- SWAP %1, %2 +-%endmacro +- +-%macro PSIGNW_MMX 2 +- pxor %1, %2 +- psubw %1, %2 +-%endmacro +- +-%macro PABSW_MMX2 2 +- pxor %1, %1 +- psubw %1, %2 +- pmaxsw %1, %2 +-%endmacro +- +-%macro PABSW_SSSE3 2 +- pabsw %1, %2 +-%endmacro +- +-%macro PSIGNW_SSSE3 2 +- psignw %1, %2 +-%endmacro +- +-%macro ABS1_MMX 2 ; a, tmp +- pxor %2, %2 +- pcmpgtw %2, %1 +- pxor %1, %2 +- psubw %1, %2 +-%endmacro +- +-%macro ABS2_MMX 4 ; a, b, tmp0, tmp1 +- pxor %3, %3 +- pxor %4, %4 +- pcmpgtw %3, %1 +- pcmpgtw %4, %2 +- pxor %1, %3 +- pxor %2, %4 +- psubw %1, %3 +- psubw %2, %4 +-%endmacro +- +-%macro ABS1_MMX2 2 ; a, tmp +- pxor %2, %2 +- psubw %2, %1 +- pmaxsw %1, %2 +-%endmacro +- +-%macro ABS2_MMX2 4 ; a, b, tmp0, tmp1 +- pxor %3, %3 +- pxor %4, %4 +- psubw %3, %1 +- psubw %4, %2 +- pmaxsw %1, %3 +- pmaxsw %2, %4 +-%endmacro +- +-%macro ABS1_SSSE3 2 +- pabsw %1, %1 +-%endmacro +- +-%macro ABS2_SSSE3 4 +- pabsw %1, %1 +- pabsw %2, %2 +-%endmacro +- +-%macro ABSB_MMX 2 +- pxor %2, %2 +- psubb %2, %1 +- pminub %1, %2 +-%endmacro +- +-%macro ABSB2_MMX 4 +- pxor %3, %3 +- pxor %4, %4 +- psubb %3, %1 +- psubb %4, %2 +- pminub %1, %3 +- pminub %2, %4 +-%endmacro +- +-%macro ABSB_SSSE3 2 +- pabsb %1, %1 +-%endmacro +- +-%macro ABSB2_SSSE3 4 +- pabsb %1, %1 +- pabsb %2, %2 +-%endmacro +- +-%macro ABS4 6 +- ABS2 %1, %2, %5, %6 +- ABS2 %3, %4, %5, %6 +-%endmacro +- +-%define ABS1 ABS1_MMX +-%define ABS2 ABS2_MMX +-%define ABSB ABSB_MMX +-%define ABSB2 ABSB2_MMX +- +-%macro SPLATB_MMX 3 +- movd %1, [%2-3] ;to avoid crossing a cacheline +- punpcklbw %1, %1 +-%if mmsize==16 +- pshuflw %1, %1, 0xff +- punpcklqdq %1, %1 +-%else +- pshufw %1, %1, 0xff +-%endif +-%endmacro +- +-%macro SPLATB_SSSE3 3 +- movd %1, [%2-3] +- pshufb %1, %3 +-%endmacro +- +-%macro PALIGNR_MMX 4 +- %ifnidn %4, %2 +- mova %4, %2 +- %endif +- %if mmsize == 8 +- psllq %1, (8-%3)*8 +- psrlq %4, %3*8 +- %else +- pslldq %1, 16-%3 +- psrldq %4, %3 +- %endif +- por %1, %4 +-%endmacro +- +-%macro PALIGNR_SSSE3 4 +- palignr %1, %2, %3 +-%endmacro +- +-%macro DEINTB 5 ; mask, reg1, mask, reg2, optional src to fill masks from +-%ifnum %5 +- mova m%1, m%5 +- mova m%3, m%5 +-%else +- mova m%1, %5 +- mova m%3, m%1 +-%endif +- pand m%1, m%2 ; dst .. y6 .. y4 +- pand m%3, m%4 ; src .. y6 .. y4 +- psrlw m%2, 8 ; dst .. y7 .. y5 +- psrlw m%4, 8 ; src .. y7 .. y5 +-%endmacro +- +-%macro SUMSUB_BA 2-3 +-%if %0==2 +- paddw %1, %2 +- paddw %2, %2 +- psubw %2, %1 +-%else +- mova %3, %1 +- paddw %1, %2 +- psubw %2, %3 +-%endif +-%endmacro +- +-%macro SUMSUB_BADC 4-5 +-%if %0==5 +- SUMSUB_BA %1, %2, %5 +- SUMSUB_BA %3, %4, %5 +-%else +- paddw %1, %2 +- paddw %3, %4 +- paddw %2, %2 +- paddw %4, %4 +- psubw %2, %1 +- psubw %4, %3 +-%endif +-%endmacro +- +-%macro SUMSUB2_AB 3 +- mova %3, %1 +- paddw %1, %1 +- paddw %1, %2 +- psubw %3, %2 +- psubw %3, %2 +-%endmacro +- +-%macro SUMSUB2_BA 3 +- mova m%3, m%1 +- paddw m%1, m%2 +- paddw m%1, m%2 +- psubw m%2, m%3 +- psubw m%2, m%3 +-%endmacro +- +-%macro SUMSUBD2_AB 4 +- mova %4, %1 +- mova %3, %2 +- psraw %2, 1 ; %2: %2>>1 +- psraw %1, 1 ; %1: %1>>1 +- paddw %2, %4 ; %2: %2>>1+%1 +- psubw %1, %3 ; %1: %1>>1-%2 +-%endmacro +- +-%macro DCT4_1D 5 +-%ifnum %5 +- SUMSUB_BADC m%4, m%1, m%3, m%2; m%5 +- SUMSUB_BA m%3, m%4, m%5 +- SUMSUB2_AB m%1, m%2, m%5 +- SWAP %1, %3, %4, %5, %2 +-%else +- SUMSUB_BADC m%4, m%1, m%3, m%2 +- SUMSUB_BA m%3, m%4 +- mova [%5], m%2 +- SUMSUB2_AB m%1, [%5], m%2 +- SWAP %1, %3, %4, %2 +-%endif +-%endmacro +- +-%macro IDCT4_1D 5-6 +-%ifnum %5 +- SUMSUBD2_AB m%2, m%4, m%6, m%5 +- ; %2: %2>>1-%4 %4: %2+%4>>1 +- SUMSUB_BA m%3, m%1, m%6 +- ; %3: %1+%3 %1: %1-%3 +- SUMSUB_BADC m%4, m%3, m%2, m%1, m%6 +- ; %4: %1+%3 + (%2+%4>>1) +- ; %3: %1+%3 - (%2+%4>>1) +- ; %2: %1-%3 + (%2>>1-%4) +- ; %1: %1-%3 - (%2>>1-%4) +-%else +- SUMSUBD2_AB m%2, m%4, [%5], [%5+16] +- SUMSUB_BA m%3, m%1 +- SUMSUB_BADC m%4, m%3, m%2, m%1 +-%endif +- SWAP %1, %4, %3 +- ; %1: %1+%3 + (%2+%4>>1) row0 +- ; %2: %1-%3 + (%2>>1-%4) row1 +- ; %3: %1-%3 - (%2>>1-%4) row2 +- ; %4: %1+%3 - (%2+%4>>1) row3 +-%endmacro +- +- +-%macro LOAD_DIFF 5 +-%ifidn %3, none +- movh %1, %4 +- movh %2, %5 +- punpcklbw %1, %2 +- punpcklbw %2, %2 +- psubw %1, %2 +-%else +- movh %1, %4 +- punpcklbw %1, %3 +- movh %2, %5 +- punpcklbw %2, %3 +- psubw %1, %2 +-%endif +-%endmacro +- +-%macro STORE_DCT 6 +- movq [%5+%6+ 0], m%1 +- movq [%5+%6+ 8], m%2 +- movq [%5+%6+16], m%3 +- movq [%5+%6+24], m%4 +- movhps [%5+%6+32], m%1 +- movhps [%5+%6+40], m%2 +- movhps [%5+%6+48], m%3 +- movhps [%5+%6+56], m%4 +-%endmacro +- +-%macro LOAD_DIFF_8x4P 7-10 r0,r2,0 ; 4x dest, 2x temp, 2x pointer, increment? +- LOAD_DIFF m%1, m%5, m%7, [%8], [%9] +- LOAD_DIFF m%2, m%6, m%7, [%8+r1], [%9+r3] +- LOAD_DIFF m%3, m%5, m%7, [%8+2*r1], [%9+2*r3] +- LOAD_DIFF m%4, m%6, m%7, [%8+r4], [%9+r5] +-%if %10 +- lea %8, [%8+4*r1] +- lea %9, [%9+4*r3] +-%endif +-%endmacro +- +-%macro DIFFx2 6-7 +- movh %3, %5 +- punpcklbw %3, %4 +- psraw %1, 6 +- paddsw %1, %3 +- movh %3, %6 +- punpcklbw %3, %4 +- psraw %2, 6 +- paddsw %2, %3 +- packuswb %2, %1 +-%endmacro +- +-%macro STORE_DIFF 4 +- movh %2, %4 +- punpcklbw %2, %3 +- psraw %1, 6 +- paddsw %1, %2 +- packuswb %1, %1 +- movh %4, %1 +-%endmacro +- +-%macro STORE_DIFFx2 8 ; add1, add2, reg1, reg2, zero, shift, source, stride +- movh %3, [%7] +- movh %4, [%7+%8] +- punpcklbw %3, %5 +- punpcklbw %4, %5 +- psraw %1, %6 +- psraw %2, %6 +- paddw %3, %1 +- paddw %4, %2 +- packuswb %3, %5 +- packuswb %4, %5 +- movh [%7], %3 +- movh [%7+%8], %4 +-%endmacro +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xan.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xan.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xan.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xan.c 2012-05-14 14:08:54.596345255 +0200 +@@ -35,7 +35,7 @@ + #include "libavutil/intreadwrite.h" + #include "avcodec.h" + #include "bytestream.h" +-#define ALT_BITSTREAM_READER_LE ++#define BITSTREAM_READER_LE + #include "get_bits.h" + // for av_memcpy_backptr + #include "libavutil/lzo.h" +@@ -91,26 +91,35 @@ + av_freep(&s->buffer1); + return AVERROR(ENOMEM); + } ++ avcodec_get_frame_defaults(&s->last_frame); ++ avcodec_get_frame_defaults(&s->current_frame); + + return 0; + } + +-static int xan_huffman_decode(unsigned char *dest, const unsigned char *src, +- int dest_len) ++static int xan_huffman_decode(unsigned char *dest, int dest_len, ++ const unsigned char *src, int src_len) + { + unsigned char byte = *src++; + unsigned char ival = byte + 0x16; + const unsigned char * ptr = src + byte*2; ++ int ptr_len = src_len - 1 - byte*2; + unsigned char val = ival; + unsigned char *dest_end = dest + dest_len; + GetBitContext gb; + +- init_get_bits(&gb, ptr, 0); // FIXME: no src size available ++ if (ptr_len < 0) ++ return AVERROR_INVALIDDATA; + +- while ( val != 0x16 ) { +- val = src[val - 0x17 + get_bits1(&gb) * byte]; ++ init_get_bits(&gb, ptr, ptr_len * 8); + +- if ( val < 0x16 ) { ++ while (val != 0x16) { ++ unsigned idx = val - 0x17 + get_bits1(&gb) * byte; ++ if (idx >= 2 * byte) ++ return -1; ++ val = src[idx]; ++ ++ if (val < 0x16) { + if (dest >= dest_end) + return 0; + *dest++ = val; +@@ -126,40 +135,41 @@ + * + * @param dest destination buffer of dest_len, must be padded with at least 130 bytes + */ +-static void xan_unpack(unsigned char *dest, const unsigned char *src, int dest_len) ++static void xan_unpack(unsigned char *dest, int dest_len, ++ const unsigned char *src, int src_len) + { + unsigned char opcode; + int size; ++ unsigned char *dest_org = dest; + unsigned char *dest_end = dest + dest_len; ++ const unsigned char *src_end = src + src_len; + +- while (dest < dest_end) { ++ while (dest < dest_end && src < src_end) { + opcode = *src++; + + if (opcode < 0xe0) { + int size2, back; +- if ( (opcode & 0x80) == 0 ) { +- ++ if ((opcode & 0x80) == 0) { + size = opcode & 3; + + back = ((opcode & 0x60) << 3) + *src++ + 1; + size2 = ((opcode & 0x1c) >> 2) + 3; +- +- } else if ( (opcode & 0x40) == 0 ) { +- ++ } else if ((opcode & 0x40) == 0) { + size = *src >> 6; + + back = (bytestream_get_be16(&src) & 0x3fff) + 1; + size2 = (opcode & 0x3f) + 4; +- + } else { +- + size = opcode & 3; + + back = ((opcode & 0x10) << 12) + bytestream_get_be16(&src) + 1; + size2 = ((opcode & 0x0c) << 6) + *src++ + 5; +- if (size + size2 > dest_end - dest) +- return; + } ++ ++ if (dest_end - dest < size + size2 || ++ dest + size - dest_org < back || ++ src_end - src < size) ++ return; + memcpy(dest, src, size); dest += size; src += size; + av_memcpy_backptr(dest, back, size2); + dest += size2; +@@ -167,6 +177,8 @@ + int finish = opcode >= 0xfc; + size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4; + ++ if (dest_end - dest < size || src_end - src < size) ++ return; + memcpy(dest, src, size); dest += size; src += size; + if (finish) + return; +@@ -189,7 +201,7 @@ + line_inc = stride - width; + index = y * stride + x; + current_x = x; +- while(pixel_count && (index < s->frame_size)) { ++ while (pixel_count && index < s->frame_size) { + int count = FFMIN(pixel_count, width - current_x); + memcpy(palette_plane + index, pixel_buffer, count); + pixel_count -= count; +@@ -204,8 +216,9 @@ + } + } + +-static inline void xan_wc3_copy_pixel_run(XanContext *s, +- int x, int y, int pixel_count, int motion_x, int motion_y) ++static inline void xan_wc3_copy_pixel_run(XanContext *s, int x, int y, ++ int pixel_count, int motion_x, ++ int motion_y) + { + int stride; + int line_inc; +@@ -214,18 +227,28 @@ + int width = s->avctx->width; + unsigned char *palette_plane, *prev_palette_plane; + ++ if (y + motion_y < 0 || y + motion_y >= s->avctx->height || ++ x + motion_x < 0 || x + motion_x >= s->avctx->width) ++ return; ++ + palette_plane = s->current_frame.data[0]; + prev_palette_plane = s->last_frame.data[0]; ++ if (!prev_palette_plane) ++ prev_palette_plane = palette_plane; + stride = s->current_frame.linesize[0]; + line_inc = stride - width; + curframe_index = y * stride + x; + curframe_x = x; + prevframe_index = (y + motion_y) * stride + x + motion_x; + prevframe_x = x + motion_x; +- while(pixel_count && (curframe_index < s->frame_size)) { +- int count = FFMIN3(pixel_count, width - curframe_x, width - prevframe_x); ++ while (pixel_count && ++ curframe_index < s->frame_size && ++ prevframe_index < s->frame_size) { ++ int count = FFMIN3(pixel_count, width - curframe_x, ++ width - prevframe_x); + +- memcpy(palette_plane + curframe_index, prev_palette_plane + prevframe_index, count); ++ memcpy(palette_plane + curframe_index, ++ prev_palette_plane + prevframe_index, count); + pixel_count -= count; + curframe_index += count; + prevframe_index += count; +@@ -244,9 +267,9 @@ + } + } + +-static void xan_wc3_decode_frame(XanContext *s) { ++static int xan_wc3_decode_frame(XanContext *s) { + +- int width = s->avctx->width; ++ int width = s->avctx->width; + int height = s->avctx->height; + int total_pixels = width * height; + unsigned char opcode; +@@ -256,6 +279,7 @@ + int x, y; + + unsigned char *opcode_buffer = s->buffer1; ++ unsigned char *opcode_buffer_end = s->buffer1 + s->buffer1_size; + int opcode_buffer_size = s->buffer1_size; + const unsigned char *imagedata_buffer = s->buffer2; + +@@ -264,22 +288,44 @@ + const unsigned char *size_segment; + const unsigned char *vector_segment; + const unsigned char *imagedata_segment; ++ int huffman_offset, size_offset, vector_offset, imagedata_offset, ++ imagedata_size; ++ ++ if (s->size < 8) ++ return AVERROR_INVALIDDATA; + +- huffman_segment = s->buf + AV_RL16(&s->buf[0]); +- size_segment = s->buf + AV_RL16(&s->buf[2]); +- vector_segment = s->buf + AV_RL16(&s->buf[4]); +- imagedata_segment = s->buf + AV_RL16(&s->buf[6]); +- +- xan_huffman_decode(opcode_buffer, huffman_segment, opcode_buffer_size); +- +- if (imagedata_segment[0] == 2) +- xan_unpack(s->buffer2, &imagedata_segment[1], s->buffer2_size); +- else ++ huffman_offset = AV_RL16(&s->buf[0]); ++ size_offset = AV_RL16(&s->buf[2]); ++ vector_offset = AV_RL16(&s->buf[4]); ++ imagedata_offset = AV_RL16(&s->buf[6]); ++ ++ if (huffman_offset >= s->size || ++ size_offset >= s->size || ++ vector_offset >= s->size || ++ imagedata_offset >= s->size) ++ return AVERROR_INVALIDDATA; ++ ++ huffman_segment = s->buf + huffman_offset; ++ size_segment = s->buf + size_offset; ++ vector_segment = s->buf + vector_offset; ++ imagedata_segment = s->buf + imagedata_offset; ++ ++ if (xan_huffman_decode(opcode_buffer, opcode_buffer_size, ++ huffman_segment, s->size - huffman_offset) < 0) ++ return AVERROR_INVALIDDATA; ++ ++ if (imagedata_segment[0] == 2) { ++ xan_unpack(s->buffer2, s->buffer2_size, ++ &imagedata_segment[1], s->size - imagedata_offset - 1); ++ imagedata_size = s->buffer2_size; ++ } else { ++ imagedata_size = s->size - imagedata_offset - 1; + imagedata_buffer = &imagedata_segment[1]; ++ } + + /* use the decoded data segments to build the frame */ + x = y = 0; +- while (total_pixels) { ++ while (total_pixels && opcode_buffer < opcode_buffer_end) { + + opcode = *opcode_buffer++; + size = 0; +@@ -329,6 +375,9 @@ + break; + } + ++ if (size > total_pixels) ++ break; ++ + if (opcode < 12) { + flag ^= 1; + if (flag) { +@@ -336,8 +385,11 @@ + xan_wc3_copy_pixel_run(s, x, y, size, 0, 0); + } else { + /* output a run of pixels from imagedata_buffer */ ++ if (imagedata_size < size) ++ break; + xan_wc3_output_pixel_run(s, imagedata_buffer, x, y, size); + imagedata_buffer += size; ++ imagedata_size -= size; + } + } else { + /* run-based motion compensation from last frame */ +@@ -356,9 +408,7 @@ + y += (x + size) / width; + x = (x + size) % width; + } +-} +- +-static void xan_wc4_decode_frame(XanContext *s) { ++ return 0; + } + + #if RUNTIME_GAMMA +@@ -469,7 +519,8 @@ + return AVERROR_INVALIDDATA; + if (s->palettes_count >= PALETTES_MAX) + return AVERROR_INVALIDDATA; +- tmpptr = av_realloc(s->palettes, (s->palettes_count + 1) * AVPALETTE_SIZE); ++ tmpptr = av_realloc(s->palettes, ++ (s->palettes_count + 1) * AVPALETTE_SIZE); + if (!tmpptr) + return AVERROR(ENOMEM); + s->palettes = tmpptr; +@@ -484,7 +535,7 @@ + int g = gamma_lookup[*buf++]; + int b = gamma_lookup[*buf++]; + #endif +- *tmpptr++ = (r << 16) | (g << 8) | b; ++ *tmpptr++ = (0xFFU << 24) | (r << 16) | (g << 8) | b; + } + s->palettes_count++; + break; +@@ -506,6 +557,11 @@ + } + buf_size = buf_end - buf; + } ++ if (s->palettes_count <= 0) { ++ av_log(s->avctx, AV_LOG_ERROR, "No palette found\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ + if ((ret = avctx->get_buffer(avctx, &s->current_frame))) { + av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; +@@ -515,23 +571,14 @@ + if (!s->frame_size) + s->frame_size = s->current_frame.linesize[0] * s->avctx->height; + +- if (avctx->codec->id == CODEC_ID_XAN_WC3) { +- memcpy(s->current_frame.data[1], s->palettes + s->cur_palette * AVPALETTE_COUNT, AVPALETTE_SIZE); +- } else { +- AVPaletteControl *palette_control = avctx->palctrl; +- palette_control->palette_changed = 0; +- memcpy(s->current_frame.data[1], palette_control->palette, +- AVPALETTE_SIZE); +- s->current_frame.palette_has_changed = 1; +- } ++ memcpy(s->current_frame.data[1], ++ s->palettes + s->cur_palette * AVPALETTE_COUNT, AVPALETTE_SIZE); + + s->buf = buf; + s->size = buf_size; + +- if (avctx->codec->id == CODEC_ID_XAN_WC3) +- xan_wc3_decode_frame(s); +- else if (avctx->codec->id == CODEC_ID_XAN_WC4) +- xan_wc4_decode_frame(s); ++ if (xan_wc3_decode_frame(s) < 0) ++ return AVERROR_INVALIDDATA; + + /* release the last frame if it is allocated */ + if (s->last_frame.data[0]) +@@ -565,29 +612,13 @@ + } + + AVCodec ff_xan_wc3_decoder = { +- "xan_wc3", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_XAN_WC3, +- sizeof(XanContext), +- xan_decode_init, +- NULL, +- xan_decode_end, +- xan_decode_frame, +- CODEC_CAP_DR1, +- .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"), +-}; +- +-/* +-AVCodec ff_xan_wc4_decoder = { +- "xan_wc4", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_XAN_WC4, +- sizeof(XanContext), +- xan_decode_init, +- NULL, +- xan_decode_end, +- xan_decode_frame, +- CODEC_CAP_DR1, +- .long_name = NULL_IF_CONFIG_SMALL("Wing Commander IV / Xxan"), ++ .name = "xan_wc3", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_XAN_WC3, ++ .priv_data_size = sizeof(XanContext), ++ .init = xan_decode_init, ++ .close = xan_decode_end, ++ .decode = xan_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III / Xan"), + }; +-*/ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xiph.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xiph.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xiph.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xiph.c 2012-05-14 14:08:54.599345315 +0200 +@@ -21,7 +21,7 @@ + #include "libavutil/intreadwrite.h" + #include "xiph.h" + +-int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, ++int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, + int first_header_size, uint8_t *header_start[3], + int header_len[3]) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xiph.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xiph.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xiph.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xiph.h 2012-05-14 14:08:54.600345335 +0200 +@@ -36,8 +36,8 @@ + * @param[out] header_len The sizes of each of the three headers. + * @return On error a negative value is returned, on success zero. + */ +-int ff_split_xiph_headers(uint8_t *extradata, int extradata_size, +- int first_header_size, uint8_t *header_start[3], +- int header_len[3]); ++int avpriv_split_xiph_headers(uint8_t *extradata, int extradata_size, ++ int first_header_size, uint8_t *header_start[3], ++ int header_len[3]); + + #endif /* AVCODEC_XIPH_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xl.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xl.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xl.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xl.c 2012-05-14 14:08:54.601345355 +0200 +@@ -60,7 +60,7 @@ + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +- p->pict_type= FF_I_TYPE; ++ p->pict_type= AV_PICTURE_TYPE_I; + p->key_frame= 1; + + Y = a->pic.data[0]; +@@ -68,6 +68,12 @@ + V = a->pic.data[2]; + + stride = avctx->width - 4; ++ ++ if (buf_size < avctx->width * avctx->height) { ++ av_log(avctx, AV_LOG_ERROR, "Packet is too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ + for (i = 0; i < avctx->height; i++) { + /* lines are stored in reversed order */ + buf += stride; +@@ -121,8 +127,9 @@ + } + + static av_cold int decode_init(AVCodecContext *avctx){ +-// VideoXLContext * const a = avctx->priv_data; ++ VideoXLContext * const a = avctx->priv_data; + ++ avcodec_get_frame_defaults(&a->pic); + avctx->pix_fmt= PIX_FMT_YUV411P; + + return 0; +@@ -139,14 +146,13 @@ + } + + AVCodec ff_xl_decoder = { +- "xl", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_VIXL, +- sizeof(VideoXLContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "xl", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VIXL, ++ .priv_data_size = sizeof(VideoXLContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Miro VideoXL"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xsubdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xsubdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xsubdec.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xsubdec.c 2012-05-14 14:08:54.601345355 +0200 +@@ -18,7 +18,9 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ +-#include "libavcore/imgutils.h" ++ ++#include "libavutil/mathematics.h" ++#include "libavutil/imgutils.h" + #include "avcodec.h" + #include "get_bits.h" + #include "bytestream.h" +@@ -51,11 +53,10 @@ + AVSubtitle *sub = data; + const uint8_t *buf_end = buf + buf_size; + uint8_t *bitmap; +- int w, h, x, y, rlelen, i; ++ int w, h, x, y, i; + int64_t packet_time = 0; + GetBitContext gb; +- +- memset(sub, 0, sizeof(*sub)); ++ int has_alpha = avctx->codec_tag == MKTAG('D','X','S','A'); + + // check that at least header fits + if (buf_size < 27 + 7 * 2 + 4 * 3) { +@@ -84,7 +85,11 @@ + // skip bottom right position, it gives no new information + bytestream_get_le16(&buf); + bytestream_get_le16(&buf); +- rlelen = bytestream_get_le16(&buf); ++ // The following value is supposed to indicate the start offset ++ // (relative to the palette) of the data for the second field, ++ // however there are files where it has a bogus value and thus ++ // we just ignore it ++ bytestream_get_le16(&buf); + + // allocate sub and set values + sub->rects = av_mallocz(sizeof(*sub->rects)); +@@ -102,12 +107,11 @@ + for (i = 0; i < sub->rects[0]->nb_colors; i++) + ((uint32_t*)sub->rects[0]->pict.data[1])[i] = bytestream_get_be24(&buf); + // make all except background (first entry) non-transparent +- for (i = 1; i < sub->rects[0]->nb_colors; i++) +- ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= 0xff000000; ++ for (i = 0; i < sub->rects[0]->nb_colors; i++) ++ ((uint32_t*)sub->rects[0]->pict.data[1])[i] |= (has_alpha ? *buf++ : (i ? 0xff : 0)) << 24; + + // process RLE-compressed data +- rlelen = FFMIN(rlelen, buf_end - buf); +- init_get_bits(&gb, buf, rlelen * 8); ++ init_get_bits(&gb, buf, (buf_end - buf) * 8); + bitmap = sub->rects[0]->pict.data[0]; + for (y = 0; y < h; y++) { + // interlaced: do odd lines +@@ -132,13 +136,10 @@ + } + + AVCodec ff_xsub_decoder = { +- "xsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_XSUB, +- 0, +- decode_init, +- NULL, +- NULL, +- decode_frame, ++ .name = "xsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_XSUB, ++ .init = decode_init, ++ .decode = decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("XSUB"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xsubenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xsubenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xsubenc.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xsubenc.c 2012-05-14 14:08:54.602345375 +0200 +@@ -36,8 +36,8 @@ + + /** + * Encode a single color run. At most 16 bits will be used. +- * \param len length of the run, values > 255 mean "until end of line", may not be < 0. +- * \param color color to encode, only the lowest two bits are used and all others must be 0. ++ * @param len length of the run, values > 255 mean "until end of line", may not be < 0. ++ * @param color color to encode, only the lowest two bits are used and all others must be 0. + */ + static void put_xsub_rle(PutBitContext *pb, int len, int color) + { +@@ -90,7 +90,7 @@ + if (color != PADDING_COLOR && (PADDING + (w&1))) + put_xsub_rle(pb, PADDING + (w&1), PADDING_COLOR); + +- align_put_bits(pb); ++ avpriv_align_put_bits(pb); + + bitmap += linesize; + } +@@ -129,7 +129,7 @@ + } + + // TODO: support multiple rects +- if (h->num_rects > 1) ++ if (h->num_rects != 1) + av_log(avctx, AV_LOG_WARNING, "Only single rects supported (%d in subtitle.)\n", h->num_rects); + + // TODO: render text-based subtitles into bitmaps +@@ -194,7 +194,7 @@ + // Enforce total height to be be multiple of 2 + if (h->rects[0]->h & 1) { + put_xsub_rle(&pb, h->rects[0]->w, PADDING_COLOR); +- align_put_bits(&pb); ++ avpriv_align_put_bits(&pb); + } + + flush_put_bits(&pb); +@@ -211,12 +211,10 @@ + } + + AVCodec ff_xsub_encoder = { +- "xsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_XSUB, +- 0, +- xsub_encoder_init, +- xsub_encode, +- NULL, ++ .name = "xsub", ++ .type = AVMEDIA_TYPE_SUBTITLE, ++ .id = CODEC_ID_XSUB, ++ .init = xsub_encoder_init, ++ .encode = xsub_encode, + .long_name = NULL_IF_CONFIG_SMALL("DivX subtitles (XSUB)"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xvmc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xvmc.h 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc.h 2012-05-14 14:08:54.603345395 +0200 +@@ -25,11 +25,6 @@ + + #include "avcodec.h" + +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-#define AV_XVMC_STATE_DISPLAY_PENDING 1 /** the surface should be shown, the video driver manipulates this */ +-#define AV_XVMC_STATE_PREDICTION 2 /** the surface is needed for prediction, the codec manipulates this */ +-#define AV_XVMC_STATE_OSD_SOURCE 4 /** the surface is needed for subpicture rendering */ +-#endif + #define AV_XVMC_ID 0x1DC711C0 /**< special value to ensure that regular pixel routines haven't corrupted the struct + the number is 1337 speak for the letters IDCT MCo (motion compensation) */ + +@@ -151,22 +146,6 @@ + of coded blocks it contains. + */ + int next_free_data_block_num; +- +-/** extensions may be placed here */ +-#if LIBAVCODEC_VERSION_MAJOR < 53 +-//@{ +- /** State flags used to work around limitations in the MPlayer video system. +- 0 - Surface is not used. +- 1 - Surface is still held in application to be displayed or is +- still visible. +- 2 - Surface is still held in libavcodec buffer for prediction. +- */ +- int state; +- +- /** pointer to the surface where the subpicture is rendered */ +- void* p_osd_target_surface_render; +-//}@ +-#endif + }; + + #endif /* AVCODEC_XVMC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-05-14 14:08:54.603345395 +0200 +@@ -18,8 +18,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef AVCODEC_INTERNAL_XVMC_H +-#define AVCODEC_INTERNAL_XVMC_H ++#ifndef AVCODEC_XVMC_INTERNAL_H ++#define AVCODEC_XVMC_INTERNAL_H + + #include "avcodec.h" + #include "mpegvideo.h" +@@ -30,4 +30,4 @@ + void ff_xvmc_field_end(MpegEncContext *s); + void ff_xvmc_decode_mb(MpegEncContext *s); + +-#endif /* AVCODEC_INTERNAL_XVMC_H */ ++#endif /* AVCODEC_XVMC_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwddec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwddec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwddec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwddec.c 2012-05-14 14:08:54.605345436 +0200 +@@ -0,0 +1,267 @@ ++/* ++ * XWD image format ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/imgutils.h" ++#include "avcodec.h" ++#include "bytestream.h" ++#include "xwd.h" ++ ++static av_cold int xwd_decode_init(AVCodecContext *avctx) ++{ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->coded_frame) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++static int xwd_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ AVFrame *p = avctx->coded_frame; ++ const uint8_t *buf = avpkt->data; ++ int i, ret, buf_size = avpkt->size; ++ uint32_t version, header_size, vclass, ncolors; ++ uint32_t xoffset, be, bpp, lsize, rsize; ++ uint32_t pixformat, pixdepth, bunit, bitorder, bpad; ++ uint32_t rgb[3]; ++ uint8_t *ptr; ++ ++ if (buf_size < XWD_HEADER_SIZE) ++ return AVERROR_INVALIDDATA; ++ ++ header_size = bytestream_get_be32(&buf); ++ if (buf_size < header_size) ++ return AVERROR_INVALIDDATA; ++ ++ version = bytestream_get_be32(&buf); ++ if (version != XWD_VERSION) { ++ av_log(avctx, AV_LOG_ERROR, "unsupported version\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (header_size < XWD_HEADER_SIZE) { ++ av_log(avctx, AV_LOG_ERROR, "invalid header size\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ pixformat = bytestream_get_be32(&buf); ++ pixdepth = bytestream_get_be32(&buf); ++ avctx->width = bytestream_get_be32(&buf); ++ avctx->height = bytestream_get_be32(&buf); ++ xoffset = bytestream_get_be32(&buf); ++ be = bytestream_get_be32(&buf); ++ bunit = bytestream_get_be32(&buf); ++ bitorder = bytestream_get_be32(&buf); ++ bpad = bytestream_get_be32(&buf); ++ bpp = bytestream_get_be32(&buf); ++ lsize = bytestream_get_be32(&buf); ++ vclass = bytestream_get_be32(&buf); ++ rgb[0] = bytestream_get_be32(&buf); ++ rgb[1] = bytestream_get_be32(&buf); ++ rgb[2] = bytestream_get_be32(&buf); ++ buf += 8; ++ ncolors = bytestream_get_be32(&buf); ++ buf += header_size - (XWD_HEADER_SIZE - 20); ++ ++ av_log(avctx, AV_LOG_DEBUG, "pixformat %d, pixdepth %d, bunit %d, bitorder %d, bpad %d\n", ++ pixformat, pixdepth, bunit, bitorder, bpad); ++ av_log(avctx, AV_LOG_DEBUG, "vclass %d, ncolors %d, bpp %d, be %d, lsize %d, xoffset %d\n", ++ vclass, ncolors, bpp, be, lsize, xoffset); ++ av_log(avctx, AV_LOG_DEBUG, "red %0x, green %0x, blue %0x\n", rgb[0], rgb[1], rgb[2]); ++ ++ if (pixformat > XWD_Z_PIXMAP) { ++ av_log(avctx, AV_LOG_ERROR, "invalid pixmap format\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (pixdepth == 0 || pixdepth > 32) { ++ av_log(avctx, AV_LOG_ERROR, "invalid pixmap depth\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (xoffset) { ++ av_log_ask_for_sample(avctx, "unsupported xoffset %d\n", xoffset); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ if (be > 1) { ++ av_log(avctx, AV_LOG_ERROR, "invalid byte order\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (bitorder > 1) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bitmap bit order\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (bunit != 8 && bunit != 16 && bunit != 32) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bitmap unit\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (bpad != 8 && bpad != 16 && bpad != 32) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bitmap scan-line pad\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (bpp == 0 || bpp > 32) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bits per pixel\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (ncolors > 256) { ++ av_log(avctx, AV_LOG_ERROR, "invalid number of entries in colormap\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((ret = av_image_check_size(avctx->width, avctx->height, 0, NULL)) < 0) ++ return ret; ++ ++ rsize = FFALIGN(avctx->width * bpp, bpad) / 8; ++ if (lsize < rsize) { ++ av_log(avctx, AV_LOG_ERROR, "invalid bytes per scan-line\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (buf_size < header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize) { ++ av_log(avctx, AV_LOG_ERROR, "input buffer too small\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (pixformat != XWD_Z_PIXMAP) { ++ av_log(avctx, AV_LOG_ERROR, "pixmap format %d unsupported\n", pixformat); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ avctx->pix_fmt = PIX_FMT_NONE; ++ switch (vclass) { ++ case XWD_STATIC_GRAY: ++ case XWD_GRAY_SCALE: ++ if (bpp != 1) ++ return AVERROR_INVALIDDATA; ++ if (pixdepth == 1) ++ avctx->pix_fmt = PIX_FMT_MONOWHITE; ++ break; ++ case XWD_STATIC_COLOR: ++ case XWD_PSEUDO_COLOR: ++ if (bpp == 8) ++ avctx->pix_fmt = PIX_FMT_PAL8; ++ break; ++ case XWD_TRUE_COLOR: ++ case XWD_DIRECT_COLOR: ++ if (bpp != 16 && bpp != 24 && bpp != 32) ++ return AVERROR_INVALIDDATA; ++ if (bpp == 16 && pixdepth == 15) { ++ if (rgb[0] == 0x7C00 && rgb[1] == 0x3E0 && rgb[2] == 0x1F) ++ avctx->pix_fmt = be ? PIX_FMT_RGB555BE : PIX_FMT_RGB555LE; ++ else if (rgb[0] == 0x1F && rgb[1] == 0x3E0 && rgb[2] == 0x7C00) ++ avctx->pix_fmt = be ? PIX_FMT_BGR555BE : PIX_FMT_BGR555LE; ++ } else if (bpp == 16 && pixdepth == 16) { ++ if (rgb[0] == 0xF800 && rgb[1] == 0x7E0 && rgb[2] == 0x1F) ++ avctx->pix_fmt = be ? PIX_FMT_RGB565BE : PIX_FMT_RGB565LE; ++ else if (rgb[0] == 0x1F && rgb[1] == 0x7E0 && rgb[2] == 0xF800) ++ avctx->pix_fmt = be ? PIX_FMT_BGR565BE : PIX_FMT_BGR565LE; ++ } else if (bpp == 24) { ++ if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF) ++ avctx->pix_fmt = be ? PIX_FMT_RGB24 : PIX_FMT_BGR24; ++ else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000) ++ avctx->pix_fmt = be ? PIX_FMT_BGR24 : PIX_FMT_RGB24; ++ } else if (bpp == 32) { ++ if (rgb[0] == 0xFF0000 && rgb[1] == 0xFF00 && rgb[2] == 0xFF) ++ avctx->pix_fmt = be ? PIX_FMT_ARGB : PIX_FMT_BGRA; ++ else if (rgb[0] == 0xFF && rgb[1] == 0xFF00 && rgb[2] == 0xFF0000) ++ avctx->pix_fmt = be ? PIX_FMT_ABGR : PIX_FMT_RGBA; ++ } ++ buf += ncolors * XWD_CMAP_SIZE; ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "invalid visual class\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (avctx->pix_fmt == PIX_FMT_NONE) { ++ av_log_ask_for_sample(avctx, "unknown file: bpp %d, pixdepth %d, vclass %d\n", bpp, pixdepth, vclass); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ if (p->data[0]) ++ avctx->release_buffer(avctx, p); ++ ++ p->reference = 0; ++ if ((ret = avctx->get_buffer(avctx, p)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); ++ return ret; ++ } ++ ++ p->key_frame = 1; ++ p->pict_type = AV_PICTURE_TYPE_I; ++ ++ if (avctx->pix_fmt == PIX_FMT_PAL8) { ++ uint32_t *dst = (uint32_t *)p->data[1]; ++ uint8_t red, green, blue; ++ ++ for (i = 0; i < ncolors; i++) { ++ ++ buf += 4; // skip colormap entry number ++ red = *buf; buf += 2; ++ green = *buf; buf += 2; ++ blue = *buf; buf += 2; ++ buf += 2; // skip bitmask flag and padding ++ ++ dst[i] = red << 16 | green << 8 | blue; ++ } ++ } ++ ++ ptr = p->data[0]; ++ for (i = 0; i < avctx->height; i++) { ++ bytestream_get_buffer(&buf, ptr, rsize); ++ buf += lsize - rsize; ++ ptr += p->linesize[0]; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *p; ++ ++ return buf_size; ++} ++ ++static av_cold int xwd_decode_close(AVCodecContext *avctx) ++{ ++ if (avctx->coded_frame->data[0]) ++ avctx->release_buffer(avctx, avctx->coded_frame); ++ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_xwd_decoder = { ++ .name = "xwd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_XWD, ++ .init = xwd_decode_init, ++ .close = xwd_decode_close, ++ .decode = xwd_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwdenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwdenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwdenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwdenc.c 2012-05-14 14:08:54.606345457 +0200 +@@ -0,0 +1,246 @@ ++/* ++ * XWD image format ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/pixdesc.h" ++#include "avcodec.h" ++#include "bytestream.h" ++#include "xwd.h" ++ ++#define WINDOW_NAME "lavcxwdenc" ++#define WINDOW_NAME_SIZE 11 ++ ++static av_cold int xwd_encode_init(AVCodecContext *avctx) ++{ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->coded_frame) ++ return AVERROR(ENOMEM); ++ ++ return 0; ++} ++ ++static int xwd_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *p = data; ++ enum PixelFormat pix_fmt = avctx->pix_fmt; ++ uint32_t pixdepth, bpp, bpad, ncolors = 0, lsize, vclass, be = 0; ++ uint32_t rgb[3] = { 0 }; ++ uint32_t header_size; ++ int i, out_size; ++ uint8_t *ptr; ++ ++ pixdepth = av_get_bits_per_pixel(&av_pix_fmt_descriptors[pix_fmt]); ++ if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BE) ++ be = 1; ++ switch (pix_fmt) { ++ case PIX_FMT_ARGB: ++ case PIX_FMT_BGRA: ++ case PIX_FMT_RGBA: ++ case PIX_FMT_ABGR: ++ if (pix_fmt == PIX_FMT_ARGB || ++ pix_fmt == PIX_FMT_ABGR) ++ be = 1; ++ if (pix_fmt == PIX_FMT_ABGR || ++ pix_fmt == PIX_FMT_RGBA) { ++ rgb[0] = 0xFF; ++ rgb[1] = 0xFF00; ++ rgb[2] = 0xFF0000; ++ } else { ++ rgb[0] = 0xFF0000; ++ rgb[1] = 0xFF00; ++ rgb[2] = 0xFF; ++ } ++ bpp = 32; ++ pixdepth = 24; ++ vclass = XWD_TRUE_COLOR; ++ bpad = 32; ++ break; ++ case PIX_FMT_BGR24: ++ case PIX_FMT_RGB24: ++ if (pix_fmt == PIX_FMT_RGB24) ++ be = 1; ++ bpp = 24; ++ vclass = XWD_TRUE_COLOR; ++ bpad = 32; ++ rgb[0] = 0xFF0000; ++ rgb[1] = 0xFF00; ++ rgb[2] = 0xFF; ++ break; ++ case PIX_FMT_RGB565LE: ++ case PIX_FMT_RGB565BE: ++ case PIX_FMT_BGR565LE: ++ case PIX_FMT_BGR565BE: ++ if (pix_fmt == PIX_FMT_BGR565LE || ++ pix_fmt == PIX_FMT_BGR565BE) { ++ rgb[0] = 0x1F; ++ rgb[1] = 0x7E0; ++ rgb[2] = 0xF800; ++ } else { ++ rgb[0] = 0xF800; ++ rgb[1] = 0x7E0; ++ rgb[2] = 0x1F; ++ } ++ bpp = 16; ++ vclass = XWD_TRUE_COLOR; ++ bpad = 16; ++ break; ++ case PIX_FMT_RGB555LE: ++ case PIX_FMT_RGB555BE: ++ case PIX_FMT_BGR555LE: ++ case PIX_FMT_BGR555BE: ++ if (pix_fmt == PIX_FMT_BGR555LE || ++ pix_fmt == PIX_FMT_BGR555BE) { ++ rgb[0] = 0x1F; ++ rgb[1] = 0x3E0; ++ rgb[2] = 0x7C00; ++ } else { ++ rgb[0] = 0x7C00; ++ rgb[1] = 0x3E0; ++ rgb[2] = 0x1F; ++ } ++ bpp = 16; ++ vclass = XWD_TRUE_COLOR; ++ bpad = 16; ++ break; ++ case PIX_FMT_RGB8: ++ case PIX_FMT_BGR8: ++ case PIX_FMT_RGB4_BYTE: ++ case PIX_FMT_BGR4_BYTE: ++ case PIX_FMT_PAL8: ++ bpp = 8; ++ vclass = XWD_PSEUDO_COLOR; ++ bpad = 8; ++ ncolors = 256; ++ break; ++ case PIX_FMT_MONOWHITE: ++ bpp = 1; ++ bpad = 8; ++ vclass = XWD_STATIC_GRAY; ++ break; ++ default: ++ av_log(avctx, AV_LOG_INFO, "unsupported pixel format\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ lsize = FFALIGN(bpp * avctx->width, bpad) / 8; ++ header_size = XWD_HEADER_SIZE + WINDOW_NAME_SIZE; ++ out_size = header_size + ncolors * XWD_CMAP_SIZE + avctx->height * lsize; ++ ++ if (buf_size < out_size) { ++ av_log(avctx, AV_LOG_ERROR, "output buffer too small\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ bytestream_put_be32(&buf, header_size); ++ bytestream_put_be32(&buf, XWD_VERSION); // file version ++ bytestream_put_be32(&buf, XWD_Z_PIXMAP); // pixmap format ++ bytestream_put_be32(&buf, pixdepth); // pixmap depth in pixels ++ bytestream_put_be32(&buf, avctx->width); // pixmap width in pixels ++ bytestream_put_be32(&buf, avctx->height); // pixmap height in pixels ++ bytestream_put_be32(&buf, 0); // bitmap x offset ++ bytestream_put_be32(&buf, be); // byte order ++ bytestream_put_be32(&buf, 32); // bitmap unit ++ bytestream_put_be32(&buf, be); // bit-order of image data ++ bytestream_put_be32(&buf, bpad); // bitmap scan-line pad in bits ++ bytestream_put_be32(&buf, bpp); // bits per pixel ++ bytestream_put_be32(&buf, lsize); // bytes per scan-line ++ bytestream_put_be32(&buf, vclass); // visual class ++ bytestream_put_be32(&buf, rgb[0]); // red mask ++ bytestream_put_be32(&buf, rgb[1]); // green mask ++ bytestream_put_be32(&buf, rgb[2]); // blue mask ++ bytestream_put_be32(&buf, 8); // size of each bitmask in bits ++ bytestream_put_be32(&buf, ncolors); // number of colors ++ bytestream_put_be32(&buf, ncolors); // number of entries in color map ++ bytestream_put_be32(&buf, avctx->width); // window width ++ bytestream_put_be32(&buf, avctx->height); // window height ++ bytestream_put_be32(&buf, 0); // window upper left X coordinate ++ bytestream_put_be32(&buf, 0); // window upper left Y coordinate ++ bytestream_put_be32(&buf, 0); // window border width ++ bytestream_put_buffer(&buf, WINDOW_NAME, WINDOW_NAME_SIZE); ++ ++ for (i = 0; i < ncolors; i++) { ++ uint32_t val; ++ uint8_t red, green, blue; ++ ++ val = AV_RN32A(p->data[1] + i * 4); ++ red = (val >> 16) & 0xFF; ++ green = (val >> 8) & 0xFF; ++ blue = val & 0xFF; ++ ++ bytestream_put_be32(&buf, i); // colormap entry number ++ bytestream_put_be16(&buf, red << 8); ++ bytestream_put_be16(&buf, green << 8); ++ bytestream_put_be16(&buf, blue << 8); ++ bytestream_put_byte(&buf, 0x7); // bitmask flag ++ bytestream_put_byte(&buf, 0); // padding ++ } ++ ++ ptr = p->data[0]; ++ for (i = 0; i < avctx->height; i++) { ++ bytestream_put_buffer(&buf, ptr, lsize); ++ ptr += p->linesize[0]; ++ } ++ ++ return out_size; ++} ++ ++static av_cold int xwd_encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_xwd_encoder = { ++ .name = "xwd", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_XWD, ++ .init = xwd_encode_init, ++ .encode = xwd_encode_frame, ++ .close = xwd_encode_close, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_BGRA, ++ PIX_FMT_RGBA, ++ PIX_FMT_ARGB, ++ PIX_FMT_ABGR, ++ PIX_FMT_RGB24, ++ PIX_FMT_BGR24, ++ PIX_FMT_RGB565BE, ++ PIX_FMT_RGB565LE, ++ PIX_FMT_BGR565BE, ++ PIX_FMT_BGR565LE, ++ PIX_FMT_RGB555BE, ++ PIX_FMT_RGB555LE, ++ PIX_FMT_BGR555BE, ++ PIX_FMT_BGR555LE, ++ PIX_FMT_RGB8, ++ PIX_FMT_BGR8, ++ PIX_FMT_RGB4_BYTE, ++ PIX_FMT_BGR4_BYTE, ++ PIX_FMT_PAL8, ++ PIX_FMT_MONOWHITE, ++ PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("XWD (X Window Dump) image"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwd.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwd.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xwd.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xwd.h 2012-05-14 14:08:54.604345415 +0200 +@@ -0,0 +1,41 @@ ++/* ++ * XWD image format ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_XWD_H ++#define AVCODEC_XWD_H ++ ++#define XWD_VERSION 7 ++#define XWD_HEADER_SIZE 100 ++#define XWD_CMAP_SIZE 12 ++ ++#define XWD_XY_BITMAP 0 ++#define XWD_XY_PIXMAP 1 ++#define XWD_Z_PIXMAP 2 ++ ++#define XWD_STATIC_GRAY 0 ++#define XWD_GRAY_SCALE 1 ++#define XWD_STATIC_COLOR 2 ++#define XWD_PSEUDO_COLOR 3 ++#define XWD_TRUE_COLOR 4 ++#define XWD_DIRECT_COLOR 5 ++ ++#endif /* AVCODEC_XWD_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xxan.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xxan.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/xxan.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/xxan.c 2012-05-14 14:08:54.607345477 +0200 +@@ -0,0 +1,431 @@ ++/* ++ * Wing Commander/Xan Video Decoder ++ * Copyright (C) 2011 Konstantin Shishkov ++ * based on work by Mike Melanson ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++#include "libavutil/intreadwrite.h" ++#include "bytestream.h" ++#define BITSTREAM_READER_LE ++#include "get_bits.h" ++// for av_memcpy_backptr ++#include "libavutil/lzo.h" ++ ++typedef struct XanContext { ++ AVCodecContext *avctx; ++ AVFrame pic; ++ ++ uint8_t *y_buffer; ++ uint8_t *scratch_buffer; ++ int buffer_size; ++ GetByteContext gb; ++} XanContext; ++ ++static av_cold int xan_decode_init(AVCodecContext *avctx) ++{ ++ XanContext *s = avctx->priv_data; ++ ++ s->avctx = avctx; ++ ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ ++ s->buffer_size = avctx->width * avctx->height; ++ s->y_buffer = av_malloc(s->buffer_size); ++ if (!s->y_buffer) ++ return AVERROR(ENOMEM); ++ s->scratch_buffer = av_malloc(s->buffer_size + 130); ++ if (!s->scratch_buffer) { ++ av_freep(&s->y_buffer); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int xan_unpack_luma(XanContext *s, ++ uint8_t *dst, const int dst_size) ++{ ++ int tree_size, eof; ++ int bits, mask; ++ int tree_root, node; ++ const uint8_t *dst_end = dst + dst_size; ++ GetByteContext tree = s->gb; ++ int start_off = bytestream2_tell(&tree); ++ ++ tree_size = bytestream2_get_byte(&s->gb); ++ eof = bytestream2_get_byte(&s->gb); ++ tree_root = eof + tree_size; ++ bytestream2_skip(&s->gb, tree_size * 2); ++ ++ node = tree_root; ++ bits = bytestream2_get_byte(&s->gb); ++ mask = 0x80; ++ for (;;) { ++ int bit = !!(bits & mask); ++ mask >>= 1; ++ bytestream2_seek(&tree, start_off + node*2 + bit - eof * 2, SEEK_SET); ++ node = bytestream2_get_byte(&tree); ++ if (node == eof) ++ break; ++ if (node < eof) { ++ *dst++ = node; ++ if (dst > dst_end) ++ break; ++ node = tree_root; ++ } ++ if (!mask) { ++ if (bytestream2_get_bytes_left(&s->gb) <= 0) ++ break; ++ bits = bytestream2_get_byteu(&s->gb); ++ mask = 0x80; ++ } ++ } ++ return dst != dst_end ? AVERROR_INVALIDDATA : 0; ++} ++ ++/* almost the same as in xan_wc3 decoder */ ++static int xan_unpack(XanContext *s, ++ uint8_t *dest, const int dest_len) ++{ ++ uint8_t opcode; ++ int size; ++ uint8_t *orig_dest = dest; ++ const uint8_t *dest_end = dest + dest_len; ++ ++ while (dest < dest_end) { ++ if (bytestream2_get_bytes_left(&s->gb) <= 0) ++ return AVERROR_INVALIDDATA; ++ ++ opcode = bytestream2_get_byteu(&s->gb); ++ ++ if (opcode < 0xe0) { ++ int size2, back; ++ if ((opcode & 0x80) == 0) { ++ size = opcode & 3; ++ back = ((opcode & 0x60) << 3) + bytestream2_get_byte(&s->gb) + 1; ++ size2 = ((opcode & 0x1c) >> 2) + 3; ++ } else if ((opcode & 0x40) == 0) { ++ size = bytestream2_peek_byte(&s->gb) >> 6; ++ back = (bytestream2_get_be16(&s->gb) & 0x3fff) + 1; ++ size2 = (opcode & 0x3f) + 4; ++ } else { ++ size = opcode & 3; ++ back = ((opcode & 0x10) << 12) + bytestream2_get_be16(&s->gb) + 1; ++ size2 = ((opcode & 0x0c) << 6) + bytestream2_get_byte(&s->gb) + 5; ++ if (size + size2 > dest_end - dest) ++ break; ++ } ++ if (dest + size + size2 > dest_end || ++ dest - orig_dest + size < back) ++ return -1; ++ bytestream2_get_buffer(&s->gb, dest, size); ++ dest += size; ++ av_memcpy_backptr(dest, back, size2); ++ dest += size2; ++ } else { ++ int finish = opcode >= 0xfc; ++ ++ size = finish ? opcode & 3 : ((opcode & 0x1f) << 2) + 4; ++ if (dest_end - dest < size) ++ return -1; ++ bytestream2_get_buffer(&s->gb, dest, size); ++ dest += size; ++ if (finish) ++ break; ++ } ++ } ++ return dest - orig_dest; ++} ++ ++static int xan_decode_chroma(AVCodecContext *avctx, unsigned chroma_off) ++{ ++ XanContext *s = avctx->priv_data; ++ uint8_t *U, *V; ++ int val, uval, vval; ++ int i, j; ++ const uint8_t *src, *src_end; ++ const uint8_t *table; ++ int mode, offset, dec_size, table_size; ++ ++ if (!chroma_off) ++ return 0; ++ if (chroma_off + 4 >= bytestream2_get_bytes_left(&s->gb)) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid chroma block position\n"); ++ return -1; ++ } ++ bytestream2_seek(&s->gb, chroma_off + 4, SEEK_SET); ++ mode = bytestream2_get_le16(&s->gb); ++ table = s->gb.buffer; ++ table_size = bytestream2_get_le16(&s->gb); ++ offset = table_size * 2; ++ table_size += 1; ++ ++ if (offset >= bytestream2_get_bytes_left(&s->gb)) { ++ av_log(avctx, AV_LOG_ERROR, "Invalid chroma block offset\n"); ++ return -1; ++ } ++ ++ bytestream2_skip(&s->gb, offset); ++ memset(s->scratch_buffer, 0, s->buffer_size); ++ dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size); ++ if (dec_size < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Chroma unpacking failed\n"); ++ return -1; ++ } ++ ++ U = s->pic.data[1]; ++ V = s->pic.data[2]; ++ src = s->scratch_buffer; ++ src_end = src + dec_size; ++ if (mode) { ++ for (j = 0; j < avctx->height >> 1; j++) { ++ for (i = 0; i < avctx->width >> 1; i++) { ++ if (src_end - src < 1) ++ return 0; ++ val = *src++; ++ if (val && val < table_size) { ++ val = AV_RL16(table + (val << 1)); ++ uval = (val >> 3) & 0xF8; ++ vval = (val >> 8) & 0xF8; ++ U[i] = uval | (uval >> 5); ++ V[i] = vval | (vval >> 5); ++ } ++ } ++ U += s->pic.linesize[1]; ++ V += s->pic.linesize[2]; ++ } ++ } else { ++ uint8_t *U2 = U + s->pic.linesize[1]; ++ uint8_t *V2 = V + s->pic.linesize[2]; ++ ++ for (j = 0; j < avctx->height >> 2; j++) { ++ for (i = 0; i < avctx->width >> 1; i += 2) { ++ if (src_end - src < 1) ++ return 0; ++ val = *src++; ++ if (val && val < table_size) { ++ val = AV_RL16(table + (val << 1)); ++ uval = (val >> 3) & 0xF8; ++ vval = (val >> 8) & 0xF8; ++ U[i] = U[i+1] = U2[i] = U2[i+1] = uval | (uval >> 5); ++ V[i] = V[i+1] = V2[i] = V2[i+1] = vval | (vval >> 5); ++ } ++ } ++ U += s->pic.linesize[1] * 2; ++ V += s->pic.linesize[2] * 2; ++ U2 += s->pic.linesize[1] * 2; ++ V2 += s->pic.linesize[2] * 2; ++ } ++ } ++ ++ return 0; ++} ++ ++static int xan_decode_frame_type0(AVCodecContext *avctx) ++{ ++ XanContext *s = avctx->priv_data; ++ uint8_t *ybuf, *prev_buf, *src = s->scratch_buffer; ++ unsigned chroma_off, corr_off; ++ int cur, last; ++ int i, j; ++ int ret; ++ ++ chroma_off = bytestream2_get_le32(&s->gb); ++ corr_off = bytestream2_get_le32(&s->gb); ++ ++ if ((ret = xan_decode_chroma(avctx, chroma_off)) != 0) ++ return ret; ++ ++ if (corr_off >= (s->gb.buffer_end - s->gb.buffer_start)) { ++ av_log(avctx, AV_LOG_WARNING, "Ignoring invalid correction block position\n"); ++ corr_off = 0; ++ } ++ bytestream2_seek(&s->gb, 12, SEEK_SET); ++ ret = xan_unpack_luma(s, src, s->buffer_size >> 1); ++ if (ret) { ++ av_log(avctx, AV_LOG_ERROR, "Luma decoding failed\n"); ++ return ret; ++ } ++ ++ ybuf = s->y_buffer; ++ last = *src++; ++ ybuf[0] = last << 1; ++ for (j = 1; j < avctx->width - 1; j += 2) { ++ cur = (last + *src++) & 0x1F; ++ ybuf[j] = last + cur; ++ ybuf[j+1] = cur << 1; ++ last = cur; ++ } ++ ybuf[j] = last << 1; ++ prev_buf = ybuf; ++ ybuf += avctx->width; ++ ++ for (i = 1; i < avctx->height; i++) { ++ last = ((prev_buf[0] >> 1) + *src++) & 0x1F; ++ ybuf[0] = last << 1; ++ for (j = 1; j < avctx->width - 1; j += 2) { ++ cur = ((prev_buf[j + 1] >> 1) + *src++) & 0x1F; ++ ybuf[j] = last + cur; ++ ybuf[j+1] = cur << 1; ++ last = cur; ++ } ++ ybuf[j] = last << 1; ++ prev_buf = ybuf; ++ ybuf += avctx->width; ++ } ++ ++ if (corr_off) { ++ int corr_end, dec_size; ++ ++ corr_end = (s->gb.buffer_end - s->gb.buffer_start); ++ if (chroma_off > corr_off) ++ corr_end = chroma_off; ++ bytestream2_seek(&s->gb, 8 + corr_off, SEEK_SET); ++ dec_size = xan_unpack(s, s->scratch_buffer, s->buffer_size); ++ if (dec_size < 0) ++ dec_size = 0; ++ else ++ dec_size = FFMIN(dec_size, s->buffer_size/2 - 1); ++ ++ for (i = 0; i < dec_size; i++) ++ s->y_buffer[i*2+1] = (s->y_buffer[i*2+1] + (s->scratch_buffer[i] << 1)) & 0x3F; ++ } ++ ++ src = s->y_buffer; ++ ybuf = s->pic.data[0]; ++ for (j = 0; j < avctx->height; j++) { ++ for (i = 0; i < avctx->width; i++) ++ ybuf[i] = (src[i] << 2) | (src[i] >> 3); ++ src += avctx->width; ++ ybuf += s->pic.linesize[0]; ++ } ++ ++ return 0; ++} ++ ++static int xan_decode_frame_type1(AVCodecContext *avctx) ++{ ++ XanContext *s = avctx->priv_data; ++ uint8_t *ybuf, *src = s->scratch_buffer; ++ int cur, last; ++ int i, j; ++ int ret; ++ ++ if ((ret = xan_decode_chroma(avctx, bytestream2_get_le32(&s->gb))) != 0) ++ return ret; ++ ++ bytestream2_seek(&s->gb, 16, SEEK_SET); ++ ret = xan_unpack_luma(s, src, ++ s->buffer_size >> 1); ++ if (ret) { ++ av_log(avctx, AV_LOG_ERROR, "Luma decoding failed\n"); ++ return ret; ++ } ++ ++ ybuf = s->y_buffer; ++ for (i = 0; i < avctx->height; i++) { ++ last = (ybuf[0] + (*src++ << 1)) & 0x3F; ++ ybuf[0] = last; ++ for (j = 1; j < avctx->width - 1; j += 2) { ++ cur = (ybuf[j + 1] + (*src++ << 1)) & 0x3F; ++ ybuf[j] = (last + cur) >> 1; ++ ybuf[j+1] = cur; ++ last = cur; ++ } ++ ybuf[j] = last; ++ ybuf += avctx->width; ++ } ++ ++ src = s->y_buffer; ++ ybuf = s->pic.data[0]; ++ for (j = 0; j < avctx->height; j++) { ++ for (i = 0; i < avctx->width; i++) ++ ybuf[i] = (src[i] << 2) | (src[i] >> 3); ++ src += avctx->width; ++ ybuf += s->pic.linesize[0]; ++ } ++ ++ return 0; ++} ++ ++static int xan_decode_frame(AVCodecContext *avctx, ++ void *data, int *data_size, ++ AVPacket *avpkt) ++{ ++ XanContext *s = avctx->priv_data; ++ int ftype; ++ int ret; ++ ++ s->pic.reference = 3; ++ s->pic.buffer_hints = FF_BUFFER_HINTS_VALID | ++ FF_BUFFER_HINTS_PRESERVE | ++ FF_BUFFER_HINTS_REUSABLE; ++ if ((ret = avctx->reget_buffer(avctx, &s->pic))) { ++ av_log(s->avctx, AV_LOG_ERROR, "reget_buffer() failed\n"); ++ return ret; ++ } ++ ++ bytestream2_init(&s->gb, avpkt->data, avpkt->size); ++ ftype = bytestream2_get_le32(&s->gb); ++ switch (ftype) { ++ case 0: ++ ret = xan_decode_frame_type0(avctx); ++ break; ++ case 1: ++ ret = xan_decode_frame_type1(avctx); ++ break; ++ default: ++ av_log(avctx, AV_LOG_ERROR, "Unknown frame type %d\n", ftype); ++ return -1; ++ } ++ if (ret) ++ return ret; ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame*)data = s->pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int xan_decode_end(AVCodecContext *avctx) ++{ ++ XanContext *s = avctx->priv_data; ++ ++ if (s->pic.data[0]) ++ avctx->release_buffer(avctx, &s->pic); ++ ++ av_freep(&s->y_buffer); ++ av_freep(&s->scratch_buffer); ++ ++ return 0; ++} ++ ++AVCodec ff_xan_wc4_decoder = { ++ .name = "xan_wc4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_XAN_WC4, ++ .priv_data_size = sizeof(XanContext), ++ .init = xan_decode_init, ++ .close = xan_decode_end, ++ .decode = xan_decode_frame, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Wing Commander IV / Xxan"), ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/y41pdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/y41pdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/y41pdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/y41pdec.c 2012-05-14 14:08:54.610345537 +0200 +@@ -0,0 +1,116 @@ ++/* ++ * y41p decoder ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++static av_cold int y41p_decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV411P; ++ avctx->bits_per_raw_sample = 12; ++ ++ if (avctx->width & 7) { ++ av_log(avctx, AV_LOG_WARNING, "y41p requires width to be divisible by 8.\n"); ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int y41p_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ AVFrame *pic = avctx->coded_frame; ++ uint8_t *src = avpkt->data; ++ uint8_t *y, *u, *v; ++ int i, j; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ if (avpkt->size < 1.5 * avctx->height * avctx->width) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ pic->reference = 0; ++ ++ if (avctx->get_buffer(avctx, pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ pic->key_frame = 1; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ ++ for (i = avctx->height - 1; i >= 0 ; i--) { ++ y = &pic->data[0][i * pic->linesize[0]]; ++ u = &pic->data[1][i * pic->linesize[1]]; ++ v = &pic->data[2][i * pic->linesize[2]]; ++ for (j = 0; j < avctx->width; j += 8) { ++ *(u++) = *src++; ++ *(y++) = *src++; ++ *(v++) = *src++; ++ *(y++) = *src++; ++ ++ *(u++) = *src++; ++ *(y++) = *src++; ++ *(v++) = *src++; ++ *(y++) = *src++; ++ ++ *(y++) = *src++; ++ *(y++) = *src++; ++ *(y++) = *src++; ++ *(y++) = *src++; ++ } ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int y41p_decode_close(AVCodecContext *avctx) ++{ ++ if (avctx->coded_frame->data[0]) ++ avctx->release_buffer(avctx, avctx->coded_frame); ++ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_y41p_decoder = { ++ .name = "y41p", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_Y41P, ++ .init = y41p_decode_init, ++ .decode = y41p_decode_frame, ++ .close = y41p_decode_close, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/y41penc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/y41penc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/y41penc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/y41penc.c 2012-05-14 14:08:54.610345537 +0200 +@@ -0,0 +1,102 @@ ++/* ++ * y41p encoder ++ * ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++static av_cold int y41p_encode_init(AVCodecContext *avctx) ++{ ++ if (avctx->width & 7) { ++ av_log(avctx, AV_LOG_ERROR, "y41p requires width to be divisible by 8.\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ avctx->bits_per_coded_sample = 12; ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int y41p_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ uint8_t *dst = buf; ++ uint8_t *y, *u, *v; ++ int i, j; ++ ++ if (buf_size < avctx->width * avctx->height * 1.5) { ++ av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->reference = 0; ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ for (i = avctx->height - 1; i >= 0; i--) { ++ y = &pic->data[0][i * pic->linesize[0]]; ++ u = &pic->data[1][i * pic->linesize[1]]; ++ v = &pic->data[2][i * pic->linesize[2]]; ++ for (j = 0; j < avctx->width; j += 8) { ++ *(dst++) = *(u++); ++ *(dst++) = *(y++); ++ *(dst++) = *(v++); ++ *(dst++) = *(y++); ++ ++ *(dst++) = *(u++); ++ *(dst++) = *(y++); ++ *(dst++) = *(v++); ++ *(dst++) = *(y++); ++ ++ *(dst++) = *(y++); ++ *(dst++) = *(y++); ++ *(dst++) = *(y++); ++ *(dst++) = *(y++); ++ } ++ } ++ ++ return avctx->width * avctx->height * 1.5; ++} ++ ++static av_cold int y41p_encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_y41p_encoder = { ++ .name = "y41p", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_Y41P, ++ .init = y41p_encode_init, ++ .encode = y41p_encode_frame, ++ .close = y41p_encode_close, ++ .pix_fmts = (const enum PixelFormat[]) { PIX_FMT_YUV411P, ++ PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed YUV 4:1:1 12-bit"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yop.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yop.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yop.c 2012-03-27 17:55:46.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yop.c 2012-05-14 14:08:54.611345557 +0200 +@@ -1,5 +1,4 @@ +-/** +- * @file ++/* + * Psygnosis YOP decoder + * + * Copyright (C) 2010 Mohamed Naufal Basheer +@@ -24,7 +23,7 @@ + */ + + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + #include "avcodec.h" + #include "get_bits.h" +@@ -92,6 +91,7 @@ + + avctx->pix_fmt = PIX_FMT_PAL8; + ++ avcodec_get_frame_defaults(&s->frame); + s->num_pal_colors = avctx->extradata[0]; + s->first_color[0] = avctx->extradata[1]; + s->first_color[1] = avctx->extradata[2]; +@@ -217,10 +217,13 @@ + firstcolor = s->first_color[is_odd_frame]; + palette = (uint32_t *)s->frame.data[1]; + +- for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) ++ for (i = 0; i < s->num_pal_colors; i++, s->srcptr += 3) { + palette[i + firstcolor] = (s->srcptr[0] << 18) | + (s->srcptr[1] << 10) | + (s->srcptr[2] << 2); ++ palette[i + firstcolor] |= 0xFF << 24 | ++ (palette[i + firstcolor] >> 6) & 0x30303; ++ } + + s->frame.palette_has_changed = 1; + +@@ -249,13 +252,12 @@ + } + + AVCodec ff_yop_decoder = { +- "yop", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_YOP, +- sizeof(YopDecContext), +- yop_decode_init, +- NULL, +- yop_decode_close, +- yop_decode_frame, ++ .name = "yop", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_YOP, ++ .priv_data_size = sizeof(YopDecContext), ++ .init = yop_decode_init, ++ .close = yop_decode_close, ++ .decode = yop_decode_frame, + .long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yuv4dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yuv4dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yuv4dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yuv4dec.c 2012-05-14 14:08:54.612345577 +0200 +@@ -0,0 +1,109 @@ ++/* ++ * libquicktime yuv4 decoder ++ * ++ * Copyright (c) 2011 Carl Eugen Hoyos ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++static av_cold int yuv4_decode_init(AVCodecContext *avctx) ++{ ++ avctx->pix_fmt = PIX_FMT_YUV420P; ++ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int yuv4_decode_frame(AVCodecContext *avctx, void *data, ++ int *data_size, AVPacket *avpkt) ++{ ++ AVFrame *pic = avctx->coded_frame; ++ const uint8_t *src = avpkt->data; ++ uint8_t *y, *u, *v; ++ int i, j; ++ ++ if (pic->data[0]) ++ avctx->release_buffer(avctx, pic); ++ ++ if (avpkt->size < 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1)) { ++ av_log(avctx, AV_LOG_ERROR, "Insufficient input data.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ pic->reference = 0; ++ ++ if (avctx->get_buffer(avctx, pic) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ pic->key_frame = 1; ++ pic->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = pic->data[0]; ++ u = pic->data[1]; ++ v = pic->data[2]; ++ ++ for (i = 0; i < (avctx->height + 1) >> 1; i++) { ++ for (j = 0; j < (avctx->width + 1) >> 1; j++) { ++ u[j] = *src++ ^ 0x80; ++ v[j] = *src++ ^ 0x80; ++ y[ 2 * j ] = *src++; ++ y[ 2 * j + 1] = *src++; ++ y[pic->linesize[0] + 2 * j ] = *src++; ++ y[pic->linesize[0] + 2 * j + 1] = *src++; ++ } ++ ++ y += 2 * pic->linesize[0]; ++ u += pic->linesize[1]; ++ v += pic->linesize[2]; ++ } ++ ++ *data_size = sizeof(AVFrame); ++ *(AVFrame *)data = *pic; ++ ++ return avpkt->size; ++} ++ ++static av_cold int yuv4_decode_close(AVCodecContext *avctx) ++{ ++ if (avctx->coded_frame->data[0]) ++ avctx->release_buffer(avctx, avctx->coded_frame); ++ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_yuv4_decoder = { ++ .name = "yuv4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_YUV4, ++ .init = yuv4_decode_init, ++ .decode = yuv4_decode_frame, ++ .close = yuv4_decode_close, ++ .capabilities = CODEC_CAP_DR1, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yuv4enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yuv4enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/yuv4enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/yuv4enc.c 2012-05-14 14:08:54.613345597 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * libquicktime yuv4 encoder ++ * ++ * Copyright (c) 2011 Carl Eugen Hoyos ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avcodec.h" ++ ++static av_cold int yuv4_encode_init(AVCodecContext *avctx) ++{ ++ avctx->coded_frame = avcodec_alloc_frame(); ++ ++ if (!avctx->coded_frame) { ++ av_log(avctx, AV_LOG_ERROR, "Could not allocate frame.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static int yuv4_encode_frame(AVCodecContext *avctx, uint8_t *buf, ++ int buf_size, void *data) ++{ ++ AVFrame *pic = data; ++ uint8_t *dst = buf; ++ uint8_t *y, *u, *v; ++ int i, j; ++ int output_size = 0; ++ ++ if (buf_size < 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1)) { ++ av_log(avctx, AV_LOG_ERROR, "Out buffer is too small.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ avctx->coded_frame->reference = 0; ++ avctx->coded_frame->key_frame = 1; ++ avctx->coded_frame->pict_type = AV_PICTURE_TYPE_I; ++ ++ y = pic->data[0]; ++ u = pic->data[1]; ++ v = pic->data[2]; ++ ++ for (i = 0; i < avctx->height + 1 >> 1; i++) { ++ for (j = 0; j < avctx->width + 1 >> 1; j++) { ++ *dst++ = u[j] ^ 0x80; ++ *dst++ = v[j] ^ 0x80; ++ *dst++ = y[ 2 * j ]; ++ *dst++ = y[ 2 * j + 1]; ++ *dst++ = y[pic->linesize[0] + 2 * j ]; ++ *dst++ = y[pic->linesize[0] + 2 * j + 1]; ++ output_size += 6; ++ } ++ y += 2 * pic->linesize[0]; ++ u += pic->linesize[1]; ++ v += pic->linesize[2]; ++ } ++ ++ return output_size; ++} ++ ++static av_cold int yuv4_encode_close(AVCodecContext *avctx) ++{ ++ av_freep(&avctx->coded_frame); ++ ++ return 0; ++} ++ ++AVCodec ff_yuv4_encoder = { ++ .name = "yuv4", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_YUV4, ++ .init = yuv4_encode_init, ++ .encode = yuv4_encode_frame, ++ .close = yuv4_encode_close, ++ .pix_fmts = (const enum PixelFormat[]){ PIX_FMT_YUV420P, PIX_FMT_NONE }, ++ .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/zmbv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/zmbv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/zmbv.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/zmbv.c 2012-05-14 14:08:54.615345637 +0200 +@@ -88,8 +88,8 @@ + output = c->cur; + prev = c->prev; + +- if(c->flags & ZMBV_DELTAPAL){ +- for(i = 0; i < 768; i++) ++ if (c->flags & ZMBV_DELTAPAL) { ++ for (i = 0; i < 768; i++) + c->pal[i] ^= *src++; + } + +@@ -97,9 +97,9 @@ + src += ((c->bx * c->by * 2 + 3) & ~3); + + block = 0; +- for(y = 0; y < c->height; y += c->bh) { ++ for (y = 0; y < c->height; y += c->bh) { + bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y); +- for(x = 0; x < c->width; x += c->bw) { ++ for (x = 0; x < c->width; x += c->bw) { + uint8_t *out, *tprev; + + d = mvec[block] & 1; +@@ -114,12 +114,12 @@ + tprev = prev + x + dx + dy * c->width; + mx = x + dx; + my = y + dy; +- for(j = 0; j < bh2; j++){ +- if((my + j < 0) || (my + j >= c->height)) { ++ for (j = 0; j < bh2; j++) { ++ if (my + j < 0 || my + j >= c->height) { + memset(out, 0, bw2); + } else { +- for(i = 0; i < bw2; i++){ +- if((mx + i < 0) || (mx + i >= c->width)) ++ for (i = 0; i < bw2; i++) { ++ if (mx + i < 0 || mx + i >= c->width) + out[i] = 0; + else + out[i] = tprev[i]; +@@ -129,10 +129,10 @@ + tprev += c->width; + } + +- if(d) { /* apply XOR'ed difference */ ++ if (d) { /* apply XOR'ed difference */ + out = output + x; +- for(j = 0; j < bh2; j++){ +- for(i = 0; i < bw2; i++) ++ for (j = 0; j < bh2; j++) { ++ for (i = 0; i < bw2; i++) + out[i] ^= *src++; + out += c->width; + } +@@ -141,8 +141,9 @@ + output += c->width * c->bh; + prev += c->width * c->bh; + } +- if(src - c->decomp_buf != c->decomp_len) +- av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); ++ if (src - c->decomp_buf != c->decomp_len) ++ av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", ++ src-c->decomp_buf, c->decomp_len); + return 0; + } + +@@ -168,9 +169,9 @@ + src += ((c->bx * c->by * 2 + 3) & ~3); + + block = 0; +- for(y = 0; y < c->height; y += c->bh) { ++ for (y = 0; y < c->height; y += c->bh) { + bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y); +- for(x = 0; x < c->width; x += c->bw) { ++ for (x = 0; x < c->width; x += c->bw) { + uint16_t *out, *tprev; + + d = mvec[block] & 1; +@@ -185,12 +186,12 @@ + tprev = prev + x + dx + dy * c->width; + mx = x + dx; + my = y + dy; +- for(j = 0; j < bh2; j++){ +- if((my + j < 0) || (my + j >= c->height)) { ++ for (j = 0; j < bh2; j++) { ++ if (my + j < 0 || my + j >= c->height) { + memset(out, 0, bw2 * 2); + } else { +- for(i = 0; i < bw2; i++){ +- if((mx + i < 0) || (mx + i >= c->width)) ++ for (i = 0; i < bw2; i++) { ++ if (mx + i < 0 || mx + i >= c->width) + out[i] = 0; + else + out[i] = tprev[i]; +@@ -200,10 +201,10 @@ + tprev += c->width; + } + +- if(d) { /* apply XOR'ed difference */ ++ if (d) { /* apply XOR'ed difference */ + out = output + x; +- for(j = 0; j < bh2; j++){ +- for(i = 0; i < bw2; i++) { ++ for (j = 0; j < bh2; j++){ ++ for (i = 0; i < bw2; i++) { + out[i] ^= *((uint16_t*)src); + src += 2; + } +@@ -214,8 +215,9 @@ + output += c->width * c->bh; + prev += c->width * c->bh; + } +- if(src - c->decomp_buf != c->decomp_len) +- av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); ++ if (src - c->decomp_buf != c->decomp_len) ++ av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", ++ src-c->decomp_buf, c->decomp_len); + return 0; + } + +@@ -244,9 +246,9 @@ + src += ((c->bx * c->by * 2 + 3) & ~3); + + block = 0; +- for(y = 0; y < c->height; y += c->bh) { ++ for (y = 0; y < c->height; y += c->bh) { + bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y); +- for(x = 0; x < c->width; x += c->bw) { ++ for (x = 0; x < c->width; x += c->bw) { + uint8_t *out, *tprev; + + d = mvec[block] & 1; +@@ -261,12 +263,12 @@ + tprev = prev + (x + dx) * 3 + dy * stride; + mx = x + dx; + my = y + dy; +- for(j = 0; j < bh2; j++){ +- if((my + j < 0) || (my + j >= c->height)) { ++ for (j = 0; j < bh2; j++) { ++ if (my + j < 0 || my + j >= c->height) { + memset(out, 0, bw2 * 3); + } else { +- for(i = 0; i < bw2; i++){ +- if((mx + i < 0) || (mx + i >= c->width)) { ++ for (i = 0; i < bw2; i++){ ++ if (mx + i < 0 || mx + i >= c->width) { + out[i * 3 + 0] = 0; + out[i * 3 + 1] = 0; + out[i * 3 + 2] = 0; +@@ -281,10 +283,10 @@ + tprev += stride; + } + +- if(d) { /* apply XOR'ed difference */ ++ if (d) { /* apply XOR'ed difference */ + out = output + x * 3; +- for(j = 0; j < bh2; j++){ +- for(i = 0; i < bw2; i++) { ++ for (j = 0; j < bh2; j++) { ++ for (i = 0; i < bw2; i++) { + out[i * 3 + 0] ^= *src++; + out[i * 3 + 1] ^= *src++; + out[i * 3 + 2] ^= *src++; +@@ -296,8 +298,9 @@ + output += stride * c->bh; + prev += stride * c->bh; + } +- if(src - c->decomp_buf != c->decomp_len) +- av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", src-c->decomp_buf, c->decomp_len); ++ if (src - c->decomp_buf != c->decomp_len) ++ av_log(c->avctx, AV_LOG_ERROR, "Used %i of %i bytes\n", ++ src-c->decomp_buf, c->decomp_len); + return 0; + } + #endif //ZMBV_ENABLE_24BPP +@@ -324,9 +327,9 @@ + src += ((c->bx * c->by * 2 + 3) & ~3); + + block = 0; +- for(y = 0; y < c->height; y += c->bh) { ++ for (y = 0; y < c->height; y += c->bh) { + bh2 = ((c->height - y) > c->bh) ? c->bh : (c->height - y); +- for(x = 0; x < c->width; x += c->bw) { ++ for (x = 0; x < c->width; x += c->bw) { + uint32_t *out, *tprev; + + d = mvec[block] & 1; +@@ -341,12 +344,12 @@ + tprev = prev + x + dx + dy * c->width; + mx = x + dx; + my = y + dy; +- for(j = 0; j < bh2; j++){ +- if((my + j < 0) || (my + j >= c->height)) { ++ for (j = 0; j < bh2; j++) { ++ if (my + j < 0 || my + j >= c->height) { + memset(out, 0, bw2 * 4); + } else { +- for(i = 0; i < bw2; i++){ +- if((mx + i < 0) || (mx + i >= c->width)) ++ for (i = 0; i < bw2; i++){ ++ if (mx + i < 0 || mx + i >= c->width) + out[i] = 0; + else + out[i] = tprev[i]; +@@ -356,11 +359,11 @@ + tprev += c->width; + } + +- if(d) { /* apply XOR'ed difference */ ++ if (d) { /* apply XOR'ed difference */ + out = output + x; +- for(j = 0; j < bh2; j++){ +- for(i = 0; i < bw2; i++) { +- out[i] ^= *((uint32_t*)src); ++ for (j = 0; j < bh2; j++){ ++ for (i = 0; i < bw2; i++) { ++ out[i] ^= *((uint32_t *) src); + src += 4; + } + out += c->width; +@@ -368,10 +371,11 @@ + } + } + output += c->width * c->bh; +- prev += c->width * c->bh; ++ prev += c->width * c->bh; + } +- if(src - c->decomp_buf != c->decomp_len) +- av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", src-c->decomp_buf, c->decomp_len); ++ if (src - c->decomp_buf != c->decomp_len) ++ av_log(c->avctx, AV_LOG_ERROR, "Used %ti of %i bytes\n", ++ src-c->decomp_buf, c->decomp_len); + return 0; + } + +@@ -401,12 +405,12 @@ + int len = buf_size; + int hi_ver, lo_ver; + +- if(c->pic.data[0]) ++ if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); + +- c->pic.reference = 1; ++ c->pic.reference = 3; + c->pic.buffer_hints = FF_BUFFER_HINTS_VALID; +- if(avctx->get_buffer(avctx, &c->pic) < 0){ ++ if (avctx->get_buffer(avctx, &c->pic) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return -1; + } +@@ -414,7 +418,9 @@ + /* parse header */ + c->flags = buf[0]; + buf++; len--; +- if(c->flags & ZMBV_KEYFRAME) { ++ if (c->flags & ZMBV_KEYFRAME) { ++ void *decode_intra = NULL; ++ c->decode_intra= NULL; + hi_ver = buf[0]; + lo_ver = buf[1]; + c->comp = buf[2]; +@@ -424,48 +430,53 @@ + + buf += 6; + len -= 6; +- av_log(avctx, AV_LOG_DEBUG, "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n",c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh); +- if(hi_ver != 0 || lo_ver != 1) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", hi_ver, lo_ver); ++ av_log(avctx, AV_LOG_DEBUG, ++ "Flags=%X ver=%i.%i comp=%i fmt=%i blk=%ix%i\n", ++ c->flags,hi_ver,lo_ver,c->comp,c->fmt,c->bw,c->bh); ++ if (hi_ver != 0 || lo_ver != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported version %i.%i\n", ++ hi_ver, lo_ver); + return -1; + } +- if(c->bw == 0 || c->bh == 0) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", c->bw, c->bh); ++ if (c->bw == 0 || c->bh == 0) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported block size %ix%i\n", ++ c->bw, c->bh); + return -1; + } +- if(c->comp != 0 && c->comp != 1) { +- av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", c->comp); ++ if (c->comp != 0 && c->comp != 1) { ++ av_log(avctx, AV_LOG_ERROR, "Unsupported compression type %i\n", ++ c->comp); + return -1; + } + +- switch(c->fmt) { ++ switch (c->fmt) { + case ZMBV_FMT_8BPP: + c->bpp = 8; +- c->decode_intra = zmbv_decode_intra; ++ decode_intra = zmbv_decode_intra; + c->decode_xor = zmbv_decode_xor_8; + break; + case ZMBV_FMT_15BPP: + case ZMBV_FMT_16BPP: + c->bpp = 16; +- c->decode_intra = zmbv_decode_intra; ++ decode_intra = zmbv_decode_intra; + c->decode_xor = zmbv_decode_xor_16; + break; + #ifdef ZMBV_ENABLE_24BPP + case ZMBV_FMT_24BPP: + c->bpp = 24; +- c->decode_intra = zmbv_decode_intra; ++ decode_intra = zmbv_decode_intra; + c->decode_xor = zmbv_decode_xor_24; + break; + #endif //ZMBV_ENABLE_24BPP + case ZMBV_FMT_32BPP: + c->bpp = 32; +- c->decode_intra = zmbv_decode_intra; ++ decode_intra = zmbv_decode_intra; + c->decode_xor = zmbv_decode_xor_32; + break; + default: +- c->decode_intra = NULL; + c->decode_xor = NULL; +- av_log(avctx, AV_LOG_ERROR, "Unsupported (for now) format %i\n", c->fmt); ++ av_log(avctx, AV_LOG_ERROR, ++ "Unsupported (for now) format %i\n", c->fmt); + return -1; + } + +@@ -475,18 +486,21 @@ + return -1; + } + +- c->cur = av_realloc(c->cur, avctx->width * avctx->height * (c->bpp / 8)); +- c->prev = av_realloc(c->prev, avctx->width * avctx->height * (c->bpp / 8)); ++ c->cur = av_realloc_f(c->cur, avctx->width * avctx->height, (c->bpp / 8)); ++ c->prev = av_realloc_f(c->prev, avctx->width * avctx->height, (c->bpp / 8)); + c->bx = (c->width + c->bw - 1) / c->bw; + c->by = (c->height+ c->bh - 1) / c->bh; ++ if (!c->cur || !c->prev) ++ return -1; ++ c->decode_intra= decode_intra; + } + +- if(c->decode_intra == NULL) { ++ if (c->decode_intra == NULL) { + av_log(avctx, AV_LOG_ERROR, "Error! Got no format or no keyframe!\n"); + return -1; + } + +- if(c->comp == 0) { //Uncompressed data ++ if (c->comp == 0) { //Uncompressed data + memcpy(c->decomp_buf, buf, len); + c->decomp_size = 1; + } else { // ZLIB-compressed data +@@ -498,14 +512,14 @@ + inflate(&c->zstream, Z_FINISH); + c->decomp_len = c->zstream.total_out; + } +- if(c->flags & ZMBV_KEYFRAME) { ++ if (c->flags & ZMBV_KEYFRAME) { + c->pic.key_frame = 1; +- c->pic.pict_type = FF_I_TYPE; ++ c->pic.pict_type = AV_PICTURE_TYPE_I; + c->decode_intra(c); + } else { + c->pic.key_frame = 0; +- c->pic.pict_type = FF_P_TYPE; +- if(c->decomp_len) ++ c->pic.pict_type = AV_PICTURE_TYPE_P; ++ if (c->decomp_len) + c->decode_xor(c); + } + +@@ -516,10 +530,10 @@ + + out = c->pic.data[0]; + src = c->cur; +- switch(c->fmt) { ++ switch (c->fmt) { + case ZMBV_FMT_8BPP: +- for(j = 0; j < c->height; j++) { +- for(i = 0; i < c->width; i++) { ++ for (j = 0; j < c->height; j++) { ++ for (i = 0; i < c->width; i++) { + out[i * 3 + 0] = c->pal[(*src) * 3 + 0]; + out[i * 3 + 1] = c->pal[(*src) * 3 + 1]; + out[i * 3 + 2] = c->pal[(*src) * 3 + 2]; +@@ -529,8 +543,8 @@ + } + break; + case ZMBV_FMT_15BPP: +- for(j = 0; j < c->height; j++) { +- for(i = 0; i < c->width; i++) { ++ for (j = 0; j < c->height; j++) { ++ for (i = 0; i < c->width; i++) { + uint16_t tmp = AV_RL16(src); + src += 2; + out[i * 3 + 0] = (tmp & 0x7C00) >> 7; +@@ -541,8 +555,8 @@ + } + break; + case ZMBV_FMT_16BPP: +- for(j = 0; j < c->height; j++) { +- for(i = 0; i < c->width; i++) { ++ for (j = 0; j < c->height; j++) { ++ for (i = 0; i < c->width; i++) { + uint16_t tmp = AV_RL16(src); + src += 2; + out[i * 3 + 0] = (tmp & 0xF800) >> 8; +@@ -554,7 +568,7 @@ + break; + #ifdef ZMBV_ENABLE_24BPP + case ZMBV_FMT_24BPP: +- for(j = 0; j < c->height; j++) { ++ for (j = 0; j < c->height; j++) { + memcpy(out, src, c->width * 3); + src += c->width * 3; + out += c->pic.linesize[0]; +@@ -562,8 +576,8 @@ + break; + #endif //ZMBV_ENABLE_24BPP + case ZMBV_FMT_32BPP: +- for(j = 0; j < c->height; j++) { +- for(i = 0; i < c->width; i++) { ++ for (j = 0; j < c->height; j++) { ++ for (i = 0; i < c->width; i++) { + uint32_t tmp = AV_RL32(src); + src += 4; + AV_WB24(out+(i*3), tmp); +@@ -574,7 +588,7 @@ + default: + av_log(avctx, AV_LOG_ERROR, "Cannot handle format %i\n", c->fmt); + } +- memcpy(c->prev, c->cur, c->width * c->height * (c->bpp / 8)); ++ FFSWAP(uint8_t *, c->cur, c->prev); + } + *data_size = sizeof(AVFrame); + *(AVFrame*)data = c->pic; +@@ -599,11 +613,12 @@ + + c->width = avctx->width; + c->height = avctx->height; ++ avcodec_get_frame_defaults(&c->pic); + + c->bpp = avctx->bits_per_coded_sample; + + // Needed if zlib unused or init aborted before inflateInit +- memset(&(c->zstream), 0, sizeof(z_stream)); ++ memset(&c->zstream, 0, sizeof(z_stream)); + + avctx->pix_fmt = PIX_FMT_RGB24; + c->decomp_size = (avctx->width + 255) * 4 * (avctx->height + 64); +@@ -611,7 +626,8 @@ + /* Allocate decompression buffer */ + if (c->decomp_size) { + if ((c->decomp_buf = av_malloc(c->decomp_size)) == NULL) { +- av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); ++ av_log(avctx, AV_LOG_ERROR, ++ "Can't allocate decompression buffer.\n"); + return 1; + } + } +@@ -619,7 +635,7 @@ + c->zstream.zalloc = Z_NULL; + c->zstream.zfree = Z_NULL; + c->zstream.opaque = Z_NULL; +- zret = inflateInit(&(c->zstream)); ++ zret = inflateInit(&c->zstream); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return 1; +@@ -643,7 +659,7 @@ + + if (c->pic.data[0]) + avctx->release_buffer(avctx, &c->pic); +- inflateEnd(&(c->zstream)); ++ inflateEnd(&c->zstream); + av_freep(&c->cur); + av_freep(&c->prev); + +@@ -651,15 +667,14 @@ + } + + AVCodec ff_zmbv_decoder = { +- "zmbv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ZMBV, +- sizeof(ZmbvContext), +- decode_init, +- NULL, +- decode_end, +- decode_frame, +- CODEC_CAP_DR1, ++ .name = "zmbv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ZMBV, ++ .priv_data_size = sizeof(ZmbvContext), ++ .init = decode_init, ++ .close = decode_end, ++ .decode = decode_frame, ++ .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"), + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/zmbvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/zmbvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcodec/zmbvenc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcodec/zmbvenc.c 2012-05-14 14:08:54.616345657 +0200 +@@ -134,7 +134,7 @@ + if(c->curfrm == c->keyint) + c->curfrm = 0; + *p = *pict; +- p->pict_type= keyframe ? FF_I_TYPE : FF_P_TYPE; ++ p->pict_type= keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; + p->key_frame= keyframe; + chpal = !keyframe && memcmp(p->data[1], c->pal2, 1024); + +@@ -181,7 +181,7 @@ + int x, y, bh2, bw2, xored; + uint8_t *tsrc, *tprev; + uint8_t *mv; +- int mx, my, bv; ++ int mx, my; + + bw = (avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK; + bh = (avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK; +@@ -197,7 +197,7 @@ + tsrc = src + x; + tprev = prev + x; + +- bv = zmbv_me(c, tsrc, p->linesize[0], tprev, c->pstride, x, y, &mx, &my, &xored); ++ zmbv_me(c, tsrc, p->linesize[0], tprev, c->pstride, x, y, &mx, &my, &xored); + mv[0] = (mx << 1) | !!xored; + mv[1] = my << 1; + tprev += mx + my * c->pstride; +@@ -269,7 +269,7 @@ + } + + // Needed if zlib unused or init aborted before deflateInit +- memset(&(c->zstream), 0, sizeof(z_stream)); ++ memset(&c->zstream, 0, sizeof(z_stream)); + c->comp_size = avctx->width * avctx->height + 1024 + + ((avctx->width + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * ((avctx->height + ZMBV_BLOCK - 1) / ZMBV_BLOCK) * 2 + 4; + if ((c->work_buf = av_malloc(c->comp_size)) == NULL) { +@@ -294,7 +294,7 @@ + c->zstream.zalloc = Z_NULL; + c->zstream.zfree = Z_NULL; + c->zstream.opaque = Z_NULL; +- zret = deflateInit(&(c->zstream), lvl); ++ zret = deflateInit(&c->zstream, lvl); + if (zret != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Inflate init error: %d\n", zret); + return -1; +@@ -317,20 +317,20 @@ + av_freep(&c->comp_buf); + av_freep(&c->work_buf); + +- deflateEnd(&(c->zstream)); ++ deflateEnd(&c->zstream); + av_freep(&c->prev); + + return 0; + } + + AVCodec ff_zmbv_encoder = { +- "zmbv", +- AVMEDIA_TYPE_VIDEO, +- CODEC_ID_ZMBV, +- sizeof(ZmbvEncContext), +- encode_init, +- encode_frame, +- encode_end, ++ .name = "zmbv", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_ZMBV, ++ .priv_data_size = sizeof(ZmbvEncContext), ++ .init = encode_init, ++ .encode = encode_frame, ++ .close = encode_end, + .pix_fmts = (const enum PixelFormat[]){PIX_FMT_PAL8, PIX_FMT_NONE}, + .long_name = NULL_IF_CONFIG_SMALL("Zip Motion Blocks Video"), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/audioconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/audioconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/audioconvert.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/audioconvert.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,116 +0,0 @@ +-/* +- * Copyright (c) 2006 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * audio conversion routines +- */ +- +-#include "libavutil/avstring.h" +-#include "audioconvert.h" +- +-static const char * const channel_names[] = { +- "FL", "FR", "FC", "LFE", "BL", "BR", "FLC", "FRC", +- "BC", "SL", "SR", "TC", "TFL", "TFC", "TFR", "TBL", +- "TBC", "TBR", +- [29] = "DL", +- [30] = "DR", +-}; +- +-static const char *get_channel_name(int channel_id) +-{ +- if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names)) +- return NULL; +- return channel_names[channel_id]; +-} +- +-static const struct { +- const char *name; +- int nb_channels; +- int64_t layout; +-} channel_layout_map[] = { +- { "mono", 1, AV_CH_LAYOUT_MONO }, +- { "stereo", 2, AV_CH_LAYOUT_STEREO }, +- { "4.0", 4, AV_CH_LAYOUT_4POINT0 }, +- { "quad", 4, AV_CH_LAYOUT_QUAD }, +- { "5.0", 5, AV_CH_LAYOUT_5POINT0 }, +- { "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK }, +- { "5.1", 6, AV_CH_LAYOUT_5POINT1 }, +- { "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK }, +- { "5.1+downmix", 8, AV_CH_LAYOUT_5POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, }, +- { "7.1", 8, AV_CH_LAYOUT_7POINT1 }, +- { "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE }, +- { "7.1+downmix", 10, AV_CH_LAYOUT_7POINT1|AV_CH_LAYOUT_STEREO_DOWNMIX, }, +- { 0 } +-}; +- +-int64_t av_get_channel_layout(const char *name) +-{ +- int i = 0; +- do { +- if (!strcmp(channel_layout_map[i].name, name)) +- return channel_layout_map[i].layout; +- i++; +- } while (channel_layout_map[i].name); +- +- return 0; +-} +- +-void av_get_channel_layout_string(char *buf, int buf_size, +- int nb_channels, int64_t channel_layout) +-{ +- int i; +- +- if (nb_channels <= 0) +- nb_channels = av_get_channel_layout_nb_channels(channel_layout); +- +- for (i = 0; channel_layout_map[i].name; i++) +- if (nb_channels == channel_layout_map[i].nb_channels && +- channel_layout == channel_layout_map[i].layout) { +- av_strlcpy(buf, channel_layout_map[i].name, buf_size); +- return; +- } +- +- snprintf(buf, buf_size, "%d channels", nb_channels); +- if (channel_layout) { +- int i,ch; +- av_strlcat(buf, " (", buf_size); +- for(i=0,ch=0; i<64; i++) { +- if ((channel_layout & (1L<0) av_strlcat(buf, "|", buf_size); +- av_strlcat(buf, name, buf_size); +- } +- ch++; +- } +- } +- av_strlcat(buf, ")", buf_size); +- } +-} +- +-int av_get_channel_layout_nb_channels(int64_t channel_layout) +-{ +- int count; +- uint64_t x = channel_layout; +- for (count = 0; x; count++) +- x &= x-1; // unset lowest set bit +- return count; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/audioconvert.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/audioconvert.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/audioconvert.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/audioconvert.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,95 +0,0 @@ +-/* +- * Copyright (c) 2006 Michael Niedermayer +- * Copyright (c) 2008 Peter Ross +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_AUDIOCONVERT_H +-#define AVCORE_AUDIOCONVERT_H +- +-/** +- * @file +- * audio conversion routines +- */ +- +-#include "avcore.h" +- +-/* Audio channel masks */ +-#define AV_CH_FRONT_LEFT 0x00000001 +-#define AV_CH_FRONT_RIGHT 0x00000002 +-#define AV_CH_FRONT_CENTER 0x00000004 +-#define AV_CH_LOW_FREQUENCY 0x00000008 +-#define AV_CH_BACK_LEFT 0x00000010 +-#define AV_CH_BACK_RIGHT 0x00000020 +-#define AV_CH_FRONT_LEFT_OF_CENTER 0x00000040 +-#define AV_CH_FRONT_RIGHT_OF_CENTER 0x00000080 +-#define AV_CH_BACK_CENTER 0x00000100 +-#define AV_CH_SIDE_LEFT 0x00000200 +-#define AV_CH_SIDE_RIGHT 0x00000400 +-#define AV_CH_TOP_CENTER 0x00000800 +-#define AV_CH_TOP_FRONT_LEFT 0x00001000 +-#define AV_CH_TOP_FRONT_CENTER 0x00002000 +-#define AV_CH_TOP_FRONT_RIGHT 0x00004000 +-#define AV_CH_TOP_BACK_LEFT 0x00008000 +-#define AV_CH_TOP_BACK_CENTER 0x00010000 +-#define AV_CH_TOP_BACK_RIGHT 0x00020000 +-#define AV_CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. +-#define AV_CH_STEREO_RIGHT 0x40000000 ///< See AV_CH_STEREO_LEFT. +- +-/** Channel mask value used for AVCodecContext.request_channel_layout +- to indicate that the user requests the channel order of the decoder output +- to be the native codec channel order. */ +-#define AV_CH_LAYOUT_NATIVE 0x8000000000000000LL +- +-/* Audio channel convenience macros */ +-#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER) +-#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT) +-#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER) +-#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) +-#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER) +-#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT) +-#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) +-#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT) +-#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY) +-#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) +-#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY) +-#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) +-#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) +-#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER) +-#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT) +- +-/** +- * Return a channel layout id that matches name, 0 if no match. +- */ +-int64_t av_get_channel_layout(const char *name); +- +-/** +- * Return a description of a channel layout. +- * If nb_channels is <= 0, it is guessed from the channel_layout. +- * +- * @param buf put here the string containing the channel layout +- * @param buf_size size in bytes of the buffer +- */ +-void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, int64_t channel_layout); +- +-/** +- * Return the number of channels in the channel layout. +- */ +-int av_get_channel_layout_nb_channels(int64_t channel_layout); +- +-#endif /* AVCORE_AUDIOCONVERT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/avcore.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/avcore.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/avcore.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/avcore.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,70 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_AVCORE_H +-#define AVCORE_AVCORE_H +- +-/** +- * @file +- * shared media utilities for the libav* libraries +- */ +- +-#include "libavutil/avutil.h" +- +-#define LIBAVCORE_VERSION_MAJOR 0 +-#define LIBAVCORE_VERSION_MINOR 16 +-#define LIBAVCORE_VERSION_MICRO 1 +- +-#define LIBAVCORE_VERSION_INT AV_VERSION_INT(LIBAVCORE_VERSION_MAJOR, \ +- LIBAVCORE_VERSION_MINOR, \ +- LIBAVCORE_VERSION_MICRO) +-#define LIBAVCORE_VERSION AV_VERSION(LIBAVCORE_VERSION_MAJOR, \ +- LIBAVCORE_VERSION_MINOR, \ +- LIBAVCORE_VERSION_MICRO) +-#define LIBAVCORE_BUILD LIBAVCORE_VERSION_INT +- +-#define LIBAVCORE_IDENT "Lavcore" AV_STRINGIFY(LIBAVCORE_VERSION) +- +-/** +- * Return the LIBAVCORE_VERSION_INT constant. +- */ +-unsigned avcore_version(void); +- +-/** +- * Return the libavcore build-time configuration. +- */ +-const char *avcore_configuration(void); +- +-/** +- * Return the libavcore license. +- */ +-const char *avcore_license(void); +- +-#define AV_NOPTS_VALUE INT64_C(0x8000000000000000) +-#define AV_TIME_BASE 1000000 +-#define AV_TIME_BASE_Q (AVRational){1, AV_TIME_BASE} +- +-/** +- * Those FF_API_* defines are not part of public API. +- * They may change, break or disappear at any time. +- */ +-#ifndef FF_API_OLD_IMAGE_NAMES +-#define FF_API_OLD_IMAGE_NAMES (LIBAVCORE_VERSION_MAJOR < 1) +-#endif +- +-#endif /* AVCORE_AVCORE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/imgutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/imgutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/imgutils.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/imgutils.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,297 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * misc image utilities +- */ +- +-#include "imgutils.h" +-#include "internal.h" +-#include "libavutil/pixdesc.h" +- +-void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], +- const AVPixFmtDescriptor *pixdesc) +-{ +- int i; +- memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0])); +- if (max_pixstep_comps) +- memset(max_pixstep_comps, 0, 4*sizeof(max_pixstep_comps[0])); +- +- for (i = 0; i < 4; i++) { +- const AVComponentDescriptor *comp = &(pixdesc->comp[i]); +- if ((comp->step_minus1+1) > max_pixsteps[comp->plane]) { +- max_pixsteps[comp->plane] = comp->step_minus1+1; +- if (max_pixstep_comps) +- max_pixstep_comps[comp->plane] = i; +- } +- } +-} +- +-int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane) +-{ +- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; +- int max_step [4]; /* max pixel step for each plane */ +- int max_step_comp[4]; /* the component for each plane which has the max pixel step */ +- int s; +- +- if (desc->flags & PIX_FMT_BITSTREAM) +- return (width * (desc->comp[0].step_minus1+1) + 7) >> 3; +- +- av_image_fill_max_pixsteps(max_step, max_step_comp, desc); +- s = (max_step_comp[plane] == 1 || max_step_comp[plane] == 2) ? desc->log2_chroma_w : 0; +- return max_step[plane] * (((width + (1 << s) - 1)) >> s); +-} +- +-int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) +-{ +- int i; +- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; +- int max_step [4]; /* max pixel step for each plane */ +- int max_step_comp[4]; /* the component for each plane which has the max pixel step */ +- +- memset(linesizes, 0, 4*sizeof(linesizes[0])); +- +- if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) +- return AVERROR(EINVAL); +- +- if (desc->flags & PIX_FMT_BITSTREAM) { +- if (width > (INT_MAX -7) / (desc->comp[0].step_minus1+1)) +- return AVERROR(EINVAL); +- linesizes[0] = (width * (desc->comp[0].step_minus1+1) + 7) >> 3; +- return 0; +- } +- +- av_image_fill_max_pixsteps(max_step, max_step_comp, desc); +- for (i = 0; i < 4; i++) { +- int s = (max_step_comp[i] == 1 || max_step_comp[i] == 2) ? desc->log2_chroma_w : 0; +- int shifted_w = ((width + (1 << s) - 1)) >> s; +- if (max_step[i] > INT_MAX / shifted_w) +- return AVERROR(EINVAL); +- linesizes[i] = max_step[i] * shifted_w; +- } +- +- return 0; +-} +- +-int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, +- uint8_t *ptr, const int linesizes[4]) +-{ +- int i, total_size, size[4], has_plane[4]; +- +- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; +- memset(data , 0, sizeof(data[0])*4); +- memset(size , 0, sizeof(size)); +- memset(has_plane, 0, sizeof(has_plane)); +- +- if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) +- return AVERROR(EINVAL); +- +- data[0] = ptr; +- if (linesizes[0] > (INT_MAX - 1024) / height) +- return AVERROR(EINVAL); +- size[0] = linesizes[0] * height; +- +- if (desc->flags & PIX_FMT_PAL) { +- size[0] = (size[0] + 3) & ~3; +- data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */ +- return size[0] + 256 * 4; +- } +- +- for (i = 0; i < 4; i++) +- has_plane[desc->comp[i].plane] = 1; +- +- total_size = size[0]; +- for (i = 1; has_plane[i] && i < 4; i++) { +- int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0; +- data[i] = data[i-1] + size[i-1]; +- h = (height + (1 << s) - 1) >> s; +- if (linesizes[i] > INT_MAX / h) +- return AVERROR(EINVAL); +- size[i] = h * linesizes[i]; +- if (total_size > INT_MAX - size[i]) +- return AVERROR(EINVAL); +- total_size += size[i]; +- } +- +- return total_size; +-} +- +-int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt) +-{ +- int i; +- +- for (i = 0; i < 256; i++) { +- int r, g, b; +- +- switch (pix_fmt) { +- case PIX_FMT_RGB8: +- r = (i>>5 )*36; +- g = ((i>>2)&7)*36; +- b = (i&3 )*85; +- break; +- case PIX_FMT_BGR8: +- b = (i>>6 )*85; +- g = ((i>>3)&7)*36; +- r = (i&7 )*36; +- break; +- case PIX_FMT_RGB4_BYTE: +- r = (i>>3 )*255; +- g = ((i>>1)&3)*85; +- b = (i&1 )*255; +- break; +- case PIX_FMT_BGR4_BYTE: +- b = (i>>3 )*255; +- g = ((i>>1)&3)*85; +- r = (i&1 )*255; +- break; +- case PIX_FMT_GRAY8: +- r = b = g = i; +- break; +- default: +- return AVERROR(EINVAL); +- } +- pal[i] = b + (g<<8) + (r<<16); +- } +- +- return 0; +-} +- +-int av_image_alloc(uint8_t *pointers[4], int linesizes[4], +- int w, int h, enum PixelFormat pix_fmt, int align) +-{ +- int i, ret; +- uint8_t *buf; +- +- if ((ret = av_image_check_size(w, h, 0, NULL)) < 0) +- return ret; +- if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, w)) < 0) +- return ret; +- +- for (i = 0; i < 4; i++) +- linesizes[i] = FFALIGN(linesizes[i], align); +- +- if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, NULL, linesizes)) < 0) +- return ret; +- buf = av_malloc(ret + align); +- if (!buf) +- return AVERROR(ENOMEM); +- if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) { +- av_free(buf); +- return ret; +- } +- if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL) +- ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt); +- +- return ret; +-} +- +-typedef struct ImgUtils { +- const AVClass *class; +- int log_offset; +- void *log_ctx; +-} ImgUtils; +- +-static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) }; +- +-int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) +-{ +- ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; +- +- if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) +- return 0; +- +- av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h); +- return AVERROR(EINVAL); +-} +- +-void av_image_copy_plane(uint8_t *dst, int dst_linesize, +- const uint8_t *src, int src_linesize, +- int bytewidth, int height) +-{ +- if (!dst || !src) +- return; +- for (;height > 0; height--) { +- memcpy(dst, src, bytewidth); +- dst += dst_linesize; +- src += src_linesize; +- } +-} +- +-void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], +- const uint8_t *src_data[4], const int src_linesizes[4], +- enum PixelFormat pix_fmt, int width, int height) +-{ +- const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; +- +- if (desc->flags & PIX_FMT_HWACCEL) +- return; +- +- if (desc->flags & PIX_FMT_PAL) { +- av_image_copy_plane(dst_data[0], dst_linesizes[0], +- src_data[0], src_linesizes[0], +- width, height); +- /* copy the palette */ +- memcpy(dst_data[1], src_data[1], 4*256); +- } else { +- int i, planes_nb = 0; +- +- for (i = 0; i < desc->nb_components; i++) +- planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1); +- +- for (i = 0; i < planes_nb; i++) { +- int h = height; +- int bwidth = av_image_get_linesize(pix_fmt, width, i); +- if (i == 1 || i == 2) { +- h= -((-height)>>desc->log2_chroma_h); +- } +- av_image_copy_plane(dst_data[i], dst_linesizes[i], +- src_data[i], src_linesizes[i], +- bwidth, h); +- } +- } +-} +- +-#if FF_API_OLD_IMAGE_NAMES +-void av_fill_image_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], +- const AVPixFmtDescriptor *pixdesc) +-{ +- av_image_fill_max_pixsteps(max_pixsteps, max_pixstep_comps, pixdesc); +-} +- +-int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane) +-{ +- return av_image_get_linesize(pix_fmt, width, plane); +-} +- +-int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) +-{ +- return av_image_fill_linesizes(linesizes, pix_fmt, width); +-} +- +-int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, +- uint8_t *ptr, const int linesizes[4]) +-{ +- return av_image_fill_pointers(data, pix_fmt, height, ptr, linesizes); +-} +- +-int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) +-{ +- return av_image_check_size(w, h, log_offset, log_ctx); +-} +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/imgutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/imgutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/imgutils.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/imgutils.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,147 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_IMGUTILS_H +-#define AVCORE_IMGUTILS_H +- +-/** +- * @file +- * misc image utilities +- */ +- +-#include "libavutil/pixdesc.h" +-#include "avcore.h" +- +-/** +- * Compute the max pixel step for each plane of an image with a +- * format described by pixdesc. +- * +- * The pixel step is the distance in bytes between the first byte of +- * the group of bytes which describe a pixel component and the first +- * byte of the successive group in the same plane for the same +- * component. +- * +- * @param max_pixsteps an array which is filled with the max pixel step +- * for each plane. Since a plane may contain different pixel +- * components, the computed max_pixsteps[plane] is relative to the +- * component in the plane with the max pixel step. +- * @param max_pixstep_comps an array which is filled with the component +- * for each plane which has the max pixel step. May be NULL. +- */ +-void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], +- const AVPixFmtDescriptor *pixdesc); +- +-/** +- * Compute the size of an image line with format pix_fmt and width +- * width for the plane plane. +- * +- * @return the computed size in bytes +- */ +-int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane); +- +-/** +- * Fill plane linesizes for an image with pixel format pix_fmt and +- * width width. +- * +- * @param linesizes array to be filled with the linesize for each plane +- * @return >= 0 in case of success, a negative error code otherwise +- */ +-int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width); +- +-/** +- * Fill plane data pointers for an image with pixel format pix_fmt and +- * height height. +- * +- * @param data pointers array to be filled with the pointer for each image plane +- * @param ptr the pointer to a buffer which will contain the image +- * @param linesizes[4] the array containing the linesize for each +- * plane, should be filled by av_image_fill_linesizes() +- * @return the size in bytes required for the image buffer, a negative +- * error code in case of failure +- */ +-int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, +- uint8_t *ptr, const int linesizes[4]); +- +-/** +- * Allocate an image with size w and h and pixel format pix_fmt, and +- * fill pointers and linesizes accordingly. +- * The allocated image buffer has to be freed by using +- * av_freep(&pointers[0]). +- * +- * @param align the value to use for buffer size alignment +- * @return the size in bytes required for the image buffer, a negative +- * error code in case of failure +- */ +-int av_image_alloc(uint8_t *pointers[4], int linesizes[4], +- int w, int h, enum PixelFormat pix_fmt, int align); +- +-/** +- * Copy image plane from src to dst. +- * That is, copy "height" number of lines of "bytewidth" bytes each. +- * The first byte of each successive line is separated by *_linesize +- * bytes. +- * +- * @param dst_linesize linesize for the image plane in dst +- * @param src_linesize linesize for the image plane in src +- */ +-void av_image_copy_plane(uint8_t *dst, int dst_linesize, +- const uint8_t *src, int src_linesize, +- int bytewidth, int height); +- +-/** +- * Copy image in src_data to dst_data. +- * +- * @param dst_linesize linesizes for the image in dst_data +- * @param src_linesize linesizes for the image in src_data +- */ +-void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], +- const uint8_t *src_data[4], const int src_linesizes[4], +- enum PixelFormat pix_fmt, int width, int height); +- +-/** +- * Check if the given dimension of an image is valid, meaning that all +- * bytes of the image can be addressed with a signed int. +- * +- * @param w the width of the picture +- * @param h the height of the picture +- * @param log_offset the offset to sum to the log level for logging with log_ctx +- * @param log_ctx the parent logging context, it may be NULL +- * @return >= 0 if valid, a negative error code otherwise +- */ +-int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); +- +-#if FF_API_OLD_IMAGE_NAMES +-attribute_deprecated +-void av_fill_image_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], +- const AVPixFmtDescriptor *pixdesc); +- +-attribute_deprecated +-int av_get_image_linesize(enum PixelFormat pix_fmt, int width, int plane); +- +-attribute_deprecated +-int av_fill_image_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width); +- +-attribute_deprecated +-int av_fill_image_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, +- uint8_t *ptr, const int linesizes[4]); +- +-attribute_deprecated +-int av_check_image_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); +-#endif +- +-#endif /* AVCORE_IMGUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/internal.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/internal.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,31 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_INTERNAL_H +-#define AVCORE_INTERNAL_H +- +-/** +- * @file +- * internal functions +- */ +- +-#include "avcore.h" +- +-int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt); +- +-#endif /* AVCORE_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/libavcore.v xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/libavcore.v +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/libavcore.v 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/libavcore.v 1970-01-01 01:00:00.000000000 +0100 +@@ -1,4 +0,0 @@ +-LIBAVCORE_$MAJOR { +- global: av_*; ff_*; avcore*; +- local: *; +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/Makefile 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/Makefile 1970-01-01 01:00:00.000000000 +0100 +@@ -1,20 +0,0 @@ +-include $(SUBDIR)../config.mak +- +-NAME = avcore +-FFLIBS = avutil +- +-HEADERS = \ +- audioconvert.h \ +- avcore.h \ +- imgutils.h \ +- parseutils.h \ +- samplefmt.h \ +- +-OBJS = \ +- audioconvert.o \ +- imgutils.o \ +- parseutils.o \ +- samplefmt.o \ +- utils.o \ +- +-include $(SUBDIR)../subdir.mak +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/parseutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/parseutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/parseutils.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/parseutils.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,474 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * misc parsing utilities for libavcore +- */ +- +-#include +-#include "parseutils.h" +-#include "libavutil/avutil.h" +-#include "libavutil/eval.h" +-#include "libavutil/avstring.h" +-#include "libavutil/random_seed.h" +- +-typedef struct { +- const char *abbr; +- int width, height; +-} VideoSizeAbbr; +- +-typedef struct { +- const char *abbr; +- AVRational rate; +-} VideoRateAbbr; +- +-static const VideoSizeAbbr video_size_abbrs[] = { +- { "ntsc", 720, 480 }, +- { "pal", 720, 576 }, +- { "qntsc", 352, 240 }, /* VCD compliant NTSC */ +- { "qpal", 352, 288 }, /* VCD compliant PAL */ +- { "sntsc", 640, 480 }, /* square pixel NTSC */ +- { "spal", 768, 576 }, /* square pixel PAL */ +- { "film", 352, 240 }, +- { "ntsc-film", 352, 240 }, +- { "sqcif", 128, 96 }, +- { "qcif", 176, 144 }, +- { "cif", 352, 288 }, +- { "4cif", 704, 576 }, +- { "16cif", 1408,1152 }, +- { "qqvga", 160, 120 }, +- { "qvga", 320, 240 }, +- { "vga", 640, 480 }, +- { "svga", 800, 600 }, +- { "xga", 1024, 768 }, +- { "uxga", 1600,1200 }, +- { "qxga", 2048,1536 }, +- { "sxga", 1280,1024 }, +- { "qsxga", 2560,2048 }, +- { "hsxga", 5120,4096 }, +- { "wvga", 852, 480 }, +- { "wxga", 1366, 768 }, +- { "wsxga", 1600,1024 }, +- { "wuxga", 1920,1200 }, +- { "woxga", 2560,1600 }, +- { "wqsxga", 3200,2048 }, +- { "wquxga", 3840,2400 }, +- { "whsxga", 6400,4096 }, +- { "whuxga", 7680,4800 }, +- { "cga", 320, 200 }, +- { "ega", 640, 350 }, +- { "hd480", 852, 480 }, +- { "hd720", 1280, 720 }, +- { "hd1080", 1920,1080 }, +-}; +- +-static const VideoRateAbbr video_rate_abbrs[]= { +- { "ntsc", { 30000, 1001 } }, +- { "pal", { 25, 1 } }, +- { "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */ +- { "qpal", { 25, 1 } }, /* VCD compliant PAL */ +- { "sntsc", { 30000, 1001 } }, /* square pixel NTSC */ +- { "spal", { 25, 1 } }, /* square pixel PAL */ +- { "film", { 24, 1 } }, +- { "ntsc-film", { 24000, 1001 } }, +-}; +- +-int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) +-{ +- int i; +- int n = FF_ARRAY_ELEMS(video_size_abbrs); +- char *p; +- int width = 0, height = 0; +- +- for (i = 0; i < n; i++) { +- if (!strcmp(video_size_abbrs[i].abbr, str)) { +- width = video_size_abbrs[i].width; +- height = video_size_abbrs[i].height; +- break; +- } +- } +- if (i == n) { +- p = str; +- width = strtol(p, &p, 10); +- if (*p) +- p++; +- height = strtol(p, &p, 10); +- } +- if (width <= 0 || height <= 0) +- return AVERROR(EINVAL); +- *width_ptr = width; +- *height_ptr = height; +- return 0; +-} +- +-int av_parse_video_rate(AVRational *rate, const char *arg) +-{ +- int i, ret; +- int n = FF_ARRAY_ELEMS(video_rate_abbrs); +- double res; +- +- /* First, we check our abbreviation table */ +- for (i = 0; i < n; ++i) +- if (!strcmp(video_rate_abbrs[i].abbr, arg)) { +- *rate = video_rate_abbrs[i].rate; +- return 0; +- } +- +- /* Then, we try to parse it as fraction */ +- if ((ret = av_expr_parse_and_eval(&res, arg, NULL, NULL, NULL, NULL, NULL, NULL, +- NULL, 0, NULL)) < 0) +- return ret; +- *rate = av_d2q(res, 1001000); +- if (rate->num <= 0 || rate->den <= 0) +- return AVERROR(EINVAL); +- return 0; +-} +- +-typedef struct { +- const char *name; ///< a string representing the name of the color +- uint8_t rgb_color[3]; ///< RGB values for the color +-} ColorEntry; +- +-static ColorEntry color_table[] = { +- { "AliceBlue", { 0xF0, 0xF8, 0xFF } }, +- { "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } }, +- { "Aqua", { 0x00, 0xFF, 0xFF } }, +- { "Aquamarine", { 0x7F, 0xFF, 0xD4 } }, +- { "Azure", { 0xF0, 0xFF, 0xFF } }, +- { "Beige", { 0xF5, 0xF5, 0xDC } }, +- { "Bisque", { 0xFF, 0xE4, 0xC4 } }, +- { "Black", { 0x00, 0x00, 0x00 } }, +- { "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } }, +- { "Blue", { 0x00, 0x00, 0xFF } }, +- { "BlueViolet", { 0x8A, 0x2B, 0xE2 } }, +- { "Brown", { 0xA5, 0x2A, 0x2A } }, +- { "BurlyWood", { 0xDE, 0xB8, 0x87 } }, +- { "CadetBlue", { 0x5F, 0x9E, 0xA0 } }, +- { "Chartreuse", { 0x7F, 0xFF, 0x00 } }, +- { "Chocolate", { 0xD2, 0x69, 0x1E } }, +- { "Coral", { 0xFF, 0x7F, 0x50 } }, +- { "CornflowerBlue", { 0x64, 0x95, 0xED } }, +- { "Cornsilk", { 0xFF, 0xF8, 0xDC } }, +- { "Crimson", { 0xDC, 0x14, 0x3C } }, +- { "Cyan", { 0x00, 0xFF, 0xFF } }, +- { "DarkBlue", { 0x00, 0x00, 0x8B } }, +- { "DarkCyan", { 0x00, 0x8B, 0x8B } }, +- { "DarkGoldenRod", { 0xB8, 0x86, 0x0B } }, +- { "DarkGray", { 0xA9, 0xA9, 0xA9 } }, +- { "DarkGreen", { 0x00, 0x64, 0x00 } }, +- { "DarkKhaki", { 0xBD, 0xB7, 0x6B } }, +- { "DarkMagenta", { 0x8B, 0x00, 0x8B } }, +- { "DarkOliveGreen", { 0x55, 0x6B, 0x2F } }, +- { "Darkorange", { 0xFF, 0x8C, 0x00 } }, +- { "DarkOrchid", { 0x99, 0x32, 0xCC } }, +- { "DarkRed", { 0x8B, 0x00, 0x00 } }, +- { "DarkSalmon", { 0xE9, 0x96, 0x7A } }, +- { "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } }, +- { "DarkSlateBlue", { 0x48, 0x3D, 0x8B } }, +- { "DarkSlateGray", { 0x2F, 0x4F, 0x4F } }, +- { "DarkTurquoise", { 0x00, 0xCE, 0xD1 } }, +- { "DarkViolet", { 0x94, 0x00, 0xD3 } }, +- { "DeepPink", { 0xFF, 0x14, 0x93 } }, +- { "DeepSkyBlue", { 0x00, 0xBF, 0xFF } }, +- { "DimGray", { 0x69, 0x69, 0x69 } }, +- { "DodgerBlue", { 0x1E, 0x90, 0xFF } }, +- { "FireBrick", { 0xB2, 0x22, 0x22 } }, +- { "FloralWhite", { 0xFF, 0xFA, 0xF0 } }, +- { "ForestGreen", { 0x22, 0x8B, 0x22 } }, +- { "Fuchsia", { 0xFF, 0x00, 0xFF } }, +- { "Gainsboro", { 0xDC, 0xDC, 0xDC } }, +- { "GhostWhite", { 0xF8, 0xF8, 0xFF } }, +- { "Gold", { 0xFF, 0xD7, 0x00 } }, +- { "GoldenRod", { 0xDA, 0xA5, 0x20 } }, +- { "Gray", { 0x80, 0x80, 0x80 } }, +- { "Green", { 0x00, 0x80, 0x00 } }, +- { "GreenYellow", { 0xAD, 0xFF, 0x2F } }, +- { "HoneyDew", { 0xF0, 0xFF, 0xF0 } }, +- { "HotPink", { 0xFF, 0x69, 0xB4 } }, +- { "IndianRed", { 0xCD, 0x5C, 0x5C } }, +- { "Indigo", { 0x4B, 0x00, 0x82 } }, +- { "Ivory", { 0xFF, 0xFF, 0xF0 } }, +- { "Khaki", { 0xF0, 0xE6, 0x8C } }, +- { "Lavender", { 0xE6, 0xE6, 0xFA } }, +- { "LavenderBlush", { 0xFF, 0xF0, 0xF5 } }, +- { "LawnGreen", { 0x7C, 0xFC, 0x00 } }, +- { "LemonChiffon", { 0xFF, 0xFA, 0xCD } }, +- { "LightBlue", { 0xAD, 0xD8, 0xE6 } }, +- { "LightCoral", { 0xF0, 0x80, 0x80 } }, +- { "LightCyan", { 0xE0, 0xFF, 0xFF } }, +- { "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } }, +- { "LightGrey", { 0xD3, 0xD3, 0xD3 } }, +- { "LightGreen", { 0x90, 0xEE, 0x90 } }, +- { "LightPink", { 0xFF, 0xB6, 0xC1 } }, +- { "LightSalmon", { 0xFF, 0xA0, 0x7A } }, +- { "LightSeaGreen", { 0x20, 0xB2, 0xAA } }, +- { "LightSkyBlue", { 0x87, 0xCE, 0xFA } }, +- { "LightSlateGray", { 0x77, 0x88, 0x99 } }, +- { "LightSteelBlue", { 0xB0, 0xC4, 0xDE } }, +- { "LightYellow", { 0xFF, 0xFF, 0xE0 } }, +- { "Lime", { 0x00, 0xFF, 0x00 } }, +- { "LimeGreen", { 0x32, 0xCD, 0x32 } }, +- { "Linen", { 0xFA, 0xF0, 0xE6 } }, +- { "Magenta", { 0xFF, 0x00, 0xFF } }, +- { "Maroon", { 0x80, 0x00, 0x00 } }, +- { "MediumAquaMarine", { 0x66, 0xCD, 0xAA } }, +- { "MediumBlue", { 0x00, 0x00, 0xCD } }, +- { "MediumOrchid", { 0xBA, 0x55, 0xD3 } }, +- { "MediumPurple", { 0x93, 0x70, 0xD8 } }, +- { "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } }, +- { "MediumSlateBlue", { 0x7B, 0x68, 0xEE } }, +- { "MediumSpringGreen", { 0x00, 0xFA, 0x9A } }, +- { "MediumTurquoise", { 0x48, 0xD1, 0xCC } }, +- { "MediumVioletRed", { 0xC7, 0x15, 0x85 } }, +- { "MidnightBlue", { 0x19, 0x19, 0x70 } }, +- { "MintCream", { 0xF5, 0xFF, 0xFA } }, +- { "MistyRose", { 0xFF, 0xE4, 0xE1 } }, +- { "Moccasin", { 0xFF, 0xE4, 0xB5 } }, +- { "NavajoWhite", { 0xFF, 0xDE, 0xAD } }, +- { "Navy", { 0x00, 0x00, 0x80 } }, +- { "OldLace", { 0xFD, 0xF5, 0xE6 } }, +- { "Olive", { 0x80, 0x80, 0x00 } }, +- { "OliveDrab", { 0x6B, 0x8E, 0x23 } }, +- { "Orange", { 0xFF, 0xA5, 0x00 } }, +- { "OrangeRed", { 0xFF, 0x45, 0x00 } }, +- { "Orchid", { 0xDA, 0x70, 0xD6 } }, +- { "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } }, +- { "PaleGreen", { 0x98, 0xFB, 0x98 } }, +- { "PaleTurquoise", { 0xAF, 0xEE, 0xEE } }, +- { "PaleVioletRed", { 0xD8, 0x70, 0x93 } }, +- { "PapayaWhip", { 0xFF, 0xEF, 0xD5 } }, +- { "PeachPuff", { 0xFF, 0xDA, 0xB9 } }, +- { "Peru", { 0xCD, 0x85, 0x3F } }, +- { "Pink", { 0xFF, 0xC0, 0xCB } }, +- { "Plum", { 0xDD, 0xA0, 0xDD } }, +- { "PowderBlue", { 0xB0, 0xE0, 0xE6 } }, +- { "Purple", { 0x80, 0x00, 0x80 } }, +- { "Red", { 0xFF, 0x00, 0x00 } }, +- { "RosyBrown", { 0xBC, 0x8F, 0x8F } }, +- { "RoyalBlue", { 0x41, 0x69, 0xE1 } }, +- { "SaddleBrown", { 0x8B, 0x45, 0x13 } }, +- { "Salmon", { 0xFA, 0x80, 0x72 } }, +- { "SandyBrown", { 0xF4, 0xA4, 0x60 } }, +- { "SeaGreen", { 0x2E, 0x8B, 0x57 } }, +- { "SeaShell", { 0xFF, 0xF5, 0xEE } }, +- { "Sienna", { 0xA0, 0x52, 0x2D } }, +- { "Silver", { 0xC0, 0xC0, 0xC0 } }, +- { "SkyBlue", { 0x87, 0xCE, 0xEB } }, +- { "SlateBlue", { 0x6A, 0x5A, 0xCD } }, +- { "SlateGray", { 0x70, 0x80, 0x90 } }, +- { "Snow", { 0xFF, 0xFA, 0xFA } }, +- { "SpringGreen", { 0x00, 0xFF, 0x7F } }, +- { "SteelBlue", { 0x46, 0x82, 0xB4 } }, +- { "Tan", { 0xD2, 0xB4, 0x8C } }, +- { "Teal", { 0x00, 0x80, 0x80 } }, +- { "Thistle", { 0xD8, 0xBF, 0xD8 } }, +- { "Tomato", { 0xFF, 0x63, 0x47 } }, +- { "Turquoise", { 0x40, 0xE0, 0xD0 } }, +- { "Violet", { 0xEE, 0x82, 0xEE } }, +- { "Wheat", { 0xF5, 0xDE, 0xB3 } }, +- { "White", { 0xFF, 0xFF, 0xFF } }, +- { "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } }, +- { "Yellow", { 0xFF, 0xFF, 0x00 } }, +- { "YellowGreen", { 0x9A, 0xCD, 0x32 } }, +-}; +- +-static int color_table_compare(const void *lhs, const void *rhs) +-{ +- return strcasecmp(lhs, ((const ColorEntry *)rhs)->name); +-} +- +-#define ALPHA_SEP '@' +- +-int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, +- void *log_ctx) +-{ +- char *tail, color_string2[128]; +- const ColorEntry *entry; +- int len, hex_offset = 0; +- +- if (color_string[0] == '#') { +- hex_offset = 1; +- } else if (!strncmp(color_string, "0x", 2)) +- hex_offset = 2; +- +- if (slen < 0) +- slen = strlen(color_string); +- av_strlcpy(color_string2, color_string + hex_offset, +- FFMIN(slen-hex_offset+1, sizeof(color_string2))); +- if ((tail = strchr(color_string2, ALPHA_SEP))) +- *tail++ = 0; +- len = strlen(color_string2); +- rgba_color[3] = 255; +- +- if (!strcasecmp(color_string2, "random") || !strcasecmp(color_string2, "bikeshed")) { +- int rgba = av_get_random_seed(); +- rgba_color[0] = rgba >> 24; +- rgba_color[1] = rgba >> 16; +- rgba_color[2] = rgba >> 8; +- rgba_color[3] = rgba; +- } else if (hex_offset || +- strspn(color_string2, "0123456789ABCDEFabcdef") == len) { +- char *tail; +- unsigned int rgba = strtoul(color_string2, &tail, 16); +- +- if (*tail || (len != 6 && len != 8)) { +- av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2); +- return AVERROR(EINVAL); +- } +- if (len == 8) { +- rgba_color[3] = rgba; +- rgba >>= 8; +- } +- rgba_color[0] = rgba >> 16; +- rgba_color[1] = rgba >> 8; +- rgba_color[2] = rgba; +- } else { +- entry = bsearch(color_string2, +- color_table, +- FF_ARRAY_ELEMS(color_table), +- sizeof(ColorEntry), +- color_table_compare); +- if (!entry) { +- av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2); +- return AVERROR(EINVAL); +- } +- memcpy(rgba_color, entry->rgb_color, 3); +- } +- +- if (tail) { +- unsigned long int alpha; +- const char *alpha_string = tail; +- if (!strncmp(alpha_string, "0x", 2)) { +- alpha = strtoul(alpha_string, &tail, 16); +- } else { +- alpha = 255 * strtod(alpha_string, &tail); +- } +- +- if (tail == alpha_string || *tail || alpha > 255) { +- av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n", +- alpha_string, color_string); +- return AVERROR(EINVAL); +- } +- rgba_color[3] = alpha; +- } +- +- return 0; +-} +- +-#ifdef TEST +- +-#undef printf +- +-int main(void) +-{ +- printf("Testing av_parse_video_rate()\n"); +- { +- int i; +- const char *rates[] = { +- "-inf", +- "inf", +- "nan", +- "123/0", +- "-123 / 0", +- "", +- "/", +- " 123 / 321", +- "foo/foo", +- "foo/1", +- "1/foo", +- "0/0", +- "/0", +- "1/", +- "1", +- "0", +- "-123/123", +- "-foo", +- "123.23", +- ".23", +- "-.23", +- "-0.234", +- "-0.0000001", +- " 21332.2324 ", +- " -21332.2324 ", +- }; +- +- for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { +- int ret; +- AVRational q = (AVRational){0, 0}; +- ret = av_parse_video_rate(&q, rates[i]), +- printf("'%s' -> %d/%d ret:%d\n", +- rates[i], q.num, q.den, ret); +- } +- } +- +- printf("\nTesting av_parse_color()\n"); +- { +- int i; +- uint8_t rgba[4]; +- const char *color_names[] = { +- "bikeshed", +- "RaNdOm", +- "foo", +- "red", +- "Red ", +- "RED", +- "Violet", +- "Yellow", +- "Red", +- "0x000000", +- "0x0000000", +- "0xff000000", +- "0x3e34ff", +- "0x3e34ffaa", +- "0xffXXee", +- "0xfoobar", +- "0xffffeeeeeeee", +- "#ff0000", +- "#ffXX00", +- "ff0000", +- "ffXX00", +- "red@foo", +- "random@10", +- "0xff0000@1.0", +- "red@", +- "red@0xfff", +- "red@0xf", +- "red@2", +- "red@0.1", +- "red@-1", +- "red@0.5", +- "red@1.0", +- "red@256", +- "red@10foo", +- "red@-1.0", +- "red@-0.0", +- }; +- +- av_log_set_level(AV_LOG_DEBUG); +- +- for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { +- if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) +- printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); +- } +- } +- +- return 0; +-} +- +-#endif /* TEST */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/parseutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/parseutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/parseutils.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/parseutils.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,75 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_PARSEUTILS_H +-#define AVCORE_PARSEUTILS_H +- +-#include "libavutil/rational.h" +- +-/** +- * @file +- * misc parsing utilities for libavcore +- */ +- +-/** +- * Parse str and put in width_ptr and height_ptr the detected values. +- * +- * @param[in,out] width_ptr pointer to the variable which will contain the detected +- * width value +- * @param[in,out] height_ptr pointer to the variable which will contain the detected +- * height value +- * @param[in] str the string to parse: it has to be a string in the format +- * width x height or a valid video size abbreviation. +- * @return >= 0 on success, a negative error code otherwise +- */ +-int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str); +- +-/** +- * Parse str and store the detected values in *rate. +- * +- * @param[in,out] rate pointer to the AVRational which will contain the detected +- * frame rate +- * @param[in] str the string to parse: it has to be a string in the format +- * rate_num / rate_den, a float number or a valid video rate abbreviation +- * @return >= 0 on success, a negative error code otherwise +- */ +-int av_parse_video_rate(AVRational *rate, const char *str); +- +-/** +- * Put the RGBA values that correspond to color_string in rgba_color. +- * +- * @param color_string a string specifying a color. It can be the name of +- * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence, +- * possibly followed by "@" and a string representing the alpha +- * component. +- * The alpha component may be a string composed by "0x" followed by an +- * hexadecimal number or a decimal number between 0.0 and 1.0, which +- * represents the opacity value (0x00/0.0 means completely transparent, +- * 0xff/1.0 completely opaque). +- * If the alpha component is not specified then 0xff is assumed. +- * The string "random" will result in a random color. +- * @param slen length of the initial part of color_string containing the +- * color. It can be set to -1 if color_string is a null terminated string +- * containing nothing else than the color. +- * @return >= 0 in case of success, a negative value in case of +- * failure (for example if color_string cannot be parsed). +- */ +-int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, +- void *log_ctx); +- +-#endif /* AVCORE_PARSEUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/samplefmt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/samplefmt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/samplefmt.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/samplefmt.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,70 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include "avcore.h" +-#include "samplefmt.h" +- +-typedef struct SampleFmtInfo { +- const char *name; +- int bits; +-} SampleFmtInfo; +- +-/** this table gives more information about formats */ +-static const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB] = { +- [AV_SAMPLE_FMT_U8] = { .name = "u8", .bits = 8 }, +- [AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16 }, +- [AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32 }, +- [AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32 }, +- [AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64 }, +-}; +- +-const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt) +-{ +- if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) +- return NULL; +- return sample_fmt_info[sample_fmt].name; +-} +- +-enum AVSampleFormat av_get_sample_fmt(const char *name) +-{ +- int i; +- +- for (i = 0; i < AV_SAMPLE_FMT_NB; i++) +- if (!strcmp(sample_fmt_info[i].name, name)) +- return i; +- return AV_SAMPLE_FMT_NONE; +-} +- +-char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt) +-{ +- /* print header */ +- if (sample_fmt < 0) +- snprintf(buf, buf_size, "name " " depth"); +- else if (sample_fmt < AV_SAMPLE_FMT_NB) { +- SampleFmtInfo info = sample_fmt_info[sample_fmt]; +- snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits); +- } +- +- return buf; +-} +- +-int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) +-{ +- return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? +- 0 : sample_fmt_info[sample_fmt].bits; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/samplefmt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/samplefmt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/samplefmt.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/samplefmt.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,72 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVCORE_SAMPLEFMT_H +-#define AVCORE_SAMPLEFMT_H +- +-#include "avcore.h" +- +-/** +- * all in native-endian format +- */ +-enum AVSampleFormat { +- AV_SAMPLE_FMT_NONE = -1, +- AV_SAMPLE_FMT_U8, ///< unsigned 8 bits +- AV_SAMPLE_FMT_S16, ///< signed 16 bits +- AV_SAMPLE_FMT_S32, ///< signed 32 bits +- AV_SAMPLE_FMT_FLT, ///< float +- AV_SAMPLE_FMT_DBL, ///< double +- AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if dynamically linking to libavcore +-}; +- +-/** +- * Return the name of sample_fmt, or NULL if sample_fmt is not +- * recognized. +- */ +-const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt); +- +-/** +- * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE +- * on error. +- */ +-enum AVSampleFormat av_get_sample_fmt(const char *name); +- +-/** +- * Generate a string corresponding to the sample format with +- * sample_fmt, or a header if sample_fmt is negative. +- * +- * @param buf the buffer where to write the string +- * @param buf_size the size of buf +- * @param sample_fmt the number of the sample format to print the +- * corresponding info string, or a negative value to print the +- * corresponding header. +- * @return the pointer to the filled buffer or NULL if sample_fmt is +- * unknown or in case of other errors +- */ +-char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt); +- +-/** +- * Return sample format bits per sample. +- * +- * @param sample_fmt the sample format +- * @return number of bits per sample or zero if unknown for the given +- * sample format +- */ +-int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt); +- +-#endif /* AVCORE_SAMPLEFMT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/utils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/utils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavcore/utils.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavcore/utils.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,41 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include "config.h" +-#include "avcore.h" +- +-/** +- * @file +- * various utility functions +- */ +- +-unsigned avcore_version(void) +-{ +- return LIBAVCORE_VERSION_INT; +-} +- +-const char *avcore_configuration(void) +-{ +- return FFMPEG_CONFIGURATION; +-} +- +-const char *avcore_license(void) +-{ +-#define LICENSE_PREFIX "libavcore license: " +- return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alldevices.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alldevices.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alldevices.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alldevices.c 2012-05-14 14:08:54.627345878 +0200 +@@ -19,7 +19,6 @@ + */ + + #include "config.h" +-#include "libavformat/avformat.h" + #include "avdevice.h" + + #define REGISTER_OUTDEV(X,x) { \ +@@ -41,14 +40,22 @@ + /* devices */ + REGISTER_INOUTDEV (ALSA, alsa); + REGISTER_INDEV (BKTR, bktr); ++ REGISTER_INDEV (DSHOW, dshow); + REGISTER_INDEV (DV1394, dv1394); ++ REGISTER_INDEV (FBDEV, fbdev); + REGISTER_INDEV (JACK, jack); ++ REGISTER_INDEV (LAVFI, lavfi); ++ REGISTER_INDEV (OPENAL, openal); + REGISTER_INOUTDEV (OSS, oss); ++ REGISTER_INDEV (PULSE, pulse); ++ REGISTER_OUTDEV (SDL, sdl); ++ REGISTER_INOUTDEV (SNDIO, sndio); + REGISTER_INDEV (V4L2, v4l2); + REGISTER_INDEV (V4L, v4l); + REGISTER_INDEV (VFWCAP, vfwcap); + REGISTER_INDEV (X11_GRAB_DEVICE, x11_grab_device); + + /* external libraries */ ++ REGISTER_INDEV (LIBCDIO, libcdio); + REGISTER_INDEV (LIBDC1394, libdc1394); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-common.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-common.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-common.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-common.c 2012-05-14 14:08:54.628345899 +0200 +@@ -29,20 +29,160 @@ + */ + + #include +-#include "libavformat/avformat.h" ++#include "avdevice.h" ++#include "libavutil/avassert.h" ++#include "libavutil/audioconvert.h" + + #include "alsa-audio.h" + + static av_cold snd_pcm_format_t codec_id_to_pcm_format(int codec_id) + { + switch(codec_id) { ++ case CODEC_ID_PCM_F64LE: return SND_PCM_FORMAT_FLOAT64_LE; ++ case CODEC_ID_PCM_F64BE: return SND_PCM_FORMAT_FLOAT64_BE; ++ case CODEC_ID_PCM_F32LE: return SND_PCM_FORMAT_FLOAT_LE; ++ case CODEC_ID_PCM_F32BE: return SND_PCM_FORMAT_FLOAT_BE; ++ case CODEC_ID_PCM_S32LE: return SND_PCM_FORMAT_S32_LE; ++ case CODEC_ID_PCM_S32BE: return SND_PCM_FORMAT_S32_BE; ++ case CODEC_ID_PCM_U32LE: return SND_PCM_FORMAT_U32_LE; ++ case CODEC_ID_PCM_U32BE: return SND_PCM_FORMAT_U32_BE; ++ case CODEC_ID_PCM_S24LE: return SND_PCM_FORMAT_S24_3LE; ++ case CODEC_ID_PCM_S24BE: return SND_PCM_FORMAT_S24_3BE; ++ case CODEC_ID_PCM_U24LE: return SND_PCM_FORMAT_U24_3LE; ++ case CODEC_ID_PCM_U24BE: return SND_PCM_FORMAT_U24_3BE; + case CODEC_ID_PCM_S16LE: return SND_PCM_FORMAT_S16_LE; + case CODEC_ID_PCM_S16BE: return SND_PCM_FORMAT_S16_BE; ++ case CODEC_ID_PCM_U16LE: return SND_PCM_FORMAT_U16_LE; ++ case CODEC_ID_PCM_U16BE: return SND_PCM_FORMAT_U16_BE; + case CODEC_ID_PCM_S8: return SND_PCM_FORMAT_S8; ++ case CODEC_ID_PCM_U8: return SND_PCM_FORMAT_U8; ++ case CODEC_ID_PCM_MULAW: return SND_PCM_FORMAT_MU_LAW; ++ case CODEC_ID_PCM_ALAW: return SND_PCM_FORMAT_A_LAW; + default: return SND_PCM_FORMAT_UNKNOWN; + } + } + ++#define REORDER_OUT_50(NAME, TYPE) \ ++static void alsa_reorder_ ## NAME ## _out_50(const void *in_v, void *out_v, int n) \ ++{ \ ++ const TYPE *in = in_v; \ ++ TYPE *out = out_v; \ ++\ ++ while (n-- > 0) { \ ++ out[0] = in[0]; \ ++ out[1] = in[1]; \ ++ out[2] = in[3]; \ ++ out[3] = in[4]; \ ++ out[4] = in[2]; \ ++ in += 5; \ ++ out += 5; \ ++ } \ ++} ++ ++#define REORDER_OUT_51(NAME, TYPE) \ ++static void alsa_reorder_ ## NAME ## _out_51(const void *in_v, void *out_v, int n) \ ++{ \ ++ const TYPE *in = in_v; \ ++ TYPE *out = out_v; \ ++\ ++ while (n-- > 0) { \ ++ out[0] = in[0]; \ ++ out[1] = in[1]; \ ++ out[2] = in[4]; \ ++ out[3] = in[5]; \ ++ out[4] = in[2]; \ ++ out[5] = in[3]; \ ++ in += 6; \ ++ out += 6; \ ++ } \ ++} ++ ++#define REORDER_OUT_71(NAME, TYPE) \ ++static void alsa_reorder_ ## NAME ## _out_71(const void *in_v, void *out_v, int n) \ ++{ \ ++ const TYPE *in = in_v; \ ++ TYPE *out = out_v; \ ++\ ++ while (n-- > 0) { \ ++ out[0] = in[0]; \ ++ out[1] = in[1]; \ ++ out[2] = in[4]; \ ++ out[3] = in[5]; \ ++ out[4] = in[2]; \ ++ out[5] = in[3]; \ ++ out[6] = in[6]; \ ++ out[7] = in[7]; \ ++ in += 8; \ ++ out += 8; \ ++ } \ ++} ++ ++REORDER_OUT_50(int8, int8_t) ++REORDER_OUT_51(int8, int8_t) ++REORDER_OUT_71(int8, int8_t) ++REORDER_OUT_50(int16, int16_t) ++REORDER_OUT_51(int16, int16_t) ++REORDER_OUT_71(int16, int16_t) ++REORDER_OUT_50(int32, int32_t) ++REORDER_OUT_51(int32, int32_t) ++REORDER_OUT_71(int32, int32_t) ++REORDER_OUT_50(f32, float) ++REORDER_OUT_51(f32, float) ++REORDER_OUT_71(f32, float) ++ ++#define FORMAT_I8 0 ++#define FORMAT_I16 1 ++#define FORMAT_I32 2 ++#define FORMAT_F32 3 ++ ++#define PICK_REORDER(layout)\ ++switch(format) {\ ++ case FORMAT_I8: s->reorder_func = alsa_reorder_int8_out_ ##layout; break;\ ++ case FORMAT_I16: s->reorder_func = alsa_reorder_int16_out_ ##layout; break;\ ++ case FORMAT_I32: s->reorder_func = alsa_reorder_int32_out_ ##layout; break;\ ++ case FORMAT_F32: s->reorder_func = alsa_reorder_f32_out_ ##layout; break;\ ++} ++ ++static av_cold int find_reorder_func(AlsaData *s, int codec_id, uint64_t layout, int out) ++{ ++ int format; ++ ++ /* reordering input is not currently supported */ ++ if (!out) ++ return AVERROR(ENOSYS); ++ ++ /* reordering is not needed for QUAD or 2_2 layout */ ++ if (layout == AV_CH_LAYOUT_QUAD || layout == AV_CH_LAYOUT_2_2) ++ return 0; ++ ++ switch (codec_id) { ++ case CODEC_ID_PCM_S8: ++ case CODEC_ID_PCM_U8: ++ case CODEC_ID_PCM_ALAW: ++ case CODEC_ID_PCM_MULAW: format = FORMAT_I8; break; ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S16BE: ++ case CODEC_ID_PCM_U16LE: ++ case CODEC_ID_PCM_U16BE: format = FORMAT_I16; break; ++ case CODEC_ID_PCM_S32LE: ++ case CODEC_ID_PCM_S32BE: ++ case CODEC_ID_PCM_U32LE: ++ case CODEC_ID_PCM_U32BE: format = FORMAT_I32; break; ++ case CODEC_ID_PCM_F32LE: ++ case CODEC_ID_PCM_F32BE: format = FORMAT_F32; break; ++ default: return AVERROR(ENOSYS); ++ } ++ ++ if (layout == AV_CH_LAYOUT_5POINT0_BACK || layout == AV_CH_LAYOUT_5POINT0) ++ PICK_REORDER(50) ++ else if (layout == AV_CH_LAYOUT_5POINT1_BACK || layout == AV_CH_LAYOUT_5POINT1) ++ PICK_REORDER(51) ++ else if (layout == AV_CH_LAYOUT_7POINT1) ++ PICK_REORDER(71) ++ ++ return s->reorder_func ? 0 : AVERROR(ENOSYS); ++} ++ + av_cold int ff_alsa_open(AVFormatContext *ctx, snd_pcm_stream_t mode, + unsigned int *sample_rate, + int channels, enum CodecID *codec_id) +@@ -54,6 +194,7 @@ + snd_pcm_t *h; + snd_pcm_hw_params_t *hw_params; + snd_pcm_uframes_t buffer_size, period_size; ++ uint64_t layout = ctx->streams[0]->codec->channel_layout; + + if (ctx->filename[0] == 0) audio_device = "default"; + else audio_device = ctx->filename; +@@ -120,6 +261,7 @@ + } + + snd_pcm_hw_params_get_buffer_size_max(hw_params, &buffer_size); ++ buffer_size = FFMIN(buffer_size, ALSA_BUFFER_SIZE_MAX); + /* TODO: maybe use ctx->max_picture_buffer somehow */ + res = snd_pcm_hw_params_set_buffer_size_near(h, hw_params, &buffer_size); + if (res < 0) { +@@ -129,6 +271,8 @@ + } + + snd_pcm_hw_params_get_period_size_min(hw_params, &period_size, NULL); ++ if (!period_size) ++ period_size = buffer_size / 4; + res = snd_pcm_hw_params_set_period_size_near(h, hw_params, &period_size, NULL); + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "cannot set ALSA period size (%s)\n", +@@ -146,6 +290,21 @@ + + snd_pcm_hw_params_free(hw_params); + ++ if (channels > 2 && layout) { ++ if (find_reorder_func(s, *codec_id, layout, mode == SND_PCM_STREAM_PLAYBACK) < 0) { ++ char name[128]; ++ av_get_channel_layout_string(name, sizeof(name), channels, layout); ++ av_log(ctx, AV_LOG_WARNING, "ALSA channel layout unknown or unimplemented for %s %s.\n", ++ name, mode == SND_PCM_STREAM_PLAYBACK ? "playback" : "capture"); ++ } ++ if (s->reorder_func) { ++ s->reorder_buf_size = buffer_size; ++ s->reorder_buf = av_malloc(s->reorder_buf_size * s->frame_size); ++ if (!s->reorder_buf) ++ goto fail1; ++ } ++ } ++ + s->h = h; + return 0; + +@@ -160,6 +319,9 @@ + { + AlsaData *s = s1->priv_data; + ++ av_freep(&s->reorder_buf); ++ if (CONFIG_ALSA_INDEV) ++ ff_timefilter_destroy(s->timefilter); + snd_pcm_close(s->h); + return 0; + } +@@ -184,3 +346,19 @@ + } + return err; + } ++ ++int ff_alsa_extend_reorder_buf(AlsaData *s, int min_size) ++{ ++ int size = s->reorder_buf_size; ++ void *r; ++ ++ av_assert0(size != 0); ++ while (size < min_size) ++ size *= 2; ++ r = av_realloc(s->reorder_buf, size * s->frame_size); ++ if (!r) ++ return AVERROR(ENOMEM); ++ s->reorder_buf = r; ++ s->reorder_buf_size = size; ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-dec.c 2012-05-14 14:08:54.629345919 +0200 +@@ -46,8 +46,11 @@ + */ + + #include +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/opt.h" ++#include "libavutil/mathematics.h" + ++#include "avdevice.h" + #include "alsa-audio.h" + + static av_cold int audio_read_header(AVFormatContext *s1, +@@ -56,66 +59,34 @@ + AlsaData *s = s1->priv_data; + AVStream *st; + int ret; +- unsigned int sample_rate; + enum CodecID codec_id; +- snd_pcm_sw_params_t *sw_params; ++ double o; + +- if (ap->sample_rate <= 0) { +- av_log(s1, AV_LOG_ERROR, "Bad sample rate %d\n", ap->sample_rate); +- +- return AVERROR(EIO); +- } +- +- if (ap->channels <= 0) { +- av_log(s1, AV_LOG_ERROR, "Bad channels number %d\n", ap->channels); +- +- return AVERROR(EIO); +- } +- +- st = av_new_stream(s1, 0); ++ st = avformat_new_stream(s1, NULL); + if (!st) { + av_log(s1, AV_LOG_ERROR, "Cannot add stream\n"); + + return AVERROR(ENOMEM); + } +- sample_rate = ap->sample_rate; + codec_id = s1->audio_codec_id; + +- ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &sample_rate, ap->channels, ++ ret = ff_alsa_open(s1, SND_PCM_STREAM_CAPTURE, &s->sample_rate, s->channels, + &codec_id); + if (ret < 0) { + return AVERROR(EIO); + } + +- if (snd_pcm_type(s->h) != SND_PCM_TYPE_HW) +- av_log(s1, AV_LOG_WARNING, +- "capture with some ALSA plugins, especially dsnoop, " +- "may hang.\n"); +- +- ret = snd_pcm_sw_params_malloc(&sw_params); +- if (ret < 0) { +- av_log(s1, AV_LOG_ERROR, "cannot allocate software parameters structure (%s)\n", +- snd_strerror(ret)); +- goto fail; +- } +- +- snd_pcm_sw_params_current(s->h, sw_params); +- snd_pcm_sw_params_set_tstamp_mode(s->h, sw_params, SND_PCM_TSTAMP_ENABLE); +- +- ret = snd_pcm_sw_params(s->h, sw_params); +- snd_pcm_sw_params_free(sw_params); +- if (ret < 0) { +- av_log(s1, AV_LOG_ERROR, "cannot install ALSA software parameters (%s)\n", +- snd_strerror(ret)); +- goto fail; +- } +- + /* take real parameters */ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = codec_id; +- st->codec->sample_rate = sample_rate; +- st->codec->channels = ap->channels; +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ st->codec->sample_rate = s->sample_rate; ++ st->codec->channels = s->channels; ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ o = 2 * M_PI * s->period_size / s->sample_rate * 1.5; // bandwidth: 1.5Hz ++ s->timefilter = ff_timefilter_new(1000000.0 / s->sample_rate, ++ sqrt(2 * o), o * o); ++ if (!s->timefilter) ++ goto fail; + + return 0; + +@@ -127,16 +98,15 @@ + static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) + { + AlsaData *s = s1->priv_data; +- AVStream *st = s1->streams[0]; + int res; +- snd_htimestamp_t timestamp; +- snd_pcm_uframes_t ts_delay; ++ int64_t dts; ++ snd_pcm_sframes_t delay = 0; + +- if (av_new_packet(pkt, s->period_size) < 0) { ++ if (av_new_packet(pkt, s->period_size * s->frame_size) < 0) { + return AVERROR(EIO); + } + +- while ((res = snd_pcm_readi(s->h, pkt->data, pkt->size / s->frame_size)) < 0) { ++ while ((res = snd_pcm_readi(s->h, pkt->data, s->period_size)) < 0) { + if (res == -EAGAIN) { + av_free_packet(pkt); + +@@ -149,27 +119,39 @@ + + return AVERROR(EIO); + } ++ ff_timefilter_reset(s->timefilter); + } + +- snd_pcm_htimestamp(s->h, &ts_delay, ×tamp); +- ts_delay += res; +- pkt->pts = timestamp.tv_sec * 1000000LL +- + (timestamp.tv_nsec * st->codec->sample_rate +- - ts_delay * 1000000000LL + st->codec->sample_rate * 500LL) +- / (st->codec->sample_rate * 1000LL); ++ dts = av_gettime(); ++ snd_pcm_delay(s->h, &delay); ++ dts -= av_rescale(delay + res, 1000000, s->sample_rate); ++ pkt->pts = ff_timefilter_update(s->timefilter, dts, res); + + pkt->size = res * s->frame_size; + + return 0; + } + ++static const AVOption options[] = { ++ { "sample_rate", "", offsetof(AlsaData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { "channels", "", offsetof(AlsaData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass alsa_demuxer_class = { ++ .class_name = "ALSA demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_alsa_demuxer = { +- "alsa", +- NULL_IF_CONFIG_SMALL("ALSA audio input"), +- sizeof(AlsaData), +- NULL, +- audio_read_header, +- audio_read_packet, +- ff_alsa_close, +- .flags = AVFMT_NOFILE, ++ .name = "alsa", ++ .long_name = NULL_IF_CONFIG_SMALL("ALSA audio input"), ++ .priv_data_size = sizeof(AlsaData), ++ .read_header = audio_read_header, ++ .read_packet = audio_read_packet, ++ .read_close = ff_alsa_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &alsa_demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio-enc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio-enc.c 2012-05-14 14:08:54.630345939 +0200 +@@ -38,8 +38,9 @@ + */ + + #include +-#include "libavformat/avformat.h" + ++#include "libavformat/internal.h" ++#include "avdevice.h" + #include "alsa-audio.h" + + static av_cold int audio_write_header(AVFormatContext *s1) +@@ -61,6 +62,7 @@ + st->codec->sample_rate, sample_rate); + goto fail; + } ++ avpriv_set_pts_info(st, 64, 1, sample_rate); + + return res; + +@@ -76,7 +78,15 @@ + int size = pkt->size; + uint8_t *buf = pkt->data; + +- while((res = snd_pcm_writei(s->h, buf, size / s->frame_size)) < 0) { ++ size /= s->frame_size; ++ if (s->reorder_func) { ++ if (size > s->reorder_buf_size) ++ if (ff_alsa_extend_reorder_buf(s, size)) ++ return AVERROR(ENOMEM); ++ s->reorder_func(buf, s->reorder_buf, size); ++ buf = s->reorder_buf; ++ } ++ while ((res = snd_pcm_writei(s->h, buf, size)) < 0) { + if (res == -EAGAIN) { + + return AVERROR(EAGAIN); +@@ -93,16 +103,26 @@ + return 0; + } + ++static void ++audio_get_output_timestamp(AVFormatContext *s1, int stream, ++ int64_t *dts, int64_t *wall) ++{ ++ AlsaData *s = s1->priv_data; ++ snd_pcm_sframes_t delay = 0; ++ *wall = av_gettime(); ++ snd_pcm_delay(s->h, &delay); ++ *dts = s1->streams[0]->cur_dts - delay; ++} ++ + AVOutputFormat ff_alsa_muxer = { +- "alsa", +- NULL_IF_CONFIG_SMALL("ALSA audio output"), +- "", +- "", +- sizeof(AlsaData), +- DEFAULT_CODEC_ID, +- CODEC_ID_NONE, +- audio_write_header, +- audio_write_packet, +- ff_alsa_close, +- .flags = AVFMT_NOFILE, ++ .name = "alsa", ++ .long_name = NULL_IF_CONFIG_SMALL("ALSA audio output"), ++ .priv_data_size = sizeof(AlsaData), ++ .audio_codec = DEFAULT_CODEC_ID, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = audio_write_header, ++ .write_packet = audio_write_packet, ++ .write_trailer = ff_alsa_close, ++ .get_output_timestamp = audio_get_output_timestamp, ++ .flags = AVFMT_NOFILE, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/alsa-audio.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/alsa-audio.h 2012-05-14 14:08:54.634346019 +0200 +@@ -32,17 +32,30 @@ + + #include + #include "config.h" +-#include "libavformat/avformat.h" ++#include "libavutil/log.h" ++#include "timefilter.h" ++#include "avdevice.h" + + /* XXX: we make the assumption that the soundcard accepts this format */ + /* XXX: find better solution with "preinit" method, needed also in + other formats */ + #define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE) + ++typedef void (*ff_reorder_func)(const void *, void *, int); ++ ++#define ALSA_BUFFER_SIZE_MAX 65536 ++ + typedef struct { ++ AVClass *class; + snd_pcm_t *h; +- int frame_size; ///< preferred size for reads and writes +- int period_size; ///< bytes per sample * channels ++ int frame_size; ///< bytes per sample * channels ++ int period_size; ///< preferred size for reads and writes, in frames ++ int sample_rate; ///< sample rate set by user ++ int channels; ///< number of channels set by user ++ TimeFilter *timefilter; ++ void (*reorder_func)(const void *, void *, int); ++ void *reorder_buf; ++ int reorder_buf_size; ///< in frames + } AlsaData; + + /** +@@ -82,4 +95,6 @@ + */ + int ff_alsa_xrun_recover(AVFormatContext *s1, int err); + ++int ff_alsa_extend_reorder_buf(AlsaData *s, int size); ++ + #endif /* AVDEVICE_ALSA_AUDIO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/avdevice.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/avdevice.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/avdevice.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/avdevice.c 2012-05-14 14:08:54.634346019 +0200 +@@ -16,10 +16,12 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/avassert.h" + #include "avdevice.h" + + unsigned avdevice_version(void) + { ++ av_assert0(LIBAVDEVICE_VERSION_MICRO >= 100); + return LIBAVDEVICE_VERSION_INT; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/avdevice.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/avdevice.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/avdevice.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/avdevice.h 2012-05-14 14:08:54.635346039 +0200 +@@ -19,11 +19,34 @@ + #ifndef AVDEVICE_AVDEVICE_H + #define AVDEVICE_AVDEVICE_H + ++/** ++ * @file ++ * @ingroup lavd ++ * Main libavdevice API header ++ */ ++ ++/** ++ * @defgroup lavd Special devices muxing/demuxing library ++ * @{ ++ * Libavdevice is a complementary library to @ref libavf "libavformat". It ++ * provides various "special" platform-specific muxers and demuxers, e.g. for ++ * grabbing devices, audio capture and playback etc. As a consequence, the ++ * (de)muxers in libavdevice are of the AVFMT_NOFILE type (they use their own ++ * I/O functions). The filename passed to avformat_open_input() often does not ++ * refer to an actually existing file, but has some special device-specific ++ * meaning - e.g. for the x11grab device it is the display name. ++ * ++ * To use libavdevice, simply call avdevice_register_all() to register all ++ * compiled muxers and demuxers. They all use standard libavformat API. ++ * @} ++ */ ++ + #include "libavutil/avutil.h" ++#include "libavformat/avformat.h" + +-#define LIBAVDEVICE_VERSION_MAJOR 52 +-#define LIBAVDEVICE_VERSION_MINOR 2 +-#define LIBAVDEVICE_VERSION_MICRO 3 ++#define LIBAVDEVICE_VERSION_MAJOR 53 ++#define LIBAVDEVICE_VERSION_MINOR 4 ++#define LIBAVDEVICE_VERSION_MICRO 100 + + #define LIBAVDEVICE_VERSION_INT AV_VERSION_INT(LIBAVDEVICE_VERSION_MAJOR, \ + LIBAVDEVICE_VERSION_MINOR, \ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/bktr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/bktr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/bktr.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/bktr.c 2012-05-14 14:08:54.636346059 +0200 +@@ -24,10 +24,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#define _BSD_SOURCE 1 +-#define _NETBSD_SOURCE +- +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" + #if HAVE_DEV_BKTR_IOCTL_METEOR_H && HAVE_DEV_BKTR_IOCTL_BT848_H + # include + # include +@@ -47,15 +47,17 @@ + #include + #include + #include +-#include ++#include "avdevice.h" + + typedef struct { ++ AVClass *class; + int video_fd; + int tuner_fd; + int width, height; +- int frame_rate; +- int frame_rate_base; + uint64_t per_frame; ++ int standard; ++ char *video_size; /**< String describing video size, set by a private option. */ ++ char *framerate; /**< Set by a private option. */ + } VideoData; + + +@@ -246,54 +248,60 @@ + VideoData *s = s1->priv_data; + AVStream *st; + int width, height; +- int frame_rate; +- int frame_rate_base; +- int format = -1; ++ AVRational framerate; ++ int ret = 0; + +- if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) +- return -1; ++ if ((ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n", s->video_size); ++ goto out; ++ } ++ ++ if (!s->framerate) ++ switch (s->standard) { ++ case PAL: s->framerate = av_strdup("pal"); break; ++ case NTSC: s->framerate = av_strdup("ntsc"); break; ++ case SECAM: s->framerate = av_strdup("25"); break; ++ default: ++ av_log(s1, AV_LOG_ERROR, "Unknown standard.\n"); ++ ret = AVERROR(EINVAL); ++ goto out; ++ } ++ if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", s->framerate); ++ goto out; ++ } + +- width = ap->width; +- height = ap->height; +- frame_rate = ap->time_base.den; +- frame_rate_base = ap->time_base.num; +- +- st = av_new_stream(s1, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */ ++ st = avformat_new_stream(s1, NULL); ++ if (!st) { ++ ret = AVERROR(ENOMEM); ++ goto out; ++ } ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in use */ + + s->width = width; + s->height = height; +- s->frame_rate = frame_rate; +- s->frame_rate_base = frame_rate_base; +- s->per_frame = ((uint64_t)1000000 * s->frame_rate_base) / s->frame_rate; ++ s->per_frame = ((uint64_t)1000000 * framerate.den) / framerate.num; + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->pix_fmt = PIX_FMT_YUV420P; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->width = width; + st->codec->height = height; +- st->codec->time_base.den = frame_rate; +- st->codec->time_base.num = frame_rate_base; ++ st->codec->time_base.den = framerate.num; ++ st->codec->time_base.num = framerate.den; + +- if (ap->standard) { +- if (!strcasecmp(ap->standard, "pal")) +- format = PAL; +- else if (!strcasecmp(ap->standard, "secam")) +- format = SECAM; +- else if (!strcasecmp(ap->standard, "ntsc")) +- format = NTSC; +- } + +- if (bktr_init(s1->filename, width, height, format, +- &(s->video_fd), &(s->tuner_fd), -1, 0.0) < 0) +- return AVERROR(EIO); ++ if (bktr_init(s1->filename, width, height, s->standard, ++ &s->video_fd, &s->tuner_fd, -1, 0.0) < 0) { ++ ret = AVERROR(EIO); ++ goto out; ++ } + + nsignals = 0; + last_frame_time = 0; + +- return 0; ++out: ++ return ret; + } + + static int grab_read_close(AVFormatContext *s1) +@@ -314,13 +322,35 @@ + return 0; + } + ++#define OFFSET(x) offsetof(VideoData, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "standard", "", offsetof(VideoData, standard), AV_OPT_TYPE_INT, {.dbl = VIDEO_FORMAT}, PAL, NTSCJ, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "SECAM", "", 0, AV_OPT_TYPE_CONST, {.dbl = SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "PALN", "", 0, AV_OPT_TYPE_CONST, {.dbl = PALN}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "PALM", "", 0, AV_OPT_TYPE_CONST, {.dbl = PALM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "NTSCJ", "", 0, AV_OPT_TYPE_CONST, {.dbl = NTSCJ}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass bktr_class = { ++ .class_name = "BKTR grab interface", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_bktr_demuxer = { +- "bktr", +- NULL_IF_CONFIG_SMALL("video grab"), +- sizeof(VideoData), +- NULL, +- grab_read_header, +- grab_read_packet, +- grab_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "bktr", ++ .long_name = NULL_IF_CONFIG_SMALL("video grab"), ++ .priv_data_size = sizeof(VideoData), ++ .read_header = grab_read_header, ++ .read_packet = grab_read_packet, ++ .read_close = grab_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &bktr_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow.c 2012-05-14 14:08:54.639346121 +0200 +@@ -0,0 +1,973 @@ ++/* ++ * Directshow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/parseutils.h" ++#include "libavutil/opt.h" ++#include "libavformat/internal.h" ++#include "avdevice.h" ++#include "dshow.h" ++ ++struct dshow_ctx { ++ const AVClass *class; ++ ++ IGraphBuilder *graph; ++ ++ char *device_name[2]; ++ int video_device_number; ++ int audio_device_number; ++ ++ int list_options; ++ int list_devices; ++ ++ IBaseFilter *device_filter[2]; ++ IPin *device_pin[2]; ++ libAVFilter *capture_filter[2]; ++ libAVPin *capture_pin[2]; ++ ++ HANDLE mutex; ++ HANDLE event; ++ AVPacketList *pktl; ++ ++ unsigned int curbufsize; ++ unsigned int video_frame_num; ++ ++ IMediaControl *control; ++ ++ char *video_size; ++ char *framerate; ++ ++ int requested_width; ++ int requested_height; ++ AVRational requested_framerate; ++ ++ int sample_rate; ++ int sample_size; ++ int channels; ++}; ++ ++static enum PixelFormat dshow_pixfmt(DWORD biCompression, WORD biBitCount) ++{ ++ switch(biCompression) { ++ case MKTAG('U', 'Y', 'V', 'Y'): ++ return PIX_FMT_UYVY422; ++ case MKTAG('Y', 'U', 'Y', '2'): ++ return PIX_FMT_YUYV422; ++ case MKTAG('I', '4', '2', '0'): ++ return PIX_FMT_YUV420P; ++ case BI_BITFIELDS: ++ case BI_RGB: ++ switch(biBitCount) { /* 1-8 are untested */ ++ case 1: ++ return PIX_FMT_MONOWHITE; ++ case 4: ++ return PIX_FMT_RGB4; ++ case 8: ++ return PIX_FMT_RGB8; ++ case 16: ++ return PIX_FMT_RGB555; ++ case 24: ++ return PIX_FMT_BGR24; ++ case 32: ++ return PIX_FMT_RGB32; ++ } ++ } ++ return PIX_FMT_NONE; ++} ++ ++static enum CodecID dshow_codecid(DWORD biCompression) ++{ ++ switch(biCompression) { ++ case MKTAG('d', 'v', 's', 'd'): ++ return CODEC_ID_DVVIDEO; ++ case MKTAG('M', 'J', 'P', 'G'): ++ case MKTAG('m', 'j', 'p', 'g'): ++ return CODEC_ID_MJPEG; ++ } ++ return CODEC_ID_NONE; ++} ++ ++static int ++dshow_read_close(AVFormatContext *s) ++{ ++ struct dshow_ctx *ctx = s->priv_data; ++ AVPacketList *pktl; ++ ++ if (ctx->control) { ++ IMediaControl_Stop(ctx->control); ++ IMediaControl_Release(ctx->control); ++ } ++ ++ if (ctx->graph) { ++ IEnumFilters *fenum; ++ int r; ++ r = IGraphBuilder_EnumFilters(ctx->graph, &fenum); ++ if (r == S_OK) { ++ IBaseFilter *f; ++ IEnumFilters_Reset(fenum); ++ while (IEnumFilters_Next(fenum, 1, &f, NULL) == S_OK) { ++ if (IGraphBuilder_RemoveFilter(ctx->graph, f) == S_OK) ++ IEnumFilters_Reset(fenum); /* When a filter is removed, ++ * the list must be reset. */ ++ IBaseFilter_Release(f); ++ } ++ IEnumFilters_Release(fenum); ++ } ++ IGraphBuilder_Release(ctx->graph); ++ } ++ ++ if (ctx->capture_pin[VideoDevice]) ++ libAVPin_Release(ctx->capture_pin[VideoDevice]); ++ if (ctx->capture_pin[AudioDevice]) ++ libAVPin_Release(ctx->capture_pin[AudioDevice]); ++ if (ctx->capture_filter[VideoDevice]) ++ libAVFilter_Release(ctx->capture_filter[VideoDevice]); ++ if (ctx->capture_filter[AudioDevice]) ++ libAVFilter_Release(ctx->capture_filter[AudioDevice]); ++ ++ if (ctx->device_pin[VideoDevice]) ++ IPin_Release(ctx->device_pin[VideoDevice]); ++ if (ctx->device_pin[AudioDevice]) ++ IPin_Release(ctx->device_pin[AudioDevice]); ++ if (ctx->device_filter[VideoDevice]) ++ IBaseFilter_Release(ctx->device_filter[VideoDevice]); ++ if (ctx->device_filter[AudioDevice]) ++ IBaseFilter_Release(ctx->device_filter[AudioDevice]); ++ ++ if (ctx->device_name[0]) ++ av_free(ctx->device_name[0]); ++ if (ctx->device_name[1]) ++ av_free(ctx->device_name[1]); ++ ++ if(ctx->mutex) ++ CloseHandle(ctx->mutex); ++ if(ctx->event) ++ CloseHandle(ctx->event); ++ ++ pktl = ctx->pktl; ++ while (pktl) { ++ AVPacketList *next = pktl->next; ++ av_destruct_packet(&pktl->pkt); ++ av_free(pktl); ++ pktl = next; ++ } ++ ++ return 0; ++} ++ ++static char *dup_wchar_to_utf8(wchar_t *w) ++{ ++ char *s = NULL; ++ int l = WideCharToMultiByte(CP_UTF8, 0, w, -1, 0, 0, 0, 0); ++ s = av_malloc(l); ++ if (s) ++ WideCharToMultiByte(CP_UTF8, 0, w, -1, s, l, 0, 0); ++ return s; ++} ++ ++static int shall_we_drop(AVFormatContext *s) ++{ ++ struct dshow_ctx *ctx = s->priv_data; ++ const uint8_t dropscore[] = {62, 75, 87, 100}; ++ const int ndropscores = FF_ARRAY_ELEMS(dropscore); ++ unsigned int buffer_fullness = (ctx->curbufsize*100)/s->max_picture_buffer; ++ ++ if(dropscore[++ctx->video_frame_num%ndropscores] <= buffer_fullness) { ++ av_log(s, AV_LOG_ERROR, ++ "real-time buffer %d%% full! frame dropped!\n", buffer_fullness); ++ return 1; ++ } ++ ++ return 0; ++} ++ ++static void ++callback(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time) ++{ ++ AVFormatContext *s = priv_data; ++ struct dshow_ctx *ctx = s->priv_data; ++ AVPacketList **ppktl, *pktl_next; ++ ++// dump_videohdr(s, vdhdr); ++ ++ if(shall_we_drop(s)) ++ return; ++ ++ WaitForSingleObject(ctx->mutex, INFINITE); ++ ++ pktl_next = av_mallocz(sizeof(AVPacketList)); ++ if(!pktl_next) ++ goto fail; ++ ++ if(av_new_packet(&pktl_next->pkt, buf_size) < 0) { ++ av_free(pktl_next); ++ goto fail; ++ } ++ ++ pktl_next->pkt.stream_index = index; ++ pktl_next->pkt.pts = time; ++ memcpy(pktl_next->pkt.data, buf, buf_size); ++ ++ for(ppktl = &ctx->pktl ; *ppktl ; ppktl = &(*ppktl)->next); ++ *ppktl = pktl_next; ++ ++ ctx->curbufsize += buf_size; ++ ++ SetEvent(ctx->event); ++ ReleaseMutex(ctx->mutex); ++ ++ return; ++fail: ++ ReleaseMutex(ctx->mutex); ++ return; ++} ++ ++/** ++ * Cycle through available devices using the device enumerator devenum, ++ * retrieve the device with type specified by devtype and return the ++ * pointer to the object found in *pfilter. ++ * If pfilter is NULL, list all device names. ++ */ ++static int ++dshow_cycle_devices(AVFormatContext *avctx, ICreateDevEnum *devenum, ++ enum dshowDeviceType devtype, IBaseFilter **pfilter) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IBaseFilter *device_filter = NULL; ++ IEnumMoniker *classenum = NULL; ++ IMoniker *m = NULL; ++ const char *device_name = ctx->device_name[devtype]; ++ int skip = (devtype == VideoDevice) ? ctx->video_device_number ++ : ctx->audio_device_number; ++ int r; ++ ++ const GUID *device_guid[2] = { &CLSID_VideoInputDeviceCategory, ++ &CLSID_AudioInputDeviceCategory }; ++ const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; ++ ++ r = ICreateDevEnum_CreateClassEnumerator(devenum, device_guid[devtype], ++ (IEnumMoniker **) &classenum, 0); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not enumerate %s devices.\n", ++ devtypename); ++ return AVERROR(EIO); ++ } ++ ++ while (!device_filter && IEnumMoniker_Next(classenum, 1, &m, NULL) == S_OK) { ++ IPropertyBag *bag = NULL; ++ char *buf = NULL; ++ VARIANT var; ++ ++ r = IMoniker_BindToStorage(m, 0, 0, &IID_IPropertyBag, (void *) &bag); ++ if (r != S_OK) ++ goto fail1; ++ ++ var.vt = VT_BSTR; ++ r = IPropertyBag_Read(bag, L"FriendlyName", &var, NULL); ++ if (r != S_OK) ++ goto fail1; ++ ++ buf = dup_wchar_to_utf8(var.bstrVal); ++ ++ if (pfilter) { ++ if (strcmp(device_name, buf)) ++ goto fail1; ++ ++ if (!skip--) ++ IMoniker_BindToObject(m, 0, 0, &IID_IBaseFilter, (void *) &device_filter); ++ } else { ++ av_log(avctx, AV_LOG_INFO, " \"%s\"\n", buf); ++ } ++ ++fail1: ++ if (buf) ++ av_free(buf); ++ if (bag) ++ IPropertyBag_Release(bag); ++ IMoniker_Release(m); ++ } ++ ++ IEnumMoniker_Release(classenum); ++ ++ if (pfilter) { ++ if (!device_filter) { ++ av_log(avctx, AV_LOG_ERROR, "Could not find %s device.\n", ++ devtypename); ++ return AVERROR(EIO); ++ } ++ *pfilter = device_filter; ++ } ++ ++ return 0; ++} ++ ++/** ++ * Cycle through available formats using the specified pin, ++ * try to set parameters specified through AVOptions and if successful ++ * return 1 in *pformat_set. ++ * If pformat_set is NULL, list all pin capabilities. ++ */ ++static void ++dshow_cycle_formats(AVFormatContext *avctx, enum dshowDeviceType devtype, ++ IPin *pin, int *pformat_set) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IAMStreamConfig *config = NULL; ++ AM_MEDIA_TYPE *type = NULL; ++ int format_set = 0; ++ void *caps = NULL; ++ int i, n, size; ++ ++ if (IPin_QueryInterface(pin, &IID_IAMStreamConfig, (void **) &config) != S_OK) ++ return; ++ if (IAMStreamConfig_GetNumberOfCapabilities(config, &n, &size) != S_OK) ++ goto end; ++ ++ caps = av_malloc(size); ++ if (!caps) ++ goto end; ++ ++ for (i = 0; i < n && !format_set; i++) { ++ IAMStreamConfig_GetStreamCaps(config, i, &type, (void *) caps); ++ ++#if DSHOWDEBUG ++ ff_print_AM_MEDIA_TYPE(type); ++#endif ++ ++ if (devtype == VideoDevice) { ++ VIDEO_STREAM_CONFIG_CAPS *vcaps = caps; ++ BITMAPINFOHEADER *bih; ++ int64_t *fr; ++#if DSHOWDEBUG ++ ff_print_VIDEO_STREAM_CONFIG_CAPS(vcaps); ++#endif ++ if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { ++ VIDEOINFOHEADER *v = (void *) type->pbFormat; ++ fr = &v->AvgTimePerFrame; ++ bih = &v->bmiHeader; ++ } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { ++ VIDEOINFOHEADER2 *v = (void *) type->pbFormat; ++ fr = &v->AvgTimePerFrame; ++ bih = &v->bmiHeader; ++ } else { ++ goto next; ++ } ++ if (!pformat_set) { ++ av_log(avctx, AV_LOG_INFO, " min s=%ldx%ld fps=%g max s=%ldx%ld fps=%g\n", ++ vcaps->MinOutputSize.cx, vcaps->MinOutputSize.cy, ++ 1e7 / vcaps->MaxFrameInterval, ++ vcaps->MaxOutputSize.cx, vcaps->MaxOutputSize.cy, ++ 1e7 / vcaps->MinFrameInterval); ++ continue; ++ } ++ if (ctx->framerate) { ++ int64_t framerate = ((int64_t) ctx->requested_framerate.den*10000000) ++ / ctx->requested_framerate.num; ++ if (framerate > vcaps->MaxFrameInterval || ++ framerate < vcaps->MinFrameInterval) ++ goto next; ++ *fr = framerate; ++ } ++ if (ctx->video_size) { ++ if (ctx->requested_width > vcaps->MaxOutputSize.cx || ++ ctx->requested_width < vcaps->MinOutputSize.cx || ++ ctx->requested_height > vcaps->MaxOutputSize.cy || ++ ctx->requested_height < vcaps->MinOutputSize.cy) ++ goto next; ++ bih->biWidth = ctx->requested_width; ++ bih->biHeight = ctx->requested_height; ++ } ++ } else { ++ AUDIO_STREAM_CONFIG_CAPS *acaps = caps; ++ WAVEFORMATEX *fx; ++#if DSHOWDEBUG ++ ff_print_AUDIO_STREAM_CONFIG_CAPS(acaps); ++#endif ++ if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { ++ fx = (void *) type->pbFormat; ++ } else { ++ goto next; ++ } ++ if (!pformat_set) { ++ av_log(avctx, AV_LOG_INFO, " min ch=%lu bits=%lu rate=%6lu max ch=%lu bits=%lu rate=%6lu\n", ++ acaps->MinimumChannels, acaps->MinimumBitsPerSample, acaps->MinimumSampleFrequency, ++ acaps->MaximumChannels, acaps->MaximumBitsPerSample, acaps->MaximumSampleFrequency); ++ continue; ++ } ++ if (ctx->sample_rate) { ++ if (ctx->sample_rate > acaps->MaximumSampleFrequency || ++ ctx->sample_rate < acaps->MinimumSampleFrequency) ++ goto next; ++ fx->nSamplesPerSec = ctx->sample_rate; ++ } ++ if (ctx->sample_size) { ++ if (ctx->sample_size > acaps->MaximumBitsPerSample || ++ ctx->sample_size < acaps->MinimumBitsPerSample) ++ goto next; ++ fx->wBitsPerSample = ctx->sample_size; ++ } ++ if (ctx->channels) { ++ if (ctx->channels > acaps->MaximumChannels || ++ ctx->channels < acaps->MinimumChannels) ++ goto next; ++ fx->nChannels = ctx->channels; ++ } ++ } ++ if (IAMStreamConfig_SetFormat(config, type) != S_OK) ++ goto next; ++ format_set = 1; ++next: ++ if (type->pbFormat) ++ CoTaskMemFree(type->pbFormat); ++ CoTaskMemFree(type); ++ } ++end: ++ IAMStreamConfig_Release(config); ++ if (caps) ++ av_free(caps); ++ if (pformat_set) ++ *pformat_set = format_set; ++} ++ ++/** ++ * Cycle through available pins using the device_filter device, of type ++ * devtype, retrieve the first output pin and return the pointer to the ++ * object found in *ppin. ++ * If ppin is NULL, cycle through all pins listing audio/video capabilities. ++ */ ++static int ++dshow_cycle_pins(AVFormatContext *avctx, enum dshowDeviceType devtype, ++ IBaseFilter *device_filter, IPin **ppin) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IEnumPins *pins = 0; ++ IPin *device_pin = NULL; ++ IPin *pin; ++ int r; ++ ++ const GUID *mediatype[2] = { &MEDIATYPE_Video, &MEDIATYPE_Audio }; ++ const char *devtypename = (devtype == VideoDevice) ? "video" : "audio"; ++ ++ int set_format = (devtype == VideoDevice && (ctx->video_size || ctx->framerate)) ++ || (devtype == AudioDevice && (ctx->channels || ctx->sample_rate)); ++ int format_set = 0; ++ ++ r = IBaseFilter_EnumPins(device_filter, &pins); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not enumerate pins.\n"); ++ return AVERROR(EIO); ++ } ++ ++ if (!ppin) { ++ av_log(avctx, AV_LOG_INFO, "DirectShow %s device options\n", ++ devtypename); ++ } ++ while (!device_pin && IEnumPins_Next(pins, 1, &pin, NULL) == S_OK) { ++ IKsPropertySet *p = NULL; ++ IEnumMediaTypes *types = NULL; ++ PIN_INFO info = {0}; ++ AM_MEDIA_TYPE *type; ++ GUID category; ++ DWORD r2; ++ ++ IPin_QueryPinInfo(pin, &info); ++ IBaseFilter_Release(info.pFilter); ++ ++ if (info.dir != PINDIR_OUTPUT) ++ goto next; ++ if (IPin_QueryInterface(pin, &IID_IKsPropertySet, (void **) &p) != S_OK) ++ goto next; ++ if (IKsPropertySet_Get(p, &ROPSETID_Pin, AMPROPERTY_PIN_CATEGORY, ++ NULL, 0, &category, sizeof(GUID), &r2) != S_OK) ++ goto next; ++ if (!IsEqualGUID(&category, &PIN_CATEGORY_CAPTURE)) ++ goto next; ++ ++ if (!ppin) { ++ char *buf = dup_wchar_to_utf8(info.achName); ++ av_log(avctx, AV_LOG_INFO, " Pin \"%s\"\n", buf); ++ av_free(buf); ++ dshow_cycle_formats(avctx, devtype, pin, NULL); ++ goto next; ++ } ++ if (set_format) { ++ dshow_cycle_formats(avctx, devtype, pin, &format_set); ++ if (!format_set) { ++ goto next; ++ } ++ } ++ ++ if (IPin_EnumMediaTypes(pin, &types) != S_OK) ++ goto next; ++ ++ IEnumMediaTypes_Reset(types); ++ while (!device_pin && IEnumMediaTypes_Next(types, 1, &type, NULL) == S_OK) { ++ if (IsEqualGUID(&type->majortype, mediatype[devtype])) { ++ device_pin = pin; ++ goto next; ++ } ++ CoTaskMemFree(type); ++ } ++ ++next: ++ if (types) ++ IEnumMediaTypes_Release(types); ++ if (p) ++ IKsPropertySet_Release(p); ++ if (device_pin != pin) ++ IPin_Release(pin); ++ } ++ ++ IEnumPins_Release(pins); ++ ++ if (ppin) { ++ if (set_format && !format_set) { ++ av_log(avctx, AV_LOG_ERROR, "Could not set %s options\n", devtypename); ++ return AVERROR(EIO); ++ } ++ if (!device_pin) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Could not find output pin from %s capture device.\n", devtypename); ++ return AVERROR(EIO); ++ } ++ *ppin = device_pin; ++ } ++ ++ return 0; ++} ++ ++/** ++ * List options for device with type devtype. ++ * ++ * @param devenum device enumerator used for accessing the device ++ */ ++static int ++dshow_list_device_options(AVFormatContext *avctx, ICreateDevEnum *devenum, ++ enum dshowDeviceType devtype) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IBaseFilter *device_filter = NULL; ++ int r; ++ ++ if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) ++ return r; ++ ctx->device_filter[devtype] = device_filter; ++ if ((r = dshow_cycle_pins(avctx, devtype, device_filter, NULL)) < 0) ++ return r; ++ ++ return 0; ++} ++ ++static int ++dshow_open_device(AVFormatContext *avctx, ICreateDevEnum *devenum, ++ enum dshowDeviceType devtype) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IBaseFilter *device_filter = NULL; ++ IGraphBuilder *graph = ctx->graph; ++ IPin *device_pin = NULL; ++ libAVPin *capture_pin = NULL; ++ libAVFilter *capture_filter = NULL; ++ int ret = AVERROR(EIO); ++ int r; ++ ++ const wchar_t *filter_name[2] = { L"Audio capture filter", L"Video capture filter" }; ++ ++ if ((r = dshow_cycle_devices(avctx, devenum, devtype, &device_filter)) < 0) { ++ ret = r; ++ goto error; ++ } ++ ++ ctx->device_filter [devtype] = device_filter; ++ ++ r = IGraphBuilder_AddFilter(graph, device_filter, NULL); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not add device filter to graph.\n"); ++ goto error; ++ } ++ ++ if ((r = dshow_cycle_pins(avctx, devtype, device_filter, &device_pin)) < 0) { ++ ret = r; ++ goto error; ++ } ++ ctx->device_pin[devtype] = device_pin; ++ ++ capture_filter = libAVFilter_Create(avctx, callback, devtype); ++ if (!capture_filter) { ++ av_log(avctx, AV_LOG_ERROR, "Could not create grabber filter.\n"); ++ goto error; ++ } ++ ctx->capture_filter[devtype] = capture_filter; ++ ++ r = IGraphBuilder_AddFilter(graph, (IBaseFilter *) capture_filter, ++ filter_name[devtype]); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not add capture filter to graph\n"); ++ goto error; ++ } ++ ++ libAVPin_AddRef(capture_filter->pin); ++ capture_pin = capture_filter->pin; ++ ctx->capture_pin[devtype] = capture_pin; ++ ++ r = IGraphBuilder_ConnectDirect(graph, device_pin, (IPin *) capture_pin, NULL); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not connect pins\n"); ++ goto error; ++ } ++ ++ ret = 0; ++ ++error: ++ return ret; ++} ++ ++static enum CodecID waveform_codec_id(enum AVSampleFormat sample_fmt) ++{ ++ switch (sample_fmt) { ++ case AV_SAMPLE_FMT_U8: return CODEC_ID_PCM_U8; ++ case AV_SAMPLE_FMT_S16: return CODEC_ID_PCM_S16LE; ++ case AV_SAMPLE_FMT_S32: return CODEC_ID_PCM_S32LE; ++ default: return CODEC_ID_NONE; /* Should never happen. */ ++ } ++} ++ ++static enum SampleFormat sample_fmt_bits_per_sample(int bits) ++{ ++ switch (bits) { ++ case 8: return AV_SAMPLE_FMT_U8; ++ case 16: return AV_SAMPLE_FMT_S16; ++ case 32: return AV_SAMPLE_FMT_S32; ++ default: return AV_SAMPLE_FMT_NONE; /* Should never happen. */ ++ } ++} ++ ++static int ++dshow_add_device(AVFormatContext *avctx, AVFormatParameters *ap, ++ enum dshowDeviceType devtype) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ AM_MEDIA_TYPE type; ++ AVCodecContext *codec; ++ AVStream *st; ++ int ret = AVERROR(EIO); ++ ++ st = avformat_new_stream(avctx, NULL); ++ if (!st) { ++ ret = AVERROR(ENOMEM); ++ goto error; ++ } ++ st->id = devtype; ++ ++ ctx->capture_filter[devtype]->stream_index = st->index; ++ ++ libAVPin_ConnectionMediaType(ctx->capture_pin[devtype], &type); ++ ++ codec = st->codec; ++ if (devtype == VideoDevice) { ++ BITMAPINFOHEADER *bih = NULL; ++ ++ if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo)) { ++ VIDEOINFOHEADER *v = (void *) type.pbFormat; ++ bih = &v->bmiHeader; ++ } else if (IsEqualGUID(&type.formattype, &FORMAT_VideoInfo2)) { ++ VIDEOINFOHEADER2 *v = (void *) type.pbFormat; ++ bih = &v->bmiHeader; ++ } ++ if (!bih) { ++ av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); ++ goto error; ++ } ++ ++ codec->time_base = ap->time_base; ++ codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ codec->width = bih->biWidth; ++ codec->height = bih->biHeight; ++ codec->pix_fmt = dshow_pixfmt(bih->biCompression, bih->biBitCount); ++ if (codec->pix_fmt == PIX_FMT_NONE) { ++ codec->codec_id = dshow_codecid(bih->biCompression); ++ if (codec->codec_id == CODEC_ID_NONE) { ++ av_log(avctx, AV_LOG_ERROR, "Unknown compression type. " ++ "Please report verbose (-v 9) debug information.\n"); ++ dshow_read_close(avctx); ++ return AVERROR_PATCHWELCOME; ++ } ++ codec->bits_per_coded_sample = bih->biBitCount; ++ } else { ++ codec->codec_id = CODEC_ID_RAWVIDEO; ++ if (bih->biCompression == BI_RGB || bih->biCompression == BI_BITFIELDS) { ++ codec->bits_per_coded_sample = bih->biBitCount; ++ codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (codec->extradata) { ++ codec->extradata_size = 9; ++ memcpy(codec->extradata, "BottomUp", 9); ++ } ++ } ++ } ++ } else { ++ WAVEFORMATEX *fx = NULL; ++ ++ if (IsEqualGUID(&type.formattype, &FORMAT_WaveFormatEx)) { ++ fx = (void *) type.pbFormat; ++ } ++ if (!fx) { ++ av_log(avctx, AV_LOG_ERROR, "Could not get media type.\n"); ++ goto error; ++ } ++ ++ codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ codec->sample_fmt = sample_fmt_bits_per_sample(fx->wBitsPerSample); ++ codec->codec_id = waveform_codec_id(codec->sample_fmt); ++ codec->sample_rate = fx->nSamplesPerSec; ++ codec->channels = fx->nChannels; ++ } ++ ++ avpriv_set_pts_info(st, 64, 1, 10000000); ++ ++ ret = 0; ++ ++error: ++ return ret; ++} ++ ++static int parse_device_name(AVFormatContext *avctx) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ char **device_name = ctx->device_name; ++ char *name = av_strdup(avctx->filename); ++ char *tmp = name; ++ int ret = 1; ++ char *type; ++ ++ while ((type = strtok(tmp, "="))) { ++ char *token = strtok(NULL, ":"); ++ tmp = NULL; ++ ++ if (!strcmp(type, "video")) { ++ device_name[0] = token; ++ } else if (!strcmp(type, "audio")) { ++ device_name[1] = token; ++ } else { ++ device_name[0] = NULL; ++ device_name[1] = NULL; ++ break; ++ } ++ } ++ ++ if (!device_name[0] && !device_name[1]) { ++ ret = 0; ++ } else { ++ if (device_name[0]) ++ device_name[0] = av_strdup(device_name[0]); ++ if (device_name[1]) ++ device_name[1] = av_strdup(device_name[1]); ++ } ++ ++ av_free(name); ++ return ret; ++} ++ ++static int dshow_read_header(AVFormatContext *avctx, AVFormatParameters *ap) ++{ ++ struct dshow_ctx *ctx = avctx->priv_data; ++ IGraphBuilder *graph = NULL; ++ ICreateDevEnum *devenum = NULL; ++ IMediaControl *control = NULL; ++ int ret = AVERROR(EIO); ++ int r; ++ ++ if (!ctx->list_devices && !parse_device_name(avctx)) { ++ av_log(avctx, AV_LOG_ERROR, "Malformed dshow input string.\n"); ++ goto error; ++ } ++ ++ if (ctx->video_size) { ++ r = av_parse_video_size(&ctx->requested_width, &ctx->requested_height, ctx->video_size); ++ if (r < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not parse video size '%s'.\n", ctx->video_size); ++ goto error; ++ } ++ } ++ if (ctx->framerate) { ++ r = av_parse_video_rate(&ctx->requested_framerate, ctx->framerate); ++ if (r < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate); ++ goto error; ++ } ++ } ++ ++ CoInitialize(0); ++ ++ r = CoCreateInstance(&CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, ++ &IID_IGraphBuilder, (void **) &graph); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not create capture graph.\n"); ++ goto error; ++ } ++ ctx->graph = graph; ++ ++ r = CoCreateInstance(&CLSID_SystemDeviceEnum, NULL, CLSCTX_INPROC_SERVER, ++ &IID_ICreateDevEnum, (void **) &devenum); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not enumerate system devices.\n"); ++ goto error; ++ } ++ ++ if (ctx->list_devices) { ++ av_log(avctx, AV_LOG_INFO, "DirectShow video devices\n"); ++ dshow_cycle_devices(avctx, devenum, VideoDevice, NULL); ++ av_log(avctx, AV_LOG_INFO, "DirectShow audio devices\n"); ++ dshow_cycle_devices(avctx, devenum, AudioDevice, NULL); ++ ret = AVERROR_EXIT; ++ goto error; ++ } ++ if (ctx->list_options) { ++ if (ctx->device_name[VideoDevice]) ++ dshow_list_device_options(avctx, devenum, VideoDevice); ++ if (ctx->device_name[AudioDevice]) ++ dshow_list_device_options(avctx, devenum, AudioDevice); ++ ret = AVERROR_EXIT; ++ goto error; ++ } ++ ++ if (ctx->device_name[VideoDevice]) { ++ ret = dshow_open_device(avctx, devenum, VideoDevice); ++ if (ret < 0) ++ goto error; ++ ret = dshow_add_device(avctx, ap, VideoDevice); ++ if (ret < 0) ++ goto error; ++ } ++ if (ctx->device_name[AudioDevice]) { ++ ret = dshow_open_device(avctx, devenum, AudioDevice); ++ if (ret < 0) ++ goto error; ++ ret = dshow_add_device(avctx, ap, AudioDevice); ++ if (ret < 0) ++ goto error; ++ } ++ ++ ctx->mutex = CreateMutex(NULL, 0, NULL); ++ if (!ctx->mutex) { ++ av_log(avctx, AV_LOG_ERROR, "Could not create Mutex\n"); ++ goto error; ++ } ++ ctx->event = CreateEvent(NULL, 1, 0, NULL); ++ if (!ctx->event) { ++ av_log(avctx, AV_LOG_ERROR, "Could not create Event\n"); ++ goto error; ++ } ++ ++ r = IGraphBuilder_QueryInterface(graph, &IID_IMediaControl, (void **) &control); ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not get media control.\n"); ++ goto error; ++ } ++ ctx->control = control; ++ ++ r = IMediaControl_Run(control); ++ if (r == S_FALSE) { ++ OAFilterState pfs; ++ r = IMediaControl_GetState(control, 0, &pfs); ++ } ++ if (r != S_OK) { ++ av_log(avctx, AV_LOG_ERROR, "Could not run filter\n"); ++ goto error; ++ } ++ ++ ret = 0; ++ ++error: ++ ++ if (ret < 0) ++ dshow_read_close(avctx); ++ ++ if (devenum) ++ ICreateDevEnum_Release(devenum); ++ ++ return ret; ++} ++ ++static int dshow_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ struct dshow_ctx *ctx = s->priv_data; ++ AVPacketList *pktl = NULL; ++ ++ while (!pktl) { ++ WaitForSingleObject(ctx->mutex, INFINITE); ++ pktl = ctx->pktl; ++ if (ctx->pktl) { ++ *pkt = ctx->pktl->pkt; ++ ctx->pktl = ctx->pktl->next; ++ av_free(pktl); ++ } ++ ResetEvent(ctx->event); ++ ReleaseMutex(ctx->mutex); ++ if (!pktl) { ++ if (s->flags & AVFMT_FLAG_NONBLOCK) { ++ return AVERROR(EAGAIN); ++ } else { ++ WaitForSingleObject(ctx->event, INFINITE); ++ } ++ } ++ } ++ ++ ctx->curbufsize -= pkt->size; ++ ++ return pkt->size; ++} ++ ++#define OFFSET(x) offsetof(struct dshow_ctx, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "video_size", "set video size given a string such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "framerate", "set video frame rate", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "sample_rate", "set audio sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC }, ++ { "sample_size", "set audio sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 16, DEC }, ++ { "channels", "set number of audio channels, such as 1 or 2", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC }, ++ { "list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_devices" }, ++ { "true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_devices" }, ++ { "false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_devices" }, ++ { "list_options", "list available options for specified device", OFFSET(list_options), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, DEC, "list_options" }, ++ { "true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, DEC, "list_options" }, ++ { "false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, DEC, "list_options" }, ++ { "video_device_number", "set video device number for devices with same name (starts at 0)", OFFSET(video_device_number), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC }, ++ { "audio_device_number", "set audio device number for devices with same name (starts at 0)", OFFSET(audio_device_number), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass dshow_class = { ++ .class_name = "DirectShow indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_dshow_demuxer = { ++ "dshow", ++ NULL_IF_CONFIG_SMALL("DirectShow capture"), ++ sizeof(struct dshow_ctx), ++ NULL, ++ dshow_read_header, ++ dshow_read_packet, ++ dshow_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &dshow_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_common.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_common.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_common.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_common.c 2012-05-14 14:08:54.641346161 +0200 +@@ -0,0 +1,190 @@ ++/* ++ * Directshow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dshow.h" ++ ++long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src) ++{ ++ uint8_t *pbFormat = NULL; ++ ++ if (src->cbFormat) { ++ pbFormat = CoTaskMemAlloc(src->cbFormat); ++ if (!pbFormat) ++ return E_OUTOFMEMORY; ++ memcpy(pbFormat, src->pbFormat, src->cbFormat); ++ } ++ ++ *dst = *src; ++ dst->pUnk = NULL; ++ dst->pbFormat = pbFormat; ++ ++ return S_OK; ++} ++ ++void ff_printGUID(const GUID *g) ++{ ++#if DSHOWDEBUG ++ const uint32_t *d = (const uint32_t *) &g->Data1; ++ const uint16_t *w = (const uint16_t *) &g->Data2; ++ const uint8_t *c = (const uint8_t *) &g->Data4; ++ ++ dshowdebug("0x%08x 0x%04x 0x%04x %02x%02x%02x%02x%02x%02x%02x%02x", ++ d[0], w[0], w[1], ++ c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]); ++#endif ++} ++ ++static const char *dshow_context_to_name(void *ptr) ++{ ++ return "dshow"; ++} ++static const AVClass ff_dshow_context_class = { "DirectShow", dshow_context_to_name }; ++const AVClass *ff_dshow_context_class_ptr = &ff_dshow_context_class; ++ ++#define dstruct(pctx, sname, var, type) \ ++ dshowdebug(" "#var":\t%"type"\n", sname->var) ++ ++#if DSHOWDEBUG ++static void dump_bih(void *s, BITMAPINFOHEADER *bih) ++{ ++ dshowdebug(" BITMAPINFOHEADER\n"); ++ dstruct(s, bih, biSize, "lu"); ++ dstruct(s, bih, biWidth, "ld"); ++ dstruct(s, bih, biHeight, "ld"); ++ dstruct(s, bih, biPlanes, "d"); ++ dstruct(s, bih, biBitCount, "d"); ++ dstruct(s, bih, biCompression, "lu"); ++ dshowdebug(" biCompression:\t\"%.4s\"\n", ++ (char*) &bih->biCompression); ++ dstruct(s, bih, biSizeImage, "lu"); ++ dstruct(s, bih, biXPelsPerMeter, "lu"); ++ dstruct(s, bih, biYPelsPerMeter, "lu"); ++ dstruct(s, bih, biClrUsed, "lu"); ++ dstruct(s, bih, biClrImportant, "lu"); ++} ++#endif ++ ++void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps) ++{ ++#if DSHOWDEBUG ++ dshowdebug(" VIDEO_STREAM_CONFIG_CAPS\n"); ++ dshowdebug(" guid\t"); ++ ff_printGUID(&caps->guid); ++ dshowdebug("\n"); ++ dshowdebug(" VideoStandard\t%lu\n", caps->VideoStandard); ++ dshowdebug(" InputSize %ld\t%ld\n", caps->InputSize.cx, caps->InputSize.cy); ++ dshowdebug(" MinCroppingSize %ld\t%ld\n", caps->MinCroppingSize.cx, caps->MinCroppingSize.cy); ++ dshowdebug(" MaxCroppingSize %ld\t%ld\n", caps->MaxCroppingSize.cx, caps->MaxCroppingSize.cy); ++ dshowdebug(" CropGranularityX\t%d\n", caps->CropGranularityX); ++ dshowdebug(" CropGranularityY\t%d\n", caps->CropGranularityY); ++ dshowdebug(" CropAlignX\t%d\n", caps->CropAlignX); ++ dshowdebug(" CropAlignY\t%d\n", caps->CropAlignY); ++ dshowdebug(" MinOutputSize %ld\t%ld\n", caps->MinOutputSize.cx, caps->MinOutputSize.cy); ++ dshowdebug(" MaxOutputSize %ld\t%ld\n", caps->MaxOutputSize.cx, caps->MaxOutputSize.cy); ++ dshowdebug(" OutputGranularityX\t%d\n", caps->OutputGranularityX); ++ dshowdebug(" OutputGranularityY\t%d\n", caps->OutputGranularityY); ++ dshowdebug(" StretchTapsX\t%d\n", caps->StretchTapsX); ++ dshowdebug(" StretchTapsY\t%d\n", caps->StretchTapsY); ++ dshowdebug(" ShrinkTapsX\t%d\n", caps->ShrinkTapsX); ++ dshowdebug(" ShrinkTapsY\t%d\n", caps->ShrinkTapsY); ++ dshowdebug(" MinFrameInterval\t%"PRId64"\n", caps->MinFrameInterval); ++ dshowdebug(" MaxFrameInterval\t%"PRId64"\n", caps->MaxFrameInterval); ++ dshowdebug(" MinBitsPerSecond\t%ld\n", caps->MinBitsPerSecond); ++ dshowdebug(" MaxBitsPerSecond\t%ld\n", caps->MaxBitsPerSecond); ++#endif ++} ++ ++void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps) ++{ ++#if DSHOWDEBUG ++ dshowdebug(" AUDIO_STREAM_CONFIG_CAPS\n"); ++ dshowdebug(" guid\t"); ++ ff_printGUID(&caps->guid); ++ dshowdebug("\n"); ++ dshowdebug(" MinimumChannels\t%lu\n", caps->MinimumChannels); ++ dshowdebug(" MaximumChannels\t%lu\n", caps->MaximumChannels); ++ dshowdebug(" ChannelsGranularity\t%lu\n", caps->ChannelsGranularity); ++ dshowdebug(" MinimumBitsPerSample\t%lu\n", caps->MinimumBitsPerSample); ++ dshowdebug(" MaximumBitsPerSample\t%lu\n", caps->MaximumBitsPerSample); ++ dshowdebug(" BitsPerSampleGranularity\t%lu\n", caps->BitsPerSampleGranularity); ++ dshowdebug(" MinimumSampleFrequency\t%lu\n", caps->MinimumSampleFrequency); ++ dshowdebug(" MaximumSampleFrequency\t%lu\n", caps->MaximumSampleFrequency); ++ dshowdebug(" SampleFrequencyGranularity\t%lu\n", caps->SampleFrequencyGranularity); ++#endif ++} ++ ++void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type) ++{ ++#if DSHOWDEBUG ++ dshowdebug(" majortype\t"); ++ ff_printGUID(&type->majortype); ++ dshowdebug("\n"); ++ dshowdebug(" subtype\t"); ++ ff_printGUID(&type->subtype); ++ dshowdebug("\n"); ++ dshowdebug(" bFixedSizeSamples\t%d\n", type->bFixedSizeSamples); ++ dshowdebug(" bTemporalCompression\t%d\n", type->bTemporalCompression); ++ dshowdebug(" lSampleSize\t%lu\n", type->lSampleSize); ++ dshowdebug(" formattype\t"); ++ ff_printGUID(&type->formattype); ++ dshowdebug("\n"); ++ dshowdebug(" pUnk\t%p\n", type->pUnk); ++ dshowdebug(" cbFormat\t%lu\n", type->cbFormat); ++ dshowdebug(" pbFormat\t%p\n", type->pbFormat); ++ ++ if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo)) { ++ VIDEOINFOHEADER *v = (void *) type->pbFormat; ++ dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n", ++ v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom); ++ dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n", ++ v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom); ++ dshowdebug(" dwBitRate: %lu\n", v->dwBitRate); ++ dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate); ++ dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame); ++ dump_bih(NULL, &v->bmiHeader); ++ } else if (IsEqualGUID(&type->formattype, &FORMAT_VideoInfo2)) { ++ VIDEOINFOHEADER2 *v = (void *) type->pbFormat; ++ dshowdebug(" rcSource: left %ld top %ld right %ld bottom %ld\n", ++ v->rcSource.left, v->rcSource.top, v->rcSource.right, v->rcSource.bottom); ++ dshowdebug(" rcTarget: left %ld top %ld right %ld bottom %ld\n", ++ v->rcTarget.left, v->rcTarget.top, v->rcTarget.right, v->rcTarget.bottom); ++ dshowdebug(" dwBitRate: %lu\n", v->dwBitRate); ++ dshowdebug(" dwBitErrorRate: %lu\n", v->dwBitErrorRate); ++ dshowdebug(" AvgTimePerFrame: %"PRId64"\n", v->AvgTimePerFrame); ++ dshowdebug(" dwInterlaceFlags: %lu\n", v->dwInterlaceFlags); ++ dshowdebug(" dwCopyProtectFlags: %lu\n", v->dwCopyProtectFlags); ++ dshowdebug(" dwPictAspectRatioX: %lu\n", v->dwPictAspectRatioX); ++ dshowdebug(" dwPictAspectRatioY: %lu\n", v->dwPictAspectRatioY); ++// dshowdebug(" dwReserved1: %lu\n", v->u.dwReserved1); /* mingw-w64 is buggy and doesn't name unnamed unions */ ++ dshowdebug(" dwReserved2: %lu\n", v->dwReserved2); ++ dump_bih(NULL, &v->bmiHeader); ++ } else if (IsEqualGUID(&type->formattype, &FORMAT_WaveFormatEx)) { ++ WAVEFORMATEX *fx = (void *) type->pbFormat; ++ dshowdebug(" wFormatTag: %u\n", fx->wFormatTag); ++ dshowdebug(" nChannels: %u\n", fx->nChannels); ++ dshowdebug(" nSamplesPerSec: %lu\n", fx->nSamplesPerSec); ++ dshowdebug(" nAvgBytesPerSec: %lu\n", fx->nAvgBytesPerSec); ++ dshowdebug(" nBlockAlign: %u\n", fx->nBlockAlign); ++ dshowdebug(" wBitsPerSample: %u\n", fx->wBitsPerSample); ++ dshowdebug(" cbSize: %u\n", fx->cbSize); ++ } ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_enummediatypes.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_enummediatypes.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_enummediatypes.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_enummediatypes.c 2012-05-14 14:08:54.642346181 +0200 +@@ -0,0 +1,103 @@ ++/* ++ * DirectShow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dshow.h" ++ ++DECLARE_QUERYINTERFACE(libAVEnumMediaTypes, ++ { {&IID_IUnknown,0}, {&IID_IEnumPins,0} }) ++DECLARE_ADDREF(libAVEnumMediaTypes) ++DECLARE_RELEASE(libAVEnumMediaTypes) ++ ++long WINAPI ++libAVEnumMediaTypes_Next(libAVEnumMediaTypes *this, unsigned long n, ++ AM_MEDIA_TYPE **types, unsigned long *fetched) ++{ ++ int count = 0; ++ dshowdebug("libAVEnumMediaTypes_Next(%p)\n", this); ++ if (!types) ++ return E_POINTER; ++ if (!this->pos && n == 1) { ++ if (!IsEqualGUID(&this->type.majortype, &GUID_NULL)) { ++ AM_MEDIA_TYPE *type = av_malloc(sizeof(AM_MEDIA_TYPE)); ++ ff_copy_dshow_media_type(type, &this->type); ++ *types = type; ++ count = 1; ++ } ++ this->pos = 1; ++ } ++ if (fetched) ++ *fetched = count; ++ if (!count) ++ return S_FALSE; ++ return S_OK; ++} ++long WINAPI ++libAVEnumMediaTypes_Skip(libAVEnumMediaTypes *this, unsigned long n) ++{ ++ dshowdebug("libAVEnumMediaTypes_Skip(%p)\n", this); ++ if (n) /* Any skip will always fall outside of the only valid type. */ ++ return S_FALSE; ++ return S_OK; ++} ++long WINAPI ++libAVEnumMediaTypes_Reset(libAVEnumMediaTypes *this) ++{ ++ dshowdebug("libAVEnumMediaTypes_Reset(%p)\n", this); ++ this->pos = 0; ++ return S_OK; ++} ++long WINAPI ++libAVEnumMediaTypes_Clone(libAVEnumMediaTypes *this, libAVEnumMediaTypes **enums) ++{ ++ libAVEnumMediaTypes *new; ++ dshowdebug("libAVEnumMediaTypes_Clone(%p)\n", this); ++ if (!enums) ++ return E_POINTER; ++ new = libAVEnumMediaTypes_Create(&this->type); ++ if (!new) ++ return E_OUTOFMEMORY; ++ new->pos = this->pos; ++ *enums = new; ++ return S_OK; ++} ++ ++static int ++libAVEnumMediaTypes_Setup(libAVEnumMediaTypes *this, const AM_MEDIA_TYPE *type) ++{ ++ IEnumPinsVtbl *vtbl = this->vtbl; ++ SETVTBL(vtbl, libAVEnumMediaTypes, QueryInterface); ++ SETVTBL(vtbl, libAVEnumMediaTypes, AddRef); ++ SETVTBL(vtbl, libAVEnumMediaTypes, Release); ++ SETVTBL(vtbl, libAVEnumMediaTypes, Next); ++ SETVTBL(vtbl, libAVEnumMediaTypes, Skip); ++ SETVTBL(vtbl, libAVEnumMediaTypes, Reset); ++ SETVTBL(vtbl, libAVEnumMediaTypes, Clone); ++ ++ if (!type) { ++ this->type.majortype = GUID_NULL; ++ } else { ++ ff_copy_dshow_media_type(&this->type, type); ++ } ++ ++ return 1; ++} ++DECLARE_CREATE(libAVEnumMediaTypes, libAVEnumMediaTypes_Setup(this, type), const AM_MEDIA_TYPE *type) ++DECLARE_DESTROY(libAVEnumMediaTypes, nothing) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_enumpins.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_enumpins.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_enumpins.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_enumpins.c 2012-05-14 14:08:54.642346181 +0200 +@@ -0,0 +1,105 @@ ++/* ++ * DirectShow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dshow.h" ++ ++DECLARE_QUERYINTERFACE(libAVEnumPins, ++ { {&IID_IUnknown,0}, {&IID_IEnumPins,0} }) ++DECLARE_ADDREF(libAVEnumPins) ++DECLARE_RELEASE(libAVEnumPins) ++ ++long WINAPI ++libAVEnumPins_Next(libAVEnumPins *this, unsigned long n, IPin **pins, ++ unsigned long *fetched) ++{ ++ int count = 0; ++ dshowdebug("libAVEnumPins_Next(%p)\n", this); ++ if (!pins) ++ return E_POINTER; ++ if (!this->pos && n == 1) { ++ libAVPin_AddRef(this->pin); ++ *pins = (IPin *) this->pin; ++ count = 1; ++ this->pos = 1; ++ } ++ if (fetched) ++ *fetched = count; ++ if (!count) ++ return S_FALSE; ++ return S_OK; ++} ++long WINAPI ++libAVEnumPins_Skip(libAVEnumPins *this, unsigned long n) ++{ ++ dshowdebug("libAVEnumPins_Skip(%p)\n", this); ++ if (n) /* Any skip will always fall outside of the only valid pin. */ ++ return S_FALSE; ++ return S_OK; ++} ++long WINAPI ++libAVEnumPins_Reset(libAVEnumPins *this) ++{ ++ dshowdebug("libAVEnumPins_Reset(%p)\n", this); ++ this->pos = 0; ++ return S_OK; ++} ++long WINAPI ++libAVEnumPins_Clone(libAVEnumPins *this, libAVEnumPins **pins) ++{ ++ libAVEnumPins *new; ++ dshowdebug("libAVEnumPins_Clone(%p)\n", this); ++ if (!pins) ++ return E_POINTER; ++ new = libAVEnumPins_Create(this->pin, this->filter); ++ if (!new) ++ return E_OUTOFMEMORY; ++ new->pos = this->pos; ++ *pins = new; ++ return S_OK; ++} ++ ++static int ++libAVEnumPins_Setup(libAVEnumPins *this, libAVPin *pin, libAVFilter *filter) ++{ ++ IEnumPinsVtbl *vtbl = this->vtbl; ++ SETVTBL(vtbl, libAVEnumPins, QueryInterface); ++ SETVTBL(vtbl, libAVEnumPins, AddRef); ++ SETVTBL(vtbl, libAVEnumPins, Release); ++ SETVTBL(vtbl, libAVEnumPins, Next); ++ SETVTBL(vtbl, libAVEnumPins, Skip); ++ SETVTBL(vtbl, libAVEnumPins, Reset); ++ SETVTBL(vtbl, libAVEnumPins, Clone); ++ ++ this->pin = pin; ++ this->filter = filter; ++ libAVFilter_AddRef(this->filter); ++ ++ return 1; ++} ++static int ++libAVEnumPins_Cleanup(libAVEnumPins *this) ++{ ++ libAVFilter_Release(this->filter); ++ return 1; ++} ++DECLARE_CREATE(libAVEnumPins, libAVEnumPins_Setup(this, pin, filter), ++ libAVPin *pin, libAVFilter *filter) ++DECLARE_DESTROY(libAVEnumPins, libAVEnumPins_Cleanup) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_filter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_filter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_filter.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_filter.c 2012-05-14 14:08:54.643346201 +0200 +@@ -0,0 +1,202 @@ ++/* ++ * DirectShow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dshow.h" ++ ++DECLARE_QUERYINTERFACE(libAVFilter, ++ { {&IID_IUnknown,0}, {&IID_IBaseFilter,0} }) ++DECLARE_ADDREF(libAVFilter) ++DECLARE_RELEASE(libAVFilter) ++ ++long WINAPI ++libAVFilter_GetClassID(libAVFilter *this, CLSID *id) ++{ ++ dshowdebug("libAVFilter_GetClassID(%p)\n", this); ++ /* I'm not creating a ClassID just for this. */ ++ return E_FAIL; ++} ++long WINAPI ++libAVFilter_Stop(libAVFilter *this) ++{ ++ dshowdebug("libAVFilter_Stop(%p)\n", this); ++ this->state = State_Stopped; ++ return S_OK; ++} ++long WINAPI ++libAVFilter_Pause(libAVFilter *this) ++{ ++ dshowdebug("libAVFilter_Pause(%p)\n", this); ++ this->state = State_Paused; ++ return S_OK; ++} ++long WINAPI ++libAVFilter_Run(libAVFilter *this, REFERENCE_TIME start) ++{ ++ dshowdebug("libAVFilter_Run(%p) %"PRId64"\n", this, start); ++ this->state = State_Running; ++ this->start_time = start; ++ return S_OK; ++} ++long WINAPI ++libAVFilter_GetState(libAVFilter *this, DWORD ms, FILTER_STATE *state) ++{ ++ dshowdebug("libAVFilter_GetState(%p)\n", this); ++ if (!state) ++ return E_POINTER; ++ *state = this->state; ++ return S_OK; ++} ++long WINAPI ++libAVFilter_SetSyncSource(libAVFilter *this, IReferenceClock *clock) ++{ ++ dshowdebug("libAVFilter_SetSyncSource(%p)\n", this); ++ ++ if (this->clock != clock) { ++ if (this->clock) ++ IReferenceClock_Release(this->clock); ++ this->clock = clock; ++ if (clock) ++ IReferenceClock_AddRef(clock); ++ } ++ ++ return S_OK; ++} ++long WINAPI ++libAVFilter_GetSyncSource(libAVFilter *this, IReferenceClock **clock) ++{ ++ dshowdebug("libAVFilter_GetSyncSource(%p)\n", this); ++ ++ if (!clock) ++ return E_POINTER; ++ if (this->clock) ++ IReferenceClock_AddRef(this->clock); ++ *clock = this->clock; ++ ++ return S_OK; ++} ++long WINAPI ++libAVFilter_EnumPins(libAVFilter *this, IEnumPins **enumpin) ++{ ++ libAVEnumPins *new; ++ dshowdebug("libAVFilter_EnumPins(%p)\n", this); ++ ++ if (!enumpin) ++ return E_POINTER; ++ new = libAVEnumPins_Create(this->pin, this); ++ if (!new) ++ return E_OUTOFMEMORY; ++ ++ *enumpin = (IEnumPins *) new; ++ return S_OK; ++} ++long WINAPI ++libAVFilter_FindPin(libAVFilter *this, const wchar_t *id, IPin **pin) ++{ ++ libAVPin *found = NULL; ++ dshowdebug("libAVFilter_FindPin(%p)\n", this); ++ ++ if (!id || !pin) ++ return E_POINTER; ++ if (!wcscmp(id, L"In")) { ++ found = this->pin; ++ libAVPin_AddRef(found); ++ } ++ *pin = (IPin *) found; ++ if (!found) ++ return VFW_E_NOT_FOUND; ++ ++ return S_OK; ++} ++long WINAPI ++libAVFilter_QueryFilterInfo(libAVFilter *this, FILTER_INFO *info) ++{ ++ dshowdebug("libAVFilter_QueryFilterInfo(%p)\n", this); ++ ++ if (!info) ++ return E_POINTER; ++ if (this->info.pGraph) ++ IFilterGraph_AddRef(this->info.pGraph); ++ *info = this->info; ++ ++ return S_OK; ++} ++long WINAPI ++libAVFilter_JoinFilterGraph(libAVFilter *this, IFilterGraph *graph, ++ const wchar_t *name) ++{ ++ dshowdebug("libAVFilter_JoinFilterGraph(%p)\n", this); ++ ++ this->info.pGraph = graph; ++ if (name) ++ wcscpy(this->info.achName, name); ++ ++ return S_OK; ++} ++long WINAPI ++libAVFilter_QueryVendorInfo(libAVFilter *this, wchar_t **info) ++{ ++ dshowdebug("libAVFilter_QueryVendorInfo(%p)\n", this); ++ ++ if (!info) ++ return E_POINTER; ++ *info = wcsdup(L"libAV"); ++ ++ return S_OK; ++} ++ ++static int ++libAVFilter_Setup(libAVFilter *this, void *priv_data, void *callback, ++ enum dshowDeviceType type) ++{ ++ IBaseFilterVtbl *vtbl = this->vtbl; ++ SETVTBL(vtbl, libAVFilter, QueryInterface); ++ SETVTBL(vtbl, libAVFilter, AddRef); ++ SETVTBL(vtbl, libAVFilter, Release); ++ SETVTBL(vtbl, libAVFilter, GetClassID); ++ SETVTBL(vtbl, libAVFilter, Stop); ++ SETVTBL(vtbl, libAVFilter, Pause); ++ SETVTBL(vtbl, libAVFilter, Run); ++ SETVTBL(vtbl, libAVFilter, GetState); ++ SETVTBL(vtbl, libAVFilter, SetSyncSource); ++ SETVTBL(vtbl, libAVFilter, GetSyncSource); ++ SETVTBL(vtbl, libAVFilter, EnumPins); ++ SETVTBL(vtbl, libAVFilter, FindPin); ++ SETVTBL(vtbl, libAVFilter, QueryFilterInfo); ++ SETVTBL(vtbl, libAVFilter, JoinFilterGraph); ++ SETVTBL(vtbl, libAVFilter, QueryVendorInfo); ++ ++ this->pin = libAVPin_Create(this); ++ ++ this->priv_data = priv_data; ++ this->callback = callback; ++ this->type = type; ++ ++ return 1; ++} ++static int ++libAVFilter_Cleanup(libAVFilter *this) ++{ ++ libAVPin_Release(this->pin); ++ return 1; ++} ++DECLARE_CREATE(libAVFilter, libAVFilter_Setup(this, priv_data, callback, type), ++ void *priv_data, void *callback, enum dshowDeviceType type) ++DECLARE_DESTROY(libAVFilter, libAVFilter_Cleanup) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow.h 2012-05-14 14:08:54.640346141 +0200 +@@ -0,0 +1,268 @@ ++/* ++ * DirectShow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#define DSHOWDEBUG 0 ++ ++#include "avdevice.h" ++ ++#define COBJMACROS ++#include ++#include ++#include ++ ++long ff_copy_dshow_media_type(AM_MEDIA_TYPE *dst, const AM_MEDIA_TYPE *src); ++void ff_print_VIDEO_STREAM_CONFIG_CAPS(const VIDEO_STREAM_CONFIG_CAPS *caps); ++void ff_print_AUDIO_STREAM_CONFIG_CAPS(const AUDIO_STREAM_CONFIG_CAPS *caps); ++void ff_print_AM_MEDIA_TYPE(const AM_MEDIA_TYPE *type); ++void ff_printGUID(const GUID *g); ++ ++#if DSHOWDEBUG ++extern const AVClass *ff_dshow_context_class_ptr; ++#define dshowdebug(...) av_log(&ff_dshow_context_class_ptr, AV_LOG_DEBUG, __VA_ARGS__) ++#else ++#define dshowdebug(...) ++#endif ++ ++static inline void nothing(void *foo) ++{ ++} ++ ++struct GUIDoffset { ++ const GUID *iid; ++ int offset; ++}; ++ ++enum dshowDeviceType { ++ VideoDevice = 0, ++ AudioDevice = 1, ++}; ++ ++#define DECLARE_QUERYINTERFACE(class, ...) \ ++long WINAPI \ ++class##_QueryInterface(class *this, const GUID *riid, void **ppvObject) \ ++{ \ ++ struct GUIDoffset ifaces[] = __VA_ARGS__; \ ++ int i; \ ++ dshowdebug(AV_STRINGIFY(class)"_QueryInterface(%p, %p, %p)\n", this, riid, ppvObject); \ ++ ff_printGUID(riid); \ ++ if (!ppvObject) \ ++ return E_POINTER; \ ++ for (i = 0; i < sizeof(ifaces)/sizeof(ifaces[0]); i++) { \ ++ if (IsEqualGUID(riid, ifaces[i].iid)) { \ ++ void *obj = (void *) ((uint8_t *) this + ifaces[i].offset); \ ++ class##_AddRef(this); \ ++ dshowdebug("\tfound %d with offset %d\n", i, ifaces[i].offset); \ ++ *ppvObject = (void *) obj; \ ++ return S_OK; \ ++ } \ ++ } \ ++ dshowdebug("\tE_NOINTERFACE\n"); \ ++ *ppvObject = NULL; \ ++ return E_NOINTERFACE; \ ++} ++#define DECLARE_ADDREF(class) \ ++unsigned long WINAPI \ ++class##_AddRef(class *this) \ ++{ \ ++ dshowdebug(AV_STRINGIFY(class)"_AddRef(%p)\t%ld\n", this, this->ref+1); \ ++ return InterlockedIncrement(&this->ref); \ ++} ++#define DECLARE_RELEASE(class) \ ++unsigned long WINAPI \ ++class##_Release(class *this) \ ++{ \ ++ long ref = InterlockedDecrement(&this->ref); \ ++ dshowdebug(AV_STRINGIFY(class)"_Release(%p)\t%ld\n", this, ref); \ ++ if (!ref) \ ++ class##_Destroy(this); \ ++ return ref; \ ++} ++ ++#define DECLARE_DESTROY(class, func) \ ++void class##_Destroy(class *this) \ ++{ \ ++ dshowdebug(AV_STRINGIFY(class)"_Destroy(%p)\n", this); \ ++ func(this); \ ++ if (this) { \ ++ if (this->vtbl) \ ++ CoTaskMemFree(this->vtbl); \ ++ CoTaskMemFree(this); \ ++ } \ ++} ++#define DECLARE_CREATE(class, setup, ...) \ ++class *class##_Create(__VA_ARGS__) \ ++{ \ ++ class *this = CoTaskMemAlloc(sizeof(class)); \ ++ void *vtbl = CoTaskMemAlloc(sizeof(*this->vtbl)); \ ++ dshowdebug(AV_STRINGIFY(class)"_Create(%p)\n", this); \ ++ if (!this || !vtbl) \ ++ goto fail; \ ++ ZeroMemory(this, sizeof(class)); \ ++ ZeroMemory(vtbl, sizeof(*this->vtbl)); \ ++ this->ref = 1; \ ++ this->vtbl = vtbl; \ ++ if (!setup) \ ++ goto fail; \ ++ dshowdebug("created "AV_STRINGIFY(class)" %p\n", this); \ ++ return this; \ ++fail: \ ++ class##_Destroy(this); \ ++ dshowdebug("could not create "AV_STRINGIFY(class)"\n"); \ ++ return NULL; \ ++} ++ ++#define SETVTBL(vtbl, class, fn) \ ++ do { (vtbl)->fn = (void *) class##_##fn; } while(0) ++ ++/***************************************************************************** ++ * Forward Declarations ++ ****************************************************************************/ ++typedef struct libAVPin libAVPin; ++typedef struct libAVMemInputPin libAVMemInputPin; ++typedef struct libAVEnumPins libAVEnumPins; ++typedef struct libAVEnumMediaTypes libAVEnumMediaTypes; ++typedef struct libAVFilter libAVFilter; ++ ++/***************************************************************************** ++ * libAVPin ++ ****************************************************************************/ ++struct libAVPin { ++ IPinVtbl *vtbl; ++ long ref; ++ libAVFilter *filter; ++ IPin *connectedto; ++ AM_MEDIA_TYPE type; ++ IMemInputPinVtbl *imemvtbl; ++}; ++ ++long WINAPI libAVPin_QueryInterface (libAVPin *, const GUID *, void **); ++unsigned long WINAPI libAVPin_AddRef (libAVPin *); ++unsigned long WINAPI libAVPin_Release (libAVPin *); ++long WINAPI libAVPin_Connect (libAVPin *, IPin *, const AM_MEDIA_TYPE *); ++long WINAPI libAVPin_ReceiveConnection (libAVPin *, IPin *, const AM_MEDIA_TYPE *); ++long WINAPI libAVPin_Disconnect (libAVPin *); ++long WINAPI libAVPin_ConnectedTo (libAVPin *, IPin **); ++long WINAPI libAVPin_ConnectionMediaType (libAVPin *, AM_MEDIA_TYPE *); ++long WINAPI libAVPin_QueryPinInfo (libAVPin *, PIN_INFO *); ++long WINAPI libAVPin_QueryDirection (libAVPin *, PIN_DIRECTION *); ++long WINAPI libAVPin_QueryId (libAVPin *, wchar_t **); ++long WINAPI libAVPin_QueryAccept (libAVPin *, const AM_MEDIA_TYPE *); ++long WINAPI libAVPin_EnumMediaTypes (libAVPin *, IEnumMediaTypes **); ++long WINAPI libAVPin_QueryInternalConnections(libAVPin *, IPin **, unsigned long *); ++long WINAPI libAVPin_EndOfStream (libAVPin *); ++long WINAPI libAVPin_BeginFlush (libAVPin *); ++long WINAPI libAVPin_EndFlush (libAVPin *); ++long WINAPI libAVPin_NewSegment (libAVPin *, REFERENCE_TIME, REFERENCE_TIME, double); ++ ++long WINAPI libAVMemInputPin_QueryInterface (libAVMemInputPin *, const GUID *, void **); ++unsigned long WINAPI libAVMemInputPin_AddRef (libAVMemInputPin *); ++unsigned long WINAPI libAVMemInputPin_Release (libAVMemInputPin *); ++long WINAPI libAVMemInputPin_GetAllocator (libAVMemInputPin *, IMemAllocator **); ++long WINAPI libAVMemInputPin_NotifyAllocator (libAVMemInputPin *, IMemAllocator *, WINBOOL); ++long WINAPI libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *, ALLOCATOR_PROPERTIES *); ++long WINAPI libAVMemInputPin_Receive (libAVMemInputPin *, IMediaSample *); ++long WINAPI libAVMemInputPin_ReceiveMultiple (libAVMemInputPin *, IMediaSample **, long, long *); ++long WINAPI libAVMemInputPin_ReceiveCanBlock (libAVMemInputPin *); ++ ++void libAVPin_Destroy(libAVPin *); ++libAVPin *libAVPin_Create (libAVFilter *filter); ++ ++void libAVMemInputPin_Destroy(libAVMemInputPin *); ++ ++/***************************************************************************** ++ * libAVEnumPins ++ ****************************************************************************/ ++struct libAVEnumPins { ++ IEnumPinsVtbl *vtbl; ++ long ref; ++ int pos; ++ libAVPin *pin; ++ libAVFilter *filter; ++}; ++ ++long WINAPI libAVEnumPins_QueryInterface(libAVEnumPins *, const GUID *, void **); ++unsigned long WINAPI libAVEnumPins_AddRef (libAVEnumPins *); ++unsigned long WINAPI libAVEnumPins_Release (libAVEnumPins *); ++long WINAPI libAVEnumPins_Next (libAVEnumPins *, unsigned long, IPin **, unsigned long *); ++long WINAPI libAVEnumPins_Skip (libAVEnumPins *, unsigned long); ++long WINAPI libAVEnumPins_Reset (libAVEnumPins *); ++long WINAPI libAVEnumPins_Clone (libAVEnumPins *, libAVEnumPins **); ++ ++void libAVEnumPins_Destroy(libAVEnumPins *); ++libAVEnumPins *libAVEnumPins_Create (libAVPin *pin, libAVFilter *filter); ++ ++/***************************************************************************** ++ * libAVEnumMediaTypes ++ ****************************************************************************/ ++struct libAVEnumMediaTypes { ++ IEnumPinsVtbl *vtbl; ++ long ref; ++ int pos; ++ AM_MEDIA_TYPE type; ++}; ++ ++long WINAPI libAVEnumMediaTypes_QueryInterface(libAVEnumMediaTypes *, const GUID *, void **); ++unsigned long WINAPI libAVEnumMediaTypes_AddRef (libAVEnumMediaTypes *); ++unsigned long WINAPI libAVEnumMediaTypes_Release (libAVEnumMediaTypes *); ++long WINAPI libAVEnumMediaTypes_Next (libAVEnumMediaTypes *, unsigned long, AM_MEDIA_TYPE **, unsigned long *); ++long WINAPI libAVEnumMediaTypes_Skip (libAVEnumMediaTypes *, unsigned long); ++long WINAPI libAVEnumMediaTypes_Reset (libAVEnumMediaTypes *); ++long WINAPI libAVEnumMediaTypes_Clone (libAVEnumMediaTypes *, libAVEnumMediaTypes **); ++ ++void libAVEnumMediaTypes_Destroy(libAVEnumMediaTypes *); ++libAVEnumMediaTypes *libAVEnumMediaTypes_Create(const AM_MEDIA_TYPE *type); ++ ++/***************************************************************************** ++ * libAVFilter ++ ****************************************************************************/ ++struct libAVFilter { ++ IBaseFilterVtbl *vtbl; ++ long ref; ++ const wchar_t *name; ++ libAVPin *pin; ++ FILTER_INFO info; ++ FILTER_STATE state; ++ IReferenceClock *clock; ++ enum dshowDeviceType type; ++ void *priv_data; ++ int stream_index; ++ int64_t start_time; ++ void (*callback)(void *priv_data, int index, uint8_t *buf, int buf_size, int64_t time); ++}; ++ ++long WINAPI libAVFilter_QueryInterface (libAVFilter *, const GUID *, void **); ++unsigned long WINAPI libAVFilter_AddRef (libAVFilter *); ++unsigned long WINAPI libAVFilter_Release (libAVFilter *); ++long WINAPI libAVFilter_GetClassID (libAVFilter *, CLSID *); ++long WINAPI libAVFilter_Stop (libAVFilter *); ++long WINAPI libAVFilter_Pause (libAVFilter *); ++long WINAPI libAVFilter_Run (libAVFilter *, REFERENCE_TIME); ++long WINAPI libAVFilter_GetState (libAVFilter *, DWORD, FILTER_STATE *); ++long WINAPI libAVFilter_SetSyncSource (libAVFilter *, IReferenceClock *); ++long WINAPI libAVFilter_GetSyncSource (libAVFilter *, IReferenceClock **); ++long WINAPI libAVFilter_EnumPins (libAVFilter *, IEnumPins **); ++long WINAPI libAVFilter_FindPin (libAVFilter *, const wchar_t *, IPin **); ++long WINAPI libAVFilter_QueryFilterInfo(libAVFilter *, FILTER_INFO *); ++long WINAPI libAVFilter_JoinFilterGraph(libAVFilter *, IFilterGraph *, const wchar_t *); ++long WINAPI libAVFilter_QueryVendorInfo(libAVFilter *, wchar_t **); ++ ++void libAVFilter_Destroy(libAVFilter *); ++libAVFilter *libAVFilter_Create (void *, void *, enum dshowDeviceType); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_pin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_pin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dshow_pin.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dshow_pin.c 2012-05-14 14:08:54.644346221 +0200 +@@ -0,0 +1,362 @@ ++/* ++ * DirectShow capture interface ++ * Copyright (c) 2010 Ramiro Polla ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dshow.h" ++ ++#include ++#define imemoffset offsetof(libAVPin, imemvtbl) ++ ++DECLARE_QUERYINTERFACE(libAVPin, ++ { {&IID_IUnknown,0}, {&IID_IPin,0}, {&IID_IMemInputPin,imemoffset} }) ++DECLARE_ADDREF(libAVPin) ++DECLARE_RELEASE(libAVPin) ++ ++long WINAPI ++libAVPin_Connect(libAVPin *this, IPin *pin, const AM_MEDIA_TYPE *type) ++{ ++ dshowdebug("libAVPin_Connect(%p, %p, %p)\n", this, pin, type); ++ /* Input pins receive connections. */ ++ return S_FALSE; ++} ++long WINAPI ++libAVPin_ReceiveConnection(libAVPin *this, IPin *pin, ++ const AM_MEDIA_TYPE *type) ++{ ++ enum dshowDeviceType devtype = this->filter->type; ++ dshowdebug("libAVPin_ReceiveConnection(%p)\n", this); ++ ++ if (!pin) ++ return E_POINTER; ++ if (this->connectedto) ++ return VFW_E_ALREADY_CONNECTED; ++ ++ ff_print_AM_MEDIA_TYPE(type); ++ if (devtype == VideoDevice) { ++ if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Video)) ++ return VFW_E_TYPE_NOT_ACCEPTED; ++ } else { ++ if (!IsEqualGUID(&type->majortype, &MEDIATYPE_Audio)) ++ return VFW_E_TYPE_NOT_ACCEPTED; ++ } ++ ++ IPin_AddRef(pin); ++ this->connectedto = pin; ++ ++ ff_copy_dshow_media_type(&this->type, type); ++ ++ return S_OK; ++} ++long WINAPI ++libAVPin_Disconnect(libAVPin *this) ++{ ++ dshowdebug("libAVPin_Disconnect(%p)\n", this); ++ ++ if (this->filter->state != State_Stopped) ++ return VFW_E_NOT_STOPPED; ++ if (!this->connectedto) ++ return S_FALSE; ++ IPin_Release(this->connectedto); ++ this->connectedto = NULL; ++ ++ return S_OK; ++} ++long WINAPI ++libAVPin_ConnectedTo(libAVPin *this, IPin **pin) ++{ ++ dshowdebug("libAVPin_ConnectedTo(%p)\n", this); ++ ++ if (!pin) ++ return E_POINTER; ++ if (!this->connectedto) ++ return VFW_E_NOT_CONNECTED; ++ IPin_AddRef(this->connectedto); ++ *pin = this->connectedto; ++ ++ return S_OK; ++} ++long WINAPI ++libAVPin_ConnectionMediaType(libAVPin *this, AM_MEDIA_TYPE *type) ++{ ++ dshowdebug("libAVPin_ConnectionMediaType(%p)\n", this); ++ ++ if (!type) ++ return E_POINTER; ++ if (!this->connectedto) ++ return VFW_E_NOT_CONNECTED; ++ ++ return ff_copy_dshow_media_type(type, &this->type); ++} ++long WINAPI ++libAVPin_QueryPinInfo(libAVPin *this, PIN_INFO *info) ++{ ++ dshowdebug("libAVPin_QueryPinInfo(%p)\n", this); ++ ++ if (!info) ++ return E_POINTER; ++ ++ if (this->filter) ++ libAVFilter_AddRef(this->filter); ++ ++ info->pFilter = (IBaseFilter *) this->filter; ++ info->dir = PINDIR_INPUT; ++ wcscpy(info->achName, L"Capture"); ++ ++ return S_OK; ++} ++long WINAPI ++libAVPin_QueryDirection(libAVPin *this, PIN_DIRECTION *dir) ++{ ++ dshowdebug("libAVPin_QueryDirection(%p)\n", this); ++ if (!dir) ++ return E_POINTER; ++ *dir = PINDIR_INPUT; ++ return S_OK; ++} ++long WINAPI ++libAVPin_QueryId(libAVPin *this, wchar_t **id) ++{ ++ dshowdebug("libAVPin_QueryId(%p)\n", this); ++ ++ if (!id) ++ return E_POINTER; ++ ++ *id = wcsdup(L"libAV Pin"); ++ ++ return S_OK; ++} ++long WINAPI ++libAVPin_QueryAccept(libAVPin *this, const AM_MEDIA_TYPE *type) ++{ ++ dshowdebug("libAVPin_QueryAccept(%p)\n", this); ++ return S_FALSE; ++} ++long WINAPI ++libAVPin_EnumMediaTypes(libAVPin *this, IEnumMediaTypes **enumtypes) ++{ ++ const AM_MEDIA_TYPE *type = NULL; ++ libAVEnumMediaTypes *new; ++ dshowdebug("libAVPin_EnumMediaTypes(%p)\n", this); ++ ++ if (!enumtypes) ++ return E_POINTER; ++ new = libAVEnumMediaTypes_Create(type); ++ if (!new) ++ return E_OUTOFMEMORY; ++ ++ *enumtypes = (IEnumMediaTypes *) new; ++ return S_OK; ++} ++long WINAPI ++libAVPin_QueryInternalConnections(libAVPin *this, IPin **pin, ++ unsigned long *npin) ++{ ++ dshowdebug("libAVPin_QueryInternalConnections(%p)\n", this); ++ return E_NOTIMPL; ++} ++long WINAPI ++libAVPin_EndOfStream(libAVPin *this) ++{ ++ dshowdebug("libAVPin_EndOfStream(%p)\n", this); ++ /* I don't care. */ ++ return S_OK; ++} ++long WINAPI ++libAVPin_BeginFlush(libAVPin *this) ++{ ++ dshowdebug("libAVPin_BeginFlush(%p)\n", this); ++ /* I don't care. */ ++ return S_OK; ++} ++long WINAPI ++libAVPin_EndFlush(libAVPin *this) ++{ ++ dshowdebug("libAVPin_EndFlush(%p)\n", this); ++ /* I don't care. */ ++ return S_OK; ++} ++long WINAPI ++libAVPin_NewSegment(libAVPin *this, REFERENCE_TIME start, REFERENCE_TIME stop, ++ double rate) ++{ ++ dshowdebug("libAVPin_NewSegment(%p)\n", this); ++ /* I don't care. */ ++ return S_OK; ++} ++ ++static int ++libAVPin_Setup(libAVPin *this, libAVFilter *filter) ++{ ++ IPinVtbl *vtbl = this->vtbl; ++ IMemInputPinVtbl *imemvtbl; ++ ++ if (!filter) ++ return 0; ++ ++ imemvtbl = av_malloc(sizeof(IMemInputPinVtbl)); ++ if (!imemvtbl) ++ return 0; ++ ++ SETVTBL(imemvtbl, libAVMemInputPin, QueryInterface); ++ SETVTBL(imemvtbl, libAVMemInputPin, AddRef); ++ SETVTBL(imemvtbl, libAVMemInputPin, Release); ++ SETVTBL(imemvtbl, libAVMemInputPin, GetAllocator); ++ SETVTBL(imemvtbl, libAVMemInputPin, NotifyAllocator); ++ SETVTBL(imemvtbl, libAVMemInputPin, GetAllocatorRequirements); ++ SETVTBL(imemvtbl, libAVMemInputPin, Receive); ++ SETVTBL(imemvtbl, libAVMemInputPin, ReceiveMultiple); ++ SETVTBL(imemvtbl, libAVMemInputPin, ReceiveCanBlock); ++ ++ this->imemvtbl = imemvtbl; ++ ++ SETVTBL(vtbl, libAVPin, QueryInterface); ++ SETVTBL(vtbl, libAVPin, AddRef); ++ SETVTBL(vtbl, libAVPin, Release); ++ SETVTBL(vtbl, libAVPin, Connect); ++ SETVTBL(vtbl, libAVPin, ReceiveConnection); ++ SETVTBL(vtbl, libAVPin, Disconnect); ++ SETVTBL(vtbl, libAVPin, ConnectedTo); ++ SETVTBL(vtbl, libAVPin, ConnectionMediaType); ++ SETVTBL(vtbl, libAVPin, QueryPinInfo); ++ SETVTBL(vtbl, libAVPin, QueryDirection); ++ SETVTBL(vtbl, libAVPin, QueryId); ++ SETVTBL(vtbl, libAVPin, QueryAccept); ++ SETVTBL(vtbl, libAVPin, EnumMediaTypes); ++ SETVTBL(vtbl, libAVPin, QueryInternalConnections); ++ SETVTBL(vtbl, libAVPin, EndOfStream); ++ SETVTBL(vtbl, libAVPin, BeginFlush); ++ SETVTBL(vtbl, libAVPin, EndFlush); ++ SETVTBL(vtbl, libAVPin, NewSegment); ++ ++ this->filter = filter; ++ ++ return 1; ++} ++DECLARE_CREATE(libAVPin, libAVPin_Setup(this, filter), libAVFilter *filter) ++DECLARE_DESTROY(libAVPin, nothing) ++ ++/***************************************************************************** ++ * libAVMemInputPin ++ ****************************************************************************/ ++long WINAPI ++libAVMemInputPin_QueryInterface(libAVMemInputPin *this, const GUID *riid, ++ void **ppvObject) ++{ ++ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); ++ dshowdebug("libAVMemInputPin_QueryInterface(%p)\n", this); ++ return libAVPin_QueryInterface(pin, riid, ppvObject); ++} ++unsigned long WINAPI ++libAVMemInputPin_AddRef(libAVMemInputPin *this) ++{ ++ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); ++ dshowdebug("libAVMemInputPin_AddRef(%p)\n", this); ++ return libAVPin_AddRef(pin); ++} ++unsigned long WINAPI ++libAVMemInputPin_Release(libAVMemInputPin *this) ++{ ++ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); ++ dshowdebug("libAVMemInputPin_Release(%p)\n", this); ++ return libAVPin_Release(pin); ++} ++long WINAPI ++libAVMemInputPin_GetAllocator(libAVMemInputPin *this, IMemAllocator **alloc) ++{ ++ dshowdebug("libAVMemInputPin_GetAllocator(%p)\n", this); ++ return VFW_E_NO_ALLOCATOR; ++} ++long WINAPI ++libAVMemInputPin_NotifyAllocator(libAVMemInputPin *this, IMemAllocator *alloc, ++ WINBOOL rdwr) ++{ ++ dshowdebug("libAVMemInputPin_NotifyAllocator(%p)\n", this); ++ return S_OK; ++} ++long WINAPI ++libAVMemInputPin_GetAllocatorRequirements(libAVMemInputPin *this, ++ ALLOCATOR_PROPERTIES *props) ++{ ++ dshowdebug("libAVMemInputPin_GetAllocatorRequirements(%p)\n", this); ++ return E_NOTIMPL; ++} ++long WINAPI ++libAVMemInputPin_Receive(libAVMemInputPin *this, IMediaSample *sample) ++{ ++ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); ++ enum dshowDeviceType devtype = pin->filter->type; ++ void *priv_data; ++ uint8_t *buf; ++ int buf_size; ++ int index; ++ int64_t curtime; ++ ++ dshowdebug("libAVMemInputPin_Receive(%p)\n", this); ++ ++ if (!sample) ++ return E_POINTER; ++ ++ if (devtype == VideoDevice) { ++ /* PTS from video devices is unreliable. */ ++ IReferenceClock *clock = pin->filter->clock; ++ IReferenceClock_GetTime(clock, &curtime); ++ } else { ++ int64_t dummy; ++ IMediaSample_GetTime(sample, &curtime, &dummy); ++ curtime += pin->filter->start_time; ++ } ++ ++ buf_size = IMediaSample_GetActualDataLength(sample); ++ IMediaSample_GetPointer(sample, &buf); ++ priv_data = pin->filter->priv_data; ++ index = pin->filter->stream_index; ++ ++ pin->filter->callback(priv_data, index, buf, buf_size, curtime); ++ ++ return S_OK; ++} ++long WINAPI ++libAVMemInputPin_ReceiveMultiple(libAVMemInputPin *this, ++ IMediaSample **samples, long n, long *nproc) ++{ ++ int i; ++ dshowdebug("libAVMemInputPin_ReceiveMultiple(%p)\n", this); ++ ++ for (i = 0; i < n; i++) ++ libAVMemInputPin_Receive(this, samples[i]); ++ ++ *nproc = n; ++ return S_OK; ++} ++long WINAPI ++libAVMemInputPin_ReceiveCanBlock(libAVMemInputPin *this) ++{ ++ dshowdebug("libAVMemInputPin_ReceiveCanBlock(%p)\n", this); ++ /* I swear I will not block. */ ++ return S_FALSE; ++} ++ ++void ++libAVMemInputPin_Destroy(libAVMemInputPin *this) ++{ ++ libAVPin *pin = (libAVPin *) ((uint8_t *) this - imemoffset); ++ dshowdebug("libAVMemInputPin_Destroy(%p)\n", this); ++ return libAVPin_Destroy(pin); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dv1394.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dv1394.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dv1394.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dv1394.c 2012-05-14 14:08:54.645346241 +0200 +@@ -28,16 +28,15 @@ + #include + #include + #include +-#include +- +-#include "libavformat/avformat.h" +- +-#undef DV1394_DEBUG + ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "avdevice.h" + #include "libavformat/dv.h" + #include "dv1394.h" + + struct dv1394_data { ++ AVClass *class; + int fd; + int channel; + int format; +@@ -86,20 +85,10 @@ + { + struct dv1394_data *dv = context->priv_data; + +- dv->dv_demux = dv_init_demux(context); ++ dv->dv_demux = avpriv_dv_init_demux(context); + if (!dv->dv_demux) + goto failed; + +- if (ap->standard && !strcasecmp(ap->standard, "pal")) +- dv->format = DV1394_PAL; +- else +- dv->format = DV1394_NTSC; +- +- if (ap->channel) +- dv->channel = ap->channel; +- else +- dv->channel = DV1394_DEFAULT_CHANNEL; +- + /* Open and initialize DV1394 device */ + dv->fd = open(context->filename, O_RDONLY); + if (dv->fd < 0) { +@@ -134,7 +123,7 @@ + struct dv1394_data *dv = context->priv_data; + int size; + +- size = dv_get_packet(dv->dv_demux, pkt); ++ size = avpriv_dv_get_packet(dv->dv_demux, pkt); + if (size > 0) + return size; + +@@ -172,15 +161,13 @@ + av_log(context, AV_LOG_ERROR, "Failed to get status: %s\n", strerror(errno)); + return AVERROR(EIO); + } +-#ifdef DV1394_DEBUG +- av_log(context, AV_LOG_DEBUG, "DV1394: status\n" ++ av_dlog(context, "DV1394: status\n" + "\tactive_frame\t%d\n" + "\tfirst_clear_frame\t%d\n" + "\tn_clear_frames\t%d\n" + "\tdropped_frames\t%d\n", + s.active_frame, s.first_clear_frame, + s.n_clear_frames, s.dropped_frames); +-#endif + + dv->avail = s.n_clear_frames; + dv->index = s.first_clear_frame; +@@ -195,14 +182,12 @@ + } + } + +-#ifdef DV1394_DEBUG +- av_log(context, AV_LOG_DEBUG, "index %d, avail %d, done %d\n", dv->index, dv->avail, ++ av_dlog(context, "index %d, avail %d, done %d\n", dv->index, dv->avail, + dv->done); +-#endif + +- size = dv_produce_packet(dv->dv_demux, pkt, ++ size = avpriv_dv_produce_packet(dv->dv_demux, pkt, + dv->ring + (dv->index * DV1394_PAL_FRAME_SIZE), +- DV1394_PAL_FRAME_SIZE); ++ DV1394_PAL_FRAME_SIZE, -1); + dv->index = (dv->index + 1) % DV1394_RING_FRAMES; + dv->done++; dv->avail--; + +@@ -227,6 +212,21 @@ + return 0; + } + ++static const AVOption options[] = { ++ { "standard", "", offsetof(struct dv1394_data, format), AV_OPT_TYPE_INT, {.dbl = DV1394_NTSC}, DV1394_PAL, DV1394_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = DV1394_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = DV1394_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "channel", "", offsetof(struct dv1394_data, channel), AV_OPT_TYPE_INT, {.dbl = DV1394_DEFAULT_CHANNEL}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass dv1394_class = { ++ .class_name = "DV1394 indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_dv1394_demuxer = { + .name = "dv1394", + .long_name = NULL_IF_CONFIG_SMALL("DV1394 A/V grab"), +@@ -234,5 +234,6 @@ + .read_header = dv1394_read_header, + .read_packet = dv1394_read_packet, + .read_close = dv1394_close, +- .flags = AVFMT_NOFILE ++ .flags = AVFMT_NOFILE, ++ .priv_class = &dv1394_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dv1394.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dv1394.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/dv1394.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/dv1394.h 2012-05-14 14:08:54.649346321 +0200 +@@ -175,7 +175,8 @@ + if(status.dropped_frames > 0) { + reset_dv1394(); + } else { +- for(int i = 0; i < status.n_clear_frames; i++) { ++ int i; ++ for(i = 0; i < status.n_clear_frames; i++) { + copy_DV_frame(); + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/fbdev.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/fbdev.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/fbdev.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/fbdev.c 2012-05-14 14:08:54.650346341 +0200 +@@ -0,0 +1,271 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * Copyright (c) 2009 Giliard B. de Freitas ++ * Copyright (C) 2002 Gunnar Monell ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Linux framebuffer input device, ++ * inspired by code from fbgrab.c by Gunnar Monell. ++ * @see http://linux-fbdev.sourceforge.net/ ++ */ ++ ++/* #define DEBUG */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "libavutil/log.h" ++#include "libavutil/mem.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "avdevice.h" ++#include "libavformat/internal.h" ++ ++struct rgb_pixfmt_map_entry { ++ int bits_per_pixel; ++ int red_offset, green_offset, blue_offset, alpha_offset; ++ enum PixelFormat pixfmt; ++}; ++ ++static const struct rgb_pixfmt_map_entry rgb_pixfmt_map[] = { ++ // bpp, red_offset, green_offset, blue_offset, alpha_offset, pixfmt ++ { 32, 0, 8, 16, 24, PIX_FMT_RGBA }, ++ { 32, 16, 8, 0, 24, PIX_FMT_BGRA }, ++ { 32, 8, 16, 24, 0, PIX_FMT_ARGB }, ++ { 32, 3, 2, 8, 0, PIX_FMT_ABGR }, ++ { 24, 0, 8, 16, 0, PIX_FMT_RGB24 }, ++ { 24, 16, 8, 0, 0, PIX_FMT_BGR24 }, ++}; ++ ++static enum PixelFormat get_pixfmt_from_fb_varinfo(struct fb_var_screeninfo *varinfo) ++{ ++ int i; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(rgb_pixfmt_map); i++) { ++ const struct rgb_pixfmt_map_entry *entry = &rgb_pixfmt_map[i]; ++ if (entry->bits_per_pixel == varinfo->bits_per_pixel && ++ entry->red_offset == varinfo->red.offset && ++ entry->green_offset == varinfo->green.offset && ++ entry->blue_offset == varinfo->blue.offset) ++ return entry->pixfmt; ++ } ++ ++ return PIX_FMT_NONE; ++} ++ ++typedef struct { ++ AVClass *class; ///< class for private options ++ int frame_size; ///< size in bytes of a grabbed frame ++ AVRational framerate_q; ///< framerate ++ char *framerate; ///< framerate string set by a private option ++ int64_t time_frame; ///< time for the next frame to output (in 1/1000000 units) ++ ++ int fd; ///< framebuffer device file descriptor ++ int width, height; ///< assumed frame resolution ++ int frame_linesize; ///< linesize of the output frame, it is assumed to be constant ++ int bytes_per_pixel; ++ ++ struct fb_var_screeninfo varinfo; ///< variable info; ++ struct fb_fix_screeninfo fixinfo; ///< fixed info; ++ ++ uint8_t *data; ///< framebuffer data ++} FBDevContext; ++ ++av_cold static int fbdev_read_header(AVFormatContext *avctx, ++ AVFormatParameters *ap) ++{ ++ FBDevContext *fbdev = avctx->priv_data; ++ AVStream *st = NULL; ++ enum PixelFormat pix_fmt; ++ int ret, flags = O_RDONLY; ++ ++ ret = av_parse_video_rate(&fbdev->framerate_q, fbdev->framerate); ++ if (ret < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", fbdev->framerate); ++ return ret; ++ } ++ ++ if (!(st = avformat_new_stream(avctx, NULL))) ++ return AVERROR(ENOMEM); ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in microseconds */ ++ ++ /* NONBLOCK is ignored by the fbdev driver, only set for consistency */ ++ if (avctx->flags & AVFMT_FLAG_NONBLOCK) ++ flags |= O_NONBLOCK; ++ ++ if ((fbdev->fd = open(avctx->filename, flags)) == -1) { ++ ret = AVERROR(errno); ++ av_log(avctx, AV_LOG_ERROR, ++ "Could not open framebuffer device '%s': %s\n", ++ avctx->filename, strerror(ret)); ++ return ret; ++ } ++ ++ if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) { ++ ret = AVERROR(errno); ++ av_log(avctx, AV_LOG_ERROR, ++ "FBIOGET_VSCREENINFO: %s\n", strerror(errno)); ++ goto fail; ++ } ++ ++ if (ioctl(fbdev->fd, FBIOGET_FSCREENINFO, &fbdev->fixinfo) < 0) { ++ ret = AVERROR(errno); ++ av_log(avctx, AV_LOG_ERROR, ++ "FBIOGET_FSCREENINFO: %s\n", strerror(errno)); ++ goto fail; ++ } ++ ++ pix_fmt = get_pixfmt_from_fb_varinfo(&fbdev->varinfo); ++ if (pix_fmt == PIX_FMT_NONE) { ++ ret = AVERROR(EINVAL); ++ av_log(avctx, AV_LOG_ERROR, ++ "Framebuffer pixel format not supported.\n"); ++ goto fail; ++ } ++ ++ fbdev->width = fbdev->varinfo.xres; ++ fbdev->height = fbdev->varinfo.yres; ++ fbdev->bytes_per_pixel = (fbdev->varinfo.bits_per_pixel + 7) >> 3; ++ fbdev->frame_linesize = fbdev->width * fbdev->bytes_per_pixel; ++ fbdev->frame_size = fbdev->frame_linesize * fbdev->height; ++ fbdev->time_frame = AV_NOPTS_VALUE; ++ fbdev->data = mmap(NULL, fbdev->fixinfo.smem_len, PROT_READ, MAP_SHARED, fbdev->fd, 0); ++ if (fbdev->data == MAP_FAILED) { ++ ret = AVERROR(errno); ++ av_log(avctx, AV_LOG_ERROR, "Error in mmap(): %s\n", strerror(errno)); ++ goto fail; ++ } ++ ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_RAWVIDEO; ++ st->codec->width = fbdev->width; ++ st->codec->height = fbdev->height; ++ st->codec->pix_fmt = pix_fmt; ++ st->codec->time_base = (AVRational){fbdev->framerate_q.den, fbdev->framerate_q.num}; ++ st->codec->bit_rate = ++ fbdev->width * fbdev->height * fbdev->bytes_per_pixel * av_q2d(fbdev->framerate_q) * 8; ++ ++ av_log(avctx, AV_LOG_INFO, ++ "w:%d h:%d bpp:%d pixfmt:%s fps:%d/%d bit_rate:%d\n", ++ fbdev->width, fbdev->height, fbdev->varinfo.bits_per_pixel, ++ av_pix_fmt_descriptors[pix_fmt].name, ++ fbdev->framerate_q.num, fbdev->framerate_q.den, ++ st->codec->bit_rate); ++ return 0; ++ ++fail: ++ close(fbdev->fd); ++ return ret; ++} ++ ++static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt) ++{ ++ FBDevContext *fbdev = avctx->priv_data; ++ int64_t curtime, delay; ++ struct timespec ts; ++ int i, ret; ++ uint8_t *pin, *pout; ++ ++ if (fbdev->time_frame == AV_NOPTS_VALUE) ++ fbdev->time_frame = av_gettime(); ++ ++ /* wait based on the frame rate */ ++ while (1) { ++ curtime = av_gettime(); ++ delay = fbdev->time_frame - curtime; ++ av_dlog(avctx, ++ "time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n", ++ fbdev->time_frame, curtime, delay); ++ if (delay <= 0) { ++ fbdev->time_frame += INT64_C(1000000) / av_q2d(fbdev->framerate_q); ++ break; ++ } ++ if (avctx->flags & AVFMT_FLAG_NONBLOCK) ++ return AVERROR(EAGAIN); ++ ts.tv_sec = delay / 1000000; ++ ts.tv_nsec = (delay % 1000000) * 1000; ++ while (nanosleep(&ts, &ts) < 0 && errno == EINTR); ++ } ++ ++ if ((ret = av_new_packet(pkt, fbdev->frame_size)) < 0) ++ return ret; ++ ++ /* refresh fbdev->varinfo, visible data position may change at each call */ ++ if (ioctl(fbdev->fd, FBIOGET_VSCREENINFO, &fbdev->varinfo) < 0) ++ av_log(avctx, AV_LOG_WARNING, ++ "Error refreshing variable info: %s\n", strerror(errno)); ++ ++ pkt->pts = curtime; ++ ++ /* compute visible data offset */ ++ pin = fbdev->data + fbdev->bytes_per_pixel * fbdev->varinfo.xoffset + ++ fbdev->varinfo.yoffset * fbdev->fixinfo.line_length; ++ pout = pkt->data; ++ ++ for (i = 0; i < fbdev->height; i++) { ++ memcpy(pout, pin, fbdev->frame_linesize); ++ pin += fbdev->fixinfo.line_length; ++ pout += fbdev->frame_linesize; ++ } ++ ++ return fbdev->frame_size; ++} ++ ++av_cold static int fbdev_read_close(AVFormatContext *avctx) ++{ ++ FBDevContext *fbdev = avctx->priv_data; ++ ++ munmap(fbdev->data, fbdev->frame_size); ++ close(fbdev->fd); ++ ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(FBDevContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "framerate","", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass fbdev_class = { ++ .class_name = "fbdev indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_fbdev_demuxer = { ++ .name = "fbdev", ++ .long_name = NULL_IF_CONFIG_SMALL("Linux framebuffer"), ++ .priv_data_size = sizeof(FBDevContext), ++ .read_header = fbdev_read_header, ++ .read_packet = fbdev_read_packet, ++ .read_close = fbdev_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &fbdev_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/jack_audio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/jack_audio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/jack_audio.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/jack_audio.c 2012-05-14 14:08:54.651346361 +0200 +@@ -26,9 +26,12 @@ + + #include "libavutil/log.h" + #include "libavutil/fifo.h" ++#include "libavutil/opt.h" + #include "libavcodec/avcodec.h" + #include "libavformat/avformat.h" +-#include "libavformat/timefilter.h" ++#include "libavformat/internal.h" ++#include "timefilter.h" ++#include "avdevice.h" + + /** + * Size of the internal FIFO buffers as a number of audio packets +@@ -36,6 +39,7 @@ + #define FIFO_PACKETS_NUM 16 + + typedef struct { ++ AVClass *class; + jack_client_t * client; + int activated; + sem_t packet_count; +@@ -136,7 +140,7 @@ + return 0; + } + +-static int start_jack(AVFormatContext *context, AVFormatParameters *params) ++static int start_jack(AVFormatContext *context) + { + JackData *self = context->priv_data; + jack_status_t status; +@@ -153,7 +157,6 @@ + sem_init(&self->packet_count, 0, 0); + + self->sample_rate = jack_get_sample_rate(self->client); +- self->nports = params->channels; + self->ports = av_malloc(self->nports * sizeof(*self->ports)); + self->buffer_size = jack_get_buffer_size(self->client); + +@@ -225,13 +228,10 @@ + AVStream *stream; + int test; + +- if (params->sample_rate <= 0 || params->channels <= 0) +- return -1; +- +- if ((test = start_jack(context, params))) ++ if ((test = start_jack(context))) + return test; + +- stream = av_new_stream(context, 0); ++ stream = avformat_new_stream(context, NULL); + if (!stream) { + stop_jack(self); + return AVERROR(ENOMEM); +@@ -246,7 +246,7 @@ + stream->codec->sample_rate = self->sample_rate; + stream->codec->channels = self->nports; + +- av_set_pts_info(stream, 64, 1, 1000000); /* 64 bits pts in us */ ++ avpriv_set_pts_info(stream, 64, 1, 1000000); /* 64 bits pts in us */ + return 0; + } + +@@ -272,7 +272,7 @@ + } + } + +- /* Wait for a packet comming back from process_callback(), if one isn't available yet */ ++ /* Wait for a packet coming back from process_callback(), if one isn't available yet */ + timeout.tv_sec = av_gettime() / 1000000 + 2; + if (sem_timedwait(&self->packet_count, &timeout)) { + if (errno == ETIMEDOUT) { +@@ -314,13 +314,26 @@ + return 0; + } + ++#define OFFSET(x) offsetof(JackData, x) ++static const AVOption options[] = { ++ { "channels", "Number of audio channels.", OFFSET(nports), AV_OPT_TYPE_INT, { 2 }, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass jack_indev_class = { ++ .class_name = "JACK indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_jack_demuxer = { +- "jack", +- NULL_IF_CONFIG_SMALL("JACK Audio Connection Kit"), +- sizeof(JackData), +- NULL, +- audio_read_header, +- audio_read_packet, +- audio_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "jack", ++ .long_name = NULL_IF_CONFIG_SMALL("JACK Audio Connection Kit"), ++ .priv_data_size = sizeof(JackData), ++ .read_header = audio_read_header, ++ .read_packet = audio_read_packet, ++ .read_close = audio_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &jack_indev_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/lavfi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/lavfi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/lavfi.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/lavfi.c 2012-05-14 14:08:54.653346402 +0200 +@@ -0,0 +1,360 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libavfilter virtual input device ++ */ ++ ++/* #define DEBUG */ ++ ++#include "float.h" /* DBL_MIN, DBL_MAX */ ++ ++#include "libavutil/log.h" ++#include "libavutil/mem.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "libavfilter/avfilter.h" ++#include "libavfilter/avfiltergraph.h" ++#include "libavfilter/buffersink.h" ++#include "libavformat/internal.h" ++#include "avdevice.h" ++ ++typedef struct { ++ AVClass *class; ///< class for private options ++ char *graph_str; ++ char *dump_graph; ++ AVFilterGraph *graph; ++ AVFilterContext **sinks; ++ int *sink_stream_map; ++ int *stream_sink_map; ++} LavfiContext; ++ ++static int *create_all_formats(int n) ++{ ++ int i, j, *fmts, count = 0; ++ ++ for (i = 0; i < n; i++) ++ if (!(av_pix_fmt_descriptors[i].flags & PIX_FMT_HWACCEL)) ++ count++; ++ ++ if (!(fmts = av_malloc((count+1) * sizeof(int)))) ++ return NULL; ++ for (j = 0, i = 0; i < n; i++) { ++ if (!(av_pix_fmt_descriptors[i].flags & PIX_FMT_HWACCEL)) ++ fmts[j++] = i; ++ } ++ fmts[j] = -1; ++ return fmts; ++} ++ ++av_cold static int lavfi_read_close(AVFormatContext *avctx) ++{ ++ LavfiContext *lavfi = avctx->priv_data; ++ ++ av_freep(&lavfi->sink_stream_map); ++ av_freep(&lavfi->stream_sink_map); ++ av_freep(&lavfi->sinks); ++ avfilter_graph_free(&lavfi->graph); ++ ++ return 0; ++} ++ ++av_cold static int lavfi_read_header(AVFormatContext *avctx, ++ AVFormatParameters *ap) ++{ ++ LavfiContext *lavfi = avctx->priv_data; ++ AVFilterInOut *input_links = NULL, *output_links = NULL, *inout; ++ AVFilter *buffersink, *abuffersink; ++ int *pix_fmts = create_all_formats(PIX_FMT_NB); ++ enum AVMediaType type; ++ int ret = 0, i, n; ++ ++#define FAIL(ERR) { ret = ERR; goto end; } ++ ++ if (!pix_fmts) ++ FAIL(AVERROR(ENOMEM)); ++ ++ avfilter_register_all(); ++ ++ buffersink = avfilter_get_by_name("buffersink"); ++ abuffersink = avfilter_get_by_name("abuffersink"); ++ ++ if (!lavfi->graph_str) ++ lavfi->graph_str = av_strdup(avctx->filename); ++ ++ /* parse the graph, create a stream for each open output */ ++ if (!(lavfi->graph = avfilter_graph_alloc())) ++ FAIL(AVERROR(ENOMEM)); ++ ++ if ((ret = avfilter_graph_parse(lavfi->graph, lavfi->graph_str, ++ &input_links, &output_links, avctx)) < 0) ++ FAIL(ret); ++ ++ if (input_links) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Open inputs in the filtergraph are not acceptable\n"); ++ FAIL(AVERROR(EINVAL)); ++ } ++ ++ /* count the outputs */ ++ for (n = 0, inout = output_links; inout; n++, inout = inout->next); ++ ++ if (!(lavfi->sink_stream_map = av_malloc(sizeof(int) * n))) ++ FAIL(AVERROR(ENOMEM)); ++ if (!(lavfi->stream_sink_map = av_malloc(sizeof(int) * n))) ++ FAIL(AVERROR(ENOMEM)); ++ ++ for (i = 0; i < n; i++) ++ lavfi->stream_sink_map[i] = -1; ++ ++ /* parse the output link names - they need to be of the form out0, out1, ... ++ * create a mapping between them and the streams */ ++ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { ++ int stream_idx; ++ if (!strcmp(inout->name, "out")) ++ stream_idx = 0; ++ else if (sscanf(inout->name, "out%d\n", &stream_idx) != 1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid outpad name '%s'\n", inout->name); ++ FAIL(AVERROR(EINVAL)); ++ } ++ ++ if ((unsigned)stream_idx >= n) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Invalid index was specified in output '%s', " ++ "must be a non-negative value < %d\n", ++ inout->name, n); ++ FAIL(AVERROR(EINVAL)); ++ } ++ ++ /* is an audio or video output? */ ++ type = inout->filter_ctx->output_pads[inout->pad_idx].type; ++ if (type != AVMEDIA_TYPE_VIDEO && type != AVMEDIA_TYPE_AUDIO) { ++ av_log(avctx, AV_LOG_ERROR, ++ "Output '%s' is not a video or audio output, not yet supported\n", inout->name); ++ FAIL(AVERROR(EINVAL)); ++ } ++ ++ if (lavfi->stream_sink_map[stream_idx] != -1) { ++ av_log(avctx, AV_LOG_ERROR, ++ "An output with stream index %d was already specified\n", ++ stream_idx); ++ FAIL(AVERROR(EINVAL)); ++ } ++ lavfi->sink_stream_map[i] = stream_idx; ++ lavfi->stream_sink_map[stream_idx] = i; ++ } ++ ++ /* for each open output create a corresponding stream */ ++ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { ++ AVStream *st; ++ if (!(st = avformat_new_stream(avctx, NULL))) ++ FAIL(AVERROR(ENOMEM)); ++ st->id = i; ++ } ++ ++ /* create a sink for each output and connect them to the graph */ ++ lavfi->sinks = av_malloc(sizeof(AVFilterContext *) * avctx->nb_streams); ++ if (!lavfi->sinks) ++ FAIL(AVERROR(ENOMEM)); ++ ++ for (i = 0, inout = output_links; inout; i++, inout = inout->next) { ++ AVFilterContext *sink; ++ ++ type = inout->filter_ctx->output_pads[inout->pad_idx].type; ++ ++ if (type == AVMEDIA_TYPE_VIDEO && ! buffersink || ++ type == AVMEDIA_TYPE_AUDIO && ! abuffersink) { ++ av_log(avctx, AV_LOG_ERROR, "Missing required buffersink filter, aborting.\n"); ++ FAIL(AVERROR_FILTER_NOT_FOUND); ++ } ++ ++ if (type == AVMEDIA_TYPE_VIDEO) { ++ AVBufferSinkParams *buffersink_params = av_buffersink_params_alloc(); ++ ++#if FF_API_OLD_VSINK_API ++ ret = avfilter_graph_create_filter(&sink, buffersink, ++ inout->name, NULL, ++ pix_fmts, lavfi->graph); ++#else ++ buffersink_params->pixel_fmts = pix_fmts; ++ ret = avfilter_graph_create_filter(&sink, buffersink, ++ inout->name, NULL, ++ buffersink_params, lavfi->graph); ++#endif ++ av_freep(&buffersink_params); ++ ++ if (ret < 0) ++ goto end; ++ } else if (type == AVMEDIA_TYPE_AUDIO) { ++ enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, -1 }; ++ const int packing_fmts[] = { AVFILTER_PACKED, -1 }; ++ const int64_t *chlayouts = avfilter_all_channel_layouts; ++ AVABufferSinkParams *abuffersink_params = av_abuffersink_params_alloc(); ++ abuffersink_params->sample_fmts = sample_fmts; ++ abuffersink_params->packing_fmts = packing_fmts; ++ abuffersink_params->channel_layouts = chlayouts; ++ ++ ret = avfilter_graph_create_filter(&sink, abuffersink, ++ inout->name, NULL, ++ abuffersink_params, lavfi->graph); ++ av_free(abuffersink_params); ++ if (ret < 0) ++ goto end; ++ } ++ ++ lavfi->sinks[i] = sink; ++ if ((ret = avfilter_link(inout->filter_ctx, inout->pad_idx, sink, 0)) < 0) ++ FAIL(ret); ++ } ++ ++ /* configure the graph */ ++ if ((ret = avfilter_graph_config(lavfi->graph, avctx)) < 0) ++ FAIL(ret); ++ ++ if (lavfi->dump_graph) { ++ char *dump = avfilter_graph_dump(lavfi->graph, lavfi->dump_graph); ++ fputs(dump, stderr); ++ fflush(stderr); ++ av_free(dump); ++ } ++ ++ /* fill each stream with the information in the corresponding sink */ ++ for (i = 0; i < avctx->nb_streams; i++) { ++ AVFilterLink *link = lavfi->sinks[lavfi->stream_sink_map[i]]->inputs[0]; ++ AVStream *st = avctx->streams[i]; ++ st->codec->codec_type = link->type; ++ avpriv_set_pts_info(st, 64, link->time_base.num, link->time_base.den); ++ if (link->type == AVMEDIA_TYPE_VIDEO) { ++ st->codec->codec_id = CODEC_ID_RAWVIDEO; ++ st->codec->pix_fmt = link->format; ++ st->codec->time_base = link->time_base; ++ st->codec->width = link->w; ++ st->codec->height = link->h; ++ st ->sample_aspect_ratio = ++ st->codec->sample_aspect_ratio = link->sample_aspect_ratio; ++ } else if (link->type == AVMEDIA_TYPE_AUDIO) { ++ st->codec->codec_id = CODEC_ID_PCM_S16LE; ++ st->codec->channels = av_get_channel_layout_nb_channels(link->channel_layout); ++ st->codec->sample_fmt = link->format; ++ st->codec->sample_rate = link->sample_rate; ++ st->codec->time_base = link->time_base; ++ st->codec->channel_layout = link->channel_layout; ++ } ++ } ++ ++end: ++ av_free(pix_fmts); ++ avfilter_inout_free(&input_links); ++ avfilter_inout_free(&output_links); ++ if (ret < 0) ++ lavfi_read_close(avctx); ++ return ret; ++} ++ ++static int lavfi_read_packet(AVFormatContext *avctx, AVPacket *pkt) ++{ ++ LavfiContext *lavfi = avctx->priv_data; ++ double min_pts = DBL_MAX; ++ int stream_idx, min_pts_sink_idx = 0; ++ AVFilterBufferRef *ref; ++ AVPicture pict; ++ int ret, i; ++ int size = 0; ++ ++ /* iterate through all the graph sinks. Select the sink with the ++ * minimum PTS */ ++ for (i = 0; i < avctx->nb_streams; i++) { ++ AVRational tb = lavfi->sinks[i]->inputs[0]->time_base; ++ double d; ++ int ret = av_buffersink_get_buffer_ref(lavfi->sinks[i], ++ &ref, AV_BUFFERSINK_FLAG_PEEK); ++ if (ret < 0) ++ return ret; ++ d = av_rescale_q(ref->pts, tb, AV_TIME_BASE_Q); ++ av_dlog(avctx, "sink_idx:%d time:%f\n", i, d); ++ ++ if (d < min_pts) { ++ min_pts = d; ++ min_pts_sink_idx = i; ++ } ++ } ++ av_dlog(avctx, "min_pts_sink_idx:%i\n", min_pts_sink_idx); ++ ++ av_buffersink_get_buffer_ref(lavfi->sinks[min_pts_sink_idx], &ref, 0); ++ stream_idx = lavfi->sink_stream_map[min_pts_sink_idx]; ++ ++ if (ref->video) { ++ size = avpicture_get_size(ref->format, ref->video->w, ref->video->h); ++ if ((ret = av_new_packet(pkt, size)) < 0) ++ return ret; ++ ++ memcpy(pict.data, ref->data, 4*sizeof(ref->data[0])); ++ memcpy(pict.linesize, ref->linesize, 4*sizeof(ref->linesize[0])); ++ ++ avpicture_layout(&pict, ref->format, ref->video->w, ++ ref->video->h, pkt->data, size); ++ } else if (ref->audio) { ++ size = ref->audio->nb_samples * ++ av_get_bytes_per_sample(ref->format) * ++ av_get_channel_layout_nb_channels(ref->audio->channel_layout); ++ if ((ret = av_new_packet(pkt, size)) < 0) ++ return ret; ++ memcpy(pkt->data, ref->data[0], size); ++ } ++ ++ pkt->stream_index = stream_idx; ++ pkt->pts = ref->pts; ++ pkt->pos = ref->pos; ++ pkt->size = size; ++ avfilter_unref_buffer(ref); ++ ++ return size; ++} ++ ++#define OFFSET(x) offsetof(LavfiContext, x) ++ ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++ ++static const AVOption options[] = { ++ { "graph", "Libavfilter graph", OFFSET(graph_str), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC }, ++ { "dumpgraph", "Dump graph to stderr", OFFSET(dump_graph), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass lavfi_class = { ++ .class_name = "lavfi indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_lavfi_demuxer = { ++ .name = "lavfi", ++ .long_name = NULL_IF_CONFIG_SMALL("Libavfilter virtual input device"), ++ .priv_data_size = sizeof(LavfiContext), ++ .read_header = lavfi_read_header, ++ .read_packet = lavfi_read_packet, ++ .read_close = lavfi_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &lavfi_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/libcdio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/libcdio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/libcdio.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/libcdio.c 2012-05-14 14:08:54.653346402 +0200 +@@ -0,0 +1,187 @@ ++/* ++ * Copyright (c) 2011 Anton Khirnov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libcdio CD grabbing ++ */ ++ ++#include ++#include ++ ++#include "libavutil/log.h" ++#include "libavutil/mem.h" ++#include "libavutil/opt.h" ++ ++#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++ ++/* cdio returns some malloced strings that need to be free()d */ ++#undef free ++ ++typedef struct CDIOContext { ++ const AVClass *class; ++ cdrom_drive_t *drive; ++ cdrom_paranoia_t *paranoia; ++ int32_t last_sector; ++ ++ /* private options */ ++ int speed; ++ int paranoia_mode; ++} CDIOContext; ++ ++static av_cold int read_header(AVFormatContext *ctx, AVFormatParameters *ap) ++{ ++ CDIOContext *s = ctx->priv_data; ++ AVStream *st; ++ int ret, i; ++ char *err = NULL; ++ ++ if (!(st = avformat_new_stream(ctx, NULL))) ++ return AVERROR(ENOMEM); ++ s->drive = cdio_cddap_identify(ctx->filename, CDDA_MESSAGE_LOGIT, &err); ++ if (!s->drive) { ++ av_log(ctx, AV_LOG_ERROR, "Could not open drive %s.\n", ctx->filename); ++ return AVERROR(EINVAL); ++ } ++ if (err) { ++ av_log(ctx, AV_LOG_VERBOSE, "%s\n", err); ++ free(err); ++ } ++ if ((ret = cdio_cddap_open(s->drive)) < 0 || !s->drive->opened) { ++ av_log(ctx, AV_LOG_ERROR, "Could not open disk in drive %s.\n", ctx->filename); ++ return AVERROR(EINVAL); ++ } ++ ++ cdio_cddap_verbose_set(s->drive, CDDA_MESSAGE_LOGIT, CDDA_MESSAGE_LOGIT); ++ if (s->speed) ++ cdio_cddap_speed_set(s->drive, s->speed); ++ ++ s->paranoia = cdio_paranoia_init(s->drive); ++ if (!s->paranoia) { ++ av_log(ctx, AV_LOG_ERROR, "Could not init paranoia.\n"); ++ return AVERROR(EINVAL); ++ } ++ cdio_paranoia_modeset(s->paranoia, s->paranoia_mode); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ if (s->drive->bigendianp) ++ st->codec->codec_id = CODEC_ID_PCM_S16BE; ++ else ++ st->codec->codec_id = CODEC_ID_PCM_S16LE; ++ st->codec->sample_rate = 44100; ++ st->codec->channels = 2; ++ if (s->drive->audio_last_sector != CDIO_INVALID_LSN && ++ s->drive->audio_first_sector != CDIO_INVALID_LSN) ++ st->duration = s->drive->audio_last_sector - s->drive->audio_first_sector; ++ else if (s->drive->tracks) ++ st->duration = s->drive->disc_toc[s->drive->tracks].dwStartSector; ++ avpriv_set_pts_info(st, 64, CDIO_CD_FRAMESIZE_RAW, 2*st->codec->channels*st->codec->sample_rate); ++ ++ for (i = 0; i < s->drive->tracks; i++) { ++ char title[16]; ++ snprintf(title, sizeof(title), "track %02d", s->drive->disc_toc[i].bTrack); ++ avpriv_new_chapter(ctx, i, st->time_base, s->drive->disc_toc[i].dwStartSector, ++ s->drive->disc_toc[i+1].dwStartSector, title); ++ } ++ ++ s->last_sector = cdio_cddap_disc_lastsector(s->drive); ++ ++ return 0; ++} ++ ++static int read_packet(AVFormatContext *ctx, AVPacket *pkt) ++{ ++ CDIOContext *s = ctx->priv_data; ++ int ret; ++ uint16_t *buf; ++ char *err = NULL; ++ ++ if (ctx->streams[0]->cur_dts > s->last_sector) ++ return AVERROR_EOF; ++ ++ buf = cdio_paranoia_read(s->paranoia, NULL); ++ if (!buf) ++ return AVERROR_EOF; ++ ++ if (err = cdio_cddap_errors(s->drive)) { ++ av_log(ctx, AV_LOG_ERROR, "%s\n", err); ++ free(err); ++ err = NULL; ++ } ++ if (err = cdio_cddap_messages(s->drive)) { ++ av_log(ctx, AV_LOG_VERBOSE, "%s\n", err); ++ free(err); ++ err = NULL; ++ } ++ ++ if ((ret = av_new_packet(pkt, CDIO_CD_FRAMESIZE_RAW)) < 0) ++ return ret; ++ memcpy(pkt->data, buf, CDIO_CD_FRAMESIZE_RAW); ++ return 0; ++} ++ ++static av_cold int read_close(AVFormatContext *ctx) ++{ ++ CDIOContext *s = ctx->priv_data; ++ cdio_paranoia_free(s->paranoia); ++ cdio_cddap_close(s->drive); ++ return 0; ++} ++ ++static int read_seek(AVFormatContext *ctx, int stream_index, int64_t timestamp, ++ int flags) ++{ ++ CDIOContext *s = ctx->priv_data; ++ AVStream *st = ctx->streams[0]; ++ ++ cdio_paranoia_seek(s->paranoia, timestamp, SEEK_SET); ++ st->cur_dts = timestamp; ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(CDIOContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "speed", "Drive reading speed.", OFFSET(speed), AV_OPT_TYPE_INT, { 0 }, 0, INT_MAX, DEC }, ++ { "paranoia_mode", "Error recovery mode.", OFFSET(paranoia_mode), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, DEC, "paranoia_mode" }, ++ { "verify", "Verify data integrity in overlap area", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_VERIFY }, 0, 0, DEC, "paranoia_mode" }, ++ { "overlap", "Perform overlapped reads.", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_OVERLAP }, 0, 0, DEC, "paranoia_mode" }, ++ { "neverskip", "Do not skip failed reads.", 0, AV_OPT_TYPE_CONST, { PARANOIA_MODE_NEVERSKIP }, 0, 0, DEC, "paranoia_mode" }, ++ { NULL }, ++}; ++ ++static const AVClass libcdio_class = { ++ .class_name = "libcdio indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_libcdio_demuxer = { ++ .name = "libcdio", ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_close = read_close, ++ .read_seek = read_seek, ++ .priv_data_size = sizeof(CDIOContext), ++ .flags = AVFMT_NOFILE, ++ .priv_class = &libcdio_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/libdc1394.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/libdc1394.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/libdc1394.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/libdc1394.c 2012-05-14 14:08:54.655346443 +0200 +@@ -2,6 +2,7 @@ + * IIDC1394 grab interface (uses libdc1394 and libraw1394) + * Copyright (c) 2004 Roman Shaposhnik + * Copyright (c) 2008 Alessandro Sappia ++ * Copyright (c) 2011 Martin Lambers + * + * This file is part of FFmpeg. + * +@@ -21,54 +22,50 @@ + */ + + #include "config.h" +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/log.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" ++#include "avdevice.h" ++ ++#include ++#include ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" + +-#if HAVE_LIBDC1394_2 + #include +-#elif HAVE_LIBDC1394_1 +-#include +-#include +- +-#define DC1394_VIDEO_MODE_320x240_YUV422 MODE_320x240_YUV422 +-#define DC1394_VIDEO_MODE_640x480_YUV411 MODE_640x480_YUV411 +-#define DC1394_VIDEO_MODE_640x480_YUV422 MODE_640x480_YUV422 +-#define DC1394_FRAMERATE_1_875 FRAMERATE_1_875 +-#define DC1394_FRAMERATE_3_75 FRAMERATE_3_75 +-#define DC1394_FRAMERATE_7_5 FRAMERATE_7_5 +-#define DC1394_FRAMERATE_15 FRAMERATE_15 +-#define DC1394_FRAMERATE_30 FRAMERATE_30 +-#define DC1394_FRAMERATE_60 FRAMERATE_60 +-#define DC1394_FRAMERATE_120 FRAMERATE_120 +-#define DC1394_FRAMERATE_240 FRAMERATE_240 +-#endif + + #undef free + + typedef struct dc1394_data { +-#if HAVE_LIBDC1394_1 +- raw1394handle_t handle; +- dc1394_cameracapture camera; +-#elif HAVE_LIBDC1394_2 ++ AVClass *class; + dc1394_t *d; + dc1394camera_t *camera; + dc1394video_frame_t *frame; +-#endif + int current_frame; +- int fps; ++ int frame_rate; /**< frames per 1000 seconds (fps * 1000) */ ++ char *video_size; /**< String describing video size, set by a private option. */ ++ char *pixel_format; /**< Set by a private option. */ ++ char *framerate; /**< Set by a private option. */ + + AVPacket packet; + } dc1394_data; + +-struct dc1394_frame_format { +- int width; +- int height; +- enum PixelFormat pix_fmt; +- int frame_size_id; +-} dc1394_frame_formats[] = { +- { 320, 240, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_320x240_YUV422 }, +- { 640, 480, PIX_FMT_UYYVYY411, DC1394_VIDEO_MODE_640x480_YUV411 }, +- { 640, 480, PIX_FMT_UYVY422, DC1394_VIDEO_MODE_640x480_YUV422 }, +- { 0, 0, 0, 0 } /* gotta be the last one */ ++/* The list of color codings that we support. ++ * We assume big endian for the dc1394 16bit modes: libdc1394 never sets the ++ * flag little_endian in dc1394video_frame_t. */ ++struct dc1394_color_coding { ++ int pix_fmt; ++ int score; ++ uint32_t coding; ++} dc1394_color_codings[] = { ++ { PIX_FMT_GRAY16BE, 1000, DC1394_COLOR_CODING_MONO16 }, ++ { PIX_FMT_RGB48BE, 1100, DC1394_COLOR_CODING_RGB16 }, ++ { PIX_FMT_GRAY8, 1200, DC1394_COLOR_CODING_MONO8 }, ++ { PIX_FMT_RGB24, 1300, DC1394_COLOR_CODING_RGB8 }, ++ { PIX_FMT_UYYVYY411, 1400, DC1394_COLOR_CODING_YUV411 }, ++ { PIX_FMT_UYVY422, 1500, DC1394_COLOR_CODING_YUV422 }, ++ { PIX_FMT_NONE, 0, 0 } /* gotta be the last one */ + }; + + struct dc1394_frame_rate { +@@ -86,167 +83,39 @@ + { 0, 0 } /* gotta be the last one */ + }; + +-static inline int dc1394_read_common(AVFormatContext *c, AVFormatParameters *ap, +- struct dc1394_frame_format **select_fmt, struct dc1394_frame_rate **select_fps) +-{ +- dc1394_data* dc1394 = c->priv_data; +- AVStream* vst; +- struct dc1394_frame_format *fmt; +- struct dc1394_frame_rate *fps; +- enum PixelFormat pix_fmt = ap->pix_fmt == PIX_FMT_NONE ? PIX_FMT_UYVY422 : ap->pix_fmt; /* defaults */ +- int width = !ap->width ? 320 : ap->width; +- int height = !ap->height ? 240 : ap->height; +- int frame_rate = !ap->time_base.num ? 30000 : av_rescale(1000, ap->time_base.den, ap->time_base.num); +- +- for (fmt = dc1394_frame_formats; fmt->width; fmt++) +- if (fmt->pix_fmt == pix_fmt && fmt->width == width && fmt->height == height) +- break; +- +- for (fps = dc1394_frame_rates; fps->frame_rate; fps++) +- if (fps->frame_rate == frame_rate) +- break; +- +- if (!fps->frame_rate || !fmt->width) { +- av_log(c, AV_LOG_ERROR, "Can't find matching camera format for %s, %dx%d@%d:1000fps\n", avcodec_get_pix_fmt_name(pix_fmt), +- width, height, frame_rate); +- goto out; +- } +- +- /* create a video stream */ +- vst = av_new_stream(c, 0); +- if (!vst) +- goto out; +- av_set_pts_info(vst, 64, 1, 1000); +- vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- vst->codec->codec_id = CODEC_ID_RAWVIDEO; +- vst->codec->time_base.den = fps->frame_rate; +- vst->codec->time_base.num = 1000; +- vst->codec->width = fmt->width; +- vst->codec->height = fmt->height; +- vst->codec->pix_fmt = fmt->pix_fmt; +- +- /* packet init */ +- av_init_packet(&dc1394->packet); +- dc1394->packet.size = avpicture_get_size(fmt->pix_fmt, fmt->width, fmt->height); +- dc1394->packet.stream_index = vst->index; +- dc1394->packet.flags |= AV_PKT_FLAG_KEY; +- +- dc1394->current_frame = 0; +- dc1394->fps = fps->frame_rate; +- +- vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, fps->frame_rate, 1000); +- *select_fps = fps; +- *select_fmt = fmt; +- return 0; +-out: +- return -1; +-} +- +-#if HAVE_LIBDC1394_1 +-static int dc1394_v1_read_header(AVFormatContext *c, AVFormatParameters * ap) +-{ +- dc1394_data* dc1394 = c->priv_data; +- AVStream* vst; +- nodeid_t* camera_nodes; +- int res; +- struct dc1394_frame_format *fmt = NULL; +- struct dc1394_frame_rate *fps = NULL; +- +- if (dc1394_read_common(c,ap,&fmt,&fps) != 0) +- return -1; +- +- /* Now let us prep the hardware. */ +- dc1394->handle = dc1394_create_handle(0); /* FIXME: gotta have ap->port */ +- if (!dc1394->handle) { +- av_log(c, AV_LOG_ERROR, "Can't acquire dc1394 handle on port %d\n", 0 /* ap->port */); +- goto out; +- } +- camera_nodes = dc1394_get_camera_nodes(dc1394->handle, &res, 1); +- if (!camera_nodes || camera_nodes[ap->channel] == DC1394_NO_CAMERA) { +- av_log(c, AV_LOG_ERROR, "There's no IIDC camera on the channel %d\n", ap->channel); +- goto out_handle; +- } +- res = dc1394_dma_setup_capture(dc1394->handle, camera_nodes[ap->channel], +- 0, +- FORMAT_VGA_NONCOMPRESSED, +- fmt->frame_size_id, +- SPEED_400, +- fps->frame_rate_id, 8, 1, +- c->filename, +- &dc1394->camera); +- dc1394_free_camera_nodes(camera_nodes); +- if (res != DC1394_SUCCESS) { +- av_log(c, AV_LOG_ERROR, "Can't prepare camera for the DMA capture\n"); +- goto out_handle; +- } +- +- res = dc1394_start_iso_transmission(dc1394->handle, dc1394->camera.node); +- if (res != DC1394_SUCCESS) { +- av_log(c, AV_LOG_ERROR, "Can't start isochronous transmission\n"); +- goto out_handle_dma; +- } +- +- return 0; +- +-out_handle_dma: +- dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); +- dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); +-out_handle: +- dc1394_destroy_handle(dc1394->handle); +-out: +- return -1; +-} +- +-static int dc1394_v1_read_packet(AVFormatContext *c, AVPacket *pkt) +-{ +- struct dc1394_data *dc1394 = c->priv_data; +- int res; +- +- /* discard stale frame */ +- if (dc1394->current_frame++) { +- if (dc1394_dma_done_with_buffer(&dc1394->camera) != DC1394_SUCCESS) +- av_log(c, AV_LOG_ERROR, "failed to release %d frame\n", dc1394->current_frame); +- } +- +- res = dc1394_dma_single_capture(&dc1394->camera); +- +- if (res == DC1394_SUCCESS) { +- dc1394->packet.data = (uint8_t *)(dc1394->camera.capture_buffer); +- dc1394->packet.pts = (dc1394->current_frame * 1000000) / dc1394->fps; +- res = dc1394->packet.size; +- } else { +- av_log(c, AV_LOG_ERROR, "DMA capture failed\n"); +- dc1394->packet.data = NULL; +- res = -1; +- } +- +- *pkt = dc1394->packet; +- return res; +-} +- +-static int dc1394_v1_close(AVFormatContext * context) +-{ +- struct dc1394_data *dc1394 = context->priv_data; +- +- dc1394_stop_iso_transmission(dc1394->handle, dc1394->camera.node); +- dc1394_dma_unlisten(dc1394->handle, &dc1394->camera); +- dc1394_dma_release_camera(dc1394->handle, &dc1394->camera); +- dc1394_destroy_handle(dc1394->handle); ++#define OFFSET(x) offsetof(dc1394_data, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "qvga"}, 0, 0, DEC }, ++ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "uyvy422"}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC }, ++ { NULL }, ++}; + +- return 0; +-} ++static const AVClass libdc1394_class = { ++ .class_name = "libdc1394 indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + +-#elif HAVE_LIBDC1394_2 +-static int dc1394_v2_read_header(AVFormatContext *c, AVFormatParameters * ap) ++static int dc1394_read_header(AVFormatContext *c, AVFormatParameters * ap) + { + dc1394_data* dc1394 = c->priv_data; ++ AVStream *vst; ++ const struct dc1394_color_coding *cc; ++ const struct dc1394_frame_rate *fr; + dc1394camera_list_t *list; +- int res, i; +- struct dc1394_frame_format *fmt = NULL; +- struct dc1394_frame_rate *fps = NULL; +- +- if (dc1394_read_common(c,ap,&fmt,&fps) != 0) +- return -1; ++ dc1394video_modes_t video_modes; ++ dc1394video_mode_t video_mode; ++ dc1394framerates_t frame_rates; ++ dc1394framerate_t frame_rate; ++ uint32_t dc1394_width, dc1394_height, dc1394_color_coding; ++ int rate, best_rate; ++ int score, max_score; ++ int final_width, final_height, final_pix_fmt, final_frame_rate; ++ int res, i, j; ++ int ret=-1; + + /* Now let us prep the hardware. */ + dc1394->d = dc1394_new(); +@@ -265,6 +134,149 @@ + /* Freeing list of cameras */ + dc1394_camera_free_list (list); + ++ /* Get the list of video modes supported by the camera. */ ++ res = dc1394_video_get_supported_modes (dc1394->camera, &video_modes); ++ if (res != DC1394_SUCCESS) { ++ av_log(c, AV_LOG_ERROR, "Could not get video formats.\n"); ++ goto out_camera; ++ } ++ ++ if (dc1394->pixel_format) { ++ if ((ap->pix_fmt = av_get_pix_fmt(dc1394->pixel_format)) == PIX_FMT_NONE) { ++ av_log(c, AV_LOG_ERROR, "No such pixel format: %s.\n", dc1394->pixel_format); ++ ret = AVERROR(EINVAL); ++ goto out; ++ } ++ } ++ ++ if (dc1394->video_size) { ++ if ((ret = av_parse_video_size(&ap->width, &ap->height, dc1394->video_size)) < 0) { ++ av_log(c, AV_LOG_ERROR, "Couldn't parse video size.\n"); ++ goto out; ++ } ++ } ++ ++ /* Choose the best mode. */ ++ rate = (ap->time_base.num ? av_rescale(1000, ap->time_base.den, ap->time_base.num) : -1); ++ max_score = -1; ++ for (i = 0; i < video_modes.num; i++) { ++ if (video_modes.modes[i] == DC1394_VIDEO_MODE_EXIF ++ || (video_modes.modes[i] >= DC1394_VIDEO_MODE_FORMAT7_MIN ++ && video_modes.modes[i] <= DC1394_VIDEO_MODE_FORMAT7_MAX)) { ++ /* These modes are currently not supported as they would require ++ * much more work. For the remaining modes, the functions ++ * dc1394_get_image_size_from_video_mode and ++ * dc1394_get_color_coding_from_video_mode do not need to query the ++ * camera, and thus cannot fail. */ ++ continue; ++ } ++ dc1394_get_color_coding_from_video_mode (NULL, video_modes.modes[i], ++ &dc1394_color_coding); ++ for (cc = dc1394_color_codings; cc->pix_fmt != PIX_FMT_NONE; cc++) ++ if (cc->coding == dc1394_color_coding) ++ break; ++ if (cc->pix_fmt == PIX_FMT_NONE) { ++ /* We currently cannot handle this color coding. */ ++ continue; ++ } ++ /* Here we know that the mode is supported. Get its frame size and the list ++ * of frame rates supported by the camera for this mode. This list is sorted ++ * in ascending order according to libdc1394 example programs. */ ++ dc1394_get_image_size_from_video_mode (NULL, video_modes.modes[i], ++ &dc1394_width, &dc1394_height); ++ res = dc1394_video_get_supported_framerates (dc1394->camera, video_modes.modes[i], ++ &frame_rates); ++ if (res != DC1394_SUCCESS || frame_rates.num == 0) { ++ av_log(c, AV_LOG_ERROR, "Cannot get frame rates for video mode.\n"); ++ goto out_camera; ++ } ++ /* Choose the best frame rate. */ ++ best_rate = -1; ++ for (j = 0; j < frame_rates.num; j++) { ++ for (fr = dc1394_frame_rates; fr->frame_rate; fr++) { ++ if (fr->frame_rate_id == frame_rates.framerates[j]) { ++ break; ++ } ++ } ++ if (!fr->frame_rate) { ++ /* This frame rate is not supported. */ ++ continue; ++ } ++ best_rate = fr->frame_rate; ++ frame_rate = fr->frame_rate_id; ++ if (ap->time_base.num && rate == fr->frame_rate) { ++ /* This is the requested frame rate. */ ++ break; ++ } ++ } ++ if (best_rate == -1) { ++ /* No supported rate found. */ ++ continue; ++ } ++ /* Here we know that both the mode and the rate are supported. Compute score. */ ++ if (ap->width && ap->height ++ && (dc1394_width == ap->width && dc1394_height == ap->height)) { ++ score = 110000; ++ } else { ++ score = dc1394_width * 10; // 1600 - 16000 ++ } ++ if (ap->pix_fmt == cc->pix_fmt) { ++ score += 90000; ++ } else { ++ score += cc->score; // 1000 - 1500 ++ } ++ if (ap->time_base.num && rate == best_rate) { ++ score += 70000; ++ } else { ++ score += best_rate / 1000; // 1 - 240 ++ } ++ if (score > max_score) { ++ video_mode = video_modes.modes[i]; ++ final_width = dc1394_width; ++ final_height = dc1394_height; ++ final_pix_fmt = cc->pix_fmt; ++ final_frame_rate = best_rate; ++ max_score = score; ++ } ++ } ++ if (max_score == -1) { ++ av_log(c, AV_LOG_ERROR, "No suitable video mode / frame rate available.\n"); ++ goto out_camera; ++ } ++ if (ap->width && ap->height && !(ap->width == final_width && ap->height == final_height)) { ++ av_log(c, AV_LOG_WARNING, "Requested frame size is not available, using fallback.\n"); ++ } ++ if (ap->pix_fmt != PIX_FMT_NONE && ap->pix_fmt != final_pix_fmt) { ++ av_log(c, AV_LOG_WARNING, "Requested pixel format is not supported, using fallback.\n"); ++ } ++ if (ap->time_base.num && rate != final_frame_rate) { ++ av_log(c, AV_LOG_WARNING, "Requested frame rate is not available, using fallback.\n"); ++ } ++ ++ /* create a video stream */ ++ vst = avformat_new_stream(c, NULL); ++ if (!vst) ++ goto out_camera; ++ avpriv_set_pts_info(vst, 64, 1, 1000); ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->codec_id = CODEC_ID_RAWVIDEO; ++ vst->codec->time_base.den = final_frame_rate; ++ vst->codec->time_base.num = 1000; ++ vst->codec->width = final_width; ++ vst->codec->height = final_height; ++ vst->codec->pix_fmt = final_pix_fmt; ++ ++ /* packet init */ ++ av_init_packet(&dc1394->packet); ++ dc1394->packet.size = avpicture_get_size(final_pix_fmt, final_width, final_height); ++ dc1394->packet.stream_index = vst->index; ++ dc1394->packet.flags |= AV_PKT_FLAG_KEY; ++ ++ dc1394->current_frame = 0; ++ dc1394->frame_rate = final_frame_rate; ++ ++ vst->codec->bit_rate = av_rescale(dc1394->packet.size * 8, final_frame_rate, 1000); ++ + /* Select MAX Speed possible from the cam */ + if (dc1394->camera->bmode_capable>0) { + dc1394_video_set_operation_mode(dc1394->camera, DC1394_OPERATION_MODE_1394B); +@@ -281,13 +293,13 @@ + goto out_camera; + } + +- if (dc1394_video_set_mode(dc1394->camera, fmt->frame_size_id) != DC1394_SUCCESS) { ++ if (dc1394_video_set_mode(dc1394->camera, video_mode) != DC1394_SUCCESS) { + av_log(c, AV_LOG_ERROR, "Couldn't set video format\n"); + goto out_camera; + } + +- if (dc1394_video_set_framerate(dc1394->camera,fps->frame_rate_id) != DC1394_SUCCESS) { +- av_log(c, AV_LOG_ERROR, "Couldn't set framerate %d \n",fps->frame_rate); ++ if (dc1394_video_set_framerate(dc1394->camera, frame_rate) != DC1394_SUCCESS) { ++ av_log(c, AV_LOG_ERROR, "Could not set framerate %d.\n", final_frame_rate); + goto out_camera; + } + if (dc1394_capture_setup(dc1394->camera, 10, DC1394_CAPTURE_FLAGS_DEFAULT)!=DC1394_SUCCESS) { +@@ -307,10 +319,10 @@ + dc1394_camera_free (dc1394->camera); + out: + dc1394_free(dc1394->d); +- return -1; ++ return ret; + } + +-static int dc1394_v2_read_packet(AVFormatContext *c, AVPacket *pkt) ++static int dc1394_read_packet(AVFormatContext *c, AVPacket *pkt) + { + struct dc1394_data *dc1394 = c->priv_data; + int res; +@@ -323,8 +335,8 @@ + + res = dc1394_capture_dequeue(dc1394->camera, DC1394_CAPTURE_POLICY_WAIT, &dc1394->frame); + if (res == DC1394_SUCCESS) { +- dc1394->packet.data = (uint8_t *)(dc1394->frame->image); +- dc1394->packet.pts = (dc1394->current_frame * 1000000) / (dc1394->fps); ++ dc1394->packet.data = (uint8_t *) dc1394->frame->image; ++ dc1394->packet.pts = dc1394->current_frame * 1000000 / dc1394->frame_rate; + res = dc1394->frame->image_bytes; + } else { + av_log(c, AV_LOG_ERROR, "DMA capture failed\n"); +@@ -336,7 +348,7 @@ + return res; + } + +-static int dc1394_v2_close(AVFormatContext * context) ++static int dc1394_close(AVFormatContext * context) + { + struct dc1394_data *dc1394 = context->priv_data; + +@@ -350,23 +362,11 @@ + + AVInputFormat ff_libdc1394_demuxer = { + .name = "libdc1394", +- .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.2 A/V grab"), +- .priv_data_size = sizeof(struct dc1394_data), +- .read_header = dc1394_v2_read_header, +- .read_packet = dc1394_v2_read_packet, +- .read_close = dc1394_v2_close, +- .flags = AVFMT_NOFILE +-}; +- +-#endif +-#if HAVE_LIBDC1394_1 +-AVInputFormat ff_libdc1394_demuxer = { +- .name = "libdc1394", +- .long_name = NULL_IF_CONFIG_SMALL("dc1394 v.1 A/V grab"), ++ .long_name = NULL_IF_CONFIG_SMALL("dc1394 A/V grab"), + .priv_data_size = sizeof(struct dc1394_data), +- .read_header = dc1394_v1_read_header, +- .read_packet = dc1394_v1_read_packet, +- .read_close = dc1394_v1_close, +- .flags = AVFMT_NOFILE ++ .read_header = dc1394_read_header, ++ .read_packet = dc1394_read_packet, ++ .read_close = dc1394_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &libdc1394_class, + }; +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/Makefile 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/Makefile 2012-05-14 14:08:54.626345858 +0200 +@@ -1,7 +1,8 @@ + include $(SUBDIR)../config.mak + + NAME = avdevice +-FFLIBS = avformat avcodec avcore avutil ++FFLIBS = avformat avcodec avutil ++FFLIBS-$(CONFIG_LAVFI_INDEV) += avfilter + + HEADERS = avdevice.h + +@@ -9,22 +10,34 @@ + + # input/output devices + OBJS-$(CONFIG_ALSA_INDEV) += alsa-audio-common.o \ +- alsa-audio-dec.o ++ alsa-audio-dec.o timefilter.o + OBJS-$(CONFIG_ALSA_OUTDEV) += alsa-audio-common.o \ + alsa-audio-enc.o + OBJS-$(CONFIG_BKTR_INDEV) += bktr.o ++OBJS-$(CONFIG_DSHOW_INDEV) += dshow.o dshow_enummediatypes.o \ ++ dshow_enumpins.o dshow_filter.o \ ++ dshow_pin.o dshow_common.o + OBJS-$(CONFIG_DV1394_INDEV) += dv1394.o +-OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o ++OBJS-$(CONFIG_FBDEV_INDEV) += fbdev.o ++OBJS-$(CONFIG_JACK_INDEV) += jack_audio.o timefilter.o ++OBJS-$(CONFIG_LAVFI_INDEV) += lavfi.o ++OBJS-$(CONFIG_OPENAL_INDEV) += openal-dec.o + OBJS-$(CONFIG_OSS_INDEV) += oss_audio.o + OBJS-$(CONFIG_OSS_OUTDEV) += oss_audio.o ++OBJS-$(CONFIG_PULSE_INDEV) += pulse.o ++OBJS-$(CONFIG_SDL_OUTDEV) += sdl.o ++OBJS-$(CONFIG_SNDIO_INDEV) += sndio_common.o sndio_dec.o ++OBJS-$(CONFIG_SNDIO_OUTDEV) += sndio_common.o sndio_enc.o + OBJS-$(CONFIG_V4L2_INDEV) += v4l2.o + OBJS-$(CONFIG_V4L_INDEV) += v4l.o + OBJS-$(CONFIG_VFWCAP_INDEV) += vfwcap.o + OBJS-$(CONFIG_X11_GRAB_DEVICE_INDEV) += x11grab.o + + # external libraries ++OBJS-$(CONFIG_LIBCDIO_INDEV) += libcdio.o + OBJS-$(CONFIG_LIBDC1394_INDEV) += libdc1394.o + + SKIPHEADERS-$(HAVE_ALSA_ASOUNDLIB_H) += alsa-audio.h ++SKIPHEADERS-$(HAVE_SNDIO_H) += sndio_common.h + +-include $(SUBDIR)../subdir.mak ++TESTPROGS = timefilter +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/openal-dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/openal-dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/openal-dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/openal-dec.c 2012-05-14 14:08:54.656346463 +0200 +@@ -0,0 +1,251 @@ ++/* ++ * Copyright (c) 2011 Jonathan Baldwin ++ * ++ * This file is part of FFmpeg. ++ * ++ * Permission to use, copy, modify, and/or distribute this software for any ++ * purpose with or without fee is hereby granted, provided that the above ++ * copyright notice and this permission notice appear in all copies. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH ++ * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY ++ * AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, ++ * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM ++ * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR ++ * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR ++ * PERFORMANCE OF THIS SOFTWARE. ++ */ ++ ++/** ++ * @file ++ * OpenAL 1.1 capture device for libavdevice ++ **/ ++ ++#include ++#include ++ ++#include "libavutil/opt.h" ++#include "libavformat/internal.h" ++#include "avdevice.h" ++ ++typedef struct { ++ AVClass *class; ++ /** OpenAL capture device context. **/ ++ ALCdevice *device; ++ /** The number of channels in the captured audio. **/ ++ int channels; ++ /** The sample rate (in Hz) of the captured audio. **/ ++ int sample_rate; ++ /** The sample size (in bits) of the captured audio. **/ ++ int sample_size; ++ /** The OpenAL sample format of the captured audio. **/ ++ ALCenum sample_format; ++ /** The number of bytes between two consecutive samples of the same channel/component. **/ ++ ALCint sample_step; ++ /** If true, print a list of capture devices on this system and exit. **/ ++ int list_devices; ++} al_data; ++ ++typedef struct { ++ ALCenum al_fmt; ++ enum CodecID codec_id; ++ int channels; ++} al_format_info; ++ ++#define LOWEST_AL_FORMAT FFMIN(FFMIN(AL_FORMAT_MONO8,AL_FORMAT_MONO16),FFMIN(AL_FORMAT_STEREO8,AL_FORMAT_STEREO16)) ++ ++/** ++ * Get information about an AL_FORMAT value. ++ * @param al_fmt the AL_FORMAT value to find information about. ++ * @return A pointer to a structure containing information about the AL_FORMAT value. ++ */ ++static inline al_format_info* get_al_format_info(ALCenum al_fmt) ++{ ++ static al_format_info info_table[] = { ++ [AL_FORMAT_MONO8-LOWEST_AL_FORMAT] = {AL_FORMAT_MONO8, CODEC_ID_PCM_U8, 1}, ++ [AL_FORMAT_MONO16-LOWEST_AL_FORMAT] = {AL_FORMAT_MONO16, AV_NE (CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), 1}, ++ [AL_FORMAT_STEREO8-LOWEST_AL_FORMAT] = {AL_FORMAT_STEREO8, CODEC_ID_PCM_U8, 2}, ++ [AL_FORMAT_STEREO16-LOWEST_AL_FORMAT] = {AL_FORMAT_STEREO16, AV_NE (CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), 2}, ++ }; ++ ++ return &info_table[al_fmt-LOWEST_AL_FORMAT]; ++} ++ ++/** ++ * Get the OpenAL error code, translated into an av/errno error code. ++ * @param device The ALC device to check for errors. ++ * @param error_msg_ret A pointer to a char* in which to return the error message, or NULL if desired. ++ * @return The error code, or 0 if there is no error. ++ */ ++static inline int al_get_error(ALCdevice *device, const char** error_msg_ret) ++{ ++ ALCenum error = alcGetError(device); ++ if (error_msg_ret) ++ *error_msg_ret = (const char*) alcGetString(device, error); ++ switch (error) { ++ case ALC_NO_ERROR: ++ return 0; ++ case ALC_INVALID_DEVICE: ++ return AVERROR(ENODEV); ++ break; ++ case ALC_INVALID_CONTEXT: ++ case ALC_INVALID_ENUM: ++ case ALC_INVALID_VALUE: ++ return AVERROR(EINVAL); ++ break; ++ case ALC_OUT_OF_MEMORY: ++ return AVERROR(ENOMEM); ++ break; ++ default: ++ return AVERROR(EIO); ++ } ++} ++ ++/** ++ * Print out a list of OpenAL capture devices on this system. ++ */ ++static inline void print_al_capture_devices(void *log_ctx) ++{ ++ const char *devices; ++ ++ if (!(devices = alcGetString(NULL, ALC_CAPTURE_DEVICE_SPECIFIER))) ++ return; ++ ++ av_log(log_ctx, AV_LOG_INFO, "List of OpenAL capture devices on this system:\n"); ++ ++ for (; *devices != '\0'; devices += strlen(devices) + 1) ++ av_log(log_ctx, AV_LOG_INFO, " %s\n", devices); ++} ++ ++static int read_header(AVFormatContext *ctx, AVFormatParameters *ap) ++{ ++ al_data *ad = ctx->priv_data; ++ static const ALCenum sample_formats[2][2] = { ++ { AL_FORMAT_MONO8, AL_FORMAT_STEREO8 }, ++ { AL_FORMAT_MONO16, AL_FORMAT_STEREO16 } ++ }; ++ int error = 0; ++ const char *error_msg; ++ AVStream *st = NULL; ++ AVCodecContext *codec = NULL; ++ ++ if (ad->list_devices) { ++ print_al_capture_devices(ctx); ++ return AVERROR_EXIT; ++ } ++ ++ ad->sample_format = sample_formats[ad->sample_size/8-1][ad->channels-1]; ++ ++ /* Open device for capture */ ++ ad->device = ++ alcCaptureOpenDevice(ctx->filename[0] ? ctx->filename : NULL, ++ ad->sample_rate, ++ ad->sample_format, ++ ad->sample_rate); /* Maximum 1 second of sample data to be read at once */ ++ ++ if (error = al_get_error(ad->device, &error_msg)) goto fail; ++ ++ /* Create stream */ ++ if (!(st = avformat_new_stream(ctx, NULL))) { ++ error = AVERROR(ENOMEM); ++ goto fail; ++ } ++ ++ /* We work in microseconds */ ++ avpriv_set_pts_info(st, 64, 1, 1000000); ++ ++ /* Set codec parameters */ ++ codec = st->codec; ++ codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ codec->sample_rate = ad->sample_rate; ++ codec->channels = get_al_format_info(ad->sample_format)->channels; ++ codec->codec_id = get_al_format_info(ad->sample_format)->codec_id; ++ ++ /* This is needed to read the audio data */ ++ ad->sample_step = (av_get_bits_per_sample(get_al_format_info(ad->sample_format)->codec_id) * ++ get_al_format_info(ad->sample_format)->channels) / 8; ++ ++ /* Finally, start the capture process */ ++ alcCaptureStart(ad->device); ++ ++ return 0; ++ ++fail: ++ /* Handle failure */ ++ if (ad->device) ++ alcCaptureCloseDevice(ad->device); ++ if (error_msg) ++ av_log(ctx, AV_LOG_ERROR, "Cannot open device: %s\n", error_msg); ++ return error; ++} ++ ++static int read_packet(AVFormatContext* ctx, AVPacket *pkt) ++{ ++ al_data *ad = ctx->priv_data; ++ int error=0; ++ const char *error_msg; ++ ALCint nb_samples; ++ ++ /* Get number of samples available */ ++ alcGetIntegerv(ad->device, ALC_CAPTURE_SAMPLES, (ALCsizei) sizeof(ALCint), &nb_samples); ++ if (error = al_get_error(ad->device, &error_msg)) goto fail; ++ ++ /* Create a packet of appropriate size */ ++ av_new_packet(pkt, nb_samples*ad->sample_step); ++ pkt->pts = av_gettime(); ++ ++ /* Fill the packet with the available samples */ ++ alcCaptureSamples(ad->device, pkt->data, nb_samples); ++ if (error = al_get_error(ad->device, &error_msg)) goto fail; ++ ++ return pkt->size; ++fail: ++ /* Handle failure */ ++ if (pkt->data) ++ av_destruct_packet(pkt); ++ if (error_msg) ++ av_log(ctx, AV_LOG_ERROR, "Error: %s\n", error_msg); ++ return error; ++} ++ ++static int read_close(AVFormatContext* ctx) ++{ ++ al_data *ad = ctx->priv_data; ++ ++ if (ad->device) { ++ alcCaptureStop(ad->device); ++ alcCaptureCloseDevice(ad->device); ++ } ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(al_data, x) ++ ++static const AVOption options[] = { ++ {"channels", "set number of channels", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl=2}, 1, 2, AV_OPT_FLAG_DECODING_PARAM }, ++ {"sample_rate", "set sample rate", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl=44100}, 1, 192000, AV_OPT_FLAG_DECODING_PARAM }, ++ {"sample_size", "set sample size", OFFSET(sample_size), AV_OPT_TYPE_INT, {.dbl=16}, 8, 16, AV_OPT_FLAG_DECODING_PARAM }, ++ {"list_devices", "list available devices", OFFSET(list_devices), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM, "list_devices" }, ++ {"true", "", 0, AV_OPT_TYPE_CONST, {.dbl=1}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" }, ++ {"false", "", 0, AV_OPT_TYPE_CONST, {.dbl=0}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "list_devices" }, ++ {NULL}, ++}; ++ ++static const AVClass class = { ++ .class_name = "openal", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT ++}; ++ ++AVInputFormat ff_openal_demuxer = { ++ .name = "openal", ++ .long_name = NULL_IF_CONFIG_SMALL("OpenAL audio capture device"), ++ .priv_data_size = sizeof(al_data), ++ .read_probe = NULL, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_close = read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &class ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/oss_audio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/oss_audio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/oss_audio.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/oss_audio.c 2012-05-14 14:08:54.658346503 +0200 +@@ -37,12 +37,15 @@ + #include + + #include "libavutil/log.h" ++#include "libavutil/opt.h" + #include "libavcodec/avcodec.h" +-#include "libavformat/avformat.h" ++#include "avdevice.h" ++#include "libavformat/internal.h" + + #define AUDIO_BLOCK_SIZE 4096 + + typedef struct { ++ AVClass *class; + int fd; + int sample_rate; + int channels; +@@ -78,13 +81,6 @@ + fcntl(audio_fd, F_SETFL, O_NONBLOCK); + + s->frame_size = AUDIO_BLOCK_SIZE; +-#if 0 +- tmp = (NB_FRAGMENTS << 16) | FRAGMENT_BITS; +- err = ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp); +- if (err < 0) { +- perror("SNDCTL_DSP_SETFRAGMENT"); +- } +-#endif + + /* select format : favour native format */ + err = ioctl(audio_fd, SNDCTL_DSP_GETFMTS, &tmp); +@@ -179,9 +175,7 @@ + uint8_t *buf= pkt->data; + + while (size > 0) { +- len = AUDIO_BLOCK_SIZE - s->buffer_ptr; +- if (len > size) +- len = size; ++ len = FFMIN(AUDIO_BLOCK_SIZE - s->buffer_ptr, size); + memcpy(s->buffer + s->buffer_ptr, buf, len); + s->buffer_ptr += len; + if (s->buffer_ptr >= AUDIO_BLOCK_SIZE) { +@@ -216,15 +210,10 @@ + AVStream *st; + int ret; + +- if (ap->sample_rate <= 0 || ap->channels <= 0) +- return -1; +- +- st = av_new_stream(s1, 0); ++ st = avformat_new_stream(s1, NULL); + if (!st) { + return AVERROR(ENOMEM); + } +- s->sample_rate = ap->sample_rate; +- s->channels = ap->channels; + + ret = audio_open(s1, 0, s1->filename); + if (ret < 0) { +@@ -237,7 +226,7 @@ + st->codec->sample_rate = s->sample_rate; + st->codec->channels = s->channels; + +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + return 0; + } + +@@ -293,33 +282,44 @@ + } + + #if CONFIG_OSS_INDEV ++static const AVOption options[] = { ++ { "sample_rate", "", offsetof(AudioData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { "channels", "", offsetof(AudioData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass oss_demuxer_class = { ++ .class_name = "OSS demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_oss_demuxer = { +- "oss", +- NULL_IF_CONFIG_SMALL("Open Sound System capture"), +- sizeof(AudioData), +- NULL, +- audio_read_header, +- audio_read_packet, +- audio_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "oss", ++ .long_name = NULL_IF_CONFIG_SMALL("Open Sound System capture"), ++ .priv_data_size = sizeof(AudioData), ++ .read_header = audio_read_header, ++ .read_packet = audio_read_packet, ++ .read_close = audio_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &oss_demuxer_class, + }; + #endif + + #if CONFIG_OSS_OUTDEV + AVOutputFormat ff_oss_muxer = { +- "oss", +- NULL_IF_CONFIG_SMALL("Open Sound System playback"), +- "", +- "", +- sizeof(AudioData), ++ .name = "oss", ++ .long_name = NULL_IF_CONFIG_SMALL("Open Sound System playback"), ++ .priv_data_size = sizeof(AudioData), + /* XXX: we make the assumption that the soundcard accepts this format */ + /* XXX: find better solution with "preinit" method, needed also in + other formats */ +- AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), +- CODEC_ID_NONE, +- audio_write_header, +- audio_write_packet, +- audio_write_trailer, +- .flags = AVFMT_NOFILE, ++ .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), ++ .video_codec = CODEC_ID_NONE, ++ .write_header = audio_write_header, ++ .write_packet = audio_write_packet, ++ .write_trailer = audio_write_trailer, ++ .flags = AVFMT_NOFILE, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/pulse.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/pulse.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/pulse.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/pulse.c 2012-05-14 14:08:54.658346503 +0200 +@@ -0,0 +1,191 @@ ++/* ++ * Pulseaudio input ++ * Copyright (c) 2011 Luca Barbato ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * PulseAudio input using the simple API. ++ * @author Luca Barbato ++ */ ++ ++#include ++#include ++#include ++ ++#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/opt.h" ++ ++#define DEFAULT_CODEC_ID AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE) ++ ++typedef struct PulseData { ++ AVClass *class; ++ char *server; ++ char *name; ++ char *stream_name; ++ int sample_rate; ++ int channels; ++ int frame_size; ++ int fragment_size; ++ pa_simple *s; ++ int64_t pts; ++ int64_t frame_duration; ++} PulseData; ++ ++static pa_sample_format_t codec_id_to_pulse_format(int codec_id) { ++ switch (codec_id) { ++ case CODEC_ID_PCM_U8: return PA_SAMPLE_U8; ++ case CODEC_ID_PCM_ALAW: return PA_SAMPLE_ALAW; ++ case CODEC_ID_PCM_MULAW: return PA_SAMPLE_ULAW; ++ case CODEC_ID_PCM_S16LE: return PA_SAMPLE_S16LE; ++ case CODEC_ID_PCM_S16BE: return PA_SAMPLE_S16BE; ++ case CODEC_ID_PCM_F32LE: return PA_SAMPLE_FLOAT32LE; ++ case CODEC_ID_PCM_F32BE: return PA_SAMPLE_FLOAT32BE; ++ case CODEC_ID_PCM_S32LE: return PA_SAMPLE_S32LE; ++ case CODEC_ID_PCM_S32BE: return PA_SAMPLE_S32BE; ++ case CODEC_ID_PCM_S24LE: return PA_SAMPLE_S24LE; ++ case CODEC_ID_PCM_S24BE: return PA_SAMPLE_S24BE; ++ default: return PA_SAMPLE_INVALID; ++ } ++} ++ ++static av_cold int pulse_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ PulseData *pd = s->priv_data; ++ AVStream *st; ++ char *device = NULL; ++ int ret; ++ enum CodecID codec_id = ++ s->audio_codec_id == CODEC_ID_NONE ? DEFAULT_CODEC_ID : s->audio_codec_id; ++ const pa_sample_spec ss = { codec_id_to_pulse_format(codec_id), ++ pd->sample_rate, ++ pd->channels }; ++ ++ pa_buffer_attr attr = { -1 }; ++ ++ st = avformat_new_stream(s, NULL); ++ ++ if (!st) { ++ av_log(s, AV_LOG_ERROR, "Cannot add stream\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ attr.fragsize = pd->fragment_size; ++ ++ if (strcmp(s->filename, "default")) ++ device = s->filename; ++ ++ pd->s = pa_simple_new(pd->server, pd->name, ++ PA_STREAM_RECORD, ++ device, pd->stream_name, &ss, ++ NULL, &attr, &ret); ++ ++ if (!pd->s) { ++ av_log(s, AV_LOG_ERROR, "pa_simple_new failed: %s\n", ++ pa_strerror(ret)); ++ return AVERROR(EIO); ++ } ++ /* take real parameters */ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = codec_id; ++ st->codec->sample_rate = pd->sample_rate; ++ st->codec->channels = pd->channels; ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ ++ pd->pts = AV_NOPTS_VALUE; ++ pd->frame_duration = (pd->frame_size * 1000000LL * 8) / ++ (pd->sample_rate * pd->channels * av_get_bits_per_sample(codec_id)); ++ ++ return 0; ++} ++ ++static int pulse_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ PulseData *pd = s->priv_data; ++ int res; ++ pa_usec_t latency; ++ ++ if (av_new_packet(pkt, pd->frame_size) < 0) { ++ return AVERROR(ENOMEM); ++ } ++ ++ if ((pa_simple_read(pd->s, pkt->data, pkt->size, &res)) < 0) { ++ av_log(s, AV_LOG_ERROR, "pa_simple_read failed: %s\n", ++ pa_strerror(res)); ++ av_free_packet(pkt); ++ return AVERROR(EIO); ++ } ++ ++ if ((latency = pa_simple_get_latency(pd->s, &res)) == (pa_usec_t) -1) { ++ av_log(s, AV_LOG_ERROR, "pa_simple_get_latency() failed: %s\n", ++ pa_strerror(res)); ++ return AVERROR(EIO); ++ } ++ ++ if (pd->pts == AV_NOPTS_VALUE) { ++ pd->pts = -latency; ++ } ++ ++ pkt->pts = pd->pts; ++ ++ pd->pts += pd->frame_duration; ++ ++ return 0; ++} ++ ++static av_cold int pulse_close(AVFormatContext *s) ++{ ++ PulseData *pd = s->priv_data; ++ pa_simple_free(pd->s); ++ return 0; ++} ++ ++#define OFFSET(a) offsetof(PulseData, a) ++#define D AV_OPT_FLAG_DECODING_PARAM ++ ++static const AVOption options[] = { ++ { "server", "pulse server name", OFFSET(server), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D }, ++ { "name", "application name", OFFSET(name), AV_OPT_TYPE_STRING, {.str = LIBAVFORMAT_IDENT}, 0, 0, D }, ++ { "stream_name", "stream description", OFFSET(stream_name), AV_OPT_TYPE_STRING, {.str = "record"}, 0, 0, D }, ++ { "sample_rate", "sample rate in Hz", OFFSET(sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, D }, ++ { "channels", "number of audio channels", OFFSET(channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, D }, ++ { "frame_size", "number of bytes per frame", OFFSET(frame_size), AV_OPT_TYPE_INT, {.dbl = 1024}, 1, INT_MAX, D }, ++ { "fragment_size", "buffering size, affects latency and cpu usage", OFFSET(fragment_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX, D }, ++ { NULL }, ++}; ++ ++static const AVClass pulse_demuxer_class = { ++ .class_name = "Pulse demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_pulse_demuxer = { ++ .name = "pulse", ++ .long_name = NULL_IF_CONFIG_SMALL("Pulse audio input"), ++ .priv_data_size = sizeof(PulseData), ++ .read_header = pulse_read_header, ++ .read_packet = pulse_read_packet, ++ .read_close = pulse_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &pulse_demuxer_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sdl.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sdl.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sdl.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sdl.c 2012-05-14 14:08:54.659346523 +0200 +@@ -0,0 +1,230 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libSDL output device ++ */ ++ ++#include ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "avdevice.h" ++ ++typedef struct { ++ AVClass *class; ++ SDL_Surface *surface; ++ SDL_Overlay *overlay; ++ char *window_title; ++ char *icon_title; ++ char *window_size; ++ int window_width, window_height; ++ int overlay_width, overlay_height; ++ int overlay_fmt; ++ int sdl_was_already_inited; ++} SDLContext; ++ ++static const struct sdl_overlay_pix_fmt_entry { ++ enum PixelFormat pix_fmt; int overlay_fmt; ++} sdl_overlay_pix_fmt_map[] = { ++ { PIX_FMT_YUV420P, SDL_IYUV_OVERLAY }, ++ { PIX_FMT_YUYV422, SDL_YUY2_OVERLAY }, ++ { PIX_FMT_UYVY422, SDL_UYVY_OVERLAY }, ++ { PIX_FMT_NONE, 0 }, ++}; ++ ++static int sdl_write_trailer(AVFormatContext *s) ++{ ++ SDLContext *sdl = s->priv_data; ++ ++ av_freep(&sdl->window_title); ++ av_freep(&sdl->icon_title); ++ av_freep(&sdl->window_size); ++ ++ if (sdl->overlay) { ++ SDL_FreeYUVOverlay(sdl->overlay); ++ sdl->overlay = NULL; ++ } ++ if (!sdl->sdl_was_already_inited) ++ SDL_Quit(); ++ ++ return 0; ++} ++ ++static int sdl_write_header(AVFormatContext *s) ++{ ++ SDLContext *sdl = s->priv_data; ++ AVStream *st = s->streams[0]; ++ AVCodecContext *encctx = st->codec; ++ float sar, dar; /* sample and display aspect ratios */ ++ int i, ret; ++ ++ if (!sdl->window_title) ++ sdl->window_title = av_strdup(s->filename); ++ if (!sdl->icon_title) ++ sdl->icon_title = av_strdup(sdl->window_title); ++ ++ if (SDL_WasInit(SDL_INIT_VIDEO)) { ++ av_log(s, AV_LOG_ERROR, ++ "SDL video subsystem was already inited, aborting.\n"); ++ sdl->sdl_was_already_inited = 1; ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ if (SDL_Init(SDL_INIT_VIDEO) != 0) { ++ av_log(s, AV_LOG_ERROR, "Unable to initialize SDL: %s\n", SDL_GetError()); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ if ( s->nb_streams > 1 ++ || encctx->codec_type != AVMEDIA_TYPE_VIDEO ++ || encctx->codec_id != CODEC_ID_RAWVIDEO) { ++ av_log(s, AV_LOG_ERROR, "Only supports one rawvideo stream\n"); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ for (i = 0; sdl_overlay_pix_fmt_map[i].pix_fmt != PIX_FMT_NONE; i++) { ++ if (sdl_overlay_pix_fmt_map[i].pix_fmt == encctx->pix_fmt) { ++ sdl->overlay_fmt = sdl_overlay_pix_fmt_map[i].overlay_fmt; ++ break; ++ } ++ } ++ ++ if (!sdl->overlay_fmt) { ++ av_log(s, AV_LOG_ERROR, ++ "Unsupported pixel format '%s', choose one of yuv420p, yuyv422, or uyvy422.\n", ++ av_get_pix_fmt_name(encctx->pix_fmt)); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ if (sdl->window_size) { ++ if (av_parse_video_size(&sdl->window_width, &sdl->window_height, ++ sdl->window_size) < 0) { ++ av_log(s, AV_LOG_ERROR, "Invalid window size '%s'\n", sdl->window_size); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ } ++ ++ /* compute overlay width and height from the codec context information */ ++ sar = st->sample_aspect_ratio.num ? av_q2d(st->sample_aspect_ratio) : 1; ++ dar = sar * (float)encctx->width / (float)encctx->height; ++ ++ /* we suppose the screen has a 1/1 sample aspect ratio */ ++ sdl->overlay_height = encctx->height; ++ sdl->overlay_width = ((int)rint(sdl->overlay_height * dar)); ++ if (sdl->overlay_width > encctx->width) { ++ sdl->overlay_width = encctx->width; ++ sdl->overlay_height = ((int)rint(sdl->overlay_width / dar)); ++ } ++ ++ if (!sdl->window_width || !sdl->window_height) { ++ sdl->window_width = sdl->overlay_width; ++ sdl->window_height = sdl->overlay_height; ++ } ++ ++ SDL_WM_SetCaption(sdl->window_title, sdl->icon_title); ++ sdl->surface = SDL_SetVideoMode(sdl->window_width, sdl->window_height, ++ 24, SDL_SWSURFACE); ++ if (!sdl->surface) { ++ av_log(s, AV_LOG_ERROR, "Unable to set video mode: %s\n", SDL_GetError()); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ sdl->overlay = SDL_CreateYUVOverlay(sdl->overlay_width, sdl->overlay_height, ++ sdl->overlay_fmt, sdl->surface); ++ if (!sdl->overlay || sdl->overlay->pitches[0] < sdl->overlay_width) { ++ av_log(s, AV_LOG_ERROR, ++ "SDL does not support an overlay with size of %dx%d pixels.\n", ++ sdl->overlay_width, sdl->overlay_height); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ av_log(s, AV_LOG_INFO, "w:%d h:%d fmt:%s sar:%f -> w:%d h:%d\n", ++ encctx->width, encctx->height, av_get_pix_fmt_name(encctx->pix_fmt), sar, ++ sdl->window_width, sdl->window_height); ++ return 0; ++ ++fail: ++ sdl_write_trailer(s); ++ return ret; ++} ++ ++static int sdl_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ SDLContext *sdl = s->priv_data; ++ AVCodecContext *encctx = s->streams[0]->codec; ++ SDL_Rect rect = { 0, 0, sdl->window_width, sdl->window_height }; ++ AVPicture pict; ++ int i; ++ ++ avpicture_fill(&pict, pkt->data, encctx->pix_fmt, encctx->width, encctx->height); ++ ++ SDL_FillRect(sdl->surface, &sdl->surface->clip_rect, ++ SDL_MapRGB(sdl->surface->format, 0, 0, 0)); ++ SDL_LockYUVOverlay(sdl->overlay); ++ for (i = 0; i < 3; i++) { ++ sdl->overlay->pixels [i] = pict.data [i]; ++ sdl->overlay->pitches[i] = pict.linesize[i]; ++ } ++ SDL_DisplayYUVOverlay(sdl->overlay, &rect); ++ SDL_UnlockYUVOverlay(sdl->overlay); ++ ++ SDL_UpdateRect(sdl->surface, 0, 0, sdl->overlay_width, sdl->overlay_height); ++ ++ return 0; ++} ++ ++#define OFFSET(x) offsetof(SDLContext,x) ++ ++static const AVOption options[] = { ++ { "window_title", "SDL window title", OFFSET(window_title), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, ++ { "icon_title", "SDL iconified window title", OFFSET(icon_title) , AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, ++ { "window_size", "SDL window forced size", OFFSET(window_size) , AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass sdl_class = { ++ .class_name = "sdl outdev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVOutputFormat ff_sdl_muxer = { ++ .name = "sdl", ++ .long_name = NULL_IF_CONFIG_SMALL("SDL output device"), ++ .priv_data_size = sizeof(SDLContext), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = sdl_write_header, ++ .write_packet = sdl_write_packet, ++ .write_trailer = sdl_write_trailer, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &sdl_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_common.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_common.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_common.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_common.c 2012-05-14 14:08:54.663346603 +0200 +@@ -0,0 +1,120 @@ ++/* ++ * sndio play and grab interface ++ * Copyright (c) 2010 Jacob Meuser ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++ ++#include "avdevice.h" ++ ++#include "sndio_common.h" ++ ++static inline void movecb(void *addr, int delta) ++{ ++ SndioData *s = addr; ++ ++ s->hwpos += delta * s->channels * s->bps; ++} ++ ++av_cold int ff_sndio_open(AVFormatContext *s1, int is_output, ++ const char *audio_device) ++{ ++ SndioData *s = s1->priv_data; ++ struct sio_hdl *hdl; ++ struct sio_par par; ++ ++ hdl = sio_open(audio_device, is_output ? SIO_PLAY : SIO_REC, 0); ++ if (!hdl) { ++ av_log(s1, AV_LOG_ERROR, "Could not open sndio device\n"); ++ return AVERROR(EIO); ++ } ++ ++ sio_initpar(&par); ++ ++ par.bits = 16; ++ par.sig = 1; ++ par.le = SIO_LE_NATIVE; ++ ++ if (is_output) ++ par.pchan = s->channels; ++ else ++ par.rchan = s->channels; ++ par.rate = s->sample_rate; ++ ++ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) { ++ av_log(s1, AV_LOG_ERROR, "Impossible to set sndio parameters, " ++ "channels: %d sample rate: %d\n", s->channels, s->sample_rate); ++ goto fail; ++ } ++ ++ if (par.bits != 16 || par.sig != 1 || ++ (is_output && (par.pchan != s->channels)) || ++ (!is_output && (par.rchan != s->channels)) || ++ (par.rate != s->sample_rate)) { ++ av_log(s1, AV_LOG_ERROR, "Could not set appropriate sndio parameters, " ++ "channels: %d sample rate: %d\n", s->channels, s->sample_rate); ++ goto fail; ++ } ++ ++ s->buffer_size = par.round * par.bps * ++ (is_output ? par.pchan : par.rchan); ++ ++ if (is_output) { ++ s->buffer = av_malloc(s->buffer_size); ++ if (!s->buffer) { ++ av_log(s1, AV_LOG_ERROR, "Could not allocate buffer\n"); ++ goto fail; ++ } ++ } ++ ++ s->codec_id = par.le ? CODEC_ID_PCM_S16LE : CODEC_ID_PCM_S16BE; ++ s->channels = is_output ? par.pchan : par.rchan; ++ s->sample_rate = par.rate; ++ s->bps = par.bps; ++ ++ sio_onmove(hdl, movecb, s); ++ ++ if (!sio_start(hdl)) { ++ av_log(s1, AV_LOG_ERROR, "Could not start sndio\n"); ++ goto fail; ++ } ++ ++ s->hdl = hdl; ++ ++ return 0; ++ ++fail: ++ av_freep(&s->buffer); ++ ++ if (hdl) ++ sio_close(hdl); ++ ++ return AVERROR(EIO); ++} ++ ++int ff_sndio_close(SndioData *s) ++{ ++ av_freep(&s->buffer); ++ ++ if (s->hdl) ++ sio_close(s->hdl); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_common.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_common.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_common.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_common.h 2012-05-14 14:08:54.664346623 +0200 +@@ -0,0 +1,48 @@ ++/* ++ * sndio play and grab interface ++ * Copyright (c) 2010 Jacob Meuser ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVDEVICE_SNDIO_COMMON_H ++#define AVDEVICE_SNDIO_COMMON_H ++ ++#include ++#include ++ ++#include "libavutil/log.h" ++#include "avdevice.h" ++ ++typedef struct { ++ AVClass *class; ++ struct sio_hdl *hdl; ++ enum CodecID codec_id; ++ int64_t hwpos; ++ int64_t softpos; ++ uint8_t *buffer; ++ int bps; ++ int buffer_size; ++ int buffer_offset; ++ int channels; ++ int sample_rate; ++} SndioData; ++ ++int ff_sndio_open(AVFormatContext *s1, int is_output, const char *audio_device); ++int ff_sndio_close(SndioData *s); ++ ++#endif /* AVDEVICE_SNDIO_COMMON_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_dec.c 2012-05-14 14:08:54.664346623 +0200 +@@ -0,0 +1,118 @@ ++/* ++ * sndio play and grab interface ++ * Copyright (c) 2010 Jacob Meuser ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++ ++#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/opt.h" ++ ++#include "sndio_common.h" ++ ++static av_cold int audio_read_header(AVFormatContext *s1, ++ AVFormatParameters *ap) ++{ ++ SndioData *s = s1->priv_data; ++ AVStream *st; ++ int ret; ++ ++ st = avformat_new_stream(s1, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ ret = ff_sndio_open(s1, 0, s1->filename); ++ if (ret < 0) ++ return ret; ++ ++ /* take real parameters */ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = s->codec_id; ++ st->codec->sample_rate = s->sample_rate; ++ st->codec->channels = s->channels; ++ ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ ++ return 0; ++} ++ ++static int audio_read_packet(AVFormatContext *s1, AVPacket *pkt) ++{ ++ SndioData *s = s1->priv_data; ++ int64_t bdelay, cur_time; ++ int ret; ++ ++ if ((ret = av_new_packet(pkt, s->buffer_size)) < 0) ++ return ret; ++ ++ ret = sio_read(s->hdl, pkt->data, pkt->size); ++ if (ret == 0 || sio_eof(s->hdl)) { ++ av_free_packet(pkt); ++ return AVERROR_EOF; ++ } ++ ++ pkt->size = ret; ++ s->softpos += ret; ++ ++ /* compute pts of the start of the packet */ ++ cur_time = av_gettime(); ++ ++ bdelay = ret + s->hwpos - s->softpos; ++ ++ /* convert to pts */ ++ pkt->pts = cur_time - ((bdelay * 1000000) / ++ (s->bps * s->channels * s->sample_rate)); ++ ++ return 0; ++} ++ ++static av_cold int audio_read_close(AVFormatContext *s1) ++{ ++ SndioData *s = s1->priv_data; ++ ++ ff_sndio_close(s); ++ ++ return 0; ++} ++ ++static const AVOption options[] = { ++ { "sample_rate", "", offsetof(SndioData, sample_rate), AV_OPT_TYPE_INT, {.dbl = 48000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { "channels", "", offsetof(SndioData, channels), AV_OPT_TYPE_INT, {.dbl = 2}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass sndio_demuxer_class = { ++ .class_name = "sndio indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_sndio_demuxer = { ++ .name = "sndio", ++ .long_name = NULL_IF_CONFIG_SMALL("sndio audio capture"), ++ .priv_data_size = sizeof(SndioData), ++ .read_header = audio_read_header, ++ .read_packet = audio_read_packet, ++ .read_close = audio_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &sndio_demuxer_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/sndio_enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/sndio_enc.c 2012-05-14 14:08:54.665346643 +0200 +@@ -0,0 +1,92 @@ ++/* ++ * sndio play and grab interface ++ * Copyright (c) 2010 Jacob Meuser ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++ ++#include "avdevice.h" ++#include "sndio_common.h" ++ ++static av_cold int audio_write_header(AVFormatContext *s1) ++{ ++ SndioData *s = s1->priv_data; ++ AVStream *st; ++ int ret; ++ ++ st = s1->streams[0]; ++ s->sample_rate = st->codec->sample_rate; ++ s->channels = st->codec->channels; ++ ++ ret = ff_sndio_open(s1, 1, s1->filename); ++ ++ return ret; ++} ++ ++static int audio_write_packet(AVFormatContext *s1, AVPacket *pkt) ++{ ++ SndioData *s = s1->priv_data; ++ uint8_t *buf= pkt->data; ++ int size = pkt->size; ++ int len, ret; ++ ++ while (size > 0) { ++ len = FFMIN(s->buffer_size - s->buffer_offset, size); ++ memcpy(s->buffer + s->buffer_offset, buf, len); ++ buf += len; ++ size -= len; ++ s->buffer_offset += len; ++ if (s->buffer_offset >= s->buffer_size) { ++ ret = sio_write(s->hdl, s->buffer, s->buffer_size); ++ if (ret == 0 || sio_eof(s->hdl)) ++ return AVERROR(EIO); ++ s->softpos += ret; ++ s->buffer_offset = 0; ++ } ++ } ++ ++ return 0; ++} ++ ++static int audio_write_trailer(AVFormatContext *s1) ++{ ++ SndioData *s = s1->priv_data; ++ ++ sio_write(s->hdl, s->buffer, s->buffer_offset); ++ ++ ff_sndio_close(s); ++ ++ return 0; ++} ++ ++AVOutputFormat ff_sndio_muxer = { ++ .name = "sndio", ++ .long_name = NULL_IF_CONFIG_SMALL("sndio audio playback"), ++ .priv_data_size = sizeof(SndioData), ++ /* XXX: we make the assumption that the soundcard accepts this format */ ++ /* XXX: find better solution with "preinit" method, needed also in ++ other formats */ ++ .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), ++ .video_codec = CODEC_ID_NONE, ++ .write_header = audio_write_header, ++ .write_packet = audio_write_packet, ++ .write_trailer = audio_write_trailer, ++ .flags = AVFMT_NOFILE, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/timefilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/timefilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/timefilter.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/timefilter.c 2012-05-14 14:08:54.665346643 +0200 +@@ -0,0 +1,151 @@ ++/* ++ * Delay Locked Loop based time filter ++ * Copyright (c) 2009 Samalyse ++ * Copyright (c) 2009 Michael Niedermayer ++ * Author: Olivier Guilyardi ++ * Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++ ++#include "config.h" ++#include "timefilter.h" ++#include "libavutil/mem.h" ++ ++struct TimeFilter { ++ /// Delay Locked Loop data. These variables refer to mathematical ++ /// concepts described in: http://www.kokkinizita.net/papers/usingdll.pdf ++ double cycle_time; ++ double feedback2_factor; ++ double feedback3_factor; ++ double clock_period; ++ int count; ++}; ++ ++TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor) ++{ ++ TimeFilter *self = av_mallocz(sizeof(TimeFilter)); ++ self->clock_period = clock_period; ++ self->feedback2_factor = feedback2_factor; ++ self->feedback3_factor = feedback3_factor; ++ return self; ++} ++ ++void ff_timefilter_destroy(TimeFilter *self) ++{ ++ av_freep(&self); ++} ++ ++void ff_timefilter_reset(TimeFilter *self) ++{ ++ self->count = 0; ++} ++ ++double ff_timefilter_update(TimeFilter *self, double system_time, double period) ++{ ++ self->count++; ++ if (self->count==1) { ++ /// init loop ++ self->cycle_time = system_time; ++ } else { ++ double loop_error; ++ self->cycle_time += self->clock_period * period; ++ /// calculate loop error ++ loop_error = system_time - self->cycle_time; ++ ++ /// update loop ++ self->cycle_time += FFMAX(self->feedback2_factor, 1.0 / self->count) * loop_error; ++ self->clock_period += self->feedback3_factor * loop_error / period; ++ } ++ return self->cycle_time; ++} ++ ++#ifdef TEST ++#include "libavutil/lfg.h" ++#define LFG_MAX ((1LL << 32) - 1) ++ ++#undef printf ++ ++int main(void) ++{ ++ AVLFG prng; ++ double n0,n1; ++#define SAMPLES 1000 ++ double ideal[SAMPLES]; ++ double samples[SAMPLES]; ++#if 1 ++ for(n0= 0; n0<40; n0=2*n0+1){ ++ for(n1= 0; n1<10; n1=2*n1+1){ ++#else ++ {{ ++ n0=7; ++ n1=1; ++#endif ++ double best_error= 1000000000; ++ double bestpar0=1; ++ double bestpar1=0.001; ++ int better, i; ++ ++ av_lfg_init(&prng, 123); ++ for(i=0; i ++ * Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVDEVICE_TIMEFILTER_H ++#define AVDEVICE_TIMEFILTER_H ++ ++/** ++ * Opaque type representing a time filter state ++ * ++ * The purpose of this filter is to provide a way to compute accurate time ++ * stamps that can be compared to wall clock time, especially when dealing ++ * with two clocks: the system clock and a hardware device clock, such as ++ * a soundcard. ++ */ ++typedef struct TimeFilter TimeFilter; ++ ++ ++/** ++ * Create a new Delay Locked Loop time filter ++ * ++ * feedback2_factor and feedback3_factor are the factors used for the ++ * multiplications that are respectively performed in the second and third ++ * feedback paths of the loop. ++ * ++ * Unless you know what you are doing, you should set these as follow: ++ * ++ * o = 2 * M_PI * bandwidth * period ++ * feedback2_factor = sqrt(2 * o) ++ * feedback3_factor = o * o ++ * ++ * Where bandwidth is up to you to choose. Smaller values will filter out more ++ * of the jitter, but also take a longer time for the loop to settle. A good ++ * starting point is something between 0.3 and 3 Hz. ++ * ++ * @param clock_period period of the hardware clock in seconds ++ * (for example 1.0/44100) ++ * ++ * For more details about these parameters and background concepts please see: ++ * http://www.kokkinizita.net/papers/usingdll.pdf ++ */ ++TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor); ++ ++/** ++ * Update the filter ++ * ++ * This function must be called in real time, at each process cycle. ++ * ++ * @param period the device cycle duration in clock_periods. For example, at ++ * 44.1kHz and a buffer size of 512 frames, period = 512 when clock_period ++ * was 1.0/44100, or 512/44100 if clock_period was 1. ++ * ++ * system_time, in seconds, should be the value of the system clock time, ++ * at (or as close as possible to) the moment the device hardware interrupt ++ * occurred (or any other event the device clock raises at the beginning of a ++ * cycle). ++ * ++ * @return the filtered time, in seconds ++ */ ++double ff_timefilter_update(TimeFilter *self, double system_time, double period); ++ ++/** ++ * Reset the filter ++ * ++ * This function should mainly be called in case of XRUN. ++ * ++ * Warning: after calling this, the filter is in an undetermined state until ++ * the next call to ff_timefilter_update() ++ */ ++void ff_timefilter_reset(TimeFilter *); ++ ++/** ++ * Free all resources associated with the filter ++ */ ++void ff_timefilter_destroy(TimeFilter *); ++ ++#endif /* AVDEVICE_TIMEFILTER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/v4l2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/v4l2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/v4l2.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/v4l2.c 2012-05-14 14:08:54.671346764 +0200 +@@ -1,15 +1,7 @@ + /* +- * Video4Linux2 grab interface + * Copyright (c) 2000,2001 Fabrice Bellard + * Copyright (c) 2006 Luca Abeni + * +- * Part of this file is based on the V4L2 video capture example +- * (http://v4l2spec.bytesex.org/v4l2spec/capture.c) +- * +- * Thanks to Michael Niedermayer for providing the mapping between +- * V4L2_PIX_FMT_* and PIX_FMT_* +- * +- * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or +@@ -27,9 +19,20 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * Video4Linux2 grab interface ++ * ++ * Part of this file is based on the V4L2 video capture example ++ * (http://v4l2spec.bytesex.org/v4l2spec/capture.c) ++ * ++ * Thanks to Michael Niedermayer for providing the mapping between ++ * V4L2_PIX_FMT_* and PIX_FMT_* ++ */ ++ + #undef __STRICT_ANSI__ //workaround due to broken kernel headers + #include "config.h" +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" + #include + #include + #include +@@ -38,32 +41,57 @@ + #if HAVE_SYS_VIDEOIO_H + #include + #else ++#if HAVE_ASM_TYPES_H + #include ++#endif + #include + #endif + #include +-#include +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "avdevice.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "libavutil/avstring.h" ++ ++#if CONFIG_LIBV4L2 ++#include ++#else ++#define v4l2_open open ++#define v4l2_close close ++#define v4l2_dup dup ++#define v4l2_ioctl ioctl ++#define v4l2_read read ++#define v4l2_mmap mmap ++#define v4l2_munmap munmap ++#endif + + static const int desired_video_buffers = 256; + +-enum io_method { +- io_read, +- io_mmap, +- io_userptr +-}; ++#define V4L_ALLFORMATS 3 ++#define V4L_RAWFORMATS 1 ++#define V4L_COMPFORMATS 2 + + struct video_data { ++ AVClass *class; + int fd; + int frame_format; /* V4L2_PIX_FMT_* */ +- enum io_method io_method; + int width, height; + int frame_size; ++ int interlaced; + int top_field_first; + + int buffers; + void **buf_start; + unsigned int *buf_len; ++ char *standard; ++ int channel; ++ char *video_size; /**< String describing video size, ++ set by a private option. */ ++ char *pixel_format; /**< Set by a private option. */ ++ int list_format; /**< Set by a private option. */ ++ char *framerate; /**< Set by a private option. */ + }; + + struct buff_data { +@@ -96,75 +124,112 @@ + { PIX_FMT_NONE, CODEC_ID_MJPEG, V4L2_PIX_FMT_JPEG }, + }; + +-static int device_open(AVFormatContext *ctx, uint32_t *capabilities) ++static int device_open(AVFormatContext *ctx) + { + struct v4l2_capability cap; + int fd; ++#if CONFIG_LIBV4L2 ++ int fd_libv4l; ++#endif + int res, err; + int flags = O_RDWR; + + if (ctx->flags & AVFMT_FLAG_NONBLOCK) { + flags |= O_NONBLOCK; + } +- fd = open(ctx->filename, flags, 0); ++ ++ fd = v4l2_open(ctx->filename, flags, 0); + if (fd < 0) { ++ err = errno; ++ + av_log(ctx, AV_LOG_ERROR, "Cannot open video device %s : %s\n", +- ctx->filename, strerror(errno)); ++ ctx->filename, strerror(err)); + +- return AVERROR(errno); ++ return AVERROR(err); + } +- +- res = ioctl(fd, VIDIOC_QUERYCAP, &cap); +- // ENOIOCTLCMD definition only availble on __KERNEL__ +- if (res < 0 && ((err = errno) == 515)) { +- av_log(ctx, AV_LOG_ERROR, "QUERYCAP not implemented, probably V4L device but not supporting V4L2\n"); +- close(fd); +- +- return AVERROR(515); ++#if CONFIG_LIBV4L2 ++ fd_libv4l = v4l2_fd_open(fd, 0); ++ if (fd < 0) { ++ err = AVERROR(errno); ++ av_log(ctx, AV_LOG_ERROR, "Cannot open video device with libv4l neither %s : %s\n", ++ ctx->filename, strerror(errno)); ++ return err; + } ++ fd = fd_libv4l; ++#endif ++ ++ res = v4l2_ioctl(fd, VIDIOC_QUERYCAP, &cap); + if (res < 0) { ++ err = errno; + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYCAP): %s\n", +- strerror(errno)); +- close(fd); ++ strerror(err)); + +- return AVERROR(err); ++ goto fail; + } +- if ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) { +- av_log(ctx, AV_LOG_ERROR, "Not a video capture device\n"); +- close(fd); + +- return AVERROR(ENODEV); ++ av_log(ctx, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n", ++ fd, cap.capabilities); ++ ++ if (!(cap.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { ++ av_log(ctx, AV_LOG_ERROR, "Not a video capture device.\n"); ++ err = ENODEV; ++ ++ goto fail; ++ } ++ ++ if (!(cap.capabilities & V4L2_CAP_STREAMING)) { ++ av_log(ctx, AV_LOG_ERROR, ++ "The device does not support the streaming I/O method.\n"); ++ err = ENOSYS; ++ ++ goto fail; + } +- *capabilities = cap.capabilities; + + return fd; ++ ++fail: ++ v4l2_close(fd); ++ return AVERROR(err); + } + +-static int device_init(AVFormatContext *ctx, int *width, int *height, uint32_t pix_fmt) ++static int device_init(AVFormatContext *ctx, int *width, int *height, ++ uint32_t pix_fmt) + { + struct video_data *s = ctx->priv_data; + int fd = s->fd; +- struct v4l2_format fmt; ++ struct v4l2_format fmt = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE }; ++ struct v4l2_pix_format *pix = &fmt.fmt.pix; ++ + int res; + +- memset(&fmt, 0, sizeof(struct v4l2_format)); +- fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- fmt.fmt.pix.width = *width; +- fmt.fmt.pix.height = *height; +- fmt.fmt.pix.pixelformat = pix_fmt; +- fmt.fmt.pix.field = V4L2_FIELD_INTERLACED; +- res = ioctl(fd, VIDIOC_S_FMT, &fmt); ++ pix->width = *width; ++ pix->height = *height; ++ pix->pixelformat = pix_fmt; ++ pix->field = V4L2_FIELD_ANY; ++ ++ res = v4l2_ioctl(fd, VIDIOC_S_FMT, &fmt); ++ + if ((*width != fmt.fmt.pix.width) || (*height != fmt.fmt.pix.height)) { +- av_log(ctx, AV_LOG_INFO, "The V4L2 driver changed the video from %dx%d to %dx%d\n", *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height); ++ av_log(ctx, AV_LOG_INFO, ++ "The V4L2 driver changed the video from %dx%d to %dx%d\n", ++ *width, *height, fmt.fmt.pix.width, fmt.fmt.pix.height); + *width = fmt.fmt.pix.width; + *height = fmt.fmt.pix.height; + } + + if (pix_fmt != fmt.fmt.pix.pixelformat) { +- av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver changed the pixel format from 0x%08X to 0x%08X\n", pix_fmt, fmt.fmt.pix.pixelformat); ++ av_log(ctx, AV_LOG_DEBUG, ++ "The V4L2 driver changed the pixel format " ++ "from 0x%08X to 0x%08X\n", ++ pix_fmt, fmt.fmt.pix.pixelformat); + res = -1; + } + ++ if (fmt.fmt.pix.field == V4L2_FIELD_INTERLACED) { ++ av_log(ctx, AV_LOG_DEBUG, "The V4L2 driver using the interlaced mode"); ++ s->interlaced = 1; ++ } ++ + return res; + } + +@@ -173,7 +238,7 @@ + int res; + v4l2_std_id std; + +- res = ioctl(fd, VIDIOC_G_STD, &std); ++ res = v4l2_ioctl(fd, VIDIOC_G_STD, &std); + if (res < 0) { + return 0; + } +@@ -227,72 +292,134 @@ + return CODEC_ID_NONE; + } + ++#if HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE ++static void list_framesizes(AVFormatContext *ctx, int fd, uint32_t pixelformat) ++{ ++ struct v4l2_frmsizeenum vfse = { .pixel_format = pixelformat }; ++ ++ while(!ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &vfse)) { ++ switch (vfse.type) { ++ case V4L2_FRMSIZE_TYPE_DISCRETE: ++ av_log(ctx, AV_LOG_INFO, " %ux%u", ++ vfse.discrete.width, vfse.discrete.height); ++ break; ++ case V4L2_FRMSIZE_TYPE_CONTINUOUS: ++ case V4L2_FRMSIZE_TYPE_STEPWISE: ++ av_log(ctx, AV_LOG_INFO, " {%u-%u, %u}x{%u-%u, %u}", ++ vfse.stepwise.min_width, ++ vfse.stepwise.max_width, ++ vfse.stepwise.step_width, ++ vfse.stepwise.min_height, ++ vfse.stepwise.max_height, ++ vfse.stepwise.step_height); ++ } ++ vfse.index++; ++ } ++} ++#endif ++ ++static void list_formats(AVFormatContext *ctx, int fd, int type) ++{ ++ struct v4l2_fmtdesc vfd = { .type = V4L2_BUF_TYPE_VIDEO_CAPTURE }; ++ ++ while(!ioctl(fd, VIDIOC_ENUM_FMT, &vfd)) { ++ enum CodecID codec_id = fmt_v4l2codec(vfd.pixelformat); ++ enum PixelFormat pix_fmt = fmt_v4l2ff(vfd.pixelformat, codec_id); ++ ++ vfd.index++; ++ ++ if (!(vfd.flags & V4L2_FMT_FLAG_COMPRESSED) && ++ type & V4L_RAWFORMATS) { ++ const char *fmt_name = av_get_pix_fmt_name(pix_fmt); ++ av_log(ctx, AV_LOG_INFO, "R : %9s : %20s :", ++ fmt_name ? fmt_name : "Unsupported", ++ vfd.description); ++ } else if (vfd.flags & V4L2_FMT_FLAG_COMPRESSED && ++ type & V4L_COMPFORMATS) { ++ AVCodec *codec = avcodec_find_encoder(codec_id); ++ av_log(ctx, AV_LOG_INFO, "C : %9s : %20s :", ++ codec ? codec->name : "Unsupported", ++ vfd.description); ++ } else { ++ continue; ++ } ++ ++#ifdef V4L2_FMT_FLAG_EMULATED ++ if (vfd.flags & V4L2_FMT_FLAG_EMULATED) { ++ av_log(ctx, AV_LOG_WARNING, "%s", "Emulated"); ++ continue; ++ } ++#endif ++#if HAVE_STRUCT_V4L2_FRMIVALENUM_DISCRETE ++ list_framesizes(ctx, fd, vfd.pixelformat); ++#endif ++ av_log(ctx, AV_LOG_INFO, "\n"); ++ } ++} ++ + static int mmap_init(AVFormatContext *ctx) + { +- struct video_data *s = ctx->priv_data; +- struct v4l2_requestbuffers req; + int i, res; ++ struct video_data *s = ctx->priv_data; ++ struct v4l2_requestbuffers req = { ++ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, ++ .count = desired_video_buffers, ++ .memory = V4L2_MEMORY_MMAP ++ }; + +- memset(&req, 0, sizeof(struct v4l2_requestbuffers)); +- req.count = desired_video_buffers; +- req.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- req.memory = V4L2_MEMORY_MMAP; +- res = ioctl(s->fd, VIDIOC_REQBUFS, &req); ++ res = v4l2_ioctl(s->fd, VIDIOC_REQBUFS, &req); + if (res < 0) { + if (errno == EINVAL) { + av_log(ctx, AV_LOG_ERROR, "Device does not support mmap\n"); + } else { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_REQBUFS)\n"); + } +- + return AVERROR(errno); + } + + if (req.count < 2) { + av_log(ctx, AV_LOG_ERROR, "Insufficient buffer memory\n"); +- + return AVERROR(ENOMEM); + } + s->buffers = req.count; + s->buf_start = av_malloc(sizeof(void *) * s->buffers); + if (s->buf_start == NULL) { + av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer pointers\n"); +- + return AVERROR(ENOMEM); + } + s->buf_len = av_malloc(sizeof(unsigned int) * s->buffers); + if (s->buf_len == NULL) { + av_log(ctx, AV_LOG_ERROR, "Cannot allocate buffer sizes\n"); + av_free(s->buf_start); +- + return AVERROR(ENOMEM); + } + + for (i = 0; i < req.count; i++) { +- struct v4l2_buffer buf; +- +- memset(&buf, 0, sizeof(struct v4l2_buffer)); +- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- buf.memory = V4L2_MEMORY_MMAP; +- buf.index = i; +- res = ioctl(s->fd, VIDIOC_QUERYBUF, &buf); ++ struct v4l2_buffer buf = { ++ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, ++ .index = i, ++ .memory = V4L2_MEMORY_MMAP ++ }; ++ res = v4l2_ioctl(s->fd, VIDIOC_QUERYBUF, &buf); + if (res < 0) { + av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QUERYBUF)\n"); +- + return AVERROR(errno); + } + + s->buf_len[i] = buf.length; + if (s->frame_size > 0 && s->buf_len[i] < s->frame_size) { +- av_log(ctx, AV_LOG_ERROR, "Buffer len [%d] = %d != %d\n", i, s->buf_len[i], s->frame_size); ++ av_log(ctx, AV_LOG_ERROR, ++ "Buffer len [%d] = %d != %d\n", ++ i, s->buf_len[i], s->frame_size); + + return -1; + } +- s->buf_start[i] = mmap (NULL, buf.length, +- PROT_READ | PROT_WRITE, MAP_SHARED, s->fd, buf.m.offset); ++ s->buf_start[i] = v4l2_mmap(NULL, buf.length, ++ PROT_READ | PROT_WRITE, MAP_SHARED, ++ s->fd, buf.m.offset); ++ + if (s->buf_start[i] == MAP_FAILED) { + av_log(ctx, AV_LOG_ERROR, "mmap: %s\n", strerror(errno)); +- + return AVERROR(errno); + } + } +@@ -300,32 +427,26 @@ + return 0; + } + +-static int read_init(AVFormatContext *ctx) +-{ +- return -1; +-} +- + static void mmap_release_buffer(AVPacket *pkt) + { +- struct v4l2_buffer buf; ++ struct v4l2_buffer buf = { 0 }; + int res, fd; + struct buff_data *buf_descriptor = pkt->priv; + +- if (pkt->data == NULL) { +- return; +- } ++ if (pkt->data == NULL) ++ return; + +- memset(&buf, 0, sizeof(struct v4l2_buffer)); + buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + buf.memory = V4L2_MEMORY_MMAP; + buf.index = buf_descriptor->index; + fd = buf_descriptor->fd; + av_free(buf_descriptor); + +- res = ioctl(fd, VIDIOC_QBUF, &buf); +- if (res < 0) { +- av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno)); +- } ++ res = v4l2_ioctl(fd, VIDIOC_QBUF, &buf); ++ if (res < 0) ++ av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", ++ strerror(errno)); ++ + pkt->data = NULL; + pkt->size = 0; + } +@@ -333,29 +454,30 @@ + static int mmap_read_frame(AVFormatContext *ctx, AVPacket *pkt) + { + struct video_data *s = ctx->priv_data; +- struct v4l2_buffer buf; ++ struct v4l2_buffer buf = { ++ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, ++ .memory = V4L2_MEMORY_MMAP ++ }; + struct buff_data *buf_descriptor; + int res; + +- memset(&buf, 0, sizeof(struct v4l2_buffer)); +- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- buf.memory = V4L2_MEMORY_MMAP; +- + /* FIXME: Some special treatment might be needed in case of loss of signal... */ +- while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR)); ++ while ((res = v4l2_ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 && (errno == EINTR)); + if (res < 0) { + if (errno == EAGAIN) { + pkt->size = 0; +- + return AVERROR(EAGAIN); + } +- av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno)); ++ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", ++ strerror(errno)); + + return AVERROR(errno); + } +- assert (buf.index < s->buffers); ++ assert(buf.index < s->buffers); + if (s->frame_size > 0 && buf.bytesused != s->frame_size) { +- av_log(ctx, AV_LOG_ERROR, "The v4l2 frame is %d bytes, but %d bytes are expected\n", buf.bytesused, s->frame_size); ++ av_log(ctx, AV_LOG_ERROR, ++ "The v4l2 frame is %d bytes, but %d bytes are expected\n", ++ buf.bytesused, s->frame_size); + + return AVERROR_INVALIDDATA; + } +@@ -371,7 +493,7 @@ + * allocate a buffer for memcopying into it + */ + av_log(ctx, AV_LOG_ERROR, "Failed to allocate a buffer descriptor\n"); +- res = ioctl(s->fd, VIDIOC_QBUF, &buf); ++ res = v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf); + + return AVERROR(ENOMEM); + } +@@ -382,11 +504,6 @@ + return s->buf_len[buf.index]; + } + +-static int read_frame(AVFormatContext *ctx, AVPacket *pkt) +-{ +- return -1; +-} +- + static int mmap_start(AVFormatContext *ctx) + { + struct video_data *s = ctx->priv_data; +@@ -394,25 +511,26 @@ + int i, res; + + for (i = 0; i < s->buffers; i++) { +- struct v4l2_buffer buf; +- +- memset(&buf, 0, sizeof(struct v4l2_buffer)); +- buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- buf.memory = V4L2_MEMORY_MMAP; +- buf.index = i; ++ struct v4l2_buffer buf = { ++ .type = V4L2_BUF_TYPE_VIDEO_CAPTURE, ++ .index = i, ++ .memory = V4L2_MEMORY_MMAP ++ }; + +- res = ioctl(s->fd, VIDIOC_QBUF, &buf); ++ res = v4l2_ioctl(s->fd, VIDIOC_QBUF, &buf); + if (res < 0) { +- av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", strerror(errno)); ++ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF): %s\n", ++ strerror(errno)); + + return AVERROR(errno); + } + } + + type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- res = ioctl(s->fd, VIDIOC_STREAMON, &type); ++ res = v4l2_ioctl(s->fd, VIDIOC_STREAMON, &type); + if (res < 0) { +- av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", strerror(errno)); ++ av_log(ctx, AV_LOG_ERROR, "ioctl(VIDIOC_STREAMON): %s\n", ++ strerror(errno)); + + return AVERROR(errno); + } +@@ -429,9 +547,9 @@ + /* We do not check for the result, because we could + * not do anything about it anyway... + */ +- ioctl(s->fd, VIDIOC_STREAMOFF, &type); ++ v4l2_ioctl(s->fd, VIDIOC_STREAMOFF, &type); + for (i = 0; i < s->buffers; i++) { +- munmap(s->buf_start[i], s->buf_len[i]); ++ v4l2_munmap(s->buf_start[i], s->buf_len[i]); + } + av_free(s->buf_start); + av_free(s->buf_len); +@@ -440,98 +558,105 @@ + static int v4l2_set_parameters(AVFormatContext *s1, AVFormatParameters *ap) + { + struct video_data *s = s1->priv_data; +- struct v4l2_input input; +- struct v4l2_standard standard; ++ struct v4l2_input input = { 0 }; ++ struct v4l2_standard standard = { 0 }; + struct v4l2_streamparm streamparm = { 0 }; + struct v4l2_fract *tpf = &streamparm.parm.capture.timeperframe; +- int i; ++ AVRational framerate_q = { 0 }; ++ int i, ret; + + streamparm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + +- if (ap->channel>=0) { +- /* set tv video input */ +- memset (&input, 0, sizeof (input)); +- input.index = ap->channel; +- if (ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) { +- av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n"); +- return AVERROR(EIO); +- } ++ if (s->framerate && ++ (ret = av_parse_video_rate(&framerate_q, s->framerate)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ++ s->framerate); ++ return ret; ++ } + +- av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", +- ap->channel, input.name); +- if (ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) { +- av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set input(%d) failed\n", +- ap->channel); +- return AVERROR(EIO); +- } ++ /* set tv video input */ ++ input.index = s->channel; ++ if (v4l2_ioctl(s->fd, VIDIOC_ENUMINPUT, &input) < 0) { ++ av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl enum input failed:\n"); ++ return AVERROR(EIO); + } + +- if (ap->standard) { ++ av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set input_id: %d, input: %s\n", ++ s->channel, input.name); ++ if (v4l2_ioctl(s->fd, VIDIOC_S_INPUT, &input.index) < 0) { ++ av_log(s1, AV_LOG_ERROR, ++ "The V4L2 driver ioctl set input(%d) failed\n", ++ s->channel); ++ return AVERROR(EIO); ++ } ++ ++ if (s->standard) { + av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s\n", +- ap->standard); ++ s->standard); + /* set tv standard */ +- memset (&standard, 0, sizeof (standard)); + for(i=0;;i++) { + standard.index = i; +- if (ioctl(s->fd, VIDIOC_ENUMSTD, &standard) < 0) { +- av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", +- ap->standard); +- return AVERROR(EIO); +- } +- +- if (!strcasecmp(standard.name, ap->standard)) { ++ ret = v4l2_ioctl(s->fd, VIDIOC_ENUMSTD, &standard); ++ if (ret < 0 || !av_strcasecmp(standard.name, s->standard)) + break; +- } ++ } ++ if (ret < 0) { ++ av_log(s1, AV_LOG_ERROR, "Unknown standard '%s'\n", s->standard); ++ return ret; + } + +- av_log(s1, AV_LOG_DEBUG, "The V4L2 driver set standard: %s, id: %"PRIu64"\n", +- ap->standard, (uint64_t)standard.id); +- if (ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) { +- av_log(s1, AV_LOG_ERROR, "The V4L2 driver ioctl set standard(%s) failed\n", +- ap->standard); ++ av_log(s1, AV_LOG_DEBUG, ++ "The V4L2 driver set standard: %s, id: %"PRIu64"\n", ++ s->standard, (uint64_t)standard.id); ++ if (v4l2_ioctl(s->fd, VIDIOC_S_STD, &standard.id) < 0) { ++ av_log(s1, AV_LOG_ERROR, ++ "The V4L2 driver ioctl set standard(%s) failed\n", ++ s->standard); + return AVERROR(EIO); + } + } + +- if (ap->time_base.num && ap->time_base.den) { ++ if (framerate_q.num && framerate_q.den) { + av_log(s1, AV_LOG_DEBUG, "Setting time per frame to %d/%d\n", +- ap->time_base.num, ap->time_base.den); +- tpf->numerator = ap->time_base.num; +- tpf->denominator = ap->time_base.den; +- if (ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) { ++ framerate_q.den, framerate_q.num); ++ tpf->numerator = framerate_q.den; ++ tpf->denominator = framerate_q.num; ++ ++ if (v4l2_ioctl(s->fd, VIDIOC_S_PARM, &streamparm) != 0) { + av_log(s1, AV_LOG_ERROR, + "ioctl set time per frame(%d/%d) failed\n", +- ap->time_base.num, ap->time_base.den); ++ framerate_q.den, framerate_q.num); + return AVERROR(EIO); + } + +- if (ap->time_base.den != tpf->denominator || +- ap->time_base.num != tpf->numerator) { ++ if (framerate_q.num != tpf->denominator || ++ framerate_q.den != tpf->numerator) { + av_log(s1, AV_LOG_INFO, +- "The driver changed the time per frame from %d/%d to %d/%d\n", +- ap->time_base.num, ap->time_base.den, ++ "The driver changed the time per frame from " ++ "%d/%d to %d/%d\n", ++ framerate_q.den, framerate_q.num, + tpf->numerator, tpf->denominator); + } + } else { +- /* if timebase value is not set in ap, read the timebase value from the driver */ +- if (ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) { +- av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n", strerror(errno)); ++ if (v4l2_ioctl(s->fd, VIDIOC_G_PARM, &streamparm) != 0) { ++ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_PARM): %s\n", ++ strerror(errno)); + return AVERROR(errno); + } + } +- ap->time_base.num = tpf->numerator; +- ap->time_base.den = tpf->denominator; ++ s1->streams[0]->codec->time_base.den = tpf->denominator; ++ s1->streams[0]->codec->time_base.num = tpf->numerator; + + return 0; + } + + static uint32_t device_try_init(AVFormatContext *s1, +- const AVFormatParameters *ap, ++ enum PixelFormat pix_fmt, + int *width, + int *height, + enum CodecID *codec_id) + { +- uint32_t desired_format = fmt_ff2v4l(ap->pix_fmt, s1->video_codec_id); ++ uint32_t desired_format = fmt_ff2v4l(pix_fmt, s1->video_codec_id); + + if (desired_format == 0 || + device_init(s1, width, height, desired_format) < 0) { +@@ -549,6 +674,7 @@ + } + } + } ++ + if (desired_format != 0) { + *codec_id = fmt_v4l2codec(desired_format); + assert(*codec_id != CODEC_ID_NONE); +@@ -561,108 +687,131 @@ + { + struct video_data *s = s1->priv_data; + AVStream *st; +- int res; +- uint32_t desired_format, capabilities; ++ int res = 0; ++ uint32_t desired_format; + enum CodecID codec_id; ++ enum PixelFormat pix_fmt = PIX_FMT_NONE; + +- st = av_new_stream(s1, 0); ++ st = avformat_new_stream(s1, NULL); + if (!st) { +- return AVERROR(ENOMEM); ++ res = AVERROR(ENOMEM); ++ goto out; + } +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ +- +- s->width = ap->width; +- s->height = ap->height; + +- capabilities = 0; +- s->fd = device_open(s1, &capabilities); ++ s->fd = device_open(s1); + if (s->fd < 0) { +- return AVERROR(EIO); ++ res = s->fd; ++ goto out; ++ } ++ ++ if (s->list_format) { ++ list_formats(s1, s->fd, s->list_format); ++ res = AVERROR_EXIT; ++ goto out; ++ } ++ ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ ++ if (s->video_size && ++ (res = av_parse_video_size(&s->width, &s->height, s->video_size)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Could not parse video size '%s'.\n", ++ s->video_size); ++ goto out; ++ } ++ ++ if (s->pixel_format) { ++ AVCodec *codec = avcodec_find_decoder_by_name(s->pixel_format); ++ ++ if (codec) ++ s1->video_codec_id = codec->id; ++ ++ pix_fmt = av_get_pix_fmt(s->pixel_format); ++ ++ if (pix_fmt == PIX_FMT_NONE && !codec) { ++ av_log(s1, AV_LOG_ERROR, "No such input format: %s.\n", ++ s->pixel_format); ++ ++ res = AVERROR(EINVAL); ++ goto out; ++ } + } +- av_log(s1, AV_LOG_VERBOSE, "[%d]Capabilities: %x\n", s->fd, capabilities); + + if (!s->width && !s->height) { + struct v4l2_format fmt; + +- av_log(s1, AV_LOG_VERBOSE, "Querying the device for the current frame size\n"); ++ av_log(s1, AV_LOG_VERBOSE, ++ "Querying the device for the current frame size\n"); + fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; +- if (ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { +- av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", strerror(errno)); +- return AVERROR(errno); ++ if (v4l2_ioctl(s->fd, VIDIOC_G_FMT, &fmt) < 0) { ++ av_log(s1, AV_LOG_ERROR, "ioctl(VIDIOC_G_FMT): %s\n", ++ strerror(errno)); ++ res = AVERROR(errno); ++ goto out; + } ++ + s->width = fmt.fmt.pix.width; + s->height = fmt.fmt.pix.height; +- av_log(s1, AV_LOG_VERBOSE, "Setting frame size to %dx%d\n", s->width, s->height); ++ av_log(s1, AV_LOG_VERBOSE, ++ "Setting frame size to %dx%d\n", s->width, s->height); + } + +- desired_format = device_try_init(s1, ap, &s->width, &s->height, &codec_id); ++ desired_format = device_try_init(s1, pix_fmt, &s->width, &s->height, ++ &codec_id); + if (desired_format == 0) { + av_log(s1, AV_LOG_ERROR, "Cannot find a proper format for " +- "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, ap->pix_fmt); +- close(s->fd); ++ "codec_id %d, pix_fmt %d.\n", s1->video_codec_id, pix_fmt); ++ v4l2_close(s->fd); + +- return AVERROR(EIO); ++ res = AVERROR(EIO); ++ goto out; + } +- if (av_image_check_size(s->width, s->height, 0, s1) < 0) +- return AVERROR(EINVAL); ++ if ((res = av_image_check_size(s->width, s->height, 0, s1)) < 0) ++ goto out; ++ + s->frame_format = desired_format; + +- if (v4l2_set_parameters(s1, ap) < 0) +- return AVERROR(EIO); ++ if ((res = v4l2_set_parameters(s1, ap)) < 0) ++ goto out; + + st->codec->pix_fmt = fmt_v4l2ff(desired_format, codec_id); +- s->frame_size = avpicture_get_size(st->codec->pix_fmt, s->width, s->height); +- if (capabilities & V4L2_CAP_STREAMING) { +- s->io_method = io_mmap; +- res = mmap_init(s1); +- if (res == 0) { +- res = mmap_start(s1); +- } +- } else { +- s->io_method = io_read; +- res = read_init(s1); +- } +- if (res < 0) { +- close(s->fd); ++ s->frame_size = ++ avpicture_get_size(st->codec->pix_fmt, s->width, s->height); + +- return AVERROR(EIO); ++ if ((res = mmap_init(s1)) || ++ (res = mmap_start(s1)) < 0) { ++ v4l2_close(s->fd); ++ goto out; + } ++ + s->top_field_first = first_field(s->fd); + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = codec_id; ++ if (codec_id == CODEC_ID_RAWVIDEO) ++ st->codec->codec_tag = ++ avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); + st->codec->width = s->width; + st->codec->height = s->height; +- st->codec->time_base.den = ap->time_base.den; +- st->codec->time_base.num = ap->time_base.num; + st->codec->bit_rate = s->frame_size * 1/av_q2d(st->codec->time_base) * 8; + +- return 0; ++out: ++ return res; + } + + static int v4l2_read_packet(AVFormatContext *s1, AVPacket *pkt) + { + struct video_data *s = s1->priv_data; ++ AVFrame *frame = s1->streams[0]->codec->coded_frame; + int res; + +- if (s->io_method == io_mmap) { +- av_init_packet(pkt); +- res = mmap_read_frame(s1, pkt); +- } else if (s->io_method == io_read) { +- if (av_new_packet(pkt, s->frame_size) < 0) +- return AVERROR(EIO); +- +- res = read_frame(s1, pkt); +- } else { +- return AVERROR(EIO); +- } +- if (res < 0) { ++ av_init_packet(pkt); ++ if ((res = mmap_read_frame(s1, pkt)) < 0) { + return res; + } + +- if (s1->streams[0]->codec->coded_frame) { +- s1->streams[0]->codec->coded_frame->interlaced_frame = 1; +- s1->streams[0]->codec->coded_frame->top_field_first = s->top_field_first; ++ if (frame && s->interlaced) { ++ frame->interlaced_frame = 1; ++ frame->top_field_first = s->top_field_first; + } + + return pkt->size; +@@ -672,21 +821,43 @@ + { + struct video_data *s = s1->priv_data; + +- if (s->io_method == io_mmap) { +- mmap_close(s); +- } ++ mmap_close(s); + +- close(s->fd); ++ v4l2_close(s->fd); + return 0; + } + ++#define OFFSET(x) offsetof(struct video_data, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++ ++static const AVOption options[] = { ++ { "standard", "TV standard, used only by analog frame grabber", OFFSET(standard), AV_OPT_TYPE_STRING, {.str = NULL }, 0, 0, DEC }, ++ { "channel", "TV channel, used only by frame grabber", OFFSET(channel), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, DEC }, ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "pixel_format", "Preferred pixel format", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "input_format", "Preferred pixel format (for raw video) or codec name", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "list_formats", "List available formats and exit", OFFSET(list_format), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX, DEC, "list_formats" }, ++ { "all", "Show all available formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.dbl = V4L_ALLFORMATS }, 0, INT_MAX, DEC, "list_formats" }, ++ { "raw", "Show only non-compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.dbl = V4L_RAWFORMATS }, 0, INT_MAX, DEC, "list_formats" }, ++ { "compressed", "Show only compressed formats", OFFSET(list_format), AV_OPT_TYPE_CONST, {.dbl = V4L_COMPFORMATS }, 0, INT_MAX, DEC, "list_formats" }, ++ { NULL }, ++}; ++ ++static const AVClass v4l2_class = { ++ .class_name = "V4L2 indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_v4l2_demuxer = { +- "video4linux2", +- NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"), +- sizeof(struct video_data), +- NULL, +- v4l2_read_header, +- v4l2_read_packet, +- v4l2_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "video4linux2,v4l2", ++ .long_name = NULL_IF_CONFIG_SMALL("Video4Linux2 device grab"), ++ .priv_data_size = sizeof(struct video_data), ++ .read_header = v4l2_read_header, ++ .read_packet = v4l2_read_packet, ++ .read_close = v4l2_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &v4l2_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/v4l.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/v4l.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/v4l.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/v4l.c 2012-05-14 14:08:54.667346683 +0200 +@@ -19,11 +19,15 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "avdevice.h" ++ + #undef __STRICT_ANSI__ //workaround due to broken kernel headers + #include "config.h" + #include "libavutil/rational.h" +-#include "libavcore/imgutils.h" +-#include "libavformat/avformat.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavformat/internal.h" + #include "libavcodec/dsputil.h" + #include + #include +@@ -33,9 +37,10 @@ + #define _LINUX_TIME_H 1 + #include + #include +-#include ++#include "avdevice.h" + + typedef struct { ++ AVClass *class; + int fd; + int frame_format; /* see VIDEO_PALETTE_xxx */ + int use_mmap; +@@ -49,6 +54,7 @@ + struct video_mbuf gb_buffers; + struct video_mmap gb_buf; + int gb_frame; ++ int standard; + } VideoData; + + static const struct { +@@ -79,6 +85,8 @@ + int j; + int vformat_num = FF_ARRAY_ELEMS(video_formats); + ++ av_log(s1, AV_LOG_WARNING, "V4L input device is deprecated and will be removed in the next release."); ++ + if (ap->time_base.den <= 0) { + av_log(s1, AV_LOG_ERROR, "Wrong time base (%d)\n", ap->time_base.den); + return -1; +@@ -88,10 +96,10 @@ + s->video_win.width = ap->width; + s->video_win.height = ap->height; + +- st = av_new_stream(s1, 0); ++ st = avformat_new_stream(s1, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + + video_fd = open(s1->filename, O_RDWR); + if (video_fd < 0) { +@@ -131,13 +139,8 @@ + } + + /* set tv standard */ +- if (ap->standard && !ioctl(video_fd, VIDIOCGTUNER, &tuner)) { +- if (!strcasecmp(ap->standard, "pal")) +- tuner.mode = VIDEO_MODE_PAL; +- else if (!strcasecmp(ap->standard, "secam")) +- tuner.mode = VIDEO_MODE_SECAM; +- else +- tuner.mode = VIDEO_MODE_NTSC; ++ if (!ioctl(video_fd, VIDIOCGTUNER, &tuner)) { ++ tuner.mode = s->standard; + ioctl(video_fd, VIDIOCSTUNER, &tuner); + } + +@@ -149,14 +152,8 @@ + ioctl(video_fd, VIDIOCSAUDIO, &audio); + + ioctl(video_fd, VIDIOCGPICT, &pict); +-#if 0 +- printf("v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n", +- pict.colour, +- pict.hue, +- pict.brightness, +- pict.contrast, +- pict.whiteness); +-#endif ++ av_dlog(s1, "v4l: colour=%d hue=%d brightness=%d constrast=%d whiteness=%d\n", ++ pict.colour, pict.hue, pict.brightness, pict.contrast, pict.whiteness); + /* try to choose a suitable video format */ + pict.palette = desired_palette; + pict.depth= desired_depth; +@@ -339,13 +336,28 @@ + return 0; + } + ++static const AVOption options[] = { ++ { "standard", "", offsetof(VideoData, standard), AV_OPT_TYPE_INT, {.dbl = VIDEO_MODE_NTSC}, VIDEO_MODE_PAL, VIDEO_MODE_NTSC, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "PAL", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_PAL}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "SECAM", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_SECAM}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { "NTSC", "", 0, AV_OPT_TYPE_CONST, {.dbl = VIDEO_MODE_NTSC}, 0, 0, AV_OPT_FLAG_DECODING_PARAM, "standard" }, ++ { NULL }, ++}; ++ ++static const AVClass v4l_class = { ++ .class_name = "V4L indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_v4l_demuxer = { +- "video4linux", +- NULL_IF_CONFIG_SMALL("Video4Linux device grab"), +- sizeof(VideoData), +- NULL, +- grab_read_header, +- grab_read_packet, +- grab_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "video4linux,v4l", ++ .long_name = NULL_IF_CONFIG_SMALL("Video4Linux device grab"), ++ .priv_data_size = sizeof(VideoData), ++ .read_header = grab_read_header, ++ .read_packet = grab_read_packet, ++ .read_close = grab_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &v4l_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/vfwcap.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/vfwcap.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/vfwcap.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/vfwcap.c 2012-05-14 14:08:54.672346784 +0200 +@@ -19,27 +19,30 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" + #include + #include +- +-//#define DEBUG_VFW ++#include "avdevice.h" + + /* Defines for VFW missing from MinGW. + * Remove this when MinGW incorporates them. */ + #define HWND_MESSAGE ((HWND)-3) + +-#define BI_RGB 0 +- + /* End of missing MinGW defines */ + + struct vfw_ctx { ++ const AVClass *class; + HWND hwnd; + HANDLE mutex; + HANDLE event; + AVPacketList *pktl; + unsigned int curbufsize; + unsigned int frame_num; ++ char *video_size; /**< A string describing video size, set by a private option. */ ++ char *framerate; /**< Set by a private option. */ + }; + + static enum PixelFormat vfw_pixfmt(DWORD biCompression, WORD biBitCount) +@@ -116,7 +119,7 @@ + + static void dump_videohdr(AVFormatContext *s, VIDEOHDR *vhdr) + { +-#ifdef DEBUG_VFW ++#ifdef DEBUG + av_log(s, AV_LOG_DEBUG, "VIDEOHDR\n"); + dstruct(s, vhdr, lpData, "p"); + dstruct(s, vhdr, dwBufferLength, "lu"); +@@ -240,13 +243,12 @@ + AVStream *st; + int devnum; + int bisize; +- BITMAPINFO *bi; ++ BITMAPINFO *bi = NULL; + CAPTUREPARMS cparms; + DWORD biCompression; + WORD biBitCount; +- int width; +- int height; + int ret; ++ AVRational framerate_q; + + if (!strcmp(s->filename, "list")) { + for (devnum = 0; devnum <= 9; devnum++) { +@@ -264,11 +266,6 @@ + return AVERROR(EIO); + } + +- if(!ap->time_base.den) { +- av_log(s, AV_LOG_ERROR, "A time base must be specified.\n"); +- return AVERROR(EIO); +- } +- + ctx->hwnd = capCreateCaptureWindow(NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, 0); + if(!ctx->hwnd) { + av_log(s, AV_LOG_ERROR, "Could not create capture window.\n"); +@@ -292,12 +289,12 @@ + (LPARAM) videostream_cb); + if(!ret) { + av_log(s, AV_LOG_ERROR, "Could not set video stream callback.\n"); +- goto fail_io; ++ goto fail; + } + + SetWindowLongPtr(ctx->hwnd, GWLP_USERDATA, (LONG_PTR) s); + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if(!st) { + vfw_read_close(s); + return AVERROR(ENOMEM); +@@ -306,7 +303,7 @@ + /* Set video format */ + bisize = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, 0, 0); + if(!bisize) +- goto fail_io; ++ goto fail; + bi = av_malloc(bisize); + if(!bi) { + vfw_read_close(s); +@@ -314,14 +311,23 @@ + } + ret = SendMessage(ctx->hwnd, WM_CAP_GET_VIDEOFORMAT, bisize, (LPARAM) bi); + if(!ret) +- goto fail_bi; ++ goto fail; + + dump_bih(s, &bi->bmiHeader); + +- width = ap->width ? ap->width : bi->bmiHeader.biWidth ; +- height = ap->height ? ap->height : bi->bmiHeader.biHeight; +- bi->bmiHeader.biWidth = width ; +- bi->bmiHeader.biHeight = height; ++ ret = av_parse_video_rate(&framerate_q, ctx->framerate); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "Could not parse framerate '%s'.\n", ctx->framerate); ++ goto fail; ++ } ++ ++ if (ctx->video_size) { ++ ret = av_parse_video_size(&bi->bmiHeader.biWidth, &bi->bmiHeader.biHeight, ctx->video_size); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); ++ goto fail; ++ } ++ } + + if (0) { + /* For testing yet unsupported compressions +@@ -338,25 +344,23 @@ + ret = SendMessage(ctx->hwnd, WM_CAP_SET_VIDEOFORMAT, bisize, (LPARAM) bi); + if(!ret) { + av_log(s, AV_LOG_ERROR, "Could not set Video Format.\n"); +- goto fail_bi; ++ goto fail; + } + + biCompression = bi->bmiHeader.biCompression; + biBitCount = bi->bmiHeader.biBitCount; + +- av_free(bi); +- + /* Set sequence setup */ + ret = SendMessage(ctx->hwnd, WM_CAP_GET_SEQUENCE_SETUP, sizeof(cparms), + (LPARAM) &cparms); + if(!ret) +- goto fail_io; ++ goto fail; + + dump_captureparms(s, &cparms); + + cparms.fYield = 1; // Spawn a background thread + cparms.dwRequestMicroSecPerFrame = +- (ap->time_base.num*1000000) / ap->time_base.den; ++ (framerate_q.den*1000000) / framerate_q.num; + cparms.fAbortLeftMouse = 0; + cparms.fAbortRightMouse = 0; + cparms.fCaptureAudio = 0; +@@ -365,13 +369,13 @@ + ret = SendMessage(ctx->hwnd, WM_CAP_SET_SEQUENCE_SETUP, sizeof(cparms), + (LPARAM) &cparms); + if(!ret) +- goto fail_io; ++ goto fail; + + codec = st->codec; +- codec->time_base = ap->time_base; ++ codec->time_base = (AVRational){framerate_q.den, framerate_q.num}; + codec->codec_type = AVMEDIA_TYPE_VIDEO; +- codec->width = width; +- codec->height = height; ++ codec->width = bi->bmiHeader.biWidth; ++ codec->height = bi->bmiHeader.biHeight; + codec->pix_fmt = vfw_pixfmt(biCompression, biBitCount); + if(codec->pix_fmt == PIX_FMT_NONE) { + codec->codec_id = vfw_codecid(biCompression); +@@ -394,31 +398,31 @@ + } + } + +- av_set_pts_info(st, 32, 1, 1000); ++ av_freep(&bi); ++ ++ avpriv_set_pts_info(st, 32, 1, 1000); + + ctx->mutex = CreateMutex(NULL, 0, NULL); + if(!ctx->mutex) { + av_log(s, AV_LOG_ERROR, "Could not create Mutex.\n" ); +- goto fail_io; ++ goto fail; + } + ctx->event = CreateEvent(NULL, 1, 0, NULL); + if(!ctx->event) { + av_log(s, AV_LOG_ERROR, "Could not create Event.\n" ); +- goto fail_io; ++ goto fail; + } + + ret = SendMessage(ctx->hwnd, WM_CAP_SEQUENCE_NOFILE, 0, 0); + if(!ret) { + av_log(s, AV_LOG_ERROR, "Could not start capture sequence.\n" ); +- goto fail_io; ++ goto fail; + } + + return 0; + +-fail_bi: +- av_free(bi); +- +-fail_io: ++fail: ++ av_freep(&bi); + vfw_read_close(s); + return AVERROR(EIO); + } +@@ -452,13 +456,28 @@ + return pkt->size; + } + ++#define OFFSET(x) offsetof(struct vfw_ctx, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass vfw_class = { ++ .class_name = "VFW indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_vfwcap_demuxer = { +- "vfwcap", +- NULL_IF_CONFIG_SMALL("VFW video capture"), +- sizeof(struct vfw_ctx), +- NULL, +- vfw_read_header, +- vfw_read_packet, +- vfw_read_close, +- .flags = AVFMT_NOFILE, ++ .name = "vfwcap", ++ .long_name = NULL_IF_CONFIG_SMALL("VfW video capture"), ++ .priv_data_size = sizeof(struct vfw_ctx), ++ .read_header = vfw_read_header, ++ .read_packet = vfw_read_packet, ++ .read_close = vfw_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &vfw_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/x11grab.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/x11grab.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavdevice/x11grab.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavdevice/x11grab.c 2012-05-14 14:08:54.674346824 +0200 +@@ -31,14 +31,16 @@ + + /** + * @file +- * X11 frame device demuxer by Clemens Fruhwirth +- * and Edouard Gomez . ++ * X11 frame device demuxer ++ * @author Clemens Fruhwirth ++ * @author Edouard Gomez + */ + +-#define _XOPEN_SOURCE 600 +- + #include "config.h" +-#include "libavformat/avformat.h" ++#include "libavformat/internal.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" + #include + #include + #include +@@ -46,18 +48,22 @@ + #include + #include + #include ++#include + #include + #include ++#include "avdevice.h" + + /** + * X11 Device Demuxer context + */ + struct x11_grab + { ++ const AVClass *class; /**< Class for private options. */ + int frame_size; /**< Size in bytes of a grabbed frame */ + AVRational time_base; /**< Time base */ + int64_t time_frame; /**< Current time */ + ++ char *video_size; /**< String describing video size, set by a private option. */ + int height; /**< Height of the grab frame */ + int width; /**< Width of the grab frame */ + int x_off; /**< Horizontal top-left corner coordinate */ +@@ -67,9 +73,75 @@ + XImage *image; /**< X11 image holding the grab */ + int use_shm; /**< !0 when using XShm extension */ + XShmSegmentInfo shminfo; /**< When using XShm, keeps track of XShm infos */ +- int nomouse; ++ int draw_mouse; /**< Set by a private option. */ ++ int follow_mouse; /**< Set by a private option. */ ++ int show_region; /**< set by a private option. */ ++ char *framerate; /**< Set by a private option. */ ++ ++ Window region_win; /**< This is used by show_region option. */ + }; + ++#define REGION_WIN_BORDER 3 ++/** ++ * Draw grabbing region window ++ * ++ * @param s x11_grab context ++ */ ++static void ++x11grab_draw_region_win(struct x11_grab *s) ++{ ++ Display *dpy = s->dpy; ++ int screen; ++ Window win = s->region_win; ++ GC gc; ++ ++ screen = DefaultScreen(dpy); ++ gc = XCreateGC(dpy, win, 0, 0); ++ XSetForeground(dpy, gc, WhitePixel(dpy, screen)); ++ XSetBackground(dpy, gc, BlackPixel(dpy, screen)); ++ XSetLineAttributes(dpy, gc, REGION_WIN_BORDER, LineDoubleDash, 0, 0); ++ XDrawRectangle(dpy, win, gc, ++ 1, 1, ++ (s->width + REGION_WIN_BORDER * 2) - 1 * 2 - 1, ++ (s->height + REGION_WIN_BORDER * 2) - 1 * 2 - 1); ++ XFreeGC(dpy, gc); ++} ++ ++/** ++ * Initialize grabbing region window ++ * ++ * @param s x11_grab context ++ */ ++static void ++x11grab_region_win_init(struct x11_grab *s) ++{ ++ Display *dpy = s->dpy; ++ int screen; ++ XSetWindowAttributes attribs; ++ XRectangle rect; ++ ++ screen = DefaultScreen(dpy); ++ attribs.override_redirect = True; ++ s->region_win = XCreateWindow(dpy, RootWindow(dpy, screen), ++ s->x_off - REGION_WIN_BORDER, ++ s->y_off - REGION_WIN_BORDER, ++ s->width + REGION_WIN_BORDER * 2, ++ s->height + REGION_WIN_BORDER * 2, ++ 0, CopyFromParent, ++ InputOutput, CopyFromParent, ++ CWOverrideRedirect, &attribs); ++ rect.x = 0; ++ rect.y = 0; ++ rect.width = s->width; ++ rect.height = s->height; ++ XShapeCombineRectangles(dpy, s->region_win, ++ ShapeBounding, REGION_WIN_BORDER, REGION_WIN_BORDER, ++ &rect, 1, ShapeSubtract, 0); ++ XMapWindow(dpy, s->region_win); ++ XSelectInput(dpy, s->region_win, ExposureMask | StructureNotifyMask); ++ x11grab_draw_region_win(s); ++} ++ + /** + * Initialize the x11 grab device demuxer (public device demuxer API). + * +@@ -91,38 +163,64 @@ + XImage *image; + int x_off = 0; + int y_off = 0; ++ int screen; + int use_shm; +- char *param, *offset; ++ char *dpyname, *offset; ++ int ret = 0; ++ AVRational framerate; + +- param = av_strdup(s1->filename); +- offset = strchr(param, '+'); ++ dpyname = av_strdup(s1->filename); ++ offset = strchr(dpyname, '+'); + if (offset) { + sscanf(offset, "%d,%d", &x_off, &y_off); +- x11grab->nomouse= strstr(offset, "nomouse"); ++ x11grab->draw_mouse = !strstr(offset, "nomouse"); + *offset= 0; + } + +- av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", s1->filename, param, x_off, y_off, ap->width, ap->height); ++ if ((ret = av_parse_video_size(&x11grab->width, &x11grab->height, x11grab->video_size)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Couldn't parse video size.\n"); ++ goto out; ++ } ++ if ((ret = av_parse_video_rate(&framerate, x11grab->framerate)) < 0) { ++ av_log(s1, AV_LOG_ERROR, "Could not parse framerate: %s.\n", x11grab->framerate); ++ goto out; ++ } ++ av_log(s1, AV_LOG_INFO, "device: %s -> display: %s x: %d y: %d width: %d height: %d\n", ++ s1->filename, dpyname, x_off, y_off, x11grab->width, x11grab->height); + +- dpy = XOpenDisplay(param); ++ dpy = XOpenDisplay(dpyname); ++ av_freep(&dpyname); + if(!dpy) { + av_log(s1, AV_LOG_ERROR, "Could not open X display.\n"); +- return AVERROR(EIO); ++ ret = AVERROR(EIO); ++ goto out; + } + +- if (ap->width <= 0 || ap->height <= 0 || ap->time_base.den <= 0) { +- av_log(s1, AV_LOG_ERROR, "AVParameters don't have video size and/or rate. Use -s and -r.\n"); +- return AVERROR(EIO); ++ st = avformat_new_stream(s1, NULL); ++ if (!st) { ++ ret = AVERROR(ENOMEM); ++ goto out; + } ++ avpriv_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + +- st = av_new_stream(s1, 0); +- if (!st) { +- return AVERROR(ENOMEM); ++ screen = DefaultScreen(dpy); ++ ++ if (x11grab->follow_mouse) { ++ int screen_w, screen_h; ++ Window w; ++ ++ screen_w = DisplayWidth(dpy, screen); ++ screen_h = DisplayHeight(dpy, screen); ++ XQueryPointer(dpy, RootWindow(dpy, screen), &w, &w, &x_off, &y_off, &ret, &ret, &ret); ++ x_off -= x11grab->width / 2; ++ y_off -= x11grab->height / 2; ++ x_off = FFMIN(FFMAX(x_off, 0), screen_w - x11grab->width); ++ y_off = FFMIN(FFMAX(y_off, 0), screen_h - x11grab->height); ++ av_log(s1, AV_LOG_INFO, "followmouse is enabled, resetting grabbing region to x: %d y: %d\n", x_off, y_off); + } +- av_set_pts_info(st, 64, 1, 1000000); /* 64 bits pts in us */ + + use_shm = XShmQueryExtension(dpy); +- av_log(s1, AV_LOG_INFO, "shared memory extension %s found\n", use_shm ? "" : "not"); ++ av_log(s1, AV_LOG_INFO, "shared memory extension%s found\n", use_shm ? "" : " not"); + + if(use_shm) { + int scr = XDefaultScreen(dpy); +@@ -132,13 +230,14 @@ + ZPixmap, + NULL, + &x11grab->shminfo, +- ap->width, ap->height); ++ x11grab->width, x11grab->height); + x11grab->shminfo.shmid = shmget(IPC_PRIVATE, + image->bytes_per_line * image->height, + IPC_CREAT|0777); + if (x11grab->shminfo.shmid == -1) { + av_log(s1, AV_LOG_ERROR, "Fatal: Can't get shared memory!\n"); +- return AVERROR(ENOMEM); ++ ret = AVERROR(ENOMEM); ++ goto out; + } + x11grab->shminfo.shmaddr = image->data = shmat(x11grab->shminfo.shmid, 0, 0); + x11grab->shminfo.readOnly = False; +@@ -146,12 +245,13 @@ + if (!XShmAttach(dpy, &x11grab->shminfo)) { + av_log(s1, AV_LOG_ERROR, "Fatal: Failed to attach shared memory!\n"); + /* needs some better error subroutine :) */ +- return AVERROR(EIO); ++ ret = AVERROR(EIO); ++ goto out; + } + } else { +- image = XGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), ++ image = XGetImage(dpy, RootWindow(dpy, screen), + x_off,y_off, +- ap->width,ap->height, ++ x11grab->width, x11grab->height, + AllPlanes, ZPixmap); + } + +@@ -174,7 +274,8 @@ + } else { + av_log(s1, AV_LOG_ERROR, "RGB ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); + av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); +- return AVERROR(EIO); ++ ret = AVERROR(EIO); ++ goto out; + } + break; + case 24: +@@ -189,38 +290,23 @@ + } else { + av_log(s1, AV_LOG_ERROR,"rgb ordering at image depth %i not supported ... aborting\n", image->bits_per_pixel); + av_log(s1, AV_LOG_ERROR, "color masks: r 0x%.6lx g 0x%.6lx b 0x%.6lx\n", image->red_mask, image->green_mask, image->blue_mask); +- return AVERROR(EIO); ++ ret = AVERROR(EIO); ++ goto out; + } + break; + case 32: +-#if 0 +- GetColorInfo (image, &c_info); +- if ( c_info.alpha_mask == 0xff000000 && image->green_mask == 0x0000ff00) { +- /* byte order is relevant here, not endianness +- * endianness is handled by avcodec, but atm no such thing +- * as having ABGR, instead of ARGB in a word. Since we +- * need this for Solaris/SPARC, but need to do the conversion +- * for every frame we do it outside of this loop, cf. below +- * this matches both ARGB32 and ABGR32 */ +- input_pixfmt = PIX_FMT_ARGB32; +- } else { +- av_log(s1, AV_LOG_ERROR,"image depth %i not supported ... aborting\n", image->bits_per_pixel); +- return AVERROR(EIO); +- } +-#endif + input_pixfmt = PIX_FMT_RGB32; + break; + default: + av_log(s1, AV_LOG_ERROR, "image depth %i not supported ... aborting\n", image->bits_per_pixel); +- return -1; ++ ret = AVERROR(EINVAL); ++ goto out; + } + +- x11grab->frame_size = ap->width * ap->height * image->bits_per_pixel/8; ++ x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8; + x11grab->dpy = dpy; +- x11grab->width = ap->width; +- x11grab->height = ap->height; +- x11grab->time_base = ap->time_base; +- x11grab->time_frame = av_gettime() / av_q2d(ap->time_base); ++ x11grab->time_base = (AVRational){framerate.den, framerate.num}; ++ x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base); + x11grab->x_off = x_off; + x11grab->y_off = y_off; + x11grab->image = image; +@@ -228,13 +314,14 @@ + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; +- st->codec->width = ap->width; +- st->codec->height = ap->height; ++ st->codec->width = x11grab->width; ++ st->codec->height = x11grab->height; + st->codec->pix_fmt = input_pixfmt; +- st->codec->time_base = ap->time_base; +- st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(ap->time_base) * 8; ++ st->codec->time_base = x11grab->time_base; ++ st->codec->bit_rate = x11grab->frame_size * 1/av_q2d(x11grab->time_base) * 8; + +- return 0; ++out: ++ return ret; + } + + /** +@@ -365,6 +452,10 @@ + int x_off = s->x_off; + int y_off = s->y_off; + ++ int screen; ++ Window root; ++ int follow_mouse = s->follow_mouse; ++ + int64_t curtime, delay; + struct timespec ts; + +@@ -386,29 +477,75 @@ + nanosleep(&ts, NULL); + } + +- if (av_new_packet(pkt, s->frame_size) < 0) { +- return AVERROR(EIO); +- } +- ++ av_init_packet(pkt); ++ pkt->data = image->data; ++ pkt->size = s->frame_size; + pkt->pts = curtime; + ++ screen = DefaultScreen(dpy); ++ root = RootWindow(dpy, screen); ++ if (follow_mouse) { ++ int screen_w, screen_h; ++ int pointer_x, pointer_y, _; ++ Window w; ++ ++ screen_w = DisplayWidth(dpy, screen); ++ screen_h = DisplayHeight(dpy, screen); ++ XQueryPointer(dpy, root, &w, &w, &pointer_x, &pointer_y, &_, &_, &_); ++ if (follow_mouse == -1) { ++ // follow the mouse, put it at center of grabbing region ++ x_off += pointer_x - s->width / 2 - x_off; ++ y_off += pointer_y - s->height / 2 - y_off; ++ } else { ++ // follow the mouse, but only move the grabbing region when mouse ++ // reaches within certain pixels to the edge. ++ if (pointer_x > x_off + s->width - follow_mouse) { ++ x_off += pointer_x - (x_off + s->width - follow_mouse); ++ } else if (pointer_x < x_off + follow_mouse) ++ x_off -= (x_off + follow_mouse) - pointer_x; ++ if (pointer_y > y_off + s->height - follow_mouse) { ++ y_off += pointer_y - (y_off + s->height - follow_mouse); ++ } else if (pointer_y < y_off + follow_mouse) ++ y_off -= (y_off + follow_mouse) - pointer_y; ++ } ++ // adjust grabbing region position if it goes out of screen. ++ s->x_off = x_off = FFMIN(FFMAX(x_off, 0), screen_w - s->width); ++ s->y_off = y_off = FFMIN(FFMAX(y_off, 0), screen_h - s->height); ++ ++ if (s->show_region && s->region_win) ++ XMoveWindow(dpy, s->region_win, ++ s->x_off - REGION_WIN_BORDER, ++ s->y_off - REGION_WIN_BORDER); ++ } ++ ++ if (s->show_region) { ++ if (s->region_win) { ++ XEvent evt; ++ // clean up the events, and do the initinal draw or redraw. ++ for (evt.type = NoEventMask; XCheckMaskEvent(dpy, ExposureMask | StructureNotifyMask, &evt); ); ++ if (evt.type) ++ x11grab_draw_region_win(s); ++ } else { ++ x11grab_region_win_init(s); ++ } ++ } ++ + if(s->use_shm) { +- if (!XShmGetImage(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off, AllPlanes)) { ++ if (!XShmGetImage(dpy, root, image, x_off, y_off, AllPlanes)) { + av_log (s1, AV_LOG_INFO, "XShmGetImage() failed\n"); + } + } else { +- if (!xget_zpixmap(dpy, RootWindow(dpy, DefaultScreen(dpy)), image, x_off, y_off)) { ++ if (!xget_zpixmap(dpy, root, image, x_off, y_off)) { + av_log (s1, AV_LOG_INFO, "XGetZPixmap() failed\n"); + } + } ++ if (image->bits_per_pixel == 32) ++ XAddPixel(image, 0xFF000000); + +- if(!s->nomouse){ ++ if (s->draw_mouse) { + paint_mouse_pointer(image, s); + } + +- +- /* XXX: avoid memcpy */ +- memcpy(pkt->data, image->data, s->frame_size); + return s->frame_size; + } + +@@ -436,20 +573,43 @@ + x11grab->image = NULL; + } + ++ if (x11grab->region_win) { ++ XDestroyWindow(x11grab->dpy, x11grab->region_win); ++ } ++ + /* Free X11 display */ + XCloseDisplay(x11grab->dpy); + return 0; + } + ++#define OFFSET(x) offsetof(struct x11_grab, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = "vga"}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "ntsc"}, 0, 0, DEC }, ++ { "draw_mouse", "Draw the mouse pointer.", OFFSET(draw_mouse), AV_OPT_TYPE_INT, { 1 }, 0, 1, DEC }, ++ { "follow_mouse", "Move the grabbing region when the mouse pointer reaches within specified amount of pixels to the edge of region.", ++ OFFSET(follow_mouse), AV_OPT_TYPE_INT, { 0 }, -1, INT_MAX, DEC, "follow_mouse" }, ++ { "centered", "Keep the mouse pointer at the center of grabbing region when following.", 0, AV_OPT_TYPE_CONST, { -1 }, INT_MIN, INT_MAX, DEC, "follow_mouse" }, ++ { "show_region", "Show the grabbing region.", OFFSET(show_region), AV_OPT_TYPE_INT, { 0 }, 0, 1, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass x11_class = { ++ .class_name = "X11grab indev", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + /** x11 grabber device demuxer declaration */ +-AVInputFormat ff_x11_grab_device_demuxer = +-{ +- "x11grab", +- NULL_IF_CONFIG_SMALL("X11grab"), +- sizeof(struct x11_grab), +- NULL, +- x11grab_read_header, +- x11grab_read_packet, +- x11grab_read_close, +- .flags = AVFMT_NOFILE, ++AVInputFormat ff_x11_grab_device_demuxer = { ++ .name = "x11grab", ++ .long_name = NULL_IF_CONFIG_SMALL("X11grab"), ++ .priv_data_size = sizeof(struct x11_grab), ++ .read_header = x11grab_read_header, ++ .read_packet = x11grab_read_packet, ++ .read_close = x11grab_read_close, ++ .flags = AVFMT_NOFILE, ++ .priv_class = &x11_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aconvert.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aconvert.c 2012-05-14 14:08:54.676346865 +0200 +@@ -0,0 +1,418 @@ ++/* ++ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram ++ * Copyright (c) 2011 Stefano Sabatini ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * sample format and channel layout conversion audio filter ++ * based on code in libavcodec/resample.c by Fabrice Bellard and ++ * libavcodec/audioconvert.c by Michael Niedermayer ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/avstring.h" ++#include "libavcodec/audioconvert.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++typedef struct { ++ enum AVSampleFormat out_sample_fmt, in_sample_fmt; ///< in/out sample formats ++ int64_t out_chlayout, in_chlayout; ///< in/out channel layout ++ int out_nb_channels, in_nb_channels; ///< number of in/output channels ++ enum AVFilterPacking out_packing_fmt, in_packing_fmt; ///< output packing format ++ ++ int max_nb_samples; ///< maximum number of buffered samples ++ AVFilterBufferRef *mix_samplesref; ///< rematrixed buffer ++ AVFilterBufferRef *out_samplesref; ///< output buffer after required conversions ++ ++ uint8_t *in_mix[8], *out_mix[8]; ///< input/output for rematrixing functions ++ uint8_t *packed_data[8]; ///< pointers for packing conversion ++ int out_strides[8], in_strides[8]; ///< input/output strides for av_audio_convert ++ uint8_t **in_conv, **out_conv; ///< input/output for av_audio_convert ++ ++ AVAudioConvert *audioconvert_ctx; ///< context for conversion to output sample format ++ ++ void (*convert_chlayout)(); ///< function to do the requested rematrixing ++} AConvertContext; ++ ++#define REMATRIX_FUNC_SIG(NAME) static void REMATRIX_FUNC_NAME(NAME) \ ++ (FMT_TYPE *outp[], FMT_TYPE *inp[], int nb_samples, AConvertContext *aconvert) ++ ++#define FMT_TYPE uint8_t ++#define REMATRIX_FUNC_NAME(NAME) NAME ## _u8 ++#include "af_aconvert_rematrix.c" ++ ++#define FMT_TYPE int16_t ++#define REMATRIX_FUNC_NAME(NAME) NAME ## _s16 ++#include "af_aconvert_rematrix.c" ++ ++#define FMT_TYPE int32_t ++#define REMATRIX_FUNC_NAME(NAME) NAME ## _s32 ++#include "af_aconvert_rematrix.c" ++ ++#define FLOATING ++ ++#define FMT_TYPE float ++#define REMATRIX_FUNC_NAME(NAME) NAME ## _flt ++#include "af_aconvert_rematrix.c" ++ ++#define FMT_TYPE double ++#define REMATRIX_FUNC_NAME(NAME) NAME ## _dbl ++#include "af_aconvert_rematrix.c" ++ ++#define FMT_TYPE uint8_t ++#define REMATRIX_FUNC_NAME(NAME) NAME ++REMATRIX_FUNC_SIG(stereo_remix_planar) ++{ ++ int size = av_get_bytes_per_sample(aconvert->in_sample_fmt) * nb_samples; ++ ++ memcpy(outp[0], inp[0], size); ++ memcpy(outp[1], inp[aconvert->in_nb_channels == 1 ? 0 : 1], size); ++} ++ ++#define REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC, PACKING) \ ++ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_U8, FUNC##_u8}, \ ++ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_S16, FUNC##_s16}, \ ++ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_S32, FUNC##_s32}, \ ++ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_FLT, FUNC##_flt}, \ ++ {INCHLAYOUT, OUTCHLAYOUT, PACKING, AV_SAMPLE_FMT_DBL, FUNC##_dbl}, ++ ++#define REGISTER_FUNC(INCHLAYOUT, OUTCHLAYOUT, FUNC) \ ++ REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC##_packed, AVFILTER_PACKED) \ ++ REGISTER_FUNC_PACKING(INCHLAYOUT, OUTCHLAYOUT, FUNC##_planar, AVFILTER_PLANAR) ++ ++static const struct RematrixFunctionInfo { ++ int64_t in_chlayout, out_chlayout; ++ int planar, sfmt; ++ void (*func)(); ++} rematrix_funcs[] = { ++ REGISTER_FUNC (AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1, stereo_to_surround_5p1) ++ REGISTER_FUNC (AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_STEREO, surround_5p1_to_stereo) ++ REGISTER_FUNC_PACKING(AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_MONO, stereo_to_mono_packed, AVFILTER_PACKED) ++ REGISTER_FUNC_PACKING(AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, mono_to_stereo_packed, AVFILTER_PACKED) ++ REGISTER_FUNC (0, AV_CH_LAYOUT_MONO, mono_downmix) ++ REGISTER_FUNC_PACKING(0, AV_CH_LAYOUT_STEREO, stereo_downmix_packed, AVFILTER_PACKED) ++ ++ // This function works for all sample formats ++ {0, AV_CH_LAYOUT_STEREO, AVFILTER_PLANAR, -1, stereo_remix_planar} ++}; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque) ++{ ++ AConvertContext *aconvert = ctx->priv; ++ char *arg, *ptr = NULL; ++ int ret = 0; ++ char *args = av_strdup(args0); ++ ++ aconvert->out_sample_fmt = AV_SAMPLE_FMT_NONE; ++ aconvert->out_chlayout = 0; ++ aconvert->out_packing_fmt = -1; ++ ++ if ((arg = av_strtok(args, ":", &ptr)) && strcmp(arg, "auto")) { ++ if ((ret = ff_parse_sample_format(&aconvert->out_sample_fmt, arg, ctx)) < 0) ++ goto end; ++ } ++ if ((arg = av_strtok(NULL, ":", &ptr)) && strcmp(arg, "auto")) { ++ if ((ret = ff_parse_channel_layout(&aconvert->out_chlayout, arg, ctx)) < 0) ++ goto end; ++ } ++ if ((arg = av_strtok(NULL, ":", &ptr)) && strcmp(arg, "auto")) { ++ if ((ret = ff_parse_packing_format((int *)&aconvert->out_packing_fmt, arg, ctx)) < 0) ++ goto end; ++ } ++ ++end: ++ av_freep(&args); ++ return ret; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ AConvertContext *aconvert = ctx->priv; ++ avfilter_unref_buffer(aconvert->mix_samplesref); ++ avfilter_unref_buffer(aconvert->out_samplesref); ++ if (aconvert->audioconvert_ctx) ++ av_audio_convert_free(aconvert->audioconvert_ctx); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats = NULL; ++ AConvertContext *aconvert = ctx->priv; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ ++ avfilter_formats_ref(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), ++ &inlink->out_formats); ++ if (aconvert->out_sample_fmt != AV_SAMPLE_FMT_NONE) { ++ formats = NULL; ++ avfilter_add_format(&formats, aconvert->out_sample_fmt); ++ avfilter_formats_ref(formats, &outlink->in_formats); ++ } else ++ avfilter_formats_ref(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), ++ &outlink->in_formats); ++ ++ avfilter_formats_ref(avfilter_make_all_channel_layouts(), ++ &inlink->out_chlayouts); ++ if (aconvert->out_chlayout != 0) { ++ formats = NULL; ++ avfilter_add_format(&formats, aconvert->out_chlayout); ++ avfilter_formats_ref(formats, &outlink->in_chlayouts); ++ } else ++ avfilter_formats_ref(avfilter_make_all_channel_layouts(), ++ &outlink->in_chlayouts); ++ ++ avfilter_formats_ref(avfilter_make_all_packing_formats(), ++ &inlink->out_packing); ++ if (aconvert->out_packing_fmt != -1) { ++ formats = NULL; ++ avfilter_add_format(&formats, aconvert->out_packing_fmt); ++ avfilter_formats_ref(formats, &outlink->in_packing); ++ } else ++ avfilter_formats_ref(avfilter_make_all_packing_formats(), ++ &outlink->in_packing); ++ ++ return 0; ++} ++ ++static int config_output(AVFilterLink *outlink) ++{ ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ AConvertContext *aconvert = outlink->src->priv; ++ char buf1[64], buf2[64]; ++ ++ aconvert->in_sample_fmt = inlink->format; ++ aconvert->in_packing_fmt = inlink->planar; ++ if (aconvert->out_packing_fmt == -1) ++ aconvert->out_packing_fmt = outlink->planar; ++ aconvert->in_chlayout = inlink->channel_layout; ++ aconvert->in_nb_channels = ++ av_get_channel_layout_nb_channels(inlink->channel_layout); ++ ++ /* if not specified in args, use the format and layout of the output */ ++ if (aconvert->out_sample_fmt == AV_SAMPLE_FMT_NONE) ++ aconvert->out_sample_fmt = outlink->format; ++ if (aconvert->out_chlayout == 0) ++ aconvert->out_chlayout = outlink->channel_layout; ++ aconvert->out_nb_channels = ++ av_get_channel_layout_nb_channels(outlink->channel_layout); ++ ++ av_get_channel_layout_string(buf1, sizeof(buf1), ++ -1, inlink ->channel_layout); ++ av_get_channel_layout_string(buf2, sizeof(buf2), ++ -1, outlink->channel_layout); ++ av_log(outlink->src, AV_LOG_INFO, ++ "fmt:%s cl:%s planar:%i -> fmt:%s cl:%s planar:%i\n", ++ av_get_sample_fmt_name(inlink ->format), buf1, inlink ->planar, ++ av_get_sample_fmt_name(outlink->format), buf2, outlink->planar); ++ ++ /* compute which channel layout conversion to use */ ++ if (inlink->channel_layout != outlink->channel_layout) { ++ int i; ++ for (i = 0; i < sizeof(rematrix_funcs); i++) { ++ const struct RematrixFunctionInfo *f = &rematrix_funcs[i]; ++ if ((f->in_chlayout == 0 || f->in_chlayout == inlink ->channel_layout) && ++ (f->out_chlayout == 0 || f->out_chlayout == outlink->channel_layout) && ++ (f->planar == -1 || f->planar == inlink->planar) && ++ (f->sfmt == -1 || f->sfmt == inlink->format) ++ ) { ++ aconvert->convert_chlayout = f->func; ++ break; ++ } ++ } ++ if (!aconvert->convert_chlayout) { ++ av_log(outlink->src, AV_LOG_ERROR, ++ "Unsupported channel layout conversion '%s -> %s' requested!\n", ++ buf1, buf2); ++ return AVERROR(EINVAL); ++ } ++ } ++ ++ return 0; ++} ++ ++static int init_buffers(AVFilterLink *inlink, int nb_samples) ++{ ++ AConvertContext *aconvert = inlink->dst->priv; ++ AVFilterLink * const outlink = inlink->dst->outputs[0]; ++ int i, packed_stride = 0; ++ const unsigned ++ packing_conv = inlink->planar != outlink->planar && ++ aconvert->out_nb_channels != 1, ++ format_conv = inlink->format != outlink->format; ++ int nb_channels = aconvert->out_nb_channels; ++ ++ uninit(inlink->dst); ++ aconvert->max_nb_samples = nb_samples; ++ ++ if (aconvert->convert_chlayout) { ++ /* allocate buffer for storing intermediary mixing samplesref */ ++ uint8_t *data[8]; ++ int linesize[8]; ++ int nb_channels = av_get_channel_layout_nb_channels(outlink->channel_layout); ++ ++ if (av_samples_alloc(data, linesize, nb_channels, nb_samples, ++ inlink->format, 16) < 0) ++ goto fail_no_mem; ++ aconvert->mix_samplesref = ++ avfilter_get_audio_buffer_ref_from_arrays(data, linesize, AV_PERM_WRITE, ++ nb_samples, inlink->format, ++ outlink->channel_layout, ++ inlink->planar); ++ if (!aconvert->mix_samplesref) ++ goto fail_no_mem; ++ } ++ ++ // if there's a format/packing conversion we need an audio_convert context ++ if (format_conv || packing_conv) { ++ aconvert->out_samplesref = ++ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples); ++ if (!aconvert->out_samplesref) ++ goto fail_no_mem; ++ ++ aconvert->in_strides [0] = av_get_bytes_per_sample(inlink ->format); ++ aconvert->out_strides[0] = av_get_bytes_per_sample(outlink->format); ++ ++ aconvert->out_conv = aconvert->out_samplesref->data; ++ if (aconvert->mix_samplesref) ++ aconvert->in_conv = aconvert->mix_samplesref->data; ++ ++ if (packing_conv) { ++ // packed -> planar ++ if (outlink->planar == AVFILTER_PLANAR) { ++ if (aconvert->mix_samplesref) ++ aconvert->packed_data[0] = aconvert->mix_samplesref->data[0]; ++ aconvert->in_conv = aconvert->packed_data; ++ packed_stride = aconvert->in_strides[0]; ++ aconvert->in_strides[0] *= nb_channels; ++ // planar -> packed ++ } else { ++ aconvert->packed_data[0] = aconvert->out_samplesref->data[0]; ++ aconvert->out_conv = aconvert->packed_data; ++ packed_stride = aconvert->out_strides[0]; ++ aconvert->out_strides[0] *= nb_channels; ++ } ++ } else if (outlink->planar == AVFILTER_PACKED) { ++ /* If there's no packing conversion, and the stream is packed ++ * then we treat the entire stream as one big channel ++ */ ++ nb_channels = 1; ++ } ++ ++ for (i = 1; i < nb_channels; i++) { ++ aconvert->packed_data[i] = aconvert->packed_data[i-1] + packed_stride; ++ aconvert->in_strides[i] = aconvert->in_strides[0]; ++ aconvert->out_strides[i] = aconvert->out_strides[0]; ++ } ++ ++ aconvert->audioconvert_ctx = ++ av_audio_convert_alloc(outlink->format, nb_channels, ++ inlink->format, nb_channels, NULL, 0); ++ if (!aconvert->audioconvert_ctx) ++ goto fail_no_mem; ++ } ++ ++ return 0; ++ ++fail_no_mem: ++ av_log(inlink->dst, AV_LOG_ERROR, "Could not allocate memory.\n"); ++ return AVERROR(ENOMEM); ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref) ++{ ++ AConvertContext *aconvert = inlink->dst->priv; ++ AVFilterBufferRef *curbuf = insamplesref; ++ AVFilterLink * const outlink = inlink->dst->outputs[0]; ++ int chan_mult; ++ ++ /* in/reinint the internal buffers if this is the first buffer ++ * provided or it is needed to use a bigger one */ ++ if (!aconvert->max_nb_samples || ++ (curbuf->audio->nb_samples > aconvert->max_nb_samples)) ++ if (init_buffers(inlink, curbuf->audio->nb_samples) < 0) { ++ av_log(inlink->dst, AV_LOG_ERROR, "Could not initialize buffers.\n"); ++ return; ++ } ++ ++ /* if channel mixing is required */ ++ if (aconvert->mix_samplesref) { ++ memcpy(aconvert->in_mix, curbuf->data, sizeof(aconvert->in_mix)); ++ memcpy(aconvert->out_mix, aconvert->mix_samplesref->data, sizeof(aconvert->out_mix)); ++ aconvert->convert_chlayout(aconvert->out_mix, ++ aconvert->in_mix, ++ curbuf->audio->nb_samples, ++ aconvert); ++ curbuf = aconvert->mix_samplesref; ++ } ++ ++ if (aconvert->audioconvert_ctx) { ++ if (!aconvert->mix_samplesref) { ++ if (aconvert->in_conv == aconvert->packed_data) { ++ int i, packed_stride = av_get_bytes_per_sample(inlink->format); ++ aconvert->packed_data[0] = curbuf->data[0]; ++ for (i = 1; i < aconvert->out_nb_channels; i++) ++ aconvert->packed_data[i] = aconvert->packed_data[i-1] + packed_stride; ++ } else { ++ aconvert->in_conv = curbuf->data; ++ } ++ } ++ ++ chan_mult = inlink->planar == outlink->planar && inlink->planar == 0 ? ++ aconvert->out_nb_channels : 1; ++ ++ av_audio_convert(aconvert->audioconvert_ctx, ++ (void * const *) aconvert->out_conv, ++ aconvert->out_strides, ++ (const void * const *) aconvert->in_conv, ++ aconvert->in_strides, ++ curbuf->audio->nb_samples * chan_mult); ++ ++ curbuf = aconvert->out_samplesref; ++ } ++ ++ avfilter_copy_buffer_ref_props(curbuf, insamplesref); ++ curbuf->audio->channel_layout = outlink->channel_layout; ++ curbuf->audio->planar = outlink->planar; ++ ++ avfilter_filter_samples(inlink->dst->outputs[0], ++ avfilter_ref_buffer(curbuf, ~0)); ++ avfilter_unref_buffer(insamplesref); ++} ++ ++AVFilter avfilter_af_aconvert = { ++ .name = "aconvert", ++ .description = NULL_IF_CONFIG_SMALL("Convert the input audio to sample_fmt:channel_layout:packed_fmt."), ++ .priv_size = sizeof(AConvertContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_output, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aconvert_rematrix.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aconvert_rematrix.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aconvert_rematrix.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aconvert_rematrix.c 2012-05-14 14:08:54.677346885 +0200 +@@ -0,0 +1,172 @@ ++/* ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio rematrixing functions, based on functions from libavcodec/resample.c ++ */ ++ ++#if defined(FLOATING) ++# define DIV2 /2 ++#else ++# define DIV2 >>1 ++#endif ++ ++REMATRIX_FUNC_SIG(stereo_to_mono_packed) ++{ ++ while (nb_samples >= 4) { ++ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2; ++ outp[0][1] = (inp[0][2] + inp[0][3]) DIV2; ++ outp[0][2] = (inp[0][4] + inp[0][5]) DIV2; ++ outp[0][3] = (inp[0][6] + inp[0][7]) DIV2; ++ outp[0] += 4; ++ inp[0] += 8; ++ nb_samples -= 4; ++ } ++ while (nb_samples--) { ++ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2; ++ outp[0]++; ++ inp[0] += 2; ++ } ++} ++ ++REMATRIX_FUNC_SIG(stereo_downmix_packed) ++{ ++ while (nb_samples--) { ++ *outp[0]++ = inp[0][0]; ++ *outp[0]++ = inp[0][1]; ++ inp[0] += aconvert->in_nb_channels; ++ } ++} ++ ++REMATRIX_FUNC_SIG(mono_to_stereo_packed) ++{ ++ while (nb_samples >= 4) { ++ outp[0][0] = outp[0][1] = inp[0][0]; ++ outp[0][2] = outp[0][3] = inp[0][1]; ++ outp[0][4] = outp[0][5] = inp[0][2]; ++ outp[0][6] = outp[0][7] = inp[0][3]; ++ outp[0] += 8; ++ inp[0] += 4; ++ nb_samples -= 4; ++ } ++ while (nb_samples--) { ++ outp[0][0] = outp[0][1] = inp[0][0]; ++ outp[0] += 2; ++ inp[0] += 1; ++ } ++} ++ ++/** ++ * This is for when we have more than 2 input channels, need to downmix to mono ++ * and do not have a conversion formula available. We just use first two input ++ * channels - left and right. This is a placeholder until more conversion ++ * functions are written. ++ */ ++REMATRIX_FUNC_SIG(mono_downmix_packed) ++{ ++ while (nb_samples--) { ++ outp[0][0] = (inp[0][0] + inp[0][1]) DIV2; ++ inp[0] += aconvert->in_nb_channels; ++ outp[0]++; ++ } ++} ++ ++REMATRIX_FUNC_SIG(mono_downmix_planar) ++{ ++ FMT_TYPE *out = outp[0]; ++ ++ while (nb_samples >= 4) { ++ out[0] = (inp[0][0] + inp[1][0]) DIV2; ++ out[1] = (inp[0][1] + inp[1][1]) DIV2; ++ out[2] = (inp[0][2] + inp[1][2]) DIV2; ++ out[3] = (inp[0][3] + inp[1][3]) DIV2; ++ out += 4; ++ inp[0] += 4; ++ inp[1] += 4; ++ nb_samples -= 4; ++ } ++ while (nb_samples--) { ++ out[0] = (inp[0][0] + inp[1][0]) DIV2; ++ out++; ++ inp[0]++; ++ inp[1]++; ++ } ++} ++ ++/* Stereo to 5.1 output */ ++REMATRIX_FUNC_SIG(stereo_to_surround_5p1_packed) ++{ ++ while (nb_samples--) { ++ outp[0][0] = inp[0][0]; /* left */ ++ outp[0][1] = inp[0][1]; /* right */ ++ outp[0][2] = (inp[0][0] + inp[0][1]) DIV2; /* center */ ++ outp[0][3] = 0; /* low freq */ ++ outp[0][4] = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */ ++ outp[0][5] = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */ ++ inp[0] += 2; ++ outp[0] += 6; ++ } ++} ++ ++REMATRIX_FUNC_SIG(stereo_to_surround_5p1_planar) ++{ ++ while (nb_samples--) { ++ *outp[0]++ = *inp[0]; /* left */ ++ *outp[1]++ = *inp[1]; /* right */ ++ *outp[2]++ = (*inp[0] + *inp[1]) DIV2; /* center */ ++ *outp[3]++ = 0; /* low freq */ ++ *outp[4]++ = 0; /* FIXME: left surround: -3dB or -6dB or -9dB of stereo left */ ++ *outp[5]++ = 0; /* FIXME: right surroud: -3dB or -6dB or -9dB of stereo right */ ++ inp[0]++; inp[1]++; ++ } ++} ++ ++ ++/* ++5.1 to stereo input: [fl, fr, c, lfe, rl, rr] ++- Left = front_left + rear_gain * rear_left + center_gain * center ++- Right = front_right + rear_gain * rear_right + center_gain * center ++Where rear_gain is usually around 0.5-1.0 and ++ center_gain is almost always 0.7 (-3 dB) ++*/ ++REMATRIX_FUNC_SIG(surround_5p1_to_stereo_packed) ++{ ++ while (nb_samples--) { ++ *outp[0]++ = inp[0][0] + (0.5 * inp[0][4]) + (0.7 * inp[0][2]); //FIXME CLIPPING! ++ *outp[0]++ = inp[0][1] + (0.5 * inp[0][5]) + (0.7 * inp[0][2]); //FIXME CLIPPING! ++ ++ inp[0] += 6; ++ } ++} ++ ++REMATRIX_FUNC_SIG(surround_5p1_to_stereo_planar) ++{ ++ while (nb_samples--) { ++ *outp[0]++ = *inp[0] + (0.5 * *inp[4]) + (0.7 * *inp[2]); //FIXME CLIPPING! ++ *outp[1]++ = *inp[1] + (0.5 * *inp[5]) + (0.7 * *inp[2]); //FIXME CLIPPING! ++ ++ inp[0]++; inp[1]++; inp[2]++; inp[3]++; inp[4]++; inp[5]++; ++ } ++} ++ ++#undef DIV2 ++#undef REMATRIX_FUNC_NAME ++#undef FMT_TYPE +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aformat.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aformat.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aformat.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aformat.c 2012-05-14 14:08:54.678346905 +0200 +@@ -0,0 +1,108 @@ ++/* ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * format audio filter ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/avstring.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++typedef struct { ++ AVFilterFormats *formats, *chlayouts, *packing; ++} AFormatContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ AFormatContext * const aformat = ctx->priv; ++ char *fmts_str = NULL, *fmt_str, *ptr = NULL; ++ int64_t fmt; ++ int ret; ++ ++ if (!args) ++ goto arg_fail; ++ ++#define ADD_FORMATS(all_formats, fmt_name, fmt_type, fmts_list) \ ++ fmts_str = av_get_token(&args, ":"); \ ++ if (!fmts_str || !*fmts_str) \ ++ goto arg_fail; \ ++ if (!strcmp(fmts_str, "all")) { \ ++ aformat->fmts_list = all_formats; \ ++ } else { \ ++ for (fmt_str = fmts_str; \ ++ fmt_str = av_strtok(fmt_str, ",", &ptr); fmt_str = NULL) { \ ++ if ((ret = ff_parse_##fmt_name((fmt_type *)&fmt, \ ++ fmt_str, ctx)) < 0) { \ ++ av_freep(&fmts_str); \ ++ return ret; \ ++ } \ ++ avfilter_add_format(&aformat->fmts_list, fmt); \ ++ } \ ++ } \ ++ av_freep(&fmts_str); \ ++ if (*args) \ ++ args++; ++ ++ ADD_FORMATS(avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO), sample_format, int, formats); ++ ADD_FORMATS(avfilter_make_all_channel_layouts(), channel_layout, int64_t, chlayouts); ++ ADD_FORMATS(avfilter_make_all_packing_formats(), packing_format, int, packing); ++ ++ return 0; ++ ++arg_fail: ++ av_log(ctx, AV_LOG_ERROR, "Invalid arguments, they must be of the form " ++ "sample_fmts:channel_layouts:packing_fmts\n"); ++ av_freep(&fmts_str); ++ return AVERROR(EINVAL); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AFormatContext * const aformat = ctx->priv; ++ ++ avfilter_set_common_sample_formats (ctx, aformat->formats); ++ avfilter_set_common_channel_layouts(ctx, aformat->chlayouts); ++ avfilter_set_common_packing_formats(ctx, aformat->packing); ++ return 0; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref) ++{ ++ avfilter_filter_samples(inlink->dst->outputs[0], insamplesref); ++} ++ ++AVFilter avfilter_af_aformat = { ++ .name = "aformat", ++ .description = NULL_IF_CONFIG_SMALL("Convert the input audio to one of the specified formats."), ++ .init = init, ++ .query_formats = query_formats, ++ .priv_size = sizeof(AFormatContext), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples}, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO}, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_amerge.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_amerge.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_amerge.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_amerge.c 2012-05-14 14:08:54.679346925 +0200 +@@ -0,0 +1,288 @@ ++/* ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Audio merging filter ++ */ ++ ++#include "libswresample/swresample.h" // only for SWR_CH_MAX ++#include "avfilter.h" ++#include "internal.h" ++ ++#define QUEUE_SIZE 16 ++ ++typedef struct { ++ int nb_in_ch[2]; /**< number of channels for each input */ ++ int route[SWR_CH_MAX]; /**< channels routing, see copy_samples */ ++ int bps; ++ struct amerge_queue { ++ AVFilterBufferRef *buf[QUEUE_SIZE]; ++ int nb_buf, nb_samples, pos; ++ } queue[2]; ++} AMergeContext; ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ AMergeContext *am = ctx->priv; ++ int i, j; ++ ++ for (i = 0; i < 2; i++) ++ for (j = 0; j < am->queue[i].nb_buf; j++) ++ avfilter_unref_buffer(am->queue[i].buf[j]); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AMergeContext *am = ctx->priv; ++ int64_t inlayout[2], outlayout; ++ const int packing_fmts[] = { AVFILTER_PACKED, -1 }; ++ AVFilterFormats *formats; ++ int i; ++ ++ for (i = 0; i < 2; i++) { ++ if (!ctx->inputs[i]->in_chlayouts || ++ !ctx->inputs[i]->in_chlayouts->format_count) { ++ av_log(ctx, AV_LOG_ERROR, ++ "No channel layout for input %d\n", i + 1); ++ return AVERROR(EINVAL); ++ } ++ inlayout[i] = ctx->inputs[i]->in_chlayouts->formats[0]; ++ if (ctx->inputs[i]->in_chlayouts->format_count > 1) { ++ char buf[256]; ++ av_get_channel_layout_string(buf, sizeof(buf), 0, inlayout[i]); ++ av_log(ctx, AV_LOG_INFO, "Using \"%s\" for input %d\n", buf, i + 1); ++ } ++ am->nb_in_ch[i] = av_get_channel_layout_nb_channels(inlayout[i]); ++ } ++ if (am->nb_in_ch[0] + am->nb_in_ch[1] > SWR_CH_MAX) { ++ av_log(ctx, AV_LOG_ERROR, "Too many channels (max %d)\n", SWR_CH_MAX); ++ return AVERROR(EINVAL); ++ } ++ if (inlayout[0] & inlayout[1]) { ++ av_log(ctx, AV_LOG_WARNING, ++ "Inputs overlap: output layout will be meaningless\n"); ++ for (i = 0; i < am->nb_in_ch[0] + am->nb_in_ch[1]; i++) ++ am->route[i] = i; ++ outlayout = av_get_default_channel_layout(am->nb_in_ch[0] + ++ am->nb_in_ch[1]); ++ if (!outlayout) ++ outlayout = ((int64_t)1 << (am->nb_in_ch[0] + am->nb_in_ch[1])) - 1; ++ } else { ++ int *route[2] = { am->route, am->route + am->nb_in_ch[0] }; ++ int c, out_ch_number = 0; ++ ++ outlayout = inlayout[0] | inlayout[1]; ++ for (c = 0; c < 64; c++) ++ for (i = 0; i < 2; i++) ++ if ((inlayout[i] >> c) & 1) ++ *(route[i]++) = out_ch_number++; ++ } ++ formats = avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO); ++ avfilter_set_common_sample_formats(ctx, formats); ++ formats = avfilter_make_format_list(packing_fmts); ++ avfilter_set_common_packing_formats(ctx, formats); ++ for (i = 0; i < 2; i++) { ++ formats = NULL; ++ avfilter_add_format(&formats, inlayout[i]); ++ avfilter_formats_ref(formats, &ctx->inputs[i]->out_chlayouts); ++ } ++ formats = NULL; ++ avfilter_add_format(&formats, outlayout); ++ avfilter_formats_ref(formats, &ctx->outputs[0]->in_chlayouts); ++ return 0; ++} ++ ++static int config_output(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ AMergeContext *am = ctx->priv; ++ int64_t layout; ++ char name[3][256]; ++ int i; ++ ++ if (ctx->inputs[0]->sample_rate != ctx->inputs[1]->sample_rate) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Inputs must have the same sample rate " ++ "(%"PRIi64" vs %"PRIi64")\n", ++ ctx->inputs[0]->sample_rate, ctx->inputs[1]->sample_rate); ++ return AVERROR(EINVAL); ++ } ++ am->bps = av_get_bytes_per_sample(ctx->outputs[0]->format); ++ outlink->sample_rate = ctx->inputs[0]->sample_rate; ++ outlink->time_base = ctx->inputs[0]->time_base; ++ for (i = 0; i < 3; i++) { ++ layout = (i < 2 ? ctx->inputs[i] : ctx->outputs[0])->channel_layout; ++ av_get_channel_layout_string(name[i], sizeof(name[i]), -1, layout); ++ } ++ av_log(ctx, AV_LOG_INFO, ++ "in1:%s + in2:%s -> out:%s\n", name[0], name[1], name[2]); ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ AMergeContext *am = ctx->priv; ++ int i; ++ ++ for (i = 0; i < 2; i++) ++ if (!am->queue[i].nb_samples) ++ avfilter_request_frame(ctx->inputs[i]); ++ return 0; ++} ++ ++/** ++ * Copy samples from two input streams to one output stream. ++ * @param nb_in_ch number of channels in each input stream ++ * @param route routing values; ++ * input channel i goes to output channel route[i]; ++ * i < nb_in_ch[0] are the channels from the first output; ++ * i >= nb_in_ch[0] are the channels from the second output ++ * @param ins pointer to the samples of each inputs, in packed format; ++ * will be left at the end of the copied samples ++ * @param outs pointer to the samples of the output, in packet format; ++ * must point to a buffer big enough; ++ * will be left at the end of the copied samples ++ * @param ns number of samples to copy ++ * @param bps bytes per sample ++ */ ++static inline void copy_samples(int nb_in_ch[2], int *route, uint8_t *ins[2], ++ uint8_t **outs, int ns, int bps) ++{ ++ int *route_cur; ++ int i, c; ++ ++ while (ns--) { ++ route_cur = route; ++ for (i = 0; i < 2; i++) { ++ for (c = 0; c < nb_in_ch[i]; c++) { ++ memcpy((*outs) + bps * *(route_cur++), ins[i], bps); ++ ins[i] += bps; ++ } ++ } ++ *outs += (nb_in_ch[0] + nb_in_ch[1]) * bps; ++ } ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AMergeContext *am = ctx->priv; ++ int input_number = inlink == ctx->inputs[1]; ++ struct amerge_queue *inq = &am->queue[input_number]; ++ int nb_samples, ns, i; ++ AVFilterBufferRef *outbuf, **inbuf[2]; ++ uint8_t *ins[2], *outs; ++ ++ if (inq->nb_buf == QUEUE_SIZE) { ++ av_log(ctx, AV_LOG_ERROR, "Packet queue overflow; dropped\n"); ++ avfilter_unref_buffer(insamples); ++ return; ++ } ++ inq->buf[inq->nb_buf++] = avfilter_ref_buffer(insamples, AV_PERM_READ | ++ AV_PERM_PRESERVE); ++ inq->nb_samples += insamples->audio->nb_samples; ++ avfilter_unref_buffer(insamples); ++ if (!am->queue[!input_number].nb_samples) ++ return; ++ ++ nb_samples = FFMIN(am->queue[0].nb_samples, ++ am->queue[1].nb_samples); ++ outbuf = avfilter_get_audio_buffer(ctx->outputs[0], AV_PERM_WRITE, ++ nb_samples); ++ outs = outbuf->data[0]; ++ for (i = 0; i < 2; i++) { ++ inbuf[i] = am->queue[i].buf; ++ ins[i] = (*inbuf[i])->data[0] + ++ am->queue[i].pos * am->nb_in_ch[i] * am->bps; ++ } ++ while (nb_samples) { ++ ns = nb_samples; ++ for (i = 0; i < 2; i++) ++ ns = FFMIN(ns, (*inbuf[i])->audio->nb_samples - am->queue[i].pos); ++ /* Unroll the most common sample formats: speed +~350% for the loop, ++ +~13% overall (including two common decoders) */ ++ switch (am->bps) { ++ case 1: ++ copy_samples(am->nb_in_ch, am->route, ins, &outs, ns, 1); ++ break; ++ case 2: ++ copy_samples(am->nb_in_ch, am->route, ins, &outs, ns, 2); ++ break; ++ case 4: ++ copy_samples(am->nb_in_ch, am->route, ins, &outs, ns, 4); ++ break; ++ default: ++ copy_samples(am->nb_in_ch, am->route, ins, &outs, ns, am->bps); ++ break; ++ } ++ ++ nb_samples -= ns; ++ for (i = 0; i < 2; i++) { ++ am->queue[i].nb_samples -= ns; ++ am->queue[i].pos += ns; ++ if (am->queue[i].pos == (*inbuf[i])->audio->nb_samples) { ++ am->queue[i].pos = 0; ++ avfilter_unref_buffer(*inbuf[i]); ++ *inbuf[i] = NULL; ++ inbuf[i]++; ++ ins[i] = *inbuf[i] ? (*inbuf[i])->data[0] : NULL; ++ } ++ } ++ } ++ for (i = 0; i < 2; i++) { ++ int nbufused = inbuf[i] - am->queue[i].buf; ++ if (nbufused) { ++ am->queue[i].nb_buf -= nbufused; ++ memmove(am->queue[i].buf, inbuf[i], ++ am->queue[i].nb_buf * sizeof(**inbuf)); ++ } ++ } ++ avfilter_filter_samples(ctx->outputs[0], outbuf); ++} ++ ++AVFilter avfilter_af_amerge = { ++ .name = "amerge", ++ .description = NULL_IF_CONFIG_SMALL("Merge two audio streams into " ++ "a single multi-channel stream."), ++ .priv_size = sizeof(AMergeContext), ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "in1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = "in2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL } ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_output, ++ .request_frame = request_frame, }, ++ { .name = NULL } ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_anull.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_anull.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_anull.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_anull.c 2012-05-14 14:08:54.680346945 +0200 +@@ -29,13 +29,13 @@ + + .priv_size = 0, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .get_audio_buffer = avfilter_null_get_audio_buffer, + .filter_samples = avfilter_null_filter_samples }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aresample.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aresample.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_aresample.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_aresample.c 2012-05-14 14:08:54.681346965 +0200 +@@ -0,0 +1,348 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * resampling audio filter ++ */ ++ ++#include "libavutil/eval.h" ++#include "libavcodec/avcodec.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++typedef struct { ++ struct AVResampleContext *resample; ++ int out_rate; ++ double ratio; ++ AVFilterBufferRef *outsamplesref; ++ int unconsumed_nb_samples, ++ max_cached_nb_samples; ++ int16_t *cached_data[8], ++ *resampled_data[8]; ++} AResampleContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ AResampleContext *aresample = ctx->priv; ++ int ret; ++ ++ if (args) { ++ if ((ret = ff_parse_sample_rate(&aresample->out_rate, args, ctx)) < 0) ++ return ret; ++ } else { ++ aresample->out_rate = -1; ++ } ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ AResampleContext *aresample = ctx->priv; ++ if (aresample->outsamplesref) { ++ int nb_channels = ++ av_get_channel_layout_nb_channels( ++ aresample->outsamplesref->audio->channel_layout); ++ avfilter_unref_buffer(aresample->outsamplesref); ++ while (nb_channels--) { ++ av_freep(&(aresample->cached_data[nb_channels])); ++ av_freep(&(aresample->resampled_data[nb_channels])); ++ } ++ } ++ ++ if (aresample->resample) ++ av_resample_close(aresample->resample); ++} ++ ++static int config_output(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ AResampleContext *aresample = ctx->priv; ++ ++ if (aresample->out_rate == -1) ++ aresample->out_rate = outlink->sample_rate; ++ else ++ outlink->sample_rate = aresample->out_rate; ++ outlink->time_base = (AVRational) {1, aresample->out_rate}; ++ ++ //TODO: make the resampling parameters configurable ++ aresample->resample = av_resample_init(aresample->out_rate, inlink->sample_rate, ++ 16, 10, 0, 0.8); ++ ++ aresample->ratio = (double)outlink->sample_rate / inlink->sample_rate; ++ ++ av_log(ctx, AV_LOG_INFO, "r:%"PRId64"Hz -> r:%"PRId64"Hz\n", ++ inlink->sample_rate, outlink->sample_rate); ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats = NULL; ++ ++ avfilter_add_format(&formats, AV_SAMPLE_FMT_S16); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_sample_formats(ctx, formats); ++ ++ formats = avfilter_make_all_channel_layouts(); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ ++ formats = avfilter_make_all_packing_formats(); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++static void deinterleave(int16_t **outp, int16_t *in, ++ int nb_channels, int nb_samples) ++{ ++ int16_t *out[8]; ++ memcpy(out, outp, nb_channels * sizeof(int16_t*)); ++ ++ switch (nb_channels) { ++ case 2: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ } ++ break; ++ case 3: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ *out[2]++ = *in++; ++ } ++ break; ++ case 4: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ *out[2]++ = *in++; ++ *out[3]++ = *in++; ++ } ++ break; ++ case 5: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ *out[2]++ = *in++; ++ *out[3]++ = *in++; ++ *out[4]++ = *in++; ++ } ++ break; ++ case 6: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ *out[2]++ = *in++; ++ *out[3]++ = *in++; ++ *out[4]++ = *in++; ++ *out[5]++ = *in++; ++ } ++ break; ++ case 8: ++ while (nb_samples--) { ++ *out[0]++ = *in++; ++ *out[1]++ = *in++; ++ *out[2]++ = *in++; ++ *out[3]++ = *in++; ++ *out[4]++ = *in++; ++ *out[5]++ = *in++; ++ *out[6]++ = *in++; ++ *out[7]++ = *in++; ++ } ++ break; ++ } ++} ++ ++static void interleave(int16_t *out, int16_t **inp, ++ int nb_channels, int nb_samples) ++{ ++ int16_t *in[8]; ++ memcpy(in, inp, nb_channels * sizeof(int16_t*)); ++ ++ switch (nb_channels) { ++ case 2: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ } ++ break; ++ case 3: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ *out++ = *in[2]++; ++ } ++ break; ++ case 4: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ *out++ = *in[2]++; ++ *out++ = *in[3]++; ++ } ++ break; ++ case 5: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ *out++ = *in[2]++; ++ *out++ = *in[3]++; ++ *out++ = *in[4]++; ++ } ++ break; ++ case 6: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ *out++ = *in[2]++; ++ *out++ = *in[3]++; ++ *out++ = *in[4]++; ++ *out++ = *in[5]++; ++ } ++ break; ++ case 8: ++ while (nb_samples--) { ++ *out++ = *in[0]++; ++ *out++ = *in[1]++; ++ *out++ = *in[2]++; ++ *out++ = *in[3]++; ++ *out++ = *in[4]++; ++ *out++ = *in[5]++; ++ *out++ = *in[6]++; ++ *out++ = *in[7]++; ++ } ++ break; ++ } ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamplesref) ++{ ++ AResampleContext *aresample = inlink->dst->priv; ++ AVFilterLink * const outlink = inlink->dst->outputs[0]; ++ int i, ++ in_nb_samples = insamplesref->audio->nb_samples, ++ cached_nb_samples = in_nb_samples + aresample->unconsumed_nb_samples, ++ requested_out_nb_samples = aresample->ratio * cached_nb_samples, ++ nb_channels = ++ av_get_channel_layout_nb_channels(inlink->channel_layout); ++ ++ if (cached_nb_samples > aresample->max_cached_nb_samples) { ++ for (i = 0; i < nb_channels; i++) { ++ aresample->cached_data[i] = ++ av_realloc(aresample->cached_data[i], cached_nb_samples * sizeof(int16_t)); ++ aresample->resampled_data[i] = ++ av_realloc(aresample->resampled_data[i], ++ FFALIGN(sizeof(int16_t) * requested_out_nb_samples, 16)); ++ ++ if (aresample->cached_data[i] == NULL || aresample->resampled_data[i] == NULL) ++ return; ++ } ++ aresample->max_cached_nb_samples = cached_nb_samples; ++ ++ if (aresample->outsamplesref) ++ avfilter_unref_buffer(aresample->outsamplesref); ++ ++ aresample->outsamplesref = ++ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, requested_out_nb_samples); ++ outlink->out_buf = aresample->outsamplesref; ++ } ++ ++ avfilter_copy_buffer_ref_props(aresample->outsamplesref, insamplesref); ++ aresample->outsamplesref->audio->sample_rate = outlink->sample_rate; ++ aresample->outsamplesref->pts = ++ av_rescale(outlink->sample_rate, insamplesref->pts, inlink->sample_rate); ++ ++ /* av_resample() works with planar audio buffers */ ++ if (!inlink->planar && nb_channels > 1) { ++ int16_t *out[8]; ++ for (i = 0; i < nb_channels; i++) ++ out[i] = aresample->cached_data[i] + aresample->unconsumed_nb_samples; ++ ++ deinterleave(out, (int16_t *)insamplesref->data[0], ++ nb_channels, in_nb_samples); ++ } else { ++ for (i = 0; i < nb_channels; i++) ++ memcpy(aresample->cached_data[i] + aresample->unconsumed_nb_samples, ++ insamplesref->data[i], ++ in_nb_samples * sizeof(int16_t)); ++ } ++ ++ for (i = 0; i < nb_channels; i++) { ++ int consumed_nb_samples; ++ const int is_last = i+1 == nb_channels; ++ ++ aresample->outsamplesref->audio->nb_samples = ++ av_resample(aresample->resample, ++ aresample->resampled_data[i], aresample->cached_data[i], ++ &consumed_nb_samples, ++ cached_nb_samples, ++ requested_out_nb_samples, is_last); ++ ++ /* move unconsumed data back to the beginning of the cache */ ++ aresample->unconsumed_nb_samples = cached_nb_samples - consumed_nb_samples; ++ memmove(aresample->cached_data[i], ++ aresample->cached_data[i] + consumed_nb_samples, ++ aresample->unconsumed_nb_samples * sizeof(int16_t)); ++ } ++ ++ ++ /* copy resampled data to the output samplesref */ ++ if (!inlink->planar && nb_channels > 1) { ++ interleave((int16_t *)aresample->outsamplesref->data[0], ++ aresample->resampled_data, ++ nb_channels, aresample->outsamplesref->audio->nb_samples); ++ } else { ++ for (i = 0; i < nb_channels; i++) ++ memcpy(aresample->outsamplesref->data[i], aresample->resampled_data[i], ++ aresample->outsamplesref->audio->nb_samples * sizeof(int16_t)); ++ } ++ ++ avfilter_filter_samples(outlink, avfilter_ref_buffer(aresample->outsamplesref, ~0)); ++ avfilter_unref_buffer(insamplesref); ++} ++ ++AVFilter avfilter_af_aresample = { ++ .name = "aresample", ++ .description = NULL_IF_CONFIG_SMALL("Resample audio data."), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ .priv_size = sizeof(AResampleContext), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .config_props = config_output, ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_ashowinfo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_ashowinfo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_ashowinfo.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_ashowinfo.c 2012-05-14 14:08:54.682346985 +0200 +@@ -0,0 +1,103 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * filter for showing textual audio frame information ++ */ ++ ++#include "libavutil/adler32.h" ++#include "libavutil/audioconvert.h" ++#include "avfilter.h" ++ ++typedef struct { ++ unsigned int frame; ++} ShowInfoContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ ShowInfoContext *showinfo = ctx->priv; ++ showinfo->frame = 0; ++ return 0; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ ShowInfoContext *showinfo = ctx->priv; ++ uint32_t plane_checksum[8] = {0}, checksum = 0; ++ char chlayout_str[128]; ++ int plane; ++ int linesize = ++ samplesref->audio->nb_samples * ++ av_get_bytes_per_sample(samplesref->format); ++ if (!samplesref->audio->planar) /* packed layout */ ++ linesize *= av_get_channel_layout_nb_channels(samplesref->audio->channel_layout); ++ ++ for (plane = 0; samplesref->data[plane] && plane < 8; plane++) { ++ uint8_t *data = samplesref->data[plane]; ++ ++ plane_checksum[plane] = av_adler32_update(plane_checksum[plane], ++ data, linesize); ++ checksum = av_adler32_update(checksum, data, linesize); ++ } ++ ++ av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), -1, ++ samplesref->audio->channel_layout); ++ ++ av_log(ctx, AV_LOG_INFO, ++ "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" " ++ "fmt:%s chlayout:%s nb_samples:%d rate:%d planar:%d " ++ "checksum:%08X plane_checksum[%08X %08X %08X %08X %08X %08X %08X %08X]\n", ++ showinfo->frame, ++ samplesref->pts, samplesref->pts * av_q2d(inlink->time_base), ++ samplesref->pos, ++ av_get_sample_fmt_name(samplesref->format), ++ chlayout_str, ++ samplesref->audio->nb_samples, ++ samplesref->audio->sample_rate, ++ samplesref->audio->planar, ++ checksum, ++ plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3], ++ plane_checksum[4], plane_checksum[5], plane_checksum[6], plane_checksum[7]); ++ ++ showinfo->frame++; ++ ++ avfilter_filter_samples(inlink->dst->outputs[0], samplesref); ++} ++ ++AVFilter avfilter_af_ashowinfo = { ++ .name = "ashowinfo", ++ .description = NULL_IF_CONFIG_SMALL("Show textual information for each audio frame."), ++ ++ .priv_size = sizeof(ShowInfoContext), ++ .init = init, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .get_audio_buffer = avfilter_null_get_audio_buffer, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_asplit.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_asplit.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_asplit.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_asplit.c 2012-05-14 14:08:54.682346985 +0200 +@@ -0,0 +1,55 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio splitter ++ */ ++ ++#include "avfilter.h" ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ avfilter_filter_samples(inlink->dst->outputs[0], ++ avfilter_ref_buffer(insamples, ~AV_PERM_WRITE)); ++ avfilter_filter_samples(inlink->dst->outputs[1], ++ avfilter_ref_buffer(insamples, ~AV_PERM_WRITE)); ++ avfilter_unref_buffer(insamples); ++} ++ ++AVFilter avfilter_af_asplit = { ++ .name = "asplit", ++ .description = NULL_IF_CONFIG_SMALL("Pass on the audio input to two outputs."), ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .get_audio_buffer = avfilter_null_get_audio_buffer, ++ .filter_samples = filter_samples, }, ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "output1", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = "output2", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_astreamsync.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_astreamsync.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_astreamsync.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_astreamsync.c 2012-05-14 14:08:54.683347005 +0200 +@@ -0,0 +1,208 @@ ++/* ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Stream (de)synchronization filter ++ */ ++ ++#include "libavutil/eval.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++#define QUEUE_SIZE 16 ++ ++static const char * const var_names[] = { ++ "b1", "b2", ++ "s1", "s2", ++ "t1", "t2", ++ NULL ++}; ++ ++enum var_name { ++ VAR_B1, VAR_B2, ++ VAR_S1, VAR_S2, ++ VAR_T1, VAR_T2, ++ VAR_NB ++}; ++ ++typedef struct { ++ AVExpr *expr; ++ double var_values[VAR_NB]; ++ struct buf_queue { ++ AVFilterBufferRef *buf[QUEUE_SIZE]; ++ unsigned tail, nb; ++ /* buf[tail] is the oldest, ++ buf[(tail + nb) % QUEUE_SIZE] is where the next is added */ ++ } queue[2]; ++ int req[2]; ++ int next_out; ++ int eof; /* bitmask, one bit for each stream */ ++} AStreamSyncContext; ++ ++static const char *default_expr = "t1-t2"; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque) ++{ ++ AStreamSyncContext *as = ctx->priv; ++ const char *expr = args0 ? args0 : default_expr; ++ int r, i; ++ ++ r = av_expr_parse(&as->expr, expr, var_names, ++ NULL, NULL, NULL, NULL, 0, ctx); ++ if (r < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error in expression \"%s\"\n", expr); ++ return r; ++ } ++ for (i = 0; i < 42; i++) ++ av_expr_eval(as->expr, as->var_values, NULL); /* exercize prng */ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ int i; ++ AVFilterFormats *formats; ++ ++ for (i = 0; i < 2; i++) { ++ formats = ctx->inputs[i]->in_formats; ++ avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats); ++ avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats); ++ formats = ctx->inputs[i]->in_packing; ++ avfilter_formats_ref(formats, &ctx->inputs[i]->out_packing); ++ avfilter_formats_ref(formats, &ctx->outputs[i]->in_packing); ++ formats = ctx->inputs[i]->in_chlayouts; ++ avfilter_formats_ref(formats, &ctx->inputs[i]->out_chlayouts); ++ avfilter_formats_ref(formats, &ctx->outputs[i]->in_chlayouts); ++ } ++ return 0; ++} ++ ++static int config_output(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ int id = outlink == ctx->outputs[1]; ++ ++ outlink->sample_rate = ctx->inputs[id]->sample_rate; ++ outlink->time_base = ctx->inputs[id]->time_base; ++ return 0; ++} ++ ++static void send_out(AVFilterContext *ctx, int out_id) ++{ ++ AStreamSyncContext *as = ctx->priv; ++ struct buf_queue *queue = &as->queue[out_id]; ++ AVFilterBufferRef *buf = queue->buf[queue->tail]; ++ ++ queue->buf[queue->tail] = NULL; ++ as->var_values[VAR_B1 + out_id]++; ++ as->var_values[VAR_S1 + out_id] += buf->audio->nb_samples; ++ if (buf->pts != AV_NOPTS_VALUE) ++ as->var_values[VAR_T1 + out_id] = ++ av_q2d(ctx->outputs[out_id]->time_base) * buf->pts; ++ as->var_values[VAR_T1 + out_id] += buf->audio->nb_samples / ++ (double)ctx->inputs[out_id]->sample_rate; ++ avfilter_filter_samples(ctx->outputs[out_id], buf); ++ queue->nb--; ++ queue->tail = (queue->tail + 1) % QUEUE_SIZE; ++ if (as->req[out_id]) ++ as->req[out_id]--; ++} ++ ++static void send_next(AVFilterContext *ctx) ++{ ++ AStreamSyncContext *as = ctx->priv; ++ int i; ++ ++ while (1) { ++ if (!as->queue[as->next_out].nb) ++ break; ++ send_out(ctx, as->next_out); ++ if (!as->eof) ++ as->next_out = av_expr_eval(as->expr, as->var_values, NULL) >= 0; ++ } ++ for (i = 0; i < 2; i++) ++ if (as->queue[i].nb == QUEUE_SIZE) ++ send_out(ctx, i); ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ AStreamSyncContext *as = ctx->priv; ++ int id = outlink == ctx->outputs[1]; ++ ++ as->req[id]++; ++ while (as->req[id] && !(as->eof & (1 << id))) { ++ if (as->queue[as->next_out].nb) { ++ send_next(ctx); ++ } else { ++ as->eof |= 1 << as->next_out; ++ avfilter_request_frame(ctx->inputs[as->next_out]); ++ if (as->eof & (1 << as->next_out)) ++ as->next_out = !as->next_out; ++ } ++ } ++ return 0; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AStreamSyncContext *as = ctx->priv; ++ int id = inlink == ctx->inputs[1]; ++ ++ as->queue[id].buf[(as->queue[id].tail + as->queue[id].nb++) % QUEUE_SIZE] = ++ insamples; ++ as->eof &= ~(1 << id); ++ send_next(ctx); ++} ++ ++AVFilter avfilter_af_astreamsync = { ++ .name = "astreamsync", ++ .description = NULL_IF_CONFIG_SMALL("Copy two streams of audio data " ++ "in a configurable order."), ++ .priv_size = sizeof(AStreamSyncContext), ++ .init = init, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "in1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = "in2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL } ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "out1", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_output, ++ .request_frame = request_frame, }, ++ { .name = "out2", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_output, ++ .request_frame = request_frame, }, ++ { .name = NULL } ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_earwax.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_earwax.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_earwax.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_earwax.c 2012-05-14 14:08:54.684347026 +0200 +@@ -0,0 +1,163 @@ ++/* ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * Copyright (c) 2000 Edward Beingessner And Sundry Contributors. ++ * This source code is freely redistributable and may be used for any purpose. ++ * This copyright notice must be maintained. Edward Beingessner And Sundry ++ * Contributors are not responsible for the consequences of using this ++ * software. ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Stereo Widening Effect. Adds audio cues to move stereo image in ++ * front of the listener. Adapted from the libsox earwax effect. ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "avfilter.h" ++ ++#define NUMTAPS 64 ++ ++static const int8_t filt[NUMTAPS] = { ++/* 30° 330° */ ++ 4, -6, /* 32 tap stereo FIR filter. */ ++ 4, -11, /* One side filters as if the */ ++ -1, -5, /* signal was from 30 degrees */ ++ 3, 3, /* from the ear, the other as */ ++ -2, 5, /* if 330 degrees. */ ++ -5, 0, ++ 9, 1, ++ 6, 3, /* Input */ ++ -4, -1, /* Left Right */ ++ -5, -3, /* __________ __________ */ ++ -2, -5, /* | | | | */ ++ -7, 1, /* .---| Hh,0(f) | | Hh,0(f) |---. */ ++ 6, -7, /* / |__________| |__________| \ */ ++ 30, -29, /* / \ / \ */ ++ 12, -3, /* / X \ */ ++ -11, 4, /* / / \ \ */ ++ -3, 7, /* ____V_____ __________V V__________ _____V____ */ ++ -20, 23, /* | | | | | | | | */ ++ 2, 0, /* | Hh,30(f) | | Hh,330(f)| | Hh,330(f)| | Hh,30(f) | */ ++ 1, -6, /* |__________| |__________| |__________| |__________| */ ++ -14, -5, /* \ ___ / \ ___ / */ ++ 15, -18, /* \ / \ / _____ \ / \ / */ ++ 6, 7, /* `->| + |<--' / \ `-->| + |<-' */ ++ 15, -10, /* \___/ _/ \_ \___/ */ ++ -14, 22, /* \ / \ / \ / */ ++ -7, -2, /* `--->| | | |<---' */ ++ -4, 9, /* \_/ \_/ */ ++ 6, -12, /* */ ++ 6, -6, /* Headphones */ ++ 0, -11, ++ 0, -5, ++ 4, 0}; ++ ++typedef struct { ++ int16_t taps[NUMTAPS * 2]; ++} EarwaxContext; ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats = NULL; ++ avfilter_add_format(&formats, AV_SAMPLE_FMT_S16); ++ avfilter_set_common_sample_formats(ctx, formats); ++ formats = NULL; ++ avfilter_add_format(&formats, AV_CH_LAYOUT_STEREO); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ formats = NULL; ++ avfilter_add_format(&formats, AVFILTER_PACKED); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ if (inlink->sample_rate != 44100) { ++ av_log(inlink->dst, AV_LOG_ERROR, ++ "The earwax filter only works for 44.1kHz audio. Insert " ++ "a resample filter before this\n"); ++ return AVERROR(EINVAL); ++ } ++ return 0; ++} ++ ++//FIXME: replace with DSPContext.scalarproduct_int16 ++static inline int16_t *scalarproduct(const int16_t *in, const int16_t *endin, int16_t *out) ++{ ++ int32_t sample; ++ int16_t j; ++ ++ while (in < endin) { ++ sample = 32; ++ for (j = 0; j < NUMTAPS; j++) ++ sample += in[j] * filt[j]; ++ *out = sample >> 6; ++ out++; ++ in++; ++ } ++ ++ return out; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ int16_t *taps, *endin, *in, *out; ++ AVFilterBufferRef *outsamples = ++ avfilter_get_audio_buffer(inlink, AV_PERM_WRITE, ++ insamples->audio->nb_samples); ++ avfilter_copy_buffer_ref_props(outsamples, insamples); ++ ++ taps = ((EarwaxContext *)inlink->dst->priv)->taps; ++ out = (int16_t *)outsamples->data[0]; ++ in = (int16_t *)insamples ->data[0]; ++ ++ // copy part of new input and process with saved input ++ memcpy(taps+NUMTAPS, in, NUMTAPS * sizeof(*taps)); ++ out = scalarproduct(taps, taps + NUMTAPS, out); ++ ++ // process current input ++ endin = in + insamples->audio->nb_samples * 2 - NUMTAPS; ++ out = scalarproduct(in, endin, out); ++ ++ // save part of input for next round ++ memcpy(taps, endin, NUMTAPS * sizeof(*taps)); ++ ++ avfilter_filter_samples(outlink, outsamples); ++ avfilter_unref_buffer(insamples); ++} ++ ++AVFilter avfilter_af_earwax = { ++ .name = "earwax", ++ .description = NULL_IF_CONFIG_SMALL("Widen the stereo image."), ++ .query_formats = query_formats, ++ .priv_size = sizeof(EarwaxContext), ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .config_props = config_input, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_pan.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_pan.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_pan.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_pan.c 2012-05-14 14:08:54.685347046 +0200 +@@ -0,0 +1,428 @@ ++/* ++ * Copyright (c) 2002 Anders Johansson ++ * Copyright (c) 2011 Clément BÅ“sch ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Audio panning filter (channels mixing) ++ * Original code written by Anders Johansson for MPlayer, ++ * reimplemented for FFmpeg. ++ */ ++ ++#include ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++#include "libswresample/swresample.h" ++#include "avfilter.h" ++ ++#define MAX_CHANNELS 63 ++ ++typedef struct PanContext { ++ int64_t out_channel_layout; ++ union { ++ double d[MAX_CHANNELS][MAX_CHANNELS]; ++ // i is 1:7:8 fixed-point, i.e. in [-128*256; +128*256[ ++ int i[MAX_CHANNELS][MAX_CHANNELS]; ++ } gain; ++ int64_t need_renorm; ++ int need_renumber; ++ int nb_input_channels; ++ int nb_output_channels; ++ ++ int pure_gains; ++ void (*filter_samples)(struct PanContext*, ++ AVFilterBufferRef*, ++ AVFilterBufferRef*, ++ int); ++ ++ /* channel mapping specific */ ++ int channel_map[SWR_CH_MAX]; ++ struct SwrContext *swr; ++} PanContext; ++ ++static int parse_channel_name(char **arg, int *rchannel, int *rnamed) ++{ ++ char buf[8]; ++ int len, i, channel_id; ++ int64_t layout, layout0; ++ ++ if (sscanf(*arg, " %7[A-Z] %n", buf, &len)) { ++ layout0 = layout = av_get_channel_layout(buf); ++ for (i = 32; i > 0; i >>= 1) { ++ if (layout >= (int64_t)1 << i) { ++ channel_id += i; ++ layout >>= i; ++ } ++ } ++ if (channel_id >= MAX_CHANNELS || layout0 != (int64_t)1 << channel_id) ++ return AVERROR(EINVAL); ++ *rchannel = channel_id; ++ *rnamed = 1; ++ *arg += len; ++ return 0; ++ } ++ if (sscanf(*arg, " c%d %n", &channel_id, &len) && ++ channel_id >= 0 && channel_id < MAX_CHANNELS) { ++ *rchannel = channel_id; ++ *rnamed = 0; ++ *arg += len; ++ return 0; ++ } ++ return AVERROR(EINVAL); ++} ++ ++static void skip_spaces(char **arg) ++{ ++ int len = 0; ++ ++ sscanf(*arg, " %n", &len); ++ *arg += len; ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque) ++{ ++ PanContext *const pan = ctx->priv; ++ char *arg, *arg0, *tokenizer, *args = av_strdup(args0); ++ int out_ch_id, in_ch_id, len, named; ++ int nb_in_channels[2] = { 0, 0 }; // number of unnamed and named input channels ++ double gain; ++ ++ if (!args0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "pan filter needs a channel layout and a set " ++ "of channels definitions as parameter\n"); ++ return AVERROR(EINVAL); ++ } ++ if (!args) ++ return AVERROR(ENOMEM); ++ arg = av_strtok(args, ":", &tokenizer); ++ pan->out_channel_layout = av_get_channel_layout(arg); ++ if (!pan->out_channel_layout) { ++ av_log(ctx, AV_LOG_ERROR, "Unknown channel layout \"%s\"\n", arg); ++ return AVERROR(EINVAL); ++ } ++ pan->nb_output_channels = av_get_channel_layout_nb_channels(pan->out_channel_layout); ++ ++ /* parse channel specifications */ ++ while ((arg = arg0 = av_strtok(NULL, ":", &tokenizer))) { ++ /* channel name */ ++ if (parse_channel_name(&arg, &out_ch_id, &named)) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Expected out channel name, got \"%.8s\"\n", arg); ++ return AVERROR(EINVAL); ++ } ++ if (named) { ++ if (!((pan->out_channel_layout >> out_ch_id) & 1)) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Channel \"%.8s\" does not exist in the chosen layout\n", arg0); ++ return AVERROR(EINVAL); ++ } ++ /* get the channel number in the output channel layout: ++ * out_channel_layout & ((1 << out_ch_id) - 1) are all the ++ * channels that come before out_ch_id, ++ * so their count is the index of out_ch_id */ ++ out_ch_id = av_get_channel_layout_nb_channels(pan->out_channel_layout & (((int64_t)1 << out_ch_id) - 1)); ++ } ++ if (out_ch_id < 0 || out_ch_id >= pan->nb_output_channels) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid out channel name \"%.8s\"\n", arg0); ++ return AVERROR(EINVAL); ++ } ++ if (*arg == '=') { ++ arg++; ++ } else if (*arg == '<') { ++ pan->need_renorm |= (int64_t)1 << out_ch_id; ++ arg++; ++ } else { ++ av_log(ctx, AV_LOG_ERROR, ++ "Syntax error after channel name in \"%.8s\"\n", arg0); ++ return AVERROR(EINVAL); ++ } ++ /* gains */ ++ while (1) { ++ gain = 1; ++ if (sscanf(arg, " %lf %n* %n", &gain, &len, &len)) ++ arg += len; ++ if (parse_channel_name(&arg, &in_ch_id, &named)){ ++ av_log(ctx, AV_LOG_ERROR, ++ "Expected in channel name, got \"%.8s\"\n", arg); ++ return AVERROR(EINVAL); ++ } ++ nb_in_channels[named]++; ++ if (nb_in_channels[!named]) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Can not mix named and numbered channels\n"); ++ return AVERROR(EINVAL); ++ } ++ pan->gain.d[out_ch_id][in_ch_id] = gain; ++ if (!*arg) ++ break; ++ if (*arg != '+') { ++ av_log(ctx, AV_LOG_ERROR, "Syntax error near \"%.8s\"\n", arg); ++ return AVERROR(EINVAL); ++ } ++ arg++; ++ skip_spaces(&arg); ++ } ++ } ++ pan->need_renumber = !!nb_in_channels[1]; ++ ++ av_free(args); ++ return 0; ++} ++ ++static int are_gains_pure(const PanContext *pan) ++{ ++ int i, j; ++ ++ for (i = 0; i < MAX_CHANNELS; i++) { ++ int nb_gain = 0; ++ ++ for (j = 0; j < MAX_CHANNELS; j++) { ++ double gain = pan->gain.d[i][j]; ++ ++ /* channel mapping is effective only if 0% or 100% of a channel is ++ * selected... */ ++ if (gain != 0. && gain != 1.) ++ return 0; ++ /* ...and if the output channel is only composed of one input */ ++ if (gain && nb_gain++) ++ return 0; ++ } ++ } ++ return 1; ++} ++ ++static int config_props(AVFilterLink *link) ++{ ++ AVFilterContext *ctx = link->dst; ++ PanContext *pan = ctx->priv; ++ char buf[1024], *cur; ++ int i, j, k, r; ++ double t; ++ ++ pan->nb_input_channels = av_get_channel_layout_nb_channels(link->channel_layout); ++ if (pan->need_renumber) { ++ // input channels were given by their name: renumber them ++ for (i = j = 0; i < MAX_CHANNELS; i++) { ++ if ((link->channel_layout >> i) & 1) { ++ for (k = 0; k < pan->nb_output_channels; k++) ++ pan->gain.d[k][j] = pan->gain.d[k][i]; ++ j++; ++ } ++ } ++ } ++ // gains are pure, init the channel mapping ++ if (pan->pure_gains) { ++ ++ // sanity check; can't be done in query_formats since the inlink ++ // channel layout is unknown at that time ++ if (pan->nb_input_channels > SWR_CH_MAX) { ++ av_log(ctx, AV_LOG_ERROR, ++ "libswresample support a maximum of %d channels. " ++ "Feel free to ask for a higher limit.\n", SWR_CH_MAX); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ // get channel map from the pure gains ++ for (i = 0; i < pan->nb_output_channels; i++) { ++ int ch_id = -1; ++ for (j = 0; j < pan->nb_input_channels; j++) { ++ if (pan->gain.d[i][j]) { ++ ch_id = j; ++ break; ++ } ++ } ++ pan->channel_map[i] = ch_id; ++ } ++ ++ // init libswresample context ++ pan->swr = swr_alloc_set_opts(pan->swr, ++ pan->out_channel_layout, link->format, link->sample_rate, ++ link->channel_layout, link->format, link->sample_rate, ++ 0, ctx); ++ if (!pan->swr) ++ return AVERROR(ENOMEM); ++ av_opt_set_int(pan->swr, "icl", pan->out_channel_layout, 0); ++ av_opt_set_int(pan->swr, "uch", pan->nb_output_channels, 0); ++ swr_set_channel_mapping(pan->swr, pan->channel_map); ++ r = swr_init(pan->swr); ++ if (r < 0) ++ return r; ++ } else { ++ // renormalize ++ for (i = 0; i < pan->nb_output_channels; i++) { ++ if (!((pan->need_renorm >> i) & 1)) ++ continue; ++ t = 0; ++ for (j = 0; j < pan->nb_input_channels; j++) ++ t += pan->gain.d[i][j]; ++ if (t > -1E-5 && t < 1E-5) { ++ // t is almost 0 but not exactly, this is probably a mistake ++ if (t) ++ av_log(ctx, AV_LOG_WARNING, ++ "Degenerate coefficients while renormalizing\n"); ++ continue; ++ } ++ for (j = 0; j < pan->nb_input_channels; j++) ++ pan->gain.d[i][j] /= t; ++ } ++ } ++ // summary ++ for (i = 0; i < pan->nb_output_channels; i++) { ++ cur = buf; ++ for (j = 0; j < pan->nb_input_channels; j++) { ++ r = snprintf(cur, buf + sizeof(buf) - cur, "%s%.3g i%d", ++ j ? " + " : "", pan->gain.d[i][j], j); ++ cur += FFMIN(buf + sizeof(buf) - cur, r); ++ } ++ av_log(ctx, AV_LOG_INFO, "o%d = %s\n", i, buf); ++ } ++ // add channel mapping summary if possible ++ if (pan->pure_gains) { ++ av_log(ctx, AV_LOG_INFO, "Pure channel mapping detected:"); ++ for (i = 0; i < pan->nb_output_channels; i++) ++ if (pan->channel_map[i] < 0) ++ av_log(ctx, AV_LOG_INFO, " M"); ++ else ++ av_log(ctx, AV_LOG_INFO, " %d", pan->channel_map[i]); ++ av_log(ctx, AV_LOG_INFO, "\n"); ++ return 0; ++ } ++ // convert to integer ++ for (i = 0; i < pan->nb_output_channels; i++) { ++ for (j = 0; j < pan->nb_input_channels; j++) { ++ if (pan->gain.d[i][j] < -128 || pan->gain.d[i][j] > 128) ++ av_log(ctx, AV_LOG_WARNING, ++ "Gain #%d->#%d too large, clamped\n", j, i); ++ pan->gain.i[i][j] = av_clipf(pan->gain.d[i][j], -128, 128) * 256.0; ++ } ++ } ++ return 0; ++} ++ ++static void filter_samples_channel_mapping(PanContext *pan, ++ AVFilterBufferRef *outsamples, ++ AVFilterBufferRef *insamples, ++ int n) ++{ ++ swr_convert(pan->swr, outsamples->data, n, (void *)insamples->data, n); ++} ++ ++static void filter_samples_panning(PanContext *pan, ++ AVFilterBufferRef *outsamples, ++ AVFilterBufferRef *insamples, ++ int n) ++{ ++ int i, o; ++ ++ /* input */ ++ const int16_t *in = (int16_t *)insamples->data[0]; ++ const int16_t *in_end = in + n * pan->nb_input_channels; ++ ++ /* output */ ++ int16_t *out = (int16_t *)outsamples->data[0]; ++ ++ for (; in < in_end; in += pan->nb_input_channels) { ++ for (o = 0; o < pan->nb_output_channels; o++) { ++ int v = 0; ++ for (i = 0; i < pan->nb_input_channels; i++) ++ v += pan->gain.i[o][i] * in[i]; ++ *(out++) = v >> 8; ++ } ++ } ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ int n = insamples->audio->nb_samples; ++ AVFilterLink *const outlink = inlink->dst->outputs[0]; ++ AVFilterBufferRef *outsamples = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, n); ++ PanContext *pan = inlink->dst->priv; ++ ++ pan->filter_samples(pan, outsamples, insamples, n); ++ ++ avfilter_filter_samples(outlink, outsamples); ++ avfilter_unref_buffer(insamples); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ PanContext *pan = ctx->priv; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ AVFilterFormats *formats; ++ ++ if (pan->nb_output_channels <= SWR_CH_MAX) ++ pan->pure_gains = are_gains_pure(pan); ++ if (pan->pure_gains) { ++ /* libswr supports any sample and packing formats */ ++ avfilter_set_common_sample_formats(ctx, avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO)); ++ avfilter_set_common_packing_formats(ctx, avfilter_make_all_packing_formats()); ++ pan->filter_samples = filter_samples_channel_mapping; ++ } else { ++ const enum AVSampleFormat sample_fmts[] = {AV_SAMPLE_FMT_S16, -1}; ++ const int packing_fmts[] = {AVFILTER_PACKED, -1}; ++ ++ avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts)); ++ avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts)); ++ pan->filter_samples = filter_samples_panning; ++ } ++ ++ // inlink supports any channel layout ++ formats = avfilter_make_all_channel_layouts(); ++ avfilter_formats_ref(formats, &inlink->out_chlayouts); ++ ++ // outlink supports only requested output channel layout ++ formats = NULL; ++ avfilter_add_format(&formats, pan->out_channel_layout); ++ avfilter_formats_ref(formats, &outlink->in_chlayouts); ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ PanContext *pan = ctx->priv; ++ swr_free(&pan->swr); ++} ++ ++AVFilter avfilter_af_pan = { ++ .name = "pan", ++ .description = NULL_IF_CONFIG_SMALL("Remix channels with coefficients (panning)."), ++ .priv_size = sizeof(PanContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_props, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_silencedetect.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_silencedetect.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_silencedetect.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_silencedetect.c 2012-05-14 14:08:54.686347066 +0200 +@@ -0,0 +1,175 @@ ++/* ++ * Copyright (c) 2012 Clément BÅ“sch ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Audio silence detector ++ */ ++ ++#include "libavutil/opt.h" ++#include "avfilter.h" ++ ++typedef struct { ++ const AVClass *class; ++ char *noise_str; ///< noise option string ++ double noise; ///< noise amplitude ratio ++ int duration; ///< minimum duration of silence until notification ++ int64_t nb_null_samples; ///< current number of continuous zero samples ++ double start; ///< if silence is detected, this value contains the time of the first zero sample ++ int last_sample_rate; ///< last sample rate to check for sample rate changes ++} SilenceDetectContext; ++ ++#define OFFSET(x) offsetof(SilenceDetectContext, x) ++static const AVOption silencedetect_options[] = { ++ { "n", "set noise tolerance", OFFSET(noise_str), AV_OPT_TYPE_STRING, {.str="-60dB"}, CHAR_MIN, CHAR_MAX }, ++ { "noise", "set noise tolerance", OFFSET(noise_str), AV_OPT_TYPE_STRING, {.str="-60dB"}, CHAR_MIN, CHAR_MAX }, ++ { "d", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_INT, {.dbl=2}, 0, INT_MAX}, ++ { "duration", "set minimum duration in seconds", OFFSET(duration), AV_OPT_TYPE_INT, {.dbl=2}, 0, INT_MAX}, ++ { NULL }, ++}; ++ ++static const char *silencedetect_get_name(void *ctx) ++{ ++ return "silencedetect"; ++} ++ ++static const AVClass silencedetect_class = { ++ .class_name = "SilenceDetectContext", ++ .item_name = silencedetect_get_name, ++ .option = silencedetect_options, ++}; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ int ret; ++ char *tail; ++ SilenceDetectContext *silence = ctx->priv; ++ ++ silence->class = &silencedetect_class; ++ av_opt_set_defaults(silence); ++ ++ if ((ret = av_set_options_string(silence, args, "=", ":")) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ silence->noise = strtod(silence->noise_str, &tail); ++ if (!strcmp(tail, "dB")) { ++ silence->noise = pow(10, silence->noise/20); ++ } else if (*tail) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for noise parameter.\n", ++ silence->noise_str); ++ return AVERROR(EINVAL); ++ } ++ ++ return 0; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ int i; ++ SilenceDetectContext *silence = inlink->dst->priv; ++ const int nb_channels = av_get_channel_layout_nb_channels(inlink->channel_layout); ++ const int srate = inlink->sample_rate; ++ const int nb_samples = insamples->audio->nb_samples * nb_channels; ++ const int64_t nb_samples_notify = srate * silence->duration * nb_channels; ++ ++ // scale number of null samples to the new sample rate ++ if (silence->last_sample_rate && silence->last_sample_rate != srate) ++ silence->nb_null_samples = ++ srate * silence->nb_null_samples / silence->last_sample_rate; ++ silence->last_sample_rate = srate; ++ ++ // TODO: support more sample formats ++ if (insamples->format == AV_SAMPLE_FMT_DBL) { ++ double *p = (double *)insamples->data[0]; ++ ++ for (i = 0; i < nb_samples; i++, p++) { ++ if (*p < silence->noise && *p > -silence->noise) { ++ if (!silence->start) { ++ silence->nb_null_samples++; ++ if (silence->nb_null_samples >= nb_samples_notify) { ++ silence->start = insamples->pts * av_q2d(inlink->time_base) - silence->duration; ++ av_log(silence, AV_LOG_INFO, ++ "silence_start: %f\n", silence->start); ++ } ++ } ++ } else { ++ if (silence->start) { ++ double end = insamples->pts * av_q2d(inlink->time_base); ++ av_log(silence, AV_LOG_INFO, ++ "silence_end: %f | silence_duration: %f\n", ++ end, end - silence->start); ++ } ++ silence->nb_null_samples = silence->start = 0; ++ } ++ } ++ } ++ ++ avfilter_filter_samples(inlink->dst->outputs[0], insamples); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats = NULL; ++ enum AVSampleFormat sample_fmts[] = { ++ AV_SAMPLE_FMT_DBL, ++ AV_SAMPLE_FMT_NONE ++ }; ++ int packing_fmts[] = { AVFILTER_PACKED, -1 }; ++ ++ formats = avfilter_make_all_channel_layouts(); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ ++ formats = avfilter_make_format_list(sample_fmts); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_sample_formats(ctx, formats); ++ ++ formats = avfilter_make_format_list(packing_fmts); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++AVFilter avfilter_af_silencedetect = { ++ .name = "silencedetect", ++ .description = NULL_IF_CONFIG_SMALL("Detect silence."), ++ .priv_size = sizeof(SilenceDetectContext), ++ .init = init, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .get_audio_buffer = avfilter_null_get_audio_buffer, ++ .filter_samples = filter_samples, }, ++ { .name = NULL } ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL } ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_volume.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_volume.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/af_volume.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/af_volume.c 2012-05-14 14:08:54.687347086 +0200 +@@ -0,0 +1,189 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio volume filter ++ * based on ffmpeg.c code ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/eval.h" ++#include "avfilter.h" ++ ++typedef struct { ++ double volume; ++ int volume_i; ++} VolumeContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ VolumeContext *vol = ctx->priv; ++ char *tail; ++ int ret = 0; ++ ++ vol->volume = 1.0; ++ ++ if (args) { ++ /* parse the number as a decimal number */ ++ double d = strtod(args, &tail); ++ ++ if (*tail) { ++ if (!strcmp(tail, "dB")) { ++ /* consider the argument an adjustement in decibels */ ++ d = pow(10, d/20); ++ } else { ++ /* parse the argument as an expression */ ++ ret = av_expr_parse_and_eval(&d, args, NULL, NULL, ++ NULL, NULL, NULL, NULL, ++ NULL, 0, ctx); ++ } ++ } ++ ++ if (ret < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid volume argument '%s'\n", args); ++ return AVERROR(EINVAL); ++ } ++ ++ if (d < 0 || d > 65536) { /* 65536 = INT_MIN / (128 * 256) */ ++ av_log(ctx, AV_LOG_ERROR, ++ "Negative or too big volume value %f\n", d); ++ return AVERROR(EINVAL); ++ } ++ ++ vol->volume = d; ++ } ++ ++ vol->volume_i = (int)(vol->volume * 256 + 0.5); ++ av_log(ctx, AV_LOG_INFO, "volume=%f\n", vol->volume); ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats = NULL; ++ enum AVSampleFormat sample_fmts[] = { ++ AV_SAMPLE_FMT_U8, ++ AV_SAMPLE_FMT_S16, ++ AV_SAMPLE_FMT_S32, ++ AV_SAMPLE_FMT_FLT, ++ AV_SAMPLE_FMT_DBL, ++ AV_SAMPLE_FMT_NONE ++ }; ++ int packing_fmts[] = { AVFILTER_PACKED, -1 }; ++ ++ formats = avfilter_make_all_channel_layouts(); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ ++ formats = avfilter_make_format_list(sample_fmts); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_sample_formats(ctx, formats); ++ ++ formats = avfilter_make_format_list(packing_fmts); ++ if (!formats) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *insamples) ++{ ++ VolumeContext *vol = inlink->dst->priv; ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ const int nb_samples = insamples->audio->nb_samples * ++ av_get_channel_layout_nb_channels(insamples->audio->channel_layout); ++ const double volume = vol->volume; ++ const int volume_i = vol->volume_i; ++ int i; ++ ++ if (volume_i != 256) { ++ switch (insamples->format) { ++ case AV_SAMPLE_FMT_U8: ++ { ++ uint8_t *p = (void *)insamples->data[0]; ++ for (i = 0; i < nb_samples; i++) { ++ int v = (((*p - 128) * volume_i + 128) >> 8) + 128; ++ *p++ = av_clip_uint8(v); ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_S16: ++ { ++ int16_t *p = (void *)insamples->data[0]; ++ for (i = 0; i < nb_samples; i++) { ++ int v = ((int64_t)*p * volume_i + 128) >> 8; ++ *p++ = av_clip_int16(v); ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_S32: ++ { ++ int32_t *p = (void *)insamples->data[0]; ++ for (i = 0; i < nb_samples; i++) { ++ int64_t v = (((int64_t)*p * volume_i + 128) >> 8); ++ *p++ = av_clipl_int32(v); ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_FLT: ++ { ++ float *p = (void *)insamples->data[0]; ++ float scale = (float)volume; ++ for (i = 0; i < nb_samples; i++) { ++ *p++ *= scale; ++ } ++ break; ++ } ++ case AV_SAMPLE_FMT_DBL: ++ { ++ double *p = (void *)insamples->data[0]; ++ for (i = 0; i < nb_samples; i++) { ++ *p *= volume; ++ p++; ++ } ++ break; ++ } ++ } ++ } ++ avfilter_filter_samples(outlink, insamples); ++} ++ ++AVFilter avfilter_af_volume = { ++ .name = "volume", ++ .description = NULL_IF_CONFIG_SMALL("Change input volume."), ++ .query_formats = query_formats, ++ .priv_size = sizeof(VolumeContext), ++ .init = init, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ|AV_PERM_WRITE}, ++ { .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/all_channel_layouts.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/all_channel_layouts.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/all_channel_layouts.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/all_channel_layouts.h 2012-05-14 14:08:54.688347106 +0200 +@@ -0,0 +1,68 @@ ++AV_CH_FRONT_CENTER, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY, ++AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER, ++AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_CENTER|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_LOW_FREQUENCY|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, ++AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT|AV_CH_FRONT_CENTER|AV_CH_BACK_CENTER|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT|AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/allfilters.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/allfilters.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/allfilters.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/allfilters.c 2012-05-14 14:08:54.689347126 +0200 +@@ -34,23 +34,50 @@ + return; + initialized = 1; + ++ REGISTER_FILTER (ACONVERT, aconvert, af); ++ REGISTER_FILTER (AFORMAT, aformat, af); ++ REGISTER_FILTER (AMERGE, amerge, af); + REGISTER_FILTER (ANULL, anull, af); +- ++ REGISTER_FILTER (ARESAMPLE, aresample, af); ++ REGISTER_FILTER (ASHOWINFO, ashowinfo, af); ++ REGISTER_FILTER (ASPLIT, asplit, af); ++ REGISTER_FILTER (ASTREAMSYNC, astreamsync, af); ++ REGISTER_FILTER (EARWAX, earwax, af); ++ REGISTER_FILTER (PAN, pan, af); ++ REGISTER_FILTER (SILENCEDETECT, silencedetect, af); ++ REGISTER_FILTER (VOLUME, volume, af); ++ ++ REGISTER_FILTER (ABUFFER, abuffer, asrc); ++ REGISTER_FILTER (AEVALSRC, aevalsrc, asrc); ++ REGISTER_FILTER (AMOVIE, amovie, asrc); + REGISTER_FILTER (ANULLSRC, anullsrc, asrc); + ++ REGISTER_FILTER (ABUFFERSINK, abuffersink, asink); + REGISTER_FILTER (ANULLSINK, anullsink, asink); + ++ REGISTER_FILTER (ASS, ass, vf); + REGISTER_FILTER (BLACKFRAME, blackframe, vf); ++ REGISTER_FILTER (BOXBLUR, boxblur, vf); + REGISTER_FILTER (COPY, copy, vf); + REGISTER_FILTER (CROP, crop, vf); + REGISTER_FILTER (CROPDETECT, cropdetect, vf); ++ REGISTER_FILTER (DELOGO, delogo, vf); ++ REGISTER_FILTER (DESHAKE, deshake, vf); + REGISTER_FILTER (DRAWBOX, drawbox, vf); ++ REGISTER_FILTER (DRAWTEXT, drawtext, vf); ++ REGISTER_FILTER (FADE, fade, vf); ++ REGISTER_FILTER (FIELDORDER, fieldorder, vf); + REGISTER_FILTER (FIFO, fifo, vf); + REGISTER_FILTER (FORMAT, format, vf); + REGISTER_FILTER (FREI0R, frei0r, vf); + REGISTER_FILTER (GRADFUN, gradfun, vf); + REGISTER_FILTER (HFLIP, hflip, vf); + REGISTER_FILTER (HQDN3D, hqdn3d, vf); ++ REGISTER_FILTER (LUT, lut, vf); ++ REGISTER_FILTER (LUTRGB, lutrgb, vf); ++ REGISTER_FILTER (LUTYUV, lutyuv, vf); ++ REGISTER_FILTER (MP, mp, vf); ++ REGISTER_FILTER (NEGATE, negate, vf); + REGISTER_FILTER (NOFORMAT, noformat, vf); + REGISTER_FILTER (NULL, null, vf); + REGISTER_FILTER (OCV, ocv, vf); +@@ -58,20 +85,39 @@ + REGISTER_FILTER (PAD, pad, vf); + REGISTER_FILTER (PIXDESCTEST, pixdesctest, vf); + REGISTER_FILTER (SCALE, scale, vf); ++ REGISTER_FILTER (SELECT, select, vf); + REGISTER_FILTER (SETDAR, setdar, vf); + REGISTER_FILTER (SETPTS, setpts, vf); + REGISTER_FILTER (SETSAR, setsar, vf); + REGISTER_FILTER (SETTB, settb, vf); ++ REGISTER_FILTER (SHOWINFO, showinfo, vf); + REGISTER_FILTER (SLICIFY, slicify, vf); ++ REGISTER_FILTER (SPLIT, split, vf); ++ REGISTER_FILTER (SWAPUV, swapuv, vf); ++ REGISTER_FILTER (THUMBNAIL, thumbnail, vf); ++ REGISTER_FILTER (TINTERLACE, tinterlace, vf); + REGISTER_FILTER (TRANSPOSE, transpose, vf); + REGISTER_FILTER (UNSHARP, unsharp, vf); + REGISTER_FILTER (VFLIP, vflip, vf); + REGISTER_FILTER (YADIF, yadif, vf); + +- REGISTER_FILTER (BUFFER, buffer, vsrc); ++ REGISTER_FILTER (CELLAUTO, cellauto, vsrc); + REGISTER_FILTER (COLOR, color, vsrc); + REGISTER_FILTER (FREI0R, frei0r_src, vsrc); ++ REGISTER_FILTER (LIFE, life, vsrc); ++ REGISTER_FILTER (MANDELBROT, mandelbrot, vsrc); ++ REGISTER_FILTER (MOVIE, movie, vsrc); ++ REGISTER_FILTER (MPTESTSRC, mptestsrc, vsrc); + REGISTER_FILTER (NULLSRC, nullsrc, vsrc); ++ REGISTER_FILTER (RGBTESTSRC, rgbtestsrc, vsrc); ++ REGISTER_FILTER (TESTSRC, testsrc, vsrc); + ++ REGISTER_FILTER (BUFFERSINK, buffersink, vsink); + REGISTER_FILTER (NULLSINK, nullsink, vsink); ++ ++ /* vsrc_buffer is a part of public API => registered unconditionally */ ++ { ++ extern AVFilter avfilter_vsrc_buffer; ++ avfilter_register(&avfilter_vsrc_buffer); ++ } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asink_anullsink.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asink_anullsink.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asink_anullsink.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asink_anullsink.c 2012-05-14 14:08:54.689347126 +0200 +@@ -26,7 +26,7 @@ + + .priv_size = 0, + +- .inputs = (AVFilterPad[]) { ++ .inputs = (const AVFilterPad[]) { + { + .name = "default", + .type = AVMEDIA_TYPE_AUDIO, +@@ -34,5 +34,5 @@ + }, + { .name = NULL}, + }, +- .outputs = (AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = NULL }}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_abuffer.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_abuffer.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_abuffer.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_abuffer.c 2012-05-14 14:08:54.691347166 +0200 +@@ -0,0 +1,372 @@ ++/* ++ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram ++ * Copyright (c) 2011 Mina Nagy Zaki ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * memory buffer source for audio ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/avstring.h" ++#include "libavutil/fifo.h" ++#include "asrc_abuffer.h" ++#include "internal.h" ++ ++typedef struct { ++ // Audio format of incoming buffers ++ int sample_rate; ++ unsigned int sample_format; ++ int64_t channel_layout; ++ int packing_format; ++ ++ // FIFO buffer of audio buffer ref pointers ++ AVFifoBuffer *fifo; ++ ++ // Normalization filters ++ AVFilterContext *aconvert; ++ AVFilterContext *aresample; ++} ABufferSourceContext; ++ ++#define FIFO_SIZE 8 ++ ++static void buf_free(AVFilterBuffer *ptr) ++{ ++ av_free(ptr); ++ return; ++} ++ ++static void set_link_source(AVFilterContext *src, AVFilterLink *link) ++{ ++ link->src = src; ++ link->srcpad = &(src->output_pads[0]); ++ src->outputs[0] = link; ++} ++ ++static int reconfigure_filter(ABufferSourceContext *abuffer, AVFilterContext *filt_ctx) ++{ ++ int ret; ++ AVFilterLink * const inlink = filt_ctx->inputs[0]; ++ AVFilterLink * const outlink = filt_ctx->outputs[0]; ++ ++ inlink->format = abuffer->sample_format; ++ inlink->channel_layout = abuffer->channel_layout; ++ inlink->planar = abuffer->packing_format; ++ inlink->sample_rate = abuffer->sample_rate; ++ ++ filt_ctx->filter->uninit(filt_ctx); ++ memset(filt_ctx->priv, 0, filt_ctx->filter->priv_size); ++ if ((ret = filt_ctx->filter->init(filt_ctx, NULL , NULL)) < 0) ++ return ret; ++ if ((ret = inlink->srcpad->config_props(inlink)) < 0) ++ return ret; ++ return outlink->srcpad->config_props(outlink); ++} ++ ++static int insert_filter(ABufferSourceContext *abuffer, ++ AVFilterLink *link, AVFilterContext **filt_ctx, ++ const char *filt_name) ++{ ++ int ret; ++ ++ if ((ret = avfilter_open(filt_ctx, avfilter_get_by_name(filt_name), NULL)) < 0) ++ return ret; ++ ++ link->src->outputs[0] = NULL; ++ if ((ret = avfilter_link(link->src, 0, *filt_ctx, 0)) < 0) { ++ link->src->outputs[0] = link; ++ return ret; ++ } ++ ++ set_link_source(*filt_ctx, link); ++ ++ if ((ret = reconfigure_filter(abuffer, *filt_ctx)) < 0) { ++ avfilter_free(*filt_ctx); ++ return ret; ++ } ++ ++ return 0; ++} ++ ++static void remove_filter(AVFilterContext **filt_ctx) ++{ ++ AVFilterLink *outlink = (*filt_ctx)->outputs[0]; ++ AVFilterContext *src = (*filt_ctx)->inputs[0]->src; ++ ++ (*filt_ctx)->outputs[0] = NULL; ++ avfilter_free(*filt_ctx); ++ *filt_ctx = NULL; ++ ++ set_link_source(src, outlink); ++} ++ ++static inline void log_input_change(void *ctx, AVFilterLink *link, AVFilterBufferRef *ref) ++{ ++ char old_layout_str[16], new_layout_str[16]; ++ av_get_channel_layout_string(old_layout_str, sizeof(old_layout_str), ++ -1, link->channel_layout); ++ av_get_channel_layout_string(new_layout_str, sizeof(new_layout_str), ++ -1, ref->audio->channel_layout); ++ av_log(ctx, AV_LOG_INFO, ++ "Audio input format changed: " ++ "%s:%s:%d -> %s:%s:%d, normalizing\n", ++ av_get_sample_fmt_name(link->format), ++ old_layout_str, (int)link->sample_rate, ++ av_get_sample_fmt_name(ref->format), ++ new_layout_str, ref->audio->sample_rate); ++} ++ ++int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *ctx, ++ AVFilterBufferRef *samplesref, ++ int av_unused flags) ++{ ++ ABufferSourceContext *abuffer = ctx->priv; ++ AVFilterLink *link; ++ int ret, logged = 0; ++ ++ if (av_fifo_space(abuffer->fifo) < sizeof(samplesref)) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Buffering limit reached. Please consume some available frames " ++ "before adding new ones.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ // Normalize input ++ ++ link = ctx->outputs[0]; ++ if (samplesref->audio->sample_rate != link->sample_rate) { ++ ++ log_input_change(ctx, link, samplesref); ++ logged = 1; ++ ++ abuffer->sample_rate = samplesref->audio->sample_rate; ++ ++ if (!abuffer->aresample) { ++ ret = insert_filter(abuffer, link, &abuffer->aresample, "aresample"); ++ if (ret < 0) return ret; ++ } else { ++ link = abuffer->aresample->outputs[0]; ++ if (samplesref->audio->sample_rate == link->sample_rate) ++ remove_filter(&abuffer->aresample); ++ else ++ if ((ret = reconfigure_filter(abuffer, abuffer->aresample)) < 0) ++ return ret; ++ } ++ } ++ ++ link = ctx->outputs[0]; ++ if (samplesref->format != link->format || ++ samplesref->audio->channel_layout != link->channel_layout || ++ samplesref->audio->planar != link->planar) { ++ ++ if (!logged) log_input_change(ctx, link, samplesref); ++ ++ abuffer->sample_format = samplesref->format; ++ abuffer->channel_layout = samplesref->audio->channel_layout; ++ abuffer->packing_format = samplesref->audio->planar; ++ ++ if (!abuffer->aconvert) { ++ ret = insert_filter(abuffer, link, &abuffer->aconvert, "aconvert"); ++ if (ret < 0) return ret; ++ } else { ++ link = abuffer->aconvert->outputs[0]; ++ if (samplesref->format == link->format && ++ samplesref->audio->channel_layout == link->channel_layout && ++ samplesref->audio->planar == link->planar ++ ) ++ remove_filter(&abuffer->aconvert); ++ else ++ if ((ret = reconfigure_filter(abuffer, abuffer->aconvert)) < 0) ++ return ret; ++ } ++ } ++ ++ if (sizeof(samplesref) != av_fifo_generic_write(abuffer->fifo, &samplesref, ++ sizeof(samplesref), NULL)) { ++ av_log(ctx, AV_LOG_ERROR, "Error while writing to FIFO\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ return 0; ++} ++ ++int av_asrc_buffer_add_samples(AVFilterContext *ctx, ++ uint8_t *data[8], int linesize[8], ++ int nb_samples, int sample_rate, ++ int sample_fmt, int64_t channel_layout, int planar, ++ int64_t pts, int av_unused flags) ++{ ++ AVFilterBufferRef *samplesref; ++ ++ samplesref = avfilter_get_audio_buffer_ref_from_arrays( ++ data, linesize, AV_PERM_WRITE, ++ nb_samples, ++ sample_fmt, channel_layout, planar); ++ if (!samplesref) ++ return AVERROR(ENOMEM); ++ ++ samplesref->buf->free = buf_free; ++ samplesref->pts = pts; ++ samplesref->audio->sample_rate = sample_rate; ++ ++ return av_asrc_buffer_add_audio_buffer_ref(ctx, samplesref, 0); ++} ++ ++int av_asrc_buffer_add_buffer(AVFilterContext *ctx, ++ uint8_t *buf, int buf_size, int sample_rate, ++ int sample_fmt, int64_t channel_layout, int planar, ++ int64_t pts, int av_unused flags) ++{ ++ uint8_t *data[8]; ++ int linesize[8]; ++ int nb_channels = av_get_channel_layout_nb_channels(channel_layout), ++ nb_samples = buf_size / nb_channels / av_get_bytes_per_sample(sample_fmt); ++ ++ av_samples_fill_arrays(data, linesize, ++ buf, nb_channels, nb_samples, ++ sample_fmt, 16); ++ ++ return av_asrc_buffer_add_samples(ctx, ++ data, linesize, nb_samples, ++ sample_rate, ++ sample_fmt, channel_layout, planar, ++ pts, flags); ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args0, void *opaque) ++{ ++ ABufferSourceContext *abuffer = ctx->priv; ++ char *arg = NULL, *ptr, chlayout_str[16]; ++ char *args = av_strdup(args0); ++ int ret; ++ ++ arg = av_strtok(args, ":", &ptr); ++ ++#define ADD_FORMAT(fmt_name) \ ++ if (!arg) \ ++ goto arg_fail; \ ++ if ((ret = ff_parse_##fmt_name(&abuffer->fmt_name, arg, ctx)) < 0) { \ ++ av_freep(&args); \ ++ return ret; \ ++ } \ ++ if (*args) \ ++ arg = av_strtok(NULL, ":", &ptr) ++ ++ ADD_FORMAT(sample_rate); ++ ADD_FORMAT(sample_format); ++ ADD_FORMAT(channel_layout); ++ ADD_FORMAT(packing_format); ++ ++ abuffer->fifo = av_fifo_alloc(FIFO_SIZE*sizeof(AVFilterBufferRef*)); ++ if (!abuffer->fifo) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo, filter init failed.\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ av_get_channel_layout_string(chlayout_str, sizeof(chlayout_str), ++ -1, abuffer->channel_layout); ++ av_log(ctx, AV_LOG_INFO, "format:%s layout:%s rate:%d\n", ++ av_get_sample_fmt_name(abuffer->sample_format), chlayout_str, ++ abuffer->sample_rate); ++ av_freep(&args); ++ ++ return 0; ++ ++arg_fail: ++ av_log(ctx, AV_LOG_ERROR, "Invalid arguments, must be of the form " ++ "sample_rate:sample_fmt:channel_layout:packing\n"); ++ av_freep(&args); ++ return AVERROR(EINVAL); ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ ABufferSourceContext *abuffer = ctx->priv; ++ av_fifo_free(abuffer->fifo); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ ABufferSourceContext *abuffer = ctx->priv; ++ AVFilterFormats *formats; ++ ++ formats = NULL; ++ avfilter_add_format(&formats, abuffer->sample_format); ++ avfilter_set_common_sample_formats(ctx, formats); ++ ++ formats = NULL; ++ avfilter_add_format(&formats, abuffer->channel_layout); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ ++ formats = NULL; ++ avfilter_add_format(&formats, abuffer->packing_format); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++static int config_output(AVFilterLink *outlink) ++{ ++ ABufferSourceContext *abuffer = outlink->src->priv; ++ outlink->sample_rate = abuffer->sample_rate; ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ ABufferSourceContext *abuffer = outlink->src->priv; ++ AVFilterBufferRef *samplesref; ++ ++ if (!av_fifo_size(abuffer->fifo)) { ++ av_log(outlink->src, AV_LOG_ERROR, ++ "request_frame() called with no available frames!\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ av_fifo_generic_read(abuffer->fifo, &samplesref, sizeof(samplesref), NULL); ++ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0)); ++ avfilter_unref_buffer(samplesref); ++ ++ return 0; ++} ++ ++static int poll_frame(AVFilterLink *outlink) ++{ ++ ABufferSourceContext *abuffer = outlink->src->priv; ++ return av_fifo_size(abuffer->fifo)/sizeof(AVFilterBufferRef*); ++} ++ ++AVFilter avfilter_asrc_abuffer = { ++ .name = "abuffer", ++ .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them accessible to the filterchain."), ++ .priv_size = sizeof(ABufferSourceContext), ++ .query_formats = query_formats, ++ ++ .init = init, ++ .uninit = uninit, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .request_frame = request_frame, ++ .poll_frame = poll_frame, ++ .config_props = config_output, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_abuffer.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_abuffer.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_abuffer.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_abuffer.h 2012-05-14 14:08:54.691347166 +0200 +@@ -0,0 +1,80 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_ASRC_ABUFFER_H ++#define AVFILTER_ASRC_ABUFFER_H ++ ++#include "avfilter.h" ++ ++/** ++ * @file ++ * memory buffer source for audio ++ */ ++ ++/** ++ * Queue an audio buffer to the audio buffer source. ++ * ++ * @param abuffersrc audio source buffer context ++ * @param data pointers to the samples planes ++ * @param linesize linesizes of each audio buffer plane ++ * @param nb_samples number of samples per channel ++ * @param sample_fmt sample format of the audio data ++ * @param ch_layout channel layout of the audio data ++ * @param planar flag to indicate if audio data is planar or packed ++ * @param pts presentation timestamp of the audio buffer ++ * @param flags unused ++ */ ++int av_asrc_buffer_add_samples(AVFilterContext *abuffersrc, ++ uint8_t *data[8], int linesize[8], ++ int nb_samples, int sample_rate, ++ int sample_fmt, int64_t ch_layout, int planar, ++ int64_t pts, int av_unused flags); ++ ++/** ++ * Queue an audio buffer to the audio buffer source. ++ * ++ * This is similar to av_asrc_buffer_add_samples(), but the samples ++ * are stored in a buffer with known size. ++ * ++ * @param abuffersrc audio source buffer context ++ * @param buf pointer to the samples data, packed is assumed ++ * @param size the size in bytes of the buffer, it must contain an ++ * integer number of samples ++ * @param sample_fmt sample format of the audio data ++ * @param ch_layout channel layout of the audio data ++ * @param pts presentation timestamp of the audio buffer ++ * @param flags unused ++ */ ++int av_asrc_buffer_add_buffer(AVFilterContext *abuffersrc, ++ uint8_t *buf, int buf_size, ++ int sample_rate, ++ int sample_fmt, int64_t ch_layout, int planar, ++ int64_t pts, int av_unused flags); ++ ++/** ++ * Queue an audio buffer to the audio buffer source. ++ * ++ * @param abuffersrc audio source buffer context ++ * @param samplesref buffer ref to queue ++ * @param flags unused ++ */ ++int av_asrc_buffer_add_audio_buffer_ref(AVFilterContext *abuffersrc, ++ AVFilterBufferRef *samplesref, ++ int av_unused flags); ++ ++#endif /* AVFILTER_ASRC_ABUFFER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_aevalsrc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_aevalsrc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_aevalsrc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_aevalsrc.c 2012-05-14 14:08:54.692347187 +0200 +@@ -0,0 +1,247 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * eval audio source ++ */ ++ ++#include "libavutil/audioconvert.h" ++#include "libavutil/avassert.h" ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++static const char * const var_names[] = { ++ "n", ///< number of frame ++ "t", ///< timestamp expressed in seconds ++ "s", ///< sample rate ++ NULL ++}; ++ ++enum var_name { ++ VAR_N, ++ VAR_T, ++ VAR_S, ++ VAR_VARS_NB ++}; ++ ++typedef struct { ++ const AVClass *class; ++ char *sample_rate_str; ++ int sample_rate; ++ int64_t chlayout; ++ int nb_channels; ++ int64_t pts; ++ AVExpr *expr[8]; ++ char *expr_str[8]; ++ int nb_samples; ///< number of samples per requested frame ++ char *duration_str; ///< total duration of the generated audio ++ double duration; ++ uint64_t n; ++ double var_values[VAR_VARS_NB]; ++} EvalContext; ++ ++#define OFFSET(x) offsetof(EvalContext, x) ++ ++static const AVOption eval_options[]= { ++ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX }, ++ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX }, ++ { "sample_rate", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX }, ++ { "s", "set the sample rate", OFFSET(sample_rate_str), AV_OPT_TYPE_STRING, {.str = "44100"}, CHAR_MIN, CHAR_MAX }, ++ { "duration", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "d", "set audio duration", OFFSET(duration_str), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++{NULL}, ++}; ++ ++static const char *eval_get_name(void *ctx) ++{ ++ return "aevalsrc"; ++} ++ ++static const AVClass eval_class = { ++ "AEvalSrcContext", ++ eval_get_name, ++ eval_options ++}; ++ ++static int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ EvalContext *eval = ctx->priv; ++ char *args1 = av_strdup(args); ++ char *expr, *buf, *bufptr; ++ int ret, i; ++ ++ eval->class = &eval_class; ++ av_opt_set_defaults(eval); ++ ++ /* parse expressions */ ++ buf = args1; ++ i = 0; ++ while (expr = av_strtok(buf, ":", &bufptr)) { ++ if (i >= 8) { ++ av_log(ctx, AV_LOG_ERROR, ++ "More than 8 expressions provided, unsupported.\n"); ++ ret = AVERROR(EINVAL); ++ return ret; ++ } ++ ret = av_expr_parse(&eval->expr[i], expr, var_names, ++ NULL, NULL, NULL, NULL, 0, ctx); ++ if (ret < 0) ++ goto end; ++ i++; ++ if (bufptr && *bufptr == ':') { /* found last expression */ ++ bufptr++; ++ break; ++ } ++ buf = NULL; ++ } ++ ++ /* guess channel layout from nb expressions/channels */ ++ eval->nb_channels = i; ++ eval->chlayout = av_get_default_channel_layout(eval->nb_channels); ++ if (!eval->chlayout) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid number of channels '%d' provided\n", ++ eval->nb_channels); ++ ret = AVERROR(EINVAL); ++ goto end; ++ } ++ ++ if (bufptr && (ret = av_set_options_string(eval, bufptr, "=", ":")) < 0) ++ goto end; ++ ++ if ((ret = ff_parse_sample_rate(&eval->sample_rate, eval->sample_rate_str, ctx))) ++ goto end; ++ ++ eval->duration = -1; ++ if (eval->duration_str) { ++ int64_t us = -1; ++ if ((ret = av_parse_time(&us, eval->duration_str, 1)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", eval->duration_str); ++ goto end; ++ } ++ eval->duration = (double)us / 1000000; ++ } ++ eval->n = 0; ++ ++end: ++ av_free(args1); ++ return ret; ++} ++ ++static void uninit(AVFilterContext *ctx) ++{ ++ EvalContext *eval = ctx->priv; ++ int i; ++ ++ for (i = 0; i < 8; i++) { ++ av_expr_free(eval->expr[i]); ++ eval->expr[i] = NULL; ++ } ++ av_freep(&eval->duration_str); ++ av_freep(&eval->sample_rate_str); ++} ++ ++static int config_props(AVFilterLink *outlink) ++{ ++ EvalContext *eval = outlink->src->priv; ++ char buf[128]; ++ ++ outlink->time_base = (AVRational){1, eval->sample_rate}; ++ outlink->sample_rate = eval->sample_rate; ++ ++ eval->var_values[VAR_S] = eval->sample_rate; ++ ++ av_get_channel_layout_string(buf, sizeof(buf), 0, eval->chlayout); ++ ++ av_log(outlink->src, AV_LOG_INFO, ++ "sample_rate:%d chlayout:%s duration:%f\n", ++ eval->sample_rate, buf, eval->duration); ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ EvalContext *eval = ctx->priv; ++ enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE }; ++ int64_t chlayouts[] = { eval->chlayout, -1 }; ++ int packing_fmts[] = { AVFILTER_PLANAR, -1 }; ++ ++ avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts)); ++ avfilter_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts)); ++ avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts)); ++ ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ EvalContext *eval = outlink->src->priv; ++ AVFilterBufferRef *samplesref; ++ int i, j; ++ double t = eval->var_values[VAR_N] * (double)1/eval->sample_rate; ++ ++ if (eval->duration >= 0 && t > eval->duration) ++ return AVERROR_EOF; ++ ++ samplesref = avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, eval->nb_samples); ++ ++ /* evaluate expression for each single sample and for each channel */ ++ for (i = 0; i < eval->nb_samples; i++, eval->n++) { ++ eval->var_values[VAR_N] = eval->n; ++ eval->var_values[VAR_T] = eval->var_values[VAR_N] * (double)1/eval->sample_rate; ++ ++ for (j = 0; j < eval->nb_channels; j++) { ++ *((double *) samplesref->data[j] + i) = ++ av_expr_eval(eval->expr[j], eval->var_values, NULL); ++ } ++ } ++ ++ samplesref->pts = eval->pts; ++ samplesref->pos = -1; ++ samplesref->audio->sample_rate = eval->sample_rate; ++ eval->pts += eval->nb_samples; ++ ++ avfilter_filter_samples(outlink, samplesref); ++ ++ return 0; ++} ++ ++AVFilter avfilter_asrc_aevalsrc = { ++ .name = "aevalsrc", ++ .description = NULL_IF_CONFIG_SMALL("Generate an audio signal generated by an expression."), ++ ++ .query_formats = query_formats, ++ .init = init, ++ .uninit = uninit, ++ .priv_size = sizeof(EvalContext), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .config_props = config_props, ++ .request_frame = request_frame, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_anullsrc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_anullsrc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/asrc_anullsrc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/asrc_anullsrc.c 2012-05-14 14:08:54.693347208 +0200 +@@ -21,74 +21,116 @@ + * null audio source + */ + ++#include "libavutil/audioconvert.h" ++#include "libavutil/opt.h" ++ + #include "avfilter.h" +-#include "libavcore/audioconvert.h" ++#include "internal.h" + + typedef struct { +- int64_t channel_layout; +- int64_t sample_rate; ++ const AVClass *class; ++ char *channel_layout_str; ++ uint64_t channel_layout; ++ char *sample_rate_str; ++ int sample_rate; ++ int nb_samples; ///< number of samples per requested frame ++ int64_t pts; + } ANullContext; + +-static int init(AVFilterContext *ctx, const char *args, void *opaque) ++#define OFFSET(x) offsetof(ANullContext, x) ++ ++static const AVOption anullsrc_options[]= { ++ { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 }, ++ { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0 }, ++ { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 }, ++ { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0 }, ++ { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX }, ++ { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.dbl = 1024}, 0, INT_MAX }, ++ { NULL }, ++}; ++ ++static const char *anullsrc_get_name(void *ctx) + { +- ANullContext *priv = ctx->priv; +- char channel_layout_str[128] = ""; ++ return "anullsrc"; ++} ++ ++static const AVClass anullsrc_class = { ++ "ANullSrcContext", ++ anullsrc_get_name, ++ anullsrc_options ++}; + +- priv->sample_rate = 44100; +- priv->channel_layout = AV_CH_LAYOUT_STEREO; ++static int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ ANullContext *null = ctx->priv; ++ int ret; + +- if (args) +- sscanf(args, "%"PRId64":%s", &priv->sample_rate, channel_layout_str); ++ null->class = &anullsrc_class; ++ av_opt_set_defaults(null); + +- if (priv->sample_rate < 0) { +- av_log(ctx, AV_LOG_ERROR, "Invalid negative sample rate: %"PRId64"\n", priv->sample_rate); +- return AVERROR(EINVAL); ++ if ((ret = (av_set_options_string(null, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; + } + +- if (*channel_layout_str) +- if (!(priv->channel_layout = av_get_channel_layout(channel_layout_str)) +- && sscanf(channel_layout_str, "%"PRId64, &priv->channel_layout) != 1) { +- av_log(ctx, AV_LOG_ERROR, "Invalid value '%s' for channel layout\n", +- channel_layout_str); +- return AVERROR(EINVAL); +- } ++ if ((ret = ff_parse_sample_rate(&null->sample_rate, ++ null->sample_rate_str, ctx)) < 0) ++ return ret; ++ ++ if ((ret = ff_parse_channel_layout(&null->channel_layout, ++ null->channel_layout_str, ctx)) < 0) ++ return ret; + + return 0; + } + + static int config_props(AVFilterLink *outlink) + { +- ANullContext *priv = outlink->src->priv; ++ ANullContext *null = outlink->src->priv; + char buf[128]; + int chans_nb; + +- outlink->sample_rate = priv->sample_rate; +- outlink->channel_layout = priv->channel_layout; ++ outlink->sample_rate = null->sample_rate; ++ outlink->channel_layout = null->channel_layout; + +- chans_nb = av_get_channel_layout_nb_channels(priv->channel_layout); +- av_get_channel_layout_string(buf, sizeof(buf), chans_nb, priv->channel_layout); ++ chans_nb = av_get_channel_layout_nb_channels(null->channel_layout); ++ av_get_channel_layout_string(buf, sizeof(buf), chans_nb, null->channel_layout); + av_log(outlink->src, AV_LOG_INFO, +- "sample_rate:%"PRId64 " channel_layout:%"PRId64 " channel_layout_description:'%s'\n", +- priv->sample_rate, priv->channel_layout, buf); ++ "sample_rate:%d channel_layout:'%s' nb_samples:%d\n", ++ null->sample_rate, buf, null->nb_samples); + + return 0; + } + +-static int request_frame(AVFilterLink *link) ++static int request_frame(AVFilterLink *outlink) + { +- return -1; ++ ANullContext *null = outlink->src->priv; ++ AVFilterBufferRef *samplesref; ++ ++ samplesref = ++ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, null->nb_samples); ++ samplesref->pts = null->pts; ++ samplesref->pos = -1; ++ samplesref->audio->channel_layout = null->channel_layout; ++ samplesref->audio->sample_rate = outlink->sample_rate; ++ ++ avfilter_filter_samples(outlink, avfilter_ref_buffer(samplesref, ~0)); ++ avfilter_unref_buffer(samplesref); ++ ++ null->pts += null->nb_samples; ++ return 0; + } + + AVFilter avfilter_asrc_anullsrc = { + .name = "anullsrc", +- .description = NULL_IF_CONFIG_SMALL("Null audio source, never return audio frames."), ++ .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."), + + .init = init, + .priv_size = sizeof(ANullContext), + +- .inputs = (AVFilterPad[]) {{ .name = NULL}}, ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_AUDIO, + .config_props = config_props, + .request_frame = request_frame, }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avcodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avcodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avcodec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avcodec.c 2012-05-14 14:08:54.694347228 +0200 +@@ -0,0 +1,75 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libavcodec/libavfilter gluing utilities ++ */ ++ ++#include "avcodec.h" ++ ++int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src) ++{ ++ dst->pts = src->pts; ++ dst->pos = src->pkt_pos; ++ dst->format = src->format; ++ ++ switch (dst->type) { ++ case AVMEDIA_TYPE_VIDEO: ++ dst->video->w = src->width; ++ dst->video->h = src->height; ++ dst->video->sample_aspect_ratio = src->sample_aspect_ratio; ++ dst->video->interlaced = src->interlaced_frame; ++ dst->video->top_field_first = src->top_field_first; ++ dst->video->key_frame = src->key_frame; ++ dst->video->pict_type = src->pict_type; ++ } ++ ++ return 0; ++} ++ ++AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, ++ int perms) ++{ ++ AVFilterBufferRef *picref = ++ avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize, perms, ++ frame->width, frame->height, ++ frame->format); ++ if (!picref) ++ return NULL; ++ avfilter_copy_frame_props(picref, frame); ++ return picref; ++} ++ ++int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame, ++ const AVFilterBufferRef *picref) ++{ ++ if (!picref || !picref->video || !frame) ++ return AVERROR(EINVAL); ++ ++ memcpy(frame->data, picref->data, sizeof(frame->data)); ++ memcpy(frame->linesize, picref->linesize, sizeof(frame->linesize)); ++ frame->pkt_pos = picref->pos; ++ frame->interlaced_frame = picref->video->interlaced; ++ frame->top_field_first = picref->video->top_field_first; ++ frame->key_frame = picref->video->key_frame; ++ frame->pict_type = picref->video->pict_type; ++ frame->sample_aspect_ratio = picref->video->sample_aspect_ratio; ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avcodec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avcodec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avcodec.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avcodec.h 2012-05-14 14:08:54.694347228 +0200 +@@ -0,0 +1,71 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_AVCODEC_H ++#define AVFILTER_AVCODEC_H ++ ++/** ++ * @file ++ * libavcodec/libavfilter gluing utilities ++ * ++ * This should be included in an application ONLY if the installed ++ * libavfilter has been compiled with libavcodec support, otherwise ++ * symbols defined below will not be available. ++ */ ++ ++#include "libavcodec/avcodec.h" // AVFrame ++#include "avfilter.h" ++#include "vsrc_buffer.h" ++ ++/** ++ * Copy the frame properties of src to dst, without copying the actual ++ * image data. ++ */ ++int avfilter_copy_frame_props(AVFilterBufferRef *dst, const AVFrame *src); ++ ++/** ++ * Create and return a picref reference from the data and properties ++ * contained in frame. ++ * ++ * @param perms permissions to assign to the new buffer reference ++ */ ++AVFilterBufferRef *avfilter_get_video_buffer_ref_from_frame(const AVFrame *frame, int perms); ++ ++/** ++ * Fill an AVFrame with the information stored in picref. ++ * ++ * @param frame an already allocated AVFrame ++ * @param picref a video buffer reference ++ * @return 0 in case of success, a negative AVERROR code in case of ++ * failure ++ */ ++int avfilter_fill_frame_from_video_buffer_ref(AVFrame *frame, ++ const AVFilterBufferRef *picref); ++ ++/** ++ * Add frame data to buffer_src. ++ * ++ * @param buffer_src pointer to a buffer source context ++ * @param flags a combination of AV_VSRC_BUF_FLAG_* flags ++ * @return >= 0 in case of success, a negative AVERROR code in case of ++ * failure ++ */ ++int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, ++ const AVFrame *frame, int flags); ++ ++#endif /* AVFILTER_AVCODEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfilter.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfilter.c 2012-05-14 14:08:54.696347268 +0200 +@@ -23,12 +23,15 @@ + + #include "libavutil/pixdesc.h" + #include "libavutil/rational.h" +-#include "libavcore/audioconvert.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/avassert.h" ++#include "libavutil/avstring.h" + #include "avfilter.h" + #include "internal.h" + + unsigned avfilter_version(void) { ++ av_assert0(LIBAVFILTER_VERSION_MICRO >= 100); + return LIBAVFILTER_VERSION_INT; + } + +@@ -43,6 +46,15 @@ + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; + } + ++static void command_queue_pop(AVFilterContext *filter) ++{ ++ AVFilterCommand *c= filter->command_queue; ++ av_freep(&c->arg); ++ av_freep(&c->command); ++ filter->command_queue= c->next; ++ av_free(c); ++} ++ + AVFilterBufferRef *avfilter_ref_buffer(AVFilterBufferRef *ref, int pmask) + { + AVFilterBufferRef *ret = av_malloc(sizeof(AVFilterBufferRef)); +@@ -69,14 +81,82 @@ + return ret; + } + ++static void free_pool(AVFilterPool *pool) ++{ ++ int i; ++ ++ av_assert0(pool->refcount > 0); ++ ++ for (i = 0; i < POOL_SIZE; i++) { ++ if (pool->pic[i]) { ++ AVFilterBufferRef *picref = pool->pic[i]; ++ /* free buffer: picrefs stored in the pool are not ++ * supposed to contain a free callback */ ++ av_assert0(!picref->buf->refcount); ++ av_freep(&picref->buf->data[0]); ++ av_freep(&picref->buf); ++ ++ av_freep(&picref->audio); ++ av_freep(&picref->video); ++ av_freep(&pool->pic[i]); ++ pool->count--; ++ } ++ } ++ pool->draining = 1; ++ ++ if (!--pool->refcount) { ++ av_assert0(!pool->count); ++ av_free(pool); ++ } ++} ++ ++static void store_in_pool(AVFilterBufferRef *ref) ++{ ++ int i; ++ AVFilterPool *pool= ref->buf->priv; ++ ++ av_assert0(ref->buf->data[0]); ++ av_assert0(pool->refcount>0); ++ ++ if (pool->count == POOL_SIZE) { ++ AVFilterBufferRef *ref1 = pool->pic[0]; ++ av_freep(&ref1->video); ++ av_freep(&ref1->audio); ++ av_freep(&ref1->buf->data[0]); ++ av_freep(&ref1->buf); ++ av_free(ref1); ++ memmove(&pool->pic[0], &pool->pic[1], sizeof(void*)*(POOL_SIZE-1)); ++ pool->count--; ++ pool->pic[POOL_SIZE-1] = NULL; ++ } ++ ++ for (i = 0; i < POOL_SIZE; i++) { ++ if (!pool->pic[i]) { ++ pool->pic[i] = ref; ++ pool->count++; ++ break; ++ } ++ } ++ if (pool->draining) { ++ free_pool(pool); ++ } else ++ --pool->refcount; ++} ++ + void avfilter_unref_buffer(AVFilterBufferRef *ref) + { + if (!ref) + return; +- if (!(--ref->buf->refcount)) ++ av_assert0(ref->buf->refcount > 0); ++ if (!(--ref->buf->refcount)) { ++ if (!ref->buf->free) { ++ store_in_pool(ref); ++ return; ++ } + ref->buf->free(ref->buf); +- av_free(ref->video); +- av_free(ref->audio); ++ } ++ av_freep(&ref->video); ++ av_freep(&ref->audio); + av_free(ref); + } + +@@ -131,6 +211,17 @@ + return 0; + } + ++void avfilter_link_free(AVFilterLink **link) ++{ ++ if (!*link) ++ return; ++ ++ if ((*link)->pool) ++ free_pool((*link)->pool); ++ ++ av_freep(link); ++} ++ + int avfilter_insert_filter(AVFilterLink *link, AVFilterContext *filt, + unsigned filt_srcpad_idx, unsigned filt_dstpad_idx) + { +@@ -158,6 +249,12 @@ + if (link->out_formats) + avfilter_formats_changeref(&link->out_formats, + &filt->outputs[filt_dstpad_idx]->out_formats); ++ if (link->out_chlayouts) ++ avfilter_formats_changeref(&link->out_chlayouts, ++ &filt->outputs[filt_dstpad_idx]->out_chlayouts); ++ if (link->out_packing) ++ avfilter_formats_changeref(&link->out_packing, ++ &filt->outputs[filt_dstpad_idx]->out_packing); + + return 0; + } +@@ -170,6 +267,8 @@ + + for (i = 0; i < filter->input_count; i ++) { + AVFilterLink *link = filter->inputs[i]; ++ AVFilterLink *inlink = link->src->input_count ? ++ link->src->inputs[0] : NULL; + + if (!link) continue; + +@@ -185,14 +284,55 @@ + if ((ret = avfilter_config_links(link->src)) < 0) + return ret; + +- if (!(config_link = link->srcpad->config_props)) +- config_link = avfilter_default_config_output_link; +- if ((ret = config_link(link)) < 0) ++ if (!(config_link = link->srcpad->config_props)) { ++ if (link->src->input_count != 1) { ++ av_log(link->src, AV_LOG_ERROR, "Source filters and filters " ++ "with more than one input " ++ "must set config_props() " ++ "callbacks on all outputs\n"); ++ return AVERROR(EINVAL); ++ } ++ } else if ((ret = config_link(link)) < 0) + return ret; + +- if (link->time_base.num == 0 && link->time_base.den == 0) +- link->time_base = link->src && link->src->input_count ? +- link->src->inputs[0]->time_base : AV_TIME_BASE_Q; ++ switch (link->type) { ++ case AVMEDIA_TYPE_VIDEO: ++ if (!link->time_base.num && !link->time_base.den) ++ link->time_base = inlink ? inlink->time_base : AV_TIME_BASE_Q; ++ ++ if (!link->sample_aspect_ratio.num && !link->sample_aspect_ratio.den) ++ link->sample_aspect_ratio = inlink ? ++ inlink->sample_aspect_ratio : (AVRational){1,1}; ++ ++ if (inlink) { ++ if (!link->w) ++ link->w = inlink->w; ++ if (!link->h) ++ link->h = inlink->h; ++ } else if (!link->w || !link->h) { ++ av_log(link->src, AV_LOG_ERROR, ++ "Video source filters must set their output link's " ++ "width and height\n"); ++ return AVERROR(EINVAL); ++ } ++ break; ++ ++ case AVMEDIA_TYPE_AUDIO: ++ if (inlink) { ++ if (!link->sample_rate) ++ link->sample_rate = inlink->sample_rate; ++ if (!link->time_base.num && !link->time_base.den) ++ link->time_base = inlink->time_base; ++ } else if (!link->sample_rate) { ++ av_log(link->src, AV_LOG_ERROR, ++ "Audio source filters must set their output link's " ++ "sample_rate\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (!link->time_base.num && !link->time_base.den) ++ link->time_base = (AVRational) {1, link->sample_rate}; ++ } + + if ((config_link = link->dstpad->config_props)) + if ((ret = config_link(link)) < 0) +@@ -227,17 +367,18 @@ + ref->pts, ref->pos); + + if (ref->video) { +- av_dlog(ctx, " a:%d/%d s:%dx%d i:%c", +- ref->video->pixel_aspect.num, ref->video->pixel_aspect.den, ++ av_dlog(ctx, " a:%d/%d s:%dx%d i:%c iskey:%d type:%c", ++ ref->video->sample_aspect_ratio.num, ref->video->sample_aspect_ratio.den, + ref->video->w, ref->video->h, + !ref->video->interlaced ? 'P' : /* Progressive */ +- ref->video->top_field_first ? 'T' : 'B'); /* Top / Bottom */ ++ ref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */ ++ ref->video->key_frame, ++ av_get_picture_type_char(ref->video->pict_type)); + } + if (ref->audio) { +- av_dlog(ctx, " cl:%"PRId64"d sn:%d s:%d sr:%d p:%d", ++ av_dlog(ctx, " cl:%"PRId64"d n:%d r:%d p:%d", + ref->audio->channel_layout, + ref->audio->nb_samples, +- ref->audio->size, + ref->audio->sample_rate, + ref->audio->planar); + } +@@ -249,7 +390,7 @@ + { + if (link->type == AVMEDIA_TYPE_VIDEO) { + av_dlog(ctx, +- "link[%p s:%dx%d fmt:%-16s %-16s->%-16s]%s", ++ "link[%p s:%dx%d fmt:%s %s->%s]%s", + link, link->w, link->h, + av_pix_fmt_descriptors[link->format].name, + link->src ? link->src->filter->name : "", +@@ -260,8 +401,8 @@ + av_get_channel_layout_string(buf, sizeof(buf), -1, link->channel_layout); + + av_dlog(ctx, +- "link[%p r:%"PRId64" cl:%s fmt:%-16s %-16s->%-16s]%s", +- link, link->sample_rate, buf, ++ "link[%p r:%d cl:%s fmt:%s %s->%s]%s", ++ link, (int)link->sample_rate, buf, + av_get_sample_fmt_name(link->format), + link->src ? link->src->filter->name : "", + link->dst ? link->dst->filter->name : "", +@@ -294,7 +435,7 @@ + } + + AVFilterBufferRef * +-avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, ++avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms, + int w, int h, enum PixelFormat format) + { + AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer)); +@@ -318,8 +459,8 @@ + picref->type = AVMEDIA_TYPE_VIDEO; + pic->format = picref->format = format; + +- memcpy(pic->data, data, sizeof(pic->data)); +- memcpy(pic->linesize, linesize, sizeof(pic->linesize)); ++ memcpy(pic->data, data, 4*sizeof(data[0])); ++ memcpy(pic->linesize, linesize, 4*sizeof(linesize[0])); + memcpy(picref->data, pic->data, sizeof(picref->data)); + memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); + +@@ -333,17 +474,16 @@ + return NULL; + } + +-AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar) ++AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, ++ int perms, int nb_samples) + { + AVFilterBufferRef *ret = NULL; + + if (link->dstpad->get_audio_buffer) +- ret = link->dstpad->get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar); ++ ret = link->dstpad->get_audio_buffer(link, perms, nb_samples); + + if (!ret) +- ret = avfilter_default_get_audio_buffer(link, perms, sample_fmt, size, channel_layout, planar); ++ ret = avfilter_default_get_audio_buffer(link, perms, nb_samples); + + if (ret) + ret->type = AVMEDIA_TYPE_AUDIO; +@@ -351,6 +491,48 @@ + return ret; + } + ++AVFilterBufferRef * ++avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms, ++ int nb_samples, enum AVSampleFormat sample_fmt, ++ uint64_t channel_layout, int planar) ++{ ++ AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); ++ AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef)); ++ ++ if (!samples || !samplesref) ++ goto fail; ++ ++ samplesref->buf = samples; ++ samplesref->buf->free = ff_avfilter_default_free_buffer; ++ if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)))) ++ goto fail; ++ ++ samplesref->audio->nb_samples = nb_samples; ++ samplesref->audio->channel_layout = channel_layout; ++ samplesref->audio->planar = planar; ++ ++ /* make sure the buffer gets read permission or it's useless for output */ ++ samplesref->perms = perms | AV_PERM_READ; ++ ++ samples->refcount = 1; ++ samplesref->type = AVMEDIA_TYPE_AUDIO; ++ samplesref->format = sample_fmt; ++ ++ memcpy(samples->data, data, sizeof(samples->data)); ++ memcpy(samples->linesize, linesize, sizeof(samples->linesize)); ++ memcpy(samplesref->data, data, sizeof(samplesref->data)); ++ memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize)); ++ ++ return samplesref; ++ ++fail: ++ if (samplesref && samplesref->audio) ++ av_freep(&samplesref->audio); ++ av_freep(&samplesref); ++ av_freep(&samples); ++ return NULL; ++} ++ + int avfilter_request_frame(AVFilterLink *link) + { + FF_DPRINTF_START(NULL, request_frame); ff_dlog_link(NULL, link, 1); +@@ -387,6 +569,7 @@ + void (*start_frame)(AVFilterLink *, AVFilterBufferRef *); + AVFilterPad *dst = link->dstpad; + int perms = picref->perms; ++ AVFilterCommand *cmd= link->dst->command_queue; + + FF_DPRINTF_START(NULL, start_frame); ff_dlog_link(NULL, link, 0); av_dlog(NULL, " "); ff_dlog_ref(NULL, picref, 1); + +@@ -409,6 +592,15 @@ + else + link->cur_buf = picref; + ++ while(cmd && cmd->time <= picref->pts * av_q2d(link->time_base)){ ++ av_log(link->dst, AV_LOG_DEBUG, ++ "Processing command time:%f command:%s arg:%s\n", ++ cmd->time, cmd->command, cmd->arg); ++ avfilter_process_command(link->dst, cmd->command, cmd->arg, 0, 0, cmd->flags); ++ command_queue_pop(link->dst); ++ cmd= link->dst->command_queue; ++ } ++ + start_frame(link, link->cur_buf); + } + +@@ -470,10 +662,22 @@ + draw_slice(link, y, h, slice_dir); + } + ++int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags) ++{ ++ if(!strcmp(cmd, "ping")){ ++ av_strlcatf(res, res_len, "pong from:%s %s\n", filter->filter->name, filter->name); ++ return 0; ++ }else if(filter->filter->process_command) { ++ return filter->filter->process_command(filter, cmd, arg, res, res_len, flags); ++ } ++ return AVERROR(ENOSYS); ++} ++ + void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) + { + void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); + AVFilterPad *dst = link->dstpad; ++ int i; + + FF_DPRINTF_START(NULL, filter_samples); ff_dlog_link(NULL, link, 1); + +@@ -489,15 +693,13 @@ + samplesref->perms, link->dstpad->min_perms, link->dstpad->rej_perms); + + link->cur_buf = avfilter_default_get_audio_buffer(link, dst->min_perms, +- samplesref->format, +- samplesref->audio->size, +- samplesref->audio->channel_layout, +- samplesref->audio->planar); ++ samplesref->audio->nb_samples); + link->cur_buf->pts = samplesref->pts; + link->cur_buf->audio->sample_rate = samplesref->audio->sample_rate; + + /* Copy actual data into new samples buffer */ +- memcpy(link->cur_buf->data[0], samplesref->data[0], samplesref->audio->size); ++ for (i = 0; samplesref->data[i] && i < 8; i++) ++ memcpy(link->cur_buf->data[i], samplesref->data[i], samplesref->linesize[0]); + + avfilter_unref_buffer(samplesref); + } else +@@ -506,7 +708,7 @@ + filter_samples(link, link->cur_buf); + } + +-#define MAX_REGISTERED_AVFILTERS_NB 64 ++#define MAX_REGISTERED_AVFILTERS_NB 128 + + static AVFilter *registered_avfilters[MAX_REGISTERED_AVFILTERS_NB + 1]; + +@@ -525,8 +727,13 @@ + + int avfilter_register(AVFilter *filter) + { +- if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) +- return -1; ++ if (next_registered_avfilter_idx == MAX_REGISTERED_AVFILTERS_NB) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Maximum number of registered filters %d reached, " ++ "impossible to register filter with name '%s'\n", ++ MAX_REGISTERED_AVFILTERS_NB, filter->name); ++ return AVERROR(ENOMEM); ++ } + + registered_avfilters[next_registered_avfilter_idx++] = filter; + return 0; +@@ -573,28 +780,53 @@ + return AVERROR(EINVAL); + + ret = av_mallocz(sizeof(AVFilterContext)); ++ if (!ret) ++ return AVERROR(ENOMEM); + + ret->av_class = &avfilter_class; + ret->filter = filter; + ret->name = inst_name ? av_strdup(inst_name) : NULL; +- ret->priv = av_mallocz(filter->priv_size); ++ if (filter->priv_size) { ++ ret->priv = av_mallocz(filter->priv_size); ++ if (!ret->priv) ++ goto err; ++ } + + ret->input_count = pad_count(filter->inputs); + if (ret->input_count) { + ret->input_pads = av_malloc(sizeof(AVFilterPad) * ret->input_count); ++ if (!ret->input_pads) ++ goto err; + memcpy(ret->input_pads, filter->inputs, sizeof(AVFilterPad) * ret->input_count); + ret->inputs = av_mallocz(sizeof(AVFilterLink*) * ret->input_count); ++ if (!ret->inputs) ++ goto err; + } + + ret->output_count = pad_count(filter->outputs); + if (ret->output_count) { + ret->output_pads = av_malloc(sizeof(AVFilterPad) * ret->output_count); ++ if (!ret->output_pads) ++ goto err; + memcpy(ret->output_pads, filter->outputs, sizeof(AVFilterPad) * ret->output_count); + ret->outputs = av_mallocz(sizeof(AVFilterLink*) * ret->output_count); ++ if (!ret->outputs) ++ goto err; + } + + *filter_ctx = ret; + return 0; ++ ++err: ++ av_freep(&ret->inputs); ++ av_freep(&ret->input_pads); ++ ret->input_count = 0; ++ av_freep(&ret->outputs); ++ av_freep(&ret->output_pads); ++ ret->output_count = 0; ++ av_freep(&ret->priv); ++ av_free(ret); ++ return AVERROR(ENOMEM); + } + + void avfilter_free(AVFilterContext *filter) +@@ -612,7 +844,7 @@ + avfilter_formats_unref(&link->in_formats); + avfilter_formats_unref(&link->out_formats); + } +- av_freep(&link); ++ avfilter_link_free(&link); + } + for (i = 0; i < filter->output_count; i++) { + if ((link = filter->outputs[i])) { +@@ -621,7 +853,7 @@ + avfilter_formats_unref(&link->in_formats); + avfilter_formats_unref(&link->out_formats); + } +- av_freep(&link); ++ avfilter_link_free(&link); + } + + av_freep(&filter->name); +@@ -630,6 +862,9 @@ + av_freep(&filter->inputs); + av_freep(&filter->outputs); + av_freep(&filter->priv); ++ while(filter->command_queue){ ++ command_queue_pop(filter); ++ } + av_free(filter); + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfiltergraph.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfiltergraph.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfiltergraph.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfiltergraph.c 2012-05-14 14:08:54.700347348 +0200 +@@ -23,6 +23,7 @@ + #include + #include + ++#include "libavutil/audioconvert.h" + #include "avfilter.h" + #include "avfiltergraph.h" + #include "internal.h" +@@ -32,14 +33,15 @@ + return av_mallocz(sizeof(AVFilterGraph)); + } + +-void avfilter_graph_free(AVFilterGraph *graph) ++void avfilter_graph_free(AVFilterGraph **graph) + { +- if (!graph) ++ if (!*graph) + return; +- for (; graph->filter_count > 0; graph->filter_count --) +- avfilter_free(graph->filters[graph->filter_count - 1]); +- av_freep(&graph->scale_sws_opts); +- av_freep(&graph->filters); ++ for (; (*graph)->filter_count > 0; (*graph)->filter_count--) ++ avfilter_free((*graph)->filters[(*graph)->filter_count - 1]); ++ av_freep(&(*graph)->scale_sws_opts); ++ av_freep(&(*graph)->filters); ++ av_freep(graph); + } + + int avfilter_graph_add_filter(AVFilterGraph *graph, AVFilterContext *filter) +@@ -89,7 +91,7 @@ + av_log(log_ctx, AV_LOG_ERROR, + "Input pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any source\n", + filt->input_pads[j].name, filt->name, filt->filter->name); +- return -1; ++ return AVERROR(EINVAL); + } + } + +@@ -98,7 +100,7 @@ + av_log(log_ctx, AV_LOG_ERROR, + "Output pad \"%s\" for the filter \"%s\" of type \"%s\" not connected to any destination\n", + filt->output_pads[j].name, filt->name, filt->filter->name); +- return -1; ++ return AVERROR(EINVAL); + } + } + } +@@ -134,11 +136,57 @@ + return NULL; + } + ++static int insert_conv_filter(AVFilterGraph *graph, AVFilterLink *link, ++ const char *filt_name, const char *filt_args) ++{ ++ static int auto_count = 0, ret; ++ char inst_name[32]; ++ AVFilterContext *filt_ctx; ++ ++ snprintf(inst_name, sizeof(inst_name), "auto-inserted %s %d", ++ filt_name, auto_count++); ++ ++ if ((ret = avfilter_graph_create_filter(&filt_ctx, ++ avfilter_get_by_name(filt_name), ++ inst_name, filt_args, NULL, graph)) < 0) ++ return ret; ++ if ((ret = avfilter_insert_filter(link, filt_ctx, 0, 0)) < 0) ++ return ret; ++ ++ filt_ctx->filter->query_formats(filt_ctx); ++ ++ if ( ((link = filt_ctx-> inputs[0]) && ++ !avfilter_merge_formats(link->in_formats, link->out_formats)) || ++ ((link = filt_ctx->outputs[0]) && ++ !avfilter_merge_formats(link->in_formats, link->out_formats)) ++ ) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Impossible to convert between the formats supported by the filter " ++ "'%s' and the filter '%s'\n", link->src->name, link->dst->name); ++ return AVERROR(EINVAL); ++ } ++ ++ if (link->type == AVMEDIA_TYPE_AUDIO && ++ (((link = filt_ctx-> inputs[0]) && ++ (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) || ++ !avfilter_merge_formats(link->in_packing, link->out_packing))) || ++ ((link = filt_ctx->outputs[0]) && ++ (!avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) || ++ !avfilter_merge_formats(link->in_packing, link->out_packing)))) ++ ) { ++ av_log(NULL, AV_LOG_ERROR, ++ "Impossible to convert between the channel layouts/packing formats supported by the filter " ++ "'%s' and the filter '%s'\n", link->src->name, link->dst->name); ++ return AVERROR(EINVAL); ++ } ++ ++ return 0; ++} ++ + static int query_formats(AVFilterGraph *graph, AVClass *log_ctx) + { + int i, j, ret; +- int scaler_count = 0; +- char inst_name[30]; ++ char filt_args[128]; + + /* ask all the sub-filters for their supported media formats */ + for (i = 0; i < graph->filter_count; i++) { +@@ -154,32 +202,30 @@ + + for (j = 0; j < filter->input_count; j++) { + AVFilterLink *link = filter->inputs[j]; +- if (link && link->in_formats != link->out_formats) { +- if (!avfilter_merge_formats(link->in_formats, +- link->out_formats)) { +- AVFilterContext *scale; +- char scale_args[256]; +- /* couldn't merge format lists. auto-insert scale filter */ +- snprintf(inst_name, sizeof(inst_name), "auto-inserted scaler %d", +- scaler_count++); +- snprintf(scale_args, sizeof(scale_args), "0:0:%s", graph->scale_sws_opts); +- if ((ret = avfilter_graph_create_filter(&scale, avfilter_get_by_name("scale"), +- inst_name, scale_args, NULL, graph)) < 0) +- return ret; +- if ((ret = avfilter_insert_filter(link, scale, 0, 0)) < 0) +- return ret; +- +- scale->filter->query_formats(scale); +- if (((link = scale-> inputs[0]) && +- !avfilter_merge_formats(link->in_formats, link->out_formats)) || +- ((link = scale->outputs[0]) && +- !avfilter_merge_formats(link->in_formats, link->out_formats))) { +- av_log(log_ctx, AV_LOG_ERROR, +- "Impossible to convert between the formats supported by the filter " +- "'%s' and the filter '%s'\n", link->src->name, link->dst->name); +- return -1; +- } +- } ++ if (!link) continue; ++ ++ if (!link->in_formats || !link->out_formats) ++ return AVERROR(EINVAL); ++ ++ if (link->type == AVMEDIA_TYPE_VIDEO && ++ !avfilter_merge_formats(link->in_formats, link->out_formats)) { ++ ++ /* couldn't merge format lists, auto-insert scale filter */ ++ snprintf(filt_args, sizeof(filt_args), "0:0:%s", ++ graph->scale_sws_opts); ++ if (ret = insert_conv_filter(graph, link, "scale", filt_args)) ++ return ret; ++ } ++ else if (link->type == AVMEDIA_TYPE_AUDIO) { ++ if (!link->in_chlayouts || !link->out_chlayouts || ++ !link->in_packing || !link->out_packing) ++ return AVERROR(EINVAL); ++ ++ if (!avfilter_merge_formats(link->in_formats, link->out_formats) || ++ !avfilter_merge_formats(link->in_chlayouts, link->out_chlayouts) || ++ !avfilter_merge_formats(link->in_packing, link->out_packing)) ++ if (ret = insert_conv_filter(graph, link, "aconvert", NULL)) ++ return ret; + } + } + } +@@ -194,9 +240,20 @@ + + link->in_formats->format_count = 1; + link->format = link->in_formats->formats[0]; +- + avfilter_formats_unref(&link->in_formats); + avfilter_formats_unref(&link->out_formats); ++ ++ if (link->type == AVMEDIA_TYPE_AUDIO) { ++ link->in_chlayouts->format_count = 1; ++ link->channel_layout = link->in_chlayouts->formats[0]; ++ avfilter_formats_unref(&link->in_chlayouts); ++ avfilter_formats_unref(&link->out_chlayouts); ++ ++ link->in_packing->format_count = 1; ++ link->planar = link->in_packing->formats[0] == AVFILTER_PLANAR; ++ avfilter_formats_unref(&link->in_packing); ++ avfilter_formats_unref(&link->out_packing); ++ } + } + + static void pick_formats(AVFilterGraph *graph) +@@ -215,9 +272,11 @@ + + int ff_avfilter_graph_config_formats(AVFilterGraph *graph, AVClass *log_ctx) + { ++ int ret; ++ + /* find supported formats from sub-filters, and merge along links */ +- if (query_formats(graph, log_ctx)) +- return -1; ++ if ((ret = query_formats(graph, log_ctx)) < 0) ++ return ret; + + /* Once everything is merged, it's possible that we'll still have + * multiple valid media format choices. We pick the first one. */ +@@ -226,7 +285,7 @@ + return 0; + } + +-int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx) ++int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx) + { + int ret; + +@@ -239,3 +298,61 @@ + + return 0; + } ++ ++int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags) ++{ ++ int i, r = AVERROR(ENOSYS); ++ ++ if(!graph) ++ return r; ++ ++ if((flags & AVFILTER_CMD_FLAG_ONE) && !(flags & AVFILTER_CMD_FLAG_FAST)) { ++ r=avfilter_graph_send_command(graph, target, cmd, arg, res, res_len, flags | AVFILTER_CMD_FLAG_FAST); ++ if(r != AVERROR(ENOSYS)) ++ return r; ++ } ++ ++ if(res_len && res) ++ res[0]= 0; ++ ++ for (i = 0; i < graph->filter_count; i++) { ++ AVFilterContext *filter = graph->filters[i]; ++ if(!strcmp(target, "all") || (filter->name && !strcmp(target, filter->name)) || !strcmp(target, filter->filter->name)){ ++ r = avfilter_process_command(filter, cmd, arg, res, res_len, flags); ++ if(r != AVERROR(ENOSYS)) { ++ if((flags & AVFILTER_CMD_FLAG_ONE) || r<0) ++ return r; ++ } ++ } ++ } ++ ++ return r; ++} ++ ++int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *command, const char *arg, int flags, double ts) ++{ ++ int i; ++ ++ if(!graph) ++ return 0; ++ ++ for (i = 0; i < graph->filter_count; i++) { ++ AVFilterContext *filter = graph->filters[i]; ++ if(filter && (!strcmp(target, "all") || !strcmp(target, filter->name) || !strcmp(target, filter->filter->name))){ ++ AVFilterCommand **que = &filter->command_queue, *next; ++ while(*que && (*que)->time <= ts) ++ que = &(*que)->next; ++ next= *que; ++ *que= av_mallocz(sizeof(AVFilterCommand)); ++ (*que)->command = av_strdup(command); ++ (*que)->arg = av_strdup(arg); ++ (*que)->time = ts; ++ (*que)->flags = flags; ++ (*que)->next = next; ++ if(flags & AVFILTER_CMD_FLAG_ONE) ++ return 0; ++ } ++ } ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfiltergraph.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfiltergraph.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfiltergraph.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfiltergraph.h 2012-05-14 14:08:54.701347368 +0200 +@@ -76,12 +76,13 @@ + * @param log_ctx context used for logging + * @return 0 in case of success, a negative AVERROR code otherwise + */ +-int avfilter_graph_config(AVFilterGraph *graphctx, AVClass *log_ctx); ++int avfilter_graph_config(AVFilterGraph *graphctx, void *log_ctx); + + /** +- * Free a graph and destroy its links, graph may be NULL. ++ * Free a graph, destroy its links, and set *graph to NULL. ++ * If *graph is NULL, do nothing. + */ +-void avfilter_graph_free(AVFilterGraph *graph); ++void avfilter_graph_free(AVFilterGraph **graph); + + /** + * A linked-list of the inputs/outputs of the filter chain. +@@ -107,16 +108,77 @@ + } AVFilterInOut; + + /** ++ * Create an AVFilterInOut. ++ * Must be free with avfilter_inout_free(). ++ */ ++AVFilterInOut *avfilter_inout_alloc(void); ++ ++/** ++ * Free the AVFilterInOut in *inout, and set its pointer to NULL. ++ * If *inout is NULL, do nothing. ++ */ ++void avfilter_inout_free(AVFilterInOut **inout); ++ ++/** + * Add a graph described by a string to a graph. + * + * @param graph the filter graph where to link the parsed graph context + * @param filters string to be parsed +- * @param inputs linked list to the inputs of the graph +- * @param outputs linked list to the outputs of the graph +- * @return zero on success, a negative AVERROR code on error ++ * @param inputs pointer to a linked list to the inputs of the graph, may be NULL. ++ * If non-NULL, *inputs is updated to contain the list of open inputs ++ * after the parsing, should be freed with avfilter_inout_free(). ++ * @param outputs pointer to a linked list to the outputs of the graph, may be NULL. ++ * If non-NULL, *outputs is updated to contain the list of open outputs ++ * after the parsing, should be freed with avfilter_inout_free(). ++ * @return non negative on success, a negative AVERROR code on error + */ + int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, +- AVFilterInOut *inputs, AVFilterInOut *outputs, +- AVClass *log_ctx); ++ AVFilterInOut **inputs, AVFilterInOut **outputs, ++ void *log_ctx); ++ ++/** ++ * Send a command to one or more filter instances. ++ * ++ * @param graph the filter graph ++ * @param target the filter(s) to which the command should be sent ++ * "all" sends to all filters ++ * otherwise it can be a filter or filter instance name ++ * which will send the command to all matching filters. ++ * @param cmd the command to sent, for handling simplicity all commands must be alphanumeric only ++ * @param arg the argument for the command ++ * @param res a buffer with size res_size where the filter(s) can return a response. ++ * ++ * @returns >=0 on success otherwise an error code. ++ * AVERROR(ENOSYS) on unsupported commands ++ */ ++int avfilter_graph_send_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, char *res, int res_len, int flags); ++ ++/** ++ * Queue a command for one or more filter instances. ++ * ++ * @param graph the filter graph ++ * @param target the filter(s) to which the command should be sent ++ * "all" sends to all filters ++ * otherwise it can be a filter or filter instance name ++ * which will send the command to all matching filters. ++ * @param cmd the command to sent, for handling simplicity all commands must be alphanummeric only ++ * @param arg the argument for the command ++ * @param ts time at which the command should be sent to the filter ++ * ++ * @note As this executes commands after this function returns, no return code ++ * from the filter is provided, also AVFILTER_CMD_FLAG_ONE is not supported. ++ */ ++int avfilter_graph_queue_command(AVFilterGraph *graph, const char *target, const char *cmd, const char *arg, int flags, double ts); ++ ++ ++/** ++ * Dump a graph into a human-readable string representation. ++ * ++ * @param graph the graph to dump ++ * @param options formatting options; currently ignored ++ * @return a string, or NULL in case of memory allocation failure; ++ * the string must be freed using av_free ++ */ ++char *avfilter_graph_dump(AVFilterGraph *graph, const char *options); + +-#endif /* AVFILTER_AVFILTERGRAPH_H */ ++#endif /* AVFILTER_AVFILTERGRAPH_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfilter.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfilter.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/avfilter.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/avfilter.h 2012-05-14 14:08:54.699347328 +0200 +@@ -23,23 +23,24 @@ + #define AVFILTER_AVFILTER_H + + #include "libavutil/avutil.h" +-#include "libavcore/avcore.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/log.h" ++#include "libavutil/samplefmt.h" ++#include "libavutil/pixfmt.h" ++#include "libavutil/rational.h" ++#include "libavcodec/avcodec.h" + +-#define LIBAVFILTER_VERSION_MAJOR 1 +-#define LIBAVFILTER_VERSION_MINOR 74 +-#define LIBAVFILTER_VERSION_MICRO 0 +- +-#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ +- LIBAVFILTER_VERSION_MINOR, \ +- LIBAVFILTER_VERSION_MICRO) +-#define LIBAVFILTER_VERSION AV_VERSION(LIBAVFILTER_VERSION_MAJOR, \ +- LIBAVFILTER_VERSION_MINOR, \ +- LIBAVFILTER_VERSION_MICRO) +-#define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT ++ ++#ifndef FF_API_OLD_VSINK_API ++#define FF_API_OLD_VSINK_API (LIBAVFILTER_VERSION_MAJOR < 3) ++#endif ++#ifndef FF_API_OLD_ALL_FORMATS_API ++#define FF_API_OLD_ALL_FORMATS_API (LIBAVFILTER_VERSION_MAJOR < 3) ++#endif + + #include + ++#include "libavfilter/version.h" ++ + /** + * Return the LIBAVFILTER_VERSION_INT constant. + */ +@@ -91,6 +92,9 @@ + #define AV_PERM_REUSE 0x08 ///< can output the buffer multiple times, with the same contents each time + #define AV_PERM_REUSE2 0x10 ///< can output the buffer multiple times, modified each time + #define AV_PERM_NEG_LINESIZES 0x20 ///< the buffer requested can have negative linesizes ++#define AV_PERM_ALIGN 0x40 ///< the buffer must be aligned ++ ++#define AVFILTER_ALIGN 16 //not part of ABI + + /** + * Audio specific properties in a reference to an AVFilterBuffer. Since +@@ -98,10 +102,9 @@ + * per reference properties must be separated out. + */ + typedef struct AVFilterBufferRefAudioProps { +- int64_t channel_layout; ///< channel layout of audio buffer +- int nb_samples; ///< number of audio samples +- int size; ///< audio buffer size +- uint32_t sample_rate; ///< audio buffer sample rate ++ uint64_t channel_layout; ///< channel layout of audio buffer ++ int nb_samples; ///< number of audio samples per channel ++ int sample_rate; ///< audio buffer sample rate + int planar; ///< audio buffer - planar or packed + } AVFilterBufferRefAudioProps; + +@@ -113,9 +116,11 @@ + typedef struct AVFilterBufferRefVideoProps { + int w; ///< image width + int h; ///< image height +- AVRational pixel_aspect; ///< pixel aspect ratio ++ AVRational sample_aspect_ratio; ///< sample aspect ratio + int interlaced; ///< is frame interlaced + int top_field_first; ///< field order ++ enum AVPictureType pict_type; ///< picture type of the frame ++ int key_frame; ///< 1 -> keyframe, 0-> not + } AVFilterBufferRefVideoProps; + + /** +@@ -224,7 +229,7 @@ + */ + typedef struct AVFilterFormats { + unsigned format_count; ///< number of formats +- int *formats; ///< list of media formats ++ int64_t *formats; ///< list of media formats + + unsigned refcount; ///< number of references to this list + struct AVFilterFormats ***refs; ///< references to this list +@@ -234,10 +239,12 @@ + * Create a list of supported formats. This is intended for use in + * AVFilter->query_formats(). + * +- * @param fmts list of media formats, terminated by -1 ++ * @param fmts list of media formats, terminated by -1. If NULL an ++ * empty list is created. + * @return the format list, with no existing references + */ + AVFilterFormats *avfilter_make_format_list(const int *fmts); ++AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts); + + /** + * Add fmt to the list of media formats contained in *avff. +@@ -247,12 +254,35 @@ + * @return a non negative value in case of success, or a negative + * value corresponding to an AVERROR code in case of error + */ +-int avfilter_add_format(AVFilterFormats **avff, int fmt); ++int avfilter_add_format(AVFilterFormats **avff, int64_t fmt); + ++#if FF_API_OLD_ALL_FORMATS_API + /** +- * Return a list of all formats supported by FFmpeg for the given media type. ++ * @deprecated Use avfilter_make_all_formats() instead. + */ ++attribute_deprecated + AVFilterFormats *avfilter_all_formats(enum AVMediaType type); ++#endif ++ ++/** ++ * Return a list of all formats supported by FFmpeg for the given media type. ++ */ ++AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type); ++ ++/** ++ * A list of all channel layouts supported by libavfilter. ++ */ ++extern const int64_t avfilter_all_channel_layouts[]; ++ ++/** ++ * Return a list of all channel layouts supported by FFmpeg. ++ */ ++AVFilterFormats *avfilter_make_all_channel_layouts(void); ++ ++/** ++ * Return a list of all audio packing formats. ++ */ ++AVFilterFormats *avfilter_make_all_packing_formats(void); + + /** + * Return a format list which contains the intersection of the formats of +@@ -266,7 +296,7 @@ + + /** + * Add *ref as a new reference to formats. +- * That is the pointers will point like in the ascii art below: ++ * That is the pointers will point like in the ASCII art below: + * ________ + * |formats |<--------. + * | ____ | ____|___________________ +@@ -323,8 +353,7 @@ + const char *name; + + /** +- * AVFilterPad type. Only video supported now, hopefully someone will +- * add audio in the future. ++ * AVFilterPad type. Can be AVMEDIA_TYPE_VIDEO or AVMEDIA_TYPE_AUDIO. + */ + enum AVMediaType type; + +@@ -371,9 +400,7 @@ + * + * Input audio pads only. + */ +- AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar); ++ AVFilterBufferRef *(*get_audio_buffer)(AVFilterLink *link, int perms, int nb_samples); + + /** + * Callback called after the slices of a frame are completely sent. If +@@ -423,15 +450,18 @@ + /** + * Link configuration callback. + * +- * For output pads, this should set the link properties such as +- * width/height. This should NOT set the format property - that is +- * negotiated between filters by the filter system using the ++ * For output pads, this should set the following link properties: ++ * video: width, height, sample_aspect_ratio, time_base ++ * audio: sample_rate. ++ * ++ * This should NOT set properties such as format, channel_layout, etc which ++ * are negotiated between filters by the filter system using the + * query_formats() callback before this function is called. + * + * For input pads, this should check the properties of the link, and update + * the filter's internal state as necessary. + * +- * For both input and output filters, this should return zero on success, ++ * For both input and output pads, this should return zero on success, + * and another value on error. + */ + int (*config_props)(AVFilterLink *link); +@@ -449,27 +479,23 @@ + /** default handler for filter_samples() for audio inputs */ + void avfilter_default_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); + +-/** default handler for config_props() for audio/video outputs */ +-int avfilter_default_config_output_link(AVFilterLink *link); +- +-/** default handler for config_props() for audio/video inputs */ +-int avfilter_default_config_input_link (AVFilterLink *link); +- + /** default handler for get_video_buffer() for video inputs */ + AVFilterBufferRef *avfilter_default_get_video_buffer(AVFilterLink *link, + int perms, int w, int h); + + /** default handler for get_audio_buffer() for audio inputs */ +-AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar); ++AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, ++ int perms, int nb_samples); + + /** +- * A helper for query_formats() which sets all links to the same list of +- * formats. If there are no links hooked to this filter, the list of formats is +- * freed. +- */ +-void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats); ++ * Helpers for query_formats() which set all links to the same list of ++ * formats/layouts. If there are no links hooked to this filter, the list ++ * of formats is freed. ++ */ ++void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats); ++void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats); ++void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats); ++void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats); + + /** Default handler for query_formats() */ + int avfilter_default_query_formats(AVFilterContext *ctx); +@@ -491,9 +517,8 @@ + int perms, int w, int h); + + /** get_audio_buffer() handler for filters which simply pass audio along */ +-AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar); ++AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, ++ int perms, int nb_samples); + + /** + * Filter definition. This defines the pads a filter contains, and all the +@@ -520,9 +545,9 @@ + void (*uninit)(AVFilterContext *ctx); + + /** +- * Queries formats supported by the filter and its pads, and sets the +- * in_formats for links connected to its output pads, and out_formats +- * for links connected to its input pads. ++ * Queries formats/layouts supported by the filter and its pads, and sets ++ * the in_formats/in_chlayouts for links connected to its output pads, ++ * and out_formats/out_chlayouts for links connected to its input pads. + * + * @return zero on success, a negative value corresponding to an + * AVERROR code otherwise +@@ -537,11 +562,25 @@ + * NULL_IF_CONFIG_SMALL() macro to define it. + */ + const char *description; ++ ++ /** ++ * Make the filter instance process a command. ++ * ++ * @param cmd the command to process, for handling simplicity all commands must be alphanumeric only ++ * @param arg the argument for the command ++ * @param res a buffer with size res_size where the filter(s) can return a response. This must not change when the command is not supported. ++ * @param flags if AVFILTER_CMD_FLAG_FAST is set and the command would be ++ * time consuming then a filter should treat it like an unsupported command ++ * ++ * @returns >=0 on success otherwise an error code. ++ * AVERROR(ENOSYS) on unsupported commands ++ */ ++ int (*process_command)(AVFilterContext *, const char *cmd, const char *arg, char *res, int res_len, int flags); + } AVFilter; + + /** An instance of a filter */ + struct AVFilterContext { +- const AVClass *av_class; ///< needed for av_log() ++ const AVClass *av_class; ///< needed for av_log() + + AVFilter *filter; ///< the AVFilter of which this is an instance + +@@ -556,6 +595,13 @@ + AVFilterLink **outputs; ///< array of pointers to output links + + void *priv; ///< private data for use by the filter ++ ++ struct AVFilterCommand *command_queue; ++}; ++ ++enum AVFilterPacking { ++ AVFILTER_PACKED = 0, ++ AVFILTER_PLANAR, + }; + + /** +@@ -581,23 +627,36 @@ + + enum AVMediaType type; ///< filter media type + +- /* These two parameters apply only to video */ ++ /* These parameters apply only to video */ + int w; ///< agreed upon image width + int h; ///< agreed upon image height +- /* These two parameters apply only to audio */ +- int64_t channel_layout; ///< channel layout of current buffer (see libavcore/audioconvert.h) ++ AVRational sample_aspect_ratio; ///< agreed upon sample aspect ratio ++ /* These parameters apply only to audio */ ++ uint64_t channel_layout; ///< channel layout of current buffer (see libavutil/audioconvert.h) ++#if LIBAVFILTER_VERSION_MAJOR < 3 + int64_t sample_rate; ///< samples per second ++#else ++ int sample_rate; ///< samples per second ++#endif ++ int planar; ///< agreed upon packing mode of audio buffers. true if planar. + + int format; ///< agreed upon media format + + /** +- * Lists of formats supported by the input and output filters respectively. +- * These lists are used for negotiating the format to actually be used, +- * which will be loaded into the format member, above, when chosen. ++ * Lists of formats and channel layouts supported by the input and output ++ * filters respectively. These lists are used for negotiating the format ++ * to actually be used, which will be loaded into the format and ++ * channel_layout members, above, when chosen. ++ * + */ + AVFilterFormats *in_formats; + AVFilterFormats *out_formats; + ++ AVFilterFormats *in_chlayouts; ++ AVFilterFormats *out_chlayouts; ++ AVFilterFormats *in_packing; ++ AVFilterFormats *out_packing; ++ + /** + * The buffer reference currently being sent across the link by the source + * filter. This is used internally by the filter system to allow +@@ -618,6 +677,8 @@ + * input link is assumed to be an unchangeable property. + */ + AVRational time_base; ++ ++ struct AVFilterPool *pool; + }; + + /** +@@ -633,6 +694,11 @@ + AVFilterContext *dst, unsigned dstpad); + + /** ++ * Free the link in *link, and set its pointer to NULL. ++ */ ++void avfilter_link_free(AVFilterLink **link); ++ ++/** + * Negotiate the media format, dimensions, etc of all inputs to a filter. + * + * @param filter the filter to negotiate the properties for its inputs +@@ -666,7 +732,7 @@ + * @param format the pixel format of the image specified by the data and linesize arrays + */ + AVFilterBufferRef * +-avfilter_get_video_buffer_ref_from_arrays(uint8_t *data[4], int linesize[4], int perms, ++avfilter_get_video_buffer_ref_from_arrays(uint8_t * const data[4], const int linesize[4], int perms, + int w, int h, enum PixelFormat format); + + /** +@@ -675,18 +741,30 @@ + * @param link the output link to the filter from which the buffer will + * be requested + * @param perms the required access permissions +- * @param sample_fmt the format of each sample in the buffer to allocate +- * @param size the buffer size in bytes +- * @param channel_layout the number and type of channels per sample in the buffer to allocate +- * @param planar audio data layout - planar or packed ++ * @param nb_samples the number of samples per channel + * @return A reference to the samples. This must be unreferenced with + * avfilter_unref_buffer when you are finished with it. + */ + AVFilterBufferRef *avfilter_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar); ++ int nb_samples); + + /** ++ * Create an audio buffer reference wrapped around an already ++ * allocated samples buffer. ++ * ++ * @param data pointers to the samples plane buffers ++ * @param linesize linesize for the samples plane buffers ++ * @param perms the required access permissions ++ * @param nb_samples number of samples per channel ++ * @param sample_fmt the format of each sample in the buffer to allocate ++ * @param channel_layout the channel layout of the buffer ++ * @param planar audio data layout - planar or packed ++ */ ++AVFilterBufferRef * ++avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms, ++ int nb_samples, enum AVSampleFormat sample_fmt, ++ uint64_t channel_layout, int planar); ++/** + * Request an input frame from the filter at the other end of the link. + * + * @param link the input link +@@ -704,7 +782,7 @@ + int avfilter_poll_frame(AVFilterLink *link); + + /** +- * Notifie the next filter of the start of a frame. ++ * Notify the next filter of the start of a frame. + * + * @param link the output link the frame will be sent over + * @param picref A reference to the frame about to be sent. The data for this +@@ -715,7 +793,7 @@ + void avfilter_start_frame(AVFilterLink *link, AVFilterBufferRef *picref); + + /** +- * Notifie the next filter that the current frame has finished. ++ * Notify the next filter that the current frame has finished. + * + * @param link the output link the frame was sent over + */ +@@ -738,6 +816,15 @@ + */ + void avfilter_draw_slice(AVFilterLink *link, int y, int h, int slice_dir); + ++#define AVFILTER_CMD_FLAG_ONE 1 ///< Stop once a filter understood the command (for target=all for example), fast filters are favored automatically ++#define AVFILTER_CMD_FLAG_FAST 2 ///< Only execute command when its fast (like a video out that supports contrast adjustment in hw) ++ ++/** ++ * Make the filter instance process a command. ++ * It is recommended to use avfilter_graph_send_command(). ++ */ ++int avfilter_process_command(AVFilterContext *filter, const char *cmd, const char *arg, char *res, int res_len, int flags); ++ + /** + * Send a buffer of audio samples to the next filter. + * +@@ -748,7 +835,7 @@ + */ + void avfilter_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); + +-/** Initialize the filter system. Register all builtin filters. */ ++/** Initialize the filter system. Register all built-in filters. */ + void avfilter_register_all(void); + + /** Uninitialize the filter system. Unregister all filters. */ +@@ -761,7 +848,7 @@ + * registered. + * + * @param filter the filter to register +- * @return 0 if the registration was succesfull, a negative value ++ * @return 0 if the registration was successful, a negative value + * otherwise + */ + int avfilter_register(AVFilter *filter); +@@ -858,4 +945,4 @@ + &f->output_pads, &f->outputs, p); + } + +-#endif /* AVFILTER_AVFILTER_H */ ++#endif /* AVFILTER_AVFILTER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/buffersink.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/buffersink.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/buffersink.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/buffersink.h 2012-05-14 14:08:54.702347388 +0200 +@@ -0,0 +1,94 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_VSINK_BUFFER_H ++#define AVFILTER_VSINK_BUFFER_H ++ ++/** ++ * @file ++ * memory buffer sink API for audio and video ++ */ ++ ++#include "avfilter.h" ++ ++/** ++ * Struct to use for initializing a buffersink context. ++ */ ++typedef struct { ++ const enum PixelFormat *pixel_fmts; ///< list of allowed pixel formats, terminated by PIX_FMT_NONE ++} AVBufferSinkParams; ++ ++/** ++ * Create an AVBufferSinkParams structure. ++ * ++ * Must be freed with av_free(). ++ */ ++AVBufferSinkParams *av_buffersink_params_alloc(void); ++ ++/** ++ * Struct to use for initializing an abuffersink context. ++ */ ++typedef struct { ++ const enum AVSampleFormat *sample_fmts; ///< list of allowed sample formats, terminated by AV_SAMPLE_FMT_NONE ++ const int64_t *channel_layouts; ///< list of allowed channel layouts, terminated by -1 ++ const int *packing_fmts; ///< list of allowed packing formats ++} AVABufferSinkParams; ++ ++/** ++ * Create an AVABufferSinkParams structure. ++ * ++ * Must be freed with av_free(). ++ */ ++AVABufferSinkParams *av_abuffersink_params_alloc(void); ++ ++/** ++ * Tell av_buffersink_get_buffer_ref() to read video/samples buffer ++ * reference, but not remove it from the buffer. This is useful if you ++ * need only to read a video/samples buffer, without to fetch it. ++ */ ++#define AV_BUFFERSINK_FLAG_PEEK 1 ++ ++/** ++ * Get an audio/video buffer data from buffer_sink and put it in bufref. ++ * ++ * This function works with both audio and video buffer sinks. ++ * ++ * @param buffer_sink pointer to a buffersink or abuffersink context ++ * @param flags a combination of AV_BUFFERSINK_FLAG_* flags ++ * @return >= 0 in case of success, a negative AVERROR code in case of ++ * failure ++ */ ++int av_buffersink_get_buffer_ref(AVFilterContext *buffer_sink, ++ AVFilterBufferRef **bufref, int flags); ++ ++ ++/** ++ * Get the number of immediately available frames. ++ */ ++int av_buffersink_poll_frame(AVFilterContext *ctx); ++ ++#if FF_API_OLD_VSINK_API ++/** ++ * @deprecated Use av_buffersink_get_buffer_ref() instead. ++ */ ++attribute_deprecated ++int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *buffer_sink, ++ AVFilterBufferRef **picref, int flags); ++#endif ++ ++#endif /* AVFILTER_VSINK_BUFFER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/buffersrc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/buffersrc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/buffersrc.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/buffersrc.h 2012-05-14 14:08:54.702347388 +0200 +@@ -0,0 +1,38 @@ ++/* ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_BUFFERSRC_H ++#define AVFILTER_BUFFERSRC_H ++ ++/** ++ * @file ++ * Memory buffer source API. ++ */ ++ ++#include "avfilter.h" ++ ++/** ++ * Add a buffer to the filtergraph s. ++ * ++ * @param buf buffer containing frame data to be passed down the filtergraph. ++ * This function will take ownership of buf, the user must not free it. ++ */ ++int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf); ++ ++#endif /* AVFILTER_BUFFERSRC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/defaults.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/defaults.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/defaults.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/defaults.c 2012-05-14 14:08:54.703347408 +0200 +@@ -19,13 +19,13 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcore/audioconvert.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/avassert.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/samplefmt.h" + #include "avfilter.h" + #include "internal.h" + +-/* TODO: buffer pool. see comment for avfilter_default_get_video_buffer() */ + void ff_avfilter_default_free_buffer(AVFilterBuffer *ptr) + { + av_free(ptr->data[0]); +@@ -39,10 +39,35 @@ + { + int linesize[4]; + uint8_t *data[4]; ++ int i; + AVFilterBufferRef *picref = NULL; ++ AVFilterPool *pool = link->pool; + +- // +2 is needed for swscaler, +16 to be SIMD-friendly +- if (av_image_alloc(data, linesize, w, h, link->format, 16) < 0) ++ if (pool) { ++ for (i = 0; i < POOL_SIZE; i++) { ++ picref = pool->pic[i]; ++ if (picref && picref->buf->format == link->format && picref->buf->w == w && picref->buf->h == h) { ++ AVFilterBuffer *pic = picref->buf; ++ pool->pic[i] = NULL; ++ pool->count--; ++ picref->video->w = w; ++ picref->video->h = h; ++ picref->perms = perms | AV_PERM_READ; ++ picref->format = link->format; ++ pic->refcount = 1; ++ memcpy(picref->data, pic->data, sizeof(picref->data)); ++ memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); ++ pool->refcount++; ++ return picref; ++ } ++ } ++ } else { ++ pool = link->pool = av_mallocz(sizeof(AVFilterPool)); ++ pool->refcount = 1; ++ } ++ ++ // align: +2 is needed for swscaler, +16 to be SIMD-friendly ++ if ((i = av_image_alloc(data, linesize, w, h, link->format, 32)) < 0) + return NULL; + + picref = avfilter_get_video_buffer_ref_from_arrays(data, linesize, +@@ -51,86 +76,45 @@ + av_free(data[0]); + return NULL; + } ++ memset(data[0], 128, i); ++ ++ picref->buf->priv = pool; ++ picref->buf->free = NULL; ++ pool->refcount++; + + return picref; + } + + AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int planar) ++ int nb_samples) + { +- AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); +- AVFilterBufferRef *ref = NULL; +- int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0; +- char *buf; +- +- if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef)))) +- goto fail; +- +- ref->buf = samples; +- ref->format = sample_fmt; +- +- ref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)); +- if (!ref->audio) +- goto fail; +- +- ref->audio->channel_layout = channel_layout; +- ref->audio->size = size; +- ref->audio->planar = planar; +- +- /* make sure the buffer gets read permission or it's useless for output */ +- ref->perms = perms | AV_PERM_READ; +- +- samples->refcount = 1; +- samples->free = ff_avfilter_default_free_buffer; +- +- sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3; +- chans_nb = av_get_channel_layout_nb_channels(channel_layout); +- +- per_channel_size = size/chans_nb; +- ref->audio->nb_samples = per_channel_size/sample_size; +- +- /* Set the number of bytes to traverse to reach next sample of a particular channel: +- * For planar, this is simply the sample size. +- * For packed, this is the number of samples * sample_size. +- */ +- for (i = 0; i < chans_nb; i++) +- samples->linesize[i] = planar > 0 ? per_channel_size : sample_size; +- memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0])); +- +- /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ +- bufsize = (size + 15)&~15; +- buf = av_malloc(bufsize); +- if (!buf) +- goto fail; +- +- /* For planar, set the start point of each channel's data within the buffer +- * For packed, set the start point of the entire buffer only +- */ +- samples->data[0] = buf; +- if (buf && planar) { +- for (i = 1; i < chans_nb; i++) { +- step_size += per_channel_size; +- samples->data[i] = buf + step_size; +- } +- } else { +- for (i = 1; i < chans_nb; i++) +- samples->data[i] = buf; +- } ++ AVFilterBufferRef *samplesref = NULL; ++ int linesize[8] = {0}; ++ uint8_t *data[8] = {0}; ++ int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout); + +- memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0])); ++ /* right now we don't support more than 8 channels */ ++ av_assert0(nb_channels <= 8); + +- memcpy(ref->data, samples->data, sizeof(ref->data)); +- memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); ++ /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ ++ if (av_samples_alloc(data, linesize, ++ nb_channels, nb_samples, ++ av_get_alt_sample_fmt(link->format, link->planar), ++ 16) < 0) ++ return NULL; + +- return ref; ++ for (ch = 1; link->planar && ch < nb_channels; ch++) ++ linesize[ch] = linesize[0]; ++ samplesref = ++ avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms, ++ nb_samples, link->format, ++ link->channel_layout, link->planar); ++ if (!samplesref) { ++ av_free(data[0]); ++ return NULL; ++ } + +-fail: +- if (ref && ref->audio) +- av_free(ref->audio); +- av_free(ref); +- av_free(samples); +- return NULL; ++ return samplesref; + } + + void avfilter_default_start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) +@@ -186,10 +170,8 @@ + outlink = inlink->dst->outputs[0]; + + if (outlink) { +- outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, samplesref->format, +- samplesref->audio->size, +- samplesref->audio->channel_layout, +- samplesref->audio->planar); ++ outlink->out_buf = avfilter_default_get_audio_buffer(inlink, AV_PERM_WRITE, ++ samplesref->audio->nb_samples); + outlink->out_buf->pts = samplesref->pts; + outlink->out_buf->audio->sample_rate = samplesref->audio->sample_rate; + avfilter_filter_samples(outlink, avfilter_ref_buffer(outlink->out_buf, ~0)); +@@ -200,68 +182,62 @@ + inlink->cur_buf = NULL; + } + +-/** +- * default config_link() implementation for output video links to simplify +- * the implementation of one input one output video filters */ +-int avfilter_default_config_output_link(AVFilterLink *link) +-{ +- if (link->src->input_count && link->src->inputs[0]) { +- if (link->type == AVMEDIA_TYPE_VIDEO) { +- link->w = link->src->inputs[0]->w; +- link->h = link->src->inputs[0]->h; +- link->time_base = link->src->inputs[0]->time_base; +- } else if (link->type == AVMEDIA_TYPE_AUDIO) { +- link->channel_layout = link->src->inputs[0]->channel_layout; +- link->sample_rate = link->src->inputs[0]->sample_rate; +- } +- } else { +- /* XXX: any non-simple filter which would cause this branch to be taken +- * really should implement its own config_props() for this link. */ +- return -1; ++static void set_common_formats(AVFilterContext *ctx, AVFilterFormats *fmts, ++ enum AVMediaType type, int offin, int offout) ++{ ++ int i; ++ for (i = 0; i < ctx->input_count; i++) ++ if (ctx->inputs[i] && ctx->inputs[i]->type == type) ++ avfilter_formats_ref(fmts, ++ (AVFilterFormats **)((uint8_t *)ctx->inputs[i]+offout)); ++ ++ for (i = 0; i < ctx->output_count; i++) ++ if (ctx->outputs[i] && ctx->outputs[i]->type == type) ++ avfilter_formats_ref(fmts, ++ (AVFilterFormats **)((uint8_t *)ctx->outputs[i]+offin)); ++ ++ if (!fmts->refcount) { ++ av_free(fmts->formats); ++ av_free(fmts->refs); ++ av_free(fmts); + } ++} + +- return 0; ++void avfilter_set_common_pixel_formats(AVFilterContext *ctx, AVFilterFormats *formats) ++{ ++ set_common_formats(ctx, formats, AVMEDIA_TYPE_VIDEO, ++ offsetof(AVFilterLink, in_formats), ++ offsetof(AVFilterLink, out_formats)); + } + +-/** +- * A helper for query_formats() which sets all links to the same list of +- * formats. If there are no links hooked to this filter, the list of formats is +- * freed. +- * +- * FIXME: this will need changed for filters with a mix of pad types +- * (video + audio, etc) +- */ +-void avfilter_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats) ++void avfilter_set_common_sample_formats(AVFilterContext *ctx, AVFilterFormats *formats) + { +- int count = 0, i; ++ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO, ++ offsetof(AVFilterLink, in_formats), ++ offsetof(AVFilterLink, out_formats)); ++} + +- for (i = 0; i < ctx->input_count; i++) { +- if (ctx->inputs[i]) { +- avfilter_formats_ref(formats, &ctx->inputs[i]->out_formats); +- count++; +- } +- } +- for (i = 0; i < ctx->output_count; i++) { +- if (ctx->outputs[i]) { +- avfilter_formats_ref(formats, &ctx->outputs[i]->in_formats); +- count++; +- } +- } ++void avfilter_set_common_channel_layouts(AVFilterContext *ctx, AVFilterFormats *formats) ++{ ++ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO, ++ offsetof(AVFilterLink, in_chlayouts), ++ offsetof(AVFilterLink, out_chlayouts)); ++} + +- if (!count) { +- av_free(formats->formats); +- av_free(formats->refs); +- av_free(formats); +- } ++void avfilter_set_common_packing_formats(AVFilterContext *ctx, AVFilterFormats *formats) ++{ ++ set_common_formats(ctx, formats, AVMEDIA_TYPE_AUDIO, ++ offsetof(AVFilterLink, in_packing), ++ offsetof(AVFilterLink, out_packing)); + } + + int avfilter_default_query_formats(AVFilterContext *ctx) + { +- enum AVMediaType type = ctx->inputs && ctx->inputs [0] ? ctx->inputs [0]->type : +- ctx->outputs && ctx->outputs[0] ? ctx->outputs[0]->type : +- AVMEDIA_TYPE_VIDEO; ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_all_formats(AVMEDIA_TYPE_VIDEO)); ++ avfilter_set_common_sample_formats(ctx, avfilter_make_all_formats(AVMEDIA_TYPE_AUDIO)); ++ avfilter_set_common_channel_layouts(ctx, avfilter_make_all_channel_layouts()); ++ avfilter_set_common_packing_formats(ctx, avfilter_make_all_packing_formats()); + +- avfilter_set_common_formats(ctx, avfilter_all_formats(type)); + return 0; + } + +@@ -291,10 +267,8 @@ + } + + AVFilterBufferRef *avfilter_null_get_audio_buffer(AVFilterLink *link, int perms, +- enum AVSampleFormat sample_fmt, int size, +- int64_t channel_layout, int packed) ++ int nb_samples) + { +- return avfilter_get_audio_buffer(link->dst->outputs[0], perms, sample_fmt, +- size, channel_layout, packed); ++ return avfilter_get_audio_buffer(link->dst->outputs[0], perms, nb_samples); + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/drawutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/drawutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/drawutils.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/drawutils.c 2012-05-14 14:08:54.704347428 +0200 +@@ -0,0 +1,122 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/avutil.h" ++#include "libavutil/colorspace.h" ++#include "libavutil/pixdesc.h" ++#include "drawutils.h" ++ ++enum { RED = 0, GREEN, BLUE, ALPHA }; ++ ++int ff_fill_rgba_map(uint8_t *rgba_map, enum PixelFormat pix_fmt) ++{ ++ switch (pix_fmt) { ++ case PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break; ++ case PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break; ++ case PIX_FMT_RGBA: ++ case PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break; ++ case PIX_FMT_BGRA: ++ case PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break; ++ default: /* unsupported */ ++ return AVERROR(EINVAL); ++ } ++ return 0; ++} ++ ++int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, uint8_t dst_color[4], ++ enum PixelFormat pix_fmt, uint8_t rgba_color[4], ++ int *is_packed_rgba, uint8_t rgba_map_ptr[4]) ++{ ++ uint8_t rgba_map[4] = {0}; ++ int i; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; ++ int hsub = pix_desc->log2_chroma_w; ++ ++ *is_packed_rgba = ff_fill_rgba_map(rgba_map, pix_fmt) >= 0; ++ ++ if (*is_packed_rgba) { ++ pixel_step[0] = (av_get_bits_per_pixel(pix_desc))>>3; ++ for (i = 0; i < 4; i++) ++ dst_color[rgba_map[i]] = rgba_color[i]; ++ ++ line[0] = av_malloc(w * pixel_step[0]); ++ for (i = 0; i < w; i++) ++ memcpy(line[0] + i * pixel_step[0], dst_color, pixel_step[0]); ++ if (rgba_map_ptr) ++ memcpy(rgba_map_ptr, rgba_map, sizeof(rgba_map[0]) * 4); ++ } else { ++ int plane; ++ ++ dst_color[0] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); ++ dst_color[1] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); ++ dst_color[2] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); ++ dst_color[3] = rgba_color[3]; ++ ++ for (plane = 0; plane < 4; plane++) { ++ int line_size; ++ int hsub1 = (plane == 1 || plane == 2) ? hsub : 0; ++ ++ pixel_step[plane] = 1; ++ line_size = (w >> hsub1) * pixel_step[plane]; ++ line[plane] = av_malloc(line_size); ++ memset(line[plane], dst_color[plane], line_size); ++ } ++ } ++ ++ return 0; ++} ++ ++void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], ++ uint8_t *src[4], int pixelstep[4], ++ int hsub, int vsub, int x, int y, int w, int h) ++{ ++ int i, plane; ++ uint8_t *p; ++ ++ for (plane = 0; plane < 4 && dst[plane]; plane++) { ++ int hsub1 = plane == 1 || plane == 2 ? hsub : 0; ++ int vsub1 = plane == 1 || plane == 2 ? vsub : 0; ++ ++ p = dst[plane] + (y >> vsub1) * dst_linesize[plane]; ++ for (i = 0; i < (h >> vsub1); i++) { ++ memcpy(p + (x >> hsub1) * pixelstep[plane], ++ src[plane], (w >> hsub1) * pixelstep[plane]); ++ p += dst_linesize[plane]; ++ } ++ } ++} ++ ++void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], ++ uint8_t *src[4], int src_linesize[4], int pixelstep[4], ++ int hsub, int vsub, int x, int y, int y2, int w, int h) ++{ ++ int i, plane; ++ uint8_t *p; ++ ++ for (plane = 0; plane < 4 && dst[plane]; plane++) { ++ int hsub1 = plane == 1 || plane == 2 ? hsub : 0; ++ int vsub1 = plane == 1 || plane == 2 ? vsub : 0; ++ ++ p = dst[plane] + (y >> vsub1) * dst_linesize[plane]; ++ for (i = 0; i < (h >> vsub1); i++) { ++ memcpy(p + (x >> hsub1) * pixelstep[plane], ++ src[plane] + src_linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * pixelstep[plane]); ++ p += dst_linesize[plane]; ++ } ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/drawutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/drawutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/drawutils.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/drawutils.h 2012-05-14 14:08:54.705347448 +0200 +@@ -0,0 +1,45 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_DRAWUTILS_H ++#define AVFILTER_DRAWUTILS_H ++ ++/** ++ * @file ++ * misc drawing utilities ++ */ ++ ++#include ++#include "libavutil/pixfmt.h" ++ ++int ff_fill_rgba_map(uint8_t *rgba_map, enum PixelFormat pix_fmt); ++ ++int ff_fill_line_with_color(uint8_t *line[4], int pixel_step[4], int w, ++ uint8_t dst_color[4], ++ enum PixelFormat pix_fmt, uint8_t rgba_color[4], ++ int *is_packed_rgba, uint8_t rgba_map[4]); ++ ++void ff_draw_rectangle(uint8_t *dst[4], int dst_linesize[4], ++ uint8_t *src[4], int pixelstep[4], ++ int hsub, int vsub, int x, int y, int w, int h); ++ ++void ff_copy_rectangle(uint8_t *dst[4], int dst_linesize[4], ++ uint8_t *src[4], int src_linesize[4], int pixelstep[4], ++ int hsub, int vsub, int x, int y, int y2, int w, int h); ++ ++#endif /* AVFILTER_DRAWUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/formats.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/formats.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/formats.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/formats.c 2012-05-14 14:08:54.706347468 +0200 +@@ -19,8 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/eval.h" + #include "libavutil/pixdesc.h" ++#include "libavutil/audioconvert.h" + #include "avfilter.h" ++#include "internal.h" + + /** + * Add all refs from a to ret and destroy a. +@@ -29,7 +32,7 @@ + { + int i; + +- for(i = 0; i < a->refcount; i ++) { ++ for (i = 0; i < a->refcount; i++) { + ret->refs[ret->refcount] = a->refs[i]; + *ret->refs[ret->refcount++] = ret; + } +@@ -44,19 +47,28 @@ + AVFilterFormats *ret; + unsigned i, j, k = 0; + ++ if (a == b) return a; ++ + ret = av_mallocz(sizeof(AVFilterFormats)); + + /* merge list of formats */ + ret->formats = av_malloc(sizeof(*ret->formats) * FFMIN(a->format_count, + b->format_count)); +- for(i = 0; i < a->format_count; i ++) +- for(j = 0; j < b->format_count; j ++) +- if(a->formats[i] == b->formats[j]) ++ for (i = 0; i < a->format_count; i++) ++ for (j = 0; j < b->format_count; j++) ++ if (a->formats[i] == b->formats[j]){ ++ if(k >= FFMIN(a->format_count, b->format_count)){ ++ av_log(0, AV_LOG_ERROR, "Duplicate formats in avfilter_merge_formats() detected\n"); ++ av_free(ret->formats); ++ av_free(ret); ++ return NULL; ++ } + ret->formats[k++] = a->formats[i]; ++ } + + ret->format_count = k; + /* check that there was at least one common format */ +- if(!ret->format_count) { ++ if (!ret->format_count) { + av_free(ret->formats); + av_free(ret); + return NULL; +@@ -70,31 +82,87 @@ + return ret; + } + ++int ff_fmt_is_in(int fmt, const int *fmts) ++{ ++ const int *p; ++ ++ for (p = fmts; *p != -1; p++) { ++ if (fmt == *p) ++ return 1; ++ } ++ return 0; ++} ++ ++#define COPY_INT_LIST(list_copy, list, type) { \ ++ int count = 0; \ ++ if (list) \ ++ for (count = 0; list[count] != -1; count++) \ ++ ; \ ++ list_copy = av_calloc(count+1, sizeof(type)); \ ++ if (list_copy) { \ ++ memcpy(list_copy, list, sizeof(type) * count); \ ++ list_copy[count] = -1; \ ++ } \ ++} ++ ++int *ff_copy_int_list(const int * const list) ++{ ++ int *ret = NULL; ++ COPY_INT_LIST(ret, list, int); ++ return ret; ++} ++ ++int64_t *ff_copy_int64_list(const int64_t * const list) ++{ ++ int64_t *ret = NULL; ++ COPY_INT_LIST(ret, list, int64_t); ++ return ret; ++} ++ ++#define MAKE_FORMAT_LIST() \ ++ AVFilterFormats *formats; \ ++ int count = 0; \ ++ if (fmts) \ ++ for (count = 0; fmts[count] != -1; count++) \ ++ ; \ ++ formats = av_mallocz(sizeof(AVFilterFormats)); \ ++ if (!formats) return NULL; \ ++ formats->format_count = count; \ ++ if (count) { \ ++ formats->formats = av_malloc(sizeof(*formats->formats)*count); \ ++ if (!formats->formats) { \ ++ av_free(formats); \ ++ return NULL; \ ++ } \ ++ } ++ + AVFilterFormats *avfilter_make_format_list(const int *fmts) + { +- AVFilterFormats *formats; +- int count; ++ MAKE_FORMAT_LIST(); ++ while (count--) ++ formats->formats[count] = fmts[count]; + +- for (count = 0; fmts[count] != -1; count++) +- ; ++ return formats; ++} + +- formats = av_mallocz(sizeof(AVFilterFormats)); +- formats->formats = av_malloc(sizeof(*formats->formats) * count); +- formats->format_count = count; +- memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); ++AVFilterFormats *avfilter_make_format64_list(const int64_t *fmts) ++{ ++ MAKE_FORMAT_LIST(); ++ if (count) ++ memcpy(formats->formats, fmts, sizeof(*formats->formats) * count); + + return formats; + } + +-int avfilter_add_format(AVFilterFormats **avff, int fmt) ++int avfilter_add_format(AVFilterFormats **avff, int64_t fmt) + { +- int *fmts; ++ int64_t *fmts; + + if (!(*avff) && !(*avff = av_mallocz(sizeof(AVFilterFormats)))) + return AVERROR(ENOMEM); + + fmts = av_realloc((*avff)->formats, +- sizeof((*avff)->formats) * ((*avff)->format_count+1)); ++ sizeof(*(*avff)->formats) * ((*avff)->format_count+1)); + if (!fmts) + return AVERROR(ENOMEM); + +@@ -103,8 +171,15 @@ + return 0; + } + ++#if FF_API_OLD_ALL_FORMATS_API + AVFilterFormats *avfilter_all_formats(enum AVMediaType type) + { ++ return avfilter_make_all_formats(type); ++} ++#endif ++ ++AVFilterFormats *avfilter_make_all_formats(enum AVMediaType type) ++{ + AVFilterFormats *ret = NULL; + int fmt; + int num_formats = type == AVMEDIA_TYPE_VIDEO ? PIX_FMT_NB : +@@ -118,6 +193,27 @@ + return ret; + } + ++const int64_t avfilter_all_channel_layouts[] = { ++#include "all_channel_layouts.h" ++ -1 ++}; ++ ++AVFilterFormats *avfilter_make_all_channel_layouts(void) ++{ ++ return avfilter_make_format64_list(avfilter_all_channel_layouts); ++} ++ ++AVFilterFormats *avfilter_make_all_packing_formats(void) ++{ ++ static const int packing[] = { ++ AVFILTER_PACKED, ++ AVFILTER_PLANAR, ++ -1, ++ }; ++ ++ return avfilter_make_format_list(packing); ++} ++ + void avfilter_formats_ref(AVFilterFormats *f, AVFilterFormats **ref) + { + *ref = f; +@@ -128,8 +224,8 @@ + static int find_ref_index(AVFilterFormats **ref) + { + int i; +- for(i = 0; i < (*ref)->refcount; i ++) +- if((*ref)->refs[i] == ref) ++ for (i = 0; i < (*ref)->refcount; i++) ++ if ((*ref)->refs[i] == ref) + return i; + return -1; + } +@@ -143,11 +239,11 @@ + + idx = find_ref_index(ref); + +- if(idx >= 0) ++ if (idx >= 0) + memmove((*ref)->refs + idx, (*ref)->refs + idx+1, + sizeof(AVFilterFormats**) * ((*ref)->refcount-idx-1)); + +- if(!--(*ref)->refcount) { ++ if (!--(*ref)->refcount) { + av_free((*ref)->formats); + av_free((*ref)->refs); + av_free(*ref); +@@ -160,10 +256,104 @@ + { + int idx = find_ref_index(oldref); + +- if(idx >= 0) { ++ if (idx >= 0) { + (*oldref)->refs[idx] = newref; + *newref = *oldref; + *oldref = NULL; + } + } + ++/* internal functions for parsing audio format arguments */ ++ ++int ff_parse_pixel_format(enum PixelFormat *ret, const char *arg, void *log_ctx) ++{ ++ char *tail; ++ int pix_fmt = av_get_pix_fmt(arg); ++ if (pix_fmt == PIX_FMT_NONE) { ++ pix_fmt = strtol(arg, &tail, 0); ++ if (*tail || (unsigned)pix_fmt >= PIX_FMT_NB) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid pixel format '%s'\n", arg); ++ return AVERROR(EINVAL); ++ } ++ } ++ *ret = pix_fmt; ++ return 0; ++} ++ ++int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx) ++{ ++ char *tail; ++ int sfmt = av_get_sample_fmt(arg); ++ if (sfmt == AV_SAMPLE_FMT_NONE) { ++ sfmt = strtol(arg, &tail, 0); ++ if (*tail || (unsigned)sfmt >= AV_SAMPLE_FMT_NB) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample format '%s'\n", arg); ++ return AVERROR(EINVAL); ++ } ++ } ++ *ret = sfmt; ++ return 0; ++} ++ ++int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx) ++{ ++ char *tail; ++ double srate = av_strtod(arg, &tail); ++ if (*tail || srate < 1 || (int)srate != srate || srate > INT_MAX) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid sample rate '%s'\n", arg); ++ return AVERROR(EINVAL); ++ } ++ *ret = srate; ++ return 0; ++} ++ ++int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx) ++{ ++ char *tail; ++ int64_t chlayout = av_get_channel_layout(arg); ++ if (chlayout == 0) { ++ chlayout = strtol(arg, &tail, 10); ++ if (*tail || chlayout == 0) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid channel layout '%s'\n", arg); ++ return AVERROR(EINVAL); ++ } ++ } ++ *ret = chlayout; ++ return 0; ++} ++ ++int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx) ++{ ++ char *tail; ++ int planar = strtol(arg, &tail, 10); ++ if (*tail) { ++ planar = !strcmp(arg, "packed") ? 0: ++ !strcmp(arg, "planar") ? 1: -1; ++ } ++ ++ if (planar != 0 && planar != 1) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid packing format '%s'\n", arg); ++ return AVERROR(EINVAL); ++ } ++ *ret = planar; ++ return 0; ++} ++ ++#ifdef TEST ++ ++#undef printf ++ ++int main(void) ++{ ++ const int64_t *cl; ++ char buf[512]; ++ ++ for (cl = avfilter_all_channel_layouts; *cl != -1; cl++) { ++ av_get_channel_layout_string(buf, sizeof(buf), -1, *cl); ++ printf("%s\n", buf); ++ } ++ ++ return 0; ++} ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/gradfun.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/gradfun.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/gradfun.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/gradfun.h 2012-05-14 14:08:54.707347488 +0200 +@@ -33,16 +33,16 @@ + int chroma_r; ///< blur radius for the chroma planes + uint16_t *buf; ///< holds image data for blur algorithm passed into filter. + /// DSP functions. +- void (*filter_line) (uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); +- void (*blur_line) (uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); ++ void (*filter_line) (uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); ++ void (*blur_line) (uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); + } GradFunContext; + +-void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); +-void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); ++void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); ++void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); + +-void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); +-void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers); ++void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); ++void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers); + +-void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width); ++void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width); + + #endif /* AVFILTER_GRADFUN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/graphdump.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/graphdump.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/graphdump.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/graphdump.c 2012-05-14 14:08:54.708347509 +0200 +@@ -0,0 +1,171 @@ ++/* ++ * Filter graphs to bad ASCII-art ++ * Copyright (c) 2012 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++#include "avfiltergraph.h" ++ ++#define BPRINTF(...) \ ++ cur += snprintf(cur, buf_end - FFMIN(cur, buf_end), __VA_ARGS__) ++ ++#define BPAD(c, l) \ ++ do { \ ++ if (cur < buf_end) memset(cur, c, FFMIN(l, buf_end - cur)); cur += l; \ ++ } while (0) ++ ++static int snprint_link_prop(char *buf, char *buf_end, AVFilterLink *link) ++{ ++ char *cur = buf, *format; ++ char layout[64]; ++ ++ switch (link->type) { ++ case AVMEDIA_TYPE_VIDEO: ++ format = av_x_if_null(av_get_pix_fmt_name(link->format), "?"); ++ BPRINTF("[%dx%d %d:%d %s]", link->w, link->h, ++ link->sample_aspect_ratio.num, ++ link->sample_aspect_ratio.den, ++ format); ++ break; ++ ++ case AVMEDIA_TYPE_AUDIO: ++ av_get_channel_layout_string(layout, sizeof(layout), ++ -1, link->channel_layout); ++ format = av_x_if_null(av_get_sample_fmt_name(link->format), "?"); ++ BPRINTF("[%dHz %s:%s:%s]", ++ (int)link->sample_rate, format, layout, ++ link->planar ? "planar" : "packed"); ++ break; ++ ++ default: ++ BPRINTF("?"); ++ break; ++ } ++ return cur - buf; ++} ++ ++static size_t avfilter_graph_dump_to_buf(AVFilterGraph *graph, ++ char *buf, char *buf_end) ++{ ++ char *cur = buf, *e; ++ unsigned i, j, x; ++ ++ for (i = 0; i < graph->filter_count; i++) { ++ AVFilterContext *filter = graph->filters[i]; ++ unsigned max_src_name = 0, max_dst_name = 0; ++ unsigned max_in_name = 0, max_out_name = 0; ++ unsigned max_in_fmt = 0, max_out_fmt = 0; ++ unsigned width, height, in_indent; ++ unsigned lname = strlen(filter->name); ++ unsigned ltype = strlen(filter->filter->name); ++ ++ for (j = 0; j < filter->input_count; j++) { ++ AVFilterLink *l = filter->inputs[j]; ++ unsigned ln = strlen(l->src->name) + 1 + strlen(l->srcpad->name); ++ max_src_name = FFMAX(max_src_name, ln); ++ max_in_name = FFMAX(max_in_name, strlen(l->dstpad->name)); ++ max_in_fmt = FFMAX(max_in_fmt, snprint_link_prop(NULL, NULL, l)); ++ } ++ for (j = 0; j < filter->output_count; j++) { ++ AVFilterLink *l = filter->outputs[j]; ++ unsigned ln = strlen(l->dst->name) + 1 + strlen(l->dstpad->name); ++ max_dst_name = FFMAX(max_dst_name, ln); ++ max_out_name = FFMAX(max_out_name, strlen(l->srcpad->name)); ++ max_out_fmt = FFMAX(max_out_fmt, snprint_link_prop(NULL, NULL, l)); ++ } ++ in_indent = max_src_name + max_in_name + max_in_fmt; ++ in_indent += in_indent ? 4 : 0; ++ width = FFMAX(lname + 2, ltype + 4); ++ height = FFMAX3(2, filter->input_count, filter->output_count); ++ BPAD(' ', in_indent); ++ BPRINTF("+"); ++ BPAD('-', width); ++ BPRINTF("+\n"); ++ for (j = 0; j < height; j++) { ++ unsigned in_no = j - (height - filter->input_count ) / 2; ++ unsigned out_no = j - (height - filter->output_count) / 2; ++ ++ /* Input link */ ++ if (in_no < filter->input_count) { ++ AVFilterLink *l = filter->inputs[in_no]; ++ e = cur + max_src_name + 2; ++ BPRINTF("%s:%s", l->src->name, l->srcpad->name); ++ BPAD('-', e - cur); ++ e = cur + max_in_fmt + 2 + ++ max_in_name - strlen(l->dstpad->name); ++ cur += snprint_link_prop(cur, buf_end, l); ++ BPAD('-', e - cur); ++ BPRINTF("%s", l->dstpad->name); ++ } else { ++ BPAD(' ', in_indent); ++ } ++ ++ /* Filter */ ++ BPRINTF("|"); ++ if (j == (height - 2) / 2) { ++ x = (width - lname) / 2; ++ BPRINTF("%*s%-*s", x, "", width - x, filter->name); ++ } else if (j == (height - 2) / 2 + 1) { ++ x = (width - ltype - 2) / 2; ++ BPRINTF("%*s(%s)%*s", x, "", filter->filter->name, ++ width - ltype - 2 - x, ""); ++ } else { ++ BPAD(' ', width); ++ } ++ BPRINTF("|"); ++ ++ /* Output link */ ++ if (out_no < filter->output_count) { ++ AVFilterLink *l = filter->outputs[out_no]; ++ unsigned ln = strlen(l->dst->name) + 1 + ++ strlen(l->dstpad->name); ++ e = cur + max_out_name + 2; ++ BPRINTF("%s", l->srcpad->name); ++ BPAD('-', e - cur); ++ e = cur + max_out_fmt + 2 + ++ max_dst_name - ln; ++ cur += snprint_link_prop(cur, buf_end, l); ++ BPAD('-', e - cur); ++ BPRINTF("%s:%s", l->dst->name, l->dstpad->name); ++ } ++ BPRINTF("\n"); ++ } ++ BPAD(' ', in_indent); ++ BPRINTF("+"); ++ BPAD('-', width); ++ BPRINTF("+\n"); ++ BPRINTF("\n"); ++ } ++ if (cur < buf_end) ++ *(cur++) = 0; ++ return cur - buf; ++} ++ ++char *avfilter_graph_dump(AVFilterGraph *graph, const char *options) ++{ ++ size_t buf_size = avfilter_graph_dump_to_buf(graph, NULL, NULL); ++ char *buf = av_malloc(buf_size); ++ if (!buf) ++ return NULL; ++ avfilter_graph_dump_to_buf(graph, buf, buf + buf_size); ++ return buf; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/graphparser.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/graphparser.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/graphparser.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/graphparser.c 2012-05-14 14:08:54.709347530 +0200 +@@ -36,7 +36,7 @@ + */ + static int link_filter(AVFilterContext *src, int srcpad, + AVFilterContext *dst, int dstpad, +- AVClass *log_ctx) ++ void *log_ctx) + { + int ret; + if ((ret = avfilter_link(src, srcpad, dst, dstpad))) { +@@ -55,7 +55,7 @@ + * @return a pointer (that need to be freed after use) to the name + * between parenthesis + */ +-static char *parse_link_name(const char **buf, AVClass *log_ctx) ++static char *parse_link_name(const char **buf, void *log_ctx) + { + const char *start = *buf; + char *name; +@@ -83,8 +83,8 @@ + * Create an instance of a filter, initialize and insert it in the + * filtergraph in *ctx. + * ++ * @param filt_ctx put here a filter context in case of successful creation and configuration, NULL otherwise. + * @param ctx the filtergraph context +- * @param put here a filter context in case of successful creation and configuration, NULL otherwise. + * @param index an index which is supposed to be unique for each filter instance added to the filtergraph + * @param filt_name the name of the filter to create + * @param args the arguments provided to the filter during its initialization +@@ -92,14 +92,14 @@ + * @return 0 in case of success, a negative AVERROR code otherwise + */ + static int create_filter(AVFilterContext **filt_ctx, AVFilterGraph *ctx, int index, +- const char *filt_name, const char *args, AVClass *log_ctx) ++ const char *filt_name, const char *args, void *log_ctx) + { + AVFilter *filt; + char inst_name[30]; + char tmp_args[256]; + int ret; + +- snprintf(inst_name, sizeof(inst_name), "Parsed filter %d %s", index, filt_name); ++ snprintf(inst_name, sizeof(inst_name), "Parsed_%s_%d", filt_name, index); + + filt = avfilter_get_by_name(filt_name); + +@@ -121,7 +121,7 @@ + return ret; + } + +- if (!strcmp(filt_name, "scale") && !strstr(args, "flags")) { ++ if (!strcmp(filt_name, "scale") && args && !strstr(args, "flags")) { + snprintf(tmp_args, sizeof(tmp_args), "%s:%s", + args, ctx->scale_sws_opts); + args = tmp_args; +@@ -141,6 +141,8 @@ + * corresponding filter instance which is added to graph with + * create_filter(). + * ++ * @param filt_ctx Pointer that is set to the created and configured filter ++ * context on success, set to NULL on failure. + * @param filt_ctx put here a pointer to the created filter context on + * success, NULL otherwise + * @param buf pointer to the buffer to parse, *buf will be updated to +@@ -151,7 +153,7 @@ + * @return 0 in case of success, a negative AVERROR code otherwise + */ + static int parse_filter(AVFilterContext **filt_ctx, const char **buf, AVFilterGraph *graph, +- int index, AVClass *log_ctx) ++ int index, void *log_ctx) + { + char *opts = NULL; + char *name = av_get_token(buf, "=,;[\n"); +@@ -168,13 +170,18 @@ + return ret; + } + +-static void free_inout(AVFilterInOut *head) ++AVFilterInOut *avfilter_inout_alloc(void) + { +- while (head) { +- AVFilterInOut *next = head->next; +- av_free(head->name); +- av_free(head); +- head = next; ++ return av_mallocz(sizeof(AVFilterInOut)); ++} ++ ++void avfilter_inout_free(AVFilterInOut **inout) ++{ ++ while (*inout) { ++ AVFilterInOut *next = (*inout)->next; ++ av_freep(&(*inout)->name); ++ av_freep(inout); ++ *inout = next; + } + } + +@@ -201,7 +208,7 @@ + + static int link_filter_inouts(AVFilterContext *filt_ctx, + AVFilterInOut **curr_inputs, +- AVFilterInOut **open_inputs, AVClass *log_ctx) ++ AVFilterInOut **open_inputs, void *log_ctx) + { + int pad = filt_ctx->input_count, ret; + +@@ -249,7 +256,7 @@ + } + + static int parse_inputs(const char **buf, AVFilterInOut **curr_inputs, +- AVFilterInOut **open_outputs, AVClass *log_ctx) ++ AVFilterInOut **open_outputs, void *log_ctx) + { + int pad = 0; + +@@ -284,7 +291,7 @@ + + static int parse_outputs(const char **buf, AVFilterInOut **curr_inputs, + AVFilterInOut **open_inputs, +- AVFilterInOut **open_outputs, AVClass *log_ctx) ++ AVFilterInOut **open_outputs, void *log_ctx) + { + int ret, pad = 0; + +@@ -328,13 +335,15 @@ + } + + int avfilter_graph_parse(AVFilterGraph *graph, const char *filters, +- AVFilterInOut *open_inputs, +- AVFilterInOut *open_outputs, AVClass *log_ctx) ++ AVFilterInOut **open_inputs_ptr, AVFilterInOut **open_outputs_ptr, ++ void *log_ctx) + { +- int index = 0, ret; ++ int index = 0, ret = 0; + char chr = 0; + + AVFilterInOut *curr_inputs = NULL; ++ AVFilterInOut *open_inputs = open_inputs_ptr ? *open_inputs_ptr : NULL; ++ AVFilterInOut *open_outputs = open_outputs_ptr ? *open_outputs_ptr : NULL; + + do { + AVFilterContext *filter; +@@ -342,24 +351,24 @@ + filters += strspn(filters, WHITESPACES); + + if ((ret = parse_inputs(&filters, &curr_inputs, &open_outputs, log_ctx)) < 0) +- goto fail; ++ goto end; + + if ((ret = parse_filter(&filter, &filters, graph, index, log_ctx)) < 0) +- goto fail; ++ goto end; + + if (filter->input_count == 1 && !curr_inputs && !index) { +- /* First input can be omitted if it is "[in]" */ ++ /* First input pad, assume it is "[in]" if not specified */ + const char *tmp = "[in]"; + if ((ret = parse_inputs(&tmp, &curr_inputs, &open_outputs, log_ctx)) < 0) +- goto fail; ++ goto end; + } + + if ((ret = link_filter_inouts(filter, &curr_inputs, &open_inputs, log_ctx)) < 0) +- goto fail; ++ goto end; + + if ((ret = parse_outputs(&filters, &curr_inputs, &open_inputs, &open_outputs, + log_ctx)) < 0) +- goto fail; ++ goto end; + + filters += strspn(filters, WHITESPACES); + chr = *filters++; +@@ -369,7 +378,7 @@ + "Invalid filterchain containing an unlabelled output pad: \"%s\"\n", + filterchain); + ret = AVERROR(EINVAL); +- goto fail; ++ goto end; + } + index++; + } while (chr == ',' || chr == ';'); +@@ -379,23 +388,29 @@ + "Unable to parse graph description substring: \"%s\"\n", + filters - 1); + ret = AVERROR(EINVAL); +- goto fail; ++ goto end; + } + +- if (open_inputs && !strcmp(open_inputs->name, "out") && curr_inputs) { +- /* Last output can be omitted if it is "[out]" */ ++ if (curr_inputs) { ++ /* Last output pad, assume it is "[out]" if not specified */ + const char *tmp = "[out]"; + if ((ret = parse_outputs(&tmp, &curr_inputs, &open_inputs, &open_outputs, + log_ctx)) < 0) +- goto fail; ++ goto end; + } + +- return 0; +- +- fail: +- avfilter_graph_free(graph); +- free_inout(open_inputs); +- free_inout(open_outputs); +- free_inout(curr_inputs); ++end: ++ /* clear open_in/outputs only if not passed as parameters */ ++ if (open_inputs_ptr) *open_inputs_ptr = open_inputs; ++ else avfilter_inout_free(&open_inputs); ++ if (open_outputs_ptr) *open_outputs_ptr = open_outputs; ++ else avfilter_inout_free(&open_outputs); ++ avfilter_inout_free(&curr_inputs); ++ ++ if (ret < 0) { ++ for (; graph->filter_count > 0; graph->filter_count--) ++ avfilter_free(graph->filters[graph->filter_count - 1]); ++ av_freep(&graph->filters); ++ } + return ret; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/internal.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/internal.h 2012-05-14 14:08:54.710347550 +0200 +@@ -27,6 +27,22 @@ + #include "avfilter.h" + #include "avfiltergraph.h" + ++#define POOL_SIZE 32 ++typedef struct AVFilterPool { ++ AVFilterBufferRef *pic[POOL_SIZE]; ++ int count; ++ int refcount; ++ int draining; ++} AVFilterPool; ++ ++typedef struct AVFilterCommand { ++ double time; ///< time expressed in seconds ++ char *command; ///< command ++ char *arg; ///< optional argument for the command ++ int flags; ++ struct AVFilterCommand *next; ++} AVFilterCommand; ++ + /** + * Check for the validity of graph. + * +@@ -52,4 +68,71 @@ + /** default handler for freeing audio/video buffer when there are no references left */ + void ff_avfilter_default_free_buffer(AVFilterBuffer *buf); + +-#endif /* AVFILTER_INTERNAL_H */ ++/** Tell is a format is contained in the provided list terminated by -1. */ ++int ff_fmt_is_in(int fmt, const int *fmts); ++ ++/** ++ * Return a copy of a list of integers terminated by -1, or NULL in ++ * case of copy failure. ++ */ ++int *ff_copy_int_list(const int * const list); ++ ++/** ++ * Return a copy of a list of 64-bit integers, or NULL in case of ++ * copy failure. ++ */ ++int64_t *ff_copy_int64_list(const int64_t * const list); ++ ++/* Functions to parse audio format arguments */ ++ ++/** ++ * Parse a pixel format. ++ * ++ * @param ret pixel format pointer to where the value should be written ++ * @param arg string to parse ++ * @param log_ctx log context ++ * @return 0 in case of success, a negative AVERROR code on error ++ */ ++int ff_parse_pixel_format(enum PixelFormat *ret, const char *arg, void *log_ctx); ++ ++/** ++ * Parse a sample rate. ++ * ++ * @param ret unsigned integer pointer to where the value should be written ++ * @param arg string to parse ++ * @param log_ctx log context ++ * @return 0 in case of success, a negative AVERROR code on error ++ */ ++int ff_parse_sample_rate(int *ret, const char *arg, void *log_ctx); ++ ++/** ++ * Parse a sample format name or a corresponding integer representation. ++ * ++ * @param ret integer pointer to where the value should be written ++ * @param arg string to parse ++ * @param log_ctx log context ++ * @return 0 in case of success, a negative AVERROR code on error ++ */ ++int ff_parse_sample_format(int *ret, const char *arg, void *log_ctx); ++ ++/** ++ * Parse a channel layout or a corresponding integer representation. ++ * ++ * @param ret 64bit integer pointer to where the value should be written. ++ * @param arg string to parse ++ * @param log_ctx log context ++ * @return 0 in case of success, a negative AVERROR code on error ++ */ ++int ff_parse_channel_layout(int64_t *ret, const char *arg, void *log_ctx); ++ ++/** ++ * Parse a packing format or a corresponding integer representation. ++ * ++ * @param ret integer pointer to where the value should be written ++ * @param arg string to parse ++ * @param log_ctx log context ++ * @return 0 in case of success, a negative AVERROR code on error ++ */ ++int ff_parse_packing_format(int *ret, const char *arg, void *log_ctx); ++ ++#endif /* AVFILTER_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/cpudetect.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/cpudetect.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/cpudetect.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/cpudetect.h 2012-05-14 14:08:54.711347570 +0200 +@@ -0,0 +1,59 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_CPUDETECT_H ++#define MPLAYER_CPUDETECT_H ++ ++//#include "config.h" ++ ++#define CPUTYPE_I386 3 ++#define CPUTYPE_I486 4 ++#define CPUTYPE_I586 5 ++#define CPUTYPE_I686 6 ++ ++#include "libavutil/x86_cpu.h" ++ ++typedef struct cpucaps_s { ++ int cpuType; ++ int cpuModel; ++ int cpuStepping; ++ int hasMMX; ++ int hasMMX2; ++ int has3DNow; ++ int has3DNowExt; ++ int hasSSE; ++ int hasSSE2; ++ int hasSSE3; ++ int hasSSSE3; ++ int hasSSE4a; ++ int isX86; ++ unsigned cl_size; /* size of cache line */ ++ int hasAltiVec; ++ int hasTSC; ++} CpuCaps; ++ ++extern CpuCaps gCpuCaps; ++ ++void do_cpuid(unsigned int ax, unsigned int *p); ++ ++void GetCpuCaps(CpuCaps *caps); ++ ++/* returned value is malloc()'ed so free() it after use */ ++char *GetCpuFriendlyName(unsigned int regs[], unsigned int regs2[]); ++ ++#endif /* MPLAYER_CPUDETECT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/help_mp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/help_mp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/help_mp.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/help_mp.h 2012-05-14 14:08:54.719347730 +0200 +@@ -0,0 +1,2136 @@ ++/* WARNING! This is a generated file, do NOT edit. ++ * See the help/ subdirectory for the editable files. */ ++ ++#ifndef MPLAYER_HELP_MP_H ++#define MPLAYER_HELP_MP_H ++ ++// $Revision: 32397 $ ++// MASTER FILE. Use this file as base for translations. ++// Translated files should be sent to the mplayer-DOCS mailing list or ++// to the help messages maintainer, see DOCS/tech/MAINTAINERS. ++// The header of the translated file should contain credits and contact ++// information. Before major releases we will notify all translators to update ++// their files. Please do not simply translate and forget this, outdated ++// translations quickly become worthless. To help us spot outdated files put a ++// note like "sync'ed with help_mp-en.h XXX" in the header of the translation. ++// Do NOT translate the above lines, just follow the instructions. ++ ++ ++// ========================= MPlayer help =========================== ++ ++static const char help_text[]= ++"Usage: mplayer [options] [url|path/]filename\n" ++"\n" ++"Basic options: (complete list in the man page)\n" ++" -vo select video output driver ('-vo help' for a list)\n" ++" -ao select audio output driver ('-ao help' for a list)\n" ++#ifdef CONFIG_VCD ++" vcd:// play (S)VCD (Super Video CD) track (raw device, no mount)\n" ++#endif ++#ifdef CONFIG_DVDREAD ++" dvd:// play DVD title from device instead of plain file\n" ++#endif ++" -alang/-slang select DVD audio/subtitle language (by 2-char country code)\n" ++" -ss seek to given (seconds or hh:mm:ss) position\n" ++" -nosound do not play sound\n" ++" -fs fullscreen playback (or -vm, -zoom, details in the man page)\n" ++" -x -y set display resolution (for use with -vm or -zoom)\n" ++" -sub specify subtitle file to use (also see -subfps, -subdelay)\n" ++" -playlist specify playlist file\n" ++" -vid x -aid y select video (x) and audio (y) stream to play\n" ++" -fps x -srate y change video (x fps) and audio (y Hz) rate\n" ++" -pp enable postprocessing filter (details in the man page)\n" ++" -framedrop enable frame dropping (for slow machines)\n" ++"\n" ++"Basic keys: (complete list in the man page, also check input.conf)\n" ++" <- or -> seek backward/forward 10 seconds\n" ++" down or up seek backward/forward 1 minute\n" ++" pgdown or pgup seek backward/forward 10 minutes\n" ++" < or > step backward/forward in playlist\n" ++" p or SPACE pause movie (press any key to continue)\n" ++" q or ESC stop playing and quit program\n" ++" + or - adjust audio delay by +/- 0.1 second\n" ++" o cycle OSD mode: none / seekbar / seekbar + timer\n" ++" * or / increase or decrease PCM volume\n" ++" x or z adjust subtitle delay by +/- 0.1 second\n" ++" r or t adjust subtitle position up/down, also see -vf expand\n" ++"\n" ++" * * * SEE THE MAN PAGE FOR DETAILS, FURTHER (ADVANCED) OPTIONS AND KEYS * * *\n" ++"\n"; ++ ++// ========================= MPlayer messages =========================== ++ ++// mplayer.c ++#define MSGTR_Exiting "\nExiting...\n" ++#define MSGTR_ExitingHow "\nExiting... (%s)\n" ++#define MSGTR_Exit_quit "Quit" ++#define MSGTR_Exit_eof "End of file" ++#define MSGTR_Exit_error "Fatal error" ++#define MSGTR_IntBySignal "\nMPlayer interrupted by signal %d in module: %s\n" ++#define MSGTR_NoHomeDir "Cannot find HOME directory.\n" ++#define MSGTR_GetpathProblem "get_path(\"config\") problem\n" ++#define MSGTR_CreatingCfgFile "Creating config file: %s\n" ++#define MSGTR_BuiltinCodecsConf "Using built-in default codecs.conf.\n" ++#define MSGTR_CantLoadFont "Cannot load bitmap font: %s\n" ++#define MSGTR_CantLoadSub "Cannot load subtitles: %s\n" ++#define MSGTR_DumpSelectedStreamMissing "dump: FATAL: Selected stream missing!\n" ++#define MSGTR_CantOpenDumpfile "Cannot open dump file.\n" ++#define MSGTR_CoreDumped "Core dumped ;)\n" ++#define MSGTR_FPSnotspecified "FPS not specified in the header or invalid, use the -fps option.\n" ++#define MSGTR_TryForceAudioFmtStr "Trying to force audio codec driver family %s...\n" ++#define MSGTR_CantFindAudioCodec "Cannot find codec for audio format 0x%X.\n" ++#define MSGTR_TryForceVideoFmtStr "Trying to force video codec driver family %s...\n" ++#define MSGTR_CantFindVideoCodec "Cannot find codec matching selected -vo and video format 0x%X.\n" ++#define MSGTR_CannotInitVO "FATAL: Cannot initialize video driver.\n" ++#define MSGTR_CannotInitAO "Could not open/initialize audio device -> no sound.\n" ++#define MSGTR_StartPlaying "Starting playback...\n" ++ ++#define MSGTR_SystemTooSlow "\n\n"\ ++" ************************************************\n"\ ++" **** Your system is too SLOW to play this! ****\n"\ ++" ************************************************\n\n"\ ++"Possible reasons, problems, workarounds:\n"\ ++"- Most common: broken/buggy _audio_ driver\n"\ ++" - Try -ao sdl or use the OSS emulation of ALSA.\n"\ ++" - Experiment with different values for -autosync, 30 is a good start.\n"\ ++"- Slow video output\n"\ ++" - Try a different -vo driver (-vo help for a list) or try -framedrop!\n"\ ++"- Slow CPU\n"\ ++" - Don't try to play a big DVD/DivX on a slow CPU! Try some of the lavdopts,\n"\ ++" e.g. -vfm ffmpeg -lavdopts lowres=1:fast:skiploopfilter=all.\n"\ ++"- Broken file\n"\ ++" - Try various combinations of -nobps -ni -forceidx -mc 0.\n"\ ++"- Slow media (NFS/SMB mounts, DVD, VCD etc)\n"\ ++" - Try -cache 8192.\n"\ ++"- Are you using -cache to play a non-interleaved AVI file?\n"\ ++" - Try -nocache.\n"\ ++"Read DOCS/HTML/en/video.html for tuning/speedup tips.\n"\ ++"If none of this helps you, read DOCS/HTML/en/bugreports.html.\n\n" ++ ++#define MSGTR_NoGui "MPlayer was compiled WITHOUT GUI support.\n" ++#define MSGTR_GuiNeedsX "MPlayer GUI requires X11.\n" ++#define MSGTR_Playing "\nPlaying %s.\n" ++#define MSGTR_NoSound "Audio: no sound\n" ++#define MSGTR_FPSforced "FPS forced to be %5.3f (ftime: %5.3f).\n" ++#define MSGTR_CompiledWithRuntimeDetection "Compiled with runtime CPU detection.\n" ++#define MSGTR_CompiledWithCPUExtensions "Compiled for x86 CPU with extensions:" ++#define MSGTR_AvailableVideoOutputDrivers "Available video output drivers:\n" ++#define MSGTR_AvailableAudioOutputDrivers "Available audio output drivers:\n" ++#define MSGTR_AvailableAudioCodecs "Available audio codecs:\n" ++#define MSGTR_AvailableVideoCodecs "Available video codecs:\n" ++#define MSGTR_AvailableAudioFm "Available (compiled-in) audio codec families/drivers:\n" ++#define MSGTR_AvailableVideoFm "Available (compiled-in) video codec families/drivers:\n" ++#define MSGTR_AvailableFsType "Available fullscreen layer change modes:\n" ++#define MSGTR_UsingRTCTiming "Using Linux hardware RTC timing (%ldHz).\n" ++#define MSGTR_CannotReadVideoProperties "Video: Cannot read properties.\n" ++#define MSGTR_NoStreamFound "No stream found.\n" ++#define MSGTR_ErrorInitializingVODevice "Error opening/initializing the selected video_out (-vo) device.\n" ++#define MSGTR_ForcedVideoCodec "Forced video codec: %s\n" ++#define MSGTR_ForcedAudioCodec "Forced audio codec: %s\n" ++#define MSGTR_Video_NoVideo "Video: no video\n" ++#define MSGTR_NotInitializeVOPorVO "\nFATAL: Could not initialize video filters (-vf) or video output (-vo).\n" ++#define MSGTR_Paused "\n ===== PAUSE =====\r" // no more than 23 characters (status line for audio files) ++#define MSGTR_PlaylistLoadUnable "\nUnable to load playlist %s.\n" ++#define MSGTR_Exit_SIGILL_RTCpuSel \ ++"- MPlayer crashed by an 'Illegal Instruction'.\n"\ ++" It may be a bug in our new runtime CPU-detection code...\n"\ ++" Please read DOCS/HTML/en/bugreports.html.\n" ++#define MSGTR_Exit_SIGILL \ ++"- MPlayer crashed by an 'Illegal Instruction'.\n"\ ++" It usually happens when you run it on a CPU different than the one it was\n"\ ++" compiled/optimized for.\n"\ ++" Verify this!\n" ++#define MSGTR_Exit_SIGSEGV_SIGFPE \ ++"- MPlayer crashed by bad usage of CPU/FPU/RAM.\n"\ ++" Recompile MPlayer with --enable-debug and make a 'gdb' backtrace and\n"\ ++" disassembly. Details in DOCS/HTML/en/bugreports_what.html#bugreports_crash.\n" ++#define MSGTR_Exit_SIGCRASH \ ++"- MPlayer crashed. This shouldn't happen.\n"\ ++" It can be a bug in the MPlayer code _or_ in your drivers _or_ in your\n"\ ++" gcc version. If you think it's MPlayer's fault, please read\n"\ ++" DOCS/HTML/en/bugreports.html and follow the instructions there. We can't and\n"\ ++" won't help unless you provide this information when reporting a possible bug.\n" ++#define MSGTR_LoadingConfig "Loading config '%s'\n" ++#define MSGTR_LoadingProtocolProfile "Loading protocol-related profile '%s'\n" ++#define MSGTR_LoadingExtensionProfile "Loading extension-related profile '%s'\n" ++#define MSGTR_AddedSubtitleFile "SUB: Added subtitle file (%d): %s\n" ++#define MSGTR_RemovedSubtitleFile "SUB: Removed subtitle file (%d): %s\n" ++#define MSGTR_ErrorOpeningOutputFile "Error opening file [%s] for writing!\n" ++#define MSGTR_CommandLine "CommandLine:" ++#define MSGTR_RTCDeviceNotOpenable "Failed to open %s: %s (it should be readable by the user.)\n" ++#define MSGTR_LinuxRTCInitErrorIrqpSet "Linux RTC init error in ioctl (rtc_irqp_set %lu): %s\n" ++#define MSGTR_IncreaseRTCMaxUserFreq "Try adding \"echo %lu > /proc/sys/dev/rtc/max-user-freq\" to your system startup scripts.\n" ++#define MSGTR_LinuxRTCInitErrorPieOn "Linux RTC init error in ioctl (rtc_pie_on): %s\n" ++#define MSGTR_UsingTimingType "Using %s timing.\n" ++#define MSGTR_NoIdleAndGui "The -idle option cannot be used with GMPlayer.\n" ++#define MSGTR_MenuInitialized "Menu initialized: %s\n" ++#define MSGTR_MenuInitFailed "Menu init failed.\n" ++#define MSGTR_Getch2InitializedTwice "WARNING: getch2_init called twice!\n" ++#define MSGTR_DumpstreamFdUnavailable "Cannot dump this stream - no file descriptor available.\n" ++#define MSGTR_CantOpenLibmenuFilterWithThisRootMenu "Can't open libmenu video filter with root menu %s.\n" ++#define MSGTR_AudioFilterChainPreinitError "Error at audio filter chain pre-init!\n" ++#define MSGTR_LinuxRTCReadError "Linux RTC read error: %s\n" ++#define MSGTR_SoftsleepUnderflow "Warning! Softsleep underflow!\n" ++#define MSGTR_DvdnavNullEvent "DVDNAV Event NULL?!\n" ++#define MSGTR_DvdnavHighlightEventBroken "DVDNAV Event: Highlight event broken\n" ++#define MSGTR_DvdnavEvent "DVDNAV Event: %s\n" ++#define MSGTR_DvdnavHighlightHide "DVDNAV Event: Highlight Hide\n" ++#define MSGTR_DvdnavStillFrame "######################################## DVDNAV Event: Still Frame: %d sec(s)\n" ++#define MSGTR_DvdnavNavStop "DVDNAV Event: Nav Stop\n" ++#define MSGTR_DvdnavNavNOP "DVDNAV Event: Nav NOP\n" ++#define MSGTR_DvdnavNavSpuStreamChangeVerbose "DVDNAV Event: Nav SPU Stream Change: phys: %d/%d/%d logical: %d\n" ++#define MSGTR_DvdnavNavSpuStreamChange "DVDNAV Event: Nav SPU Stream Change: phys: %d logical: %d\n" ++#define MSGTR_DvdnavNavAudioStreamChange "DVDNAV Event: Nav Audio Stream Change: phys: %d logical: %d\n" ++#define MSGTR_DvdnavNavVTSChange "DVDNAV Event: Nav VTS Change\n" ++#define MSGTR_DvdnavNavCellChange "DVDNAV Event: Nav Cell Change\n" ++#define MSGTR_DvdnavNavSpuClutChange "DVDNAV Event: Nav SPU CLUT Change\n" ++#define MSGTR_DvdnavNavSeekDone "DVDNAV Event: Nav Seek Done\n" ++#define MSGTR_MenuCall "Menu call\n" ++#define MSGTR_MasterQuit "Option -udp-slave: exiting because master exited\n" ++#define MSGTR_InvalidIP "Option -udp-ip: invalid IP address\n" ++ ++// --- edit decision lists ++#define MSGTR_EdlOutOfMem "Can't allocate enough memory to hold EDL data.\n" ++#define MSGTR_EdlOutOfMemFile "Can't allocate enough memory to hold EDL file name [%s].\n" ++#define MSGTR_EdlRecordsNo "Read %d EDL actions.\n" ++#define MSGTR_EdlQueueEmpty "There are no EDL actions to take care of.\n" ++#define MSGTR_EdlCantOpenForWrite "Can't open EDL file [%s] for writing.\n" ++#define MSGTR_EdlCantOpenForRead "Can't open EDL file [%s] for reading.\n" ++#define MSGTR_EdlNOsh_video "Cannot use EDL without video, disabling.\n" ++#define MSGTR_EdlNOValidLine "Invalid EDL line: %s\n" ++#define MSGTR_EdlBadlyFormattedLine "Badly formatted EDL line [%d], discarding.\n" ++#define MSGTR_EdlBadLineOverlap "Last stop position was [%f]; next start is [%f].\n"\ ++"Entries must be in chronological order, cannot overlap. Discarding.\n" ++#define MSGTR_EdlBadLineBadStop "Stop time has to be after start time.\n" ++#define MSGTR_EdloutBadStop "EDL skip canceled, last start > stop\n" ++#define MSGTR_EdloutStartSkip "EDL skip start, press 'i' again to end block.\n" ++#define MSGTR_EdloutEndSkip "EDL skip end, line written.\n" ++#define MSGTR_MPEndposNoSizeBased "Option -endpos in MPlayer does not yet support size units.\n" ++ ++// mplayer.c OSD ++#define MSGTR_OSDenabled "enabled" ++#define MSGTR_OSDdisabled "disabled" ++#define MSGTR_OSDAudio "Audio: %s" ++#define MSGTR_OSDVideo "Video: %s" ++#define MSGTR_OSDChannel "Channel: %s" ++#define MSGTR_OSDSubDelay "Sub delay: %d ms" ++#define MSGTR_OSDSpeed "Speed: x %6.2f" ++#define MSGTR_OSDosd "OSD: %s" ++#define MSGTR_OSDChapter "Chapter: (%d) %s" ++#define MSGTR_OSDAngle "Angle: %d/%d" ++#define MSGTR_OSDDeinterlace "Deinterlace: %s" ++ ++// property values ++#define MSGTR_Enabled "enabled" ++#define MSGTR_EnabledEdl "enabled (EDL)" ++#define MSGTR_Disabled "disabled" ++#define MSGTR_HardFrameDrop "hard" ++#define MSGTR_Unknown "unknown" ++#define MSGTR_Bottom "bottom" ++#define MSGTR_Center "center" ++#define MSGTR_Top "top" ++#define MSGTR_SubSourceFile "file" ++#define MSGTR_SubSourceVobsub "vobsub" ++#define MSGTR_SubSourceDemux "embedded" ++ ++// OSD bar names ++#define MSGTR_Volume "Volume" ++#define MSGTR_Panscan "Panscan" ++#define MSGTR_Gamma "Gamma" ++#define MSGTR_Brightness "Brightness" ++#define MSGTR_Contrast "Contrast" ++#define MSGTR_Saturation "Saturation" ++#define MSGTR_Hue "Hue" ++#define MSGTR_Balance "Balance" ++ ++// property state ++#define MSGTR_LoopStatus "Loop: %s" ++#define MSGTR_MuteStatus "Mute: %s" ++#define MSGTR_AVDelayStatus "A-V delay: %s" ++#define MSGTR_OnTopStatus "Stay on top: %s" ++#define MSGTR_RootwinStatus "Rootwin: %s" ++#define MSGTR_BorderStatus "Border: %s" ++#define MSGTR_FramedroppingStatus "Framedropping: %s" ++#define MSGTR_VSyncStatus "VSync: %s" ++#define MSGTR_SubSelectStatus "Subtitles: %s" ++#define MSGTR_SubSourceStatus "Sub source: %s" ++#define MSGTR_SubPosStatus "Sub position: %s/100" ++#define MSGTR_SubAlignStatus "Sub alignment: %s" ++#define MSGTR_SubDelayStatus "Sub delay: %s" ++#define MSGTR_SubScale "Sub Scale: %s" ++#define MSGTR_SubVisibleStatus "Subtitles: %s" ++#define MSGTR_SubForcedOnlyStatus "Forced sub only: %s" ++ ++// mencoder.c ++#define MSGTR_UsingPass3ControlFile "Using pass3 control file: %s\n" ++#define MSGTR_MissingFilename "\nFilename missing.\n\n" ++#define MSGTR_CannotOpenFile_Device "Cannot open file/device.\n" ++#define MSGTR_CannotOpenDemuxer "Cannot open demuxer.\n" ++#define MSGTR_NoAudioEncoderSelected "\nNo audio encoder (-oac) selected. Select one (see -oac help) or use -nosound.\n" ++#define MSGTR_NoVideoEncoderSelected "\nNo video encoder (-ovc) selected. Select one (see -ovc help).\n" ++#define MSGTR_CannotOpenOutputFile "Cannot open output file '%s'.\n" ++#define MSGTR_EncoderOpenFailed "Failed to open the encoder.\n" ++#define MSGTR_MencoderWrongFormatAVI "\nWARNING: OUTPUT FILE FORMAT IS _AVI_. See -of help.\n" ++#define MSGTR_MencoderWrongFormatMPG "\nWARNING: OUTPUT FILE FORMAT IS _MPEG_. See -of help.\n" ++#define MSGTR_MissingOutputFilename "No output file specified, please see the -o option." ++#define MSGTR_ForcingOutputFourcc "Forcing output FourCC to %x [%.4s].\n" ++#define MSGTR_ForcingOutputAudiofmtTag "Forcing output audio format tag to 0x%x.\n" ++#define MSGTR_DuplicateFrames "\n%d duplicate frame(s)!\n" ++#define MSGTR_SkipFrame "\nSkipping frame!\n" ++#define MSGTR_ResolutionDoesntMatch "\nNew video file has different resolution or colorspace than the previous one.\n" ++#define MSGTR_FrameCopyFileMismatch "\nAll video files must have identical fps, resolution, and codec for -ovc copy.\n" ++#define MSGTR_AudioCopyFileMismatch "\nAll files must have identical audio codec and format for -oac copy.\n" ++#define MSGTR_NoAudioFileMismatch "\nCannot mix video-only files with audio and video files. Try -nosound.\n" ++#define MSGTR_NoSpeedWithFrameCopy "WARNING: -speed is not guaranteed to work correctly with -oac copy!\n"\ ++"Your encode might be broken!\n" ++#define MSGTR_ErrorWritingFile "%s: Error writing file.\n" ++#define MSGTR_FlushingVideoFrames "\nFlushing video frames.\n" ++#define MSGTR_FiltersHaveNotBeenConfiguredEmptyFile "Filters have not been configured! Empty file?\n" ++#define MSGTR_RecommendedVideoBitrate "Recommended video bitrate for %s CD: %d\n" ++#define MSGTR_VideoStreamResult "\nVideo stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs %d frames\n" ++#define MSGTR_AudioStreamResult "\nAudio stream: %8.3f kbit/s (%d B/s) size: %"PRIu64" bytes %5.3f secs\n" ++#define MSGTR_EdlSkipStartEndCurrent "EDL SKIP: Start: %.2f End: %.2f Current: V: %.2f A: %.2f \r" ++#define MSGTR_OpenedStream "success: format: %d data: 0x%X - 0x%x\n" ++#define MSGTR_VCodecFramecopy "videocodec: framecopy (%dx%d %dbpp fourcc=%x)\n" ++#define MSGTR_ACodecFramecopy "audiocodec: framecopy (format=%x chans=%d rate=%d bits=%d B/s=%d sample-%d)\n" ++#define MSGTR_CBRPCMAudioSelected "CBR PCM audio selected.\n" ++#define MSGTR_MP3AudioSelected "MP3 audio selected.\n" ++#define MSGTR_CannotAllocateBytes "Couldn't allocate %d bytes.\n" ++#define MSGTR_SettingAudioDelay "Setting audio delay to %5.3fs.\n" ++#define MSGTR_SettingVideoDelay "Setting video delay to %5.3fs.\n" ++#define MSGTR_SettingAudioInputGain "Setting audio input gain to %f.\n" ++#define MSGTR_LamePresetEquals "\npreset=%s\n\n" ++#define MSGTR_LimitingAudioPreload "Limiting audio preload to 0.4s.\n" ++#define MSGTR_IncreasingAudioDensity "Increasing audio density to 4.\n" ++#define MSGTR_ZeroingAudioPreloadAndMaxPtsCorrection "Forcing audio preload to 0, max pts correction to 0.\n" ++#define MSGTR_CBRAudioByterate "\n\nCBR audio: %d bytes/sec, %d bytes/block\n" ++#define MSGTR_LameVersion "LAME version %s (%s)\n\n" ++#define MSGTR_InvalidBitrateForLamePreset "Error: The bitrate specified is out of the valid range for this preset.\n"\ ++"\n"\ ++"When using this mode you must enter a value between \"8\" and \"320\".\n"\ ++"\n"\ ++"For further information try: \"-lameopts preset=help\"\n" ++#define MSGTR_InvalidLamePresetOptions "Error: You did not enter a valid profile and/or options with preset.\n"\ ++"\n"\ ++"Available profiles are:\n"\ ++"\n"\ ++" standard\n"\ ++" extreme\n"\ ++" insane\n"\ ++" (ABR Mode) - The ABR Mode is implied. To use it,\n"\ ++" simply specify a bitrate. For example:\n"\ ++" \"preset=185\" activates this\n"\ ++" preset and uses 185 as an average kbps.\n"\ ++"\n"\ ++" Some examples:\n"\ ++"\n"\ ++" \"-lameopts fast:preset=standard \"\n"\ ++" or \"-lameopts cbr:preset=192 \"\n"\ ++" or \"-lameopts preset=172 \"\n"\ ++" or \"-lameopts preset=extreme \"\n"\ ++"\n"\ ++"For further information try: \"-lameopts preset=help\"\n" ++#define MSGTR_LamePresetsLongInfo "\n"\ ++"The preset switches are designed to provide the highest possible quality.\n"\ ++"\n"\ ++"They have for the most part been subjected to and tuned via rigorous double\n"\ ++"blind listening tests to verify and achieve this objective.\n"\ ++"\n"\ ++"These are continually updated to coincide with the latest developments that\n"\ ++"occur and as a result should provide you with nearly the best quality\n"\ ++"currently possible from LAME.\n"\ ++"\n"\ ++"To activate these presets:\n"\ ++"\n"\ ++" For VBR modes (generally highest quality):\n"\ ++"\n"\ ++" \"preset=standard\" This preset should generally be transparent\n"\ ++" to most people on most music and is already\n"\ ++" quite high in quality.\n"\ ++"\n"\ ++" \"preset=extreme\" If you have extremely good hearing and similar\n"\ ++" equipment, this preset will generally provide\n"\ ++" slightly higher quality than the \"standard\"\n"\ ++" mode.\n"\ ++"\n"\ ++" For CBR 320kbps (highest quality possible from the preset switches):\n"\ ++"\n"\ ++" \"preset=insane\" This preset will usually be overkill for most\n"\ ++" people and most situations, but if you must\n"\ ++" have the absolute highest quality with no\n"\ ++" regard to filesize, this is the way to go.\n"\ ++"\n"\ ++" For ABR modes (high quality per given bitrate but not as high as VBR):\n"\ ++"\n"\ ++" \"preset=\" Using this preset will usually give you good\n"\ ++" quality at a specified bitrate. Depending on the\n"\ ++" bitrate entered, this preset will determine the\n"\ ++" optimal settings for that particular situation.\n"\ ++" While this approach works, it is not nearly as\n"\ ++" flexible as VBR, and usually will not attain the\n"\ ++" same level of quality as VBR at higher bitrates.\n"\ ++"\n"\ ++"The following options are also available for the corresponding profiles:\n"\ ++"\n"\ ++" standard\n"\ ++" extreme\n"\ ++" insane\n"\ ++" (ABR Mode) - The ABR Mode is implied. To use it,\n"\ ++" simply specify a bitrate. For example:\n"\ ++" \"preset=185\" activates this\n"\ ++" preset and uses 185 as an average kbps.\n"\ ++"\n"\ ++" \"fast\" - Enables the new fast VBR for a particular profile. The\n"\ ++" disadvantage to the speed switch is that often times the\n"\ ++" bitrate will be slightly higher than with the normal mode\n"\ ++" and quality may be slightly lower also.\n"\ ++" Warning: with the current version fast presets might result in too\n"\ ++" high bitrate compared to regular presets.\n"\ ++"\n"\ ++" \"cbr\" - If you use the ABR mode (read above) with a significant\n"\ ++" bitrate such as 80, 96, 112, 128, 160, 192, 224, 256, 320,\n"\ ++" you can use the \"cbr\" option to force CBR mode encoding\n"\ ++" instead of the standard abr mode. ABR does provide higher\n"\ ++" quality but CBR may be useful in situations such as when\n"\ ++" streaming an MP3 over the internet may be important.\n"\ ++"\n"\ ++" For example:\n"\ ++"\n"\ ++" \"-lameopts fast:preset=standard \"\n"\ ++" or \"-lameopts cbr:preset=192 \"\n"\ ++" or \"-lameopts preset=172 \"\n"\ ++" or \"-lameopts preset=extreme \"\n"\ ++"\n"\ ++"\n"\ ++"A few aliases are available for ABR mode:\n"\ ++"phone => 16kbps/mono phon+/lw/mw-eu/sw => 24kbps/mono\n"\ ++"mw-us => 40kbps/mono voice => 56kbps/mono\n"\ ++"fm/radio/tape => 112kbps hifi => 160kbps\n"\ ++"cd => 192kbps studio => 256kbps" ++#define MSGTR_LameCantInit \ ++"Cannot set LAME options, check bitrate/samplerate, some very low bitrates\n"\ ++"(<32) need lower samplerates (i.e. -srate 8000).\n"\ ++"If everything else fails, try a preset." ++#define MSGTR_ConfigFileError "config file error" ++#define MSGTR_ErrorParsingCommandLine "error parsing command line" ++#define MSGTR_VideoStreamRequired "Video stream is mandatory!\n" ++#define MSGTR_ForcingInputFPS "Input fps will be interpreted as %5.3f instead.\n" ++#define MSGTR_RawvideoDoesNotSupportAudio "Output file format RAWVIDEO does not support audio - disabling audio.\n" ++#define MSGTR_DemuxerDoesntSupportNosound "This demuxer doesn't support -nosound yet.\n" ++#define MSGTR_MemAllocFailed "Memory allocation failed.\n" ++#define MSGTR_NoMatchingFilter "Couldn't find matching filter/ao format!\n" ++#define MSGTR_MP3WaveFormatSizeNot30 "sizeof(MPEGLAYER3WAVEFORMAT)==%d!=30, maybe broken C compiler?\n" ++#define MSGTR_NoLavcAudioCodecName "Audio LAVC, Missing codec name!\n" ++#define MSGTR_LavcAudioCodecNotFound "Audio LAVC, couldn't find encoder for codec %s.\n" ++#define MSGTR_CouldntAllocateLavcContext "Audio LAVC, couldn't allocate context!\n" ++#define MSGTR_CouldntOpenCodec "Couldn't open codec %s, br=%d.\n" ++#define MSGTR_CantCopyAudioFormat "Audio format 0x%x is incompatible with '-oac copy', please try '-oac pcm' instead or use '-fafmttag' to override it.\n" ++ ++// cfg-mencoder.h ++#define MSGTR_MEncoderMP3LameHelp "\n\n"\ ++" vbr=<0-4> variable bitrate method\n"\ ++" 0: cbr (constant bitrate)\n"\ ++" 1: mt (Mark Taylor VBR algorithm)\n"\ ++" 2: rh (Robert Hegemann VBR algorithm - default)\n"\ ++" 3: abr (average bitrate)\n"\ ++" 4: mtrh (Mark Taylor Robert Hegemann VBR algorithm)\n"\ ++"\n"\ ++" abr average bitrate\n"\ ++"\n"\ ++" cbr constant bitrate\n"\ ++" Also forces CBR mode encoding on subsequent ABR presets modes.\n"\ ++"\n"\ ++" br=<0-1024> specify bitrate in kBit (CBR and ABR only)\n"\ ++"\n"\ ++" q=<0-9> quality (0-highest, 9-lowest) (only for VBR)\n"\ ++"\n"\ ++" aq=<0-9> algorithmic quality (0-best/slowest, 9-worst/fastest)\n"\ ++"\n"\ ++" ratio=<1-100> compression ratio\n"\ ++"\n"\ ++" vol=<0-10> set audio input gain\n"\ ++"\n"\ ++" mode=<0-3> (default: auto)\n"\ ++" 0: stereo\n"\ ++" 1: joint-stereo\n"\ ++" 2: dualchannel\n"\ ++" 3: mono\n"\ ++"\n"\ ++" padding=<0-2>\n"\ ++" 0: no\n"\ ++" 1: all\n"\ ++" 2: adjust\n"\ ++"\n"\ ++" fast Switch on faster encoding on subsequent VBR presets modes,\n"\ ++" slightly lower quality and higher bitrates.\n"\ ++"\n"\ ++" preset= Provide the highest possible quality settings.\n"\ ++" medium: VBR encoding, good quality\n"\ ++" (150-180 kbps bitrate range)\n"\ ++" standard: VBR encoding, high quality\n"\ ++" (170-210 kbps bitrate range)\n"\ ++" extreme: VBR encoding, very high quality\n"\ ++" (200-240 kbps bitrate range)\n"\ ++" insane: CBR encoding, highest preset quality\n"\ ++" (320 kbps bitrate)\n"\ ++" <8-320>: ABR encoding at average given kbps bitrate.\n\n" ++ ++// codec-cfg.c ++#define MSGTR_DuplicateFourcc "duplicated FourCC" ++#define MSGTR_TooManyFourccs "too many FourCCs/formats..." ++#define MSGTR_ParseError "parse error" ++#define MSGTR_ParseErrorFIDNotNumber "parse error (format ID not a number?)" ++#define MSGTR_ParseErrorFIDAliasNotNumber "parse error (format ID alias not a number?)" ++#define MSGTR_DuplicateFID "duplicated format ID" ++#define MSGTR_TooManyOut "too many out..." ++#define MSGTR_InvalidCodecName "\ncodec(%s) name is not valid!\n" ++#define MSGTR_CodecLacksFourcc "\ncodec(%s) does not have FourCC/format!\n" ++#define MSGTR_CodecLacksDriver "\ncodec(%s) does not have a driver!\n" ++#define MSGTR_CodecNeedsDLL "\ncodec(%s) needs a 'dll'!\n" ++#define MSGTR_CodecNeedsOutfmt "\ncodec(%s) needs an 'outfmt'!\n" ++#define MSGTR_CantAllocateComment "Can't allocate memory for comment. " ++#define MSGTR_GetTokenMaxNotLessThanMAX_NR_TOKEN "get_token(): max >= MAX_MR_TOKEN!" ++#define MSGTR_ReadingFile "Reading %s: " ++#define MSGTR_CantOpenFileError "Can't open '%s': %s\n" ++#define MSGTR_CantGetMemoryForLine "Can't get memory for 'line': %s\n" ++#define MSGTR_CantReallocCodecsp "Can't realloc '*codecsp': %s\n" ++#define MSGTR_CodecNameNotUnique "Codec name '%s' isn't unique." ++#define MSGTR_CantStrdupName "Can't strdup -> 'name': %s\n" ++#define MSGTR_CantStrdupInfo "Can't strdup -> 'info': %s\n" ++#define MSGTR_CantStrdupDriver "Can't strdup -> 'driver': %s\n" ++#define MSGTR_CantStrdupDLL "Can't strdup -> 'dll': %s" ++#define MSGTR_AudioVideoCodecTotals "%d audio & %d video codecs\n" ++#define MSGTR_CodecDefinitionIncorrect "Codec is not defined correctly." ++#define MSGTR_OutdatedCodecsConf "This codecs.conf is too old and incompatible with this MPlayer release!" ++ ++// fifo.c ++#define MSGTR_CannotMakePipe "Cannot make PIPE!\n" ++ ++// parser-mecmd.c, parser-mpcmd.c ++#define MSGTR_NoFileGivenOnCommandLine "'--' indicates no more options, but no filename was given on the command line.\n" ++#define MSGTR_TheLoopOptionMustBeAnInteger "The loop option must be an integer: %s\n" ++#define MSGTR_UnknownOptionOnCommandLine "Unknown option on the command line: -%s\n" ++#define MSGTR_ErrorParsingOptionOnCommandLine "Error parsing option on the command line: -%s\n" ++#define MSGTR_InvalidPlayEntry "Invalid play entry %s\n" ++#define MSGTR_NotAnMEncoderOption "-%s is not an MEncoder option\n" ++#define MSGTR_NoFileGiven "No file given\n" ++ ++// m_config.c ++#define MSGTR_SaveSlotTooOld "Save slot found from lvl %d is too old: %d !!!\n" ++#define MSGTR_InvalidCfgfileOption "The %s option can't be used in a config file.\n" ++#define MSGTR_InvalidCmdlineOption "The %s option can't be used on the command line.\n" ++#define MSGTR_InvalidSuboption "Error: option '%s' has no suboption '%s'.\n" ++#define MSGTR_MissingSuboptionParameter "Error: suboption '%s' of '%s' must have a parameter!\n" ++#define MSGTR_MissingOptionParameter "Error: option '%s' must have a parameter!\n" ++#define MSGTR_OptionListHeader "\n Name Type Min Max Global CL Cfg\n\n" ++#define MSGTR_TotalOptions "\nTotal: %d options\n" ++#define MSGTR_ProfileInclusionTooDeep "WARNING: Profile inclusion too deep.\n" ++#define MSGTR_NoProfileDefined "No profiles have been defined.\n" ++#define MSGTR_AvailableProfiles "Available profiles:\n" ++#define MSGTR_UnknownProfile "Unknown profile '%s'.\n" ++#define MSGTR_Profile "Profile %s: %s\n" ++ ++// m_property.c ++#define MSGTR_PropertyListHeader "\n Name Type Min Max\n\n" ++#define MSGTR_TotalProperties "\nTotal: %d properties\n" ++ ++// loader/ldt_keeper.c ++#define MSGTR_LOADER_DYLD_Warning "WARNING: Attempting to use DLL codecs but environment variable\n DYLD_BIND_AT_LAUNCH not set. This will likely crash.\n" ++ ++ ++// ====================== GUI messages/buttons ======================== ++ ++// --- labels --- ++#define MSGTR_About "About" ++#define MSGTR_FileSelect "Select file..." ++#define MSGTR_SubtitleSelect "Select subtitle..." ++#define MSGTR_OtherSelect "Select..." ++#define MSGTR_AudioFileSelect "Select external audio channel..." ++#define MSGTR_FontSelect "Select font..." ++// Note: If you change MSGTR_PlayList please see if it still fits MSGTR_MENU_PlayList ++#define MSGTR_PlayList "Playlist" ++#define MSGTR_Equalizer "Equalizer" ++#define MSGTR_ConfigureEqualizer "Configure Equalizer" ++#define MSGTR_SkinBrowser "Skin Browser" ++#define MSGTR_Network "Network streaming..." ++// Note: If you change MSGTR_Preferences please see if it still fits MSGTR_MENU_Preferences ++#define MSGTR_Preferences "Preferences" ++#define MSGTR_AudioPreferences "Audio driver configuration" ++#define MSGTR_NoMediaOpened "No media opened." ++#define MSGTR_VCDTrack "VCD track %d" ++#define MSGTR_NoChapter "No chapter" ++#define MSGTR_Chapter "Chapter %d" ++#define MSGTR_NoFileLoaded "No file loaded." ++ ++// --- buttons --- ++#define MSGTR_Ok "OK" ++#define MSGTR_Cancel "Cancel" ++#define MSGTR_Add "Add" ++#define MSGTR_Remove "Remove" ++#define MSGTR_Clear "Clear" ++#define MSGTR_Config "Config" ++#define MSGTR_ConfigDriver "Configure driver" ++#define MSGTR_Browse "Browse" ++ ++// --- error messages --- ++#define MSGTR_NEMDB "Sorry, not enough memory to draw buffer." ++#define MSGTR_NEMFMR "Sorry, not enough memory for menu rendering." ++#define MSGTR_IDFGCVD "Sorry, I did not find a GUI-compatible video output driver." ++#define MSGTR_NEEDLAVC "Sorry, you cannot play non-MPEG files with your DXR3/H+ device without reencoding.\nPlease enable lavc in the DXR3/H+ configuration box." ++#define MSGTR_UNKNOWNWINDOWTYPE "Unknown window type found ..." ++ ++// --- skin loader error messages ++#define MSGTR_SKIN_ERRORMESSAGE "[skin] error in skin config file on line %d: %s" ++#define MSGTR_SKIN_WARNING1 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"section\" found before" ++#define MSGTR_SKIN_WARNING2 "[skin] warning: in config file line %d:\nwidget (%s) found but no \"subsection\" found before" ++#define MSGTR_SKIN_WARNING3 "[skin] warning: in config file line %d:\nthis subsection is not supported by widget (%s)" ++#define MSGTR_SKIN_SkinFileNotFound "[skin] file ( %s ) not found.\n" ++#define MSGTR_SKIN_SkinFileNotReadable "[skin] file ( %s ) not readable.\n" ++#define MSGTR_SKIN_BITMAP_16bit "Bitmaps of 16 bits or less depth not supported (%s).\n" ++#define MSGTR_SKIN_BITMAP_FileNotFound "File not found (%s)\n" ++#define MSGTR_SKIN_BITMAP_BMPReadError "BMP read error (%s)\n" ++#define MSGTR_SKIN_BITMAP_TGAReadError "TGA read error (%s)\n" ++#define MSGTR_SKIN_BITMAP_PNGReadError "PNG read error (%s)\n" ++#define MSGTR_SKIN_BITMAP_RLENotSupported "RLE packed TGA not supported (%s)\n" ++#define MSGTR_SKIN_BITMAP_UnknownFileType "unknown file type (%s)\n" ++#define MSGTR_SKIN_BITMAP_ConversionError "24 bit to 32 bit conversion error (%s)\n" ++#define MSGTR_SKIN_BITMAP_UnknownMessage "unknown message: %s\n" ++#define MSGTR_SKIN_FONT_NotEnoughtMemory "not enough memory\n" ++#define MSGTR_SKIN_FONT_TooManyFontsDeclared "Too many fonts declared.\n" ++#define MSGTR_SKIN_FONT_FontFileNotFound "Font file not found.\n" ++#define MSGTR_SKIN_FONT_FontImageNotFound "Font image file not found.\n" ++#define MSGTR_SKIN_FONT_NonExistentFontID "non-existent font identifier (%s)\n" ++#define MSGTR_SKIN_UnknownParameter "unknown parameter (%s)\n" ++#define MSGTR_SKIN_SKINCFG_SkinNotFound "Skin not found (%s).\n" ++#define MSGTR_SKIN_SKINCFG_SelectedSkinNotFound "Selected skin ( %s ) not found, trying 'default'...\n" ++#define MSGTR_SKIN_SKINCFG_SkinCfgReadError "skin config file read error (%s)\n" ++#define MSGTR_SKIN_LABEL "Skins:" ++ ++// --- GTK menus ++#define MSGTR_MENU_AboutMPlayer "About MPlayer" ++#define MSGTR_MENU_Open "Open..." ++#define MSGTR_MENU_PlayFile "Play file..." ++#define MSGTR_MENU_PlayVCD "Play VCD..." ++#define MSGTR_MENU_PlayDVD "Play DVD..." ++#define MSGTR_MENU_PlayURL "Play URL..." ++#define MSGTR_MENU_LoadSubtitle "Load subtitle..." ++#define MSGTR_MENU_DropSubtitle "Drop subtitle..." ++#define MSGTR_MENU_LoadExternAudioFile "Load external audio file..." ++#define MSGTR_MENU_Playing "Playing" ++#define MSGTR_MENU_Play "Play" ++#define MSGTR_MENU_Pause "Pause" ++#define MSGTR_MENU_Stop "Stop" ++#define MSGTR_MENU_NextStream "Next stream" ++#define MSGTR_MENU_PrevStream "Prev stream" ++#define MSGTR_MENU_Size "Size" ++#define MSGTR_MENU_HalfSize "Half size" ++#define MSGTR_MENU_NormalSize "Normal size" ++#define MSGTR_MENU_DoubleSize "Double size" ++#define MSGTR_MENU_FullScreen "Fullscreen" ++#define MSGTR_MENU_DVD "DVD" ++#define MSGTR_MENU_VCD "VCD" ++#define MSGTR_MENU_PlayDisc "Open disc..." ++#define MSGTR_MENU_ShowDVDMenu "Show DVD menu" ++#define MSGTR_MENU_Titles "Titles" ++#define MSGTR_MENU_Title "Title %2d" ++#define MSGTR_MENU_None "(none)" ++#define MSGTR_MENU_Chapters "Chapters" ++#define MSGTR_MENU_Chapter "Chapter %2d" ++#define MSGTR_MENU_AudioLanguages "Audio languages" ++#define MSGTR_MENU_SubtitleLanguages "Subtitle languages" ++#define MSGTR_MENU_PlayList MSGTR_PlayList ++#define MSGTR_MENU_SkinBrowser "Skin browser" ++#define MSGTR_MENU_Preferences MSGTR_Preferences ++#define MSGTR_MENU_Exit "Exit..." ++#define MSGTR_MENU_Mute "Mute" ++#define MSGTR_MENU_Original "Original" ++#define MSGTR_MENU_AspectRatio "Aspect ratio" ++#define MSGTR_MENU_AudioTrack "Audio track" ++#define MSGTR_MENU_Track "Track %d" ++#define MSGTR_MENU_VideoTrack "Video track" ++#define MSGTR_MENU_Subtitles "Subtitles" ++ ++// --- equalizer ++// Note: If you change MSGTR_EQU_Audio please see if it still fits MSGTR_PREFERENCES_Audio ++#define MSGTR_EQU_Audio "Audio" ++// Note: If you change MSGTR_EQU_Video please see if it still fits MSGTR_PREFERENCES_Video ++#define MSGTR_EQU_Video "Video" ++#define MSGTR_EQU_Contrast "Contrast: " ++#define MSGTR_EQU_Brightness "Brightness: " ++#define MSGTR_EQU_Hue "Hue: " ++#define MSGTR_EQU_Saturation "Saturation: " ++#define MSGTR_EQU_Front_Left "Front Left" ++#define MSGTR_EQU_Front_Right "Front Right" ++#define MSGTR_EQU_Back_Left "Rear Left" ++#define MSGTR_EQU_Back_Right "Rear Right" ++#define MSGTR_EQU_Center "Center" ++#define MSGTR_EQU_Bass "Bass" ++#define MSGTR_EQU_All "All" ++#define MSGTR_EQU_Channel1 "Channel 1:" ++#define MSGTR_EQU_Channel2 "Channel 2:" ++#define MSGTR_EQU_Channel3 "Channel 3:" ++#define MSGTR_EQU_Channel4 "Channel 4:" ++#define MSGTR_EQU_Channel5 "Channel 5:" ++#define MSGTR_EQU_Channel6 "Channel 6:" ++ ++// --- playlist ++#define MSGTR_PLAYLIST_Path "Path" ++#define MSGTR_PLAYLIST_Selected "Selected files" ++#define MSGTR_PLAYLIST_Files "Files" ++#define MSGTR_PLAYLIST_DirectoryTree "Directory tree" ++ ++// --- preferences ++#define MSGTR_PREFERENCES_Audio MSGTR_EQU_Audio ++#define MSGTR_PREFERENCES_Video MSGTR_EQU_Video ++#define MSGTR_PREFERENCES_SubtitleOSD "Subtitles & OSD" ++#define MSGTR_PREFERENCES_Codecs "Codecs & demuxer" ++// Note: If you change MSGTR_PREFERENCES_Misc see if it still fits MSGTR_PREFERENCES_FRAME_Misc ++#define MSGTR_PREFERENCES_Misc "Misc" ++#define MSGTR_PREFERENCES_None "None" ++#define MSGTR_PREFERENCES_DriverDefault "driver default" ++#define MSGTR_PREFERENCES_AvailableDrivers "Available drivers:" ++#define MSGTR_PREFERENCES_DoNotPlaySound "Do not play sound" ++#define MSGTR_PREFERENCES_NormalizeSound "Normalize sound" ++#define MSGTR_PREFERENCES_EnableEqualizer "Enable equalizer" ++#define MSGTR_PREFERENCES_SoftwareMixer "Enable Software Mixer" ++#define MSGTR_PREFERENCES_ExtraStereo "Enable extra stereo" ++#define MSGTR_PREFERENCES_Coefficient "Coefficient:" ++#define MSGTR_PREFERENCES_AudioDelay "Audio delay" ++#define MSGTR_PREFERENCES_DoubleBuffer "Enable double buffering" ++#define MSGTR_PREFERENCES_DirectRender "Enable direct rendering" ++#define MSGTR_PREFERENCES_FrameDrop "Enable frame dropping" ++#define MSGTR_PREFERENCES_HFrameDrop "Enable HARD frame dropping (dangerous)" ++#define MSGTR_PREFERENCES_Flip "Flip image upside down" ++#define MSGTR_PREFERENCES_Panscan "Panscan: " ++#define MSGTR_PREFERENCES_OSDTimer "Timer and indicators" ++#define MSGTR_PREFERENCES_OSDProgress "Progressbars only" ++#define MSGTR_PREFERENCES_OSDTimerPercentageTotalTime "Timer, percentage and total time" ++#define MSGTR_PREFERENCES_Subtitle "Subtitle:" ++#define MSGTR_PREFERENCES_SUB_Delay "Delay: " ++#define MSGTR_PREFERENCES_SUB_FPS "FPS:" ++#define MSGTR_PREFERENCES_SUB_POS "Position: " ++#define MSGTR_PREFERENCES_SUB_AutoLoad "Disable subtitle autoloading" ++#define MSGTR_PREFERENCES_SUB_Unicode "Unicode subtitle" ++#define MSGTR_PREFERENCES_SUB_MPSUB "Convert the given subtitle to MPlayer's subtitle format" ++#define MSGTR_PREFERENCES_SUB_SRT "Convert the given subtitle to the time based SubViewer (SRT) format" ++#define MSGTR_PREFERENCES_SUB_Overlap "Toggle subtitle overlapping" ++#define MSGTR_PREFERENCES_SUB_USE_ASS "SSA/ASS subtitle rendering" ++#define MSGTR_PREFERENCES_SUB_ASS_USE_MARGINS "Use margins" ++#define MSGTR_PREFERENCES_SUB_ASS_TOP_MARGIN "Top: " ++#define MSGTR_PREFERENCES_SUB_ASS_BOTTOM_MARGIN "Bottom: " ++#define MSGTR_PREFERENCES_Font "Font:" ++#define MSGTR_PREFERENCES_FontFactor "Font factor:" ++#define MSGTR_PREFERENCES_PostProcess "Enable postprocessing" ++#define MSGTR_PREFERENCES_AutoQuality "Auto quality: " ++#define MSGTR_PREFERENCES_NI "Use non-interleaved AVI parser" ++#define MSGTR_PREFERENCES_IDX "Rebuild index table, if needed" ++#define MSGTR_PREFERENCES_VideoCodecFamily "Video codec family:" ++#define MSGTR_PREFERENCES_AudioCodecFamily "Audio codec family:" ++#define MSGTR_PREFERENCES_FRAME_OSD_Level "OSD level" ++#define MSGTR_PREFERENCES_FRAME_Subtitle "Subtitle" ++#define MSGTR_PREFERENCES_FRAME_Font "Font" ++#define MSGTR_PREFERENCES_FRAME_PostProcess "Postprocessing" ++#define MSGTR_PREFERENCES_FRAME_CodecDemuxer "Codec & demuxer" ++#define MSGTR_PREFERENCES_FRAME_Cache "Cache" ++#define MSGTR_PREFERENCES_FRAME_Misc MSGTR_PREFERENCES_Misc ++#define MSGTR_PREFERENCES_Audio_Device "Device:" ++#define MSGTR_PREFERENCES_Audio_Mixer "Mixer:" ++#define MSGTR_PREFERENCES_Audio_MixerChannel "Mixer channel:" ++#define MSGTR_PREFERENCES_Message "Please remember that you need to restart playback for some options to take effect!" ++#define MSGTR_PREFERENCES_DXR3_VENC "Video encoder:" ++#define MSGTR_PREFERENCES_DXR3_LAVC "Use LAVC (FFmpeg)" ++#define MSGTR_PREFERENCES_FontEncoding1 "Unicode" ++#define MSGTR_PREFERENCES_FontEncoding2 "Western European Languages (ISO-8859-1)" ++#define MSGTR_PREFERENCES_FontEncoding3 "Western European Languages with Euro (ISO-8859-15)" ++#define MSGTR_PREFERENCES_FontEncoding4 "Slavic/Central European Languages (ISO-8859-2)" ++#define MSGTR_PREFERENCES_FontEncoding5 "Esperanto, Galician, Maltese, Turkish (ISO-8859-3)" ++#define MSGTR_PREFERENCES_FontEncoding6 "Old Baltic charset (ISO-8859-4)" ++#define MSGTR_PREFERENCES_FontEncoding7 "Cyrillic (ISO-8859-5)" ++#define MSGTR_PREFERENCES_FontEncoding8 "Arabic (ISO-8859-6)" ++#define MSGTR_PREFERENCES_FontEncoding9 "Modern Greek (ISO-8859-7)" ++#define MSGTR_PREFERENCES_FontEncoding10 "Turkish (ISO-8859-9)" ++#define MSGTR_PREFERENCES_FontEncoding11 "Baltic (ISO-8859-13)" ++#define MSGTR_PREFERENCES_FontEncoding12 "Celtic (ISO-8859-14)" ++#define MSGTR_PREFERENCES_FontEncoding13 "Hebrew charsets (ISO-8859-8)" ++#define MSGTR_PREFERENCES_FontEncoding14 "Russian (KOI8-R)" ++#define MSGTR_PREFERENCES_FontEncoding15 "Ukrainian, Belarusian (KOI8-U/RU)" ++#define MSGTR_PREFERENCES_FontEncoding16 "Simplified Chinese charset (CP936)" ++#define MSGTR_PREFERENCES_FontEncoding17 "Traditional Chinese charset (BIG5)" ++#define MSGTR_PREFERENCES_FontEncoding18 "Japanese charsets (SHIFT-JIS)" ++#define MSGTR_PREFERENCES_FontEncoding19 "Korean charset (CP949)" ++#define MSGTR_PREFERENCES_FontEncoding20 "Thai charset (CP874)" ++#define MSGTR_PREFERENCES_FontEncoding21 "Cyrillic Windows (CP1251)" ++#define MSGTR_PREFERENCES_FontEncoding22 "Slavic/Central European Windows (CP1250)" ++#define MSGTR_PREFERENCES_FontEncoding23 "Arabic Windows (CP1256)" ++#define MSGTR_PREFERENCES_FontNoAutoScale "No autoscale" ++#define MSGTR_PREFERENCES_FontPropWidth "Proportional to movie width" ++#define MSGTR_PREFERENCES_FontPropHeight "Proportional to movie height" ++#define MSGTR_PREFERENCES_FontPropDiagonal "Proportional to movie diagonal" ++#define MSGTR_PREFERENCES_FontEncoding "Encoding:" ++#define MSGTR_PREFERENCES_FontBlur "Blur:" ++#define MSGTR_PREFERENCES_FontOutLine "Outline:" ++#define MSGTR_PREFERENCES_FontTextScale "Text scale:" ++#define MSGTR_PREFERENCES_FontOSDScale "OSD scale:" ++#define MSGTR_PREFERENCES_Cache "Cache on/off" ++#define MSGTR_PREFERENCES_CacheSize "Cache size: " ++#define MSGTR_PREFERENCES_LoadFullscreen "Start in fullscreen" ++#define MSGTR_PREFERENCES_SaveWinPos "Save window position" ++#define MSGTR_PREFERENCES_XSCREENSAVER "Stop XScreenSaver" ++#define MSGTR_PREFERENCES_PlayBar "Enable playbar" ++#define MSGTR_PREFERENCES_AutoSync "AutoSync on/off" ++#define MSGTR_PREFERENCES_AutoSyncValue "Autosync: " ++#define MSGTR_PREFERENCES_CDROMDevice "CD-ROM device:" ++#define MSGTR_PREFERENCES_DVDDevice "DVD device:" ++#define MSGTR_PREFERENCES_FPS "Movie FPS:" ++#define MSGTR_PREFERENCES_ShowVideoWindow "Show video window when inactive" ++#define MSGTR_PREFERENCES_ArtsBroken "Newer aRts versions are incompatible "\ ++ "with GTK 1.x and will crash GMPlayer!" ++ ++// -- aboutbox ++#define MSGTR_ABOUT_UHU "GUI development sponsored by UHU Linux\n" ++#define MSGTR_ABOUT_Contributors "Code and documentation contributors\n" ++#define MSGTR_ABOUT_Codecs_libs_contributions "Codecs and third party libraries\n" ++#define MSGTR_ABOUT_Translations "Translations\n" ++#define MSGTR_ABOUT_Skins "Skins\n" ++ ++// --- messagebox ++#define MSGTR_MSGBOX_LABEL_FatalError "Fatal error!" ++#define MSGTR_MSGBOX_LABEL_Error "Error!" ++#define MSGTR_MSGBOX_LABEL_Warning "Warning!" ++ ++// bitmap.c ++#define MSGTR_NotEnoughMemoryC32To1 "[c32to1] not enough memory for image\n" ++#define MSGTR_NotEnoughMemoryC1To32 "[c1to32] not enough memory for image\n" ++ ++// cfg.c ++#define MSGTR_ConfigFileReadError "[cfg] config file read error ...\n" ++#define MSGTR_UnableToSaveOption "[cfg] Unable to save the '%s' option.\n" ++ ++// interface.c ++#define MSGTR_DeletingSubtitles "[GUI] Deleting subtitles.\n" ++#define MSGTR_LoadingSubtitles "[GUI] Loading subtitles: %s\n" ++#define MSGTR_AddingVideoFilter "[GUI] Adding video filter: %s\n" ++#define MSGTR_RemovingVideoFilter "[GUI] Removing video filter: %s\n" ++ ++// mw.c ++#define MSGTR_NotAFile "This does not seem to be a file: %s !\n" ++ ++// ws.c ++#define MSGTR_WS_CouldNotOpenDisplay "[ws] Could not open the display.\n" ++#define MSGTR_WS_RemoteDisplay "[ws] Remote display, disabling XMITSHM.\n" ++#define MSGTR_WS_NoXshm "[ws] Sorry, your system does not support the X shared memory extension.\n" ++#define MSGTR_WS_NoXshape "[ws] Sorry, your system does not support the XShape extension.\n" ++#define MSGTR_WS_ColorDepthTooLow "[ws] Sorry, the color depth is too low.\n" ++#define MSGTR_WS_TooManyOpenWindows "[ws] There are too many open windows.\n" ++#define MSGTR_WS_ShmError "[ws] shared memory extension error\n" ++#define MSGTR_WS_NotEnoughMemoryDrawBuffer "[ws] Sorry, not enough memory to draw buffer.\n" ++#define MSGTR_WS_DpmsUnavailable "DPMS not available?\n" ++#define MSGTR_WS_DpmsNotEnabled "Could not enable DPMS.\n" ++ ++// wsxdnd.c ++#define MSGTR_WS_NotAFile "This does not seem to be a file...\n" ++#define MSGTR_WS_DDNothing "D&D: Nothing returned!\n" ++ ++// ======================= video output drivers ======================== ++ ++#define MSGTR_VOincompCodec "The selected video_out device is incompatible with this codec.\n"\ ++ "Try appending the scale filter to your filter list,\n"\ ++ "e.g. -vf spp,scale instead of -vf spp.\n" ++#define MSGTR_VO_GenericError "This error has occurred" ++#define MSGTR_VO_UnableToAccess "Unable to access" ++#define MSGTR_VO_ExistsButNoDirectory "already exists, but is not a directory." ++#define MSGTR_VO_DirExistsButNotWritable "Output directory already exists, but is not writable." ++#define MSGTR_VO_DirExistsAndIsWritable "Output directory already exists and is writable." ++#define MSGTR_VO_CantCreateDirectory "Unable to create output directory." ++#define MSGTR_VO_CantCreateFile "Unable to create output file." ++#define MSGTR_VO_DirectoryCreateSuccess "Output directory successfully created." ++#define MSGTR_VO_ValueOutOfRange "value out of range" ++#define MSGTR_VO_NoValueSpecified "No value specified." ++#define MSGTR_VO_UnknownSuboptions "unknown suboption(s)" ++ ++// aspect.c ++#define MSGTR_LIBVO_ASPECT_NoSuitableNewResFound "[ASPECT] Warning: No suitable new res found!\n" ++#define MSGTR_LIBVO_ASPECT_NoNewSizeFoundThatFitsIntoRes "[ASPECT] Error: No new size found that fits into res!\n" ++ ++// font_load_ft.c ++#define MSGTR_LIBVO_FONT_LOAD_FT_NewFaceFailed "New_Face failed. Maybe the font path is wrong.\nPlease supply the text font file (~/.mplayer/subfont.ttf).\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_NewMemoryFaceFailed "New_Memory_Face failed..\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_SubFaceFailed "subtitle font: load_sub_face failed.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_SubFontCharsetFailed "subtitle font: prepare_charset failed.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_CannotPrepareSubtitleFont "Cannot prepare subtitle font.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_CannotPrepareOSDFont "Cannot prepare OSD font.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_CannotGenerateTables "Cannot generate tables.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_DoneFreeTypeFailed "FT_Done_FreeType failed.\n" ++#define MSGTR_LIBVO_FONT_LOAD_FT_FontconfigNoMatch "Fontconfig failed to select a font. Trying without fontconfig...\n" ++ ++// sub.c ++#define MSGTR_VO_SUB_Seekbar "Seekbar" ++#define MSGTR_VO_SUB_Play "Play" ++#define MSGTR_VO_SUB_Pause "Pause" ++#define MSGTR_VO_SUB_Stop "Stop" ++#define MSGTR_VO_SUB_Rewind "Rewind" ++#define MSGTR_VO_SUB_Forward "Forward" ++#define MSGTR_VO_SUB_Clock "Clock" ++#define MSGTR_VO_SUB_Contrast "Contrast" ++#define MSGTR_VO_SUB_Saturation "Saturation" ++#define MSGTR_VO_SUB_Volume "Volume" ++#define MSGTR_VO_SUB_Brightness "Brightness" ++#define MSGTR_VO_SUB_Hue "Hue" ++#define MSGTR_VO_SUB_Balance "Balance" ++ ++// vo_3dfx.c ++#define MSGTR_LIBVO_3DFX_Only16BppSupported "[VO_3DFX] Only 16bpp supported!" ++#define MSGTR_LIBVO_3DFX_VisualIdIs "[VO_3DFX] Visual ID is %lx.\n" ++#define MSGTR_LIBVO_3DFX_UnableToOpenDevice "[VO_3DFX] Unable to open /dev/3dfx.\n" ++#define MSGTR_LIBVO_3DFX_Error "[VO_3DFX] Error: %d.\n" ++#define MSGTR_LIBVO_3DFX_CouldntMapMemoryArea "[VO_3DFX] Couldn't map 3dfx memory areas: %p,%p,%d.\n" ++#define MSGTR_LIBVO_3DFX_DisplayInitialized "[VO_3DFX] Initialized: %p.\n" ++#define MSGTR_LIBVO_3DFX_UnknownSubdevice "[VO_3DFX] Unknown subdevice: %s.\n" ++ ++// vo_aa.c ++#define MSGTR_VO_AA_HelpHeader "\n\nHere are the aalib vo_aa suboptions:\n" ++#define MSGTR_VO_AA_AdditionalOptions "Additional options vo_aa provides:\n" \ ++" help print this help message\n" \ ++" osdcolor set OSD color\n subcolor set subtitle color\n" \ ++" the color parameters are:\n 0 : normal\n" \ ++" 1 : dim\n 2 : bold\n 3 : boldfont\n" \ ++" 4 : reverse\n 5 : special\n\n\n" ++ ++// vo_dxr3.c ++#define MSGTR_LIBVO_DXR3_UnableToLoadNewSPUPalette "[VO_DXR3] Unable to load new SPU palette!\n" ++#define MSGTR_LIBVO_DXR3_UnableToSetPlaymode "[VO_DXR3] Unable to set playmode!\n" ++#define MSGTR_LIBVO_DXR3_UnableToSetSubpictureMode "[VO_DXR3] Unable to set subpicture mode!\n" ++#define MSGTR_LIBVO_DXR3_UnableToGetTVNorm "[VO_DXR3] Unable to get TV norm!\n" ++#define MSGTR_LIBVO_DXR3_AutoSelectedTVNormByFrameRate "[VO_DXR3] Auto-selected TV norm by framerate: " ++#define MSGTR_LIBVO_DXR3_UnableToSetTVNorm "[VO_DXR3] Unable to set TV norm!\n" ++#define MSGTR_LIBVO_DXR3_SettingUpForNTSC "[VO_DXR3] Setting up for NTSC.\n" ++#define MSGTR_LIBVO_DXR3_SettingUpForPALSECAM "[VO_DXR3] Setting up for PAL/SECAM.\n" ++#define MSGTR_LIBVO_DXR3_SettingAspectRatioTo43 "[VO_DXR3] Setting aspect ratio to 4:3.\n" ++#define MSGTR_LIBVO_DXR3_SettingAspectRatioTo169 "[VO_DXR3] Setting aspect ratio to 16:9.\n" ++#define MSGTR_LIBVO_DXR3_OutOfMemory "[VO_DXR3] out of memory\n" ++#define MSGTR_LIBVO_DXR3_UnableToAllocateKeycolor "[VO_DXR3] Unable to allocate keycolor!\n" ++#define MSGTR_LIBVO_DXR3_UnableToAllocateExactKeycolor "[VO_DXR3] Unable to allocate exact keycolor, using closest match (0x%lx).\n" ++#define MSGTR_LIBVO_DXR3_Uninitializing "[VO_DXR3] Uninitializing.\n" ++#define MSGTR_LIBVO_DXR3_FailedRestoringTVNorm "[VO_DXR3] Failed restoring TV norm!\n" ++#define MSGTR_LIBVO_DXR3_EnablingPrebuffering "[VO_DXR3] Enabling prebuffering.\n" ++#define MSGTR_LIBVO_DXR3_UsingNewSyncEngine "[VO_DXR3] Using new sync engine.\n" ++#define MSGTR_LIBVO_DXR3_UsingOverlay "[VO_DXR3] Using overlay.\n" ++#define MSGTR_LIBVO_DXR3_ErrorYouNeedToCompileMplayerWithX11 "[VO_DXR3] Error: Overlay requires compiling with X11 libs/headers installed.\n" ++#define MSGTR_LIBVO_DXR3_WillSetTVNormTo "[VO_DXR3] Will set TV norm to: " ++#define MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALPAL60 "auto-adjust to movie framerate (PAL/PAL-60)" ++#define MSGTR_LIBVO_DXR3_AutoAdjustToMovieFrameRatePALNTSC "auto-adjust to movie framerate (PAL/NTSC)" ++#define MSGTR_LIBVO_DXR3_UseCurrentNorm "Use current norm." ++#define MSGTR_LIBVO_DXR3_UseUnknownNormSuppliedCurrentNorm "Unknown norm supplied. Use current norm." ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTrying "[VO_DXR3] Error opening %s for writing, trying /dev/em8300 instead.\n" ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingMV "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_mv instead.\n" ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWell "[VO_DXR3] Error opening /dev/em8300 for writing as well!\nBailing out.\n" ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellMV "[VO_DXR3] Error opening /dev/em8300_mv for writing as well!\nBailing out.\n" ++#define MSGTR_LIBVO_DXR3_Opened "[VO_DXR3] Opened: %s.\n" ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingTryingSP "[VO_DXR3] Error opening %s for writing, trying /dev/em8300_sp instead.\n" ++#define MSGTR_LIBVO_DXR3_ErrorOpeningForWritingAsWellSP "[VO_DXR3] Error opening /dev/em8300_sp for writing as well!\nBailing out.\n" ++#define MSGTR_LIBVO_DXR3_UnableToOpenDisplayDuringHackSetup "[VO_DXR3] Unable to open display during overlay hack setup!\n" ++#define MSGTR_LIBVO_DXR3_UnableToInitX11 "[VO_DXR3] Unable to init X11!\n" ++#define MSGTR_LIBVO_DXR3_FailedSettingOverlayAttribute "[VO_DXR3] Failed setting overlay attribute.\n" ++#define MSGTR_LIBVO_DXR3_FailedSettingOverlayScreen "[VO_DXR3] Failed setting overlay screen!\nExiting.\n" ++#define MSGTR_LIBVO_DXR3_FailedEnablingOverlay "[VO_DXR3] Failed enabling overlay!\nExiting.\n" ++#define MSGTR_LIBVO_DXR3_FailedResizingOverlayWindow "[VO_DXR3] Failed resizing overlay window!\n" ++#define MSGTR_LIBVO_DXR3_FailedSettingOverlayBcs "[VO_DXR3] Failed setting overlay bcs!\n" ++#define MSGTR_LIBVO_DXR3_FailedGettingOverlayYOffsetValues "[VO_DXR3] Failed getting overlay Y-offset values!\nExiting.\n" ++#define MSGTR_LIBVO_DXR3_FailedGettingOverlayXOffsetValues "[VO_DXR3] Failed getting overlay X-offset values!\nExiting.\n" ++#define MSGTR_LIBVO_DXR3_FailedGettingOverlayXScaleCorrection "[VO_DXR3] Failed getting overlay X scale correction!\nExiting.\n" ++#define MSGTR_LIBVO_DXR3_YOffset "[VO_DXR3] Yoffset: %d.\n" ++#define MSGTR_LIBVO_DXR3_XOffset "[VO_DXR3] Xoffset: %d.\n" ++#define MSGTR_LIBVO_DXR3_XCorrection "[VO_DXR3] Xcorrection: %d.\n" ++#define MSGTR_LIBVO_DXR3_FailedSetSignalMix "[VO_DXR3] Failed to set signal mix!\n" ++ ++// vo_jpeg.c ++#define MSGTR_VO_JPEG_ProgressiveJPEG "Progressive JPEG enabled." ++#define MSGTR_VO_JPEG_NoProgressiveJPEG "Progressive JPEG disabled." ++#define MSGTR_VO_JPEG_BaselineJPEG "Baseline JPEG enabled." ++#define MSGTR_VO_JPEG_NoBaselineJPEG "Baseline JPEG disabled." ++ ++// vo_mga.c ++#define MSGTR_LIBVO_MGA_AspectResized "[VO_MGA] aspect(): resized to %dx%d.\n" ++#define MSGTR_LIBVO_MGA_Uninit "[VO] uninit!\n" ++ ++// mga_template.c ++#define MSGTR_LIBVO_MGA_ErrorInConfigIoctl "[MGA] error in mga_vid_config ioctl (wrong mga_vid.o version?)" ++#define MSGTR_LIBVO_MGA_CouldNotGetLumaValuesFromTheKernelModule "[MGA] Could not get luma values from the kernel module!\n" ++#define MSGTR_LIBVO_MGA_CouldNotSetLumaValuesFromTheKernelModule "[MGA] Could not set luma values from the kernel module!\n" ++#define MSGTR_LIBVO_MGA_ScreenWidthHeightUnknown "[MGA] Screen width/height unknown!\n" ++#define MSGTR_LIBVO_MGA_InvalidOutputFormat "[MGA] invalid output format %0X\n" ++#define MSGTR_LIBVO_MGA_IncompatibleDriverVersion "[MGA] Your mga_vid driver version is incompatible with this MPlayer version!\n" ++#define MSGTR_LIBVO_MGA_CouldntOpen "[MGA] Couldn't open: %s\n" ++#define MSGTR_LIBVO_MGA_ResolutionTooHigh "[MGA] Source resolution exceeds 1023x1023 in at least one dimension.\n[MGA] Rescale in software or use -lavdopts lowres=1.\n" ++#define MSGTR_LIBVO_MGA_mgavidVersionMismatch "[MGA] mismatch between kernel (%u) and MPlayer (%u) mga_vid driver versions\n" ++ ++// vo_null.c ++#define MSGTR_LIBVO_NULL_UnknownSubdevice "[VO_NULL] Unknown subdevice: %s.\n" ++ ++// vo_png.c ++#define MSGTR_LIBVO_PNG_Warning1 "[VO_PNG] Warning: compression level set to 0, compression disabled!\n" ++#define MSGTR_LIBVO_PNG_Warning2 "[VO_PNG] Info: Use -vo png:z= to set compression level from 0 to 9.\n" ++#define MSGTR_LIBVO_PNG_Warning3 "[VO_PNG] Info: (0 = no compression, 1 = fastest, lowest - 9 best, slowest compression)\n" ++#define MSGTR_LIBVO_PNG_ErrorOpeningForWriting "\n[VO_PNG] Error opening '%s' for writing!\n" ++#define MSGTR_LIBVO_PNG_ErrorInCreatePng "[VO_PNG] Error in create_png.\n" ++ ++// vo_pnm.c ++#define MSGTR_VO_PNM_ASCIIMode "ASCII mode enabled." ++#define MSGTR_VO_PNM_RawMode "Raw mode enabled." ++#define MSGTR_VO_PNM_PPMType "Will write PPM files." ++#define MSGTR_VO_PNM_PGMType "Will write PGM files." ++#define MSGTR_VO_PNM_PGMYUVType "Will write PGMYUV files." ++ ++// vo_sdl.c ++#define MSGTR_LIBVO_SDL_CouldntGetAnyAcceptableSDLModeForOutput "[VO_SDL] Couldn't get any acceptable SDL Mode for output.\n" ++#define MSGTR_LIBVO_SDL_SetVideoModeFailed "[VO_SDL] set_video_mode: SDL_SetVideoMode failed: %s.\n" ++#define MSGTR_LIBVO_SDL_SetVideoModeFailedFull "[VO_SDL] Set_fullmode: SDL_SetVideoMode failed: %s.\n" ++#define MSGTR_LIBVO_SDL_MappingI420ToIYUV "[VO_SDL] Mapping I420 to IYUV.\n" ++#define MSGTR_LIBVO_SDL_UnsupportedImageFormat "[VO_SDL] Unsupported image format (0x%X).\n" ++#define MSGTR_LIBVO_SDL_InfoPleaseUseVmOrZoom "[VO_SDL] Info - please use -vm or -zoom to switch to the best resolution.\n" ++#define MSGTR_LIBVO_SDL_FailedToSetVideoMode "[VO_SDL] Failed to set video mode: %s.\n" ++#define MSGTR_LIBVO_SDL_CouldntCreateAYUVOverlay "[VO_SDL] Couldn't create a YUV overlay: %s.\n" ++#define MSGTR_LIBVO_SDL_CouldntCreateARGBSurface "[VO_SDL] Couldn't create an RGB surface: %s.\n" ++#define MSGTR_LIBVO_SDL_UsingDepthColorspaceConversion "[VO_SDL] Using depth/colorspace conversion, this will slow things down (%ibpp -> %ibpp).\n" ++#define MSGTR_LIBVO_SDL_UnsupportedImageFormatInDrawslice "[VO_SDL] Unsupported image format in draw_slice, contact MPlayer developers!\n" ++#define MSGTR_LIBVO_SDL_BlitFailed "[VO_SDL] Blit failed: %s.\n" ++#define MSGTR_LIBVO_SDL_InitializationFailed "[VO_SDL] SDL initialization failed: %s.\n" ++#define MSGTR_LIBVO_SDL_UsingDriver "[VO_SDL] Using driver: %s.\n" ++ ++// vo_svga.c ++#define MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable "[VO_SVGA] Forced vid_mode %d (%s) not available.\n" ++#define MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall "[VO_SVGA] Forced vid_mode %d (%s) too small.\n" ++#define MSGTR_LIBVO_SVGA_Vidmode "[VO_SVGA] Vid_mode: %d, %dx%d %dbpp.\n" ++#define MSGTR_LIBVO_SVGA_VgasetmodeFailed "[VO_SVGA] Vga_setmode(%d) failed.\n" ++#define MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed "[VO_SVGA] Video mode is linear and memcpy could be used for image transfer.\n" ++#define MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration "[VO_SVGA] Video mode has hardware acceleration and put_image could be used.\n" ++#define MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow "[VO_SVGA] If it works for you I would like to know.\n[VO_SVGA] (send log with `mplayer test.avi -v -v -v -v &> svga.log`). Thx!\n" ++#define MSGTR_LIBVO_SVGA_VideoModeHas "[VO_SVGA] Video mode has %d page(s).\n" ++#define MSGTR_LIBVO_SVGA_CenteringImageStartAt "[VO_SVGA] Centering image. Starting at (%d,%d)\n" ++#define MSGTR_LIBVO_SVGA_UsingVidix "[VO_SVGA] Using VIDIX. w=%i h=%i mw=%i mh=%i\n" ++ ++// vo_tdfx_vid.c ++#define MSGTR_LIBVO_TDFXVID_Move "[VO_TDXVID] Move %d(%d) x %d => %d.\n" ++#define MSGTR_LIBVO_TDFXVID_AGPMoveFailedToClearTheScreen "[VO_TDFXVID] AGP move failed to clear the screen.\n" ++#define MSGTR_LIBVO_TDFXVID_BlitFailed "[VO_TDFXVID] Blit failed.\n" ++#define MSGTR_LIBVO_TDFXVID_NonNativeOverlayFormatNeedConversion "[VO_TDFXVID] Non-native overlay format needs conversion.\n" ++#define MSGTR_LIBVO_TDFXVID_UnsupportedInputFormat "[VO_TDFXVID] Unsupported input format 0x%x.\n" ++#define MSGTR_LIBVO_TDFXVID_OverlaySetupFailed "[VO_TDFXVID] Overlay setup failed.\n" ++#define MSGTR_LIBVO_TDFXVID_OverlayOnFailed "[VO_TDFXVID] Overlay on failed.\n" ++#define MSGTR_LIBVO_TDFXVID_OverlayReady "[VO_TDFXVID] Overlay ready: %d(%d) x %d @ %d => %d(%d) x %d @ %d.\n" ++#define MSGTR_LIBVO_TDFXVID_TextureBlitReady "[VO_TDFXVID] Texture blit ready: %d(%d) x %d @ %d => %d(%d) x %d @ %d.\n" ++#define MSGTR_LIBVO_TDFXVID_OverlayOffFailed "[VO_TDFXVID] Overlay off failed\n" ++#define MSGTR_LIBVO_TDFXVID_CantOpen "[VO_TDFXVID] Can't open %s: %s.\n" ++#define MSGTR_LIBVO_TDFXVID_CantGetCurrentCfg "[VO_TDFXVID] Can't get current configuration: %s.\n" ++#define MSGTR_LIBVO_TDFXVID_MemmapFailed "[VO_TDFXVID] Memmap failed !!!!!\n" ++#define MSGTR_LIBVO_TDFXVID_GetImageTodo "Get image todo.\n" ++#define MSGTR_LIBVO_TDFXVID_AgpMoveFailed "[VO_TDFXVID] AGP move failed.\n" ++#define MSGTR_LIBVO_TDFXVID_SetYuvFailed "[VO_TDFXVID] Set YUV failed.\n" ++#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnYPlane "[VO_TDFXVID] AGP move failed on Y plane.\n" ++#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnUPlane "[VO_TDFXVID] AGP move failed on U plane.\n" ++#define MSGTR_LIBVO_TDFXVID_AgpMoveFailedOnVPlane "[VO_TDFXVID] AGP move failed on V plane.\n" ++#define MSGTR_LIBVO_TDFXVID_UnknownFormat "[VO_TDFXVID] unknown format: 0x%x.\n" ++ ++// vo_tdfxfb.c ++#define MSGTR_LIBVO_TDFXFB_CantOpen "[VO_TDFXFB] Can't open %s: %s.\n" ++#define MSGTR_LIBVO_TDFXFB_ProblemWithFbitgetFscreenInfo "[VO_TDFXFB] Problem with FBITGET_FSCREENINFO ioctl: %s.\n" ++#define MSGTR_LIBVO_TDFXFB_ProblemWithFbitgetVscreenInfo "[VO_TDFXFB] Problem with FBITGET_VSCREENINFO ioctl: %s.\n" ++#define MSGTR_LIBVO_TDFXFB_ThisDriverOnlySupports "[VO_TDFXFB] This driver only supports the 3Dfx Banshee, Voodoo3 and Voodoo 5.\n" ++#define MSGTR_LIBVO_TDFXFB_OutputIsNotSupported "[VO_TDFXFB] %d bpp output is not supported.\n" ++#define MSGTR_LIBVO_TDFXFB_CouldntMapMemoryAreas "[VO_TDFXFB] Couldn't map memory areas: %s.\n" ++#define MSGTR_LIBVO_TDFXFB_BppOutputIsNotSupported "[VO_TDFXFB] %d bpp output is not supported (This should never have happened).\n" ++#define MSGTR_LIBVO_TDFXFB_SomethingIsWrongWithControl "[VO_TDFXFB] Eik! Something's wrong with control().\n" ++#define MSGTR_LIBVO_TDFXFB_NotEnoughVideoMemoryToPlay "[VO_TDFXFB] Not enough video memory to play this movie. Try at a lower resolution.\n" ++#define MSGTR_LIBVO_TDFXFB_ScreenIs "[VO_TDFXFB] Screen is %dx%d at %d bpp, in is %dx%d at %d bpp, norm is %dx%d.\n" ++ ++// vo_tga.c ++#define MSGTR_LIBVO_TGA_UnknownSubdevice "[VO_TGA] Unknown subdevice: %s.\n" ++ ++// vo_vesa.c ++#define MSGTR_LIBVO_VESA_FatalErrorOccurred "[VO_VESA] Fatal error occurred! Can't continue.\n" ++#define MSGTR_LIBVO_VESA_UnknownSubdevice "[VO_VESA] unknown subdevice: '%s'.\n" ++#define MSGTR_LIBVO_VESA_YouHaveTooLittleVideoMemory "[VO_VESA] You have too little video memory for this mode:\n[VO_VESA] Required: %08lX present: %08lX.\n" ++#define MSGTR_LIBVO_VESA_YouHaveToSpecifyTheCapabilitiesOfTheMonitor "[VO_VESA] You have to specify the capabilities of the monitor. Not changing refresh rate.\n" ++#define MSGTR_LIBVO_VESA_UnableToFitTheMode "[VO_VESA] The mode does not fit the monitor limits. Not changing refresh rate.\n" ++#define MSGTR_LIBVO_VESA_DetectedInternalFatalError "[VO_VESA] Detected internal fatal error: init is called before preinit.\n" ++#define MSGTR_LIBVO_VESA_SwitchFlipIsNotSupported "[VO_VESA] The -flip option is not supported.\n" ++#define MSGTR_LIBVO_VESA_PossibleReasonNoVbe2BiosFound "[VO_VESA] Possible reason: No VBE2 BIOS found.\n" ++#define MSGTR_LIBVO_VESA_FoundVesaVbeBiosVersion "[VO_VESA] Found VESA VBE BIOS Version %x.%x Revision: %x.\n" ++#define MSGTR_LIBVO_VESA_VideoMemory "[VO_VESA] Video memory: %u Kb.\n" ++#define MSGTR_LIBVO_VESA_Capabilites "[VO_VESA] VESA Capabilities: %s %s %s %s %s.\n" ++#define MSGTR_LIBVO_VESA_BelowWillBePrintedOemInfo "[VO_VESA] !!! OEM info will be printed below !!!\n" ++#define MSGTR_LIBVO_VESA_YouShouldSee5OemRelatedLines "[VO_VESA] You should see 5 OEM related lines below; If not, you've broken vm86.\n" ++#define MSGTR_LIBVO_VESA_OemInfo "[VO_VESA] OEM info: %s.\n" ++#define MSGTR_LIBVO_VESA_OemRevision "[VO_VESA] OEM Revision: %x.\n" ++#define MSGTR_LIBVO_VESA_OemVendor "[VO_VESA] OEM vendor: %s.\n" ++#define MSGTR_LIBVO_VESA_OemProductName "[VO_VESA] OEM Product Name: %s.\n" ++#define MSGTR_LIBVO_VESA_OemProductRev "[VO_VESA] OEM Product Rev: %s.\n" ++#define MSGTR_LIBVO_VESA_Hint "[VO_VESA] Hint: For working TV-Out you should have plugged in the TV connector\n"\ ++"[VO_VESA] before booting since VESA BIOS initializes itself only during POST.\n" ++#define MSGTR_LIBVO_VESA_UsingVesaMode "[VO_VESA] Using VESA mode (%u) = %x [%ux%u@%u]\n" ++#define MSGTR_LIBVO_VESA_CantInitializeSwscaler "[VO_VESA] Can't initialize software scaler.\n" ++#define MSGTR_LIBVO_VESA_CantUseDga "[VO_VESA] Can't use DGA. Force bank switching mode. :(\n" ++#define MSGTR_LIBVO_VESA_UsingDga "[VO_VESA] Using DGA (physical resources: %08lXh, %08lXh)" ++#define MSGTR_LIBVO_VESA_CantUseDoubleBuffering "[VO_VESA] Can't use double buffering: not enough video memory.\n" ++#define MSGTR_LIBVO_VESA_CantFindNeitherDga "[VO_VESA] Can find neither DGA nor relocatable window frame.\n" ++#define MSGTR_LIBVO_VESA_YouveForcedDga "[VO_VESA] You've forced DGA. Exiting\n" ++#define MSGTR_LIBVO_VESA_CantFindValidWindowAddress "[VO_VESA] Can't find valid window address.\n" ++#define MSGTR_LIBVO_VESA_UsingBankSwitchingMode "[VO_VESA] Using bank switching mode (physical resources: %08lXh, %08lXh).\n" ++#define MSGTR_LIBVO_VESA_CantAllocateTemporaryBuffer "[VO_VESA] Can't allocate temporary buffer.\n" ++#define MSGTR_LIBVO_VESA_SorryUnsupportedMode "[VO_VESA] Sorry, unsupported mode -- try -x 640 -zoom.\n" ++#define MSGTR_LIBVO_VESA_OhYouReallyHavePictureOnTv "[VO_VESA] Oh you really have a picture on the TV!\n" ++#define MSGTR_LIBVO_VESA_CantInitialozeLinuxVideoOverlay "[VO_VESA] Can't initialize Linux Video Overlay.\n" ++#define MSGTR_LIBVO_VESA_UsingVideoOverlay "[VO_VESA] Using video overlay: %s.\n" ++#define MSGTR_LIBVO_VESA_CantInitializeVidixDriver "[VO_VESA] Can't initialize VIDIX driver.\n" ++#define MSGTR_LIBVO_VESA_UsingVidix "[VO_VESA] Using VIDIX.\n" ++#define MSGTR_LIBVO_VESA_CantFindModeFor "[VO_VESA] Can't find mode for: %ux%u@%u.\n" ++#define MSGTR_LIBVO_VESA_InitializationComplete "[VO_VESA] VESA initialization complete.\n" ++ ++// vesa_lvo.c ++#define MSGTR_LIBVO_VESA_ThisBranchIsNoLongerSupported "[VESA_LVO] This branch is no longer supported.\n[VESA_LVO] Please use -vo vesa:vidix instead.\n" ++#define MSGTR_LIBVO_VESA_CouldntOpen "[VESA_LVO] Couldn't open: '%s'\n" ++#define MSGTR_LIBVO_VESA_InvalidOutputFormat "[VESA_LVI] Invalid output format: %s(%0X)\n" ++#define MSGTR_LIBVO_VESA_IncompatibleDriverVersion "[VESA_LVO] Your fb_vid driver version is incompatible with this MPlayer version!\n" ++ ++// vo_x11.c ++#define MSGTR_LIBVO_X11_DrawFrameCalled "[VO_X11] draw_frame() called!!!!!!\n" ++ ++// vo_xv.c ++#define MSGTR_LIBVO_XV_DrawFrameCalled "[VO_XV] draw_frame() called!!!!!!\n" ++#define MSGTR_LIBVO_XV_SharedMemoryNotSupported "[VO_XV] Shared memory not supported\nReverting to normal Xv.\n" ++#define MSGTR_LIBVO_XV_XvNotSupportedByX11 "[VO_XV] Sorry, Xv not supported by this X11 version/driver\n[VO_XV] ******** Try with -vo x11 or -vo sdl *********\n" ++#define MSGTR_LIBVO_XV_XvQueryAdaptorsFailed "[VO_XV] XvQueryAdaptors failed.\n" ++#define MSGTR_LIBVO_XV_InvalidPortParameter "[VO_XV] Invalid port parameter, overriding with port 0.\n" ++#define MSGTR_LIBVO_XV_CouldNotGrabPort "[VO_XV] Could not grab port %i.\n" ++#define MSGTR_LIBVO_XV_CouldNotFindFreePort "[VO_XV] Could not find free Xvideo port - maybe another process is already\n"\ ++"[VO_XV] using it. Close all video applications, and try again. If that does\n"\ ++"[VO_XV] not help, see 'mplayer -vo help' for other (non-xv) video out drivers.\n" ++#define MSGTR_LIBVO_XV_NoXvideoSupport "[VO_XV] It seems there is no Xvideo support for your video card available.\n"\ ++"[VO_XV] Run 'xvinfo' to verify its Xv support and read\n"\ ++"[VO_XV] DOCS/HTML/en/video.html#xv!\n"\ ++"[VO_XV] See 'mplayer -vo help' for other (non-xv) video out drivers.\n"\ ++"[VO_XV] Try -vo x11.\n" ++#define MSGTR_VO_XV_ImagedimTooHigh "Source image dimensions are too high: %ux%u (maximum is %ux%u)\n" ++ ++// vo_yuv4mpeg.c ++#define MSGTR_VO_YUV4MPEG_InterlacedHeightDivisibleBy4 "Interlaced mode requires image height to be divisible by 4." ++#define MSGTR_VO_YUV4MPEG_InterlacedLineBufAllocFail "Unable to allocate line buffer for interlaced mode." ++#define MSGTR_VO_YUV4MPEG_WidthDivisibleBy2 "Image width must be divisible by 2." ++#define MSGTR_VO_YUV4MPEG_OutFileOpenError "Can't get memory or file handle to write \"%s\"!" ++#define MSGTR_VO_YUV4MPEG_OutFileWriteError "Error writing image to output!" ++#define MSGTR_VO_YUV4MPEG_UnknownSubDev "Unknown subdevice: %s" ++#define MSGTR_VO_YUV4MPEG_InterlacedTFFMode "Using interlaced output mode, top-field first." ++#define MSGTR_VO_YUV4MPEG_InterlacedBFFMode "Using interlaced output mode, bottom-field first." ++#define MSGTR_VO_YUV4MPEG_ProgressiveMode "Using (default) progressive frame mode." ++ ++// vosub_vidix.c ++#define MSGTR_LIBVO_SUB_VIDIX_CantStartPlayback "[VO_SUB_VIDIX] Can't start playback: %s\n" ++#define MSGTR_LIBVO_SUB_VIDIX_CantStopPlayback "[VO_SUB_VIDIX] Can't stop playback: %s\n" ++#define MSGTR_LIBVO_SUB_VIDIX_InterleavedUvForYuv410pNotSupported "[VO_SUB_VIDIX] Interleaved UV for YUV410P not supported.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawsliceWasCalled "[VO_SUB_VIDIX] Dummy vidix_draw_slice() was called.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_DummyVidixdrawframeWasCalled "[VO_SUB_VIDIX] Dummy vidix_draw_frame() was called.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_UnsupportedFourccForThisVidixDriver "[VO_SUB_VIDIX] Unsupported FourCC for this VIDIX driver: %x (%s).\n" ++#define MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedResolution "[VO_SUB_VIDIX] Video server has unsupported resolution (%dx%d), supported: %dx%d-%dx%d.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_VideoServerHasUnsupportedColorDepth "[VO_SUB_VIDIX] Video server has unsupported color depth by vidix (%d).\n" ++#define MSGTR_LIBVO_SUB_VIDIX_DriverCantUpscaleImage "[VO_SUB_VIDIX] VIDIX driver can't upscale image (%d%d -> %d%d).\n" ++#define MSGTR_LIBVO_SUB_VIDIX_DriverCantDownscaleImage "[VO_SUB_VIDIX] VIDIX driver can't downscale image (%d%d -> %d%d).\n" ++#define MSGTR_LIBVO_SUB_VIDIX_CantConfigurePlayback "[VO_SUB_VIDIX] Can't configure playback: %s.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_YouHaveWrongVersionOfVidixLibrary "[VO_SUB_VIDIX] You have the wrong version of the VIDIX library.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_CouldntFindWorkingVidixDriver "[VO_SUB_VIDIX] Couldn't find working VIDIX driver.\n" ++#define MSGTR_LIBVO_SUB_VIDIX_CouldntGetCapability "[VO_SUB_VIDIX] Couldn't get capability: %s.\n" ++ ++// x11_common.c ++#define MSGTR_EwmhFullscreenStateFailed "\nX11: Couldn't send EWMH fullscreen event!\n" ++#define MSGTR_CouldNotFindXScreenSaver "xscreensaver_disable: Could not find XScreenSaver window.\n" ++#define MSGTR_SelectedVideoMode "XF86VM: Selected video mode %dx%d for image size %dx%d.\n" ++ ++#define MSGTR_InsertingAfVolume "[Mixer] No hardware mixing, inserting volume filter.\n" ++#define MSGTR_NoVolume "[Mixer] No volume control available.\n" ++#define MSGTR_NoBalance "[Mixer] No balance control available.\n" ++ ++// old vo drivers that have been replaced ++#define MSGTR_VO_PGM_HasBeenReplaced "The pgm video output driver has been replaced by -vo pnm:pgmyuv.\n" ++#define MSGTR_VO_MD5_HasBeenReplaced "The md5 video output driver has been replaced by -vo md5sum.\n" ++ ++ ++// ======================= audio output drivers ======================== ++ ++// audio_out.c ++#define MSGTR_AO_ALSA9_1x_Removed "audio_out: alsa9 and alsa1x modules were removed, use -ao alsa instead.\n" ++#define MSGTR_AO_TryingPreferredAudioDriver "Trying preferred audio driver '%.*s', options '%s'\n" ++#define MSGTR_AO_NoSuchDriver "No such audio driver '%.*s'\n" ++#define MSGTR_AO_FailedInit "Failed to initialize audio driver '%s'\n" ++#define MSGTR_AO_TryingEveryKnown "Trying every known audio driver...\n" ++ ++// ao_oss.c ++#define MSGTR_AO_OSS_CantOpenMixer "[AO OSS] audio_setup: Can't open mixer device %s: %s\n" ++#define MSGTR_AO_OSS_ChanNotFound "[AO OSS] audio_setup: Audio card mixer does not have channel '%s', using default.\n" ++#define MSGTR_AO_OSS_CantOpenDev "[AO OSS] audio_setup: Can't open audio device %s: %s\n" ++#define MSGTR_AO_OSS_CantMakeFd "[AO OSS] audio_setup: Can't make file descriptor blocking: %s\n" ++#define MSGTR_AO_OSS_CantSet "[AO OSS] Can't set audio device %s to %s output, trying %s...\n" ++#define MSGTR_AO_OSS_CantSetChans "[AO OSS] audio_setup: Failed to set audio device to %d channels.\n" ++#define MSGTR_AO_OSS_CantUseGetospace "[AO OSS] audio_setup: driver doesn't support SNDCTL_DSP_GETOSPACE :-(\n" ++#define MSGTR_AO_OSS_CantUseSelect "[AO OSS]\n *** Your audio driver DOES NOT support select() ***\n Recompile MPlayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n" ++#define MSGTR_AO_OSS_CantReopen "[AO OSS]\nFatal error: *** CANNOT RE-OPEN / RESET AUDIO DEVICE *** %s\n" ++#define MSGTR_AO_OSS_UnknownUnsupportedFormat "[AO OSS] Unknown/Unsupported OSS format: %x.\n" ++ ++// ao_arts.c ++#define MSGTR_AO_ARTS_CantInit "[AO ARTS] %s\n" ++#define MSGTR_AO_ARTS_ServerConnect "[AO ARTS] Connected to sound server.\n" ++#define MSGTR_AO_ARTS_CantOpenStream "[AO ARTS] Unable to open a stream.\n" ++#define MSGTR_AO_ARTS_StreamOpen "[AO ARTS] Stream opened.\n" ++#define MSGTR_AO_ARTS_BufferSize "[AO ARTS] buffer size: %d\n" ++ ++// ao_dxr2.c ++#define MSGTR_AO_DXR2_SetVolFailed "[AO DXR2] Setting volume to %d failed.\n" ++#define MSGTR_AO_DXR2_UnsupSamplerate "[AO DXR2] %d Hz not supported, try to resample.\n" ++ ++// ao_esd.c ++#define MSGTR_AO_ESD_CantOpenSound "[AO ESD] esd_open_sound failed: %s\n" ++#define MSGTR_AO_ESD_LatencyInfo "[AO ESD] latency: [server: %0.2fs, net: %0.2fs] (adjust %0.2fs)\n" ++#define MSGTR_AO_ESD_CantOpenPBStream "[AO ESD] failed to open ESD playback stream: %s\n" ++ ++// ao_mpegpes.c ++#define MSGTR_AO_MPEGPES_CantSetMixer "[AO MPEGPES] DVB audio set mixer failed: %s.\n" ++#define MSGTR_AO_MPEGPES_UnsupSamplerate "[AO MPEGPES] %d Hz not supported, try to resample.\n" ++ ++// ao_pcm.c ++#define MSGTR_AO_PCM_FileInfo "[AO PCM] File: %s (%s)\nPCM: Samplerate: %iHz Channels: %s Format %s\n" ++#define MSGTR_AO_PCM_HintInfo "[AO PCM] Info: Faster dumping is achieved with -vc null -vo null -ao pcm:fast\n[AO PCM] Info: To write WAVE files use -ao pcm:waveheader (default).\n" ++#define MSGTR_AO_PCM_CantOpenOutputFile "[AO PCM] Failed to open %s for writing!\n" ++ ++// ao_sdl.c ++#define MSGTR_AO_SDL_INFO "[AO SDL] Samplerate: %iHz Channels: %s Format %s\n" ++#define MSGTR_AO_SDL_DriverInfo "[AO SDL] using %s audio driver.\n" ++#define MSGTR_AO_SDL_UnsupportedAudioFmt "[AO SDL] Unsupported audio format: 0x%x.\n" ++#define MSGTR_AO_SDL_CantInit "[AO SDL] SDL Audio initialization failed: %s\n" ++#define MSGTR_AO_SDL_CantOpenAudio "[AO SDL] Unable to open audio: %s\n" ++ ++// ao_sgi.c ++#define MSGTR_AO_SGI_INFO "[AO SGI] control.\n" ++#define MSGTR_AO_SGI_InitInfo "[AO SGI] init: Samplerate: %iHz Channels: %s Format %s\n" ++#define MSGTR_AO_SGI_InvalidDevice "[AO SGI] play: invalid device.\n" ++#define MSGTR_AO_SGI_CantSetParms_Samplerate "[AO SGI] init: setparams failed: %s\nCould not set desired samplerate.\n" ++#define MSGTR_AO_SGI_CantSetAlRate "[AO SGI] init: AL_RATE was not accepted on the given resource.\n" ++#define MSGTR_AO_SGI_CantGetParms "[AO SGI] init: getparams failed: %s\n" ++#define MSGTR_AO_SGI_SampleRateInfo "[AO SGI] init: samplerate is now %lf (desired rate is %lf)\n" ++#define MSGTR_AO_SGI_InitConfigError "[AO SGI] init: %s\n" ++#define MSGTR_AO_SGI_InitOpenAudioFailed "[AO SGI] init: Unable to open audio channel: %s\n" ++#define MSGTR_AO_SGI_Uninit "[AO SGI] uninit: ...\n" ++#define MSGTR_AO_SGI_Reset "[AO SGI] reset: ...\n" ++#define MSGTR_AO_SGI_PauseInfo "[AO SGI] audio_pause: ...\n" ++#define MSGTR_AO_SGI_ResumeInfo "[AO SGI] audio_resume: ...\n" ++ ++// ao_sun.c ++#define MSGTR_AO_SUN_RtscSetinfoFailed "[AO SUN] rtsc: SETINFO failed.\n" ++#define MSGTR_AO_SUN_RtscWriteFailed "[AO SUN] rtsc: write failed.\n" ++#define MSGTR_AO_SUN_CantOpenAudioDev "[AO SUN] Can't open audio device %s, %s -> nosound.\n" ++#define MSGTR_AO_SUN_UnsupSampleRate "[AO SUN] audio_setup: your card doesn't support %d channel, %s, %d Hz samplerate.\n" ++#define MSGTR_AO_SUN_CantUseSelect "[AO SUN]\n *** Your audio driver DOES NOT support select() ***\nRecompile MPlayer with #undef HAVE_AUDIO_SELECT in config.h !\n\n" ++#define MSGTR_AO_SUN_CantReopenReset "[AO SUN]\nFatal error: *** CANNOT REOPEN / RESET AUDIO DEVICE (%s) ***\n" ++ ++// ao_alsa5.c ++#define MSGTR_AO_ALSA5_InitInfo "[AO ALSA5] alsa-init: requested format: %d Hz, %d channels, %s\n" ++#define MSGTR_AO_ALSA5_SoundCardNotFound "[AO ALSA5] alsa-init: no soundcards found.\n" ++#define MSGTR_AO_ALSA5_InvalidFormatReq "[AO ALSA5] alsa-init: invalid format (%s) requested - output disabled.\n" ++#define MSGTR_AO_ALSA5_PlayBackError "[AO ALSA5] alsa-init: playback open error: %s\n" ++#define MSGTR_AO_ALSA5_PcmInfoError "[AO ALSA5] alsa-init: PCM info error: %s\n" ++#define MSGTR_AO_ALSA5_SoundcardsFound "[AO ALSA5] alsa-init: %d soundcard(s) found, using: %s\n" ++#define MSGTR_AO_ALSA5_PcmChanInfoError "[AO ALSA5] alsa-init: PCM channel info error: %s\n" ++#define MSGTR_AO_ALSA5_CantSetParms "[AO ALSA5] alsa-init: error setting parameters: %s\n" ++#define MSGTR_AO_ALSA5_CantSetChan "[AO ALSA5] alsa-init: error setting up channel: %s\n" ++#define MSGTR_AO_ALSA5_ChanPrepareError "[AO ALSA5] alsa-init: channel prepare error: %s\n" ++#define MSGTR_AO_ALSA5_DrainError "[AO ALSA5] alsa-uninit: playback drain error: %s\n" ++#define MSGTR_AO_ALSA5_FlushError "[AO ALSA5] alsa-uninit: playback flush error: %s\n" ++#define MSGTR_AO_ALSA5_PcmCloseError "[AO ALSA5] alsa-uninit: PCM close error: %s\n" ++#define MSGTR_AO_ALSA5_ResetDrainError "[AO ALSA5] alsa-reset: playback drain error: %s\n" ++#define MSGTR_AO_ALSA5_ResetFlushError "[AO ALSA5] alsa-reset: playback flush error: %s\n" ++#define MSGTR_AO_ALSA5_ResetChanPrepareError "[AO ALSA5] alsa-reset: channel prepare error: %s\n" ++#define MSGTR_AO_ALSA5_PauseDrainError "[AO ALSA5] alsa-pause: playback drain error: %s\n" ++#define MSGTR_AO_ALSA5_PauseFlushError "[AO ALSA5] alsa-pause: playback flush error: %s\n" ++#define MSGTR_AO_ALSA5_ResumePrepareError "[AO ALSA5] alsa-resume: channel prepare error: %s\n" ++#define MSGTR_AO_ALSA5_Underrun "[AO ALSA5] alsa-play: alsa underrun, resetting stream.\n" ++#define MSGTR_AO_ALSA5_PlaybackPrepareError "[AO ALSA5] alsa-play: playback prepare error: %s\n" ++#define MSGTR_AO_ALSA5_WriteErrorAfterReset "[AO ALSA5] alsa-play: write error after reset: %s - giving up.\n" ++#define MSGTR_AO_ALSA5_OutPutError "[AO ALSA5] alsa-play: output error: %s\n" ++ ++// ao_alsa.c ++#define MSGTR_AO_ALSA_InvalidMixerIndexDefaultingToZero "[AO_ALSA] Invalid mixer index. Defaulting to 0.\n" ++#define MSGTR_AO_ALSA_MixerOpenError "[AO_ALSA] Mixer open error: %s\n" ++#define MSGTR_AO_ALSA_MixerAttachError "[AO_ALSA] Mixer attach %s error: %s\n" ++#define MSGTR_AO_ALSA_MixerRegisterError "[AO_ALSA] Mixer register error: %s\n" ++#define MSGTR_AO_ALSA_MixerLoadError "[AO_ALSA] Mixer load error: %s\n" ++#define MSGTR_AO_ALSA_UnableToFindSimpleControl "[AO_ALSA] Unable to find simple control '%s',%i.\n" ++#define MSGTR_AO_ALSA_ErrorSettingLeftChannel "[AO_ALSA] Error setting left channel, %s\n" ++#define MSGTR_AO_ALSA_ErrorSettingRightChannel "[AO_ALSA] Error setting right channel, %s\n" ++#define MSGTR_AO_ALSA_CommandlineHelp "\n[AO_ALSA] -ao alsa commandline help:\n"\ ++"[AO_ALSA] Example: mplayer -ao alsa:device=hw=0.3\n"\ ++"[AO_ALSA] Sets first card fourth hardware device.\n\n"\ ++"[AO_ALSA] Options:\n"\ ++"[AO_ALSA] noblock\n"\ ++"[AO_ALSA] Opens device in non-blocking mode.\n"\ ++"[AO_ALSA] device=\n"\ ++"[AO_ALSA] Sets device (change , to . and : to =)\n" ++#define MSGTR_AO_ALSA_ChannelsNotSupported "[AO_ALSA] %d channels are not supported.\n" ++#define MSGTR_AO_ALSA_OpenInNonblockModeFailed "[AO_ALSA] Open in nonblock-mode failed, trying to open in block-mode.\n" ++#define MSGTR_AO_ALSA_PlaybackOpenError "[AO_ALSA] Playback open error: %s\n" ++#define MSGTR_AO_ALSA_ErrorSetBlockMode "[AL_ALSA] Error setting block-mode %s.\n" ++#define MSGTR_AO_ALSA_UnableToGetInitialParameters "[AO_ALSA] Unable to get initial parameters: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetAccessType "[AO_ALSA] Unable to set access type: %s\n" ++#define MSGTR_AO_ALSA_FormatNotSupportedByHardware "[AO_ALSA] Format %s is not supported by hardware, trying default.\n" ++#define MSGTR_AO_ALSA_UnableToSetFormat "[AO_ALSA] Unable to set format: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetChannels "[AO_ALSA] Unable to set channels: %s\n" ++#define MSGTR_AO_ALSA_UnableToDisableResampling "[AO_ALSA] Unable to disable resampling: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetSamplerate2 "[AO_ALSA] Unable to set samplerate-2: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetBufferTimeNear "[AO_ALSA] Unable to set buffer time near: %s\n" ++#define MSGTR_AO_ALSA_UnableToGetPeriodSize "[AO ALSA] Unable to get period size: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetPeriods "[AO_ALSA] Unable to set periods: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetHwParameters "[AO_ALSA] Unable to set hw-parameters: %s\n" ++#define MSGTR_AO_ALSA_UnableToGetBufferSize "[AO_ALSA] Unable to get buffersize: %s\n" ++#define MSGTR_AO_ALSA_UnableToGetSwParameters "[AO_ALSA] Unable to get sw-parameters: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetSwParameters "[AO_ALSA] Unable to set sw-parameters: %s\n" ++#define MSGTR_AO_ALSA_UnableToGetBoundary "[AO_ALSA] Unable to get boundary: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetStartThreshold "[AO_ALSA] Unable to set start threshold: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetStopThreshold "[AO_ALSA] Unable to set stop threshold: %s\n" ++#define MSGTR_AO_ALSA_UnableToSetSilenceSize "[AO_ALSA] Unable to set silence size: %s\n" ++#define MSGTR_AO_ALSA_PcmCloseError "[AO_ALSA] pcm close error: %s\n" ++#define MSGTR_AO_ALSA_NoHandlerDefined "[AO_ALSA] No handler defined!\n" ++#define MSGTR_AO_ALSA_PcmPrepareError "[AO_ALSA] pcm prepare error: %s\n" ++#define MSGTR_AO_ALSA_PcmPauseError "[AO_ALSA] pcm pause error: %s\n" ++#define MSGTR_AO_ALSA_PcmDropError "[AO_ALSA] pcm drop error: %s\n" ++#define MSGTR_AO_ALSA_PcmResumeError "[AO_ALSA] pcm resume error: %s\n" ++#define MSGTR_AO_ALSA_DeviceConfigurationError "[AO_ALSA] Device configuration error." ++#define MSGTR_AO_ALSA_PcmInSuspendModeTryingResume "[AO_ALSA] Pcm in suspend mode, trying to resume.\n" ++#define MSGTR_AO_ALSA_WriteError "[AO_ALSA] Write error: %s\n" ++#define MSGTR_AO_ALSA_TryingToResetSoundcard "[AO_ALSA] Trying to reset soundcard.\n" ++#define MSGTR_AO_ALSA_CannotGetPcmStatus "[AO_ALSA] Cannot get pcm status: %s\n" ++ ++// ao_plugin.c ++#define MSGTR_AO_PLUGIN_InvalidPlugin "[AO PLUGIN] invalid plugin: %s\n" ++ ++ ++// ======================= audio filters ================================ ++ ++// af_scaletempo.c ++#define MSGTR_AF_ValueOutOfRange MSGTR_VO_ValueOutOfRange ++ ++// af_ladspa.c ++#define MSGTR_AF_LADSPA_AvailableLabels "available labels in" ++#define MSGTR_AF_LADSPA_WarnNoInputs "WARNING! This LADSPA plugin has no audio inputs.\n The incoming audio signal will be lost." ++#define MSGTR_AF_LADSPA_ErrMultiChannel "Multi-channel (>2) plugins are not supported (yet).\n Use only mono and stereo plugins." ++#define MSGTR_AF_LADSPA_ErrNoOutputs "This LADSPA plugin has no audio outputs." ++#define MSGTR_AF_LADSPA_ErrInOutDiff "The number of audio inputs and audio outputs of the LADSPA plugin differ." ++#define MSGTR_AF_LADSPA_ErrFailedToLoad "failed to load" ++#define MSGTR_AF_LADSPA_ErrNoDescriptor "Couldn't find ladspa_descriptor() function in the specified library file." ++#define MSGTR_AF_LADSPA_ErrLabelNotFound "Couldn't find label in plugin library." ++#define MSGTR_AF_LADSPA_ErrNoSuboptions "No suboptions specified." ++#define MSGTR_AF_LADSPA_ErrNoLibFile "No library file specified." ++#define MSGTR_AF_LADSPA_ErrNoLabel "No filter label specified." ++#define MSGTR_AF_LADSPA_ErrNotEnoughControls "Not enough controls specified on the command line." ++#define MSGTR_AF_LADSPA_ErrControlBelow "%s: Input control #%d is below lower boundary of %0.4f.\n" ++#define MSGTR_AF_LADSPA_ErrControlAbove "%s: Input control #%d is above upper boundary of %0.4f.\n" ++ ++// format.c ++#define MSGTR_AF_FORMAT_UnknownFormat "unknown format " ++ ++ ++// ========================== INPUT ========================================= ++ ++// joystick.c ++#define MSGTR_INPUT_JOYSTICK_Opening "Opening joystick device %s\n" ++#define MSGTR_INPUT_JOYSTICK_CantOpen "Can't open joystick device %s: %s\n" ++#define MSGTR_INPUT_JOYSTICK_ErrReading "Error while reading joystick device: %s\n" ++#define MSGTR_INPUT_JOYSTICK_LoosingBytes "Joystick: We lose %d bytes of data\n" ++#define MSGTR_INPUT_JOYSTICK_WarnLostSync "Joystick: warning init event, we have lost sync with driver.\n" ++#define MSGTR_INPUT_JOYSTICK_WarnUnknownEvent "Joystick warning unknown event type %d\n" ++ ++// appleir.c ++#define MSGTR_INPUT_APPLE_IR_Init "Initializing Apple IR on %s\n" ++#define MSGTR_INPUT_APPLE_IR_Detect "Detected Apple IR on %s\n" ++#define MSGTR_INPUT_APPLE_IR_CantOpen "Can't open Apple IR device: %s\n" ++ ++// input.c ++#define MSGTR_INPUT_INPUT_ErrCantRegister2ManyCmdFds "Too many command file descriptors, cannot register file descriptor %d.\n" ++#define MSGTR_INPUT_INPUT_ErrCantRegister2ManyKeyFds "Too many key file descriptors, cannot register file descriptor %d.\n" ++#define MSGTR_INPUT_INPUT_ErrArgMustBeInt "Command %s: argument %d isn't an integer.\n" ++#define MSGTR_INPUT_INPUT_ErrArgMustBeFloat "Command %s: argument %d isn't a float.\n" ++#define MSGTR_INPUT_INPUT_ErrUnterminatedArg "Command %s: argument %d is unterminated.\n" ++#define MSGTR_INPUT_INPUT_ErrUnknownArg "Unknown argument %d\n" ++#define MSGTR_INPUT_INPUT_Err2FewArgs "Command %s requires at least %d arguments, we found only %d so far.\n" ++#define MSGTR_INPUT_INPUT_ErrReadingCmdFd "Error while reading command file descriptor %d: %s\n" ++#define MSGTR_INPUT_INPUT_ErrCmdBufferFullDroppingContent "Command buffer of file descriptor %d is full: dropping content.\n" ++#define MSGTR_INPUT_INPUT_ErrInvalidCommandForKey "Invalid command for bound key %s" ++#define MSGTR_INPUT_INPUT_ErrSelect "Select error: %s\n" ++#define MSGTR_INPUT_INPUT_ErrOnKeyInFd "Error on key input file descriptor %d\n" ++#define MSGTR_INPUT_INPUT_ErrDeadKeyOnFd "Dead key input on file descriptor %d\n" ++#define MSGTR_INPUT_INPUT_Err2ManyKeyDowns "Too many key down events at the same time\n" ++#define MSGTR_INPUT_INPUT_ErrOnCmdFd "Error on command file descriptor %d\n" ++#define MSGTR_INPUT_INPUT_ErrReadingInputConfig "Error while reading input config file %s: %s\n" ++#define MSGTR_INPUT_INPUT_ErrUnknownKey "Unknown key '%s'\n" ++#define MSGTR_INPUT_INPUT_ErrUnfinishedBinding "Unfinished binding %s\n" ++#define MSGTR_INPUT_INPUT_ErrBuffer2SmallForKeyName "Buffer is too small for this key name: %s\n" ++#define MSGTR_INPUT_INPUT_ErrNoCmdForKey "No command found for key %s" ++#define MSGTR_INPUT_INPUT_ErrBuffer2SmallForCmd "Buffer is too small for command %s\n" ++#define MSGTR_INPUT_INPUT_ErrWhyHere "What are we doing here?\n" ++#define MSGTR_INPUT_INPUT_ErrCantInitJoystick "Can't init input joystick\n" ++#define MSGTR_INPUT_INPUT_ErrCantStatFile "Can't stat %s: %s\n" ++#define MSGTR_INPUT_INPUT_ErrCantOpenFile "Can't open %s: %s\n" ++#define MSGTR_INPUT_INPUT_ErrCantInitAppleRemote "Can't init Apple Remote.\n" ++ ++// lirc.c ++#define MSGTR_SettingUpLIRC "Setting up LIRC support...\n" ++#define MSGTR_LIRCopenfailed "Failed to open LIRC support. You will not be able to use your remote control.\n" ++#define MSGTR_LIRCcfgerr "Failed to read LIRC config file %s.\n" ++ ++ ++// ========================== LIBMPDEMUX =================================== ++ ++// muxer.c, muxer_*.c ++#define MSGTR_TooManyStreams "Too many streams!" ++#define MSGTR_RawMuxerOnlyOneStream "Rawaudio muxer supports only one audio stream!\n" ++#define MSGTR_IgnoringVideoStream "Ignoring video stream!\n" ++#define MSGTR_UnknownStreamType "Warning, unknown stream type: %d\n" ++#define MSGTR_WarningLenIsntDivisible "Warning, len isn't divisible by samplesize!\n" ++#define MSGTR_MuxbufMallocErr "Muxer frame buffer cannot allocate memory!\n" ++#define MSGTR_MuxbufReallocErr "Muxer frame buffer cannot reallocate memory!\n" ++#define MSGTR_MuxbufSending "Muxer frame buffer sending %d frame(s) to the muxer.\n" ++#define MSGTR_WritingHeader "Writing header...\n" ++#define MSGTR_WritingTrailer "Writing index...\n" ++ ++// demuxer.c, demux_*.c ++#define MSGTR_AudioStreamRedefined "WARNING: Audio stream header %d redefined.\n" ++#define MSGTR_VideoStreamRedefined "WARNING: Video stream header %d redefined.\n" ++#define MSGTR_TooManyAudioInBuffer "\nToo many audio packets in the buffer: (%d in %d bytes).\n" ++#define MSGTR_TooManyVideoInBuffer "\nToo many video packets in the buffer: (%d in %d bytes).\n" ++#define MSGTR_MaybeNI "Maybe you are playing a non-interleaved stream/file or the codec failed?\n" \ ++ "For AVI files, try to force non-interleaved mode with the -ni option.\n" ++#define MSGTR_WorkAroundBlockAlignHeaderBug "AVI: Working around CBR-MP3 nBlockAlign header bug!\n" ++#define MSGTR_SwitchToNi "\nBadly interleaved AVI file detected - switching to -ni mode...\n" ++#define MSGTR_InvalidAudioStreamNosound "AVI: invalid audio stream ID: %d - ignoring (nosound)\n" ++#define MSGTR_InvalidAudioStreamUsingDefault "AVI: invalid video stream ID: %d - ignoring (using default)\n" ++#define MSGTR_ON2AviFormat "ON2 AVI format" ++#define MSGTR_Detected_XXX_FileFormat "%s file format detected.\n" ++#define MSGTR_DetectedAudiofile "Audio file detected.\n" ++#define MSGTR_NotSystemStream "Not MPEG System Stream format... (maybe Transport Stream?)\n" ++#define MSGTR_InvalidMPEGES "Invalid MPEG-ES stream??? Contact the author, it may be a bug :(\n" ++#define MSGTR_FormatNotRecognized "============ Sorry, this file format is not recognized/supported =============\n"\ ++ "=== If this file is an AVI, ASF or MPEG stream, please contact the author! ===\n" ++#define MSGTR_SettingProcessPriority "Setting process priority: %s\n" ++#define MSGTR_FilefmtFourccSizeFpsFtime "[V] filefmt:%d fourcc:0x%X size:%dx%d fps:%5.3f ftime:=%6.4f\n" ++#define MSGTR_CannotInitializeMuxer "Cannot initialize muxer." ++#define MSGTR_MissingVideoStream "No video stream found.\n" ++#define MSGTR_MissingAudioStream "No audio stream found -> no sound.\n" ++#define MSGTR_MissingVideoStreamBug "Missing video stream!? Contact the author, it may be a bug :(\n" ++ ++#define MSGTR_DoesntContainSelectedStream "demux: File doesn't contain the selected audio or video stream.\n" ++ ++#define MSGTR_NI_Forced "Forced" ++#define MSGTR_NI_Detected "Detected" ++#define MSGTR_NI_Message "%s NON-INTERLEAVED AVI file format.\n" ++ ++#define MSGTR_UsingNINI "Using NON-INTERLEAVED broken AVI file format.\n" ++#define MSGTR_CouldntDetFNo "Could not determine number of frames (for absolute seek).\n" ++#define MSGTR_CantSeekRawAVI "Cannot seek in raw AVI streams. (Index required, try with the -idx switch.)\n" ++#define MSGTR_CantSeekFile "Cannot seek in this file.\n" ++ ++#define MSGTR_MOVcomprhdr "MOV: Compressed headers support requires ZLIB!\n" ++#define MSGTR_MOVvariableFourCC "MOV: WARNING: Variable FourCC detected!?\n" ++#define MSGTR_MOVtooManyTrk "MOV: WARNING: too many tracks" ++#define MSGTR_FoundAudioStream "==> Found audio stream: %d\n" ++#define MSGTR_FoundVideoStream "==> Found video stream: %d\n" ++#define MSGTR_DetectedTV "TV detected! ;-)\n" ++#define MSGTR_ErrorOpeningOGGDemuxer "Unable to open the Ogg demuxer.\n" ++#define MSGTR_ASFSearchingForAudioStream "ASF: Searching for audio stream (id:%d).\n" ++#define MSGTR_CannotOpenAudioStream "Cannot open audio stream: %s\n" ++#define MSGTR_CannotOpenSubtitlesStream "Cannot open subtitle stream: %s\n" ++#define MSGTR_OpeningAudioDemuxerFailed "Failed to open audio demuxer: %s\n" ++#define MSGTR_OpeningSubtitlesDemuxerFailed "Failed to open subtitle demuxer: %s\n" ++#define MSGTR_TVInputNotSeekable "TV input is not seekable! (Seeking will probably be for changing channels ;)\n" ++#define MSGTR_DemuxerInfoChanged "Demuxer info %s changed to %s\n" ++#define MSGTR_ClipInfo "Clip info:\n" ++ ++#define MSGTR_LeaveTelecineMode "\ndemux_mpg: 30000/1001fps NTSC content detected, switching framerate.\n" ++#define MSGTR_EnterTelecineMode "\ndemux_mpg: 24000/1001fps progressive NTSC content detected, switching framerate.\n" ++ ++#define MSGTR_CacheFill "\rCache fill: %5.2f%% (%"PRId64" bytes) " ++#define MSGTR_NoBindFound "No bind found for key '%s'." ++#define MSGTR_FailedToOpen "Failed to open %s.\n" ++ ++#define MSGTR_VideoID "[%s] Video stream found, -vid %d\n" ++#define MSGTR_AudioID "[%s] Audio stream found, -aid %d\n" ++#define MSGTR_SubtitleID "[%s] Subtitle stream found, -sid %d\n" ++ ++// asfheader.c ++#define MSGTR_MPDEMUX_ASFHDR_HeaderSizeOver1MB "FATAL: header size bigger than 1 MB (%d)!\nPlease contact MPlayer authors, and upload/send this file.\n" ++#define MSGTR_MPDEMUX_ASFHDR_HeaderMallocFailed "Could not allocate %d bytes for header.\n" ++#define MSGTR_MPDEMUX_ASFHDR_EOFWhileReadingHeader "EOF while reading ASF header, broken/incomplete file?\n" ++#define MSGTR_MPDEMUX_ASFHDR_DVRWantsLibavformat "DVR will probably only work with libavformat, try -demuxer 35 if you have problems\n" ++#define MSGTR_MPDEMUX_ASFHDR_NoDataChunkAfterHeader "No data chunk following header!\n" ++#define MSGTR_MPDEMUX_ASFHDR_AudioVideoHeaderNotFound "ASF: no audio or video headers found - broken file?\n" ++#define MSGTR_MPDEMUX_ASFHDR_InvalidLengthInASFHeader "Invalid length in ASF header!\n" ++#define MSGTR_MPDEMUX_ASFHDR_DRMLicenseURL "DRM License URL: %s\n" ++#define MSGTR_MPDEMUX_ASFHDR_DRMProtected "This file has been encumbered with DRM encryption, it will not play in MPlayer!\n" ++ ++// aviheader.c ++#define MSGTR_MPDEMUX_AVIHDR_EmptyList "** empty list?!\n" ++#define MSGTR_MPDEMUX_AVIHDR_FoundMovieAt "Found movie at 0x%X - 0x%X\n" ++#define MSGTR_MPDEMUX_AVIHDR_FoundBitmapInfoHeader "Found 'bih', %u bytes of %d\n" ++#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPG4V1 "Regenerating keyframe table for M$ mpg4v1 video.\n" ++#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForDIVX3 "Regenerating keyframe table for DIVX3 video.\n" ++#define MSGTR_MPDEMUX_AVIHDR_RegeneratingKeyfTableForMPEG4 "Regenerating keyframe table for MPEG-4 video.\n" ++#define MSGTR_MPDEMUX_AVIHDR_FoundWaveFmt "Found 'wf', %d bytes of %d\n" ++#define MSGTR_MPDEMUX_AVIHDR_FoundAVIV2Header "AVI: dmlh found (size=%d) (total_frames=%d)\n" ++#define MSGTR_MPDEMUX_AVIHDR_ReadingIndexBlockChunksForFrames "Reading INDEX block, %d chunks for %d frames (fpos=%"PRId64").\n" ++#define MSGTR_MPDEMUX_AVIHDR_AdditionalRIFFHdr "Additional RIFF header...\n" ++#define MSGTR_MPDEMUX_AVIHDR_WarnNotExtendedAVIHdr "** Warning: this is no extended AVI header..\n" ++#define MSGTR_MPDEMUX_AVIHDR_BrokenChunk "Broken chunk? chunksize=%d (id=%.4s)\n" ++#define MSGTR_MPDEMUX_AVIHDR_BuildingODMLidx "AVI: ODML: Building ODML index (%d superindexchunks).\n" ++#define MSGTR_MPDEMUX_AVIHDR_BrokenODMLfile "AVI: ODML: Broken (incomplete?) file detected. Will use traditional index.\n" ++#define MSGTR_MPDEMUX_AVIHDR_CantReadIdxFile "Can't read index file %s: %s\n" ++#define MSGTR_MPDEMUX_AVIHDR_NotValidMPidxFile "%s is not a valid MPlayer index file.\n" ++#define MSGTR_MPDEMUX_AVIHDR_FailedMallocForIdxFile "Could not allocate memory for index data from %s.\n" ++#define MSGTR_MPDEMUX_AVIHDR_PrematureEOF "premature end of index file %s\n" ++#define MSGTR_MPDEMUX_AVIHDR_IdxFileLoaded "Loaded index file: %s\n" ++#define MSGTR_MPDEMUX_AVIHDR_GeneratingIdx "Generating Index: %3lu %s \r" ++#define MSGTR_MPDEMUX_AVIHDR_IdxGeneratedForHowManyChunks "AVI: Generated index table for %d chunks!\n" ++#define MSGTR_MPDEMUX_AVIHDR_Failed2WriteIdxFile "Couldn't write index file %s: %s\n" ++#define MSGTR_MPDEMUX_AVIHDR_IdxFileSaved "Saved index file: %s\n" ++ ++// demux_audio.c ++#define MSGTR_MPDEMUX_AUDIO_UnknownFormat "Audio demuxer: unknown format %d.\n" ++ ++// demux_demuxers.c ++#define MSGTR_MPDEMUX_DEMUXERS_FillBufferError "fill_buffer error: bad demuxer: not vd, ad or sd.\n" ++ ++// demux_mkv.c ++#define MSGTR_MPDEMUX_MKV_ZlibInitializationFailed "[mkv] zlib initialization failed.\n" ++#define MSGTR_MPDEMUX_MKV_ZlibDecompressionFailed "[mkv] zlib decompression failed.\n" ++#define MSGTR_MPDEMUX_MKV_LzoInitializationFailed "[mkv] lzo initialization failed.\n" ++#define MSGTR_MPDEMUX_MKV_LzoDecompressionFailed "[mkv] lzo decompression failed.\n" ++#define MSGTR_MPDEMUX_MKV_TrackEncrypted "[mkv] Track number %u has been encrypted and decryption has not yet been\n[mkv] implemented. Skipping track.\n" ++#define MSGTR_MPDEMUX_MKV_UnknownContentEncoding "[mkv] Unknown content encoding type for track %u. Skipping track.\n" ++#define MSGTR_MPDEMUX_MKV_UnknownCompression "[mkv] Track %u has been compressed with an unknown/unsupported compression\n[mkv] algorithm (%u). Skipping track.\n" ++#define MSGTR_MPDEMUX_MKV_ZlibCompressionUnsupported "[mkv] Track %u was compressed with zlib but mplayer has not been compiled\n[mkv] with support for zlib compression. Skipping track.\n" ++#define MSGTR_MPDEMUX_MKV_TrackIDName "[mkv] Track ID %u: %s (%s) \"%s\", %s\n" ++#define MSGTR_MPDEMUX_MKV_TrackID "[mkv] Track ID %u: %s (%s), %s\n" ++#define MSGTR_MPDEMUX_MKV_UnknownCodecID "[mkv] Unknown/unsupported CodecID (%s) or missing/bad CodecPrivate\n[mkv] data (track %u).\n" ++#define MSGTR_MPDEMUX_MKV_FlacTrackDoesNotContainValidHeaders "[mkv] FLAC track does not contain valid headers.\n" ++#define MSGTR_MPDEMUX_MKV_UnknownAudioCodec "[mkv] Unknown/unsupported audio codec ID '%s' for track %u or missing/faulty\n[mkv] private codec data.\n" ++#define MSGTR_MPDEMUX_MKV_SubtitleTypeNotSupported "[mkv] Subtitle type '%s' is not supported.\n" ++#define MSGTR_MPDEMUX_MKV_WillPlayVideoTrack "[mkv] Will play video track %u.\n" ++#define MSGTR_MPDEMUX_MKV_NoVideoTrackFound "[mkv] No video track found/wanted.\n" ++#define MSGTR_MPDEMUX_MKV_NoAudioTrackFound "[mkv] No audio track found/wanted.\n" ++#define MSGTR_MPDEMUX_MKV_WillDisplaySubtitleTrack "[mkv] Will display subtitle track %u.\n" ++#define MSGTR_MPDEMUX_MKV_NoBlockDurationForSubtitleTrackFound "[mkv] Warning: No BlockDuration for subtitle track found.\n" ++#define MSGTR_MPDEMUX_MKV_TooManySublines "[mkv] Warning: too many sublines to render, skipping.\n" ++#define MSGTR_MPDEMUX_MKV_TooManySublinesSkippingAfterFirst "\n[mkv] Warning: too many sublines to render, skipping after first %i.\n" ++ ++// demux_nuv.c ++#define MSGTR_MPDEMUX_NUV_NoVideoBlocksInFile "No video blocks in file.\n" ++ ++// demux_xmms.c ++#define MSGTR_MPDEMUX_XMMS_FoundPlugin "Found plugin: %s (%s).\n" ++#define MSGTR_MPDEMUX_XMMS_ClosingPlugin "Closing plugin: %s.\n" ++#define MSGTR_MPDEMUX_XMMS_WaitForStart "Waiting for the XMMS plugin to start playback of '%s'...\n" ++ ++ ++// ========================== LIBMENU =================================== ++ ++// common ++#define MSGTR_LIBMENU_NoEntryFoundInTheMenuDefinition "[MENU] No entry found in the menu definition.\n" ++ ++// libmenu/menu.c ++#define MSGTR_LIBMENU_SyntaxErrorAtLine "[MENU] syntax error at line: %d\n" ++#define MSGTR_LIBMENU_MenuDefinitionsNeedANameAttrib "[MENU] Menu definitions need a name attribute (line %d).\n" ++#define MSGTR_LIBMENU_BadAttrib "[MENU] bad attribute %s=%s in menu '%s' at line %d\n" ++#define MSGTR_LIBMENU_UnknownMenuType "[MENU] unknown menu type '%s' at line %d\n" ++#define MSGTR_LIBMENU_CantOpenConfigFile "[MENU] Can't open menu config file: %s\n" ++#define MSGTR_LIBMENU_ConfigFileIsTooBig "[MENU] Config file is too big (> %d KB)\n" ++#define MSGTR_LIBMENU_ConfigFileIsEmpty "[MENU] Config file is empty.\n" ++#define MSGTR_LIBMENU_MenuNotFound "[MENU] Menu %s not found.\n" ++#define MSGTR_LIBMENU_MenuInitFailed "[MENU] Menu '%s': Init failed.\n" ++#define MSGTR_LIBMENU_UnsupportedOutformat "[MENU] Unsupported output format!!!!\n" ++ ++// libmenu/menu_cmdlist.c ++#define MSGTR_LIBMENU_ListMenuEntryDefinitionsNeedAName "[MENU] List menu entry definitions need a name (line %d).\n" ++#define MSGTR_LIBMENU_ListMenuNeedsAnArgument "[MENU] List menu needs an argument.\n" ++ ++// libmenu/menu_console.c ++#define MSGTR_LIBMENU_WaitPidError "[MENU] Waitpid error: %s.\n" ++#define MSGTR_LIBMENU_SelectError "[MENU] Select error.\n" ++#define MSGTR_LIBMENU_ReadErrorOnChildFD "[MENU] Read error on child's file descriptor: %s.\n" ++#define MSGTR_LIBMENU_ConsoleRun "[MENU] Console run: %s ...\n" ++#define MSGTR_LIBMENU_AChildIsAlreadyRunning "[MENU] A child is already running.\n" ++#define MSGTR_LIBMENU_ForkFailed "[MENU] Fork failed !!!\n" ++#define MSGTR_LIBMENU_WriteError "[MENU] write error\n" ++ ++// libmenu/menu_filesel.c ++#define MSGTR_LIBMENU_OpendirError "[MENU] opendir error: %s\n" ++#define MSGTR_LIBMENU_ReallocError "[MENU] realloc error: %s\n" ++#define MSGTR_LIBMENU_MallocError "[MENU] memory allocation error: %s\n" ++#define MSGTR_LIBMENU_ReaddirError "[MENU] readdir error: %s\n" ++#define MSGTR_LIBMENU_CantOpenDirectory "[MENU] Can't open directory %s.\n" ++ ++// libmenu/menu_param.c ++#define MSGTR_LIBMENU_SubmenuDefinitionNeedAMenuAttribut "[MENU] Submenu definition needs a 'menu' attribute.\n" ++#define MSGTR_LIBMENU_InvalidProperty "[MENU] Invalid property '%s' in pref menu entry. (line %d).\n" ++#define MSGTR_LIBMENU_PrefMenuEntryDefinitionsNeed "[MENU] Pref menu entry definitions need a valid 'property' or 'txt' attribute (line %d).\n" ++#define MSGTR_LIBMENU_PrefMenuNeedsAnArgument "[MENU] Pref menu needs an argument.\n" ++ ++// libmenu/menu_pt.c ++#define MSGTR_LIBMENU_CantfindTheTargetItem "[MENU] Can't find the target item ????\n" ++#define MSGTR_LIBMENU_FailedToBuildCommand "[MENU] Failed to build command: %s.\n" ++ ++// libmenu/menu_txt.c ++#define MSGTR_LIBMENU_MenuTxtNeedATxtFileName "[MENU] Text menu needs a textfile name (parameter file).\n" ++#define MSGTR_LIBMENU_MenuTxtCantOpen "[MENU] Can't open %s.\n" ++#define MSGTR_LIBMENU_WarningTooLongLineSplitting "[MENU] Warning, line too long. Splitting it.\n" ++#define MSGTR_LIBMENU_ParsedLines "[MENU] Parsed %d lines.\n" ++ ++// libmenu/vf_menu.c ++#define MSGTR_LIBMENU_UnknownMenuCommand "[MENU] Unknown command: '%s'.\n" ++#define MSGTR_LIBMENU_FailedToOpenMenu "[MENU] Failed to open menu: '%s'.\n" ++ ++ ++// ========================== LIBMPCODECS =================================== ++ ++// dec_video.c & dec_audio.c: ++#define MSGTR_CantOpenCodec "Could not open codec.\n" ++#define MSGTR_CantCloseCodec "Could not close codec.\n" ++ ++#define MSGTR_MissingDLLcodec "ERROR: Could not open required DirectShow codec %s.\n" ++#define MSGTR_ACMiniterror "Could not load/initialize Win32/ACM audio codec (missing DLL file?).\n" ++#define MSGTR_MissingLAVCcodec "Cannot find codec '%s' in libavcodec...\n" ++ ++#define MSGTR_MpegNoSequHdr "MPEG: FATAL: EOF while searching for sequence header.\n" ++#define MSGTR_CannotReadMpegSequHdr "FATAL: Cannot read sequence header.\n" ++#define MSGTR_CannotReadMpegSequHdrEx "FATAL: Cannot read sequence header extension.\n" ++#define MSGTR_BadMpegSequHdr "MPEG: bad sequence header\n" ++#define MSGTR_BadMpegSequHdrEx "MPEG: bad sequence header extension\n" ++ ++#define MSGTR_ShMemAllocFail "Cannot allocate shared memory.\n" ++#define MSGTR_CantAllocAudioBuf "Cannot allocate audio out buffer.\n" ++ ++#define MSGTR_UnknownAudio "Unknown/missing audio format -> no sound\n" ++ ++#define MSGTR_UsingExternalPP "[PP] Using external postprocessing filter, max q = %d.\n" ++#define MSGTR_UsingCodecPP "[PP] Using codec's postprocessing, max q = %d.\n" ++#define MSGTR_VideoAttributeNotSupportedByVO_VD "Video attribute '%s' is not supported by selected vo & vd.\n" ++#define MSGTR_VideoCodecFamilyNotAvailableStr "Requested video codec family [%s] (vfm=%s) not available.\nEnable it at compilation.\n" ++#define MSGTR_AudioCodecFamilyNotAvailableStr "Requested audio codec family [%s] (afm=%s) not available.\nEnable it at compilation.\n" ++#define MSGTR_OpeningVideoDecoder "Opening video decoder: [%s] %s\n" ++#define MSGTR_SelectedVideoCodec "Selected video codec: [%s] vfm: %s (%s)\n" ++#define MSGTR_OpeningAudioDecoder "Opening audio decoder: [%s] %s\n" ++#define MSGTR_SelectedAudioCodec "Selected audio codec: [%s] afm: %s (%s)\n" ++#define MSGTR_BuildingAudioFilterChain "Building audio filter chain for %dHz/%dch/%s -> %dHz/%dch/%s...\n" ++#define MSGTR_UninitVideoStr "Uninit video: %s\n" ++#define MSGTR_UninitAudioStr "Uninit audio: %s\n" ++#define MSGTR_VDecoderInitFailed "VDecoder init failed :(\n" ++#define MSGTR_ADecoderInitFailed "ADecoder init failed :(\n" ++#define MSGTR_ADecoderPreinitFailed "ADecoder preinit failed :(\n" ++#define MSGTR_AllocatingBytesForInputBuffer "dec_audio: Allocating %d bytes for input buffer.\n" ++#define MSGTR_AllocatingBytesForOutputBuffer "dec_audio: Allocating %d + %d = %d bytes for output buffer.\n" ++ ++// ad_dvdpcm.c: ++#define MSGTR_SamplesWanted "Samples of this format are needed to improve support. Please contact the developers.\n" ++ ++// libmpcodecs/ad_libdv.c ++#define MSGTR_MPCODECS_AudioFramesizeDiffers "[AD_LIBDV] Warning! Audio framesize differs! read=%d hdr=%d.\n" ++ ++// vd.c ++#define MSGTR_CodecDidNotSet "VDec: Codec did not set sh->disp_w and sh->disp_h, trying workaround.\n" ++#define MSGTR_CouldNotFindColorspace "Could not find matching colorspace - retrying with -vf scale...\n" ++#define MSGTR_MovieAspectIsSet "Movie-Aspect is %.2f:1 - prescaling to correct movie aspect.\n" ++#define MSGTR_MovieAspectUndefined "Movie-Aspect is undefined - no prescaling applied.\n" ++ ++// vd_dshow.c, vd_dmo.c ++#define MSGTR_DownloadCodecPackage "You need to upgrade/install the binary codecs package.\nGo to http://www.mplayerhq.hu/dload.html\n" ++#define MSGTR_DShowInitOK "INFO: Win32/DShow video codec init OK.\n" ++#define MSGTR_DMOInitOK "INFO: Win32/DMO video codec init OK.\n" ++ ++// libmpcodecs/vd_dmo.c vd_dshow.c vd_vfw.c ++#define MSGTR_MPCODECS_CouldntAllocateImageForCinepakCodec "[VD_DMO] Couldn't allocate image for cinepak codec.\n" ++ ++// libmpcodecs/vd_ffmpeg.c ++#define MSGTR_MPCODECS_XVMCAcceleratedCodec "[VD_FFMPEG] XVMC accelerated codec.\n" ++#define MSGTR_MPCODECS_ArithmeticMeanOfQP "[VD_FFMPEG] Arithmetic mean of QP: %2.4f, Harmonic mean of QP: %2.4f\n" ++#define MSGTR_MPCODECS_DRIFailure "[VD_FFMPEG] DRI failure.\n" ++#define MSGTR_MPCODECS_CouldntAllocateImageForCodec "[VD_FFMPEG] Couldn't allocate image for codec.\n" ++#define MSGTR_MPCODECS_XVMCAcceleratedMPEG2 "[VD_FFMPEG] XVMC-accelerated MPEG-2.\n" ++#define MSGTR_MPCODECS_TryingPixfmt "[VD_FFMPEG] Trying pixfmt=%d.\n" ++#define MSGTR_MPCODECS_McGetBufferShouldWorkOnlyWithXVMC "[VD_FFMPEG] The mc_get_buffer should work only with XVMC acceleration!!" ++#define MSGTR_MPCODECS_UnexpectedInitVoError "[VD_FFMPEG] Unexpected init_vo error.\n" ++#define MSGTR_MPCODECS_UnrecoverableErrorRenderBuffersNotTaken "[VD_FFMPEG] Unrecoverable error, render buffers not taken.\n" ++#define MSGTR_MPCODECS_OnlyBuffersAllocatedByVoXvmcAllowed "[VD_FFMPEG] Only buffers allocated by vo_xvmc allowed.\n" ++ ++// libmpcodecs/ve_lavc.c ++#define MSGTR_MPCODECS_HighQualityEncodingSelected "[VE_LAVC] High quality encoding selected (non-realtime)!\n" ++#define MSGTR_MPCODECS_UsingConstantQscale "[VE_LAVC] Using constant qscale = %f (VBR).\n" ++ ++// libmpcodecs/ve_raw.c ++#define MSGTR_MPCODECS_OutputWithFourccNotSupported "[VE_RAW] Raw output with FourCC [%x] not supported!\n" ++#define MSGTR_MPCODECS_NoVfwCodecSpecified "[VE_RAW] Required VfW codec not specified!!\n" ++ ++// vf.c ++#define MSGTR_CouldNotFindVideoFilter "Couldn't find video filter '%s'.\n" ++#define MSGTR_CouldNotOpenVideoFilter "Couldn't open video filter '%s'.\n" ++#define MSGTR_OpeningVideoFilter "Opening video filter: " ++#define MSGTR_CannotFindColorspace "Cannot find matching colorspace, even by inserting 'scale' :(\n" ++ ++// libmpcodecs/vf_crop.c ++#define MSGTR_MPCODECS_CropBadPositionWidthHeight "[CROP] Bad position/width/height - cropped area outside of the original!\n" ++ ++// libmpcodecs/vf_cropdetect.c ++#define MSGTR_MPCODECS_CropArea "[CROP] Crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d).\n" ++ ++// libmpcodecs/vf_format.c, vf_palette.c, vf_noformat.c ++#define MSGTR_MPCODECS_UnknownFormatName "[VF_FORMAT] Unknown format name: '%s'.\n" ++ ++// libmpcodecs/vf_framestep.c vf_noformat.c vf_palette.c vf_tile.c ++#define MSGTR_MPCODECS_ErrorParsingArgument "[VF_FRAMESTEP] Error parsing argument.\n" ++ ++// libmpcodecs/ve_vfw.c ++#define MSGTR_MPCODECS_CompressorType "Compressor type: %.4lx\n" ++#define MSGTR_MPCODECS_CompressorSubtype "Compressor subtype: %.4lx\n" ++#define MSGTR_MPCODECS_CompressorFlags "Compressor flags: %lu, version %lu, ICM version: %lu\n" ++#define MSGTR_MPCODECS_Flags "Flags:" ++#define MSGTR_MPCODECS_Quality " quality" ++ ++// libmpcodecs/vf_expand.c ++#define MSGTR_MPCODECS_FullDRNotPossible "Full DR not possible, trying SLICES instead!\n" ++#define MSGTR_MPCODECS_WarnNextFilterDoesntSupportSlices "WARNING! Next filter doesn't support SLICES, get ready for sig11...\n" ++#define MSGTR_MPCODECS_FunWhydowegetNULL "Why do we get NULL??\n" ++ ++// libmpcodecs/vf_test.c, vf_yuy2.c, vf_yvu9.c ++#define MSGTR_MPCODECS_WarnNextFilterDoesntSupport "%s not supported by next filter/vo :(\n" ++ ++ ++// ================================== LIBASS ==================================== ++ ++// ass_bitmap.c ++#define MSGTR_LIBASS_FT_Glyph_To_BitmapError "[ass] FT_Glyph_To_Bitmap error %d \n" ++#define MSGTR_LIBASS_UnsupportedPixelMode "[ass] Unsupported pixel mode: %d\n" ++#define MSGTR_LIBASS_GlyphBBoxTooLarge "[ass] Glyph bounding box too large: %dx%dpx\n" ++ ++// ass.c ++#define MSGTR_LIBASS_NoStyleNamedXFoundUsingY "[ass] [%p] Warning: no style named '%s' found, using '%s'\n" ++#define MSGTR_LIBASS_BadTimestamp "[ass] bad timestamp\n" ++#define MSGTR_LIBASS_BadEncodedDataSize "[ass] bad encoded data size\n" ++#define MSGTR_LIBASS_FontLineTooLong "[ass] Font line too long: %d, %s\n" ++#define MSGTR_LIBASS_EventFormatHeaderMissing "[ass] Event format header missing\n" ++#define MSGTR_LIBASS_ErrorOpeningIconvDescriptor "[ass] error opening iconv descriptor.\n" ++#define MSGTR_LIBASS_ErrorRecodingFile "[ass] error recoding file.\n" ++#define MSGTR_LIBASS_FopenFailed "[ass] ass_read_file(%s): fopen failed\n" ++#define MSGTR_LIBASS_FseekFailed "[ass] ass_read_file(%s): fseek failed\n" ++#define MSGTR_LIBASS_RefusingToLoadSubtitlesLargerThan100M "[ass] ass_read_file(%s): Refusing to load subtitles larger than 100M\n" ++#define MSGTR_LIBASS_ReadFailed "Read failed, %d: %s\n" ++#define MSGTR_LIBASS_AddedSubtitleFileMemory "[ass] Added subtitle file: (%d styles, %d events)\n" ++#define MSGTR_LIBASS_AddedSubtitleFileFname "[ass] Added subtitle file: %s (%d styles, %d events)\n" ++#define MSGTR_LIBASS_FailedToCreateDirectory "[ass] Failed to create directory %s\n" ++#define MSGTR_LIBASS_NotADirectory "[ass] Not a directory: %s\n" ++ ++// ass_cache.c ++#define MSGTR_LIBASS_TooManyFonts "[ass] Too many fonts\n" ++#define MSGTR_LIBASS_ErrorOpeningFont "[ass] Error opening font: %s, %d\n" ++ ++// ass_fontconfig.c ++#define MSGTR_LIBASS_SelectedFontFamilyIsNotTheRequestedOne "[ass] fontconfig: Selected font is not the requested one: '%s' != '%s'\n" ++#define MSGTR_LIBASS_UsingDefaultFontFamily "[ass] fontconfig_select: Using default font family: (%s, %d, %d) -> %s, %d\n" ++#define MSGTR_LIBASS_UsingDefaultFont "[ass] fontconfig_select: Using default font: (%s, %d, %d) -> %s, %d\n" ++#define MSGTR_LIBASS_UsingArialFontFamily "[ass] fontconfig_select: Using 'Arial' font family: (%s, %d, %d) -> %s, %d\n" ++#define MSGTR_LIBASS_FcInitLoadConfigAndFontsFailed "[ass] FcInitLoadConfigAndFonts failed.\n" ++#define MSGTR_LIBASS_UpdatingFontCache "[ass] Updating font cache.\n" ++#define MSGTR_LIBASS_BetaVersionsOfFontconfigAreNotSupported "[ass] Beta versions of fontconfig are not supported.\n[ass] Update before reporting any bugs.\n" ++#define MSGTR_LIBASS_FcStrSetAddFailed "[ass] FcStrSetAdd failed.\n" ++#define MSGTR_LIBASS_FcDirScanFailed "[ass] FcDirScan failed.\n" ++#define MSGTR_LIBASS_FcDirSave "[ass] FcDirSave failed.\n" ++#define MSGTR_LIBASS_FcConfigAppFontAddDirFailed "[ass] FcConfigAppFontAddDir failed\n" ++#define MSGTR_LIBASS_FontconfigDisabledDefaultFontWillBeUsed "[ass] Fontconfig disabled, only default font will be used.\n" ++#define MSGTR_LIBASS_FunctionCallFailed "[ass] %s failed\n" ++ ++// ass_render.c ++#define MSGTR_LIBASS_NeitherPlayResXNorPlayResYDefined "[ass] Neither PlayResX nor PlayResY defined. Assuming 384x288.\n" ++#define MSGTR_LIBASS_PlayResYUndefinedSettingY "[ass] PlayResY undefined, setting %d.\n" ++#define MSGTR_LIBASS_PlayResXUndefinedSettingX "[ass] PlayResX undefined, setting %d.\n" ++#define MSGTR_LIBASS_FT_Init_FreeTypeFailed "[ass] FT_Init_FreeType failed.\n" ++#define MSGTR_LIBASS_Init "[ass] Init\n" ++#define MSGTR_LIBASS_InitFailed "[ass] Init failed.\n" ++#define MSGTR_LIBASS_BadCommand "[ass] Bad command: %c%c\n" ++#define MSGTR_LIBASS_ErrorLoadingGlyph "[ass] Error loading glyph.\n" ++#define MSGTR_LIBASS_FT_Glyph_Stroke_Error "[ass] FT_Glyph_Stroke error %d \n" ++#define MSGTR_LIBASS_UnknownEffectType_InternalError "[ass] Unknown effect type (internal error)\n" ++#define MSGTR_LIBASS_NoStyleFound "[ass] No style found!\n" ++#define MSGTR_LIBASS_EmptyEvent "[ass] Empty event!\n" ++#define MSGTR_LIBASS_MAX_GLYPHS_Reached "[ass] MAX_GLYPHS reached: event %d, start = %llu, duration = %llu\n Text = %s\n" ++#define MSGTR_LIBASS_EventHeightHasChanged "[ass] Warning! Event height has changed! \n" ++ ++// ass_font.c ++#define MSGTR_LIBASS_GlyphNotFoundReselectingFont "[ass] Glyph 0x%X not found, selecting one more font for (%s, %d, %d)\n" ++#define MSGTR_LIBASS_GlyphNotFound "[ass] Glyph 0x%X not found in font for (%s, %d, %d)\n" ++#define MSGTR_LIBASS_ErrorOpeningMemoryFont "[ass] Error opening memory font: %s\n" ++#define MSGTR_LIBASS_NoCharmaps "[ass] font face with no charmaps\n" ++#define MSGTR_LIBASS_NoCharmapAutodetected "[ass] no charmap autodetected, trying the first one\n" ++ ++ ++// ================================== stream ==================================== ++ ++// ai_alsa1x.c ++#define MSGTR_MPDEMUX_AIALSA1X_CannotSetSamplerate "Cannot set samplerate.\n" ++#define MSGTR_MPDEMUX_AIALSA1X_CannotSetBufferTime "Cannot set buffer time.\n" ++#define MSGTR_MPDEMUX_AIALSA1X_CannotSetPeriodTime "Cannot set period time.\n" ++ ++// ai_alsa1x.c / ai_alsa.c ++#define MSGTR_MPDEMUX_AIALSA_PcmBrokenConfig "Broken configuration for this PCM: no configurations available.\n" ++#define MSGTR_MPDEMUX_AIALSA_UnavailableAccessType "Access type not available.\n" ++#define MSGTR_MPDEMUX_AIALSA_UnavailableSampleFmt "Sample format not available.\n" ++#define MSGTR_MPDEMUX_AIALSA_UnavailableChanCount "Channel count not available - reverting to default: %d\n" ++#define MSGTR_MPDEMUX_AIALSA_CannotInstallHWParams "Unable to install hardware parameters: %s" ++#define MSGTR_MPDEMUX_AIALSA_PeriodEqualsBufferSize "Can't use period equal to buffer size (%u == %lu)\n" ++#define MSGTR_MPDEMUX_AIALSA_CannotInstallSWParams "Unable to install software parameters:\n" ++#define MSGTR_MPDEMUX_AIALSA_ErrorOpeningAudio "Error opening audio: %s\n" ++#define MSGTR_MPDEMUX_AIALSA_AlsaStatusError "ALSA status error: %s" ++#define MSGTR_MPDEMUX_AIALSA_AlsaXRUN "ALSA xrun!!! (at least %.3f ms long)\n" ++#define MSGTR_MPDEMUX_AIALSA_AlsaStatus "ALSA Status:\n" ++#define MSGTR_MPDEMUX_AIALSA_AlsaXRUNPrepareError "ALSA xrun: prepare error: %s" ++#define MSGTR_MPDEMUX_AIALSA_AlsaReadWriteError "ALSA read/write error" ++ ++// ai_oss.c ++#define MSGTR_MPDEMUX_AIOSS_Unable2SetChanCount "Unable to set channel count: %d\n" ++#define MSGTR_MPDEMUX_AIOSS_Unable2SetStereo "Unable to set stereo: %d\n" ++#define MSGTR_MPDEMUX_AIOSS_Unable2Open "Unable to open '%s': %s\n" ++#define MSGTR_MPDEMUX_AIOSS_UnsupportedFmt "unsupported format\n" ++#define MSGTR_MPDEMUX_AIOSS_Unable2SetAudioFmt "Unable to set audio format." ++#define MSGTR_MPDEMUX_AIOSS_Unable2SetSamplerate "Unable to set samplerate: %d\n" ++#define MSGTR_MPDEMUX_AIOSS_Unable2SetTrigger "Unable to set trigger: %d\n" ++#define MSGTR_MPDEMUX_AIOSS_Unable2GetBlockSize "Unable to get block size!\n" ++#define MSGTR_MPDEMUX_AIOSS_AudioBlockSizeZero "Audio block size is zero, setting to %d!\n" ++#define MSGTR_MPDEMUX_AIOSS_AudioBlockSize2Low "Audio block size too low, setting to %d!\n" ++ ++// asf_mmst_streaming.c ++#define MSGTR_MPDEMUX_MMST_WriteError "write error\n" ++#define MSGTR_MPDEMUX_MMST_EOFAlert "\nAlert! EOF\n" ++#define MSGTR_MPDEMUX_MMST_PreHeaderReadFailed "pre-header read failed\n" ++#define MSGTR_MPDEMUX_MMST_InvalidHeaderSize "Invalid header size, giving up.\n" ++#define MSGTR_MPDEMUX_MMST_HeaderDataReadFailed "Header data read failed.\n" ++#define MSGTR_MPDEMUX_MMST_packet_lenReadFailed "packet_len read failed.\n" ++#define MSGTR_MPDEMUX_MMST_InvalidRTSPPacketSize "Invalid RTSP packet size, giving up.\n" ++#define MSGTR_MPDEMUX_MMST_CmdDataReadFailed "Command data read failed.\n" ++#define MSGTR_MPDEMUX_MMST_HeaderObject "header object\n" ++#define MSGTR_MPDEMUX_MMST_DataObject "data object\n" ++#define MSGTR_MPDEMUX_MMST_FileObjectPacketLen "file object, packet length = %d (%d)\n" ++#define MSGTR_MPDEMUX_MMST_StreamObjectStreamID "stream object, stream ID: %d\n" ++#define MSGTR_MPDEMUX_MMST_2ManyStreamID "Too many IDs, stream skipped." ++#define MSGTR_MPDEMUX_MMST_UnknownObject "unknown object\n" ++#define MSGTR_MPDEMUX_MMST_MediaDataReadFailed "Media data read failed.\n" ++#define MSGTR_MPDEMUX_MMST_MissingSignature "missing signature\n" ++#define MSGTR_MPDEMUX_MMST_PatentedTechnologyJoke "Everything done. Thank you for downloading a media file containing proprietary and patented technology.\n" ++#define MSGTR_MPDEMUX_MMST_UnknownCmd "unknown command %02x\n" ++#define MSGTR_MPDEMUX_MMST_GetMediaPacketErr "get_media_packet error : %s\n" ++#define MSGTR_MPDEMUX_MMST_Connected "Connected\n" ++ ++// asf_streaming.c ++#define MSGTR_MPDEMUX_ASF_StreamChunkSize2Small "Ahhhh, stream_chunck size is too small: %d\n" ++#define MSGTR_MPDEMUX_ASF_SizeConfirmMismatch "size_confirm mismatch!: %d %d\n" ++#define MSGTR_MPDEMUX_ASF_WarnDropHeader "Warning: drop header ????\n" ++#define MSGTR_MPDEMUX_ASF_ErrorParsingChunkHeader "Error while parsing chunk header\n" ++#define MSGTR_MPDEMUX_ASF_NoHeaderAtFirstChunk "Didn't get a header as first chunk !!!!\n" ++#define MSGTR_MPDEMUX_ASF_BufferMallocFailed "Error: Can't allocate %d bytes buffer.\n" ++#define MSGTR_MPDEMUX_ASF_ErrReadingNetworkStream "Error while reading network stream.\n" ++#define MSGTR_MPDEMUX_ASF_ErrChunk2Small "Error: Chunk is too small.\n" ++#define MSGTR_MPDEMUX_ASF_ErrSubChunkNumberInvalid "Error: Subchunk number is invalid.\n" ++#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallCannotPlay "Bandwidth too small, file cannot be played!\n" ++#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedAudio "Bandwidth too small, deselected audio stream.\n" ++#define MSGTR_MPDEMUX_ASF_Bandwidth2SmallDeselectedVideo "Bandwidth too small, deselected video stream.\n" ++#define MSGTR_MPDEMUX_ASF_InvalidLenInHeader "Invalid length in ASF header!\n" ++#define MSGTR_MPDEMUX_ASF_ErrReadingChunkHeader "Error while reading chunk header.\n" ++#define MSGTR_MPDEMUX_ASF_ErrChunkBiggerThanPacket "Error: chunk_size > packet_size\n" ++#define MSGTR_MPDEMUX_ASF_ErrReadingChunk "Error while reading chunk.\n" ++#define MSGTR_MPDEMUX_ASF_ASFRedirector "=====> ASF Redirector\n" ++#define MSGTR_MPDEMUX_ASF_InvalidProxyURL "invalid proxy URL\n" ++#define MSGTR_MPDEMUX_ASF_UnknownASFStreamType "unknown ASF stream type\n" ++#define MSGTR_MPDEMUX_ASF_Failed2ParseHTTPResponse "Failed to parse HTTP response.\n" ++#define MSGTR_MPDEMUX_ASF_ServerReturn "Server returned %d:%s\n" ++#define MSGTR_MPDEMUX_ASF_ASFHTTPParseWarnCuttedPragma "ASF HTTP PARSE WARNING : Pragma %s cut from %zd bytes to %d\n" ++#define MSGTR_MPDEMUX_ASF_SocketWriteError "socket write error: %s\n" ++#define MSGTR_MPDEMUX_ASF_HeaderParseFailed "Failed to parse header.\n" ++#define MSGTR_MPDEMUX_ASF_NoStreamFound "No stream found.\n" ++#define MSGTR_MPDEMUX_ASF_UnknownASFStreamingType "unknown ASF streaming type\n" ++#define MSGTR_MPDEMUX_ASF_InfoStreamASFURL "STREAM_ASF, URL: %s\n" ++#define MSGTR_MPDEMUX_ASF_StreamingFailed "Failed, exiting.\n" ++ ++// audio_in.c ++#define MSGTR_MPDEMUX_AUDIOIN_ErrReadingAudio "\nError reading audio: %s\n" ++#define MSGTR_MPDEMUX_AUDIOIN_XRUNSomeFramesMayBeLeftOut "Recovered from cross-run, some frames may be left out!\n" ++#define MSGTR_MPDEMUX_AUDIOIN_ErrFatalCannotRecover "Fatal error, cannot recover!\n" ++#define MSGTR_MPDEMUX_AUDIOIN_NotEnoughSamples "\nNot enough audio samples!\n" ++ ++// cache2.c ++#define MSGTR_MPDEMUX_CACHE2_NonCacheableStream "\rThis stream is non-cacheable.\n" ++#define MSGTR_MPDEMUX_CACHE2_ReadFileposDiffers "!!! read_filepos differs!!! Report this bug...\n" ++ ++// network.c ++#define MSGTR_MPDEMUX_NW_UnknownAF "Unknown address family %d\n" ++#define MSGTR_MPDEMUX_NW_ResolvingHostForAF "Resolving %s for %s...\n" ++#define MSGTR_MPDEMUX_NW_CantResolv "Couldn't resolve name for %s: %s\n" ++#define MSGTR_MPDEMUX_NW_ConnectingToServer "Connecting to server %s[%s]: %d...\n" ++#define MSGTR_MPDEMUX_NW_CantConnect2Server "Failed to connect to server with %s\n" ++#define MSGTR_MPDEMUX_NW_SelectFailed "Select failed.\n" ++#define MSGTR_MPDEMUX_NW_ConnTimeout "connection timeout\n" ++#define MSGTR_MPDEMUX_NW_GetSockOptFailed "getsockopt failed: %s\n" ++#define MSGTR_MPDEMUX_NW_ConnectError "connect error: %s\n" ++#define MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout "Invalid proxy setting... Trying without proxy.\n" ++#define MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy "Could not resolve remote hostname for AF_INET. Trying without proxy.\n" ++#define MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest "Error while sending HTTP request: Didn't send all the request.\n" ++#define MSGTR_MPDEMUX_NW_ReadFailed "Read failed.\n" ++#define MSGTR_MPDEMUX_NW_Read0CouldBeEOF "http_read_response read 0 (i.e. EOF).\n" ++#define MSGTR_MPDEMUX_NW_AuthFailed "Authentication failed. Please use the -user and -passwd options to provide your\n"\ ++"username/password for a list of URLs, or form an URL like:\n"\ ++"http://username:password@hostname/file\n" ++#define MSGTR_MPDEMUX_NW_AuthRequiredFor "Authentication required for %s\n" ++#define MSGTR_MPDEMUX_NW_AuthRequired "Authentication required.\n" ++#define MSGTR_MPDEMUX_NW_NoPasswdProvidedTryingBlank "No password provided, trying blank password.\n" ++#define MSGTR_MPDEMUX_NW_ErrServerReturned "Server returns %d: %s\n" ++#define MSGTR_MPDEMUX_NW_CacheSizeSetTo "Cache size set to %d KBytes\n" ++ ++// open.c, stream.c: ++#define MSGTR_CdDevNotfound "CD-ROM Device '%s' not found.\n" ++#define MSGTR_ErrTrackSelect "Error selecting VCD track." ++#define MSGTR_ReadSTDIN "Reading from stdin...\n" ++#define MSGTR_UnableOpenURL "Unable to open URL: %s\n" ++#define MSGTR_ConnToServer "Connected to server: %s\n" ++#define MSGTR_FileNotFound "File not found: '%s'\n" ++ ++#define MSGTR_SMBInitError "Cannot init the libsmbclient library: %d\n" ++#define MSGTR_SMBFileNotFound "Could not open from LAN: '%s'\n" ++#define MSGTR_SMBNotCompiled "MPlayer was not compiled with SMB reading support.\n" ++ ++#define MSGTR_CantOpenBluray "Couldn't open Blu-ray device: %s\n" ++#define MSGTR_CantOpenDVD "Couldn't open DVD device: %s (%s)\n" ++ ++// stream_cdda.c ++#define MSGTR_MPDEMUX_CDDA_CantOpenCDDADevice "Can't open CDDA device.\n" ++#define MSGTR_MPDEMUX_CDDA_CantOpenDisc "Can't open disc.\n" ++#define MSGTR_MPDEMUX_CDDA_AudioCDFoundWithNTracks "Found audio CD with %d tracks.\n" ++ ++// stream_cddb.c ++#define MSGTR_MPDEMUX_CDDB_FailedToReadTOC "Failed to read TOC.\n" ++#define MSGTR_MPDEMUX_CDDB_FailedToOpenDevice "Failed to open %s device.\n" ++#define MSGTR_MPDEMUX_CDDB_NotAValidURL "not a valid URL\n" ++#define MSGTR_MPDEMUX_CDDB_FailedToSendHTTPRequest "Failed to send the HTTP request.\n" ++#define MSGTR_MPDEMUX_CDDB_FailedToReadHTTPResponse "Failed to read the HTTP response.\n" ++#define MSGTR_MPDEMUX_CDDB_HTTPErrorNOTFOUND "Not Found.\n" ++#define MSGTR_MPDEMUX_CDDB_HTTPErrorUnknown "unknown error code\n" ++#define MSGTR_MPDEMUX_CDDB_NoCacheFound "No cache found.\n" ++#define MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenRead "Not all the xmcd file has been read.\n" ++#define MSGTR_MPDEMUX_CDDB_FailedToCreateDirectory "Failed to create directory %s.\n" ++#define MSGTR_MPDEMUX_CDDB_NotAllXMCDFileHasBeenWritten "Not all of the xmcd file has been written.\n" ++#define MSGTR_MPDEMUX_CDDB_InvalidXMCDDatabaseReturned "Invalid xmcd database file returned.\n" ++#define MSGTR_MPDEMUX_CDDB_UnexpectedFIXME "unexpected FIXME\n" ++#define MSGTR_MPDEMUX_CDDB_UnhandledCode "unhandled code\n" ++#define MSGTR_MPDEMUX_CDDB_UnableToFindEOL "Unable to find end of line.\n" ++#define MSGTR_MPDEMUX_CDDB_ParseOKFoundAlbumTitle "Parse OK, found: %s\n" ++#define MSGTR_MPDEMUX_CDDB_AlbumNotFound "Album not found.\n" ++#define MSGTR_MPDEMUX_CDDB_ServerReturnsCommandSyntaxErr "Server returns: Command syntax error\n" ++#define MSGTR_MPDEMUX_CDDB_NoSitesInfoAvailable "No sites information available.\n" ++#define MSGTR_MPDEMUX_CDDB_FailedToGetProtocolLevel "Failed to get the protocol level.\n" ++#define MSGTR_MPDEMUX_CDDB_NoCDInDrive "No CD in the drive.\n" ++ ++// stream_cue.c ++#define MSGTR_MPDEMUX_CUEREAD_UnexpectedCuefileLine "[bincue] Unexpected cuefile line: %s\n" ++#define MSGTR_MPDEMUX_CUEREAD_BinFilenameTested "[bincue] bin filename tested: %s\n" ++#define MSGTR_MPDEMUX_CUEREAD_CannotFindBinFile "[bincue] Couldn't find the bin file - giving up.\n" ++#define MSGTR_MPDEMUX_CUEREAD_UsingBinFile "[bincue] Using bin file %s.\n" ++#define MSGTR_MPDEMUX_CUEREAD_UnknownModeForBinfile "[bincue] unknown mode for binfile. Should not happen. Aborting.\n" ++#define MSGTR_MPDEMUX_CUEREAD_CannotOpenCueFile "[bincue] Cannot open %s.\n" ++#define MSGTR_MPDEMUX_CUEREAD_ErrReadingFromCueFile "[bincue] Error reading from %s\n" ++#define MSGTR_MPDEMUX_CUEREAD_ErrGettingBinFileSize "[bincue] Error getting size of bin file.\n" ++#define MSGTR_MPDEMUX_CUEREAD_InfoTrackFormat "track %02d: format=%d %02d:%02d:%02d\n" ++#define MSGTR_MPDEMUX_CUEREAD_UnexpectedBinFileEOF "[bincue] unexpected end of bin file\n" ++#define MSGTR_MPDEMUX_CUEREAD_CannotReadNBytesOfPayload "[bincue] Couldn't read %d bytes of payload.\n" ++#define MSGTR_MPDEMUX_CUEREAD_CueStreamInfo_FilenameTrackTracksavail "CUE stream_open, filename=%s, track=%d, available tracks: %d -> %d\n" ++ ++// stream_dvd.c ++#define MSGTR_DVDspeedCantOpen "Couldn't open DVD device for writing, changing DVD speed needs write access.\n" ++#define MSGTR_DVDrestoreSpeed "Restoring DVD speed... " ++#define MSGTR_DVDlimitSpeed "Limiting DVD speed to %dKB/s... " ++#define MSGTR_DVDlimitFail "failed\n" ++#define MSGTR_DVDlimitOk "successful\n" ++#define MSGTR_NoDVDSupport "MPlayer was compiled without DVD support, exiting.\n" ++#define MSGTR_DVDnumTitles "There are %d titles on this DVD.\n" ++#define MSGTR_DVDinvalidTitle "Invalid DVD title number: %d\n" ++#define MSGTR_DVDnumChapters "There are %d chapters in this DVD title.\n" ++#define MSGTR_DVDinvalidChapter "Invalid DVD chapter number: %d\n" ++#define MSGTR_DVDinvalidChapterRange "Invalid chapter range specification %s\n" ++#define MSGTR_DVDinvalidLastChapter "Invalid DVD last chapter number: %d\n" ++#define MSGTR_DVDnumAngles "There are %d angles in this DVD title.\n" ++#define MSGTR_DVDinvalidAngle "Invalid DVD angle number: %d\n" ++#define MSGTR_DVDnoIFO "Cannot open the IFO file for DVD title %d.\n" ++#define MSGTR_DVDnoVMG "Can't open VMG info!\n" ++#define MSGTR_DVDnoVOBs "Cannot open title VOBS (VTS_%02d_1.VOB).\n" ++#define MSGTR_DVDnoMatchingAudio "No matching DVD audio language found!\n" ++#define MSGTR_DVDaudioChannel "Selected DVD audio channel: %d language: %c%c\n" ++#define MSGTR_DVDaudioStreamInfo "audio stream: %d format: %s (%s) language: %s aid: %d.\n" ++#define MSGTR_DVDnumAudioChannels "number of audio channels on disk: %d.\n" ++#define MSGTR_DVDnoMatchingSubtitle "No matching DVD subtitle language found!\n" ++#define MSGTR_DVDsubtitleChannel "Selected DVD subtitle channel: %d language: %c%c\n" ++#define MSGTR_DVDsubtitleLanguage "subtitle ( sid ): %d language: %s\n" ++#define MSGTR_DVDnumSubtitles "number of subtitles on disk: %d\n" ++ ++// stream_bluray.c ++#define MSGTR_BlurayNoDevice "No Blu-ray device/location was specified ...\n" ++#define MSGTR_BlurayNoTitles "Can't find any Blu-ray-compatible title here.\n" ++#define MSGTR_BlurayOK "Blu-ray successfully opened.\n" ++ ++// stream_radio.c ++#define MSGTR_RADIO_ChannelNamesDetected "[radio] Radio channel names detected.\n" ++#define MSGTR_RADIO_FreqRange "[radio] Allowed frequency range is %.2f-%.2f MHz.\n" ++#define MSGTR_RADIO_WrongFreqForChannel "[radio] Wrong frequency for channel %s\n" ++#define MSGTR_RADIO_WrongChannelNumberFloat "[radio] Wrong channel number: %.2f\n" ++#define MSGTR_RADIO_WrongChannelNumberInt "[radio] Wrong channel number: %d\n" ++#define MSGTR_RADIO_WrongChannelName "[radio] Wrong channel name: %s\n" ++#define MSGTR_RADIO_FreqParameterDetected "[radio] Radio frequency parameter detected.\n" ++#define MSGTR_RADIO_DoneParsingChannels "[radio] Done parsing channels.\n" ++#define MSGTR_RADIO_GetTunerFailed "[radio] Warning: ioctl get tuner failed: %s. Setting frac to %d.\n" ++#define MSGTR_RADIO_NotRadioDevice "[radio] %s is no radio device!\n" ++#define MSGTR_RADIO_TunerCapLowYes "[radio] tuner is low:yes frac=%d\n" ++#define MSGTR_RADIO_TunerCapLowNo "[radio] tuner is low:no frac=%d\n" ++#define MSGTR_RADIO_SetFreqFailed "[radio] ioctl set frequency 0x%x (%.2f) failed: %s\n" ++#define MSGTR_RADIO_GetFreqFailed "[radio] ioctl get frequency failed: %s\n" ++#define MSGTR_RADIO_SetMuteFailed "[radio] ioctl set mute failed: %s\n" ++#define MSGTR_RADIO_QueryControlFailed "[radio] ioctl query control failed: %s\n" ++#define MSGTR_RADIO_GetVolumeFailed "[radio] ioctl get volume failed: %s\n" ++#define MSGTR_RADIO_SetVolumeFailed "[radio] ioctl set volume failed: %s\n" ++#define MSGTR_RADIO_DroppingFrame "\n[radio] too bad - dropping audio frame (%d bytes)!\n" ++#define MSGTR_RADIO_BufferEmpty "[radio] grab_audio_frame: buffer empty, waiting for %d data bytes.\n" ++#define MSGTR_RADIO_AudioInitFailed "[radio] audio_in_init failed: %s\n" ++#define MSGTR_RADIO_AudioBuffer "[radio] Audio capture - buffer=%d bytes (block=%d bytes).\n" ++#define MSGTR_RADIO_AllocateBufferFailed "[radio] cannot allocate audio buffer (block=%d,buf=%d): %s\n" ++#define MSGTR_RADIO_CurrentFreq "[radio] Current frequency: %.2f\n" ++#define MSGTR_RADIO_SelectedChannel "[radio] Selected channel: %d - %s (freq: %.2f)\n" ++#define MSGTR_RADIO_ChangeChannelNoChannelList "[radio] Can not change channel: no channel list given.\n" ++#define MSGTR_RADIO_UnableOpenDevice "[radio] Unable to open '%s': %s\n" ++#define MSGTR_RADIO_RadioDevice "[radio] Radio fd: %d, %s\n" ++#define MSGTR_RADIO_InitFracFailed "[radio] init_frac failed.\n" ++#define MSGTR_RADIO_WrongFreq "[radio] Wrong frequency: %.2f\n" ++#define MSGTR_RADIO_UsingFreq "[radio] Using frequency: %.2f.\n" ++#define MSGTR_RADIO_AudioInInitFailed "[radio] audio_in_init failed.\n" ++#define MSGTR_RADIO_BufferString "[radio] %s: in buffer=%d dropped=%d\n" ++#define MSGTR_RADIO_AudioInSetupFailed "[radio] audio_in_setup call failed: %s\n" ++#define MSGTR_RADIO_CaptureStarting "[radio] Starting capture stuff.\n" ++#define MSGTR_RADIO_ClearBufferFailed "[radio] Clearing buffer failed: %s\n" ++#define MSGTR_RADIO_StreamEnableCacheFailed "[radio] Call to stream_enable_cache failed: %s\n" ++#define MSGTR_RADIO_DriverUnknownStr "[radio] Unknown driver name: %s\n" ++#define MSGTR_RADIO_DriverV4L2 "[radio] Using V4Lv2 radio interface.\n" ++#define MSGTR_RADIO_DriverV4L "[radio] Using V4Lv1 radio interface.\n" ++#define MSGTR_RADIO_DriverBSDBT848 "[radio] Using *BSD BT848 radio interface.\n" ++#define MSGTR_RADIO_AvailableDrivers "[radio] Available drivers: " ++ ++//tv.c ++#define MSGTR_TV_BogusNormParameter "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n" ++#define MSGTR_TV_NoVideoInputPresent "Error: No video input present!\n" ++#define MSGTR_TV_UnknownImageFormat ""\ ++"==================================================================\n"\ ++" WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\ ++" This may cause buggy playback or program crash! Bug reports will\n"\ ++" be ignored! You should try again with YV12 (which is the default\n"\ ++" colorspace) and read the documentation!\n"\ ++"==================================================================\n" ++#define MSGTR_TV_SelectedNormId "Selected norm id: %d\n" ++#define MSGTR_TV_SelectedNorm "Selected norm : %s\n" ++#define MSGTR_TV_CannotSetNorm "Error: Cannot set norm!\n" ++#define MSGTR_TV_MJP_WidthHeight " MJP: width %d height %d\n" ++#define MSGTR_TV_UnableToSetWidth "Unable to set requested width: %d\n" ++#define MSGTR_TV_UnableToSetHeight "Unable to set requested height: %d\n" ++#define MSGTR_TV_NoTuner "Selected input hasn't got a tuner!\n" ++#define MSGTR_TV_UnableFindChanlist "Unable to find selected channel list! (%s)\n" ++#define MSGTR_TV_SelectedChanlist "Selected channel list: %s (including %d channels)\n" ++#define MSGTR_TV_ChannelFreqParamConflict "You can't set frequency and channel simultaneously!\n" ++#define MSGTR_TV_ChannelNamesDetected "TV channel names detected.\n" ++#define MSGTR_TV_NoFreqForChannel "Couldn't find frequency for channel %s (%s)\n" ++#define MSGTR_TV_SelectedChannel3 "Selected channel: %s - %s (freq: %.3f)\n" ++#define MSGTR_TV_SelectedChannel2 "Selected channel: %s (freq: %.3f)\n" ++#define MSGTR_TV_SelectedFrequency "Selected frequency: %lu (%.3f)\n" ++#define MSGTR_TV_RequestedChannel "Requested channel: %s\n" ++#define MSGTR_TV_UnsupportedAudioType "Audio type '%s (%x)' unsupported!\n" ++#define MSGTR_TV_AudioFormat " TV audio: %d channels, %d bits, %d Hz\n" ++#define MSGTR_TV_AvailableDrivers "Available drivers:\n" ++#define MSGTR_TV_DriverInfo "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n" ++#define MSGTR_TV_NoSuchDriver "No such driver: %s\n" ++#define MSGTR_TV_DriverAutoDetectionFailed "TV driver autodetection failed.\n" ++#define MSGTR_TV_UnknownColorOption "Unknown color option (%d) specified!\n" ++#define MSGTR_TV_CurrentFrequency "Current frequency: %lu (%.3f)\n" ++#define MSGTR_TV_NoTeletext "No teletext" ++#define MSGTR_TV_Bt848IoctlFailed "tvi_bsdbt848: Call to %s ioctl failed. Error: %s\n" ++#define MSGTR_TV_Bt848InvalidAudioRate "tvi_bsdbt848: Invalid audio rate. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorOpeningBktrDev "tvi_bsdbt848: Unable to open bktr device. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorOpeningTunerDev "tvi_bsdbt848: Unable to open tuner device. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorOpeningDspDev "tvi_bsdbt848: Unable to open dsp device. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorConfiguringDsp "tvi_bsdbt848: Configuration of dsp failed. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorReadingAudio "tvi_bsdbt848: Error reading audio data. Error: %s\n" ++#define MSGTR_TV_Bt848MmapFailed "tvi_bsdbt848: mmap failed. Error: %s\n" ++#define MSGTR_TV_Bt848FrameBufAllocFailed "tvi_bsdbt848: Frame buffer allocation failed. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorSettingWidth "tvi_bsdbt848: Error setting picture width. Error: %s\n" ++#define MSGTR_TV_Bt848ErrorSettingHeight "tvi_bsdbt848: Error setting picture height. Error: %s\n" ++#define MSGTR_TV_Bt848UnableToStopCapture "tvi_bsdbt848: Unable to stop capture. Error: %s\n" ++#define MSGTR_TV_TTSupportedLanguages "Supported Teletext languages:\n" ++#define MSGTR_TV_TTSelectedLanguage "Selected default teletext language: %s\n" ++#define MSGTR_TV_ScannerNotAvailableWithoutTuner "Channel scanner is not available without tuner\n" ++ ++//tvi_dshow.c ++#define MSGTR_TVI_DS_UnableConnectInputVideoDecoder "Unable to connect given input to video decoder. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableConnectInputAudioDecoder "Unable to connect given input to audio decoder. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableSelectVideoFormat "tvi_dshow: Unable to select video format. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableSelectAudioFormat "tvi_dshow: Unable to select audio format. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableGetMediaControlInterface "tvi_dshow: Unable to get IMediaControl interface. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableStartGraph "tvi_dshow: Unable to start graph! Error:0x%x\n" ++#define MSGTR_TVI_DS_DeviceNotFound "tvi_dshow: Device #%d not found\n" ++#define MSGTR_TVI_DS_UnableGetDeviceName "tvi_dshow: Unable to get name for device #%d\n" ++#define MSGTR_TVI_DS_UsingDevice "tvi_dshow: Using device #%d: %s\n" ++#define MSGTR_TVI_DS_DeviceName "tvi_dshow: Device #%d: %s\n" ++#define MSGTR_TVI_DS_DirectGetFreqFailed "tvi_dshow: Unable to get frequency directly. OS built-in channels table will be used.\n" ++#define MSGTR_TVI_DS_DirectSetFreqFailed "tvi_dshow: Unable to set frequency directly. OS built-in channels table will be used.\n" ++#define MSGTR_TVI_DS_SupportedNorms "tvi_dshow: supported norms:" ++#define MSGTR_TVI_DS_AvailableVideoInputs "tvi_dshow: available video inputs:" ++#define MSGTR_TVI_DS_AvailableAudioInputs "tvi_dshow: available audio inputs:" ++//following phrase will be printed near the selected audio/video input ++#define MSGTR_TVI_DS_InputSelected "(selected)" ++#define MSGTR_TVI_DS_UnableExtractFreqTable "tvi_dshow: Unable to load frequency table from kstvtune.ax\n" ++#define MSGTR_TVI_DS_WrongDeviceParam "tvi_dshow: Wrong device parameter: %s\n" ++#define MSGTR_TVI_DS_WrongDeviceIndex "tvi_dshow: Wrong device index: %d\n" ++#define MSGTR_TVI_DS_WrongADeviceParam "tvi_dshow: Wrong adevice parameter: %s\n" ++#define MSGTR_TVI_DS_WrongADeviceIndex "tvi_dshow: Wrong adevice index: %d\n" ++ ++#define MSGTR_TVI_DS_SamplerateNotsupported "tvi_dshow: Samplerate %d is not supported by device. Failing back to first available.\n" ++#define MSGTR_TVI_DS_VideoAdjustigNotSupported "tvi_dshow: Adjusting of brightness/hue/saturation/contrast is not supported by device\n" ++ ++#define MSGTR_TVI_DS_ChangingWidthHeightNotSupported "tvi_dshow: Changing video width/height is not supported by device.\n" ++#define MSGTR_TVI_DS_SelectingInputNotSupported "tvi_dshow: Selection of capture source is not supported by device\n" ++#define MSGTR_TVI_DS_FreqTableLoaded "tvi_dshow: loaded system (%s) frequency table for country id=%d (channels:%d).\n" ++#define MSGTR_TVI_DS_ErrorParsingAudioFormatStruct "tvi_dshow: Unable to parse audio format structure.\n" ++#define MSGTR_TVI_DS_ErrorParsingVideoFormatStruct "tvi_dshow: Unable to parse video format structure.\n" ++#define MSGTR_TVI_DS_UnableSetAudioMode "tvi_dshow: Unable to set audio mode %d. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnsupportedMediaType "tvi_dshow: Unsupported media type passed to %s\n" ++#define MSGTR_TVI_DS_UnableGetsupportedVideoFormats "tvi_dshow: Unable to get supported media formats from video pin. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableGetsupportedAudioFormats "tvi_dshow: Unable to get supported media formats from audio pin. Error:0x%x Disabling audio.\n" ++#define MSGTR_TVI_DS_UnableFindNearestChannel "tvi_dshow: Unable to find nearest channel in system frequency table\n" ++#define MSGTR_TVI_DS_UnableToSetChannel "tvi_dshow: Unable to switch to nearest channel from system frequency table. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableTerminateVPPin "tvi_dshow: Unable to terminate VideoPort pin with any filter in graph. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableBuildVideoSubGraph "tvi_dshow: Unable to build video chain of capture graph. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableBuildAudioSubGraph "tvi_dshow: Unable to build audio chain of capture graph. Error:0x%x\n" ++#define MSGTR_TVI_DS_UnableBuildVBISubGraph "tvi_dshow: Unable to build VBI chain of capture graph. Error:0x%x\n" ++#define MSGTR_TVI_DS_GraphInitFailure "tvi_dshow: Directshow graph initialization failure.\n" ++#define MSGTR_TVI_DS_NoVideoCaptureDevice "tvi_dshow: Unable to find video capture device\n" ++#define MSGTR_TVI_DS_NoAudioCaptureDevice "tvi_dshow: Unable to find audio capture device\n" ++#define MSGTR_TVI_DS_GetActualMediatypeFailed "tvi_dshow: Unable to get actual mediatype (Error:0x%x). Assuming equal to requested.\n" ++ ++// url.c ++#define MSGTR_MPDEMUX_URL_StringAlreadyEscaped "String appears to be already escaped in url_escape %c%c1%c2\n" ++ ++// subtitles ++#define MSGTR_SUBTITLES_SubRip_UnknownFontColor "SubRip: unknown font color in subtitle: %s\n" ++ ++ ++/* untranslated messages from the English master file */ ++ ++ ++#endif /* MPLAYER_HELP_MP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/img_format.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/img_format.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/img_format.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/img_format.c 2012-05-14 14:08:54.720347750 +0200 +@@ -0,0 +1,170 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include "config.h" ++#include "img_format.h" ++#include "stdio.h" ++ ++const char *vo_format_name(int format) ++{ ++ static char unknown_format[20]; ++ switch(format) ++ { ++ case IMGFMT_RGB1: return "RGB 1-bit"; ++ case IMGFMT_RGB4: return "RGB 4-bit"; ++ case IMGFMT_RG4B: return "RGB 4-bit per byte"; ++ case IMGFMT_RGB8: return "RGB 8-bit"; ++ case IMGFMT_RGB12: return "RGB 12-bit"; ++ case IMGFMT_RGB15: return "RGB 15-bit"; ++ case IMGFMT_RGB16: return "RGB 16-bit"; ++ case IMGFMT_RGB24: return "RGB 24-bit"; ++// case IMGFMT_RGB32: return "RGB 32-bit"; ++ case IMGFMT_RGB48LE: return "RGB 48-bit LE"; ++ case IMGFMT_RGB48BE: return "RGB 48-bit BE"; ++ case IMGFMT_BGR1: return "BGR 1-bit"; ++ case IMGFMT_BGR4: return "BGR 4-bit"; ++ case IMGFMT_BG4B: return "BGR 4-bit per byte"; ++ case IMGFMT_BGR8: return "BGR 8-bit"; ++ case IMGFMT_BGR12: return "BGR 12-bit"; ++ case IMGFMT_BGR15: return "BGR 15-bit"; ++ case IMGFMT_BGR16: return "BGR 16-bit"; ++ case IMGFMT_BGR24: return "BGR 24-bit"; ++// case IMGFMT_BGR32: return "BGR 32-bit"; ++ case IMGFMT_ABGR: return "ABGR"; ++ case IMGFMT_BGRA: return "BGRA"; ++ case IMGFMT_ARGB: return "ARGB"; ++ case IMGFMT_RGBA: return "RGBA"; ++ case IMGFMT_YVU9: return "Planar YVU9"; ++ case IMGFMT_IF09: return "Planar IF09"; ++ case IMGFMT_YV12: return "Planar YV12"; ++ case IMGFMT_I420: return "Planar I420"; ++ case IMGFMT_IYUV: return "Planar IYUV"; ++ case IMGFMT_CLPL: return "Planar CLPL"; ++ case IMGFMT_Y800: return "Planar Y800"; ++ case IMGFMT_Y8: return "Planar Y8"; ++ case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian"; ++ case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian"; ++ case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian"; ++ case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian"; ++ case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian"; ++ case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian"; ++ case IMGFMT_420A: return "Planar 420P with alpha"; ++ case IMGFMT_444P: return "Planar 444P"; ++ case IMGFMT_422P: return "Planar 422P"; ++ case IMGFMT_411P: return "Planar 411P"; ++ case IMGFMT_NV12: return "Planar NV12"; ++ case IMGFMT_NV21: return "Planar NV21"; ++ case IMGFMT_HM12: return "Planar NV12 Macroblock"; ++ case IMGFMT_IUYV: return "Packed IUYV"; ++ case IMGFMT_IY41: return "Packed IY41"; ++ case IMGFMT_IYU1: return "Packed IYU1"; ++ case IMGFMT_IYU2: return "Packed IYU2"; ++ case IMGFMT_UYVY: return "Packed UYVY"; ++ case IMGFMT_UYNV: return "Packed UYNV"; ++ case IMGFMT_cyuv: return "Packed CYUV"; ++ case IMGFMT_Y422: return "Packed Y422"; ++ case IMGFMT_YUY2: return "Packed YUY2"; ++ case IMGFMT_YUNV: return "Packed YUNV"; ++ case IMGFMT_YVYU: return "Packed YVYU"; ++ case IMGFMT_Y41P: return "Packed Y41P"; ++ case IMGFMT_Y211: return "Packed Y211"; ++ case IMGFMT_Y41T: return "Packed Y41T"; ++ case IMGFMT_Y42T: return "Packed Y42T"; ++ case IMGFMT_V422: return "Packed V422"; ++ case IMGFMT_V655: return "Packed V655"; ++ case IMGFMT_CLJR: return "Packed CLJR"; ++ case IMGFMT_YUVP: return "Packed YUVP"; ++ case IMGFMT_UYVP: return "Packed UYVP"; ++ case IMGFMT_MPEGPES: return "Mpeg PES"; ++ case IMGFMT_ZRMJPEGNI: return "Zoran MJPEG non-interlaced"; ++ case IMGFMT_ZRMJPEGIT: return "Zoran MJPEG top field first"; ++ case IMGFMT_ZRMJPEGIB: return "Zoran MJPEG bottom field first"; ++ case IMGFMT_XVMC_MOCO_MPEG2: return "MPEG1/2 Motion Compensation"; ++ case IMGFMT_XVMC_IDCT_MPEG2: return "MPEG1/2 Motion Compensation and IDCT"; ++ case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration"; ++ case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration"; ++ case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration"; ++ case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration"; ++ case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration"; ++ case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration"; ++ } ++ snprintf(unknown_format,20,"Unknown 0x%04x",format); ++ return unknown_format; ++} ++ ++int mp_get_chroma_shift(int format, int *x_shift, int *y_shift) ++{ ++ int xs = 0, ys = 0; ++ int bpp; ++ int bpp_factor = 1; ++ int err = 0; ++ switch (format) { ++ case IMGFMT_420P16_LE: ++ case IMGFMT_420P16_BE: ++ bpp_factor = 2; ++ case IMGFMT_420A: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YV12: ++ xs = 1; ++ ys = 1; ++ break; ++ case IMGFMT_IF09: ++ case IMGFMT_YVU9: ++ xs = 2; ++ ys = 2; ++ break; ++ case IMGFMT_444P16_LE: ++ case IMGFMT_444P16_BE: ++ bpp_factor = 2; ++ case IMGFMT_444P: ++ xs = 0; ++ ys = 0; ++ break; ++ case IMGFMT_422P16_LE: ++ case IMGFMT_422P16_BE: ++ bpp_factor = 2; ++ case IMGFMT_422P: ++ xs = 1; ++ ys = 0; ++ break; ++ case IMGFMT_411P: ++ xs = 2; ++ ys = 0; ++ break; ++ case IMGFMT_440P: ++ xs = 0; ++ ys = 1; ++ break; ++ case IMGFMT_Y8: ++ case IMGFMT_Y800: ++ xs = 31; ++ ys = 31; ++ break; ++ default: ++ err = 1; ++ break; ++ } ++ if (x_shift) *x_shift = xs; ++ if (y_shift) *y_shift = ys; ++ bpp = 8 + ((16 >> xs) >> ys); ++ if (format == IMGFMT_420A) ++ bpp += 8; ++ bpp *= bpp_factor; ++ return err ? 0 : bpp; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/img_format.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/img_format.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/img_format.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/img_format.h 2012-05-14 14:08:54.721347770 +0200 +@@ -0,0 +1,214 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_IMG_FORMAT_H ++#define MPLAYER_IMG_FORMAT_H ++ ++#include "config.h" ++ ++/* RGB/BGR Formats */ ++ ++#define IMGFMT_RGB_MASK 0xFFFFFF00 ++#define IMGFMT_RGB (('R'<<24)|('G'<<16)|('B'<<8)) ++#define IMGFMT_RGB1 (IMGFMT_RGB|1) ++#define IMGFMT_RGB4 (IMGFMT_RGB|4) ++#define IMGFMT_RGB4_CHAR (IMGFMT_RGB|4|128) // RGB4 with 1 pixel per byte ++#define IMGFMT_RGB8 (IMGFMT_RGB|8) ++#define IMGFMT_RGB12 (IMGFMT_RGB|12) ++#define IMGFMT_RGB15 (IMGFMT_RGB|15) ++#define IMGFMT_RGB16 (IMGFMT_RGB|16) ++#define IMGFMT_RGB24 (IMGFMT_RGB|24) ++#define IMGFMT_RGB32 (IMGFMT_RGB|32) ++#define IMGFMT_RGB48LE (IMGFMT_RGB|48) ++#define IMGFMT_RGB48BE (IMGFMT_RGB|48|128) ++ ++#define IMGFMT_BGR_MASK 0xFFFFFF00 ++#define IMGFMT_BGR (('B'<<24)|('G'<<16)|('R'<<8)) ++#define IMGFMT_BGR1 (IMGFMT_BGR|1) ++#define IMGFMT_BGR4 (IMGFMT_BGR|4) ++#define IMGFMT_BGR4_CHAR (IMGFMT_BGR|4|128) // BGR4 with 1 pixel per byte ++#define IMGFMT_BGR8 (IMGFMT_BGR|8) ++#define IMGFMT_BGR12 (IMGFMT_BGR|12) ++#define IMGFMT_BGR15 (IMGFMT_BGR|15) ++#define IMGFMT_BGR16 (IMGFMT_BGR|16) ++#define IMGFMT_BGR24 (IMGFMT_BGR|24) ++#define IMGFMT_BGR32 (IMGFMT_BGR|32) ++ ++#if HAVE_BIGENDIAN ++#define IMGFMT_ABGR IMGFMT_RGB32 ++#define IMGFMT_BGRA (IMGFMT_RGB32|64) ++#define IMGFMT_ARGB IMGFMT_BGR32 ++#define IMGFMT_RGBA (IMGFMT_BGR32|64) ++#define IMGFMT_RGB48NE IMGFMT_RGB48BE ++#define IMGFMT_RGB12BE IMGFMT_RGB12 ++#define IMGFMT_RGB12LE (IMGFMT_RGB12|64) ++#define IMGFMT_RGB15BE IMGFMT_RGB15 ++#define IMGFMT_RGB15LE (IMGFMT_RGB15|64) ++#define IMGFMT_RGB16BE IMGFMT_RGB16 ++#define IMGFMT_RGB16LE (IMGFMT_RGB16|64) ++#define IMGFMT_BGR12BE IMGFMT_BGR12 ++#define IMGFMT_BGR12LE (IMGFMT_BGR12|64) ++#define IMGFMT_BGR15BE IMGFMT_BGR15 ++#define IMGFMT_BGR15LE (IMGFMT_BGR15|64) ++#define IMGFMT_BGR16BE IMGFMT_BGR16 ++#define IMGFMT_BGR16LE (IMGFMT_BGR16|64) ++#else ++#define IMGFMT_ABGR (IMGFMT_BGR32|64) ++#define IMGFMT_BGRA IMGFMT_BGR32 ++#define IMGFMT_ARGB (IMGFMT_RGB32|64) ++#define IMGFMT_RGBA IMGFMT_RGB32 ++#define IMGFMT_RGB48NE IMGFMT_RGB48LE ++#define IMGFMT_RGB12BE (IMGFMT_RGB12|64) ++#define IMGFMT_RGB12LE IMGFMT_RGB12 ++#define IMGFMT_RGB15BE (IMGFMT_RGB15|64) ++#define IMGFMT_RGB15LE IMGFMT_RGB15 ++#define IMGFMT_RGB16BE (IMGFMT_RGB16|64) ++#define IMGFMT_RGB16LE IMGFMT_RGB16 ++#define IMGFMT_BGR12BE (IMGFMT_BGR12|64) ++#define IMGFMT_BGR12LE IMGFMT_BGR12 ++#define IMGFMT_BGR15BE (IMGFMT_BGR15|64) ++#define IMGFMT_BGR15LE IMGFMT_BGR15 ++#define IMGFMT_BGR16BE (IMGFMT_BGR16|64) ++#define IMGFMT_BGR16LE IMGFMT_BGR16 ++#endif ++ ++/* old names for compatibility */ ++#define IMGFMT_RG4B IMGFMT_RGB4_CHAR ++#define IMGFMT_BG4B IMGFMT_BGR4_CHAR ++ ++#define IMGFMT_IS_RGB(fmt) (((fmt)&IMGFMT_RGB_MASK)==IMGFMT_RGB) ++#define IMGFMT_IS_BGR(fmt) (((fmt)&IMGFMT_BGR_MASK)==IMGFMT_BGR) ++ ++#define IMGFMT_RGB_DEPTH(fmt) ((fmt)&0x3F) ++#define IMGFMT_BGR_DEPTH(fmt) ((fmt)&0x3F) ++ ++ ++/* Planar YUV Formats */ ++ ++#define IMGFMT_YVU9 0x39555659 ++#define IMGFMT_IF09 0x39304649 ++#define IMGFMT_YV12 0x32315659 ++#define IMGFMT_I420 0x30323449 ++#define IMGFMT_IYUV 0x56555949 ++#define IMGFMT_CLPL 0x4C504C43 ++#define IMGFMT_Y800 0x30303859 ++#define IMGFMT_Y8 0x20203859 ++#define IMGFMT_NV12 0x3231564E ++#define IMGFMT_NV21 0x3132564E ++ ++/* unofficial Planar Formats, FIXME if official 4CC exists */ ++#define IMGFMT_444P 0x50343434 ++#define IMGFMT_422P 0x50323234 ++#define IMGFMT_411P 0x50313134 ++#define IMGFMT_440P 0x50303434 ++#define IMGFMT_HM12 0x32314D48 ++ ++// 4:2:0 planar with alpha ++#define IMGFMT_420A 0x41303234 ++ ++#define IMGFMT_444P16_LE 0x51343434 ++#define IMGFMT_444P16_BE 0x34343451 ++#define IMGFMT_422P16_LE 0x51323234 ++#define IMGFMT_422P16_BE 0x34323251 ++#define IMGFMT_420P16_LE 0x51303234 ++#define IMGFMT_420P16_BE 0x34323051 ++#if HAVE_BIGENDIAN ++#define IMGFMT_444P16 IMGFMT_444P16_BE ++#define IMGFMT_422P16 IMGFMT_422P16_BE ++#define IMGFMT_420P16 IMGFMT_420P16_BE ++#else ++#define IMGFMT_444P16 IMGFMT_444P16_LE ++#define IMGFMT_422P16 IMGFMT_422P16_LE ++#define IMGFMT_420P16 IMGFMT_420P16_LE ++#endif ++ ++#define IMGFMT_IS_YUVP16_LE(fmt) (((fmt ^ IMGFMT_420P16_LE) & 0xff0000ff) == 0) ++#define IMGFMT_IS_YUVP16_BE(fmt) (((fmt ^ IMGFMT_420P16_BE) & 0xff0000ff) == 0) ++#define IMGFMT_IS_YUVP16_NE(fmt) (((fmt ^ IMGFMT_420P16 ) & 0xff0000ff) == 0) ++#define IMGFMT_IS_YUVP16(fmt) (IMGFMT_IS_YUVP16_LE(fmt) || IMGFMT_IS_YUVP16_BE(fmt)) ++ ++/* Packed YUV Formats */ ++ ++#define IMGFMT_IUYV 0x56595549 ++#define IMGFMT_IY41 0x31435949 ++#define IMGFMT_IYU1 0x31555949 ++#define IMGFMT_IYU2 0x32555949 ++#define IMGFMT_UYVY 0x59565955 ++#define IMGFMT_UYNV 0x564E5955 ++#define IMGFMT_cyuv 0x76757963 ++#define IMGFMT_Y422 0x32323459 ++#define IMGFMT_YUY2 0x32595559 ++#define IMGFMT_YUNV 0x564E5559 ++#define IMGFMT_YVYU 0x55595659 ++#define IMGFMT_Y41P 0x50313459 ++#define IMGFMT_Y211 0x31313259 ++#define IMGFMT_Y41T 0x54313459 ++#define IMGFMT_Y42T 0x54323459 ++#define IMGFMT_V422 0x32323456 ++#define IMGFMT_V655 0x35353656 ++#define IMGFMT_CLJR 0x524A4C43 ++#define IMGFMT_YUVP 0x50565559 ++#define IMGFMT_UYVP 0x50565955 ++ ++/* Compressed Formats */ ++#define IMGFMT_MPEGPES (('M'<<24)|('P'<<16)|('E'<<8)|('S')) ++#define IMGFMT_MJPEG (('M')|('J'<<8)|('P'<<16)|('G'<<24)) ++/* Formats that are understood by zoran chips, we include ++ * non-interlaced, interlaced top-first, interlaced bottom-first */ ++#define IMGFMT_ZRMJPEGNI (('Z'<<24)|('R'<<16)|('N'<<8)|('I')) ++#define IMGFMT_ZRMJPEGIT (('Z'<<24)|('R'<<16)|('I'<<8)|('T')) ++#define IMGFMT_ZRMJPEGIB (('Z'<<24)|('R'<<16)|('I'<<8)|('B')) ++ ++// I think that this code could not be used by any other codec/format ++#define IMGFMT_XVMC 0x1DC70000 ++#define IMGFMT_XVMC_MASK 0xFFFF0000 ++#define IMGFMT_IS_XVMC(fmt) (((fmt)&IMGFMT_XVMC_MASK)==IMGFMT_XVMC) ++//these are chroma420 ++#define IMGFMT_XVMC_MOCO_MPEG2 (IMGFMT_XVMC|0x02) ++#define IMGFMT_XVMC_IDCT_MPEG2 (IMGFMT_XVMC|0x82) ++ ++// VDPAU specific format. ++#define IMGFMT_VDPAU 0x1DC80000 ++#define IMGFMT_VDPAU_MASK 0xFFFF0000 ++#define IMGFMT_IS_VDPAU(fmt) (((fmt)&IMGFMT_VDPAU_MASK)==IMGFMT_VDPAU) ++#define IMGFMT_VDPAU_MPEG1 (IMGFMT_VDPAU|0x01) ++#define IMGFMT_VDPAU_MPEG2 (IMGFMT_VDPAU|0x02) ++#define IMGFMT_VDPAU_H264 (IMGFMT_VDPAU|0x03) ++#define IMGFMT_VDPAU_WMV3 (IMGFMT_VDPAU|0x04) ++#define IMGFMT_VDPAU_VC1 (IMGFMT_VDPAU|0x05) ++#define IMGFMT_VDPAU_MPEG4 (IMGFMT_VDPAU|0x06) ++ ++#define IMGFMT_IS_HWACCEL(fmt) (IMGFMT_IS_VDPAU(fmt) || IMGFMT_IS_XVMC(fmt)) ++ ++typedef struct { ++ void* data; ++ int size; ++ int id; // stream id. usually 0x1E0 ++ int timestamp; // pts, 90000 Hz counter based ++} vo_mpegpes_t; ++ ++const char *vo_format_name(int format); ++ ++/** ++ * Calculates the scale shifts for the chroma planes for planar YUV ++ * ++ * \return bits-per-pixel for format if successful (i.e. format is 3 or 4-planes planar YUV), 0 otherwise ++ */ ++int mp_get_chroma_shift(int format, int *x_shift, int *y_shift); ++ ++#endif /* MPLAYER_IMG_FORMAT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/libvo/fastmemcpy.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/libvo/fastmemcpy.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/libvo/fastmemcpy.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/libvo/fastmemcpy.h 2012-05-14 14:08:54.722347790 +0200 +@@ -0,0 +1,99 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * MPlayer 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with MPlayer; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef MPLAYER_FASTMEMCPY_H ++#define MPLAYER_FASTMEMCPY_H ++ ++#include ++#include ++#include ++ ++void * fast_memcpy(void * to, const void * from, size_t len); ++void * mem2agpcpy(void * to, const void * from, size_t len); ++ ++#if ! defined(CONFIG_FASTMEMCPY) || ! (HAVE_MMX || HAVE_MMX2 || HAVE_AMD3DNOW /* || HAVE_SSE || HAVE_SSE2 */) ++#define mem2agpcpy(a,b,c) memcpy(a,b,c) ++#define fast_memcpy(a,b,c) memcpy(a,b,c) ++#endif ++ ++static inline void * mem2agpcpy_pic(void * dst, const void * src, int bytesPerLine, int height, int dstStride, int srcStride) ++{ ++ int i; ++ void *retval=dst; ++ ++ if(dstStride == srcStride) ++ { ++ if (srcStride < 0) { ++ src = (const uint8_t*)src + (height-1)*srcStride; ++ dst = (uint8_t*)dst + (height-1)*dstStride; ++ srcStride = -srcStride; ++ } ++ ++ mem2agpcpy(dst, src, srcStride*height); ++ } ++ else ++ { ++ for(i=0; i ++#include ++ ++//#include "sub/font_load.h" ++#include "../img_format.h" ++//#include "vidix/vidix.h" ++ ++#define VO_EVENT_EXPOSE 1 ++#define VO_EVENT_RESIZE 2 ++#define VO_EVENT_KEYPRESS 4 ++#define VO_EVENT_REINIT 8 ++#define VO_EVENT_MOVE 16 ++ ++/* Obsolete: VOCTRL_QUERY_VAA 1 */ ++/* does the device support the required format */ ++#define VOCTRL_QUERY_FORMAT 2 ++/* signal a device reset seek */ ++#define VOCTRL_RESET 3 ++/* true if vo driver can use GUI created windows */ ++#define VOCTRL_GUISUPPORT 4 ++#define VOCTRL_GUI_NOWINDOW 19 ++/* used to switch to fullscreen */ ++#define VOCTRL_FULLSCREEN 5 ++/* signal a device pause */ ++#define VOCTRL_PAUSE 7 ++/* start/resume playback */ ++#define VOCTRL_RESUME 8 ++/* libmpcodecs direct rendering: */ ++#define VOCTRL_GET_IMAGE 9 ++#define VOCTRL_DRAW_IMAGE 13 ++#define VOCTRL_SET_SPU_PALETTE 14 ++/* decoding ahead: */ ++#define VOCTRL_GET_NUM_FRAMES 10 ++#define VOCTRL_GET_FRAME_NUM 11 ++#define VOCTRL_SET_FRAME_NUM 12 ++#define VOCTRL_GET_PANSCAN 15 ++#define VOCTRL_SET_PANSCAN 16 ++/* equalizer controls */ ++#define VOCTRL_SET_EQUALIZER 17 ++#define VOCTRL_GET_EQUALIZER 18 ++//#define VOCTRL_GUI_NOWINDOW 19 ++/* Frame duplication */ ++#define VOCTRL_DUPLICATE_FRAME 20 ++// ... 21 ++#define VOCTRL_START_SLICE 21 ++ ++#define VOCTRL_ONTOP 25 ++#define VOCTRL_ROOTWIN 26 ++#define VOCTRL_BORDER 27 ++#define VOCTRL_DRAW_EOSD 28 ++#define VOCTRL_GET_EOSD_RES 29 ++ ++#define VOCTRL_SET_DEINTERLACE 30 ++#define VOCTRL_GET_DEINTERLACE 31 ++ ++#define VOCTRL_UPDATE_SCREENINFO 32 ++ ++// Vo can be used by xover ++#define VOCTRL_XOVERLAY_SUPPORT 22 ++ ++#define VOCTRL_XOVERLAY_SET_COLORKEY 24 ++typedef struct { ++ uint32_t x11; // The raw x11 color ++ uint16_t r,g,b; ++} mp_colorkey_t; ++ ++#define VOCTRL_XOVERLAY_SET_WIN 23 ++typedef struct { ++ int x,y; ++ int w,h; ++} mp_win_t; ++ ++#define VO_TRUE 1 ++#define VO_FALSE 0 ++#define VO_ERROR -1 ++#define VO_NOTAVAIL -2 ++#define VO_NOTIMPL -3 ++ ++#define VOFLAG_FULLSCREEN 0x01 ++#define VOFLAG_MODESWITCHING 0x02 ++#define VOFLAG_SWSCALE 0x04 ++#define VOFLAG_FLIPPING 0x08 ++#define VOFLAG_HIDDEN 0x10 //< Use to create a hidden window ++#define VOFLAG_STEREO 0x20 //< Use to create a stereo-capable window ++#define VOFLAG_XOVERLAY_SUB_VO 0x10000 ++ ++typedef struct vo_info_s ++{ ++ /* driver name ("Matrox Millennium G200/G400" */ ++ const char *name; ++ /* short name (for config strings) ("mga") */ ++ const char *short_name; ++ /* author ("Aaron Holtzman ") */ ++ const char *author; ++ /* any additional comments */ ++ const char *comment; ++} vo_info_t; ++ ++typedef struct vo_functions_s ++{ ++ const vo_info_t *info; ++ /* ++ * Preinitializes driver (real INITIALIZATION) ++ * arg - currently it's vo_subdevice ++ * returns: zero on successful initialization, non-zero on error. ++ */ ++ int (*preinit)(const char *arg); ++ /* ++ * Initialize (means CONFIGURE) the display driver. ++ * params: ++ * width,height: image source size ++ * d_width,d_height: size of the requested window size, just a hint ++ * fullscreen: flag, 0=windowd 1=fullscreen, just a hint ++ * title: window title, if available ++ * format: fourcc of pixel format ++ * returns : zero on successful initialization, non-zero on error. ++ */ ++ int (*config)(uint32_t width, uint32_t height, uint32_t d_width, ++ uint32_t d_height, uint32_t fullscreen, char *title, ++ uint32_t format); ++ ++ /* ++ * Control interface ++ */ ++ int (*control)(uint32_t request, void *data, ...); ++ ++ /* ++ * Display a new RGB/BGR frame of the video to the screen. ++ * params: ++ * src[0] - pointer to the image ++ */ ++ int (*draw_frame)(uint8_t *src[]); ++ ++ /* ++ * Draw a planar YUV slice to the buffer: ++ * params: ++ * src[3] = source image planes (Y,U,V) ++ * stride[3] = source image planes line widths (in bytes) ++ * w,h = width*height of area to be copied (in Y pixels) ++ * x,y = position at the destination image (in Y pixels) ++ */ ++ int (*draw_slice)(uint8_t *src[], int stride[], int w,int h, int x,int y); ++ ++ /* ++ * Draws OSD to the screen buffer ++ */ ++ void (*draw_osd)(void); ++ ++ /* ++ * Blit/Flip buffer to the screen. Must be called after each frame! ++ */ ++ void (*flip_page)(void); ++ ++ /* ++ * This func is called after every frames to handle keyboard and ++ * other events. It's called in PAUSE mode too! ++ */ ++ void (*check_events)(void); ++ ++ /* ++ * Closes driver. Should restore the original state of the system. ++ */ ++ void (*uninit)(void); ++} vo_functions_t; ++ ++const vo_functions_t* init_best_video_out(char** vo_list); ++int config_video_out(const vo_functions_t *vo, uint32_t width, uint32_t height, ++ uint32_t d_width, uint32_t d_height, uint32_t flags, ++ char *title, uint32_t format); ++void list_video_out(void); ++ ++// NULL terminated array of all drivers ++extern const vo_functions_t* const video_out_drivers[]; ++ ++extern int vo_flags; ++ ++extern int vo_config_count; ++ ++extern int xinerama_screen; ++extern int xinerama_x; ++extern int xinerama_y; ++ ++// correct resolution/bpp on screen: (should be autodetected by vo_init()) ++extern int vo_depthonscreen; ++extern int vo_screenwidth; ++extern int vo_screenheight; ++ ++// requested resolution/bpp: (-x -y -bpp options) ++extern int vo_dx; ++extern int vo_dy; ++extern int vo_dwidth; ++extern int vo_dheight; ++extern int vo_dbpp; ++ ++extern int vo_grabpointer; ++extern int vo_doublebuffering; ++extern int vo_directrendering; ++extern int vo_vsync; ++extern int vo_fs; ++extern int vo_fsmode; ++extern float vo_panscan; ++extern int vo_adapter_num; ++extern int vo_refresh_rate; ++extern int vo_keepaspect; ++extern int vo_rootwin; ++extern int vo_ontop; ++extern int vo_border; ++ ++extern int vo_gamma_gamma; ++extern int vo_gamma_brightness; ++extern int vo_gamma_saturation; ++extern int vo_gamma_contrast; ++extern int vo_gamma_hue; ++extern int vo_gamma_red_intensity; ++extern int vo_gamma_green_intensity; ++extern int vo_gamma_blue_intensity; ++ ++extern int vo_nomouse_input; ++extern int enable_mouse_movements; ++ ++extern int vo_pts; ++extern float vo_fps; ++ ++extern char *vo_subdevice; ++ ++extern int vo_colorkey; ++ ++extern char *vo_winname; ++extern char *vo_wintitle; ++ ++extern int64_t WinID; ++ ++typedef struct { ++ float min; ++ float max; ++ } range_t; ++ ++float range_max(range_t *r); ++int in_range(range_t *r, float f); ++range_t *str2range(char *s); ++extern char *monitor_hfreq_str; ++extern char *monitor_vfreq_str; ++extern char *monitor_dotclock_str; ++ ++struct mp_keymap { ++ int from; ++ int to; ++}; ++int lookup_keymap_table(const struct mp_keymap *map, int key); ++struct vo_rect { ++ int left, right, top, bottom, width, height; ++}; ++void calc_src_dst_rects(int src_width, int src_height, struct vo_rect *src, struct vo_rect *dst, ++ struct vo_rect *borders, const struct vo_rect *crop); ++void vo_mouse_movement(int posx, int posy); ++ ++static inline int aspect_scaling(void) ++{ ++ return vo_fs; ++} ++ ++#endif /* MPLAYER_VIDEO_OUT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mpbswap.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mpbswap.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mpbswap.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mpbswap.h 2012-05-14 14:08:54.725347851 +0200 +@@ -0,0 +1,34 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_MPBSWAP_H ++#define MPLAYER_MPBSWAP_H ++ ++#include ++#include "config.h" ++#include "libavutil/bswap.h" ++ ++#define bswap_16(v) av_bswap16(v) ++#define bswap_32(v) av_bswap32(v) ++#define le2me_16(v) av_le2ne16(v) ++#define le2me_32(v) av_le2ne32(v) ++#define le2me_64(v) av_le2ne64(v) ++#define be2me_16(v) av_be2ne16(v) ++#define be2me_32(v) av_be2ne32(v) ++ ++#endif /* MPLAYER_MPBSWAP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mpc_info.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mpc_info.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mpc_info.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mpc_info.h 2012-05-14 14:08:54.726347871 +0200 +@@ -0,0 +1,43 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_MPC_INFO_H ++#define MPLAYER_MPC_INFO_H ++ ++typedef struct mp_codec_info_s ++{ ++ /* codec long name ("Autodesk FLI/FLC Animation decoder" */ ++ const char *name; ++ /* short name (same as driver name in codecs.conf) ("dshow") */ ++ const char *short_name; ++ /* interface author/maintainer */ ++ const char *maintainer; ++ /* codec author ("Aaron Holtzman ") */ ++ const char *author; ++ /* any additional comments */ ++ const char *comment; ++} mp_codec_info_t; ++ ++#define CONTROL_OK 1 ++#define CONTROL_TRUE 1 ++#define CONTROL_FALSE 0 ++#define CONTROL_UNKNOWN -1 ++#define CONTROL_ERROR -2 ++#define CONTROL_NA -3 ++ ++#endif /* MPLAYER_MPC_INFO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.c 2012-05-14 14:08:54.723347811 +0200 +@@ -0,0 +1,200 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include "config.h" ++ ++#include ++#include ++#include ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "img_format.h" ++#include "mp_image.h" ++ ++#include "libvo/fastmemcpy.h" ++//#include "libavutil/mem.h" ++ ++void mp_image_alloc_planes(mp_image_t *mpi) { ++ // IF09 - allocate space for 4. plane delta info - unused ++ if (mpi->imgfmt == IMGFMT_IF09) { ++ mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8+ ++ mpi->chroma_width*mpi->chroma_height); ++ } else ++ mpi->planes[0]=av_malloc(mpi->bpp*mpi->width*(mpi->height+2)/8); ++ if (mpi->flags&MP_IMGFLAG_PLANAR) { ++ int bpp = IMGFMT_IS_YUVP16(mpi->imgfmt)? 2 : 1; ++ // YV12/I420/YVU9/IF09. feel free to add other planar formats here... ++ mpi->stride[0]=mpi->stride[3]=bpp*mpi->width; ++ if(mpi->num_planes > 2){ ++ mpi->stride[1]=mpi->stride[2]=bpp*mpi->chroma_width; ++ if(mpi->flags&MP_IMGFLAG_SWAPPED){ ++ // I420/IYUV (Y,U,V) ++ mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height; ++ mpi->planes[2]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height; ++ if (mpi->num_planes > 3) ++ mpi->planes[3]=mpi->planes[2]+mpi->stride[2]*mpi->chroma_height; ++ } else { ++ // YV12,YVU9,IF09 (Y,V,U) ++ mpi->planes[2]=mpi->planes[0]+mpi->stride[0]*mpi->height; ++ mpi->planes[1]=mpi->planes[2]+mpi->stride[1]*mpi->chroma_height; ++ if (mpi->num_planes > 3) ++ mpi->planes[3]=mpi->planes[1]+mpi->stride[1]*mpi->chroma_height; ++ } ++ } else { ++ // NV12/NV21 ++ mpi->stride[1]=mpi->chroma_width; ++ mpi->planes[1]=mpi->planes[0]+mpi->stride[0]*mpi->height; ++ } ++ } else { ++ mpi->stride[0]=mpi->width*mpi->bpp/8; ++ if (mpi->flags & MP_IMGFLAG_RGB_PALETTE) ++ mpi->planes[1] = av_malloc(1024); ++ } ++ mpi->flags|=MP_IMGFLAG_ALLOCATED; ++} ++ ++mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt) { ++ mp_image_t* mpi = new_mp_image(w,h); ++ ++ mp_image_setfmt(mpi,fmt); ++ mp_image_alloc_planes(mpi); ++ ++ return mpi; ++} ++ ++void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi) { ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ memcpy_pic(dmpi->planes[0],mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0],mpi->stride[0]); ++ memcpy_pic(dmpi->planes[1],mpi->planes[1], mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1],mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2],mpi->stride[2]); ++ } else { ++ memcpy_pic(dmpi->planes[0],mpi->planes[0], ++ mpi->w*(dmpi->bpp/8), mpi->h, ++ dmpi->stride[0],mpi->stride[0]); ++ } ++} ++ ++void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt){ ++ mpi->flags&=~(MP_IMGFLAG_PLANAR|MP_IMGFLAG_YUV|MP_IMGFLAG_SWAPPED); ++ mpi->imgfmt=out_fmt; ++ // compressed formats ++ if(out_fmt == IMGFMT_MPEGPES || ++ out_fmt == IMGFMT_ZRMJPEGNI || out_fmt == IMGFMT_ZRMJPEGIT || out_fmt == IMGFMT_ZRMJPEGIB || ++ IMGFMT_IS_HWACCEL(out_fmt)){ ++ mpi->bpp=0; ++ return; ++ } ++ mpi->num_planes=1; ++ if (IMGFMT_IS_RGB(out_fmt)) { ++ if (IMGFMT_RGB_DEPTH(out_fmt) < 8 && !(out_fmt&128)) ++ mpi->bpp = IMGFMT_RGB_DEPTH(out_fmt); ++ else ++ mpi->bpp=(IMGFMT_RGB_DEPTH(out_fmt)+7)&(~7); ++ return; ++ } ++ if (IMGFMT_IS_BGR(out_fmt)) { ++ if (IMGFMT_BGR_DEPTH(out_fmt) < 8 && !(out_fmt&128)) ++ mpi->bpp = IMGFMT_BGR_DEPTH(out_fmt); ++ else ++ mpi->bpp=(IMGFMT_BGR_DEPTH(out_fmt)+7)&(~7); ++ mpi->flags|=MP_IMGFLAG_SWAPPED; ++ return; ++ } ++ mpi->flags|=MP_IMGFLAG_YUV; ++ mpi->num_planes=3; ++ if (mp_get_chroma_shift(out_fmt, NULL, NULL)) { ++ mpi->flags|=MP_IMGFLAG_PLANAR; ++ mpi->bpp = mp_get_chroma_shift(out_fmt, &mpi->chroma_x_shift, &mpi->chroma_y_shift); ++ mpi->chroma_width = mpi->width >> mpi->chroma_x_shift; ++ mpi->chroma_height = mpi->height >> mpi->chroma_y_shift; ++ } ++ switch(out_fmt){ ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ mpi->flags|=MP_IMGFLAG_SWAPPED; ++ case IMGFMT_YV12: ++ return; ++ case IMGFMT_420A: ++ case IMGFMT_IF09: ++ mpi->num_planes=4; ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ case IMGFMT_440P: ++ case IMGFMT_444P16_LE: ++ case IMGFMT_444P16_BE: ++ case IMGFMT_422P16_LE: ++ case IMGFMT_422P16_BE: ++ case IMGFMT_420P16_LE: ++ case IMGFMT_420P16_BE: ++ return; ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ /* they're planar ones, but for easier handling use them as packed */ ++ mpi->flags&=~MP_IMGFLAG_PLANAR; ++ mpi->num_planes=1; ++ return; ++ case IMGFMT_UYVY: ++ mpi->flags|=MP_IMGFLAG_SWAPPED; ++ case IMGFMT_YUY2: ++ mpi->bpp=16; ++ mpi->num_planes=1; ++ return; ++ case IMGFMT_NV12: ++ mpi->flags|=MP_IMGFLAG_SWAPPED; ++ case IMGFMT_NV21: ++ mpi->flags|=MP_IMGFLAG_PLANAR; ++ mpi->bpp=12; ++ mpi->num_planes=2; ++ mpi->chroma_width=(mpi->width>>0); ++ mpi->chroma_height=(mpi->height>>1); ++ mpi->chroma_x_shift=0; ++ mpi->chroma_y_shift=1; ++ return; ++ } ++ mp_msg(MSGT_DECVIDEO,MSGL_WARN,"mp_image: unknown out_fmt: 0x%X\n",out_fmt); ++ mpi->bpp=0; ++} ++ ++mp_image_t* new_mp_image(int w,int h){ ++ mp_image_t* mpi = malloc(sizeof(mp_image_t)); ++ if(!mpi) return NULL; // error! ++ memset(mpi,0,sizeof(mp_image_t)); ++ mpi->width=mpi->w=w; ++ mpi->height=mpi->h=h; ++ return mpi; ++} ++ ++void free_mp_image(mp_image_t* mpi){ ++ if(!mpi) return; ++ if(mpi->flags&MP_IMGFLAG_ALLOCATED){ ++ /* becouse we allocate the whole image in once */ ++ av_free(mpi->planes[0]); ++ if (mpi->flags & MP_IMGFLAG_RGB_PALETTE) ++ av_free(mpi->planes[1]); ++ } ++ free(mpi); ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_image.h 2012-05-14 14:08:54.724347831 +0200 +@@ -0,0 +1,150 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_MP_IMAGE_H ++#define MPLAYER_MP_IMAGE_H ++ ++#include ++#include ++#include ++#undef printf //FIXME ++#undef fprintf //FIXME ++#include "mp_msg.h" ++#include "libavutil/avutil.h" ++#include "libavutil/avassert.h" ++#undef realloc ++#undef malloc ++#undef free ++#undef rand ++#undef srand ++#undef printf ++#undef strncpy ++#define ASMALIGN(ZEROBITS) ".p2align " #ZEROBITS "\n\t" ++ ++ ++//--------- codec's requirements (filled by the codec/vf) --------- ++ ++//--- buffer content restrictions: ++// set if buffer content shouldn't be modified: ++#define MP_IMGFLAG_PRESERVE 0x01 ++// set if buffer content will be READ for next frame's MC: (I/P mpeg frames) ++#define MP_IMGFLAG_READABLE 0x02 ++ ++//--- buffer width/stride/plane restrictions: (used for direct rendering) ++// stride _have_to_ be aligned to MB boundary: [for DR restrictions] ++#define MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE 0x4 ++// stride should be aligned to MB boundary: [for buffer allocation] ++#define MP_IMGFLAG_PREFER_ALIGNED_STRIDE 0x8 ++// codec accept any stride (>=width): ++#define MP_IMGFLAG_ACCEPT_STRIDE 0x10 ++// codec accept any width (width*bpp=stride -> stride%bpp==0) (>=width): ++#define MP_IMGFLAG_ACCEPT_WIDTH 0x20 ++//--- for planar formats only: ++// uses only stride[0], and stride[1]=stride[2]=stride[0]>>mpi->chroma_x_shift ++#define MP_IMGFLAG_COMMON_STRIDE 0x40 ++// uses only planes[0], and calculates planes[1,2] from width,height,imgfmt ++#define MP_IMGFLAG_COMMON_PLANE 0x80 ++ ++#define MP_IMGFLAGMASK_RESTRICTIONS 0xFF ++ ++//--------- color info (filled by mp_image_setfmt() ) ----------- ++// set if number of planes > 1 ++#define MP_IMGFLAG_PLANAR 0x100 ++// set if it's YUV colorspace ++#define MP_IMGFLAG_YUV 0x200 ++// set if it's swapped (BGR or YVU) plane/byteorder ++#define MP_IMGFLAG_SWAPPED 0x400 ++// set if you want memory for palette allocated and managed by vf_get_image etc. ++#define MP_IMGFLAG_RGB_PALETTE 0x800 ++ ++#define MP_IMGFLAGMASK_COLORS 0xF00 ++ ++// codec uses drawing/rendering callbacks (draw_slice()-like thing, DR method 2) ++// [the codec will set this flag if it supports callbacks, and the vo _may_ ++// clear it in get_image() if draw_slice() not implemented] ++#define MP_IMGFLAG_DRAW_CALLBACK 0x1000 ++// set if it's in video buffer/memory: [set by vo/vf's get_image() !!!] ++#define MP_IMGFLAG_DIRECT 0x2000 ++// set if buffer is allocated (used in destination images): ++#define MP_IMGFLAG_ALLOCATED 0x4000 ++ ++// buffer type was printed (do NOT set this flag - it's for INTERNAL USE!!!) ++#define MP_IMGFLAG_TYPE_DISPLAYED 0x8000 ++ ++// codec doesn't support any form of direct rendering - it has own buffer ++// allocation. so we just export its buffer pointers: ++#define MP_IMGTYPE_EXPORT 0 ++// codec requires a static WO buffer, but it does only partial updates later: ++#define MP_IMGTYPE_STATIC 1 ++// codec just needs some WO memory, where it writes/copies the whole frame to: ++#define MP_IMGTYPE_TEMP 2 ++// I+P type, requires 2+ independent static R/W buffers ++#define MP_IMGTYPE_IP 3 ++// I+P+B type, requires 2+ independent static R/W and 1+ temp WO buffers ++#define MP_IMGTYPE_IPB 4 ++// Upper 16 bits give desired buffer number, -1 means get next available ++#define MP_IMGTYPE_NUMBERED 5 ++// Doesn't need any buffer, incomplete image (probably a first field only) ++// we need this type to be able to differentiate between half frames and ++// all other cases ++#define MP_IMGTYPE_INCOMPLETE 6 ++ ++#define MP_MAX_PLANES 4 ++ ++#define MP_IMGFIELD_ORDERED 0x01 ++#define MP_IMGFIELD_TOP_FIRST 0x02 ++#define MP_IMGFIELD_REPEAT_FIRST 0x04 ++#define MP_IMGFIELD_TOP 0x08 ++#define MP_IMGFIELD_BOTTOM 0x10 ++#define MP_IMGFIELD_INTERLACED 0x20 ++ ++typedef struct mp_image { ++ unsigned int flags; ++ unsigned char type; ++ int number; ++ unsigned char bpp; // bits/pixel. NOT depth! for RGB it will be n*8 ++ unsigned int imgfmt; ++ int width,height; // stored dimensions ++ int x,y,w,h; // visible dimensions ++ unsigned char* planes[MP_MAX_PLANES]; ++ int stride[MP_MAX_PLANES]; ++ char * qscale; ++ int qstride; ++ int pict_type; // 0->unknown, 1->I, 2->P, 3->B ++ int fields; ++ int qscale_type; // 0->mpeg1/4/h263, 1->mpeg2 ++ int num_planes; ++ /* these are only used by planar formats Y,U(Cb),V(Cr) */ ++ int chroma_width; ++ int chroma_height; ++ int chroma_x_shift; // horizontal ++ int chroma_y_shift; // vertical ++ int usage_count; ++ /* for private use by filter or vo driver (to store buffer id or dmpi) */ ++ void* priv; ++} mp_image_t; ++ ++void mp_image_setfmt(mp_image_t* mpi,unsigned int out_fmt); ++mp_image_t* new_mp_image(int w,int h); ++void free_mp_image(mp_image_t* mpi); ++ ++mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt); ++void mp_image_alloc_planes(mp_image_t *mpi); ++void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi); ++ ++#endif /* MPLAYER_MP_IMAGE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_msg.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_msg.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/mp_msg.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/mp_msg.h 2012-05-14 14:08:54.725347851 +0200 +@@ -0,0 +1,164 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_MP_MSG_H ++#define MPLAYER_MP_MSG_H ++ ++#include ++ ++// defined in mplayer.c and mencoder.c ++extern int verbose; ++ ++// verbosity elevel: ++ ++/* Only messages level MSGL_FATAL-MSGL_STATUS should be translated, ++ * messages level MSGL_V and above should not be translated. */ ++ ++#define MSGL_FATAL 0 // will exit/abort ++#define MSGL_ERR 1 // continues ++#define MSGL_WARN 2 // only warning ++#define MSGL_HINT 3 // short help message ++#define MSGL_INFO 4 // -quiet ++#define MSGL_STATUS 5 // v=0 ++#define MSGL_V 6 // v=1 ++#define MSGL_DBG2 7 // v=2 ++#define MSGL_DBG3 8 // v=3 ++#define MSGL_DBG4 9 // v=4 ++#define MSGL_DBG5 10 // v=5 ++ ++#define MSGL_FIXME 1 // for conversions from printf where the appropriate MSGL is not known; set equal to ERR for obtrusiveness ++#define MSGT_FIXME 0 // for conversions from printf where the appropriate MSGT is not known; set equal to GLOBAL for obtrusiveness ++ ++// code/module: ++ ++#define MSGT_GLOBAL 0 // common player stuff errors ++#define MSGT_CPLAYER 1 // console player (mplayer.c) ++#define MSGT_GPLAYER 2 // gui player ++ ++#define MSGT_VO 3 // libvo ++#define MSGT_AO 4 // libao ++ ++#define MSGT_DEMUXER 5 // demuxer.c (general stuff) ++#define MSGT_DS 6 // demux stream (add/read packet etc) ++#define MSGT_DEMUX 7 // fileformat-specific stuff (demux_*.c) ++#define MSGT_HEADER 8 // fileformat-specific header (*header.c) ++ ++#define MSGT_AVSYNC 9 // mplayer.c timer stuff ++#define MSGT_AUTOQ 10 // mplayer.c auto-quality stuff ++ ++#define MSGT_CFGPARSER 11 // cfgparser.c ++ ++#define MSGT_DECAUDIO 12 // av decoder ++#define MSGT_DECVIDEO 13 ++ ++#define MSGT_SEEK 14 // seeking code ++#define MSGT_WIN32 15 // win32 dll stuff ++#define MSGT_OPEN 16 // open.c (stream opening) ++#define MSGT_DVD 17 // open.c (DVD init/read/seek) ++ ++#define MSGT_PARSEES 18 // parse_es.c (mpeg stream parser) ++#define MSGT_LIRC 19 // lirc_mp.c and input lirc driver ++ ++#define MSGT_STREAM 20 // stream.c ++#define MSGT_CACHE 21 // cache2.c ++ ++#define MSGT_MENCODER 22 ++ ++#define MSGT_XACODEC 23 // XAnim codecs ++ ++#define MSGT_TV 24 // TV input subsystem ++ ++#define MSGT_OSDEP 25 // OS-dependent parts ++ ++#define MSGT_SPUDEC 26 // spudec.c ++ ++#define MSGT_PLAYTREE 27 // Playtree handeling (playtree.c, playtreeparser.c) ++ ++#define MSGT_INPUT 28 ++ ++#define MSGT_VFILTER 29 ++ ++#define MSGT_OSD 30 ++ ++#define MSGT_NETWORK 31 ++ ++#define MSGT_CPUDETECT 32 ++ ++#define MSGT_CODECCFG 33 ++ ++#define MSGT_SWS 34 ++ ++#define MSGT_VOBSUB 35 ++#define MSGT_SUBREADER 36 ++ ++#define MSGT_AFILTER 37 // Audio filter messages ++ ++#define MSGT_NETST 38 // Netstream ++ ++#define MSGT_MUXER 39 // muxer layer ++ ++#define MSGT_OSD_MENU 40 ++ ++#define MSGT_IDENTIFY 41 // -identify output ++ ++#define MSGT_RADIO 42 ++ ++#define MSGT_ASS 43 // libass messages ++ ++#define MSGT_LOADER 44 // dll loader messages ++ ++#define MSGT_STATUSLINE 45 // playback/encoding status line ++ ++#define MSGT_TELETEXT 46 // Teletext decoder ++ ++#define MSGT_MAX 64 ++ ++ ++extern char *mp_msg_charset; ++extern int mp_msg_color; ++extern int mp_msg_module; ++ ++extern int mp_msg_levels[MSGT_MAX]; ++extern int mp_msg_level_all; ++ ++ ++void mp_msg_init(void); ++int mp_msg_test(int mod, int lev); ++ ++#include "config.h" ++ ++void mp_msg_va(int mod, int lev, const char *format, va_list va); ++#ifdef __GNUC__ ++void mp_msg(int mod, int lev, const char *format, ... ) __attribute__ ((format (printf, 3, 4))); ++# ifdef MP_DEBUG ++# define mp_dbg(mod,lev, args... ) mp_msg(mod, lev, ## args ) ++# else ++# define mp_dbg(mod,lev, args... ) /* only useful for developers */ ++# endif ++#else // not GNU C ++void mp_msg(int mod, int lev, const char *format, ... ); ++# ifdef MP_DEBUG ++# define mp_dbg(mod,lev, ... ) mp_msg(mod, lev, __VA_ARGS__) ++# else ++# define mp_dbg(mod,lev, ... ) /* only useful for developers */ ++# endif ++#endif /* __GNUC__ */ ++ ++const char* filename_recode(const char* filename); ++ ++#endif /* MPLAYER_MP_MSG_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/pullup.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/pullup.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/pullup.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/pullup.c 2012-05-14 14:08:54.728347911 +0200 +@@ -0,0 +1,822 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include "config.h" ++#include "pullup.h" ++#include "cpudetect.h" ++ ++ ++ ++#if ARCH_X86 ++#if HAVE_MMX ++static int diff_y_mmx(unsigned char *a, unsigned char *b, int s) ++{ ++ int ret; ++ __asm__ volatile ( ++ "movl $4, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ ++ "1: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "add %%"REG_a", %%"REG_D" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm4 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 1b \n\t" ++ ++ "movq %%mm4, %%mm3 \n\t" ++ "punpcklwd %%mm7, %%mm4 \n\t" ++ "punpckhwd %%mm7, %%mm3 \n\t" ++ "paddd %%mm4, %%mm3 \n\t" ++ "movd %%mm3, %%eax \n\t" ++ "psrlq $32, %%mm3 \n\t" ++ "movd %%mm3, %%edx \n\t" ++ "addl %%edx, %%eax \n\t" ++ "emms \n\t" ++ : "=a" (ret) ++ : "S" (a), "D" (b), "a" (s) ++ : "%ecx", "%edx" ++ ); ++ return ret; ++} ++ ++static int licomb_y_mmx(unsigned char *a, unsigned char *b, int s) ++{ ++ int ret; ++ __asm__ volatile ( ++ "movl $4, %%ecx \n\t" ++ "pxor %%mm6, %%mm6 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ "sub %%"REG_a", %%"REG_D" \n\t" ++ ++ "2: \n\t" ++ ++ "movq (%%"REG_D"), %%mm0 \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm2 \n\t" ++ "paddw %%mm0, %%mm0 \n\t" ++ "paddw %%mm2, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "psubusw %%mm1, %%mm0 \n\t" ++ "psubusw %%mm2, %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ "paddw %%mm1, %%mm6 \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm0 \n\t" ++ "movq (%%"REG_D",%%"REG_a"), %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "paddw %%mm0, %%mm0 \n\t" ++ "paddw %%mm2, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "psubusw %%mm1, %%mm0 \n\t" ++ "psubusw %%mm2, %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ "paddw %%mm1, %%mm6 \n\t" ++ ++ "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm2 \n\t" ++ "paddw %%mm0, %%mm0 \n\t" ++ "paddw %%mm2, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "psubusw %%mm1, %%mm0 \n\t" ++ "psubusw %%mm2, %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ "paddw %%mm1, %%mm6 \n\t" ++ ++ "movq (%%"REG_D",%%"REG_a"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm0 \n\t" ++ "movq (%%"REG_S",%%"REG_a"), %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "paddw %%mm0, %%mm0 \n\t" ++ "paddw %%mm2, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "psubusw %%mm1, %%mm0 \n\t" ++ "psubusw %%mm2, %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ "paddw %%mm1, %%mm6 \n\t" ++ ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "add %%"REG_a", %%"REG_D" \n\t" ++ "decl %%ecx \n\t" ++ "jnz 2b \n\t" ++ ++ "movq %%mm6, %%mm5 \n\t" ++ "punpcklwd %%mm7, %%mm6 \n\t" ++ "punpckhwd %%mm7, %%mm5 \n\t" ++ "paddd %%mm6, %%mm5 \n\t" ++ "movd %%mm5, %%eax \n\t" ++ "psrlq $32, %%mm5 \n\t" ++ "movd %%mm5, %%edx \n\t" ++ "addl %%edx, %%eax \n\t" ++ ++ "emms \n\t" ++ : "=a" (ret) ++ : "S" (a), "D" (b), "a" (s) ++ : "%ecx", "%edx" ++ ); ++ return ret; ++} ++ ++static int var_y_mmx(unsigned char *a, unsigned char *b, int s) ++{ ++ int ret; ++ __asm__ volatile ( ++ "movl $3, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ ++ "1: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm4 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 1b \n\t" ++ ++ "movq %%mm4, %%mm3 \n\t" ++ "punpcklwd %%mm7, %%mm4 \n\t" ++ "punpckhwd %%mm7, %%mm3 \n\t" ++ "paddd %%mm4, %%mm3 \n\t" ++ "movd %%mm3, %%eax \n\t" ++ "psrlq $32, %%mm3 \n\t" ++ "movd %%mm3, %%edx \n\t" ++ "addl %%edx, %%eax \n\t" ++ "emms \n\t" ++ : "=a" (ret) ++ : "S" (a), "a" (s) ++ : "%ecx", "%edx" ++ ); ++ return 4*ret; ++} ++#endif ++#endif ++ ++#define ABS(a) (((a)^((a)>>31))-((a)>>31)) ++ ++static int diff_y(unsigned char *a, unsigned char *b, int s) ++{ ++ int i, j, diff=0; ++ for (i=4; i; i--) { ++ for (j=0; j<8; j++) diff += ABS(a[j]-b[j]); ++ a+=s; b+=s; ++ } ++ return diff; ++} ++ ++static int licomb_y(unsigned char *a, unsigned char *b, int s) ++{ ++ int i, j, diff=0; ++ for (i=4; i; i--) { ++ for (j=0; j<8; j++) ++ diff += ABS((a[j]<<1) - b[j-s] - b[j]) ++ + ABS((b[j]<<1) - a[j] - a[j+s]); ++ a+=s; b+=s; ++ } ++ return diff; ++} ++ ++#if 0 ++static int qpcomb_y(unsigned char *a, unsigned char *b, int s) ++{ ++ int i, j, diff=0; ++ for (i=4; i; i--) { ++ for (j=0; j<8; j++) ++ diff += ABS(a[j] - 3*b[j-s] + 3*a[j+s] - b[j]); ++ a+=s; b+=s; ++ } ++ return diff; ++} ++ ++static int licomb_y_test(unsigned char *a, unsigned char *b, int s) ++{ ++ int c = licomb_y(a,b,s); ++ int m = licomb_y_mmx(a,b,s); ++ if (c != m) printf("%d != %d\n", c, m); ++ return m; ++} ++#endif ++ ++static int var_y(unsigned char *a, unsigned char *b, int s) ++{ ++ int i, j, var=0; ++ for (i=3; i; i--) { ++ for (j=0; j<8; j++) { ++ var += ABS(a[j]-a[j+s]); ++ } ++ a+=s; b+=s; ++ } ++ return 4*var; /* match comb scaling */ ++} ++ ++ ++ ++ ++ ++ ++ ++ ++ ++static void alloc_buffer(struct pullup_context *c, struct pullup_buffer *b) ++{ ++ int i; ++ if (b->planes) return; ++ b->planes = calloc(c->nplanes, sizeof(unsigned char *)); ++ for (i = 0; i < c->nplanes; i++) { ++ b->planes[i] = malloc(c->h[i]*c->stride[i]); ++ /* Deal with idiotic 128=0 for chroma: */ ++ memset(b->planes[i], c->background[i], c->h[i]*c->stride[i]); ++ } ++} ++ ++struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity) ++{ ++ if (!b) return 0; ++ if ((parity+1) & 1) b->lock[0]++; ++ if ((parity+1) & 2) b->lock[1]++; ++ return b; ++} ++ ++void pullup_release_buffer(struct pullup_buffer *b, int parity) ++{ ++ if (!b) return; ++ if ((parity+1) & 1) b->lock[0]--; ++ if ((parity+1) & 2) b->lock[1]--; ++} ++ ++struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity) ++{ ++ int i; ++ ++ /* Try first to get the sister buffer for the previous field */ ++ if (parity < 2 && c->last && parity != c->last->parity ++ && !c->last->buffer->lock[parity]) { ++ alloc_buffer(c, c->last->buffer); ++ return pullup_lock_buffer(c->last->buffer, parity); ++ } ++ ++ /* Prefer a buffer with both fields open */ ++ for (i = 0; i < c->nbuffers; i++) { ++ if (c->buffers[i].lock[0]) continue; ++ if (c->buffers[i].lock[1]) continue; ++ alloc_buffer(c, &c->buffers[i]); ++ return pullup_lock_buffer(&c->buffers[i], parity); ++ } ++ ++ if (parity == 2) return 0; ++ ++ /* Search for any half-free buffer */ ++ for (i = 0; i < c->nbuffers; i++) { ++ if (((parity+1) & 1) && c->buffers[i].lock[0]) continue; ++ if (((parity+1) & 2) && c->buffers[i].lock[1]) continue; ++ alloc_buffer(c, &c->buffers[i]); ++ return pullup_lock_buffer(&c->buffers[i], parity); ++ } ++ ++ return 0; ++} ++ ++ ++ ++ ++ ++ ++static void compute_metric(struct pullup_context *c, ++ struct pullup_field *fa, int pa, ++ struct pullup_field *fb, int pb, ++ int (*func)(unsigned char *, unsigned char *, int), int *dest) ++{ ++ unsigned char *a, *b; ++ int x, y; ++ int mp = c->metric_plane; ++ int xstep = c->bpp[mp]; ++ int ystep = c->stride[mp]<<3; ++ int s = c->stride[mp]<<1; /* field stride */ ++ int w = c->metric_w*xstep; ++ ++ if (!fa->buffer || !fb->buffer) return; ++ ++ /* Shortcut for duplicate fields (e.g. from RFF flag) */ ++ if (fa->buffer == fb->buffer && pa == pb) { ++ memset(dest, 0, c->metric_len * sizeof(int)); ++ return; ++ } ++ ++ a = fa->buffer->planes[mp] + pa * c->stride[mp] + c->metric_offset; ++ b = fb->buffer->planes[mp] + pb * c->stride[mp] + c->metric_offset; ++ ++ for (y = c->metric_h; y; y--) { ++ for (x = 0; x < w; x += xstep) { ++ *dest++ = func(a + x, b + x, s); ++ } ++ a += ystep; b += ystep; ++ } ++} ++ ++ ++ ++ ++ ++static void alloc_metrics(struct pullup_context *c, struct pullup_field *f) ++{ ++ f->diffs = calloc(c->metric_len, sizeof(int)); ++ f->comb = calloc(c->metric_len, sizeof(int)); ++ f->var = calloc(c->metric_len, sizeof(int)); ++ /* add more metrics here as needed */ ++} ++ ++static struct pullup_field *make_field_queue(struct pullup_context *c, int len) ++{ ++ struct pullup_field *head, *f; ++ f = head = calloc(1, sizeof(struct pullup_field)); ++ alloc_metrics(c, f); ++ for (; len > 0; len--) { ++ f->next = calloc(1, sizeof(struct pullup_field)); ++ f->next->prev = f; ++ f = f->next; ++ alloc_metrics(c, f); ++ } ++ f->next = head; ++ head->prev = f; ++ return head; ++} ++ ++static void check_field_queue(struct pullup_context *c) ++{ ++ if (c->head->next == c->first) { ++ struct pullup_field *f = calloc(1, sizeof(struct pullup_field)); ++ alloc_metrics(c, f); ++ f->prev = c->head; ++ f->next = c->first; ++ c->head->next = f; ++ c->first->prev = f; ++ } ++} ++ ++void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity) ++{ ++ struct pullup_field *f; ++ ++ /* Grow the circular list if needed */ ++ check_field_queue(c); ++ ++ /* Cannot have two fields of same parity in a row; drop the new one */ ++ if (c->last && c->last->parity == parity) return; ++ ++ f = c->head; ++ f->parity = parity; ++ f->buffer = pullup_lock_buffer(b, parity); ++ f->flags = 0; ++ f->breaks = 0; ++ f->affinity = 0; ++ ++ compute_metric(c, f, parity, f->prev->prev, parity, c->diff, f->diffs); ++ compute_metric(c, parity?f->prev:f, 0, parity?f:f->prev, 1, c->comb, f->comb); ++ compute_metric(c, f, parity, f, -1, c->var, f->var); ++ ++ /* Advance the circular list */ ++ if (!c->first) c->first = c->head; ++ c->last = c->head; ++ c->head = c->head->next; ++} ++ ++void pullup_flush_fields(struct pullup_context *c) ++{ ++ struct pullup_field *f; ++ ++ for (f = c->first; f && f != c->head; f = f->next) { ++ pullup_release_buffer(f->buffer, f->parity); ++ f->buffer = 0; ++ } ++ c->first = c->last = 0; ++} ++ ++ ++ ++ ++ ++ ++ ++ ++#define F_HAVE_BREAKS 1 ++#define F_HAVE_AFFINITY 2 ++ ++ ++#define BREAK_LEFT 1 ++#define BREAK_RIGHT 2 ++ ++ ++ ++ ++static int queue_length(struct pullup_field *begin, struct pullup_field *end) ++{ ++ int count = 1; ++ struct pullup_field *f; ++ ++ if (!begin || !end) return 0; ++ for (f = begin; f != end; f = f->next) count++; ++ return count; ++} ++ ++static int find_first_break(struct pullup_field *f, int max) ++{ ++ int i; ++ for (i = 0; i < max; i++) { ++ if (f->breaks & BREAK_RIGHT || f->next->breaks & BREAK_LEFT) ++ return i+1; ++ f = f->next; ++ } ++ return 0; ++} ++ ++static void compute_breaks(struct pullup_context *c, struct pullup_field *f0) ++{ ++ int i; ++ struct pullup_field *f1 = f0->next; ++ struct pullup_field *f2 = f1->next; ++ struct pullup_field *f3 = f2->next; ++ int l, max_l=0, max_r=0; ++ //struct pullup_field *ff; ++ //for (i=0, ff=c->first; ff != f0; i++, ff=ff->next); ++ ++ if (f0->flags & F_HAVE_BREAKS) return; ++ //printf("\n%d: ", i); ++ f0->flags |= F_HAVE_BREAKS; ++ ++ /* Special case when fields are 100% identical */ ++ if (f0->buffer == f2->buffer && f1->buffer != f3->buffer) { ++ f2->breaks |= BREAK_RIGHT; ++ return; ++ } ++ if (f0->buffer != f2->buffer && f1->buffer == f3->buffer) { ++ f1->breaks |= BREAK_LEFT; ++ return; ++ } ++ ++ for (i = 0; i < c->metric_len; i++) { ++ l = f2->diffs[i] - f3->diffs[i]; ++ if (l > max_l) max_l = l; ++ if (-l > max_r) max_r = -l; ++ } ++ /* Don't get tripped up when differences are mostly quant error */ ++ //printf("%d %d\n", max_l, max_r); ++ if (max_l + max_r < 128) return; ++ if (max_l > 4*max_r) f1->breaks |= BREAK_LEFT; ++ if (max_r > 4*max_l) f2->breaks |= BREAK_RIGHT; ++} ++ ++static void compute_affinity(struct pullup_context *c, struct pullup_field *f) ++{ ++ int i; ++ int max_l=0, max_r=0, l; ++ if (f->flags & F_HAVE_AFFINITY) return; ++ f->flags |= F_HAVE_AFFINITY; ++ if (f->buffer == f->next->next->buffer) { ++ f->affinity = 1; ++ f->next->affinity = 0; ++ f->next->next->affinity = -1; ++ f->next->flags |= F_HAVE_AFFINITY; ++ f->next->next->flags |= F_HAVE_AFFINITY; ++ return; ++ } ++ if (1) { ++ for (i = 0; i < c->metric_len; i++) { ++ int lv = f->prev->var[i]; ++ int rv = f->next->var[i]; ++ int v = f->var[i]; ++ int lc = f->comb[i] - (v+lv) + ABS(v-lv); ++ int rc = f->next->comb[i] - (v+rv) + ABS(v-rv); ++ lc = lc>0 ? lc : 0; ++ rc = rc>0 ? rc : 0; ++ l = lc - rc; ++ if (l > max_l) max_l = l; ++ if (-l > max_r) max_r = -l; ++ } ++ if (max_l + max_r < 64) return; ++ if (max_r > 6*max_l) f->affinity = -1; ++ else if (max_l > 6*max_r) f->affinity = 1; ++ } else { ++ for (i = 0; i < c->metric_len; i++) { ++ l = f->comb[i] - f->next->comb[i]; ++ if (l > max_l) max_l = l; ++ if (-l > max_r) max_r = -l; ++ } ++ if (max_l + max_r < 64) return; ++ if (max_r > 2*max_l) f->affinity = -1; ++ else if (max_l > 2*max_r) f->affinity = 1; ++ } ++} ++ ++static void foo(struct pullup_context *c) ++{ ++ struct pullup_field *f = c->first; ++ int i, n = queue_length(f, c->last); ++ for (i = 0; i < n-1; i++) { ++ if (i < n-3) compute_breaks(c, f); ++ compute_affinity(c, f); ++ f = f->next; ++ } ++} ++ ++static int decide_frame_length(struct pullup_context *c) ++{ ++ struct pullup_field *f0 = c->first; ++ struct pullup_field *f1 = f0->next; ++ struct pullup_field *f2 = f1->next; ++ int l; ++ ++ if (queue_length(c->first, c->last) < 4) return 0; ++ foo(c); ++ ++ if (f0->affinity == -1) return 1; ++ ++ l = find_first_break(f0, 3); ++ if (l == 1 && c->strict_breaks < 0) l = 0; ++ ++ switch (l) { ++ case 1: ++ if (c->strict_breaks < 1 && f0->affinity == 1 && f1->affinity == -1) ++ return 2; ++ else return 1; ++ case 2: ++ /* FIXME: strictly speaking, f0->prev is no longer valid... :) */ ++ if (c->strict_pairs ++ && (f0->prev->breaks & BREAK_RIGHT) && (f2->breaks & BREAK_LEFT) ++ && (f0->affinity != 1 || f1->affinity != -1) ) ++ return 1; ++ if (f1->affinity == 1) return 1; ++ else return 2; ++ case 3: ++ if (f2->affinity == 1) return 2; ++ else return 3; ++ default: ++ /* 9 possibilities covered before switch */ ++ if (f1->affinity == 1) return 1; /* covers 6 */ ++ else if (f1->affinity == -1) return 2; /* covers 6 */ ++ else if (f2->affinity == -1) { /* covers 2 */ ++ if (f0->affinity == 1) return 3; ++ else return 1; ++ } ++ else return 2; /* the remaining 6 */ ++ } ++} ++ ++ ++static void print_aff_and_breaks(struct pullup_context *c, struct pullup_field *f) ++{ ++ int i; ++ struct pullup_field *f0 = f; ++ const char aff_l[] = "+..", aff_r[] = "..+"; ++ printf("\naffinity: "); ++ for (i = 0; i < 4; i++) { ++ printf("%c%d%c", aff_l[1+f->affinity], i, aff_r[1+f->affinity]); ++ f = f->next; ++ } ++ f = f0; ++ printf("\nbreaks: "); ++ for (i=0; i<4; i++) { ++ printf("%c%d%c", f->breaks & BREAK_LEFT ? '|' : '.', i, f->breaks & BREAK_RIGHT ? '|' : '.'); ++ f = f->next; ++ } ++ printf("\n"); ++} ++ ++ ++ ++ ++ ++struct pullup_frame *pullup_get_frame(struct pullup_context *c) ++{ ++ int i; ++ struct pullup_frame *fr = c->frame; ++ int n = decide_frame_length(c); ++ int aff = c->first->next->affinity; ++ ++ if (!n) return 0; ++ if (fr->lock) return 0; ++ ++ if (c->verbose) { ++ print_aff_and_breaks(c, c->first); ++ printf("duration: %d \n", n); ++ } ++ ++ fr->lock++; ++ fr->length = n; ++ fr->parity = c->first->parity; ++ fr->buffer = 0; ++ for (i = 0; i < n; i++) { ++ /* We cheat and steal the buffer without release+relock */ ++ fr->ifields[i] = c->first->buffer; ++ c->first->buffer = 0; ++ c->first = c->first->next; ++ } ++ ++ if (n == 1) { ++ fr->ofields[fr->parity] = fr->ifields[0]; ++ fr->ofields[fr->parity^1] = 0; ++ } else if (n == 2) { ++ fr->ofields[fr->parity] = fr->ifields[0]; ++ fr->ofields[fr->parity^1] = fr->ifields[1]; ++ } else if (n == 3) { ++ if (aff == 0) ++ aff = (fr->ifields[0] == fr->ifields[1]) ? -1 : 1; ++ /* else if (c->verbose) printf("forced aff: %d \n", aff); */ ++ fr->ofields[fr->parity] = fr->ifields[1+aff]; ++ fr->ofields[fr->parity^1] = fr->ifields[1]; ++ } ++ pullup_lock_buffer(fr->ofields[0], 0); ++ pullup_lock_buffer(fr->ofields[1], 1); ++ ++ if (fr->ofields[0] == fr->ofields[1]) { ++ fr->buffer = fr->ofields[0]; ++ pullup_lock_buffer(fr->buffer, 2); ++ return fr; ++ } ++ return fr; ++} ++ ++static void copy_field(struct pullup_context *c, struct pullup_buffer *dest, ++ struct pullup_buffer *src, int parity) ++{ ++ int i, j; ++ unsigned char *d, *s; ++ for (i = 0; i < c->nplanes; i++) { ++ s = src->planes[i] + parity*c->stride[i]; ++ d = dest->planes[i] + parity*c->stride[i]; ++ for (j = c->h[i]>>1; j; j--) { ++ memcpy(d, s, c->stride[i]); ++ s += c->stride[i]<<1; ++ d += c->stride[i]<<1; ++ } ++ } ++} ++ ++void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr) ++{ ++ int i; ++ if (fr->buffer) return; ++ if (fr->length < 2) return; /* FIXME: deal with this */ ++ for (i = 0; i < 2; i++) ++ { ++ if (fr->ofields[i]->lock[i^1]) continue; ++ fr->buffer = fr->ofields[i]; ++ pullup_lock_buffer(fr->buffer, 2); ++ copy_field(c, fr->buffer, fr->ofields[i^1], i^1); ++ return; ++ } ++ fr->buffer = pullup_get_buffer(c, 2); ++ copy_field(c, fr->buffer, fr->ofields[0], 0); ++ copy_field(c, fr->buffer, fr->ofields[1], 1); ++} ++ ++void pullup_release_frame(struct pullup_frame *fr) ++{ ++ int i; ++ for (i = 0; i < fr->length; i++) ++ pullup_release_buffer(fr->ifields[i], fr->parity ^ (i&1)); ++ pullup_release_buffer(fr->ofields[0], 0); ++ pullup_release_buffer(fr->ofields[1], 1); ++ if (fr->buffer) pullup_release_buffer(fr->buffer, 2); ++ fr->lock--; ++} ++ ++ ++ ++ ++ ++ ++struct pullup_context *pullup_alloc_context(void) ++{ ++ struct pullup_context *c; ++ ++ c = calloc(1, sizeof(struct pullup_context)); ++ ++ return c; ++} ++ ++void pullup_preinit_context(struct pullup_context *c) ++{ ++ c->bpp = calloc(c->nplanes, sizeof(int)); ++ c->w = calloc(c->nplanes, sizeof(int)); ++ c->h = calloc(c->nplanes, sizeof(int)); ++ c->stride = calloc(c->nplanes, sizeof(int)); ++ c->background = calloc(c->nplanes, sizeof(int)); ++} ++ ++void pullup_init_context(struct pullup_context *c) ++{ ++ int mp = c->metric_plane; ++ if (c->nbuffers < 10) c->nbuffers = 10; ++ c->buffers = calloc(c->nbuffers, sizeof (struct pullup_buffer)); ++ ++ c->metric_w = (c->w[mp] - ((c->junk_left + c->junk_right) << 3)) >> 3; ++ c->metric_h = (c->h[mp] - ((c->junk_top + c->junk_bottom) << 1)) >> 3; ++ c->metric_offset = c->junk_left*c->bpp[mp] + (c->junk_top<<1)*c->stride[mp]; ++ c->metric_len = c->metric_w * c->metric_h; ++ ++ c->head = make_field_queue(c, 8); ++ ++ c->frame = calloc(1, sizeof (struct pullup_frame)); ++ c->frame->ifields = calloc(3, sizeof (struct pullup_buffer *)); ++ ++ switch(c->format) { ++ case PULLUP_FMT_Y: ++ c->diff = diff_y; ++ c->comb = licomb_y; ++ c->var = var_y; ++#if ARCH_X86 ++#if HAVE_MMX ++ if (c->cpu & PULLUP_CPU_MMX) { ++ c->diff = diff_y_mmx; ++ c->comb = licomb_y_mmx; ++ c->var = var_y_mmx; ++ } ++#endif ++#endif ++ /* c->comb = qpcomb_y; */ ++ break; ++#if 0 ++ case PULLUP_FMT_YUY2: ++ c->diff = diff_yuy2; ++ break; ++ case PULLUP_FMT_RGB32: ++ c->diff = diff_rgb32; ++ break; ++#endif ++ } ++} ++ ++void pullup_free_context(struct pullup_context *c) ++{ ++ struct pullup_field *f; ++ free(c->buffers); ++ f = c->head; ++ do { ++ if (!f) break; ++ free(f->diffs); ++ free(f->comb); ++ f = f->next; ++ free(f->prev); ++ } while (f != c->head); ++ free(c->frame); ++ free(c); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/pullup.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/pullup.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/pullup.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/pullup.h 2012-05-14 14:08:54.728347911 +0200 +@@ -0,0 +1,102 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_PULLUP_H ++#define MPLAYER_PULLUP_H ++ ++#define PULLUP_CPU_MMX 1 ++#define PULLUP_CPU_MMX2 2 ++#define PULLUP_CPU_3DNOW 4 ++#define PULLUP_CPU_3DNOWEXT 8 ++#define PULLUP_CPU_SSE 16 ++#define PULLUP_CPU_SSE2 32 ++ ++#define PULLUP_FMT_Y 1 ++#define PULLUP_FMT_YUY2 2 ++#define PULLUP_FMT_UYVY 3 ++#define PULLUP_FMT_RGB32 4 ++ ++struct pullup_buffer ++{ ++ int lock[2]; ++ unsigned char **planes; ++}; ++ ++struct pullup_field ++{ ++ int parity; ++ struct pullup_buffer *buffer; ++ unsigned int flags; ++ int breaks; ++ int affinity; ++ int *diffs; ++ int *comb; ++ int *var; ++ struct pullup_field *prev, *next; ++}; ++ ++struct pullup_frame ++{ ++ int lock; ++ int length; ++ int parity; ++ struct pullup_buffer **ifields, *ofields[2]; ++ struct pullup_buffer *buffer; ++}; ++ ++struct pullup_context ++{ ++ /* Public interface */ ++ int format; ++ int nplanes; ++ int *bpp, *w, *h, *stride, *background; ++ unsigned int cpu; ++ int junk_left, junk_right, junk_top, junk_bottom; ++ int verbose; ++ int metric_plane; ++ int strict_breaks; ++ int strict_pairs; ++ /* Internal data */ ++ struct pullup_field *first, *last, *head; ++ struct pullup_buffer *buffers; ++ int nbuffers; ++ int (*diff)(unsigned char *, unsigned char *, int); ++ int (*comb)(unsigned char *, unsigned char *, int); ++ int (*var)(unsigned char *, unsigned char *, int); ++ int metric_w, metric_h, metric_len, metric_offset; ++ struct pullup_frame *frame; ++}; ++ ++ ++struct pullup_buffer *pullup_lock_buffer(struct pullup_buffer *b, int parity); ++void pullup_release_buffer(struct pullup_buffer *b, int parity); ++struct pullup_buffer *pullup_get_buffer(struct pullup_context *c, int parity); ++ ++void pullup_submit_field(struct pullup_context *c, struct pullup_buffer *b, int parity); ++void pullup_flush_fields(struct pullup_context *c); ++ ++struct pullup_frame *pullup_get_frame(struct pullup_context *c); ++void pullup_pack_frame(struct pullup_context *c, struct pullup_frame *fr); ++void pullup_release_frame(struct pullup_frame *fr); ++ ++struct pullup_context *pullup_alloc_context(void); ++void pullup_preinit_context(struct pullup_context *c); ++void pullup_init_context(struct pullup_context *c); ++void pullup_free_context(struct pullup_context *c); ++ ++#endif /* MPLAYER_PULLUP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vd_ffmpeg.h 2012-05-14 14:08:54.729347931 +0200 +@@ -0,0 +1,24 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_VD_FFMPEG_H ++#define MPLAYER_VD_FFMPEG_H ++ ++void init_avcodec(void); ++ ++#endif /* MPLAYER_VD_FFMPEG_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_2xsai.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_2xsai.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_2xsai.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_2xsai.c 2012-05-14 14:08:54.731347972 +0200 +@@ -0,0 +1,336 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++//===========================================================================// ++ ++/* FIXME: these all belong in the context, not as globals! */ ++ ++static uint32_t colorMask = 0xF7DEF7DE; ++static uint32_t lowPixelMask = 0x08210821; ++static uint32_t qcolorMask = 0xE79CE79C; ++static uint32_t qlowpixelMask = 0x18631863; ++static uint32_t redblueMask = 0xF81F; ++static uint32_t greenMask = 0x7E0; ++static int PixelsPerMask = 2; ++ ++#define makecol(r,g,b) (r+(g<<8)+(b<<16)) ++#define makecol_depth(d,r,g,b) (r+(g<<8)+(b<<16)) ++ ++static int Init_2xSaI(int d) ++{ ++ ++ int minr = 0, ming = 0, minb = 0; ++ int i; ++ ++// if (d != 15 && d != 16 && d != 24 && d != 32) ++// return -1; ++ ++ /* Get lowest color bit */ ++ for (i = 0; i < 255; i++) { ++ if (!minr) ++ minr = makecol(i, 0, 0); ++ if (!ming) ++ ming = makecol(0, i, 0); ++ if (!minb) ++ minb = makecol(0, 0, i); ++ } ++ ++ colorMask = (makecol_depth(d, 255, 0, 0) - minr) | (makecol_depth(d, 0, 255, 0) - ming) | (makecol_depth(d, 0, 0, 255) - minb); ++ lowPixelMask = minr | ming | minb; ++ qcolorMask = (makecol_depth(d, 255, 0, 0) - 3 * minr) | (makecol_depth(d, 0, 255, 0) - 3 * ming) | (makecol_depth(d, 0, 0, 255) - 3 * minb); ++ qlowpixelMask = (minr * 3) | (ming * 3) | (minb * 3); ++ redblueMask = makecol_depth(d, 255, 0, 255); ++ greenMask = makecol_depth(d, 0, 255, 0); ++ ++ PixelsPerMask = (d <= 16) ? 2 : 1; ++ ++ if (PixelsPerMask == 2) { ++ colorMask |= (colorMask << 16); ++ qcolorMask |= (qcolorMask << 16); ++ lowPixelMask |= (lowPixelMask << 16); ++ qlowpixelMask |= (qlowpixelMask << 16); ++ } ++ ++// TRACE("Color Mask: 0x%lX\n", colorMask); ++// TRACE("Low Pixel Mask: 0x%lX\n", lowPixelMask); ++// TRACE("QColor Mask: 0x%lX\n", qcolorMask); ++// TRACE("QLow Pixel Mask: 0x%lX\n", qlowpixelMask); ++ ++ return 0; ++} ++ ++ ++#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D)) ++ ++#define INTERPOLATE(A, B) (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask)) ++ ++#define Q_INTERPOLATE(A, B, C, D) ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2) \ ++ + ((((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2) & qlowpixelMask) ++ ++ ++static void Super2xSaI_ex(uint8_t *src, uint32_t src_pitch, ++ uint8_t *dst, uint32_t dst_pitch, ++ uint32_t width, uint32_t height, int sbpp) ++{ ++ ++ unsigned int x, y; ++ uint32_t color[16]; ++ unsigned char *src_line[4]; ++ ++ /* Point to the first 3 lines. */ ++ src_line[0] = src; ++ src_line[1] = src; ++ src_line[2] = src + src_pitch; ++ src_line[3] = src + src_pitch * 2; ++ ++ x = 0, y = 0; ++ ++ if (PixelsPerMask == 2) { ++ unsigned short *sbp; ++ sbp = (unsigned short*)src_line[0]; ++ color[0] = *sbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0]; ++ color[4] = color[0]; color[5] = color[0]; color[6] = *(sbp + 1); color[7] = *(sbp + 2); ++ sbp = (unsigned short*)src_line[2]; ++ color[8] = *sbp; color[9] = color[8]; color[10] = *(sbp + 1); color[11] = *(sbp + 2); ++ sbp = (unsigned short*)src_line[3]; ++ color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2); ++ } ++ else { ++ uint32_t *lbp; ++ lbp = (uint32_t*)src_line[0]; ++ color[0] = *lbp; color[1] = color[0]; color[2] = color[0]; color[3] = color[0]; ++ color[4] = color[0]; color[5] = color[0]; color[6] = *(lbp + 1); color[7] = *(lbp + 2); ++ lbp = (uint32_t*)src_line[2]; ++ color[8] = *lbp; color[9] = color[8]; color[10] = *(lbp + 1); color[11] = *(lbp + 2); ++ lbp = (uint32_t*)src_line[3]; ++ color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2); ++ } ++ ++ for (y = 0; y < height; y++) { ++ unsigned char *dst_line[2]; ++ ++ dst_line[0] = dst + dst_pitch*2*y; ++ dst_line[1] = dst + dst_pitch*(2*y+1); ++ ++ /* Todo: x = width - 2, x = width - 1 */ ++ ++ for (x = 0; x < width; x++) { ++ uint32_t product1a, product1b, product2a, product2b; ++ ++//--------------------------------------- B0 B1 B2 B3 0 1 2 3 ++// 4 5* 6 S2 -> 4 5* 6 7 ++// 1 2 3 S1 8 9 10 11 ++// A0 A1 A2 A3 12 13 14 15 ++//-------------------------------------- ++ if (color[9] == color[6] && color[5] != color[10]) { ++ product2b = color[9]; ++ product1b = product2b; ++ } ++ else if (color[5] == color[10] && color[9] != color[6]) { ++ product2b = color[5]; ++ product1b = product2b; ++ } ++ else if (color[5] == color[10] && color[9] == color[6]) { ++ int r = 0; ++ ++ r += GET_RESULT(color[6], color[5], color[8], color[13]); ++ r += GET_RESULT(color[6], color[5], color[4], color[1]); ++ r += GET_RESULT(color[6], color[5], color[14], color[11]); ++ r += GET_RESULT(color[6], color[5], color[2], color[7]); ++ ++ if (r > 0) ++ product1b = color[6]; ++ else if (r < 0) ++ product1b = color[5]; ++ else ++ product1b = INTERPOLATE(color[5], color[6]); ++ ++ product2b = product1b; ++ ++ } ++ else { ++ if (color[6] == color[10] && color[10] == color[13] && color[9] != color[14] && color[10] != color[12]) ++ product2b = Q_INTERPOLATE(color[10], color[10], color[10], color[9]); ++ else if (color[5] == color[9] && color[9] == color[14] && color[13] != color[10] && color[9] != color[15]) ++ product2b = Q_INTERPOLATE(color[9], color[9], color[9], color[10]); ++ else ++ product2b = INTERPOLATE(color[9], color[10]); ++ ++ if (color[6] == color[10] && color[6] == color[1] && color[5] != color[2] && color[6] != color[0]) ++ product1b = Q_INTERPOLATE(color[6], color[6], color[6], color[5]); ++ else if (color[5] == color[9] && color[5] == color[2] && color[1] != color[6] && color[5] != color[3]) ++ product1b = Q_INTERPOLATE(color[6], color[5], color[5], color[5]); ++ else ++ product1b = INTERPOLATE(color[5], color[6]); ++ } ++ ++ if (color[5] == color[10] && color[9] != color[6] && color[4] == color[5] && color[5] != color[14]) ++ product2a = INTERPOLATE(color[9], color[5]); ++ else if (color[5] == color[8] && color[6] == color[5] && color[4] != color[9] && color[5] != color[12]) ++ product2a = INTERPOLATE(color[9], color[5]); ++ else ++ product2a = color[9]; ++ ++ if (color[9] == color[6] && color[5] != color[10] && color[8] == color[9] && color[9] != color[2]) ++ product1a = INTERPOLATE(color[9], color[5]); ++ else if (color[4] == color[9] && color[10] == color[9] && color[8] != color[5] && color[9] != color[0]) ++ product1a = INTERPOLATE(color[9], color[5]); ++ else ++ product1a = color[5]; ++ ++ if (PixelsPerMask == 2) { ++ *((uint32_t *) (&dst_line[0][x * 4])) = product1a | (product1b << 16); ++ *((uint32_t *) (&dst_line[1][x * 4])) = product2a | (product2b << 16); ++ } ++ else { ++ *((uint32_t *) (&dst_line[0][x * 8])) = product1a; ++ *((uint32_t *) (&dst_line[0][x * 8 + 4])) = product1b; ++ *((uint32_t *) (&dst_line[1][x * 8])) = product2a; ++ *((uint32_t *) (&dst_line[1][x * 8 + 4])) = product2b; ++ } ++ ++ /* Move color matrix forward */ ++ color[0] = color[1]; color[4] = color[5]; color[8] = color[9]; color[12] = color[13]; ++ color[1] = color[2]; color[5] = color[6]; color[9] = color[10]; color[13] = color[14]; ++ color[2] = color[3]; color[6] = color[7]; color[10] = color[11]; color[14] = color[15]; ++ ++ if (x < width - 3) { ++ x += 3; ++ if (PixelsPerMask == 2) { ++ color[3] = *(((unsigned short*)src_line[0]) + x); ++ color[7] = *(((unsigned short*)src_line[1]) + x); ++ color[11] = *(((unsigned short*)src_line[2]) + x); ++ color[15] = *(((unsigned short*)src_line[3]) + x); ++ } ++ else { ++ color[3] = *(((uint32_t*)src_line[0]) + x); ++ color[7] = *(((uint32_t*)src_line[1]) + x); ++ color[11] = *(((uint32_t*)src_line[2]) + x); ++ color[15] = *(((uint32_t*)src_line[3]) + x); ++ } ++ x -= 3; ++ } ++ } ++ ++ /* We're done with one line, so we shift the source lines up */ ++ src_line[0] = src_line[1]; ++ src_line[1] = src_line[2]; ++ src_line[2] = src_line[3]; ++ ++ /* Read next line */ ++ if (y + 3 >= height) ++ src_line[3] = src_line[2]; ++ else ++ src_line[3] = src_line[2] + src_pitch; ++ ++ /* Then shift the color matrix up */ ++ if (PixelsPerMask == 2) { ++ unsigned short *sbp; ++ sbp = (unsigned short*)src_line[0]; ++ color[0] = *sbp; color[1] = color[0]; color[2] = *(sbp + 1); color[3] = *(sbp + 2); ++ sbp = (unsigned short*)src_line[1]; ++ color[4] = *sbp; color[5] = color[4]; color[6] = *(sbp + 1); color[7] = *(sbp + 2); ++ sbp = (unsigned short*)src_line[2]; ++ color[8] = *sbp; color[9] = color[9]; color[10] = *(sbp + 1); color[11] = *(sbp + 2); ++ sbp = (unsigned short*)src_line[3]; ++ color[12] = *sbp; color[13] = color[12]; color[14] = *(sbp + 1); color[15] = *(sbp + 2); ++ } ++ else { ++ uint32_t *lbp; ++ lbp = (uint32_t*)src_line[0]; ++ color[0] = *lbp; color[1] = color[0]; color[2] = *(lbp + 1); color[3] = *(lbp + 2); ++ lbp = (uint32_t*)src_line[1]; ++ color[4] = *lbp; color[5] = color[4]; color[6] = *(lbp + 1); color[7] = *(lbp + 2); ++ lbp = (uint32_t*)src_line[2]; ++ color[8] = *lbp; color[9] = color[9]; color[10] = *(lbp + 1); color[11] = *(lbp + 2); ++ lbp = (uint32_t*)src_line[3]; ++ color[12] = *lbp; color[13] = color[12]; color[14] = *(lbp + 1); color[15] = *(lbp + 2); ++ } ++ ++ } // y loop ++ ++} ++ ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ Init_2xSaI(outfmt&255); ++ ++ return vf_next_config(vf,2*width,2*height,2*d_width,2*d_height,flags,outfmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ 2*mpi->w, 2*mpi->h); ++ ++ Super2xSaI_ex(mpi->planes[0], mpi->stride[0], ++ dmpi->planes[0], dmpi->stride[0], ++ mpi->w, mpi->h, mpi->bpp/8); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++// case IMGFMT_BGR15: ++// case IMGFMT_BGR16: ++ case IMGFMT_BGR32: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ return 1; ++} ++ ++const vf_info_t vf_info_2xsai = { ++ "2xSai BGR bitmap 2x scaler", ++ "2xsai", ++ "A'rpi", ++ "http://elektron.its.tudelft.nl/~dalikifa/", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vfcap.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vfcap.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vfcap.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vfcap.h 2012-05-14 14:08:54.793349219 +0200 +@@ -0,0 +1,56 @@ ++/* VFCAP_* values: they are flags, returned by query_format(): ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_VFCAP_H ++#define MPLAYER_VFCAP_H ++ ++// set, if the given colorspace is supported (with or without conversion) ++#define VFCAP_CSP_SUPPORTED 0x1 ++// set, if the given colorspace is supported _without_ conversion ++#define VFCAP_CSP_SUPPORTED_BY_HW 0x2 ++// set if the driver/filter can draw OSD ++#define VFCAP_OSD 0x4 ++// set if the driver/filter can handle compressed SPU stream ++#define VFCAP_SPU 0x8 ++// scaling up/down by hardware, or software: ++#define VFCAP_HWSCALE_UP 0x10 ++#define VFCAP_HWSCALE_DOWN 0x20 ++#define VFCAP_SWSCALE 0x40 ++// driver/filter can do vertical flip (upside-down) ++#define VFCAP_FLIP 0x80 ++ ++// driver/hardware handles timing (blocking) ++#define VFCAP_TIMER 0x100 ++// driver _always_ flip image upside-down (for ve_vfw) ++#define VFCAP_FLIPPED 0x200 ++// vf filter: accepts stride (put_image) ++// vo driver: has draw_slice() support for the given csp ++#define VFCAP_ACCEPT_STRIDE 0x400 ++// filter does postprocessing (so you shouldn't scale/filter image before it) ++#define VFCAP_POSTPROC 0x800 ++// filter cannot be reconfigured to different size & format ++#define VFCAP_CONSTANT 0x1000 ++// filter can draw EOSD ++#define VFCAP_EOSD 0x2000 ++// filter will draw EOSD at screen resolution (without scaling) ++#define VFCAP_EOSD_UNSCALED 0x4000 ++// used by libvo and vf_vo, indicates the VO does not support draw_slice for this format ++#define VOCAP_NOSLICES 0x8000 ++ ++#endif /* MPLAYER_VFCAP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_decimate.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_decimate.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_decimate.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_decimate.c 2012-05-14 14:08:54.732347992 +0200 +@@ -0,0 +1,198 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++ ++struct vf_priv_s { ++ int hi, lo; ++ float frac; ++ int max, last, cnt; ++}; ++ ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns) ++{ ++ volatile short out[4]; ++ __asm__ ( ++ "movl $8, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ ++ ASMALIGN(4) ++ "1: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm4 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 1b \n\t" ++ "movq %%mm4, (%%"REG_d") \n\t" ++ "emms \n\t" ++ : ++ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out) ++ : "%ecx", "memory" ++ ); ++ return out[0]+out[1]+out[2]+out[3]; ++} ++#endif ++ ++static int diff_C(unsigned char *old, unsigned char *new, int os, int ns) ++{ ++ int x, y, d=0; ++ for (y = 8; y; y--) { ++ for (x = 8; x; x--) { ++ d += abs(new[x] - old[x]); ++ } ++ new += ns; ++ old += os; ++ } ++ return d; ++} ++ ++static int (*diff)(unsigned char *, unsigned char *, int, int); ++ ++static int diff_to_drop_plane(int hi, int lo, float frac, unsigned char *old, unsigned char *new, int w, int h, int os, int ns) ++{ ++ int x, y; ++ int d, c=0; ++ int t = (w/16)*(h/16)*frac; ++ for (y = 0; y < h-7; y += 4) { ++ for (x = 8; x < w-7; x += 4) { ++ d = diff(old+x+y*os, new+x+y*ns, os, ns); ++ if (d > hi) return 0; ++ if (d > lo) { ++ c++; ++ if (c > t) return 0; ++ } ++ } ++ } ++ return 1; ++} ++ ++static int diff_to_drop(int hi, int lo, float frac, mp_image_t *old, mp_image_t *new) ++{ ++ if (new->flags & MP_IMGFLAG_PLANAR) { ++ return diff_to_drop_plane(hi,lo,frac, old->planes[0], new->planes[0], ++ new->w, new->h, old->stride[0], new->stride[0]) ++ && diff_to_drop_plane(hi,lo,frac, old->planes[1], new->planes[1], ++ new->chroma_width, new->chroma_height, ++ old->stride[1], new->stride[1]) ++ && diff_to_drop_plane(hi,lo,frac, old->planes[2], new->planes[2], ++ new->chroma_width, new->chroma_height, ++ old->stride[2], new->stride[2]); ++ } ++ return diff_to_drop_plane(hi,lo,frac, old->planes[0], new->planes[0], ++ new->w*(new->bpp/8), new->h, old->stride[0], new->stride[0]); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, ++ mpi->width, mpi->height); ++ dmpi->qscale = mpi->qscale; ++ dmpi->qstride = mpi->qstride; ++ dmpi->qscale_type = mpi->qscale_type; ++ ++ if (diff_to_drop(vf->priv->hi, vf->priv->lo, vf->priv->frac, dmpi, mpi)) { ++ if (vf->priv->max == 0) ++ return 0; ++ else if ((vf->priv->max > 0) && (vf->priv->cnt++ < vf->priv->max)) ++ return 0; ++ else if ((vf->priv->max < 0) && (vf->priv->last+1 >= -vf->priv->max)) ++ return vf->priv->last=0; ++ } ++ vf->priv->last++; ++ vf->priv->cnt=0; ++ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0], mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2], mpi->stride[2]); ++ } ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ p->max = 0; ++ p->hi = 64*12; ++ p->lo = 64*5; ++ p->frac = 0.33; ++ if (args) sscanf(args, "%d:%d:%d:%f", &p->max, &p->hi, &p->lo, &p->frac); ++ diff = diff_C; ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++ if(gCpuCaps.hasMMX) diff = diff_MMX; ++#endif ++ return 1; ++} ++ ++const vf_info_t vf_info_decimate = { ++ "near-duplicate frame remover", ++ "decimate", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_denoise3d.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_denoise3d.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_denoise3d.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_denoise3d.c 2012-05-14 14:08:54.733348012 +0200 +@@ -0,0 +1,268 @@ ++/* ++ * Copyright (C) 2003 Daniel Moreno ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#define PARAM1_DEFAULT 4.0 ++#define PARAM2_DEFAULT 3.0 ++#define PARAM3_DEFAULT 6.0 ++ ++//===========================================================================// ++ ++struct vf_priv_s { ++ int Coefs[4][512]; ++ unsigned char *Line; ++ mp_image_t *pmpi; ++}; ++ ++ ++/***************************************************************************/ ++ ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ free(vf->priv->Line); ++ vf->priv->Line = malloc(width); ++ vf->priv->pmpi=NULL; ++// vf->default_caps &= !VFCAP_ACCEPT_STRIDE; ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv->Line); ++} ++ ++#define LowPass(Prev, Curr, Coef) (Curr + Coef[Prev - Curr]) ++ ++static void deNoise(unsigned char *Frame, // mpi->planes[x] ++ unsigned char *FramePrev, // pmpi->planes[x] ++ unsigned char *FrameDest, // dmpi->planes[x] ++ unsigned char *LineAnt, // vf->priv->Line (width bytes) ++ int W, int H, int sStride, int pStride, int dStride, ++ int *Horizontal, int *Vertical, int *Temporal) ++{ ++ int X, Y; ++ int sLineOffs = 0, pLineOffs = 0, dLineOffs = 0; ++ unsigned char PixelAnt; ++ ++ /* First pixel has no left nor top neighbor. Only previous frame */ ++ LineAnt[0] = PixelAnt = Frame[0]; ++ FrameDest[0] = LowPass(FramePrev[0], LineAnt[0], Temporal); ++ ++ /* Fist line has no top neighbor. Only left one for each pixel and ++ * last frame */ ++ for (X = 1; X < W; X++) ++ { ++ PixelAnt = LowPass(PixelAnt, Frame[X], Horizontal); ++ LineAnt[X] = PixelAnt; ++ FrameDest[X] = LowPass(FramePrev[X], LineAnt[X], Temporal); ++ } ++ ++ for (Y = 1; Y < H; Y++) ++ { ++ sLineOffs += sStride, pLineOffs += pStride, dLineOffs += dStride; ++ /* First pixel on each line doesn't have previous pixel */ ++ PixelAnt = Frame[sLineOffs]; ++ LineAnt[0] = LowPass(LineAnt[0], PixelAnt, Vertical); ++ FrameDest[dLineOffs] = LowPass(FramePrev[pLineOffs], LineAnt[0], Temporal); ++ ++ for (X = 1; X < W; X++) ++ { ++ /* The rest are normal */ ++ PixelAnt = LowPass(PixelAnt, Frame[sLineOffs+X], Horizontal); ++ LineAnt[X] = LowPass(LineAnt[X], PixelAnt, Vertical); ++ FrameDest[dLineOffs+X] = LowPass(FramePrev[pLineOffs+X], LineAnt[X], Temporal); ++ } ++ } ++} ++ ++ ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ int W = mpi->w, H = mpi->h; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, ++ mpi->w,mpi->h); ++ ++ if(!dmpi) return 0; ++ if (!vf->priv->pmpi) vf->priv->pmpi=mpi; ++ ++ deNoise(mpi->planes[0], vf->priv->pmpi->planes[0], dmpi->planes[0], ++ vf->priv->Line, W, H, ++ mpi->stride[0], vf->priv->pmpi->stride[0], dmpi->stride[0], ++ vf->priv->Coefs[0] + 256, ++ vf->priv->Coefs[0] + 256, ++ vf->priv->Coefs[1] + 256); ++ deNoise(mpi->planes[1], vf->priv->pmpi->planes[1], dmpi->planes[1], ++ vf->priv->Line, cw, ch, ++ mpi->stride[1], vf->priv->pmpi->stride[1], dmpi->stride[1], ++ vf->priv->Coefs[2] + 256, ++ vf->priv->Coefs[2] + 256, ++ vf->priv->Coefs[3] + 256); ++ deNoise(mpi->planes[2], vf->priv->pmpi->planes[2], dmpi->planes[2], ++ vf->priv->Line, cw, ch, ++ mpi->stride[2], vf->priv->pmpi->stride[2], dmpi->stride[2], ++ vf->priv->Coefs[2] + 256, ++ vf->priv->Coefs[2] + 256, ++ vf->priv->Coefs[3] + 256); ++ ++ vf->priv->pmpi=dmpi; // save reference image ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++ ++#define ABS(A) ( (A) > 0 ? (A) : -(A) ) ++ ++static void PrecalcCoefs(int *Ct, double Dist25) ++{ ++ int i; ++ double Gamma, Simil, C; ++ ++ Gamma = log(0.25) / log(1.0 - Dist25/255.0); ++ ++ for (i = -256; i <= 255; i++) ++ { ++ Simil = 1.0 - ABS(i) / 255.0; ++// Ct[256+i] = lround(pow(Simil, Gamma) * (double)i); ++ C = pow(Simil, Gamma) * (double)i; ++ Ct[256+i] = (C<0) ? (C-0.5) : (C+0.5); ++ } ++} ++ ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ double LumSpac, LumTmp, ChromSpac, ChromTmp; ++ double Param1, Param2, Param3; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if (args) ++ { ++ switch(sscanf(args, "%lf:%lf:%lf", ++ &Param1, &Param2, &Param3 ++ )) ++ { ++ case 0: ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 1: ++ LumSpac = Param1; ++ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 2: ++ LumSpac = Param1; ++ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ++ ChromSpac = Param2; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 3: ++ LumSpac = Param1; ++ LumTmp = Param3; ++ ++ ChromSpac = Param2; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ default: ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ } ++ } ++ else ++ { ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ } ++ ++ PrecalcCoefs(vf->priv->Coefs[0], LumSpac); ++ PrecalcCoefs(vf->priv->Coefs[1], LumTmp); ++ PrecalcCoefs(vf->priv->Coefs[2], ChromSpac); ++ PrecalcCoefs(vf->priv->Coefs[3], ChromTmp); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_denoise3d = { ++ "3D Denoiser (variable lowpass filter)", ++ "denoise3d", ++ "Daniel Moreno", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_detc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_detc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_detc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_detc.c 2012-05-14 14:08:54.734348032 +0200 +@@ -0,0 +1,453 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++struct metrics { ++ int even; ++ int odd; ++ int noise; ++ int temp; ++}; ++ ++struct vf_priv_s { ++ int frame; ++ int drop, lastdrop; ++ struct metrics pm; ++ int thres[5]; ++ int inframes, outframes; ++ int mode; ++ int (*analyze)(struct vf_priv_s *, mp_image_t *, mp_image_t *); ++ int needread; ++}; ++ ++#define COMPE(a,b,e) (abs((a)-(b)) < (((a)+(b))>>(e))) ++#define COMPARABLE(a,b) COMPE((a),(b),2) ++#define VERYCLOSE(a,b) COMPE((a),(b),3) ++ ++#define OUTER_TC_NBHD(s) ( \ ++ COMPARABLE((s)[-1].m.even,(s)[-1].m.odd) && \ ++ COMPARABLE((s)[1].m.even,(s)[0].m.odd) && \ ++ COMPARABLE((s)[2].m.even,(s)[1].m.odd) && \ ++ COMPARABLE((s)[-1].m.noise,(s)[0].m.temp) && \ ++ COMPARABLE((s)[2].m.noise,(s)[2].m.temp) ) ++ ++#define INNER_TC_NBHD(s,l,h) ( \ ++ COMPARABLE((s)[0].m.even,(l)) && \ ++ COMPARABLE((s)[2].m.odd,(l)) && ( \ ++ COMPARABLE((s)[0].m.noise,(h)) || \ ++ COMPARABLE((s)[1].m.noise,(h)) ) ) ++ ++enum { ++ TC_DROP, ++ TC_PROG, ++ TC_IL1, ++ TC_IL2 ++}; ++ ++static void block_diffs(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns) ++{ ++ int x, y, even=0, odd=0, noise, temp; ++ unsigned char *oldp, *newp; ++ m->noise = m->temp = 0; ++ for (x = 8; x; x--) { ++ oldp = old++; ++ newp = new++; ++ noise = temp = 0; ++ for (y = 4; y; y--) { ++ even += abs(newp[0]-oldp[0]); ++ odd += abs(newp[ns]-oldp[os]); ++ noise += newp[ns]-newp[0]; ++ temp += oldp[os]-newp[0]; ++ oldp += os<<1; ++ newp += ns<<1; ++ } ++ m->noise += abs(noise); ++ m->temp += abs(temp); ++ } ++ m->even = even; ++ m->odd = odd; ++} ++ ++static void diff_planes(struct metrics *m, unsigned char *old, unsigned char *new, int w, int h, int os, int ns) ++{ ++ int x, y, me=0, mo=0, mn=0, mt=0; ++ struct metrics l; ++ for (y = 0; y < h-7; y += 8) { ++ for (x = 0; x < w-7; x += 8) { ++ block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns); ++ if (l.even > me) me = l.even; ++ if (l.odd > mo) mo = l.odd; ++ if (l.noise > mn) mn = l.noise; ++ if (l.temp > mt) mt = l.temp; ++ } ++ } ++ m->even = me; ++ m->odd = mo; ++ m->noise = mn; ++ m->temp = mt; ++} ++ ++static void diff_fields(struct metrics *metr, mp_image_t *old, mp_image_t *new) ++{ ++ struct metrics m, mu, mv; ++ diff_planes(&m, old->planes[0], new->planes[0], ++ new->w, new->h, old->stride[0], new->stride[0]); ++ if (new->flags & MP_IMGFLAG_PLANAR) { ++ diff_planes(&mu, old->planes[1], new->planes[1], ++ new->chroma_width, new->chroma_height, ++ old->stride[1], new->stride[1]); ++ diff_planes(&mv, old->planes[2], new->planes[2], ++ new->chroma_width, new->chroma_height, ++ old->stride[2], new->stride[2]); ++ if (mu.even > m.even) m.even = mu.even; ++ if (mu.odd > m.odd) m.odd = mu.odd; ++ if (mu.noise > m.noise) m.noise = mu.noise; ++ if (mu.temp > m.temp) m.temp = mu.temp; ++ if (mv.even > m.even) m.even = mv.even; ++ if (mv.odd > m.odd) m.odd = mv.odd; ++ if (mv.noise > m.noise) m.noise = mv.noise; ++ if (mv.temp > m.temp) m.temp = mv.temp; ++ } ++ *metr = m; ++} ++ ++static void status(int f, struct metrics *m) ++{ ++ mp_msg(MSGT_VFILTER, MSGL_V, "frame %d: e=%d o=%d n=%d t=%d\n", ++ f, m->even, m->odd, m->noise, m->temp); ++} ++ ++static int analyze_fixed_pattern(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old) ++{ ++ if (p->frame >= 0) p->frame = (p->frame+1)%5; ++ mp_msg(MSGT_VFILTER, MSGL_V, "frame %d\n", p->frame); ++ switch (p->frame) { ++ case -1: case 0: case 1: case 2: ++ return TC_PROG; ++ case 3: ++ return TC_IL1; ++ case 4: ++ return TC_IL2; ++ } ++ return 0; ++} ++ ++static int analyze_aggressive(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old) ++{ ++ struct metrics m, pm; ++ ++ if (p->frame >= 0) p->frame = (p->frame+1)%5; ++ ++ diff_fields(&m, old, new); ++ ++ status(p->frame, &m); ++ ++ pm = p->pm; ++ p->pm = m; ++ ++ if (p->frame == 4) { ++ /* We need to break at scene changes, but is this a valid test? */ ++ if ((m.even > p->thres[2]) && (m.odd > p->thres[2]) && (m.temp > p->thres[3]) ++ && (m.temp > 5*pm.temp) && (m.temp*2 > m.noise)) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "scene change breaking telecine!\n"); ++ p->frame = -1; ++ return TC_DROP; ++ } ++ /* Thres. is to compensate for quantization errors when noise is low */ ++ if (m.noise - m.temp > -p->thres[4]) { ++ if (COMPARABLE(m.even, pm.odd)) { ++ //mp_msg(MSGT_VFILTER, MSGL_V, "confirmed field match!\n"); ++ return TC_IL2; ++ } else if ((m.even < p->thres[0]) && (m.odd < p->thres[0]) && VERYCLOSE(m.even, m.odd) ++ && VERYCLOSE(m.noise,m.temp) && VERYCLOSE(m.noise,pm.noise)) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "interlaced frame appears in duplicate!!!\n"); ++ p->pm = pm; /* hack :) */ ++ p->frame = 3; ++ return TC_IL1; ++ } ++ } else { ++ mp_msg(MSGT_VFILTER, MSGL_V, "mismatched telecine fields!\n"); ++ p->frame = -1; ++ } ++ } ++ ++ if (2*m.even*m.temp < m.odd*m.noise) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "caught telecine sync!\n"); ++ p->frame = 3; ++ return TC_IL1; ++ } ++ ++ if (p->frame < 3) { ++ if (m.noise > p->thres[3]) { ++ if (m.noise > 2*m.temp) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n"); ++ return TC_IL2; ++ } ++ if ((m.noise > 2*pm.noise) && (m.even > p->thres[2]) && (m.odd > p->thres[2])) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "dropping horrible interlaced frame!\n"); ++ return TC_DROP; ++ } ++ } ++ } ++ ++ switch (p->frame) { ++ case -1: ++ if (4*m.noise > 5*m.temp) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "merging fields out of sequence!\n"); ++ return TC_IL2; ++ } ++ case 0: ++ case 1: ++ case 2: ++ return TC_PROG; ++ case 3: ++ if ((m.even > p->thres[1]) && (m.even > m.odd) && (m.temp > m.noise)) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "lost telecine tracking!\n"); ++ p->frame = -1; ++ return TC_PROG; ++ } ++ return TC_IL1; ++ case 4: ++ return TC_IL2; ++ } ++ return 0; ++} ++ ++static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field) ++{ ++ switch (field) { ++ case 0: ++ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ break; ++ case 1: ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ break; ++ case 2: ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0], mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2], mpi->stride[2]); ++ } ++ break; ++ } ++} ++ ++static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi) ++{ ++ struct vf_priv_s *p = vf->priv; ++ int dropflag; ++ ++ switch (p->drop) { ++ default: ++ dropflag = 0; ++ break; ++ case 1: ++ dropflag = (++p->lastdrop >= 5); ++ break; ++ case 2: ++ dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes); ++ break; ++ } ++ ++ if (dropflag) { ++ mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n", ++ p->outframes, p->inframes, (float)p->outframes/p->inframes); ++ p->lastdrop = 0; ++ return 0; ++ } ++ ++ p->outframes++; ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ int ret=0; ++ mp_image_t *dmpi; ++ struct vf_priv_s *p = vf->priv; ++ ++ p->inframes++; ++ ++ if (p->needread) dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, ++ mpi->width, mpi->height); ++ /* FIXME: is there a good way to get rid of static type? */ ++ else dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height); ++ ++ switch (p->analyze(p, mpi, dmpi)) { ++ case TC_DROP: ++ /* Don't copy anything unless we'll need to read it. */ ++ if (p->needread) copy_image(dmpi, mpi, 2); ++ p->lastdrop = 0; ++ break; ++ case TC_PROG: ++ /* Copy and display the whole frame. */ ++ copy_image(dmpi, mpi, 2); ++ ret = do_put_image(vf, dmpi); ++ break; ++ case TC_IL1: ++ /* Only copy bottom field unless we need to read. */ ++ if (p->needread) copy_image(dmpi, mpi, 2); ++ else copy_image(dmpi, mpi, 1); ++ p->lastdrop = 0; ++ break; ++ case TC_IL2: ++ /* Copy top field and show frame, then copy bottom if needed. */ ++ copy_image(dmpi, mpi, 0); ++ ret = do_put_image(vf, dmpi); ++ if (p->needread) copy_image(dmpi, mpi, 1); ++ break; ++ } ++ return ret; ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - figure out which other formats work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static struct { ++ const char *name; ++ int (*func)(struct vf_priv_s *p, mp_image_t *new, mp_image_t *old); ++ int needread; ++} anal_funcs[] = { ++ { "fixed", analyze_fixed_pattern, 0 }, ++ { "aggressive", analyze_aggressive, 1 }, ++ { NULL, NULL, 0 } ++}; ++ ++#define STARTVARS if (0) ++#define GETVAR(str, name, out, func) \ ++ else if (!strncmp((str), name "=", sizeof(name))) \ ++ (out) = (func)((str) + sizeof(name)) ++ ++static void parse_var(struct vf_priv_s *p, char *var) ++{ ++ STARTVARS; ++ GETVAR(var, "dr", p->drop, atoi); ++ GETVAR(var, "t0", p->thres[0], atoi); ++ GETVAR(var, "t1", p->thres[1], atoi); ++ GETVAR(var, "t2", p->thres[2], atoi); ++ GETVAR(var, "t3", p->thres[3], atoi); ++ GETVAR(var, "t4", p->thres[4], atoi); ++ GETVAR(var, "fr", p->frame, atoi); ++ GETVAR(var, "am", p->mode, atoi); ++} ++ ++static void parse_args(struct vf_priv_s *p, char *args) ++{ ++ char *next, *orig; ++ for (args=orig=av_strdup(args); args; args=next) { ++ next = strchr(args, ':'); ++ if (next) *next++ = 0; ++ parse_var(p, args); ++ } ++ free(orig); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->config = config; ++ vf->put_image = put_image; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ p->frame = -1; ++ p->thres[0] = 440; ++ p->thres[1] = 720; ++ p->thres[2] = 2500; ++ p->thres[3] = 2500; ++ p->thres[4] = 800; ++ p->drop = 0; ++ p->mode = 1; ++ if (args) parse_args(p, args); ++ p->analyze = anal_funcs[p->mode].func; ++ p->needread = anal_funcs[p->mode].needread; ++ return 1; ++} ++ ++const vf_info_t vf_info_detc = { ++ "de-telecine filter", ++ "detc", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_dint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_dint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_dint.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_dint.c 2012-05-14 14:08:54.735348052 +0200 +@@ -0,0 +1,214 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "mp_image.h" ++#include "img_format.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ float sense; // first parameter ++ float level; // second parameter ++ unsigned int imgfmt; ++ int diff; ++ uint32_t max; ++// int dfr; ++// int rdfr; ++ int was_dint; ++ mp_image_t *pmpi; // previous mpi ++}; ++ ++#define MAXROWSIZE 1200 ++ ++static int config (struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ int rowsize; ++ ++ vf->priv->pmpi = vf_get_image (vf->next, outfmt, MP_IMGTYPE_TEMP, ++ 0, width, height); ++ if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) && ++ outfmt != IMGFMT_RGB32 && outfmt != IMGFMT_BGR32 && ++ outfmt != IMGFMT_RGB24 && outfmt != IMGFMT_BGR24 && ++ outfmt != IMGFMT_RGB16 && outfmt != IMGFMT_BGR16) ++ { ++ mp_msg (MSGT_VFILTER, MSGL_WARN, "Drop-interlaced filter doesn't support this outfmt :(\n"); ++ return 0; ++ } ++ vf->priv->imgfmt = outfmt; ++ // recalculate internal values ++ rowsize = vf->priv->pmpi->width; ++ if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE; ++ vf->priv->max = vf->priv->level * vf->priv->pmpi->height * rowsize / 2; ++ if (vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) // planar YUV ++ vf->priv->diff = vf->priv->sense * 256; ++ else ++ vf->priv->diff = vf->priv->sense * (1 << (vf->priv->pmpi->bpp/3)); ++ if (vf->priv->diff < 0) vf->priv->diff = 0; ++ if (!(vf->priv->pmpi->flags & MP_IMGFLAG_PLANAR) && ++ vf->priv->pmpi->bpp < 24 && vf->priv->diff > 31) ++ vf->priv->diff = 31; ++ mp_msg (MSGT_VFILTER, MSGL_INFO, "Drop-interlaced: %dx%d diff %d / level %u\n", ++ vf->priv->pmpi->width, vf->priv->pmpi->height, ++ vf->priv->diff, (unsigned int)vf->priv->max); ++// vf->priv->rdfr = vf->priv->dfr = 0; ++ vf->priv->was_dint = 0; ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static int put_image (struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ int8_t rrow0[MAXROWSIZE]; ++ int8_t rrow1[MAXROWSIZE]; ++ int8_t rrow2[MAXROWSIZE]; ++ int8_t *row0 = rrow0, *row1 = rrow1, *row2 = rrow2/*, *row3 = rrow3*/; ++ int rowsize = mpi->width; ++ uint32_t nok = 0, max = vf->priv->max; ++ int diff = vf->priv->diff; ++ int i, j; ++ register int n1, n2; ++ unsigned char *cur0, *prv0; ++ register unsigned char *cur, *prv; ++ ++ if (rowsize > MAXROWSIZE) rowsize = MAXROWSIZE; ++ // check if nothing to do ++ if (mpi->imgfmt == vf->priv->imgfmt) ++ { ++ cur0 = mpi->planes[0] + mpi->stride[0]; ++ prv0 = mpi->planes[0]; ++ for (j = 1; j < mpi->height && nok <= max; j++) ++ { ++ cur = cur0; ++ prv = prv0; ++ // analyse row (row0) ++ if (mpi->flags & MP_IMGFLAG_PLANAR) // planar YUV - check luminance ++ for (i = 0; i < rowsize; i++) ++ { ++ if (cur[0] - prv[0] > diff) ++ row0[i] = 1; ++ else if (cur[0] - prv[0] < -diff) ++ row0[i] = -1; ++ else ++ row0[i] = 0; ++ cur++; ++ prv++; ++ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0 ++ // but row3 is 1 so it's interlaced ptr (nok++) ++ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) && ++ (++nok) > max) ++ break; ++ } ++ else if (mpi->bpp < 24) // RGB/BGR 16 - check all colors ++ for (i = 0; i < rowsize; i++) ++ { ++ n1 = cur[0] + (cur[1]<<8); ++ n2 = prv[0] + (prv[1]<<8); ++ if ((n1&0x1f) - (n2&0x1f) > diff || ++ ((n1>>5)&0x3f) - ((n2>>5)&0x3f) > diff || ++ ((n1>>11)&0x1f) - ((n2>>11)&0x1f) > diff) ++ row0[i] = 1; ++ else if ((n1&0x1f) - (n2&0x1f) < -diff || ++ ((n1>>5)&0x3f) - ((n2>>5)&0x3f) < -diff || ++ ((n1>>11)&0x1f) - ((n2>>11)&0x1f) < -diff) ++ row0[i] = -1; ++ else ++ row0[i] = 0; ++ cur += 2; ++ prv += 2; ++ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0 ++ // but row3 is 1 so it's interlaced ptr (nok++) ++ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) && ++ (++nok) > max) ++ break; ++ } ++ else // RGB/BGR 24/32 ++ for (i = 0; i < rowsize; i++) ++ { ++ if (cur[0] - prv[0] > diff || ++ cur[1] - prv[1] > diff || ++ cur[2] - prv[2] > diff) ++ row0[i] = 1; ++ else if (prv[0] - cur[0] > diff || ++ prv[1] - cur[1] > diff || ++ prv[2] - cur[2] > diff) ++ row0[i] = -1; ++ else ++ row0[i] = 0; ++ cur += mpi->bpp/8; ++ prv += mpi->bpp/8; ++ // check if row0 is 1 but row1 is 0, and row2 is 1 or row2 is 0 ++ // but row3 is 1 so it's interlaced ptr (nok++) ++ if (j > 2 && row0[i] > 0 && (row1[i] < 0 || (!row1[i] && row2[i] < 0)) && ++ (++nok) > max) ++ break; ++ } ++ cur0 += mpi->stride[0]; ++ prv0 += mpi->stride[0]; ++ // rotate rows ++ cur = row2; ++ row2 = row1; ++ row1 = row0; ++ row0 = cur; ++ } ++ } ++ // check if number of interlaced is above of max ++ if (nok > max) ++ { ++// vf->priv->dfr++; ++ if (vf->priv->was_dint < 1) // can skip at most one frame! ++ { ++ vf->priv->was_dint++; ++// vf->priv->rdfr++; ++// mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr); ++ return 0; ++ } ++ } ++ vf->priv->was_dint = 0; ++// mp_msg (MSGT_VFILTER, MSGL_INFO, "DI:%d/%d ", vf->priv->rdfr, vf->priv->dfr); ++ return vf_next_put_image (vf, mpi, pts); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config = config; ++ vf->put_image = put_image; ++// vf->default_reqs=VFCAP_ACCEPT_STRIDE; ++ vf->priv = malloc (sizeof(struct vf_priv_s)); ++ vf->priv->sense = 0.1; ++ vf->priv->level = 0.15; ++ vf->priv->pmpi = NULL; ++ if (args) ++ sscanf (args, "%f:%f", &vf->priv->sense, &vf->priv->level); ++ return 1; ++} ++ ++const vf_info_t vf_info_dint = { ++ "drop interlaced frames", ++ "dint", ++ "A.G.", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_divtc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_divtc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_divtc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_divtc.c 2012-05-14 14:08:54.737348092 +0200 +@@ -0,0 +1,721 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++#include "libavutil/common.h" ++#include "mpbswap.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++const vf_info_t vf_info_divtc; ++ ++struct vf_priv_s ++ { ++ int deghost, pass, phase, window, fcount, bcount, frameno, misscount, ++ ocount, sum[5]; ++ double threshold; ++ FILE *file; ++ int8_t *bdata; ++ unsigned int *csdata; ++ int *history; ++ }; ++ ++/* ++ * diff_MMX and diff_C stolen from vf_decimate.c ++ */ ++ ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++static int diff_MMX(unsigned char *old, unsigned char *new, int os, int ns) ++ { ++ volatile short out[4]; ++ __asm__ ( ++ "movl $8, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ ++ ASMALIGN(4) ++ "1: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm4 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 1b \n\t" ++ "movq %%mm4, (%%"REG_d") \n\t" ++ "emms \n\t" ++ : ++ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out) ++ : "%ecx", "memory" ++ ); ++ return out[0]+out[1]+out[2]+out[3]; ++ } ++#endif ++ ++static int diff_C(unsigned char *old, unsigned char *new, int os, int ns) ++ { ++ int x, y, d=0; ++ ++ for(y=8; y; y--, new+=ns, old+=os) ++ for(x=8; x; x--) ++ d+=abs(new[x]-old[x]); ++ ++ return d; ++ } ++ ++static int (*diff)(unsigned char *, unsigned char *, int, int); ++ ++static int diff_plane(unsigned char *old, unsigned char *new, ++ int w, int h, int os, int ns, int arg) ++ { ++ int x, y, d, max=0, sum=0, n=0; ++ ++ for(y=0; ymax) max=d; ++ sum+=d; ++ n++; ++ } ++ } ++ ++ return (sum+n*max)/2; ++ } ++ ++/* ++static unsigned int checksum_plane(unsigned char *p, unsigned char *z, ++ int w, int h, int s, int zs, int arg) ++ { ++ unsigned int shift, sum; ++ unsigned char *e; ++ ++ for(sum=0; h; h--, p+=s-w) ++ for(e=p+w, shift=32; p>32^wsum)); ++#else ++ t=be2me_32(wsum); ++#endif ++ ++ for(sum^=(t<>(32-shift)); p=threshold) ++ *d=(t=(*d<<1)-*s)<0?0:t>255?255:t; ++ ++ return 0; ++ } ++ ++static int copyop(unsigned char *d, unsigned char *s, int bpl, int h, int dstride, int sstride, int dummy) { ++ memcpy_pic(d, s, bpl, h, dstride, sstride); ++ return 0; ++} ++ ++static int imgop(int(*planeop)(unsigned char *, unsigned char *, ++ int, int, int, int, int), ++ mp_image_t *dst, mp_image_t *src, int arg) ++ { ++ if(dst->flags&MP_IMGFLAG_PLANAR) ++ return planeop(dst->planes[0], src?src->planes[0]:0, ++ dst->w, dst->h, ++ dst->stride[0], src?src->stride[0]:0, arg)+ ++ planeop(dst->planes[1], src?src->planes[1]:0, ++ dst->chroma_width, dst->chroma_height, ++ dst->stride[1], src?src->stride[1]:0, arg)+ ++ planeop(dst->planes[2], src?src->planes[2]:0, ++ dst->chroma_width, dst->chroma_height, ++ dst->stride[2], src?src->stride[2]:0, arg); ++ ++ return planeop(dst->planes[0], src?src->planes[0]:0, ++ dst->w*(dst->bpp/8), dst->h, ++ dst->stride[0], src?src->stride[0]:0, arg); ++ } ++ ++/* ++ * Find the phase in which the telecine pattern fits best to the ++ * given 5 frame slice of frame difference measurements. ++ * ++ * If phase1 and phase2 are not negative, only the two specified ++ * phases are tested. ++ */ ++ ++static int match(struct vf_priv_s *p, int *diffs, ++ int phase1, int phase2, double *strength) ++ { ++ static const int pattern1[]={ -4, 1, 1, 1, 1 }, ++ pattern2[]={ -2, -3, 4, 4, -3 }, *pattern; ++ int f, m, n, t[5]; ++ ++ pattern=p->deghost>0?pattern2:pattern1; ++ ++ for(f=0; f<5; f++) ++ { ++ if(phase1<0 || phase2<0 || f==phase1 || f==phase2) ++ { ++ for(n=t[f]=0; n<5; n++) ++ t[f]+=diffs[n]*pattern[(n-f+5)%5]; ++ } ++ else ++ t[f]=INT_MIN; ++ } ++ ++ /* find the best match */ ++ for(m=0, n=1; n<5; n++) ++ if(t[n]>t[m]) m=n; ++ ++ if(strength) ++ { ++ /* the second best match */ ++ for(f=m?0:1, n=f+1; n<5; n++) ++ if(n!=m && t[n]>t[f]) f=n; ++ ++ *strength=(t[m]>0?(double)(t[m]-t[f])/t[m]:0.0); ++ } ++ ++ return m; ++ } ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++ { ++ mp_image_t *dmpi, *tmpi=0; ++ int n, m, f, newphase; ++ struct vf_priv_s *p=vf->priv; ++ unsigned int checksum; ++ double d; ++ ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, ++ mpi->width, mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++ newphase=p->phase; ++ ++ switch(p->pass) ++ { ++ case 1: ++ fprintf(p->file, "%08x %d\n", ++ (unsigned int)imgop((void *)checksum_plane, mpi, 0, 0), ++ p->frameno?imgop(diff_plane, dmpi, mpi, 0):0); ++ break; ++ ++ case 2: ++ if(p->frameno/5>p->bcount) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, ++ "\n%s: Log file ends prematurely! " ++ "Switching to one pass mode.\n", vf->info->name); ++ p->pass=0; ++ break; ++ } ++ ++ checksum=(unsigned int)imgop((void *)checksum_plane, mpi, 0, 0); ++ ++ if(checksum!=p->csdata[p->frameno]) ++ { ++ for(f=0; f<100; f++) ++ if(p->frameno+ffcount && p->csdata[p->frameno+f]==checksum) ++ break; ++ else if(p->frameno-f>=0 && p->csdata[p->frameno-f]==checksum) ++ { ++ f=-f; ++ break; ++ } ++ ++ if(f<100) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_INFO, ++ "\n%s: Mismatch with pass-1: %+d frame(s).\n", ++ vf->info->name, f); ++ ++ p->frameno+=f; ++ p->misscount=0; ++ } ++ else if(p->misscount++>=30) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, ++ "\n%s: Sync with pass-1 lost! " ++ "Switching to one pass mode.\n", vf->info->name); ++ p->pass=0; ++ break; ++ } ++ } ++ ++ n=(p->frameno)/5; ++ if(n>=p->bcount) n=p->bcount-1; ++ ++ newphase=p->bdata[n]; ++ break; ++ ++ default: ++ if(p->frameno) ++ { ++ int *sump=p->sum+p->frameno%5, ++ *histp=p->history+p->frameno%p->window; ++ ++ *sump-=*histp; ++ *sump+=(*histp=imgop(diff_plane, dmpi, mpi, 0)); ++ } ++ ++ m=match(p, p->sum, -1, -1, &d); ++ ++ if(d>=p->threshold) ++ newphase=m; ++ } ++ ++ n=p->ocount++%5; ++ ++ if(newphase!=p->phase && ((p->phase+4)%5phase=newphase; ++ mp_msg(MSGT_VFILTER, MSGL_STATUS, ++ "\n%s: Telecine phase %d.\n", vf->info->name, p->phase); ++ } ++ ++ switch((p->frameno++-p->phase+10)%5) ++ { ++ case 0: ++ imgop(copyop, dmpi, mpi, 0); ++ return 0; ++ ++ case 4: ++ if(p->deghost>0) ++ { ++ tmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_READABLE, ++ mpi->width, mpi->height); ++ vf_clone_mpi_attributes(tmpi, mpi); ++ ++ imgop(copyop, tmpi, mpi, 0); ++ imgop(deghost_plane, tmpi, dmpi, p->deghost); ++ imgop(copyop, dmpi, mpi, 0); ++ return vf_next_put_image(vf, tmpi, MP_NOPTS_VALUE); ++ } ++ } ++ ++ imgop(copyop, dmpi, mpi, 0); ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ ++static int analyze(struct vf_priv_s *p) ++ { ++ int *buf=0, *bp, bufsize=0, n, b, f, i, j, m, s; ++ unsigned int *cbuf=0, *cp; ++ int8_t *pbuf; ++ int8_t lbuf[256]; ++ int sum[5]; ++ double d; ++ ++ /* read the file */ ++ ++ n=15; ++ while(fgets(lbuf, 256, p->file)) ++ { ++ if(n>=bufsize-19) ++ { ++ bufsize=bufsize?bufsize*2:30000; ++ if((bp=realloc(buf, bufsize*sizeof *buf))) buf=bp; ++ if((cp=realloc(cbuf, bufsize*sizeof *cbuf))) cbuf=cp; ++ ++ if(!bp || !cp) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Not enough memory.\n", ++ vf_info_divtc.name); ++ free(buf); ++ free(cbuf); ++ return 0; ++ } ++ } ++ sscanf(lbuf, "%x %d", cbuf+n, buf+n); ++ n++; ++ } ++ ++ if(!n) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "%s: Empty 2-pass log file.\n", ++ vf_info_divtc.name); ++ free(buf); ++ free(cbuf); ++ return 0; ++ } ++ ++ /* generate some dummy data past the beginning and end of the array */ ++ ++ buf+=15, cbuf+=15; ++ n-=15; ++ ++ memcpy(buf-15, buf, 15*sizeof *buf); ++ memset(cbuf-15, 0, 15*sizeof *cbuf); ++ ++ while(n%5) ++ buf[n]=buf[n-5], cbuf[n]=0, n++; ++ ++ memcpy(buf+n, buf+n-15, 15*sizeof *buf); ++ memset(cbuf+n, 0, 15*sizeof *cbuf); ++ ++ p->csdata=cbuf; ++ p->fcount=n; ++ ++ /* array with one slot for each slice of 5 frames */ ++ ++ p->bdata=pbuf=malloc(p->bcount=b=(n/5)); ++ memset(pbuf, 255, b); ++ ++ /* resolve the automatic mode */ ++ ++ if(p->deghost<0) ++ { ++ int deghost=-p->deghost; ++ double s0=0.0, s1=0.0; ++ ++ for(f=0; fdeghost=0; match(p, buf+f, -1, -1, &d); s0+=d; ++ p->deghost=1; match(p, buf+f, -1, -1, &d); s1+=d; ++ } ++ ++ p->deghost=s1>s0?deghost:0; ++ ++ mp_msg(MSGT_VFILTER, MSGL_INFO, ++ "%s: Deghosting %-3s (relative pattern strength %+.2fdB).\n", ++ vf_info_divtc.name, ++ p->deghost?"ON":"OFF", ++ 10.0*log10(s1/s0)); ++ } ++ ++ /* analyze the data */ ++ ++ for(f=0; f<5; f++) ++ for(sum[f]=0, n=-15; n<20; n+=5) ++ sum[f]+=buf[n+f]; ++ ++ for(f=0; f=p->threshold) ++ pbuf[f]=m; ++ ++ if(ff && mf; j--) ++ if(pbuf[j-1]==pbuf[f-1] && pbuf[j]==pbuf[n]) break; ++ for(s=m; spriv) ++ { ++ if(vf->priv->file) fclose(vf->priv->file); ++ if(vf->priv->csdata) free(vf->priv->csdata-15); ++ free(vf->priv->bdata); ++ free(vf->priv->history); ++ free(vf->priv); ++ } ++ } ++ ++static int vf_open(vf_instance_t *vf, char *args) ++ { ++ struct vf_priv_s *p; ++ const char *filename="framediff.log"; ++ char *ap, *q, *a; ++ ++ if(args && !(args=av_strdup(args))) ++ { ++ nomem: ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "%s: Not enough memory.\n", vf->info->name); ++ fail: ++ uninit(vf); ++ free(args); ++ return 0; ++ } ++ ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ vf->query_format=query_format; ++ vf->default_reqs=VFCAP_ACCEPT_STRIDE; ++ if(!(vf->priv=p=calloc(1, sizeof(struct vf_priv_s)))) ++ goto nomem; ++ ++ p->phase=5; ++ p->threshold=0.5; ++ p->window=30; ++ ++ if((ap=args)) ++ while(*ap) ++ { ++ q=ap; ++ if((ap=strchr(q, ':'))) *ap++=0; else ap=q+strlen(q); ++ if((a=strchr(q, '='))) *a++=0; else a=q+strlen(q); ++ ++ switch(*q) ++ { ++ case 0: break; ++ case 'f': filename=a; break; ++ case 't': p->threshold=atof(a); break; ++ case 'w': p->window=5*(atoi(a)+4)/5; break; ++ case 'd': p->deghost=atoi(a); break; ++ case 'p': ++ if(q[1]=='h') p->phase=atoi(a); ++ else p->pass=atoi(a); ++ break; ++ ++ case 'h': ++ mp_msg(MSGT_VFILTER, MSGL_INFO, ++ "\n%s options:\n\n" ++ "pass=1|2 - Use 2-pass mode.\n" ++ "file=filename - Set the 2-pass log file name " ++ "(default %s).\n" ++ "threshold=value - Set the pattern recognition " ++ "sensitivity (default %g).\n" ++ "deghost=value - Select deghosting threshold " ++ "(default %d).\n" ++ "window=numframes - Set the statistics window " ++ "for 1-pass mode (default %d).\n" ++ "phase=0|1|2|3|4 - Set the initial phase " ++ "for 1-pass mode (default %d).\n\n" ++ "The option names can be abbreviated to the shortest " ++ "unique prefix.\n\n", ++ vf->info->name, filename, p->threshold, p->deghost, ++ p->window, p->phase%5); ++ break; ++ ++ default: ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "%s: Unknown argument %s.\n", vf->info->name, q); ++ goto fail; ++ } ++ } ++ ++ switch(p->pass) ++ { ++ case 1: ++ if(!(p->file=fopen(filename, "w"))) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "%s: Can't create file %s.\n", vf->info->name, filename); ++ goto fail; ++ } ++ ++ break; ++ ++ case 2: ++ if(!(p->file=fopen(filename, "r"))) ++ { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "%s: Can't open file %s.\n", vf->info->name, filename); ++ goto fail; ++ } ++ ++ if(!analyze(p)) ++ goto fail; ++ ++ fclose(p->file); ++ p->file=0; ++ break; ++ } ++ ++ if(p->window<5) p->window=5; ++ if(!(p->history=calloc(sizeof *p->history, p->window))) ++ goto nomem; ++ ++ diff = diff_C; ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++ if(gCpuCaps.hasMMX) diff = diff_MMX; ++#endif ++ ++ free(args); ++ return 1; ++ } ++ ++const vf_info_t vf_info_divtc = ++ { ++ "inverse telecine for deinterlaced video", ++ "divtc", ++ "Ville Saari", ++ "", ++ vf_open, ++ NULL ++ }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_down3dright.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_down3dright.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_down3dright.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_down3dright.c 2012-05-14 14:08:54.738348112 +0200 +@@ -0,0 +1,166 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++struct vf_priv_s { ++ int skipline; ++ int scalew; ++ int scaleh; ++}; ++ ++static void toright(unsigned char *dst[3], unsigned char *src[3], ++ int dststride[3], int srcstride[3], ++ int w, int h, struct vf_priv_s* p) ++{ ++ int k; ++ ++ for (k = 0; k < 3; k++) { ++ unsigned char* fromL = src[k]; ++ unsigned char* fromR = src[k]; ++ unsigned char* to = dst[k]; ++ int src = srcstride[k]; ++ int dst = dststride[k]; ++ int ss; ++ unsigned int dd; ++ int i; ++ ++ if (k > 0) { ++ i = h / 4 - p->skipline / 2; ++ ss = src * (h / 4 + p->skipline / 2); ++ dd = w / 4; ++ } else { ++ i = h / 2 - p->skipline; ++ ss = src * (h / 2 + p->skipline); ++ dd = w / 2; ++ } ++ fromR += ss; ++ for ( ; i > 0; i--) { ++ int j; ++ unsigned char* t = to; ++ unsigned char* sL = fromL; ++ unsigned char* sR = fromR; ++ ++ if (p->scalew == 1) { ++ for (j = dd; j > 0; j--) { ++ *t++ = (sL[0] + sL[1]) / 2; ++ sL+=2; ++ } ++ for (j = dd ; j > 0; j--) { ++ *t++ = (sR[0] + sR[1]) / 2; ++ sR+=2; ++ } ++ } else { ++ for (j = dd * 2 ; j > 0; j--) ++ *t++ = *sL++; ++ for (j = dd * 2 ; j > 0; j--) ++ *t++ = *sR++; ++ } ++ if (p->scaleh == 1) { ++ fast_memcpy(to + dst, to, dst); ++ to += dst; ++ } ++ to += dst; ++ fromL += src; ++ fromR += src; ++ } ++ //printf("K %d %d %d %d %d \n", k, w, h, src, dst); ++ } ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next, IMGFMT_YV12, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | ++ (vf->priv->scaleh == 1) ? MP_IMGFLAG_READABLE : 0, ++ mpi->w * vf->priv->scalew, ++ mpi->h / vf->priv->scaleh - vf->priv->skipline); ++ ++ toright(dmpi->planes, mpi->planes, dmpi->stride, ++ mpi->stride, mpi->w, mpi->h, vf->priv); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ /* FIXME - also support UYVY output? */ ++ return vf_next_config(vf, width * vf->priv->scalew, ++ height / vf->priv->scaleh - vf->priv->skipline, d_width, d_height, flags, IMGFMT_YV12); ++} ++ ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - really any YUV 4:2:0 input format should work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, IMGFMT_YV12); ++ } ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->config=config; ++ vf->query_format=query_format; ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ ++ vf->priv = calloc(1, sizeof (struct vf_priv_s)); ++ vf->priv->skipline = 0; ++ vf->priv->scalew = 1; ++ vf->priv->scaleh = 2; ++ if (args) sscanf(args, "%d:%d:%d", &vf->priv->skipline, &vf->priv->scalew, &vf->priv->scaleh); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_down3dright = { ++ "convert stereo movie from top-bottom to left-right field", ++ "down3dright", ++ "Zdenek Kabelac", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_dsize.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_dsize.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_dsize.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_dsize.c 2012-05-14 14:08:54.738348112 +0200 +@@ -0,0 +1,123 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int w, h; ++ int method; // aspect method, 0 -> downscale, 1-> upscale. +2 -> original aspect. ++ int round; ++ float aspect; ++}; ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ if (vf->priv->aspect < 0.001) { // did the user input aspect or w,h params ++ if (vf->priv->w == 0) vf->priv->w = d_width; ++ if (vf->priv->h == 0) vf->priv->h = d_height; ++ if (vf->priv->w == -1) vf->priv->w = width; ++ if (vf->priv->h == -1) vf->priv->h = height; ++ if (vf->priv->w == -2) vf->priv->w = vf->priv->h * (double)d_width / d_height; ++ if (vf->priv->w == -3) vf->priv->w = vf->priv->h * (double)width / height; ++ if (vf->priv->h == -2) vf->priv->h = vf->priv->w * (double)d_height / d_width; ++ if (vf->priv->h == -3) vf->priv->h = vf->priv->w * (double)height / width; ++ if (vf->priv->method > -1) { ++ double aspect = (vf->priv->method & 2) ? ((double)height / width) : ((double)d_height / d_width); ++ if ((vf->priv->h > vf->priv->w * aspect) ^ (vf->priv->method & 1)) { ++ vf->priv->h = vf->priv->w * aspect; ++ } else { ++ vf->priv->w = vf->priv->h / aspect; ++ } ++ } ++ if (vf->priv->round > 1) { // round up ++ vf->priv->w += (vf->priv->round - 1 - (vf->priv->w - 1) % vf->priv->round); ++ vf->priv->h += (vf->priv->round - 1 - (vf->priv->h - 1) % vf->priv->round); ++ } ++ d_width = vf->priv->w; ++ d_height = vf->priv->h; ++ } else { ++ if (vf->priv->aspect * height > width) { ++ d_width = height * vf->priv->aspect + .5; ++ d_height = height; ++ } else { ++ d_height = width / vf->priv->aspect + .5; ++ d_width = width; ++ } ++ } ++ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); ++} ++ ++static void uninit(vf_instance_t *vf) { ++ free(vf->priv); ++ vf->priv = NULL; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->config = config; ++ vf->draw_slice = vf_next_draw_slice; ++ vf->uninit = uninit; ++ //vf->default_caps = 0; ++ vf->priv = calloc(sizeof(struct vf_priv_s), 1); ++ vf->priv->aspect = 0.; ++ vf->priv->w = -1; ++ vf->priv->h = -1; ++ vf->priv->method = -1; ++ vf->priv->round = 1; ++ if (args) { ++ if (strchr(args, '/')) { ++ int w, h; ++ sscanf(args, "%d/%d", &w, &h); ++ vf->priv->aspect = (float)w/h; ++ } else if (strchr(args, '.')) { ++ sscanf(args, "%f", &vf->priv->aspect); ++ } else { ++ sscanf(args, "%d:%d:%d:%d", &vf->priv->w, &vf->priv->h, &vf->priv->method, &vf->priv->round); ++ } ++ } ++ if ((vf->priv->aspect < 0.) || (vf->priv->w < -3) || (vf->priv->h < -3) || ++ ((vf->priv->w < -1) && (vf->priv->h < -1)) || ++ (vf->priv->method < -1) || (vf->priv->method > 3) || ++ (vf->priv->round < 0)) { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, "[dsize] Illegal value(s): aspect: %f w: %d h: %d aspect_method: %d round: %d\n", vf->priv->aspect, vf->priv->w, vf->priv->h, vf->priv->method, vf->priv->round); ++ free(vf->priv); vf->priv = NULL; ++ return -1; ++ } ++ return 1; ++} ++ ++const vf_info_t vf_info_dsize = { ++ "reset displaysize/aspect", ++ "dsize", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq2.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq2.c 2012-05-14 14:08:54.741348173 +0200 +@@ -0,0 +1,519 @@ ++/* ++ * Software equalizer (brightness, contrast, gamma, saturation) ++ * ++ * Hampa Hug (original LUT gamma/contrast/brightness filter) ++ * Daniel Moreno (saturation, R/G/B gamma support) ++ * Richard Felker (original MMX contrast/brightness code (vf_eq.c)) ++ * Michael Niedermayer (LUT16) ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#define LUT16 ++ ++/* Per channel parameters */ ++typedef struct eq2_param_t { ++ unsigned char lut[256]; ++#ifdef LUT16 ++ uint16_t lut16[256*256]; ++#endif ++ int lut_clean; ++ ++ void (*adjust) (struct eq2_param_t *par, unsigned char *dst, unsigned char *src, ++ unsigned w, unsigned h, unsigned dstride, unsigned sstride); ++ ++ double c; ++ double b; ++ double g; ++ double w; ++} eq2_param_t; ++ ++typedef struct vf_priv_s { ++ eq2_param_t param[3]; ++ ++ double contrast; ++ double brightness; ++ double saturation; ++ ++ double gamma; ++ double gamma_weight; ++ double rgamma; ++ double ggamma; ++ double bgamma; ++ ++ unsigned buf_w[3]; ++ unsigned buf_h[3]; ++ unsigned char *buf[3]; ++} vf_eq2_t; ++ ++ ++static ++void create_lut (eq2_param_t *par) ++{ ++ unsigned i; ++ double g, v; ++ double lw, gw; ++ ++ g = par->g; ++ gw = par->w; ++ lw = 1.0 - gw; ++ ++ if ((g < 0.001) || (g > 1000.0)) { ++ g = 1.0; ++ } ++ ++ g = 1.0 / g; ++ ++ for (i = 0; i < 256; i++) { ++ v = (double) i / 255.0; ++ v = par->c * (v - 0.5) + 0.5 + par->b; ++ ++ if (v <= 0.0) { ++ par->lut[i] = 0; ++ } ++ else { ++ v = v*lw + pow(v, g)*gw; ++ ++ if (v >= 1.0) { ++ par->lut[i] = 255; ++ } ++ else { ++ par->lut[i] = (unsigned char) (256.0 * v); ++ } ++ } ++ } ++ ++#ifdef LUT16 ++ for(i=0; i<256*256; i++){ ++ par->lut16[i]= par->lut[i&0xFF] + (par->lut[i>>8]<<8); ++ } ++#endif ++ ++ par->lut_clean = 1; ++} ++ ++#if HAVE_MMX ++static ++void affine_1d_MMX (eq2_param_t *par, unsigned char *dst, unsigned char *src, ++ unsigned w, unsigned h, unsigned dstride, unsigned sstride) ++{ ++ unsigned i; ++ int contrast, brightness; ++ unsigned dstep, sstep; ++ int pel; ++ short brvec[4]; ++ short contvec[4]; ++ ++// printf("\nmmx: src=%p dst=%p w=%d h=%d ds=%d ss=%d\n",src,dst,w,h,dstride,sstride); ++ ++ contrast = (int) (par->c * 256 * 16); ++ brightness = ((int) (100.0 * par->b + 100.0) * 511) / 200 - 128 - contrast / 32; ++ ++ brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; ++ contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; ++ ++ sstep = sstride - w; ++ dstep = dstride - w; ++ ++ while (h-- > 0) { ++ __asm__ volatile ( ++ "movq (%5), %%mm3 \n\t" ++ "movq (%6), %%mm4 \n\t" ++ "pxor %%mm0, %%mm0 \n\t" ++ "movl %4, %%eax\n\t" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%0), %%mm1 \n\t" ++ "movq (%0), %%mm2 \n\t" ++ "punpcklbw %%mm0, %%mm1 \n\t" ++ "punpckhbw %%mm0, %%mm2 \n\t" ++ "psllw $4, %%mm1 \n\t" ++ "psllw $4, %%mm2 \n\t" ++ "pmulhw %%mm4, %%mm1 \n\t" ++ "pmulhw %%mm4, %%mm2 \n\t" ++ "paddw %%mm3, %%mm1 \n\t" ++ "paddw %%mm3, %%mm2 \n\t" ++ "packuswb %%mm2, %%mm1 \n\t" ++ "add $8, %0 \n\t" ++ "movq %%mm1, (%1) \n\t" ++ "add $8, %1 \n\t" ++ "decl %%eax \n\t" ++ "jnz 1b \n\t" ++ : "=r" (src), "=r" (dst) ++ : "0" (src), "1" (dst), "r" (w >> 3), "r" (brvec), "r" (contvec) ++ : "%eax" ++ ); ++ ++ for (i = w & 7; i > 0; i--) { ++ pel = ((*src++ * contrast) >> 12) + brightness; ++ if (pel & 768) { ++ pel = (-pel) >> 31; ++ } ++ *dst++ = pel; ++ } ++ ++ src += sstep; ++ dst += dstep; ++ } ++ ++ __asm__ volatile ( "emms \n\t" ::: "memory" ); ++} ++#endif ++ ++static ++void apply_lut (eq2_param_t *par, unsigned char *dst, unsigned char *src, ++ unsigned w, unsigned h, unsigned dstride, unsigned sstride) ++{ ++ unsigned i, j, w2; ++ unsigned char *lut; ++ uint16_t *lut16; ++ ++ if (!par->lut_clean) { ++ create_lut (par); ++ } ++ ++ lut = par->lut; ++#ifdef LUT16 ++ lut16 = par->lut16; ++ w2= (w>>3)<<2; ++ for (j = 0; j < h; j++) { ++ uint16_t *src16= (uint16_t*)src; ++ uint16_t *dst16= (uint16_t*)dst; ++ for (i = 0; i < w2; i+=4) { ++ dst16[i+0] = lut16[src16[i+0]]; ++ dst16[i+1] = lut16[src16[i+1]]; ++ dst16[i+2] = lut16[src16[i+2]]; ++ dst16[i+3] = lut16[src16[i+3]]; ++ } ++ i <<= 1; ++#else ++ w2= (w>>3)<<3; ++ for (j = 0; j < h; j++) { ++ for (i = 0; i < w2; i+=8) { ++ dst[i+0] = lut[src[i+0]]; ++ dst[i+1] = lut[src[i+1]]; ++ dst[i+2] = lut[src[i+2]]; ++ dst[i+3] = lut[src[i+3]]; ++ dst[i+4] = lut[src[i+4]]; ++ dst[i+5] = lut[src[i+5]]; ++ dst[i+6] = lut[src[i+6]]; ++ dst[i+7] = lut[src[i+7]]; ++ } ++#endif ++ for (; i < w; i++) { ++ dst[i] = lut[src[i]]; ++ } ++ ++ src += sstride; ++ dst += dstride; ++ } ++} ++ ++static ++int put_image (vf_instance_t *vf, mp_image_t *src, double pts) ++{ ++ unsigned i; ++ vf_eq2_t *eq2; ++ mp_image_t *dst; ++ unsigned long img_n,img_c; ++ ++ eq2 = vf->priv; ++ ++ if ((eq2->buf_w[0] != src->w) || (eq2->buf_h[0] != src->h)) { ++ eq2->buf_w[0] = src->w; ++ eq2->buf_h[0] = src->h; ++ eq2->buf_w[1] = eq2->buf_w[2] = src->w >> src->chroma_x_shift; ++ eq2->buf_h[1] = eq2->buf_h[2] = src->h >> src->chroma_y_shift; ++ img_n = eq2->buf_w[0]*eq2->buf_h[0]; ++ if(src->num_planes>1){ ++ img_c = eq2->buf_w[1]*eq2->buf_h[1]; ++ eq2->buf[0] = realloc (eq2->buf[0], img_n + 2*img_c); ++ eq2->buf[1] = eq2->buf[0] + img_n; ++ eq2->buf[2] = eq2->buf[1] + img_c; ++ } else ++ eq2->buf[0] = realloc (eq2->buf[0], img_n); ++ } ++ ++ dst = vf_get_image (vf->next, src->imgfmt, MP_IMGTYPE_EXPORT, 0, src->w, src->h); ++ ++ for (i = 0; i < ((src->num_planes>1)?3:1); i++) { ++ if (eq2->param[i].adjust != NULL) { ++ dst->planes[i] = eq2->buf[i]; ++ dst->stride[i] = eq2->buf_w[i]; ++ ++ eq2->param[i].adjust (&eq2->param[i], dst->planes[i], src->planes[i], ++ eq2->buf_w[i], eq2->buf_h[i], dst->stride[i], src->stride[i]); ++ } ++ else { ++ dst->planes[i] = src->planes[i]; ++ dst->stride[i] = src->stride[i]; ++ } ++ } ++ ++ return vf_next_put_image (vf, dst, pts); ++} ++ ++static ++void check_values (eq2_param_t *par) ++{ ++ /* yuck! floating point comparisons... */ ++ ++ if ((par->c == 1.0) && (par->b == 0.0) && (par->g == 1.0)) { ++ par->adjust = NULL; ++ } ++#if HAVE_MMX ++ else if (par->g == 1.0 && gCpuCaps.hasMMX) { ++ par->adjust = &affine_1d_MMX; ++ } ++#endif ++ else { ++ par->adjust = &apply_lut; ++ } ++} ++ ++static ++void print_values (vf_eq2_t *eq2) ++{ ++ mp_msg (MSGT_VFILTER, MSGL_V, "vf_eq2: c=%.2f b=%.2f g=%.4f s=%.2f \n", ++ eq2->contrast, eq2->brightness, eq2->gamma, eq2->saturation ++ ); ++} ++ ++static ++void set_contrast (vf_eq2_t *eq2, double c) ++{ ++ eq2->contrast = c; ++ eq2->param[0].c = c; ++ eq2->param[0].lut_clean = 0; ++ check_values (&eq2->param[0]); ++ print_values (eq2); ++} ++ ++static ++void set_brightness (vf_eq2_t *eq2, double b) ++{ ++ eq2->brightness = b; ++ eq2->param[0].b = b; ++ eq2->param[0].lut_clean = 0; ++ check_values (&eq2->param[0]); ++ print_values (eq2); ++} ++ ++static ++void set_gamma (vf_eq2_t *eq2, double g) ++{ ++ eq2->gamma = g; ++ ++ eq2->param[0].g = eq2->gamma * eq2->ggamma; ++ eq2->param[1].g = sqrt (eq2->bgamma / eq2->ggamma); ++ eq2->param[2].g = sqrt (eq2->rgamma / eq2->ggamma); ++ eq2->param[0].w = eq2->param[1].w = eq2->param[2].w = eq2->gamma_weight; ++ ++ eq2->param[0].lut_clean = 0; ++ eq2->param[1].lut_clean = 0; ++ eq2->param[2].lut_clean = 0; ++ ++ check_values (&eq2->param[0]); ++ check_values (&eq2->param[1]); ++ check_values (&eq2->param[2]); ++ ++ print_values (eq2); ++} ++ ++static ++void set_saturation (vf_eq2_t *eq2, double s) ++{ ++ eq2->saturation = s; ++ ++ eq2->param[1].c = s; ++ eq2->param[2].c = s; ++ ++ eq2->param[1].lut_clean = 0; ++ eq2->param[2].lut_clean = 0; ++ ++ check_values (&eq2->param[1]); ++ check_values (&eq2->param[2]); ++ ++ print_values (eq2); ++} ++ ++static ++int control (vf_instance_t *vf, int request, void *data) ++{ ++ vf_equalizer_t *eq; ++ ++ switch (request) { ++ case VFCTRL_SET_EQUALIZER: ++ eq = (vf_equalizer_t *) data; ++ ++ if (strcmp (eq->item, "gamma") == 0) { ++ set_gamma (vf->priv, exp (log (8.0) * eq->value / 100.0)); ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "contrast") == 0) { ++ set_contrast (vf->priv, (1.0 / 100.0) * (eq->value + 100)); ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "brightness") == 0) { ++ set_brightness (vf->priv, (1.0 / 100.0) * eq->value); ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "saturation") == 0) { ++ set_saturation (vf->priv, (double) (eq->value + 100) / 100.0); ++ return CONTROL_TRUE; ++ } ++ break; ++ ++ case VFCTRL_GET_EQUALIZER: ++ eq = (vf_equalizer_t *) data; ++ if (strcmp (eq->item, "gamma") == 0) { ++ eq->value = (int) (100.0 * log (vf->priv->gamma) / log (8.0)); ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "contrast") == 0) { ++ eq->value = (int) (100.0 * vf->priv->contrast) - 100; ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "brightness") == 0) { ++ eq->value = (int) (100.0 * vf->priv->brightness); ++ return CONTROL_TRUE; ++ } ++ else if (strcmp (eq->item, "saturation") == 0) { ++ eq->value = (int) (100.0 * vf->priv->saturation) - 100; ++ return CONTROL_TRUE; ++ } ++ break; ++ } ++ ++ return vf_next_control (vf, request, data); ++} ++ ++static ++int query_format (vf_instance_t *vf, unsigned fmt) ++{ ++ switch (fmt) { ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format (vf, fmt); ++ } ++ ++ return 0; ++} ++ ++static ++void uninit (vf_instance_t *vf) ++{ ++ if (vf->priv != NULL) { ++ free (vf->priv->buf[0]); ++ free (vf->priv); ++ } ++} ++ ++static ++int vf_open(vf_instance_t *vf, char *args) ++{ ++ unsigned i; ++ vf_eq2_t *eq2; ++ double par[8]; ++ ++ vf->control = control; ++ vf->query_format = query_format; ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ ++ vf->priv = malloc (sizeof (vf_eq2_t)); ++ eq2 = vf->priv; ++ ++ for (i = 0; i < 3; i++) { ++ eq2->buf[i] = NULL; ++ eq2->buf_w[i] = 0; ++ eq2->buf_h[i] = 0; ++ ++ eq2->param[i].adjust = NULL; ++ eq2->param[i].c = 1.0; ++ eq2->param[i].b = 0.0; ++ eq2->param[i].g = 1.0; ++ eq2->param[i].lut_clean = 0; ++ } ++ ++ eq2->contrast = 1.0; ++ eq2->brightness = 0.0; ++ eq2->saturation = 1.0; ++ ++ eq2->gamma = 1.0; ++ eq2->gamma_weight = 1.0; ++ eq2->rgamma = 1.0; ++ eq2->ggamma = 1.0; ++ eq2->bgamma = 1.0; ++ ++ if (args != NULL) { ++ par[0] = 1.0; ++ par[1] = 1.0; ++ par[2] = 0.0; ++ par[3] = 1.0; ++ par[4] = 1.0; ++ par[5] = 1.0; ++ par[6] = 1.0; ++ par[7] = 1.0; ++ sscanf (args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf", ++ par, par + 1, par + 2, par + 3, par + 4, par + 5, par + 6, par + 7 ++ ); ++ ++ eq2->rgamma = par[4]; ++ eq2->ggamma = par[5]; ++ eq2->bgamma = par[6]; ++ eq2->gamma_weight = par[7]; ++ ++ set_gamma (eq2, par[0]); ++ set_contrast (eq2, par[1]); ++ set_brightness (eq2, par[2]); ++ set_saturation (eq2, par[3]); ++ } ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_eq2 = { ++ "Software equalizer", ++ "eq2", ++ "Hampa Hug, Daniel Moreno, Richard Felker", ++ "", ++ &vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_eq.c 2012-05-14 14:08:54.739348133 +0200 +@@ -0,0 +1,240 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/video_out.h" ++ ++static struct vf_priv_s { ++ unsigned char *buf; ++ int brightness; ++ int contrast; ++}; ++ ++#if HAVE_MMX ++static void process_MMX(unsigned char *dest, int dstride, unsigned char *src, int sstride, ++ int w, int h, int brightness, int contrast) ++{ ++ int i; ++ int pel; ++ int dstep = dstride-w; ++ int sstep = sstride-w; ++ short brvec[4]; ++ short contvec[4]; ++ ++ contrast = ((contrast+100)*256*16)/100; ++ brightness = ((brightness+100)*511)/200-128 - contrast/32; ++ ++ brvec[0] = brvec[1] = brvec[2] = brvec[3] = brightness; ++ contvec[0] = contvec[1] = contvec[2] = contvec[3] = contrast; ++ ++ while (h--) { ++ __asm__ volatile ( ++ "movq (%5), %%mm3 \n\t" ++ "movq (%6), %%mm4 \n\t" ++ "pxor %%mm0, %%mm0 \n\t" ++ "movl %4, %%eax\n\t" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%0), %%mm1 \n\t" ++ "movq (%0), %%mm2 \n\t" ++ "punpcklbw %%mm0, %%mm1 \n\t" ++ "punpckhbw %%mm0, %%mm2 \n\t" ++ "psllw $4, %%mm1 \n\t" ++ "psllw $4, %%mm2 \n\t" ++ "pmulhw %%mm4, %%mm1 \n\t" ++ "pmulhw %%mm4, %%mm2 \n\t" ++ "paddw %%mm3, %%mm1 \n\t" ++ "paddw %%mm3, %%mm2 \n\t" ++ "packuswb %%mm2, %%mm1 \n\t" ++ "add $8, %0 \n\t" ++ "movq %%mm1, (%1) \n\t" ++ "add $8, %1 \n\t" ++ "decl %%eax \n\t" ++ "jnz 1b \n\t" ++ : "=r" (src), "=r" (dest) ++ : "0" (src), "1" (dest), "r" (w>>3), "r" (brvec), "r" (contvec) ++ : "%eax" ++ ); ++ ++ for (i = w&7; i; i--) ++ { ++ pel = ((*src++* contrast)>>12) + brightness; ++ if(pel&768) pel = (-pel)>>31; ++ *dest++ = pel; ++ } ++ ++ src += sstep; ++ dest += dstep; ++ } ++ __asm__ volatile ( "emms \n\t" ::: "memory" ); ++} ++#endif ++ ++static void process_C(unsigned char *dest, int dstride, unsigned char *src, int sstride, ++ int w, int h, int brightness, int contrast) ++{ ++ int i; ++ int pel; ++ int dstep = dstride-w; ++ int sstep = sstride-w; ++ ++ contrast = ((contrast+100)*256*256)/100; ++ brightness = ((brightness+100)*511)/200-128 - contrast/512; ++ ++ while (h--) { ++ for (i = w; i; i--) ++ { ++ pel = ((*src++* contrast)>>16) + brightness; ++ if(pel&768) pel = (-pel)>>31; ++ *dest++ = pel; ++ } ++ src += sstep; ++ dest += dstep; ++ } ++} ++ ++static void (*process)(unsigned char *dest, int dstride, unsigned char *src, int sstride, ++ int w, int h, int brightness, int contrast); ++ ++/* FIXME: add packed yuv version of process */ ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, ++ mpi->w, mpi->h); ++ ++ dmpi->stride[0] = mpi->stride[0]; ++ dmpi->planes[1] = mpi->planes[1]; ++ dmpi->planes[2] = mpi->planes[2]; ++ dmpi->stride[1] = mpi->stride[1]; ++ dmpi->stride[2] = mpi->stride[2]; ++ ++ if (!vf->priv->buf) vf->priv->buf = malloc(mpi->stride[0]*mpi->h); ++ ++ if ((vf->priv->brightness == 0) && (vf->priv->contrast == 0)) ++ dmpi->planes[0] = mpi->planes[0]; ++ else { ++ dmpi->planes[0] = vf->priv->buf; ++ process(dmpi->planes[0], dmpi->stride[0], ++ mpi->planes[0], mpi->stride[0], ++ mpi->w, mpi->h, vf->priv->brightness, ++ vf->priv->contrast); ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static int control(struct vf_instance *vf, int request, void* data) ++{ ++ vf_equalizer_t *eq; ++ ++ switch (request) { ++ case VFCTRL_SET_EQUALIZER: ++ eq = data; ++ if (!strcmp(eq->item,"brightness")) { ++ vf->priv->brightness = eq->value; ++ return CONTROL_TRUE; ++ } ++ else if (!strcmp(eq->item,"contrast")) { ++ vf->priv->contrast = eq->value; ++ return CONTROL_TRUE; ++ } ++ break; ++ case VFCTRL_GET_EQUALIZER: ++ eq = data; ++ if (!strcmp(eq->item,"brightness")) { ++ eq->value = vf->priv->brightness; ++ return CONTROL_TRUE; ++ } ++ else if (!strcmp(eq->item,"contrast")) { ++ eq->value = vf->priv->contrast; ++ return CONTROL_TRUE; ++ } ++ break; ++ } ++ return vf_next_control(vf, request, data); ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch (fmt) { ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_NV12: ++ case IMGFMT_NV21: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv->buf); ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->control=control; ++ vf->query_format=query_format; ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ ++ vf->priv = malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ if (args) sscanf(args, "%d:%d", &vf->priv->brightness, &vf->priv->contrast); ++ ++ process = process_C; ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) process = process_MMX; ++#endif ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_eq = { ++ "soft video equalizer", ++ "eq", ++ "Richard Felker", ++ "", ++ vf_open, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_field.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_field.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_field.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_field.c 2012-05-14 14:08:54.741348173 +0200 +@@ -0,0 +1,89 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int field; ++}; ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ return vf_next_config(vf,width,height/2,d_width,d_height,flags,outfmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->width, mpi->height/2); ++ ++ // set up mpi as a double-stride image of dmpi: ++ vf->dmpi->planes[0]=mpi->planes[0]+mpi->stride[0]*vf->priv->field; ++ vf->dmpi->stride[0]=2*mpi->stride[0]; ++ if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){ ++ vf->dmpi->planes[1]=mpi->planes[1]+ ++ mpi->stride[1]*vf->priv->field; ++ vf->dmpi->stride[1]=2*mpi->stride[1]; ++ vf->dmpi->planes[2]=mpi->planes[2]+ ++ mpi->stride[2]*vf->priv->field; ++ vf->dmpi->stride[2]=2*mpi->stride[2]; ++ } else ++ vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!! ++ ++ return vf_next_put_image(vf,vf->dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ vf->default_reqs=VFCAP_ACCEPT_STRIDE; ++ vf->priv=calloc(1, sizeof(struct vf_priv_s)); ++ if (args) sscanf(args, "%d", &vf->priv->field); ++ vf->priv->field &= 1; ++ return 1; ++} ++ ++const vf_info_t vf_info_field = { ++ "extract single field", ++ "field", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fil.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fil.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fil.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fil.c 2012-05-14 14:08:54.742348193 +0200 +@@ -0,0 +1,116 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int interleave; ++ int height; ++ int width; ++ int stridefactor; ++}; ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int pixel_stride= (width+15)&~15; //FIXME this is ust a guess ... especially for non planar its somewhat bad one ++ ++#if 0 ++ if(mpi->flags&MP_IMGFLAG_PLANAR) ++ pixel_stride= mpi->stride[0]; ++ else ++ pixel_stride= 8*mpi->stride[0] / mpi->bpp; ++ ++#endif ++ ++ if(vf->priv->interleave){ ++ vf->priv->height= 2*height; ++ vf->priv->width= width - (pixel_stride/2); ++ vf->priv->stridefactor=1; ++ }else{ ++ vf->priv->height= height/2; ++ vf->priv->width= width + pixel_stride; ++ vf->priv->stridefactor=4; ++ } ++//printf("hX %d %d %d\n", vf->priv->width,vf->priv->height,vf->priv->stridefactor); ++ ++ return vf_next_config(vf, vf->priv->width, vf->priv->height, ++ (d_width*vf->priv->stridefactor)>>1, 2*d_height/vf->priv->stridefactor, flags, outfmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ if(mpi->flags&MP_IMGFLAG_DIRECT){ ++ // we've used DR, so we're ready... ++ return vf_next_put_image(vf,(mp_image_t*)mpi->priv, pts); ++ } ++ ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, ++ vf->priv->width, vf->priv->height); ++ ++ // set up mpi as a double-stride image of dmpi: ++ vf->dmpi->planes[0]=mpi->planes[0]; ++ vf->dmpi->stride[0]=(mpi->stride[0]*vf->priv->stridefactor)>>1; ++ if(vf->dmpi->flags&MP_IMGFLAG_PLANAR){ ++ vf->dmpi->planes[1]=mpi->planes[1]; ++ vf->dmpi->stride[1]=(mpi->stride[1]*vf->priv->stridefactor)>>1; ++ vf->dmpi->planes[2]=mpi->planes[2]; ++ vf->dmpi->stride[2]=(mpi->stride[2]*vf->priv->stridefactor)>>1; ++ } else ++ vf->dmpi->planes[1]=mpi->planes[1]; // passthru bgr8 palette!!! ++ ++ return vf_next_put_image(vf,vf->dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ vf->default_reqs=VFCAP_ACCEPT_STRIDE; ++ vf->priv=calloc(1, sizeof(struct vf_priv_s)); ++ vf->priv->interleave= args && (*args == 'i'); ++ return 1; ++} ++ ++const vf_info_t vf_info_fil = { ++ "fast (de)interleaver", ++ "fil", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_filmdint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_filmdint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_filmdint.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_filmdint.c 2012-05-14 14:08:54.746348273 +0200 +@@ -0,0 +1,1461 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vd.h" ++#include "vf.h" ++#include "cmmx.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++#define NUM_STORED 4 ++ ++enum pu_field_type_t { ++ PU_1ST_OF_3, ++ PU_2ND_OF_3, ++ PU_3RD_OF_3, ++ PU_1ST_OF_2, ++ PU_2ND_OF_2, ++ PU_INTERLACED ++}; ++ ++struct metrics { ++ /* This struct maps to a packed word 64-bit MMX register */ ++ unsigned short int even; ++ unsigned short int odd; ++ unsigned short int noise; ++ unsigned short int temp; ++} __attribute__ ((aligned (8))); ++ ++struct frame_stats { ++ struct metrics tiny, low, high, bigger, twox, max; ++ struct { unsigned int even, odd, noise, temp; } sad; ++ unsigned short interlaced_high; ++ unsigned short interlaced_low; ++ unsigned short num_blocks; ++}; ++ ++struct vf_priv_s { ++ unsigned long inframes; ++ unsigned long outframes; ++ enum pu_field_type_t prev_type; ++ unsigned swapped, chroma_swapped; ++ unsigned luma_only; ++ unsigned verbose; ++ unsigned fast; ++ unsigned long w, h, cw, ch, stride, chroma_stride, nplanes; ++ unsigned long sad_thres; ++ unsigned long dint_thres; ++ unsigned char *memory_allocated; ++ unsigned char *planes[2*NUM_STORED][4]; ++ unsigned char **old_planes; ++ unsigned long static_idx; ++ unsigned long temp_idx; ++ unsigned long crop_x, crop_y, crop_cx, crop_cy; ++ unsigned long export_count, merge_count; ++ unsigned long num_breaks; ++ unsigned long num_copies; ++ long in_inc, out_dec, iosync; ++ long num_fields; ++ long prev_fields; ++ long notout; ++ long mmx2; ++ unsigned small_bytes[2]; ++ unsigned mmx_temp[2]; ++ struct frame_stats stats[2]; ++ struct metrics thres; ++ char chflag; ++ double diff_time, merge_time, decode_time, vo_time, filter_time; ++}; ++ ++#define PPZ { 2000, 2000, 0, 2000 } ++#define PPR { 2000, 2000, 0, 2000 } ++static const struct frame_stats ppzs = {PPZ,PPZ,PPZ,PPZ,PPZ,PPZ,PPZ,0,0,9999}; ++static const struct frame_stats pprs = {PPR,PPR,PPR,PPR,PPR,PPR,PPR,0,0,9999}; ++ ++#ifndef MIN ++#define MIN(a,b) (((a)<(b))?(a):(b)) ++#endif ++#ifndef MAX ++#define MAX(a,b) (((a)>(b))?(a):(b)) ++#endif ++ ++#define PDIFFUB(X,Y,T) "movq " #X "," #T "\n\t" \ ++ "psubusb " #Y "," #T "\n\t" \ ++ "psubusb " #X "," #Y "\n\t" \ ++ "paddusb " #Y "," #T "\n\t" ++ ++#define PDIFFUBT(X,Y,T) "movq " #X "," #T "\n\t" \ ++ "psubusb " #Y "," #T "\n\t" \ ++ "psubusb " #X "," #Y "\n\t" \ ++ "paddusb " #T "," #Y "\n\t" ++ ++#define PSUMBW(X,T,Z) "movq " #X "," #T "\n\t" \ ++ "punpcklbw " #Z "," #X "\n\t" \ ++ "punpckhbw " #Z "," #T "\n\t" \ ++ "paddw " #T "," #X "\n\t" \ ++ "movq " #X "," #T "\n\t" \ ++ "psllq $32, " #T "\n\t" \ ++ "paddw " #T "," #X "\n\t" \ ++ "movq " #X "," #T "\n\t" \ ++ "psllq $16, " #T "\n\t" \ ++ "paddw " #T "," #X "\n\t" \ ++ "psrlq $48, " #X "\n\t" ++ ++#define PSADBW(X,Y,T,Z) PDIFFUBT(X,Y,T) PSUMBW(Y,T,Z) ++ ++#define PMAXUB(X,Y) "psubusb " #X "," #Y "\n\tpaddusb " #X "," #Y "\n\t" ++#define PMAXUW(X,Y) "psubusw " #X "," #Y "\n\tpaddusw " #X "," #Y "\n\t" ++#define PMINUBT(X,Y,T) "movq " #Y "," #T "\n\t" \ ++ "psubusb " #X "," #T "\n\t" \ ++ "psubusb " #T "," #Y "\n\t" ++#define PAVGB(X,Y) "pavgusb " #X "," #Y "\n\t" ++ ++static inline void ++get_metrics_c(unsigned char *a, unsigned char *b, int as, int bs, int lines, ++ struct metrics *m) ++{ ++ a -= as; ++ b -= bs; ++ do { ++ cmmx_t old_po = *(cmmx_t*)(a ); ++ cmmx_t po = *(cmmx_t*)(b ); ++ cmmx_t e = *(cmmx_t*)(b + bs); ++ cmmx_t old_o = *(cmmx_t*)(a + 2*as); ++ cmmx_t o = *(cmmx_t*)(b + 2*bs); ++ cmmx_t ne = *(cmmx_t*)(b + 3*bs); ++ cmmx_t old_no = *(cmmx_t*)(a + 4*as); ++ cmmx_t no = *(cmmx_t*)(b + 4*bs); ++ ++ cmmx_t qup_old_odd = p31avgb(old_o, old_po); ++ cmmx_t qup_odd = p31avgb( o, po); ++ cmmx_t qdown_old_odd = p31avgb(old_o, old_no); ++ cmmx_t qdown_odd = p31avgb( o, no); ++ ++ cmmx_t qup_even = p31avgb(ne, e); ++ cmmx_t qdown_even = p31avgb(e, ne); ++ ++ cmmx_t temp_up_diff = pdiffub(qdown_even, qup_old_odd); ++ cmmx_t noise_up_diff = pdiffub(qdown_even, qup_odd); ++ cmmx_t temp_down_diff = pdiffub(qup_even, qdown_old_odd); ++ cmmx_t noise_down_diff = pdiffub(qup_even, qdown_odd); ++ ++ cmmx_t odd_diff = pdiffub(o, old_o); ++ m->odd += psumbw(odd_diff); ++ m->even += psadbw(e, *(cmmx_t*)(a+as)); ++ ++ temp_up_diff = pminub(temp_up_diff, temp_down_diff); ++ temp_up_diff = pminub(temp_up_diff, odd_diff); ++ m->temp += psumbw(temp_up_diff); ++ noise_up_diff = pminub(noise_up_diff, odd_diff); ++ noise_up_diff = pminub(noise_up_diff, noise_down_diff); ++ ++ m->noise += psumbw(noise_up_diff); ++ a += 2*as; ++ b += 2*bs; ++ } while (--lines); ++} ++ ++static inline void ++get_metrics_fast_c(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct metrics *m) ++{ ++ a -= as; ++ b -= bs; ++ do { ++ cmmx_t old_po = (*(cmmx_t*)(a ) >> 1) & ~SIGN_BITS; ++ cmmx_t po = (*(cmmx_t*)(b ) >> 1) & ~SIGN_BITS; ++ cmmx_t old_e = (*(cmmx_t*)(a + as) >> 1) & ~SIGN_BITS; ++ cmmx_t e = (*(cmmx_t*)(b + bs) >> 1) & ~SIGN_BITS; ++ cmmx_t old_o = (*(cmmx_t*)(a + 2*as) >> 1) & ~SIGN_BITS; ++ cmmx_t o = (*(cmmx_t*)(b + 2*bs) >> 1) & ~SIGN_BITS; ++ cmmx_t ne = (*(cmmx_t*)(b + 3*bs) >> 1) & ~SIGN_BITS; ++ cmmx_t old_no = (*(cmmx_t*)(a + 4*as) >> 1) & ~SIGN_BITS; ++ cmmx_t no = (*(cmmx_t*)(b + 4*bs) >> 1) & ~SIGN_BITS; ++ ++ cmmx_t qup_old_odd = p31avgb_s(old_o, old_po); ++ cmmx_t qup_odd = p31avgb_s( o, po); ++ cmmx_t qdown_old_odd = p31avgb_s(old_o, old_no); ++ cmmx_t qdown_odd = p31avgb_s( o, no); ++ ++ cmmx_t qup_even = p31avgb_s(ne, e); ++ cmmx_t qdown_even = p31avgb_s(e, ne); ++ ++ cmmx_t temp_up_diff = pdiffub_s(qdown_even, qup_old_odd); ++ cmmx_t noise_up_diff = pdiffub_s(qdown_even, qup_odd); ++ cmmx_t temp_down_diff = pdiffub_s(qup_even, qdown_old_odd); ++ cmmx_t noise_down_diff = pdiffub_s(qup_even, qdown_odd); ++ ++ cmmx_t odd_diff = pdiffub_s(o, old_o); ++ m->odd += psumbw_s(odd_diff) << 1; ++ m->even += psadbw_s(e, old_e) << 1; ++ ++ temp_up_diff = pminub_s(temp_up_diff, temp_down_diff); ++ temp_up_diff = pminub_s(temp_up_diff, odd_diff); ++ m->temp += psumbw_s(temp_up_diff) << 1; ++ noise_up_diff = pminub_s(noise_up_diff, odd_diff); ++ noise_up_diff = pminub_s(noise_up_diff, noise_down_diff); ++ ++ m->noise += psumbw_s(noise_up_diff) << 1; ++ a += 2*as; ++ b += 2*bs; ++ } while (--lines); ++} ++ ++static inline void ++get_metrics_faster_c(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct metrics *m) ++{ ++ a -= as; ++ b -= bs; ++ do { ++ cmmx_t old_po = (*(cmmx_t*)(a )>>1) & ~SIGN_BITS; ++ cmmx_t po = (*(cmmx_t*)(b )>>1) & ~SIGN_BITS; ++ cmmx_t old_e = (*(cmmx_t*)(a + as)>>1) & ~SIGN_BITS; ++ cmmx_t e = (*(cmmx_t*)(b + bs)>>1) & ~SIGN_BITS; ++ cmmx_t old_o = (*(cmmx_t*)(a + 2*as)>>1) & ~SIGN_BITS; ++ cmmx_t o = (*(cmmx_t*)(b + 2*bs)>>1) & ~SIGN_BITS; ++ cmmx_t ne = (*(cmmx_t*)(b + 3*bs)>>1) & ~SIGN_BITS; ++ ++ cmmx_t down_even = p31avgb_s(e, ne); ++ cmmx_t up_odd = p31avgb_s(o, po); ++ cmmx_t up_old_odd = p31avgb_s(old_o, old_po); ++ ++ cmmx_t odd_diff = pdiffub_s(o, old_o); ++ cmmx_t temp_diff = pdiffub_s(down_even, up_old_odd); ++ cmmx_t noise_diff = pdiffub_s(down_even, up_odd); ++ ++ m->even += psadbw_s(e, old_e) << 1; ++ m->odd += psumbw_s(odd_diff) << 1; ++ ++ temp_diff = pminub_s(temp_diff, odd_diff); ++ noise_diff = pminub_s(noise_diff, odd_diff); ++ ++ m->noise += psumbw_s(noise_diff) << 1; ++ m->temp += psumbw_s(temp_diff) << 1; ++ a += 2*as; ++ b += 2*bs; ++ } while (--lines); ++ ++} ++ ++static inline void ++get_block_stats(struct metrics *m, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ unsigned two_e = m->even + MAX(m->even , p->thres.even ); ++ unsigned two_o = m->odd + MAX(m->odd , p->thres.odd ); ++ unsigned two_n = m->noise + MAX(m->noise, p->thres.noise); ++ unsigned two_t = m->temp + MAX(m->temp , p->thres.temp ); ++ ++ unsigned e_big = m->even >= (m->odd + two_o + 1)/2; ++ unsigned o_big = m->odd >= (m->even + two_e + 1)/2; ++ unsigned n_big = m->noise >= (m->temp + two_t + 1)/2; ++ unsigned t_big = m->temp >= (m->noise + two_n + 1)/2; ++ ++ unsigned e2x = m->even >= two_o; ++ unsigned o2x = m->odd >= two_e; ++ unsigned n2x = m->noise >= two_t; ++ unsigned t2x = m->temp >= two_n; ++ ++ unsigned ntiny_e = m->even > p->thres.even ; ++ unsigned ntiny_o = m->odd > p->thres.odd ; ++ unsigned ntiny_n = m->noise > p->thres.noise; ++ unsigned ntiny_t = m->temp > p->thres.temp ; ++ ++ unsigned nlow_e = m->even > 2*p->thres.even ; ++ unsigned nlow_o = m->odd > 2*p->thres.odd ; ++ unsigned nlow_n = m->noise > 2*p->thres.noise; ++ unsigned nlow_t = m->temp > 2*p->thres.temp ; ++ ++ unsigned high_e = m->even > 4*p->thres.even ; ++ unsigned high_o = m->odd > 4*p->thres.odd ; ++ unsigned high_n = m->noise > 4*p->thres.noise; ++ unsigned high_t = m->temp > 4*p->thres.temp ; ++ ++ unsigned low_il = !n_big && !t_big && ntiny_n && ntiny_t; ++ unsigned high_il = !n_big && !t_big && nlow_n && nlow_t; ++ ++ if (low_il | high_il) { ++ s->interlaced_low += low_il; ++ s->interlaced_high += high_il; ++ } else { ++ s->tiny.even += ntiny_e; ++ s->tiny.odd += ntiny_o; ++ s->tiny.noise += ntiny_n; ++ s->tiny.temp += ntiny_t; ++ ++ s->low .even += nlow_e ; ++ s->low .odd += nlow_o ; ++ s->low .noise += nlow_n ; ++ s->low .temp += nlow_t ; ++ ++ s->high.even += high_e ; ++ s->high.odd += high_o ; ++ s->high.noise += high_n ; ++ s->high.temp += high_t ; ++ ++ if (m->even >= p->sad_thres) s->sad.even += m->even ; ++ if (m->odd >= p->sad_thres) s->sad.odd += m->odd ; ++ if (m->noise >= p->sad_thres) s->sad.noise += m->noise; ++ if (m->temp >= p->sad_thres) s->sad.temp += m->temp ; ++ } ++ s->num_blocks++; ++ s->max.even = MAX(s->max.even , m->even ); ++ s->max.odd = MAX(s->max.odd , m->odd ); ++ s->max.noise = MAX(s->max.noise, m->noise); ++ s->max.temp = MAX(s->max.temp , m->temp ); ++ ++ s->bigger.even += e_big ; ++ s->bigger.odd += o_big ; ++ s->bigger.noise += n_big ; ++ s->bigger.temp += t_big ; ++ ++ s->twox.even += e2x ; ++ s->twox.odd += o2x ; ++ s->twox.noise += n2x ; ++ s->twox.temp += t2x ; ++ ++} ++ ++static inline struct metrics ++block_metrics_c(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct metrics tm; ++ tm.even = tm.odd = tm.noise = tm.temp = 0; ++ get_metrics_c(a, b, as, bs, lines, &tm); ++ if (sizeof(cmmx_t) < 8) ++ get_metrics_c(a+4, b+4, as, bs, lines, &tm); ++ get_block_stats(&tm, p, s); ++ return tm; ++} ++ ++static inline struct metrics ++block_metrics_fast_c(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct metrics tm; ++ tm.even = tm.odd = tm.noise = tm.temp = 0; ++ get_metrics_fast_c(a, b, as, bs, lines, &tm); ++ if (sizeof(cmmx_t) < 8) ++ get_metrics_fast_c(a+4, b+4, as, bs, lines, &tm); ++ get_block_stats(&tm, p, s); ++ return tm; ++} ++ ++static inline struct metrics ++block_metrics_faster_c(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct metrics tm; ++ tm.even = tm.odd = tm.noise = tm.temp = 0; ++ get_metrics_faster_c(a, b, as, bs, lines, &tm); ++ if (sizeof(cmmx_t) < 8) ++ get_metrics_faster_c(a+4, b+4, as, bs, lines, &tm); ++ get_block_stats(&tm, p, s); ++ return tm; ++} ++ ++#define MEQ(X,Y) ((X).even == (Y).even && (X).odd == (Y).odd && (X).temp == (Y).temp && (X).noise == (Y).noise) ++ ++#define BLOCK_METRICS_TEMPLATE() \ ++ __asm__ volatile("pxor %mm7, %mm7\n\t" /* The result is colleted in mm7 */ \ ++ "pxor %mm6, %mm6\n\t" /* Temp to stay at 0 */ \ ++ ); \ ++ a -= as; \ ++ b -= bs; \ ++ do { \ ++ __asm__ volatile( \ ++ "movq (%0,%2), %%mm0\n\t" \ ++ "movq (%1,%3), %%mm1\n\t" /* mm1 = even */ \ ++ PSADBW(%%mm1, %%mm0, %%mm4, %%mm6) \ ++ "paddusw %%mm0, %%mm7\n\t" /* even diff */ \ ++ "movq (%0,%2,2), %%mm0\n\t" /* mm0 = old odd */ \ ++ "movq (%1,%3,2), %%mm2\n\t" /* mm2 = odd */ \ ++ "movq (%0), %%mm3\n\t" \ ++ "psubusb %4, %%mm3\n\t" \ ++ PAVGB(%%mm0, %%mm3) \ ++ PAVGB(%%mm0, %%mm3) /* mm3 = qup old odd */ \ ++ "movq %%mm0, %%mm5\n\t" \ ++ PSADBW(%%mm2, %%mm0, %%mm4, %%mm6) \ ++ "psllq $16, %%mm0\n\t" \ ++ "paddusw %%mm0, %%mm7\n\t" \ ++ "movq (%1), %%mm4\n\t" \ ++ "lea (%0,%2,2), %0\n\t" \ ++ "lea (%1,%3,2), %1\n\t" \ ++ "psubusb %4, %%mm4\n\t" \ ++ PAVGB(%%mm2, %%mm4) \ ++ PAVGB(%%mm2, %%mm4) /* mm4 = qup odd */ \ ++ PDIFFUBT(%%mm5, %%mm2, %%mm0) /* mm2 =abs(oldodd-odd) */ \ ++ "movq (%1,%3), %%mm5\n\t" \ ++ "psubusb %4, %%mm5\n\t" \ ++ PAVGB(%%mm1, %%mm5) \ ++ PAVGB(%%mm5, %%mm1) /* mm1 = qdown even */ \ ++ PAVGB((%1,%3), %%mm5) /* mm5 = qup next even */ \ ++ PDIFFUBT(%%mm1, %%mm3, %%mm0) /* mm3 = abs(qupoldo-qde) */ \ ++ PDIFFUBT(%%mm1, %%mm4, %%mm0) /* mm4 = abs(qupodd-qde) */ \ ++ PMINUBT(%%mm2, %%mm3, %%mm0) /* limit temp to odd diff */ \ ++ PMINUBT(%%mm2, %%mm4, %%mm0) /* limit noise to odd diff */ \ ++ "movq (%1,%3,2), %%mm2\n\t" \ ++ "psubusb %4, %%mm2\n\t" \ ++ PAVGB((%1), %%mm2) \ ++ PAVGB((%1), %%mm2) /* mm2 = qdown odd */ \ ++ "movq (%0,%2,2), %%mm1\n\t" \ ++ "psubusb %4, %%mm1\n\t" \ ++ PAVGB((%0), %%mm1) \ ++ PAVGB((%0), %%mm1) /* mm1 = qdown old odd */ \ ++ PDIFFUBT(%%mm5, %%mm2, %%mm0) /* mm2 = abs(qdo-qune) */ \ ++ PDIFFUBT(%%mm5, %%mm1, %%mm0) /* mm1 = abs(qdoo-qune) */ \ ++ PMINUBT(%%mm4, %%mm2, %%mm0) /* current */ \ ++ PMINUBT(%%mm3, %%mm1, %%mm0) /* old */ \ ++ PSUMBW(%%mm2, %%mm0, %%mm6) \ ++ PSUMBW(%%mm1, %%mm0, %%mm6) \ ++ "psllq $32, %%mm2\n\t" \ ++ "psllq $48, %%mm1\n\t" \ ++ "paddusw %%mm2, %%mm7\n\t" \ ++ "paddusw %%mm1, %%mm7\n\t" \ ++ : "=r" (a), "=r" (b) \ ++ : "r"((x86_reg)as), "r"((x86_reg)bs), "m" (ones), "0"(a), "1"(b), "X"(*a), "X"(*b) \ ++ ); \ ++ } while (--lines); ++ ++static inline struct metrics ++block_metrics_3dnow(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct metrics tm; ++#if !HAVE_AMD3DNOW ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "block_metrics_3dnow: internal error\n"); ++#else ++ static const unsigned long long ones = 0x0101010101010101ull; ++ ++ BLOCK_METRICS_TEMPLATE(); ++ __asm__ volatile("movq %%mm7, %0\n\temms" : "=m" (tm)); ++ get_block_stats(&tm, p, s); ++#endif ++ return tm; ++} ++ ++#undef PSUMBW ++#undef PSADBW ++#undef PMAXUB ++#undef PMINUBT ++#undef PAVGB ++ ++#define PSUMBW(X,T,Z) "psadbw " #Z "," #X "\n\t" ++#define PSADBW(X,Y,T,Z) "psadbw " #X "," #Y "\n\t" ++#define PMAXUB(X,Y) "pmaxub " #X "," #Y "\n\t" ++#define PMINUBT(X,Y,T) "pminub " #X "," #Y "\n\t" ++#define PAVGB(X,Y) "pavgb " #X "," #Y "\n\t" ++ ++static inline struct metrics ++block_metrics_mmx2(unsigned char *a, unsigned char *b, int as, int bs, ++ int lines, struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct metrics tm; ++#if !HAVE_MMX ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "block_metrics_mmx2: internal error\n"); ++#else ++ static const unsigned long long ones = 0x0101010101010101ull; ++ x86_reg interlaced; ++ x86_reg prefetch_line = (((long)a>>3) & 7) + 10; ++#ifdef DEBUG ++ struct frame_stats ts = *s; ++#endif ++ __asm__ volatile("prefetcht0 (%0,%2)\n\t" ++ "prefetcht0 (%1,%3)\n\t" : ++ : "r" (a), "r" (b), ++ "r" (prefetch_line * as), "r" (prefetch_line * bs)); ++ ++ BLOCK_METRICS_TEMPLATE(); ++ ++ s->num_blocks++; ++ __asm__ volatile( ++ "movq %3, %%mm0\n\t" ++ "movq %%mm7, %%mm1\n\t" ++ "psubusw %%mm0, %%mm1\n\t" ++ "movq %%mm1, %%mm2\n\t" ++ "paddusw %%mm0, %%mm2\n\t" ++ "paddusw %%mm7, %%mm2\n\t" ++ "pshufw $0xb1, %%mm2, %%mm3\n\t" ++ "pavgw %%mm7, %%mm2\n\t" ++ "pshufw $0xb1, %%mm2, %%mm2\n\t" ++ "psubusw %%mm7, %%mm2\n\t" ++ "pcmpeqw %%mm6, %%mm2\n\t" /* 1 if >= 1.5x */ ++ "psubusw %%mm7, %%mm3\n\t" ++ "pcmpeqw %%mm6, %%mm3\n\t" /* 1 if >= 2x */ ++ "movq %1, %%mm4\n\t" ++ "movq %2, %%mm5\n\t" ++ "psubw %%mm2, %%mm4\n\t" ++ "psubw %%mm3, %%mm5\n\t" ++ "movq %%mm4, %1\n\t" ++ "movq %%mm5, %2\n\t" ++ "pxor %%mm4, %%mm4\n\t" ++ "pcmpeqw %%mm1, %%mm4\n\t" /* 1 if <= t */ ++ "psubusw %%mm0, %%mm1\n\t" ++ "pxor %%mm5, %%mm5\n\t" ++ "pcmpeqw %%mm1, %%mm5\n\t" /* 1 if <= 2t */ ++ "psubusw %%mm0, %%mm1\n\t" ++ "psubusw %%mm0, %%mm1\n\t" ++ "pcmpeqw %%mm6, %%mm1\n\t" /* 1 if <= 4t */ ++ "pshufw $0xb1, %%mm2, %%mm0\n\t" ++ "por %%mm2, %%mm0\n\t" /* 1 if not close */ ++ "punpckhdq %%mm0, %%mm0\n\t" ++ "movq %%mm4, %%mm2\n\t" /* tttt */ ++ "punpckhdq %%mm5, %%mm2\n\t" /* ttll */ ++ "por %%mm2, %%mm0\n\t" ++ "pcmpeqd %%mm6, %%mm0\n\t" /* close && big */ ++ "psrlq $16, %%mm0\n\t" ++ "psrlw $15, %%mm0\n\t" ++ "movd %%mm0, %0\n\t" ++ : "=r" (interlaced), "=m" (s->bigger), "=m" (s->twox) ++ : "m" (p->thres) ++ ); ++ ++ if (interlaced) { ++ s->interlaced_high += interlaced >> 16; ++ s->interlaced_low += interlaced; ++ } else { ++ __asm__ volatile( ++ "pcmpeqw %%mm0, %%mm0\n\t" /* -1 */ ++ "psubw %%mm0, %%mm4\n\t" ++ "psubw %%mm0, %%mm5\n\t" ++ "psubw %%mm0, %%mm1\n\t" ++ "paddw %0, %%mm4\n\t" ++ "paddw %1, %%mm5\n\t" ++ "paddw %2, %%mm1\n\t" ++ "movq %%mm4, %0\n\t" ++ "movq %%mm5, %1\n\t" ++ "movq %%mm1, %2\n\t" ++ : "=m" (s->tiny), "=m" (s->low), "=m" (s->high) ++ ); ++ ++ __asm__ volatile( ++ "pshufw $0, %2, %%mm0\n\t" ++ "psubusw %%mm7, %%mm0\n\t" ++ "pcmpeqw %%mm6, %%mm0\n\t" /* 0 if below sad_thres */ ++ "pand %%mm7, %%mm0\n\t" ++ "movq %%mm0, %%mm1\n\t" ++ "punpcklwd %%mm6, %%mm0\n\t" /* sad even, odd */ ++ "punpckhwd %%mm6, %%mm1\n\t" /* sad noise, temp */ ++ "paddd %0, %%mm0\n\t" ++ "paddd %1, %%mm1\n\t" ++ "movq %%mm0, %0\n\t" ++ "movq %%mm1, %1\n\t" ++ : "=m" (s->sad.even), "=m" (s->sad.noise) ++ : "m" (p->sad_thres) ++ ); ++ } ++ ++ __asm__ volatile( ++ "movq %%mm7, (%1)\n\t" ++ PMAXUW((%0), %%mm7) ++ "movq %%mm7, (%0)\n\t" ++ "emms" ++ : : "r" (&s->max), "r" (&tm), "X" (s->max) ++ : "memory" ++ ); ++#ifdef DEBUG ++ if (1) { ++ struct metrics cm; ++ a -= 7*as; ++ b -= 7*bs; ++ cm = block_metrics_c(a, b, as, bs, 4, p, &ts); ++ if (!MEQ(tm, cm)) ++ mp_msg(MSGT_VFILTER, MSGL_WARN, "Bad metrics\n"); ++ if (s) { ++# define CHECK(X) if (!MEQ(s->X, ts.X)) \ ++ mp_msg(MSGT_VFILTER, MSGL_WARN, "Bad " #X "\n"); ++ CHECK(tiny); ++ CHECK(low); ++ CHECK(high); ++ CHECK(sad); ++ CHECK(max); ++ } ++ } ++#endif ++#endif ++ return tm; ++} ++ ++static inline int ++dint_copy_line_mmx2(unsigned char *dst, unsigned char *a, long bos, ++ long cos, int ds, int ss, int w, int t) ++{ ++#if !HAVE_MMX ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "dint_copy_line_mmx2: internal error\n"); ++ return 0; ++#else ++ unsigned long len = (w+7) >> 3; ++ int ret; ++ __asm__ volatile ( ++ "pxor %%mm6, %%mm6 \n\t" /* deinterlaced pixel counter */ ++ "movd %0, %%mm7 \n\t" ++ "punpcklbw %%mm7, %%mm7 \n\t" ++ "punpcklwd %%mm7, %%mm7 \n\t" ++ "punpckldq %%mm7, %%mm7 \n\t" /* mm7 = threshold */ ++ : /* no output */ ++ : "rm" (t) ++ ); ++ do { ++ __asm__ volatile ( ++ "movq (%0), %%mm0\n\t" ++ "movq (%0,%3,2), %%mm1\n\t" ++ "movq %%mm0, (%2)\n\t" ++ "pmaxub %%mm1, %%mm0\n\t" ++ "pavgb (%0), %%mm1\n\t" ++ "psubusb %%mm1, %%mm0\n\t" ++ "paddusb %%mm7, %%mm0\n\t" /* mm0 = max-avg+thr */ ++ "movq (%0,%1), %%mm2\n\t" ++ "movq (%0,%5), %%mm3\n\t" ++ "movq %%mm2, %%mm4\n\t" ++ PDIFFUBT(%%mm1, %%mm2, %%mm5) ++ PDIFFUBT(%%mm1, %%mm3, %%mm5) ++ "pminub %%mm2, %%mm3\n\t" ++ "pcmpeqb %%mm3, %%mm2\n\t" /* b = min */ ++ "pand %%mm2, %%mm4\n\t" ++ "pandn (%0,%5), %%mm2\n\t" ++ "por %%mm4, %%mm2\n\t" ++ "pminub %%mm0, %%mm3\n\t" ++ "pcmpeqb %%mm0, %%mm3\n\t" /* set to 1s if >= threshold */ ++ "psubb %%mm3, %%mm6\n\t" /* count pixels above thr. */ ++ "pand %%mm3, %%mm1 \n\t" ++ "pandn %%mm2, %%mm3 \n\t" ++ "por %%mm3, %%mm1 \n\t" /* avg if >= threshold */ ++ "movq %%mm1, (%2,%4) \n\t" ++ : /* no output */ ++ : "r" (a), "r" ((x86_reg)bos), "r" ((x86_reg)dst), "r" ((x86_reg)ss), "r" ((x86_reg)ds), "r" ((x86_reg)cos) ++ ); ++ a += 8; ++ dst += 8; ++ } while (--len); ++ ++ __asm__ volatile ("pxor %%mm7, %%mm7 \n\t" ++ "psadbw %%mm6, %%mm7 \n\t" ++ "movd %%mm7, %0 \n\t" ++ "emms \n\t" ++ : "=r" (ret) ++ ); ++ return ret; ++#endif ++} ++ ++static inline int ++dint_copy_line(unsigned char *dst, unsigned char *a, long bos, ++ long cos, int ds, int ss, int w, int t) ++{ ++ unsigned long len = ((unsigned long)w+sizeof(cmmx_t)-1) / sizeof(cmmx_t); ++ cmmx_t dint_count = 0; ++ cmmx_t thr; ++ t |= t << 8; ++ thr = t | (t << 16); ++ if (sizeof(cmmx_t) > 4) ++ thr |= thr << (sizeof(cmmx_t)*4); ++ do { ++ cmmx_t e = *(cmmx_t*)a; ++ cmmx_t ne = *(cmmx_t*)(a+2*ss); ++ cmmx_t o = *(cmmx_t*)(a+bos); ++ cmmx_t oo = *(cmmx_t*)(a+cos); ++ cmmx_t maxe = pmaxub(e, ne); ++ cmmx_t avge = pavgb(e, ne); ++ cmmx_t max_diff = maxe - avge + thr; /* 0<=max-avg<128, thr<128 */ ++ cmmx_t diffo = pdiffub(avge, o); ++ cmmx_t diffoo = pdiffub(avge, oo); ++ cmmx_t diffcmp = pcmpgtub(diffo, diffoo); ++ cmmx_t bo = ((oo ^ o) & diffcmp) ^ o; ++ cmmx_t diffbo = ((diffoo ^ diffo) & diffcmp) ^ diffo; ++ cmmx_t above_thr = ~pcmpgtub(max_diff, diffbo); ++ cmmx_t bo_or_avg = ((avge ^ bo) & above_thr) ^ bo; ++ dint_count += above_thr & ONE_BYTES; ++ *(cmmx_t*)(dst) = e; ++ *(cmmx_t*)(dst+ds) = bo_or_avg; ++ a += sizeof(cmmx_t); ++ dst += sizeof(cmmx_t); ++ } while (--len); ++ return psumbw(dint_count); ++} ++ ++static int ++dint_copy_plane(unsigned char *d, unsigned char *a, unsigned char *b, ++ unsigned char *c, unsigned long w, unsigned long h, ++ unsigned long ds, unsigned long ss, unsigned long threshold, ++ long field, long mmx2) ++{ ++ unsigned long ret = 0; ++ long bos = b - a; ++ long cos = c - a; ++ if (field) { ++ fast_memcpy(d, b, w); ++ h--; ++ d += ds; ++ a += ss; ++ } ++ bos += ss; ++ cos += ss; ++ while (h > 2) { ++ if (threshold >= 128) { ++ fast_memcpy(d, a, w); ++ fast_memcpy(d+ds, a+bos, w); ++ } else if (mmx2 == 1) { ++ ret += dint_copy_line_mmx2(d, a, bos, cos, ds, ss, w, threshold); ++ } else ++ ret += dint_copy_line(d, a, bos, cos, ds, ss, w, threshold); ++ h -= 2; ++ d += 2*ds; ++ a += 2*ss; ++ } ++ fast_memcpy(d, a, w); ++ if (h == 2) ++ fast_memcpy(d+ds, a+bos, w); ++ return ret; ++} ++ ++static void ++copy_merge_fields(struct vf_priv_s *p, mp_image_t *dmpi, ++ unsigned char **old, unsigned char **new, unsigned long show) ++{ ++ unsigned long threshold = 256; ++ unsigned long field = p->swapped; ++ unsigned long dint_pixels = 0; ++ unsigned char **other = old; ++ if (show >= 12 || !(show & 3)) ++ show >>= 2, other = new, new = old; ++ if (show <= 2) { /* Single field: de-interlace */ ++ threshold = p->dint_thres; ++ field ^= show & 1; ++ old = new; ++ } else if (show == 3) ++ old = new; ++ else ++ field ^= 1; ++ dint_pixels +=dint_copy_plane(dmpi->planes[0], old[0], new[0], ++ other[0], p->w, p->h, dmpi->stride[0], ++ p->stride, threshold, field, p->mmx2); ++ if (dmpi->flags & MP_IMGFLAG_PLANAR) { ++ if (p->luma_only) ++ old = new, other = new; ++ else ++ threshold = threshold/2 + 1; ++ field ^= p->chroma_swapped; ++ dint_copy_plane(dmpi->planes[1], old[1], new[1], ++ other[1], p->cw, p->ch, dmpi->stride[1], ++ p->chroma_stride, threshold, field, p->mmx2); ++ dint_copy_plane(dmpi->planes[2], old[2], new[2], ++ other[2], p->cw, p->ch, dmpi->stride[2], ++ p->chroma_stride, threshold, field, p->mmx2); ++ } ++ if (dint_pixels > 0 && p->verbose) ++ mp_msg(MSGT_VFILTER,MSGL_INFO,"Deinterlaced %lu pixels\n",dint_pixels); ++} ++ ++static void diff_planes(struct vf_priv_s *p, struct frame_stats *s, ++ unsigned char *of, unsigned char *nf, ++ int w, int h, int os, int ns, int swapped) ++{ ++ int i, y; ++ int align = -(long)nf & 7; ++ of += align; ++ nf += align; ++ w -= align; ++ if (swapped) ++ of -= os, nf -= ns; ++ i = (h*3 >> 7) & ~1; ++ of += i*os + 8; ++ nf += i*ns + 8; ++ h -= i; ++ w -= 16; ++ ++ memset(s, 0, sizeof(*s)); ++ ++ for (y = (h-8) >> 3; y; y--) { ++ if (p->mmx2 == 1) { ++ for (i = 0; i < w; i += 8) ++ block_metrics_mmx2(of+i, nf+i, os, ns, 4, p, s); ++ } else if (p->mmx2 == 2) { ++ for (i = 0; i < w; i += 8) ++ block_metrics_3dnow(of+i, nf+i, os, ns, 4, p, s); ++ } else if (p->fast > 3) { ++ for (i = 0; i < w; i += 8) ++ block_metrics_faster_c(of+i, nf+i, os, ns, 4, p, s); ++ } else if (p->fast > 1) { ++ for (i = 0; i < w; i += 8) ++ block_metrics_fast_c(of+i, nf+i, os, ns, 4, p, s); ++ } else { ++ for (i = 0; i < w; i += 8) ++ block_metrics_c(of+i, nf+i, os, ns, 4, p, s); ++ } ++ of += 8*os; ++ nf += 8*ns; ++ } ++} ++ ++#define METRICS(X) (X).even, (X).odd, (X).noise, (X).temp ++ ++static void diff_fields(struct vf_priv_s *p, struct frame_stats *s, ++ unsigned char **old, unsigned char **new) ++{ ++ diff_planes(p, s, old[0], new[0], p->w, p->h, ++ p->stride, p->stride, p->swapped); ++ s->sad.even = (s->sad.even * 16ul) / s->num_blocks; ++ s->sad.odd = (s->sad.odd * 16ul) / s->num_blocks; ++ s->sad.noise = (s->sad.noise * 16ul) / s->num_blocks; ++ s->sad.temp = (s->sad.temp * 16ul) / s->num_blocks; ++ if (p->verbose) ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "%lu%c M:%d/%d/%d/%d - %d, " ++ "t:%d/%d/%d/%d, l:%d/%d/%d/%d, h:%d/%d/%d/%d, bg:%d/%d/%d/%d, " ++ "2x:%d/%d/%d/%d, sad:%d/%d/%d/%d, lil:%d, hil:%d, ios:%.1f\n", ++ p->inframes, p->chflag, METRICS(s->max), s->num_blocks, ++ METRICS(s->tiny), METRICS(s->low), METRICS(s->high), ++ METRICS(s->bigger), METRICS(s->twox), METRICS(s->sad), ++ s->interlaced_low, s->interlaced_high, ++ p->iosync / (double) p->in_inc); ++} ++ ++static const char *parse_args(struct vf_priv_s *p, const char *args) ++{ ++ args--; ++ while (args && *++args && ++ (sscanf(args, "io=%lu:%lu", &p->out_dec, &p->in_inc) == 2 || ++ sscanf(args, "diff_thres=%hu", &p->thres.even ) == 1 || ++ sscanf(args, "comb_thres=%hu", &p->thres.noise) == 1 || ++ sscanf(args, "sad_thres=%lu", &p->sad_thres ) == 1 || ++ sscanf(args, "dint_thres=%lu", &p->dint_thres ) == 1 || ++ sscanf(args, "fast=%u", &p->fast ) == 1 || ++ sscanf(args, "mmx2=%lu", &p->mmx2 ) == 1 || ++ sscanf(args, "luma_only=%u", &p->luma_only ) == 1 || ++ sscanf(args, "verbose=%u", &p->verbose ) == 1 || ++ sscanf(args, "crop=%lu:%lu:%lu:%lu", &p->w, ++ &p->h, &p->crop_x, &p->crop_y) == 4)) ++ args = strchr(args, '/'); ++ return args; ++} ++ ++static unsigned long gcd(unsigned long x, unsigned long y) ++{ ++ unsigned long t; ++ if (x > y) ++ t = x, x = y, y = t; ++ ++ while (x) { ++ t = y % x; ++ y = x; ++ x = t; ++ } ++ return y; ++} ++ ++static void init(struct vf_priv_s *p, mp_image_t *mpi) ++{ ++ unsigned long i; ++ unsigned long plane_size, chroma_plane_size; ++ unsigned char *plane; ++ unsigned long cos, los; ++ p->crop_cx = p->crop_x >> mpi->chroma_x_shift; ++ p->crop_cy = p->crop_y >> mpi->chroma_y_shift; ++ if (mpi->flags & MP_IMGFLAG_ACCEPT_STRIDE) { ++ p->stride = (mpi->w + 15) & ~15; ++ p->chroma_stride = p->stride >> mpi->chroma_x_shift; ++ } else { ++ p->stride = mpi->width; ++ p->chroma_stride = mpi->chroma_width; ++ } ++ p->cw = p->w >> mpi->chroma_x_shift; ++ p->ch = p->h >> mpi->chroma_y_shift; ++ p->nplanes = 1; ++ p->static_idx = 0; ++ p->temp_idx = 0; ++ p->old_planes = p->planes[0]; ++ plane_size = mpi->h * p->stride; ++ chroma_plane_size = mpi->flags & MP_IMGFLAG_PLANAR ? ++ mpi->chroma_height * p->chroma_stride : 0; ++ p->memory_allocated = ++ malloc(NUM_STORED * (plane_size+2*chroma_plane_size) + ++ 8*p->chroma_stride + 4096); ++ /* align to page boundary */ ++ plane = p->memory_allocated + (-(long)p->memory_allocated & 4095); ++ memset(plane, 0, NUM_STORED * plane_size); ++ los = p->crop_x + p->crop_y * p->stride; ++ cos = p->crop_cx + p->crop_cy * p->chroma_stride; ++ for (i = 0; i != NUM_STORED; i++, plane += plane_size) { ++ p->planes[i][0] = plane; ++ p->planes[NUM_STORED + i][0] = plane + los; ++ } ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ p->nplanes = 3; ++ memset(plane, 0x80, NUM_STORED * 2 * chroma_plane_size); ++ for (i = 0; i != NUM_STORED; i++) { ++ p->planes[i][1] = plane; ++ p->planes[NUM_STORED + i][1] = plane + cos; ++ plane += chroma_plane_size; ++ p->planes[i][2] = plane; ++ p->planes[NUM_STORED + i][2] = plane + cos; ++ plane += chroma_plane_size; ++ } ++ } ++ p->out_dec <<= 2; ++ i = gcd(p->in_inc, p->out_dec); ++ p->in_inc /= i; ++ p->out_dec /= i; ++ p->iosync = 0; ++ p->num_fields = 3; ++} ++ ++static inline double get_time(void) ++{ ++ struct timeval tv; ++ gettimeofday(&tv, 0); ++ return tv.tv_sec + tv.tv_usec * 1e-6; ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ struct vf_priv_s *p = vf->priv; ++ static unsigned char **planes, planes_idx; ++ ++ if (mpi->type == MP_IMGTYPE_STATIC) return; ++ ++ if (!p->planes[0][0]) init(p, mpi); ++ ++ if (mpi->type == MP_IMGTYPE_TEMP || ++ (mpi->type == MP_IMGTYPE_IPB && !(mpi->flags & MP_IMGFLAG_READABLE))) ++ planes_idx = NUM_STORED/2 + (++p->temp_idx % (NUM_STORED/2)); ++ else ++ planes_idx = ++p->static_idx % (NUM_STORED/2); ++ planes = p->planes[planes_idx]; ++ mpi->priv = p->planes[NUM_STORED + planes_idx]; ++ if (mpi->priv == p->old_planes) { ++ unsigned char **old_planes = ++ p->planes[NUM_STORED + 2 + (++p->temp_idx & 1)]; ++ my_memcpy_pic(old_planes[0], p->old_planes[0], ++ p->w, p->h, p->stride, p->stride); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(old_planes[1], p->old_planes[1], ++ p->cw, p->ch, p->chroma_stride, p->chroma_stride); ++ my_memcpy_pic(old_planes[2], p->old_planes[2], ++ p->cw, p->ch, p->chroma_stride, p->chroma_stride); ++ } ++ p->old_planes = old_planes; ++ p->num_copies++; ++ } ++ mpi->planes[0] = planes[0]; ++ mpi->stride[0] = p->stride; ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ mpi->planes[1] = planes[1]; ++ mpi->planes[2] = planes[2]; ++ mpi->stride[1] = mpi->stride[2] = p->chroma_stride; ++ } ++ mpi->width = p->stride; ++ ++ mpi->flags |= MP_IMGFLAG_DIRECT; ++ mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; ++} ++ ++static inline long ++cmpe(unsigned long x, unsigned long y, unsigned long err, unsigned long e) ++{ ++ long diff = x-y; ++ long unit = ((x+y+err) >> e); ++ long ret = (diff > unit) - (diff < -unit); ++ unit >>= 1; ++ return ret + (diff > unit) - (diff < -unit); ++} ++ ++static unsigned long ++find_breaks(struct vf_priv_s *p, struct frame_stats *s) ++{ ++ struct frame_stats *ps = &p->stats[(p->inframes-1) & 1]; ++ long notfilm = 5*p->in_inc - p->out_dec; ++ unsigned long n = s->num_blocks >> 8; ++ unsigned long sad_comb_cmp = cmpe(s->sad.temp, s->sad.noise, 512, 1); ++ unsigned long ret = 8; ++ ++ if (cmpe(s->sad.temp, s->sad.even, 512, 1) > 0) ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "@@@@@@@@ Bottom-first field??? @@@@@@@@\n"); ++ if (s->sad.temp > 1000 && s->sad.noise > 1000) ++ return 3; ++ if (s->interlaced_high >= 2*n && s->sad.temp > 256 && s->sad.noise > 256) ++ return 3; ++ if (s->high.noise > s->num_blocks/4 && s->sad.noise > 10000 && ++ s->sad.noise > 2*s->sad.even && s->sad.noise > 2*ps->sad.odd) { ++ // Mid-frame scene change ++ if (s->tiny.temp + s->interlaced_low < n || ++ s->low.temp + s->interlaced_high < n/4 || ++ s->high.temp + s->interlaced_high < n/8 || ++ s->sad.temp < 160) ++ return 1; ++ return 3; ++ } ++ if (s->high.temp > s->num_blocks/4 && s->sad.temp > 10000 && ++ s->sad.temp > 2*ps->sad.odd && s->sad.temp > 2*ps->sad.even) { ++ // Start frame scene change ++ if (s->tiny.noise + s->interlaced_low < n || ++ s->low.noise + s->interlaced_high < n/4 || ++ s->high.noise + s->interlaced_high < n/8 || ++ s->sad.noise < 160) ++ return 2; ++ return 3; ++ } ++ if (sad_comb_cmp == 2) ++ return 2; ++ if (sad_comb_cmp == -2) ++ return 1; ++ ++ if (s->tiny.odd > 3*MAX(n,s->tiny.even) + s->interlaced_low) ++ return 1; ++ if (s->tiny.even > 3*MAX(n,s->tiny.odd)+s->interlaced_low && ++ (!sad_comb_cmp || (s->low.noise <= n/4 && s->low.temp <= n/4))) ++ return 4; ++ ++ if (s->sad.noise < 64 && s->sad.temp < 64 && ++ s->low.noise <= n/2 && s->high.noise <= n/4 && ++ s->low.temp <= n/2 && s->high.temp <= n/4) ++ goto still; ++ ++ if (s->tiny.temp > 3*MAX(n,s->tiny.noise) + s->interlaced_low) ++ return 2; ++ if (s->tiny.noise > 3*MAX(n,s->tiny.temp) + s->interlaced_low) ++ return 1; ++ ++ if (s->low.odd > 3*MAX(n/4,s->low.even) + s->interlaced_high) ++ return 1; ++ if (s->low.even > 3*MAX(n/4,s->low.odd)+s->interlaced_high && ++ s->sad.even > 2*s->sad.odd && ++ (!sad_comb_cmp || (s->low.noise <= n/4 && s->low.temp <= n/4))) ++ return 4; ++ ++ if (s->low.temp > 3*MAX(n/4,s->low.noise) + s->interlaced_high) ++ return 2; ++ if (s->low.noise > 3*MAX(n/4,s->low.temp) + s->interlaced_high) ++ return 1; ++ ++ if (sad_comb_cmp == 1 && s->sad.noise < 64) ++ return 2; ++ if (sad_comb_cmp == -1 && s->sad.temp < 64) ++ return 1; ++ ++ if (s->tiny.odd <= n || (s->tiny.noise <= n/2 && s->tiny.temp <= n/2)) { ++ if (s->interlaced_low <= n) { ++ if (p->num_fields == 1) ++ goto still; ++ if (s->tiny.even <= n || ps->tiny.noise <= n/2) ++ /* Still frame */ ++ goto still; ++ if (s->bigger.even >= 2*MAX(n,s->bigger.odd) + s->interlaced_low) ++ return 4; ++ if (s->low.even >= 2*n + s->interlaced_low) ++ return 4; ++ goto still; ++ } ++ } ++ if (s->low.odd <= n/4) { ++ if (s->interlaced_high <= n/4) { ++ if (p->num_fields == 1) ++ goto still; ++ if (s->low.even <= n/4) ++ /* Still frame */ ++ goto still; ++ if (s->bigger.even >= 2*MAX(n/4,s->bigger.odd)+s->interlaced_high) ++ return 4; ++ if (s->low.even >= n/2 + s->interlaced_high) ++ return 4; ++ goto still; ++ } ++ } ++ if (s->bigger.temp > 2*MAX(n,s->bigger.noise) + s->interlaced_low) ++ return 2; ++ if (s->bigger.noise > 2*MAX(n,s->bigger.temp) + s->interlaced_low) ++ return 1; ++ if (s->bigger.temp > 2*MAX(n,s->bigger.noise) + s->interlaced_high) ++ return 2; ++ if (s->bigger.noise > 2*MAX(n,s->bigger.temp) + s->interlaced_high) ++ return 1; ++ if (s->twox.temp > 2*MAX(n,s->twox.noise) + s->interlaced_high) ++ return 2; ++ if (s->twox.noise > 2*MAX(n,s->twox.temp) + s->interlaced_high) ++ return 1; ++ if (s->bigger.even > 2*MAX(n,s->bigger.odd) + s->interlaced_low && ++ s->bigger.temp < n && s->bigger.noise < n) ++ return 4; ++ if (s->interlaced_low > MIN(2*n, s->tiny.odd)) ++ return 3; ++ ret = 8 + (1 << (s->sad.temp > s->sad.noise)); ++ still: ++ if (p->num_fields == 1 && p->prev_fields == 3 && notfilm >= 0 && ++ (s->tiny.temp <= s->tiny.noise || s->sad.temp < s->sad.noise+16)) ++ return 1; ++ if (p->notout < p->num_fields && p->iosync > 2*p->in_inc && notfilm < 0) ++ notfilm = 0; ++ if (p->num_fields < 2 || ++ (p->num_fields == 2 && p->prev_fields == 2 && notfilm < 0)) ++ return ret; ++ if (!notfilm && (p->prev_fields&~1) == 2) { ++ if (p->prev_fields + p->num_fields == 5) { ++ if (s->tiny.noise <= s->tiny.temp || ++ s->low.noise == 0 || s->low.noise < s->low.temp || ++ s->sad.noise < s->sad.temp+16) ++ return 2; ++ } ++ if (p->prev_fields + p->num_fields == 4) { ++ if (s->tiny.temp <= s->tiny.noise || ++ s->low.temp == 0 || s->low.temp < s->low.noise || ++ s->sad.temp < s->sad.noise+16) ++ return 1; ++ } ++ } ++ if (p->num_fields > 2 && ++ ps->sad.noise > s->sad.noise && ps->sad.noise > s->sad.temp) ++ return 4; ++ return 2 >> (s->sad.noise > s->sad.temp); ++} ++ ++#define ITOC(X) (!(X) ? ' ' : (X) + ((X)>9 ? 'a'-10 : '0')) ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ struct vf_priv_s *p = vf->priv; ++ unsigned char **planes, **old_planes; ++ struct frame_stats *s = &p->stats[p->inframes & 1]; ++ struct frame_stats *ps = &p->stats[(p->inframes-1) & 1]; ++ int swapped = 0; ++ const int flags = mpi->fields; ++ int breaks, prev; ++ int show_fields = 0; ++ int dropped_fields = 0; ++ double start_time, diff_time; ++ char prev_chflag = p->chflag; ++ int keep_rate; ++ ++ if (!p->planes[0][0]) init(p, mpi); ++ ++ old_planes = p->old_planes; ++ ++ if ((mpi->flags & MP_IMGFLAG_DIRECT) && mpi->priv) { ++ planes = mpi->priv; ++ mpi->priv = 0; ++ } else { ++ planes = p->planes[2 + (++p->temp_idx & 1)]; ++ my_memcpy_pic(planes[0], ++ mpi->planes[0] + p->crop_x + p->crop_y * mpi->stride[0], ++ p->w, p->h, p->stride, mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(planes[1], ++ mpi->planes[1] + p->crop_cx + p->crop_cy * mpi->stride[1], ++ p->cw, p->ch, p->chroma_stride, mpi->stride[1]); ++ my_memcpy_pic(planes[2], ++ mpi->planes[2] + p->crop_cx + p->crop_cy * mpi->stride[2], ++ p->cw, p->ch, p->chroma_stride, mpi->stride[2]); ++ p->num_copies++; ++ } ++ } ++ ++ p->old_planes = planes; ++ p->chflag = ';'; ++ if (flags & MP_IMGFIELD_ORDERED) { ++ swapped = !(flags & MP_IMGFIELD_TOP_FIRST); ++ p->chflag = (flags & MP_IMGFIELD_REPEAT_FIRST ? '|' : ++ flags & MP_IMGFIELD_TOP_FIRST ? ':' : '.'); ++ } ++ p->swapped = swapped; ++ ++ start_time = get_time(); ++ if (p->chflag == '|') { ++ *s = ppzs; ++ p->iosync += p->in_inc; ++ } else if ((p->fast & 1) && prev_chflag == '|') ++ *s = pprs; ++ else ++ diff_fields(p, s, old_planes, planes); ++ diff_time = get_time(); ++ p->diff_time += diff_time - start_time; ++ breaks = p->inframes ? find_breaks(p, s) : 2; ++ p->inframes++; ++ keep_rate = 4*p->in_inc == p->out_dec; ++ ++ switch (breaks) { ++ case 0: ++ case 8: ++ case 9: ++ case 10: ++ if (!keep_rate && p->notout < p->num_fields && p->iosync < 2*p->in_inc) ++ break; ++ if (p->notout < p->num_fields) ++ dropped_fields = -2; ++ case 4: ++ if (keep_rate || p->iosync >= -2*p->in_inc) ++ show_fields = (4<num_fields)-1; ++ break; ++ case 3: ++ if (keep_rate) ++ show_fields = 2; ++ else if (p->iosync > 0) { ++ if (p->notout >= p->num_fields && p->iosync > 2*p->in_inc) { ++ show_fields = 4; /* prev odd only */ ++ if (p->num_fields > 1) ++ show_fields |= 8; /* + prev even */ ++ } else { ++ show_fields = 2; /* even only */ ++ if (p->notout >= p->num_fields) ++ dropped_fields += p->num_fields; ++ } ++ } ++ break; ++ case 2: ++ if (p->iosync <= -3*p->in_inc) { ++ if (p->notout >= p->num_fields) ++ dropped_fields = p->num_fields; ++ break; ++ } ++ if (p->num_fields == 1) { ++ int prevbreak = ps->sad.noise >= 128; ++ if (p->iosync < 4*p->in_inc) { ++ show_fields = 3; ++ dropped_fields = prevbreak; ++ } else { ++ show_fields = 4 | (!prevbreak << 3); ++ if (p->notout < 1 + p->prev_fields) ++ dropped_fields = -!prevbreak; ++ } ++ break; ++ } ++ default: ++ if (keep_rate) ++ show_fields = 3 << (breaks & 1); ++ else if (p->notout >= p->num_fields && ++ p->iosync >= (breaks == 1 ? -p->in_inc : ++ p->in_inc << (p->num_fields == 1))) { ++ show_fields = (1 << (2 + p->num_fields)) - (1<notout >= p->num_fields) ++ dropped_fields += p->num_fields + 2 - breaks; ++ if (breaks == 1) { ++ if (p->iosync >= 4*p->in_inc) ++ show_fields = 6; ++ } else if (p->iosync > -3*p->in_inc) ++ show_fields = 3; /* odd+even */ ++ } ++ break; ++ } ++ ++ show_fields &= 15; ++ prev = p->prev_fields; ++ if (breaks < 8) { ++ if (p->num_fields == 1) ++ breaks &= ~4; ++ if (breaks) ++ p->num_breaks++; ++ if (breaks == 3) ++ p->prev_fields = p->num_fields = 1; ++ else if (breaks) { ++ p->prev_fields = p->num_fields + (breaks==1) - (breaks==4); ++ p->num_fields = breaks - (breaks == 4) + (p->chflag == '|'); ++ } else ++ p->num_fields += 2; ++ } else ++ p->num_fields += 2; ++ ++ p->iosync += 4 * p->in_inc; ++ if (p->chflag == '|') ++ p->iosync += p->in_inc; ++ ++ if (show_fields) { ++ p->iosync -= p->out_dec; ++ p->notout = !(show_fields & 1) + !(show_fields & 3); ++ if (((show_fields & 3) == 3 && ++ (s->low.noise + s->interlaced_low < (s->num_blocks>>8) || ++ s->sad.noise < 160)) || ++ ((show_fields & 12) == 12 && ++ (ps->low.noise + ps->interlaced_low < (s->num_blocks>>8) || ++ ps->sad.noise < 160))) { ++ p->export_count++; ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, ++ MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE, ++ p->w, p->h); ++ if ((show_fields & 3) != 3) planes = old_planes; ++ dmpi->planes[0] = planes[0]; ++ dmpi->stride[0] = p->stride; ++ dmpi->width = mpi->width; ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ dmpi->planes[1] = planes[1]; ++ dmpi->planes[2] = planes[2]; ++ dmpi->stride[1] = p->chroma_stride; ++ dmpi->stride[2] = p->chroma_stride; ++ } ++ } else { ++ p->merge_count++; ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ p->w, p->h); ++ copy_merge_fields(p, dmpi, old_planes, planes, show_fields); ++ } ++ p->outframes++; ++ } else ++ p->notout += 2; ++ ++ if (p->verbose) ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "%lu %lu: %x %c %c %lu%s%s%c%s\n", ++ p->inframes, p->outframes, ++ breaks, breaks<8 && breaks>0 ? (int) p->prev_fields+'0' : ' ', ++ ITOC(show_fields), ++ p->num_breaks, 5*p->in_inc == p->out_dec && breaks<8 && ++ breaks>0 && ((prev&~1)!=2 || prev+p->prev_fields!=5) ? ++ " ######## bad telecine ########" : "", ++ dropped_fields ? " ======== dropped ":"", ITOC(dropped_fields), ++ !show_fields || (show_fields & (show_fields-1)) ? ++ "" : " @@@@@@@@@@@@@@@@@"); ++ ++ p->merge_time += get_time() - diff_time; ++ return show_fields ? vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) : 0; ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - support more formats */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ case IMGFMT_411P: ++ case IMGFMT_422P: ++ case IMGFMT_444P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ unsigned long cxm = 0; ++ unsigned long cym = 0; ++ struct vf_priv_s *p = vf->priv; ++ // rounding: ++ if(!IMGFMT_IS_RGB(outfmt) && !IMGFMT_IS_BGR(outfmt)){ ++ switch(outfmt){ ++ case IMGFMT_444P: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ break; ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ cym = 3; ++ case IMGFMT_411P: ++ cxm = 3; ++ break; ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ cym = 1; ++ default: ++ cxm = 1; ++ } ++ } ++ p->chroma_swapped = !!(p->crop_y & (cym+1)); ++ if (p->w) p->w += p->crop_x & cxm; ++ if (p->h) p->h += p->crop_y & cym; ++ p->crop_x &= ~cxm; ++ p->crop_y &= ~cym; ++ if (!p->w || p->w > width ) p->w = width; ++ if (!p->h || p->h > height) p->h = height; ++ if (p->crop_x + p->w > width ) p->crop_x = 0; ++ if (p->crop_y + p->h > height) p->crop_y = 0; ++ ++ if(!opt_screen_size_x && !opt_screen_size_y){ ++ d_width = d_width * p->w/width; ++ d_height = d_height * p->h/height; ++ } ++ return vf_next_config(vf, p->w, p->h, d_width, d_height, flags, outfmt); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ struct vf_priv_s *p = vf->priv; ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "diff_time: %.3f, merge_time: %.3f, " ++ "export: %lu, merge: %lu, copy: %lu\n", p->diff_time, p->merge_time, ++ p->export_count, p->merge_count, p->num_copies); ++ free(p->memory_allocated); ++ free(p); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->get_image = get_image; ++ vf->put_image = put_image; ++ vf->config = config; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ p->out_dec = 5; ++ p->in_inc = 4; ++ p->thres.noise = 128; ++ p->thres.even = 128; ++ p->sad_thres = 64; ++ p->dint_thres = 4; ++ p->luma_only = 0; ++ p->fast = 3; ++ p->mmx2 = gCpuCaps.hasMMX2 ? 1 : gCpuCaps.has3DNow ? 2 : 0; ++ if (args) { ++ const char *args_remain = parse_args(p, args); ++ if (args_remain) { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "filmdint: unknown suboption: %s\n", args_remain); ++ return 0; ++ } ++ if (p->out_dec < p->in_inc) { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "filmdint: increasing the frame rate is not supported\n"); ++ return 0; ++ } ++ } ++ if (p->mmx2 > 2) ++ p->mmx2 = 0; ++#if !HAVE_MMX ++ p->mmx2 = 0; ++#endif ++#if !HAVE_AMD3DNOW ++ p->mmx2 &= 1; ++#endif ++ p->thres.odd = p->thres.even; ++ p->thres.temp = p->thres.noise; ++ p->diff_time = 0; ++ p->merge_time = 0; ++ return 1; ++} ++ ++const vf_info_t vf_info_filmdint = { ++ "Advanced inverse telecine filer", ++ "filmdint", ++ "Zoltan Hidvegi", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fixpts.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fixpts.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fixpts.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fixpts.c 2012-05-14 14:08:54.746348273 +0200 +@@ -0,0 +1,137 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ double current; ++ double step; ++ int autostart; ++ int autostep; ++ unsigned have_step:1; ++ unsigned print:1; ++}; ++ ++static int put_image(vf_instance_t *vf, mp_image_t *src, double pts) ++{ ++ struct vf_priv_s *p = vf->priv; ++ ++ if (p->print) { ++ if (pts == MP_NOPTS_VALUE) ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: undef\n"); ++ else ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "PTS: %f\n", pts); ++ } ++ if (pts != MP_NOPTS_VALUE && p->autostart != 0) { ++ p->current = pts; ++ if (p->autostart > 0) ++ p->autostart--; ++ } else if (pts != MP_NOPTS_VALUE && p->autostep > 0) { ++ p->step = pts - p->current; ++ p->current = pts; ++ p->autostep--; ++ p->have_step = 1; ++ } else if (p->have_step) { ++ p->current += p->step; ++ pts = p->current; ++ } else { ++ pts = MP_NOPTS_VALUE; ++ } ++ return vf_next_put_image(vf, src, pts); ++} ++ ++static void uninit(vf_instance_t *vf) ++{ ++ free(vf->priv); ++} ++ ++static int parse_args(struct vf_priv_s *p, const char *args) ++{ ++ int pos; ++ double num, denom = 1; ++ int iarg; ++ ++ while (*args != 0) { ++ pos = 0; ++ if (sscanf(args, "print%n", &pos) == 0 && pos > 0) { ++ p->print = 1; ++ } else if (sscanf(args, "fps=%lf%n/%lf%n", &num, &pos, &denom, &pos) >= ++ 1 && pos > 0) { ++ p->step = denom / num; ++ p->have_step = 1; ++ } else if (sscanf(args, "start=%lf%n", &num, &pos) >= 1 && pos > 0) { ++ p->current = num; ++ } else if (sscanf(args, "autostart=%d%n", &iarg, &pos) == 1 && pos > 0) { ++ p->autostart = iarg; ++ } else if (sscanf(args, "autofps=%d%n", &iarg, &pos) == 1 && pos > 0) { ++ p->autostep = iarg; ++ } else { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, ++ "fixpts: unknown suboption: %s\n", args); ++ return 0; ++ } ++ args += pos; ++ if (*args == ':') ++ args++; ++ } ++ return 1; ++} ++ ++static int open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ struct vf_priv_s ptmp = { ++ .current = 0, ++ .step = 0, ++ .autostart = 0, ++ .autostep = 0, ++ .have_step = 0, ++ .print = 0, ++ }; ++ ++ if (!parse_args(&ptmp, args == NULL ? "" : args)) ++ return 0; ++ ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ vf->priv = p = malloc(sizeof(struct vf_priv_s)); ++ *p = ptmp; ++ p->current = -p->step; ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_fixpts = { ++ "Fix presentation timestamps", ++ "fixpts", ++ "Nicolas George", ++ "", ++ &open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_framestep.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_framestep.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_framestep.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_framestep.c 2012-05-14 14:08:54.747348293 +0200 +@@ -0,0 +1,205 @@ ++/* ++ * filter to ouput only 1 every n frame, or only the I (key)frame ++ * ++ * The parameters are: ++ * ++ * [I] | [i]num ++ * ++ * if you call the filter with I (uppercase) as the parameter ++ * ... -vf framestep=I ... ++ * then ONLY the keyframes are outputted. ++ * For DVD it means, generally, one every 15 frames (IBBPBBPBBPBBPBB), for avi it means ++ * every scene change or every keyint value (see -lavcopts). ++ * ++ * if you call the filter with the i (lowercase) ++ * ... -vf framestep=i ... ++ * then a I! followed by a cr is printed when a key frame (eg Intra frame) is ++ * found, leaving the current line of mplayer/mencoder, where you got the ++ * time, in seconds, and frame of the key. Use this information to split the ++ * AVI. ++ * ++ * After the i or alone you can put a positive number and only one frame every ++ * x (the number you set) is passed on the filter chain, limiting the output ++ * of the frame. ++ * ++ * Example ++ * ... -vf framestep=i20 ... ++ * Dump one every 20 frames, printing on the console when a I-Frame is encounter. ++ * ++ * ... -vf framestep=25 ++ * Dump one every 25 frames. ++ * ++ * If you call the filter without parameter it does nothing (except using memory ++ * and resource of your system,. of course). ++ * ++ * This filter doesn' t work like the option -sstep seconds. ++ * ++ * The -sstep seek to the new position, without decoding all frames but, ++ * expecially on avi file coded whith mpeg4 (lavc or xvid or divx), the ++ * seek is not always too much precise. ++ * ++ * This filter simply discard the unwanted frames, so you are very precise in ++ * counting the frame but sometime you use a lot of CPU for nothing. ++ * ++ * As usual it depends on what you're doing. ++ * ++ * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it ) ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++/* Uncomment if you want to print some info on the format */ ++// #define DUMP_FORMAT_DATA ++ ++/* Private data */ ++struct vf_priv_s { ++ /* Current frame */ ++ int frame_cur; ++ /* Frame output step, 0 = all */ ++ int frame_step; ++ /* Only I-Frame (2), print on I-Frame (1) */ ++ int dump_iframe; ++}; ++ ++/* Filter handler */ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ struct vf_priv_s *priv; ++ int skip; ++ ++ priv = vf->priv; ++ ++ /* Print the 'I' if is a intra frame. The \n advance the current line so you got the ++ * current file time (in second) and the frame number on the console ;-) ++ */ ++ if (priv->dump_iframe) { ++ if (mpi->pict_type == 1) { ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "I!\n"); ++ } ++ } ++ ++ /* decide if frame must be shown */ ++ if (priv->dump_iframe == 2) { ++ /* Only key frame */ ++ skip = mpi->pict_type == 1 ? 0 : 1; ++ } ++ else { ++ /* Only 1 every frame_step */ ++ skip = 0; ++ if ((priv->frame_step != 0) && ((priv->frame_cur % priv->frame_step) != 0)) { ++ skip = 1; ++ } ++ } ++ /* Increment current frame */ ++ ++priv->frame_cur; ++ ++ if (skip == 0) { ++ /* Get image, export type (we don't modify tghe image) */ ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, ++ mpi->w, mpi->h); ++ /* Copy only the pointer ( MP_IMGTYPE_EXPORT ! ) */ ++ dmpi->planes[0] = mpi->planes[0]; ++ dmpi->planes[1] = mpi->planes[1]; ++ dmpi->planes[2] = mpi->planes[2]; ++ ++ dmpi->stride[0] = mpi->stride[0]; ++ dmpi->stride[1] = mpi->stride[1]; ++ dmpi->stride[2] = mpi->stride[2]; ++ ++ dmpi->width = mpi->width; ++ dmpi->height = mpi->height; ++ ++ /* Chain to next filter / output ... */ ++ return vf_next_put_image(vf, dmpi, pts); ++ } ++ ++ /* Skip the frame */ ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ /* Free private data */ ++ free(vf->priv); ++} ++ ++/* Main entry funct for the filter */ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ if (p == NULL) { ++ return 0; ++ } ++ ++ if (args != NULL) { ++#ifdef DUMP_FORMAT_DATA ++ if (*args == 'd') { ++ p->dump_iframe = 3; ++ } ++ else ++#endif ++ if (*args == 'I') { ++ /* Dump only KEY (ie INTRA) frame */ ++ p->dump_iframe = 2; ++ } ++ else { ++ if (*args == 'i') { ++ /* Print a 'I!' when a i-frame is encounter */ ++ p->dump_iframe = 1; ++ ++args; ++ } ++ ++ if (*args != '\0') { ++ p->frame_step = atoi(args); ++ if (p->frame_step <= 0) { ++ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_ErrorParsingArgument); ++ return 0; ++ } ++ } ++ } ++ } ++ return 1; ++} ++ ++const vf_info_t vf_info_framestep = { ++ "Dump one every n / key frames", ++ "framestep", ++ "Daniele Forghieri", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fspp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fspp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_fspp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_fspp.c 2012-05-14 14:08:54.752348395 +0200 +@@ -0,0 +1,2117 @@ ++/* ++ * Copyright (C) 2003 Michael Niedermayer ++ * Copyright (C) 2005 Nikolaj Poroshin ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/* ++ * This implementation is based on an algorithm described in ++ * "Aria Nosratinia Embedded Post-Processing for ++ * Enhancement of Compressed Images (1999)" ++ * (http://citeseer.nj.nec.com/nosratinia99embedded.html) ++ * Futher, with splitting (i)dct into hor/ver passes, one of them can be ++ * performed once per block, not pixel. This allows for much better speed. ++ */ ++ ++/* ++ Heavily optimized version of SPP filter by Nikolaj ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "vd_ffmpeg.h" ++#include "libvo/fastmemcpy.h" ++ ++#include "libavutil/internal.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/mem.h" ++#include "libavcodec/avcodec.h" ++#include "libavcodec/dsputil.h" ++ ++#undef free ++#undef malloc ++ ++//===========================================================================// ++#define BLOCKSZ 12 ++ ++static const short custom_threshold[64]= ++// values (296) can't be too high ++// -it causes too big quant dependence ++// or maybe overflow(check), which results in some flashing ++{ 71, 296, 295, 237, 71, 40, 38, 19, ++ 245, 193, 185, 121, 102, 73, 53, 27, ++ 158, 129, 141, 107, 97, 73, 50, 26, ++ 102, 116, 109, 98, 82, 66, 45, 23, ++ 71, 94, 95, 81, 70, 56, 38, 20, ++ 56, 77, 74, 66, 56, 44, 30, 15, ++ 38, 53, 50, 45, 38, 30, 21, 11, ++ 20, 27, 26, 23, 20, 15, 11, 5 ++}; ++ ++static const uint8_t __attribute__((aligned(32))) dither[8][8]={ ++ { 0, 48, 12, 60, 3, 51, 15, 63, }, ++ { 32, 16, 44, 28, 35, 19, 47, 31, }, ++ { 8, 56, 4, 52, 11, 59, 7, 55, }, ++ { 40, 24, 36, 20, 43, 27, 39, 23, }, ++ { 2, 50, 14, 62, 1, 49, 13, 61, }, ++ { 34, 18, 46, 30, 33, 17, 45, 29, }, ++ { 10, 58, 6, 54, 9, 57, 5, 53, }, ++ { 42, 26, 38, 22, 41, 25, 37, 21, }, ++}; ++ ++struct vf_priv_s { //align 16 ! ++ uint64_t threshold_mtx_noq[8*2]; ++ uint64_t threshold_mtx[8*2];//used in both C & MMX (& later SSE2) versions ++ ++ int log2_count; ++ int temp_stride; ++ int qp; ++ int mpeg2; ++ int prev_q; ++ uint8_t *src; ++ int16_t *temp; ++ int bframes; ++ char *non_b_qp; ++}; ++ ++ ++#if !HAVE_MMX ++ ++//This func reads from 1 slice, 1 and clears 0 & 1 ++static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale) ++{int y, x; ++#define STORE(pos) \ ++ temp= (src[x + pos] + (d[pos]>>log2_scale))>>(6-log2_scale); \ ++ src[x + pos]=src[x + pos - 8*src_stride]=0; \ ++ if(temp & 0x100) temp= ~(temp>>31); \ ++ dst[x + pos]= temp; ++ ++ for(y=0; y>log2_scale))>>(6-log2_scale); \ ++ src[x + pos + 16*src_stride]=0; \ ++ if(temp & 0x100) temp= ~(temp>>31); \ ++ dst[x + pos]= temp; ++ ++ for(y=0; ythreshold_mtx)[a]=q * ((short*)p->threshold_mtx_noq)[a];//ints faster in C ++} ++ ++static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt); ++static void row_idct_c(DCTELEM* workspace, ++ int16_t* output_adr, int output_stride, int cnt); ++static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt); ++ ++//this is rather ugly, but there is no need for function pointers ++#define store_slice_s store_slice_c ++#define store_slice2_s store_slice2_c ++#define mul_thrmat_s mul_thrmat_c ++#define column_fidct_s column_fidct_c ++#define row_idct_s row_idct_c ++#define row_fdct_s row_fdct_c ++ ++#else /* HAVE_MMX */ ++ ++//This func reads from 1 slice, 1 and clears 0 & 1 ++static void store_slice_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale) ++{ ++ const uint8_t *od=&dither[0][0]; ++ const uint8_t *end=&dither[height][0]; ++ width = (width+7)&~7; ++ dst_stride-=width; ++ //src_stride=(src_stride-width)*2; ++ __asm__ volatile( ++ "mov %5, %%"REG_d" \n\t" ++ "mov %6, %%"REG_S" \n\t" ++ "mov %7, %%"REG_D" \n\t" ++ "mov %1, %%"REG_a" \n\t" ++ "movd %%"REG_d", %%mm5 \n\t" ++ "xor $-1, %%"REG_d" \n\t" ++ "mov %%"REG_a", %%"REG_c" \n\t" ++ "add $7, %%"REG_d" \n\t" ++ "neg %%"REG_a" \n\t" ++ "sub %0, %%"REG_c" \n\t" ++ "add %%"REG_c", %%"REG_c" \n\t" ++ "movd %%"REG_d", %%mm2 \n\t" ++ "mov %%"REG_c", %1 \n\t" ++ "mov %2, %%"REG_d" \n\t" ++ "shl $4, %%"REG_a" \n\t" ++ ++ "2: \n\t" ++ "movq (%%"REG_d"), %%mm3 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ "punpckhbw %%mm7, %%mm4 \n\t" ++ "mov %0, %%"REG_c" \n\t" ++ "psraw %%mm5, %%mm3 \n\t" ++ "psraw %%mm5, %%mm4 \n\t" ++ "1: \n\t" ++ "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t" ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq 8(%%"REG_S"), %%mm1 \n\t" ++ ++ "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t" ++ "paddw %%mm3, %%mm0 \n\t" ++ "paddw %%mm4, %%mm1 \n\t" ++ ++ "movq %%mm7, (%%"REG_S") \n\t" ++ "psraw %%mm2, %%mm0 \n\t" ++ "psraw %%mm2, %%mm1 \n\t" ++ ++ "movq %%mm7, 8(%%"REG_S") \n\t" ++ "packuswb %%mm1, %%mm0 \n\t" ++ "add $16, %%"REG_S" \n\t" ++ ++ "movq %%mm0, (%%"REG_D") \n\t" ++ "add $8, %%"REG_D" \n\t" ++ "sub $8, %%"REG_c" \n\t" ++ "jg 1b \n\t" ++ "add %1, %%"REG_S" \n\t" ++ "add $8, %%"REG_d" \n\t" ++ "add %3, %%"REG_D" \n\t" ++ "cmp %4, %%"REG_d" \n\t" ++ "jl 2b \n\t" ++ ++ : ++ : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end), ++ "m" (log2_scale), "m" (src), "m" (dst) //input ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D ++ ); ++} ++ ++//This func reads from 2 slices, 0 & 2 and clears 2-nd ++static void store_slice2_mmx(uint8_t *dst, int16_t *src, long dst_stride, long src_stride, long width, long height, long log2_scale) ++{ ++ const uint8_t *od=&dither[0][0]; ++ const uint8_t *end=&dither[height][0]; ++ width = (width+7)&~7; ++ dst_stride-=width; ++ //src_stride=(src_stride-width)*2; ++ __asm__ volatile( ++ "mov %5, %%"REG_d" \n\t" ++ "mov %6, %%"REG_S" \n\t" ++ "mov %7, %%"REG_D" \n\t" ++ "mov %1, %%"REG_a" \n\t" ++ "movd %%"REG_d", %%mm5 \n\t" ++ "xor $-1, %%"REG_d" \n\t" ++ "mov %%"REG_a", %%"REG_c" \n\t" ++ "add $7, %%"REG_d" \n\t" ++ "sub %0, %%"REG_c" \n\t" ++ "add %%"REG_c", %%"REG_c" \n\t" ++ "movd %%"REG_d", %%mm2 \n\t" ++ "mov %%"REG_c", %1 \n\t" ++ "mov %2, %%"REG_d" \n\t" ++ "shl $5, %%"REG_a" \n\t" ++ ++ "2: \n\t" ++ "movq (%%"REG_d"), %%mm3 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ "punpckhbw %%mm7, %%mm4 \n\t" ++ "mov %0, %%"REG_c" \n\t" ++ "psraw %%mm5, %%mm3 \n\t" ++ "psraw %%mm5, %%mm4 \n\t" ++ "1: \n\t" ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq 8(%%"REG_S"), %%mm1 \n\t" ++ "paddw %%mm3, %%mm0 \n\t" ++ ++ "paddw (%%"REG_S",%%"REG_a",), %%mm0 \n\t" ++ "paddw %%mm4, %%mm1 \n\t" ++ "movq 8(%%"REG_S",%%"REG_a",), %%mm6 \n\t" ++ ++ "movq %%mm7, (%%"REG_S",%%"REG_a",) \n\t" ++ "psraw %%mm2, %%mm0 \n\t" ++ "paddw %%mm6, %%mm1 \n\t" ++ ++ "movq %%mm7, 8(%%"REG_S",%%"REG_a",) \n\t" ++ "psraw %%mm2, %%mm1 \n\t" ++ "packuswb %%mm1, %%mm0 \n\t" ++ ++ "movq %%mm0, (%%"REG_D") \n\t" ++ "add $16, %%"REG_S" \n\t" ++ "add $8, %%"REG_D" \n\t" ++ "sub $8, %%"REG_c" \n\t" ++ "jg 1b \n\t" ++ "add %1, %%"REG_S" \n\t" ++ "add $8, %%"REG_d" \n\t" ++ "add %3, %%"REG_D" \n\t" ++ "cmp %4, %%"REG_d" \n\t" ++ "jl 2b \n\t" ++ ++ : ++ : "m" (width), "m" (src_stride), "erm" (od), "m" (dst_stride), "erm" (end), ++ "m" (log2_scale), "m" (src), "m" (dst) //input ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_D, "%"REG_S ++ ); ++} ++ ++static void mul_thrmat_mmx(struct vf_priv_s *p, int q) ++{ ++ uint64_t *adr=&p->threshold_mtx_noq[0]; ++ __asm__ volatile( ++ "movd %0, %%mm7 \n\t" ++ "add $8*8*2, %%"REG_D" \n\t" ++ "movq 0*8(%%"REG_S"), %%mm0 \n\t" ++ "punpcklwd %%mm7, %%mm7 \n\t" ++ "movq 1*8(%%"REG_S"), %%mm1 \n\t" ++ "punpckldq %%mm7, %%mm7 \n\t" ++ "pmullw %%mm7, %%mm0 \n\t" ++ ++ "movq 2*8(%%"REG_S"), %%mm2 \n\t" ++ "pmullw %%mm7, %%mm1 \n\t" ++ ++ "movq 3*8(%%"REG_S"), %%mm3 \n\t" ++ "pmullw %%mm7, %%mm2 \n\t" ++ ++ "movq %%mm0, 0*8(%%"REG_D") \n\t" ++ "movq 4*8(%%"REG_S"), %%mm4 \n\t" ++ "pmullw %%mm7, %%mm3 \n\t" ++ ++ "movq %%mm1, 1*8(%%"REG_D") \n\t" ++ "movq 5*8(%%"REG_S"), %%mm5 \n\t" ++ "pmullw %%mm7, %%mm4 \n\t" ++ ++ "movq %%mm2, 2*8(%%"REG_D") \n\t" ++ "movq 6*8(%%"REG_S"), %%mm6 \n\t" ++ "pmullw %%mm7, %%mm5 \n\t" ++ ++ "movq %%mm3, 3*8(%%"REG_D") \n\t" ++ "movq 7*8+0*8(%%"REG_S"), %%mm0 \n\t" ++ "pmullw %%mm7, %%mm6 \n\t" ++ ++ "movq %%mm4, 4*8(%%"REG_D") \n\t" ++ "movq 7*8+1*8(%%"REG_S"), %%mm1 \n\t" ++ "pmullw %%mm7, %%mm0 \n\t" ++ ++ "movq %%mm5, 5*8(%%"REG_D") \n\t" ++ "movq 7*8+2*8(%%"REG_S"), %%mm2 \n\t" ++ "pmullw %%mm7, %%mm1 \n\t" ++ ++ "movq %%mm6, 6*8(%%"REG_D") \n\t" ++ "movq 7*8+3*8(%%"REG_S"), %%mm3 \n\t" ++ "pmullw %%mm7, %%mm2 \n\t" ++ ++ "movq %%mm0, 7*8+0*8(%%"REG_D") \n\t" ++ "movq 7*8+4*8(%%"REG_S"), %%mm4 \n\t" ++ "pmullw %%mm7, %%mm3 \n\t" ++ ++ "movq %%mm1, 7*8+1*8(%%"REG_D") \n\t" ++ "movq 7*8+5*8(%%"REG_S"), %%mm5 \n\t" ++ "pmullw %%mm7, %%mm4 \n\t" ++ ++ "movq %%mm2, 7*8+2*8(%%"REG_D") \n\t" ++ "movq 7*8+6*8(%%"REG_S"), %%mm6 \n\t" ++ "pmullw %%mm7, %%mm5 \n\t" ++ ++ "movq %%mm3, 7*8+3*8(%%"REG_D") \n\t" ++ "movq 14*8+0*8(%%"REG_S"), %%mm0 \n\t" ++ "pmullw %%mm7, %%mm6 \n\t" ++ ++ "movq %%mm4, 7*8+4*8(%%"REG_D") \n\t" ++ "movq 14*8+1*8(%%"REG_S"), %%mm1 \n\t" ++ "pmullw %%mm7, %%mm0 \n\t" ++ ++ "movq %%mm5, 7*8+5*8(%%"REG_D") \n\t" ++ "pmullw %%mm7, %%mm1 \n\t" ++ ++ "movq %%mm6, 7*8+6*8(%%"REG_D") \n\t" ++ "movq %%mm0, 14*8+0*8(%%"REG_D") \n\t" ++ "movq %%mm1, 14*8+1*8(%%"REG_D") \n\t" ++ ++ : "+g" (q), "+S" (adr), "+D" (adr) ++ : ++ ); ++} ++ ++static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt); ++static void row_idct_mmx(DCTELEM* workspace, ++ int16_t* output_adr, int output_stride, int cnt); ++static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt); ++ ++#define store_slice_s store_slice_mmx ++#define store_slice2_s store_slice2_mmx ++#define mul_thrmat_s mul_thrmat_mmx ++#define column_fidct_s column_fidct_mmx ++#define row_idct_s row_idct_mmx ++#define row_fdct_s row_fdct_mmx ++#endif // HAVE_MMX ++ ++static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, ++ int dst_stride, int src_stride, ++ int width, int height, ++ uint8_t *qp_store, int qp_stride, int is_luma) ++{ ++ int x, x0, y, es, qy, t; ++ const int stride= is_luma ? p->temp_stride : (width+16);//((width+16+15)&(~15)) ++ const int step=6-p->log2_count; ++ const int qps= 3 + is_luma; ++ int32_t __attribute__((aligned(32))) block_align[4*8*BLOCKSZ+ 4*8*BLOCKSZ]; ++ DCTELEM *block= (DCTELEM *)block_align; ++ DCTELEM *block3=(DCTELEM *)(block_align+4*8*BLOCKSZ); ++ ++ memset(block3, 0, 4*8*BLOCKSZ); ++ ++ //p->src=src-src_stride*8-8;//! ++ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace ++ for(y=0; ysrc + index, src + y*src_stride, width);//this line can be avoided by using DR & user fr.buffers ++ for(x=0; x<8; x++){ ++ p->src[index - x - 1]= p->src[index + x ]; ++ p->src[index + width + x ]= p->src[index + width - x - 1]; ++ } ++ } ++ for(y=0; y<8; y++){ ++ fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride); ++ fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride); ++ } ++ //FIXME (try edge emu) ++ ++ for(y=8; y<24; y++) ++ memset(p->temp+ 8 +y*stride, 0,width*sizeof(int16_t)); ++ ++ for(y=step; yheight-1) qy=height-1; ++ if (qy<0) qy=0; ++ qy=(qy>>qps)*qp_stride; ++ row_fdct_s(block, p->src + y*stride +2-(y&1), stride, 2); ++ for(x0=0; x0src + y*stride+8+x0 +2-(y&1), stride, 2*(BLOCKSZ-1)); ++ if(p->qp) ++ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+0*8, block3+0*8, 8*(BLOCKSZ-1)); //yes, this is a HOTSPOT ++ else ++ for (x=0; x<8*(BLOCKSZ-1); x+=8) { ++ t=x+x0-2; //correct t=x+x0-2-(y&1), but its the same ++ if (t<0) t=0;//t always < width-2 ++ t=qp_store[qy+(t>>qps)]; ++ t=norm_qscale(t, p->mpeg2); ++ if (t!=p->prev_q) p->prev_q=t, mul_thrmat_s(p, t); ++ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block+x*8, block3+x*8, 8); //yes, this is a HOTSPOT ++ } ++ row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, 2*(BLOCKSZ-1)); ++ memmove(block, block+(BLOCKSZ-1)*64, 8*8*sizeof(DCTELEM)); //cycling ++ memmove(block3, block3+(BLOCKSZ-1)*64, 6*8*sizeof(DCTELEM)); ++ } ++ // ++ es=width+8-x0; // 8, ... ++ if (es>8) ++ row_fdct_s(block+8*8, p->src + y*stride+8+x0 +2-(y&1), stride, (es-4)>>2); ++ column_fidct_s((int16_t*)(&p->threshold_mtx[0]), block, block3, es&(~1)); ++ row_idct_s(block3+0*8, p->temp + (y&15)*stride+x0+2-(y&1), stride, es>>2); ++ {const int y1=y-8+step;//l5-7 l4-6 ++ if (!(y1&7) && y1) { ++ if (y1&8) store_slice_s(dst + (y1-8)*dst_stride, p->temp+ 8 +8*stride, ++ dst_stride, stride, width, 8, 5-p->log2_count); ++ else store_slice2_s(dst + (y1-8)*dst_stride, p->temp+ 8 +0*stride, ++ dst_stride, stride, width, 8, 5-p->log2_count); ++ } } ++ } ++ ++ if (y&7) { // == height & 7 ++ if (y&8) store_slice_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +8*stride, ++ dst_stride, stride, width, y&7, 5-p->log2_count); ++ else store_slice2_s(dst + ((y-8)&~7)*dst_stride, p->temp+ 8 +0*stride, ++ dst_stride, stride, width, y&7, 5-p->log2_count); ++ } ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ int h= (height+16+15)&(~15); ++ ++ vf->priv->temp_stride= (width+16+15)&(~15); ++ vf->priv->temp= (int16_t*)av_mallocz(vf->priv->temp_stride*3*8*sizeof(int16_t)); ++ //this can also be avoided, see above ++ vf->priv->src = (uint8_t*)av_malloc(vf->priv->temp_stride*h*sizeof(uint8_t)); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ }else{ ++ dmpi=vf->dmpi; ++ } ++ ++ vf->priv->mpeg2= mpi->qscale_type; ++ if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){ ++ int w = mpi->qstride; ++ int h = (mpi->h + 15) >> 4; ++ if (!w) { ++ w = (mpi->w + 15) >> 4; ++ h = 1; ++ } ++ if(!vf->priv->non_b_qp) ++ vf->priv->non_b_qp= malloc(w*h); ++ fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h); ++ } ++ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ char *qp_tab= vf->priv->non_b_qp; ++ if(vf->priv->bframes || !qp_tab) ++ qp_tab= mpi->qscale; ++ ++ if(qp_tab || vf->priv->qp){ ++ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], ++ mpi->w, mpi->h, qp_tab, mpi->qstride, 1); ++ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], ++ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0); ++ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], ++ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0); ++ }else{ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); ++ } ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); ++#endif ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ if(!vf->priv) return; ++ ++ av_free(vf->priv->temp); ++ vf->priv->temp= NULL; ++ av_free(vf->priv->src); ++ vf->priv->src= NULL; ++ //free(vf->priv->avctx); ++ //vf->priv->avctx= NULL; ++ free(vf->priv->non_b_qp); ++ vf->priv->non_b_qp= NULL; ++ ++ av_free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch(fmt){ ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int control(struct vf_instance *vf, int request, void* data) ++{ ++ switch(request){ ++ case VFCTRL_QUERY_MAX_PP_LEVEL: ++ return 5; ++ case VFCTRL_SET_PP_LEVEL: ++ vf->priv->log2_count= *((unsigned int*)data); ++ if (vf->priv->log2_count < 4) vf->priv->log2_count=4; ++ return CONTROL_TRUE; ++ } ++ return vf_next_control(vf,request,data); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ int i=0, bias; ++ int custom_threshold_m[64]; ++ int log2c=-1; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->control= control; ++ vf->priv=av_mallocz(sizeof(struct vf_priv_s));//assumes align 16 ! ++ ++ init_avcodec(); ++ ++ //vf->priv->avctx= avcodec_alloc_context(); ++ //dsputil_init(&vf->priv->dsp, vf->priv->avctx); ++ ++ vf->priv->log2_count= 4; ++ vf->priv->bframes = 0; ++ ++ if (args) sscanf(args, "%d:%d:%d:%d", &log2c, &vf->priv->qp, &i, &vf->priv->bframes); ++ ++ if( log2c >=4 && log2c <=5 ) ++ vf->priv->log2_count = log2c; ++ else if( log2c >= 6 ) ++ vf->priv->log2_count = 5; ++ ++ if(vf->priv->qp < 0) ++ vf->priv->qp = 0; ++ ++ if (i < -15) i = -15; ++ if (i > 32) i = 32; ++ ++ bias= (1<<4)+i; //regulable ++ vf->priv->prev_q=0; ++ // ++ for(i=0;i<64;i++) //FIXME: tune custom_threshold[] and remove this ! ++ custom_threshold_m[i]=(int)(custom_threshold[i]*(bias/71.)+ 0.5); ++ for(i=0;i<8;i++){ ++ vf->priv->threshold_mtx_noq[2*i]=(uint64_t)custom_threshold_m[i*8+2] ++ |(((uint64_t)custom_threshold_m[i*8+6])<<16) ++ |(((uint64_t)custom_threshold_m[i*8+0])<<32) ++ |(((uint64_t)custom_threshold_m[i*8+4])<<48); ++ vf->priv->threshold_mtx_noq[2*i+1]=(uint64_t)custom_threshold_m[i*8+5] ++ |(((uint64_t)custom_threshold_m[i*8+3])<<16) ++ |(((uint64_t)custom_threshold_m[i*8+1])<<32) ++ |(((uint64_t)custom_threshold_m[i*8+7])<<48); ++ } ++ ++ if (vf->priv->qp) vf->priv->prev_q=vf->priv->qp, mul_thrmat_s(vf->priv, vf->priv->qp); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_fspp = { ++ "fast simple postprocess", ++ "fspp", ++ "Michael Niedermayer, Nikolaj Poroshin", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//==================================================================== ++//Specific spp's dct, idct and threshold functions ++//I'd prefer to have them in the separate file. ++ ++//#define MANGLE(a) #a ++ ++//typedef int16_t DCTELEM; //! only int16_t ++ ++#define DCTSIZE 8 ++#define DCTSIZE_S "8" ++ ++#define FIX(x,s) ((int) ((x) * (1<>16) ++#define THRESHOLD(r,x,t) if(((unsigned)((x)+t))>t*2) r=(x);else r=0; ++#define DESCALE(x,n) (((x) + (1 << ((n)-1))) >> n) ++ ++#if HAVE_MMX ++ ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_382683433)=FIX64(0.382683433, 14); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_541196100)=FIX64(0.541196100, 14); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_707106781)=FIX64(0.707106781, 14); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_306562965)=FIX64(1.306562965, 14); ++ ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562_A)=FIX64(1.414213562, 14); ++ ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_847759065)=FIX64(1.847759065, 13); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_2_613125930)=FIX64(-2.613125930, 13); //- ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_414213562)=FIX64(1.414213562, 13); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_1_082392200)=FIX64(1.082392200, 13); ++//for t3,t5,t7 == 0 shortcut ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_847759065)=FIX64(0.847759065, 14); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_566454497)=FIX64(0.566454497, 14); ++DECLARE_ASM_CONST(8, uint64_t, MM_FIX_0_198912367)=FIX64(0.198912367, 14); ++ ++DECLARE_ASM_CONST(8, uint64_t, MM_DESCALE_RND)=C64(4); ++DECLARE_ASM_CONST(8, uint64_t, MM_2)=C64(2); ++ ++#else /* !HAVE_MMX */ ++ ++typedef int32_t int_simd16_t; ++static const int16_t FIX_0_382683433=FIX(0.382683433, 14); ++static const int16_t FIX_0_541196100=FIX(0.541196100, 14); ++static const int16_t FIX_0_707106781=FIX(0.707106781, 14); ++static const int16_t FIX_1_306562965=FIX(1.306562965, 14); ++static const int16_t FIX_1_414213562_A=FIX(1.414213562, 14); ++static const int16_t FIX_1_847759065=FIX(1.847759065, 13); ++static const int16_t FIX_2_613125930=FIX(-2.613125930, 13); //- ++static const int16_t FIX_1_414213562=FIX(1.414213562, 13); ++static const int16_t FIX_1_082392200=FIX(1.082392200, 13); ++ ++#endif ++ ++#if !HAVE_MMX ++ ++static void column_fidct_c(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt) ++{ ++ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int_simd16_t tmp10, tmp11, tmp12, tmp13; ++ int_simd16_t z1,z2,z3,z4,z5, z10, z11, z12, z13; ++ int_simd16_t d0, d1, d2, d3, d4, d5, d6, d7; ++ ++ DCTELEM* dataptr; ++ DCTELEM* wsptr; ++ int16_t *threshold; ++ int ctr; ++ ++ dataptr = data; ++ wsptr = output; ++ ++ for (; cnt > 0; cnt-=2) { //start positions ++ threshold=(int16_t*)thr_adr;//threshold_mtx ++ for (ctr = DCTSIZE; ctr > 0; ctr--) { ++ // Process columns from input, add to output. ++ tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7]; ++ tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7]; ++ ++ tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6]; ++ tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6]; ++ ++ tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5]; ++ tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5]; ++ ++ tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4]; ++ tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4]; ++ ++ // Even part of FDCT ++ ++ tmp10 = tmp0 + tmp3; ++ tmp13 = tmp0 - tmp3; ++ tmp11 = tmp1 + tmp2; ++ tmp12 = tmp1 - tmp2; ++ ++ d0 = tmp10 + tmp11; ++ d4 = tmp10 - tmp11; ++ ++ z1 = MULTIPLY16H((tmp12 + tmp13) <<2, FIX_0_707106781); ++ d2 = tmp13 + z1; ++ d6 = tmp13 - z1; ++ ++ // Even part of IDCT ++ ++ THRESHOLD(tmp0, d0, threshold[0*8]); ++ THRESHOLD(tmp1, d2, threshold[2*8]); ++ THRESHOLD(tmp2, d4, threshold[4*8]); ++ THRESHOLD(tmp3, d6, threshold[6*8]); ++ tmp0+=2; ++ tmp10 = (tmp0 + tmp2)>>2; ++ tmp11 = (tmp0 - tmp2)>>2; ++ ++ tmp13 = (tmp1 + tmp3)>>2; //+2 ! (psnr decides) ++ tmp12 = MULTIPLY16H((tmp1 - tmp3), FIX_1_414213562_A) - tmp13; //<<2 ++ ++ tmp0 = tmp10 + tmp13; //->temps ++ tmp3 = tmp10 - tmp13; //->temps ++ tmp1 = tmp11 + tmp12; //->temps ++ tmp2 = tmp11 - tmp12; //->temps ++ ++ // Odd part of FDCT ++ ++ tmp10 = tmp4 + tmp5; ++ tmp11 = tmp5 + tmp6; ++ tmp12 = tmp6 + tmp7; ++ ++ z5 = MULTIPLY16H((tmp10 - tmp12)<<2, FIX_0_382683433); ++ z2 = MULTIPLY16H(tmp10 <<2, FIX_0_541196100) + z5; ++ z4 = MULTIPLY16H(tmp12 <<2, FIX_1_306562965) + z5; ++ z3 = MULTIPLY16H(tmp11 <<2, FIX_0_707106781); ++ ++ z11 = tmp7 + z3; ++ z13 = tmp7 - z3; ++ ++ d5 = z13 + z2; ++ d3 = z13 - z2; ++ d1 = z11 + z4; ++ d7 = z11 - z4; ++ ++ // Odd part of IDCT ++ ++ THRESHOLD(tmp4, d1, threshold[1*8]); ++ THRESHOLD(tmp5, d3, threshold[3*8]); ++ THRESHOLD(tmp6, d5, threshold[5*8]); ++ THRESHOLD(tmp7, d7, threshold[7*8]); ++ ++ //Simd version uses here a shortcut for the tmp5,tmp6,tmp7 == 0 ++ z13 = tmp6 + tmp5; ++ z10 = (tmp6 - tmp5)<<1; ++ z11 = tmp4 + tmp7; ++ z12 = (tmp4 - tmp7)<<1; ++ ++ tmp7 = (z11 + z13)>>2; //+2 ! ++ tmp11 = MULTIPLY16H((z11 - z13)<<1, FIX_1_414213562); ++ z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065); ++ tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5; ++ tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - !! ++ ++ tmp6 = tmp12 - tmp7; ++ tmp5 = tmp11 - tmp6; ++ tmp4 = tmp10 + tmp5; ++ ++ wsptr[DCTSIZE*0]+= (tmp0 + tmp7); ++ wsptr[DCTSIZE*1]+= (tmp1 + tmp6); ++ wsptr[DCTSIZE*2]+= (tmp2 + tmp5); ++ wsptr[DCTSIZE*3]+= (tmp3 - tmp4); ++ wsptr[DCTSIZE*4]+= (tmp3 + tmp4); ++ wsptr[DCTSIZE*5]+= (tmp2 - tmp5); ++ wsptr[DCTSIZE*6]= (tmp1 - tmp6); ++ wsptr[DCTSIZE*7]= (tmp0 - tmp7); ++ // ++ dataptr++; //next column ++ wsptr++; ++ threshold++; ++ } ++ dataptr+=8; //skip each second start pos ++ wsptr +=8; ++ } ++} ++ ++#else /* HAVE_MMX */ ++ ++static void column_fidct_mmx(int16_t* thr_adr, DCTELEM *data, DCTELEM *output, int cnt) ++{ ++ uint64_t __attribute__((aligned(8))) temps[4]; ++ __asm__ volatile( ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t" ++ // ++ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t" ++ "movq %%mm1, %%mm0 \n\t" ++ ++ "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0 ++ "movq %%mm7, %%mm3 \n\t" ++ ++ "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3 ++ "movq %%mm1, %%mm5 \n\t" ++ ++ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //t13 ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t" ++ "movq %%mm6, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1 ++ "paddw %%mm7, %%mm5 \n\t" //t10 ++ ++ "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2 ++ "movq %%mm6, %%mm7 \n\t" ++ ++ "paddw %%mm2, %%mm6 \n\t" //t11 ++ "psubw %%mm2, %%mm7 \n\t" //t12 ++ ++ "movq %%mm5, %%mm2 \n\t" ++ "paddw %%mm6, %%mm5 \n\t" //d0 ++ // i0 t13 t12 i3 i1 d0 - d4 ++ "psubw %%mm6, %%mm2 \n\t" //d4 ++ "paddw %%mm1, %%mm7 \n\t" ++ ++ "movq 4*16(%%"REG_d"), %%mm6 \n\t" ++ "psllw $2, %%mm7 \n\t" ++ ++ "psubw 0*16(%%"REG_d"), %%mm5 \n\t" ++ "psubw %%mm6, %%mm2 \n\t" ++ ++ "paddusw 0*16(%%"REG_d"), %%mm5 \n\t" ++ "paddusw %%mm6, %%mm2 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t" ++ // ++ "paddw 0*16(%%"REG_d"), %%mm5 \n\t" ++ "paddw %%mm6, %%mm2 \n\t" ++ ++ "psubusw 0*16(%%"REG_d"), %%mm5 \n\t" ++ "psubusw %%mm6, %%mm2 \n\t" ++ ++//This func is totally compute-bound, operates at huge speed. So, DC shortcut ++// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3). ++//However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare. ++ "paddw "MANGLE(MM_2)", %%mm5 \n\t" ++ "movq %%mm2, %%mm6 \n\t" ++ ++ "paddw %%mm5, %%mm2 \n\t" ++ "psubw %%mm6, %%mm5 \n\t" ++ ++ "movq %%mm1, %%mm6 \n\t" ++ "paddw %%mm7, %%mm1 \n\t" //d2 ++ ++ "psubw 2*16(%%"REG_d"), %%mm1 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" //d6 ++ ++ "movq 6*16(%%"REG_d"), %%mm7 \n\t" ++ "psraw $2, %%mm5 \n\t" ++ ++ "paddusw 2*16(%%"REG_d"), %%mm1 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" ++ // t7 d2 /t11 t4 t6 - d6 /t10 ++ ++ "paddw 2*16(%%"REG_d"), %%mm1 \n\t" ++ "paddusw %%mm7, %%mm6 \n\t" ++ ++ "psubusw 2*16(%%"REG_d"), %%mm1 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" ++ ++ "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t" ++ "psubusw %%mm7, %%mm6 \n\t" ++ ++ //movq [edi+"DCTSIZE_S"*2*2], mm1 ++ //movq [edi+"DCTSIZE_S"*6*2], mm6 ++ "movq %%mm1, %%mm7 \n\t" ++ "psraw $2, %%mm2 \n\t" ++ ++ "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t" ++ "psubw %%mm6, %%mm1 \n\t" ++ ++ "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" //'t13 ++ ++ "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! --- ++ "movq %%mm2, %%mm7 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t" ++ "paddw %%mm6, %%mm2 \n\t" //'t0 ++ ++ "movq %%mm2, 0*8+%3 \n\t" //! ++ "psubw %%mm6, %%mm7 \n\t" //'t3 ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t" ++ "psubw %%mm6, %%mm1 \n\t" //'t12 ++ ++ "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5 ++ "movq %%mm5, %%mm6 \n\t" ++ ++ "movq %%mm7, 3*8+%3 \n\t" ++ "paddw %%mm2, %%mm3 \n\t" //t10 ++ ++ "paddw %%mm4, %%mm2 \n\t" //t11 ++ "paddw %%mm0, %%mm4 \n\t" //t12 ++ ++ "movq %%mm3, %%mm7 \n\t" ++ "psubw %%mm4, %%mm3 \n\t" ++ ++ "psllw $2, %%mm3 \n\t" ++ "psllw $2, %%mm7 \n\t" //opt for P6 ++ ++ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" ++ "psllw $2, %%mm4 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t" ++ "psllw $2, %%mm2 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" //'t1 ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t" ++ "psubw %%mm1, %%mm6 \n\t" //'t2 ++ // t7 't12 't11 t4 t6 - 't13 't10 --- ++ ++ "paddw %%mm3, %%mm7 \n\t" //z2 ++ ++ "movq %%mm5, 1*8+%3 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" //z4 ++ ++ "movq 3*16(%%"REG_d"), %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ ++ "movq %%mm6, 2*8+%3 \n\t" ++ "psubw %%mm2, %%mm1 \n\t" //z13 ++ ++//=== ++ "paddw %%mm2, %%mm0 \n\t" //z11 ++ "movq %%mm1, %%mm5 \n\t" ++ ++ "movq 5*16(%%"REG_d"), %%mm2 \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //d3 ++ ++ "paddw %%mm7, %%mm5 \n\t" //d5 ++ "psubw %%mm3, %%mm1 \n\t" ++ ++ "movq 1*16(%%"REG_d"), %%mm7 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ ++ "movq %%mm0, %%mm6 \n\t" ++ "paddw %%mm4, %%mm0 \n\t" //d1 ++ ++ "paddusw %%mm3, %%mm1 \n\t" ++ "psubw %%mm4, %%mm6 \n\t" //d7 ++ ++ // d1 d3 - - - d5 d7 - ++ "movq 7*16(%%"REG_d"), %%mm4 \n\t" ++ "psubw %%mm7, %%mm0 \n\t" ++ ++ "psubw %%mm4, %%mm6 \n\t" ++ "paddusw %%mm2, %%mm5 \n\t" ++ ++ "paddusw %%mm4, %%mm6 \n\t" ++ "paddw %%mm3, %%mm1 \n\t" ++ ++ "paddw %%mm2, %%mm5 \n\t" ++ "paddw %%mm4, %%mm6 \n\t" ++ ++ "psubusw %%mm3, %%mm1 \n\t" ++ "psubusw %%mm2, %%mm5 \n\t" ++ ++ "psubusw %%mm4, %%mm6 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ ++ "por %%mm5, %%mm4 \n\t" ++ "paddusw %%mm7, %%mm0 \n\t" ++ ++ "por %%mm6, %%mm4 \n\t" ++ "paddw %%mm7, %%mm0 \n\t" ++ ++ "packssdw %%mm4, %%mm4 \n\t" ++ "psubusw %%mm7, %%mm0 \n\t" ++ ++ "movd %%mm4, %%"REG_a" \n\t" ++ "or %%"REG_a", %%"REG_a" \n\t" ++ "jnz 2f \n\t" ++ //movq [edi+"DCTSIZE_S"*3*2], mm1 ++ //movq [edi+"DCTSIZE_S"*5*2], mm5 ++ //movq [edi+"DCTSIZE_S"*1*2], mm0 ++ //movq [edi+"DCTSIZE_S"*7*2], mm6 ++ // t4 t5 - - - t6 t7 - ++ //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0 ++//Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile ++ "movq 0*8+%3, %%mm4 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6 ++ "movq %%mm1, %%mm2 \n\t" ++ ++ "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t" ++ "movq %%mm2, %%mm3 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5 ++ "paddw %%mm4, %%mm5 \n\t" ++ ++ "movq 1*8+%3, %%mm6 \n\t" ++ //paddw mm3, MM_2 ++ "psraw $2, %%mm3 \n\t" //tmp7 ++ ++ "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4 ++ "psubw %%mm3, %%mm4 \n\t" ++ ++ "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t" ++ "paddw %%mm3, %%mm5 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t" ++ "paddw %%mm6, %%mm7 \n\t" ++ ++ "movq 2*8+%3, %%mm3 \n\t" ++ "psubw %%mm0, %%mm6 \n\t" ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t" ++ "paddw %%mm0, %%mm7 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t" ++ "psubw %%mm1, %%mm3 \n\t" ++ ++ "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ ++ "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t" ++ "paddw %%mm3, %%mm5 \n\t" ++ ++ "movq 3*8+%3, %%mm0 \n\t" ++ "add $8, %%"REG_S" \n\t" ++ ++ "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t" ++ "psubw %%mm2, %%mm0 \n\t" ++ ++ "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t" ++ "paddw %%mm2, %%mm6 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t" ++ "paddw %%mm0, %%mm7 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t" ++ ++ "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t" ++ "add $8, %%"REG_D" \n\t" ++ "jmp 4f \n\t" ++ ++ "2: \n\t" ++ //--- non DC2 ++ //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1) ++ //psraw mm5, 2 ++ //psraw mm0, 2 ++ //psraw mm6, 2 ++ "movq %%mm5, %%mm3 \n\t" ++ "psubw %%mm1, %%mm5 \n\t" ++ ++ "psllw $1, %%mm5 \n\t" //'z10 ++ "paddw %%mm1, %%mm3 \n\t" //'z13 ++ ++ "movq %%mm0, %%mm2 \n\t" ++ "psubw %%mm6, %%mm0 \n\t" ++ ++ "movq %%mm5, %%mm1 \n\t" ++ "psllw $1, %%mm0 \n\t" //'z12 ++ ++ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //- ++ "paddw %%mm0, %%mm5 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5 ++ "paddw %%mm6, %%mm2 \n\t" //'z11 ++ ++ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t" ++ "movq %%mm2, %%mm7 \n\t" ++ ++ //--- ++ "movq 0*8+%3, %%mm4 \n\t" ++ "psubw %%mm3, %%mm2 \n\t" ++ ++ "psllw $1, %%mm2 \n\t" ++ "paddw %%mm3, %%mm7 \n\t" //'t7 ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11 ++ "movq %%mm4, %%mm6 \n\t" ++ //paddw mm7, MM_2 ++ "psraw $2, %%mm7 \n\t" ++ ++ "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" ++ ++ "movq 1*8+%3, %%mm3 \n\t" ++ "paddw %%mm7, %%mm4 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t" ++ "paddw %%mm5, %%mm1 \n\t" //'t12 ++ ++ "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //'t6 ++ ++ "movq 2*8+%3, %%mm7 \n\t" ++ "psubw %%mm5, %%mm0 \n\t" //'t10 ++ ++ "movq 3*8+%3, %%mm6 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ ++ "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t" ++ "psubw %%mm1, %%mm5 \n\t" ++ ++ "psubw %%mm1, %%mm2 \n\t" //'t5 ++ "paddw %%mm1, %%mm3 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t" ++ "movq %%mm7, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t" ++ "psubw %%mm2, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t" ++ "paddw %%mm2, %%mm7 \n\t" ++ ++ "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t" ++ "paddw %%mm2, %%mm0 \n\t" //'t4 ++ ++ // 't4 't6 't5 - - - - 't7 ++ "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t" ++ "movq %%mm6, %%mm1 \n\t" ++ ++ "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t" ++ "psubw %%mm0, %%mm1 \n\t" ++ ++ "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t" ++ "add $8, %%"REG_S" \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t" ++ ++ "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t" ++ "add $8, %%"REG_D" \n\t" ++ ++ "4: \n\t" ++//=part 2 (the same)=========================================================== ++ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm1 \n\t" ++ // ++ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm7 \n\t" ++ "movq %%mm1, %%mm0 \n\t" ++ ++ "paddw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm1 \n\t" //t0 ++ "movq %%mm7, %%mm3 \n\t" ++ ++ "paddw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm7 \n\t" //t3 ++ "movq %%mm1, %%mm5 \n\t" ++ ++ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm6 \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //t13 ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t" ++ "movq %%mm6, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm6 \n\t" //t1 ++ "paddw %%mm7, %%mm5 \n\t" //t10 ++ ++ "paddw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t2 ++ "movq %%mm6, %%mm7 \n\t" ++ ++ "paddw %%mm2, %%mm6 \n\t" //t11 ++ "psubw %%mm2, %%mm7 \n\t" //t12 ++ ++ "movq %%mm5, %%mm2 \n\t" ++ "paddw %%mm6, %%mm5 \n\t" //d0 ++ // i0 t13 t12 i3 i1 d0 - d4 ++ "psubw %%mm6, %%mm2 \n\t" //d4 ++ "paddw %%mm1, %%mm7 \n\t" ++ ++ "movq 1*8+4*16(%%"REG_d"), %%mm6 \n\t" ++ "psllw $2, %%mm7 \n\t" ++ ++ "psubw 1*8+0*16(%%"REG_d"), %%mm5 \n\t" ++ "psubw %%mm6, %%mm2 \n\t" ++ ++ "paddusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t" ++ "paddusw %%mm6, %%mm2 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm7 \n\t" ++ // ++ "paddw 1*8+0*16(%%"REG_d"), %%mm5 \n\t" ++ "paddw %%mm6, %%mm2 \n\t" ++ ++ "psubusw 1*8+0*16(%%"REG_d"), %%mm5 \n\t" ++ "psubusw %%mm6, %%mm2 \n\t" ++ ++//This func is totally compute-bound, operates at huge speed. So, DC shortcut ++// at this place isn't worthwhile due to BTB miss penalty (checked on Pent. 3). ++//However, typical numbers: nondc - 29%%, dc - 46%%, zero - 25%%. All <> 0 case is very rare. ++ "paddw "MANGLE(MM_2)", %%mm5 \n\t" ++ "movq %%mm2, %%mm6 \n\t" ++ ++ "paddw %%mm5, %%mm2 \n\t" ++ "psubw %%mm6, %%mm5 \n\t" ++ ++ "movq %%mm1, %%mm6 \n\t" ++ "paddw %%mm7, %%mm1 \n\t" //d2 ++ ++ "psubw 1*8+2*16(%%"REG_d"), %%mm1 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" //d6 ++ ++ "movq 1*8+6*16(%%"REG_d"), %%mm7 \n\t" ++ "psraw $2, %%mm5 \n\t" ++ ++ "paddusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" ++ // t7 d2 /t11 t4 t6 - d6 /t10 ++ ++ "paddw 1*8+2*16(%%"REG_d"), %%mm1 \n\t" ++ "paddusw %%mm7, %%mm6 \n\t" ++ ++ "psubusw 1*8+2*16(%%"REG_d"), %%mm1 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" ++ ++ "psubw "DCTSIZE_S"*4*2(%%"REG_S"), %%mm3 \n\t" ++ "psubusw %%mm7, %%mm6 \n\t" ++ ++ //movq [edi+"DCTSIZE_S"*2*2], mm1 ++ //movq [edi+"DCTSIZE_S"*6*2], mm6 ++ "movq %%mm1, %%mm7 \n\t" ++ "psraw $2, %%mm2 \n\t" ++ ++ "psubw "DCTSIZE_S"*6*2(%%"REG_S"), %%mm4 \n\t" ++ "psubw %%mm6, %%mm1 \n\t" ++ ++ "psubw "DCTSIZE_S"*7*2(%%"REG_S"), %%mm0 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" //'t13 ++ ++ "psraw $2, %%mm6 \n\t" //paddw mm6, MM_2 !! --- ++ "movq %%mm2, %%mm7 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm1 \n\t" ++ "paddw %%mm6, %%mm2 \n\t" //'t0 ++ ++ "movq %%mm2, 0*8+%3 \n\t" //! ++ "psubw %%mm6, %%mm7 \n\t" //'t3 ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t" ++ "psubw %%mm6, %%mm1 \n\t" //'t12 ++ ++ "psubw "DCTSIZE_S"*5*2(%%"REG_S"), %%mm2 \n\t" //t5 ++ "movq %%mm5, %%mm6 \n\t" ++ ++ "movq %%mm7, 3*8+%3 \n\t" ++ "paddw %%mm2, %%mm3 \n\t" //t10 ++ ++ "paddw %%mm4, %%mm2 \n\t" //t11 ++ "paddw %%mm0, %%mm4 \n\t" //t12 ++ ++ "movq %%mm3, %%mm7 \n\t" ++ "psubw %%mm4, %%mm3 \n\t" ++ ++ "psllw $2, %%mm3 \n\t" ++ "psllw $2, %%mm7 \n\t" //opt for P6 ++ ++ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" ++ "psllw $2, %%mm4 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm7 \n\t" ++ "psllw $2, %%mm2 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm4 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" //'t1 ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm2 \n\t" ++ "psubw %%mm1, %%mm6 \n\t" //'t2 ++ // t7 't12 't11 t4 t6 - 't13 't10 --- ++ ++ "paddw %%mm3, %%mm7 \n\t" //z2 ++ ++ "movq %%mm5, 1*8+%3 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" //z4 ++ ++ "movq 1*8+3*16(%%"REG_d"), %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ ++ "movq %%mm6, 2*8+%3 \n\t" ++ "psubw %%mm2, %%mm1 \n\t" //z13 ++ ++//=== ++ "paddw %%mm2, %%mm0 \n\t" //z11 ++ "movq %%mm1, %%mm5 \n\t" ++ ++ "movq 1*8+5*16(%%"REG_d"), %%mm2 \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //d3 ++ ++ "paddw %%mm7, %%mm5 \n\t" //d5 ++ "psubw %%mm3, %%mm1 \n\t" ++ ++ "movq 1*8+1*16(%%"REG_d"), %%mm7 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ ++ "movq %%mm0, %%mm6 \n\t" ++ "paddw %%mm4, %%mm0 \n\t" //d1 ++ ++ "paddusw %%mm3, %%mm1 \n\t" ++ "psubw %%mm4, %%mm6 \n\t" //d7 ++ ++ // d1 d3 - - - d5 d7 - ++ "movq 1*8+7*16(%%"REG_d"), %%mm4 \n\t" ++ "psubw %%mm7, %%mm0 \n\t" ++ ++ "psubw %%mm4, %%mm6 \n\t" ++ "paddusw %%mm2, %%mm5 \n\t" ++ ++ "paddusw %%mm4, %%mm6 \n\t" ++ "paddw %%mm3, %%mm1 \n\t" ++ ++ "paddw %%mm2, %%mm5 \n\t" ++ "paddw %%mm4, %%mm6 \n\t" ++ ++ "psubusw %%mm3, %%mm1 \n\t" ++ "psubusw %%mm2, %%mm5 \n\t" ++ ++ "psubusw %%mm4, %%mm6 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ ++ "por %%mm5, %%mm4 \n\t" ++ "paddusw %%mm7, %%mm0 \n\t" ++ ++ "por %%mm6, %%mm4 \n\t" ++ "paddw %%mm7, %%mm0 \n\t" ++ ++ "packssdw %%mm4, %%mm4 \n\t" ++ "psubusw %%mm7, %%mm0 \n\t" ++ ++ "movd %%mm4, %%"REG_a" \n\t" ++ "or %%"REG_a", %%"REG_a" \n\t" ++ "jnz 3f \n\t" ++ //movq [edi+"DCTSIZE_S"*3*2], mm1 ++ //movq [edi+"DCTSIZE_S"*5*2], mm5 ++ //movq [edi+"DCTSIZE_S"*1*2], mm0 ++ //movq [edi+"DCTSIZE_S"*7*2], mm6 ++ // t4 t5 - - - t6 t7 - ++ //--- t4 (mm0) may be <>0; mm1, mm5, mm6 == 0 ++//Typical numbers: nondc - 19%%, dc - 26%%, zero - 55%%. zero case alone isn't worthwhile ++ "movq 0*8+%3, %%mm4 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_847759065)", %%mm0 \n\t" //tmp6 ++ "movq %%mm1, %%mm2 \n\t" ++ ++ "movq "DCTSIZE_S"*0*2(%%"REG_D"), %%mm5 \n\t" ++ "movq %%mm2, %%mm3 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_566454497)", %%mm1 \n\t" //tmp5 ++ "paddw %%mm4, %%mm5 \n\t" ++ ++ "movq 1*8+%3, %%mm6 \n\t" ++ //paddw mm3, MM_2 ++ "psraw $2, %%mm3 \n\t" //tmp7 ++ ++ "pmulhw "MANGLE(MM_FIX_0_198912367)", %%mm2 \n\t" //-tmp4 ++ "psubw %%mm3, %%mm4 \n\t" ++ ++ "movq "DCTSIZE_S"*1*2(%%"REG_D"), %%mm7 \n\t" ++ "paddw %%mm3, %%mm5 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*7*2(%%"REG_D") \n\t" ++ "paddw %%mm6, %%mm7 \n\t" ++ ++ "movq 2*8+%3, %%mm3 \n\t" ++ "psubw %%mm0, %%mm6 \n\t" ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_D"), %%mm4 \n\t" ++ "paddw %%mm0, %%mm7 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*0*2(%%"REG_D") \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*6*2(%%"REG_D") \n\t" ++ "psubw %%mm1, %%mm3 \n\t" ++ ++ "movq "DCTSIZE_S"*5*2(%%"REG_D"), %%mm5 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ ++ "movq "DCTSIZE_S"*3*2(%%"REG_D"), %%mm6 \n\t" ++ "paddw %%mm3, %%mm5 \n\t" ++ ++ "movq 3*8+%3, %%mm0 \n\t" ++ "add $24, %%"REG_S" \n\t" ++ ++ "movq %%mm7, "DCTSIZE_S"*1*2(%%"REG_D") \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*2*2(%%"REG_D") \n\t" ++ "psubw %%mm2, %%mm0 \n\t" ++ ++ "movq "DCTSIZE_S"*4*2(%%"REG_D"), %%mm7 \n\t" ++ "paddw %%mm2, %%mm6 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*5*2(%%"REG_D") \n\t" ++ "paddw %%mm0, %%mm7 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*3*2(%%"REG_D") \n\t" ++ ++ "movq %%mm7, "DCTSIZE_S"*4*2(%%"REG_D") \n\t" ++ "add $24, %%"REG_D" \n\t" ++ "sub $2, %%"REG_c" \n\t" ++ "jnz 1b \n\t" ++ "jmp 5f \n\t" ++ ++ "3: \n\t" ++ //--- non DC2 ++ //psraw mm1, 2 w/o it -> offset. thr1, thr1, thr1 (actually thr1, thr1, thr1-1) ++ //psraw mm5, 2 ++ //psraw mm0, 2 ++ //psraw mm6, 2 ++ "movq %%mm5, %%mm3 \n\t" ++ "psubw %%mm1, %%mm5 \n\t" ++ ++ "psllw $1, %%mm5 \n\t" //'z10 ++ "paddw %%mm1, %%mm3 \n\t" //'z13 ++ ++ "movq %%mm0, %%mm2 \n\t" ++ "psubw %%mm6, %%mm0 \n\t" ++ ++ "movq %%mm5, %%mm1 \n\t" ++ "psllw $1, %%mm0 \n\t" //'z12 ++ ++ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm1 \n\t" //- ++ "paddw %%mm0, %%mm5 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm5 \n\t" //'z5 ++ "paddw %%mm6, %%mm2 \n\t" //'z11 ++ ++ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm0 \n\t" ++ "movq %%mm2, %%mm7 \n\t" ++ ++ //--- ++ "movq 0*8+%3, %%mm4 \n\t" ++ "psubw %%mm3, %%mm2 \n\t" ++ ++ "psllw $1, %%mm2 \n\t" ++ "paddw %%mm3, %%mm7 \n\t" //'t7 ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //'t11 ++ "movq %%mm4, %%mm6 \n\t" ++ //paddw mm7, MM_2 ++ "psraw $2, %%mm7 \n\t" ++ ++ "paddw "DCTSIZE_S"*0*2(%%"REG_D"), %%mm4 \n\t" ++ "psubw %%mm7, %%mm6 \n\t" ++ ++ "movq 1*8+%3, %%mm3 \n\t" ++ "paddw %%mm7, %%mm4 \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*7*2(%%"REG_D") \n\t" ++ "paddw %%mm5, %%mm1 \n\t" //'t12 ++ ++ "movq %%mm4, "DCTSIZE_S"*0*2(%%"REG_D") \n\t" ++ "psubw %%mm7, %%mm1 \n\t" //'t6 ++ ++ "movq 2*8+%3, %%mm7 \n\t" ++ "psubw %%mm5, %%mm0 \n\t" //'t10 ++ ++ "movq 3*8+%3, %%mm6 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ ++ "paddw "DCTSIZE_S"*1*2(%%"REG_D"), %%mm3 \n\t" ++ "psubw %%mm1, %%mm5 \n\t" ++ ++ "psubw %%mm1, %%mm2 \n\t" //'t5 ++ "paddw %%mm1, %%mm3 \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*6*2(%%"REG_D") \n\t" ++ "movq %%mm7, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*2*2(%%"REG_D"), %%mm7 \n\t" ++ "psubw %%mm2, %%mm4 \n\t" ++ ++ "paddw "DCTSIZE_S"*5*2(%%"REG_D"), %%mm4 \n\t" ++ "paddw %%mm2, %%mm7 \n\t" ++ ++ "movq %%mm3, "DCTSIZE_S"*1*2(%%"REG_D") \n\t" ++ "paddw %%mm2, %%mm0 \n\t" //'t4 ++ ++ // 't4 't6 't5 - - - - 't7 ++ "movq %%mm7, "DCTSIZE_S"*2*2(%%"REG_D") \n\t" ++ "movq %%mm6, %%mm1 \n\t" ++ ++ "paddw "DCTSIZE_S"*4*2(%%"REG_D"), %%mm6 \n\t" ++ "psubw %%mm0, %%mm1 \n\t" ++ ++ "paddw "DCTSIZE_S"*3*2(%%"REG_D"), %%mm1 \n\t" ++ "paddw %%mm0, %%mm6 \n\t" ++ ++ "movq %%mm4, "DCTSIZE_S"*5*2(%%"REG_D") \n\t" ++ "add $24, %%"REG_S" \n\t" ++ ++ "movq %%mm6, "DCTSIZE_S"*4*2(%%"REG_D") \n\t" ++ ++ "movq %%mm1, "DCTSIZE_S"*3*2(%%"REG_D") \n\t" ++ "add $24, %%"REG_D" \n\t" ++ "sub $2, %%"REG_c" \n\t" ++ "jnz 1b \n\t" ++ "5: \n\t" ++ ++ : "+S"(data), "+D"(output), "+c"(cnt), "=o"(temps) ++ : "d"(thr_adr) ++ : "%"REG_a ++ ); ++} ++ ++#endif // HAVE_MMX ++ ++#if !HAVE_MMX ++ ++static void row_idct_c(DCTELEM* workspace, ++ int16_t* output_adr, int output_stride, int cnt) ++{ ++ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int_simd16_t tmp10, tmp11, tmp12, tmp13; ++ int_simd16_t z5, z10, z11, z12, z13; ++ int16_t* outptr; ++ DCTELEM* wsptr; ++ ++ cnt*=4; ++ wsptr = workspace; ++ outptr = output_adr; ++ for (; cnt > 0; cnt--) { ++ // Even part ++ //Simd version reads 4x4 block and transposes it ++ tmp10 = ( wsptr[2] + wsptr[3]); ++ tmp11 = ( wsptr[2] - wsptr[3]); ++ ++ tmp13 = ( wsptr[0] + wsptr[1]); ++ tmp12 = (MULTIPLY16H( wsptr[0] - wsptr[1], FIX_1_414213562_A)<<2) - tmp13;//this shift order to avoid overflow ++ ++ tmp0 = tmp10 + tmp13; //->temps ++ tmp3 = tmp10 - tmp13; //->temps ++ tmp1 = tmp11 + tmp12; ++ tmp2 = tmp11 - tmp12; ++ ++ // Odd part ++ //Also transpose, with previous: ++ // ---- ---- |||| ++ // ---- ---- idct |||| ++ // ---- ---- ---> |||| ++ // ---- ---- |||| ++ z13 = wsptr[4] + wsptr[5]; ++ z10 = wsptr[4] - wsptr[5]; ++ z11 = wsptr[6] + wsptr[7]; ++ z12 = wsptr[6] - wsptr[7]; ++ ++ tmp7 = z11 + z13; ++ tmp11 = MULTIPLY16H(z11 - z13, FIX_1_414213562); ++ ++ z5 = MULTIPLY16H(z10 + z12, FIX_1_847759065); ++ tmp10 = MULTIPLY16H(z12, FIX_1_082392200) - z5; ++ tmp12 = MULTIPLY16H(z10, FIX_2_613125930) + z5; // - FIX_ ++ ++ tmp6 = (tmp12<<3) - tmp7; ++ tmp5 = (tmp11<<3) - tmp6; ++ tmp4 = (tmp10<<3) + tmp5; ++ ++ // Final output stage: descale and write column ++ outptr[0*output_stride]+= DESCALE(tmp0 + tmp7, 3); ++ outptr[1*output_stride]+= DESCALE(tmp1 + tmp6, 3); ++ outptr[2*output_stride]+= DESCALE(tmp2 + tmp5, 3); ++ outptr[3*output_stride]+= DESCALE(tmp3 - tmp4, 3); ++ outptr[4*output_stride]+= DESCALE(tmp3 + tmp4, 3); ++ outptr[5*output_stride]+= DESCALE(tmp2 - tmp5, 3); ++ outptr[6*output_stride]+= DESCALE(tmp1 - tmp6, 3); //no += ? ++ outptr[7*output_stride]+= DESCALE(tmp0 - tmp7, 3); //no += ? ++ outptr++; ++ ++ wsptr += DCTSIZE; // advance pointer to next row ++ } ++} ++ ++#else /* HAVE_MMX */ ++ ++static void row_idct_mmx (DCTELEM* workspace, ++ int16_t* output_adr, int output_stride, int cnt) ++{ ++ uint64_t __attribute__((aligned(8))) temps[4]; ++ __asm__ volatile( ++ "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t" ++ "1: \n\t" ++ "movq "DCTSIZE_S"*0*2(%%"REG_S"), %%mm0 \n\t" ++ // ++ ++ "movq "DCTSIZE_S"*1*2(%%"REG_S"), %%mm1 \n\t" ++ "movq %%mm0, %%mm4 \n\t" ++ ++ "movq "DCTSIZE_S"*2*2(%%"REG_S"), %%mm2 \n\t" ++ "punpcklwd %%mm1, %%mm0 \n\t" ++ ++ "movq "DCTSIZE_S"*3*2(%%"REG_S"), %%mm3 \n\t" ++ "punpckhwd %%mm1, %%mm4 \n\t" ++ ++ //transpose 4x4 ++ "movq %%mm2, %%mm7 \n\t" ++ "punpcklwd %%mm3, %%mm2 \n\t" ++ ++ "movq %%mm0, %%mm6 \n\t" ++ "punpckldq %%mm2, %%mm0 \n\t" //0 ++ ++ "punpckhdq %%mm2, %%mm6 \n\t" //1 ++ "movq %%mm0, %%mm5 \n\t" ++ ++ "punpckhwd %%mm3, %%mm7 \n\t" ++ "psubw %%mm6, %%mm0 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562_A)", %%mm0 \n\t" ++ "movq %%mm4, %%mm2 \n\t" ++ ++ "punpckldq %%mm7, %%mm4 \n\t" //2 ++ "paddw %%mm6, %%mm5 \n\t" ++ ++ "punpckhdq %%mm7, %%mm2 \n\t" //3 ++ "movq %%mm4, %%mm1 \n\t" ++ ++ "psllw $2, %%mm0 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" //t10 ++ ++ "movq "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_S"), %%mm3 \n\t" ++ "psubw %%mm2, %%mm1 \n\t" //t11 ++ ++ "movq "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_S"), %%mm2 \n\t" ++ "psubw %%mm5, %%mm0 \n\t" ++ ++ "movq %%mm4, %%mm6 \n\t" ++ "paddw %%mm5, %%mm4 \n\t" //t0 ++ ++ "psubw %%mm5, %%mm6 \n\t" //t3 ++ "movq %%mm1, %%mm7 \n\t" ++ ++ "movq "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_S"), %%mm5 \n\t" ++ "paddw %%mm0, %%mm1 \n\t" //t1 ++ ++ "movq %%mm4, 0*8+%3 \n\t" //t0 ++ "movq %%mm3, %%mm4 \n\t" ++ ++ "movq %%mm6, 1*8+%3 \n\t" //t3 ++ "punpcklwd %%mm2, %%mm3 \n\t" ++ ++ //transpose 4x4 ++ "movq "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_S"), %%mm6 \n\t" ++ "punpckhwd %%mm2, %%mm4 \n\t" ++ ++ "movq %%mm5, %%mm2 \n\t" ++ "punpcklwd %%mm6, %%mm5 \n\t" ++ ++ "psubw %%mm0, %%mm7 \n\t" //t2 ++ "punpckhwd %%mm6, %%mm2 \n\t" ++ ++ "movq %%mm3, %%mm0 \n\t" ++ "punpckldq %%mm5, %%mm3 \n\t" //4 ++ ++ "punpckhdq %%mm5, %%mm0 \n\t" //5 ++ "movq %%mm4, %%mm5 \n\t" ++ ++ // ++ "movq %%mm3, %%mm6 \n\t" ++ "punpckldq %%mm2, %%mm4 \n\t" //6 ++ ++ "psubw %%mm0, %%mm3 \n\t" //z10 ++ "punpckhdq %%mm2, %%mm5 \n\t" //7 ++ ++ "paddw %%mm0, %%mm6 \n\t" //z13 ++ "movq %%mm4, %%mm2 \n\t" ++ ++ "movq %%mm3, %%mm0 \n\t" ++ "psubw %%mm5, %%mm4 \n\t" //z12 ++ ++ "pmulhw "MANGLE(MM_FIX_2_613125930)", %%mm0 \n\t" //- ++ "paddw %%mm4, %%mm3 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_847759065)", %%mm3 \n\t" //z5 ++ "paddw %%mm5, %%mm2 \n\t" //z11 > ++ ++ "pmulhw "MANGLE(MM_FIX_1_082392200)", %%mm4 \n\t" ++ "movq %%mm2, %%mm5 \n\t" ++ ++ "psubw %%mm6, %%mm2 \n\t" ++ "paddw %%mm6, %%mm5 \n\t" //t7 ++ ++ "pmulhw "MANGLE(MM_FIX_1_414213562)", %%mm2 \n\t" //t11 ++ "paddw %%mm3, %%mm0 \n\t" //t12 ++ ++ "psllw $3, %%mm0 \n\t" ++ "psubw %%mm3, %%mm4 \n\t" //t10 ++ ++ "movq 0*8+%3, %%mm6 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ ++ "psllw $3, %%mm4 \n\t" ++ "psubw %%mm5, %%mm0 \n\t" //t6 ++ ++ "psllw $3, %%mm2 \n\t" ++ "paddw %%mm0, %%mm1 \n\t" //d1 ++ ++ "psubw %%mm0, %%mm2 \n\t" //t5 ++ "psubw %%mm0, %%mm3 \n\t" //d6 ++ ++ "paddw %%mm2, %%mm4 \n\t" //t4 ++ "movq %%mm7, %%mm0 \n\t" ++ ++ "paddw %%mm2, %%mm7 \n\t" //d2 ++ "psubw %%mm2, %%mm0 \n\t" //d5 ++ ++ "movq "MANGLE(MM_DESCALE_RND)", %%mm2 \n\t" //4 ++ "psubw %%mm5, %%mm6 \n\t" //d7 ++ ++ "paddw 0*8+%3, %%mm5 \n\t" //d0 ++ "paddw %%mm2, %%mm1 \n\t" ++ ++ "paddw %%mm2, %%mm5 \n\t" ++ "psraw $3, %%mm1 \n\t" ++ ++ "paddw %%mm2, %%mm7 \n\t" ++ "psraw $3, %%mm5 \n\t" ++ ++ "paddw (%%"REG_D"), %%mm5 \n\t" ++ "psraw $3, %%mm7 \n\t" ++ ++ "paddw (%%"REG_D",%%"REG_a",), %%mm1 \n\t" ++ "paddw %%mm2, %%mm0 \n\t" ++ ++ "paddw (%%"REG_D",%%"REG_a",2), %%mm7 \n\t" ++ "paddw %%mm2, %%mm3 \n\t" ++ ++ "movq %%mm5, (%%"REG_D") \n\t" ++ "paddw %%mm2, %%mm6 \n\t" ++ ++ "movq %%mm1, (%%"REG_D",%%"REG_a",) \n\t" ++ "psraw $3, %%mm0 \n\t" ++ ++ "movq %%mm7, (%%"REG_D",%%"REG_a",2) \n\t" ++ "add %%"REG_d", %%"REG_D" \n\t" //3*ls ++ ++ "movq 1*8+%3, %%mm5 \n\t" //t3 ++ "psraw $3, %%mm3 \n\t" ++ ++ "paddw (%%"REG_D",%%"REG_a",2), %%mm0 \n\t" ++ "psubw %%mm4, %%mm5 \n\t" //d3 ++ ++ "paddw (%%"REG_D",%%"REG_d",), %%mm3 \n\t" ++ "psraw $3, %%mm6 \n\t" ++ ++ "paddw 1*8+%3, %%mm4 \n\t" //d4 ++ "paddw %%mm2, %%mm5 \n\t" ++ ++ "paddw (%%"REG_D",%%"REG_a",4), %%mm6 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ ++ "movq %%mm0, (%%"REG_D",%%"REG_a",2) \n\t" ++ "psraw $3, %%mm5 \n\t" ++ ++ "paddw (%%"REG_D"), %%mm5 \n\t" ++ "psraw $3, %%mm4 \n\t" ++ ++ "paddw (%%"REG_D",%%"REG_a",), %%mm4 \n\t" ++ "add $"DCTSIZE_S"*2*4, %%"REG_S" \n\t" //4 rows ++ ++ "movq %%mm3, (%%"REG_D",%%"REG_d",) \n\t" ++ "movq %%mm6, (%%"REG_D",%%"REG_a",4) \n\t" ++ "movq %%mm5, (%%"REG_D") \n\t" ++ "movq %%mm4, (%%"REG_D",%%"REG_a",) \n\t" ++ ++ "sub %%"REG_d", %%"REG_D" \n\t" ++ "add $8, %%"REG_D" \n\t" ++ "dec %%"REG_c" \n\t" ++ "jnz 1b \n\t" ++ ++ : "+S"(workspace), "+D"(output_adr), "+c"(cnt), "=o"(temps) ++ : "a"(output_stride*sizeof(short)) ++ : "%"REG_d ++ ); ++} ++ ++#endif // HAVE_MMX ++ ++#if !HAVE_MMX ++ ++static void row_fdct_c(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt) ++{ ++ int_simd16_t tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; ++ int_simd16_t tmp10, tmp11, tmp12, tmp13; ++ int_simd16_t z1, z2, z3, z4, z5, z11, z13; ++ DCTELEM *dataptr; ++ ++ cnt*=4; ++ // Pass 1: process rows. ++ ++ dataptr = data; ++ for (; cnt > 0; cnt--) { ++ tmp0 = pixels[line_size*0] + pixels[line_size*7]; ++ tmp7 = pixels[line_size*0] - pixels[line_size*7]; ++ tmp1 = pixels[line_size*1] + pixels[line_size*6]; ++ tmp6 = pixels[line_size*1] - pixels[line_size*6]; ++ tmp2 = pixels[line_size*2] + pixels[line_size*5]; ++ tmp5 = pixels[line_size*2] - pixels[line_size*5]; ++ tmp3 = pixels[line_size*3] + pixels[line_size*4]; ++ tmp4 = pixels[line_size*3] - pixels[line_size*4]; ++ ++ // Even part ++ ++ tmp10 = tmp0 + tmp3; ++ tmp13 = tmp0 - tmp3; ++ tmp11 = tmp1 + tmp2; ++ tmp12 = tmp1 - tmp2; ++ //Even columns are written first, this leads to different order of columns ++ //in column_fidct(), but they are processed independently, so all ok. ++ //Later in the row_idct() columns readed at the same order. ++ dataptr[2] = tmp10 + tmp11; ++ dataptr[3] = tmp10 - tmp11; ++ ++ z1 = MULTIPLY16H((tmp12 + tmp13)<<2, FIX_0_707106781); ++ dataptr[0] = tmp13 + z1; ++ dataptr[1] = tmp13 - z1; ++ ++ // Odd part ++ ++ tmp10 = (tmp4 + tmp5) <<2; ++ tmp11 = (tmp5 + tmp6) <<2; ++ tmp12 = (tmp6 + tmp7) <<2; ++ ++ z5 = MULTIPLY16H(tmp10 - tmp12, FIX_0_382683433); ++ z2 = MULTIPLY16H(tmp10, FIX_0_541196100) + z5; ++ z4 = MULTIPLY16H(tmp12, FIX_1_306562965) + z5; ++ z3 = MULTIPLY16H(tmp11, FIX_0_707106781); ++ ++ z11 = tmp7 + z3; ++ z13 = tmp7 - z3; ++ ++ dataptr[4] = z13 + z2; ++ dataptr[5] = z13 - z2; ++ dataptr[6] = z11 + z4; ++ dataptr[7] = z11 - z4; ++ ++ pixels++; // advance pointer to next column ++ dataptr += DCTSIZE; ++ } ++} ++ ++#else /* HAVE_MMX */ ++ ++static void row_fdct_mmx(DCTELEM *data, const uint8_t *pixels, int line_size, int cnt) ++{ ++ uint64_t __attribute__((aligned(8))) temps[4]; ++ __asm__ volatile( ++ "lea (%%"REG_a",%%"REG_a",2), %%"REG_d" \n\t" ++ "6: \n\t" ++ "movd (%%"REG_S"), %%mm0 \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ ++ "movd (%%"REG_S",%%"REG_a",), %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ ++ "movd (%%"REG_S",%%"REG_a",2), %%mm2 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ ++ "punpcklbw %%mm7, %%mm2 \n\t" ++ "add %%"REG_d", %%"REG_S" \n\t" ++ ++ "movq %%mm0, %%mm5 \n\t" ++ // ++ ++ "movd (%%"REG_S",%%"REG_a",4), %%mm3 \n\t" //7 ;prefetch! ++ "movq %%mm1, %%mm6 \n\t" ++ ++ "movd (%%"REG_S",%%"REG_d",), %%mm4 \n\t" //6 ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ ++ "psubw %%mm3, %%mm5 \n\t" ++ "punpcklbw %%mm7, %%mm4 \n\t" ++ ++ "paddw %%mm3, %%mm0 \n\t" ++ "psubw %%mm4, %%mm6 \n\t" ++ ++ "movd (%%"REG_S",%%"REG_a",2), %%mm3 \n\t" //5 ++ "paddw %%mm4, %%mm1 \n\t" ++ ++ "movq %%mm5, 0*8+%3 \n\t" //t7 ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ ++ "movq %%mm6, 1*8+%3 \n\t" //t6 ++ "movq %%mm2, %%mm4 \n\t" ++ ++ "movd (%%"REG_S"), %%mm5 \n\t" //3 ++ "paddw %%mm3, %%mm2 \n\t" ++ ++ "movd (%%"REG_S",%%"REG_a",), %%mm6 \n\t" //4 ++ "punpcklbw %%mm7, %%mm5 \n\t" ++ ++ "psubw %%mm3, %%mm4 \n\t" ++ "punpcklbw %%mm7, %%mm6 \n\t" ++ ++ "movq %%mm5, %%mm3 \n\t" ++ "paddw %%mm6, %%mm5 \n\t" //t3 ++ ++ "psubw %%mm6, %%mm3 \n\t" //t4 ; t0 t1 t2 t4 t5 t3 - - ++ "movq %%mm0, %%mm6 \n\t" ++ ++ "movq %%mm1, %%mm7 \n\t" ++ "psubw %%mm5, %%mm0 \n\t" //t13 ++ ++ "psubw %%mm2, %%mm1 \n\t" ++ "paddw %%mm2, %%mm7 \n\t" //t11 ++ ++ "paddw %%mm0, %%mm1 \n\t" ++ "movq %%mm7, %%mm2 \n\t" ++ ++ "psllw $2, %%mm1 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" //t10 ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm1 \n\t" ++ "paddw %%mm6, %%mm7 \n\t" //d2 ++ ++ "psubw %%mm2, %%mm6 \n\t" //d3 ++ "movq %%mm0, %%mm5 \n\t" ++ ++ //transpose 4x4 ++ "movq %%mm7, %%mm2 \n\t" ++ "punpcklwd %%mm6, %%mm7 \n\t" ++ ++ "paddw %%mm1, %%mm0 \n\t" //d0 ++ "punpckhwd %%mm6, %%mm2 \n\t" ++ ++ "psubw %%mm1, %%mm5 \n\t" //d1 ++ "movq %%mm0, %%mm6 \n\t" ++ ++ "movq 1*8+%3, %%mm1 \n\t" ++ "punpcklwd %%mm5, %%mm0 \n\t" ++ ++ "punpckhwd %%mm5, %%mm6 \n\t" ++ "movq %%mm0, %%mm5 \n\t" ++ ++ "punpckldq %%mm7, %%mm0 \n\t" //0 ++ "paddw %%mm4, %%mm3 \n\t" ++ ++ "punpckhdq %%mm7, %%mm5 \n\t" //1 ++ "movq %%mm6, %%mm7 \n\t" ++ ++ "movq %%mm0, "DCTSIZE_S"*0*2(%%"REG_D") \n\t" ++ "punpckldq %%mm2, %%mm6 \n\t" //2 ++ ++ "movq %%mm5, "DCTSIZE_S"*1*2(%%"REG_D") \n\t" ++ "punpckhdq %%mm2, %%mm7 \n\t" //3 ++ ++ "movq %%mm6, "DCTSIZE_S"*2*2(%%"REG_D") \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ ++ "movq %%mm7, "DCTSIZE_S"*3*2(%%"REG_D") \n\t" ++ "psllw $2, %%mm3 \n\t" //t10 ++ ++ "movq 0*8+%3, %%mm2 \n\t" ++ "psllw $2, %%mm4 \n\t" //t11 ++ ++ "pmulhw "MANGLE(MM_FIX_0_707106781)", %%mm4 \n\t" //z3 ++ "paddw %%mm2, %%mm1 \n\t" ++ ++ "psllw $2, %%mm1 \n\t" //t12 ++ "movq %%mm3, %%mm0 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_541196100)", %%mm0 \n\t" ++ "psubw %%mm1, %%mm3 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_0_382683433)", %%mm3 \n\t" //z5 ++ "movq %%mm2, %%mm5 \n\t" ++ ++ "pmulhw "MANGLE(MM_FIX_1_306562965)", %%mm1 \n\t" ++ "psubw %%mm4, %%mm2 \n\t" //z13 ++ ++ "paddw %%mm4, %%mm5 \n\t" //z11 ++ "movq %%mm2, %%mm6 \n\t" ++ ++ "paddw %%mm3, %%mm0 \n\t" //z2 ++ "movq %%mm5, %%mm7 \n\t" ++ ++ "paddw %%mm0, %%mm2 \n\t" //d4 ++ "psubw %%mm0, %%mm6 \n\t" //d5 ++ ++ "movq %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm1 \n\t" //z4 ++ ++ //transpose 4x4 ++ "punpcklwd %%mm6, %%mm2 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" //d6 ++ ++ "punpckhwd %%mm6, %%mm4 \n\t" ++ "psubw %%mm1, %%mm7 \n\t" //d7 ++ ++ "movq %%mm5, %%mm6 \n\t" ++ "punpcklwd %%mm7, %%mm5 \n\t" ++ ++ "punpckhwd %%mm7, %%mm6 \n\t" ++ "movq %%mm2, %%mm7 \n\t" ++ ++ "punpckldq %%mm5, %%mm2 \n\t" //4 ++ "sub %%"REG_d", %%"REG_S" \n\t" ++ ++ "punpckhdq %%mm5, %%mm7 \n\t" //5 ++ "movq %%mm4, %%mm5 \n\t" ++ ++ "movq %%mm2, "DCTSIZE_S"*0*2+"DCTSIZE_S"(%%"REG_D") \n\t" ++ "punpckldq %%mm6, %%mm4 \n\t" //6 ++ ++ "movq %%mm7, "DCTSIZE_S"*1*2+"DCTSIZE_S"(%%"REG_D") \n\t" ++ "punpckhdq %%mm6, %%mm5 \n\t" //7 ++ ++ "movq %%mm4, "DCTSIZE_S"*2*2+"DCTSIZE_S"(%%"REG_D") \n\t" ++ "add $4, %%"REG_S" \n\t" ++ ++ "movq %%mm5, "DCTSIZE_S"*3*2+"DCTSIZE_S"(%%"REG_D") \n\t" ++ "add $"DCTSIZE_S"*2*4, %%"REG_D" \n\t" //4 rows ++ "dec %%"REG_c" \n\t" ++ "jnz 6b \n\t" ++ ++ : "+S"(pixels), "+D"(data), "+c"(cnt), "=o"(temps) ++ : "a"(line_size) ++ : "%"REG_d); ++} ++ ++#endif // HAVE_MMX +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_geq.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_geq.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_geq.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_geq.c 2012-05-14 14:08:54.753348415 +0200 +@@ -0,0 +1,196 @@ ++/* ++ * Copyright (C) 2006 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++ ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libavcodec/avcodec.h" ++#include "libavutil/eval.h" ++ ++struct vf_priv_s { ++ AVExpr * e[3]; ++ int framenum; ++ mp_image_t *mpi; ++}; ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static inline double getpix(struct vf_instance *vf, double x, double y, int plane){ ++ int xi, yi; ++ mp_image_t *mpi= vf->priv->mpi; ++ int stride= mpi->stride[plane]; ++ uint8_t *src= mpi->planes[plane]; ++ xi=x= FFMIN(FFMAX(x, 0), (mpi->w >> (plane ? mpi->chroma_x_shift : 0))-1); ++ yi=y= FFMIN(FFMAX(y, 0), (mpi->h >> (plane ? mpi->chroma_y_shift : 0))-1); ++ ++ x-=xi; ++ y-=yi; ++ ++ return ++ (1-y)*((1-x)*src[xi + yi * stride] + x*src[xi + 1 + yi * stride]) ++ + y *((1-x)*src[xi + (yi+1) * stride] + x*src[xi + 1 + (yi+1) * stride]); ++} ++ ++//FIXME cubic interpolate ++//FIXME keep the last few frames ++static double lum(void *vf, double x, double y){ ++ return getpix(vf, x, y, 0); ++} ++ ++static double cb(void *vf, double x, double y){ ++ return getpix(vf, x, y, 1); ++} ++ ++static double cr(void *vf, double x, double y){ ++ return getpix(vf, x, y, 2); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ int x,y, plane; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->w,mpi->h); ++ } ++ ++ dmpi= vf->dmpi; ++ vf->priv->mpi= mpi; ++ ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++ for(plane=0; plane<3; plane++){ ++ int w= mpi->w >> (plane ? mpi->chroma_x_shift : 0); ++ int h= mpi->h >> (plane ? mpi->chroma_y_shift : 0); ++ uint8_t *dst = dmpi->planes[plane]; ++ int dst_stride= dmpi->stride[plane]; ++ double const_values[]={ ++ M_PI, ++ M_E, ++ 0, ++ 0, ++ w, ++ h, ++ vf->priv->framenum, ++ w/(double)mpi->w, ++ h/(double)mpi->h, ++ 0 ++ }; ++ if (!vf->priv->e[plane]) continue; ++ for(y=0; ypriv->e[plane], ++ const_values, vf); ++ } ++ } ++ } ++ ++ vf->priv->framenum++; ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ av_free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int vf_open(vf_instance_t *vf, char *args){ ++ char eq[3][2000] = { { 0 }, { 0 }, { 0 } }; ++ int plane, res; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++// vf->get_image=get_image; ++ vf->uninit=uninit; ++ vf->priv=av_malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if (args) sscanf(args, "%1999[^:]:%1999[^:]:%1999[^:]", eq[0], eq[1], eq[2]); ++ ++ if (!eq[1][0]) strncpy(eq[1], eq[0], sizeof(eq[0])-1); ++ if (!eq[2][0]) strncpy(eq[2], eq[1], sizeof(eq[0])-1); ++ ++ for(plane=0; plane<3; plane++){ ++ static const char *const_names[]={ ++ "PI", ++ "E", ++ "X", ++ "Y", ++ "W", ++ "H", ++ "N", ++ "SW", ++ "SH", ++ NULL ++ }; ++ static const char *func2_names[]={ ++ "lum", ++ "cb", ++ "cr", ++ "p", ++ NULL ++ }; ++ double (*func2[])(void *, double, double)={ ++ lum, ++ cb, ++ cr, ++ plane==0 ? lum : (plane==1 ? cb : cr), ++ NULL ++ }; ++ res = av_expr_parse(&vf->priv->e[plane], eq[plane], const_names, NULL, NULL, func2_names, func2, 0, NULL); ++ ++ if (res < 0) { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, "geq: error loading equation `%s'\n", eq[plane]); ++ return 0; ++ } ++ } ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_geq = { ++ "generic equation filter", ++ "geq", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf.h 2012-05-14 14:08:54.730347951 +0200 +@@ -0,0 +1,169 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_VF_H ++#define MPLAYER_VF_H ++ ++//#include "m_option.h" ++#include "mp_image.h" ++ ++//extern m_obj_settings_t* vf_settings; ++//extern const m_obj_list_t vf_obj_list; ++ ++struct vf_instance; ++struct vf_priv_s; ++ ++typedef struct vf_info_s { ++ const char *info; ++ const char *name; ++ const char *author; ++ const char *comment; ++ int (*vf_open)(struct vf_instance *vf,char* args); ++ // Ptr to a struct dscribing the options ++ const void* opts; ++} vf_info_t; ++ ++#define NUM_NUMBERED_MPI 50 ++ ++typedef struct vf_image_context_s { ++ mp_image_t* static_images[2]; ++ mp_image_t* temp_images[1]; ++ mp_image_t* export_images[1]; ++ mp_image_t* numbered_images[NUM_NUMBERED_MPI]; ++ int static_idx; ++} vf_image_context_t; ++ ++typedef struct vf_format_context_t { ++ int have_configured; ++ int orig_width, orig_height, orig_fmt; ++} vf_format_context_t; ++ ++typedef struct vf_instance { ++ const vf_info_t* info; ++ // funcs: ++ int (*config)(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt); ++ int (*control)(struct vf_instance *vf, ++ int request, void* data); ++ int (*query_format)(struct vf_instance *vf, ++ unsigned int fmt); ++ void (*get_image)(struct vf_instance *vf, ++ mp_image_t *mpi); ++ int (*put_image)(struct vf_instance *vf, ++ mp_image_t *mpi, double pts); ++ void (*start_slice)(struct vf_instance *vf, ++ mp_image_t *mpi); ++ void (*draw_slice)(struct vf_instance *vf, ++ unsigned char** src, int* stride, int w,int h, int x, int y); ++ void (*uninit)(struct vf_instance *vf); ++ ++ int (*continue_buffered_image)(struct vf_instance *vf); ++ // caps: ++ unsigned int default_caps; // used by default query_format() ++ unsigned int default_reqs; // used by default config() ++ // data: ++ int w, h; ++ vf_image_context_t imgctx; ++ vf_format_context_t fmt; ++ struct vf_instance *next; ++ mp_image_t *dmpi; ++ struct vf_priv_s* priv; ++} vf_instance_t; ++ ++// control codes: ++#include "mpc_info.h" ++ ++typedef struct vf_seteq_s ++{ ++ const char *item; ++ int value; ++} vf_equalizer_t; ++ ++#define VFCTRL_QUERY_MAX_PP_LEVEL 4 /* test for postprocessing support (max level) */ ++#define VFCTRL_SET_PP_LEVEL 5 /* set postprocessing level */ ++#define VFCTRL_SET_EQUALIZER 6 /* set color options (brightness,contrast etc) */ ++#define VFCTRL_GET_EQUALIZER 8 /* gset color options (brightness,contrast etc) */ ++#define VFCTRL_DRAW_OSD 7 ++#define VFCTRL_CHANGE_RECTANGLE 9 /* Change the rectangle boundaries */ ++#define VFCTRL_FLIP_PAGE 10 /* Tell the vo to flip pages */ ++#define VFCTRL_DUPLICATE_FRAME 11 /* For encoding - encode zero-change frame */ ++#define VFCTRL_SKIP_NEXT_FRAME 12 /* For encoding - drop the next frame that passes thru */ ++#define VFCTRL_FLUSH_FRAMES 13 /* For encoding - flush delayed frames */ ++#define VFCTRL_SCREENSHOT 14 /* Make a screenshot */ ++#define VFCTRL_INIT_EOSD 15 /* Select EOSD renderer */ ++#define VFCTRL_DRAW_EOSD 16 /* Render EOSD */ ++#define VFCTRL_GET_PTS 17 /* Return last pts value that reached vf_vo*/ ++#define VFCTRL_SET_DEINTERLACE 18 /* Set deinterlacing status */ ++#define VFCTRL_GET_DEINTERLACE 19 /* Get deinterlacing status */ ++ ++#include "vfcap.h" ++ ++//FIXME this should be in a common header, but i dunno which ++#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly ++ ++ ++// functions: ++void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h); ++mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h); ++ ++vf_instance_t* vf_open_plugin(const vf_info_t* const* filter_list, vf_instance_t* next, const char *name, char **args); ++vf_instance_t* vf_open_filter(vf_instance_t* next, const char *name, char **args); ++vf_instance_t* vf_add_before_vo(vf_instance_t **vf, char *name, char **args); ++vf_instance_t* vf_open_encoder(vf_instance_t* next, const char *name, char *args); ++ ++unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred); ++void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src); ++void vf_queue_frame(vf_instance_t *vf, int (*)(vf_instance_t *)); ++int vf_output_queued_frame(vf_instance_t *vf); ++ ++// default wrappers: ++int vf_next_config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt); ++int vf_next_control(struct vf_instance *vf, int request, void* data); ++void vf_extra_flip(struct vf_instance *vf); ++int vf_next_query_format(struct vf_instance *vf, unsigned int fmt); ++int vf_next_put_image(struct vf_instance *vf,mp_image_t *mpi, double pts); ++void vf_next_draw_slice (struct vf_instance *vf, unsigned char** src, int* stride, int w,int h, int x, int y); ++ ++vf_instance_t* append_filters(vf_instance_t* last); ++ ++void vf_uninit_filter(vf_instance_t* vf); ++void vf_uninit_filter_chain(vf_instance_t* vf); ++ ++int vf_config_wrapper(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt); ++ ++static inline int norm_qscale(int qscale, int type) ++{ ++ switch (type) { ++ case 0: // MPEG-1 ++ return qscale; ++ case 1: // MPEG-2 ++ return qscale >> 1; ++ case 2: // H264 ++ return qscale >> 2; ++ case 3: // VP56 ++ return (63 - qscale + 2) >> 2; ++ } ++ return qscale; ++} ++ ++#endif /* MPLAYER_VF_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_harddup.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_harddup.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_harddup.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_harddup.c 2012-05-14 14:08:54.754348435 +0200 +@@ -0,0 +1,92 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ mp_image_t *last_mpi; ++}; ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ vf->priv->last_mpi = mpi; ++ ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height); ++ ++ dmpi->planes[0] = mpi->planes[0]; ++ dmpi->stride[0] = mpi->stride[0]; ++ if (dmpi->flags&MP_IMGFLAG_PLANAR) { ++ dmpi->planes[1] = mpi->planes[1]; ++ dmpi->stride[1] = mpi->stride[1]; ++ dmpi->planes[2] = mpi->planes[2]; ++ dmpi->stride[2] = mpi->stride[2]; ++ } ++ ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static int control(struct vf_instance *vf, int request, void* data) ++{ ++ switch (request) { ++ case VFCTRL_DUPLICATE_FRAME: ++ if (!vf->priv->last_mpi) break; ++ // This is a huge hack. We assume nothing ++ // has been called earlier in the filter chain ++ // since the last put_image. This is reasonable ++ // because we're handling a duplicate frame! ++ if (put_image(vf, vf->priv->last_mpi, MP_NOPTS_VALUE)) ++ return CONTROL_TRUE; ++ break; ++ } ++ return vf_next_control(vf, request, data); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->put_image = put_image; ++ vf->control = control; ++ vf->uninit = uninit; ++ vf->priv = calloc(1, sizeof(struct vf_priv_s)); ++ return 1; ++} ++ ++const vf_info_t vf_info_harddup = { ++ "resubmit duplicate frames for encoding", ++ "harddup", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_hqdn3d.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_hqdn3d.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_hqdn3d.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_hqdn3d.c 2012-05-14 14:08:54.755348455 +0200 +@@ -0,0 +1,373 @@ ++/* ++ * Copyright (C) 2003 Daniel Moreno ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#define PARAM1_DEFAULT 4.0 ++#define PARAM2_DEFAULT 3.0 ++#define PARAM3_DEFAULT 6.0 ++ ++//===========================================================================// ++ ++struct vf_priv_s { ++ int Coefs[4][512*16]; ++ unsigned int *Line; ++ unsigned short *Frame[3]; ++}; ++ ++ ++/***************************************************************************/ ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv->Line); ++ free(vf->priv->Frame[0]); ++ free(vf->priv->Frame[1]); ++ free(vf->priv->Frame[2]); ++ ++ vf->priv->Line = NULL; ++ vf->priv->Frame[0] = NULL; ++ vf->priv->Frame[1] = NULL; ++ vf->priv->Frame[2] = NULL; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ uninit(vf); ++ vf->priv->Line = malloc(width*sizeof(int)); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static inline unsigned int LowPassMul(unsigned int PrevMul, unsigned int CurrMul, int* Coef){ ++// int dMul= (PrevMul&0xFFFFFF)-(CurrMul&0xFFFFFF); ++ int dMul= PrevMul-CurrMul; ++ unsigned int d=((dMul+0x10007FF)>>12); ++ return CurrMul + Coef[d]; ++} ++ ++static void deNoiseTemporal( ++ unsigned char *Frame, // mpi->planes[x] ++ unsigned char *FrameDest, // dmpi->planes[x] ++ unsigned short *FrameAnt, ++ int W, int H, int sStride, int dStride, ++ int *Temporal) ++{ ++ long X, Y; ++ unsigned int PixelDst; ++ ++ for (Y = 0; Y < H; Y++){ ++ for (X = 0; X < W; X++){ ++ PixelDst = LowPassMul(FrameAnt[X]<<8, Frame[X]<<16, Temporal); ++ FrameAnt[X] = ((PixelDst+0x1000007F)>>8); ++ FrameDest[X]= ((PixelDst+0x10007FFF)>>16); ++ } ++ Frame += sStride; ++ FrameDest += dStride; ++ FrameAnt += W; ++ } ++} ++ ++static void deNoiseSpacial( ++ unsigned char *Frame, // mpi->planes[x] ++ unsigned char *FrameDest, // dmpi->planes[x] ++ unsigned int *LineAnt, // vf->priv->Line (width bytes) ++ int W, int H, int sStride, int dStride, ++ int *Horizontal, int *Vertical) ++{ ++ long X, Y; ++ long sLineOffs = 0, dLineOffs = 0; ++ unsigned int PixelAnt; ++ unsigned int PixelDst; ++ ++ /* First pixel has no left nor top neighbor. */ ++ PixelDst = LineAnt[0] = PixelAnt = Frame[0]<<16; ++ FrameDest[0]= ((PixelDst+0x10007FFF)>>16); ++ ++ /* First line has no top neighbor, only left. */ ++ for (X = 1; X < W; X++){ ++ PixelDst = LineAnt[X] = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal); ++ FrameDest[X]= ((PixelDst+0x10007FFF)>>16); ++ } ++ ++ for (Y = 1; Y < H; Y++){ ++ unsigned int PixelAnt; ++ sLineOffs += sStride, dLineOffs += dStride; ++ /* First pixel on each line doesn't have previous pixel */ ++ PixelAnt = Frame[sLineOffs]<<16; ++ PixelDst = LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical); ++ FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16); ++ ++ for (X = 1; X < W; X++){ ++ unsigned int PixelDst; ++ /* The rest are normal */ ++ PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal); ++ PixelDst = LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical); ++ FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16); ++ } ++ } ++} ++ ++static void deNoise(unsigned char *Frame, // mpi->planes[x] ++ unsigned char *FrameDest, // dmpi->planes[x] ++ unsigned int *LineAnt, // vf->priv->Line (width bytes) ++ unsigned short **FrameAntPtr, ++ int W, int H, int sStride, int dStride, ++ int *Horizontal, int *Vertical, int *Temporal) ++{ ++ long X, Y; ++ long sLineOffs = 0, dLineOffs = 0; ++ unsigned int PixelAnt; ++ unsigned int PixelDst; ++ unsigned short* FrameAnt=(*FrameAntPtr); ++ ++ if(!FrameAnt){ ++ (*FrameAntPtr)=FrameAnt=malloc(W*H*sizeof(unsigned short)); ++ for (Y = 0; Y < H; Y++){ ++ unsigned short* dst=&FrameAnt[Y*W]; ++ unsigned char* src=Frame+Y*sStride; ++ for (X = 0; X < W; X++) dst[X]=src[X]<<8; ++ } ++ } ++ ++ if(!Horizontal[0] && !Vertical[0]){ ++ deNoiseTemporal(Frame, FrameDest, FrameAnt, ++ W, H, sStride, dStride, Temporal); ++ return; ++ } ++ if(!Temporal[0]){ ++ deNoiseSpacial(Frame, FrameDest, LineAnt, ++ W, H, sStride, dStride, Horizontal, Vertical); ++ return; ++ } ++ ++ /* First pixel has no left nor top neighbor. Only previous frame */ ++ LineAnt[0] = PixelAnt = Frame[0]<<16; ++ PixelDst = LowPassMul(FrameAnt[0]<<8, PixelAnt, Temporal); ++ FrameAnt[0] = ((PixelDst+0x1000007F)>>8); ++ FrameDest[0]= ((PixelDst+0x10007FFF)>>16); ++ ++ /* First line has no top neighbor. Only left one for each pixel and ++ * last frame */ ++ for (X = 1; X < W; X++){ ++ LineAnt[X] = PixelAnt = LowPassMul(PixelAnt, Frame[X]<<16, Horizontal); ++ PixelDst = LowPassMul(FrameAnt[X]<<8, PixelAnt, Temporal); ++ FrameAnt[X] = ((PixelDst+0x1000007F)>>8); ++ FrameDest[X]= ((PixelDst+0x10007FFF)>>16); ++ } ++ ++ for (Y = 1; Y < H; Y++){ ++ unsigned int PixelAnt; ++ unsigned short* LinePrev=&FrameAnt[Y*W]; ++ sLineOffs += sStride, dLineOffs += dStride; ++ /* First pixel on each line doesn't have previous pixel */ ++ PixelAnt = Frame[sLineOffs]<<16; ++ LineAnt[0] = LowPassMul(LineAnt[0], PixelAnt, Vertical); ++ PixelDst = LowPassMul(LinePrev[0]<<8, LineAnt[0], Temporal); ++ LinePrev[0] = ((PixelDst+0x1000007F)>>8); ++ FrameDest[dLineOffs]= ((PixelDst+0x10007FFF)>>16); ++ ++ for (X = 1; X < W; X++){ ++ unsigned int PixelDst; ++ /* The rest are normal */ ++ PixelAnt = LowPassMul(PixelAnt, Frame[sLineOffs+X]<<16, Horizontal); ++ LineAnt[X] = LowPassMul(LineAnt[X], PixelAnt, Vertical); ++ PixelDst = LowPassMul(LinePrev[X]<<8, LineAnt[X], Temporal); ++ LinePrev[X] = ((PixelDst+0x1000007F)>>8); ++ FrameDest[dLineOffs+X]= ((PixelDst+0x10007FFF)>>16); ++ } ++ } ++} ++ ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ int W = mpi->w, H = mpi->h; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ ++ if(!dmpi) return 0; ++ ++ deNoise(mpi->planes[0], dmpi->planes[0], ++ vf->priv->Line, &vf->priv->Frame[0], W, H, ++ mpi->stride[0], dmpi->stride[0], ++ vf->priv->Coefs[0], ++ vf->priv->Coefs[0], ++ vf->priv->Coefs[1]); ++ deNoise(mpi->planes[1], dmpi->planes[1], ++ vf->priv->Line, &vf->priv->Frame[1], cw, ch, ++ mpi->stride[1], dmpi->stride[1], ++ vf->priv->Coefs[2], ++ vf->priv->Coefs[2], ++ vf->priv->Coefs[3]); ++ deNoise(mpi->planes[2], dmpi->planes[2], ++ vf->priv->Line, &vf->priv->Frame[2], cw, ch, ++ mpi->stride[2], dmpi->stride[2], ++ vf->priv->Coefs[2], ++ vf->priv->Coefs[2], ++ vf->priv->Coefs[3]); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++ ++#define ABS(A) ( (A) > 0 ? (A) : -(A) ) ++ ++static void PrecalcCoefs(int *Ct, double Dist25) ++{ ++ int i; ++ double Gamma, Simil, C; ++ ++ Gamma = log(0.25) / log(1.0 - Dist25/255.0 - 0.00001); ++ ++ for (i = -255*16; i <= 255*16; i++) ++ { ++ Simil = 1.0 - ABS(i) / (16*255.0); ++ C = pow(Simil, Gamma) * 65536.0 * (double)i / 16.0; ++ Ct[16*256+i] = (C<0) ? (C-0.5) : (C+0.5); ++ } ++ ++ Ct[0] = (Dist25 != 0); ++} ++ ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ double LumSpac, LumTmp, ChromSpac, ChromTmp; ++ double Param1, Param2, Param3, Param4; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if (args) ++ { ++ switch(sscanf(args, "%lf:%lf:%lf:%lf", ++ &Param1, &Param2, &Param3, &Param4 ++ )) ++ { ++ case 0: ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 1: ++ LumSpac = Param1; ++ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 2: ++ LumSpac = Param1; ++ LumTmp = PARAM3_DEFAULT * Param1 / PARAM1_DEFAULT; ++ ++ ChromSpac = Param2; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 3: ++ LumSpac = Param1; ++ LumTmp = Param3; ++ ++ ChromSpac = Param2; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ break; ++ ++ case 4: ++ LumSpac = Param1; ++ LumTmp = Param3; ++ ++ ChromSpac = Param2; ++ ChromTmp = Param4; ++ break; ++ ++ default: ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ } ++ } ++ else ++ { ++ LumSpac = PARAM1_DEFAULT; ++ LumTmp = PARAM3_DEFAULT; ++ ++ ChromSpac = PARAM2_DEFAULT; ++ ChromTmp = LumTmp * ChromSpac / LumSpac; ++ } ++ ++ PrecalcCoefs(vf->priv->Coefs[0], LumSpac); ++ PrecalcCoefs(vf->priv->Coefs[1], LumTmp); ++ PrecalcCoefs(vf->priv->Coefs[2], ChromSpac); ++ PrecalcCoefs(vf->priv->Coefs[3], ChromTmp); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_hqdn3d = { ++ "High Quality 3D Denoiser", ++ "hqdn3d", ++ "Daniel Moreno & A'rpi", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_hue.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_hue.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_hue.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_hue.c 2012-05-14 14:08:54.756348475 +0200 +@@ -0,0 +1,181 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/video_out.h" ++ ++struct vf_priv_s { ++ uint8_t *buf[2]; ++ float hue; ++ float saturation; ++}; ++ ++static void process_C(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride, ++ int w, int h, float hue, float sat) ++{ ++ int i; ++ const int s= rint(sin(hue) * (1<<16) * sat); ++ const int c= rint(cos(hue) * (1<<16) * sat); ++ ++ while (h--) { ++ for (i = 0; i>16; ++ int new_v= (s*u + c*v + (1<<15) + (128<<16))>>16; ++ if(new_u & 768) new_u= (-new_u)>>31; ++ if(new_v & 768) new_v= (-new_v)>>31; ++ udst[i]= new_u; ++ vdst[i]= new_v; ++ } ++ usrc += srcstride; ++ vsrc += srcstride; ++ udst += dststride; ++ vdst += dststride; ++ } ++} ++ ++static void (*process)(uint8_t *udst, uint8_t *vdst, uint8_t *usrc, uint8_t *vsrc, int dststride, int srcstride, ++ int w, int h, float hue, float sat); ++ ++/* FIXME: add packed yuv version of process */ ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, ++ mpi->w, mpi->h); ++ ++ dmpi->planes[0] = mpi->planes[0]; ++ dmpi->stride[0] = mpi->stride[0]; ++ dmpi->stride[1] = mpi->stride[1]; ++ dmpi->stride[2] = mpi->stride[2]; ++ ++ if (!vf->priv->buf[0]){ ++ vf->priv->buf[0] = malloc(mpi->stride[1]*mpi->h >> mpi->chroma_y_shift); ++ vf->priv->buf[1] = malloc(mpi->stride[2]*mpi->h >> mpi->chroma_y_shift); ++ } ++ ++ if (vf->priv->hue == 0 && vf->priv->saturation == 1){ ++ dmpi->planes[1] = mpi->planes[1]; ++ dmpi->planes[2] = mpi->planes[2]; ++ }else { ++ dmpi->planes[1] = vf->priv->buf[0]; ++ dmpi->planes[2] = vf->priv->buf[1]; ++ process(dmpi->planes[1], dmpi->planes[2], ++ mpi->planes[1], mpi->planes[2], ++ dmpi->stride[1],mpi->stride[1], ++ mpi->w>> mpi->chroma_x_shift, mpi->h>> mpi->chroma_y_shift, ++ vf->priv->hue, vf->priv->saturation); ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static int control(struct vf_instance *vf, int request, void* data) ++{ ++ vf_equalizer_t *eq; ++ ++ switch (request) { ++ case VFCTRL_SET_EQUALIZER: ++ eq = data; ++ if (!strcmp(eq->item,"hue")) { ++ vf->priv->hue = eq->value * M_PI / 100; ++ return CONTROL_TRUE; ++ } else if (!strcmp(eq->item,"saturation")) { ++ vf->priv->saturation = (eq->value + 100)/100.0; ++ return CONTROL_TRUE; ++ } ++ break; ++ case VFCTRL_GET_EQUALIZER: ++ eq = data; ++ if (!strcmp(eq->item,"hue")) { ++ eq->value = rint(vf->priv->hue *100 / M_PI); ++ return CONTROL_TRUE; ++ }else if (!strcmp(eq->item,"saturation")) { ++ eq->value = rint(vf->priv->saturation*100 - 100); ++ return CONTROL_TRUE; ++ } ++ break; ++ } ++ return vf_next_control(vf, request, data); ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch (fmt) { ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv->buf[0]); ++ free(vf->priv->buf[1]); ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->control=control; ++ vf->query_format=query_format; ++ vf->put_image=put_image; ++ vf->uninit=uninit; ++ ++ vf->priv = malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ sscanf(args, "%f:%f", &vf->priv->hue, &vf->priv->saturation); ++ vf->priv->hue *= M_PI / 180.0; ++ ++ process = process_C; ++ return 1; ++} ++ ++const vf_info_t vf_info_hue = { ++ "hue changer", ++ "hue", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_il.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_il.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_il.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_il.c 2012-05-14 14:08:54.756348475 +0200 +@@ -0,0 +1,148 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++ ++ ++//===========================================================================// ++ ++typedef struct FilterParam{ ++ int interleave; ++ int swap; ++}FilterParam; ++ ++struct vf_priv_s { ++ FilterParam lumaParam; ++ FilterParam chromaParam; ++}; ++ ++/***************************************************************************/ ++ ++static void interleave(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, int interleave, int swap){ ++ const int a= swap; ++ const int b= 1-a; ++ const int m= h>>1; ++ int y; ++ ++ switch(interleave){ ++ case -1: ++ for(y=0; y < m; y++){ ++ fast_memcpy(dst + dstStride* y , src + srcStride*(y*2 + a), w); ++ fast_memcpy(dst + dstStride*(y + m), src + srcStride*(y*2 + b), w); ++ } ++ break; ++ case 0: ++ for(y=0; y < m; y++){ ++ fast_memcpy(dst + dstStride* y*2 , src + srcStride*(y*2 + a), w); ++ fast_memcpy(dst + dstStride*(y*2+1), src + srcStride*(y*2 + b), w); ++ } ++ break; ++ case 1: ++ for(y=0; y < m; y++){ ++ fast_memcpy(dst + dstStride*(y*2+a), src + srcStride* y , w); ++ fast_memcpy(dst + dstStride*(y*2+b), src + srcStride*(y + m), w); ++ } ++ break; ++ } ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int w; ++ FilterParam *luma = &vf->priv->lumaParam; ++ FilterParam *chroma= &vf->priv->chromaParam; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ ++ if(mpi->flags&MP_IMGFLAG_PLANAR) ++ w= mpi->w; ++ else ++ w= mpi->w * mpi->bpp/8; ++ ++ interleave(dmpi->planes[0], mpi->planes[0], ++ w, mpi->h, dmpi->stride[0], mpi->stride[0], luma->interleave, luma->swap); ++ ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ ++ interleave(dmpi->planes[1], mpi->planes[1], cw,ch, ++ dmpi->stride[1], mpi->stride[1], chroma->interleave, luma->swap); ++ interleave(dmpi->planes[2], mpi->planes[2], cw,ch, ++ dmpi->stride[2], mpi->stride[2], chroma->interleave, luma->swap); ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static void parse(FilterParam *fp, char* args){ ++ char *pos; ++ char *max= strchr(args, ':'); ++ ++ if(!max) max= args + strlen(args); ++ ++ pos= strchr(args, 's'); ++ if(pos && posswap=1; ++ pos= strchr(args, 'i'); ++ if(pos && posinterleave=1; ++ pos= strchr(args, 'd'); ++ if(pos && posinterleave=-1; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ ++ vf->put_image=put_image; ++// vf->get_image=get_image; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if(args) ++ { ++ char *arg2= strchr(args,':'); ++ if(arg2) parse(&vf->priv->chromaParam, arg2+1); ++ parse(&vf->priv->lumaParam, args); ++ } ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_il = { ++ "(de)interleave", ++ "il", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ilpack.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ilpack.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ilpack.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ilpack.c 2012-05-14 14:08:54.758348515 +0200 +@@ -0,0 +1,456 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libavutil/attributes.h" ++ ++typedef void (pack_func_t)(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, int us, int vs); ++ ++struct vf_priv_s { ++ int mode; ++ pack_func_t *pack[2]; ++}; ++ ++static void pack_nn_C(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, ++ int av_unused us, int av_unused vs) ++{ ++ int j; ++ for (j = w/2; j; j--) { ++ *dst++ = *y++; ++ *dst++ = *u++; ++ *dst++ = *y++; ++ *dst++ = *v++; ++ } ++} ++ ++static void pack_li_0_C(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, int us, int vs) ++{ ++ int j; ++ for (j = w/2; j; j--) { ++ *dst++ = *y++; ++ *dst++ = (u[us+us] + 7*u[0])>>3; ++ *dst++ = *y++; ++ *dst++ = (v[vs+vs] + 7*v[0])>>3; ++ u++; v++; ++ } ++} ++ ++static void pack_li_1_C(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, int us, int vs) ++{ ++ int j; ++ for (j = w/2; j; j--) { ++ *dst++ = *y++; ++ *dst++ = (3*u[us+us] + 5*u[0])>>3; ++ *dst++ = *y++; ++ *dst++ = (3*v[vs+vs] + 5*v[0])>>3; ++ u++; v++; ++ } ++} ++ ++#if HAVE_MMX ++static void pack_nn_MMX(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, ++ int av_unused us, int av_unused vs) ++{ ++ __asm__ volatile ("" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%0), %%mm1 \n\t" ++ "movq (%0), %%mm2 \n\t" ++ "movq (%1), %%mm4 \n\t" ++ "movq (%2), %%mm6 \n\t" ++ "punpcklbw %%mm6, %%mm4 \n\t" ++ "punpcklbw %%mm4, %%mm1 \n\t" ++ "punpckhbw %%mm4, %%mm2 \n\t" ++ ++ "add $8, %0 \n\t" ++ "add $4, %1 \n\t" ++ "add $4, %2 \n\t" ++ "movq %%mm1, (%3) \n\t" ++ "movq %%mm2, 8(%3) \n\t" ++ "add $16, %3 \n\t" ++ "decl %4 \n\t" ++ "jnz 1b \n\t" ++ "emms \n\t" ++ : ++ : "r" (y), "r" (u), "r" (v), "r" (dst), "r" (w/8) ++ : "memory" ++ ); ++ pack_nn_C(dst, y, u, v, (w&7), 0, 0); ++} ++ ++#if HAVE_EBX_AVAILABLE ++static void pack_li_0_MMX(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, int us, int vs) ++{ ++ __asm__ volatile ("" ++ "push %%"REG_BP" \n\t" ++#if ARCH_X86_64 ++ "mov %6, %%"REG_BP" \n\t" ++#else ++ "movl 4(%%"REG_d"), %%"REG_BP" \n\t" ++ "movl (%%"REG_d"), %%"REG_d" \n\t" ++#endif ++ "pxor %%mm0, %%mm0 \n\t" ++ ++ ASMALIGN(4) ++ ".Lli0: \n\t" ++ "movq (%%"REG_S"), %%mm1 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ ++ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t" ++ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t" ++ "punpcklbw %%mm0, %%mm4 \n\t" ++ "punpcklbw %%mm0, %%mm6 \n\t" ++ "movq (%%"REG_a"), %%mm3 \n\t" ++ "movq (%%"REG_b"), %%mm5 \n\t" ++ "punpcklbw %%mm0, %%mm3 \n\t" ++ "punpcklbw %%mm0, %%mm5 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "psrlw $3, %%mm4 \n\t" ++ "psrlw $3, %%mm6 \n\t" ++ "packuswb %%mm4, %%mm4 \n\t" ++ "packuswb %%mm6, %%mm6 \n\t" ++ "punpcklbw %%mm6, %%mm4 \n\t" ++ "punpcklbw %%mm4, %%mm1 \n\t" ++ "punpckhbw %%mm4, %%mm2 \n\t" ++ ++ "movq %%mm1, (%%"REG_D") \n\t" ++ "movq %%mm2, 8(%%"REG_D") \n\t" ++ ++ "movq 8(%%"REG_S"), %%mm1 \n\t" ++ "movq 8(%%"REG_S"), %%mm2 \n\t" ++ ++ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t" ++ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t" ++ "punpckhbw %%mm0, %%mm4 \n\t" ++ "punpckhbw %%mm0, %%mm6 \n\t" ++ "movq (%%"REG_a"), %%mm3 \n\t" ++ "movq (%%"REG_b"), %%mm5 \n\t" ++ "punpckhbw %%mm0, %%mm3 \n\t" ++ "punpckhbw %%mm0, %%mm5 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "psrlw $3, %%mm4 \n\t" ++ "psrlw $3, %%mm6 \n\t" ++ "packuswb %%mm4, %%mm4 \n\t" ++ "packuswb %%mm6, %%mm6 \n\t" ++ "punpcklbw %%mm6, %%mm4 \n\t" ++ "punpcklbw %%mm4, %%mm1 \n\t" ++ "punpckhbw %%mm4, %%mm2 \n\t" ++ ++ "add $16, %%"REG_S" \n\t" ++ "add $8, %%"REG_a" \n\t" ++ "add $8, %%"REG_b" \n\t" ++ ++ "movq %%mm1, 16(%%"REG_D") \n\t" ++ "movq %%mm2, 24(%%"REG_D") \n\t" ++ "add $32, %%"REG_D" \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz .Lli0 \n\t" ++ "emms \n\t" ++ "pop %%"REG_BP" \n\t" ++ : ++ : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16), ++#if ARCH_X86_64 ++ "d" ((x86_reg)us), "r" ((x86_reg)vs) ++#else ++ "d" (&us) ++#endif ++ : "memory" ++ ); ++ pack_li_0_C(dst, y, u, v, (w&15), us, vs); ++} ++ ++static void pack_li_1_MMX(unsigned char *dst, unsigned char *y, ++ unsigned char *u, unsigned char *v, int w, int us, int vs) ++{ ++ __asm__ volatile ("" ++ "push %%"REG_BP" \n\t" ++#if ARCH_X86_64 ++ "mov %6, %%"REG_BP" \n\t" ++#else ++ "movl 4(%%"REG_d"), %%"REG_BP" \n\t" ++ "movl (%%"REG_d"), %%"REG_d" \n\t" ++#endif ++ "pxor %%mm0, %%mm0 \n\t" ++ ++ ASMALIGN(4) ++ ".Lli1: \n\t" ++ "movq (%%"REG_S"), %%mm1 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ ++ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t" ++ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t" ++ "punpcklbw %%mm0, %%mm4 \n\t" ++ "punpcklbw %%mm0, %%mm6 \n\t" ++ "movq (%%"REG_a"), %%mm3 \n\t" ++ "movq (%%"REG_b"), %%mm5 \n\t" ++ "punpcklbw %%mm0, %%mm3 \n\t" ++ "punpcklbw %%mm0, %%mm5 \n\t" ++ "movq %%mm4, %%mm7 \n\t" ++ "paddw %%mm4, %%mm4 \n\t" ++ "paddw %%mm7, %%mm4 \n\t" ++ "movq %%mm6, %%mm7 \n\t" ++ "paddw %%mm6, %%mm6 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "psrlw $3, %%mm4 \n\t" ++ "psrlw $3, %%mm6 \n\t" ++ "packuswb %%mm4, %%mm4 \n\t" ++ "packuswb %%mm6, %%mm6 \n\t" ++ "punpcklbw %%mm6, %%mm4 \n\t" ++ "punpcklbw %%mm4, %%mm1 \n\t" ++ "punpckhbw %%mm4, %%mm2 \n\t" ++ ++ "movq %%mm1, (%%"REG_D") \n\t" ++ "movq %%mm2, 8(%%"REG_D") \n\t" ++ ++ "movq 8(%%"REG_S"), %%mm1 \n\t" ++ "movq 8(%%"REG_S"), %%mm2 \n\t" ++ ++ "movq (%%"REG_a",%%"REG_d",2), %%mm4 \n\t" ++ "movq (%%"REG_b",%%"REG_BP",2), %%mm6 \n\t" ++ "punpckhbw %%mm0, %%mm4 \n\t" ++ "punpckhbw %%mm0, %%mm6 \n\t" ++ "movq (%%"REG_a"), %%mm3 \n\t" ++ "movq (%%"REG_b"), %%mm5 \n\t" ++ "punpckhbw %%mm0, %%mm3 \n\t" ++ "punpckhbw %%mm0, %%mm5 \n\t" ++ "movq %%mm4, %%mm7 \n\t" ++ "paddw %%mm4, %%mm4 \n\t" ++ "paddw %%mm7, %%mm4 \n\t" ++ "movq %%mm6, %%mm7 \n\t" ++ "paddw %%mm6, %%mm6 \n\t" ++ "paddw %%mm7, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ "paddw %%mm5, %%mm6 \n\t" ++ "psrlw $3, %%mm4 \n\t" ++ "psrlw $3, %%mm6 \n\t" ++ "packuswb %%mm4, %%mm4 \n\t" ++ "packuswb %%mm6, %%mm6 \n\t" ++ "punpcklbw %%mm6, %%mm4 \n\t" ++ "punpcklbw %%mm4, %%mm1 \n\t" ++ "punpckhbw %%mm4, %%mm2 \n\t" ++ ++ "add $16, %%"REG_S" \n\t" ++ "add $8, %%"REG_a" \n\t" ++ "add $8, %%"REG_b" \n\t" ++ ++ "movq %%mm1, 16(%%"REG_D") \n\t" ++ "movq %%mm2, 24(%%"REG_D") \n\t" ++ "add $32, %%"REG_D" \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz .Lli1 \n\t" ++ "emms \n\t" ++ "pop %%"REG_BP" \n\t" ++ : ++ : "S" (y), "D" (dst), "a" (u), "b" (v), "c" (w/16), ++#if ARCH_X86_64 ++ "d" ((x86_reg)us), "r" ((x86_reg)vs) ++#else ++ "d" (&us) ++#endif ++ : "memory" ++ ); ++ pack_li_1_C(dst, y, u, v, (w&15), us, vs); ++} ++#endif /* HAVE_EBX_AVAILABLE */ ++#endif ++ ++static pack_func_t *pack_nn; ++static pack_func_t *pack_li_0; ++static pack_func_t *pack_li_1; ++ ++static void ilpack(unsigned char *dst, unsigned char *src[3], ++ int dststride, int srcstride[3], int w, int h, pack_func_t *pack[2]) ++{ ++ int i; ++ unsigned char *y, *u, *v; ++ int ys = srcstride[0], us = srcstride[1], vs = srcstride[2]; ++ int a, b; ++ ++ y = src[0]; ++ u = src[1]; ++ v = src[2]; ++ ++ pack_nn(dst, y, u, v, w, 0, 0); ++ y += ys; dst += dststride; ++ pack_nn(dst, y, u+us, v+vs, w, 0, 0); ++ y += ys; dst += dststride; ++ for (i=2; i>1); ++ pack[b](dst, y, u, v, w, us*a, vs*a); ++ y += ys; ++ if ((i&3) == 1) { ++ u -= us; ++ v -= vs; ++ } else { ++ u += us; ++ v += vs; ++ } ++ dst += dststride; ++ } ++ pack_nn(dst, y, u, v, w, 0, 0); ++ y += ys; dst += dststride; u += us; v += vs; ++ pack_nn(dst, y, u, v, w, 0, 0); ++} ++ ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next, IMGFMT_YUY2, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w, mpi->h); ++ ++ ilpack(dmpi->planes[0], mpi->planes, dmpi->stride[0], mpi->stride, mpi->w, mpi->h, vf->priv->pack); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ /* FIXME - also support UYVY output? */ ++ return vf_next_config(vf, width, height, d_width, d_height, flags, IMGFMT_YUY2); ++} ++ ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - really any YUV 4:2:0 input format should work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf,IMGFMT_YUY2); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->config=config; ++ vf->query_format=query_format; ++ vf->put_image=put_image; ++ vf->priv = calloc(1, sizeof(struct vf_priv_s)); ++ vf->priv->mode = 1; ++ if (args) sscanf(args, "%d", &vf->priv->mode); ++ ++ pack_nn = pack_nn_C; ++ pack_li_0 = pack_li_0_C; ++ pack_li_1 = pack_li_1_C; ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) { ++ pack_nn = pack_nn_MMX; ++#if HAVE_EBX_AVAILABLE ++ pack_li_0 = pack_li_0_MMX; ++ pack_li_1 = pack_li_1_MMX; ++#endif ++ } ++#endif ++ ++ switch(vf->priv->mode) { ++ case 0: ++ vf->priv->pack[0] = vf->priv->pack[1] = pack_nn; ++ break; ++ default: ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "ilpack: unknown mode %d (fallback to linear)\n", ++ vf->priv->mode); ++ case 1: ++ vf->priv->pack[0] = pack_li_0; ++ vf->priv->pack[1] = pack_li_1; ++ break; ++ } ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_ilpack = { ++ "4:2:0 planar -> 4:2:2 packed reinterlacer", ++ "ilpack", ++ "Richard Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ivtc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ivtc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ivtc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ivtc.c 2012-05-14 14:08:54.759348535 +0200 +@@ -0,0 +1,550 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++ ++struct metrics { ++ /* difference: total, even lines, odd lines */ ++ int d, e, o; ++ /* noise: temporal, spacial (current), spacial (past) */ ++ int t, s, p; ++}; ++ ++struct frameinfo { ++ /* peak, relative, mean */ ++ struct metrics p, r, m; ++}; ++ ++struct vf_priv_s { ++ struct frameinfo fi[2]; ++ mp_image_t *dmpi; ++ int first; ++ int drop, lastdrop, dropnext; ++ int inframes, outframes; ++}; ++ ++enum { ++ F_DROP, ++ F_MERGE, ++ F_NEXT, ++ F_SHOW ++}; ++ ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++static void block_diffs_MMX(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns) ++{ ++ int i; ++ short out[24]; // output buffer for the partial metrics from the mmx code ++ ++ __asm__ ( ++ "movl $4, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" // 4 even difference sums ++ "pxor %%mm5, %%mm5 \n\t" // 4 odd difference sums ++ "pxor %%mm7, %%mm7 \n\t" // all zeros ++ ++ ASMALIGN(4) ++ "1: \n\t" ++ ++ // Even difference ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm4 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm2, %%mm4 \n\t" ++ "paddw %%mm3, %%mm4 \n\t" ++ ++ // Odd difference ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S"), %%mm2 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm1 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "psubusb %%mm1, %%mm2 \n\t" ++ "psubusb %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm0 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm0, %%mm5 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" ++ "paddw %%mm2, %%mm5 \n\t" ++ "paddw %%mm3, %%mm5 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 1b \n\t" ++ "movq %%mm4, (%%"REG_d") \n\t" ++ "movq %%mm5, 8(%%"REG_d") \n\t" ++ : ++ : "S" (old), "D" (new), "a" (os), "b" (ns), "d" (out) ++ : "memory" ++ ); ++ m->e = out[0]+out[1]+out[2]+out[3]; ++ m->o = out[4]+out[5]+out[6]+out[7]; ++ m->d = m->e + m->o; ++ ++ __asm__ ( ++ // First loop to measure first four columns ++ "movl $4, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" // Past spacial noise ++ "pxor %%mm5, %%mm5 \n\t" // Temporal noise ++ "pxor %%mm6, %%mm6 \n\t" // Current spacial noise ++ ++ ASMALIGN(4) ++ "2: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm2 \n\t" ++ "movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm2 \n\t" ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" ++ "paddw %%mm3, %%mm6 \n\t" ++ "psubw %%mm0, %%mm4 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ "psubw %%mm2, %%mm6 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 2b \n\t" ++ ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "pcmpgtw %%mm4, %%mm1 \n\t" ++ "pcmpgtw %%mm5, %%mm2 \n\t" ++ "pcmpgtw %%mm6, %%mm3 \n\t" ++ "pxor %%mm1, %%mm4 \n\t" ++ "pxor %%mm2, %%mm5 \n\t" ++ "pxor %%mm3, %%mm6 \n\t" ++ "psubw %%mm1, %%mm4 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ "psubw %%mm3, %%mm6 \n\t" ++ "movq %%mm4, (%%"REG_d") \n\t" ++ "movq %%mm5, 16(%%"REG_d") \n\t" ++ "movq %%mm6, 32(%%"REG_d") \n\t" ++ ++ "mov %%"REG_a", %%"REG_c" \n\t" ++ "shl $3, %%"REG_c" \n\t" ++ "sub %%"REG_c", %%"REG_S" \n\t" ++ "mov %%"REG_b", %%"REG_c" \n\t" ++ "shl $3, %%"REG_c" \n\t" ++ "sub %%"REG_c", %%"REG_D" \n\t" ++ ++ // Second loop for the last four columns ++ "movl $4, %%ecx \n\t" ++ "pxor %%mm4, %%mm4 \n\t" ++ "pxor %%mm5, %%mm5 \n\t" ++ "pxor %%mm6, %%mm6 \n\t" ++ ++ ASMALIGN(4) ++ "3: \n\t" ++ ++ "movq (%%"REG_S"), %%mm0 \n\t" ++ "movq (%%"REG_S",%%"REG_a"), %%mm1 \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "add %%"REG_a", %%"REG_S" \n\t" ++ "movq (%%"REG_D"), %%mm2 \n\t" ++ "movq (%%"REG_D",%%"REG_b"), %%mm3 \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "add %%"REG_b", %%"REG_D" \n\t" ++ "punpckhbw %%mm7, %%mm0 \n\t" ++ "punpckhbw %%mm7, %%mm1 \n\t" ++ "punpckhbw %%mm7, %%mm2 \n\t" ++ "punpckhbw %%mm7, %%mm3 \n\t" ++ "paddw %%mm1, %%mm4 \n\t" ++ "paddw %%mm1, %%mm5 \n\t" ++ "paddw %%mm3, %%mm6 \n\t" ++ "psubw %%mm0, %%mm4 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ "psubw %%mm2, %%mm6 \n\t" ++ ++ "decl %%ecx \n\t" ++ "jnz 3b \n\t" ++ ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "pcmpgtw %%mm4, %%mm1 \n\t" ++ "pcmpgtw %%mm5, %%mm2 \n\t" ++ "pcmpgtw %%mm6, %%mm3 \n\t" ++ "pxor %%mm1, %%mm4 \n\t" ++ "pxor %%mm2, %%mm5 \n\t" ++ "pxor %%mm3, %%mm6 \n\t" ++ "psubw %%mm1, %%mm4 \n\t" ++ "psubw %%mm2, %%mm5 \n\t" ++ "psubw %%mm3, %%mm6 \n\t" ++ "movq %%mm4, 8(%%"REG_d") \n\t" ++ "movq %%mm5, 24(%%"REG_d") \n\t" ++ "movq %%mm6, 40(%%"REG_d") \n\t" ++ ++ "emms \n\t" ++ : ++ : "S" (old), "D" (new), "a" ((long)os), "b" ((long)ns), "d" (out) ++ : "memory" ++ ); ++ m->p = m->t = m->s = 0; ++ for (i=0; i<8; i++) { ++ m->p += out[i]; ++ m->t += out[8+i]; ++ m->s += out[16+i]; ++ } ++ //printf("e=%d o=%d d=%d p=%d t=%d s=%d\n", m->e, m->o, m->d, m->p, m->t, m->s); ++} ++#endif ++ ++//#define MAG(a) ((a)*(a)) ++//#define MAG(a) (abs(a)) ++#define MAG(a) (((a)^((a)>>31))-((a)>>31)) ++ ++//#define LOWPASS(s) (((s)[-2] + 4*(s)[-1] + 6*(s)[0] + 4*(s)[1] + (s)[2])>>4) ++//#define LOWPASS(s) (((s)[-1] + 2*(s)[0] + (s)[1])>>2) ++#define LOWPASS(s) ((s)[0]) ++ ++ ++static void block_diffs_C(struct metrics *m, unsigned char *old, unsigned char *new, int os, int ns) ++{ ++ int x, y, e=0, o=0, s=0, p=0, t=0; ++ unsigned char *oldp, *newp; ++ m->s = m->p = m->t = 0; ++ for (x = 8; x; x--) { ++ oldp = old++; ++ newp = new++; ++ s = p = t = 0; ++ for (y = 4; y; y--) { ++ e += MAG(newp[0]-oldp[0]); ++ o += MAG(newp[ns]-oldp[os]); ++ s += newp[ns]-newp[0]; ++ p += oldp[os]-oldp[0]; ++ t += oldp[os]-newp[0]; ++ oldp += os<<1; ++ newp += ns<<1; ++ } ++ m->s += MAG(s); ++ m->p += MAG(p); ++ m->t += MAG(t); ++ } ++ m->e = e; ++ m->o = o; ++ m->d = e+o; ++} ++ ++static void (*block_diffs)(struct metrics *, unsigned char *, unsigned char *, int, int); ++ ++#define MAXUP(a,b) ((a) = ((a)>(b)) ? (a) : (b)) ++ ++static void diff_planes(struct frameinfo *fi, ++ unsigned char *old, unsigned char *new, int w, int h, int os, int ns) ++{ ++ int x, y; ++ struct metrics l; ++ struct metrics *peak=&fi->p, *rel=&fi->r, *mean=&fi->m; ++ memset(peak, 0, sizeof(struct metrics)); ++ memset(rel, 0, sizeof(struct metrics)); ++ memset(mean, 0, sizeof(struct metrics)); ++ for (y = 0; y < h-7; y += 8) { ++ for (x = 8; x < w-8-7; x += 8) { ++ block_diffs(&l, old+x+y*os, new+x+y*ns, os, ns); ++ mean->d += l.d; ++ mean->e += l.e; ++ mean->o += l.o; ++ mean->s += l.s; ++ mean->p += l.p; ++ mean->t += l.t; ++ MAXUP(peak->d, l.d); ++ MAXUP(peak->e, l.e); ++ MAXUP(peak->o, l.o); ++ MAXUP(peak->s, l.s); ++ MAXUP(peak->p, l.p); ++ MAXUP(peak->t, l.t); ++ MAXUP(rel->e, l.e-l.o); ++ MAXUP(rel->o, l.o-l.e); ++ MAXUP(rel->s, l.s-l.t); ++ MAXUP(rel->p, l.p-l.t); ++ MAXUP(rel->t, l.t-l.p); ++ MAXUP(rel->d, l.t-l.s); /* hack */ ++ } ++ } ++ x = (w/8-2)*(h/8); ++ mean->d /= x; ++ mean->e /= x; ++ mean->o /= x; ++ mean->s /= x; ++ mean->p /= x; ++ mean->t /= x; ++} ++ ++static void diff_fields(struct frameinfo *fi, mp_image_t *old, mp_image_t *new) ++{ ++ diff_planes(fi, old->planes[0], new->planes[0], ++ new->w, new->h, old->stride[0], new->stride[0]); ++} ++ ++static void stats(struct frameinfo *f) ++{ ++ mp_msg(MSGT_VFILTER, MSGL_V, " pd=%d re=%d ro=%d rp=%d rt=%d rs=%d rd=%d pp=%d pt=%d ps=%d\r", ++ f->p.d, f->r.e, f->r.o, f->r.p, f->r.t, f->r.s, f->r.d, f->p.p, f->p.t, f->p.s); ++} ++ ++static int foo(struct vf_priv_s *p, mp_image_t *new, mp_image_t *cur) ++{ ++ struct frameinfo *f = p->fi; ++ ++ f[0] = f[1]; ++ diff_fields(&f[1], cur, new); ++ stats(&f[1]); ++ ++ // Immediately drop this frame if it's already been used. ++ if (p->dropnext) { ++ p->dropnext = 0; ++ return F_DROP; ++ } ++ ++ // Sometimes a pulldown frame comes all by itself, so both ++ // its top and bottom field are duplicates from the adjacent ++ // two frames. We can just drop such a frame, but we ++ // immediately show the next frame instead to keep the frame ++ // drops evenly spaced during normal 3:2 pulldown sequences. ++ if ((3*f[1].r.o < f[1].r.e) && (f[1].r.s < f[1].r.d)) { ++ p->dropnext = 1; ++ return F_NEXT; ++ } ++ ++ // If none of these conditions hold, we will consider the frame ++ // progressive and just show it as-is. ++ if (!( (3*f[0].r.e < f[0].r.o) || ++ ((2*f[0].r.d < f[0].r.s) && (f[0].r.s > 1200)) || ++ ((2*f[1].r.t < f[1].r.p) && (f[1].r.p > 1200)) )) ++ return F_SHOW; ++ ++ // Otherwise, we have to decide whether to merge or drop. ++ // If the noise metric only increases minimally, we're off ++ // to a good start... ++ if (((2*f[1].r.t < 3*f[1].r.p) && (f[1].r.t < 3600)) || ++ (f[1].r.t < 900) || (f[1].r.d < 900)) { ++ // ...and if noise decreases or the duplicate even field ++ // is detected, we go ahead with the merge. ++ if ((3*f[0].r.e < f[0].r.o) || (2*f[1].r.t < f[1].r.p)) { ++ p->dropnext = 1; ++ return F_MERGE; ++ } ++ } ++ return F_DROP; ++} ++ ++ ++ ++static void copy_image(mp_image_t *dmpi, mp_image_t *mpi, int field) ++{ ++ switch (field) { ++ case 0: ++ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ break; ++ case 1: ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ break; ++ case 2: ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0], mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2], mpi->stride[2]); ++ } ++ break; ++ } ++} ++ ++static int do_put_image(struct vf_instance *vf, mp_image_t *dmpi) ++{ ++ struct vf_priv_s *p = vf->priv; ++ int dropflag=0; ++ ++ if (!p->dropnext) switch (p->drop) { ++ case 0: ++ dropflag = 0; ++ break; ++ case 1: ++ dropflag = (++p->lastdrop >= 5); ++ break; ++ case 2: ++ dropflag = (++p->lastdrop >= 5) && (4*p->inframes <= 5*p->outframes); ++ break; ++ } ++ ++ if (dropflag) { ++ //mp_msg(MSGT_VFILTER, MSGL_V, "drop! [%d/%d=%g]\n", ++ // p->outframes, p->inframes, (float)p->outframes/p->inframes); ++ mp_msg(MSGT_VFILTER, MSGL_V, "!"); ++ p->lastdrop = 0; ++ return 0; ++ } ++ ++ p->outframes++; ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ int ret=0; ++ struct vf_priv_s *p = vf->priv; ++ ++ p->inframes++; ++ ++ if (p->first) { /* hack */ ++ p->first = 0; ++ return 1; ++ } ++ ++ if (!p->dmpi) p->dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE | MP_IMGFLAG_READABLE, ++ mpi->width, mpi->height); ++ /* FIXME -- not correct, off by one frame! */ ++ p->dmpi->qscale = mpi->qscale; ++ p->dmpi->qstride = mpi->qstride; ++ p->dmpi->qscale_type = mpi->qscale_type; ++ ++ switch (foo(p, mpi, p->dmpi)) { ++ case F_DROP: ++ copy_image(p->dmpi, mpi, 2); ++ ret = 0; ++ p->lastdrop = 0; ++ mp_msg(MSGT_VFILTER, MSGL_V, "DROP\n"); ++ break; ++ case F_MERGE: ++ copy_image(p->dmpi, mpi, 0); ++ ret = do_put_image(vf, p->dmpi); ++ copy_image(p->dmpi, mpi, 1); ++ mp_msg(MSGT_VFILTER, MSGL_V, "MERGE\n"); ++ p->dmpi = NULL; ++ break; ++ case F_NEXT: ++ copy_image(p->dmpi, mpi, 2); ++ ret = do_put_image(vf, p->dmpi); ++ mp_msg(MSGT_VFILTER, MSGL_V, "NEXT\n"); ++ p->dmpi = NULL; ++ break; ++ case F_SHOW: ++ ret = do_put_image(vf, p->dmpi); ++ copy_image(p->dmpi, mpi, 2); ++ mp_msg(MSGT_VFILTER, MSGL_V, "OK\n"); ++ p->dmpi = NULL; ++ break; ++ } ++ return ret; ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->put_image = put_image; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ p->drop = 0; ++ p->first = 1; ++ if (args) sscanf(args, "%d", &p->drop); ++ block_diffs = block_diffs_C; ++#if HAVE_MMX && HAVE_EBX_AVAILABLE ++ if(gCpuCaps.hasMMX) block_diffs = block_diffs_MMX; ++#endif ++ return 1; ++} ++ ++const vf_info_t vf_info_ivtc = { ++ "inverse telecine, take 2", ++ "ivtc", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_kerndeint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_kerndeint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_kerndeint.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_kerndeint.c 2012-05-14 14:08:54.760348555 +0200 +@@ -0,0 +1,345 @@ ++/* ++ * Original AVISynth Filter Copyright (C) 2003 Donald A. Graft ++ * Adapted to MPlayer by Tobias Diedrich ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++ ++//===========================================================================// ++ ++struct vf_priv_s { ++ int frame; ++ int map; ++ int order; ++ int thresh; ++ int sharp; ++ int twoway; ++ int do_deinterlace; ++}; ++ ++ ++/***************************************************************************/ ++ ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static inline int IsRGB(mp_image_t *mpi) ++{ ++ return mpi->imgfmt == IMGFMT_RGB; ++} ++ ++static inline int IsYUY2(mp_image_t *mpi) ++{ ++ return mpi->imgfmt == IMGFMT_YUY2; ++} ++ ++#define PLANAR_Y 0 ++#define PLANAR_U 1 ++#define PLANAR_V 2 ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ int W = mpi->w, H = mpi->h; ++ const unsigned char *prvp, *prvpp, *prvpn, *prvpnn, *prvppp, *prvp4p, *prvp4n; ++ const unsigned char *srcp_saved; ++ const unsigned char *srcp, *srcpp, *srcpn, *srcpnn, *srcppp, *srcp3p, *srcp3n, *srcp4p, *srcp4n; ++ unsigned char *dstp, *dstp_saved; ++ int src_pitch; ++ int psrc_pitch; ++ int dst_pitch; ++ int x, y, z; ++ int n = vf->priv->frame++; ++ int val, hi, lo, w, h; ++ double valf; ++ int plane; ++ int threshold = vf->priv->thresh; ++ int order = vf->priv->order; ++ int map = vf->priv->map; ++ int sharp = vf->priv->sharp; ++ int twoway = vf->priv->twoway; ++ mp_image_t *dmpi, *pmpi; ++ ++ if(!vf->priv->do_deinterlace) ++ return vf_next_put_image(vf, mpi, pts); ++ ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_IP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ pmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ if(!dmpi) return 0; ++ ++ for (z=0; znum_planes; z++) { ++ if (z == 0) plane = PLANAR_Y; ++ else if (z == 1) plane = PLANAR_U; ++ else plane = PLANAR_V; ++ ++ h = plane == PLANAR_Y ? H : ch; ++ w = plane == PLANAR_Y ? W : cw; ++ ++ srcp = srcp_saved = mpi->planes[z]; ++ src_pitch = mpi->stride[z]; ++ psrc_pitch = pmpi->stride[z]; ++ dstp = dstp_saved = dmpi->planes[z]; ++ dst_pitch = dmpi->stride[z]; ++ srcp = srcp_saved + (1-order) * src_pitch; ++ dstp = dstp_saved + (1-order) * dst_pitch; ++ ++ for (y=0; yplanes[z] + 5*psrc_pitch - (1-order)*psrc_pitch; ++ prvpp = prvp - psrc_pitch; ++ prvppp = prvp - 2*psrc_pitch; ++ prvp4p = prvp - 4*psrc_pitch; ++ prvpn = prvp + psrc_pitch; ++ prvpnn = prvp + 2*psrc_pitch; ++ prvp4n = prvp + 4*psrc_pitch; ++ srcp = srcp_saved + 5*src_pitch - (1-order)*src_pitch; ++ srcpp = srcp - src_pitch; ++ srcppp = srcp - 2*src_pitch; ++ srcp3p = srcp - 3*src_pitch; ++ srcp4p = srcp - 4*src_pitch; ++ srcpn = srcp + src_pitch; ++ srcpnn = srcp + 2*src_pitch; ++ srcp3n = srcp + 3*src_pitch; ++ srcp4n = srcp + 4*src_pitch; ++ dstp = dstp_saved + 5*dst_pitch - (1-order)*dst_pitch; ++ for (y = 5 - (1-order); y <= h - 5 - (1-order); y+=2) ++ { ++ for (x = 0; x < w; x++) ++ { ++ if ((threshold == 0) || (n == 0) || ++ (abs((int)prvp[x] - (int)srcp[x]) > threshold) || ++ (abs((int)prvpp[x] - (int)srcpp[x]) > threshold) || ++ (abs((int)prvpn[x] - (int)srcpn[x]) > threshold)) ++ { ++ if (map == 1) ++ { ++ int g = x & ~3; ++ if (IsRGB(mpi) == 1) ++ { ++ dstp[g++] = 255; ++ dstp[g++] = 255; ++ dstp[g++] = 255; ++ dstp[g] = 255; ++ x = g; ++ } ++ else if (IsYUY2(mpi) == 1) ++ { ++ dstp[g++] = 235; ++ dstp[g++] = 128; ++ dstp[g++] = 235; ++ dstp[g] = 128; ++ x = g; ++ } ++ else ++ { ++ if (plane == PLANAR_Y) dstp[x] = 235; ++ else dstp[x] = 128; ++ } ++ } ++ else ++ { ++ if (IsRGB(mpi)) ++ { ++ hi = 255; ++ lo = 0; ++ } ++ else if (IsYUY2(mpi)) ++ { ++ hi = (x & 1) ? 240 : 235; ++ lo = 16; ++ } ++ else ++ { ++ hi = (plane == PLANAR_Y) ? 235 : 240; ++ lo = 16; ++ } ++ ++ if (sharp == 1) ++ { ++ if (twoway == 1) ++ valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) ++ + 0.170*((int)srcp[x] + (int)prvp[x]) ++ - 0.116*((int)srcppp[x] + (int)srcpnn[x] + (int)prvppp[x] + (int)prvpnn[x]) ++ - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) ++ + 0.031*((int)srcp4p[x] + (int)srcp4n[x] + (int)prvp4p[x] + (int)prvp4n[x]); ++ else ++ valf = + 0.526*((int)srcpp[x] + (int)srcpn[x]) ++ + 0.170*((int)prvp[x]) ++ - 0.116*((int)prvppp[x] + (int)prvpnn[x]) ++ - 0.026*((int)srcp3p[x] + (int)srcp3n[x]) ++ + 0.031*((int)prvp4p[x] + (int)prvp4p[x]); ++ if (valf > hi) valf = hi; ++ else if (valf < lo) valf = lo; ++ dstp[x] = (int) valf; ++ } ++ else ++ { ++ if (twoway == 1) ++ val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)srcp[x] + (int)prvp[x]) - ++ (int)(srcppp[x]) - (int)(srcpnn[x]) - ++ (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; ++ else ++ val = (8*((int)srcpp[x] + (int)srcpn[x]) + 2*((int)prvp[x]) - ++ (int)(prvppp[x]) - (int)(prvpnn[x])) >> 4; ++ if (val > hi) val = hi; ++ else if (val < lo) val = lo; ++ dstp[x] = (int) val; ++ } ++ } ++ } ++ else ++ { ++ dstp[x] = srcp[x]; ++ } ++ } ++ prvp += 2*psrc_pitch; ++ prvpp += 2*psrc_pitch; ++ prvppp += 2*psrc_pitch; ++ prvpn += 2*psrc_pitch; ++ prvpnn += 2*psrc_pitch; ++ prvp4p += 2*psrc_pitch; ++ prvp4n += 2*psrc_pitch; ++ srcp += 2*src_pitch; ++ srcpp += 2*src_pitch; ++ srcppp += 2*src_pitch; ++ srcp3p += 2*src_pitch; ++ srcp4p += 2*src_pitch; ++ srcpn += 2*src_pitch; ++ srcpnn += 2*src_pitch; ++ srcp3n += 2*src_pitch; ++ srcp4n += 2*src_pitch; ++ dstp += 2*dst_pitch; ++ } ++ ++ srcp = mpi->planes[z]; ++ dstp = pmpi->planes[z]; ++ for (y=0; ypriv->do_deinterlace; ++ return CONTROL_OK; ++ case VFCTRL_SET_DEINTERLACE: ++ vf->priv->do_deinterlace = *(int*)data; ++ return CONTROL_OK; ++ } ++ return vf_next_control (vf, request, data); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ ++ vf->control=control; ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ vf->priv->frame = 0; ++ ++ vf->priv->map = 0; ++ vf->priv->order = 0; ++ vf->priv->thresh = 10; ++ vf->priv->sharp = 0; ++ vf->priv->twoway = 0; ++ vf->priv->do_deinterlace=1; ++ ++ if (args) ++ { ++ sscanf(args, "%d:%d:%d:%d:%d", ++ &vf->priv->thresh, &vf->priv->map, ++ &vf->priv->order, &vf->priv->sharp, ++ &vf->priv->twoway); ++ } ++ if (vf->priv->order > 1) vf->priv->order = 1; ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_kerndeint = { ++ "Kernel Deinterlacer", ++ "kerndeint", ++ "Donald Graft", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_mcdeint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_mcdeint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_mcdeint.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_mcdeint.c 2012-05-14 14:08:54.762348595 +0200 +@@ -0,0 +1,337 @@ ++/* ++ * Copyright (C) 2006 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++ ++/* ++Known Issues: ++* The motion estimation is somewhat at the mercy of the input, if the input ++ frames are created purely based on spatial interpolation then for example ++ a thin black line or another random and not interpolateable pattern ++ will cause problems ++ Note: completly ignoring the "unavailable" lines during motion estimation ++ didnt look any better, so the most obvious solution would be to improve ++ tfields or penalize problematic motion vectors ... ++ ++* If non iterative ME is used then snow currently ignores the OBMC window ++ and as a result sometimes creates artifacts ++ ++* only past frames are used, we should ideally use future frames too, something ++ like filtering the whole movie in forward and then backward direction seems ++ like a interresting idea but the current filter framework is FAR from ++ supporting such things ++ ++* combining the motion compensated image with the input image also isnt ++ as trivial as it seems, simple blindly taking even lines from one and ++ odd ones from the other doesnt work at all as ME/MC sometimes simple ++ has nothing in the previous frames which matches the current, the current ++ algo has been found by trial and error and almost certainly can be ++ improved ... ++*/ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "libavutil/internal.h" ++#include "libavutil/intreadwrite.h" ++#include "libavcodec/avcodec.h" ++#include "libavcodec/dsputil.h" ++ ++#undef fprintf ++#undef free ++#undef malloc ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "vd_ffmpeg.h" ++ ++#define MIN(a,b) ((a) > (b) ? (b) : (a)) ++#define MAX(a,b) ((a) < (b) ? (b) : (a)) ++#define ABS(a) ((a) > 0 ? (a) : (-(a))) ++ ++//===========================================================================// ++ ++struct vf_priv_s { ++ int mode; ++ int qp; ++ int parity; ++#if 0 ++ int temp_stride[3]; ++ uint8_t *src[3]; ++ int16_t *temp[3]; ++#endif ++ int outbuf_size; ++ uint8_t *outbuf; ++ AVCodecContext *avctx_enc; ++ AVFrame *frame; ++ AVFrame *frame_dec; ++}; ++ ++static void filter(struct vf_priv_s *p, uint8_t *dst[3], uint8_t *src[3], int dst_stride[3], int src_stride[3], int width, int height){ ++ int x, y, i; ++ ++ for(i=0; i<3; i++){ ++ p->frame->data[i]= src[i]; ++ p->frame->linesize[i]= src_stride[i]; ++ } ++ ++ p->avctx_enc->me_cmp= ++ p->avctx_enc->me_sub_cmp= FF_CMP_SAD /*| (p->parity ? FF_CMP_ODD : FF_CMP_EVEN)*/; ++ p->frame->quality= p->qp*FF_QP2LAMBDA; ++ avcodec_encode_video(p->avctx_enc, p->outbuf, p->outbuf_size, p->frame); ++ p->frame_dec = p->avctx_enc->coded_frame; ++ ++ for(i=0; i<3; i++){ ++ int is_chroma= !!i; ++ int w= width >>is_chroma; ++ int h= height>>is_chroma; ++ int fils= p->frame_dec->linesize[i]; ++ int srcs= src_stride[i]; ++ ++ for(y=0; yparity) & 1){ ++ for(x=0; x=0 && (x+2)+(y+1)*wframe_dec->data[i][x + y*fils]; ++ uint8_t *srcp= &src[i][x + y*srcs]; ++ int diff0= filp[-fils] - srcp[-srcs]; ++ int diff1= filp[+fils] - srcp[+srcs]; ++ int spatial_score= ABS(srcp[-srcs-1] - srcp[+srcs-1]) ++ +ABS(srcp[-srcs ] - srcp[+srcs ]) ++ +ABS(srcp[-srcs+1] - srcp[+srcs+1]) - 1; ++ int temp= filp[0]; ++ ++#define CHECK(j)\ ++ { int score= ABS(srcp[-srcs-1+j] - srcp[+srcs-1-j])\ ++ + ABS(srcp[-srcs +j] - srcp[+srcs -j])\ ++ + ABS(srcp[-srcs+1+j] - srcp[+srcs+1-j]);\ ++ if(score < spatial_score){\ ++ spatial_score= score;\ ++ diff0= filp[-fils+j] - srcp[-srcs+j];\ ++ diff1= filp[+fils-j] - srcp[+srcs-j]; ++ ++ CHECK(-1) CHECK(-2) }} }} ++ CHECK( 1) CHECK( 2) }} }} ++#if 0 ++ if((diff0 ^ diff1) > 0){ ++ int mindiff= ABS(diff0) > ABS(diff1) ? diff1 : diff0; ++ temp-= mindiff; ++ } ++#elif 1 ++ if(diff0 + diff1 > 0) ++ temp-= (diff0 + diff1 - ABS( ABS(diff0) - ABS(diff1) )/2)/2; ++ else ++ temp-= (diff0 + diff1 + ABS( ABS(diff0) - ABS(diff1) )/2)/2; ++#else ++ temp-= (diff0 + diff1)/2; ++#endif ++#if 1 ++ filp[0]= ++ dst[i][x + y*dst_stride[i]]= temp > 255U ? ~(temp>>31) : temp; ++#else ++ dst[i][x + y*dst_stride[i]]= filp[0]; ++ filp[0]= temp > 255U ? ~(temp>>31) : temp; ++#endif ++ }else ++ dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils]; ++ } ++ } ++ } ++ for(y=0; yparity) & 1)){ ++ for(x=0; xframe_dec->data[i][x + y*fils]= ++ dst[i][x + y*dst_stride[i]]= src[i][x + y*srcs]; ++#else ++ dst[i][x + y*dst_stride[i]]= p->frame_dec->data[i][x + y*fils]; ++ p->frame_dec->data[i][x + y*fils]= src[i][x + y*srcs]; ++#endif ++ } ++ } ++ } ++ } ++ p->parity ^= 1; ++ ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int i; ++ AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW); ++ ++ for(i=0; i<3; i++){ ++ AVCodecContext *avctx_enc; ++#if 0 ++ int is_chroma= !!i; ++ int w= ((width + 31) & (~31))>>is_chroma; ++ int h= ((height + 31) & (~31))>>is_chroma; ++ ++ vf->priv->temp_stride[i]= w; ++ vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t)); ++ vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t)); ++#endif ++ avctx_enc= ++ vf->priv->avctx_enc= avcodec_alloc_context(); ++ avctx_enc->width = width; ++ avctx_enc->height = height; ++ avctx_enc->time_base= (AVRational){1,25}; // meaningless ++ avctx_enc->gop_size = 300; ++ avctx_enc->max_b_frames= 0; ++ avctx_enc->pix_fmt = PIX_FMT_YUV420P; ++ avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY; ++ avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; ++ avctx_enc->global_quality= 1; ++ avctx_enc->flags2= CODEC_FLAG2_MEMC_ONLY; ++ avctx_enc->me_cmp= ++ avctx_enc->me_sub_cmp= FF_CMP_SAD; //SSE; ++ avctx_enc->mb_cmp= FF_CMP_SSE; ++ ++ switch(vf->priv->mode){ ++ case 3: ++ avctx_enc->refs= 3; ++ case 2: ++ avctx_enc->me_method= ME_ITER; ++ case 1: ++ avctx_enc->flags |= CODEC_FLAG_4MV; ++ avctx_enc->dia_size=2; ++// avctx_enc->mb_decision = MB_DECISION_RD; ++ case 0: ++ avctx_enc->flags |= CODEC_FLAG_QPEL; ++ } ++ ++ avcodec_open(avctx_enc, enc); ++ ++ } ++ vf->priv->frame= avcodec_alloc_frame(); ++ ++ vf->priv->outbuf_size= width*height*10; ++ vf->priv->outbuf= malloc(vf->priv->outbuf_size); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++return; //caused problems, dunno why ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ }else{ ++ dmpi=vf->dmpi; ++ } ++ ++ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++#if 0 ++ for(i=0; i<3; i++){ ++ free(vf->priv->temp[i]); ++ vf->priv->temp[i]= NULL; ++ free(vf->priv->src[i]); ++ vf->priv->src[i]= NULL; ++ } ++#endif ++ if (vf->priv->avctx_enc) { ++ avcodec_close(vf->priv->avctx_enc); ++ av_freep(&vf->priv->avctx_enc); ++ } ++ ++ free(vf->priv->outbuf); ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ init_avcodec(); ++ ++ vf->priv->mode=0; ++ vf->priv->parity= -1; ++ vf->priv->qp=1; ++ ++ if (args) sscanf(args, "%d:%d:%d", &vf->priv->mode, &vf->priv->parity, &vf->priv->qp); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_mcdeint = { ++ "motion compensating deinterlacer", ++ "mcdeint", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_mirror.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_mirror.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_mirror.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_mirror.c 2012-05-14 14:08:54.762348595 +0200 +@@ -0,0 +1,131 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++ ++static void mirror(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,unsigned int fmt){ ++ int y; ++ for(y=0;y>1; ++ for(x=0;x>1; ++ for(x=0;xnext,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w, mpi->h); ++ ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mirror(dmpi->planes[0],mpi->planes[0], ++ dmpi->stride[0],mpi->stride[0], ++ dmpi->w,dmpi->h,1,mpi->imgfmt); ++ mirror(dmpi->planes[1],mpi->planes[1], ++ dmpi->stride[1],mpi->stride[1], ++ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt); ++ mirror(dmpi->planes[2],mpi->planes[2], ++ dmpi->stride[2],mpi->stride[2], ++ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,mpi->imgfmt); ++ } else { ++ mirror(dmpi->planes[0],mpi->planes[0], ++ dmpi->stride[0],mpi->stride[0], ++ dmpi->w,dmpi->h,dmpi->bpp>>3,mpi->imgfmt); ++ dmpi->planes[1]=mpi->planes[1]; // passthrough rgb8 palette ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ //vf->config=config; ++ vf->put_image=put_image; ++ return 1; ++} ++ ++const vf_info_t vf_info_mirror = { ++ "horizontal mirror", ++ "mirror", ++ "Eyck", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_noise.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_noise.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_noise.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_noise.c 2012-05-14 14:08:54.764348636 +0200 +@@ -0,0 +1,474 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++#include "libavutil/mem.h" ++ ++#define MAX_NOISE 4096 ++#define MAX_SHIFT 1024 ++#define MAX_RES (MAX_NOISE-MAX_SHIFT) ++ ++//===========================================================================// ++ ++static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift); ++static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift); ++ ++static void (*lineNoise)(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift)= lineNoise_C; ++static void (*lineNoiseAvg)(uint8_t *dst, uint8_t *src, int len, int8_t **shift)= lineNoiseAvg_C; ++ ++typedef struct FilterParam{ ++ int strength; ++ int uniform; ++ int temporal; ++ int quality; ++ int averaged; ++ int pattern; ++ int shiftptr; ++ int8_t *noise; ++ int8_t *prev_shift[MAX_RES][3]; ++}FilterParam; ++ ++struct vf_priv_s { ++ FilterParam lumaParam; ++ FilterParam chromaParam; ++ unsigned int outfmt; ++}; ++ ++static int nonTempRandShift_init; ++static int nonTempRandShift[MAX_RES]; ++ ++static int patt[4] = { ++ -1,0,1,0 ++}; ++ ++#define RAND_N(range) ((int) ((double)range*rand()/(RAND_MAX+1.0))) ++static int8_t *initNoise(FilterParam *fp){ ++ int strength= fp->strength; ++ int uniform= fp->uniform; ++ int averaged= fp->averaged; ++ int pattern= fp->pattern; ++ int8_t *noise= av_malloc(MAX_NOISE*sizeof(int8_t)); ++ int i, j; ++ ++ srand(123457); ++ ++ for(i=0,j=0; i= 1.0 ); ++ ++ w = sqrt( (-2.0 * log( w ) ) / w ); ++ y1= x1 * w; ++ y1*= strength / sqrt(3.0); ++ if (pattern) { ++ y1 /= 2; ++ y1 += patt[j%4]*strength*0.35; ++ } ++ if (y1<-128) y1=-128; ++ else if(y1> 127) y1= 127; ++ if (averaged) y1 /= 3.0; ++ noise[i]= (int)y1; ++ } ++ if (RAND_N(6) == 0) j--; ++ } ++ ++ ++ for (i = 0; i < MAX_RES; i++) ++ for (j = 0; j < 3; j++) ++ fp->prev_shift[i][j] = noise + (rand()&(MAX_SHIFT-1)); ++ ++ if(!nonTempRandShift_init){ ++ for(i=0; inoise= noise; ++ fp->shiftptr= 0; ++ return noise; ++} ++ ++/***************************************************************************/ ++ ++#if HAVE_MMX ++static inline void lineNoise_MMX(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ ++ x86_reg mmx_len= len&(~7); ++ noise+=shift; ++ ++ __asm__ volatile( ++ "mov %3, %%"REG_a" \n\t" ++ "pcmpeqb %%mm7, %%mm7 \n\t" ++ "psllw $15, %%mm7 \n\t" ++ "packsswb %%mm7, %%mm7 \n\t" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%0, %%"REG_a"), %%mm0 \n\t" ++ "movq (%1, %%"REG_a"), %%mm1 \n\t" ++ "pxor %%mm7, %%mm0 \n\t" ++ "paddsb %%mm1, %%mm0 \n\t" ++ "pxor %%mm7, %%mm0 \n\t" ++ "movq %%mm0, (%2, %%"REG_a") \n\t" ++ "add $8, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len) ++ : "%"REG_a ++ ); ++ if(mmx_len!=len) ++ lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0); ++} ++#endif ++ ++//duplicate of previous except movntq ++#if HAVE_MMX2 ++static inline void lineNoise_MMX2(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ ++ x86_reg mmx_len= len&(~7); ++ noise+=shift; ++ ++ __asm__ volatile( ++ "mov %3, %%"REG_a" \n\t" ++ "pcmpeqb %%mm7, %%mm7 \n\t" ++ "psllw $15, %%mm7 \n\t" ++ "packsswb %%mm7, %%mm7 \n\t" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%0, %%"REG_a"), %%mm0 \n\t" ++ "movq (%1, %%"REG_a"), %%mm1 \n\t" ++ "pxor %%mm7, %%mm0 \n\t" ++ "paddsb %%mm1, %%mm0 \n\t" ++ "pxor %%mm7, %%mm0 \n\t" ++ "movntq %%mm0, (%2, %%"REG_a") \n\t" ++ "add $8, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ :: "r" (src+mmx_len), "r" (noise+mmx_len), "r" (dst+mmx_len), "g" (-mmx_len) ++ : "%"REG_a ++ ); ++ if(mmx_len!=len) ++ lineNoise_C(dst+mmx_len, src+mmx_len, noise+mmx_len, len-mmx_len, 0); ++} ++#endif ++ ++static inline void lineNoise_C(uint8_t *dst, uint8_t *src, int8_t *noise, int len, int shift){ ++ int i; ++ noise+= shift; ++ for(i=0; i255) dst[i]=255; //FIXME optimize ++ else if(v<0) dst[i]=0; ++ else dst[i]=v; ++ } ++} ++ ++/***************************************************************************/ ++ ++#if HAVE_MMX ++static inline void lineNoiseAvg_MMX(uint8_t *dst, uint8_t *src, int len, int8_t **shift){ ++ x86_reg mmx_len= len&(~7); ++ ++ __asm__ volatile( ++ "mov %5, %%"REG_a" \n\t" ++ ASMALIGN(4) ++ "1: \n\t" ++ "movq (%1, %%"REG_a"), %%mm1 \n\t" ++ "movq (%0, %%"REG_a"), %%mm0 \n\t" ++ "paddb (%2, %%"REG_a"), %%mm1 \n\t" ++ "paddb (%3, %%"REG_a"), %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "punpcklbw %%mm0, %%mm0 \n\t" ++ "punpckhbw %%mm2, %%mm2 \n\t" ++ "punpcklbw %%mm1, %%mm1 \n\t" ++ "punpckhbw %%mm3, %%mm3 \n\t" ++ "pmulhw %%mm0, %%mm1 \n\t" ++ "pmulhw %%mm2, %%mm3 \n\t" ++ "paddw %%mm1, %%mm1 \n\t" ++ "paddw %%mm3, %%mm3 \n\t" ++ "paddw %%mm0, %%mm1 \n\t" ++ "paddw %%mm2, %%mm3 \n\t" ++ "psrlw $8, %%mm1 \n\t" ++ "psrlw $8, %%mm3 \n\t" ++ "packuswb %%mm3, %%mm1 \n\t" ++ "movq %%mm1, (%4, %%"REG_a") \n\t" ++ "add $8, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ :: "r" (src+mmx_len), "r" (shift[0]+mmx_len), "r" (shift[1]+mmx_len), "r" (shift[2]+mmx_len), ++ "r" (dst+mmx_len), "g" (-mmx_len) ++ : "%"REG_a ++ ); ++ ++ if(mmx_len!=len){ ++ int8_t *shift2[3]={shift[0]+mmx_len, shift[1]+mmx_len, shift[2]+mmx_len}; ++ lineNoiseAvg_C(dst+mmx_len, src+mmx_len, len-mmx_len, shift2); ++ } ++} ++#endif ++ ++static inline void lineNoiseAvg_C(uint8_t *dst, uint8_t *src, int len, int8_t **shift){ ++ int i; ++ int8_t *src2= (int8_t*)src; ++ ++ for(i=0; i>7); ++ } ++} ++ ++/***************************************************************************/ ++ ++static void noise(uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp){ ++ int8_t *noise= fp->noise; ++ int y; ++ int shift=0; ++ ++ if(!noise) ++ { ++ if(src==dst) return; ++ ++ if(dstStride==srcStride) fast_memcpy(dst, src, srcStride*height); ++ else ++ { ++ for(y=0; ytemporal) shift= rand()&(MAX_SHIFT -1); ++ else shift= nonTempRandShift[y]; ++ ++ if(fp->quality==0) shift&= ~7; ++ if (fp->averaged) { ++ lineNoiseAvg(dst, src, width, fp->prev_shift[y]); ++ fp->prev_shift[y][fp->shiftptr] = noise + shift; ++ } else { ++ lineNoise(dst, src, noise, width, shift); ++ } ++ dst+= dstStride; ++ src+= srcStride; ++ } ++ fp->shiftptr++; ++ if (fp->shiftptr == 3) fp->shiftptr = 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ if(mpi->imgfmt!=vf->priv->outfmt) return; // colorspace differ ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags, mpi->w, mpi->h); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ vf->dmpi=vf_get_image(vf->next,vf->priv->outfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++//printf("nodr\n"); ++ } ++//else printf("dr\n"); ++ dmpi= vf->dmpi; ++ ++ noise(dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam); ++ noise(dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); ++ noise(dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam); ++ ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); ++#endif ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ av_free(vf->priv->chromaParam.noise); ++ vf->priv->chromaParam.noise= NULL; ++ ++ av_free(vf->priv->lumaParam.noise); ++ vf->priv->lumaParam.noise= NULL; ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ return vf_next_query_format(vf,vf->priv->outfmt); ++ } ++ return 0; ++} ++ ++static void parse(FilterParam *fp, char* args){ ++ char *pos; ++ char *max= strchr(args, ':'); ++ ++ if(!max) max= args + strlen(args); ++ ++ fp->strength= atoi(args); ++ pos= strchr(args, 'u'); ++ if(pos && posuniform=1; ++ pos= strchr(args, 't'); ++ if(pos && postemporal=1; ++ pos= strchr(args, 'h'); ++ if(pos && posquality=1; ++ pos= strchr(args, 'p'); ++ if(pos && pospattern=1; ++ pos= strchr(args, 'a'); ++ if(pos && postemporal=1; ++ fp->averaged=1; ++ } ++ ++ if(fp->strength) initNoise(fp); ++} ++ ++static const unsigned int fmt_list[]={ ++ IMGFMT_YV12, ++ IMGFMT_I420, ++ IMGFMT_IYUV, ++ 0 ++}; ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ if(args) ++ { ++ char *arg2= strchr(args,':'); ++ if(arg2) parse(&vf->priv->chromaParam, arg2+1); ++ parse(&vf->priv->lumaParam, args); ++ } ++ ++ // check csp: ++ vf->priv->outfmt=vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); ++ if(!vf->priv->outfmt) ++ { ++ uninit(vf); ++ return 0; // no csp match :( ++ } ++ ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX){ ++ lineNoise= lineNoise_MMX; ++ lineNoiseAvg= lineNoiseAvg_MMX; ++ } ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) lineNoise= lineNoise_MMX2; ++// if(gCpuCaps.hasMMX) lineNoiseAvg= lineNoiseAvg_MMX2; ++#endif ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_noise = { ++ "noise generator", ++ "noise", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ow.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ow.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_ow.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_ow.c 2012-05-14 14:08:54.765348657 +0200 +@@ -0,0 +1,322 @@ ++/* ++ * Copyright (C) 2007 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * @todo try to change to int ++ * @todo try lifting based implementation ++ * @todo optimize optimize optimize ++ * @todo hard tresholding ++ * @todo use QP to decide filter strength ++ * @todo wavelet normalization / least squares optimal signal vs. noise thresholds ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++//===========================================================================// ++static const uint8_t __attribute__((aligned(8))) dither[8][8]={ ++{ 0, 48, 12, 60, 3, 51, 15, 63, }, ++{ 32, 16, 44, 28, 35, 19, 47, 31, }, ++{ 8, 56, 4, 52, 11, 59, 7, 55, }, ++{ 40, 24, 36, 20, 43, 27, 39, 23, }, ++{ 2, 50, 14, 62, 1, 49, 13, 61, }, ++{ 34, 18, 46, 30, 33, 17, 45, 29, }, ++{ 10, 58, 6, 54, 9, 57, 5, 53, }, ++{ 42, 26, 38, 22, 41, 25, 37, 21, }, ++}; ++//FIXME the above is duplicated in many filters ++ ++struct vf_priv_s { ++ float strength[2]; ++ float delta; ++ int mode; ++ int depth; ++ float *plane[16][4]; ++ int stride; ++}; ++ ++#define S 1.41421356237 //sqrt(2) ++ ++static const double coeff[2][5]={ ++ { ++ 0.6029490182363579 *S, ++ 0.2668641184428723 *S, ++ -0.07822326652898785 *S, ++ -0.01686411844287495 *S, ++ 0.02674875741080976 *S ++ },{ ++ 1.115087052456994 /S, ++ -0.5912717631142470 /S, ++ -0.05754352622849957 /S, ++ 0.09127176311424948 /S ++ } ++}; ++ ++static const double icoeff[2][5]={ ++ { ++ 1.115087052456994 /S, ++ 0.5912717631142470 /S, ++ -0.05754352622849957 /S, ++ -0.09127176311424948 /S ++ },{ ++ 0.6029490182363579 *S, ++ -0.2668641184428723 *S, ++ -0.07822326652898785 *S, ++ 0.01686411844287495 *S, ++ 0.02674875741080976 *S ++ } ++}; ++#undef S ++ ++static inline int mirror(int x, int w){ ++ while((unsigned)x > (unsigned)w){ ++ x=-x; ++ if(x<0) x+= 2*w; ++ } ++ return x; ++} ++ ++static inline void decompose(float *dstL, float *dstH, float *src, int stride, int w){ ++ int x, i; ++ for(x=0; xstrength[!is_luma]; ++ int depth= p->depth; ++ ++ while(1< width || 1< height) ++ depth--; ++ ++ for(y=0; yplane[0][0][x + y*p->stride]= src[x + y*src_stride]; ++ ++ for(i=0; iplane[i+1], p->plane[i][0], p->plane[0]+1,p->stride, 1<plane[i+1][j][x + y*p->stride]; ++ if (v> s) v-=s; ++ else if(v<-s) v+=s; ++ else v =0; ++ p->plane[i+1][j][x + y*p->stride]= v; ++ } ++ } ++ } ++ } ++ for(i=depth-1; i>=0; i--){ ++ compose2D2(p->plane[i][0], p->plane[i+1], p->plane[0]+1, p->stride, 1<plane[0][0][x + y*p->stride] + dither[x&7][y&7]*(1.0/64) + 1.0/128; //yes the rounding is insane but optimal :) ++// double e= i - src[x + y*src_stride]; ++// sum += e*e; ++ if((unsigned)i > 255U) i= ~(i>>31); ++ dst[x + y*dst_stride]= i; ++ } ++ ++// printf("%f\n", sum/height/width); ++} ++ ++static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt){ ++ int h= (height+15)&(~15); ++ int i,j; ++ ++ vf->priv->stride= (width+15)&(~15); ++ for(j=0; j<4; j++){ ++ for(i=0; i<=vf->priv->depth; i++) ++ vf->priv->plane[i][j]= malloc(vf->priv->stride*h*sizeof(vf->priv->plane[0][0][0])); ++ } ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ }else{ ++ dmpi=vf->dmpi; ++ } ++ ++ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, 1); ++ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0); ++ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, 0); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ int i,j; ++ if(!vf->priv) return; ++ ++ for(j=0; j<4; j++){ ++ for(i=0; i<16; i++){ ++ free(vf->priv->plane[i][j]); ++ vf->priv->plane[i][j]= NULL; ++ } ++ } ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ vf->priv->depth= 8; ++ vf->priv->strength[0]= 1.0; ++ vf->priv->strength[1]= 1.0; ++ vf->priv->delta= 1.0; ++ ++ if (args) sscanf(args, "%d:%f:%f:%d:%f", &vf->priv->depth, ++ &vf->priv->strength[0], ++ &vf->priv->strength[1], ++ &vf->priv->mode, ++ &vf->priv->delta); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_ow = { ++ "overcomplete wavelet denoiser", ++ "ow", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_palette.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_palette.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_palette.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_palette.c 2012-05-14 14:08:54.766348677 +0200 +@@ -0,0 +1,236 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "mpbswap.h" ++ ++#include "libswscale/swscale.h" ++ ++#include "libavutil/avstring.h" ++ ++//===========================================================================// ++ ++// commented out 16 and 15 bit output support, because the conversion ++// routines are incorrrect. they assume the palette to be of the same ++// depth as the output, which is incorrect. --Joey ++ ++static const unsigned int bgr_list[]={ ++ IMGFMT_BGR32, ++ IMGFMT_BGR24, ++// IMGFMT_BGR16, ++// IMGFMT_BGR15, ++ 0 ++}; ++static const unsigned int rgb_list[]={ ++ IMGFMT_RGB32, ++ IMGFMT_RGB24, ++// IMGFMT_RGB16, ++// IMGFMT_RGB15, ++ 0 ++}; ++ ++/** ++ * Palette is assumed to contain BGR16, see rgb32to16 to convert the palette. ++ */ ++static void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++{ ++ long i; ++ for (i=0; inext->query_format(vf->next,*p); ++ mp_msg(MSGT_VFILTER,MSGL_DBG2,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); ++ if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo! ++ if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion ++ ++p; ++ } ++ return best; ++} ++ ++//===========================================================================// ++ ++struct vf_priv_s { ++ unsigned int fmt; ++ int pal_msg; ++}; ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ if (!vf->priv->fmt) ++ vf->priv->fmt=find_best(vf,outfmt); ++ if(!vf->priv->fmt){ ++ // no matching fmt, so force one... ++ if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32; ++ else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32; ++ else return 0; ++ } ++ return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ uint8_t *old_palette = mpi->planes[1]; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,vf->priv->fmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w, mpi->h); ++ ++ if (!mpi->planes[1]) ++ { ++ if(!vf->priv->pal_msg){ ++ mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name); ++ vf->priv->pal_msg=1; ++ } ++ mpi->planes[1] = (unsigned char*)gray_pal; ++ } ++ ++ if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ ++ // no stride conversion needed ++ switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ ++ case 15: ++ case 16: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ else ++ palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ break; ++ case 24: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ else ++ sws_convertPalette8ToPacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ break; ++ case 32: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ else ++ sws_convertPalette8ToPacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); ++ break; ++ } ++ } else { ++ int y; ++ for(y=0;yh;y++){ ++ unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; ++ unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0]; ++ switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ ++ case 15: ++ case 16: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); ++ else ++ palette8torgb16(src,dst,mpi->w,mpi->planes[1]); ++ break; ++ case 24: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]); ++ else ++ sws_convertPalette8ToPacked24(src,dst,mpi->w,mpi->planes[1]); ++ break; ++ case 32: ++ if (IMGFMT_IS_BGR(dmpi->imgfmt)) ++ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]); ++ else ++ sws_convertPalette8ToPacked32(src,dst,mpi->w,mpi->planes[1]); ++ break; ++ } ++ } ++ } ++ mpi->planes[1] = old_palette; ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ int best=find_best(vf,fmt); ++ if(!best) return 0; // no match ++ return vf->next->query_format(vf->next,best); ++} ++ ++static void uninit(vf_instance_t *vf) { ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ unsigned int i; ++ vf->config=config; ++ vf->uninit=uninit; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ for(i=0;i<256;i++) gray_pal[i]=0x01010101*i; ++ if (args) ++ { ++ if (!av_strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else ++ if (!av_strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else ++ if (!av_strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else ++ if (!av_strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else ++ if (!av_strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else ++ if (!av_strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else ++ if (!av_strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else ++ if (!av_strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else ++ { ++ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_UnknownFormatName, args); ++ return 0; ++ } ++ } ++ return 1; ++} ++ ++const vf_info_t vf_info_palette = { ++ "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", ++ "palette", ++ "A'rpi & Alex", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_perspective.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_perspective.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_perspective.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_perspective.c 2012-05-14 14:08:54.767348697 +0200 +@@ -0,0 +1,345 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "libavutil/mem.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#define SUB_PIXEL_BITS 8 ++#define SUB_PIXELS (1<ref; ++ int x,y; ++ ++ g= ( (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[2][1] - ref[3][1]) ++ - (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[2][0] - ref[3][0]))*H; ++ h= ( (ref[0][1] - ref[1][1] - ref[2][1] + ref[3][1])*(ref[1][0] - ref[3][0]) ++ - (ref[0][0] - ref[1][0] - ref[2][0] + ref[3][0])*(ref[1][1] - ref[3][1]))*W; ++ D= (ref[1][0] - ref[3][0])*(ref[2][1] - ref[3][1]) ++ - (ref[2][0] - ref[3][0])*(ref[1][1] - ref[3][1]); ++ ++ a= D*(ref[1][0] - ref[0][0])*H + g*ref[1][0]; ++ b= D*(ref[2][0] - ref[0][0])*W + h*ref[2][0]; ++ c= D*ref[0][0]*W*H; ++ d= D*(ref[1][1] - ref[0][1])*H + g*ref[1][1]; ++ e= D*(ref[2][1] - ref[0][1])*W + h*ref[2][1]; ++ f= D*ref[0][1]*W*H; ++ ++ for(y=0; ypv[x + y*W][0]= u; ++ priv->pv[x + y*W][1]= v; ++ } ++ } ++} ++ ++static double getCoeff(double d){ ++ double A= -0.60; ++ double coeff; ++ ++ d= fabs(d); ++ ++ // Equation is from VirtualDub ++ if(d<1.0) ++ coeff = (1.0 - (A+3.0)*d*d + (A+2.0)*d*d*d); ++ else if(d<2.0) ++ coeff = (-4.0*A + 8.0*A*d - 5.0*A*d*d + A*d*d*d); ++ else ++ coeff=0.0; ++ ++ return coeff; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int i, j; ++ ++ vf->priv->pvStride= width; ++ vf->priv->pv= av_malloc(width*height*2*sizeof(int32_t)); ++ initPv(vf->priv, width, height); ++ ++ for(i=0; ipriv->coeff[i][j]= (int)floor((1<priv) return; ++ ++ av_free(vf->priv->pv); ++ vf->priv->pv= NULL; ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++static inline void resampleCubic(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, struct vf_priv_s *privParam, int xShift, int yShift){ ++ int x, y; ++ struct vf_priv_s priv= *privParam; ++ ++ for(y=0; y>xShift; ++ v= priv.pv[sx + sy*priv.pvStride][1]>>yShift; ++ subU= u & (SUB_PIXELS-1); ++ subV= v & (SUB_PIXELS-1); ++ u >>= SUB_PIXEL_BITS; ++ v >>= SUB_PIXEL_BITS; ++ ++ if(u>0 && v>0 && u=h) iy=h-1; ++ for(dx=0; dx<4; dx++){ ++ int ix= u + dx - 1; ++ if (ix< 0) ix=0; ++ else if(ix>=w) ix=w-1; ++ ++ sum+= priv.coeff[subU][dx]*priv.coeff[subV][dy] ++ *src[ ix + iy*srcStride]; ++ } ++ } ++ } ++ sum= (sum + (1<<(COEFF_BITS*2-1)) ) >> (COEFF_BITS*2); ++ if(sum&~255){ ++ if(sum<0) sum=0; ++ else sum=255; ++ } ++ dst[ x + y*dstStride]= sum; ++ } ++ } ++} ++ ++static inline void resampleLinear(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, ++ struct vf_priv_s *privParam, int xShift, int yShift){ ++ int x, y; ++ struct vf_priv_s priv= *privParam; ++ ++ for(y=0; y>xShift; ++ v= priv.pv[sx + sy*priv.pvStride][1]>>yShift; ++ subU= u & (SUB_PIXELS-1); ++ subV= v & (SUB_PIXELS-1); ++ u >>= SUB_PIXEL_BITS; ++ v >>= SUB_PIXEL_BITS; ++ index= u + v*srcStride; ++ subUI= SUB_PIXELS - subU; ++ subVI= SUB_PIXELS - subV; ++ ++ if((unsigned)u < (unsigned)(w - 1)){ ++ if((unsigned)v < (unsigned)(h - 1)){ ++ sum= subVI*(subUI*src[index ] + subU*src[index +1]) ++ +subV *(subUI*src[index+srcStride] + subU*src[index+srcStride+1]); ++ sum= (sum + (1<<(SUB_PIXEL_BITS*2-1)) ) >> (SUB_PIXEL_BITS*2); ++ }else{ ++ if(v<0) v= 0; ++ else v= h-1; ++ index= u + v*srcStride; ++ sum= subUI*src[index] + subU*src[index+1]; ++ sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS; ++ } ++ }else{ ++ if((unsigned)v < (unsigned)(h - 1)){ ++ if(u<0) u= 0; ++ else u= w-1; ++ index= u + v*srcStride; ++ sum= subVI*src[index] + subV*src[index+srcStride]; ++ sum= (sum + (1<<(SUB_PIXEL_BITS-1)) ) >> SUB_PIXEL_BITS; ++ }else{ ++ if(u<0) u= 0; ++ else u= w-1; ++ if(v<0) v= 0; ++ else v= h-1; ++ index= u + v*srcStride; ++ sum= src[index]; ++ } ++ } ++ if(sum&~255){ ++ if(sum<0) sum=0; ++ else sum=255; ++ } ++ dst[ x + y*dstStride]= sum; ++ } ++ } ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ ++ assert(mpi->flags&MP_IMGFLAG_PLANAR); ++ ++ if(vf->priv->cubic){ ++ resampleCubic(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], ++ vf->priv, 0, 0); ++ resampleCubic(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], ++ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift); ++ resampleCubic(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], ++ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift); ++ }else{ ++ resampleLinear(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], ++ vf->priv, 0, 0); ++ resampleLinear(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], ++ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift); ++ resampleLinear(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], ++ vf->priv, mpi->chroma_x_shift, mpi->chroma_y_shift); ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ int e; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++// vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if(args==NULL) return 0; ++ ++ e=sscanf(args, "%lf:%lf:%lf:%lf:%lf:%lf:%lf:%lf:%d", ++ &vf->priv->ref[0][0], &vf->priv->ref[0][1], ++ &vf->priv->ref[1][0], &vf->priv->ref[1][1], ++ &vf->priv->ref[2][0], &vf->priv->ref[2][1], ++ &vf->priv->ref[3][0], &vf->priv->ref[3][1], ++ &vf->priv->cubic ++ ); ++ ++ if(e!=9) ++ return 0; ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_perspective = { ++ "perspective correcture", ++ "perspective", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_phase.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_phase.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_phase.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_phase.c 2012-05-14 14:08:54.768348717 +0200 +@@ -0,0 +1,301 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++enum mode { PROGRESSIVE, TOP_FIRST, BOTTOM_FIRST, ++ TOP_FIRST_ANALYZE, BOTTOM_FIRST_ANALYZE, ++ ANALYZE, FULL_ANALYZE, AUTO, AUTO_ANALYZE }; ++ ++#define fixed_mode(p) ((p)<=BOTTOM_FIRST) ++ ++struct vf_priv_s ++ { ++ enum mode mode; ++ int verbose; ++ unsigned char *buf[3]; ++ }; ++ ++/* ++ * Copy fields from either current or buffered previous frame to the ++ * output and store the current frame unmodified to the buffer. ++ */ ++ ++static void do_plane(unsigned char *to, unsigned char *from, ++ int w, int h, int ts, int fs, ++ unsigned char **bufp, enum mode mode) ++ { ++ unsigned char *buf, *end; ++ int top; ++ ++ if(!*bufp) ++ { ++ mode=PROGRESSIVE; ++ if(!(*bufp=malloc(h*w))) return; ++ } ++ ++ for(end=to+h*ts, buf=*bufp, top=1; tonext, mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w, mpi->h))) ++ return 0; ++ ++ w=dmpi->w; ++ if(!(dmpi->flags&MP_IMGFLAG_PLANAR)) ++ w*=dmpi->bpp/8; ++ ++ mode=vf->priv->mode; ++ ++ if(!vf->priv->buf[0]) ++ mode=PROGRESSIVE; ++ else ++ mode=analyze_plane(vf->priv->buf[0], mpi->planes[0], ++ w, dmpi->h, w, mpi->stride[0], mode, ++ vf->priv->verbose, mpi->fields); ++ ++ do_plane(dmpi->planes[0], mpi->planes[0], ++ w, dmpi->h, ++ dmpi->stride[0], mpi->stride[0], ++ &vf->priv->buf[0], mode); ++ ++ if(dmpi->flags&MP_IMGFLAG_PLANAR) ++ { ++ do_plane(dmpi->planes[1], mpi->planes[1], ++ dmpi->chroma_width, dmpi->chroma_height, ++ dmpi->stride[1], mpi->stride[1], ++ &vf->priv->buf[1], mode); ++ do_plane(dmpi->planes[2], mpi->planes[2], ++ dmpi->chroma_width, dmpi->chroma_height, ++ dmpi->stride[2], mpi->stride[2], ++ &vf->priv->buf[2], mode); ++ } ++ ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ ++static void uninit(struct vf_instance *vf) ++ { ++ free(vf->priv->buf[0]); ++ free(vf->priv->buf[1]); ++ free(vf->priv->buf[2]); ++ free(vf->priv); ++ } ++ ++static int vf_open(vf_instance_t *vf, char *args) ++ { ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ ++ if(!(vf->priv = calloc(1, sizeof(struct vf_priv_s)))) ++ { ++ uninit(vf); ++ return 0; ++ } ++ ++ vf->priv->mode=AUTO_ANALYZE; ++ vf->priv->verbose=0; ++ ++ while(args && *args) ++ { ++ switch(*args) ++ { ++ case 't': vf->priv->mode=TOP_FIRST; break; ++ case 'a': vf->priv->mode=AUTO; break; ++ case 'b': vf->priv->mode=BOTTOM_FIRST; break; ++ case 'u': vf->priv->mode=ANALYZE; break; ++ case 'T': vf->priv->mode=TOP_FIRST_ANALYZE; break; ++ case 'A': vf->priv->mode=AUTO_ANALYZE; break; ++ case 'B': vf->priv->mode=BOTTOM_FIRST_ANALYZE; break; ++ case 'U': vf->priv->mode=FULL_ANALYZE; break; ++ case 'p': vf->priv->mode=PROGRESSIVE; break; ++ case 'v': vf->priv->verbose=1; break; ++ case ':': break; ++ ++ default: ++ uninit(vf); ++ return 0; /* bad args */ ++ } ++ ++ if( (args=strchr(args, ':')) ) args++; ++ } ++ ++ return 1; ++ } ++ ++const vf_info_t vf_info_phase = ++ { ++ "phase shift fields", ++ "phase", ++ "Ville Saari", ++ "", ++ vf_open, ++ NULL ++ }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_pp7.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_pp7.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_pp7.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_pp7.c 2012-05-14 14:08:54.770348757 +0200 +@@ -0,0 +1,493 @@ ++/* ++ * Copyright (C) 2005 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "libavutil/mem.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++ ++#define XMIN(a,b) ((a) < (b) ? (a) : (b)) ++#define XMAX(a,b) ((a) > (b) ? (a) : (b)) ++ ++typedef short DCTELEM; ++ ++//===========================================================================// ++static const uint8_t __attribute__((aligned(8))) dither[8][8]={ ++{ 0, 48, 12, 60, 3, 51, 15, 63, }, ++{ 32, 16, 44, 28, 35, 19, 47, 31, }, ++{ 8, 56, 4, 52, 11, 59, 7, 55, }, ++{ 40, 24, 36, 20, 43, 27, 39, 23, }, ++{ 2, 50, 14, 62, 1, 49, 13, 61, }, ++{ 34, 18, 46, 30, 33, 17, 45, 29, }, ++{ 10, 58, 6, 54, 9, 57, 5, 53, }, ++{ 42, 26, 38, 22, 41, 25, 37, 21, }, ++}; ++ ++struct vf_priv_s { ++ int qp; ++ int mode; ++ int mpeg2; ++ int temp_stride; ++ uint8_t *src; ++}; ++#if 0 ++static inline void dct7_c(DCTELEM *dst, int s0, int s1, int s2, int s3, int step){ ++ int s, d; ++ int dst2[64]; ++//#define S0 (1024/0.37796447300922719759) ++#define C0 ((int)(1024*0.37796447300922719759+0.5)) //sqrt(1/7) ++#define C1 ((int)(1024*0.53452248382484879308/6+0.5)) //sqrt(2/7)/6 ++ ++#define C2 ((int)(1024*0.45221175985034745004/2+0.5)) ++#define C3 ((int)(1024*0.36264567479870879474/2+0.5)) ++ ++//0.1962505182412941918 0.0149276808419397944-0.2111781990832339584 ++#define C4 ((int)(1024*0.1962505182412941918+0.5)) ++#define C5 ((int)(1024*0.0149276808419397944+0.5)) ++//#define C6 ((int)(1024*0.2111781990832339584+0.5)) ++#if 0 ++ s= s0 + s1 + s2; ++ dst[0*step] = ((s + s3)*C0 + 512) >> 10; ++ s= (s - 6*s3)*C1 + 512; ++ d= (s0-s2)*C4 + (s1-s2)*C5; ++ dst[1*step] = (s + 2*d)>>10; ++ s -= d; ++ d= (s1-s0)*C2 + (s1-s2)*C3; ++ dst[2*step] = (s + d)>>10; ++ dst[3*step] = (s - d)>>10; ++#elif 1 ++ s = s3+s3; ++ s3= s-s0; ++ s0= s+s0; ++ s = s2+s1; ++ s2= s2-s1; ++ dst[0*step]= s0 + s; ++ dst[2*step]= s0 - s; ++ dst[1*step]= 2*s3 + s2; ++ dst[3*step]= s3 - 2*s2; ++#else ++ int i,j,n=7; ++ for(i=0; i<7; i+=2){ ++ dst2[i*step/2]= 0; ++ for(j=0; j<4; j++) ++ dst2[i*step/2] += src[j*step] * cos(i*M_PI/n*(j+0.5)) * sqrt((i?2.0:1.0)/n); ++ if(fabs(dst2[i*step/2] - dst[i*step/2]) > 20) ++ printf("%d %d %d (%d %d %d %d) -> (%d %d %d %d)\n", i,dst2[i*step/2], dst[i*step/2],src[0*step], src[1*step], src[2*step], src[3*step], dst[0*step], dst[1*step],dst[2*step],dst[3*step]); ++ } ++#endif ++} ++#endif ++ ++static inline void dctA_c(DCTELEM *dst, uint8_t *src, int stride){ ++ int i; ++ ++ for(i=0; i<4; i++){ ++ int s0= src[0*stride] + src[6*stride]; ++ int s1= src[1*stride] + src[5*stride]; ++ int s2= src[2*stride] + src[4*stride]; ++ int s3= src[3*stride]; ++ int s= s3+s3; ++ s3= s-s0; ++ s0= s+s0; ++ s = s2+s1; ++ s2= s2-s1; ++ dst[0]= s0 + s; ++ dst[2]= s0 - s; ++ dst[1]= 2*s3 + s2; ++ dst[3]= s3 - 2*s2; ++ src++; ++ dst+=4; ++ } ++} ++ ++static void dctB_c(DCTELEM *dst, DCTELEM *src){ ++ int i; ++ ++ for(i=0; i<4; i++){ ++ int s0= src[0*4] + src[6*4]; ++ int s1= src[1*4] + src[5*4]; ++ int s2= src[2*4] + src[4*4]; ++ int s3= src[3*4]; ++ int s= s3+s3; ++ s3= s-s0; ++ s0= s+s0; ++ s = s2+s1; ++ s2= s2-s1; ++ dst[0*4]= s0 + s; ++ dst[2*4]= s0 - s; ++ dst[1*4]= 2*s3 + s2; ++ dst[3*4]= s3 - 2*s2; ++ src++; ++ dst++; ++ } ++} ++ ++#if HAVE_MMX ++static void dctB_mmx(DCTELEM *dst, DCTELEM *src){ ++ __asm__ volatile ( ++ "movq (%0), %%mm0 \n\t" ++ "movq 1*4*2(%0), %%mm1 \n\t" ++ "paddw 6*4*2(%0), %%mm0 \n\t" ++ "paddw 5*4*2(%0), %%mm1 \n\t" ++ "movq 2*4*2(%0), %%mm2 \n\t" ++ "movq 3*4*2(%0), %%mm3 \n\t" ++ "paddw 4*4*2(%0), %%mm2 \n\t" ++ "paddw %%mm3, %%mm3 \n\t" //s ++ "movq %%mm3, %%mm4 \n\t" //s ++ "psubw %%mm0, %%mm3 \n\t" //s-s0 ++ "paddw %%mm0, %%mm4 \n\t" //s+s0 ++ "movq %%mm2, %%mm0 \n\t" //s2 ++ "psubw %%mm1, %%mm2 \n\t" //s2-s1 ++ "paddw %%mm1, %%mm0 \n\t" //s2+s1 ++ "movq %%mm4, %%mm1 \n\t" //s0' ++ "psubw %%mm0, %%mm4 \n\t" //s0'-s' ++ "paddw %%mm0, %%mm1 \n\t" //s0'+s' ++ "movq %%mm3, %%mm0 \n\t" //s3' ++ "psubw %%mm2, %%mm3 \n\t" ++ "psubw %%mm2, %%mm3 \n\t" ++ "paddw %%mm0, %%mm2 \n\t" ++ "paddw %%mm0, %%mm2 \n\t" ++ "movq %%mm1, (%1) \n\t" ++ "movq %%mm4, 2*4*2(%1) \n\t" ++ "movq %%mm2, 1*4*2(%1) \n\t" ++ "movq %%mm3, 3*4*2(%1) \n\t" ++ :: "r" (src), "r"(dst) ++ ); ++} ++#endif ++ ++static void (*dctB)(DCTELEM *dst, DCTELEM *src)= dctB_c; ++ ++#define N0 4 ++#define N1 5 ++#define N2 10 ++#define SN0 2 ++#define SN1 2.2360679775 ++#define SN2 3.16227766017 ++#define N (1<<16) ++ ++static const int factor[16]={ ++ N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2), ++ N/(N1*N0), N/(N1*N1), N/(N1*N0),N/(N1*N2), ++ N/(N0*N0), N/(N0*N1), N/(N0*N0),N/(N0*N2), ++ N/(N2*N0), N/(N2*N1), N/(N2*N0),N/(N2*N2), ++}; ++ ++static const int thres[16]={ ++ N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2), ++ N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2), ++ N/(SN0*SN0), N/(SN0*SN2), N/(SN0*SN0),N/(SN0*SN2), ++ N/(SN2*SN0), N/(SN2*SN2), N/(SN2*SN0),N/(SN2*SN2), ++}; ++ ++static int thres2[99][16]; ++ ++static void init_thres2(void){ ++ int qp, i; ++ int bias= 0; //FIXME ++ ++ for(qp=0; qp<99; qp++){ ++ for(i=0; i<16; i++){ ++ thres2[qp][i]= ((i&1)?SN2:SN0) * ((i&4)?SN2:SN0) * XMAX(1,qp) * (1<<2) - 1 - bias; ++ } ++ } ++} ++ ++static int hardthresh_c(DCTELEM *src, int qp){ ++ int i; ++ int a; ++ ++ a= src[0] * factor[0]; ++ for(i=1; i<16; i++){ ++ unsigned int threshold1= thres2[qp][i]; ++ unsigned int threshold2= (threshold1<<1); ++ int level= src[i]; ++ if(((unsigned)(level+threshold1))>threshold2){ ++ a += level * factor[i]; ++ } ++ } ++ return (a + (1<<11))>>12; ++} ++ ++static int mediumthresh_c(DCTELEM *src, int qp){ ++ int i; ++ int a; ++ ++ a= src[0] * factor[0]; ++ for(i=1; i<16; i++){ ++ unsigned int threshold1= thres2[qp][i]; ++ unsigned int threshold2= (threshold1<<1); ++ int level= src[i]; ++ if(((unsigned)(level+threshold1))>threshold2){ ++ if(((unsigned)(level+2*threshold1))>2*threshold2){ ++ a += level * factor[i]; ++ }else{ ++ if(level>0) a+= 2*(level - (int)threshold1)*factor[i]; ++ else a+= 2*(level + (int)threshold1)*factor[i]; ++ } ++ } ++ } ++ return (a + (1<<11))>>12; ++} ++ ++static int softthresh_c(DCTELEM *src, int qp){ ++ int i; ++ int a; ++ ++ a= src[0] * factor[0]; ++ for(i=1; i<16; i++){ ++ unsigned int threshold1= thres2[qp][i]; ++ unsigned int threshold2= (threshold1<<1); ++ int level= src[i]; ++ if(((unsigned)(level+threshold1))>threshold2){ ++ if(level>0) a+= (level - (int)threshold1)*factor[i]; ++ else a+= (level + (int)threshold1)*factor[i]; ++ } ++ } ++ return (a + (1<<11))>>12; ++} ++ ++static int (*requantize)(DCTELEM *src, int qp)= hardthresh_c; ++ ++static void filter(struct vf_priv_s *p, uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, uint8_t *qp_store, int qp_stride, int is_luma){ ++ int x, y; ++ const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); ++ uint8_t *p_src= p->src + 8*stride; ++ DCTELEM *block= (DCTELEM *)p->src; ++ DCTELEM *temp= (DCTELEM *)(p->src + 32); ++ ++ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace ++ for(y=0; yqp) ++ qp= p->qp; ++ else{ ++ qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride]; ++ qp=norm_qscale(qp, p->mpeg2); ++ } ++ for(; x>6; ++ if((unsigned)v > 255) ++ v= (-v)>>31; ++ dst[x + y*dst_stride]= v; ++ } ++ } ++ } ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int h= (height+16+15)&(~15); ++ ++ vf->priv->temp_stride= (width+16+15)&(~15); ++ vf->priv->src = av_malloc(vf->priv->temp_stride*(h+8)*sizeof(uint8_t)); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(mpi->flags&MP_IMGFLAG_DIRECT){ ++ dmpi=vf->dmpi; ++ }else{ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ } ++ ++ vf->priv->mpeg2= mpi->qscale_type; ++ if(mpi->qscale || vf->priv->qp){ ++ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, mpi->qscale, mpi->qstride, 1); ++ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0); ++ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, mpi->qscale, mpi->qstride, 0); ++ }else{ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); ++#endif ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ av_free(vf->priv->src); ++ vf->priv->src= NULL; ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int control(struct vf_instance *vf, int request, void* data){ ++ return vf_next_control(vf,request,data); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->control= control; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if (args) sscanf(args, "%d:%d", &vf->priv->qp, &vf->priv->mode); ++ ++ if(vf->priv->qp < 0) ++ vf->priv->qp = 0; ++ ++ init_thres2(); ++ ++ switch(vf->priv->mode){ ++ case 0: requantize= hardthresh_c; break; ++ case 1: requantize= softthresh_c; break; ++ default: ++ case 2: requantize= mediumthresh_c; break; ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX){ ++ dctB= dctB_mmx; ++ } ++#endif ++#if 0 ++ if(gCpuCaps.hasMMX){ ++ switch(vf->priv->mode){ ++ case 0: requantize= hardthresh_mmx; break; ++ case 1: requantize= softthresh_mmx; break; ++ } ++ } ++#endif ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_pp7 = { ++ "postprocess 7", ++ "pp7", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_pullup.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_pullup.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_pullup.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_pullup.c 2012-05-14 14:08:54.771348777 +0200 +@@ -0,0 +1,314 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++#include "pullup.h" ++ ++#undef MAX ++#define MAX(a,b) ((a)>(b)?(a):(b)) ++ ++struct vf_priv_s { ++ struct pullup_context *ctx; ++ int init; ++ int fakecount; ++ char *qbuf; ++}; ++ ++static void init_pullup(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ struct pullup_context *c = vf->priv->ctx; ++ ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ c->format = PULLUP_FMT_Y; ++ c->nplanes = 4; ++ pullup_preinit_context(c); ++ c->bpp[0] = c->bpp[1] = c->bpp[2] = 8; ++ c->w[0] = mpi->w; ++ c->h[0] = mpi->h; ++ c->w[1] = c->w[2] = mpi->chroma_width; ++ c->h[1] = c->h[2] = mpi->chroma_height; ++ c->w[3] = ((mpi->w+15)/16) * ((mpi->h+15)/16); ++ c->h[3] = 2; ++ c->stride[0] = mpi->width; ++ c->stride[1] = c->stride[2] = mpi->chroma_width; ++ c->stride[3] = c->w[3]; ++ c->background[1] = c->background[2] = 128; ++ } ++ ++ if (gCpuCaps.hasMMX) c->cpu |= PULLUP_CPU_MMX; ++ if (gCpuCaps.hasMMX2) c->cpu |= PULLUP_CPU_MMX2; ++ if (gCpuCaps.has3DNow) c->cpu |= PULLUP_CPU_3DNOW; ++ if (gCpuCaps.has3DNowExt) c->cpu |= PULLUP_CPU_3DNOWEXT; ++ if (gCpuCaps.hasSSE) c->cpu |= PULLUP_CPU_SSE; ++ if (gCpuCaps.hasSSE2) c->cpu |= PULLUP_CPU_SSE2; ++ ++ pullup_init_context(c); ++ ++ vf->priv->init = 1; ++ vf->priv->qbuf = malloc(c->w[3]); ++} ++ ++ ++#if 0 ++static void get_image(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ struct pullup_context *c = vf->priv->ctx; ++ struct pullup_buffer *b; ++ ++ if (mpi->type == MP_IMGTYPE_STATIC) return; ++ ++ if (!vf->priv->init) init_pullup(vf, mpi); ++ ++ b = pullup_get_buffer(c, 2); ++ if (!b) return; /* shouldn't happen... */ ++ ++ mpi->priv = b; ++ ++ mpi->planes[0] = b->planes[0]; ++ mpi->planes[1] = b->planes[1]; ++ mpi->planes[2] = b->planes[2]; ++ mpi->stride[0] = c->stride[0]; ++ mpi->stride[1] = c->stride[1]; ++ mpi->stride[2] = c->stride[2]; ++ ++ mpi->flags |= MP_IMGFLAG_DIRECT; ++ mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; ++} ++#endif ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ struct pullup_context *c = vf->priv->ctx; ++ struct pullup_buffer *b; ++ struct pullup_frame *f; ++ mp_image_t *dmpi; ++ int ret; ++ int p; ++ int i; ++ ++ if (!vf->priv->init) init_pullup(vf, mpi); ++ ++ if (mpi->flags & MP_IMGFLAG_DIRECT) { ++ b = mpi->priv; ++ mpi->priv = 0; ++ } else { ++ b = pullup_get_buffer(c, 2); ++ if (!b) { ++ mp_msg(MSGT_VFILTER,MSGL_ERR,"Could not get buffer from pullup!\n"); ++ f = pullup_get_frame(c); ++ pullup_release_frame(f); ++ return 0; ++ } ++ memcpy_pic(b->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ c->stride[0], mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(b->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ c->stride[1], mpi->stride[1]); ++ memcpy_pic(b->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ c->stride[2], mpi->stride[2]); ++ } ++ } ++ if (mpi->qscale) { ++ fast_memcpy(b->planes[3], mpi->qscale, c->w[3]); ++ fast_memcpy(b->planes[3]+c->w[3], mpi->qscale, c->w[3]); ++ } ++ ++ p = mpi->fields & MP_IMGFIELD_TOP_FIRST ? 0 : ++ (mpi->fields & MP_IMGFIELD_ORDERED ? 1 : 0); ++ pullup_submit_field(c, b, p); ++ pullup_submit_field(c, b, p^1); ++ if (mpi->fields & MP_IMGFIELD_REPEAT_FIRST) ++ pullup_submit_field(c, b, p); ++ ++ pullup_release_buffer(b, 2); ++ ++ f = pullup_get_frame(c); ++ ++ /* Fake yes for first few frames (buffer depth) to keep from ++ * breaking A/V sync with G1's bad architecture... */ ++ if (!f) return vf->priv->fakecount ? (--vf->priv->fakecount,1) : 0; ++ ++ if (f->length < 2) { ++ pullup_release_frame(f); ++ f = pullup_get_frame(c); ++ if (!f) return 0; ++ if (f->length < 2) { ++ pullup_release_frame(f); ++ if (!(mpi->fields & MP_IMGFIELD_REPEAT_FIRST)) ++ return 0; ++ f = pullup_get_frame(c); ++ if (!f) return 0; ++ if (f->length < 2) { ++ pullup_release_frame(f); ++ return 0; ++ } ++ } ++ } ++ ++#if 0 ++ /* Average qscale tables from both frames. */ ++ if (mpi->qscale) { ++ for (i=0; iw[3]; i++) { ++ vf->priv->qbuf[i] = (f->ofields[0]->planes[3][i] ++ + f->ofields[1]->planes[3][i+c->w[3]])>>1; ++ } ++ } ++#else ++ /* Take worst of qscale tables from both frames. */ ++ if (mpi->qscale) { ++ for (i=0; iw[3]; i++) { ++ vf->priv->qbuf[i] = MAX(f->ofields[0]->planes[3][i], f->ofields[1]->planes[3][i+c->w[3]]); ++ } ++ } ++#endif ++ ++ /* If the frame isn't already exportable... */ ++ while (!f->buffer) { ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->width, mpi->height); ++ /* FIXME: Is it ok to discard dmpi if it's not direct? */ ++ if (!(dmpi->flags & MP_IMGFLAG_DIRECT)) { ++ pullup_pack_frame(c, f); ++ break; ++ } ++ /* Direct render fields into output buffer */ ++ my_memcpy_pic(dmpi->planes[0], f->ofields[0]->planes[0], ++ mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); ++ my_memcpy_pic(dmpi->planes[0] + dmpi->stride[0], ++ f->ofields[1]->planes[0] + c->stride[0], ++ mpi->w, mpi->h/2, dmpi->stride[0]*2, c->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], f->ofields[0]->planes[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, c->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[1] + dmpi->stride[1], ++ f->ofields[1]->planes[1] + c->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, c->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], f->ofields[0]->planes[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, c->stride[2]*2); ++ my_memcpy_pic(dmpi->planes[2] + dmpi->stride[2], ++ f->ofields[1]->planes[2] + c->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, c->stride[2]*2); ++ } ++ pullup_release_frame(f); ++ if (mpi->qscale) { ++ dmpi->qscale = vf->priv->qbuf; ++ dmpi->qstride = mpi->qstride; ++ dmpi->qscale_type = mpi->qscale_type; ++ } ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->width, mpi->height); ++ ++ dmpi->planes[0] = f->buffer->planes[0]; ++ dmpi->planes[1] = f->buffer->planes[1]; ++ dmpi->planes[2] = f->buffer->planes[2]; ++ ++ dmpi->stride[0] = c->stride[0]; ++ dmpi->stride[1] = c->stride[1]; ++ dmpi->stride[2] = c->stride[2]; ++ ++ if (mpi->qscale) { ++ dmpi->qscale = vf->priv->qbuf; ++ dmpi->qstride = mpi->qstride; ++ dmpi->qscale_type = mpi->qscale_type; ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ pullup_release_frame(f); ++ return ret; ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - support more formats */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ if (height&3) return 0; ++ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ pullup_free_context(vf->priv->ctx); ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ struct pullup_context *c; ++ //vf->get_image = get_image; ++ vf->put_image = put_image; ++ vf->config = config; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ p->ctx = c = pullup_alloc_context(); ++ p->fakecount = 1; ++ c->verbose = 1; ++ c->junk_left = c->junk_right = 1; ++ c->junk_top = c->junk_bottom = 4; ++ c->strict_breaks = 0; ++ c->metric_plane = 0; ++ if (args) { ++ sscanf(args, "%d:%d:%d:%d:%d:%d", &c->junk_left, &c->junk_right, &c->junk_top, &c->junk_bottom, &c->strict_breaks, &c->metric_plane); ++ } ++ return 1; ++} ++ ++const vf_info_t vf_info_pullup = { ++ "pullup (from field sequence to frames)", ++ "pullup", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_qp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_qp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_qp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_qp.c 2012-05-14 14:08:54.772348797 +0200 +@@ -0,0 +1,177 @@ ++/* ++ * Copyright (C) 2004 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++ ++#include "libavcodec/avcodec.h" ++#include "libavutil/eval.h" ++ ++ ++struct vf_priv_s { ++ char eq[200]; ++ int8_t *qp; ++ int8_t lut[257]; ++ int qp_stride; ++}; ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int h= (height+15)>>4; ++ int i; ++ ++ vf->priv->qp_stride= (width+15)>>4; ++ vf->priv->qp= av_malloc(vf->priv->qp_stride*h*sizeof(int8_t)); ++ ++ for(i=-129; i<128; i++){ ++ double const_values[]={ ++ M_PI, ++ M_E, ++ i != -129, ++ i, ++ 0 ++ }; ++ static const char *const_names[]={ ++ "PI", ++ "E", ++ "known", ++ "qp", ++ NULL ++ }; ++ double temp_val; ++ int res; ++ ++ res= av_expr_parse_and_eval(&temp_val, vf->priv->eq, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, NULL); ++ ++ if (res < 0){ ++ mp_msg(MSGT_VFILTER, MSGL_ERR, "qp: Error evaluating \"%s\" \n", vf->priv->eq); ++ return 0; ++ } ++ vf->priv->lut[i+129]= lrintf(temp_val); ++ } ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags, mpi->w, mpi->h); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ int x,y; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->w,mpi->h); ++ } ++ ++ dmpi= vf->dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); ++ } ++ } ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++ dmpi->qscale = vf->priv->qp; ++ dmpi->qstride= vf->priv->qp_stride; ++ if(mpi->qscale){ ++ for(y=0; y<((dmpi->h+15)>>4); y++){ ++ for(x=0; xpriv->qp_stride; x++){ ++ dmpi->qscale[x + dmpi->qstride*y]= ++ vf->priv->lut[ 129 + ((int8_t)mpi->qscale[x + mpi->qstride*y]) ]; ++ } ++ } ++ }else{ ++ int qp= vf->priv->lut[0]; ++ for(y=0; y<((dmpi->h+15)>>4); y++){ ++ for(x=0; xpriv->qp_stride; x++){ ++ dmpi->qscale[x + dmpi->qstride*y]= qp; ++ } ++ } ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ av_free(vf->priv->qp); ++ vf->priv->qp= NULL; ++ ++ av_free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->uninit=uninit; ++ vf->priv=av_malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++// avcodec_init(); ++ ++ if (args) strncpy(vf->priv->eq, args, 199); ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_qp = { ++ "QP changer", ++ "qp", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_rectangle.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_rectangle.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_rectangle.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_rectangle.c 2012-05-14 14:08:54.773348817 +0200 +@@ -0,0 +1,181 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include "mp_image.h" ++#include "mp_msg.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++#include "libavutil/common.h" ++ ++struct vf_priv_s { ++ int x, y, w, h; ++}; ++ ++static int ++config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ if (vf->priv->w < 0 || width < vf->priv->w) ++ vf->priv->w = width; ++ if (vf->priv->h < 0 || height < vf->priv->h) ++ vf->priv->h = height; ++ if (vf->priv->x < 0) ++ vf->priv->x = (width - vf->priv->w) / 2; ++ if (vf->priv->y < 0) ++ vf->priv->y = (height - vf->priv->h) / 2; ++ if (vf->priv->w + vf->priv->x > width ++ || vf->priv->h + vf->priv->y > height) { ++ mp_msg(MSGT_VFILTER,MSGL_WARN,"rectangle: bad position/width/height - rectangle area is out of the original!\n"); ++ return 0; ++ } ++ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); ++} ++ ++static int ++control(struct vf_instance *vf, int request, void *data) ++{ ++ const int *const tmp = data; ++ switch(request){ ++ case VFCTRL_CHANGE_RECTANGLE: ++ switch (tmp[0]){ ++ case 0: ++ vf->priv->w += tmp[1]; ++ return 1; ++ break; ++ case 1: ++ vf->priv->h += tmp[1]; ++ return 1; ++ break; ++ case 2: ++ vf->priv->x += tmp[1]; ++ return 1; ++ break; ++ case 3: ++ vf->priv->y += tmp[1]; ++ return 1; ++ break; ++ default: ++ mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]); ++ return 0; ++ } ++ } ++ return vf_next_control(vf, request, data); ++ return 0; ++} ++static int ++put_image(struct vf_instance *vf, mp_image_t* mpi, double pts){ ++ mp_image_t* dmpi; ++ unsigned int bpp = mpi->bpp / 8; ++ int x, y, w, h; ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->w, mpi->h); ++ ++ memcpy_pic(dmpi->planes[0],mpi->planes[0],mpi->w*bpp, mpi->h, ++ dmpi->stride[0],mpi->stride[0]); ++ if(mpi->flags&MP_IMGFLAG_PLANAR && mpi->flags&MP_IMGFLAG_YUV){ ++ memcpy_pic(dmpi->planes[1],mpi->planes[1], ++ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, ++ dmpi->stride[1],mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2],mpi->planes[2], ++ mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, ++ dmpi->stride[2],mpi->stride[2]); ++ } ++ ++ /* Draw the rectangle */ ++ ++ mp_msg(MSGT_VFILTER,MSGL_INFO, "rectangle: -vf rectangle=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y); ++ ++ x = FFMIN(vf->priv->x, dmpi->width); ++ x = FFMAX(x, 0); ++ ++ w = vf->priv->x + vf->priv->w - 1 - x; ++ w = FFMIN(w, dmpi->width - x); ++ w = FFMAX(w, 0); ++ ++ y = FFMIN(vf->priv->y, dmpi->height); ++ y = FFMAX(y, 0); ++ ++ h = vf->priv->y + vf->priv->h - 1 - y; ++ h = FFMIN(h, dmpi->height - y); ++ h = FFMAX(h, 0); ++ ++ if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) { ++ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; ++ unsigned int count = w * bpp; ++ while (count--) ++ p[count] = 0xff - p[count]; ++ } ++ if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) { ++ unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp; ++ unsigned int count = w * bpp; ++ while (count--) ++ p[count] = 0xff - p[count]; ++ } ++ if (0 <= vf->priv->x && vf->priv->x <= dmpi->width) { ++ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; ++ unsigned int count = h; ++ while (count--) { ++ unsigned int i = bpp; ++ while (i--) ++ p[i] = 0xff - p[i]; ++ p += dmpi->stride[0]; ++ } ++ } ++ if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) { ++ unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp; ++ unsigned int count = h; ++ while (count--) { ++ unsigned int i = bpp; ++ while (i--) ++ p[i] = 0xff - p[i]; ++ p += dmpi->stride[0]; ++ } ++ } ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static int ++vf_open(vf_instance_t *vf, char *args) { ++ vf->config = config; ++ vf->control = control; ++ vf->put_image = put_image; ++ vf->priv = malloc(sizeof(struct vf_priv_s)); ++ vf->priv->x = -1; ++ vf->priv->y = -1; ++ vf->priv->w = -1; ++ vf->priv->h = -1; ++ if (args) ++ sscanf(args, "%d:%d:%d:%d", ++ &vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y); ++ return 1; ++} ++ ++const vf_info_t vf_info_rectangle = { ++ "draw rectangle", ++ "rectangle", ++ "Kim Minh Kaplan", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_remove_logo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_remove_logo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_remove_logo.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_remove_logo.c 2012-05-14 14:08:54.776348877 +0200 +@@ -0,0 +1,906 @@ ++/* ++ * This filter loads a .pgm mask file showing where a logo is and uses ++ * a blur transform to remove the logo. ++ * ++ * Copyright (C) 2005 Robert Edele ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * \file ++ * ++ * \brief Advanced blur-based logo removing filter. ++ ++ * Hello and welcome. This code implements a filter to remove annoying TV ++ * logos and other annoying images placed onto a video stream. It works by filling ++ * in the pixels that comprise the logo with neighboring pixels. The transform is ++ * very loosely based on a gaussian blur, but it is different enough to merit its ++ * own paragraph later on. It is a major improvement on the old delogo filter as ++ * it both uses a better blurring algorithm and uses a bitmap to use an arbitrary ++ * and generally much tighter fitting shape than a rectangle. ++ * ++ * The filter requires 1 argument and has no optional arguments. It requires ++ * a filter bitmap, which must be in PGM or PPM format. A sample invocation would ++ * be -vf remove_logo=/home/username/logo_bitmaps/xyz.pgm. Pixels with a value of ++ * zero are not part of the logo, and non-zero pixels are part of the logo. If you ++ * use white (255) for the logo and black (0) for the rest, you will be safe. For ++ * making the filter bitmap, I recommend taking a screen capture of a black frame ++ * with the logo visible, and then using The GIMP's threshold filter followed by ++ * the erode filter once or twice. If needed, little splotches can be fixed ++ * manually. Remember that if logo pixels are not covered, the filter quality will ++ * be much reduced. Marking too many pixels as part of the logo doesn't hurt as ++ * much, but it will increase the amount of blurring needed to cover over the ++ * image and will destroy more information than necessary. Additionally, this blur ++ * algorithm is O(n) = n^4, where n is the width and height of a hypothetical ++ * square logo, so extra pixels will slow things down on a large lo ++ * ++ * The logo removal algorithm has two key points. The first is that it ++ * distinguishes between pixels in the logo and those not in the logo by using the ++ * passed-in bitmap. Pixels not in the logo are copied over directly without being ++ * modified and they also serve as source pixels for the logo fill-in. Pixels ++ * inside the logo have the mask applied. ++ * ++ * At init-time the bitmap is reprocessed internally, and the distance to the ++ * nearest edge of the logo (Manhattan distance), along with a little extra to ++ * remove rough edges, is stored in each pixel. This is done using an in-place ++ * erosion algorithm, and incrementing each pixel that survives any given erosion. ++ * Once every pixel is eroded, the maximum value is recorded, and a set of masks ++ * from size 0 to this size are generaged. The masks are circular binary masks, ++ * where each pixel within a radius N (where N is the size of the mask) is a 1, ++ * and all other pixels are a 0. Although a gaussian mask would be more ++ * mathematically accurate, a binary mask works better in practice because we ++ * generally do not use the central pixels in the mask (because they are in the ++ * logo region), and thus a gaussian mask will cause too little blur and thus a ++ * very unstable image. ++ * ++ * The mask is applied in a special way. Namely, only pixels in the mask that ++ * line up to pixels outside the logo are used. The dynamic mask size means that ++ * the mask is just big enough so that the edges touch pixels outside the logo, so ++ * the blurring is kept to a minimum and at least the first boundary condition is ++ * met (that the image function itself is continuous), even if the second boundary ++ * condition (that the derivative of the image function is continuous) is not met. ++ * A masking algorithm that does preserve the second boundary coundition ++ * (perhaps something based on a highly-modified bi-cubic algorithm) should offer ++ * even better results on paper, but the noise in a typical TV signal should make ++ * anything based on derivatives hopelessly noisy. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "libvo/fastmemcpy.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++//===========================================================================// ++ ++/** \brief Returns the larger of the two arguments. **/ ++#define max(x,y) ((x)>(y)?(x):(y)) ++/** \brief Returns the smaller of the two arguments. **/ ++#define min(x,y) ((x)>(y)?(y):(x)) ++ ++/** ++ * \brief Test if a pixel is part of the logo. ++ */ ++#define test_filter(image, x, y) ((unsigned char) (image->pixel[((y) * image->width) + (x)])) ++ ++/** ++ * \brief Chooses a slightly larger mask size to improve performance. ++ * ++ * This function maps the absolute minimum mask size needed to the mask size we'll ++ * actually use. f(x) = x (the smallest that will work) will produce the sharpest ++ * results, but will be quite jittery. f(x) = 1.25x (what I'm using) is a good ++ * tradeoff in my opinion. This will calculate only at init-time, so you can put a ++ * long expression here without effecting performance. ++ */ ++#define apply_mask_fudge_factor(x) (((x) >> 2) + x) ++ ++/** ++ * \brief Simple implementation of the PGM image format. ++ * ++ * This struct holds a bare-bones image loaded from a PGM or PPM file. Once ++ * loaded and pre-processed, each pixel in this struct will contain how far from ++ * the edge of the logo each pixel is, using the manhattan distance (|dx| + |dy|). ++ * ++ * pixels in char * pixel can be addressed using (y * width) + height. ++ */ ++typedef struct ++{ ++ unsigned int width; ++ unsigned int height; ++ ++ unsigned char * pixel; ++ ++} pgm_structure; ++ ++/** ++ * \brief Stores persistant variables. ++ * ++ * Variables stored here are kept from frame to frame, and separate instances of ++ * the filter will get their own separate copies. ++ */ ++struct vf_priv_s ++{ ++ unsigned int fmt; /* Not exactly sure of the use for this. It came with the example filter I used as a basis for this, and it looks like a lot of stuff will break if I remove it. */ ++ int max_mask_size; /* The largest possible mask size that will be needed with the given filter and corresponding half_size_filter. The half_size_filter can have a larger requirment in some rare (but not degenerate) cases. */ ++ int * * * mask; /* Stores our collection of masks. The first * is for an array of masks, the second for the y axis, and the third for the x axis. */ ++ pgm_structure * filter; /* Stores the full-size filter image. This is used to tell what pixels are in the logo or not in the luma plane. */ ++ pgm_structure * half_size_filter; /* Stores a 50% width and 50% height filter image. This is used to tell what pixels are in the logo or not in the chroma planes. */ ++ /* These 8 variables store the bounding rectangles that the logo resides in. */ ++ int bounding_rectangle_posx1; ++ int bounding_rectangle_posy1; ++ int bounding_rectangle_posx2; ++ int bounding_rectangle_posy2; ++ int bounding_rectangle_half_size_posx1; ++ int bounding_rectangle_half_size_posy1; ++ int bounding_rectangle_half_size_posx2; ++ int bounding_rectangle_half_size_posy2; ++} vf_priv_s; ++ ++/** ++ * \brief Mallocs memory and checks to make sure it succeeded. ++ * ++ * \param size How many bytes to allocate. ++ * ++ * \return A pointer to the freshly allocated memory block, or NULL on failutre. ++ * ++ * Mallocs memory, and checks to make sure it was successfully allocated. Because ++ * of how MPlayer works, it cannot safely halt execution, but at least the user ++ * will get an error message before the segfault happens. ++ */ ++static void * safe_malloc(int size) ++{ ++ void * answer = malloc(size); ++ if (answer == NULL) ++ mp_msg(MSGT_VFILTER, MSGL_ERR, "Unable to allocate memory in vf_remove_logo.c\n"); ++ ++ return answer; ++} ++ ++/** ++ * \brief Calculates the smallest rectangle that will encompass the logo region. ++ * ++ * \param filter This image contains the logo around which the rectangle will ++ * will be fitted. ++ * ++ * The bounding rectangle is calculated by testing successive lines (from the four ++ * sides of the rectangle) until no more can be removed without removing logo ++ * pixels. The results are returned by reference to posx1, posy1, posx2, and ++ * posy2. ++ */ ++static void calculate_bounding_rectangle(int * posx1, int * posy1, int * posx2, int * posy2, pgm_structure * filter) ++{ ++ int x; /* Temporary variables to run */ ++ int y; /* through each row or column. */ ++ int start_x; ++ int start_y; ++ int end_x = filter->width - 1; ++ int end_y = filter->height - 1; ++ int did_we_find_a_logo_pixel = 0; ++ ++ /* Let's find the top bound first. */ ++ for (start_x = 0; start_x < filter->width && !did_we_find_a_logo_pixel; start_x++) ++ { ++ for (y = 0; y < filter->height; y++) ++ { ++ did_we_find_a_logo_pixel |= test_filter(filter, start_x, y); ++ } ++ } ++ start_x--; ++ ++ /* Now the bottom bound. */ ++ did_we_find_a_logo_pixel = 0; ++ for (end_x = filter->width - 1; end_x > start_x && !did_we_find_a_logo_pixel; end_x--) ++ { ++ for (y = 0; y < filter->height; y++) ++ { ++ did_we_find_a_logo_pixel |= test_filter(filter, end_x, y); ++ } ++ } ++ end_x++; ++ ++ /* Left bound. */ ++ did_we_find_a_logo_pixel = 0; ++ for (start_y = 0; start_y < filter->height && !did_we_find_a_logo_pixel; start_y++) ++ { ++ for (x = 0; x < filter->width; x++) ++ { ++ did_we_find_a_logo_pixel |= test_filter(filter, x, start_y); ++ } ++ } ++ start_y--; ++ ++ /* Right bound. */ ++ did_we_find_a_logo_pixel = 0; ++ for (end_y = filter->height - 1; end_y > start_y && !did_we_find_a_logo_pixel; end_y--) ++ { ++ for (x = 0; x < filter->width; x++) ++ { ++ did_we_find_a_logo_pixel |= test_filter(filter, x, end_y); ++ } ++ } ++ end_y++; ++ ++ *posx1 = start_x; ++ *posy1 = start_y; ++ *posx2 = end_x; ++ *posy2 = end_y; ++ ++ return; ++} ++ ++/** ++ * \brief Free mask memory. ++ * ++ * \param vf Data structure which stores our persistant data, and is to be freed. ++ * ++ * We call this function when our filter is done. It will free the memory ++ * allocated to the masks and leave the variables in a safe state. ++ */ ++static void destroy_masks(vf_instance_t * vf) ++{ ++ int a, b; ++ ++ /* Load values from the vf->priv struct for faster dereferencing. */ ++ int * * * mask = vf->priv->mask; ++ int max_mask_size = vf->priv->max_mask_size; ++ ++ if (mask == NULL) ++ return; /* Nothing allocated, so return before we segfault. */ ++ ++ /* Free all allocated memory. */ ++ for (a = 0; a <= max_mask_size; a++) /* Loop through each mask. */ ++ { ++ for (b = -a; b <= a; b++) /* Loop through each scanline in a mask. */ ++ { ++ free(mask[a][b + a]); /* Free a scanline. */ ++ } ++ free(mask[a]); /* Free a mask. */ ++ } ++ free(mask); /* Free the array of pointers pointing to the masks. */ ++ ++ /* Set the pointer to NULL, so that any duplicate calls to this function will not cause a crash. */ ++ vf->priv->mask = NULL; ++ ++ return; ++} ++ ++/** ++ * \brief Set up our array of masks. ++ * ++ * \param vf Where our filter stores persistance data, like these masks. ++ * ++ * This creates an array of progressively larger masks and calculates their ++ * values. The values will not change during program execution once this function ++ * is done. ++ */ ++static void initialize_masks(vf_instance_t * vf) ++{ ++ int a, b, c; ++ ++ /* Load values from the vf->priv struct for faster dereferencing. */ ++ int * * * mask = vf->priv->mask; ++ int max_mask_size = vf->priv->max_mask_size; /* This tells us how many masks we'll need to generate. */ ++ ++ /* Create a circular mask for each size up to max_mask_size. When the filter is applied, the mask size is ++ determined on a pixel by pixel basis, with pixels nearer the edge of the logo getting smaller mask sizes. */ ++ mask = (int * * *) safe_malloc(sizeof(int * *) * (max_mask_size + 1)); ++ for (a = 0; a <= max_mask_size; a++) ++ { ++ mask[a] = (int * *) safe_malloc(sizeof(int *) * ((a * 2) + 1)); ++ for (b = -a; b <= a; b++) ++ { ++ mask[a][b + a] = (int *) safe_malloc(sizeof(int) * ((a * 2) + 1)); ++ for (c = -a; c <= a; c++) ++ { ++ if ((b * b) + (c * c) <= (a * a)) /* Circular 0/1 mask. */ ++ mask[a][b + a][c + a] = 1; ++ else ++ mask[a][b + a][c + a] = 0; ++ } ++ } ++ } ++ ++ /* Store values back to vf->priv so they aren't lost after the function returns. */ ++ vf->priv->mask = mask; ++ ++ return; ++} ++ ++/** ++ * \brief Pre-processes an image to give distance information. ++ * ++ * \param vf Data structure that holds persistant information. All it is used for ++ in this function is to store the calculated max_mask_size variable. ++ * \param mask This image will be converted from a greyscale image into a ++ * distance image. ++ * ++ * This function takes a greyscale image (pgm_structure * mask) and converts it ++ * in place into a distance image. A distance image is zero for pixels ourside of ++ * the logo and is the manhattan distance (|dx| + |dy|) for pixels inside of the ++ * logo. This will overestimate the distance, but that is safe, and is far easier ++ * to implement than a proper pythagorean distance since I'm using a modified ++ * erosion algorithm to compute the distances. ++ */ ++static void convert_mask_to_strength_mask(vf_instance_t * vf, pgm_structure * mask) ++{ ++ int x, y; /* Used by our for loops to go through every single pixel in the picture one at a time. */ ++ int has_anything_changed = 1; /* Used by the main while() loop to know if anything changed on the last erosion. */ ++ int current_pass = 0; /* How many times we've gone through the loop. Used in the in-place erosion algorithm ++ and to get us max_mask_size later on. */ ++ int max_mask_size; /* This will record how large a mask the pixel that is the furthest from the edge of the logo ++ (and thus the neediest) is. */ ++ char * current_pixel = mask->pixel; /* This stores the actual pixel data. */ ++ ++ /* First pass, set all non-zero values to 1. After this loop finishes, the data should be considered numeric ++ data for the filter, not color data. */ ++ for (x = 0; x < mask->height * mask->width; x++, current_pixel++) ++ if(*current_pixel) *current_pixel = 1; ++ ++ /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass, ++ and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass, ++ then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask, ++ but if it isn't this will ensure that we eventually exit). */ ++ while (has_anything_changed) ++ { ++ current_pass++; ++ current_pixel = mask->pixel; ++ ++ has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */ ++ ++ for (y = 1; y < mask->height - 1; y++) ++ { ++ for (x = 1; x < mask->width - 1; x++) ++ { ++ /* Apply the in-place erosion transform. It is based on the following two premises: 1 - Any pixel that fails 1 erosion ++ will fail all future erosions. 2 - Only pixels having survived all erosions up to the present will be >= to ++ current_pass. It doesn't matter if it survived the current pass, failed it, or hasn't been tested yet. */ ++ if (*current_pixel >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */ ++ *(current_pixel + 1) >= current_pass && ++ *(current_pixel - 1) >= current_pass && ++ *(current_pixel + mask->width) >= current_pass && ++ *(current_pixel - mask->width) >= current_pass) ++ { ++ (*current_pixel)++; /* Increment the value since it still has not been eroded, as evidenced by the if statement ++ that just evaluated to true. */ ++ has_anything_changed = 1; ++ } ++ current_pixel++; ++ } ++ } ++ } ++ ++ /* Apply the fudge factor, which will increase the size of the mask a little to reduce jitter at the cost of more blur. */ ++ for (y = 1; y < mask->height - 1; y++) ++ { ++ for (x = 1; x < mask->width - 1; x++) ++ { ++ mask->pixel[(y * mask->width) + x] = apply_mask_fudge_factor(mask->pixel[(y * mask->width) + x]); ++ } ++ } ++ ++ max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */ ++ max_mask_size = apply_mask_fudge_factor(max_mask_size); /* Apply the fudge factor to this number too, since we must ++ ensure that enough masks are generated. */ ++ vf->priv->max_mask_size = max_mask_size; /* Commit the newly calculated max_mask_size to the vf->priv struct. */ ++ ++ return; ++} ++ ++/** ++ * \brief Our blurring function. ++ * ++ * \param vf Stores persistant data. In this function we are interested in the ++ * array of masks. ++ * \param value_out The properly blurred and delogoed pixel is outputted here. ++ * \param logo_mask Tells us which pixels are in the logo and which aren't. ++ * \param image The image that is having its logo removed. ++ * \param x x-coordinate of the pixel to blur. ++ * \param y y-coordinate of the pixel to blur. ++ * \param plane 0 = luma, 1 = blue chroma, 2 = red chroma (YUV). ++ * ++ * This function is the core of the filter. It takes a pixel that is inside the ++ * logo and blurs it. It does so by finding the average of all the pixels within ++ * the mask and outside of the logo. ++ */ ++static void get_blur(const vf_instance_t * const vf, unsigned int * const value_out, const pgm_structure * const logo_mask, ++ const mp_image_t * const image, const int x, const int y, const int plane) ++{ ++ int mask_size; /* Mask size tells how large a circle to use. The radius is about (slightly larger than) mask size. */ ++ /* Get values from vf->priv for faster dereferencing. */ ++ int * * * mask = vf->priv->mask; ++ ++ int start_posx, start_posy, end_posx, end_posy; ++ int i, j; ++ unsigned int accumulator = 0, divisor = 0; ++ const unsigned char * mask_read_position; /* What pixel we are reading out of the circular blur mask. */ ++ const unsigned char * logo_mask_read_position; /* What pixel we are reading out of the filter image. */ ++ ++ /* Prepare our bounding rectangle and clip it if need be. */ ++ mask_size = test_filter(logo_mask, x, y); ++ start_posx = max(0, x - mask_size); ++ start_posy = max(0, y - mask_size); ++ end_posx = min(image->width - 1, x + mask_size); ++ end_posy = min(image->height - 1, y + mask_size); ++ ++ mask_read_position = image->planes[plane] + (image->stride[plane] * start_posy) + start_posx; ++ logo_mask_read_position = logo_mask->pixel + (start_posy * logo_mask->width) + start_posx; ++ ++ for (j = start_posy; j <= end_posy; j++) ++ { ++ for (i = start_posx; i <= end_posx; i++) ++ { ++ if (!(*logo_mask_read_position) && mask[mask_size][i - start_posx][j - start_posy]) ++ { /* Check to see if this pixel is in the logo or not. Only use the pixel if it is not. */ ++ accumulator += *mask_read_position; ++ divisor++; ++ } ++ ++ mask_read_position++; ++ logo_mask_read_position++; ++ } ++ ++ mask_read_position += (image->stride[plane] - ((end_posx + 1) - start_posx)); ++ logo_mask_read_position += (logo_mask->width - ((end_posx + 1) - start_posx)); ++ } ++ ++ if (divisor == 0) /* This means that not a single pixel is outside of the logo, so we have no data. */ ++ { /* We should put some eye catching value here, to indicate the flaw to the user. */ ++ *value_out = 255; ++ } ++ else /* Else we need to normalise the data using the divisor. */ ++ { ++ *value_out = (accumulator + (divisor / 2)) / divisor; /* Divide, taking into account average rounding error. */ ++ } ++ ++ return; ++} ++ ++/** ++ * \brief Free a pgm_structure. Undoes load_pgm(...). ++ */ ++static void destroy_pgm(pgm_structure * to_be_destroyed) ++{ ++ if (to_be_destroyed == NULL) ++ return; /* Don't do anything if a NULL pointer was passed it. */ ++ ++ /* Internally allocated memory. */ ++ if (to_be_destroyed->pixel != NULL) ++ { ++ free(to_be_destroyed->pixel); ++ to_be_destroyed->pixel = NULL; ++ } ++ ++ /* Free the actual struct instance. This is done here and not by the calling function. */ ++ free(to_be_destroyed); ++} ++ ++/** \brief Helper function for load_pgm(...) to skip whitespace. */ ++static void load_pgm_skip(FILE *f) { ++ int c, comment = 0; ++ do { ++ c = fgetc(f); ++ if (c == '#') ++ comment = 1; ++ if (c == '\n') ++ comment = 0; ++ } while (c != EOF && (isspace(c) || comment)); ++ ungetc(c, f); ++} ++ ++#define REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE(message) {mp_msg(MSGT_VFILTER, MSGL_ERR, message); return NULL;} ++ ++/** ++ * \brief Loads a raw pgm or ppm file into a newly created pgm_structure object. ++ * ++ * \param file_name The name of the file to be loaded. So long as the file is a ++ * valid pgm or ppm file, it will load correctly, even if the ++ * extension is missing or invalid. ++ * ++ * \return A pointer to the newly created pgm_structure object. Don't forget to ++ * call destroy_pgm(...) when you're done with this. If an error occurs, ++ * NULL is returned. ++ * ++ * Can load either raw pgm (P5) or raw ppm (P6) image files as a binary image. ++ * While a pgm file will be loaded normally (greyscale), the only thing that is ++ * guaranteed with ppm is that all zero (R = 0, G = 0, B = 0) pixels will remain ++ * zero, and non-zero pixels will remain non-zero. ++ */ ++static pgm_structure * load_pgm(const char * file_name) ++{ ++ int maximum_greyscale_value; ++ FILE * input; ++ int pnm_number; ++ pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure)); ++ char * write_position; ++ char * end_position; ++ int image_size; /* width * height */ ++ ++ if((input = fopen(file_name, "rb")) == NULL) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Unable to open file. File not found or insufficient permissions.\n"); ++ ++ /* Parse the PGM header. */ ++ if (fgetc(input) != 'P') REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: File is not a valid PGM or PPM file.\n"); ++ pnm_number = fgetc(input) - '0'; ++ if (pnm_number != 5 && pnm_number != 6) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PNM file. Only raw PGM (Portable Gray Map) and raw PPM (Portable Pixel Map) subtypes are allowed.\n"); ++ load_pgm_skip(input); ++ if (fscanf(input, "%i", &(new_pgm->width)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); ++ load_pgm_skip(input); ++ if (fscanf(input, "%i", &(new_pgm->height)) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); ++ load_pgm_skip(input); ++ if (fscanf(input, "%i", &maximum_greyscale_value) != 1) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove-logo: Invalid PGM/PPM header.\n"); ++ if (maximum_greyscale_value >= 256) REMOVE_LOGO_LOAD_PGM_ERROR_MESSAGE("[vf]remove_logo: Only 1 byte per pixel (pgm) or 1 byte per color value (ppm) are supported.\n"); ++ load_pgm_skip(input); ++ ++ new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height); ++ ++ /* Load the pixels. */ ++ /* Note: I am aware that fgetc(input) isn't the fastest way of doing things, but it is quite compact and the code only runs once when the filter is initialized.*/ ++ image_size = new_pgm->width * new_pgm->height; ++ end_position = new_pgm->pixel + image_size; ++ for (write_position = new_pgm->pixel; write_position < end_position; write_position++) ++ { ++ *write_position = fgetc(input); ++ if (pnm_number == 6) /* This tests to see if the file is a PPM file. */ ++ { /* If it is, then consider the pixel set if any of the three color channels are set. Since we just care about == 0 or != 0, a bitwise or will do the trick. */ ++ *write_position |= fgetc(input); ++ *write_position |= fgetc(input); ++ } ++ } ++ ++ return new_pgm; ++} ++ ++/** ++ * \brief Generates a scaled down image with half width, height, and intensity. ++ * ++ * \param vf Our struct for persistant data. In this case, it is used to update ++ * mask_max_size with the larger of the old or new value. ++ * \param input_image The image from which the new half-sized one will be based. ++ * ++ * \return The newly allocated and shrunken image. ++ * ++ * This function not only scales down an image, but halves the value in each pixel ++ * too. The purpose of this is to produce a chroma filter image out of a luma ++ * filter image. The pixel values store the distance to the edge of the logo and ++ * halving the dimensions halves the distance. This function rounds up, because ++ * a downwards rounding error could cause the filter to fail, but an upwards ++ * rounding error will only cause a minor amount of excess blur in the chroma ++ * planes. ++ */ ++static pgm_structure * generate_half_size_image(vf_instance_t * vf, pgm_structure * input_image) ++{ ++ int x, y; ++ pgm_structure * new_pgm = (pgm_structure *) safe_malloc (sizeof(pgm_structure)); ++ int has_anything_changed = 1; ++ int current_pass; ++ int max_mask_size; ++ char * current_pixel; ++ ++ new_pgm->width = input_image->width / 2; ++ new_pgm->height = input_image->height / 2; ++ new_pgm->pixel = (unsigned char *) safe_malloc (sizeof(unsigned char) * new_pgm->width * new_pgm->height); ++ ++ /* Copy over the image data, using the average of 4 pixels for to calculate each downsampled pixel. */ ++ for (y = 0; y < new_pgm->height; y++) ++ for (x = 0; x < new_pgm->width; x++) ++ { ++ /* Set the pixel if there exists a non-zero value in the source pixels, else clear it. */ ++ new_pgm->pixel[(y * new_pgm->width) + x] = input_image->pixel[((y << 1) * input_image->width) + (x << 1)] || ++ input_image->pixel[((y << 1) * input_image->width) + (x << 1) + 1] || ++ input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1)] || ++ input_image->pixel[(((y << 1) + 1) * input_image->width) + (x << 1) + 1]; ++ new_pgm->pixel[(y * new_pgm->width) + x] = min(1, new_pgm->pixel[(y * new_pgm->width) + x]); ++ } ++ ++ /* Now we need to recalculate the numbers for the smaller size. Just using the old_value / 2 can cause subtle ++ and fairly rare, but very nasty, bugs. */ ++ ++ current_pixel = new_pgm->pixel; ++ /* First pass, set all non-zero values to 1. */ ++ for (x = 0; x < new_pgm->height * new_pgm->width; x++, current_pixel++) ++ if(*current_pixel) *current_pixel = 1; ++ ++ /* Second pass and future passes. For each pass, if a pixel is itself the same value as the current pass, ++ and its four neighbors are too, then it is incremented. If no pixels are incremented by the end of the pass, ++ then we go again. Edge pixels are counted as always excluded (this should be true anyway for any sane mask, ++ but if it isn't this will ensure that we eventually exit). */ ++ current_pass = 0; ++ while (has_anything_changed) ++ { ++ current_pass++; ++ ++ has_anything_changed = 0; /* If this doesn't get set by the end of this pass, then we're done. */ ++ ++ for (y = 1; y < new_pgm->height - 1; y++) ++ { ++ for (x = 1; x < new_pgm->width - 1; x++) ++ { ++ if (new_pgm->pixel[(y * new_pgm->width) + x] >= current_pass && /* By using >= instead of ==, we allow the algorithm to work in place. */ ++ new_pgm->pixel[(y * new_pgm->width) + (x + 1)] >= current_pass && ++ new_pgm->pixel[(y * new_pgm->width) + (x - 1)] >= current_pass && ++ new_pgm->pixel[((y + 1) * new_pgm->width) + x] >= current_pass && ++ new_pgm->pixel[((y - 1) * new_pgm->width) + x] >= current_pass) ++ { ++ new_pgm->pixel[(y * new_pgm->width) + x]++; /* Increment the value since it still has not been eroded, ++ as evidenced by the if statement that just evaluated to true. */ ++ has_anything_changed = 1; ++ } ++ } ++ } ++ } ++ ++ for (y = 1; y < new_pgm->height - 1; y++) ++ { ++ for (x = 1; x < new_pgm->width - 1; x++) ++ { ++ new_pgm->pixel[(y * new_pgm->width) + x] = apply_mask_fudge_factor(new_pgm->pixel[(y * new_pgm->width) + x]); ++ } ++ } ++ ++ max_mask_size = current_pass + 1; /* As a side-effect, we now know the maximum mask size, which we'll use to generate our masks. */ ++ max_mask_size = apply_mask_fudge_factor(max_mask_size); ++ /* Commit the newly calculated max_mask_size to the vf->priv struct. */ ++ vf->priv->max_mask_size = max(max_mask_size, vf->priv->max_mask_size); ++ ++ return new_pgm; ++} ++ ++/** ++ * \brief Checks if YV12 is supported by the next filter. ++ */ ++static unsigned int find_best(struct vf_instance *vf){ ++ int is_format_okay = vf_next_query_format(vf, IMGFMT_YV12); ++ if ((is_format_okay & VFCAP_CSP_SUPPORTED_BY_HW) || (is_format_okay & VFCAP_CSP_SUPPORTED)) ++ return IMGFMT_YV12; ++ else ++ return 0; ++} ++ ++//===========================================================================// ++ ++/** ++ * \brief Configure the filter and call the next filter's config function. ++ */ ++static int config(struct vf_instance *vf, int width, int height, int d_width, int d_height, unsigned int flags, unsigned int outfmt) ++{ ++ if(!(vf->priv->fmt=find_best(vf))) ++ return 0; ++ else ++ return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); ++} ++ ++/** ++ * \brief Removes the logo from a plane (either luma or chroma). ++ * ++ * \param vf Not needed by this function, but needed by the blur function. ++ * \param source The image to have it's logo removed. ++ * \param destination Where the output image will be stored. ++ * \param source_stride How far apart (in memory) two consecutive lines are. ++ * \param destination Same as source_stride, but for the destination image. ++ * \param width Width of the image. This is the same for source and destination. ++ * \param height Height of the image. This is the same for source and destination. ++ * \param is_image_direct If the image is direct, then source and destination are ++ * the same and we can save a lot of time by not copying pixels that ++ * haven't changed. ++ * \param filter The image that stores the distance to the edge of the logo for ++ * each pixel. ++ * \param logo_start_x Smallest x-coordinate that contains at least 1 logo pixel. ++ * \param logo_start_y Smallest y-coordinate that contains at least 1 logo pixel. ++ * \param logo_end_x Largest x-coordinate that contains at least 1 logo pixel. ++ * \param logo_end_y Largest y-coordinate that contains at least 1 logo pixel. ++ * ++ * This function processes an entire plane. Pixels outside of the logo are copied ++ * to the output without change, and pixels inside the logo have the de-blurring ++ * function applied. ++ */ ++static void convert_yv12(const vf_instance_t * const vf, const char * const source, const int source_stride, ++ const mp_image_t * const source_image, const int width, const int height, ++ char * const destination, const int destination_stride, int is_image_direct, pgm_structure * filter, ++ const int plane, const int logo_start_x, const int logo_start_y, const int logo_end_x, const int logo_end_y) ++{ ++ int y; ++ int x; ++ ++ /* These pointers point to where we are getting our pixel data (inside mpi) and where we are storing it (inside dmpi). */ ++ const unsigned char * source_line; ++ unsigned char * destination_line; ++ ++ if (!is_image_direct) ++ memcpy_pic(destination, source, width, height, destination_stride, source_stride); ++ ++ for (y = logo_start_y; y <= logo_end_y; y++) ++ { ++ source_line = (const unsigned char *) source + (source_stride * y); ++ destination_line = (unsigned char *) destination + (destination_stride * y); ++ ++ for (x = logo_start_x; x <= logo_end_x; x++) ++ { ++ unsigned int output; ++ ++ if (filter->pixel[(y * filter->width) + x]) /* Only process if we are in the logo. */ ++ { ++ get_blur(vf, &output, filter, source_image, x, y, plane); ++ destination_line[x] = output; ++ } ++ else /* Else just copy the data. */ ++ if (!is_image_direct) ++ destination_line[x] = source_line[x]; ++ } ++ } ++} ++ ++/** ++ * \brief Process a frame. ++ * ++ * \param mpi The image sent to use by the previous filter. ++ * \param dmpi Where we will store the processed output image. ++ * \param vf This is how the filter gets access to it's persistant data. ++ * ++ * \return The return code of the next filter, or 0 on failure/error. ++ * ++ * This function processes an entire frame. The frame is sent by the previous ++ * filter, has the logo removed by the filter, and is then sent to the next ++ * filter. ++ */ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ dmpi=vf_get_image(vf->next,vf->priv->fmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w, mpi->h); ++ ++ /* Check to make sure that the filter image and the video stream are the same size. */ ++ if (vf->priv->filter->width != mpi->w || vf->priv->filter->height != mpi->h) ++ { ++ mp_msg(MSGT_VFILTER,MSGL_ERR, "Filter image and video stream are not of the same size. (Filter: %d x %d, Stream: %d x %d)\n", ++ vf->priv->filter->width, vf->priv->filter->height, mpi->w, mpi->h); ++ return 0; ++ } ++ ++ switch(dmpi->imgfmt){ ++ case IMGFMT_YV12: ++ convert_yv12(vf, mpi->planes[0], mpi->stride[0], mpi, mpi->w, mpi->h, ++ dmpi->planes[0], dmpi->stride[0], ++ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->filter, 0, ++ vf->priv->bounding_rectangle_posx1, vf->priv->bounding_rectangle_posy1, ++ vf->priv->bounding_rectangle_posx2, vf->priv->bounding_rectangle_posy2); ++ convert_yv12(vf, mpi->planes[1], mpi->stride[1], mpi, mpi->w / 2, mpi->h / 2, ++ dmpi->planes[1], dmpi->stride[1], ++ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->half_size_filter, 1, ++ vf->priv->bounding_rectangle_half_size_posx1, vf->priv->bounding_rectangle_half_size_posy1, ++ vf->priv->bounding_rectangle_half_size_posx2, vf->priv->bounding_rectangle_half_size_posy2); ++ convert_yv12(vf, mpi->planes[2], mpi->stride[2], mpi, mpi->w / 2, mpi->h / 2, ++ dmpi->planes[2], dmpi->stride[2], ++ mpi->flags & MP_IMGFLAG_DIRECT, vf->priv->half_size_filter, 2, ++ vf->priv->bounding_rectangle_half_size_posx1, vf->priv->bounding_rectangle_half_size_posy1, ++ vf->priv->bounding_rectangle_half_size_posx2, vf->priv->bounding_rectangle_half_size_posy2); ++ break; ++ ++ default: ++ mp_msg(MSGT_VFILTER,MSGL_ERR,"Unhandled format: 0x%X\n",dmpi->imgfmt); ++ return 0; ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++/** ++ * \brief Checks to see if the next filter accepts YV12 images. ++ */ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ if (fmt == IMGFMT_YV12) ++ return vf_next_query_format(vf, IMGFMT_YV12); ++ else ++ return 0; ++} ++ ++/** ++ * \brief Frees memory that our filter allocated. ++ * ++ * This is called at exit-time. ++ */ ++static void uninit(vf_instance_t *vf) ++{ ++ /* Destroy our masks and images. */ ++ destroy_pgm(vf->priv->filter); ++ destroy_pgm(vf->priv->half_size_filter); ++ destroy_masks(vf); ++ ++ /* Destroy our private structure that had been used to store those masks and images. */ ++ free(vf->priv); ++ ++ return; ++} ++ ++/** ++ * \brief Initializes our filter. ++ * ++ * \param args The arguments passed in from the command line go here. This ++ * filter expects only a single argument telling it where the PGM ++ * or PPM file that describes the logo region is. ++ * ++ * This sets up our instance variables and parses the arguments to the filter. ++ */ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->priv = safe_malloc(sizeof(vf_priv_s)); ++ vf->uninit = uninit; ++ ++ /* Load our filter image. */ ++ if (args) ++ vf->priv->filter = load_pgm(args); ++ else ++ { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, "[vf]remove_logo usage: remove_logo=/path/to/filter_image_file.pgm\n"); ++ free(vf->priv); ++ return 0; ++ } ++ ++ if (vf->priv->filter == NULL) ++ { ++ /* Error message was displayed by load_pgm(). */ ++ free(vf->priv); ++ return 0; ++ } ++ ++ /* Create the scaled down filter image for the chroma planes. */ ++ convert_mask_to_strength_mask(vf, vf->priv->filter); ++ vf->priv->half_size_filter = generate_half_size_image(vf, vf->priv->filter); ++ ++ /* Now that we know how many masks we need (the info is in vf), we can generate the masks. */ ++ initialize_masks(vf); ++ ++ /* Calculate our bounding rectangles, which determine in what region the logo resides for faster processing. */ ++ calculate_bounding_rectangle(&vf->priv->bounding_rectangle_posx1, &vf->priv->bounding_rectangle_posy1, ++ &vf->priv->bounding_rectangle_posx2, &vf->priv->bounding_rectangle_posy2, ++ vf->priv->filter); ++ calculate_bounding_rectangle(&vf->priv->bounding_rectangle_half_size_posx1, ++ &vf->priv->bounding_rectangle_half_size_posy1, ++ &vf->priv->bounding_rectangle_half_size_posx2, ++ &vf->priv->bounding_rectangle_half_size_posy2, ++ vf->priv->half_size_filter); ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ return 1; ++} ++ ++/** ++ * \brief Meta data about our filter. ++ */ ++const vf_info_t vf_info_remove_logo = { ++ "Removes a tv logo based on a mask image.", ++ "remove-logo", ++ "Robert Edele", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_rotate.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_rotate.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_rotate.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_rotate.c 2012-05-14 14:08:54.776348877 +0200 +@@ -0,0 +1,152 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int direction; ++}; ++ ++static void rotate(unsigned char* dst,unsigned char* src,int dststride,int srcstride,int w,int h,int bpp,int dir){ ++ int y; ++ if(dir&1){ ++ src+=srcstride*(w-1); ++ srcstride*=-1; ++ } ++ if(dir&2){ ++ dst+=dststride*(h-1); ++ dststride*=-1; ++ } ++ ++ for(y=0;ypriv->direction & 4) { ++ if (widthpriv->direction&=3; ++ } ++ if (vf->priv->direction & 4){ ++ vf->put_image=vf_next_put_image; // passthru mode! ++ if (vf->next->draw_slice) vf->draw_slice=vf_next_draw_slice; ++/* FIXME: this should be in an other procedure in vf.c; that should always check ++ whether the filter after the passthrough one still (not)supports slices */ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++ } ++ return vf_next_config(vf,height,width,d_height,d_width,flags,outfmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->h, mpi->w); ++ ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ rotate(dmpi->planes[0],mpi->planes[0], ++ dmpi->stride[0],mpi->stride[0], ++ dmpi->w,dmpi->h,1,vf->priv->direction); ++ rotate(dmpi->planes[1],mpi->planes[1], ++ dmpi->stride[1],mpi->stride[1], ++ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction); ++ rotate(dmpi->planes[2],mpi->planes[2], ++ dmpi->stride[2],mpi->stride[2], ++ dmpi->w>>mpi->chroma_x_shift,dmpi->h>>mpi->chroma_y_shift,1,vf->priv->direction); ++ } else { ++ rotate(dmpi->planes[0],mpi->planes[0], ++ dmpi->stride[0],mpi->stride[0], ++ dmpi->w,dmpi->h,dmpi->bpp>>3,vf->priv->direction); ++ dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette ++ } ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ if(IMGFMT_IS_RGB(fmt) || IMGFMT_IS_BGR(fmt)) return vf_next_query_format(vf, fmt); ++ // we can support only symmetric (chroma_x_shift==chroma_y_shift) YUV formats: ++ switch(fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++// case IMGFMT_IF09: ++ case IMGFMT_Y8: ++ case IMGFMT_Y800: ++ case IMGFMT_444P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ vf->priv->direction=args?atoi(args):0; ++ return 1; ++} ++ ++const vf_info_t vf_info_rotate = { ++ "rotate", ++ "rotate", ++ "A'rpi", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_sab.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_sab.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_sab.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_sab.c 2012-05-14 14:08:54.777348897 +0200 +@@ -0,0 +1,323 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "libavutil/avutil.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libswscale/swscale.h" ++#include "vf_scale.h" ++ ++ ++//===========================================================================// ++ ++typedef struct FilterParam{ ++ float radius; ++ float preFilterRadius; ++ float strength; ++ float quality; ++ struct SwsContext *preFilterContext; ++ uint8_t *preFilterBuf; ++ int preFilterStride; ++ int distWidth; ++ int distStride; ++ int *distCoeff; ++ int colorDiffCoeff[512]; ++}FilterParam; ++ ++struct vf_priv_s { ++ FilterParam luma; ++ FilterParam chroma; ++}; ++ ++ ++/***************************************************************************/ ++ ++//FIXME stupid code duplication ++static void getSubSampleFactors(int *h, int *v, int format){ ++ switch(format){ ++ default: ++ assert(0); ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ *h=1; ++ *v=1; ++ break; ++ case IMGFMT_YVU9: ++ *h=2; ++ *v=2; ++ break; ++ case IMGFMT_444P: ++ *h=0; ++ *v=0; ++ break; ++ case IMGFMT_422P: ++ *h=1; ++ *v=0; ++ break; ++ case IMGFMT_411P: ++ *h=2; ++ *v=0; ++ break; ++ } ++} ++ ++static int allocStuff(FilterParam *f, int width, int height){ ++ int stride= (width+7)&~7; ++ SwsVector *vec; ++ SwsFilter swsF; ++ int i,x,y; ++ f->preFilterBuf= av_malloc(stride*height); ++ f->preFilterStride= stride; ++ ++ vec = sws_getGaussianVec(f->preFilterRadius, f->quality); ++ swsF.lumH= swsF.lumV= vec; ++ swsF.chrH= swsF.chrV= NULL; ++ f->preFilterContext= sws_getContext( ++ width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_POINT, &swsF, NULL, NULL); ++ ++ sws_freeVec(vec); ++ vec = sws_getGaussianVec(f->strength, 5.0); ++ for(i=0; i<512; i++){ ++ double d; ++ int index= i-256 + vec->length/2; ++ ++ if(index<0 || index>=vec->length) d= 0.0; ++ else d= vec->coeff[index]; ++ ++ f->colorDiffCoeff[i]= (int)(d/vec->coeff[vec->length/2]*(1<<12) + 0.5); ++ } ++ sws_freeVec(vec); ++ vec = sws_getGaussianVec(f->radius, f->quality); ++ f->distWidth= vec->length; ++ f->distStride= (vec->length+7)&~7; ++ f->distCoeff= av_malloc(f->distWidth*f->distStride*sizeof(int32_t)); ++ ++ for(y=0; ylength; y++){ ++ for(x=0; xlength; x++){ ++ double d= vec->coeff[x] * vec->coeff[y]; ++ ++ f->distCoeff[x + y*f->distStride]= (int)(d*(1<<10) + 0.5); ++// if(y==vec->length/2) ++// printf("%6d ", f->distCoeff[x + y*f->distStride]); ++ } ++ } ++ sws_freeVec(vec); ++ ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ int sw, sh; ++//__asm__ volatile("emms\n\t"); ++ allocStuff(&vf->priv->luma, width, height); ++ ++ getSubSampleFactors(&sw, &sh, outfmt); ++ allocStuff(&vf->priv->chroma, width>>sw, height>>sh); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void freeBuffers(FilterParam *f){ ++ if(f->preFilterContext) sws_freeContext(f->preFilterContext); ++ f->preFilterContext=NULL; ++ ++ av_free(f->preFilterBuf); ++ f->preFilterBuf=NULL; ++ ++ av_free(f->distCoeff); ++ f->distCoeff=NULL; ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ freeBuffers(&vf->priv->luma); ++ freeBuffers(&vf->priv->chroma); ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){ ++ int x, y; ++ FilterParam f= *fp; ++ const int radius= f.distWidth/2; ++ const uint8_t* const srcArray[MP_MAX_PLANES] = {src}; ++ uint8_t *dstArray[MP_MAX_PLANES]= {f.preFilterBuf}; ++ int srcStrideArray[MP_MAX_PLANES]= {srcStride}; ++ int dstStrideArray[MP_MAX_PLANES]= {f.preFilterStride}; ++ ++// f.preFilterContext->swScale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); ++ sws_scale(f.preFilterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); ++ ++ for(y=0; y= radius && x < w - radius){ ++ for(dy=0; dy=h) iy= h+h-iy-1; ++ ++ for(dx=0; dx=h) iy= h+h-iy-1; ++ ++ for(dx=0; dx=w) ix= w+w-ix-1; ++ ++ factor= f.colorDiffCoeff[256+preVal - f.preFilterBuf[ix + iy*f.preFilterStride] ] ++ *f.distCoeff[dx + dy*f.distStride]; ++ sum+= src[ix + iy*srcStride] *factor; ++ div+= factor; ++ } ++ } ++ } ++ dst[x + y*dstStride]= (sum + div/2)/div; ++ } ++ } ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->w,mpi->h); ++ ++ assert(mpi->flags&MP_IMGFLAG_PLANAR); ++ ++ blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma); ++ blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma); ++ blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ int e; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++// vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if(args==NULL) return 0; ++ ++ e=sscanf(args, "%f:%f:%f:%f:%f:%f", ++ &vf->priv->luma.radius, ++ &vf->priv->luma.preFilterRadius, ++ &vf->priv->luma.strength, ++ &vf->priv->chroma.radius, ++ &vf->priv->chroma.preFilterRadius, ++ &vf->priv->chroma.strength ++ ); ++ ++ vf->priv->luma.quality = vf->priv->chroma.quality= 3.0; ++ ++ if(e==3){ ++ vf->priv->chroma.radius= vf->priv->luma.radius; ++ vf->priv->chroma.preFilterRadius = vf->priv->luma.preFilterRadius; ++ vf->priv->chroma.strength= vf->priv->luma.strength; ++ }else if(e!=6) ++ return 0; ++ ++// if(vf->priv->luma.radius < 0) return 0; ++// if(vf->priv->chroma.radius < 0) return 0; ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_sab = { ++ "shape adaptive blur", ++ "sab", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_scale.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_scale.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_scale.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_scale.h 2012-05-14 14:08:54.778348917 +0200 +@@ -0,0 +1,34 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#ifndef MPLAYER_VF_SCALE_H ++#define MPLAYER_VF_SCALE_H ++ ++extern int sws_chr_vshift; ++extern int sws_chr_hshift; ++ ++extern float sws_chr_gblur; ++extern float sws_lum_gblur; ++extern float sws_chr_sharpen; ++extern float sws_lum_sharpen; ++ ++extern int sws_flags; ++ ++struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat); ++ ++#endif /* MPLAYER_VF_SCALE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_screenshot.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_screenshot.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_screenshot.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_screenshot.c 2012-05-14 14:08:54.779348938 +0200 +@@ -0,0 +1,322 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include "config.h" ++ ++#include ++#include ++#if HAVE_MALLOC_H ++#include ++#endif ++#include ++#include ++ ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "vf_scale.h" ++ ++#include "libswscale/swscale.h" ++#include "libavcodec/avcodec.h" ++ ++struct vf_priv_s { ++ int frameno; ++ char fname[102]; ++ /// shot stores current screenshot mode: ++ /// 0: don't take screenshots ++ /// 1: take single screenshot, reset to 0 afterwards ++ /// 2: take screenshots of each frame ++ int shot, store_slices; ++ int dw, dh, stride; ++ uint8_t *buffer; ++ struct SwsContext *ctx; ++ AVCodecContext *avctx; ++ uint8_t *outbuffer; ++ int outbuffer_size; ++}; ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ vf->priv->ctx=sws_getContextFromCmdLine(width, height, outfmt, ++ d_width, d_height, IMGFMT_RGB24); ++ ++ vf->priv->outbuffer_size = d_width * d_height * 3 * 2; ++ vf->priv->outbuffer = realloc(vf->priv->outbuffer, vf->priv->outbuffer_size); ++ vf->priv->avctx->width = d_width; ++ vf->priv->avctx->height = d_height; ++ vf->priv->avctx->pix_fmt = PIX_FMT_RGB24; ++ vf->priv->avctx->compression_level = 0; ++ vf->priv->dw = d_width; ++ vf->priv->dh = d_height; ++ vf->priv->stride = (3*vf->priv->dw+15)&~15; ++ ++ free(vf->priv->buffer); // probably reconfigured ++ vf->priv->buffer = NULL; ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void write_png(struct vf_priv_s *priv) ++{ ++ char *fname = priv->fname; ++ FILE * fp; ++ AVFrame pic; ++ int size; ++ ++ fp = fopen (fname, "wb"); ++ if (fp == NULL) { ++ mp_msg(MSGT_VFILTER,MSGL_ERR,"\nPNG Error opening %s for writing!\n", fname); ++ return; ++ } ++ ++ pic.data[0] = priv->buffer; ++ pic.linesize[0] = priv->stride; ++ size = avcodec_encode_video(priv->avctx, priv->outbuffer, priv->outbuffer_size, &pic); ++ if (size > 0) ++ fwrite(priv->outbuffer, size, 1, fp); ++ ++ fclose (fp); ++} ++ ++static int fexists(char *fname) ++{ ++ struct stat dummy; ++ if (stat(fname, &dummy) == 0) return 1; ++ else return 0; ++} ++ ++static void gen_fname(struct vf_priv_s* priv) ++{ ++ do { ++ snprintf (priv->fname, 100, "shot%04d.png", ++priv->frameno); ++ } while (fexists(priv->fname) && priv->frameno < 100000); ++ if (fexists(priv->fname)) { ++ priv->fname[0] = '\0'; ++ return; ++ } ++ ++ mp_msg(MSGT_VFILTER,MSGL_INFO,"*** screenshot '%s' ***\n",priv->fname); ++ ++} ++ ++static void scale_image(struct vf_priv_s* priv, mp_image_t *mpi) ++{ ++ uint8_t *dst[MP_MAX_PLANES] = {NULL}; ++ int dst_stride[MP_MAX_PLANES] = {0}; ++ ++ dst_stride[0] = priv->stride; ++ if (!priv->buffer) ++ priv->buffer = av_malloc(dst_stride[0]*priv->dh); ++ ++ dst[0] = priv->buffer; ++ sws_scale(priv->ctx, mpi->planes, mpi->stride, 0, priv->dh, dst, dst_stride); ++} ++ ++static void start_slice(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags, mpi->width, mpi->height); ++ if (vf->priv->shot) { ++ vf->priv->store_slices = 1; ++ if (!vf->priv->buffer) ++ vf->priv->buffer = av_malloc(vf->priv->stride*vf->priv->dh); ++ } ++ ++} ++ ++static void draw_slice(struct vf_instance *vf, unsigned char** src, ++ int* stride, int w,int h, int x, int y) ++{ ++ if (vf->priv->store_slices) { ++ uint8_t *dst[MP_MAX_PLANES] = {NULL}; ++ int dst_stride[MP_MAX_PLANES] = {0}; ++ dst_stride[0] = vf->priv->stride; ++ dst[0] = vf->priv->buffer; ++ sws_scale(vf->priv->ctx, src, stride, y, h, dst, dst_stride); ++ } ++ vf_next_draw_slice(vf,src,stride,w,h,x,y); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi) ++{ ++ // FIXME: should vf.c really call get_image when using slices?? ++ if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) ++ return; ++ vf->dmpi= vf_get_image(vf->next, mpi->imgfmt, ++ mpi->type, mpi->flags/* | MP_IMGFLAG_READABLE*/, mpi->width, mpi->height); ++ ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->width=vf->dmpi->width; ++ ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++ ++ mpi->priv=(void*)vf->dmpi; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi = (mp_image_t *)mpi->priv; ++ ++ if (mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) ++ dmpi = vf->dmpi; ++ else ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, ++ mpi->width, mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ dmpi->planes[0]=mpi->planes[0]; ++ dmpi->planes[1]=mpi->planes[1]; ++ dmpi->planes[2]=mpi->planes[2]; ++ dmpi->stride[0]=mpi->stride[0]; ++ dmpi->stride[1]=mpi->stride[1]; ++ dmpi->stride[2]=mpi->stride[2]; ++ dmpi->width=mpi->width; ++ dmpi->height=mpi->height; ++ } ++ ++ if(vf->priv->shot) { ++ if (vf->priv->shot==1) ++ vf->priv->shot=0; ++ gen_fname(vf->priv); ++ if (vf->priv->fname[0]) { ++ if (!vf->priv->store_slices) ++ scale_image(vf->priv, dmpi); ++ write_png(vf->priv); ++ } ++ vf->priv->store_slices = 0; ++ } ++ ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static int control (vf_instance_t *vf, int request, void *data) ++{ ++ /** data contains an integer argument ++ * 0: take screenshot with the next frame ++ * 1: take screenshots with each frame until the same command is given once again ++ **/ ++ if(request==VFCTRL_SCREENSHOT) { ++ if (data && *(int*)data) { // repeated screenshot mode ++ if (vf->priv->shot==2) ++ vf->priv->shot=0; ++ else ++ vf->priv->shot=2; ++ } else { // single screenshot ++ if (!vf->priv->shot) ++ vf->priv->shot=1; ++ } ++ return CONTROL_TRUE; ++ } ++ return vf_next_control (vf, request, data); ++} ++ ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch(fmt){ ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_UYVY: ++ case IMGFMT_YUY2: ++ case IMGFMT_BGR32: ++ case IMGFMT_BGR24: ++ case IMGFMT_BGR16: ++ case IMGFMT_BGR15: ++ case IMGFMT_BGR12: ++ case IMGFMT_RGB32: ++ case IMGFMT_RGB24: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static void uninit(vf_instance_t *vf) ++{ ++ avcodec_close(vf->priv->avctx); ++ av_freep(&vf->priv->avctx); ++ if(vf->priv->ctx) sws_freeContext(vf->priv->ctx); ++ av_free(vf->priv->buffer); ++ free(vf->priv->outbuffer); ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->config=config; ++ vf->control=control; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ vf->start_slice=start_slice; ++ vf->draw_slice=draw_slice; ++ vf->get_image=get_image; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ vf->priv->frameno=0; ++ vf->priv->shot=0; ++ vf->priv->store_slices=0; ++ vf->priv->buffer=0; ++ vf->priv->outbuffer=0; ++ vf->priv->ctx=0; ++ vf->priv->avctx = avcodec_alloc_context(); ++ avcodec_register_all(); ++ if (avcodec_open(vf->priv->avctx, avcodec_find_encoder(CODEC_ID_PNG))) { ++ mp_msg(MSGT_VFILTER, MSGL_FATAL, "Could not open libavcodec PNG encoder\n"); ++ return 0; ++ } ++ return 1; ++} ++ ++ ++const vf_info_t vf_info_screenshot = { ++ "screenshot to file", ++ "screenshot", ++ "A'rpi, Jindrich Makovicka", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_smartblur.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_smartblur.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_smartblur.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_smartblur.c 2012-05-14 14:08:54.780348958 +0200 +@@ -0,0 +1,264 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "libavutil/avutil.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libswscale/swscale.h" ++#include "vf_scale.h" ++ ++//===========================================================================// ++ ++typedef struct FilterParam{ ++ float radius; ++ float strength; ++ int threshold; ++ float quality; ++ struct SwsContext *filterContext; ++}FilterParam; ++ ++struct vf_priv_s { ++ FilterParam luma; ++ FilterParam chroma; ++}; ++ ++ ++/***************************************************************************/ ++ ++//FIXME stupid code duplication ++static void getSubSampleFactors(int *h, int *v, int format){ ++ switch(format){ ++ default: ++ assert(0); ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ *h=1; ++ *v=1; ++ break; ++ case IMGFMT_YVU9: ++ *h=2; ++ *v=2; ++ break; ++ case IMGFMT_444P: ++ *h=0; ++ *v=0; ++ break; ++ case IMGFMT_422P: ++ *h=1; ++ *v=0; ++ break; ++ case IMGFMT_411P: ++ *h=2; ++ *v=0; ++ break; ++ } ++} ++ ++static int allocStuff(FilterParam *f, int width, int height){ ++ SwsVector *vec; ++ SwsFilter swsF; ++ ++ vec = sws_getGaussianVec(f->radius, f->quality); ++ sws_scaleVec(vec, f->strength); ++ vec->coeff[vec->length/2]+= 1.0 - f->strength; ++ swsF.lumH= swsF.lumV= vec; ++ swsF.chrH= swsF.chrV= NULL; ++ f->filterContext= sws_getContext( ++ width, height, PIX_FMT_GRAY8, width, height, PIX_FMT_GRAY8, SWS_BICUBIC, &swsF, NULL, NULL); ++ ++ sws_freeVec(vec); ++ ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ int sw, sh; ++ ++ allocStuff(&vf->priv->luma, width, height); ++ ++ getSubSampleFactors(&sw, &sh, outfmt); ++ allocStuff(&vf->priv->chroma, width>>sw, height>>sh); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void freeBuffers(FilterParam *f){ ++ if(f->filterContext) sws_freeContext(f->filterContext); ++ f->filterContext=NULL; ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ freeBuffers(&vf->priv->luma); ++ freeBuffers(&vf->priv->chroma); ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++static inline void blur(uint8_t *dst, uint8_t *src, int w, int h, int dstStride, int srcStride, FilterParam *fp){ ++ int x, y; ++ FilterParam f= *fp; ++ const uint8_t* const srcArray[MP_MAX_PLANES] = {src}; ++ uint8_t *dstArray[MP_MAX_PLANES]= {dst}; ++ int srcStrideArray[MP_MAX_PLANES]= {srcStride}; ++ int dstStrideArray[MP_MAX_PLANES]= {dstStride}; ++ ++ sws_scale(f.filterContext, srcArray, srcStrideArray, 0, h, dstArray, dstStrideArray); ++ ++ if(f.threshold > 0){ ++ for(y=0; y 0){ ++ if(diff > 2*f.threshold){ ++ dst[x + y*dstStride]= orig; ++ }else if(diff > f.threshold){ ++ dst[x + y*dstStride]= filtered + diff - f.threshold; ++ } ++ }else{ ++ if(-diff > 2*f.threshold){ ++ dst[x + y*dstStride]= orig; ++ }else if(-diff > f.threshold){ ++ dst[x + y*dstStride]= filtered + diff + f.threshold; ++ } ++ } ++ } ++ } ++ }else if(f.threshold < 0){ ++ for(y=0; y 0){ ++ if(diff > -2*f.threshold){ ++ }else if(diff > -f.threshold){ ++ dst[x + y*dstStride]= orig - diff - f.threshold; ++ }else ++ dst[x + y*dstStride]= orig; ++ }else{ ++ if(diff < 2*f.threshold){ ++ }else if(diff < f.threshold){ ++ dst[x + y*dstStride]= orig - diff + f.threshold; ++ }else ++ dst[x + y*dstStride]= orig; ++ } ++ } ++ } ++ } ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int cw= mpi->w >> mpi->chroma_x_shift; ++ int ch= mpi->h >> mpi->chroma_y_shift; ++ int threshold = vf->priv->luma.threshold || vf->priv->chroma.threshold; ++ ++ mp_image_t *dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE| ++ (threshold ? MP_IMGFLAG_READABLE : 0), ++ mpi->w,mpi->h); ++ ++ assert(mpi->flags&MP_IMGFLAG_PLANAR); ++ ++ blur(dmpi->planes[0], mpi->planes[0], mpi->w,mpi->h, dmpi->stride[0], mpi->stride[0], &vf->priv->luma); ++ blur(dmpi->planes[1], mpi->planes[1], cw , ch , dmpi->stride[1], mpi->stride[1], &vf->priv->chroma); ++ blur(dmpi->planes[2], mpi->planes[2], cw , ch , dmpi->stride[2], mpi->stride[2], &vf->priv->chroma); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ int e; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++// vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ if(args==NULL) return 0; ++ ++ e=sscanf(args, "%f:%f:%d:%f:%f:%d", ++ &vf->priv->luma.radius, ++ &vf->priv->luma.strength, ++ &vf->priv->luma.threshold, ++ &vf->priv->chroma.radius, ++ &vf->priv->chroma.strength, ++ &vf->priv->chroma.threshold ++ ); ++ ++ vf->priv->luma.quality = vf->priv->chroma.quality= 3.0; ++ ++ if(e==3){ ++ vf->priv->chroma.radius= vf->priv->luma.radius; ++ vf->priv->chroma.strength= vf->priv->luma.strength; ++ vf->priv->chroma.threshold = vf->priv->luma.threshold; ++ }else if(e!=6) ++ return 0; ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_smartblur = { ++ "smart blur", ++ "smartblur", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_softpulldown.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_softpulldown.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_softpulldown.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_softpulldown.c 2012-05-14 14:08:54.781348978 +0200 +@@ -0,0 +1,164 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++struct vf_priv_s { ++ int state; ++ long long in; ++ long long out; ++}; ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ int ret = 0; ++ int flags = mpi->fields; ++ int state = vf->priv->state; ++ ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height); ++ ++ vf->priv->in++; ++ ++ if ((state == 0 && ++ !(flags & MP_IMGFIELD_TOP_FIRST)) || ++ (state == 1 && ++ flags & MP_IMGFIELD_TOP_FIRST)) { ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "softpulldown: Unexpected field flags: state=%d top_field_first=%d repeat_first_field=%d\n", ++ state, ++ (flags & MP_IMGFIELD_TOP_FIRST) != 0, ++ (flags & MP_IMGFIELD_REPEAT_FIRST) != 0); ++ state ^= 1; ++ } ++ ++ if (state == 0) { ++ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); ++ vf->priv->out++; ++ if (flags & MP_IMGFIELD_REPEAT_FIRST) { ++ my_memcpy_pic(dmpi->planes[0], ++ mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], ++ mpi->planes[1], ++ mpi->chroma_width, ++ mpi->chroma_height/2, ++ dmpi->stride[1]*2, ++ mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], ++ mpi->planes[2], ++ mpi->chroma_width, ++ mpi->chroma_height/2, ++ dmpi->stride[2]*2, ++ mpi->stride[2]*2); ++ } ++ state=1; ++ } ++ } else { ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ vf->priv->out++; ++ if (flags & MP_IMGFIELD_REPEAT_FIRST) { ++ ret |= vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); ++ vf->priv->out++; ++ state=0; ++ } else { ++ my_memcpy_pic(dmpi->planes[0], ++ mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], ++ mpi->planes[1], ++ mpi->chroma_width, ++ mpi->chroma_height/2, ++ dmpi->stride[1]*2, ++ mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], ++ mpi->planes[2], ++ mpi->chroma_width, ++ mpi->chroma_height/2, ++ dmpi->stride[2]*2, ++ mpi->stride[2]*2); ++ } ++ } ++ } ++ ++ vf->priv->state = state; ++ ++ return ret; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ mp_msg(MSGT_VFILTER, MSGL_INFO, "softpulldown: %lld frames in, %lld frames out\n", vf->priv->in, vf->priv->out); ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->config = config; ++ vf->put_image = put_image; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ vf->priv->state = 0; ++ return 1; ++} ++ ++const vf_info_t vf_info_softpulldown = { ++ "mpeg2 soft 3:2 pulldown", ++ "softpulldown", ++ "Tobias Diedrich ", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_softskip.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_softskip.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_softskip.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_softskip.c 2012-05-14 14:08:54.781348978 +0200 +@@ -0,0 +1,102 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int skipflag; ++}; ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ ++ if (vf->priv->skipflag) ++ return vf->priv->skipflag = 0; ++ ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_EXPORT, 0, mpi->width, mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++ dmpi->planes[0] = mpi->planes[0]; ++ dmpi->stride[0] = mpi->stride[0]; ++ if (dmpi->flags&MP_IMGFLAG_PLANAR) { ++ dmpi->planes[1] = mpi->planes[1]; ++ dmpi->stride[1] = mpi->stride[1]; ++ dmpi->planes[2] = mpi->planes[2]; ++ dmpi->stride[2] = mpi->stride[2]; ++ } ++ ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static int control(struct vf_instance *vf, int request, void* data) ++{ ++ switch (request) { ++ case VFCTRL_SKIP_NEXT_FRAME: ++ vf->priv->skipflag = 1; ++ return CONTROL_TRUE; ++ } ++ return vf_next_control(vf, request, data); ++} ++ ++#if 0 ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - figure out which other formats work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++#endif ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->put_image = put_image; ++ vf->control = control; ++ vf->uninit = uninit; ++ vf->priv = calloc(1, sizeof(struct vf_priv_s)); ++ return 1; ++} ++ ++const vf_info_t vf_info_softskip = { ++ "soft (post-filter) frame skipping for encoding", ++ "softskip", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_spp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_spp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_spp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_spp.c 2012-05-14 14:08:54.783349018 +0200 +@@ -0,0 +1,620 @@ ++/* ++ * Copyright (C) 2003 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/* ++ * This implementation is based on an algorithm described in ++ * "Aria Nosratinia Embedded Post-Processing for ++ * Enhancement of Compressed Images (1999)" ++ * (http://citeseer.nj.nec.com/nosratinia99embedded.html) ++ */ ++ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "libavutil/internal.h" ++#include "libavutil/intreadwrite.h" ++#include "libavcodec/avcodec.h" ++#include "libavcodec/dsputil.h" ++ ++#undef fprintf ++#undef free ++#undef malloc ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "vd_ffmpeg.h" ++#include "libvo/fastmemcpy.h" ++ ++#define XMIN(a,b) ((a) < (b) ? (a) : (b)) ++ ++//===========================================================================// ++static const uint8_t __attribute__((aligned(8))) dither[8][8]={ ++{ 0, 48, 12, 60, 3, 51, 15, 63, }, ++{ 32, 16, 44, 28, 35, 19, 47, 31, }, ++{ 8, 56, 4, 52, 11, 59, 7, 55, }, ++{ 40, 24, 36, 20, 43, 27, 39, 23, }, ++{ 2, 50, 14, 62, 1, 49, 13, 61, }, ++{ 34, 18, 46, 30, 33, 17, 45, 29, }, ++{ 10, 58, 6, 54, 9, 57, 5, 53, }, ++{ 42, 26, 38, 22, 41, 25, 37, 21, }, ++}; ++ ++static const uint8_t offset[127][2]= { ++{0,0}, ++{0,0}, {4,4}, ++{0,0}, {2,2}, {6,4}, {4,6}, ++{0,0}, {5,1}, {2,2}, {7,3}, {4,4}, {1,5}, {6,6}, {3,7}, ++ ++{0,0}, {4,0}, {1,1}, {5,1}, {3,2}, {7,2}, {2,3}, {6,3}, ++{0,4}, {4,4}, {1,5}, {5,5}, {3,6}, {7,6}, {2,7}, {6,7}, ++ ++{0,0}, {0,2}, {0,4}, {0,6}, {1,1}, {1,3}, {1,5}, {1,7}, ++{2,0}, {2,2}, {2,4}, {2,6}, {3,1}, {3,3}, {3,5}, {3,7}, ++{4,0}, {4,2}, {4,4}, {4,6}, {5,1}, {5,3}, {5,5}, {5,7}, ++{6,0}, {6,2}, {6,4}, {6,6}, {7,1}, {7,3}, {7,5}, {7,7}, ++ ++{0,0}, {4,4}, {0,4}, {4,0}, {2,2}, {6,6}, {2,6}, {6,2}, ++{0,2}, {4,6}, {0,6}, {4,2}, {2,0}, {6,4}, {2,4}, {6,0}, ++{1,1}, {5,5}, {1,5}, {5,1}, {3,3}, {7,7}, {3,7}, {7,3}, ++{1,3}, {5,7}, {1,7}, {5,3}, {3,1}, {7,5}, {3,5}, {7,1}, ++{0,1}, {4,5}, {0,5}, {4,1}, {2,3}, {6,7}, {2,7}, {6,3}, ++{0,3}, {4,7}, {0,7}, {4,3}, {2,1}, {6,5}, {2,5}, {6,1}, ++{1,0}, {5,4}, {1,4}, {5,0}, {3,2}, {7,6}, {3,6}, {7,2}, ++{1,2}, {5,6}, {1,6}, {5,2}, {3,0}, {7,4}, {3,4}, {7,0}, ++}; ++ ++struct vf_priv_s { ++ int log2_count; ++ int qp; ++ int mode; ++ int mpeg2; ++ int temp_stride; ++ uint8_t *src; ++ int16_t *temp; ++ AVCodecContext *avctx; ++ DSPContext dsp; ++ char *non_b_qp; ++}; ++ ++#define SHIFT 22 ++ ++static void hardthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ ++ int i; ++ int bias= 0; //FIXME ++ unsigned int threshold1, threshold2; ++ ++ threshold1= qp*((1<<4) - bias) - 1; ++ threshold2= (threshold1<<1); ++ ++ memset(dst, 0, 64*sizeof(DCTELEM)); ++ dst[0]= (src[0] + 4)>>3; ++ ++ for(i=1; i<64; i++){ ++ int level= src[i]; ++ if(((unsigned)(level+threshold1))>threshold2){ ++ const int j= permutation[i]; ++ dst[j]= (level + 4)>>3; ++ } ++ } ++} ++ ++static void softthresh_c(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ ++ int i; ++ int bias= 0; //FIXME ++ unsigned int threshold1, threshold2; ++ ++ threshold1= qp*((1<<4) - bias) - 1; ++ threshold2= (threshold1<<1); ++ ++ memset(dst, 0, 64*sizeof(DCTELEM)); ++ dst[0]= (src[0] + 4)>>3; ++ ++ for(i=1; i<64; i++){ ++ int level= src[i]; ++ if(((unsigned)(level+threshold1))>threshold2){ ++ const int j= permutation[i]; ++ if(level>0) ++ dst[j]= (level - threshold1 + 4)>>3; ++ else ++ dst[j]= (level + threshold1 + 4)>>3; ++ } ++ } ++} ++ ++#if HAVE_MMX ++static void hardthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ ++ int bias= 0; //FIXME ++ unsigned int threshold1; ++ ++ threshold1= qp*((1<<4) - bias) - 1; ++ ++ __asm__ volatile( ++#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ ++ "movq " #src0 ", %%mm0 \n\t"\ ++ "movq " #src1 ", %%mm1 \n\t"\ ++ "movq " #src2 ", %%mm2 \n\t"\ ++ "movq " #src3 ", %%mm3 \n\t"\ ++ "psubw %%mm4, %%mm0 \n\t"\ ++ "psubw %%mm4, %%mm1 \n\t"\ ++ "psubw %%mm4, %%mm2 \n\t"\ ++ "psubw %%mm4, %%mm3 \n\t"\ ++ "paddusw %%mm5, %%mm0 \n\t"\ ++ "paddusw %%mm5, %%mm1 \n\t"\ ++ "paddusw %%mm5, %%mm2 \n\t"\ ++ "paddusw %%mm5, %%mm3 \n\t"\ ++ "paddw %%mm6, %%mm0 \n\t"\ ++ "paddw %%mm6, %%mm1 \n\t"\ ++ "paddw %%mm6, %%mm2 \n\t"\ ++ "paddw %%mm6, %%mm3 \n\t"\ ++ "psubusw %%mm6, %%mm0 \n\t"\ ++ "psubusw %%mm6, %%mm1 \n\t"\ ++ "psubusw %%mm6, %%mm2 \n\t"\ ++ "psubusw %%mm6, %%mm3 \n\t"\ ++ "psraw $3, %%mm0 \n\t"\ ++ "psraw $3, %%mm1 \n\t"\ ++ "psraw $3, %%mm2 \n\t"\ ++ "psraw $3, %%mm3 \n\t"\ ++\ ++ "movq %%mm0, %%mm7 \n\t"\ ++ "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\ ++ "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\ ++ "movq %%mm1, %%mm2 \n\t"\ ++ "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\ ++ "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\ ++ "movq %%mm0, %%mm3 \n\t"\ ++ "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\ ++ "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\ ++ "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\ ++ "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\ ++\ ++ "movq %%mm0, " #dst0 " \n\t"\ ++ "movq %%mm7, " #dst1 " \n\t"\ ++ "movq %%mm3, " #dst2 " \n\t"\ ++ "movq %%mm1, " #dst3 " \n\t" ++ ++ "movd %2, %%mm4 \n\t" ++ "movd %3, %%mm5 \n\t" ++ "movd %4, %%mm6 \n\t" ++ "packssdw %%mm4, %%mm4 \n\t" ++ "packssdw %%mm5, %%mm5 \n\t" ++ "packssdw %%mm6, %%mm6 \n\t" ++ "packssdw %%mm4, %%mm4 \n\t" ++ "packssdw %%mm5, %%mm5 \n\t" ++ "packssdw %%mm6, %%mm6 \n\t" ++ REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0)) ++ REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0)) ++ REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0)) ++ REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0)) ++ : : "r" (src), "r" (dst), "g" (threshold1+1), "g" (threshold1+5), "g" (threshold1-4) //FIXME maybe more accurate then needed? ++ ); ++ dst[0]= (src[0] + 4)>>3; ++} ++ ++static void softthresh_mmx(DCTELEM dst[64], DCTELEM src[64], int qp, uint8_t *permutation){ ++ int bias= 0; //FIXME ++ unsigned int threshold1; ++ ++ threshold1= qp*((1<<4) - bias) - 1; ++ ++ __asm__ volatile( ++#undef REQUANT_CORE ++#define REQUANT_CORE(dst0, dst1, dst2, dst3, src0, src1, src2, src3) \ ++ "movq " #src0 ", %%mm0 \n\t"\ ++ "movq " #src1 ", %%mm1 \n\t"\ ++ "pxor %%mm6, %%mm6 \n\t"\ ++ "pxor %%mm7, %%mm7 \n\t"\ ++ "pcmpgtw %%mm0, %%mm6 \n\t"\ ++ "pcmpgtw %%mm1, %%mm7 \n\t"\ ++ "pxor %%mm6, %%mm0 \n\t"\ ++ "pxor %%mm7, %%mm1 \n\t"\ ++ "psubusw %%mm4, %%mm0 \n\t"\ ++ "psubusw %%mm4, %%mm1 \n\t"\ ++ "pxor %%mm6, %%mm0 \n\t"\ ++ "pxor %%mm7, %%mm1 \n\t"\ ++ "movq " #src2 ", %%mm2 \n\t"\ ++ "movq " #src3 ", %%mm3 \n\t"\ ++ "pxor %%mm6, %%mm6 \n\t"\ ++ "pxor %%mm7, %%mm7 \n\t"\ ++ "pcmpgtw %%mm2, %%mm6 \n\t"\ ++ "pcmpgtw %%mm3, %%mm7 \n\t"\ ++ "pxor %%mm6, %%mm2 \n\t"\ ++ "pxor %%mm7, %%mm3 \n\t"\ ++ "psubusw %%mm4, %%mm2 \n\t"\ ++ "psubusw %%mm4, %%mm3 \n\t"\ ++ "pxor %%mm6, %%mm2 \n\t"\ ++ "pxor %%mm7, %%mm3 \n\t"\ ++\ ++ "paddsw %%mm5, %%mm0 \n\t"\ ++ "paddsw %%mm5, %%mm1 \n\t"\ ++ "paddsw %%mm5, %%mm2 \n\t"\ ++ "paddsw %%mm5, %%mm3 \n\t"\ ++ "psraw $3, %%mm0 \n\t"\ ++ "psraw $3, %%mm1 \n\t"\ ++ "psraw $3, %%mm2 \n\t"\ ++ "psraw $3, %%mm3 \n\t"\ ++\ ++ "movq %%mm0, %%mm7 \n\t"\ ++ "punpcklwd %%mm2, %%mm0 \n\t" /*A*/\ ++ "punpckhwd %%mm2, %%mm7 \n\t" /*C*/\ ++ "movq %%mm1, %%mm2 \n\t"\ ++ "punpcklwd %%mm3, %%mm1 \n\t" /*B*/\ ++ "punpckhwd %%mm3, %%mm2 \n\t" /*D*/\ ++ "movq %%mm0, %%mm3 \n\t"\ ++ "punpcklwd %%mm1, %%mm0 \n\t" /*A*/\ ++ "punpckhwd %%mm7, %%mm3 \n\t" /*C*/\ ++ "punpcklwd %%mm2, %%mm7 \n\t" /*B*/\ ++ "punpckhwd %%mm2, %%mm1 \n\t" /*D*/\ ++\ ++ "movq %%mm0, " #dst0 " \n\t"\ ++ "movq %%mm7, " #dst1 " \n\t"\ ++ "movq %%mm3, " #dst2 " \n\t"\ ++ "movq %%mm1, " #dst3 " \n\t" ++ ++ "movd %2, %%mm4 \n\t" ++ "movd %3, %%mm5 \n\t" ++ "packssdw %%mm4, %%mm4 \n\t" ++ "packssdw %%mm5, %%mm5 \n\t" ++ "packssdw %%mm4, %%mm4 \n\t" ++ "packssdw %%mm5, %%mm5 \n\t" ++ REQUANT_CORE( (%1), 8(%1), 16(%1), 24(%1), (%0), 8(%0), 64(%0), 72(%0)) ++ REQUANT_CORE(32(%1), 40(%1), 48(%1), 56(%1),16(%0),24(%0), 48(%0), 56(%0)) ++ REQUANT_CORE(64(%1), 72(%1), 80(%1), 88(%1),32(%0),40(%0), 96(%0),104(%0)) ++ REQUANT_CORE(96(%1),104(%1),112(%1),120(%1),80(%0),88(%0),112(%0),120(%0)) ++ : : "r" (src), "r" (dst), "g" (threshold1), "rm" (4) //FIXME maybe more accurate then needed? ++ ); ++ ++ dst[0]= (src[0] + 4)>>3; ++} ++#endif ++ ++static inline void add_block(int16_t *dst, int stride, DCTELEM block[64]){ ++ int y; ++ ++ for(y=0; y<8; y++){ ++ *(uint32_t*)&dst[0 + y*stride]+= *(uint32_t*)&block[0 + y*8]; ++ *(uint32_t*)&dst[2 + y*stride]+= *(uint32_t*)&block[2 + y*8]; ++ *(uint32_t*)&dst[4 + y*stride]+= *(uint32_t*)&block[4 + y*8]; ++ *(uint32_t*)&dst[6 + y*stride]+= *(uint32_t*)&block[6 + y*8]; ++ } ++} ++ ++static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){ ++ int y, x; ++ ++#define STORE(pos) \ ++ temp= ((src[x + y*src_stride + pos]<>6;\ ++ if(temp & 0x100) temp= ~(temp>>31);\ ++ dst[x + y*dst_stride + pos]= temp; ++ ++ for(y=0; ylog2_count; ++ const int stride= is_luma ? p->temp_stride : ((width+16+15)&(~15)); ++ uint64_t __attribute__((aligned(16))) block_align[32]; ++ DCTELEM *block = (DCTELEM *)block_align; ++ DCTELEM *block2= (DCTELEM *)(block_align+16); ++ ++ if (!src || !dst) return; // HACK avoid crash for Y8 colourspace ++ for(y=0; ysrc + index, src + y*src_stride, width); ++ for(x=0; x<8; x++){ ++ p->src[index - x - 1]= p->src[index + x ]; ++ p->src[index + width + x ]= p->src[index + width - x - 1]; ++ } ++ } ++ for(y=0; y<8; y++){ ++ fast_memcpy(p->src + ( 7-y)*stride, p->src + ( y+8)*stride, stride); ++ fast_memcpy(p->src + (height+8+y)*stride, p->src + (height-y+7)*stride, stride); ++ } ++ //FIXME (try edge emu) ++ ++ for(y=0; ytemp + (8+y)*stride, 0, 8*stride*sizeof(int16_t)); ++ for(x=0; xqp) ++ qp= p->qp; ++ else{ ++ qp= qp_store[ (XMIN(x, width-1)>>qps) + (XMIN(y, height-1)>>qps) * qp_stride]; ++ qp = FFMAX(1, norm_qscale(qp, p->mpeg2)); ++ } ++ for(i=0; idsp.get_pixels(block, p->src + index, stride); ++ p->dsp.fdct(block); ++ requantize(block2, block, qp, p->dsp.idct_permutation); ++ p->dsp.idct(block2); ++ add_block(p->temp + index, stride, block2); ++ } ++ } ++ if(y) ++ store_slice(dst + (y-8)*dst_stride, p->temp + 8 + y*stride, dst_stride, stride, width, XMIN(8, height+8-y), 6-p->log2_count); ++ } ++#if 0 ++ for(y=0; y>6) ^ (y>>6)) & 1) == 0) ++ dst[x + y*dst_stride]= p->src[8 + 8*stride + x + y*stride]; ++ if((x&63) == 0 || (y&63)==0) ++ dst[x + y*dst_stride] += 128; ++ } ++ } ++#endif ++ //FIXME reorder for better caching ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int h= (height+16+15)&(~15); ++ ++ vf->priv->temp_stride= (width+16+15)&(~15); ++ vf->priv->temp= malloc(vf->priv->temp_stride*h*sizeof(int16_t)); ++ vf->priv->src = malloc(vf->priv->temp_stride*h*sizeof(uint8_t)); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ }else{ ++ dmpi=vf->dmpi; ++ } ++ ++ vf->priv->mpeg2= mpi->qscale_type; ++ if(mpi->pict_type != 3 && mpi->qscale && !vf->priv->qp){ ++ int w = mpi->qstride; ++ int h = (mpi->h + 15) >> 4; ++ if (!w) { ++ w = (mpi->w + 15) >> 4; ++ h = 1; ++ } ++ if(!vf->priv->non_b_qp) ++ vf->priv->non_b_qp= malloc(w*h); ++ fast_memcpy(vf->priv->non_b_qp, mpi->qscale, w*h); ++ } ++ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ char *qp_tab= vf->priv->non_b_qp; ++ if((vf->priv->mode&4) || !qp_tab) ++ qp_tab= mpi->qscale; ++ ++ if(qp_tab || vf->priv->qp){ ++ filter(vf->priv, dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, qp_tab, mpi->qstride, 1); ++ filter(vf->priv, dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0); ++ filter(vf->priv, dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, qp_tab, mpi->qstride, 0); ++ }else{ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); ++ } ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); ++#endif ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ if(!vf->priv) return; ++ ++ free(vf->priv->temp); ++ vf->priv->temp= NULL; ++ free(vf->priv->src); ++ vf->priv->src= NULL; ++ free(vf->priv->avctx); ++ vf->priv->avctx= NULL; ++ free(vf->priv->non_b_qp); ++ vf->priv->non_b_qp= NULL; ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_CLPL: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int control(struct vf_instance *vf, int request, void* data){ ++ switch(request){ ++ case VFCTRL_QUERY_MAX_PP_LEVEL: ++ return 6; ++ case VFCTRL_SET_PP_LEVEL: ++ vf->priv->log2_count= *((unsigned int*)data); ++ return CONTROL_TRUE; ++ } ++ return vf_next_control(vf,request,data); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ ++ int log2c=-1; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->control= control; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ init_avcodec(); ++ ++ vf->priv->avctx= avcodec_alloc_context(); ++ dsputil_init(&vf->priv->dsp, vf->priv->avctx); ++ ++ vf->priv->log2_count= 3; ++ ++ if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode); ++ ++ if( log2c >=0 && log2c <=6 ) ++ vf->priv->log2_count = log2c; ++ ++ if(vf->priv->qp < 0) ++ vf->priv->qp = 0; ++ ++ switch(vf->priv->mode&3){ ++ default: ++ case 0: requantize= hardthresh_c; break; ++ case 1: requantize= softthresh_c; break; ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX){ ++ store_slice= store_slice_mmx; ++ switch(vf->priv->mode&3){ ++ case 0: requantize= hardthresh_mmx; break; ++ case 1: requantize= softthresh_mmx; break; ++ } ++ } ++#endif ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_spp = { ++ "simple postprocess", ++ "spp", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_stereo3d.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_stereo3d.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_stereo3d.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_stereo3d.c 2012-05-14 14:08:54.785349058 +0200 +@@ -0,0 +1,512 @@ ++/* ++ * Copyright (C) 2010 Gordon Schmidt s2000.tu-chemnitz.de> ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++//==includes==// ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libavutil/common.h" ++#include "libvo/fastmemcpy.h" ++ ++//==types==// ++typedef enum stereo_code { ++ ANAGLYPH_RC_GRAY, //anaglyph red/cyan gray ++ ANAGLYPH_RC_HALF, //anaglyph red/cyan half colored ++ ANAGLYPH_RC_COLOR, //anaglyph red/cyan colored ++ ANAGLYPH_RC_DUBOIS, //anaglyph red/cyan dubois ++ ANAGLYPH_GM_GRAY, //anaglyph green/magenta gray ++ ANAGLYPH_GM_HALF, //anaglyph green/magenta half colored ++ ANAGLYPH_GM_COLOR, //anaglyph green/magenta colored ++ ANAGLYPH_YB_GRAY, //anaglyph yellow/blue gray ++ ANAGLYPH_YB_HALF, //anaglyph yellow/blue half colored ++ ANAGLYPH_YB_COLOR, //anaglyph yellow/blue colored ++ MONO_L, //mono output for debugging (left eye only) ++ MONO_R, //mono output for debugging (right eye only) ++ SIDE_BY_SIDE_LR, //side by side parallel (left eye left, right eye right) ++ SIDE_BY_SIDE_RL, //side by side crosseye (right eye left, left eye right) ++ SIDE_BY_SIDE_2_LR, //side by side parallel with half width resolution ++ SIDE_BY_SIDE_2_RL, //side by side crosseye with half width resolution ++ ABOVE_BELOW_LR, //above-below (left eye above, right eye below) ++ ABOVE_BELOW_RL, //above-below (right eye above, left eye below) ++ ABOVE_BELOW_2_LR, //above-below with half height resolution ++ ABOVE_BELOW_2_RL, //above-below with half height resolution ++ INTERLEAVE_ROWS_LR, //row-interleave (left eye has top row) ++ INTERLEAVE_ROWS_RL, //row-interleave (right eye has top row) ++ STEREO_CODE_COUNT //no value set - TODO: needs autodetection ++} stereo_code; ++ ++typedef struct component { ++ stereo_code fmt; ++ unsigned int width; ++ unsigned int height; ++ unsigned int off_left; ++ unsigned int off_right; ++ unsigned int row_left; ++ unsigned int row_right; ++} component; ++ ++//==global variables==// ++static const int ana_coeff[10][3][6] = { ++ {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_GRAY ++ { 0, 0, 0, 19595, 38470, 7471}, ++ { 0, 0, 0, 19595, 38470, 7471}}, ++ {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_HALF ++ { 0, 0, 0, 0, 65536, 0}, ++ { 0, 0, 0, 0, 0, 65536}}, ++ {{65536, 0, 0, 0, 0, 0}, //ANAGLYPH_RC_COLOR ++ { 0, 0, 0, 0, 65536, 0}, ++ { 0, 0, 0, 0, 0, 65536}}, ++ {{29891, 32800, 11559, -2849, -5763, -102}, //ANAGLYPH_RC_DUBOIS ++ {-2627, -2479, -1033, 24804, 48080, -1209}, ++ { -997, -1350, -358, -4729, -7403, 80373}}, ++ {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_GM_GRAY ++ {19595, 38470, 7471, 0, 0, 0}, ++ { 0, 0, 0, 19595, 38470, 7471}}, ++ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_HALF ++ {19595, 38470, 7471, 0, 0, 0}, ++ { 0, 0, 0, 0, 0, 65536}}, ++ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_COLOR ++ { 0, 65536, 0, 0, 0, 0}, ++ { 0, 0, 0, 0, 0, 65536}}, ++ {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_YB_GRAY ++ { 0, 0, 0, 19595, 38470, 7471}, ++ {19595, 38470, 7471, 0, 0, 0}}, ++ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_HALF ++ { 0, 0, 0, 0, 65536, 0}, ++ {19595, 38470, 7471, 0, 0, 0}}, ++ {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_COLOR ++ { 0, 0, 0, 0, 65536, 0}, ++ { 0, 0, 65536, 0, 0, 0}} ++}; ++ ++struct vf_priv_s { ++ component in; ++ component out; ++ int ana_matrix[3][6]; ++ unsigned int width; ++ unsigned int height; ++ unsigned int row_step; ++} const vf_priv_default = { ++ {SIDE_BY_SIDE_LR}, ++ {ANAGLYPH_RC_DUBOIS} ++}; ++ ++//==functions==// ++static inline uint8_t ana_convert(int coeff[6], uint8_t left[3], uint8_t right[3]) ++{ ++ int sum; ++ ++ sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in ++ sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in ++ sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in ++ return av_clip_uint8(sum >> 16); ++} ++ ++static int config(struct vf_instance *vf, int width, int height, int d_width, ++ int d_height, unsigned int flags, unsigned int outfmt) ++{ ++ if ((width & 1) || (height & 1)) { ++ mp_msg(MSGT_VFILTER, MSGL_WARN, "[stereo3d] invalid height or width\n"); ++ return 0; ++ } ++ //default input values ++ vf->priv->width = width; ++ vf->priv->height = height; ++ vf->priv->row_step = 1; ++ vf->priv->in.width = width; ++ vf->priv->in.height = height; ++ vf->priv->in.off_left = 0; ++ vf->priv->in.off_right = 0; ++ vf->priv->in.row_left = 0; ++ vf->priv->in.row_right = 0; ++ ++ //check input format ++ switch (vf->priv->in.fmt) { ++ case SIDE_BY_SIDE_2_LR: ++ d_width *= 2; ++ case SIDE_BY_SIDE_LR: ++ vf->priv->width = width / 2; ++ vf->priv->in.off_right = vf->priv->width * 3; ++ break; ++ case SIDE_BY_SIDE_2_RL: ++ d_width *= 2; ++ case SIDE_BY_SIDE_RL: ++ vf->priv->width = width / 2; ++ vf->priv->in.off_left = vf->priv->width * 3; ++ break; ++ case ABOVE_BELOW_2_LR: ++ d_height *= 2; ++ case ABOVE_BELOW_LR: ++ vf->priv->height = height / 2; ++ vf->priv->in.row_right = vf->priv->height; ++ break; ++ case ABOVE_BELOW_2_RL: ++ d_height *= 2; ++ case ABOVE_BELOW_RL: ++ vf->priv->height = height / 2; ++ vf->priv->in.row_left = vf->priv->height; ++ break; ++ default: ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "[stereo3d] stereo format of input is not supported\n"); ++ return 0; ++ break; ++ } ++ //default output values ++ vf->priv->out.width = vf->priv->width; ++ vf->priv->out.height = vf->priv->height; ++ vf->priv->out.off_left = 0; ++ vf->priv->out.off_right = 0; ++ vf->priv->out.row_left = 0; ++ vf->priv->out.row_right = 0; ++ ++ //check output format ++ switch (vf->priv->out.fmt) { ++ case ANAGLYPH_RC_GRAY: ++ case ANAGLYPH_RC_HALF: ++ case ANAGLYPH_RC_COLOR: ++ case ANAGLYPH_RC_DUBOIS: ++ case ANAGLYPH_GM_GRAY: ++ case ANAGLYPH_GM_HALF: ++ case ANAGLYPH_GM_COLOR: ++ case ANAGLYPH_YB_GRAY: ++ case ANAGLYPH_YB_HALF: ++ case ANAGLYPH_YB_COLOR: ++ memcpy(vf->priv->ana_matrix, ana_coeff[vf->priv->out.fmt], ++ sizeof(vf->priv->ana_matrix)); ++ break; ++ case SIDE_BY_SIDE_2_LR: ++ d_width /= 2; ++ case SIDE_BY_SIDE_LR: ++ vf->priv->out.width = vf->priv->width * 2; ++ vf->priv->out.off_right = vf->priv->width * 3; ++ break; ++ case SIDE_BY_SIDE_2_RL: ++ d_width /= 2; ++ case SIDE_BY_SIDE_RL: ++ vf->priv->out.width = vf->priv->width * 2; ++ vf->priv->out.off_left = vf->priv->width * 3; ++ break; ++ case ABOVE_BELOW_2_LR: ++ d_height /= 2; ++ case ABOVE_BELOW_LR: ++ vf->priv->out.height = vf->priv->height * 2; ++ vf->priv->out.row_right = vf->priv->height; ++ break; ++ case ABOVE_BELOW_2_RL: ++ d_height /= 2; ++ case ABOVE_BELOW_RL: ++ vf->priv->out.height = vf->priv->height * 2; ++ vf->priv->out.row_left = vf->priv->height; ++ break; ++ case INTERLEAVE_ROWS_LR: ++ vf->priv->row_step = 2; ++ vf->priv->height = vf->priv->height / 2; ++ vf->priv->out.off_right = vf->priv->width * 3; ++ vf->priv->in.off_right += vf->priv->in.width * 3; ++ break; ++ case INTERLEAVE_ROWS_RL: ++ vf->priv->row_step = 2; ++ vf->priv->height = vf->priv->height / 2; ++ vf->priv->out.off_left = vf->priv->width * 3; ++ vf->priv->in.off_left += vf->priv->in.width * 3; ++ break; ++ case MONO_R: ++ //same as MONO_L only needs switching of input offsets ++ vf->priv->in.off_left = vf->priv->in.off_right; ++ vf->priv->in.row_left = vf->priv->in.row_right; ++ //nobreak; ++ case MONO_L: ++ //use default settings ++ break; ++ default: ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "[stereo3d] stereo format of output is not supported\n"); ++ return 0; ++ break; ++ } ++// if (!opt_screen_size_x && !opt_screen_size_y) { ++ d_width = d_width * vf->priv->out.width / width; ++ d_height = d_height * vf->priv->out.height / height; ++// } ++ ++ return vf_next_config(vf, vf->priv->out.width, vf->priv->out.height, ++ d_width, d_height, flags, outfmt); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do ++ dmpi = mpi; ++ } else { ++ int out_off_left, out_off_right; ++ int in_off_left = vf->priv->in.row_left * mpi->stride[0] + ++ vf->priv->in.off_left; ++ int in_off_right = vf->priv->in.row_right * mpi->stride[0] + ++ vf->priv->in.off_right; ++ ++ dmpi = vf_get_image(vf->next, IMGFMT_RGB24, MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE, ++ vf->priv->out.width, vf->priv->out.height); ++ out_off_left = vf->priv->out.row_left * dmpi->stride[0] + ++ vf->priv->out.off_left; ++ out_off_right = vf->priv->out.row_right * dmpi->stride[0] + ++ vf->priv->out.off_right; ++ ++ switch (vf->priv->out.fmt) { ++ case SIDE_BY_SIDE_LR: ++ case SIDE_BY_SIDE_RL: ++ case SIDE_BY_SIDE_2_LR: ++ case SIDE_BY_SIDE_2_RL: ++ case ABOVE_BELOW_LR: ++ case ABOVE_BELOW_RL: ++ case ABOVE_BELOW_2_LR: ++ case ABOVE_BELOW_2_RL: ++ case INTERLEAVE_ROWS_LR: ++ case INTERLEAVE_ROWS_RL: ++ memcpy_pic2(dmpi->planes[0] + out_off_left, ++ mpi->planes[0] + in_off_left, ++ 3 * vf->priv->width, ++ vf->priv->height, ++ dmpi->stride[0] * vf->priv->row_step, ++ mpi->stride[0] * vf->priv->row_step, ++ vf->priv->row_step != 1); ++ memcpy_pic2(dmpi->planes[0] + out_off_right, ++ mpi->planes[0] + in_off_right, ++ 3 * vf->priv->width, ++ vf->priv->height, ++ dmpi->stride[0] * vf->priv->row_step, ++ mpi->stride[0] * vf->priv->row_step, ++ vf->priv->row_step != 1); ++ break; ++ case MONO_L: ++ case MONO_R: ++ memcpy_pic(dmpi->planes[0], ++ mpi->planes[0] + in_off_left, ++ 3 * vf->priv->width, ++ vf->priv->height, ++ dmpi->stride[0], ++ mpi->stride[0]); ++ break; ++ case ANAGLYPH_RC_GRAY: ++ case ANAGLYPH_RC_HALF: ++ case ANAGLYPH_RC_COLOR: ++ case ANAGLYPH_RC_DUBOIS: ++ case ANAGLYPH_GM_GRAY: ++ case ANAGLYPH_GM_HALF: ++ case ANAGLYPH_GM_COLOR: ++ case ANAGLYPH_YB_GRAY: ++ case ANAGLYPH_YB_HALF: ++ case ANAGLYPH_YB_COLOR: { ++ int i,x,y,il,ir,o; ++ unsigned char *source = mpi->planes[0]; ++ unsigned char *dest = dmpi->planes[0]; ++ unsigned int out_width = vf->priv->out.width; ++ int *ana_matrix[3]; ++ ++ for(i = 0; i < 3; i++) ++ ana_matrix[i] = vf->priv->ana_matrix[i]; ++ ++ for (y = 0; y < vf->priv->out.height; y++) { ++ o = dmpi->stride[0] * y; ++ il = in_off_left + y * mpi->stride[0]; ++ ir = in_off_right + y * mpi->stride[0]; ++ for (x = 0; x < out_width; x++) { ++ dest[o ] = ana_convert( ++ ana_matrix[0], source + il, source + ir); //red out ++ dest[o + 1] = ana_convert( ++ ana_matrix[1], source + il, source + ir); //green out ++ dest[o + 2] = ana_convert( ++ ana_matrix[2], source + il, source + ir); //blue out ++ il += 3; ++ ir += 3; ++ o += 3; ++ } ++ } ++ break; ++ } ++ default: ++ mp_msg(MSGT_VFILTER, MSGL_WARN, ++ "[stereo3d] stereo format of output is not supported\n"); ++ return 0; ++ break; ++ } ++ } ++ return vf_next_put_image(vf, dmpi, pts); ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch (fmt) ++ case IMGFMT_RGB24: ++ return vf_next_query_format(vf, fmt); ++ return 0; ++} ++ ++static void uninit(vf_instance_t *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ vf->config = config; ++ vf->uninit = uninit; ++ vf->put_image = put_image; ++ vf->query_format = query_format; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ vf->priv->in.fmt = SIDE_BY_SIDE_LR; ++ vf->priv->out.fmt= ANAGLYPH_RC_DUBOIS; ++ if (args) sscanf(args, "%d:%d", &vf->priv->in.fmt, &vf->priv->out.fmt); ++ ++ return 1; ++} ++#if 0 ++///Presets usage ++static const struct format_preset { ++ char* name; ++ stereo_code scode; ++} vf_format_presets_defs[] = { ++ {"arcg", ANAGLYPH_RC_GRAY}, ++ {"anaglyph_red_cyan_gray", ANAGLYPH_RC_GRAY}, ++ {"arch", ANAGLYPH_RC_HALF}, ++ {"anaglyph_red_cyan_half_color", ANAGLYPH_RC_HALF}, ++ {"arcc", ANAGLYPH_RC_COLOR}, ++ {"anaglyph_red_cyan_color", ANAGLYPH_RC_COLOR}, ++ {"arcd", ANAGLYPH_RC_DUBOIS}, ++ {"anaglyph_red_cyan_dubios", ANAGLYPH_RC_DUBOIS}, ++ {"agmg", ANAGLYPH_GM_GRAY}, ++ {"anaglyph_green_magenta_gray", ANAGLYPH_GM_GRAY}, ++ {"agmh", ANAGLYPH_GM_HALF}, ++ {"anaglyph_green_magenta_half_color",ANAGLYPH_GM_HALF}, ++ {"agmc", ANAGLYPH_GM_COLOR}, ++ {"anaglyph_green_magenta_color", ANAGLYPH_GM_COLOR}, ++ {"aybg", ANAGLYPH_YB_GRAY}, ++ {"anaglyph_yellow_blue_gray", ANAGLYPH_YB_GRAY}, ++ {"aybh", ANAGLYPH_YB_HALF}, ++ {"anaglyph_yellow_blue_half_color", ANAGLYPH_YB_HALF}, ++ {"aybc", ANAGLYPH_YB_COLOR}, ++ {"anaglyph_yellow_blue_color", ANAGLYPH_YB_COLOR}, ++ {"ml", MONO_L}, ++ {"mono_left", MONO_L}, ++ {"mr", MONO_R}, ++ {"mono_right", MONO_R}, ++ {"sbsl", SIDE_BY_SIDE_LR}, ++ {"side_by_side_left_first", SIDE_BY_SIDE_LR}, ++ {"sbsr", SIDE_BY_SIDE_RL}, ++ {"side_by_side_right_first", SIDE_BY_SIDE_RL}, ++ {"sbs2l", SIDE_BY_SIDE_2_LR}, ++ {"side_by_side_half_width_left_first", SIDE_BY_SIDE_2_LR}, ++ {"sbs2r", SIDE_BY_SIDE_2_RL}, ++ {"side_by_side_half_width_right_first",SIDE_BY_SIDE_2_RL}, ++ {"abl", ABOVE_BELOW_LR}, ++ {"above_below_left_first", ABOVE_BELOW_LR}, ++ {"abr", ABOVE_BELOW_RL}, ++ {"above_below_right_first", ABOVE_BELOW_RL}, ++ {"ab2l", ABOVE_BELOW_2_LR}, ++ {"above_below_half_height_left_first", ABOVE_BELOW_2_LR}, ++ {"ab2r", ABOVE_BELOW_2_RL}, ++ {"above_below_half_height_right_first",ABOVE_BELOW_2_RL}, ++ {"irl", INTERLEAVE_ROWS_LR}, ++ {"interleave_rows_left_first", INTERLEAVE_ROWS_LR}, ++ {"irr", INTERLEAVE_ROWS_RL}, ++ {"interleave_rows_right_first", INTERLEAVE_ROWS_RL}, ++ { NULL, 0} ++}; ++ ++#define ST_OFF(f) M_ST_OFF(struct format_preset,f) ++static const m_option_t vf_format_preset_fields_in[] = { ++ {"in", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL}, ++ { NULL, NULL, 0, 0, 0, 0, NULL } ++}; ++static const m_option_t vf_format_preset_fields_out[] = { ++ {"out", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL}, ++ { NULL, NULL, 0, 0, 0, 0, NULL } ++}; ++ ++static const m_struct_t vf_format_preset_in = { ++ "stereo_format_preset_in", ++ sizeof(struct format_preset), ++ NULL, ++ vf_format_preset_fields_in ++}; ++static const m_struct_t vf_format_preset_out = { ++ "stereo_format_preset_out", ++ sizeof(struct format_preset), ++ NULL, ++ vf_format_preset_fields_out ++}; ++ ++static const m_struct_t vf_opts; ++static const m_obj_presets_t format_preset_in = { ++ (struct m_struct_st*)&vf_format_preset_in, ++ (struct m_struct_st*)&vf_opts, ++ (struct format_preset*)vf_format_presets_defs, ++ ST_OFF(name) ++}; ++static const m_obj_presets_t format_preset_out = { ++ (struct m_struct_st*)&vf_format_preset_out, ++ (struct m_struct_st*)&vf_opts, ++ (struct format_preset*)vf_format_presets_defs, ++ ST_OFF(name) ++}; ++ ++/// Now the options ++#undef ST_OFF ++#define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) ++static const m_option_t vf_opts_fields[] = { ++ {"stereo_in", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, ++ (m_obj_presets_t*)&format_preset_in}, ++ {"stereo_out", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, ++ (m_obj_presets_t*)&format_preset_out}, ++ {"in", ST_OFF(in.fmt), CONF_TYPE_INT, 0,0,0, NULL}, ++ {"out", ST_OFF(out.fmt), CONF_TYPE_INT, 0,0,0, NULL}, ++ { NULL, NULL, 0, 0, 0, 0, NULL } ++}; ++ ++static const m_struct_t vf_opts = { ++ "stereo3d", ++ sizeof(struct vf_priv_s), ++ &vf_priv_default, ++ vf_opts_fields ++}; ++#endif ++ ++//==info struct==// ++const vf_info_t vf_info_stereo3d = { ++ "stereoscopic 3d view", ++ "stereo3d", ++ "Gordon Schmidt", ++ "view stereoscopic videos", ++ vf_open, ++// &vf_opts ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_swapuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_swapuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_swapuv.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_swapuv.c 2012-05-14 14:08:54.786349078 +0200 +@@ -0,0 +1,106 @@ ++/* ++ * Copyright (C) 2002 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "mp_msg.h" ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++ ++//===========================================================================// ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ mp_image_t *dmpi= vf_get_image(vf->next, mpi->imgfmt, ++ mpi->type, mpi->flags, mpi->w, mpi->h); ++ ++ mpi->planes[0]=dmpi->planes[0]; ++ mpi->planes[1]=dmpi->planes[2]; ++ mpi->planes[2]=dmpi->planes[1]; ++ mpi->stride[0]=dmpi->stride[0]; ++ mpi->stride[1]=dmpi->stride[2]; ++ mpi->stride[2]=dmpi->stride[1]; ++ mpi->width=dmpi->width; ++ ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++ mpi->priv=(void*)dmpi; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(mpi->flags&MP_IMGFLAG_DIRECT){ ++ dmpi=(mp_image_t*)mpi->priv; ++ } else { ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_EXPORT, 0, mpi->w, mpi->h); ++ assert(mpi->flags&MP_IMGFLAG_PLANAR); ++ dmpi->planes[0]=mpi->planes[0]; ++ dmpi->planes[1]=mpi->planes[2]; ++ dmpi->planes[2]=mpi->planes[1]; ++ dmpi->stride[0]=mpi->stride[0]; ++ dmpi->stride[1]=mpi->stride[2]; ++ dmpi->stride[2]=mpi->stride[1]; ++ dmpi->width=mpi->width; ++ } ++ ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++//===========================================================================// ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt) ++ { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_YVU9: ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ return 1; ++} ++ ++const vf_info_t vf_info_swapuv = { ++ "UV swapper", ++ "swapuv", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_telecine.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_telecine.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_telecine.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_telecine.c 2012-05-14 14:08:54.787349099 +0200 +@@ -0,0 +1,155 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++struct vf_priv_s { ++ int frame; ++}; ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ int ret; ++ ++ vf->priv->frame = (vf->priv->frame+1)%4; ++ ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE, mpi->width, mpi->height); ++ ++ ret = 0; ++ // 0/0 1/1 2/2 2/3 3/0 ++ switch (vf->priv->frame) { ++ case 0: ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ case 1: ++ case 2: ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0], mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2], mpi->stride[2]); ++ } ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE) || ret; ++ case 3: ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ return ret; ++ } ++ return 0; ++} ++ ++#if 0 ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - figure out which other formats work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++#endif ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ //vf->config = config; ++ vf->put_image = put_image; ++ //vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = calloc(1, sizeof(struct vf_priv_s)); ++ vf->priv->frame = 1; ++ if (args) sscanf(args, "%d", &vf->priv->frame); ++ vf->priv->frame--; ++ return 1; ++} ++ ++const vf_info_t vf_info_telecine = { ++ "telecine filter", ++ "telecine", ++ "Rich Felker", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_tile.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_tile.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_tile.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_tile.c 2012-05-14 14:08:54.788349119 +0200 +@@ -0,0 +1,330 @@ ++/* ++ * filter to tile a serie of image in a single, bigger, image ++ * ++ * The parameters are: ++ * ++ * xtile: number of tile on the x axis (5) ++ * ytile: number of tile on the y axis (5) ++ * xytile: when write the image, it can be different then xtile * ytile ++ * (for example you can write 8 * 7 tile, writing the file every ++ * 50 frame, to have one image every 2 seconds @ 25 fps ). ++ * start: pixel at the start (x/y), default 2 ++ * delta: pixel between 2 tile, (x/y), default 4 ++ * ++ * For example a valid command line is: ++ * ... -vf tile=10:5:-1:4:8 ... ++ * that make images of 10 * 5 tiles, with 4 pixel at the beginning and ++ * 8 pixel between tiles. ++ * ++ * The default command is: ++ * ... -vf tile=5:5:25:2:4 ++ * ++ * If you omit a parameter or put a value less then 0, the default is used. ++ * ... -vf tile=10:5::-1:10 ++ * ++ * You can also stop when you're ok ++ * ... -vf tile=10:5 ++ * (and this is probably the option you will use more often ...) ++ * ++ * Probably is good to put the scale filter before the tile :-) ++ * ++ * copyright (c) 2003 Daniele Forghieri ( guru@digitalfantasy.it ) ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++// strtoi memcpy_pic ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++#include "cpudetect.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++/* private data */ ++struct vf_priv_s { ++ /* configuration data */ ++ /* Number on hor/ver tiles */ ++ int xtile; ++ int ytile; ++ /* When write the whole frame (default = xtile * ytile) */ ++ int xytile; ++ /* pixel at start / end (default = 4) */ ++ int start; ++ /* pixel between image (default = 2) */ ++ int delta; ++// /* Background color, in destination format */ ++// int bkgSet; ++ ++ /* Work data */ ++ int frame_cur; ++}; ++ ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ struct vf_priv_s *priv; ++ int xw; ++ int yh; ++ ++ /* Calculate new destination size */ ++ priv = vf->priv; ++ xw = priv->start * 2 + ++ priv->xtile * width + ++ (priv->xtile - 1) * priv->delta; ++ yh = priv->start * 2 + ++ priv->ytile * height + ++ (priv->ytile - 1) * priv->delta; ++ ++ mp_msg(MSGT_VFILTER,MSGL_V,"vf_tile:config size set to %d * %d\n", xw, yh); ++ ++ return vf_next_config(vf, xw, yh, xw, yh, flags, outfmt); ++} ++ ++/* Filter handler */ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ mp_image_t *dmpi; ++ struct vf_priv_s *priv; ++ int t; ++ int xw; ++ int yh; ++ int xi; ++ int yi; ++ int by; ++ int dw; ++ ++ /* Calculate new size */ ++ priv = vf->priv; ++ xw = priv->start * 2 + ++ priv->xtile * mpi->w + ++ (priv->xtile - 1) * priv->delta; ++ yh = priv->start * 2 + ++ priv->ytile * mpi->h+ ++ (priv->ytile - 1) * priv->delta; ++ ++ /* Get the big image! */ ++ dmpi=vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE, ++ xw, yh); ++ ++ /* bytes x pixel & bytes x line */ ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ by = 1; ++ dw = mpi->w; ++ } ++ else { ++ by = (mpi->bpp + 7) / 8; ++ dw = mpi->w * by; ++ } ++ /* Index position */ ++ t = priv->frame_cur % priv->xytile; ++// if ((t == 0) && (bkg != 0)) { ++// /* First frame, delete the background */ ++// ++// } ++ ++ /* Position of image */ ++ xi = priv->start + (mpi->w + priv->delta) * (t % priv->xtile); ++ yi = priv->start + (mpi->h + priv->delta) * (t / priv->xtile); ++ ++ /* Copy first (or only) plane */ ++ memcpy_pic( dmpi->planes[0] + xi * by + yi * dmpi->stride[0], ++ mpi->planes[0], ++ dw, ++ mpi->h, ++ dmpi->stride[0], ++ mpi->stride[0]); ++ ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ /* Copy the other 2 planes */ ++ memcpy_pic( dmpi->planes[1] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[1], ++ mpi->planes[1], ++ mpi->chroma_width, ++ mpi->chroma_height, ++ dmpi->stride[1], ++ mpi->stride[1]); ++ memcpy_pic( dmpi->planes[2] + (xi >> mpi->chroma_x_shift) + (yi >> mpi->chroma_y_shift) * dmpi->stride[2], ++ mpi->planes[2], ++ mpi->chroma_width, ++ mpi->chroma_height, ++ dmpi->stride[2], ++ mpi->stride[2]); ++ } ++ ++ /* Increment current frame */ ++ ++priv->frame_cur; ++ ++ if (t == priv->xytile - 1) { ++ /* Display the composition */ ++ dmpi->width = xw; ++ dmpi->height = yh; ++ return vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ else { ++ /* Skip the frame */ ++ return 0; ++ } ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ /* free local data */ ++ free(vf->priv); ++} ++ ++/* rgb/bgr 12...32 supported & some Yxxx */ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ switch (fmt) { ++ /* rgb 12...32 bit */ ++ case IMGFMT_RGB12: ++ case IMGFMT_RGB15: ++ case IMGFMT_RGB16: ++ case IMGFMT_RGB24: ++ case IMGFMT_RGB32: ++ /* bgr 12...32 bit */ ++ case IMGFMT_BGR12: ++ case IMGFMT_BGR15: ++ case IMGFMT_BGR16: ++ case IMGFMT_BGR24: ++ case IMGFMT_BGR32: ++ /* Various Yxxx Formats */ ++ case IMGFMT_444P: ++ case IMGFMT_422P: ++ case IMGFMT_411P: ++ case IMGFMT_YUY2: ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_YVU9: ++ case IMGFMT_IF09: ++ case IMGFMT_IYUV: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++/* Get an integer from the string pointed by s, adjusting s. ++ * If the value is less then 0 def_val is used. ++ * Return 0 for ok ++ * ++ * Look below ( in vf_open(...) ) for a use ... ++ */ ++static int parse_int(char **s, int *rt, int def_val) ++{ ++ ++ int t = 0; ++ ++ if (**s) { ++ /* Get value (dec, hex or octal) */ ++ t = strtol( *s, s, 0 ); ++ ++ /* Use default */ ++ if (t < 0) { ++ t = def_val; ++ } ++ ++ if (**s == ':') { ++ /* Point to next character (problably a digit) */ ++ ++(*s); ++ } ++ else if (**s != '\0') { ++ /* Error, we got some wrong char */ ++ return 1; ++ } ++ } ++ else { ++ t = def_val; ++ } ++ ++ *rt = t; ++ return 0; ++ ++} ++ ++/* Main entry funct for the filter */ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ int er; ++ ++ vf->put_image = put_image; ++ vf->query_format = query_format; ++ vf->config = config; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ /* Private data */ ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ if (p == NULL) { ++ return 0; ++ } ++ ++ if (args == NULL) { ++ /* Use the default */ ++ args = ""; ++ } ++ /* Parse all the arguments */ ++ er = parse_int( &args, &p->xtile, 5 ); ++ er |= parse_int( &args, &p->ytile, 5 ); ++ er |= parse_int( &args, &p->xytile, 0 ); ++ er |= parse_int( &args, &p->start, 2 ); ++ er |= parse_int( &args, &p->delta, 4 ); ++// er |= parse_int( &args, &p->bkgSet, 0 ); ++ ++ if (er) { ++ mp_msg(MSGT_VFILTER, MSGL_ERR, MSGTR_MPCODECS_ErrorParsingArgument); ++ return 0; ++ } ++ /* Load some default */ ++ if ((p->xytile <= 0) || (p->xytile > p->xtile * p->ytile)) { ++ p->xytile = p->xtile * p->ytile; ++ } ++ ++ /* Say what happen: use mp_msg(...)? */ ++ if ( mp_msg_test(MSGT_VFILTER,MSGL_V) ) { ++ printf("vf_tile: tiling %d * %d, output every %d frames\n", ++ p->xtile, ++ p->ytile, ++ p->xytile); ++ printf("vf_tile: start pixel %d, delta pixel %d\n", ++ p->start, ++ p->delta); ++// printf("vf_tile: background 0x%x\n", ++// p->bkgSet); ++ } ++ return 1; ++} ++ ++const vf_info_t vf_info_tile = { ++ "Make a single image tiling x/y images", ++ "tile", ++ "Daniele Forghieri", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_tinterlace.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_tinterlace.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_tinterlace.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_tinterlace.c 2012-05-14 14:08:54.789349139 +0200 +@@ -0,0 +1,235 @@ ++/* ++ * Copyright (C) 2003 Michael Zucchi ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++struct vf_priv_s { ++ int mode; ++ int frame; ++ mp_image_t *dmpi; ++}; ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) ++{ ++ int ret = 0; ++ mp_image_t *dmpi; ++ ++ switch (vf->priv->mode) { ++ case 0: ++ dmpi = vf->priv->dmpi; ++ if (dmpi == NULL) { ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE, ++ mpi->width, mpi->height*2); ++ ++ vf->priv->dmpi = dmpi; ++ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0]*2, mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1]*2, mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2]*2, mpi->stride[2]); ++ } ++ } else { ++ vf->priv->dmpi = NULL; ++ ++ memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0]*2, mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1]*2, mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2]*2, mpi->stride[2]); ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ break; ++ case 1: ++ if (vf->priv->frame & 1) ++ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); ++ break; ++ case 2: ++ if ((vf->priv->frame & 1) == 0) ++ ret = vf_next_put_image(vf, mpi, MP_NOPTS_VALUE); ++ break; ++ case 3: ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->width, mpi->height*2); ++ /* fixme, just clear alternate lines */ ++ vf_mpi_clear(dmpi, 0, 0, dmpi->w, dmpi->h); ++ if ((vf->priv->frame & 1) == 0) { ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0]*2, mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1]*2, mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2]*2, mpi->stride[2]); ++ } ++ } else { ++ memcpy_pic(dmpi->planes[0]+dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, ++ dmpi->stride[0]*2, mpi->stride[0]); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ memcpy_pic(dmpi->planes[1]+dmpi->stride[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[1]*2, mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2]+dmpi->stride[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height, ++ dmpi->stride[2]*2, mpi->stride[2]); ++ } ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ break; ++ case 4: ++ // Interleave even lines (only) from Frame 'i' with odd ++ // lines (only) from Frame 'i+1', halving the Frame ++ // rate and preserving image height. ++ ++ dmpi = vf->priv->dmpi; ++ ++ // @@ Need help: Should I set dmpi->fields to indicate ++ // that the (new) frame will be interlaced!? E.g. ... ++ // dmpi->fields |= MP_IMGFIELD_INTERLACED; ++ // dmpi->fields |= MP_IMGFIELD_TOP_FIRST; ++ // etc. ++ ++ if (dmpi == NULL) { ++ dmpi = vf_get_image(vf->next, mpi->imgfmt, ++ MP_IMGTYPE_STATIC, MP_IMGFLAG_ACCEPT_STRIDE | ++ MP_IMGFLAG_PRESERVE, ++ mpi->width, mpi->height); ++ ++ vf->priv->dmpi = dmpi; ++ ++ my_memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1], mpi->planes[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2], mpi->planes[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ } else { ++ vf->priv->dmpi = NULL; ++ ++ my_memcpy_pic(dmpi->planes[0]+dmpi->stride[0], ++ mpi->planes[0]+mpi->stride[0], ++ mpi->w, mpi->h/2, ++ dmpi->stride[0]*2, mpi->stride[0]*2); ++ if (mpi->flags & MP_IMGFLAG_PLANAR) { ++ my_memcpy_pic(dmpi->planes[1]+dmpi->stride[1], ++ mpi->planes[1]+mpi->stride[1], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[1]*2, mpi->stride[1]*2); ++ my_memcpy_pic(dmpi->planes[2]+dmpi->stride[2], ++ mpi->planes[2]+mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height/2, ++ dmpi->stride[2]*2, mpi->stride[2]*2); ++ } ++ ret = vf_next_put_image(vf, dmpi, MP_NOPTS_VALUE); ++ } ++ break; ++ } ++ ++ vf->priv->frame++; ++ ++ return ret; ++} ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt) ++{ ++ /* FIXME - figure out which other formats work */ ++ switch (fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_IYUV: ++ case IMGFMT_I420: ++ return vf_next_query_format(vf, fmt); ++ } ++ return 0; ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt) ++{ ++ switch (vf->priv->mode) { ++ case 0: ++ case 3: ++ return vf_next_config(vf,width,height*2,d_width,d_height*2,flags,outfmt); ++ case 1: /* odd frames */ ++ case 2: /* even frames */ ++ case 4: /* alternate frame (height-preserving) interlacing */ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++ } ++ return 0; ++} ++ ++static void uninit(struct vf_instance *vf) ++{ ++ free(vf->priv); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args) ++{ ++ struct vf_priv_s *p; ++ vf->config = config; ++ vf->put_image = put_image; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->default_reqs = VFCAP_ACCEPT_STRIDE; ++ vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); ++ vf->priv->mode = 0; ++ if (args) ++ sscanf(args, "%d", &vf->priv->mode); ++ vf->priv->frame = 0; ++ return 1; ++} ++ ++const vf_info_t vf_info_tinterlace = { ++ "temporal field interlacing", ++ "tinterlace", ++ "Michael Zucchi", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_unsharp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_unsharp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_unsharp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_unsharp.c 2012-05-14 14:08:54.790349159 +0200 +@@ -0,0 +1,324 @@ ++/* ++ * Copyright (C) 2002 Remi Guyomarch ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#if HAVE_MALLOC_H ++#include ++#endif ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "libvo/fastmemcpy.h" ++#include "libavutil/common.h" ++ ++//===========================================================================// ++ ++#define MIN_MATRIX_SIZE 3 ++#define MAX_MATRIX_SIZE 63 ++ ++typedef struct FilterParam { ++ int msizeX, msizeY; ++ double amount; ++ uint32_t *SC[MAX_MATRIX_SIZE-1]; ++} FilterParam; ++ ++struct vf_priv_s { ++ FilterParam lumaParam; ++ FilterParam chromaParam; ++ unsigned int outfmt; ++}; ++ ++ ++//===========================================================================// ++ ++/* This code is based on : ++ ++An Efficient algorithm for Gaussian blur using finite-state machines ++Frederick M. Waltz and John W. V. Miller ++ ++SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII ++Originally published Boston, Nov 98 ++ ++*/ ++ ++static void unsharp( uint8_t *dst, uint8_t *src, int dstStride, int srcStride, int width, int height, FilterParam *fp ) { ++ ++ uint32_t **SC = fp->SC; ++ uint32_t SR[MAX_MATRIX_SIZE-1], Tmp1, Tmp2; ++ uint8_t* src2 = src; // avoid gcc warning ++ ++ int32_t res; ++ int x, y, z; ++ int amount = fp->amount * 65536.0; ++ int stepsX = fp->msizeX/2; ++ int stepsY = fp->msizeY/2; ++ int scalebits = (stepsX+stepsY)*2; ++ int32_t halfscale = 1 << ((stepsX+stepsY)*2-1); ++ ++ if( !fp->amount ) { ++ if( src == dst ) ++ return; ++ if( dstStride == srcStride ) ++ fast_memcpy( dst, src, srcStride*height ); ++ else ++ for( y=0; y=width ? src2[width-1] : src2[x]; ++ for( z=0; z=stepsX && y>=stepsY ) { ++ uint8_t* srx = src - stepsY*srcStride + x - stepsX; ++ uint8_t* dsx = dst - stepsY*dstStride + x - stepsX; ++ ++ res = (int32_t)*srx + ( ( ( (int32_t)*srx - (int32_t)((Tmp1+halfscale) >> scalebits) ) * amount ) >> 16 ); ++ *dsx = res>255 ? 255 : res<0 ? 0 : (uint8_t)res; ++ } ++ } ++ if( y >= 0 ) { ++ dst += dstStride; ++ src += srcStride; ++ } ++ } ++} ++ ++//===========================================================================// ++ ++static int config( struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt ) { ++ ++ int z, stepsX, stepsY; ++ FilterParam *fp; ++ const char *effect; ++ ++ // allocate buffers ++ ++ fp = &vf->priv->lumaParam; ++ effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen"; ++ mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s luma) \n", fp->msizeX, fp->msizeY, fp->amount, effect ); ++ memset( fp->SC, 0, sizeof( fp->SC ) ); ++ stepsX = fp->msizeX/2; ++ stepsY = fp->msizeY/2; ++ for( z=0; z<2*stepsY; z++ ) ++ fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX)); ++ ++ fp = &vf->priv->chromaParam; ++ effect = fp->amount == 0 ? "don't touch" : fp->amount < 0 ? "blur" : "sharpen"; ++ mp_msg( MSGT_VFILTER, MSGL_INFO, "unsharp: %dx%d:%0.2f (%s chroma)\n", fp->msizeX, fp->msizeY, fp->amount, effect ); ++ memset( fp->SC, 0, sizeof( fp->SC ) ); ++ stepsX = fp->msizeX/2; ++ stepsY = fp->msizeY/2; ++ for( z=0; z<2*stepsY; z++ ) ++ fp->SC[z] = av_malloc(sizeof(*(fp->SC[z])) * (width+2*stepsX)); ++ ++ return vf_next_config( vf, width, height, d_width, d_height, flags, outfmt ); ++} ++ ++//===========================================================================// ++ ++static void get_image( struct vf_instance *vf, mp_image_t *mpi ) { ++ if( mpi->flags & MP_IMGFLAG_PRESERVE ) ++ return; // don't change ++ if( mpi->imgfmt!=vf->priv->outfmt ) ++ return; // colorspace differ ++ ++ vf->dmpi = vf_get_image( vf->next, mpi->imgfmt, mpi->type, mpi->flags, mpi->w, mpi->h ); ++ mpi->planes[0] = vf->dmpi->planes[0]; ++ mpi->stride[0] = vf->dmpi->stride[0]; ++ mpi->width = vf->dmpi->width; ++ if( mpi->flags & MP_IMGFLAG_PLANAR ) { ++ mpi->planes[1] = vf->dmpi->planes[1]; ++ mpi->planes[2] = vf->dmpi->planes[2]; ++ mpi->stride[1] = vf->dmpi->stride[1]; ++ mpi->stride[2] = vf->dmpi->stride[2]; ++ } ++ mpi->flags |= MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image( struct vf_instance *vf, mp_image_t *mpi, double pts) { ++ mp_image_t *dmpi; ++ ++ if( !(mpi->flags & MP_IMGFLAG_DIRECT) ) ++ // no DR, so get a new image! hope we'll get DR buffer: ++ vf->dmpi = vf_get_image( vf->next,vf->priv->outfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->w, mpi->h); ++ dmpi= vf->dmpi; ++ ++ unsharp( dmpi->planes[0], mpi->planes[0], dmpi->stride[0], mpi->stride[0], mpi->w, mpi->h, &vf->priv->lumaParam ); ++ unsharp( dmpi->planes[1], mpi->planes[1], dmpi->stride[1], mpi->stride[1], mpi->w/2, mpi->h/2, &vf->priv->chromaParam ); ++ unsharp( dmpi->planes[2], mpi->planes[2], dmpi->stride[2], mpi->stride[2], mpi->w/2, mpi->h/2, &vf->priv->chromaParam ); ++ ++ vf_clone_mpi_attributes(dmpi, mpi); ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) ++ __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) ++ __asm__ volatile ("sfence\n\t"); ++#endif ++ ++ return vf_next_put_image( vf, dmpi, pts); ++} ++ ++static void uninit( struct vf_instance *vf ) { ++ unsigned int z; ++ FilterParam *fp; ++ ++ if( !vf->priv ) return; ++ ++ fp = &vf->priv->lumaParam; ++ for( z=0; zSC)/sizeof(fp->SC[0]); z++ ) { ++ av_free( fp->SC[z] ); ++ fp->SC[z] = NULL; ++ } ++ fp = &vf->priv->chromaParam; ++ for( z=0; zSC)/sizeof(fp->SC[0]); z++ ) { ++ av_free( fp->SC[z] ); ++ fp->SC[z] = NULL; ++ } ++ ++ free( vf->priv ); ++ vf->priv = NULL; ++} ++ ++//===========================================================================// ++ ++static int query_format( struct vf_instance *vf, unsigned int fmt ) { ++ switch(fmt) { ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ return vf_next_query_format( vf, vf->priv->outfmt ); ++ } ++ return 0; ++} ++ ++//===========================================================================// ++ ++static void parse( FilterParam *fp, char* args ) { ++ ++ // l7x5:0.8:c3x3:-0.2 ++ ++ char *z; ++ char *pos = args; ++ char *max = args + strlen(args); ++ ++ // parse matrix sizes ++ fp->msizeX = ( pos && pos+1msizeY = ( z && z+1msizeX; ++ ++ // min/max & odd ++ fp->msizeX = 1 | av_clip(fp->msizeX, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE); ++ fp->msizeY = 1 | av_clip(fp->msizeY, MIN_MATRIX_SIZE, MAX_MATRIX_SIZE); ++ ++ // parse amount ++ pos = strchr( pos+1, ':' ); ++ fp->amount = ( pos && pos+1config = config; ++ vf->put_image = put_image; ++ vf->get_image = get_image; ++ vf->query_format = query_format; ++ vf->uninit = uninit; ++ vf->priv = malloc( sizeof(struct vf_priv_s) ); ++ memset( vf->priv, 0, sizeof(struct vf_priv_s) ); ++ ++ if( args ) { ++ char *args2 = strchr( args, 'l' ); ++ if( args2 ) ++ parse( &vf->priv->lumaParam, args2 ); ++ else { ++ vf->priv->lumaParam.amount = ++ vf->priv->lumaParam.msizeX = ++ vf->priv->lumaParam.msizeY = 0; ++ } ++ ++ args2 = strchr( args, 'c' ); ++ if( args2 ) ++ parse( &vf->priv->chromaParam, args2 ); ++ else { ++ vf->priv->chromaParam.amount = ++ vf->priv->chromaParam.msizeX = ++ vf->priv->chromaParam.msizeY = 0; ++ } ++ ++ if( !vf->priv->lumaParam.msizeX && !vf->priv->chromaParam.msizeX ) ++ return 0; // nothing to do ++ } ++ ++ // check csp: ++ vf->priv->outfmt = vf_match_csp( &vf->next, fmt_list, IMGFMT_YV12 ); ++ if( !vf->priv->outfmt ) { ++ uninit( vf ); ++ return 0; // no csp match :( ++ } ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_unsharp = { ++ "unsharp mask & gaussian blur", ++ "unsharp", ++ "Remi Guyomarch", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_uspp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_uspp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_uspp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_uspp.c 2012-05-14 14:08:54.791349179 +0200 +@@ -0,0 +1,385 @@ ++/* ++ * Copyright (C) 2005 Michael Niedermayer ++ * ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++ ++#include "mp_msg.h" ++#include "cpudetect.h" ++ ++#include "libavcodec/avcodec.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++#include "vd_ffmpeg.h" ++#include "libvo/fastmemcpy.h" ++ ++#define XMIN(a,b) ((a) < (b) ? (a) : (b)) ++ ++#define BLOCK 16 ++ ++//===========================================================================// ++static const uint8_t __attribute__((aligned(8))) dither[8][8]={ ++{ 0*4, 48*4, 12*4, 60*4, 3*4, 51*4, 15*4, 63*4, }, ++{ 32*4, 16*4, 44*4, 28*4, 35*4, 19*4, 47*4, 31*4, }, ++{ 8*4, 56*4, 4*4, 52*4, 11*4, 59*4, 7*4, 55*4, }, ++{ 40*4, 24*4, 36*4, 20*4, 43*4, 27*4, 39*4, 23*4, }, ++{ 2*4, 50*4, 14*4, 62*4, 1*4, 49*4, 13*4, 61*4, }, ++{ 34*4, 18*4, 46*4, 30*4, 33*4, 17*4, 45*4, 29*4, }, ++{ 10*4, 58*4, 6*4, 54*4, 9*4, 57*4, 5*4, 53*4, }, ++{ 42*4, 26*4, 38*4, 22*4, 41*4, 25*4, 37*4, 21*4, }, ++}; ++ ++static const uint8_t offset[511][2]= { ++{ 0, 0}, ++{ 0, 0}, { 8, 8}, ++{ 0, 0}, { 4, 4}, {12, 8}, { 8,12}, ++{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14}, ++ ++{ 0, 0}, {10, 2}, { 4, 4}, {14, 6}, { 8, 8}, { 2,10}, {12,12}, { 6,14}, ++{ 5, 1}, {15, 3}, { 9, 5}, { 3, 7}, {13, 9}, { 7,11}, { 1,13}, {11,15}, ++ ++{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, ++{ 2, 2}, {10, 2}, { 2,10}, {10,10}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, ++{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, ++{ 6, 6}, {14, 6}, { 6,14}, {14,14}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, ++ ++{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, ++{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, ++{ 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, ++{ 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, ++{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, ++{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, ++{ 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, ++{ 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, ++ ++{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, ++{ 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, ++{ 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, ++{ 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, ++{ 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, ++{ 2, 4}, {10, 4}, { 2,12}, {10,12}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, ++{ 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, ++{ 3, 5}, {11, 5}, { 3,13}, {11,13}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, ++{ 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, ++{ 4, 4}, {12, 4}, { 4,12}, {12,12}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, ++{ 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, ++{ 5, 5}, {13, 5}, { 5,13}, {13,13}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, ++{ 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, ++{ 6, 4}, {14, 4}, { 6,12}, {14,12}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, ++{ 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, ++{ 7, 5}, {15, 5}, { 7,13}, {15,13}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, ++ ++{ 0, 0}, { 8, 0}, { 0, 8}, { 8, 8}, { 4, 4}, {12, 4}, { 4,12}, {12,12}, { 0, 4}, { 8, 4}, { 0,12}, { 8,12}, { 4, 0}, {12, 0}, { 4, 8}, {12, 8}, { 2, 2}, {10, 2}, { 2,10}, {10,10}, { 6, 6}, {14, 6}, { 6,14}, {14,14}, { 2, 6}, {10, 6}, { 2,14}, {10,14}, { 6, 2}, {14, 2}, { 6,10}, {14,10}, { 0, 2}, { 8, 2}, { 0,10}, { 8,10}, { 4, 6}, {12, 6}, { 4,14}, {12,14}, { 0, 6}, { 8, 6}, { 0,14}, { 8,14}, { 4, 2}, {12, 2}, { 4,10}, {12,10}, { 2, 0}, {10, 0}, { 2, 8}, {10, 8}, { 6, 4}, {14, 4}, { 6,12}, {14,12}, { 2, 4}, {10, 4}, { 2,12}, {10,12}, { 6, 0}, {14, 0}, { 6, 8}, {14, 8}, { 1, 1}, { 9, 1}, { 1, 9}, { 9, 9}, { 5, 5}, {13, 5}, { 5,13}, {13,13}, { 1, 5}, { 9, 5}, { 1,13}, { 9,13}, { 5, 1}, {13, 1}, { 5, 9}, {13, 9}, { 3, 3}, {11, 3}, { 3,11}, {11,11}, { 7, 7}, {15, 7}, { 7,15}, {15,15}, { 3, 7}, {11, 7}, { 3,15}, {11,15}, { 7, 3}, {15, 3}, { 7,11}, {15,11}, { 1, 3}, { 9, 3}, { 1,11}, { 9,11}, { 5, 7}, {13, 7}, { 5,15}, {13,15}, { 1, 7}, { 9, 7}, { 1,15}, { 9,15}, { 5, 3}, {13, 3}, { 5,11}, {13,11}, { 3, 1}, {11, 1}, { 3, 9}, {11, 9}, { 7, 5}, {15, 5}, { 7,13}, {15,13}, { 3, 5}, {11, 5}, { 3,13}, {11,13}, { 7, 1}, {15, 1}, { 7, 9}, {15, 9}, { 0, 1}, { 8, 1}, { 0, 9}, { 8, 9}, { 4, 5}, {12, 5}, { 4,13}, {12,13}, { 0, 5}, { 8, 5}, { 0,13}, { 8,13}, { 4, 1}, {12, 1}, { 4, 9}, {12, 9}, { 2, 3}, {10, 3}, { 2,11}, {10,11}, { 6, 7}, {14, 7}, { 6,15}, {14,15}, { 2, 7}, {10, 7}, { 2,15}, {10,15}, { 6, 3}, {14, 3}, { 6,11}, {14,11}, { 0, 3}, { 8, 3}, { 0,11}, { 8,11}, { 4, 7}, {12, 7}, { 4,15}, {12,15}, { 0, 7}, { 8, 7}, { 0,15}, { 8,15}, { 4, 3}, {12, 3}, { 4,11}, {12,11}, { 2, 1}, {10, 1}, { 2, 9}, {10, 9}, { 6, 5}, {14, 5}, { 6,13}, {14,13}, { 2, 5}, {10, 5}, { 2,13}, {10,13}, { 6, 1}, {14, 1}, { 6, 9}, {14, 9}, { 1, 0}, { 9, 0}, { 1, 8}, { 9, 8}, { 5, 4}, {13, 4}, { 5,12}, {13,12}, { 1, 4}, { 9, 4}, { 1,12}, { 9,12}, { 5, 0}, {13, 0}, { 5, 8}, {13, 8}, { 3, 2}, {11, 2}, { 3,10}, {11,10}, { 7, 6}, {15, 6}, { 7,14}, {15,14}, { 3, 6}, {11, 6}, { 3,14}, {11,14}, { 7, 2}, {15, 2}, { 7,10}, {15,10}, { 1, 2}, { 9, 2}, { 1,10}, { 9,10}, { 5, 6}, {13, 6}, { 5,14}, {13,14}, { 1, 6}, { 9, 6}, { 1,14}, { 9,14}, { 5, 2}, {13, 2}, { 5,10}, {13,10}, { 3, 0}, {11, 0}, { 3, 8}, {11, 8}, { 7, 4}, {15, 4}, { 7,12}, {15,12}, { 3, 4}, {11, 4}, { 3,12}, {11,12}, { 7, 0}, {15, 0}, { 7, 8}, {15, 8}, ++}; ++ ++struct vf_priv_s { ++ int log2_count; ++ int qp; ++ int mode; ++ int mpeg2; ++ int temp_stride[3]; ++ uint8_t *src[3]; ++ int16_t *temp[3]; ++ int outbuf_size; ++ uint8_t *outbuf; ++ AVCodecContext *avctx_enc[BLOCK*BLOCK]; ++ AVFrame *frame; ++ AVFrame *frame_dec; ++}; ++ ++static void store_slice_c(uint8_t *dst, int16_t *src, int dst_stride, int src_stride, int width, int height, int log2_scale){ ++ int y, x; ++ ++#define STORE(pos) \ ++ temp= ((src[x + y*src_stride + pos]<>8;\ ++ if(temp & 0x100) temp= ~(temp>>31);\ ++ dst[x + y*dst_stride + pos]= temp; ++ ++ for(y=0; ylog2_count; ++ ++ for(i=0; i<3; i++){ ++ int is_chroma= !!i; ++ int w= width >>is_chroma; ++ int h= height>>is_chroma; ++ int stride= p->temp_stride[i]; ++ int block= BLOCK>>is_chroma; ++ ++ if (!src[i] || !dst[i]) ++ continue; // HACK avoid crash for Y8 colourspace ++ for(y=0; ysrc[i] + index, src[i] + y*src_stride[i], w); ++ for(x=0; xsrc[i][index - x - 1]= p->src[i][index + x ]; ++ p->src[i][index + w + x ]= p->src[i][index + w - x - 1]; ++ } ++ } ++ for(y=0; ysrc[i] + ( block-1-y)*stride, p->src[i] + ( y+block )*stride, stride); ++ fast_memcpy(p->src[i] + (h+block +y)*stride, p->src[i] + (h-y+block-1)*stride, stride); ++ } ++ ++ p->frame->linesize[i]= stride; ++ memset(p->temp[i], 0, (h+2*block)*stride*sizeof(int16_t)); ++ } ++ ++ if(p->qp) ++ p->frame->quality= p->qp * FF_QP2LAMBDA; ++ else ++ p->frame->quality= norm_qscale(qp_store[0], p->mpeg2) * FF_QP2LAMBDA; ++// init per MB qscale stuff FIXME ++ ++ for(i=0; iframe->data[0]= p->src[0] + x1 + y1 * p->frame->linesize[0]; ++ p->frame->data[1]= p->src[1] + x1/2 + y1/2 * p->frame->linesize[1]; ++ p->frame->data[2]= p->src[2] + x1/2 + y1/2 * p->frame->linesize[2]; ++ ++ avcodec_encode_video(p->avctx_enc[i], p->outbuf, p->outbuf_size, p->frame); ++ p->frame_dec = p->avctx_enc[i]->coded_frame; ++ ++ offset= (BLOCK-x1) + (BLOCK-y1)*p->frame_dec->linesize[0]; ++ //FIXME optimize ++ for(y=0; ytemp[0][ x + y*p->temp_stride[0] ] += p->frame_dec->data[0][ x + y*p->frame_dec->linesize[0] + offset ]; ++ } ++ } ++ offset= (BLOCK/2-x1/2) + (BLOCK/2-y1/2)*p->frame_dec->linesize[1]; ++ for(y=0; ytemp[1][ x + y*p->temp_stride[1] ] += p->frame_dec->data[1][ x + y*p->frame_dec->linesize[1] + offset ]; ++ p->temp[2][ x + y*p->temp_stride[2] ] += p->frame_dec->data[2][ x + y*p->frame_dec->linesize[2] + offset ]; ++ } ++ } ++ } ++ ++ for(j=0; j<3; j++){ ++ int is_chroma= !!j; ++ store_slice_c(dst[j], p->temp[j], dst_stride[j], p->temp_stride[j], width>>is_chroma, height>>is_chroma, 8-p->log2_count); ++ } ++} ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ int i; ++ AVCodec *enc= avcodec_find_encoder(CODEC_ID_SNOW); ++ ++ for(i=0; i<3; i++){ ++ int is_chroma= !!i; ++ int w= ((width + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma; ++ int h= ((height + 4*BLOCK-1) & (~(2*BLOCK-1)))>>is_chroma; ++ ++ vf->priv->temp_stride[i]= w; ++ vf->priv->temp[i]= malloc(vf->priv->temp_stride[i]*h*sizeof(int16_t)); ++ vf->priv->src [i]= malloc(vf->priv->temp_stride[i]*h*sizeof(uint8_t)); ++ } ++ for(i=0; i< (1<priv->log2_count); i++){ ++ AVCodecContext *avctx_enc; ++ ++ avctx_enc= ++ vf->priv->avctx_enc[i]= avcodec_alloc_context(); ++ avctx_enc->width = width + BLOCK; ++ avctx_enc->height = height + BLOCK; ++ avctx_enc->time_base= (AVRational){1,25}; // meaningless ++ avctx_enc->gop_size = 300; ++ avctx_enc->max_b_frames= 0; ++ avctx_enc->pix_fmt = PIX_FMT_YUV420P; ++ avctx_enc->flags = CODEC_FLAG_QSCALE | CODEC_FLAG_LOW_DELAY; ++ avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; ++ avctx_enc->global_quality= 123; ++ avcodec_open(avctx_enc, enc); ++ assert(avctx_enc->codec); ++ } ++ vf->priv->frame= avcodec_alloc_frame(); ++ vf->priv->frame_dec= avcodec_alloc_frame(); ++ ++ vf->priv->outbuf_size= (width + BLOCK)*(height + BLOCK)*10; ++ vf->priv->outbuf= malloc(vf->priv->outbuf_size); ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); ++} ++ ++static void get_image(struct vf_instance *vf, mp_image_t *mpi){ ++ if(mpi->flags&MP_IMGFLAG_PRESERVE) return; // don't change ++ // ok, we can do pp in-place (or pp disabled): ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ mpi->type, mpi->flags | MP_IMGFLAG_READABLE, mpi->width, mpi->height); ++ mpi->planes[0]=vf->dmpi->planes[0]; ++ mpi->stride[0]=vf->dmpi->stride[0]; ++ mpi->width=vf->dmpi->width; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ mpi->planes[1]=vf->dmpi->planes[1]; ++ mpi->planes[2]=vf->dmpi->planes[2]; ++ mpi->stride[1]=vf->dmpi->stride[1]; ++ mpi->stride[2]=vf->dmpi->stride[2]; ++ } ++ mpi->flags|=MP_IMGFLAG_DIRECT; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // no DR, so get a new image! hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, ++ MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_PREFER_ALIGNED_STRIDE, ++ mpi->width,mpi->height); ++ vf_clone_mpi_attributes(dmpi, mpi); ++ }else{ ++ dmpi=vf->dmpi; ++ } ++ ++ vf->priv->mpeg2= mpi->qscale_type; ++ if(vf->priv->log2_count || !(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ if(mpi->qscale || vf->priv->qp){ ++ filter(vf->priv, dmpi->planes, mpi->planes, dmpi->stride, mpi->stride, mpi->w, mpi->h, mpi->qscale, mpi->qstride); ++ }else{ ++ memcpy_pic(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h, dmpi->stride[0], mpi->stride[0]); ++ memcpy_pic(dmpi->planes[1], mpi->planes[1], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[1], mpi->stride[1]); ++ memcpy_pic(dmpi->planes[2], mpi->planes[2], mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, dmpi->stride[2], mpi->stride[2]); ++ } ++ } ++ ++#if HAVE_MMX ++ if(gCpuCaps.hasMMX) __asm__ volatile ("emms\n\t"); ++#endif ++#if HAVE_MMX2 ++ if(gCpuCaps.hasMMX2) __asm__ volatile ("sfence\n\t"); ++#endif ++ ++ return vf_next_put_image(vf,dmpi, pts); ++} ++ ++static void uninit(struct vf_instance *vf){ ++ int i; ++ if(!vf->priv) return; ++ ++ for(i=0; i<3; i++){ ++ free(vf->priv->temp[i]); ++ vf->priv->temp[i]= NULL; ++ free(vf->priv->src[i]); ++ vf->priv->src[i]= NULL; ++ } ++ for(i=0; ipriv->avctx_enc[i]); ++ } ++ ++ free(vf->priv); ++ vf->priv=NULL; ++} ++ ++//===========================================================================// ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ case IMGFMT_Y800: ++ case IMGFMT_Y8: ++ return vf_next_query_format(vf,fmt); ++ } ++ return 0; ++} ++ ++static int control(struct vf_instance *vf, int request, void* data){ ++ switch(request){ ++ case VFCTRL_QUERY_MAX_PP_LEVEL: ++ return 8; ++ case VFCTRL_SET_PP_LEVEL: ++ vf->priv->log2_count= *((unsigned int*)data); ++ //FIXME we have to realloc a few things here ++ return CONTROL_TRUE; ++ } ++ return vf_next_control(vf,request,data); ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ ++ int log2c=-1; ++ ++ vf->config=config; ++ vf->put_image=put_image; ++ vf->get_image=get_image; ++ vf->query_format=query_format; ++ vf->uninit=uninit; ++ vf->control= control; ++ vf->priv=malloc(sizeof(struct vf_priv_s)); ++ memset(vf->priv, 0, sizeof(struct vf_priv_s)); ++ ++ init_avcodec(); ++ ++ vf->priv->log2_count= 4; ++ ++ if (args) sscanf(args, "%d:%d:%d", &log2c, &vf->priv->qp, &vf->priv->mode); ++ ++ if( log2c >=0 && log2c <=8 ) ++ vf->priv->log2_count = log2c; ++ ++ if(vf->priv->qp < 0) ++ vf->priv->qp = 0; ++ ++// #if HAVE_MMX ++// if(gCpuCaps.hasMMX){ ++// store_slice= store_slice_mmx; ++// } ++// #endif ++ ++ return 1; ++} ++ ++const vf_info_t vf_info_uspp = { ++ "ultra simple/slow postprocess", ++ "uspp", ++ "Michael Niedermayer", ++ "", ++ vf_open, ++ NULL ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_yuvcsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_yuvcsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_yuvcsp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_yuvcsp.c 2012-05-14 14:08:54.792349199 +0200 +@@ -0,0 +1,120 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++struct vf_priv_s { ++ int csp; ++}; ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); ++} ++ ++static inline int clamp_y(int x){ ++ return (x > 235) ? 235 : (x < 16) ? 16 : x; ++} ++ ++static inline int clamp_c(int x){ ++ return (x > 240) ? 240 : (x < 16) ? 16 : x; ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ int i,j; ++ uint8_t *y_in, *cb_in, *cr_in; ++ uint8_t *y_out, *cb_out, *cr_out; ++ ++ vf->dmpi=vf_get_image(vf->next,mpi->imgfmt, ++ MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, ++ mpi->width, mpi->height); ++ ++ y_in = mpi->planes[0]; ++ cb_in = mpi->planes[1]; ++ cr_in = mpi->planes[2]; ++ ++ y_out = vf->dmpi->planes[0]; ++ cb_out = vf->dmpi->planes[1]; ++ cr_out = vf->dmpi->planes[2]; ++ ++ for (i = 0; i < mpi->height; i++) ++ for (j = 0; j < mpi->width; j++) ++ y_out[i*vf->dmpi->stride[0]+j] = clamp_y(y_in[i*mpi->stride[0]+j]); ++ ++ for (i = 0; i < mpi->chroma_height; i++) ++ for (j = 0; j < mpi->chroma_width; j++) ++ { ++ cb_out[i*vf->dmpi->stride[1]+j] = clamp_c(cb_in[i*mpi->stride[1]+j]); ++ cr_out[i*vf->dmpi->stride[2]+j] = clamp_c(cr_in[i*mpi->stride[2]+j]); ++ } ++ ++ return vf_next_put_image(vf,vf->dmpi, pts); ++} ++ ++//===========================================================================// ++ ++/* ++static void uninit(struct vf_instance *vf){ ++ free(vf->priv); ++} ++*/ ++ ++static int query_format(struct vf_instance *vf, unsigned int fmt){ ++ switch(fmt){ ++ case IMGFMT_YV12: ++ case IMGFMT_I420: ++ case IMGFMT_IYUV: ++ return 1; ++ } ++ return 0; ++} ++ ++static int vf_open(vf_instance_t *vf, char *args){ ++ vf->config=config; ++ vf->put_image=put_image; ++// vf->uninit=uninit; ++ vf->query_format=query_format; ++// vf->priv=calloc(1, sizeof(struct vf_priv_s)); ++// if (args) ++// vf->priv->csp = atoi(args); ++ return 1; ++} ++ ++const vf_info_t vf_info_yuvcsp = { ++ "yuv colorspace converter", ++ "yuvcsp", ++ "Alex Beregszaszi", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_yvu9.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_yvu9.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/libmpcodecs/vf_yvu9.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/libmpcodecs/vf_yvu9.c 2012-05-14 14:08:54.793349219 +0200 +@@ -0,0 +1,105 @@ ++/* ++ * This file is part of MPlayer. ++ * ++ * MPlayer 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. ++ * ++ * MPlayer 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 MPlayer; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "config.h" ++#include "mp_msg.h" ++#include "help_mp.h" ++ ++#include "img_format.h" ++#include "mp_image.h" ++#include "vf.h" ++ ++#include "libvo/fastmemcpy.h" ++ ++//===========================================================================// ++ ++static int config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int flags, unsigned int outfmt){ ++ ++ if(vf_next_query_format(vf,IMGFMT_YV12)<=0){ ++ mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_WarnNextFilterDoesntSupport, "YVU9"); ++ return 0; ++ } ++ ++ return vf_next_config(vf,width,height,d_width,d_height,flags,IMGFMT_YV12); ++} ++ ++static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ ++ mp_image_t *dmpi; ++ int y,w,h; ++ ++ // hope we'll get DR buffer: ++ dmpi=vf_get_image(vf->next,IMGFMT_YV12, ++ MP_IMGTYPE_TEMP, 0/*MP_IMGFLAG_ACCEPT_STRIDE*/, ++ mpi->w, mpi->h); ++ ++ for(y=0;yh;y++) ++ fast_memcpy(dmpi->planes[0]+dmpi->stride[0]*y, ++ mpi->planes[0]+mpi->stride[0]*y, ++ mpi->w); ++ ++ w=mpi->w/4; h=mpi->h/2; ++ for(y=0;yplanes[1]+mpi->stride[1]*(y>>1); ++ unsigned char* d=dmpi->planes[1]+dmpi->stride[1]*y; ++ int x; ++ for(x=0;xplanes[2]+mpi->stride[2]*(y>>1); ++ unsigned char* d=dmpi->planes[2]+dmpi->stride[2]*y; ++ int x; ++ for(x=0;xconfig=config; ++ vf->put_image=put_image; ++ vf->query_format=query_format; ++ return 1; ++} ++ ++const vf_info_t vf_info_yvu9 = { ++ "fast YVU9->YV12 conversion", ++ "yvu9", ++ "alex", ++ "", ++ vf_open, ++ NULL ++}; ++ ++//===========================================================================// +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/Makefile 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/Makefile 2012-05-14 14:08:54.675346844 +0200 +@@ -1,35 +1,75 @@ + include $(SUBDIR)../config.mak + + NAME = avfilter +-FFLIBS = avcore avutil +-FFLIBS-$(CONFIG_SCALE_FILTER) += swscale ++FFLIBS = avutil + +-HEADERS = avfilter.h avfiltergraph.h ++FFLIBS-$(CONFIG_ACONVERT_FILTER) += avcodec ++FFLIBS-$(CONFIG_AMOVIE_FILTER) += avformat avcodec ++FFLIBS-$(CONFIG_ARESAMPLE_FILTER) += avcodec ++FFLIBS-$(CONFIG_MOVIE_FILTER) += avformat avcodec ++FFLIBS-$(CONFIG_PAN_FILTER) += swresample ++FFLIBS-$(CONFIG_SCALE_FILTER) += swscale ++FFLIBS-$(CONFIG_MP_FILTER) += avcodec ++ ++HEADERS = avcodec.h avfilter.h avfiltergraph.h buffersink.h version.h vsrc_buffer.h + + OBJS = allfilters.o \ + avfilter.o \ + avfiltergraph.o \ + defaults.o \ ++ drawutils.o \ + formats.o \ ++ graphdump.o \ + graphparser.o \ ++ transform.o \ ++ vsrc_buffer.o + +-OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o ++OBJS-$(CONFIG_AVCODEC) += avcodec.o + ++OBJS-$(CONFIG_ACONVERT_FILTER) += af_aconvert.o ++OBJS-$(CONFIG_AFORMAT_FILTER) += af_aformat.o ++OBJS-$(CONFIG_AMERGE_FILTER) += af_amerge.o ++OBJS-$(CONFIG_ANULL_FILTER) += af_anull.o ++OBJS-$(CONFIG_ARESAMPLE_FILTER) += af_aresample.o ++OBJS-$(CONFIG_ASHOWINFO_FILTER) += af_ashowinfo.o ++OBJS-$(CONFIG_ASPLIT_FILTER) += af_asplit.o ++OBJS-$(CONFIG_ASTREAMSYNC_FILTER) += af_astreamsync.o ++OBJS-$(CONFIG_EARWAX_FILTER) += af_earwax.o ++OBJS-$(CONFIG_PAN_FILTER) += af_pan.o ++OBJS-$(CONFIG_SILENCEDETECT_FILTER) += af_silencedetect.o ++OBJS-$(CONFIG_VOLUME_FILTER) += af_volume.o ++ ++OBJS-$(CONFIG_ABUFFER_FILTER) += asrc_abuffer.o ++OBJS-$(CONFIG_AEVALSRC_FILTER) += asrc_aevalsrc.o ++OBJS-$(CONFIG_AMOVIE_FILTER) += src_movie.o + OBJS-$(CONFIG_ANULLSRC_FILTER) += asrc_anullsrc.o + ++OBJS-$(CONFIG_ABUFFERSINK_FILTER) += sink_buffer.o + OBJS-$(CONFIG_ANULLSINK_FILTER) += asink_anullsink.o + ++OBJS-$(CONFIG_ASS_FILTER) += vf_ass.o + OBJS-$(CONFIG_BLACKFRAME_FILTER) += vf_blackframe.o ++OBJS-$(CONFIG_BOXBLUR_FILTER) += vf_boxblur.o + OBJS-$(CONFIG_COPY_FILTER) += vf_copy.o + OBJS-$(CONFIG_CROP_FILTER) += vf_crop.o + OBJS-$(CONFIG_CROPDETECT_FILTER) += vf_cropdetect.o ++OBJS-$(CONFIG_DELOGO_FILTER) += vf_delogo.o ++OBJS-$(CONFIG_DESHAKE_FILTER) += vf_deshake.o + OBJS-$(CONFIG_DRAWBOX_FILTER) += vf_drawbox.o ++OBJS-$(CONFIG_DRAWTEXT_FILTER) += vf_drawtext.o ++OBJS-$(CONFIG_FADE_FILTER) += vf_fade.o ++OBJS-$(CONFIG_FIELDORDER_FILTER) += vf_fieldorder.o + OBJS-$(CONFIG_FIFO_FILTER) += vf_fifo.o + OBJS-$(CONFIG_FORMAT_FILTER) += vf_format.o + OBJS-$(CONFIG_FREI0R_FILTER) += vf_frei0r.o + OBJS-$(CONFIG_GRADFUN_FILTER) += vf_gradfun.o + OBJS-$(CONFIG_HFLIP_FILTER) += vf_hflip.o + OBJS-$(CONFIG_HQDN3D_FILTER) += vf_hqdn3d.o ++OBJS-$(CONFIG_LUT_FILTER) += vf_lut.o ++OBJS-$(CONFIG_LUTRGB_FILTER) += vf_lut.o ++OBJS-$(CONFIG_LUTYUV_FILTER) += vf_lut.o ++OBJS-$(CONFIG_MP_FILTER) += vf_mp.o ++OBJS-$(CONFIG_NEGATE_FILTER) += vf_lut.o + OBJS-$(CONFIG_NOFORMAT_FILTER) += vf_format.o + OBJS-$(CONFIG_NULL_FILTER) += vf_null.o + OBJS-$(CONFIG_OCV_FILTER) += vf_libopencv.o +@@ -37,25 +77,95 @@ + OBJS-$(CONFIG_PAD_FILTER) += vf_pad.o + OBJS-$(CONFIG_PIXDESCTEST_FILTER) += vf_pixdesctest.o + OBJS-$(CONFIG_SCALE_FILTER) += vf_scale.o ++OBJS-$(CONFIG_SELECT_FILTER) += vf_select.o + OBJS-$(CONFIG_SETDAR_FILTER) += vf_aspect.o + OBJS-$(CONFIG_SETPTS_FILTER) += vf_setpts.o + OBJS-$(CONFIG_SETSAR_FILTER) += vf_aspect.o + OBJS-$(CONFIG_SETTB_FILTER) += vf_settb.o ++OBJS-$(CONFIG_SHOWINFO_FILTER) += vf_showinfo.o + OBJS-$(CONFIG_SLICIFY_FILTER) += vf_slicify.o ++OBJS-$(CONFIG_SPLIT_FILTER) += vf_split.o ++OBJS-$(CONFIG_SWAPUV_FILTER) += vf_swapuv.o ++OBJS-$(CONFIG_THUMBNAIL_FILTER) += vf_thumbnail.o ++OBJS-$(CONFIG_TINTERLACE_FILTER) += vf_tinterlace.o + OBJS-$(CONFIG_TRANSPOSE_FILTER) += vf_transpose.o + OBJS-$(CONFIG_UNSHARP_FILTER) += vf_unsharp.o + OBJS-$(CONFIG_VFLIP_FILTER) += vf_vflip.o + OBJS-$(CONFIG_YADIF_FILTER) += vf_yadif.o + +-OBJS-$(CONFIG_BUFFER_FILTER) += vsrc_buffer.o +-OBJS-$(CONFIG_COLOR_FILTER) += vf_pad.o ++OBJS-$(CONFIG_CELLAUTO_FILTER) += vsrc_cellauto.o ++OBJS-$(CONFIG_COLOR_FILTER) += vsrc_color.o + OBJS-$(CONFIG_FREI0R_SRC_FILTER) += vf_frei0r.o +-OBJS-$(CONFIG_NULLSRC_FILTER) += vsrc_nullsrc.o ++OBJS-$(CONFIG_LIFE_FILTER) += vsrc_life.o ++OBJS-$(CONFIG_MANDELBROT_FILTER) += vsrc_mandelbrot.o ++OBJS-$(CONFIG_MOVIE_FILTER) += src_movie.o ++OBJS-$(CONFIG_MPTESTSRC_FILTER) += vsrc_mptestsrc.o ++OBJS-$(CONFIG_NULLSRC_FILTER) += vsrc_testsrc.o ++OBJS-$(CONFIG_RGBTESTSRC_FILTER) += vsrc_testsrc.o ++OBJS-$(CONFIG_TESTSRC_FILTER) += vsrc_testsrc.o + ++OBJS-$(CONFIG_BUFFERSINK_FILTER) += sink_buffer.o + OBJS-$(CONFIG_NULLSINK_FILTER) += vsink_nullsink.o + +--include $(SUBDIR)$(ARCH)/Makefile ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/mp_image.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/img_format.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_2xsai.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_decimate.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_denoise3d.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_detc.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dint.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_divtc.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_down3dright.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_dsize.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq2.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_eq.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_field.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fil.o ++#OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_filmdint.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fixpts.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_framestep.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_fspp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_geq.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_harddup.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_hqdn3d.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_hue.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_il.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ilpack.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ivtc.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_kerndeint.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mcdeint.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_mirror.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_noise.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_ow.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_palette.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_perspective.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_phase.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pp7.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_pullup.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_qp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_rectangle.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_remove_logo.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_rotate.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_sab.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_screenshot.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_smartblur.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softpulldown.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_softskip.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_spp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_stereo3d.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_swapuv.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_telecine.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_tile.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_tinterlace.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_unsharp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_uspp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_yuvcsp.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/vf_yvu9.o ++OBJS-$(CONFIG_MP_FILTER) += libmpcodecs/pullup.o ++ ++ ++DIRS = x86 libmpcodecs + +-DIRS = x86 ++TESTPROGS = formats + +-include $(SUBDIR)../subdir.mak ++TOOLS = graph2dot lavfi-showfiltfmts +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/sink_buffer.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/sink_buffer.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/sink_buffer.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/sink_buffer.c 2012-05-14 14:08:54.794349239 +0200 +@@ -0,0 +1,298 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * buffer video sink ++ */ ++ ++#include "libavutil/fifo.h" ++#include "avfilter.h" ++#include "buffersink.h" ++#include "internal.h" ++ ++AVBufferSinkParams *av_buffersink_params_alloc(void) ++{ ++ static const int pixel_fmts[] = { -1 }; ++ AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams)); ++ if (!params) ++ return NULL; ++ ++ params->pixel_fmts = pixel_fmts; ++ return params; ++} ++ ++AVABufferSinkParams *av_abuffersink_params_alloc(void) ++{ ++ static const int sample_fmts[] = { -1 }; ++ static const int packing_fmts[] = { -1 }; ++ static const int64_t channel_layouts[] = { -1 }; ++ AVABufferSinkParams *params = av_malloc(sizeof(AVABufferSinkParams)); ++ ++ if (!params) ++ return NULL; ++ ++ params->sample_fmts = sample_fmts; ++ params->channel_layouts = channel_layouts; ++ params->packing_fmts = packing_fmts; ++ return params; ++} ++ ++typedef struct { ++ AVFifoBuffer *fifo; ///< FIFO buffer of video frame references ++ ++ /* only used for video */ ++ enum PixelFormat *pixel_fmts; ///< list of accepted pixel formats, must be terminated with -1 ++ ++ /* only used for audio */ ++ enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE ++ int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1 ++ int *packing_fmts; ///< list of accepted packing formats, terminated by -1 ++} BufferSinkContext; ++ ++#define FIFO_INIT_SIZE 8 ++ ++static av_cold int common_init(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ ++ buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *)); ++ if (!buf->fifo) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n"); ++ return AVERROR(ENOMEM); ++ } ++ return 0; ++} ++ ++static av_cold void common_uninit(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ AVFilterBufferRef *picref; ++ ++ if (buf->fifo) { ++ while (av_fifo_size(buf->fifo) >= sizeof(AVFilterBufferRef *)) { ++ av_fifo_generic_read(buf->fifo, &picref, sizeof(picref), NULL); ++ avfilter_unref_buffer(picref); ++ } ++ av_fifo_free(buf->fifo); ++ buf->fifo = NULL; ++ } ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ BufferSinkContext *buf = inlink->dst->priv; ++ ++ if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) { ++ /* realloc fifo size */ ++ if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Cannot buffer more frames. Consume some available frames " ++ "before adding new ones.\n"); ++ return; ++ } ++ } ++ ++ /* cache frame */ ++ av_fifo_generic_write(buf->fifo, ++ &inlink->cur_buf, sizeof(AVFilterBufferRef *), NULL); ++} ++ ++int av_buffersink_get_buffer_ref(AVFilterContext *ctx, ++ AVFilterBufferRef **bufref, int flags) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ int ret; ++ *bufref = NULL; ++ ++ /* no picref available, fetch it from the filterchain */ ++ if (!av_fifo_size(buf->fifo)) { ++ if ((ret = avfilter_request_frame(inlink)) < 0) ++ return ret; ++ } ++ ++ if (!av_fifo_size(buf->fifo)) ++ return AVERROR(EINVAL); ++ ++ if (flags & AV_BUFFERSINK_FLAG_PEEK) ++ *bufref = *((AVFilterBufferRef **)av_fifo_peek2(buf->fifo, 0)); ++ else ++ av_fifo_generic_read(buf->fifo, bufref, sizeof(*bufref), NULL); ++ ++ return 0; ++} ++ ++int av_buffersink_poll_frame(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ ++ return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + avfilter_poll_frame(inlink); ++} ++ ++#if FF_API_OLD_VSINK_API ++int av_vsink_buffer_get_video_buffer_ref(AVFilterContext *ctx, ++ AVFilterBufferRef **picref, int flags) ++{ ++ return av_buffersink_get_buffer_ref(ctx, picref, flags); ++} ++#endif ++ ++#if CONFIG_BUFFERSINK_FILTER ++ ++static av_cold int vsink_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ av_unused AVBufferSinkParams *params; ++ ++ if (!opaque) { ++ av_log(ctx, AV_LOG_ERROR, ++ "No opaque field provided\n"); ++ return AVERROR(EINVAL); ++ } else { ++#if FF_API_OLD_VSINK_API ++ const int *pixel_fmts = (const enum PixelFormat *)opaque; ++#else ++ params = (AVBufferSinkParams *)opaque; ++ const int *pixel_fmts = params->pixel_fmts; ++#endif ++ buf->pixel_fmts = ff_copy_int_list(pixel_fmts); ++ if (!buf->pixel_fmts) ++ return AVERROR(ENOMEM); ++ } ++ ++ return common_init(ctx); ++} ++ ++static av_cold void vsink_uninit(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ av_freep(&buf->pixel_fmts); ++ return common_uninit(ctx); ++} ++ ++static int vsink_query_formats(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(buf->pixel_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vsink_buffersink = { ++ .name = "buffersink", ++ .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."), ++ .priv_size = sizeof(BufferSinkContext), ++ .init = vsink_init, ++ .uninit = vsink_uninit, ++ ++ .query_formats = vsink_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = NULL }}, ++}; ++ ++#endif /* CONFIG_BUFFERSINK_FILTER */ ++ ++#if CONFIG_ABUFFERSINK_FILTER ++ ++static void filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) ++{ ++ end_frame(link); ++} ++ ++static av_cold int asink_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ AVABufferSinkParams *params; ++ ++ if (!opaque) { ++ av_log(ctx, AV_LOG_ERROR, ++ "No opaque field provided, an AVABufferSinkParams struct is required\n"); ++ return AVERROR(EINVAL); ++ } else ++ params = (AVABufferSinkParams *)opaque; ++ ++ buf->sample_fmts = ff_copy_int_list (params->sample_fmts); ++ buf->channel_layouts = ff_copy_int64_list(params->channel_layouts); ++ buf->packing_fmts = ff_copy_int_list (params->packing_fmts); ++ if (!buf->sample_fmts || !buf->channel_layouts || !buf->sample_fmts) { ++ av_freep(&buf->sample_fmts); ++ av_freep(&buf->channel_layouts); ++ av_freep(&buf->packing_fmts); ++ return AVERROR(ENOMEM); ++ } ++ ++ return common_init(ctx); ++} ++ ++static av_cold void asink_uninit(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ ++ av_freep(&buf->sample_fmts); ++ av_freep(&buf->channel_layouts); ++ av_freep(&buf->packing_fmts); ++ return common_uninit(ctx); ++} ++ ++static int asink_query_formats(AVFilterContext *ctx) ++{ ++ BufferSinkContext *buf = ctx->priv; ++ AVFilterFormats *formats = NULL; ++ ++ if (!(formats = avfilter_make_format_list(buf->sample_fmts))) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_sample_formats(ctx, formats); ++ ++ if (!(formats = avfilter_make_format64_list(buf->channel_layouts))) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_channel_layouts(ctx, formats); ++ ++ if (!(formats = avfilter_make_format_list(buf->packing_fmts))) ++ return AVERROR(ENOMEM); ++ avfilter_set_common_packing_formats(ctx, formats); ++ ++ return 0; ++} ++ ++AVFilter avfilter_asink_abuffersink = { ++ .name = "abuffersink", ++ .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."), ++ .init = asink_init, ++ .uninit = asink_uninit, ++ .priv_size = sizeof(BufferSinkContext), ++ .query_formats = asink_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .filter_samples = filter_samples, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = NULL }}, ++}; ++ ++#endif /* CONFIG_ABUFFERSINK_FILTER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/src_movie.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/src_movie.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/src_movie.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/src_movie.c 2012-05-14 14:08:54.795349260 +0200 +@@ -0,0 +1,471 @@ ++/* ++ * Copyright (c) 2010 Stefano Sabatini ++ * Copyright (c) 2008 Victor Paesa ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * movie video source ++ * ++ * @todo use direct rendering (no allocation of a new frame) ++ * @todo support a PTS correction mechanism ++ * @todo support more than one output stream ++ */ ++ ++/* #define DEBUG */ ++ ++#include ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++#include "libavutil/imgutils.h" ++#include "libavformat/avformat.h" ++#include "avcodec.h" ++#include "avfilter.h" ++ ++typedef struct { ++ /* common A/V fields */ ++ const AVClass *class; ++ int64_t seek_point; ///< seekpoint in microseconds ++ double seek_point_d; ++ char *format_name; ++ char *file_name; ++ int stream_index; ++ ++ AVFormatContext *format_ctx; ++ AVCodecContext *codec_ctx; ++ int is_done; ++ AVFrame *frame; ///< video frame to store the decoded images in ++ ++ /* video-only fields */ ++ int w, h; ++ AVFilterBufferRef *picref; ++ ++ /* audio-only fields */ ++ int bps; ///< bytes per sample ++ AVPacket pkt, pkt0; ++ AVFilterBufferRef *samplesref; ++} MovieContext; ++ ++#define OFFSET(x) offsetof(MovieContext, x) ++ ++static const AVOption movie_options[]= { ++{"format_name", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX }, ++{"f", "set format name", OFFSET(format_name), AV_OPT_TYPE_STRING, {.str = 0}, CHAR_MIN, CHAR_MAX }, ++{"stream_index", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX }, ++{"si", "set stream index", OFFSET(stream_index), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX }, ++{"seek_point", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 }, ++{"sp", "set seekpoint (seconds)", OFFSET(seek_point_d), AV_OPT_TYPE_DOUBLE, {.dbl = 0}, 0, (INT64_MAX-1) / 1000000 }, ++{NULL}, ++}; ++ ++static const char *movie_get_name(void *ctx) ++{ ++ return "movie"; ++} ++ ++static const AVClass movie_class = { ++ "MovieContext", ++ movie_get_name, ++ movie_options ++}; ++ ++static av_cold int movie_common_init(AVFilterContext *ctx, const char *args, void *opaque, ++ enum AVMediaType type) ++{ ++ MovieContext *movie = ctx->priv; ++ AVInputFormat *iformat = NULL; ++ AVCodec *codec; ++ int64_t timestamp; ++ int ret; ++ ++ movie->class = &movie_class; ++ av_opt_set_defaults(movie); ++ ++ if (args) ++ movie->file_name = av_get_token(&args, ":"); ++ if (!movie->file_name || !*movie->file_name) { ++ av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (*args++ == ':' && (ret = av_set_options_string(movie, args, "=", ":")) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ movie->seek_point = movie->seek_point_d * 1000000 + 0.5; ++ ++ av_register_all(); ++ ++ // Try to find the movie format (container) ++ iformat = movie->format_name ? av_find_input_format(movie->format_name) : NULL; ++ ++ movie->format_ctx = NULL; ++ if ((ret = avformat_open_input(&movie->format_ctx, movie->file_name, iformat, NULL)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Failed to avformat_open_input '%s'\n", movie->file_name); ++ return ret; ++ } ++ if ((ret = avformat_find_stream_info(movie->format_ctx, NULL)) < 0) ++ av_log(ctx, AV_LOG_WARNING, "Failed to find stream info\n"); ++ ++ // if seeking requested, we execute it ++ if (movie->seek_point > 0) { ++ timestamp = movie->seek_point; ++ // add the stream start time, should it exist ++ if (movie->format_ctx->start_time != AV_NOPTS_VALUE) { ++ if (timestamp > INT64_MAX - movie->format_ctx->start_time) { ++ av_log(ctx, AV_LOG_ERROR, ++ "%s: seek value overflow with start_time:%"PRId64" seek_point:%"PRId64"\n", ++ movie->file_name, movie->format_ctx->start_time, movie->seek_point); ++ return AVERROR(EINVAL); ++ } ++ timestamp += movie->format_ctx->start_time; ++ } ++ if ((ret = av_seek_frame(movie->format_ctx, -1, timestamp, AVSEEK_FLAG_BACKWARD)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "%s: could not seek to position %"PRId64"\n", ++ movie->file_name, timestamp); ++ return ret; ++ } ++ } ++ ++ /* select the media stream */ ++ if ((ret = av_find_best_stream(movie->format_ctx, type, ++ movie->stream_index, -1, NULL, 0)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "No %s stream with index '%d' found\n", ++ av_get_media_type_string(type), movie->stream_index); ++ return ret; ++ } ++ movie->stream_index = ret; ++ movie->codec_ctx = movie->format_ctx->streams[movie->stream_index]->codec; ++ ++ /* ++ * So now we've got a pointer to the so-called codec context for our video ++ * stream, but we still have to find the actual codec and open it. ++ */ ++ codec = avcodec_find_decoder(movie->codec_ctx->codec_id); ++ if (!codec) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to find any codec\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to open codec\n"); ++ return ret; ++ } ++ ++ av_log(ctx, AV_LOG_INFO, "seek_point:%"PRIi64" format_name:%s file_name:%s stream_index:%d\n", ++ movie->seek_point, movie->format_name, movie->file_name, ++ movie->stream_index); ++ ++ if (!(movie->frame = avcodec_alloc_frame()) ) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to alloc frame\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ return 0; ++} ++ ++static av_cold void movie_common_uninit(AVFilterContext *ctx) ++{ ++ MovieContext *movie = ctx->priv; ++ ++ av_free(movie->file_name); ++ av_free(movie->format_name); ++ if (movie->codec_ctx) ++ avcodec_close(movie->codec_ctx); ++ if (movie->format_ctx) ++ avformat_close_input(&movie->format_ctx); ++ ++ avfilter_unref_buffer(movie->picref); ++ av_freep(&movie->frame); ++ ++ avfilter_unref_buffer(movie->samplesref); ++} ++ ++#if CONFIG_MOVIE_FILTER ++ ++static av_cold int movie_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ MovieContext *movie = ctx->priv; ++ int ret; ++ ++ if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_VIDEO)) < 0) ++ return ret; ++ ++ movie->w = movie->codec_ctx->width; ++ movie->h = movie->codec_ctx->height; ++ ++ return 0; ++} ++ ++static int movie_query_formats(AVFilterContext *ctx) ++{ ++ MovieContext *movie = ctx->priv; ++ enum PixelFormat pix_fmts[] = { movie->codec_ctx->pix_fmt, PIX_FMT_NONE }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int movie_config_output_props(AVFilterLink *outlink) ++{ ++ MovieContext *movie = outlink->src->priv; ++ ++ outlink->w = movie->w; ++ outlink->h = movie->h; ++ outlink->time_base = movie->format_ctx->streams[movie->stream_index]->time_base; ++ ++ return 0; ++} ++ ++static int movie_get_frame(AVFilterLink *outlink) ++{ ++ MovieContext *movie = outlink->src->priv; ++ AVPacket pkt; ++ int ret, frame_decoded; ++ AVStream *st = movie->format_ctx->streams[movie->stream_index]; ++ ++ if (movie->is_done == 1) ++ return 0; ++ ++ while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) { ++ // Is this a packet from the video stream? ++ if (pkt.stream_index == movie->stream_index) { ++ avcodec_decode_video2(movie->codec_ctx, movie->frame, &frame_decoded, &pkt); ++ ++ if (frame_decoded) { ++ /* FIXME: avoid the memcpy */ ++ movie->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE | AV_PERM_PRESERVE | ++ AV_PERM_REUSE2, outlink->w, outlink->h); ++ av_image_copy(movie->picref->data, movie->picref->linesize, ++ (void*)movie->frame->data, movie->frame->linesize, ++ movie->picref->format, outlink->w, outlink->h); ++ avfilter_copy_frame_props(movie->picref, movie->frame); ++ ++ /* FIXME: use a PTS correction mechanism as that in ++ * ffplay.c when some API will be available for that */ ++ /* use pkt_dts if pkt_pts is not available */ ++ movie->picref->pts = movie->frame->pkt_pts == AV_NOPTS_VALUE ? ++ movie->frame->pkt_dts : movie->frame->pkt_pts; ++ ++ if (!movie->frame->sample_aspect_ratio.num) ++ movie->picref->video->sample_aspect_ratio = st->sample_aspect_ratio; ++ av_dlog(outlink->src, ++ "movie_get_frame(): file:'%s' pts:%"PRId64" time:%lf pos:%"PRId64" aspect:%d/%d\n", ++ movie->file_name, movie->picref->pts, ++ (double)movie->picref->pts * av_q2d(st->time_base), ++ movie->picref->pos, ++ movie->picref->video->sample_aspect_ratio.num, ++ movie->picref->video->sample_aspect_ratio.den); ++ // We got it. Free the packet since we are returning ++ av_free_packet(&pkt); ++ ++ return 0; ++ } ++ } ++ // Free the packet that was allocated by av_read_frame ++ av_free_packet(&pkt); ++ } ++ ++ // On multi-frame source we should stop the mixing process when ++ // the movie source does not have more frames ++ if (ret == AVERROR_EOF) ++ movie->is_done = 1; ++ return ret; ++} ++ ++static int movie_request_frame(AVFilterLink *outlink) ++{ ++ AVFilterBufferRef *outpicref; ++ MovieContext *movie = outlink->src->priv; ++ int ret; ++ ++ if (movie->is_done) ++ return AVERROR_EOF; ++ if ((ret = movie_get_frame(outlink)) < 0) ++ return ret; ++ ++ outpicref = avfilter_ref_buffer(movie->picref, ~0); ++ avfilter_start_frame(outlink, outpicref); ++ avfilter_draw_slice(outlink, 0, outlink->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(movie->picref); ++ movie->picref = NULL; ++ ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_movie = { ++ .name = "movie", ++ .description = NULL_IF_CONFIG_SMALL("Read from a movie source."), ++ .priv_size = sizeof(MovieContext), ++ .init = movie_init, ++ .uninit = movie_common_uninit, ++ .query_formats = movie_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = movie_request_frame, ++ .config_props = movie_config_output_props, }, ++ { .name = NULL}}, ++}; ++ ++#endif /* CONFIG_MOVIE_FILTER */ ++ ++#if CONFIG_AMOVIE_FILTER ++ ++static av_cold int amovie_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ MovieContext *movie = ctx->priv; ++ int ret; ++ ++ if ((ret = movie_common_init(ctx, args, opaque, AVMEDIA_TYPE_AUDIO)) < 0) ++ return ret; ++ ++ movie->bps = av_get_bytes_per_sample(movie->codec_ctx->sample_fmt); ++ return 0; ++} ++ ++static int amovie_query_formats(AVFilterContext *ctx) ++{ ++ MovieContext *movie = ctx->priv; ++ AVCodecContext *c = movie->codec_ctx; ++ ++ enum AVSampleFormat sample_fmts[] = { c->sample_fmt, -1 }; ++ int packing_fmts[] = { AVFILTER_PACKED, -1 }; ++ int64_t chlayouts[] = { c->channel_layout ? c->channel_layout : ++ av_get_default_channel_layout(c->channels), -1 }; ++ ++ avfilter_set_common_sample_formats (ctx, avfilter_make_format_list(sample_fmts)); ++ avfilter_set_common_packing_formats(ctx, avfilter_make_format_list(packing_fmts)); ++ avfilter_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts)); ++ ++ return 0; ++} ++ ++static int amovie_config_output_props(AVFilterLink *outlink) ++{ ++ MovieContext *movie = outlink->src->priv; ++ AVCodecContext *c = movie->codec_ctx; ++ ++ outlink->sample_rate = c->sample_rate; ++ outlink->time_base = movie->format_ctx->streams[movie->stream_index]->time_base; ++ ++ return 0; ++} ++ ++static int amovie_get_samples(AVFilterLink *outlink) ++{ ++ MovieContext *movie = outlink->src->priv; ++ AVPacket pkt; ++ int ret, got_frame = 0; ++ ++ if (!movie->pkt.size && movie->is_done == 1) ++ return AVERROR_EOF; ++ ++ /* check for another frame, in case the previous one was completely consumed */ ++ if (!movie->pkt.size) { ++ while ((ret = av_read_frame(movie->format_ctx, &pkt)) >= 0) { ++ // Is this a packet from the selected stream? ++ if (pkt.stream_index != movie->stream_index) { ++ av_free_packet(&pkt); ++ continue; ++ } else { ++ movie->pkt0 = movie->pkt = pkt; ++ break; ++ } ++ } ++ ++ if (ret == AVERROR_EOF) { ++ movie->is_done = 1; ++ return ret; ++ } ++ } ++ ++ /* decode and update the movie pkt */ ++ avcodec_get_frame_defaults(movie->frame); ++ ret = avcodec_decode_audio4(movie->codec_ctx, movie->frame, &got_frame, &movie->pkt); ++ if (ret < 0) { ++ movie->pkt.size = 0; ++ return ret; ++ } ++ movie->pkt.data += ret; ++ movie->pkt.size -= ret; ++ ++ /* wrap the decoded data in a samplesref */ ++ if (got_frame) { ++ int nb_samples = movie->frame->nb_samples; ++ int data_size = ++ av_samples_get_buffer_size(NULL, movie->codec_ctx->channels, ++ nb_samples, movie->codec_ctx->sample_fmt, 1); ++ if (data_size < 0) ++ return data_size; ++ movie->samplesref = ++ avfilter_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples); ++ memcpy(movie->samplesref->data[0], movie->frame->data[0], data_size); ++ movie->samplesref->pts = movie->pkt.pts; ++ movie->samplesref->pos = movie->pkt.pos; ++ movie->samplesref->audio->sample_rate = movie->codec_ctx->sample_rate; ++ } ++ ++ // We got it. Free the packet since we are returning ++ if (movie->pkt.size <= 0) ++ av_free_packet(&movie->pkt0); ++ ++ return 0; ++} ++ ++static int amovie_request_frame(AVFilterLink *outlink) ++{ ++ MovieContext *movie = outlink->src->priv; ++ int ret; ++ ++ if (movie->is_done) ++ return AVERROR_EOF; ++ do { ++ if ((ret = amovie_get_samples(outlink)) < 0) ++ return ret; ++ } while (!movie->samplesref); ++ ++ avfilter_filter_samples(outlink, avfilter_ref_buffer(movie->samplesref, ~0)); ++ avfilter_unref_buffer(movie->samplesref); ++ movie->samplesref = NULL; ++ ++ return 0; ++} ++ ++AVFilter avfilter_asrc_amovie = { ++ .name = "amovie", ++ .description = NULL_IF_CONFIG_SMALL("Read audio from a movie source."), ++ .priv_size = sizeof(MovieContext), ++ .init = amovie_init, ++ .uninit = movie_common_uninit, ++ .query_formats = amovie_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_AUDIO, ++ .request_frame = amovie_request_frame, ++ .config_props = amovie_config_output_props, }, ++ { .name = NULL}}, ++}; ++ ++#endif /* CONFIG_AMOVIE_FILTER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/transform.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/transform.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/transform.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/transform.c 2012-05-14 14:08:54.796349280 +0200 +@@ -0,0 +1,185 @@ ++/* ++ * Copyright (C) 2010 Georg Martius ++ * Copyright (C) 2010 Daniel G. Taylor ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * transform input video ++ */ ++ ++#include "libavutil/common.h" ++ ++#include "transform.h" ++ ++#define INTERPOLATE_METHOD(name) \ ++ static uint8_t name(float x, float y, const uint8_t *src, \ ++ int width, int height, int stride, uint8_t def) ++ ++#define PIXEL(img, x, y, w, h, stride, def) \ ++ ((x) < 0 || (y) < 0) ? (def) : \ ++ (((x) >= (w) || (y) >= (h)) ? (def) : \ ++ img[(x) + (y) * (stride)]) ++ ++/** ++ * Nearest neighbor interpolation ++ */ ++INTERPOLATE_METHOD(interpolate_nearest) ++{ ++ return PIXEL(src, (int)(x + 0.5), (int)(y + 0.5), width, height, stride, def); ++} ++ ++/** ++ * Bilinear interpolation ++ */ ++INTERPOLATE_METHOD(interpolate_bilinear) ++{ ++ int x_c, x_f, y_c, y_f; ++ int v1, v2, v3, v4; ++ ++ if (x < -1 || x > width || y < -1 || y > height) { ++ return def; ++ } else { ++ x_f = (int)x; ++ x_c = x_f + 1; ++ ++ y_f = (int)y; ++ y_c = y_f + 1; ++ ++ v1 = PIXEL(src, x_c, y_c, width, height, stride, def); ++ v2 = PIXEL(src, x_c, y_f, width, height, stride, def); ++ v3 = PIXEL(src, x_f, y_c, width, height, stride, def); ++ v4 = PIXEL(src, x_f, y_f, width, height, stride, def); ++ ++ return (v1*(x - x_f)*(y - y_f) + v2*((x - x_f)*(y_c - y)) + ++ v3*(x_c - x)*(y - y_f) + v4*((x_c - x)*(y_c - y))); ++ } ++} ++ ++/** ++ * Biquadratic interpolation ++ */ ++INTERPOLATE_METHOD(interpolate_biquadratic) ++{ ++ int x_c, x_f, y_c, y_f; ++ uint8_t v1, v2, v3, v4; ++ float f1, f2, f3, f4; ++ ++ if (x < - 1 || x > width || y < -1 || y > height) ++ return def; ++ else { ++ x_f = (int)x; ++ x_c = x_f + 1; ++ y_f = (int)y; ++ y_c = y_f + 1; ++ ++ v1 = PIXEL(src, x_c, y_c, width, height, stride, def); ++ v2 = PIXEL(src, x_c, y_f, width, height, stride, def); ++ v3 = PIXEL(src, x_f, y_c, width, height, stride, def); ++ v4 = PIXEL(src, x_f, y_f, width, height, stride, def); ++ ++ f1 = 1 - sqrt((x_c - x) * (y_c - y)); ++ f2 = 1 - sqrt((x_c - x) * (y - y_f)); ++ f3 = 1 - sqrt((x - x_f) * (y_c - y)); ++ f4 = 1 - sqrt((x - x_f) * (y - y_f)); ++ return (v1 * f1 + v2 * f2 + v3 * f3 + v4 * f4) / (f1 + f2 + f3 + f4); ++ } ++} ++ ++void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix) { ++ matrix[0] = zoom * cos(angle); ++ matrix[1] = -sin(angle); ++ matrix[2] = x_shift; ++ matrix[3] = -matrix[1]; ++ matrix[4] = matrix[0]; ++ matrix[5] = y_shift; ++ matrix[6] = 0; ++ matrix[7] = 0; ++ matrix[8] = 1; ++} ++ ++void avfilter_add_matrix(const float *m1, const float *m2, float *result) ++{ ++ int i; ++ for (i = 0; i < 9; i++) ++ result[i] = m1[i] + m2[i]; ++} ++ ++void avfilter_sub_matrix(const float *m1, const float *m2, float *result) ++{ ++ int i; ++ for (i = 0; i < 9; i++) ++ result[i] = m1[i] - m2[i]; ++} ++ ++void avfilter_mul_matrix(const float *m1, float scalar, float *result) ++{ ++ int i; ++ for (i = 0; i < 9; i++) ++ result[i] = m1[i] * scalar; ++} ++ ++void avfilter_transform(const uint8_t *src, uint8_t *dst, ++ int src_stride, int dst_stride, ++ int width, int height, const float *matrix, ++ enum InterpolateMethod interpolate, ++ enum FillMethod fill) ++{ ++ int x, y; ++ float x_s, y_s; ++ uint8_t def = 0; ++ uint8_t (*func)(float, float, const uint8_t *, int, int, int, uint8_t) = NULL; ++ ++ switch(interpolate) { ++ case INTERPOLATE_NEAREST: ++ func = interpolate_nearest; ++ break; ++ case INTERPOLATE_BILINEAR: ++ func = interpolate_bilinear; ++ break; ++ case INTERPOLATE_BIQUADRATIC: ++ func = interpolate_biquadratic; ++ break; ++ } ++ ++ for (y = 0; y < height; y++) { ++ for(x = 0; x < width; x++) { ++ x_s = x * matrix[0] + y * matrix[1] + matrix[2]; ++ y_s = x * matrix[3] + y * matrix[4] + matrix[5]; ++ ++ switch(fill) { ++ case FILL_ORIGINAL: ++ def = src[y * src_stride + x]; ++ break; ++ case FILL_CLAMP: ++ y_s = av_clipf(y_s, 0, height - 1); ++ x_s = av_clipf(x_s, 0, width - 1); ++ def = src[(int)y_s * src_stride + (int)x_s]; ++ break; ++ case FILL_MIRROR: ++ y_s = (y_s < 0) ? -y_s : (y_s >= height) ? (height + height - y_s) : y_s; ++ x_s = (x_s < 0) ? -x_s : (x_s >= width) ? (width + width - x_s) : x_s; ++ def = src[(int)y_s * src_stride + (int)x_s]; ++ } ++ ++ dst[y * dst_stride + x] = func(x_s, y_s, src, width, height, src_stride, def); ++ } ++ } ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/transform.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/transform.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/transform.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/transform.h 2012-05-14 14:08:54.797349300 +0200 +@@ -0,0 +1,124 @@ ++/* ++ * Copyright (C) 2010 Georg Martius ++ * Copyright (C) 2010 Daniel G. Taylor ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_TRANSFORM_H ++#define AVFILTER_TRANSFORM_H ++ ++/** ++ * @file ++ * transform input video ++ * ++ * All matrices are defined as a single 9-item block of contiguous memory. For ++ * example, the identity matrix would be: ++ * ++ * float *matrix = {1, 0, 0, ++ * 0, 1, 0, ++ * 0, 0, 1}; ++ */ ++ ++enum InterpolateMethod { ++ INTERPOLATE_NEAREST, //< Nearest-neighbor (fast) ++ INTERPOLATE_BILINEAR, //< Bilinear ++ INTERPOLATE_BIQUADRATIC, //< Biquadratic (best) ++ INTERPOLATE_COUNT, //< Number of interpolation methods ++}; ++ ++// Shortcuts for the fastest and best interpolation methods ++#define INTERPOLATE_DEFAULT INTERPOLATE_BILINEAR ++#define INTERPOLATE_FAST INTERPOLATE_NEAREST ++#define INTERPOLATE_BEST INTERPOLATE_BIQUADRATIC ++ ++enum FillMethod { ++ FILL_BLANK, //< Fill zeroes at blank locations ++ FILL_ORIGINAL, //< Original image at blank locations ++ FILL_CLAMP, //< Extruded edge value at blank locations ++ FILL_MIRROR, //< Mirrored edge at blank locations ++ FILL_COUNT, //< Number of edge fill methods ++}; ++ ++// Shortcuts for fill methods ++#define FILL_DEFAULT FILL_ORIGINAL ++ ++/** ++ * Get an affine transformation matrix from a given translation, rotation, and ++ * zoom factor. The matrix will look like: ++ * ++ * [ zoom * cos(angle), -sin(angle), x_shift, ++ * sin(angle), zoom * cos(angle), y_shift, ++ * 0, 0, 1 ] ++ * ++ * @param x_shift horizontal translation ++ * @param y_shift vertical translation ++ * @param angle rotation in radians ++ * @param zoom scale percent (1.0 = 100%) ++ * @param matrix 9-item affine transformation matrix ++ */ ++void avfilter_get_matrix(float x_shift, float y_shift, float angle, float zoom, float *matrix); ++ ++/** ++ * Add two matrices together. result = m1 + m2. ++ * ++ * @param m1 9-item transformation matrix ++ * @param m2 9-item transformation matrix ++ * @param result 9-item transformation matrix ++ */ ++void avfilter_add_matrix(const float *m1, const float *m2, float *result); ++ ++/** ++ * Subtract one matrix from another. result = m1 - m2. ++ * ++ * @param m1 9-item transformation matrix ++ * @param m2 9-item transformation matrix ++ * @param result 9-item transformation matrix ++ */ ++void avfilter_sub_matrix(const float *m1, const float *m2, float *result); ++ ++/** ++ * Multiply a matrix by a scalar value. result = m1 * scalar. ++ * ++ * @param m1 9-item transformation matrix ++ * @param scalar a number ++ * @param result 9-item transformation matrix ++ */ ++void avfilter_mul_matrix(const float *m1, float scalar, float *result); ++ ++/** ++ * Do an affine transformation with the given interpolation method. This ++ * multiplies each vector [x,y,1] by the matrix and then interpolates to ++ * get the final value. ++ * ++ * @param src source image ++ * @param dst destination image ++ * @param src_stride source image line size in bytes ++ * @param dst_stride destination image line size in bytes ++ * @param width image width in pixels ++ * @param height image height in pixels ++ * @param matrix 9-item affine transformation matrix ++ * @param interpolate pixel interpolation method ++ * @param fill edge fill method ++ */ ++void avfilter_transform(const uint8_t *src, uint8_t *dst, ++ int src_stride, int dst_stride, ++ int width, int height, const float *matrix, ++ enum InterpolateMethod interpolate, ++ enum FillMethod fill); ++ ++#endif /* AVFILTER_TRANSFORM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/version.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/version.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/version.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/version.h 2012-05-14 14:08:54.797349300 +0200 +@@ -0,0 +1,43 @@ ++/* ++ * Version macros. ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFILTER_VERSION_H ++#define AVFILTER_VERSION_H ++ ++/** ++ * @file ++ * Libavfilter version macros ++ */ ++ ++#include "libavutil/avutil.h" ++ ++#define LIBAVFILTER_VERSION_MAJOR 2 ++#define LIBAVFILTER_VERSION_MINOR 61 ++#define LIBAVFILTER_VERSION_MICRO 100 ++ ++#define LIBAVFILTER_VERSION_INT AV_VERSION_INT(LIBAVFILTER_VERSION_MAJOR, \ ++ LIBAVFILTER_VERSION_MINOR, \ ++ LIBAVFILTER_VERSION_MICRO) ++#define LIBAVFILTER_VERSION AV_VERSION(LIBAVFILTER_VERSION_MAJOR, \ ++ LIBAVFILTER_VERSION_MINOR, \ ++ LIBAVFILTER_VERSION_MICRO) ++#define LIBAVFILTER_BUILD LIBAVFILTER_VERSION_INT ++ ++#endif // AVFILTER_VERSION_H +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_aspect.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_aspect.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_aspect.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_aspect.c 2012-05-14 14:08:54.798349320 +0200 +@@ -23,6 +23,7 @@ + * aspect ratio modification video filters + */ + ++#include "libavutil/mathematics.h" + #include "avfilter.h" + + typedef struct { +@@ -65,7 +66,7 @@ + { + AspectContext *aspect = link->dst->priv; + +- picref->video->pixel_aspect = aspect->aspect; ++ picref->video->sample_aspect_ratio = aspect->aspect; + avfilter_start_frame(link->dst->outputs[0], picref); + } + +@@ -80,8 +81,11 @@ + aspect->aspect.num * inlink->h, + aspect->aspect.den * inlink->w, 100); + +- av_log(inlink->dst, AV_LOG_INFO, "w:%d h:%d -> dar:%d/%d par:%d/%d\n", ++ av_log(inlink->dst, AV_LOG_INFO, "w:%d h:%d -> dar:%d/%d sar:%d/%d\n", + inlink->w, inlink->h, dar.num, dar.den, aspect->aspect.num, aspect->aspect.den); ++ ++ inlink->sample_aspect_ratio = aspect->aspect; ++ + return 0; + } + +@@ -93,7 +97,7 @@ + + .priv_size = sizeof(AspectContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = setdar_config_props, + .get_video_buffer = avfilter_null_get_video_buffer, +@@ -101,13 +105,23 @@ + .end_frame = avfilter_null_end_frame }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; + #endif /* CONFIG_SETDAR_FILTER */ + + #if CONFIG_SETSAR_FILTER ++/* for setdar filter, convert from frame aspect ratio to pixel aspect ratio */ ++static int setsar_config_props(AVFilterLink *inlink) ++{ ++ AspectContext *aspect = inlink->dst->priv; ++ ++ inlink->sample_aspect_ratio = aspect->aspect; ++ ++ return 0; ++} ++ + AVFilter avfilter_vf_setsar = { + .name = "setsar", + .description = NULL_IF_CONFIG_SMALL("Set the pixel sample aspect ratio."), +@@ -116,14 +130,15 @@ + + .priv_size = sizeof(AspectContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = setsar_config_props, + .get_video_buffer = avfilter_null_get_video_buffer, + .start_frame = start_frame, + .end_frame = avfilter_null_end_frame }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_ass.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_ass.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_ass.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_ass.c 2012-05-14 14:08:54.799349340 +0200 +@@ -0,0 +1,242 @@ ++/* ++ * Copyright (c) 2011 Baptiste Coudurier ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Libass subtitles burning filter. ++ * ++ * @see{http://www.matroska.org/technical/specs/subtitles/ssa.html} ++ */ ++ ++#include ++ ++#include "libavutil/avstring.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/pixdesc.h" ++#include "drawutils.h" ++#include "avfilter.h" ++ ++typedef struct { ++ ASS_Library *library; ++ ASS_Renderer *renderer; ++ ASS_Track *track; ++ int hsub, vsub; ++ char *filename; ++ uint8_t rgba_map[4]; ++ int pix_step[4]; ///< steps per pixel for each plane of the main output ++} AssContext; ++ ++/* libass supports a log level ranging from 0 to 7 */ ++int ass_libav_log_level_map[] = { ++ AV_LOG_QUIET, /* 0 */ ++ AV_LOG_PANIC, /* 1 */ ++ AV_LOG_FATAL, /* 2 */ ++ AV_LOG_ERROR, /* 3 */ ++ AV_LOG_WARNING, /* 4 */ ++ AV_LOG_INFO, /* 5 */ ++ AV_LOG_VERBOSE, /* 6 */ ++ AV_LOG_DEBUG, /* 7 */ ++}; ++ ++static void ass_log(int ass_level, const char *fmt, va_list args, void *ctx) ++{ ++ int level = ass_libav_log_level_map[ass_level]; ++ ++ av_vlog(ctx, level, fmt, args); ++ av_log(ctx, level, "\n"); ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ AssContext *ass = ctx->priv; ++ ++ if (args) ++ ass->filename = av_get_token(&args, ":"); ++ if (!ass->filename || !*ass->filename) { ++ av_log(ctx, AV_LOG_ERROR, "No filename provided!\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ ass->library = ass_library_init(); ++ if (!ass->library) { ++ av_log(ctx, AV_LOG_ERROR, "Could not initialize libass.\n"); ++ return AVERROR(EINVAL); ++ } ++ ass_set_message_cb(ass->library, ass_log, ctx); ++ ++ ass->renderer = ass_renderer_init(ass->library); ++ if (!ass->renderer) { ++ av_log(ctx, AV_LOG_ERROR, "Could not initialize libass renderer.\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ ass->track = ass_read_file(ass->library, ass->filename, NULL); ++ if (!ass->track) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Could not create a libass track when reading file '%s'\n", ++ ass->filename); ++ return AVERROR(EINVAL); ++ } ++ ++ ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1); ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ AssContext *ass = ctx->priv; ++ ++ av_freep(&ass->filename); ++ if (ass->track) ++ ass_free_track(ass->track); ++ if (ass->renderer) ++ ass_renderer_done(ass->renderer); ++ if (ass->library) ++ ass_library_done(ass->library); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_ARGB, PIX_FMT_RGBA, ++ PIX_FMT_ABGR, PIX_FMT_BGRA, ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ ++ return 0; ++} ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ AssContext *ass = inlink->dst->priv; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; ++ double sar = inlink->sample_aspect_ratio.num ? ++ av_q2d(inlink->sample_aspect_ratio) : 1; ++ double dar = inlink->w / inlink->h * sar; ++ ++ av_image_fill_max_pixsteps(ass->pix_step, NULL, pix_desc); ++ ff_fill_rgba_map(ass->rgba_map, inlink->format); ++ ++ ass->hsub = pix_desc->log2_chroma_w; ++ ass->vsub = pix_desc->log2_chroma_h; ++ ++ ass_set_frame_size (ass->renderer, inlink->w, inlink->h); ++ ass_set_aspect_ratio(ass->renderer, dar, sar); ++ ++ return 0; ++} ++ ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } ++ ++#define R 0 ++#define G 1 ++#define B 2 ++#define A 3 ++ ++#define SET_PIXEL_RGB(picref, rgba_color, val, x, y, pixel_step, r_off, g_off, b_off) { \ ++ p = picref->data[0] + (x) * pixel_step + ((y) * picref->linesize[0]); \ ++ alpha = rgba_color[A] * (val) * 129; \ ++ *(p+r_off) = (alpha * rgba_color[R] + (255*255*129 - alpha) * *(p+r_off)) >> 23; \ ++ *(p+g_off) = (alpha * rgba_color[G] + (255*255*129 - alpha) * *(p+g_off)) >> 23; \ ++ *(p+b_off) = (alpha * rgba_color[B] + (255*255*129 - alpha) * *(p+b_off)) >> 23; \ ++} ++ ++/* libass stores an RGBA color in the format RRGGBBTT, where TT is the transparency level */ ++#define AR(c) ( (c)>>24) ++#define AG(c) (((c)>>16)&0xFF) ++#define AB(c) (((c)>>8) &0xFF) ++#define AA(c) ((0xFF-c) &0xFF) ++ ++static void overlay_ass_image(AVFilterBufferRef *picref, const uint8_t *rgba_map, const int pix_step, ++ const ASS_Image *image) ++{ ++ int i, j; ++ int alpha; ++ uint8_t *p; ++ const int ro = rgba_map[R]; ++ const int go = rgba_map[G]; ++ const int bo = rgba_map[B]; ++ ++ for (; image; image = image->next) { ++ uint8_t rgba_color[] = {AR(image->color), AG(image->color), AB(image->color), AA(image->color)}; ++ unsigned char *row = image->bitmap; ++ ++ for (i = 0; i < image->h; i++) { ++ for (j = 0; j < image->w; j++) { ++ if (row[j]) { ++ SET_PIXEL_RGB(picref, rgba_color, row[j], image->dst_x + j, image->dst_y + i, pix_step, ro, go, bo); ++ } ++ } ++ row += image->stride; ++ } ++ } ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ AssContext *ass = ctx->priv; ++ AVFilterBufferRef *picref = inlink->cur_buf; ++ int detect_change = 0; ++ double time_ms = picref->pts * av_q2d(inlink->time_base) * 1000; ++ ASS_Image *image = ass_render_frame(ass->renderer, ass->track, ++ time_ms, &detect_change); ++ ++ if (detect_change) ++ av_log(ctx, AV_LOG_DEBUG, "Change happened at time ms:%f\n", time_ms); ++ ++ overlay_ass_image(picref, ass->rgba_map, ass->pix_step[0], image); ++ ++ avfilter_draw_slice(outlink, 0, picref->video->h, 1); ++ avfilter_end_frame(outlink); ++} ++ ++AVFilter avfilter_vf_ass = { ++ .name = "ass", ++ .description = NULL_IF_CONFIG_SMALL("Render subtitles onto input video using the libass library."), ++ .priv_size = sizeof(AssContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = avfilter_null_start_frame, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, ++ .config_props = config_input, ++ .min_perms = AV_PERM_WRITE | AV_PERM_READ, ++ .rej_perms = AV_PERM_PRESERVE }, ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_blackframe.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_blackframe.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_blackframe.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_blackframe.c 2012-05-14 14:08:54.800349360 +0200 +@@ -34,6 +34,7 @@ + unsigned int bthresh; ///< black threshold + unsigned int frame; ///< frame number + unsigned int nblack; ///< number of black pixels counted so far ++ unsigned int last_keyframe; ///< frame number of the last received key-frame + } BlackFrameContext; + + static int query_formats(AVFilterContext *ctx) +@@ -44,7 +45,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -56,6 +57,7 @@ + blackframe->bthresh = 32; + blackframe->nblack = 0; + blackframe->frame = 0; ++ blackframe->last_keyframe = 0; + + if (args) + sscanf(args, "%u:%u", &blackframe->bamount, &blackframe->bthresh); +@@ -95,11 +97,16 @@ + AVFilterBufferRef *picref = inlink->cur_buf; + int pblack = 0; + ++ if (picref->video->key_frame) ++ blackframe->last_keyframe = blackframe->frame; ++ + pblack = blackframe->nblack * 100 / (inlink->w * inlink->h); + if (pblack >= blackframe->bamount) +- av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pos:%"PRId64" pts:%"PRId64" t:%f\n", ++ av_log(ctx, AV_LOG_INFO, "frame:%u pblack:%u pos:%"PRId64" pts:%"PRId64" t:%f " ++ "type:%c last_keyframe:%d\n", + blackframe->frame, pblack, picref->pos, picref->pts, +- picref->pts == AV_NOPTS_VALUE ? -1 : picref->pts * av_q2d(inlink->time_base)); ++ picref->pts == AV_NOPTS_VALUE ? -1 : picref->pts * av_q2d(inlink->time_base), ++ av_get_picture_type_char(picref->video->pict_type), blackframe->last_keyframe); + + blackframe->frame++; + blackframe->nblack = 0; +@@ -115,7 +122,7 @@ + + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = draw_slice, + .get_video_buffer = avfilter_null_get_video_buffer, +@@ -123,7 +130,7 @@ + .end_frame = end_frame, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_boxblur.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_boxblur.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_boxblur.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_boxblur.c 2012-05-14 14:08:54.801349380 +0200 +@@ -0,0 +1,349 @@ ++/* ++ * Copyright (c) 2002 Michael Niedermayer ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * @file ++ * Apply a boxblur filter to the input video. ++ * Ported from MPlayer libmpcodecs/vf_boxblur.c. ++ */ ++ ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++ ++static const char * const var_names[] = { ++ "w", ++ "h", ++ "cw", ++ "ch", ++ "hsub", ++ "vsub", ++ NULL ++}; ++ ++enum var_name { ++ VAR_W, ++ VAR_H, ++ VAR_CW, ++ VAR_CH, ++ VAR_HSUB, ++ VAR_VSUB, ++ VARS_NB ++}; ++ ++typedef struct { ++ int radius; ++ int power; ++} FilterParam; ++ ++typedef struct { ++ FilterParam luma_param; ++ FilterParam chroma_param; ++ FilterParam alpha_param; ++ char luma_radius_expr [256]; ++ char chroma_radius_expr[256]; ++ char alpha_radius_expr [256]; ++ ++ int hsub, vsub; ++ int radius[4]; ++ int power[4]; ++ uint8_t *temp[2]; ///< temporary buffer used in blur_power() ++} BoxBlurContext; ++ ++#define Y 0 ++#define U 1 ++#define V 2 ++#define A 3 ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ BoxBlurContext *boxblur = ctx->priv; ++ int e; ++ ++ if (!args) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Filter expects 2 or 4 or 6 arguments, none provided\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ e = sscanf(args, "%255[^:]:%d:%255[^:]:%d:%255[^:]:%d", ++ boxblur->luma_radius_expr, &boxblur->luma_param .power, ++ boxblur->chroma_radius_expr, &boxblur->chroma_param.power, ++ boxblur->alpha_radius_expr, &boxblur->alpha_param .power); ++ ++ if (e != 2 && e != 4 && e != 6) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Filter expects 2 or 4 or 6 params, provided %d\n", e); ++ return AVERROR(EINVAL); ++ } ++ ++ if (e < 4) { ++ boxblur->chroma_param.power = boxblur->luma_param.power; ++ av_strlcpy(boxblur->chroma_radius_expr, boxblur->luma_radius_expr, ++ sizeof(boxblur->chroma_radius_expr)); ++ } ++ if (e < 6) { ++ boxblur->alpha_param.power = boxblur->luma_param.power; ++ av_strlcpy(boxblur->alpha_radius_expr, boxblur->luma_radius_expr, ++ sizeof(boxblur->alpha_radius_expr)); ++ } ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ BoxBlurContext *boxblur = ctx->priv; ++ ++ av_freep(&boxblur->temp[0]); ++ av_freep(&boxblur->temp[1]); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, ++ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUVA420P, ++ PIX_FMT_YUV440P, PIX_FMT_GRAY8, ++ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, ++ PIX_FMT_YUVJ440P, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ BoxBlurContext *boxblur = ctx->priv; ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format]; ++ int w = inlink->w, h = inlink->h; ++ int cw, ch; ++ double var_values[VARS_NB], res; ++ char *expr; ++ int ret; ++ ++ if (!(boxblur->temp[0] = av_malloc(FFMAX(w, h))) || ++ !(boxblur->temp[1] = av_malloc(FFMAX(w, h)))) ++ return AVERROR(ENOMEM); ++ ++ boxblur->hsub = desc->log2_chroma_w; ++ boxblur->vsub = desc->log2_chroma_h; ++ ++ var_values[VAR_W] = inlink->w; ++ var_values[VAR_H] = inlink->h; ++ var_values[VAR_CW] = cw = w>>boxblur->hsub; ++ var_values[VAR_CH] = ch = h>>boxblur->vsub; ++ var_values[VAR_HSUB] = 1<hsub; ++ var_values[VAR_VSUB] = 1<vsub; ++ ++#define EVAL_RADIUS_EXPR(comp) \ ++ expr = boxblur->comp##_radius_expr; \ ++ ret = av_expr_parse_and_eval(&res, expr, var_names, var_values, \ ++ NULL, NULL, NULL, NULL, NULL, 0, ctx); \ ++ boxblur->comp##_param.radius = res; \ ++ if (ret < 0) { \ ++ av_log(NULL, AV_LOG_ERROR, \ ++ "Error when evaluating " #comp " radius expression '%s'\n", expr); \ ++ return ret; \ ++ } ++ EVAL_RADIUS_EXPR(luma); ++ EVAL_RADIUS_EXPR(chroma); ++ EVAL_RADIUS_EXPR(alpha); ++ ++ av_log(ctx, AV_LOG_INFO, ++ "luma_radius:%d luma_power:%d " ++ "chroma_radius:%d chroma_power:%d " ++ "alpha_radius:%d alpha_power:%d " ++ "w:%d chroma_w:%d h:%d chroma_h:%d\n", ++ boxblur->luma_param .radius, boxblur->luma_param .power, ++ boxblur->chroma_param.radius, boxblur->chroma_param.power, ++ boxblur->alpha_param .radius, boxblur->alpha_param .power, ++ w, cw, h, ch); ++ ++#define CHECK_RADIUS_VAL(w_, h_, comp) \ ++ if (boxblur->comp##_param.radius < 0 || \ ++ 2*boxblur->comp##_param.radius > FFMIN(w_, h_)) { \ ++ av_log(ctx, AV_LOG_ERROR, \ ++ "Invalid " #comp " radius value %d, must be >= 0 and <= %d\n", \ ++ boxblur->comp##_param.radius, FFMIN(w_, h_)/2); \ ++ return AVERROR(EINVAL); \ ++ } ++ CHECK_RADIUS_VAL(w, h, luma); ++ CHECK_RADIUS_VAL(cw, ch, chroma); ++ CHECK_RADIUS_VAL(w, h, alpha); ++ ++ boxblur->radius[Y] = boxblur->luma_param.radius; ++ boxblur->radius[U] = boxblur->radius[V] = boxblur->chroma_param.radius; ++ boxblur->radius[A] = boxblur->alpha_param.radius; ++ ++ boxblur->power[Y] = boxblur->luma_param.power; ++ boxblur->power[U] = boxblur->power[V] = boxblur->chroma_param.power; ++ boxblur->power[A] = boxblur->alpha_param.power; ++ ++ return 0; ++} ++ ++static inline void blur(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, ++ int len, int radius) ++{ ++ /* Naive boxblur would sum source pixels from x-radius .. x+radius ++ * for destination pixel x. That would be O(radius*width). ++ * If you now look at what source pixels represent 2 consecutive ++ * output pixels, then you see they are almost identical and only ++ * differ by 2 pixels, like: ++ * src0 111111111 ++ * dst0 1 ++ * src1 111111111 ++ * dst1 1 ++ * src0-src1 1 -1 ++ * so when you know one output pixel you can find the next by just adding ++ * and subtracting 1 input pixel. ++ * The following code adopts this faster variant. ++ */ ++ int x, sum = 0; ++ const int length = radius*2 + 1; ++ const int inv = ((1<<16) + length/2)/length; ++ ++ for (x = 0; x < radius; x++) ++ sum += src[x*src_step]<<1; ++ sum += src[radius*src_step]; ++ ++ for (x = 0; x <= radius; x++) { ++ sum += src[(radius+x)*src_step] - src[(radius-x)*src_step]; ++ dst[x*dst_step] = (sum*inv + (1<<15))>>16; ++ } ++ ++ for (; x < len-radius; x++) { ++ sum += src[(radius+x)*src_step] - src[(x-radius-1)*src_step]; ++ dst[x*dst_step] = (sum*inv + (1<<15))>>16; ++ } ++ ++ for (; x < len; x++) { ++ sum += src[(2*len-radius-x-1)*src_step] - src[(x-radius-1)*src_step]; ++ dst[x*dst_step] = (sum*inv + (1<<15))>>16; ++ } ++} ++ ++static inline void blur_power(uint8_t *dst, int dst_step, const uint8_t *src, int src_step, ++ int len, int radius, int power, uint8_t *temp[2]) ++{ ++ uint8_t *a = temp[0], *b = temp[1]; ++ ++ if (radius && power) { ++ blur(a, 1, src, src_step, len, radius); ++ for (; power > 2; power--) { ++ uint8_t *c; ++ blur(b, 1, a, 1, len, radius); ++ c = a; a = b; b = c; ++ } ++ if (power > 1) { ++ blur(dst, dst_step, a, 1, len, radius); ++ } else { ++ int i; ++ for (i = 0; i < len; i++) ++ dst[i*dst_step] = a[i]; ++ } ++ } else { ++ int i; ++ for (i = 0; i < len; i++) ++ dst[i*dst_step] = src[i*src_step]; ++ } ++} ++ ++static void hblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, ++ int w, int h, int radius, int power, uint8_t *temp[2]) ++{ ++ int y; ++ ++ if (radius == 0 && dst == src) ++ return; ++ ++ for (y = 0; y < h; y++) ++ blur_power(dst + y*dst_linesize, 1, src + y*src_linesize, 1, ++ w, radius, power, temp); ++} ++ ++static void vblur(uint8_t *dst, int dst_linesize, const uint8_t *src, int src_linesize, ++ int w, int h, int radius, int power, uint8_t *temp[2]) ++{ ++ int x; ++ ++ if (radius == 0 && dst == src) ++ return; ++ ++ for (x = 0; x < w; x++) ++ blur_power(dst + x, dst_linesize, src + x, src_linesize, ++ h, radius, power, temp); ++} ++ ++static void null_draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) { } ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ BoxBlurContext *boxblur = ctx->priv; ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ AVFilterBufferRef *inpicref = inlink ->cur_buf; ++ AVFilterBufferRef *outpicref = outlink->out_buf; ++ int plane; ++ int cw = inlink->w >> boxblur->hsub, ch = inlink->h >> boxblur->vsub; ++ int w[4] = { inlink->w, cw, cw, inlink->w }; ++ int h[4] = { inlink->h, ch, ch, inlink->h }; ++ ++ for (plane = 0; inpicref->data[plane] && plane < 4; plane++) ++ hblur(outpicref->data[plane], outpicref->linesize[plane], ++ inpicref ->data[plane], inpicref ->linesize[plane], ++ w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane], ++ boxblur->temp); ++ ++ for (plane = 0; inpicref->data[plane] && plane < 4; plane++) ++ vblur(outpicref->data[plane], outpicref->linesize[plane], ++ outpicref->data[plane], outpicref->linesize[plane], ++ w[plane], h[plane], boxblur->radius[plane], boxblur->power[plane], ++ boxblur->temp); ++ ++ avfilter_draw_slice(outlink, 0, inlink->h, 1); ++ avfilter_default_end_frame(inlink); ++} ++ ++AVFilter avfilter_vf_boxblur = { ++ .name = "boxblur", ++ .description = NULL_IF_CONFIG_SMALL("Blur the input."), ++ .priv_size = sizeof(BoxBlurContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = config_input, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_READ }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_copy.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_copy.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_copy.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_copy.c 2012-05-14 14:08:54.802349400 +0200 +@@ -27,14 +27,14 @@ + .name = "copy", + .description = NULL_IF_CONFIG_SMALL("Copy the input video unchanged to the output."), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .start_frame = avfilter_null_start_frame, + .end_frame = avfilter_null_end_frame, + .rej_perms = ~0 }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_crop.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_crop.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_crop.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_crop.c 2012-05-14 14:08:54.803349421 +0200 +@@ -29,16 +29,19 @@ + #include "libavutil/eval.h" + #include "libavutil/avstring.h" + #include "libavutil/libm.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/mathematics.h" + +-static const char *var_names[] = { +- "E", +- "PHI", +- "PI", ++static const char * const var_names[] = { + "in_w", "iw", ///< width of the input video + "in_h", "ih", ///< height of the input video + "out_w", "ow", ///< width of the cropped video + "out_h", "oh", ///< height of the cropped video ++ "a", ++ "sar", ++ "dar", ++ "hsub", ++ "vsub", + "x", + "y", + "n", ///< number of frame +@@ -48,13 +51,15 @@ + }; + + enum var_name { +- VAR_E, +- VAR_PHI, +- VAR_PI, + VAR_IN_W, VAR_IW, + VAR_IN_H, VAR_IH, + VAR_OUT_W, VAR_OW, + VAR_OUT_H, VAR_OH, ++ VAR_A, ++ VAR_SAR, ++ VAR_DAR, ++ VAR_HSUB, ++ VAR_VSUB, + VAR_X, + VAR_Y, + VAR_N, +@@ -80,6 +85,7 @@ + { + static const enum PixelFormat pix_fmts[] = { + PIX_FMT_RGB48BE, PIX_FMT_RGB48LE, ++ PIX_FMT_BGR48BE, PIX_FMT_BGR48LE, + PIX_FMT_ARGB, PIX_FMT_RGBA, + PIX_FMT_ABGR, PIX_FMT_BGRA, + PIX_FMT_RGB24, PIX_FMT_BGR24, +@@ -103,7 +109,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + + return 0; + } +@@ -155,11 +161,13 @@ + const char *expr; + double res; + +- crop->var_values[VAR_E] = M_E; +- crop->var_values[VAR_PHI] = M_PHI; +- crop->var_values[VAR_PI] = M_PI; + crop->var_values[VAR_IN_W] = crop->var_values[VAR_IW] = ctx->inputs[0]->w; + crop->var_values[VAR_IN_H] = crop->var_values[VAR_IH] = ctx->inputs[0]->h; ++ crop->var_values[VAR_A] = (float) link->w / link->h; ++ crop->var_values[VAR_SAR] = link->sample_aspect_ratio.num ? av_q2d(link->sample_aspect_ratio) : 1; ++ crop->var_values[VAR_DAR] = crop->var_values[VAR_A] * crop->var_values[VAR_SAR]; ++ crop->var_values[VAR_HSUB] = 1<log2_chroma_w; ++ crop->var_values[VAR_VSUB] = 1<log2_chroma_h; + crop->var_values[VAR_X] = NAN; + crop->var_values[VAR_Y] = NAN; + crop->var_values[VAR_OUT_W] = crop->var_values[VAR_OW] = NAN; +@@ -263,11 +271,9 @@ + crop->x &= ~((1 << crop->hsub) - 1); + crop->y &= ~((1 << crop->vsub) - 1); + +-#ifdef DEBUG +- av_log(ctx, AV_LOG_DEBUG, +- "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", +- (int)crop->var_values[VAR_N], crop->var_values[VAR_T], crop->x, crop->y, crop->x+crop->w, crop->y+crop->h); +-#endif ++ av_dlog(ctx, "n:%d t:%f x:%d y:%d x+w:%d y+h:%d\n", ++ (int)crop->var_values[VAR_N], crop->var_values[VAR_T], crop->x, ++ crop->y, crop->x+crop->w, crop->y+crop->h); + + ref2->data[0] += crop->y * ref2->linesize[0]; + ref2->data[0] += crop->x * crop->max_step[0]; +@@ -327,7 +333,7 @@ + .init = init, + .uninit = uninit, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, + .draw_slice = draw_slice, +@@ -335,7 +341,7 @@ + .get_video_buffer = avfilter_null_get_video_buffer, + .config_props = config_input, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_cropdetect.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_cropdetect.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_cropdetect.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_cropdetect.c 2012-05-14 14:08:54.804349442 +0200 +@@ -23,7 +23,7 @@ + * Ported from MPlayer libmpcodecs/vf_cropdetect.c. + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avfilter.h" + + typedef struct { +@@ -46,7 +46,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -200,7 +200,7 @@ + + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .get_video_buffer = avfilter_null_get_video_buffer, +@@ -208,7 +208,7 @@ + .end_frame = end_frame, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_delogo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_delogo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_delogo.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_delogo.c 2012-05-14 14:08:54.805349462 +0200 +@@ -0,0 +1,288 @@ ++/* ++ * Copyright (c) 2002 Jindrich Makovicka ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * @file ++ * A very simple tv station logo remover ++ * Ported from MPlayer libmpcodecs/vf_delogo.c. ++ */ ++ ++#include "libavutil/imgutils.h" ++#include "libavutil/opt.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++ ++/** ++ * Apply a simple delogo algorithm to the image in dst and put the ++ * result in src. ++ * ++ * The algorithm is only applied to the region specified by the logo ++ * parameters. ++ * ++ * @param w width of the input image ++ * @param h height of the input image ++ * @param logo_x x coordinate of the top left corner of the logo region ++ * @param logo_y y coordinate of the top left corner of the logo region ++ * @param logo_w width of the logo ++ * @param logo_h height of the logo ++ * @param band the size of the band around the processed area ++ * @param show show a rectangle around the processed area, useful for ++ * parameters tweaking ++ * @param direct if non-zero perform in-place processing ++ */ ++static void apply_delogo(uint8_t *dst, int dst_linesize, ++ uint8_t *src, int src_linesize, ++ int w, int h, ++ int logo_x, int logo_y, int logo_w, int logo_h, ++ int band, int show, int direct) ++{ ++ int x, y; ++ int interp, dist; ++ uint8_t *xdst, *xsrc; ++ ++ uint8_t *topleft, *botleft, *topright; ++ int xclipl, xclipr, yclipt, yclipb; ++ int logo_x1, logo_x2, logo_y1, logo_y2; ++ ++ xclipl = FFMAX(-logo_x, 0); ++ xclipr = FFMAX(logo_x+logo_w-w, 0); ++ yclipt = FFMAX(-logo_y, 0); ++ yclipb = FFMAX(logo_y+logo_h-h, 0); ++ ++ logo_x1 = logo_x + xclipl; ++ logo_x2 = logo_x + logo_w - xclipr; ++ logo_y1 = logo_y + yclipt; ++ logo_y2 = logo_y + logo_h - yclipb; ++ ++ topleft = src+logo_y1 * src_linesize+logo_x1; ++ topright = src+logo_y1 * src_linesize+logo_x2-1; ++ botleft = src+(logo_y2-1) * src_linesize+logo_x1; ++ ++ dst += (logo_y1+1)*dst_linesize; ++ src += (logo_y1+1)*src_linesize; ++ ++ if (!direct) ++ av_image_copy_plane(dst, dst_linesize, src, src_linesize, w, h); ++ ++ for (y = logo_y1+1; y < logo_y2-1; y++) { ++ for (x = logo_x1+1, ++ xdst = dst+logo_x1+1, ++ xsrc = src+logo_x1+1; x < logo_x2-1; x++, xdst++, xsrc++) { ++ interp = ++ (topleft[src_linesize*(y-logo_y -yclipt)] + ++ topleft[src_linesize*(y-logo_y-1-yclipt)] + ++ topleft[src_linesize*(y-logo_y+1-yclipt)]) * (logo_w-(x-logo_x))/logo_w ++ + ++ (topright[src_linesize*(y-logo_y-yclipt)] + ++ topright[src_linesize*(y-logo_y-1-yclipt)] + ++ topright[src_linesize*(y-logo_y+1-yclipt)]) * (x-logo_x)/logo_w ++ + ++ (topleft[x-logo_x-xclipl] + ++ topleft[x-logo_x-1-xclipl] + ++ topleft[x-logo_x+1-xclipl]) * (logo_h-(y-logo_y))/logo_h ++ + ++ (botleft[x-logo_x-xclipl] + ++ botleft[x-logo_x-1-xclipl] + ++ botleft[x-logo_x+1-xclipl]) * (y-logo_y)/logo_h; ++ interp /= 6; ++ ++ if (y >= logo_y+band && y < logo_y+logo_h-band && ++ x >= logo_x+band && x < logo_x+logo_w-band) { ++ *xdst = interp; ++ } else { ++ dist = 0; ++ if (x < logo_x+band) ++ dist = FFMAX(dist, logo_x-x+band); ++ else if (x >= logo_x+logo_w-band) ++ dist = FFMAX(dist, x-(logo_x+logo_w-1-band)); ++ ++ if (y < logo_y+band) ++ dist = FFMAX(dist, logo_y-y+band); ++ else if (y >= logo_y+logo_h-band) ++ dist = FFMAX(dist, y-(logo_y+logo_h-1-band)); ++ ++ *xdst = (*xsrc*dist + interp*(band-dist))/band; ++ if (show && (dist == band-1)) ++ *xdst = 0; ++ } ++ } ++ ++ dst += dst_linesize; ++ src += src_linesize; ++ } ++} ++ ++typedef struct { ++ const AVClass *class; ++ int x, y, w, h, band, show; ++} DelogoContext; ++ ++#define OFFSET(x) offsetof(DelogoContext, x) ++ ++static const AVOption delogo_options[]= { ++ {"x", "set logo x position", OFFSET(x), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX }, ++ {"y", "set logo y position", OFFSET(y), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX }, ++ {"w", "set logo width", OFFSET(w), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX }, ++ {"h", "set logo height", OFFSET(h), AV_OPT_TYPE_INT, {.dbl=-1}, -1, INT_MAX }, ++ {"band", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX }, ++ {"t", "set delogo area band size", OFFSET(band), AV_OPT_TYPE_INT, {.dbl= 4}, -1, INT_MAX }, ++ {"show", "show delogo area", OFFSET(show), AV_OPT_TYPE_INT, {.dbl= 0}, 0, 1 }, ++ {NULL}, ++}; ++ ++static const char *delogo_get_name(void *ctx) ++{ ++ return "delogo"; ++} ++ ++static const AVClass delogo_class = { ++ .class_name = "DelogoContext", ++ .item_name = delogo_get_name, ++ .option = delogo_options, ++}; ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, ++ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUV440P, ++ PIX_FMT_YUVA420P, PIX_FMT_GRAY8, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ DelogoContext *delogo = ctx->priv; ++ int ret = 0; ++ ++ delogo->class = &delogo_class; ++ av_opt_set_defaults(delogo); ++ ++ if (args) ++ ret = sscanf(args, "%d:%d:%d:%d:%d", ++ &delogo->x, &delogo->y, &delogo->w, &delogo->h, &delogo->band); ++ if (ret == 5) { ++ if (delogo->band < 0) ++ delogo->show = 1; ++ } else if ((ret = (av_set_options_string(delogo, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++#define CHECK_UNSET_OPT(opt) \ ++ if (delogo->opt == -1) { \ ++ av_log(delogo, AV_LOG_ERROR, "Option %s was not set.\n", #opt); \ ++ return AVERROR(EINVAL); \ ++ } ++ CHECK_UNSET_OPT(x); ++ CHECK_UNSET_OPT(y); ++ CHECK_UNSET_OPT(w); ++ CHECK_UNSET_OPT(h); ++ ++ if (delogo->show) ++ delogo->band = 4; ++ ++ av_log(ctx, AV_LOG_INFO, "x:%d y:%d, w:%d h:%d band:%d show:%d\n", ++ delogo->x, delogo->y, delogo->w, delogo->h, delogo->band, delogo->show); ++ ++ delogo->w += delogo->band*2; ++ delogo->h += delogo->band*2; ++ delogo->x -= delogo->band; ++ delogo->y -= delogo->band; ++ ++ return 0; ++} ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) ++{ ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ AVFilterBufferRef *outpicref; ++ ++ if (inpicref->perms & AV_PERM_PRESERVE) { ++ outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, ++ outlink->w, outlink->h); ++ avfilter_copy_buffer_ref_props(outpicref, inpicref); ++ outpicref->video->w = outlink->w; ++ outpicref->video->h = outlink->h; ++ } else ++ outpicref = inpicref; ++ ++ outlink->out_buf = outpicref; ++ avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0)); ++} ++ ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ DelogoContext *delogo = inlink->dst->priv; ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ AVFilterBufferRef *inpicref = inlink ->cur_buf; ++ AVFilterBufferRef *outpicref = outlink->out_buf; ++ int direct = inpicref == outpicref; ++ int hsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_w; ++ int vsub0 = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; ++ int plane; ++ ++ for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { ++ int hsub = plane == 1 || plane == 2 ? hsub0 : 0; ++ int vsub = plane == 1 || plane == 2 ? vsub0 : 0; ++ ++ apply_delogo(outpicref->data[plane], outpicref->linesize[plane], ++ inpicref ->data[plane], inpicref ->linesize[plane], ++ inlink->w>>hsub, inlink->h>>vsub, ++ delogo->x>>hsub, delogo->y>>vsub, ++ delogo->w>>hsub, delogo->h>>vsub, ++ delogo->band>>FFMIN(hsub, vsub), ++ delogo->show, direct); ++ } ++ ++ avfilter_draw_slice(outlink, 0, inlink->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(inpicref); ++ if (!direct) ++ avfilter_unref_buffer(outpicref); ++} ++ ++AVFilter avfilter_vf_delogo = { ++ .name = "delogo", ++ .description = NULL_IF_CONFIG_SMALL("Remove logo from input video."), ++ .priv_size = sizeof(DelogoContext), ++ .init = init, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = start_frame, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_WRITE | AV_PERM_READ, ++ .rej_perms = AV_PERM_PRESERVE }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_deshake.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_deshake.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_deshake.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_deshake.c 2012-05-14 14:08:54.807349502 +0200 +@@ -0,0 +1,556 @@ ++/* ++ * Copyright (C) 2010 Georg Martius ++ * Copyright (C) 2010 Daniel G. Taylor ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * fast deshake / depan video filter ++ * ++ * SAD block-matching motion compensation to fix small changes in ++ * horizontal and/or vertical shift. This filter helps remove camera shake ++ * from hand-holding a camera, bumping a tripod, moving on a vehicle, etc. ++ * ++ * Algorithm: ++ * - For each frame with one previous reference frame ++ * - For each block in the frame ++ * - If contrast > threshold then find likely motion vector ++ * - For all found motion vectors ++ * - Find most common, store as global motion vector ++ * - Find most likely rotation angle ++ * - Transform image along global motion ++ * ++ * TODO: ++ * - Fill frame edges based on previous/next reference frames ++ * - Fill frame edges by stretching image near the edges? ++ * - Can this be done quickly and look decent? ++ * ++ * Dark Shikari links to http://wiki.videolan.org/SoC_x264_2010#GPU_Motion_Estimation_2 ++ * for an algorithm similar to what could be used here to get the gmv ++ * It requires only a couple diamond searches + fast downscaling ++ * ++ * Special thanks to Jason Kotenko for his help with the algorithm and my ++ * inability to see simple errors in C code. ++ */ ++ ++#include "avfilter.h" ++#include "libavutil/common.h" ++#include "libavutil/mem.h" ++#include "libavutil/pixdesc.h" ++#include "libavcodec/dsputil.h" ++ ++#include "transform.h" ++ ++#define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_descriptors[link->format].log2_chroma_w) ++#define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_descriptors[link->format].log2_chroma_h) ++ ++enum SearchMethod { ++ EXHAUSTIVE, ///< Search all possible positions ++ SMART_EXHAUSTIVE, ///< Search most possible positions (faster) ++ SEARCH_COUNT ++}; ++ ++typedef struct { ++ int x; ///< Horizontal shift ++ int y; ///< Vertical shift ++} IntMotionVector; ++ ++typedef struct { ++ double x; ///< Horizontal shift ++ double y; ///< Vertical shift ++} MotionVector; ++ ++typedef struct { ++ MotionVector vector; ///< Motion vector ++ double angle; ///< Angle of rotation ++ double zoom; ///< Zoom percentage ++} Transform; ++ ++typedef struct { ++ AVClass av_class; ++ AVFilterBufferRef *ref; ///< Previous frame ++ int rx; ///< Maximum horizontal shift ++ int ry; ///< Maximum vertical shift ++ enum FillMethod edge; ///< Edge fill method ++ int blocksize; ///< Size of blocks to compare ++ int contrast; ///< Contrast threshold ++ enum SearchMethod search; ///< Motion search method ++ AVCodecContext *avctx; ++ DSPContext c; ///< Context providing optimized SAD methods ++ Transform last; ///< Transform from last frame ++ int refcount; ///< Number of reference frames (defines averaging window) ++ FILE *fp; ++ Transform avg; ++ int cw; ///< Crop motion search to this box ++ int ch; ++ int cx; ++ int cy; ++} DeshakeContext; ++ ++static int cmp(const double *a, const double *b) ++{ ++ return *a < *b ? -1 : ( *a > *b ? 1 : 0 ); ++} ++ ++/** ++ * Cleaned mean (cuts off 20% of values to remove outliers and then averages) ++ */ ++static double clean_mean(double *values, int count) ++{ ++ double mean = 0; ++ int cut = count / 5; ++ int x; ++ ++ qsort(values, count, sizeof(double), (void*)cmp); ++ ++ for (x = cut; x < count - cut; x++) { ++ mean += values[x]; ++ } ++ ++ return mean / (count - cut * 2); ++} ++ ++/** ++ * Find the most likely shift in motion between two frames for a given ++ * macroblock. Test each block against several shifts given by the rx ++ * and ry attributes. Searches using a simple matrix of those shifts and ++ * chooses the most likely shift by the smallest difference in blocks. ++ */ ++static void find_block_motion(DeshakeContext *deshake, uint8_t *src1, ++ uint8_t *src2, int cx, int cy, int stride, ++ IntMotionVector *mv) ++{ ++ int x, y; ++ int diff; ++ int smallest = INT_MAX; ++ int tmp, tmp2; ++ ++ #define CMP(i, j) deshake->c.sad[0](deshake, src1 + cy * stride + cx, \ ++ src2 + (j) * stride + (i), stride, \ ++ deshake->blocksize) ++ ++ if (deshake->search == EXHAUSTIVE) { ++ // Compare every possible position - this is sloooow! ++ for (y = -deshake->ry; y <= deshake->ry; y++) { ++ for (x = -deshake->rx; x <= deshake->rx; x++) { ++ diff = CMP(cx - x, cy - y); ++ if (diff < smallest) { ++ smallest = diff; ++ mv->x = x; ++ mv->y = y; ++ } ++ } ++ } ++ } else if (deshake->search == SMART_EXHAUSTIVE) { ++ // Compare every other possible position and find the best match ++ for (y = -deshake->ry + 1; y < deshake->ry - 2; y += 2) { ++ for (x = -deshake->rx + 1; x < deshake->rx - 2; x += 2) { ++ diff = CMP(cx - x, cy - y); ++ if (diff < smallest) { ++ smallest = diff; ++ mv->x = x; ++ mv->y = y; ++ } ++ } ++ } ++ ++ // Hone in on the specific best match around the match we found above ++ tmp = mv->x; ++ tmp2 = mv->y; ++ ++ for (y = tmp2 - 1; y <= tmp2 + 1; y++) { ++ for (x = tmp - 1; x <= tmp + 1; x++) { ++ if (x == tmp && y == tmp2) ++ continue; ++ ++ diff = CMP(cx - x, cy - y); ++ if (diff < smallest) { ++ smallest = diff; ++ mv->x = x; ++ mv->y = y; ++ } ++ } ++ } ++ } ++ ++ if (smallest > 512) { ++ mv->x = -1; ++ mv->y = -1; ++ } ++ emms_c(); ++ //av_log(NULL, AV_LOG_ERROR, "%d\n", smallest); ++ //av_log(NULL, AV_LOG_ERROR, "Final: (%d, %d) = %d x %d\n", cx, cy, mv->x, mv->y); ++} ++ ++/** ++ * Find the contrast of a given block. When searching for global motion we ++ * really only care about the high contrast blocks, so using this method we ++ * can actually skip blocks we don't care much about. ++ */ ++static int block_contrast(uint8_t *src, int x, int y, int stride, int blocksize) ++{ ++ int highest = 0; ++ int lowest = 0; ++ int i, j, pos; ++ ++ for (i = 0; i <= blocksize * 2; i++) { ++ // We use a width of 16 here to match the libavcodec sad functions ++ for (j = 0; i <= 15; i++) { ++ pos = (y - i) * stride + (x - j); ++ if (src[pos] < lowest) ++ lowest = src[pos]; ++ else if (src[pos] > highest) { ++ highest = src[pos]; ++ } ++ } ++ } ++ ++ return highest - lowest; ++} ++ ++/** ++ * Find the rotation for a given block. ++ */ ++static double block_angle(int x, int y, int cx, int cy, IntMotionVector *shift) ++{ ++ double a1, a2, diff; ++ ++ a1 = atan2(y - cy, x - cx); ++ a2 = atan2(y - cy + shift->y, x - cx + shift->x); ++ ++ diff = a2 - a1; ++ ++ return (diff > M_PI) ? diff - 2 * M_PI : ++ (diff < -M_PI) ? diff + 2 * M_PI : ++ diff; ++} ++ ++/** ++ * Find the estimated global motion for a scene given the most likely shift ++ * for each block in the frame. The global motion is estimated to be the ++ * same as the motion from most blocks in the frame, so if most blocks ++ * move one pixel to the right and two pixels down, this would yield a ++ * motion vector (1, -2). ++ */ ++static void find_motion(DeshakeContext *deshake, uint8_t *src1, uint8_t *src2, ++ int width, int height, int stride, Transform *t) ++{ ++ int x, y; ++ IntMotionVector mv = {0, 0}; ++ int counts[128][128]; ++ int count_max_value = 0; ++ int contrast; ++ ++ int pos; ++ double *angles = av_malloc(sizeof(*angles) * width * height / (16 * deshake->blocksize)); ++ int center_x = 0, center_y = 0; ++ double p_x, p_y; ++ ++ // Reset counts to zero ++ for (x = 0; x < deshake->rx * 2 + 1; x++) { ++ for (y = 0; y < deshake->ry * 2 + 1; y++) { ++ counts[x][y] = 0; ++ } ++ } ++ ++ pos = 0; ++ // Find motion for every block and store the motion vector in the counts ++ for (y = deshake->ry; y < height - deshake->ry - (deshake->blocksize * 2); y += deshake->blocksize * 2) { ++ // We use a width of 16 here to match the libavcodec sad functions ++ for (x = deshake->rx; x < width - deshake->rx - 16; x += 16) { ++ // If the contrast is too low, just skip this block as it probably ++ // won't be very useful to us. ++ contrast = block_contrast(src2, x, y, stride, deshake->blocksize); ++ if (contrast > deshake->contrast) { ++ //av_log(NULL, AV_LOG_ERROR, "%d\n", contrast); ++ find_block_motion(deshake, src1, src2, x, y, stride, &mv); ++ if (mv.x != -1 && mv.y != -1) { ++ counts[mv.x + deshake->rx][mv.y + deshake->ry] += 1; ++ if (x > deshake->rx && y > deshake->ry) ++ angles[pos++] = block_angle(x, y, 0, 0, &mv); ++ ++ center_x += mv.x; ++ center_y += mv.y; ++ } ++ } ++ } ++ } ++ ++ if (pos) { ++ center_x /= pos; ++ center_y /= pos; ++ t->angle = clean_mean(angles, pos); ++ if (t->angle < 0.001) ++ t->angle = 0; ++ } else { ++ t->angle = 0; ++ } ++ ++ // Find the most common motion vector in the frame and use it as the gmv ++ for (y = deshake->ry * 2; y >= 0; y--) { ++ for (x = 0; x < deshake->rx * 2 + 1; x++) { ++ //av_log(NULL, AV_LOG_ERROR, "%5d ", counts[x][y]); ++ if (counts[x][y] > count_max_value) { ++ t->vector.x = x - deshake->rx; ++ t->vector.y = y - deshake->ry; ++ count_max_value = counts[x][y]; ++ } ++ } ++ //av_log(NULL, AV_LOG_ERROR, "\n"); ++ } ++ ++ p_x = (center_x - width / 2); ++ p_y = (center_y - height / 2); ++ t->vector.x += (cos(t->angle)-1)*p_x - sin(t->angle)*p_y; ++ t->vector.y += sin(t->angle)*p_x + (cos(t->angle)-1)*p_y; ++ ++ // Clamp max shift & rotation? ++ t->vector.x = av_clipf(t->vector.x, -deshake->rx * 2, deshake->rx * 2); ++ t->vector.y = av_clipf(t->vector.y, -deshake->ry * 2, deshake->ry * 2); ++ t->angle = av_clipf(t->angle, -0.1, 0.1); ++ ++ //av_log(NULL, AV_LOG_ERROR, "%d x %d\n", avg->x, avg->y); ++ av_free(angles); ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ DeshakeContext *deshake = ctx->priv; ++ char filename[256] = {0}; ++ ++ deshake->rx = 16; ++ deshake->ry = 16; ++ deshake->edge = FILL_MIRROR; ++ deshake->blocksize = 8; ++ deshake->contrast = 125; ++ deshake->search = EXHAUSTIVE; ++ deshake->refcount = 20; ++ ++ deshake->cw = -1; ++ deshake->ch = -1; ++ deshake->cx = -1; ++ deshake->cy = -1; ++ ++ if (args) { ++ sscanf(args, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%255s", ++ &deshake->cx, &deshake->cy, &deshake->cw, &deshake->ch, ++ &deshake->rx, &deshake->ry, (int *)&deshake->edge, ++ &deshake->blocksize, &deshake->contrast, (int *)&deshake->search, filename); ++ ++ deshake->blocksize /= 2; ++ ++ deshake->rx = av_clip(deshake->rx, 0, 64); ++ deshake->ry = av_clip(deshake->ry, 0, 64); ++ deshake->edge = av_clip(deshake->edge, FILL_BLANK, FILL_COUNT - 1); ++ deshake->blocksize = av_clip(deshake->blocksize, 4, 128); ++ deshake->contrast = av_clip(deshake->contrast, 1, 255); ++ deshake->search = av_clip(deshake->search, EXHAUSTIVE, SEARCH_COUNT - 1); ++ ++ } ++ if (*filename) ++ deshake->fp = fopen(filename, "w"); ++ if (deshake->fp) ++ fwrite("Ori x, Avg x, Fin x, Ori y, Avg y, Fin y, Ori angle, Avg angle, Fin angle, Ori zoom, Avg zoom, Fin zoom\n", sizeof(char), 104, deshake->fp); ++ ++ // Quadword align left edge of box for MMX code, adjust width if necessary ++ // to keep right margin ++ if (deshake->cx > 0) { ++ deshake->cw += deshake->cx - (deshake->cx & ~15); ++ deshake->cx &= ~15; ++ } ++ ++ av_log(ctx, AV_LOG_INFO, "cx: %d, cy: %d, cw: %d, ch: %d, rx: %d, ry: %d, edge: %d blocksize: %d contrast: %d search: %d\n", ++ deshake->cx, deshake->cy, deshake->cw, deshake->ch, ++ deshake->rx, deshake->ry, deshake->edge, deshake->blocksize * 2, deshake->contrast, deshake->search); ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, PIX_FMT_YUV410P, ++ PIX_FMT_YUV411P, PIX_FMT_YUV440P, PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, ++ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ440P, PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ ++ return 0; ++} ++ ++static int config_props(AVFilterLink *link) ++{ ++ DeshakeContext *deshake = link->dst->priv; ++ ++ deshake->ref = NULL; ++ deshake->last.vector.x = 0; ++ deshake->last.vector.y = 0; ++ deshake->last.angle = 0; ++ deshake->last.zoom = 0; ++ ++ deshake->avctx = avcodec_alloc_context3(NULL); ++ dsputil_init(&deshake->c, deshake->avctx); ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ DeshakeContext *deshake = ctx->priv; ++ ++ avfilter_unref_buffer(deshake->ref); ++ if (deshake->fp) ++ fclose(deshake->fp); ++} ++ ++static void end_frame(AVFilterLink *link) ++{ ++ DeshakeContext *deshake = link->dst->priv; ++ AVFilterBufferRef *in = link->cur_buf; ++ AVFilterBufferRef *out = link->dst->outputs[0]->out_buf; ++ Transform t = {{0},0}, orig = {{0},0}; ++ float matrix[9]; ++ float alpha = 2.0 / deshake->refcount; ++ char tmp[256]; ++ ++ if (deshake->cx < 0 || deshake->cy < 0 || deshake->cw < 0 || deshake->ch < 0) { ++ // Find the most likely global motion for the current frame ++ find_motion(deshake, (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0], in->data[0], link->w, link->h, in->linesize[0], &t); ++ } else { ++ uint8_t *src1 = (deshake->ref == NULL) ? in->data[0] : deshake->ref->data[0]; ++ uint8_t *src2 = in->data[0]; ++ ++ deshake->cx = FFMIN(deshake->cx, link->w); ++ deshake->cy = FFMIN(deshake->cy, link->h); ++ ++ if ((unsigned)deshake->cx + (unsigned)deshake->cw > link->w) deshake->cw = link->w - deshake->cx; ++ if ((unsigned)deshake->cy + (unsigned)deshake->ch > link->h) deshake->ch = link->h - deshake->cy; ++ ++ // Quadword align right margin ++ deshake->cw &= ~15; ++ ++ src1 += deshake->cy * in->linesize[0] + deshake->cx; ++ src2 += deshake->cy * in->linesize[0] + deshake->cx; ++ ++ find_motion(deshake, src1, src2, deshake->cw, deshake->ch, in->linesize[0], &t); ++ } ++ ++ ++ // Copy transform so we can output it later to compare to the smoothed value ++ orig.vector.x = t.vector.x; ++ orig.vector.y = t.vector.y; ++ orig.angle = t.angle; ++ orig.zoom = t.zoom; ++ ++ // Generate a one-sided moving exponential average ++ deshake->avg.vector.x = alpha * t.vector.x + (1.0 - alpha) * deshake->avg.vector.x; ++ deshake->avg.vector.y = alpha * t.vector.y + (1.0 - alpha) * deshake->avg.vector.y; ++ deshake->avg.angle = alpha * t.angle + (1.0 - alpha) * deshake->avg.angle; ++ deshake->avg.zoom = alpha * t.zoom + (1.0 - alpha) * deshake->avg.zoom; ++ ++ // Remove the average from the current motion to detect the motion that ++ // is not on purpose, just as jitter from bumping the camera ++ t.vector.x -= deshake->avg.vector.x; ++ t.vector.y -= deshake->avg.vector.y; ++ t.angle -= deshake->avg.angle; ++ t.zoom -= deshake->avg.zoom; ++ ++ // Invert the motion to undo it ++ t.vector.x *= -1; ++ t.vector.y *= -1; ++ t.angle *= -1; ++ ++ // Write statistics to file ++ if (deshake->fp) { ++ snprintf(tmp, 256, "%f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f\n", orig.vector.x, deshake->avg.vector.x, t.vector.x, orig.vector.y, deshake->avg.vector.y, t.vector.y, orig.angle, deshake->avg.angle, t.angle, orig.zoom, deshake->avg.zoom, t.zoom); ++ fwrite(tmp, sizeof(char), strlen(tmp), deshake->fp); ++ } ++ ++ // Turn relative current frame motion into absolute by adding it to the ++ // last absolute motion ++ t.vector.x += deshake->last.vector.x; ++ t.vector.y += deshake->last.vector.y; ++ t.angle += deshake->last.angle; ++ t.zoom += deshake->last.zoom; ++ ++ // Shrink motion by 10% to keep things centered in the camera frame ++ t.vector.x *= 0.9; ++ t.vector.y *= 0.9; ++ t.angle *= 0.9; ++ ++ // Store the last absolute motion information ++ deshake->last.vector.x = t.vector.x; ++ deshake->last.vector.y = t.vector.y; ++ deshake->last.angle = t.angle; ++ deshake->last.zoom = t.zoom; ++ ++ // Generate a luma transformation matrix ++ avfilter_get_matrix(t.vector.x, t.vector.y, t.angle, 1.0 + t.zoom / 100.0, matrix); ++ ++ // Transform the luma plane ++ avfilter_transform(in->data[0], out->data[0], in->linesize[0], out->linesize[0], link->w, link->h, matrix, INTERPOLATE_BILINEAR, deshake->edge); ++ ++ // Generate a chroma transformation matrix ++ avfilter_get_matrix(t.vector.x / (link->w / CHROMA_WIDTH(link)), t.vector.y / (link->h / CHROMA_HEIGHT(link)), t.angle, 1.0 + t.zoom / 100.0, matrix); ++ ++ // Transform the chroma planes ++ avfilter_transform(in->data[1], out->data[1], in->linesize[1], out->linesize[1], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), matrix, INTERPOLATE_BILINEAR, deshake->edge); ++ avfilter_transform(in->data[2], out->data[2], in->linesize[2], out->linesize[2], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), matrix, INTERPOLATE_BILINEAR, deshake->edge); ++ ++ // Store the current frame as the reference frame for calculating the ++ // motion of the next frame ++ if (deshake->ref != NULL) ++ avfilter_unref_buffer(deshake->ref); ++ ++ // Cleanup the old reference frame ++ deshake->ref = in; ++ ++ // Draw the transformed frame information ++ avfilter_draw_slice(link->dst->outputs[0], 0, link->h, 1); ++ avfilter_end_frame(link->dst->outputs[0]); ++ avfilter_unref_buffer(out); ++} ++ ++static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) ++{ ++} ++ ++AVFilter avfilter_vf_deshake = { ++ .name = "deshake", ++ .description = NULL_IF_CONFIG_SMALL("Stabilize shaky video."), ++ ++ .priv_size = sizeof(DeshakeContext), ++ ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame, ++ .config_props = config_props, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_drawbox.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_drawbox.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_drawbox.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_drawbox.c 2012-05-14 14:08:54.807349502 +0200 +@@ -26,7 +26,7 @@ + + #include "libavutil/colorspace.h" + #include "libavutil/pixdesc.h" +-#include "libavcore/parseutils.h" ++#include "libavutil/parseutils.h" + #include "avfilter.h" + + enum { Y, U, V, A }; +@@ -34,7 +34,7 @@ + typedef struct { + int x, y, w, h; + unsigned char yuv_color[4]; +- int vsub, hsub; //< chroma subsampling ++ int vsub, hsub; ///< chroma subsampling + } DrawBoxContext; + + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +@@ -70,7 +70,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -127,7 +127,7 @@ + .init = init, + + .query_formats = query_formats, +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .get_video_buffer = avfilter_null_get_video_buffer, +@@ -137,7 +137,7 @@ + .min_perms = AV_PERM_WRITE | AV_PERM_READ, + .rej_perms = AV_PERM_PRESERVE }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_drawtext.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_drawtext.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_drawtext.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_drawtext.c 2012-05-14 14:08:54.810349562 +0200 +@@ -0,0 +1,901 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * Copyright (c) 2010 S.N. Hemanth Meenakshisundaram ++ * Copyright (c) 2003 Gustavo Sverzut Barbieri ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * drawtext filter, based on the original vhook/drawtext.c ++ * filter by Gustavo Sverzut Barbieri ++ */ ++ ++#include ++#include ++ ++#include "config.h" ++#include "libavcodec/timecode.h" ++#include "libavutil/avstring.h" ++#include "libavutil/colorspace.h" ++#include "libavutil/file.h" ++#include "libavutil/eval.h" ++#include "libavutil/opt.h" ++#include "libavutil/random_seed.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "libavutil/tree.h" ++#include "libavutil/lfg.h" ++#include "avfilter.h" ++#include "drawutils.h" ++ ++#undef time ++ ++#include ++#include ++#include FT_FREETYPE_H ++#include FT_GLYPH_H ++ ++static const char * const var_names[] = { ++ "main_w", "w", "W", ///< width of the input video ++ "main_h", "h", "H", ///< height of the input video ++ "tw", "text_w", ///< width of the rendered text ++ "th", "text_h", ///< height of the rendered text ++ "max_glyph_w", ///< max glyph width ++ "max_glyph_h", ///< max glyph height ++ "max_glyph_a", "ascent", ///< max glyph ascent ++ "max_glyph_d", "descent", ///< min glyph descent ++ "line_h", "lh", ///< line height, same as max_glyph_h ++ "sar", ++ "dar", ++ "hsub", ++ "vsub", ++ "x", ++ "y", ++ "n", ///< number of frame ++ "t", ///< timestamp expressed in seconds ++ NULL ++}; ++ ++static const char *fun2_names[] = { ++ "rand", ++}; ++ ++static double drand(void *opaque, double min, double max) ++{ ++ return min + (max-min) / UINT_MAX * av_lfg_get(opaque); ++} ++ ++typedef double (*eval_func2)(void *, double a, double b); ++ ++static const eval_func2 fun2[] = { ++ drand, ++ NULL ++}; ++ ++enum var_name { ++ VAR_MAIN_W, VAR_w, VAR_W, ++ VAR_MAIN_H, VAR_h, VAR_H, ++ VAR_TW, VAR_TEXT_W, ++ VAR_TH, VAR_TEXT_H, ++ VAR_MAX_GLYPH_W, ++ VAR_MAX_GLYPH_H, ++ VAR_MAX_GLYPH_A, VAR_ASCENT, ++ VAR_MAX_GLYPH_D, VAR_DESCENT, ++ VAR_LINE_H, VAR_LH, ++ VAR_SAR, ++ VAR_DAR, ++ VAR_HSUB, ++ VAR_VSUB, ++ VAR_X, ++ VAR_Y, ++ VAR_N, ++ VAR_T, ++ VAR_VARS_NB ++}; ++ ++typedef struct { ++ const AVClass *class; ++ int reinit; ///< tells if the filter is being reinited ++ uint8_t *fontfile; ///< font to be used ++ uint8_t *text; ///< text to be drawn ++ uint8_t *expanded_text; ///< used to contain the strftime()-expanded text ++ size_t expanded_text_size; ///< size in bytes of the expanded_text buffer ++ int ft_load_flags; ///< flags used for loading fonts, see FT_LOAD_* ++ FT_Vector *positions; ///< positions for each element in the text ++ size_t nb_positions; ///< number of elements of positions array ++ char *textfile; ///< file with text to be drawn ++ int x; ///< x position to start drawing text ++ int y; ///< y position to start drawing text ++ int max_glyph_w; ///< max glyph width ++ int max_glyph_h; ///< max glyph heigth ++ int shadowx, shadowy; ++ unsigned int fontsize; ///< font size to use ++ char *fontcolor_string; ///< font color as string ++ char *boxcolor_string; ///< box color as string ++ char *shadowcolor_string; ///< shadow color as string ++ uint8_t fontcolor[4]; ///< foreground color ++ uint8_t boxcolor[4]; ///< background color ++ uint8_t shadowcolor[4]; ///< shadow color ++ uint8_t fontcolor_rgba[4]; ///< foreground color in RGBA ++ uint8_t boxcolor_rgba[4]; ///< background color in RGBA ++ uint8_t shadowcolor_rgba[4]; ///< shadow color in RGBA ++ ++ short int draw_box; ///< draw box around text - true or false ++ int use_kerning; ///< font kerning is used - true/false ++ int tabsize; ///< tab size ++ ++ FT_Library library; ///< freetype font library handle ++ FT_Face face; ///< freetype font face handle ++ struct AVTreeNode *glyphs; ///< rendered glyphs, stored using the UTF-32 char code ++ int hsub, vsub; ///< chroma subsampling values ++ int is_packed_rgb; ++ int pixel_step[4]; ///< distance in bytes between the component of each pixel ++ uint8_t rgba_map[4]; ///< map RGBA offsets to the positions in the packed RGBA format ++ uint8_t *box_line[4]; ///< line used for filling the box background ++ char *x_expr; ///< expression for x position ++ char *y_expr; ///< expression for y position ++ AVExpr *x_pexpr, *y_pexpr; ///< parsed expressions for x and y ++ int64_t basetime; ///< base pts time in the real world for display ++ double var_values[VAR_VARS_NB]; ++ char *d_expr; ++ AVExpr *d_pexpr; ++ int draw; ///< set to zero to prevent drawing ++ AVLFG prng; ///< random ++ struct ff_timecode tc; ++ int frame_id; ++} DrawTextContext; ++ ++#define OFFSET(x) offsetof(DrawTextContext, x) ++ ++static const AVOption drawtext_options[]= { ++{"fontfile", "set font file", OFFSET(fontfile), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, ++{"text", "set text", OFFSET(text), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, ++{"textfile", "set text file", OFFSET(textfile), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, ++{"fontcolor", "set foreground color", OFFSET(fontcolor_string), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX }, ++{"boxcolor", "set box color", OFFSET(boxcolor_string), AV_OPT_TYPE_STRING, {.str="white"}, CHAR_MIN, CHAR_MAX }, ++{"shadowcolor", "set shadow color", OFFSET(shadowcolor_string), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX }, ++{"box", "set box", OFFSET(draw_box), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1 }, ++{"fontsize", "set font size", OFFSET(fontsize), AV_OPT_TYPE_INT, {.dbl=16}, 1, INT_MAX }, ++{"x", "set x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX }, ++{"y", "set y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str="0"}, CHAR_MIN, CHAR_MAX }, ++{"shadowx", "set x", OFFSET(shadowx), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, ++{"shadowy", "set y", OFFSET(shadowy), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, ++{"tabsize", "set tab size", OFFSET(tabsize), AV_OPT_TYPE_INT, {.dbl=4}, 0, INT_MAX }, ++{"basetime", "set base time", OFFSET(basetime), AV_OPT_TYPE_INT64, {.dbl=AV_NOPTS_VALUE}, INT64_MIN, INT64_MAX }, ++{"draw", "if false do not draw", OFFSET(d_expr), AV_OPT_TYPE_STRING, {.str="1"}, CHAR_MIN, CHAR_MAX }, ++{"timecode", "set initial timecode", OFFSET(tc.str), AV_OPT_TYPE_STRING, {.str=NULL}, CHAR_MIN, CHAR_MAX }, ++{"r", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, ++{"rate", "set rate (timecode only)", OFFSET(tc.rate), AV_OPT_TYPE_RATIONAL, {.dbl=0}, 0, INT_MAX }, ++ ++/* FT_LOAD_* flags */ ++{"ft_load_flags", "set font loading flags for libfreetype", OFFSET(ft_load_flags), AV_OPT_TYPE_FLAGS, {.dbl=FT_LOAD_DEFAULT|FT_LOAD_RENDER}, 0, INT_MAX, 0, "ft_load_flags" }, ++{"default", "set default", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_DEFAULT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"no_scale", "set no_scale", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_SCALE}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"no_hinting", "set no_hinting", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_HINTING}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"render", "set render", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_RENDER}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"no_bitmap", "set no_bitmap", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"vertical_layout", "set vertical_layout", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_VERTICAL_LAYOUT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"force_autohint", "set force_autohint", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_FORCE_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"crop_bitmap", "set crop_bitmap", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_CROP_BITMAP}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"pedantic", "set pedantic", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_PEDANTIC}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"ignore_global_advance_width", "set ignore_global_advance_width", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"no_recurse", "set no_recurse", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_RECURSE}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"ignore_transform", "set ignore_transform", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_IGNORE_TRANSFORM}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"monochrome", "set monochrome", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_MONOCHROME}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"linear_design", "set linear_design", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_LINEAR_DESIGN}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{"no_autohint", "set no_autohint", 0, AV_OPT_TYPE_CONST, {.dbl=FT_LOAD_NO_AUTOHINT}, INT_MIN, INT_MAX, 0, "ft_load_flags" }, ++{NULL}, ++}; ++ ++static const char *drawtext_get_name(void *ctx) ++{ ++ return "drawtext"; ++} ++ ++static const AVClass drawtext_class = { ++ "DrawTextContext", ++ drawtext_get_name, ++ drawtext_options ++}; ++ ++#undef __FTERRORS_H__ ++#define FT_ERROR_START_LIST { ++#define FT_ERRORDEF(e, v, s) { (e), (s) }, ++#define FT_ERROR_END_LIST { 0, NULL } }; ++ ++struct ft_error ++{ ++ int err; ++ const char *err_msg; ++} static ft_errors[] = ++#include FT_ERRORS_H ++ ++#define FT_ERRMSG(e) ft_errors[e].err_msg ++ ++typedef struct { ++ FT_Glyph *glyph; ++ uint32_t code; ++ FT_Bitmap bitmap; ///< array holding bitmaps of font ++ FT_BBox bbox; ++ int advance; ++ int bitmap_left; ++ int bitmap_top; ++} Glyph; ++ ++static int glyph_cmp(void *key, const void *b) ++{ ++ const Glyph *a = key, *bb = b; ++ int64_t diff = (int64_t)a->code - (int64_t)bb->code; ++ return diff > 0 ? 1 : diff < 0 ? -1 : 0; ++} ++ ++/** ++ * Load glyphs corresponding to the UTF-32 codepoint code. ++ */ ++static int load_glyph(AVFilterContext *ctx, Glyph **glyph_ptr, uint32_t code) ++{ ++ DrawTextContext *dtext = ctx->priv; ++ Glyph *glyph; ++ struct AVTreeNode *node = NULL; ++ int ret; ++ ++ /* load glyph into dtext->face->glyph */ ++ if (FT_Load_Char(dtext->face, code, dtext->ft_load_flags)) ++ return AVERROR(EINVAL); ++ ++ /* save glyph */ ++ if (!(glyph = av_mallocz(sizeof(*glyph))) || ++ !(glyph->glyph = av_mallocz(sizeof(*glyph->glyph)))) { ++ ret = AVERROR(ENOMEM); ++ goto error; ++ } ++ glyph->code = code; ++ ++ if (FT_Get_Glyph(dtext->face->glyph, glyph->glyph)) { ++ ret = AVERROR(EINVAL); ++ goto error; ++ } ++ ++ glyph->bitmap = dtext->face->glyph->bitmap; ++ glyph->bitmap_left = dtext->face->glyph->bitmap_left; ++ glyph->bitmap_top = dtext->face->glyph->bitmap_top; ++ glyph->advance = dtext->face->glyph->advance.x >> 6; ++ ++ /* measure text height to calculate text_height (or the maximum text height) */ ++ FT_Glyph_Get_CBox(*glyph->glyph, ft_glyph_bbox_pixels, &glyph->bbox); ++ ++ /* cache the newly created glyph */ ++ if (!(node = av_mallocz(av_tree_node_size))) { ++ ret = AVERROR(ENOMEM); ++ goto error; ++ } ++ av_tree_insert(&dtext->glyphs, glyph, glyph_cmp, &node); ++ ++ if (glyph_ptr) ++ *glyph_ptr = glyph; ++ return 0; ++ ++error: ++ if (glyph) ++ av_freep(&glyph->glyph); ++ av_freep(&glyph); ++ av_freep(&node); ++ return ret; ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ int err; ++ DrawTextContext *dtext = ctx->priv; ++ Glyph *glyph; ++ ++ dtext->class = &drawtext_class; ++ av_opt_set_defaults(dtext); ++ ++ if ((err = (av_set_options_string(dtext, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return err; ++ } ++ ++ if (!dtext->fontfile) { ++ av_log(ctx, AV_LOG_ERROR, "No font filename provided\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (dtext->textfile) { ++ uint8_t *textbuf; ++ size_t textbuf_size; ++ ++ if (dtext->text) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Both text and text file provided. Please provide only one\n"); ++ return AVERROR(EINVAL); ++ } ++ if ((err = av_file_map(dtext->textfile, &textbuf, &textbuf_size, 0, ctx)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "The text file '%s' could not be read or is empty\n", ++ dtext->textfile); ++ return err; ++ } ++ ++ if (!(dtext->text = av_malloc(textbuf_size+1))) ++ return AVERROR(ENOMEM); ++ memcpy(dtext->text, textbuf, textbuf_size); ++ dtext->text[textbuf_size] = 0; ++ av_file_unmap(textbuf, textbuf_size); ++ } ++ ++ if (dtext->tc.str) { ++#if CONFIG_AVCODEC ++ if (avpriv_init_smpte_timecode(ctx, &dtext->tc) < 0) ++ return AVERROR(EINVAL); ++ if (!dtext->text) ++ dtext->text = av_strdup(""); ++#else ++ av_log(ctx, AV_LOG_ERROR, ++ "Timecode options are only available if libavfilter is built with libavcodec enabled.\n"); ++ return AVERROR(EINVAL); ++#endif ++ } ++ ++ if (!dtext->text) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Either text, a valid file or a timecode must be provided\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if ((err = av_parse_color(dtext->fontcolor_rgba, dtext->fontcolor_string, -1, ctx))) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid font color '%s'\n", dtext->fontcolor_string); ++ return err; ++ } ++ ++ if ((err = av_parse_color(dtext->boxcolor_rgba, dtext->boxcolor_string, -1, ctx))) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid box color '%s'\n", dtext->boxcolor_string); ++ return err; ++ } ++ ++ if ((err = av_parse_color(dtext->shadowcolor_rgba, dtext->shadowcolor_string, -1, ctx))) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid shadow color '%s'\n", dtext->shadowcolor_string); ++ return err; ++ } ++ ++ if ((err = FT_Init_FreeType(&(dtext->library)))) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Could not load FreeType: %s\n", FT_ERRMSG(err)); ++ return AVERROR(EINVAL); ++ } ++ ++ /* load the face, and set up the encoding, which is by default UTF-8 */ ++ if ((err = FT_New_Face(dtext->library, dtext->fontfile, 0, &dtext->face))) { ++ av_log(ctx, AV_LOG_ERROR, "Could not load fontface from file '%s': %s\n", ++ dtext->fontfile, FT_ERRMSG(err)); ++ return AVERROR(EINVAL); ++ } ++ if ((err = FT_Set_Pixel_Sizes(dtext->face, 0, dtext->fontsize))) { ++ av_log(ctx, AV_LOG_ERROR, "Could not set font size to %d pixels: %s\n", ++ dtext->fontsize, FT_ERRMSG(err)); ++ return AVERROR(EINVAL); ++ } ++ ++ dtext->use_kerning = FT_HAS_KERNING(dtext->face); ++ ++ /* load the fallback glyph with code 0 */ ++ load_glyph(ctx, NULL, 0); ++ ++ /* set the tabsize in pixels */ ++ if ((err = load_glyph(ctx, &glyph, ' ')) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Could not set tabsize.\n"); ++ return err; ++ } ++ dtext->tabsize *= glyph->advance; ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_ARGB, PIX_FMT_RGBA, ++ PIX_FMT_ABGR, PIX_FMT_BGRA, ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ PIX_FMT_YUV420P, PIX_FMT_YUV444P, ++ PIX_FMT_YUV422P, PIX_FMT_YUV411P, ++ PIX_FMT_YUV410P, PIX_FMT_YUV440P, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int glyph_enu_free(void *opaque, void *elem) ++{ ++ av_free(elem); ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ DrawTextContext *dtext = ctx->priv; ++ int i; ++ ++ av_expr_free(dtext->x_pexpr); dtext->x_pexpr = NULL; ++ av_expr_free(dtext->y_pexpr); dtext->y_pexpr = NULL; ++ ++ av_freep(&dtext->boxcolor_string); ++ av_freep(&dtext->expanded_text); ++ av_freep(&dtext->fontcolor_string); ++ av_freep(&dtext->fontfile); ++ av_freep(&dtext->shadowcolor_string); ++ av_freep(&dtext->text); ++ av_freep(&dtext->x_expr); ++ av_freep(&dtext->y_expr); ++ ++ av_freep(&dtext->positions); ++ dtext->nb_positions = 0; ++ ++ av_tree_enumerate(dtext->glyphs, NULL, NULL, glyph_enu_free); ++ av_tree_destroy(dtext->glyphs); ++ dtext->glyphs = NULL; ++ ++ FT_Done_Face(dtext->face); ++ FT_Done_FreeType(dtext->library); ++ ++ for (i = 0; i < 4; i++) { ++ av_freep(&dtext->box_line[i]); ++ dtext->pixel_step[i] = 0; ++ } ++} ++ ++static inline int is_newline(uint32_t c) ++{ ++ return c == '\n' || c == '\r' || c == '\f' || c == '\v'; ++} ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ DrawTextContext *dtext = ctx->priv; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; ++ int ret; ++ ++ dtext->hsub = pix_desc->log2_chroma_w; ++ dtext->vsub = pix_desc->log2_chroma_h; ++ ++ if ((ret = ++ ff_fill_line_with_color(dtext->box_line, dtext->pixel_step, ++ inlink->w, dtext->boxcolor, ++ inlink->format, dtext->boxcolor_rgba, ++ &dtext->is_packed_rgb, dtext->rgba_map)) < 0) ++ return ret; ++ ++ if (!dtext->is_packed_rgb) { ++ uint8_t *rgba = dtext->fontcolor_rgba; ++ dtext->fontcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); ++ dtext->fontcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); ++ dtext->fontcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); ++ dtext->fontcolor[3] = rgba[3]; ++ rgba = dtext->shadowcolor_rgba; ++ dtext->shadowcolor[0] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]); ++ dtext->shadowcolor[1] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0); ++ dtext->shadowcolor[2] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0); ++ dtext->shadowcolor[3] = rgba[3]; ++ } ++ ++ dtext->var_values[VAR_w] = dtext->var_values[VAR_W] = dtext->var_values[VAR_MAIN_W] = inlink->w; ++ dtext->var_values[VAR_h] = dtext->var_values[VAR_H] = dtext->var_values[VAR_MAIN_H] = inlink->h; ++ dtext->var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1; ++ dtext->var_values[VAR_DAR] = (double)inlink->w / inlink->h * dtext->var_values[VAR_SAR]; ++ dtext->var_values[VAR_HSUB] = 1<log2_chroma_w; ++ dtext->var_values[VAR_VSUB] = 1<log2_chroma_h; ++ dtext->var_values[VAR_X] = NAN; ++ dtext->var_values[VAR_Y] = NAN; ++ if (!dtext->reinit) ++ dtext->var_values[VAR_N] = 0; ++ dtext->var_values[VAR_T] = NAN; ++ ++ av_lfg_init(&dtext->prng, av_get_random_seed()); ++ ++ if ((ret = av_expr_parse(&dtext->x_pexpr, dtext->x_expr, var_names, ++ NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || ++ (ret = av_expr_parse(&dtext->y_pexpr, dtext->y_expr, var_names, ++ NULL, NULL, fun2_names, fun2, 0, ctx)) < 0 || ++ (ret = av_expr_parse(&dtext->d_pexpr, dtext->d_expr, var_names, ++ NULL, NULL, fun2_names, fun2, 0, ctx)) < 0) ++ ++ return AVERROR(EINVAL); ++ ++ return 0; ++} ++ ++static int command(AVFilterContext *ctx, const char *cmd, const char *arg, char *res, int res_len, int flags) ++{ ++ DrawTextContext *dtext = ctx->priv; ++ ++ if (!strcmp(cmd, "reinit")) { ++ int ret; ++ uninit(ctx); ++ dtext->reinit = 1; ++ if ((ret = init(ctx, arg, NULL)) < 0) ++ return ret; ++ return config_input(ctx->inputs[0]); ++ } ++ ++ return AVERROR(ENOSYS); ++} ++ ++#define GET_BITMAP_VAL(r, c) \ ++ bitmap->pixel_mode == FT_PIXEL_MODE_MONO ? \ ++ (bitmap->buffer[(r) * bitmap->pitch + ((c)>>3)] & (0x80 >> ((c)&7))) * 255 : \ ++ bitmap->buffer[(r) * bitmap->pitch + (c)] ++ ++#define SET_PIXEL_YUV(picref, yuva_color, val, x, y, hsub, vsub) { \ ++ luma_pos = ((x) ) + ((y) ) * picref->linesize[0]; \ ++ alpha = yuva_color[3] * (val) * 129; \ ++ picref->data[0][luma_pos] = (alpha * yuva_color[0] + (255*255*129 - alpha) * picref->data[0][luma_pos] ) >> 23; \ ++ if (((x) & ((1<<(hsub)) - 1)) == 0 && ((y) & ((1<<(vsub)) - 1)) == 0) {\ ++ chroma_pos1 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[1]; \ ++ chroma_pos2 = ((x) >> (hsub)) + ((y) >> (vsub)) * picref->linesize[2]; \ ++ picref->data[1][chroma_pos1] = (alpha * yuva_color[1] + (255*255*129 - alpha) * picref->data[1][chroma_pos1]) >> 23; \ ++ picref->data[2][chroma_pos2] = (alpha * yuva_color[2] + (255*255*129 - alpha) * picref->data[2][chroma_pos2]) >> 23; \ ++ }\ ++} ++ ++static inline int draw_glyph_yuv(AVFilterBufferRef *picref, FT_Bitmap *bitmap, ++ int x, int y, int width, int height, ++ const uint8_t yuva_color[4], int hsub, int vsub) ++{ ++ int r, c, alpha; ++ unsigned int luma_pos, chroma_pos1, chroma_pos2; ++ uint8_t src_val; ++ ++ for (r = 0; r < bitmap->rows && r+y < height; r++) { ++ for (c = 0; c < bitmap->width && c+x < width; c++) { ++ if (c+x < 0 || r+y < 0) ++ continue; ++ ++ /* get intensity value in the glyph bitmap (source) */ ++ src_val = GET_BITMAP_VAL(r, c); ++ if (!src_val) ++ continue; ++ ++ SET_PIXEL_YUV(picref, yuva_color, src_val, c+x, y+r, hsub, vsub); ++ } ++ } ++ ++ return 0; ++} ++ ++#define SET_PIXEL_RGB(picref, rgba_color, val, x, y, pixel_step, r_off, g_off, b_off, a_off) { \ ++ p = picref->data[0] + (x) * pixel_step + ((y) * picref->linesize[0]); \ ++ alpha = rgba_color[3] * (val) * 129; \ ++ *(p+r_off) = (alpha * rgba_color[0] + (255*255*129 - alpha) * *(p+r_off)) >> 23; \ ++ *(p+g_off) = (alpha * rgba_color[1] + (255*255*129 - alpha) * *(p+g_off)) >> 23; \ ++ *(p+b_off) = (alpha * rgba_color[2] + (255*255*129 - alpha) * *(p+b_off)) >> 23; \ ++} ++ ++static inline int draw_glyph_rgb(AVFilterBufferRef *picref, FT_Bitmap *bitmap, ++ int x, int y, int width, int height, int pixel_step, ++ const uint8_t rgba_color[4], const uint8_t rgba_map[4]) ++{ ++ int r, c, alpha; ++ uint8_t *p; ++ uint8_t src_val; ++ ++ for (r = 0; r < bitmap->rows && r+y < height; r++) { ++ for (c = 0; c < bitmap->width && c+x < width; c++) { ++ if (c+x < 0 || r+y < 0) ++ continue; ++ /* get intensity value in the glyph bitmap (source) */ ++ src_val = GET_BITMAP_VAL(r, c); ++ if (!src_val) ++ continue; ++ ++ SET_PIXEL_RGB(picref, rgba_color, src_val, c+x, y+r, pixel_step, ++ rgba_map[0], rgba_map[1], rgba_map[2], rgba_map[3]); ++ } ++ } ++ ++ return 0; ++} ++ ++static inline void drawbox(AVFilterBufferRef *picref, int x, int y, ++ int width, int height, ++ uint8_t *line[4], int pixel_step[4], uint8_t color[4], ++ int hsub, int vsub, int is_rgba_packed, uint8_t rgba_map[4]) ++{ ++ int i, j, alpha; ++ ++ if (color[3] != 0xFF) { ++ if (is_rgba_packed) { ++ uint8_t *p; ++ for (j = 0; j < height; j++) ++ for (i = 0; i < width; i++) ++ SET_PIXEL_RGB(picref, color, 255, i+x, y+j, pixel_step[0], ++ rgba_map[0], rgba_map[1], rgba_map[2], rgba_map[3]); ++ } else { ++ unsigned int luma_pos, chroma_pos1, chroma_pos2; ++ for (j = 0; j < height; j++) ++ for (i = 0; i < width; i++) ++ SET_PIXEL_YUV(picref, color, 255, i+x, y+j, hsub, vsub); ++ } ++ } else { ++ ff_draw_rectangle(picref->data, picref->linesize, ++ line, pixel_step, hsub, vsub, ++ x, y, width, height); ++ } ++} ++ ++static int draw_glyphs(DrawTextContext *dtext, AVFilterBufferRef *picref, ++ int width, int height, const uint8_t rgbcolor[4], const uint8_t yuvcolor[4], int x, int y) ++{ ++ char *text = dtext->expanded_text; ++ uint32_t code = 0; ++ int i, x1, y1; ++ uint8_t *p; ++ Glyph *glyph = NULL; ++ ++ for (i = 0, p = text; *p; i++) { ++ Glyph dummy = { 0 }; ++ GET_UTF8(code, *p++, continue;); ++ ++ /* skip new line chars, just go to new line */ ++ if (code == '\n' || code == '\r' || code == '\t') ++ continue; ++ ++ dummy.code = code; ++ glyph = av_tree_find(dtext->glyphs, &dummy, (void *)glyph_cmp, NULL); ++ ++ if (glyph->bitmap.pixel_mode != FT_PIXEL_MODE_MONO && ++ glyph->bitmap.pixel_mode != FT_PIXEL_MODE_GRAY) ++ return AVERROR(EINVAL); ++ ++ x1 = dtext->positions[i].x+dtext->x+x; ++ y1 = dtext->positions[i].y+dtext->y+y; ++ ++ if (dtext->is_packed_rgb) { ++ draw_glyph_rgb(picref, &glyph->bitmap, ++ x1, y1, width, height, ++ dtext->pixel_step[0], rgbcolor, dtext->rgba_map); ++ } else { ++ draw_glyph_yuv(picref, &glyph->bitmap, ++ x1, y1, width, height, ++ yuvcolor, dtext->hsub, dtext->vsub); ++ } ++ } ++ ++ return 0; ++} ++ ++static int draw_text(AVFilterContext *ctx, AVFilterBufferRef *picref, ++ int width, int height) ++{ ++ DrawTextContext *dtext = ctx->priv; ++ uint32_t code = 0, prev_code = 0; ++ int x = 0, y = 0, i = 0, ret; ++ int max_text_line_w = 0, len; ++ int box_w, box_h; ++ char *text = dtext->text; ++ uint8_t *p; ++ int y_min = 32000, y_max = -32000; ++ int x_min = 32000, x_max = -32000; ++ FT_Vector delta; ++ Glyph *glyph = NULL, *prev_glyph = NULL; ++ Glyph dummy = { 0 }; ++ ++ time_t now = time(0); ++ struct tm ltime; ++ uint8_t *buf = dtext->expanded_text; ++ int buf_size = dtext->expanded_text_size; ++ ++ if(dtext->basetime != AV_NOPTS_VALUE) ++ now= picref->pts*av_q2d(ctx->inputs[0]->time_base) + dtext->basetime/1000000; ++ ++ if (!buf) { ++ buf_size = 2*strlen(dtext->text)+1; ++ buf = av_malloc(buf_size); ++ } ++ ++#if HAVE_LOCALTIME_R ++ localtime_r(&now, <ime); ++#else ++ if(strchr(dtext->text, '%')) ++ ltime= *localtime(&now); ++#endif ++ ++ do { ++ *buf = 1; ++ if (strftime(buf, buf_size, dtext->text, <ime) != 0 || *buf == 0) ++ break; ++ buf_size *= 2; ++ } while ((buf = av_realloc(buf, buf_size))); ++ ++#if CONFIG_AVCODEC ++ if (dtext->tc.str) { ++ char tcbuf[16]; ++ avpriv_timecode_to_string(tcbuf, &dtext->tc, dtext->frame_id++); ++ buf = av_asprintf("%s%s", dtext->text, tcbuf); ++ } ++#endif ++ ++ if (!buf) ++ return AVERROR(ENOMEM); ++ text = dtext->expanded_text = buf; ++ dtext->expanded_text_size = buf_size; ++ if ((len = strlen(text)) > dtext->nb_positions) { ++ if (!(dtext->positions = ++ av_realloc(dtext->positions, len*sizeof(*dtext->positions)))) ++ return AVERROR(ENOMEM); ++ dtext->nb_positions = len; ++ } ++ ++ x = 0; ++ y = 0; ++ ++ /* load and cache glyphs */ ++ for (i = 0, p = text; *p; i++) { ++ GET_UTF8(code, *p++, continue;); ++ ++ /* get glyph */ ++ dummy.code = code; ++ glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); ++ if (!glyph) ++ load_glyph(ctx, &glyph, code); ++ ++ y_min = FFMIN(glyph->bbox.yMin, y_min); ++ y_max = FFMAX(glyph->bbox.yMax, y_max); ++ x_min = FFMIN(glyph->bbox.xMin, x_min); ++ x_max = FFMAX(glyph->bbox.xMax, x_max); ++ } ++ dtext->max_glyph_h = y_max - y_min; ++ dtext->max_glyph_w = x_max - x_min; ++ ++ /* compute and save position for each glyph */ ++ glyph = NULL; ++ for (i = 0, p = text; *p; i++) { ++ GET_UTF8(code, *p++, continue;); ++ ++ /* skip the \n in the sequence \r\n */ ++ if (prev_code == '\r' && code == '\n') ++ continue; ++ ++ prev_code = code; ++ if (is_newline(code)) { ++ max_text_line_w = FFMAX(max_text_line_w, x); ++ y += dtext->max_glyph_h; ++ x = 0; ++ continue; ++ } ++ ++ /* get glyph */ ++ prev_glyph = glyph; ++ dummy.code = code; ++ glyph = av_tree_find(dtext->glyphs, &dummy, glyph_cmp, NULL); ++ ++ /* kerning */ ++ if (dtext->use_kerning && prev_glyph && glyph->code) { ++ FT_Get_Kerning(dtext->face, prev_glyph->code, glyph->code, ++ ft_kerning_default, &delta); ++ x += delta.x >> 6; ++ } ++ ++ /* save position */ ++ dtext->positions[i].x = x + glyph->bitmap_left; ++ dtext->positions[i].y = y - glyph->bitmap_top + y_max; ++ if (code == '\t') x = (x / dtext->tabsize + 1)*dtext->tabsize; ++ else x += glyph->advance; ++ } ++ ++ max_text_line_w = FFMAX(x, max_text_line_w); ++ ++ dtext->var_values[VAR_TW] = dtext->var_values[VAR_TEXT_W] = max_text_line_w; ++ dtext->var_values[VAR_TH] = dtext->var_values[VAR_TEXT_H] = y + dtext->max_glyph_h; ++ ++ dtext->var_values[VAR_MAX_GLYPH_W] = dtext->max_glyph_w; ++ dtext->var_values[VAR_MAX_GLYPH_H] = dtext->max_glyph_h; ++ dtext->var_values[VAR_MAX_GLYPH_A] = dtext->var_values[VAR_ASCENT ] = y_max; ++ dtext->var_values[VAR_MAX_GLYPH_D] = dtext->var_values[VAR_DESCENT] = y_min; ++ ++ dtext->var_values[VAR_LINE_H] = dtext->var_values[VAR_LH] = dtext->max_glyph_h; ++ ++ dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); ++ dtext->y = dtext->var_values[VAR_Y] = av_expr_eval(dtext->y_pexpr, dtext->var_values, &dtext->prng); ++ dtext->x = dtext->var_values[VAR_X] = av_expr_eval(dtext->x_pexpr, dtext->var_values, &dtext->prng); ++ dtext->draw = av_expr_eval(dtext->d_pexpr, dtext->var_values, &dtext->prng); ++ ++ if(!dtext->draw) ++ return 0; ++ ++ dtext->x &= ~((1 << dtext->hsub) - 1); ++ dtext->y &= ~((1 << dtext->vsub) - 1); ++ ++ box_w = FFMIN(width - 1 , max_text_line_w); ++ box_h = FFMIN(height - 1, y + dtext->max_glyph_h); ++ ++ /* draw box */ ++ if (dtext->draw_box) ++ drawbox(picref, dtext->x, dtext->y, box_w, box_h, ++ dtext->box_line, dtext->pixel_step, dtext->is_packed_rgb ? dtext->boxcolor_rgba : dtext->boxcolor, ++ dtext->hsub, dtext->vsub, dtext->is_packed_rgb, dtext->rgba_map); ++ ++ if (dtext->shadowx || dtext->shadowy) { ++ if ((ret = draw_glyphs(dtext, picref, width, height, dtext->shadowcolor_rgba, ++ dtext->shadowcolor, dtext->shadowx, dtext->shadowy)) < 0) ++ return ret; ++ } ++ ++ if ((ret = draw_glyphs(dtext, picref, width, height, dtext->fontcolor_rgba, ++ dtext->fontcolor, 0, 0)) < 0) ++ return ret; ++ ++ return 0; ++} ++ ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ DrawTextContext *dtext = ctx->priv; ++ AVFilterBufferRef *picref = inlink->cur_buf; ++ ++ dtext->var_values[VAR_T] = picref->pts == AV_NOPTS_VALUE ? ++ NAN : picref->pts * av_q2d(inlink->time_base); ++ ++ draw_text(ctx, picref, picref->video->w, picref->video->h); ++ ++ av_log(ctx, AV_LOG_DEBUG, "n:%d t:%f text_w:%d text_h:%d x:%d y:%d\n", ++ (int)dtext->var_values[VAR_N], dtext->var_values[VAR_T], ++ (int)dtext->var_values[VAR_TEXT_W], (int)dtext->var_values[VAR_TEXT_H], ++ dtext->x, dtext->y); ++ ++ dtext->var_values[VAR_N] += 1.0; ++ ++ avfilter_draw_slice(outlink, 0, picref->video->h, 1); ++ avfilter_end_frame(outlink); ++} ++ ++AVFilter avfilter_vf_drawtext = { ++ .name = "drawtext", ++ .description = NULL_IF_CONFIG_SMALL("Draw text on top of video frames using libfreetype library."), ++ .priv_size = sizeof(DrawTextContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = avfilter_null_start_frame, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, ++ .config_props = config_input, ++ .min_perms = AV_PERM_WRITE | ++ AV_PERM_READ, ++ .rej_perms = AV_PERM_PRESERVE }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++ .process_command = command, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fade.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fade.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fade.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fade.c 2012-05-14 14:08:54.811349582 +0200 +@@ -0,0 +1,300 @@ ++/* ++ * Copyright (c) 2010 Brandon Mintern ++ * Copyright (c) 2007 Bobby Bingham ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * video fade filter ++ * based heavily on vf_negate.c by Bobby Bingham ++ */ ++ ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" ++#include "libavutil/opt.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++#include "drawutils.h" ++#include "internal.h" ++ ++#define R 0 ++#define G 1 ++#define B 2 ++#define A 3 ++ ++#define Y 0 ++#define U 1 ++#define V 2 ++ ++typedef struct { ++ const AVClass *class; ++ int factor, fade_per_frame; ++ unsigned int frame_index, start_frame, stop_frame, nb_frames; ++ int hsub, vsub, bpp; ++ unsigned int black_level, black_level_scaled; ++ uint8_t is_packed_rgb; ++ uint8_t rgba_map[4]; ++ int alpha; ++ ++ char *type; ++} FadeContext; ++ ++#define OFFSET(x) offsetof(FadeContext, x) ++ ++static const AVOption fade_options[] = { ++ { "type", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX }, ++ { "t", "set the fade direction", OFFSET(type), AV_OPT_TYPE_STRING, {.str = "in" }, CHAR_MIN, CHAR_MAX }, ++ { "start_frame", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX }, ++ { "s", "set expression of frame to start fading", OFFSET(start_frame), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, INT_MAX }, ++ { "nb_frames", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.dbl = 25 }, 0, INT_MAX }, ++ { "n", "set expression for fade duration in frames", OFFSET(nb_frames), AV_OPT_TYPE_INT, {.dbl = 25 }, 0, INT_MAX }, ++ { "alpha", "fade alpha if it is available on the input", OFFSET(alpha), AV_OPT_TYPE_INT, {.dbl = 0 }, 0, 1 }, ++ {NULL}, ++}; ++ ++static const char *fade_get_name(void *ctx) ++{ ++ return "fade"; ++} ++ ++static const AVClass fade_class = { ++ "FadeContext", ++ fade_get_name, ++ fade_options ++}; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ FadeContext *fade = ctx->priv; ++ int ret = 0; ++ char *args1, *expr, *bufptr = NULL; ++ ++ fade->class = &fade_class; ++ av_opt_set_defaults(fade); ++ ++ if (!(args1 = av_strdup(args))) { ++ ret = AVERROR(ENOMEM); ++ goto end; ++ } ++ ++ if (expr = av_strtok(args1, ":", &bufptr)) { ++ if (!(fade->type = av_strdup(expr))) { ++ ret = AVERROR(ENOMEM); ++ goto end; ++ } ++ } ++ if (expr = av_strtok(NULL, ":", &bufptr)) { ++ if ((ret = av_opt_set(fade, "start_frame", expr, 0)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid value '%s' for start_frame option\n", expr); ++ return ret; ++ } ++ } ++ if (expr = av_strtok(NULL, ":", &bufptr)) { ++ if ((ret = av_opt_set(fade, "nb_frames", expr, 0)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid value '%s' for nb_frames option\n", expr); ++ return ret; ++ } ++ } ++ ++ if (bufptr && (ret = av_set_options_string(fade, bufptr, "=", ":")) < 0) ++ goto end; ++ ++ fade->fade_per_frame = (1 << 16) / fade->nb_frames; ++ if (!strcmp(fade->type, "in")) ++ fade->factor = 0; ++ else if (!strcmp(fade->type, "out")) { ++ fade->fade_per_frame = -fade->fade_per_frame; ++ fade->factor = (1 << 16); ++ } else { ++ av_log(ctx, AV_LOG_ERROR, ++ "Type argument must be 'in' or 'out' but '%s' was specified\n", fade->type); ++ ret = AVERROR(EINVAL); ++ goto end; ++ } ++ fade->stop_frame = fade->start_frame + fade->nb_frames; ++ ++ av_log(ctx, AV_LOG_INFO, ++ "type:%s start_frame:%d nb_frames:%d alpha:%d\n", ++ fade->type, fade->start_frame, fade->nb_frames, fade->alpha); ++ ++end: ++ av_free(args1); ++ return ret; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ FadeContext *fade = ctx->priv; ++ ++ av_freep(&fade->type); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, ++ PIX_FMT_YUV411P, PIX_FMT_YUV410P, ++ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, ++ PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, ++ PIX_FMT_YUVA420P, ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ PIX_FMT_ARGB, PIX_FMT_ABGR, ++ PIX_FMT_RGBA, PIX_FMT_BGRA, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++const static enum PixelFormat studio_level_pix_fmts[] = { ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, ++ PIX_FMT_YUV411P, PIX_FMT_YUV410P, ++ PIX_FMT_YUV440P, ++ PIX_FMT_NONE ++}; ++ ++static enum PixelFormat alpha_pix_fmts[] = { ++ PIX_FMT_YUVA420P, ++ PIX_FMT_ARGB, PIX_FMT_ABGR, ++ PIX_FMT_RGBA, PIX_FMT_BGRA, ++ PIX_FMT_NONE ++}; ++ ++static int config_props(AVFilterLink *inlink) ++{ ++ FadeContext *fade = inlink->dst->priv; ++ const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[inlink->format]; ++ ++ fade->hsub = pixdesc->log2_chroma_w; ++ fade->vsub = pixdesc->log2_chroma_h; ++ ++ fade->bpp = av_get_bits_per_pixel(pixdesc) >> 3; ++ fade->alpha = fade->alpha ? ff_fmt_is_in(inlink->format, alpha_pix_fmts) : 0; ++ fade->is_packed_rgb = ff_fill_rgba_map(fade->rgba_map, inlink->format) >= 0; ++ ++ /* CCIR601/709 black level unless input is RGB or has alpha */ ++ fade->black_level = ++ ff_fmt_is_in(inlink->format, studio_level_pix_fmts) || fade->alpha ? 0 : 16; ++ /* 32768 = 1 << 15, it is an integer representation ++ * of 0.5 and is for rounding. */ ++ fade->black_level_scaled = (fade->black_level << 16) + 32768; ++ return 0; ++} ++ ++static void fade_plane(int y, int h, int w, ++ int fade_factor, int black_level, int black_level_scaled, ++ uint8_t offset, uint8_t step, int bytes_per_plane, ++ uint8_t *data, int line_size) ++{ ++ uint8_t *p; ++ int i, j; ++ ++ /* luma, alpha or rgb plane */ ++ for (i = 0; i < h; i++) { ++ p = data + offset + (y+i) * line_size; ++ for (j = 0; j < w * bytes_per_plane; j++) { ++ /* fade->factor is using 16 lower-order bits for decimal places. */ ++ *p = ((*p - black_level) * fade_factor + black_level_scaled) >> 16; ++ p+=step; ++ } ++ } ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ FadeContext *fade = inlink->dst->priv; ++ AVFilterBufferRef *outpic = inlink->cur_buf; ++ uint8_t *p; ++ int i, j, plane; ++ ++ if (fade->factor < UINT16_MAX) { ++ if (fade->alpha) { ++ // alpha only ++ plane = fade->is_packed_rgb ? 0 : A; // alpha is on plane 0 for packed formats ++ // or plane 3 for planar formats ++ fade_plane(y, h, inlink->w, ++ fade->factor, fade->black_level, fade->black_level_scaled, ++ fade->is_packed_rgb ? fade->rgba_map[A] : 0, // alpha offset for packed formats ++ fade->is_packed_rgb ? 4 : 1, // pixstep for 8 bit packed formats ++ 1, outpic->data[plane], outpic->linesize[plane]); ++ } else { ++ /* luma or rgb plane */ ++ fade_plane(y, h, inlink->w, ++ fade->factor, fade->black_level, fade->black_level_scaled, ++ 0, 1, // offset & pixstep for Y plane or RGB packed format ++ fade->bpp, outpic->data[0], outpic->linesize[0]); ++ if (outpic->data[1] && outpic->data[2]) { ++ /* chroma planes */ ++ for (plane = 1; plane < 3; plane++) { ++ for (i = 0; i < h; i++) { ++ p = outpic->data[plane] + ((y+i) >> fade->vsub) * outpic->linesize[plane]; ++ for (j = 0; j < inlink->w >> fade->hsub; j++) { ++ /* 8421367 = ((128 << 1) + 1) << 15. It is an integer ++ * representation of 128.5. The .5 is for rounding ++ * purposes. */ ++ *p = ((*p - 128) * fade->factor + 8421367) >> 16; ++ p++; ++ } ++ } ++ } ++ } ++ } ++ } ++ ++ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ FadeContext *fade = inlink->dst->priv; ++ ++ avfilter_end_frame(inlink->dst->outputs[0]); ++ ++ if (fade->frame_index >= fade->start_frame && ++ fade->frame_index <= fade->stop_frame) ++ fade->factor += fade->fade_per_frame; ++ fade->factor = av_clip_uint16(fade->factor); ++ fade->frame_index++; ++} ++ ++AVFilter avfilter_vf_fade = { ++ .name = "fade", ++ .description = NULL_IF_CONFIG_SMALL("Fade in/out input video."), ++ .init = init, ++ .uninit = uninit, ++ .priv_size = sizeof(FadeContext), ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = config_props, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = avfilter_null_start_frame, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_READ | AV_PERM_WRITE, ++ .rej_perms = AV_PERM_PRESERVE, }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fieldorder.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fieldorder.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fieldorder.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fieldorder.c 2012-05-14 14:08:54.812349602 +0200 +@@ -0,0 +1,234 @@ ++/* ++ * Copyright (c) 2011 Mark Himsley ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * video field order filter, heavily influenced by vf_pad.c ++ */ ++ ++/* #define DEBUG */ ++ ++#include "libavutil/imgutils.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++ ++typedef struct ++{ ++ unsigned int dst_tff; ///< output bff/tff ++ int line_size[4]; ///< bytes of pixel data per line for each plane ++} FieldOrderContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ FieldOrderContext *fieldorder = ctx->priv; ++ ++ const char *tff = "tff"; ++ const char *bff = "bff"; ++ ++ if (!args) { ++ fieldorder->dst_tff = 1; ++ } else if (sscanf(args, "%u", &fieldorder->dst_tff) == 1) { ++ fieldorder->dst_tff = !!fieldorder->dst_tff; ++ } else if (!strcmp(tff, args)) { ++ fieldorder->dst_tff = 1; ++ } else if (!strcmp(bff, args)) { ++ fieldorder->dst_tff = 0; ++ } else { ++ av_log(ctx, AV_LOG_ERROR, "Invalid argument '%s'.\n", args); ++ return AVERROR(EINVAL); ++ } ++ ++ av_log(ctx, AV_LOG_INFO, "output field order: %s\n", ++ fieldorder->dst_tff ? tff : bff); ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *formats; ++ enum PixelFormat pix_fmt; ++ int ret; ++ ++ /** accept any input pixel format that is not hardware accelerated, not ++ * a bitstream format, and does not have vertically sub-sampled chroma */ ++ if (ctx->inputs[0]) { ++ formats = NULL; ++ for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) ++ if (!( av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_HWACCEL ++ || av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_BITSTREAM) ++ && av_pix_fmt_descriptors[pix_fmt].nb_components ++ && !av_pix_fmt_descriptors[pix_fmt].log2_chroma_h ++ && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { ++ avfilter_formats_unref(&formats); ++ return ret; ++ } ++ avfilter_formats_ref(formats, &ctx->inputs[0]->out_formats); ++ avfilter_formats_ref(formats, &ctx->outputs[0]->in_formats); ++ } ++ ++ return 0; ++} ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ FieldOrderContext *fieldorder = ctx->priv; ++ int plane; ++ ++ /** full an array with the number of bytes that the video ++ * data occupies per line for each plane of the input video */ ++ for (plane = 0; plane < 4; plane++) { ++ fieldorder->line_size[plane] = av_image_get_linesize( ++ inlink->format, ++ inlink->w, ++ plane); ++ } ++ ++ return 0; ++} ++ ++static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ ++ return avfilter_get_video_buffer(outlink, perms, w, h); ++} ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *inpicref) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ ++ AVFilterBufferRef *outpicref; ++ ++ outpicref = avfilter_ref_buffer(inpicref, ~0); ++ outlink->out_buf = outpicref; ++ ++ avfilter_start_frame(outlink, outpicref); ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ FieldOrderContext *fieldorder = ctx->priv; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ ++ AVFilterBufferRef *inpicref = inlink->cur_buf; ++ ++ /** can only currently do slices if this filter is doing nothing ++ * because this filter is moving picture content, the output ++ * slice will contain different video lines than the input slice ++ * and that complexity will be added later */ ++ if ( !inpicref->video->interlaced ++ || inpicref->video->top_field_first == fieldorder->dst_tff) { ++ avfilter_draw_slice(outlink, y, h, slice_dir); ++ } ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ FieldOrderContext *fieldorder = ctx->priv; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ ++ AVFilterBufferRef *inpicref = inlink->cur_buf; ++ AVFilterBufferRef *outpicref = outlink->out_buf; ++ ++ int h, plane, line_step, line_size, line; ++ uint8_t *cpy_src, *cpy_dst; ++ ++ if ( inpicref->video->interlaced ++ && inpicref->video->top_field_first != fieldorder->dst_tff) { ++ av_dlog(ctx, ++ "picture will move %s one line\n", ++ fieldorder->dst_tff ? "up" : "down"); ++ h = inpicref->video->h; ++ for (plane = 0; plane < 4 && inpicref->data[plane]; plane++) { ++ line_step = inpicref->linesize[plane]; ++ line_size = fieldorder->line_size[plane]; ++ cpy_src = inpicref->data[plane]; ++ cpy_dst = outpicref->data[plane]; ++ if (fieldorder->dst_tff) { ++ /** Move every line up one line, working from ++ * the top to the bottom of the frame. ++ * The original top line is lost. ++ * The new last line is created as a copy of the ++ * penultimate line from that field. */ ++ for (line = 0; line < h; line++) { ++ if (1 + line < outpicref->video->h) { ++ memcpy(cpy_dst, cpy_src + line_step, line_size); ++ } else { ++ memcpy(cpy_dst, cpy_src - line_step - line_step, line_size); ++ } ++ cpy_src += line_step; ++ cpy_dst += line_step; ++ } ++ } else { ++ /** Move every line down one line, working from ++ * the bottom to the top of the frame. ++ * The original bottom line is lost. ++ * The new first line is created as a copy of the ++ * second line from that field. */ ++ cpy_src += (h - 1) * line_step; ++ cpy_dst += (h - 1) * line_step; ++ for (line = h - 1; line >= 0 ; line--) { ++ if (line > 0) { ++ memcpy(cpy_dst, cpy_src - line_step, line_size); ++ } else { ++ memcpy(cpy_dst, cpy_src + line_step + line_step, line_size); ++ } ++ cpy_src -= line_step; ++ cpy_dst -= line_step; ++ } ++ } ++ } ++ outpicref->video->top_field_first = fieldorder->dst_tff; ++ avfilter_draw_slice(outlink, 0, h, 1); ++ } else { ++ av_dlog(ctx, ++ "not interlaced or field order already correct\n"); ++ } ++ ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(inpicref); ++} ++ ++AVFilter avfilter_vf_fieldorder = { ++ .name = "fieldorder", ++ .description = NULL_IF_CONFIG_SMALL("Set the field order."), ++ .init = init, ++ .priv_size = sizeof(FieldOrderContext), ++ .query_formats = query_formats, ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = config_input, ++ .start_frame = start_frame, ++ .get_video_buffer = get_video_buffer, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_READ, ++ .rej_perms = AV_PERM_REUSE2|AV_PERM_PRESERVE,}, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fifo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fifo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_fifo.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_fifo.c 2012-05-14 14:08:54.813349622 +0200 +@@ -76,7 +76,7 @@ + int ret; + + if (!fifo->root.next) { +- if ((ret = avfilter_request_frame(outlink->src->inputs[0]) < 0)) ++ if ((ret = avfilter_request_frame(outlink->src->inputs[0])) < 0) + return ret; + } + +@@ -104,7 +104,7 @@ + + .priv_size = sizeof(FifoContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer= avfilter_null_get_video_buffer, + .start_frame = start_frame, +@@ -112,7 +112,7 @@ + .end_frame = end_frame, + .rej_perms = AV_PERM_REUSE2, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .request_frame = request_frame, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_format.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_format.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_format.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_format.c 2012-05-14 14:08:54.814349642 +0200 +@@ -25,6 +25,7 @@ + + #include "libavutil/pixdesc.h" + #include "avfilter.h" ++#include "internal.h" + + typedef struct { + /** +@@ -41,7 +42,7 @@ + FormatContext *format = ctx->priv; + const char *cur, *sep; + char pix_fmt_name[PIX_FMT_NAME_MAXSIZE]; +- int pix_fmt_name_len; ++ int pix_fmt_name_len, ret; + enum PixelFormat pix_fmt; + + /* parse the list of formats */ +@@ -57,12 +58,9 @@ + + memcpy(pix_fmt_name, cur, pix_fmt_name_len); + pix_fmt_name[pix_fmt_name_len] = 0; +- pix_fmt = av_get_pix_fmt(pix_fmt_name); + +- if (pix_fmt == PIX_FMT_NONE) { +- av_log(ctx, AV_LOG_ERROR, "Unknown pixel format: %s\n", pix_fmt_name); +- return -1; +- } ++ if ((ret = ff_parse_pixel_format(&pix_fmt, pix_fmt_name, ctx)) < 0) ++ return ret; + + format->listed_pix_fmt_flags[pix_fmt] = 1; + } +@@ -88,7 +86,7 @@ + #if CONFIG_FORMAT_FILTER + static int query_formats_format(AVFilterContext *ctx) + { +- avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 1)); ++ avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 1)); + return 0; + } + +@@ -102,14 +100,14 @@ + + .priv_size = sizeof(FormatContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer= avfilter_null_get_video_buffer, + .start_frame = avfilter_null_start_frame, + .draw_slice = avfilter_null_draw_slice, + .end_frame = avfilter_null_end_frame, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO }, + { .name = NULL}}, + }; +@@ -118,7 +116,7 @@ + #if CONFIG_NOFORMAT_FILTER + static int query_formats_noformat(AVFilterContext *ctx) + { +- avfilter_set_common_formats(ctx, make_format_list(ctx->priv, 0)); ++ avfilter_set_common_pixel_formats(ctx, make_format_list(ctx->priv, 0)); + return 0; + } + +@@ -132,14 +130,14 @@ + + .priv_size = sizeof(FormatContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer= avfilter_null_get_video_buffer, + .start_frame = avfilter_null_start_frame, + .draw_slice = avfilter_null_draw_slice, + .end_frame = avfilter_null_end_frame, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_frei0r.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_frei0r.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_frei0r.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_frei0r.c 2012-05-14 14:08:54.815349662 +0200 +@@ -27,8 +27,9 @@ + #include + #include + #include "libavutil/avstring.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/parseutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/parseutils.h" + #include "avfilter.h" + + typedef f0r_instance_t (*f0r_construct_f)(unsigned int width, unsigned int height); +@@ -215,7 +216,7 @@ + /* see: http://piksel.org/frei0r/1.2/spec/1.2/spec/group__pluglocations.html */ + if ((path = av_strdup(getenv("FREI0R_PATH")))) { + char *p, *ptr = NULL; +- for (p = path; p = strtok_r(p, ":", &ptr); p = NULL) ++ for (p = path; p = av_strtok(p, ":", &ptr); p = NULL) + if (frei0r->dl_handle = load_path(ctx, p, dl_name)) + break; + av_free(path); +@@ -332,7 +333,7 @@ + if (!formats) + return AVERROR(ENOMEM); + +- avfilter_set_common_formats(ctx, formats); ++ avfilter_set_common_pixel_formats(ctx, formats); + return 0; + } + +@@ -364,7 +365,7 @@ + + .priv_size = sizeof(Frei0rContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = null_draw_slice, + .config_props = config_input_props, +@@ -372,7 +373,7 @@ + .min_perms = AV_PERM_READ }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +@@ -430,7 +431,7 @@ + { + Frei0rContext *frei0r = outlink->src->priv; + AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); +- picref->video->pixel_aspect = (AVRational) {1, 1}; ++ picref->video->sample_aspect_ratio = (AVRational) {1, 1}; + picref->pts = frei0r->pts++; + picref->pos = -1; + +@@ -454,9 +455,9 @@ + + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = NULL}}, ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .request_frame = source_request_frame, + .config_props = source_config_props }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_gradfun.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_gradfun.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_gradfun.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_gradfun.c 2012-05-14 14:08:54.816349682 +0200 +@@ -32,7 +32,7 @@ + * Dither it back to 8bit. + */ + +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "libavutil/cpu.h" + #include "libavutil/pixdesc.h" + #include "avfilter.h" +@@ -49,7 +49,7 @@ + {0x54,0x34,0x4C,0x2C,0x52,0x32,0x4A,0x2A}, + }; + +-void ff_gradfun_filter_line_c(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) ++void ff_gradfun_filter_line_c(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) + { + int x; + for (x = 0; x < width; x++, dc += x & 1) { +@@ -63,7 +63,7 @@ + } + } + +-void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width) ++void ff_gradfun_blur_line_c(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width) + { + int x, v, old; + for (x = 0; x < width; x++) { +@@ -74,7 +74,7 @@ + } + } + +-static void filter(GradFunContext *ctx, uint8_t *dst, uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r) ++static void filter(GradFunContext *ctx, uint8_t *dst, const uint8_t *src, int width, int height, int dst_linesize, int src_linesize, int r) + { + int bstride = FFALIGN(width, 16) / 2; + int y; +@@ -160,7 +160,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + + return 0; + } +@@ -240,7 +240,7 @@ + .uninit = uninit, + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .start_frame = start_frame, +@@ -248,7 +248,7 @@ + .end_frame = end_frame, + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_hflip.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_hflip.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_hflip.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_hflip.c 2012-05-14 14:08:54.816349682 +0200 +@@ -27,7 +27,7 @@ + #include "avfilter.h" + #include "libavutil/pixdesc.h" + #include "libavutil/intreadwrite.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + typedef struct { + int max_step[4]; ///< max pixel step for each plane, expressed as a number of bytes +@@ -38,6 +38,7 @@ + { + static const enum PixelFormat pix_fmts[] = { + PIX_FMT_RGB48BE, PIX_FMT_RGB48LE, ++ PIX_FMT_BGR48BE, PIX_FMT_BGR48LE, + PIX_FMT_ARGB, PIX_FMT_RGBA, + PIX_FMT_ABGR, PIX_FMT_BGRA, + PIX_FMT_RGB24, PIX_FMT_BGR24, +@@ -61,7 +62,7 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -95,10 +96,8 @@ + for (i = 0; i < h>>vsub; i++) { + switch (step) { + case 1: +- { + for (j = 0; j < (inlink->w >> hsub); j++) + outrow[j] = inrow[-j]; +- } + break; + + case 2: +@@ -149,13 +148,13 @@ + .priv_size = sizeof(FlipContext), + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = draw_slice, + .config_props = config_props, + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_hqdn3d.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_hqdn3d.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_hqdn3d.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_hqdn3d.c 2012-05-14 14:08:54.817349702 +0200 +@@ -268,7 +268,7 @@ + PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV411P, PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + + return 0; + } +@@ -332,14 +332,14 @@ + .uninit = uninit, + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = null_draw_slice, + .config_props = config_input, + .end_frame = end_frame }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_libopencv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_libopencv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_libopencv.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_libopencv.c 2012-05-14 14:08:54.818349722 +0200 +@@ -26,7 +26,7 @@ + /* #define DEBUG */ + + #include +-#include ++#include + #include "libavutil/avstring.h" + #include "libavutil/file.h" + #include "avfilter.h" +@@ -61,7 +61,7 @@ + PIX_FMT_BGR24, PIX_FMT_BGRA, PIX_FMT_GRAY8, PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -158,7 +158,7 @@ + } + w++; + } +- if (*rows > (FF_INTERNAL_MEM_TYPE_MAX_VALUE / (sizeof(int)) / *cols)) { ++ if (*rows > (SIZE_MAX / sizeof(int) / *cols)) { + av_log(log_ctx, AV_LOG_ERROR, "File with size %dx%d is too big\n", + *rows, *cols); + return AVERROR_INVALIDDATA; +@@ -379,14 +379,14 @@ + .init = init, + .uninit = uninit, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = null_draw_slice, + .end_frame = end_frame, + .min_perms = AV_PERM_READ }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_lut.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_lut.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_lut.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_lut.c 2012-05-14 14:08:54.819349743 +0200 +@@ -0,0 +1,383 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Compute a look-up table for binding the input value to the output ++ * value, and apply it to input video. ++ */ ++ ++#include "libavutil/eval.h" ++#include "libavutil/opt.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++static const char * const var_names[] = { ++ "w", ///< width of the input video ++ "h", ///< height of the input video ++ "val", ///< input value for the pixel ++ "maxval", ///< max value for the pixel ++ "minval", ///< min value for the pixel ++ "negval", ///< negated value ++ "clipval", ++ NULL ++}; ++ ++enum var_name { ++ VAR_W, ++ VAR_H, ++ VAR_VAL, ++ VAR_MAXVAL, ++ VAR_MINVAL, ++ VAR_NEGVAL, ++ VAR_CLIPVAL, ++ VAR_VARS_NB ++}; ++ ++typedef struct { ++ const AVClass *class; ++ uint8_t lut[4][256]; ///< lookup table for each component ++ char *comp_expr_str[4]; ++ AVExpr *comp_expr[4]; ++ int hsub, vsub; ++ double var_values[VAR_VARS_NB]; ++ int is_rgb, is_yuv; ++ int rgba_map[4]; ++ int step; ++ int negate_alpha; /* only used by negate */ ++} LutContext; ++ ++#define Y 0 ++#define U 1 ++#define V 2 ++#define R 0 ++#define G 1 ++#define B 2 ++#define A 3 ++ ++#define OFFSET(x) offsetof(LutContext, x) ++ ++static const AVOption lut_options[] = { ++ {"c0", "set component #0 expression", OFFSET(comp_expr_str[0]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"c1", "set component #1 expression", OFFSET(comp_expr_str[1]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"c2", "set component #2 expression", OFFSET(comp_expr_str[2]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"c3", "set component #3 expression", OFFSET(comp_expr_str[3]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"y", "set Y expression", OFFSET(comp_expr_str[Y]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"u", "set U expression", OFFSET(comp_expr_str[U]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"v", "set V expression", OFFSET(comp_expr_str[V]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"r", "set R expression", OFFSET(comp_expr_str[R]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"g", "set G expression", OFFSET(comp_expr_str[G]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"b", "set B expression", OFFSET(comp_expr_str[B]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {"a", "set A expression", OFFSET(comp_expr_str[A]), AV_OPT_TYPE_STRING, {.str="val"}, CHAR_MIN, CHAR_MAX}, ++ {NULL}, ++}; ++ ++static const char *lut_get_name(void *ctx) ++{ ++ return "lut"; ++} ++ ++static const AVClass lut_class = { ++ "LutContext", ++ lut_get_name, ++ lut_options ++}; ++ ++static int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ LutContext *lut = ctx->priv; ++ int ret; ++ ++ lut->class = &lut_class; ++ av_opt_set_defaults(lut); ++ ++ lut->is_rgb = !strcmp(ctx->filter->name, "lutrgb"); ++ lut->is_yuv = !strcmp(ctx->filter->name, "lutyuv"); ++ if (args && (ret = av_set_options_string(lut, args, "=", ":")) < 0) ++ return ret; ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ LutContext *lut = ctx->priv; ++ int i; ++ ++ for (i = 0; i < 4; i++) { ++ av_expr_free(lut->comp_expr[i]); ++ lut->comp_expr[i] = NULL; ++ av_freep(&lut->comp_expr_str[i]); ++ } ++} ++ ++#define YUV_FORMATS \ ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, PIX_FMT_YUV420P, \ ++ PIX_FMT_YUV411P, PIX_FMT_YUV410P, PIX_FMT_YUV440P, \ ++ PIX_FMT_YUVA420P, \ ++ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ420P, \ ++ PIX_FMT_YUVJ440P ++ ++#define RGB_FORMATS \ ++ PIX_FMT_ARGB, PIX_FMT_RGBA, \ ++ PIX_FMT_ABGR, PIX_FMT_BGRA, \ ++ PIX_FMT_RGB24, PIX_FMT_BGR24 ++ ++static const enum PixelFormat yuv_pix_fmts[] = { YUV_FORMATS, PIX_FMT_NONE }; ++static const enum PixelFormat rgb_pix_fmts[] = { RGB_FORMATS, PIX_FMT_NONE }; ++static const enum PixelFormat all_pix_fmts[] = { RGB_FORMATS, YUV_FORMATS, PIX_FMT_NONE }; ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ LutContext *lut = ctx->priv; ++ ++ const enum PixelFormat *pix_fmts = lut->is_rgb ? rgb_pix_fmts : ++ lut->is_yuv ? yuv_pix_fmts : all_pix_fmts; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++/** ++ * Clip value val in the minval - maxval range. ++ */ ++static double clip(void *opaque, double val) ++{ ++ LutContext *lut = opaque; ++ double minval = lut->var_values[VAR_MINVAL]; ++ double maxval = lut->var_values[VAR_MAXVAL]; ++ ++ return av_clip(val, minval, maxval); ++} ++ ++/** ++ * Compute gamma correction for value val, assuming the minval-maxval ++ * range, val is clipped to a value contained in the same interval. ++ */ ++static double compute_gammaval(void *opaque, double gamma) ++{ ++ LutContext *lut = opaque; ++ double val = lut->var_values[VAR_CLIPVAL]; ++ double minval = lut->var_values[VAR_MINVAL]; ++ double maxval = lut->var_values[VAR_MAXVAL]; ++ ++ return pow((val-minval)/(maxval-minval), gamma) * (maxval-minval)+minval; ++} ++ ++static double (* const funcs1[])(void *, double) = { ++ (void *)clip, ++ (void *)compute_gammaval, ++ NULL ++}; ++ ++static const char * const funcs1_names[] = { ++ "clip", ++ "gammaval", ++ NULL ++}; ++ ++static int config_props(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ LutContext *lut = ctx->priv; ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[inlink->format]; ++ int min[4], max[4]; ++ int val, comp, ret; ++ ++ lut->hsub = desc->log2_chroma_w; ++ lut->vsub = desc->log2_chroma_h; ++ ++ lut->var_values[VAR_W] = inlink->w; ++ lut->var_values[VAR_H] = inlink->h; ++ ++ switch (inlink->format) { ++ case PIX_FMT_YUV410P: ++ case PIX_FMT_YUV411P: ++ case PIX_FMT_YUV420P: ++ case PIX_FMT_YUV422P: ++ case PIX_FMT_YUV440P: ++ case PIX_FMT_YUV444P: ++ case PIX_FMT_YUVA420P: ++ min[Y] = min[U] = min[V] = 16; ++ max[Y] = 235; ++ max[U] = max[V] = 240; ++ min[A] = 0; max[A] = 255; ++ break; ++ default: ++ min[0] = min[1] = min[2] = min[3] = 0; ++ max[0] = max[1] = max[2] = max[3] = 255; ++ } ++ ++ lut->is_yuv = lut->is_rgb = 0; ++ if (ff_fmt_is_in(inlink->format, yuv_pix_fmts)) lut->is_yuv = 1; ++ else if (ff_fmt_is_in(inlink->format, rgb_pix_fmts)) lut->is_rgb = 1; ++ ++ if (lut->is_rgb) { ++ switch (inlink->format) { ++ case PIX_FMT_ARGB: lut->rgba_map[A] = 0; lut->rgba_map[R] = 1; lut->rgba_map[G] = 2; lut->rgba_map[B] = 3; break; ++ case PIX_FMT_ABGR: lut->rgba_map[A] = 0; lut->rgba_map[B] = 1; lut->rgba_map[G] = 2; lut->rgba_map[R] = 3; break; ++ case PIX_FMT_RGBA: ++ case PIX_FMT_RGB24: lut->rgba_map[R] = 0; lut->rgba_map[G] = 1; lut->rgba_map[B] = 2; lut->rgba_map[A] = 3; break; ++ case PIX_FMT_BGRA: ++ case PIX_FMT_BGR24: lut->rgba_map[B] = 0; lut->rgba_map[G] = 1; lut->rgba_map[R] = 2; lut->rgba_map[A] = 3; break; ++ } ++ lut->step = av_get_bits_per_pixel(desc) >> 3; ++ } ++ ++ for (comp = 0; comp < desc->nb_components; comp++) { ++ double res; ++ ++ /* create the parsed expression */ ++ ret = av_expr_parse(&lut->comp_expr[comp], lut->comp_expr_str[comp], ++ var_names, funcs1_names, funcs1, NULL, NULL, 0, ctx); ++ if (ret < 0) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Error when parsing the expression '%s' for the component %d.\n", ++ lut->comp_expr_str[comp], comp); ++ return AVERROR(EINVAL); ++ } ++ ++ /* compute the lut */ ++ lut->var_values[VAR_MAXVAL] = max[comp]; ++ lut->var_values[VAR_MINVAL] = min[comp]; ++ ++ for (val = 0; val < 256; val++) { ++ lut->var_values[VAR_VAL] = val; ++ lut->var_values[VAR_CLIPVAL] = av_clip(val, min[comp], max[comp]); ++ lut->var_values[VAR_NEGVAL] = ++ av_clip(min[comp] + max[comp] - lut->var_values[VAR_VAL], ++ min[comp], max[comp]); ++ ++ res = av_expr_eval(lut->comp_expr[comp], lut->var_values, lut); ++ if (isnan(res)) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Error when evaluating the expression '%s' for the value %d for the component #%d.\n", ++ lut->comp_expr_str[comp], val, comp); ++ return AVERROR(EINVAL); ++ } ++ lut->lut[comp][val] = av_clip((int)res, min[comp], max[comp]); ++ av_log(ctx, AV_LOG_DEBUG, "val[%d][%d] = %d\n", comp, val, lut->lut[comp][val]); ++ } ++ } ++ ++ return 0; ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ LutContext *lut = ctx->priv; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ AVFilterBufferRef *inpic = inlink ->cur_buf; ++ AVFilterBufferRef *outpic = outlink->out_buf; ++ uint8_t *inrow, *outrow, *inrow0, *outrow0; ++ int i, j, k, plane; ++ ++ if (lut->is_rgb) { ++ /* packed */ ++ inrow0 = inpic ->data[0] + y * inpic ->linesize[0]; ++ outrow0 = outpic->data[0] + y * outpic->linesize[0]; ++ ++ for (i = 0; i < h; i ++) { ++ inrow = inrow0; ++ outrow = outrow0; ++ for (j = 0; j < inlink->w; j++) { ++ for (k = 0; k < lut->step; k++) ++ outrow[k] = lut->lut[lut->rgba_map[k]][inrow[k]]; ++ outrow += lut->step; ++ inrow += lut->step; ++ } ++ inrow0 += inpic ->linesize[0]; ++ outrow0 += outpic->linesize[0]; ++ } ++ } else { ++ /* planar */ ++ for (plane = 0; plane < 4 && inpic->data[plane]; plane++) { ++ int vsub = plane == 1 || plane == 2 ? lut->vsub : 0; ++ int hsub = plane == 1 || plane == 2 ? lut->hsub : 0; ++ ++ inrow = inpic ->data[plane] + (y>>vsub) * inpic ->linesize[plane]; ++ outrow = outpic->data[plane] + (y>>vsub) * outpic->linesize[plane]; ++ ++ for (i = 0; i < h>>vsub; i ++) { ++ for (j = 0; j < inlink->w>>hsub; j++) ++ outrow[j] = lut->lut[plane][inrow[j]]; ++ inrow += inpic ->linesize[plane]; ++ outrow += outpic->linesize[plane]; ++ } ++ } ++ } ++ ++ avfilter_draw_slice(outlink, y, h, slice_dir); ++} ++ ++#define DEFINE_LUT_FILTER(name_, description_, init_) \ ++ AVFilter avfilter_vf_##name_ = { \ ++ .name = #name_, \ ++ .description = NULL_IF_CONFIG_SMALL(description_), \ ++ .priv_size = sizeof(LutContext), \ ++ \ ++ .init = init_, \ ++ .uninit = uninit, \ ++ .query_formats = query_formats, \ ++ \ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", \ ++ .type = AVMEDIA_TYPE_VIDEO, \ ++ .draw_slice = draw_slice, \ ++ .config_props = config_props, \ ++ .min_perms = AV_PERM_READ, }, \ ++ { .name = NULL}}, \ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", \ ++ .type = AVMEDIA_TYPE_VIDEO, }, \ ++ { .name = NULL}}, \ ++ } ++ ++#if CONFIG_LUT_FILTER ++DEFINE_LUT_FILTER(lut, "Compute and apply a lookup table to the RGB/YUV input video.", init); ++#endif ++#if CONFIG_LUTYUV_FILTER ++DEFINE_LUT_FILTER(lutyuv, "Compute and apply a lookup table to the YUV input video.", init); ++#endif ++#if CONFIG_LUTRGB_FILTER ++DEFINE_LUT_FILTER(lutrgb, "Compute and apply a lookup table to the RGB input video.", init); ++#endif ++ ++#if CONFIG_NEGATE_FILTER ++ ++static int negate_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ LutContext *lut = ctx->priv; ++ char lut_params[64]; ++ ++ if (args) ++ sscanf(args, "%d", &lut->negate_alpha); ++ ++ av_log(ctx, AV_LOG_DEBUG, "negate_alpha:%d\n", lut->negate_alpha); ++ ++ snprintf(lut_params, sizeof(lut_params), "c0=negval:c1=negval:c2=negval:a=%s", ++ lut->negate_alpha ? "negval" : "val"); ++ ++ return init(ctx, lut_params, opaque); ++} ++ ++DEFINE_LUT_FILTER(negate, "Negate input video.", negate_init); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_mp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_mp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_mp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_mp.c 2012-05-14 14:08:54.822349804 +0200 +@@ -0,0 +1,899 @@ ++/* ++ * Copyright (c) 2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ * ++ * Parts of this file have been stolen from mplayer ++ */ ++ ++/** ++ * @file ++ */ ++ ++#include "avfilter.h" ++#include "libavutil/avassert.h" ++#include "libavutil/pixdesc.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/imgutils.h" ++ ++#include "libmpcodecs/vf.h" ++#include "libmpcodecs/img_format.h" ++#include "libmpcodecs/cpudetect.h" ++#include "libmpcodecs/vd_ffmpeg.h" ++#include "libmpcodecs/vf_scale.h" ++#include "libmpcodecs/libvo/fastmemcpy.h" ++ ++#include "libswscale/swscale.h" ++ ++ ++//FIXME maybe link the orig in ++//XXX: identical pix_fmt must be following with each others ++static const struct { ++ int fmt; ++ enum PixelFormat pix_fmt; ++} conversion_map[] = { ++ {IMGFMT_ARGB, PIX_FMT_ARGB}, ++ {IMGFMT_BGRA, PIX_FMT_BGRA}, ++ {IMGFMT_BGR24, PIX_FMT_BGR24}, ++ {IMGFMT_BGR16BE, PIX_FMT_RGB565BE}, ++ {IMGFMT_BGR16LE, PIX_FMT_RGB565LE}, ++ {IMGFMT_BGR15BE, PIX_FMT_RGB555BE}, ++ {IMGFMT_BGR15LE, PIX_FMT_RGB555LE}, ++ {IMGFMT_BGR12BE, PIX_FMT_RGB444BE}, ++ {IMGFMT_BGR12LE, PIX_FMT_RGB444LE}, ++ {IMGFMT_BGR8, PIX_FMT_RGB8}, ++ {IMGFMT_BGR4, PIX_FMT_RGB4}, ++ {IMGFMT_BGR1, PIX_FMT_MONOBLACK}, ++ {IMGFMT_RGB1, PIX_FMT_MONOBLACK}, ++ {IMGFMT_RG4B, PIX_FMT_BGR4_BYTE}, ++ {IMGFMT_BG4B, PIX_FMT_RGB4_BYTE}, ++ {IMGFMT_RGB48LE, PIX_FMT_RGB48LE}, ++ {IMGFMT_RGB48BE, PIX_FMT_RGB48BE}, ++ {IMGFMT_ABGR, PIX_FMT_ABGR}, ++ {IMGFMT_RGBA, PIX_FMT_RGBA}, ++ {IMGFMT_RGB24, PIX_FMT_RGB24}, ++ {IMGFMT_RGB16BE, PIX_FMT_BGR565BE}, ++ {IMGFMT_RGB16LE, PIX_FMT_BGR565LE}, ++ {IMGFMT_RGB15BE, PIX_FMT_BGR555BE}, ++ {IMGFMT_RGB15LE, PIX_FMT_BGR555LE}, ++ {IMGFMT_RGB12BE, PIX_FMT_BGR444BE}, ++ {IMGFMT_RGB12LE, PIX_FMT_BGR444LE}, ++ {IMGFMT_RGB8, PIX_FMT_BGR8}, ++ {IMGFMT_RGB4, PIX_FMT_BGR4}, ++ {IMGFMT_BGR8, PIX_FMT_PAL8}, ++ {IMGFMT_YUY2, PIX_FMT_YUYV422}, ++ {IMGFMT_UYVY, PIX_FMT_UYVY422}, ++ {IMGFMT_NV12, PIX_FMT_NV12}, ++ {IMGFMT_NV21, PIX_FMT_NV21}, ++ {IMGFMT_Y800, PIX_FMT_GRAY8}, ++ {IMGFMT_Y8, PIX_FMT_GRAY8}, ++ {IMGFMT_YVU9, PIX_FMT_YUV410P}, ++ {IMGFMT_IF09, PIX_FMT_YUV410P}, ++ {IMGFMT_YV12, PIX_FMT_YUV420P}, ++ {IMGFMT_I420, PIX_FMT_YUV420P}, ++ {IMGFMT_IYUV, PIX_FMT_YUV420P}, ++ {IMGFMT_411P, PIX_FMT_YUV411P}, ++ {IMGFMT_422P, PIX_FMT_YUV422P}, ++ {IMGFMT_444P, PIX_FMT_YUV444P}, ++ {IMGFMT_440P, PIX_FMT_YUV440P}, ++ ++ {IMGFMT_420A, PIX_FMT_YUVA420P}, ++ ++ {IMGFMT_420P16_LE, PIX_FMT_YUV420P16LE}, ++ {IMGFMT_420P16_BE, PIX_FMT_YUV420P16BE}, ++ {IMGFMT_422P16_LE, PIX_FMT_YUV422P16LE}, ++ {IMGFMT_422P16_BE, PIX_FMT_YUV422P16BE}, ++ {IMGFMT_444P16_LE, PIX_FMT_YUV444P16LE}, ++ {IMGFMT_444P16_BE, PIX_FMT_YUV444P16BE}, ++ ++ // YUVJ are YUV formats that use the full Y range and not just ++ // 16 - 235 (see colorspaces.txt). ++ // Currently they are all treated the same way. ++ {IMGFMT_YV12, PIX_FMT_YUVJ420P}, ++ {IMGFMT_422P, PIX_FMT_YUVJ422P}, ++ {IMGFMT_444P, PIX_FMT_YUVJ444P}, ++ {IMGFMT_440P, PIX_FMT_YUVJ440P}, ++ ++ {IMGFMT_XVMC_MOCO_MPEG2, PIX_FMT_XVMC_MPEG2_MC}, ++ {IMGFMT_XVMC_IDCT_MPEG2, PIX_FMT_XVMC_MPEG2_IDCT}, ++ {IMGFMT_VDPAU_MPEG1, PIX_FMT_VDPAU_MPEG1}, ++ {IMGFMT_VDPAU_MPEG2, PIX_FMT_VDPAU_MPEG2}, ++ {IMGFMT_VDPAU_H264, PIX_FMT_VDPAU_H264}, ++ {IMGFMT_VDPAU_WMV3, PIX_FMT_VDPAU_WMV3}, ++ {IMGFMT_VDPAU_VC1, PIX_FMT_VDPAU_VC1}, ++ {IMGFMT_VDPAU_MPEG4, PIX_FMT_VDPAU_MPEG4}, ++ {0, PIX_FMT_NONE} ++}; ++ ++//copied from vf.c ++extern const vf_info_t vf_info_1bpp; ++extern const vf_info_t vf_info_2xsai; ++extern const vf_info_t vf_info_ass; ++extern const vf_info_t vf_info_bmovl; ++extern const vf_info_t vf_info_crop; ++extern const vf_info_t vf_info_decimate; ++extern const vf_info_t vf_info_denoise3d; ++extern const vf_info_t vf_info_detc; ++extern const vf_info_t vf_info_dint; ++extern const vf_info_t vf_info_divtc; ++extern const vf_info_t vf_info_down3dright; ++extern const vf_info_t vf_info_dsize; ++extern const vf_info_t vf_info_dvbscale; ++extern const vf_info_t vf_info_eq2; ++extern const vf_info_t vf_info_eq; ++extern const vf_info_t vf_info_expand; ++extern const vf_info_t vf_info_field; ++extern const vf_info_t vf_info_fil; ++extern const vf_info_t vf_info_filmdint; ++extern const vf_info_t vf_info_fixpts; ++extern const vf_info_t vf_info_flip; ++extern const vf_info_t vf_info_format; ++extern const vf_info_t vf_info_framestep; ++extern const vf_info_t vf_info_fspp; ++extern const vf_info_t vf_info_geq; ++extern const vf_info_t vf_info_halfpack; ++extern const vf_info_t vf_info_harddup; ++extern const vf_info_t vf_info_hqdn3d; ++extern const vf_info_t vf_info_hue; ++extern const vf_info_t vf_info_il; ++extern const vf_info_t vf_info_ilpack; ++extern const vf_info_t vf_info_ivtc; ++extern const vf_info_t vf_info_kerndeint; ++extern const vf_info_t vf_info_lavc; ++extern const vf_info_t vf_info_lavcdeint; ++extern const vf_info_t vf_info_mcdeint; ++extern const vf_info_t vf_info_mirror; ++extern const vf_info_t vf_info_noformat; ++extern const vf_info_t vf_info_noise; ++extern const vf_info_t vf_info_ow; ++extern const vf_info_t vf_info_palette; ++extern const vf_info_t vf_info_perspective; ++extern const vf_info_t vf_info_phase; ++extern const vf_info_t vf_info_pp7; ++extern const vf_info_t vf_info_pp; ++extern const vf_info_t vf_info_pullup; ++extern const vf_info_t vf_info_qp; ++extern const vf_info_t vf_info_rectangle; ++extern const vf_info_t vf_info_remove_logo; ++extern const vf_info_t vf_info_rotate; ++extern const vf_info_t vf_info_sab; ++extern const vf_info_t vf_info_scale; ++extern const vf_info_t vf_info_screenshot; ++extern const vf_info_t vf_info_smartblur; ++extern const vf_info_t vf_info_softpulldown; ++extern const vf_info_t vf_info_softskip; ++extern const vf_info_t vf_info_spp; ++extern const vf_info_t vf_info_stereo3d; ++extern const vf_info_t vf_info_swapuv; ++extern const vf_info_t vf_info_telecine; ++extern const vf_info_t vf_info_test; ++extern const vf_info_t vf_info_tfields; ++extern const vf_info_t vf_info_tile; ++extern const vf_info_t vf_info_tinterlace; ++extern const vf_info_t vf_info_unsharp; ++extern const vf_info_t vf_info_uspp; ++extern const vf_info_t vf_info_vo; ++extern const vf_info_t vf_info_yadif; ++extern const vf_info_t vf_info_yuvcsp; ++extern const vf_info_t vf_info_yvu9; ++extern const vf_info_t vf_info_zrmjpeg; ++ ++ ++static const vf_info_t* const filters[]={ ++ &vf_info_2xsai, ++ &vf_info_decimate, ++ &vf_info_denoise3d, ++ &vf_info_detc, ++ &vf_info_dint, ++ &vf_info_divtc, ++ &vf_info_down3dright, ++ &vf_info_dsize, ++ &vf_info_eq2, ++ &vf_info_eq, ++ &vf_info_field, ++ &vf_info_fil, ++// &vf_info_filmdint, cmmx.h vd.h ‘opt_screen_size_x’ ++ &vf_info_fixpts, ++ &vf_info_framestep, ++ &vf_info_fspp, ++ &vf_info_geq, ++ &vf_info_harddup, ++ &vf_info_hqdn3d, ++ &vf_info_hue, ++ &vf_info_il, ++ &vf_info_ilpack, ++ &vf_info_ivtc, ++ &vf_info_kerndeint, ++ &vf_info_mcdeint, ++ &vf_info_mirror, ++ &vf_info_noise, ++ &vf_info_ow, ++ &vf_info_palette, ++ &vf_info_perspective, ++ &vf_info_phase, ++ &vf_info_pp7, ++ &vf_info_pullup, ++ &vf_info_qp, ++ &vf_info_rectangle, ++ &vf_info_remove_logo, ++ &vf_info_rotate, ++ &vf_info_sab, ++ &vf_info_screenshot, ++ &vf_info_smartblur, ++ &vf_info_softpulldown, ++ &vf_info_softskip, ++ &vf_info_spp, ++ &vf_info_stereo3d, ++ &vf_info_swapuv, ++ &vf_info_telecine, ++ &vf_info_tile, ++ &vf_info_tinterlace, ++ &vf_info_unsharp, ++ &vf_info_uspp, ++ &vf_info_yuvcsp, ++ &vf_info_yvu9, ++ ++ NULL ++}; ++ ++/* ++Unsupported filters ++1bpp ++ass ++bmovl ++crop ++dvbscale ++flip ++expand ++format ++halfpack ++lavc ++lavcdeint ++noformat ++pp ++scale ++tfields ++vo ++yadif ++zrmjpeg ++*/ ++ ++CpuCaps gCpuCaps; //FIXME initialize this so optims work ++ ++ ++static void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam) ++{ ++ static int firstTime=1; ++ *flags=0; ++ ++#if ARCH_X86 ++ if(gCpuCaps.hasMMX) ++ __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) ++#endif ++ if(firstTime) ++ { ++ firstTime=0; ++ *flags= SWS_PRINT_INFO; ++ } ++ else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO; ++ ++ switch(SWS_BILINEAR) ++ { ++ case 0: *flags|= SWS_FAST_BILINEAR; break; ++ case 1: *flags|= SWS_BILINEAR; break; ++ case 2: *flags|= SWS_BICUBIC; break; ++ case 3: *flags|= SWS_X; break; ++ case 4: *flags|= SWS_POINT; break; ++ case 5: *flags|= SWS_AREA; break; ++ case 6: *flags|= SWS_BICUBLIN; break; ++ case 7: *flags|= SWS_GAUSS; break; ++ case 8: *flags|= SWS_SINC; break; ++ case 9: *flags|= SWS_LANCZOS; break; ++ case 10:*flags|= SWS_SPLINE; break; ++ default:*flags|= SWS_BILINEAR; break; ++ } ++ ++ *srcFilterParam= NULL; ++ *dstFilterParam= NULL; ++} ++ ++//exact copy from vf_scale.c ++// will use sws_flags & src_filter (from cmd line) ++struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat) ++{ ++ int flags, i; ++ SwsFilter *dstFilterParam, *srcFilterParam; ++ enum PixelFormat dfmt, sfmt; ++ ++ for(i=0; conversion_map[i].fmt && dstFormat != conversion_map[i].fmt; i++); ++ dfmt= conversion_map[i].pix_fmt; ++ for(i=0; conversion_map[i].fmt && srcFormat != conversion_map[i].fmt; i++); ++ sfmt= conversion_map[i].pix_fmt; ++ ++ if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8; ++ sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam); ++ ++ return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags , srcFilterParam, dstFilterParam, NULL); ++} ++ ++typedef struct { ++ vf_instance_t vf; ++ vf_instance_t next_vf; ++ AVFilterContext *avfctx; ++ int frame_returned; ++} MPContext; ++ ++void mp_msg(int mod, int lev, const char *format, ... ){ ++ va_list va; ++ va_start(va, format); ++ //FIXME convert lev/mod ++ av_vlog(NULL, AV_LOG_DEBUG, format, va); ++ va_end(va); ++} ++ ++int mp_msg_test(int mod, int lev){ ++ return 123; ++} ++ ++void init_avcodec(void) ++{ ++ //we maybe should init but its kinda 1. unneeded 2. a bit inpolite from here ++} ++ ++//Exact copy of vf.c ++void vf_clone_mpi_attributes(mp_image_t* dst, mp_image_t* src){ ++ dst->pict_type= src->pict_type; ++ dst->fields = src->fields; ++ dst->qscale_type= src->qscale_type; ++ if(dst->width == src->width && dst->height == src->height){ ++ dst->qstride= src->qstride; ++ dst->qscale= src->qscale; ++ } ++} ++ ++//Exact copy of vf.c ++void vf_next_draw_slice(struct vf_instance *vf,unsigned char** src, int * stride,int w, int h, int x, int y){ ++ if (vf->next->draw_slice) { ++ vf->next->draw_slice(vf->next,src,stride,w,h,x,y); ++ return; ++ } ++ if (!vf->dmpi) { ++ mp_msg(MSGT_VFILTER,MSGL_ERR,"draw_slice: dmpi not stored by vf_%s\n", vf->info->name); ++ return; ++ } ++ if (!(vf->dmpi->flags & MP_IMGFLAG_PLANAR)) { ++ memcpy_pic(vf->dmpi->planes[0]+y*vf->dmpi->stride[0]+vf->dmpi->bpp/8*x, ++ src[0], vf->dmpi->bpp/8*w, h, vf->dmpi->stride[0], stride[0]); ++ return; ++ } ++ memcpy_pic(vf->dmpi->planes[0]+y*vf->dmpi->stride[0]+x, src[0], ++ w, h, vf->dmpi->stride[0], stride[0]); ++ memcpy_pic(vf->dmpi->planes[1]+(y>>vf->dmpi->chroma_y_shift)*vf->dmpi->stride[1]+(x>>vf->dmpi->chroma_x_shift), ++ src[1], w>>vf->dmpi->chroma_x_shift, h>>vf->dmpi->chroma_y_shift, vf->dmpi->stride[1], stride[1]); ++ memcpy_pic(vf->dmpi->planes[2]+(y>>vf->dmpi->chroma_y_shift)*vf->dmpi->stride[2]+(x>>vf->dmpi->chroma_x_shift), ++ src[2], w>>vf->dmpi->chroma_x_shift, h>>vf->dmpi->chroma_y_shift, vf->dmpi->stride[2], stride[2]); ++} ++ ++//Exact copy of vf.c ++void vf_mpi_clear(mp_image_t* mpi,int x0,int y0,int w,int h){ ++ int y; ++ if(mpi->flags&MP_IMGFLAG_PLANAR){ ++ y0&=~1;h+=h&1; ++ if(x0==0 && w==mpi->width){ ++ // full width clear: ++ memset(mpi->planes[0]+mpi->stride[0]*y0,0,mpi->stride[0]*h); ++ memset(mpi->planes[1]+mpi->stride[1]*(y0>>mpi->chroma_y_shift),128,mpi->stride[1]*(h>>mpi->chroma_y_shift)); ++ memset(mpi->planes[2]+mpi->stride[2]*(y0>>mpi->chroma_y_shift),128,mpi->stride[2]*(h>>mpi->chroma_y_shift)); ++ } else ++ for(y=y0;yplanes[0]+x0+mpi->stride[0]*y,0,w); ++ memset(mpi->planes[0]+x0+mpi->stride[0]*(y+1),0,w); ++ memset(mpi->planes[1]+(x0>>mpi->chroma_x_shift)+mpi->stride[1]*(y>>mpi->chroma_y_shift),128,(w>>mpi->chroma_x_shift)); ++ memset(mpi->planes[2]+(x0>>mpi->chroma_x_shift)+mpi->stride[2]*(y>>mpi->chroma_y_shift),128,(w>>mpi->chroma_x_shift)); ++ } ++ return; ++ } ++ // packed: ++ for(y=y0;yplanes[0]+mpi->stride[0]*y+(mpi->bpp>>3)*x0; ++ if(mpi->flags&MP_IMGFLAG_YUV){ ++ unsigned int* p=(unsigned int*) dst; ++ int size=(mpi->bpp>>3)*w/4; ++ int i; ++#if HAVE_BIGENDIAN ++#define CLEAR_PACKEDYUV_PATTERN 0x00800080 ++#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000 ++#else ++#define CLEAR_PACKEDYUV_PATTERN 0x80008000 ++#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080 ++#endif ++ if(mpi->flags&MP_IMGFLAG_SWAPPED){ ++ for(i=0;ibpp>>3)*w); ++ } ++} ++ ++int vf_next_query_format(struct vf_instance *vf, unsigned int fmt){ ++ return 1; ++} ++ ++//used by delogo ++unsigned int vf_match_csp(vf_instance_t** vfp,const unsigned int* list,unsigned int preferred){ ++ return preferred; ++} ++ ++mp_image_t* vf_get_image(vf_instance_t* vf, unsigned int outfmt, int mp_imgtype, int mp_imgflag, int w, int h){ ++ MPContext *m= (MPContext*)(((uint8_t*)vf) - offsetof(MPContext, next_vf)); ++ mp_image_t* mpi=NULL; ++ int w2; ++ int number = mp_imgtype >> 16; ++ ++ av_assert0(vf->next == NULL); // all existing filters call this just on next ++ ++ //vf_dint needs these as it calls vf_get_image() before configuring the output ++ if(vf->w==0 && w>0) vf->w=w; ++ if(vf->h==0 && h>0) vf->h=h; ++ ++ av_assert0(w == -1 || w >= vf->w); ++ av_assert0(h == -1 || h >= vf->h); ++ av_assert0(vf->w > 0); ++ av_assert0(vf->h > 0); ++ ++ av_log(m->avfctx, AV_LOG_DEBUG, "get_image: %d:%d, vf: %d:%d\n", w,h,vf->w,vf->h); ++ ++ if (w == -1) w = vf->w; ++ if (h == -1) h = vf->h; ++ ++ w2=(mp_imgflag&MP_IMGFLAG_ACCEPT_ALIGNED_STRIDE)?((w+15)&(~15)):w; ++ ++ // Note: we should call libvo first to check if it supports direct rendering ++ // and if not, then fallback to software buffers: ++ switch(mp_imgtype & 0xff){ ++ case MP_IMGTYPE_EXPORT: ++ if(!vf->imgctx.export_images[0]) vf->imgctx.export_images[0]=new_mp_image(w2,h); ++ mpi=vf->imgctx.export_images[0]; ++ break; ++ case MP_IMGTYPE_STATIC: ++ if(!vf->imgctx.static_images[0]) vf->imgctx.static_images[0]=new_mp_image(w2,h); ++ mpi=vf->imgctx.static_images[0]; ++ break; ++ case MP_IMGTYPE_TEMP: ++ if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h); ++ mpi=vf->imgctx.temp_images[0]; ++ break; ++ case MP_IMGTYPE_IPB: ++ if(!(mp_imgflag&MP_IMGFLAG_READABLE)){ // B frame: ++ if(!vf->imgctx.temp_images[0]) vf->imgctx.temp_images[0]=new_mp_image(w2,h); ++ mpi=vf->imgctx.temp_images[0]; ++ break; ++ } ++ case MP_IMGTYPE_IP: ++ if(!vf->imgctx.static_images[vf->imgctx.static_idx]) vf->imgctx.static_images[vf->imgctx.static_idx]=new_mp_image(w2,h); ++ mpi=vf->imgctx.static_images[vf->imgctx.static_idx]; ++ vf->imgctx.static_idx^=1; ++ break; ++ case MP_IMGTYPE_NUMBERED: ++ if (number == -1) { ++ int i; ++ for (i = 0; i < NUM_NUMBERED_MPI; i++) ++ if (!vf->imgctx.numbered_images[i] || !vf->imgctx.numbered_images[i]->usage_count) ++ break; ++ number = i; ++ } ++ if (number < 0 || number >= NUM_NUMBERED_MPI) return NULL; ++ if (!vf->imgctx.numbered_images[number]) vf->imgctx.numbered_images[number] = new_mp_image(w2,h); ++ mpi = vf->imgctx.numbered_images[number]; ++ mpi->number = number; ++ break; ++ } ++ if(mpi){ ++ mpi->type=mp_imgtype; ++ mpi->w=vf->w; mpi->h=vf->h; ++ // keep buffer allocation status & color flags only: ++// mpi->flags&=~(MP_IMGFLAG_PRESERVE|MP_IMGFLAG_READABLE|MP_IMGFLAG_DIRECT); ++ mpi->flags&=MP_IMGFLAG_ALLOCATED|MP_IMGFLAG_TYPE_DISPLAYED|MP_IMGFLAGMASK_COLORS; ++ // accept restrictions, draw_slice and palette flags only: ++ mpi->flags|=mp_imgflag&(MP_IMGFLAGMASK_RESTRICTIONS|MP_IMGFLAG_DRAW_CALLBACK|MP_IMGFLAG_RGB_PALETTE); ++ if(!vf->draw_slice) mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; ++ if(mpi->width!=w2 || mpi->height!=h){ ++// printf("vf.c: MPI parameters changed! %dx%d -> %dx%d \n", mpi->width,mpi->height,w2,h); ++ if(mpi->flags&MP_IMGFLAG_ALLOCATED){ ++ if(mpi->widthheightplanes[0]); ++ mpi->flags&=~MP_IMGFLAG_ALLOCATED; ++ mp_msg(MSGT_VFILTER,MSGL_V,"vf.c: have to REALLOCATE buffer memory :(\n"); ++ } ++// } else { ++ } { ++ mpi->width=w2; mpi->chroma_width=(w2 + (1<chroma_x_shift) - 1)>>mpi->chroma_x_shift; ++ mpi->height=h; mpi->chroma_height=(h + (1<chroma_y_shift) - 1)>>mpi->chroma_y_shift; ++ } ++ } ++ if(!mpi->bpp) mp_image_setfmt(mpi,outfmt); ++ if(!(mpi->flags&MP_IMGFLAG_ALLOCATED) && mpi->type>MP_IMGTYPE_EXPORT){ ++ ++ av_assert0(!vf->get_image); ++ // check libvo first! ++ if(vf->get_image) vf->get_image(vf,mpi); ++ ++ if(!(mpi->flags&MP_IMGFLAG_DIRECT)){ ++ // non-direct and not yet allocated image. allocate it! ++ if (!mpi->bpp) { // no way we can allocate this ++ mp_msg(MSGT_DECVIDEO, MSGL_FATAL, ++ "vf_get_image: Tried to allocate a format that can not be allocated!\n"); ++ return NULL; ++ } ++ ++ // check if codec prefer aligned stride: ++ if(mp_imgflag&MP_IMGFLAG_PREFER_ALIGNED_STRIDE){ ++ int align=(mpi->flags&MP_IMGFLAG_PLANAR && ++ mpi->flags&MP_IMGFLAG_YUV) ? ++ (8<chroma_x_shift)-1 : 15; // -- maybe FIXME ++ w2=((w+align)&(~align)); ++ if(mpi->width!=w2){ ++#if 0 ++ // we have to change width... check if we CAN co it: ++ int flags=vf->query_format(vf,outfmt); // should not fail ++ if(!(flags&3)) mp_msg(MSGT_DECVIDEO,MSGL_WARN,"??? vf_get_image{vf->query_format(outfmt)} failed!\n"); ++// printf("query -> 0x%X \n",flags); ++ if(flags&VFCAP_ACCEPT_STRIDE){ ++#endif ++ mpi->width=w2; ++ mpi->chroma_width=(w2 + (1<chroma_x_shift) - 1)>>mpi->chroma_x_shift; ++// } ++ } ++ } ++ ++ mp_image_alloc_planes(mpi); ++// printf("clearing img!\n"); ++ vf_mpi_clear(mpi,0,0,mpi->width,mpi->height); ++ } ++ } ++ av_assert0(!vf->start_slice); ++ if(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK) ++ if(vf->start_slice) vf->start_slice(vf,mpi); ++ if(!(mpi->flags&MP_IMGFLAG_TYPE_DISPLAYED)){ ++ mp_msg(MSGT_DECVIDEO,MSGL_V,"*** [%s] %s%s mp_image_t, %dx%dx%dbpp %s %s, %d bytes\n", ++ "NULL"/*vf->info->name*/, ++ (mpi->type==MP_IMGTYPE_EXPORT)?"Exporting": ++ ((mpi->flags&MP_IMGFLAG_DIRECT)?"Direct Rendering":"Allocating"), ++ (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)?" (slices)":"", ++ mpi->width,mpi->height,mpi->bpp, ++ (mpi->flags&MP_IMGFLAG_YUV)?"YUV":((mpi->flags&MP_IMGFLAG_SWAPPED)?"BGR":"RGB"), ++ (mpi->flags&MP_IMGFLAG_PLANAR)?"planar":"packed", ++ mpi->bpp*mpi->width*mpi->height/8); ++ mp_msg(MSGT_DECVIDEO,MSGL_DBG2,"(imgfmt: %x, planes: %p,%p,%p strides: %d,%d,%d, chroma: %dx%d, shift: h:%d,v:%d)\n", ++ mpi->imgfmt, mpi->planes[0], mpi->planes[1], mpi->planes[2], ++ mpi->stride[0], mpi->stride[1], mpi->stride[2], ++ mpi->chroma_width, mpi->chroma_height, mpi->chroma_x_shift, mpi->chroma_y_shift); ++ mpi->flags|=MP_IMGFLAG_TYPE_DISPLAYED; ++ } ++ ++ mpi->qscale = NULL; ++ } ++ mpi->usage_count++; ++// printf("\rVF_MPI: %p %p %p %d %d %d \n", ++// mpi->planes[0],mpi->planes[1],mpi->planes[2], ++// mpi->stride[0],mpi->stride[1],mpi->stride[2]); ++ return mpi; ++} ++ ++ ++int vf_next_put_image(struct vf_instance *vf,mp_image_t *mpi, double pts){ ++ MPContext *m= (void*)vf; ++ AVFilterLink *outlink = m->avfctx->outputs[0]; ++ AVFilterBuffer *pic = av_mallocz(sizeof(AVFilterBuffer)); ++ AVFilterBufferRef *picref = av_mallocz(sizeof(AVFilterBufferRef)); ++ int i; ++ ++ av_assert0(vf->next); ++ ++ av_log(m->avfctx, AV_LOG_DEBUG, "vf_next_put_image\n"); ++ ++ if (!pic || !picref) ++ goto fail; ++ ++ picref->buf = pic; ++ picref->buf->please_use_av_free= (void*)av_free; ++ if (!(picref->video = av_mallocz(sizeof(AVFilterBufferRefVideoProps)))) ++ goto fail; ++ ++ pic->w = picref->video->w = mpi->w; ++ pic->h = picref->video->h = mpi->h; ++ ++ /* make sure the buffer gets read permission or it's useless for output */ ++ picref->perms = AV_PERM_READ | AV_PERM_REUSE2; ++// av_assert0(mpi->flags&MP_IMGFLAG_READABLE); ++ if(!(mpi->flags&MP_IMGFLAG_PRESERVE)) ++ picref->perms |= AV_PERM_WRITE; ++ ++ pic->refcount = 1; ++ picref->type = AVMEDIA_TYPE_VIDEO; ++ ++ for(i=0; conversion_map[i].fmt && mpi->imgfmt != conversion_map[i].fmt; i++); ++ pic->format = picref->format = conversion_map[i].pix_fmt; ++ ++ memcpy(pic->data, mpi->planes, FFMIN(sizeof(pic->data) , sizeof(mpi->planes))); ++ memcpy(pic->linesize, mpi->stride, FFMIN(sizeof(pic->linesize), sizeof(mpi->stride))); ++ memcpy(picref->data, pic->data, sizeof(picref->data)); ++ memcpy(picref->linesize, pic->linesize, sizeof(picref->linesize)); ++ ++ if(pts != MP_NOPTS_VALUE) ++ picref->pts= pts * av_q2d(outlink->time_base); ++ ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, picref->video->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ m->frame_returned++; ++ ++ return 1; ++fail: ++ if (picref && picref->video) ++ av_free(picref->video); ++ av_free(picref); ++ av_free(pic); ++ return 0; ++} ++ ++int vf_next_config(struct vf_instance *vf, ++ int width, int height, int d_width, int d_height, ++ unsigned int voflags, unsigned int outfmt){ ++ ++ av_assert0(width>0 && height>0); ++ vf->next->w = width; vf->next->h = height; ++ ++ return 1; ++#if 0 ++ int flags=vf->next->query_format(vf->next,outfmt); ++ if(!flags){ ++ // hmm. colorspace mismatch!!! ++ //this is fatal for us ATM ++ return 0; ++ } ++ mp_msg(MSGT_VFILTER,MSGL_V,"REQ: flags=0x%X req=0x%X \n",flags,vf->default_reqs); ++ miss=vf->default_reqs - (flags&vf->default_reqs); ++ if(miss&VFCAP_ACCEPT_STRIDE){ ++ // vf requires stride support but vf->next doesn't support it! ++ // let's insert the 'expand' filter, it does the job for us: ++ vf_instance_t* vf2=vf_open_filter(vf->next,"expand",NULL); ++ if(!vf2) return 0; // shouldn't happen! ++ vf->next=vf2; ++ } ++ vf->next->w = width; vf->next->h = height; ++#endif ++ return 1; ++} ++ ++int vf_next_control(struct vf_instance *vf, int request, void* data){ ++ MPContext *m= (void*)vf; ++ av_log(m->avfctx, AV_LOG_DEBUG, "Received control %d\n", request); ++ return 0; ++} ++ ++static int vf_default_query_format(struct vf_instance *vf, unsigned int fmt){ ++ MPContext *m= (void*)vf; ++ int i; ++ av_log(m->avfctx, AV_LOG_DEBUG, "query %X\n", fmt); ++ ++ for(i=0; conversion_map[i].fmt; i++){ ++ if(fmt==conversion_map[i].fmt) ++ return 1; //we suport all ++ } ++ return 0; ++} ++ ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ MPContext *m = ctx->priv; ++ char name[256]; ++ int i; ++ ++ m->avfctx= ctx; ++ ++ if(!args || 1!=sscanf(args, "%255[^:=]", name)){ ++ av_log(ctx, AV_LOG_ERROR, "Invalid parameter.\n"); ++ return AVERROR(EINVAL); ++ } ++ args+= strlen(name)+1; ++ ++ for(i=0; ;i++){ ++ if(!filters[i] || !strcmp(name, filters[i]->name)) ++ break; ++ } ++ ++ if(!filters[i]){ ++ av_log(ctx, AV_LOG_ERROR, "Unknown filter %s\n", name); ++ return AVERROR(EINVAL); ++ } ++ ++ av_log(ctx, AV_LOG_WARNING, ++ "'%s' is a wrapped MPlayer filter (libmpcodecs). This filter may be removed\n" ++ "once it has been ported to a native libavfilter.\n", name); ++ ++ memset(&m->vf,0,sizeof(m->vf)); ++ m->vf.info= filters[i]; ++ ++ m->vf.next = &m->next_vf; ++ m->vf.put_image = vf_next_put_image; ++ m->vf.config = vf_next_config; ++ m->vf.query_format= vf_default_query_format; ++ m->vf.control = vf_next_control; ++ m->vf.default_caps=VFCAP_ACCEPT_STRIDE; ++ m->vf.default_reqs=0; ++ if(m->vf.info->opts) ++ av_log(ctx, AV_LOG_ERROR, "opts / m_struct_set is unsupported\n"); ++#if 0 ++ if(vf->info->opts) { // vf_vo get some special argument ++ const m_struct_t* st = vf->info->opts; ++ void* vf_priv = m_struct_alloc(st); ++ int n; ++ for(n = 0 ; args && args[2*n] ; n++) ++ m_struct_set(st,vf_priv,args[2*n],args[2*n+1]); ++ vf->priv = vf_priv; ++ args = NULL; ++ } else // Otherwise we should have the '_oldargs_' ++ if(args && !strcmp(args[0],"_oldargs_")) ++ args = (char**)args[1]; ++ else ++ args = NULL; ++#endif ++ if(m->vf.info->vf_open(&m->vf, args)<=0){ ++ av_log(ctx, AV_LOG_ERROR, "vf_open() of %s with arg=%s failed\n", name, args); ++ return -1; ++ } ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ AVFilterFormats *avfmts=NULL; ++ MPContext *m = ctx->priv; ++ enum PixelFormat lastpixfmt = PIX_FMT_NONE; ++ int i; ++ ++ for(i=0; conversion_map[i].fmt; i++){ ++ av_log(ctx, AV_LOG_DEBUG, "query: %X\n", conversion_map[i].fmt); ++ if(m->vf.query_format(&m->vf, conversion_map[i].fmt)){ ++ av_log(ctx, AV_LOG_DEBUG, "supported,adding\n"); ++ if (conversion_map[i].pix_fmt != lastpixfmt) { ++ avfilter_add_format(&avfmts, conversion_map[i].pix_fmt); ++ lastpixfmt = conversion_map[i].pix_fmt; ++ } ++ } ++ } ++ ++ //We assume all allowed input formats are also allowed output formats ++ avfilter_set_common_pixel_formats(ctx, avfmts); ++ return 0; ++} ++ ++static int config_inprops(AVFilterLink *inlink) ++{ ++ MPContext *m = inlink->dst->priv; ++ int i; ++ for(i=0; conversion_map[i].fmt && conversion_map[i].pix_fmt != inlink->format; i++); ++ ++ av_assert0(conversion_map[i].fmt && inlink->w && inlink->h); ++ ++ m->vf.fmt.have_configured = 1; ++ m->vf.fmt.orig_height = inlink->h; ++ m->vf.fmt.orig_width = inlink->w; ++ m->vf.fmt.orig_fmt = conversion_map[i].fmt; ++ ++ if(m->vf.config(&m->vf, inlink->w, inlink->h, inlink->w, inlink->h, 0, conversion_map[i].fmt)<=0) ++ return -1; ++ ++ return 0; ++} ++ ++static int config_outprops(AVFilterLink *outlink) ++{ ++ MPContext *m = outlink->src->priv; ++ ++ outlink->w = m->next_vf.w; ++ outlink->h = m->next_vf.h; ++ ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ MPContext *m = outlink->src->priv; ++ int ret; ++ ++ av_log(m->avfctx, AV_LOG_DEBUG, "mp request_frame\n"); ++ ++ for(m->frame_returned=0; !m->frame_returned;){ ++ ret=avfilter_request_frame(outlink->src->inputs[0]); ++ if(ret<0) ++ break; ++ } ++ ++ av_log(m->avfctx, AV_LOG_DEBUG, "mp request_frame ret=%d\n", ret); ++ return ret; ++} ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ++{ ++} ++ ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) ++{ ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ MPContext *m = inlink->dst->priv; ++ AVFilterBufferRef *inpic = inlink->cur_buf; ++ int i; ++ double pts= MP_NOPTS_VALUE; ++ mp_image_t* mpi = new_mp_image(inpic->video->w, inpic->video->h); ++ ++ if(inpic->pts != AV_NOPTS_VALUE) ++ pts= inpic->pts / av_q2d(inlink->time_base); ++ ++ for(i=0; conversion_map[i].fmt && conversion_map[i].pix_fmt != inlink->format; i++); ++ mp_image_setfmt(mpi,conversion_map[i].fmt); ++ ++ memcpy(mpi->planes, inpic->data, FFMIN(sizeof(inpic->data) , sizeof(mpi->planes))); ++ memcpy(mpi->stride, inpic->linesize, FFMIN(sizeof(inpic->linesize), sizeof(mpi->stride))); ++ ++ //FIXME pass interleced & tff flags around ++ ++ // mpi->flags|=MP_IMGFLAG_ALLOCATED; ? ++ mpi->flags |= MP_IMGFLAG_READABLE; ++ if(!(inpic->perms & AV_PERM_WRITE)) ++ mpi->flags |= MP_IMGFLAG_PRESERVE; ++ if(m->vf.put_image(&m->vf, mpi, pts) == 0){ ++ av_log(m->avfctx, AV_LOG_DEBUG, "put_image() says skip\n"); ++ } ++ free_mp_image(mpi); ++ ++ avfilter_unref_buffer(inpic); ++} ++ ++AVFilter avfilter_vf_mp = { ++ .name = "mp", ++ .description = NULL_IF_CONFIG_SMALL("Apply a libmpcodecs filter to the input video."), ++ .init = init, ++ .priv_size = sizeof(MPContext), ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .start_frame = start_frame, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, ++ .config_props = config_inprops, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_outprops, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_null.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_null.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_null.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_null.c 2012-05-14 14:08:54.822349804 +0200 +@@ -29,14 +29,14 @@ + + .priv_size = 0, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .start_frame = avfilter_null_start_frame, + .end_frame = avfilter_null_end_frame }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_overlay.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_overlay.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_overlay.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_overlay.c 2012-05-14 14:08:54.824349844 +0200 +@@ -28,14 +28,14 @@ + #include "avfilter.h" + #include "libavutil/eval.h" + #include "libavutil/avstring.h" ++#include "libavutil/opt.h" + #include "libavutil/pixdesc.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/mathematics.h" + #include "internal.h" ++#include "drawutils.h" + +-static const char *var_names[] = { +- "E", +- "PHI", +- "PI", ++static const char * const var_names[] = { + "main_w", "W", ///< width of the main video + "main_h", "H", ///< height of the main video + "overlay_w", "w", ///< width of the overlay video +@@ -44,9 +44,6 @@ + }; + + enum var_name { +- VAR_E, +- VAR_PHI, +- VAR_PI, + VAR_MAIN_W, VAR_MW, + VAR_MAIN_H, VAR_MH, + VAR_OVERLAY_W, VAR_OW, +@@ -57,61 +54,155 @@ + #define MAIN 0 + #define OVERLAY 1 + ++#define R 0 ++#define G 1 ++#define B 2 ++#define A 3 ++ ++#define Y 0 ++#define U 1 ++#define V 2 ++ + typedef struct { ++ const AVClass *class; + int x, y; ///< position of overlayed picture + ++ int allow_packed_rgb; ++ uint8_t main_is_packed_rgb; ++ uint8_t main_rgba_map[4]; ++ uint8_t main_has_alpha; ++ uint8_t overlay_is_packed_rgb; ++ uint8_t overlay_rgba_map[4]; ++ uint8_t overlay_has_alpha; ++ + AVFilterBufferRef *overpicref; + +- int max_plane_step[4]; ///< steps per pixel for each plane ++ int main_pix_step[4]; ///< steps per pixel for each plane of the main output ++ int overlay_pix_step[4]; ///< steps per pixel for each plane of the overlay + int hsub, vsub; ///< chroma subsampling values + +- char x_expr[256], y_expr[256]; ++ char *x_expr, *y_expr; + } OverlayContext; + ++#define OFFSET(x) offsetof(OverlayContext, x) ++ ++static const AVOption overlay_options[] = { ++ { "x", "set the x expression", OFFSET(x_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX }, ++ { "y", "set the y expression", OFFSET(y_expr), AV_OPT_TYPE_STRING, {.str = "0"}, CHAR_MIN, CHAR_MAX }, ++ {"rgb", "force packed RGB in input and output", OFFSET(allow_packed_rgb), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1 }, ++ {NULL}, ++}; ++ ++static const char *overlay_get_name(void *ctx) ++{ ++ return "overlay"; ++} ++ ++static const AVClass overlay_class = { ++ "OverlayContext", ++ overlay_get_name, ++ overlay_options ++}; ++ + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) + { + OverlayContext *over = ctx->priv; ++ char *args1 = av_strdup(args); ++ char *expr, *bufptr = NULL; ++ int ret = 0; ++ ++ over->class = &overlay_class; ++ av_opt_set_defaults(over); ++ ++ if (expr = av_strtok(args1, ":", &bufptr)) { ++ av_free(over->x_expr); ++ if (!(over->x_expr = av_strdup(expr))) { ++ ret = AVERROR(ENOMEM); ++ goto end; ++ } ++ } ++ if (expr = av_strtok(NULL, ":", &bufptr)) { ++ av_free(over->y_expr); ++ if (!(over->y_expr = av_strdup(expr))) { ++ ret = AVERROR(ENOMEM); ++ goto end; ++ } ++ } + +- av_strlcpy(over->x_expr, "0", sizeof(over->x_expr)); +- av_strlcpy(over->y_expr, "0", sizeof(over->y_expr)); +- +- if (args) +- sscanf(args, "%255[^:]:%255[^:]", over->x_expr, over->y_expr); ++ if (bufptr && (ret = av_set_options_string(over, bufptr, "=", ":")) < 0) ++ goto end; + +- return 0; ++end: ++ av_free(args1); ++ return ret; + } + + static av_cold void uninit(AVFilterContext *ctx) + { + OverlayContext *over = ctx->priv; + ++ av_freep(&over->x_expr); ++ av_freep(&over->y_expr); ++ + if (over->overpicref) + avfilter_unref_buffer(over->overpicref); + } + + static int query_formats(AVFilterContext *ctx) + { +- const enum PixelFormat inout_pix_fmts[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; +- const enum PixelFormat blend_pix_fmts[] = { PIX_FMT_YUVA420P, PIX_FMT_NONE }; +- AVFilterFormats *inout_formats = avfilter_make_format_list(inout_pix_fmts); +- AVFilterFormats *blend_formats = avfilter_make_format_list(blend_pix_fmts); +- +- avfilter_formats_ref(inout_formats, &ctx->inputs [MAIN ]->out_formats); +- avfilter_formats_ref(blend_formats, &ctx->inputs [OVERLAY]->out_formats); +- avfilter_formats_ref(inout_formats, &ctx->outputs[MAIN ]->in_formats ); ++ OverlayContext *over = ctx->priv; ++ ++ /* overlay formats contains alpha, for avoiding conversion with alpha information loss */ ++ const enum PixelFormat main_pix_fmts_yuv[] = { PIX_FMT_YUV420P, PIX_FMT_NONE }; ++ const enum PixelFormat overlay_pix_fmts_yuv[] = { PIX_FMT_YUVA420P, PIX_FMT_NONE }; ++ const enum PixelFormat main_pix_fmts_rgb[] = { ++ PIX_FMT_ARGB, PIX_FMT_RGBA, ++ PIX_FMT_ABGR, PIX_FMT_BGRA, ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ PIX_FMT_NONE ++ }; ++ const enum PixelFormat overlay_pix_fmts_rgb[] = { ++ PIX_FMT_ARGB, PIX_FMT_RGBA, ++ PIX_FMT_ABGR, PIX_FMT_BGRA, ++ PIX_FMT_NONE ++ }; ++ ++ AVFilterFormats *main_formats; ++ AVFilterFormats *overlay_formats; ++ ++ if (over->allow_packed_rgb) { ++ main_formats = avfilter_make_format_list(main_pix_fmts_rgb); ++ overlay_formats = avfilter_make_format_list(overlay_pix_fmts_rgb); ++ } else { ++ main_formats = avfilter_make_format_list(main_pix_fmts_yuv); ++ overlay_formats = avfilter_make_format_list(overlay_pix_fmts_yuv); ++ } ++ ++ avfilter_formats_ref(main_formats, &ctx->inputs [MAIN ]->out_formats); ++ avfilter_formats_ref(overlay_formats, &ctx->inputs [OVERLAY]->out_formats); ++ avfilter_formats_ref(main_formats, &ctx->outputs[MAIN ]->in_formats ); + + return 0; + } + ++static const enum PixelFormat alpha_pix_fmts[] = { ++ PIX_FMT_YUVA420P, PIX_FMT_ARGB, PIX_FMT_ABGR, PIX_FMT_RGBA, ++ PIX_FMT_BGRA, PIX_FMT_NONE ++}; ++ + static int config_input_main(AVFilterLink *inlink) + { + OverlayContext *over = inlink->dst->priv; + const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; + +- av_image_fill_max_pixsteps(over->max_plane_step, NULL, pix_desc); ++ av_image_fill_max_pixsteps(over->main_pix_step, NULL, pix_desc); ++ + over->hsub = pix_desc->log2_chroma_w; + over->vsub = pix_desc->log2_chroma_h; + ++ over->main_is_packed_rgb = ++ ff_fill_rgba_map(over->main_rgba_map, inlink->format) >= 0; ++ over->main_has_alpha = ff_fmt_is_in(inlink->format, alpha_pix_fmts); + return 0; + } + +@@ -122,13 +213,12 @@ + char *expr; + double var_values[VAR_VARS_NB], res; + int ret; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; ++ ++ av_image_fill_max_pixsteps(over->overlay_pix_step, NULL, pix_desc); + + /* Finish the configuration by evaluating the expressions + now when both inputs are configured. */ +- var_values[VAR_E ] = M_E; +- var_values[VAR_PHI] = M_PHI; +- var_values[VAR_PI ] = M_PI; +- + var_values[VAR_MAIN_W ] = var_values[VAR_MW] = ctx->inputs[MAIN ]->w; + var_values[VAR_MAIN_H ] = var_values[VAR_MH] = ctx->inputs[MAIN ]->h; + var_values[VAR_OVERLAY_W] = var_values[VAR_OW] = ctx->inputs[OVERLAY]->w; +@@ -148,6 +238,10 @@ + goto fail; + over->x = res; + ++ over->overlay_is_packed_rgb = ++ ff_fill_rgba_map(over->overlay_rgba_map, inlink->format) >= 0; ++ over->overlay_has_alpha = ff_fmt_is_in(inlink->format, alpha_pix_fmts); ++ + av_log(ctx, AV_LOG_INFO, + "main w:%d h:%d fmt:%s overlay x:%d y:%d w:%d h:%d fmt:%s\n", + ctx->inputs[MAIN]->w, ctx->inputs[MAIN]->h, +@@ -239,6 +333,10 @@ + ctx->outputs[0]->time_base); + } + ++// divide by 255 and round to nearest ++// apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16 ++#define FAST_DIV255(x) ((((x) + 128) * 257) >> 16) ++ + static void blend_slice(AVFilterContext *ctx, + AVFilterBufferRef *dst, AVFilterBufferRef *src, + int x, int y, int w, int h, +@@ -256,21 +354,72 @@ + start_y = FFMAX(y, slice_y); + height = end_y - start_y; + +- if (dst->format == PIX_FMT_BGR24 || dst->format == PIX_FMT_RGB24) { +- uint8_t *dp = dst->data[0] + x * 3 + start_y * dst->linesize[0]; ++ if (over->main_is_packed_rgb) { ++ uint8_t *dp = dst->data[0] + x * over->main_pix_step[0] + ++ start_y * dst->linesize[0]; + uint8_t *sp = src->data[0]; +- int b = dst->format == PIX_FMT_BGR24 ? 2 : 0; +- int r = dst->format == PIX_FMT_BGR24 ? 0 : 2; ++ uint8_t alpha; ///< the amount of overlay to blend on to main ++ const int dr = over->main_rgba_map[R]; ++ const int dg = over->main_rgba_map[G]; ++ const int db = over->main_rgba_map[B]; ++ const int da = over->main_rgba_map[A]; ++ const int dstep = over->main_pix_step[0]; ++ const int sr = over->overlay_rgba_map[R]; ++ const int sg = over->overlay_rgba_map[G]; ++ const int sb = over->overlay_rgba_map[B]; ++ const int sa = over->overlay_rgba_map[A]; ++ const int sstep = over->overlay_pix_step[0]; ++ const int main_has_alpha = over->main_has_alpha; + if (slice_y > y) + sp += (slice_y - y) * src->linesize[0]; + for (i = 0; i < height; i++) { + uint8_t *d = dp, *s = sp; + for (j = 0; j < width; j++) { +- d[r] = (d[r] * (0xff - s[3]) + s[0] * s[3] + 128) >> 8; +- d[1] = (d[1] * (0xff - s[3]) + s[1] * s[3] + 128) >> 8; +- d[b] = (d[b] * (0xff - s[3]) + s[2] * s[3] + 128) >> 8; +- d += 3; +- s += 4; ++ alpha = s[sa]; ++ ++ // if the main channel has an alpha channel, alpha has to be calculated ++ // to create an un-premultiplied (straight) alpha value ++ if (main_has_alpha && alpha != 0 && alpha != 255) { ++ // apply the general equation: ++ // alpha = alpha_overlay / ( (alpha_main + alpha_overlay) - (alpha_main * alpha_overlay) ) ++ alpha = ++ // the next line is a faster version of: 255 * 255 * alpha ++ ( (alpha << 16) - (alpha << 9) + alpha ) ++ / ++ // the next line is a faster version of: 255 * (alpha + d[da]) ++ ( ((alpha + d[da]) << 8 ) - (alpha + d[da]) ++ - d[da] * alpha ); ++ } ++ ++ switch (alpha) { ++ case 0: ++ break; ++ case 255: ++ d[dr] = s[sr]; ++ d[dg] = s[sg]; ++ d[db] = s[sb]; ++ break; ++ default: ++ // main_value = main_value * (1 - alpha) + overlay_value * alpha ++ // since alpha is in the range 0-255, the result must divided by 255 ++ d[dr] = FAST_DIV255(d[dr] * (255 - alpha) + s[sr] * alpha); ++ d[dg] = FAST_DIV255(d[dg] * (255 - alpha) + s[sg] * alpha); ++ d[db] = FAST_DIV255(d[db] * (255 - alpha) + s[sb] * alpha); ++ } ++ if (main_has_alpha) { ++ switch (alpha) { ++ case 0: ++ break; ++ case 255: ++ d[da] = s[sa]; ++ break; ++ default: ++ // apply alpha compositing: main_alpha += (1-main_alpha) * overlay_alpha ++ d[da] += FAST_DIV255((255 - d[da]) * s[sa]); ++ } ++ } ++ d += dstep; ++ s += sstep; + } + dp += dst->linesize[0]; + sp += src->linesize[0]; +@@ -305,7 +454,8 @@ + alpha = (alpha_v + alpha_h) >> 1; + } else + alpha = a[0]; +- *d = (*d * (0xff - alpha) + *s++ * alpha + 128) >> 8; ++ *d = FAST_DIV255(*d * (255 - alpha) + *s * alpha); ++ s++; + d++; + a += 1 << hsub; + } +@@ -355,7 +505,7 @@ + + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "main", ++ .inputs = (const AVFilterPad[]) {{ .name = "main", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, + .get_video_buffer= get_video_buffer, +@@ -373,7 +523,7 @@ + .min_perms = AV_PERM_READ, + .rej_perms = AV_PERM_REUSE2, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_pad.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_pad.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_pad.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_pad.c 2012-05-14 14:08:54.826349884 +0200 +@@ -21,103 +21,49 @@ + + /** + * @file +- * video padding filter and color source ++ * video padding filter + */ + + #include "avfilter.h" ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" + #include "libavutil/pixdesc.h" + #include "libavutil/colorspace.h" + #include "libavutil/avassert.h" +-#include "libavcore/imgutils.h" +-#include "libavcore/parseutils.h" +- +-enum { RED = 0, GREEN, BLUE, ALPHA }; +- +-static int fill_line_with_color(uint8_t *line[4], int line_step[4], int w, uint8_t color[4], +- enum PixelFormat pix_fmt, uint8_t rgba_color[4], int *is_packed_rgba) +-{ +- uint8_t rgba_map[4] = {0}; +- int i; +- const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[pix_fmt]; +- int hsub = pix_desc->log2_chroma_w; +- +- *is_packed_rgba = 1; +- switch (pix_fmt) { +- case PIX_FMT_ARGB: rgba_map[ALPHA] = 0; rgba_map[RED ] = 1; rgba_map[GREEN] = 2; rgba_map[BLUE ] = 3; break; +- case PIX_FMT_ABGR: rgba_map[ALPHA] = 0; rgba_map[BLUE ] = 1; rgba_map[GREEN] = 2; rgba_map[RED ] = 3; break; +- case PIX_FMT_RGBA: +- case PIX_FMT_RGB24: rgba_map[RED ] = 0; rgba_map[GREEN] = 1; rgba_map[BLUE ] = 2; rgba_map[ALPHA] = 3; break; +- case PIX_FMT_BGRA: +- case PIX_FMT_BGR24: rgba_map[BLUE ] = 0; rgba_map[GREEN] = 1; rgba_map[RED ] = 2; rgba_map[ALPHA] = 3; break; +- default: +- *is_packed_rgba = 0; +- } +- +- if (*is_packed_rgba) { +- line_step[0] = (av_get_bits_per_pixel(pix_desc))>>3; +- for (i = 0; i < 4; i++) +- color[rgba_map[i]] = rgba_color[i]; +- +- line[0] = av_malloc(w * line_step[0]); +- for (i = 0; i < w; i++) +- memcpy(line[0] + i * line_step[0], color, line_step[0]); +- } else { +- int plane; +- +- color[RED ] = RGB_TO_Y_CCIR(rgba_color[0], rgba_color[1], rgba_color[2]); +- color[GREEN] = RGB_TO_U_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); +- color[BLUE ] = RGB_TO_V_CCIR(rgba_color[0], rgba_color[1], rgba_color[2], 0); +- color[ALPHA] = rgba_color[3]; +- +- for (plane = 0; plane < 4; plane++) { +- int line_size; +- int hsub1 = (plane == 1 || plane == 2) ? hsub : 0; +- +- line_step[plane] = 1; +- line_size = (w >> hsub1) * line_step[plane]; +- line[plane] = av_malloc(line_size); +- memset(line[plane], color[plane], line_size); +- } +- } +- +- return 0; +-} +- +-static void draw_rectangle(AVFilterBufferRef *outpic, uint8_t *line[4], int line_step[4], +- int hsub, int vsub, int x, int y, int w, int h) +-{ +- int i, plane; +- uint8_t *p; +- +- for (plane = 0; plane < 4 && outpic->data[plane]; plane++) { +- int hsub1 = plane == 1 || plane == 2 ? hsub : 0; +- int vsub1 = plane == 1 || plane == 2 ? vsub : 0; +- +- p = outpic->data[plane] + (y >> vsub1) * outpic->linesize[plane]; +- for (i = 0; i < (h >> vsub1); i++) { +- memcpy(p + (x >> hsub1) * line_step[plane], line[plane], (w >> hsub1) * line_step[plane]); +- p += outpic->linesize[plane]; +- } +- } +-} +- +-static void copy_rectangle(AVFilterBufferRef *outpic,uint8_t *line[4], int line_step[4], int linesize[4], +- int hsub, int vsub, int x, int y, int y2, int w, int h) +-{ +- int i, plane; +- uint8_t *p; ++#include "libavutil/imgutils.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/mathematics.h" ++#include "drawutils.h" ++ ++static const char * const var_names[] = { ++ "in_w", "iw", ++ "in_h", "ih", ++ "out_w", "ow", ++ "out_h", "oh", ++ "x", ++ "y", ++ "a", ++ "sar", ++ "dar", ++ "hsub", ++ "vsub", ++ NULL ++}; + +- for (plane = 0; plane < 4 && outpic->data[plane]; plane++) { +- int hsub1 = plane == 1 || plane == 2 ? hsub : 0; +- int vsub1 = plane == 1 || plane == 2 ? vsub : 0; +- +- p = outpic->data[plane] + (y >> vsub1) * outpic->linesize[plane]; +- for (i = 0; i < (h >> vsub1); i++) { +- memcpy(p + (x >> hsub1) * line_step[plane], line[plane] + linesize[plane]*(i+(y2>>vsub1)), (w >> hsub1) * line_step[plane]); +- p += outpic->linesize[plane]; +- } +- } +-} ++enum var_name { ++ VAR_IN_W, VAR_IW, ++ VAR_IN_H, VAR_IH, ++ VAR_OUT_W, VAR_OW, ++ VAR_OUT_H, VAR_OH, ++ VAR_X, ++ VAR_Y, ++ VAR_A, ++ VAR_SAR, ++ VAR_DAR, ++ VAR_HSUB, ++ VAR_VSUB, ++ VARS_NB ++}; + + static int query_formats(AVFilterContext *ctx) + { +@@ -136,17 +82,20 @@ + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +-#if CONFIG_PAD_FILTER +- + typedef struct { + int w, h; ///< output dimensions, a value of 0 will result in the input size + int x, y; ///< offsets of the input area with respect to the padded area + int in_w, in_h; ///< width and height for the padded input video, which has to be aligned to the chroma values in order to avoid chroma issues + ++ char w_expr[256]; ///< width expression string ++ char h_expr[256]; ///< height expression string ++ char x_expr[256]; ///< width expression string ++ char y_expr[256]; ///< height expression string ++ + uint8_t color[4]; ///< color expressed either in YUVA or RGBA colorspace for the padding area + uint8_t *line[4]; + int line_step[4]; +@@ -159,18 +108,18 @@ + PadContext *pad = ctx->priv; + char color_string[128] = "black"; + ++ av_strlcpy(pad->w_expr, "iw", sizeof(pad->w_expr)); ++ av_strlcpy(pad->h_expr, "ih", sizeof(pad->h_expr)); ++ av_strlcpy(pad->x_expr, "0" , sizeof(pad->w_expr)); ++ av_strlcpy(pad->y_expr, "0" , sizeof(pad->h_expr)); ++ + if (args) +- sscanf(args, "%d:%d:%d:%d:%s", &pad->w, &pad->h, &pad->x, &pad->y, color_string); ++ sscanf(args, "%255[^:]:%255[^:]:%255[^:]:%255[^:]:%127s", ++ pad->w_expr, pad->h_expr, pad->x_expr, pad->y_expr, color_string); + + if (av_parse_color(pad->color, color_string, -1, ctx) < 0) + return AVERROR(EINVAL); + +- /* sanity check params */ +- if (pad->w < 0 || pad->h < 0) { +- av_log(ctx, AV_LOG_ERROR, "Negative size values are not acceptable.\n"); +- return AVERROR(EINVAL); +- } +- + return 0; + } + +@@ -191,11 +140,64 @@ + PadContext *pad = ctx->priv; + const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; + uint8_t rgba_color[4]; +- int is_packed_rgba; ++ int ret, is_packed_rgba; ++ double var_values[VARS_NB], res; ++ char *expr; + + pad->hsub = pix_desc->log2_chroma_w; + pad->vsub = pix_desc->log2_chroma_h; + ++ var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; ++ var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; ++ var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; ++ var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; ++ var_values[VAR_A] = (float) inlink->w / inlink->h; ++ var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? ++ (float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1; ++ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR]; ++ var_values[VAR_HSUB] = 1<hsub; ++ var_values[VAR_VSUB] = 1<vsub; ++ ++ /* evaluate width and height */ ++ av_expr_parse_and_eval(&res, (expr = pad->w_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx); ++ pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; ++ if ((ret = av_expr_parse_and_eval(&res, (expr = pad->h_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto eval_fail; ++ pad->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; ++ /* evaluate the width again, as it may depend on the evaluated output height */ ++ if ((ret = av_expr_parse_and_eval(&res, (expr = pad->w_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto eval_fail; ++ pad->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; ++ ++ /* evaluate x and y */ ++ av_expr_parse_and_eval(&res, (expr = pad->x_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx); ++ pad->x = var_values[VAR_X] = res; ++ if ((ret = av_expr_parse_and_eval(&res, (expr = pad->y_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto eval_fail; ++ pad->y = var_values[VAR_Y] = res; ++ /* evaluate x again, as it may depend on the evaluated y value */ ++ if ((ret = av_expr_parse_and_eval(&res, (expr = pad->x_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto eval_fail; ++ pad->x = var_values[VAR_X] = res; ++ ++ /* sanity check params */ ++ if (pad->w < 0 || pad->h < 0 || pad->x < 0 || pad->y < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Negative values are not acceptable.\n"); ++ return AVERROR(EINVAL); ++ } ++ + if (!pad->w) + pad->w = inlink->w; + if (!pad->h) +@@ -210,8 +212,8 @@ + pad->in_h = inlink->h & ~((1 << pad->vsub) - 1); + + memcpy(rgba_color, pad->color, sizeof(rgba_color)); +- fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color, +- inlink->format, rgba_color, &is_packed_rgba); ++ ff_fill_line_with_color(pad->line, pad->line_step, pad->w, pad->color, ++ inlink->format, rgba_color, &is_packed_rgba, NULL); + + av_log(ctx, AV_LOG_INFO, "w:%d h:%d -> w:%d h:%d x:%d y:%d color:0x%02X%02X%02X%02X[%s]\n", + inlink->w, inlink->h, pad->w, pad->h, pad->x, pad->y, +@@ -229,6 +231,12 @@ + } + + return 0; ++ ++eval_fail: ++ av_log(NULL, AV_LOG_ERROR, ++ "Error when evaluating the expression '%s'\n", expr); ++ return ret; ++ + } + + static int config_output(AVFilterLink *outlink) +@@ -243,9 +251,10 @@ + static AVFilterBufferRef *get_video_buffer(AVFilterLink *inlink, int perms, int w, int h) + { + PadContext *pad = inlink->dst->priv; ++ int align = (perms&AV_PERM_ALIGN) ? AVFILTER_ALIGN : 1; + + AVFilterBufferRef *picref = avfilter_get_video_buffer(inlink->dst->outputs[0], perms, +- w + (pad->w - pad->in_w), ++ w + (pad->w - pad->in_w) + 4*align, + h + (pad->h - pad->in_h)); + int plane; + +@@ -256,7 +265,7 @@ + int hsub = (plane == 1 || plane == 2) ? pad->hsub : 0; + int vsub = (plane == 1 || plane == 2) ? pad->vsub : 0; + +- picref->data[plane] += (pad->x >> hsub) * pad->line_step[plane] + ++ picref->data[plane] += FFALIGN(pad->x >> hsub, align) * pad->line_step[plane] + + (pad->y >> vsub) * picref->linesize[plane]; + } + +@@ -351,9 +360,10 @@ + } + + if (bar_h) { +- draw_rectangle(link->dst->outputs[0]->out_buf, +- pad->line, pad->line_step, pad->hsub, pad->vsub, +- 0, bar_y, pad->w, bar_h); ++ ff_draw_rectangle(link->dst->outputs[0]->out_buf->data, ++ link->dst->outputs[0]->out_buf->linesize, ++ pad->line, pad->line_step, pad->hsub, pad->vsub, ++ 0, bar_y, pad->w, bar_h); + avfilter_draw_slice(link->dst->outputs[0], bar_y, bar_h, slice_dir); + } + } +@@ -374,18 +384,20 @@ + draw_send_bar_slice(link, y, h, slice_dir, 1); + + /* left border */ +- draw_rectangle(outpic, pad->line, pad->line_step, pad->hsub, pad->vsub, +- 0, y, pad->x, h); ++ ff_draw_rectangle(outpic->data, outpic->linesize, pad->line, pad->line_step, ++ pad->hsub, pad->vsub, 0, y, pad->x, h); + + if(pad->needs_copy){ +- copy_rectangle(outpic, +- inpic->data, pad->line_step, inpic->linesize, pad->hsub, pad->vsub, +- pad->x, y, y-pad->y, inpic->video->w, h); ++ ff_copy_rectangle(outpic->data, outpic->linesize, ++ inpic->data, inpic->linesize, pad->line_step, ++ pad->hsub, pad->vsub, ++ pad->x, y, y-pad->y, inpic->video->w, h); + } + + /* right border */ +- draw_rectangle(outpic, pad->line, pad->line_step, pad->hsub, pad->vsub, +- pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h); ++ ff_draw_rectangle(outpic->data, outpic->linesize, ++ pad->line, pad->line_step, pad->hsub, pad->vsub, ++ pad->x + pad->in_w, y, pad->w - pad->x - pad->in_w, h); + avfilter_draw_slice(link->dst->outputs[0], y, h, slice_dir); + + draw_send_bar_slice(link, y, h, slice_dir, -1); +@@ -400,7 +412,7 @@ + .uninit = uninit, + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_input, + .get_video_buffer = get_video_buffer, +@@ -409,134 +421,8 @@ + .end_frame = end_frame, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output, }, + { .name = NULL}}, + }; +- +-#endif /* CONFIG_PAD_FILTER */ +- +-#if CONFIG_COLOR_FILTER +- +-typedef struct { +- int w, h; +- uint8_t color[4]; +- AVRational time_base; +- uint8_t *line[4]; +- int line_step[4]; +- int hsub, vsub; ///< chroma subsampling values +- uint64_t pts; +-} ColorContext; +- +-static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque) +-{ +- ColorContext *color = ctx->priv; +- char color_string[128] = "black"; +- char frame_size [128] = "320x240"; +- char frame_rate [128] = "25"; +- AVRational frame_rate_q; +- int ret; +- +- if (args) +- sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate); +- +- if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) { +- av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size); +- return AVERROR(EINVAL); +- } +- +- if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 || +- frame_rate_q.den <= 0 || frame_rate_q.num <= 0) { +- av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate); +- return AVERROR(EINVAL); +- } +- color->time_base.num = frame_rate_q.den; +- color->time_base.den = frame_rate_q.num; +- +- if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0) +- return ret; +- +- return 0; +-} +- +-static av_cold void color_uninit(AVFilterContext *ctx) +-{ +- ColorContext *color = ctx->priv; +- int i; +- +- for (i = 0; i < 4; i++) { +- av_freep(&color->line[i]); +- color->line_step[i] = 0; +- } +-} +- +-static int color_config_props(AVFilterLink *inlink) +-{ +- AVFilterContext *ctx = inlink->src; +- ColorContext *color = ctx->priv; +- uint8_t rgba_color[4]; +- int is_packed_rgba; +- const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; +- +- color->hsub = pix_desc->log2_chroma_w; +- color->vsub = pix_desc->log2_chroma_h; +- +- color->w &= ~((1 << color->hsub) - 1); +- color->h &= ~((1 << color->vsub) - 1); +- if (av_image_check_size(color->w, color->h, 0, ctx) < 0) +- return AVERROR(EINVAL); +- +- memcpy(rgba_color, color->color, sizeof(rgba_color)); +- fill_line_with_color(color->line, color->line_step, color->w, color->color, +- inlink->format, rgba_color, &is_packed_rgba); +- +- av_log(ctx, AV_LOG_INFO, "w:%d h:%d r:%d/%d color:0x%02x%02x%02x%02x[%s]\n", +- color->w, color->h, color->time_base.den, color->time_base.num, +- color->color[0], color->color[1], color->color[2], color->color[3], +- is_packed_rgba ? "rgba" : "yuva"); +- inlink->w = color->w; +- inlink->h = color->h; +- +- return 0; +-} +- +-static int color_request_frame(AVFilterLink *link) +-{ +- ColorContext *color = link->src->priv; +- AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); +- picref->video->pixel_aspect = (AVRational) {1, 1}; +- picref->pts = av_rescale_q(color->pts++, color->time_base, AV_TIME_BASE_Q); +- picref->pos = 0; +- +- avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); +- draw_rectangle(picref, +- color->line, color->line_step, color->hsub, color->vsub, +- 0, 0, color->w, color->h); +- avfilter_draw_slice(link, 0, color->h, 1); +- avfilter_end_frame(link); +- avfilter_unref_buffer(picref); +- +- return 0; +-} +- +-AVFilter avfilter_vsrc_color = { +- .name = "color", +- .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]"), +- +- .priv_size = sizeof(ColorContext), +- .init = color_init, +- .uninit = color_uninit, +- +- .query_formats = query_formats, +- +- .inputs = (AVFilterPad[]) {{ .name = NULL}}, +- +- .outputs = (AVFilterPad[]) {{ .name = "default", +- .type = AVMEDIA_TYPE_VIDEO, +- .request_frame = color_request_frame, +- .config_props = color_config_props }, +- { .name = NULL}}, +-}; +- +-#endif /* CONFIG_COLOR_FILTER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_pixdesctest.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_pixdesctest.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_pixdesctest.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_pixdesctest.c 2012-05-14 14:08:54.827349904 +0200 +@@ -92,7 +92,7 @@ + + for (i = y1; i < y1 + h1; i++) { + av_read_image_line(priv->line, +- inpic->data, ++ (void*)inpic->data, + inpic->linesize, + priv->pix_desc, + 0, i, c, w1, 0); +@@ -115,7 +115,7 @@ + .priv_size = sizeof(PixdescTestContext), + .uninit = uninit, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, + .draw_slice = draw_slice, +@@ -123,7 +123,7 @@ + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_scale.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_scale.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_scale.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_scale.c 2012-05-14 14:08:54.828349924 +0200 +@@ -24,11 +24,42 @@ + */ + + #include "avfilter.h" ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" ++#include "libavutil/mathematics.h" + #include "libavutil/pixdesc.h" ++#include "libavutil/avassert.h" + #include "libswscale/swscale.h" + ++static const char * const var_names[] = { ++ "in_w", "iw", ++ "in_h", "ih", ++ "out_w", "ow", ++ "out_h", "oh", ++ "a", ++ "sar", ++ "dar", ++ "hsub", ++ "vsub", ++ NULL ++}; ++ ++enum var_name { ++ VAR_IN_W, VAR_IW, ++ VAR_IN_H, VAR_IH, ++ VAR_OUT_W, VAR_OW, ++ VAR_OUT_H, VAR_OH, ++ VAR_A, ++ VAR_SAR, ++ VAR_DAR, ++ VAR_HSUB, ++ VAR_VSUB, ++ VARS_NB ++}; ++ + typedef struct { + struct SwsContext *sws; ///< software scaler context ++ struct SwsContext *isws[2]; ///< software scaler context for interlaced material + + /** + * New dimensions. Special values are: +@@ -41,6 +72,10 @@ + int hsub, vsub; ///< chroma subsampling + int slice_y; ///< top of current output slice + int input_is_pal; ///< set to 1 if the input format is paletted ++ int interlaced; ++ ++ char w_expr[256]; ///< width expression string ++ char h_expr[256]; ///< height expression string + } ScaleContext; + + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +@@ -48,21 +83,20 @@ + ScaleContext *scale = ctx->priv; + const char *p; + ++ av_strlcpy(scale->w_expr, "iw", sizeof(scale->w_expr)); ++ av_strlcpy(scale->h_expr, "ih", sizeof(scale->h_expr)); ++ + scale->flags = SWS_BILINEAR; + if (args) { +- sscanf(args, "%d:%d", &scale->w, &scale->h); ++ sscanf(args, "%255[^:]:%255[^:]", scale->w_expr, scale->h_expr); + p = strstr(args,"flags="); + if (p) scale->flags = strtoul(p+6, NULL, 0); ++ if(strstr(args,"interl=1")){ ++ scale->interlaced=1; ++ }else if(strstr(args,"interl=-1")) ++ scale->interlaced=-1; + } + +- /* sanity check params */ +- if (scale->w < -1 || scale->h < -1) { +- av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); +- return AVERROR(EINVAL); +- } +- if (scale->w == -1 && scale->h == -1) +- scale->w = scale->h = 0; +- + return 0; + } + +@@ -70,6 +104,8 @@ + { + ScaleContext *scale = ctx->priv; + sws_freeContext(scale->sws); ++ sws_freeContext(scale->isws[0]); ++ sws_freeContext(scale->isws[1]); + scale->sws = NULL; + } + +@@ -92,7 +128,7 @@ + if (ctx->outputs[0]) { + formats = NULL; + for (pix_fmt = 0; pix_fmt < PIX_FMT_NB; pix_fmt++) +- if ( sws_isSupportedOutput(pix_fmt) ++ if ( (sws_isSupportedOutput(pix_fmt) || pix_fmt == PIX_FMT_PAL8) + && (ret = avfilter_add_format(&formats, pix_fmt)) < 0) { + avfilter_formats_unref(&formats); + return ret; +@@ -107,8 +143,51 @@ + { + AVFilterContext *ctx = outlink->src; + AVFilterLink *inlink = outlink->src->inputs[0]; ++ enum PixelFormat outfmt = outlink->format; + ScaleContext *scale = ctx->priv; + int64_t w, h; ++ double var_values[VARS_NB], res; ++ char *expr; ++ int ret; ++ ++ var_values[VAR_IN_W] = var_values[VAR_IW] = inlink->w; ++ var_values[VAR_IN_H] = var_values[VAR_IH] = inlink->h; ++ var_values[VAR_OUT_W] = var_values[VAR_OW] = NAN; ++ var_values[VAR_OUT_H] = var_values[VAR_OH] = NAN; ++ var_values[VAR_A] = (float) inlink->w / inlink->h; ++ var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? ++ (float) inlink->sample_aspect_ratio.num / inlink->sample_aspect_ratio.den : 1; ++ var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR]; ++ var_values[VAR_HSUB] = 1<format].log2_chroma_w; ++ var_values[VAR_VSUB] = 1<format].log2_chroma_h; ++ ++ /* evaluate width and height */ ++ av_expr_parse_and_eval(&res, (expr = scale->w_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx); ++ scale->w = var_values[VAR_OUT_W] = var_values[VAR_OW] = res; ++ if ((ret = av_expr_parse_and_eval(&res, (expr = scale->h_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto fail; ++ scale->h = var_values[VAR_OUT_H] = var_values[VAR_OH] = res; ++ /* evaluate again the width, as it may depend on the output height */ ++ if ((ret = av_expr_parse_and_eval(&res, (expr = scale->w_expr), ++ var_names, var_values, ++ NULL, NULL, NULL, NULL, NULL, 0, ctx)) < 0) ++ goto fail; ++ scale->w = res; ++ ++ w = scale->w; ++ h = scale->h; ++ ++ /* sanity check params */ ++ if (w < -1 || h < -1) { ++ av_log(ctx, AV_LOG_ERROR, "Size values less than -1 are not acceptable.\n"); ++ return AVERROR(EINVAL); ++ } ++ if (w == -1 && h == -1) ++ scale->w = scale->h = 0; + + if (!(w = scale->w)) + w = inlink->w; +@@ -134,14 +213,39 @@ + scale->flags); + + scale->input_is_pal = av_pix_fmt_descriptors[inlink->format].flags & PIX_FMT_PAL; ++ if (outfmt == PIX_FMT_PAL8) outfmt = PIX_FMT_BGR8; + ++ if (scale->sws) ++ sws_freeContext(scale->sws); + scale->sws = sws_getContext(inlink ->w, inlink ->h, inlink ->format, +- outlink->w, outlink->h, outlink->format, ++ outlink->w, outlink->h, outfmt, + scale->flags, NULL, NULL, NULL); +- if (!scale->sws) ++ if (scale->isws[0]) ++ sws_freeContext(scale->isws[0]); ++ scale->isws[0] = sws_getContext(inlink ->w, inlink ->h/2, inlink ->format, ++ outlink->w, outlink->h/2, outfmt, ++ scale->flags, NULL, NULL, NULL); ++ if (scale->isws[1]) ++ sws_freeContext(scale->isws[1]); ++ scale->isws[1] = sws_getContext(inlink ->w, inlink ->h/2, inlink ->format, ++ outlink->w, outlink->h/2, outfmt, ++ scale->flags, NULL, NULL, NULL); ++ if (!scale->sws || !scale->isws[0] || !scale->isws[1]) + return AVERROR(EINVAL); + ++ if (inlink->sample_aspect_ratio.num){ ++ outlink->sample_aspect_ratio = av_mul_q((AVRational){outlink->h * inlink->w, outlink->w * inlink->h}, inlink->sample_aspect_ratio); ++ } else ++ outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; ++ + return 0; ++ ++fail: ++ av_log(NULL, AV_LOG_ERROR, ++ "Error when evaluating the expression '%s'.\n" ++ "Maybe the expression for out_w:'%s' or for out_h:'%s' is self-referencing.\n", ++ expr, scale->w_expr, scale->h_expr); ++ return ret; + } + + static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) +@@ -153,42 +257,63 @@ + scale->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; + scale->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; + +- outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); ++ outpicref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE|AV_PERM_ALIGN, outlink->w, outlink->h); + avfilter_copy_buffer_ref_props(outpicref, picref); + outpicref->video->w = outlink->w; + outpicref->video->h = outlink->h; + + outlink->out_buf = outpicref; + +- av_reduce(&outpicref->video->pixel_aspect.num, &outpicref->video->pixel_aspect.den, +- (int64_t)picref->video->pixel_aspect.num * outlink->h * link->w, +- (int64_t)picref->video->pixel_aspect.den * outlink->w * link->h, ++ av_reduce(&outpicref->video->sample_aspect_ratio.num, &outpicref->video->sample_aspect_ratio.den, ++ (int64_t)picref->video->sample_aspect_ratio.num * outlink->h * link->w, ++ (int64_t)picref->video->sample_aspect_ratio.den * outlink->w * link->h, + INT_MAX); + + scale->slice_y = 0; + avfilter_start_frame(outlink, avfilter_ref_buffer(outpicref, ~0)); + } + ++static int scale_slice(AVFilterLink *link, struct SwsContext *sws, int y, int h, int mul, int field) ++{ ++ ScaleContext *scale = link->dst->priv; ++ AVFilterBufferRef *cur_pic = link->cur_buf; ++ AVFilterBufferRef *out_buf = link->dst->outputs[0]->out_buf; ++ const uint8_t *in[4]; ++ uint8_t *out[4]; ++ int in_stride[4],out_stride[4]; ++ int i; ++ ++ for(i=0; i<4; i++){ ++ int vsub= ((i+1)&2) ? scale->vsub : 0; ++ in_stride[i] = cur_pic->linesize[i] * mul; ++ out_stride[i] = out_buf->linesize[i] * mul; ++ in[i] = cur_pic->data[i] + ((y>>vsub)+field) * cur_pic->linesize[i]; ++ out[i] = out_buf->data[i] + field * out_buf->linesize[i]; ++ } ++ if(scale->input_is_pal){ ++ in[1] = cur_pic->data[1]; ++ out[1] = out_buf->data[1]; ++ } ++ ++ return sws_scale(sws, in, in_stride, y/mul, h, ++ out,out_stride); ++} ++ + static void draw_slice(AVFilterLink *link, int y, int h, int slice_dir) + { + ScaleContext *scale = link->dst->priv; + int out_h; +- AVFilterBufferRef *cur_pic = link->cur_buf; +- const uint8_t *data[4]; + + if (scale->slice_y == 0 && slice_dir == -1) + scale->slice_y = link->dst->outputs[0]->h; + +- data[0] = cur_pic->data[0] + y * cur_pic->linesize[0]; +- data[1] = scale->input_is_pal ? +- cur_pic->data[1] : +- cur_pic->data[1] + (y>>scale->vsub) * cur_pic->linesize[1]; +- data[2] = cur_pic->data[2] + (y>>scale->vsub) * cur_pic->linesize[2]; +- data[3] = cur_pic->data[3] + y * cur_pic->linesize[3]; +- +- out_h = sws_scale(scale->sws, data, cur_pic->linesize, y, h, +- link->dst->outputs[0]->out_buf->data, +- link->dst->outputs[0]->out_buf->linesize); ++ if(scale->interlaced>0 || (scale->interlaced<0 && link->cur_buf->video->interlaced)){ ++ av_assert0(y%(2<vsub) == 0); ++ out_h = scale_slice(link, scale->isws[0], y, (h+1)/2, 2, 0); ++ out_h+= scale_slice(link, scale->isws[1], y, h /2, 2, 1); ++ }else{ ++ out_h = scale_slice(link, scale->sws, y, h, 1, 0); ++ } + + if (slice_dir == -1) + scale->slice_y -= out_h; +@@ -208,13 +333,13 @@ + + .priv_size = sizeof(ScaleContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, + .draw_slice = draw_slice, + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_props, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_select.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_select.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_select.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_select.c 2012-05-14 14:08:54.829349944 +0200 +@@ -0,0 +1,340 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * filter for selecting which frame passes in the filterchain ++ */ ++ ++#include "libavutil/eval.h" ++#include "libavutil/fifo.h" ++#include "avfilter.h" ++ ++static const char * const var_names[] = { ++ "TB", ///< timebase ++ ++ "pts", ///< original pts in the file of the frame ++ "start_pts", ///< first PTS in the stream, expressed in TB units ++ "prev_pts", ///< previous frame PTS ++ "prev_selected_pts", ///< previous selected frame PTS ++ ++ "t", ///< first PTS in seconds ++ "start_t", ///< first PTS in the stream, expressed in seconds ++ "prev_t", ///< previous frame time ++ "prev_selected_t", ///< previously selected time ++ ++ "pict_type", ///< the type of picture in the movie ++ "I", ++ "P", ++ "B", ++ "S", ++ "SI", ++ "SP", ++ "BI", ++ ++ "interlace_type", ///< the frame interlace type ++ "PROGRESSIVE", ++ "TOPFIRST", ++ "BOTTOMFIRST", ++ ++ "n", ///< frame number (starting from zero) ++ "selected_n", ///< selected frame number (starting from zero) ++ "prev_selected_n", ///< number of the last selected frame ++ ++ "key", ///< tell if the frame is a key frame ++ "pos", ///< original position in the file of the frame ++ ++ NULL ++}; ++ ++enum var_name { ++ VAR_TB, ++ ++ VAR_PTS, ++ VAR_START_PTS, ++ VAR_PREV_PTS, ++ VAR_PREV_SELECTED_PTS, ++ ++ VAR_T, ++ VAR_START_T, ++ VAR_PREV_T, ++ VAR_PREV_SELECTED_T, ++ ++ VAR_PICT_TYPE, ++ VAR_PICT_TYPE_I, ++ VAR_PICT_TYPE_P, ++ VAR_PICT_TYPE_B, ++ VAR_PICT_TYPE_S, ++ VAR_PICT_TYPE_SI, ++ VAR_PICT_TYPE_SP, ++ VAR_PICT_TYPE_BI, ++ ++ VAR_INTERLACE_TYPE, ++ VAR_INTERLACE_TYPE_P, ++ VAR_INTERLACE_TYPE_T, ++ VAR_INTERLACE_TYPE_B, ++ ++ VAR_N, ++ VAR_SELECTED_N, ++ VAR_PREV_SELECTED_N, ++ ++ VAR_KEY, ++ VAR_POS, ++ ++ VAR_VARS_NB ++}; ++ ++#define FIFO_SIZE 8 ++ ++typedef struct { ++ AVExpr *expr; ++ double var_values[VAR_VARS_NB]; ++ double select; ++ int cache_frames; ++ AVFifoBuffer *pending_frames; ///< FIFO buffer of video frames ++} SelectContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ SelectContext *select = ctx->priv; ++ int ret; ++ ++ if ((ret = av_expr_parse(&select->expr, args ? args : "1", ++ var_names, NULL, NULL, NULL, NULL, 0, ctx)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error while parsing expression '%s'\n", args); ++ return ret; ++ } ++ ++ select->pending_frames = av_fifo_alloc(FIFO_SIZE*sizeof(AVFilterBufferRef*)); ++ if (!select->pending_frames) { ++ av_log(ctx, AV_LOG_ERROR, "Failed to allocate pending frames buffer.\n"); ++ return AVERROR(ENOMEM); ++ } ++ return 0; ++} ++ ++#define INTERLACE_TYPE_P 0 ++#define INTERLACE_TYPE_T 1 ++#define INTERLACE_TYPE_B 2 ++ ++static int config_input(AVFilterLink *inlink) ++{ ++ SelectContext *select = inlink->dst->priv; ++ ++ select->var_values[VAR_N] = 0.0; ++ select->var_values[VAR_SELECTED_N] = 0.0; ++ ++ select->var_values[VAR_TB] = av_q2d(inlink->time_base); ++ ++ select->var_values[VAR_PREV_PTS] = NAN; ++ select->var_values[VAR_PREV_SELECTED_PTS] = NAN; ++ select->var_values[VAR_PREV_SELECTED_T] = NAN; ++ select->var_values[VAR_START_PTS] = NAN; ++ select->var_values[VAR_START_T] = NAN; ++ ++ select->var_values[VAR_PICT_TYPE_I] = AV_PICTURE_TYPE_I; ++ select->var_values[VAR_PICT_TYPE_P] = AV_PICTURE_TYPE_P; ++ select->var_values[VAR_PICT_TYPE_B] = AV_PICTURE_TYPE_B; ++ select->var_values[VAR_PICT_TYPE_SI] = AV_PICTURE_TYPE_SI; ++ select->var_values[VAR_PICT_TYPE_SP] = AV_PICTURE_TYPE_SP; ++ ++ select->var_values[VAR_INTERLACE_TYPE_P] = INTERLACE_TYPE_P; ++ select->var_values[VAR_INTERLACE_TYPE_T] = INTERLACE_TYPE_T; ++ select->var_values[VAR_INTERLACE_TYPE_B] = INTERLACE_TYPE_B; ++ ++ return 0; ++} ++ ++#define D2TS(d) (isnan(d) ? AV_NOPTS_VALUE : (int64_t)(d)) ++#define TS2D(ts) ((ts) == AV_NOPTS_VALUE ? NAN : (double)(ts)) ++ ++static int select_frame(AVFilterContext *ctx, AVFilterBufferRef *picref) ++{ ++ SelectContext *select = ctx->priv; ++ AVFilterLink *inlink = ctx->inputs[0]; ++ double res; ++ ++ if (isnan(select->var_values[VAR_START_PTS])) ++ select->var_values[VAR_START_PTS] = TS2D(picref->pts); ++ if (isnan(select->var_values[VAR_START_T])) ++ select->var_values[VAR_START_T] = TS2D(picref->pts) * av_q2d(inlink->time_base); ++ ++ select->var_values[VAR_PTS] = TS2D(picref->pts); ++ select->var_values[VAR_T ] = TS2D(picref->pts) * av_q2d(inlink->time_base); ++ select->var_values[VAR_POS] = picref->pos == -1 ? NAN : picref->pos; ++ select->var_values[VAR_PREV_PTS] = TS2D(picref ->pts); ++ ++ select->var_values[VAR_INTERLACE_TYPE] = ++ !picref->video->interlaced ? INTERLACE_TYPE_P : ++ picref->video->top_field_first ? INTERLACE_TYPE_T : INTERLACE_TYPE_B; ++ select->var_values[VAR_PICT_TYPE] = picref->video->pict_type; ++ ++ res = av_expr_eval(select->expr, select->var_values, NULL); ++ av_log(inlink->dst, AV_LOG_DEBUG, ++ "n:%d pts:%d t:%f pos:%d interlace_type:%c key:%d pict_type:%c " ++ "-> select:%f\n", ++ (int)select->var_values[VAR_N], ++ (int)select->var_values[VAR_PTS], ++ select->var_values[VAR_T], ++ (int)select->var_values[VAR_POS], ++ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_P ? 'P' : ++ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_T ? 'T' : ++ select->var_values[VAR_INTERLACE_TYPE] == INTERLACE_TYPE_B ? 'B' : '?', ++ (int)select->var_values[VAR_KEY], ++ av_get_picture_type_char(select->var_values[VAR_PICT_TYPE]), ++ res); ++ ++ select->var_values[VAR_N] += 1.0; ++ ++ if (res) { ++ select->var_values[VAR_PREV_SELECTED_N] = select->var_values[VAR_N]; ++ select->var_values[VAR_PREV_SELECTED_PTS] = select->var_values[VAR_PTS]; ++ select->var_values[VAR_PREV_SELECTED_T] = select->var_values[VAR_T]; ++ select->var_values[VAR_SELECTED_N] += 1.0; ++ } ++ return res; ++} ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ++{ ++ SelectContext *select = inlink->dst->priv; ++ ++ select->select = select_frame(inlink->dst, picref); ++ if (select->select) { ++ /* frame was requested through poll_frame */ ++ if (select->cache_frames) { ++ if (!av_fifo_space(select->pending_frames)) ++ av_log(inlink->dst, AV_LOG_ERROR, ++ "Buffering limit reached, cannot cache more frames\n"); ++ else ++ av_fifo_generic_write(select->pending_frames, &picref, ++ sizeof(picref), NULL); ++ return; ++ } ++ avfilter_start_frame(inlink->dst->outputs[0], avfilter_ref_buffer(picref, ~0)); ++ } ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ SelectContext *select = inlink->dst->priv; ++ ++ if (select->select && !select->cache_frames) ++ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ SelectContext *select = inlink->dst->priv; ++ AVFilterBufferRef *picref = inlink->cur_buf; ++ ++ if (select->select) { ++ if (select->cache_frames) ++ return; ++ avfilter_end_frame(inlink->dst->outputs[0]); ++ } ++ avfilter_unref_buffer(picref); ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ SelectContext *select = ctx->priv; ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ select->select = 0; ++ ++ if (av_fifo_size(select->pending_frames)) { ++ AVFilterBufferRef *picref; ++ av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL); ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, outlink->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ return 0; ++ } ++ ++ while (!select->select) { ++ int ret = avfilter_request_frame(inlink); ++ if (ret < 0) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++static int poll_frame(AVFilterLink *outlink) ++{ ++ SelectContext *select = outlink->src->priv; ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ int count, ret; ++ ++ if (!av_fifo_size(select->pending_frames)) { ++ if ((count = avfilter_poll_frame(inlink)) <= 0) ++ return count; ++ /* request frame from input, and apply select condition to it */ ++ select->cache_frames = 1; ++ while (count-- && av_fifo_space(select->pending_frames)) { ++ ret = avfilter_request_frame(inlink); ++ if (ret < 0) ++ break; ++ } ++ select->cache_frames = 0; ++ } ++ ++ return av_fifo_size(select->pending_frames)/sizeof(AVFilterBufferRef *); ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ SelectContext *select = ctx->priv; ++ AVFilterBufferRef *picref; ++ ++ av_expr_free(select->expr); ++ select->expr = NULL; ++ ++ while (select->pending_frames && ++ av_fifo_generic_read(select->pending_frames, &picref, sizeof(picref), NULL) == sizeof(picref)) ++ avfilter_unref_buffer(picref); ++ av_fifo_free(select->pending_frames); ++ select->pending_frames = NULL; ++} ++ ++AVFilter avfilter_vf_select = { ++ .name = "select", ++ .description = NULL_IF_CONFIG_SMALL("Select frames to pass in output."), ++ .init = init, ++ .uninit = uninit, ++ ++ .priv_size = sizeof(SelectContext), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .config_props = config_input, ++ .start_frame = start_frame, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame }, ++ { .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .poll_frame = poll_frame, ++ .request_frame = request_frame, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_setpts.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_setpts.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_setpts.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_setpts.c 2012-05-14 14:08:54.830349964 +0200 +@@ -27,14 +27,12 @@ + /* #define DEBUG */ + + #include "libavutil/eval.h" ++#include "libavutil/mathematics.h" + #include "avfilter.h" + +-static const char *var_names[] = { +- "E", ///< Euler number ++static const char * const var_names[] = { + "INTERLACED", ///< tell if the current frame is interlaced + "N", ///< frame number (starting at zero) +- "PHI", ///< golden ratio +- "PI", ///< greek pi + "POS", ///< original position in the file of the frame + "PREV_INPTS", ///< previous input PTS + "PREV_OUTPTS", ///< previous output PTS +@@ -45,11 +43,8 @@ + }; + + enum var_name { +- VAR_E, + VAR_INTERLACED, + VAR_N, +- VAR_PHI, +- VAR_PI, + VAR_POS, + VAR_PREV_INPTS, + VAR_PREV_OUTPTS, +@@ -75,10 +70,7 @@ + return ret; + } + +- setpts->var_values[VAR_E ] = M_E; + setpts->var_values[VAR_N ] = 0.0; +- setpts->var_values[VAR_PHI ] = M_PHI; +- setpts->var_values[VAR_PI ] = M_PI; + setpts->var_values[VAR_PREV_INPTS ] = NAN; + setpts->var_values[VAR_PREV_OUTPTS] = NAN; + setpts->var_values[VAR_STARTPTS ] = NAN; +@@ -145,13 +137,13 @@ + + .priv_size = sizeof(SetPTSContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .config_props = config_input, + .start_frame = start_frame, }, + { .name = NULL }}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_settb.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_settb.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_settb.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_settb.c 2012-05-14 14:08:54.831349984 +0200 +@@ -25,23 +25,18 @@ + + #include "libavutil/avstring.h" + #include "libavutil/eval.h" ++#include "libavutil/mathematics.h" + #include "libavutil/rational.h" + #include "avfilter.h" + #include "internal.h" + +-static const char *var_names[] = { +- "E", +- "PHI", +- "PI", ++static const char * const var_names[] = { + "AVTB", /* default timebase 1/AV_TIME_BASE */ + "intb", /* input timebase */ + NULL + }; + + enum var_name { +- VAR_E, +- VAR_PHI, +- VAR_PI, + VAR_AVTB, + VAR_INTB, + VAR_VARS_NB +@@ -72,9 +67,6 @@ + int ret; + double res; + +- settb->var_values[VAR_E] = M_E; +- settb->var_values[VAR_PHI] = M_PHI; +- settb->var_values[VAR_PI] = M_PI; + settb->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q); + settb->var_values[VAR_INTB] = av_q2d(inlink->time_base); + +@@ -127,14 +119,14 @@ + + .priv_size = sizeof(SetTBContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .start_frame = start_frame, + .end_frame = avfilter_null_end_frame }, + { .name = NULL }}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .config_props = config_output_props, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_showinfo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_showinfo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_showinfo.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_showinfo.c 2012-05-14 14:08:54.831349984 +0200 +@@ -0,0 +1,98 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * filter for showing textual video frame information ++ */ ++ ++#include "libavutil/adler32.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++ ++typedef struct { ++ unsigned int frame; ++} ShowInfoContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ ShowInfoContext *showinfo = ctx->priv; ++ showinfo->frame = 0; ++ return 0; ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ ShowInfoContext *showinfo = ctx->priv; ++ AVFilterBufferRef *picref = inlink->cur_buf; ++ uint32_t plane_checksum[4] = {0}, checksum = 0; ++ int i, plane, vsub = av_pix_fmt_descriptors[inlink->format].log2_chroma_h; ++ ++ for (plane = 0; picref->data[plane] && plane < 4; plane++) { ++ size_t linesize = av_image_get_linesize(picref->format, picref->video->w, plane); ++ uint8_t *data = picref->data[plane]; ++ int h = plane == 1 || plane == 2 ? inlink->h >> vsub : inlink->h; ++ ++ for (i = 0; i < h; i++) { ++ plane_checksum[plane] = av_adler32_update(plane_checksum[plane], data, linesize); ++ checksum = av_adler32_update(checksum, data, linesize); ++ data += picref->linesize[plane]; ++ } ++ } ++ ++ av_log(ctx, AV_LOG_INFO, ++ "n:%d pts:%"PRId64" pts_time:%f pos:%"PRId64" " ++ "fmt:%s sar:%d/%d s:%dx%d i:%c iskey:%d type:%c " ++ "checksum:%08X plane_checksum:[%08X %08X %08X %08X]\n", ++ showinfo->frame, ++ picref->pts, picref ->pts * av_q2d(inlink->time_base), picref->pos, ++ av_pix_fmt_descriptors[picref->format].name, ++ picref->video->sample_aspect_ratio.num, picref->video->sample_aspect_ratio.den, ++ picref->video->w, picref->video->h, ++ !picref->video->interlaced ? 'P' : /* Progressive */ ++ picref->video->top_field_first ? 'T' : 'B', /* Top / Bottom */ ++ picref->video->key_frame, ++ av_get_picture_type_char(picref->video->pict_type), ++ checksum, plane_checksum[0], plane_checksum[1], plane_checksum[2], plane_checksum[3]); ++ ++ showinfo->frame++; ++ avfilter_end_frame(inlink->dst->outputs[0]); ++} ++ ++AVFilter avfilter_vf_showinfo = { ++ .name = "showinfo", ++ .description = NULL_IF_CONFIG_SMALL("Show textual information for each video frame."), ++ ++ .priv_size = sizeof(ShowInfoContext), ++ .init = init, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = avfilter_null_start_frame, ++ .end_frame = end_frame, ++ .min_perms = AV_PERM_READ, }, ++ { .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_slicify.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_slicify.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_slicify.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_slicify.c 2012-05-14 14:08:54.832350004 +0200 +@@ -103,7 +103,7 @@ + + .priv_size = sizeof(SliceContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = avfilter_null_get_video_buffer, + .start_frame = start_frame, +@@ -111,7 +111,7 @@ + .config_props = config_props, + .end_frame = avfilter_null_end_frame, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_split.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_split.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_split.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_split.c 2012-05-14 14:08:54.832350004 +0200 +@@ -0,0 +1,66 @@ ++/* ++ * Copyright (c) 2007 Bobby Bingham ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Video splitter ++ */ ++ ++#include "avfilter.h" ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ++{ ++ avfilter_start_frame(inlink->dst->outputs[0], ++ avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); ++ avfilter_start_frame(inlink->dst->outputs[1], ++ avfilter_ref_buffer(picref, ~AV_PERM_WRITE)); ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ avfilter_draw_slice(inlink->dst->outputs[0], y, h, slice_dir); ++ avfilter_draw_slice(inlink->dst->outputs[1], y, h, slice_dir); ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ avfilter_end_frame(inlink->dst->outputs[0]); ++ avfilter_end_frame(inlink->dst->outputs[1]); ++ ++ avfilter_unref_buffer(inlink->cur_buf); ++} ++ ++AVFilter avfilter_vf_split = { ++ .name = "split", ++ .description = NULL_IF_CONFIG_SMALL("Pass on the input to two outputs."), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer= avfilter_null_get_video_buffer, ++ .start_frame = start_frame, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame, }, ++ { .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "output1", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = "output2", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_swapuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_swapuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_swapuv.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_swapuv.c 2012-05-14 14:08:54.833350024 +0200 +@@ -0,0 +1,93 @@ ++/* ++ * Copyright (c) 2002 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * swap UV filter ++ */ ++ ++#include "avfilter.h" ++ ++static AVFilterBufferRef *get_video_buffer(AVFilterLink *link, int perms, ++ int w, int h) ++{ ++ AVFilterBufferRef *picref = ++ avfilter_default_get_video_buffer(link, perms, w, h); ++ uint8_t *tmp; ++ int tmp2; ++ ++ tmp = picref->data[2]; ++ picref->data[2] = picref->data[1]; ++ picref->data[1] = tmp; ++ ++ tmp2 = picref->linesize[2]; ++ picref->linesize[2] = picref->linesize[1]; ++ picref->linesize[1] = tmp2; ++ ++ return picref; ++} ++ ++static void start_frame(AVFilterLink *link, AVFilterBufferRef *inpicref) ++{ ++ AVFilterBufferRef *outpicref = avfilter_ref_buffer(inpicref, ~0); ++ ++ outpicref->data[1] = inpicref->data[2]; ++ outpicref->data[2] = inpicref->data[1]; ++ ++ outpicref->linesize[1] = inpicref->linesize[2]; ++ outpicref->linesize[2] = inpicref->linesize[1]; ++ ++ avfilter_start_frame(link->dst->outputs[0], outpicref); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, PIX_FMT_YUVA420P, ++ PIX_FMT_YUV444P, PIX_FMT_YUVJ444P, ++ PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, ++ PIX_FMT_YUV422P, PIX_FMT_YUVJ422P, ++ PIX_FMT_YUV411P, ++ PIX_FMT_NONE, ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vf_swapuv = { ++ .name = "swapuv", ++ .description = NULL_IF_CONFIG_SMALL("Swap U and V components."), ++ .priv_size = 0, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = get_video_buffer, ++ .start_frame = start_frame, }, ++ { .name = NULL } ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, }, ++ { .name = NULL } ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_thumbnail.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_thumbnail.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_thumbnail.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_thumbnail.c 2012-05-14 14:08:54.834350045 +0200 +@@ -0,0 +1,243 @@ ++/* ++ * Copyright (c) 2011 Smartjog S.A.S, Clément Bœsch ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Potential thumbnail lookup filter to reduce the risk of an inappropriate ++ * selection (such as a black frame) we could get with an absolute seek. ++ * ++ * Simplified version of algorithm by Vadim Zaliva . ++ * @url http://notbrainsurgery.livejournal.com/29773.html ++ */ ++ ++#include "avfilter.h" ++ ++#define HIST_SIZE (3*256) ++ ++struct thumb_frame { ++ AVFilterBufferRef *buf; ///< cached frame ++ int histogram[HIST_SIZE]; ///< RGB color distribution histogram of the frame ++}; ++ ++typedef struct { ++ int n; ///< current frame ++ int n_frames; ///< number of frames for analysis ++ struct thumb_frame *frames; ///< the n_frames frames ++} ThumbContext; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ ThumbContext *thumb = ctx->priv; ++ ++ if (!args) { ++ thumb->n_frames = 100; ++ } else { ++ int n = sscanf(args, "%d", &thumb->n_frames); ++ if (n != 1 || thumb->n_frames < 2) { ++ thumb->n_frames = 0; ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid number of frames specified (minimum is 2).\n"); ++ return AVERROR(EINVAL); ++ } ++ } ++ thumb->frames = av_calloc(thumb->n_frames, sizeof(*thumb->frames)); ++ if (!thumb->frames) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Allocation failure, try to lower the number of frames\n"); ++ return AVERROR(ENOMEM); ++ } ++ av_log(ctx, AV_LOG_INFO, "batch size: %d frames\n", thumb->n_frames); ++ return 0; ++} ++ ++static void draw_slice(AVFilterLink *inlink, int y, int h, int slice_dir) ++{ ++ int i, j; ++ AVFilterContext *ctx = inlink->dst; ++ ThumbContext *thumb = ctx->priv; ++ int *hist = thumb->frames[thumb->n].histogram; ++ AVFilterBufferRef *picref = inlink->cur_buf; ++ const uint8_t *p = picref->data[0] + y * picref->linesize[0]; ++ ++ // update current frame RGB histogram ++ for (j = 0; j < h; j++) { ++ for (i = 0; i < inlink->w; i++) { ++ hist[0*256 + p[i*3 ]]++; ++ hist[1*256 + p[i*3 + 1]]++; ++ hist[2*256 + p[i*3 + 2]]++; ++ } ++ p += picref->linesize[0]; ++ } ++} ++ ++/** ++ * @brief Compute Sum-square deviation to estimate "closeness". ++ * @param hist color distribution histogram ++ * @param median average color distribution histogram ++ * @return sum of squared errors ++ */ ++static double frame_sum_square_err(const int *hist, const double *median) ++{ ++ int i; ++ double err, sum_sq_err = 0; ++ ++ for (i = 0; i < HIST_SIZE; i++) { ++ err = median[i] - (double)hist[i]; ++ sum_sq_err += err*err; ++ } ++ return sum_sq_err; ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ int i, j, best_frame_idx = 0; ++ double avg_hist[HIST_SIZE] = {0}, sq_err, min_sq_err = -1; ++ AVFilterLink *outlink = inlink->dst->outputs[0]; ++ ThumbContext *thumb = inlink->dst->priv; ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterBufferRef *picref; ++ ++ // keep a reference of each frame ++ thumb->frames[thumb->n].buf = inlink->cur_buf; ++ ++ // no selection until the buffer of N frames is filled up ++ if (thumb->n < thumb->n_frames - 1) { ++ thumb->n++; ++ return; ++ } ++ ++ // average histogram of the N frames ++ for (j = 0; j < FF_ARRAY_ELEMS(avg_hist); j++) { ++ for (i = 0; i < thumb->n_frames; i++) ++ avg_hist[j] += (double)thumb->frames[i].histogram[j]; ++ avg_hist[j] /= thumb->n_frames; ++ } ++ ++ // find the frame closer to the average using the sum of squared errors ++ for (i = 0; i < thumb->n_frames; i++) { ++ sq_err = frame_sum_square_err(thumb->frames[i].histogram, avg_hist); ++ if (i == 0 || sq_err < min_sq_err) ++ best_frame_idx = i, min_sq_err = sq_err; ++ } ++ ++ // free and reset everything (except the best frame buffer) ++ for (i = 0; i < thumb->n_frames; i++) { ++ memset(thumb->frames[i].histogram, 0, sizeof(thumb->frames[i].histogram)); ++ if (i == best_frame_idx) ++ continue; ++ avfilter_unref_buffer(thumb->frames[i].buf); ++ thumb->frames[i].buf = NULL; ++ } ++ thumb->n = 0; ++ ++ // raise the chosen one ++ picref = thumb->frames[best_frame_idx].buf; ++ av_log(ctx, AV_LOG_INFO, "frame id #%d (pts_time=%f) selected\n", ++ best_frame_idx, picref->pts * av_q2d(inlink->time_base)); ++ avfilter_start_frame(outlink, picref); ++ thumb->frames[best_frame_idx].buf = NULL; ++ avfilter_draw_slice(outlink, 0, inlink->h, 1); ++ avfilter_end_frame(outlink); ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ int i; ++ ThumbContext *thumb = ctx->priv; ++ for (i = 0; i < thumb->n_frames && thumb->frames[i].buf; i++) { ++ avfilter_unref_buffer(thumb->frames[i].buf); ++ thumb->frames[i].buf = NULL; ++ } ++ av_freep(&thumb->frames); ++} ++ ++static void null_start_frame(AVFilterLink *link, AVFilterBufferRef *picref) { } ++ ++static int request_frame(AVFilterLink *link) ++{ ++ ThumbContext *thumb = link->src->priv; ++ ++ /* loop until a frame thumbnail is available (when a frame is queued, ++ * thumb->n is reset to zero) */ ++ while (thumb->n) { ++ int ret = avfilter_request_frame(link->src->inputs[0]); ++ if (ret < 0) ++ return ret; ++ } ++ return 0; ++} ++ ++static int poll_frame(AVFilterLink *link) ++{ ++ ThumbContext *thumb = link->src->priv; ++ AVFilterLink *inlink = link->src->inputs[0]; ++ int ret, available_frames = avfilter_poll_frame(inlink); ++ ++ /* If the input link is not able to provide any frame, we can't do anything ++ * at the moment and thus have zero thumbnail available. */ ++ if (!available_frames) ++ return 0; ++ ++ /* Since at least one frame is available and the next frame will allow us ++ * to compute a thumbnail, we can return 1 frame. */ ++ if (thumb->n == thumb->n_frames - 1) ++ return 1; ++ ++ /* we have some frame(s) available in the input link, but not yet enough to ++ * output a thumbnail, so we request more */ ++ ret = avfilter_request_frame(inlink); ++ return ret < 0 ? ret : 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ PIX_FMT_NONE ++ }; ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vf_thumbnail = { ++ .name = "thumbnail", ++ .description = NULL_IF_CONFIG_SMALL("Select the most representative frame in a given sequence of consecutive frames."), ++ .priv_size = sizeof(ThumbContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .get_video_buffer = avfilter_null_get_video_buffer, ++ .start_frame = null_start_frame, ++ .draw_slice = draw_slice, ++ .end_frame = end_frame, ++ },{ .name = NULL } ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .poll_frame = poll_frame, ++ .rej_perms = AV_PERM_REUSE2, ++ },{ .name = NULL } ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_tinterlace.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_tinterlace.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_tinterlace.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_tinterlace.c 2012-05-14 14:08:54.835350065 +0200 +@@ -0,0 +1,328 @@ ++/* ++ * Copyright (c) 2011 Stefano Sabatini ++ * Copyright (c) 2010 Baptiste Coudurier ++ * Copyright (c) 2003 Michael Zucchi ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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. ++ * ++ * FFmpeg 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 FFmpeg if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * @file ++ * temporal field interlace filter, ported from MPlayer/libmpcodecs ++ */ ++ ++#include "libavutil/imgutils.h" ++#include "avfilter.h" ++#include "internal.h" ++ ++typedef struct { ++ int mode; ///< interlace mode selected ++ int frame; ///< number of the output frame ++ int vsub; ///< chroma vertical subsampling ++ AVFilterBufferRef *cur; ++ AVFilterBufferRef *next; ++ uint8_t *black_data[4]; ///< buffer used to fill padded lines ++ int black_linesize[4]; ++} TInterlaceContext; ++ ++#define FULL_SCALE_YUVJ_FORMATS \ ++ PIX_FMT_YUVJ420P, PIX_FMT_YUVJ422P, PIX_FMT_YUVJ444P, PIX_FMT_YUVJ440P ++ ++static enum PixelFormat full_scale_yuvj_pix_fmts[] = { ++ FULL_SCALE_YUVJ_FORMATS, PIX_FMT_NONE ++}; ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV420P, PIX_FMT_YUV422P, PIX_FMT_YUV444P, ++ PIX_FMT_YUV444P, PIX_FMT_YUV410P, PIX_FMT_YUVA420P, ++ PIX_FMT_GRAY8, FULL_SCALE_YUVJ_FORMATS, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ TInterlaceContext *tinterlace = ctx->priv; ++ int n; ++ tinterlace->mode = 0; ++ ++ if (args) { ++ n = sscanf(args, "%d", &tinterlace->mode); ++ ++ if (n != 1 || tinterlace->mode < 0 || tinterlace->mode > 5) { ++ av_log(ctx, AV_LOG_ERROR, ++ "Invalid mode '%s', use an integer between 0 and 5\n", args); ++ return AVERROR(EINVAL); ++ } ++ } ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ TInterlaceContext *tinterlace = ctx->priv; ++ ++ if (tinterlace->cur ) avfilter_unref_buffer(tinterlace->cur ); ++ if (tinterlace->next) avfilter_unref_buffer(tinterlace->next); ++ ++ av_freep(&tinterlace->black_data[0]); ++} ++ ++static int config_out_props(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[outlink->format]; ++ TInterlaceContext *tinterlace = ctx->priv; ++ ++ tinterlace->vsub = desc->log2_chroma_h; ++ outlink->w = inlink->w; ++ outlink->h = tinterlace->mode == 0 || tinterlace->mode == 3 ? ++ inlink->h*2 : inlink->h; ++ ++ if (tinterlace->mode == 3) { ++ uint8_t black[4] = { 16, 128, 128, 16 }; ++ int i, ret; ++ if (ff_fmt_is_in(outlink->format, full_scale_yuvj_pix_fmts)) ++ black[0] = black[3] = 0; ++ ret = av_image_alloc(tinterlace->black_data, tinterlace->black_linesize, ++ outlink->w, outlink->h, outlink->format, 1); ++ if (ret < 0) ++ return ret; ++ ++ /* fill black picture with black */ ++ for (i = 0; i < 4 && tinterlace->black_data[i]; i++) { ++ int h = i == 1 || i == 2 ? outlink->h >> desc->log2_chroma_h : outlink->h; ++ memset(tinterlace->black_data[i], black[i], ++ tinterlace->black_linesize[i] * h); ++ } ++ } ++ av_log(ctx, AV_LOG_INFO, "mode:%d h:%d -> h:%d\n", ++ tinterlace->mode, inlink->h, outlink->h); ++ ++ return 0; ++} ++ ++#define FIELD_UPPER 0 ++#define FIELD_LOWER 1 ++#define FIELD_UPPER_AND_LOWER 2 ++ ++/** ++ * Copy picture field from src to dst. ++ * ++ * @param src_field copy from upper, lower field or both ++ * @param interleave leave a padding line between each copied field ++ * @param dst_field copy to upper or lower field, ++ * only meaningful when interleave is selected ++ */ ++static inline ++void copy_picture_field(uint8_t *dst[4], int dst_linesize[4], ++ uint8_t *src[4], int src_linesize[4], ++ enum PixelFormat format, int w, int src_h, ++ int src_field, int interleave, int dst_field) ++{ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[format]; ++ int plane, vsub = desc->log2_chroma_h; ++ int k = src_field == FIELD_UPPER_AND_LOWER ? 1 : 2; ++ ++ for (plane = 0; plane < desc->nb_components; plane++) { ++ int lines = plane == 1 || plane == 2 ? src_h >> vsub : src_h; ++ int linesize = av_image_get_linesize(format, w, plane); ++ uint8_t *dstp = dst[plane]; ++ uint8_t *srcp = src[plane]; ++ lines /= k; ++ if (src_field == FIELD_LOWER) ++ srcp += src_linesize[plane]; ++ if (interleave && dst_field == FIELD_LOWER) ++ dstp += dst_linesize[plane]; ++ av_image_copy_plane(dstp, dst_linesize[plane] * (interleave ? 2 : 1), ++ srcp, src_linesize[plane]*k, linesize, lines); ++ } ++} ++ ++static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *picref) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ TInterlaceContext *tinterlace = ctx->priv; ++ ++ if (tinterlace->cur) ++ avfilter_unref_buffer(tinterlace->cur); ++ tinterlace->cur = tinterlace->next; ++ tinterlace->next = picref; ++} ++ ++static void end_frame(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->dst; ++ AVFilterLink *outlink = ctx->outputs[0]; ++ TInterlaceContext *tinterlace = ctx->priv; ++ AVFilterBufferRef *cur = tinterlace->cur; ++ AVFilterBufferRef *next = tinterlace->next; ++ AVFilterBufferRef *out = NULL; ++ int field, tff; ++ ++ /* we need at least two frames */ ++ if (!tinterlace->cur) ++ return; ++ ++ switch (tinterlace->mode) { ++ case 0: /* move the odd frame into the upper field of the new image, even into ++ * the lower field, generating a double-height video at half framerate */ ++ out = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); ++ avfilter_copy_buffer_ref_props(out, cur); ++ out->video->h = outlink->h; ++ out->video->interlaced = 1; ++ out->video->top_field_first = 1; ++ ++ /* write odd frame lines into the upper field of the new frame */ ++ copy_picture_field(out->data, out->linesize, ++ cur->data, cur->linesize, ++ inlink->format, inlink->w, inlink->h, ++ FIELD_UPPER_AND_LOWER, 1, FIELD_UPPER); ++ /* write even frame lines into the lower field of the new frame */ ++ copy_picture_field(out->data, out->linesize, ++ next->data, next->linesize, ++ inlink->format, inlink->w, inlink->h, ++ FIELD_UPPER_AND_LOWER, 1, FIELD_LOWER); ++ avfilter_unref_buffer(tinterlace->next); ++ tinterlace->next = NULL; ++ break; ++ ++ case 1: /* only output even frames, odd frames are dropped; height unchanged, half framerate */ ++ case 2: /* only output odd frames, even frames are dropped; height unchanged, half framerate */ ++ out = avfilter_ref_buffer(tinterlace->mode == 2 ? cur : next, AV_PERM_READ); ++ avfilter_unref_buffer(tinterlace->next); ++ tinterlace->next = NULL; ++ break; ++ ++ case 3: /* expand each frame to double height, but pad alternate ++ * lines with black; framerate unchanged */ ++ out = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); ++ avfilter_copy_buffer_ref_props(out, cur); ++ out->video->h = outlink->h; ++ ++ field = (1 + tinterlace->frame) & 1 ? FIELD_UPPER : FIELD_LOWER; ++ /* copy upper and lower fields */ ++ copy_picture_field(out->data, out->linesize, ++ cur->data, cur->linesize, ++ inlink->format, inlink->w, inlink->h, ++ FIELD_UPPER_AND_LOWER, 1, field); ++ /* pad with black the other field */ ++ copy_picture_field(out->data, out->linesize, ++ tinterlace->black_data, tinterlace->black_linesize, ++ inlink->format, inlink->w, inlink->h, ++ FIELD_UPPER_AND_LOWER, 1, !field); ++ break; ++ ++ /* interleave upper/lower lines from odd frames with lower/upper lines from even frames, ++ * halving the frame rate and preserving image height */ ++ case 4: /* top field first */ ++ case 5: /* bottom field first */ ++ tff = tinterlace->mode == 4; ++ out = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, outlink->w, outlink->h); ++ avfilter_copy_buffer_ref_props(out, cur); ++ out->video->interlaced = 1; ++ out->video->top_field_first = tff; ++ ++ /* copy upper/lower field from cur */ ++ copy_picture_field(out->data, out->linesize, ++ cur->data, cur->linesize, ++ inlink->format, inlink->w, inlink->h, ++ tff ? FIELD_UPPER : FIELD_LOWER, 1, tff ? FIELD_UPPER : FIELD_LOWER); ++ /* copy lower/upper field from next */ ++ copy_picture_field(out->data, out->linesize, ++ next->data, next->linesize, ++ inlink->format, inlink->w, inlink->h, ++ tff ? FIELD_LOWER : FIELD_UPPER, 1, tff ? FIELD_LOWER : FIELD_UPPER); ++ avfilter_unref_buffer(tinterlace->next); ++ tinterlace->next = NULL; ++ break; ++ } ++ ++ avfilter_start_frame(outlink, out); ++ avfilter_draw_slice(outlink, 0, outlink->h, 1); ++ avfilter_end_frame(outlink); ++ ++ tinterlace->frame++; ++} ++ ++static int poll_frame(AVFilterLink *outlink) ++{ ++ TInterlaceContext *tinterlace = outlink->src->priv; ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ int ret, val; ++ ++ val = avfilter_poll_frame(inlink); ++ ++ if (val == 1 && !tinterlace->next) { ++ if ((ret = avfilter_request_frame(inlink)) < 0) ++ return ret; ++ val = avfilter_poll_frame(inlink); ++ } ++ assert(tinterlace->next); ++ ++ return val; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ TInterlaceContext *tinterlace = outlink->src->priv; ++ AVFilterLink *inlink = outlink->src->inputs[0]; ++ ++ do { ++ int ret; ++ ++ if ((ret = avfilter_request_frame(inlink)) < 0) ++ return ret; ++ } while (!tinterlace->cur); ++ ++ return 0; ++} ++ ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } ++ ++AVFilter avfilter_vf_tinterlace = { ++ .name = "tinterlace", ++ .description = NULL_IF_CONFIG_SMALL("Perform temporal field interlacing."), ++ .priv_size = sizeof(TInterlaceContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .start_frame = start_frame, ++ .draw_slice = null_draw_slice, ++ .end_frame = end_frame, }, ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = config_out_props, ++ .poll_frame = poll_frame, ++ .request_frame = request_frame }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_transpose.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_transpose.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_transpose.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_transpose.c 2012-05-14 14:08:54.836350085 +0200 +@@ -27,7 +27,7 @@ + + #include "libavutil/intreadwrite.h" + #include "libavutil/pixdesc.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "avfilter.h" + + typedef struct { +@@ -69,21 +69,18 @@ + PIX_FMT_BGR555BE, PIX_FMT_BGR555LE, + PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE, + PIX_FMT_YUV420P16LE, PIX_FMT_YUV420P16BE, +- PIX_FMT_YUV422P16LE, PIX_FMT_YUV422P16BE, + PIX_FMT_YUV444P16LE, PIX_FMT_YUV444P16BE, + PIX_FMT_NV12, PIX_FMT_NV21, + PIX_FMT_RGB8, PIX_FMT_BGR8, + PIX_FMT_RGB4_BYTE, PIX_FMT_BGR4_BYTE, +- PIX_FMT_YUV444P, PIX_FMT_YUV422P, ++ PIX_FMT_YUV444P, PIX_FMT_YUVJ444P, + PIX_FMT_YUV420P, PIX_FMT_YUVJ420P, +- PIX_FMT_YUV411P, PIX_FMT_YUV410P, +- PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, +- PIX_FMT_YUV440P, PIX_FMT_YUVJ440P, ++ PIX_FMT_YUV410P, + PIX_FMT_YUVA420P, PIX_FMT_GRAY8, + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -102,6 +99,11 @@ + outlink->w = inlink->h; + outlink->h = inlink->w; + ++ if (inlink->sample_aspect_ratio.num){ ++ outlink->sample_aspect_ratio = av_div_q((AVRational){1,1}, inlink->sample_aspect_ratio); ++ } else ++ outlink->sample_aspect_ratio = inlink->sample_aspect_ratio; ++ + av_log(ctx, AV_LOG_INFO, "w:%d h:%d dir:%d -> w:%d h:%d rotation:%s vflip:%d\n", + inlink->w, inlink->h, trans->dir, outlink->w, outlink->h, + trans->dir == 1 || trans->dir == 3 ? "clockwise" : "counterclockwise", +@@ -117,11 +119,11 @@ + outlink->w, outlink->h); + outlink->out_buf->pts = picref->pts; + +- if (picref->video->pixel_aspect.num == 0) { +- outlink->out_buf->video->pixel_aspect = picref->video->pixel_aspect; ++ if (picref->video->sample_aspect_ratio.num == 0) { ++ outlink->out_buf->video->sample_aspect_ratio = picref->video->sample_aspect_ratio; + } else { +- outlink->out_buf->video->pixel_aspect.num = picref->video->pixel_aspect.den; +- outlink->out_buf->video->pixel_aspect.den = picref->video->pixel_aspect.num; ++ outlink->out_buf->video->sample_aspect_ratio.num = picref->video->sample_aspect_ratio.den; ++ outlink->out_buf->video->sample_aspect_ratio.den = picref->video->sample_aspect_ratio.num; + } + + avfilter_start_frame(outlink, avfilter_ref_buffer(outlink->out_buf, ~0)); +@@ -190,6 +192,8 @@ + avfilter_unref_buffer(outpic); + } + ++static void null_draw_slice(AVFilterLink *link, int y, int h, int slice_dir) { } ++ + AVFilter avfilter_vf_transpose = { + .name = "transpose", + .description = NULL_IF_CONFIG_SMALL("Transpose input video."), +@@ -199,13 +203,14 @@ + + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, ++ .draw_slice = null_draw_slice, + .end_frame = end_frame, + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .config_props = config_props_output, + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_unsharp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_unsharp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_unsharp.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_unsharp.c 2012-05-14 14:08:54.837350105 +0200 +@@ -44,8 +44,8 @@ + #define MIN_SIZE 3 + #define MAX_SIZE 13 + +-#define CHROMA_WIDTH(link) -((-link->w) >> av_pix_fmt_descriptors[link->format].log2_chroma_w) +-#define CHROMA_HEIGHT(link) -((-link->h) >> av_pix_fmt_descriptors[link->format].log2_chroma_h) ++/* right-shift and round-up */ ++#define SHIFTUP(x,shift) (-((-(x))>>(shift))) + + typedef struct FilterParam { + int msize_x; ///< matrix width +@@ -61,15 +61,19 @@ + typedef struct { + FilterParam luma; ///< luma parameters (width, height, amount) + FilterParam chroma; ///< chroma parameters (width, height, amount) ++ int hsub, vsub; + } UnsharpContext; + +-static void unsharpen(uint8_t *dst, uint8_t *src, int dst_stride, int src_stride, int width, int height, FilterParam *fp) ++static void apply_unsharp( uint8_t *dst, int dst_stride, ++ const uint8_t *src, int src_stride, ++ int width, int height, FilterParam *fp) + { + uint32_t **sc = fp->sc; + uint32_t sr[(MAX_SIZE * MAX_SIZE) - 1], tmp1, tmp2; + + int32_t res; + int x, y, z; ++ const uint8_t *src2 = NULL; //silence a warning + + if (!fp->amount) { + if (dst_stride == src_stride) +@@ -84,9 +88,12 @@ + memset(sc[y], 0, sizeof(sc[y][0]) * (width + 2 * fp->steps_x)); + + for (y = -fp->steps_y; y < height + fp->steps_y; y++) { ++ if (y < height) ++ src2 = src; ++ + memset(sr, 0, sizeof(sr[0]) * (2 * fp->steps_x - 1)); + for (x = -fp->steps_x; x < width + fp->steps_x; x++) { +- tmp1 = x <= 0 ? src[0] : x >= width ? src[width-1] : src[x]; ++ tmp1 = x <= 0 ? src2[0] : x >= width ? src2[width-1] : src2[x]; + for (z = 0; z < fp->steps_x * 2; z += 2) { + tmp2 = sr[z + 0] + tmp1; sr[z + 0] = tmp1; + tmp1 = sr[z + 1] + tmp2; sr[z + 1] = tmp2; +@@ -96,8 +103,8 @@ + tmp1 = sc[z + 1][x + fp->steps_x] + tmp2; sc[z + 1][x + fp->steps_x] = tmp2; + } + if (x >= fp->steps_x && y >= fp->steps_y) { +- uint8_t* srx = src - fp->steps_y * src_stride + x - fp->steps_x; +- uint8_t* dsx = dst - fp->steps_y * dst_stride + x - fp->steps_x; ++ const uint8_t *srx = src - fp->steps_y * src_stride + x - fp->steps_x; ++ uint8_t *dsx = dst - fp->steps_y * dst_stride + x - fp->steps_x; + + res = (int32_t)*srx + ((((int32_t) * srx - (int32_t)((tmp1 + fp->halfscale) >> fp->scalebits)) * fp->amount) >> 16); + *dsx = av_clip_uint8(res); +@@ -125,8 +132,8 @@ + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) + { + UnsharpContext *unsharp = ctx->priv; +- int lmsize_x = 5, cmsize_x = 0; +- int lmsize_y = 5, cmsize_y = 0; ++ int lmsize_x = 5, cmsize_x = 5; ++ int lmsize_y = 5, cmsize_y = 5; + double lamount = 1.0f, camount = 0.0f; + + if (args) +@@ -155,7 +162,7 @@ + PIX_FMT_YUVJ444P, PIX_FMT_YUVJ440P, PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + + return 0; + } +@@ -178,8 +185,11 @@ + { + UnsharpContext *unsharp = link->dst->priv; + ++ unsharp->hsub = av_pix_fmt_descriptors[link->format].log2_chroma_w; ++ unsharp->vsub = av_pix_fmt_descriptors[link->format].log2_chroma_h; ++ + init_filter_param(link->dst, &unsharp->luma, "luma", link->w); +- init_filter_param(link->dst, &unsharp->chroma, "chroma", CHROMA_WIDTH(link)); ++ init_filter_param(link->dst, &unsharp->chroma, "chroma", SHIFTUP(link->w, unsharp->hsub)); + + return 0; + } +@@ -205,10 +215,12 @@ + UnsharpContext *unsharp = link->dst->priv; + AVFilterBufferRef *in = link->cur_buf; + AVFilterBufferRef *out = link->dst->outputs[0]->out_buf; ++ int cw = SHIFTUP(link->w, unsharp->hsub); ++ int ch = SHIFTUP(link->h, unsharp->vsub); + +- unsharpen(out->data[0], in->data[0], out->linesize[0], in->linesize[0], link->w, link->h, &unsharp->luma); +- unsharpen(out->data[1], in->data[1], out->linesize[1], in->linesize[1], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma); +- unsharpen(out->data[2], in->data[2], out->linesize[2], in->linesize[2], CHROMA_WIDTH(link), CHROMA_HEIGHT(link), &unsharp->chroma); ++ apply_unsharp(out->data[0], out->linesize[0], in->data[0], in->linesize[0], link->w, link->h, &unsharp->luma); ++ apply_unsharp(out->data[1], out->linesize[1], in->data[1], in->linesize[1], cw, ch, &unsharp->chroma); ++ apply_unsharp(out->data[2], out->linesize[2], in->data[2], in->linesize[2], cw, ch, &unsharp->chroma); + + avfilter_unref_buffer(in); + avfilter_draw_slice(link->dst->outputs[0], 0, link->h, 1); +@@ -230,7 +242,7 @@ + .uninit = uninit, + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .draw_slice = draw_slice, + .end_frame = end_frame, +@@ -238,7 +250,7 @@ + .min_perms = AV_PERM_READ, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_vflip.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_vflip.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_vflip.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_vflip.c 2012-05-14 14:08:54.838350125 +0200 +@@ -93,14 +93,14 @@ + + .priv_size = sizeof(FlipContext), + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .get_video_buffer = get_video_buffer, + .start_frame = start_frame, + .draw_slice = draw_slice, + .config_props = config_input, }, + { .name = NULL}}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, }, + { .name = NULL}}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_yadif.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_yadif.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vf_yadif.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vf_yadif.c 2012-05-14 14:08:54.839350145 +0200 +@@ -1,7 +1,6 @@ + /* +- * Copyright (C) 2006-2010 Michael Niedermayer +- * +- * This file is part of FFmpeg. ++ * Copyright (C) 2006-2011 Michael Niedermayer ++ * 2010 James Darnley + * + * FFmpeg is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -20,6 +19,7 @@ + + #include "libavutil/cpu.h" + #include "libavutil/common.h" ++#include "libavutil/pixdesc.h" + #include "avfilter.h" + #include "yadif.h" + +@@ -36,8 +36,8 @@ + int mode; + + /** +- * 0: bottom field first +- * 1: top field first ++ * 0: top field first ++ * 1: bottom field first + * -1: auto-detection + */ + int parity; +@@ -57,8 +57,58 @@ + void (*filter_line)(uint8_t *dst, + uint8_t *prev, uint8_t *cur, uint8_t *next, + int w, int prefs, int mrefs, int parity, int mode); ++ ++ const AVPixFmtDescriptor *csp; + } YADIFContext; + ++#define CHECK(j)\ ++ { int score = FFABS(cur[mrefs-1+(j)] - cur[prefs-1-(j)])\ ++ + FFABS(cur[mrefs +(j)] - cur[prefs -(j)])\ ++ + FFABS(cur[mrefs+1+(j)] - cur[prefs+1-(j)]);\ ++ if (score < spatial_score) {\ ++ spatial_score= score;\ ++ spatial_pred= (cur[mrefs +(j)] + cur[prefs -(j)])>>1;\ ++ ++#define FILTER \ ++ for (x = 0; x < w; x++) { \ ++ int c = cur[mrefs]; \ ++ int d = (prev2[0] + next2[0])>>1; \ ++ int e = cur[prefs]; \ ++ int temporal_diff0 = FFABS(prev2[0] - next2[0]); \ ++ int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; \ ++ int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; \ ++ int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); \ ++ int spatial_pred = (c+e)>>1; \ ++ int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) \ ++ + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; \ ++ \ ++ CHECK(-1) CHECK(-2) }} }} \ ++ CHECK( 1) CHECK( 2) }} }} \ ++ \ ++ if (mode < 2) { \ ++ int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; \ ++ int f = (prev2[2*prefs] + next2[2*prefs])>>1; \ ++ int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); \ ++ int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); \ ++ \ ++ diff = FFMAX3(diff, min, -max); \ ++ } \ ++ \ ++ if (spatial_pred > d + diff) \ ++ spatial_pred = d + diff; \ ++ else if (spatial_pred < d - diff) \ ++ spatial_pred = d - diff; \ ++ \ ++ dst[0] = spatial_pred; \ ++ \ ++ dst++; \ ++ cur++; \ ++ prev++; \ ++ next++; \ ++ prev2++; \ ++ next2++; \ ++ } ++ + static void filter_line_c(uint8_t *dst, + uint8_t *prev, uint8_t *cur, uint8_t *next, + int w, int prefs, int mrefs, int parity, int mode) +@@ -66,59 +116,21 @@ + int x; + uint8_t *prev2 = parity ? prev : cur ; + uint8_t *next2 = parity ? cur : next; +- for (x = 0; x < w; x++) { +- int c = cur[mrefs]; +- int d = (prev2[0] + next2[0])>>1; +- int e = cur[prefs]; +- int temporal_diff0 = FFABS(prev2[0] - next2[0]); +- int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; +- int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; +- int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); +- int spatial_pred = (c+e)>>1; +- int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) +- + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; +- +-#define CHECK(j)\ +- { int score = FFABS(cur[mrefs-1+j] - cur[prefs-1-j])\ +- + FFABS(cur[mrefs +j] - cur[prefs -j])\ +- + FFABS(cur[mrefs+1+j] - cur[prefs+1-j]);\ +- if (score < spatial_score) {\ +- spatial_score= score;\ +- spatial_pred= (cur[mrefs +j] + cur[prefs -j])>>1;\ +- +- CHECK(-1) CHECK(-2) }} }} +- CHECK( 1) CHECK( 2) }} }} + +- if (mode < 2) { +- int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; +- int f = (prev2[2*prefs] + next2[2*prefs])>>1; +-#if 0 +- int a = cur[-3*refs]; +- int g = cur[+3*refs]; +- int max = FFMAX3(d-e, d-c, FFMIN3(FFMAX(b-c,f-e),FFMAX(b-c,b-a),FFMAX(f-g,f-e)) ); +- int min = FFMIN3(d-e, d-c, FFMAX3(FFMIN(b-c,f-e),FFMIN(b-c,b-a),FFMIN(f-g,f-e)) ); +-#else +- int max = FFMAX3(d-e, d-c, FFMIN(b-c, f-e)); +- int min = FFMIN3(d-e, d-c, FFMAX(b-c, f-e)); +-#endif ++ FILTER ++} + +- diff = FFMAX3(diff, min, -max); +- } ++static void filter_line_c_16bit(uint16_t *dst, ++ uint16_t *prev, uint16_t *cur, uint16_t *next, ++ int w, int prefs, int mrefs, int parity, int mode) ++{ ++ int x; ++ uint16_t *prev2 = parity ? prev : cur ; ++ uint16_t *next2 = parity ? cur : next; ++ mrefs /= 2; ++ prefs /= 2; + +- if (spatial_pred > d + diff) +- spatial_pred = d + diff; +- else if (spatial_pred < d - diff) +- spatial_pred = d - diff; +- +- dst[0] = spatial_pred; +- +- dst++; +- cur++; +- prev++; +- next++; +- prev2++; +- next2++; +- } ++ FILTER + } + + static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, +@@ -127,11 +139,17 @@ + YADIFContext *yadif = ctx->priv; + int y, i; + +- for (i = 0; i < 3; i++) { +- int is_chroma = !!i; +- int w = dstpic->video->w >> is_chroma; +- int h = dstpic->video->h >> is_chroma; ++ for (i = 0; i < yadif->csp->nb_components; i++) { ++ int w = dstpic->video->w; ++ int h = dstpic->video->h; + int refs = yadif->cur->linesize[i]; ++ int df = (yadif->csp->comp[i].depth_minus1 + 8) / 8; ++ ++ if (i == 1 || i == 2) { ++ /* Why is this not part of the per-plane description thing? */ ++ w >>= yadif->csp->log2_chroma_w; ++ h >>= yadif->csp->log2_chroma_h; ++ } + + for (y = 0; y < h; y++) { + if ((y ^ parity) & 1) { +@@ -143,7 +161,7 @@ + yadif->filter_line(dst, prev, cur, next, w, y+1data[i][y*dstpic->linesize[i]], +- &yadif->cur->data[i][y*refs], w); ++ &yadif->cur->data[i][y*refs], w*df); + } + } + } +@@ -156,7 +174,7 @@ + { + AVFilterBufferRef *picref; + int width = FFALIGN(w, 32); +- int height= FFALIGN(h+6, 32); ++ int height= FFALIGN(h+2, 32); + int i; + + picref = avfilter_default_get_video_buffer(link, perms, width, height); +@@ -165,7 +183,7 @@ + picref->video->h = h; + + for (i = 0; i < 3; i++) +- picref->data[i] += 3 * picref->linesize[i]; ++ picref->data[i] += picref->linesize[i]; + + return picref; + } +@@ -190,6 +208,11 @@ + yadif->out->video->interlaced = 0; + } + ++ if (!yadif->csp) ++ yadif->csp = &av_pix_fmt_descriptors[link->format]; ++ if (yadif->csp->comp[0].depth_minus1 / 8 == 1) ++ yadif->filter_line = (void*)filter_line_c_16bit; ++ + filter(ctx, yadif->out, tff ^ !is_second, tff); + + if (is_second) { +@@ -297,7 +320,7 @@ + return ret; + val = avfilter_poll_frame(link->src->inputs[0]); + } +- assert(yadif->next); ++ assert(yadif->next || !val); + + if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced) + return val; +@@ -318,11 +341,28 @@ + { + static const enum PixelFormat pix_fmts[] = { + PIX_FMT_YUV420P, ++ PIX_FMT_YUV422P, ++ PIX_FMT_YUV444P, ++ PIX_FMT_YUV410P, ++ PIX_FMT_YUV411P, + PIX_FMT_GRAY8, ++ PIX_FMT_YUVJ420P, ++ PIX_FMT_YUVJ422P, ++ PIX_FMT_YUVJ444P, ++ AV_NE( PIX_FMT_GRAY16BE, PIX_FMT_GRAY16LE ), ++ PIX_FMT_YUV440P, ++ PIX_FMT_YUVJ440P, ++ AV_NE( PIX_FMT_YUV420P10BE, PIX_FMT_YUV420P10LE ), ++ AV_NE( PIX_FMT_YUV422P10BE, PIX_FMT_YUV422P10LE ), ++ AV_NE( PIX_FMT_YUV444P10BE, PIX_FMT_YUV444P10LE ), ++ AV_NE( PIX_FMT_YUV420P16BE, PIX_FMT_YUV420P16LE ), ++ AV_NE( PIX_FMT_YUV422P16BE, PIX_FMT_YUV422P16LE ), ++ AV_NE( PIX_FMT_YUV444P16BE, PIX_FMT_YUV444P16LE ), ++ PIX_FMT_YUVA420P, + PIX_FMT_NONE + }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + + return 0; + } +@@ -335,6 +375,7 @@ + yadif->mode = 0; + yadif->parity = -1; + yadif->auto_enable = 0; ++ yadif->csp = NULL; + + if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable); + +@@ -355,22 +396,23 @@ + + AVFilter avfilter_vf_yadif = { + .name = "yadif", +- .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image"), ++ .description = NULL_IF_CONFIG_SMALL("Deinterlace the input image."), + + .priv_size = sizeof(YADIFContext), + .init = init, + .uninit = uninit, + .query_formats = query_formats, + +- .inputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .start_frame = start_frame, + .get_video_buffer = get_video_buffer, + .draw_slice = null_draw_slice, +- .end_frame = end_frame, }, ++ .end_frame = end_frame, ++ .rej_perms = AV_PERM_REUSE2, }, + { .name = NULL}}, + +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .poll_frame = poll_frame, + .request_frame = request_frame, }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsink_nullsink.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsink_nullsink.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsink_nullsink.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsink_nullsink.c 2012-05-14 14:08:54.840350165 +0200 +@@ -32,7 +32,7 @@ + + .priv_size = 0, + +- .inputs = (AVFilterPad[]) { ++ .inputs = (const AVFilterPad[]) { + { + .name = "default", + .type = AVMEDIA_TYPE_VIDEO, +@@ -41,5 +41,5 @@ + }, + { .name = NULL}, + }, +- .outputs = (AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = NULL }}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_buffer.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_buffer.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_buffer.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_buffer.c 2012-05-14 14:08:54.841350185 +0200 +@@ -24,73 +24,178 @@ + */ + + #include "avfilter.h" ++#include "internal.h" ++#include "avcodec.h" ++#include "buffersrc.h" + #include "vsrc_buffer.h" +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + + typedef struct { +- int64_t pts; +- AVFrame frame; +- int has_frame; ++ AVFilterBufferRef *picref; + int h, w; + enum PixelFormat pix_fmt; + AVRational time_base; ///< time_base to set in the output link +- AVRational pixel_aspect; ++ AVRational sample_aspect_ratio; ++ char sws_param[256]; + } BufferSourceContext; + +-int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, +- int64_t pts, AVRational pixel_aspect) ++#define CHECK_PARAM_CHANGE(s, c, width, height, format)\ ++ if (c->w != width || c->h != height || c->pix_fmt != format) {\ ++ av_log(s, AV_LOG_ERROR, "Changing frame properties on the fly is not supported.\n");\ ++ return AVERROR(EINVAL);\ ++ } ++ ++int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_filter, ++ AVFilterBufferRef *picref, int flags) + { + BufferSourceContext *c = buffer_filter->priv; ++ AVFilterLink *outlink = buffer_filter->outputs[0]; ++ int ret; ++ ++ if (c->picref) { ++ if (flags & AV_VSRC_BUF_FLAG_OVERWRITE) { ++ avfilter_unref_buffer(c->picref); ++ c->picref = NULL; ++ } else { ++ av_log(buffer_filter, AV_LOG_ERROR, ++ "Buffering several frames is not supported. " ++ "Please consume all available frames before adding a new one.\n"); ++ return AVERROR(EINVAL); ++ } ++ } ++ ++ if (picref->video->w != c->w || picref->video->h != c->h || picref->format != c->pix_fmt) { ++ AVFilterContext *scale = buffer_filter->outputs[0]->dst; ++ AVFilterLink *link; ++ char scale_param[1024]; ++ ++ av_log(buffer_filter, AV_LOG_INFO, ++ "Buffer video input changed from size:%dx%d fmt:%s to size:%dx%d fmt:%s\n", ++ c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, ++ picref->video->w, picref->video->h, av_pix_fmt_descriptors[picref->format].name); ++ ++ if (!scale || strcmp(scale->filter->name, "scale")) { ++ AVFilter *f = avfilter_get_by_name("scale"); ++ ++ av_log(buffer_filter, AV_LOG_INFO, "Inserting scaler filter\n"); ++ if ((ret = avfilter_open(&scale, f, "Input equalizer")) < 0) ++ return ret; ++ ++ snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", c->w, c->h, c->sws_param); ++ if ((ret = avfilter_init_filter(scale, scale_param, NULL)) < 0) { ++ avfilter_free(scale); ++ return ret; ++ } ++ ++ if ((ret = avfilter_insert_filter(buffer_filter->outputs[0], scale, 0, 0)) < 0) { ++ avfilter_free(scale); ++ return ret; ++ } ++ scale->outputs[0]->time_base = scale->inputs[0]->time_base; ++ ++ scale->outputs[0]->format= c->pix_fmt; ++ } else if (!strcmp(scale->filter->name, "scale")) { ++ snprintf(scale_param, sizeof(scale_param)-1, "%d:%d:%s", ++ scale->outputs[0]->w, scale->outputs[0]->h, c->sws_param); ++ scale->filter->init(scale, scale_param, NULL); ++ } + +- if (c->has_frame) { +- av_log(buffer_filter, AV_LOG_ERROR, ++ c->pix_fmt = scale->inputs[0]->format = picref->format; ++ c->w = scale->inputs[0]->w = picref->video->w; ++ c->h = scale->inputs[0]->h = picref->video->h; ++ ++ link = scale->outputs[0]; ++ if ((ret = link->srcpad->config_props(link)) < 0) ++ return ret; ++ } ++ ++ c->picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, ++ picref->video->w, picref->video->h); ++ av_image_copy(c->picref->data, c->picref->linesize, ++ (void*)picref->data, picref->linesize, ++ picref->format, picref->video->w, picref->video->h); ++ avfilter_copy_buffer_ref_props(c->picref, picref); ++ ++ return 0; ++} ++ ++int av_buffersrc_buffer(AVFilterContext *s, AVFilterBufferRef *buf) ++{ ++ BufferSourceContext *c = s->priv; ++ ++ if (c->picref) { ++ av_log(s, AV_LOG_ERROR, + "Buffering several frames is not supported. " + "Please consume all available frames before adding a new one.\n" + ); +- //return -1; ++ return AVERROR(EINVAL); + } + +- memcpy(c->frame.data , frame->data , sizeof(frame->data)); +- memcpy(c->frame.linesize, frame->linesize, sizeof(frame->linesize)); +- c->frame.interlaced_frame= frame->interlaced_frame; +- c->frame.top_field_first = frame->top_field_first; +- c->pts = pts; +- c->pixel_aspect = pixel_aspect; +- c->has_frame = 1; ++// CHECK_PARAM_CHANGE(s, c, buf->video->w, buf->video->h, buf->format); ++ ++ c->picref = buf; + + return 0; + } + ++#if CONFIG_AVCODEC ++#include "avcodec.h" ++ ++int av_vsrc_buffer_add_frame(AVFilterContext *buffer_src, ++ const AVFrame *frame, int flags) ++{ ++ int ret; ++ AVFilterBufferRef *picref = ++ avfilter_get_video_buffer_ref_from_frame(frame, AV_PERM_WRITE); ++ if (!picref) ++ return AVERROR(ENOMEM); ++ ret = av_vsrc_buffer_add_video_buffer_ref(buffer_src, picref, flags); ++ picref->buf->data[0] = NULL; ++ avfilter_unref_buffer(picref); ++ ++ return ret; ++} ++#endif ++ + static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) + { + BufferSourceContext *c = ctx->priv; + char pix_fmt_str[128]; +- int n = 0; ++ int ret, n = 0; ++ *c->sws_param = 0; + + if (!args || +- (n = sscanf(args, "%d:%d:%127[^:]:%d:%d", &c->w, &c->h, pix_fmt_str, &c->time_base.num, &c->time_base.den)) != 5) { +- av_log(ctx, AV_LOG_ERROR, "Expected 5 arguments, but only %d found in '%s'\n", n, args); ++ (n = sscanf(args, "%d:%d:%127[^:]:%d:%d:%d:%d:%255c", &c->w, &c->h, pix_fmt_str, ++ &c->time_base.num, &c->time_base.den, ++ &c->sample_aspect_ratio.num, &c->sample_aspect_ratio.den, c->sws_param)) < 7) { ++ av_log(ctx, AV_LOG_ERROR, "Expected at least 7 arguments, but only %d found in '%s'\n", n, args); + return AVERROR(EINVAL); + } +- if ((c->pix_fmt = av_get_pix_fmt(pix_fmt_str)) == PIX_FMT_NONE) { +- char *tail; +- c->pix_fmt = strtol(pix_fmt_str, &tail, 10); +- if (*tail || c->pix_fmt < 0 || c->pix_fmt >= PIX_FMT_NB) { +- av_log(ctx, AV_LOG_ERROR, "Invalid pixel format string '%s'\n", pix_fmt_str); +- return AVERROR(EINVAL); +- } +- } + +- av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s\n", c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name); ++ if ((ret = ff_parse_pixel_format(&c->pix_fmt, pix_fmt_str, ctx)) < 0) ++ return ret; ++ ++ av_log(ctx, AV_LOG_INFO, "w:%d h:%d pixfmt:%s tb:%d/%d sar:%d/%d sws_param:%s\n", ++ c->w, c->h, av_pix_fmt_descriptors[c->pix_fmt].name, ++ c->time_base.num, c->time_base.den, ++ c->sample_aspect_ratio.num, c->sample_aspect_ratio.den, c->sws_param); + return 0; + } + ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ BufferSourceContext *s = ctx->priv; ++ if (s->picref) ++ avfilter_unref_buffer(s->picref); ++ s->picref = NULL; ++} ++ + static int query_formats(AVFilterContext *ctx) + { + BufferSourceContext *c = ctx->priv; + enum PixelFormat pix_fmts[] = { c->pix_fmt, PIX_FMT_NONE }; + +- avfilter_set_common_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); + return 0; + } + +@@ -100,6 +205,7 @@ + + link->w = c->w; + link->h = c->h; ++ link->sample_aspect_ratio = c->sample_aspect_ratio; + link->time_base = c->time_base; + + return 0; +@@ -108,34 +214,18 @@ + static int request_frame(AVFilterLink *link) + { + BufferSourceContext *c = link->src->priv; +- AVFilterBufferRef *picref; + +- if (!c->has_frame) { +- av_log(link->src, AV_LOG_ERROR, ++ if (!c->picref) { ++ av_log(link->src, AV_LOG_WARNING, + "request_frame() called with no available frame!\n"); +- //return -1; ++ return AVERROR(EINVAL); + } + +- /* This picture will be needed unmodified later for decoding the next +- * frame */ +- picref = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | +- AV_PERM_REUSE2, +- link->w, link->h); +- +- av_image_copy(picref->data, picref->linesize, +- c->frame.data, c->frame.linesize, +- picref->format, link->w, link->h); +- +- picref->pts = c->pts; +- picref->video->pixel_aspect = c->pixel_aspect; +- picref->video->interlaced = c->frame.interlaced_frame; +- picref->video->top_field_first = c->frame.top_field_first; +- avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); ++ avfilter_start_frame(link, avfilter_ref_buffer(c->picref, ~0)); + avfilter_draw_slice(link, 0, link->h, 1); + avfilter_end_frame(link); +- avfilter_unref_buffer(picref); +- +- c->has_frame = 0; ++ avfilter_unref_buffer(c->picref); ++ c->picref = NULL; + + return 0; + } +@@ -143,7 +233,7 @@ + static int poll_frame(AVFilterLink *link) + { + BufferSourceContext *c = link->src->priv; +- return !!(c->has_frame); ++ return !!c->picref; + } + + AVFilter avfilter_vsrc_buffer = { +@@ -153,9 +243,10 @@ + .query_formats = query_formats, + + .init = init, ++ .uninit = uninit, + +- .inputs = (AVFilterPad[]) {{ .name = NULL }}, +- .outputs = (AVFilterPad[]) {{ .name = "default", ++ .inputs = (const AVFilterPad[]) {{ .name = NULL }}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", + .type = AVMEDIA_TYPE_VIDEO, + .request_frame = request_frame, + .poll_frame = poll_frame, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_buffer.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_buffer.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_buffer.h 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_buffer.h 2012-05-14 14:08:54.842350206 +0200 +@@ -1,5 +1,4 @@ + /* +- * Memory buffer source filter + * Copyright (c) 2008 Vitor Sessak + * + * This file is part of FFmpeg. +@@ -19,9 +18,32 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavcodec/avcodec.h" /* AVFrame */ ++#ifndef AVFILTER_VSRC_BUFFER_H ++#define AVFILTER_VSRC_BUFFER_H ++ ++/** ++ * @file ++ * memory buffer source API for video ++ */ ++ + #include "avfilter.h" + +-int av_vsrc_buffer_add_frame(AVFilterContext *buffer_filter, AVFrame *frame, +- int64_t pts, AVRational pixel_aspect); ++/** ++ * Tell av_vsrc_buffer_add_video_buffer_ref() to overwrite the already ++ * cached video buffer with the new added one, otherwise the function ++ * will complain and exit. ++ */ ++#define AV_VSRC_BUF_FLAG_OVERWRITE 1 ++ ++/** ++ * Add video buffer data in picref to buffer_src. ++ * ++ * @param buffer_src pointer to a buffer source context ++ * @param flags a combination of AV_VSRC_BUF_FLAG_* flags ++ * @return >= 0 in case of success, a negative AVERROR code in case of ++ * failure ++ */ ++int av_vsrc_buffer_add_video_buffer_ref(AVFilterContext *buffer_src, ++ AVFilterBufferRef *picref, int flags); + ++#endif /* AVFILTER_VSRC_BUFFER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_cellauto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_cellauto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_cellauto.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_cellauto.c 2012-05-14 14:08:54.843350226 +0200 +@@ -0,0 +1,370 @@ ++/* ++ * Copyright (c) Stefano Sabatini 2011 ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * cellular automaton video source, based on Stephen Wolfram "experimentus crucis" ++ */ ++ ++/* #define DEBUG */ ++ ++#include "libavutil/file.h" ++#include "libavutil/lfg.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/random_seed.h" ++#include "avfilter.h" ++ ++typedef struct { ++ const AVClass *class; ++ int w, h; ++ char *filename; ++ char *rule_str; ++ uint8_t *file_buf; ++ size_t file_bufsize; ++ uint8_t *buf; ++ int buf_prev_row_idx, buf_row_idx; ++ uint8_t rule; ++ uint64_t pts; ++ AVRational time_base; ++ char *size; ///< video frame size ++ char *rate; ///< video frame rate ++ double random_fill_ratio; ++ uint32_t random_seed; ++ int stitch, scroll, start_full; ++ int64_t generation; ///< the generation number, starting from 0 ++ AVLFG lfg; ++ char *pattern; ++} CellAutoContext; ++ ++#define OFFSET(x) offsetof(CellAutoContext, x) ++ ++static const AVOption cellauto_options[] = { ++ { "filename", "read initial pattern from file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "f", "read initial pattern from file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "pattern", "set initial pattern", OFFSET(pattern), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "p", "set initial pattern", OFFSET(pattern), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "rule", "set rule", OFFSET(rule), AV_OPT_TYPE_INT, {.dbl = 110}, 0, 255 }, ++ { "random_fill_ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl = 1/M_PHI}, 0, 1 }, ++ { "ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl = 1/M_PHI}, 0, 1 }, ++ { "random_seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.dbl = -1}, -1, UINT32_MAX }, ++ { "seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.dbl = -1}, -1, UINT32_MAX }, ++ { "scroll", "scroll pattern downward", OFFSET(scroll), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1 }, ++ { "start_full", "start filling the whole video", OFFSET(start_full), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1 }, ++ { "full", "start filling the whole video", OFFSET(start_full), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1 }, ++ { "stitch", "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1 }, ++ { NULL }, ++}; ++ ++static const char *cellauto_get_name(void *ctx) ++{ ++ return "cellauto"; ++} ++ ++static const AVClass cellauto_class = { ++ "CellAutoContext", ++ cellauto_get_name, ++ cellauto_options ++}; ++ ++#ifdef DEBUG ++static void show_cellauto_row(AVFilterContext *ctx) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ int i; ++ uint8_t *row = cellauto->buf + cellauto->w * cellauto->buf_row_idx; ++ char *line = av_malloc(cellauto->w + 1); ++ if (!line) ++ return; ++ ++ for (i = 0; i < cellauto->w; i++) ++ line[i] = row[i] ? '@' : ' '; ++ line[i] = 0; ++ av_log(ctx, AV_LOG_DEBUG, "generation:%"PRId64" row:%s|\n", cellauto->generation, line); ++ av_free(line); ++} ++#endif ++ ++static int init_pattern_from_string(AVFilterContext *ctx) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ char *p; ++ int i, w = 0; ++ ++ w = strlen(cellauto->pattern); ++ av_log(ctx, AV_LOG_DEBUG, "w:%d\n", w); ++ ++ if (cellauto->size) { ++ if (w > cellauto->w) { ++ av_log(ctx, AV_LOG_ERROR, ++ "The specified width is %d which cannot contain the provided string width of %d\n", ++ cellauto->w, w); ++ return AVERROR(EINVAL); ++ } ++ } else { ++ /* width was not specified, set it to width of the provided row */ ++ cellauto->w = w; ++ cellauto->h = (double)cellauto->w * M_PHI; ++ } ++ ++ cellauto->buf = av_mallocz(sizeof(uint8_t) * cellauto->w * cellauto->h); ++ if (!cellauto->buf) ++ return AVERROR(ENOMEM); ++ ++ /* fill buf */ ++ p = cellauto->pattern; ++ for (i = (cellauto->w - w)/2;; i++) { ++ av_log(ctx, AV_LOG_DEBUG, "%d %c\n", i, *p == '\n' ? 'N' : *p); ++ if (*p == '\n' || !*p) ++ break; ++ else ++ cellauto->buf[i] = !!isgraph(*(p++)); ++ } ++ ++ return 0; ++} ++ ++static int init_pattern_from_file(AVFilterContext *ctx) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ int ret; ++ ++ ret = av_file_map(cellauto->filename, ++ &cellauto->file_buf, &cellauto->file_bufsize, 0, ctx); ++ if (ret < 0) ++ return ret; ++ ++ /* create a string based on the read file */ ++ cellauto->pattern = av_malloc(cellauto->file_bufsize + 1); ++ if (!cellauto->pattern) ++ return AVERROR(ENOMEM); ++ memcpy(cellauto->pattern, cellauto->file_buf, cellauto->file_bufsize); ++ cellauto->pattern[cellauto->file_bufsize] = 0; ++ ++ return init_pattern_from_string(ctx); ++} ++ ++static int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ AVRational frame_rate; ++ int ret; ++ ++ cellauto->class = &cellauto_class; ++ av_opt_set_defaults(cellauto); ++ ++ if ((ret = av_set_options_string(cellauto, args, "=", ":")) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ if ((ret = av_parse_video_rate(&frame_rate, cellauto->rate)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", cellauto->rate); ++ return AVERROR(EINVAL); ++ } ++ ++ if (!cellauto->size && !cellauto->filename && !cellauto->pattern) ++ av_opt_set(cellauto, "size", "320x518", 0); ++ ++ if (cellauto->size && ++ (ret = av_parse_video_size(&cellauto->w, &cellauto->h, cellauto->size)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", cellauto->size); ++ return ret; ++ } ++ ++ cellauto->time_base.num = frame_rate.den; ++ cellauto->time_base.den = frame_rate.num; ++ ++ if (cellauto->filename && cellauto->pattern) { ++ av_log(ctx, AV_LOG_ERROR, "Only one of the filename or pattern options can be used\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (cellauto->filename) { ++ if ((ret = init_pattern_from_file(ctx)) < 0) ++ return ret; ++ } else if (cellauto->pattern) { ++ if ((ret = init_pattern_from_string(ctx)) < 0) ++ return ret; ++ } else { ++ /* fill the first row randomly */ ++ int i; ++ ++ cellauto->buf = av_mallocz(sizeof(uint8_t) * cellauto->w * cellauto->h); ++ if (!cellauto->buf) ++ return AVERROR(ENOMEM); ++ if (cellauto->random_seed == -1) ++ cellauto->random_seed = av_get_random_seed(); ++ ++ av_lfg_init(&cellauto->lfg, cellauto->random_seed); ++ ++ for (i = 0; i < cellauto->w; i++) { ++ double r = (double)av_lfg_get(&cellauto->lfg) / UINT32_MAX; ++ if (r <= cellauto->random_fill_ratio) ++ cellauto->buf[i] = 1; ++ } ++ } ++ ++ av_log(ctx, AV_LOG_INFO, ++ "s:%dx%d r:%d/%d rule:%d stitch:%d scroll:%d full:%d seed:%u\n", ++ cellauto->w, cellauto->h, frame_rate.num, frame_rate.den, ++ cellauto->rule, cellauto->stitch, cellauto->scroll, cellauto->start_full, ++ cellauto->random_seed); ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ ++ av_file_unmap(cellauto->file_buf, cellauto->file_bufsize); ++ av_freep(&cellauto->buf); ++ av_freep(&cellauto->pattern); ++} ++ ++static int config_props(AVFilterLink *outlink) ++{ ++ CellAutoContext *cellauto = outlink->src->priv; ++ ++ outlink->w = cellauto->w; ++ outlink->h = cellauto->h; ++ outlink->time_base = cellauto->time_base; ++ ++ return 0; ++} ++ ++static void evolve(AVFilterContext *ctx) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ int i, v, pos[3]; ++ uint8_t *row, *prev_row = cellauto->buf + cellauto->buf_row_idx * cellauto->w; ++ enum { NW, N, NE }; ++ ++ cellauto->buf_prev_row_idx = cellauto->buf_row_idx; ++ cellauto->buf_row_idx = cellauto->buf_row_idx == cellauto->h-1 ? 0 : cellauto->buf_row_idx+1; ++ row = cellauto->buf + cellauto->w * cellauto->buf_row_idx; ++ ++ for (i = 0; i < cellauto->w; i++) { ++ if (cellauto->stitch) { ++ pos[NW] = i-1 < 0 ? cellauto->w-1 : i-1; ++ pos[N] = i; ++ pos[NE] = i+1 == cellauto->w ? 0 : i+1; ++ v = prev_row[pos[NW]]<<2 | prev_row[pos[N]]<<1 | prev_row[pos[NE]]; ++ } else { ++ v = 0; ++ v|= i-1 >= 0 ? prev_row[i-1]<<2 : 0; ++ v|= prev_row[i ]<<1 ; ++ v|= i+1 < cellauto->w ? prev_row[i+1] : 0; ++ } ++ row[i] = !!(cellauto->rule & (1< cell:%d\n", i, ++ v&4?'@':' ', v&2?'@':' ', v&1?'@':' ', row[i]); ++ } ++ ++ cellauto->generation++; ++} ++ ++static void fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) ++{ ++ CellAutoContext *cellauto = ctx->priv; ++ int i, j, k, row_idx = 0; ++ uint8_t *p0 = picref->data[0]; ++ ++ if (cellauto->scroll && cellauto->generation >= cellauto->h) ++ /* show on top the oldest row */ ++ row_idx = (cellauto->buf_row_idx + 1) % cellauto->h; ++ ++ /* fill the output picture with the whole buffer */ ++ for (i = 0; i < cellauto->h; i++) { ++ uint8_t byte = 0; ++ uint8_t *row = cellauto->buf + row_idx*cellauto->w; ++ uint8_t *p = p0; ++ for (k = 0, j = 0; j < cellauto->w; j++) { ++ byte |= row[j]<<(7-k++); ++ if (k==8 || j == cellauto->w-1) { ++ k = 0; ++ *p++ = byte; ++ byte = 0; ++ } ++ } ++ row_idx = (row_idx + 1) % cellauto->h; ++ p0 += picref->linesize[0]; ++ } ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ CellAutoContext *cellauto = outlink->src->priv; ++ AVFilterBufferRef *picref = ++ avfilter_get_video_buffer(outlink, AV_PERM_WRITE, cellauto->w, cellauto->h); ++ picref->video->sample_aspect_ratio = (AVRational) {1, 1}; ++ if (cellauto->generation == 0 && cellauto->start_full) { ++ int i; ++ for (i = 0; i < cellauto->h-1; i++) ++ evolve(outlink->src); ++ } ++ fill_picture(outlink->src, picref); ++ evolve(outlink->src); ++ ++ picref->pts = cellauto->pts++; ++ picref->pos = -1; ++ ++#ifdef DEBUG ++ show_cellauto_row(outlink->src); ++#endif ++ ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, cellauto->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { PIX_FMT_MONOBLACK, PIX_FMT_NONE }; ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_cellauto = { ++ .name = "cellauto", ++ .description = NULL_IF_CONFIG_SMALL("Create pattern generated by an elementary cellular automaton."), ++ .priv_size = sizeof(CellAutoContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_props }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_color.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_color.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_color.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_color.c 2012-05-14 14:08:54.844350246 +0200 +@@ -0,0 +1,174 @@ ++/* ++ * Copyright (c) 2010 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * color source ++ */ ++ ++#include "avfilter.h" ++#include "libavutil/pixdesc.h" ++#include "libavutil/colorspace.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/parseutils.h" ++#include "drawutils.h" ++ ++typedef struct { ++ int w, h; ++ uint8_t color[4]; ++ AVRational time_base; ++ uint8_t *line[4]; ++ int line_step[4]; ++ int hsub, vsub; ///< chroma subsampling values ++ uint64_t pts; ++} ColorContext; ++ ++static av_cold int color_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ ColorContext *color = ctx->priv; ++ char color_string[128] = "black"; ++ char frame_size [128] = "320x240"; ++ char frame_rate [128] = "25"; ++ AVRational frame_rate_q; ++ int ret; ++ ++ if (args) ++ sscanf(args, "%127[^:]:%127[^:]:%127s", color_string, frame_size, frame_rate); ++ ++ if (av_parse_video_size(&color->w, &color->h, frame_size) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", frame_size); ++ return AVERROR(EINVAL); ++ } ++ ++ if (av_parse_video_rate(&frame_rate_q, frame_rate) < 0 || ++ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", frame_rate); ++ return AVERROR(EINVAL); ++ } ++ color->time_base.num = frame_rate_q.den; ++ color->time_base.den = frame_rate_q.num; ++ ++ if ((ret = av_parse_color(color->color, color_string, -1, ctx)) < 0) ++ return ret; ++ ++ return 0; ++} ++ ++static av_cold void color_uninit(AVFilterContext *ctx) ++{ ++ ColorContext *color = ctx->priv; ++ int i; ++ ++ for (i = 0; i < 4; i++) { ++ av_freep(&color->line[i]); ++ color->line_step[i] = 0; ++ } ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_ARGB, PIX_FMT_RGBA, ++ PIX_FMT_ABGR, PIX_FMT_BGRA, ++ PIX_FMT_RGB24, PIX_FMT_BGR24, ++ ++ PIX_FMT_YUV444P, PIX_FMT_YUV422P, ++ PIX_FMT_YUV420P, PIX_FMT_YUV411P, ++ PIX_FMT_YUV410P, PIX_FMT_YUV440P, ++ PIX_FMT_YUVJ444P, PIX_FMT_YUVJ422P, ++ PIX_FMT_YUVJ420P, PIX_FMT_YUVJ440P, ++ PIX_FMT_YUVA420P, ++ ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int color_config_props(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->src; ++ ColorContext *color = ctx->priv; ++ uint8_t rgba_color[4]; ++ int is_packed_rgba; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[inlink->format]; ++ ++ color->hsub = pix_desc->log2_chroma_w; ++ color->vsub = pix_desc->log2_chroma_h; ++ ++ color->w &= ~((1 << color->hsub) - 1); ++ color->h &= ~((1 << color->vsub) - 1); ++ if (av_image_check_size(color->w, color->h, 0, ctx) < 0) ++ return AVERROR(EINVAL); ++ ++ memcpy(rgba_color, color->color, sizeof(rgba_color)); ++ ff_fill_line_with_color(color->line, color->line_step, color->w, color->color, ++ inlink->format, rgba_color, &is_packed_rgba, NULL); ++ ++ av_log(ctx, AV_LOG_INFO, "w:%d h:%d r:%d/%d color:0x%02x%02x%02x%02x[%s]\n", ++ color->w, color->h, color->time_base.den, color->time_base.num, ++ color->color[0], color->color[1], color->color[2], color->color[3], ++ is_packed_rgba ? "rgba" : "yuva"); ++ inlink->w = color->w; ++ inlink->h = color->h; ++ inlink->time_base = color->time_base; ++ ++ return 0; ++} ++ ++static int color_request_frame(AVFilterLink *link) ++{ ++ ColorContext *color = link->src->priv; ++ AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, color->w, color->h); ++ picref->video->sample_aspect_ratio = (AVRational) {1, 1}; ++ picref->pts = color->pts++; ++ picref->pos = -1; ++ ++ avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); ++ ff_draw_rectangle(picref->data, picref->linesize, ++ color->line, color->line_step, color->hsub, color->vsub, ++ 0, 0, color->w, color->h); ++ avfilter_draw_slice(link, 0, color->h, 1); ++ avfilter_end_frame(link); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_color = { ++ .name = "color", ++ .description = NULL_IF_CONFIG_SMALL("Provide an uniformly colored input, syntax is: [color[:size[:rate]]]."), ++ ++ .priv_size = sizeof(ColorContext), ++ .init = color_init, ++ .uninit = color_uninit, ++ ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = color_request_frame, ++ .config_props = color_config_props }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_life.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_life.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_life.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_life.c 2012-05-14 14:08:54.846350286 +0200 +@@ -0,0 +1,496 @@ ++/* ++ * Copyright (c) Stefano Sabatini 2010 ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * life video source, based on John Conways' Life Game ++ */ ++ ++/* #define DEBUG */ ++ ++#include "libavutil/file.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/lfg.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/random_seed.h" ++#include "avfilter.h" ++ ++typedef struct { ++ const AVClass *class; ++ int w, h; ++ char *filename; ++ char *rule_str; ++ uint8_t *file_buf; ++ size_t file_bufsize; ++ ++ /** ++ * The two grid state buffers. ++ * ++ * A 0xFF (ALIVE_CELL) value means the cell is alive (or new born), while ++ * the decreasing values from 0xFE to 0 means the cell is dead; the range ++ * of values is used for the slow death effect, or mold (0xFE means dead, ++ * 0xFD means very dead, 0xFC means very very dead... and 0x00 means ++ * definitely dead/mold). ++ */ ++ uint8_t *buf[2]; ++ ++ uint8_t buf_idx; ++ uint16_t stay_rule; ///< encode the behavior for filled cells ++ uint16_t born_rule; ///< encode the behavior for empty cells ++ uint64_t pts; ++ AVRational time_base; ++ char *size; ///< video frame size ++ char *rate; ///< video frame rate ++ double random_fill_ratio; ++ uint32_t random_seed; ++ int stitch; ++ int mold; ++ char *life_color_str; ++ char *death_color_str; ++ char *mold_color_str; ++ uint8_t life_color[4]; ++ uint8_t death_color[4]; ++ uint8_t mold_color[4]; ++ AVLFG lfg; ++ void (*draw)(AVFilterContext*, AVFilterBufferRef*); ++} LifeContext; ++ ++#define ALIVE_CELL 0xFF ++#define OFFSET(x) offsetof(LifeContext, x) ++ ++static const AVOption life_options[] = { ++ { "filename", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "f", "set source file", OFFSET(filename), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "rule", "set rule", OFFSET(rule_str), AV_OPT_TYPE_STRING, {.str = "B3/S23"}, CHAR_MIN, CHAR_MAX }, ++ { "random_fill_ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1 }, ++ { "ratio", "set fill ratio for filling initial grid randomly", OFFSET(random_fill_ratio), AV_OPT_TYPE_DOUBLE, {.dbl=1/M_PHI}, 0, 1 }, ++ { "random_seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.dbl=-1}, -1, UINT32_MAX }, ++ { "seed", "set the seed for filling the initial grid randomly", OFFSET(random_seed), AV_OPT_TYPE_INT, {.dbl=-1}, -1, UINT32_MAX }, ++ { "stitch", "stitch boundaries", OFFSET(stitch), AV_OPT_TYPE_INT, {.dbl=1}, 0, 1 }, ++ { "mold", "set mold speed for dead cells", OFFSET(mold), AV_OPT_TYPE_INT, {.dbl=0}, 0, 0xFF }, ++ { "life_color", "set life color", OFFSET( life_color_str), AV_OPT_TYPE_STRING, {.str="white"}, CHAR_MIN, CHAR_MAX }, ++ { "death_color", "set death color", OFFSET(death_color_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX }, ++ { "mold_color", "set mold color", OFFSET( mold_color_str), AV_OPT_TYPE_STRING, {.str="black"}, CHAR_MIN, CHAR_MAX }, ++ { NULL }, ++}; ++ ++static const char *life_get_name(void *ctx) ++{ ++ return "life"; ++} ++ ++static const AVClass life_class = { ++ "LifeContext", ++ life_get_name, ++ life_options ++}; ++ ++static int parse_rule(uint16_t *born_rule, uint16_t *stay_rule, ++ const char *rule_str, void *log_ctx) ++{ ++ char *tail; ++ const char *p = rule_str; ++ *born_rule = 0; ++ *stay_rule = 0; ++ ++ if (strchr("bBsS", *p)) { ++ /* parse rule as a Born / Stay Alive code, see ++ * http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life */ ++ do { ++ uint16_t *rule = (*p == 'b' || *p == 'B') ? born_rule : stay_rule; ++ p++; ++ while (*p >= '0' && *p <= '8') { ++ *rule += 1<<(*p - '0'); ++ p++; ++ } ++ if (*p != '/') ++ break; ++ p++; ++ } while (strchr("bBsS", *p)); ++ ++ if (*p) ++ goto error; ++ } else { ++ /* parse rule as a number, expressed in the form STAY|(BORN<<9), ++ * where STAY and BORN encode the corresponding 9-bits rule */ ++ long int rule = strtol(rule_str, &tail, 10); ++ if (*tail) ++ goto error; ++ *born_rule = ((1<<9)-1) & rule; ++ *stay_rule = rule >> 9; ++ } ++ ++ return 0; ++ ++error: ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid rule code '%s' provided\n", rule_str); ++ return AVERROR(EINVAL); ++} ++ ++#ifdef DEBUG ++static void show_life_grid(AVFilterContext *ctx) ++{ ++ LifeContext *life = ctx->priv; ++ int i, j; ++ ++ char *line = av_malloc(life->w + 1); ++ if (!line) ++ return; ++ for (i = 0; i < life->h; i++) { ++ for (j = 0; j < life->w; j++) ++ line[j] = life->buf[life->buf_idx][i*life->w + j] == ALIVE_CELL ? '@' : ' '; ++ line[j] = 0; ++ av_log(ctx, AV_LOG_DEBUG, "%3d: %s\n", i, line); ++ } ++ av_free(line); ++} ++#endif ++ ++static int init_pattern_from_file(AVFilterContext *ctx) ++{ ++ LifeContext *life = ctx->priv; ++ char *p; ++ int ret, i, i0, j, h = 0, w, max_w = 0; ++ ++ if ((ret = av_file_map(life->filename, &life->file_buf, &life->file_bufsize, ++ 0, ctx)) < 0) ++ return ret; ++ ++ /* prescan file to get the number of lines and the maximum width */ ++ w = 0; ++ for (i = 0; i < life->file_bufsize; i++) { ++ if (life->file_buf[i] == '\n') { ++ h++; max_w = FFMAX(w, max_w); w = 0; ++ } else { ++ w++; ++ } ++ } ++ av_log(ctx, AV_LOG_DEBUG, "h:%d max_w:%d\n", h, max_w); ++ ++ if (life->size) { ++ if (max_w > life->w || h > life->h) { ++ av_log(ctx, AV_LOG_ERROR, ++ "The specified size is %dx%d which cannot contain the provided file size of %dx%d\n", ++ life->w, life->h, max_w, h); ++ return AVERROR(EINVAL); ++ } ++ } else { ++ /* size was not specified, set it to size of the grid */ ++ life->w = max_w; ++ life->h = h; ++ } ++ ++ if (!(life->buf[0] = av_mallocz(sizeof(char) * life->h * life->w)) || ++ !(life->buf[1] = av_mallocz(sizeof(char) * life->h * life->w))) { ++ av_free(life->buf[0]); ++ av_free(life->buf[1]); ++ return AVERROR(ENOMEM); ++ } ++ ++ /* fill buf[0] */ ++ p = life->file_buf; ++ for (i0 = 0, i = (life->h - h)/2; i0 < h; i0++, i++) { ++ for (j = (life->w - max_w)/2;; j++) { ++ av_log(ctx, AV_LOG_DEBUG, "%d:%d %c\n", i, j, *p == '\n' ? 'N' : *p); ++ if (*p == '\n') { ++ p++; break; ++ } else ++ life->buf[0][i*life->w + j] = isgraph(*(p++)) ? ALIVE_CELL : 0; ++ } ++ } ++ life->buf_idx = 0; ++ ++ return 0; ++} ++ ++static int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ LifeContext *life = ctx->priv; ++ AVRational frame_rate; ++ int ret; ++ ++ life->class = &life_class; ++ av_opt_set_defaults(life); ++ ++ if ((ret = av_set_options_string(life, args, "=", ":")) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ if ((ret = av_parse_video_rate(&frame_rate, life->rate)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", life->rate); ++ return AVERROR(EINVAL); ++ } ++ ++ if (!life->size && !life->filename) ++ av_opt_set(life, "size", "320x240", 0); ++ ++ if (life->size && ++ (ret = av_parse_video_size(&life->w, &life->h, life->size)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", life->size); ++ return ret; ++ } ++ ++ if ((ret = parse_rule(&life->born_rule, &life->stay_rule, life->rule_str, ctx)) < 0) ++ return ret; ++ ++#define PARSE_COLOR(name) do { \ ++ if ((ret = av_parse_color(life->name ## _color, life->name ## _color_str, -1, ctx))) { \ ++ av_log(ctx, AV_LOG_ERROR, "Invalid " #name " color '%s'\n", \ ++ life->name ## _color_str); \ ++ return ret; \ ++ } \ ++} while (0) ++ ++ PARSE_COLOR(life); ++ PARSE_COLOR(death); ++ PARSE_COLOR(mold); ++ ++ if (!life->mold && memcmp(life->mold_color, "\x00\x00\x00", 3)) ++ av_log(ctx, AV_LOG_WARNING, ++ "Mold color is set while mold isn't, ignoring the color.\n"); ++ ++ life->time_base.num = frame_rate.den; ++ life->time_base.den = frame_rate.num; ++ ++ if (!life->filename) { ++ /* fill the grid randomly */ ++ int i; ++ ++ if (!(life->buf[0] = av_mallocz(sizeof(char) * life->h * life->w)) || ++ !(life->buf[1] = av_mallocz(sizeof(char) * life->h * life->w))) { ++ av_free(life->buf[0]); ++ av_free(life->buf[1]); ++ return AVERROR(ENOMEM); ++ } ++ if (life->random_seed == -1) ++ life->random_seed = av_get_random_seed(); ++ ++ av_lfg_init(&life->lfg, life->random_seed); ++ ++ for (i = 0; i < life->w * life->h; i++) { ++ double r = (double)av_lfg_get(&life->lfg) / UINT32_MAX; ++ if (r <= life->random_fill_ratio) ++ life->buf[0][i] = ALIVE_CELL; ++ } ++ life->buf_idx = 0; ++ } else { ++ if ((ret = init_pattern_from_file(ctx)) < 0) ++ return ret; ++ } ++ ++ av_log(ctx, AV_LOG_INFO, ++ "s:%dx%d r:%d/%d rule:%s stay_rule:%d born_rule:%d stitch:%d seed:%u\n", ++ life->w, life->h, frame_rate.num, frame_rate.den, ++ life->rule_str, life->stay_rule, life->born_rule, life->stitch, ++ life->random_seed); ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ LifeContext *life = ctx->priv; ++ ++ av_file_unmap(life->file_buf, life->file_bufsize); ++ av_freep(&life->rule_str); ++ av_freep(&life->buf[0]); ++ av_freep(&life->buf[1]); ++} ++ ++static int config_props(AVFilterLink *outlink) ++{ ++ LifeContext *life = outlink->src->priv; ++ ++ outlink->w = life->w; ++ outlink->h = life->h; ++ outlink->time_base = life->time_base; ++ ++ return 0; ++} ++ ++static void evolve(AVFilterContext *ctx) ++{ ++ LifeContext *life = ctx->priv; ++ int i, j; ++ uint8_t *oldbuf = life->buf[ life->buf_idx]; ++ uint8_t *newbuf = life->buf[!life->buf_idx]; ++ ++ enum { NW, N, NE, W, E, SW, S, SE }; ++ ++ /* evolve the grid */ ++ for (i = 0; i < life->h; i++) { ++ for (j = 0; j < life->w; j++) { ++ int pos[8][2], n, alive, cell; ++ if (life->stitch) { ++ pos[NW][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NW][1] = (j-1) < 0 ? life->w-1 : j-1; ++ pos[N ][0] = (i-1) < 0 ? life->h-1 : i-1; pos[N ][1] = j ; ++ pos[NE][0] = (i-1) < 0 ? life->h-1 : i-1; pos[NE][1] = (j+1) == life->w ? 0 : j+1; ++ pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? life->w-1 : j-1; ++ pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? 0 : j+1; ++ pos[SW][0] = (i+1) == life->h ? 0 : i+1; pos[SW][1] = (j-1) < 0 ? life->w-1 : j-1; ++ pos[S ][0] = (i+1) == life->h ? 0 : i+1; pos[S ][1] = j ; ++ pos[SE][0] = (i+1) == life->h ? 0 : i+1; pos[SE][1] = (j+1) == life->w ? 0 : j+1; ++ } else { ++ pos[NW][0] = (i-1) < 0 ? -1 : i-1; pos[NW][1] = (j-1) < 0 ? -1 : j-1; ++ pos[N ][0] = (i-1) < 0 ? -1 : i-1; pos[N ][1] = j ; ++ pos[NE][0] = (i-1) < 0 ? -1 : i-1; pos[NE][1] = (j+1) == life->w ? -1 : j+1; ++ pos[W ][0] = i ; pos[W ][1] = (j-1) < 0 ? -1 : j-1; ++ pos[E ][0] = i ; pos[E ][1] = (j+1) == life->w ? -1 : j+1; ++ pos[SW][0] = (i+1) == life->h ? -1 : i+1; pos[SW][1] = (j-1) < 0 ? -1 : j-1; ++ pos[S ][0] = (i+1) == life->h ? -1 : i+1; pos[S ][1] = j ; ++ pos[SE][0] = (i+1) == life->h ? -1 : i+1; pos[SE][1] = (j+1) == life->w ? -1 : j+1; ++ } ++ ++ /* compute the number of live neighbor cells */ ++ n = (pos[NW][0] == -1 || pos[NW][1] == -1 ? 0 : oldbuf[pos[NW][0]*life->w + pos[NW][1]] == ALIVE_CELL) + ++ (pos[N ][0] == -1 || pos[N ][1] == -1 ? 0 : oldbuf[pos[N ][0]*life->w + pos[N ][1]] == ALIVE_CELL) + ++ (pos[NE][0] == -1 || pos[NE][1] == -1 ? 0 : oldbuf[pos[NE][0]*life->w + pos[NE][1]] == ALIVE_CELL) + ++ (pos[W ][0] == -1 || pos[W ][1] == -1 ? 0 : oldbuf[pos[W ][0]*life->w + pos[W ][1]] == ALIVE_CELL) + ++ (pos[E ][0] == -1 || pos[E ][1] == -1 ? 0 : oldbuf[pos[E ][0]*life->w + pos[E ][1]] == ALIVE_CELL) + ++ (pos[SW][0] == -1 || pos[SW][1] == -1 ? 0 : oldbuf[pos[SW][0]*life->w + pos[SW][1]] == ALIVE_CELL) + ++ (pos[S ][0] == -1 || pos[S ][1] == -1 ? 0 : oldbuf[pos[S ][0]*life->w + pos[S ][1]] == ALIVE_CELL) + ++ (pos[SE][0] == -1 || pos[SE][1] == -1 ? 0 : oldbuf[pos[SE][0]*life->w + pos[SE][1]] == ALIVE_CELL); ++ cell = oldbuf[i*life->w + j]; ++ alive = 1<stay_rule : life->born_rule); ++ if (alive) *newbuf = ALIVE_CELL; // new cell is alive ++ else if (cell) *newbuf = cell - 1; // new cell is dead and in the process of mold ++ else *newbuf = 0; // new cell is definitely dead ++ av_dlog(ctx, "i:%d j:%d live_neighbors:%d cell:%d -> cell:%d\n", i, j, n, cell, *newbuf); ++ newbuf++; ++ } ++ } ++ ++ life->buf_idx = !life->buf_idx; ++} ++ ++static void fill_picture_monoblack(AVFilterContext *ctx, AVFilterBufferRef *picref) ++{ ++ LifeContext *life = ctx->priv; ++ uint8_t *buf = life->buf[life->buf_idx]; ++ int i, j, k; ++ ++ /* fill the output picture with the old grid buffer */ ++ for (i = 0; i < life->h; i++) { ++ uint8_t byte = 0; ++ uint8_t *p = picref->data[0] + i * picref->linesize[0]; ++ for (k = 0, j = 0; j < life->w; j++) { ++ byte |= (buf[i*life->w+j] == ALIVE_CELL)<<(7-k++); ++ if (k==8 || j == life->w-1) { ++ k = 0; ++ *p++ = byte; ++ byte = 0; ++ } ++ } ++ } ++} ++ ++// divide by 255 and round to nearest ++// apply a fast variant: (X+127)/255 = ((X+127)*257+257)>>16 = ((X+128)*257)>>16 ++#define FAST_DIV255(x) ((((x) + 128) * 257) >> 16) ++ ++static void fill_picture_rgb(AVFilterContext *ctx, AVFilterBufferRef *picref) ++{ ++ LifeContext *life = ctx->priv; ++ uint8_t *buf = life->buf[life->buf_idx]; ++ int i, j; ++ ++ /* fill the output picture with the old grid buffer */ ++ for (i = 0; i < life->h; i++) { ++ uint8_t *p = picref->data[0] + i * picref->linesize[0]; ++ for (j = 0; j < life->w; j++) { ++ uint8_t v = buf[i*life->w + j]; ++ if (life->mold && v != ALIVE_CELL) { ++ const uint8_t *c1 = life-> mold_color; ++ const uint8_t *c2 = life->death_color; ++ int death_age = FFMIN((0xff - v) * life->mold, 0xff); ++ *p++ = FAST_DIV255((c2[0] << 8) + ((int)c1[0] - (int)c2[0]) * death_age); ++ *p++ = FAST_DIV255((c2[1] << 8) + ((int)c1[1] - (int)c2[1]) * death_age); ++ *p++ = FAST_DIV255((c2[2] << 8) + ((int)c1[2] - (int)c2[2]) * death_age); ++ } else { ++ const uint8_t *c = v == ALIVE_CELL ? life->life_color : life->death_color; ++ AV_WB24(p, c[0]<<16 | c[1]<<8 | c[2]); ++ p += 3; ++ } ++ } ++ } ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ LifeContext *life = outlink->src->priv; ++ AVFilterBufferRef *picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, life->w, life->h); ++ picref->video->sample_aspect_ratio = (AVRational) {1, 1}; ++ picref->pts = life->pts++; ++ picref->pos = -1; ++ ++ life->draw(outlink->src, picref); ++ evolve(outlink->src); ++#ifdef DEBUG ++ show_life_grid(outlink->src); ++#endif ++ ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, life->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ LifeContext *life = ctx->priv; ++ enum PixelFormat pix_fmts[] = { PIX_FMT_NONE, PIX_FMT_NONE }; ++ if (life->mold || memcmp(life-> life_color, "\xff\xff\xff", 3) ++ || memcmp(life->death_color, "\x00\x00\x00", 3)) { ++ pix_fmts[0] = PIX_FMT_RGB24; ++ life->draw = fill_picture_rgb; ++ } else { ++ pix_fmts[0] = PIX_FMT_MONOBLACK; ++ life->draw = fill_picture_monoblack; ++ } ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_life = { ++ .name = "life", ++ .description = NULL_IF_CONFIG_SMALL("Create life."), ++ .priv_size = sizeof(LifeContext), ++ .init = init, ++ .uninit = uninit, ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) { ++ { .name = NULL} ++ }, ++ .outputs = (const AVFilterPad[]) { ++ { .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_props }, ++ { .name = NULL} ++ }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_mandelbrot.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_mandelbrot.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_mandelbrot.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_mandelbrot.c 2012-05-14 14:08:54.847350306 +0200 +@@ -0,0 +1,429 @@ ++/* ++ * Copyright (c) 2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ * ++ * The vsrc_color filter from Stefano Sabatini was used as template to create ++ * this ++ */ ++ ++/** ++ * @file ++ * Mandelbrot fraktal renderer ++ */ ++ ++#include "avfilter.h" ++#include "libavutil/imgutils.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include ++#include ++ ++#define SQR(a) ((a)*(a)) ++ ++enum Outer{ ++ ITERATION_COUNT, ++ NORMALIZED_ITERATION_COUNT, ++}; ++ ++enum Inner{ ++ BLACK, ++ PERIOD, ++ CONVTIME, ++ MINCOL, ++}; ++ ++typedef struct Point { ++ double p[2]; ++ uint32_t val; ++} Point; ++ ++typedef struct { ++ const AVClass *class; ++ int w, h; ++ AVRational time_base; ++ uint64_t pts; ++ char *size, *rate; ++ int maxiter; ++ double start_x; ++ double start_y; ++ double start_scale; ++ double end_scale; ++ double end_pts; ++ double bailout; ++ enum Outer outer; ++ enum Inner inner; ++ int cache_allocated; ++ int cache_used; ++ Point *point_cache; ++ Point *next_cache; ++ double (*zyklus)[2]; ++ uint32_t dither; ++} MBContext; ++ ++#define OFFSET(x) offsetof(MBContext, x) ++ ++static const AVOption mandelbrot_options[] = { ++ {"size", "set frame size", OFFSET(size), AV_OPT_TYPE_STRING, {.str="640x480"}, CHAR_MIN, CHAR_MAX }, ++ {"s", "set frame size", OFFSET(size), AV_OPT_TYPE_STRING, {.str="640x480"}, CHAR_MIN, CHAR_MAX }, ++ {"rate", "set frame rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str="25"}, CHAR_MIN, CHAR_MAX }, ++ {"r", "set frame rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str="25"}, CHAR_MIN, CHAR_MAX }, ++ {"maxiter", "set max iterations number", OFFSET(maxiter), AV_OPT_TYPE_INT, {.dbl=7189}, 1, INT_MAX }, ++ {"start_x", "set the initial x position", OFFSET(start_x), AV_OPT_TYPE_DOUBLE, {.dbl=-0.743643887037158704752191506114774}, -100, 100 }, ++ {"start_y", "set the initial y position", OFFSET(start_y), AV_OPT_TYPE_DOUBLE, {.dbl=-0.131825904205311970493132056385139}, -100, 100 }, ++ {"start_scale", "set the initial scale value", OFFSET(start_scale), AV_OPT_TYPE_DOUBLE, {.dbl=3.0}, 0, FLT_MAX }, ++ {"end_scale", "set the terminal scale value", OFFSET(end_scale), AV_OPT_TYPE_DOUBLE, {.dbl=0.3}, 0, FLT_MAX }, ++ {"end_pts", "set the terminal pts value", OFFSET(end_pts), AV_OPT_TYPE_DOUBLE, {.dbl=400}, 0, INT64_MAX }, ++ {"bailout", "set the bailout value", OFFSET(bailout), AV_OPT_TYPE_DOUBLE, {.dbl=10}, 0, FLT_MAX }, ++ ++ {"outer", "set outer coloring mode", OFFSET(outer), AV_OPT_TYPE_INT, {.dbl=NORMALIZED_ITERATION_COUNT}, 0, INT_MAX, 0, "outer"}, ++ {"iteration_count", "set iteration count mode", 0, AV_OPT_TYPE_CONST, {.dbl=ITERATION_COUNT}, INT_MIN, INT_MAX, 0, "outer" }, ++ {"normalized_iteration_count", "set normalized iteration count mode", 0, AV_OPT_TYPE_CONST, {.dbl=NORMALIZED_ITERATION_COUNT}, INT_MIN, INT_MAX, 0, "outer" }, ++ ++ {"inner", "set inner coloring mode", OFFSET(inner), AV_OPT_TYPE_INT, {.dbl=MINCOL}, 0, INT_MAX, 0, "inner"}, ++ {"black", "set black mode", 0, AV_OPT_TYPE_CONST, {.dbl=BLACK}, INT_MIN, INT_MAX, 0, "inner" }, ++ {"period", "set period mode", 0, AV_OPT_TYPE_CONST, {.dbl=PERIOD}, INT_MIN, INT_MAX, 0, "inner" }, ++ {"convergence", "show time until convergence", 0, AV_OPT_TYPE_CONST, {.dbl=CONVTIME}, INT_MIN, INT_MAX, 0, "inner" }, ++ {"mincol", "color based on point closest to the origin of the iterations", 0, AV_OPT_TYPE_CONST, {.dbl=MINCOL}, INT_MIN, INT_MAX, 0, "inner" }, ++ ++ {NULL}, ++}; ++ ++static const char *mandelbrot_get_name(void *ctx) ++{ ++ return "mandelbrot"; ++} ++ ++static const AVClass mandelbrot_class = { ++ "MBContext", ++ mandelbrot_get_name, ++ mandelbrot_options ++}; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ MBContext *mb = ctx->priv; ++ AVRational rate_q; ++ int err; ++ ++ mb->class = &mandelbrot_class; ++ av_opt_set_defaults(mb); ++ ++ if ((err = (av_set_options_string(mb, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return err; ++ } ++ mb->bailout *= mb->bailout; ++ ++ if (av_parse_video_size(&mb->w, &mb->h, mb->size) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: %s\n", mb->size); ++ return AVERROR(EINVAL); ++ } ++ mb->start_scale /=mb->h; ++ mb->end_scale /=mb->h; ++ ++ if (av_parse_video_rate(&rate_q, mb->rate) < 0 || ++ rate_q.den <= 0 || rate_q.num <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: %s\n", mb->rate); ++ return AVERROR(EINVAL); ++ } ++ mb->time_base.num = rate_q.den; ++ mb->time_base.den = rate_q.num; ++ ++ mb->cache_allocated = mb->w * mb->h * 3; ++ mb->cache_used = 0; ++ mb->point_cache= av_malloc(sizeof(*mb->point_cache)*mb->cache_allocated); ++ mb-> next_cache= av_malloc(sizeof(*mb-> next_cache)*mb->cache_allocated); ++ mb-> zyklus = av_malloc(sizeof(*mb->zyklus) * (mb->maxiter+16)); ++ ++ return 0; ++} ++ ++static av_cold void uninit(AVFilterContext *ctx) ++{ ++ MBContext *mb = ctx->priv; ++ ++ av_freep(&mb->size); ++ av_freep(&mb->rate); ++ av_freep(&mb->point_cache); ++ av_freep(&mb-> next_cache); ++ av_freep(&mb->zyklus); ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_BGR32, ++ PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int config_props(AVFilterLink *inlink) ++{ ++ AVFilterContext *ctx = inlink->src; ++ MBContext *mb = ctx->priv; ++ ++ if (av_image_check_size(mb->w, mb->h, 0, ctx) < 0) ++ return AVERROR(EINVAL); ++ ++ inlink->w = mb->w; ++ inlink->h = mb->h; ++ inlink->time_base = mb->time_base; ++ ++ return 0; ++} ++ ++static void fill_from_cache(AVFilterContext *ctx, uint32_t *color, int *in_cidx, int *out_cidx, double py, double scale){ ++ MBContext *mb = ctx->priv; ++ for(; *in_cidx < mb->cache_used; (*in_cidx)++){ ++ Point *p= &mb->point_cache[*in_cidx]; ++ int x; ++ if(p->p[1] > py) ++ break; ++ x= round((p->p[0] - mb->start_x) / scale + mb->w/2); ++ if(x<0 || x >= mb->w) ++ continue; ++ if(color) color[x] = p->val; ++ if(out_cidx && *out_cidx < mb->cache_allocated) ++ mb->next_cache[(*out_cidx)++]= *p; ++ } ++} ++ ++static int interpol(MBContext *mb, uint32_t *color, int x, int y, int linesize) ++{ ++ uint32_t a,b,c,d, i; ++ uint32_t ipol=0xFF000000; ++ int dist; ++ ++ if(!x || !y || x+1==mb->w || y+1==mb->h) ++ return 0; ++ ++ dist= FFMAX(FFABS(x-(mb->w>>1))*mb->h, FFABS(y-(mb->h>>1))*mb->w); ++ ++ if(dist<(mb->w*mb->h>>3)) ++ return 0; ++ ++ a=color[(x+1) + (y+0)*linesize]; ++ b=color[(x-1) + (y+1)*linesize]; ++ c=color[(x+0) + (y+1)*linesize]; ++ d=color[(x+1) + (y+1)*linesize]; ++ ++ if(a&&c){ ++ b= color[(x-1) + (y+0)*linesize]; ++ d= color[(x+0) + (y-1)*linesize]; ++ }else if(b&&d){ ++ a= color[(x+1) + (y-1)*linesize]; ++ c= color[(x-1) + (y-1)*linesize]; ++ }else if(c){ ++ d= color[(x+0) + (y-1)*linesize]; ++ a= color[(x-1) + (y+0)*linesize]; ++ b= color[(x+1) + (y-1)*linesize]; ++ }else if(d){ ++ c= color[(x-1) + (y-1)*linesize]; ++ a= color[(x-1) + (y+0)*linesize]; ++ b= color[(x+1) + (y-1)*linesize]; ++ }else ++ return 0; ++ ++ for(i=0; i<3; i++){ ++ int s= 8*i; ++ uint8_t ac= a>>s; ++ uint8_t bc= b>>s; ++ uint8_t cc= c>>s; ++ uint8_t dc= d>>s; ++ int ipolab= (ac + bc); ++ int ipolcd= (cc + dc); ++ if(FFABS(ipolab - ipolcd) > 5) ++ return 0; ++ if(FFABS(ac-bc)+FFABS(cc-dc) > 20) ++ return 0; ++ ipol |= ((ipolab + ipolcd + 2)/4)<priv; ++ int x,y,i, in_cidx=0, next_cidx=0, tmp_cidx; ++ double scale= mb->start_scale*pow(mb->end_scale/mb->start_scale, pts/mb->end_pts); ++ int use_zyklus=0; ++ fill_from_cache(ctx, NULL, &in_cidx, NULL, mb->start_y+scale*(-mb->h/2-0.5), scale); ++ tmp_cidx= in_cidx; ++ memset(color, 0, sizeof(*color)*mb->w); ++ for(y=0; yh; y++){ ++ int y1= y+1; ++ const double ci=mb->start_y+scale*(y-mb->h/2); ++ fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci, scale); ++ if(y1h){ ++ memset(color+linesize*y1, 0, sizeof(*color)*mb->w); ++ fill_from_cache(ctx, color+linesize*y1, &tmp_cidx, NULL, ci + 3*scale/2, scale); ++ } ++ ++ for(x=0; xw; x++){ ++ float av_uninit(epsilon); ++ const double cr=mb->start_x+scale*(x-mb->w/2); ++ double zr=cr; ++ double zi=ci; ++ uint32_t c=0; ++ double dv= mb->dither / (double)(1LL<<32); ++ mb->dither= mb->dither*1664525+1013904223; ++ ++ if(color[x + y*linesize] & 0xFF000000) ++ continue; ++ if(interpol(mb, color, x, y, linesize)){ ++ if(next_cidx < mb->cache_allocated){ ++ mb->next_cache[next_cidx ].p[0]= cr; ++ mb->next_cache[next_cidx ].p[1]= ci; ++ mb->next_cache[next_cidx++].val = color[x + y*linesize]; ++ } ++ continue; ++ } ++ ++ use_zyklus= (x==0 || mb->inner!=BLACK ||color[x-1 + y*linesize] == 0xFF000000); ++ if(use_zyklus) ++ epsilon= scale*1*sqrt(SQR(x-mb->w/2) + SQR(y-mb->h/2))/mb->w; ++ ++#define Z_Z2_C(outr,outi,inr,ini)\ ++ outr= inr*inr - ini*ini + cr;\ ++ outi= 2*inr*ini + ci; ++ ++#define Z_Z2_C_ZYKLUS(outr,outi,inr,ini, Z)\ ++ Z_Z2_C(outr,outi,inr,ini)\ ++ if(use_zyklus){\ ++ if(Z && fabs(mb->zyklus[i>>1][0]-outr)+fabs(mb->zyklus[i>>1][1]-outi) <= epsilon)\ ++ break;\ ++ }\ ++ mb->zyklus[i][0]= outr;\ ++ mb->zyklus[i][1]= outi;\ ++ ++ ++ ++ for(i=0; imaxiter-8; i++){ ++ double t; ++ Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) ++ i++; ++ Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) ++ i++; ++ Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) ++ i++; ++ Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) ++ i++; ++ Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) ++ i++; ++ Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) ++ i++; ++ Z_Z2_C_ZYKLUS(t, zi, zr, zi, 0) ++ i++; ++ Z_Z2_C_ZYKLUS(zr, zi, t, zi, 1) ++ if(zr*zr + zi*zi > mb->bailout){ ++ i-= FFMIN(7, i); ++ for(; imaxiter; i++){ ++ zr= mb->zyklus[i][0]; ++ zi= mb->zyklus[i][1]; ++ if(zr*zr + zi*zi > mb->bailout){ ++ switch(mb->outer){ ++ case ITERATION_COUNT: zr = i; break; ++ case NORMALIZED_ITERATION_COUNT: zr= i + log2(log(mb->bailout) / log(zr*zr + zi*zi)); break; ++ } ++ c= lrintf((sin(zr)+1)*127) + lrintf((sin(zr/1.234)+1)*127)*256*256 + lrintf((sin(zr/100)+1)*127)*256; ++ break; ++ } ++ } ++ break; ++ } ++ } ++ if(!c){ ++ if(mb->inner==PERIOD){ ++ int j; ++ for(j=i-1; j; j--) ++ if(SQR(mb->zyklus[j][0]-zr) + SQR(mb->zyklus[j][1]-zi) < epsilon*epsilon*10) ++ break; ++ if(j){ ++ c= i-j; ++ c= ((c<<5)&0xE0) + ((c<<16)&0xE000) + ((c<<27)&0xE00000); ++ } ++ }else if(mb->inner==CONVTIME){ ++ c= floor(i*255.0/mb->maxiter+dv)*0x010101; ++ } else if(mb->inner==MINCOL){ ++ int j; ++ double closest=9999; ++ int closest_index=0; ++ for(j=i-1; j>=0; j--) ++ if(SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]) < closest){ ++ closest= SQR(mb->zyklus[j][0]) + SQR(mb->zyklus[j][1]); ++ closest_index= j; ++ } ++ closest = sqrt(closest); ++ c= lrintf((mb->zyklus[closest_index][0]/closest+1)*127+dv) + lrintf((mb->zyklus[closest_index][1]/closest+1)*127+dv)*256; ++ } ++ } ++ c |= 0xFF000000; ++ color[x + y*linesize]= c; ++ if(next_cidx < mb->cache_allocated){ ++ mb->next_cache[next_cidx ].p[0]= cr; ++ mb->next_cache[next_cidx ].p[1]= ci; ++ mb->next_cache[next_cidx++].val = c; ++ } ++ } ++ fill_from_cache(ctx, NULL, &in_cidx, &next_cidx, ci + scale/2, scale); ++ } ++ FFSWAP(void*, mb->next_cache, mb->point_cache); ++ mb->cache_used = next_cidx; ++ if(mb->cache_used == mb->cache_allocated) ++ av_log(0, AV_LOG_INFO, "Mandelbrot cache is too small!\n"); ++} ++ ++static int request_frame(AVFilterLink *link) ++{ ++ MBContext *mb = link->src->priv; ++ AVFilterBufferRef *picref = avfilter_get_video_buffer(link, AV_PERM_WRITE, mb->w, mb->h); ++ picref->video->sample_aspect_ratio = (AVRational) {1, 1}; ++ picref->pts = mb->pts++; ++ picref->pos = -1; ++ ++ avfilter_start_frame(link, avfilter_ref_buffer(picref, ~0)); ++ draw_mandelbrot(link->src, (uint32_t*)picref->data[0], picref->linesize[0]/4, picref->pts); ++ avfilter_draw_slice(link, 0, mb->h, 1); ++ avfilter_end_frame(link); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_mandelbrot = { ++ .name = "mandelbrot", ++ .description = NULL_IF_CONFIG_SMALL("Render a Mandelbrot fractal."), ++ ++ .priv_size = sizeof(MBContext), ++ .init = init, ++ .uninit = uninit, ++ ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_props }, ++ { .name = NULL}}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_mptestsrc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_mptestsrc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_mptestsrc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_mptestsrc.c 2012-05-14 14:08:54.848350326 +0200 +@@ -0,0 +1,392 @@ ++/* ++ * Copyright (c) 2002 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg 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. ++ * ++ * FFmpeg 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 FFmpeg; if not, write to the Free Software Foundation, Inc., ++ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ */ ++ ++/** ++ * @file ++ * MP test source, ported from MPlayer libmpcodecs/vf_test.c ++ */ ++ ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" ++#include "avfilter.h" ++ ++#define WIDTH 512 ++#define HEIGHT 512 ++ ++enum test_type { ++ TEST_DC_LUMA, ++ TEST_DC_CHROMA, ++ TEST_FREQ_LUMA, ++ TEST_FREQ_CHROMA, ++ TEST_AMP_LUMA, ++ TEST_AMP_CHROMA, ++ TEST_CBP, ++ TEST_MV, ++ TEST_RING1, ++ TEST_RING2, ++ TEST_ALL, ++ TEST_NB ++}; ++ ++typedef struct MPTestContext { ++ const AVClass *class; ++ unsigned int frame_nb; ++ AVRational time_base; ++ int64_t pts, max_pts; ++ int hsub, vsub; ++ char *size, *rate, *duration; ++ enum test_type test; ++} MPTestContext; ++ ++#define OFFSET(x) offsetof(MPTestContext, x) ++ ++static const AVOption mptestsrc_options[]= { ++ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ ++ { "test", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.dbl=TEST_ALL}, 0, INT_MAX, 0, "test" }, ++ { "t", "set test to perform", OFFSET(test), AV_OPT_TYPE_INT, {.dbl=TEST_ALL}, 0, INT_MAX, 0, "test" }, ++ { "dc_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_DC_LUMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "dc_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_DC_CHROMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "freq_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_FREQ_LUMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "freq_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_FREQ_CHROMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "amp_luma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_AMP_LUMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "amp_chroma", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_AMP_CHROMA}, INT_MIN, INT_MAX, 0, "test" }, ++ { "cbp", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_CBP}, INT_MIN, INT_MAX, 0, "test" }, ++ { "mv", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_MV}, INT_MIN, INT_MAX, 0, "test" }, ++ { "ring1", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_RING1}, INT_MIN, INT_MAX, 0, "test" }, ++ { "ring2", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_RING2}, INT_MIN, INT_MAX, 0, "test" }, ++ { "all", "", 0, AV_OPT_TYPE_CONST, {.dbl=TEST_ALL}, INT_MIN, INT_MAX, 0, "test" }, ++ ++ { NULL }, ++}; ++ ++static const char *mptestsrc_get_name(void *ctx) ++{ ++ return "mptestsrc"; ++} ++ ++static const AVClass mptestsrc_class = { ++ "MPTestContext", ++ mptestsrc_get_name, ++ mptestsrc_options ++}; ++ ++static double c[64]; ++ ++static void init_idct(void) ++{ ++ int i, j; ++ ++ for (i = 0; i < 8; i++) { ++ double s = i == 0 ? sqrt(0.125) : 0.5; ++ ++ for (j = 0; j < 8; j++) ++ c[i*8+j] = s*cos((M_PI/8.0)*i*(j+0.5)); ++ } ++} ++ ++static void idct(uint8_t *dst, int dst_linesize, int src[64]) ++{ ++ int i, j, k; ++ double tmp[64]; ++ ++ for (i = 0; i < 8; i++) { ++ for (j = 0; j < 8; j++) { ++ double sum = 0.0; ++ ++ for (k = 0; k < 8; k++) ++ sum += c[k*8+j] * src[8*i+k]; ++ ++ tmp[8*i+j] = sum; ++ } ++ } ++ ++ for (j = 0; j < 8; j++) { ++ for (i = 0; i < 8; i++) { ++ double sum = 0.0; ++ ++ for (k = 0; k < 8; k++) ++ sum += c[k*8+i]*tmp[8*k+j]; ++ ++ dst[dst_linesize*i + j] = av_clip((int)floor(sum+0.5), 0, 255); ++ } ++ } ++} ++ ++static void draw_dc(uint8_t *dst, int dst_linesize, int color, int w, int h) ++{ ++ int x, y; ++ ++ for (y = 0; y < h; y++) ++ for (x = 0; x < w; x++) ++ dst[x + y*dst_linesize] = color; ++} ++ ++static void draw_basis(uint8_t *dst, int dst_linesize, int amp, int freq, int dc) ++{ ++ int src[64]; ++ ++ memset(src, 0, 64*sizeof(int)); ++ src[0] = dc; ++ if (amp) ++ src[freq] = amp; ++ idct(dst, dst_linesize, src); ++} ++ ++static void draw_cbp(uint8_t *dst[3], int dst_linesize[3], int cbp, int amp, int dc) ++{ ++ if (cbp&1) draw_basis(dst[0] , dst_linesize[0], amp, 1, dc); ++ if (cbp&2) draw_basis(dst[0]+8 , dst_linesize[0], amp, 1, dc); ++ if (cbp&4) draw_basis(dst[0]+ 8*dst_linesize[0], dst_linesize[0], amp, 1, dc); ++ if (cbp&8) draw_basis(dst[0]+8+8*dst_linesize[0], dst_linesize[0], amp, 1, dc); ++ if (cbp&16) draw_basis(dst[1] , dst_linesize[1], amp, 1, dc); ++ if (cbp&32) draw_basis(dst[2] , dst_linesize[2], amp, 1, dc); ++} ++ ++static void dc_test(uint8_t *dst, int dst_linesize, int w, int h, int off) ++{ ++ const int step = FFMAX(256/(w*h/256), 1); ++ int x, y, color = off; ++ ++ for (y = 0; y < h; y += 16) { ++ for (x = 0; x < w; x += 16) { ++ draw_dc(dst + x + y*dst_linesize, dst_linesize, color, 8, 8); ++ color += step; ++ } ++ } ++} ++ ++static void freq_test(uint8_t *dst, int dst_linesize, int off) ++{ ++ int x, y, freq = 0; ++ ++ for (y = 0; y < 8*16; y += 16) { ++ for (x = 0; x < 8*16; x += 16) { ++ draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*(96+off), freq, 128*8); ++ freq++; ++ } ++ } ++} ++ ++static void amp_test(uint8_t *dst, int dst_linesize, int off) ++{ ++ int x, y, amp = off; ++ ++ for (y = 0; y < 16*16; y += 16) { ++ for (x = 0; x < 16*16; x += 16) { ++ draw_basis(dst + x + y*dst_linesize, dst_linesize, 4*amp, 1, 128*8); ++ amp++; ++ } ++ } ++} ++ ++static void cbp_test(uint8_t *dst[3], int dst_linesize[3], int off) ++{ ++ int x, y, cbp = 0; ++ ++ for (y = 0; y < 16*8; y += 16) { ++ for (x = 0; x < 16*8; x += 16) { ++ uint8_t *dst1[3]; ++ dst1[0] = dst[0] + x*2 + y*2*dst_linesize[0]; ++ dst1[1] = dst[1] + x + y* dst_linesize[1]; ++ dst1[2] = dst[2] + x + y* dst_linesize[2]; ++ ++ draw_cbp(dst1, dst_linesize, cbp, (64+off)*4, 128*8); ++ cbp++; ++ } ++ } ++} ++ ++static void mv_test(uint8_t *dst, int dst_linesize, int off) ++{ ++ int x, y; ++ ++ for (y = 0; y < 16*16; y++) { ++ if (y&16) ++ continue; ++ for (x = 0; x < 16*16; x++) ++ dst[x + y*dst_linesize] = x + off*8/(y/32+1); ++ } ++} ++ ++static void ring1_test(uint8_t *dst, int dst_linesize, int off) ++{ ++ int x, y, color = 0; ++ ++ for (y = off; y < 16*16; y += 16) { ++ for (x = off; x < 16*16; x += 16) { ++ draw_dc(dst + x + y*dst_linesize, dst_linesize, ((x+y)&16) ? color : -color, 16, 16); ++ color++; ++ } ++ } ++} ++ ++static void ring2_test(uint8_t *dst, int dst_linesize, int off) ++{ ++ int x, y; ++ ++ for (y = 0; y < 16*16; y++) { ++ for (x = 0; x < 16*16; x++) { ++ double d = sqrt((x-8*16)*(x-8*16) + (y-8*16)*(y-8*16)); ++ double r = d/20 - (int)(d/20); ++ if (r < off/30.0) { ++ dst[x + y*dst_linesize] = 255; ++ dst[x + y*dst_linesize+256] = 0; ++ } else { ++ dst[x + y*dst_linesize] = x; ++ dst[x + y*dst_linesize+256] = x; ++ } ++ } ++ } ++} ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ MPTestContext *test = ctx->priv; ++ AVRational frame_rate_q; ++ int64_t duration = -1; ++ int ret; ++ ++ test->class = &mptestsrc_class; ++ av_opt_set_defaults(test); ++ ++ if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 || ++ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate); ++ return ret; ++ } ++ ++ if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration); ++ return ret; ++ } ++ ++ test->time_base.num = frame_rate_q.den; ++ test->time_base.den = frame_rate_q.num; ++ test->max_pts = duration >= 0 ? ++ av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1; ++ test->frame_nb = 0; ++ test->pts = 0; ++ ++ av_log(ctx, AV_LOG_INFO, "rate:%d/%d duration:%f\n", ++ frame_rate_q.num, frame_rate_q.den, ++ duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base)); ++ init_idct(); ++ ++ return 0; ++} ++ ++static int config_props(AVFilterLink *outlink) ++{ ++ AVFilterContext *ctx = outlink->src; ++ MPTestContext *test = ctx->priv; ++ const AVPixFmtDescriptor *pix_desc = &av_pix_fmt_descriptors[outlink->format]; ++ ++ test->hsub = pix_desc->log2_chroma_w; ++ test->vsub = pix_desc->log2_chroma_h; ++ ++ outlink->w = WIDTH; ++ outlink->h = HEIGHT; ++ outlink->time_base = test->time_base; ++ ++ return 0; ++} ++ ++static int query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_YUV420P, PIX_FMT_NONE ++ }; ++ ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ MPTestContext *test = outlink->src->priv; ++ AVFilterBufferRef *picref; ++ int w = WIDTH, h = HEIGHT, ch = h>>test->vsub; ++ unsigned int frame = test->frame_nb; ++ enum test_type tt = test->test; ++ ++ if (test->max_pts >= 0 && test->pts > test->max_pts) ++ return AVERROR_EOF; ++ picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, w, h); ++ picref->pts = test->pts++; ++ ++ // clean image ++ memset(picref->data[0], 0, picref->linesize[0] * h); ++ memset(picref->data[1], 128, picref->linesize[1] * ch); ++ memset(picref->data[2], 128, picref->linesize[2] * ch); ++ ++ if (tt == TEST_ALL && frame%30) /* draw a black frame at the beginning of each test */ ++ tt = (frame/30)%(TEST_NB-1); ++ ++ switch (tt) { ++ case TEST_DC_LUMA: dc_test(picref->data[0], picref->linesize[0], 256, 256, frame%30); break; ++ case TEST_DC_CHROMA: dc_test(picref->data[1], picref->linesize[1], 256, 256, frame%30); break; ++ case TEST_FREQ_LUMA: freq_test(picref->data[0], picref->linesize[0], frame%30); break; ++ case TEST_FREQ_CHROMA: freq_test(picref->data[1], picref->linesize[1], frame%30); break; ++ case TEST_AMP_LUMA: amp_test(picref->data[0], picref->linesize[0], frame%30); break; ++ case TEST_AMP_CHROMA: amp_test(picref->data[1], picref->linesize[1], frame%30); break; ++ case TEST_CBP: cbp_test(picref->data , picref->linesize , frame%30); break; ++ case TEST_MV: mv_test(picref->data[0], picref->linesize[0], frame%30); break; ++ case TEST_RING1: ring1_test(picref->data[0], picref->linesize[0], frame%30); break; ++ case TEST_RING2: ring2_test(picref->data[0], picref->linesize[0], frame%30); break; ++ } ++ ++ test->frame_nb++; ++ ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, picref->video->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_mptestsrc = { ++ .name = "mptestsrc", ++ .description = NULL_IF_CONFIG_SMALL("Generate various test pattern."), ++ .priv_size = sizeof(MPTestContext), ++ .init = init, ++ ++ .query_formats = query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .config_props = config_props, ++ .request_frame = request_frame, ++ .config_props = config_props, }, ++ { .name = NULL }}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_nullsrc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_nullsrc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_nullsrc.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_nullsrc.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,129 +0,0 @@ +-/* +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * null video source +- */ +- +-#include "libavutil/avstring.h" +-#include "libavutil/eval.h" +-#include "libavcore/parseutils.h" +-#include "avfilter.h" +- +-static const char *var_names[] = { +- "E", +- "PHI", +- "PI", +- "AVTB", /* default timebase 1/AV_TIME_BASE */ +- NULL +-}; +- +-enum var_name { +- VAR_E, +- VAR_PHI, +- VAR_PI, +- VAR_AVTB, +- VAR_VARS_NB +-}; +- +-typedef struct { +- int w, h; +- char tb_expr[256]; +- double var_values[VAR_VARS_NB]; +-} NullContext; +- +-static int init(AVFilterContext *ctx, const char *args, void *opaque) +-{ +- NullContext *priv = ctx->priv; +- +- priv->w = 352; +- priv->h = 288; +- av_strlcpy(priv->tb_expr, "AVTB", sizeof(priv->tb_expr)); +- +- if (args) +- sscanf(args, "%d:%d:%255[^:]", &priv->w, &priv->h, priv->tb_expr); +- +- if (priv->w <= 0 || priv->h <= 0) { +- av_log(ctx, AV_LOG_ERROR, "Non-positive size values are not acceptable.\n"); +- return AVERROR(EINVAL); +- } +- +- return 0; +-} +- +-static int config_props(AVFilterLink *outlink) +-{ +- AVFilterContext *ctx = outlink->src; +- NullContext *priv = ctx->priv; +- AVRational tb; +- int ret; +- double res; +- +- priv->var_values[VAR_E] = M_E; +- priv->var_values[VAR_PHI] = M_PHI; +- priv->var_values[VAR_PI] = M_PI; +- priv->var_values[VAR_AVTB] = av_q2d(AV_TIME_BASE_Q); +- +- if ((ret = av_expr_parse_and_eval(&res, priv->tb_expr, var_names, priv->var_values, +- NULL, NULL, NULL, NULL, NULL, 0, NULL)) < 0) { +- av_log(ctx, AV_LOG_ERROR, "Invalid expression '%s' for timebase.\n", priv->tb_expr); +- return ret; +- } +- tb = av_d2q(res, INT_MAX); +- if (tb.num <= 0 || tb.den <= 0) { +- av_log(ctx, AV_LOG_ERROR, +- "Invalid non-positive value for the timebase %d/%d.\n", +- tb.num, tb.den); +- return AVERROR(EINVAL); +- } +- +- outlink->w = priv->w; +- outlink->h = priv->h; +- outlink->time_base = tb; +- +- av_log(outlink->src, AV_LOG_INFO, "w:%d h:%d tb:%d/%d\n", priv->w, priv->h, +- tb.num, tb.den); +- +- return 0; +-} +- +-static int request_frame(AVFilterLink *link) +-{ +- return -1; +-} +- +-AVFilter avfilter_vsrc_nullsrc = { +- .name = "nullsrc", +- .description = NULL_IF_CONFIG_SMALL("Null video source, never return images."), +- +- .init = init, +- .priv_size = sizeof(NullContext), +- +- .inputs = (AVFilterPad[]) {{ .name = NULL}}, +- +- .outputs = (AVFilterPad[]) { +- { +- .name = "default", +- .type = AVMEDIA_TYPE_VIDEO, +- .config_props = config_props, +- .request_frame = request_frame, +- }, +- { .name = NULL} +- }, +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_testsrc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_testsrc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/vsrc_testsrc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/vsrc_testsrc.c 2012-05-14 14:08:54.851350387 +0200 +@@ -0,0 +1,553 @@ ++/* ++ * Copyright (c) 2007 Nicolas George ++ * Copyright (c) 2011 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Misc test sources. ++ * ++ * testsrc is based on the test pattern generator demuxer by Nicolas George: ++ * http://lists.ffmpeg.org/pipermail/ffmpeg-devel/2007-October/037845.html ++ * ++ * rgbtestsrc is ported from MPlayer libmpcodecs/vf_rgbtest.c by ++ * Michael Niedermayer. ++ */ ++ ++#include ++ ++#include "libavutil/opt.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/parseutils.h" ++#include "avfilter.h" ++ ++typedef struct { ++ const AVClass *class; ++ int h, w; ++ unsigned int nb_frame; ++ AVRational time_base; ++ int64_t pts, max_pts; ++ char *size; ///< video frame size ++ char *rate; ///< video frame rate ++ char *duration; ///< total duration of the generated video ++ AVRational sar; ///< sample aspect ratio ++ int nb_decimals; ++ ++ void (* fill_picture_fn)(AVFilterContext *ctx, AVFilterBufferRef *picref); ++ ++ /* only used by rgbtest */ ++ int rgba_map[4]; ++} TestSourceContext; ++ ++#define OFFSET(x) offsetof(TestSourceContext, x) ++ ++static const AVOption testsrc_options[]= { ++ { "size", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 }, ++ { "s", "set video size", OFFSET(size), AV_OPT_TYPE_STRING, {.str = "320x240"}, 0, 0 }, ++ { "rate", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "r", "set video rate", OFFSET(rate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0 }, ++ { "duration", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "d", "set video duration", OFFSET(duration), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0 }, ++ { "sar", "set video sample aspect ratio", OFFSET(sar), AV_OPT_TYPE_RATIONAL, {.dbl= 1}, 0, INT_MAX }, ++ { "decimals", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, ++ { "n", "set number of decimals to show", OFFSET(nb_decimals), AV_OPT_TYPE_INT, {.dbl=0}, INT_MIN, INT_MAX }, ++ { NULL }, ++}; ++ ++static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ TestSourceContext *test = ctx->priv; ++ AVRational frame_rate_q; ++ int64_t duration = -1; ++ int ret = 0; ++ ++ av_opt_set_defaults(test); ++ ++ if ((ret = (av_set_options_string(test, args, "=", ":"))) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Error parsing options string: '%s'\n", args); ++ return ret; ++ } ++ ++ if ((ret = av_parse_video_size(&test->w, &test->h, test->size)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame size: '%s'\n", test->size); ++ return ret; ++ } ++ ++ if ((ret = av_parse_video_rate(&frame_rate_q, test->rate)) < 0 || ++ frame_rate_q.den <= 0 || frame_rate_q.num <= 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid frame rate: '%s'\n", test->rate); ++ return ret; ++ } ++ ++ if ((test->duration) && (ret = av_parse_time(&duration, test->duration, 1)) < 0) { ++ av_log(ctx, AV_LOG_ERROR, "Invalid duration: '%s'\n", test->duration); ++ return ret; ++ } ++ ++ if (test->nb_decimals && strcmp(ctx->filter->name, "testsrc")) { ++ av_log(ctx, AV_LOG_WARNING, ++ "Option 'decimals' is ignored with source '%s'\n", ++ ctx->filter->name); ++ } ++ ++ test->time_base.num = frame_rate_q.den; ++ test->time_base.den = frame_rate_q.num; ++ test->max_pts = duration >= 0 ? ++ av_rescale_q(duration, AV_TIME_BASE_Q, test->time_base) : -1; ++ test->nb_frame = 0; ++ test->pts = 0; ++ ++ av_log(ctx, AV_LOG_INFO, "size:%dx%d rate:%d/%d duration:%f sar:%d/%d\n", ++ test->w, test->h, frame_rate_q.num, frame_rate_q.den, ++ duration < 0 ? -1 : test->max_pts * av_q2d(test->time_base), ++ test->sar.num, test->sar.den); ++ return 0; ++} ++ ++static int config_props(AVFilterLink *outlink) ++{ ++ TestSourceContext *test = outlink->src->priv; ++ ++ outlink->w = test->w; ++ outlink->h = test->h; ++ outlink->sample_aspect_ratio = test->sar; ++ outlink->time_base = test->time_base; ++ ++ return 0; ++} ++ ++static int request_frame(AVFilterLink *outlink) ++{ ++ TestSourceContext *test = outlink->src->priv; ++ AVFilterBufferRef *picref; ++ ++ if (test->max_pts >= 0 && test->pts >= test->max_pts) ++ return AVERROR_EOF; ++ picref = avfilter_get_video_buffer(outlink, AV_PERM_WRITE, ++ test->w, test->h); ++ picref->pts = test->pts++; ++ picref->pos = -1; ++ picref->video->key_frame = 1; ++ picref->video->interlaced = 0; ++ picref->video->pict_type = AV_PICTURE_TYPE_I; ++ picref->video->sample_aspect_ratio = test->sar; ++ test->fill_picture_fn(outlink->src, picref); ++ test->nb_frame++; ++ ++ avfilter_start_frame(outlink, avfilter_ref_buffer(picref, ~0)); ++ avfilter_draw_slice(outlink, 0, picref->video->h, 1); ++ avfilter_end_frame(outlink); ++ avfilter_unref_buffer(picref); ++ ++ return 0; ++} ++ ++#if CONFIG_NULLSRC_FILTER ++ ++static const char *nullsrc_get_name(void *ctx) ++{ ++ return "nullsrc"; ++} ++ ++static const AVClass nullsrc_class = { ++ .class_name = "NullSourceContext", ++ .item_name = nullsrc_get_name, ++ .option = testsrc_options, ++}; ++ ++static void nullsrc_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) { } ++ ++static av_cold int nullsrc_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ TestSourceContext *test = ctx->priv; ++ ++ test->class = &nullsrc_class; ++ test->fill_picture_fn = nullsrc_fill_picture; ++ return init(ctx, args, opaque); ++} ++ ++AVFilter avfilter_vsrc_nullsrc = { ++ .name = "nullsrc", ++ .description = NULL_IF_CONFIG_SMALL("Null video source, return unprocessed video frames."), ++ .init = nullsrc_init, ++ .priv_size = sizeof(TestSourceContext), ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_props, }, ++ { .name = NULL}}, ++}; ++ ++#endif /* CONFIG_NULLSRC_FILTER */ ++ ++#if CONFIG_TESTSRC_FILTER ++ ++static const char *testsrc_get_name(void *ctx) ++{ ++ return "testsrc"; ++} ++ ++static const AVClass testsrc_class = { ++ .class_name = "TestSourceContext", ++ .item_name = testsrc_get_name, ++ .option = testsrc_options, ++}; ++ ++/** ++ * Fill a rectangle with value val. ++ * ++ * @param val the RGB value to set ++ * @param dst pointer to the destination buffer to fill ++ * @param dst_linesize linesize of destination ++ * @param segment_width width of the segment ++ * @param x horizontal coordinate where to draw the rectangle in the destination buffer ++ * @param y horizontal coordinate where to draw the rectangle in the destination buffer ++ * @param w width of the rectangle to draw, expressed as a number of segment_width units ++ * @param h height of the rectangle to draw, expressed as a number of segment_width units ++ */ ++static void draw_rectangle(unsigned val, uint8_t *dst, int dst_linesize, unsigned segment_width, ++ unsigned x, unsigned y, unsigned w, unsigned h) ++{ ++ int i; ++ int step = 3; ++ ++ dst += segment_width * (step * x + y * dst_linesize); ++ w *= segment_width * step; ++ h *= segment_width; ++ for (i = 0; i < h; i++) { ++ memset(dst, val, w); ++ dst += dst_linesize; ++ } ++} ++ ++static void draw_digit(int digit, uint8_t *dst, unsigned dst_linesize, ++ unsigned segment_width) ++{ ++#define TOP_HBAR 1 ++#define MID_HBAR 2 ++#define BOT_HBAR 4 ++#define LEFT_TOP_VBAR 8 ++#define LEFT_BOT_VBAR 16 ++#define RIGHT_TOP_VBAR 32 ++#define RIGHT_BOT_VBAR 64 ++ struct { ++ int x, y, w, h; ++ } segments[] = { ++ { 1, 0, 5, 1 }, /* TOP_HBAR */ ++ { 1, 6, 5, 1 }, /* MID_HBAR */ ++ { 1, 12, 5, 1 }, /* BOT_HBAR */ ++ { 0, 1, 1, 5 }, /* LEFT_TOP_VBAR */ ++ { 0, 7, 1, 5 }, /* LEFT_BOT_VBAR */ ++ { 6, 1, 1, 5 }, /* RIGHT_TOP_VBAR */ ++ { 6, 7, 1, 5 } /* RIGHT_BOT_VBAR */ ++ }; ++ static const unsigned char masks[10] = { ++ /* 0 */ TOP_HBAR |BOT_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 1 */ RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 2 */ TOP_HBAR|MID_HBAR|BOT_HBAR|LEFT_BOT_VBAR |RIGHT_TOP_VBAR, ++ /* 3 */ TOP_HBAR|MID_HBAR|BOT_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 4 */ MID_HBAR |LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 5 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_BOT_VBAR, ++ /* 6 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR |RIGHT_BOT_VBAR, ++ /* 7 */ TOP_HBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 8 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR|LEFT_BOT_VBAR|RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ /* 9 */ TOP_HBAR|BOT_HBAR|MID_HBAR|LEFT_TOP_VBAR |RIGHT_TOP_VBAR|RIGHT_BOT_VBAR, ++ }; ++ unsigned mask = masks[digit]; ++ int i; ++ ++ draw_rectangle(0, dst, dst_linesize, segment_width, 0, 0, 8, 13); ++ for (i = 0; i < FF_ARRAY_ELEMS(segments); i++) ++ if (mask & (1<priv; ++ uint8_t *p, *p0; ++ int x, y; ++ int color, color_rest; ++ int icolor; ++ int radius; ++ int quad0, quad; ++ int dquad_x, dquad_y; ++ int grad, dgrad, rgrad, drgrad; ++ int seg_size; ++ int second; ++ int i; ++ uint8_t *data = picref->data[0]; ++ int width = picref->video->w; ++ int height = picref->video->h; ++ ++ /* draw colored bars and circle */ ++ radius = (width + height) / 4; ++ quad0 = width * width / 4 + height * height / 4 - radius * radius; ++ dquad_y = 1 - height; ++ p0 = data; ++ for (y = 0; y < height; y++) { ++ p = p0; ++ color = 0; ++ color_rest = 0; ++ quad = quad0; ++ dquad_x = 1 - width; ++ for (x = 0; x < width; x++) { ++ icolor = color; ++ if (quad < 0) ++ icolor ^= 7; ++ quad += dquad_x; ++ dquad_x += 2; ++ *(p++) = icolor & 1 ? 255 : 0; ++ *(p++) = icolor & 2 ? 255 : 0; ++ *(p++) = icolor & 4 ? 255 : 0; ++ color_rest += 8; ++ if (color_rest >= width) { ++ color_rest -= width; ++ color++; ++ } ++ } ++ quad0 += dquad_y; ++ dquad_y += 2; ++ p0 += picref->linesize[0]; ++ } ++ ++ /* draw sliding color line */ ++ p0 = p = data + picref->linesize[0] * height * 3/4; ++ grad = (256 * test->nb_frame * test->time_base.num / test->time_base.den) % ++ GRADIENT_SIZE; ++ rgrad = 0; ++ dgrad = GRADIENT_SIZE / width; ++ drgrad = GRADIENT_SIZE % width; ++ for (x = 0; x < width; x++) { ++ *(p++) = ++ grad < 256 || grad >= 5 * 256 ? 255 : ++ grad >= 2 * 256 && grad < 4 * 256 ? 0 : ++ grad < 2 * 256 ? 2 * 256 - 1 - grad : grad - 4 * 256; ++ *(p++) = ++ grad >= 4 * 256 ? 0 : ++ grad >= 1 * 256 && grad < 3 * 256 ? 255 : ++ grad < 1 * 256 ? grad : 4 * 256 - 1 - grad; ++ *(p++) = ++ grad < 2 * 256 ? 0 : ++ grad >= 3 * 256 && grad < 5 * 256 ? 255 : ++ grad < 3 * 256 ? grad - 2 * 256 : 6 * 256 - 1 - grad; ++ grad += dgrad; ++ rgrad += drgrad; ++ if (rgrad >= GRADIENT_SIZE) { ++ grad++; ++ rgrad -= GRADIENT_SIZE; ++ } ++ if (grad >= GRADIENT_SIZE) ++ grad -= GRADIENT_SIZE; ++ } ++ p = p0; ++ for (y = height / 8; y > 0; y--) { ++ memcpy(p+picref->linesize[0], p, 3 * width); ++ p += picref->linesize[0]; ++ } ++ ++ /* draw digits */ ++ seg_size = width / 80; ++ if (seg_size >= 1 && height >= 13 * seg_size) { ++ double time = av_q2d(test->time_base) * test->nb_frame * ++ pow(10, test->nb_decimals); ++ if (time > INT_MAX) ++ return; ++ second = (int)time; ++ x = width - (width - seg_size * 64) / 2; ++ y = (height - seg_size * 13) / 2; ++ p = data + (x*3 + y * picref->linesize[0]); ++ for (i = 0; i < 8; i++) { ++ p -= 3 * 8 * seg_size; ++ draw_digit(second % 10, p, picref->linesize[0], seg_size); ++ second /= 10; ++ if (second == 0) ++ break; ++ } ++ } ++} ++ ++static av_cold int test_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ TestSourceContext *test = ctx->priv; ++ ++ test->class = &testsrc_class; ++ test->fill_picture_fn = test_fill_picture; ++ return init(ctx, args, opaque); ++} ++ ++static int test_query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_RGB24, PIX_FMT_NONE ++ }; ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++AVFilter avfilter_vsrc_testsrc = { ++ .name = "testsrc", ++ .description = NULL_IF_CONFIG_SMALL("Generate test pattern."), ++ .priv_size = sizeof(TestSourceContext), ++ .init = test_init, ++ ++ .query_formats = test_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = config_props, }, ++ { .name = NULL }}, ++}; ++ ++#endif /* CONFIG_TESTSRC_FILTER */ ++ ++#if CONFIG_RGBTESTSRC_FILTER ++ ++static const char *rgbtestsrc_get_name(void *ctx) ++{ ++ return "rgbtestsrc"; ++} ++ ++static const AVClass rgbtestsrc_class = { ++ .class_name = "RGBTestSourceContext", ++ .item_name = rgbtestsrc_get_name, ++ .option = testsrc_options, ++}; ++ ++#define R 0 ++#define G 1 ++#define B 2 ++#define A 3 ++ ++static void rgbtest_put_pixel(uint8_t *dst, int dst_linesize, ++ int x, int y, int r, int g, int b, enum PixelFormat fmt, ++ int rgba_map[4]) ++{ ++ int32_t v; ++ uint8_t *p; ++ ++ switch (fmt) { ++ case PIX_FMT_BGR444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r >> 4) << 8) | ((g >> 4) << 4) | (b >> 4); break; ++ case PIX_FMT_RGB444: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b >> 4) << 8) | ((g >> 4) << 4) | (r >> 4); break; ++ case PIX_FMT_BGR555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<10) | ((g>>3)<<5) | (b>>3); break; ++ case PIX_FMT_RGB555: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<10) | ((g>>3)<<5) | (r>>3); break; ++ case PIX_FMT_BGR565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((r>>3)<<11) | ((g>>2)<<5) | (b>>3); break; ++ case PIX_FMT_RGB565: ((uint16_t*)(dst + y*dst_linesize))[x] = ((b>>3)<<11) | ((g>>2)<<5) | (r>>3); break; ++ case PIX_FMT_RGB24: ++ case PIX_FMT_BGR24: ++ v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)); ++ p = dst + 3*x + y*dst_linesize; ++ AV_WL24(p, v); ++ break; ++ case PIX_FMT_RGBA: ++ case PIX_FMT_BGRA: ++ case PIX_FMT_ARGB: ++ case PIX_FMT_ABGR: ++ v = (r << (rgba_map[R]*8)) + (g << (rgba_map[G]*8)) + (b << (rgba_map[B]*8)) + (255 << (rgba_map[A]*8)); ++ p = dst + 4*x + y*dst_linesize; ++ AV_WL32(p, v); ++ break; ++ } ++} ++ ++static void rgbtest_fill_picture(AVFilterContext *ctx, AVFilterBufferRef *picref) ++{ ++ TestSourceContext *test = ctx->priv; ++ int x, y, w = picref->video->w, h = picref->video->h; ++ ++ for (y = 0; y < h; y++) { ++ for (x = 0; x < picref->video->w; x++) { ++ int c = 256*x/w; ++ int r = 0, g = 0, b = 0; ++ ++ if (3*y < h ) r = c; ++ else if (3*y < 2*h) g = c; ++ else b = c; ++ ++ rgbtest_put_pixel(picref->data[0], picref->linesize[0], x, y, r, g, b, ++ ctx->outputs[0]->format, test->rgba_map); ++ } ++ } ++} ++ ++static av_cold int rgbtest_init(AVFilterContext *ctx, const char *args, void *opaque) ++{ ++ TestSourceContext *test = ctx->priv; ++ ++ test->class = &rgbtestsrc_class; ++ test->fill_picture_fn = rgbtest_fill_picture; ++ return init(ctx, args, opaque); ++} ++ ++static int rgbtest_query_formats(AVFilterContext *ctx) ++{ ++ static const enum PixelFormat pix_fmts[] = { ++ PIX_FMT_RGBA, PIX_FMT_ARGB, PIX_FMT_BGRA, PIX_FMT_ABGR, ++ PIX_FMT_BGR24, PIX_FMT_RGB24, ++ PIX_FMT_RGB444, PIX_FMT_BGR444, ++ PIX_FMT_RGB565, PIX_FMT_BGR565, ++ PIX_FMT_RGB555, PIX_FMT_BGR555, ++ PIX_FMT_NONE ++ }; ++ avfilter_set_common_pixel_formats(ctx, avfilter_make_format_list(pix_fmts)); ++ return 0; ++} ++ ++static int rgbtest_config_props(AVFilterLink *outlink) ++{ ++ TestSourceContext *test = outlink->src->priv; ++ ++ switch (outlink->format) { ++ case PIX_FMT_ARGB: test->rgba_map[A] = 0; test->rgba_map[R] = 1; test->rgba_map[G] = 2; test->rgba_map[B] = 3; break; ++ case PIX_FMT_ABGR: test->rgba_map[A] = 0; test->rgba_map[B] = 1; test->rgba_map[G] = 2; test->rgba_map[R] = 3; break; ++ case PIX_FMT_RGBA: ++ case PIX_FMT_RGB24: test->rgba_map[R] = 0; test->rgba_map[G] = 1; test->rgba_map[B] = 2; test->rgba_map[A] = 3; break; ++ case PIX_FMT_BGRA: ++ case PIX_FMT_BGR24: test->rgba_map[B] = 0; test->rgba_map[G] = 1; test->rgba_map[R] = 2; test->rgba_map[A] = 3; break; ++ } ++ ++ return config_props(outlink); ++} ++ ++AVFilter avfilter_vsrc_rgbtestsrc = { ++ .name = "rgbtestsrc", ++ .description = NULL_IF_CONFIG_SMALL("Generate RGB test pattern."), ++ .priv_size = sizeof(TestSourceContext), ++ .init = rgbtest_init, ++ ++ .query_formats = rgbtest_query_formats, ++ ++ .inputs = (const AVFilterPad[]) {{ .name = NULL}}, ++ ++ .outputs = (const AVFilterPad[]) {{ .name = "default", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .request_frame = request_frame, ++ .config_props = rgbtest_config_props, }, ++ { .name = NULL }}, ++}; ++ ++#endif /* CONFIG_RGBTESTSRC_FILTER */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/x86/gradfun.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/x86/gradfun.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/x86/gradfun.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/x86/gradfun.c 2012-05-14 14:08:54.851350387 +0200 +@@ -1,19 +1,21 @@ + /* ++ * Copyright (C) 2009 Loren Merritt ++ * + * This file is part of FFmpeg. + * +- * FFmpeg 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. ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg 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. ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * Lesser General Public License for more details. + * +- * You should have received a copy of the GNU General Public License along +- * with FFmpeg; if not, write to the Free Software Foundation, Inc., +- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + + #include "libavutil/cpu.h" +@@ -23,7 +25,7 @@ + DECLARE_ALIGNED(16, static const uint16_t, pw_7f)[8] = {0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F}; + DECLARE_ALIGNED(16, static const uint16_t, pw_ff)[8] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}; + +-void ff_gradfun_filter_line_mmx2(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) ++void ff_gradfun_filter_line_mmx2(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) + { + #if HAVE_MMX + intptr_t x; +@@ -71,7 +73,7 @@ + #endif + } + +-void ff_gradfun_filter_line_ssse3(uint8_t *dst, uint8_t *src, uint16_t *dc, int width, int thresh, const uint16_t *dithers) ++void ff_gradfun_filter_line_ssse3(uint8_t *dst, const uint8_t *src, const uint16_t *dc, int width, int thresh, const uint16_t *dithers) + { + #if HAVE_SSSE3 + intptr_t x; +@@ -118,7 +120,7 @@ + #endif // HAVE_SSSE3 + } + +-void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, uint16_t *buf1, uint8_t *src, int src_linesize, int width) ++void ff_gradfun_blur_line_sse2(uint16_t *dc, uint16_t *buf, const uint16_t *buf1, const uint8_t *src, int src_linesize, int width) + { + #if HAVE_SSE + #define BLURV(load)\ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/x86/yadif_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/x86/yadif_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavfilter/x86/yadif_template.c 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavfilter/x86/yadif_template.c 2012-05-14 14:08:54.852350408 +0200 +@@ -107,10 +107,8 @@ + uint8_t *prev, uint8_t *cur, uint8_t *next, + int w, int prefs, int mrefs, int parity, int mode) + { +- DECLARE_ALIGNED(16, uint8_t, tmp0[16]); +- DECLARE_ALIGNED(16, uint8_t, tmp1[16]); +- DECLARE_ALIGNED(16, uint8_t, tmp2[16]); +- DECLARE_ALIGNED(16, uint8_t, tmp3[16]); ++ uint8_t tmp[5*16]; ++ uint8_t *tmpA= (uint8_t*)(((uint64_t)(tmp+15)) & ~15); + int x; + + #define FILTER\ +@@ -124,9 +122,9 @@ + MOVQ" "MM"3, "MM"4 \n\t"\ + "paddw "MM"2, "MM"3 \n\t"\ + "psraw $1, "MM"3 \n\t" /* d = (prev2[x] + next2[x])>>1 */\ +- MOVQ" "MM"0, %[tmp0] \n\t" /* c */\ +- MOVQ" "MM"3, %[tmp1] \n\t" /* d */\ +- MOVQ" "MM"1, %[tmp2] \n\t" /* e */\ ++ MOVQ" "MM"0, (%[tmpA]) \n\t" /* c */\ ++ MOVQ" "MM"3, 16(%[tmpA]) \n\t" /* d */\ ++ MOVQ" "MM"1, 32(%[tmpA]) \n\t" /* e */\ + "psubw "MM"4, "MM"2 \n\t"\ + PABS( MM"4", MM"2") /* temporal_diff0 */\ + LOAD("(%[prev],%[mrefs])", MM"3") /* prev[x-refs] */\ +@@ -148,7 +146,7 @@ + "paddw "MM"4, "MM"3 \n\t" /* temporal_diff2 */\ + "psrlw $1, "MM"3 \n\t"\ + "pmaxsw "MM"3, "MM"2 \n\t"\ +- MOVQ" "MM"2, %[tmp3] \n\t" /* diff */\ ++ MOVQ" "MM"2, 48(%[tmpA]) \n\t" /* diff */\ + \ + "paddw "MM"0, "MM"1 \n\t"\ + "paddw "MM"0, "MM"0 \n\t"\ +@@ -179,7 +177,7 @@ + CHECK2\ + \ + /* if(p->mode<2) ... */\ +- MOVQ" %[tmp3], "MM"6 \n\t" /* diff */\ ++ MOVQ" 48(%[tmpA]), "MM"6 \n\t" /* diff */\ + "cmpl $2, %[mode] \n\t"\ + "jge 1f \n\t"\ + LOAD("(%["prev2"],%[mrefs],2)", MM"2") /* prev2[x-2*refs] */\ +@@ -190,9 +188,9 @@ + "paddw "MM"5, "MM"3 \n\t"\ + "psrlw $1, "MM"2 \n\t" /* b */\ + "psrlw $1, "MM"3 \n\t" /* f */\ +- MOVQ" %[tmp0], "MM"4 \n\t" /* c */\ +- MOVQ" %[tmp1], "MM"5 \n\t" /* d */\ +- MOVQ" %[tmp2], "MM"7 \n\t" /* e */\ ++ MOVQ" (%[tmpA]), "MM"4 \n\t" /* c */\ ++ MOVQ" 16(%[tmpA]), "MM"5 \n\t" /* d */\ ++ MOVQ" 32(%[tmpA]), "MM"7 \n\t" /* e */\ + "psubw "MM"4, "MM"2 \n\t" /* b-c */\ + "psubw "MM"7, "MM"3 \n\t" /* f-e */\ + MOVQ" "MM"5, "MM"0 \n\t"\ +@@ -211,7 +209,7 @@ + "pmaxsw "MM"4, "MM"6 \n\t" /* diff= MAX3(diff, min, -max); */\ + "1: \n\t"\ + \ +- MOVQ" %[tmp1], "MM"2 \n\t" /* d */\ ++ MOVQ" 16(%[tmpA]), "MM"2 \n\t" /* d */\ + MOVQ" "MM"2, "MM"3 \n\t"\ + "psubw "MM"6, "MM"2 \n\t" /* d-diff */\ + "paddw "MM"6, "MM"3 \n\t" /* d+diff */\ +@@ -219,11 +217,9 @@ + "pminsw "MM"3, "MM"1 \n\t" /* d = clip(spatial_pred, d-diff, d+diff); */\ + "packuswb "MM"1, "MM"1 \n\t"\ + \ +- :[tmp0]"=m"(tmp0),\ +- [tmp1]"=m"(tmp1),\ +- [tmp2]"=m"(tmp2),\ +- [tmp3]"=m"(tmp3)\ +- :[prev] "r"(prev),\ ++ :\ ++ :[tmpA] "r"(tmpA),\ ++ [prev] "r"(prev),\ + [cur] "r"(cur),\ + [next] "r"(next),\ + [prefs]"r"((x86_reg)prefs),\ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/4xm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/4xm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/4xm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/4xm.c 2012-05-14 14:08:54.854350448 +0200 +@@ -28,7 +28,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + + #define RIFF_TAG MKTAG('R', 'I', 'F', 'F') + #define FOURXMV_TAG MKTAG('4', 'X', 'M', 'V') +@@ -54,11 +56,11 @@ + #define strk_SIZE 0x28 + + #define GET_LIST_HEADER() \ +- fourcc_tag = get_le32(pb); \ +- size = get_le32(pb); \ ++ fourcc_tag = avio_rl32(pb); \ ++ size = avio_rl32(pb); \ + if (fourcc_tag != LIST_TAG) \ + return AVERROR_INVALIDDATA; \ +- fourcc_tag = get_le32(pb); ++ fourcc_tag = avio_rl32(pb); + + typedef struct AudioTrack { + int sample_rate; +@@ -92,7 +94,7 @@ + static int fourxm_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int fourcc_tag; + unsigned int size; + int header_size; +@@ -106,7 +108,7 @@ + fourxm->fps = 1.0; + + /* skip the first 3 32-bit numbers */ +- url_fseek(pb, 12, SEEK_CUR); ++ avio_skip(pb, 12); + + /* check for LIST-HEAD */ + GET_LIST_HEADER(); +@@ -118,7 +120,7 @@ + header = av_malloc(header_size); + if (!header) + return AVERROR(ENOMEM); +- if (get_buffer(pb, header, header_size) != header_size){ ++ if (avio_read(pb, header, header_size) != header_size){ + av_free(header); + return AVERROR(EIO); + } +@@ -129,7 +131,7 @@ + size = AV_RL32(&header[i + 4]); + + if (fourcc_tag == std__TAG) { +- fourxm->fps = av_int2flt(AV_RL32(&header[i + 12])); ++ fourxm->fps = av_int2float(AV_RL32(&header[i + 12])); + } else if (fourcc_tag == vtrk_TAG) { + /* check that there is enough data */ + if (size != vtrk_SIZE) { +@@ -140,12 +142,12 @@ + fourxm->height = AV_RL32(&header[i + 40]); + + /* allocate a new AVStream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st){ + ret= AVERROR(ENOMEM); + goto fail; + } +- av_set_pts_info(st, 60, 1, fourxm->fps); ++ avpriv_set_pts_info(st, 60, 1, fourxm->fps); + + fourxm->video_stream_index = st->index; + +@@ -172,13 +174,16 @@ + goto fail; + } + if (current_track + 1 > fourxm->track_count) { +- fourxm->track_count = current_track + 1; +- fourxm->tracks = av_realloc(fourxm->tracks, +- fourxm->track_count * sizeof(AudioTrack)); ++ fourxm->tracks = av_realloc_f(fourxm->tracks, ++ sizeof(AudioTrack), ++ current_track + 1); + if (!fourxm->tracks) { +- ret= AVERROR(ENOMEM); ++ ret = AVERROR(ENOMEM); + goto fail; + } ++ memset(&fourxm->tracks[fourxm->track_count], 0, ++ sizeof(AudioTrack) * (current_track + 1 - fourxm->track_count)); ++ fourxm->track_count = current_track + 1; + } + fourxm->tracks[current_track].adpcm = AV_RL32(&header[i + 12]); + fourxm->tracks[current_track].channels = AV_RL32(&header[i + 36]); +@@ -195,13 +200,14 @@ + i += 8 + size; + + /* allocate a new AVStream */ +- st = av_new_stream(s, current_track); ++ st = avformat_new_stream(s, NULL); + if (!st){ + ret= AVERROR(ENOMEM); + goto fail; + } + +- av_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate); ++ st->id = current_track; ++ avpriv_set_pts_info(st, 60, 1, fourxm->tracks[current_track].sample_rate); + + fourxm->tracks[current_track].stream_index = st->index; + +@@ -244,9 +250,9 @@ + AVPacket *pkt) + { + FourxmDemuxContext *fourxm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int fourcc_tag; +- unsigned int size, out_size; ++ unsigned int size; + int ret = 0; + unsigned int track_number; + int packet_read = 0; +@@ -255,7 +261,7 @@ + + while (!packet_read) { + +- if ((ret = get_buffer(s->pb, header, 8)) < 0) ++ if ((ret = avio_read(s->pb, header, 8)) < 0) + return ret; + fourcc_tag = AV_RL32(&header[0]); + size = AV_RL32(&header[4]); +@@ -268,7 +274,7 @@ + fourxm->video_pts ++; + + /* skip the LIST-* tag and move on to the next fourcc */ +- get_le32(pb); ++ avio_rl32(pb); + break; + + case ifrm_TAG: +@@ -283,9 +289,9 @@ + return AVERROR(EIO); + pkt->stream_index = fourxm->video_stream_index; + pkt->pts = fourxm->video_pts; +- pkt->pos = url_ftell(s->pb); ++ pkt->pos = avio_tell(s->pb); + memcpy(pkt->data, header, 8); +- ret = get_buffer(s->pb, &pkt->data[8], size); ++ ret = avio_read(s->pb, &pkt->data[8], size); + + if (ret < 0){ + av_free_packet(pkt); +@@ -294,8 +300,8 @@ + break; + + case snd__TAG: +- track_number = get_le32(pb); +- out_size= get_le32(pb); ++ track_number = avio_rl32(pb); ++ avio_skip(pb, 4); + size-=8; + + if (track_number < fourxm->track_count && fourxm->tracks[track_number].channels>0) { +@@ -322,12 +328,12 @@ + fourxm->tracks[track_number].audio_pts += audio_frame_count; + + } else { +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + } + break; + + default: +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + break; + } + } +@@ -344,11 +350,11 @@ + } + + AVInputFormat ff_fourxm_demuxer = { +- "4xm", +- NULL_IF_CONFIG_SMALL("4X Technologies format"), +- sizeof(FourxmDemuxContext), +- fourxm_probe, +- fourxm_read_header, +- fourxm_read_packet, +- fourxm_read_close, ++ .name = "4xm", ++ .long_name = NULL_IF_CONFIG_SMALL("4X Technologies format"), ++ .priv_data_size = sizeof(FourxmDemuxContext), ++ .read_probe = fourxm_probe, ++ .read_header = fourxm_read_header, ++ .read_packet = fourxm_read_packet, ++ .read_close = fourxm_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/a64.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/a64.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/a64.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/a64.c 2012-05-14 14:08:54.857350508 +0200 +@@ -55,9 +55,8 @@ + break; + default: + return AVERROR(EINVAL); +- break; + } +- put_buffer(s->pb, header, 2); ++ avio_write(s->pb, header, 2); + c->prev_pkt.size = 0; + c->prev_frame_count = 0; + return 0; +@@ -110,18 +109,18 @@ + for(i = 0; i < num_frames; i++) { + if(pkt->data) { + /* if available, put newest charset chunk into buffer */ +- put_buffer(s->pb, pkt->data + ch_chunksize * i, ch_chunksize); ++ avio_write(s->pb, pkt->data + ch_chunksize * i, ch_chunksize); + } else { + /* a bit ugly, but is there an alternative to put many zeros? */ +- for(j = 0; j < ch_chunksize; j++) put_byte(s->pb, 0); ++ for(j = 0; j < ch_chunksize; j++) avio_w8(s->pb, 0); + } + + if(c->prev_pkt.data) { + /* put frame (screen + colram) from last packet into buffer */ +- put_buffer(s->pb, c->prev_pkt.data + charset_size + frame_size * i, frame_size); ++ avio_write(s->pb, c->prev_pkt.data + charset_size + frame_size * i, frame_size); + } else { + /* a bit ugly, but is there an alternative to put many zeros? */ +- for(j = 0; j < frame_size; j++) put_byte(s->pb, 0); ++ for(j = 0; j < frame_size; j++) avio_w8(s->pb, 0); + } + } + +@@ -145,11 +144,11 @@ + default: + /* Write things as is. Nice for self-contained frames from non-multicolor modes or if played + * directly from ram and not from a streaming device (rrnet/mmc) */ +- if(pkt) put_buffer(s->pb, pkt->data, pkt->size); ++ if(pkt) avio_write(s->pb, pkt->data, pkt->size); + break; + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + +@@ -167,11 +166,10 @@ + AVOutputFormat ff_a64_muxer = { + .name = "a64", + .long_name = NULL_IF_CONFIG_SMALL("a64 - video for Commodore 64"), +- .mime_type = NULL, + .extensions = "a64, A64", + .priv_data_size = sizeof (A64Context), + .video_codec = CODEC_ID_A64_MULTI, +- a64_write_header, +- a64_write_packet, +- a64_write_trailer ++ .write_header = a64_write_header, ++ .write_packet = a64_write_packet, ++ .write_trailer = a64_write_trailer + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aacdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aacdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aacdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aacdec.c 2012-05-14 14:08:54.857350508 +0200 +@@ -22,6 +22,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "rawdec.h" + #include "id3v1.h" + +@@ -44,9 +45,10 @@ + uint32_t header = AV_RB16(buf2); + if((header&0xFFF6) != 0xFFF0) + break; +- fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF; ++ fsize = (AV_RB32(buf2 + 3) >> 13) & 0x1FFF; + if(fsize < 7) + break; ++ fsize = FFMIN(fsize, end - buf2); + buf2 += fsize; + } + max_frames = FFMAX(max_frames, frames); +@@ -65,7 +67,7 @@ + { + AVStream *st; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -76,18 +78,17 @@ + ff_id3v1_read(s); + + //LCM of all possible ADTS sample rates +- av_set_pts_info(st, 64, 1, 28224000); ++ avpriv_set_pts_info(st, 64, 1, 28224000); + + return 0; + } + + AVInputFormat ff_aac_demuxer = { +- "aac", +- NULL_IF_CONFIG_SMALL("raw ADTS AAC"), +- 0, +- adts_aac_probe, +- adts_aac_read_header, +- ff_raw_read_partial_packet, ++ .name = "aac", ++ .long_name = NULL_IF_CONFIG_SMALL("raw ADTS AAC"), ++ .read_probe = adts_aac_probe, ++ .read_header = adts_aac_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "aac", + .value = CODEC_ID_AAC, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ac3dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ac3dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ac3dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ac3dec.c 2012-05-14 14:08:54.858350528 +0200 +@@ -40,8 +40,10 @@ + buf2 = buf; + + for(frames = 0; buf2 < end; frames++) { ++ if(!memcmp(buf2, "\x1\x10\0\0\0\0\0\0", 8)) ++ buf2+=16; + init_get_bits(&gbc, buf2, 54); +- if(ff_ac3_parse_header(&gbc, &hdr) < 0) ++ if(avpriv_ac3_parse_header(&gbc, &hdr) < 0) + break; + if(buf2 + hdr.frame_size > end || + av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0, buf2 + 2, hdr.frame_size - 2)) +@@ -58,7 +60,7 @@ + // keep this in sync with mp3 probe, both need to avoid + // issues with MPEG-files! + if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; +- else if(max_frames>500)return AVPROBE_SCORE_MAX/2; ++ else if(max_frames>200)return AVPROBE_SCORE_MAX/2; + else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; + else if(max_frames>=1) return 1; + else return 0; +@@ -71,12 +73,11 @@ + } + + AVInputFormat ff_ac3_demuxer = { +- "ac3", +- NULL_IF_CONFIG_SMALL("raw AC-3"), +- 0, +- ac3_probe, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++ .name = "ac3", ++ .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"), ++ .read_probe = ac3_probe, ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "ac3", + .value = CODEC_ID_AC3, +@@ -90,12 +91,11 @@ + } + + AVInputFormat ff_eac3_demuxer = { +- "eac3", +- NULL_IF_CONFIG_SMALL("raw E-AC-3"), +- 0, +- eac3_probe, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++ .name = "eac3", ++ .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"), ++ .read_probe = eac3_probe, ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "eac3", + .value = CODEC_ID_EAC3, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/act.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/act.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/act.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/act.c 2012-05-14 14:08:54.859350548 +0200 +@@ -0,0 +1,208 @@ ++/* ++ * ACT file format demuxer ++ * Copyright (c) 2007-2008 Vladimir Voroshilov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++#include "avformat.h" ++#include "riff.h" ++#include "internal.h" ++#include "libavcodec/get_bits.h" ++ ++#define CHUNK_SIZE 512 ++#define RIFF_TAG MKTAG('R','I','F','F') ++#define WAVE_TAG MKTAG('W','A','V','E') ++ ++typedef struct{ ++ int bytes_left_in_chunk; ++ uint8_t audio_buffer[22];///< temporary buffer for ACT frame ++ char second_packet; ///< 1 - if temporary buffer contains valid (second) G.729 packet ++} ACTContext; ++ ++static int probe(AVProbeData *p) ++{ ++ int i; ++ ++ if ((AV_RL32(&p->buf[0]) != RIFF_TAG) || ++ (AV_RL32(&p->buf[8]) != WAVE_TAG) || ++ (AV_RL32(&p->buf[16]) != 16)) ++ return 0; ++ ++ //We cant be sure that this is ACT and not regular WAV ++ if (p->buf_size<512) ++ return 0; ++ ++ for(i=44; i<256; i++) ++ if(p->buf[i]) ++ return 0; ++ ++ if(p->buf[256]!=0x84) ++ return 0; ++ ++ for(i=264; i<512; i++) ++ if(p->buf[i]) ++ return 0; ++ ++ return AVPROBE_SCORE_MAX; ++} ++ ++static int read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ ACTContext* ctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int size; ++ AVStream* st; ++ ++ int min,sec,msec; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ avio_skip(pb, 16); ++ size=avio_rl32(pb); ++ ff_get_wav_header(pb, st->codec, size); ++ ++ /* ++ 8000Hz (Fine-rec) file format has 10 bytes long ++ packets with 10ms of sound data in them ++ */ ++ if (st->codec->sample_rate != 8000) { ++ av_log(s, AV_LOG_ERROR, "Sample rate %d is not supported.\n", st->codec->sample_rate); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ st->codec->frame_size=80; ++ st->codec->channels=1; ++ avpriv_set_pts_info(st, 64, 1, 100); ++ ++ st->codec->codec_id=CODEC_ID_G729; ++ ++ avio_seek(pb, 257, SEEK_SET); ++ msec=avio_rl16(pb); ++ sec=avio_r8(pb); ++ min=avio_rl32(pb); ++ ++ st->duration = av_rescale(1000*(min*60+sec)+msec, st->codec->sample_rate, 1000 * st->codec->frame_size); ++ ++ ctx->bytes_left_in_chunk=CHUNK_SIZE; ++ ++ avio_seek(pb, 512, SEEK_SET); ++ ++ return 0; ++} ++ ++ ++static int read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ ACTContext *ctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int ret; ++ int frame_size=s->streams[0]->codec->sample_rate==8000?10:22; ++ ++ ++ if(s->streams[0]->codec->sample_rate==8000) ++ ret=av_new_packet(pkt, 10); ++ else ++ ret=av_new_packet(pkt, 11); ++ ++ if(ret) ++ return ret; ++ ++ if(s->streams[0]->codec->sample_rate==4400 && !ctx->second_packet) ++ { ++ ret = avio_read(pb, ctx->audio_buffer, frame_size); ++ ++ if(ret<0) ++ return ret; ++ if(ret!=frame_size) ++ return AVERROR(EIO); ++ ++ pkt->data[0]=ctx->audio_buffer[11]; ++ pkt->data[1]=ctx->audio_buffer[0]; ++ pkt->data[2]=ctx->audio_buffer[12]; ++ pkt->data[3]=ctx->audio_buffer[1]; ++ pkt->data[4]=ctx->audio_buffer[13]; ++ pkt->data[5]=ctx->audio_buffer[2]; ++ pkt->data[6]=ctx->audio_buffer[14]; ++ pkt->data[7]=ctx->audio_buffer[3]; ++ pkt->data[8]=ctx->audio_buffer[15]; ++ pkt->data[9]=ctx->audio_buffer[4]; ++ pkt->data[10]=ctx->audio_buffer[16]; ++ ++ ctx->second_packet=1; ++ } ++ else if(s->streams[0]->codec->sample_rate==4400 && ctx->second_packet) ++ { ++ pkt->data[0]=ctx->audio_buffer[5]; ++ pkt->data[1]=ctx->audio_buffer[17]; ++ pkt->data[2]=ctx->audio_buffer[6]; ++ pkt->data[3]=ctx->audio_buffer[18]; ++ pkt->data[4]=ctx->audio_buffer[7]; ++ pkt->data[5]=ctx->audio_buffer[19]; ++ pkt->data[6]=ctx->audio_buffer[8]; ++ pkt->data[7]=ctx->audio_buffer[20]; ++ pkt->data[8]=ctx->audio_buffer[9]; ++ pkt->data[9]=ctx->audio_buffer[21]; ++ pkt->data[10]=ctx->audio_buffer[10]; ++ ++ ctx->second_packet=0; ++ } ++ else // 8000 Hz ++ { ++ ret = avio_read(pb, ctx->audio_buffer, frame_size); ++ ++ if(ret<0) ++ return ret; ++ if(ret!=frame_size) ++ return AVERROR(EIO); ++ ++ pkt->data[0]=ctx->audio_buffer[5]; ++ pkt->data[1]=ctx->audio_buffer[0]; ++ pkt->data[2]=ctx->audio_buffer[6]; ++ pkt->data[3]=ctx->audio_buffer[1]; ++ pkt->data[4]=ctx->audio_buffer[7]; ++ pkt->data[5]=ctx->audio_buffer[2]; ++ pkt->data[6]=ctx->audio_buffer[8]; ++ pkt->data[7]=ctx->audio_buffer[3]; ++ pkt->data[8]=ctx->audio_buffer[9]; ++ pkt->data[9]=ctx->audio_buffer[4]; ++ } ++ ++ ctx->bytes_left_in_chunk -= frame_size; ++ ++ if(ctx->bytes_left_in_chunk < frame_size) ++ { ++ avio_skip(pb, ctx->bytes_left_in_chunk); ++ ctx->bytes_left_in_chunk=CHUNK_SIZE; ++ } ++ ++ pkt->duration=1; ++ ++ return ret; ++} ++ ++AVInputFormat ff_act_demuxer = { ++ .name = "act", ++ .long_name = "ACT Voice file format", ++ .priv_data_size = sizeof(ACTContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/adtsenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/adtsenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/adtsenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/adtsenc.c 2012-05-14 14:08:54.860350568 +0200 +@@ -27,6 +27,8 @@ + #include "avformat.h" + #include "adts.h" + ++#define ADTS_MAX_FRAME_BYTES ((1 << 13) - 1) ++ + int ff_adts_decode_extradata(AVFormatContext *s, ADTSContext *adts, uint8_t *buf, int size) + { + GetBitContext gb; +@@ -35,7 +37,7 @@ + int off; + + init_get_bits(&gb, buf, size * 8); +- off = ff_mpeg4audio_get_config(&m4ac, buf, size); ++ off = avpriv_mpeg4audio_get_config(&m4ac, buf, size * 8, 1); + if (off < 0) + return off; + skip_bits_long(&gb, off); +@@ -59,11 +61,15 @@ + av_log(s, AV_LOG_ERROR, "Scalable configurations are not allowed in ADTS\n"); + return -1; + } ++ if (get_bits(&gb, 1)) { ++ av_log(s, AV_LOG_ERROR, "Extension flag is not allowed in ADTS\n"); ++ return -1; ++ } + if (!adts->channel_conf) { + init_put_bits(&pb, adts->pce_data, MAX_PCE_SIZE); + + put_bits(&pb, 3, 5); //ID_PCE +- adts->pce_size = (ff_copy_pce_data(&pb, &gb) + 3) / 8; ++ adts->pce_size = (avpriv_copy_pce_data(&pb, &gb) + 3) / 8; + flush_put_bits(&pb); + } + +@@ -89,6 +95,13 @@ + { + PutBitContext pb; + ++ unsigned full_frame_size = (unsigned)ADTS_HEADER_SIZE + size + pce_size; ++ if (full_frame_size > ADTS_MAX_FRAME_BYTES) { ++ av_log(NULL, AV_LOG_ERROR, "ADTS frame size too large: %u (max %d)\n", ++ full_frame_size, ADTS_MAX_FRAME_BYTES); ++ return AVERROR_INVALIDDATA; ++ } ++ + init_put_bits(&pb, buf, ADTS_HEADER_SIZE); + + /* adts_fixed_header */ +@@ -106,7 +119,7 @@ + /* adts_variable_header */ + put_bits(&pb, 1, 0); /* copyright_identification_bit */ + put_bits(&pb, 1, 0); /* copyright_identification_start */ +- put_bits(&pb, 13, ADTS_HEADER_SIZE + size + pce_size); /* aac_frame_length */ ++ put_bits(&pb, 13, full_frame_size); /* aac_frame_length */ + put_bits(&pb, 11, 0x7ff); /* adts_buffer_fullness */ + put_bits(&pb, 2, 0); /* number_of_raw_data_blocks_in_frame */ + +@@ -118,33 +131,36 @@ + static int adts_write_packet(AVFormatContext *s, AVPacket *pkt) + { + ADTSContext *adts = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t buf[ADTS_HEADER_SIZE]; + + if (!pkt->size) + return 0; + if (adts->write_adts) { +- ff_adts_write_frame_header(adts, buf, pkt->size, adts->pce_size); +- put_buffer(pb, buf, ADTS_HEADER_SIZE); ++ int err = ff_adts_write_frame_header(adts, buf, pkt->size, ++ adts->pce_size); ++ if (err < 0) ++ return err; ++ avio_write(pb, buf, ADTS_HEADER_SIZE); + if (adts->pce_size) { +- put_buffer(pb, adts->pce_data, adts->pce_size); ++ avio_write(pb, adts->pce_data, adts->pce_size); + adts->pce_size = 0; + } + } +- put_buffer(pb, pkt->data, pkt->size); +- put_flush_packet(pb); ++ avio_write(pb, pkt->data, pkt->size); ++ avio_flush(pb); + + return 0; + } + + AVOutputFormat ff_adts_muxer = { +- "adts", +- NULL_IF_CONFIG_SMALL("ADTS AAC"), +- "audio/aac", +- "aac,adts", +- sizeof(ADTSContext), +- CODEC_ID_AAC, +- CODEC_ID_NONE, +- adts_write_header, +- adts_write_packet, ++ .name = "adts", ++ .long_name = NULL_IF_CONFIG_SMALL("ADTS AAC"), ++ .mime_type = "audio/aac", ++ .extensions = "aac,adts", ++ .priv_data_size = sizeof(ADTSContext), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = adts_write_header, ++ .write_packet = adts_write_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/adxdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/adxdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/adxdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/adxdec.c 2012-05-14 14:08:54.860350568 +0200 +@@ -0,0 +1,113 @@ ++/* ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * CRI ADX demuxer ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavcodec/adx.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define BLOCK_SIZE 18 ++#define BLOCK_SAMPLES 32 ++ ++typedef struct ADXDemuxerContext { ++ int header_size; ++} ADXDemuxerContext; ++ ++static int adx_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ ADXDemuxerContext *c = s->priv_data; ++ AVCodecContext *avctx = s->streams[0]->codec; ++ int ret, size; ++ ++ size = BLOCK_SIZE * avctx->channels; ++ ++ pkt->pos = avio_tell(s->pb); ++ pkt->stream_index = 0; ++ ++ ret = av_get_packet(s->pb, pkt, size); ++ if (ret != size) { ++ av_free_packet(pkt); ++ return ret < 0 ? ret : AVERROR(EIO); ++ } ++ if (AV_RB16(pkt->data) & 0x8000) { ++ av_free_packet(pkt); ++ return AVERROR_EOF; ++ } ++ pkt->size = size; ++ pkt->duration = 1; ++ pkt->pts = (pkt->pos - c->header_size) / size; ++ ++ return 0; ++} ++ ++static int adx_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ ADXDemuxerContext *c = s->priv_data; ++ AVCodecContext *avctx; ++ int ret; ++ ++ AVStream *st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ avctx = s->streams[0]->codec; ++ ++ if (avio_rb16(s->pb) != 0x8000) ++ return AVERROR_INVALIDDATA; ++ c->header_size = avio_rb16(s->pb) + 4; ++ avio_seek(s->pb, -4, SEEK_CUR); ++ ++ avctx->extradata = av_mallocz(c->header_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!avctx->extradata) ++ return AVERROR(ENOMEM); ++ if (avio_read(s->pb, avctx->extradata, c->header_size) < c->header_size) { ++ av_freep(&avctx->extradata); ++ return AVERROR(EIO); ++ } ++ avctx->extradata_size = c->header_size; ++ ++ ret = avpriv_adx_decode_header(avctx, avctx->extradata, ++ avctx->extradata_size, &c->header_size, ++ NULL); ++ if (ret) ++ return ret; ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = s->iformat->value; ++ ++ avpriv_set_pts_info(st, 64, BLOCK_SAMPLES, avctx->sample_rate); ++ ++ return 0; ++} ++ ++AVInputFormat ff_adx_demuxer = { ++ .name = "adx", ++ .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"), ++ .priv_data_size = sizeof(ADXDemuxerContext), ++ .read_header = adx_read_header, ++ .read_packet = adx_read_packet, ++ .extensions = "adx", ++ .value = CODEC_ID_ADPCM_ADX, ++ .flags = AVFMT_GENERIC_INDEX, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aea.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aea.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aea.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aea.c 2012-05-14 14:08:54.861350588 +0200 +@@ -23,6 +23,7 @@ + #include "avformat.h" + #include "pcm.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/audioconvert.h" + + #define AT1_SU_SIZE 212 + +@@ -56,14 +57,14 @@ + static int aea_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + /* Parse the amount of channels and skip to pos 2048(0x800) */ +- url_fskip(s->pb, 264); +- st->codec->channels = get_byte(s->pb); +- url_fskip(s->pb, 1783); ++ avio_skip(s->pb, 264); ++ st->codec->channels = avio_r8(s->pb); ++ avio_skip(s->pb, 1783); + + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -76,7 +77,7 @@ + return -1; + } + +- st->codec->channel_layout = (st->codec->channels == 1) ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO; ++ st->codec->channel_layout = (st->codec->channels == 1) ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; + + st->codec->block_align = AT1_SU_SIZE * st->codec->channels; + return 0; +@@ -94,14 +95,12 @@ + } + + AVInputFormat ff_aea_demuxer = { +- "aea", +- NULL_IF_CONFIG_SMALL("MD STUDIO audio"), +- 0, +- aea_read_probe, +- aea_read_header, +- aea_read_packet, +- 0, +- pcm_read_seek, ++ .name = "aea", ++ .long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"), ++ .read_probe = aea_read_probe, ++ .read_header = aea_read_header, ++ .read_packet = aea_read_packet, ++ .read_seek = pcm_read_seek, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "aea", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiffdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiffdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiffdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiffdec.c 2012-05-14 14:08:54.863350628 +0200 +@@ -19,10 +19,13 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavutil/intfloat_readwrite.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + #include "pcm.h" + #include "aiff.h" ++#include "isom.h" + + #define AIFF 0 + #define AIFF_C_VERSION1 0xA2805140 +@@ -47,15 +50,15 @@ + } + + /* returns the size of the found tag */ +-static int get_tag(ByteIOContext *pb, uint32_t * tag) ++static int get_tag(AVIOContext *pb, uint32_t * tag) + { + int size; + + if (url_feof(pb)) + return AVERROR(EIO); + +- *tag = get_le32(pb); +- size = get_be32(pb); ++ *tag = avio_rl32(pb); ++ size = avio_rb32(pb); + + if (size < 0) + size = 0x7fffffff; +@@ -67,44 +70,47 @@ + static void get_meta(AVFormatContext *s, const char *key, int size) + { + uint8_t *str = av_malloc(size+1); +- int res; + +- if (!str) { +- url_fskip(s->pb, size); +- return; +- } +- +- res = get_buffer(s->pb, str, size); +- if (res < 0) +- return; ++ if (str) { ++ int res = avio_read(s->pb, str, size); ++ if (res < 0){ ++ av_free(str); ++ return; ++ } ++ size += (size&1)-res; ++ str[res] = 0; ++ av_dict_set(&s->metadata, key, str, AV_METADATA_DONT_STRDUP_VAL); ++ }else ++ size+= size&1; + +- str[res] = 0; +- av_metadata_set2(&s->metadata, key, str, AV_METADATA_DONT_STRDUP_VAL); ++ avio_skip(s->pb, size); + } + + /* Returns the number of sound data frames or negative on error */ +-static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec, ++static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec, + int size, unsigned version) + { +- AVExtFloat ext; ++ int exp; ++ uint64_t val; + double sample_rate; + unsigned int num_frames; + + if (size & 1) + size++; + codec->codec_type = AVMEDIA_TYPE_AUDIO; +- codec->channels = get_be16(pb); +- num_frames = get_be32(pb); +- codec->bits_per_coded_sample = get_be16(pb); +- +- get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */ +- sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */ ++ codec->channels = avio_rb16(pb); ++ num_frames = avio_rb32(pb); ++ codec->bits_per_coded_sample = avio_rb16(pb); ++ ++ exp = avio_rb16(pb); ++ val = avio_rb64(pb); ++ sample_rate = ldexp(val, exp - 16383 - 63); + codec->sample_rate = sample_rate; + size -= 18; + + /* Got an AIFF-C? */ + if (version == AIFF_C_VERSION1) { +- codec->codec_tag = get_le32(pb); ++ codec->codec_tag = avio_rl32(pb); + codec->codec_id = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag); + + switch (codec->codec_id) { +@@ -152,7 +158,7 @@ + + /* Chunk is over */ + if (size) +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + + return num_frames; + } +@@ -177,7 +183,7 @@ + int64_t offset = 0; + uint32_t tag; + unsigned version = AIFF_C_VERSION1; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream * st; + AIFFInputContext *aiff = s->priv_data; + +@@ -187,7 +193,7 @@ + return AVERROR_INVALIDDATA; + + /* AIFF data type */ +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */ + version = AIFF; + else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */ +@@ -195,7 +201,7 @@ + + filesize -= 4; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -217,7 +223,7 @@ + goto got_sound; + break; + case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */ +- version = get_be32(pb); ++ version = avio_rb32(pb); + break; + case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */ + get_meta(s, "title" , size); +@@ -232,17 +238,17 @@ + get_meta(s, "comment" , size); + break; + case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */ +- aiff->data_end = url_ftell(pb) + size; +- offset = get_be32(pb); /* Offset of sound data */ +- get_be32(pb); /* BlockSize... don't care */ +- offset += url_ftell(pb); /* Compute absolute data offset */ ++ aiff->data_end = avio_tell(pb) + size; ++ offset = avio_rb32(pb); /* Offset of sound data */ ++ avio_rb32(pb); /* BlockSize... don't care */ ++ offset += avio_tell(pb); /* Compute absolute data offset */ + if (st->codec->block_align) /* Assume COMM already parsed */ + goto got_sound; +- if (url_is_streamed(pb)) { ++ if (!pb->seekable) { + av_log(s, AV_LOG_ERROR, "file is not seekable\n"); + return -1; + } +- url_fskip(pb, size - 8); ++ avio_skip(pb, size - 8); + break; + case MKTAG('w', 'a', 'v', 'e'): + if ((uint64_t)size > (1<<30)) +@@ -251,32 +257,34 @@ + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = size; +- get_buffer(pb, st->codec->extradata, size); ++ avio_read(pb, st->codec->extradata, size); ++ break; ++ case MKTAG('C','H','A','N'): ++ if (size < 12) ++ return AVERROR_INVALIDDATA; ++ ff_mov_read_chan(s, size, st->codec); + break; + default: /* Jump */ + if (size & 1) /* Always even aligned */ + size++; +- url_fskip (pb, size); ++ avio_skip(pb, size); + } + } + ++got_sound: + if (!st->codec->block_align) { +- av_log(s, AV_LOG_ERROR, "could not find COMM tag\n"); ++ av_log(s, AV_LOG_ERROR, "could not find COMM tag or invalid block_align value\n"); + return -1; + } + +-got_sound: + /* Now positioned, get the sound data start and end */ +- if (st->nb_frames) +- s->file_size = st->nb_frames * st->codec->block_align; +- +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->start_time = 0; + st->duration = st->codec->frame_size ? + st->nb_frames * st->codec->frame_size : st->nb_frames; + + /* Position the stream at the first block */ +- url_fseek(pb, offset, SEEK_SET); ++ avio_seek(pb, offset, SEEK_SET); + + return 0; + } +@@ -292,7 +300,7 @@ + int res, size; + + /* calculate size of remaining data */ +- max_size = aiff->data_end - url_ftell(s->pb); ++ max_size = aiff->data_end - avio_tell(s->pb); + if (max_size <= 0) + return AVERROR_EOF; + +@@ -312,13 +320,12 @@ + } + + AVInputFormat ff_aiff_demuxer = { +- "aiff", +- NULL_IF_CONFIG_SMALL("Audio IFF"), +- sizeof(AIFFInputContext), +- aiff_probe, +- aiff_read_header, +- aiff_read_packet, +- NULL, +- pcm_read_seek, ++ .name = "aiff", ++ .long_name = NULL_IF_CONFIG_SMALL("Audio IFF"), ++ .priv_data_size = sizeof(AIFFInputContext), ++ .read_probe = aiff_probe, ++ .read_header = aiff_read_header, ++ .read_packet = aiff_read_packet, ++ .read_seek = pcm_read_seek, + .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiffenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiffenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiffenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiffenc.c 2012-05-14 14:08:54.864350648 +0200 +@@ -19,8 +19,12 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + #include "aiff.h" ++#include "avio_internal.h" ++#include "isom.h" + + typedef struct { + int64_t form; +@@ -31,9 +35,9 @@ + static int aiff_write_header(AVFormatContext *s) + { + AIFFOutputContext *aiff = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; +- AVExtFloat sample_rate; ++ uint64_t sample_rate; + int aifc = 0; + + /* First verify if format is ok */ +@@ -43,10 +47,10 @@ + aifc = 1; + + /* FORM AIFF header */ +- put_tag(pb, "FORM"); +- aiff->form = url_ftell(pb); +- put_be32(pb, 0); /* file length */ +- put_tag(pb, aifc ? "AIFC" : "AIFF"); ++ ffio_wfourcc(pb, "FORM"); ++ aiff->form = avio_tell(pb); ++ avio_wb32(pb, 0); /* file length */ ++ ffio_wfourcc(pb, aifc ? "AIFC" : "AIFF"); + + if (aifc) { // compressed audio + enc->bits_per_coded_sample = 16; +@@ -55,18 +59,24 @@ + return -1; + } + /* Version chunk */ +- put_tag(pb, "FVER"); +- put_be32(pb, 4); +- put_be32(pb, 0xA2805140); ++ ffio_wfourcc(pb, "FVER"); ++ avio_wb32(pb, 4); ++ avio_wb32(pb, 0xA2805140); ++ } ++ ++ if (enc->channels > 2 && enc->channel_layout) { ++ ffio_wfourcc(pb, "CHAN"); ++ avio_wb32(pb, 12); ++ ff_mov_write_chan(pb, enc->channel_layout); + } + + /* Common chunk */ +- put_tag(pb, "COMM"); +- put_be32(pb, aifc ? 24 : 18); /* size */ +- put_be16(pb, enc->channels); /* Number of channels */ ++ ffio_wfourcc(pb, "COMM"); ++ avio_wb32(pb, aifc ? 24 : 18); /* size */ ++ avio_wb16(pb, enc->channels); /* Number of channels */ + +- aiff->frames = url_ftell(pb); +- put_be32(pb, 0); /* Number of frames */ ++ aiff->frames = avio_tell(pb); ++ avio_wb32(pb, 0); /* Number of frames */ + + if (!enc->bits_per_coded_sample) + enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id); +@@ -77,84 +87,85 @@ + if (!enc->block_align) + enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; + +- put_be16(pb, enc->bits_per_coded_sample); /* Sample size */ ++ avio_wb16(pb, enc->bits_per_coded_sample); /* Sample size */ + +- sample_rate = av_dbl2ext((double)enc->sample_rate); +- put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate)); ++ sample_rate = av_double2int(enc->sample_rate); ++ avio_wb16(pb, (sample_rate >> 52) + (16383 - 1023)); ++ avio_wb64(pb, UINT64_C(1) << 63 | sample_rate << 11); + + if (aifc) { +- put_le32(pb, enc->codec_tag); +- put_be16(pb, 0); ++ avio_wl32(pb, enc->codec_tag); ++ avio_wb16(pb, 0); + } + + /* Sound data chunk */ +- put_tag(pb, "SSND"); +- aiff->ssnd = url_ftell(pb); /* Sound chunk size */ +- put_be32(pb, 0); /* Sound samples data size */ +- put_be32(pb, 0); /* Data offset */ +- put_be32(pb, 0); /* Block-size (block align) */ ++ ffio_wfourcc(pb, "SSND"); ++ aiff->ssnd = avio_tell(pb); /* Sound chunk size */ ++ avio_wb32(pb, 0); /* Sound samples data size */ ++ avio_wb32(pb, 0); /* Data offset */ ++ avio_wb32(pb, 0); /* Block-size (block align) */ + +- av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); ++ avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + + /* Data is starting here */ +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; +- put_buffer(pb, pkt->data, pkt->size); ++ AVIOContext *pb = s->pb; ++ avio_write(pb, pkt->data, pkt->size); + return 0; + } + + static int aiff_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AIFFOutputContext *aiff = s->priv_data; + AVCodecContext *enc = s->streams[0]->codec; + + /* Chunks sizes must be even */ + int64_t file_size, end_size; +- end_size = file_size = url_ftell(pb); ++ end_size = file_size = avio_tell(pb); + if (file_size & 1) { +- put_byte(pb, 0); ++ avio_w8(pb, 0); + end_size++; + } + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + /* File length */ +- url_fseek(pb, aiff->form, SEEK_SET); +- put_be32(pb, file_size - aiff->form - 4); ++ avio_seek(pb, aiff->form, SEEK_SET); ++ avio_wb32(pb, file_size - aiff->form - 4); + + /* Number of sample frames */ +- url_fseek(pb, aiff->frames, SEEK_SET); +- put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align); ++ avio_seek(pb, aiff->frames, SEEK_SET); ++ avio_wb32(pb, (file_size-aiff->ssnd-12)/enc->block_align); + + /* Sound Data chunk size */ +- url_fseek(pb, aiff->ssnd, SEEK_SET); +- put_be32(pb, file_size - aiff->ssnd - 4); ++ avio_seek(pb, aiff->ssnd, SEEK_SET); ++ avio_wb32(pb, file_size - aiff->ssnd - 4); + + /* return to the end */ +- url_fseek(pb, end_size, SEEK_SET); ++ avio_seek(pb, end_size, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + } + + return 0; + } + + AVOutputFormat ff_aiff_muxer = { +- "aiff", +- NULL_IF_CONFIG_SMALL("Audio IFF"), +- "audio/aiff", +- "aif,aiff,afc,aifc", +- sizeof(AIFFOutputContext), +- CODEC_ID_PCM_S16BE, +- CODEC_ID_NONE, +- aiff_write_header, +- aiff_write_packet, +- aiff_write_trailer, ++ .name = "aiff", ++ .long_name = NULL_IF_CONFIG_SMALL("Audio IFF"), ++ .mime_type = "audio/aiff", ++ .extensions = "aif,aiff,afc,aifc", ++ .priv_data_size = sizeof(AIFFOutputContext), ++ .audio_codec = CODEC_ID_PCM_S16BE, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = aiff_write_header, ++ .write_packet = aiff_write_packet, ++ .write_trailer = aiff_write_trailer, + .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiff.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiff.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aiff.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aiff.h 2012-05-14 14:08:54.862350608 +0200 +@@ -43,6 +43,7 @@ + { CODEC_ID_MACE6, MKTAG('M','A','C','6') }, + { CODEC_ID_GSM, MKTAG('G','S','M',' ') }, + { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') }, ++ { CODEC_ID_PCM_S16BE, MKTAG('t','w','o','s') }, + { CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') }, + { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') }, + { CODEC_ID_QDM2, MKTAG('Q','D','M','2') }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/allformats.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/allformats.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/allformats.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/allformats.c 2012-05-14 14:08:54.866350688 +0200 +@@ -21,6 +21,7 @@ + #include "avformat.h" + #include "rtp.h" + #include "rdt.h" ++#include "url.h" + + #define REGISTER_MUXER(X,x) { \ + extern AVOutputFormat ff_##x##_muxer; \ +@@ -34,7 +35,7 @@ + + #define REGISTER_PROTOCOL(X,x) { \ + extern URLProtocol ff_##x##_protocol; \ +- if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } ++ if(CONFIG_##X##_PROTOCOL) ffurl_register_protocol(&ff_##x##_protocol, sizeof(ff_##x##_protocol)); } + + void av_register_all(void) + { +@@ -50,7 +51,10 @@ + REGISTER_MUXER (A64, a64); + REGISTER_DEMUXER (AAC, aac); + REGISTER_MUXDEMUX (AC3, ac3); ++ REGISTER_DEMUXER (ACT, act); ++ REGISTER_DEMUXER (ADF, adf); + REGISTER_MUXER (ADTS, adts); ++ REGISTER_MUXDEMUX (ADX, adx); + REGISTER_DEMUXER (AEA, aea); + REGISTER_MUXDEMUX (AIFF, aiff); + REGISTER_MUXDEMUX (AMR, amr); +@@ -68,13 +72,17 @@ + REGISTER_DEMUXER (AVS, avs); + REGISTER_DEMUXER (BETHSOFTVID, bethsoftvid); + REGISTER_DEMUXER (BFI, bfi); ++ REGISTER_DEMUXER (BINTEXT, bintext); + REGISTER_DEMUXER (BINK, bink); ++ REGISTER_MUXDEMUX (BIT, bit); ++ REGISTER_DEMUXER (BMV, bmv); + REGISTER_DEMUXER (C93, c93); +- REGISTER_DEMUXER (CAF, caf); ++ REGISTER_MUXDEMUX (CAF, caf); + REGISTER_MUXDEMUX (CAVSVIDEO, cavsvideo); + REGISTER_DEMUXER (CDG, cdg); + REGISTER_MUXER (CRC, crc); + REGISTER_MUXDEMUX (DAUD, daud); ++ REGISTER_DEMUXER (DFA, dfa); + REGISTER_MUXDEMUX (DIRAC, dirac); + REGISTER_MUXDEMUX (DNXHD, dnxhd); + REGISTER_DEMUXER (DSICIN, dsicin); +@@ -94,28 +102,37 @@ + REGISTER_MUXER (FRAMECRC, framecrc); + REGISTER_MUXER (FRAMEMD5, framemd5); + REGISTER_MUXDEMUX (G722, g722); ++ REGISTER_MUXDEMUX (G723_1, g723_1); ++ REGISTER_DEMUXER (G729, g729); + REGISTER_MUXER (GIF, gif); + REGISTER_DEMUXER (GSM, gsm); + REGISTER_MUXDEMUX (GXF, gxf); + REGISTER_MUXDEMUX (H261, h261); + REGISTER_MUXDEMUX (H263, h263); + REGISTER_MUXDEMUX (H264, h264); ++ REGISTER_DEMUXER (ICO, ico); + REGISTER_DEMUXER (IDCIN, idcin); ++ REGISTER_DEMUXER (IDF, idf); + REGISTER_DEMUXER (IFF, iff); + REGISTER_MUXDEMUX (IMAGE2, image2); + REGISTER_MUXDEMUX (IMAGE2PIPE, image2pipe); + REGISTER_DEMUXER (INGENIENT, ingenient); + REGISTER_DEMUXER (IPMOVIE, ipmovie); + REGISTER_MUXER (IPOD, ipod); ++ REGISTER_MUXER (ISMV, ismv); + REGISTER_DEMUXER (ISS, iss); + REGISTER_DEMUXER (IV8, iv8); + REGISTER_MUXDEMUX (IVF, ivf); ++ REGISTER_DEMUXER (JV, jv); ++ REGISTER_MUXDEMUX (LATM, latm); + REGISTER_DEMUXER (LMLM4, lmlm4); ++ REGISTER_DEMUXER (LOAS, loas); + REGISTER_DEMUXER (LXF, lxf); + REGISTER_MUXDEMUX (M4V, m4v); + REGISTER_MUXER (MD5, md5); + REGISTER_MUXDEMUX (MATROSKA, matroska); + REGISTER_MUXER (MATROSKA_AUDIO, matroska_audio); ++ REGISTER_MUXDEMUX (MICRODVD, microdvd); + REGISTER_MUXDEMUX (MJPEG, mjpeg); + REGISTER_MUXDEMUX (MLP, mlp); + REGISTER_DEMUXER (MM, mm); +@@ -150,7 +167,7 @@ + REGISTER_MUXDEMUX (NUT, nut); + REGISTER_DEMUXER (NUV, nuv); + REGISTER_MUXDEMUX (OGG, ogg); +- REGISTER_DEMUXER (OMA, oma); ++ REGISTER_MUXDEMUX (OMA, oma); + REGISTER_MUXDEMUX (PCM_ALAW, pcm_alaw); + REGISTER_MUXDEMUX (PCM_MULAW, pcm_mulaw); + REGISTER_MUXDEMUX (PCM_F64BE, pcm_f64be); +@@ -171,6 +188,7 @@ + REGISTER_MUXDEMUX (PCM_U16BE, pcm_u16be); + REGISTER_MUXDEMUX (PCM_U16LE, pcm_u16le); + REGISTER_MUXDEMUX (PCM_U8, pcm_u8); ++ REGISTER_DEMUXER (PMP, pmp); + REGISTER_MUXER (PSP, psp); + REGISTER_DEMUXER (PVA, pva); + REGISTER_DEMUXER (QCP, qcp); +@@ -184,15 +202,18 @@ + REGISTER_MUXDEMUX (RTP, rtp); + REGISTER_MUXDEMUX (RTSP, rtsp); + REGISTER_MUXDEMUX (SAP, sap); ++ REGISTER_DEMUXER (SBG, sbg); + REGISTER_DEMUXER (SDP, sdp); + #if CONFIG_RTPDEC + av_register_rtp_dynamic_payload_handlers(); + av_register_rdt_dynamic_payload_handlers(); + #endif + REGISTER_DEMUXER (SEGAFILM, segafilm); ++ REGISTER_MUXER (SEGMENT, segment); + REGISTER_DEMUXER (SHORTEN, shorten); + REGISTER_DEMUXER (SIFF, siff); + REGISTER_DEMUXER (SMACKER, smacker); ++ REGISTER_MUXDEMUX (SMJPEG, smjpeg); + REGISTER_DEMUXER (SOL, sol); + REGISTER_MUXDEMUX (SOX, sox); + REGISTER_MUXDEMUX (SPDIF, spdif); +@@ -203,6 +224,7 @@ + REGISTER_MUXER (TGP, tgp); + REGISTER_DEMUXER (THP, thp); + REGISTER_DEMUXER (TIERTEXSEQ, tiertexseq); ++ REGISTER_MUXER (MKVTIMESTAMP_V2, mkvtimestamp_v2); + REGISTER_DEMUXER (TMV, tmv); + REGISTER_MUXDEMUX (TRUEHD, truehd); + REGISTER_DEMUXER (TTA, tta); +@@ -219,20 +241,31 @@ + REGISTER_MUXER (WEBM, webm); + REGISTER_DEMUXER (WSAUD, wsaud); + REGISTER_DEMUXER (WSVQA, wsvqa); +- REGISTER_DEMUXER (WTV, wtv); ++ REGISTER_MUXDEMUX (WTV, wtv); + REGISTER_DEMUXER (WV, wv); + REGISTER_DEMUXER (XA, xa); ++ REGISTER_DEMUXER (XBIN, xbin); ++ REGISTER_DEMUXER (XMV, xmv); ++ REGISTER_DEMUXER (XWMA, xwma); + REGISTER_DEMUXER (YOP, yop); + REGISTER_MUXDEMUX (YUV4MPEGPIPE, yuv4mpegpipe); + + /* external libraries */ ++#if CONFIG_LIBMODPLUG ++ REGISTER_DEMUXER (LIBMODPLUG, libmodplug); ++#endif + REGISTER_MUXDEMUX (LIBNUT, libnut); + + /* protocols */ ++ REGISTER_PROTOCOL (APPLEHTTP, applehttp); ++ REGISTER_PROTOCOL (CACHE, cache); + REGISTER_PROTOCOL (CONCAT, concat); ++ REGISTER_PROTOCOL (CRYPTO, crypto); + REGISTER_PROTOCOL (FILE, file); + REGISTER_PROTOCOL (GOPHER, gopher); + REGISTER_PROTOCOL (HTTP, http); ++ REGISTER_PROTOCOL (HTTPPROXY, httpproxy); ++ REGISTER_PROTOCOL (HTTPS, https); + REGISTER_PROTOCOL (MMSH, mmsh); + REGISTER_PROTOCOL (MMST, mmst); + REGISTER_PROTOCOL (MD5, md5); +@@ -246,5 +279,6 @@ + #endif + REGISTER_PROTOCOL (RTP, rtp); + REGISTER_PROTOCOL (TCP, tcp); ++ REGISTER_PROTOCOL (TLS, tls); + REGISTER_PROTOCOL (UDP, udp); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/amr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/amr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/amr.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/amr.c 2012-05-14 14:08:54.866350688 +0200 +@@ -26,6 +26,7 @@ + + */ + #include "avformat.h" ++#include "internal.h" + + static const char AMR_header [] = "#!AMR\n"; + static const char AMRWB_header [] = "#!AMR-WB\n"; +@@ -33,31 +34,31 @@ + #if CONFIG_AMR_MUXER + static int amr_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; + + s->priv_data = NULL; + + if (enc->codec_id == CODEC_ID_AMR_NB) + { +- put_tag(pb, AMR_header); /* magic number */ ++ avio_write(pb, AMR_header, sizeof(AMR_header) - 1); /* magic number */ + } + else if(enc->codec_id == CODEC_ID_AMR_WB) + { +- put_tag(pb, AMRWB_header); /* magic number */ ++ avio_write(pb, AMRWB_header, sizeof(AMRWB_header) - 1); /* magic number */ + } + else + { + return -1; + } +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + + static int amr_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- put_buffer(s->pb, pkt->data, pkt->size); +- put_flush_packet(s->pb); ++ avio_write(s->pb, pkt->data, pkt->size); ++ avio_flush(s->pb); + return 0; + } + #endif /* CONFIG_AMR_MUXER */ +@@ -78,20 +79,20 @@ + static int amr_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + uint8_t header[9]; + +- get_buffer(pb, header, 6); ++ avio_read(pb, header, 6); + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + { + return AVERROR(ENOMEM); + } + if(memcmp(header,AMR_header,6)!=0) + { +- get_buffer(pb, header+6, 3); ++ avio_read(pb, header+6, 3); + if(memcmp(header,AMRWB_header,9)!=0) + { + return -1; +@@ -111,7 +112,7 @@ + } + st->codec->channels = 1; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; + } +@@ -121,6 +122,7 @@ + { + AVCodecContext *enc = s->streams[0]->codec; + int read, size = 0, toc, mode; ++ int64_t pos = avio_tell(s->pb); + + if (url_feof(s->pb)) + { +@@ -128,7 +130,7 @@ + } + + //FIXME this is wrong, this should rather be in a AVParset +- toc=get_byte(s->pb); ++ toc=avio_r8(s->pb); + mode = (toc >> 3) & 0x0F; + + if (enc->codec_id == CODEC_ID_AMR_NB) +@@ -153,11 +155,14 @@ + return AVERROR(EIO); + } + ++ /* Both AMR formats have 50 frames per second */ ++ s->streams[0]->codec->bit_rate = size*8*50; ++ + pkt->stream_index = 0; +- pkt->pos= url_ftell(s->pb); ++ pkt->pos = pos; + pkt->data[0]=toc; + pkt->duration= enc->codec_id == CODEC_ID_AMR_NB ? 160 : 320; +- read = get_buffer(s->pb, pkt->data+1, size-1); ++ read = avio_read(s->pb, pkt->data+1, size-1); + + if (read != size-1) + { +@@ -170,26 +175,24 @@ + + #if CONFIG_AMR_DEMUXER + AVInputFormat ff_amr_demuxer = { +- "amr", +- NULL_IF_CONFIG_SMALL("3GPP AMR file format"), +- 0, /*priv_data_size*/ +- amr_probe, +- amr_read_header, +- amr_read_packet, +- NULL, ++ .name = "amr", ++ .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR file format"), ++ .read_probe = amr_probe, ++ .read_header = amr_read_header, ++ .read_packet = amr_read_packet, ++ .flags = AVFMT_GENERIC_INDEX, + }; + #endif + + #if CONFIG_AMR_MUXER + AVOutputFormat ff_amr_muxer = { +- "amr", +- NULL_IF_CONFIG_SMALL("3GPP AMR file format"), +- "audio/amr", +- "amr", +- 0, +- CODEC_ID_AMR_NB, +- CODEC_ID_NONE, +- amr_write_header, +- amr_write_packet, ++ .name = "amr", ++ .long_name = NULL_IF_CONFIG_SMALL("3GPP AMR file format"), ++ .mime_type = "audio/amr", ++ .extensions = "amr", ++ .audio_codec = CODEC_ID_AMR_NB, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = amr_write_header, ++ .write_packet = amr_write_packet, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/anm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/anm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/anm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/anm.c 2012-05-14 14:08:54.867350709 +0200 +@@ -26,6 +26,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + typedef struct { + int base_record; +@@ -79,105 +80,98 @@ + AVFormatParameters *ap) + { + AnmDemuxContext *anm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + int i, ret; + +- url_fskip(pb, 4); /* magic number */ +- if (get_le16(pb) != MAX_PAGES) { ++ avio_skip(pb, 4); /* magic number */ ++ if (avio_rl16(pb) != MAX_PAGES) { + av_log_ask_for_sample(s, "max_pages != " AV_STRINGIFY(MAX_PAGES) "\n"); + return AVERROR_INVALIDDATA; + } + +- anm->nb_pages = get_le16(pb); +- anm->nb_records = get_le32(pb); +- url_fskip(pb, 2); /* max records per page */ +- anm->page_table_offset = get_le16(pb); +- if (get_le32(pb) != ANIM_TAG) ++ anm->nb_pages = avio_rl16(pb); ++ anm->nb_records = avio_rl32(pb); ++ avio_skip(pb, 2); /* max records per page */ ++ anm->page_table_offset = avio_rl16(pb); ++ if (avio_rl32(pb) != ANIM_TAG) + return AVERROR_INVALIDDATA; + + /* video stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ANM; + st->codec->codec_tag = 0; /* no fourcc */ +- st->codec->width = get_le16(pb); +- st->codec->height = get_le16(pb); +- if (get_byte(pb) != 0) ++ st->codec->width = avio_rl16(pb); ++ st->codec->height = avio_rl16(pb); ++ if (avio_r8(pb) != 0) + goto invalid; +- url_fskip(pb, 1); /* frame rate multiplier info */ ++ avio_skip(pb, 1); /* frame rate multiplier info */ + + /* ignore last delta record (used for looping) */ +- if (get_byte(pb)) /* has_last_delta */ ++ if (avio_r8(pb)) /* has_last_delta */ + anm->nb_records = FFMAX(anm->nb_records - 1, 0); + +- url_fskip(pb, 1); /* last_delta_valid */ ++ avio_skip(pb, 1); /* last_delta_valid */ + +- if (get_byte(pb) != 0) ++ if (avio_r8(pb) != 0) + goto invalid; + +- if (get_byte(pb) != 1) ++ if (avio_r8(pb) != 1) + goto invalid; + +- url_fskip(pb, 1); /* other recs per frame */ ++ avio_skip(pb, 1); /* other recs per frame */ + +- if (get_byte(pb) != 1) ++ if (avio_r8(pb) != 1) + goto invalid; + +- url_fskip(pb, 32); /* record_types */ +- st->nb_frames = get_le32(pb); +- av_set_pts_info(st, 64, 1, get_le16(pb)); +- url_fskip(pb, 58); ++ avio_skip(pb, 32); /* record_types */ ++ st->nb_frames = avio_rl32(pb); ++ avpriv_set_pts_info(st, 64, 1, avio_rl16(pb)); ++ avio_skip(pb, 58); + + /* color cycling and palette data */ + st->codec->extradata_size = 16*8 + 4*256; + st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!st->codec->extradata) { +- ret = AVERROR(ENOMEM); +- goto close_and_return; +- } +- ret = get_buffer(pb, st->codec->extradata, st->codec->extradata_size); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ ++ ret = avio_read(pb, st->codec->extradata, st->codec->extradata_size); + if (ret < 0) +- goto close_and_return; ++ return ret; + + /* read page table */ +- ret = url_fseek(pb, anm->page_table_offset, SEEK_SET); ++ ret = avio_seek(pb, anm->page_table_offset, SEEK_SET); + if (ret < 0) +- goto close_and_return; ++ return ret; + + for (i = 0; i < MAX_PAGES; i++) { + Page *p = &anm->pt[i]; +- p->base_record = get_le16(pb); +- p->nb_records = get_le16(pb); +- p->size = get_le16(pb); ++ p->base_record = avio_rl16(pb); ++ p->nb_records = avio_rl16(pb); ++ p->size = avio_rl16(pb); + } + + /* find page of first frame */ + anm->page = find_record(anm, 0); +- if (anm->page < 0) { +- ret = anm->page; +- goto close_and_return; +- } ++ if (anm->page < 0) ++ return anm->page; + + anm->record = -1; + return 0; + + invalid: + av_log_ask_for_sample(s, NULL); +- ret = AVERROR_INVALIDDATA; +- +-close_and_return: +- av_close_input_stream(s); +- return ret; ++ return AVERROR_INVALIDDATA; + } + + static int read_packet(AVFormatContext *s, + AVPacket *pkt) + { + AnmDemuxContext *anm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + Page *p; + int tmp, record_size; + +@@ -192,8 +186,8 @@ + + /* parse page header */ + if (anm->record < 0) { +- url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET); +- url_fskip(pb, 8 + 2*p->nb_records); ++ avio_seek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16), SEEK_SET); ++ avio_skip(pb, 8 + 2*p->nb_records); + anm->record = 0; + } + +@@ -208,11 +202,11 @@ + } + + /* fetch record size */ +- tmp = url_ftell(pb); +- url_fseek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) + ++ tmp = avio_tell(pb); ++ avio_seek(pb, anm->page_table_offset + MAX_PAGES*6 + (anm->page<<16) + + 8 + anm->record * 2, SEEK_SET); +- record_size = get_le16(pb); +- url_fseek(pb, tmp, SEEK_SET); ++ record_size = avio_rl16(pb); ++ avio_seek(pb, tmp, SEEK_SET); + + /* fetch record */ + pkt->size = av_get_packet(s->pb, pkt, record_size); +@@ -226,10 +220,10 @@ + } + + AVInputFormat ff_anm_demuxer = { +- "anm", +- NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"), +- sizeof(AnmDemuxContext), +- probe, +- read_header, +- read_packet, ++ .name = "anm", ++ .long_name = NULL_IF_CONFIG_SMALL("Deluxe Paint Animation"), ++ .priv_data_size = sizeof(AnmDemuxContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/apc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/apc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/apc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/apc.c 2012-05-14 14:08:54.868350730 +0200 +@@ -32,22 +32,22 @@ + + static int apc_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + +- get_le32(pb); /* CRYO */ +- get_le32(pb); /* _APC */ +- get_le32(pb); /* 1.20 */ ++ avio_rl32(pb); /* CRYO */ ++ avio_rl32(pb); /* _APC */ ++ avio_rl32(pb); /* 1.20 */ + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; ++ st->codec->codec_id = CODEC_ID_ADPCM_IMA_APC; + +- get_le32(pb); /* number of samples */ +- st->codec->sample_rate = get_le32(pb); ++ avio_rl32(pb); /* number of samples */ ++ st->codec->sample_rate = avio_rl32(pb); + + st->codec->extradata_size = 2 * 4; + st->codec->extradata = av_malloc(st->codec->extradata_size + +@@ -56,10 +56,10 @@ + return AVERROR(ENOMEM); + + /* initial predictor values for adpcm decoder */ +- get_buffer(pb, st->codec->extradata, 2 * 4); ++ avio_read(pb, st->codec->extradata, 2 * 4); + + st->codec->channels = 1; +- if (get_le32(pb)) ++ if (avio_rl32(pb)) + st->codec->channels = 2; + + st->codec->bits_per_coded_sample = 4; +@@ -81,10 +81,9 @@ + } + + AVInputFormat ff_apc_demuxer = { +- "apc", +- NULL_IF_CONFIG_SMALL("CRYO APC format"), +- 0, +- apc_probe, +- apc_read_header, +- apc_read_packet, ++ .name = "apc", ++ .long_name = NULL_IF_CONFIG_SMALL("CRYO APC format"), ++ .read_probe = apc_probe, ++ .read_header = apc_read_header, ++ .read_packet = apc_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ape.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ape.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ape.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ape.c 2012-05-14 14:08:54.870350770 +0200 +@@ -24,10 +24,9 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "apetag.h" + +-#define ENABLE_DEBUG 0 +- + /* The earliest and latest file formats supported by this library */ + #define APE_MIN_VERSION 3950 + #define APE_MAX_VERSION 3990 +@@ -96,19 +95,19 @@ + + static void ape_dumpinfo(AVFormatContext * s, APEContext * ape_ctx) + { +-#if ENABLE_DEBUG ++#ifdef DEBUG + int i; + + av_log(s, AV_LOG_DEBUG, "Descriptor Block:\n\n"); + av_log(s, AV_LOG_DEBUG, "magic = \"%c%c%c%c\"\n", ape_ctx->magic[0], ape_ctx->magic[1], ape_ctx->magic[2], ape_ctx->magic[3]); +- av_log(s, AV_LOG_DEBUG, "fileversion = %d\n", ape_ctx->fileversion); +- av_log(s, AV_LOG_DEBUG, "descriptorlength = %d\n", ape_ctx->descriptorlength); +- av_log(s, AV_LOG_DEBUG, "headerlength = %d\n", ape_ctx->headerlength); +- av_log(s, AV_LOG_DEBUG, "seektablelength = %d\n", ape_ctx->seektablelength); +- av_log(s, AV_LOG_DEBUG, "wavheaderlength = %d\n", ape_ctx->wavheaderlength); +- av_log(s, AV_LOG_DEBUG, "audiodatalength = %d\n", ape_ctx->audiodatalength); +- av_log(s, AV_LOG_DEBUG, "audiodatalength_high = %d\n", ape_ctx->audiodatalength_high); +- av_log(s, AV_LOG_DEBUG, "wavtaillength = %d\n", ape_ctx->wavtaillength); ++ av_log(s, AV_LOG_DEBUG, "fileversion = %"PRId16"\n", ape_ctx->fileversion); ++ av_log(s, AV_LOG_DEBUG, "descriptorlength = %"PRIu32"\n", ape_ctx->descriptorlength); ++ av_log(s, AV_LOG_DEBUG, "headerlength = %"PRIu32"\n", ape_ctx->headerlength); ++ av_log(s, AV_LOG_DEBUG, "seektablelength = %"PRIu32"\n", ape_ctx->seektablelength); ++ av_log(s, AV_LOG_DEBUG, "wavheaderlength = %"PRIu32"\n", ape_ctx->wavheaderlength); ++ av_log(s, AV_LOG_DEBUG, "audiodatalength = %"PRIu32"\n", ape_ctx->audiodatalength); ++ av_log(s, AV_LOG_DEBUG, "audiodatalength_high = %"PRIu32"\n", ape_ctx->audiodatalength_high); ++ av_log(s, AV_LOG_DEBUG, "wavtaillength = %"PRIu32"\n", ape_ctx->wavtaillength); + av_log(s, AV_LOG_DEBUG, "md5 = "); + for (i = 0; i < 16; i++) + av_log(s, AV_LOG_DEBUG, "%02x", ape_ctx->md5[i]); +@@ -116,14 +115,14 @@ + + av_log(s, AV_LOG_DEBUG, "\nHeader Block:\n\n"); + +- av_log(s, AV_LOG_DEBUG, "compressiontype = %d\n", ape_ctx->compressiontype); +- av_log(s, AV_LOG_DEBUG, "formatflags = %d\n", ape_ctx->formatflags); +- av_log(s, AV_LOG_DEBUG, "blocksperframe = %d\n", ape_ctx->blocksperframe); +- av_log(s, AV_LOG_DEBUG, "finalframeblocks = %d\n", ape_ctx->finalframeblocks); +- av_log(s, AV_LOG_DEBUG, "totalframes = %d\n", ape_ctx->totalframes); +- av_log(s, AV_LOG_DEBUG, "bps = %d\n", ape_ctx->bps); +- av_log(s, AV_LOG_DEBUG, "channels = %d\n", ape_ctx->channels); +- av_log(s, AV_LOG_DEBUG, "samplerate = %d\n", ape_ctx->samplerate); ++ av_log(s, AV_LOG_DEBUG, "compressiontype = %"PRIu16"\n", ape_ctx->compressiontype); ++ av_log(s, AV_LOG_DEBUG, "formatflags = %"PRIu16"\n", ape_ctx->formatflags); ++ av_log(s, AV_LOG_DEBUG, "blocksperframe = %"PRIu32"\n", ape_ctx->blocksperframe); ++ av_log(s, AV_LOG_DEBUG, "finalframeblocks = %"PRIu32"\n", ape_ctx->finalframeblocks); ++ av_log(s, AV_LOG_DEBUG, "totalframes = %"PRIu32"\n", ape_ctx->totalframes); ++ av_log(s, AV_LOG_DEBUG, "bps = %"PRIu16"\n", ape_ctx->bps); ++ av_log(s, AV_LOG_DEBUG, "channels = %"PRIu16"\n", ape_ctx->channels); ++ av_log(s, AV_LOG_DEBUG, "samplerate = %"PRIu32"\n", ape_ctx->samplerate); + + av_log(s, AV_LOG_DEBUG, "\nSeektable\n\n"); + if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) { +@@ -131,27 +130,31 @@ + } else { + for (i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) { + if (i < ape_ctx->totalframes - 1) { +- av_log(s, AV_LOG_DEBUG, "%8d %d (%d bytes)\n", i, ape_ctx->seektable[i], ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]); ++ av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32" (%"PRIu32" bytes)\n", ++ i, ape_ctx->seektable[i], ++ ape_ctx->seektable[i + 1] - ape_ctx->seektable[i]); + } else { +- av_log(s, AV_LOG_DEBUG, "%8d %d\n", i, ape_ctx->seektable[i]); ++ av_log(s, AV_LOG_DEBUG, "%8d %"PRIu32"\n", i, ape_ctx->seektable[i]); + } + } + } + + av_log(s, AV_LOG_DEBUG, "\nFrames\n\n"); + for (i = 0; i < ape_ctx->totalframes; i++) +- av_log(s, AV_LOG_DEBUG, "%8d %8lld %8d (%d samples)\n", i, ape_ctx->frames[i].pos, ape_ctx->frames[i].size, ape_ctx->frames[i].nblocks); ++ av_log(s, AV_LOG_DEBUG, "%8d %8"PRId64" %8d (%d samples)\n", i, ++ ape_ctx->frames[i].pos, ape_ctx->frames[i].size, ++ ape_ctx->frames[i].nblocks); + + av_log(s, AV_LOG_DEBUG, "\nCalculated information:\n\n"); +- av_log(s, AV_LOG_DEBUG, "junklength = %d\n", ape_ctx->junklength); +- av_log(s, AV_LOG_DEBUG, "firstframe = %d\n", ape_ctx->firstframe); +- av_log(s, AV_LOG_DEBUG, "totalsamples = %d\n", ape_ctx->totalsamples); ++ av_log(s, AV_LOG_DEBUG, "junklength = %"PRIu32"\n", ape_ctx->junklength); ++ av_log(s, AV_LOG_DEBUG, "firstframe = %"PRIu32"\n", ape_ctx->firstframe); ++ av_log(s, AV_LOG_DEBUG, "totalsamples = %"PRIu32"\n", ape_ctx->totalsamples); + #endif + } + + static int ape_read_header(AVFormatContext * s, AVFormatParameters * ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + APEContext *ape = s->priv_data; + AVStream *st; + uint32_t tag; +@@ -159,65 +162,66 @@ + int total_blocks; + int64_t pts; + +- /* TODO: Skip any leading junk such as id3v2 tags */ +- ape->junklength = 0; ++ /* Skip any leading junk such as id3v2 tags */ ++ ape->junklength = avio_tell(pb); + +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('M', 'A', 'C', ' ')) + return -1; + +- ape->fileversion = get_le16(pb); ++ ape->fileversion = avio_rl16(pb); + + if (ape->fileversion < APE_MIN_VERSION || ape->fileversion > APE_MAX_VERSION) { +- av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10); ++ av_log(s, AV_LOG_ERROR, "Unsupported file version - %d.%02d\n", ++ ape->fileversion / 1000, (ape->fileversion % 1000) / 10); + return -1; + } + + if (ape->fileversion >= 3980) { +- ape->padding1 = get_le16(pb); +- ape->descriptorlength = get_le32(pb); +- ape->headerlength = get_le32(pb); +- ape->seektablelength = get_le32(pb); +- ape->wavheaderlength = get_le32(pb); +- ape->audiodatalength = get_le32(pb); +- ape->audiodatalength_high = get_le32(pb); +- ape->wavtaillength = get_le32(pb); +- get_buffer(pb, ape->md5, 16); ++ ape->padding1 = avio_rl16(pb); ++ ape->descriptorlength = avio_rl32(pb); ++ ape->headerlength = avio_rl32(pb); ++ ape->seektablelength = avio_rl32(pb); ++ ape->wavheaderlength = avio_rl32(pb); ++ ape->audiodatalength = avio_rl32(pb); ++ ape->audiodatalength_high = avio_rl32(pb); ++ ape->wavtaillength = avio_rl32(pb); ++ avio_read(pb, ape->md5, 16); + + /* Skip any unknown bytes at the end of the descriptor. + This is for future compatibility */ + if (ape->descriptorlength > 52) +- url_fseek(pb, ape->descriptorlength - 52, SEEK_CUR); ++ avio_skip(pb, ape->descriptorlength - 52); + + /* Read header data */ +- ape->compressiontype = get_le16(pb); +- ape->formatflags = get_le16(pb); +- ape->blocksperframe = get_le32(pb); +- ape->finalframeblocks = get_le32(pb); +- ape->totalframes = get_le32(pb); +- ape->bps = get_le16(pb); +- ape->channels = get_le16(pb); +- ape->samplerate = get_le32(pb); ++ ape->compressiontype = avio_rl16(pb); ++ ape->formatflags = avio_rl16(pb); ++ ape->blocksperframe = avio_rl32(pb); ++ ape->finalframeblocks = avio_rl32(pb); ++ ape->totalframes = avio_rl32(pb); ++ ape->bps = avio_rl16(pb); ++ ape->channels = avio_rl16(pb); ++ ape->samplerate = avio_rl32(pb); + } else { + ape->descriptorlength = 0; + ape->headerlength = 32; + +- ape->compressiontype = get_le16(pb); +- ape->formatflags = get_le16(pb); +- ape->channels = get_le16(pb); +- ape->samplerate = get_le32(pb); +- ape->wavheaderlength = get_le32(pb); +- ape->wavtaillength = get_le32(pb); +- ape->totalframes = get_le32(pb); +- ape->finalframeblocks = get_le32(pb); ++ ape->compressiontype = avio_rl16(pb); ++ ape->formatflags = avio_rl16(pb); ++ ape->channels = avio_rl16(pb); ++ ape->samplerate = avio_rl32(pb); ++ ape->wavheaderlength = avio_rl32(pb); ++ ape->wavtaillength = avio_rl32(pb); ++ ape->totalframes = avio_rl32(pb); ++ ape->finalframeblocks = avio_rl32(pb); + + if (ape->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) { +- url_fseek(pb, 4, SEEK_CUR); /* Skip the peak level */ ++ avio_skip(pb, 4); /* Skip the peak level */ + ape->headerlength += 4; + } + + if (ape->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) { +- ape->seektablelength = get_le32(pb); ++ ape->seektablelength = avio_rl32(pb); + ape->headerlength += 4; + ape->seektablelength *= sizeof(int32_t); + } else +@@ -239,13 +243,24 @@ + + /* Skip any stored wav header */ + if (!(ape->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER)) +- url_fskip(pb, ape->wavheaderlength); ++ avio_skip(pb, ape->wavheaderlength); + } + ++ if(!ape->totalframes){ ++ av_log(s, AV_LOG_ERROR, "No frames in the file!\n"); ++ return AVERROR(EINVAL); ++ } + if(ape->totalframes > UINT_MAX / sizeof(APEFrame)){ +- av_log(s, AV_LOG_ERROR, "Too many frames: %d\n", ape->totalframes); ++ av_log(s, AV_LOG_ERROR, "Too many frames: %"PRIu32"\n", ++ ape->totalframes); + return -1; + } ++ if (ape->seektablelength && (ape->seektablelength / sizeof(*ape->seektable)) < ape->totalframes) { ++ av_log(s, AV_LOG_ERROR, ++ "Number of seek entries is less than number of frames: %zu vs. %"PRIu32"\n", ++ ape->seektablelength / sizeof(*ape->seektable), ape->totalframes); ++ return AVERROR_INVALIDDATA; ++ } + ape->frames = av_malloc(ape->totalframes * sizeof(APEFrame)); + if(!ape->frames) + return AVERROR(ENOMEM); +@@ -259,15 +274,17 @@ + + if (ape->seektablelength > 0) { + ape->seektable = av_malloc(ape->seektablelength); ++ if (!ape->seektable) ++ return AVERROR(ENOMEM); + for (i = 0; i < ape->seektablelength / sizeof(uint32_t); i++) +- ape->seektable[i] = get_le32(pb); ++ ape->seektable[i] = avio_rl32(pb); + } + + ape->frames[0].pos = ape->firstframe; + ape->frames[0].nblocks = ape->blocksperframe; + ape->frames[0].skip = 0; + for (i = 1; i < ape->totalframes; i++) { +- ape->frames[i].pos = ape->seektable[i]; //ape->frames[i-1].pos + ape->blocksperframe; ++ ape->frames[i].pos = ape->seektable[i] + ape->junklength; + ape->frames[i].nblocks = ape->blocksperframe; + ape->frames[i - 1].size = ape->frames[i].pos - ape->frames[i - 1].pos; + ape->frames[i].skip = (ape->frames[i].pos - ape->frames[0].pos) & 3; +@@ -287,15 +304,17 @@ + ape_dumpinfo(s, ape); + + /* try to read APE tags */ +- if (!url_is_streamed(pb)) { ++ if (pb->seekable) { + ff_ape_parse_tag(s); +- url_fseek(pb, 0, SEEK_SET); ++ avio_seek(pb, 0, SEEK_SET); + } + +- av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %d\n", ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ape->compressiontype); ++ av_log(s, AV_LOG_DEBUG, "Decoding file - v%d.%02d, compression level %"PRIu16"\n", ++ ape->fileversion / 1000, (ape->fileversion % 1000) / 10, ++ ape->compressiontype); + + /* now we are ready: build format streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + +@@ -312,7 +331,7 @@ + st->nb_frames = ape->totalframes; + st->start_time = 0; + st->duration = total_blocks / MAC_SUBFRAME_SIZE; +- av_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); ++ avpriv_set_pts_info(st, 64, MAC_SUBFRAME_SIZE, ape->samplerate); + + st->codec->extradata = av_malloc(APE_EXTRADATA_SIZE); + st->codec->extradata_size = APE_EXTRADATA_SIZE; +@@ -342,7 +361,7 @@ + if (ape->currentframe > ape->totalframes) + return AVERROR(EIO); + +- url_fseek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET); ++ avio_seek (s->pb, ape->frames[ape->currentframe].pos, SEEK_SET); + + /* Calculate how many blocks there are in this frame */ + if (ape->currentframe == (ape->totalframes - 1)) +@@ -355,7 +374,7 @@ + + AV_WL32(pkt->data , nblocks); + AV_WL32(pkt->data + 4, ape->frames[ape->currentframe].skip); +- ret = get_buffer(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); ++ ret = avio_read(s->pb, pkt->data + extra_size, ape->frames[ape->currentframe].size); + + pkt->pts = ape->frames[ape->currentframe].pts; + pkt->stream_index = 0; +@@ -392,13 +411,13 @@ + } + + AVInputFormat ff_ape_demuxer = { +- "ape", +- NULL_IF_CONFIG_SMALL("Monkey's Audio"), +- sizeof(APEContext), +- ape_probe, +- ape_read_header, +- ape_read_packet, +- ape_read_close, +- ape_read_seek, ++ .name = "ape", ++ .long_name = NULL_IF_CONFIG_SMALL("Monkey's Audio"), ++ .priv_data_size = sizeof(APEContext), ++ .read_probe = ape_probe, ++ .read_header = ape_read_header, ++ .read_packet = ape_read_packet, ++ .read_close = ape_read_close, ++ .read_seek = ape_read_seek, + .extensions = "ape,apl,mac" + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/apetag.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/apetag.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/apetag.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/apetag.c 2012-05-14 14:08:54.871350790 +0200 +@@ -21,11 +21,10 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" + #include "apetag.h" + +-#define ENABLE_DEBUG 0 +- + #define APE_TAG_VERSION 2000 + #define APE_TAG_FOOTER_BYTES 32 + #define APE_TAG_FLAG_CONTAINS_HEADER (1 << 31) +@@ -33,15 +32,15 @@ + + static int ape_tag_read_field(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t key[1024], *value; +- uint32_t size, flags; ++ uint32_t size; + int i, c; + +- size = get_le32(pb); /* field size */ +- flags = get_le32(pb); /* field flags */ ++ size = avio_rl32(pb); /* field size */ ++ avio_skip(pb, 4); /* field flags */ + for (i = 0; i < sizeof(key) - 1; i++) { +- c = get_byte(pb); ++ c = avio_r8(pb); + if (c < 0x20 || c > 0x7E) + break; + else +@@ -57,16 +56,16 @@ + value = av_malloc(size+1); + if (!value) + return AVERROR(ENOMEM); +- get_buffer(pb, value, size); ++ avio_read(pb, value, size); + value[size] = 0; +- av_metadata_set2(&s->metadata, key, value, AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL); + return 0; + } + + void ff_ape_parse_tag(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; +- int file_size = url_fsize(pb); ++ AVIOContext *pb = s->pb; ++ int file_size = avio_size(pb); + uint32_t val, fields, tag_bytes; + uint8_t buf[8]; + int i; +@@ -74,38 +73,38 @@ + if (file_size < APE_TAG_FOOTER_BYTES) + return; + +- url_fseek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); ++ avio_seek(pb, file_size - APE_TAG_FOOTER_BYTES, SEEK_SET); + +- get_buffer(pb, buf, 8); /* APETAGEX */ ++ avio_read(pb, buf, 8); /* APETAGEX */ + if (strncmp(buf, "APETAGEX", 8)) { + return; + } + +- val = get_le32(pb); /* APE tag version */ ++ val = avio_rl32(pb); /* APE tag version */ + if (val > APE_TAG_VERSION) { + av_log(s, AV_LOG_ERROR, "Unsupported tag version. (>=%d)\n", APE_TAG_VERSION); + return; + } + +- tag_bytes = get_le32(pb); /* tag size */ ++ tag_bytes = avio_rl32(pb); /* tag size */ + if (tag_bytes - APE_TAG_FOOTER_BYTES > (1024 * 1024 * 16)) { + av_log(s, AV_LOG_ERROR, "Tag size is way too big\n"); + return; + } + +- fields = get_le32(pb); /* number of fields */ ++ fields = avio_rl32(pb); /* number of fields */ + if (fields > 65536) { + av_log(s, AV_LOG_ERROR, "Too many tag fields (%d)\n", fields); + return; + } + +- val = get_le32(pb); /* flags */ ++ val = avio_rl32(pb); /* flags */ + if (val & APE_TAG_FLAG_IS_HEADER) { + av_log(s, AV_LOG_ERROR, "APE Tag is a header\n"); + return; + } + +- url_fseek(pb, file_size - tag_bytes, SEEK_SET); ++ avio_seek(pb, file_size - tag_bytes, SEEK_SET); + + for (i=0; i ++#include "avio_internal.h" ++#include "url.h" ++ ++#define INITIAL_BUFFER_SIZE 32768 + + /* + * An apple http stream consists of a playlist with media segment files, +@@ -43,42 +50,62 @@ + * one anonymous toplevel variant for this, to maintain the structure. + */ + ++enum KeyType { ++ KEY_NONE, ++ KEY_AES_128, ++}; ++ + struct segment { + int duration; + char url[MAX_URL_SIZE]; ++ char key[MAX_URL_SIZE]; ++ enum KeyType key_type; ++ uint8_t iv[16]; + }; + + /* + * Each variant has its own demuxer. If it currently is active, +- * it has an open ByteIOContext too, and potentially an AVPacket ++ * it has an open AVIOContext too, and potentially an AVPacket + * containing the next packet from this stream. + */ + struct variant { + int bandwidth; + char url[MAX_URL_SIZE]; +- ByteIOContext *pb; ++ AVIOContext pb; ++ uint8_t* read_buffer; ++ URLContext *input; ++ AVFormatContext *parent; ++ int index; + AVFormatContext *ctx; + AVPacket pkt; + int stream_offset; + ++ int finished; ++ int target_duration; + int start_seq_no; + int n_segments; + struct segment **segments; +- int needed; ++ int needed, cur_needed; ++ int cur_seq_no; ++ int64_t last_load_time; ++ ++ char key_url[MAX_URL_SIZE]; ++ uint8_t key[16]; + }; + + typedef struct AppleHTTPContext { +- int target_duration; +- int finished; + int n_variants; + struct variant **variants; + int cur_seq_no; +- int64_t last_load_time; +- int64_t last_packet_dts; +- int max_start_seq, min_end_seq; ++ int end_of_segment; ++ int first_packet; ++ int64_t first_timestamp; ++ int64_t seek_timestamp; ++ int seek_flags; ++ AVIOInterruptCB *interrupt_callback; + } AppleHTTPContext; + +-static int read_chomp_line(ByteIOContext *s, char *buf, int maxlen) ++static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) + { + int len = ff_get_line(s, buf, maxlen); + while (len > 0 && isspace(buf[len - 1])) +@@ -86,43 +113,6 @@ + return len; + } + +-static void make_absolute_url(char *buf, int size, const char *base, +- const char *rel) +-{ +- char *sep; +- /* If rel actually is an absolute url, just copy it */ +- if (!base || strstr(rel, "://") || rel[0] == '/') { +- av_strlcpy(buf, rel, size); +- return; +- } +- if (base != buf) +- av_strlcpy(buf, base, size); +- /* Remove the file name from the base url */ +- sep = strrchr(buf, '/'); +- if (sep) +- sep[1] = '\0'; +- else +- buf[0] = '\0'; +- while (av_strstart(rel, "../", NULL) && sep) { +- /* Remove the path delimiter at the end */ +- sep[0] = '\0'; +- sep = strrchr(buf, '/'); +- /* If the next directory name to pop off is "..", break here */ +- if (!strcmp(sep ? &sep[1] : buf, "..")) { +- /* Readd the slash we just removed */ +- av_strlcat(buf, "/", size); +- break; +- } +- /* Cut off the directory name */ +- if (sep) +- sep[1] = '\0'; +- else +- buf[0] = '\0'; +- rel += 3; +- } +- av_strlcat(buf, rel, size); +-} +- + static void free_segment_list(struct variant *var) + { + int i; +@@ -139,11 +129,12 @@ + struct variant *var = c->variants[i]; + free_segment_list(var); + av_free_packet(&var->pkt); +- if (var->pb) +- url_fclose(var->pb); ++ av_free(var->pb.buffer); ++ if (var->input) ++ ffurl_close(var->input); + if (var->ctx) { + var->ctx->pb = NULL; +- av_close_input_file(var->ctx); ++ avformat_close_input(&var->ctx); + } + av_free(var); + } +@@ -169,7 +160,7 @@ + return NULL; + reset_packet(&var->pkt); + var->bandwidth = bandwidth; +- make_absolute_url(var->url, sizeof(var->url), base, url); ++ ff_make_absolute_url(var->url, sizeof(var->url), base, url); + dynarray_add(&c->variants, &c->n_variants, var); + return var; + } +@@ -187,17 +178,43 @@ + } + } + ++struct key_info { ++ char uri[MAX_URL_SIZE]; ++ char method[10]; ++ char iv[35]; ++}; ++ ++static void handle_key_args(struct key_info *info, const char *key, ++ int key_len, char **dest, int *dest_len) ++{ ++ if (!strncmp(key, "METHOD=", key_len)) { ++ *dest = info->method; ++ *dest_len = sizeof(info->method); ++ } else if (!strncmp(key, "URI=", key_len)) { ++ *dest = info->uri; ++ *dest_len = sizeof(info->uri); ++ } else if (!strncmp(key, "IV=", key_len)) { ++ *dest = info->iv; ++ *dest_len = sizeof(info->iv); ++ } ++} ++ + static int parse_playlist(AppleHTTPContext *c, const char *url, +- struct variant *var, ByteIOContext *in) ++ struct variant *var, AVIOContext *in) + { + int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0; ++ enum KeyType key_type = KEY_NONE; ++ uint8_t iv[16] = ""; ++ int has_iv = 0; ++ char key[MAX_URL_SIZE] = ""; + char line[1024]; + const char *ptr; + int close_in = 0; + + if (!in) { + close_in = 1; +- if ((ret = url_fopen(&in, url, URL_RDONLY)) < 0) ++ if ((ret = avio_open2(&in, url, AVIO_FLAG_READ, ++ c->interrupt_callback, NULL)) < 0) + return ret; + } + +@@ -207,9 +224,10 @@ + goto fail; + } + +- if (var) ++ if (var) { + free_segment_list(var); +- c->finished = 0; ++ var->finished = 0; ++ } + while (!url_feof(in)) { + read_chomp_line(in, line, sizeof(line)); + if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) { +@@ -218,8 +236,28 @@ + ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args, + &info); + bandwidth = atoi(info.bandwidth); ++ } else if (av_strstart(line, "#EXT-X-KEY:", &ptr)) { ++ struct key_info info = {{0}}; ++ ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_key_args, ++ &info); ++ key_type = KEY_NONE; ++ has_iv = 0; ++ if (!strcmp(info.method, "AES-128")) ++ key_type = KEY_AES_128; ++ if (!strncmp(info.iv, "0x", 2) || !strncmp(info.iv, "0X", 2)) { ++ ff_hex_to_data(iv, info.iv + 2); ++ has_iv = 1; ++ } ++ av_strlcpy(key, info.uri, sizeof(key)); + } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) { +- c->target_duration = atoi(ptr); ++ if (!var) { ++ var = new_variant(c, 0, url, NULL); ++ if (!var) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ } ++ var->target_duration = atoi(ptr); + } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) { + if (!var) { + var = new_variant(c, 0, url, NULL); +@@ -230,7 +268,8 @@ + } + var->start_seq_no = atoi(ptr); + } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { +- c->finished = 1; ++ if (var) ++ var->finished = 1; + } else if (av_strstart(line, "#EXTINF:", &ptr)) { + is_segment = 1; + duration = atoi(ptr); +@@ -260,25 +299,159 @@ + goto fail; + } + seg->duration = duration; +- make_absolute_url(seg->url, sizeof(seg->url), url, line); ++ seg->key_type = key_type; ++ if (has_iv) { ++ memcpy(seg->iv, iv, sizeof(iv)); ++ } else { ++ int seq = var->start_seq_no + var->n_segments; ++ memset(seg->iv, 0, sizeof(seg->iv)); ++ AV_WB32(seg->iv + 12, seq); ++ } ++ ff_make_absolute_url(seg->key, sizeof(seg->key), url, key); ++ ff_make_absolute_url(seg->url, sizeof(seg->url), url, line); + dynarray_add(&var->segments, &var->n_segments, seg); + is_segment = 0; + } + } + } +- c->last_load_time = av_gettime(); ++ if (var) ++ var->last_load_time = av_gettime(); + + fail: + if (close_in) +- url_fclose(in); ++ avio_close(in); + return ret; + } + ++static int open_input(struct variant *var) ++{ ++ struct segment *seg = var->segments[var->cur_seq_no - var->start_seq_no]; ++ if (seg->key_type == KEY_NONE) { ++ return ffurl_open(&var->input, seg->url, AVIO_FLAG_READ, ++ &var->parent->interrupt_callback, NULL); ++ } else if (seg->key_type == KEY_AES_128) { ++ char iv[33], key[33], url[MAX_URL_SIZE]; ++ int ret; ++ if (strcmp(seg->key, var->key_url)) { ++ URLContext *uc; ++ if (ffurl_open(&uc, seg->key, AVIO_FLAG_READ, ++ &var->parent->interrupt_callback, NULL) == 0) { ++ if (ffurl_read_complete(uc, var->key, sizeof(var->key)) ++ != sizeof(var->key)) { ++ av_log(NULL, AV_LOG_ERROR, "Unable to read key file %s\n", ++ seg->key); ++ } ++ ffurl_close(uc); ++ } else { ++ av_log(NULL, AV_LOG_ERROR, "Unable to open key file %s\n", ++ seg->key); ++ } ++ av_strlcpy(var->key_url, seg->key, sizeof(var->key_url)); ++ } ++ ff_data_to_hex(iv, seg->iv, sizeof(seg->iv), 0); ++ ff_data_to_hex(key, var->key, sizeof(var->key), 0); ++ iv[32] = key[32] = '\0'; ++ if (strstr(seg->url, "://")) ++ snprintf(url, sizeof(url), "crypto+%s", seg->url); ++ else ++ snprintf(url, sizeof(url), "crypto:%s", seg->url); ++ if ((ret = ffurl_alloc(&var->input, url, AVIO_FLAG_READ, ++ &var->parent->interrupt_callback)) < 0) ++ return ret; ++ av_opt_set(var->input->priv_data, "key", key, 0); ++ av_opt_set(var->input->priv_data, "iv", iv, 0); ++ if ((ret = ffurl_connect(var->input, NULL)) < 0) { ++ ffurl_close(var->input); ++ var->input = NULL; ++ return ret; ++ } ++ return 0; ++ } ++ return AVERROR(ENOSYS); ++} ++ ++static int read_data(void *opaque, uint8_t *buf, int buf_size) ++{ ++ struct variant *v = opaque; ++ AppleHTTPContext *c = v->parent->priv_data; ++ int ret, i; ++ ++restart: ++ if (!v->input) { ++ /* If this is a live stream and the reload interval has elapsed since ++ * the last playlist reload, reload the variant playlists now. */ ++ int64_t reload_interval = v->n_segments > 0 ? ++ v->segments[v->n_segments - 1]->duration : ++ v->target_duration; ++ reload_interval *= 1000000; ++ ++reload: ++ if (!v->finished && ++ av_gettime() - v->last_load_time >= reload_interval) { ++ if ((ret = parse_playlist(c, v->url, v, NULL)) < 0) ++ return ret; ++ /* If we need to reload the playlist again below (if ++ * there's still no more segments), switch to a reload ++ * interval of half the target duration. */ ++ reload_interval = v->target_duration * 500000; ++ } ++ if (v->cur_seq_no < v->start_seq_no) { ++ av_log(NULL, AV_LOG_WARNING, ++ "skipping %d segments ahead, expired from playlists\n", ++ v->start_seq_no - v->cur_seq_no); ++ v->cur_seq_no = v->start_seq_no; ++ } ++ if (v->cur_seq_no >= v->start_seq_no + v->n_segments) { ++ if (v->finished) ++ return AVERROR_EOF; ++ while (av_gettime() - v->last_load_time < reload_interval) { ++ if (ff_check_interrupt(c->interrupt_callback)) ++ return AVERROR_EXIT; ++ usleep(100*1000); ++ } ++ /* Enough time has elapsed since the last reload */ ++ goto reload; ++ } ++ ++ ret = open_input(v); ++ if (ret < 0) ++ return ret; ++ } ++ ret = ffurl_read(v->input, buf, buf_size); ++ if (ret > 0) ++ return ret; ++ if (ret < 0 && ret != AVERROR_EOF) ++ return ret; ++ ffurl_close(v->input); ++ v->input = NULL; ++ v->cur_seq_no++; ++ ++ c->end_of_segment = 1; ++ c->cur_seq_no = v->cur_seq_no; ++ ++ if (v->ctx && v->ctx->nb_streams) { ++ v->needed = 0; ++ for (i = v->stream_offset; i < v->stream_offset + v->ctx->nb_streams; ++ i++) { ++ if (v->parent->streams[i]->discard < AVDISCARD_ALL) ++ v->needed = 1; ++ } ++ } ++ if (!v->needed) { ++ av_log(v->parent, AV_LOG_INFO, "No longer receiving variant %d\n", ++ v->index); ++ return AVERROR_EOF; ++ } ++ goto restart; ++} ++ + static int applehttp_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + AppleHTTPContext *c = s->priv_data; + int ret = 0, i, j, stream_offset = 0; + ++ c->interrupt_callback = &s->interrupt_callback; ++ + if ((ret = parse_playlist(c, s->filename, NULL, s->pb)) < 0) + goto fail; + +@@ -305,46 +478,76 @@ + + /* If this isn't a live stream, calculate the total duration of the + * stream. */ +- if (c->finished) { ++ if (c->variants[0]->finished) { + int64_t duration = 0; + for (i = 0; i < c->variants[0]->n_segments; i++) + duration += c->variants[0]->segments[i]->duration; + s->duration = duration * AV_TIME_BASE; + } + +- c->min_end_seq = INT_MAX; + /* Open the demuxer for each variant */ + for (i = 0; i < c->n_variants; i++) { + struct variant *v = c->variants[i]; ++ AVInputFormat *in_fmt = NULL; ++ char bitrate_str[20]; + if (v->n_segments == 0) + continue; +- c->max_start_seq = FFMAX(c->max_start_seq, v->start_seq_no); +- c->min_end_seq = FFMIN(c->min_end_seq, v->start_seq_no + +- v->n_segments); +- ret = av_open_input_file(&v->ctx, v->segments[0]->url, NULL, 0, NULL); ++ ++ if (!(v->ctx = avformat_alloc_context())) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ ++ v->index = i; ++ v->needed = 1; ++ v->parent = s; ++ ++ /* If this is a live stream with more than 3 segments, start at the ++ * third last segment. */ ++ v->cur_seq_no = v->start_seq_no; ++ if (!v->finished && v->n_segments > 3) ++ v->cur_seq_no = v->start_seq_no + v->n_segments - 3; ++ ++ v->read_buffer = av_malloc(INITIAL_BUFFER_SIZE); ++ ffio_init_context(&v->pb, v->read_buffer, INITIAL_BUFFER_SIZE, 0, v, ++ read_data, NULL, NULL); ++ v->pb.seekable = 0; ++ ret = av_probe_input_buffer(&v->pb, &in_fmt, v->segments[0]->url, ++ NULL, 0, 0); ++ if (ret < 0) { ++ /* Free the ctx - it isn't initialized properly at this point, ++ * so avformat_close_input shouldn't be called. If ++ * avformat_open_input fails below, it frees and zeros the ++ * context, so it doesn't need any special treatment like this. */ ++ avformat_free_context(v->ctx); ++ v->ctx = NULL; ++ goto fail; ++ } ++ v->ctx->pb = &v->pb; ++ ret = avformat_open_input(&v->ctx, v->segments[0]->url, in_fmt, NULL); + if (ret < 0) + goto fail; +- url_fclose(v->ctx->pb); +- v->ctx->pb = NULL; + v->stream_offset = stream_offset; ++ snprintf(bitrate_str, sizeof(bitrate_str), "%d", v->bandwidth); + /* Create new AVStreams for each stream in this variant */ + for (j = 0; j < v->ctx->nb_streams; j++) { +- AVStream *st = av_new_stream(s, i); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) { + ret = AVERROR(ENOMEM); + goto fail; + } ++ st->id = i; + avcodec_copy_context(st->codec, v->ctx->streams[j]->codec); ++ if (v->bandwidth) ++ av_dict_set(&st->metadata, "variant_bitrate", bitrate_str, ++ 0); + } + stream_offset += v->ctx->nb_streams; + } +- c->last_packet_dts = AV_NOPTS_VALUE; + +- c->cur_seq_no = c->max_start_seq; +- /* If this is a live stream with more than 3 segments, start at the +- * third last segment. */ +- if (!c->finished && c->min_end_seq - c->max_start_seq > 3) +- c->cur_seq_no = c->min_end_seq - 2; ++ c->first_packet = 1; ++ c->first_timestamp = AV_NOPTS_VALUE; ++ c->seek_timestamp = AV_NOPTS_VALUE; + + return 0; + fail: +@@ -352,100 +555,96 @@ + return ret; + } + +-static int open_variant(AppleHTTPContext *c, struct variant *var, int skip) ++static int recheck_discard_flags(AVFormatContext *s, int first) + { +- int ret; ++ AppleHTTPContext *c = s->priv_data; ++ int i, changed = 0; + +- if (c->cur_seq_no < var->start_seq_no) { +- av_log(NULL, AV_LOG_WARNING, +- "seq %d not available in variant %s, skipping\n", +- var->start_seq_no, var->url); +- return 0; ++ /* Check if any new streams are needed */ ++ for (i = 0; i < c->n_variants; i++) ++ c->variants[i]->cur_needed = 0; ++ ++ for (i = 0; i < s->nb_streams; i++) { ++ AVStream *st = s->streams[i]; ++ struct variant *var = c->variants[s->streams[i]->id]; ++ if (st->discard < AVDISCARD_ALL) ++ var->cur_needed = 1; + } +- if (c->cur_seq_no - var->start_seq_no >= var->n_segments) +- return c->finished ? AVERROR_EOF : 0; +- ret = url_fopen(&var->pb, +- var->segments[c->cur_seq_no - var->start_seq_no]->url, +- URL_RDONLY); +- if (ret < 0) +- return ret; +- var->ctx->pb = var->pb; +- /* If this is a new segment in parallel with another one already opened, +- * skip ahead so they're all at the same dts. */ +- if (skip && c->last_packet_dts != AV_NOPTS_VALUE) { +- while (1) { +- ret = av_read_frame(var->ctx, &var->pkt); +- if (ret < 0) { +- if (ret == AVERROR_EOF) { +- reset_packet(&var->pkt); +- return 0; +- } +- return ret; +- } +- if (var->pkt.dts >= c->last_packet_dts) +- break; +- av_free_packet(&var->pkt); ++ for (i = 0; i < c->n_variants; i++) { ++ struct variant *v = c->variants[i]; ++ if (v->cur_needed && !v->needed) { ++ v->needed = 1; ++ changed = 1; ++ v->cur_seq_no = c->cur_seq_no; ++ v->pb.eof_reached = 0; ++ av_log(s, AV_LOG_INFO, "Now receiving variant %d\n", i); ++ } else if (first && !v->cur_needed && v->needed) { ++ if (v->input) ++ ffurl_close(v->input); ++ v->input = NULL; ++ v->needed = 0; ++ changed = 1; ++ av_log(s, AV_LOG_INFO, "No longer receiving variant %d\n", i); + } + } +- return 0; ++ return changed; + } + + static int applehttp_read_packet(AVFormatContext *s, AVPacket *pkt) + { + AppleHTTPContext *c = s->priv_data; +- int ret, i, minvariant = -1, first = 1, needed = 0, changed = 0, +- variants = 0; ++ int ret, i, minvariant = -1; + +- /* Recheck the discard flags - which streams are desired at the moment */ +- for (i = 0; i < c->n_variants; i++) +- c->variants[i]->needed = 0; +- for (i = 0; i < s->nb_streams; i++) { +- AVStream *st = s->streams[i]; +- struct variant *var = c->variants[s->streams[i]->id]; +- if (st->discard < AVDISCARD_ALL) { +- var->needed = 1; +- needed++; +- } +- /* Copy the discard flag to the chained demuxer, to indicate which +- * streams are desired. */ +- var->ctx->streams[i - var->stream_offset]->discard = st->discard; ++ if (c->first_packet) { ++ recheck_discard_flags(s, 1); ++ c->first_packet = 0; + } +- if (!needed) +- return AVERROR_EOF; ++ + start: ++ c->end_of_segment = 0; + for (i = 0; i < c->n_variants; i++) { + struct variant *var = c->variants[i]; +- /* Close unneeded streams, open newly requested streams */ +- if (var->pb && !var->needed) { +- av_log(s, AV_LOG_DEBUG, +- "Closing variant stream %d, no longer needed\n", i); +- av_free_packet(&var->pkt); +- reset_packet(&var->pkt); +- url_fclose(var->pb); +- var->pb = NULL; +- changed = 1; +- } else if (!var->pb && var->needed) { +- if (first) +- av_log(s, AV_LOG_DEBUG, "Opening variant stream %d\n", i); +- if (first && !c->finished) +- if ((ret = parse_playlist(c, var->url, var, NULL)) < 0) +- return ret; +- ret = open_variant(c, var, first); +- if (ret < 0) +- return ret; +- changed = 1; +- } +- /* Count the number of open variants */ +- if (var->pb) +- variants++; + /* Make sure we've got one buffered packet from each open variant + * stream */ +- if (var->pb && !var->pkt.data) { +- ret = av_read_frame(var->ctx, &var->pkt); +- if (ret < 0) { +- if (!url_feof(var->pb)) +- return ret; +- reset_packet(&var->pkt); ++ if (var->needed && !var->pkt.data) { ++ while (1) { ++ int64_t ts_diff; ++ ret = av_read_frame(var->ctx, &var->pkt); ++ if (ret < 0) { ++ if (!url_feof(&var->pb)) { ++ return ret; ++ } else { ++ if ((var->cur_seq_no - var->start_seq_no) == (var->n_segments)) { ++ return AVERROR_EOF; ++ } ++ } ++ reset_packet(&var->pkt); ++ } else { ++ if (c->first_timestamp == AV_NOPTS_VALUE) ++ c->first_timestamp = var->pkt.dts; ++ } ++ ++ if (c->seek_timestamp == AV_NOPTS_VALUE) ++ break; ++ ++ if (var->pkt.dts == AV_NOPTS_VALUE) { ++ c->seek_timestamp = AV_NOPTS_VALUE; ++ break; ++ } ++ ++ ts_diff = var->pkt.dts - c->seek_timestamp; ++ if (ts_diff >= 0) { ++ if (c->seek_flags & AVSEEK_FLAG_ANY) { ++ c->seek_timestamp = AV_NOPTS_VALUE; ++ break; ++ } ++ ++ /* Seek to keyframe */ ++ if (var->pkt.flags & AV_PKT_FLAG_KEY) { ++ c->seek_timestamp = AV_NOPTS_VALUE; ++ break; ++ } ++ } + } + } + /* Check if this stream has the packet with the lowest dts */ +@@ -455,70 +654,18 @@ + minvariant = i; + } + } +- if (first && changed) +- av_log(s, AV_LOG_INFO, "Receiving %d variant streams\n", variants); ++ if (c->end_of_segment) { ++ if (recheck_discard_flags(s, 0)) ++ goto start; ++ } + /* If we got a packet, return it */ + if (minvariant >= 0) { + *pkt = c->variants[minvariant]->pkt; + pkt->stream_index += c->variants[minvariant]->stream_offset; + reset_packet(&c->variants[minvariant]->pkt); +- c->last_packet_dts = pkt->dts; + return 0; + } +- /* No more packets - eof reached in all variant streams, close the +- * current segments. */ +- for (i = 0; i < c->n_variants; i++) { +- struct variant *var = c->variants[i]; +- if (var->pb) { +- url_fclose(var->pb); +- var->pb = NULL; +- } +- } +- /* Indicate that we're opening the next segment, not opening a new +- * variant stream in parallel, so we shouldn't try to skip ahead. */ +- first = 0; +- c->cur_seq_no++; +-reload: +- if (!c->finished) { +- /* If this is a live stream and target_duration has elapsed since +- * the last playlist reload, reload the variant playlists now. */ +- int64_t now = av_gettime(); +- if (now - c->last_load_time >= c->target_duration*1000000) { +- c->max_start_seq = 0; +- c->min_end_seq = INT_MAX; +- for (i = 0; i < c->n_variants; i++) { +- struct variant *var = c->variants[i]; +- if (var->needed) { +- if ((ret = parse_playlist(c, var->url, var, NULL)) < 0) +- return ret; +- c->max_start_seq = FFMAX(c->max_start_seq, +- var->start_seq_no); +- c->min_end_seq = FFMIN(c->min_end_seq, +- var->start_seq_no + var->n_segments); +- } +- } +- } +- } +- if (c->cur_seq_no < c->max_start_seq) { +- av_log(NULL, AV_LOG_WARNING, +- "skipping %d segments ahead, expired from playlists\n", +- c->max_start_seq - c->cur_seq_no); +- c->cur_seq_no = c->max_start_seq; +- } +- /* If more segments exit, open the next one */ +- if (c->cur_seq_no < c->min_end_seq) +- goto start; +- /* We've reached the end of the playlists - return eof if this is a +- * non-live stream, wait until the next playlist reload if it is live. */ +- if (c->finished) +- return AVERROR_EOF; +- while (av_gettime() - c->last_load_time < c->target_duration*1000000) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); +- usleep(100*1000); +- } +- /* Enough time has elapsed since the last reload */ +- goto reload; ++ return AVERROR_EOF; + } + + static int applehttp_close(AVFormatContext *s) +@@ -533,37 +680,53 @@ + int64_t timestamp, int flags) + { + AppleHTTPContext *c = s->priv_data; +- int pos = 0, i; +- struct variant *var = c->variants[0]; ++ int i, j, ret; + +- if ((flags & AVSEEK_FLAG_BYTE) || !c->finished) ++ if ((flags & AVSEEK_FLAG_BYTE) || !c->variants[0]->finished) + return AVERROR(ENOSYS); + +- /* Reset the variants */ +- c->last_packet_dts = AV_NOPTS_VALUE; ++ c->seek_timestamp = timestamp; ++ c->seek_flags = flags; ++ timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ? ++ s->streams[stream_index]->time_base.den : ++ AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ? ++ AV_ROUND_DOWN : AV_ROUND_UP); ++ if (s->duration < c->seek_timestamp) { ++ c->seek_timestamp = AV_NOPTS_VALUE; ++ return AVERROR(EIO); ++ } ++ ++ ret = AVERROR(EIO); + for (i = 0; i < c->n_variants; i++) { ++ /* Reset reading */ + struct variant *var = c->variants[i]; +- if (var->pb) { +- url_fclose(var->pb); +- var->pb = NULL; ++ int64_t pos = c->first_timestamp == AV_NOPTS_VALUE ? 0 : ++ av_rescale_rnd(c->first_timestamp, 1, stream_index >= 0 ? ++ s->streams[stream_index]->time_base.den : ++ AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ? ++ AV_ROUND_DOWN : AV_ROUND_UP); ++ if (var->input) { ++ ffurl_close(var->input); ++ var->input = NULL; + } + av_free_packet(&var->pkt); + reset_packet(&var->pkt); +- } ++ var->pb.eof_reached = 0; + +- timestamp = av_rescale_rnd(timestamp, 1, stream_index >= 0 ? +- s->streams[stream_index]->time_base.den : +- AV_TIME_BASE, flags & AVSEEK_FLAG_BACKWARD ? +- AV_ROUND_DOWN : AV_ROUND_UP); +- /* Locate the segment that contains the target timestamp */ +- for (i = 0; i < var->n_segments; i++) { +- if (timestamp >= pos && timestamp < pos + var->segments[i]->duration) { +- c->cur_seq_no = var->start_seq_no + i; +- return 0; ++ /* Locate the segment that contains the target timestamp */ ++ for (j = 0; j < var->n_segments; j++) { ++ if (timestamp >= pos && ++ timestamp < pos + var->segments[j]->duration) { ++ var->cur_seq_no = var->start_seq_no + j; ++ ret = 0; ++ break; ++ } ++ pos += var->segments[j]->duration; + } +- pos += var->segments[i]->duration; ++ if (ret != 0) ++ c->seek_timestamp = AV_NOPTS_VALUE; + } +- return AVERROR(EIO); ++ return ret; + } + + static int applehttp_probe(AVProbeData *p) +@@ -580,12 +743,12 @@ + } + + AVInputFormat ff_applehttp_demuxer = { +- "applehttp", +- NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"), +- sizeof(AppleHTTPContext), +- applehttp_probe, +- applehttp_read_header, +- applehttp_read_packet, +- applehttp_close, +- applehttp_read_seek, ++ .name = "applehttp", ++ .long_name = NULL_IF_CONFIG_SMALL("Apple HTTP Live Streaming format"), ++ .priv_data_size = sizeof(AppleHTTPContext), ++ .read_probe = applehttp_probe, ++ .read_header = applehttp_read_header, ++ .read_packet = applehttp_read_packet, ++ .read_close = applehttp_close, ++ .read_seek = applehttp_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/applehttpproto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/applehttpproto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/applehttpproto.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/applehttpproto.c 2012-05-14 14:08:54.875350870 +0200 +@@ -0,0 +1,313 @@ ++/* ++ * Apple HTTP Live Streaming Protocol Handler ++ * Copyright (c) 2010 Martin Storsjo ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Apple HTTP Live Streaming Protocol Handler ++ * http://tools.ietf.org/html/draft-pantos-http-live-streaming ++ */ ++ ++#include "libavutil/avstring.h" ++#include "avformat.h" ++#include "internal.h" ++#include "url.h" ++#include ++ ++/* ++ * An apple http stream consists of a playlist with media segment files, ++ * played sequentially. There may be several playlists with the same ++ * video content, in different bandwidth variants, that are played in ++ * parallel (preferrably only one bandwidth variant at a time). In this case, ++ * the user supplied the url to a main playlist that only lists the variant ++ * playlists. ++ * ++ * If the main playlist doesn't point at any variants, we still create ++ * one anonymous toplevel variant for this, to maintain the structure. ++ */ ++ ++struct segment { ++ int duration; ++ char url[MAX_URL_SIZE]; ++}; ++ ++struct variant { ++ int bandwidth; ++ char url[MAX_URL_SIZE]; ++}; ++ ++typedef struct AppleHTTPContext { ++ char playlisturl[MAX_URL_SIZE]; ++ int target_duration; ++ int start_seq_no; ++ int finished; ++ int n_segments; ++ struct segment **segments; ++ int n_variants; ++ struct variant **variants; ++ int cur_seq_no; ++ URLContext *seg_hd; ++ int64_t last_load_time; ++} AppleHTTPContext; ++ ++static int read_chomp_line(AVIOContext *s, char *buf, int maxlen) ++{ ++ int len = ff_get_line(s, buf, maxlen); ++ while (len > 0 && isspace(buf[len - 1])) ++ buf[--len] = '\0'; ++ return len; ++} ++ ++static void free_segment_list(AppleHTTPContext *s) ++{ ++ int i; ++ for (i = 0; i < s->n_segments; i++) ++ av_free(s->segments[i]); ++ av_freep(&s->segments); ++ s->n_segments = 0; ++} ++ ++static void free_variant_list(AppleHTTPContext *s) ++{ ++ int i; ++ for (i = 0; i < s->n_variants; i++) ++ av_free(s->variants[i]); ++ av_freep(&s->variants); ++ s->n_variants = 0; ++} ++ ++struct variant_info { ++ char bandwidth[20]; ++}; ++ ++static void handle_variant_args(struct variant_info *info, const char *key, ++ int key_len, char **dest, int *dest_len) ++{ ++ if (!strncmp(key, "BANDWIDTH=", key_len)) { ++ *dest = info->bandwidth; ++ *dest_len = sizeof(info->bandwidth); ++ } ++} ++ ++static int parse_playlist(URLContext *h, const char *url) ++{ ++ AppleHTTPContext *s = h->priv_data; ++ AVIOContext *in; ++ int ret = 0, duration = 0, is_segment = 0, is_variant = 0, bandwidth = 0; ++ char line[1024]; ++ const char *ptr; ++ ++ if ((ret = avio_open2(&in, url, AVIO_FLAG_READ, ++ &h->interrupt_callback, NULL)) < 0) ++ return ret; ++ ++ read_chomp_line(in, line, sizeof(line)); ++ if (strcmp(line, "#EXTM3U")) ++ return AVERROR_INVALIDDATA; ++ ++ free_segment_list(s); ++ s->finished = 0; ++ while (!url_feof(in)) { ++ read_chomp_line(in, line, sizeof(line)); ++ if (av_strstart(line, "#EXT-X-STREAM-INF:", &ptr)) { ++ struct variant_info info = {{0}}; ++ is_variant = 1; ++ ff_parse_key_value(ptr, (ff_parse_key_val_cb) handle_variant_args, ++ &info); ++ bandwidth = atoi(info.bandwidth); ++ } else if (av_strstart(line, "#EXT-X-TARGETDURATION:", &ptr)) { ++ s->target_duration = atoi(ptr); ++ } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) { ++ s->start_seq_no = atoi(ptr); ++ } else if (av_strstart(line, "#EXT-X-ENDLIST", &ptr)) { ++ s->finished = 1; ++ } else if (av_strstart(line, "#EXTINF:", &ptr)) { ++ is_segment = 1; ++ duration = atoi(ptr); ++ } else if (av_strstart(line, "#", NULL)) { ++ continue; ++ } else if (line[0]) { ++ if (is_segment) { ++ struct segment *seg = av_malloc(sizeof(struct segment)); ++ if (!seg) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ seg->duration = duration; ++ ff_make_absolute_url(seg->url, sizeof(seg->url), url, line); ++ dynarray_add(&s->segments, &s->n_segments, seg); ++ is_segment = 0; ++ } else if (is_variant) { ++ struct variant *var = av_malloc(sizeof(struct variant)); ++ if (!var) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ var->bandwidth = bandwidth; ++ ff_make_absolute_url(var->url, sizeof(var->url), url, line); ++ dynarray_add(&s->variants, &s->n_variants, var); ++ is_variant = 0; ++ } ++ } ++ } ++ s->last_load_time = av_gettime(); ++ ++fail: ++ avio_close(in); ++ return ret; ++} ++ ++static int applehttp_close(URLContext *h) ++{ ++ AppleHTTPContext *s = h->priv_data; ++ ++ free_segment_list(s); ++ free_variant_list(s); ++ ffurl_close(s->seg_hd); ++ return 0; ++} ++ ++static int applehttp_open(URLContext *h, const char *uri, int flags) ++{ ++ AppleHTTPContext *s = h->priv_data; ++ int ret, i; ++ const char *nested_url; ++ ++ if (flags & AVIO_FLAG_WRITE) ++ return AVERROR(ENOSYS); ++ ++ h->is_streamed = 1; ++ ++ if (av_strstart(uri, "applehttp+", &nested_url)) { ++ av_strlcpy(s->playlisturl, nested_url, sizeof(s->playlisturl)); ++ } else if (av_strstart(uri, "applehttp://", &nested_url)) { ++ av_strlcpy(s->playlisturl, "http://", sizeof(s->playlisturl)); ++ av_strlcat(s->playlisturl, nested_url, sizeof(s->playlisturl)); ++ } else { ++ av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ if ((ret = parse_playlist(h, s->playlisturl)) < 0) ++ goto fail; ++ ++ if (s->n_segments == 0 && s->n_variants > 0) { ++ int max_bandwidth = 0, maxvar = -1; ++ for (i = 0; i < s->n_variants; i++) { ++ if (s->variants[i]->bandwidth > max_bandwidth || i == 0) { ++ max_bandwidth = s->variants[i]->bandwidth; ++ maxvar = i; ++ } ++ } ++ av_strlcpy(s->playlisturl, s->variants[maxvar]->url, ++ sizeof(s->playlisturl)); ++ if ((ret = parse_playlist(h, s->playlisturl)) < 0) ++ goto fail; ++ } ++ ++ if (s->n_segments == 0) { ++ av_log(h, AV_LOG_WARNING, "Empty playlist\n"); ++ ret = AVERROR(EIO); ++ goto fail; ++ } ++ s->cur_seq_no = s->start_seq_no; ++ if (!s->finished && s->n_segments >= 3) ++ s->cur_seq_no = s->start_seq_no + s->n_segments - 3; ++ ++ return 0; ++ ++fail: ++ applehttp_close(h); ++ return ret; ++} ++ ++static int applehttp_read(URLContext *h, uint8_t *buf, int size) ++{ ++ AppleHTTPContext *s = h->priv_data; ++ const char *url; ++ int ret; ++ int64_t reload_interval; ++ ++start: ++ if (s->seg_hd) { ++ ret = ffurl_read(s->seg_hd, buf, size); ++ if (ret > 0) ++ return ret; ++ } ++ if (s->seg_hd) { ++ ffurl_close(s->seg_hd); ++ s->seg_hd = NULL; ++ s->cur_seq_no++; ++ } ++ reload_interval = s->n_segments > 0 ? ++ s->segments[s->n_segments - 1]->duration : ++ s->target_duration; ++ reload_interval *= 1000000; ++retry: ++ if (!s->finished) { ++ int64_t now = av_gettime(); ++ if (now - s->last_load_time >= reload_interval) { ++ if ((ret = parse_playlist(h, s->playlisturl)) < 0) ++ return ret; ++ /* If we need to reload the playlist again below (if ++ * there's still no more segments), switch to a reload ++ * interval of half the target duration. */ ++ reload_interval = s->target_duration * 500000; ++ } ++ } ++ if (s->cur_seq_no < s->start_seq_no) { ++ av_log(h, AV_LOG_WARNING, ++ "skipping %d segments ahead, expired from playlist\n", ++ s->start_seq_no - s->cur_seq_no); ++ s->cur_seq_no = s->start_seq_no; ++ } ++ if (s->cur_seq_no - s->start_seq_no >= s->n_segments) { ++ if (s->finished) ++ return AVERROR_EOF; ++ while (av_gettime() - s->last_load_time < reload_interval) { ++ if (ff_check_interrupt(&h->interrupt_callback)) ++ return AVERROR_EXIT; ++ usleep(100*1000); ++ } ++ goto retry; ++ } ++ url = s->segments[s->cur_seq_no - s->start_seq_no]->url, ++ av_log(h, AV_LOG_DEBUG, "opening %s\n", url); ++ ret = ffurl_open(&s->seg_hd, url, AVIO_FLAG_READ, ++ &h->interrupt_callback, NULL); ++ if (ret < 0) { ++ if (ff_check_interrupt(&h->interrupt_callback)) ++ return AVERROR_EXIT; ++ av_log(h, AV_LOG_WARNING, "Unable to open %s\n", url); ++ s->cur_seq_no++; ++ goto retry; ++ } ++ goto start; ++} ++ ++URLProtocol ff_applehttp_protocol = { ++ .name = "applehttp", ++ .url_open = applehttp_open, ++ .url_read = applehttp_read, ++ .url_close = applehttp_close, ++ .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, ++ .priv_data_size = sizeof(AppleHTTPContext), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asf.c 2012-05-14 14:08:54.876350890 +0200 +@@ -152,7 +152,6 @@ + { "WM/Publisher" , "publisher" }, + { "WM/Tool" , "encoder" }, + { "WM/TrackNumber" , "track" }, +- { "WM/Track" , "track" }, + { "WM/MediaStationCallSign", "service_provider" }, + { "WM/MediaStationName", "service_name" }, + // { "Year" , "date" }, TODO: conversion year<->date +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfcrypt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfcrypt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfcrypt.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfcrypt.c 2012-05-14 14:08:54.877350910 +0200 +@@ -28,9 +28,9 @@ + #include "asfcrypt.h" + + /** +- * \brief find multiplicative inverse modulo 2 ^ 32 +- * \param v number to invert, must be odd! +- * \return number so that result * v = 1 (mod 2^32) ++ * @brief find multiplicative inverse modulo 2 ^ 32 ++ * @param v number to invert, must be odd! ++ * @return number so that result * v = 1 (mod 2^32) + */ + static uint32_t inverse(uint32_t v) { + // v ^ 3 gives the inverse (mod 16), could also be implemented +@@ -45,9 +45,9 @@ + } + + /** +- * \brief read keys from keybuf into keys +- * \param keybuf buffer containing the keys +- * \param keys output key array containing the keys for encryption in ++ * @brief read keys from keybuf into keys ++ * @param keybuf buffer containing the keys ++ * @param keys output key array containing the keys for encryption in + * native endianness + */ + static void multiswap_init(const uint8_t keybuf[48], uint32_t keys[12]) { +@@ -57,9 +57,9 @@ + } + + /** +- * \brief invert the keys so that encryption become decryption keys and ++ * @brief invert the keys so that encryption become decryption keys and + * the other way round. +- * \param keys key array of ints to invert ++ * @param keys key array of ints to invert + */ + static void multiswap_invert_keys(uint32_t keys[12]) { + int i; +@@ -92,12 +92,12 @@ + } + + /** +- * \brief "MultiSwap" encryption +- * \param keys 32 bit numbers in machine endianness, ++ * @brief "MultiSwap" encryption ++ * @param keys 32 bit numbers in machine endianness, + * 0-4 and 6-10 must be inverted from decryption +- * \param key another key, this one must be the same for the decryption +- * \param data data to encrypt +- * \return encrypted data ++ * @param key another key, this one must be the same for the decryption ++ * @param data data to encrypt ++ * @return encrypted data + */ + static uint64_t multiswap_enc(const uint32_t keys[12], uint64_t key, uint64_t data) { + uint32_t a = data; +@@ -114,12 +114,12 @@ + } + + /** +- * \brief "MultiSwap" decryption +- * \param keys 32 bit numbers in machine endianness, ++ * @brief "MultiSwap" decryption ++ * @param keys 32 bit numbers in machine endianness, + * 0-4 and 6-10 must be inverted from encryption +- * \param key another key, this one must be the same as for the encryption +- * \param data data to decrypt +- * \return decrypted data ++ * @param key another key, this one must be the same as for the encryption ++ * @param data data to decrypt ++ * @return decrypted data + */ + static uint64_t multiswap_dec(const uint32_t keys[12], uint64_t key, uint64_t data) { + uint32_t a; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfdec.c 2012-05-14 14:08:54.882351011 +0200 +@@ -21,16 +21,59 @@ + + //#define DEBUG + ++#include "libavutil/bswap.h" + #include "libavutil/common.h" + #include "libavutil/avstring.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "libavcodec/mpegaudio.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "riff.h" + #include "asf.h" + #include "asfcrypt.h" + #include "avlanguage.h" + +-void ff_mms_set_stream_selection(URLContext *h, AVFormatContext *format); ++typedef struct { ++ int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID ++ ASFStream streams[128]; ///< it's max number and it's not that big ++ uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming) ++ AVRational dar[128]; ++ char stream_languages[128][6]; ///< max number of streams, language for each (RFC1766, e.g. en-US) ++ /* non streamed additonnal info */ ++ /* packet filling */ ++ int packet_size_left; ++ /* only for reading */ ++ uint64_t data_offset; ///< beginning of the first data packet ++ uint64_t data_object_offset; ///< data object offset (excl. GUID & size) ++ uint64_t data_object_size; ///< size of the data object ++ int index_read; ++ ++ ASFMainHeader hdr; ++ ++ int packet_flags; ++ int packet_property; ++ int packet_timestamp; ++ int packet_segsizetype; ++ int packet_segments; ++ int packet_seq; ++ int packet_replic_size; ++ int packet_key_frame; ++ int packet_padsize; ++ unsigned int packet_frag_offset; ++ unsigned int packet_frag_size; ++ int64_t packet_frag_timestamp; ++ int packet_multi_size; ++ int packet_obj_size; ++ int packet_time_delta; ++ int packet_time_start; ++ int64_t packet_pos; ++ ++ int stream_index; ++ ++ ASFStream* asf_st; ///< currently decoded stream ++} ASFContext; + + #undef NDEBUG + #include +@@ -43,18 +86,11 @@ + 0x90, 0x08, 0x00, 0x33, 0xb1, 0xe5, 0xcf, 0x11, 0x89, 0xf4, 0x00, 0xa0, 0xc9, 0x03, 0x49, 0xcb + }; + ++#ifdef DEBUG + static const ff_asf_guid stream_bitrate_guid = { /* (http://get.to/sdp) */ + 0xce, 0x75, 0xf8, 0x7b, 0x8d, 0x46, 0xd1, 0x11, 0x8d, 0x82, 0x00, 0x60, 0x97, 0xc9, 0xa2, 0xb2 + }; +-/**********************************/ +-/* decoding */ +- +-int ff_guidcmp(const void *g1, const void *g2) +-{ +- return memcmp(g1, g2, sizeof(ff_asf_guid)); +-} + +-#ifdef DEBUG + #define PRINT_IF_GUID(g,cmp) \ + if (!ff_guidcmp(g, &cmp)) \ + av_dlog(NULL, "(GUID: %s) ", #cmp) +@@ -97,12 +133,6 @@ + #define print_guid(g) + #endif + +-void ff_get_guid(ByteIOContext *s, ff_asf_guid *g) +-{ +- assert(sizeof(*g) == 16); +- get_buffer(s, *g, sizeof(*g)); +-} +- + static int asf_probe(AVProbeData *pd) + { + /* check file header */ +@@ -112,12 +142,12 @@ + return 0; + } + +-static int get_value(ByteIOContext *pb, int type){ ++static int get_value(AVIOContext *pb, int type){ + switch(type){ +- case 2: return get_le32(pb); +- case 3: return get_le32(pb); +- case 4: return get_le64(pb); +- case 5: return get_le16(pb); ++ case 2: return avio_rl32(pb); ++ case 3: return avio_rl32(pb); ++ case 4: return avio_rl64(pb); ++ case 5: return avio_rl16(pb); + default:return INT_MIN; + } + } +@@ -125,7 +155,7 @@ + static void get_tag(AVFormatContext *s, const char *key, int type, int len) + { + char *value; +- int64_t off = url_ftell(s->pb); ++ int64_t off = avio_tell(s->pb); + + if ((unsigned)len >= (UINT_MAX - 1)/2) + return; +@@ -136,6 +166,9 @@ + + if (type == 0) { // UTF16-LE + avio_get_str16le(s->pb, len, value, 2*len + 1); ++ } else if (type == -1) { // ASCII ++ avio_read(s->pb, value, len); ++ value[len]=0; + } else if (type > 1 && type <= 5) { // boolean or DWORD or QWORD or WORD + uint64_t num = get_value(s->pb, type); + snprintf(value, len, "%"PRIu64, num); +@@ -143,45 +176,433 @@ + av_log(s, AV_LOG_DEBUG, "Unsupported value type %d in tag %s.\n", type, key); + goto finish; + } +- av_metadata_set2(&s->metadata, key, value, 0); ++ if (*value) ++ av_dict_set(&s->metadata, key, value, 0); + finish: + av_freep(&value); +- url_fseek(s->pb, off + len, SEEK_SET); ++ avio_seek(s->pb, off + len, SEEK_SET); + } + +-static int asf_read_header(AVFormatContext *s, AVFormatParameters *ap) ++static int asf_read_file_properties(AVFormatContext *s, int64_t size) + { + ASFContext *asf = s->priv_data; +- ff_asf_guid g; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; ++ ++ ff_get_guid(pb, &asf->hdr.guid); ++ asf->hdr.file_size = avio_rl64(pb); ++ asf->hdr.create_time = avio_rl64(pb); ++ avio_rl64(pb); /* number of packets */ ++ asf->hdr.play_time = avio_rl64(pb); ++ asf->hdr.send_time = avio_rl64(pb); ++ asf->hdr.preroll = avio_rl32(pb); ++ asf->hdr.ignore = avio_rl32(pb); ++ asf->hdr.flags = avio_rl32(pb); ++ asf->hdr.min_pktsize = avio_rl32(pb); ++ asf->hdr.max_pktsize = avio_rl32(pb); ++ if (asf->hdr.min_pktsize >= (1U<<29)) ++ return AVERROR_INVALIDDATA; ++ asf->hdr.max_bitrate = avio_rl32(pb); ++ s->packet_size = asf->hdr.max_pktsize; ++ ++ return 0; ++} ++ ++static int asf_read_stream_properties(AVFormatContext *s, int64_t size) ++{ ++ ASFContext *asf = s->priv_data; ++ AVIOContext *pb = s->pb; + AVStream *st; + ASFStream *asf_st; +- int size, i; +- int64_t gsize; +- AVRational dar[128]; +- uint32_t bitrate[128]; ++ ff_asf_guid g; ++ enum AVMediaType type; ++ int type_specific_size, sizeX; ++ unsigned int tag1; ++ int64_t pos1, pos2, start_time; ++ int test_for_ext_stream_audio, is_dvr_ms_audio=0; ++ ++ if (s->nb_streams == ASF_MAX_STREAMS) { ++ av_log(s, AV_LOG_ERROR, "too many streams\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ pos1 = avio_tell(pb); ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ ++ asf_st = av_mallocz(sizeof(ASFStream)); ++ if (!asf_st) ++ return AVERROR(ENOMEM); ++ st->priv_data = asf_st; ++ start_time = asf->hdr.preroll; ++ ++ asf_st->stream_language_index = 128; // invalid stream index means no language info ++ ++ if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming... ++ st->duration = asf->hdr.play_time / ++ (10000000 / 1000) - start_time; ++ } ++ ff_get_guid(pb, &g); ++ ++ test_for_ext_stream_audio = 0; ++ if (!ff_guidcmp(&g, &ff_asf_audio_stream)) { ++ type = AVMEDIA_TYPE_AUDIO; ++ } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) { ++ type = AVMEDIA_TYPE_VIDEO; ++ } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) { ++ type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_MJPEG; ++ } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) { ++ type = AVMEDIA_TYPE_DATA; ++ } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) { ++ test_for_ext_stream_audio = 1; ++ type = AVMEDIA_TYPE_UNKNOWN; ++ } else { ++ return -1; ++ } ++ ff_get_guid(pb, &g); ++ avio_skip(pb, 8); /* total_size */ ++ type_specific_size = avio_rl32(pb); ++ avio_rl32(pb); ++ st->id = avio_rl16(pb) & 0x7f; /* stream id */ ++ // mapping of asf ID to AV stream ID; ++ asf->asfid2avid[st->id] = s->nb_streams - 1; ++ ++ avio_rl32(pb); ++ ++ if (test_for_ext_stream_audio) { ++ ff_get_guid(pb, &g); ++ if (!ff_guidcmp(&g, &ff_asf_ext_stream_audio_stream)) { ++ type = AVMEDIA_TYPE_AUDIO; ++ is_dvr_ms_audio=1; ++ ff_get_guid(pb, &g); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ ff_get_guid(pb, &g); ++ avio_rl32(pb); ++ } ++ } ++ ++ st->codec->codec_type = type; ++ if (type == AVMEDIA_TYPE_AUDIO) { ++ int ret = ff_get_wav_header(pb, st->codec, type_specific_size); ++ if (ret < 0) ++ return ret; ++ if (is_dvr_ms_audio) { ++ // codec_id and codec_tag are unreliable in dvr_ms ++ // files. Set them later by probing stream. ++ st->request_probe= 1; ++ st->codec->codec_tag = 0; ++ } ++ if (st->codec->codec_id == CODEC_ID_AAC) { ++ st->need_parsing = AVSTREAM_PARSE_NONE; ++ } else { ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ } ++ /* We have to init the frame size at some point .... */ ++ pos2 = avio_tell(pb); ++ if (size >= (pos2 + 8 - pos1 + 24)) { ++ asf_st->ds_span = avio_r8(pb); ++ asf_st->ds_packet_size = avio_rl16(pb); ++ asf_st->ds_chunk_size = avio_rl16(pb); ++ avio_rl16(pb); //ds_data_size ++ avio_r8(pb); //ds_silence_data ++ } ++ //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n", ++ // asf_st->ds_packet_size, asf_st->ds_chunk_size, ++ // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data); ++ if (asf_st->ds_span > 1) { ++ if (!asf_st->ds_chunk_size ++ || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1) ++ || asf_st->ds_packet_size % asf_st->ds_chunk_size) ++ asf_st->ds_span = 0; // disable descrambling ++ } ++ switch (st->codec->codec_id) { ++ case CODEC_ID_MP3: ++ st->codec->frame_size = MPA_FRAME_SIZE; ++ break; ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S16BE: ++ case CODEC_ID_PCM_U16LE: ++ case CODEC_ID_PCM_U16BE: ++ case CODEC_ID_PCM_S8: ++ case CODEC_ID_PCM_U8: ++ case CODEC_ID_PCM_ALAW: ++ case CODEC_ID_PCM_MULAW: ++ st->codec->frame_size = 1; ++ break; ++ default: ++ /* This is probably wrong, but it prevents a crash later */ ++ st->codec->frame_size = 1; ++ break; ++ } ++ } else if (type == AVMEDIA_TYPE_VIDEO && ++ size - (avio_tell(pb) - pos1 + 24) >= 51) { ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_r8(pb); ++ avio_rl16(pb); /* size */ ++ sizeX= avio_rl32(pb); /* size */ ++ st->codec->width = avio_rl32(pb); ++ st->codec->height = avio_rl32(pb); ++ /* not available for asf */ ++ avio_rl16(pb); /* panes */ ++ st->codec->bits_per_coded_sample = avio_rl16(pb); /* depth */ ++ tag1 = avio_rl32(pb); ++ avio_skip(pb, 20); ++ // av_log(s, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX); ++ if (sizeX > 40) { ++ st->codec->extradata_size = sizeX - 40; ++ st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ avio_read(pb, st->codec->extradata, st->codec->extradata_size); ++ } ++ ++ /* Extract palette from extradata if bpp <= 8 */ ++ /* This code assumes that extradata contains only palette */ ++ /* This is true for all paletted codecs implemented in libavcodec */ ++ if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { ++ int av_unused i; ++#if HAVE_BIGENDIAN ++ for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++) ++ asf_st->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); ++#else ++ memcpy(asf_st->palette, st->codec->extradata, ++ FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); ++#endif ++ asf_st->palette_changed = 1; ++ } ++ ++ st->codec->codec_tag = tag1; ++ st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); ++ if(tag1 == MKTAG('D', 'V', 'R', ' ')){ ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ // issue658 containse wrong w/h and MS even puts a fake seq header with wrong w/h in extradata while a correct one is in te stream. maximum lameness ++ st->codec->width = ++ st->codec->height = 0; ++ av_freep(&st->codec->extradata); ++ st->codec->extradata_size=0; ++ } ++ if(st->codec->codec_id == CODEC_ID_H264) ++ st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; ++ } ++ pos2 = avio_tell(pb); ++ avio_skip(pb, size - (pos2 - pos1 + 24)); ++ ++ return 0; ++} ++ ++static int asf_read_ext_stream_properties(AVFormatContext *s, int64_t size) ++{ ++ ASFContext *asf = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ff_asf_guid g; ++ int ext_len, payload_ext_ct, stream_ct, i; ++ uint32_t leak_rate, stream_num; ++ unsigned int stream_languageid_index; ++ ++ avio_rl64(pb); // starttime ++ avio_rl64(pb); // endtime ++ leak_rate = avio_rl32(pb); // leak-datarate ++ avio_rl32(pb); // bucket-datasize ++ avio_rl32(pb); // init-bucket-fullness ++ avio_rl32(pb); // alt-leak-datarate ++ avio_rl32(pb); // alt-bucket-datasize ++ avio_rl32(pb); // alt-init-bucket-fullness ++ avio_rl32(pb); // max-object-size ++ avio_rl32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved) ++ stream_num = avio_rl16(pb); // stream-num ++ ++ stream_languageid_index = avio_rl16(pb); // stream-language-id-index ++ if (stream_num < 128) ++ asf->streams[stream_num].stream_language_index = stream_languageid_index; ++ ++ avio_rl64(pb); // avg frametime in 100ns units ++ stream_ct = avio_rl16(pb); //stream-name-count ++ payload_ext_ct = avio_rl16(pb); //payload-extension-system-count ++ ++ if (stream_num < 128) ++ asf->stream_bitrates[stream_num] = leak_rate; ++ ++ for (i=0; ipb; ++ int len1, len2, len3, len4, len5; ++ ++ len1 = avio_rl16(pb); ++ len2 = avio_rl16(pb); ++ len3 = avio_rl16(pb); ++ len4 = avio_rl16(pb); ++ len5 = avio_rl16(pb); ++ get_tag(s, "title" , 0, len1); ++ get_tag(s, "author" , 0, len2); ++ get_tag(s, "copyright", 0, len3); ++ get_tag(s, "comment" , 0, len4); ++ avio_skip(pb, len5); ++ ++ return 0; ++} ++ ++static int asf_read_ext_content_desc(AVFormatContext *s, int64_t size) ++{ ++ AVIOContext *pb = s->pb; ++ ASFContext *asf = s->priv_data; ++ int desc_count, i, ret; ++ ++ desc_count = avio_rl16(pb); ++ for(i=0;idar[0].num= get_value(s->pb, value_type); ++ } else if(!strcmp(name, "AspectRatioY")){ ++ asf->dar[0].den= get_value(s->pb, value_type); ++ } else ++ get_tag(s, name, value_type, value_len); ++ } ++ ++ return 0; ++} ++ ++static int asf_read_language_list(AVFormatContext *s, int64_t size) ++{ ++ AVIOContext *pb = s->pb; ++ ASFContext *asf = s->priv_data; ++ int j, ret; ++ int stream_count = avio_rl16(pb); ++ for(j = 0; j < stream_count; j++) { ++ char lang[6]; ++ unsigned int lang_len = avio_r8(pb); ++ if ((ret = avio_get_str16le(pb, lang_len, lang, sizeof(lang))) < lang_len) ++ avio_skip(pb, lang_len - ret); ++ if (j < 128) ++ av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages)); ++ } ++ ++ return 0; ++} ++ ++static int asf_read_metadata(AVFormatContext *s, int64_t size) ++{ ++ AVIOContext *pb = s->pb; ++ ASFContext *asf = s->priv_data; ++ int n, stream_num, name_len, value_len, value_num; ++ int ret, i; ++ n = avio_rl16(pb); ++ ++ for(i=0;i\n", i, stream_num, name_len, value_type, value_len, name); ++ value_num= avio_rl16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere ++ avio_skip(pb, value_len - 2); ++ ++ if(stream_num<128){ ++ if (!strcmp(name, "AspectRatioX")) asf->dar[stream_num].num= value_num; ++ else if(!strcmp(name, "AspectRatioY")) asf->dar[stream_num].den= value_num; ++ } ++ } ++ ++ return 0; ++} ++ ++static int asf_read_marker(AVFormatContext *s, int64_t size) ++{ ++ AVIOContext *pb = s->pb; ++ int i, count, name_len, ret; ++ char name[1024]; ++ ++ avio_rl64(pb); // reserved 16 bytes ++ avio_rl64(pb); // ... ++ count = avio_rl32(pb); // markers count ++ avio_rl16(pb); // reserved 2 bytes ++ name_len = avio_rl16(pb); // name length ++ for(i=0;ipriv_data; ++ ff_asf_guid g; ++ AVIOContext *pb = s->pb; ++ int i; ++ int64_t gsize; + + ff_get_guid(pb, &g); + if (ff_guidcmp(&g, &ff_asf_header)) + return -1; +- get_le64(pb); +- get_le32(pb); +- get_byte(pb); +- get_byte(pb); ++ avio_rl64(pb); ++ avio_rl32(pb); ++ avio_r8(pb); ++ avio_r8(pb); + memset(&asf->asfid2avid, -1, sizeof(asf->asfid2avid)); + for(;;) { +- uint64_t gpos= url_ftell(pb); +- int ret; ++ uint64_t gpos= avio_tell(pb); + ff_get_guid(pb, &g); +- gsize = get_le64(pb); ++ gsize = avio_rl64(pb); + av_dlog(s, "%08"PRIx64": ", gpos); + print_guid(&g); + av_dlog(s, " size=0x%"PRIx64"\n", gsize); + if (!ff_guidcmp(&g, &ff_asf_data_header)) { +- asf->data_object_offset = url_ftell(pb); ++ asf->data_object_offset = avio_tell(pb); + // if not streaming, gsize is not unlimited (how?), and there is enough space in the file.. + if (!(asf->hdr.flags & 0x01) && gsize >= 100) { + asf->data_object_size = gsize - 24; +@@ -193,387 +614,67 @@ + if (gsize < 24) + return -1; + if (!ff_guidcmp(&g, &ff_asf_file_header)) { +- ff_get_guid(pb, &asf->hdr.guid); +- asf->hdr.file_size = get_le64(pb); +- asf->hdr.create_time = get_le64(pb); +- asf->nb_packets = get_le64(pb); +- asf->hdr.play_time = get_le64(pb); +- asf->hdr.send_time = get_le64(pb); +- asf->hdr.preroll = get_le32(pb); +- asf->hdr.ignore = get_le32(pb); +- asf->hdr.flags = get_le32(pb); +- asf->hdr.min_pktsize = get_le32(pb); +- asf->hdr.max_pktsize = get_le32(pb); +- asf->hdr.max_bitrate = get_le32(pb); +- s->packet_size = asf->hdr.max_pktsize; ++ int ret = asf_read_file_properties(s, gsize); ++ if (ret < 0) ++ return ret; + } else if (!ff_guidcmp(&g, &ff_asf_stream_header)) { +- enum AVMediaType type; +- int type_specific_size, sizeX; +- uint64_t total_size; +- unsigned int tag1; +- int64_t pos1, pos2, start_time; +- int test_for_ext_stream_audio, is_dvr_ms_audio=0; +- +- if (s->nb_streams == ASF_MAX_STREAMS) { +- av_log(s, AV_LOG_ERROR, "too many streams\n"); +- return AVERROR(EINVAL); +- } +- +- pos1 = url_ftell(pb); +- +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ +- asf_st = av_mallocz(sizeof(ASFStream)); +- if (!asf_st) +- return AVERROR(ENOMEM); +- st->priv_data = asf_st; +- start_time = asf->hdr.preroll; +- +- asf_st->stream_language_index = 128; // invalid stream index means no language info +- +- if(!(asf->hdr.flags & 0x01)) { // if we aren't streaming... +- st->duration = asf->hdr.play_time / +- (10000000 / 1000) - start_time; +- } +- ff_get_guid(pb, &g); +- +- test_for_ext_stream_audio = 0; +- if (!ff_guidcmp(&g, &ff_asf_audio_stream)) { +- type = AVMEDIA_TYPE_AUDIO; +- } else if (!ff_guidcmp(&g, &ff_asf_video_stream)) { +- type = AVMEDIA_TYPE_VIDEO; +- } else if (!ff_guidcmp(&g, &ff_asf_jfif_media)) { +- type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_id = CODEC_ID_MJPEG; +- } else if (!ff_guidcmp(&g, &ff_asf_command_stream)) { +- type = AVMEDIA_TYPE_DATA; +- } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_embed_stream_header)) { +- test_for_ext_stream_audio = 1; +- type = AVMEDIA_TYPE_UNKNOWN; +- } else { +- return -1; +- } +- ff_get_guid(pb, &g); +- total_size = get_le64(pb); +- type_specific_size = get_le32(pb); +- get_le32(pb); +- st->id = get_le16(pb) & 0x7f; /* stream id */ +- // mapping of asf ID to AV stream ID; +- asf->asfid2avid[st->id] = s->nb_streams - 1; +- +- get_le32(pb); +- +- if (test_for_ext_stream_audio) { +- ff_get_guid(pb, &g); +- if (!ff_guidcmp(&g, &ff_asf_ext_stream_audio_stream)) { +- type = AVMEDIA_TYPE_AUDIO; +- is_dvr_ms_audio=1; +- ff_get_guid(pb, &g); +- get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- ff_get_guid(pb, &g); +- get_le32(pb); +- } +- } +- +- st->codec->codec_type = type; +- if (type == AVMEDIA_TYPE_AUDIO) { +- ff_get_wav_header(pb, st->codec, type_specific_size); +- if (is_dvr_ms_audio) { +- // codec_id and codec_tag are unreliable in dvr_ms +- // files. Set them later by probing stream. +- st->codec->codec_id = CODEC_ID_PROBE; +- st->codec->codec_tag = 0; +- } +- if (st->codec->codec_id == CODEC_ID_AAC) { +- st->need_parsing = AVSTREAM_PARSE_NONE; +- } else { +- st->need_parsing = AVSTREAM_PARSE_FULL; +- } +- /* We have to init the frame size at some point .... */ +- pos2 = url_ftell(pb); +- if (gsize >= (pos2 + 8 - pos1 + 24)) { +- asf_st->ds_span = get_byte(pb); +- asf_st->ds_packet_size = get_le16(pb); +- asf_st->ds_chunk_size = get_le16(pb); +- get_le16(pb); //ds_data_size +- get_byte(pb); //ds_silence_data +- } +- //printf("Descrambling: ps:%d cs:%d ds:%d s:%d sd:%d\n", +- // asf_st->ds_packet_size, asf_st->ds_chunk_size, +- // asf_st->ds_data_size, asf_st->ds_span, asf_st->ds_silence_data); +- if (asf_st->ds_span > 1) { +- if (!asf_st->ds_chunk_size +- || (asf_st->ds_packet_size/asf_st->ds_chunk_size <= 1) +- || asf_st->ds_packet_size % asf_st->ds_chunk_size) +- asf_st->ds_span = 0; // disable descrambling +- } +- switch (st->codec->codec_id) { +- case CODEC_ID_MP3: +- st->codec->frame_size = MPA_FRAME_SIZE; +- break; +- case CODEC_ID_PCM_S16LE: +- case CODEC_ID_PCM_S16BE: +- case CODEC_ID_PCM_U16LE: +- case CODEC_ID_PCM_U16BE: +- case CODEC_ID_PCM_S8: +- case CODEC_ID_PCM_U8: +- case CODEC_ID_PCM_ALAW: +- case CODEC_ID_PCM_MULAW: +- st->codec->frame_size = 1; +- break; +- default: +- /* This is probably wrong, but it prevents a crash later */ +- st->codec->frame_size = 1; +- break; +- } +- } else if (type == AVMEDIA_TYPE_VIDEO && +- gsize - (url_ftell(pb) - pos1 + 24) >= 51) { +- get_le32(pb); +- get_le32(pb); +- get_byte(pb); +- size = get_le16(pb); /* size */ +- sizeX= get_le32(pb); /* size */ +- st->codec->width = get_le32(pb); +- st->codec->height = get_le32(pb); +- /* not available for asf */ +- get_le16(pb); /* panes */ +- st->codec->bits_per_coded_sample = get_le16(pb); /* depth */ +- tag1 = get_le32(pb); +- url_fskip(pb, 20); +-// av_log(s, AV_LOG_DEBUG, "size:%d tsize:%d sizeX:%d\n", size, total_size, sizeX); +- size= sizeX; +- if (size > 40) { +- st->codec->extradata_size = size - 40; +- st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- get_buffer(pb, st->codec->extradata, st->codec->extradata_size); +- } +- +- /* Extract palette from extradata if bpp <= 8 */ +- /* This code assumes that extradata contains only palette */ +- /* This is true for all paletted codecs implemented in ffmpeg */ +- if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { +- st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl)); +-#if HAVE_BIGENDIAN +- for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++) +- st->codec->palctrl->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); +-#else +- memcpy(st->codec->palctrl->palette, st->codec->extradata, +- FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); +-#endif +- st->codec->palctrl->palette_changed = 1; +- } +- +- st->codec->codec_tag = tag1; +- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, tag1); +- if(tag1 == MKTAG('D', 'V', 'R', ' ')){ +- st->need_parsing = AVSTREAM_PARSE_FULL; +- // issue658 containse wrong w/h and MS even puts a fake seq header with wrong w/h in extradata while a correct one is in te stream. maximum lameness +- st->codec->width = +- st->codec->height = 0; +- av_freep(&st->codec->extradata); +- st->codec->extradata_size=0; +- } +- if(st->codec->codec_id == CODEC_ID_H264) +- st->need_parsing = AVSTREAM_PARSE_FULL_ONCE; +- } +- pos2 = url_ftell(pb); +- url_fskip(pb, gsize - (pos2 - pos1 + 24)); ++ asf_read_stream_properties(s, gsize); + } else if (!ff_guidcmp(&g, &ff_asf_comment_header)) { +- int len1, len2, len3, len4, len5; +- +- len1 = get_le16(pb); +- len2 = get_le16(pb); +- len3 = get_le16(pb); +- len4 = get_le16(pb); +- len5 = get_le16(pb); +- get_tag(s, "title" , 0, len1); +- get_tag(s, "author" , 0, len2); +- get_tag(s, "copyright", 0, len3); +- get_tag(s, "comment" , 0, len4); +- url_fskip(pb, len5); +- } else if (!ff_guidcmp(&g, &stream_bitrate_guid)) { +- int stream_count = get_le16(pb); +- int j; +- +-// av_log(s, AV_LOG_ERROR, "stream bitrate properties\n"); +-// av_log(s, AV_LOG_ERROR, "streams %d\n", streams); +- for(j = 0; j < stream_count; j++) { +- int flags, bitrate, stream_id; +- +- flags= get_le16(pb); +- bitrate= get_le32(pb); +- stream_id= (flags & 0x7f); +-// av_log(s, AV_LOG_ERROR, "flags: 0x%x stream id %d, bitrate %d\n", flags, stream_id, bitrate); +- asf->stream_bitrates[stream_id]= bitrate; +- } ++ asf_read_content_desc(s, gsize); + } else if (!ff_guidcmp(&g, &ff_asf_language_guid)) { +- int j; +- int stream_count = get_le16(pb); +- for(j = 0; j < stream_count; j++) { +- char lang[6]; +- unsigned int lang_len = get_byte(pb); +- if ((ret = avio_get_str16le(pb, lang_len, lang, sizeof(lang))) < lang_len) +- url_fskip(pb, lang_len - ret); +- if (j < 128) +- av_strlcpy(asf->stream_languages[j], lang, sizeof(*asf->stream_languages)); +- } ++ asf_read_language_list(s, gsize); + } else if (!ff_guidcmp(&g, &ff_asf_extended_content_header)) { +- int desc_count, i; +- +- desc_count = get_le16(pb); +- for(i=0;ipb, value_type); +- } else if(!strcmp(name, "AspectRatioY")){ +- dar[0].den= get_value(s->pb, value_type); +- } else +- get_tag(s, name, value_type, value_len); +- } ++ asf_read_ext_content_desc(s, gsize); + } else if (!ff_guidcmp(&g, &ff_asf_metadata_header)) { +- int n, stream_num, name_len, value_len, value_type, value_num; +- n = get_le16(pb); +- +- for(i=0;i\n", i, stream_num, name_len, value_type, value_len, name); +- value_num= get_le16(pb);//we should use get_value() here but it does not work 2 is le16 here but le32 elsewhere +- url_fskip(pb, value_len - 2); +- +- if(stream_num<128){ +- if (!strcmp(name, "AspectRatioX")) dar[stream_num].num= value_num; +- else if(!strcmp(name, "AspectRatioY")) dar[stream_num].den= value_num; +- } +- } ++ asf_read_metadata(s, gsize); + } else if (!ff_guidcmp(&g, &ff_asf_ext_stream_header)) { +- int ext_len, payload_ext_ct, stream_ct; +- uint32_t ext_d, leak_rate, stream_num; +- unsigned int stream_languageid_index; +- +- get_le64(pb); // starttime +- get_le64(pb); // endtime +- leak_rate = get_le32(pb); // leak-datarate +- get_le32(pb); // bucket-datasize +- get_le32(pb); // init-bucket-fullness +- get_le32(pb); // alt-leak-datarate +- get_le32(pb); // alt-bucket-datasize +- get_le32(pb); // alt-init-bucket-fullness +- get_le32(pb); // max-object-size +- get_le32(pb); // flags (reliable,seekable,no_cleanpoints?,resend-live-cleanpoints, rest of bits reserved) +- stream_num = get_le16(pb); // stream-num +- +- stream_languageid_index = get_le16(pb); // stream-language-id-index +- if (stream_num < 128) +- asf->streams[stream_num].stream_language_index = stream_languageid_index; +- +- get_le64(pb); // avg frametime in 100ns units +- stream_ct = get_le16(pb); //stream-name-count +- payload_ext_ct = get_le16(pb); //payload-extension-system-count +- +- if (stream_num < 128) +- bitrate[stream_num] = leak_rate; +- +- for (i=0; ikeylen) { + if (!ff_guidcmp(&g, &ff_asf_content_encryption)) { ++ unsigned int len; ++ AVPacket pkt; + av_log(s, AV_LOG_WARNING, "DRM protected stream detected, decoding will likely fail!\n"); ++ len= avio_rl32(pb); ++ av_log(s, AV_LOG_DEBUG, "Secret data:\n"); ++ av_get_packet(pb, &pkt, len); av_hex_dump_log(s, AV_LOG_DEBUG, pkt.data, pkt.size); av_free_packet(&pkt); ++ len= avio_rl32(pb); ++ get_tag(s, "ASF_Protection_Type", -1, len); ++ len= avio_rl32(pb); ++ get_tag(s, "ASF_Key_ID", -1, len); ++ len= avio_rl32(pb); ++ get_tag(s, "ASF_License_URL", -1, len); + } else if (!ff_guidcmp(&g, &ff_asf_ext_content_encryption)) { + av_log(s, AV_LOG_WARNING, "Ext DRM protected stream detected, decoding will likely fail!\n"); ++ av_dict_set(&s->metadata, "encryption", "ASF Extended Content Encryption", 0); + } else if (!ff_guidcmp(&g, &ff_asf_digital_signature)) { +- av_log(s, AV_LOG_WARNING, "Digital signature detected, decoding will likely fail!\n"); ++ av_log(s, AV_LOG_INFO, "Digital signature detected!\n"); + } + } + } +- if(url_ftell(pb) != gpos + gsize) +- av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", url_ftell(pb)-gpos, gsize); +- url_fseek(pb, gpos + gsize, SEEK_SET); ++ if(avio_tell(pb) != gpos + gsize) ++ av_log(s, AV_LOG_DEBUG, "gpos mismatch our pos=%"PRIu64", end=%"PRIu64"\n", avio_tell(pb)-gpos, gsize); ++ avio_seek(pb, gpos + gsize, SEEK_SET); + } + ff_get_guid(pb, &g); +- get_le64(pb); +- get_byte(pb); +- get_byte(pb); ++ avio_rl64(pb); ++ avio_r8(pb); ++ avio_r8(pb); + if (url_feof(pb)) + return -1; +- asf->data_offset = url_ftell(pb); ++ asf->data_offset = avio_tell(pb); + asf->packet_size_left = 0; + + +@@ -582,15 +683,15 @@ + if(stream_num>=0){ + AVStream *st = s->streams[stream_num]; + if (!st->codec->bit_rate) +- st->codec->bit_rate = bitrate[i]; +- if (dar[i].num > 0 && dar[i].den > 0){ ++ st->codec->bit_rate = asf->stream_bitrates[i]; ++ if (asf->dar[i].num > 0 && asf->dar[i].den > 0){ + av_reduce(&st->sample_aspect_ratio.num, + &st->sample_aspect_ratio.den, +- dar[i].num, dar[i].den, INT_MAX); +- } else if ((dar[0].num > 0) && (dar[0].den > 0) && (st->codec->codec_type==AVMEDIA_TYPE_VIDEO)) // Use ASF container value if the stream doesn't AR set. ++ asf->dar[i].num, asf->dar[i].den, INT_MAX); ++ } else if ((asf->dar[0].num > 0) && (asf->dar[0].den > 0) && (st->codec->codec_type==AVMEDIA_TYPE_VIDEO)) // Use ASF container value if the stream doesn't AR set. + av_reduce(&st->sample_aspect_ratio.num, + &st->sample_aspect_ratio.den, +- dar[0].num, dar[0].den, INT_MAX); ++ asf->dar[0].num, asf->dar[0].den, INT_MAX); + + //av_log(s, AV_LOG_INFO, "i=%d, st->codec->codec_type:%d, dar %d:%d sar=%d:%d\n", i, st->codec->codec_type, dar[i].num, dar[i].den, st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); + +@@ -601,7 +702,7 @@ + const char primary_tag[3] = { rfc1766[0], rfc1766[1], '\0' }; // ignore country code if any + const char *iso6392 = av_convert_lang_to(primary_tag, AV_LANG_ISO639_2_BIBL); + if (iso6392) +- av_metadata_set2(&st->metadata, "language", iso6392, 0); ++ av_dict_set(&st->metadata, "language", iso6392, 0); + } + } + } +@@ -615,9 +716,9 @@ + #define DO_2BITS(bits, var, defval) \ + switch (bits & 3) \ + { \ +- case 3: var = get_le32(pb); rsize += 4; break; \ +- case 2: var = get_le16(pb); rsize += 2; break; \ +- case 1: var = get_byte(pb); rsize++; break; \ ++ case 3: var = avio_rl32(pb); rsize += 4; break; \ ++ case 2: var = avio_rl16(pb); rsize += 2; break; \ ++ case 1: var = avio_r8(pb); rsize++; break; \ + default: var = defval; break; \ + } + +@@ -627,7 +728,7 @@ + * @param pb context to read data from + * @return 0 on success, <0 on error + */ +-static int ff_asf_get_packet(AVFormatContext *s, ByteIOContext *pb) ++static int ff_asf_get_packet(AVFormatContext *s, AVIOContext *pb) + { + ASFContext *asf = s->priv_data; + uint32_t packet_length, padsize; +@@ -637,12 +738,12 @@ + // if we do not know packet size, allow skipping up to 32 kB + off= 32768; + if (s->packet_size > 0) +- off= (url_ftell(pb) - s->data_offset) % s->packet_size + 3; ++ off= (avio_tell(pb) - s->data_offset) % s->packet_size + 3; + + c=d=e=-1; + while(off-- > 0){ + c=d; d=e; +- e= get_byte(pb); ++ e= avio_r8(pb); + if(c == 0x82 && !d && !e) + break; + } +@@ -654,10 +755,10 @@ + * imply complete -EAGAIN handling support at random positions in + * the stream. + */ +- if (url_ferror(pb) == AVERROR(EAGAIN)) ++ if (pb->error == AVERROR(EAGAIN)) + return AVERROR(EAGAIN); + if (!url_feof(pb)) +- av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, url_ftell(pb)); ++ av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%"PRId64"\n", c, avio_tell(pb)); + } + if ((c & 0x8f) == 0x82) { + if (d || e) { +@@ -665,11 +766,11 @@ + av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n"); + return -1; + } +- c= get_byte(pb); +- d= get_byte(pb); ++ c= avio_r8(pb); ++ d= avio_r8(pb); + rsize+=3; +- }else{ +- url_fseek(pb, -1, SEEK_CUR); //FIXME ++ }else if(!url_feof(pb)){ ++ avio_seek(pb, -1, SEEK_CUR); //FIXME + } + + asf->packet_flags = c; +@@ -681,25 +782,32 @@ + + //the following checks prevent overflows and infinite loops + if(!packet_length || packet_length >= (1U<<29)){ +- av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, url_ftell(pb)); ++ av_log(s, AV_LOG_ERROR, "invalid packet_length %d at:%"PRId64"\n", packet_length, avio_tell(pb)); + return -1; + } + if(padsize >= packet_length){ +- av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, url_ftell(pb)); ++ av_log(s, AV_LOG_ERROR, "invalid padsize %d at:%"PRId64"\n", padsize, avio_tell(pb)); + return -1; + } + +- asf->packet_timestamp = get_le32(pb); +- get_le16(pb); /* duration */ ++ asf->packet_timestamp = avio_rl32(pb); ++ avio_rl16(pb); /* duration */ + // rsize has at least 11 bytes which have to be present + + if (asf->packet_flags & 0x01) { +- asf->packet_segsizetype = get_byte(pb); rsize++; ++ asf->packet_segsizetype = avio_r8(pb); rsize++; + asf->packet_segments = asf->packet_segsizetype & 0x3f; + } else { + asf->packet_segments = 1; + asf->packet_segsizetype = 0x80; + } ++ if (rsize > packet_length - padsize) { ++ asf->packet_size_left = 0; ++ av_log(s, AV_LOG_ERROR, ++ "invalid packet header length %d for pktlen %d-%d at %"PRId64"\n", ++ rsize, packet_length, padsize, avio_tell(pb)); ++ return -1; ++ } + asf->packet_size_left = packet_length - padsize - rsize; + if (packet_length < asf->hdr.min_pktsize) + padsize += asf->hdr.min_pktsize - packet_length; +@@ -712,11 +820,11 @@ + * + * @return <0 if error + */ +-static int asf_read_frame_header(AVFormatContext *s, ByteIOContext *pb){ ++static int asf_read_frame_header(AVFormatContext *s, AVIOContext *pb){ + ASFContext *asf = s->priv_data; + int rsize = 1; +- int num = get_byte(pb); +- int64_t ts0, ts1; ++ int num = avio_r8(pb); ++ int64_t ts0, ts1 av_unused; + + asf->packet_segments--; + asf->packet_key_frame = num >> 7; +@@ -726,27 +834,31 @@ + DO_2BITS(asf->packet_property >> 2, asf->packet_frag_offset, 0); + DO_2BITS(asf->packet_property, asf->packet_replic_size, 0); + //printf("key:%d stream:%d seq:%d offset:%d replic_size:%d\n", asf->packet_key_frame, asf->stream_index, asf->packet_seq, //asf->packet_frag_offset, asf->packet_replic_size); ++ if (rsize+asf->packet_replic_size > asf->packet_size_left) { ++ av_log(s, AV_LOG_ERROR, "packet_replic_size %d is invalid\n", asf->packet_replic_size); ++ return -1; ++ } + if (asf->packet_replic_size >= 8) { +- asf->packet_obj_size = get_le32(pb); ++ asf->packet_obj_size = avio_rl32(pb); + if(asf->packet_obj_size >= (1<<24) || asf->packet_obj_size <= 0){ + av_log(s, AV_LOG_ERROR, "packet_obj_size invalid\n"); + return -1; + } +- asf->packet_frag_timestamp = get_le32(pb); // timestamp ++ asf->packet_frag_timestamp = avio_rl32(pb); // timestamp + if(asf->packet_replic_size >= 8+38+4){ + // for(i=0; ipacket_replic_size-8; i++) +-// av_log(s, AV_LOG_DEBUG, "%02X ",get_byte(pb)); ++// av_log(s, AV_LOG_DEBUG, "%02X ",avio_r8(pb)); + // av_log(s, AV_LOG_DEBUG, "\n"); +- url_fskip(pb, 10); +- ts0= get_le64(pb); +- ts1= get_le64(pb); +- url_fskip(pb, 12); +- get_le32(pb); +- url_fskip(pb, asf->packet_replic_size - 8 - 38 - 4); ++ avio_skip(pb, 10); ++ ts0= avio_rl64(pb); ++ ts1= avio_rl64(pb); ++ avio_skip(pb, 12); ++ avio_rl32(pb); ++ avio_skip(pb, asf->packet_replic_size - 8 - 38 - 4); + if(ts0!= -1) asf->packet_frag_timestamp= ts0/10000; + else asf->packet_frag_timestamp= AV_NOPTS_VALUE; + }else +- url_fskip(pb, asf->packet_replic_size - 8); ++ avio_skip(pb, asf->packet_replic_size - 8); + rsize += asf->packet_replic_size; // FIXME - check validity + } else if (asf->packet_replic_size==1){ + // multipacket - frag_offset is beginning timestamp +@@ -754,7 +866,7 @@ + asf->packet_frag_offset = 0; + asf->packet_frag_timestamp = asf->packet_timestamp; + +- asf->packet_time_delta = get_byte(pb); ++ asf->packet_time_delta = avio_r8(pb); + rsize++; + }else if(asf->packet_replic_size!=0){ + av_log(s, AV_LOG_ERROR, "unexpected packet_replic_size of %d\n", asf->packet_replic_size); +@@ -762,9 +874,18 @@ + } + if (asf->packet_flags & 0x01) { + DO_2BITS(asf->packet_segsizetype >> 6, asf->packet_frag_size, 0); // 0 is illegal +- if(asf->packet_frag_size > asf->packet_size_left - rsize){ +- av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid\n"); ++ if (rsize > asf->packet_size_left) { ++ av_log(s, AV_LOG_ERROR, "packet_replic_size is invalid\n"); + return -1; ++ } else if(asf->packet_frag_size > asf->packet_size_left - rsize){ ++ if (asf->packet_frag_size > asf->packet_size_left - rsize + asf->packet_padsize) { ++ av_log(s, AV_LOG_ERROR, "packet_frag_size is invalid (%d-%d)\n", asf->packet_size_left, rsize); ++ return -1; ++ } else { ++ int diff = asf->packet_frag_size - (asf->packet_size_left - rsize); ++ asf->packet_size_left += diff; ++ asf->packet_padsize -= diff; ++ } + } + //printf("Fragsize %d\n", asf->packet_frag_size); + } else { +@@ -791,7 +912,7 @@ + * @return 0 if data was stored in pkt, <0 on error or 1 if more ASF + * packets need to be loaded (through asf_get_packet()) + */ +-static int ff_asf_parse_packet(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt) ++static int ff_asf_parse_packet(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) + { + ASFContext *asf = s->priv_data; + ASFStream *asf_st = 0; +@@ -803,12 +924,12 @@ + || asf->packet_segments < 1) { + //asf->packet_size_left <= asf->packet_padsize) { + int ret = asf->packet_size_left + asf->packet_padsize; +- //printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, url_ftell(pb)); ++ //printf("PacketLeftSize:%d Pad:%d Pos:%"PRId64"\n", asf->packet_size_left, asf->packet_padsize, avio_tell(pb)); + assert(ret>=0); + /* fail safe */ +- url_fskip(pb, ret); ++ avio_skip(pb, ret); + +- asf->packet_pos= url_ftell(pb); ++ asf->packet_pos= avio_tell(pb); + if (asf->data_object_size != (uint64_t)-1 && + (asf->packet_pos - asf->data_object_offset >= asf->data_object_size)) + return AVERROR_EOF; /* Do not exceed the size of the data object */ +@@ -825,7 +946,7 @@ + ) { + asf->packet_time_start = 0; + /* unhandled packet (should not happen) */ +- url_fskip(pb, asf->packet_frag_size); ++ avio_skip(pb, asf->packet_frag_size); + asf->packet_size_left -= asf->packet_frag_size; + if(asf->stream_index < 0) + av_log(s, AV_LOG_ERROR, "ff asf skip %d (unknown stream)\n", asf->packet_frag_size); +@@ -839,13 +960,13 @@ + // frag_offset is here used as the beginning timestamp + asf->packet_frag_timestamp = asf->packet_time_start; + asf->packet_time_start += asf->packet_time_delta; +- asf->packet_obj_size = asf->packet_frag_size = get_byte(pb); ++ asf->packet_obj_size = asf->packet_frag_size = avio_r8(pb); + asf->packet_size_left--; + asf->packet_multi_size--; + if (asf->packet_multi_size < asf->packet_obj_size) + { + asf->packet_time_start = 0; +- url_fskip(pb, asf->packet_multi_size); ++ avio_skip(pb, asf->packet_multi_size); + asf->packet_size_left -= asf->packet_multi_size; + continue; + } +@@ -871,10 +992,21 @@ + /* new packet */ + av_new_packet(&asf_st->pkt, asf->packet_obj_size); + asf_st->seq = asf->packet_seq; +- asf_st->pkt.dts = asf->packet_frag_timestamp; ++ asf_st->pkt.dts = asf->packet_frag_timestamp - asf->hdr.preroll; + asf_st->pkt.stream_index = asf->stream_index; + asf_st->pkt.pos = + asf_st->packet_pos= asf->packet_pos; ++ if (asf_st->pkt.data && asf_st->palette_changed) { ++ uint8_t *pal; ++ pal = av_packet_new_side_data(&asf_st->pkt, AV_PKT_DATA_PALETTE, ++ AVPALETTE_SIZE); ++ if (!pal) { ++ av_log(s, AV_LOG_ERROR, "Cannot append palette to packet\n"); ++ } else { ++ memcpy(pal, asf_st->palette, AVPALETTE_SIZE); ++ asf_st->palette_changed = 0; ++ } ++ } + //printf("new packet: stream:%d key:%d packet_key:%d audio:%d size:%d\n", + //asf->stream_index, asf->packet_key_frame, asf_st->pkt.flags & AV_PKT_FLAG_KEY, + //s->streams[asf->stream_index]->codec->codec_type == AVMEDIA_TYPE_AUDIO, asf->packet_obj_size); +@@ -899,7 +1031,7 @@ + continue; + } + +- ret = get_buffer(pb, asf_st->pkt.data + asf->packet_frag_offset, ++ ret = avio_read(pb, asf_st->pkt.data + asf->packet_frag_offset, + asf->packet_frag_size); + if (ret != asf->packet_frag_size) { + if (ret < 0 || asf->packet_frag_offset + ret == 0) +@@ -988,8 +1120,6 @@ + assert(asf->packet_size_left < FRAME_HEADER_SIZE || asf->packet_segments < 1); + asf->packet_time_start = 0; + } +- +- return 0; + } + + // Added to support seeking after packets have been read +@@ -1001,7 +1131,6 @@ + ASFStream *asf_st; + int i; + +- asf->packet_nb_frames = 0; + asf->packet_size_left = 0; + asf->packet_segments = 0; + asf->packet_flags = 0; +@@ -1032,13 +1161,8 @@ + + static int asf_read_close(AVFormatContext *s) + { +- int i; +- + asf_reset_header(s); +- for(i=0;inb_streams;i++) { +- AVStream *st = s->streams[i]; +- av_free(st->codec->palctrl); +- } ++ + return 0; + } + +@@ -1058,7 +1182,7 @@ + if (s->packet_size > 0) + pos= (pos+s->packet_size-1-s->data_offset)/s->packet_size*s->packet_size+ s->data_offset; + *ppos= pos; +- if (url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) + return AV_NOPTS_VALUE; + + //printf("asf_read_pts\n"); +@@ -1069,7 +1193,7 @@ + return AV_NOPTS_VALUE; + } + +- pts= pkt->pts; ++ pts = pkt->dts; + + av_free_packet(pkt); + if(pkt->flags&AV_PKT_FLAG_KEY){ +@@ -1098,12 +1222,11 @@ + { + ff_asf_guid g; + ASFContext *asf = s->priv_data; +- int64_t current_pos= url_ftell(s->pb); +- int i; ++ int64_t current_pos= avio_tell(s->pb); + +- if(url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) { +- asf->index_read= -1; +- return; ++ if(avio_seek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) { ++ asf->index_read= -1; ++ return; + } + + ff_get_guid(s->pb, &g); +@@ -1111,67 +1234,66 @@ + /* the data object can be followed by other top-level objects, + skip them until the simple index object is reached */ + while (ff_guidcmp(&g, &index_guid)) { +- int64_t gsize= get_le64(s->pb); ++ int64_t gsize= avio_rl64(s->pb); + if (gsize < 24 || url_feof(s->pb)) { +- url_fseek(s->pb, current_pos, SEEK_SET); ++ avio_seek(s->pb, current_pos, SEEK_SET); + asf->index_read= -1; + return; + } +- url_fseek(s->pb, gsize-24, SEEK_CUR); ++ avio_skip(s->pb, gsize-24); + ff_get_guid(s->pb, &g); + } + + { + int64_t itime, last_pos=-1; + int pct, ict; +- int64_t av_unused gsize= get_le64(s->pb); ++ int i; ++ int64_t av_unused gsize= avio_rl64(s->pb); + ff_get_guid(s->pb, &g); +- itime=get_le64(s->pb); +- pct=get_le32(s->pb); +- ict=get_le32(s->pb); ++ itime=avio_rl64(s->pb); ++ pct=avio_rl32(s->pb); ++ ict=avio_rl32(s->pb); + av_log(s, AV_LOG_DEBUG, "itime:0x%"PRIx64", pct:%d, ict:%d\n",itime,pct,ict); + + for (i=0;ipb); +- int pktct =get_le16(s->pb); ++ int pktnum=avio_rl32(s->pb); ++ int pktct =avio_rl16(s->pb); + int64_t pos = s->data_offset + s->packet_size*(int64_t)pktnum; +- int64_t index_pts= av_rescale(itime, i, 10000); ++ int64_t index_pts= FFMAX(av_rescale(itime, i, 10000) - asf->hdr.preroll, 0); + + if(pos != last_pos){ +- av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d\n", pktnum, pktct); ++ av_log(s, AV_LOG_DEBUG, "pktnum:%d, pktct:%d pts: %"PRId64"\n", pktnum, pktct, index_pts); + av_add_index_entry(s->streams[stream_index], pos, index_pts, s->packet_size, 0, AVINDEX_KEYFRAME); + last_pos=pos; + } + } + asf->index_read= 1; + } +- url_fseek(s->pb, current_pos, SEEK_SET); ++ avio_seek(s->pb, current_pos, SEEK_SET); + } + + static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int flags) + { + ASFContext *asf = s->priv_data; + AVStream *st = s->streams[stream_index]; +- int64_t pos; +- int index; + + if (pts == 0) { + // this is a hack since av_gen_search searches the entire file in this case + av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", s->data_offset); +- if (url_fseek(s->pb, s->data_offset, SEEK_SET) < 0) ++ if (avio_seek(s->pb, s->data_offset, SEEK_SET) < 0) + return -1; + return 0; + } + + if (s->packet_size <= 0) +- return -1; ++ return AVERROR(ENOSYS); + + if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) + return -1; + + /* Try using the protocol's read_seek if available */ + if(s->pb) { +- int ret = av_url_read_fseek(s->pb, stream_index, pts, flags); ++ int ret = avio_seek_time(s->pb, stream_index, pts, flags); + if(ret >= 0) + asf_reset_header(s); + if (ret != AVERROR(ENOSYS)) +@@ -1181,55 +1303,36 @@ + if (!asf->index_read) + asf_build_simple_index(s, stream_index); + +- if(!(asf->index_read && st->index_entries)){ +- if(av_seek_frame_binary(s, stream_index, pts, flags)<0) +- return -1; +- }else{ +- index= av_index_search_timestamp(st, pts, flags); +- if(index<0) +- return -1; +- +- /* find the position */ +- pos = st->index_entries[index].pos; +- +- // various attempts to find key frame have failed so far +- // asf_reset_header(s); +- // url_fseek(s->pb, pos, SEEK_SET); +- // key_pos = pos; +- // for(i=0;i<16;i++){ +- // pos = url_ftell(s->pb); +- // if (av_read_frame(s, &pkt) < 0){ +- // av_log(s, AV_LOG_INFO, "seek failed\n"); +- // return -1; +- // } +- // asf_st = s->streams[stream_index]->priv_data; +- // pos += st->parser->frame_offset; +- // +- // if (pkt.size > b) { +- // b = pkt.size; +- // key_pos = pos; +- // } +- // +- // av_free_packet(&pkt); +- // } +- +- /* do the seek */ +- av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); +- if(url_fseek(s->pb, pos, SEEK_SET)<0) +- return -1; ++ if((asf->index_read > 0 && st->index_entries)){ ++ int index= av_index_search_timestamp(st, pts, flags); ++ if(index >= 0) { ++ /* find the position */ ++ uint64_t pos = st->index_entries[index].pos; ++ ++ /* do the seek */ ++ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); ++ if(avio_seek(s->pb, pos, SEEK_SET) < 0) ++ return -1; ++ asf_reset_header(s); ++ return 0; ++ } + } ++ /* no index or seeking by index failed */ ++ if (ff_seek_frame_binary(s, stream_index, pts, flags) < 0) ++ return -1; + asf_reset_header(s); + return 0; + } + + AVInputFormat ff_asf_demuxer = { +- "asf", +- NULL_IF_CONFIG_SMALL("ASF format"), +- sizeof(ASFContext), +- asf_probe, +- asf_read_header, +- asf_read_packet, +- asf_read_close, +- asf_read_seek, +- asf_read_pts, ++ .name = "asf", ++ .long_name = NULL_IF_CONFIG_SMALL("ASF format"), ++ .priv_data_size = sizeof(ASFContext), ++ .read_probe = asf_probe, ++ .read_header = asf_read_header, ++ .read_packet = asf_read_packet, ++ .read_close = asf_read_close, ++ .read_seek = asf_read_seek, ++ .read_timestamp = asf_read_pts, ++ .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asfenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asfenc.c 2012-05-14 14:08:54.885351071 +0200 +@@ -19,9 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" +-#include "metadata.h" ++#include "internal.h" + #include "riff.h" + #include "asf.h" ++#include "avio_internal.h" ++#include "libavutil/dict.h" + + #undef NDEBUG + #include +@@ -188,70 +190,95 @@ + 2*PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS \ + ) + ++typedef struct { ++ uint32_t seqno; ++ int is_streamed; ++ ASFStream streams[128]; ///< it's max number and it's not that big ++ /* non streamed additonnal info */ ++ uint64_t nb_packets; ///< how many packets are there in the file, invalid if broadcasting ++ int64_t duration; ///< in 100ns units ++ /* packet filling */ ++ unsigned char multi_payloads_present; ++ int packet_size_left; ++ int64_t packet_timestamp_start; ++ int64_t packet_timestamp_end; ++ unsigned int packet_nb_payloads; ++ uint8_t packet_buf[PACKET_SIZE]; ++ AVIOContext pb; ++ /* only for reading */ ++ uint64_t data_offset; ///< beginning of the first data packet ++ ++ int64_t last_indexed_pts; ++ ASFIndex* index_ptr; ++ uint32_t nb_index_count; ++ uint32_t nb_index_memory_alloc; ++ uint16_t maximum_packet; ++} ASFContext; ++ + static const AVCodecTag codec_asf_bmp_tags[] = { +- { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') }, + { CODEC_ID_MPEG4, MKTAG('M', '4', 'S', '2') }, ++ { CODEC_ID_MPEG4, MKTAG('M', 'P', '4', 'S') }, + { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, + { CODEC_ID_NONE, 0 }, + }; + + #define PREROLL_TIME 3100 + +-static void put_guid(ByteIOContext *s, const ff_asf_guid *g) ++void ff_put_guid(AVIOContext *s, const ff_asf_guid *g) + { + assert(sizeof(*g) == 16); +- put_buffer(s, *g, sizeof(*g)); ++ avio_write(s, *g, sizeof(*g)); + } + +-static void put_str16(ByteIOContext *s, const char *tag) ++static void put_str16(AVIOContext *s, const char *tag) + { + int len; + uint8_t *pb; +- ByteIOContext *dyn_buf; +- if (url_open_dyn_buf(&dyn_buf) < 0) ++ AVIOContext *dyn_buf; ++ if (avio_open_dyn_buf(&dyn_buf) < 0) + return; + + avio_put_str16le(dyn_buf, tag); +- len = url_close_dyn_buf(dyn_buf, &pb); +- put_le16(s, len); +- put_buffer(s, pb, len); ++ len = avio_close_dyn_buf(dyn_buf, &pb); ++ avio_wl16(s, len); ++ avio_write(s, pb, len); + av_freep(&pb); + } + +-static int64_t put_header(ByteIOContext *pb, const ff_asf_guid *g) ++static int64_t put_header(AVIOContext *pb, const ff_asf_guid *g) + { + int64_t pos; + +- pos = url_ftell(pb); +- put_guid(pb, g); +- put_le64(pb, 24); ++ pos = avio_tell(pb); ++ ff_put_guid(pb, g); ++ avio_wl64(pb, 24); + return pos; + } + + /* update header size */ +-static void end_header(ByteIOContext *pb, int64_t pos) ++static void end_header(AVIOContext *pb, int64_t pos) + { + int64_t pos1; + +- pos1 = url_ftell(pb); +- url_fseek(pb, pos + 16, SEEK_SET); +- put_le64(pb, pos1 - pos); +- url_fseek(pb, pos1, SEEK_SET); ++ pos1 = avio_tell(pb); ++ avio_seek(pb, pos + 16, SEEK_SET); ++ avio_wl64(pb, pos1 - pos); ++ avio_seek(pb, pos1, SEEK_SET); + } + + /* write an asf chunk (only used in streaming case) */ + static void put_chunk(AVFormatContext *s, int type, int payload_length, int flags) + { + ASFContext *asf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int length; + + length = payload_length + 8; +- put_le16(pb, type); +- put_le16(pb, length); //size +- put_le32(pb, asf->seqno);//sequence number +- put_le16(pb, flags); /* unknown bytes */ +- put_le16(pb, length); //size_confirm ++ avio_wl16(pb, type); ++ avio_wl16(pb, length); //size ++ avio_wl32(pb, asf->seqno);//sequence number ++ avio_wl16(pb, flags); /* unknown bytes */ ++ avio_wl16(pb, length); //size_confirm + asf->seqno++; + } + +@@ -269,8 +296,8 @@ + static int asf_write_header1(AVFormatContext *s, int64_t file_size, int64_t data_chunk_size) + { + ASFContext *asf = s->priv_data; +- ByteIOContext *pb = s->pb; +- AVMetadataTag *tags[5]; ++ AVIOContext *pb = s->pb; ++ AVDictionaryEntry *tags[5]; + int header_size, n, extra_size, extra_size2, wav_extra_size, file_time; + int has_title; + int metadata_count; +@@ -281,11 +308,11 @@ + + ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL); + +- tags[0] = av_metadata_get(s->metadata, "title" , NULL, 0); +- tags[1] = av_metadata_get(s->metadata, "author" , NULL, 0); +- tags[2] = av_metadata_get(s->metadata, "copyright", NULL, 0); +- tags[3] = av_metadata_get(s->metadata, "comment" , NULL, 0); +- tags[4] = av_metadata_get(s->metadata, "rating" , NULL, 0); ++ tags[0] = av_dict_get(s->metadata, "title" , NULL, 0); ++ tags[1] = av_dict_get(s->metadata, "author" , NULL, 0); ++ tags[2] = av_dict_get(s->metadata, "copyright", NULL, 0); ++ tags[3] = av_dict_get(s->metadata, "comment" , NULL, 0); ++ tags[4] = av_dict_get(s->metadata, "rating" , NULL, 0); + + duration = asf->duration + PREROLL_TIME * 10000; + has_title = tags[0] || tags[1] || tags[2] || tags[3] || tags[4]; +@@ -295,7 +322,7 @@ + for(n=0;nnb_streams;n++) { + enc = s->streams[n]->codec; + +- av_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ ++ avpriv_set_pts_info(s->streams[n], 32, 1, 1000); /* 32 bit pts in ms */ + + bit_rate += enc->bit_rate; + } +@@ -304,63 +331,63 @@ + put_chunk(s, 0x4824, 0, 0xc00); /* start of stream (length will be patched later) */ + } + +- put_guid(pb, &ff_asf_header); +- put_le64(pb, -1); /* header length, will be patched after */ +- put_le32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */ +- put_byte(pb, 1); /* ??? */ +- put_byte(pb, 2); /* ??? */ ++ ff_put_guid(pb, &ff_asf_header); ++ avio_wl64(pb, -1); /* header length, will be patched after */ ++ avio_wl32(pb, 3 + has_title + !!metadata_count + s->nb_streams); /* number of chunks in header */ ++ avio_w8(pb, 1); /* ??? */ ++ avio_w8(pb, 2); /* ??? */ + + /* file header */ +- header_offset = url_ftell(pb); ++ header_offset = avio_tell(pb); + hpos = put_header(pb, &ff_asf_file_header); +- put_guid(pb, &ff_asf_my_guid); +- put_le64(pb, file_size); ++ ff_put_guid(pb, &ff_asf_my_guid); ++ avio_wl64(pb, file_size); + file_time = 0; +- put_le64(pb, unix_to_file_time(file_time)); +- put_le64(pb, asf->nb_packets); /* number of packets */ +- put_le64(pb, duration); /* end time stamp (in 100ns units) */ +- put_le64(pb, asf->duration); /* duration (in 100ns units) */ +- put_le64(pb, PREROLL_TIME); /* start time stamp */ +- put_le32(pb, (asf->is_streamed || url_is_streamed(pb)) ? 3 : 2); /* ??? */ +- put_le32(pb, s->packet_size); /* packet size */ +- put_le32(pb, s->packet_size); /* packet size */ +- put_le32(pb, bit_rate); /* Nominal data rate in bps */ ++ avio_wl64(pb, unix_to_file_time(file_time)); ++ avio_wl64(pb, asf->nb_packets); /* number of packets */ ++ avio_wl64(pb, duration); /* end time stamp (in 100ns units) */ ++ avio_wl64(pb, asf->duration); /* duration (in 100ns units) */ ++ avio_wl64(pb, PREROLL_TIME); /* start time stamp */ ++ avio_wl32(pb, (asf->is_streamed || !pb->seekable ) ? 3 : 2); /* ??? */ ++ avio_wl32(pb, s->packet_size); /* packet size */ ++ avio_wl32(pb, s->packet_size); /* packet size */ ++ avio_wl32(pb, bit_rate); /* Nominal data rate in bps */ + end_header(pb, hpos); + + /* unknown headers */ + hpos = put_header(pb, &ff_asf_head1_guid); +- put_guid(pb, &ff_asf_head2_guid); +- put_le32(pb, 6); +- put_le16(pb, 0); ++ ff_put_guid(pb, &ff_asf_head2_guid); ++ avio_wl32(pb, 6); ++ avio_wl16(pb, 0); + end_header(pb, hpos); + + /* title and other infos */ + if (has_title) { + int len; + uint8_t *buf; +- ByteIOContext *dyn_buf; ++ AVIOContext *dyn_buf; + +- if (url_open_dyn_buf(&dyn_buf) < 0) ++ if (avio_open_dyn_buf(&dyn_buf) < 0) + return AVERROR(ENOMEM); + + hpos = put_header(pb, &ff_asf_comment_header); + + for (n = 0; n < FF_ARRAY_ELEMS(tags); n++) { + len = tags[n] ? avio_put_str16le(dyn_buf, tags[n]->value) : 0; +- put_le16(pb, len); ++ avio_wl16(pb, len); + } +- len = url_close_dyn_buf(dyn_buf, &buf); +- put_buffer(pb, buf, len); ++ len = avio_close_dyn_buf(dyn_buf, &buf); ++ avio_write(pb, buf, len); + av_freep(&buf); + end_header(pb, hpos); + } + if (metadata_count) { +- AVMetadataTag *tag = NULL; ++ AVDictionaryEntry *tag = NULL; + hpos = put_header(pb, &ff_asf_extended_content_header); +- put_le16(pb, metadata_count); +- while ((tag = av_metadata_get(s->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { ++ avio_wl16(pb, metadata_count); ++ while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { + put_str16(pb, tag->key); +- put_le16(pb, 0); ++ avio_wl16(pb, 0); + put_str16(pb, tag->value); + } + end_header(pb, hpos); +@@ -392,51 +419,47 @@ + + hpos = put_header(pb, &ff_asf_stream_header); + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { +- put_guid(pb, &ff_asf_audio_stream); +- put_guid(pb, &ff_asf_audio_conceal_spread); ++ ff_put_guid(pb, &ff_asf_audio_stream); ++ ff_put_guid(pb, &ff_asf_audio_conceal_spread); + } else { +- put_guid(pb, &ff_asf_video_stream); +- put_guid(pb, &ff_asf_video_conceal_none); ++ ff_put_guid(pb, &ff_asf_video_stream); ++ ff_put_guid(pb, &ff_asf_video_conceal_none); + } +- put_le64(pb, 0); /* ??? */ +- es_pos = url_ftell(pb); +- put_le32(pb, extra_size); /* wav header len */ +- put_le32(pb, extra_size2); /* additional data len */ +- put_le16(pb, n + 1); /* stream number */ +- put_le32(pb, 0); /* ??? */ ++ avio_wl64(pb, 0); /* ??? */ ++ es_pos = avio_tell(pb); ++ avio_wl32(pb, extra_size); /* wav header len */ ++ avio_wl32(pb, extra_size2); /* additional data len */ ++ avio_wl16(pb, n + 1); /* stream number */ ++ avio_wl32(pb, 0); /* ??? */ + + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + /* WAVEFORMATEX header */ + int wavsize = ff_put_wav_header(pb, enc); +- if ((enc->codec_id != CODEC_ID_MP3) && (enc->codec_id != CODEC_ID_MP2) && (enc->codec_id != CODEC_ID_ADPCM_IMA_WAV) && (enc->extradata_size==0)) { +- wavsize += 2; +- put_le16(pb, 0); +- } + + if (wavsize < 0) + return -1; + if (wavsize != extra_size) { +- cur_pos = url_ftell(pb); +- url_fseek(pb, es_pos, SEEK_SET); +- put_le32(pb, wavsize); /* wav header len */ +- url_fseek(pb, cur_pos, SEEK_SET); ++ cur_pos = avio_tell(pb); ++ avio_seek(pb, es_pos, SEEK_SET); ++ avio_wl32(pb, wavsize); /* wav header len */ ++ avio_seek(pb, cur_pos, SEEK_SET); + } + /* ERROR Correction */ +- put_byte(pb, 0x01); ++ avio_w8(pb, 0x01); + if(enc->codec_id == CODEC_ID_ADPCM_G726 || !enc->block_align){ +- put_le16(pb, 0x0190); +- put_le16(pb, 0x0190); ++ avio_wl16(pb, 0x0190); ++ avio_wl16(pb, 0x0190); + }else{ +- put_le16(pb, enc->block_align); +- put_le16(pb, enc->block_align); ++ avio_wl16(pb, enc->block_align); ++ avio_wl16(pb, enc->block_align); + } +- put_le16(pb, 0x01); +- put_byte(pb, 0x00); ++ avio_wl16(pb, 0x01); ++ avio_w8(pb, 0x00); + } else { +- put_le32(pb, enc->width); +- put_le32(pb, enc->height); +- put_byte(pb, 2); /* ??? */ +- put_le16(pb, 40 + enc->extradata_size); /* size */ ++ avio_wl32(pb, enc->width); ++ avio_wl32(pb, enc->height); ++ avio_w8(pb, 2); /* ??? */ ++ avio_wl16(pb, 40 + enc->extradata_size); /* size */ + + /* BITMAPINFOHEADER header */ + ff_put_bmp_header(pb, enc, ff_codec_bmp_tags, 1); +@@ -447,50 +470,50 @@ + /* media comments */ + + hpos = put_header(pb, &ff_asf_codec_comment_header); +- put_guid(pb, &ff_asf_codec_comment1_header); +- put_le32(pb, s->nb_streams); ++ ff_put_guid(pb, &ff_asf_codec_comment1_header); ++ avio_wl32(pb, s->nb_streams); + for(n=0;nnb_streams;n++) { + AVCodec *p; + const char *desc; + int len; + uint8_t *buf; +- ByteIOContext *dyn_buf; ++ AVIOContext *dyn_buf; + + enc = s->streams[n]->codec; + p = avcodec_find_encoder(enc->codec_id); + + if(enc->codec_type == AVMEDIA_TYPE_AUDIO) +- put_le16(pb, 2); ++ avio_wl16(pb, 2); + else if(enc->codec_type == AVMEDIA_TYPE_VIDEO) +- put_le16(pb, 1); ++ avio_wl16(pb, 1); + else +- put_le16(pb, -1); ++ avio_wl16(pb, -1); + + if(enc->codec_id == CODEC_ID_WMAV2) + desc = "Windows Media Audio V8"; + else + desc = p ? p->name : enc->codec_name; + +- if ( url_open_dyn_buf(&dyn_buf) < 0) ++ if ( avio_open_dyn_buf(&dyn_buf) < 0) + return AVERROR(ENOMEM); + + avio_put_str16le(dyn_buf, desc); +- len = url_close_dyn_buf(dyn_buf, &buf); +- put_le16(pb, len / 2); // "number of characters" = length in bytes / 2 ++ len = avio_close_dyn_buf(dyn_buf, &buf); ++ avio_wl16(pb, len / 2); // "number of characters" = length in bytes / 2 + +- put_buffer(pb, buf, len); ++ avio_write(pb, buf, len); + av_freep(&buf); + +- put_le16(pb, 0); /* no parameters */ ++ avio_wl16(pb, 0); /* no parameters */ + + + /* id */ + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { +- put_le16(pb, 2); +- put_le16(pb, enc->codec_tag); ++ avio_wl16(pb, 2); ++ avio_wl16(pb, enc->codec_tag); + } else { +- put_le16(pb, 4); +- put_le32(pb, enc->codec_tag); ++ avio_wl16(pb, 4); ++ avio_wl32(pb, enc->codec_tag); + } + if(!enc->codec_tag) + return -1; +@@ -499,31 +522,31 @@ + + /* patch the header size fields */ + +- cur_pos = url_ftell(pb); ++ cur_pos = avio_tell(pb); + header_size = cur_pos - header_offset; + if (asf->is_streamed) { + header_size += 8 + 30 + 50; + +- url_fseek(pb, header_offset - 10 - 30, SEEK_SET); +- put_le16(pb, header_size); +- url_fseek(pb, header_offset - 2 - 30, SEEK_SET); +- put_le16(pb, header_size); ++ avio_seek(pb, header_offset - 10 - 30, SEEK_SET); ++ avio_wl16(pb, header_size); ++ avio_seek(pb, header_offset - 2 - 30, SEEK_SET); ++ avio_wl16(pb, header_size); + + header_size -= 8 + 30 + 50; + } + header_size += 24 + 6; +- url_fseek(pb, header_offset - 14, SEEK_SET); +- put_le64(pb, header_size); +- url_fseek(pb, cur_pos, SEEK_SET); ++ avio_seek(pb, header_offset - 14, SEEK_SET); ++ avio_wl64(pb, header_size); ++ avio_seek(pb, cur_pos, SEEK_SET); + + /* movie chunk, followed by packets of packet_size */ + asf->data_offset = cur_pos; +- put_guid(pb, &ff_asf_data_header); +- put_le64(pb, data_chunk_size); +- put_guid(pb, &ff_asf_my_guid); +- put_le64(pb, asf->nb_packets); /* nb packets */ +- put_byte(pb, 1); /* ??? */ +- put_byte(pb, 1); /* ??? */ ++ ff_put_guid(pb, &ff_asf_data_header); ++ avio_wl64(pb, data_chunk_size); ++ ff_put_guid(pb, &ff_asf_my_guid); ++ avio_wl64(pb, asf->nb_packets); /* nb packets */ ++ avio_w8(pb, 1); /* ??? */ ++ avio_w8(pb, 1); /* ??? */ + return 0; + } + +@@ -548,12 +571,12 @@ + return -1; + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + asf->packet_nb_payloads = 0; + asf->packet_timestamp_start = -1; + asf->packet_timestamp_end = -1; +- init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1, ++ ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1, + NULL, NULL, NULL, NULL); + + return 0; +@@ -577,9 +600,9 @@ + ) + { + ASFContext *asf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ppi_size, i; +- int64_t start= url_ftell(pb); ++ int64_t start= avio_tell(pb); + + int iLengthTypeFlags = ASF_PPI_LENGTH_TYPE_FLAGS; + +@@ -588,9 +611,9 @@ + padsize--; + assert(padsize>=0); + +- put_byte(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS); ++ avio_w8(pb, ASF_PACKET_ERROR_CORRECTION_FLAGS); + for (i = 0; i < ASF_PACKET_ERROR_CORRECTION_DATA_SIZE; i++){ +- put_byte(pb, 0x0); ++ avio_w8(pb, 0x0); + } + + if (asf->multi_payloads_present) +@@ -602,21 +625,21 @@ + else + iLengthTypeFlags |= ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD; + } +- put_byte(pb, iLengthTypeFlags); ++ avio_w8(pb, iLengthTypeFlags); + +- put_byte(pb, ASF_PPI_PROPERTY_FLAGS); ++ avio_w8(pb, ASF_PPI_PROPERTY_FLAGS); + + if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_WORD) +- put_le16(pb, padsize - 2); ++ avio_wl16(pb, padsize - 2); + if (iLengthTypeFlags & ASF_PPI_FLAG_PADDING_LENGTH_FIELD_IS_BYTE) +- put_byte(pb, padsize - 1); ++ avio_w8(pb, padsize - 1); + +- put_le32(pb, sendtime); +- put_le16(pb, duration); ++ avio_wl32(pb, sendtime); ++ avio_wl16(pb, duration); + if (asf->multi_payloads_present) +- put_byte(pb, nb_payloads | ASF_PAYLOAD_FLAGS); ++ avio_w8(pb, nb_payloads | ASF_PAYLOAD_FLAGS); + +- ppi_size = url_ftell(pb) - start; ++ ppi_size = avio_tell(pb) - start; + + return ppi_size; + } +@@ -644,21 +667,21 @@ + assert(packet_hdr_size <= asf->packet_size_left); + memset(asf->packet_buf + packet_filled_size, 0, asf->packet_size_left); + +- put_buffer(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size); ++ avio_write(s->pb, asf->packet_buf, s->packet_size - packet_hdr_size); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + asf->nb_packets++; + asf->packet_nb_payloads = 0; + asf->packet_timestamp_start = -1; + asf->packet_timestamp_end = -1; +- init_put_byte(&asf->pb, asf->packet_buf, s->packet_size, 1, ++ ffio_init_context(&asf->pb, asf->packet_buf, s->packet_size, 1, + NULL, NULL, NULL, NULL); + } + + static void put_payload_header( + AVFormatContext *s, + ASFStream *stream, +- int presentation_time, ++ int64_t presentation_time, + int m_obj_size, + int m_obj_offset, + int payload_len, +@@ -666,29 +689,29 @@ + ) + { + ASFContext *asf = s->priv_data; +- ByteIOContext *pb = &asf->pb; ++ AVIOContext *pb = &asf->pb; + int val; + + val = stream->num; + if (flags & AV_PKT_FLAG_KEY) + val |= ASF_PL_FLAG_KEY_FRAME; +- put_byte(pb, val); ++ avio_w8(pb, val); + +- put_byte(pb, stream->seq); //Media object number +- put_le32(pb, m_obj_offset); //Offset Into Media Object ++ avio_w8(pb, stream->seq); //Media object number ++ avio_wl32(pb, m_obj_offset); //Offset Into Media Object + + // Replicated Data shall be at least 8 bytes long. + // The first 4 bytes of data shall contain the + // Size of the Media Object that the payload belongs to. + // The next 4 bytes of data shall contain the + // Presentation Time for the media object that the payload belongs to. +- put_byte(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH); ++ avio_w8(pb, ASF_PAYLOAD_REPLICATED_DATA_LENGTH); + +- put_le32(pb, m_obj_size); //Replicated Data - Media Object Size +- put_le32(pb, presentation_time);//Replicated Data - Presentation Time ++ avio_wl32(pb, m_obj_size); //Replicated Data - Media Object Size ++ avio_wl32(pb, (uint32_t) presentation_time);//Replicated Data - Presentation Time + + if (asf->multi_payloads_present){ +- put_le16(pb, payload_len); //payload length ++ avio_wl16(pb, payload_len); //payload length + } + } + +@@ -696,7 +719,7 @@ + AVFormatContext *s, + ASFStream *stream, + AVStream *avst, +- int timestamp, ++ int64_t timestamp, + const uint8_t *buf, + int m_obj_size, + int flags +@@ -736,7 +759,7 @@ + payload_len = frag_len1 - 2; //additional byte need to put padding length + + put_payload_header(s, stream, timestamp+PREROLL_TIME, m_obj_size, m_obj_offset, payload_len, flags); +- put_buffer(&asf->pb, buf, payload_len); ++ avio_write(&asf->pb, buf, payload_len); + + if (asf->multi_payloads_present) + asf->packet_size_left -= (payload_len + PAYLOAD_HEADER_SIZE_MULTIPLE_PAYLOADS); +@@ -807,18 +830,18 @@ + // + static int asf_write_index(AVFormatContext *s, ASFIndex *index, uint16_t max, uint32_t count) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i; + +- put_guid(pb, &ff_asf_simple_index_header); +- put_le64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count); +- put_guid(pb, &ff_asf_my_guid); +- put_le64(pb, ASF_INDEXED_INTERVAL); +- put_le32(pb, max); +- put_le32(pb, count); ++ ff_put_guid(pb, &ff_asf_simple_index_header); ++ avio_wl64(pb, 24 + 16 + 8 + 4 + 4 + (4 + 2)*count); ++ ff_put_guid(pb, &ff_asf_my_guid); ++ avio_wl64(pb, ASF_INDEXED_INTERVAL); ++ avio_wl32(pb, max); ++ avio_wl32(pb, count); + for(i=0; ipb); ++ data_size = avio_tell(s->pb); + if ((!asf->is_streamed) && (asf->nb_index_count != 0)) { + asf_write_index(s, asf->index_ptr, asf->maximum_packet, asf->nb_index_count); + } +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + +- if (asf->is_streamed || url_is_streamed(s->pb)) { ++ if (asf->is_streamed || !s->pb->seekable) { + put_chunk(s, 0x4524, 0, 0); /* end of stream */ + } else { + /* rewrite an updated header */ +- file_size = url_ftell(s->pb); +- url_fseek(s->pb, 0, SEEK_SET); ++ file_size = avio_tell(s->pb); ++ avio_seek(s->pb, 0, SEEK_SET); + asf_write_header1(s, file_size, data_size - asf->data_offset); + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + av_free(asf->index_ptr); + return 0; + } + + #if CONFIG_ASF_MUXER + AVOutputFormat ff_asf_muxer = { +- "asf", +- NULL_IF_CONFIG_SMALL("ASF format"), +- "video/x-ms-asf", +- "asf,wmv,wma", +- sizeof(ASFContext), +-#if CONFIG_LIBMP3LAME +- CODEC_ID_MP3, +-#else +- CODEC_ID_MP2, +-#endif +- CODEC_ID_MSMPEG4V3, +- asf_write_header, +- asf_write_packet, +- asf_write_trailer, ++ .name = "asf", ++ .long_name = NULL_IF_CONFIG_SMALL("ASF format"), ++ .mime_type = "video/x-ms-asf", ++ .extensions = "asf,wmv,wma", ++ .priv_data_size = sizeof(ASFContext), ++ .audio_codec = CODEC_ID_WMAV2, ++ .video_codec = CODEC_ID_MSMPEG4V3, ++ .write_header = asf_write_header, ++ .write_packet = asf_write_packet, ++ .write_trailer = asf_write_trailer, + .flags = AVFMT_GLOBALHEADER, + .codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0}, + }; +@@ -877,20 +896,16 @@ + + #if CONFIG_ASF_STREAM_MUXER + AVOutputFormat ff_asf_stream_muxer = { +- "asf_stream", +- NULL_IF_CONFIG_SMALL("ASF format"), +- "video/x-ms-asf", +- "asf,wmv,wma", +- sizeof(ASFContext), +-#if CONFIG_LIBMP3LAME +- CODEC_ID_MP3, +-#else +- CODEC_ID_MP2, +-#endif +- CODEC_ID_MSMPEG4V3, +- asf_write_stream_header, +- asf_write_packet, +- asf_write_trailer, ++ .name = "asf_stream", ++ .long_name = NULL_IF_CONFIG_SMALL("ASF format"), ++ .mime_type = "video/x-ms-asf", ++ .extensions = "asf,wmv,wma", ++ .priv_data_size = sizeof(ASFContext), ++ .audio_codec = CODEC_ID_WMAV2, ++ .video_codec = CODEC_ID_MSMPEG4V3, ++ .write_header = asf_write_stream_header, ++ .write_packet = asf_write_packet, ++ .write_trailer = asf_write_trailer, + .flags = AVFMT_GLOBALHEADER, + .codec_tag= (const AVCodecTag* const []){codec_asf_bmp_tags, ff_codec_bmp_tags, ff_codec_wav_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asf.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asf.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/asf.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/asf.h 2012-05-14 14:08:54.876350890 +0200 +@@ -24,6 +24,7 @@ + #include + #include "avformat.h" + #include "metadata.h" ++#include "riff.h" + + #define PACKET_SIZE 3200 + +@@ -44,10 +45,10 @@ + + uint16_t stream_language_index; + ++ int palette_changed; ++ uint32_t palette[256]; + } ASFStream; + +-typedef uint8_t ff_asf_guid[16]; +- + typedef struct { + ff_asf_guid guid; ///< generated by client computer + uint64_t file_size; /**< in bytes +@@ -79,64 +80,6 @@ + uint16_t packet_count; + } ASFIndex; + +- +-typedef struct { +- uint32_t seqno; +- int is_streamed; +- int asfid2avid[128]; ///< conversion table from asf ID 2 AVStream ID +- ASFStream streams[128]; ///< it's max number and it's not that big +- uint32_t stream_bitrates[128]; ///< max number of streams, bitrate for each (for streaming) +- char stream_languages[128][6]; ///< max number of streams, language for each (RFC1766, e.g. en-US) +- /* non streamed additonnal info */ +- uint64_t nb_packets; ///< how many packets are there in the file, invalid if broadcasting +- int64_t duration; ///< in 100ns units +- /* packet filling */ +- unsigned char multi_payloads_present; +- int packet_size_left; +- int packet_timestamp_start; +- int packet_timestamp_end; +- unsigned int packet_nb_payloads; +- int packet_nb_frames; +- uint8_t packet_buf[PACKET_SIZE]; +- ByteIOContext pb; +- /* only for reading */ +- uint64_t data_offset; ///< beginning of the first data packet +- uint64_t data_object_offset; ///< data object offset (excl. GUID & size) +- uint64_t data_object_size; ///< size of the data object +- int index_read; +- +- ASFMainHeader hdr; +- +- int packet_flags; +- int packet_property; +- int packet_timestamp; +- int packet_segsizetype; +- int packet_segments; +- int packet_seq; +- int packet_replic_size; +- int packet_key_frame; +- int packet_padsize; +- unsigned int packet_frag_offset; +- unsigned int packet_frag_size; +- int64_t packet_frag_timestamp; +- int packet_multi_size; +- int packet_obj_size; +- int packet_time_delta; +- int packet_time_start; +- int64_t packet_pos; +- +- int stream_index; +- +- +- int64_t last_indexed_pts; +- ASFIndex* index_ptr; +- uint32_t nb_index_count; +- uint32_t nb_index_memory_alloc; +- uint16_t maximum_packet; +- +- ASFStream* asf_st; ///< currently decoded stream +-} ASFContext; +- + extern const ff_asf_guid ff_asf_header; + extern const ff_asf_guid ff_asf_file_header; + extern const ff_asf_guid ff_asf_stream_header; +@@ -230,7 +173,7 @@ + #define ASF_PL_FLAG_KEY_FRAME 0x80 //1000 0000 + + extern AVInputFormat ff_asf_demuxer; +-int ff_guidcmp(const void *g1, const void *g2); +-void ff_get_guid(ByteIOContext *s, ff_asf_guid *g); ++ ++void ff_put_guid(AVIOContext *s, const ff_asf_guid *g); + + #endif /* AVFORMAT_ASF_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/assdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/assdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/assdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/assdec.c 2012-05-14 14:08:54.886351091 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "avformat.h" + #include "internal.h" + +@@ -76,16 +77,16 @@ + { + int i, len, header_remaining; + ASSContext *ass = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + int allocated[2]={0}; + uint8_t *p, **dst[2]={0}; + int pos[2]={0}; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; +- av_set_pts_info(st, 64, 1, 100); ++ avpriv_set_pts_info(st, 64, 1, 100); + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codec->codec_id= CODEC_ID_SSA; + +@@ -168,7 +169,7 @@ + ASSContext *ass = s->priv_data; + + if (flags & AVSEEK_FLAG_BYTE) { +- return AVERROR_NOTSUPP; ++ return AVERROR(ENOSYS); + } else if (flags & AVSEEK_FLAG_FRAME) { + if (ts < 0 || ts >= ass->event_count) + return AVERROR(ERANGE); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/assenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/assenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/assenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/assenc.c 2012-05-14 14:08:54.887351111 +0200 +@@ -42,7 +42,7 @@ + if(!end) end= avctx->extradata + avctx->extradata_size; + else end++; + +- put_buffer(s->pb, p, end-p); ++ avio_write(s->pb, p, end-p); + ass->extra_index += end-p; + + if(last && !memcmp(last, "[Events]", 8)) +@@ -50,16 +50,16 @@ + last=p; + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + return 0; + } + + static int write_packet(AVFormatContext *s, AVPacket *pkt) + { +- put_buffer(s->pb, pkt->data, pkt->size); ++ avio_write(s->pb, pkt->data, pkt->size); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + return 0; + } +@@ -69,10 +69,10 @@ + ASSContext *ass = s->priv_data; + AVCodecContext *avctx= s->streams[0]->codec; + +- put_buffer(s->pb, avctx->extradata + ass->extra_index, ++ avio_write(s->pb, avctx->extradata + ass->extra_index, + avctx->extradata_size - ass->extra_index); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/au.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/au.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/au.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/au.c 2012-05-14 14:08:54.888351131 +0200 +@@ -28,13 +28,15 @@ + */ + + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "pcm.h" + #include "riff.h" + + /* if we don't know the size in advance */ + #define AU_UNKNOWN_SIZE ((uint32_t)(~0)) + +-/* The ffmpeg codecs we support, and the IDs they have in the file */ ++/* The libavcodec codecs we support, and the IDs they have in the file */ + static const AVCodecTag codec_au_tags[] = { + { CODEC_ID_PCM_MULAW, 1 }, + { CODEC_ID_PCM_S8, 2 }, +@@ -49,22 +51,22 @@ + + #if CONFIG_AU_MUXER + /* AUDIO_FILE header */ +-static int put_au_header(ByteIOContext *pb, AVCodecContext *enc) ++static int put_au_header(AVIOContext *pb, AVCodecContext *enc) + { + if(!enc->codec_tag) + return -1; +- put_tag(pb, ".snd"); /* magic number */ +- put_be32(pb, 24); /* header size */ +- put_be32(pb, AU_UNKNOWN_SIZE); /* data size */ +- put_be32(pb, (uint32_t)enc->codec_tag); /* codec ID */ +- put_be32(pb, enc->sample_rate); +- put_be32(pb, (uint32_t)enc->channels); ++ ffio_wfourcc(pb, ".snd"); /* magic number */ ++ avio_wb32(pb, 24); /* header size */ ++ avio_wb32(pb, AU_UNKNOWN_SIZE); /* data size */ ++ avio_wb32(pb, (uint32_t)enc->codec_tag); /* codec ID */ ++ avio_wb32(pb, enc->sample_rate); ++ avio_wb32(pb, (uint32_t)enc->channels); + return 0; + } + + static int au_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + s->priv_data = NULL; + +@@ -73,32 +75,32 @@ + return -1; + } + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int au_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; +- put_buffer(pb, pkt->data, pkt->size); ++ AVIOContext *pb = s->pb; ++ avio_write(pb, pkt->data, pkt->size); + return 0; + } + + static int au_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t file_size; + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + + /* update file size */ +- file_size = url_ftell(pb); +- url_fseek(pb, 8, SEEK_SET); +- put_be32(pb, (uint32_t)(file_size - 24)); +- url_fseek(pb, file_size, SEEK_SET); ++ file_size = avio_tell(pb); ++ avio_seek(pb, 8, SEEK_SET); ++ avio_wb32(pb, (uint32_t)(file_size - 24)); ++ avio_seek(pb, file_size, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + } + + return 0; +@@ -119,38 +121,43 @@ + static int au_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- int size; ++ int size, bps, data_size = 0; + unsigned int tag; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int id, channels, rate; + enum CodecID codec; + AVStream *st; + + /* check ".snd" header */ +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('.', 's', 'n', 'd')) + return -1; +- size = get_be32(pb); /* header size */ +- get_be32(pb); /* data size */ ++ size = avio_rb32(pb); /* header size */ ++ data_size = avio_rb32(pb); /* data size in bytes */ + +- id = get_be32(pb); +- rate = get_be32(pb); +- channels = get_be32(pb); ++ if (data_size < 0 && data_size != AU_UNKNOWN_SIZE) { ++ av_log(s, AV_LOG_ERROR, "Invalid negative data size '%d' found\n", data_size); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ id = avio_rb32(pb); ++ rate = avio_rb32(pb); ++ channels = avio_rb32(pb); + + codec = ff_codec_get_id(codec_au_tags, id); + +- if (!av_get_bits_per_sample(codec)) { ++ if (!(bps = av_get_bits_per_sample(codec))) { + av_log_ask_for_sample(s, "could not determine bits per sample\n"); + return AVERROR_INVALIDDATA; + } + + if (size >= 24) { + /* skip unused data */ +- url_fseek(pb, size - 24, SEEK_CUR); ++ avio_skip(pb, size - 24); + } + + /* now we are ready: build format streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -158,7 +165,9 @@ + st->codec->codec_id = codec; + st->codec->channels = channels; + st->codec->sample_rate = rate; +- av_set_pts_info(st, 64, 1, rate); ++ if (data_size != AU_UNKNOWN_SIZE) ++ st->duration = (((int64_t)data_size)<<3) / (st->codec->channels * bps); ++ avpriv_set_pts_info(st, 64, 1, rate); + return 0; + } + +@@ -184,30 +193,27 @@ + + #if CONFIG_AU_DEMUXER + AVInputFormat ff_au_demuxer = { +- "au", +- NULL_IF_CONFIG_SMALL("SUN AU format"), +- 0, +- au_probe, +- au_read_header, +- au_read_packet, +- NULL, +- pcm_read_seek, ++ .name = "au", ++ .long_name = NULL_IF_CONFIG_SMALL("SUN AU format"), ++ .read_probe = au_probe, ++ .read_header = au_read_header, ++ .read_packet = au_read_packet, ++ .read_seek = pcm_read_seek, + .codec_tag= (const AVCodecTag* const []){codec_au_tags, 0}, + }; + #endif + + #if CONFIG_AU_MUXER + AVOutputFormat ff_au_muxer = { +- "au", +- NULL_IF_CONFIG_SMALL("SUN AU format"), +- "audio/basic", +- "au", +- 0, +- CODEC_ID_PCM_S16BE, +- CODEC_ID_NONE, +- au_write_header, +- au_write_packet, +- au_write_trailer, ++ .name = "au", ++ .long_name = NULL_IF_CONFIG_SMALL("SUN AU format"), ++ .mime_type = "audio/basic", ++ .extensions = "au", ++ .audio_codec = CODEC_ID_PCM_S16BE, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = au_write_header, ++ .write_packet = au_write_packet, ++ .write_trailer = au_write_trailer, + .codec_tag= (const AVCodecTag* const []){codec_au_tags, 0}, + }; + #endif //CONFIG_AU_MUXER +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/audiointerleave.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/audiointerleave.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/audiointerleave.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/audiointerleave.c 2012-05-14 14:08:54.889351151 +0200 +@@ -21,6 +21,7 @@ + */ + + #include "libavutil/fifo.h" ++#include "libavutil/mathematics.h" + #include "avformat.h" + #include "audiointerleave.h" + #include "internal.h" +@@ -112,10 +113,13 @@ + } + av_fifo_generic_write(aic->fifo, pkt->data, pkt->size, NULL); + } else { ++ int ret; + // rewrite pts and dts to be decoded time line position + pkt->pts = pkt->dts = aic->dts; + aic->dts += pkt->duration; +- ff_interleave_add_packet(s, pkt, compare_ts); ++ ret = ff_interleave_add_packet(s, pkt, compare_ts); ++ if (ret < 0) ++ return ret; + } + pkt = NULL; + } +@@ -124,8 +128,12 @@ + AVStream *st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + AVPacket new_pkt; +- while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush)) +- ff_interleave_add_packet(s, &new_pkt, compare_ts); ++ int ret; ++ while (ff_interleave_new_audio_packet(s, &new_pkt, i, flush)) { ++ ret = ff_interleave_add_packet(s, &new_pkt, compare_ts); ++ if (ret < 0) ++ return ret; ++ } + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avc.c 2012-05-14 14:08:54.890351172 +0200 +@@ -67,7 +67,7 @@ + return out; + } + +-int ff_avc_parse_nal_units(ByteIOContext *pb, const uint8_t *buf_in, int size) ++int ff_avc_parse_nal_units(AVIOContext *pb, const uint8_t *buf_in, int size) + { + const uint8_t *p = buf_in; + const uint8_t *end = p + size; +@@ -75,11 +75,14 @@ + + size = 0; + nal_start = ff_avc_find_startcode(p, end); +- while (nal_start < end) { +- while(!*(nal_start++)); ++ for (;;) { ++ while (nal_start < end && !*(nal_start++)); ++ if (nal_start == end) ++ break; ++ + nal_end = ff_avc_find_startcode(nal_start, end); +- put_be32(pb, nal_end - nal_start); +- put_buffer(pb, nal_start, nal_end - nal_start); ++ avio_wb32(pb, nal_end - nal_start); ++ avio_write(pb, nal_start, nal_end - nal_start); + size += 4 + nal_end - nal_start; + nal_start = nal_end; + } +@@ -88,19 +91,19 @@ + + int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size) + { +- ByteIOContext *pb; +- int ret = url_open_dyn_buf(&pb); ++ AVIOContext *pb; ++ int ret = avio_open_dyn_buf(&pb); + if(ret < 0) + return ret; + + ff_avc_parse_nal_units(pb, buf_in, *size); + + av_freep(buf); +- *size = url_close_dyn_buf(pb, buf); ++ *size = avio_close_dyn_buf(pb, buf); + return 0; + } + +-int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len) ++int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len) + { + if (len > 6) { + /* check for h264 start code */ +@@ -117,38 +120,42 @@ + end = buf + len; + + /* look for sps and pps */ +- while (buf < end) { +- unsigned int size; ++ while (end - buf > 4) { ++ uint32_t size; + uint8_t nal_type; +- size = AV_RB32(buf); +- nal_type = buf[4] & 0x1f; ++ size = FFMIN(AV_RB32(buf), end - buf - 4); ++ buf += 4; ++ nal_type = buf[0] & 0x1f; ++ + if (nal_type == 7) { /* SPS */ +- sps = buf + 4; ++ sps = buf; + sps_size = size; + } else if (nal_type == 8) { /* PPS */ +- pps = buf + 4; ++ pps = buf; + pps_size = size; + } +- buf += size + 4; ++ ++ buf += size; + } +- assert(sps); +- assert(pps); + +- put_byte(pb, 1); /* version */ +- put_byte(pb, sps[1]); /* profile */ +- put_byte(pb, sps[2]); /* profile compat */ +- put_byte(pb, sps[3]); /* level */ +- put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ +- put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ +- +- put_be16(pb, sps_size); +- put_buffer(pb, sps, sps_size); +- put_byte(pb, 1); /* number of pps */ +- put_be16(pb, pps_size); +- put_buffer(pb, pps, pps_size); ++ if (!sps || !pps || sps_size < 4 || sps_size > UINT16_MAX || pps_size > UINT16_MAX) ++ return AVERROR_INVALIDDATA; ++ ++ avio_w8(pb, 1); /* version */ ++ avio_w8(pb, sps[1]); /* profile */ ++ avio_w8(pb, sps[2]); /* profile compat */ ++ avio_w8(pb, sps[3]); /* level */ ++ avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ ++ avio_w8(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ ++ ++ avio_wb16(pb, sps_size); ++ avio_write(pb, sps, sps_size); ++ avio_w8(pb, 1); /* number of pps */ ++ avio_wb16(pb, pps_size); ++ avio_write(pb, pps, pps_size); + av_free(start); + } else { +- put_buffer(pb, data, len); ++ avio_write(pb, data, len); + } + } + return 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avc.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avc.h 2012-05-14 14:08:54.890351172 +0200 +@@ -25,9 +25,9 @@ + #include + #include "avio.h" + +-int ff_avc_parse_nal_units(ByteIOContext *s, const uint8_t *buf, int size); ++int ff_avc_parse_nal_units(AVIOContext *s, const uint8_t *buf, int size); + int ff_avc_parse_nal_units_buf(const uint8_t *buf_in, uint8_t **buf, int *size); +-int ff_isom_write_avcc(ByteIOContext *pb, const uint8_t *data, int len); ++int ff_isom_write_avcc(AVIOContext *pb, const uint8_t *data, int len); + const uint8_t *ff_avc_find_startcode(const uint8_t *p, const uint8_t *end); + + #endif /* AVFORMAT_AVC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avformat.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avformat.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avformat.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avformat.h 2012-05-14 14:08:54.897351312 +0200 +@@ -21,26 +21,125 @@ + #ifndef AVFORMAT_AVFORMAT_H + #define AVFORMAT_AVFORMAT_H + +- +-/** +- * I return the LIBAVFORMAT_VERSION_INT constant. You got +- * a fucking problem with that, douchebag? +- */ +-unsigned avformat_version(void); +- + /** +- * Return the libavformat build-time configuration. ++ * @file ++ * @ingroup libavf ++ * Main libavformat public API header + */ +-const char *avformat_configuration(void); + + /** +- * Return the libavformat license. ++ * @defgroup libavf I/O and Muxing/Demuxing Library ++ * @{ ++ * ++ * Libavformat (lavf) is a library for dealing with various media container ++ * formats. Its main two purposes are demuxing - i.e. splitting a media file ++ * into component streams, and the reverse process of muxing - writing supplied ++ * data in a specified container format. It also has an @ref lavf_io ++ * "I/O module" which supports a number of protocols for accessing the data (e.g. ++ * file, tcp, http and others). Before using lavf, you need to call ++ * av_register_all() to register all compiled muxers, demuxers and protocols. ++ * Unless you are absolutely sure you won't use libavformat's network ++ * capabilities, you should also call avformat_network_init(). ++ * ++ * A supported input format is described by an AVInputFormat struct, conversely ++ * an output format is described by AVOutputFormat. You can iterate over all ++ * registered input/output formats using the av_iformat_next() / ++ * av_oformat_next() functions. The protocols layer is not part of the public ++ * API, so you can only get the names of supported protocols with the ++ * avio_enum_protocols() function. ++ * ++ * Main lavf structure used for both muxing and demuxing is AVFormatContext, ++ * which exports all information about the file being read or written. As with ++ * most Libav structures, its size is not part of public ABI, so it cannot be ++ * allocated on stack or directly with av_malloc(). To create an ++ * AVFormatContext, use avformat_alloc_context() (some functions, like ++ * avformat_open_input() might do that for you). ++ * ++ * Most importantly an AVFormatContext contains: ++ * @li the @ref AVFormatContext.iformat "input" or @ref AVFormatContext.oformat ++ * "output" format. It is either autodetected or set by user for input; ++ * always set by user for output. ++ * @li an @ref AVFormatContext.streams "array" of AVStreams, which describe all ++ * elementary streams stored in the file. AVStreams are typically referred to ++ * using their index in this array. ++ * @li an @ref AVFormatContext.pb "I/O context". It is either opened by lavf or ++ * set by user for input, always set by user for output (unless you are dealing ++ * with an AVFMT_NOFILE format). ++ * ++ * @defgroup lavf_decoding Demuxing ++ * @{ ++ * Demuxers read a media file and split it into chunks of data (@em packets). A ++ * @ref AVPacket "packet" contains one or more frames which belong a single ++ * elementary stream. In lavf API this process is represented by the ++ * avformat_open_input() function for opening a file, av_read_frame() for ++ * reading a single packet and finally avformat_close_input(), which does the ++ * cleanup. ++ * ++ * @section lavf_decoding_open Opening a media file ++ * The minimum information required to open a file is its URL or filename, which ++ * is passed to avformat_open_input(), as in the following code: ++ * @code ++ * const char *url = "in.mp3"; ++ * AVFormatContext *s = NULL; ++ * int ret = avformat_open_input(&s, url, NULL, NULL); ++ * if (ret < 0) ++ * abort(); ++ * @endcode ++ * The above code attempts to allocate an AVFormatContext, open the ++ * specified file (autodetecting the format) and read the header, exporting the ++ * information stored there into s. Some formats do not have a header or do not ++ * store enough information there, so it is recommended that you call the ++ * avformat_find_stream_info() function which tries to read and decode a few ++ * frames to find missing information. ++ * ++ * In some cases you might want to preallocate an AVFormatContext yourself with ++ * avformat_alloc_context() and do some tweaking on it before passing it to ++ * avformat_open_input(). One such case is when you want to use custom functions ++ * for reading input data instead of lavf internal I/O layer. ++ * To do that, create your own AVIOContext with avio_alloc_context(), passing ++ * your reading callbacks to it. Then set the @em pb field of your ++ * AVFormatContext to newly created AVIOContext. ++ * ++ * After you have finished reading the file, you must close it with ++ * avformat_close_input(). It will free everything associated with the file. ++ * ++ * @section lavf_decoding_read Reading from an opened file ++ * ++ * @section lavf_decoding_seek Seeking ++ * @} ++ * ++ * @defgroup lavf_encoding Muxing ++ * @{ ++ * @} ++ * ++ * @defgroup lavf_io I/O Read/Write ++ * @{ ++ * @} ++ * ++ * @defgroup lavf_codec Demuxers ++ * @{ ++ * @defgroup lavf_codec_native Native Demuxers ++ * @{ ++ * @} ++ * @defgroup lavf_codec_wrappers External library wrappers ++ * @{ ++ * @} ++ * @} ++ * @defgroup lavf_protos I/O Protocols ++ * @{ ++ * @} ++ * @defgroup lavf_internal Internal ++ * @{ ++ * @} ++ * @} ++ * + */ +-const char *avformat_license(void); + + #include + #include /* FILE */ + #include "libavcodec/avcodec.h" ++#include "libavutil/dict.h" ++#include "libavutil/log.h" + + #include "avio.h" + #include "libavformat/version.h" +@@ -48,78 +147,97 @@ + struct AVFormatContext; + + +-/* +- * Public Metadata API. ++/** ++ * @defgroup metadata_api Public Metadata API ++ * @{ ++ * @ingroup libavf + * The metadata API allows libavformat to export metadata tags to a client +- * application using a sequence of key/value pairs. Like all strings in FFmpeg, +- * metadata must be stored as UTF-8 encoded Unicode. Note that metadata ++ * application when demuxing. Conversely it allows a client application to ++ * set metadata when muxing. ++ * ++ * Metadata is exported or set as pairs of key/value strings in the 'metadata' ++ * fields of the AVFormatContext, AVStream, AVChapter and AVProgram structs ++ * using the @ref lavu_dict "AVDictionary" API. Like all strings in FFmpeg, ++ * metadata is assumed to be UTF-8 encoded Unicode. Note that metadata + * exported by demuxers isn't checked to be valid UTF-8 in most cases. ++ * + * Important concepts to keep in mind: +- * 1. Keys are unique; there can never be 2 tags with the same key. This is ++ * - Keys are unique; there can never be 2 tags with the same key. This is + * also meant semantically, i.e., a demuxer should not knowingly produce + * several keys that are literally different but semantically identical. + * E.g., key=Author5, key=Author6. In this example, all authors must be + * placed in the same tag. +- * 2. Metadata is flat, not hierarchical; there are no subtags. If you ++ * - Metadata is flat, not hierarchical; there are no subtags. If you + * want to store, e.g., the email address of the child of producer Alice + * and actor Bob, that could have key=alice_and_bobs_childs_email_address. +- * 3. Several modifiers can be applied to the tag name. This is done by ++ * - Several modifiers can be applied to the tag name. This is done by + * appending a dash character ('-') and the modifier name in the order + * they appear in the list below -- e.g. foo-eng-sort, not foo-sort-eng. +- * a) language -- a tag whose value is localized for a particular language ++ * - language -- a tag whose value is localized for a particular language + * is appended with the ISO 639-2/B 3-letter language code. + * For example: Author-ger=Michael, Author-eng=Mike + * The original/default language is in the unqualified "Author" tag. + * A demuxer should set a default if it sets any translated tag. +- * b) sorting -- a modified version of a tag that should be used for ++ * - sorting -- a modified version of a tag that should be used for + * sorting will have '-sort' appended. E.g. artist="The Beatles", + * artist-sort="Beatles, The". + * +- * 4. Demuxers attempt to export metadata in a generic format, however tags ++ * - Demuxers attempt to export metadata in a generic format, however tags + * with no generic equivalents are left as they are stored in the container. + * Follows a list of generic tag names: + * +- * album -- name of the set this work belongs to +- * album_artist -- main creator of the set/album, if different from artist. +- * e.g. "Various Artists" for compilation albums. +- * artist -- main creator of the work +- * comment -- any additional description of the file. +- * composer -- who composed the work, if different from artist. +- * copyright -- name of copyright holder. +- * creation_time-- date when the file was created, preferably in ISO 8601. +- * date -- date when the work was created, preferably in ISO 8601. +- * disc -- number of a subset, e.g. disc in a multi-disc collection. +- * encoder -- name/settings of the software/hardware that produced the file. +- * encoded_by -- person/group who created the file. +- * filename -- original name of the file. +- * genre -- . +- * language -- main language in which the work is performed, preferably +- * in ISO 639-2 format. +- * performer -- artist who performed the work, if different from artist. +- * E.g for "Also sprach Zarathustra", artist would be "Richard +- * Strauss" and performer "London Philharmonic Orchestra". +- * publisher -- name of the label/publisher. +- * service_name -- name of the service in broadcasting (channel name). +- * service_provider -- name of the service provider in broadcasting. +- * title -- name of the work. +- * track -- number of this work in the set, can be in form current/total. +- */ +- +-#define AV_METADATA_MATCH_CASE 1 +-#define AV_METADATA_IGNORE_SUFFIX 2 +-#define AV_METADATA_DONT_STRDUP_KEY 4 +-#define AV_METADATA_DONT_STRDUP_VAL 8 +-#define AV_METADATA_DONT_OVERWRITE 16 ///< Don't overwrite existing tags. +- +-typedef struct { +- char *key; +- char *value; +-}AVMetadataTag; ++ @verbatim ++ album -- name of the set this work belongs to ++ album_artist -- main creator of the set/album, if different from artist. ++ e.g. "Various Artists" for compilation albums. ++ artist -- main creator of the work ++ comment -- any additional description of the file. ++ composer -- who composed the work, if different from artist. ++ copyright -- name of copyright holder. ++ creation_time-- date when the file was created, preferably in ISO 8601. ++ date -- date when the work was created, preferably in ISO 8601. ++ disc -- number of a subset, e.g. disc in a multi-disc collection. ++ encoder -- name/settings of the software/hardware that produced the file. ++ encoded_by -- person/group who created the file. ++ filename -- original name of the file. ++ genre -- . ++ language -- main language in which the work is performed, preferably ++ in ISO 639-2 format. Multiple languages can be specified by ++ separating them with commas. ++ performer -- artist who performed the work, if different from artist. ++ E.g for "Also sprach Zarathustra", artist would be "Richard ++ Strauss" and performer "London Philharmonic Orchestra". ++ publisher -- name of the label/publisher. ++ service_name -- name of the service in broadcasting (channel name). ++ service_provider -- name of the service provider in broadcasting. ++ title -- name of the work. ++ track -- number of this work in the set, can be in form current/total. ++ variant_bitrate -- the total bitrate of the bitrate variant that the current stream is part of ++ @endverbatim ++ * ++ * Look in the examples section for an application example how to use the Metadata API. ++ * ++ * @} ++ */ ++ ++#if FF_API_OLD_METADATA2 ++/** ++ * @defgroup old_metadata Old metadata API ++ * The following functions are deprecated, use ++ * their equivalents from libavutil/dict.h instead. ++ * @{ ++ */ ++ ++#define AV_METADATA_MATCH_CASE AV_DICT_MATCH_CASE ++#define AV_METADATA_IGNORE_SUFFIX AV_DICT_IGNORE_SUFFIX ++#define AV_METADATA_DONT_STRDUP_KEY AV_DICT_DONT_STRDUP_KEY ++#define AV_METADATA_DONT_STRDUP_VAL AV_DICT_DONT_STRDUP_VAL ++#define AV_METADATA_DONT_OVERWRITE AV_DICT_DONT_OVERWRITE ++ ++typedef attribute_deprecated AVDictionary AVMetadata; ++typedef attribute_deprecated AVDictionaryEntry AVMetadataTag; + +-typedef struct AVMetadata AVMetadata; +-#if FF_API_OLD_METADATA + typedef struct AVMetadataConv AVMetadataConv; +-#endif + + /** + * Get a metadata element with matching key. +@@ -129,22 +247,8 @@ + * @param flags Allows case as well as suffix-insensitive comparisons. + * @return Found tag or NULL, changing key or value leads to undefined behavior. + */ +-AVMetadataTag * +-av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags); +- +-#if FF_API_OLD_METADATA +-/** +- * Set the given tag in *pm, overwriting an existing tag. +- * +- * @param pm pointer to a pointer to a metadata struct. If *pm is NULL +- * a metadata struct is allocated and put in *pm. +- * @param key tag key to add to *pm (will be av_strduped) +- * @param value tag value to add to *pm (will be av_strduped) +- * @return >= 0 on success otherwise an error code <0 +- * @deprecated Use av_metadata_set2() instead. +- */ +-attribute_deprecated int av_metadata_set(AVMetadata **pm, const char *key, const char *value); +-#endif ++attribute_deprecated AVDictionaryEntry * ++av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags); + + /** + * Set the given tag in *pm, overwriting an existing tag. +@@ -156,30 +260,32 @@ + * Passing a NULL value will cause an existing tag to be deleted. + * @return >= 0 on success otherwise an error code <0 + */ +-int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags); ++attribute_deprecated int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags); + +-#if FF_API_OLD_METADATA + /** + * This function is provided for compatibility reason and currently does nothing. + */ + attribute_deprecated void av_metadata_conv(struct AVFormatContext *ctx, const AVMetadataConv *d_conv, + const AVMetadataConv *s_conv); +-#endif + + /** +- * Copy metadata from one AVMetadata struct into another. +- * @param dst pointer to a pointer to a AVMetadata struct. If *dst is NULL, ++ * Copy metadata from one AVDictionary struct into another. ++ * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL, + * this function will allocate a struct for you and put it in *dst +- * @param src pointer to source AVMetadata struct ++ * @param src pointer to source AVDictionary struct + * @param flags flags to use when setting metadata in *dst +- * @note metadata is read using the AV_METADATA_IGNORE_SUFFIX flag ++ * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag + */ +-void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags); ++attribute_deprecated void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags); + + /** +- * Free all the memory allocated for an AVMetadata struct. ++ * Free all the memory allocated for an AVDictionary struct. ++ */ ++attribute_deprecated void av_metadata_free(AVDictionary **m); ++/** ++ * @} + */ +-void av_metadata_free(AVMetadata **m); ++#endif + + + /* packet functions */ +@@ -193,7 +299,7 @@ + * @param size desired payload size + * @return >0 (read size) if OK, AVERROR_xxx otherwise + */ +-int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size); ++int av_get_packet(AVIOContext *s, AVPacket *pkt, int size); + + + /** +@@ -209,7 +315,7 @@ + * @return >0 (read size) if OK, AVERROR_xxx otherwise, previous data + * will not be lost even if an error occurs. + */ +-int av_append_packet(ByteIOContext *s, AVPacket *pkt, int size); ++int av_append_packet(AVIOContext *s, AVPacket *pkt, int size); + + /*************************************************/ + /* fractional numbers for exact pts handling */ +@@ -240,28 +346,25 @@ + #define AVPROBE_PADDING_SIZE 32 ///< extra allocated bytes at the end of the probe buffer + + typedef struct AVFormatParameters { +- AVRational time_base; +- int sample_rate; +- int channels; +- int width; +- int height; +- enum PixelFormat pix_fmt; +- int channel; /**< Used to select DV channel. */ +- const char *standard; /**< TV standard, NTSC, PAL, SECAM */ +- unsigned int mpeg2ts_raw:1; /**< Force raw MPEG-2 transport stream output, if possible. */ +- unsigned int mpeg2ts_compute_pcr:1; /**< Compute exact PCR for each transport +- stream packet (only meaningful if +- mpeg2ts_raw is TRUE). */ +- unsigned int initial_pause:1; /**< Do not begin to play the stream +- immediately (RTSP only). */ +- unsigned int prealloced_context:1; +-#if FF_API_PARAMETERS_CODEC_ID +- attribute_deprecated enum CodecID video_codec_id; +- attribute_deprecated enum CodecID audio_codec_id; ++#if FF_API_FORMAT_PARAMETERS ++ attribute_deprecated AVRational time_base; ++ attribute_deprecated int sample_rate; ++ attribute_deprecated int channels; ++ attribute_deprecated int width; ++ attribute_deprecated int height; ++ attribute_deprecated enum PixelFormat pix_fmt; ++ attribute_deprecated int channel; /**< Used to select DV channel. */ ++ attribute_deprecated const char *standard; /**< deprecated, use demuxer-specific options instead. */ ++ attribute_deprecated unsigned int mpeg2ts_raw:1; /**< deprecated, use mpegtsraw demuxer */ ++ /**< deprecated, use mpegtsraw demuxer-specific options instead */ ++ attribute_deprecated unsigned int mpeg2ts_compute_pcr:1; ++ attribute_deprecated unsigned int initial_pause:1; /**< Do not begin to play the stream ++ immediately (RTSP only). */ ++ attribute_deprecated unsigned int prealloced_context:1; + #endif + } AVFormatParameters; + +-//! Demuxer will use url_fopen, no opened file should be provided by the caller. ++/// Demuxer will use avio_open, no opened file should be provided by the caller. + #define AVFMT_NOFILE 0x0001 + #define AVFMT_NEEDNUMBER 0x0002 /**< Needs '%d' in filename. */ + #define AVFMT_SHOW_IDS 0x0008 /**< Show format stream IDs numbers. */ +@@ -274,7 +377,18 @@ + #define AVFMT_VARIABLE_FPS 0x0400 /**< Format allows variable fps. */ + #define AVFMT_NODIMENSIONS 0x0800 /**< Format does not need width/height */ + #define AVFMT_NOSTREAMS 0x1000 /**< Format does not require any streams */ ++#define AVFMT_NOBINSEARCH 0x2000 /**< Format does not allow to fallback to binary search via read_timestamp */ ++#define AVFMT_NOGENSEARCH 0x4000 /**< Format does not allow to fallback to generic search */ ++#define AVFMT_NO_BYTE_SEEK 0x8000 /**< Format does not allow seeking by bytes */ ++#define AVFMT_ALLOW_FLUSH 0x10000 /**< Format allows flushing. If not set, the muxer will not receive a NULL packet in the write_packet function. */ ++#define AVFMT_TS_NONSTRICT 0x8000000 /**< Format does not require strictly ++ increasing timestamps, but they must ++ still be monotonic */ + ++/** ++ * @addtogroup lavf_encoding ++ * @{ ++ */ + typedef struct AVOutputFormat { + const char *name; + /** +@@ -293,16 +407,24 @@ + enum CodecID audio_codec; /**< default audio codec */ + enum CodecID video_codec; /**< default video codec */ + int (*write_header)(struct AVFormatContext *); ++ /** ++ * Write a packet. If AVFMT_ALLOW_FLUSH is set in flags, ++ * pkt can be NULL in order to flush data buffered in the muxer. ++ * When flushing, return 0 if there still is more data to flush, ++ * or 1 if everything was flushed and there is no more buffered ++ * data. ++ */ + int (*write_packet)(struct AVFormatContext *, AVPacket *pkt); + int (*write_trailer)(struct AVFormatContext *); + /** +- * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_GLOBALHEADER ++ * can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_RAWPICTURE, ++ * AVFMT_GLOBALHEADER, AVFMT_NOTIMESTAMPS, AVFMT_VARIABLE_FPS, ++ * AVFMT_NODIMENSIONS, AVFMT_NOSTREAMS, AVFMT_ALLOW_FLUSH + */ + int flags; +- /** +- * Currently only used to set pixel format if not YUV420P. +- */ +- int (*set_parameters)(struct AVFormatContext *, AVFormatParameters *); ++ ++ void *dummy; ++ + int (*interleave_packet)(struct AVFormatContext *, AVPacket *out, + AVPacket *in, int flush); + +@@ -314,16 +436,34 @@ + + enum CodecID subtitle_codec; /**< default subtitle codec */ + +-#if FF_API_OLD_METADATA ++#if FF_API_OLD_METADATA2 + const AVMetadataConv *metadata_conv; + #endif + + const AVClass *priv_class; ///< AVClass for the private context + ++ /** ++ * Test if the given codec can be stored in this container. ++ * ++ * @return 1 if the codec is supported, 0 if it is not. ++ * A negative number if unknown. ++ */ ++ int (*query_codec)(enum CodecID id, int std_compliance); ++ ++ void (*get_output_timestamp)(struct AVFormatContext *s, int stream, ++ int64_t *dts, int64_t *wall); ++ + /* private fields */ + struct AVOutputFormat *next; + } AVOutputFormat; ++/** ++ * @} ++ */ + ++/** ++ * @addtogroup lavf_decoding ++ * @{ ++ */ + typedef struct AVInputFormat { + /** + * A comma separated list of short names for the format. New names +@@ -376,7 +516,6 @@ + */ + int (*read_close)(struct AVFormatContext *); + +-#if FF_API_READ_SEEK + /** + * Seek to a given timestamp relative to the frames in + * stream component stream_index. +@@ -385,18 +524,20 @@ + * match is available. + * @return >= 0 on success (but not necessarily the new offset) + */ +- attribute_deprecated int (*read_seek)(struct AVFormatContext *, +- int stream_index, int64_t timestamp, int flags); +-#endif ++ int (*read_seek)(struct AVFormatContext *, ++ int stream_index, int64_t timestamp, int flags); ++ + /** +- * Gets the next timestamp in stream[stream_index].time_base units. ++ * Get the next timestamp in stream[stream_index].time_base units. + * @return the timestamp or AV_NOPTS_VALUE if an error occurred + */ + int64_t (*read_timestamp)(struct AVFormatContext *s, int stream_index, + int64_t *pos, int64_t pos_limit); + + /** +- * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER. ++ * Can use flags: AVFMT_NOFILE, AVFMT_NEEDNUMBER, AVFMT_SHOW_IDS, ++ * AVFMT_GENERIC_INDEX, AVFMT_TS_DISCONT, AVFMT_NOBINSEARCH, ++ * AVFMT_NOGENSEARCH, AVFMT_NO_BYTE_SEEK. + */ + int flags; + +@@ -434,13 +575,18 @@ + */ + int (*read_seek2)(struct AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags); + +-#if FF_API_OLD_METADATA ++#if FF_API_OLD_METADATA2 + const AVMetadataConv *metadata_conv; + #endif + ++ const AVClass *priv_class; ///< AVClass for the private context ++ + /* private fields */ + struct AVInputFormat *next; + } AVInputFormat; ++/** ++ * @} ++ */ + + enum AVStreamParseType { + AVSTREAM_PARSE_NONE, +@@ -452,7 +598,12 @@ + + typedef struct AVIndexEntry { + int64_t pos; +- int64_t timestamp; ++ int64_t timestamp; /**< ++ * Timestamp in AVStream.time_base units, preferably the time from which on correctly decoded frames are available ++ * when seeking to this entry. That means preferable PTS on keyframe based formats. ++ * But demuxers can choose to store a different timestamp, if it is more convenient for the implementation or nothing better ++ * is known ++ */ + #define AVINDEX_KEYFRAME 0x0001 + int flags:2; + int size:30; //Yeah, trying to keep the size of this small to reduce memory requirements (it is 24 vs. 32 bytes due to possible 8-byte alignment). +@@ -472,6 +623,9 @@ + * even when user did not explicitly ask for subtitles. + */ + #define AV_DISPOSITION_FORCED 0x0040 ++#define AV_DISPOSITION_HEARING_IMPAIRED 0x0080 /**< stream for hearing impaired audiences */ ++#define AV_DISPOSITION_VISUAL_IMPAIRED 0x0100 /**< stream for visual impaired audiences */ ++#define AV_DISPOSITION_CLEAN_EFFECTS 0x0200 /**< stream without voice */ + + /** + * Stream structure. +@@ -495,8 +649,10 @@ + AVRational r_frame_rate; + void *priv_data; + ++#if FF_API_REORDER_PRIVATE + /* internal data used in av_find_stream_info() */ + int64_t first_dts; ++#endif + + /** + * encoding: pts generation when outputting stream +@@ -507,22 +663,30 @@ + * This is the fundamental unit of time (in seconds) in terms + * of which frame timestamps are represented. For fixed-fps content, + * time base should be 1/framerate and timestamp increments should be 1. ++ * decoding: set by libavformat ++ * encoding: set by libavformat in av_write_header + */ + AVRational time_base; ++#if FF_API_REORDER_PRIVATE + int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ ++#endif ++#if FF_API_STREAM_COPY + /* ffmpeg.c private use */ +- int stream_copy; /**< If set, just copy stream. */ ++ attribute_deprecated int stream_copy; /**< If set, just copy stream. */ ++#endif + enum AVDiscard discard; ///< Selects which packets can be discarded at will and do not need to be demuxed. + ++#if FF_API_AVSTREAM_QUALITY + //FIXME move stuff to a flags field? + /** + * Quality, as it has been removed from AVCodecContext and put in AVVideoFrame. + * MN: dunno if that is the right place for it + */ +- float quality; ++ attribute_deprecated float quality; ++#endif + + /** +- * Decoding: pts of the first frame of the stream, in stream time base. ++ * Decoding: pts of the first frame of the stream in presentation order, in stream time base. + * Only set this if you are absolutely 100% sure that the value you set + * it to really is the pts of the first frame. + * This may be undefined (AV_NOPTS_VALUE). +@@ -538,10 +702,7 @@ + */ + int64_t duration; + +-#if FF_API_OLD_METADATA +- attribute_deprecated char language[4]; /**< ISO 639-2/B 3-letter language code (empty string if undefined) */ +-#endif +- ++#if FF_API_REORDER_PRIVATE + /* av_read_frame() support */ + enum AVStreamParseType need_parsing; + struct AVCodecParserContext *parser; +@@ -554,22 +715,17 @@ + support seeking natively. */ + int nb_index_entries; + unsigned int index_entries_allocated_size; +- +- int64_t nb_frames; ///< number of frames in this stream if known or 0 +- +-#if FF_API_LAVF_UNUSED +- attribute_deprecated int64_t unused[4+1]; + #endif + +-#if FF_API_OLD_METADATA +- attribute_deprecated char *filename; /**< source filename of the stream */ +-#endif ++ int64_t nb_frames; ///< number of frames in this stream if known or 0 + + int disposition; /**< AV_DISPOSITION_* bit field */ + ++#if FF_API_REORDER_PRIVATE + AVProbeData probe_data; + #define MAX_REORDER_DELAY 16 + int64_t pts_buffer[MAX_REORDER_DELAY+1]; ++#endif + + /** + * sample aspect ratio (0 if unknown) +@@ -578,8 +734,9 @@ + */ + AVRational sample_aspect_ratio; + +- AVMetadata *metadata; ++ AVDictionary *metadata; + ++#if FF_API_REORDER_PRIVATE + /* Intended mostly for av_read_frame() support. Not supposed to be used by */ + /* external applications; try to use something else if at all possible. */ + const uint8_t *cur_ptr; +@@ -605,31 +762,101 @@ + + /** + * last packet in packet_buffer for this stream when muxing. +- * used internally, NOT PART OF PUBLIC API, dont read or write from outside of libav* ++ * Used internally, NOT PART OF PUBLIC API, do not read or ++ * write from outside of libav* + */ + struct AVPacketList *last_in_packet_buffer; ++#endif + + /** + * Average framerate + */ + AVRational avg_frame_rate; + ++ /***************************************************************** ++ * All fields below this line are not part of the public API. They ++ * may not be used outside of libavformat and can be changed and ++ * removed at will. ++ * New public fields should be added right above. ++ ***************************************************************** ++ */ ++ + /** + * Number of frames that have been demuxed during av_find_stream_info() + */ + int codec_info_nb_frames; + + /** +- * Stream informations used internally by av_find_stream_info() ++ * Stream Identifier ++ * This is the MPEG-TS stream identifier +1 ++ * 0 means unknown ++ */ ++ int stream_identifier; ++ ++ int64_t interleaver_chunk_size; ++ int64_t interleaver_chunk_duration; ++ ++ /** ++ * Stream information used internally by av_find_stream_info() + */ + #define MAX_STD_TIMEBASES (60*12+5) + struct { + int64_t last_dts; + int64_t duration_gcd; + int duration_count; +- double duration_error[MAX_STD_TIMEBASES]; ++ double duration_error[2][2][MAX_STD_TIMEBASES]; + int64_t codec_info_duration; ++ int nb_decoded_frames; + } *info; ++ ++ /** ++ * flag to indicate that probing is requested ++ * NOT PART OF PUBLIC API ++ */ ++ int request_probe; ++#if !FF_API_REORDER_PRIVATE ++ const uint8_t *cur_ptr; ++ int cur_len; ++ AVPacket cur_pkt; ++ ++ // Timestamp generation support: ++ /** ++ * Timestamp corresponding to the last dts sync point. ++ * ++ * Initialized when AVCodecParserContext.dts_sync_point >= 0 and ++ * a DTS is received from the underlying container. Otherwise set to ++ * AV_NOPTS_VALUE by default. ++ */ ++ int64_t reference_dts; ++ int64_t first_dts; ++ int64_t cur_dts; ++ int last_IP_duration; ++ int64_t last_IP_pts; ++ ++ /** ++ * Number of packets to buffer for codec probing ++ */ ++#define MAX_PROBE_PACKETS 2500 ++ int probe_packets; ++ ++ /** ++ * last packet in packet_buffer for this stream when muxing. ++ */ ++ struct AVPacketList *last_in_packet_buffer; ++ AVProbeData probe_data; ++#define MAX_REORDER_DELAY 16 ++ int64_t pts_buffer[MAX_REORDER_DELAY+1]; ++ /* av_read_frame() support */ ++ enum AVStreamParseType need_parsing; ++ struct AVCodecParserContext *parser; ++ ++ AVIndexEntry *index_entries; /**< Only used if the format does not ++ support seeking natively. */ ++ int nb_index_entries; ++ unsigned int index_entries_allocated_size; ++ ++ int pts_wrap_bits; /**< number of bits in pts (used for wrapping control) */ ++#endif + } AVStream; + + #define AV_PROGRAM_RUNNING 1 +@@ -642,15 +869,15 @@ + */ + typedef struct AVProgram { + int id; +-#if FF_API_OLD_METADATA +- attribute_deprecated char *provider_name; ///< network name for DVB streams +- attribute_deprecated char *name; ///< service name for DVB streams +-#endif + int flags; + enum AVDiscard discard; ///< selects which program to discard and which to feed to the caller + unsigned int *stream_index; + unsigned int nb_stream_indexes; +- AVMetadata *metadata; ++ AVDictionary *metadata; ++ ++ int program_num; ++ int pmt_pid; ++ int pcr_pid; + } AVProgram; + + #define AVFMTCTX_NOHEADER 0x0001 /**< signal that no header is present +@@ -660,51 +887,75 @@ + int id; ///< unique ID to identify the chapter + AVRational time_base; ///< time base in which the start/end timestamps are specified + int64_t start, end; ///< chapter start/end time in time_base units +-#if FF_API_OLD_METADATA +- attribute_deprecated char *title; ///< chapter title +-#endif +- AVMetadata *metadata; ++ AVDictionary *metadata; + } AVChapter; + +-#if FF_API_MAX_STREAMS +-#define MAX_STREAMS 100 +-#endif +- + /** + * Format I/O context. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. +- * sizeof(AVFormatContext) must not be used outside libav*. ++ * sizeof(AVFormatContext) must not be used outside libav*, use ++ * avformat_alloc_context() to create an AVFormatContext. + */ + typedef struct AVFormatContext { +- const AVClass *av_class; /**< Set by avformat_alloc_context. */ +- /* Can only be iformat or oformat, not both at the same time. */ ++ /** ++ * A class for logging and AVOptions. Set by avformat_alloc_context(). ++ * Exports (de)muxer private options if they exist. ++ */ ++ const AVClass *av_class; ++ ++ /** ++ * Can only be iformat or oformat, not both at the same time. ++ * ++ * decoding: set by avformat_open_input(). ++ * encoding: set by the user. ++ */ + struct AVInputFormat *iformat; + struct AVOutputFormat *oformat; ++ ++ /** ++ * Format private data. This is an AVOptions-enabled struct ++ * if and only if iformat/oformat.priv_class is not NULL. ++ */ + void *priv_data; +- ByteIOContext *pb; ++ ++ /* ++ * I/O context. ++ * ++ * decoding: either set by the user before avformat_open_input() (then ++ * the user must close it manually) or set by avformat_open_input(). ++ * encoding: set by the user. ++ * ++ * Do NOT set this field if AVFMT_NOFILE flag is set in ++ * iformat/oformat.flags. In such a case, the (de)muxer will handle ++ * I/O in some other way and this field will be NULL. ++ */ ++ AVIOContext *pb; ++ ++ /** ++ * A list of all streams in the file. New streams are created with ++ * avformat_new_stream(). ++ * ++ * decoding: streams are created by libavformat in avformat_open_input(). ++ * If AVFMTCTX_NOHEADER is set in ctx_flags, then new streams may also ++ * appear in av_read_frame(). ++ * encoding: streams are created by the user before avformat_write_header(). ++ */ + unsigned int nb_streams; +-#if FF_API_MAX_STREAMS +- AVStream *streams[MAX_STREAMS]; +-#else + AVStream **streams; +-#endif ++ + char filename[1024]; /**< input or output filename */ + /* stream info */ +- int64_t timestamp; +-#if FF_API_OLD_METADATA +- attribute_deprecated char title[512]; +- attribute_deprecated char author[512]; +- attribute_deprecated char copyright[512]; +- attribute_deprecated char comment[512]; +- attribute_deprecated char album[512]; +- attribute_deprecated int year; /**< ID3 year, 0 if none */ +- attribute_deprecated int track; /**< track number, 0 if none */ +- attribute_deprecated char genre[32]; /**< ID3 genre */ ++#if FF_API_TIMESTAMP ++ /** ++ * @deprecated use 'creation_time' metadata tag instead ++ */ ++ attribute_deprecated int64_t timestamp; + #endif + + int ctx_flags; /**< Format-specific flags, see AVFMTCTX_xx */ ++#if FF_API_REORDER_PRIVATE + /* private data for pts handling (do not modify directly). */ + /** + * This buffer is only needed when packets were already buffered but +@@ -712,6 +963,7 @@ + * streams. + */ + struct AVPacketList *packet_buffer; ++#endif + + /** + * Decoding: position of the first frame of the component, in +@@ -723,15 +975,17 @@ + /** + * Decoding: duration of the stream, in AV_TIME_BASE fractional + * seconds. Only set this value if you know none of the individual stream +- * durations and also dont set any of them. This is deduced from the ++ * durations and also do not set any of them. This is deduced from the + * AVStream values if not set. + */ + int64_t duration; + ++#if FF_API_FILESIZE + /** + * decoding: total file size, 0 if unknown + */ +- int64_t file_size; ++ attribute_deprecated int64_t file_size; ++#endif + + /** + * Decoding: total stream bitrate in bit/s, 0 if not +@@ -740,29 +994,36 @@ + */ + int bit_rate; + ++#if FF_API_REORDER_PRIVATE + /* av_read_frame() support */ + AVStream *cur_st; +-#if FF_API_LAVF_UNUSED +- const uint8_t *cur_ptr_deprecated; +- int cur_len_deprecated; +- AVPacket cur_pkt_deprecated; +-#endif + + /* av_seek_frame() support */ + int64_t data_offset; /**< offset of the first packet */ +- int index_built; ++#endif + +- int mux_rate; ++#if FF_API_MUXRATE ++ /** ++ * use mpeg muxer private options instead ++ */ ++ attribute_deprecated int mux_rate; ++#endif + unsigned int packet_size; +- int preload; ++#if FF_API_PRELOAD ++ attribute_deprecated int preload; ++#endif + int max_delay; + ++#if FF_API_LOOP_OUTPUT + #define AVFMT_NOOUTPUTLOOP -1 + #define AVFMT_INFINITEOUTPUTLOOP 0 + /** + * number of times to loop output in formats that support it ++ * ++ * @deprecated use the 'loop' private option in the gif muxer. + */ +- int loop_output; ++ attribute_deprecated int loop_output; ++#endif + + int flags; + #define AVFMT_FLAG_GENPTS 0x0001 ///< Generate missing pts even if it requires parsing future frames. +@@ -771,9 +1032,22 @@ + #define AVFMT_FLAG_IGNDTS 0x0008 ///< Ignore DTS on frames that contain both DTS & PTS + #define AVFMT_FLAG_NOFILLIN 0x0010 ///< Do not infer any values from other values, just return what is stored in the container + #define AVFMT_FLAG_NOPARSE 0x0020 ///< Do not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fillin code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled +-#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Add RTP hinting to the output file ++#if FF_API_FLAG_RTP_HINT ++#define AVFMT_FLAG_RTP_HINT 0x0040 ///< Deprecated, use the -movflags rtphint muxer specific AVOption instead ++#endif ++#define AVFMT_FLAG_CUSTOM_IO 0x0080 ///< The caller has supplied a custom AVIOContext, don't avio_close() it. ++#define AVFMT_FLAG_DISCARD_CORRUPT 0x0100 ///< Discard frames marked corrupted ++#define AVFMT_FLAG_MP4A_LATM 0x8000 ///< Enable RTP MP4A-LATM payload ++#define AVFMT_FLAG_SORT_DTS 0x10000 ///< try to interleave outputted packets by dts (using this flag can slow demuxing down) ++#define AVFMT_FLAG_PRIV_OPT 0x20000 ///< Enable use of private options by delaying codec open (this could be made default once all code is converted) ++#define AVFMT_FLAG_KEEP_SIDE_DATA 0x40000 ///< Dont merge side data but keep it seperate. + +- int loop_input; ++#if FF_API_LOOP_INPUT ++ /** ++ * @deprecated, use the 'loop' img2 demuxer private option. ++ */ ++ attribute_deprecated int loop_input; ++#endif + + /** + * decoding: size of data to probe; encoding: unused. +@@ -781,8 +1055,8 @@ + unsigned int probesize; + + /** +- * Maximum time (in AV_TIME_BASE units) during which the input should +- * be analyzed in av_find_stream_info(). ++ * decoding: maximum time (in AV_TIME_BASE units) during which the input should ++ * be analyzed in avformat_find_stream_info(). + */ + int max_analyze_duration; + +@@ -837,6 +1111,7 @@ + int debug; + #define FF_FDEBUG_TS 0x0001 + ++#if FF_API_REORDER_PRIVATE + /** + * Raw packets from the demuxer, prior to parsing and decoding. + * This buffer is used for buffering packets until the codec can +@@ -847,15 +1122,18 @@ + struct AVPacketList *raw_packet_buffer_end; + + struct AVPacketList *packet_buffer_end; ++#endif + +- AVMetadata *metadata; ++ AVDictionary *metadata; + ++#if FF_API_REORDER_PRIVATE + /** + * Remaining size available for raw_packet_buffer, in bytes. + * NOT PART OF PUBLIC API + */ + #define RAW_PACKET_BUFFER_SIZE 2500000 + int raw_packet_buffer_remaining_size; ++#endif + + /** + * Start time of the stream in real world time, in microseconds +@@ -865,6 +1143,97 @@ + * - decoding: Unused. + */ + int64_t start_time_realtime; ++ ++ /** ++ * decoding: number of frames used to probe fps ++ */ ++ int fps_probe_size; ++ ++ /** ++ * Error recognition; higher values will detect more errors but may ++ * misdetect some more or less valid parts as errors. ++ * - encoding: unused ++ * - decoding: Set by user. ++ */ ++ int error_recognition; ++ ++ /** ++ * Custom interrupt callbacks for the I/O layer. ++ * ++ * decoding: set by the user before avformat_open_input(). ++ * encoding: set by the user before avformat_write_header() ++ * (mainly useful for AVFMT_NOFILE formats). The callback ++ * should also be passed to avio_open2() if it's used to ++ * open the file. ++ */ ++ AVIOInterruptCB interrupt_callback; ++ ++ /** ++ * Transport stream id. ++ * This will be moved into demuxer private options. Thus no API/ABI compatibility ++ */ ++ int ts_id; ++ ++ /** ++ * Audio preload in microseconds. ++ * Note, not all formats support this and unpredictable things may happen if it is used when not supported. ++ * - encoding: Set by user via AVOptions (NO direct access) ++ * - decoding: unused ++ */ ++ int audio_preload; ++ ++ /** ++ * Max chunk time in microseconds. ++ * Note, not all formats support this and unpredictable things may happen if it is used when not supported. ++ * - encoding: Set by user via AVOptions (NO direct access) ++ * - decoding: unused ++ */ ++ int max_chunk_duration; ++ ++ /** ++ * Max chunk size in bytes ++ * Note, not all formats support this and unpredictable things may happen if it is used when not supported. ++ * - encoding: Set by user via AVOptions (NO direct access) ++ * - decoding: unused ++ */ ++ int max_chunk_size; ++ ++ /***************************************************************** ++ * All fields below this line are not part of the public API. They ++ * may not be used outside of libavformat and can be changed and ++ * removed at will. ++ * New public fields should be added right above. ++ ***************************************************************** ++ */ ++#if !FF_API_REORDER_PRIVATE ++ /** ++ * Raw packets from the demuxer, prior to parsing and decoding. ++ * This buffer is used for buffering packets until the codec can ++ * be identified, as parsing cannot be done without knowing the ++ * codec. ++ */ ++ struct AVPacketList *raw_packet_buffer; ++ struct AVPacketList *raw_packet_buffer_end; ++ /** ++ * Remaining size available for raw_packet_buffer, in bytes. ++ */ ++#define RAW_PACKET_BUFFER_SIZE 2500000 ++ int raw_packet_buffer_remaining_size; ++ ++ /** ++ * This buffer is only needed when packets were already buffered but ++ * not decoded, for example to get the codec parameters in MPEG ++ * streams. ++ */ ++ struct AVPacketList *packet_buffer; ++ struct AVPacketList *packet_buffer_end; ++ ++ /* av_read_frame() support */ ++ AVStream *cur_st; ++ ++ /* av_seek_frame() support */ ++ int64_t data_offset; /**< offset of the first packet */ ++#endif + } AVFormatContext; + + typedef struct AVPacketList { +@@ -872,145 +1241,163 @@ + struct AVPacketList *next; + } AVPacketList; + +-#if FF_API_FIRST_FORMAT +-attribute_deprecated extern AVInputFormat *first_iformat; +-attribute_deprecated extern AVOutputFormat *first_oformat; +-#endif + + /** +- * If f is NULL, returns the first registered input format, +- * if f is non-NULL, returns the next registered input format after f +- * or NULL if f is the last one. ++ * @defgroup lavf_core Core functions ++ * @ingroup libavf ++ * ++ * Functions for querying libavformat capabilities, allocating core structures, ++ * etc. ++ * @{ + */ +-AVInputFormat *av_iformat_next(AVInputFormat *f); + + /** +- * If f is NULL, returns the first registered output format, +- * if f is non-NULL, returns the next registered output format after f +- * or NULL if f is the last one. ++ * Return the LIBAVFORMAT_VERSION_INT constant. + */ +-AVOutputFormat *av_oformat_next(AVOutputFormat *f); ++unsigned avformat_version(void); + +-enum CodecID av_guess_image2_codec(const char *filename); ++/** ++ * Return the libavformat build-time configuration. ++ */ ++const char *avformat_configuration(void); ++ ++/** ++ * Return the libavformat license. ++ */ ++const char *avformat_license(void); + +-/* XXX: Use automatic init with either ELF sections or C file parser */ +-/* modules. */ ++/** ++ * Initialize libavformat and register all the muxers, demuxers and ++ * protocols. If you do not call this function, then you can select ++ * exactly which formats you want to support. ++ * ++ * @see av_register_input_format() ++ * @see av_register_output_format() ++ * @see av_register_protocol() ++ */ ++void av_register_all(void); + +-/* utils.c */ + void av_register_input_format(AVInputFormat *format); + void av_register_output_format(AVOutputFormat *format); +-#if FF_API_GUESS_FORMAT +-attribute_deprecated AVOutputFormat *guess_stream_format(const char *short_name, +- const char *filename, +- const char *mime_type); + + /** +- * @deprecated Use av_guess_format() instead. ++ * Do global initialization of network components. This is optional, ++ * but recommended, since it avoids the overhead of implicitly ++ * doing the setup for each session. ++ * ++ * Calling this function will become mandatory if using network ++ * protocols at some major version bump. + */ +-attribute_deprecated AVOutputFormat *guess_format(const char *short_name, +- const char *filename, +- const char *mime_type); +-#endif ++int avformat_network_init(void); + + /** +- * Return the output format in the list of registered output formats +- * which best matches the provided parameters, or return NULL if +- * there is no match. +- * +- * @param short_name if non-NULL checks if short_name matches with the +- * names of the registered formats +- * @param filename if non-NULL checks if filename terminates with the +- * extensions of the registered formats +- * @param mime_type if non-NULL checks if mime_type matches with the +- * MIME type of the registered formats ++ * Undo the initialization done by avformat_network_init. + */ +-AVOutputFormat *av_guess_format(const char *short_name, +- const char *filename, +- const char *mime_type); ++int avformat_network_deinit(void); + + /** +- * Guess the codec ID based upon muxer and filename. ++ * If f is NULL, returns the first registered input format, ++ * if f is non-NULL, returns the next registered input format after f ++ * or NULL if f is the last one. + */ +-enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, +- const char *filename, const char *mime_type, +- enum AVMediaType type); ++AVInputFormat *av_iformat_next(AVInputFormat *f); + + /** +- * Send a nice hexadecimal dump of a buffer to the specified file stream. +- * +- * @param f The file stream pointer where the dump should be sent to. +- * @param buf buffer +- * @param size buffer size +- * +- * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log ++ * If f is NULL, returns the first registered output format, ++ * if f is non-NULL, returns the next registered output format after f ++ * or NULL if f is the last one. + */ +-void av_hex_dump(FILE *f, uint8_t *buf, int size); ++AVOutputFormat *av_oformat_next(AVOutputFormat *f); + + /** +- * Send a nice hexadecimal dump of a buffer to the log. +- * +- * @param avcl A pointer to an arbitrary struct of which the first field is a +- * pointer to an AVClass struct. +- * @param level The importance level of the message, lower values signifying +- * higher importance. +- * @param buf buffer +- * @param size buffer size +- * +- * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log ++ * Allocate an AVFormatContext. ++ * avformat_free_context() can be used to free the context and everything ++ * allocated by the framework within it. + */ +-void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size); ++AVFormatContext *avformat_alloc_context(void); + + /** +- * Send a nice dump of a packet to the specified file stream. +- * +- * @param f The file stream pointer where the dump should be sent to. +- * @param pkt packet to dump +- * @param dump_payload True if the payload must be displayed, too. ++ * Free an AVFormatContext and all its streams. ++ * @param s context to free + */ +-void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); ++void avformat_free_context(AVFormatContext *s); + + /** +- * Send a nice dump of a packet to the log. ++ * Get the AVClass for AVFormatContext. It can be used in combination with ++ * AV_OPT_SEARCH_FAKE_OBJ for examining options. + * +- * @param avcl A pointer to an arbitrary struct of which the first field is a +- * pointer to an AVClass struct. +- * @param level The importance level of the message, lower values signifying +- * higher importance. +- * @param pkt packet to dump +- * @param dump_payload True if the payload must be displayed, too. ++ * @see av_opt_find(). + */ +-void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload); ++const AVClass *avformat_get_class(void); + + /** +- * Initialize libavformat and register all the muxers, demuxers and +- * protocols. If you do not call this function, then you can select +- * exactly which formats you want to support. ++ * Add a new stream to a media file. + * +- * @see av_register_input_format() +- * @see av_register_output_format() +- * @see av_register_protocol() ++ * When demuxing, it is called by the demuxer in read_header(). If the ++ * flag AVFMTCTX_NOHEADER is set in s.ctx_flags, then it may also ++ * be called in read_packet(). ++ * ++ * When muxing, should be called by the user before avformat_write_header(). ++ * ++ * @param c If non-NULL, the AVCodecContext corresponding to the new stream ++ * will be initialized to use this codec. This is needed for e.g. codec-specific ++ * defaults to be set, so codec should be provided if it is known. ++ * ++ * @return newly created stream or NULL on error. + */ +-void av_register_all(void); ++AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c); ++ ++AVProgram *av_new_program(AVFormatContext *s, int id); + + /** +- * Get the CodecID for the given codec tag tag. +- * If no codec id is found returns CODEC_ID_NONE. +- * +- * @param tags list of supported codec_id-codec_tag pairs, as stored +- * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag ++ * @} + */ +-enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag); + ++ ++#if FF_API_GUESS_IMG2_CODEC ++attribute_deprecated enum CodecID av_guess_image2_codec(const char *filename); ++#endif ++ ++#if FF_API_PKT_DUMP ++attribute_deprecated void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); ++attribute_deprecated void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, ++ int dump_payload); ++#endif ++ ++ ++#if FF_API_ALLOC_OUTPUT_CONTEXT + /** +- * Get the codec tag for the given codec id id. +- * If no codec tag is found returns 0. +- * +- * @param tags list of supported codec_id-codec_tag pairs, as stored +- * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag ++ * @deprecated deprecated in favor of avformat_alloc_output_context2() + */ +-unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id); ++attribute_deprecated ++AVFormatContext *avformat_alloc_output_context(const char *format, ++ AVOutputFormat *oformat, ++ const char *filename); ++#endif ++ ++/** ++ * Allocate an AVFormatContext for an output format. ++ * avformat_free_context() can be used to free the context and ++ * everything allocated by the framework within it. ++ * ++ * @param *ctx is set to the created format context, or to NULL in ++ * case of failure ++ * @param oformat format to use for allocating the context, if NULL ++ * format_name and filename are used instead ++ * @param format_name the name of output format to use for allocating the ++ * context, if NULL filename is used instead ++ * @param filename the name of the filename to use for allocating the ++ * context, may be NULL ++ * @return >= 0 in case of success, a negative AVERROR code in case of ++ * failure ++ */ ++int avformat_alloc_output_context2(AVFormatContext **ctx, AVOutputFormat *oformat, ++ const char *format_name, const char *filename); + +-/* media file input */ ++/** ++ * @addtogroup lavf_decoding ++ * @{ ++ */ + + /** + * Find AVInputFormat based on the short name of the input format. +@@ -1039,6 +1426,15 @@ + AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max); + + /** ++ * Guess the file format. ++ * ++ * @param is_opened Whether the file is already opened; determines whether ++ * demuxers with or without AVFMT_NOFILE are probed. ++ * @param score_ret The score of the best detection. ++ */ ++AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret); ++ ++/** + * Probe a bytestream to determine the input format. Each time a probe returns + * with a score that is too low, the probe buffer size is increased and another + * attempt is made. When the maximum probe size is reached, the input format +@@ -1053,16 +1449,18 @@ + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code otherwise + */ +-int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, ++int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, + const char *filename, void *logctx, + unsigned int offset, unsigned int max_probe_size); + ++#if FF_API_FORMAT_PARAMETERS + /** + * Allocate all the structures needed to read an input stream. + * This does not open the needed codecs for decoding the stream[s]. ++ * @deprecated use avformat_open_input instead. + */ +-int av_open_input_stream(AVFormatContext **ic_ptr, +- ByteIOContext *pb, const char *filename, ++attribute_deprecated int av_open_input_stream(AVFormatContext **ic_ptr, ++ AVIOContext *pb, const char *filename, + AVInputFormat *fmt, AVFormatParameters *ap); + + /** +@@ -1076,25 +1474,57 @@ + * @param ap Additional parameters needed when opening the file + * (NULL if default). + * @return 0 if OK, AVERROR_xxx otherwise ++ * ++ * @deprecated use avformat_open_input instead. + */ +-int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, ++attribute_deprecated int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, + AVInputFormat *fmt, + int buf_size, + AVFormatParameters *ap); ++#endif + +-#if FF_API_ALLOC_FORMAT_CONTEXT + /** +- * @deprecated Use avformat_alloc_context() instead. ++ * Open an input stream and read the header. The codecs are not opened. ++ * The stream must be closed with av_close_input_file(). ++ * ++ * @param ps Pointer to user-supplied AVFormatContext (allocated by avformat_alloc_context). ++ * May be a pointer to NULL, in which case an AVFormatContext is allocated by this ++ * function and written into ps. ++ * Note that a user-supplied AVFormatContext will be freed on failure. ++ * @param filename Name of the stream to open. ++ * @param fmt If non-NULL, this parameter forces a specific input format. ++ * Otherwise the format is autodetected. ++ * @param options A dictionary filled with AVFormatContext and demuxer-private options. ++ * On return this parameter will be destroyed and replaced with a dict containing ++ * options that were not found. May be NULL. ++ * ++ * @return 0 on success, a negative AVERROR on failure. ++ * ++ * @note If you want to use custom IO, preallocate the format context and set its pb field. + */ +-attribute_deprecated AVFormatContext *av_alloc_format_context(void); +-#endif ++int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options); ++ ++int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap); + ++#if FF_API_FORMAT_PARAMETERS + /** +- * Allocate an AVFormatContext. +- * Can be freed with av_free() but do not forget to free everything you +- * explicitly allocated as well! ++ * Read packets of a media file to get stream information. This ++ * is useful for file formats with no headers such as MPEG. This ++ * function also computes the real framerate in case of MPEG-2 repeat ++ * frame mode. ++ * The logical file position is not changed by this function; ++ * examined packets may be buffered for later processing. ++ * ++ * @param ic media file handle ++ * @return >=0 if OK, AVERROR_xxx on error ++ * @todo Let the user decide somehow what information is needed so that ++ * we do not waste time getting stuff the user does not need. ++ * ++ * @deprecated use avformat_find_stream_info. + */ +-AVFormatContext *avformat_alloc_context(void); ++attribute_deprecated ++int av_find_stream_info(AVFormatContext *ic); ++#endif + + /** + * Read packets of a media file to get stream information. This +@@ -1105,11 +1535,31 @@ + * examined packets may be buffered for later processing. + * + * @param ic media file handle ++ * @param options If non-NULL, an ic.nb_streams long array of pointers to ++ * dictionaries, where i-th member contains options for ++ * codec corresponding to i-th stream. ++ * On return each dictionary will be filled with options that were not found. + * @return >=0 if OK, AVERROR_xxx on error ++ * ++ * @note this function isn't guaranteed to open all the codecs, so ++ * options being non-empty at return is a perfectly normal behavior. ++ * + * @todo Let the user decide somehow what information is needed so that + * we do not waste time getting stuff the user does not need. + */ +-int av_find_stream_info(AVFormatContext *ic); ++int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options); ++ ++/** ++ * Find the programs which belong to a given stream. ++ * ++ * @param ic media file handle ++ * @param last the last found program, the search will start after this ++ * program, or from the beginning if it is NULL ++ * @param s stream index ++ * @return the next program which belongs to s, NULL if no program is found or ++ * the last program is not among the programs of ic. ++ */ ++AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s); + + /** + * Find the "best" stream in the file. +@@ -1181,6 +1631,11 @@ + int av_read_frame(AVFormatContext *s, AVPacket *pkt); + + /** ++ * Clear out any buffered data in context ++ */ ++void av_read_frame_flush(AVFormatContext *s); ++ ++/** + * Seek to the keyframe at timestamp. + * 'timestamp' in 'stream_index'. + * @param stream_index If stream_index is (-1), a default +@@ -1235,19 +1690,37 @@ + */ + int av_read_pause(AVFormatContext *s); + ++#if FF_API_FORMAT_PARAMETERS + /** + * Free a AVFormatContext allocated by av_open_input_stream. + * @param s context to free ++ * @deprecated use av_close_input_file() + */ ++attribute_deprecated + void av_close_input_stream(AVFormatContext *s); ++#endif + ++#if FF_API_CLOSE_INPUT_FILE + /** ++ * @deprecated use avformat_close_input() + * Close a media file (but not its codecs). + * + * @param s media file handle + */ ++attribute_deprecated + void av_close_input_file(AVFormatContext *s); ++#endif ++ ++/** ++ * Close an opened input AVFormatContext. Free it and all its contents ++ * and set *s to NULL. ++ */ ++void avformat_close_input(AVFormatContext **s); ++/** ++ * @} ++ */ + ++#if FF_API_NEW_STREAM + /** + * Add a new stream to a media file. + * +@@ -1258,146 +1731,81 @@ + * @param s media file handle + * @param id file-format-dependent stream ID + */ ++attribute_deprecated + AVStream *av_new_stream(AVFormatContext *s, int id); +-AVProgram *av_new_program(AVFormatContext *s, int id); +- +-/** +- * Add a new chapter. +- * This function is NOT part of the public API +- * and should ONLY be used by demuxers. +- * +- * @param s media file handle +- * @param id unique ID for this chapter +- * @param start chapter start time in time_base units +- * @param end chapter end time in time_base units +- * @param title chapter title +- * +- * @return AVChapter or NULL on error +- */ +-AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, +- int64_t start, int64_t end, const char *title); ++#endif + ++#if FF_API_SET_PTS_INFO + /** +- * Set the pts for a given stream. +- * +- * @param s stream +- * @param pts_wrap_bits number of bits effectively used by the pts +- * (used for wrap control, 33 is the value for MPEG) +- * @param pts_num numerator to convert to seconds (MPEG: 1) +- * @param pts_den denominator to convert to seconds (MPEG: 90000) ++ * @deprecated this function is not supposed to be called outside of lavf + */ ++attribute_deprecated + void av_set_pts_info(AVStream *s, int pts_wrap_bits, + unsigned int pts_num, unsigned int pts_den); ++#endif + + #define AVSEEK_FLAG_BACKWARD 1 ///< seek backward + #define AVSEEK_FLAG_BYTE 2 ///< seeking based on position in bytes + #define AVSEEK_FLAG_ANY 4 ///< seek to any frame, even non-keyframes + #define AVSEEK_FLAG_FRAME 8 ///< seeking based on frame number + +-int av_find_default_stream_index(AVFormatContext *s); +- +-/** +- * Get the index for a specific timestamp. +- * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond +- * to the timestamp which is <= the requested one, if backward +- * is 0, then it will be >= +- * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise +- * @return < 0 if no such timestamp could be found +- */ +-int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); +- +-/** +- * Ensure the index uses less memory than the maximum specified in +- * AVFormatContext.max_index_size by discarding entries if it grows +- * too large. +- * This function is not part of the public API and should only be called +- * by demuxers. +- */ +-void ff_reduce_index(AVFormatContext *s, int stream_index); +- +-/** +- * Add an index entry into a sorted list. Update the entry if the list +- * already contains it. +- * +- * @param timestamp timestamp in the time base of the given stream +- */ +-int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, +- int size, int distance, int flags); +- +-/** +- * Perform a binary search using av_index_search_timestamp() and +- * AVInputFormat.read_timestamp(). +- * This is not supposed to be called directly by a user application, +- * but by demuxers. +- * @param target_ts target timestamp in the time base of the given stream +- * @param stream_index stream number +- */ ++#if FF_API_SEEK_PUBLIC ++attribute_deprecated + int av_seek_frame_binary(AVFormatContext *s, int stream_index, + int64_t target_ts, int flags); +- +-/** +- * Update cur_dts of all streams based on the given timestamp and AVStream. +- * +- * Stream ref_st unchanged, others set cur_dts in their native time base. +- * Only needed for timestamp wrapping or if (dts not set and pts!=dts). +- * @param timestamp new dts expressed in time_base of param ref_st +- * @param ref_st reference stream giving time_base of param timestamp +- */ ++attribute_deprecated + void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); +- +-/** +- * Perform a binary search using read_timestamp(). +- * This is not supposed to be called directly by a user application, +- * but by demuxers. +- * @param target_ts target timestamp in the time base of the given stream +- * @param stream_index stream number +- */ ++attribute_deprecated + int64_t av_gen_search(AVFormatContext *s, int stream_index, + int64_t target_ts, int64_t pos_min, + int64_t pos_max, int64_t pos_limit, + int64_t ts_min, int64_t ts_max, + int flags, int64_t *ts_ret, + int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); ++#endif + ++#if FF_API_FORMAT_PARAMETERS + /** +- * media file output ++ * @deprecated pass the options to avformat_write_header directly. + */ +-int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); ++attribute_deprecated int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap); ++#endif + + /** +- * Split a URL string into components. ++ * @addtogroup lavf_encoding ++ * @{ ++ */ ++/** ++ * Allocate the stream private data and write the stream header to ++ * an output media file. + * +- * The pointers to buffers for storing individual components may be null, +- * in order to ignore that component. Buffers for components not found are +- * set to empty strings. If the port is not found, it is set to a negative +- * value. ++ * @param s Media file handle, must be allocated with avformat_alloc_context(). ++ * Its oformat field must be set to the desired output format; ++ * Its pb field must be set to an already openened AVIOContext. ++ * @param options An AVDictionary filled with AVFormatContext and muxer-private options. ++ * On return this parameter will be destroyed and replaced with a dict containing ++ * options that were not found. May be NULL. + * +- * @param proto the buffer for the protocol +- * @param proto_size the size of the proto buffer +- * @param authorization the buffer for the authorization +- * @param authorization_size the size of the authorization buffer +- * @param hostname the buffer for the host name +- * @param hostname_size the size of the hostname buffer +- * @param port_ptr a pointer to store the port number in +- * @param path the buffer for the path +- * @param path_size the size of the path buffer +- * @param url the URL to split ++ * @return 0 on success, negative AVERROR on failure. ++ * ++ * @see av_opt_find, av_dict_set, avio_open, av_oformat_next. + */ +-void av_url_split(char *proto, int proto_size, +- char *authorization, int authorization_size, +- char *hostname, int hostname_size, +- int *port_ptr, +- char *path, int path_size, +- const char *url); ++int avformat_write_header(AVFormatContext *s, AVDictionary **options); + ++#if FF_API_FORMAT_PARAMETERS + /** + * Allocate the stream private data and write the stream header to an + * output media file. ++ * @note: this sets stream time-bases, if possible to stream->codec->time_base ++ * but for some formats it might also be some other time base + * + * @param s media file handle + * @return 0 if OK, AVERROR_xxx on error ++ * ++ * @deprecated use avformat_write_header. + */ +-int av_write_header(AVFormatContext *s); ++attribute_deprecated int av_write_header(AVFormatContext *s); ++#endif + + /** + * Write a packet to an output media file. +@@ -1408,8 +1816,12 @@ + * + * @param s media file handle + * @param pkt The packet, which contains the stream_index, buf/buf_size, +- dts/pts, ... +- * @return < 0 on error, = 0 if OK, 1 if end of stream wanted ++ * dts/pts, ... ++ * This can be NULL (at any time, not just at the end), in ++ * order to immediately flush data buffered within the muxer, ++ * for muxers that buffer up data internally before writing it ++ * to the output. ++ * @return < 0 on error, = 0 if OK, 1 if flushed and there is no more data to flush + */ + int av_write_frame(AVFormatContext *s, AVPacket *pkt); + +@@ -1424,9 +1836,18 @@ + * demuxer level. + * + * @param s media file handle +- * @param pkt The packet, which contains the stream_index, buf/buf_size, +- dts/pts, ... +- * @return < 0 on error, = 0 if OK, 1 if end of stream wanted ++ * @param pkt The packet containing the data to be written. Libavformat takes ++ * ownership of the data and will free it when it sees fit using the packet's ++ * @ref AVPacket.destruct "destruct" field. The caller must not access the data ++ * after this function returns, as it may already be freed. ++ * Packet's @ref AVPacket.stream_index "stream_index" field must be set to the ++ * index of the corresponding stream in @ref AVFormatContext.streams ++ * "s.streams". ++ * It is very strongly recommended that timing information (@ref AVPacket.pts ++ * "pts", @ref AVPacket.dts "dts" @ref AVPacket.duration "duration") is set to ++ * correct values. ++ * ++ * @return 0 on success, a negative AVERROR on error. + */ + int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt); + +@@ -1459,74 +1880,216 @@ + */ + int av_write_trailer(AVFormatContext *s); + +-void dump_format(AVFormatContext *ic, +- int index, +- const char *url, +- int is_output); ++/** ++ * Return the output format in the list of registered output formats ++ * which best matches the provided parameters, or return NULL if ++ * there is no match. ++ * ++ * @param short_name if non-NULL checks if short_name matches with the ++ * names of the registered formats ++ * @param filename if non-NULL checks if filename terminates with the ++ * extensions of the registered formats ++ * @param mime_type if non-NULL checks if mime_type matches with the ++ * MIME type of the registered formats ++ */ ++AVOutputFormat *av_guess_format(const char *short_name, ++ const char *filename, ++ const char *mime_type); ++ ++/** ++ * Guess the codec ID based upon muxer and filename. ++ */ ++enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, ++ const char *filename, const char *mime_type, ++ enum AVMediaType type); ++ ++/** ++ * Get timing information for the data currently output. ++ * The exact meaning of "currently output" depends on the format. ++ * It is mostly relevant for devices that have an internal buffer and/or ++ * work in real time. ++ * @param s media file handle ++ * @param stream stream in the media file ++ * @param dts[out] DTS of the last packet output for the stream, in stream ++ * time_base units ++ * @param wall[out] absolute time when that packet whas output, ++ * in microsecond ++ * @return 0 if OK, AVERROR(ENOSYS) if the format does not support it ++ * Note: some formats or devices may not allow to measure dts and wall ++ * atomically. ++ */ ++int av_get_output_timestamp(struct AVFormatContext *s, int stream, ++ int64_t *dts, int64_t *wall); ++ ++ ++/** ++ * @} ++ */ ++ ++ ++/** ++ * @defgroup lavf_misc Utility functions ++ * @ingroup libavf ++ * @{ ++ * ++ * Miscelaneous utility functions related to both muxing and demuxing ++ * (or neither). ++ */ + +-#if FF_API_PARSE_FRAME_PARAM + /** +- * Parse width and height out of string str. +- * @deprecated Use av_parse_video_frame_size instead. ++ * Send a nice hexadecimal dump of a buffer to the specified file stream. ++ * ++ * @param f The file stream pointer where the dump should be sent to. ++ * @param buf buffer ++ * @param size buffer size ++ * ++ * @see av_hex_dump_log, av_pkt_dump2, av_pkt_dump_log2 + */ +-attribute_deprecated int parse_image_size(int *width_ptr, int *height_ptr, +- const char *str); ++void av_hex_dump(FILE *f, uint8_t *buf, int size); + + /** +- * Convert framerate from a string to a fraction. +- * @deprecated Use av_parse_video_frame_rate instead. ++ * Send a nice hexadecimal dump of a buffer to the log. ++ * ++ * @param avcl A pointer to an arbitrary struct of which the first field is a ++ * pointer to an AVClass struct. ++ * @param level The importance level of the message, lower values signifying ++ * higher importance. ++ * @param buf buffer ++ * @param size buffer size ++ * ++ * @see av_hex_dump, av_pkt_dump2, av_pkt_dump_log2 + */ +-attribute_deprecated int parse_frame_rate(int *frame_rate, int *frame_rate_base, +- const char *arg); ++void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size); ++ ++/** ++ * Send a nice dump of a packet to the specified file stream. ++ * ++ * @param f The file stream pointer where the dump should be sent to. ++ * @param pkt packet to dump ++ * @param dump_payload True if the payload must be displayed, too. ++ * @param st AVStream that the packet belongs to ++ */ ++void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st); ++ ++ ++/** ++ * Send a nice dump of a packet to the log. ++ * ++ * @param avcl A pointer to an arbitrary struct of which the first field is a ++ * pointer to an AVClass struct. ++ * @param level The importance level of the message, lower values signifying ++ * higher importance. ++ * @param pkt packet to dump ++ * @param dump_payload True if the payload must be displayed, too. ++ * @param st AVStream that the packet belongs to ++ */ ++void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, ++ AVStream *st); ++ ++/** ++ * Get the CodecID for the given codec tag tag. ++ * If no codec id is found returns CODEC_ID_NONE. ++ * ++ * @param tags list of supported codec_id-codec_tag pairs, as stored ++ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag ++ */ ++enum CodecID av_codec_get_id(const struct AVCodecTag * const *tags, unsigned int tag); ++ ++/** ++ * Get the codec tag for the given codec id id. ++ * If no codec tag is found returns 0. ++ * ++ * @param tags list of supported codec_id-codec_tag pairs, as stored ++ * in AVInputFormat.codec_tag and AVOutputFormat.codec_tag ++ */ ++unsigned int av_codec_get_tag(const struct AVCodecTag * const *tags, enum CodecID id); ++ ++int av_find_default_stream_index(AVFormatContext *s); ++ ++/** ++ * Get the index for a specific timestamp. ++ * @param flags if AVSEEK_FLAG_BACKWARD then the returned index will correspond ++ * to the timestamp which is <= the requested one, if backward ++ * is 0, then it will be >= ++ * if AVSEEK_FLAG_ANY seek to any frame, only keyframes otherwise ++ * @return < 0 if no such timestamp could be found ++ */ ++int av_index_search_timestamp(AVStream *st, int64_t timestamp, int flags); ++ ++/** ++ * Add an index entry into a sorted list. Update the entry if the list ++ * already contains it. ++ * ++ * @param timestamp timestamp in the time base of the given stream ++ */ ++int av_add_index_entry(AVStream *st, int64_t pos, int64_t timestamp, ++ int size, int distance, int flags); ++ ++ ++/** ++ * Split a URL string into components. ++ * ++ * The pointers to buffers for storing individual components may be null, ++ * in order to ignore that component. Buffers for components not found are ++ * set to empty strings. If the port is not found, it is set to a negative ++ * value. ++ * ++ * @param proto the buffer for the protocol ++ * @param proto_size the size of the proto buffer ++ * @param authorization the buffer for the authorization ++ * @param authorization_size the size of the authorization buffer ++ * @param hostname the buffer for the host name ++ * @param hostname_size the size of the hostname buffer ++ * @param port_ptr a pointer to store the port number in ++ * @param path the buffer for the path ++ * @param path_size the size of the path buffer ++ * @param url the URL to split ++ */ ++void av_url_split(char *proto, int proto_size, ++ char *authorization, int authorization_size, ++ char *hostname, int hostname_size, ++ int *port_ptr, ++ char *path, int path_size, ++ const char *url); ++ ++#if FF_API_DUMP_FORMAT ++/** ++ * @deprecated Deprecated in favor of av_dump_format(). ++ */ ++attribute_deprecated void dump_format(AVFormatContext *ic, ++ int index, ++ const char *url, ++ int is_output); + #endif + ++void av_dump_format(AVFormatContext *ic, ++ int index, ++ const char *url, ++ int is_output); ++ ++#if FF_API_PARSE_DATE + /** + * Parse datestr and return a corresponding number of microseconds. ++ * + * @param datestr String representing a date or a duration. +- * - If a date the syntax is: +- * @code +- * now|{[{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z|z]} +- * @endcode +- * If the value is "now" it takes the current time. +- * Time is local time unless Z is appended, in which case it is +- * interpreted as UTC. +- * If the year-month-day part is not specified it takes the current +- * year-month-day. +- * @return the number of microseconds since 1st of January, 1970 up to +- * the time of the parsed date or INT64_MIN if datestr cannot be +- * successfully parsed. +- * - If a duration the syntax is: +- * @code +- * [-]HH[:MM[:SS[.m...]]] +- * [-]S+[.m...] +- * @endcode +- * @return the number of microseconds contained in a time interval +- * with the specified duration or INT64_MIN if datestr cannot be +- * successfully parsed. +- * @param duration Flag which tells how to interpret datestr, if +- * not zero datestr is interpreted as a duration, otherwise as a +- * date. ++ * See av_parse_time() for the syntax of the provided string. ++ * @deprecated in favor of av_parse_time() + */ ++attribute_deprecated + int64_t parse_date(const char *datestr, int duration); ++#endif + + /** + * Get the current time in microseconds. + */ + int64_t av_gettime(void); + +-/* ffm-specific for ffserver */ +-#define FFM_PACKET_SIZE 4096 +-int64_t ffm_read_write_index(int fd); +-int ffm_write_write_index(int fd, int64_t pos); +-void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size); +- ++#if FF_API_FIND_INFO_TAG + /** +- * Attempt to find a specific tag in a URL. +- * +- * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. +- * Return 1 if found. ++ * @deprecated use av_find_info_tag in libavutil instead. + */ +-int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); ++attribute_deprecated int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); ++#endif + + /** + * Return in 'buf' the path with '%d' replaced by a number. +@@ -1560,12 +2123,16 @@ + * all the contexts in the array (an AVCodecContext per RTP stream) + * must contain only one AVStream. + * @param n_files number of AVCodecContexts contained in ac +- * @param buff buffer where the SDP will be stored (must be allocated by +- * the caller) ++ * @param buf buffer where the SDP will be stored (must be allocated by ++ * the caller) + * @param size the size of the buffer + * @return 0 if OK, AVERROR_xxx on error + */ +-int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size); ++int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size); ++ ++#if FF_API_SDP_CREATE ++attribute_deprecated int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size); ++#endif + + /** + * Return a positive value if the given filename has one of the given +@@ -1575,4 +2142,42 @@ + */ + int av_match_ext(const char *filename, const char *extensions); + ++/** ++ * Test if the given container can store a codec. ++ * ++ * @param std_compliance standards compliance level, one of FF_COMPLIANCE_* ++ * ++ * @return 1 if codec with ID codec_id can be stored in ofmt, 0 if it cannot. ++ * A negative number if this information is not available. ++ */ ++int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance); ++ ++/** ++ * @defgroup riff_fourcc RIFF FourCCs ++ * @{ ++ * Get the tables mapping RIFF FourCCs to libavcodec CodecIDs. The tables are ++ * meant to be passed to av_codec_get_id()/av_codec_get_tag() as in the ++ * following code: ++ * @code ++ * uint32_t tag = MKTAG('H', '2', '6', '4'); ++ * const struct AVCodecTag *table[] = { avformat_get_riff_video_tags(), 0 }; ++ * enum CodecID id = av_codec_get_id(table, tag); ++ * @endcode ++ */ ++/** ++ * @return the table mapping RIFF FourCCs for video to libavcodec CodecID. ++ */ ++const struct AVCodecTag *avformat_get_riff_video_tags(void); ++/** ++ * @return the table mapping RIFF FourCCs for audio to CodecID. ++ */ ++const struct AVCodecTag *avformat_get_riff_audio_tags(void); ++/** ++ * @} ++ */ ++ ++/** ++ * @} ++ */ ++ + #endif /* AVFORMAT_AVFORMAT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avi.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avi.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,45 +0,0 @@ +-/* +- * AVI common data +- * Copyright (c) 2010 Anton Khirnov +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include "avi.h" +- +-const AVMetadataConv ff_avi_metadata_conv[] = { +- { "IART", "artist" }, +- { "ICMT", "comment" }, +- { "ICOP", "copyright" }, +- { "ICRD", "date" }, +- { "IGNR", "genre" }, +- { "ILNG", "language" }, +- { "INAM", "title" }, +- { "IPRD", "album" }, +- { "IPRT", "track" }, +- { "ISFT", "encoder" }, +- { "ITCH", "encoded_by"}, +- { "strn", "title" }, +- { 0 }, +-}; +- +-const char ff_avi_tags[][5] = { +- "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI", +- "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD", +- "IPRT", "ISBJ", "ISFT", "ISHP", "ISRC", "ISRF", "ITCH", +- {0} +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avidec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avidec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avidec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avidec.c 2012-05-14 14:08:54.903351433 +0200 +@@ -19,14 +19,14 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-//#define DEBUG +-//#define DEBUG_SEEK +- +-#include + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "libavutil/bswap.h" +-#include "libavcodec/bytestream.h" ++#include "libavutil/opt.h" ++#include "libavutil/dict.h" ++#include "libavutil/avstring.h" + #include "avformat.h" ++#include "internal.h" + #include "avi.h" + #include "dv.h" + #include "riff.h" +@@ -55,9 +55,12 @@ + AVFormatContext *sub_ctx; + AVPacket sub_pkt; + uint8_t *sub_buffer; ++ ++ int64_t seek_pos; + } AVIStream; + + typedef struct { ++ const AVClass *class; + int64_t riff_end; + int64_t movi_end; + int64_t fsize; +@@ -69,9 +72,25 @@ + int stream_index; + DVDemuxContext* dv_demux; + int odml_depth; ++ int use_odml; + #define MAX_ODML_DEPTH 1000 ++ int64_t dts_max; + } AVIContext; + ++ ++static const AVOption options[] = { ++ { "use_odml", "use odml index", offsetof(AVIContext, use_odml), AV_OPT_TYPE_INT, {.dbl = 1}, -1, 1, AV_OPT_FLAG_DECODING_PARAM}, ++ { NULL }, ++}; ++ ++static const AVClass demuxer_class = { ++ "AVI demuxer", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++ + static const char avi_headers[][8] = { + { 'R', 'I', 'F', 'F', 'A', 'V', 'I', ' ' }, + { 'R', 'I', 'F', 'F', 'A', 'V', 'I', 'X' }, +@@ -81,6 +100,11 @@ + { 0 } + }; + ++static const AVMetadataConv avi_metadata_conv[] = { ++ { "strn", "title" }, ++ { 0 }, ++}; ++ + static int avi_load_index(AVFormatContext *s); + static int guess_ni_flag(AVFormatContext *s); + +@@ -101,17 +125,17 @@ + return 1; + } + +-static int get_riff(AVFormatContext *s, ByteIOContext *pb) ++static int get_riff(AVFormatContext *s, AVIOContext *pb) + { + AVIContext *avi = s->priv_data; + char header[8]; + int i; + + /* check RIFF header */ +- get_buffer(pb, header, 4); +- avi->riff_end = get_le32(pb); /* RIFF chunk size */ +- avi->riff_end += url_ftell(pb); /* RIFF chunk end */ +- get_buffer(pb, header+4, 4); ++ avio_read(pb, header, 4); ++ avi->riff_end = avio_rl32(pb); /* RIFF chunk size */ ++ avi->riff_end += avio_tell(pb); /* RIFF chunk end */ ++ avio_read(pb, header+4, 4); + + for(i=0; avi_headers[i][0]; i++) + if(!memcmp(header, avi_headers[i], 8)) +@@ -127,13 +151,13 @@ + + static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; +- int longs_pre_entry= get_le16(pb); +- int index_sub_type = get_byte(pb); +- int index_type = get_byte(pb); +- int entries_in_use = get_le32(pb); +- int chunk_id = get_le32(pb); +- int64_t base = get_le64(pb); ++ AVIOContext *pb = s->pb; ++ int longs_pre_entry= avio_rl16(pb); ++ int index_sub_type = avio_r8(pb); ++ int index_type = avio_r8(pb); ++ int entries_in_use = avio_rl32(pb); ++ int chunk_id = avio_rl32(pb); ++ int64_t base = avio_rl64(pb); + int stream_id= 10*((chunk_id&0xFF) - '0') + (((chunk_id>>8)&0xFF) - '0'); + AVStream *st; + AVIStream *ast; +@@ -141,10 +165,8 @@ + int64_t last_pos= -1; + int64_t filesize= avi->fsize; + +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n", +- longs_pre_entry,index_type, entries_in_use, chunk_id, base); +-#endif ++ av_dlog(s, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n", ++ longs_pre_entry,index_type, entries_in_use, chunk_id, base); + + if(stream_id >= s->nb_streams || stream_id < 0) + return -1; +@@ -154,7 +176,7 @@ + if(index_sub_type) + return -1; + +- get_le32(pb); ++ avio_rl32(pb); + + if(index_type && longs_pre_entry != 2) + return -1; +@@ -171,8 +193,8 @@ + + for(i=0; i= 0; + len &= 0x7FFFFFFF; + +@@ -192,35 +214,35 @@ + }else{ + int64_t offset, pos; + int duration; +- offset = get_le64(pb); +- get_le32(pb); /* size */ +- duration = get_le32(pb); ++ offset = avio_rl64(pb); ++ avio_rl32(pb); /* size */ ++ duration = avio_rl32(pb); + + if(url_feof(pb)) + return -1; + +- pos = url_ftell(pb); ++ pos = avio_tell(pb); + + if(avi->odml_depth > MAX_ODML_DEPTH){ + av_log(s, AV_LOG_ERROR, "Too deeply nested ODML indexes\n"); + return -1; + } + +- if(url_fseek(pb, offset+8, SEEK_SET) < 0) ++ if(avio_seek(pb, offset+8, SEEK_SET) < 0) + return -1; + avi->odml_depth++; + read_braindead_odml_indx(s, frame_num); + avi->odml_depth--; + frame_num += duration; + +- if(url_fseek(pb, pos, SEEK_SET) < 0) { ++ if(avio_seek(pb, pos, SEEK_SET) < 0) { + av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index"); + return -1; + } + + } + } +- avi->index_loaded=1; ++ avi->index_loaded=2; + return 0; + } + +@@ -252,7 +274,7 @@ + + static int avi_read_tag(AVFormatContext *s, AVStream *st, uint32_t tag, uint32_t size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + char key[5] = {0}, *value; + + size += (size & 1); +@@ -262,28 +284,19 @@ + value = av_malloc(size+1); + if (!value) + return -1; +- get_buffer(pb, value, size); ++ avio_read(pb, value, size); + value[size]=0; + + AV_WL32(key, tag); + +- return av_metadata_set2(st ? &st->metadata : &s->metadata, key, value, +- AV_METADATA_DONT_STRDUP_VAL); +-} +- +-static void avi_read_info(AVFormatContext *s, uint64_t end) +-{ +- while (url_ftell(s->pb) < end) { +- uint32_t tag = get_le32(s->pb); +- uint32_t size = get_le32(s->pb); +- avi_read_tag(s, NULL, tag, size); +- } ++ return av_dict_set(st ? &st->metadata : &s->metadata, key, value, ++ AV_DICT_DONT_STRDUP_VAL); + } + + static const char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + +-static void avi_metadata_creation_time(AVMetadata **metadata, char *date) ++static void avi_metadata_creation_time(AVDictionary **metadata, char *date) + { + char month[4], time[9], buffer[64]; + int i, day, year; +@@ -291,31 +304,31 @@ + if (sscanf(date, "%*3s%*[ ]%3s%*[ ]%2d%*[ ]%8s%*[ ]%4d", + month, &day, time, &year) == 4) { + for (i=0; i<12; i++) +- if (!strcasecmp(month, months[i])) { ++ if (!av_strcasecmp(month, months[i])) { + snprintf(buffer, sizeof(buffer), "%.4d-%.2d-%.2d %s", + year, i+1, day, time); +- av_metadata_set2(metadata, "creation_time", buffer, 0); ++ av_dict_set(metadata, "creation_time", buffer, 0); + } + } else if (date[4] == '/' && date[7] == '/') { + date[4] = date[7] = '-'; +- av_metadata_set2(metadata, "creation_time", date, 0); ++ av_dict_set(metadata, "creation_time", date, 0); + } + } + + static void avi_read_nikon(AVFormatContext *s, uint64_t end) + { +- while (url_ftell(s->pb) < end) { +- uint32_t tag = get_le32(s->pb); +- uint32_t size = get_le32(s->pb); ++ while (avio_tell(s->pb) < end) { ++ uint32_t tag = avio_rl32(s->pb); ++ uint32_t size = avio_rl32(s->pb); + switch (tag) { + case MKTAG('n', 'c', 't', 'g'): { /* Nikon Tags */ +- uint64_t tag_end = url_ftell(s->pb) + size; +- while (url_ftell(s->pb) < tag_end) { +- uint16_t tag = get_le16(s->pb); +- uint16_t size = get_le16(s->pb); ++ uint64_t tag_end = avio_tell(s->pb) + size; ++ while (avio_tell(s->pb) < tag_end) { ++ uint16_t tag = avio_rl16(s->pb); ++ uint16_t size = avio_rl16(s->pb); + const char *name = NULL; + char buffer[64] = {0}; +- size -= get_buffer(s->pb, buffer, ++ size -= avio_read(s->pb, buffer, + FFMIN(size, sizeof(buffer)-1)); + switch (tag) { + case 0x03: name = "maker"; break; +@@ -326,13 +339,13 @@ + break; + } + if (name) +- av_metadata_set2(&s->metadata, name, buffer, 0); +- url_fskip(s->pb, size); ++ av_dict_set(&s->metadata, name, buffer, 0); ++ avio_skip(s->pb, size); + } + break; + } + default: +- url_fskip(s->pb, size); ++ avio_skip(s->pb, size); + break; + } + } +@@ -341,9 +354,9 @@ + static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int tag, tag1, handler; +- int codec_type, stream_index, frame_period, bit_rate; ++ int codec_type, stream_index, frame_period; + unsigned int size; + int i; + AVStream *st; +@@ -351,13 +364,16 @@ + int avih_width=0, avih_height=0; + int amv_file_format=0; + uint64_t list_end = 0; ++ int ret; + + avi->stream_index= -1; + + if (get_riff(s, pb) < 0) + return -1; + +- avi->fsize = url_fsize(pb); ++ av_log(avi, AV_LOG_DEBUG, "use odml:%d\n", avi->use_odml); ++ ++ avi->fsize = avio_size(pb); + if(avi->fsize<=0 || avi->fsize < avi->riff_end) + avi->fsize= avi->riff_end == 8 ? INT64_MAX : avi->riff_end; + +@@ -368,28 +384,28 @@ + for(;;) { + if (url_feof(pb)) + goto fail; +- tag = get_le32(pb); +- size = get_le32(pb); ++ tag = avio_rl32(pb); ++ size = avio_rl32(pb); + + print_tag("tag", tag, size); + + switch(tag) { + case MKTAG('L', 'I', 'S', 'T'): +- list_end = url_ftell(pb) + size; ++ list_end = avio_tell(pb) + size; + /* Ignored, except at start of video packets. */ +- tag1 = get_le32(pb); ++ tag1 = avio_rl32(pb); + + print_tag("list", tag1, 0); + + if (tag1 == MKTAG('m', 'o', 'v', 'i')) { +- avi->movi_list = url_ftell(pb) - 4; ++ avi->movi_list = avio_tell(pb) - 4; + if(size) avi->movi_end = avi->movi_list + size + (size & 1); + else avi->movi_end = avi->fsize; + av_dlog(NULL, "movi end=%"PRIx64"\n", avi->movi_end); + goto end_of_header; + } + else if (tag1 == MKTAG('I', 'N', 'F', 'O')) +- avi_read_info(s, list_end); ++ ff_read_riff_info(s, size - 4); + else if (tag1 == MKTAG('n', 'c', 'd', 't')) + avi_read_nikon(s, list_end); + +@@ -397,48 +413,49 @@ + case MKTAG('I', 'D', 'I', 'T'): { + unsigned char date[64] = {0}; + size += (size & 1); +- size -= get_buffer(pb, date, FFMIN(size, sizeof(date)-1)); +- url_fskip(pb, size); ++ size -= avio_read(pb, date, FFMIN(size, sizeof(date)-1)); ++ avio_skip(pb, size); + avi_metadata_creation_time(&s->metadata, date); + break; + } + case MKTAG('d', 'm', 'l', 'h'): + avi->is_odml = 1; +- url_fskip(pb, size + (size & 1)); ++ avio_skip(pb, size + (size & 1)); + break; + case MKTAG('a', 'm', 'v', 'h'): + amv_file_format=1; + case MKTAG('a', 'v', 'i', 'h'): + /* AVI header */ + /* using frame_period is bad idea */ +- frame_period = get_le32(pb); +- bit_rate = get_le32(pb) * 8; +- get_le32(pb); +- avi->non_interleaved |= get_le32(pb) & AVIF_MUSTUSEINDEX; +- +- url_fskip(pb, 2 * 4); +- get_le32(pb); +- get_le32(pb); +- avih_width=get_le32(pb); +- avih_height=get_le32(pb); ++ frame_period = avio_rl32(pb); ++ avio_rl32(pb); /* max. bytes per second */ ++ avio_rl32(pb); ++ avi->non_interleaved |= avio_rl32(pb) & AVIF_MUSTUSEINDEX; ++ ++ avio_skip(pb, 2 * 4); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avih_width=avio_rl32(pb); ++ avih_height=avio_rl32(pb); + +- url_fskip(pb, size - 10 * 4); ++ avio_skip(pb, size - 10 * 4); + break; + case MKTAG('s', 't', 'r', 'h'): + /* stream header */ + +- tag1 = get_le32(pb); +- handler = get_le32(pb); /* codec tag */ ++ tag1 = avio_rl32(pb); ++ handler = avio_rl32(pb); /* codec tag */ + + if(tag1 == MKTAG('p', 'a', 'd', 's')){ +- url_fskip(pb, size - 8); ++ avio_skip(pb, size - 8); + break; + }else{ + stream_index++; +- st = av_new_stream(s, stream_index); ++ st = avformat_new_stream(s, NULL); + if (!st) + goto fail; + ++ st->id = stream_index; + ast = av_mallocz(sizeof(AVIStream)); + if (!ast) + goto fail; +@@ -470,17 +487,17 @@ + av_freep(&s->streams[0]); + s->nb_streams = 0; + if (CONFIG_DV_DEMUXER) { +- avi->dv_demux = dv_init_demux(s); ++ avi->dv_demux = avpriv_dv_init_demux(s); + if (!avi->dv_demux) + goto fail; + } + s->streams[0]->priv_data = ast; +- url_fskip(pb, 3 * 4); +- ast->scale = get_le32(pb); +- ast->rate = get_le32(pb); +- url_fskip(pb, 4); /* start time */ ++ avio_skip(pb, 3 * 4); ++ ast->scale = avio_rl32(pb); ++ ast->rate = avio_rl32(pb); ++ avio_skip(pb, 4); /* start time */ + +- dv_dur = get_le32(pb); ++ dv_dur = avio_rl32(pb); + if (ast->scale > 0 && ast->rate > 0 && dv_dur > 0) { + dv_dur *= AV_TIME_BASE; + s->duration = av_rescale(dv_dur, ast->scale, ast->rate); +@@ -491,19 +508,19 @@ + */ + + stream_index = s->nb_streams - 1; +- url_fskip(pb, size - 9*4); ++ avio_skip(pb, size - 9*4); + break; + } + + assert(stream_index < s->nb_streams); + st->codec->stream_codec_tag= handler; + +- get_le32(pb); /* flags */ +- get_le16(pb); /* priority */ +- get_le16(pb); /* language */ +- get_le32(pb); /* initial frame */ +- ast->scale = get_le32(pb); +- ast->rate = get_le32(pb); ++ avio_rl32(pb); /* flags */ ++ avio_rl16(pb); /* priority */ ++ avio_rl16(pb); /* language */ ++ avio_rl32(pb); /* initial frame */ ++ ast->scale = avio_rl32(pb); ++ ast->rate = avio_rl32(pb); + if(!(ast->scale && ast->rate)){ + av_log(s, AV_LOG_WARNING, "scale/rate is %u/%u which is invalid. (This file has been generated by broken software.)\n", ast->scale, ast->rate); + if(frame_period){ +@@ -514,15 +531,19 @@ + ast->scale = 1; + } + } +- av_set_pts_info(st, 64, ast->scale, ast->rate); ++ avpriv_set_pts_info(st, 64, ast->scale, ast->rate); + +- ast->cum_len=get_le32(pb); /* start */ +- st->nb_frames = get_le32(pb); ++ ast->cum_len=avio_rl32(pb); /* start */ ++ st->nb_frames = avio_rl32(pb); + + st->start_time = 0; +- get_le32(pb); /* buffer size */ +- get_le32(pb); /* quality */ +- ast->sample_size = get_le32(pb); /* sample ssize */ ++ avio_rl32(pb); /* buffer size */ ++ avio_rl32(pb); /* quality */ ++ if (ast->cum_len*ast->scale/ast->rate > 3600) { ++ av_log(s, AV_LOG_ERROR, "crazy start time, iam scared, giving up\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ast->sample_size = avio_rl32(pb); /* sample ssize */ + ast->cum_len *= FFMAX(1, ast->sample_size); + // av_log(s, AV_LOG_DEBUG, "%d %d %d %d\n", ast->rate, ast->scale, ast->start, ast->sample_size); + +@@ -542,20 +563,21 @@ + codec_type = AVMEDIA_TYPE_DATA; + break; + default: +- av_log(s, AV_LOG_ERROR, "unknown stream type %X\n", tag1); +- goto fail; ++ av_log(s, AV_LOG_INFO, "unknown stream type %X\n", tag1); + } + if(ast->sample_size == 0) + st->duration = st->nb_frames; + ast->frame_offset= ast->cum_len; +- url_fskip(pb, size - 12 * 4); ++ avio_skip(pb, size - 12 * 4); + break; + case MKTAG('s', 't', 'r', 'f'): + /* stream header */ ++ if (!size) ++ break; + if (stream_index >= (unsigned)s->nb_streams || avi->dv_demux) { +- url_fskip(pb, size); ++ avio_skip(pb, size); + } else { +- uint64_t cur_pos = url_ftell(pb); ++ uint64_t cur_pos = avio_tell(pb); + if (cur_pos < list_end) + size = FFMIN(size, list_end - cur_pos); + st = s->streams[stream_index]; +@@ -566,7 +588,7 @@ + st->codec->height=avih_height; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_AMV; +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + tag1 = ff_get_bmp_header(pb, st); +@@ -578,32 +600,31 @@ + break; + } + +- if(size > 10*4 && size<(1<<30)){ ++ if(size > 10*4 && size<(1<<30) && size < avi->fsize){ + st->codec->extradata_size= size - 10*4; + st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) { + st->codec->extradata_size= 0; + return AVERROR(ENOMEM); + } +- get_buffer(pb, st->codec->extradata, st->codec->extradata_size); ++ avio_read(pb, st->codec->extradata, st->codec->extradata_size); + } + + if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly +- get_byte(pb); ++ avio_r8(pb); + + /* Extract palette from extradata if bpp <= 8. */ + /* This code assumes that extradata contains only palette. */ + /* This is true for all paletted codecs implemented in FFmpeg. */ + if (st->codec->extradata_size && (st->codec->bits_per_coded_sample <= 8)) { +- st->codec->palctrl = av_mallocz(sizeof(AVPaletteControl)); +-#if HAVE_BIGENDIAN +- for (i = 0; i < FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)/4; i++) +- st->codec->palctrl->palette[i] = av_bswap32(((uint32_t*)st->codec->extradata)[i]); +-#else +- memcpy(st->codec->palctrl->palette, st->codec->extradata, +- FFMIN(st->codec->extradata_size, AVPALETTE_SIZE)); +-#endif +- st->codec->palctrl->palette_changed = 1; ++ int pal_size = (1 << st->codec->bits_per_coded_sample) << 2; ++ const uint8_t *pal_src; ++ ++ pal_size = FFMIN(pal_size, st->codec->extradata_size); ++ pal_src = st->codec->extradata + st->codec->extradata_size - pal_size; ++ for (i = 0; i < pal_size/4; i++) ++ ast->pal[i] = 0xFF<<24 | AV_RL32(pal_src+4*i); ++ ast->has_pal = 1; + } + + print_tag("video", tag1, 0); +@@ -620,23 +641,25 @@ + + if(st->codec->codec_tag==0 && st->codec->height > 0 && st->codec->extradata_size < 1U<<30){ + st->codec->extradata_size+= 9; +- st->codec->extradata= av_realloc(st->codec->extradata, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ st->codec->extradata= av_realloc_f(st->codec->extradata, 1, st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if(st->codec->extradata) + memcpy(st->codec->extradata + st->codec->extradata_size - 9, "BottomUp", 9); + } + st->codec->height= FFABS(st->codec->height); + +-// url_fskip(pb, size - 5 * 4); ++// avio_skip(pb, size - 5 * 4); + break; + case AVMEDIA_TYPE_AUDIO: +- ff_get_wav_header(pb, st->codec, size); ++ ret = ff_get_wav_header(pb, st->codec, size); ++ if (ret < 0) ++ return ret; + ast->dshow_block_align= st->codec->block_align; + if(ast->sample_size && st->codec->block_align && ast->sample_size != st->codec->block_align){ + av_log(s, AV_LOG_WARNING, "sample size (%d) != block align (%d)\n", ast->sample_size, st->codec->block_align); + ast->sample_size= st->codec->block_align; + } + if (size&1) /* 2-aligned (fix for Stargate SG-1 - 3x18 - Shades of Grey.avi) */ +- url_fskip(pb, 1); ++ avio_skip(pb, 1); + /* Force parsing as several audio frames can be in + * one packet and timestamps refer to packet start. */ + st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; +@@ -650,6 +673,7 @@ + if (st->codec->stream_codec_tag == AV_RL32("Axan")){ + st->codec->codec_id = CODEC_ID_XAN_DPCM; + st->codec->codec_tag = 0; ++ ast->dshow_block_align = 0; + } + if (amv_file_format){ + st->codec->codec_id = CODEC_ID_ADPCM_IMA_AMV; +@@ -658,40 +682,63 @@ + break; + case AVMEDIA_TYPE_SUBTITLE: + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; +- st->codec->codec_id = CODEC_ID_PROBE; ++ st->request_probe= 1; + break; + default: + st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codec->codec_id= CODEC_ID_NONE; + st->codec->codec_tag= 0; +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + } + break; +- case MKTAG('i', 'n', 'd', 'x'): +- i= url_ftell(pb); +- if(!url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX)){ +- read_braindead_odml_indx(s, 0); ++ case MKTAG('s', 't', 'r', 'd'): ++ if (stream_index >= (unsigned)s->nb_streams || s->streams[stream_index]->codec->extradata_size) { ++ avio_skip(pb, size); ++ } else { ++ uint64_t cur_pos = avio_tell(pb); ++ if (cur_pos < list_end) ++ size = FFMIN(size, list_end - cur_pos); ++ st = s->streams[stream_index]; ++ ++ if(size<(1<<30)){ ++ st->codec->extradata_size= size; ++ st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) { ++ st->codec->extradata_size= 0; ++ return AVERROR(ENOMEM); ++ } ++ avio_read(pb, st->codec->extradata, st->codec->extradata_size); ++ } ++ ++ if(st->codec->extradata_size & 1) //FIXME check if the encoder really did this correctly ++ avio_r8(pb); + } +- url_fseek(pb, i+size, SEEK_SET); ++ break; ++ case MKTAG('i', 'n', 'd', 'x'): ++ i= avio_tell(pb); ++ if(pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && avi->use_odml && ++ read_braindead_odml_indx(s, 0) < 0 && s->error_recognition >= FF_ER_EXPLODE) ++ goto fail; ++ avio_seek(pb, i+size, SEEK_SET); + break; + case MKTAG('v', 'p', 'r', 'p'): + if(stream_index < (unsigned)s->nb_streams && size > 9*4){ + AVRational active, active_aspect; + + st = s->streams[stream_index]; +- get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- +- active_aspect.den= get_le16(pb); +- active_aspect.num= get_le16(pb); +- active.num = get_le32(pb); +- active.den = get_le32(pb); +- get_le32(pb); //nbFieldsPerFrame ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ ++ active_aspect.den= avio_rl16(pb); ++ active_aspect.num= avio_rl16(pb); ++ active.num = avio_rl32(pb); ++ active.den = avio_rl32(pb); ++ avio_rl32(pb); //nbFieldsPerFrame + + if(active_aspect.num && active_aspect.den && active.num && active.den){ + st->sample_aspect_ratio= av_div_q(active_aspect, active); +@@ -699,7 +746,7 @@ + } + size -= 9*4; + } +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + break; + case MKTAG('s', 't', 'r', 'n'): + if(s->nb_streams){ +@@ -710,13 +757,15 @@ + if(size > 1000000){ + av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, " + "I will ignore it and try to continue anyway.\n"); +- avi->movi_list = url_ftell(pb) - 4; ++ if (s->error_recognition & AV_EF_EXPLODE) ++ goto fail; ++ avi->movi_list = avio_tell(pb) - 4; + avi->movi_end = avi->fsize; + goto end_of_header; + } + /* skip tag */ + size += (size & 1); +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + } +@@ -727,15 +776,19 @@ + return -1; + } + +- if(!avi->index_loaded && !url_is_streamed(pb)) ++ if(!avi->index_loaded && pb->seekable) + avi_load_index(s); +- avi->index_loaded = 1; +- avi->non_interleaved |= guess_ni_flag(s); ++ avi->index_loaded |= 1; ++ avi->non_interleaved |= guess_ni_flag(s) | (s->flags & AVFMT_FLAG_SORT_DTS); + for(i=0; inb_streams; i++){ + AVStream *st = s->streams[i]; + if(st->nb_index_entries) + break; + } ++ // DV-in-AVI cannot be non-interleaved, if set this must be ++ // a mis-detection. ++ if(avi->dv_demux) ++ avi->non_interleaved=0; + if(i==s->nb_streams && avi->non_interleaved) { + av_log(s, AV_LOG_WARNING, "non-interleaved AVI without index, switching to interleaved\n"); + avi->non_interleaved=0; +@@ -746,56 +799,56 @@ + clean_index(s); + } + +- ff_metadata_conv_ctx(s, NULL, ff_avi_metadata_conv); ++ ff_metadata_conv_ctx(s, NULL, avi_metadata_conv); ++ ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); + + return 0; + } + + static int read_gab2_sub(AVStream *st, AVPacket *pkt) { + if (!strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data+5) == 2) { +- uint8_t desc[256], *d = desc; +- uint8_t *end, *ptr = pkt->data+7; +- unsigned int size, desc_len = bytestream_get_le32(&ptr); +- int score = AVPROBE_SCORE_MAX / 2; ++ uint8_t desc[256]; ++ int score = AVPROBE_SCORE_MAX / 2, ret; + AVIStream *ast = st->priv_data; + AVInputFormat *sub_demuxer; + AVRational time_base; +- ByteIOContext *pb; ++ AVIOContext *pb = avio_alloc_context( pkt->data + 7, ++ pkt->size - 7, ++ 0, NULL, NULL, NULL, NULL); + AVProbeData pd; ++ unsigned int desc_len = avio_rl32(pb); + +- if (desc_len > FFMAX(pkt->size-17, 0)) +- return 0; ++ if (desc_len > pb->buf_end - pb->buf_ptr) ++ goto error; + +- end = ptr + desc_len; +- while (ptr < end-1) { +- uint8_t tmp; +- uint32_t ch; +- GET_UTF16(ch, ptr < end-1 ? bytestream_get_le16(&ptr) : 0, break;); +- PUT_UTF8(ch, tmp, if(d-desc < sizeof(desc)-1) *d++ = tmp;); +- } +- *d = 0; ++ ret = avio_get_str16le(pb, desc_len, desc, sizeof(desc)); ++ avio_skip(pb, desc_len - ret); + if (*desc) +- av_metadata_set2(&st->metadata, "title", desc, 0); ++ av_dict_set(&st->metadata, "title", desc, 0); + +- ptr = end + 2; +- size = bytestream_get_le32(&ptr); +- size = FFMIN(size, pkt->size+pkt->data-ptr); ++ avio_rl16(pb); /* flags? */ ++ avio_rl32(pb); /* data size */ + +- pd = (AVProbeData) { .buf = ptr, .buf_size = size }; ++ pd = (AVProbeData) { .buf = pb->buf_ptr, .buf_size = pb->buf_end - pb->buf_ptr }; + if (!(sub_demuxer = av_probe_input_format2(&pd, 1, &score))) +- return 0; ++ goto error; + +- pb = av_alloc_put_byte(ptr, size, 0, NULL, NULL, NULL, NULL); +- if (!av_open_input_stream(&ast->sub_ctx, pb, "", sub_demuxer, NULL)) { ++ if (!(ast->sub_ctx = avformat_alloc_context())) ++ goto error; ++ ++ ast->sub_ctx->pb = pb; ++ if (!avformat_open_input(&ast->sub_ctx, "", sub_demuxer, NULL)) { + av_read_packet(ast->sub_ctx, &ast->sub_pkt); + *st->codec = *ast->sub_ctx->streams[0]->codec; + ast->sub_ctx->streams[0]->codec->extradata = NULL; + time_base = ast->sub_ctx->streams[0]->time_base; +- av_set_pts_info(st, 64, time_base.num, time_base.den); ++ avpriv_set_pts_info(st, 64, time_base.num, time_base.den); + } + ast->sub_buffer = pkt->data; + memset(pkt, 0, sizeof(*pkt)); + return 1; ++error: ++ av_freep(&pb); + } + return 0; + } +@@ -842,17 +895,148 @@ + } + } + +-static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) ++static int avi_sync(AVFormatContext *s, int exit_early) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; +- int n, d[8]; ++ AVIOContext *pb = s->pb; ++ int n; ++ unsigned int d[8]; + unsigned int size; + int64_t i, sync; ++ ++start_sync: ++ memset(d, -1, sizeof(d)); ++ for(i=sync=avio_tell(pb); !url_feof(pb); i++) { ++ int j; ++ ++ for(j=0; j<7; j++) ++ d[j]= d[j+1]; ++ d[7]= avio_r8(pb); ++ ++ size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); ++ ++ n= get_stream_idx(d+2); ++//av_log(s, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n); ++ if(i + (uint64_t)size > avi->fsize || d[0] > 127) ++ continue; ++ ++ //parse ix## ++ if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) ++ //parse JUNK ++ ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') ++ ||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){ ++ avio_skip(pb, size); ++//av_log(s, AV_LOG_DEBUG, "SKIP\n"); ++ goto start_sync; ++ } ++ ++ //parse stray LIST ++ if(d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T'){ ++ avio_skip(pb, 4); ++ goto start_sync; ++ } ++ ++ n= get_stream_idx(d); ++ ++ if(!((i-avi->last_pkt_pos)&1) && get_stream_idx(d+1) < s->nb_streams) ++ continue; ++ ++ //detect ##ix chunk and skip ++ if(d[2] == 'i' && d[3] == 'x' && n < s->nb_streams){ ++ avio_skip(pb, size); ++ goto start_sync; ++ } ++ ++ //parse ##dc/##wb ++ if(n < s->nb_streams){ ++ AVStream *st; ++ AVIStream *ast; ++ st = s->streams[n]; ++ ast = st->priv_data; ++ ++ if(s->nb_streams>=2){ ++ AVStream *st1 = s->streams[1]; ++ AVIStream *ast1= st1->priv_data; ++ //workaround for broken small-file-bug402.avi ++ if( d[2] == 'w' && d[3] == 'b' ++ && n==0 ++ && st ->codec->codec_type == AVMEDIA_TYPE_VIDEO ++ && st1->codec->codec_type == AVMEDIA_TYPE_AUDIO ++ && ast->prefix == 'd'*256+'c' ++ && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count) ++ ){ ++ n=1; ++ st = st1; ++ ast = ast1; ++ av_log(s, AV_LOG_WARNING, "Invalid stream + prefix combination, assuming audio.\n"); ++ } ++ } ++ ++ ++ if( (st->discard >= AVDISCARD_DEFAULT && size==0) ++ /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering ++ || st->discard >= AVDISCARD_ALL){ ++ if (!exit_early) { ++ ast->frame_offset += get_duration(ast, size); ++ } ++ avio_skip(pb, size); ++ goto start_sync; ++ } ++ ++ if (d[2] == 'p' && d[3] == 'c' && size<=4*256+4) { ++ int k = avio_r8(pb); ++ int last = (k + avio_r8(pb) - 1) & 0xFF; ++ ++ avio_rl16(pb); //flags ++ ++ for (; k <= last; k++) ++ ast->pal[k] = 0xFF<<24 | avio_rb32(pb)>>8;// b + (g << 8) + (r << 16); ++ ast->has_pal= 1; ++ goto start_sync; ++ } else if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) || ++ d[2]*256+d[3] == ast->prefix /*|| ++ (d[2] == 'd' && d[3] == 'c') || ++ (d[2] == 'w' && d[3] == 'b')*/) { ++ ++ if (exit_early) ++ return 0; ++//av_log(s, AV_LOG_DEBUG, "OK\n"); ++ if(d[2]*256+d[3] == ast->prefix) ++ ast->prefix_count++; ++ else{ ++ ast->prefix= d[2]*256+d[3]; ++ ast->prefix_count= 0; ++ } ++ ++ avi->stream_index= n; ++ ast->packet_size= size + 8; ++ ast->remaining= size; ++ ++ if(size || !ast->sample_size){ ++ uint64_t pos= avio_tell(pb) - 8; ++ if(!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos){ ++ av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); ++ } ++ } ++ return 0; ++ } ++ } ++ } ++ ++ if(pb->error) ++ return pb->error; ++ return AVERROR_EOF; ++} ++ ++static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIContext *avi = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int err; + void* dstr; + + if (CONFIG_DV_DEMUXER && avi->dv_demux) { +- int size = dv_get_packet(avi->dv_demux, pkt); ++ int size = avpriv_dv_get_packet(avi->dv_demux, pkt); + if (size >= 0) + return size; + } +@@ -887,10 +1071,10 @@ + } + } + if(!best_st) +- return -1; ++ return AVERROR_EOF; + + best_ast = best_st->priv_data; +- best_ts = av_rescale_q(best_ts, (AVRational){FFMAX(1, best_ast->sample_size), AV_TIME_BASE}, best_st->time_base); ++ best_ts = best_ast->frame_offset; + if(best_ast->remaining) + i= av_index_search_timestamp(best_st, best_ts, AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); + else{ +@@ -903,7 +1087,7 @@ + if(i>=0){ + int64_t pos= best_st->index_entries[i].pos; + pos += best_ast->packet_size - best_ast->remaining; +- if(url_fseek(s->pb, pos + 8, SEEK_SET) < 0) ++ if(avio_seek(s->pb, pos + 8, SEEK_SET) < 0) + return AVERROR_EOF; + // av_log(s, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos); + +@@ -937,26 +1121,26 @@ + + if(size > ast->remaining) + size= ast->remaining; +- avi->last_pkt_pos= url_ftell(pb); ++ avi->last_pkt_pos= avio_tell(pb); + err= av_get_packet(pb, pkt, size); + if(err<0) + return err; + + if(ast->has_pal && pkt->data && pkt->size<(unsigned)INT_MAX/2){ +- void *ptr= av_realloc(pkt->data, pkt->size + 4*256 + FF_INPUT_BUFFER_PADDING_SIZE); +- if(ptr){ +- ast->has_pal=0; +- pkt->size += 4*256; +- pkt->data= ptr; +- memcpy(pkt->data + pkt->size - 4*256, ast->pal, 4*256); +- }else +- av_log(s, AV_LOG_ERROR, "Failed to append palette\n"); ++ uint8_t *pal; ++ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); ++ if(!pal){ ++ av_log(s, AV_LOG_ERROR, "Failed to allocate data for palette\n"); ++ }else{ ++ memcpy(pal, ast->pal, AVPALETTE_SIZE); ++ ast->has_pal = 0; ++ } + } + + if (CONFIG_DV_DEMUXER && avi->dv_demux) { + dstr = pkt->destruct; +- size = dv_produce_packet(avi->dv_demux, pkt, +- pkt->data, pkt->size); ++ size = avpriv_dv_produce_packet(avi->dv_demux, pkt, ++ pkt->data, pkt->size, pkt->pos); + pkt->destruct = dstr; + pkt->flags |= AV_PKT_FLAG_KEY; + if (size < 0) +@@ -985,6 +1169,23 @@ + e= &st->index_entries[index]; + + if(index >= 0 && e->timestamp == ast->frame_offset){ ++ if (index == st->nb_index_entries-1){ ++ int key=1; ++ int i; ++ uint32_t state=-1; ++ for(i=0; icodec->codec_id == CODEC_ID_MPEG4){ ++ if(state == 0x1B6){ ++ key= !(pkt->data[i]&0xC0); ++ break; ++ } ++ }else ++ break; ++ state= (state<<8) + pkt->data[i]; ++ } ++ if(!key) ++ e->flags &= ~AVINDEX_KEYFRAME; ++ } + if (e->flags & AVINDEX_KEYFRAME) + pkt->flags |= AV_PKT_FLAG_KEY; + } +@@ -999,124 +1200,28 @@ + ast->packet_size= 0; + } + +- return size; +- } +- +- memset(d, -1, sizeof(int)*8); +- for(i=sync=url_ftell(pb); !url_feof(pb); i++) { +- int j; +- +- for(j=0; j<7; j++) +- d[j]= d[j+1]; +- d[7]= get_byte(pb); +- +- size= d[4] + (d[5]<<8) + (d[6]<<16) + (d[7]<<24); +- +- n= get_stream_idx(d+2); +-//av_log(s, AV_LOG_DEBUG, "%X %X %X %X %X %X %X %X %"PRId64" %d %d\n", d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], i, size, n); +- if(i + (uint64_t)size > avi->fsize || d[0]<0) +- continue; +- +- //parse ix## +- if( (d[0] == 'i' && d[1] == 'x' && n < s->nb_streams) +- //parse JUNK +- ||(d[0] == 'J' && d[1] == 'U' && d[2] == 'N' && d[3] == 'K') +- ||(d[0] == 'i' && d[1] == 'd' && d[2] == 'x' && d[3] == '1')){ +- url_fskip(pb, size); +-//av_log(s, AV_LOG_DEBUG, "SKIP\n"); ++ if(!avi->non_interleaved && pkt->pos >= 0 && ast->seek_pos > pkt->pos){ ++ av_free_packet(pkt); + goto resync; + } ++ ast->seek_pos= 0; + +- //parse stray LIST +- if(d[0] == 'L' && d[1] == 'I' && d[2] == 'S' && d[3] == 'T'){ +- url_fskip(pb, 4); +- goto resync; +- } ++ if(!avi->non_interleaved && st->nb_index_entries>1 && avi->index_loaded>1){ ++ int64_t dts= av_rescale_q(pkt->dts, st->time_base, AV_TIME_BASE_Q); + +- n= get_stream_idx(d); +- +- if(!((i-avi->last_pkt_pos)&1) && get_stream_idx(d+1) < s->nb_streams) +- continue; +- +- //detect ##ix chunk and skip +- if(d[2] == 'i' && d[3] == 'x' && n < s->nb_streams){ +- url_fskip(pb, size); +- goto resync; ++ if(avi->dts_max - dts > 2*AV_TIME_BASE){ ++ avi->non_interleaved= 1; ++ av_log(s, AV_LOG_INFO, "Switching to NI mode, due to poor interleaving\n"); ++ }else if(avi->dts_max < dts) ++ avi->dts_max = dts; + } + +- //parse ##dc/##wb +- if(n < s->nb_streams){ +- AVStream *st; +- AVIStream *ast; +- st = s->streams[n]; +- ast = st->priv_data; +- +- if(s->nb_streams>=2){ +- AVStream *st1 = s->streams[1]; +- AVIStream *ast1= st1->priv_data; +- //workaround for broken small-file-bug402.avi +- if( d[2] == 'w' && d[3] == 'b' +- && n==0 +- && st ->codec->codec_type == AVMEDIA_TYPE_VIDEO +- && st1->codec->codec_type == AVMEDIA_TYPE_AUDIO +- && ast->prefix == 'd'*256+'c' +- && (d[2]*256+d[3] == ast1->prefix || !ast1->prefix_count) +- ){ +- n=1; +- st = st1; +- ast = ast1; +- av_log(s, AV_LOG_WARNING, "Invalid stream + prefix combination, assuming audio.\n"); +- } +- } +- +- +- if( (st->discard >= AVDISCARD_DEFAULT && size==0) +- /*|| (st->discard >= AVDISCARD_NONKEY && !(pkt->flags & AV_PKT_FLAG_KEY))*/ //FIXME needs a little reordering +- || st->discard >= AVDISCARD_ALL){ +- ast->frame_offset += get_duration(ast, size); +- url_fskip(pb, size); +- goto resync; +- } +- +- if (d[2] == 'p' && d[3] == 'c' && size<=4*256+4) { +- int k = get_byte(pb); +- int last = (k + get_byte(pb) - 1) & 0xFF; +- +- get_le16(pb); //flags +- +- for (; k <= last; k++) +- ast->pal[k] = get_be32(pb)>>8;// b + (g << 8) + (r << 16); +- ast->has_pal= 1; +- goto resync; +- } else if( ((ast->prefix_count<5 || sync+9 > i) && d[2]<128 && d[3]<128) || +- d[2]*256+d[3] == ast->prefix /*|| +- (d[2] == 'd' && d[3] == 'c') || +- (d[2] == 'w' && d[3] == 'b')*/) { +- +-//av_log(s, AV_LOG_DEBUG, "OK\n"); +- if(d[2]*256+d[3] == ast->prefix) +- ast->prefix_count++; +- else{ +- ast->prefix= d[2]*256+d[3]; +- ast->prefix_count= 0; +- } +- +- avi->stream_index= n; +- ast->packet_size= size + 8; +- ast->remaining= size; +- +- if(size || !ast->sample_size){ +- uint64_t pos= url_ftell(pb) - 8; +- if(!st->index_entries || !st->nb_index_entries || st->index_entries[st->nb_index_entries - 1].pos < pos){ +- av_add_index_entry(st, pos, ast->frame_offset, size, 0, AVINDEX_KEYFRAME); +- } +- } +- goto resync; +- } +- } ++ return size; + } + +- return AVERROR_EOF; ++ if ((err = avi_sync(s, 0)) < 0) ++ return err; ++ goto resync; + } + + /* XXX: We make the implicit supposition that the positions are sorted +@@ -1124,30 +1229,37 @@ + static int avi_read_idx1(AVFormatContext *s, int size) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int nb_index_entries, i; + AVStream *st; + AVIStream *ast; +- unsigned int index, tag, flags, pos, len; ++ unsigned int index, tag, flags, pos, len, first_packet = 1; + unsigned last_pos= -1; ++ int64_t idx1_pos, first_packet_pos = 0, data_offset = 0; + + nb_index_entries = size / 16; + if (nb_index_entries <= 0) + return -1; + ++ idx1_pos = avio_tell(pb); ++ avio_seek(pb, avi->movi_list+4, SEEK_SET); ++ if (avi_sync(s, 1) == 0) { ++ first_packet_pos = avio_tell(pb) - 8; ++ } ++ avi->stream_index = -1; ++ avio_seek(pb, idx1_pos, SEEK_SET); ++ + /* Read the entries and sort them in each stream component. */ + for(i = 0; i < nb_index_entries; i++) { +- tag = get_le32(pb); +- flags = get_le32(pb); +- pos = get_le32(pb); +- len = get_le32(pb); +-#if defined(DEBUG_SEEK) +- av_log(s, AV_LOG_DEBUG, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/", +- i, tag, flags, pos, len); +-#endif +- if(i==0 && pos > avi->movi_list) +- avi->movi_list= 0; //FIXME better check +- pos += avi->movi_list; ++ if(url_feof(pb)) ++ return -1; ++ ++ tag = avio_rl32(pb); ++ flags = avio_rl32(pb); ++ pos = avio_rl32(pb); ++ len = avio_rl32(pb); ++ av_dlog(s, "%d: tag=0x%x flags=0x%x pos=0x%x len=%d/", ++ i, tag, flags, pos, len); + + index = ((tag & 0xff) - '0') * 10; + index += ((tag >> 8) & 0xff) - '0'; +@@ -1156,11 +1268,14 @@ + st = s->streams[index]; + ast = st->priv_data; + +-#if defined(DEBUG_SEEK) +- av_log(s, AV_LOG_DEBUG, "%d cum_len=%"PRId64"\n", len, ast->cum_len); +-#endif +- if(url_feof(pb)) +- return -1; ++ if(first_packet && first_packet_pos && len) { ++ data_offset = first_packet_pos - pos; ++ first_packet = 0; ++ } ++ pos += data_offset; ++ ++ av_dlog(s, "%d cum_len=%"PRId64"\n", len, ast->cum_len); ++ + + if(last_pos == pos) + avi->non_interleaved= 1; +@@ -1176,7 +1291,7 @@ + int i; + int64_t last_start=0; + int64_t first_end= INT64_MAX; +- int64_t oldpos= url_ftell(s->pb); ++ int64_t oldpos= avio_tell(s->pb); + + for(i=0; inb_streams; i++){ + AVStream *st = s->streams[i]; +@@ -1188,8 +1303,8 @@ + + if(n >= 2){ + int64_t pos= st->index_entries[0].pos; +- url_fseek(s->pb, pos + 4, SEEK_SET); +- size= get_le32(s->pb); ++ avio_seek(s->pb, pos + 4, SEEK_SET); ++ size= avio_rl32(s->pb); + if(pos + size > st->index_entries[1].pos) + last_start= INT64_MAX; + } +@@ -1199,53 +1314,46 @@ + if(st->index_entries[n-1].pos < first_end) + first_end= st->index_entries[n-1].pos; + } +- url_fseek(s->pb, oldpos, SEEK_SET); ++ avio_seek(s->pb, oldpos, SEEK_SET); + return last_start > first_end; + } + + static int avi_load_index(AVFormatContext *s) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint32_t tag, size; +- int64_t pos= url_ftell(pb); ++ int64_t pos= avio_tell(pb); + int ret = -1; + +- if (url_fseek(pb, avi->movi_end, SEEK_SET) < 0) ++ if (avio_seek(pb, avi->movi_end, SEEK_SET) < 0) + goto the_end; // maybe truncated file +-#ifdef DEBUG_SEEK +- printf("movi_end=0x%"PRIx64"\n", avi->movi_end); +-#endif ++ av_dlog(s, "movi_end=0x%"PRIx64"\n", avi->movi_end); + for(;;) { + if (url_feof(pb)) + break; +- tag = get_le32(pb); +- size = get_le32(pb); +-#ifdef DEBUG_SEEK +- printf("tag=%c%c%c%c size=0x%x\n", +- tag & 0xff, +- (tag >> 8) & 0xff, +- (tag >> 16) & 0xff, +- (tag >> 24) & 0xff, +- size); +-#endif +- switch(tag) { +- case MKTAG('i', 'd', 'x', '1'): +- if (avi_read_idx1(s, size) < 0) +- goto skip; ++ tag = avio_rl32(pb); ++ size = avio_rl32(pb); ++ av_dlog(s, "tag=%c%c%c%c size=0x%x\n", ++ tag & 0xff, ++ (tag >> 8) & 0xff, ++ (tag >> 16) & 0xff, ++ (tag >> 24) & 0xff, ++ size); ++ ++ if (tag == MKTAG('i', 'd', 'x', '1') && ++ avi_read_idx1(s, size) >= 0) { ++ avi->index_loaded=2; + ret = 0; +- goto the_end; +- break; +- default: +- skip: +- size += (size & 1); +- if (url_fseek(pb, size, SEEK_CUR) < 0) +- goto the_end; // something is wrong here + break; + } ++ ++ size += (size & 1); ++ if (avio_skip(pb, size) < 0) ++ break; // something is wrong here + } + the_end: +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + return ret; + } + +@@ -1264,13 +1372,13 @@ + AVIContext *avi = s->priv_data; + AVStream *st; + int i, index; +- int64_t pos; ++ int64_t pos, pos_min; + AVIStream *ast; + + if (!avi->index_loaded) { + /* we only load the index on demand */ + avi_load_index(s); +- avi->index_loaded = 1; ++ avi->index_loaded |= 1; + } + assert(stream_index>= 0); + +@@ -1292,7 +1400,7 @@ + /* the av_index_search_timestamp call above. */ + assert(stream_index == 0); + +- if(url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if(avio_seek(s->pb, pos, SEEK_SET) < 0) + return -1; + + /* Feed the DV video stream version of the timestamp to the */ +@@ -1303,6 +1411,7 @@ + return 0; + } + ++ pos_min= pos; + for(i = 0; i < s->nb_streams; i++) { + AVStream *st2 = s->streams[i]; + AVIStream *ast2 = st2->priv_data; +@@ -1323,26 +1432,35 @@ + index = av_index_search_timestamp( + st2, + av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1), +- flags | AVSEEK_FLAG_BACKWARD); ++ flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); + if(index<0) + index=0; ++ ast2->seek_pos= st2->index_entries[index].pos; ++ pos_min= FFMIN(pos_min,ast2->seek_pos); ++ } ++ for(i = 0; i < s->nb_streams; i++) { ++ AVStream *st2 = s->streams[i]; ++ AVIStream *ast2 = st2->priv_data; + +- if(!avi->non_interleaved){ +- while(index>0 && st2->index_entries[index].pos > pos) +- index--; +- while(index+1 < st2->nb_index_entries && st2->index_entries[index].pos < pos) +- index++; +- } ++ if (ast2->sub_ctx || st2->nb_index_entries <= 0) ++ continue; + +-// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %"PRId64"\n", timestamp, index, st2->index_entries[index].timestamp); +- /* extract the current frame number */ ++ index = av_index_search_timestamp( ++ st2, ++ av_rescale_q(timestamp, st->time_base, st2->time_base) * FFMAX(ast2->sample_size, 1), ++ flags | AVSEEK_FLAG_BACKWARD | (st2->codec->codec_type != AVMEDIA_TYPE_VIDEO ? AVSEEK_FLAG_ANY : 0)); ++ if(index<0) ++ index=0; ++ while(!avi->non_interleaved && index>0 && st2->index_entries[index-1].pos >= pos_min) ++ index--; + ast2->frame_offset = st2->index_entries[index].timestamp; + } + + /* do the seek */ +- if(url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if (avio_seek(s->pb, pos_min, SEEK_SET) < 0) + return -1; + avi->stream_index= -1; ++ avi->dts_max= INT_MIN; + return 0; + } + +@@ -1354,19 +1472,17 @@ + for(i=0;inb_streams;i++) { + AVStream *st = s->streams[i]; + AVIStream *ast = st->priv_data; +- av_free(st->codec->palctrl); + if (ast) { + if (ast->sub_ctx) { + av_freep(&ast->sub_ctx->pb); +- av_close_input_stream(ast->sub_ctx); ++ avformat_close_input(&ast->sub_ctx); + } + av_free(ast->sub_buffer); + av_free_packet(&ast->sub_pkt); + } + } + +- if (avi->dv_demux) +- av_free(avi->dv_demux); ++ av_free(avi->dv_demux); + + return 0; + } +@@ -1385,12 +1501,13 @@ + } + + AVInputFormat ff_avi_demuxer = { +- "avi", +- NULL_IF_CONFIG_SMALL("AVI format"), +- sizeof(AVIContext), +- avi_probe, +- avi_read_header, +- avi_read_packet, +- avi_read_close, +- avi_read_seek, ++ .name = "avi", ++ .long_name = NULL_IF_CONFIG_SMALL("AVI format"), ++ .priv_data_size = sizeof(AVIContext), ++ .read_probe = avi_probe, ++ .read_header = avi_read_header, ++ .read_packet = avi_read_packet, ++ .read_close = avi_read_close, ++ .read_seek = avi_read_seek, ++ .priv_class = &demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avienc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avienc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avienc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avienc.c 2012-05-14 14:08:54.906351494 +0200 +@@ -19,9 +19,12 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "internal.h" + #include "avi.h" ++#include "avio_internal.h" + #include "riff.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + + /* + * TODO: +@@ -63,7 +66,7 @@ + return &idx->cluster[cl][id]; + } + +-static int64_t avi_start_new_riff(AVFormatContext *s, ByteIOContext *pb, ++static int64_t avi_start_new_riff(AVFormatContext *s, AVIOContext *pb, + const char* riff_tag, const char* list_tag) + { + AVIContext *avi= s->priv_data; +@@ -77,16 +80,16 @@ + } + + avi->riff_start = ff_start_tag(pb, "RIFF"); +- put_tag(pb, riff_tag); ++ ffio_wfourcc(pb, riff_tag); + loff = ff_start_tag(pb, "LIST"); +- put_tag(pb, list_tag); ++ ffio_wfourcc(pb, list_tag); + return loff; + } + + static char* avi_stream2fourcc(char* tag, int index, enum AVMediaType type) + { +- tag[0] = '0'; +- tag[1] = '0' + index; ++ tag[0] = '0' + index/10; ++ tag[1] = '0' + index%10; + if (type == AVMEDIA_TYPE_VIDEO) { + tag[2] = 'd'; + tag[3] = 'c'; +@@ -102,49 +105,49 @@ + return tag; + } + +-static void avi_write_info_tag(ByteIOContext *pb, const char *tag, const char *str) ++static void avi_write_info_tag(AVIOContext *pb, const char *tag, const char *str) + { + int len = strlen(str); + if (len > 0) { + len++; +- put_tag(pb, tag); +- put_le32(pb, len); ++ ffio_wfourcc(pb, tag); ++ avio_wl32(pb, len); + avio_put_str(pb, str); + if (len & 1) +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + } + + static int avi_write_counters(AVFormatContext* s, int riff_id) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVIContext *avi = s->priv_data; + int n, au_byterate, au_ssize, au_scale, nb_frames = 0; + int64_t file_size; + AVCodecContext* stream; + +- file_size = url_ftell(pb); ++ file_size = avio_tell(pb); + for(n = 0; n < s->nb_streams; n++) { + AVIStream *avist= s->streams[n]->priv_data; + + assert(avist->frames_hdr_strm); + stream = s->streams[n]->codec; +- url_fseek(pb, avist->frames_hdr_strm, SEEK_SET); ++ avio_seek(pb, avist->frames_hdr_strm, SEEK_SET); + ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); + if(au_ssize == 0) { +- put_le32(pb, avist->packet_count); ++ avio_wl32(pb, avist->packet_count); + } else { +- put_le32(pb, avist->audio_strm_length / au_ssize); ++ avio_wl32(pb, avist->audio_strm_length / au_ssize); + } + if(stream->codec_type == AVMEDIA_TYPE_VIDEO) + nb_frames = FFMAX(nb_frames, avist->packet_count); + } + if(riff_id == 1) { + assert(avi->frames_hdr_all); +- url_fseek(pb, avi->frames_hdr_all, SEEK_SET); +- put_le32(pb, nb_frames); ++ avio_seek(pb, avi->frames_hdr_all, SEEK_SET); ++ avio_wl32(pb, nb_frames); + } +- url_fseek(pb, file_size, SEEK_SET); ++ avio_seek(pb, file_size, SEEK_SET); + + return 0; + } +@@ -152,11 +155,17 @@ + static int avi_write_header(AVFormatContext *s) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int bitrate, n, i, nb_frames, au_byterate, au_ssize, au_scale; + AVCodecContext *stream, *video_enc; + int64_t list1, list2, strh, strf; +- AVMetadataTag *t = NULL; ++ AVDictionaryEntry *t = NULL; ++ ++ if (s->nb_streams > AVI_MAX_STREAM_COUNT) { ++ av_log(s, AV_LOG_ERROR, "AVI does not support >%d streams\n", ++ AVI_MAX_STREAM_COUNT); ++ return -1; ++ } + + for(n=0;nnb_streams;n++) { + s->streams[n]->priv_data= av_mallocz(sizeof(AVIStream)); +@@ -169,8 +178,8 @@ + list1 = avi_start_new_riff(s, pb, "AVI ", "hdrl"); + + /* avi header */ +- put_tag(pb, "avih"); +- put_le32(pb, 14 * 4); ++ ffio_wfourcc(pb, "avih"); ++ avio_wl32(pb, 14 * 4); + bitrate = 0; + + video_enc = NULL; +@@ -184,38 +193,38 @@ + nb_frames = 0; + + if(video_enc){ +- put_le32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den)); ++ avio_wl32(pb, (uint32_t)(INT64_C(1000000) * video_enc->time_base.num / video_enc->time_base.den)); + } else { +- put_le32(pb, 0); ++ avio_wl32(pb, 0); + } +- put_le32(pb, bitrate / 8); /* XXX: not quite exact */ +- put_le32(pb, 0); /* padding */ +- if (url_is_streamed(pb)) +- put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */ ++ avio_wl32(pb, bitrate / 8); /* XXX: not quite exact */ ++ avio_wl32(pb, 0); /* padding */ ++ if (!pb->seekable) ++ avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_ISINTERLEAVED); /* flags */ + else +- put_le32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ +- avi->frames_hdr_all = url_ftell(pb); /* remember this offset to fill later */ +- put_le32(pb, nb_frames); /* nb frames, filled later */ +- put_le32(pb, 0); /* initial frame */ +- put_le32(pb, s->nb_streams); /* nb streams */ +- put_le32(pb, 1024 * 1024); /* suggested buffer size */ ++ avio_wl32(pb, AVIF_TRUSTCKTYPE | AVIF_HASINDEX | AVIF_ISINTERLEAVED); /* flags */ ++ avi->frames_hdr_all = avio_tell(pb); /* remember this offset to fill later */ ++ avio_wl32(pb, nb_frames); /* nb frames, filled later */ ++ avio_wl32(pb, 0); /* initial frame */ ++ avio_wl32(pb, s->nb_streams); /* nb streams */ ++ avio_wl32(pb, 1024 * 1024); /* suggested buffer size */ + if(video_enc){ +- put_le32(pb, video_enc->width); +- put_le32(pb, video_enc->height); ++ avio_wl32(pb, video_enc->width); ++ avio_wl32(pb, video_enc->height); + } else { +- put_le32(pb, 0); +- put_le32(pb, 0); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); + } +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ + + /* stream list */ + for(i=0;istreams[i]->priv_data; + list2 = ff_start_tag(pb, "LIST"); +- put_tag(pb, "strl"); ++ ffio_wfourcc(pb, "strl"); + + stream = s->streams[i]->codec; + +@@ -229,46 +238,46 @@ + av_log(s, AV_LOG_ERROR, "Subtitle streams other than DivX XSUB are not supported by the AVI muxer.\n"); + return AVERROR_PATCHWELCOME; + } +- case AVMEDIA_TYPE_VIDEO: put_tag(pb, "vids"); break; +- case AVMEDIA_TYPE_AUDIO: put_tag(pb, "auds"); break; +-// case AVMEDIA_TYPE_TEXT : put_tag(pb, "txts"); break; +- case AVMEDIA_TYPE_DATA : put_tag(pb, "dats"); break; ++ case AVMEDIA_TYPE_VIDEO: ffio_wfourcc(pb, "vids"); break; ++ case AVMEDIA_TYPE_AUDIO: ffio_wfourcc(pb, "auds"); break; ++// case AVMEDIA_TYPE_TEXT : ffio_wfourcc(pb, "txts"); break; ++ case AVMEDIA_TYPE_DATA : ffio_wfourcc(pb, "dats"); break; + } + if(stream->codec_type == AVMEDIA_TYPE_VIDEO || + stream->codec_id == CODEC_ID_XSUB) +- put_le32(pb, stream->codec_tag); ++ avio_wl32(pb, stream->codec_tag); + else +- put_le32(pb, 1); +- put_le32(pb, 0); /* flags */ +- put_le16(pb, 0); /* priority */ +- put_le16(pb, 0); /* language */ +- put_le32(pb, 0); /* initial frame */ ++ avio_wl32(pb, 1); ++ avio_wl32(pb, 0); /* flags */ ++ avio_wl16(pb, 0); /* priority */ ++ avio_wl16(pb, 0); /* language */ ++ avio_wl32(pb, 0); /* initial frame */ + + ff_parse_specific_params(stream, &au_byterate, &au_ssize, &au_scale); + +- put_le32(pb, au_scale); /* scale */ +- put_le32(pb, au_byterate); /* rate */ +- av_set_pts_info(s->streams[i], 64, au_scale, au_byterate); +- +- put_le32(pb, 0); /* start */ +- avist->frames_hdr_strm = url_ftell(pb); /* remember this offset to fill later */ +- if (url_is_streamed(pb)) +- put_le32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */ ++ avio_wl32(pb, au_scale); /* scale */ ++ avio_wl32(pb, au_byterate); /* rate */ ++ avpriv_set_pts_info(s->streams[i], 64, au_scale, au_byterate); ++ ++ avio_wl32(pb, 0); /* start */ ++ avist->frames_hdr_strm = avio_tell(pb); /* remember this offset to fill later */ ++ if (!pb->seekable) ++ avio_wl32(pb, AVI_MAX_RIFF_SIZE); /* FIXME: this may be broken, but who cares */ + else +- put_le32(pb, 0); /* length, XXX: filled later */ ++ avio_wl32(pb, 0); /* length, XXX: filled later */ + + /* suggested buffer size */ //FIXME set at the end to largest chunk + if(stream->codec_type == AVMEDIA_TYPE_VIDEO) +- put_le32(pb, 1024 * 1024); ++ avio_wl32(pb, 1024 * 1024); + else if(stream->codec_type == AVMEDIA_TYPE_AUDIO) +- put_le32(pb, 12 * 1024); ++ avio_wl32(pb, 12 * 1024); + else +- put_le32(pb, 0); +- put_le32(pb, -1); /* quality */ +- put_le32(pb, au_ssize); /* sample size */ +- put_le32(pb, 0); +- put_le16(pb, stream->width); +- put_le16(pb, stream->height); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, -1); /* quality */ ++ avio_wl32(pb, au_ssize); /* sample size */ ++ avio_wl32(pb, 0); ++ avio_wl16(pb, stream->width); ++ avio_wl16(pb, stream->height); + ff_end_tag(pb, strh); + + if(stream->codec_type != AVMEDIA_TYPE_DATA){ +@@ -290,13 +299,13 @@ + return -1; + } + ff_end_tag(pb, strf); +- if ((t = av_metadata_get(s->streams[i]->metadata, "title", NULL, 0))) { ++ if ((t = av_dict_get(s->streams[i]->metadata, "title", NULL, 0))) { + avi_write_info_tag(s->pb, "strn", t->value); + t = NULL; + } + } + +- if (!url_is_streamed(pb)) { ++ if (pb->seekable) { + unsigned char tag[5]; + int j; + +@@ -307,16 +316,16 @@ + */ + avist->indexes.entry = avist->indexes.ents_allocated = 0; + avist->indexes.indx_start = ff_start_tag(pb, "JUNK"); +- put_le16(pb, 4); /* wLongsPerEntry */ +- put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ +- put_byte(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ +- put_le32(pb, 0); /* nEntriesInUse (will fill out later on) */ +- put_tag(pb, avi_stream2fourcc(&tag[0], i, stream->codec_type)); ++ avio_wl16(pb, 4); /* wLongsPerEntry */ ++ avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ ++ avio_w8(pb, 0); /* bIndexType (0 == AVI_INDEX_OF_INDEXES) */ ++ avio_wl32(pb, 0); /* nEntriesInUse (will fill out later on) */ ++ ffio_wfourcc(pb, avi_stream2fourcc(tag, i, stream->codec_type)); + /* dwChunkId */ +- put_le64(pb, 0); /* dwReserved[3] +- put_le32(pb, 0); Must be 0. */ ++ avio_wl64(pb, 0); /* dwReserved[3] ++ avio_wl32(pb, 0); Must be 0. */ + for (j=0; j < AVI_MASTER_INDEX_SIZE * 2; j++) +- put_le64(pb, 0); ++ avio_wl64(pb, 0); + ff_end_tag(pb, avist->indexes.indx_start); + } + +@@ -329,50 +338,50 @@ + int num, den; + av_reduce(&num, &den, dar.num, dar.den, 0xFFFF); + +- put_le32(pb, 0); //video format = unknown +- put_le32(pb, 0); //video standard= unknown +- put_le32(pb, lrintf(1.0/av_q2d(stream->time_base))); +- put_le32(pb, stream->width ); +- put_le32(pb, stream->height); +- put_le16(pb, den); +- put_le16(pb, num); +- put_le32(pb, stream->width ); +- put_le32(pb, stream->height); +- put_le32(pb, 1); //progressive FIXME +- +- put_le32(pb, stream->height); +- put_le32(pb, stream->width ); +- put_le32(pb, stream->height); +- put_le32(pb, stream->width ); +- put_le32(pb, 0); +- put_le32(pb, 0); ++ avio_wl32(pb, 0); //video format = unknown ++ avio_wl32(pb, 0); //video standard= unknown ++ avio_wl32(pb, lrintf(1.0/av_q2d(stream->time_base))); ++ avio_wl32(pb, stream->width ); ++ avio_wl32(pb, stream->height); ++ avio_wl16(pb, den); ++ avio_wl16(pb, num); ++ avio_wl32(pb, stream->width ); ++ avio_wl32(pb, stream->height); ++ avio_wl32(pb, 1); //progressive FIXME ++ ++ avio_wl32(pb, stream->height); ++ avio_wl32(pb, stream->width ); ++ avio_wl32(pb, stream->height); ++ avio_wl32(pb, stream->width ); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); + +- put_le32(pb, 0); +- put_le32(pb, 0); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); + ff_end_tag(pb, vprp); + } + + ff_end_tag(pb, list2); + } + +- if (!url_is_streamed(pb)) { ++ if (pb->seekable) { + /* AVI could become an OpenDML one, if it grows beyond 2Gb range */ + avi->odml_list = ff_start_tag(pb, "JUNK"); +- put_tag(pb, "odml"); +- put_tag(pb, "dmlh"); +- put_le32(pb, 248); ++ ffio_wfourcc(pb, "odml"); ++ ffio_wfourcc(pb, "dmlh"); ++ avio_wl32(pb, 248); + for (i = 0; i < 248; i+= 4) +- put_le32(pb, 0); ++ avio_wl32(pb, 0); + ff_end_tag(pb, avi->odml_list); + } + + ff_end_tag(pb, list1); + + list2 = ff_start_tag(pb, "LIST"); +- put_tag(pb, "INFO"); +- ff_metadata_conv(&s->metadata, ff_avi_metadata_conv, NULL); +- for (i = 0; *ff_avi_tags[i]; i++) { +- if ((t = av_metadata_get(s->metadata, ff_avi_tags[i], NULL, AV_METADATA_MATCH_CASE))) ++ ffio_wfourcc(pb, "INFO"); ++ ff_metadata_conv(&s->metadata, ff_riff_info_conv, NULL); ++ for (i = 0; *ff_riff_tags[i]; i++) { ++ if ((t = av_dict_get(s->metadata, ff_riff_tags[i], NULL, AV_DICT_MATCH_CASE))) + avi_write_info_tag(s->pb, t->key, t->value); + } + ff_end_tag(pb, list2); +@@ -380,26 +389,26 @@ + /* some padding for easier tag editing */ + list2 = ff_start_tag(pb, "JUNK"); + for (i = 0; i < 1016; i += 4) +- put_le32(pb, 0); ++ avio_wl32(pb, 0); + ff_end_tag(pb, list2); + + avi->movi_list = ff_start_tag(pb, "LIST"); +- put_tag(pb, "movi"); ++ ffio_wfourcc(pb, "movi"); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int avi_write_ix(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVIContext *avi = s->priv_data; + char tag[5]; + char ix_tag[] = "ix00"; + int i, j; + +- assert(!url_is_streamed(pb)); ++ assert(pb->seekable); + + if (avi->riff_id > AVI_MASTER_INDEX_SIZE) + return -1; +@@ -408,56 +417,56 @@ + AVIStream *avist= s->streams[i]->priv_data; + int64_t ix, pos; + +- avi_stream2fourcc(&tag[0], i, s->streams[i]->codec->codec_type); ++ avi_stream2fourcc(tag, i, s->streams[i]->codec->codec_type); + ix_tag[3] = '0' + i; + + /* Writing AVI OpenDML leaf index chunk */ +- ix = url_ftell(pb); +- put_tag(pb, &ix_tag[0]); /* ix?? */ +- put_le32(pb, avist->indexes.entry * 8 + 24); ++ ix = avio_tell(pb); ++ ffio_wfourcc(pb, ix_tag); /* ix?? */ ++ avio_wl32(pb, avist->indexes.entry * 8 + 24); + /* chunk size */ +- put_le16(pb, 2); /* wLongsPerEntry */ +- put_byte(pb, 0); /* bIndexSubType (0 == frame index) */ +- put_byte(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */ +- put_le32(pb, avist->indexes.entry); ++ avio_wl16(pb, 2); /* wLongsPerEntry */ ++ avio_w8(pb, 0); /* bIndexSubType (0 == frame index) */ ++ avio_w8(pb, 1); /* bIndexType (1 == AVI_INDEX_OF_CHUNKS) */ ++ avio_wl32(pb, avist->indexes.entry); + /* nEntriesInUse */ +- put_tag(pb, &tag[0]); /* dwChunkId */ +- put_le64(pb, avi->movi_list);/* qwBaseOffset */ +- put_le32(pb, 0); /* dwReserved_3 (must be 0) */ ++ ffio_wfourcc(pb, tag); /* dwChunkId */ ++ avio_wl64(pb, avi->movi_list);/* qwBaseOffset */ ++ avio_wl32(pb, 0); /* dwReserved_3 (must be 0) */ + + for (j=0; jindexes.entry; j++) { + AVIIentry* ie = avi_get_ientry(&avist->indexes, j); +- put_le32(pb, ie->pos + 8); +- put_le32(pb, ((uint32_t)ie->len & ~0x80000000) | ++ avio_wl32(pb, ie->pos + 8); ++ avio_wl32(pb, ((uint32_t)ie->len & ~0x80000000) | + (ie->flags & 0x10 ? 0 : 0x80000000)); + } +- put_flush_packet(pb); +- pos = url_ftell(pb); ++ avio_flush(pb); ++ pos = avio_tell(pb); + + /* Updating one entry in the AVI OpenDML master index */ +- url_fseek(pb, avist->indexes.indx_start - 8, SEEK_SET); +- put_tag(pb, "indx"); /* enabling this entry */ +- url_fskip(pb, 8); +- put_le32(pb, avi->riff_id); /* nEntriesInUse */ +- url_fskip(pb, 16*avi->riff_id); +- put_le64(pb, ix); /* qwOffset */ +- put_le32(pb, pos - ix); /* dwSize */ +- put_le32(pb, avist->indexes.entry); /* dwDuration */ ++ avio_seek(pb, avist->indexes.indx_start - 8, SEEK_SET); ++ ffio_wfourcc(pb, "indx"); /* enabling this entry */ ++ avio_skip(pb, 8); ++ avio_wl32(pb, avi->riff_id); /* nEntriesInUse */ ++ avio_skip(pb, 16*avi->riff_id); ++ avio_wl64(pb, ix); /* qwOffset */ ++ avio_wl32(pb, pos - ix); /* dwSize */ ++ avio_wl32(pb, avist->indexes.entry); /* dwDuration */ + +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + } + return 0; + } + + static int avi_write_idx1(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVIContext *avi = s->priv_data; + int64_t idx_chunk; + int i; + char tag[5]; + +- if (!url_is_streamed(pb)) { ++ if (pb->seekable) { + AVIStream *avist; + AVIIentry* ie = 0, *tie; + int empty, stream_id = -1; +@@ -484,12 +493,12 @@ + } + if (!empty) { + avist= s->streams[stream_id]->priv_data; +- avi_stream2fourcc(&tag[0], stream_id, ++ avi_stream2fourcc(tag, stream_id, + s->streams[stream_id]->codec->codec_type); +- put_tag(pb, &tag[0]); +- put_le32(pb, ie->flags); +- put_le32(pb, ie->pos); +- put_le32(pb, ie->len); ++ ffio_wfourcc(pb, tag); ++ avio_wl32(pb, ie->flags); ++ avio_wl32(pb, ie->pos); ++ avio_wl32(pb, ie->len); + avist->entry++; + } + } while (!empty); +@@ -503,7 +512,7 @@ + static int avi_write_packet(AVFormatContext *s, AVPacket *pkt) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned char tag[5]; + unsigned int flags=0; + const int stream_index= pkt->stream_index; +@@ -511,22 +520,27 @@ + AVCodecContext *enc= s->streams[stream_index]->codec; + int size= pkt->size; + +-// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avi->packet_count[stream_index], stream_index); ++// av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avist->packet_count, stream_index); + while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){ + AVPacket empty_packet; + ++ if(pkt->dts - avist->packet_count > 60000){ ++ av_log(s, AV_LOG_ERROR, "Too large number of skiped frames %"PRId64"\n", pkt->dts - avist->packet_count); ++ return AVERROR(EINVAL); ++ } ++ + av_init_packet(&empty_packet); + empty_packet.size= 0; + empty_packet.data= NULL; + empty_packet.stream_index= stream_index; + avi_write_packet(s, &empty_packet); +-// av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avi->packet_count[stream_index]); ++// av_log(s, AV_LOG_DEBUG, "dup %"PRId64" %d\n", pkt->dts, avist->packet_count); + } + avist->packet_count++; + + // Make sure to put an OpenDML chunk when the file size exceeds the limits +- if (!url_is_streamed(pb) && +- (url_ftell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) { ++ if (pb->seekable && ++ (avio_tell(pb) - avi->riff_start > AVI_MAX_RIFF_SIZE)) { + + avi_write_ix(s); + ff_end_tag(pb, avi->movi_list); +@@ -538,19 +552,19 @@ + avi->movi_list = avi_start_new_riff(s, pb, "AVIX", "movi"); + } + +- avi_stream2fourcc(&tag[0], stream_index, enc->codec_type); ++ avi_stream2fourcc(tag, stream_index, enc->codec_type); + if(pkt->flags&AV_PKT_FLAG_KEY) + flags = 0x10; + if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + avist->audio_strm_length += size; + } + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + AVIIndex* idx = &avist->indexes; + int cl = idx->entry / AVI_INDEX_CLUSTER_SIZE; + int id = idx->entry % AVI_INDEX_CLUSTER_SIZE; + if (idx->ents_allocated <= idx->entry) { +- idx->cluster = av_realloc(idx->cluster, (cl+1)*sizeof(void*)); ++ idx->cluster = av_realloc_f(idx->cluster, sizeof(void*), cl+1); + if (!idx->cluster) + return -1; + idx->cluster[cl] = av_malloc(AVI_INDEX_CLUSTER_SIZE*sizeof(AVIIentry)); +@@ -560,30 +574,30 @@ + } + + idx->cluster[cl][id].flags = flags; +- idx->cluster[cl][id].pos = url_ftell(pb) - avi->movi_list; ++ idx->cluster[cl][id].pos = avio_tell(pb) - avi->movi_list; + idx->cluster[cl][id].len = size; + idx->entry++; + } + +- put_buffer(pb, tag, 4); +- put_le32(pb, size); +- put_buffer(pb, pkt->data, size); ++ avio_write(pb, tag, 4); ++ avio_wl32(pb, size); ++ avio_write(pb, pkt->data, size); + if (size & 1) +- put_byte(pb, 0); ++ avio_w8(pb, 0); + +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + + static int avi_write_trailer(AVFormatContext *s) + { + AVIContext *avi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int res = 0; + int i, j, n, nb_frames; + int64_t file_size; + +- if (!url_is_streamed(pb)){ ++ if (pb->seekable){ + if (avi->riff_id == 1) { + ff_end_tag(pb, avi->movi_list); + res = avi_write_idx1(s); +@@ -593,10 +607,10 @@ + ff_end_tag(pb, avi->movi_list); + ff_end_tag(pb, avi->riff_start); + +- file_size = url_ftell(pb); +- url_fseek(pb, avi->odml_list - 8, SEEK_SET); +- put_tag(pb, "LIST"); /* Making this AVI OpenDML one */ +- url_fskip(pb, 16); ++ file_size = avio_tell(pb); ++ avio_seek(pb, avi->odml_list - 8, SEEK_SET); ++ ffio_wfourcc(pb, "LIST"); /* Making this AVI OpenDML one */ ++ avio_skip(pb, 16); + + for (n=nb_frames=0;nnb_streams;n++) { + AVCodecContext *stream = s->streams[n]->codec; +@@ -611,13 +625,13 @@ + } + } + } +- put_le32(pb, nb_frames); +- url_fseek(pb, file_size, SEEK_SET); ++ avio_wl32(pb, nb_frames); ++ avio_seek(pb, file_size, SEEK_SET); + + avi_write_counters(s, avi->riff_id); + } + } +- put_flush_packet(pb); ++ avio_flush(pb); + + for (i=0; inb_streams; i++) { + AVIStream *avist= s->streams[i]->priv_data; +@@ -631,16 +645,20 @@ + } + + AVOutputFormat ff_avi_muxer = { +- "avi", +- NULL_IF_CONFIG_SMALL("AVI format"), +- "video/x-msvideo", +- "avi", +- sizeof(AVIContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG4, +- avi_write_header, +- avi_write_packet, +- avi_write_trailer, ++ .name = "avi", ++ .long_name = NULL_IF_CONFIG_SMALL("AVI format"), ++ .mime_type = "video/x-msvideo", ++ .extensions = "avi", ++ .priv_data_size = sizeof(AVIContext), ++#if CONFIG_LIBMP3LAME_ENCODER ++ .audio_codec = CODEC_ID_MP3, ++#else ++ .audio_codec = CODEC_ID_AC3, ++#endif ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = avi_write_header, ++ .write_packet = avi_write_packet, ++ .write_trailer = avi_write_trailer, + .codec_tag= (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, + .flags= AVFMT_VARIABLE_FPS, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avi.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avi.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avi.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avi.h 2012-05-14 14:08:54.898351333 +0200 +@@ -21,8 +21,6 @@ + #ifndef AVFORMAT_AVI_H + #define AVFORMAT_AVI_H + +-#include "metadata.h" +- + #define AVIF_HASINDEX 0x00000010 // Index at end of file? + #define AVIF_MUSTUSEINDEX 0x00000020 + #define AVIF_ISINTERLEAVED 0x00000100 +@@ -32,15 +30,9 @@ + + #define AVI_MAX_RIFF_SIZE 0x40000000LL + #define AVI_MASTER_INDEX_SIZE 256 ++#define AVI_MAX_STREAM_COUNT 100 + + /* index flags */ + #define AVIIF_INDEX 0x10 + +-extern const AVMetadataConv ff_avi_metadata_conv[]; +- +-/** +- * A list of AVI info tags. +- */ +-extern const char ff_avi_tags[][5]; +- + #endif /* AVFORMAT_AVI_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aviobuf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aviobuf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/aviobuf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/aviobuf.c 2012-05-14 14:08:54.915351675 +0200 +@@ -1,5 +1,5 @@ + /* +- * Buffered I/O for ffmpeg system ++ * buffered I/O + * Copyright (c) 2000,2001 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -20,10 +20,15 @@ + */ + + #include "libavutil/crc.h" ++#include "libavutil/dict.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + #include "avformat.h" + #include "avio.h" ++#include "avio_internal.h" + #include "internal.h" ++#include "url.h" + #include + + #define IO_BUFFER_SIZE 32768 +@@ -35,12 +40,35 @@ + */ + #define SHORT_SEEK_THRESHOLD 4096 + +-static void fill_buffer(ByteIOContext *s); +-#if !FF_API_URL_RESETBUF +-static int url_resetbuf(ByteIOContext *s, int flags); ++#if !FF_API_OLD_AVIO ++static void *ffio_url_child_next(void *obj, void *prev) ++{ ++ AVIOContext *s = obj; ++ return prev ? NULL : s->opaque; ++} ++ ++static const AVClass *ffio_url_child_class_next(const AVClass *prev) ++{ ++ return prev ? NULL : &ffurl_context_class; ++} ++ ++static const AVOption ffio_url_options[] = { ++ { NULL }, ++}; ++ ++const AVClass ffio_url_class = { ++ .class_name = "AVIOContext", ++ .item_name = av_default_item_name, ++ .version = LIBAVUTIL_VERSION_INT, ++ .option = ffio_url_options, ++ .child_next = ffio_url_child_next, ++ .child_class_next = ffio_url_child_class_next, ++}; + #endif ++static void fill_buffer(AVIOContext *s); ++static int url_resetbuf(AVIOContext *s, int flags); + +-int init_put_byte(ByteIOContext *s, ++int ffio_init_context(AVIOContext *s, + unsigned char *buffer, + int buffer_size, + int write_flag, +@@ -53,7 +81,7 @@ + s->buffer_size = buffer_size; + s->buf_ptr = buffer; + s->opaque = opaque; +- url_resetbuf(s, write_flag ? URL_WRONLY : URL_RDONLY); ++ url_resetbuf(s, write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ); + s->write_packet = write_packet; + s->read_packet = read_packet; + s->seek = seek; +@@ -61,7 +89,10 @@ + s->must_flush = 0; + s->eof_reached = 0; + s->error = 0; ++#if FF_API_OLD_AVIO + s->is_streamed = 0; ++#endif ++ s->seekable = AVIO_SEEKABLE_NORMAL; + s->max_packet_size = 0; + s->update_checksum= NULL; + if(!read_packet && !write_flag){ +@@ -73,7 +104,34 @@ + return 0; + } + +-ByteIOContext *av_alloc_put_byte( ++#if FF_API_OLD_AVIO ++int init_put_byte(AVIOContext *s, ++ unsigned char *buffer, ++ int buffer_size, ++ int write_flag, ++ void *opaque, ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int64_t (*seek)(void *opaque, int64_t offset, int whence)) ++{ ++ return ffio_init_context(s, buffer, buffer_size, write_flag, opaque, ++ read_packet, write_packet, seek); ++} ++AVIOContext *av_alloc_put_byte( ++ unsigned char *buffer, ++ int buffer_size, ++ int write_flag, ++ void *opaque, ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int64_t (*seek)(void *opaque, int64_t offset, int whence)) ++{ ++ return avio_alloc_context(buffer, buffer_size, write_flag, opaque, ++ read_packet, write_packet, seek); ++} ++#endif ++ ++AVIOContext *avio_alloc_context( + unsigned char *buffer, + int buffer_size, + int write_flag, +@@ -82,13 +140,15 @@ + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), + int64_t (*seek)(void *opaque, int64_t offset, int whence)) + { +- ByteIOContext *s = av_mallocz(sizeof(ByteIOContext)); +- init_put_byte(s, buffer, buffer_size, write_flag, opaque, ++ AVIOContext *s = av_mallocz(sizeof(AVIOContext)); ++ if (!s) ++ return NULL; ++ ffio_init_context(s, buffer, buffer_size, write_flag, opaque, + read_packet, write_packet, seek); + return s; + } + +-static void flush_buffer(ByteIOContext *s) ++static void flush_buffer(AVIOContext *s) + { + if (s->buf_ptr > s->buffer) { + if (s->write_packet && !s->error){ +@@ -106,14 +166,14 @@ + s->buf_ptr = s->buffer; + } + +-void put_byte(ByteIOContext *s, int b) ++void avio_w8(AVIOContext *s, int b) + { +- *(s->buf_ptr)++ = b; ++ *s->buf_ptr++ = b; + if (s->buf_ptr >= s->buf_end) + flush_buffer(s); + } + +-void put_nbyte(ByteIOContext *s, int b, int count) ++void ffio_fill(AVIOContext *s, int b, int count) + { + while (count > 0) { + int len = FFMIN(s->buf_end - s->buf_ptr, count); +@@ -127,7 +187,7 @@ + } + } + +-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size) ++void avio_write(AVIOContext *s, const unsigned char *buf, int size) + { + while (size > 0) { + int len = FFMIN(s->buf_end - s->buf_ptr, size); +@@ -142,13 +202,13 @@ + } + } + +-void put_flush_packet(ByteIOContext *s) ++void avio_flush(AVIOContext *s) + { + flush_buffer(s); + s->must_flush = 0; + } + +-int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence) ++int64_t avio_seek(AVIOContext *s, int64_t offset, int whence) + { + int64_t offset1; + int64_t pos; +@@ -174,7 +234,7 @@ + offset1 >= 0 && offset1 <= (s->buf_end - s->buffer)) { + /* can do the seek inside the buffer */ + s->buf_ptr = s->buffer + offset1; +- } else if ((s->is_streamed || ++ } else if ((!s->seekable || + offset1 <= s->buf_end + SHORT_SEEK_THRESHOLD - s->buffer) && + !s->write_flag && offset1 >= 0 && + (whence != SEEK_END || force)) { +@@ -205,18 +265,25 @@ + return offset; + } + +-int url_fskip(ByteIOContext *s, int64_t offset) ++int64_t avio_skip(AVIOContext *s, int64_t offset) ++{ ++ return avio_seek(s, offset, SEEK_CUR); ++} ++ ++#if FF_API_OLD_AVIO ++int url_fskip(AVIOContext *s, int64_t offset) + { +- int64_t ret = url_fseek(s, offset, SEEK_CUR); ++ int64_t ret = avio_seek(s, offset, SEEK_CUR); + return ret < 0 ? ret : 0; + } + +-int64_t url_ftell(ByteIOContext *s) ++int64_t url_ftell(AVIOContext *s) + { +- return url_fseek(s, 0, SEEK_CUR); ++ return avio_seek(s, 0, SEEK_CUR); + } ++#endif + +-int64_t url_fsize(ByteIOContext *s) ++int64_t avio_size(AVIOContext *s) + { + int64_t size; + +@@ -235,55 +302,191 @@ + return size; + } + +-int url_feof(ByteIOContext *s) ++int url_feof(AVIOContext *s) + { + if(!s) + return 0; ++ if(s->eof_reached){ ++ s->eof_reached=0; ++ fill_buffer(s); ++ } + return s->eof_reached; + } + +-int url_ferror(ByteIOContext *s) ++#if FF_API_OLD_AVIO ++int url_ferror(AVIOContext *s) + { + if(!s) + return 0; + return s->error; + } ++#endif + +-void put_le32(ByteIOContext *s, unsigned int val) ++void avio_wl32(AVIOContext *s, unsigned int val) + { +- put_byte(s, val); +- put_byte(s, val >> 8); +- put_byte(s, val >> 16); +- put_byte(s, val >> 24); ++ avio_w8(s, val); ++ avio_w8(s, val >> 8); ++ avio_w8(s, val >> 16); ++ avio_w8(s, val >> 24); + } + +-void put_be32(ByteIOContext *s, unsigned int val) ++void avio_wb32(AVIOContext *s, unsigned int val) + { +- put_byte(s, val >> 24); +- put_byte(s, val >> 16); +- put_byte(s, val >> 8); +- put_byte(s, val); ++ avio_w8(s, val >> 24); ++ avio_w8(s, val >> 16); ++ avio_w8(s, val >> 8); ++ avio_w8(s, val); + } + + #if FF_API_OLD_AVIO +-void put_strz(ByteIOContext *s, const char *str) ++void put_strz(AVIOContext *s, const char *str) + { + avio_put_str(s, str); + } ++ ++#define GET(name, type) \ ++ type get_be ##name(AVIOContext *s) \ ++{\ ++ return avio_rb ##name(s);\ ++}\ ++ type get_le ##name(AVIOContext *s) \ ++{\ ++ return avio_rl ##name(s);\ ++} ++ ++GET(16, unsigned int) ++GET(24, unsigned int) ++GET(32, unsigned int) ++GET(64, uint64_t) ++ ++#undef GET ++ ++#define PUT(name, type ) \ ++ void put_le ##name(AVIOContext *s, type val)\ ++{\ ++ avio_wl ##name(s, val);\ ++}\ ++ void put_be ##name(AVIOContext *s, type val)\ ++{\ ++ avio_wb ##name(s, val);\ ++} ++ ++PUT(16, unsigned int) ++PUT(24, unsigned int) ++PUT(32, unsigned int) ++PUT(64, uint64_t) ++#undef PUT ++ ++int get_byte(AVIOContext *s) ++{ ++ return avio_r8(s); ++} ++int get_buffer(AVIOContext *s, unsigned char *buf, int size) ++{ ++ return avio_read(s, buf, size); ++} ++int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size) ++{ ++ return ffio_read_partial(s, buf, size); ++} ++void put_byte(AVIOContext *s, int val) ++{ ++ avio_w8(s, val); ++} ++void put_buffer(AVIOContext *s, const unsigned char *buf, int size) ++{ ++ avio_write(s, buf, size); ++} ++void put_nbyte(AVIOContext *s, int b, int count) ++{ ++ ffio_fill(s, b, count); ++} ++ ++int url_fopen(AVIOContext **s, const char *filename, int flags) ++{ ++ return avio_open(s, filename, flags); ++} ++int url_fclose(AVIOContext *s) ++{ ++ return avio_close(s); ++} ++int64_t url_fseek(AVIOContext *s, int64_t offset, int whence) ++{ ++ return avio_seek(s, offset, whence); ++} ++int64_t url_fsize(AVIOContext *s) ++{ ++ return avio_size(s); ++} ++int url_setbufsize(AVIOContext *s, int buf_size) ++{ ++ return ffio_set_buf_size(s, buf_size); ++} ++int url_fprintf(AVIOContext *s, const char *fmt, ...) ++{ ++ va_list ap; ++ char buf[4096]; ++ int ret; ++ ++ va_start(ap, fmt); ++ ret = vsnprintf(buf, sizeof(buf), fmt, ap); ++ va_end(ap); ++ avio_write(s, buf, strlen(buf)); ++ return ret; ++} ++void put_flush_packet(AVIOContext *s) ++{ ++ avio_flush(s); ++} ++int av_url_read_fpause(AVIOContext *s, int pause) ++{ ++ return avio_pause(s, pause); ++} ++int64_t av_url_read_fseek(AVIOContext *s, int stream_index, ++ int64_t timestamp, int flags) ++{ ++ return avio_seek_time(s, stream_index, timestamp, flags); ++} ++void init_checksum(AVIOContext *s, ++ unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), ++ unsigned long checksum) ++{ ++ ffio_init_checksum(s, update_checksum, checksum); ++} ++unsigned long get_checksum(AVIOContext *s) ++{ ++ return ffio_get_checksum(s); ++} ++int url_open_dyn_buf(AVIOContext **s) ++{ ++ return avio_open_dyn_buf(s); ++} ++int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) ++{ ++ return ffio_open_dyn_packet_buf(s, max_packet_size); ++} ++int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) ++{ ++ return avio_close_dyn_buf(s, pbuffer); ++} ++int url_fdopen(AVIOContext **s, URLContext *h) ++{ ++ return ffio_fdopen(s, h); ++} + #endif + +-int avio_put_str(ByteIOContext *s, const char *str) ++int avio_put_str(AVIOContext *s, const char *str) + { + int len = 1; + if (str) { + len += strlen(str); +- put_buffer(s, (const unsigned char *) str, len); ++ avio_write(s, (const unsigned char *) str, len); + } else +- put_byte(s, 0); ++ avio_w8(s, 0); + return len; + } + +-int avio_put_str16le(ByteIOContext *s, const char *str) ++int avio_put_str16le(AVIOContext *s, const char *str) + { + const uint8_t *q = str; + int ret = 0; +@@ -293,9 +496,9 @@ + uint16_t tmp; + + GET_UTF8(ch, *q++, break;) +- PUT_UTF16(ch, tmp, put_le16(s, tmp);ret += 2;) ++ PUT_UTF16(ch, tmp, avio_wl16(s, tmp);ret += 2;) + } +- put_le16(s, 0); ++ avio_wl16(s, 0); + ret += 2; + return ret; + } +@@ -309,66 +512,72 @@ + return i; + } + +-void ff_put_v(ByteIOContext *bc, uint64_t val){ ++void ff_put_v(AVIOContext *bc, uint64_t val){ + int i= ff_get_v_length(val); + + while(--i>0) +- put_byte(bc, 128 | (val>>(7*i))); ++ avio_w8(bc, 128 | (val>>(7*i))); + +- put_byte(bc, val&127); ++ avio_w8(bc, val&127); + } + +-void put_le64(ByteIOContext *s, uint64_t val) ++void avio_wl64(AVIOContext *s, uint64_t val) + { +- put_le32(s, (uint32_t)(val & 0xffffffff)); +- put_le32(s, (uint32_t)(val >> 32)); ++ avio_wl32(s, (uint32_t)(val & 0xffffffff)); ++ avio_wl32(s, (uint32_t)(val >> 32)); + } + +-void put_be64(ByteIOContext *s, uint64_t val) ++void avio_wb64(AVIOContext *s, uint64_t val) + { +- put_be32(s, (uint32_t)(val >> 32)); +- put_be32(s, (uint32_t)(val & 0xffffffff)); ++ avio_wb32(s, (uint32_t)(val >> 32)); ++ avio_wb32(s, (uint32_t)(val & 0xffffffff)); + } + +-void put_le16(ByteIOContext *s, unsigned int val) ++void avio_wl16(AVIOContext *s, unsigned int val) + { +- put_byte(s, val); +- put_byte(s, val >> 8); ++ avio_w8(s, val); ++ avio_w8(s, val >> 8); + } + +-void put_be16(ByteIOContext *s, unsigned int val) ++void avio_wb16(AVIOContext *s, unsigned int val) + { +- put_byte(s, val >> 8); +- put_byte(s, val); ++ avio_w8(s, val >> 8); ++ avio_w8(s, val); + } + +-void put_le24(ByteIOContext *s, unsigned int val) ++void avio_wl24(AVIOContext *s, unsigned int val) + { +- put_le16(s, val & 0xffff); +- put_byte(s, val >> 16); ++ avio_wl16(s, val & 0xffff); ++ avio_w8(s, val >> 16); + } + +-void put_be24(ByteIOContext *s, unsigned int val) ++void avio_wb24(AVIOContext *s, unsigned int val) + { +- put_be16(s, val >> 8); +- put_byte(s, val); ++ avio_wb16(s, val >> 8); ++ avio_w8(s, val); + } + +-void put_tag(ByteIOContext *s, const char *tag) ++#if FF_API_OLD_AVIO ++void put_tag(AVIOContext *s, const char *tag) + { + while (*tag) { +- put_byte(s, *tag++); ++ avio_w8(s, *tag++); + } + } ++#endif + + /* Input stream */ + +-static void fill_buffer(ByteIOContext *s) ++static void fill_buffer(AVIOContext *s) + { +- uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_ptr : s->buffer; ++ uint8_t *dst= !s->max_packet_size && s->buf_end - s->buffer < s->buffer_size ? s->buf_end : s->buffer; + int len= s->buffer_size - (dst - s->buffer); + int max_buffer_size = s->max_packet_size ? s->max_packet_size : IO_BUFFER_SIZE; + ++ /* can't fill the buffer without read_packet, just set EOF if appropiate */ ++ if (!s->read_packet && s->buf_ptr >= s->buf_end) ++ s->eof_reached = 1; ++ + /* no need to do anything if EOF already reached */ + if (s->eof_reached) + return; +@@ -380,8 +589,8 @@ + } + + /* make buffer smaller in case it ended up large after probing */ +- if (s->buffer_size > max_buffer_size) { +- url_setbufsize(s, max_buffer_size); ++ if (s->read_packet && s->buffer_size > max_buffer_size) { ++ ffio_set_buf_size(s, max_buffer_size); + + s->checksum_ptr = dst = s->buffer; + len = s->buffer_size; +@@ -410,14 +619,14 @@ + return av_crc(av_crc_get_table(AV_CRC_32_IEEE), checksum, buf, len); + } + +-unsigned long get_checksum(ByteIOContext *s) ++unsigned long ffio_get_checksum(AVIOContext *s) + { + s->checksum= s->update_checksum(s->checksum, s->checksum_ptr, s->buf_ptr - s->checksum_ptr); + s->update_checksum= NULL; + return s->checksum; + } + +-void init_checksum(ByteIOContext *s, ++void ffio_init_checksum(AVIOContext *s, + unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), + unsigned long checksum) + { +@@ -429,7 +638,7 @@ + } + + /* XXX: put an inline version */ +-int get_byte(ByteIOContext *s) ++int avio_r8(AVIOContext *s) + { + if (s->buf_ptr >= s->buf_end) + fill_buffer(s); +@@ -438,7 +647,8 @@ + return 0; + } + +-int url_fgetc(ByteIOContext *s) ++#if FF_API_OLD_AVIO ++int url_fgetc(AVIOContext *s) + { + if (s->buf_ptr >= s->buf_end) + fill_buffer(s); +@@ -446,8 +656,9 @@ + return *s->buf_ptr++; + return URL_EOF; + } ++#endif + +-int get_buffer(ByteIOContext *s, unsigned char *buf, int size) ++int avio_read(AVIOContext *s, unsigned char *buf, int size) + { + int len, size1; + +@@ -488,13 +699,13 @@ + } + } + if (size1 == size) { +- if (url_ferror(s)) return url_ferror(s); ++ if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; + } + return size1 - size; + } + +-int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size) ++int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size) + { + int len; + +@@ -511,89 +722,82 @@ + memcpy(buf, s->buf_ptr, len); + s->buf_ptr += len; + if (!len) { +- if (url_ferror(s)) return url_ferror(s); ++ if (s->error) return s->error; + if (url_feof(s)) return AVERROR_EOF; + } + return len; + } + +-unsigned int get_le16(ByteIOContext *s) ++unsigned int avio_rl16(AVIOContext *s) + { + unsigned int val; +- val = get_byte(s); +- val |= get_byte(s) << 8; ++ val = avio_r8(s); ++ val |= avio_r8(s) << 8; + return val; + } + +-unsigned int get_le24(ByteIOContext *s) ++unsigned int avio_rl24(AVIOContext *s) + { + unsigned int val; +- val = get_le16(s); +- val |= get_byte(s) << 16; ++ val = avio_rl16(s); ++ val |= avio_r8(s) << 16; + return val; + } + +-unsigned int get_le32(ByteIOContext *s) ++unsigned int avio_rl32(AVIOContext *s) + { + unsigned int val; +- val = get_le16(s); +- val |= get_le16(s) << 16; ++ val = avio_rl16(s); ++ val |= avio_rl16(s) << 16; + return val; + } + +-uint64_t get_le64(ByteIOContext *s) ++uint64_t avio_rl64(AVIOContext *s) + { + uint64_t val; +- val = (uint64_t)get_le32(s); +- val |= (uint64_t)get_le32(s) << 32; ++ val = (uint64_t)avio_rl32(s); ++ val |= (uint64_t)avio_rl32(s) << 32; + return val; + } + +-unsigned int get_be16(ByteIOContext *s) ++unsigned int avio_rb16(AVIOContext *s) + { + unsigned int val; +- val = get_byte(s) << 8; +- val |= get_byte(s); ++ val = avio_r8(s) << 8; ++ val |= avio_r8(s); + return val; + } + +-unsigned int get_be24(ByteIOContext *s) ++unsigned int avio_rb24(AVIOContext *s) + { + unsigned int val; +- val = get_be16(s) << 8; +- val |= get_byte(s); ++ val = avio_rb16(s) << 8; ++ val |= avio_r8(s); + return val; + } +-unsigned int get_be32(ByteIOContext *s) ++unsigned int avio_rb32(AVIOContext *s) + { + unsigned int val; +- val = get_be16(s) << 16; +- val |= get_be16(s); ++ val = avio_rb16(s) << 16; ++ val |= avio_rb16(s); + return val; + } + +-char *get_strz(ByteIOContext *s, char *buf, int maxlen) ++#if FF_API_OLD_AVIO ++char *get_strz(AVIOContext *s, char *buf, int maxlen) + { +- int i = 0; +- char c; +- +- while ((c = get_byte(s))) { +- if (i < maxlen-1) +- buf[i++] = c; +- } +- +- buf[i] = 0; /* Ensure null terminated, but may be truncated */ +- ++ avio_get_str(s, INT_MAX, buf, maxlen); + return buf; + } ++#endif + +-int ff_get_line(ByteIOContext *s, char *buf, int maxlen) ++int ff_get_line(AVIOContext *s, char *buf, int maxlen) + { + int i = 0; + char c; + + do { +- c = get_byte(s); ++ c = avio_r8(s); + if (c && i < maxlen-1) + buf[i++] = c; + } while (c != '\n' && c); +@@ -602,11 +806,31 @@ + return i; + } + ++int avio_get_str(AVIOContext *s, int maxlen, char *buf, int buflen) ++{ ++ int i; ++ ++ if (buflen <= 0) ++ return AVERROR(EINVAL); ++ // reserve 1 byte for terminating 0 ++ buflen = FFMIN(buflen - 1, maxlen); ++ for (i = 0; i < buflen; i++) ++ if (!(buf[i] = avio_r8(s))) ++ return i + 1; ++ buf[i] = 0; ++ for (; i < maxlen; i++) ++ if (!avio_r8(s)) ++ return i + 1; ++ return maxlen; ++} ++ + #define GET_STR16(type, read) \ +- int avio_get_str16 ##type(ByteIOContext *pb, int maxlen, char *buf, int buflen)\ ++ int avio_get_str16 ##type(AVIOContext *pb, int maxlen, char *buf, int buflen)\ + {\ + char* q = buf;\ + int ret = 0;\ ++ if (buflen <= 0) \ ++ return AVERROR(EINVAL); \ + while (ret + 1 < maxlen) {\ + uint8_t tmp;\ + uint32_t ch;\ +@@ -619,36 +843,36 @@ + return ret;\ + }\ + +-GET_STR16(le, get_le16) +-GET_STR16(be, get_be16) ++GET_STR16(le, avio_rl16) ++GET_STR16(be, avio_rb16) + + #undef GET_STR16 + +-uint64_t get_be64(ByteIOContext *s) ++uint64_t avio_rb64(AVIOContext *s) + { + uint64_t val; +- val = (uint64_t)get_be32(s) << 32; +- val |= (uint64_t)get_be32(s); ++ val = (uint64_t)avio_rb32(s) << 32; ++ val |= (uint64_t)avio_rb32(s); + return val; + } + +-uint64_t ff_get_v(ByteIOContext *bc){ ++uint64_t ffio_read_varlen(AVIOContext *bc){ + uint64_t val = 0; + int tmp; + + do{ +- tmp = get_byte(bc); ++ tmp = avio_r8(bc); + val= (val<<7) + (tmp&127); + }while(tmp&128); + return val; + } + +-int url_fdopen(ByteIOContext **s, URLContext *h) ++int ffio_fdopen(AVIOContext **s, URLContext *h) + { + uint8_t *buffer; + int buffer_size, max_packet_size; + +- max_packet_size = url_get_max_packet_size(h); ++ max_packet_size = h->max_packet_size; + if (max_packet_size) { + buffer_size = max_packet_size; /* no need to bufferize more than one packet */ + } else { +@@ -658,29 +882,29 @@ + if (!buffer) + return AVERROR(ENOMEM); + +- *s = av_mallocz(sizeof(ByteIOContext)); +- if(!*s) { ++ *s = avio_alloc_context(buffer, buffer_size, h->flags & AVIO_FLAG_WRITE, h, ++ ffurl_read, ffurl_write, ffurl_seek); ++ if (!*s) { + av_free(buffer); + return AVERROR(ENOMEM); + } + +- if (init_put_byte(*s, buffer, buffer_size, +- (h->flags & URL_WRONLY || h->flags & URL_RDWR), h, +- url_read, url_write, url_seek) < 0) { +- av_free(buffer); +- av_freep(s); +- return AVERROR(EIO); +- } ++#if FF_API_OLD_AVIO + (*s)->is_streamed = h->is_streamed; ++#endif ++ (*s)->seekable = h->is_streamed ? 0 : AVIO_SEEKABLE_NORMAL; + (*s)->max_packet_size = max_packet_size; + if(h->prot) { + (*s)->read_pause = (int (*)(void *, int))h->prot->url_read_pause; + (*s)->read_seek = (int64_t (*)(void *, int, int64_t, int))h->prot->url_read_seek; + } ++#if !FF_API_OLD_AVIO ++ (*s)->av_class = &ffio_url_class; ++#endif + return 0; + } + +-int url_setbufsize(ByteIOContext *s, int buf_size) ++int ffio_set_buf_size(AVIOContext *s, int buf_size) + { + uint8_t *buffer; + buffer = av_malloc(buf_size); +@@ -691,24 +915,15 @@ + s->buffer = buffer; + s->buffer_size = buf_size; + s->buf_ptr = buffer; +- url_resetbuf(s, s->write_flag ? URL_WRONLY : URL_RDONLY); ++ url_resetbuf(s, s->write_flag ? AVIO_FLAG_WRITE : AVIO_FLAG_READ); + return 0; + } + +-#if FF_API_URL_RESETBUF +-int url_resetbuf(ByteIOContext *s, int flags) +-#else +-static int url_resetbuf(ByteIOContext *s, int flags) +-#endif ++static int url_resetbuf(AVIOContext *s, int flags) + { +-#if FF_API_URL_RESETBUF +- if (flags & URL_RDWR) +- return AVERROR(EINVAL); +-#else +- assert(flags == URL_WRONLY || flags == URL_RDONLY); +-#endif ++ assert(flags == AVIO_FLAG_WRITE || flags == AVIO_FLAG_READ); + +- if (flags & URL_WRONLY) { ++ if (flags & AVIO_FLAG_WRITE) { + s->buf_end = s->buffer + s->buffer_size; + s->write_flag = 1; + } else { +@@ -718,7 +933,7 @@ + return 0; + } + +-int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size) ++int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size) + { + int64_t buffer_start; + int buffer_size; +@@ -738,7 +953,7 @@ + + alloc_size = FFMAX(s->buffer_size, new_size); + if (alloc_size > buf_size) +- if (!(buf = av_realloc(buf, alloc_size))) ++ if (!(buf = av_realloc_f(buf, 1, alloc_size))) + return AVERROR(ENOMEM); + + if (new_size > buf_size) { +@@ -757,38 +972,45 @@ + return 0; + } + +-int url_fopen(ByteIOContext **s, const char *filename, int flags) ++int avio_open(AVIOContext **s, const char *filename, int flags) ++{ ++ return avio_open2(s, filename, flags, NULL, NULL); ++} ++ ++int avio_open2(AVIOContext **s, const char *filename, int flags, ++ const AVIOInterruptCB *int_cb, AVDictionary **options) + { + URLContext *h; + int err; + +- err = url_open(&h, filename, flags); ++ err = ffurl_open(&h, filename, flags, int_cb, options); + if (err < 0) + return err; +- err = url_fdopen(s, h); ++ err = ffio_fdopen(s, h); + if (err < 0) { +- url_close(h); ++ ffurl_close(h); + return err; + } + return 0; + } + +-int url_fclose(ByteIOContext *s) ++int avio_close(AVIOContext *s) + { + URLContext *h = s->opaque; + + av_free(s->buffer); + av_free(s); +- return url_close(h); ++ return ffurl_close(h); + } + +-URLContext *url_fileno(ByteIOContext *s) ++#if FF_API_OLD_AVIO ++URLContext *url_fileno(AVIOContext *s) + { + return s->opaque; + } ++#endif + +-#if CONFIG_MUXERS +-int url_fprintf(ByteIOContext *s, const char *fmt, ...) ++int avio_printf(AVIOContext *s, const char *fmt, ...) + { + va_list ap; + char buf[4096]; +@@ -797,46 +1019,47 @@ + va_start(ap, fmt); + ret = vsnprintf(buf, sizeof(buf), fmt, ap); + va_end(ap); +- put_buffer(s, buf, strlen(buf)); ++ avio_write(s, buf, strlen(buf)); + return ret; + } +-#endif //CONFIG_MUXERS + +-char *url_fgets(ByteIOContext *s, char *buf, int buf_size) ++#if FF_API_OLD_AVIO ++char *url_fgets(AVIOContext *s, char *buf, int buf_size) + { + int c; + char *q; + +- c = url_fgetc(s); +- if (c == EOF) ++ c = avio_r8(s); ++ if (url_feof(s)) + return NULL; + q = buf; + for(;;) { +- if (c == EOF || c == '\n') ++ if (url_feof(s) || c == '\n') + break; + if ((q - buf) < buf_size - 1) + *q++ = c; +- c = url_fgetc(s); ++ c = avio_r8(s); + } + if (buf_size > 0) + *q = '\0'; + return buf; + } + +-int url_fget_max_packet_size(ByteIOContext *s) ++int url_fget_max_packet_size(AVIOContext *s) + { + return s->max_packet_size; + } ++#endif + +-int av_url_read_fpause(ByteIOContext *s, int pause) ++int avio_pause(AVIOContext *s, int pause) + { + if (!s->read_pause) + return AVERROR(ENOSYS); + return s->read_pause(s->opaque, pause); + } + +-int64_t av_url_read_fseek(ByteIOContext *s, int stream_index, +- int64_t timestamp, int flags) ++int64_t avio_seek_time(AVIOContext *s, int stream_index, ++ int64_t timestamp, int flags) + { + URLContext *h = s->opaque; + int64_t ret; +@@ -855,29 +1078,28 @@ + return ret; + } + +-/* url_open_dyn_buf and url_close_dyn_buf are used in rtp.c to send a response +- * back to the server even if CONFIG_MUXERS is false. */ +-#if CONFIG_MUXERS || CONFIG_NETWORK + /* buffer handling */ +-int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags) ++#if FF_API_OLD_AVIO ++int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags) + { + int ret; +- *s = av_mallocz(sizeof(ByteIOContext)); ++ *s = av_mallocz(sizeof(AVIOContext)); + if(!*s) + return AVERROR(ENOMEM); +- ret = init_put_byte(*s, buf, buf_size, +- (flags & URL_WRONLY || flags & URL_RDWR), ++ ret = ffio_init_context(*s, buf, buf_size, ++ flags & AVIO_FLAG_WRITE, + NULL, NULL, NULL, NULL); + if(ret != 0) + av_freep(s); + return ret; + } + +-int url_close_buf(ByteIOContext *s) ++int url_close_buf(AVIOContext *s) + { +- put_flush_packet(s); ++ avio_flush(s); + return s->buf_ptr - s->buffer; + } ++#endif + + /* output in a dynamic buffer */ + +@@ -906,7 +1128,7 @@ + } + + if (new_allocated_size > d->allocated_size) { +- d->buffer = av_realloc(d->buffer, new_allocated_size); ++ d->buffer = av_realloc_f(d->buffer, 1, new_allocated_size); + if(d->buffer == NULL) + return AVERROR(ENOMEM); + d->allocated_size = new_allocated_size; +@@ -947,10 +1169,9 @@ + return 0; + } + +-static int url_open_dyn_buf_internal(ByteIOContext **s, int max_packet_size) ++static int url_open_dyn_buf_internal(AVIOContext **s, int max_packet_size) + { + DynBuffer *d; +- int ret; + unsigned io_buffer_size = max_packet_size ? max_packet_size : 1024; + + if(sizeof(DynBuffer) + io_buffer_size < io_buffer_size) +@@ -958,38 +1179,31 @@ + d = av_mallocz(sizeof(DynBuffer) + io_buffer_size); + if (!d) + return AVERROR(ENOMEM); +- *s = av_mallocz(sizeof(ByteIOContext)); ++ d->io_buffer_size = io_buffer_size; ++ *s = avio_alloc_context(d->io_buffer, d->io_buffer_size, 1, d, NULL, ++ max_packet_size ? dyn_packet_buf_write : dyn_buf_write, ++ max_packet_size ? NULL : dyn_buf_seek); + if(!*s) { + av_free(d); + return AVERROR(ENOMEM); + } +- d->io_buffer_size = io_buffer_size; +- ret = init_put_byte(*s, d->io_buffer, io_buffer_size, +- 1, d, NULL, +- max_packet_size ? dyn_packet_buf_write : dyn_buf_write, +- max_packet_size ? NULL : dyn_buf_seek); +- if (ret == 0) { +- (*s)->max_packet_size = max_packet_size; +- } else { +- av_free(d); +- av_freep(s); +- } +- return ret; ++ (*s)->max_packet_size = max_packet_size; ++ return 0; + } + +-int url_open_dyn_buf(ByteIOContext **s) ++int avio_open_dyn_buf(AVIOContext **s) + { + return url_open_dyn_buf_internal(s, 0); + } + +-int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size) ++int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size) + { + if (max_packet_size <= 0) + return -1; + return url_open_dyn_buf_internal(s, max_packet_size); + } + +-int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer) ++int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer) + { + DynBuffer *d = s->opaque; + int size; +@@ -998,11 +1212,11 @@ + + /* don't attempt to pad fixed-size packet buffers */ + if (!s->max_packet_size) { +- put_buffer(s, padbuf, sizeof(padbuf)); ++ avio_write(s, padbuf, sizeof(padbuf)); + padding = FF_INPUT_BUFFER_PADDING_SIZE; + } + +- put_flush_packet(s); ++ avio_flush(s); + + *pbuffer = d->buffer; + size = d->size; +@@ -1010,4 +1224,3 @@ + av_free(s); + return size - padding; + } +-#endif /* CONFIG_MUXERS || CONFIG_NETWORK */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio.c 2012-05-14 14:08:54.908351535 +0200 +@@ -1,5 +1,5 @@ + /* +- * Unbuffered io for ffmpeg system ++ * unbuffered I/O + * Copyright (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -19,18 +19,25 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/* needed for usleep() */ +-#define _XOPEN_SOURCE 600 + #include ++ + #include "libavutil/avstring.h" ++#include "libavutil/dict.h" + #include "libavutil/opt.h" + #include "os_support.h" + #include "avformat.h" + #if CONFIG_NETWORK + #include "network.h" + #endif ++#include "url.h" ++ ++static URLProtocol *first_protocol = NULL; ++ ++URLProtocol *ffurl_protocol_next(URLProtocol *prev) ++{ ++ return prev ? prev->next : first_protocol; ++} + +-#if FF_API_URL_CLASS + /** @name Logging context. */ + /*@{*/ + static const char *urlcontext_to_name(void *ptr) +@@ -39,24 +46,65 @@ + if(h->prot) return h->prot->name; + else return "NULL"; + } ++ ++static void *urlcontext_child_next(void *obj, void *prev) ++{ ++ URLContext *h = obj; ++ if (!prev && h->priv_data && h->prot->priv_data_class) ++ return h->priv_data; ++ return NULL; ++} ++ ++static const AVClass *urlcontext_child_class_next(const AVClass *prev) ++{ ++ URLProtocol *p = NULL; ++ ++ /* find the protocol that corresponds to prev */ ++ while (prev && (p = ffurl_protocol_next(p))) ++ if (p->priv_data_class == prev) ++ break; ++ ++ /* find next protocol with priv options */ ++ while (p = ffurl_protocol_next(p)) ++ if (p->priv_data_class) ++ return p->priv_data_class; ++ return NULL; ++ ++} ++ + static const AVOption options[] = {{NULL}}; +-static const AVClass urlcontext_class = +- { "URLContext", urlcontext_to_name, options, LIBAVUTIL_VERSION_INT }; ++const AVClass ffurl_context_class = { ++ .class_name = "URLContext", ++ .item_name = urlcontext_to_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++ .child_next = urlcontext_child_next, ++ .child_class_next = urlcontext_child_class_next, ++}; + /*@}*/ +-#endif + +-static int default_interrupt_cb(void); + +-URLProtocol *first_protocol = NULL; +-URLInterruptCB *url_interrupt_cb = default_interrupt_cb; ++#if FF_API_OLD_INTERRUPT_CB ++static int default_interrupt_cb(void); ++int (*url_interrupt_cb)(void) = default_interrupt_cb; ++#endif + + URLProtocol *av_protocol_next(URLProtocol *p) + { +- if(p) return p->next; +- else return first_protocol; ++ return ffurl_protocol_next(p); + } + +-int av_register_protocol2(URLProtocol *protocol, int size) ++const char *avio_enum_protocols(void **opaque, int output) ++{ ++ URLProtocol **p = opaque; ++ *p = ffurl_protocol_next(*p); ++ if (!*p) return NULL; ++ if ((output && (*p)->url_write) || (!output && (*p)->url_read)) ++ return (*p)->name; ++ return avio_enum_protocols(opaque, output); ++} ++ ++int ffurl_register_protocol(URLProtocol *protocol, int size) + { + URLProtocol **p; + if (size < sizeof(URLProtocol)) { +@@ -71,37 +119,15 @@ + return 0; + } + +-#if FF_API_REGISTER_PROTOCOL +-/* The layout of URLProtocol as of when major was bumped to 52 */ +-struct URLProtocol_compat { +- const char *name; +- int (*url_open)(URLContext *h, const char *filename, int flags); +- int (*url_read)(URLContext *h, unsigned char *buf, int size); +- int (*url_write)(URLContext *h, unsigned char *buf, int size); +- int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); +- int (*url_close)(URLContext *h); +- struct URLProtocol *next; +-}; +- +-int av_register_protocol(URLProtocol *protocol) +-{ +- return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat)); +-} +- +-int register_protocol(URLProtocol *protocol) +-{ +- return av_register_protocol2(protocol, sizeof(struct URLProtocol_compat)); +-} +-#endif +- + static int url_alloc_for_protocol (URLContext **puc, struct URLProtocol *up, +- const char *filename, int flags) ++ const char *filename, int flags, ++ const AVIOInterruptCB *int_cb) + { + URLContext *uc; + int err; + + #if CONFIG_NETWORK +- if (!ff_network_init()) ++ if (up->flags & URL_PROTOCOL_FLAG_NETWORK && !ff_network_init()) + return AVERROR(EIO); + #endif + uc = av_mallocz(sizeof(URLContext) + strlen(filename) + 1); +@@ -109,9 +135,7 @@ + err = AVERROR(ENOMEM); + goto fail; + } +-#if FF_API_URL_CLASS +- uc->av_class = &urlcontext_class; +-#endif ++ uc->av_class = &ffurl_context_class; + uc->filename = (char *) &uc[1]; + strcpy(uc->filename, filename); + uc->prot = up; +@@ -121,109 +145,211 @@ + if (up->priv_data_size) { + uc->priv_data = av_mallocz(up->priv_data_size); + if (up->priv_data_class) { ++ int proto_len= strlen(up->name); ++ char *start = strchr(uc->filename, ','); + *(const AVClass**)uc->priv_data = up->priv_data_class; + av_opt_set_defaults(uc->priv_data); ++ if(!strncmp(up->name, uc->filename, proto_len) && uc->filename + proto_len == start){ ++ int ret= 0; ++ char *p= start; ++ char sep= *++p; ++ char *key, *val; ++ p++; ++ while(ret >= 0 && (key= strchr(p, sep)) && ppriv_data, p, key+1, 0); ++ if (ret == AVERROR_OPTION_NOT_FOUND) ++ av_log(uc, AV_LOG_ERROR, "Key '%s' not found.\n", p); ++ *val= *key= sep; ++ p= val+1; ++ } ++ if(ret<0 || p!=key){ ++ av_log(uc, AV_LOG_ERROR, "Error parsing options string %s\n", start); ++ av_freep(&uc->priv_data); ++ av_freep(&uc); ++ goto fail; ++ } ++ memmove(start, key+1, strlen(key)); ++ } + } + } ++ if (int_cb) ++ uc->interrupt_callback = *int_cb; + + *puc = uc; + return 0; + fail: + *puc = NULL; + #if CONFIG_NETWORK +- ff_network_close(); ++ if (up->flags & URL_PROTOCOL_FLAG_NETWORK) ++ ff_network_close(); + #endif + return err; + } + +-int url_connect(URLContext* uc) ++int ffurl_connect(URLContext* uc, AVDictionary **options) + { +- int err = uc->prot->url_open(uc, uc->filename, uc->flags); ++ int err = ++#if !FF_API_OLD_AVIO ++ uc->prot->url_open2 ? uc->prot->url_open2(uc, uc->filename, uc->flags, options) : ++#endif ++ uc->prot->url_open(uc, uc->filename, uc->flags); + if (err) + return err; + uc->is_connected = 1; +- //We must be careful here as url_seek() could be slow, for example for http +- if( (uc->flags & (URL_WRONLY | URL_RDWR)) ++ //We must be careful here as ffurl_seek() could be slow, for example for http ++ if( (uc->flags & AVIO_FLAG_WRITE) + || !strcmp(uc->prot->name, "file")) +- if(!uc->is_streamed && url_seek(uc, 0, SEEK_SET) < 0) ++ if(!uc->is_streamed && ffurl_seek(uc, 0, SEEK_SET) < 0) + uc->is_streamed= 1; + return 0; + } + ++#if FF_API_OLD_AVIO + int url_open_protocol (URLContext **puc, struct URLProtocol *up, + const char *filename, int flags) + { + int ret; + +- ret = url_alloc_for_protocol(puc, up, filename, flags); ++ ret = url_alloc_for_protocol(puc, up, filename, flags, NULL); + if (ret) + goto fail; +- ret = url_connect(*puc); ++ ret = ffurl_connect(*puc, NULL); + if (!ret) + return 0; + fail: +- url_close(*puc); ++ ffurl_close(*puc); + *puc = NULL; + return ret; + } ++int url_alloc(URLContext **puc, const char *filename, int flags) ++{ ++ return ffurl_alloc(puc, filename, flags, NULL); ++} ++int url_connect(URLContext* uc) ++{ ++ return ffurl_connect(uc, NULL); ++} ++int url_open(URLContext **puc, const char *filename, int flags) ++{ ++ return ffurl_open(puc, filename, flags, NULL, NULL); ++} ++int url_read(URLContext *h, unsigned char *buf, int size) ++{ ++ return ffurl_read(h, buf, size); ++} ++int url_read_complete(URLContext *h, unsigned char *buf, int size) ++{ ++ return ffurl_read_complete(h, buf, size); ++} ++int url_write(URLContext *h, const unsigned char *buf, int size) ++{ ++ return ffurl_write(h, buf, size); ++} ++int64_t url_seek(URLContext *h, int64_t pos, int whence) ++{ ++ return ffurl_seek(h, pos, whence); ++} ++int url_close(URLContext *h) ++{ ++ return ffurl_close(h); ++} ++int64_t url_filesize(URLContext *h) ++{ ++ return ffurl_size(h); ++} ++int url_get_file_handle(URLContext *h) ++{ ++ return ffurl_get_file_handle(h); ++} ++int url_get_max_packet_size(URLContext *h) ++{ ++ return h->max_packet_size; ++} ++void url_get_filename(URLContext *h, char *buf, int buf_size) ++{ ++ av_strlcpy(buf, h->filename, buf_size); ++} ++void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) ++{ ++ avio_set_interrupt_cb(interrupt_cb); ++} ++int av_register_protocol2(URLProtocol *protocol, int size) ++{ ++ return ffurl_register_protocol(protocol, size); ++} ++#endif + + #define URL_SCHEME_CHARS \ + "abcdefghijklmnopqrstuvwxyz" \ + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + "0123456789+-." + +-int url_alloc(URLContext **puc, const char *filename, int flags) ++int ffurl_alloc(URLContext **puc, const char *filename, int flags, ++ const AVIOInterruptCB *int_cb) + { +- URLProtocol *up; +- char proto_str[128]; ++ URLProtocol *up = NULL; ++ char proto_str[128], proto_nested[128], *ptr; + size_t proto_len = strspn(filename, URL_SCHEME_CHARS); + +- if (filename[proto_len] != ':' || is_dos_path(filename)) ++ if (!first_protocol) { ++ av_log(NULL, AV_LOG_WARNING, "No URL Protocols are registered. " ++ "Missing call to av_register_all()?\n"); ++ } ++ ++ if (filename[proto_len] != ':' && filename[proto_len] != ',' || is_dos_path(filename)) + strcpy(proto_str, "file"); + else + av_strlcpy(proto_str, filename, FFMIN(proto_len+1, sizeof(proto_str))); + +- up = first_protocol; +- while (up != NULL) { ++ if ((ptr = strchr(proto_str, ','))) ++ *ptr = '\0'; ++ av_strlcpy(proto_nested, proto_str, sizeof(proto_nested)); ++ if ((ptr = strchr(proto_nested, '+'))) ++ *ptr = '\0'; ++ ++ while (up = ffurl_protocol_next(up)) { + if (!strcmp(proto_str, up->name)) +- return url_alloc_for_protocol (puc, up, filename, flags); +- up = up->next; ++ return url_alloc_for_protocol (puc, up, filename, flags, int_cb); ++ if (up->flags & URL_PROTOCOL_FLAG_NESTED_SCHEME && ++ !strcmp(proto_nested, up->name)) ++ return url_alloc_for_protocol (puc, up, filename, flags, int_cb); + } + *puc = NULL; + return AVERROR(ENOENT); + } + +-int url_open(URLContext **puc, const char *filename, int flags) ++int ffurl_open(URLContext **puc, const char *filename, int flags, ++ const AVIOInterruptCB *int_cb, AVDictionary **options) + { +- int ret = url_alloc(puc, filename, flags); ++ int ret = ffurl_alloc(puc, filename, flags, int_cb); + if (ret) + return ret; +- ret = url_connect(*puc); ++ if (options && (*puc)->prot->priv_data_class && ++ (ret = av_opt_set_dict((*puc)->priv_data, options)) < 0) ++ goto fail; ++ ret = ffurl_connect(*puc, options); + if (!ret) + return 0; +- url_close(*puc); ++fail: ++ ffurl_close(*puc); + *puc = NULL; + return ret; + } + +-int url_read(URLContext *h, unsigned char *buf, int size) +-{ +- int ret; +- if (h->flags & URL_WRONLY) +- return AVERROR(EIO); +- ret = h->prot->url_read(h, buf, size); +- return ret; +-} +- +-static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, ++static inline int retry_transfer_wrapper(URLContext *h, unsigned char *buf, int size, int size_min, + int (*transfer_func)(URLContext *h, unsigned char *buf, int size)) + { + int ret, len; + int fast_retries = 5; + + len = 0; +- while (len < size) { ++ while (len < size_min) { + ret = transfer_func(h, buf+len, size-len); ++ if (ret == AVERROR(EINTR)) ++ continue; ++ if (h->flags & AVIO_FLAG_NONBLOCK) ++ return ret; + if (ret == AVERROR(EAGAIN)) { + ret = 0; + if (fast_retries) +@@ -235,27 +361,38 @@ + if (ret) + fast_retries = FFMAX(fast_retries, 2); + len += ret; ++ if (len < size && ff_check_interrupt(&h->interrupt_callback)) ++ return AVERROR_EXIT; + } + return len; + } + +-int url_read_complete(URLContext *h, unsigned char *buf, int size) ++int ffurl_read(URLContext *h, unsigned char *buf, int size) + { +- return retry_transfer_wrapper(h, buf, size, url_read); ++ if (!(h->flags & AVIO_FLAG_READ)) ++ return AVERROR(EIO); ++ return retry_transfer_wrapper(h, buf, size, 1, h->prot->url_read); + } + +-int url_write(URLContext *h, const unsigned char *buf, int size) ++int ffurl_read_complete(URLContext *h, unsigned char *buf, int size) ++{ ++ if (!(h->flags & AVIO_FLAG_READ)) ++ return AVERROR(EIO); ++ return retry_transfer_wrapper(h, buf, size, size, h->prot->url_read); ++} ++ ++int ffurl_write(URLContext *h, const unsigned char *buf, int size) + { +- if (!(h->flags & (URL_WRONLY | URL_RDWR))) ++ if (!(h->flags & AVIO_FLAG_WRITE)) + return AVERROR(EIO); + /* avoid sending too big packets */ + if (h->max_packet_size && size > h->max_packet_size) + return AVERROR(EIO); + +- return retry_transfer_wrapper(h, buf, size, h->prot->url_write); ++ return retry_transfer_wrapper(h, buf, size, size, (void*)h->prot->url_write); + } + +-int64_t url_seek(URLContext *h, int64_t pos, int whence) ++int64_t ffurl_seek(URLContext *h, int64_t pos, int whence) + { + int64_t ret; + +@@ -265,76 +402,105 @@ + return ret; + } + +-int url_close(URLContext *h) ++int ffurl_close(URLContext *h) + { + int ret = 0; +- if (!h) return 0; /* can happen when url_open fails */ ++ if (!h) return 0; /* can happen when ffurl_open fails */ + + if (h->is_connected && h->prot->url_close) + ret = h->prot->url_close(h); + #if CONFIG_NETWORK +- ff_network_close(); ++ if (h->prot->flags & URL_PROTOCOL_FLAG_NETWORK) ++ ff_network_close(); + #endif +- if (h->prot->priv_data_size) ++ if (h->prot->priv_data_size) { ++ if (h->prot->priv_data_class) ++ av_opt_free(h->priv_data); + av_free(h->priv_data); ++ } + av_free(h); + return ret; + } + ++#if FF_API_OLD_AVIO + int url_exist(const char *filename) + { + URLContext *h; +- if (url_open(&h, filename, URL_RDONLY) < 0) ++ if (ffurl_open(&h, filename, AVIO_FLAG_READ, NULL, NULL) < 0) + return 0; +- url_close(h); ++ ffurl_close(h); + return 1; + } ++#endif + +-int64_t url_filesize(URLContext *h) ++int avio_check(const char *url, int flags) ++{ ++ URLContext *h; ++ int ret = ffurl_alloc(&h, url, flags, NULL); ++ if (ret) ++ return ret; ++ ++ if (h->prot->url_check) { ++ ret = h->prot->url_check(h, flags); ++ } else { ++ ret = ffurl_connect(h, NULL); ++ if (ret >= 0) ++ ret = flags; ++ } ++ ++ ffurl_close(h); ++ return ret; ++} ++ ++int64_t ffurl_size(URLContext *h) + { + int64_t pos, size; + +- size= url_seek(h, 0, AVSEEK_SIZE); ++ size= ffurl_seek(h, 0, AVSEEK_SIZE); + if(size<0){ +- pos = url_seek(h, 0, SEEK_CUR); +- if ((size = url_seek(h, -1, SEEK_END)) < 0) ++ pos = ffurl_seek(h, 0, SEEK_CUR); ++ if ((size = ffurl_seek(h, -1, SEEK_END)) < 0) + return size; + size++; +- url_seek(h, pos, SEEK_SET); ++ ffurl_seek(h, pos, SEEK_SET); + } + return size; + } + +-int url_get_file_handle(URLContext *h) ++int ffurl_get_file_handle(URLContext *h) + { + if (!h->prot->url_get_file_handle) + return -1; + return h->prot->url_get_file_handle(h); + } + +-int url_get_max_packet_size(URLContext *h) +-{ +- return h->max_packet_size; +-} +- +-void url_get_filename(URLContext *h, char *buf, int buf_size) +-{ +- av_strlcpy(buf, h->filename, buf_size); +-} +- +- ++#if FF_API_OLD_INTERRUPT_CB + static int default_interrupt_cb(void) + { + return 0; + } + +-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb) ++void avio_set_interrupt_cb(int (*interrupt_cb)(void)) + { + if (!interrupt_cb) + interrupt_cb = default_interrupt_cb; + url_interrupt_cb = interrupt_cb; + } ++#endif + ++int ff_check_interrupt(AVIOInterruptCB *cb) ++{ ++ int ret; ++ if (cb && cb->callback && (ret = cb->callback(cb->opaque))) ++ return ret; ++#if FF_API_OLD_INTERRUPT_CB ++ return url_interrupt_cb(); ++#else ++ return 0; ++#endif ++} ++ ++#if FF_API_OLD_AVIO + int av_url_read_pause(URLContext *h, int pause) + { + if (!h->prot->url_read_pause) +@@ -349,3 +515,4 @@ + return AVERROR(ENOSYS); + return h->prot->url_read_seek(h, stream_index, timestamp, flags); + } ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio.h 2012-05-14 14:08:54.911351595 +0200 +@@ -22,32 +22,125 @@ + + /** + * @file +- * unbuffered I/O operations +- * +- * @warning This file has to be considered an internal but installed +- * header, so it should not be directly included in your projects. ++ * @ingroup lavf_io ++ * Buffered I/O operations + */ + + #include + + #include "libavutil/common.h" ++#include "libavutil/dict.h" + #include "libavutil/log.h" + + #include "libavformat/version.h" + ++ ++#define AVIO_SEEKABLE_NORMAL 0x0001 /**< Seeking works like for a local file */ ++ ++/** ++ * Callback for checking whether to abort blocking functions. ++ * AVERROR_EXIT is returned in this case by the interrupted ++ * function. During blocking operations, callback is called with ++ * opaque as parameter. If the callback returns 1, the ++ * blocking operation will be aborted. ++ * ++ * No members can be added to this struct without a major bump, if ++ * new elements have been added after this struct in AVFormatContext ++ * or AVIOContext. ++ */ ++typedef struct { ++ int (*callback)(void*); ++ void *opaque; ++} AVIOInterruptCB; ++ ++/** ++ * Bytestream IO Context. ++ * New fields can be added to the end with minor version bumps. ++ * Removal, reordering and changes to existing fields require a major ++ * version bump. ++ * sizeof(AVIOContext) must not be used outside libav*. ++ * ++ * @note None of the function pointers in AVIOContext should be called ++ * directly, they should only be set by the client application ++ * when implementing custom I/O. Normally these are set to the ++ * function pointers specified in avio_alloc_context() ++ */ ++typedef struct { ++#if !FF_API_OLD_AVIO ++ /** ++ * A class for private options. ++ * ++ * If this AVIOContext is created by avio_open2(), av_class is set and ++ * passes the options down to protocols. ++ * ++ * If this AVIOContext is manually allocated, then av_class may be set by ++ * the caller. ++ * ++ * warning -- this field can be NULL, be sure to not pass this AVIOContext ++ * to any av_opt_* functions in that case. ++ */ ++ AVClass *av_class; ++#endif ++ unsigned char *buffer; /**< Start of the buffer. */ ++ int buffer_size; /**< Maximum buffer size */ ++ unsigned char *buf_ptr; /**< Current position in the buffer */ ++ unsigned char *buf_end; /**< End of the data, may be less than ++ buffer+buffer_size if the read function returned ++ less data than requested, e.g. for streams where ++ no more data has been received yet. */ ++ void *opaque; /**< A private pointer, passed to the read/write/seek/... ++ functions. */ ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); ++ int64_t (*seek)(void *opaque, int64_t offset, int whence); ++ int64_t pos; /**< position in the file of the current buffer */ ++ int must_flush; /**< true if the next seek should flush */ ++ int eof_reached; /**< true if eof reached */ ++ int write_flag; /**< true if open for writing */ ++#if FF_API_OLD_AVIO ++ attribute_deprecated int is_streamed; ++#endif ++ int max_packet_size; ++ unsigned long checksum; ++ unsigned char *checksum_ptr; ++ unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); ++ int error; /**< contains the error code or 0 if no error happened */ ++ /** ++ * Pause or resume playback for network streaming protocols - e.g. MMS. ++ */ ++ int (*read_pause)(void *opaque, int pause); ++ /** ++ * Seek to a given timestamp in stream with the specified stream_index. ++ * Needed for some network streaming protocols which don't support seeking ++ * to byte position. ++ */ ++ int64_t (*read_seek)(void *opaque, int stream_index, ++ int64_t timestamp, int flags); ++ /** ++ * A combination of AVIO_SEEKABLE_ flags or 0 when the stream is not seekable. ++ */ ++ int seekable; ++ ++ /** ++ * max filesize, used to limit allocations ++ * This field is internal to libavformat and access from outside is not allowed. ++ */ ++ int64_t maxsize; ++} AVIOContext; ++ + /* unbuffered I/O */ + ++#if FF_API_OLD_AVIO + /** + * URL Context. + * New fields can be added to the end with minor version bumps. + * Removal, reordering and changes to existing fields require a major + * version bump. + * sizeof(URLContext) must not be used outside libav*. ++ * @deprecated This struct will be made private + */ + typedef struct URLContext { +-#if FF_API_URL_CLASS + const AVClass *av_class; ///< information for av_log(). Set by url_open(). +-#endif + struct URLProtocol *prot; + int flags; + int is_streamed; /**< true if streamed (no seek possible), default = false */ +@@ -55,297 +148,285 @@ + void *priv_data; + char *filename; /**< specified URL */ + int is_connected; ++ AVIOInterruptCB interrupt_callback; + } URLContext; + ++#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ ++#define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */ ++ ++/** ++ * @deprecated This struct is to be made private. Use the higher-level ++ * AVIOContext-based API instead. ++ */ ++typedef struct URLProtocol { ++ const char *name; ++ int (*url_open)(URLContext *h, const char *url, int flags); ++ int (*url_read)(URLContext *h, unsigned char *buf, int size); ++ int (*url_write)(URLContext *h, const unsigned char *buf, int size); ++ int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); ++ int (*url_close)(URLContext *h); ++ struct URLProtocol *next; ++ int (*url_read_pause)(URLContext *h, int pause); ++ int64_t (*url_read_seek)(URLContext *h, int stream_index, ++ int64_t timestamp, int flags); ++ int (*url_get_file_handle)(URLContext *h); ++ int priv_data_size; ++ const AVClass *priv_data_class; ++ int flags; ++ int (*url_check)(URLContext *h, int mask); ++} URLProtocol; ++ + typedef struct URLPollEntry { + URLContext *handle; + int events; + int revents; + } URLPollEntry; + +-#define URL_RDONLY 0 +-#define URL_WRONLY 1 +-#define URL_RDWR 2 +- +-typedef int URLInterruptCB(void); ++/* not implemented */ ++attribute_deprecated int url_poll(URLPollEntry *poll_table, int n, int timeout); + + /** +- * Create a URLContext for accessing to the resource indicated by +- * url, and open it using the URLProtocol up. +- * +- * @param puc pointer to the location where, in case of success, the +- * function puts the pointer to the created URLContext +- * @param flags flags which control how the resource indicated by url +- * is to be opened +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code in case of failure ++ * @name URL open modes ++ * The flags argument to url_open and cosins must be one of the following ++ * constants, optionally ORed with other flags. ++ * @{ + */ +-int url_open_protocol (URLContext **puc, struct URLProtocol *up, +- const char *url, int flags); +- ++#define URL_RDONLY 1 /**< read-only */ ++#define URL_WRONLY 2 /**< write-only */ ++#define URL_RDWR (URL_RDONLY|URL_WRONLY) /**< read-write */ + /** +- * Create a URLContext for accessing to the resource indicated by +- * url, but do not initiate the connection yet. +- * +- * @param puc pointer to the location where, in case of success, the +- * function puts the pointer to the created URLContext +- * @param flags flags which control how the resource indicated by url +- * is to be opened +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code in case of failure ++ * @} + */ +-int url_alloc(URLContext **h, const char *url, int flags); + + /** +- * Connect an URLContext that has been allocated by url_alloc ++ * Use non-blocking mode. ++ * If this flag is set, operations on the context will return ++ * AVERROR(EAGAIN) if they can not be performed immediately. ++ * If this flag is not set, operations on the context will never return ++ * AVERROR(EAGAIN). ++ * Note that this flag does not affect the opening/connecting of the ++ * context. Connecting a protocol will always block if necessary (e.g. on ++ * network protocols) but never hang (e.g. on busy devices). ++ * Warning: non-blocking protocols is work-in-progress; this flag may be ++ * silently ignored. + */ +-int url_connect(URLContext *h); ++#define URL_FLAG_NONBLOCK 8 + +-/** +- * Create an URLContext for accessing to the resource indicated by +- * url, and open it. +- * +- * @param puc pointer to the location where, in case of success, the +- * function puts the pointer to the created URLContext +- * @param flags flags which control how the resource indicated by url +- * is to be opened +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code in case of failure +- */ +-int url_open(URLContext **h, const char *url, int flags); ++typedef int URLInterruptCB(void); ++extern URLInterruptCB *url_interrupt_cb; + + /** +- * Read up to size bytes from the resource accessed by h, and store +- * the read bytes in buf. +- * +- * @return The number of bytes actually read, or a negative value +- * corresponding to an AVERROR code in case of error. A value of zero +- * indicates that it is not possible to read more from the accessed +- * resource (except if the value of the size argument is also zero). +- */ +-int url_read(URLContext *h, unsigned char *buf, int size); ++ * @defgroup old_url_funcs Old url_* functions ++ * The following functions are deprecated. Use the buffered API based on #AVIOContext instead. ++ * @{ ++ * @ingroup lavf_io ++ */ ++attribute_deprecated int url_open_protocol (URLContext **puc, struct URLProtocol *up, ++ const char *url, int flags); ++attribute_deprecated int url_alloc(URLContext **h, const char *url, int flags); ++attribute_deprecated int url_connect(URLContext *h); ++attribute_deprecated int url_open(URLContext **h, const char *url, int flags); ++attribute_deprecated int url_read(URLContext *h, unsigned char *buf, int size); ++attribute_deprecated int url_read_complete(URLContext *h, unsigned char *buf, int size); ++attribute_deprecated int url_write(URLContext *h, const unsigned char *buf, int size); ++attribute_deprecated int64_t url_seek(URLContext *h, int64_t pos, int whence); ++attribute_deprecated int url_close(URLContext *h); ++attribute_deprecated int64_t url_filesize(URLContext *h); ++attribute_deprecated int url_get_file_handle(URLContext *h); ++attribute_deprecated int url_get_max_packet_size(URLContext *h); ++attribute_deprecated void url_get_filename(URLContext *h, char *buf, int buf_size); ++attribute_deprecated int av_url_read_pause(URLContext *h, int pause); ++attribute_deprecated int64_t av_url_read_seek(URLContext *h, int stream_index, ++ int64_t timestamp, int flags); ++attribute_deprecated void url_set_interrupt_cb(int (*interrupt_cb)(void)); + + /** +- * Read as many bytes as possible (up to size), calling the +- * read function multiple times if necessary. +- * Will also retry if the read function returns AVERROR(EAGAIN). +- * This makes special short-read handling in applications +- * unnecessary, if the return value is < size then it is +- * certain there was either an error or the end of file was reached. ++ * returns the next registered protocol after the given protocol (the first if ++ * NULL is given), or NULL if protocol is the last one. + */ +-int url_read_complete(URLContext *h, unsigned char *buf, int size); ++URLProtocol *av_protocol_next(URLProtocol *p); + + /** +- * Write size bytes from buf to the resource accessed by h. ++ * Register the URLProtocol protocol. + * +- * @return the number of bytes actually written, or a negative value +- * corresponding to an AVERROR code in case of failure ++ * @param size the size of the URLProtocol struct referenced + */ +-int url_write(URLContext *h, const unsigned char *buf, int size); +- ++attribute_deprecated int av_register_protocol2(URLProtocol *protocol, int size); + /** +- * Passing this as the "whence" parameter to a seek function causes it to +- * return the filesize without seeking anywhere. Supporting this is optional. +- * If it is not supported then the seek function will return <0. ++ * @} + */ +-#define AVSEEK_SIZE 0x10000 + +-/** +- * Change the position that will be used by the next read/write +- * operation on the resource accessed by h. +- * +- * @param pos specifies the new position to set +- * @param whence specifies how pos should be interpreted, it must be +- * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the +- * current position), SEEK_END (seek from the end), or AVSEEK_SIZE +- * (return the filesize of the requested resource, pos is ignored). +- * @return a negative value corresponding to an AVERROR code in case +- * of failure, or the resulting file position, measured in bytes from +- * the beginning of the file. You can use this feature together with +- * SEEK_CUR to read the current file position. +- */ +-int64_t url_seek(URLContext *h, int64_t pos, int whence); + +-/** +- * Close the resource accessed by the URLContext h, and free the +- * memory used by it. +- * +- * @return a negative value if an error condition occurred, 0 +- * otherwise +- */ +-int url_close(URLContext *h); ++typedef attribute_deprecated AVIOContext ByteIOContext; + +-/** +- * Return a non-zero value if the resource indicated by url +- * exists, 0 otherwise. +- */ +-int url_exist(const char *url); ++attribute_deprecated int init_put_byte(AVIOContext *s, ++ unsigned char *buffer, ++ int buffer_size, ++ int write_flag, ++ void *opaque, ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int64_t (*seek)(void *opaque, int64_t offset, int whence)); ++attribute_deprecated AVIOContext *av_alloc_put_byte( ++ unsigned char *buffer, ++ int buffer_size, ++ int write_flag, ++ void *opaque, ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int64_t (*seek)(void *opaque, int64_t offset, int whence)); + + /** +- * Return the filesize of the resource accessed by h, AVERROR(ENOSYS) +- * if the operation is not supported by h, or another negative value +- * corresponding to an AVERROR error code in case of failure. +- */ +-int64_t url_filesize(URLContext *h); +- ++ * @defgroup old_avio_funcs Old put_/get_*() functions ++ * The following functions are deprecated. Use the "avio_"-prefixed functions instead. ++ * @{ ++ * @ingroup lavf_io ++ */ ++attribute_deprecated int get_buffer(AVIOContext *s, unsigned char *buf, int size); ++attribute_deprecated int get_partial_buffer(AVIOContext *s, unsigned char *buf, int size); ++attribute_deprecated int get_byte(AVIOContext *s); ++attribute_deprecated unsigned int get_le16(AVIOContext *s); ++attribute_deprecated unsigned int get_le24(AVIOContext *s); ++attribute_deprecated unsigned int get_le32(AVIOContext *s); ++attribute_deprecated uint64_t get_le64(AVIOContext *s); ++attribute_deprecated unsigned int get_be16(AVIOContext *s); ++attribute_deprecated unsigned int get_be24(AVIOContext *s); ++attribute_deprecated unsigned int get_be32(AVIOContext *s); ++attribute_deprecated uint64_t get_be64(AVIOContext *s); ++ ++attribute_deprecated void put_byte(AVIOContext *s, int b); ++attribute_deprecated void put_nbyte(AVIOContext *s, int b, int count); ++attribute_deprecated void put_buffer(AVIOContext *s, const unsigned char *buf, int size); ++attribute_deprecated void put_le64(AVIOContext *s, uint64_t val); ++attribute_deprecated void put_be64(AVIOContext *s, uint64_t val); ++attribute_deprecated void put_le32(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_be32(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_le24(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_be24(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_le16(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_be16(AVIOContext *s, unsigned int val); ++attribute_deprecated void put_tag(AVIOContext *s, const char *tag); ++/** ++ * @} ++ */ ++ ++attribute_deprecated int av_url_read_fpause(AVIOContext *h, int pause); ++attribute_deprecated int64_t av_url_read_fseek (AVIOContext *h, int stream_index, ++ int64_t timestamp, int flags); ++ ++/** ++ * @defgroup old_url_f_funcs Old url_f* functions ++ * The following functions are deprecated, use the "avio_"-prefixed functions instead. ++ * @{ ++ * @ingroup lavf_io ++ */ ++attribute_deprecated int url_fopen( AVIOContext **s, const char *url, int flags); ++attribute_deprecated int url_fclose(AVIOContext *s); ++attribute_deprecated int64_t url_fseek(AVIOContext *s, int64_t offset, int whence); ++attribute_deprecated int url_fskip(AVIOContext *s, int64_t offset); ++attribute_deprecated int64_t url_ftell(AVIOContext *s); ++attribute_deprecated int64_t url_fsize(AVIOContext *s); ++#define URL_EOF (-1) ++attribute_deprecated int url_fgetc(AVIOContext *s); ++attribute_deprecated int url_setbufsize(AVIOContext *s, int buf_size); ++attribute_deprecated int url_fprintf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3); ++attribute_deprecated void put_flush_packet(AVIOContext *s); ++attribute_deprecated int url_open_dyn_buf(AVIOContext **s); ++attribute_deprecated int url_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); ++attribute_deprecated int url_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); ++attribute_deprecated int url_fdopen(AVIOContext **s, URLContext *h); + /** +- * Return the file descriptor associated with this URL. For RTP, this +- * will return only the RTP file descriptor, not the RTCP file descriptor. +- * +- * @return the file descriptor associated with this URL, or <0 on error. ++ * @} + */ +-int url_get_file_handle(URLContext *h); + +-/** +- * Return the maximum packet size associated to packetized file +- * handle. If the file is not packetized (stream like HTTP or file on +- * disk), then 0 is returned. +- * +- * @param h file handle +- * @return maximum packet size in bytes +- */ +-int url_get_max_packet_size(URLContext *h); ++attribute_deprecated int url_ferror(AVIOContext *s); + +-/** +- * Copy the filename of the resource accessed by h to buf. +- * +- * @param buf_size size in bytes of buf +- */ +-void url_get_filename(URLContext *h, char *buf, int buf_size); ++attribute_deprecated int udp_set_remote_url(URLContext *h, const char *uri); ++attribute_deprecated int udp_get_local_port(URLContext *h); + ++attribute_deprecated void init_checksum(AVIOContext *s, ++ unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), ++ unsigned long checksum); ++attribute_deprecated unsigned long get_checksum(AVIOContext *s); ++attribute_deprecated void put_strz(AVIOContext *s, const char *buf); ++/** @note unlike fgets, the EOL character is not returned and a whole ++ line is parsed. return NULL if first char read was EOF */ ++attribute_deprecated char *url_fgets(AVIOContext *s, char *buf, int buf_size); + /** +- * The callback is called in blocking functions to test regulary if +- * asynchronous interruption is needed. AVERROR(EINTR) is returned +- * in this case by the interrupted function. 'NULL' means no interrupt +- * callback is given. ++ * @deprecated use avio_get_str instead + */ +-void url_set_interrupt_cb(URLInterruptCB *interrupt_cb); +- +-/* not implemented */ +-int url_poll(URLPollEntry *poll_table, int n, int timeout); +- ++attribute_deprecated char *get_strz(AVIOContext *s, char *buf, int maxlen); + /** +- * Pause and resume playing - only meaningful if using a network streaming +- * protocol (e.g. MMS). +- * @param pause 1 for pause, 0 for resume ++ * @deprecated Use AVIOContext.seekable field directly. + */ +-int av_url_read_pause(URLContext *h, int pause); ++attribute_deprecated static inline int url_is_streamed(AVIOContext *s) ++{ ++ return !s->seekable; ++} ++attribute_deprecated URLContext *url_fileno(AVIOContext *s); + + /** +- * Seek to a given timestamp relative to some component stream. +- * Only meaningful if using a network streaming protocol (e.g. MMS.). +- * @param stream_index The stream index that the timestamp is relative to. +- * If stream_index is (-1) the timestamp should be in AV_TIME_BASE +- * units from the beginning of the presentation. +- * If a stream_index >= 0 is used and the protocol does not support +- * seeking based on component streams, the call will fail with ENOTSUP. +- * @param timestamp timestamp in AVStream.time_base units +- * or if there is no stream specified then in AV_TIME_BASE units. +- * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE +- * and AVSEEK_FLAG_ANY. The protocol may silently ignore +- * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will +- * fail with ENOTSUP if used and not supported. +- * @return >= 0 on success +- * @see AVInputFormat::read_seek ++ * @deprecated use AVIOContext.max_packet_size directly. + */ +-int64_t av_url_read_seek(URLContext *h, int stream_index, +- int64_t timestamp, int flags); ++attribute_deprecated int url_fget_max_packet_size(AVIOContext *s); + +-/** +- * Oring this flag as into the "whence" parameter to a seek function causes it to +- * seek by any means (like reopening and linear reading) or other normally unreasonble +- * means that can be extreemly slow. +- * This may be ignored by the seek code. +- */ +-#define AVSEEK_FORCE 0x20000 +- +-typedef struct URLProtocol { +- const char *name; +- int (*url_open)(URLContext *h, const char *url, int flags); +- int (*url_read)(URLContext *h, unsigned char *buf, int size); +- int (*url_write)(URLContext *h, const unsigned char *buf, int size); +- int64_t (*url_seek)(URLContext *h, int64_t pos, int whence); +- int (*url_close)(URLContext *h); +- struct URLProtocol *next; +- int (*url_read_pause)(URLContext *h, int pause); +- int64_t (*url_read_seek)(URLContext *h, int stream_index, +- int64_t timestamp, int flags); +- int (*url_get_file_handle)(URLContext *h); +- int priv_data_size; +- const AVClass *priv_data_class; +-} URLProtocol; +- +-#if FF_API_REGISTER_PROTOCOL +-extern URLProtocol *first_protocol; +-#endif ++attribute_deprecated int url_open_buf(AVIOContext **s, uint8_t *buf, int buf_size, int flags); + +-extern URLInterruptCB *url_interrupt_cb; ++/** return the written or read size */ ++attribute_deprecated int url_close_buf(AVIOContext *s); + + /** +- * If protocol is NULL, returns the first registered protocol, +- * if protocol is non-NULL, returns the next registered protocol after protocol, +- * or NULL if protocol is the last one. ++ * Return a non-zero value if the resource indicated by url ++ * exists, 0 otherwise. ++ * @deprecated Use avio_check instead. + */ +-URLProtocol *av_protocol_next(URLProtocol *p); ++attribute_deprecated int url_exist(const char *url); ++#endif // FF_API_OLD_AVIO + +-#if FF_API_REGISTER_PROTOCOL + /** +- * @deprecated Use av_register_protocol() instead. ++ * Return AVIO_FLAG_* access flags corresponding to the access permissions ++ * of the resource in url, or a negative value corresponding to an ++ * AVERROR code in case of failure. The returned access flags are ++ * masked by the value in flags. ++ * ++ * @note This function is intrinsically unsafe, in the sense that the ++ * checked resource may change its existence or permission status from ++ * one call to another. Thus you should not trust the returned value, ++ * unless you are sure that no other processes are accessing the ++ * checked resource. + */ +-attribute_deprecated int register_protocol(URLProtocol *protocol); ++int avio_check(const char *url, int flags); + ++#if FF_API_OLD_INTERRUPT_CB + /** +- * @deprecated Use av_register_protocol2() instead. ++ * The callback is called in blocking functions to test regulary if ++ * asynchronous interruption is needed. AVERROR_EXIT is returned ++ * in this case by the interrupted function. 'NULL' means no interrupt ++ * callback is given. ++ * @deprecated Use interrupt_callback in AVFormatContext/avio_open2 ++ * instead. + */ +-attribute_deprecated int av_register_protocol(URLProtocol *protocol); ++attribute_deprecated void avio_set_interrupt_cb(int (*interrupt_cb)(void)); + #endif + + /** +- * Register the URLProtocol protocol. ++ * Allocate and initialize an AVIOContext for buffered I/O. It must be later ++ * freed with av_free(). + * +- * @param size the size of the URLProtocol struct referenced +- */ +-int av_register_protocol2(URLProtocol *protocol, int size); +- +-/** +- * Bytestream IO Context. +- * New fields can be added to the end with minor version bumps. +- * Removal, reordering and changes to existing fields require a major +- * version bump. +- * sizeof(ByteIOContext) must not be used outside libav*. ++ * @param buffer Memory block for input/output operations via AVIOContext. ++ * The buffer must be allocated with av_malloc() and friends. ++ * @param buffer_size The buffer size is very important for performance. ++ * For protocols with fixed blocksize it should be set to this blocksize. ++ * For others a typical size is a cache page, e.g. 4kb. ++ * @param write_flag Set to 1 if the buffer should be writable, 0 otherwise. ++ * @param opaque An opaque pointer to user-specific data. ++ * @param read_packet A function for refilling the buffer, may be NULL. ++ * @param write_packet A function for writing the buffer contents, may be NULL. ++ * @param seek A function for seeking to specified byte position, may be NULL. ++ * ++ * @return Allocated AVIOContext or NULL on failure. + */ +-typedef struct { +- unsigned char *buffer; +- int buffer_size; +- unsigned char *buf_ptr, *buf_end; +- void *opaque; +- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size); +- int (*write_packet)(void *opaque, uint8_t *buf, int buf_size); +- int64_t (*seek)(void *opaque, int64_t offset, int whence); +- int64_t pos; /**< position in the file of the current buffer */ +- int must_flush; /**< true if the next seek should flush */ +- int eof_reached; /**< true if eof reached */ +- int write_flag; /**< true if open for writing */ +- int is_streamed; +- int max_packet_size; +- unsigned long checksum; +- unsigned char *checksum_ptr; +- unsigned long (*update_checksum)(unsigned long checksum, const uint8_t *buf, unsigned int size); +- int error; ///< contains the error code or 0 if no error happened +- int (*read_pause)(void *opaque, int pause); +- int64_t (*read_seek)(void *opaque, int stream_index, +- int64_t timestamp, int flags); +-} ByteIOContext; +- +-int init_put_byte(ByteIOContext *s, +- unsigned char *buffer, +- int buffer_size, +- int write_flag, +- void *opaque, +- int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), +- int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), +- int64_t (*seek)(void *opaque, int64_t offset, int whence)); +-ByteIOContext *av_alloc_put_byte( ++AVIOContext *avio_alloc_context( + unsigned char *buffer, + int buffer_size, + int write_flag, +@@ -354,111 +435,122 @@ + int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), + int64_t (*seek)(void *opaque, int64_t offset, int whence)); + +-void put_byte(ByteIOContext *s, int b); +-void put_nbyte(ByteIOContext *s, int b, int count); +-void put_buffer(ByteIOContext *s, const unsigned char *buf, int size); +-void put_le64(ByteIOContext *s, uint64_t val); +-void put_be64(ByteIOContext *s, uint64_t val); +-void put_le32(ByteIOContext *s, unsigned int val); +-void put_be32(ByteIOContext *s, unsigned int val); +-void put_le24(ByteIOContext *s, unsigned int val); +-void put_be24(ByteIOContext *s, unsigned int val); +-void put_le16(ByteIOContext *s, unsigned int val); +-void put_be16(ByteIOContext *s, unsigned int val); +-void put_tag(ByteIOContext *s, const char *tag); +- +-#if FF_API_OLD_AVIO +-attribute_deprecated void put_strz(ByteIOContext *s, const char *buf); +-#endif ++void avio_w8(AVIOContext *s, int b); ++void avio_write(AVIOContext *s, const unsigned char *buf, int size); ++void avio_wl64(AVIOContext *s, uint64_t val); ++void avio_wb64(AVIOContext *s, uint64_t val); ++void avio_wl32(AVIOContext *s, unsigned int val); ++void avio_wb32(AVIOContext *s, unsigned int val); ++void avio_wl24(AVIOContext *s, unsigned int val); ++void avio_wb24(AVIOContext *s, unsigned int val); ++void avio_wl16(AVIOContext *s, unsigned int val); ++void avio_wb16(AVIOContext *s, unsigned int val); + + /** + * Write a NULL-terminated string. + * @return number of bytes written. + */ +-int avio_put_str(ByteIOContext *s, const char *str); ++int avio_put_str(AVIOContext *s, const char *str); + + /** + * Convert an UTF-8 string to UTF-16LE and write it. + * @return number of bytes written. + */ +-int avio_put_str16le(ByteIOContext *s, const char *str); ++int avio_put_str16le(AVIOContext *s, const char *str); ++ ++/** ++ * Passing this as the "whence" parameter to a seek function causes it to ++ * return the filesize without seeking anywhere. Supporting this is optional. ++ * If it is not supported then the seek function will return <0. ++ */ ++#define AVSEEK_SIZE 0x10000 ++ ++/** ++ * Oring this flag as into the "whence" parameter to a seek function causes it to ++ * seek by any means (like reopening and linear reading) or other normally unreasonble ++ * means that can be extreemly slow. ++ * This may be ignored by the seek code. ++ */ ++#define AVSEEK_FORCE 0x20000 + + /** +- * fseek() equivalent for ByteIOContext. ++ * fseek() equivalent for AVIOContext. + * @return new position or AVERROR. + */ +-int64_t url_fseek(ByteIOContext *s, int64_t offset, int whence); ++int64_t avio_seek(AVIOContext *s, int64_t offset, int whence); + + /** +- * Skip given number of bytes forward. +- * @param offset number of bytes +- * @return 0 on success, <0 on error ++ * Skip given number of bytes forward ++ * @return new position or AVERROR. + */ +-int url_fskip(ByteIOContext *s, int64_t offset); ++int64_t avio_skip(AVIOContext *s, int64_t offset); + + /** +- * ftell() equivalent for ByteIOContext. ++ * ftell() equivalent for AVIOContext. + * @return position or AVERROR. + */ +-int64_t url_ftell(ByteIOContext *s); ++static av_always_inline int64_t avio_tell(AVIOContext *s) ++{ ++ return avio_seek(s, 0, SEEK_CUR); ++} + + /** + * Get the filesize. + * @return filesize or AVERROR + */ +-int64_t url_fsize(ByteIOContext *s); ++int64_t avio_size(AVIOContext *s); + + /** +- * feof() equivalent for ByteIOContext. ++ * feof() equivalent for AVIOContext. + * @return non zero if and only if end of file + */ +-int url_feof(ByteIOContext *s); +- +-int url_ferror(ByteIOContext *s); +- +-int av_url_read_fpause(ByteIOContext *h, int pause); +-int64_t av_url_read_fseek(ByteIOContext *h, int stream_index, +- int64_t timestamp, int flags); +- +-#define URL_EOF (-1) +-/** @note return URL_EOF (-1) if EOF */ +-int url_fgetc(ByteIOContext *s); ++int url_feof(AVIOContext *s); + + /** @warning currently size is limited */ +-#ifdef __GNUC__ +-int url_fprintf(ByteIOContext *s, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 2, 3))); +-#else +-int url_fprintf(ByteIOContext *s, const char *fmt, ...); +-#endif ++int avio_printf(AVIOContext *s, const char *fmt, ...) av_printf_format(2, 3); + +-/** @note unlike fgets, the EOL character is not returned and a whole +- line is parsed. return NULL if first char read was EOF */ +-char *url_fgets(ByteIOContext *s, char *buf, int buf_size); +- +-void put_flush_packet(ByteIOContext *s); ++void avio_flush(AVIOContext *s); + + + /** +- * Read size bytes from ByteIOContext into buf. ++ * Read size bytes from AVIOContext into buf. + * @return number of bytes read or AVERROR + */ +-int get_buffer(ByteIOContext *s, unsigned char *buf, int size); ++int avio_read(AVIOContext *s, unsigned char *buf, int size); + + /** +- * Read size bytes from ByteIOContext into buf. +- * This reads at most 1 packet. If that is not enough fewer bytes will be +- * returned. +- * @return number of bytes read or AVERROR ++ * @name Functions for reading from AVIOContext ++ * @{ ++ * ++ * @note return 0 if EOF, so you cannot use it if EOF handling is ++ * necessary ++ */ ++int avio_r8 (AVIOContext *s); ++unsigned int avio_rl16(AVIOContext *s); ++unsigned int avio_rl24(AVIOContext *s); ++unsigned int avio_rl32(AVIOContext *s); ++uint64_t avio_rl64(AVIOContext *s); ++unsigned int avio_rb16(AVIOContext *s); ++unsigned int avio_rb24(AVIOContext *s); ++unsigned int avio_rb32(AVIOContext *s); ++uint64_t avio_rb64(AVIOContext *s); ++/** ++ * @} + */ +-int get_partial_buffer(ByteIOContext *s, unsigned char *buf, int size); + +-/** @note return 0 if EOF, so you cannot use it if EOF handling is +- necessary */ +-int get_byte(ByteIOContext *s); +-unsigned int get_le24(ByteIOContext *s); +-unsigned int get_le32(ByteIOContext *s); +-uint64_t get_le64(ByteIOContext *s); +-unsigned int get_le16(ByteIOContext *s); ++/** ++ * Read a string from pb into buf. The reading will terminate when either ++ * a NULL character was encountered, maxlen bytes have been read, or nothing ++ * more can be read from pb. The result is guaranteed to be NULL-terminated, it ++ * will be truncated if buf is too small. ++ * Note that the string is not interpreted or validated in any way, it ++ * might get truncated in the middle of a sequence for multi-byte encodings. ++ * ++ * @return number of bytes read (is always <= maxlen). ++ * If reading ends on EOF or error, the return value will be one more than ++ * bytes actually read. ++ */ ++int avio_get_str(AVIOContext *pb, int maxlen, char *buf, int buflen); + + /** + * Read a UTF-16 string from pb and convert it to UTF-8. +@@ -466,136 +558,138 @@ + * encountered or maxlen bytes have been read. + * @return number of bytes read (is always <= maxlen) + */ +-int avio_get_str16le(ByteIOContext *pb, int maxlen, char *buf, int buflen); +-int avio_get_str16be(ByteIOContext *pb, int maxlen, char *buf, int buflen); ++int avio_get_str16le(AVIOContext *pb, int maxlen, char *buf, int buflen); ++int avio_get_str16be(AVIOContext *pb, int maxlen, char *buf, int buflen); + +-char *get_strz(ByteIOContext *s, char *buf, int maxlen); +-unsigned int get_be16(ByteIOContext *s); +-unsigned int get_be24(ByteIOContext *s); +-unsigned int get_be32(ByteIOContext *s); +-uint64_t get_be64(ByteIOContext *s); +- +-uint64_t ff_get_v(ByteIOContext *bc); +- +-static inline int url_is_streamed(ByteIOContext *s) +-{ +- return s->is_streamed; +-} + + /** +- * Create and initialize a ByteIOContext for accessing the +- * resource referenced by the URLContext h. +- * @note When the URLContext h has been opened in read+write mode, the +- * ByteIOContext can be used only for writing. +- * +- * @param s Used to return the pointer to the created ByteIOContext. +- * In case of failure the pointed to value is set to NULL. +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code in case of failure ++ * @name URL open modes ++ * The flags argument to avio_open must be one of the following ++ * constants, optionally ORed with other flags. ++ * @{ ++ */ ++#define AVIO_FLAG_READ 1 /**< read-only */ ++#define AVIO_FLAG_WRITE 2 /**< write-only */ ++#define AVIO_FLAG_READ_WRITE (AVIO_FLAG_READ|AVIO_FLAG_WRITE) /**< read-write pseudo flag */ ++/** ++ * @} + */ +-int url_fdopen(ByteIOContext **s, URLContext *h); +- +-/** @warning must be called before any I/O */ +-int url_setbufsize(ByteIOContext *s, int buf_size); +-#if FF_API_URL_RESETBUF +-/** Reset the buffer for reading or writing. +- * @note Will drop any data currently in the buffer without transmitting it. +- * @param flags URL_RDONLY to set up the buffer for reading, or URL_WRONLY +- * to set up the buffer for writing. */ +-int url_resetbuf(ByteIOContext *s, int flags); +-#endif + + /** +- * Rewind the ByteIOContext using the specified buffer containing the first buf_size bytes of the file. +- * Used after probing to avoid seeking. +- * Joins buf and s->buffer, taking any overlap into consideration. +- * @note s->buffer must overlap with buf or they can't be joined and the function fails +- * @note This function is NOT part of the public API +- * +- * @param s The read-only ByteIOContext to rewind +- * @param buf The probe buffer containing the first buf_size bytes of the file +- * @param buf_size The size of buf +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code in case of failure ++ * Use non-blocking mode. ++ * If this flag is set, operations on the context will return ++ * AVERROR(EAGAIN) if they can not be performed immediately. ++ * If this flag is not set, operations on the context will never return ++ * AVERROR(EAGAIN). ++ * Note that this flag does not affect the opening/connecting of the ++ * context. Connecting a protocol will always block if necessary (e.g. on ++ * network protocols) but never hang (e.g. on busy devices). ++ * Warning: non-blocking protocols is work-in-progress; this flag may be ++ * silently ignored. + */ +-int ff_rewind_with_probe_data(ByteIOContext *s, unsigned char *buf, int buf_size); ++#define AVIO_FLAG_NONBLOCK 8 + + /** +- * Create and initialize a ByteIOContext for accessing the ++ * Create and initialize a AVIOContext for accessing the + * resource indicated by url. + * @note When the resource indicated by url has been opened in +- * read+write mode, the ByteIOContext can be used only for writing. ++ * read+write mode, the AVIOContext can be used only for writing. + * +- * @param s Used to return the pointer to the created ByteIOContext. ++ * @param s Used to return the pointer to the created AVIOContext. + * In case of failure the pointed to value is set to NULL. + * @param flags flags which control how the resource indicated by url + * is to be opened + * @return 0 in case of success, a negative value corresponding to an + * AVERROR code in case of failure + */ +-int url_fopen(ByteIOContext **s, const char *url, int flags); +- +-int url_fclose(ByteIOContext *s); +-URLContext *url_fileno(ByteIOContext *s); ++int avio_open(AVIOContext **s, const char *url, int flags); + + /** +- * Return the maximum packet size associated to packetized buffered file +- * handle. If the file is not packetized (stream like http or file on +- * disk), then 0 is returned. ++ * Create and initialize a AVIOContext for accessing the ++ * resource indicated by url. ++ * @note When the resource indicated by url has been opened in ++ * read+write mode, the AVIOContext can be used only for writing. + * +- * @param s buffered file handle +- * @return maximum packet size in bytes ++ * @param s Used to return the pointer to the created AVIOContext. ++ * In case of failure the pointed to value is set to NULL. ++ * @param flags flags which control how the resource indicated by url ++ * is to be opened ++ * @param int_cb an interrupt callback to be used at the protocols level ++ * @param options A dictionary filled with protocol-private options. On return ++ * this parameter will be destroyed and replaced with a dict containing options ++ * that were not found. May be NULL. ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code in case of failure + */ +-int url_fget_max_packet_size(ByteIOContext *s); +- +-int url_open_buf(ByteIOContext **s, uint8_t *buf, int buf_size, int flags); +- +-/** return the written or read size */ +-int url_close_buf(ByteIOContext *s); ++int avio_open2(AVIOContext **s, const char *url, int flags, ++ const AVIOInterruptCB *int_cb, AVDictionary **options); + + /** +- * Open a write only memory stream. ++ * Close the resource accessed by the AVIOContext s and free it. ++ * This function can only be used if s was opened by avio_open(). + * +- * @param s new IO context +- * @return zero if no error. ++ * @return 0 on success, an AVERROR < 0 on error. + */ +-int url_open_dyn_buf(ByteIOContext **s); ++int avio_close(AVIOContext *s); + + /** +- * Open a write only packetized memory stream with a maximum packet +- * size of 'max_packet_size'. The stream is stored in a memory buffer +- * with a big endian 4 byte header giving the packet size in bytes. ++ * Open a write only memory stream. + * + * @param s new IO context +- * @param max_packet_size maximum packet size (must be > 0) + * @return zero if no error. + */ +-int url_open_dyn_packet_buf(ByteIOContext **s, int max_packet_size); ++int avio_open_dyn_buf(AVIOContext **s); + + /** + * Return the written size and a pointer to the buffer. The buffer +- * must be freed with av_free(). If the buffer is opened with +- * url_open_dyn_buf, then padding of FF_INPUT_BUFFER_PADDING_SIZE is +- * added; if opened with url_open_dyn_packet_buf, no padding is added. ++ * must be freed with av_free(). ++ * Padding of FF_INPUT_BUFFER_PADDING_SIZE is added to the buffer. + * + * @param s IO context + * @param pbuffer pointer to a byte buffer + * @return the length of the byte buffer + */ +-int url_close_dyn_buf(ByteIOContext *s, uint8_t **pbuffer); ++int avio_close_dyn_buf(AVIOContext *s, uint8_t **pbuffer); + +-unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, +- unsigned int len); +-unsigned long get_checksum(ByteIOContext *s); +-void init_checksum(ByteIOContext *s, +- unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), +- unsigned long checksum); ++/** ++ * Iterate through names of available protocols. ++ * @note it is recommanded to use av_protocol_next() instead of this ++ * ++ * @param opaque A private pointer representing current protocol. ++ * It must be a pointer to NULL on first iteration and will ++ * be updated by successive calls to avio_enum_protocols. ++ * @param output If set to 1, iterate over output protocols, ++ * otherwise over input protocols. ++ * ++ * @return A static string containing the name of current protocol or NULL ++ */ ++const char *avio_enum_protocols(void **opaque, int output); + +-/* udp.c */ +-int udp_set_remote_url(URLContext *h, const char *uri); +-int udp_get_local_port(URLContext *h); +-#if FF_API_UDP_GET_FILE +-int udp_get_file_handle(URLContext *h); +-#endif ++/** ++ * Pause and resume playing - only meaningful if using a network streaming ++ * protocol (e.g. MMS). ++ * @param pause 1 for pause, 0 for resume ++ */ ++int avio_pause(AVIOContext *h, int pause); ++ ++/** ++ * Seek to a given timestamp relative to some component stream. ++ * Only meaningful if using a network streaming protocol (e.g. MMS.). ++ * @param stream_index The stream index that the timestamp is relative to. ++ * If stream_index is (-1) the timestamp should be in AV_TIME_BASE ++ * units from the beginning of the presentation. ++ * If a stream_index >= 0 is used and the protocol does not support ++ * seeking based on component streams, the call will fail. ++ * @param timestamp timestamp in AVStream.time_base units ++ * or if there is no stream specified then in AV_TIME_BASE units. ++ * @param flags Optional combination of AVSEEK_FLAG_BACKWARD, AVSEEK_FLAG_BYTE ++ * and AVSEEK_FLAG_ANY. The protocol may silently ignore ++ * AVSEEK_FLAG_BACKWARD and AVSEEK_FLAG_ANY, but AVSEEK_FLAG_BYTE will ++ * fail if used and not supported. ++ * @return >= 0 on success ++ * @see AVInputFormat::read_seek ++ */ ++int64_t avio_seek_time(AVIOContext *h, int stream_index, ++ int64_t timestamp, int flags); + + #endif /* AVFORMAT_AVIO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avio_internal.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avio_internal.h 2012-05-14 14:08:54.912351615 +0200 +@@ -0,0 +1,107 @@ ++/* ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFORMAT_AVIO_INTERNAL_H ++#define AVFORMAT_AVIO_INTERNAL_H ++ ++#include "avio.h" ++#include "url.h" ++ ++#include "libavutil/log.h" ++ ++extern const AVClass ffio_url_class; ++ ++int ffio_init_context(AVIOContext *s, ++ unsigned char *buffer, ++ int buffer_size, ++ int write_flag, ++ void *opaque, ++ int (*read_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int (*write_packet)(void *opaque, uint8_t *buf, int buf_size), ++ int64_t (*seek)(void *opaque, int64_t offset, int whence)); ++ ++ ++/** ++ * Read size bytes from AVIOContext into buf. ++ * This reads at most 1 packet. If that is not enough fewer bytes will be ++ * returned. ++ * @return number of bytes read or AVERROR ++ */ ++int ffio_read_partial(AVIOContext *s, unsigned char *buf, int size); ++ ++void ffio_fill(AVIOContext *s, int b, int count); ++ ++static av_always_inline void ffio_wfourcc(AVIOContext *pb, const uint8_t *s) ++{ ++ avio_wl32(pb, MKTAG(s[0], s[1], s[2], s[3])); ++} ++ ++/** ++ * Rewind the AVIOContext using the specified buffer containing the first buf_size bytes of the file. ++ * Used after probing to avoid seeking. ++ * Joins buf and s->buffer, taking any overlap into consideration. ++ * @note s->buffer must overlap with buf or they can't be joined and the function fails ++ * ++ * @param s The read-only AVIOContext to rewind ++ * @param buf The probe buffer containing the first buf_size bytes of the file ++ * @param buf_size The size of buf ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code in case of failure ++ */ ++int ffio_rewind_with_probe_data(AVIOContext *s, unsigned char *buf, int buf_size); ++ ++uint64_t ffio_read_varlen(AVIOContext *bc); ++ ++/** @warning must be called before any I/O */ ++int ffio_set_buf_size(AVIOContext *s, int buf_size); ++ ++int ffio_limit(AVIOContext *s, int size); ++ ++void ffio_init_checksum(AVIOContext *s, ++ unsigned long (*update_checksum)(unsigned long c, const uint8_t *p, unsigned int len), ++ unsigned long checksum); ++unsigned long ffio_get_checksum(AVIOContext *s); ++unsigned long ff_crc04C11DB7_update(unsigned long checksum, const uint8_t *buf, ++ unsigned int len); ++ ++/** ++ * Open a write only packetized memory stream with a maximum packet ++ * size of 'max_packet_size'. The stream is stored in a memory buffer ++ * with a big endian 4 byte header giving the packet size in bytes. ++ * ++ * @param s new IO context ++ * @param max_packet_size maximum packet size (must be > 0) ++ * @return zero if no error. ++ */ ++int ffio_open_dyn_packet_buf(AVIOContext **s, int max_packet_size); ++ ++/** ++ * Create and initialize a AVIOContext for accessing the ++ * resource referenced by the URLContext h. ++ * @note When the URLContext h has been opened in read+write mode, the ++ * AVIOContext can be used only for writing. ++ * ++ * @param s Used to return the pointer to the created AVIOContext. ++ * In case of failure the pointed to value is set to NULL. ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code in case of failure ++ */ ++int ffio_fdopen(AVIOContext **s, URLContext *h); ++ ++#endif /* AVFORMAT_AVIO_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avisynth.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avisynth.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avisynth.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avisynth.c 2012-05-14 14:08:54.917351715 +0200 +@@ -1,5 +1,5 @@ + /* +- * AVISynth support for ffmpeg system ++ * AVISynth support + * Copyright (c) 2006 DivX, Inc. + * + * This file is part of FFmpeg. +@@ -20,6 +20,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + + #include +@@ -84,7 +85,8 @@ + if (AVIStreamReadFormat(stream->handle, 0, &wvfmt, &struct_size) != S_OK) + continue; + +- st = av_new_stream(s, id); ++ st = avformat_new_stream(s, NULL); ++ st->id = id; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + + st->codec->block_align = wvfmt.nBlockAlign; +@@ -110,7 +112,8 @@ + if (AVIStreamReadFormat(stream->handle, 0, &imgfmt, &struct_size) != S_OK) + continue; + +- st = av_new_stream(s, id); ++ st = avformat_new_stream(s, NULL); ++ st->id = id; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->r_frame_rate.num = stream->info.dwRate; + st->r_frame_rate.den = stream->info.dwScale; +@@ -122,6 +125,14 @@ + st->codec->bit_rate = (uint64_t)stream->info.dwSampleSize * (uint64_t)stream->info.dwRate * 8 / (uint64_t)stream->info.dwScale; + st->codec->codec_tag = imgfmt.bmiHeader.biCompression; + st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, imgfmt.bmiHeader.biCompression); ++ if (st->codec->codec_id == CODEC_ID_RAWVIDEO && imgfmt.bmiHeader.biCompression== BI_RGB) { ++ st->codec->extradata = av_malloc(9 + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (st->codec->extradata) { ++ st->codec->extradata_size = 9; ++ memcpy(st->codec->extradata, "BottomUp", 9); ++ } ++ } ++ + + st->duration = stream->info.dwLength; + } +@@ -135,7 +146,7 @@ + + st->codec->stream_codec_tag = stream->info.fccHandler; + +- av_set_pts_info(st, 64, info.dwScale, info.dwRate); ++ avpriv_set_pts_info(st, 64, info.dwScale, info.dwRate); + st->start_time = stream->info.dwStart; + } + } +@@ -165,7 +176,6 @@ + + res = AVIStreamRead(stream->handle, stream->read, stream->chunck_samples, pkt->data, stream->chunck_size, &read_size, NULL); + +- pkt->pts = stream->read; + pkt->size = read_size; + + stream->read += stream->chunck_samples; +@@ -208,15 +218,12 @@ + } + + AVInputFormat ff_avisynth_demuxer = { +- "avs", +- NULL_IF_CONFIG_SMALL("AVISynth"), +- sizeof(AVISynthContext), +- NULL, +- avisynth_read_header, +- avisynth_read_packet, +- avisynth_read_close, +- avisynth_read_seek, +- NULL, +- 0, +- "avs", ++ .name = "avs", ++ .long_name = NULL_IF_CONFIG_SMALL("AVISynth"), ++ .priv_data_size = sizeof(AVISynthContext), ++ .read_header = avisynth_read_header, ++ .read_packet = avisynth_read_packet, ++ .read_close = avisynth_read_close, ++ .read_seek = avisynth_read_seek, ++ .extensions = "avs", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avlanguage.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avlanguage.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avlanguage.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avlanguage.c 2012-05-14 14:08:54.918351735 +0200 +@@ -20,6 +20,7 @@ + + #include "avlanguage.h" + #include "libavutil/avstring.h" ++#include "libavutil/common.h" + #include + #include + #include +@@ -736,7 +737,7 @@ + { + int i; + const LangEntry *entry = NULL; +- const int NB_CODESPACES = sizeof(lang_table_counts)/sizeof(*lang_table_counts); ++ const int NB_CODESPACES = FF_ARRAY_ELEMS(lang_table_counts); + + if (target_codespace >= NB_CODESPACES) + return NULL; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avs.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avs.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/avs.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/avs.c 2012-05-14 14:08:54.918351735 +0200 +@@ -61,12 +61,12 @@ + + s->ctx_flags |= AVFMTCTX_NOHEADER; + +- url_fskip(s->pb, 4); +- avs->width = get_le16(s->pb); +- avs->height = get_le16(s->pb); +- avs->bits_per_sample = get_le16(s->pb); +- avs->fps = get_le16(s->pb); +- avs->nb_frames = get_le32(s->pb); ++ avio_skip(s->pb, 4); ++ avs->width = avio_rl16(s->pb); ++ avs->height = avio_rl16(s->pb); ++ avs->bits_per_sample = avio_rl16(s->pb); ++ avs->fps = avio_rl16(s->pb); ++ avs->nb_frames = avio_rl32(s->pb); + avs->remaining_frame_size = 0; + avs->remaining_audio_size = 0; + +@@ -104,7 +104,7 @@ + pkt->data[palette_size + 1] = type; + pkt->data[palette_size + 2] = size & 0xFF; + pkt->data[palette_size + 3] = (size >> 8) & 0xFF; +- ret = get_buffer(s->pb, pkt->data + palette_size + 4, size - 4) + 4; ++ ret = avio_read(s->pb, pkt->data + palette_size + 4, size - 4) + 4; + if (ret < size) { + av_free_packet(pkt); + return AVERROR(EIO); +@@ -123,9 +123,9 @@ + AvsFormat *avs = s->priv_data; + int ret, size; + +- size = url_ftell(s->pb); ++ size = avio_tell(s->pb); + ret = voc_get_packet(s, pkt, avs->st_audio, avs->remaining_audio_size); +- size = url_ftell(s->pb) - size; ++ size = avio_tell(s->pb) - size; + avs->remaining_audio_size -= size; + + if (ret == AVERROR(EIO)) +@@ -154,20 +154,24 @@ + + while (1) { + if (avs->remaining_frame_size <= 0) { +- if (!get_le16(s->pb)) /* found EOF */ ++ if (!avio_rl16(s->pb)) /* found EOF */ + return AVERROR(EIO); +- avs->remaining_frame_size = get_le16(s->pb) - 4; ++ avs->remaining_frame_size = avio_rl16(s->pb) - 4; + } + + while (avs->remaining_frame_size > 0) { +- sub_type = get_byte(s->pb); +- type = get_byte(s->pb); +- size = get_le16(s->pb); ++ sub_type = avio_r8(s->pb); ++ type = avio_r8(s->pb); ++ size = avio_rl16(s->pb); ++ if (size < 4) ++ return AVERROR_INVALIDDATA; + avs->remaining_frame_size -= size; + + switch (type) { + case AVS_PALETTE: +- ret = get_buffer(s->pb, palette, size - 4); ++ if (size - 4 > sizeof(palette)) ++ return AVERROR_INVALIDDATA; ++ ret = avio_read(s->pb, palette, size - 4); + if (ret < size - 4) + return AVERROR(EIO); + palette_size = size; +@@ -175,7 +179,7 @@ + + case AVS_VIDEO: + if (!avs->st_video) { +- avs->st_video = av_new_stream(s, AVS_VIDEO); ++ avs->st_video = avformat_new_stream(s, NULL); + if (avs->st_video == NULL) + return AVERROR(ENOMEM); + avs->st_video->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -192,7 +196,7 @@ + + case AVS_AUDIO: + if (!avs->st_audio) { +- avs->st_audio = av_new_stream(s, AVS_AUDIO); ++ avs->st_audio = avformat_new_stream(s, NULL); + if (avs->st_audio == NULL) + return AVERROR(ENOMEM); + avs->st_audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -204,7 +208,7 @@ + break; + + default: +- url_fskip(s->pb, size - 4); ++ avio_skip(s->pb, size - 4); + } + } + } +@@ -216,11 +220,11 @@ + } + + AVInputFormat ff_avs_demuxer = { +- "avs", +- NULL_IF_CONFIG_SMALL("AVS format"), +- sizeof(AvsFormat), +- avs_probe, +- avs_read_header, +- avs_read_packet, +- avs_read_close, ++ .name = "avs", ++ .long_name = NULL_IF_CONFIG_SMALL("AVS format"), ++ .priv_data_size = sizeof(AvsFormat), ++ .read_probe = avs_probe, ++ .read_header = avs_read_header, ++ .read_packet = avs_read_packet, ++ .read_close = avs_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bethsoftvid.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bethsoftvid.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bethsoftvid.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bethsoftvid.c 2012-05-14 14:08:54.920351775 +0200 +@@ -23,12 +23,13 @@ + * @file + * @brief Bethesda Softworks VID (.vid) file demuxer + * @author Nicholas Tung [ntung (at. ntung com] (2007-03) +- * @sa http://wiki.multimedia.cx/index.php?title=Bethsoft_VID +- * @sa http://www.svatopluk.com/andux/docs/dfvid.html ++ * @see http://wiki.multimedia.cx/index.php?title=Bethsoft_VID ++ * @see http://www.svatopluk.com/andux/docs/dfvid.html + */ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "libavcodec/bethsoftvideo.h" + + typedef struct BVID_DemuxContext +@@ -60,30 +61,30 @@ + AVFormatParameters *ap) + { + BVID_DemuxContext *vid = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *stream; + + /* load main header. Contents: + * bytes: 'V' 'I' 'D' + * int16s: always_512, nframes, width, height, delay, always_14 + */ +- url_fseek(pb, 5, SEEK_CUR); +- vid->nframes = get_le16(pb); ++ avio_skip(pb, 5); ++ vid->nframes = avio_rl16(pb); + +- stream = av_new_stream(s, 0); ++ stream = avformat_new_stream(s, NULL); + if (!stream) + return AVERROR(ENOMEM); +- av_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps ++ avpriv_set_pts_info(stream, 32, 1, 60); // 16 ms increments, i.e. 60 fps + stream->codec->codec_type = AVMEDIA_TYPE_VIDEO; + stream->codec->codec_id = CODEC_ID_BETHSOFTVID; +- stream->codec->width = get_le16(pb); +- stream->codec->height = get_le16(pb); ++ stream->codec->width = avio_rl16(pb); ++ stream->codec->height = avio_rl16(pb); + stream->codec->pix_fmt = PIX_FMT_PAL8; +- vid->bethsoft_global_delay = get_le16(pb); +- get_le16(pb); ++ vid->bethsoft_global_delay = avio_rl16(pb); ++ avio_rl16(pb); + + // done with video codec, set up audio codec +- stream = av_new_stream(s, 0); ++ stream = avformat_new_stream(s, NULL); + if (!stream) + return AVERROR(ENOMEM); + stream->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -97,7 +98,7 @@ + } + + #define BUFFER_PADDING_SIZE 1000 +-static int read_frame(BVID_DemuxContext *vid, ByteIOContext *pb, AVPacket *pkt, ++static int read_frame(BVID_DemuxContext *vid, AVIOContext *pb, AVPacket *pkt, + uint8_t block_type, AVFormatContext *s, int npixels) + { + uint8_t * vidbuf_start = NULL; +@@ -112,16 +113,16 @@ + return AVERROR(ENOMEM); + + // save the file position for the packet, include block type +- position = url_ftell(pb) - 1; ++ position = avio_tell(pb) - 1; + + vidbuf_start[vidbuf_nbytes++] = block_type; + + // get the video delay (next int16), and set the presentation time +- vid->video_pts += vid->bethsoft_global_delay + get_le16(pb); ++ vid->video_pts += vid->bethsoft_global_delay + avio_rl16(pb); + + // set the y offset if it exists (decoder header data should be in data section) + if(block_type == VIDEO_YOFF_P_FRAME){ +- if(get_buffer(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) ++ if(avio_read(pb, &vidbuf_start[vidbuf_nbytes], 2) != 2) + goto fail; + vidbuf_nbytes += 2; + } +@@ -131,22 +132,22 @@ + if(!vidbuf_start) + return AVERROR(ENOMEM); + +- code = get_byte(pb); ++ code = avio_r8(pb); + vidbuf_start[vidbuf_nbytes++] = code; + + if(code >= 0x80){ // rle sequence + if(block_type == VIDEO_I_FRAME) +- vidbuf_start[vidbuf_nbytes++] = get_byte(pb); ++ vidbuf_start[vidbuf_nbytes++] = avio_r8(pb); + } else if(code){ // plain sequence +- if(get_buffer(pb, &vidbuf_start[vidbuf_nbytes], code) != code) ++ if(avio_read(pb, &vidbuf_start[vidbuf_nbytes], code) != code) + goto fail; + vidbuf_nbytes += code; + } + bytes_copied += code & 0x7F; + if(bytes_copied == npixels){ // sometimes no stop character is given, need to keep track of bytes copied + // may contain a 0 byte even if read all pixels +- if(get_byte(pb)) +- url_fseek(pb, -1, SEEK_CUR); ++ if(avio_r8(pb)) ++ avio_seek(pb, -1, SEEK_CUR); + break; + } + if(bytes_copied > npixels) +@@ -174,7 +175,7 @@ + AVPacket *pkt) + { + BVID_DemuxContext *vid = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned char block_type; + int audio_length; + int ret_value; +@@ -182,10 +183,10 @@ + if(vid->is_finished || url_feof(pb)) + return AVERROR(EIO); + +- block_type = get_byte(pb); ++ block_type = avio_r8(pb); + switch(block_type){ + case PALETTE_BLOCK: +- url_fseek(pb, -1, SEEK_CUR); // include block type ++ avio_seek(pb, -1, SEEK_CUR); // include block type + ret_value = av_get_packet(pb, pkt, 3 * 256 + 1); + if(ret_value != 3 * 256 + 1){ + av_free_packet(pkt); +@@ -195,12 +196,12 @@ + return ret_value; + + case FIRST_AUDIO_BLOCK: +- get_le16(pb); ++ avio_rl16(pb); + // soundblaster DAC used for sample rate, as on specification page (link above) +- s->streams[1]->codec->sample_rate = 1000000 / (256 - get_byte(pb)); ++ s->streams[1]->codec->sample_rate = 1000000 / (256 - avio_r8(pb)); + s->streams[1]->codec->bit_rate = s->streams[1]->codec->channels * s->streams[1]->codec->sample_rate * s->streams[1]->codec->bits_per_coded_sample; + case AUDIO_BLOCK: +- audio_length = get_le16(pb); ++ audio_length = avio_rl16(pb); + ret_value = av_get_packet(pb, pkt, audio_length); + pkt->stream_index = 1; + return ret_value != audio_length ? AVERROR(EIO) : ret_value; +@@ -220,15 +221,13 @@ + av_log(s, AV_LOG_ERROR, "unknown block (character = %c, decimal = %d, hex = %x)!!!\n", + block_type, block_type, block_type); return -1; + } +- +- return 0; + } + + AVInputFormat ff_bethsoftvid_demuxer = { +- "bethsoftvid", +- NULL_IF_CONFIG_SMALL("Bethesda Softworks VID format"), +- sizeof(BVID_DemuxContext), +- vid_probe, +- vid_read_header, +- vid_read_packet, ++ .name = "bethsoftvid", ++ .long_name = NULL_IF_CONFIG_SMALL("Bethesda Softworks VID format"), ++ .priv_data_size = sizeof(BVID_DemuxContext), ++ .read_probe = vid_probe, ++ .read_header = vid_read_header, ++ .read_packet = vid_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bfi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bfi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bfi.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bfi.c 2012-05-14 14:08:54.920351775 +0200 +@@ -23,11 +23,12 @@ + * @file + * @brief Brute Force & Ignorance (.bfi) file demuxer + * @author Sisir Koppaka ( sisir.koppaka at gmail dot com ) +- * @sa http://wiki.multimedia.cx/index.php?title=BFI ++ * @see http://wiki.multimedia.cx/index.php?title=BFI + */ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + typedef struct BFIContext { + int nframes; +@@ -49,44 +50,44 @@ + static int bfi_read_header(AVFormatContext * s, AVFormatParameters * ap) + { + BFIContext *bfi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *vstream; + AVStream *astream; + int fps, chunk_header; + + /* Initialize the video codec... */ +- vstream = av_new_stream(s, 0); ++ vstream = avformat_new_stream(s, NULL); + if (!vstream) + return AVERROR(ENOMEM); + + /* Initialize the audio codec... */ +- astream = av_new_stream(s, 0); ++ astream = avformat_new_stream(s, NULL); + if (!astream) + return AVERROR(ENOMEM); + + /* Set the total number of frames. */ +- url_fskip(pb, 8); +- chunk_header = get_le32(pb); +- bfi->nframes = get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- get_le32(pb); +- fps = get_le32(pb); +- url_fskip(pb, 12); +- vstream->codec->width = get_le32(pb); +- vstream->codec->height = get_le32(pb); ++ avio_skip(pb, 8); ++ chunk_header = avio_rl32(pb); ++ bfi->nframes = avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ avio_rl32(pb); ++ fps = avio_rl32(pb); ++ avio_skip(pb, 12); ++ vstream->codec->width = avio_rl32(pb); ++ vstream->codec->height = avio_rl32(pb); + + /*Load the palette to extradata */ +- url_fskip(pb, 8); ++ avio_skip(pb, 8); + vstream->codec->extradata = av_malloc(768); + vstream->codec->extradata_size = 768; +- get_buffer(pb, vstream->codec->extradata, ++ avio_read(pb, vstream->codec->extradata, + vstream->codec->extradata_size); + +- astream->codec->sample_rate = get_le32(pb); ++ astream->codec->sample_rate = avio_rl32(pb); + + /* Set up the video codec... */ +- av_set_pts_info(vstream, 32, 1, fps); ++ avpriv_set_pts_info(vstream, 32, 1, fps); + vstream->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vstream->codec->codec_id = CODEC_ID_BFI; + vstream->codec->pix_fmt = PIX_FMT_PAL8; +@@ -98,8 +99,8 @@ + astream->codec->bits_per_coded_sample = 8; + astream->codec->bit_rate = + astream->codec->sample_rate * astream->codec->bits_per_coded_sample; +- url_fseek(pb, chunk_header - 3, SEEK_SET); +- av_set_pts_info(astream, 64, 1, astream->codec->sample_rate); ++ avio_seek(pb, chunk_header - 3, SEEK_SET); ++ avpriv_set_pts_info(astream, 64, 1, astream->codec->sample_rate); + return 0; + } + +@@ -107,7 +108,7 @@ + static int bfi_read_packet(AVFormatContext * s, AVPacket * pkt) + { + BFIContext *bfi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret, audio_offset, video_offset, chunk_size, audio_size = 0; + if (bfi->nframes == 0 || url_feof(pb)) { + return AVERROR(EIO); +@@ -119,14 +120,14 @@ + while(state != MKTAG('S','A','V','I')){ + if (url_feof(pb)) + return AVERROR(EIO); +- state = 256*state + get_byte(pb); ++ state = 256*state + avio_r8(pb); + } + /* Now that the chunk's location is confirmed, we proceed... */ +- chunk_size = get_le32(pb); +- get_le32(pb); +- audio_offset = get_le32(pb); +- get_le32(pb); +- video_offset = get_le32(pb); ++ chunk_size = avio_rl32(pb); ++ avio_rl32(pb); ++ audio_offset = avio_rl32(pb); ++ avio_rl32(pb); ++ video_offset = avio_rl32(pb); + audio_size = video_offset - audio_offset; + bfi->video_size = chunk_size - video_offset; + +@@ -159,10 +160,10 @@ + } + + AVInputFormat ff_bfi_demuxer = { +- "bfi", +- NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"), +- sizeof(BFIContext), +- bfi_probe, +- bfi_read_header, +- bfi_read_packet, ++ .name = "bfi", ++ .long_name = NULL_IF_CONFIG_SMALL("Brute Force & Ignorance"), ++ .priv_data_size = sizeof(BFIContext), ++ .read_probe = bfi_probe, ++ .read_header = bfi_read_header, ++ .read_packet = bfi_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bink.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bink.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bink.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bink.c 2012-05-14 14:08:54.922351816 +0200 +@@ -30,6 +30,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + enum BinkAudFlags { + BINK_AUD_16BITS = 0x4000, ///< prefer 16-bit output +@@ -70,7 +71,7 @@ + static int read_header(AVFormatContext *s, AVFormatParameters *ap) + { + BinkDemuxContext *bink = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint32_t fps_num, fps_den; + AVStream *vst, *ast; + unsigned int i; +@@ -78,46 +79,46 @@ + uint16_t flags; + int keyframe; + +- vst = av_new_stream(s, 0); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + +- vst->codec->codec_tag = get_le32(pb); ++ vst->codec->codec_tag = avio_rl32(pb); + +- bink->file_size = get_le32(pb) + 8; +- vst->duration = get_le32(pb); ++ bink->file_size = avio_rl32(pb) + 8; ++ vst->duration = avio_rl32(pb); + + if (vst->duration > 1000000) { + av_log(s, AV_LOG_ERROR, "invalid header: more than 1000000 frames\n"); + return AVERROR(EIO); + } + +- if (get_le32(pb) > bink->file_size) { ++ if (avio_rl32(pb) > bink->file_size) { + av_log(s, AV_LOG_ERROR, + "invalid header: largest frame size greater than file size\n"); + return AVERROR(EIO); + } + +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + +- vst->codec->width = get_le32(pb); +- vst->codec->height = get_le32(pb); ++ vst->codec->width = avio_rl32(pb); ++ vst->codec->height = avio_rl32(pb); + +- fps_num = get_le32(pb); +- fps_den = get_le32(pb); ++ fps_num = avio_rl32(pb); ++ fps_den = avio_rl32(pb); + if (fps_num == 0 || fps_den == 0) { + av_log(s, AV_LOG_ERROR, "invalid header: invalid fps (%d/%d)\n", fps_num, fps_den); + return AVERROR(EIO); + } +- av_set_pts_info(vst, 64, fps_den, fps_num); ++ avpriv_set_pts_info(vst, 64, fps_den, fps_num); + + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_BINKVIDEO; + vst->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); + vst->codec->extradata_size = 4; +- get_buffer(pb, vst->codec->extradata, 4); ++ avio_read(pb, vst->codec->extradata, 4); + +- bink->num_audio_tracks = get_le32(pb); ++ bink->num_audio_tracks = avio_rl32(pb); + + if (bink->num_audio_tracks > BINK_MAX_AUDIO_TRACKS) { + av_log(s, AV_LOG_ERROR, +@@ -127,34 +128,40 @@ + } + + if (bink->num_audio_tracks) { +- url_fskip(pb, 4 * bink->num_audio_tracks); ++ avio_skip(pb, 4 * bink->num_audio_tracks); + + for (i = 0; i < bink->num_audio_tracks; i++) { +- ast = av_new_stream(s, 1); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codec->codec_tag = 0; +- ast->codec->sample_rate = get_le16(pb); +- av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); +- flags = get_le16(pb); ++ ast->codec->sample_rate = avio_rl16(pb); ++ avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); ++ flags = avio_rl16(pb); + ast->codec->codec_id = flags & BINK_AUD_USEDCT ? + CODEC_ID_BINKAUDIO_DCT : CODEC_ID_BINKAUDIO_RDFT; + ast->codec->channels = flags & BINK_AUD_STEREO ? 2 : 1; ++ ast->codec->extradata = av_mallocz(4 + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!ast->codec->extradata) ++ return AVERROR(ENOMEM); ++ ast->codec->extradata_size = 4; ++ AV_WL32(ast->codec->extradata, vst->codec->codec_tag); + } + +- url_fskip(pb, 4 * bink->num_audio_tracks); ++ for (i = 0; i < bink->num_audio_tracks; i++) ++ s->streams[i + 1]->id = avio_rl32(pb); + } + + /* frame index table */ +- next_pos = get_le32(pb); ++ next_pos = avio_rl32(pb); + for (i = 0; i < vst->duration; i++) { + pos = next_pos; + if (i == vst->duration - 1) { + next_pos = bink->file_size; + keyframe = 0; + } else { +- next_pos = get_le32(pb); ++ next_pos = avio_rl32(pb); + keyframe = pos & 1; + } + pos &= ~1; +@@ -168,7 +175,7 @@ + keyframe ? AVINDEX_KEYFRAME : 0); + } + +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + + bink->current_track = -1; + return 0; +@@ -177,7 +184,7 @@ + static int read_packet(AVFormatContext *s, AVPacket *pkt) + { + BinkDemuxContext *bink = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret; + + if (bink->current_track < 0) { +@@ -201,7 +208,7 @@ + } + + while (bink->current_track < bink->num_audio_tracks) { +- uint32_t audio_size = get_le32(pb); ++ uint32_t audio_size = avio_rl32(pb); + if (audio_size > bink->remain_packet_size - 4) { + av_log(s, AV_LOG_ERROR, + "frame %"PRId64": audio size in header (%u) > size of packet left (%u)\n", +@@ -224,7 +231,7 @@ + AV_RL32(pkt->data) / (2 * s->streams[bink->current_track]->codec->channels); + return 0; + } else { +- url_fseek(pb, audio_size, SEEK_CUR); ++ avio_skip(pb, audio_size); + } + } + +@@ -246,11 +253,13 @@ + BinkDemuxContext *bink = s->priv_data; + AVStream *vst = s->streams[0]; + +- if (url_is_streamed(s->pb)) ++ if (!s->pb->seekable) + return -1; + + /* seek to the first frame */ +- url_fseek(s->pb, vst->index_entries[0].pos, SEEK_SET); ++ if (avio_seek(s->pb, vst->index_entries[0].pos, SEEK_SET) < 0) ++ return -1; ++ + bink->video_pts = 0; + memset(bink->audio_pts, 0, sizeof(bink->audio_pts)); + bink->current_track = -1; +@@ -258,12 +267,11 @@ + } + + AVInputFormat ff_bink_demuxer = { +- "bink", +- NULL_IF_CONFIG_SMALL("Bink"), +- sizeof(BinkDemuxContext), +- probe, +- read_header, +- read_packet, +- NULL, +- read_seek, ++ .name = "bink", ++ .long_name = NULL_IF_CONFIG_SMALL("Bink"), ++ .priv_data_size = sizeof(BinkDemuxContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_seek = read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bintext.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bintext.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bintext.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bintext.c 2012-05-14 14:08:54.923351837 +0200 +@@ -0,0 +1,376 @@ ++/* ++ * Binary text demuxer ++ * eXtended BINary text (XBIN) demuxer ++ * Artworx Data Format demuxer ++ * iCEDraw File demuxer ++ * Copyright (c) 2010 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Binary text demuxer ++ * eXtended BINary text (XBIN) demuxer ++ * Artworx Data Format demuxer ++ * iCEDraw File demuxer ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++#include "sauce.h" ++#include "libavcodec/bintext.h" ++ ++#define LINE_RATE 6000 /** characters per second */ ++ ++typedef struct { ++ int chars_per_frame; ++ uint64_t fsize; /**< file size less metadata buffer */ ++} BinDemuxContext; ++ ++#if CONFIG_BINTEXT_DEMUXER | CONFIG_ADF_DEMUXER | CONFIG_IDF_DEMUXER ++/** ++ * Given filesize and width, calculate height (assume font_height of 16) ++ */ ++static void calculate_height(AVCodecContext *avctx, uint64_t fsize) ++{ ++ avctx->height = (fsize / ((avctx->width>>3)*2)) << 4; ++} ++#endif ++ ++#if CONFIG_BINTEXT_DEMUXER ++static const uint8_t next_magic[]={ ++ 0x1A, 0x1B, '[', '0', ';', '3', '0', ';', '4', '0', 'm', 'N', 'E', 'X', 'T', 0x00 ++}; ++ ++static int next_tag_read(AVFormatContext *avctx, uint64_t *fsize) ++{ ++ AVIOContext *pb = avctx->pb; ++ char buf[36]; ++ int len; ++ uint64_t start_pos = avio_size(pb) - 256; ++ ++ avio_seek(pb, start_pos, SEEK_SET); ++ if (avio_read(pb, buf, sizeof(next_magic)) != sizeof(next_magic)) ++ return -1; ++ if (memcmp(buf, next_magic, sizeof(next_magic))) ++ return -1; ++ if (avio_r8(pb) != 0x01) ++ return -1; ++ ++ *fsize -= 256; ++ ++#define GET_EFI2_META(name,size) \ ++ len = avio_r8(pb); \ ++ if (len < 1 || len > size) \ ++ return -1; \ ++ if (avio_read(pb, buf, size) == size && *buf) { \ ++ buf[len] = 0; \ ++ av_dict_set(&avctx->metadata, name, buf, 0); \ ++ } ++ ++ GET_EFI2_META("filename", 12) ++ GET_EFI2_META("author", 20) ++ GET_EFI2_META("publisher", 20) ++ GET_EFI2_META("title", 35) ++ ++ return 0; ++} ++ ++static void predict_width(AVCodecContext *avctx, uint64_t fsize, int got_width) ++{ ++ /** attempt to guess width */ ++ if (!got_width) ++ avctx->width = fsize > 4000 ? (160<<3) : (80<<3); ++} ++ ++static AVStream * init_stream(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ AVStream *st = avformat_new_stream(s, NULL); ++ if (!st) ++ return NULL; ++ st->codec->codec_tag = 0; ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ ++ if (!ap->time_base.num) { ++ avpriv_set_pts_info(st, 60, 1, 25); ++ } else { ++ avpriv_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); ++ } ++ ++ /* simulate tty display speed */ ++ bin->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1); ++ ++ st->codec->width = ap->width ? ap->width : (80<<3); ++ st->codec->height = ap->height ? ap->height : (25<<4); ++ return st; ++} ++ ++static int bintext_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ++ AVStream *st = init_stream(s, ap); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->codec->codec_id = CODEC_ID_BINTEXT; ++ ++ st->codec->extradata_size = 2; ++ st->codec->extradata = av_malloc(st->codec->extradata_size); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ st->codec->extradata[0] = 16; ++ st->codec->extradata[1] = 0; ++ ++ if (pb->seekable) { ++ int got_width = 0; ++ bin->fsize = avio_size(pb); ++ if (ff_sauce_read(s, &bin->fsize, &got_width, 0) < 0) ++ next_tag_read(s, &bin->fsize); ++ if (!ap->width) ++ predict_width(st->codec, bin->fsize, got_width); ++ if (!ap->height) ++ calculate_height(st->codec, bin->fsize); ++ avio_seek(pb, 0, SEEK_SET); ++ } ++ return 0; ++}; ++#endif /* CONFIG_BINTEXT_DEMUXER */ ++ ++#if CONFIG_XBIN_DEMUXER ++static int xbin_probe(AVProbeData *p) ++{ ++ const uint8_t *d = p->buf; ++ ++ if (AV_RL32(d) == MKTAG('X','B','I','N') && d[4] == 0x1A && ++ AV_RL16(d+5) > 0 && AV_RL16(d+5) <= 160 && ++ d[9] > 0 && d[9] <= 32) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int xbin_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ AVIOContext *pb = s->pb; ++ char fontheight, flags; ++ ++ AVStream *st = init_stream(s, ap); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ avio_skip(pb, 5); ++ st->codec->width = avio_rl16(pb)<<3; ++ st->codec->height = avio_rl16(pb); ++ fontheight = avio_r8(pb); ++ st->codec->height *= fontheight; ++ flags = avio_r8(pb); ++ ++ st->codec->extradata_size = 2; ++ if ((flags & BINTEXT_PALETTE)) ++ st->codec->extradata_size += 48; ++ if ((flags & BINTEXT_FONT)) ++ st->codec->extradata_size += fontheight * (flags & 0x10 ? 512 : 256); ++ st->codec->codec_id = flags & 4 ? CODEC_ID_XBIN : CODEC_ID_BINTEXT; ++ ++ st->codec->extradata = av_malloc(st->codec->extradata_size); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ st->codec->extradata[0] = fontheight; ++ st->codec->extradata[1] = flags; ++ if (avio_read(pb, st->codec->extradata + 2, st->codec->extradata_size - 2) < 0) ++ return AVERROR(EIO); ++ ++ if (pb->seekable) { ++ bin->fsize = avio_size(pb) - 9 - st->codec->extradata_size; ++ ff_sauce_read(s, &bin->fsize, NULL, 0); ++ avio_seek(pb, 9 + st->codec->extradata_size, SEEK_SET); ++ } ++ ++ return 0; ++} ++#endif /* CONFIG_XBIN_DEMUXER */ ++ ++#if CONFIG_ADF_DEMUXER ++static int adf_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ ++ if (avio_r8(pb) != 1) ++ return AVERROR_INVALIDDATA; ++ ++ st = init_stream(s, ap); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->codec->codec_id = CODEC_ID_BINTEXT; ++ ++ st->codec->extradata_size = 2 + 48 + 4096; ++ st->codec->extradata = av_malloc(st->codec->extradata_size); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ st->codec->extradata[0] = 16; ++ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; ++ ++ if (avio_read(pb, st->codec->extradata + 2, 24) < 0) ++ return AVERROR(EIO); ++ avio_skip(pb, 144); ++ if (avio_read(pb, st->codec->extradata + 2 + 24, 24) < 0) ++ return AVERROR(EIO); ++ if (avio_read(pb, st->codec->extradata + 2 + 48, 4096) < 0) ++ return AVERROR(EIO); ++ ++ if (pb->seekable) { ++ int got_width = 0; ++ bin->fsize = avio_size(pb) - 1 - 192 - 4096; ++ st->codec->width = 80<<3; ++ ff_sauce_read(s, &bin->fsize, &got_width, 0); ++ if (!ap->height) ++ calculate_height(st->codec, bin->fsize); ++ avio_seek(pb, 1 + 192 + 4096, SEEK_SET); ++ } ++ return 0; ++} ++#endif /* CONFIG_ADF_DEMUXER */ ++ ++#if CONFIG_IDF_DEMUXER ++static const uint8_t idf_magic[] = { ++ 0x04, 0x31, 0x2e, 0x34, 0x00, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x15, 0x00 ++}; ++ ++static int idf_probe(AVProbeData *p) ++{ ++ if (p->buf_size < sizeof(idf_magic)) ++ return 0; ++ if (!memcmp(p->buf, idf_magic, sizeof(idf_magic))) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int idf_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ int got_width = 0; ++ ++ if (!pb->seekable) ++ return AVERROR(EIO); ++ ++ st = init_stream(s, ap); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->codec->codec_id = CODEC_ID_IDF; ++ ++ st->codec->extradata_size = 2 + 48 + 4096; ++ st->codec->extradata = av_malloc(st->codec->extradata_size); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ st->codec->extradata[0] = 16; ++ st->codec->extradata[1] = BINTEXT_PALETTE|BINTEXT_FONT; ++ ++ avio_seek(pb, avio_size(pb) - 4096 - 48, SEEK_SET); ++ ++ if (avio_read(pb, st->codec->extradata + 2 + 48, 4096) < 0) ++ return AVERROR(EIO); ++ if (avio_read(pb, st->codec->extradata + 2, 48) < 0) ++ return AVERROR(EIO); ++ ++ bin->fsize = avio_size(pb) - 12 - 4096 - 48; ++ ff_sauce_read(s, &bin->fsize, &got_width, 0); ++ if (!ap->height) ++ calculate_height(st->codec, bin->fsize); ++ avio_seek(pb, 12, SEEK_SET); ++ return 0; ++} ++#endif /* CONFIG_IDF_DEMUXER */ ++ ++static int read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ BinDemuxContext *bin = s->priv_data; ++ ++ if (bin->fsize > 0) { ++ if (av_get_packet(s->pb, pkt, bin->fsize) < 0) ++ return AVERROR(EIO); ++ bin->fsize = -1; /* done */ ++ } else if (!bin->fsize) { ++ if (url_feof(s->pb)) ++ return AVERROR(EIO); ++ if (av_get_packet(s->pb, pkt, bin->chars_per_frame) < 0) ++ return AVERROR(EIO); ++ } else { ++ return AVERROR(EIO); ++ } ++ ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ return 0; ++} ++ ++#if CONFIG_BINTEXT_DEMUXER ++AVInputFormat ff_bintext_demuxer = { ++ .name = "bin", ++ .long_name = NULL_IF_CONFIG_SMALL("Binary text"), ++ .priv_data_size = sizeof(BinDemuxContext), ++ .read_header = bintext_read_header, ++ .read_packet = read_packet, ++ .extensions = "bin", ++}; ++#endif ++ ++#if CONFIG_XBIN_DEMUXER ++AVInputFormat ff_xbin_demuxer = { ++ .name = "xbin", ++ .long_name = NULL_IF_CONFIG_SMALL("eXtended BINary text (XBIN)"), ++ .priv_data_size = sizeof(BinDemuxContext), ++ .read_probe = xbin_probe, ++ .read_header = xbin_read_header, ++ .read_packet = read_packet, ++}; ++#endif ++ ++#if CONFIG_ADF_DEMUXER ++AVInputFormat ff_adf_demuxer = { ++ .name = "adf", ++ .long_name = NULL_IF_CONFIG_SMALL("Artworx Data Format"), ++ .priv_data_size = sizeof(BinDemuxContext), ++ .read_header = adf_read_header, ++ .read_packet = read_packet, ++ .extensions = "adf", ++}; ++#endif ++ ++#if CONFIG_IDF_DEMUXER ++AVInputFormat ff_idf_demuxer = { ++ .name = "idf", ++ .long_name = NULL_IF_CONFIG_SMALL("iCE Draw File"), ++ .priv_data_size = sizeof(BinDemuxContext), ++ .read_probe = idf_probe, ++ .read_header = idf_read_header, ++ .read_packet = read_packet, ++ .extensions = "idf", ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bit.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bit.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bit.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bit.c 2012-05-14 14:08:54.924351857 +0200 +@@ -0,0 +1,156 @@ ++/* ++ * G.729 bit format muxer and demuxer ++ * Copyright (c) 2007-2008 Vladimir Voroshilov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++#include "avformat.h" ++#include "internal.h" ++#include "libavcodec/get_bits.h" ++#include "libavcodec/put_bits.h" ++ ++#define MAX_FRAME_SIZE 10 ++ ++#define SYNC_WORD 0x6b21 ++#define BIT_0 0x7f ++#define BIT_1 0x81 ++ ++static int probe(AVProbeData *p) ++{ ++ int i, j; ++ ++ if(p->buf_size < 0x40) ++ return 0; ++ ++ for(i=0; i+3buf_size && i< 10*0x50; ){ ++ if(AV_RL16(&p->buf[0]) != SYNC_WORD) ++ return 0; ++ j=AV_RL16(&p->buf[2]); ++ if(j!=0x40 && j!=0x50) ++ return 0; ++ i+=j; ++ } ++ return AVPROBE_SCORE_MAX/2; ++} ++ ++static int read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVStream* st; ++ ++ st=avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id=CODEC_ID_G729; ++ st->codec->sample_rate=8000; ++ st->codec->block_align = 16; ++ st->codec->channels=1; ++ ++ avpriv_set_pts_info(st, 64, 1, 100); ++ return 0; ++} ++ ++static int read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ PutBitContext pbo; ++ uint16_t buf[8 * MAX_FRAME_SIZE + 2]; ++ int packet_size; ++ uint16_t* src=buf; ++ int i, j, ret; ++ int64_t pos= avio_tell(pb); ++ ++ if(url_feof(pb)) ++ return AVERROR_EOF; ++ ++ avio_rl16(pb); // sync word ++ packet_size = avio_rl16(pb) / 8; ++ if(packet_size > MAX_FRAME_SIZE) ++ return AVERROR_INVALIDDATA; ++ ++ ret = avio_read(pb, (uint8_t*)buf, (8 * packet_size) * sizeof(uint16_t)); ++ if(ret<0) ++ return ret; ++ if(ret != 8 * packet_size * sizeof(uint16_t)) ++ return AVERROR(EIO); ++ ++ av_new_packet(pkt, packet_size); ++ ++ init_put_bits(&pbo, pkt->data, packet_size); ++ for(j=0; j < packet_size; j++) ++ for(i=0; i<8;i++) ++ put_bits(&pbo,1, AV_RL16(src++) == BIT_1 ? 1 : 0); ++ ++ flush_put_bits(&pbo); ++ ++ pkt->duration=1; ++ pkt->pos = pos; ++ return 0; ++} ++ ++AVInputFormat ff_bit_demuxer = { ++ .name = "bit", ++ .long_name = NULL_IF_CONFIG_SMALL("G.729 BIT file format"), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .extensions = "bit", ++}; ++ ++#if CONFIG_MUXERS ++static int write_header(AVFormatContext *s) ++{ ++ AVCodecContext *enc = s->streams[0]->codec; ++ ++ enc->codec_id = CODEC_ID_G729; ++ enc->channels = 1; ++ enc->bits_per_coded_sample = 16; ++ enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3; ++ ++ return 0; ++} ++ ++static int write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ GetBitContext gb; ++ int i; ++ ++ avio_wl16(pb, SYNC_WORD); ++ avio_wl16(pb, 8 * 10); ++ ++ init_get_bits(&gb, pkt->data, 8*10); ++ for(i=0; i< 8 * 10; i++) ++ avio_wl16(pb, get_bits1(&gb) ? BIT_1 : BIT_0); ++ avio_flush(pb); ++ ++ return 0; ++} ++ ++AVOutputFormat ff_bit_muxer = { ++ .name = "bit", ++ .long_name = NULL_IF_CONFIG_SMALL("G.729 BIT file format"), ++ .mime_type = "audio/bit", ++ .extensions = "bit", ++ .audio_codec = CODEC_ID_G729, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = write_header, ++ .write_packet = write_packet, ++}; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/bmv.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/bmv.c 2012-05-14 14:08:54.924351857 +0200 +@@ -0,0 +1,137 @@ ++/* ++ * Discworld II BMV demuxer ++ * Copyright (c) 2011 Konstantin Shishkov. ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++ ++enum BMVFlags { ++ BMV_NOP = 0, ++ BMV_END, ++ BMV_DELTA, ++ BMV_INTRA, ++ ++ BMV_AUDIO = 0x20, ++}; ++ ++typedef struct BMVContext { ++ uint8_t *packet; ++ int size; ++ int get_next; ++ int64_t audio_pos; ++} BMVContext; ++ ++static int bmv_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVStream *st, *ast; ++ BMVContext *c = s->priv_data; ++ ++ st = avformat_new_stream(s, 0); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_BMV_VIDEO; ++ st->codec->width = 640; ++ st->codec->height = 429; ++ st->codec->pix_fmt = PIX_FMT_PAL8; ++ avpriv_set_pts_info(st, 16, 1, 12); ++ ast = avformat_new_stream(s, 0); ++ if (!ast) ++ return AVERROR(ENOMEM); ++ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ast->codec->codec_id = CODEC_ID_BMV_AUDIO; ++ ast->codec->channels = 2; ++ ast->codec->sample_rate = 22050; ++ avpriv_set_pts_info(ast, 16, 1, 22050); ++ ++ c->get_next = 1; ++ c->audio_pos = 0; ++ return 0; ++} ++ ++static int bmv_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ BMVContext *c = s->priv_data; ++ int type; ++ void *tmp; ++ ++ while (c->get_next) { ++ if (s->pb->eof_reached) ++ return AVERROR_EOF; ++ type = avio_r8(s->pb); ++ if (type == BMV_NOP) ++ continue; ++ if (type == BMV_END) ++ return AVERROR_EOF; ++ c->size = avio_rl24(s->pb); ++ if (!c->size) ++ return AVERROR_INVALIDDATA; ++ tmp = av_realloc(c->packet, c->size + 1); ++ if (!tmp) ++ return AVERROR(ENOMEM); ++ c->packet = tmp; ++ c->packet[0] = type; ++ if (avio_read(s->pb, c->packet + 1, c->size) != c->size) ++ return AVERROR(EIO); ++ if (type & BMV_AUDIO) { ++ int audio_size = c->packet[1] * 65 + 1; ++ if (audio_size >= c->size) { ++ av_log(s, AV_LOG_ERROR, "Reported audio size %d is bigger than packet size (%d)\n", ++ audio_size, c->size); ++ return AVERROR_INVALIDDATA; ++ } ++ if (av_new_packet(pkt, audio_size) < 0) ++ return AVERROR(ENOMEM); ++ memcpy(pkt->data, c->packet + 1, pkt->size); ++ pkt->stream_index = 1; ++ pkt->pts = c->audio_pos; ++ pkt->duration = c->packet[1] * 32; ++ c->audio_pos += pkt->duration; ++ c->get_next = 0; ++ return pkt->size; ++ } else ++ break; ++ } ++ if (av_new_packet(pkt, c->size + 1) < 0) ++ return AVERROR(ENOMEM); ++ pkt->stream_index = 0; ++ c->get_next = 1; ++ memcpy(pkt->data, c->packet, pkt->size); ++ return pkt->size; ++} ++ ++static int bmv_read_close(AVFormatContext *s) ++{ ++ BMVContext *c = s->priv_data; ++ ++ av_freep(&c->packet); ++ ++ return 0; ++} ++ ++AVInputFormat ff_bmv_demuxer = { ++ .name = "bmv", ++ .long_name = NULL_IF_CONFIG_SMALL("Discworld II BMV"), ++ .priv_data_size = sizeof(BMVContext), ++ .read_header = bmv_read_header, ++ .read_packet = bmv_read_packet, ++ .read_close = bmv_read_close, ++ .extensions = "bmv" ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/c93.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/c93.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/c93.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/c93.c 2012-05-14 14:08:54.925351877 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "voc.h" + #include "libavutil/intreadwrite.h" + +@@ -60,15 +61,15 @@ + AVFormatParameters *ap) + { + AVStream *video; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + C93DemuxContext *c93 = s->priv_data; + int i; + int framecount = 0; + + for (i = 0; i < 512; i++) { +- c93->block_records[i].index = get_le16(pb); +- c93->block_records[i].length = get_byte(pb); +- c93->block_records[i].frames = get_byte(pb); ++ c93->block_records[i].index = avio_rl16(pb); ++ c93->block_records[i].length = avio_r8(pb); ++ c93->block_records[i].frames = avio_r8(pb); + if (c93->block_records[i].frames > 32) { + av_log(s, AV_LOG_ERROR, "too many frames in block\n"); + return AVERROR_INVALIDDATA; +@@ -79,7 +80,7 @@ + /* Audio streams are added if audio packets are found */ + s->ctx_flags |= AVFMTCTX_NOHEADER; + +- video = av_new_stream(s, 0); ++ video = avformat_new_stream(s, NULL); + if (!video) + return AVERROR(ENOMEM); + +@@ -89,7 +90,7 @@ + video->codec->height = 192; + /* 4:3 320x200 with 8 empty lines */ + video->sample_aspect_ratio = (AVRational) { 5, 6 }; +- video->time_base = (AVRational) { 2, 25 }; ++ avpriv_set_pts_info(video, 64, 2, 25); + video->nb_frames = framecount; + video->duration = framecount; + video->start_time = 0; +@@ -105,7 +106,7 @@ + + static int read_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + C93DemuxContext *c93 = s->priv_data; + C93BlockRecord *br = &c93->block_records[c93->current_block]; + int datasize; +@@ -114,15 +115,15 @@ + if (c93->next_pkt_is_audio) { + c93->current_frame++; + c93->next_pkt_is_audio = 0; +- datasize = get_le16(pb); ++ datasize = avio_rl16(pb); + if (datasize > 42) { + if (!c93->audio) { +- c93->audio = av_new_stream(s, 1); ++ c93->audio = avformat_new_stream(s, NULL); + if (!c93->audio) + return AVERROR(ENOMEM); + c93->audio->codec->codec_type = AVMEDIA_TYPE_AUDIO; + } +- url_fskip(pb, 26); /* VOC header */ ++ avio_skip(pb, 26); /* VOC header */ + ret = voc_get_packet(s, pkt, c93->audio, datasize - 26); + if (ret > 0) { + pkt->stream_index = 1; +@@ -140,15 +141,15 @@ + } + + if (c93->current_frame == 0) { +- url_fseek(pb, br->index * 2048, SEEK_SET); ++ avio_seek(pb, br->index * 2048, SEEK_SET); + for (i = 0; i < 32; i++) { +- c93->frame_offsets[i] = get_le32(pb); ++ c93->frame_offsets[i] = avio_rl32(pb); + } + } + +- url_fseek(pb,br->index * 2048 + ++ avio_seek(pb,br->index * 2048 + + c93->frame_offsets[c93->current_frame], SEEK_SET); +- datasize = get_le16(pb); /* video frame size */ ++ datasize = avio_rl16(pb); /* video frame size */ + + ret = av_new_packet(pkt, datasize + 768 + 1); + if (ret < 0) +@@ -156,13 +157,13 @@ + pkt->data[0] = 0; + pkt->size = datasize + 1; + +- ret = get_buffer(pb, pkt->data + 1, datasize); ++ ret = avio_read(pb, pkt->data + 1, datasize); + if (ret < datasize) { + ret = AVERROR(EIO); + goto fail; + } + +- datasize = get_le16(pb); /* palette size */ ++ datasize = avio_rl16(pb); /* palette size */ + if (datasize) { + if (datasize != 768) { + av_log(s, AV_LOG_ERROR, "invalid palette size %u\n", datasize); +@@ -170,7 +171,7 @@ + goto fail; + } + pkt->data[0] |= C93_HAS_PALETTE; +- ret = get_buffer(pb, pkt->data + pkt->size, datasize); ++ ret = avio_read(pb, pkt->data + pkt->size, datasize); + if (ret < datasize) { + ret = AVERROR(EIO); + goto fail; +@@ -193,10 +194,10 @@ + } + + AVInputFormat ff_c93_demuxer = { +- "c93", +- NULL_IF_CONFIG_SMALL("Interplay C93"), +- sizeof(C93DemuxContext), +- probe, +- read_header, +- read_packet, ++ .name = "c93", ++ .long_name = NULL_IF_CONFIG_SMALL("Interplay C93"), ++ .priv_data_size = sizeof(C93DemuxContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cache.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cache.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cache.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cache.c 2012-05-14 14:08:54.926351897 +0200 +@@ -0,0 +1,136 @@ ++/* ++ * Input cache protocol. ++ * Copyright (c) 2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ * ++ * Based on file.c by Fabrice Bellard ++ */ ++ ++/** ++ * @TODO ++ * support non continuous caching ++ * support keeping files ++ * support filling with a background thread ++ */ ++ ++#include "libavutil/avassert.h" ++#include "libavutil/avstring.h" ++#include "libavutil/file.h" ++#include "avformat.h" ++#include ++#if HAVE_SETMODE ++#include ++#endif ++#include ++#include ++#include ++#include "os_support.h" ++#include "url.h" ++ ++typedef struct Context { ++ int fd; ++ int64_t end; ++ int64_t pos; ++ URLContext *inner; ++} Context; ++ ++static int cache_open(URLContext *h, const char *arg, int flags) ++{ ++ const char *buffername; ++ Context *c= h->priv_data; ++ ++ av_strstart(arg, "cache:", &arg); ++ ++ c->fd = av_tempfile("ffcache", &buffername, 0, h); ++ if (c->fd < 0){ ++ av_log(h, AV_LOG_ERROR, "Failed to create tempfile\n"); ++ return c->fd; ++ } ++ ++ unlink(buffername); ++ av_freep(&buffername); ++ ++ return ffurl_open(&c->inner, arg, flags, &h->interrupt_callback, NULL); ++} ++ ++static int cache_read(URLContext *h, unsigned char *buf, int size) ++{ ++ Context *c= h->priv_data; ++ int r; ++ ++ if(c->posend){ ++ r = read(c->fd, buf, FFMIN(size, c->end - c->pos)); ++ if(r>0) ++ c->pos += r; ++ return (-1 == r)?AVERROR(errno):r; ++ }else{ ++ r = ffurl_read(c->inner, buf, size); ++ if(r > 0){ ++ int r2= write(c->fd, buf, r); ++ av_assert0(r2==r); // FIXME handle cache failure ++ c->pos += r; ++ c->end += r; ++ } ++ return r; ++ } ++} ++ ++static int64_t cache_seek(URLContext *h, int64_t pos, int whence) ++{ ++ Context *c= h->priv_data; ++ ++ if (whence == AVSEEK_SIZE) { ++ pos= ffurl_seek(c->inner, pos, whence); ++ if(pos <= 0){ ++ pos= ffurl_seek(c->inner, -1, SEEK_END); ++ ffurl_seek(c->inner, c->end, SEEK_SET); ++ if(pos <= 0) ++ return c->end; ++ } ++ return pos; ++ } ++ ++ pos= lseek(c->fd, pos, whence); ++ if(pos<0){ ++ return pos; ++ }else if(pos <= c->end){ ++ c->pos= pos; ++ return pos; ++ }else{ ++ lseek(c->fd, c->pos, SEEK_SET); ++ return AVERROR(EPIPE); ++ } ++} ++ ++static int cache_close(URLContext *h) ++{ ++ Context *c= h->priv_data; ++ close(c->fd); ++ ffurl_close(c->inner); ++ ++ return 0; ++} ++ ++URLProtocol ff_cache_protocol = { ++ .name = "cache", ++ .url_open = cache_open, ++ .url_read = cache_read, ++ .url_seek = cache_seek, ++ .url_close = cache_close, ++ .priv_data_size = sizeof(Context), ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/caf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/caf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/caf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/caf.c 2012-05-14 14:08:54.927351917 +0200 +@@ -32,27 +32,34 @@ + * Known codec tags for CAF + */ + const AVCodecTag ff_codec_caf_tags[] = { +- { CODEC_ID_AAC, MKBETAG('a','a','c',' ') }, +- { CODEC_ID_AC3, MKBETAG('a','c','-','3') }, +- { CODEC_ID_ALAC, MKBETAG('a','l','a','c') }, ++ { CODEC_ID_AAC, MKTAG('a','a','c',' ') }, ++ { CODEC_ID_AC3, MKTAG('a','c','-','3') }, ++ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') }, ++ { CODEC_ID_ADPCM_IMA_WAV, MKTAG('m','s', 0, 17 ) }, ++ { CODEC_ID_ADPCM_MS, MKTAG('m','s', 0, 2 ) }, ++ { CODEC_ID_ALAC, MKTAG('a','l','a','c') }, ++ { CODEC_ID_AMR_NB, MKTAG('s','a','m','r') }, + /* FIXME: use DV demuxer, as done in MOV */ +- /*{ CODEC_ID_DVAUDIO, MKBETAG('v','d','v','a') },*/ +- /*{ CODEC_ID_DVAUDIO, MKBETAG('d','v','c','a') },*/ +- { CODEC_ID_ADPCM_IMA_QT, MKBETAG('i','m','a','4') }, +- { CODEC_ID_MACE3, MKBETAG('M','A','C','3') }, +- { CODEC_ID_MACE6, MKBETAG('M','A','C','6') }, +- { CODEC_ID_MP3, MKBETAG('.','m','p','3') }, +- { CODEC_ID_MP2, MKBETAG('.','m','p','2') }, +- { CODEC_ID_MP1, MKBETAG('.','m','p','1') }, +- { CODEC_ID_PCM_ALAW, MKBETAG('a','l','a','w') }, +- { CODEC_ID_PCM_MULAW, MKBETAG('u','l','a','w') }, +- { CODEC_ID_QCELP, MKBETAG('Q','c','l','p') }, +- { CODEC_ID_QDM2, MKBETAG('Q','D','M','2') }, +- { CODEC_ID_QDM2, MKBETAG('Q','D','M','C') }, ++ /*{ CODEC_ID_DVAUDIO, MKTAG('v','d','v','a') },*/ ++ /*{ CODEC_ID_DVAUDIO, MKTAG('d','v','c','a') },*/ ++ { CODEC_ID_GSM, MKTAG('a','g','s','m') }, ++ { CODEC_ID_GSM_MS, MKTAG('m','s', 0, '1') }, ++ { CODEC_ID_MACE3, MKTAG('M','A','C','3') }, ++ { CODEC_ID_MACE6, MKTAG('M','A','C','6') }, ++ { CODEC_ID_MP1, MKTAG('.','m','p','1') }, ++ { CODEC_ID_MP2, MKTAG('.','m','p','2') }, ++ { CODEC_ID_MP3, MKTAG('.','m','p','3') }, ++ { CODEC_ID_MP3, MKTAG('m','s', 0 ,'U') }, ++ { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') }, ++ { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') }, ++ { CODEC_ID_QCELP, MKTAG('Q','c','l','p') }, ++ { CODEC_ID_QDM2, MKTAG('Q','D','M','2') }, ++ { CODEC_ID_QDM2, MKTAG('Q','D','M','C') }, + /* currently unsupported codecs */ +- /*{ AC-3 over S/PDIF MKBETAG('c','a','c','3') },*/ +- /*{ MPEG4CELP MKBETAG('c','e','l','p') },*/ +- /*{ MPEG4HVXC MKBETAG('h','v','x','c') },*/ +- /*{ MPEG4TwinVQ MKBETAG('t','w','v','q') },*/ ++ /*{ AC-3 over S/PDIF MKTAG('c','a','c','3') },*/ ++ /*{ MPEG4CELP MKTAG('c','e','l','p') },*/ ++ /*{ MPEG4HVXC MKTAG('h','v','x','c') },*/ ++ /*{ MPEG4TwinVQ MKTAG('t','w','v','q') },*/ + { CODEC_ID_NONE, 0 }, + }; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cafdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cafdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cafdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cafdec.c 2012-05-14 14:08:54.928351937 +0200 +@@ -26,9 +26,12 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + #include "isom.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/dict.h" + #include "caf.h" + + typedef struct { +@@ -53,26 +56,26 @@ + /** Read audio description chunk */ + static int read_desc_chunk(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + CaffContext *caf = s->priv_data; + AVStream *st; + int flags; + + /* new audio stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + /* parse format description */ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- st->codec->sample_rate = av_int2dbl(get_be64(pb)); +- st->codec->codec_tag = get_be32(pb); +- flags = get_be32(pb); +- caf->bytes_per_packet = get_be32(pb); ++ st->codec->sample_rate = av_int2double(avio_rb64(pb)); ++ st->codec->codec_tag = avio_rl32(pb); ++ flags = avio_rb32(pb); ++ caf->bytes_per_packet = avio_rb32(pb); + st->codec->block_align = caf->bytes_per_packet; +- caf->frames_per_packet = get_be32(pb); +- st->codec->channels = get_be32(pb); +- st->codec->bits_per_coded_sample = get_be32(pb); ++ caf->frames_per_packet = avio_rb32(pb); ++ st->codec->channels = avio_rb32(pb); ++ st->codec->bits_per_coded_sample = avio_rb32(pb); + + /* calculate bit rate for constant size packets */ + if (caf->frames_per_packet > 0 && caf->bytes_per_packet > 0) { +@@ -83,7 +86,7 @@ + } + + /* determine codec */ +- if (st->codec->codec_tag == MKBETAG('l','p','c','m')) ++ if (st->codec->codec_tag == MKTAG('l','p','c','m')) + st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, (flags ^ 0x2) | 0x4); + else + st->codec->codec_id = ff_codec_get_id(ff_codec_caf_tags, st->codec->codec_tag); +@@ -93,7 +96,7 @@ + /** Read magic cookie chunk */ + static int read_kuki_chunk(AVFormatContext *s, int64_t size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + + if (size < 0 || size > INT_MAX - FF_INPUT_BUFFER_PADDING_SIZE) +@@ -106,35 +109,45 @@ + int strt, skip; + MOVAtom atom; + +- strt = url_ftell(pb); ++ strt = avio_tell(pb); + ff_mov_read_esds(s, pb, atom); +- skip = size - (url_ftell(pb) - strt); ++ skip = size - (avio_tell(pb) - strt); + if (skip < 0 || !st->codec->extradata || + st->codec->codec_id != CODEC_ID_AAC) { + av_log(s, AV_LOG_ERROR, "invalid AAC magic cookie\n"); + return AVERROR_INVALIDDATA; + } +- url_fskip(pb, skip); ++ avio_skip(pb, skip); + } else if (st->codec->codec_id == CODEC_ID_ALAC) { + #define ALAC_PREAMBLE 12 + #define ALAC_HEADER 36 +- if (size < ALAC_PREAMBLE + ALAC_HEADER) { +- av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n"); +- url_fskip(pb, size); +- return AVERROR_INVALIDDATA; ++#define ALAC_NEW_KUKI 24 ++ if (size == ALAC_NEW_KUKI) { ++ st->codec->extradata = av_mallocz(ALAC_HEADER + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ memcpy(st->codec->extradata, "\0\0\0\24alac", 8); ++ avio_read(pb, st->codec->extradata + ALAC_HEADER - ALAC_NEW_KUKI, ALAC_NEW_KUKI); ++ st->codec->extradata_size = ALAC_HEADER; ++ } else { ++ if (size < ALAC_PREAMBLE + ALAC_HEADER) { ++ av_log(s, AV_LOG_ERROR, "invalid ALAC magic cookie\n"); ++ avio_skip(pb, size); ++ return AVERROR_INVALIDDATA; ++ } ++ avio_skip(pb, ALAC_PREAMBLE); ++ st->codec->extradata = av_mallocz(ALAC_HEADER + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ avio_read(pb, st->codec->extradata, ALAC_HEADER); ++ st->codec->extradata_size = ALAC_HEADER; ++ avio_skip(pb, size - ALAC_PREAMBLE - ALAC_HEADER); + } +- url_fskip(pb, ALAC_PREAMBLE); +- st->codec->extradata = av_mallocz(ALAC_HEADER + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!st->codec->extradata) +- return AVERROR(ENOMEM); +- get_buffer(pb, st->codec->extradata, ALAC_HEADER); +- st->codec->extradata_size = ALAC_HEADER; +- url_fskip(pb, size - ALAC_PREAMBLE - ALAC_HEADER); + } else { + st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); +- get_buffer(pb, st->codec->extradata, size); ++ avio_read(pb, st->codec->extradata, size); + st->codec->extradata_size = size; + } + +@@ -144,21 +157,21 @@ + /** Read packet table chunk */ + static int read_pakt_chunk(AVFormatContext *s, int64_t size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; + int64_t pos = 0, ccount; + int num_packets, i; + +- ccount = url_ftell(pb); ++ ccount = avio_tell(pb); + +- num_packets = get_be64(pb); ++ num_packets = avio_rb64(pb); + if (num_packets < 0 || INT32_MAX / sizeof(AVIndexEntry) < num_packets) + return AVERROR_INVALIDDATA; + +- st->nb_frames = get_be64(pb); /* valid frames */ +- st->nb_frames += get_be32(pb); /* priming frames */ +- st->nb_frames += get_be32(pb); /* remainder frames */ ++ st->nb_frames = avio_rb64(pb); /* valid frames */ ++ st->nb_frames += avio_rb32(pb); /* priming frames */ ++ st->nb_frames += avio_rb32(pb); /* remainder frames */ + + st->duration = 0; + for (i = 0; i < num_packets; i++) { +@@ -167,7 +180,7 @@ + st->duration += caf->frames_per_packet ? caf->frames_per_packet : ff_mp4_read_descr_len(pb); + } + +- if (url_ftell(pb) - ccount != size) { ++ if (avio_tell(pb) - ccount != size) { + av_log(s, AV_LOG_ERROR, "error reading packet table\n"); + return -1; + } +@@ -179,36 +192,36 @@ + /** Read information chunk */ + static void read_info_chunk(AVFormatContext *s, int64_t size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int i; +- unsigned int nb_entries = get_be32(pb); ++ unsigned int nb_entries = avio_rb32(pb); + for (i = 0; i < nb_entries; i++) { + char key[32]; + char value[1024]; +- get_strz(pb, key, sizeof(key)); +- get_strz(pb, value, sizeof(value)); +- av_metadata_set2(&s->metadata, key, value, 0); ++ avio_get_str(pb, INT_MAX, key, sizeof(key)); ++ avio_get_str(pb, INT_MAX, value, sizeof(value)); ++ av_dict_set(&s->metadata, key, value, 0); + } + } + + static int read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + CaffContext *caf = s->priv_data; + AVStream *st; + uint32_t tag = 0; + int found_data, ret; + int64_t size; + +- url_fskip(pb, 8); /* magic, version, file flags */ ++ avio_skip(pb, 8); /* magic, version, file flags */ + + /* audio description chunk */ +- if (get_be32(pb) != MKBETAG('d','e','s','c')) { ++ if (avio_rb32(pb) != MKBETAG('d','e','s','c')) { + av_log(s, AV_LOG_ERROR, "desc chunk not present\n"); + return AVERROR_INVALIDDATA; + } +- size = get_be64(pb); ++ size = avio_rb64(pb); + if (size != 32) + return AVERROR_INVALIDDATA; + +@@ -223,21 +236,21 @@ + + /* stop at data chunk if seeking is not supported or + data chunk size is unknown */ +- if (found_data && (caf->data_size < 0 || url_is_streamed(pb))) ++ if (found_data && (caf->data_size < 0 || !pb->seekable)) + break; + +- tag = get_be32(pb); +- size = get_be64(pb); ++ tag = avio_rb32(pb); ++ size = avio_rb64(pb); + if (url_feof(pb)) + break; + + switch (tag) { + case MKBETAG('d','a','t','a'): +- url_fskip(pb, 4); /* edit count */ +- caf->data_start = url_ftell(pb); ++ avio_skip(pb, 4); /* edit count */ ++ caf->data_start = avio_tell(pb); + caf->data_size = size < 0 ? -1 : size - 4; +- if (caf->data_size > 0 && !url_is_streamed(pb)) +- url_fskip(pb, caf->data_size); ++ if (caf->data_size > 0 && pb->seekable) ++ avio_skip(pb, caf->data_size); + found_data = 1; + break; + +@@ -257,15 +270,21 @@ + read_info_chunk(s, size); + break; + ++ case MKBETAG('c','h','a','n'): ++ if (size < 12) ++ return AVERROR_INVALIDDATA; ++ ff_mov_read_chan(s, size, st->codec); ++ break; ++ + default: + #define _(x) ((x) >= ' ' ? (x) : ' ') +- av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c)\n", +- tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF)); ++ av_log(s, AV_LOG_WARNING, "skipping CAF chunk: %08X (%c%c%c%c), size %"PRId64"\n", ++ tag, _(tag>>24), _((tag>>16)&0xFF), _((tag>>8)&0xFF), _(tag&0xFF), size); + #undef _ + case MKBETAG('f','r','e','e'): + if (size < 0) + return AVERROR_INVALIDDATA; +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + } +@@ -284,15 +303,13 @@ + "block size or frame size are variable.\n"); + return AVERROR_INVALIDDATA; + } +- s->file_size = url_fsize(pb); +- s->file_size = FFMAX(0, s->file_size); + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + st->start_time = 0; + + /* position the stream at the start of data */ + if (caf->data_size >= 0) +- url_fseek(pb, caf->data_start, SEEK_SET); ++ avio_seek(pb, caf->data_start, SEEK_SET); + + return 0; + } +@@ -301,7 +318,7 @@ + + static int read_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; + int res, pkt_size = 0, pkt_frames = 0; +@@ -312,7 +329,7 @@ + + /* don't read past end of data chunk */ + if (caf->data_size > 0) { +- left = (caf->data_start + caf->data_size) - url_ftell(pb); ++ left = (caf->data_start + caf->data_size) - avio_tell(pb); + if (left <= 0) + return AVERROR(EIO); + } +@@ -358,6 +375,7 @@ + { + AVStream *st = s->streams[0]; + CaffContext *caf = s->priv_data; ++ CaffContext caf2 = *caf; + int64_t pos; + + timestamp = FFMAX(timestamp, 0); +@@ -377,18 +395,20 @@ + return -1; + } + +- url_fseek(s->pb, pos + caf->data_start, SEEK_SET); ++ if (avio_seek(s->pb, pos + caf->data_start, SEEK_SET) < 0) { ++ *caf = caf2; ++ return -1; ++ } + return 0; + } + + AVInputFormat ff_caf_demuxer = { +- "caf", +- NULL_IF_CONFIG_SMALL("Apple Core Audio Format"), +- sizeof(CaffContext), +- probe, +- read_header, +- read_packet, +- NULL, +- read_seek, ++ .name = "caf", ++ .long_name = NULL_IF_CONFIG_SMALL("Apple Core Audio Format"), ++ .priv_data_size = sizeof(CaffContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_seek = read_seek, + .codec_tag = (const AVCodecTag*[]){ff_codec_caf_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cafenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cafenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cafenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cafenc.c 2012-05-14 14:08:54.929351957 +0200 +@@ -0,0 +1,262 @@ ++/* ++ * Core Audio Format muxer ++ * Copyright (c) 2011 Carl Eugen Hoyos ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "caf.h" ++#include "riff.h" ++#include "isom.h" ++#include "avio_internal.h" ++#include "libavutil/intfloat.h" ++ ++typedef struct { ++ int64_t data; ++ uint8_t *pkt_sizes; ++ int size_buffer_size; ++ int size_entries_used; ++ int packets; ++} CAFContext; ++ ++static uint32_t codec_flags(enum CodecID codec_id) { ++ switch (codec_id) { ++ case CODEC_ID_PCM_F32BE: ++ case CODEC_ID_PCM_F64BE: ++ return 1; //< kCAFLinearPCMFormatFlagIsFloat ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S24LE: ++ case CODEC_ID_PCM_S32LE: ++ return 2; //< kCAFLinearPCMFormatFlagIsLittleEndian ++ case CODEC_ID_PCM_F32LE: ++ case CODEC_ID_PCM_F64LE: ++ return 3; //< kCAFLinearPCMFormatFlagIsFloat | kCAFLinearPCMFormatFlagIsLittleEndian ++ default: ++ return 0; ++ } ++} ++ ++static uint32_t samples_per_packet(enum CodecID codec_id, int channels) { ++ switch (codec_id) { ++ case CODEC_ID_PCM_S8: ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S16BE: ++ case CODEC_ID_PCM_S24LE: ++ case CODEC_ID_PCM_S24BE: ++ case CODEC_ID_PCM_S32LE: ++ case CODEC_ID_PCM_S32BE: ++ case CODEC_ID_PCM_F32LE: ++ case CODEC_ID_PCM_F32BE: ++ case CODEC_ID_PCM_F64LE: ++ case CODEC_ID_PCM_F64BE: ++ case CODEC_ID_PCM_ALAW: ++ case CODEC_ID_PCM_MULAW: ++ return 1; ++ case CODEC_ID_MACE3: ++ case CODEC_ID_MACE6: ++ return 6; ++ case CODEC_ID_ADPCM_IMA_QT: ++ return 64; ++ case CODEC_ID_AMR_NB: ++ case CODEC_ID_GSM: ++ case CODEC_ID_QCELP: ++ return 160; ++ case CODEC_ID_GSM_MS: ++ return 320; ++ case CODEC_ID_MP1: ++ return 384; ++ case CODEC_ID_MP2: ++ case CODEC_ID_MP3: ++ return 1152; ++ case CODEC_ID_AC3: ++ return 1536; ++ case CODEC_ID_ALAC: ++ case CODEC_ID_QDM2: ++ return 4096; ++ case CODEC_ID_ADPCM_IMA_WAV: ++ return (1024 - 4 * channels) * 8 / (4 * channels) + 1; ++ case CODEC_ID_ADPCM_MS: ++ return (1024 - 7 * channels) * 2 / channels + 2; ++ default: ++ return 0; ++ } ++} ++ ++static int caf_write_header(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ AVCodecContext *enc = s->streams[0]->codec; ++ CAFContext *caf = s->priv_data; ++ unsigned int codec_tag = ff_codec_get_tag(ff_codec_caf_tags, enc->codec_id); ++ ++ switch (enc->codec_id) { ++ case CODEC_ID_AAC: ++ case CODEC_ID_AC3: ++ av_log(s, AV_LOG_ERROR, "muxing codec currently unsupported\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ switch (enc->codec_id) { ++ case CODEC_ID_PCM_S8: ++ case CODEC_ID_PCM_S16LE: ++ case CODEC_ID_PCM_S16BE: ++ case CODEC_ID_PCM_S24LE: ++ case CODEC_ID_PCM_S24BE: ++ case CODEC_ID_PCM_S32LE: ++ case CODEC_ID_PCM_S32BE: ++ case CODEC_ID_PCM_F32LE: ++ case CODEC_ID_PCM_F32BE: ++ case CODEC_ID_PCM_F64LE: ++ case CODEC_ID_PCM_F64BE: ++ case CODEC_ID_PCM_ALAW: ++ case CODEC_ID_PCM_MULAW: ++ codec_tag = MKTAG('l','p','c','m'); ++ } ++ ++ if (!codec_tag) { ++ av_log(s, AV_LOG_ERROR, "unsupported codec\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (!enc->block_align && !pb->seekable) { ++ av_log(s, AV_LOG_ERROR, "Muxing variable packet size not supported on non seekable output\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ffio_wfourcc(pb, "caff"); //< mFileType ++ avio_wb16(pb, 1); //< mFileVersion ++ avio_wb16(pb, 0); //< mFileFlags ++ ++ ffio_wfourcc(pb, "desc"); //< Audio Description chunk ++ avio_wb64(pb, 32); //< mChunkSize ++ avio_wb64(pb, av_double2int(enc->sample_rate)); //< mSampleRate ++ avio_wl32(pb, codec_tag); //< mFormatID ++ avio_wb32(pb, codec_flags(enc->codec_id)); //< mFormatFlags ++ avio_wb32(pb, enc->block_align); //< mBytesPerPacket ++ avio_wb32(pb, samples_per_packet(enc->codec_id, enc->channels)); //< mFramesPerPacket ++ avio_wb32(pb, enc->channels); //< mChannelsPerFrame ++ avio_wb32(pb, av_get_bits_per_sample(enc->codec_id)); //< mBitsPerChannel ++ ++ if (enc->channel_layout) { ++ ffio_wfourcc(pb, "chan"); ++ avio_wb64(pb, 12); ++ ff_mov_write_chan(pb, enc->channel_layout); ++ } ++ ++ if (enc->codec_id == CODEC_ID_ALAC) { ++ ffio_wfourcc(pb, "kuki"); ++ avio_wb64(pb, 12 + enc->extradata_size); ++ avio_write(pb, "\0\0\0\14frmaalac", 12); ++ avio_write(pb, enc->extradata, enc->extradata_size); ++ } else if (enc->codec_id == CODEC_ID_AMR_NB) { ++ ffio_wfourcc(pb, "kuki"); ++ avio_wb64(pb, 29); ++ avio_write(pb, "\0\0\0\14frmasamr", 12); ++ avio_wb32(pb, 0x11); /* size */ ++ avio_write(pb, "samrFFMP", 8); ++ avio_w8(pb, 0); /* decoder version */ ++ ++ avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ ++ avio_w8(pb, 0x00); /* Mode change period (no restriction) */ ++ avio_w8(pb, 0x01); /* Frames per sample */ ++ } else if (enc->codec_id == CODEC_ID_QDM2) { ++ ffio_wfourcc(pb, "kuki"); ++ avio_wb64(pb, enc->extradata_size); ++ avio_write(pb, enc->extradata, enc->extradata_size); ++ } ++ ++ ffio_wfourcc(pb, "data"); //< Audio Data chunk ++ caf->data = avio_tell(pb); ++ avio_wb64(pb, -1); //< mChunkSize ++ avio_wb32(pb, 0); //< mEditCount ++ ++ avio_flush(pb); ++ return 0; ++} ++ ++static int caf_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ CAFContext *caf = s->priv_data; ++ ++ avio_write(s->pb, pkt->data, pkt->size); ++ if (!s->streams[0]->codec->block_align) { ++ void *pkt_sizes = caf->pkt_sizes; ++ int i, alloc_size = caf->size_entries_used + 5; ++ if (alloc_size < 0) { ++ caf->pkt_sizes = NULL; ++ } else { ++ caf->pkt_sizes = av_fast_realloc(caf->pkt_sizes, ++ &caf->size_buffer_size, ++ alloc_size); ++ } ++ if (!caf->pkt_sizes) { ++ av_free(pkt_sizes); ++ return AVERROR(ENOMEM); ++ } ++ for (i = 4; i > 0; i--) { ++ unsigned top = pkt->size >> i * 7; ++ if (top) ++ caf->pkt_sizes[caf->size_entries_used++] = 128 | top; ++ } ++ caf->pkt_sizes[caf->size_entries_used++] = pkt->size & 127; ++ caf->packets++; ++ } ++ return 0; ++} ++ ++static int caf_write_trailer(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ AVCodecContext *enc = s->streams[0]->codec; ++ ++ if (pb->seekable) { ++ CAFContext *caf = s->priv_data; ++ int64_t file_size = avio_tell(pb); ++ ++ avio_seek(pb, caf->data, SEEK_SET); ++ avio_wb64(pb, file_size - caf->data - 8); ++ avio_seek(pb, file_size, SEEK_SET); ++ if (!enc->block_align) { ++ ffio_wfourcc(pb, "pakt"); ++ avio_wb64(pb, caf->size_entries_used + 24); ++ avio_wb64(pb, caf->packets); ///< mNumberPackets ++ avio_wb64(pb, caf->packets * samples_per_packet(enc->codec_id, enc->channels)); ///< mNumberValidFrames ++ avio_wb32(pb, 0); ///< mPrimingFrames ++ avio_wb32(pb, 0); ///< mRemainderFrames ++ avio_write(pb, caf->pkt_sizes, caf->size_entries_used); ++ av_freep(&caf->pkt_sizes); ++ caf->size_buffer_size = 0; ++ } ++ avio_flush(pb); ++ } ++ return 0; ++} ++ ++AVOutputFormat ff_caf_muxer = { ++ .name = "caf", ++ .long_name = NULL_IF_CONFIG_SMALL("Apple Core Audio Format"), ++ .mime_type = "audio/x-caf", ++ .extensions = "caf", ++ .priv_data_size = sizeof(CAFContext), ++ .audio_codec = CODEC_ID_PCM_S16BE, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = caf_write_header, ++ .write_packet = caf_write_packet, ++ .write_trailer = caf_write_trailer, ++ .codec_tag= (const AVCodecTag* const []){ff_codec_caf_tags, 0}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cavsvideodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cavsvideodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cavsvideodec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cavsvideodec.c 2012-05-14 14:08:54.930351977 +0200 +@@ -65,13 +65,4 @@ + return 0; + } + +-AVInputFormat ff_cavsvideo_demuxer = { +- "cavsvideo", +- NULL_IF_CONFIG_SMALL("raw Chinese AVS video"), +- 0, +- cavsvideo_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .value = CODEC_ID_CAVS, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(cavsvideo, "raw Chinese AVS video", cavsvideo_probe, NULL, CODEC_ID_CAVS) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cdg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cdg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cdg.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cdg.c 2012-05-14 14:08:54.931351997 +0200 +@@ -20,15 +20,18 @@ + */ + + #include "avformat.h" ++#include "internal.h" + + #define CDG_PACKET_SIZE 24 ++#define CDG_COMMAND 0x09 ++#define CDG_MASK 0x3F + + static int read_header(AVFormatContext *s, AVFormatParameters *ap) + { + AVStream *vst; + int ret; + +- vst = av_new_stream(s, 0); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + +@@ -36,9 +39,9 @@ + vst->codec->codec_id = CODEC_ID_CDGRAPHICS; + + /// 75 sectors/sec * 4 packets/sector = 300 packets/sec +- av_set_pts_info(vst, 32, 1, 300); ++ avpriv_set_pts_info(vst, 32, 1, 300); + +- ret = url_fsize(s->pb); ++ ret = avio_size(s->pb); + if (ret > 0) + vst->duration = (ret * vst->time_base.den) / (CDG_PACKET_SIZE * 300); + +@@ -49,18 +52,27 @@ + { + int ret; + +- ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE); ++ while (1) { ++ ret = av_get_packet(s->pb, pkt, CDG_PACKET_SIZE); ++ if (ret < 1 || (pkt->data[0] & CDG_MASK) == CDG_COMMAND) ++ break; ++ av_free_packet(pkt); ++ } + + pkt->stream_index = 0; ++ pkt->dts=pkt->pts= s->streams[0]->cur_dts; ++ ++ if(ret>5 && (pkt->data[0]&0x3F) == 9 && (pkt->data[1]&0x3F)==1 && !(pkt->data[2+2+1] & 0x0F)){ ++ pkt->flags = AV_PKT_FLAG_KEY; ++ } + return ret; + } + + AVInputFormat ff_cdg_demuxer = { +- "cdg", +- NULL_IF_CONFIG_SMALL("CD Graphics Format"), +- 0, +- NULL, +- read_header, +- read_packet, ++ .name = "cdg", ++ .long_name = NULL_IF_CONFIG_SMALL("CD Graphics Format"), ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .flags= AVFMT_GENERIC_INDEX, + .extensions = "cdg" + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/concat.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/concat.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/concat.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/concat.c 2012-05-14 14:08:54.932352017 +0200 +@@ -24,6 +24,7 @@ + #include "avformat.h" + #include "libavutil/avstring.h" + #include "libavutil/mem.h" ++#include "url.h" + + #define AV_CAT_SEPARATOR "|" + +@@ -46,10 +47,9 @@ + struct concat_nodes *nodes = data->nodes; + + for (i = 0; i != data->length; i++) +- err |= url_close(nodes[i].uc); ++ err |= ffurl_close(nodes[i].uc); + + av_freep(&data->nodes); +- av_freep(&h->priv_data); + + return err < 0 ? -1 : 0; + } +@@ -61,16 +61,11 @@ + int64_t size; + size_t len, i; + URLContext *uc; +- struct concat_data *data; ++ struct concat_data *data = h->priv_data; + struct concat_nodes *nodes; + + av_strstart(uri, "concat:", &uri); + +- /* creating data */ +- if (!(data = av_mallocz(sizeof(*data)))) +- return AVERROR(ENOMEM); +- h->priv_data = data; +- + for (i = 0, len = 1; uri[i]; i++) + if (uri[i] == *AV_CAT_SEPARATOR) + /* integer overflow */ +@@ -80,7 +75,6 @@ + } + + if (!(nodes = av_malloc(sizeof(*nodes) * len))) { +- av_freep(&h->priv_data); + return AVERROR(ENOMEM); + } else + data->nodes = nodes; +@@ -100,12 +94,13 @@ + uri += len + strspn(uri+len, AV_CAT_SEPARATOR); + + /* creating URLContext */ +- if ((err = url_open(&uc, node_uri, flags)) < 0) ++ if ((err = ffurl_open(&uc, node_uri, flags, ++ &h->interrupt_callback, NULL)) < 0) + break; + + /* creating size */ +- if ((size = url_filesize(uc)) < 0) { +- url_close(uc); ++ if ((size = ffurl_size(uc)) < 0) { ++ ffurl_close(uc); + err = AVERROR(ENOSYS); + break; + } +@@ -135,12 +130,12 @@ + size_t i = data->current; + + while (size > 0) { +- result = url_read(nodes[i].uc, buf, size); ++ result = ffurl_read(nodes[i].uc, buf, size); + if (result < 0) + return total ? total : result; + if (!result) + if (i + 1 == data->length || +- url_seek(nodes[++i].uc, 0, SEEK_SET) < 0) ++ ffurl_seek(nodes[++i].uc, 0, SEEK_SET) < 0) + break; + total += result; + buf += result; +@@ -168,7 +163,7 @@ + /* get the absolute position */ + for (i = 0; i != data->current; i++) + pos += nodes[i].size; +- pos += url_seek(nodes[i].uc, 0, SEEK_CUR); ++ pos += ffurl_seek(nodes[i].uc, 0, SEEK_CUR); + whence = SEEK_SET; + /* fall through with the absolute position */ + case SEEK_SET: +@@ -179,7 +174,7 @@ + return AVERROR(EINVAL); + } + +- result = url_seek(nodes[i].uc, pos, whence); ++ result = ffurl_seek(nodes[i].uc, pos, whence); + if (result >= 0) { + data->current = i; + while (i) +@@ -189,10 +184,10 @@ + } + + URLProtocol ff_concat_protocol = { +- "concat", +- concat_open, +- concat_read, +- NULL, +- concat_seek, +- concat_close, ++ .name = "concat", ++ .url_open = concat_open, ++ .url_read = concat_read, ++ .url_seek = concat_seek, ++ .url_close = concat_close, ++ .priv_data_size = sizeof(struct concat_data), + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/crcenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/crcenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/crcenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/crcenc.c 2012-05-14 14:08:54.932352017 +0200 +@@ -49,20 +49,19 @@ + char buf[64]; + + snprintf(buf, sizeof(buf), "CRC=0x%08x\n", crc->crcval); +- put_buffer(s->pb, buf, strlen(buf)); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf, strlen(buf)); ++ avio_flush(s->pb); + return 0; + } + + AVOutputFormat ff_crc_muxer = { +- "crc", +- NULL_IF_CONFIG_SMALL("CRC testing format"), +- NULL, +- "", +- sizeof(CRCState), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_RAWVIDEO, +- crc_write_header, +- crc_write_packet, +- crc_write_trailer, ++ .name = "crc", ++ .long_name = NULL_IF_CONFIG_SMALL("CRC testing format"), ++ .priv_data_size = sizeof(CRCState), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = crc_write_header, ++ .write_packet = crc_write_packet, ++ .write_trailer = crc_write_trailer, ++ .flags = AVFMT_NOTIMESTAMPS, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/crypto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/crypto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/crypto.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/crypto.c 2012-05-14 14:08:54.933352037 +0200 +@@ -0,0 +1,170 @@ ++/* ++ * Decryption protocol handler ++ * Copyright (c) 2011 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "libavutil/aes.h" ++#include "libavutil/avstring.h" ++#include "libavutil/opt.h" ++#include "internal.h" ++#include "url.h" ++ ++#define MAX_BUFFER_BLOCKS 150 ++#define BLOCKSIZE 16 ++ ++typedef struct { ++ const AVClass *class; ++ URLContext *hd; ++ uint8_t inbuffer [BLOCKSIZE*MAX_BUFFER_BLOCKS], ++ outbuffer[BLOCKSIZE*MAX_BUFFER_BLOCKS]; ++ uint8_t *outptr; ++ int indata, indata_used, outdata; ++ int eof; ++ uint8_t *key; ++ int keylen; ++ uint8_t *iv; ++ int ivlen; ++ struct AVAES *aes; ++} CryptoContext; ++ ++#define OFFSET(x) offsetof(CryptoContext, x) ++#define D AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ {"key", "AES decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, .flags = D }, ++ {"iv", "AES decryption initialization vector", OFFSET(iv), AV_OPT_TYPE_BINARY, .flags = D }, ++ { NULL } ++}; ++ ++static const AVClass crypto_class = { ++ .class_name = "crypto", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static int crypto_open(URLContext *h, const char *uri, int flags) ++{ ++ const char *nested_url; ++ int ret = 0; ++ CryptoContext *c = h->priv_data; ++ ++ if (!av_strstart(uri, "crypto+", &nested_url) && ++ !av_strstart(uri, "crypto:", &nested_url)) { ++ av_log(h, AV_LOG_ERROR, "Unsupported url %s\n", uri); ++ ret = AVERROR(EINVAL); ++ goto err; ++ } ++ ++ if (c->keylen < BLOCKSIZE || c->ivlen < BLOCKSIZE) { ++ av_log(h, AV_LOG_ERROR, "Key or IV not set\n"); ++ ret = AVERROR(EINVAL); ++ goto err; ++ } ++ if (flags & AVIO_FLAG_WRITE) { ++ av_log(h, AV_LOG_ERROR, "Only decryption is supported currently\n"); ++ ret = AVERROR(ENOSYS); ++ goto err; ++ } ++ if ((ret = ffurl_open(&c->hd, nested_url, AVIO_FLAG_READ, ++ &h->interrupt_callback, NULL)) < 0) { ++ av_log(h, AV_LOG_ERROR, "Unable to open input\n"); ++ goto err; ++ } ++ c->aes = av_mallocz(av_aes_size); ++ if (!c->aes) { ++ ret = AVERROR(ENOMEM); ++ goto err; ++ } ++ ++ av_aes_init(c->aes, c->key, 128, 1); ++ ++ h->is_streamed = 1; ++ ++err: ++ return ret; ++} ++ ++static int crypto_read(URLContext *h, uint8_t *buf, int size) ++{ ++ CryptoContext *c = h->priv_data; ++ int blocks; ++retry: ++ if (c->outdata > 0) { ++ size = FFMIN(size, c->outdata); ++ memcpy(buf, c->outptr, size); ++ c->outptr += size; ++ c->outdata -= size; ++ return size; ++ } ++ // We avoid using the last block until we've found EOF, ++ // since we'll remove PKCS7 padding at the end. So make ++ // sure we've got at least 2 blocks, so we can decrypt ++ // at least one. ++ while (c->indata - c->indata_used < 2*BLOCKSIZE) { ++ int n = ffurl_read(c->hd, c->inbuffer + c->indata, ++ sizeof(c->inbuffer) - c->indata); ++ if (n <= 0) { ++ c->eof = 1; ++ break; ++ } ++ c->indata += n; ++ } ++ blocks = (c->indata - c->indata_used) / BLOCKSIZE; ++ if (!blocks) ++ return AVERROR_EOF; ++ if (!c->eof) ++ blocks--; ++ av_aes_crypt(c->aes, c->outbuffer, c->inbuffer + c->indata_used, blocks, ++ c->iv, 1); ++ c->outdata = BLOCKSIZE * blocks; ++ c->outptr = c->outbuffer; ++ c->indata_used += BLOCKSIZE * blocks; ++ if (c->indata_used >= sizeof(c->inbuffer)/2) { ++ memmove(c->inbuffer, c->inbuffer + c->indata_used, ++ c->indata - c->indata_used); ++ c->indata -= c->indata_used; ++ c->indata_used = 0; ++ } ++ if (c->eof) { ++ // Remove PKCS7 padding at the end ++ int padding = c->outbuffer[c->outdata - 1]; ++ c->outdata -= padding; ++ } ++ goto retry; ++} ++ ++static int crypto_close(URLContext *h) ++{ ++ CryptoContext *c = h->priv_data; ++ if (c->hd) ++ ffurl_close(c->hd); ++ av_freep(&c->aes); ++ return 0; ++} ++ ++URLProtocol ff_crypto_protocol = { ++ .name = "crypto", ++ .url_open = crypto_open, ++ .url_read = crypto_read, ++ .url_close = crypto_close, ++ .priv_data_size = sizeof(CryptoContext), ++ .priv_data_class = &crypto_class, ++ .flags = URL_PROTOCOL_FLAG_NESTED_SCHEME, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/cutils.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/cutils.c 2012-05-14 14:08:54.934352057 +0200 +@@ -1,5 +1,5 @@ + /* +- * Various simple utilities for ffmpeg system ++ * various simple utilities for libavformat + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -21,46 +21,6 @@ + #include "avformat.h" + #include "internal.h" + +-/* add one element to a dynamic array */ +-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem) +-{ +- /* see similar ffmpeg.c:grow_array() */ +- int nb, nb_alloc; +- intptr_t *tab; +- +- nb = *nb_ptr; +- tab = *tab_ptr; +- if ((nb & (nb - 1)) == 0) { +- if (nb == 0) +- nb_alloc = 1; +- else +- nb_alloc = nb * 2; +- tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); +- *tab_ptr = tab; +- } +- tab[nb++] = elem; +- *nb_ptr = nb; +-} +- +-time_t mktimegm(struct tm *tm) +-{ +- time_t t; +- +- int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; +- +- if (m < 3) { +- m += 12; +- y--; +- } +- +- t = 86400 * +- (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); +- +- t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; +- +- return t; +-} +- + #define ISLEAP(y) (((y) % 4 == 0) && (((y) % 100) != 0 || ((y) % 400) == 0)) + #define LEAPS_COUNT(y) ((y)/4 - (y)/100 + (y)/400) + +@@ -95,94 +55,3 @@ + + return tm; + } +- +-/* get a positive number between n_min and n_max, for a maximum length +- of len_max. Return -1 if error. */ +-static int date_get_num(const char **pp, +- int n_min, int n_max, int len_max) +-{ +- int i, val, c; +- const char *p; +- +- p = *pp; +- val = 0; +- for(i = 0; i < len_max; i++) { +- c = *p; +- if (!isdigit(c)) +- break; +- val = (val * 10) + c - '0'; +- p++; +- } +- /* no number read ? */ +- if (p == *pp) +- return -1; +- if (val < n_min || val > n_max) +- return -1; +- *pp = p; +- return val; +-} +- +-/* small strptime for ffmpeg */ +-const char *small_strptime(const char *p, const char *fmt, +- struct tm *dt) +-{ +- int c, val; +- +- for(;;) { +- c = *fmt++; +- if (c == '\0') { +- return p; +- } else if (c == '%') { +- c = *fmt++; +- switch(c) { +- case 'H': +- val = date_get_num(&p, 0, 23, 2); +- if (val == -1) +- return NULL; +- dt->tm_hour = val; +- break; +- case 'M': +- val = date_get_num(&p, 0, 59, 2); +- if (val == -1) +- return NULL; +- dt->tm_min = val; +- break; +- case 'S': +- val = date_get_num(&p, 0, 59, 2); +- if (val == -1) +- return NULL; +- dt->tm_sec = val; +- break; +- case 'Y': +- val = date_get_num(&p, 0, 9999, 4); +- if (val == -1) +- return NULL; +- dt->tm_year = val - 1900; +- break; +- case 'm': +- val = date_get_num(&p, 1, 12, 2); +- if (val == -1) +- return NULL; +- dt->tm_mon = val - 1; +- break; +- case 'd': +- val = date_get_num(&p, 1, 31, 2); +- if (val == -1) +- return NULL; +- dt->tm_mday = val; +- break; +- case '%': +- goto match; +- default: +- return NULL; +- } +- } else { +- match: +- if (c != *p) +- return NULL; +- p++; +- } +- } +- return p; +-} +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/daud.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/daud.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/daud.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/daud.c 2012-05-14 14:08:54.935352077 +0200 +@@ -21,7 +21,7 @@ + #include "avformat.h" + + static int daud_header(AVFormatContext *s, AVFormatParameters *ap) { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -36,12 +36,12 @@ + } + + static int daud_packet(AVFormatContext *s, AVPacket *pkt) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret, size; + if (url_feof(pb)) + return AVERROR(EIO); +- size = get_be16(pb); +- get_be16(pb); // unknown ++ size = avio_rb16(pb); ++ avio_rb16(pb); // unknown + ret = av_get_packet(pb, pkt, size); + pkt->stream_index = 0; + return ret; +@@ -57,39 +57,37 @@ + + static int daud_write_packet(struct AVFormatContext *s, AVPacket *pkt) + { +- put_be16(s->pb, pkt->size); +- put_be16(s->pb, 0x8010); // unknown +- put_buffer(s->pb, pkt->data, pkt->size); +- put_flush_packet(s->pb); ++ if (pkt->size > 65535) { ++ av_log(s, AV_LOG_ERROR, ++ "Packet size too large for s302m. (%d > 65535)\n", pkt->size); ++ return -1; ++ } ++ avio_wb16(s->pb, pkt->size); ++ avio_wb16(s->pb, 0x8010); // unknown ++ avio_write(s->pb, pkt->data, pkt->size); ++ avio_flush(s->pb); + return 0; + } + + #if CONFIG_DAUD_DEMUXER + AVInputFormat ff_daud_demuxer = { +- "daud", +- NULL_IF_CONFIG_SMALL("D-Cinema audio format"), +- 0, +- NULL, +- daud_header, +- daud_packet, +- NULL, +- NULL, ++ .name = "daud", ++ .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"), ++ .read_header = daud_header, ++ .read_packet = daud_packet, + .extensions = "302", + }; + #endif + + #if CONFIG_DAUD_MUXER +-AVOutputFormat ff_daud_muxer = +-{ +- "daud", +- NULL_IF_CONFIG_SMALL("D-Cinema audio format"), +- NULL, +- "302", +- 0, +- CODEC_ID_PCM_S24DAUD, +- CODEC_ID_NONE, +- daud_write_header, +- daud_write_packet, +- .flags= AVFMT_NOTIMESTAMPS, ++AVOutputFormat ff_daud_muxer = { ++ .name = "daud", ++ .long_name = NULL_IF_CONFIG_SMALL("D-Cinema audio format"), ++ .extensions = "302", ++ .audio_codec = CODEC_ID_PCM_S24DAUD, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = daud_write_header, ++ .write_packet = daud_write_packet, ++ .flags = AVFMT_NOTIMESTAMPS, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dfa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dfa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dfa.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dfa.c 2012-05-14 14:08:54.935352077 +0200 +@@ -0,0 +1,119 @@ ++/* ++ * Chronomaster DFA Format Demuxer ++ * Copyright (c) 2011 Konstantin Shishkov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++ ++static int dfa_probe(AVProbeData *p) ++{ ++ if (p->buf_size < 4 || AV_RL32(p->buf) != MKTAG('D', 'F', 'I', 'A')) ++ return 0; ++ ++ return AVPROBE_SCORE_MAX; ++} ++ ++static int dfa_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ int frames; ++ uint32_t mspf; ++ ++ if (avio_rl32(pb) != MKTAG('D', 'F', 'I', 'A')) { ++ av_log(s, AV_LOG_ERROR, "Invalid magic for DFA\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ avio_skip(pb, 2); // unused ++ frames = avio_rl16(pb); ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_DFA; ++ st->codec->width = avio_rl16(pb); ++ st->codec->height = avio_rl16(pb); ++ mspf = avio_rl32(pb); ++ if (!mspf) { ++ av_log(s, AV_LOG_WARNING, "Zero FPS reported, defaulting to 10\n"); ++ mspf = 100; ++ } ++ avpriv_set_pts_info(st, 24, mspf, 1000); ++ avio_skip(pb, 128 - 16); // padding ++ st->duration = frames; ++ ++ return 0; ++} ++ ++static int dfa_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ uint32_t frame_size; ++ int ret, first = 1; ++ ++ if (pb->eof_reached) ++ return AVERROR_EOF; ++ ++ if (av_get_packet(pb, pkt, 12) != 12) ++ return AVERROR(EIO); ++ while (!pb->eof_reached) { ++ if (!first) { ++ ret = av_append_packet(pb, pkt, 12); ++ if (ret < 0) { ++ av_free_packet(pkt); ++ return ret; ++ } ++ } else ++ first = 0; ++ frame_size = AV_RL32(pkt->data + pkt->size - 8); ++ if (frame_size > INT_MAX - 4) { ++ av_log(s, AV_LOG_ERROR, "Too large chunk size: %d\n", frame_size); ++ return AVERROR(EIO); ++ } ++ if (AV_RL32(pkt->data + pkt->size - 12) == MKTAG('E', 'O', 'F', 'R')) { ++ if (frame_size) { ++ av_log(s, AV_LOG_WARNING, "skipping %d bytes of end-of-frame marker chunk\n", ++ frame_size); ++ avio_skip(pb, frame_size); ++ } ++ return 0; ++ } ++ ret = av_append_packet(pb, pkt, frame_size); ++ if (ret < 0) { ++ av_free_packet(pkt); ++ return ret; ++ } ++ } ++ ++ return 0; ++} ++ ++AVInputFormat ff_dfa_demuxer = { ++ .name = "dfa", ++ .long_name = NULL_IF_CONFIG_SMALL("Chronomaster DFA"), ++ .read_probe = dfa_probe, ++ .read_header = dfa_read_header, ++ .read_packet = dfa_read_packet, ++ .flags = AVFMT_GENERIC_INDEX, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/diracdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/diracdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/diracdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/diracdec.c 2012-05-14 14:08:54.936352097 +0200 +@@ -31,13 +31,4 @@ + return 0; + } + +-AVInputFormat ff_dirac_demuxer = { +- "dirac", +- NULL_IF_CONFIG_SMALL("raw Dirac"), +- 0, +- dirac_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .value = CODEC_ID_DIRAC, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(dirac, "raw Dirac", dirac_probe, NULL, CODEC_ID_DIRAC) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dnxhddec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dnxhddec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dnxhddec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dnxhddec.c 2012-05-14 14:08:54.936352097 +0200 +@@ -42,13 +42,4 @@ + return AVPROBE_SCORE_MAX; + } + +-AVInputFormat ff_dnxhd_demuxer = { +- "dnxhd", +- NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"), +- 0, +- dnxhd_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .value = CODEC_ID_DNXHD, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(dnxhd, "raw DNxHD (SMPTE VC-3)", dnxhd_probe, NULL, CODEC_ID_DNXHD) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dsicin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dsicin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dsicin.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dsicin.c 2012-05-14 14:08:54.938352138 +0200 +@@ -26,6 +26,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + + typedef struct CinFileHeader { +@@ -70,19 +72,19 @@ + return AVPROBE_SCORE_MAX; + } + +-static int cin_read_file_header(CinDemuxContext *cin, ByteIOContext *pb) { ++static int cin_read_file_header(CinDemuxContext *cin, AVIOContext *pb) { + CinFileHeader *hdr = &cin->file_header; + +- if (get_le32(pb) != 0x55AA0000) ++ if (avio_rl32(pb) != 0x55AA0000) + return AVERROR_INVALIDDATA; + +- hdr->video_frame_size = get_le32(pb); +- hdr->video_frame_width = get_le16(pb); +- hdr->video_frame_height = get_le16(pb); +- hdr->audio_frequency = get_le32(pb); +- hdr->audio_bits = get_byte(pb); +- hdr->audio_stereo = get_byte(pb); +- hdr->audio_frame_size = get_le16(pb); ++ hdr->video_frame_size = avio_rl32(pb); ++ hdr->video_frame_width = avio_rl16(pb); ++ hdr->video_frame_height = avio_rl16(pb); ++ hdr->audio_frequency = avio_rl32(pb); ++ hdr->audio_bits = avio_r8(pb); ++ hdr->audio_stereo = avio_r8(pb); ++ hdr->audio_frame_size = avio_rl16(pb); + + if (hdr->audio_frequency != 22050 || hdr->audio_bits != 16 || hdr->audio_stereo != 0) + return AVERROR_INVALIDDATA; +@@ -95,7 +97,7 @@ + int rc; + CinDemuxContext *cin = s->priv_data; + CinFileHeader *hdr = &cin->file_header; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + + rc = cin_read_file_header(cin, pb); +@@ -107,11 +109,11 @@ + cin->audio_buffer_size = 0; + + /* initialize the video decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 32, 1, 12); ++ avpriv_set_pts_info(st, 32, 1, 12); + cin->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_DSICINVIDEO; +@@ -120,37 +122,36 @@ + st->codec->height = hdr->video_frame_height; + + /* initialize the audio decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 32, 1, 22050); ++ avpriv_set_pts_info(st, 32, 1, 22050); + cin->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_DSICINAUDIO; + st->codec->codec_tag = 0; /* no tag */ + st->codec->channels = 1; + st->codec->sample_rate = 22050; +- st->codec->bits_per_coded_sample = 16; ++ st->codec->bits_per_coded_sample = 8; + st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample * st->codec->channels; +- st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + + return 0; + } + +-static int cin_read_frame_header(CinDemuxContext *cin, ByteIOContext *pb) { ++static int cin_read_frame_header(CinDemuxContext *cin, AVIOContext *pb) { + CinFrameHeader *hdr = &cin->frame_header; + +- hdr->video_frame_type = get_byte(pb); +- hdr->audio_frame_type = get_byte(pb); +- hdr->pal_colors_count = get_le16(pb); +- hdr->video_frame_size = get_le32(pb); +- hdr->audio_frame_size = get_le32(pb); ++ hdr->video_frame_type = avio_r8(pb); ++ hdr->audio_frame_type = avio_r8(pb); ++ hdr->pal_colors_count = avio_rl16(pb); ++ hdr->video_frame_size = avio_rl32(pb); ++ hdr->audio_frame_size = avio_rl32(pb); + +- if (url_feof(pb) || url_ferror(pb)) ++ if (url_feof(pb) || pb->error) + return AVERROR(EIO); + +- if (get_le32(pb) != 0xAA55AA55) ++ if (avio_rl32(pb) != 0xAA55AA55) + return AVERROR_INVALIDDATA; + + return 0; +@@ -159,7 +160,7 @@ + static int cin_read_packet(AVFormatContext *s, AVPacket *pkt) + { + CinDemuxContext *cin = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + CinFrameHeader *hdr = &cin->frame_header; + int rc, palette_type, pkt_size; + int ret; +@@ -179,6 +180,8 @@ + /* palette and video packet */ + pkt_size = (palette_type + 3) * hdr->pal_colors_count + hdr->video_frame_size; + ++ pkt_size = ffio_limit(pb, pkt_size); ++ + ret = av_new_packet(pkt, 4 + pkt_size); + if (ret < 0) + return ret; +@@ -191,7 +194,7 @@ + pkt->data[2] = hdr->pal_colors_count >> 8; + pkt->data[3] = hdr->video_frame_type; + +- ret = get_buffer(pb, &pkt->data[4], pkt_size); ++ ret = avio_read(pb, &pkt->data[4], pkt_size); + if (ret < 0) { + av_free_packet(pkt); + return ret; +@@ -211,16 +214,17 @@ + + pkt->stream_index = cin->audio_stream_index; + pkt->pts = cin->audio_stream_pts; +- cin->audio_stream_pts += cin->audio_buffer_size * 2 / cin->file_header.audio_frame_size; ++ pkt->duration = cin->audio_buffer_size - (pkt->pts == 0); ++ cin->audio_stream_pts += pkt->duration; + cin->audio_buffer_size = 0; + return 0; + } + + AVInputFormat ff_dsicin_demuxer = { +- "dsicin", +- NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"), +- sizeof(CinDemuxContext), +- cin_probe, +- cin_read_header, +- cin_read_packet, ++ .name = "dsicin", ++ .long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN format"), ++ .priv_data_size = sizeof(CinDemuxContext), ++ .read_probe = cin_probe, ++ .read_header = cin_read_header, ++ .read_packet = cin_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dtsdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dtsdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dtsdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dtsdec.c 2012-05-14 14:08:54.938352138 +0200 +@@ -66,12 +66,11 @@ + } + + AVInputFormat ff_dts_demuxer = { +- "dts", +- NULL_IF_CONFIG_SMALL("raw DTS"), +- 0, +- dts_probe, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++ .name = "dts", ++ .long_name = NULL_IF_CONFIG_SMALL("raw DTS"), ++ .read_probe = dts_probe, ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "dts", + .value = CODEC_ID_DTS, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dv.c 2012-05-14 14:08:54.940352178 +0200 +@@ -30,9 +30,12 @@ + */ + #include + #include "avformat.h" ++#include "internal.h" + #include "libavcodec/dvdata.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "dv.h" ++#include "libavutil/avassert.h" + + struct DVDemuxContext { + const DVprofile* sys; /* Current DV profile. E.g.: 525/60, 625/50 */ +@@ -85,6 +88,9 @@ + case dv_video_control: + offs = (80*5 + 48 + 5); + break; ++ case dv_timecode: ++ offs = (80*1 + 3 + 3); ++ break; + default: + return NULL; + } +@@ -95,7 +101,7 @@ + /* + * 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. ++ * We can pass them upwards when libavcodec 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. +@@ -119,21 +125,29 @@ + if (quant > 1) + return -1; /* unsupported quantization */ + ++ if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency)) ++ return AVERROR_INVALIDDATA; ++ + size = (sys->audio_min_samples[freq] + smpls) * 4; /* 2ch, 2bytes */ + half_ch = sys->difseg_size / 2; + + /* We work with 720p frames split in half, thus even frames have + * channels 0,1 and odd 2,3. */ + ipcm = (sys->height == 720 && !(frame[1] & 0x0C)) ? 2 : 0; +- pcm = ppcm[ipcm++]; + + /* for each DIF channel */ + for (chan = 0; chan < sys->n_difchan; chan++) { ++ av_assert0(ipcm<4); ++ /* next stereo channel (50Mbps and 100Mbps only) */ ++ pcm = ppcm[ipcm++]; ++ if (!pcm) ++ break; + /* 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) { + /* next stereo channel (12bit mode only) */ ++ av_assert0(ipcm<4); + pcm = ppcm[ipcm++]; + if (!pcm) + break; +@@ -176,11 +190,6 @@ + frame += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ + } + } +- +- /* next stereo channel (50Mbps and 100Mbps only) */ +- pcm = ppcm[ipcm++]; +- if (!pcm) +- break; + } + + return size; +@@ -202,6 +211,18 @@ + stype = (as_pack[3] & 0x1f); /* 0 - 2CH, 2 - 4CH, 3 - 8CH */ + quant = as_pack[4] & 0x07; /* 0 - 16bit linear, 1 - 12bit nonlinear */ + ++ if (freq >= FF_ARRAY_ELEMS(dv_audio_frequency)) { ++ av_log(c->fctx, AV_LOG_ERROR, ++ "Unrecognized audio sample rate index (%d)\n", freq); ++ return 0; ++ } ++ ++ if (stype > 3) { ++ av_log(c->fctx, AV_LOG_ERROR, "stype %d is invalid\n", stype); ++ c->ach = 0; ++ return 0; ++ } ++ + /* note: ach counts PAIRS of channels (i.e. stereo channels) */ + ach = ((int[4]){ 1, 0, 2, 4})[stype]; + if (ach == 1 && quant && freq == 2) +@@ -210,10 +231,10 @@ + /* Dynamic handling of the audio streams in DV */ + for (i = 0; i < ach; i++) { + if (!c->ast[i]) { +- c->ast[i] = av_new_stream(c->fctx, 0); ++ c->ast[i] = avformat_new_stream(c->fctx, NULL); + if (!c->ast[i]) + break; +- av_set_pts_info(c->ast[i], 64, 1, 30000); ++ avpriv_set_pts_info(c->ast[i], 64, 1, 30000); + c->ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; + c->ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE; + +@@ -243,13 +264,11 @@ + if (c->sys) { + avctx = c->vst->codec; + +- av_set_pts_info(c->vst, 64, c->sys->time_base.num, ++ avpriv_set_pts_info(c->vst, 64, c->sys->time_base.num, + c->sys->time_base.den); + avctx->time_base= c->sys->time_base; +- if (!avctx->width){ +- avctx->width = c->sys->width; +- avctx->height = c->sys->height; +- } ++ if (!avctx->width) ++ avcodec_set_dimensions(avctx, c->sys->width, c->sys->height); + avctx->pix_fmt = c->sys->pix_fmt; + + /* finding out SAR is a little bit messy */ +@@ -265,11 +284,50 @@ + return size; + } + ++static int bcd2int(uint8_t bcd) ++{ ++ int low = bcd & 0xf; ++ int high = bcd >> 4; ++ if (low > 9 || high > 9) ++ return -1; ++ return low + 10*high; ++} ++ ++static int dv_extract_timecode(DVDemuxContext* c, uint8_t* frame, char tc[32]) ++{ ++ int hh, mm, ss, ff, drop_frame; ++ const uint8_t *tc_pack; ++ ++ tc_pack = dv_extract_pack(frame, dv_timecode); ++ if (!tc_pack) ++ return 0; ++ ++ ff = bcd2int(tc_pack[1] & 0x3f); ++ ss = bcd2int(tc_pack[2] & 0x7f); ++ mm = bcd2int(tc_pack[3] & 0x7f); ++ hh = bcd2int(tc_pack[4] & 0x3f); ++ drop_frame = tc_pack[1] >> 6 & 0x1; ++ ++ if (ff < 0 || ss < 0 || mm < 0 || hh < 0) ++ return -1; ++ ++ // For PAL systems, drop frame bit is replaced by an arbitrary ++ // bit so its value should not be considered. Drop frame timecode ++ // is only relevant for NTSC systems. ++ if(c->sys->ltc_divisor == 25 || c->sys->ltc_divisor == 50) { ++ drop_frame = 0; ++ } ++ ++ snprintf(tc, 32, "%02d:%02d:%02d%c%02d", ++ hh, mm, ss, drop_frame ? ';' : ':', ff); ++ return 1; ++} ++ + /* + * The following 3 functions constitute our interface to the world + */ + +-DVDemuxContext* dv_init_demux(AVFormatContext *s) ++DVDemuxContext* avpriv_dv_init_demux(AVFormatContext *s) + { + DVDemuxContext *c; + +@@ -277,7 +335,7 @@ + if (!c) + return NULL; + +- c->vst = av_new_stream(s, 0); ++ c->vst = avformat_new_stream(s, NULL); + if (!c->vst) { + av_free(c); + return NULL; +@@ -298,7 +356,7 @@ + return c; + } + +-int dv_get_packet(DVDemuxContext *c, AVPacket *pkt) ++int avpriv_dv_get_packet(DVDemuxContext *c, AVPacket *pkt) + { + int size = -1; + int i; +@@ -315,14 +373,14 @@ + return size; + } + +-int dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, +- uint8_t* buf, int buf_size) ++int avpriv_dv_produce_packet(DVDemuxContext *c, AVPacket *pkt, ++ uint8_t* buf, int buf_size, int64_t pos) + { + int size, i; + uint8_t *ppcm[4] = {0}; + + if (buf_size < DV_PROFILE_BYTES || +- !(c->sys = ff_dv_frame_profile(c->sys, buf, buf_size)) || ++ !(c->sys = avpriv_dv_frame_profile(c->sys, buf, buf_size)) || + buf_size < c->sys->frame_size) { + return -1; /* Broken frame, or not enough data */ + } +@@ -331,11 +389,13 @@ + /* FIXME: in case of no audio/bad audio we have to do something */ + size = dv_extract_audio_info(c, buf); + for (i = 0; i < c->ach; i++) { ++ c->audio_pkt[i].pos = pos; + c->audio_pkt[i].size = size; + c->audio_pkt[i].pts = c->abytes * 30000*8 / c->ast[i]->codec->bit_rate; + ppcm[i] = c->audio_buf[i]; + } +- dv_extract_audio(buf, ppcm, c->sys); ++ if (c->ach) ++ dv_extract_audio(buf, ppcm, c->sys); + + /* We work with 720p frames split in half, thus even frames have + * channels 0,1 and odd 2,3. */ +@@ -354,6 +414,7 @@ + size = dv_extract_video_info(c, buf); + av_init_packet(pkt); + pkt->data = buf; ++ pkt->pos = pos; + pkt->size = size; + pkt->flags |= AV_PKT_FLAG_KEY; + pkt->stream_index = c->vst->id; +@@ -368,9 +429,9 @@ + int64_t timestamp, int flags) + { + // FIXME: sys may be wrong if last dv_read_packet() failed (buffer is junk) +- const DVprofile* sys = ff_dv_codec_profile(c->vst->codec); ++ const DVprofile* sys = avpriv_dv_codec_profile(c->vst->codec); + int64_t offset; +- int64_t size = url_fsize(s->pb) - s->data_offset; ++ int64_t size = avio_size(s->pb) - s->data_offset; + int64_t max_offset = ((size-1) / sys->frame_size) * sys->frame_size; + + offset = sys->frame_size * timestamp; +@@ -400,38 +461,70 @@ + uint8_t buf[DV_MAX_FRAME_SIZE]; + } RawDVContext; + ++static int dv_read_timecode(AVFormatContext *s) { ++ int ret; ++ char timecode[32]; ++ int64_t pos = avio_tell(s->pb); ++ ++ // Read 3 DIF blocks: Header block and 2 Subcode blocks. ++ int partial_frame_size = 3 * 80; ++ uint8_t *partial_frame = av_mallocz(sizeof(*partial_frame) * ++ partial_frame_size); ++ ++ RawDVContext *c = s->priv_data; ++ ret = avio_read(s->pb, partial_frame, partial_frame_size); ++ if (ret < 0) ++ goto finish; ++ ++ if (ret < partial_frame_size) { ++ ret = -1; ++ goto finish; ++ } ++ ++ ret = dv_extract_timecode(c->dv_demux, partial_frame, timecode); ++ if (ret) ++ av_dict_set(&s->metadata, "timecode", timecode, 0); ++ else if (ret < 0) ++ av_log(s, AV_LOG_ERROR, "Detected timecode is invalid"); ++ ++finish: ++ av_free(partial_frame); ++ avio_seek(s->pb, pos, SEEK_SET); ++ return ret; ++} ++ + static int dv_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { + unsigned state, marker_pos = 0; + RawDVContext *c = s->priv_data; + +- c->dv_demux = dv_init_demux(s); ++ c->dv_demux = avpriv_dv_init_demux(s); + if (!c->dv_demux) + return -1; + +- state = get_be32(s->pb); ++ state = avio_rb32(s->pb); + while ((state & 0xffffff7f) != 0x1f07003f) { + if (url_feof(s->pb)) { + av_log(s, AV_LOG_ERROR, "Cannot find DV header.\n"); + return -1; + } + if (state == 0x003f0700 || state == 0xff3f0700) +- marker_pos = url_ftell(s->pb); +- if (state == 0xff3f0701 && url_ftell(s->pb) - marker_pos == 80) { +- url_fseek(s->pb, -163, SEEK_CUR); +- state = get_be32(s->pb); ++ marker_pos = avio_tell(s->pb); ++ if (state == 0xff3f0701 && avio_tell(s->pb) - marker_pos == 80) { ++ avio_seek(s->pb, -163, SEEK_CUR); ++ state = avio_rb32(s->pb); + break; + } +- state = (state << 8) | get_byte(s->pb); ++ state = (state << 8) | avio_r8(s->pb); + } + AV_WB32(c->buf, state); + +- if (get_buffer(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) <= 0 || +- url_fseek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) ++ if (avio_read(s->pb, c->buf + 4, DV_PROFILE_BYTES - 4) <= 0 || ++ avio_seek(s->pb, -DV_PROFILE_BYTES, SEEK_CUR) < 0) + return AVERROR(EIO); + +- c->dv_demux->sys = ff_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES); ++ c->dv_demux->sys = avpriv_dv_frame_profile(c->dv_demux->sys, c->buf, DV_PROFILE_BYTES); + if (!c->dv_demux->sys) { + av_log(s, AV_LOG_ERROR, "Can't determine profile of DV input stream.\n"); + return -1; +@@ -440,6 +533,9 @@ + s->bit_rate = av_rescale_q(c->dv_demux->sys->frame_size, (AVRational){8,1}, + c->dv_demux->sys->time_base); + ++ if (s->pb->seekable) ++ dv_read_timecode(s); ++ + return 0; + } + +@@ -449,16 +545,17 @@ + int size; + RawDVContext *c = s->priv_data; + +- size = dv_get_packet(c->dv_demux, pkt); ++ size = avpriv_dv_get_packet(c->dv_demux, pkt); + + if (size < 0) { ++ int64_t pos = avio_tell(s->pb); + if (!c->dv_demux->sys) + return AVERROR(EIO); + size = c->dv_demux->sys->frame_size; +- if (get_buffer(s->pb, c->buf, size) <= 0) ++ if (avio_read(s->pb, c->buf, size) <= 0) + return AVERROR(EIO); + +- size = dv_produce_packet(c->dv_demux, pkt, c->buf, size); ++ size = avpriv_dv_produce_packet(c->dv_demux, pkt, c->buf, size, pos); + } + + return size; +@@ -471,10 +568,11 @@ + DVDemuxContext *c = r->dv_demux; + int64_t offset = dv_frame_offset(s, c, timestamp, flags); + +- dv_offset_reset(c, offset / c->sys->frame_size); ++ if (avio_seek(s->pb, offset, SEEK_SET) < 0) ++ return -1; + +- offset = url_fseek(s->pb, offset, SEEK_SET); +- return (offset < 0) ? offset : 0; ++ dv_offset_reset(c, offset / c->sys->frame_size); ++ return 0; + } + + static int dv_read_close(AVFormatContext *s) +@@ -519,14 +617,14 @@ + + #if CONFIG_DV_DEMUXER + AVInputFormat ff_dv_demuxer = { +- "dv", +- NULL_IF_CONFIG_SMALL("DV video format"), +- sizeof(RawDVContext), +- dv_probe, +- dv_read_header, +- dv_read_packet, +- dv_read_close, +- dv_read_seek, ++ .name = "dv", ++ .long_name = NULL_IF_CONFIG_SMALL("DV video format"), ++ .priv_data_size = sizeof(RawDVContext), ++ .read_probe = dv_probe, ++ .read_header = dv_read_header, ++ .read_packet = dv_read_packet, ++ .read_close = dv_read_close, ++ .read_seek = dv_read_seek, + .extensions = "dv,dif", + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dvenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dvenc.c 2012-05-14 14:08:54.942352218 +0200 +@@ -33,19 +33,25 @@ + #include "avformat.h" + #include "internal.h" + #include "libavcodec/dvdata.h" ++#include "libavcodec/timecode.h" + #include "dv.h" + #include "libavutil/fifo.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/opt.h" + + struct DVMuxContext { ++ AVClass *av_class; + const DVprofile* sys; /* current DV profile, e.g.: 525/60, 625/50 */ + int n_ast; /* number of stereo audio streams (up to 2) */ + AVStream *ast[2]; /* stereo audio streams */ + AVFifoBuffer *audio_data[2]; /* FIFO for storing excessive amounts of PCM */ + int frames; /* current frame number */ +- time_t start_time; /* recording start time */ ++ int64_t start_time; /* recording start time */ + int has_audio; /* frame under contruction has audio */ + int has_video; /* frame under contruction has video */ + uint8_t frame_buf[DV_MAX_FRAME_SIZE]; /* frame under contruction */ ++ struct ff_timecode tc; + }; + + static const int dv_aaux_packs_dist[12][9] = { +@@ -74,33 +80,23 @@ + struct tm tc; + time_t ct; + int ltc_frame; ++ uint32_t timecode; + va_list ap; + + buf[0] = (uint8_t)pack_id; + switch (pack_id) { + case dv_timecode: +- ct = (time_t)av_rescale_rnd(c->frames, c->sys->time_base.num, +- c->sys->time_base.den, AV_ROUND_DOWN); +- brktimegm(ct, &tc); + /* + * LTC drop-frame frame counter drops two frames (0 and 1) every + * minute, unless it is exactly divisible by 10 + */ +- ltc_frame = (c->frames + 2 * ct / 60 - 2 * ct / 600) % c->sys->ltc_divisor; +- buf[1] = (0 << 7) | /* color frame: 0 - unsync; 1 - sync mode */ +- (1 << 6) | /* drop frame timecode: 0 - nondrop; 1 - drop */ +- ((ltc_frame / 10) << 4) | /* tens of frames */ +- (ltc_frame % 10); /* units of frames */ +- buf[2] = (1 << 7) | /* biphase mark polarity correction: 0 - even; 1 - odd */ +- ((tc.tm_sec / 10) << 4) | /* tens of seconds */ +- (tc.tm_sec % 10); /* units of seconds */ +- buf[3] = (1 << 7) | /* binary group flag BGF0 */ +- ((tc.tm_min / 10) << 4) | /* tens of minutes */ +- (tc.tm_min % 10); /* units of minutes */ +- buf[4] = (1 << 7) | /* binary group flag BGF2 */ +- (1 << 6) | /* binary group flag BGF1 */ +- ((tc.tm_hour / 10) << 4) | /* tens of hours */ +- (tc.tm_hour % 10); /* units of hours */ ++ ltc_frame = c->tc.start + c->frames; ++ if (c->tc.drop) ++ ltc_frame = avpriv_framenum_to_drop_timecode(ltc_frame); ++ timecode = avpriv_framenum_to_smpte_timecode(ltc_frame, c->sys->ltc_divisor, ++ c->tc.drop); ++ timecode |= 1<<23 | 1<<15 | 1<<7 | 1<<6; // biphase and binary group flags ++ AV_WB32(buf + 1, timecode); + break; + case dv_audio_source: /* AAUX source pack */ + va_start(ap, buf); +@@ -191,8 +187,8 @@ + if (of*2 >= size) + continue; + +- frame_ptr[d] = av_fifo_peek(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit +- frame_ptr[d+1] = av_fifo_peek(c->audio_data[channel], of*2); // that DV is a big-endian PCM ++ frame_ptr[d] = *av_fifo_peek2(c->audio_data[channel], of*2+1); // FIXME: maybe we have to admit ++ frame_ptr[d+1] = *av_fifo_peek2(c->audio_data[channel], of*2); // that DV is a big-endian PCM + } + frame_ptr += 16 * 80; /* 15 Video DIFs + 1 Audio DIF */ + } +@@ -289,6 +285,7 @@ + { + DVMuxContext *c = s->priv_data; + AVStream *vst = NULL; ++ AVDictionaryEntry *t; + int i; + + /* we support at most 1 video and 2 audio streams */ +@@ -323,7 +320,7 @@ + c->ast[i]->codec->channels != 2)) + goto bail_out; + } +- c->sys = ff_dv_codec_profile(vst->codec); ++ c->sys = avpriv_dv_codec_profile(vst->codec); + if (!c->sys) + goto bail_out; + +@@ -336,7 +333,13 @@ + c->frames = 0; + c->has_audio = 0; + c->has_video = 0; +- c->start_time = (time_t)s->timestamp; ++#if FF_API_TIMESTAMP ++ if (s->timestamp) ++ c->start_time = s->timestamp; ++ else ++#endif ++ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) ++ c->start_time = ff_iso8601_to_unix_time(t->value); + + for (i=0; i < c->n_ast; i++) { + if (c->ast[i] && !(c->audio_data[i]=av_fifo_alloc(100*AVCODEC_MAX_AUDIO_FRAME_SIZE))) { +@@ -363,6 +366,8 @@ + + static int dv_write_header(AVFormatContext *s) + { ++ DVMuxContext *dvc = s->priv_data; ++ + if (!dv_init_mux(s)) { + av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n" + "Make sure that you supply exactly two streams:\n" +@@ -370,6 +375,12 @@ + " (50Mbps allows an optional second audio stream)\n"); + return -1; + } ++ if (dvc->tc.str) { ++ dvc->tc.rate.num = dvc->sys->time_base.den; ++ dvc->tc.rate.den = dvc->sys->time_base.num; ++ if (avpriv_init_smpte_timecode(s, &dvc->tc) < 0) ++ return -1; ++ } + return 0; + } + +@@ -381,8 +392,8 @@ + fsize = dv_assemble_frame(s->priv_data, s->streams[pkt->stream_index], + pkt->data, pkt->size, &frame); + if (fsize > 0) { +- put_buffer(s->pb, frame, fsize); +- put_flush_packet(s->pb); ++ avio_write(s->pb, frame, fsize); ++ avio_flush(s->pb); + } + return 0; + } +@@ -399,15 +410,25 @@ + return 0; + } + ++static const AVClass class = { ++ .class_name = "dv", ++ .item_name = av_default_item_name, ++ .version = LIBAVUTIL_VERSION_INT, ++ .option = (const AVOption[]){ ++ {TIMECODE_OPT(DVMuxContext, AV_OPT_FLAG_ENCODING_PARAM)}, ++ {NULL}, ++ }, ++}; ++ + AVOutputFormat ff_dv_muxer = { +- "dv", +- NULL_IF_CONFIG_SMALL("DV video format"), +- NULL, +- "dv", +- sizeof(DVMuxContext), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_DVVIDEO, +- dv_write_header, +- dv_write_packet, +- dv_write_trailer, ++ .name = "dv", ++ .long_name = NULL_IF_CONFIG_SMALL("DV video format"), ++ .extensions = "dv", ++ .priv_data_size = sizeof(DVMuxContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_DVVIDEO, ++ .write_header = dv_write_header, ++ .write_packet = dv_write_packet, ++ .write_trailer = dv_write_trailer, ++ .priv_class = &class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dv.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dv.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dv.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dv.h 2012-05-14 14:08:54.940352178 +0200 +@@ -31,9 +31,9 @@ + #include "avformat.h" + + typedef struct DVDemuxContext DVDemuxContext; +-DVDemuxContext* dv_init_demux(AVFormatContext* s); +-int dv_get_packet(DVDemuxContext*, AVPacket *); +-int dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int); ++DVDemuxContext* avpriv_dv_init_demux(AVFormatContext* s); ++int avpriv_dv_get_packet(DVDemuxContext*, AVPacket *); ++int avpriv_dv_produce_packet(DVDemuxContext*, AVPacket*, uint8_t*, int, int64_t); + void dv_offset_reset(DVDemuxContext *c, int64_t frame_offset); + + typedef struct DVMuxContext DVMuxContext; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dxa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dxa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/dxa.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/dxa.c 2012-05-14 14:08:54.943352238 +0200 +@@ -21,6 +21,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + + #define DXA_EXTRA_SIZE 9 +@@ -52,7 +53,7 @@ + + static int dxa_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + DXAContext *c = s->priv_data; + AVStream *st, *ast; + uint32_t tag; +@@ -60,18 +61,19 @@ + int w, h; + int num, den; + int flags; ++ int ret; + +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('D', 'E', 'X', 'A')) + return -1; +- flags = get_byte(pb); +- c->frames = get_be16(pb); ++ flags = avio_r8(pb); ++ c->frames = avio_rb16(pb); + if(!c->frames){ + av_log(s, AV_LOG_ERROR, "File contains no frames ???\n"); + return -1; + } + +- fps = get_be32(pb); ++ fps = avio_rb32(pb); + if(fps > 0){ + den = 1000; + num = fps; +@@ -82,40 +84,42 @@ + den = 10; + num = 1; + } +- w = get_be16(pb); +- h = get_be16(pb); ++ w = avio_rb16(pb); ++ h = avio_rb16(pb); + c->has_sound = 0; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + + // Parse WAV data header +- if(get_le32(pb) == MKTAG('W', 'A', 'V', 'E')){ ++ if(avio_rl32(pb) == MKTAG('W', 'A', 'V', 'E')){ + uint32_t size, fsize; + c->has_sound = 1; +- size = get_be32(pb); +- c->vidpos = url_ftell(pb) + size; +- url_fskip(pb, 16); +- fsize = get_le32(pb); ++ size = avio_rb32(pb); ++ c->vidpos = avio_tell(pb) + size; ++ avio_skip(pb, 16); ++ fsize = avio_rl32(pb); + +- ast = av_new_stream(s, 0); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return -1; +- ff_get_wav_header(pb, ast->codec, fsize); ++ ret = ff_get_wav_header(pb, ast->codec, fsize); ++ if (ret < 0) ++ return ret; + // find 'data' chunk +- while(url_ftell(pb) < c->vidpos && !url_feof(pb)){ +- tag = get_le32(pb); +- fsize = get_le32(pb); ++ while(avio_tell(pb) < c->vidpos && !url_feof(pb)){ ++ tag = avio_rl32(pb); ++ fsize = avio_rl32(pb); + if(tag == MKTAG('d', 'a', 't', 'a')) break; +- url_fskip(pb, fsize); ++ avio_skip(pb, fsize); + } + c->bpc = (fsize + c->frames - 1) / c->frames; + if(ast->codec->block_align) + c->bpc = ((c->bpc + ast->codec->block_align - 1) / ast->codec->block_align) * ast->codec->block_align; + c->bytes_left = fsize; +- c->wavpos = url_ftell(pb); +- url_fseek(pb, c->vidpos, SEEK_SET); ++ c->wavpos = avio_tell(pb); ++ avio_seek(pb, c->vidpos, SEEK_SET); + } + + /* now we are ready: build format streams */ +@@ -124,7 +128,7 @@ + st->codec->width = w; + st->codec->height = h; + av_reduce(&den, &num, den, num, (1UL<<31)-1); +- av_set_pts_info(st, 33, num, den); ++ avpriv_set_pts_info(st, 33, num, den); + /* flags & 0x80 means that image is interlaced, + * flags & 0x40 means that image has double height + * either way set true height +@@ -133,7 +137,7 @@ + st->codec->height >>= 1; + } + c->readvid = !c->has_sound; +- c->vidpos = url_ftell(pb); ++ c->vidpos = avio_tell(pb); + s->start_time = 0; + s->duration = (int64_t)c->frames * AV_TIME_BASE * num / den; + av_log(s, AV_LOG_DEBUG, "%d frame(s)\n",c->frames); +@@ -151,19 +155,19 @@ + + if(!c->readvid && c->has_sound && c->bytes_left){ + c->readvid = 1; +- url_fseek(s->pb, c->wavpos, SEEK_SET); ++ avio_seek(s->pb, c->wavpos, SEEK_SET); + size = FFMIN(c->bytes_left, c->bpc); + ret = av_get_packet(s->pb, pkt, size); + pkt->stream_index = 1; + if(ret != size) + return AVERROR(EIO); + c->bytes_left -= size; +- c->wavpos = url_ftell(s->pb); ++ c->wavpos = avio_tell(s->pb); + return 0; + } +- url_fseek(s->pb, c->vidpos, SEEK_SET); ++ avio_seek(s->pb, c->vidpos, SEEK_SET); + while(!url_feof(s->pb) && c->frames){ +- get_buffer(s->pb, buf, 4); ++ avio_read(s->pb, buf, 4); + switch(AV_RL32(buf)){ + case MKTAG('N', 'U', 'L', 'L'): + if(av_new_packet(pkt, 4 + pal_size) < 0) +@@ -172,16 +176,16 @@ + if(pal_size) memcpy(pkt->data, pal, pal_size); + memcpy(pkt->data + pal_size, buf, 4); + c->frames--; +- c->vidpos = url_ftell(s->pb); ++ c->vidpos = avio_tell(s->pb); + c->readvid = 0; + return 0; + case MKTAG('C', 'M', 'A', 'P'): + pal_size = 768+4; + memcpy(pal, buf, 4); +- get_buffer(s->pb, pal + 4, 768); ++ avio_read(s->pb, pal + 4, 768); + break; + case MKTAG('F', 'R', 'A', 'M'): +- get_buffer(s->pb, buf + 4, DXA_EXTRA_SIZE - 4); ++ avio_read(s->pb, buf + 4, DXA_EXTRA_SIZE - 4); + size = AV_RB32(buf + 5); + if(size > 0xFFFFFF){ + av_log(s, AV_LOG_ERROR, "Frame size is too big: %d\n", size); +@@ -190,7 +194,7 @@ + if(av_new_packet(pkt, size + DXA_EXTRA_SIZE + pal_size) < 0) + return AVERROR(ENOMEM); + memcpy(pkt->data + pal_size, buf, DXA_EXTRA_SIZE); +- ret = get_buffer(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); ++ ret = avio_read(s->pb, pkt->data + DXA_EXTRA_SIZE + pal_size, size); + if(ret != size){ + av_free_packet(pkt); + return AVERROR(EIO); +@@ -198,7 +202,7 @@ + if(pal_size) memcpy(pkt->data, pal, pal_size); + pkt->stream_index = 0; + c->frames--; +- c->vidpos = url_ftell(s->pb); ++ c->vidpos = avio_tell(s->pb); + c->readvid = 0; + return 0; + default: +@@ -210,10 +214,10 @@ + } + + AVInputFormat ff_dxa_demuxer = { +- "dxa", +- NULL_IF_CONFIG_SMALL("DXA"), +- sizeof(DXAContext), +- dxa_probe, +- dxa_read_header, +- dxa_read_packet, ++ .name = "dxa", ++ .long_name = NULL_IF_CONFIG_SMALL("DXA"), ++ .priv_data_size = sizeof(DXAContext), ++ .read_probe = dxa_probe, ++ .read_header = dxa_read_header, ++ .read_packet = dxa_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/eacdata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/eacdata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/eacdata.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/eacdata.c 2012-05-14 14:08:54.943352238 +0200 +@@ -29,6 +29,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + + typedef struct { + unsigned int channels; +@@ -39,7 +40,7 @@ + { + const uint8_t *b = p->buf; + +- if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C)) ++ if (b[0] == 0x04 && (b[1] == 0x00 || b[1] == 0x04 || b[1] == 0x0C || b[1] == 0x14)) + return AVPROBE_SCORE_MAX/8; + return 0; + } +@@ -47,32 +48,36 @@ + static int cdata_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + CdataDemuxContext *cdata = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int sample_rate, header; + AVStream *st; ++ int64_t channel_layout = 0; + +- header = get_be16(pb); ++ header = avio_rb16(pb); + switch (header) { + case 0x0400: cdata->channels = 1; break; + case 0x0404: cdata->channels = 2; break; +- case 0x040C: cdata->channels = 4; break; ++ case 0x040C: cdata->channels = 4; channel_layout = AV_CH_LAYOUT_QUAD; break; ++ case 0x0414: cdata->channels = 6; channel_layout = AV_CH_LAYOUT_5POINT1_BACK; break; + default: + av_log(s, AV_LOG_INFO, "unknown header 0x%04x\n", header); + return -1; + }; + +- sample_rate = get_be16(pb); +- url_fskip(pb, 12); ++ sample_rate = avio_rb16(pb); ++ avio_skip(pb, (avio_r8(pb) & 0x20) ? 15 : 11); + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->codec_id = CODEC_ID_ADPCM_EA_XAS; + st->codec->channels = cdata->channels; ++ st->codec->channel_layout = channel_layout; + st->codec->sample_rate = sample_rate; +- av_set_pts_info(st, 64, 1, sample_rate); ++ st->codec->sample_fmt = AV_SAMPLE_FMT_S16; ++ avpriv_set_pts_info(st, 64, 1, sample_rate); + + cdata->audio_pts = 0; + return 0; +@@ -91,11 +96,11 @@ + } + + AVInputFormat ff_ea_cdata_demuxer = { +- "ea_cdata", +- NULL_IF_CONFIG_SMALL("Electronic Arts cdata"), +- sizeof(CdataDemuxContext), +- cdata_probe, +- cdata_read_header, +- cdata_read_packet, ++ .name = "ea_cdata", ++ .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts cdata"), ++ .priv_data_size = sizeof(CdataDemuxContext), ++ .read_probe = cdata_probe, ++ .read_header = cdata_read_header, ++ .read_packet = cdata_read_packet, + .extensions = "cdata", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/electronicarts.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/electronicarts.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/electronicarts.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/electronicarts.c 2012-05-14 14:08:54.945352279 +0200 +@@ -27,6 +27,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define SCHl_TAG MKTAG('S', 'C', 'H', 'l') + #define SEAD_TAG MKTAG('S', 'E', 'A', 'D') /* Sxxx header */ +@@ -77,16 +78,16 @@ + int num_samples; + } EaDemuxContext; + +-static uint32_t read_arbitary(ByteIOContext *pb) { ++static uint32_t read_arbitary(AVIOContext *pb) { + uint8_t size, byte; + int i; + uint32_t word; + +- size = get_byte(pb); ++ size = avio_r8(pb); + + word = 0; + for (i = 0; i < size; i++) { +- byte = get_byte(pb); ++ byte = avio_r8(pb); + word <<= 8; + word |= byte; + } +@@ -102,7 +103,7 @@ + { + int inHeader = 1; + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int compression_type = -1, revision = -1, revision2 = -1; + + ea->bytes = 2; +@@ -112,7 +113,7 @@ + while (!url_feof(pb) && inHeader) { + int inSubheader; + uint8_t byte; +- byte = get_byte(pb); ++ byte = avio_r8(pb); + + switch (byte) { + case 0xFD: +@@ -120,7 +121,7 @@ + inSubheader = 1; + while (!url_feof(pb) && inSubheader) { + uint8_t subbyte; +- subbyte = get_byte(pb); ++ subbyte = avio_r8(pb); + + switch (subbyte) { + case 0x80: +@@ -215,14 +216,14 @@ + static int process_audio_header_eacs(AVFormatContext *s) + { + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int compression_type; + +- ea->sample_rate = ea->big_endian ? get_be32(pb) : get_le32(pb); +- ea->bytes = get_byte(pb); /* 1=8-bit, 2=16-bit */ +- ea->num_channels = get_byte(pb); +- compression_type = get_byte(pb); +- url_fskip(pb, 13); ++ ea->sample_rate = ea->big_endian ? avio_rb32(pb) : avio_rl32(pb); ++ ea->bytes = avio_r8(pb); /* 1=8-bit, 2=16-bit */ ++ ea->num_channels = avio_r8(pb); ++ compression_type = avio_r8(pb); ++ avio_skip(pb, 13); + + switch (compression_type) { + case 0: +@@ -247,11 +248,11 @@ + static int process_audio_header_sead(AVFormatContext *s) + { + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- ea->sample_rate = get_le32(pb); +- ea->bytes = get_le32(pb); /* 1=8-bit, 2=16-bit */ +- ea->num_channels = get_le32(pb); ++ ea->sample_rate = avio_rl32(pb); ++ ea->bytes = avio_rl32(pb); /* 1=8-bit, 2=16-bit */ ++ ea->num_channels = avio_rl32(pb); + ea->audio_codec = CODEC_ID_ADPCM_IMA_EA_SEAD; + + return 1; +@@ -260,10 +261,10 @@ + static int process_video_header_mdec(AVFormatContext *s) + { + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; +- url_fskip(pb, 4); +- ea->width = get_le16(pb); +- ea->height = get_le16(pb); ++ AVIOContext *pb = s->pb; ++ avio_skip(pb, 4); ++ ea->width = avio_rl16(pb); ++ ea->height = avio_rl16(pb); + ea->time_base = (AVRational){1,15}; + ea->video_codec = CODEC_ID_MDEC; + return 1; +@@ -272,11 +273,11 @@ + static int process_video_header_vp6(AVFormatContext *s) + { + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- url_fskip(pb, 16); +- ea->time_base.den = get_le32(pb); +- ea->time_base.num = get_le32(pb); ++ avio_skip(pb, 16); ++ ea->time_base.den = avio_rl32(pb); ++ ea->time_base.num = avio_rl32(pb); + ea->video_codec = CODEC_ID_VP6; + + return 1; +@@ -289,15 +290,15 @@ + static int process_ea_header(AVFormatContext *s) { + uint32_t blockid, size = 0; + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i; + + for (i=0; i<5 && (!ea->audio_codec || !ea->video_codec); i++) { +- unsigned int startpos = url_ftell(pb); ++ unsigned int startpos = avio_tell(pb); + int err = 0; + +- blockid = get_le32(pb); +- size = get_le32(pb); ++ blockid = avio_rl32(pb); ++ size = avio_rl32(pb); + if (i == 0) + ea->big_endian = size > 0x000FFFFF; + if (ea->big_endian) +@@ -305,7 +306,7 @@ + + switch (blockid) { + case ISNh_TAG: +- if (get_le32(pb) != EACS_TAG) { ++ if (avio_rl32(pb) != EACS_TAG) { + av_log (s, AV_LOG_ERROR, "unknown 1SNh headerid\n"); + return 0; + } +@@ -314,9 +315,9 @@ + + case SCHl_TAG : + case SHEN_TAG : +- blockid = get_le32(pb); ++ blockid = avio_rl32(pb); + if (blockid == GSTR_TAG) { +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + } else if ((blockid & 0xFFFF)!=PT00_TAG) { + av_log (s, AV_LOG_ERROR, "unknown SCHl headerid\n"); + return 0; +@@ -330,12 +331,10 @@ + + case MVIh_TAG : + ea->video_codec = CODEC_ID_CMV; +- ea->time_base = (AVRational){0,0}; + break; + + case kVGT_TAG: + ea->video_codec = CODEC_ID_TGV; +- ea->time_base = (AVRational){0,0}; + break; + + case mTCD_TAG : +@@ -369,10 +368,10 @@ + return err; + } + +- url_fseek(pb, startpos + size, SEEK_SET); ++ avio_seek(pb, startpos + size, SEEK_SET); + } + +- url_fseek(pb, 0, SEEK_SET); ++ avio_seek(pb, 0, SEEK_SET); + + return 1; + } +@@ -405,19 +404,23 @@ + EaDemuxContext *ea = s->priv_data; + AVStream *st; + +- if (!process_ea_header(s)) ++ if (process_ea_header(s)<=0) + return AVERROR(EIO); + + if (ea->video_codec) { + /* initialize the video decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + ea->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = ea->video_codec; ++ // parsing is necessary to make FFmpeg generate correct timestamps ++ if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) ++ st->need_parsing = AVSTREAM_PARSE_HEADERS; + st->codec->codec_tag = 0; /* no fourcc */ +- st->codec->time_base = ea->time_base; ++ if (ea->time_base.num) ++ avpriv_set_pts_info(st, 64, ea->time_base.num, ea->time_base.den); + st->codec->width = ea->width; + st->codec->height = ea->height; + } +@@ -433,12 +436,17 @@ + ea->audio_codec = 0; + return 1; + } ++ if (ea->bytes <= 0) { ++ av_log(s, AV_LOG_ERROR, "Invalid number of bytes per sample: %d\n", ea->bytes); ++ ea->audio_codec = CODEC_ID_NONE; ++ return 1; ++ } + + /* initialize the audio decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, ea->sample_rate); ++ avpriv_set_pts_info(st, 33, 1, ea->sample_rate); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = ea->audio_codec; + st->codec->codec_tag = 0; /* no tag */ +@@ -459,7 +467,7 @@ + AVPacket *pkt) + { + EaDemuxContext *ea = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret = 0; + int packet_read = 0; + unsigned int chunk_type, chunk_size; +@@ -467,26 +475,26 @@ + int av_uninit(num_samples); + + while (!packet_read) { +- chunk_type = get_le32(pb); +- chunk_size = (ea->big_endian ? get_be32(pb) : get_le32(pb)) - 8; ++ chunk_type = avio_rl32(pb); ++ chunk_size = (ea->big_endian ? avio_rb32(pb) : avio_rl32(pb)) - 8; + + switch (chunk_type) { + /* audio data */ + case ISNh_TAG: + /* header chunk also contains data; skip over the header portion*/ +- url_fskip(pb, 32); ++ avio_skip(pb, 32); + chunk_size -= 32; + case ISNd_TAG: + case SCDl_TAG: + case SNDC_TAG: + case SDEN_TAG: + if (!ea->audio_codec) { +- url_fskip(pb, chunk_size); ++ avio_skip(pb, chunk_size); + break; + } else if (ea->audio_codec == CODEC_ID_PCM_S16LE_PLANAR || + ea->audio_codec == CODEC_ID_MP3) { +- num_samples = get_le32(pb); +- url_fskip(pb, 8); ++ num_samples = avio_rl32(pb); ++ avio_skip(pb, 8); + chunk_size -= 12; + } + ret = av_get_packet(pb, pkt, chunk_size); +@@ -536,12 +544,12 @@ + case fVGT_TAG: + case MADm_TAG: + case MADe_TAG: +- url_fseek(pb, -8, SEEK_CUR); // include chunk preamble ++ avio_seek(pb, -8, SEEK_CUR); // include chunk preamble + chunk_size += 8; + goto get_video_packet; + + case mTCD_TAG: +- url_fseek(pb, 8, SEEK_CUR); // skip ea dct header ++ avio_skip(pb, 8); // skip ea dct header + chunk_size -= 8; + goto get_video_packet; + +@@ -560,7 +568,7 @@ + break; + + default: +- url_fseek(pb, chunk_size, SEEK_CUR); ++ avio_skip(pb, chunk_size); + break; + } + } +@@ -569,10 +577,10 @@ + } + + AVInputFormat ff_ea_demuxer = { +- "ea", +- NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia Format"), +- sizeof(EaDemuxContext), +- ea_probe, +- ea_read_header, +- ea_read_packet, ++ .name = "ea", ++ .long_name = NULL_IF_CONFIG_SMALL("Electronic Arts Multimedia Format"), ++ .priv_data_size = sizeof(EaDemuxContext), ++ .read_probe = ea_probe, ++ .read_header = ea_read_header, ++ .read_packet = ea_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmdec.c 2012-05-14 14:08:54.946352299 +0200 +@@ -20,7 +20,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + #include "ffm.h" + #if CONFIG_FFSERVER + #include +@@ -65,7 +67,7 @@ + len = ffm->packet_end - ffm->packet_ptr; + if (size <= len) + return 1; +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + if (!ffm->write_index) { + if (pos == ffm->file_size) + return AVERROR_EOF; +@@ -95,7 +97,7 @@ + av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n"); + return -1; + } +- state = (state << 8) | get_byte(s->pb); ++ state = (state << 8) | avio_r8(s->pb); + } + return 0; + } +@@ -105,7 +107,7 @@ + uint8_t *buf, int size, int header) + { + FFMContext *ffm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int len, fill_size, size1, frame_offset, id; + + size1 = size; +@@ -117,17 +119,22 @@ + if (len > size) + len = size; + if (len == 0) { +- if (url_ftell(pb) == ffm->file_size) +- url_fseek(pb, ffm->packet_size, SEEK_SET); ++ if (avio_tell(pb) == ffm->file_size) ++ avio_seek(pb, ffm->packet_size, SEEK_SET); + retry_read: +- id = get_be16(pb); /* PACKET_ID */ ++ if (pb->buffer_size != ffm->packet_size) { ++ int64_t tell = avio_tell(pb); ++ url_setbufsize(pb, ffm->packet_size); ++ avio_seek(pb, tell, SEEK_SET); ++ } ++ id = avio_rb16(pb); /* PACKET_ID */ + if (id != PACKET_ID) + if (ffm_resync(s, id) < 0) + return -1; +- fill_size = get_be16(pb); +- ffm->dts = get_be64(pb); +- frame_offset = get_be16(pb); +- get_buffer(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); ++ fill_size = avio_rb16(pb); ++ ffm->dts = avio_rb64(pb); ++ frame_offset = avio_rb16(pb); ++ avio_read(pb, ffm->packet, ffm->packet_size - FFM_HEADER_SIZE); + ffm->packet_end = ffm->packet + (ffm->packet_size - FFM_HEADER_SIZE - fill_size); + if (ffm->packet_end < ffm->packet || frame_offset < 0) + return -1; +@@ -136,8 +143,8 @@ + if (ffm->first_packet || (frame_offset & 0x8000)) { + if (!frame_offset) { + /* This packet has no frame headers in it */ +- if (url_ftell(pb) >= ffm->packet_size * 3) { +- url_fseek(pb, -ffm->packet_size * 2, SEEK_CUR); ++ if (avio_tell(pb) >= ffm->packet_size * 3) { ++ avio_seek(pb, -ffm->packet_size * 2, SEEK_CUR); + goto retry_read; + } + /* This is bad, we cannot find a valid frame header */ +@@ -163,47 +170,41 @@ + return size1 - size; + } + +-//#define DEBUG_SEEK +- + /* ensure that acutal seeking happens between FFM_PACKET_SIZE + and file_size - FFM_PACKET_SIZE */ +-static void ffm_seek1(AVFormatContext *s, int64_t pos1) ++static int64_t ffm_seek1(AVFormatContext *s, int64_t pos1) + { + FFMContext *ffm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; + + pos = FFMIN(pos1, ffm->file_size - FFM_PACKET_SIZE); + pos = FFMAX(pos, FFM_PACKET_SIZE); +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); +-#endif +- url_fseek(pb, pos, SEEK_SET); ++ av_dlog(s, "seek to %"PRIx64" -> %"PRIx64"\n", pos1, pos); ++ return avio_seek(pb, pos, SEEK_SET); + } + + static int64_t get_dts(AVFormatContext *s, int64_t pos) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t dts; + + ffm_seek1(s, pos); +- url_fskip(pb, 4); +- dts = get_be64(pb); +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "dts=%0.6f\n", dts / 1000000.0); +-#endif ++ avio_skip(pb, 4); ++ dts = avio_rb64(pb); ++ av_dlog(s, "dts=%0.6f\n", dts / 1000000.0); + return dts; + } + + static void adjust_write_index(AVFormatContext *s) + { + FFMContext *ffm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pts; + //int64_t orig_write_index = ffm->write_index; + int64_t pos_min, pos_max; + int64_t pts_start; +- int64_t ptr = url_ftell(pb); ++ int64_t ptr = avio_tell(pb); + + + pos_min = 0; +@@ -248,7 +249,7 @@ + //printf("pts range %0.6f - %0.6f\n", get_dts(s, 0) / 1000000. , get_dts(s, ffm->file_size - 2 * FFM_PACKET_SIZE) / 1000000. ); + + end: +- url_fseek(pb, ptr, SEEK_SET); ++ avio_seek(pb, ptr, SEEK_SET); + } + + +@@ -267,121 +268,121 @@ + { + FFMContext *ffm = s->priv_data; + AVStream *st; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *codec; + int i, nb_streams; + uint32_t tag; + + /* header */ +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('F', 'F', 'M', '1')) + goto fail; +- ffm->packet_size = get_be32(pb); ++ ffm->packet_size = avio_rb32(pb); + if (ffm->packet_size != FFM_PACKET_SIZE) + goto fail; +- ffm->write_index = get_be64(pb); ++ ffm->write_index = avio_rb64(pb); + /* get also filesize */ +- if (!url_is_streamed(pb)) { +- ffm->file_size = url_fsize(pb); ++ if (pb->seekable) { ++ ffm->file_size = avio_size(pb); + if (ffm->write_index) + adjust_write_index(s); + } else { + ffm->file_size = (UINT64_C(1) << 63) - 1; + } + +- nb_streams = get_be32(pb); +- get_be32(pb); /* total bitrate */ ++ nb_streams = avio_rb32(pb); ++ avio_rb32(pb); /* total bitrate */ + /* read each stream */ + for(i=0;icodec; + /* generic info */ +- codec->codec_id = get_be32(pb); +- codec->codec_type = get_byte(pb); /* codec_type */ +- codec->bit_rate = get_be32(pb); +- st->quality = get_be32(pb); +- codec->flags = get_be32(pb); +- codec->flags2 = get_be32(pb); +- codec->debug = get_be32(pb); ++ codec->codec_id = avio_rb32(pb); ++ codec->codec_type = avio_r8(pb); /* codec_type */ ++ codec->bit_rate = avio_rb32(pb); ++ codec->flags = avio_rb32(pb); ++ codec->flags2 = avio_rb32(pb); ++ codec->debug = avio_rb32(pb); + /* specific info */ + switch(codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: +- codec->time_base.num = get_be32(pb); +- codec->time_base.den = get_be32(pb); +- codec->width = get_be16(pb); +- codec->height = get_be16(pb); +- codec->gop_size = get_be16(pb); +- codec->pix_fmt = get_be32(pb); +- codec->qmin = get_byte(pb); +- codec->qmax = get_byte(pb); +- codec->max_qdiff = get_byte(pb); +- codec->qcompress = get_be16(pb) / 10000.0; +- codec->qblur = get_be16(pb) / 10000.0; +- codec->bit_rate_tolerance = get_be32(pb); +- codec->rc_eq = av_strdup(get_strz(pb, rc_eq_buf, sizeof(rc_eq_buf))); +- codec->rc_max_rate = get_be32(pb); +- codec->rc_min_rate = get_be32(pb); +- codec->rc_buffer_size = get_be32(pb); +- codec->i_quant_factor = av_int2dbl(get_be64(pb)); +- codec->b_quant_factor = av_int2dbl(get_be64(pb)); +- codec->i_quant_offset = av_int2dbl(get_be64(pb)); +- codec->b_quant_offset = av_int2dbl(get_be64(pb)); +- codec->dct_algo = get_be32(pb); +- codec->strict_std_compliance = get_be32(pb); +- codec->max_b_frames = get_be32(pb); +- codec->luma_elim_threshold = get_be32(pb); +- codec->chroma_elim_threshold = get_be32(pb); +- codec->mpeg_quant = get_be32(pb); +- codec->intra_dc_precision = get_be32(pb); +- codec->me_method = get_be32(pb); +- codec->mb_decision = get_be32(pb); +- codec->nsse_weight = get_be32(pb); +- codec->frame_skip_cmp = get_be32(pb); +- codec->rc_buffer_aggressivity = av_int2dbl(get_be64(pb)); +- codec->codec_tag = get_be32(pb); +- codec->thread_count = get_byte(pb); +- codec->coder_type = get_be32(pb); +- codec->me_cmp = get_be32(pb); +- codec->partitions = get_be32(pb); +- codec->me_subpel_quality = get_be32(pb); +- codec->me_range = get_be32(pb); +- codec->keyint_min = get_be32(pb); +- codec->scenechange_threshold = get_be32(pb); +- codec->b_frame_strategy = get_be32(pb); +- codec->qcompress = av_int2dbl(get_be64(pb)); +- codec->qblur = av_int2dbl(get_be64(pb)); +- codec->max_qdiff = get_be32(pb); +- codec->refs = get_be32(pb); +- codec->directpred = get_be32(pb); ++ codec->time_base.num = avio_rb32(pb); ++ codec->time_base.den = avio_rb32(pb); ++ codec->width = avio_rb16(pb); ++ codec->height = avio_rb16(pb); ++ codec->gop_size = avio_rb16(pb); ++ codec->pix_fmt = avio_rb32(pb); ++ codec->qmin = avio_r8(pb); ++ codec->qmax = avio_r8(pb); ++ codec->max_qdiff = avio_r8(pb); ++ codec->qcompress = avio_rb16(pb) / 10000.0; ++ codec->qblur = avio_rb16(pb) / 10000.0; ++ codec->bit_rate_tolerance = avio_rb32(pb); ++ avio_get_str(pb, INT_MAX, rc_eq_buf, sizeof(rc_eq_buf)); ++ codec->rc_eq = av_strdup(rc_eq_buf); ++ codec->rc_max_rate = avio_rb32(pb); ++ codec->rc_min_rate = avio_rb32(pb); ++ codec->rc_buffer_size = avio_rb32(pb); ++ codec->i_quant_factor = av_int2double(avio_rb64(pb)); ++ codec->b_quant_factor = av_int2double(avio_rb64(pb)); ++ codec->i_quant_offset = av_int2double(avio_rb64(pb)); ++ codec->b_quant_offset = av_int2double(avio_rb64(pb)); ++ codec->dct_algo = avio_rb32(pb); ++ codec->strict_std_compliance = avio_rb32(pb); ++ codec->max_b_frames = avio_rb32(pb); ++ codec->luma_elim_threshold = avio_rb32(pb); ++ codec->chroma_elim_threshold = avio_rb32(pb); ++ codec->mpeg_quant = avio_rb32(pb); ++ codec->intra_dc_precision = avio_rb32(pb); ++ codec->me_method = avio_rb32(pb); ++ codec->mb_decision = avio_rb32(pb); ++ codec->nsse_weight = avio_rb32(pb); ++ codec->frame_skip_cmp = avio_rb32(pb); ++ codec->rc_buffer_aggressivity = av_int2double(avio_rb64(pb)); ++ codec->codec_tag = avio_rb32(pb); ++ codec->thread_count = avio_r8(pb); ++ codec->coder_type = avio_rb32(pb); ++ codec->me_cmp = avio_rb32(pb); ++ codec->partitions = avio_rb32(pb); ++ codec->me_subpel_quality = avio_rb32(pb); ++ codec->me_range = avio_rb32(pb); ++ codec->keyint_min = avio_rb32(pb); ++ codec->scenechange_threshold = avio_rb32(pb); ++ codec->b_frame_strategy = avio_rb32(pb); ++ codec->qcompress = av_int2double(avio_rb64(pb)); ++ codec->qblur = av_int2double(avio_rb64(pb)); ++ codec->max_qdiff = avio_rb32(pb); ++ codec->refs = avio_rb32(pb); ++ codec->directpred = avio_rb32(pb); + break; + case AVMEDIA_TYPE_AUDIO: +- codec->sample_rate = get_be32(pb); +- codec->channels = get_le16(pb); +- codec->frame_size = get_le16(pb); +- codec->sample_fmt = (int16_t) get_le16(pb); ++ codec->sample_rate = avio_rb32(pb); ++ codec->channels = avio_rl16(pb); ++ codec->frame_size = avio_rl16(pb); ++ codec->sample_fmt = (int16_t) avio_rl16(pb); + break; + default: + goto fail; + } + if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) { +- codec->extradata_size = get_be32(pb); ++ codec->extradata_size = avio_rb32(pb); + codec->extradata = av_malloc(codec->extradata_size); + if (!codec->extradata) + return AVERROR(ENOMEM); +- get_buffer(pb, codec->extradata, codec->extradata_size); ++ avio_read(pb, codec->extradata, codec->extradata_size); + } + } + + /* get until end of block reached */ +- while ((url_ftell(pb) % ffm->packet_size) != 0) +- get_byte(pb); ++ while ((avio_tell(pb) % ffm->packet_size) != 0) ++ avio_r8(pb); + + /* init packet demux */ + ffm->packet_ptr = ffm->packet; +@@ -409,16 +410,13 @@ + return ret; + + av_dlog(s, "pos=%08"PRIx64" spos=%"PRIx64", write_index=%"PRIx64" size=%"PRIx64"\n", +- url_ftell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size); ++ avio_tell(s->pb), s->pb->pos, ffm->write_index, ffm->file_size); + if (ffm_read_data(s, ffm->header, FRAME_HEADER_SIZE, 1) != + FRAME_HEADER_SIZE) + return -1; + if (ffm->header[1] & FLAG_DTS) + if (ffm_read_data(s, ffm->header+16, 4, 1) != 4) + return -1; +-#if 0 +- av_hexdump_log(s, AV_LOG_DEBUG, ffm->header, FRAME_HEADER_SIZE); +-#endif + ffm->read_state = READ_DATA; + /* fall thru */ + case READ_DATA: +@@ -436,7 +434,7 @@ + ffm->read_state = READ_HEADER; + return -1; + } +- pkt->pos = url_ftell(s->pb); ++ pkt->pos = avio_tell(s->pb); + if (ffm->header[1] & FLAG_KEY_FRAME) + pkt->flags |= AV_PKT_FLAG_KEY; + +@@ -467,16 +465,28 @@ + int64_t pts_min, pts_max, pts; + double pos1; + +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0); +-#endif ++ av_dlog(s, "wanted_pts=%0.6f\n", wanted_pts / 1000000.0); + /* find the position using linear interpolation (better than + dichotomy in typical cases) */ +- pos_min = FFM_PACKET_SIZE; +- pos_max = ffm->file_size - FFM_PACKET_SIZE; ++ if (ffm->write_index && ffm->write_index < ffm->file_size) { ++ if (get_dts(s, FFM_PACKET_SIZE) < wanted_pts) { ++ pos_min = FFM_PACKET_SIZE; ++ pos_max = ffm->write_index - FFM_PACKET_SIZE; ++ } else { ++ pos_min = ffm->write_index; ++ pos_max = ffm->file_size - FFM_PACKET_SIZE; ++ } ++ } else { ++ pos_min = FFM_PACKET_SIZE; ++ pos_max = ffm->file_size - FFM_PACKET_SIZE; ++ } + while (pos_min <= pos_max) { + pts_min = get_dts(s, pos_min); + pts_max = get_dts(s, pos_max); ++ if (pts_min > wanted_pts || pts_max < wanted_pts) { ++ pos = pts_min > wanted_pts ? pos_min : pos_max; ++ goto found; ++ } + /* linear interpolation */ + pos1 = (double)(pos_max - pos_min) * (double)(wanted_pts - pts_min) / + (double)(pts_max - pts_min); +@@ -498,7 +508,8 @@ + pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; + + found: +- ffm_seek1(s, pos); ++ if (ffm_seek1(s, pos) < 0) ++ return -1; + + /* reset read state */ + ffm->read_state = READ_HEADER; +@@ -519,12 +530,12 @@ + } + + AVInputFormat ff_ffm_demuxer = { +- "ffm", +- NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"), +- sizeof(FFMContext), +- ffm_probe, +- ffm_read_header, +- ffm_read_packet, +- ffm_close, +- ffm_seek, ++ .name = "ffm", ++ .long_name = NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"), ++ .priv_data_size = sizeof(FFMContext), ++ .read_probe = ffm_probe, ++ .read_header = ffm_read_header, ++ .read_packet = ffm_read_packet, ++ .read_close = ffm_close, ++ .read_seek = ffm_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmenc.c 2012-05-14 14:08:54.947352319 +0200 +@@ -20,31 +20,33 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + #include "ffm.h" + + static void flush_packet(AVFormatContext *s) + { + FFMContext *ffm = s->priv_data; + int fill_size, h; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + fill_size = ffm->packet_end - ffm->packet_ptr; + memset(ffm->packet_ptr, 0, fill_size); + +- if (url_ftell(pb) % ffm->packet_size) ++ if (avio_tell(pb) % ffm->packet_size) + av_abort(); + + /* put header */ +- put_be16(pb, PACKET_ID); +- put_be16(pb, fill_size); +- put_be64(pb, ffm->dts); ++ avio_wb16(pb, PACKET_ID); ++ avio_wb16(pb, fill_size); ++ avio_wb64(pb, ffm->dts); + h = ffm->frame_offset; + if (ffm->first_packet) + h |= 0x8000; +- put_be16(pb, h); +- put_buffer(pb, ffm->packet, ffm->packet_end - ffm->packet); +- put_flush_packet(pb); ++ avio_wb16(pb, h); ++ avio_write(pb, ffm->packet, ffm->packet_end - ffm->packet); ++ avio_flush(pb); + + /* prepare next packet */ + ffm->frame_offset = 0; /* no key frame */ +@@ -84,110 +86,109 @@ + { + FFMContext *ffm = s->priv_data; + AVStream *st; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *codec; + int bit_rate, i; + + ffm->packet_size = FFM_PACKET_SIZE; + + /* header */ +- put_le32(pb, MKTAG('F', 'F', 'M', '1')); +- put_be32(pb, ffm->packet_size); +- put_be64(pb, 0); /* current write position */ ++ avio_wl32(pb, MKTAG('F', 'F', 'M', '1')); ++ avio_wb32(pb, ffm->packet_size); ++ avio_wb64(pb, 0); /* current write position */ + +- put_be32(pb, s->nb_streams); ++ avio_wb32(pb, s->nb_streams); + bit_rate = 0; + for(i=0;inb_streams;i++) { + st = s->streams[i]; + bit_rate += st->codec->bit_rate; + } +- put_be32(pb, bit_rate); ++ avio_wb32(pb, bit_rate); + + /* list of streams */ + for(i=0;inb_streams;i++) { + st = s->streams[i]; +- av_set_pts_info(st, 64, 1, 1000000); ++ avpriv_set_pts_info(st, 64, 1, 1000000); + + codec = st->codec; + /* generic info */ +- put_be32(pb, codec->codec_id); +- put_byte(pb, codec->codec_type); +- put_be32(pb, codec->bit_rate); +- put_be32(pb, st->quality); +- put_be32(pb, codec->flags); +- put_be32(pb, codec->flags2); +- put_be32(pb, codec->debug); ++ avio_wb32(pb, codec->codec_id); ++ avio_w8(pb, codec->codec_type); ++ avio_wb32(pb, codec->bit_rate); ++ avio_wb32(pb, codec->flags); ++ avio_wb32(pb, codec->flags2); ++ avio_wb32(pb, codec->debug); + /* specific info */ + switch(codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: +- put_be32(pb, codec->time_base.num); +- put_be32(pb, codec->time_base.den); +- put_be16(pb, codec->width); +- put_be16(pb, codec->height); +- put_be16(pb, codec->gop_size); +- put_be32(pb, codec->pix_fmt); +- put_byte(pb, codec->qmin); +- put_byte(pb, codec->qmax); +- put_byte(pb, codec->max_qdiff); +- put_be16(pb, (int) (codec->qcompress * 10000.0)); +- put_be16(pb, (int) (codec->qblur * 10000.0)); +- put_be32(pb, codec->bit_rate_tolerance); ++ avio_wb32(pb, codec->time_base.num); ++ avio_wb32(pb, codec->time_base.den); ++ avio_wb16(pb, codec->width); ++ avio_wb16(pb, codec->height); ++ avio_wb16(pb, codec->gop_size); ++ avio_wb32(pb, codec->pix_fmt); ++ avio_w8(pb, codec->qmin); ++ avio_w8(pb, codec->qmax); ++ avio_w8(pb, codec->max_qdiff); ++ avio_wb16(pb, (int) (codec->qcompress * 10000.0)); ++ avio_wb16(pb, (int) (codec->qblur * 10000.0)); ++ avio_wb32(pb, codec->bit_rate_tolerance); + avio_put_str(pb, codec->rc_eq ? codec->rc_eq : "tex^qComp"); +- put_be32(pb, codec->rc_max_rate); +- put_be32(pb, codec->rc_min_rate); +- put_be32(pb, codec->rc_buffer_size); +- put_be64(pb, av_dbl2int(codec->i_quant_factor)); +- put_be64(pb, av_dbl2int(codec->b_quant_factor)); +- put_be64(pb, av_dbl2int(codec->i_quant_offset)); +- put_be64(pb, av_dbl2int(codec->b_quant_offset)); +- put_be32(pb, codec->dct_algo); +- put_be32(pb, codec->strict_std_compliance); +- put_be32(pb, codec->max_b_frames); +- put_be32(pb, codec->luma_elim_threshold); +- put_be32(pb, codec->chroma_elim_threshold); +- put_be32(pb, codec->mpeg_quant); +- put_be32(pb, codec->intra_dc_precision); +- put_be32(pb, codec->me_method); +- put_be32(pb, codec->mb_decision); +- put_be32(pb, codec->nsse_weight); +- put_be32(pb, codec->frame_skip_cmp); +- put_be64(pb, av_dbl2int(codec->rc_buffer_aggressivity)); +- put_be32(pb, codec->codec_tag); +- put_byte(pb, codec->thread_count); +- put_be32(pb, codec->coder_type); +- put_be32(pb, codec->me_cmp); +- put_be32(pb, codec->partitions); +- put_be32(pb, codec->me_subpel_quality); +- put_be32(pb, codec->me_range); +- put_be32(pb, codec->keyint_min); +- put_be32(pb, codec->scenechange_threshold); +- put_be32(pb, codec->b_frame_strategy); +- put_be64(pb, av_dbl2int(codec->qcompress)); +- put_be64(pb, av_dbl2int(codec->qblur)); +- put_be32(pb, codec->max_qdiff); +- put_be32(pb, codec->refs); +- put_be32(pb, codec->directpred); ++ avio_wb32(pb, codec->rc_max_rate); ++ avio_wb32(pb, codec->rc_min_rate); ++ avio_wb32(pb, codec->rc_buffer_size); ++ avio_wb64(pb, av_double2int(codec->i_quant_factor)); ++ avio_wb64(pb, av_double2int(codec->b_quant_factor)); ++ avio_wb64(pb, av_double2int(codec->i_quant_offset)); ++ avio_wb64(pb, av_double2int(codec->b_quant_offset)); ++ avio_wb32(pb, codec->dct_algo); ++ avio_wb32(pb, codec->strict_std_compliance); ++ avio_wb32(pb, codec->max_b_frames); ++ avio_wb32(pb, codec->luma_elim_threshold); ++ avio_wb32(pb, codec->chroma_elim_threshold); ++ avio_wb32(pb, codec->mpeg_quant); ++ avio_wb32(pb, codec->intra_dc_precision); ++ avio_wb32(pb, codec->me_method); ++ avio_wb32(pb, codec->mb_decision); ++ avio_wb32(pb, codec->nsse_weight); ++ avio_wb32(pb, codec->frame_skip_cmp); ++ avio_wb64(pb, av_double2int(codec->rc_buffer_aggressivity)); ++ avio_wb32(pb, codec->codec_tag); ++ avio_w8(pb, codec->thread_count); ++ avio_wb32(pb, codec->coder_type); ++ avio_wb32(pb, codec->me_cmp); ++ avio_wb32(pb, codec->partitions); ++ avio_wb32(pb, codec->me_subpel_quality); ++ avio_wb32(pb, codec->me_range); ++ avio_wb32(pb, codec->keyint_min); ++ avio_wb32(pb, codec->scenechange_threshold); ++ avio_wb32(pb, codec->b_frame_strategy); ++ avio_wb64(pb, av_double2int(codec->qcompress)); ++ avio_wb64(pb, av_double2int(codec->qblur)); ++ avio_wb32(pb, codec->max_qdiff); ++ avio_wb32(pb, codec->refs); ++ avio_wb32(pb, codec->directpred); + break; + case AVMEDIA_TYPE_AUDIO: +- put_be32(pb, codec->sample_rate); +- put_le16(pb, codec->channels); +- put_le16(pb, codec->frame_size); +- put_le16(pb, codec->sample_fmt); ++ avio_wb32(pb, codec->sample_rate); ++ avio_wl16(pb, codec->channels); ++ avio_wl16(pb, codec->frame_size); ++ avio_wl16(pb, codec->sample_fmt); + break; + default: + return -1; + } + if (codec->flags & CODEC_FLAG_GLOBAL_HEADER) { +- put_be32(pb, codec->extradata_size); +- put_buffer(pb, codec->extradata, codec->extradata_size); ++ avio_wb32(pb, codec->extradata_size); ++ avio_write(pb, codec->extradata, codec->extradata_size); + } + } + + /* flush until end of block reached */ +- while ((url_ftell(pb) % ffm->packet_size) != 0) +- put_byte(pb, 0); ++ while ((avio_tell(pb) % ffm->packet_size) != 0) ++ avio_w8(pb, 0); + +- put_flush_packet(pb); ++ avio_flush(pb); + + /* init packet mux */ + ffm->packet_ptr = ffm->packet; +@@ -206,7 +207,7 @@ + uint8_t header[FRAME_HEADER_SIZE+4]; + int header_size = FRAME_HEADER_SIZE; + +- dts = s->timestamp + pkt->dts; ++ dts = pkt->dts; + /* packet size & key_frame */ + header[0] = pkt->stream_index; + header[1] = 0; +@@ -214,7 +215,7 @@ + header[1] |= FLAG_KEY_FRAME; + AV_WB24(header+2, pkt->size); + AV_WB24(header+5, pkt->duration); +- AV_WB64(header+8, s->timestamp + pkt->pts); ++ AV_WB64(header+8, pkt->pts); + if (pkt->pts != pkt->dts) { + header[1] |= FLAG_DTS; + AV_WB32(header+16, pkt->pts - pkt->dts); +@@ -228,28 +229,26 @@ + + static int ffm_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + FFMContext *ffm = s->priv_data; + + /* flush packets */ + if (ffm->packet_ptr > ffm->packet) + flush_packet(s); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + AVOutputFormat ff_ffm_muxer = { +- "ffm", +- NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"), +- "", +- "ffm", +- sizeof(FFMContext), +- /* not really used */ +- CODEC_ID_MP2, +- CODEC_ID_MPEG1VIDEO, +- ffm_write_header, +- ffm_write_packet, +- ffm_write_trailer, ++ .name = "ffm", ++ .long_name = NULL_IF_CONFIG_SMALL("FFM (FFserver live feed) format"), ++ .extensions = "ffm", ++ .priv_data_size = sizeof(FFMContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG1VIDEO, ++ .write_header = ffm_write_header, ++ .write_packet = ffm_write_packet, ++ .write_trailer = ffm_write_trailer, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmetadec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmetadec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmetadec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmetadec.c 2012-05-14 14:08:54.949352359 +0200 +@@ -19,8 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "avformat.h" + #include "ffmeta.h" ++#include "internal.h" ++#include "libavutil/dict.h" + + static int probe(AVProbeData *p) + { +@@ -29,17 +32,17 @@ + return 0; + } + +-static void get_line(ByteIOContext *s, uint8_t *buf, int size) ++static void get_line(AVIOContext *s, uint8_t *buf, int size) + { + do { + uint8_t c; + int i = 0; + +- while ((c = get_byte(s))) { ++ while ((c = avio_r8(s))) { + if (c == '\\') { + if (i < size - 1) + buf[i++] = c; +- c = get_byte(s); ++ c = avio_r8(s); + } else if (c == '\n') + break; + +@@ -60,19 +63,19 @@ + + if (sscanf(line, "TIMEBASE=%d/%d", &tb.num, &tb.den)) + get_line(s->pb, line, sizeof(line)); +- if (!sscanf(line, "START=%lld", &start)) { ++ if (!sscanf(line, "START=%"SCNd64, &start)) { + av_log(s, AV_LOG_ERROR, "Expected chapter start timestamp, found %s.\n", line); + start = (s->nb_chapters && s->chapters[s->nb_chapters - 1]->end != AV_NOPTS_VALUE) ? + s->chapters[s->nb_chapters - 1]->end : 0; + } else + get_line(s->pb, line, sizeof(line)); + +- if (!sscanf(line, "END=%lld", &end)) { ++ if (!sscanf(line, "END=%"SCNd64, &end)) { + av_log(s, AV_LOG_ERROR, "Expected chapter end timestamp, found %s.\n", line); + end = AV_NOPTS_VALUE; + } + +- return ff_new_chapter(s, s->nb_chapters, tb, start, end, NULL); ++ return avpriv_new_chapter(s, s->nb_chapters, tb, start, end, NULL); + } + + static uint8_t *unescape(uint8_t *buf, int size) +@@ -92,7 +95,7 @@ + return ret; + } + +-static int read_tag(uint8_t *line, AVMetadata **m) ++static int read_tag(uint8_t *line, AVDictionary **m) + { + uint8_t *key, *value, *p = line; + +@@ -116,20 +119,20 @@ + return AVERROR(ENOMEM); + } + +- av_metadata_set2(m, key, value, AV_METADATA_DONT_STRDUP_KEY | AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(m, key, value, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); + return 0; + } + + static int read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- AVMetadata **m = &s->metadata; ++ AVDictionary **m = &s->metadata; + uint8_t line[1024]; + + while(!url_feof(s->pb)) { + get_line(s->pb, line, sizeof(line)); + + if (!memcmp(line, ID_STREAM, strlen(ID_STREAM))) { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + + if (!st) + return -1; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmetaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmetaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmetaenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmetaenc.c 2012-05-14 14:08:54.949352359 +0200 +@@ -23,37 +23,38 @@ + + #include "avformat.h" + #include "ffmeta.h" ++#include "libavutil/dict.h" + + +-static void write_escape_str(ByteIOContext *s, const uint8_t *str) ++static void write_escape_str(AVIOContext *s, const uint8_t *str) + { + const uint8_t *p = str; + + while (*p) { + if (*p == '#' || *p == ';' || *p == '=' || *p == '\\' || *p == '\n') +- put_byte(s, '\\'); +- put_byte(s, *p); ++ avio_w8(s, '\\'); ++ avio_w8(s, *p); + p++; + } + } + +-static void write_tags(ByteIOContext *s, AVMetadata *m) ++static void write_tags(AVIOContext *s, AVDictionary *m) + { +- AVMetadataTag *t = NULL; +- while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) { ++ AVDictionaryEntry *t = NULL; ++ while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) { + write_escape_str(s, t->key); +- put_byte(s, '='); ++ avio_w8(s, '='); + write_escape_str(s, t->value); +- put_byte(s, '\n'); ++ avio_w8(s, '\n'); + } + } + + static int write_header(AVFormatContext *s) + { +- put_tag(s->pb, ID_STRING); +- put_byte(s->pb, '1'); // version +- put_byte(s->pb, '\n'); +- put_flush_packet(s->pb); ++ avio_write(s->pb, ID_STRING, sizeof(ID_STRING) - 1); ++ avio_w8(s->pb, '1'); // version ++ avio_w8(s->pb, '\n'); ++ avio_flush(s->pb); + return 0; + } + +@@ -64,22 +65,22 @@ + write_tags(s->pb, s->metadata); + + for (i = 0; i < s->nb_streams; i++) { +- put_tag(s->pb, ID_STREAM); +- put_byte(s->pb, '\n'); ++ avio_write(s->pb, ID_STREAM, sizeof(ID_STREAM) - 1); ++ avio_w8(s->pb, '\n'); + write_tags(s->pb, s->streams[i]->metadata); + } + + for (i = 0; i < s->nb_chapters; i++) { + AVChapter *ch = s->chapters[i]; +- put_tag(s->pb, ID_CHAPTER); +- put_byte(s->pb, '\n'); +- url_fprintf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); +- url_fprintf(s->pb, "START=%"PRId64"\n", ch->start); +- url_fprintf(s->pb, "END=%"PRId64"\n", ch->end); ++ avio_write(s->pb, ID_CHAPTER, sizeof(ID_CHAPTER) - 1); ++ avio_w8(s->pb, '\n'); ++ avio_printf(s->pb, "TIMEBASE=%d/%d\n", ch->time_base.num, ch->time_base.den); ++ avio_printf(s->pb, "START=%"PRId64"\n", ch->start); ++ avio_printf(s->pb, "END=%"PRId64"\n", ch->end); + write_tags(s->pb, ch->metadata); + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmeta.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmeta.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffmeta.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffmeta.h 2012-05-14 14:08:54.948352339 +0200 +@@ -19,11 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#ifndef AVFORMAT_META_H +-#define AVFORMAT_META_H ++#ifndef AVFORMAT_FFMETA_H ++#define AVFORMAT_FFMETA_H + + #define ID_STRING ";FFMETADATA" + #define ID_CHAPTER "[CHAPTER]" + #define ID_STREAM "[STREAM]" + +-#endif /* AVFORMAT_META_H */ ++#endif /* AVFORMAT_FFMETA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ffm.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ffm.h 2012-05-14 14:08:54.945352279 +0200 +@@ -28,6 +28,7 @@ + + /* The FFM file is made of blocks of fixed size */ + #define FFM_HEADER_SIZE 14 ++#define FFM_PACKET_SIZE 4096 + #define PACKET_ID 0x666d + + /* each packet contains frames (which can span several packets */ +@@ -55,4 +56,8 @@ + uint8_t packet[FFM_PACKET_SIZE]; + } FFMContext; + ++int64_t ffm_read_write_index(int fd); ++int ffm_write_write_index(int fd, int64_t pos); ++void ffm_set_write_index(AVFormatContext *s, int64_t pos, int64_t file_size); ++ + #endif /* AVFORMAT_FFM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/file.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/file.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/file.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/file.c 2012-05-14 14:08:54.950352379 +0200 +@@ -1,5 +1,5 @@ + /* +- * Buffered file io for ffmpeg system ++ * buffered file I/O + * Copyright (c) 2001 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -29,6 +29,7 @@ + #include + #include + #include "os_support.h" ++#include "url.h" + + + /* standard file protocol */ +@@ -36,13 +37,15 @@ + static int file_read(URLContext *h, unsigned char *buf, int size) + { + int fd = (intptr_t) h->priv_data; +- return read(fd, buf, size); ++ int r = read(fd, buf, size); ++ return (-1 == r)?AVERROR(errno):r; + } + + static int file_write(URLContext *h, const unsigned char *buf, int size) + { + int fd = (intptr_t) h->priv_data; +- return write(fd, buf, size); ++ int r = write(fd, buf, size); ++ return (-1 == r)?AVERROR(errno):r; + } + + static int file_get_handle(URLContext *h) +@@ -50,6 +53,19 @@ + return (intptr_t) h->priv_data; + } + ++static int file_check(URLContext *h, int mask) ++{ ++ struct stat st; ++ int ret = stat(h->filename, &st); ++ if (ret < 0) ++ return AVERROR(errno); ++ ++ ret |= st.st_mode&S_IRUSR ? mask&AVIO_FLAG_READ : 0; ++ ret |= st.st_mode&S_IWUSR ? mask&AVIO_FLAG_WRITE : 0; ++ ++ return ret; ++} ++ + #if CONFIG_FILE_PROTOCOL + + static int file_open(URLContext *h, const char *filename, int flags) +@@ -59,9 +75,9 @@ + + av_strstart(filename, "file:", &filename); + +- if (flags & URL_RDWR) { ++ if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) { + access = O_CREAT | O_TRUNC | O_RDWR; +- } else if (flags & URL_WRONLY) { ++ } else if (flags & AVIO_FLAG_WRITE) { + access = O_CREAT | O_TRUNC | O_WRONLY; + } else { + access = O_RDONLY; +@@ -95,13 +111,14 @@ + } + + URLProtocol ff_file_protocol = { +- "file", +- file_open, +- file_read, +- file_write, +- file_seek, +- file_close, ++ .name = "file", ++ .url_open = file_open, ++ .url_read = file_read, ++ .url_write = file_write, ++ .url_seek = file_seek, ++ .url_close = file_close, + .url_get_file_handle = file_get_handle, ++ .url_check = file_check, + }; + + #endif /* CONFIG_FILE_PROTOCOL */ +@@ -116,7 +133,7 @@ + + fd = strtol(filename, &final, 10); + if((filename == final) || *final ) {/* No digits found, or something like 10ab */ +- if (flags & URL_WRONLY) { ++ if (flags & AVIO_FLAG_WRITE) { + fd = 1; + } else { + fd = 0; +@@ -131,11 +148,12 @@ + } + + URLProtocol ff_pipe_protocol = { +- "pipe", +- pipe_open, +- file_read, +- file_write, ++ .name = "pipe", ++ .url_open = pipe_open, ++ .url_read = file_read, ++ .url_write = file_write, + .url_get_file_handle = file_get_handle, ++ .url_check = file_check, + }; + + #endif /* CONFIG_PIPE_PROTOCOL */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/filmstripdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/filmstripdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/filmstripdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/filmstripdec.c 2012-05-14 14:08:54.950352379 +0200 +@@ -26,6 +26,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define RAND_TAG MKBETAG('R','a','n','d') + +@@ -37,39 +38,39 @@ + AVFormatParameters *ap) + { + FilmstripDemuxContext *film = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + +- if (url_is_streamed(s->pb)) ++ if (!s->pb->seekable) + return AVERROR(EIO); + +- url_fseek(pb, url_fsize(pb) - 36, SEEK_SET); +- if (get_be32(pb) != RAND_TAG) { ++ avio_seek(pb, avio_size(pb) - 36, SEEK_SET); ++ if (avio_rb32(pb) != RAND_TAG) { + av_log(s, AV_LOG_ERROR, "magic number not found"); + return AVERROR_INVALIDDATA; + } + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- st->nb_frames = get_be32(pb); +- if (get_be16(pb) != 0) { ++ st->nb_frames = avio_rb32(pb); ++ if (avio_rb16(pb) != 0) { + av_log_ask_for_sample(s, "unsupported packing method\n"); + return AVERROR_INVALIDDATA; + } + +- url_fskip(pb, 2); ++ avio_skip(pb, 2); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->pix_fmt = PIX_FMT_RGBA; + st->codec->codec_tag = 0; /* no fourcc */ +- st->codec->width = get_be16(pb); +- st->codec->height = get_be16(pb); +- film->leading = get_be16(pb); +- av_set_pts_info(st, 64, 1, get_be16(pb)); ++ st->codec->width = avio_rb16(pb); ++ st->codec->height = avio_rb16(pb); ++ film->leading = avio_rb16(pb); ++ avpriv_set_pts_info(st, 64, 1, avio_rb16(pb)); + +- url_fseek(pb, 0, SEEK_SET); ++ avio_seek(pb, 0, SEEK_SET); + + return 0; + } +@@ -82,9 +83,9 @@ + + if (url_feof(s->pb)) + return AVERROR(EIO); +- pkt->dts = url_ftell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4); ++ pkt->dts = avio_tell(s->pb) / (st->codec->width * (st->codec->height + film->leading) * 4); + pkt->size = av_get_packet(s->pb, pkt, st->codec->width * st->codec->height * 4); +- url_fskip(s->pb, st->codec->width * film->leading * 4); ++ avio_skip(s->pb, st->codec->width * film->leading * 4); + if (pkt->size < 0) + return pkt->size; + pkt->flags |= AV_PKT_FLAG_KEY; +@@ -94,18 +95,17 @@ + static int read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) + { + AVStream *st = s->streams[stream_index]; +- url_fseek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET); ++ if (avio_seek(s->pb, FFMAX(timestamp, 0) * st->codec->width * st->codec->height * 4, SEEK_SET) < 0) ++ return -1; + return 0; + } + + AVInputFormat ff_filmstrip_demuxer = { +- "filmstrip", +- NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), +- sizeof(FilmstripDemuxContext), +- NULL, +- read_header, +- read_packet, +- NULL, +- read_seek, ++ .name = "filmstrip", ++ .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), ++ .priv_data_size = sizeof(FilmstripDemuxContext), ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_seek = read_seek, + .extensions = "flm", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/filmstripenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/filmstripenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/filmstripenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/filmstripenc.c 2012-05-14 14:08:54.951352399 +0200 +@@ -45,7 +45,7 @@ + static int write_packet(AVFormatContext *s, AVPacket *pkt) + { + FilmstripMuxContext *film = s->priv_data; +- put_buffer(s->pb, pkt->data, pkt->size); ++ avio_write(s->pb, pkt->data, pkt->size); + film->nb_frames++; + return 0; + } +@@ -53,33 +53,32 @@ + static int write_trailer(AVFormatContext *s) + { + FilmstripMuxContext *film = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + int i; + +- put_be32(pb, RAND_TAG); +- put_be32(pb, film->nb_frames); +- put_be16(pb, 0); // packing method +- put_be16(pb, 0); // reserved +- put_be16(pb, st->codec->width); +- put_be16(pb, st->codec->height); +- put_be16(pb, 0); // leading +- put_be16(pb, 1/av_q2d(st->codec->time_base)); ++ avio_wb32(pb, RAND_TAG); ++ avio_wb32(pb, film->nb_frames); ++ avio_wb16(pb, 0); // packing method ++ avio_wb16(pb, 0); // reserved ++ avio_wb16(pb, st->codec->width); ++ avio_wb16(pb, st->codec->height); ++ avio_wb16(pb, 0); // leading ++ avio_wb16(pb, 1/av_q2d(st->codec->time_base)); + for (i = 0; i < 16; i++) +- put_byte(pb, 0x00); // reserved +- put_flush_packet(pb); ++ avio_w8(pb, 0x00); // reserved ++ avio_flush(pb); + return 0; + } + + AVOutputFormat ff_filmstrip_muxer = { +- "filmstrip", +- NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), +- NULL, +- "flm", +- sizeof(FilmstripMuxContext), +- CODEC_ID_NONE, +- CODEC_ID_RAWVIDEO, +- write_header, +- write_packet, +- write_trailer, ++ .name = "filmstrip", ++ .long_name = NULL_IF_CONFIG_SMALL("Adobe Filmstrip"), ++ .extensions = "flm", ++ .priv_data_size = sizeof(FilmstripMuxContext), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = write_header, ++ .write_packet = write_packet, ++ .write_trailer = write_trailer, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacdec.c 2012-05-14 14:08:54.951352399 +0200 +@@ -21,9 +21,11 @@ + + #include "libavcodec/flac.h" + #include "avformat.h" ++#include "internal.h" + #include "rawdec.h" + #include "oggdec.h" + #include "vorbiscomment.h" ++#include "libavcodec/bytestream.h" + + static int flac_read_header(AVFormatContext *s, + AVFormatParameters *ap) +@@ -31,7 +33,7 @@ + int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0; + uint8_t header[4]; + uint8_t *buffer=NULL; +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -40,32 +42,33 @@ + /* the parameters will be extracted from the compressed bitstream */ + + /* if fLaC marker is not found, assume there is no header */ +- if (get_le32(s->pb) != MKTAG('f','L','a','C')) { +- url_fseek(s->pb, -4, SEEK_CUR); ++ if (avio_rl32(s->pb) != MKTAG('f','L','a','C')) { ++ avio_seek(s->pb, -4, SEEK_CUR); + return 0; + } + + /* process metadata blocks */ + while (!url_feof(s->pb) && !metadata_last) { +- get_buffer(s->pb, header, 4); +- ff_flac_parse_block_header(header, &metadata_last, &metadata_type, ++ avio_read(s->pb, header, 4); ++ avpriv_flac_parse_block_header(header, &metadata_last, &metadata_type, + &metadata_size); + switch (metadata_type) { + /* allocate and read metadata block for supported types */ + case FLAC_METADATA_TYPE_STREAMINFO: ++ case FLAC_METADATA_TYPE_CUESHEET: + case FLAC_METADATA_TYPE_VORBIS_COMMENT: + buffer = av_mallocz(metadata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!buffer) { + return AVERROR(ENOMEM); + } +- if (get_buffer(s->pb, buffer, metadata_size) != metadata_size) { ++ if (avio_read(s->pb, buffer, metadata_size) != metadata_size) { + av_freep(&buffer); + return AVERROR(EIO); + } + break; + /* skip metadata block for unsupported types */ + default: +- ret = url_fseek(s->pb, metadata_size, SEEK_CUR); ++ ret = avio_skip(s->pb, metadata_size); + if (ret < 0) + return ret; + } +@@ -87,14 +90,38 @@ + buffer = NULL; + + /* get codec params from STREAMINFO header */ +- ff_flac_parse_streaminfo(st->codec, &si, st->codec->extradata); ++ avpriv_flac_parse_streaminfo(st->codec, &si, st->codec->extradata); + + /* set time base and duration */ + if (si.samplerate > 0) { +- av_set_pts_info(st, 64, 1, si.samplerate); ++ avpriv_set_pts_info(st, 64, 1, si.samplerate); + if (si.samples > 0) + st->duration = si.samples; + } ++ } else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) { ++ uint8_t isrc[13]; ++ uint64_t start; ++ const uint8_t *offset; ++ int i, chapters, track, ti; ++ if (metadata_size < 431) ++ return AVERROR_INVALIDDATA; ++ offset = buffer + 395; ++ chapters = bytestream_get_byte(&offset) - 1; ++ if (chapters <= 0) ++ return AVERROR_INVALIDDATA; ++ for (i = 0; i < chapters; i++) { ++ if (offset + 36 - buffer > metadata_size) ++ return AVERROR_INVALIDDATA; ++ start = bytestream_get_be64(&offset); ++ track = bytestream_get_byte(&offset); ++ bytestream_get_buffer(&offset, isrc, 12); ++ isrc[12] = 0; ++ offset += 14; ++ ti = bytestream_get_byte(&offset); ++ if (ti <= 0) return AVERROR_INVALIDDATA; ++ offset += ti * 12; ++ avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc); ++ } + } else { + /* STREAMINFO must be the first block */ + if (!found_streaminfo) { +@@ -124,12 +151,11 @@ + } + + AVInputFormat ff_flac_demuxer = { +- "flac", +- NULL_IF_CONFIG_SMALL("raw FLAC"), +- 0, +- flac_probe, +- flac_read_header, +- ff_raw_read_partial_packet, ++ .name = "flac", ++ .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"), ++ .read_probe = flac_probe, ++ .read_header = flac_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "flac", + .value = CODEC_ID_FLAC, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc.c 2012-05-14 14:08:54.952352419 +0200 +@@ -22,24 +22,23 @@ + #include "libavcodec/flac.h" + #include "avformat.h" + #include "flacenc.h" +-#include "metadata.h" + #include "vorbiscomment.h" + #include "libavcodec/bytestream.h" + + +-static int flac_write_block_padding(ByteIOContext *pb, unsigned int n_padding_bytes, ++static int flac_write_block_padding(AVIOContext *pb, unsigned int n_padding_bytes, + int last_block) + { +- put_byte(pb, last_block ? 0x81 : 0x01); +- put_be24(pb, n_padding_bytes); ++ avio_w8(pb, last_block ? 0x81 : 0x01); ++ avio_wb24(pb, n_padding_bytes); + while (n_padding_bytes > 0) { +- put_byte(pb, 0); ++ avio_w8(pb, 0); + n_padding_bytes--; + } + return 0; + } + +-static int flac_write_block_comment(ByteIOContext *pb, AVMetadata **m, ++static int flac_write_block_comment(AVIOContext *pb, AVDictionary **m, + int last_block, int bitexact) + { + const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; +@@ -58,7 +57,7 @@ + bytestream_put_be24(&p, len); + ff_vorbiscomment_write(&p, m, vendor, count); + +- put_buffer(pb, p0, len+4); ++ avio_write(pb, p0, len+4); + av_freep(&p0); + p = NULL; + +@@ -90,21 +89,21 @@ + + static int flac_write_trailer(struct AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t *streaminfo; + enum FLACExtradataFormat format; + int64_t file_size; + +- if (!ff_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo)) ++ if (!avpriv_flac_is_extradata_valid(s->streams[0]->codec, &format, &streaminfo)) + return -1; + +- if (!url_is_streamed(pb)) { ++ if (pb->seekable) { + /* rewrite the STREAMINFO header block data */ +- file_size = url_ftell(pb); +- url_fseek(pb, 8, SEEK_SET); +- put_buffer(pb, streaminfo, FLAC_STREAMINFO_SIZE); +- url_fseek(pb, file_size, SEEK_SET); +- put_flush_packet(pb); ++ file_size = avio_tell(pb); ++ avio_seek(pb, 8, SEEK_SET); ++ avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE); ++ avio_seek(pb, file_size, SEEK_SET); ++ avio_flush(pb); + } else { + av_log(s, AV_LOG_WARNING, "unable to rewrite FLAC header.\n"); + } +@@ -113,21 +112,20 @@ + + static int flac_write_packet(struct AVFormatContext *s, AVPacket *pkt) + { +- put_buffer(s->pb, pkt->data, pkt->size); +- put_flush_packet(s->pb); ++ avio_write(s->pb, pkt->data, pkt->size); ++ avio_flush(s->pb); + return 0; + } + + AVOutputFormat ff_flac_muxer = { +- "flac", +- NULL_IF_CONFIG_SMALL("raw FLAC"), +- "audio/x-flac", +- "flac", +- 0, +- CODEC_ID_FLAC, +- CODEC_ID_NONE, +- flac_write_header, +- flac_write_packet, +- flac_write_trailer, ++ .name = "flac", ++ .long_name = NULL_IF_CONFIG_SMALL("raw FLAC"), ++ .mime_type = "audio/x-flac", ++ .extensions = "flac", ++ .audio_codec = CODEC_ID_FLAC, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = flac_write_header, ++ .write_packet = flac_write_packet, ++ .write_trailer = flac_write_trailer, + .flags= AVFMT_NOTIMESTAMPS, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc.h 2012-05-14 14:08:54.952352419 +0200 +@@ -26,7 +26,7 @@ + #include "libavcodec/bytestream.h" + #include "avformat.h" + +-int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec, ++int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, + int last_block); + + #endif /* AVFORMAT_FLACENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc_header.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc_header.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flacenc_header.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flacenc_header.c 2012-05-14 14:08:54.953352440 +0200 +@@ -24,7 +24,7 @@ + #include "avformat.h" + #include "flacenc.h" + +-int ff_flac_write_header(ByteIOContext *pb, AVCodecContext *codec, ++int ff_flac_write_header(AVIOContext *pb, AVCodecContext *codec, + int last_block) + { + uint8_t header[8] = { +@@ -34,16 +34,14 @@ + enum FLACExtradataFormat format; + + header[4] = last_block ? 0x80 : 0x00; +- if (!ff_flac_is_extradata_valid(codec, &format, &streaminfo)) ++ if (!avpriv_flac_is_extradata_valid(codec, &format, &streaminfo)) + return -1; + +- /* write "fLaC" stream marker and first metadata block header if needed */ +- if (format == FLAC_EXTRADATA_FORMAT_STREAMINFO) { +- put_buffer(pb, header, 8); +- } ++ /* write "fLaC" stream marker and first metadata block header */ ++ avio_write(pb, header, 8); + +- /* write STREAMINFO or full header */ +- put_buffer(pb, codec->extradata, codec->extradata_size); ++ /* write STREAMINFO */ ++ avio_write(pb, streaminfo, FLAC_STREAMINFO_SIZE); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flic.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flic.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flic.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flic.c 2012-05-14 14:08:54.954352460 +0200 +@@ -32,7 +32,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/audioconvert.h" + #include "avformat.h" ++#include "internal.h" + + #define FLIC_FILE_MAGIC_1 0xAF11 + #define FLIC_FILE_MAGIC_2 0xAF12 +@@ -85,7 +87,7 @@ + AVFormatParameters *ap) + { + FlicDemuxContext *flic = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned char header[FLIC_HEADER_SIZE]; + AVStream *st, *ast; + int speed; +@@ -95,7 +97,7 @@ + flic->frame_number = 0; + + /* load the whole header and pull out the width and height */ +- if (get_buffer(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE) ++ if (avio_read(pb, header, FLIC_HEADER_SIZE) != FLIC_HEADER_SIZE) + return AVERROR(EIO); + + magic_number = AV_RL16(&header[4]); +@@ -104,7 +106,7 @@ + speed = FLIC_DEFAULT_SPEED; + + /* initialize the decoder streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + flic->video_stream_index = st->index; +@@ -129,12 +131,12 @@ + memcpy(st->codec->extradata, header, FLIC_HEADER_SIZE); + + /* peek at the preamble to detect TFTD videos - they seem to always start with an audio chunk */ +- if (get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE) != FLIC_PREAMBLE_SIZE) { ++ if (avio_read(pb, preamble, FLIC_PREAMBLE_SIZE) != FLIC_PREAMBLE_SIZE) { + av_log(s, AV_LOG_ERROR, "Failed to peek at preamble\n"); + return AVERROR(EIO); + } + +- url_fseek(pb, -FLIC_PREAMBLE_SIZE, SEEK_CUR); ++ avio_seek(pb, -FLIC_PREAMBLE_SIZE, SEEK_CUR); + + /* Time to figure out the framerate: + * If the first preamble's magic number is 0xAAAA then this file is from +@@ -144,7 +146,7 @@ + */ + if (AV_RL16(&preamble[4]) == FLIC_TFTD_CHUNK_AUDIO) { + /* TFTD videos have an extra 22050 Hz 8-bit mono audio stream */ +- ast = av_new_stream(s, 1); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + +@@ -160,19 +162,19 @@ + ast->codec->sample_fmt = AV_SAMPLE_FMT_U8; + ast->codec->bit_rate = st->codec->sample_rate * 8; + ast->codec->bits_per_coded_sample = 8; +- ast->codec->channel_layout = CH_LAYOUT_MONO; ++ ast->codec->channel_layout = AV_CH_LAYOUT_MONO; + ast->codec->extradata_size = 0; + + /* Since the header information is incorrect we have to figure out the + * framerate using block_align and the fact that the audio is 22050 Hz. + * We usually have two cases: 2205 -> 10 fps and 1470 -> 15 fps */ +- av_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE); +- av_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE); ++ avpriv_set_pts_info(st, 64, ast->codec->block_align, FLIC_TFTD_SAMPLE_RATE); ++ avpriv_set_pts_info(ast, 64, 1, FLIC_TFTD_SAMPLE_RATE); + } else if (AV_RL16(&header[0x10]) == FLIC_CHUNK_MAGIC_1) { +- av_set_pts_info(st, 64, FLIC_MC_SPEED, 70); ++ avpriv_set_pts_info(st, 64, FLIC_MC_SPEED, 70); + + /* rewind the stream since the first chunk is at offset 12 */ +- url_fseek(pb, 12, SEEK_SET); ++ avio_seek(pb, 12, SEEK_SET); + + /* send over abbreviated FLIC header chunk */ + av_free(st->codec->extradata); +@@ -181,10 +183,10 @@ + memcpy(st->codec->extradata, header, 12); + + } else if (magic_number == FLIC_FILE_MAGIC_1) { +- av_set_pts_info(st, 64, speed, 70); ++ avpriv_set_pts_info(st, 64, speed, 70); + } else if ((magic_number == FLIC_FILE_MAGIC_2) || + (magic_number == FLIC_FILE_MAGIC_3)) { +- av_set_pts_info(st, 64, speed, 1000); ++ avpriv_set_pts_info(st, 64, speed, 1000); + } else { + av_log(s, AV_LOG_INFO, "Invalid or unsupported magic chunk in file\n"); + return AVERROR_INVALIDDATA; +@@ -197,7 +199,7 @@ + AVPacket *pkt) + { + FlicDemuxContext *flic = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int packet_read = 0; + unsigned int size; + int magic; +@@ -206,7 +208,7 @@ + + while (!packet_read) { + +- if ((ret = get_buffer(pb, preamble, FLIC_PREAMBLE_SIZE)) != ++ if ((ret = avio_read(pb, preamble, FLIC_PREAMBLE_SIZE)) != + FLIC_PREAMBLE_SIZE) { + ret = AVERROR(EIO); + break; +@@ -222,9 +224,9 @@ + } + pkt->stream_index = flic->video_stream_index; + pkt->pts = flic->frame_number++; +- pkt->pos = url_ftell(pb); ++ pkt->pos = avio_tell(pb); + memcpy(pkt->data, preamble, FLIC_PREAMBLE_SIZE); +- ret = get_buffer(pb, pkt->data + FLIC_PREAMBLE_SIZE, ++ ret = avio_read(pb, pkt->data + FLIC_PREAMBLE_SIZE, + size - FLIC_PREAMBLE_SIZE); + if (ret != size - FLIC_PREAMBLE_SIZE) { + av_free_packet(pkt); +@@ -238,11 +240,11 @@ + } + + /* skip useless 10B sub-header (yes, it's not accounted for in the chunk header) */ +- url_fseek(pb, 10, SEEK_CUR); ++ avio_skip(pb, 10); + + pkt->stream_index = flic->audio_stream_index; +- pkt->pos = url_ftell(pb); +- ret = get_buffer(pb, pkt->data, size); ++ pkt->pos = avio_tell(pb); ++ ret = avio_read(pb, pkt->data, size); + + if (ret != size) { + av_free_packet(pkt); +@@ -252,7 +254,7 @@ + packet_read = 1; + } else { + /* not interested in this chunk */ +- url_fseek(pb, size - 6, SEEK_CUR); ++ avio_skip(pb, size - 6); + } + } + +@@ -260,10 +262,10 @@ + } + + AVInputFormat ff_flic_demuxer = { +- "flic", +- NULL_IF_CONFIG_SMALL("FLI/FLC/FLX animation format"), +- sizeof(FlicDemuxContext), +- flic_probe, +- flic_read_header, +- flic_read_packet, ++ .name = "flic", ++ .long_name = NULL_IF_CONFIG_SMALL("FLI/FLC/FLX animation format"), ++ .priv_data_size = sizeof(FlicDemuxContext), ++ .read_probe = flic_probe, ++ .read_header = flic_read_header, ++ .read_packet = flic_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flvdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flvdec.c 2012-05-14 14:08:54.958352540 +0200 +@@ -25,17 +25,22 @@ + */ + + #include "libavutil/avstring.h" ++#include "libavutil/dict.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/mathematics.h" + #include "libavcodec/bytestream.h" + #include "libavcodec/mpeg4audio.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "flv.h" + +-#define KEYFRAMES_TAG "keyframes" +-#define KEYFRAMES_TIMESTAMP_TAG "times" +-#define KEYFRAMES_BYTEOFFSET_TAG "filepositions" +- + typedef struct { + int wrong_dts; ///< wrong dts due to negative cts ++ uint8_t *new_extradata[FLV_STREAM_TYPE_NB]; ++ int new_extradata_size[FLV_STREAM_TYPE_NB]; ++ int last_sample_rate; ++ int last_channels; + } FLVContext; + + static int flv_probe(AVProbeData *p) +@@ -49,8 +54,7 @@ + return 0; + } + +-static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, int flv_codecid) { +- AVCodecContext *acodec = astream->codec; ++static void flv_set_audio_codec(AVFormatContext *s, AVStream *astream, AVCodecContext *acodec, int flv_codecid) { + switch(flv_codecid) { + //no distinction between S16 and S8 PCM codec flags + case FLV_CODECID_PCM: +@@ -91,6 +95,7 @@ + AVCodecContext *vcodec = vstream->codec; + switch(flv_codecid) { + case FLV_CODECID_H263 : vcodec->codec_id = CODEC_ID_FLV1 ; break; ++ case FLV_CODECID_REALH263: vcodec->codec_id = CODEC_ID_H263 ; break; // Really mean it this time + case FLV_CODECID_SCREEN: vcodec->codec_id = CODEC_ID_FLASHSV; break; + case FLV_CODECID_SCREEN2: vcodec->codec_id = CODEC_ID_FLASHSV2; break; + case FLV_CODECID_VP6 : vcodec->codec_id = CODEC_ID_VP6F ; +@@ -101,11 +106,14 @@ + vcodec->extradata_size = 1; + vcodec->extradata = av_malloc(1); + } +- vcodec->extradata[0] = get_byte(s->pb); ++ vcodec->extradata[0] = avio_r8(s->pb); + return 1; // 1 byte body size adjustment for flv_read_packet() + case FLV_CODECID_H264: + vcodec->codec_id = CODEC_ID_H264; + return 3; // not 4, reading packet type will consume one byte ++ case FLV_CODECID_MPEG4: ++ vcodec->codec_id = CODEC_ID_MPEG4; ++ return 3; + default: + av_log(s, AV_LOG_INFO, "Unsupported video codec (%x)\n", flv_codecid); + vcodec->codec_tag = flv_codecid; +@@ -114,37 +122,42 @@ + return 0; + } + +-static int amf_get_string(ByteIOContext *ioc, char *buffer, int buffsize) { +- int length = get_be16(ioc); ++static int amf_get_string(AVIOContext *ioc, char *buffer, int buffsize) { ++ int length = avio_rb16(ioc); + if(length >= buffsize) { +- url_fskip(ioc, length); ++ avio_skip(ioc, length); + return -1; + } + +- get_buffer(ioc, buffer, length); ++ avio_read(ioc, buffer, length); + + buffer[length] = '\0'; + + return length; + } + +-static int parse_keyframes_index(AVFormatContext *s, ByteIOContext *ioc, AVStream *vstream, int64_t max_pos) { ++static int parse_keyframes_index(AVFormatContext *s, AVIOContext *ioc, AVStream *vstream, int64_t max_pos) { + unsigned int timeslen = 0, fileposlen = 0, i; + char str_val[256]; + int64_t *times = NULL; + int64_t *filepositions = NULL; + int ret = AVERROR(ENOSYS); +- int64_t initial_pos = url_ftell(ioc); ++ int64_t initial_pos = avio_tell(ioc); ++ ++ if(vstream->nb_index_entries>0){ ++ av_log(s, AV_LOG_WARNING, "Skiping duplicate index\n"); ++ return 0; ++ } + +- while (url_ftell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { ++ while (avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { + int64_t** current_array; + unsigned int arraylen; + + // Expect array object in context +- if (get_byte(ioc) != AMF_DATA_TYPE_ARRAY) ++ if (avio_r8(ioc) != AMF_DATA_TYPE_ARRAY) + break; + +- arraylen = get_be32(ioc); ++ arraylen = avio_rb32(ioc); + if(arraylen>>28) + break; + +@@ -162,10 +175,10 @@ + goto finish; + } + +- for (i = 0; i < arraylen && url_ftell(ioc) < max_pos - 1; i++) { +- if (get_byte(ioc) != AMF_DATA_TYPE_NUMBER) +- goto finish; +- current_array[0][i] = av_int2dbl(get_be64(ioc)); ++ for (i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) { ++ if (avio_r8(ioc) != AMF_DATA_TYPE_NUMBER) ++ goto invalid; ++ current_array[0][i] = av_int2double(avio_rb64(ioc)); + } + if (times && filepositions) { + // All done, exiting at a position allowing amf_parse_object +@@ -175,22 +188,33 @@ + } + } + +- if (timeslen == fileposlen) { ++ if (timeslen == fileposlen && fileposlen>1 && max_pos <= filepositions[0]) { ++ int64_t dts, size0, size1; ++ avio_seek(ioc, filepositions[1]-4, SEEK_SET); ++ size0 = avio_rb32(ioc); ++ avio_r8(ioc); ++ size1 = avio_rb24(ioc); ++ dts = avio_rb24(ioc); ++ dts |= avio_r8(ioc) << 24; ++ if (size0 > filepositions[1] || FFABS(dts - times[1]*1000)>5000/*arbitraray threshold to detect invalid index*/) ++ goto invalid; + for(i = 0; i < timeslen; i++) + av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME); +- } else ++ } else { ++invalid: + av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n"); ++ } + + finish: + av_freep(×); + av_freep(&filepositions); +- url_fseek(ioc, initial_pos, SEEK_SET); ++ avio_seek(ioc, initial_pos, SEEK_SET); + return ret; + } + + static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) { + AVCodecContext *acodec, *vcodec; +- ByteIOContext *ioc; ++ AVIOContext *ioc; + AMFDataType amf_type; + char str_val[256]; + double num_val; +@@ -198,13 +222,13 @@ + num_val = 0; + ioc = s->pb; + +- amf_type = get_byte(ioc); ++ amf_type = avio_r8(ioc); + + switch(amf_type) { + case AMF_DATA_TYPE_NUMBER: +- num_val = av_int2dbl(get_be64(ioc)); break; ++ num_val = av_int2double(avio_rb64(ioc)); break; + case AMF_DATA_TYPE_BOOL: +- num_val = get_byte(ioc); break; ++ num_val = avio_r8(ioc); break; + case AMF_DATA_TYPE_STRING: + if(amf_get_string(ioc, str_val, sizeof(str_val)) < 0) + return -1; +@@ -212,16 +236,17 @@ + case AMF_DATA_TYPE_OBJECT: { + unsigned int keylen; + +- if (!url_is_streamed(s->pb) && key && !strcmp(KEYFRAMES_TAG, key) && depth == 1) +- if (parse_keyframes_index(s, ioc, vstream, max_pos) < 0) ++ if ((vstream || astream) && ioc->seekable && key && !strcmp(KEYFRAMES_TAG, key) && depth == 1) ++ if (parse_keyframes_index(s, ioc, vstream ? vstream : astream, ++ max_pos) < 0) + av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n"); + +- while(url_ftell(ioc) < max_pos - 2 && (keylen = get_be16(ioc))) { +- url_fskip(ioc, keylen); //skip key string ++ while(avio_tell(ioc) < max_pos - 2 && (keylen = avio_rb16(ioc))) { ++ avio_skip(ioc, keylen); //skip key string + if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0) + return -1; //if we couldn't skip, bomb out. + } +- if(get_byte(ioc) != AMF_END_OF_OBJECT) ++ if(avio_r8(ioc) != AMF_END_OF_OBJECT) + return -1; + } + break; +@@ -230,27 +255,27 @@ + case AMF_DATA_TYPE_UNSUPPORTED: + break; //these take up no additional space + case AMF_DATA_TYPE_MIXEDARRAY: +- url_fskip(ioc, 4); //skip 32-bit max array index +- while(url_ftell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { ++ avio_skip(ioc, 4); //skip 32-bit max array index ++ while(avio_tell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { + //this is the only case in which we would want a nested parse to not skip over the object + if(amf_parse_object(s, astream, vstream, str_val, max_pos, depth + 1) < 0) + return -1; + } +- if(get_byte(ioc) != AMF_END_OF_OBJECT) ++ if(avio_r8(ioc) != AMF_END_OF_OBJECT) + return -1; + break; + case AMF_DATA_TYPE_ARRAY: { + unsigned int arraylen, i; + +- arraylen = get_be32(ioc); +- for(i = 0; i < arraylen && url_ftell(ioc) < max_pos - 1; i++) { ++ arraylen = avio_rb32(ioc); ++ for(i = 0; i < arraylen && avio_tell(ioc) < max_pos - 1; i++) { + if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0) + return -1; //if we couldn't skip, bomb out. + } + } + break; + case AMF_DATA_TYPE_DATE: +- url_fskip(ioc, 8 + 2); //timestamp (double) and UTC offset (int16) ++ avio_skip(ioc, 8 + 2); //timestamp (double) and UTC offset (int16) + break; + default: //unsupported type, we couldn't skip + return -1; +@@ -260,19 +285,42 @@ + acodec = astream ? astream->codec : NULL; + vcodec = vstream ? vstream->codec : NULL; + ++ if (amf_type == AMF_DATA_TYPE_NUMBER) { ++ if (!strcmp(key, "duration")) ++ s->duration = num_val * AV_TIME_BASE; ++ else if (!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0)) ++ vcodec->bit_rate = num_val * 1024.0; ++ else if (!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0)) ++ acodec->bit_rate = num_val * 1024.0; ++ } ++ ++ if (amf_type == AMF_DATA_TYPE_OBJECT && s->nb_streams == 1 && ++ ((!acodec && !strcmp(key, "audiocodecid")) || ++ (!vcodec && !strcmp(key, "videocodecid")))) ++ s->ctx_flags &= ~AVFMTCTX_NOHEADER; //If there is either audio/video missing, codecid will be an empty object ++ ++ if (!strcmp(key, "duration") || ++ !strcmp(key, "filesize") || ++ !strcmp(key, "width") || ++ !strcmp(key, "height") || ++ !strcmp(key, "videodatarate") || ++ !strcmp(key, "framerate") || ++ !strcmp(key, "videocodecid") || ++ !strcmp(key, "audiodatarate") || ++ !strcmp(key, "audiosamplerate") || ++ !strcmp(key, "audiosamplesize") || ++ !strcmp(key, "stereo") || ++ !strcmp(key, "audiocodecid")) ++ return 0; ++ + if(amf_type == AMF_DATA_TYPE_BOOL) { + av_strlcpy(str_val, num_val > 0 ? "true" : "false", sizeof(str_val)); +- av_metadata_set2(&s->metadata, key, str_val, 0); ++ av_dict_set(&s->metadata, key, str_val, 0); + } else if(amf_type == AMF_DATA_TYPE_NUMBER) { + snprintf(str_val, sizeof(str_val), "%.f", num_val); +- av_metadata_set2(&s->metadata, key, str_val, 0); +- if(!strcmp(key, "duration")) s->duration = num_val * AV_TIME_BASE; +- else if(!strcmp(key, "videodatarate") && vcodec && 0 <= (int)(num_val * 1024.0)) +- vcodec->bit_rate = num_val * 1024.0; +- else if(!strcmp(key, "audiodatarate") && acodec && 0 <= (int)(num_val * 1024.0)) +- acodec->bit_rate = num_val * 1024.0; ++ av_dict_set(&s->metadata, key, str_val, 0); + } else if (amf_type == AMF_DATA_TYPE_STRING) +- av_metadata_set2(&s->metadata, key, str_val, 0); ++ av_dict_set(&s->metadata, key, str_val, 0); + } + + return 0; +@@ -280,25 +328,25 @@ + + static int flv_read_metabody(AVFormatContext *s, int64_t next_pos) { + AMFDataType type; +- AVStream *stream, *astream, *vstream; +- ByteIOContext *ioc; ++ AVStream *stream, *astream, *vstream, *dstream; ++ AVIOContext *ioc; + int i; + char buffer[11]; //only needs to hold the string "onMetaData". Anything longer is something we don't want. + +- astream = NULL; +- vstream = NULL; ++ vstream = astream = dstream = NULL; + ioc = s->pb; + + //first object needs to be "onMetaData" string +- type = get_byte(ioc); ++ type = avio_r8(ioc); + if(type != AMF_DATA_TYPE_STRING || amf_get_string(ioc, buffer, sizeof(buffer)) < 0 || strcmp(buffer, "onMetaData")) + return -1; + + //find the streams now so that amf_parse_object doesn't need to do the lookup every time it is called. + for(i = 0; i < s->nb_streams; i++) { + stream = s->streams[i]; +- if (stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; +- else if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; ++ if(stream->codec->codec_type == AVMEDIA_TYPE_VIDEO) vstream = stream; ++ else if(stream->codec->codec_type == AVMEDIA_TYPE_AUDIO) astream = stream; ++ else if(stream->codec->codec_type == AVMEDIA_TYPE_DATA) dstream = stream; + } + + //parse the second object (we want a mixed array) +@@ -308,12 +356,25 @@ + return 0; + } + +-static AVStream *create_stream(AVFormatContext *s, int is_audio){ +- AVStream *st = av_new_stream(s, is_audio); ++static AVStream *create_stream(AVFormatContext *s, int stream_type){ ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return NULL; +- st->codec->codec_type = is_audio ? AVMEDIA_TYPE_AUDIO : AVMEDIA_TYPE_VIDEO; +- av_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ ++ st->id = stream_type; ++ switch(stream_type) { ++ case FLV_STREAM_TYPE_VIDEO: st->codec->codec_type = AVMEDIA_TYPE_VIDEO; break; ++ case FLV_STREAM_TYPE_AUDIO: st->codec->codec_type = AVMEDIA_TYPE_AUDIO; break; ++ case FLV_STREAM_TYPE_DATA: ++ st->codec->codec_type = AVMEDIA_TYPE_DATA; ++ st->codec->codec_id = CODEC_ID_NONE; // Going to rely on copy for now ++ av_log(s, AV_LOG_DEBUG, "Data stream created\n"); ++ } ++ if(s->nb_streams>=3 ||( s->nb_streams==2 ++ && s->streams[0]->codec->codec_type != AVMEDIA_TYPE_DATA ++ && s->streams[1]->codec->codec_type != AVMEDIA_TYPE_DATA)) ++ s->ctx_flags &= ~AVFMTCTX_NOHEADER; ++ ++ avpriv_set_pts_info(st, 32, 1, 1000); /* 32 bit pts in ms */ + return st; + } + +@@ -322,37 +383,45 @@ + { + int offset, flags; + +- url_fskip(s->pb, 4); +- flags = get_byte(s->pb); ++ avio_skip(s->pb, 4); ++ flags = avio_r8(s->pb); + /* old flvtool cleared this field */ + /* FIXME: better fix needed */ + if (!flags) { + flags = FLV_HEADER_FLAG_HASVIDEO | FLV_HEADER_FLAG_HASAUDIO; + av_log(s, AV_LOG_WARNING, "Broken FLV file, which says no streams present, this might fail\n"); + } +- +- if((flags & (FLV_HEADER_FLAG_HASVIDEO|FLV_HEADER_FLAG_HASAUDIO)) +- != (FLV_HEADER_FLAG_HASVIDEO|FLV_HEADER_FLAG_HASAUDIO)) + s->ctx_flags |= AVFMTCTX_NOHEADER; + + if(flags & FLV_HEADER_FLAG_HASVIDEO){ +- if(!create_stream(s, 0)) ++ if(!create_stream(s, FLV_STREAM_TYPE_VIDEO)) + return AVERROR(ENOMEM); + } + if(flags & FLV_HEADER_FLAG_HASAUDIO){ +- if(!create_stream(s, 1)) ++ if(!create_stream(s, FLV_STREAM_TYPE_AUDIO)) + return AVERROR(ENOMEM); + } ++ // Flag doesn't indicate whether or not there is script-data present. Must ++ // create that stream if it's encountered. + +- offset = get_be32(s->pb); +- url_fseek(s->pb, offset, SEEK_SET); +- url_fskip(s->pb, 4); ++ offset = avio_rb32(s->pb); ++ avio_seek(s->pb, offset, SEEK_SET); ++ avio_skip(s->pb, 4); + + s->start_time = 0; + + return 0; + } + ++static int flv_read_close(AVFormatContext *s) ++{ ++ int i; ++ FLVContext *flv = s->priv_data; ++ for(i=0; inew_extradata[i]); ++ return 0; ++} ++ + static int flv_get_extradata(AVFormatContext *s, AVStream *st, int size) + { + av_free(st->codec->extradata); +@@ -360,52 +429,73 @@ + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = size; +- get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size); ++ avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); ++ return 0; ++} ++ ++static int flv_queue_extradata(FLVContext *flv, AVIOContext *pb, int stream, ++ int size) ++{ ++ av_free(flv->new_extradata[stream]); ++ flv->new_extradata[stream] = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!flv->new_extradata[stream]) ++ return AVERROR(ENOMEM); ++ flv->new_extradata_size[stream] = size; ++ avio_read(pb, flv->new_extradata[stream], size); + return 0; + } + + static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) + { + FLVContext *flv = s->priv_data; +- int ret, i, type, size, flags, is_audio; ++ int ret, i, type, size, flags; ++ int stream_type=-1; + int64_t next, pos; + int64_t dts, pts = AV_NOPTS_VALUE; ++ int av_uninit(channels); ++ int av_uninit(sample_rate); + AVStream *st = NULL; + +- for(;;url_fskip(s->pb, 4)){ /* pkt size is repeated at end. skip it */ +- pos = url_ftell(s->pb); +- type = get_byte(s->pb); +- size = get_be24(s->pb); +- dts = get_be24(s->pb); +- dts |= get_byte(s->pb) << 24; +-// av_log(s, AV_LOG_DEBUG, "type:%d, size:%d, dts:%d\n", type, size, dts); ++ for(;;avio_skip(s->pb, 4)){ /* pkt size is repeated at end. skip it */ ++ pos = avio_tell(s->pb); ++ type = avio_r8(s->pb); ++ size = avio_rb24(s->pb); ++ dts = avio_rb24(s->pb); ++ dts |= avio_r8(s->pb) << 24; ++ av_dlog(s, "type:%d, size:%d, dts:%"PRId64"\n", type, size, dts); + if (url_feof(s->pb)) + return AVERROR_EOF; +- url_fskip(s->pb, 3); /* stream id, always 0 */ ++ avio_skip(s->pb, 3); /* stream id, always 0 */ + flags = 0; + + if(size == 0) + continue; + +- next= size + url_ftell(s->pb); ++ next= size + avio_tell(s->pb); + + if (type == FLV_TAG_TYPE_AUDIO) { +- is_audio=1; +- flags = get_byte(s->pb); ++ stream_type=FLV_STREAM_TYPE_AUDIO; ++ flags = avio_r8(s->pb); + size--; + } else if (type == FLV_TAG_TYPE_VIDEO) { +- is_audio=0; +- flags = get_byte(s->pb); ++ stream_type=FLV_STREAM_TYPE_VIDEO; ++ flags = avio_r8(s->pb); + size--; + if ((flags & 0xf0) == 0x50) /* video info / command frame */ + goto skip; +- } else { +- if (type == FLV_TAG_TYPE_META && size > 13+1+4) ++ } else if (type == FLV_TAG_TYPE_META) { ++ if (size > 13+1+4 && dts == 0) { // Header-type metadata stuff + flv_read_metabody(s, next); +- else /* skip packet */ +- av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); ++ goto skip; ++ } else if (dts != 0) { // Script-data "special" metadata frames - don't skip ++ stream_type=FLV_STREAM_TYPE_DATA; ++ } else { ++ goto skip; ++ } ++ } else { ++ av_log(s, AV_LOG_DEBUG, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags); + skip: +- url_fseek(s->pb, next, SEEK_SET); ++ avio_seek(s->pb, next, SEEK_SET); + continue; + } + +@@ -416,20 +506,19 @@ + /* now find stream */ + for(i=0;inb_streams;i++) { + st = s->streams[i]; +- if (st->id == is_audio) ++ if (st->id == stream_type) + break; + } + if(i == s->nb_streams){ +- av_log(s, AV_LOG_ERROR, "invalid stream\n"); +- st= create_stream(s, is_audio); +- s->ctx_flags &= ~AVFMTCTX_NOHEADER; ++ av_log(s, AV_LOG_WARNING, "Stream discovered after head already parsed\n"); ++ st= create_stream(s, stream_type); + } +-// av_log(s, AV_LOG_DEBUG, "%d %X %d \n", is_audio, flags, st->discard); +- if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || is_audio)) +- ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && !is_audio)) ++ av_dlog(s, "%d %X %d \n", stream_type, flags, st->discard); ++ if( (st->discard >= AVDISCARD_NONKEY && !((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY || (stream_type == FLV_STREAM_TYPE_AUDIO))) ++ ||(st->discard >= AVDISCARD_BIDIR && ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_DISP_INTER && (stream_type == FLV_STREAM_TYPE_VIDEO))) + || st->discard >= AVDISCARD_ALL + ){ +- url_fseek(s->pb, next, SEEK_SET); ++ avio_seek(s->pb, next, SEEK_SET); + continue; + } + if ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) +@@ -438,40 +527,52 @@ + } + + // if not streamed and no duration from metadata then seek to end to find the duration from the timestamps +- if(!url_is_streamed(s->pb) && (!s->duration || s->duration==AV_NOPTS_VALUE)){ ++ if(s->pb->seekable && (!s->duration || s->duration==AV_NOPTS_VALUE)){ + int size; +- const int64_t pos= url_ftell(s->pb); +- const int64_t fsize= url_fsize(s->pb); +- url_fseek(s->pb, fsize-4, SEEK_SET); +- size= get_be32(s->pb); +- url_fseek(s->pb, fsize-3-size, SEEK_SET); +- if(size == get_be24(s->pb) + 11){ +- uint32_t ts = get_be24(s->pb); +- ts |= get_byte(s->pb) << 24; ++ const int64_t pos= avio_tell(s->pb); ++ const int64_t fsize= avio_size(s->pb); ++ avio_seek(s->pb, fsize-4, SEEK_SET); ++ size= avio_rb32(s->pb); ++ avio_seek(s->pb, fsize-3-size, SEEK_SET); ++ if(size == avio_rb24(s->pb) + 11){ ++ uint32_t ts = avio_rb24(s->pb); ++ ts |= avio_r8(s->pb) << 24; + s->duration = ts * (int64_t)AV_TIME_BASE / 1000; + } +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + } + +- if(is_audio){ ++ if(stream_type == FLV_STREAM_TYPE_AUDIO){ ++ int bits_per_coded_sample; ++ channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; ++ sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); ++ bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; + if(!st->codec->channels || !st->codec->sample_rate || !st->codec->bits_per_coded_sample) { +- st->codec->channels = (flags & FLV_AUDIO_CHANNEL_MASK) == FLV_STEREO ? 2 : 1; +- st->codec->sample_rate = (44100 << ((flags & FLV_AUDIO_SAMPLERATE_MASK) >> FLV_AUDIO_SAMPLERATE_OFFSET) >> 3); +- st->codec->bits_per_coded_sample = (flags & FLV_AUDIO_SAMPLESIZE_MASK) ? 16 : 8; ++ st->codec->channels = channels; ++ st->codec->sample_rate = sample_rate; ++ st->codec->bits_per_coded_sample = bits_per_coded_sample; + } + if(!st->codec->codec_id){ +- flv_set_audio_codec(s, st, flags & FLV_AUDIO_CODECID_MASK); ++ flv_set_audio_codec(s, st, st->codec, flags & FLV_AUDIO_CODECID_MASK); ++ flv->last_sample_rate = st->codec->sample_rate; ++ flv->last_channels = st->codec->channels; ++ } else { ++ AVCodecContext ctx; ++ ctx.sample_rate = sample_rate; ++ flv_set_audio_codec(s, st, &ctx, flags & FLV_AUDIO_CODECID_MASK); ++ sample_rate = ctx.sample_rate; + } +- }else{ ++ } else if(stream_type == FLV_STREAM_TYPE_VIDEO) { + size -= flv_set_video_codec(s, st, flags & FLV_VIDEO_CODECID_MASK); + } + + if (st->codec->codec_id == CODEC_ID_AAC || +- st->codec->codec_id == CODEC_ID_H264) { +- int type = get_byte(s->pb); ++ st->codec->codec_id == CODEC_ID_H264 || ++ st->codec->codec_id == CODEC_ID_MPEG4) { ++ int type = avio_r8(s->pb); + size--; +- if (st->codec->codec_id == CODEC_ID_H264) { +- int32_t cts = (get_be24(s->pb)+0xff800000)^0xff800000; // sign extension ++ if (st->codec->codec_id == CODEC_ID_H264 || st->codec->codec_id == CODEC_ID_MPEG4) { ++ int32_t cts = (avio_rb24(s->pb)+0xff800000)^0xff800000; // sign extension + pts = dts + cts; + if (cts < 0) { // dts are wrong + flv->wrong_dts = 1; +@@ -480,13 +581,19 @@ + if (flv->wrong_dts) + dts = AV_NOPTS_VALUE; + } +- if (type == 0) { ++ if (type == 0 && !st->codec->extradata) { ++ if (st->codec->extradata) { ++ if ((ret = flv_queue_extradata(flv, s->pb, stream_type, size)) < 0) ++ return ret; ++ ret = AVERROR(EAGAIN); ++ goto leave; ++ } + if ((ret = flv_get_extradata(s, st, size)) < 0) + return ret; + if (st->codec->codec_id == CODEC_ID_AAC) { + MPEG4AudioConfig cfg; +- ff_mpeg4audio_get_config(&cfg, st->codec->extradata, +- st->codec->extradata_size); ++ if (avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, ++ st->codec->extradata_size * 8, 1) >= 0) { + st->codec->channels = cfg.channels; + if (cfg.ext_sample_rate) + st->codec->sample_rate = cfg.ext_sample_rate; +@@ -494,6 +601,7 @@ + st->codec->sample_rate = cfg.sample_rate; + av_dlog(s, "mp4a config channels %d sample rate %d\n", + st->codec->channels, st->codec->sample_rate); ++ } + } + + ret = AVERROR(EAGAIN); +@@ -517,19 +625,37 @@ + pkt->dts = dts; + pkt->pts = pts == AV_NOPTS_VALUE ? dts : pts; + pkt->stream_index = st->index; +- +- if (is_audio || ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY)) ++ if (flv->new_extradata[stream_type]) { ++ uint8_t *side = av_packet_new_side_data(pkt, AV_PKT_DATA_NEW_EXTRADATA, ++ flv->new_extradata_size[stream_type]); ++ if (side) { ++ memcpy(side, flv->new_extradata[stream_type], ++ flv->new_extradata_size[stream_type]); ++ av_freep(&flv->new_extradata[stream_type]); ++ flv->new_extradata_size[stream_type] = 0; ++ } ++ } ++ if (stream_type == FLV_STREAM_TYPE_AUDIO && (sample_rate != flv->last_sample_rate || ++ channels != flv->last_channels)) { ++ flv->last_sample_rate = sample_rate; ++ flv->last_channels = channels; ++ ff_add_param_change(pkt, channels, 0, sample_rate, 0, 0); ++ } ++ ++ if ( stream_type == FLV_STREAM_TYPE_AUDIO || ++ ((flags & FLV_VIDEO_FRAMETYPE_MASK) == FLV_FRAME_KEY) || ++ stream_type == FLV_STREAM_TYPE_DATA) + pkt->flags |= AV_PKT_FLAG_KEY; + + leave: +- url_fskip(s->pb, 4); ++ avio_skip(s->pb, 4); + return ret; + } + + static int flv_read_seek(AVFormatContext *s, int stream_index, + int64_t ts, int flags) + { +- return av_url_read_fseek(s->pb, stream_index, ts, flags); ++ return avio_seek_time(s->pb, stream_index, ts, flags); + } + + #if 0 /* don't know enough to implement this */ +@@ -540,7 +666,7 @@ + + if (ts - min_ts > (uint64_t)(max_ts - ts)) flags |= AVSEEK_FLAG_BACKWARD; + +- if (url_is_streamed(s->pb)) { ++ if (!s->pb->seekable) { + if (stream_index < 0) { + stream_index = av_find_default_stream_index(s); + if (stream_index < 0) +@@ -550,7 +676,7 @@ + ts = av_rescale_rnd(ts, 1000, AV_TIME_BASE, + flags & AVSEEK_FLAG_BACKWARD ? AV_ROUND_DOWN : AV_ROUND_UP); + } +- ret = av_url_read_fseek(s->pb, stream_index, ts, flags); ++ ret = avio_seek_time(s->pb, stream_index, ts, flags); + } + + if (ret == AVERROR(ENOSYS)) +@@ -560,16 +686,17 @@ + #endif + + AVInputFormat ff_flv_demuxer = { +- "flv", +- NULL_IF_CONFIG_SMALL("FLV format"), +- sizeof(FLVContext), +- flv_probe, +- flv_read_header, +- flv_read_packet, ++ .name = "flv", ++ .long_name = NULL_IF_CONFIG_SMALL("FLV format"), ++ .priv_data_size = sizeof(FLVContext), ++ .read_probe = flv_probe, ++ .read_header = flv_read_header, ++ .read_packet = flv_read_packet, + .read_seek = flv_read_seek, + #if 0 + .read_seek2 = flv_read_seek2, + #endif ++ .read_close = flv_read_close, + .extensions = "flv", + .value = CODEC_ID_FLV1, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flvenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flvenc.c 2012-05-14 14:08:54.960352580 +0200 +@@ -18,17 +18,23 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" + #include "flv.h" + #include "internal.h" + #include "avc.h" + #include "metadata.h" ++#include "libavutil/dict.h" + + #undef NDEBUG + #include + + static const AVCodecTag flv_video_codec_ids[] = { + {CODEC_ID_FLV1, FLV_CODECID_H263 }, ++ {CODEC_ID_H263, FLV_CODECID_REALH263}, ++ {CODEC_ID_MPEG4, FLV_CODECID_MPEG4 }, + {CODEC_ID_FLASHSV, FLV_CODECID_SCREEN}, + {CODEC_ID_FLASHSV2, FLV_CODECID_SCREEN2}, + {CODEC_ID_VP6F, FLV_CODECID_VP6 }, +@@ -54,10 +60,13 @@ + int64_t duration_offset; + int64_t filesize_offset; + int64_t duration; +- int delay; ///< first dts delay for AVC +- int64_t last_video_ts; ++ int64_t delay; ///< first dts delay (needed for AVC & Speex) + } FLVContext; + ++typedef struct FLVStreamContext { ++ int64_t last_ts; ///< last timestamp for each stream ++} FLVStreamContext; ++ + static int get_audio_flags(AVCodecContext *enc){ + int flags = (enc->bits_per_coded_sample == 16) ? FLV_SAMPLESSIZE_16BIT : FLV_SAMPLESSIZE_8BIT; + +@@ -72,11 +81,6 @@ + av_log(enc, AV_LOG_ERROR, "flv only supports mono Speex audio\n"); + return -1; + } +- if (enc->frame_size / 320 > 8) { +- av_log(enc, AV_LOG_WARNING, "Warning: Speex stream has more than " +- "8 frames per packet. Adobe Flash " +- "Player cannot handle this!\n"); +- } + return FLV_CODECID_SPEEX | FLV_SAMPLERATE_11025HZ | FLV_SAMPLESSIZE_16BIT; + } else { + switch (enc->sample_rate) { +@@ -89,6 +93,7 @@ + case 11025: + flags |= FLV_SAMPLERATE_11025HZ; + break; ++ case 16000: //nellymoser only + case 8000: //nellymoser only + case 5512: //not mp3 + if(enc->codec_id != CODEC_ID_MP3){ +@@ -124,6 +129,8 @@ + case CODEC_ID_NELLYMOSER: + if (enc->sample_rate == 8000) { + flags |= FLV_CODECID_NELLYMOSER_8KHZ_MONO | FLV_SAMPLESSIZE_16BIT; ++ } else if (enc->sample_rate == 16000) { ++ flags |= FLV_CODECID_NELLYMOSER_16KHZ_MONO | FLV_SAMPLESSIZE_16BIT; + } else { + flags |= FLV_CODECID_NELLYMOSER | FLV_SAMPLESSIZE_16BIT; + } +@@ -139,48 +146,49 @@ + return flags; + } + +-static void put_amf_string(ByteIOContext *pb, const char *str) ++static void put_amf_string(AVIOContext *pb, const char *str) + { + size_t len = strlen(str); +- put_be16(pb, len); +- put_buffer(pb, str, len); ++ avio_wb16(pb, len); ++ avio_write(pb, str, len); + } + +-static void put_avc_eos_tag(ByteIOContext *pb, unsigned ts) { +- put_byte(pb, FLV_TAG_TYPE_VIDEO); +- put_be24(pb, 5); /* Tag Data Size */ +- put_be24(pb, ts); /* lower 24 bits of timestamp in ms*/ +- put_byte(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms*/ +- put_be24(pb, 0); /* StreamId = 0 */ +- put_byte(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */ +- put_byte(pb, 2); /* AVC end of sequence */ +- put_be24(pb, 0); /* Always 0 for AVC EOS. */ +- put_be32(pb, 16); /* Size of FLV tag */ ++static void put_avc_eos_tag(AVIOContext *pb, unsigned ts) { ++ avio_w8(pb, FLV_TAG_TYPE_VIDEO); ++ avio_wb24(pb, 5); /* Tag Data Size */ ++ avio_wb24(pb, ts); /* lower 24 bits of timestamp in ms*/ ++ avio_w8(pb, (ts >> 24) & 0x7F); /* MSB of ts in ms*/ ++ avio_wb24(pb, 0); /* StreamId = 0 */ ++ avio_w8(pb, 23); /* ub[4] FrameType = 1, ub[4] CodecId = 7 */ ++ avio_w8(pb, 2); /* AVC end of sequence */ ++ avio_wb24(pb, 0); /* Always 0 for AVC EOS. */ ++ avio_wb32(pb, 16); /* Size of FLV tag */ + } + +-static void put_amf_double(ByteIOContext *pb, double d) ++static void put_amf_double(AVIOContext *pb, double d) + { +- put_byte(pb, AMF_DATA_TYPE_NUMBER); +- put_be64(pb, av_dbl2int(d)); ++ avio_w8(pb, AMF_DATA_TYPE_NUMBER); ++ avio_wb64(pb, av_double2int(d)); + } + +-static void put_amf_bool(ByteIOContext *pb, int b) { +- put_byte(pb, AMF_DATA_TYPE_BOOL); +- put_byte(pb, !!b); ++static void put_amf_bool(AVIOContext *pb, int b) { ++ avio_w8(pb, AMF_DATA_TYPE_BOOL); ++ avio_w8(pb, !!b); + } + + static int flv_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + FLVContext *flv = s->priv_data; + AVCodecContext *audio_enc = NULL, *video_enc = NULL; +- int i; ++ int i, metadata_count = 0; + double framerate = 0.0; +- int metadata_size_pos, data_size; +- AVMetadataTag *tag = NULL; ++ int64_t metadata_size_pos, data_size, metadata_count_pos; ++ AVDictionaryEntry *tag = NULL; + + for(i=0; inb_streams; i++){ + AVCodecContext *enc = s->streams[i]->codec; ++ FLVStreamContext *sc; + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { + if (s->streams[i]->r_frame_rate.den && s->streams[i]->r_frame_rate.num) { + framerate = av_q2d(s->streams[i]->r_frame_rate); +@@ -192,52 +200,60 @@ + av_log(enc, AV_LOG_ERROR, "video codec not compatible with flv\n"); + return -1; + } +- } else { ++ } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + audio_enc = enc; + if(get_audio_flags(enc)<0) + return -1; + } +- av_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */ +- } +- put_tag(pb,"FLV"); +- put_byte(pb,1); +- put_byte(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc ++ avpriv_set_pts_info(s->streams[i], 32, 1, 1000); /* 32 bit pts in ms */ ++ ++ sc = av_mallocz(sizeof(FLVStreamContext)); ++ if (!sc) ++ return AVERROR(ENOMEM); ++ s->streams[i]->priv_data = sc; ++ sc->last_ts = -1; ++ } ++ flv->delay = AV_NOPTS_VALUE; ++ ++ avio_write(pb, "FLV", 3); ++ avio_w8(pb,1); ++ avio_w8(pb, FLV_HEADER_FLAG_HASAUDIO * !!audio_enc + + FLV_HEADER_FLAG_HASVIDEO * !!video_enc); +- put_be32(pb,9); +- put_be32(pb,0); ++ avio_wb32(pb,9); ++ avio_wb32(pb,0); + + for(i=0; inb_streams; i++){ + if(s->streams[i]->codec->codec_tag == 5){ +- put_byte(pb,8); // message type +- put_be24(pb,0); // include flags +- put_be24(pb,0); // time stamp +- put_be32(pb,0); // reserved +- put_be32(pb,11); // size ++ avio_w8(pb,8); // message type ++ avio_wb24(pb,0); // include flags ++ avio_wb24(pb,0); // time stamp ++ avio_wb32(pb,0); // reserved ++ avio_wb32(pb,11); // size + flv->reserved=5; + } + } + +- flv->last_video_ts = -1; +- + /* write meta_tag */ +- put_byte(pb, 18); // tag type META +- metadata_size_pos= url_ftell(pb); +- put_be24(pb, 0); // size of data part (sum of all parts below) +- put_be24(pb, 0); // time stamp +- put_be32(pb, 0); // reserved ++ avio_w8(pb, 18); // tag type META ++ metadata_size_pos= avio_tell(pb); ++ avio_wb24(pb, 0); // size of data part (sum of all parts below) ++ avio_wb24(pb, 0); // time stamp ++ avio_wb32(pb, 0); // reserved + + /* now data of data_size size */ + + /* first event name as a string */ +- put_byte(pb, AMF_DATA_TYPE_STRING); ++ avio_w8(pb, AMF_DATA_TYPE_STRING); + put_amf_string(pb, "onMetaData"); // 12 bytes + + /* mixed array (hash) with size and string/type/data tuples */ +- put_byte(pb, AMF_DATA_TYPE_MIXEDARRAY); +- put_be32(pb, 5*!!video_enc + 5*!!audio_enc + 2); // +2 for duration and file size ++ avio_w8(pb, AMF_DATA_TYPE_MIXEDARRAY); ++ metadata_count_pos = avio_tell(pb); ++ metadata_count = 5*!!video_enc + 5*!!audio_enc + 2; // +2 for duration and file size ++ avio_wb32(pb, metadata_count); + + put_amf_string(pb, "duration"); +- flv->duration_offset= url_ftell(pb); ++ flv->duration_offset= avio_tell(pb); + put_amf_double(pb, s->duration / AV_TIME_BASE); // fill in the guessed duration, it'll be corrected later if incorrect + + if(video_enc){ +@@ -274,52 +290,73 @@ + put_amf_double(pb, audio_enc->codec_tag); + } + +- while ((tag = av_metadata_get(s->metadata, "", tag, AV_METADATA_IGNORE_SUFFIX))) { ++ while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { ++ if( !strcmp(tag->key, "width") ++ ||!strcmp(tag->key, "height") ++ ||!strcmp(tag->key, "videodatarate") ++ ||!strcmp(tag->key, "framerate") ++ ||!strcmp(tag->key, "videocodecid") ++ ||!strcmp(tag->key, "audiodatarate") ++ ||!strcmp(tag->key, "audiosamplerate") ++ ||!strcmp(tag->key, "audiosamplesize") ++ ||!strcmp(tag->key, "stereo") ++ ||!strcmp(tag->key, "audiocodecid") ++ ||!strcmp(tag->key, "duration") ++ ||!strcmp(tag->key, "onMetaData") ++ ){ ++ av_log(s, AV_LOG_DEBUG, "ignoring metadata for %s\n", tag->key); ++ continue; ++ } + put_amf_string(pb, tag->key); +- put_byte(pb, AMF_DATA_TYPE_STRING); ++ avio_w8(pb, AMF_DATA_TYPE_STRING); + put_amf_string(pb, tag->value); ++ metadata_count++; + } + + put_amf_string(pb, "filesize"); +- flv->filesize_offset= url_ftell(pb); ++ flv->filesize_offset= avio_tell(pb); + put_amf_double(pb, 0); // delayed write + + put_amf_string(pb, ""); +- put_byte(pb, AMF_END_OF_OBJECT); ++ avio_w8(pb, AMF_END_OF_OBJECT); + + /* write total size of tag */ +- data_size= url_ftell(pb) - metadata_size_pos - 10; +- url_fseek(pb, metadata_size_pos, SEEK_SET); +- put_be24(pb, data_size); +- url_fseek(pb, data_size + 10 - 3, SEEK_CUR); +- put_be32(pb, data_size + 11); ++ data_size= avio_tell(pb) - metadata_size_pos - 10; ++ ++ avio_seek(pb, metadata_count_pos, SEEK_SET); ++ avio_wb32(pb, metadata_count); ++ ++ avio_seek(pb, metadata_size_pos, SEEK_SET); ++ avio_wb24(pb, data_size); ++ avio_skip(pb, data_size + 10 - 3); ++ avio_wb32(pb, data_size + 11); + + for (i = 0; i < s->nb_streams; i++) { + AVCodecContext *enc = s->streams[i]->codec; +- if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264) { ++ if (enc->codec_id == CODEC_ID_AAC || enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { + int64_t pos; +- put_byte(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? ++ avio_w8(pb, enc->codec_type == AVMEDIA_TYPE_VIDEO ? + FLV_TAG_TYPE_VIDEO : FLV_TAG_TYPE_AUDIO); +- put_be24(pb, 0); // size patched later +- put_be24(pb, 0); // ts +- put_byte(pb, 0); // ts ext +- put_be24(pb, 0); // streamid +- pos = url_ftell(pb); ++ avio_wb24(pb, 0); // size patched later ++ avio_wb24(pb, 0); // ts ++ avio_w8(pb, 0); // ts ext ++ avio_wb24(pb, 0); // streamid ++ pos = avio_tell(pb); + if (enc->codec_id == CODEC_ID_AAC) { +- put_byte(pb, get_audio_flags(enc)); +- put_byte(pb, 0); // AAC sequence header +- put_buffer(pb, enc->extradata, enc->extradata_size); ++ avio_w8(pb, get_audio_flags(enc)); ++ avio_w8(pb, 0); // AAC sequence header ++ avio_write(pb, enc->extradata, enc->extradata_size); + } else { +- put_byte(pb, enc->codec_tag | FLV_FRAME_KEY); // flags +- put_byte(pb, 0); // AVC sequence header +- put_be24(pb, 0); // composition time ++ avio_w8(pb, enc->codec_tag | FLV_FRAME_KEY); // flags ++ avio_w8(pb, 0); // AVC sequence header ++ avio_wb24(pb, 0); // composition time + ff_isom_write_avcc(pb, enc->extradata, enc->extradata_size); + } +- data_size = url_ftell(pb) - pos; +- url_fseek(pb, -data_size - 10, SEEK_CUR); +- put_be24(pb, data_size); +- url_fseek(pb, data_size + 10 - 3, SEEK_CUR); +- put_be32(pb, data_size + 11); // previous tag size ++ data_size = avio_tell(pb) - pos; ++ avio_seek(pb, -data_size - 10, SEEK_CUR); ++ avio_wb24(pb, data_size); ++ avio_skip(pb, data_size + 10 - 3); ++ avio_wb32(pb, data_size + 11); // previous tag size + } + } + +@@ -330,36 +367,38 @@ + { + int64_t file_size; + +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + FLVContext *flv = s->priv_data; + int i; + + /* Add EOS tag */ + for (i = 0; i < s->nb_streams; i++) { + AVCodecContext *enc = s->streams[i]->codec; ++ FLVStreamContext *sc = s->streams[i]->priv_data; + if (enc->codec_type == AVMEDIA_TYPE_VIDEO && +- enc->codec_id == CODEC_ID_H264) { +- put_avc_eos_tag(pb, flv->last_video_ts); ++ (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4)) { ++ put_avc_eos_tag(pb, sc->last_ts); + } + } + +- file_size = url_ftell(pb); ++ file_size = avio_tell(pb); + +- /* update informations */ +- url_fseek(pb, flv->duration_offset, SEEK_SET); ++ /* update information */ ++ avio_seek(pb, flv->duration_offset, SEEK_SET); + put_amf_double(pb, flv->duration / (double)1000); +- url_fseek(pb, flv->filesize_offset, SEEK_SET); ++ avio_seek(pb, flv->filesize_offset, SEEK_SET); + put_amf_double(pb, file_size); + +- url_fseek(pb, file_size, SEEK_SET); ++ avio_seek(pb, file_size, SEEK_SET); + return 0; + } + + static int flv_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[pkt->stream_index]->codec; + FLVContext *flv = s->priv_data; ++ FLVStreamContext *sc = s->streams[pkt->stream_index]->priv_data; + unsigned ts; + int size= pkt->size; + uint8_t *data= NULL; +@@ -370,88 +409,112 @@ + if(enc->codec_id == CODEC_ID_VP6 || enc->codec_id == CODEC_ID_VP6F || + enc->codec_id == CODEC_ID_AAC) + flags_size= 2; +- else if(enc->codec_id == CODEC_ID_H264) ++ else if(enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) + flags_size= 5; + else + flags_size= 1; + + if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { +- put_byte(pb, FLV_TAG_TYPE_VIDEO); ++ avio_w8(pb, FLV_TAG_TYPE_VIDEO); + + flags = enc->codec_tag; + if(flags == 0) { +- av_log(enc, AV_LOG_ERROR, "video codec %X not compatible with flv\n",enc->codec_id); ++ av_log(enc, AV_LOG_ERROR, "video codec %s not compatible with flv\n", avcodec_get_name(enc->codec_id)); + return -1; + } + + flags |= pkt->flags & AV_PKT_FLAG_KEY ? FLV_FRAME_KEY : FLV_FRAME_INTER; +- } else { +- assert(enc->codec_type == AVMEDIA_TYPE_AUDIO); ++ } else if (enc->codec_type == AVMEDIA_TYPE_AUDIO) { + flags = get_audio_flags(enc); + + assert(size); + +- put_byte(pb, FLV_TAG_TYPE_AUDIO); ++ avio_w8(pb, FLV_TAG_TYPE_AUDIO); ++ } else { ++ // In-band flv metadata ("scriptdata") ++ assert(enc->codec_type == AVMEDIA_TYPE_DATA); ++ avio_w8(pb, FLV_TAG_TYPE_META); ++ flags_size = 0; ++ flags = 0; + } + +- if (enc->codec_id == CODEC_ID_H264) { ++ if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { + /* check if extradata looks like mp4 formated */ + if (enc->extradata_size > 0 && *(uint8_t*)enc->extradata != 1) { + if (ff_avc_parse_nal_units_buf(pkt->data, &data, &size) < 0) + return -1; + } +- if (!flv->delay && pkt->dts < 0) +- flv->delay = -pkt->dts; ++ } else if (enc->codec_id == CODEC_ID_AAC && pkt->size > 2 && ++ (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { ++ av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n"); ++ return -1; ++ } ++ if (flv->delay == AV_NOPTS_VALUE) ++ flv->delay = -pkt->dts; ++ if (pkt->dts < -flv->delay) { ++ av_log(s, AV_LOG_WARNING, "Packets are not in the proper order with " ++ "respect to DTS\n"); ++ return AVERROR(EINVAL); + } + + ts = pkt->dts + flv->delay; // add delay to force positive dts +- if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { +- if (flv->last_video_ts < ts) +- flv->last_video_ts = ts; +- } +- put_be24(pb,size + flags_size); +- put_be24(pb,ts); +- put_byte(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_ +- put_be24(pb,flv->reserved); +- put_byte(pb,flags); ++ ++ /* check Speex packet duration */ ++ if (enc->codec_id == CODEC_ID_SPEEX && ts - sc->last_ts > 160) { ++ av_log(s, AV_LOG_WARNING, "Warning: Speex stream has more than " ++ "8 frames per packet. Adobe Flash " ++ "Player cannot handle this!\n"); ++ } ++ ++ if (sc->last_ts < ts) ++ sc->last_ts = ts; ++ ++ avio_wb24(pb,size + flags_size); ++ avio_wb24(pb,ts); ++ avio_w8(pb,(ts >> 24) & 0x7F); // timestamps are 32bits _signed_ ++ avio_wb24(pb,flv->reserved); ++ ++ if(flags_size) ++ avio_w8(pb,flags); ++ + if (enc->codec_id == CODEC_ID_VP6) +- put_byte(pb,0); ++ avio_w8(pb,0); + if (enc->codec_id == CODEC_ID_VP6F) +- put_byte(pb, enc->extradata_size ? enc->extradata[0] : 0); ++ avio_w8(pb, enc->extradata_size ? enc->extradata[0] : 0); + else if (enc->codec_id == CODEC_ID_AAC) +- put_byte(pb,1); // AAC raw +- else if (enc->codec_id == CODEC_ID_H264) { +- put_byte(pb,1); // AVC NALU +- put_be24(pb,pkt->pts - pkt->dts); ++ avio_w8(pb,1); // AAC raw ++ else if (enc->codec_id == CODEC_ID_H264 || enc->codec_id == CODEC_ID_MPEG4) { ++ avio_w8(pb,1); // AVC NALU ++ avio_wb24(pb,pkt->pts - pkt->dts); + } + +- put_buffer(pb, data ? data : pkt->data, size); ++ avio_write(pb, data ? data : pkt->data, size); + +- put_be32(pb,size+flags_size+11); // previous tag size ++ avio_wb32(pb,size+flags_size+11); // previous tag size + flv->duration = FFMAX(flv->duration, pkt->pts + flv->delay + pkt->duration); + +- put_flush_packet(pb); ++ avio_flush(pb); + + av_free(data); + +- return 0; ++ return pb->error; + } + + AVOutputFormat ff_flv_muxer = { +- "flv", +- NULL_IF_CONFIG_SMALL("FLV format"), +- "video/x-flv", +- "flv", +- sizeof(FLVContext), ++ .name = "flv", ++ .long_name = NULL_IF_CONFIG_SMALL("FLV format"), ++ .mime_type = "video/x-flv", ++ .extensions = "flv", ++ .priv_data_size = sizeof(FLVContext), + #if CONFIG_LIBMP3LAME +- CODEC_ID_MP3, ++ .audio_codec = CODEC_ID_MP3, + #else // CONFIG_LIBMP3LAME +- CODEC_ID_ADPCM_SWF, ++ .audio_codec = CODEC_ID_ADPCM_SWF, + #endif // CONFIG_LIBMP3LAME +- CODEC_ID_FLV1, +- flv_write_header, +- flv_write_packet, +- flv_write_trailer, ++ .video_codec = CODEC_ID_FLV1, ++ .write_header = flv_write_header, ++ .write_packet = flv_write_packet, ++ .write_trailer = flv_write_trailer, + .codec_tag= (const AVCodecTag* const []){flv_video_codec_ids, flv_audio_codec_ids, 0}, + .flags= AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flv.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flv.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/flv.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/flv.h 2012-05-14 14:08:54.955352480 +0200 +@@ -1,5 +1,4 @@ +-/** +- * @file ++/* + * FLV common header + * + * Copyright (c) 2006 The FFmpeg Project +@@ -21,6 +20,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * FLV common header ++ */ ++ + #ifndef AVFORMAT_FLV_H + #define AVFORMAT_FLV_H + +@@ -42,6 +46,11 @@ + + #define AMF_END_OF_OBJECT 0x09 + ++#define KEYFRAMES_TAG "keyframes" ++#define KEYFRAMES_TIMESTAMP_TAG "times" ++#define KEYFRAMES_BYTEOFFSET_TAG "filepositions" ++ ++ + enum { + FLV_HEADER_FLAG_HASVIDEO = 1, + FLV_HEADER_FLAG_HASAUDIO = 4, +@@ -54,6 +63,13 @@ + }; + + enum { ++ FLV_STREAM_TYPE_VIDEO, ++ FLV_STREAM_TYPE_AUDIO, ++ FLV_STREAM_TYPE_DATA, ++ FLV_STREAM_TYPE_NB, ++}; ++ ++enum { + FLV_MONO = 0, + FLV_STEREO = 1, + }; +@@ -89,6 +105,8 @@ + FLV_CODECID_VP6A = 5, + FLV_CODECID_SCREEN2 = 6, + FLV_CODECID_H264 = 7, ++ FLV_CODECID_REALH263= 8, ++ FLV_CODECID_MPEG4 = 9, + }; + + enum { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/framecrcenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/framecrcenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/framecrcenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/framecrcenc.c 2012-05-14 14:08:54.960352580 +0200 +@@ -28,20 +28,16 @@ + char buf[256]; + + snprintf(buf, sizeof(buf), "%d, %"PRId64", %d, 0x%08x\n", pkt->stream_index, pkt->dts, pkt->size, crc); +- put_buffer(s->pb, buf, strlen(buf)); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf, strlen(buf)); ++ avio_flush(s->pb); + return 0; + } + + AVOutputFormat ff_framecrc_muxer = { +- "framecrc", +- NULL_IF_CONFIG_SMALL("framecrc testing format"), +- NULL, +- "", +- 0, +- CODEC_ID_PCM_S16LE, +- CODEC_ID_RAWVIDEO, +- NULL, +- framecrc_write_packet, +- NULL, ++ .name = "framecrc", ++ .long_name = NULL_IF_CONFIG_SMALL("framecrc testing format"), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_packet = framecrc_write_packet, ++ .flags = AVFMT_VARIABLE_FPS, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/g723_1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/g723_1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/g723_1.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/g723_1.c 2012-05-14 14:08:54.961352600 +0200 +@@ -0,0 +1,82 @@ ++/* ++ * G.723.1 demuxer ++ * Copyright (c) 2010 Mohamed Naufal Basheer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * G.723.1 demuxer ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++ ++static const uint8_t frame_size[4] = {24, 20, 4, 1}; ++ ++static int g723_1_init(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVStream *st; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = CODEC_ID_G723_1; ++ st->codec->channels = 1; ++ st->codec->sample_rate = 8000; ++ ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ ++ return 0; ++} ++ ++static int g723_1_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ int size, byte, ret; ++ ++ pkt->pos = avio_tell(s->pb); ++ byte = avio_r8(s->pb); ++ size = frame_size[byte & 3]; ++ ++ ret = av_new_packet(pkt, size); ++ if (ret < 0) ++ return ret; ++ ++ pkt->data[0] = byte; ++ pkt->duration = 240; ++ pkt->stream_index = 0; ++ ++ ret = avio_read(s->pb, pkt->data + 1, size - 1); ++ if (ret < size - 1) { ++ av_free_packet(pkt); ++ return ret < 0 ? ret : AVERROR_EOF; ++ } ++ ++ return pkt->size; ++} ++ ++AVInputFormat ff_g723_1_demuxer = { ++ .name = "g723_1", ++ .long_name = NULL_IF_CONFIG_SMALL("G.723.1 format"), ++ .read_header = g723_1_init, ++ .read_packet = g723_1_read_packet, ++ .extensions = "tco,rco", ++ .flags = AVFMT_GENERIC_INDEX ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/g729dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/g729dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/g729dec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/g729dec.c 2012-05-14 14:08:54.961352600 +0200 +@@ -0,0 +1,103 @@ ++/* ++ * G.729 raw format demuxer ++ * Copyright (c) 2011 Vladimir Voroshilov ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ ++typedef struct G729DemuxerContext { ++ AVClass *class; ++ int bit_rate; ++} G729DemuxerContext; ++ ++static int g729_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVStream* st; ++ G729DemuxerContext *s1 = s->priv_data; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = CODEC_ID_G729; ++ st->codec->sample_rate = 8000; ++ st->codec->channels = 1; ++ ++ if (s1 && s1->bit_rate) { ++ s->bit_rate = s1->bit_rate; ++ } ++ ++ if (s->bit_rate == 0) { ++ av_log(s, AV_LOG_DEBUG, "No bitrate specified. Assuming 8000 b/s\n"); ++ s->bit_rate = 8000; ++ } ++ ++ if (s->bit_rate == 6400) { ++ st->codec->block_align = 8; ++ } else if (s->bit_rate == 8000) { ++ st->codec->block_align = 10; ++ } else { ++ av_log(s, AV_LOG_ERROR, "Only 8000 b/s and 6400 b/s bitrates are supported. Provided: %d b/s\n", s->bit_rate); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avpriv_set_pts_info(st, st->codec->block_align << 3, 1, st->codec->sample_rate); ++ return 0; ++} ++static int g729_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ int ret; ++ ++ ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); ++ ++ pkt->stream_index = 0; ++ if (ret < 0) ++ return ret; ++ ++ pkt->dts = pkt->pts = pkt->pos / s->streams[0]->codec->block_align; ++ ++ return ret; ++} ++ ++static const AVOption g729_options[] = { ++ { "bit_rate", "", offsetof(G729DemuxerContext, bit_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass g729_demuxer_class = { ++ .class_name = "g729 demuxer", ++ .item_name = av_default_item_name, ++ .option = g729_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_g729_demuxer = { ++ .name = "g729", ++ .long_name = NULL_IF_CONFIG_SMALL("G.729 raw format demuxer"), ++ .priv_data_size = sizeof(G729DemuxerContext), ++ .read_header = g729_read_header, ++ .read_packet = g729_read_packet, ++ .flags = AVFMT_GENERIC_INDEX, ++ .extensions = "g729", ++ .priv_class = &g729_demuxer_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gif.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gif.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gif.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gif.c 2012-05-14 14:08:54.963352642 +0200 +@@ -40,6 +40,8 @@ + */ + + #include "avformat.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + + /* The GIF format uses reversed order for bitstreams... */ + /* at least they don't use PDP_ENDIAN :) */ +@@ -107,33 +109,33 @@ + }; + + /* GIF header */ +-static int gif_image_write_header(ByteIOContext *pb, ++static int gif_image_write_header(AVIOContext *pb, + int width, int height, int loop_count, + uint32_t *palette) + { + int i; + unsigned int v; + +- put_tag(pb, "GIF"); +- put_tag(pb, "89a"); +- put_le16(pb, width); +- put_le16(pb, height); +- +- put_byte(pb, 0xf7); /* flags: global clut, 256 entries */ +- put_byte(pb, 0x1f); /* background color index */ +- put_byte(pb, 0); /* aspect ratio */ ++ avio_write(pb, "GIF", 3); ++ avio_write(pb, "89a", 3); ++ avio_wl16(pb, width); ++ avio_wl16(pb, height); ++ ++ avio_w8(pb, 0xf7); /* flags: global clut, 256 entries */ ++ avio_w8(pb, 0x1f); /* background color index */ ++ avio_w8(pb, 0); /* aspect ratio */ + + /* the global palette */ + if (!palette) { +- put_buffer(pb, (const unsigned char *)gif_clut, 216*3); ++ avio_write(pb, (const unsigned char *)gif_clut, 216*3); + for(i=0;i<((256-216)*3);i++) +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } else { + for(i=0;i<256;i++) { + v = palette[i]; +- put_byte(pb, (v >> 16) & 0xff); +- put_byte(pb, (v >> 8) & 0xff); +- put_byte(pb, (v) & 0xff); ++ avio_w8(pb, (v >> 16) & 0xff); ++ avio_w8(pb, (v >> 8) & 0xff); ++ avio_w8(pb, (v) & 0xff); + } + } + +@@ -159,14 +161,14 @@ + /* application extension header */ + #ifdef GIF_ADD_APP_HEADER + if (loop_count >= 0 && loop_count <= 65535) { +- put_byte(pb, 0x21); +- put_byte(pb, 0xff); +- put_byte(pb, 0x0b); +- put_tag(pb, "NETSCAPE2.0"); // bytes 4 to 14 +- put_byte(pb, 0x03); // byte 15 +- put_byte(pb, 0x01); // byte 16 +- put_le16(pb, (uint16_t)loop_count); +- put_byte(pb, 0x00); // byte 19 ++ avio_w8(pb, 0x21); ++ avio_w8(pb, 0xff); ++ avio_w8(pb, 0x0b); ++ avio_write(pb, "NETSCAPE2.0", sizeof("NETSCAPE2.0") - 1); // bytes 4 to 14 ++ avio_w8(pb, 0x03); // byte 15 ++ avio_w8(pb, 0x01); // byte 16 ++ avio_wl16(pb, (uint16_t)loop_count); ++ avio_w8(pb, 0x00); // byte 19 + } + #endif + return 0; +@@ -179,7 +181,7 @@ + } + + +-static int gif_image_write_image(ByteIOContext *pb, ++static int gif_image_write_image(AVIOContext *pb, + int x1, int y1, int width, int height, + const uint8_t *buf, int linesize, int pix_fmt) + { +@@ -189,15 +191,15 @@ + const uint8_t *ptr; + /* image block */ + +- put_byte(pb, 0x2c); +- put_le16(pb, x1); +- put_le16(pb, y1); +- put_le16(pb, width); +- put_le16(pb, height); +- put_byte(pb, 0x00); /* flags */ ++ avio_w8(pb, 0x2c); ++ avio_wl16(pb, x1); ++ avio_wl16(pb, y1); ++ avio_wl16(pb, width); ++ avio_wl16(pb, height); ++ avio_w8(pb, 0x00); /* flags */ + /* no local clut */ + +- put_byte(pb, 0x08); ++ avio_w8(pb, 0x08); + + left= width * height; + +@@ -233,28 +235,30 @@ + flush_put_bits(&p); + } + if(put_bits_ptr(&p) - p.buf > 0) { +- put_byte(pb, put_bits_ptr(&p) - p.buf); /* byte count of the packet */ +- put_buffer(pb, p.buf, put_bits_ptr(&p) - p.buf); /* the actual buffer */ ++ avio_w8(pb, put_bits_ptr(&p) - p.buf); /* byte count of the packet */ ++ avio_write(pb, p.buf, put_bits_ptr(&p) - p.buf); /* the actual buffer */ + p.buf_ptr = p.buf; /* dequeue the bytes off the bitstream */ + } + left-=GIF_CHUNKS; + } +- put_byte(pb, 0x00); /* end of image block */ ++ avio_w8(pb, 0x00); /* end of image block */ + + return 0; + } + + typedef struct { ++ AVClass *class; /** Class for private options. */ + int64_t time, file_time; + uint8_t buffer[100]; /* data chunks */ ++ int loop; + } GIFContext; + + static int gif_write_header(AVFormatContext *s) + { + GIFContext *gif = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc, *video_enc; +- int i, width, height, loop_count /*, rate*/; ++ int i, width, height /*, rate*/; + + /* XXX: do we reject audio streams or just ignore them ? + if(s->nb_streams > 1) +@@ -276,7 +280,6 @@ + } else { + width = video_enc->width; + height = video_enc->height; +- loop_count = s->loop_output; + // rate = video_enc->time_base.den; + } + +@@ -285,44 +288,45 @@ + return AVERROR(EIO); + } + +- gif_image_write_header(pb, width, height, loop_count, NULL); ++#if FF_API_LOOP_OUTPUT ++ if (s->loop_output) ++ gif->loop = s->loop_output; ++#endif ++ ++ gif_image_write_header(pb, width, height, gif->loop, NULL); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + + static int gif_write_video(AVFormatContext *s, + AVCodecContext *enc, const uint8_t *buf, int size) + { +- ByteIOContext *pb = s->pb; +- GIFContext *gif = s->priv_data; ++ AVIOContext *pb = s->pb; + int jiffies; +- int64_t delay; + + /* graphic control extension block */ +- put_byte(pb, 0x21); +- put_byte(pb, 0xf9); +- put_byte(pb, 0x04); /* block size */ +- put_byte(pb, 0x04); /* flags */ ++ avio_w8(pb, 0x21); ++ avio_w8(pb, 0xf9); ++ avio_w8(pb, 0x04); /* block size */ ++ avio_w8(pb, 0x04); /* flags */ + + /* 1 jiffy is 1/70 s */ + /* the delay_time field indicates the number of jiffies - 1 */ +- delay = gif->file_time - gif->time; +- + /* XXX: should use delay, in order to be more accurate */ + /* instead of using the same rounded value each time */ + /* XXX: don't even remember if I really use it for now */ + jiffies = (70*enc->time_base.num/enc->time_base.den) - 1; + +- put_le16(pb, jiffies); ++ avio_wl16(pb, jiffies); + +- put_byte(pb, 0x1f); /* transparent color index */ +- put_byte(pb, 0x00); ++ avio_w8(pb, 0x1f); /* transparent color index */ ++ avio_w8(pb, 0x00); + + gif_image_write_image(pb, 0, 0, enc->width, enc->height, + buf, enc->width * 3, PIX_FMT_RGB24); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + +@@ -337,22 +341,37 @@ + + static int gif_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- put_byte(pb, 0x3b); +- put_flush_packet(s->pb); ++ avio_w8(pb, 0x3b); ++ avio_flush(s->pb); + return 0; + } + ++#define OFFSET(x) offsetof(GIFContext, x) ++#define ENC AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "loop", "Number of times to loop the output.", OFFSET(loop), AV_OPT_TYPE_INT, {0}, 0, 65535, ENC }, ++ { NULL }, ++}; ++ ++static const AVClass gif_muxer_class = { ++ .class_name = "GIF muxer", ++ .item_name = av_default_item_name, ++ .version = LIBAVUTIL_VERSION_INT, ++ .option = options, ++}; ++ + AVOutputFormat ff_gif_muxer = { +- "gif", +- NULL_IF_CONFIG_SMALL("GIF Animation"), +- "image/gif", +- "gif", +- sizeof(GIFContext), +- CODEC_ID_NONE, +- CODEC_ID_RAWVIDEO, +- gif_write_header, +- gif_write_packet, +- gif_write_trailer, ++ .name = "gif", ++ .long_name = NULL_IF_CONFIG_SMALL("GIF Animation"), ++ .mime_type = "image/gif", ++ .extensions = "gif", ++ .priv_data_size = sizeof(GIFContext), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = gif_write_header, ++ .write_packet = gif_write_packet, ++ .write_trailer = gif_write_trailer, ++ .priv_class = &gif_muxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gopher.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gopher.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gopher.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gopher.c 2012-05-14 14:08:54.963352642 +0200 +@@ -26,6 +26,7 @@ + #include "avformat.h" + #include "internal.h" + #include "network.h" ++#include "url.h" + + typedef struct { + URLContext *hd; +@@ -34,7 +35,7 @@ + static int gopher_write(URLContext *h, const uint8_t *buf, int size) + { + GopherContext *s = h->priv_data; +- return url_write(s->hd, buf, size); ++ return ffurl_write(s->hd, buf, size); + } + + static int gopher_connect(URLContext *h, const char *path) +@@ -49,7 +50,7 @@ + if (!path) return AVERROR(EINVAL); + break; + default: +- av_log(NULL, AV_LOG_WARNING, ++ av_log(h, AV_LOG_WARNING, + "Gopher protocol type '%c' not supported yet!\n", + *path); + return AVERROR(EINVAL); +@@ -68,27 +69,20 @@ + { + GopherContext *s = h->priv_data; + if (s->hd) { +- url_close(s->hd); ++ ffurl_close(s->hd); + s->hd = NULL; + } +- av_freep(&h->priv_data); + return 0; + } + + static int gopher_open(URLContext *h, const char *uri, int flags) + { +- GopherContext *s; ++ GopherContext *s = h->priv_data; + char hostname[1024], auth[1024], path[1024], buf[1024]; + int port, err; + + h->is_streamed = 1; + +- s = av_malloc(sizeof(GopherContext)); +- if (!s) { +- return AVERROR(ENOMEM); +- } +- h->priv_data = s; +- + /* needed in any case to build the host string */ + av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, + path, sizeof(path), uri); +@@ -99,7 +93,8 @@ + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); + + s->hd = NULL; +- err = url_open(&s->hd, buf, URL_RDWR); ++ err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE, ++ &h->interrupt_callback, NULL); + if (err < 0) + goto fail; + +@@ -114,16 +109,17 @@ + static int gopher_read(URLContext *h, uint8_t *buf, int size) + { + GopherContext *s = h->priv_data; +- int len = url_read(s->hd, buf, size); ++ int len = ffurl_read(s->hd, buf, size); + return len; + } + + + URLProtocol ff_gopher_protocol = { +- "gopher", +- gopher_open, +- gopher_read, +- gopher_write, +- NULL, /*seek*/ +- gopher_close, ++ .name = "gopher", ++ .url_open = gopher_open, ++ .url_read = gopher_read, ++ .url_write = gopher_write, ++ .url_close = gopher_close, ++ .priv_data_size = sizeof(GopherContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gsmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gsmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gsmdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gsmdec.c 2012-05-14 14:08:54.964352662 +0200 +@@ -0,0 +1,99 @@ ++/* ++ * RAW GSM demuxer ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define GSM_BLOCK_SIZE 33 ++#define GSM_BLOCK_SAMPLES 160 ++#define GSM_SAMPLE_RATE 8000 ++ ++typedef struct { ++ AVClass *class; ++ int sample_rate; ++} GSMDemuxerContext; ++ ++static int gsm_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ int ret, size; ++ ++ size = GSM_BLOCK_SIZE; ++ ++ pkt->pos = avio_tell(s->pb); ++ pkt->stream_index = 0; ++ ++ ret = av_get_packet(s->pb, pkt, size); ++ if (ret < GSM_BLOCK_SIZE) { ++ av_free_packet(pkt); ++ return ret < 0 ? ret : AVERROR(EIO); ++ } ++ pkt->size = ret; ++ pkt->duration = 1; ++ pkt->pts = pkt->pos / GSM_BLOCK_SIZE; ++ ++ return 0; ++} ++ ++static int gsm_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ GSMDemuxerContext *c = s->priv_data; ++ AVStream *st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = s->iformat->value; ++ st->codec->channels = 1; ++ st->codec->sample_rate = c->sample_rate; ++ st->codec->bit_rate = GSM_BLOCK_SIZE * 8 * c->sample_rate / GSM_BLOCK_SAMPLES; ++ ++ avpriv_set_pts_info(st, 64, GSM_BLOCK_SAMPLES, GSM_SAMPLE_RATE); ++ ++ return 0; ++} ++ ++static const AVOption options[] = { ++ { "sample_rate", "", offsetof(GSMDemuxerContext, sample_rate), ++ AV_OPT_TYPE_INT, {.dbl = GSM_SAMPLE_RATE}, 1, INT_MAX / GSM_BLOCK_SIZE, ++ AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass class = { ++ .class_name = "gsm demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_gsm_demuxer = { ++ .name = "gsm", ++ .long_name = NULL_IF_CONFIG_SMALL("raw GSM"), ++ .priv_data_size = sizeof(GSMDemuxerContext), ++ .read_header = gsm_read_header, ++ .read_packet = gsm_read_packet, ++ .flags = AVFMT_GENERIC_INDEX, ++ .extensions = "gsm", ++ .value = CODEC_ID_GSM, ++ .priv_class = &class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gxf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gxf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gxf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gxf.c 2012-05-14 14:08:54.966352702 +0200 +@@ -29,36 +29,58 @@ + int64_t last_field; + AVRational frames_per_second; + int32_t fields_per_frame; ++ int64_t track_aux_data; + }; + + /** +- * \brief parses a packet header, extracting type and length +- * \param pb ByteIOContext to read header from +- * \param type detected packet type is stored here +- * \param length detected packet length, excluding header is stored here +- * \return 0 if header not found or contains invalid data, 1 otherwise ++ * @brief parse gxf timecode and add it to metadata + */ +-static int parse_packet_header(ByteIOContext *pb, GXFPktType *type, int *length) { +- if (get_be32(pb)) ++static int add_timecode_metadata(AVDictionary **pm, const char *key, uint32_t timecode, int fields_per_frame) ++{ ++ char tmp[128]; ++ int field = timecode & 0xff; ++ int frame = fields_per_frame ? field / fields_per_frame : field; ++ int second = (timecode >> 8) & 0xff; ++ int minute = (timecode >> 16) & 0xff; ++ int hour = (timecode >> 24) & 0x1f; ++ int drop = (timecode >> 29) & 1; ++ // bit 30: color_frame, unused ++ // ignore invalid time code ++ if (timecode >> 31) ++ return 0; ++ snprintf(tmp, sizeof(tmp), "%02d:%02d:%02d%c%02d", ++ hour, minute, second, drop ? ';' : ':', frame); ++ return av_dict_set(pm, key, tmp, 0); ++} ++ ++/** ++ * @brief parses a packet header, extracting type and length ++ * @param pb AVIOContext to read header from ++ * @param type detected packet type is stored here ++ * @param length detected packet length, excluding header is stored here ++ * @return 0 if header not found or contains invalid data, 1 otherwise ++ */ ++static int parse_packet_header(AVIOContext *pb, GXFPktType *type, int *length) { ++ if (avio_rb32(pb)) + return 0; +- if (get_byte(pb) != 1) ++ if (avio_r8(pb) != 1) + return 0; +- *type = get_byte(pb); +- *length = get_be32(pb); ++ *type = avio_r8(pb); ++ *length = avio_rb32(pb); + if ((*length >> 24) || *length < 16) + return 0; + *length -= 16; +- if (get_be32(pb)) ++ if (avio_rb32(pb)) + return 0; +- if (get_byte(pb) != 0xe1) ++ if (avio_r8(pb) != 0xe1) + return 0; +- if (get_byte(pb) != 0xe2) ++ if (avio_r8(pb) != 0xe2) + return 0; + return 1; + } + + /** +- * \brief check if file starts with a PKT_MAP header ++ * @brief check if file starts with a PKT_MAP header + */ + static int gxf_probe(AVProbeData *p) { + static const uint8_t startcode[] = {0, 0, 0, 0, 1, 0xbc}; // start with map packet +@@ -70,10 +92,10 @@ + } + + /** +- * \brief gets the stream index for the track with the specified id, creates new ++ * @brief gets the stream index for the track with the specified id, creates new + * stream if not found +- * \param id id of stream to find / add +- * \param format stream format identifier ++ * @param id id of stream to find / add ++ * @param format stream format identifier + */ + static int get_sindex(AVFormatContext *s, int id, int format) { + int i; +@@ -81,9 +103,10 @@ + i = ff_find_stream_index(s, id); + if (i >= 0) + return i; +- st = av_new_stream(s, id); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); ++ st->id = id; + switch (format) { + case 3: + case 4: +@@ -153,46 +176,46 @@ + } + + /** +- * \brief filters out interesting tags from material information. +- * \param len length of tag section, will be adjusted to contain remaining bytes +- * \param si struct to store collected information into ++ * @brief filters out interesting tags from material information. ++ * @param len length of tag section, will be adjusted to contain remaining bytes ++ * @param si struct to store collected information into + */ +-static void gxf_material_tags(ByteIOContext *pb, int *len, struct gxf_stream_info *si) { ++static void gxf_material_tags(AVIOContext *pb, int *len, struct gxf_stream_info *si) { + si->first_field = AV_NOPTS_VALUE; + si->last_field = AV_NOPTS_VALUE; + while (*len >= 2) { +- GXFMatTag tag = get_byte(pb); +- int tlen = get_byte(pb); ++ GXFMatTag tag = avio_r8(pb); ++ int tlen = avio_r8(pb); + *len -= 2; + if (tlen > *len) + return; + *len -= tlen; + if (tlen == 4) { +- uint32_t value = get_be32(pb); ++ uint32_t value = avio_rb32(pb); + if (tag == MAT_FIRST_FIELD) + si->first_field = value; + else if (tag == MAT_LAST_FIELD) + si->last_field = value; + } else +- url_fskip(pb, tlen); ++ avio_skip(pb, tlen); + } + } + + /** +- * \brief convert fps tag value to AVRational fps +- * \param fps fps value from tag +- * \return fps as AVRational, or 0 / 0 if unknown ++ * @brief convert fps tag value to AVRational fps ++ * @param fps fps value from tag ++ * @return fps as AVRational, or 0 / 0 if unknown + */ + static AVRational fps_tag2avr(int32_t fps) { +- extern const AVRational ff_frame_rate_tab[]; ++ extern const AVRational avpriv_frame_rate_tab[]; + if (fps < 1 || fps > 9) fps = 9; +- return ff_frame_rate_tab[9 - fps]; // values have opposite order ++ return avpriv_frame_rate_tab[9 - fps]; // values have opposite order + } + + /** +- * \brief convert UMF attributes flags to AVRational fps +- * \param flags UMF flags to convert +- * \return fps as AVRational, or 0 / 0 if unknown ++ * @brief convert UMF attributes flags to AVRational fps ++ * @param flags UMF flags to convert ++ * @return fps as AVRational, or 0 / 0 if unknown + */ + static AVRational fps_umf2avr(uint32_t flags) { + static const AVRational map[] = {{50, 1}, {60000, 1001}, {24, 1}, +@@ -202,43 +225,46 @@ + } + + /** +- * \brief filters out interesting tags from track information. +- * \param len length of tag section, will be adjusted to contain remaining bytes +- * \param si struct to store collected information into ++ * @brief filters out interesting tags from track information. ++ * @param len length of tag section, will be adjusted to contain remaining bytes ++ * @param si struct to store collected information into + */ +-static void gxf_track_tags(ByteIOContext *pb, int *len, struct gxf_stream_info *si) { ++static void gxf_track_tags(AVIOContext *pb, int *len, struct gxf_stream_info *si) { + si->frames_per_second = (AVRational){0, 0}; + si->fields_per_frame = 0; ++ si->track_aux_data = 0x80000000; + while (*len >= 2) { +- GXFTrackTag tag = get_byte(pb); +- int tlen = get_byte(pb); ++ GXFTrackTag tag = avio_r8(pb); ++ int tlen = avio_r8(pb); + *len -= 2; + if (tlen > *len) + return; + *len -= tlen; + if (tlen == 4) { +- uint32_t value = get_be32(pb); ++ uint32_t value = avio_rb32(pb); + if (tag == TRACK_FPS) + si->frames_per_second = fps_tag2avr(value); + else if (tag == TRACK_FPF && (value == 1 || value == 2)) + si->fields_per_frame = value; +- } else +- url_fskip(pb, tlen); ++ } else if (tlen == 8 && tag == TRACK_AUX) ++ si->track_aux_data = avio_rl64(pb); ++ else ++ avio_skip(pb, tlen); + } + } + + /** +- * \brief read index from FLT packet into stream 0 av_index ++ * @brief read index from FLT packet into stream 0 av_index + */ + static void gxf_read_index(AVFormatContext *s, int pkt_len) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; +- uint32_t fields_per_map = get_le32(pb); +- uint32_t map_cnt = get_le32(pb); ++ uint32_t fields_per_map = avio_rl32(pb); ++ uint32_t map_cnt = avio_rl32(pb); + int i; + pkt_len -= 8; + if (s->flags & AVFMT_FLAG_IGNIDX) { +- url_fskip(pb, pkt_len); ++ avio_skip(pb, pkt_len); + return; + } + if (map_cnt > 1000) { +@@ -247,45 +273,45 @@ + } + if (pkt_len < 4 * map_cnt) { + av_log(s, AV_LOG_ERROR, "invalid index length\n"); +- url_fskip(pb, pkt_len); ++ avio_skip(pb, pkt_len); + return; + } + pkt_len -= 4 * map_cnt; + av_add_index_entry(st, 0, 0, 0, 0, 0); + for (i = 0; i < map_cnt; i++) +- av_add_index_entry(st, (uint64_t)get_le32(pb) * 1024, ++ av_add_index_entry(st, (uint64_t)avio_rl32(pb) * 1024, + i * (uint64_t)fields_per_map + 1, 0, 0, 0); +- url_fskip(pb, pkt_len); ++ avio_skip(pb, pkt_len); + } + + static int gxf_header(AVFormatContext *s, AVFormatParameters *ap) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + GXFPktType pkt_type; + int map_len; + int len; + AVRational main_timebase = {0, 0}; +- struct gxf_stream_info si; ++ struct gxf_stream_info *si = s->priv_data; + int i; + if (!parse_packet_header(pb, &pkt_type, &map_len) || pkt_type != PKT_MAP) { + av_log(s, AV_LOG_ERROR, "map packet not found\n"); + return 0; + } + map_len -= 2; +- if (get_byte(pb) != 0x0e0 || get_byte(pb) != 0xff) { ++ if (avio_r8(pb) != 0x0e0 || avio_r8(pb) != 0xff) { + av_log(s, AV_LOG_ERROR, "unknown version or invalid map preamble\n"); + return 0; + } + map_len -= 2; +- len = get_be16(pb); // length of material data section ++ len = avio_rb16(pb); // length of material data section + if (len > map_len) { + av_log(s, AV_LOG_ERROR, "material data longer than map data\n"); + return 0; + } + map_len -= len; +- gxf_material_tags(pb, &len, &si); +- url_fskip(pb, len); ++ gxf_material_tags(pb, &len, si); ++ avio_skip(pb, len); + map_len -= 2; +- len = get_be16(pb); // length of track description ++ len = avio_rb16(pb); // length of track description + if (len > map_len) { + av_log(s, AV_LOG_ERROR, "track description longer than map data\n"); + return 0; +@@ -296,12 +322,10 @@ + AVStream *st; + int idx; + len -= 4; +- track_type = get_byte(pb); +- track_id = get_byte(pb); +- track_len = get_be16(pb); ++ track_type = avio_r8(pb); ++ track_id = avio_r8(pb); ++ track_len = avio_rb16(pb); + len -= track_len; +- gxf_track_tags(pb, &track_len, &si); +- url_fskip(pb, track_len); + if (!(track_type & 0x80)) { + av_log(s, AV_LOG_ERROR, "invalid track type %x\n", track_type); + continue; +@@ -312,21 +336,31 @@ + continue; + } + track_id &= 0x3f; ++ gxf_track_tags(pb, &track_len, si); ++ // check for timecode tracks ++ if (track_type == 7 || track_type == 8 || track_type == 24) { ++ add_timecode_metadata(&s->metadata, "timecode", ++ si->track_aux_data & 0xffffffff, ++ si->fields_per_frame); ++ ++ } ++ avio_skip(pb, track_len); ++ + idx = get_sindex(s, track_id, track_type); + if (idx < 0) continue; + st = s->streams[idx]; + if (!main_timebase.num || !main_timebase.den) { +- main_timebase.num = si.frames_per_second.den; +- main_timebase.den = si.frames_per_second.num * 2; ++ main_timebase.num = si->frames_per_second.den; ++ main_timebase.den = si->frames_per_second.num * 2; + } +- st->start_time = si.first_field; +- if (si.first_field != AV_NOPTS_VALUE && si.last_field != AV_NOPTS_VALUE) +- st->duration = si.last_field - si.first_field; ++ st->start_time = si->first_field; ++ if (si->first_field != AV_NOPTS_VALUE && si->last_field != AV_NOPTS_VALUE) ++ st->duration = si->last_field - si->first_field; + } + if (len < 0) + av_log(s, AV_LOG_ERROR, "invalid track description length specified\n"); + if (map_len) +- url_fskip(pb, map_len); ++ avio_skip(pb, map_len); + if (!parse_packet_header(pb, &pkt_type, &len)) { + av_log(s, AV_LOG_ERROR, "sync lost in header\n"); + return -1; +@@ -342,26 +376,37 @@ + if (len >= 0x39) { + AVRational fps; + len -= 0x39; +- url_fskip(pb, 5); // preamble +- url_fskip(pb, 0x30); // payload description +- fps = fps_umf2avr(get_le32(pb)); ++ avio_skip(pb, 5); // preamble ++ avio_skip(pb, 0x30); // payload description ++ fps = fps_umf2avr(avio_rl32(pb)); + if (!main_timebase.num || !main_timebase.den) { ++ av_log(s, AV_LOG_WARNING, "No FPS track tag, using UMF fps tag." ++ " This might give wrong results.\n"); + // this may not always be correct, but simply the best we can get + main_timebase.num = fps.den; + main_timebase.den = fps.num * 2; + } ++ ++ if (len >= 0x18) { ++ len -= 0x18; ++ avio_skip(pb, 0x10); ++ add_timecode_metadata(&s->metadata, "timecode_at_mark_in", ++ avio_rl32(pb), si->fields_per_frame); ++ add_timecode_metadata(&s->metadata, "timecode_at_mark_out", ++ avio_rl32(pb), si->fields_per_frame); ++ } + } else + av_log(s, AV_LOG_INFO, "UMF packet too short\n"); + } else + av_log(s, AV_LOG_INFO, "UMF packet missing\n"); +- url_fskip(pb, len); ++ avio_skip(pb, len); + // set a fallback value, 60000/1001 is specified for audio-only files + // so use that regardless of why we do not know the video frame rate. + if (!main_timebase.num || !main_timebase.den) + main_timebase = (AVRational){1001, 60000}; + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; +- av_set_pts_info(st, 32, main_timebase.num, main_timebase.den); ++ avpriv_set_pts_info(st, 32, main_timebase.num, main_timebase.den); + } + return 0; + } +@@ -370,15 +415,15 @@ + { \ + if (!max_interval-- || url_feof(pb)) \ + goto out; \ +- tmp = tmp << 8 | get_byte(pb); \ ++ tmp = tmp << 8 | avio_r8(pb); \ + } + + /** +- * \brief resync the stream on the next media packet with specified properties +- * \param max_interval how many bytes to search for matching packet at most +- * \param track track id the media packet must belong to, -1 for any +- * \param timestamp minimum timestamp (== field number) the packet must have, -1 for any +- * \return timestamp of packet found ++ * @brief resync the stream on the next media packet with specified properties ++ * @param max_interval how many bytes to search for matching packet at most ++ * @param track track id the media packet must belong to, -1 for any ++ * @param timestamp minimum timestamp (== field number) the packet must have, -1 for any ++ * @return timestamp of packet found + */ + static int64_t gxf_resync_media(AVFormatContext *s, uint64_t max_interval, int track, int timestamp) { + uint32_t tmp; +@@ -387,42 +432,44 @@ + int cur_track; + int64_t cur_timestamp = AV_NOPTS_VALUE; + int len; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + GXFPktType type; +- tmp = get_be32(pb); ++ tmp = avio_rb32(pb); + start: + while (tmp) + READ_ONE(); + READ_ONE(); + if (tmp != 1) + goto start; +- last_pos = url_ftell(pb); +- if (url_fseek(pb, -5, SEEK_CUR) < 0) ++ last_pos = avio_tell(pb); ++ if (avio_seek(pb, -5, SEEK_CUR) < 0) + goto out; + if (!parse_packet_header(pb, &type, &len) || type != PKT_MEDIA) { +- if (url_fseek(pb, last_pos, SEEK_SET) < 0) ++ if (avio_seek(pb, last_pos, SEEK_SET) < 0) + goto out; + goto start; + } +- get_byte(pb); +- cur_track = get_byte(pb); +- cur_timestamp = get_be32(pb); +- last_found_pos = url_ftell(pb) - 16 - 6; ++ avio_r8(pb); ++ cur_track = avio_r8(pb); ++ cur_timestamp = avio_rb32(pb); ++ last_found_pos = avio_tell(pb) - 16 - 6; + if ((track >= 0 && track != cur_track) || (timestamp >= 0 && timestamp > cur_timestamp)) { +- if (url_fseek(pb, last_pos, SEEK_SET) >= 0) ++ if (avio_seek(pb, last_pos, SEEK_SET) >= 0) + goto start; + } + out: + if (last_found_pos) +- url_fseek(pb, last_found_pos, SEEK_SET); ++ avio_seek(pb, last_found_pos, SEEK_SET); + return cur_timestamp; + } + + static int gxf_packet(AVFormatContext *s, AVPacket *pkt) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + GXFPktType pkt_type; + int pkt_len; +- while (!url_feof(pb)) { ++ struct gxf_stream_info *si = s->priv_data; ++ ++ while (!pb->eof_reached) { + AVStream *st; + int track_type, track_id, ret; + int field_nr, field_info, skip = 0; +@@ -437,7 +484,7 @@ + continue; + } + if (pkt_type != PKT_MEDIA) { +- url_fskip(pb, pkt_len); ++ avio_skip(pb, pkt_len); + continue; + } + if (pkt_len < 16) { +@@ -445,24 +492,24 @@ + continue; + } + pkt_len -= 16; +- track_type = get_byte(pb); +- track_id = get_byte(pb); ++ track_type = avio_r8(pb); ++ track_id = avio_r8(pb); + stream_index = get_sindex(s, track_id, track_type); + if (stream_index < 0) + return stream_index; + st = s->streams[stream_index]; +- field_nr = get_be32(pb); +- field_info = get_be32(pb); +- get_be32(pb); // "timeline" field number +- get_byte(pb); // flags +- get_byte(pb); // reserved ++ field_nr = avio_rb32(pb); ++ field_info = avio_rb32(pb); ++ avio_rb32(pb); // "timeline" field number ++ avio_r8(pb); // flags ++ avio_r8(pb); // reserved + if (st->codec->codec_id == CODEC_ID_PCM_S24LE || + st->codec->codec_id == CODEC_ID_PCM_S16LE) { + int first = field_info >> 16; + int last = field_info & 0xffff; // last is exclusive + int bps = av_get_bits_per_sample(st->codec->codec_id)>>3; + if (first <= last && last*bps <= pkt_len) { +- url_fskip(pb, first*bps); ++ avio_skip(pb, first*bps); + skip = pkt_len - last*bps; + pkt_len = (last-first)*bps; + } else +@@ -470,9 +517,14 @@ + } + ret = av_get_packet(pb, pkt, pkt_len); + if (skip) +- url_fskip(pb, skip); ++ avio_skip(pb, skip); + pkt->stream_index = stream_index; + pkt->dts = field_nr; ++ ++ //set duration manually for DV or else lavf misdetects the frame rate ++ if (st->codec->codec_id == CODEC_ID_DVVIDEO) ++ pkt->duration = si->fields_per_frame; ++ + return ret; + } + return AVERROR(EIO); +@@ -490,39 +542,38 @@ + idx = av_index_search_timestamp(st, timestamp - start_time, + AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); + if (idx < 0) +- return -1; ++ return AVERROR(ENOSYS); + pos = st->index_entries[idx].pos; + if (idx < st->nb_index_entries - 2) + maxlen = st->index_entries[idx + 2].pos - pos; + maxlen = FFMAX(maxlen, 200 * 1024); +- res = url_fseek(s->pb, pos, SEEK_SET); ++ res = avio_seek(s->pb, pos, SEEK_SET); + if (res < 0) + return res; + found = gxf_resync_media(s, maxlen, -1, timestamp); + if (FFABS(found - timestamp) > 4) +- return -1; ++ return AVERROR(ENOSYS); + return 0; + } + + static int64_t gxf_read_timestamp(AVFormatContext *s, int stream_index, + int64_t *pos, int64_t pos_limit) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t res; +- if (url_fseek(pb, *pos, SEEK_SET) < 0) ++ if (avio_seek(pb, *pos, SEEK_SET) < 0) + return AV_NOPTS_VALUE; + res = gxf_resync_media(s, pos_limit - *pos, -1, -1); +- *pos = url_ftell(pb); ++ *pos = avio_tell(pb); + return res; + } + + AVInputFormat ff_gxf_demuxer = { +- "gxf", +- NULL_IF_CONFIG_SMALL("GXF format"), +- 0, +- gxf_probe, +- gxf_header, +- gxf_packet, +- NULL, +- gxf_seek, +- gxf_read_timestamp, ++ .name = "gxf", ++ .long_name = NULL_IF_CONFIG_SMALL("GXF format"), ++ .priv_data_size = sizeof(struct gxf_stream_info), ++ .read_probe = gxf_probe, ++ .read_header = gxf_header, ++ .read_packet = gxf_packet, ++ .read_seek = gxf_seek, ++ .read_timestamp = gxf_read_timestamp, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gxfenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gxfenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/gxfenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/gxfenc.c 2012-05-14 14:08:54.969352762 +0200 +@@ -19,13 +19,31 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/intfloat.h" ++#include "libavutil/opt.h" ++#include "libavutil/mathematics.h" ++#include "libavcodec/timecode.h" + #include "avformat.h" ++#include "internal.h" + #include "gxf.h" + #include "riff.h" + #include "audiointerleave.h" + + #define GXF_AUDIO_PACKET_SIZE 65536 + ++#define GXF_TIMECODE(c, d, h, m, s, f) \ ++ ((c) << 30 | (d) << 29 | (h) << 24 | (m) << 16 | (s) << 8 | (f)) ++ ++typedef struct GXFTimecode{ ++ int hh; ++ int mm; ++ int ss; ++ int ff; ++ int color; ++ int drop; ++ char *str; ++} GXFTimecode; ++ + typedef struct GXFStreamContext { + AudioInterleaveContext aic; + uint32_t track_type; +@@ -46,6 +64,7 @@ + } GXFStreamContext; + + typedef struct GXFContext { ++ AVClass *av_class; + uint32_t nb_fields; + uint16_t audio_tracks; + uint16_t mpeg_tracks; +@@ -64,6 +83,7 @@ + uint64_t *map_offsets; ///< offset of map packets + unsigned map_offsets_nb; + unsigned packet_count; ++ GXFTimecode tc; + } GXFContext; + + static const struct { +@@ -113,53 +133,53 @@ + return -1; + } + +-static void gxf_write_padding(ByteIOContext *pb, int64_t to_pad) ++static void gxf_write_padding(AVIOContext *pb, int64_t to_pad) + { + for (; to_pad > 0; to_pad--) { +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + } + +-static int64_t updatePacketSize(ByteIOContext *pb, int64_t pos) ++static int64_t updatePacketSize(AVIOContext *pb, int64_t pos) + { + int64_t curpos; + int size; + +- size = url_ftell(pb) - pos; ++ size = avio_tell(pb) - pos; + if (size % 4) { + gxf_write_padding(pb, 4 - size % 4); +- size = url_ftell(pb) - pos; ++ size = avio_tell(pb) - pos; + } +- curpos = url_ftell(pb); +- url_fseek(pb, pos + 6, SEEK_SET); +- put_be32(pb, size); +- url_fseek(pb, curpos, SEEK_SET); ++ curpos = avio_tell(pb); ++ avio_seek(pb, pos + 6, SEEK_SET); ++ avio_wb32(pb, size); ++ avio_seek(pb, curpos, SEEK_SET); + return curpos - pos; + } + +-static int64_t updateSize(ByteIOContext *pb, int64_t pos) ++static int64_t updateSize(AVIOContext *pb, int64_t pos) + { + int64_t curpos; + +- curpos = url_ftell(pb); +- url_fseek(pb, pos, SEEK_SET); +- put_be16(pb, curpos - pos - 2); +- url_fseek(pb, curpos, SEEK_SET); ++ curpos = avio_tell(pb); ++ avio_seek(pb, pos, SEEK_SET); ++ avio_wb16(pb, curpos - pos - 2); ++ avio_seek(pb, curpos, SEEK_SET); + return curpos - pos; + } + +-static void gxf_write_packet_header(ByteIOContext *pb, GXFPktType type) ++static void gxf_write_packet_header(AVIOContext *pb, GXFPktType type) + { +- put_be32(pb, 0); /* packet leader for synchro */ +- put_byte(pb, 1); +- put_byte(pb, type); /* map packet */ +- put_be32(pb, 0); /* size */ +- put_be32(pb, 0); /* reserved */ +- put_byte(pb, 0xE1); /* trailer 1 */ +- put_byte(pb, 0xE2); /* trailer 2 */ ++ avio_wb32(pb, 0); /* packet leader for synchro */ ++ avio_w8(pb, 1); ++ avio_w8(pb, type); /* map packet */ ++ avio_wb32(pb, 0); /* size */ ++ avio_wb32(pb, 0); /* reserved */ ++ avio_w8(pb, 0xE1); /* trailer 1 */ ++ avio_w8(pb, 0xE2); /* trailer 2 */ + } + +-static int gxf_write_mpeg_auxiliary(ByteIOContext *pb, AVStream *st) ++static int gxf_write_mpeg_auxiliary(AVIOContext *pb, AVStream *st) + { + GXFStreamContext *sc = st->priv_data; + char buffer[1024]; +@@ -191,75 +211,77 @@ + (float)st->codec->bit_rate, sc->p_per_gop, sc->b_per_i_or_p, + st->codec->pix_fmt == PIX_FMT_YUV422P ? 2 : 1, sc->first_gop_closed == 1, + starting_line, (st->codec->height + 15) / 16); +- put_byte(pb, TRACK_MPG_AUX); +- put_byte(pb, size + 1); +- put_buffer(pb, (uint8_t *)buffer, size + 1); ++ avio_w8(pb, TRACK_MPG_AUX); ++ avio_w8(pb, size + 1); ++ avio_write(pb, (uint8_t *)buffer, size + 1); + return size + 3; + } + +-static int gxf_write_timecode_auxiliary(ByteIOContext *pb, GXFStreamContext *sc) ++static int gxf_write_timecode_auxiliary(AVIOContext *pb, GXFContext *gxf) + { +- put_byte(pb, 0); /* fields */ +- put_byte(pb, 0); /* seconds */ +- put_byte(pb, 0); /* minutes */ +- put_byte(pb, 0); /* flags + hours */ ++ uint32_t timecode = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop, ++ gxf->tc.hh, gxf->tc.mm, ++ gxf->tc.ss, gxf->tc.ff); ++ ++ avio_wl32(pb, timecode); + /* reserved */ +- put_be32(pb, 0); ++ avio_wl32(pb, 0); + return 8; + } + + static int gxf_write_track_description(AVFormatContext *s, GXFStreamContext *sc, int index) + { +- ByteIOContext *pb = s->pb; ++ GXFContext *gxf = s->priv_data; ++ AVIOContext *pb = s->pb; + int64_t pos; + int mpeg = sc->track_type == 4 || sc->track_type == 9; + + /* track description section */ +- put_byte(pb, sc->media_type + 0x80); +- put_byte(pb, index + 0xC0); ++ avio_w8(pb, sc->media_type + 0x80); ++ avio_w8(pb, index + 0xC0); + +- pos = url_ftell(pb); +- put_be16(pb, 0); /* size */ ++ pos = avio_tell(pb); ++ avio_wb16(pb, 0); /* size */ + + /* media file name */ +- put_byte(pb, TRACK_NAME); +- put_byte(pb, strlen(ES_NAME_PATTERN) + 3); +- put_tag(pb, ES_NAME_PATTERN); +- put_be16(pb, sc->media_info); +- put_byte(pb, 0); ++ avio_w8(pb, TRACK_NAME); ++ avio_w8(pb, strlen(ES_NAME_PATTERN) + 3); ++ avio_write(pb, ES_NAME_PATTERN, sizeof(ES_NAME_PATTERN) - 1); ++ avio_wb16(pb, sc->media_info); ++ avio_w8(pb, 0); + + if (!mpeg) { + /* auxiliary information */ +- put_byte(pb, TRACK_AUX); +- put_byte(pb, 8); ++ avio_w8(pb, TRACK_AUX); ++ avio_w8(pb, 8); + if (sc->track_type == 3) +- gxf_write_timecode_auxiliary(pb, sc); ++ gxf_write_timecode_auxiliary(pb, gxf); + else +- put_le64(pb, 0); ++ avio_wl64(pb, 0); + } + + /* file system version */ +- put_byte(pb, TRACK_VER); +- put_byte(pb, 4); +- put_be32(pb, 0); ++ avio_w8(pb, TRACK_VER); ++ avio_w8(pb, 4); ++ avio_wb32(pb, 0); + + if (mpeg) + gxf_write_mpeg_auxiliary(pb, s->streams[index]); + + /* frame rate */ +- put_byte(pb, TRACK_FPS); +- put_byte(pb, 4); +- put_be32(pb, sc->frame_rate_index); ++ avio_w8(pb, TRACK_FPS); ++ avio_w8(pb, 4); ++ avio_wb32(pb, sc->frame_rate_index); + + /* lines per frame */ +- put_byte(pb, TRACK_LINES); +- put_byte(pb, 4); +- put_be32(pb, sc->lines_index); ++ avio_w8(pb, TRACK_LINES); ++ avio_w8(pb, 4); ++ avio_wb32(pb, sc->lines_index); + + /* fields per frame */ +- put_byte(pb, TRACK_FPF); +- put_byte(pb, 4); +- put_be32(pb, sc->fields); ++ avio_w8(pb, TRACK_FPF); ++ avio_w8(pb, 4); ++ avio_wb32(pb, sc->fields); + + return updateSize(pb, pos); + } +@@ -267,47 +289,50 @@ + static int gxf_write_material_data_section(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; ++ int len; + const char *filename = strrchr(s->filename, '/'); + +- pos = url_ftell(pb); +- put_be16(pb, 0); /* size */ ++ pos = avio_tell(pb); ++ avio_wb16(pb, 0); /* size */ + + /* name */ + if (filename) + filename++; + else + filename = s->filename; +- put_byte(pb, MAT_NAME); +- put_byte(pb, strlen(SERVER_PATH) + strlen(filename) + 1); +- put_tag(pb, SERVER_PATH); +- put_tag(pb, filename); +- put_byte(pb, 0); ++ len = strlen(filename); ++ ++ avio_w8(pb, MAT_NAME); ++ avio_w8(pb, strlen(SERVER_PATH) + len + 1); ++ avio_write(pb, SERVER_PATH, sizeof(SERVER_PATH) - 1); ++ avio_write(pb, filename, len); ++ avio_w8(pb, 0); + + /* first field */ +- put_byte(pb, MAT_FIRST_FIELD); +- put_byte(pb, 4); +- put_be32(pb, 0); ++ avio_w8(pb, MAT_FIRST_FIELD); ++ avio_w8(pb, 4); ++ avio_wb32(pb, 0); + + /* last field */ +- put_byte(pb, MAT_LAST_FIELD); +- put_byte(pb, 4); +- put_be32(pb, gxf->nb_fields); ++ avio_w8(pb, MAT_LAST_FIELD); ++ avio_w8(pb, 4); ++ avio_wb32(pb, gxf->nb_fields); + + /* reserved */ +- put_byte(pb, MAT_MARK_IN); +- put_byte(pb, 4); +- put_be32(pb, 0); +- +- put_byte(pb, MAT_MARK_OUT); +- put_byte(pb, 4); +- put_be32(pb, gxf->nb_fields); ++ avio_w8(pb, MAT_MARK_IN); ++ avio_w8(pb, 4); ++ avio_wb32(pb, 0); ++ ++ avio_w8(pb, MAT_MARK_OUT); ++ avio_w8(pb, 4); ++ avio_wb32(pb, gxf->nb_fields); + + /* estimated size */ +- put_byte(pb, MAT_SIZE); +- put_byte(pb, 4); +- put_be32(pb, url_fsize(pb) / 1024); ++ avio_w8(pb, MAT_SIZE); ++ avio_w8(pb, 4); ++ avio_wb32(pb, avio_size(pb) / 1024); + + return updateSize(pb, pos); + } +@@ -315,12 +340,12 @@ + static int gxf_write_track_description_section(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; + int i; + +- pos = url_ftell(pb); +- put_be16(pb, 0); /* size */ ++ pos = avio_tell(pb); ++ avio_wb16(pb, 0); /* size */ + for (i = 0; i < s->nb_streams; ++i) + gxf_write_track_description(s, s->streams[i]->priv_data, i); + +@@ -332,13 +357,14 @@ + static int gxf_write_map_packet(AVFormatContext *s, int rewrite) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; +- int64_t pos = url_ftell(pb); ++ AVIOContext *pb = s->pb; ++ int64_t pos = avio_tell(pb); + + if (!rewrite) { + if (!(gxf->map_offsets_nb % 30)) { +- gxf->map_offsets = av_realloc(gxf->map_offsets, +- (gxf->map_offsets_nb+30)*sizeof(*gxf->map_offsets)); ++ gxf->map_offsets = av_realloc_f(gxf->map_offsets, ++ sizeof(*gxf->map_offsets), ++ gxf->map_offsets_nb+30); + if (!gxf->map_offsets) { + av_log(s, AV_LOG_ERROR, "could not realloc map offsets\n"); + return -1; +@@ -350,8 +376,8 @@ + gxf_write_packet_header(pb, PKT_MAP); + + /* preamble */ +- put_byte(pb, 0xE0); /* version */ +- put_byte(pb, 0xFF); /* reserved */ ++ avio_w8(pb, 0xE0); /* version */ ++ avio_w8(pb, 0xFF); /* reserved */ + + gxf_write_material_data_section(s); + gxf_write_track_description_section(s); +@@ -362,24 +388,24 @@ + static int gxf_write_flt_packet(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; +- int64_t pos = url_ftell(pb); ++ AVIOContext *pb = s->pb; ++ int64_t pos = avio_tell(pb); + int fields_per_flt = (gxf->nb_fields+1) / 1000 + 1; + int flt_entries = gxf->nb_fields / fields_per_flt; + int i = 0; + + gxf_write_packet_header(pb, PKT_FLT); + +- put_le32(pb, fields_per_flt); /* number of fields */ +- put_le32(pb, flt_entries); /* number of active flt entries */ ++ avio_wl32(pb, fields_per_flt); /* number of fields */ ++ avio_wl32(pb, flt_entries); /* number of active flt entries */ + + if (gxf->flt_entries) { + for (i = 0; i < flt_entries; i++) +- put_le32(pb, gxf->flt_entries[(i*fields_per_flt)>>1]); ++ avio_wl32(pb, gxf->flt_entries[(i*fields_per_flt)>>1]); + } + + for (; i < 1000; i++) +- put_le32(pb, 0); ++ avio_wl32(pb, 0); + + return updatePacketSize(pb, pos); + } +@@ -387,138 +413,160 @@ + static int gxf_write_umf_material_description(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int timecode_base = gxf->time_base.den == 60000 ? 60 : 50; ++ int64_t timestamp = 0; ++ AVDictionaryEntry *t; ++ uint64_t nb_fields; ++ uint32_t timecode_in; // timecode at mark in ++ uint32_t timecode_out; // timecode at mark out ++ ++#if FF_API_TIMESTAMP ++ if (s->timestamp) ++ timestamp = s->timestamp; ++ else ++#endif ++ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) ++ timestamp = ff_iso8601_to_unix_time(t->value); + +- // XXX drop frame +- uint32_t timecode = +- gxf->nb_fields / (timecode_base * 3600) % 24 << 24 | // hours +- gxf->nb_fields / (timecode_base * 60) % 60 << 16 | // minutes +- gxf->nb_fields / timecode_base % 60 << 8 | // seconds +- gxf->nb_fields % timecode_base; // fields +- +- put_le32(pb, gxf->flags); +- put_le32(pb, gxf->nb_fields); /* length of the longest track */ +- put_le32(pb, gxf->nb_fields); /* length of the shortest track */ +- put_le32(pb, 0); /* mark in */ +- put_le32(pb, gxf->nb_fields); /* mark out */ +- put_le32(pb, 0); /* timecode mark in */ +- put_le32(pb, timecode); /* timecode mark out */ +- put_le64(pb, s->timestamp); /* modification time */ +- put_le64(pb, s->timestamp); /* creation time */ +- put_le16(pb, 0); /* reserved */ +- put_le16(pb, 0); /* reserved */ +- put_le16(pb, gxf->audio_tracks); +- put_le16(pb, 1); /* timecode track count */ +- put_le16(pb, 0); /* reserved */ +- put_le16(pb, gxf->mpeg_tracks); ++ timecode_in = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop, ++ gxf->tc.hh, gxf->tc.mm, ++ gxf->tc.ss, gxf->tc.ff); ++ ++ nb_fields = gxf->nb_fields + ++ gxf->tc.hh * (timecode_base * 3600) + ++ gxf->tc.mm * (timecode_base * 60) + ++ gxf->tc.ss * timecode_base + ++ gxf->tc.ff; ++ ++ timecode_out = GXF_TIMECODE(gxf->tc.color, gxf->tc.drop, ++ nb_fields / (timecode_base * 3600) % 24, ++ nb_fields / (timecode_base * 60) % 60, ++ nb_fields / timecode_base % 60, ++ nb_fields % timecode_base); ++ ++ avio_wl32(pb, gxf->flags); ++ avio_wl32(pb, gxf->nb_fields); /* length of the longest track */ ++ avio_wl32(pb, gxf->nb_fields); /* length of the shortest track */ ++ avio_wl32(pb, 0); /* mark in */ ++ avio_wl32(pb, gxf->nb_fields); /* mark out */ ++ avio_wl32(pb, timecode_in); /* timecode mark in */ ++ avio_wl32(pb, timecode_out); /* timecode mark out */ ++ avio_wl64(pb, timestamp); /* modification time */ ++ avio_wl64(pb, timestamp); /* creation time */ ++ avio_wl16(pb, 0); /* reserved */ ++ avio_wl16(pb, 0); /* reserved */ ++ avio_wl16(pb, gxf->audio_tracks); ++ avio_wl16(pb, 1); /* timecode track count */ ++ avio_wl16(pb, 0); /* reserved */ ++ avio_wl16(pb, gxf->mpeg_tracks); + return 48; + } + + static int gxf_write_umf_payload(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- put_le32(pb, gxf->umf_length); /* total length of the umf data */ +- put_le32(pb, 3); /* version */ +- put_le32(pb, s->nb_streams+1); +- put_le32(pb, gxf->umf_track_offset); /* umf track section offset */ +- put_le32(pb, gxf->umf_track_size); +- put_le32(pb, s->nb_streams+1); +- put_le32(pb, gxf->umf_media_offset); +- put_le32(pb, gxf->umf_media_size); +- put_le32(pb, gxf->umf_length); /* user data offset */ +- put_le32(pb, 0); /* user data size */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ ++ avio_wl32(pb, gxf->umf_length); /* total length of the umf data */ ++ avio_wl32(pb, 3); /* version */ ++ avio_wl32(pb, s->nb_streams+1); ++ avio_wl32(pb, gxf->umf_track_offset); /* umf track section offset */ ++ avio_wl32(pb, gxf->umf_track_size); ++ avio_wl32(pb, s->nb_streams+1); ++ avio_wl32(pb, gxf->umf_media_offset); ++ avio_wl32(pb, gxf->umf_media_size); ++ avio_wl32(pb, gxf->umf_length); /* user data offset */ ++ avio_wl32(pb, 0); /* user data size */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ + return 48; + } + + static int gxf_write_umf_track_description(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + GXFContext *gxf = s->priv_data; +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + int i; + + gxf->umf_track_offset = pos - gxf->umf_start_offset; + for (i = 0; i < s->nb_streams; ++i) { + GXFStreamContext *sc = s->streams[i]->priv_data; +- put_le16(pb, sc->media_info); +- put_le16(pb, 1); ++ avio_wl16(pb, sc->media_info); ++ avio_wl16(pb, 1); + } + +- put_le16(pb, gxf->timecode_track.media_info); +- put_le16(pb, 1); ++ avio_wl16(pb, gxf->timecode_track.media_info); ++ avio_wl16(pb, 1); + +- return url_ftell(pb) - pos; ++ return avio_tell(pb) - pos; + } + +-static int gxf_write_umf_media_mpeg(ByteIOContext *pb, AVStream *st) ++static int gxf_write_umf_media_mpeg(AVIOContext *pb, AVStream *st) + { + GXFStreamContext *sc = st->priv_data; + + if (st->codec->pix_fmt == PIX_FMT_YUV422P) +- put_le32(pb, 2); ++ avio_wl32(pb, 2); + else +- put_le32(pb, 1); /* default to 420 */ +- put_le32(pb, sc->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */ +- put_le32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */ +- put_le32(pb, 1); /* I picture per GOP */ +- put_le32(pb, sc->p_per_gop); +- put_le32(pb, sc->b_per_i_or_p); ++ avio_wl32(pb, 1); /* default to 420 */ ++ avio_wl32(pb, sc->first_gop_closed == 1); /* closed = 1, open = 0, unknown = 255 */ ++ avio_wl32(pb, 3); /* top = 1, bottom = 2, frame = 3, unknown = 0 */ ++ avio_wl32(pb, 1); /* I picture per GOP */ ++ avio_wl32(pb, sc->p_per_gop); ++ avio_wl32(pb, sc->b_per_i_or_p); + if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) +- put_le32(pb, 2); ++ avio_wl32(pb, 2); + else if (st->codec->codec_id == CODEC_ID_MPEG1VIDEO) +- put_le32(pb, 1); ++ avio_wl32(pb, 1); + else +- put_le32(pb, 0); +- put_le32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); /* reserved */ + return 32; + } + +-static int gxf_write_umf_media_timecode(ByteIOContext *pb, GXFStreamContext *sc) ++static int gxf_write_umf_media_timecode(AVIOContext *pb, int drop) + { +- put_le32(pb, 1); /* non drop frame */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ ++ avio_wl32(pb, drop); /* drop frame */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ + return 32; + } + +-static int gxf_write_umf_media_dv(ByteIOContext *pb, GXFStreamContext *sc) ++static int gxf_write_umf_media_dv(AVIOContext *pb, GXFStreamContext *sc) + { + int i; + + for (i = 0; i < 8; i++) { +- put_be32(pb, 0); ++ avio_wb32(pb, 0); + } + return 32; + } + +-static int gxf_write_umf_media_audio(ByteIOContext *pb, GXFStreamContext *sc) ++static int gxf_write_umf_media_audio(AVIOContext *pb, GXFStreamContext *sc) + { +- put_le64(pb, av_dbl2int(1)); /* sound level to begin to */ +- put_le64(pb, av_dbl2int(1)); /* sound level to begin to */ +- put_le32(pb, 0); /* number of fields over which to ramp up sound level */ +- put_le32(pb, 0); /* number of fields over which to ramp down sound level */ +- put_le32(pb, 0); /* reserved */ +- put_le32(pb, 0); /* reserved */ ++ avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ ++ avio_wl64(pb, av_double2int(1)); /* sound level to begin to */ ++ avio_wl32(pb, 0); /* number of fields over which to ramp up sound level */ ++ avio_wl32(pb, 0); /* number of fields over which to ramp down sound level */ ++ avio_wl32(pb, 0); /* reserved */ ++ avio_wl32(pb, 0); /* reserved */ + return 32; + } + + #if 0 +-static int gxf_write_umf_media_mjpeg(ByteIOContext *pb, GXFStreamContext *sc) ++static int gxf_write_umf_media_mjpeg(AVIOContext *pb, GXFStreamContext *sc) + { +- put_be64(pb, 0); /* FIXME FLOAT max chroma quant level */ +- put_be64(pb, 0); /* FIXME FLOAT max luma quant level */ +- put_be64(pb, 0); /* FIXME FLOAT min chroma quant level */ +- put_be64(pb, 0); /* FIXME FLOAT min luma quant level */ ++ avio_wb64(pb, 0); /* FIXME FLOAT max chroma quant level */ ++ avio_wb64(pb, 0); /* FIXME FLOAT max luma quant level */ ++ avio_wb64(pb, 0); /* FIXME FLOAT min chroma quant level */ ++ avio_wb64(pb, 0); /* FIXME FLOAT min luma quant level */ + return 32; + } + #endif +@@ -526,11 +574,11 @@ + static int gxf_write_umf_media_description(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; + int i, j; + +- pos = url_ftell(pb); ++ pos = avio_tell(pb); + gxf->umf_media_offset = pos - gxf->umf_start_offset; + for (i = 0; i <= s->nb_streams; ++i) { + GXFStreamContext *sc; +@@ -541,26 +589,26 @@ + else + sc = s->streams[i]->priv_data; + +- startpos = url_ftell(pb); +- put_le16(pb, 0); /* length */ +- put_le16(pb, sc->media_info); +- put_le16(pb, 0); /* reserved */ +- put_le16(pb, 0); /* reserved */ +- put_le32(pb, gxf->nb_fields); +- put_le32(pb, 0); /* attributes rw, ro */ +- put_le32(pb, 0); /* mark in */ +- put_le32(pb, gxf->nb_fields); /* mark out */ +- put_buffer(pb, ES_NAME_PATTERN, strlen(ES_NAME_PATTERN)); +- put_be16(pb, sc->media_info); ++ startpos = avio_tell(pb); ++ avio_wl16(pb, 0); /* length */ ++ avio_wl16(pb, sc->media_info); ++ avio_wl16(pb, 0); /* reserved */ ++ avio_wl16(pb, 0); /* reserved */ ++ avio_wl32(pb, gxf->nb_fields); ++ avio_wl32(pb, 0); /* attributes rw, ro */ ++ avio_wl32(pb, 0); /* mark in */ ++ avio_wl32(pb, gxf->nb_fields); /* mark out */ ++ avio_write(pb, ES_NAME_PATTERN, strlen(ES_NAME_PATTERN)); ++ avio_wb16(pb, sc->media_info); + for (j = strlen(ES_NAME_PATTERN)+2; j < 88; j++) +- put_byte(pb, 0); +- put_le32(pb, sc->track_type); +- put_le32(pb, sc->sample_rate); +- put_le32(pb, sc->sample_size); +- put_le32(pb, 0); /* reserved */ ++ avio_w8(pb, 0); ++ avio_wl32(pb, sc->track_type); ++ avio_wl32(pb, sc->sample_rate); ++ avio_wl32(pb, sc->sample_size); ++ avio_wl32(pb, 0); /* reserved */ + + if (sc == &gxf->timecode_track) +- gxf_write_umf_media_timecode(pb, sc); /* 8 0bytes */ ++ gxf_write_umf_media_timecode(pb, gxf->tc.drop); + else { + AVStream *st = s->streams[i]; + switch (st->codec->codec_id) { +@@ -577,32 +625,32 @@ + } + } + +- curpos = url_ftell(pb); +- url_fseek(pb, startpos, SEEK_SET); +- put_le16(pb, curpos - startpos); +- url_fseek(pb, curpos, SEEK_SET); ++ curpos = avio_tell(pb); ++ avio_seek(pb, startpos, SEEK_SET); ++ avio_wl16(pb, curpos - startpos); ++ avio_seek(pb, curpos, SEEK_SET); + } +- return url_ftell(pb) - pos; ++ return avio_tell(pb) - pos; + } + + static int gxf_write_umf_packet(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; +- int64_t pos = url_ftell(pb); ++ AVIOContext *pb = s->pb; ++ int64_t pos = avio_tell(pb); + + gxf_write_packet_header(pb, PKT_UMF); + + /* preamble */ +- put_byte(pb, 3); /* first and last (only) packet */ +- put_be32(pb, gxf->umf_length); /* data length */ ++ avio_w8(pb, 3); /* first and last (only) packet */ ++ avio_wb32(pb, gxf->umf_length); /* data length */ + +- gxf->umf_start_offset = url_ftell(pb); ++ gxf->umf_start_offset = avio_tell(pb); + gxf_write_umf_payload(s); + gxf_write_umf_material_description(s); + gxf->umf_track_size = gxf_write_umf_track_description(s); + gxf->umf_media_size = gxf_write_umf_media_description(s); +- gxf->umf_length = url_ftell(pb) - gxf->umf_start_offset; ++ gxf->umf_length = avio_tell(pb) - gxf->umf_start_offset; + return updatePacketSize(pb, pos); + } + +@@ -623,15 +671,34 @@ + sc->fields = vsc->fields; + } + ++static int gxf_init_timecode(AVFormatContext *s, GXFTimecode *tc, int fields) ++{ ++ char c; ++ ++ if (sscanf(tc->str, "%d:%d:%d%c%d", &tc->hh, &tc->mm, &tc->ss, &c, &tc->ff) != 5) { ++ av_log(s, AV_LOG_ERROR, "unable to parse timecode, " ++ "syntax: hh:mm:ss[:;.]ff\n"); ++ return -1; ++ } ++ ++ tc->color = 0; ++ tc->drop = c != ':'; ++ ++ if (fields == 2) ++ tc->ff = tc->ff * 2; ++ ++ return 0; ++} ++ + static int gxf_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + GXFContext *gxf = s->priv_data; + GXFStreamContext *vsc = NULL; + uint8_t tracks[255] = {0}; + int i, media_info = 0; + +- if (url_is_streamed(pb)) { ++ if (!pb->seekable) { + av_log(s, AV_LOG_ERROR, "gxf muxer does not support streamed output, patch welcome"); + return -1; + } +@@ -660,7 +727,7 @@ + } + sc->track_type = 2; + sc->sample_rate = st->codec->sample_rate; +- av_set_pts_info(st, 64, 1, sc->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, sc->sample_rate); + sc->sample_size = 16; + sc->frame_rate_index = -2; + sc->lines_index = -2; +@@ -690,7 +757,7 @@ + "gxf muxer only accepts PAL or NTSC resolutions currently\n"); + return -1; + } +- av_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); ++ avpriv_set_pts_info(st, 64, gxf->time_base.num, gxf->time_base.den); + if (gxf_find_lines_index(st) < 0) + sc->lines_index = -1; + sc->sample_size = st->codec->bit_rate; +@@ -741,6 +808,10 @@ + if (ff_audio_interleave_init(s, GXF_samples_per_frame, (AVRational){ 1, 48000 }) < 0) + return -1; + ++ if (gxf->tc.str) { ++ gxf_init_timecode(s, &gxf->tc, vsc->fields); ++ } ++ + gxf_init_timecode_track(&gxf->timecode_track, vsc); + gxf->flags |= 0x200000; // time code track is non-drop frame + +@@ -750,13 +821,13 @@ + + gxf->packet_count = 3; + +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + +-static int gxf_write_eos_packet(ByteIOContext *pb) ++static int gxf_write_eos_packet(AVIOContext *pb) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + + gxf_write_packet_header(pb, PKT_EOS); + return updatePacketSize(pb, pos); +@@ -765,28 +836,28 @@ + static int gxf_write_trailer(AVFormatContext *s) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t end; + int i; + + ff_audio_interleave_close(s); + + gxf_write_eos_packet(pb); +- end = url_ftell(pb); +- url_fseek(pb, 0, SEEK_SET); ++ end = avio_tell(pb); ++ avio_seek(pb, 0, SEEK_SET); + /* overwrite map, flt and umf packets with new values */ + gxf_write_map_packet(s, 1); + gxf_write_flt_packet(s); + gxf_write_umf_packet(s); +- put_flush_packet(pb); ++ avio_flush(pb); + /* update duration in all map packets */ + for (i = 1; i < gxf->map_offsets_nb; i++) { +- url_fseek(pb, gxf->map_offsets[i], SEEK_SET); ++ avio_seek(pb, gxf->map_offsets[i], SEEK_SET); + gxf_write_map_packet(s, 1); +- put_flush_packet(pb); ++ avio_flush(pb); + } + +- url_fseek(pb, end, SEEK_SET); ++ avio_seek(pb, end, SEEK_SET); + + av_freep(&gxf->flt_entries); + av_freep(&gxf->map_offsets); +@@ -809,7 +880,7 @@ + static int gxf_write_media_preamble(AVFormatContext *s, AVPacket *pkt, int size) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[pkt->stream_index]; + GXFStreamContext *sc = st->priv_data; + unsigned field_nb; +@@ -823,44 +894,44 @@ + (int64_t)48000*gxf->time_base.num, AV_ROUND_UP); + } + +- put_byte(pb, sc->media_type); +- put_byte(pb, st->index); +- put_be32(pb, field_nb); ++ avio_w8(pb, sc->media_type); ++ avio_w8(pb, st->index); ++ avio_wb32(pb, field_nb); + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- put_be16(pb, 0); +- put_be16(pb, size / 2); ++ avio_wb16(pb, 0); ++ avio_wb16(pb, size / 2); + } else if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO) { + int frame_type = gxf_parse_mpeg_frame(sc, pkt->data, pkt->size); +- if (frame_type == FF_I_TYPE) { +- put_byte(pb, 0x0d); ++ if (frame_type == AV_PICTURE_TYPE_I) { ++ avio_w8(pb, 0x0d); + sc->iframes++; +- } else if (frame_type == FF_B_TYPE) { +- put_byte(pb, 0x0f); ++ } else if (frame_type == AV_PICTURE_TYPE_B) { ++ avio_w8(pb, 0x0f); + sc->bframes++; + } else { +- put_byte(pb, 0x0e); ++ avio_w8(pb, 0x0e); + sc->pframes++; + } +- put_be24(pb, size); ++ avio_wb24(pb, size); + } else if (st->codec->codec_id == CODEC_ID_DVVIDEO) { +- put_byte(pb, size / 4096); +- put_be24(pb, 0); ++ avio_w8(pb, size / 4096); ++ avio_wb24(pb, 0); + } else +- put_be32(pb, size); +- put_be32(pb, field_nb); +- put_byte(pb, 1); /* flags */ +- put_byte(pb, 0); /* reserved */ ++ avio_wb32(pb, size); ++ avio_wb32(pb, field_nb); ++ avio_w8(pb, 1); /* flags */ ++ avio_w8(pb, 0); /* reserved */ + return 16; + } + + static int gxf_write_packet(AVFormatContext *s, AVPacket *pkt) + { + GXFContext *gxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[pkt->stream_index]; +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + int padding = 0; +- int packet_start_offset = url_ftell(pb) / 1024; ++ int packet_start_offset = avio_tell(pb) / 1024; + + gxf_write_packet_header(pb, PKT_MEDIA); + if (st->codec->codec_id == CODEC_ID_MPEG2VIDEO && pkt->size % 4) /* MPEG-2 frames must be padded */ +@@ -868,13 +939,14 @@ + else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) + padding = GXF_AUDIO_PACKET_SIZE - pkt->size; + gxf_write_media_preamble(s, pkt, pkt->size + padding); +- put_buffer(pb, pkt->data, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); + gxf_write_padding(pb, padding); + + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (!(gxf->flt_entries_nb % 500)) { +- gxf->flt_entries = av_realloc(gxf->flt_entries, +- (gxf->flt_entries_nb+500)*sizeof(*gxf->flt_entries)); ++ gxf->flt_entries = av_realloc_f(gxf->flt_entries, ++ sizeof(*gxf->flt_entries), ++ gxf->flt_entries_nb+500); + if (!gxf->flt_entries) { + av_log(s, AV_LOG_ERROR, "could not reallocate flt entries\n"); + return -1; +@@ -892,7 +964,7 @@ + gxf->packet_count = 0; + } + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } +@@ -927,18 +999,28 @@ + av_interleave_packet_per_dts, gxf_compare_field_nb); + } + ++static const AVOption options[] = { ++ { TIMECODE_OPT(GXFContext, AV_OPT_FLAG_ENCODING_PARAM) }, ++ { NULL } ++}; ++ ++static const AVClass gxf_muxer_class = { ++ .class_name = "GXF muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVOutputFormat ff_gxf_muxer = { +- "gxf", +- NULL_IF_CONFIG_SMALL("GXF format"), +- NULL, +- "gxf", +- sizeof(GXFContext), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_MPEG2VIDEO, +- gxf_write_header, +- gxf_write_packet, +- gxf_write_trailer, +- 0, +- NULL, +- gxf_interleave_packet, ++ .name = "gxf", ++ .long_name = NULL_IF_CONFIG_SMALL("GXF format"), ++ .extensions = "gxf", ++ .priv_data_size = sizeof(GXFContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = gxf_write_header, ++ .write_packet = gxf_write_packet, ++ .write_trailer = gxf_write_trailer, ++ .interleave_packet = gxf_interleave_packet, ++ .priv_class = &gxf_muxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h261dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h261dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h261dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h261dec.c 2012-05-14 14:08:54.970352782 +0200 +@@ -62,14 +62,4 @@ + return 0; + } + +-AVInputFormat ff_h261_demuxer = { +- "h261", +- NULL_IF_CONFIG_SMALL("raw H.261"), +- 0, +- h261_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .extensions = "h261", +- .value = CODEC_ID_H261, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(h261, "raw H.261", h261_probe, "h261", CODEC_ID_H261) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h263dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h263dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h263dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h263dec.c 2012-05-14 14:08:54.971352802 +0200 +@@ -64,14 +64,4 @@ + return 0; + } + +-AVInputFormat ff_h263_demuxer = { +- "h263", +- NULL_IF_CONFIG_SMALL("raw H.263"), +- 0, +- h263_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +-// .extensions = "h263", //FIXME remove after writing mpeg4_probe +- .value = CODEC_ID_H263, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(h263, "raw H.263", h263_probe, NULL, CODEC_ID_H263) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h264dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h264dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/h264dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/h264dec.c 2012-05-14 14:08:54.971352802 +0200 +@@ -54,7 +54,7 @@ + case 1: sli++; break; + case 5: idr++; break; + case 7: +- if(p->buf[i+2]&0x0F) ++ if(p->buf[i+2]&0x03) + return 0; + sps++; + break; +@@ -67,14 +67,4 @@ + return 0; + } + +-AVInputFormat ff_h264_demuxer = { +- "h264", +- NULL_IF_CONFIG_SMALL("raw H.264 video format"), +- 0, +- h264_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .extensions = "h26l,h264,264", //FIXME remove after writing mpeg4_probe +- .value = CODEC_ID_H264, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(h264 , "raw H.264 video format", h264_probe, "h26l,h264,264", CODEC_ID_H264) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/httpauth.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/httpauth.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/httpauth.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/httpauth.c 2012-05-14 14:08:54.975352882 +0200 +@@ -87,7 +87,7 @@ + void ff_http_auth_handle_header(HTTPAuthState *state, const char *key, + const char *value) + { +- if (!strcmp(key, "WWW-Authenticate")) { ++ if (!strcmp(key, "WWW-Authenticate") || !strcmp(key, "Proxy-Authenticate")) { + const char *p; + if (av_stristart(value, "Basic ", &p) && + state->auth_type <= HTTP_AUTH_BASIC) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/http.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/http.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/http.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/http.c 2012-05-14 14:08:54.974352862 +0200 +@@ -22,12 +22,12 @@ + #include "libavutil/avstring.h" + #include "avformat.h" + #include +-#include + #include "internal.h" + #include "network.h" + #include "http.h" + #include "os_support.h" + #include "httpauth.h" ++#include "url.h" + #include "libavutil/opt.h" + + /* XXX: POST protocol is not completely implemented because ffmpeg uses +@@ -44,57 +44,60 @@ + int line_count; + int http_code; + int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ ++ char *user_agent; + int64_t off, filesize; + char location[MAX_URL_SIZE]; + HTTPAuthState auth_state; +- unsigned char headers[BUFFER_SIZE]; ++ HTTPAuthState proxy_auth_state; ++ char *headers; + int willclose; /**< Set if the server correctly handles Connection: close and will close the connection after feeding us the content. */ ++ int chunked_post; + } HTTPContext; + + #define OFFSET(x) offsetof(HTTPContext, x) ++#define D AV_OPT_FLAG_DECODING_PARAM ++#define E AV_OPT_FLAG_ENCODING_PARAM ++#define DEC AV_OPT_FLAG_DECODING_PARAM + static const AVOption options[] = { +-{"chunksize", "use chunked transfer-encoding for posts, -1 disables it, 0 enables it", OFFSET(chunksize), FF_OPT_TYPE_INT64, 0, -1, 0 }, /* Default to 0, for chunked POSTs */ ++{"chunked_post", "use chunked transfer-encoding for posts", OFFSET(chunked_post), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, E }, ++{"headers", "custom HTTP headers, can override built in default headers", OFFSET(headers), AV_OPT_TYPE_STRING, { 0 }, 0, 0, D|E }, ++{"user-agent", "override User-Agent header", OFFSET(user_agent), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC}, + {NULL} + }; +-static const AVClass httpcontext_class = { +- "HTTP", av_default_item_name, options, LIBAVUTIL_VERSION_INT +-}; +- +-static int http_connect(URLContext *h, const char *path, const char *hoststr, +- const char *auth, int *new_location); +- +-void ff_http_set_headers(URLContext *h, const char *headers) +-{ +- HTTPContext *s = h->priv_data; +- int len = strlen(headers); +- +- if (len && strcmp("\r\n", headers + len - 2)) +- av_log(NULL, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n"); +- +- av_strlcpy(s->headers, headers, sizeof(s->headers)); ++#define HTTP_CLASS(flavor)\ ++static const AVClass flavor ## _context_class = {\ ++ .class_name = #flavor,\ ++ .item_name = av_default_item_name,\ ++ .option = options,\ ++ .version = LIBAVUTIL_VERSION_INT,\ + } + +-void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked) +-{ +- ((HTTPContext*)h->priv_data)->chunksize = is_chunked ? 0 : -1; +-} ++HTTP_CLASS(http); ++HTTP_CLASS(https); ++ ++static int http_connect(URLContext *h, const char *path, const char *local_path, ++ const char *hoststr, const char *auth, ++ const char *proxyauth, int *new_location); + + void ff_http_init_auth_state(URLContext *dest, const URLContext *src) + { + memcpy(&((HTTPContext*)dest->priv_data)->auth_state, + &((HTTPContext*)src->priv_data)->auth_state, sizeof(HTTPAuthState)); ++ memcpy(&((HTTPContext*)dest->priv_data)->proxy_auth_state, ++ &((HTTPContext*)src->priv_data)->proxy_auth_state, ++ sizeof(HTTPAuthState)); + } + + /* return non zero if error */ + static int http_open_cnx(URLContext *h) + { +- const char *path, *proxy_path; +- char hostname[1024], hoststr[1024]; +- char auth[1024]; ++ const char *path, *proxy_path, *lower_proto = "tcp", *local_path; ++ char hostname[1024], hoststr[1024], proto[10]; ++ char auth[1024], proxyauth[1024] = ""; + char path1[1024]; +- char buf[1024]; ++ char buf[1024], urlbuf[1024]; + int port, use_proxy, err, location_changed = 0, redirects = 0; +- HTTPAuthType cur_auth_type; ++ HTTPAuthType cur_auth_type, cur_proxy_auth_type; + HTTPContext *s = h->priv_data; + URLContext *hd = NULL; + +@@ -105,35 +108,57 @@ + /* fill the dest addr */ + redo: + /* needed in any case to build the host string */ +- av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, ++ av_url_split(proto, sizeof(proto), auth, sizeof(auth), ++ hostname, sizeof(hostname), &port, + path1, sizeof(path1), s->location); + ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); + +- if (use_proxy) { +- av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, +- NULL, 0, proxy_path); +- path = s->location; +- } else { +- if (path1[0] == '\0') +- path = "/"; +- else +- path = path1; ++ if (!strcmp(proto, "https")) { ++ lower_proto = "tls"; ++ use_proxy = 0; ++ if (port < 0) ++ port = 443; + } + if (port < 0) + port = 80; + +- ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); +- err = url_open(&hd, buf, URL_RDWR); ++ if (path1[0] == '\0') ++ path = "/"; ++ else ++ path = path1; ++ local_path = path; ++ if (use_proxy) { ++ /* Reassemble the request URL without auth string - we don't ++ * want to leak the auth to the proxy. */ ++ ff_url_join(urlbuf, sizeof(urlbuf), proto, NULL, hostname, port, "%s", ++ path1); ++ path = urlbuf; ++ av_url_split(NULL, 0, proxyauth, sizeof(proxyauth), ++ hostname, sizeof(hostname), &port, NULL, 0, proxy_path); ++ } ++ ++ ff_url_join(buf, sizeof(buf), lower_proto, NULL, hostname, port, NULL); ++ err = ffurl_open(&hd, buf, AVIO_FLAG_READ_WRITE, ++ &h->interrupt_callback, NULL); + if (err < 0) + goto fail; + + s->hd = hd; + cur_auth_type = s->auth_state.auth_type; +- if (http_connect(h, path, hoststr, auth, &location_changed) < 0) ++ cur_proxy_auth_type = s->auth_state.auth_type; ++ if (http_connect(h, path, local_path, hoststr, auth, proxyauth, &location_changed) < 0) + goto fail; + if (s->http_code == 401) { + if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { +- url_close(hd); ++ ffurl_close(hd); ++ goto redo; ++ } else ++ goto fail; ++ } ++ if (s->http_code == 407) { ++ if (cur_proxy_auth_type == HTTP_AUTH_NONE && ++ s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) { ++ ffurl_close(hd); + goto redo; + } else + goto fail; +@@ -141,7 +166,7 @@ + if ((s->http_code == 301 || s->http_code == 302 || s->http_code == 303 || s->http_code == 307) + && location_changed == 1) { + /* url moved, get next */ +- url_close(hd); ++ ffurl_close(hd); + if (redirects++ >= MAX_REDIRECTS) + return AVERROR(EIO); + location_changed = 0; +@@ -150,7 +175,7 @@ + return 0; + fail: + if (hd) +- url_close(hd); ++ ffurl_close(hd); + s->hd = NULL; + return AVERROR(EIO); + } +@@ -164,13 +189,19 @@ + s->filesize = -1; + av_strlcpy(s->location, uri, sizeof(s->location)); + ++ if (s->headers) { ++ int len = strlen(s->headers); ++ if (len < 2 || strcmp("\r\n", s->headers + len - 2)) ++ av_log(h, AV_LOG_WARNING, "No trailing CRLF found in HTTP header.\n"); ++ } ++ + return http_open_cnx(h); + } + static int http_getc(HTTPContext *s) + { + int len; + if (s->buf_ptr >= s->buf_end) { +- len = url_read(s->hd, s->buffer, BUFFER_SIZE); ++ len = ffurl_read(s->hd, s->buffer, BUFFER_SIZE); + if (len < 0) { + return AVERROR(EIO); + } else if (len == 0) { +@@ -229,9 +260,11 @@ + + /* error codes are 4xx and 5xx, but regard 401 as a success, so we + * don't abort until all headers have been parsed. */ +- if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) { ++ if (s->http_code >= 400 && s->http_code < 600 && (s->http_code != 401 ++ || s->auth_state.auth_type != HTTP_AUTH_NONE) && ++ (s->http_code != 407 || s->proxy_auth_state.auth_type != HTTP_AUTH_NONE)) { + end += strspn(end, SPACE_CHARS); +- av_log(NULL, AV_LOG_WARNING, "HTTP error %d %s\n", ++ av_log(h, AV_LOG_WARNING, "HTTP error %d %s\n", + s->http_code, end); + return -1; + } +@@ -246,12 +279,12 @@ + p++; + while (isspace(*p)) + p++; +- if (!strcmp(tag, "Location")) { ++ if (!av_strcasecmp(tag, "Location")) { + strcpy(s->location, p); + *new_location = 1; +- } else if (!strcmp (tag, "Content-Length") && s->filesize == -1) { ++ } else if (!av_strcasecmp (tag, "Content-Length") && s->filesize == -1) { + s->filesize = atoll(p); +- } else if (!strcmp (tag, "Content-Range")) { ++ } else if (!av_strcasecmp (tag, "Content-Range")) { + /* "bytes $from-$to/$document_size" */ + const char *slash; + if (!strncmp (p, "bytes ", 6)) { +@@ -261,14 +294,18 @@ + s->filesize = atoll(slash+1); + } + h->is_streamed = 0; /* we _can_ in fact seek */ +- } else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) { ++ } else if (!av_strcasecmp(tag, "Accept-Ranges") && !strncmp(p, "bytes", 5)) { ++ h->is_streamed = 0; ++ } else if (!av_strcasecmp (tag, "Transfer-Encoding") && !av_strncasecmp(p, "chunked", 7)) { + s->filesize = -1; + s->chunksize = 0; +- } else if (!strcmp (tag, "WWW-Authenticate")) { ++ } else if (!av_strcasecmp (tag, "WWW-Authenticate")) { + ff_http_auth_handle_header(&s->auth_state, tag, p); +- } else if (!strcmp (tag, "Authentication-Info")) { ++ } else if (!av_strcasecmp (tag, "Authentication-Info")) { + ff_http_auth_handle_header(&s->auth_state, tag, p); +- } else if (!strcmp (tag, "Connection")) { ++ } else if (!av_strcasecmp (tag, "Proxy-Authenticate")) { ++ ff_http_auth_handle_header(&s->proxy_auth_state, tag, p); ++ } else if (!av_strcasecmp (tag, "Connection")) { + if (!strcmp(p, "close")) + s->willclose = 1; + } +@@ -279,34 +316,42 @@ + static inline int has_header(const char *str, const char *header) + { + /* header + 2 to skip over CRLF prefix. (make sure you have one!) */ ++ if (!str) ++ return 0; + return av_stristart(str, header + 2, NULL) || av_stristr(str, header); + } + +-static int http_connect(URLContext *h, const char *path, const char *hoststr, +- const char *auth, int *new_location) ++static int http_connect(URLContext *h, const char *path, const char *local_path, ++ const char *hoststr, const char *auth, ++ const char *proxyauth, int *new_location) + { + HTTPContext *s = h->priv_data; + int post, err; + char line[1024]; + char headers[1024] = ""; +- char *authstr = NULL; ++ char *authstr = NULL, *proxyauthstr = NULL; + int64_t off = s->off; + int len = 0; ++ const char *method; + + + /* send http header */ +- post = h->flags & URL_WRONLY; +- authstr = ff_http_auth_create_response(&s->auth_state, auth, path, +- post ? "POST" : "GET"); ++ post = h->flags & AVIO_FLAG_WRITE; ++ method = post ? "POST" : "GET"; ++ authstr = ff_http_auth_create_response(&s->auth_state, auth, local_path, ++ method); ++ proxyauthstr = ff_http_auth_create_response(&s->proxy_auth_state, proxyauth, ++ local_path, method); + + /* set default headers if needed */ + if (!has_header(s->headers, "\r\nUser-Agent: ")) +- len += av_strlcatf(headers + len, sizeof(headers) - len, +- "User-Agent: %s\r\n", LIBAVFORMAT_IDENT); ++ len += av_strlcatf(headers + len, sizeof(headers) - len, ++ "User-Agent: %s\r\n", ++ s->user_agent ? s->user_agent : LIBAVFORMAT_IDENT); + if (!has_header(s->headers, "\r\nAccept: ")) + len += av_strlcpy(headers + len, "Accept: */*\r\n", + sizeof(headers) - len); +- if (!has_header(s->headers, "\r\nRange: ")) ++ if (!has_header(s->headers, "\r\nRange: ") && !post) + len += av_strlcatf(headers + len, sizeof(headers) - len, + "Range: bytes=%"PRId64"-\r\n", s->off); + if (!has_header(s->headers, "\r\nConnection: ")) +@@ -317,22 +362,26 @@ + "Host: %s\r\n", hoststr); + + /* now add in custom headers */ +- av_strlcpy(headers+len, s->headers, sizeof(headers)-len); ++ if (s->headers) ++ av_strlcpy(headers + len, s->headers, sizeof(headers) - len); + + snprintf(s->buffer, sizeof(s->buffer), + "%s %s HTTP/1.1\r\n" + "%s" + "%s" + "%s" ++ "%s%s" + "\r\n", +- post ? "POST" : "GET", ++ method, + path, +- post && s->chunksize >= 0 ? "Transfer-Encoding: chunked\r\n" : "", ++ post && s->chunked_post ? "Transfer-Encoding: chunked\r\n" : "", + headers, +- authstr ? authstr : ""); ++ authstr ? authstr : "", ++ proxyauthstr ? "Proxy-" : "", proxyauthstr ? proxyauthstr : ""); + + av_freep(&authstr); +- if (url_write(s->hd, s->buffer, strlen(s->buffer)) < 0) ++ av_freep(&proxyauthstr); ++ if (ffurl_write(s->hd, s->buffer, strlen(s->buffer)) < 0) + return AVERROR(EIO); + + /* init input buffer */ +@@ -370,10 +419,33 @@ + } + + +-static int http_read(URLContext *h, uint8_t *buf, int size) ++static int http_buf_read(URLContext *h, uint8_t *buf, int size) + { + HTTPContext *s = h->priv_data; + int len; ++ /* read bytes from input buffer first */ ++ len = s->buf_end - s->buf_ptr; ++ if (len > 0) { ++ if (len > size) ++ len = size; ++ memcpy(buf, s->buf_ptr, len); ++ s->buf_ptr += len; ++ } else { ++ if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize) ++ return AVERROR_EOF; ++ len = ffurl_read(s->hd, buf, size); ++ } ++ if (len > 0) { ++ s->off += len; ++ if (s->chunksize > 0) ++ s->chunksize -= len; ++ } ++ return len; ++} ++ ++static int http_read(URLContext *h, uint8_t *buf, int size) ++{ ++ HTTPContext *s = h->priv_data; + + if (s->chunksize >= 0) { + if (!s->chunksize) { +@@ -396,24 +468,7 @@ + } + size = FFMIN(size, s->chunksize); + } +- /* read bytes from input buffer first */ +- len = s->buf_end - s->buf_ptr; +- if (len > 0) { +- if (len > size) +- len = size; +- memcpy(buf, s->buf_ptr, len); +- s->buf_ptr += len; +- } else { +- if (!s->willclose && s->filesize >= 0 && s->off >= s->filesize) +- return AVERROR_EOF; +- len = url_read(s->hd, buf, size); +- } +- if (len > 0) { +- s->off += len; +- if (s->chunksize > 0) +- s->chunksize -= len; +- } +- return len; ++ return http_buf_read(h, buf, size); + } + + /* used only when posting data */ +@@ -424,9 +479,9 @@ + char crlf[] = "\r\n"; + HTTPContext *s = h->priv_data; + +- if (s->chunksize == -1) { ++ if (!s->chunked_post) { + /* non-chunked data is sent without any special encoding */ +- return url_write(s->hd, buf, size); ++ return ffurl_write(s->hd, buf, size); + } + + /* silently ignore zero-size data since chunk encoding that would +@@ -435,9 +490,9 @@ + /* upload data using chunked encoding */ + snprintf(temp, sizeof(temp), "%x\r\n", size); + +- if ((ret = url_write(s->hd, temp, strlen(temp))) < 0 || +- (ret = url_write(s->hd, buf, size)) < 0 || +- (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) ++ if ((ret = ffurl_write(s->hd, temp, strlen(temp))) < 0 || ++ (ret = ffurl_write(s->hd, buf, size)) < 0 || ++ (ret = ffurl_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) + return ret; + } + return size; +@@ -450,13 +505,13 @@ + HTTPContext *s = h->priv_data; + + /* signal end of chunked encoding if used */ +- if ((h->flags & URL_WRONLY) && s->chunksize != -1) { +- ret = url_write(s->hd, footer, sizeof(footer) - 1); ++ if ((h->flags & AVIO_FLAG_WRITE) && s->chunked_post) { ++ ret = ffurl_write(s->hd, footer, sizeof(footer) - 1); + ret = ret > 0 ? 0 : ret; + } + + if (s->hd) +- url_close(s->hd); ++ ffurl_close(s->hd); + return ret; + } + +@@ -492,7 +547,7 @@ + s->off = old_off; + return -1; + } +- url_close(old_hd); ++ ffurl_close(old_hd); + return off; + } + +@@ -500,17 +555,150 @@ + http_get_file_handle(URLContext *h) + { + HTTPContext *s = h->priv_data; +- return url_get_file_handle(s->hd); ++ return ffurl_get_file_handle(s->hd); + } + ++#if CONFIG_HTTP_PROTOCOL + URLProtocol ff_http_protocol = { +- "http", +- http_open, +- http_read, +- http_write, +- http_seek, +- http_close, ++ .name = "http", ++ .url_open = http_open, ++ .url_read = http_read, ++ .url_write = http_write, ++ .url_seek = http_seek, ++ .url_close = http_close, ++ .url_get_file_handle = http_get_file_handle, ++ .priv_data_size = sizeof(HTTPContext), ++ .priv_data_class = &http_context_class, ++ .flags = URL_PROTOCOL_FLAG_NETWORK, ++}; ++#endif ++#if CONFIG_HTTPS_PROTOCOL ++URLProtocol ff_https_protocol = { ++ .name = "https", ++ .url_open = http_open, ++ .url_read = http_read, ++ .url_write = http_write, ++ .url_seek = http_seek, ++ .url_close = http_close, ++ .url_get_file_handle = http_get_file_handle, ++ .priv_data_size = sizeof(HTTPContext), ++ .priv_data_class = &https_context_class, ++ .flags = URL_PROTOCOL_FLAG_NETWORK, ++}; ++#endif ++ ++#if CONFIG_HTTPPROXY_PROTOCOL ++static int http_proxy_close(URLContext *h) ++{ ++ HTTPContext *s = h->priv_data; ++ if (s->hd) ++ ffurl_close(s->hd); ++ return 0; ++} ++ ++static int http_proxy_open(URLContext *h, const char *uri, int flags) ++{ ++ HTTPContext *s = h->priv_data; ++ char hostname[1024], hoststr[1024]; ++ char auth[1024], pathbuf[1024], *path; ++ char line[1024], lower_url[100]; ++ int port, ret = 0; ++ HTTPAuthType cur_auth_type; ++ char *authstr; ++ ++ h->is_streamed = 1; ++ ++ av_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, ++ pathbuf, sizeof(pathbuf), uri); ++ ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); ++ path = pathbuf; ++ if (*path == '/') ++ path++; ++ ++ ff_url_join(lower_url, sizeof(lower_url), "tcp", NULL, hostname, port, ++ NULL); ++redo: ++ ret = ffurl_open(&s->hd, lower_url, AVIO_FLAG_READ_WRITE, ++ &h->interrupt_callback, NULL); ++ if (ret < 0) ++ return ret; ++ ++ authstr = ff_http_auth_create_response(&s->proxy_auth_state, auth, ++ path, "CONNECT"); ++ snprintf(s->buffer, sizeof(s->buffer), ++ "CONNECT %s HTTP/1.1\r\n" ++ "Host: %s\r\n" ++ "Connection: close\r\n" ++ "%s%s" ++ "\r\n", ++ path, ++ hoststr, ++ authstr ? "Proxy-" : "", authstr ? authstr : ""); ++ av_freep(&authstr); ++ ++ if ((ret = ffurl_write(s->hd, s->buffer, strlen(s->buffer))) < 0) ++ goto fail; ++ ++ s->buf_ptr = s->buffer; ++ s->buf_end = s->buffer; ++ s->line_count = 0; ++ s->filesize = -1; ++ cur_auth_type = s->proxy_auth_state.auth_type; ++ ++ for (;;) { ++ int new_loc; ++ // Note: This uses buffering, potentially reading more than the ++ // HTTP header. If tunneling a protocol where the server starts ++ // the conversation, we might buffer part of that here, too. ++ // Reading that requires using the proper ffurl_read() function ++ // on this URLContext, not using the fd directly (as the tls ++ // protocol does). This shouldn't be an issue for tls though, ++ // since the client starts the conversation there, so there ++ // is no extra data that we might buffer up here. ++ if (http_get_line(s, line, sizeof(line)) < 0) { ++ ret = AVERROR(EIO); ++ goto fail; ++ } ++ ++ av_dlog(h, "header='%s'\n", line); ++ ++ ret = process_line(h, line, s->line_count, &new_loc); ++ if (ret < 0) ++ goto fail; ++ if (ret == 0) ++ break; ++ s->line_count++; ++ } ++ if (s->http_code == 407 && cur_auth_type == HTTP_AUTH_NONE && ++ s->proxy_auth_state.auth_type != HTTP_AUTH_NONE) { ++ ffurl_close(s->hd); ++ s->hd = NULL; ++ goto redo; ++ } ++ ++ if (s->http_code < 400) ++ return 0; ++ ret = AVERROR(EIO); ++ ++fail: ++ http_proxy_close(h); ++ return ret; ++} ++ ++static int http_proxy_write(URLContext *h, const uint8_t *buf, int size) ++{ ++ HTTPContext *s = h->priv_data; ++ return ffurl_write(s->hd, buf, size); ++} ++ ++URLProtocol ff_httpproxy_protocol = { ++ .name = "httpproxy", ++ .url_open = http_proxy_open, ++ .url_read = http_buf_read, ++ .url_write = http_proxy_write, ++ .url_close = http_proxy_close, + .url_get_file_handle = http_get_file_handle, +- .priv_data_size = sizeof(HTTPContext), +- .priv_data_class = &httpcontext_class, ++ .priv_data_size = sizeof(HTTPContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/http.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/http.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/http.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/http.h 2012-05-14 14:08:54.974352862 +0200 +@@ -22,33 +22,7 @@ + #ifndef AVFORMAT_HTTP_H + #define AVFORMAT_HTTP_H + +-#include "avio.h" +- +-/** +- * Set custom HTTP headers. +- * A trailing CRLF ("\r\n") is required for custom headers. +- * Passing in an empty header string ("\0") will reset to defaults. +- * +- * The following headers can be overriden by custom values, +- * otherwise they will be set to their defaults. +- * -User-Agent +- * -Accept +- * -Range +- * -Host +- * -Connection +- * +- * @param h URL context for this HTTP connection +- * @param headers the custom headers to set +- */ +-void ff_http_set_headers(URLContext *h, const char *headers); +- +-/** +- * Enable or disable chunked transfer encoding. (default is enabled) +- * +- * @param h URL context for this HTTP connection +- * @param is_chunked 0 to disable chunking, nonzero otherwise. +- */ +-void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked); ++#include "url.h" + + /** + * Initialize the authentication state based on another HTTP URLContext. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/icodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/icodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/icodec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/icodec.c 2012-05-14 14:08:54.976352902 +0200 +@@ -0,0 +1,181 @@ ++/* ++ * Microsoft Windows ICO demuxer ++ * Copyright (c) 2011 Peter Ross (pross@xvid.org) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Microsoft Windows ICO demuxer ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavcodec/bytestream.h" ++#include "libavcodec/bmp.h" ++#include "avformat.h" ++#include "internal.h" ++ ++typedef struct { ++ int offset; ++ int size; ++ int nb_pal; ++} IcoImage; ++ ++typedef struct { ++ int current_image; ++ int nb_images; ++ IcoImage * images; ++} IcoDemuxContext; ++ ++static int probe(AVProbeData *p) ++{ ++ if (AV_RL16(p->buf) == 0 && AV_RL16(p->buf + 2) == 1 && AV_RL16(p->buf + 4)) ++ return AVPROBE_SCORE_MAX / 3; ++ return 0; ++} ++ ++static int read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ IcoDemuxContext *ico = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int i; ++ ++ avio_skip(pb, 4); ++ ico->nb_images = avio_rl16(pb); ++ ++ ico->images = av_malloc(ico->nb_images * sizeof(IcoImage)); ++ if (!ico->images) ++ return AVERROR(ENOMEM); ++ ++ for (i = 0; i < ico->nb_images; i++) { ++ AVStream *st; ++ int tmp; ++ ++ if (avio_seek(pb, 6 + i * 16, SEEK_SET) < 0) ++ break; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->width = avio_r8(pb); ++ st->codec->height = avio_r8(pb); ++ ico->images[i].nb_pal = avio_r8(pb); ++ if (ico->images[i].nb_pal == 255) ++ ico->images[i].nb_pal = 0; ++ ++ avio_skip(pb, 5); ++ ++ ico->images[i].size = avio_rl32(pb); ++ ico->images[i].offset = avio_rl32(pb); ++ ++ if (avio_seek(pb, ico->images[i].offset, SEEK_SET) < 0) ++ break; ++ ++ switch(avio_rl32(pb)) { ++ case MKTAG(0x89, 'P', 'N', 'G'): ++ st->codec->codec_id = CODEC_ID_PNG; ++ st->codec->width = 0; ++ st->codec->height = 0; ++ break; ++ case 40: ++ if (ico->images[i].size < 40) ++ return AVERROR_INVALIDDATA; ++ st->codec->codec_id = CODEC_ID_BMP; ++ tmp = avio_rl32(pb); ++ if (tmp) ++ st->codec->width = tmp; ++ tmp = avio_rl32(pb); ++ if (tmp) ++ st->codec->height = tmp / 2; ++ break; ++ default: ++ av_log_ask_for_sample(s, "unsupported codec\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ ++ return 0; ++} ++ ++static int read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ IcoDemuxContext *ico = s->priv_data; ++ IcoImage *image; ++ AVIOContext *pb = s->pb; ++ AVStream *st = s->streams[0]; ++ int ret; ++ ++ if (ico->current_image >= ico->nb_images) ++ return AVERROR(EIO); ++ ++ image = &ico->images[ico->current_image]; ++ ++ if ((ret = avio_seek(pb, image->offset, SEEK_SET)) < 0) ++ return ret; ++ ++ if (s->streams[ico->current_image]->codec->codec_id == CODEC_ID_PNG) { ++ if ((ret = av_get_packet(pb, pkt, image->size)) < 0) ++ return ret; ++ } else { ++ uint8_t *buf; ++ if ((ret = av_new_packet(pkt, 14 + image->size)) < 0) ++ return ret; ++ buf = pkt->data; ++ ++ /* add BMP header */ ++ bytestream_put_byte(&buf, 'B'); ++ bytestream_put_byte(&buf, 'M'); ++ bytestream_put_le32(&buf, pkt->size); ++ bytestream_put_le16(&buf, 0); ++ bytestream_put_le16(&buf, 0); ++ bytestream_put_le32(&buf, 0); ++ ++ if ((ret = avio_read(pb, buf, image->size)) < 0) ++ return ret; ++ ++ st->codec->bits_per_coded_sample = AV_RL16(buf + 14); ++ ++ if (AV_RL32(buf + 32)) ++ image->nb_pal = AV_RL32(buf + 32); ++ ++ if (st->codec->bits_per_coded_sample <= 8 && !image->nb_pal) { ++ image->nb_pal = 1 << st->codec->bits_per_coded_sample; ++ AV_WL32(buf + 32, image->nb_pal); ++ } ++ ++ AV_WL32(buf - 4, 14 + 40 + image->nb_pal * 4); ++ AV_WL32(buf + 8, AV_RL32(buf + 8) / 2); ++ } ++ ++ pkt->stream_index = ico->current_image++; ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ ++ return 0; ++} ++ ++AVInputFormat ff_ico_demuxer = { ++ .name = "ico", ++ .long_name = NULL_IF_CONFIG_SMALL("Microsoft Windows ICO"), ++ .priv_data_size = sizeof(IcoDemuxContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .flags = AVFMT_NOTIMESTAMPS, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v1.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v1.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v1.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v1.c 2012-05-14 14:08:54.976352902 +0200 +@@ -21,6 +21,7 @@ + + #include "id3v1.h" + #include "libavcodec/avcodec.h" ++#include "libavutil/dict.h" + + const char * const ff_id3v1_genre_str[ID3v1_GENRE_MAX + 1] = { + [0] = "Blues", +@@ -191,7 +192,7 @@ + *q = '\0'; + + if (*str) +- av_metadata_set2(&s->metadata, key, str, 0); ++ av_dict_set(&s->metadata, key, str, 0); + } + + /** +@@ -215,29 +216,30 @@ + get_string(s, "comment", buf + 97, 30); + if (buf[125] == 0 && buf[126] != 0) { + snprintf(str, sizeof(str), "%d", buf[126]); +- av_metadata_set2(&s->metadata, "track", str, 0); ++ av_dict_set(&s->metadata, "track", str, 0); + } + genre = buf[127]; + if (genre <= ID3v1_GENRE_MAX) +- av_metadata_set2(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0); ++ av_dict_set(&s->metadata, "genre", ff_id3v1_genre_str[genre], 0); + return 0; + } + + void ff_id3v1_read(AVFormatContext *s) + { +- int ret, filesize; ++ int ret; + uint8_t buf[ID3v1_TAG_SIZE]; ++ int64_t filesize, position = avio_tell(s->pb); + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + /* XXX: change that */ +- filesize = url_fsize(s->pb); ++ filesize = avio_size(s->pb); + if (filesize > 128) { +- url_fseek(s->pb, filesize - 128, SEEK_SET); +- ret = get_buffer(s->pb, buf, ID3v1_TAG_SIZE); ++ avio_seek(s->pb, filesize - 128, SEEK_SET); ++ ret = avio_read(s->pb, buf, ID3v1_TAG_SIZE); + if (ret == ID3v1_TAG_SIZE) { + parse_tag(s, buf); + } +- url_fseek(s->pb, 0, SEEK_SET); ++ avio_seek(s->pb, position, SEEK_SET); + } + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2.c 2012-05-14 14:08:54.979352964 +0200 +@@ -1,5 +1,4 @@ + /* +- * ID3v2 header parser + * Copyright (c) 2003 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -19,11 +18,86 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * ID3v2 header parser ++ * ++ * Specifications available at: ++ * http://id3.org/Developer_Information ++ */ ++ ++#include "config.h" ++ ++#if CONFIG_ZLIB ++#include ++#endif ++ + #include "id3v2.h" + #include "id3v1.h" + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" +-#include "metadata.h" ++#include "libavutil/dict.h" ++#include "avio_internal.h" ++ ++const AVMetadataConv ff_id3v2_34_metadata_conv[] = { ++ { "TALB", "album"}, ++ { "TCOM", "composer"}, ++ { "TCON", "genre"}, ++ { "TCOP", "copyright"}, ++ { "TENC", "encoded_by"}, ++ { "TIT2", "title"}, ++ { "TLAN", "language"}, ++ { "TPE1", "artist"}, ++ { "TPE2", "album_artist"}, ++ { "TPE3", "performer"}, ++ { "TPOS", "disc"}, ++ { "TPUB", "publisher"}, ++ { "TRCK", "track"}, ++ { "TSSE", "encoder"}, ++ { 0 } ++}; ++ ++const AVMetadataConv ff_id3v2_4_metadata_conv[] = { ++ { "TDRL", "date"}, ++ { "TDRC", "date"}, ++ { "TDEN", "creation_time"}, ++ { "TSOA", "album-sort"}, ++ { "TSOP", "artist-sort"}, ++ { "TSOT", "title-sort"}, ++ { 0 } ++}; ++ ++static const AVMetadataConv id3v2_2_metadata_conv[] = { ++ { "TAL", "album"}, ++ { "TCO", "genre"}, ++ { "TT2", "title"}, ++ { "TEN", "encoded_by"}, ++ { "TP1", "artist"}, ++ { "TP2", "album_artist"}, ++ { "TP3", "performer"}, ++ { "TRK", "track"}, ++ { 0 } ++}; ++ ++ ++const char ff_id3v2_tags[][4] = { ++ "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDLY", "TENC", "TEXT", ++ "TFLT", "TIT1", "TIT2", "TIT3", "TKEY", "TLAN", "TLEN", "TMED", ++ "TOAL", "TOFN", "TOLY", "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", ++ "TPE4", "TPOS", "TPUB", "TRCK", "TRSN", "TRSO", "TSRC", "TSSE", ++ { 0 }, ++}; ++ ++const char ff_id3v2_4_tags[][4] = { ++ "TDEN", "TDOR", "TDRC", "TDRL", "TDTG", "TIPL", "TMCL", "TMOO", ++ "TPRO", "TSOA", "TSOP", "TSOT", "TSST", ++ { 0 }, ++}; ++ ++const char ff_id3v2_3_tags[][4] = { ++ "TDAT", "TIME", "TORY", "TRDA", "TSIZ", "TYER", ++ { 0 }, ++}; + + int ff_id3v2_match(const uint8_t *buf, const char * magic) + { +@@ -50,101 +124,322 @@ + return len; + } + +-static unsigned int get_size(ByteIOContext *s, int len) ++static unsigned int get_size(AVIOContext *s, int len) + { + int v = 0; + while (len--) +- v = (v << 7) + (get_byte(s) & 0x7F); ++ v = (v << 7) + (avio_r8(s) & 0x7F); + return v; + } + +-static void read_ttag(AVFormatContext *s, ByteIOContext *pb, int taglen, const char *key) ++/** ++ * Free GEOB type extra metadata. ++ */ ++static void free_geobtag(void *obj) + { +- char *q, dst[512]; +- const char *val = NULL; +- int len, dstlen = sizeof(dst) - 1; +- unsigned genre; +- unsigned int (*get)(ByteIOContext*) = get_be16; +- +- dst[0] = 0; +- if (taglen < 1) +- return; ++ ID3v2ExtraMetaGEOB *geob = obj; ++ av_free(geob->mime_type); ++ av_free(geob->file_name); ++ av_free(geob->description); ++ av_free(geob->data); ++ av_free(geob); ++} + +- taglen--; /* account for encoding type byte */ ++/** ++ * Decode characters to UTF-8 according to encoding type. The decoded buffer is ++ * always null terminated. Stop reading when either *maxread bytes are read from ++ * pb or U+0000 character is found. ++ * ++ * @param dst Pointer where the address of the buffer with the decoded bytes is ++ * stored. Buffer must be freed by caller. ++ * @param maxread Pointer to maximum number of characters to read from the ++ * AVIOContext. After execution the value is decremented by the number of bytes ++ * actually read. ++ * @returns 0 if no error occurred, dst is uninitialized on error ++ */ ++static int decode_str(AVFormatContext *s, AVIOContext *pb, int encoding, ++ uint8_t **dst, int *maxread) ++{ ++ int ret; ++ uint8_t tmp; ++ uint32_t ch = 1; ++ int left = *maxread; ++ unsigned int (*get)(AVIOContext*) = avio_rb16; ++ AVIOContext *dynbuf; ++ ++ if ((ret = avio_open_dyn_buf(&dynbuf)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Error opening memory stream\n"); ++ return ret; ++ } + +- switch (get_byte(pb)) { /* encoding type */ ++ switch (encoding) { + + case ID3v2_ENCODING_ISO8859: +- q = dst; +- while (taglen-- && q - dst < dstlen - 7) { +- uint8_t tmp; +- PUT_UTF8(get_byte(pb), tmp, *q++ = tmp;) ++ while (left && ch) { ++ ch = avio_r8(pb); ++ PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);) ++ left--; + } +- *q = 0; + break; + + case ID3v2_ENCODING_UTF16BOM: +- taglen -= 2; +- switch (get_be16(pb)) { ++ if ((left -= 2) < 0) { ++ av_log(s, AV_LOG_ERROR, "Cannot read BOM value, input too short\n"); ++ avio_close_dyn_buf(dynbuf, dst); ++ av_freep(dst); ++ return AVERROR_INVALIDDATA; ++ } ++ switch (avio_rb16(pb)) { + case 0xfffe: +- get = get_le16; ++ get = avio_rl16; + case 0xfeff: + break; + default: +- av_log(s, AV_LOG_ERROR, "Incorrect BOM value in tag %s.\n", key); +- return; ++ av_log(s, AV_LOG_ERROR, "Incorrect BOM value\n"); ++ avio_close_dyn_buf(dynbuf, dst); ++ av_freep(dst); ++ *maxread = left; ++ return AVERROR_INVALIDDATA; + } + // fall-through + + case ID3v2_ENCODING_UTF16BE: +- q = dst; +- while (taglen > 1 && q - dst < dstlen - 7) { +- uint32_t ch; +- uint8_t tmp; +- +- GET_UTF16(ch, ((taglen -= 2) >= 0 ? get(pb) : 0), break;) +- PUT_UTF8(ch, tmp, *q++ = tmp;) ++ while ((left > 1) && ch) { ++ GET_UTF16(ch, ((left -= 2) >= 0 ? get(pb) : 0), break;) ++ PUT_UTF8(ch, tmp, avio_w8(dynbuf, tmp);) + } +- *q = 0; ++ if (left < 0) ++ left += 2; /* did not read last char from pb */ + break; + + case ID3v2_ENCODING_UTF8: +- len = FFMIN(taglen, dstlen); +- get_buffer(pb, dst, len); +- dst[len] = 0; ++ while (left && ch) { ++ ch = avio_r8(pb); ++ avio_w8(dynbuf, ch); ++ left--; ++ } + break; + default: +- av_log(s, AV_LOG_WARNING, "Unknown encoding in tag %s\n.", key); ++ av_log(s, AV_LOG_WARNING, "Unknown encoding\n"); ++ } ++ ++ if (ch) ++ avio_w8(dynbuf, 0); ++ ++ avio_close_dyn_buf(dynbuf, dst); ++ *maxread = left; ++ ++ return 0; ++} ++ ++/** ++ * Parse a text tag. ++ */ ++static void read_ttag(AVFormatContext *s, AVIOContext *pb, int taglen, const char *key) ++{ ++ uint8_t *dst; ++ int encoding, dict_flags = AV_DICT_DONT_OVERWRITE; ++ unsigned genre; ++ ++ if (taglen < 1) ++ return; ++ ++ encoding = avio_r8(pb); ++ taglen--; /* account for encoding type byte */ ++ ++ if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { ++ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key); ++ return; + } + + if (!(strcmp(key, "TCON") && strcmp(key, "TCO")) + && (sscanf(dst, "(%d)", &genre) == 1 || sscanf(dst, "%d", &genre) == 1) +- && genre <= ID3v1_GENRE_MAX) +- val = ff_id3v1_genre_str[genre]; +- else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { +- /* dst now contains two 0-terminated strings */ +- dst[dstlen] = 0; +- len = strlen(dst); ++ && genre <= ID3v1_GENRE_MAX) { ++ av_freep(&dst); ++ dst = ff_id3v1_genre_str[genre]; ++ } else if (!(strcmp(key, "TXXX") && strcmp(key, "TXX"))) { ++ /* dst now contains the key, need to get value */ + key = dst; +- val = dst + FFMIN(len + 1, dstlen); ++ if (decode_str(s, pb, encoding, &dst, &taglen) < 0) { ++ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", key); ++ av_freep(&key); ++ return; ++ } ++ dict_flags |= AV_DICT_DONT_STRDUP_VAL | AV_DICT_DONT_STRDUP_KEY; + } + else if (*dst) +- val = dst; ++ dict_flags |= AV_DICT_DONT_STRDUP_VAL; ++ ++ if (dst) ++ av_dict_set(&s->metadata, key, dst, dict_flags); ++} ++ ++/** ++ * Parse GEOB tag into a ID3v2ExtraMetaGEOB struct. ++ */ ++static void read_geobtag(AVFormatContext *s, AVIOContext *pb, int taglen, char *tag, ID3v2ExtraMeta **extra_meta) ++{ ++ ID3v2ExtraMetaGEOB *geob_data = NULL; ++ ID3v2ExtraMeta *new_extra = NULL; ++ char encoding; ++ unsigned int len; ++ ++ if (taglen < 1) ++ return; ++ ++ geob_data = av_mallocz(sizeof(ID3v2ExtraMetaGEOB)); ++ if (!geob_data) { ++ av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMetaGEOB)); ++ return; ++ } ++ ++ new_extra = av_mallocz(sizeof(ID3v2ExtraMeta)); ++ if (!new_extra) { ++ av_log(s, AV_LOG_ERROR, "Failed to alloc %zu bytes\n", sizeof(ID3v2ExtraMeta)); ++ goto fail; ++ } + +- if (val) +- av_metadata_set2(&s->metadata, key, val, AV_METADATA_DONT_OVERWRITE); ++ /* read encoding type byte */ ++ encoding = avio_r8(pb); ++ taglen--; ++ ++ /* read MIME type (always ISO-8859) */ ++ if (decode_str(s, pb, ID3v2_ENCODING_ISO8859, &geob_data->mime_type, &taglen) < 0 ++ || taglen <= 0) ++ goto fail; ++ ++ /* read file name */ ++ if (decode_str(s, pb, encoding, &geob_data->file_name, &taglen) < 0 ++ || taglen <= 0) ++ goto fail; ++ ++ /* read content description */ ++ if (decode_str(s, pb, encoding, &geob_data->description, &taglen) < 0 ++ || taglen < 0) ++ goto fail; ++ ++ if (taglen) { ++ /* save encapsulated binary data */ ++ geob_data->data = av_malloc(taglen); ++ if (!geob_data->data) { ++ av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", taglen); ++ goto fail; ++ } ++ if ((len = avio_read(pb, geob_data->data, taglen)) < taglen) ++ av_log(s, AV_LOG_WARNING, "Error reading GEOB frame, data truncated.\n"); ++ geob_data->datasize = len; ++ } else { ++ geob_data->data = NULL; ++ geob_data->datasize = 0; ++ } ++ ++ /* add data to the list */ ++ new_extra->tag = "GEOB"; ++ new_extra->data = geob_data; ++ new_extra->next = *extra_meta; ++ *extra_meta = new_extra; ++ ++ return; ++ ++fail: ++ av_log(s, AV_LOG_ERROR, "Error reading frame %s, skipped\n", tag); ++ free_geobtag(geob_data); ++ av_free(new_extra); ++ return; ++} ++ ++static int is_number(const char *str) ++{ ++ while (*str >= '0' && *str <= '9') str++; ++ return !*str; ++} ++ ++static AVDictionaryEntry* get_date_tag(AVDictionary *m, const char *tag) ++{ ++ AVDictionaryEntry *t; ++ if ((t = av_dict_get(m, tag, NULL, AV_DICT_MATCH_CASE)) && ++ strlen(t->value) == 4 && is_number(t->value)) ++ return t; ++ return NULL; ++} ++ ++static void merge_date(AVDictionary **m) ++{ ++ AVDictionaryEntry *t; ++ char date[17] = {0}; // YYYY-MM-DD hh:mm ++ ++ if (!(t = get_date_tag(*m, "TYER")) && ++ !(t = get_date_tag(*m, "TYE"))) ++ return; ++ av_strlcpy(date, t->value, 5); ++ av_dict_set(m, "TYER", NULL, 0); ++ av_dict_set(m, "TYE", NULL, 0); ++ ++ if (!(t = get_date_tag(*m, "TDAT")) && ++ !(t = get_date_tag(*m, "TDA"))) ++ goto finish; ++ snprintf(date + 4, sizeof(date) - 4, "-%.2s-%.2s", t->value + 2, t->value); ++ av_dict_set(m, "TDAT", NULL, 0); ++ av_dict_set(m, "TDA", NULL, 0); ++ ++ if (!(t = get_date_tag(*m, "TIME")) && ++ !(t = get_date_tag(*m, "TIM"))) ++ goto finish; ++ snprintf(date + 10, sizeof(date) - 10, " %.2s:%.2s", t->value, t->value + 2); ++ av_dict_set(m, "TIME", NULL, 0); ++ av_dict_set(m, "TIM", NULL, 0); ++ ++finish: ++ if (date[0]) ++ av_dict_set(m, "date", date, 0); ++} ++ ++typedef struct ID3v2EMFunc { ++ const char *tag3; ++ const char *tag4; ++ void (*read)(AVFormatContext*, AVIOContext*, int, char*, ID3v2ExtraMeta **); ++ void (*free)(void *obj); ++} ID3v2EMFunc; ++ ++static const ID3v2EMFunc id3v2_extra_meta_funcs[] = { ++ { "GEO", "GEOB", read_geobtag, free_geobtag }, ++ { NULL } ++}; ++ ++/** ++ * Get the corresponding ID3v2EMFunc struct for a tag. ++ * @param isv34 Determines if v2.2 or v2.3/4 strings are used ++ * @return A pointer to the ID3v2EMFunc struct if found, NULL otherwise. ++ */ ++static const ID3v2EMFunc *get_extra_meta_func(const char *tag, int isv34) ++{ ++ int i = 0; ++ while (id3v2_extra_meta_funcs[i].tag3) { ++ if (tag && !memcmp(tag, ++ (isv34 ? id3v2_extra_meta_funcs[i].tag4 : ++ id3v2_extra_meta_funcs[i].tag3), ++ (isv34 ? 4 : 3))) ++ return &id3v2_extra_meta_funcs[i]; ++ i++; ++ } ++ return NULL; + } + +-static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags) ++static void ff_id3v2_parse(AVFormatContext *s, int len, uint8_t version, uint8_t flags, ID3v2ExtraMeta **extra_meta) + { +- int isv34, tlen, unsync; ++ int isv34, unsync; ++ unsigned tlen; + char tag[5]; +- int64_t next; ++ int64_t next, end = avio_tell(s->pb) + len; + int taghdrlen; +- const char *reason; +- ByteIOContext pb; ++ const char *reason = NULL; ++ AVIOContext pb; ++ AVIOContext *pbx; + unsigned char *buffer = NULL; + int buffer_size = 0; ++ const ID3v2EMFunc *extra_func = NULL; ++ unsigned char *compressed_buffer = NULL; ++ int compressed_buffer_size = 0; + + switch (version) { + case 2: +@@ -169,86 +464,163 @@ + + unsync = flags & 0x80; + +- if (isv34 && flags & 0x40) /* Extended header present, just skip over it */ +- url_fskip(s->pb, get_size(s->pb, 4)); ++ /* Extended header present, just skip over it */ ++ if (isv34 && flags & 0x40) { ++ int size = get_size(s->pb, 4); ++ if (size < 6) { ++ reason = "extended header too short."; ++ goto error; ++ } ++ len -= size; ++ if (len < 0) { ++ reason = "extended header too long."; ++ goto error; ++ } ++ /* already seeked past size, skip the reset */ ++ size -= 4; ++ avio_skip(s->pb, size); ++ } + + while (len >= taghdrlen) { +- unsigned int tflags; ++ unsigned int tflags = 0; + int tunsync = 0; ++ int tcomp = 0; ++ int tencr = 0; ++ unsigned long dlen; + + if (isv34) { +- get_buffer(s->pb, tag, 4); ++ avio_read(s->pb, tag, 4); + tag[4] = 0; + if(version==3){ +- tlen = get_be32(s->pb); ++ tlen = avio_rb32(s->pb); + }else + tlen = get_size(s->pb, 4); +- tflags = get_be16(s->pb); ++ tflags = avio_rb16(s->pb); + tunsync = tflags & ID3v2_FLAG_UNSYNCH; + } else { +- get_buffer(s->pb, tag, 3); ++ avio_read(s->pb, tag, 3); + tag[3] = 0; +- tlen = get_be24(s->pb); ++ tlen = avio_rb24(s->pb); + } ++ if (tlen > (1<<28)) ++ break; + len -= taghdrlen + tlen; + + if (len < 0) + break; + +- next = url_ftell(s->pb) + tlen; ++ next = avio_tell(s->pb) + tlen; ++ ++ if (!tlen) { ++ if (tag[0]) ++ av_log(s, AV_LOG_DEBUG, "Invalid empty frame %s, skipping.\n", tag); ++ continue; ++ } + + if (tflags & ID3v2_FLAG_DATALEN) { +- get_be32(s->pb); ++ if (tlen < 4) ++ break; ++ dlen = avio_rb32(s->pb); + tlen -= 4; +- } ++ } else ++ dlen = tlen; ++ ++ tcomp = tflags & ID3v2_FLAG_COMPRESSION; ++ tencr = tflags & ID3v2_FLAG_ENCRYPTION; + +- if (tflags & (ID3v2_FLAG_ENCRYPTION | ID3v2_FLAG_COMPRESSION)) { +- av_log(s, AV_LOG_WARNING, "Skipping encrypted/compressed ID3v2 frame %s.\n", tag); +- url_fskip(s->pb, tlen); +- } else if (tag[0] == 'T') { +- if (unsync || tunsync) { ++ /* skip encrypted tags and, if no zlib, compressed tags */ ++ if (tencr || (!CONFIG_ZLIB && tcomp)) { ++ const char *type; ++ if (!tcomp) ++ type = "encrypted"; ++ else if (!tencr) ++ type = "compressed"; ++ else ++ type = "encrypted and compressed"; ++ ++ av_log(s, AV_LOG_WARNING, "Skipping %s ID3v2 frame %s.\n", type, tag); ++ avio_skip(s->pb, tlen); ++ /* check for text tag or supported special meta tag */ ++ } else if (tag[0] == 'T' || (extra_meta && (extra_func = get_extra_meta_func(tag, isv34)))) { ++ if (unsync || tunsync || tcomp) { + int i, j; +- av_fast_malloc(&buffer, &buffer_size, tlen); +- for (i = 0, j = 0; i < tlen; i++, j++) { +- buffer[j] = get_byte(s->pb); ++ ++ av_fast_malloc(&buffer, &buffer_size, dlen); ++ if (!buffer) { ++ av_log(s, AV_LOG_ERROR, "Failed to alloc %ld bytes\n", dlen); ++ goto seek; ++ } ++#if CONFIG_ZLIB ++ if (tcomp) { ++ int n, err; ++ ++ av_log(s, AV_LOG_DEBUG, "Compresssed frame %s tlen=%d dlen=%ld\n", tag, tlen, dlen); ++ ++ av_fast_malloc(&compressed_buffer, &compressed_buffer_size, tlen); ++ if (!compressed_buffer) { ++ av_log(s, AV_LOG_ERROR, "Failed to alloc %d bytes\n", tlen); ++ goto seek; ++ } ++ ++ n = avio_read(s->pb, compressed_buffer, tlen); ++ if (n < 0) { ++ av_log(s, AV_LOG_ERROR, "Failed to read compressed tag\n"); ++ goto seek; ++ } ++ ++ err = uncompress(buffer, &dlen, compressed_buffer, n); ++ if (err != Z_OK) { ++ av_log(s, AV_LOG_ERROR, "Failed to uncompress tag: %d\n", err); ++ goto seek; ++ } ++ } ++#endif ++ ++ for (i = 0, j = 0; i < dlen; i++, j++) { ++ if (!tcomp) ++ buffer[j] = avio_r8(s->pb); + if (j > 0 && !buffer[j] && buffer[j - 1] == 0xff) { + /* Unsynchronised byte, skip it */ + j--; + } + } +- init_put_byte(&pb, buffer, j, 0, NULL, NULL, NULL, NULL); +- read_ttag(s, &pb, j, tag); ++ ffio_init_context(&pb, buffer, j, 0, NULL, NULL, NULL, NULL); ++ tlen = j; ++ pbx = &pb; // read from sync buffer + } else { +- read_ttag(s, s->pb, tlen, tag); ++ pbx = s->pb; // read straight from input + } ++ if (tag[0] == 'T') ++ /* parse text tag */ ++ read_ttag(s, pbx, tlen, tag); ++ else ++ /* parse special meta tag */ ++ extra_func->read(s, pbx, tlen, tag, extra_meta); + } + else if (!tag[0]) { + if (tag[1]) + av_log(s, AV_LOG_WARNING, "invalid frame id, assuming padding"); +- url_fskip(s->pb, tlen); ++ avio_skip(s->pb, tlen); + break; + } + /* Skip to end of tag */ +- url_fseek(s->pb, next, SEEK_SET); ++seek: ++ avio_seek(s->pb, next, SEEK_SET); + } + +- if (len > 0) { +- /* Skip padding */ +- url_fskip(s->pb, len); +- } + if (version == 4 && flags & 0x10) /* Footer preset, always 10 bytes, skip over it */ +- url_fskip(s->pb, 10); +- +- av_free(buffer); +- return; ++ end += 10; + + error: +- av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); +- url_fskip(s->pb, len); ++ if (reason) ++ av_log(s, AV_LOG_INFO, "ID3v2.%d tag skipped, cannot handle %s\n", version, reason); ++ avio_seek(s->pb, end, SEEK_SET); + av_free(buffer); ++ av_free(compressed_buffer); ++ return; + } + +-void ff_id3v2_read(AVFormatContext *s, const char *magic) ++void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta) + { + int len, ret; + uint8_t buf[ID3v2_HEADER_SIZE]; +@@ -257,8 +629,8 @@ + + do { + /* save the current offset in case there's nothing to read/skip */ +- off = url_ftell(s->pb); +- ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE); ++ off = avio_tell(s->pb); ++ ret = avio_read(s->pb, buf, ID3v2_HEADER_SIZE); + if (ret != ID3v2_HEADER_SIZE) + break; + found_header = ff_id3v2_match(buf, magic); +@@ -268,72 +640,32 @@ + ((buf[7] & 0x7f) << 14) | + ((buf[8] & 0x7f) << 7) | + (buf[9] & 0x7f); +- ff_id3v2_parse(s, len, buf[3], buf[5]); ++ ff_id3v2_parse(s, len, buf[3], buf[5], extra_meta); + } else { +- url_fseek(s->pb, off, SEEK_SET); ++ avio_seek(s->pb, off, SEEK_SET); + } + } while (found_header); + ff_metadata_conv(&s->metadata, NULL, ff_id3v2_34_metadata_conv); +- ff_metadata_conv(&s->metadata, NULL, ff_id3v2_2_metadata_conv); ++ ff_metadata_conv(&s->metadata, NULL, id3v2_2_metadata_conv); + ff_metadata_conv(&s->metadata, NULL, ff_id3v2_4_metadata_conv); ++ merge_date(&s->metadata); + } + +-const AVMetadataConv ff_id3v2_34_metadata_conv[] = { +- { "TALB", "album"}, +- { "TCOM", "composer"}, +- { "TCON", "genre"}, +- { "TCOP", "copyright"}, +- { "TENC", "encoded_by"}, +- { "TIT2", "title"}, +- { "TLAN", "language"}, +- { "TPE1", "artist"}, +- { "TPE2", "album_artist"}, +- { "TPE3", "performer"}, +- { "TPOS", "disc"}, +- { "TPUB", "publisher"}, +- { "TRCK", "track"}, +- { "TSSE", "encoder"}, +- { 0 } +-}; +- +-const AVMetadataConv ff_id3v2_4_metadata_conv[] = { +- { "TDRL", "date"}, +- { "TDRC", "date"}, +- { "TDEN", "creation_time"}, +- { "TSOA", "album-sort"}, +- { "TSOP", "artist-sort"}, +- { "TSOT", "title-sort"}, +- { 0 } +-}; +- +-const AVMetadataConv ff_id3v2_2_metadata_conv[] = { +- { "TAL", "album"}, +- { "TCO", "genre"}, +- { "TT2", "title"}, +- { "TEN", "encoded_by"}, +- { "TP1", "artist"}, +- { "TP2", "album_artist"}, +- { "TP3", "performer"}, +- { "TRK", "track"}, +- { 0 } +-}; +- +- +-const char ff_id3v2_tags[][4] = { +- "TALB", "TBPM", "TCOM", "TCON", "TCOP", "TDLY", "TENC", "TEXT", +- "TFLT", "TIT1", "TIT2", "TIT3", "TKEY", "TLAN", "TLEN", "TMED", +- "TOAL", "TOFN", "TOLY", "TOPE", "TOWN", "TPE1", "TPE2", "TPE3", +- "TPE4", "TPOS", "TPUB", "TRCK", "TRSN", "TRSO", "TSRC", "TSSE", +- { 0 }, +-}; ++void ff_id3v2_read(AVFormatContext *s, const char *magic) ++{ ++ ff_id3v2_read_all(s, magic, NULL); ++} + +-const char ff_id3v2_4_tags[][4] = { +- "TDEN", "TDOR", "TDRC", "TDRL", "TDTG", "TIPL", "TMCL", "TMOO", +- "TPRO", "TSOA", "TSOP", "TSOT", "TSST", +- { 0 }, +-}; ++void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta) ++{ ++ ID3v2ExtraMeta *current = *extra_meta, *next; ++ const ID3v2EMFunc *extra_func; + +-const char ff_id3v2_3_tags[][4] = { +- "TDAT", "TIME", "TORY", "TRDA", "TSIZ", "TYER", +- { 0 }, +-}; ++ while (current) { ++ if ((extra_func = get_extra_meta_func(current->tag, 1))) ++ extra_func->free(current->data); ++ next = current->next; ++ av_freep(¤t); ++ current = next; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2enc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2enc.c 2012-05-14 14:08:54.980352984 +0200 +@@ -0,0 +1,186 @@ ++/* ++ * ID3v2 header writer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "libavutil/avstring.h" ++#include "libavutil/dict.h" ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "avio.h" ++#include "id3v2.h" ++ ++static void id3v2_put_size(AVFormatContext *s, int size) ++{ ++ avio_w8(s->pb, size >> 21 & 0x7f); ++ avio_w8(s->pb, size >> 14 & 0x7f); ++ avio_w8(s->pb, size >> 7 & 0x7f); ++ avio_w8(s->pb, size & 0x7f); ++} ++ ++static int string_is_ascii(const uint8_t *str) ++{ ++ while (*str && *str < 128) str++; ++ return !*str; ++} ++ ++/** ++ * Write a text frame with one (normal frames) or two (TXXX frames) strings ++ * according to encoding (only UTF-8 or UTF-16+BOM supported). ++ * @return number of bytes written or a negative error code. ++ */ ++static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2, ++ uint32_t tag, enum ID3v2Encoding enc) ++{ ++ int len; ++ uint8_t *pb; ++ int (*put)(AVIOContext*, const char*); ++ AVIOContext *dyn_buf; ++ if (avio_open_dyn_buf(&dyn_buf) < 0) ++ return AVERROR(ENOMEM); ++ ++ /* check if the strings are ASCII-only and use UTF16 only if ++ * they're not */ ++ if (enc == ID3v2_ENCODING_UTF16BOM && string_is_ascii(str1) && ++ (!str2 || string_is_ascii(str2))) ++ enc = ID3v2_ENCODING_ISO8859; ++ ++ avio_w8(dyn_buf, enc); ++ if (enc == ID3v2_ENCODING_UTF16BOM) { ++ avio_wl16(dyn_buf, 0xFEFF); /* BOM */ ++ put = avio_put_str16le; ++ } else ++ put = avio_put_str; ++ ++ put(dyn_buf, str1); ++ if (str2) ++ put(dyn_buf, str2); ++ len = avio_close_dyn_buf(dyn_buf, &pb); ++ ++ avio_wb32(s->pb, tag); ++ id3v2_put_size(s, len); ++ avio_wb16(s->pb, 0); ++ avio_write(s->pb, pb, len); ++ ++ av_freep(&pb); ++ return len + ID3v2_HEADER_SIZE; ++} ++ ++static int id3v2_check_write_tag(AVFormatContext *s, AVDictionaryEntry *t, const char table[][4], ++ enum ID3v2Encoding enc) ++{ ++ uint32_t tag; ++ int i; ++ ++ if (t->key[0] != 'T' || strlen(t->key) != 4) ++ return -1; ++ tag = AV_RB32(t->key); ++ for (i = 0; *table[i]; i++) ++ if (tag == AV_RB32(table[i])) ++ return id3v2_put_ttag(s, t->value, NULL, tag, enc); ++ return -1; ++} ++ ++static void id3v2_3_metadata_split_date(AVDictionary **pm) ++{ ++ AVDictionaryEntry *mtag = NULL; ++ AVDictionary *dst = NULL; ++ const char *key, *value; ++ char year[5] = {0}, day_month[5] = {0}; ++ int i; ++ ++ while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) { ++ key = mtag->key; ++ if (!av_strcasecmp(key, "date")) { ++ /* split date tag using "YYYY-MM-DD" format into year and month/day segments */ ++ value = mtag->value; ++ i = 0; ++ while (value[i] >= '0' && value[i] <= '9') i++; ++ if (value[i] == '\0' || value[i] == '-') { ++ av_strlcpy(year, value, sizeof(year)); ++ av_dict_set(&dst, "TYER", year, 0); ++ ++ if (value[i] == '-' && ++ value[i+1] >= '0' && value[i+1] <= '1' && ++ value[i+2] >= '0' && value[i+2] <= '9' && ++ value[i+3] == '-' && ++ value[i+4] >= '0' && value[i+4] <= '3' && ++ value[i+5] >= '0' && value[i+5] <= '9' && ++ (value[i+6] == '\0' || value[i+6] == ' ')) { ++ snprintf(day_month, sizeof(day_month), "%.2s%.2s", value + i + 4, value + i + 1); ++ av_dict_set(&dst, "TDAT", day_month, 0); ++ } ++ } else ++ av_dict_set(&dst, key, value, 0); ++ } else ++ av_dict_set(&dst, key, mtag->value, 0); ++ } ++ av_dict_free(pm); ++ *pm = dst; ++} ++ ++int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, ++ const char *magic) ++{ ++ int64_t size_pos, cur_pos; ++ AVDictionaryEntry *t = NULL; ++ ++ int totlen = 0, enc = id3v2_version == 3 ? ID3v2_ENCODING_UTF16BOM : ++ ID3v2_ENCODING_UTF8; ++ ++ ++ avio_wb32(s->pb, MKBETAG(magic[0], magic[1], magic[2], id3v2_version)); ++ avio_w8(s->pb, 0); ++ avio_w8(s->pb, 0); /* flags */ ++ ++ /* reserve space for size */ ++ size_pos = avio_tell(s->pb); ++ avio_wb32(s->pb, 0); ++ ++ ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL); ++ if (id3v2_version == 3) ++ id3v2_3_metadata_split_date(&s->metadata); ++ else if (id3v2_version == 4) ++ ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL); ++ ++ while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { ++ int ret; ++ ++ if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) { ++ totlen += ret; ++ continue; ++ } ++ if ((ret = id3v2_check_write_tag(s, t, id3v2_version == 3 ? ++ ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) { ++ totlen += ret; ++ continue; ++ } ++ ++ /* unknown tag, write as TXXX frame */ ++ if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0) ++ return ret; ++ totlen += ret; ++ } ++ ++ cur_pos = avio_tell(s->pb); ++ avio_seek(s->pb, size_pos, SEEK_SET); ++ id3v2_put_size(s, totlen); ++ avio_seek(s->pb, cur_pos, SEEK_SET); ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/id3v2.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/id3v2.h 2012-05-14 14:08:54.979352964 +0200 +@@ -45,10 +45,24 @@ + ID3v2_ENCODING_UTF8 = 3, + }; + ++typedef struct ID3v2ExtraMeta { ++ const char *tag; ++ void *data; ++ struct ID3v2ExtraMeta *next; ++} ID3v2ExtraMeta; ++ ++typedef struct ID3v2ExtraMetaGEOB { ++ uint32_t datasize; ++ uint8_t *mime_type; ++ uint8_t *file_name; ++ uint8_t *description; ++ uint8_t *data; ++} ID3v2ExtraMetaGEOB; ++ + /** + * Detect ID3v2 Header. + * @param buf must be ID3v2_HEADER_SIZE byte long +- * @param magic magic bytes to identify the header, machine byte order. ++ * @param magic magic bytes to identify the header. + * If in doubt, use ID3v2_DEFAULT_MAGIC. + */ + int ff_id3v2_match(const uint8_t *buf, const char *magic); +@@ -61,13 +75,33 @@ + int ff_id3v2_tag_len(const uint8_t *buf); + + /** +- * Read an ID3v2 tag ++ * Read an ID3v2 tag (text tags only) + */ + void ff_id3v2_read(AVFormatContext *s, const char *magic); + ++/** ++ * Read an ID3v2 tag, including supported extra metadata (currently only GEOB) ++ * @param extra_meta If not NULL, extra metadata is parsed into a list of ++ * ID3v2ExtraMeta structs and *extra_meta points to the head of the list ++ */ ++void ff_id3v2_read_all(AVFormatContext *s, const char *magic, ID3v2ExtraMeta **extra_meta); ++ ++/** ++ * Write an ID3v2 tag. ++ * @param id3v2_version Subversion of ID3v2; supported values are 3 and 4 ++ * @param magic magic bytes to identify the header ++ * If in doubt, use ID3v2_DEFAULT_MAGIC. ++ */ ++int ff_id3v2_write(struct AVFormatContext *s, int id3v2_version, const char *magic); ++ ++/** ++ * Free memory allocated parsing special (non-text) metadata. ++ * @param extra_meta Pointer to a pointer to the head of a ID3v2ExtraMeta list, *extra_meta is set to NULL. ++ */ ++void ff_id3v2_free_extra_meta(ID3v2ExtraMeta **extra_meta); ++ + extern const AVMetadataConv ff_id3v2_34_metadata_conv[]; + extern const AVMetadataConv ff_id3v2_4_metadata_conv[]; +-extern const AVMetadataConv ff_id3v2_2_metadata_conv[]; + + /** + * A list of text information frames allowed in both ID3 v2.3 and v2.4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idcin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idcin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idcin.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idcin.c 2012-05-14 14:08:54.981353004 +0200 +@@ -70,6 +70,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define HUFFMAN_TABLE_SIZE (64 * 1024) + #define IDCIN_FPS 14 +@@ -86,8 +87,6 @@ + int audio_present; + + int64_t pts; +- +- AVPaletteControl palctrl; + } IdcinDemuxContext; + + static int idcin_probe(AVProbeData *p) +@@ -142,23 +141,23 @@ + static int idcin_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + IdcinDemuxContext *idcin = s->priv_data; + AVStream *st; + unsigned int width, height; + unsigned int sample_rate, bytes_per_sample, channels; + + /* get the 5 header parameters */ +- width = get_le32(pb); +- height = get_le32(pb); +- sample_rate = get_le32(pb); +- bytes_per_sample = get_le32(pb); +- channels = get_le32(pb); ++ width = avio_rl32(pb); ++ height = avio_rl32(pb); ++ sample_rate = avio_rl32(pb); ++ bytes_per_sample = avio_rl32(pb); ++ channels = avio_rl32(pb); + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, IDCIN_FPS); ++ avpriv_set_pts_info(st, 33, 1, IDCIN_FPS); + idcin->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_IDCIN; +@@ -169,19 +168,17 @@ + /* load up the Huffman tables into extradata */ + st->codec->extradata_size = HUFFMAN_TABLE_SIZE; + st->codec->extradata = av_malloc(HUFFMAN_TABLE_SIZE); +- if (get_buffer(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) != ++ if (avio_read(pb, st->codec->extradata, HUFFMAN_TABLE_SIZE) != + HUFFMAN_TABLE_SIZE) + return AVERROR(EIO); +- /* save a reference in order to transport the palette */ +- st->codec->palctrl = &idcin->palctrl; + + /* if sample rate is 0, assume no audio */ + if (sample_rate) { + idcin->audio_present = 1; +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, IDCIN_FPS); ++ avpriv_set_pts_info(st, 33, 1, IDCIN_FPS); + idcin->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_tag = 1; +@@ -221,23 +218,23 @@ + unsigned int command; + unsigned int chunk_size; + IdcinDemuxContext *idcin = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i; + int palette_scale; + unsigned char r, g, b; + unsigned char palette_buffer[768]; ++ uint32_t palette[256]; + + if (url_feof(s->pb)) + return AVERROR(EIO); + + if (idcin->next_chunk_is_video) { +- command = get_le32(pb); ++ command = avio_rl32(pb); + if (command == 2) { + return AVERROR(EIO); + } else if (command == 1) { + /* trigger a palette change */ +- idcin->palctrl.palette_changed = 1; +- if (get_buffer(pb, palette_buffer, 768) != 768) ++ if (avio_read(pb, palette_buffer, 768) != 768) + return AVERROR(EIO); + /* scale the palette as necessary */ + palette_scale = 2; +@@ -251,17 +248,28 @@ + r = palette_buffer[i * 3 ] << palette_scale; + g = palette_buffer[i * 3 + 1] << palette_scale; + b = palette_buffer[i * 3 + 2] << palette_scale; +- idcin->palctrl.palette[i] = (r << 16) | (g << 8) | (b); ++ palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b); ++ if (palette_scale == 2) ++ palette[i] |= palette[i] >> 6 & 0x30303; + } + } + +- chunk_size = get_le32(pb); ++ chunk_size = avio_rl32(pb); + /* skip the number of decoded bytes (always equal to width * height) */ +- url_fseek(pb, 4, SEEK_CUR); ++ avio_skip(pb, 4); + chunk_size -= 4; + ret= av_get_packet(pb, pkt, chunk_size); + if (ret < 0) + return ret; ++ if (command == 1) { ++ uint8_t *pal; ++ ++ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, ++ AVPALETTE_SIZE); ++ if (!pal) ++ return AVERROR(ENOMEM); ++ memcpy(pal, palette, AVPALETTE_SIZE); ++ } + pkt->stream_index = idcin->video_stream_index; + pkt->pts = idcin->pts; + } else { +@@ -287,10 +295,10 @@ + } + + AVInputFormat ff_idcin_demuxer = { +- "idcin", +- NULL_IF_CONFIG_SMALL("id Cinematic format"), +- sizeof(IdcinDemuxContext), +- idcin_probe, +- idcin_read_header, +- idcin_read_packet, ++ .name = "idcin", ++ .long_name = NULL_IF_CONFIG_SMALL("id Cinematic format"), ++ .priv_data_size = sizeof(IdcinDemuxContext), ++ .read_probe = idcin_probe, ++ .read_header = idcin_read_header, ++ .read_packet = idcin_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idroqdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idroqdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idroqdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idroqdec.c 2012-05-14 14:08:54.982353024 +0200 +@@ -29,6 +29,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + #define RoQ_MAGIC_NUMBER 0x1084 + #define RoQ_CHUNK_PREAMBLE_SIZE 8 +@@ -43,6 +45,7 @@ + + typedef struct RoqDemuxContext { + ++ int frame_rate; + int width; + int height; + int audio_channels; +@@ -68,30 +71,22 @@ + AVFormatParameters *ap) + { + RoqDemuxContext *roq = s->priv_data; +- ByteIOContext *pb = s->pb; +- int framerate; +- AVStream *st; ++ AVIOContext *pb = s->pb; + unsigned char preamble[RoQ_CHUNK_PREAMBLE_SIZE]; + + /* get the main header */ +- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != ++ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != + RoQ_CHUNK_PREAMBLE_SIZE) + return AVERROR(EIO); +- framerate = AV_RL16(&preamble[6]); ++ roq->frame_rate = AV_RL16(&preamble[6]); + + /* init private context parameters */ + roq->width = roq->height = roq->audio_channels = roq->video_pts = + roq->audio_frame_count = 0; + roq->audio_stream_index = -1; ++ roq->video_stream_index = -1; + +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 63, 1, framerate); +- roq->video_stream_index = st->index; +- st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_id = CODEC_ID_ROQ; +- st->codec->codec_tag = 0; /* no fourcc */ ++ s->ctx_flags |= AVFMTCTX_NOHEADER; + + return 0; + } +@@ -100,7 +95,7 @@ + AVPacket *pkt) + { + RoqDemuxContext *roq = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret = 0; + unsigned int chunk_size; + unsigned int chunk_type; +@@ -115,7 +110,7 @@ + return AVERROR(EIO); + + /* get the next chunk preamble */ +- if ((ret = get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) != ++ if ((ret = avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE)) != + RoQ_CHUNK_PREAMBLE_SIZE) + return AVERROR(EIO); + +@@ -124,34 +119,44 @@ + if(chunk_size > INT_MAX) + return AVERROR_INVALIDDATA; + ++ chunk_size = ffio_limit(pb, chunk_size); ++ + switch (chunk_type) { + + case RoQ_INFO: +- if (!roq->width || !roq->height) { +- AVStream *st = s->streams[roq->video_stream_index]; +- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) ++ if (roq->video_stream_index == -1) { ++ AVStream *st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ avpriv_set_pts_info(st, 63, 1, roq->frame_rate); ++ roq->video_stream_index = st->index; ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_ROQ; ++ st->codec->codec_tag = 0; /* no fourcc */ ++ ++ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != RoQ_CHUNK_PREAMBLE_SIZE) + return AVERROR(EIO); + st->codec->width = roq->width = AV_RL16(preamble); + st->codec->height = roq->height = AV_RL16(preamble + 2); + break; + } + /* don't care about this chunk anymore */ +- url_fseek(pb, RoQ_CHUNK_PREAMBLE_SIZE, SEEK_CUR); ++ avio_skip(pb, RoQ_CHUNK_PREAMBLE_SIZE); + break; + + case RoQ_QUAD_CODEBOOK: + /* packet needs to contain both this codebook and next VQ chunk */ +- codebook_offset = url_ftell(pb) - RoQ_CHUNK_PREAMBLE_SIZE; ++ codebook_offset = avio_tell(pb) - RoQ_CHUNK_PREAMBLE_SIZE; + codebook_size = chunk_size; +- url_fseek(pb, codebook_size, SEEK_CUR); +- if (get_buffer(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != ++ avio_skip(pb, codebook_size); ++ if (avio_read(pb, preamble, RoQ_CHUNK_PREAMBLE_SIZE) != + RoQ_CHUNK_PREAMBLE_SIZE) + return AVERROR(EIO); + chunk_size = AV_RL32(&preamble[2]) + RoQ_CHUNK_PREAMBLE_SIZE * 2 + + codebook_size; + + /* rewind */ +- url_fseek(pb, codebook_offset, SEEK_SET); ++ avio_seek(pb, codebook_offset, SEEK_SET); + + /* load up the packet */ + ret= av_get_packet(pb, pkt, chunk_size); +@@ -166,10 +171,10 @@ + case RoQ_SOUND_MONO: + case RoQ_SOUND_STEREO: + if (roq->audio_stream_index == -1) { +- AVStream *st = av_new_stream(s, 1); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); ++ avpriv_set_pts_info(st, 32, 1, RoQ_AUDIO_SAMPLE_RATE); + roq->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ROQ_DPCM; +@@ -197,8 +202,8 @@ + roq->audio_frame_count += (chunk_size / roq->audio_channels); + } + +- pkt->pos= url_ftell(pb); +- ret = get_buffer(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, ++ pkt->pos= avio_tell(pb); ++ ret = avio_read(pb, pkt->data + RoQ_CHUNK_PREAMBLE_SIZE, + chunk_size); + if (ret != chunk_size) + ret = AVERROR(EIO); +@@ -209,7 +214,6 @@ + default: + av_log(s, AV_LOG_ERROR, " unknown RoQ chunk (%04X)\n", chunk_type); + return AVERROR_INVALIDDATA; +- break; + } + } + +@@ -217,10 +221,10 @@ + } + + AVInputFormat ff_roq_demuxer = { +- "RoQ", +- NULL_IF_CONFIG_SMALL("id RoQ format"), +- sizeof(RoqDemuxContext), +- roq_probe, +- roq_read_header, +- roq_read_packet, ++ .name = "RoQ", ++ .long_name = NULL_IF_CONFIG_SMALL("id RoQ format"), ++ .priv_data_size = sizeof(RoqDemuxContext), ++ .read_probe = roq_probe, ++ .read_header = roq_read_header, ++ .read_packet = roq_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idroqenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idroqenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/idroqenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/idroqenc.c 2012-05-14 14:08:54.983353044 +0200 +@@ -29,21 +29,18 @@ + 0x84, 0x10, 0xFF, 0xFF, 0xFF, 0xFF, 0x1E, 0x00 + }; + +- put_buffer(s->pb, header, 8); +- put_flush_packet(s->pb); ++ avio_write(s->pb, header, 8); ++ avio_flush(s->pb); + + return 0; + } + +-AVOutputFormat ff_roq_muxer = +-{ +- "RoQ", +- NULL_IF_CONFIG_SMALL("raw id RoQ format"), +- NULL, +- "roq", +- 0, +- CODEC_ID_ROQ_DPCM, +- CODEC_ID_ROQ, +- roq_write_header, +- ff_raw_write_packet, ++AVOutputFormat ff_roq_muxer = { ++ .name = "RoQ", ++ .long_name = NULL_IF_CONFIG_SMALL("raw id RoQ format"), ++ .extensions = "roq", ++ .audio_codec = CODEC_ID_ROQ_DPCM, ++ .video_codec = CODEC_ID_ROQ, ++ .write_header = roq_write_header, ++ .write_packet = ff_raw_write_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iff.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iff.c 2012-05-14 14:08:54.985353084 +0200 +@@ -1,5 +1,4 @@ + /* +- * IFF (.iff) file demuxer + * Copyright (c) 2008 Jaikrishnan Menon + * Copyright (c) 2010 Peter Ross + * Copyright (c) 2010 Sebastian Vater +@@ -29,8 +28,11 @@ + * http://wiki.multimedia.cx/index.php?title=IFF + */ + ++#include "libavcodec/bytestream.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + + #define ID_8SVX MKTAG('8','S','V','X') + #define ID_VHDR MKTAG('V','H','D','R') +@@ -40,7 +42,9 @@ + #define ID_PBM MKTAG('P','B','M',' ') + #define ID_ILBM MKTAG('I','L','B','M') + #define ID_BMHD MKTAG('B','M','H','D') ++#define ID_CAMG MKTAG('C','A','M','G') + #define ID_CMAP MKTAG('C','M','A','P') ++#define ID_ACBM MKTAG('A','C','B','M') + + #define ID_FORM MKTAG('F','O','R','M') + #define ID_ANNO MKTAG('A','N','N','O') +@@ -51,6 +55,7 @@ + #define ID_FVER MKTAG('F','V','E','R') + #define ID_NAME MKTAG('N','A','M','E') + #define ID_TEXT MKTAG('T','E','X','T') ++#define ID_ABIT MKTAG('A','B','I','T') + #define ID_BODY MKTAG('B','O','D','Y') + #define ID_ANNO MKTAG('A','N','N','O') + +@@ -58,7 +63,15 @@ + #define RIGHT 4 + #define STEREO 6 + +-#define PACKET_SIZE 1024 ++/** ++ * This number of bytes if added at the beginning of each AVPacket ++ * which contain additional information about video properties ++ * which has to be shared between demuxer and decoder. ++ * This number may change between frames, e.g. the demuxer might ++ * set it to smallest possible size of 2 to indicate that there's ++ * no extradata changing in this frame. ++ */ ++#define IFF_EXTRA_VIDEO_SIZE 9 + + typedef enum { + COMP_NONE, +@@ -75,22 +88,15 @@ + uint64_t body_pos; + uint32_t body_size; + uint32_t sent_bytes; +- uint32_t audio_frame_count; ++ svx8_compression_type svx8_compression; ++ bitmap_compression_type bitmap_compression; ///< delta compression method used ++ unsigned bpp; ///< bits per plane to decode (differs from bits_per_coded_sample if HAM) ++ unsigned ham; ///< 0 if non-HAM or number of hold bits (6 for bpp > 6, 4 otherwise) ++ unsigned flags; ///< 1 for EHB, 0 is no extra half darkening ++ unsigned transparency; ///< transparency color index in palette ++ unsigned masking; ///< masking method used + } IffDemuxContext; + +- +-static void interleave_stereo(const uint8_t *src, uint8_t *dest, int size) +-{ +- uint8_t *end = dest + size; +- size = size>>1; +- +- while(dest < end) { +- *dest++ = *src; +- *dest++ = *(src+size); +- src++; +- } +-} +- + /* Metadata string read */ + static int get_metadata(AVFormatContext *s, + const char *const tag, +@@ -101,12 +107,12 @@ + if (!buf) + return AVERROR(ENOMEM); + +- if (get_buffer(s->pb, buf, data_size) < 0) { ++ if (avio_read(s->pb, buf, data_size) < 0) { + av_free(buf); + return AVERROR(EIO); + } + buf[data_size] = 0; +- av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&s->metadata, tag, buf, AV_DICT_DONT_STRDUP_VAL); + return 0; + } + +@@ -115,7 +121,7 @@ + const uint8_t *d = p->buf; + + if ( AV_RL32(d) == ID_FORM && +- (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM) ) ++ (AV_RL32(d+8) == ID_8SVX || AV_RL32(d+8) == ID_PBM || AV_RL32(d+8) == ID_ILBM || AV_RL32(d+8) == ID_ACBM) ) + return AVPROBE_SCORE_MAX; + return 0; + } +@@ -124,27 +130,30 @@ + AVFormatParameters *ap) + { + IffDemuxContext *iff = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; ++ uint8_t *buf; + uint32_t chunk_id, data_size; +- int compression = -1; ++ uint32_t screenmode = 0; ++ unsigned transparency = 0; ++ unsigned masking = 0; // no mask + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->channels = 1; +- url_fskip(pb, 8); ++ avio_skip(pb, 8); + // codec_tag used by ByteRun1 decoder to distinguish progressive (PBM) and interlaced (ILBM) content +- st->codec->codec_tag = get_le32(pb); ++ st->codec->codec_tag = avio_rl32(pb); + + while(!url_feof(pb)) { + uint64_t orig_pos; + int res; + const char *metadata_tag = NULL; +- chunk_id = get_le32(pb); +- data_size = get_be32(pb); +- orig_pos = url_ftell(pb); ++ chunk_id = avio_rl32(pb); ++ data_size = avio_rb32(pb); ++ orig_pos = avio_tell(pb); + + switch(chunk_id) { + case ID_VHDR: +@@ -152,69 +161,69 @@ + + if (data_size < 14) + return AVERROR_INVALIDDATA; +- url_fskip(pb, 12); +- st->codec->sample_rate = get_be16(pb); ++ avio_skip(pb, 12); ++ st->codec->sample_rate = avio_rb16(pb); + if (data_size >= 16) { +- url_fskip(pb, 1); +- compression = get_byte(pb); ++ avio_skip(pb, 1); ++ iff->svx8_compression = avio_r8(pb); + } + break; + ++ case ID_ABIT: + case ID_BODY: +- iff->body_pos = url_ftell(pb); ++ iff->body_pos = avio_tell(pb); + iff->body_size = data_size; + break; + + case ID_CHAN: + if (data_size < 4) + return AVERROR_INVALIDDATA; +- st->codec->channels = (get_be32(pb) < 6) ? 1 : 2; ++ st->codec->channels = (avio_rb32(pb) < 6) ? 1 : 2; ++ break; ++ ++ case ID_CAMG: ++ if (data_size < 4) ++ return AVERROR_INVALIDDATA; ++ screenmode = avio_rb32(pb); + break; + + case ID_CMAP: +- st->codec->extradata_size = data_size; +- st->codec->extradata = av_malloc(data_size); ++ st->codec->extradata_size = data_size + IFF_EXTRA_VIDEO_SIZE; ++ st->codec->extradata = av_malloc(data_size + IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); +- if (get_buffer(pb, st->codec->extradata, data_size) < 0) ++ if (avio_read(pb, st->codec->extradata + IFF_EXTRA_VIDEO_SIZE, data_size) < 0) + return AVERROR(EIO); + break; + + case ID_BMHD: ++ iff->bitmap_compression = -1; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + if (data_size <= 8) + return AVERROR_INVALIDDATA; +- st->codec->width = get_be16(pb); +- st->codec->height = get_be16(pb); +- url_fskip(pb, 4); // x, y offset +- st->codec->bits_per_coded_sample = get_byte(pb); +- if (data_size >= 11) { +- url_fskip(pb, 1); // masking +- compression = get_byte(pb); ++ st->codec->width = avio_rb16(pb); ++ st->codec->height = avio_rb16(pb); ++ avio_skip(pb, 4); // x, y offset ++ st->codec->bits_per_coded_sample = avio_r8(pb); ++ if (data_size >= 10) ++ masking = avio_r8(pb); ++ if (data_size >= 11) ++ iff->bitmap_compression = avio_r8(pb); ++ if (data_size >= 14) { ++ avio_skip(pb, 1); // padding ++ transparency = avio_rb16(pb); + } + if (data_size >= 16) { +- url_fskip(pb, 3); // paddding, transparent +- st->sample_aspect_ratio.num = get_byte(pb); +- st->sample_aspect_ratio.den = get_byte(pb); ++ st->sample_aspect_ratio.num = avio_r8(pb); ++ st->sample_aspect_ratio.den = avio_r8(pb); + } + break; + + case ID_ANNO: +- case ID_TEXT: +- metadata_tag = "comment"; +- break; +- +- case ID_AUTH: +- metadata_tag = "artist"; +- break; +- +- case ID_COPYRIGHT: +- metadata_tag = "copyright"; +- break; +- +- case ID_NAME: +- metadata_tag = "title"; +- break; ++ case ID_TEXT: metadata_tag = "comment"; break; ++ case ID_AUTH: metadata_tag = "artist"; break; ++ case ID_COPYRIGHT: metadata_tag = "copyright"; break; ++ case ID_NAME: metadata_tag = "title"; break; + } + + if (metadata_tag) { +@@ -223,18 +232,18 @@ + return res; + } + } +- url_fskip(pb, data_size - (url_ftell(pb) - orig_pos) + (data_size & 1)); ++ avio_skip(pb, data_size - (avio_tell(pb) - orig_pos) + (data_size & 1)); + } + +- url_fseek(pb, iff->body_pos, SEEK_SET); ++ avio_seek(pb, iff->body_pos, SEEK_SET); + + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: +- av_set_pts_info(st, 32, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + +- switch(compression) { ++ switch (iff->svx8_compression) { + case COMP_NONE: +- st->codec->codec_id = CODEC_ID_PCM_S8; ++ st->codec->codec_id = CODEC_ID_PCM_S8_PLANAR; + break; + case COMP_FIB: + st->codec->codec_id = CODEC_ID_8SVX_FIB; +@@ -243,17 +252,42 @@ + st->codec->codec_id = CODEC_ID_8SVX_EXP; + break; + default: +- av_log(s, AV_LOG_ERROR, "unknown compression method\n"); ++ av_log(s, AV_LOG_ERROR, ++ "Unknown SVX8 compression method '%d'\n", iff->svx8_compression); + return -1; + } + +- st->codec->bits_per_coded_sample = 8; ++ st->codec->bits_per_coded_sample = iff->svx8_compression == COMP_NONE ? 8 : 4; + st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * st->codec->bits_per_coded_sample; + st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; + break; + + case AVMEDIA_TYPE_VIDEO: +- switch (compression) { ++ iff->bpp = st->codec->bits_per_coded_sample; ++ if ((screenmode & 0x800 /* Hold And Modify */) && iff->bpp <= 8) { ++ iff->ham = iff->bpp > 6 ? 6 : 4; ++ st->codec->bits_per_coded_sample = 24; ++ } ++ iff->flags = (screenmode & 0x80 /* Extra HalfBrite */) && iff->bpp <= 8; ++ iff->masking = masking; ++ iff->transparency = transparency; ++ ++ if (!st->codec->extradata) { ++ st->codec->extradata_size = IFF_EXTRA_VIDEO_SIZE; ++ st->codec->extradata = av_malloc(IFF_EXTRA_VIDEO_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ } ++ buf = st->codec->extradata; ++ bytestream_put_be16(&buf, IFF_EXTRA_VIDEO_SIZE); ++ bytestream_put_byte(&buf, iff->bitmap_compression); ++ bytestream_put_byte(&buf, iff->bpp); ++ bytestream_put_byte(&buf, iff->ham); ++ bytestream_put_byte(&buf, iff->flags); ++ bytestream_put_be16(&buf, iff->transparency); ++ bytestream_put_byte(&buf, iff->masking); ++ ++ switch (iff->bitmap_compression) { + case BITMAP_RAW: + st->codec->codec_id = CODEC_ID_IFF_ILBM; + break; +@@ -261,7 +295,8 @@ + st->codec->codec_id = CODEC_ID_IFF_BYTERUN1; + break; + default: +- av_log(s, AV_LOG_ERROR, "unknown compression method\n"); ++ av_log(s, AV_LOG_ERROR, ++ "Unknown bitmap compression method '%d'\n", iff->bitmap_compression); + return AVERROR_INVALIDDATA; + } + break; +@@ -276,49 +311,42 @@ + AVPacket *pkt) + { + IffDemuxContext *iff = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[0]; + int ret; + + if(iff->sent_bytes >= iff->body_size) +- return AVERROR(EIO); ++ return AVERROR_EOF; + +- if(st->codec->channels == 2) { +- uint8_t sample_buffer[PACKET_SIZE]; ++ if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { ++ ret = av_get_packet(pb, pkt, iff->body_size); ++ } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ uint8_t *buf; + +- ret = get_buffer(pb, sample_buffer, PACKET_SIZE); +- if(av_new_packet(pkt, PACKET_SIZE) < 0) { +- av_log(s, AV_LOG_ERROR, "cannot allocate packet\n"); ++ if (av_new_packet(pkt, iff->body_size + 2) < 0) { + return AVERROR(ENOMEM); + } +- interleave_stereo(sample_buffer, pkt->data, PACKET_SIZE); +- } else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- ret = av_get_packet(pb, pkt, iff->body_size); ++ ++ buf = pkt->data; ++ bytestream_put_be16(&buf, 2); ++ ret = avio_read(pb, buf, iff->body_size); + } else { +- ret = av_get_packet(pb, pkt, PACKET_SIZE); ++ av_abort(); + } + + if(iff->sent_bytes == 0) + pkt->flags |= AV_PKT_FLAG_KEY; ++ iff->sent_bytes = iff->body_size; + +- if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- iff->sent_bytes += PACKET_SIZE; +- } else { +- iff->sent_bytes = iff->body_size; +- } + pkt->stream_index = 0; +- if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- pkt->pts = iff->audio_frame_count; +- iff->audio_frame_count += ret / st->codec->channels; +- } + return ret; + } + + AVInputFormat ff_iff_demuxer = { +- "IFF", +- NULL_IF_CONFIG_SMALL("IFF format"), +- sizeof(IffDemuxContext), +- iff_probe, +- iff_read_header, +- iff_read_packet, ++ .name = "IFF", ++ .long_name = NULL_IF_CONFIG_SMALL("IFF format"), ++ .priv_data_size = sizeof(IffDemuxContext), ++ .read_probe = iff_probe, ++ .read_header = iff_read_header, ++ .read_packet = iff_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/img2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/img2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/img2.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/img2.c 2012-05-14 14:08:54.987353124 +0200 +@@ -22,16 +22,28 @@ + + #include "libavutil/intreadwrite.h" + #include "libavutil/avstring.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/pixdesc.h" ++#include "libavutil/parseutils.h" + #include "avformat.h" +-#include ++#include "avio_internal.h" ++#include "internal.h" + + typedef struct { ++ const AVClass *class; /**< Class for private options. */ + int img_first; + int img_last; + int img_number; + int img_count; + int is_pipe; ++ int split_planes; /**< use independent file for each Y, U, V plane */ + char path[1024]; ++ char *pixel_format; /**< Set by a private option. */ ++ char *video_size; /**< Set by a private option. */ ++ char *framerate; /**< Set by a private option. */ ++ int loop; ++ int updatefirst; + } VideoData; + + typedef struct { +@@ -43,6 +55,7 @@ + { CODEC_ID_MJPEG , "jpeg"}, + { CODEC_ID_MJPEG , "jpg"}, + { CODEC_ID_LJPEG , "ljpg"}, ++ { CODEC_ID_JPEGLS , "jls"}, + { CODEC_ID_PNG , "png"}, + { CODEC_ID_PNG , "mng"}, + { CODEC_ID_PPM , "ppm"}, +@@ -56,6 +69,7 @@ + { CODEC_ID_MPEG4 , "mpg4-img"}, + { CODEC_ID_FFV1 , "ffv1-img"}, + { CODEC_ID_RAWVIDEO , "y"}, ++ { CODEC_ID_RAWVIDEO , "raw"}, + { CODEC_ID_BMP , "bmp"}, + { CODEC_ID_GIF , "gif"}, + { CODEC_ID_TARGA , "tga"}, +@@ -71,9 +85,13 @@ + { CODEC_ID_SUNRAST , "im8"}, + { CODEC_ID_SUNRAST , "im24"}, + { CODEC_ID_SUNRAST , "sunras"}, ++ { CODEC_ID_JPEG2000 , "j2c"}, ++ { CODEC_ID_JPEG2000 , "j2k"}, + { CODEC_ID_JPEG2000 , "jp2"}, ++ { CODEC_ID_JPEG2000 , "jpc"}, + { CODEC_ID_DPX , "dpx"}, + { CODEC_ID_PICTOR , "pic"}, ++ { CODEC_ID_XWD , "xwd"}, + { CODEC_ID_NONE , NULL} + }; + +@@ -109,7 +127,7 @@ + str++; + + while (tags->id) { +- if (!strcasecmp(str, tags->str)) ++ if (!av_strcasecmp(str, tags->str)) + return tags->id; + + tags++; +@@ -129,11 +147,11 @@ + if (av_get_frame_filename(buf, sizeof(buf), path, first_index) < 0){ + *pfirst_index = + *plast_index = 1; +- if(url_exist(buf)) ++ if (avio_check(buf, AVIO_FLAG_READ) > 0) + return 0; + return -1; + } +- if (url_exist(buf)) ++ if (avio_check(buf, AVIO_FLAG_READ) > 0) + break; + } + if (first_index == 5) +@@ -151,7 +169,7 @@ + if (av_get_frame_filename(buf, sizeof(buf), path, + last_index + range1) < 0) + goto fail; +- if (!url_exist(buf)) ++ if (avio_check(buf, AVIO_FLAG_READ) <= 0) + break; + range = range1; + /* just in case... */ +@@ -182,23 +200,51 @@ + return 0; + } + ++enum CodecID ff_guess_image2_codec(const char *filename) ++{ ++ return av_str2id(img_tags, filename); ++} ++ ++#if FF_API_GUESS_IMG2_CODEC + enum CodecID av_guess_image2_codec(const char *filename){ + return av_str2id(img_tags, filename); + } ++#endif + + static int read_header(AVFormatContext *s1, AVFormatParameters *ap) + { + VideoData *s = s1->priv_data; +- int first_index, last_index; ++ int first_index, last_index, ret = 0; ++ int width = 0, height = 0; + AVStream *st; ++ enum PixelFormat pix_fmt = PIX_FMT_NONE; ++ AVRational framerate; + + s1->ctx_flags |= AVFMTCTX_NOHEADER; + +- st = av_new_stream(s1, 0); ++ st = avformat_new_stream(s1, NULL); + if (!st) { + return AVERROR(ENOMEM); + } + ++ if (s->pixel_format && (pix_fmt = av_get_pix_fmt(s->pixel_format)) == PIX_FMT_NONE) { ++ av_log(s1, AV_LOG_ERROR, "No such pixel format: %s.\n", s->pixel_format); ++ return AVERROR(EINVAL); ++ } ++ if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Could not parse video size: %s.\n", s->video_size); ++ return ret; ++ } ++ if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); ++ return ret; ++ } ++ ++#if FF_API_LOOP_INPUT ++ if (s1->loop_input) ++ s->loop = s1->loop_input; ++#endif ++ + av_strlcpy(s->path, s1->filename, sizeof(s->path)); + s->img_number = 0; + s->img_count = 0; +@@ -211,15 +257,11 @@ + st->need_parsing = AVSTREAM_PARSE_FULL; + } + +- if (!ap->time_base.num) { +- av_set_pts_info(st, 60, 1, 25); +- } else { +- av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); +- } ++ avpriv_set_pts_info(st, 60, framerate.den, framerate.num); + +- if(ap->width && ap->height){ +- st->codec->width = ap->width; +- st->codec->height= ap->height; ++ if (width && height) { ++ st->codec->width = width; ++ st->codec->height = height; + } + + if (!s->is_pipe) { +@@ -240,11 +282,15 @@ + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = s1->audio_codec_id; + }else{ ++ const char *str= strrchr(s->path, '.'); ++ s->split_planes = str && !av_strcasecmp(str + 1, "y"); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = av_str2id(img_tags, s->path); ++ if (st->codec->codec_id == CODEC_ID_LJPEG) ++ st->codec->codec_id = CODEC_ID_MJPEG; + } +- if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && ap->pix_fmt != PIX_FMT_NONE) +- st->codec->pix_fmt = ap->pix_fmt; ++ if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO && pix_fmt != PIX_FMT_NONE) ++ st->codec->pix_fmt = pix_fmt; + + return 0; + } +@@ -255,12 +301,12 @@ + char filename[1024]; + int i; + int size[3]={0}, ret[3]={0}; +- ByteIOContext *f[3]; ++ AVIOContext *f[3]; + AVCodecContext *codec= s1->streams[0]->codec; + + if (!s->is_pipe) { + /* loop over input */ +- if (s1->loop_input && s->img_number > s->img_last) { ++ if (s->loop && s->img_number > s->img_last) { + s->img_number = s->img_first; + } + if (s->img_number > s->img_last) +@@ -269,15 +315,16 @@ + s->path, s->img_number)<0 && s->img_number > 1) + return AVERROR(EIO); + for(i=0; i<3; i++){ +- if (url_fopen(&f[i], filename, URL_RDONLY) < 0) { ++ if (avio_open2(&f[i], filename, AVIO_FLAG_READ, ++ &s1->interrupt_callback, NULL) < 0) { + if(i==1) + break; + av_log(s1, AV_LOG_ERROR, "Could not open file : %s\n",filename); + return AVERROR(EIO); + } +- size[i]= url_fsize(f[i]); ++ size[i]= avio_size(f[i]); + +- if(codec->codec_id != CODEC_ID_RAWVIDEO) ++ if(!s->split_planes) + break; + filename[ strlen(filename) - 1 ]= 'U' + i; + } +@@ -298,9 +345,9 @@ + pkt->size= 0; + for(i=0; i<3; i++){ + if(size[i]){ +- ret[i]= get_buffer(f[i], pkt->data + pkt->size, size[i]); ++ ret[i]= avio_read(f[i], pkt->data + pkt->size, size[i]); + if (!s->is_pipe) +- url_fclose(f[i]); ++ avio_close(f[i]); + if(ret[i]>0) + pkt->size += ret[i]; + } +@@ -323,6 +370,7 @@ + static int write_header(AVFormatContext *s) + { + VideoData *img = s->priv_data; ++ const char *str; + + img->img_number = 1; + av_strlcpy(img->path, s->filename, sizeof(img->path)); +@@ -333,32 +381,35 @@ + else + img->is_pipe = 1; + ++ str = strrchr(img->path, '.'); ++ img->split_planes = str && !av_strcasecmp(str + 1, "y"); + return 0; + } + + static int write_packet(AVFormatContext *s, AVPacket *pkt) + { + VideoData *img = s->priv_data; +- ByteIOContext *pb[3]; ++ AVIOContext *pb[3]; + char filename[1024]; + AVCodecContext *codec= s->streams[ pkt->stream_index ]->codec; + int i; + + if (!img->is_pipe) { + if (av_get_frame_filename(filename, sizeof(filename), +- img->path, img->img_number) < 0 && img->img_number>1) { ++ img->path, img->img_number) < 0 && img->img_number>1 && !img->updatefirst) { + av_log(s, AV_LOG_ERROR, + "Could not get frame filename number %d from pattern '%s'\n", + img->img_number, img->path); +- return AVERROR(EIO); ++ return AVERROR(EINVAL); + } + for(i=0; i<3; i++){ +- if (url_fopen(&pb[i], filename, URL_WRONLY) < 0) { ++ if (avio_open2(&pb[i], filename, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL) < 0) { + av_log(s, AV_LOG_ERROR, "Could not open file : %s\n",filename); + return AVERROR(EIO); + } + +- if(codec->codec_id != CODEC_ID_RAWVIDEO) ++ if(!img->split_planes) + break; + filename[ strlen(filename) - 1 ]= 'U' + i; + } +@@ -366,15 +417,15 @@ + pb[0] = s->pb; + } + +- if(codec->codec_id == CODEC_ID_RAWVIDEO){ ++ if(img->split_planes){ + int ysize = codec->width * codec->height; +- put_buffer(pb[0], pkt->data , ysize); +- put_buffer(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); +- put_buffer(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); +- put_flush_packet(pb[1]); +- put_flush_packet(pb[2]); +- url_fclose(pb[1]); +- url_fclose(pb[2]); ++ avio_write(pb[0], pkt->data , ysize); ++ avio_write(pb[1], pkt->data + ysize, (pkt->size - ysize)/2); ++ avio_write(pb[2], pkt->data + ysize +(pkt->size - ysize)/2, (pkt->size - ysize)/2); ++ avio_flush(pb[1]); ++ avio_flush(pb[2]); ++ avio_close(pb[1]); ++ avio_close(pb[2]); + }else{ + if(av_str2id(img_tags, s->filename) == CODEC_ID_JPEG2000){ + AVStream *st = s->streams[0]; +@@ -382,28 +433,30 @@ + AV_RL32(st->codec->extradata+4) == MKTAG('j','p','2','h')){ + if(pkt->size < 8 || AV_RL32(pkt->data+4) != MKTAG('j','p','2','c')) + goto error; +- put_be32(pb[0], 12); +- put_tag (pb[0], "jP "); +- put_be32(pb[0], 0x0D0A870A); // signature +- put_be32(pb[0], 20); +- put_tag (pb[0], "ftyp"); +- put_tag (pb[0], "jp2 "); +- put_be32(pb[0], 0); +- put_tag (pb[0], "jp2 "); +- put_buffer(pb[0], st->codec->extradata, st->codec->extradata_size); ++ avio_wb32(pb[0], 12); ++ ffio_wfourcc(pb[0], "jP "); ++ avio_wb32(pb[0], 0x0D0A870A); // signature ++ avio_wb32(pb[0], 20); ++ ffio_wfourcc(pb[0], "ftyp"); ++ ffio_wfourcc(pb[0], "jp2 "); ++ avio_wb32(pb[0], 0); ++ ffio_wfourcc(pb[0], "jp2 "); ++ avio_write(pb[0], st->codec->extradata, st->codec->extradata_size); ++ }else if(pkt->size >= 8 && AV_RB32(pkt->data) == 0xFF4FFF51){ ++ //jpeg2000 codestream + }else if(pkt->size < 8 || + (!st->codec->extradata_size && + AV_RL32(pkt->data+4) != MKTAG('j','P',' ',' '))){ // signature + error: +- av_log(s, AV_LOG_ERROR, "malformated jpeg2000 codestream\n"); ++ av_log(s, AV_LOG_ERROR, "malformed JPEG 2000 codestream %X\n", AV_RB32(pkt->data)); + return -1; + } + } +- put_buffer(pb[0], pkt->data, pkt->size); ++ avio_write(pb[0], pkt->data, pkt->size); + } +- put_flush_packet(pb[0]); ++ avio_flush(pb[0]); + if (!img->is_pipe) { +- url_fclose(pb[0]); ++ avio_close(pb[0]); + } + + img->img_number++; +@@ -412,8 +465,30 @@ + + #endif /* CONFIG_IMAGE2_MUXER || CONFIG_IMAGE2PIPE_MUXER */ + ++#define OFFSET(x) offsetof(VideoData, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++#define ENC AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "video_size", "", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, ++ { "loop", "", OFFSET(loop), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, DEC }, ++ { NULL }, ++}; ++ ++static const AVOption muxoptions[] = { ++ { "updatefirst", "", OFFSET(updatefirst), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, ENC }, ++ { NULL }, ++}; ++ + /* input */ + #if CONFIG_IMAGE2_DEMUXER ++static const AVClass img2_class = { ++ .class_name = "image2 demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + AVInputFormat ff_image2_demuxer = { + .name = "image2", + .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), +@@ -422,30 +497,45 @@ + .read_header = read_header, + .read_packet = read_packet, + .flags = AVFMT_NOFILE, ++ .priv_class = &img2_class, + }; + #endif + #if CONFIG_IMAGE2PIPE_DEMUXER ++static const AVClass img2pipe_class = { ++ .class_name = "image2pipe demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + AVInputFormat ff_image2pipe_demuxer = { + .name = "image2pipe", + .long_name = NULL_IF_CONFIG_SMALL("piped image2 sequence"), + .priv_data_size = sizeof(VideoData), + .read_header = read_header, + .read_packet = read_packet, ++ .priv_class = &img2pipe_class, + }; + #endif + + /* output */ + #if CONFIG_IMAGE2_MUXER ++static const AVClass img2mux_class = { ++ .class_name = "image2 muxer", ++ .item_name = av_default_item_name, ++ .option = muxoptions, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + AVOutputFormat ff_image2_muxer = { + .name = "image2", + .long_name = NULL_IF_CONFIG_SMALL("image2 sequence"), +- .extensions = "bmp,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," +- "ppm,sgi,tga,tif,tiff,jp2", ++ .extensions = "bmp,dpx,jls,jpeg,jpg,ljpg,pam,pbm,pcx,pgm,pgmyuv,png," ++ "ppm,sgi,tga,tif,tiff,jp2,j2c,xwd", + .priv_data_size = sizeof(VideoData), + .video_codec = CODEC_ID_MJPEG, + .write_header = write_header, + .write_packet = write_packet, +- .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE ++ .flags = AVFMT_NOTIMESTAMPS | AVFMT_NODIMENSIONS | AVFMT_NOFILE, ++ .priv_class = &img2mux_class, + }; + #endif + #if CONFIG_IMAGE2PIPE_MUXER +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ingenientdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ingenientdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ingenientdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ingenientdec.c 2012-05-14 14:08:54.988353144 +0200 +@@ -27,19 +27,19 @@ + { + int ret, size, w, h, unk1, unk2; + +- if (get_le32(s->pb) != MKTAG('M', 'J', 'P', 'G')) ++ if (avio_rl32(s->pb) != MKTAG('M', 'J', 'P', 'G')) + return AVERROR(EIO); // FIXME + +- size = get_le32(s->pb); ++ size = avio_rl32(s->pb); + +- w = get_le16(s->pb); +- h = get_le16(s->pb); ++ w = avio_rl16(s->pb); ++ h = avio_rl16(s->pb); + +- url_fskip(s->pb, 8); // zero + size (padded?) +- url_fskip(s->pb, 2); +- unk1 = get_le16(s->pb); +- unk2 = get_le16(s->pb); +- url_fskip(s->pb, 22); // ASCII timestamp ++ avio_skip(s->pb, 8); // zero + size (padded?) ++ avio_skip(s->pb, 2); ++ unk1 = avio_rl16(s->pb); ++ unk2 = avio_rl16(s->pb); ++ avio_skip(s->pb, 22); // ASCII timestamp + + av_log(s, AV_LOG_DEBUG, "Ingenient packet: size=%d, width=%d, height=%d, unk1=%d unk2=%d\n", + size, w, h, unk1, unk2); +@@ -47,9 +47,9 @@ + if (av_new_packet(pkt, size) < 0) + return AVERROR(ENOMEM); + +- pkt->pos = url_ftell(s->pb); ++ pkt->pos = avio_tell(s->pb); + pkt->stream_index = 0; +- ret = get_buffer(s->pb, pkt->data, size); ++ ret = avio_read(s->pb, pkt->data, size); + if (ret < 0) { + av_free_packet(pkt); + return ret; +@@ -58,14 +58,16 @@ + return ret; + } + ++FF_RAWVIDEO_DEMUXER_CLASS(ingenient) ++ + AVInputFormat ff_ingenient_demuxer = { +- "ingenient", +- NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"), +- 0, +- NULL, +- ff_raw_video_read_header, +- ingenient_read_packet, ++ .name = "ingenient", ++ .long_name = NULL_IF_CONFIG_SMALL("raw Ingenient MJPEG"), ++ .priv_data_size = sizeof(FFRawVideoDemuxerContext), ++ .read_header = ff_raw_video_read_header, ++ .read_packet = ingenient_read_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "cgi", // FIXME + .value = CODEC_ID_MJPEG, ++ .priv_class = &ingenient_demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/internal.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/internal.h 2012-05-14 14:08:54.989353164 +0200 +@@ -26,32 +26,33 @@ + + #define MAX_URL_SIZE 4096 + ++#ifdef DEBUG ++# define hex_dump_debug(class, buf, size) av_hex_dump_log(class, AV_LOG_DEBUG, buf, size) ++#else ++# define hex_dump_debug(class, buf, size) ++#endif ++ + typedef struct AVCodecTag { + enum CodecID id; + unsigned int tag; + } AVCodecTag; + +-void ff_dynarray_add(intptr_t **tab_ptr, int *nb_ptr, intptr_t elem); +- + #ifdef __GNUC__ + #define dynarray_add(tab, nb_ptr, elem)\ + do {\ + __typeof__(tab) _tab = (tab);\ + __typeof__(elem) _elem = (elem);\ + (void)sizeof(**_tab == _elem); /* check that types are compatible */\ +- ff_dynarray_add((intptr_t **)_tab, nb_ptr, (intptr_t)_elem);\ ++ av_dynarray_add(_tab, nb_ptr, _elem);\ + } while(0) + #else + #define dynarray_add(tab, nb_ptr, elem)\ + do {\ +- ff_dynarray_add((intptr_t **)(tab), nb_ptr, (intptr_t)(elem));\ ++ av_dynarray_add((tab), nb_ptr, (elem));\ + } while(0) + #endif + +-time_t mktimegm(struct tm *tm); + struct tm *brktimegm(time_t secs, struct tm *tm); +-const char *small_strptime(const char *p, const char *fmt, +- struct tm *dt); + + char *ff_data_to_hex(char *buf, const uint8_t *src, int size, int lowercase); + +@@ -70,8 +71,9 @@ + /** + * Add packet to AVFormatContext->packet_buffer list, determining its + * interleaved position using compare() function argument. ++ * @return 0, or < 0 on error + */ +-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, ++int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, + int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)); + + void ff_read_frame_flush(AVFormatContext *s); +@@ -82,18 +84,6 @@ + /** Get the current time since NTP epoch in microseconds. */ + uint64_t ff_ntp_time(void); + +-#if FF_API_URL_SPLIT +-/** +- * @deprecated use av_url_split() instead +- */ +-void ff_url_split(char *proto, int proto_size, +- char *authorization, int authorization_size, +- char *hostname, int hostname_size, +- int *port_ptr, +- char *path, int path_size, +- const char *url); +-#endif +- + /** + * Assemble a URL string from components. This is the reverse operation + * of av_url_split. +@@ -117,7 +107,7 @@ + */ + int ff_url_join(char *str, int size, const char *proto, + const char *authorization, const char *hostname, +- int port, const char *fmt, ...); ++ int port, const char *fmt, ...) av_printf_format(7, 8); + + /** + * Append the media-specific SDP fragment for the media stream c +@@ -133,10 +123,12 @@ + * @param dest_type the destination address type, may be NULL + * @param port the destination port of the media stream, 0 if unknown + * @param ttl the time to live of the stream, 0 if not multicast ++ * @param fmt the AVFormatContext, which might contain options modifying ++ * the generated SDP + */ + void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, + const char *dest_addr, const char *dest_type, +- int port, int ttl); ++ int port, int ttl, AVFormatContext *fmt); + + /** + * Write a packet to another muxer than the one the user originally +@@ -160,20 +152,20 @@ + /** + * Put val using a variable number of bytes. + */ +-void ff_put_v(ByteIOContext *bc, uint64_t val); ++void ff_put_v(AVIOContext *bc, uint64_t val); + + /** +- * Read a whole line of text from ByteIOContext. Stop reading after reaching +- * either a \n, a \0 or EOF. The returned string is always \0 terminated, ++ * Read a whole line of text from AVIOContext. Stop reading after reaching ++ * either a \\n, a \\0 or EOF. The returned string is always \\0-terminated, + * and may be truncated if the buffer is too small. + * +- * @param s the read-only ByteIOContext ++ * @param s the read-only AVIOContext + * @param buf buffer to store the read line + * @param maxlen size of the buffer + * @return the length of the string written in the buffer, not including the +- * final \0 ++ * final \\0 + */ +-int ff_get_line(ByteIOContext *s, char *buf, int maxlen); ++int ff_get_line(AVIOContext *s, char *buf, int maxlen); + + #define SPACE_CHARS " \t\r\n" + +@@ -207,4 +199,111 @@ + */ + int ff_find_stream_index(AVFormatContext *s, int id); + ++/** ++ * Internal version of av_index_search_timestamp ++ */ ++int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, ++ int64_t wanted_timestamp, int flags); ++ ++/** ++ * Internal version of av_add_index_entry ++ */ ++int ff_add_index_entry(AVIndexEntry **index_entries, ++ int *nb_index_entries, ++ unsigned int *index_entries_allocated_size, ++ int64_t pos, int64_t timestamp, int size, int distance, int flags); ++ ++/** ++ * Add a new chapter. ++ * ++ * @param s media file handle ++ * @param id unique ID for this chapter ++ * @param start chapter start time in time_base units ++ * @param end chapter end time in time_base units ++ * @param title chapter title ++ * ++ * @return AVChapter or NULL on error ++ */ ++AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, ++ int64_t start, int64_t end, const char *title); ++ ++/** ++ * Ensure the index uses less memory than the maximum specified in ++ * AVFormatContext.max_index_size by discarding entries if it grows ++ * too large. ++ */ ++void ff_reduce_index(AVFormatContext *s, int stream_index); ++ ++/* ++ * Convert a relative url into an absolute url, given a base url. ++ * ++ * @param buf the buffer where output absolute url is written ++ * @param size the size of buf ++ * @param base the base url, may be equal to buf. ++ * @param rel the new url, which is interpreted relative to base ++ */ ++void ff_make_absolute_url(char *buf, int size, const char *base, ++ const char *rel); ++ ++enum CodecID ff_guess_image2_codec(const char *filename); ++ ++/** ++ * Convert a date string in ISO8601 format to Unix timestamp. ++ */ ++int64_t ff_iso8601_to_unix_time(const char *datestr); ++ ++/** ++ * Perform a binary search using av_index_search_timestamp() and ++ * AVInputFormat.read_timestamp(). ++ * ++ * @param target_ts target timestamp in the time base of the given stream ++ * @param stream_index stream number ++ */ ++int ff_seek_frame_binary(AVFormatContext *s, int stream_index, ++ int64_t target_ts, int flags); ++ ++/** ++ * Update cur_dts of all streams based on the given timestamp and AVStream. ++ * ++ * Stream ref_st unchanged, others set cur_dts in their native time base. ++ * Only needed for timestamp wrapping or if (dts not set and pts!=dts). ++ * @param timestamp new dts expressed in time_base of param ref_st ++ * @param ref_st reference stream giving time_base of param timestamp ++ */ ++void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp); ++ ++/** ++ * Perform a binary search using read_timestamp(). ++ * ++ * @param target_ts target timestamp in the time base of the given stream ++ * @param stream_index stream number ++ */ ++int64_t ff_gen_search(AVFormatContext *s, int stream_index, ++ int64_t target_ts, int64_t pos_min, ++ int64_t pos_max, int64_t pos_limit, ++ int64_t ts_min, int64_t ts_max, ++ int flags, int64_t *ts_ret, ++ int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )); ++ ++/** ++ * Set the pts for a given stream. If the new values would be invalid ++ * (<= 0), it leaves the AVStream unchanged. ++ * ++ * @param s stream ++ * @param pts_wrap_bits number of bits effectively used by the pts ++ * (used for wrap control, 33 is the value for MPEG) ++ * @param pts_num numerator to convert to seconds (MPEG: 1) ++ * @param pts_den denominator to convert to seconds (MPEG: 90000) ++ */ ++void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, ++ unsigned int pts_num, unsigned int pts_den); ++ ++/** ++ * Add side data to a packet for changing parameters to the given values. ++ * Parameters set to 0 aren't included in the change. ++ */ ++int ff_add_param_change(AVPacket *pkt, int32_t channels, ++ uint64_t channel_layout, int32_t sample_rate, ++ int32_t width, int32_t height); ++ + #endif /* AVFORMAT_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ipmovie.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ipmovie.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ipmovie.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ipmovie.c 2012-05-14 14:08:54.991353204 +0200 +@@ -34,17 +34,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" +- +-/* debugging support: #define DEBUG_IPMOVIE as non-zero to see extremely +- * verbose information about the demux process */ +-#define DEBUG_IPMOVIE 0 +- +-#if DEBUG_IPMOVIE +-#undef printf +-#define debug_ipmovie printf +-#else +-static inline void debug_ipmovie(const char *format, ...) { } +-#endif ++#include "internal.h" + + #define CHUNK_PREAMBLE_SIZE 4 + #define OPCODE_PREAMBLE_SIZE 4 +@@ -97,6 +87,9 @@ + unsigned int video_width; + unsigned int video_height; + int64_t video_pts; ++ uint32_t palette[256]; ++ int has_palette; ++ int changed; + + unsigned int audio_bits; + unsigned int audio_channels; +@@ -116,16 +109,19 @@ + + int64_t next_chunk_offset; + +- AVPaletteControl palette_control; +- + } IPMVEContext; + +-static int load_ipmovie_packet(IPMVEContext *s, ByteIOContext *pb, ++static int load_ipmovie_packet(IPMVEContext *s, AVIOContext *pb, + AVPacket *pkt) { + + int chunk_type; + +- if (s->audio_chunk_offset) { ++ if (s->audio_chunk_offset && s->audio_channels && s->audio_bits) { ++ if (s->audio_type == CODEC_ID_NONE) { ++ av_log(NULL, AV_LOG_ERROR, "Can not read audio packet before" ++ "audio codec is known\n"); ++ return CHUNK_BAD; ++ } + + /* adjust for PCM audio by skipping chunk header */ + if (s->audio_type != CODEC_ID_INTERPLAY_DPCM) { +@@ -133,7 +129,7 @@ + s->audio_chunk_size -= 6; + } + +- url_fseek(pb, s->audio_chunk_offset, SEEK_SET); ++ avio_seek(pb, s->audio_chunk_offset, SEEK_SET); + s->audio_chunk_offset = 0; + + if (s->audio_chunk_size != av_get_packet(pb, pkt, s->audio_chunk_size)) +@@ -148,10 +144,10 @@ + (s->audio_chunk_size / s->audio_channels / (s->audio_bits / 8)); + else + s->audio_frame_count += +- (s->audio_chunk_size - 6) / s->audio_channels; ++ (s->audio_chunk_size - 6 - s->audio_channels) / s->audio_channels; + +- debug_ipmovie("sending audio frame with pts %"PRId64" (%d audio frames)\n", +- pkt->pts, s->audio_frame_count); ++ av_dlog(NULL, "sending audio frame with pts %"PRId64" (%d audio frames)\n", ++ pkt->pts, s->audio_frame_count); + + chunk_type = CHUNK_VIDEO; + +@@ -162,20 +158,35 @@ + if (av_new_packet(pkt, s->decode_map_chunk_size + s->video_chunk_size)) + return CHUNK_NOMEM; + ++ if (s->has_palette) { ++ uint8_t *pal; ++ ++ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, ++ AVPALETTE_SIZE); ++ if (pal) { ++ memcpy(pal, s->palette, AVPALETTE_SIZE); ++ s->has_palette = 0; ++ } ++ } ++ ++ if (s->changed) { ++ ff_add_param_change(pkt, 0, 0, 0, s->video_width, s->video_height); ++ s->changed = 0; ++ } + pkt->pos= s->decode_map_chunk_offset; +- url_fseek(pb, s->decode_map_chunk_offset, SEEK_SET); ++ avio_seek(pb, s->decode_map_chunk_offset, SEEK_SET); + s->decode_map_chunk_offset = 0; + +- if (get_buffer(pb, pkt->data, s->decode_map_chunk_size) != ++ if (avio_read(pb, pkt->data, s->decode_map_chunk_size) != + s->decode_map_chunk_size) { + av_free_packet(pkt); + return CHUNK_EOF; + } + +- url_fseek(pb, s->video_chunk_offset, SEEK_SET); ++ avio_seek(pb, s->video_chunk_offset, SEEK_SET); + s->video_chunk_offset = 0; + +- if (get_buffer(pb, pkt->data + s->decode_map_chunk_size, ++ if (avio_read(pb, pkt->data + s->decode_map_chunk_size, + s->video_chunk_size) != s->video_chunk_size) { + av_free_packet(pkt); + return CHUNK_EOF; +@@ -184,8 +195,7 @@ + pkt->stream_index = s->video_stream_index; + pkt->pts = s->video_pts; + +- debug_ipmovie("sending video frame with pts %"PRId64"\n", +- pkt->pts); ++ av_dlog(NULL, "sending video frame with pts %"PRId64"\n", pkt->pts); + + s->video_pts += s->frame_pts_inc; + +@@ -193,7 +203,7 @@ + + } else { + +- url_fseek(pb, s->next_chunk_offset, SEEK_SET); ++ avio_seek(pb, s->next_chunk_offset, SEEK_SET); + chunk_type = CHUNK_DONE; + + } +@@ -203,7 +213,7 @@ + + /* This function loads and processes a single chunk in an IP movie file. + * It returns the type of chunk that was processed. */ +-static int process_ipmovie_chunk(IPMVEContext *s, ByteIOContext *pb, ++static int process_ipmovie_chunk(IPMVEContext *s, AVIOContext *pb, + AVPacket *pkt) + { + unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; +@@ -218,6 +228,7 @@ + int first_color, last_color; + int audio_flags; + unsigned char r, g, b; ++ unsigned int width, height; + + /* see if there are any pending packets */ + chunk_type = load_ipmovie_packet(s, pb, pkt); +@@ -227,42 +238,42 @@ + /* read the next chunk, wherever the file happens to be pointing */ + if (url_feof(pb)) + return CHUNK_EOF; +- if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != ++ if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != + CHUNK_PREAMBLE_SIZE) + return CHUNK_BAD; + chunk_size = AV_RL16(&chunk_preamble[0]); + chunk_type = AV_RL16(&chunk_preamble[2]); + +- debug_ipmovie("chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size); ++ av_dlog(NULL, "chunk type 0x%04X, 0x%04X bytes: ", chunk_type, chunk_size); + + switch (chunk_type) { + + case CHUNK_INIT_AUDIO: +- debug_ipmovie("initialize audio\n"); ++ av_dlog(NULL, "initialize audio\n"); + break; + + case CHUNK_AUDIO_ONLY: +- debug_ipmovie("audio only\n"); ++ av_dlog(NULL, "audio only\n"); + break; + + case CHUNK_INIT_VIDEO: +- debug_ipmovie("initialize video\n"); ++ av_dlog(NULL, "initialize video\n"); + break; + + case CHUNK_VIDEO: +- debug_ipmovie("video (and audio)\n"); ++ av_dlog(NULL, "video (and audio)\n"); + break; + + case CHUNK_SHUTDOWN: +- debug_ipmovie("shutdown\n"); ++ av_dlog(NULL, "shutdown\n"); + break; + + case CHUNK_END: +- debug_ipmovie("end\n"); ++ av_dlog(NULL, "end\n"); + break; + + default: +- debug_ipmovie("invalid chunk\n"); ++ av_dlog(NULL, "invalid chunk\n"); + chunk_type = CHUNK_BAD; + break; + +@@ -275,7 +286,7 @@ + chunk_type = CHUNK_EOF; + break; + } +- if (get_buffer(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) != ++ if (avio_read(pb, opcode_preamble, CHUNK_PREAMBLE_SIZE) != + CHUNK_PREAMBLE_SIZE) { + chunk_type = CHUNK_BAD; + break; +@@ -288,50 +299,51 @@ + chunk_size -= OPCODE_PREAMBLE_SIZE; + chunk_size -= opcode_size; + if (chunk_size < 0) { +- debug_ipmovie("chunk_size countdown just went negative\n"); ++ av_dlog(NULL, "chunk_size countdown just went negative\n"); + chunk_type = CHUNK_BAD; + break; + } + +- debug_ipmovie(" opcode type %02X, version %d, 0x%04X bytes: ", +- opcode_type, opcode_version, opcode_size); ++ av_dlog(NULL, " opcode type %02X, version %d, 0x%04X bytes: ", ++ opcode_type, opcode_version, opcode_size); + switch (opcode_type) { + + case OPCODE_END_OF_STREAM: +- debug_ipmovie("end of stream\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "end of stream\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_END_OF_CHUNK: +- debug_ipmovie("end of chunk\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "end of chunk\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_CREATE_TIMER: +- debug_ipmovie("create timer\n"); ++ av_dlog(NULL, "create timer\n"); + if ((opcode_version > 0) || (opcode_size > 6)) { +- debug_ipmovie("bad create_timer opcode\n"); ++ av_dlog(NULL, "bad create_timer opcode\n"); + chunk_type = CHUNK_BAD; + break; + } +- if (get_buffer(pb, scratch, opcode_size) != ++ if (avio_read(pb, scratch, opcode_size) != + opcode_size) { + chunk_type = CHUNK_BAD; + break; + } + s->frame_pts_inc = ((uint64_t)AV_RL32(&scratch[0])) * AV_RL16(&scratch[4]); +- debug_ipmovie(" %.2f frames/second (timer div = %d, subdiv = %d)\n", +- 1000000.0/s->frame_pts_inc, AV_RL32(&scratch[0]), AV_RL16(&scratch[4])); ++ av_dlog(NULL, " %.2f frames/second (timer div = %d, subdiv = %d)\n", ++ 1000000.0 / s->frame_pts_inc, AV_RL32(&scratch[0]), ++ AV_RL16(&scratch[4])); + break; + + case OPCODE_INIT_AUDIO_BUFFERS: +- debug_ipmovie("initialize audio buffers\n"); ++ av_dlog(NULL, "initialize audio buffers\n"); + if ((opcode_version > 1) || (opcode_size > 10)) { +- debug_ipmovie("bad init_audio_buffers opcode\n"); ++ av_dlog(NULL, "bad init_audio_buffers opcode\n"); + chunk_type = CHUNK_BAD; + break; + } +- if (get_buffer(pb, scratch, opcode_size) != ++ if (avio_read(pb, scratch, opcode_size) != + opcode_size) { + chunk_type = CHUNK_BAD; + break; +@@ -349,40 +361,47 @@ + s->audio_type = CODEC_ID_PCM_S16LE; + else + s->audio_type = CODEC_ID_PCM_U8; +- debug_ipmovie("audio: %d bits, %d Hz, %s, %s format\n", +- s->audio_bits, +- s->audio_sample_rate, +- (s->audio_channels == 2) ? "stereo" : "mono", +- (s->audio_type == CODEC_ID_INTERPLAY_DPCM) ? +- "Interplay audio" : "PCM"); ++ av_dlog(NULL, "audio: %d bits, %d Hz, %s, %s format\n", ++ s->audio_bits, s->audio_sample_rate, ++ (s->audio_channels == 2) ? "stereo" : "mono", ++ (s->audio_type == CODEC_ID_INTERPLAY_DPCM) ? ++ "Interplay audio" : "PCM"); + break; + + case OPCODE_START_STOP_AUDIO: +- debug_ipmovie("start/stop audio\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "start/stop audio\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_INIT_VIDEO_BUFFERS: +- debug_ipmovie("initialize video buffers\n"); ++ av_dlog(NULL, "initialize video buffers\n"); + if ((opcode_version > 2) || (opcode_size > 8)) { +- debug_ipmovie("bad init_video_buffers opcode\n"); ++ av_dlog(NULL, "bad init_video_buffers opcode\n"); + chunk_type = CHUNK_BAD; + break; + } +- if (get_buffer(pb, scratch, opcode_size) != ++ if (avio_read(pb, scratch, opcode_size) != + opcode_size) { + chunk_type = CHUNK_BAD; + break; + } +- s->video_width = AV_RL16(&scratch[0]) * 8; +- s->video_height = AV_RL16(&scratch[2]) * 8; ++ width = AV_RL16(&scratch[0]) * 8; ++ height = AV_RL16(&scratch[2]) * 8; ++ if (width != s->video_width) { ++ s->video_width = width; ++ s->changed++; ++ } ++ if (height != s->video_height) { ++ s->video_height = height; ++ s->changed++; ++ } + if (opcode_version < 2 || !AV_RL16(&scratch[6])) { + s->video_bpp = 8; + } else { + s->video_bpp = 16; + } +- debug_ipmovie("video resolution: %d x %d\n", +- s->video_width, s->video_height); ++ av_dlog(NULL, "video resolution: %d x %d\n", ++ s->video_width, s->video_height); + break; + + case OPCODE_UNKNOWN_06: +@@ -392,49 +411,49 @@ + case OPCODE_UNKNOWN_13: + case OPCODE_UNKNOWN_14: + case OPCODE_UNKNOWN_15: +- debug_ipmovie("unknown (but documented) opcode %02X\n", opcode_type); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "unknown (but documented) opcode %02X\n", opcode_type); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_SEND_BUFFER: +- debug_ipmovie("send buffer\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "send buffer\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_AUDIO_FRAME: +- debug_ipmovie("audio frame\n"); ++ av_dlog(NULL, "audio frame\n"); + + /* log position and move on for now */ +- s->audio_chunk_offset = url_ftell(pb); ++ s->audio_chunk_offset = avio_tell(pb); + s->audio_chunk_size = opcode_size; +- url_fseek(pb, opcode_size, SEEK_CUR); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_SILENCE_FRAME: +- debug_ipmovie("silence frame\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "silence frame\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_INIT_VIDEO_MODE: +- debug_ipmovie("initialize video mode\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "initialize video mode\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_CREATE_GRADIENT: +- debug_ipmovie("create gradient\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "create gradient\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_SET_PALETTE: +- debug_ipmovie("set palette\n"); ++ av_dlog(NULL, "set palette\n"); + /* check for the logical maximum palette size + * (3 * 256 + 4 bytes) */ + if (opcode_size > 0x304) { +- debug_ipmovie("demux_ipmovie: set_palette opcode too large\n"); ++ av_dlog(NULL, "demux_ipmovie: set_palette opcode too large\n"); + chunk_type = CHUNK_BAD; + break; + } +- if (get_buffer(pb, scratch, opcode_size) != opcode_size) { ++ if (avio_read(pb, scratch, opcode_size) != opcode_size) { + chunk_type = CHUNK_BAD; + break; + } +@@ -444,7 +463,7 @@ + last_color = first_color + AV_RL16(&scratch[2]) - 1; + /* sanity check (since they are 16 bit values) */ + if ((first_color > 0xFF) || (last_color > 0xFF)) { +- debug_ipmovie("demux_ipmovie: set_palette indexes out of range (%d -> %d)\n", ++ av_dlog(NULL, "demux_ipmovie: set_palette indexes out of range (%d -> %d)\n", + first_color, last_color); + chunk_type = CHUNK_BAD; + break; +@@ -456,37 +475,37 @@ + r = scratch[j++] * 4; + g = scratch[j++] * 4; + b = scratch[j++] * 4; +- s->palette_control.palette[i] = (r << 16) | (g << 8) | (b); ++ s->palette[i] = (0xFFU << 24) | (r << 16) | (g << 8) | (b); ++ s->palette[i] |= s->palette[i] >> 6 & 0x30303; + } +- /* indicate a palette change */ +- s->palette_control.palette_changed = 1; ++ s->has_palette = 1; + break; + + case OPCODE_SET_PALETTE_COMPRESSED: +- debug_ipmovie("set palette compressed\n"); +- url_fseek(pb, opcode_size, SEEK_CUR); ++ av_dlog(NULL, "set palette compressed\n"); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_SET_DECODING_MAP: +- debug_ipmovie("set decoding map\n"); ++ av_dlog(NULL, "set decoding map\n"); + + /* log position and move on for now */ +- s->decode_map_chunk_offset = url_ftell(pb); ++ s->decode_map_chunk_offset = avio_tell(pb); + s->decode_map_chunk_size = opcode_size; +- url_fseek(pb, opcode_size, SEEK_CUR); ++ avio_skip(pb, opcode_size); + break; + + case OPCODE_VIDEO_DATA: +- debug_ipmovie("set video data\n"); ++ av_dlog(NULL, "set video data\n"); + + /* log position and move on for now */ +- s->video_chunk_offset = url_ftell(pb); ++ s->video_chunk_offset = avio_tell(pb); + s->video_chunk_size = opcode_size; +- url_fseek(pb, opcode_size, SEEK_CUR); ++ avio_skip(pb, opcode_size); + break; + + default: +- debug_ipmovie("*** unknown opcode type\n"); ++ av_dlog(NULL, "*** unknown opcode type\n"); + chunk_type = CHUNK_BAD; + break; + +@@ -494,7 +513,7 @@ + } + + /* make a note of where the stream is sitting */ +- s->next_chunk_offset = url_ftell(pb); ++ s->next_chunk_offset = avio_tell(pb); + + /* dispatch the first of any pending packets */ + if ((chunk_type == CHUNK_VIDEO) || (chunk_type == CHUNK_AUDIO_ONLY)) +@@ -521,17 +540,17 @@ + AVFormatParameters *ap) + { + IPMVEContext *ipmovie = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVPacket pkt; + AVStream *st; + unsigned char chunk_preamble[CHUNK_PREAMBLE_SIZE]; +- int chunk_type; ++ int chunk_type, i; + uint8_t signature_buffer[sizeof(signature)]; + +- get_buffer(pb, signature_buffer, sizeof(signature_buffer)); ++ avio_read(pb, signature_buffer, sizeof(signature_buffer)); + while (memcmp(signature_buffer, signature, sizeof(signature))) { + memmove(signature_buffer, signature_buffer + 1, sizeof(signature_buffer) - 1); +- signature_buffer[sizeof(signature_buffer) - 1] = get_byte(pb); ++ signature_buffer[sizeof(signature_buffer) - 1] = avio_r8(pb); + if (url_feof(pb)) + return AVERROR_EOF; + } +@@ -541,7 +560,10 @@ + ipmovie->decode_map_chunk_offset = 0; + + /* on the first read, this will position the stream at the first chunk */ +- ipmovie->next_chunk_offset = url_ftell(pb) + 4; ++ ipmovie->next_chunk_offset = avio_tell(pb) + 4; ++ ++ for (i = 0; i < 256; i++) ++ ipmovie->palette[i] = 0xFFU << 24; + + /* process the first chunk which should be CHUNK_INIT_VIDEO */ + if (process_ipmovie_chunk(ipmovie, pb, &pkt) != CHUNK_INIT_VIDEO) +@@ -549,11 +571,11 @@ + + /* peek ahead to the next chunk-- if it is an init audio chunk, process + * it; if it is the first video chunk, this is a silent file */ +- if (get_buffer(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != ++ if (avio_read(pb, chunk_preamble, CHUNK_PREAMBLE_SIZE) != + CHUNK_PREAMBLE_SIZE) + return AVERROR(EIO); + chunk_type = AV_RL16(&chunk_preamble[2]); +- url_fseek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR); ++ avio_seek(pb, -CHUNK_PREAMBLE_SIZE, SEEK_CUR); + + if (chunk_type == CHUNK_VIDEO) + ipmovie->audio_type = CODEC_ID_NONE; /* no audio */ +@@ -561,10 +583,10 @@ + return AVERROR_INVALIDDATA; + + /* initialize the stream decoders */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 63, 1, 1000000); ++ avpriv_set_pts_info(st, 63, 1, 1000000); + ipmovie->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_INTERPLAY_VIDEO; +@@ -573,14 +595,11 @@ + st->codec->height = ipmovie->video_height; + st->codec->bits_per_coded_sample = ipmovie->video_bpp; + +- /* palette considerations */ +- st->codec->palctrl = &ipmovie->palette_control; +- + if (ipmovie->audio_type) { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); ++ avpriv_set_pts_info(st, 32, 1, ipmovie->audio_sample_rate); + ipmovie->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = ipmovie->audio_type; +@@ -602,9 +621,10 @@ + AVPacket *pkt) + { + IPMVEContext *ipmovie = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret; + ++ for (;;) { + ret = process_ipmovie_chunk(ipmovie, pb, pkt); + if (ret == CHUNK_BAD) + ret = AVERROR_INVALIDDATA; +@@ -614,17 +634,20 @@ + ret = AVERROR(ENOMEM); + else if (ret == CHUNK_VIDEO) + ret = 0; ++ else if (ret == CHUNK_INIT_VIDEO || ret == CHUNK_INIT_AUDIO) ++ continue; + else + ret = -1; + + return ret; ++ } + } + + AVInputFormat ff_ipmovie_demuxer = { +- "ipmovie", +- NULL_IF_CONFIG_SMALL("Interplay MVE format"), +- sizeof(IPMVEContext), +- ipmovie_probe, +- ipmovie_read_header, +- ipmovie_read_packet, ++ .name = "ipmovie", ++ .long_name = NULL_IF_CONFIG_SMALL("Interplay MVE format"), ++ .priv_data_size = sizeof(IPMVEContext), ++ .read_probe = ipmovie_probe, ++ .read_header = ipmovie_read_header, ++ .read_packet = ipmovie_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/isom.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/isom.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/isom.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/isom.c 2012-05-14 14:08:54.994353265 +0200 +@@ -57,9 +57,12 @@ + { CODEC_ID_VC1 , 0xA3 }, + { CODEC_ID_DIRAC , 0xA4 }, + { CODEC_ID_AC3 , 0xA5 }, ++ { CODEC_ID_DTS , 0xA9 }, /* mp4ra.org */ + { CODEC_ID_VORBIS , 0xDD }, /* non standard, gpac uses it */ + { CODEC_ID_DVD_SUBTITLE, 0xE0 }, /* non standard, see unsupported-embedded-subs-2.mp4 */ + { CODEC_ID_QCELP , 0xE1 }, ++ { CODEC_ID_MPEG4SYSTEMS, 0x01 }, ++ { CODEC_ID_MPEG4SYSTEMS, 0x02 }, + { CODEC_ID_NONE , 0 }, + }; + +@@ -81,10 +84,18 @@ + { CODEC_ID_RAWVIDEO, MKTAG('A', 'B', 'G', 'R') }, + { CODEC_ID_RAWVIDEO, MKTAG('b', '1', '6', 'g') }, + { CODEC_ID_RAWVIDEO, MKTAG('b', '4', '8', 'r') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('D', 'V', 'O', 'O') }, /* Digital Voodoo SD 8 Bit */ + + { CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') }, /* UNCOMPRESSED 10BIT RGB */ ++ { CODEC_ID_R10K, MKTAG('R', '1', '0', 'g') }, /* UNCOMPRESSED 10BIT RGB */ + { CODEC_ID_R210, MKTAG('r', '2', '1', '0') }, /* UNCOMPRESSED 10BIT RGB */ ++ { CODEC_ID_AVRP, MKTAG('A', 'V', 'r', 'p') }, /* Avid 1:1 10-bit RGB Packer */ ++ { CODEC_ID_AVRP, MKTAG('S', 'U', 'D', 'S') }, /* Avid DS Uncompressed */ + { CODEC_ID_V210, MKTAG('v', '2', '1', '0') }, /* UNCOMPRESSED 10BIT 4:2:2 */ ++ { CODEC_ID_V308, MKTAG('v', '3', '0', '8') }, /* UNCOMPRESSED 4:4:4 */ ++ { CODEC_ID_V410, MKTAG('v', '4', '1', '0') }, /* UNCOMPRESSED 10BIT 4:4:4 */ ++ { CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') }, /* UNCOMPRESSED 12BIT 4:1:1 */ ++ { CODEC_ID_YUV4, MKTAG('y', 'u', 'v', '4') }, /* libquicktime packed yuv420p */ + + { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */ + { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */ +@@ -134,17 +145,33 @@ + { CODEC_ID_RAWVIDEO, MKTAG('W', 'R', 'A', 'W') }, + + { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, /* AVC-1/H.264 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', 'p') }, /* AVC-Intra 50M 720p24/30/60 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', 'q') }, /* AVC-Intra 50M 720p25/50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', '2') }, /* AVC-Intra 50M 1080p25/50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', '3') }, /* AVC-Intra 50M 1080p24/30/60 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', '5') }, /* AVC-Intra 50M 1080i50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '5', '6') }, /* AVC-Intra 50M 1080i60 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', 'p') }, /* AVC-Intra 100M 720p24/30/60 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', 'q') }, /* AVC-Intra 100M 720p25/50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', '2') }, /* AVC-Intra 100M 1080p25/50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', '3') }, /* AVC-Intra 100M 1080p24/30/60 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', '5') }, /* AVC-Intra 100M 1080i50 */ ++ { CODEC_ID_H264, MKTAG('a', 'i', '1', '6') }, /* AVC-Intra 100M 1080i60 */ + + { CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', '1') }, /* Apple MPEG-1 Camcorder */ + { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */ ++ { CODEC_ID_MPEG1VIDEO, MKTAG('m', '1', 'v', ' ') }, + { CODEC_ID_MPEG2VIDEO, MKTAG('m', '2', 'v', '1') }, /* Apple MPEG-2 Camcorder */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '1') }, /* MPEG2 HDV 720p30 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '2') }, /* MPEG2 HDV 1080i60 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '3') }, /* MPEG2 HDV 1080i50 */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '4') }, /* MPEG2 HDV 720p24 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '5') }, /* MPEG2 HDV 720p25 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '6') }, /* MPEG2 HDV 1080p24 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '7') }, /* MPEG2 HDV 1080p25 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '8') }, /* MPEG2 HDV 1080p30 */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', '9') }, /* MPEG2 HDV 720p60 JVC */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('h', 'd', 'v', 'a') }, /* MPEG2 HDV 720p50 */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'n') }, /* MPEG2 IMX NTSC 525/60 50mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '5', 'p') }, /* MPEG2 IMX PAL 625/50 50mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '4', 'n') }, /* MPEG2 IMX NTSC 525/60 40mb/s produced by FCP */ +@@ -152,6 +179,7 @@ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'n') }, /* MPEG2 IMX NTSC 525/60 30mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'x', '3', 'p') }, /* MPEG2 IMX PAL 625/50 30mb/s produced by FCP */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '4') }, /* XDCAM HD422 720p24 CBR */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '5') }, /* XDCAM HD422 720p25 CBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', '9') }, /* XDCAM HD422 720p60 CBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'a') }, /* XDCAM HD422 720p50 CBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', '5', 'b') }, /* XDCAM HD422 1080i60 CBR */ +@@ -174,6 +202,8 @@ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'd') }, /* XDCAM EX 1080p24 VBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'e') }, /* XDCAM EX 1080p25 VBR */ + { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'v', 'f') }, /* XDCAM EX 1080p30 VBR */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', 'd') }, /* XDCAM HD 540p */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('x', 'd', 'h', '2') }, /* XDCAM HD422 540p */ + { CODEC_ID_MPEG2VIDEO, MKTAG('A', 'V', 'm', 'p') }, /* AVID IMX PAL */ + + { CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, /* JPEG 2000 produced by FCP */ +@@ -188,67 +218,66 @@ + + { CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') }, + { CODEC_ID_DNXHD, MKTAG('A', 'V', 'd', 'n') }, /* AVID DNxHD */ ++// { CODEC_ID_FLV1, MKTAG('H', '2', '6', '3') }, /* Flash Media Server */ ++ { CODEC_ID_MSMPEG4V3, MKTAG('3', 'I', 'V', 'D') }, /* 3ivx DivX Doctor */ + { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', '1', 'x') }, /* AVID 1:1x */ + { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'u', 'p') }, + { CODEC_ID_SGI, MKTAG('s', 'g', 'i', ' ') }, /* SGI */ + { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, /* DPX */ + ++ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'h') }, /* Apple ProRes 422 High Quality */ ++ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'n') }, /* Apple ProRes 422 Standard Definition */ ++ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 's') }, /* Apple ProRes 422 LT */ ++ { CODEC_ID_PRORES, MKTAG('a', 'p', 'c', 'o') }, /* Apple ProRes 422 Proxy */ ++ { CODEC_ID_PRORES, MKTAG('a', 'p', '4', 'h') }, /* Apple ProRes 4444 */ ++ + { CODEC_ID_NONE, 0 }, + }; + + const AVCodecTag codec_movaudio_tags[] = { +- { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, +- { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') }, +- { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, +- { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, +- { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */ +- { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ +- { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, +- { CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') }, +- { CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') }, +- { CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') }, +- { CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') }, +- { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, +- { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ +- { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, /* uncompressed */ +- { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */ +- { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */ +- +- { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */ +- +- { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */ +- { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */ +- +- { CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') }, /* MPEG layer 1 */ +- { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '2') }, /* MPEG layer 2 */ +- +- { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */ +- { CODEC_ID_MP3, 0x6D730055 }, /* MPEG layer 3 */ +- +-/* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ +- +- { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */ +- { CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ +- { CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */ +- { CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* DTS */ +- +- { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ +- { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ +- +- { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, +- { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, /* Apple Lossless */ +- +- { CODEC_ID_QCELP, MKTAG('Q','c','l','p') }, +- { CODEC_ID_QCELP, MKTAG('Q','c','l','q') }, +- { CODEC_ID_QCELP, MKTAG('s','q','c','p') }, /* ISO Media fourcc */ +- +- { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, /* QDM2 */ +- +- { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, +- { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, +- +- { CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, +- ++ { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, ++ { CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ ++ { CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */ ++ { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, ++ { CODEC_ID_ALAC, MKTAG('a', 'l', 'a', 'c') }, ++ { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ ++ { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ ++ { CODEC_ID_DTS, MKTAG('d', 't', 's', 'c') }, /* mp4ra.org */ ++ { CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* non-standard */ ++ { CODEC_ID_DVAUDIO, MKTAG('v', 'd', 'v', 'a') }, ++ { CODEC_ID_DVAUDIO, MKTAG('d', 'v', 'c', 'a') }, ++ { CODEC_ID_EAC3, MKTAG('e', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ ++ { CODEC_ID_GSM, MKTAG('a', 'g', 's', 'm') }, ++ { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, ++ { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, ++ { CODEC_ID_MP1, MKTAG('.', 'm', 'p', '1') }, ++ { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '2') }, ++ { CODEC_ID_MP3, MKTAG('.', 'm', 'p', '3') }, ++ { CODEC_ID_MP3, 0x6D730055 }, ++ { CODEC_ID_NELLYMOSER, MKTAG('n', 'm', 'o', 's') }, /* Flash Media Server */ ++ { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, ++ { CODEC_ID_PCM_F32BE, MKTAG('f', 'l', '3', '2') }, ++ { CODEC_ID_PCM_F32LE, MKTAG('f', 'l', '3', '2') }, ++ { CODEC_ID_PCM_F64BE, MKTAG('f', 'l', '6', '4') }, ++ { CODEC_ID_PCM_F64LE, MKTAG('f', 'l', '6', '4') }, ++ { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, ++ { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, ++ { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, ++ { CODEC_ID_PCM_S16LE, MKTAG('l', 'p', 'c', 'm') }, ++ { CODEC_ID_PCM_S24BE, MKTAG('i', 'n', '2', '4') }, ++ { CODEC_ID_PCM_S24LE, MKTAG('i', 'n', '2', '4') }, ++ { CODEC_ID_PCM_S32BE, MKTAG('i', 'n', '3', '2') }, ++ { CODEC_ID_PCM_S32LE, MKTAG('i', 'n', '3', '2') }, ++ { CODEC_ID_PCM_S8, MKTAG('s', 'o', 'w', 't') }, ++ { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, ++ { CODEC_ID_PCM_U8, MKTAG('N', 'O', 'N', 'E') }, ++ { CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'p') }, ++ { CODEC_ID_QCELP, MKTAG('Q', 'c', 'l', 'q') }, ++ { CODEC_ID_QCELP, MKTAG('s', 'q', 'c', 'p') }, /* ISO Media fourcc */ ++ { CODEC_ID_QDM2, MKTAG('Q', 'D', 'M', '2') }, ++ { CODEC_ID_QDMC, MKTAG('Q', 'D', 'M', 'C') }, ++ { CODEC_ID_SPEEX, MKTAG('s', 'p', 'e', 'x') }, /* Flash Media Server */ ++ { CODEC_ID_WMAV2, MKTAG('W', 'M', 'A', '2') }, + { CODEC_ID_NONE, 0 }, + }; + +@@ -333,12 +362,12 @@ + return 1; + } + +-int ff_mp4_read_descr_len(ByteIOContext *pb) ++int ff_mp4_read_descr_len(AVIOContext *pb) + { + int len = 0; + int count = 4; + while (count--) { +- int c = get_byte(pb); ++ int c = avio_r8(pb); + len = (len << 7) | (c & 0x7f); + if (!(c & 0x80)) + break; +@@ -346,15 +375,31 @@ + return len; + } + +-int ff_mp4_read_descr(AVFormatContext *fc, ByteIOContext *pb, int *tag) ++int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag) + { + int len; +- *tag = get_byte(pb); ++ *tag = avio_r8(pb); + len = ff_mp4_read_descr_len(pb); + av_dlog(fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); + return len; + } + ++void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id) ++{ ++ int flags; ++ if (es_id) *es_id = avio_rb16(pb); ++ else avio_rb16(pb); ++ flags = avio_r8(pb); ++ if (flags & 0x80) //streamDependenceFlag ++ avio_rb16(pb); ++ if (flags & 0x40) { //URL_Flag ++ int len = avio_r8(pb); ++ avio_skip(pb, len); ++ } ++ if (flags & 0x20) //OCRstreamFlag ++ avio_rb16(pb); ++} ++ + static const AVCodecTag mp4_audio_types[] = { + { CODEC_ID_MP3ON4, AOT_PS }, /* old mp3on4 draft */ + { CODEC_ID_MP3ON4, AOT_L1 }, /* layer 1 */ +@@ -364,35 +409,35 @@ + { CODEC_ID_NONE, AOT_NULL }, + }; + +-int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, ByteIOContext *pb) ++int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb) + { + int len, tag; +- int object_type_id = get_byte(pb); +- get_byte(pb); /* stream type */ +- get_be24(pb); /* buffer size db */ +- get_be32(pb); /* max bitrate */ +- get_be32(pb); /* avg bitrate */ ++ int object_type_id = avio_r8(pb); ++ avio_r8(pb); /* stream type */ ++ avio_rb24(pb); /* buffer size db */ ++ avio_rb32(pb); /* max bitrate */ ++ avio_rb32(pb); /* avg bitrate */ + + st->codec->codec_id= ff_codec_get_id(ff_mp4_obj_type, object_type_id); + av_dlog(fc, "esds object type id 0x%02x\n", object_type_id); + len = ff_mp4_read_descr(fc, pb, &tag); + if (tag == MP4DecSpecificDescrTag) { + av_dlog(fc, "Specific MPEG4 header len=%d\n", len); +- if((uint64_t)len > (1<<30)) ++ if (!len || (uint64_t)len > (1<<30)) + return -1; + av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); +- get_buffer(pb, st->codec->extradata, len); ++ avio_read(pb, st->codec->extradata, len); + st->codec->extradata_size = len; + if (st->codec->codec_id == CODEC_ID_AAC) { + MPEG4AudioConfig cfg; +- ff_mpeg4audio_get_config(&cfg, st->codec->extradata, +- st->codec->extradata_size); ++ avpriv_mpeg4audio_get_config(&cfg, st->codec->extradata, ++ st->codec->extradata_size * 8, 1); + st->codec->channels = cfg.channels; + if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 +- st->codec->sample_rate = ff_mpa_freq_tab[cfg.sampling_index]; ++ st->codec->sample_rate = avpriv_mpa_freq_tab[cfg.sampling_index]; + else if (cfg.ext_sample_rate) + st->codec->sample_rate = cfg.ext_sample_rate; + else +@@ -408,3 +453,87 @@ + } + return 0; + } ++ ++typedef struct MovChannelLayout { ++ int64_t channel_layout; ++ uint32_t layout_tag; ++} MovChannelLayout; ++ ++static const MovChannelLayout mov_channel_layout[] = { ++ { AV_CH_LAYOUT_MONO, (100<<16) | 1}, // kCAFChannelLayoutTag_Mono ++ { AV_CH_LAYOUT_STEREO, (101<<16) | 2}, // kCAFChannelLayoutTag_Stereo ++ { AV_CH_LAYOUT_STEREO, (102<<16) | 2}, // kCAFChannelLayoutTag_StereoHeadphones ++ { AV_CH_LAYOUT_2_1, (131<<16) | 3}, // kCAFChannelLayoutTag_ITU_2_1 ++ { AV_CH_LAYOUT_QUAD, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2 ++ { AV_CH_LAYOUT_2_2, (132<<16) | 4}, // kCAFChannelLayoutTag_ITU_2_2 ++ { AV_CH_LAYOUT_QUAD, (108<<16) | 4}, // kCAFChannelLayoutTag_Quadraphonic ++ { AV_CH_LAYOUT_SURROUND, (113<<16) | 3}, // kCAFChannelLayoutTag_MPEG_3_0_A ++ { AV_CH_LAYOUT_4POINT0, (115<<16) | 4}, // kCAFChannelLayoutTag_MPEG_4_0_A ++ { AV_CH_LAYOUT_5POINT0_BACK, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A ++ { AV_CH_LAYOUT_5POINT0, (117<<16) | 5}, // kCAFChannelLayoutTag_MPEG_5_0_A ++ { AV_CH_LAYOUT_5POINT1_BACK, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A ++ { AV_CH_LAYOUT_5POINT1, (121<<16) | 6}, // kCAFChannelLayoutTag_MPEG_5_1_A ++ { AV_CH_LAYOUT_7POINT1, (128<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_C ++ { AV_CH_LAYOUT_7POINT1_WIDE, (126<<16) | 8}, // kCAFChannelLayoutTag_MPEG_7_1_A ++ { AV_CH_LAYOUT_5POINT1_BACK|AV_CH_LAYOUT_STEREO_DOWNMIX, (130<<16) | 8}, // kCAFChannelLayoutTag_SMPTE_DTV ++ { AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY, (133<<16) | 3}, // kCAFChannelLayoutTag_DVD_4 ++ { AV_CH_LAYOUT_2_1|AV_CH_LOW_FREQUENCY, (134<<16) | 4}, // kCAFChannelLayoutTag_DVD_5 ++ { AV_CH_LAYOUT_QUAD|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6 ++ { AV_CH_LAYOUT_2_2|AV_CH_LOW_FREQUENCY, (135<<16) | 4}, // kCAFChannelLayoutTag_DVD_6 ++ { AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY, (136<<16) | 4}, // kCAFChannelLayoutTag_DVD_10 ++ { AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY, (137<<16) | 5}, // kCAFChannelLayoutTag_DVD_11 ++ { 0, 0}, ++}; ++ ++void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec) ++{ ++ uint32_t layout_tag; ++ AVIOContext *pb = s->pb; ++ const MovChannelLayout *layouts = mov_channel_layout; ++ layout_tag = avio_rb32(pb); ++ size -= 4; ++ if (layout_tag == 0) { // kCAFChannelLayoutTag_UseChannelDescriptions ++ // Channel descriptions not implemented ++ av_log_ask_for_sample(s, "Unimplemented container channel layout.\n"); ++ avio_skip(pb, size); ++ return; ++ } ++ if (layout_tag == 0x10000) { // kCAFChannelLayoutTag_UseChannelBitmap ++ codec->channel_layout = avio_rb32(pb); ++ size -= 4; ++ avio_skip(pb, size); ++ return; ++ } ++ while (layouts->channel_layout) { ++ if (layout_tag == layouts->layout_tag) { ++ codec->channel_layout = layouts->channel_layout; ++ break; ++ } ++ layouts++; ++ } ++ if (!codec->channel_layout) ++ av_log(s, AV_LOG_WARNING, "Unknown container channel layout.\n"); ++ avio_skip(pb, size); ++} ++ ++void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout) ++{ ++ const MovChannelLayout *layouts; ++ uint32_t layout_tag = 0; ++ ++ for (layouts = mov_channel_layout; layouts->channel_layout; layouts++) ++ if (channel_layout == layouts->channel_layout) { ++ layout_tag = layouts->layout_tag; ++ break; ++ } ++ ++ if (layout_tag) { ++ avio_wb32(pb, layout_tag); // mChannelLayoutTag ++ avio_wb32(pb, 0); // mChannelBitmap ++ } else { ++ avio_wb32(pb, 0x10000); // kCAFChannelLayoutTag_UseChannelBitmap ++ avio_wb32(pb, channel_layout); ++ } ++ avio_wb32(pb, 0); // mNumberChannelDescriptions ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/isom.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/isom.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/isom.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/isom.h 2012-05-14 14:08:54.994353265 +0200 +@@ -88,7 +88,7 @@ + } MOVTrackExt; + + typedef struct MOVStreamContext { +- ByteIOContext *pb; ++ AVIOContext *pb; + int ffindex; ///< AVStream index + int next_chunk; + unsigned int chunk_count; +@@ -109,7 +109,9 @@ + unsigned int keyframe_count; + int *keyframes; + int time_scale; +- int time_offset; ///< time offset of the first edit list entry ++ int64_t empty_duration; ///< empty duration of the first edit list entry ++ int64_t start_time; ///< start time of the media ++ int64_t time_offset; ///< time offset of the edit list entries + int current_sample; + unsigned int bytes_per_frame; + unsigned int samples_per_frame; +@@ -123,9 +125,13 @@ + int width; ///< tkhd width + int height; ///< tkhd height + int dts_shift; ///< dts shift when ctts is negative ++ uint32_t palette[256]; ++ int has_palette; ++ int64_t data_size; + } MOVStreamContext; + + typedef struct MOVContext { ++ AVClass *avclass; + AVFormatContext *fc; + int time_scale; + int64_t duration; ///< duration of the longest track +@@ -139,20 +145,26 @@ + unsigned trex_count; + int itunes_metadata; ///< metadata are itunes style + int chapter_track; ++ int use_absolute_path; + } MOVContext; + +-int ff_mp4_read_descr_len(ByteIOContext *pb); +-int ff_mp4_read_descr(AVFormatContext *fc, ByteIOContext *pb, int *tag); +-int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, ByteIOContext *pb); ++int ff_mp4_read_descr_len(AVIOContext *pb); ++int ff_mp4_read_descr(AVFormatContext *fc, AVIOContext *pb, int *tag); ++int ff_mp4_read_dec_config_descr(AVFormatContext *fc, AVStream *st, AVIOContext *pb); ++void ff_mp4_parse_es_descr(AVIOContext *pb, int *es_id); + ++#define MP4ODescrTag 0x01 + #define MP4IODescrTag 0x02 + #define MP4ESDescrTag 0x03 + #define MP4DecConfigDescrTag 0x04 + #define MP4DecSpecificDescrTag 0x05 ++#define MP4SLDescrTag 0x06 + +-int ff_mov_read_esds(AVFormatContext *fc, ByteIOContext *pb, MOVAtom atom); ++int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom); + enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags); + +-int ff_mov_read_stsd_entries(MOVContext *c, ByteIOContext *pb, int entries); ++int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries); ++void ff_mov_read_chan(AVFormatContext *s, int64_t size, AVCodecContext *codec); ++void ff_mov_write_chan(AVIOContext *pb, int64_t channel_layout); + + #endif /* AVFORMAT_ISOM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iss.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iss.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iss.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iss.c 2012-05-14 14:08:54.995353285 +0200 +@@ -23,11 +23,11 @@ + * @file + * Funcom ISS file demuxer + * @author Jaikrishnan Menon +- * for more information on the .iss file format, visit: +- * http://wiki.multimedia.cx/index.php?title=FunCom_ISS ++ * @see http://wiki.multimedia.cx/index.php?title=FunCom_ISS + */ + + #include "avformat.h" ++#include "internal.h" + #include "libavutil/avstring.h" + + #define ISS_SIG "IMA_ADPCM_Sound" +@@ -39,12 +39,12 @@ + int sample_start_pos; + } IssDemuxContext; + +-static void get_token(ByteIOContext *s, char *buf, int maxlen) ++static void get_token(AVIOContext *s, char *buf, int maxlen) + { + int i = 0; + char c; + +- while ((c = get_byte(s))) { ++ while ((c = avio_r8(s))) { + if(c == ' ') + break; + if (i < maxlen-1) +@@ -52,7 +52,7 @@ + } + + if(!c) +- get_byte(s); ++ avio_r8(s); + + buf[i] = 0; /* Ensure null terminated, but may be truncated */ + } +@@ -68,7 +68,7 @@ + static av_cold int iss_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + IssDemuxContext *iss = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + char token[MAX_TOKEN_SIZE]; + int stereo, rate_divisor; +@@ -87,9 +87,14 @@ + get_token(pb, token, sizeof(token)); //Version ID + get_token(pb, token, sizeof(token)); //Size + +- iss->sample_start_pos = url_ftell(pb); ++ if (iss->packet_size <= 0) { ++ av_log(s, AV_LOG_ERROR, "packet_size %d is invalid\n", iss->packet_size); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ iss->sample_start_pos = avio_tell(pb); + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -102,7 +107,7 @@ + st->codec->bit_rate = st->codec->channels * st->codec->sample_rate + * st->codec->bits_per_coded_sample; + st->codec->block_align = iss->packet_size; +- av_set_pts_info(st, 32, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + + return 0; + } +@@ -116,18 +121,18 @@ + return AVERROR(EIO); + + pkt->stream_index = 0; +- pkt->pts = url_ftell(s->pb) - iss->sample_start_pos; ++ pkt->pts = avio_tell(s->pb) - iss->sample_start_pos; + if(s->streams[0]->codec->channels > 0) + pkt->pts /= s->streams[0]->codec->channels*2; + return 0; + } + + AVInputFormat ff_iss_demuxer = { +- "ISS", +- NULL_IF_CONFIG_SMALL("Funcom ISS format"), +- sizeof(IssDemuxContext), +- iss_probe, +- iss_read_header, +- iss_read_packet, ++ .name = "ISS", ++ .long_name = NULL_IF_CONFIG_SMALL("Funcom ISS format"), ++ .priv_data_size = sizeof(IssDemuxContext), ++ .read_probe = iss_probe, ++ .read_header = iss_read_header, ++ .read_packet = iss_read_packet, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iv8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iv8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/iv8.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/iv8.c 2012-05-14 14:08:54.996353305 +0200 +@@ -19,11 +19,12 @@ + */ + + #include "avformat.h" ++#include "internal.h" + + + static int probe(AVProbeData *p) + { +- // the single file i have starts with that, i dont know if others do too ++ // the single file I have starts with that, I do not know if others do, too + if( p->buf[0] == 1 + && p->buf[1] == 1 + && p->buf[2] == 3 +@@ -40,14 +41,14 @@ + { + AVStream *st; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG4; + st->need_parsing = AVSTREAM_PARSE_FULL; +- av_set_pts_info(st, 64, 1, 90000); ++ avpriv_set_pts_info(st, 64, 1, 90000); + + return 0; + +@@ -55,42 +56,64 @@ + + static int read_packet(AVFormatContext *s, AVPacket *pkt) + { +- int ret, size, pts, type; +-retry: +- type= get_be16(s->pb); // 257 or 258 +- size= get_be16(s->pb); +- +- get_be16(s->pb); //some flags, 0x80 indicates end of frame +- get_be16(s->pb); //packet number +- pts=get_be32(s->pb); +- get_be32(s->pb); //6A 13 E3 88 +- +- size -= 12; +- if(size<1) +- return -1; +- +- if(type==258){ +- url_fskip(s->pb, size); +- goto retry; ++ int ret, size, pts, type, flags; ++ int first_pkt = 0; ++ int frame_complete = 0; ++ ++ while (!frame_complete) { ++ ++ type = avio_rb16(s->pb); // 257 or 258 ++ size = avio_rb16(s->pb); ++ flags = avio_rb16(s->pb); //some flags, 0x80 indicates end of frame ++ avio_rb16(s->pb); //packet number ++ pts = avio_rb32(s->pb); ++ avio_rb32(s->pb); //6A 13 E3 88 ++ ++ frame_complete = flags & 0x80; ++ ++ size -= 12; ++ if (size < 1) ++ return -1; ++ ++ if (type == 258) { ++ avio_skip(s->pb, size); ++ frame_complete = 0; ++ continue; ++ } ++ ++ if (!first_pkt) { ++ ret = av_get_packet(s->pb, pkt, size); ++ if (ret < 0) ++ return ret; ++ first_pkt = 1; ++ pkt->pts = pts; ++ pkt->pos -= 16; ++ } else { ++ ret = av_append_packet(s->pb, pkt, size); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "failed to grow packet\n"); ++ av_free_packet(pkt); ++ return ret; ++ } ++ } ++ if (ret < size) { ++ av_log(s, AV_LOG_ERROR, "Truncated packet! Read %d of %d bytes\n", ++ ret, size); ++ pkt->flags |= AV_PKT_FLAG_CORRUPT; ++ break; ++ } + } +- +- ret= av_get_packet(s->pb, pkt, size); +- +- pkt->pts= pts; +- pkt->pos-=16; +- + pkt->stream_index = 0; + +- return ret; ++ return 0; + } + + AVInputFormat ff_iv8_demuxer = { +- "iv8", +- NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"), +- 0, +- probe, +- read_header, +- read_packet, ++ .name = "iv8", ++ .long_name = NULL_IF_CONFIG_SMALL("A format generated by IndigoVision 8000 video server"), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, + .flags= AVFMT_GENERIC_INDEX, + .value = CODEC_ID_MPEG4, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ivfdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ivfdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ivfdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ivfdec.c 2012-05-14 14:08:54.997353325 +0200 +@@ -19,6 +19,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + #include "libavutil/intreadwrite.h" + +@@ -36,23 +37,23 @@ + AVStream *st; + AVRational time_base; + +- get_le32(s->pb); // DKIF +- get_le16(s->pb); // version +- get_le16(s->pb); // header size ++ avio_rl32(s->pb); // DKIF ++ avio_rl16(s->pb); // version ++ avio_rl16(s->pb); // header size + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_tag = get_le32(s->pb); ++ st->codec->codec_tag = avio_rl32(s->pb); + st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, st->codec->codec_tag); +- st->codec->width = get_le16(s->pb); +- st->codec->height = get_le16(s->pb); +- time_base.den = get_le32(s->pb); +- time_base.num = get_le32(s->pb); +- st->duration = get_le64(s->pb); ++ st->codec->width = avio_rl16(s->pb); ++ st->codec->height = avio_rl16(s->pb); ++ time_base.den = avio_rl32(s->pb); ++ time_base.num = avio_rl32(s->pb); ++ st->duration = avio_rl64(s->pb); + + st->need_parsing = AVSTREAM_PARSE_HEADERS; + +@@ -61,15 +62,15 @@ + return AVERROR_INVALIDDATA; + } + +- av_set_pts_info(st, 64, time_base.num, time_base.den); ++ avpriv_set_pts_info(st, 64, time_base.num, time_base.den); + + return 0; + } + + static int read_packet(AVFormatContext *s, AVPacket *pkt) + { +- int ret, size = get_le32(s->pb); +- int64_t pts = get_le64(s->pb); ++ int ret, size = avio_rl32(s->pb); ++ int64_t pts = avio_rl64(s->pb); + + ret = av_get_packet(s->pb, pkt, size); + pkt->stream_index = 0; +@@ -80,12 +81,11 @@ + } + + AVInputFormat ff_ivf_demuxer = { +- "ivf", +- NULL_IF_CONFIG_SMALL("On2 IVF"), +- 0, +- probe, +- read_header, +- read_packet, ++ .name = "ivf", ++ .long_name = NULL_IF_CONFIG_SMALL("On2 IVF"), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, + .flags= AVFMT_GENERIC_INDEX, + .codec_tag = (const AVCodecTag*[]){ff_codec_bmp_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ivfenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ivfenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ivfenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ivfenc.c 2012-05-14 14:08:54.997353325 +0200 +@@ -23,37 +23,37 @@ + static int ivf_write_header(AVFormatContext *s) + { + AVCodecContext *ctx; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (s->nb_streams != 1) { + av_log(s, AV_LOG_ERROR, "Format supports only exactly one video stream\n"); + return AVERROR(EINVAL); + } + ctx = s->streams[0]->codec; +- if (ctx->codec_type != CODEC_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) { ++ if (ctx->codec_type != AVMEDIA_TYPE_VIDEO || ctx->codec_id != CODEC_ID_VP8) { + av_log(s, AV_LOG_ERROR, "Currently only VP8 is supported!\n"); + return AVERROR(EINVAL); + } +- put_buffer(pb, "DKIF", 4); +- put_le16(pb, 0); // version +- put_le16(pb, 32); // header length +- put_le32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80")); +- put_le16(pb, ctx->width); +- put_le16(pb, ctx->height); +- put_le32(pb, s->streams[0]->time_base.den); +- put_le32(pb, s->streams[0]->time_base.num); +- put_le64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!? ++ avio_write(pb, "DKIF", 4); ++ avio_wl16(pb, 0); // version ++ avio_wl16(pb, 32); // header length ++ avio_wl32(pb, ctx->codec_tag ? ctx->codec_tag : AV_RL32("VP80")); ++ avio_wl16(pb, ctx->width); ++ avio_wl16(pb, ctx->height); ++ avio_wl32(pb, s->streams[0]->time_base.den); ++ avio_wl32(pb, s->streams[0]->time_base.num); ++ avio_wl64(pb, s->streams[0]->duration); // TODO: duration or number of frames?!? + + return 0; + } + + static int ivf_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; +- put_le32(pb, pkt->size); +- put_le64(pb, pkt->pts); +- put_buffer(pb, pkt->data, pkt->size); +- put_flush_packet(pb); ++ AVIOContext *pb = s->pb; ++ avio_wl32(pb, pkt->size); ++ avio_wl64(pb, pkt->pts); ++ avio_write(pb, pkt->data, pkt->size); ++ avio_flush(pb); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/jvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/jvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/jvdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/jvdec.c 2012-05-14 14:08:54.998353345 +0200 +@@ -0,0 +1,227 @@ ++/* ++ * Bitmap Brothers JV demuxer ++ * Copyright (c) 2005, 2011 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Bitmap Brothers JV demuxer ++ * @author Peter Ross ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define JV_PREAMBLE_SIZE 5 ++ ++typedef struct { ++ int audio_size; /** audio packet size (bytes) */ ++ int video_size; /** video packet size (bytes) */ ++ int palette_size; /** palette size (bytes) */ ++ int video_type; /** per-frame video compression type */ ++} JVFrame; ++ ++typedef struct { ++ JVFrame *frames; ++ enum { ++ JV_AUDIO = 0, ++ JV_VIDEO, ++ JV_PADDING ++ } state; ++ int64_t pts; ++} JVDemuxContext; ++ ++#define MAGIC " Compression by John M Phillips Copyright (C) 1995 The Bitmap Brothers Ltd." ++ ++static int read_probe(AVProbeData *pd) ++{ ++ if (pd->buf[0] == 'J' && pd->buf[1] == 'V' && ++ !memcmp(pd->buf + 4, MAGIC, FFMIN(strlen(MAGIC), pd->buf_size - 4))) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ JVDemuxContext *jv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *vst, *ast; ++ int64_t audio_pts = 0; ++ int64_t offset; ++ int i; ++ ++ avio_skip(pb, 80); ++ ++ ast = avformat_new_stream(s, NULL); ++ vst = avformat_new_stream(s, NULL); ++ if (!ast || !vst) ++ return AVERROR(ENOMEM); ++ ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->codec_id = CODEC_ID_JV; ++ vst->codec->codec_tag = 0; /* no fourcc */ ++ vst->codec->width = avio_rl16(pb); ++ vst->codec->height = avio_rl16(pb); ++ vst->nb_frames = ++ ast->nb_index_entries = avio_rl16(pb); ++ avpriv_set_pts_info(vst, 64, avio_rl16(pb), 1000); ++ ++ avio_skip(pb, 4); ++ ++ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ast->codec->codec_id = CODEC_ID_PCM_U8; ++ ast->codec->codec_tag = 0; /* no fourcc */ ++ ast->codec->sample_rate = avio_rl16(pb); ++ ast->codec->channels = 1; ++ avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); ++ ++ avio_skip(pb, 10); ++ ++ ast->index_entries = av_malloc(ast->nb_index_entries * sizeof(*ast->index_entries)); ++ if (!ast->index_entries) ++ return AVERROR(ENOMEM); ++ ++ jv->frames = av_malloc(ast->nb_index_entries * sizeof(JVFrame)); ++ if (!jv->frames) ++ return AVERROR(ENOMEM); ++ ++ offset = 0x68 + ast->nb_index_entries * 16; ++ for(i = 0; i < ast->nb_index_entries; i++) { ++ AVIndexEntry *e = ast->index_entries + i; ++ JVFrame *jvf = jv->frames + i; ++ ++ /* total frame size including audio, video, palette data and padding */ ++ e->size = avio_rl32(pb); ++ e->timestamp = i; ++ e->pos = offset; ++ offset += e->size; ++ ++ jvf->audio_size = avio_rl32(pb); ++ jvf->video_size = avio_rl32(pb); ++ jvf->palette_size = avio_r8(pb) ? 768 : 0; ++ jvf->video_size = FFMIN(FFMAX(jvf->video_size, 0), ++ INT_MAX - JV_PREAMBLE_SIZE - jvf->palette_size); ++ if (avio_r8(pb)) ++ av_log(s, AV_LOG_WARNING, "unsupported audio codec\n"); ++ jvf->video_type = avio_r8(pb); ++ avio_skip(pb, 1); ++ ++ e->timestamp = jvf->audio_size ? audio_pts : AV_NOPTS_VALUE; ++ audio_pts += jvf->audio_size; ++ ++ e->flags = jvf->video_type != 1 ? AVINDEX_KEYFRAME : 0; ++ } ++ ++ jv->state = JV_AUDIO; ++ return 0; ++} ++ ++static int read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ JVDemuxContext *jv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *ast = s->streams[0]; ++ ++ while (!url_feof(s->pb) && jv->pts < ast->nb_index_entries) { ++ const AVIndexEntry *e = ast->index_entries + jv->pts; ++ const JVFrame *jvf = jv->frames + jv->pts; ++ ++ switch(jv->state) { ++ case JV_AUDIO: ++ jv->state++; ++ if (jvf->audio_size ) { ++ if (av_get_packet(s->pb, pkt, jvf->audio_size) < 0) ++ return AVERROR(ENOMEM); ++ pkt->stream_index = 0; ++ pkt->pts = e->timestamp; ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ return 0; ++ } ++ case JV_VIDEO: ++ jv->state++; ++ if (jvf->video_size || jvf->palette_size) { ++ int size = jvf->video_size + jvf->palette_size; ++ if (av_new_packet(pkt, size + JV_PREAMBLE_SIZE)) ++ return AVERROR(ENOMEM); ++ ++ AV_WL32(pkt->data, jvf->video_size); ++ pkt->data[4] = jvf->video_type; ++ if (avio_read(pb, pkt->data + JV_PREAMBLE_SIZE, size) < 0) ++ return AVERROR(EIO); ++ ++ pkt->size = size + JV_PREAMBLE_SIZE; ++ pkt->stream_index = 1; ++ pkt->pts = jv->pts; ++ if (jvf->video_type != 1) ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ return 0; ++ } ++ case JV_PADDING: ++ avio_skip(pb, FFMAX(e->size - jvf->audio_size - jvf->video_size ++ - jvf->palette_size, 0)); ++ jv->state = JV_AUDIO; ++ jv->pts++; ++ } ++ } ++ ++ return AVERROR(EIO); ++} ++ ++static int read_seek(AVFormatContext *s, int stream_index, ++ int64_t ts, int flags) ++{ ++ JVDemuxContext *jv = s->priv_data; ++ AVStream *ast = s->streams[0]; ++ int i; ++ ++ if (flags & (AVSEEK_FLAG_BYTE|AVSEEK_FLAG_FRAME)) ++ return AVERROR(ENOSYS); ++ ++ switch(stream_index) { ++ case 0: ++ i = av_index_search_timestamp(ast, ts, flags); ++ break; ++ case 1: ++ i = ts; ++ break; ++ default: ++ return 0; ++ } ++ ++ if (i < 0 || i >= ast->nb_index_entries) ++ return -1; ++ if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0) ++ return -1; ++ ++ jv->state = JV_AUDIO; ++ jv->pts = i; ++ return 0; ++} ++ ++AVInputFormat ff_jv_demuxer = { ++ .name = "jv", ++ .long_name = NULL_IF_CONFIG_SMALL("Bitmap Brothers JV"), ++ .priv_data_size = sizeof(JVDemuxContext), ++ .read_probe = read_probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_seek = read_seek, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/latmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/latmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/latmenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/latmenc.c 2012-05-14 14:08:54.999353365 +0200 +@@ -0,0 +1,198 @@ ++/* ++ * LATM/LOAS muxer ++ * Copyright (c) 2011 Kieran Kunhya ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavcodec/get_bits.h" ++#include "libavcodec/put_bits.h" ++#include "libavcodec/avcodec.h" ++#include "libavcodec/mpeg4audio.h" ++#include "libavutil/opt.h" ++#include "avformat.h" ++#include "rawenc.h" ++ ++typedef struct { ++ AVClass *av_class; ++ int off; ++ int channel_conf; ++ int object_type; ++ int counter; ++ int mod; ++} LATMContext; ++ ++static const AVOption options[] = { ++ {"smc-interval", "StreamMuxConfig interval.", ++ offsetof(LATMContext, mod), AV_OPT_TYPE_INT, {.dbl = 0x0014}, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, ++ {NULL}, ++}; ++ ++static const AVClass latm_muxer_class = { ++ .class_name = "LATM/LOAS muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++static int latm_decode_extradata(LATMContext *ctx, uint8_t *buf, int size) ++{ ++ GetBitContext gb; ++ MPEG4AudioConfig m4ac; ++ ++ init_get_bits(&gb, buf, size * 8); ++ ctx->off = avpriv_mpeg4audio_get_config(&m4ac, buf, size * 8, 1); ++ if (ctx->off < 0) ++ return ctx->off; ++ skip_bits_long(&gb, ctx->off); ++ ++ /* FIXME: are any formats not allowed in LATM? */ ++ ++ if (m4ac.object_type > AOT_SBR && m4ac.object_type != AOT_ALS) { ++ av_log(ctx, AV_LOG_ERROR, "Muxing MPEG-4 AOT %d in LATM is not supported\n", m4ac.object_type); ++ return AVERROR_INVALIDDATA; ++ } ++ ctx->channel_conf = m4ac.chan_config; ++ ctx->object_type = m4ac.object_type; ++ ++ return 0; ++} ++ ++static int latm_write_header(AVFormatContext *s) ++{ ++ LATMContext *ctx = s->priv_data; ++ AVCodecContext *avctx = s->streams[0]->codec; ++ ++ if (avctx->codec_id == CODEC_ID_AAC_LATM) ++ return 0; ++ ++ if (avctx->extradata_size > 0 && ++ latm_decode_extradata(ctx, avctx->extradata, avctx->extradata_size) < 0) ++ return AVERROR_INVALIDDATA; ++ ++ return 0; ++} ++ ++static int latm_write_frame_header(AVFormatContext *s, PutBitContext *bs) ++{ ++ LATMContext *ctx = s->priv_data; ++ AVCodecContext *avctx = s->streams[0]->codec; ++ GetBitContext gb; ++ int header_size; ++ ++ /* AudioMuxElement */ ++ put_bits(bs, 1, !!ctx->counter); ++ ++ if (!ctx->counter) { ++ init_get_bits(&gb, avctx->extradata, avctx->extradata_size * 8); ++ ++ /* StreamMuxConfig */ ++ put_bits(bs, 1, 0); /* audioMuxVersion */ ++ put_bits(bs, 1, 1); /* allStreamsSameTimeFraming */ ++ put_bits(bs, 6, 0); /* numSubFrames */ ++ put_bits(bs, 4, 0); /* numProgram */ ++ put_bits(bs, 3, 0); /* numLayer */ ++ ++ /* AudioSpecificConfig */ ++ if (ctx->object_type == AOT_ALS) { ++ header_size = avctx->extradata_size-(ctx->off + 7) >> 3; ++ avpriv_copy_bits(bs, &avctx->extradata[ctx->off], header_size); ++ } else { ++ avpriv_copy_bits(bs, avctx->extradata, ctx->off + 3); ++ ++ if (!ctx->channel_conf) { ++ avpriv_copy_pce_data(bs, &gb); ++ } ++ } ++ ++ put_bits(bs, 3, 0); /* frameLengthType */ ++ put_bits(bs, 8, 0xff); /* latmBufferFullness */ ++ ++ put_bits(bs, 1, 0); /* otherDataPresent */ ++ put_bits(bs, 1, 0); /* crcCheckPresent */ ++ } ++ ++ ctx->counter++; ++ ctx->counter %= ctx->mod; ++ ++ return 0; ++} ++ ++static int latm_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ PutBitContext bs; ++ int i, len; ++ uint8_t loas_header[] = "\x56\xe0\x00"; ++ uint8_t *buf; ++ ++ if (s->streams[0]->codec->codec_id == CODEC_ID_AAC_LATM) ++ return ff_raw_write_packet(s, pkt); ++ ++ if (pkt->size > 2 && pkt->data[0] == 0xff && (pkt->data[1] >> 4) == 0xf) { ++ av_log(s, AV_LOG_ERROR, "ADTS header detected - ADTS will not be incorrectly muxed into LATM\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ buf = av_malloc(pkt->size+1024); ++ if (!buf) ++ return AVERROR(ENOMEM); ++ ++ init_put_bits(&bs, buf, pkt->size+1024); ++ ++ latm_write_frame_header(s, &bs); ++ ++ /* PayloadLengthInfo() */ ++ for (i = 0; i <= pkt->size-255; i+=255) ++ put_bits(&bs, 8, 255); ++ ++ put_bits(&bs, 8, pkt->size-i); ++ ++ /* The LATM payload is written unaligned */ ++ ++ /* PayloadMux() */ ++ for (i = 0; i < pkt->size; i++) ++ put_bits(&bs, 8, pkt->data[i]); ++ ++ avpriv_align_put_bits(&bs); ++ flush_put_bits(&bs); ++ ++ len = put_bits_count(&bs) >> 3; ++ ++ loas_header[1] |= (len >> 8) & 0x1f; ++ loas_header[2] |= len & 0xff; ++ ++ avio_write(pb, loas_header, 3); ++ avio_write(pb, buf, len); ++ ++ av_free(buf); ++ ++ return 0; ++} ++ ++AVOutputFormat ff_latm_muxer = { ++ .name = "latm", ++ .long_name = NULL_IF_CONFIG_SMALL("LOAS/LATM"), ++ .mime_type = "audio/MP4A-LATM", ++ .extensions = "latm,loas", ++ .priv_data_size = sizeof(LATMContext), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = latm_write_header, ++ .write_packet = latm_write_packet, ++ .priv_class = &latm_muxer_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libavformat.v xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libavformat.v +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libavformat.v 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libavformat.v 2012-05-14 14:08:54.999353365 +0200 +@@ -1,7 +1,36 @@ + LIBAVFORMAT_$MAJOR { +- global: *; +- local: +- ff_*_demuxer; +- ff_*_muxer; +- ff_*_protocol; ++ global: av*; ++ #FIXME those are for ffserver ++ ff_inet_aton; ++ ff_socket_nonblock; ++ ffm_set_write_index; ++ ffm_read_write_index; ++ ffm_write_write_index; ++ ff_rtsp_parse_line; ++ ff_rtp_get_local_rtp_port; ++ ff_rtp_get_local_rtcp_port; ++ ffio_open_dyn_packet_buf; ++ ffurl_close; ++ ffurl_open; ++ ffurl_write; ++ url_open; ++ url_close; ++ url_write; ++ url_get_max_packet_size; ++ #those are deprecated, remove on next bump ++ find_info_tag; ++ parse_date; ++ dump_format; ++ url_*; ++ ff_timefilter_destroy; ++ ff_timefilter_new; ++ ff_timefilter_update; ++ ff_timefilter_reset; ++ get_*; ++ put_*; ++ udp_set_remote_url; ++ udp_get_local_port; ++ init_checksum; ++ init_put_byte; ++ local: *; + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libmodplug.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libmodplug.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libmodplug.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libmodplug.c 2012-05-14 14:08:55.001353406 +0200 +@@ -0,0 +1,368 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++* @file ++* ModPlug demuxer ++* @todo better probing than extensions matching ++*/ ++ ++#include ++#include "libavutil/avstring.h" ++#include "libavutil/eval.h" ++#include "libavutil/opt.h" ++#include "avformat.h" ++#include "internal.h" ++ ++typedef struct ModPlugContext { ++ const AVClass *class; ++ ModPlugFile *f; ++ uint8_t *buf; ///< input file content ++ ++ /* options */ ++ int noise_reduction; ++ int reverb_depth; ++ int reverb_delay; ++ int bass_amount; ++ int bass_range; ++ int surround_depth; ++ int surround_delay; ++ ++ int max_size; ///< max file size to allocate ++ ++ /* optional video stream */ ++ double ts_per_packet; ///< used to define the pts/dts using packet_count; ++ int packet_count; ///< total number of audio packets ++ int print_textinfo; ///< bool flag for printing speed, tempo, order, ... ++ int video_stream; ///< 1 if the user want a video stream, otherwise 0 ++ int w; ///< video stream width in char (one char = 8x8px) ++ int h; ///< video stream height in char (one char = 8x8px) ++ int video_switch; ///< 1 if current packet is video, otherwise 0 ++ int fsize; ///< constant frame size ++ int linesize; ///< line size in bytes ++ char *color_eval; ///< color eval user input expression ++ AVExpr *expr; ///< parsed color eval expression ++} ModPlugContext; ++ ++static const char *var_names[] = { ++ "x", "y", ++ "w", "h", ++ "t", ++ "speed", "tempo", "order", "pattern", "row", ++ NULL ++}; ++ ++enum var_name { ++ VAR_X, VAR_Y, ++ VAR_W, VAR_H, ++ VAR_TIME, ++ VAR_SPEED, VAR_TEMPO, VAR_ORDER, VAR_PATTERN, VAR_ROW, ++ VAR_VARS_NB ++}; ++ ++#define FF_MODPLUG_MAX_FILE_SIZE (100 * 1<<20) // 100M ++#define FF_MODPLUG_DEF_FILE_SIZE ( 5 * 1<<20) // 5M ++ ++#define OFFSET(x) offsetof(ModPlugContext, x) ++#define D AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ {"noise_reduction", "Enable noise reduction 0(off)-1(on)", OFFSET(noise_reduction), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D}, ++ {"reverb_depth", "Reverb level 0(quiet)-100(loud)", OFFSET(reverb_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D}, ++ {"reverb_delay", "Reverb delay in ms, usually 40-200ms", OFFSET(reverb_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D}, ++ {"bass_amount", "XBass level 0(quiet)-100(loud)", OFFSET(bass_amount), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D}, ++ {"bass_range", "XBass cutoff in Hz 10-100", OFFSET(bass_range), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D}, ++ {"surround_depth", "Surround level 0(quiet)-100(heavy)", OFFSET(surround_depth), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 100, D}, ++ {"surround_delay", "Surround delay in ms, usually 5-40ms", OFFSET(surround_delay), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, D}, ++ {"max_size", "Max file size supported (in bytes). Default is 5MB. Set to 0 for no limit (not recommended)", ++ OFFSET(max_size), AV_OPT_TYPE_INT, {.dbl = FF_MODPLUG_DEF_FILE_SIZE}, 0, FF_MODPLUG_MAX_FILE_SIZE, D}, ++ {"video_stream_expr", "Color formula", OFFSET(color_eval), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, D}, ++ {"video_stream", "Make demuxer output a video stream", OFFSET(video_stream), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, D}, ++ {"video_stream_w", "Video stream width in char (one char = 8x8px)", OFFSET(w), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D}, ++ {"video_stream_h", "Video stream height in char (one char = 8x8px)", OFFSET(h), AV_OPT_TYPE_INT, {.dbl = 30}, 20, 512, D}, ++ {"video_stream_ptxt", "Print speed, tempo, order, ... in video stream", OFFSET(print_textinfo), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, D}, ++ {NULL}, ++}; ++ ++#define SET_OPT_IF_REQUESTED(libopt, opt, flag) do { \ ++ if (modplug->opt) { \ ++ settings.libopt = modplug->opt; \ ++ settings.mFlags |= flag; \ ++ } \ ++} while (0) ++ ++#define ADD_META_MULTIPLE_ENTRIES(entry_name, fname) do { \ ++ if (n_## entry_name ##s) { \ ++ unsigned i, n = 0; \ ++ \ ++ for (i = 0; i < n_## entry_name ##s; i++) { \ ++ char item_name[64] = {0}; \ ++ fname(f, i, item_name); \ ++ if (!*item_name) \ ++ continue; \ ++ if (n) \ ++ av_dict_set(&s->metadata, #entry_name, "\n", AV_DICT_APPEND); \ ++ av_dict_set(&s->metadata, #entry_name, item_name, AV_DICT_APPEND); \ ++ n++; \ ++ } \ ++ \ ++ extra = av_asprintf(", %u/%u " #entry_name "%s", \ ++ n, n_## entry_name ##s, n > 1 ? "s" : ""); \ ++ if (!extra) \ ++ return AVERROR(ENOMEM); \ ++ av_dict_set(&s->metadata, "extra info", extra, AV_DICT_APPEND); \ ++ av_free(extra); \ ++ } \ ++} while (0) ++ ++static int modplug_load_metadata(AVFormatContext *s) ++{ ++ ModPlugContext *modplug = s->priv_data; ++ ModPlugFile *f = modplug->f; ++ char *extra; ++ const char *name = ModPlug_GetName(f); ++ const char *msg = ModPlug_GetMessage(f); ++ ++ unsigned n_instruments = ModPlug_NumInstruments(f); ++ unsigned n_samples = ModPlug_NumSamples(f); ++ unsigned n_patterns = ModPlug_NumPatterns(f); ++ unsigned n_channels = ModPlug_NumChannels(f); ++ ++ if (name && *name) av_dict_set(&s->metadata, "name", name, 0); ++ if (msg && *msg) av_dict_set(&s->metadata, "message", msg, 0); ++ ++ extra = av_asprintf("%u pattern%s, %u channel%s", ++ n_patterns, n_patterns > 1 ? "s" : "", ++ n_channels, n_channels > 1 ? "s" : ""); ++ if (!extra) ++ return AVERROR(ENOMEM); ++ av_dict_set(&s->metadata, "extra info", extra, AV_DICT_DONT_STRDUP_VAL); ++ ++ ADD_META_MULTIPLE_ENTRIES(instrument, ModPlug_InstrumentName); ++ ADD_META_MULTIPLE_ENTRIES(sample, ModPlug_SampleName); ++ ++ return 0; ++} ++ ++#define AUDIO_PKT_SIZE 512 ++ ++static int modplug_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVStream *st; ++ AVIOContext *pb = s->pb; ++ ModPlug_Settings settings; ++ ModPlugContext *modplug = s->priv_data; ++ int sz = avio_size(pb); ++ ++ if (sz < 0) { ++ av_log(s, AV_LOG_WARNING, "Could not determine file size\n"); ++ sz = modplug->max_size; ++ } else if (modplug->max_size && sz > modplug->max_size) { ++ sz = modplug->max_size; ++ av_log(s, AV_LOG_WARNING, "Max file size reach%s, allocating %dB " ++ "but demuxing is likely to fail due to incomplete buffer\n", ++ sz == FF_MODPLUG_DEF_FILE_SIZE ? " (see -max_size)" : "", sz); ++ } ++ ++ if (modplug->color_eval) { ++ int r = av_expr_parse(&modplug->expr, modplug->color_eval, var_names, ++ NULL, NULL, NULL, NULL, 0, s); ++ if (r < 0) ++ return r; ++ } ++ ++ modplug->buf = av_malloc(modplug->max_size); ++ if (!modplug->buf) ++ return AVERROR(ENOMEM); ++ sz = avio_read(pb, modplug->buf, sz); ++ ++ ModPlug_GetSettings(&settings); ++ settings.mChannels = 2; ++ settings.mBits = 16; ++ settings.mFrequency = 44100; ++ settings.mResamplingMode = MODPLUG_RESAMPLE_FIR; // best quality ++ settings.mLoopCount = 0; // prevents looping forever ++ ++ if (modplug->noise_reduction) settings.mFlags |= MODPLUG_ENABLE_NOISE_REDUCTION; ++ SET_OPT_IF_REQUESTED(mReverbDepth, reverb_depth, MODPLUG_ENABLE_REVERB); ++ SET_OPT_IF_REQUESTED(mReverbDelay, reverb_delay, MODPLUG_ENABLE_REVERB); ++ SET_OPT_IF_REQUESTED(mBassAmount, bass_amount, MODPLUG_ENABLE_MEGABASS); ++ SET_OPT_IF_REQUESTED(mBassRange, bass_range, MODPLUG_ENABLE_MEGABASS); ++ SET_OPT_IF_REQUESTED(mSurroundDepth, surround_depth, MODPLUG_ENABLE_SURROUND); ++ SET_OPT_IF_REQUESTED(mSurroundDelay, surround_delay, MODPLUG_ENABLE_SURROUND); ++ ++ if (modplug->reverb_depth) settings.mReverbDepth = modplug->reverb_depth; ++ if (modplug->reverb_delay) settings.mReverbDelay = modplug->reverb_delay; ++ if (modplug->bass_amount) settings.mBassAmount = modplug->bass_amount; ++ if (modplug->bass_range) settings.mBassRange = modplug->bass_range; ++ if (modplug->surround_depth) settings.mSurroundDepth = modplug->surround_depth; ++ if (modplug->surround_delay) settings.mSurroundDelay = modplug->surround_delay; ++ ++ ModPlug_SetSettings(&settings); ++ ++ modplug->f = ModPlug_Load(modplug->buf, sz); ++ if (!modplug->f) ++ return AVERROR_INVALIDDATA; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ avpriv_set_pts_info(st, 64, 1, 1000); ++ st->duration = ModPlug_GetLength(modplug->f); ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = CODEC_ID_PCM_S16LE; ++ st->codec->channels = settings.mChannels; ++ st->codec->sample_rate = settings.mFrequency; ++ ++ // timebase = 1/1000, 2ch 16bits 44.1kHz-> 2*2*44100 ++ modplug->ts_per_packet = 1000*AUDIO_PKT_SIZE / (4*44100.); ++ ++ if (modplug->video_stream) { ++ AVStream *vst = avformat_new_stream(s, NULL); ++ if (!vst) ++ return AVERROR(ENOMEM); ++ avpriv_set_pts_info(vst, 64, 1, 1000); ++ vst->duration = st->duration; ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->codec_id = CODEC_ID_XBIN; ++ vst->codec->width = modplug->w << 3; ++ vst->codec->height = modplug->h << 3; ++ modplug->linesize = modplug->w * 3; ++ modplug->fsize = modplug->linesize * modplug->h; ++ } ++ ++ return modplug_load_metadata(s); ++} ++ ++static void write_text(uint8_t *dst, const char *s, int linesize, int x, int y) ++{ ++ int i; ++ dst += y*linesize + x*3; ++ for (i = 0; s[i]; i++, dst += 3) { ++ dst[0] = 0x0; // count - 1 ++ dst[1] = s[i]; // char ++ dst[2] = 0x0f; // background / foreground ++ } ++} ++ ++#define PRINT_INFO(line, name, idvalue) do { \ ++ snprintf(intbuf, sizeof(intbuf), "%.0f", var_values[idvalue]); \ ++ write_text(pkt->data, name ":", modplug->linesize, 0+1, line+1); \ ++ write_text(pkt->data, intbuf, modplug->linesize, 10+1, line+1); \ ++} while (0) ++ ++static int modplug_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ ModPlugContext *modplug = s->priv_data; ++ ++ if (modplug->video_stream) { ++ modplug->video_switch ^= 1; // one video packet for one audio packet ++ if (modplug->video_switch) { ++ double var_values[VAR_VARS_NB]; ++ ++ var_values[VAR_W ] = modplug->w; ++ var_values[VAR_H ] = modplug->h; ++ var_values[VAR_TIME ] = modplug->packet_count * modplug->ts_per_packet; ++ var_values[VAR_SPEED ] = ModPlug_GetCurrentSpeed (modplug->f); ++ var_values[VAR_TEMPO ] = ModPlug_GetCurrentTempo (modplug->f); ++ var_values[VAR_ORDER ] = ModPlug_GetCurrentOrder (modplug->f); ++ var_values[VAR_PATTERN] = ModPlug_GetCurrentPattern(modplug->f); ++ var_values[VAR_ROW ] = ModPlug_GetCurrentRow (modplug->f); ++ ++ if (av_new_packet(pkt, modplug->fsize) < 0) ++ return AVERROR(ENOMEM); ++ pkt->stream_index = 1; ++ memset(pkt->data, 0, modplug->fsize); ++ ++ if (modplug->print_textinfo) { ++ char intbuf[32]; ++ PRINT_INFO(0, "speed", VAR_SPEED); ++ PRINT_INFO(1, "tempo", VAR_TEMPO); ++ PRINT_INFO(2, "order", VAR_ORDER); ++ PRINT_INFO(3, "pattern", VAR_PATTERN); ++ PRINT_INFO(4, "row", VAR_ROW); ++ PRINT_INFO(5, "ts", VAR_TIME); ++ } ++ ++ if (modplug->expr) { ++ int x, y; ++ for (y = 0; y < modplug->h; y++) { ++ for (x = 0; x < modplug->w; x++) { ++ double color; ++ var_values[VAR_X] = x; ++ var_values[VAR_Y] = y; ++ color = av_expr_eval(modplug->expr, var_values, NULL); ++ pkt->data[y*modplug->linesize + x*3 + 2] |= av_clip((int)color, 0, 0xf)<<4; ++ } ++ } ++ } ++ pkt->pts = pkt->dts = var_values[VAR_TIME]; ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ return 0; ++ } ++ } ++ ++ if (av_new_packet(pkt, AUDIO_PKT_SIZE) < 0) ++ return AVERROR(ENOMEM); ++ ++ if (modplug->video_stream) ++ pkt->pts = pkt->dts = modplug->packet_count++ * modplug->ts_per_packet; ++ ++ pkt->size = ModPlug_Read(modplug->f, pkt->data, AUDIO_PKT_SIZE); ++ if (pkt->size <= 0) { ++ av_free_packet(pkt); ++ return pkt->size == 0 ? AVERROR_EOF : AVERROR(EIO); ++ } ++ return 0; ++} ++ ++static int modplug_read_close(AVFormatContext *s) ++{ ++ ModPlugContext *modplug = s->priv_data; ++ ModPlug_Unload(modplug->f); ++ av_freep(&modplug->buf); ++ return 0; ++} ++ ++static int modplug_read_seek(AVFormatContext *s, int stream_idx, int64_t ts, int flags) ++{ ++ ModPlugContext *modplug = s->priv_data; ++ ModPlug_Seek(modplug->f, (int)ts); ++ if (modplug->video_stream) ++ modplug->packet_count = ts / modplug->ts_per_packet; ++ return 0; ++} ++ ++static const AVClass modplug_class = { ++ .class_name = "ModPlug demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_libmodplug_demuxer = { ++ .name = "libmodplug", ++ .long_name = NULL_IF_CONFIG_SMALL("ModPlug demuxer"), ++ .priv_data_size = sizeof(ModPlugContext), ++ .read_header = modplug_read_header, ++ .read_packet = modplug_read_packet, ++ .read_close = modplug_read_close, ++ .read_seek = modplug_read_seek, ++ .extensions = "669,abc,amf,ams,dbm,dmf,dsm,far,it,mdl,med,mid,mod,mt2,mtm,okt,psm,ptm,s3m,stm,ult,umx,xm" ++ ",itgz,itr,itz,mdgz,mdr,mdz,s3gz,s3r,s3z,xmgz,xmr,xmz", // compressed mods ++ .priv_class = &modplug_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libnut.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libnut.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/libnut.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/libnut.c 2012-05-14 14:08:55.002353426 +0200 +@@ -26,6 +26,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + #include + +@@ -46,15 +47,15 @@ + + #if CONFIG_LIBNUT_MUXER + static int av_write(void * h, size_t len, const uint8_t * buf) { +- ByteIOContext * bc = h; +- put_buffer(bc, buf, len); +- //put_flush_packet(bc); ++ AVIOContext * bc = h; ++ avio_write(bc, buf, len); ++ //avio_flush(bc); + return len; + } + + static int nut_write_header(AVFormatContext * avf) { + NUTContext * priv = avf->priv_data; +- ByteIOContext * bc = avf->pb; ++ AVIOContext * bc = avf->pb; + nut_muxer_opts_tt mopts = { + .output = { + .priv = bc, +@@ -70,6 +71,8 @@ + int i; + + priv->s = s = av_mallocz((avf->nb_streams + 1) * sizeof*s); ++ if(!s) ++ return AVERROR(ENOMEM); + + for (i = 0; i < avf->nb_streams; i++) { + AVCodecContext * codec = avf->streams[i]->codec; +@@ -92,7 +95,7 @@ + for (j = 0; j < s[i].fourcc_len; j++) s[i].fourcc[j] = (fourcc >> (j*8)) & 0xFF; + + ff_parse_specific_params(codec, &num, &ssize, &denom); +- av_set_pts_info(avf->streams[i], 60, denom, num); ++ avpriv_set_pts_info(avf->streams[i], 60, denom, num); + + s[i].time_base.num = denom; + s[i].time_base.den = num; +@@ -137,12 +140,12 @@ + } + + static int nut_write_trailer(AVFormatContext * avf) { +- ByteIOContext * bc = avf->pb; ++ AVIOContext * bc = avf->pb; + NUTContext * priv = avf->priv_data; + int i; + + nut_muxer_uninit_reorder(priv->nut); +- put_flush_packet(bc); ++ avio_flush(bc); + + for(i = 0; priv->s[i].type != -1; i++ ) av_freep(&priv->s[i].fourcc); + av_freep(&priv->s); +@@ -151,16 +154,16 @@ + } + + AVOutputFormat ff_libnut_muxer = { +- "libnut", +- "nut format", +- "video/x-nut", +- "nut", +- sizeof(NUTContext), +- CODEC_ID_VORBIS, +- CODEC_ID_MPEG4, +- nut_write_header, +- nut_write_packet, +- nut_write_trailer, ++ .name = "libnut", ++ .long_name = "nut format", ++ .mime_type = "video/x-nut", ++ .extensions = "nut", ++ .priv_data_size = sizeof(NUTContext), ++ .audio_codec = CODEC_ID_VORBIS, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = nut_write_header, ++ .write_packet = nut_write_packet, ++ .write_trailer = nut_write_trailer, + .flags = AVFMT_GLOBALHEADER, + }; + #endif /* CONFIG_LIBNUT_MUXER */ +@@ -172,22 +175,22 @@ + } + + static size_t av_read(void * h, size_t len, uint8_t * buf) { +- ByteIOContext * bc = h; +- return get_buffer(bc, buf, len); ++ AVIOContext * bc = h; ++ return avio_read(bc, buf, len); + } + + static off_t av_seek(void * h, long long pos, int whence) { +- ByteIOContext * bc = h; ++ AVIOContext * bc = h; + if (whence == SEEK_END) { +- pos = url_fsize(bc) + pos; ++ pos = avio_size(bc) + pos; + whence = SEEK_SET; + } +- return url_fseek(bc, pos, whence); ++ return avio_seek(bc, pos, whence); + } + + static int nut_read_header(AVFormatContext * avf, AVFormatParameters * ap) { + NUTContext * priv = avf->priv_data; +- ByteIOContext * bc = avf->pb; ++ AVIOContext * bc = avf->pb; + nut_demuxer_opts_tt dopts = { + .input = { + .priv = bc, +@@ -204,16 +207,20 @@ + nut_stream_header_tt * s; + int ret, i; + ++ if(!nut) ++ return -1; ++ + if ((ret = nut_read_headers(nut, &s, NULL))) { + av_log(avf, AV_LOG_ERROR, " NUT error: %s\n", nut_error(ret)); + nut_demuxer_uninit(nut); ++ priv->nut = NULL; + return -1; + } + + priv->s = s; + + for (i = 0; s[i].type != -1 && i < 2; i++) { +- AVStream * st = av_new_stream(avf, i); ++ AVStream * st = avformat_new_stream(avf, NULL); + int j; + + for (j = 0; j < s[i].fourcc_len && j < 8; j++) st->codec->codec_tag |= s[i].fourcc[j]<<(j*8); +@@ -223,10 +230,15 @@ + st->codec->extradata_size = s[i].codec_specific_len; + if (st->codec->extradata_size) { + st->codec->extradata = av_mallocz(st->codec->extradata_size); ++ if(!st->codec->extradata){ ++ nut_demuxer_uninit(nut); ++ priv->nut = NULL; ++ return AVERROR(ENOMEM); ++ } + memcpy(st->codec->extradata, s[i].codec_specific, st->codec->extradata_size); + } + +- av_set_pts_info(avf->streams[i], 60, s[i].time_base.num, s[i].time_base.den); ++ avpriv_set_pts_info(avf->streams[i], 60, s[i].time_base.num, s[i].time_base.den); + st->start_time = 0; + st->duration = s[i].max_pts; + +@@ -272,7 +284,7 @@ + if (pd.flags & NUT_FLAG_KEY) pkt->flags |= AV_PKT_FLAG_KEY; + pkt->pts = pd.pts; + pkt->stream_index = pd.stream; +- pkt->pos = url_ftell(avf->pb); ++ pkt->pos = avio_tell(avf->pb); + + ret = nut_read_frame(priv->nut, &pd.len, pkt->data); + +@@ -298,13 +310,13 @@ + } + + AVInputFormat ff_libnut_demuxer = { +- "libnut", +- NULL_IF_CONFIG_SMALL("NUT format"), +- sizeof(NUTContext), +- nut_probe, +- nut_read_header, +- nut_read_packet, +- nut_read_close, +- nut_read_seek, ++ .name = "libnut", ++ .long_name = NULL_IF_CONFIG_SMALL("NUT format"), ++ .priv_data_size = sizeof(NUTContext), ++ .read_probe = nut_probe, ++ .read_header = nut_read_header, ++ .read_packet = nut_read_packet, ++ .read_close = nut_read_close, ++ .read_seek = nut_read_seek, + .extensions = "nut", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/librtmp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/librtmp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/librtmp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/librtmp.c 2012-05-14 14:08:55.003353446 +0200 +@@ -24,7 +24,9 @@ + * RTMP protocol based on http://rtmpdump.mplayerhq.hu/ librtmp + */ + ++#include "libavutil/mathematics.h" + #include "avformat.h" ++#include "url.h" + + #include + #include +@@ -50,7 +52,6 @@ + RTMP *r = s->priv_data; + + RTMP_Close(r); +- av_free(r); + return 0; + } + +@@ -68,13 +69,9 @@ + */ + static int rtmp_open(URLContext *s, const char *uri, int flags) + { +- RTMP *r; ++ RTMP *r = s->priv_data; + int rc; + +- r = av_mallocz(sizeof(RTMP)); +- if (!r) +- return AVERROR(ENOMEM); +- + switch (av_log_get_level()) { + default: + case AV_LOG_FATAL: rc = RTMP_LOGCRIT; break; +@@ -93,7 +90,7 @@ + goto fail; + } + +- if (flags & URL_WRONLY) ++ if (flags & AVIO_FLAG_WRITE) + RTMP_EnableWrite(r); + + if (!RTMP_Connect(r, NULL) || !RTMP_ConnectStream(r, 0)) { +@@ -101,11 +98,9 @@ + goto fail; + } + +- s->priv_data = r; + s->is_streamed = 1; + return 0; + fail: +- av_free(r); + return rc; + } + +@@ -158,66 +153,66 @@ + } + + URLProtocol ff_rtmp_protocol = { +- "rtmp", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, +- NULL, /* next */ +- rtmp_read_pause, +- rtmp_read_seek, +- rtmp_get_file_handle ++ .name = "rtmp", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .url_read_pause = rtmp_read_pause, ++ .url_read_seek = rtmp_read_seek, ++ .url_get_file_handle = rtmp_get_file_handle, ++ .priv_data_size = sizeof(RTMP), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; + + URLProtocol ff_rtmpt_protocol = { +- "rtmpt", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, +- NULL, /* next */ +- rtmp_read_pause, +- rtmp_read_seek, +- rtmp_get_file_handle ++ .name = "rtmpt", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .url_read_pause = rtmp_read_pause, ++ .url_read_seek = rtmp_read_seek, ++ .url_get_file_handle = rtmp_get_file_handle, ++ .priv_data_size = sizeof(RTMP), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; + + URLProtocol ff_rtmpe_protocol = { +- "rtmpe", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, +- NULL, /* next */ +- rtmp_read_pause, +- rtmp_read_seek, +- rtmp_get_file_handle ++ .name = "rtmpe", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .url_read_pause = rtmp_read_pause, ++ .url_read_seek = rtmp_read_seek, ++ .url_get_file_handle = rtmp_get_file_handle, ++ .priv_data_size = sizeof(RTMP), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; + + URLProtocol ff_rtmpte_protocol = { +- "rtmpte", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, +- NULL, /* next */ +- rtmp_read_pause, +- rtmp_read_seek, +- rtmp_get_file_handle ++ .name = "rtmpte", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .url_read_pause = rtmp_read_pause, ++ .url_read_seek = rtmp_read_seek, ++ .url_get_file_handle = rtmp_get_file_handle, ++ .priv_data_size = sizeof(RTMP), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; + + URLProtocol ff_rtmps_protocol = { +- "rtmps", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, +- NULL, /* next */ +- rtmp_read_pause, +- rtmp_read_seek, +- rtmp_get_file_handle ++ .name = "rtmps", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .url_read_pause = rtmp_read_pause, ++ .url_read_seek = rtmp_read_seek, ++ .url_get_file_handle = rtmp_get_file_handle, ++ .priv_data_size = sizeof(RTMP), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/lmlm4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/lmlm4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/lmlm4.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/lmlm4.c 2012-05-14 14:08:55.003353446 +0200 +@@ -24,6 +24,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define LMLM4_I_FRAME 0x00 + #define LMLM4_P_FRAME 0x01 +@@ -60,14 +61,14 @@ + static int lmlm4_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + +- if (!(st = av_new_stream(s, 0))) ++ if (!(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG4; + st->need_parsing = AVSTREAM_PARSE_HEADERS; +- av_set_pts_info(st, 64, 1001, 30000); ++ avpriv_set_pts_info(st, 64, 1001, 30000); + +- if (!(st = av_new_stream(s, 1))) ++ if (!(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MP2; +@@ -78,13 +79,13 @@ + } + + static int lmlm4_read_packet(AVFormatContext *s, AVPacket *pkt) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret; + unsigned int frame_type, packet_size, padding, frame_size; + +- get_be16(pb); /* channel number */ +- frame_type = get_be16(pb); +- packet_size = get_be32(pb); ++ avio_rb16(pb); /* channel number */ ++ frame_type = avio_rb16(pb); ++ packet_size = avio_rb32(pb); + padding = -packet_size & 511; + frame_size = packet_size - 8; + +@@ -100,7 +101,7 @@ + if ((ret = av_get_packet(pb, pkt, frame_size)) <= 0) + return AVERROR(EIO); + +- url_fskip(pb, padding); ++ avio_skip(pb, padding); + + switch (frame_type) { + case LMLM4_I_FRAME: +@@ -118,10 +119,9 @@ + } + + AVInputFormat ff_lmlm4_demuxer = { +- "lmlm4", +- NULL_IF_CONFIG_SMALL("lmlm4 raw format"), +- 0, +- lmlm4_probe, +- lmlm4_read_header, +- lmlm4_read_packet, ++ .name = "lmlm4", ++ .long_name = NULL_IF_CONFIG_SMALL("lmlm4 raw format"), ++ .read_probe = lmlm4_probe, ++ .read_header = lmlm4_read_header, ++ .read_packet = lmlm4_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/loasdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/loasdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/loasdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/loasdec.c 2012-05-14 14:08:55.004353466 +0200 +@@ -0,0 +1,89 @@ ++/* ++ * LOAS AudioSyncStream demuxer ++ * Copyright (c) 2008 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/internal.h" ++#include "avformat.h" ++#include "internal.h" ++#include "rawdec.h" ++ ++static int loas_probe(AVProbeData *p) ++{ ++ int max_frames = 0, first_frames = 0; ++ int fsize, frames; ++ uint8_t *buf0 = p->buf; ++ uint8_t *buf2; ++ uint8_t *buf; ++ uint8_t *end = buf0 + p->buf_size - 3; ++ buf = buf0; ++ ++ for(; buf < end; buf= buf2+1) { ++ buf2 = buf; ++ ++ for(frames = 0; buf2 < end; frames++) { ++ uint32_t header = AV_RB24(buf2); ++ if((header >> 13) != 0x2B7) ++ break; ++ fsize = (header & 0x1FFF) + 3; ++ if(fsize < 7) ++ break; ++ fsize = FFMIN(fsize, end - buf2); ++ buf2 += fsize; ++ } ++ max_frames = FFMAX(max_frames, frames); ++ if(buf == buf0) ++ first_frames= frames; ++ } ++ if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1; ++ else if(max_frames>100)return AVPROBE_SCORE_MAX/2; ++ else if(max_frames>=3) return AVPROBE_SCORE_MAX/4; ++ else if(max_frames>=1) return 1; ++ else return 0; ++} ++ ++static int loas_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ AVStream *st; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = s->iformat->value; ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ ++ //LCM of all possible AAC sample rates ++ avpriv_set_pts_info(st, 64, 1, 28224000); ++ ++ return 0; ++} ++ ++AVInputFormat ff_loas_demuxer = { ++ .name = "loas", ++ .long_name = NULL_IF_CONFIG_SMALL("LOAS AudioSyncStream"), ++ .read_probe = loas_probe, ++ .read_header = loas_read_header, ++ .read_packet = ff_raw_read_partial_packet, ++ .flags= AVFMT_GENERIC_INDEX, ++ .value = CODEC_ID_AAC_LATM, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/lxfdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/lxfdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/lxfdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/lxfdec.c 2012-05-14 14:08:55.005353486 +0200 +@@ -21,6 +21,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + + #define LXF_PACKET_HEADER_SIZE 60 +@@ -86,7 +87,7 @@ + uint8_t buf[LXF_IDENT_LENGTH]; + int ret; + +- if ((ret = get_buffer(s->pb, buf, LXF_IDENT_LENGTH)) != LXF_IDENT_LENGTH) ++ if ((ret = avio_read(s->pb, buf, LXF_IDENT_LENGTH)) != LXF_IDENT_LENGTH) + return ret < 0 ? ret : AVERROR_EOF; + + while (memcmp(buf, LXF_IDENT, LXF_IDENT_LENGTH)) { +@@ -94,7 +95,7 @@ + return AVERROR_EOF; + + memmove(buf, &buf[1], LXF_IDENT_LENGTH-1); +- buf[LXF_IDENT_LENGTH-1] = get_byte(s->pb); ++ buf[LXF_IDENT_LENGTH-1] = avio_r8(s->pb); + } + + memcpy(header, LXF_IDENT, LXF_IDENT_LENGTH); +@@ -111,7 +112,7 @@ + */ + static int get_packet_header(AVFormatContext *s, uint8_t *header, uint32_t *format) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int track_size, samples, ret; + AVStream *st; + +@@ -120,7 +121,7 @@ + return ret; + + //read the rest of the packet header +- if ((ret = get_buffer(pb, header + LXF_IDENT_LENGTH, ++ if ((ret = avio_read(pb, header + LXF_IDENT_LENGTH, + LXF_PACKET_HEADER_SIZE - LXF_IDENT_LENGTH)) != + LXF_PACKET_HEADER_SIZE - LXF_IDENT_LENGTH) { + return ret < 0 ? ret : AVERROR_EOF; +@@ -137,7 +138,7 @@ + case 0: + //video + //skip VBI data and metadata +- url_fskip(pb, (int64_t)(uint32_t)AV_RL32(&header[44]) + ++ avio_skip(pb, (int64_t)(uint32_t)AV_RL32(&header[44]) + + (int64_t)(uint32_t)AV_RL32(&header[52])); + break; + case 1: +@@ -174,14 +175,14 @@ + //use audio packet size to determine video standard + //for NTSC we have one 8008-sample audio frame per five video frames + if (samples == LXF_SAMPLERATE * 5005 / 30000) { +- av_set_pts_info(s->streams[0], 64, 1001, 30000); ++ avpriv_set_pts_info(s->streams[0], 64, 1001, 30000); + } else { + //assume PAL, but warn if we don't have 1920 samples + if (samples != LXF_SAMPLERATE / 25) + av_log(s, AV_LOG_WARNING, + "video doesn't seem to be PAL or NTSC. guessing PAL\n"); + +- av_set_pts_info(s->streams[0], 64, 1, 25); ++ avpriv_set_pts_info(s->streams[0], 64, 1, 25); + } + + //TODO: warning if track mask != (1 << channels) - 1? +@@ -198,7 +199,7 @@ + static int lxf_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + LXFDemuxContext *lxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t header[LXF_PACKET_HEADER_SIZE], header_data[LXF_HEADER_DATA_SIZE]; + int ret; + AVStream *st; +@@ -214,11 +215,11 @@ + return AVERROR_INVALIDDATA; + } + +- if ((ret = get_buffer(pb, header_data, LXF_HEADER_DATA_SIZE)) != LXF_HEADER_DATA_SIZE) ++ if ((ret = avio_read(pb, header_data, LXF_HEADER_DATA_SIZE)) != LXF_HEADER_DATA_SIZE) + return ret < 0 ? ret : AVERROR_EOF; + +- if (!(st = av_new_stream(s, 0))) +- return AVERROR_NOMEM; ++ if (!(st = avformat_new_stream(s, NULL))) ++ return AVERROR(ENOMEM); + + st->duration = AV_RL32(&header_data[32]); + video_params = AV_RL32(&header_data[40]); +@@ -243,19 +244,19 @@ + av_log(s, AV_LOG_WARNING, "VBI data not yet supported\n"); + + if ((lxf->channels = (disk_params >> 2) & 0xF)) { +- if (!(st = av_new_stream(s, 1))) +- return AVERROR_NOMEM; ++ if (!(st = avformat_new_stream(s, NULL))) ++ return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->sample_rate = LXF_SAMPLERATE; + st->codec->channels = lxf->channels; + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + } + + if (format == 1) { + //skip extended field data +- url_fskip(s->pb, (uint32_t)AV_RL32(&header[40])); ++ avio_skip(s->pb, (uint32_t)AV_RL32(&header[40])); + } + + return 0; +@@ -281,7 +282,7 @@ + static int lxf_read_packet(AVFormatContext *s, AVPacket *pkt) + { + LXFDemuxContext *lxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t header[LXF_PACKET_HEADER_SIZE], *buf; + AVStream *ast = NULL; + uint32_t stream, format; +@@ -315,7 +316,7 @@ + //read non-20-bit audio data into lxf->temp so we can deplanarize it + buf = ast && ast->codec->codec_id != CODEC_ID_PCM_LXF ? lxf->temp : pkt->data; + +- if ((ret2 = get_buffer(pb, buf, ret)) != ret) { ++ if ((ret2 = avio_read(pb, buf, ret)) != ret) { + av_free_packet(pkt); + return ret2 < 0 ? ret2 : AVERROR_EOF; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/m4vdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/m4vdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/m4vdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/m4vdec.c 2012-05-14 14:08:55.005353486 +0200 +@@ -45,18 +45,8 @@ + } + + if (VOP >= VISO && VOP >= VOL && VO >= VOL && VOL > 0 && res==0) +- return AVPROBE_SCORE_MAX/2; ++ return VOP+VO > 3 ? AVPROBE_SCORE_MAX/2 : AVPROBE_SCORE_MAX/4; + return 0; + } + +-AVInputFormat ff_m4v_demuxer = { +- "m4v", +- NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"), +- 0, +- mpeg4video_probe, /** probing for MPEG-4 data */ +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .extensions = "m4v", +- .value = CODEC_ID_MPEG4, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(m4v, "raw MPEG-4 video format", mpeg4video_probe, "m4v", CODEC_ID_MPEG4) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/Makefile 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/Makefile 2012-05-14 14:08:54.856350488 +0200 +@@ -1,7 +1,7 @@ + include $(SUBDIR)../config.mak + + NAME = avformat +-FFLIBS = avcodec avcore avutil ++FFLIBS = avcodec avutil + + HEADERS = avformat.h avio.h version.h + +@@ -10,22 +10,28 @@ + id3v1.o \ + id3v2.o \ + metadata.o \ +- metadata_compat.o \ + options.o \ + os_support.o \ ++ riff.o \ + sdp.o \ + seek.o \ + utils.o \ + ++OBJS-$(CONFIG_NETWORK) += network.o ++ + # muxers/demuxers + OBJS-$(CONFIG_A64_MUXER) += a64.o + OBJS-$(CONFIG_AAC_DEMUXER) += aacdec.o rawdec.o + OBJS-$(CONFIG_AC3_DEMUXER) += ac3dec.o rawdec.o + OBJS-$(CONFIG_AC3_MUXER) += rawenc.o ++OBJS-$(CONFIG_ACT_DEMUXER) += act.o ++OBJS-$(CONFIG_ADF_DEMUXER) += bintext.o sauce.o ++OBJS-$(CONFIG_ADX_DEMUXER) += adxdec.o ++OBJS-$(CONFIG_ADX_MUXER) += rawenc.o + OBJS-$(CONFIG_ADTS_MUXER) += adtsenc.o + OBJS-$(CONFIG_AEA_DEMUXER) += aea.o pcm.o +-OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o riff.o pcm.o +-OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o riff.o ++OBJS-$(CONFIG_AIFF_DEMUXER) += aiffdec.o pcm.o isom.o ++OBJS-$(CONFIG_AIFF_MUXER) += aiffenc.o isom.o + OBJS-$(CONFIG_AMR_DEMUXER) += amr.o + OBJS-$(CONFIG_AMR_MUXER) += amr.o + OBJS-$(CONFIG_ANM_DEMUXER) += anm.o +@@ -33,28 +39,35 @@ + OBJS-$(CONFIG_APE_DEMUXER) += ape.o apetag.o + OBJS-$(CONFIG_APPLEHTTP_DEMUXER) += applehttp.o + OBJS-$(CONFIG_ASF_DEMUXER) += asfdec.o asf.o asfcrypt.o \ +- riff.o avlanguage.o +-OBJS-$(CONFIG_ASF_MUXER) += asfenc.o asf.o riff.o ++ avlanguage.o ++OBJS-$(CONFIG_ASF_MUXER) += asfenc.o asf.o + OBJS-$(CONFIG_ASS_DEMUXER) += assdec.o + OBJS-$(CONFIG_ASS_MUXER) += assenc.o + OBJS-$(CONFIG_AU_DEMUXER) += au.o pcm.o + OBJS-$(CONFIG_AU_MUXER) += au.o +-OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o riff.o avi.o +-OBJS-$(CONFIG_AVI_MUXER) += avienc.o riff.o avi.o ++OBJS-$(CONFIG_AVI_DEMUXER) += avidec.o ++OBJS-$(CONFIG_AVI_MUXER) += avienc.o + OBJS-$(CONFIG_AVISYNTH) += avisynth.o + OBJS-$(CONFIG_AVM2_MUXER) += swfenc.o + OBJS-$(CONFIG_AVS_DEMUXER) += avs.o vocdec.o voc.o + OBJS-$(CONFIG_BETHSOFTVID_DEMUXER) += bethsoftvid.o + OBJS-$(CONFIG_BFI_DEMUXER) += bfi.o + OBJS-$(CONFIG_BINK_DEMUXER) += bink.o ++OBJS-$(CONFIG_BINTEXT_DEMUXER) += bintext.o sauce.o ++OBJS-$(CONFIG_BIT_DEMUXER) += bit.o ++OBJS-$(CONFIG_BIT_MUXER) += bit.o ++OBJS-$(CONFIG_BMV_DEMUXER) += bmv.o + OBJS-$(CONFIG_C93_DEMUXER) += c93.o vocdec.o voc.o +-OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o riff.o isom.o ++OBJS-$(CONFIG_CAF_DEMUXER) += cafdec.o caf.o mov.o mov_chan.o \ ++ isom.o ++OBJS-$(CONFIG_CAF_MUXER) += cafenc.o caf.o riff.o isom.o + OBJS-$(CONFIG_CAVSVIDEO_DEMUXER) += cavsvideodec.o rawdec.o + OBJS-$(CONFIG_CAVSVIDEO_MUXER) += rawenc.o + OBJS-$(CONFIG_CDG_DEMUXER) += cdg.o + OBJS-$(CONFIG_CRC_MUXER) += crcenc.o + OBJS-$(CONFIG_DAUD_DEMUXER) += daud.o + OBJS-$(CONFIG_DAUD_MUXER) += daud.o ++OBJS-$(CONFIG_DFA_DEMUXER) += dfa.o + OBJS-$(CONFIG_DIRAC_DEMUXER) += diracdec.o rawdec.o + OBJS-$(CONFIG_DIRAC_MUXER) += rawenc.o + OBJS-$(CONFIG_DNXHD_DEMUXER) += dnxhddec.o rawdec.o +@@ -64,7 +77,7 @@ + OBJS-$(CONFIG_DTS_MUXER) += rawenc.o + OBJS-$(CONFIG_DV_DEMUXER) += dv.o + OBJS-$(CONFIG_DV_MUXER) += dvenc.o +-OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o riff.o ++OBJS-$(CONFIG_DXA_DEMUXER) += dxa.o + OBJS-$(CONFIG_EA_CDATA_DEMUXER) += eacdata.o + OBJS-$(CONFIG_EA_DEMUXER) += electronicarts.o + OBJS-$(CONFIG_EAC3_DEMUXER) += ac3dec.o rawdec.o +@@ -87,18 +100,23 @@ + OBJS-$(CONFIG_FRAMECRC_MUXER) += framecrcenc.o + OBJS-$(CONFIG_FRAMEMD5_MUXER) += md5enc.o + OBJS-$(CONFIG_GIF_MUXER) += gif.o +-OBJS-$(CONFIG_GSM_DEMUXER) += rawdec.o ++OBJS-$(CONFIG_GSM_DEMUXER) += gsmdec.o + OBJS-$(CONFIG_GXF_DEMUXER) += gxf.o + OBJS-$(CONFIG_GXF_MUXER) += gxfenc.o audiointerleave.o + OBJS-$(CONFIG_G722_DEMUXER) += rawdec.o + OBJS-$(CONFIG_G722_MUXER) += rawenc.o ++OBJS-$(CONFIG_G723_1_DEMUXER) += g723_1.o ++OBJS-$(CONFIG_G723_1_MUXER) += rawenc.o ++OBJS-$(CONFIG_G729_DEMUXER) += g729dec.o + OBJS-$(CONFIG_H261_DEMUXER) += h261dec.o rawdec.o + OBJS-$(CONFIG_H261_MUXER) += rawenc.o + OBJS-$(CONFIG_H263_DEMUXER) += h263dec.o rawdec.o + OBJS-$(CONFIG_H263_MUXER) += rawenc.o + OBJS-$(CONFIG_H264_DEMUXER) += h264dec.o rawdec.o + OBJS-$(CONFIG_H264_MUXER) += rawenc.o ++OBJS-$(CONFIG_ICO_DEMUXER) += icodec.o + OBJS-$(CONFIG_IDCIN_DEMUXER) += idcin.o ++OBJS-$(CONFIG_IDF_DEMUXER) += bintext.o + OBJS-$(CONFIG_IFF_DEMUXER) += iff.o + OBJS-$(CONFIG_IMAGE2_DEMUXER) += img2.o + OBJS-$(CONFIG_IMAGE2_MUXER) += img2.o +@@ -108,30 +126,38 @@ + OBJS-$(CONFIG_IPMOVIE_DEMUXER) += ipmovie.o + OBJS-$(CONFIG_ISS_DEMUXER) += iss.o + OBJS-$(CONFIG_IV8_DEMUXER) += iv8.o +-OBJS-$(CONFIG_IVF_DEMUXER) += ivfdec.o riff.o ++OBJS-$(CONFIG_IVF_DEMUXER) += ivfdec.o + OBJS-$(CONFIG_IVF_MUXER) += ivfenc.o ++OBJS-$(CONFIG_JV_DEMUXER) += jvdec.o ++OBJS-$(CONFIG_LATM_DEMUXER) += rawdec.o ++OBJS-$(CONFIG_LATM_MUXER) += latmenc.o + OBJS-$(CONFIG_LMLM4_DEMUXER) += lmlm4.o ++OBJS-$(CONFIG_LOAS_DEMUXER) += loasdec.o + OBJS-$(CONFIG_LXF_DEMUXER) += lxfdec.o + OBJS-$(CONFIG_M4V_DEMUXER) += m4vdec.o rawdec.o + OBJS-$(CONFIG_M4V_MUXER) += rawenc.o + OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \ +- riff.o isom.o rmdec.o rm.o ++ isom.o rmdec.o rm.o + OBJS-$(CONFIG_MATROSKA_MUXER) += matroskaenc.o matroska.o \ +- riff.o isom.o avc.o \ ++ isom.o avc.o \ + flacenc_header.o avlanguage.o + OBJS-$(CONFIG_MD5_MUXER) += md5enc.o ++OBJS-$(CONFIG_MICRODVD_DEMUXER) += microdvddec.o ++OBJS-$(CONFIG_MICRODVD_MUXER) += microdvdenc.o rawenc.o + OBJS-$(CONFIG_MJPEG_DEMUXER) += rawdec.o + OBJS-$(CONFIG_MJPEG_MUXER) += rawenc.o + OBJS-$(CONFIG_MLP_DEMUXER) += rawdec.o + OBJS-$(CONFIG_MLP_MUXER) += rawenc.o + OBJS-$(CONFIG_MM_DEMUXER) += mm.o + OBJS-$(CONFIG_MMF_DEMUXER) += mmf.o pcm.o +-OBJS-$(CONFIG_MMF_MUXER) += mmf.o riff.o +-OBJS-$(CONFIG_MOV_DEMUXER) += mov.o riff.o isom.o +-OBJS-$(CONFIG_MOV_MUXER) += movenc.o riff.o isom.o avc.o movenchint.o +-OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o ++OBJS-$(CONFIG_MMF_MUXER) += mmf.o ++OBJS-$(CONFIG_MOV_DEMUXER) += mov.o isom.o mov_chan.o ++OBJS-$(CONFIG_MOV_MUXER) += movenc.o isom.o avc.o \ ++ movenchint.o rtpenc_chain.o \ ++ mov_chan.o ++OBJS-$(CONFIG_MP2_MUXER) += mp3enc.o rawenc.o + OBJS-$(CONFIG_MP3_DEMUXER) += mp3dec.o +-OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o ++OBJS-$(CONFIG_MP3_MUXER) += mp3enc.o rawenc.o id3v2enc.o + OBJS-$(CONFIG_MPC_DEMUXER) += mpc.o apetag.o + OBJS-$(CONFIG_MPC8_DEMUXER) += mpc8.o + OBJS-$(CONFIG_MPEG1SYSTEM_MUXER) += mpegenc.o +@@ -155,10 +181,11 @@ + OBJS-$(CONFIG_NC_DEMUXER) += ncdec.o + OBJS-$(CONFIG_NSV_DEMUXER) += nsvdec.o + OBJS-$(CONFIG_NULL_MUXER) += nullenc.o +-OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o riff.o +-OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o riff.o +-OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o riff.o ++OBJS-$(CONFIG_NUT_DEMUXER) += nutdec.o nut.o ++OBJS-$(CONFIG_NUT_MUXER) += nutenc.o nut.o ++OBJS-$(CONFIG_NUV_DEMUXER) += nuv.o + OBJS-$(CONFIG_OGG_DEMUXER) += oggdec.o \ ++ oggparsecelt.o \ + oggparsedirac.o \ + oggparseflac.o \ + oggparseogm.o \ +@@ -166,11 +193,11 @@ + oggparsespeex.o \ + oggparsetheora.o \ + oggparsevorbis.o \ +- riff.o \ + vorbiscomment.o + OBJS-$(CONFIG_OGG_MUXER) += oggenc.o \ + vorbiscomment.o +-OBJS-$(CONFIG_OMA_DEMUXER) += oma.o pcm.o ++OBJS-$(CONFIG_OMA_DEMUXER) += omadec.o pcm.o oma.o ++OBJS-$(CONFIG_OMA_MUXER) += omaenc.o rawenc.o oma.o id3v2enc.o + OBJS-$(CONFIG_PCM_ALAW_DEMUXER) += pcmdec.o pcm.o rawdec.o + OBJS-$(CONFIG_PCM_ALAW_MUXER) += pcmenc.o rawenc.o + OBJS-$(CONFIG_PCM_F32BE_DEMUXER) += pcmdec.o pcm.o rawdec.o +@@ -211,6 +238,7 @@ + OBJS-$(CONFIG_PCM_U32LE_MUXER) += pcmenc.o rawenc.o + OBJS-$(CONFIG_PCM_U8_DEMUXER) += pcmdec.o pcm.o rawdec.o + OBJS-$(CONFIG_PCM_U8_MUXER) += pcmenc.o rawenc.o ++OBJS-$(CONFIG_PMP_DEMUXER) += pmpdec.o + OBJS-$(CONFIG_PVA_DEMUXER) += pva.o + OBJS-$(CONFIG_QCP_DEMUXER) += qcp.o + OBJS-$(CONFIG_R3D_DEMUXER) += r3d.o +@@ -226,6 +254,7 @@ + OBJS-$(CONFIG_RPL_DEMUXER) += rpl.o + OBJS-$(CONFIG_RTP_MUXER) += rtp.o \ + rtpenc_aac.o \ ++ rtpenc_latm.o \ + rtpenc_amr.o \ + rtpenc_h263.o \ + rtpenc_mpv.o \ +@@ -239,6 +268,7 @@ + rtpdec.o \ + rtpdec_amr.o \ + rtpdec_asf.o \ ++ rtpdec_g726.o \ + rtpdec_h263.o \ + rtpdec_h264.o \ + rtpdec_latm.o \ +@@ -254,11 +284,15 @@ + rtpenc_chain.o + OBJS-$(CONFIG_SAP_DEMUXER) += sapdec.o + OBJS-$(CONFIG_SAP_MUXER) += sapenc.o rtpenc_chain.o ++OBJS-$(CONFIG_SBG_DEMUXER) += sbgdec.o + OBJS-$(CONFIG_SDP_DEMUXER) += rtsp.o + OBJS-$(CONFIG_SEGAFILM_DEMUXER) += segafilm.o ++OBJS-$(CONFIG_SEGMENT_MUXER) += segment.o + OBJS-$(CONFIG_SHORTEN_DEMUXER) += rawdec.o + OBJS-$(CONFIG_SIFF_DEMUXER) += siff.o + OBJS-$(CONFIG_SMACKER_DEMUXER) += smacker.o ++OBJS-$(CONFIG_SMJPEG_DEMUXER) += smjpegdec.o smjpeg.o ++OBJS-$(CONFIG_SMJPEG_MUXER) += smjpegenc.o smjpeg.o + OBJS-$(CONFIG_SOL_DEMUXER) += sol.o pcm.o + OBJS-$(CONFIG_SOX_DEMUXER) += soxdec.o pcm.o + OBJS-$(CONFIG_SOX_MUXER) += soxenc.o +@@ -271,6 +305,7 @@ + OBJS-$(CONFIG_SWF_MUXER) += swfenc.o + OBJS-$(CONFIG_THP_DEMUXER) += thp.o + OBJS-$(CONFIG_TIERTEXSEQ_DEMUXER) += tiertexseq.o ++OBJS-$(CONFIG_MKVTIMESTAMP_V2_MUXER) += mkvtimestamp_v2.o + OBJS-$(CONFIG_TMV_DEMUXER) += tmv.o + OBJS-$(CONFIG_TRUEHD_DEMUXER) += rawdec.o + OBJS-$(CONFIG_TRUEHD_MUXER) += rawenc.o +@@ -284,33 +319,44 @@ + OBJS-$(CONFIG_VOC_DEMUXER) += vocdec.o voc.o + OBJS-$(CONFIG_VOC_MUXER) += vocenc.o voc.o + OBJS-$(CONFIG_VQF_DEMUXER) += vqf.o +-OBJS-$(CONFIG_W64_DEMUXER) += wav.o riff.o pcm.o +-OBJS-$(CONFIG_WAV_DEMUXER) += wav.o riff.o pcm.o +-OBJS-$(CONFIG_WAV_MUXER) += wav.o riff.o ++OBJS-$(CONFIG_W64_DEMUXER) += wav.o pcm.o ++OBJS-$(CONFIG_WAV_DEMUXER) += wav.o pcm.o ++OBJS-$(CONFIG_WAV_MUXER) += wav.o + OBJS-$(CONFIG_WC3_DEMUXER) += wc3movie.o + OBJS-$(CONFIG_WEBM_MUXER) += matroskaenc.o matroska.o \ +- riff.o isom.o avc.o \ ++ isom.o avc.o \ + flacenc_header.o avlanguage.o +-OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood.o +-OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood.o +-OBJS-$(CONFIG_WTV_DEMUXER) += wtv.o asf.o asfdec.o mpegts.o riff.o ++OBJS-$(CONFIG_WSAUD_DEMUXER) += westwood_aud.o ++OBJS-$(CONFIG_WSVQA_DEMUXER) += westwood_vqa.o ++OBJS-$(CONFIG_WTV_DEMUXER) += wtvdec.o wtv.o asfdec.o asf.o asfcrypt.o \ ++ avlanguage.o mpegts.o isom.o ++OBJS-$(CONFIG_WTV_MUXER) += wtvenc.o wtv.o asf.o asfenc.o + OBJS-$(CONFIG_WV_DEMUXER) += wv.o apetag.o + OBJS-$(CONFIG_XA_DEMUXER) += xa.o ++OBJS-$(CONFIG_XBIN_DEMUXER) += bintext.o sauce.o ++OBJS-$(CONFIG_XMV_DEMUXER) += xmv.o ++OBJS-$(CONFIG_XWMA_DEMUXER) += xwma.o + OBJS-$(CONFIG_YOP_DEMUXER) += yop.o + OBJS-$(CONFIG_YUV4MPEGPIPE_MUXER) += yuv4mpeg.o + OBJS-$(CONFIG_YUV4MPEGPIPE_DEMUXER) += yuv4mpeg.o + + # external libraries +-OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o riff.o +-OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o riff.o ++OBJS-$(CONFIG_LIBMODPLUG_DEMUXER) += libmodplug.o ++OBJS-$(CONFIG_LIBNUT_DEMUXER) += libnut.o ++OBJS-$(CONFIG_LIBNUT_MUXER) += libnut.o + + # protocols I/O + OBJS+= avio.o aviobuf.o + ++OBJS-$(CONFIG_APPLEHTTP_PROTOCOL) += applehttpproto.o ++OBJS-$(CONFIG_CACHE_PROTOCOL) += cache.o + OBJS-$(CONFIG_CONCAT_PROTOCOL) += concat.o ++OBJS-$(CONFIG_CRYPTO_PROTOCOL) += crypto.o + OBJS-$(CONFIG_FILE_PROTOCOL) += file.o + OBJS-$(CONFIG_GOPHER_PROTOCOL) += gopher.o + OBJS-$(CONFIG_HTTP_PROTOCOL) += http.o httpauth.o ++OBJS-$(CONFIG_HTTPPROXY_PROTOCOL) += http.o httpauth.o ++OBJS-$(CONFIG_HTTPS_PROTOCOL) += http.o httpauth.o + OBJS-$(CONFIG_MMSH_PROTOCOL) += mmsh.o mms.o asf.o + OBJS-$(CONFIG_MMST_PROTOCOL) += mmst.o mms.o asf.o + OBJS-$(CONFIG_MD5_PROTOCOL) += md5proto.o +@@ -323,14 +369,9 @@ + + OBJS-$(CONFIG_RTP_PROTOCOL) += rtpproto.o + OBJS-$(CONFIG_TCP_PROTOCOL) += tcp.o ++OBJS-$(CONFIG_TLS_PROTOCOL) += tls.o + OBJS-$(CONFIG_UDP_PROTOCOL) += udp.o + +-# libavdevice dependencies +-OBJS-$(CONFIG_JACK_INDEV) += timefilter.o +- +-EXAMPLES = output +-TESTPROGS = timefilter +- +-include $(SUBDIR)../subdir.mak +- +-$(SUBDIR)output-example$(EXESUF): ELIBS = -lswscale ++SKIPHEADERS-$(CONFIG_NETWORK) += network.h rtsp.h ++TESTPROGS = seek ++TOOLS = aviocat ismindex pktdumper probetest +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroska.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroska.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroska.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroska.c 2012-05-14 14:08:55.006353506 +0200 +@@ -99,3 +99,27 @@ + { "PART_NUMBER" , "track" }, + { 0 } + }; ++ ++const char * const matroska_video_stereo_mode[MATROSKA_VIDEO_STEREO_MODE_COUNT] = { ++ "mono", ++ "left_right", ++ "bottom_top", ++ "top_bottom", ++ "checkerboard_rl", ++ "checkerboard_lr" ++ "row_interleaved_rl", ++ "row_interleaved_lr", ++ "col_interleaved_rl", ++ "col_interleaved_lr", ++ "anaglyph_cyan_red", ++ "right_left", ++ "anaglyph_green_magenta", ++ "block_lr", ++ "block_rl", ++}; ++ ++const char * const matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT] = { ++ "left", ++ "right", ++ "background", ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroskadec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroskadec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroskadec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroskadec.c 2012-05-14 14:08:55.012353627 +0200 +@@ -22,25 +22,27 @@ + /** + * @file + * Matroska file demuxer +- * by Ronald Bultje +- * with a little help from Moritz Bunkus +- * totally reworked by Aurelien Jacobs +- * Specs available on the Matroska project page: http://www.matroska.org/. ++ * @author Ronald Bultje ++ * @author with a little help from Moritz Bunkus ++ * @author totally reworked by Aurelien Jacobs ++ * @see specs available on the Matroska project page: http://www.matroska.org/ + */ + + #include + #include "avformat.h" + #include "internal.h" ++#include "avio_internal.h" + /* For ff_codec_get_id(). */ + #include "riff.h" + #include "isom.h" + #include "rm.h" + #include "matroska.h" + #include "libavcodec/mpeg4audio.h" +-#include "libavutil/intfloat_readwrite.h" ++#include "libavutil/intfloat.h" + #include "libavutil/intreadwrite.h" + #include "libavutil/avstring.h" + #include "libavutil/lzo.h" ++#include "libavutil/dict.h" + #if CONFIG_ZLIB + #include + #endif +@@ -58,6 +60,7 @@ + EBML_NEST, + EBML_PASS, + EBML_STOP, ++ EBML_TYPE_COUNT + } EbmlType; + + typedef const struct EbmlSyntax { +@@ -109,7 +112,8 @@ + uint64_t display_height; + uint64_t pixel_width; + uint64_t pixel_height; +- uint64_t fourcc; ++ EbmlBin color_space; ++ uint64_t stereo_mode; + } MatroskaTrackVideo; + + typedef struct { +@@ -125,10 +129,20 @@ + int sub_packet_size; + int sub_packet_cnt; + int pkt_cnt; ++ uint64_t buf_timecode; + uint8_t *buf; + } MatroskaTrackAudio; + + typedef struct { ++ uint64_t uid; ++ uint64_t type; ++} MatroskaTrackPlane; ++ ++typedef struct { ++ EbmlList combine_planes; ++} MatroskaTrackOperation; ++ ++typedef struct { + uint64_t num; + uint64_t uid; + uint64_t type; +@@ -142,6 +156,7 @@ + uint64_t flag_forced; + MatroskaTrackVideo video; + MatroskaTrackAudio audio; ++ MatroskaTrackOperation operation; + EbmlList encodings; + + AVStream *stream; +@@ -240,6 +255,9 @@ + /* What to skip before effectively reading a packet. */ + int skip_to_keyframe; + uint64_t skip_to_timecode; ++ ++ /* File has a CUES element, but we defer parsing until it is needed. */ ++ int cues_parsing_deferred; + } MatroskaDemuxContext; + + typedef struct { +@@ -287,14 +305,14 @@ + { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) }, + { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) }, + { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) }, +- { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) }, ++ { MATROSKA_ID_VIDEOCOLORSPACE, EBML_BIN, 0, offsetof(MatroskaTrackVideo,color_space) }, ++ { MATROSKA_ID_VIDEOSTEREOMODE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,stereo_mode) }, + { MATROSKA_ID_VIDEOPIXELCROPB, EBML_NONE }, + { MATROSKA_ID_VIDEOPIXELCROPT, EBML_NONE }, + { MATROSKA_ID_VIDEOPIXELCROPL, EBML_NONE }, + { MATROSKA_ID_VIDEOPIXELCROPR, EBML_NONE }, + { MATROSKA_ID_VIDEODISPLAYUNIT, EBML_NONE }, + { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE }, +- { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE }, + { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE }, + { 0 } + }; +@@ -326,6 +344,22 @@ + { 0 } + }; + ++static EbmlSyntax matroska_track_plane[] = { ++ { MATROSKA_ID_TRACKPLANEUID, EBML_UINT, 0, offsetof(MatroskaTrackPlane,uid) }, ++ { MATROSKA_ID_TRACKPLANETYPE, EBML_UINT, 0, offsetof(MatroskaTrackPlane,type) }, ++ { 0 } ++}; ++ ++static EbmlSyntax matroska_track_combine_planes[] = { ++ { MATROSKA_ID_TRACKPLANE, EBML_NEST, sizeof(MatroskaTrackPlane), offsetof(MatroskaTrackOperation,combine_planes), {.n=matroska_track_plane} }, ++ { 0 } ++}; ++ ++static EbmlSyntax matroska_track_operation[] = { ++ { MATROSKA_ID_TRACKCOMBINEPLANES, EBML_NEST, 0, 0, {.n=matroska_track_combine_planes} }, ++ { 0 } ++}; ++ + static EbmlSyntax matroska_track[] = { + { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) }, + { MATROSKA_ID_TRACKNAME, EBML_UTF8, 0, offsetof(MatroskaTrack,name) }, +@@ -340,6 +374,7 @@ + { MATROSKA_ID_TRACKFLAGFORCED, EBML_UINT, 0, offsetof(MatroskaTrack,flag_forced), {.u=0} }, + { MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} }, + { MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} }, ++ { MATROSKA_ID_TRACKOPERATION, EBML_NEST, 0, offsetof(MatroskaTrack,operation), {.n=matroska_track_operation} }, + { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} }, + { MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE }, + { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE }, +@@ -483,7 +518,7 @@ + static EbmlSyntax matroska_blockgroup[] = { + { MATROSKA_ID_BLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) }, + { MATROSKA_ID_SIMPLEBLOCK, EBML_BIN, 0, offsetof(MatroskaBlock,bin) }, +- { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration), {.u=AV_NOPTS_VALUE} }, ++ { MATROSKA_ID_BLOCKDURATION, EBML_UINT, 0, offsetof(MatroskaBlock,duration) }, + { MATROSKA_ID_BLOCKREFERENCE, EBML_UINT, 0, offsetof(MatroskaBlock,reference) }, + { 1, EBML_UINT, 0, offsetof(MatroskaBlock,non_simple), {.u=1} }, + { 0 } +@@ -514,8 +549,8 @@ + */ + static int ebml_level_end(MatroskaDemuxContext *matroska) + { +- ByteIOContext *pb = matroska->ctx->pb; +- int64_t pos = url_ftell(pb); ++ AVIOContext *pb = matroska->ctx->pb; ++ int64_t pos = avio_tell(pb); + + if (matroska->num_levels > 0) { + MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1]; +@@ -535,19 +570,19 @@ + * number. + * Returns: number of bytes read, < 0 on error + */ +-static int ebml_read_num(MatroskaDemuxContext *matroska, ByteIOContext *pb, ++static int ebml_read_num(MatroskaDemuxContext *matroska, AVIOContext *pb, + int max_size, uint64_t *number) + { + int read = 1, n = 1; + uint64_t total = 0; + +- /* The first byte tells us the length in bytes - get_byte() can normally ++ /* The first byte tells us the length in bytes - avio_r8() can normally + * return 0, but since that's not a valid first ebmlID byte, we can + * use it safely here to catch EOS. */ +- if (!(total = get_byte(pb))) { ++ if (!(total = avio_r8(pb))) { + /* we might encounter EOS here */ + if (!url_feof(pb)) { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + av_log(matroska->ctx, AV_LOG_ERROR, + "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", + pos, pos); +@@ -558,7 +593,7 @@ + /* get the length of the EBML number */ + read = 8 - ff_log2_tab[total]; + if (read > max_size) { +- int64_t pos = url_ftell(pb) - 1; ++ int64_t pos = avio_tell(pb) - 1; + av_log(matroska->ctx, AV_LOG_ERROR, + "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n", + (uint8_t) total, pos, pos); +@@ -568,7 +603,7 @@ + /* read out length */ + total ^= 1 << ff_log2_tab[total]; + while (n++ < read) +- total = (total << 8) | get_byte(pb); ++ total = (total << 8) | avio_r8(pb); + + *number = total; + +@@ -580,7 +615,7 @@ + * This needs special handling for the "unknown length" case which has multiple + * encodings. + */ +-static int ebml_read_length(MatroskaDemuxContext *matroska, ByteIOContext *pb, ++static int ebml_read_length(MatroskaDemuxContext *matroska, AVIOContext *pb, + uint64_t *number) + { + int res = ebml_read_num(matroska, pb, 8, number); +@@ -593,7 +628,7 @@ + * Read the next element as an unsigned int. + * 0 is success, < 0 is failure. + */ +-static int ebml_read_uint(ByteIOContext *pb, int size, uint64_t *num) ++static int ebml_read_uint(AVIOContext *pb, int size, uint64_t *num) + { + int n = 0; + +@@ -603,7 +638,7 @@ + /* big-endian ordering; build up number */ + *num = 0; + while (n++ < size) +- *num = (*num << 8) | get_byte(pb); ++ *num = (*num << 8) | avio_r8(pb); + + return 0; + } +@@ -612,14 +647,14 @@ + * Read the next element as a float. + * 0 is success, < 0 is failure. + */ +-static int ebml_read_float(ByteIOContext *pb, int size, double *num) ++static int ebml_read_float(AVIOContext *pb, int size, double *num) + { + if (size == 0) { + *num = 0; + } else if (size == 4) { +- *num= av_int2flt(get_be32(pb)); +- } else if(size==8){ +- *num= av_int2dbl(get_be64(pb)); ++ *num = av_int2float(avio_rb32(pb)); ++ } else if (size == 8){ ++ *num = av_int2double(avio_rb64(pb)); + } else + return AVERROR_INVALIDDATA; + +@@ -630,18 +665,21 @@ + * Read the next element as an ASCII string. + * 0 is success, < 0 is failure. + */ +-static int ebml_read_ascii(ByteIOContext *pb, int size, char **str) ++static int ebml_read_ascii(AVIOContext *pb, int size, char **str) + { +- av_free(*str); ++ char *res; ++ + /* EBML strings are usually not 0-terminated, so we allocate one + * byte more, read the string and NULL-terminate it ourselves. */ +- if (!(*str = av_malloc(size + 1))) ++ if (!(res = av_malloc(size + 1))) + return AVERROR(ENOMEM); +- if (get_buffer(pb, (uint8_t *) *str, size) != size) { +- av_freep(str); ++ if (avio_read(pb, (uint8_t *) res, size) != size) { ++ av_free(res); + return AVERROR(EIO); + } +- (*str)[size] = '\0'; ++ (res)[size] = '\0'; ++ av_free(*str); ++ *str = res; + + return 0; + } +@@ -650,15 +688,15 @@ + * Read the next element as binary data. + * 0 is success, < 0 is failure. + */ +-static int ebml_read_binary(ByteIOContext *pb, int length, EbmlBin *bin) ++static int ebml_read_binary(AVIOContext *pb, int length, EbmlBin *bin) + { + av_free(bin->data); + if (!(bin->data = av_malloc(length))) + return AVERROR(ENOMEM); + + bin->size = length; +- bin->pos = url_ftell(pb); +- if (get_buffer(pb, bin->data, length) != length) { ++ bin->pos = avio_tell(pb); ++ if (avio_read(pb, bin->data, length) != length) { + av_freep(&bin->data); + return AVERROR(EIO); + } +@@ -673,7 +711,7 @@ + */ + static int ebml_read_master(MatroskaDemuxContext *matroska, uint64_t length) + { +- ByteIOContext *pb = matroska->ctx->pb; ++ AVIOContext *pb = matroska->ctx->pb; + MatroskaLevel *level; + + if (matroska->num_levels >= EBML_MAX_DEPTH) { +@@ -683,7 +721,7 @@ + } + + level = &matroska->levels[matroska->num_levels++]; +- level->start = url_ftell(pb); ++ level->start = avio_tell(pb); + level->length = length; + + return 0; +@@ -696,8 +734,8 @@ + static int matroska_ebmlnum_uint(MatroskaDemuxContext *matroska, + uint8_t *data, uint32_t size, uint64_t *num) + { +- ByteIOContext pb; +- init_put_byte(&pb, data, size, 0, NULL, NULL, NULL, NULL); ++ AVIOContext pb; ++ ffio_init_context(&pb, data, size, 0, NULL, NULL, NULL, NULL); + return ebml_read_num(matroska, &pb, FFMIN(size, 8), num); + } + +@@ -780,15 +818,29 @@ + static int ebml_parse_elem(MatroskaDemuxContext *matroska, + EbmlSyntax *syntax, void *data) + { +- ByteIOContext *pb = matroska->ctx->pb; ++ static const uint64_t max_lengths[EBML_TYPE_COUNT] = { ++ [EBML_UINT] = 8, ++ [EBML_FLOAT] = 8, ++ // max. 16 MB for strings ++ [EBML_STR] = 0x1000000, ++ [EBML_UTF8] = 0x1000000, ++ // max. 256 MB for binary data ++ [EBML_BIN] = 0x10000000, ++ // no limits for anything else ++ }; ++ AVIOContext *pb = matroska->ctx->pb; + uint32_t id = syntax->id; + uint64_t length; + int res; ++ void *newelem; + + data = (char *)data + syntax->data_offset; + if (syntax->list_elem_size) { + EbmlList *list = data; +- list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size); ++ newelem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size); ++ if (!newelem) ++ return AVERROR(ENOMEM); ++ list->elem = newelem; + data = (char*)list->elem + list->nb_elem*syntax->list_elem_size; + memset(data, 0, syntax->list_elem_size); + list->nb_elem++; +@@ -798,6 +850,12 @@ + matroska->current_id = 0; + if ((res = ebml_read_length(matroska, pb, &length)) < 0) + return res; ++ if (max_lengths[syntax->type] && length > max_lengths[syntax->type]) { ++ av_log(matroska->ctx, AV_LOG_ERROR, ++ "Invalid length 0x%"PRIx64" > 0x%"PRIx64" for syntax element %i\n", ++ length, max_lengths[syntax->type], syntax->type); ++ return AVERROR_INVALIDDATA; ++ } + } + + switch (syntax->type) { +@@ -809,11 +867,11 @@ + case EBML_NEST: if ((res=ebml_read_master(matroska, length)) < 0) + return res; + if (id == MATROSKA_ID_SEGMENT) +- matroska->segment_start = url_ftell(matroska->ctx->pb); ++ matroska->segment_start = avio_tell(matroska->ctx->pb); + return ebml_parse_nest(matroska, syntax->def.n, data); + case EBML_PASS: return ebml_parse_id(matroska, syntax->def.n, id, data); + case EBML_STOP: return 1; +- default: return url_fseek(pb,length,SEEK_CUR)<0 ? AVERROR(EIO) : 0; ++ default: return avio_skip(pb,length)<0 ? AVERROR(EIO) : 0; + } + if (res == AVERROR_INVALIDDATA) + av_log(matroska->ctx, AV_LOG_ERROR, "Invalid element\n"); +@@ -880,6 +938,8 @@ + * Not fully fool-proof, but good enough. */ + for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) { + int probelen = strlen(matroska_doctypes[i]); ++ if (total < probelen) ++ continue; + for (n = 4+size; n <= 4+size+total-probelen; n++) + if (!memcmp(p->buf+n, matroska_doctypes[i], probelen)) + return AVPROBE_SCORE_MAX; +@@ -910,6 +970,7 @@ + uint8_t* data = *buf; + int isize = *buf_size; + uint8_t* pkt_data = NULL; ++ uint8_t* newpktdata; + int pkt_size = isize; + int result = 0; + int olen; +@@ -939,10 +1000,18 @@ + zstream.avail_in = isize; + do { + pkt_size *= 3; +- pkt_data = av_realloc(pkt_data, pkt_size); ++ newpktdata = av_realloc(pkt_data, pkt_size); ++ if (!newpktdata) { ++ inflateEnd(&zstream); ++ goto failed; ++ } ++ pkt_data = newpktdata; + zstream.avail_out = pkt_size - zstream.total_out; + zstream.next_out = pkt_data + zstream.total_out; +- result = inflate(&zstream, Z_NO_FLUSH); ++ if (pkt_data) { ++ result = inflate(&zstream, Z_NO_FLUSH); ++ } else ++ result = Z_MEM_ERROR; + } while (result==Z_OK && pkt_size<10000000); + pkt_size = zstream.total_out; + inflateEnd(&zstream); +@@ -960,10 +1029,18 @@ + bzstream.avail_in = isize; + do { + pkt_size *= 3; +- pkt_data = av_realloc(pkt_data, pkt_size); ++ newpktdata = av_realloc(pkt_data, pkt_size); ++ if (!newpktdata) { ++ BZ2_bzDecompressEnd(&bzstream); ++ goto failed; ++ } ++ pkt_data = newpktdata; + bzstream.avail_out = pkt_size - bzstream.total_out_lo32; + bzstream.next_out = pkt_data + bzstream.total_out_lo32; +- result = BZ2_bzDecompress(&bzstream); ++ if (pkt_data) { ++ result = BZ2_bzDecompress(&bzstream); ++ } else ++ result = BZ_MEM_ERROR; + } while (result==BZ_OK && pkt_size<10000000); + pkt_size = bzstream.total_out_lo32; + BZ2_bzDecompressEnd(&bzstream); +@@ -990,7 +1067,8 @@ + char *line, *layer, *ptr = pkt->data, *end = ptr+pkt->size; + for (; *ptr!=',' && ptrpts + display_duration; +@@ -1015,17 +1093,21 @@ + } + } + +-static void matroska_merge_packets(AVPacket *out, AVPacket *in) ++static int matroska_merge_packets(AVPacket *out, AVPacket *in) + { +- out->data = av_realloc(out->data, out->size+in->size); ++ void *newdata = av_realloc(out->data, out->size+in->size); ++ if (!newdata) ++ return AVERROR(ENOMEM); ++ out->data = newdata; + memcpy(out->data+out->size, in->data, in->size); + out->size += in->size; + av_destruct_packet(in); + av_free(in); ++ return 0; + } + + static void matroska_convert_tag(AVFormatContext *s, EbmlList *list, +- AVMetadata **metadata, char *prefix) ++ AVDictionary **metadata, char *prefix) + { + MatroskaTag *tags = list->elem; + char key[1024]; +@@ -1041,14 +1123,14 @@ + if (prefix) snprintf(key, sizeof(key), "%s/%s", prefix, tags[i].name); + else av_strlcpy(key, tags[i].name, sizeof(key)); + if (tags[i].def || !lang) { +- av_metadata_set2(metadata, key, tags[i].string, 0); ++ av_dict_set(metadata, key, tags[i].string, 0); + if (tags[i].sub.nb_elem) + matroska_convert_tag(s, &tags[i].sub, metadata, key); + } + if (lang) { + av_strlcat(key, "-", sizeof(key)); + av_strlcat(key, lang, sizeof(key)); +- av_metadata_set2(metadata, key, tags[i].string, 0); ++ av_dict_set(metadata, key, tags[i].string, 0); + if (tags[i].sub.nb_elem) + matroska_convert_tag(s, &tags[i].sub, metadata, key); + } +@@ -1090,62 +1172,123 @@ + } + } + +-static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) ++static int matroska_parse_seekhead_entry(MatroskaDemuxContext *matroska, int idx) + { + EbmlList *seekhead_list = &matroska->seekhead; + MatroskaSeekhead *seekhead = seekhead_list->elem; + uint32_t level_up = matroska->level_up; +- int64_t before_pos = url_ftell(matroska->ctx->pb); ++ int64_t before_pos = avio_tell(matroska->ctx->pb); + uint32_t saved_id = matroska->current_id; + MatroskaLevel level; ++ int64_t offset; ++ int ret = 0; ++ ++ if (idx >= seekhead_list->nb_elem ++ || seekhead[idx].id == MATROSKA_ID_SEEKHEAD ++ || seekhead[idx].id == MATROSKA_ID_CLUSTER) ++ return 0; ++ ++ /* seek */ ++ offset = seekhead[idx].pos + matroska->segment_start; ++ if (avio_seek(matroska->ctx->pb, offset, SEEK_SET) == offset) { ++ /* We don't want to lose our seekhead level, so we add ++ * a dummy. This is a crude hack. */ ++ if (matroska->num_levels == EBML_MAX_DEPTH) { ++ av_log(matroska->ctx, AV_LOG_INFO, ++ "Max EBML element depth (%d) reached, " ++ "cannot parse further.\n", EBML_MAX_DEPTH); ++ ret = AVERROR_INVALIDDATA; ++ } else { ++ level.start = 0; ++ level.length = (uint64_t)-1; ++ matroska->levels[matroska->num_levels] = level; ++ matroska->num_levels++; ++ matroska->current_id = 0; ++ ++ ret = ebml_parse(matroska, matroska_segment, matroska); ++ ++ /* remove dummy level */ ++ while (matroska->num_levels) { ++ uint64_t length = matroska->levels[--matroska->num_levels].length; ++ if (length == (uint64_t)-1) ++ break; ++ } ++ } ++ } ++ /* seek back */ ++ avio_seek(matroska->ctx->pb, before_pos, SEEK_SET); ++ matroska->level_up = level_up; ++ matroska->current_id = saved_id; ++ ++ return ret; ++} ++ ++static void matroska_execute_seekhead(MatroskaDemuxContext *matroska) ++{ ++ EbmlList *seekhead_list = &matroska->seekhead; ++ int64_t before_pos = avio_tell(matroska->ctx->pb); + int i; + + // we should not do any seeking in the streaming case +- if (url_is_streamed(matroska->ctx->pb) || ++ if (!matroska->ctx->pb->seekable || + (matroska->ctx->flags & AVFMT_FLAG_IGNIDX)) + return; + +- for (i=0; inb_elem; i++) { +- int64_t offset = seekhead[i].pos + matroska->segment_start; +- +- if (seekhead[i].pos <= before_pos +- || seekhead[i].id == MATROSKA_ID_SEEKHEAD +- || seekhead[i].id == MATROSKA_ID_CLUSTER) ++ for (i = 0; i < seekhead_list->nb_elem; i++) { ++ MatroskaSeekhead *seekhead = seekhead_list->elem; ++ if (seekhead[i].pos <= before_pos) + continue; + +- /* seek */ +- if (url_fseek(matroska->ctx->pb, offset, SEEK_SET) != offset) ++ // defer cues parsing until we actually need cue data. ++ if (seekhead[i].id == MATROSKA_ID_CUES) { ++ matroska->cues_parsing_deferred = 1; + continue; +- +- /* We don't want to lose our seekhead level, so we add +- * a dummy. This is a crude hack. */ +- if (matroska->num_levels == EBML_MAX_DEPTH) { +- av_log(matroska->ctx, AV_LOG_INFO, +- "Max EBML element depth (%d) reached, " +- "cannot parse further.\n", EBML_MAX_DEPTH); +- break; + } + +- level.start = 0; +- level.length = (uint64_t)-1; +- matroska->levels[matroska->num_levels] = level; +- matroska->num_levels++; +- matroska->current_id = 0; ++ if (matroska_parse_seekhead_entry(matroska, i) < 0) ++ break; ++ } ++} + +- ebml_parse(matroska, matroska_segment, matroska); ++static void matroska_add_index_entries(MatroskaDemuxContext *matroska) { ++ EbmlList *index_list; ++ MatroskaIndex *index; ++ int index_scale = 1; ++ int i, j; + +- /* remove dummy level */ +- while (matroska->num_levels) { +- uint64_t length = matroska->levels[--matroska->num_levels].length; +- if (length == (uint64_t)-1) +- break; ++ index_list = &matroska->index; ++ index = index_list->elem; ++ if (index_list->nb_elem ++ && index[0].time > 1E14/matroska->time_scale) { ++ av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n"); ++ index_scale = matroska->time_scale; ++ } ++ for (i = 0; i < index_list->nb_elem; i++) { ++ EbmlList *pos_list = &index[i].pos; ++ MatroskaIndexPos *pos = pos_list->elem; ++ for (j = 0; j < pos_list->nb_elem; j++) { ++ MatroskaTrack *track = matroska_find_track_by_num(matroska, pos[j].track); ++ if (track && track->stream) ++ av_add_index_entry(track->stream, ++ pos[j].pos + matroska->segment_start, ++ index[i].time/index_scale, 0, 0, ++ AVINDEX_KEYFRAME); + } + } ++} + +- /* seek back */ +- url_fseek(matroska->ctx->pb, before_pos, SEEK_SET); +- matroska->level_up = level_up; +- matroska->current_id = saved_id; ++static void matroska_parse_cues(MatroskaDemuxContext *matroska) { ++ EbmlList *seekhead_list = &matroska->seekhead; ++ MatroskaSeekhead *seekhead = seekhead_list->elem; ++ int i; ++ ++ for (i = 0; i < seekhead_list->nb_elem; i++) ++ if (seekhead[i].id == MATROSKA_ID_CUES) ++ break; ++ assert(i <= seekhead_list->nb_elem); ++ ++ matroska_parse_seekhead_entry(matroska, i); ++ matroska_add_index_entries(matroska); + } + + static int matroska_aac_profile(char *codec_id) +@@ -1163,8 +1306,8 @@ + { + int sri; + +- for (sri=0; srichapters; + MatroskaChapter *chapters; + MatroskaTrack *tracks; +- EbmlList *index_list; +- MatroskaIndex *index; +- int index_scale = 1; + uint64_t max_start = 0; + Ebml ebml = { 0 }; + AVStream *st; +- int i, j, res; ++ int i, j, k, res; + + matroska->ctx = s; + + /* First read the EBML header. */ + if (ebml_parse(matroska, ebml_syntax, &ebml) + || ebml.version > EBML_VERSION || ebml.max_size > sizeof(uint64_t) +- || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 2) { ++ || ebml.id_length > sizeof(uint32_t) || ebml.doctype_version > 3) { + av_log(matroska->ctx, AV_LOG_ERROR, + "EBML header using unsupported features\n" + "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n", + ebml.version, ebml.doctype, ebml.doctype_version); + ebml_free(ebml_syntax, &ebml); + return AVERROR_PATCHWELCOME; ++ } else if (ebml.doctype_version == 3) { ++ av_log(matroska->ctx, AV_LOG_WARNING, ++ "EBML header using unsupported features\n" ++ "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n", ++ ebml.version, ebml.doctype, ebml.doctype_version); + } + for (i = 0; i < FF_ARRAY_ELEMS(matroska_doctypes); i++) + if (!strcmp(ebml.doctype, matroska_doctypes[i])) +@@ -1216,7 +1361,7 @@ + if (matroska->duration) + matroska->ctx->duration = matroska->duration * matroska->time_scale + * 1000 / AV_TIME_BASE; +- av_metadata_set2(&s->metadata, "title", matroska->title, 0); ++ av_dict_set(&s->metadata, "title", matroska->title, 0); + + tracks = matroska->tracks.elem; + for (i=0; i < matroska->tracks.nb_elem; i++) { +@@ -1227,7 +1372,8 @@ + uint8_t *extradata = NULL; + int extradata_size = 0; + int extradata_offset = 0; +- ByteIOContext b; ++ uint32_t fourcc = 0; ++ AVIOContext b; + + /* Apply some sanity checks. */ + if (track->type != MATROSKA_TRACK_TYPE_VIDEO && +@@ -1248,13 +1394,15 @@ + track->video.display_width = track->video.pixel_width; + if (!track->video.display_height) + track->video.display_height = track->video.pixel_height; ++ if (track->video.color_space.size == 4) ++ fourcc = AV_RL32(track->video.color_space.data); + } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { + if (!track->audio.out_samplerate) + track->audio.out_samplerate = track->audio.samplerate; + } + if (encodings_list->nb_elem > 1) { + av_log(matroska->ctx, AV_LOG_ERROR, +- "Multiple combined encodings no supported"); ++ "Multiple combined encodings not supported"); + } else if (encodings_list->nb_elem == 1) { + if (encodings[0].type || + (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP && +@@ -1299,7 +1447,7 @@ + } + } + +- st = track->stream = av_new_stream(s, 0); ++ st = track->stream = avformat_new_stream(s, NULL); + if (st == NULL) + return AVERROR(ENOMEM); + +@@ -1307,22 +1455,25 @@ + && track->codec_priv.size >= 40 + && track->codec_priv.data != NULL) { + track->ms_compat = 1; +- track->video.fourcc = AV_RL32(track->codec_priv.data + 16); +- codec_id = ff_codec_get_id(ff_codec_bmp_tags, track->video.fourcc); ++ fourcc = AV_RL32(track->codec_priv.data + 16); ++ codec_id = ff_codec_get_id(ff_codec_bmp_tags, fourcc); + extradata_offset = 40; + } else if (!strcmp(track->codec_id, "A_MS/ACM") + && track->codec_priv.size >= 14 + && track->codec_priv.data != NULL) { +- init_put_byte(&b, track->codec_priv.data, track->codec_priv.size, +- URL_RDONLY, NULL, NULL, NULL, NULL); +- ff_get_wav_header(&b, st->codec, track->codec_priv.size); ++ int ret; ++ ffio_init_context(&b, track->codec_priv.data, track->codec_priv.size, ++ AVIO_FLAG_READ, NULL, NULL, NULL, NULL); ++ ret = ff_get_wav_header(&b, st->codec, track->codec_priv.size); ++ if (ret < 0) ++ return ret; + codec_id = st->codec->codec_id; + extradata_offset = FFMIN(track->codec_priv.size, 18); + } else if (!strcmp(track->codec_id, "V_QUICKTIME") + && (track->codec_priv.size >= 86) + && (track->codec_priv.data != NULL)) { +- track->video.fourcc = AV_RL32(track->codec_priv.data); +- codec_id=ff_codec_get_id(codec_movvideo_tags, track->video.fourcc); ++ fourcc = AV_RL32(track->codec_priv.data); ++ codec_id = ff_codec_get_id(codec_movvideo_tags, fourcc); + } else if (codec_id == CODEC_ID_PCM_S16BE) { + switch (track->audio.bitdepth) { + case 8: codec_id = CODEC_ID_PCM_U8; break; +@@ -1340,7 +1491,7 @@ + } else if (codec_id == CODEC_ID_AAC && !track->codec_priv.size) { + int profile = matroska_aac_profile(track->codec_id); + int sri = matroska_aac_sri(track->audio.samplerate); +- extradata = av_malloc(5); ++ extradata = av_mallocz(5 + FF_INPUT_BUFFER_PADDING_SIZE); + if (extradata == NULL) + return AVERROR(ENOMEM); + extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); +@@ -1355,17 +1506,17 @@ + extradata_size = 2; + } else if (codec_id == CODEC_ID_TTA) { + extradata_size = 30; +- extradata = av_mallocz(extradata_size); ++ extradata = av_mallocz(extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); + if (extradata == NULL) + return AVERROR(ENOMEM); +- init_put_byte(&b, extradata, extradata_size, 1, ++ ffio_init_context(&b, extradata, extradata_size, 1, + NULL, NULL, NULL, NULL); +- put_buffer(&b, "TTA1", 4); +- put_le16(&b, 1); +- put_le16(&b, track->audio.channels); +- put_le16(&b, track->audio.bitdepth); +- put_le32(&b, track->audio.out_samplerate); +- put_le32(&b, matroska->ctx->duration * track->audio.out_samplerate); ++ avio_write(&b, "TTA1", 4); ++ avio_wl16(&b, 1); ++ avio_wl16(&b, track->audio.channels); ++ avio_wl16(&b, track->audio.bitdepth); ++ avio_wl32(&b, track->audio.out_samplerate); ++ avio_wl32(&b, matroska->ctx->duration * track->audio.out_samplerate); + } else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 || + codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) { + extradata_offset = 26; +@@ -1375,15 +1526,15 @@ + } else if (codec_id == CODEC_ID_RA_288 || codec_id == CODEC_ID_COOK || + codec_id == CODEC_ID_ATRAC3 || codec_id == CODEC_ID_SIPR) { + int flavor; +- init_put_byte(&b, track->codec_priv.data,track->codec_priv.size, ++ ffio_init_context(&b, track->codec_priv.data,track->codec_priv.size, + 0, NULL, NULL, NULL, NULL); +- url_fskip(&b, 22); +- flavor = get_be16(&b); +- track->audio.coded_framesize = get_be32(&b); +- url_fskip(&b, 12); +- track->audio.sub_packet_h = get_be16(&b); +- track->audio.frame_size = get_be16(&b); +- track->audio.sub_packet_size = get_be16(&b); ++ avio_skip(&b, 22); ++ flavor = avio_rb16(&b); ++ track->audio.coded_framesize = avio_rb32(&b); ++ avio_skip(&b, 12); ++ track->audio.sub_packet_h = avio_rb16(&b); ++ track->audio.frame_size = avio_rb16(&b); ++ track->audio.sub_packet_size = avio_rb16(&b); + track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h); + if (codec_id == CODEC_ID_RA_288) { + st->codec->block_align = track->audio.coded_framesize; +@@ -1406,23 +1557,19 @@ + + if (track->time_scale < 0.01) + track->time_scale = 1.0; +- av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */ ++ avpriv_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */ + + st->codec->codec_id = codec_id; + st->start_time = 0; + if (strcmp(track->language, "und")) +- av_metadata_set2(&st->metadata, "language", track->language, 0); +- av_metadata_set2(&st->metadata, "title", track->name, 0); ++ av_dict_set(&st->metadata, "language", track->language, 0); ++ av_dict_set(&st->metadata, "title", track->name, 0); + + if (track->flag_default) + st->disposition |= AV_DISPOSITION_DEFAULT; + if (track->flag_forced) + st->disposition |= AV_DISPOSITION_FORCED; + +- if (track->default_duration) +- av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, +- track->default_duration, 1000000000, 30000); +- + if (!st->codec->extradata) { + if(extradata){ + st->codec->extradata = extradata; +@@ -1440,8 +1587,10 @@ + } + + if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { ++ MatroskaTrackPlane *planes = track->operation.combine_planes.elem; ++ + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_tag = track->video.fourcc; ++ st->codec->codec_tag = fourcc; + st->codec->width = track->video.pixel_width; + st->codec->height = track->video.pixel_height; + av_reduce(&st->sample_aspect_ratio.num, +@@ -1453,6 +1602,25 @@ + st->need_parsing = AVSTREAM_PARSE_HEADERS; + if (track->default_duration) + st->avg_frame_rate = av_d2q(1000000000.0/track->default_duration, INT_MAX); ++ ++ /* export stereo mode flag as metadata tag */ ++ if (track->video.stereo_mode && track->video.stereo_mode < MATROSKA_VIDEO_STEREO_MODE_COUNT) ++ av_dict_set(&st->metadata, "stereo_mode", matroska_video_stereo_mode[track->video.stereo_mode], 0); ++ ++ /* if we have virtual track, mark the real tracks */ ++ for (j=0; j < track->operation.combine_planes.nb_elem; j++) { ++ char buf[32]; ++ if (planes[j].type >= MATROSKA_VIDEO_STEREO_PLANE_COUNT) ++ continue; ++ snprintf(buf, sizeof(buf), "%s_%d", ++ matroska_video_stereo_plane[planes[j].type], i); ++ for (k=0; k < matroska->tracks.nb_elem; k++) ++ if (planes[j].uid == tracks[k].uid) { ++ av_dict_set(&s->streams[k]->metadata, ++ "stereo_mode", buf, 0); ++ break; ++ } ++ } + } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->sample_rate = track->audio.out_samplerate; +@@ -1470,13 +1638,14 @@ + attachements[j].bin.data && attachements[j].bin.size > 0)) { + av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n"); + } else { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (st == NULL) + break; +- av_metadata_set2(&st->metadata, "filename",attachements[j].filename, 0); ++ av_dict_set(&st->metadata, "filename",attachements[j].filename, 0); ++ av_dict_set(&st->metadata, "mimetype", attachements[j].mime, 0); + st->codec->codec_id = CODEC_ID_NONE; + st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; +- st->codec->extradata = av_malloc(attachements[j].bin.size); ++ st->codec->extradata = av_malloc(attachements[j].bin.size + FF_INPUT_BUFFER_PADDING_SIZE); + if(st->codec->extradata == NULL) + break; + st->codec->extradata_size = attachements[j].bin.size; +@@ -1498,34 +1667,15 @@ + if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid + && (max_start==0 || chapters[i].start > max_start)) { + chapters[i].chapter = +- ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, ++ avpriv_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, + chapters[i].start, chapters[i].end, + chapters[i].title); +- av_metadata_set2(&chapters[i].chapter->metadata, ++ av_dict_set(&chapters[i].chapter->metadata, + "title", chapters[i].title, 0); + max_start = chapters[i].start; + } + +- index_list = &matroska->index; +- index = index_list->elem; +- if (index_list->nb_elem +- && index[0].time > 100000000000000/matroska->time_scale) { +- av_log(matroska->ctx, AV_LOG_WARNING, "Working around broken index.\n"); +- index_scale = matroska->time_scale; +- } +- for (i=0; inb_elem; i++) { +- EbmlList *pos_list = &index[i].pos; +- MatroskaIndexPos *pos = pos_list->elem; +- for (j=0; jnb_elem; j++) { +- MatroskaTrack *track = matroska_find_track_by_num(matroska, +- pos[j].track); +- if (track && track->stream) +- av_add_index_entry(track->stream, +- pos[j].pos + matroska->segment_start, +- index[i].time/index_scale, 0, 0, +- AVINDEX_KEYFRAME); +- } +- } ++ matroska_add_index_entries(matroska); + + matroska_convert_tags(s); + +@@ -1543,11 +1693,13 @@ + memcpy(pkt, matroska->packets[0], sizeof(AVPacket)); + av_free(matroska->packets[0]); + if (matroska->num_packets > 1) { ++ void *newpackets; + memmove(&matroska->packets[0], &matroska->packets[1], + (matroska->num_packets - 1) * sizeof(AVPacket *)); +- matroska->packets = +- av_realloc(matroska->packets, (matroska->num_packets - 1) * +- sizeof(AVPacket *)); ++ newpackets = av_realloc(matroska->packets, ++ (matroska->num_packets - 1) * sizeof(AVPacket *)); ++ if (newpackets) ++ matroska->packets = newpackets; + } else { + av_freep(&matroska->packets); + } +@@ -1597,15 +1749,16 @@ + size -= n; + + track = matroska_find_track_by_num(matroska, num); +- if (size <= 3 || !track || !track->stream) { ++ if (!track || !track->stream) { + av_log(matroska->ctx, AV_LOG_INFO, + "Invalid stream %"PRIu64" or size %u\n", num, size); + return res; +- } ++ } else if (size <= 3) ++ return 0; + st = track->stream; + if (st->discard >= AVDISCARD_ALL) + return res; +- if (duration == AV_NOPTS_VALUE) ++ if (!duration) + duration = track->default_duration / matroska->time_scale; + + block_time = AV_RB16(data); +@@ -1701,7 +1854,7 @@ + lace_size[n] = lace_size[n - 1] + snum; + total += lace_size[n]; + } +- lace_size[n] = size - total; ++ lace_size[laces - 1] = size - total; + break; + } + } +@@ -1724,15 +1877,33 @@ + int x; + + if (!track->audio.pkt_cnt) { +- if (st->codec->codec_id == CODEC_ID_RA_288) ++ if (track->audio.sub_packet_cnt == 0) ++ track->audio.buf_timecode = timecode; ++ if (st->codec->codec_id == CODEC_ID_RA_288) { ++ if (size < cfs * h / 2) { ++ av_log(matroska->ctx, AV_LOG_ERROR, ++ "Corrupt int4 RM-style audio packet size\n"); ++ return AVERROR_INVALIDDATA; ++ } + for (x=0; xaudio.buf+x*2*w+y*cfs, + data+x*cfs, cfs); +- else if (st->codec->codec_id == CODEC_ID_SIPR) ++ } else if (st->codec->codec_id == CODEC_ID_SIPR) { ++ if (size < w) { ++ av_log(matroska->ctx, AV_LOG_ERROR, ++ "Corrupt sipr RM-style audio packet size\n"); ++ return AVERROR_INVALIDDATA; ++ } + memcpy(track->audio.buf + y*w, data, w); +- else ++ } else { ++ if (size < sps * w / sps) { ++ av_log(matroska->ctx, AV_LOG_ERROR, ++ "Corrupt generic RM-style audio packet size\n"); ++ return AVERROR_INVALIDDATA; ++ } + for (x=0; xaudio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps); ++ } + + if (++track->audio.sub_packet_cnt >= h) { + if (st->codec->codec_id == CODEC_ID_SIPR) +@@ -1746,6 +1917,8 @@ + av_new_packet(pkt, a); + memcpy(pkt->data, track->audio.buf + + a * (h*w / a - track->audio.pkt_cnt--), a); ++ pkt->pts = track->audio.buf_timecode; ++ track->audio.buf_timecode = AV_NOPTS_VALUE; + pkt->pos = pos; + pkt->stream_index = st->index; + dynarray_add(&matroska->packets,&matroska->num_packets,pkt); +@@ -1826,7 +1999,7 @@ + EbmlList *blocks_list; + MatroskaBlock *blocks; + int i, res; +- int64_t pos = url_ftell(matroska->ctx->pb); ++ int64_t pos = avio_tell(matroska->ctx->pb); + matroska->prev_pkt = NULL; + if (matroska->current_id) + pos -= 4; /* sizeof the ID which was already read */ +@@ -1868,12 +2041,20 @@ + AVStream *st = s->streams[stream_index]; + int i, index, index_sub, index_min; + ++ /* Parse the CUES now since we need the index data to seek. */ ++ if (matroska->cues_parsing_deferred) { ++ matroska_parse_cues(matroska); ++ matroska->cues_parsing_deferred = 0; ++ } ++ + if (!st->nb_index_entries) +- return 0; ++ return -1; + timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); + + if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { +- url_fseek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); ++ if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0) ++ return -1; ++ matroska->current_id = 0; + while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { + matroska_clear_queue(matroska); + if (matroska_parse_cluster(matroska) < 0) +@@ -1881,13 +2062,11 @@ + } + } + +- matroska_clear_queue(matroska); + if (index < 0) + return 0; + + index_min = index; + for (i=0; i < matroska->tracks.nb_elem; i++) { +- tracks[i].end_timecode = 0; + if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE + && !tracks[i].stream->discard != AVDISCARD_ALL) { + index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD); +@@ -1898,11 +2077,21 @@ + } + } + +- url_fseek(s->pb, st->index_entries[index_min].pos, SEEK_SET); ++ if (avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET) < 0) ++ return -1; ++ ++ matroska_clear_queue(matroska); ++ for (i=0; i < matroska->tracks.nb_elem; i++) { ++ tracks[i].audio.pkt_cnt = 0; ++ tracks[i].audio.sub_packet_cnt = 0; ++ tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; ++ tracks[i].end_timecode = 0; ++ } ++ matroska->current_id = 0; + matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); + matroska->skip_to_timecode = st->index_entries[index].timestamp; + matroska->done = 0; +- av_update_cur_dts(s, st, st->index_entries[index].timestamp); ++ ff_update_cur_dts(s, st, st->index_entries[index].timestamp); + return 0; + } + +@@ -1923,12 +2112,12 @@ + } + + AVInputFormat ff_matroska_demuxer = { +- "matroska,webm", +- NULL_IF_CONFIG_SMALL("Matroska/WebM file format"), +- sizeof(MatroskaDemuxContext), +- matroska_probe, +- matroska_read_header, +- matroska_read_packet, +- matroska_read_close, +- matroska_read_seek, ++ .name = "matroska,webm", ++ .long_name = NULL_IF_CONFIG_SMALL("Matroska/WebM file format"), ++ .priv_data_size = sizeof(MatroskaDemuxContext), ++ .read_probe = matroska_probe, ++ .read_header = matroska_read_header, ++ .read_packet = matroska_read_packet, ++ .read_close = matroska_read_close, ++ .read_seek = matroska_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroskaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroskaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroskaenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroskaenc.c 2012-05-14 14:08:55.016353707 +0200 +@@ -20,19 +20,23 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + #include "isom.h" + #include "matroska.h" + #include "avc.h" + #include "flacenc.h" + #include "avlanguage.h" +-#include "libavcore/samplefmt.h" ++#include "libavutil/samplefmt.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/mathematics.h" + #include "libavutil/random_seed.h" + #include "libavutil/lfg.h" ++#include "libavutil/dict.h" ++#include "libavutil/avstring.h" + #include "libavcodec/xiph.h" + #include "libavcodec/mpeg4audio.h" +-#include + + typedef struct ebml_master { + int64_t pos; ///< absolute offset in the file where the master's elements start +@@ -74,7 +78,7 @@ + + typedef struct MatroskaMuxContext { + int mode; +- ByteIOContext *dyn_bc; ++ AVIOContext *dyn_bc; + ebml_master segment; + int64_t segment_offset; + ebml_master cluster; +@@ -88,6 +92,8 @@ + + unsigned int audio_buffer_size; + AVPacket cur_audio_pkt; ++ ++ int have_attachments; + } MatroskaMuxContext; + + +@@ -108,11 +114,11 @@ + return (av_log2(id+1)-1)/7+1; + } + +-static void put_ebml_id(ByteIOContext *pb, unsigned int id) ++static void put_ebml_id(AVIOContext *pb, unsigned int id) + { + int i = ebml_id_size(id); + while (i--) +- put_byte(pb, id >> (i*8)); ++ avio_w8(pb, id >> (i*8)); + } + + /** +@@ -120,12 +126,12 @@ + * + * @param bytes The number of bytes the size should occupy (maximum: 8). + */ +-static void put_ebml_size_unknown(ByteIOContext *pb, int bytes) ++static void put_ebml_size_unknown(AVIOContext *pb, int bytes) + { + assert(bytes <= 8); +- put_byte(pb, 0x1ff >> bytes); ++ avio_w8(pb, 0x1ff >> bytes); + while (--bytes) +- put_byte(pb, 0xff); ++ avio_w8(pb, 0xff); + } + + /** +@@ -144,7 +150,7 @@ + * @param bytes The number of bytes that need to be used to write the number. + * If zero, any number of bytes can be used. + */ +-static void put_ebml_num(ByteIOContext *pb, uint64_t num, int bytes) ++static void put_ebml_num(AVIOContext *pb, uint64_t num, int bytes) + { + int i, needed_bytes = ebml_num_size(num); + +@@ -160,10 +166,10 @@ + + num |= 1ULL << bytes*7; + for (i = bytes - 1; i >= 0; i--) +- put_byte(pb, num >> i*8); ++ avio_w8(pb, num >> i*8); + } + +-static void put_ebml_uint(ByteIOContext *pb, unsigned int elementid, uint64_t val) ++static void put_ebml_uint(AVIOContext *pb, unsigned int elementid, uint64_t val) + { + int i, bytes = 1; + uint64_t tmp = val; +@@ -172,25 +178,25 @@ + put_ebml_id(pb, elementid); + put_ebml_num(pb, bytes, 0); + for (i = bytes - 1; i >= 0; i--) +- put_byte(pb, val >> i*8); ++ avio_w8(pb, val >> i*8); + } + +-static void put_ebml_float(ByteIOContext *pb, unsigned int elementid, double val) ++static void put_ebml_float(AVIOContext *pb, unsigned int elementid, double val) + { + put_ebml_id(pb, elementid); + put_ebml_num(pb, 8, 0); +- put_be64(pb, av_dbl2int(val)); ++ avio_wb64(pb, av_double2int(val)); + } + +-static void put_ebml_binary(ByteIOContext *pb, unsigned int elementid, ++static void put_ebml_binary(AVIOContext *pb, unsigned int elementid, + const void *buf, int size) + { + put_ebml_id(pb, elementid); + put_ebml_num(pb, size, 0); +- put_buffer(pb, buf, size); ++ avio_write(pb, buf, size); + } + +-static void put_ebml_string(ByteIOContext *pb, unsigned int elementid, const char *str) ++static void put_ebml_string(AVIOContext *pb, unsigned int elementid, const char *str) + { + put_ebml_binary(pb, elementid, str, strlen(str)); + } +@@ -201,9 +207,9 @@ + * + * @param size The number of bytes to reserve, which must be at least 2. + */ +-static void put_ebml_void(ByteIOContext *pb, uint64_t size) ++static void put_ebml_void(AVIOContext *pb, uint64_t size) + { +- int64_t currentpos = url_ftell(pb); ++ int64_t currentpos = avio_tell(pb); + + assert(size >= 2); + +@@ -215,34 +221,34 @@ + put_ebml_num(pb, size-1, 0); + else + put_ebml_num(pb, size-9, 8); +- while(url_ftell(pb) < currentpos + size) +- put_byte(pb, 0); ++ while(avio_tell(pb) < currentpos + size) ++ avio_w8(pb, 0); + } + +-static ebml_master start_ebml_master(ByteIOContext *pb, unsigned int elementid, uint64_t expectedsize) ++static ebml_master start_ebml_master(AVIOContext *pb, unsigned int elementid, uint64_t expectedsize) + { + int bytes = expectedsize ? ebml_num_size(expectedsize) : 8; + put_ebml_id(pb, elementid); + put_ebml_size_unknown(pb, bytes); +- return (ebml_master){ url_ftell(pb), bytes }; ++ return (ebml_master){ avio_tell(pb), bytes }; + } + +-static void end_ebml_master(ByteIOContext *pb, ebml_master master) ++static void end_ebml_master(AVIOContext *pb, ebml_master master) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + +- if (url_fseek(pb, master.pos - master.sizebytes, SEEK_SET) < 0) ++ if (avio_seek(pb, master.pos - master.sizebytes, SEEK_SET) < 0) + return; + put_ebml_num(pb, pos - master.pos, master.sizebytes); +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + } + +-static void put_xiph_size(ByteIOContext *pb, int size) ++static void put_xiph_size(AVIOContext *pb, int size) + { + int i; + for (i = 0; i < size / 255; i++) +- put_byte(pb, 255); +- put_byte(pb, size % 255); ++ avio_w8(pb, 255); ++ avio_w8(pb, size % 255); + } + + /** +@@ -256,7 +262,7 @@ + * @param numelements The maximum number of elements that will be indexed + * by this seek head, 0 if unlimited. + */ +-static mkv_seekhead * mkv_start_seekhead(ByteIOContext *pb, int64_t segment_offset, int numelements) ++static mkv_seekhead * mkv_start_seekhead(AVIOContext *pb, int64_t segment_offset, int numelements) + { + mkv_seekhead *new_seekhead = av_mallocz(sizeof(mkv_seekhead)); + if (new_seekhead == NULL) +@@ -265,7 +271,7 @@ + new_seekhead->segment_offset = segment_offset; + + if (numelements > 0) { +- new_seekhead->filepos = url_ftell(pb); ++ new_seekhead->filepos = avio_tell(pb); + // 21 bytes max for a seek entry, 10 bytes max for the SeekHead ID + // and size, and 3 bytes to guarantee that an EBML void element + // will fit afterwards +@@ -304,17 +310,20 @@ + * @return The file offset where the seekhead was written, + * -1 if an error occurred. + */ +-static int64_t mkv_write_seekhead(ByteIOContext *pb, mkv_seekhead *seekhead) ++static int64_t mkv_write_seekhead(AVIOContext *pb, mkv_seekhead *seekhead) + { + ebml_master metaseek, seekentry; + int64_t currentpos; + int i; + +- currentpos = url_ftell(pb); ++ currentpos = avio_tell(pb); + +- if (seekhead->reserved_size > 0) +- if (url_fseek(pb, seekhead->filepos, SEEK_SET) < 0) +- return -1; ++ if (seekhead->reserved_size > 0) { ++ if (avio_seek(pb, seekhead->filepos, SEEK_SET) < 0) { ++ currentpos = -1; ++ goto fail; ++ } ++ } + + metaseek = start_ebml_master(pb, MATROSKA_ID_SEEKHEAD, seekhead->reserved_size); + for (i = 0; i < seekhead->num_entries; i++) { +@@ -332,12 +341,13 @@ + end_ebml_master(pb, metaseek); + + if (seekhead->reserved_size > 0) { +- uint64_t remaining = seekhead->filepos + seekhead->reserved_size - url_ftell(pb); ++ uint64_t remaining = seekhead->filepos + seekhead->reserved_size - avio_tell(pb); + put_ebml_void(pb, remaining); +- url_fseek(pb, currentpos, SEEK_SET); ++ avio_seek(pb, currentpos, SEEK_SET); + + currentpos = seekhead->filepos; + } ++fail: + av_free(seekhead->entries); + av_free(seekhead); + +@@ -373,13 +383,13 @@ + return 0; + } + +-static int64_t mkv_write_cues(ByteIOContext *pb, mkv_cues *cues, int num_tracks) ++static int64_t mkv_write_cues(AVIOContext *pb, mkv_cues *cues, int num_tracks) + { + ebml_master cues_element; + int64_t currentpos; + int i, j; + +- currentpos = url_ftell(pb); ++ currentpos = avio_tell(pb); + cues_element = start_ebml_master(pb, MATROSKA_ID_CUES, 0); + + for (i = 0; i < cues->num_entries; i++) { +@@ -403,12 +413,10 @@ + } + end_ebml_master(pb, cues_element); + +- av_free(cues->entries); +- av_free(cues); + return currentpos; + } + +-static int put_xiph_codecpriv(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec) ++static int put_xiph_codecpriv(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec) + { + uint8_t *header_start[3]; + int header_len[3]; +@@ -420,56 +428,43 @@ + else + first_header_size = 42; + +- if (ff_split_xiph_headers(codec->extradata, codec->extradata_size, ++ if (avpriv_split_xiph_headers(codec->extradata, codec->extradata_size, + first_header_size, header_start, header_len) < 0) { + av_log(s, AV_LOG_ERROR, "Extradata corrupt.\n"); + return -1; + } + +- put_byte(pb, 2); // number packets - 1 ++ avio_w8(pb, 2); // number packets - 1 + for (j = 0; j < 2; j++) { + put_xiph_size(pb, header_len[j]); + } + for (j = 0; j < 3; j++) +- put_buffer(pb, header_start[j], header_len[j]); ++ avio_write(pb, header_start[j], header_len[j]); + + return 0; + } + + static void get_aac_sample_rates(AVFormatContext *s, AVCodecContext *codec, int *sample_rate, int *output_sample_rate) + { +- int sri; ++ MPEG4AudioConfig mp4ac; + +- if (codec->extradata_size < 2) { +- av_log(s, AV_LOG_WARNING, "No AAC extradata, unable to determine samplerate.\n"); ++ if (avpriv_mpeg4audio_get_config(&mp4ac, codec->extradata, ++ codec->extradata_size * 8, 1) < 0) { ++ av_log(s, AV_LOG_WARNING, "Error parsing AAC extradata, unable to determine samplerate.\n"); + return; + } + +- sri = ((codec->extradata[0] << 1) & 0xE) | (codec->extradata[1] >> 7); +- if (sri > 12) { +- av_log(s, AV_LOG_WARNING, "AAC samplerate index out of bounds\n"); +- return; +- } +- *sample_rate = ff_mpeg4audio_sample_rates[sri]; +- +- // if sbr, get output sample rate as well +- if (codec->extradata_size == 5) { +- sri = (codec->extradata[4] >> 3) & 0xF; +- if (sri > 12) { +- av_log(s, AV_LOG_WARNING, "AAC output samplerate index out of bounds\n"); +- return; +- } +- *output_sample_rate = ff_mpeg4audio_sample_rates[sri]; +- } ++ *sample_rate = mp4ac.sample_rate; ++ *output_sample_rate = mp4ac.ext_sample_rate; + } + +-static int mkv_write_codecprivate(AVFormatContext *s, ByteIOContext *pb, AVCodecContext *codec, int native_id, int qt_id) ++static int mkv_write_codecprivate(AVFormatContext *s, AVIOContext *pb, AVCodecContext *codec, int native_id, int qt_id) + { +- ByteIOContext *dyn_cp; ++ AVIOContext *dyn_cp; + uint8_t *codecpriv; + int ret, codecpriv_size; + +- ret = url_open_dyn_buf(&dyn_cp); ++ ret = avio_open_dyn_buf(&dyn_cp); + if(ret < 0) + return ret; + +@@ -481,13 +476,13 @@ + else if (codec->codec_id == CODEC_ID_H264) + ret = ff_isom_write_avcc(dyn_cp, codec->extradata, codec->extradata_size); + else if (codec->extradata_size) +- put_buffer(dyn_cp, codec->extradata, codec->extradata_size); ++ avio_write(dyn_cp, codec->extradata, codec->extradata_size); + } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { + if (qt_id) { + if (!codec->codec_tag) + codec->codec_tag = ff_codec_get_tag(codec_movvideo_tags, codec->codec_id); + if (codec->extradata_size) +- put_buffer(dyn_cp, codec->extradata, codec->extradata_size); ++ avio_write(dyn_cp, codec->extradata, codec->extradata_size); + } else { + if (!codec->codec_tag) + codec->codec_tag = ff_codec_get_tag(ff_codec_bmp_tags, codec->codec_id); +@@ -512,7 +507,7 @@ + ff_put_wav_header(dyn_cp, codec); + } + +- codecpriv_size = url_close_dyn_buf(dyn_cp, &codecpriv); ++ codecpriv_size = avio_close_dyn_buf(dyn_cp, &codecpriv); + if (codecpriv_size) + put_ebml_binary(pb, MATROSKA_ID_CODECPRIVATE, codecpriv, codecpriv_size); + av_free(codecpriv); +@@ -522,11 +517,11 @@ + static int mkv_write_tracks(AVFormatContext *s) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + ebml_master tracks; + int i, j, ret; + +- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, url_ftell(pb)); ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TRACKS, avio_tell(pb)); + if (ret < 0) return ret; + + tracks = start_ebml_master(pb, MATROSKA_ID_TRACKS, 0); +@@ -539,10 +534,15 @@ + int bit_depth = av_get_bits_per_sample(codec->codec_id); + int sample_rate = codec->sample_rate; + int output_sample_rate = 0; +- AVMetadataTag *tag; ++ AVDictionaryEntry *tag; ++ ++ if (codec->codec_type == AVMEDIA_TYPE_ATTACHMENT) { ++ mkv->have_attachments = 1; ++ continue; ++ } + + if (!bit_depth) +- bit_depth = av_get_bits_per_sample_fmt(codec->sample_fmt); ++ bit_depth = av_get_bytes_per_sample(codec->sample_fmt) << 3; + + if (codec->codec_id == CODEC_ID_AAC) + get_aac_sample_rates(s, codec, &sample_rate, &output_sample_rate); +@@ -552,9 +552,9 @@ + put_ebml_uint (pb, MATROSKA_ID_TRACKUID , i + 1); + put_ebml_uint (pb, MATROSKA_ID_TRACKFLAGLACING , 0); // no lacing (yet) + +- if ((tag = av_metadata_get(st->metadata, "title", NULL, 0))) ++ if ((tag = av_dict_get(st->metadata, "title", NULL, 0))) + put_ebml_string(pb, MATROSKA_ID_TRACKNAME, tag->value); +- tag = av_metadata_get(st->metadata, "language", NULL, 0); ++ tag = av_dict_get(st->metadata, "language", NULL, 0); + put_ebml_string(pb, MATROSKA_ID_TRACKLANGUAGE, tag ? tag->value:"und"); + + if (st->disposition) +@@ -580,7 +580,10 @@ + switch (codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: + put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_VIDEO); +- put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, av_q2d(codec->time_base)*1E9); ++ if(st->avg_frame_rate.num && st->avg_frame_rate.den && 1.0/av_q2d(st->avg_frame_rate) > av_q2d(codec->time_base)) ++ put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, 1E9/av_q2d(st->avg_frame_rate)); ++ else ++ put_ebml_uint(pb, MATROSKA_ID_TRACKDEFAULTDURATION, av_q2d(codec->time_base)*1E9); + + if (!native_id && + ff_codec_get_tag(codec_movvideo_tags, codec->codec_id) && +@@ -602,12 +605,38 @@ + // XXX: interlace flag? + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELWIDTH , codec->width); + put_ebml_uint (pb, MATROSKA_ID_VIDEOPIXELHEIGHT, codec->height); ++ ++ if ((tag = av_dict_get(st->metadata, "stereo_mode", NULL, 0)) || ++ (tag = av_dict_get( s->metadata, "stereo_mode", NULL, 0))) { ++ // save stereo mode flag ++ uint64_t st_mode = MATROSKA_VIDEO_STEREO_MODE_COUNT; ++ ++ for (j=0; jvalue, matroska_video_stereo_mode[j])){ ++ st_mode = j; ++ break; ++ } ++ ++ if ((mkv->mode == MODE_WEBM && st_mode > 3 && st_mode != 11) ++ || st_mode >= MATROSKA_VIDEO_STEREO_MODE_COUNT) { ++ av_log(s, AV_LOG_ERROR, ++ "The specified stereo mode is not valid.\n"); ++ return AVERROR(EINVAL); ++ } else ++ put_ebml_uint(pb, MATROSKA_ID_VIDEOSTEREOMODE, st_mode); ++ } ++ + if (st->sample_aspect_ratio.num) { + int d_width = codec->width*av_q2d(st->sample_aspect_ratio); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYWIDTH , d_width); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYHEIGHT, codec->height); + put_ebml_uint(pb, MATROSKA_ID_VIDEODISPLAYUNIT, 3); + } ++ ++ if (codec->codec_id == CODEC_ID_RAWVIDEO) { ++ uint32_t color_space = av_le2ne32(codec->codec_tag); ++ put_ebml_binary(pb, MATROSKA_ID_VIDEOCOLORSPACE, &color_space, sizeof(color_space)); ++ } + end_ebml_master(pb, subinfo); + break; + +@@ -630,9 +659,13 @@ + + case AVMEDIA_TYPE_SUBTITLE: + put_ebml_uint(pb, MATROSKA_ID_TRACKTYPE, MATROSKA_TRACK_TYPE_SUBTITLE); ++ if (!native_id) { ++ av_log(s, AV_LOG_ERROR, "Subtitle codec %d is not supported.\n", codec->codec_id); ++ return AVERROR(ENOSYS); ++ } + break; + default: +- av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska."); ++ av_log(s, AV_LOG_ERROR, "Only audio, video, and subtitles are supported for Matroska.\n"); + break; + } + ret = mkv_write_codecprivate(s, pb, codec, native_id, qt_id); +@@ -641,7 +674,7 @@ + end_ebml_master(pb, track); + + // ms precision is the de-facto standard timescale for mkv files +- av_set_pts_info(st, 64, 1, 1000); ++ avpriv_set_pts_info(st, 64, 1, 1000); + } + end_ebml_master(pb, tracks); + return 0; +@@ -650,7 +683,7 @@ + static int mkv_write_chapters(AVFormatContext *s) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + ebml_master chapters, editionentry; + AVRational scale = {1, 1E9}; + int i, ret; +@@ -658,7 +691,7 @@ + if (!s->nb_chapters) + return 0; + +- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, url_ftell(pb)); ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CHAPTERS, avio_tell(pb)); + if (ret < 0) return ret; + + chapters = start_ebml_master(pb, MATROSKA_ID_CHAPTERS , 0); +@@ -668,7 +701,7 @@ + for (i = 0; i < s->nb_chapters; i++) { + ebml_master chapteratom, chapterdisplay; + AVChapter *c = s->chapters[i]; +- AVMetadataTag *t = NULL; ++ AVDictionaryEntry *t = NULL; + + chapteratom = start_ebml_master(pb, MATROSKA_ID_CHAPTERATOM, 0); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERUID, c->id); +@@ -678,7 +711,7 @@ + av_rescale_q(c->end, c->time_base, scale)); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGHIDDEN , 0); + put_ebml_uint(pb, MATROSKA_ID_CHAPTERFLAGENABLED, 1); +- if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { ++ if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { + chapterdisplay = start_ebml_master(pb, MATROSKA_ID_CHAPTERDISPLAY, 0); + put_ebml_string(pb, MATROSKA_ID_CHAPSTRING, t->value); + put_ebml_string(pb, MATROSKA_ID_CHAPLANG , "und"); +@@ -691,7 +724,7 @@ + return 0; + } + +-static void mkv_write_simpletag(ByteIOContext *pb, AVMetadataTag *t) ++static void mkv_write_simpletag(AVIOContext *pb, AVDictionaryEntry *t) + { + uint8_t *key = av_strdup(t->key); + uint8_t *p = key; +@@ -721,16 +754,16 @@ + av_freep(&key); + } + +-static int mkv_write_tag(AVFormatContext *s, AVMetadata *m, unsigned int elementid, ++static int mkv_write_tag(AVFormatContext *s, AVDictionary *m, unsigned int elementid, + unsigned int uid, ebml_master *tags) + { + MatroskaMuxContext *mkv = s->priv_data; + ebml_master tag, targets; +- AVMetadataTag *t = NULL; ++ AVDictionaryEntry *t = NULL; + int ret; + + if (!tags->pos) { +- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TAGS, url_ftell(s->pb)); ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_TAGS, avio_tell(s->pb)); + if (ret < 0) return ret; + + *tags = start_ebml_master(s->pb, MATROSKA_ID_TAGS, 0); +@@ -742,8 +775,8 @@ + put_ebml_uint(s->pb, elementid, uid); + end_ebml_master(s->pb, targets); + +- while ((t = av_metadata_get(m, "", t, AV_METADATA_IGNORE_SUFFIX))) +- if (strcasecmp(t->key, "title")) ++ while ((t = av_dict_get(m, "", t, AV_DICT_IGNORE_SUFFIX))) ++ if (av_strcasecmp(t->key, "title") && av_strcasecmp(t->key, "stereo_mode")) + mkv_write_simpletag(s->pb, t); + + end_ebml_master(s->pb, tag); +@@ -757,7 +790,7 @@ + + ff_metadata_conv_ctx(s, ff_mkv_metadata_conv, NULL); + +- if (av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) { ++ if (av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) { + ret = mkv_write_tag(s, s->metadata, 0, 0, &tags); + if (ret < 0) return ret; + } +@@ -765,7 +798,7 @@ + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + +- if (!av_metadata_get(st->metadata, "", 0, AV_METADATA_IGNORE_SUFFIX)) ++ if (!av_dict_get(st->metadata, "", 0, AV_DICT_IGNORE_SUFFIX)) + continue; + + ret = mkv_write_tag(s, st->metadata, MATROSKA_ID_TAGTARGETS_TRACKUID, i + 1, &tags); +@@ -775,7 +808,7 @@ + for (i = 0; i < s->nb_chapters; i++) { + AVChapter *ch = s->chapters[i]; + +- if (!av_metadata_get(ch->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ++ if (!av_dict_get(ch->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + continue; + + ret = mkv_write_tag(s, ch->metadata, MATROSKA_ID_TAGTARGETS_CHAPTERUID, ch->id, &tags); +@@ -787,12 +820,74 @@ + return 0; + } + ++static int mkv_write_attachments(AVFormatContext *s) ++{ ++ MatroskaMuxContext *mkv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ebml_master attachments; ++ AVLFG c; ++ int i, ret; ++ ++ if (!mkv->have_attachments) ++ return 0; ++ ++ av_lfg_init(&c, av_get_random_seed()); ++ ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_ATTACHMENTS, avio_tell(pb)); ++ if (ret < 0) return ret; ++ ++ attachments = start_ebml_master(pb, MATROSKA_ID_ATTACHMENTS, 0); ++ ++ for (i = 0; i < s->nb_streams; i++) { ++ AVStream *st = s->streams[i]; ++ ebml_master attached_file; ++ AVDictionaryEntry *t; ++ const char *mimetype = NULL; ++ ++ if (st->codec->codec_type != AVMEDIA_TYPE_ATTACHMENT) ++ continue; ++ ++ attached_file = start_ebml_master(pb, MATROSKA_ID_ATTACHEDFILE, 0); ++ ++ if (t = av_dict_get(st->metadata, "title", NULL, 0)) ++ put_ebml_string(pb, MATROSKA_ID_FILEDESC, t->value); ++ if (!(t = av_dict_get(st->metadata, "filename", NULL, 0))) { ++ av_log(s, AV_LOG_ERROR, "Attachment stream %d has no filename tag.\n", i); ++ return AVERROR(EINVAL); ++ } ++ put_ebml_string(pb, MATROSKA_ID_FILENAME, t->value); ++ if (t = av_dict_get(st->metadata, "mimetype", NULL, 0)) ++ mimetype = t->value; ++ else if (st->codec->codec_id != CODEC_ID_NONE ) { ++ int i; ++ for (i = 0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) ++ if (ff_mkv_mime_tags[i].id == st->codec->codec_id) { ++ mimetype = ff_mkv_mime_tags[i].str; ++ break; ++ } ++ } ++ if (!mimetype) { ++ av_log(s, AV_LOG_ERROR, "Attachment stream %d has no mimetype tag and " ++ "it cannot be deduced from the codec id.\n", i); ++ return AVERROR(EINVAL); ++ } ++ ++ put_ebml_string(pb, MATROSKA_ID_FILEMIMETYPE, mimetype); ++ put_ebml_binary(pb, MATROSKA_ID_FILEDATA, st->codec->extradata, st->codec->extradata_size); ++ put_ebml_uint(pb, MATROSKA_ID_FILEUID, av_lfg_get(&c)); ++ end_ebml_master(pb, attached_file); ++ } ++ end_ebml_master(pb, attachments); ++ ++ return 0; ++} ++ + static int mkv_write_header(AVFormatContext *s) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + ebml_master ebml_header, segment_info; +- AVMetadataTag *tag; ++ AVDictionaryEntry *tag; + int ret, i; + + if (!strcmp(s->oformat->name, "webm")) mkv->mode = MODE_WEBM; +@@ -813,7 +908,7 @@ + end_ebml_master(pb, ebml_header); + + mkv->segment = start_ebml_master(pb, MATROSKA_ID_SEGMENT, 0); +- mkv->segment_offset = url_ftell(pb); ++ mkv->segment_offset = avio_tell(pb); + + // we write 2 seek heads - one at the end of the file to point to each + // cluster, and one at the beginning to point to all other level one +@@ -824,12 +919,12 @@ + if (!mkv->main_seekhead) + return AVERROR(ENOMEM); + +- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, url_ftell(pb)); ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_INFO, avio_tell(pb)); + if (ret < 0) return ret; + + segment_info = start_ebml_master(pb, MATROSKA_ID_INFO, 0); + put_ebml_uint(pb, MATROSKA_ID_TIMECODESCALE, 1000000); +- if ((tag = av_metadata_get(s->metadata, "title", NULL, 0))) ++ if ((tag = av_dict_get(s->metadata, "title", NULL, 0))) + put_ebml_string(pb, MATROSKA_ID_TITLE, tag->value); + if (!(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { + uint32_t segment_uid[4]; +@@ -847,7 +942,7 @@ + + // reserve space for the duration + mkv->duration = 0; +- mkv->duration_offset = url_ftell(pb); ++ mkv->duration_offset = avio_tell(pb); + put_ebml_void(pb, 11); // assumes double-precision float to be written + end_ebml_master(pb, segment_info); + +@@ -860,9 +955,12 @@ + + ret = mkv_write_tags(s); + if (ret < 0) return ret; ++ ++ ret = mkv_write_attachments(s); ++ if (ret < 0) return ret; + } + +- if (url_is_streamed(s->pb)) ++ if (!s->pb->seekable) + mkv_write_seekhead(pb, mkv->main_seekhead); + + mkv->cues = mkv_start_cues(mkv->segment_offset); +@@ -873,7 +971,7 @@ + mkv->cur_audio_pkt.size = 0; + mkv->audio_buffer_size = 0; + +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + +@@ -901,7 +999,7 @@ + return end - start; + } + +-static int mkv_write_ass_blocks(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt) ++static int mkv_write_ass_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) + { + MatroskaMuxContext *mkv = s->priv_data; + int i, layer = 0, max_duration = 0, size, line_size, data_size = pkt->size; +@@ -922,20 +1020,20 @@ + size -= start - data; + sscanf(data, "Dialogue: %d,", &layer); + i = snprintf(buffer, sizeof(buffer), "%"PRId64",%d,", +- s->streams[pkt->stream_index]->nb_frames++, layer); ++ s->streams[pkt->stream_index]->nb_frames, layer); + size = FFMIN(i+size, sizeof(buffer)); + memcpy(buffer+i, start, size-i); + + av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " + "pts %" PRId64 ", duration %d\n", +- url_ftell(pb), size, pkt->pts, duration); ++ avio_tell(pb), size, pkt->pts, duration); + blockgroup = start_ebml_master(pb, MATROSKA_ID_BLOCKGROUP, mkv_blockgroup_size(size)); + put_ebml_id(pb, MATROSKA_ID_BLOCK); + put_ebml_num(pb, size+4, 0); +- put_byte(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 +- put_be16(pb, pkt->pts - mkv->cluster_pts); +- put_byte(pb, 0); +- put_buffer(pb, buffer, size); ++ avio_w8(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 ++ avio_wb16(pb, pkt->pts - mkv->cluster_pts); ++ avio_w8(pb, 0); ++ avio_write(pb, buffer, size); + put_ebml_uint(pb, MATROSKA_ID_BLOCKDURATION, duration); + end_ebml_master(pb, blockgroup); + +@@ -946,7 +1044,7 @@ + return max_duration; + } + +-static void mkv_write_block(AVFormatContext *s, ByteIOContext *pb, ++static void mkv_write_block(AVFormatContext *s, AVIOContext *pb, + unsigned int blockid, AVPacket *pkt, int flags) + { + MatroskaMuxContext *mkv = s->priv_data; +@@ -957,7 +1055,7 @@ + + av_log(s, AV_LOG_DEBUG, "Writing block at offset %" PRIu64 ", size %d, " + "pts %" PRId64 ", dts %" PRId64 ", duration %d, flags %d\n", +- url_ftell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, flags); ++ avio_tell(pb), pkt->size, pkt->pts, pkt->dts, pkt->duration, flags); + if (codec->codec_id == CODEC_ID_H264 && codec->extradata_size > 0 && + (AV_RB24(codec->extradata) == 1 || AV_RB32(codec->extradata) == 1)) + ff_avc_parse_nal_units_buf(pkt->data, &data, &size); +@@ -965,10 +1063,10 @@ + data = pkt->data; + put_ebml_id(pb, blockid); + put_ebml_num(pb, size+4, 0); +- put_byte(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 +- put_be16(pb, ts - mkv->cluster_pts); +- put_byte(pb, flags); +- put_buffer(pb, data, size); ++ avio_w8(pb, 0x80 | (pkt->stream_index + 1)); // this assumes stream_index is less than 126 ++ avio_wb16(pb, ts - mkv->cluster_pts); ++ avio_w8(pb, flags); ++ avio_write(pb, data, size); + if (data != pkt->data) + av_free(data); + } +@@ -992,7 +1090,7 @@ + return duration; + } + +-static int mkv_write_srt_blocks(AVFormatContext *s, ByteIOContext *pb, AVPacket *pkt) ++static int mkv_write_srt_blocks(AVFormatContext *s, AVIOContext *pb, AVPacket *pkt) + { + ebml_master blockgroup; + AVPacket pkt2 = *pkt; +@@ -1017,8 +1115,8 @@ + if (!mkv->dyn_bc) + return; + +- bufsize = url_close_dyn_buf(mkv->dyn_bc, &dyn_buf); +- put_buffer(s->pb, dyn_buf, bufsize); ++ bufsize = avio_close_dyn_buf(mkv->dyn_bc, &dyn_buf); ++ avio_write(s->pb, dyn_buf, bufsize); + av_free(dyn_buf); + mkv->dyn_bc = NULL; + } +@@ -1026,7 +1124,7 @@ + static int mkv_write_packet_internal(AVFormatContext *s, AVPacket *pkt) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + int keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); + int duration = pkt->duration; +@@ -1038,14 +1136,14 @@ + return AVERROR(EINVAL); + } + +- if (url_is_streamed(s->pb)) { ++ if (!s->pb->seekable) { + if (!mkv->dyn_bc) +- url_open_dyn_buf(&mkv->dyn_bc); ++ avio_open_dyn_buf(&mkv->dyn_bc); + pb = mkv->dyn_bc; + } + + if (!mkv->cluster_pos) { +- mkv->cluster_pos = url_ftell(s->pb); ++ mkv->cluster_pos = avio_tell(s->pb); + mkv->cluster = start_ebml_master(pb, MATROSKA_ID_CLUSTER, 0); + put_ebml_uint(pb, MATROSKA_ID_CLUSTERTIMECODE, FFMAX(0, ts)); + mkv->cluster_pts = FFMAX(0, ts); +@@ -1090,20 +1188,20 @@ + static int mkv_write_packet(AVFormatContext *s, AVPacket *pkt) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = url_is_streamed(s->pb) ? mkv->dyn_bc : s->pb; ++ AVIOContext *pb = s->pb->seekable ? s->pb : mkv->dyn_bc; + AVCodecContext *codec = s->streams[pkt->stream_index]->codec; + int ret, keyframe = !!(pkt->flags & AV_PKT_FLAG_KEY); + int64_t ts = mkv->tracks[pkt->stream_index].write_dts ? pkt->dts : pkt->pts; +- int cluster_size = url_ftell(pb) - (url_is_streamed(s->pb) ? 0 : mkv->cluster_pos); ++ int cluster_size = avio_tell(pb) - (s->pb->seekable ? mkv->cluster_pos : 0); + + // start a new cluster every 5 MB or 5 sec, or 32k / 1 sec for streaming or + // after 4k and on a keyframe + if (mkv->cluster_pos && +- ((url_is_streamed(s->pb) && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000)) ++ ((!s->pb->seekable && (cluster_size > 32*1024 || ts > mkv->cluster_pts + 1000)) + || cluster_size > 5*1024*1024 || ts > mkv->cluster_pts + 5000 + || (codec->codec_type == AVMEDIA_TYPE_VIDEO && keyframe && cluster_size > 4*1024))) { + av_log(s, AV_LOG_DEBUG, "Starting new cluster at offset %" PRIu64 +- " bytes, pts %" PRIu64 "\n", url_ftell(pb), ts); ++ " bytes, pts %" PRIu64 "\n", avio_tell(pb), ts); + end_ebml_master(pb, mkv->cluster); + mkv->cluster_pos = 0; + if (mkv->dyn_bc) +@@ -1132,7 +1230,7 @@ + static int mkv_write_trailer(AVFormatContext *s) + { + MatroskaMuxContext *mkv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t currentpos, cuespos; + int ret; + +@@ -1153,76 +1251,108 @@ + end_ebml_master(pb, mkv->cluster); + } + +- if (!url_is_streamed(pb)) { +- cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); ++ if (pb->seekable) { ++ if (mkv->cues->num_entries) { ++ cuespos = mkv_write_cues(pb, mkv->cues, s->nb_streams); ++ ++ ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES, cuespos); ++ if (ret < 0) return ret; ++ } + +- ret = mkv_add_seekhead_entry(mkv->main_seekhead, MATROSKA_ID_CUES , cuespos); +- if (ret < 0) return ret; + mkv_write_seekhead(pb, mkv->main_seekhead); + + // update the duration + av_log(s, AV_LOG_DEBUG, "end duration = %" PRIu64 "\n", mkv->duration); +- currentpos = url_ftell(pb); +- url_fseek(pb, mkv->duration_offset, SEEK_SET); ++ currentpos = avio_tell(pb); ++ avio_seek(pb, mkv->duration_offset, SEEK_SET); + put_ebml_float(pb, MATROSKA_ID_DURATION, mkv->duration); + +- url_fseek(pb, currentpos, SEEK_SET); ++ avio_seek(pb, currentpos, SEEK_SET); + } + + end_ebml_master(pb, mkv->segment); + av_free(mkv->tracks); ++ av_freep(&mkv->cues->entries); ++ av_freep(&mkv->cues); + av_destruct_packet(&mkv->cur_audio_pkt); +- put_flush_packet(pb); ++ avio_flush(pb); ++ return 0; ++} ++ ++static int mkv_query_codec(enum CodecID codec_id, int std_compliance) ++{ ++ int i; ++ for (i = 0; ff_mkv_codec_tags[i].id != CODEC_ID_NONE; i++) ++ if (ff_mkv_codec_tags[i].id == codec_id) ++ return 1; ++ ++ if (std_compliance < FF_COMPLIANCE_NORMAL) { // mkv theoretically supports any ++ enum AVMediaType type = avcodec_get_type(codec_id); // video/audio through VFW/ACM ++ if (type == AVMEDIA_TYPE_VIDEO || type == AVMEDIA_TYPE_AUDIO) ++ return 1; ++ } ++ + return 0; + } + + #if CONFIG_MATROSKA_MUXER + AVOutputFormat ff_matroska_muxer = { +- "matroska", +- NULL_IF_CONFIG_SMALL("Matroska file format"), +- "video/x-matroska", +- "mkv", +- sizeof(MatroskaMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG4, +- mkv_write_header, +- mkv_write_packet, +- mkv_write_trailer, +- .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, +- .codec_tag = (const AVCodecTag* const []){ff_codec_bmp_tags, ff_codec_wav_tags, 0}, +- .subtitle_codec = CODEC_ID_TEXT, ++ .name = "matroska", ++ .long_name = NULL_IF_CONFIG_SMALL("Matroska file format"), ++ .mime_type = "video/x-matroska", ++ .extensions = "mkv", ++ .priv_data_size = sizeof(MatroskaMuxContext), ++#if CONFIG_LIBVORBIS_ENCODER ++ .audio_codec = CODEC_ID_VORBIS, ++#else ++ .audio_codec = CODEC_ID_AC3, ++#endif ++#if CONFIG_LIBX264_ENCODER ++ .video_codec = CODEC_ID_H264, ++#else ++ .video_codec = CODEC_ID_MPEG4, ++#endif ++ .write_header = mkv_write_header, ++ .write_packet = mkv_write_packet, ++ .write_trailer = mkv_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, ++ .subtitle_codec = CODEC_ID_SSA, ++ .query_codec = mkv_query_codec, + }; + #endif + + #if CONFIG_WEBM_MUXER + AVOutputFormat ff_webm_muxer = { +- "webm", +- NULL_IF_CONFIG_SMALL("WebM file format"), +- "video/webm", +- "webm", +- sizeof(MatroskaMuxContext), +- CODEC_ID_VORBIS, +- CODEC_ID_VP8, +- mkv_write_header, +- mkv_write_packet, +- mkv_write_trailer, +- .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, ++ .name = "webm", ++ .long_name = NULL_IF_CONFIG_SMALL("WebM file format"), ++ .mime_type = "video/webm", ++ .extensions = "webm", ++ .priv_data_size = sizeof(MatroskaMuxContext), ++ .audio_codec = CODEC_ID_VORBIS, ++ .video_codec = CODEC_ID_VP8, ++ .write_header = mkv_write_header, ++ .write_packet = mkv_write_packet, ++ .write_trailer = mkv_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS | AVFMT_TS_NONSTRICT, + }; + #endif + + #if CONFIG_MATROSKA_AUDIO_MUXER + AVOutputFormat ff_matroska_audio_muxer = { +- "matroska", +- NULL_IF_CONFIG_SMALL("Matroska file format"), +- "audio/x-matroska", +- "mka", +- sizeof(MatroskaMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_NONE, +- mkv_write_header, +- mkv_write_packet, +- mkv_write_trailer, ++ .name = "matroska", ++ .long_name = NULL_IF_CONFIG_SMALL("Matroska file format"), ++ .mime_type = "audio/x-matroska", ++ .extensions = "mka", ++ .priv_data_size = sizeof(MatroskaMuxContext), ++#if CONFIG_LIBVORBIS_ENCODER ++ .audio_codec = CODEC_ID_VORBIS, ++#else ++ .audio_codec = CODEC_ID_AC3, ++#endif ++ .video_codec = CODEC_ID_NONE, ++ .write_header = mkv_write_header, ++ .write_packet = mkv_write_packet, ++ .write_trailer = mkv_write_trailer, + .flags = AVFMT_GLOBALHEADER, +- .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0}, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroska.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroska.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/matroska.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/matroska.h 2012-05-14 14:08:55.007353526 +0200 +@@ -77,8 +77,13 @@ + #define MATROSKA_ID_TRACKNUMBER 0xD7 + #define MATROSKA_ID_TRACKUID 0x73C5 + #define MATROSKA_ID_TRACKTYPE 0x83 +-#define MATROSKA_ID_TRACKAUDIO 0xE1 +-#define MATROSKA_ID_TRACKVIDEO 0xE0 ++#define MATROSKA_ID_TRACKVIDEO 0xE0 ++#define MATROSKA_ID_TRACKAUDIO 0xE1 ++#define MATROSKA_ID_TRACKOPERATION 0xE2 ++#define MATROSKA_ID_TRACKCOMBINEPLANES 0xE3 ++#define MATROSKA_ID_TRACKPLANE 0xE4 ++#define MATROSKA_ID_TRACKPLANEUID 0xE5 ++#define MATROSKA_ID_TRACKPLANETYPE 0xE6 + #define MATROSKA_ID_CODECID 0x86 + #define MATROSKA_ID_CODECPRIVATE 0x63A2 + #define MATROSKA_ID_CODECNAME 0x258688 +@@ -111,7 +116,7 @@ + #define MATROSKA_ID_VIDEOPIXELCROPR 0x54DD + #define MATROSKA_ID_VIDEODISPLAYUNIT 0x54B2 + #define MATROSKA_ID_VIDEOFLAGINTERLACED 0x9A +-#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B9 ++#define MATROSKA_ID_VIDEOSTEREOMODE 0x53B8 + #define MATROSKA_ID_VIDEOASPECTRATIO 0x54B3 + #define MATROSKA_ID_VIDEOCOLORSPACE 0x2EB524 + +@@ -218,6 +223,24 @@ + MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP = 3, + } MatroskaTrackEncodingCompAlgo; + ++typedef enum { ++ MATROSKA_VIDEO_STEREOMODE_TYPE_MONO = 0, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_LEFT_RIGHT = 1, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_BOTTOM_TOP = 2, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_TOP_BOTTOM = 3, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_RL = 4, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_CHECKERBOARD_LR = 5, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_RL = 6, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_ROW_INTERLEAVED_LR = 7, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_RL = 8, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_COL_INTERLEAVED_LR = 9, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_CYAN_RED = 10, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_RIGHT_LEFT = 11, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_ANAGLYPH_GREEN_MAG = 12, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_LR = 13, ++ MATROSKA_VIDEO_STEREOMODE_TYPE_BOTH_EYES_BLOCK_RL = 14, ++} MatroskaVideoStereoModeType; ++ + /* + * Matroska Codec IDs, strings + */ +@@ -235,8 +258,13 @@ + /* max. depth in the EBML tree structure */ + #define EBML_MAX_DEPTH 16 + ++#define MATROSKA_VIDEO_STEREO_MODE_COUNT 15 ++#define MATROSKA_VIDEO_STEREO_PLANE_COUNT 3 ++ + extern const CodecTags ff_mkv_codec_tags[]; + extern const CodecMime ff_mkv_mime_tags[]; + extern const AVMetadataConv ff_mkv_metadata_conv[]; ++extern const char * const matroska_video_stereo_mode[MATROSKA_VIDEO_STEREO_MODE_COUNT]; ++extern const char * const matroska_video_stereo_plane[MATROSKA_VIDEO_STEREO_PLANE_COUNT]; + + #endif /* AVFORMAT_MATROSKA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/md5enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/md5enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/md5enc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/md5enc.c 2012-05-14 14:08:55.017353728 +0200 +@@ -36,8 +36,8 @@ + buf[offset] = '\n'; + buf[offset+1] = 0; + +- put_buffer(s->pb, buf, strlen(buf)); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf, strlen(buf)); ++ avio_flush(s->pb); + } + + #if CONFIG_MD5_MUXER +@@ -66,16 +66,15 @@ + } + + AVOutputFormat ff_md5_muxer = { +- "md5", +- NULL_IF_CONFIG_SMALL("MD5 testing format"), +- NULL, +- "", +- PRIVSIZE, +- CODEC_ID_PCM_S16LE, +- CODEC_ID_RAWVIDEO, +- write_header, +- write_packet, +- write_trailer, ++ .name = "md5", ++ .long_name = NULL_IF_CONFIG_SMALL("MD5 testing format"), ++ .priv_data_size = PRIVSIZE, ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = write_header, ++ .write_packet = write_packet, ++ .write_trailer = write_trailer, ++ .flags = AVFMT_NOTIMESTAMPS, + }; + #endif + +@@ -96,15 +95,12 @@ + } + + AVOutputFormat ff_framemd5_muxer = { +- "framemd5", +- NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"), +- NULL, +- "", +- PRIVSIZE, +- CODEC_ID_PCM_S16LE, +- CODEC_ID_RAWVIDEO, +- NULL, +- framemd5_write_packet, +- NULL, ++ .name = "framemd5", ++ .long_name = NULL_IF_CONFIG_SMALL("Per-frame MD5 testing format"), ++ .priv_data_size = PRIVSIZE, ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_packet = framemd5_write_packet, ++ .flags = AVFMT_VARIABLE_FPS, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/md5proto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/md5proto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/md5proto.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/md5proto.c 2012-05-14 14:08:55.018353749 +0200 +@@ -25,6 +25,7 @@ + #include "libavutil/error.h" + #include "avformat.h" + #include "avio.h" ++#include "url.h" + + #define PRIV_SIZE 128 + +@@ -35,7 +36,7 @@ + return -1; + } + +- if (flags != URL_WRONLY) ++ if (!(flags & AVIO_FLAG_WRITE)) + return AVERROR(EINVAL); + + av_md5_init(h->priv_data); +@@ -64,11 +65,12 @@ + av_strstart(filename, "md5:", &filename); + + if (*filename) { +- err = url_open(&out, filename, URL_WRONLY); ++ err = ffurl_open(&out, filename, AVIO_FLAG_WRITE, ++ &h->interrupt_callback, NULL); + if (err) + return err; +- err = url_write(out, buf, i*2+1); +- url_close(out); ++ err = ffurl_write(out, buf, i*2+1); ++ ffurl_close(out); + } else { + if (fwrite(buf, 1, i*2+1, stdout) < i*2+1) + err = AVERROR(errno); +@@ -77,16 +79,11 @@ + return err; + } + +-static int md5_get_handle(URLContext *h) +-{ +- return (intptr_t)h->priv_data; +-} + + URLProtocol ff_md5_protocol = { + .name = "md5", + .url_open = md5_open, + .url_write = md5_write, + .url_close = md5_close, +- .url_get_file_handle = md5_get_handle, + .priv_data_size = PRIV_SIZE, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata.c 2012-05-14 14:08:55.019353769 +0200 +@@ -18,78 +18,21 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include + #include "avformat.h" + #include "metadata.h" ++#include "libavutil/dict.h" ++#include "libavutil/avstring.h" + +-AVMetadataTag * +-av_metadata_get(AVMetadata *m, const char *key, const AVMetadataTag *prev, int flags) ++#if FF_API_OLD_METADATA2 ++AVDictionaryEntry * ++av_metadata_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) + { +- unsigned int i, j; +- +- if(!m) +- return NULL; +- +- if(prev) i= prev - m->elems + 1; +- else i= 0; +- +- for(; icount; i++){ +- const char *s= m->elems[i].key; +- if(flags & AV_METADATA_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++); +- else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++); +- if(key[j]) +- continue; +- if(s[j] && !(flags & AV_METADATA_IGNORE_SUFFIX)) +- continue; +- return &m->elems[i]; +- } +- return NULL; ++ return av_dict_get(m, key, prev, flags); + } + +-int av_metadata_set2(AVMetadata **pm, const char *key, const char *value, int flags) ++int av_metadata_set2(AVDictionary **pm, const char *key, const char *value, int flags) + { +- AVMetadata *m= *pm; +- AVMetadataTag *tag= av_metadata_get(m, key, NULL, flags); +- +- if(!m) +- m=*pm= av_mallocz(sizeof(*m)); +- +- if(tag){ +- if (flags & AV_METADATA_DONT_OVERWRITE) +- return 0; +- av_free(tag->value); +- av_free(tag->key); +- *tag= m->elems[--m->count]; +- }else{ +- AVMetadataTag *tmp= av_realloc(m->elems, (m->count+1) * sizeof(*m->elems)); +- if(tmp){ +- m->elems= tmp; +- }else +- return AVERROR(ENOMEM); +- } +- if(value){ +- if(flags & AV_METADATA_DONT_STRDUP_KEY){ +- m->elems[m->count].key = key; +- }else +- m->elems[m->count].key = av_strdup(key ); +- if(flags & AV_METADATA_DONT_STRDUP_VAL){ +- m->elems[m->count].value= value; +- }else +- m->elems[m->count].value= av_strdup(value); +- m->count++; +- } +- if(!m->count) { +- av_free(m->elems); +- av_freep(pm); +- } +- +- return 0; +-} +- +-#if FF_API_OLD_METADATA +-int av_metadata_set(AVMetadata **pm, const char *key, const char *value) +-{ +- return av_metadata_set2(pm, key, value, 0); ++ return av_dict_set(pm, key, value, flags); + } + + void av_metadata_conv(AVFormatContext *ctx, const AVMetadataConv *d_conv, +@@ -97,52 +40,48 @@ + { + return; + } +-#endif + +-void av_metadata_free(AVMetadata **pm) ++void av_metadata_free(AVDictionary **pm) + { +- AVMetadata *m= *pm; ++ av_dict_free(pm); ++} + +- if(m){ +- while(m->count--){ +- av_free(m->elems[m->count].key); +- av_free(m->elems[m->count].value); +- } +- av_free(m->elems); +- } +- av_freep(pm); ++void av_metadata_copy(AVDictionary **dst, AVDictionary *src, int flags) ++{ ++ av_dict_copy(dst, src, flags); + } ++#endif + +-void ff_metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, ++void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, + const AVMetadataConv *s_conv) + { + /* TODO: use binary search to look up the two conversion tables + if the tables are getting big enough that it would matter speed wise */ + const AVMetadataConv *sc, *dc; +- AVMetadataTag *mtag = NULL; +- AVMetadata *dst = NULL; ++ AVDictionaryEntry *mtag = NULL; ++ AVDictionary *dst = NULL; + const char *key; + + if (d_conv == s_conv) + return; + +- while((mtag=av_metadata_get(*pm, "", mtag, AV_METADATA_IGNORE_SUFFIX))) { ++ while ((mtag = av_dict_get(*pm, "", mtag, AV_DICT_IGNORE_SUFFIX))) { + key = mtag->key; + if (s_conv) + for (sc=s_conv; sc->native; sc++) +- if (!strcasecmp(key, sc->native)) { ++ if (!av_strcasecmp(key, sc->native)) { + key = sc->generic; + break; + } + if (d_conv) + for (dc=d_conv; dc->native; dc++) +- if (!strcasecmp(key, dc->generic)) { ++ if (!av_strcasecmp(key, dc->generic)) { + key = dc->native; + break; + } +- av_metadata_set2(&dst, key, mtag->value, 0); ++ av_dict_set(&dst, key, mtag->value, 0); + } +- av_metadata_free(pm); ++ av_dict_free(pm); + *pm = dst; + } + +@@ -159,10 +98,3 @@ + ff_metadata_conv(&ctx->programs[i]->metadata, d_conv, s_conv); + } + +-void av_metadata_copy(AVMetadata **dst, AVMetadata *src, int flags) +-{ +- AVMetadataTag *t = NULL; +- +- while ((t = av_metadata_get(src, "", t, AV_METADATA_IGNORE_SUFFIX))) +- av_metadata_set2(dst, t->key, t->value, flags); +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata_compat.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata_compat.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata_compat.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata_compat.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,148 +0,0 @@ +-/* +- * Copyright (c) 2009 Aurelien Jacobs +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#include +-#include "avformat.h" +-#include "metadata.h" +-#include "libavutil/avstring.h" +- +-#if FF_API_OLD_METADATA +- +-#define SIZE_OFFSET(x) sizeof(((AVFormatContext*)0)->x),offsetof(AVFormatContext,x) +- +-static const struct { +- const char name[16]; +- int size; +- int offset; +-} compat_tab[] = { +- { "title", SIZE_OFFSET(title) }, +- { "author", SIZE_OFFSET(author) }, +- { "copyright", SIZE_OFFSET(copyright) }, +- { "comment", SIZE_OFFSET(comment) }, +- { "album", SIZE_OFFSET(album) }, +- { "year", SIZE_OFFSET(year) }, +- { "track", SIZE_OFFSET(track) }, +- { "genre", SIZE_OFFSET(genre) }, +- +- { "artist", SIZE_OFFSET(author) }, +- { "creator", SIZE_OFFSET(author) }, +- { "written_by", SIZE_OFFSET(author) }, +- { "lead_performer", SIZE_OFFSET(author) }, +- { "composer", SIZE_OFFSET(author) }, +- { "performer", SIZE_OFFSET(author) }, +- { "description", SIZE_OFFSET(comment) }, +- { "albumtitle", SIZE_OFFSET(album) }, +- { "date", SIZE_OFFSET(year) }, +- { "date_written", SIZE_OFFSET(year) }, +- { "date_released", SIZE_OFFSET(year) }, +- { "tracknumber", SIZE_OFFSET(track) }, +- { "part_number", SIZE_OFFSET(track) }, +-}; +- +-void ff_metadata_demux_compat(AVFormatContext *ctx) +-{ +- AVMetadata *m; +- int i, j; +- +- if ((m = ctx->metadata)) +- for (j=0; jcount; j++) +- for (i=0; ielems[j].key, compat_tab[i].name)) { +- int *ptr = (int *)((char *)ctx+compat_tab[i].offset); +- if (*ptr) continue; +- if (compat_tab[i].size > sizeof(int)) +- av_strlcpy((char *)ptr, m->elems[j].value, compat_tab[i].size); +- else +- *ptr = atoi(m->elems[j].value); +- } +- +- for (i=0; inb_chapters; i++) +- if ((m = ctx->chapters[i]->metadata)) +- for (j=0; jcount; j++) +- if (!strcasecmp(m->elems[j].key, "title")) { +- av_free(ctx->chapters[i]->title); +- ctx->chapters[i]->title = av_strdup(m->elems[j].value); +- } +- +- for (i=0; inb_programs; i++) +- if ((m = ctx->programs[i]->metadata)) +- for (j=0; jcount; j++) { +- if (!strcasecmp(m->elems[j].key, "name")) { +- av_free(ctx->programs[i]->name); +- ctx->programs[i]->name = av_strdup(m->elems[j].value); +- } +- if (!strcasecmp(m->elems[j].key, "provider_name")) { +- av_free(ctx->programs[i]->provider_name); +- ctx->programs[i]->provider_name = av_strdup(m->elems[j].value); +- } +- } +- +- for (i=0; inb_streams; i++) +- if ((m = ctx->streams[i]->metadata)) +- for (j=0; jcount; j++) { +- if (!strcasecmp(m->elems[j].key, "language")) +- av_strlcpy(ctx->streams[i]->language, m->elems[j].value, 4); +- if (!strcasecmp(m->elems[j].key, "filename")) { +- av_free(ctx->streams[i]->filename); +- ctx->streams[i]->filename= av_strdup(m->elems[j].value); +- } +- } +-} +- +- +-#define FILL_METADATA(s, key, value) { \ +- if (!av_metadata_get(s->metadata, #key, NULL, 0)) \ +- av_metadata_set2(&s->metadata, #key, value, 0); \ +- } +-#define FILL_METADATA_STR(s, key) { \ +- if (s->key && *s->key) FILL_METADATA(s, key, s->key); } +-#define FILL_METADATA_INT(s, key) { \ +- char number[10]; \ +- snprintf(number, sizeof(number), "%d", s->key); \ +- if(s->key) FILL_METADATA(s, key, number) } +- +-void ff_metadata_mux_compat(AVFormatContext *ctx) +-{ +- int i; +- +- if (ctx->metadata && ctx->metadata->count > 0) +- return; +- +- FILL_METADATA_STR(ctx, title); +- FILL_METADATA_STR(ctx, author); +- FILL_METADATA_STR(ctx, copyright); +- FILL_METADATA_STR(ctx, comment); +- FILL_METADATA_STR(ctx, album); +- FILL_METADATA_INT(ctx, year); +- FILL_METADATA_INT(ctx, track); +- FILL_METADATA_STR(ctx, genre); +- for (i=0; inb_chapters; i++) +- FILL_METADATA_STR(ctx->chapters[i], title); +- for (i=0; inb_programs; i++) { +- FILL_METADATA_STR(ctx->programs[i], name); +- FILL_METADATA_STR(ctx->programs[i], provider_name); +- } +- for (i=0; inb_streams; i++) { +- FILL_METADATA_STR(ctx->streams[i], language); +- FILL_METADATA_STR(ctx->streams[i], filename); +- } +-} +- +-#endif /* FF_API_OLD_METADATA */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/metadata.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/metadata.h 2012-05-14 14:08:55.019353769 +0200 +@@ -29,26 +29,17 @@ + + + #include "avformat.h" +- +-struct AVMetadata{ +- int count; +- AVMetadataTag *elems; +-}; ++#include "libavutil/dict.h" + + struct AVMetadataConv{ + const char *native; + const char *generic; + }; +-#if !FF_API_OLD_METADATA ++#if !FF_API_OLD_METADATA2 + typedef struct AVMetadataConv AVMetadataConv; + #endif + +-#if FF_API_OLD_METADATA +-void ff_metadata_demux_compat(AVFormatContext *s); +-void ff_metadata_mux_compat(AVFormatContext *s); +-#endif +- +-void ff_metadata_conv(AVMetadata **pm, const AVMetadataConv *d_conv, ++void ff_metadata_conv(AVDictionary **pm, const AVMetadataConv *d_conv, + const AVMetadataConv *s_conv); + void ff_metadata_conv_ctx(AVFormatContext *ctx, const AVMetadataConv *d_conv, + const AVMetadataConv *s_conv); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/microdvddec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/microdvddec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/microdvddec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/microdvddec.c 2012-05-14 14:08:55.021353809 +0200 +@@ -0,0 +1,129 @@ ++/* ++ * MicroDVD subtitle demuxer ++ * Copyright (c) 2010 Aurelien Jacobs ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "libavutil/intreadwrite.h" ++ ++#define MAX_LINESIZE 2048 ++ ++ ++typedef struct { ++ uint8_t lines[3][MAX_LINESIZE]; ++ int64_t pos[3]; ++} MicroDVDContext; ++ ++ ++static int microdvd_probe(AVProbeData *p) ++{ ++ unsigned char c, *ptr = p->buf; ++ int i; ++ ++ if (AV_RB24(ptr) == 0xEFBBBF) ++ ptr += 3; /* skip UTF-8 BOM */ ++ ++ for (i=0; i<3; i++) { ++ if (sscanf(ptr, "{%*d}{}%c", &c) != 1 && ++ sscanf(ptr, "{%*d}{%*d}%c", &c) != 1 && ++ sscanf(ptr, "{DEFAULT}{}%c", &c) != 1) ++ return 0; ++ ptr += strcspn(ptr, "\n") + 1; ++ } ++ return AVPROBE_SCORE_MAX; ++} ++ ++static int microdvd_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ AVRational pts_info = (AVRational){ 2997, 125 }; /* default: 23.976 fps */ ++ MicroDVDContext *microdvd = s->priv_data; ++ AVStream *st = avformat_new_stream(s, NULL); ++ int i, frame; ++ double fps; ++ char c; ++ ++ if (!st) ++ return -1; ++ for (i=0; ilines); i++) { ++ microdvd->pos[i] = avio_tell(s->pb); ++ ff_get_line(s->pb, microdvd->lines[i], sizeof(microdvd->lines[i])); ++ if ((sscanf(microdvd->lines[i], "{%d}{}%6lf", &frame, &fps) == 2 || ++ sscanf(microdvd->lines[i], "{%d}{%*d}%6lf", &frame, &fps) == 2) ++ && frame <= 1 && fps > 3 && fps < 100) ++ pts_info = av_d2q(fps, 100000); ++ if (sscanf(microdvd->lines[i], "{DEFAULT}{}%c", &c) == 1) { ++ st->codec->extradata = av_strdup(microdvd->lines[i] + 11); ++ st->codec->extradata_size = strlen(st->codec->extradata); ++ i--; ++ } ++ } ++ avpriv_set_pts_info(st, 64, pts_info.den, pts_info.num); ++ st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; ++ st->codec->codec_id = CODEC_ID_MICRODVD; ++ return 0; ++} ++ ++static int64_t get_pts(const char *buf) ++{ ++ int frame; ++ char c; ++ ++ if (sscanf(buf, "{%d}{%c", &frame, &c) == 2) ++ return frame; ++ return AV_NOPTS_VALUE; ++} ++ ++static int microdvd_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ MicroDVDContext *microdvd = s->priv_data; ++ char buffer[MAX_LINESIZE]; ++ int64_t pos = avio_tell(s->pb); ++ int i, len = 0, res = AVERROR_EOF; ++ ++ for (i=0; ilines); i++) { ++ if (microdvd->lines[i][0]) { ++ strcpy(buffer, microdvd->lines[i]); ++ pos = microdvd->pos[i]; ++ len = strlen(buffer); ++ microdvd->lines[i][0] = 0; ++ break; ++ } ++ } ++ if (!len) ++ len = ff_get_line(s->pb, buffer, sizeof(buffer)); ++ ++ if (buffer[0] && !(res = av_new_packet(pkt, len))) { ++ memcpy(pkt->data, buffer, len); ++ pkt->flags |= AV_PKT_FLAG_KEY; ++ pkt->pos = pos; ++ pkt->pts = pkt->dts = get_pts(buffer); ++ } ++ return res; ++} ++ ++AVInputFormat ff_microdvd_demuxer = { ++ .name = "microdvd", ++ .long_name = NULL_IF_CONFIG_SMALL("MicroDVD subtitle format"), ++ .priv_data_size = sizeof(MicroDVDContext), ++ .read_probe = microdvd_probe, ++ .read_header = microdvd_read_header, ++ .read_packet = microdvd_read_packet, ++ .flags = AVFMT_GENERIC_INDEX, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/microdvdenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/microdvdenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/microdvdenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/microdvdenc.c 2012-05-14 14:08:55.021353809 +0200 +@@ -0,0 +1,51 @@ ++/* ++ * MicroDVD subtitle muxer ++ * Copyright (c) 2010 Aurelien Jacobs ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "rawenc.h" ++ ++static int microdvd_write_header(struct AVFormatContext *s) ++{ ++ AVCodecContext *avctx = s->streams[0]->codec; ++ ++ if (s->nb_streams != 1 || avctx->codec_id != CODEC_ID_MICRODVD) { ++ av_log(s, AV_LOG_ERROR, "Exactly one MicroDVD stream is needed.\n"); ++ return -1; ++ } ++ ++ if (avctx->extradata && avctx->extradata_size > 0) { ++ avio_write(s->pb, "{DEFAULT}{}", 11); ++ avio_write(s->pb, avctx->extradata, avctx->extradata_size); ++ avio_flush(s->pb); ++ } ++ return 0; ++} ++ ++AVOutputFormat ff_microdvd_muxer = { ++ .name = "microdvd", ++ .long_name = NULL_IF_CONFIG_SMALL("MicroDVD subtitle format"), ++ .mime_type = "text/x-microdvd", ++ .extensions = "sub", ++ .write_header = microdvd_write_header, ++ .write_packet = ff_raw_write_packet, ++ .flags = AVFMT_NOTIMESTAMPS, ++ .subtitle_codec = CODEC_ID_MICRODVD, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mkvtimestamp_v2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mkvtimestamp_v2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mkvtimestamp_v2.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mkvtimestamp_v2.c 2012-05-14 14:08:55.022353829 +0200 +@@ -0,0 +1,51 @@ ++/* ++ * extract pts as timecode v2, as defined by mkvtoolnix ++ * Copyright (c) 2009 David Conrad ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++ ++static int write_header(AVFormatContext *s) ++{ ++ static const char *header = "# timecode format v2\n"; ++ put_buffer(s->pb, header, strlen(header)); ++ avpriv_set_pts_info(s->streams[0], 64, 1, 1000); ++ return 0; ++} ++ ++static int write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ char buf[256]; ++ if (pkt->stream_index) ++ av_log(s, AV_LOG_WARNING, "More than one stream unsupported\n"); ++ snprintf(buf, sizeof(buf), "%" PRId64 "\n", pkt->dts); ++ put_buffer(s->pb, buf, strlen(buf)); ++ put_flush_packet(s->pb); ++ return 0; ++} ++ ++AVOutputFormat ff_mkvtimestamp_v2_muxer = { ++ .name = "mkvtimestamp_v2", ++ .long_name = NULL_IF_CONFIG_SMALL("extract pts as timecode v2 format, as defined by mkvtoolnix"), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = write_header, ++ .write_packet = write_packet, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mm.c 2012-05-14 14:08:55.023353849 +0200 +@@ -33,6 +33,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define MM_PREAMBLE_SIZE 6 + +@@ -84,28 +85,28 @@ + AVFormatParameters *ap) + { + MmDemuxContext *mm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + + unsigned int type, length; + unsigned int frame_rate, width, height; + +- type = get_le16(pb); +- length = get_le32(pb); ++ type = avio_rl16(pb); ++ length = avio_rl32(pb); + + if (type != MM_TYPE_HEADER) + return AVERROR_INVALIDDATA; + + /* read header */ +- get_le16(pb); /* total number of chunks */ +- frame_rate = get_le16(pb); +- get_le16(pb); /* ibm-pc video bios mode */ +- width = get_le16(pb); +- height = get_le16(pb); +- url_fseek(pb, length - 10, SEEK_CUR); /* unknown data */ ++ avio_rl16(pb); /* total number of chunks */ ++ frame_rate = avio_rl16(pb); ++ avio_rl16(pb); /* ibm-pc video bios mode */ ++ width = avio_rl16(pb); ++ height = avio_rl16(pb); ++ avio_skip(pb, length - 10); /* unknown data */ + + /* video stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -113,11 +114,11 @@ + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->width = width; + st->codec->height = height; +- av_set_pts_info(st, 64, 1, frame_rate); ++ avpriv_set_pts_info(st, 64, 1, frame_rate); + + /* audio stream */ + if (length == MM_HEADER_LEN_AV) { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -125,7 +126,7 @@ + st->codec->codec_id = CODEC_ID_PCM_U8; + st->codec->channels = 1; + st->codec->sample_rate = 8000; +- av_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ ++ avpriv_set_pts_info(st, 64, 1, 8000); /* 8000 hz */ + } + + mm->audio_pts = 0; +@@ -137,13 +138,13 @@ + AVPacket *pkt) + { + MmDemuxContext *mm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned char preamble[MM_PREAMBLE_SIZE]; + unsigned int type, length; + + while(1) { + +- if (get_buffer(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { ++ if (avio_read(pb, preamble, MM_PREAMBLE_SIZE) != MM_PREAMBLE_SIZE) { + return AVERROR(EIO); + } + +@@ -162,7 +163,7 @@ + if (av_new_packet(pkt, length + MM_PREAMBLE_SIZE)) + return AVERROR(ENOMEM); + memcpy(pkt->data, preamble, MM_PREAMBLE_SIZE); +- if (get_buffer(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) ++ if (avio_read(pb, pkt->data + MM_PREAMBLE_SIZE, length) != length) + return AVERROR(EIO); + pkt->size = length + MM_PREAMBLE_SIZE; + pkt->stream_index = 0; +@@ -181,18 +182,16 @@ + + default : + av_log(s, AV_LOG_INFO, "unknown chunk type 0x%x\n", type); +- url_fseek(pb, length, SEEK_CUR); ++ avio_skip(pb, length); + } + } +- +- return 0; + } + + AVInputFormat ff_mm_demuxer = { +- "mm", +- NULL_IF_CONFIG_SMALL("American Laser Games MM format"), +- sizeof(MmDemuxContext), +- probe, +- read_header, +- read_packet, ++ .name = "mm", ++ .long_name = NULL_IF_CONFIG_SMALL("American Laser Games MM format"), ++ .priv_data_size = sizeof(MmDemuxContext), ++ .read_probe = probe, ++ .read_header = read_header, ++ .read_packet = read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmf.c 2012-05-14 14:08:55.024353869 +0200 +@@ -19,6 +19,8 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "pcm.h" + #include "riff.h" + +@@ -47,20 +49,20 @@ + } + + /* Copy of end_tag() from avienc.c, but for big-endian chunk size */ +-static void end_tag_be(ByteIOContext *pb, int64_t start) ++static void end_tag_be(AVIOContext *pb, int64_t start) + { + int64_t pos; + +- pos = url_ftell(pb); +- url_fseek(pb, start - 4, SEEK_SET); +- put_be32(pb, (uint32_t)(pos - start)); +- url_fseek(pb, pos, SEEK_SET); ++ pos = avio_tell(pb); ++ avio_seek(pb, start - 4, SEEK_SET); ++ avio_wb32(pb, (uint32_t)(pos - start)); ++ avio_seek(pb, pos, SEEK_SET); + } + + static int mmf_write_header(AVFormatContext *s) + { + MMFContext *mmf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; + int rate; + +@@ -70,96 +72,96 @@ + return -1; + } + +- put_tag(pb, "MMMD"); +- put_be32(pb, 0); ++ ffio_wfourcc(pb, "MMMD"); ++ avio_wb32(pb, 0); + pos = ff_start_tag(pb, "CNTI"); +- put_byte(pb, 0); /* class */ +- put_byte(pb, 0); /* type */ +- put_byte(pb, 0); /* code type */ +- put_byte(pb, 0); /* status */ +- put_byte(pb, 0); /* counts */ +- put_tag(pb, "VN:libavcodec,"); /* metadata ("ST:songtitle,VN:version,...") */ ++ avio_w8(pb, 0); /* class */ ++ avio_w8(pb, 0); /* type */ ++ avio_w8(pb, 0); /* code type */ ++ avio_w8(pb, 0); /* status */ ++ avio_w8(pb, 0); /* counts */ ++ avio_write(pb, "VN:libavcodec,", sizeof("VN:libavcodec,") -1); /* metadata ("ST:songtitle,VN:version,...") */ + end_tag_be(pb, pos); + +- put_buffer(pb, "ATR\x00", 4); +- put_be32(pb, 0); +- mmf->atrpos = url_ftell(pb); +- put_byte(pb, 0); /* format type */ +- put_byte(pb, 0); /* sequence type */ +- put_byte(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */ +- put_byte(pb, 0); /* wave base bit */ +- put_byte(pb, 2); /* time base d */ +- put_byte(pb, 2); /* time base g */ +- +- put_tag(pb, "Atsq"); +- put_be32(pb, 16); +- mmf->atsqpos = url_ftell(pb); ++ avio_write(pb, "ATR\x00", 4); ++ avio_wb32(pb, 0); ++ mmf->atrpos = avio_tell(pb); ++ avio_w8(pb, 0); /* format type */ ++ avio_w8(pb, 0); /* sequence type */ ++ avio_w8(pb, (0 << 7) | (1 << 4) | rate); /* (channel << 7) | (format << 4) | rate */ ++ avio_w8(pb, 0); /* wave base bit */ ++ avio_w8(pb, 2); /* time base d */ ++ avio_w8(pb, 2); /* time base g */ ++ ++ ffio_wfourcc(pb, "Atsq"); ++ avio_wb32(pb, 16); ++ mmf->atsqpos = avio_tell(pb); + /* Will be filled on close */ +- put_buffer(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); ++ avio_write(pb, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 16); + + mmf->awapos = ff_start_tag(pb, "Awa\x01"); + +- av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); ++ avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int mmf_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; +- put_buffer(pb, pkt->data, pkt->size); ++ AVIOContext *pb = s->pb; ++ avio_write(pb, pkt->data, pkt->size); + return 0; + } + + /* Write a variable-length symbol */ +-static void put_varlength(ByteIOContext *pb, int val) ++static void put_varlength(AVIOContext *pb, int val) + { + if(val < 128) +- put_byte(pb, val); ++ avio_w8(pb, val); + else { + val -= 128; +- put_byte(pb, 0x80 | val >> 7); +- put_byte(pb, 0x7f & val); ++ avio_w8(pb, 0x80 | val >> 7); ++ avio_w8(pb, 0x7f & val); + } + } + + static int mmf_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + MMFContext *mmf = s->priv_data; + int64_t pos, size; + int gatetime; + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + /* Fill in length fields */ + end_tag_be(pb, mmf->awapos); + end_tag_be(pb, mmf->atrpos); + end_tag_be(pb, 8); + +- pos = url_ftell(pb); ++ pos = avio_tell(pb); + size = pos - mmf->awapos; + + /* Fill Atsq chunk */ +- url_fseek(pb, mmf->atsqpos, SEEK_SET); ++ avio_seek(pb, mmf->atsqpos, SEEK_SET); + + /* "play wav" */ +- put_byte(pb, 0); /* start time */ +- put_byte(pb, 1); /* (channel << 6) | wavenum */ ++ avio_w8(pb, 0); /* start time */ ++ avio_w8(pb, 1); /* (channel << 6) | wavenum */ + gatetime = size * 500 / s->streams[0]->codec->sample_rate; + put_varlength(pb, gatetime); /* duration */ + + /* "nop" */ + put_varlength(pb, gatetime); /* start time */ +- put_buffer(pb, "\xff\x00", 2); /* nop */ ++ avio_write(pb, "\xff\x00", 2); /* nop */ + + /* "end of sequence" */ +- put_buffer(pb, "\x00\x00\x00\x00", 4); ++ avio_write(pb, "\x00\x00\x00\x00", 4); + +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + } + return 0; + } +@@ -183,20 +185,20 @@ + { + MMFContext *mmf = s->priv_data; + unsigned int tag; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; +- int64_t file_size, size; ++ int64_t size; + int rate, params; + +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('M', 'M', 'M', 'D')) + return -1; +- file_size = get_be32(pb); ++ avio_skip(pb, 4); /* file_size */ + + /* Skip some unused chunks that may or may not be present */ +- for(;; url_fseek(pb, size, SEEK_CUR)) { +- tag = get_le32(pb); +- size = get_be32(pb); ++ for(;; avio_skip(pb, size)) { ++ tag = avio_rl32(pb); ++ size = avio_rb32(pb); + if(tag == MKTAG('C','N','T','I')) continue; + if(tag == MKTAG('O','P','D','A')) continue; + break; +@@ -212,22 +214,22 @@ + return -1; + } + +- get_byte(pb); /* format type */ +- get_byte(pb); /* sequence type */ +- params = get_byte(pb); /* (channel << 7) | (format << 4) | rate */ ++ avio_r8(pb); /* format type */ ++ avio_r8(pb); /* sequence type */ ++ params = avio_r8(pb); /* (channel << 7) | (format << 4) | rate */ + rate = mmf_rate(params & 0x0f); + if(rate < 0) { + av_log(s, AV_LOG_ERROR, "Invalid sample rate\n"); + return -1; + } +- get_byte(pb); /* wave base bit */ +- get_byte(pb); /* time base d */ +- get_byte(pb); /* time base g */ ++ avio_r8(pb); /* wave base bit */ ++ avio_r8(pb); /* time base d */ ++ avio_r8(pb); /* time base g */ + + /* Skip some unused chunks that may or may not be present */ +- for(;; url_fseek(pb, size, SEEK_CUR)) { +- tag = get_le32(pb); +- size = get_be32(pb); ++ for(;; avio_skip(pb, size)) { ++ tag = avio_rl32(pb); ++ size = avio_rb32(pb); + if(tag == MKTAG('A','t','s','q')) continue; + if(tag == MKTAG('A','s','p','I')) continue; + break; +@@ -240,7 +242,7 @@ + } + mmf->data_size = size; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -251,7 +253,7 @@ + st->codec->bits_per_coded_sample = 4; + st->codec->bit_rate = st->codec->sample_rate * st->codec->bits_per_coded_sample; + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; + } +@@ -262,12 +264,10 @@ + AVPacket *pkt) + { + MMFContext *mmf = s->priv_data; +- AVStream *st; + int ret, size; + + if (url_feof(s->pb)) + return AVERROR(EIO); +- st = s->streams[0]; + + size = MAX_SIZE; + if(size > mmf->data_size) +@@ -280,7 +280,7 @@ + return AVERROR(EIO); + pkt->stream_index = 0; + +- ret = get_buffer(s->pb, pkt->data, pkt->size); ++ ret = avio_read(s->pb, pkt->data, pkt->size); + if (ret < 0) + av_free_packet(pkt); + +@@ -292,27 +292,26 @@ + + #if CONFIG_MMF_DEMUXER + AVInputFormat ff_mmf_demuxer = { +- "mmf", +- NULL_IF_CONFIG_SMALL("Yamaha SMAF"), +- sizeof(MMFContext), +- mmf_probe, +- mmf_read_header, +- mmf_read_packet, +- NULL, +- pcm_read_seek, ++ .name = "mmf", ++ .long_name = NULL_IF_CONFIG_SMALL("Yamaha SMAF"), ++ .priv_data_size = sizeof(MMFContext), ++ .read_probe = mmf_probe, ++ .read_header = mmf_read_header, ++ .read_packet = mmf_read_packet, ++ .read_seek = pcm_read_seek, + }; + #endif + #if CONFIG_MMF_MUXER + AVOutputFormat ff_mmf_muxer = { +- "mmf", +- NULL_IF_CONFIG_SMALL("Yamaha SMAF"), +- "application/vnd.smaf", +- "mmf", +- sizeof(MMFContext), +- CODEC_ID_ADPCM_YAMAHA, +- CODEC_ID_NONE, +- mmf_write_header, +- mmf_write_packet, +- mmf_write_trailer, ++ .name = "mmf", ++ .long_name = NULL_IF_CONFIG_SMALL("Yamaha SMAF"), ++ .mime_type = "application/vnd.smaf", ++ .extensions = "mmf", ++ .priv_data_size = sizeof(MMFContext), ++ .audio_codec = CODEC_ID_ADPCM_YAMAHA, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = mmf_write_header, ++ .write_packet = mmf_write_packet, ++ .write_trailer = mmf_write_trailer, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mms.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mms.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mms.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mms.c 2012-05-14 14:08:55.025353889 +0200 +@@ -24,11 +24,7 @@ + #include "asf.h" + #include "libavutil/intreadwrite.h" + +-#if FF_API_MAX_STREAMS +-#define MMS_MAX_STREAMS MAX_STREAMS +-#else + #define MMS_MAX_STREAMS 256 /**< arbitrary sanity check value */ +-#endif + + int ff_mms_read_header(MMSContext *mms, uint8_t *buf, const int size) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mms.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mms.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mms.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mms.h 2012-05-14 14:08:55.025353889 +0200 +@@ -21,7 +21,7 @@ + #ifndef AVFORMAT_MMS_H + #define AVFORMAT_MMS_H + +-#include "avformat.h" ++#include "url.h" + + typedef struct { + int id; +@@ -33,7 +33,7 @@ + + /** Buffer for outgoing packets. */ + /*@{*/ +- uint8_t *write_out_ptr; ///< Pointer for writting the buffer. ++ uint8_t *write_out_ptr; ///< Pointer for writing the buffer. + uint8_t out_buffer[512]; ///< Buffer for outgoing packet. + /*@}*/ + +@@ -60,4 +60,5 @@ + int ff_mms_asf_header_parser(MMSContext * mms); + int ff_mms_read_data(MMSContext *mms, uint8_t *buf, const int size); + int ff_mms_read_header(MMSContext * mms, uint8_t * buf, const int size); +-#endif ++ ++#endif /* AVFORMAT_MMS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmsh.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmsh.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmsh.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmsh.c 2012-05-14 14:08:55.026353909 +0200 +@@ -28,10 +28,12 @@ + #include + #include "libavutil/intreadwrite.h" + #include "libavutil/avstring.h" +-#include "libavformat/internal.h" ++#include "libavutil/opt.h" ++#include "internal.h" + #include "mms.h" + #include "asf.h" + #include "http.h" ++#include "url.h" + + #define CHUNK_HEADER_LENGTH 4 // 2bytes chunk type and 2bytes chunk length. + #define EXT_HEADER_LENGTH 8 // 4bytes sequence, 2bytes useless and 2bytes chunk length. +@@ -64,10 +66,9 @@ + MMSHContext *mmsh = (MMSHContext *)h->priv_data; + MMSContext *mms = &mmsh->mms; + if (mms->mms_hd) +- url_close(mms->mms_hd); ++ ffurl_close(mms->mms_hd); + av_free(mms->streams); + av_free(mms->asf_header); +- av_freep(&h->priv_data); + return 0; + } + +@@ -79,7 +80,7 @@ + ChunkType chunk_type; + int chunk_len, res, ext_header_len; + +- res = url_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); ++ res = ffurl_read_complete(mms->mms_hd, chunk_header, CHUNK_HEADER_LENGTH); + if (res != CHUNK_HEADER_LENGTH) { + av_log(NULL, AV_LOG_ERROR, "Read data packet header failed!\n"); + return AVERROR(EIO); +@@ -101,7 +102,7 @@ + return AVERROR_INVALIDDATA; + } + +- res = url_read_complete(mms->mms_hd, ext_header, ext_header_len); ++ res = ffurl_read_complete(mms->mms_hd, ext_header, ext_header_len); + if (res != ext_header_len) { + av_log(NULL, AV_LOG_ERROR, "Read ext header failed!\n"); + return AVERROR(EIO); +@@ -122,7 +123,7 @@ + len, sizeof(mms->in_buffer)); + return AVERROR(EIO); + } +- res = url_read_complete(mms->mms_hd, mms->in_buffer, len); ++ res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len); + av_dlog(NULL, "Data packet len = %d\n", len); + if (res != len) { + av_log(NULL, AV_LOG_ERROR, "Read data packet failed!\n"); +@@ -174,7 +175,7 @@ + len, mms->asf_header_size); + return AVERROR(EIO); + } +- res = url_read_complete(mms->mms_hd, mms->asf_header, len); ++ res = ffurl_read_complete(mms->mms_hd, mms->asf_header, len); + if (res != len) { + av_log(NULL, AV_LOG_ERROR, + "Recv asf header data len %d != expected len %d\n", res, len); +@@ -197,7 +198,7 @@ + len, sizeof(mms->in_buffer)); + return AVERROR(EIO); + } +- res = url_read_complete(mms->mms_hd, mms->in_buffer, len); ++ res = ffurl_read_complete(mms->mms_hd, mms->in_buffer, len); + if (res != len) { + av_log(NULL, AV_LOG_ERROR, "Read other chunk type data failed!\n"); + return AVERROR(EIO); +@@ -208,7 +209,6 @@ + } + } + } +- return 0; + } + + static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int timestamp, int64_t pos) +@@ -217,12 +217,9 @@ + char httpname[256], path[256], host[128]; + char *stream_selection = NULL; + char headers[1024]; +- MMSHContext *mmsh; ++ MMSHContext *mmsh = h->priv_data; + MMSContext *mms; + +- mmsh = h->priv_data = av_mallocz(sizeof(MMSHContext)); +- if (!h->priv_data) +- return AVERROR(ENOMEM); + mmsh->request_seq = h->is_streamed = 1; + mms = &mmsh->mms; + av_strlcpy(mmsh->location, uri, sizeof(mmsh->location)); +@@ -231,9 +228,10 @@ + host, sizeof(host), &port, path, sizeof(path), mmsh->location); + if (port<0) + port = 80; // default mmsh protocol port +- ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path); ++ ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, "%s", path); + +- if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { ++ if (ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ, ++ &h->interrupt_callback) < 0) { + return AVERROR(EIO); + } + +@@ -244,11 +242,11 @@ + "Pragma: no-cache,rate=1.000000,stream-time=0," + "stream-offset=0:0,request-context=%u,max-duration=0\r\n" + CLIENTGUID +- "Connection: Close\r\n\r\n", ++ "Connection: Close\r\n", + host, port, mmsh->request_seq++); +- ff_http_set_headers(mms->mms_hd, headers); ++ av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0); + +- err = url_connect(mms->mms_hd); ++ err = ffurl_connect(mms->mms_hd, NULL); + if (err) { + goto fail; + } +@@ -259,10 +257,11 @@ + } + + // close the socket and then reopen it for sending the second play request. +- url_close(mms->mms_hd); ++ ffurl_close(mms->mms_hd); + memset(headers, 0, sizeof(headers)); +- if (url_alloc(&mms->mms_hd, httpname, URL_RDONLY) < 0) { +- return AVERROR(EIO); ++ if ((err = ffurl_alloc(&mms->mms_hd, httpname, AVIO_FLAG_READ, ++ &h->interrupt_callback)) < 0) { ++ goto fail; + } + stream_selection = av_mallocz(mms->stream_num * 19 + 1); + if (!stream_selection) +@@ -285,7 +284,7 @@ + "Pragma: stream-switch-count=%d\r\n" + "Pragma: stream-switch-entry=%s\r\n" + "Pragma: no-cache,rate=1.000000,stream-time=%u" +- "Connection: Close\r\n\r\n", ++ "Connection: Close\r\n", + host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp); + av_freep(&stream_selection); + if (err < 0) { +@@ -293,9 +292,9 @@ + goto fail; + } + av_dlog(NULL, "out_buffer is %s", headers); +- ff_http_set_headers(mms->mms_hd, headers); ++ av_opt_set(mms->mms_hd->priv_data, "headers", headers, 0); + +- err = url_connect(mms->mms_hd); ++ err = ffurl_connect(mms->mms_hd, NULL); + if (err) { + goto fail; + } +@@ -377,7 +376,7 @@ + + if(ret>=0){ + if (mms->mms_hd) +- url_close(mms->mms_hd); ++ ffurl_close(mms->mms_hd); + av_freep(&mms->streams); + av_freep(&mms->asf_header); + av_free(mmsh); +@@ -400,11 +399,12 @@ + } + + URLProtocol ff_mmsh_protocol = { +- .name = "mmsh", +- .url_open = mmsh_open, +- .url_read = mmsh_read, +- .url_write = NULL, +- .url_seek = mmsh_seek, +- .url_close = mmsh_close, ++ .name = "mmsh", ++ .url_open = mmsh_open, ++ .url_read = mmsh_read, ++ .url_seek = mmsh_seek, ++ .url_close = mmsh_close, + .url_read_seek = mmsh_read_seek, ++ .priv_data_size = sizeof(MMSHContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmst.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmst.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mmst.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mmst.c 2012-05-14 14:08:55.028353949 +0200 +@@ -31,9 +31,11 @@ + #include "avformat.h" + #include "mms.h" + #include "internal.h" ++#include "avio_internal.h" + #include "libavutil/intreadwrite.h" + #include "libavcodec/bytestream.h" + #include "network.h" ++#include "url.h" + + #define LOCAL_ADDRESS 0xc0a80081 // FIXME get and use correct local ip address. + #define LOCAL_PORT 1037 // as above. +@@ -137,25 +139,25 @@ + memset(mms->write_out_ptr, 0, exact_length - len); + + // write it out. +- write_result= url_write(mms->mms_hd, mms->out_buffer, exact_length); ++ write_result= ffurl_write(mms->mms_hd, mms->out_buffer, exact_length); + if(write_result != exact_length) { + av_log(NULL, AV_LOG_ERROR, + "Failed to write data of length %d: %d (%s)\n", + exact_length, write_result, + write_result < 0 ? strerror(write_result) : + "The server closed the connection"); +- return AVERROR_IO; ++ return AVERROR(EIO); + } + + return 0; + } + +-static void mms_put_utf16(MMSContext *mms, uint8_t *src) ++static void mms_put_utf16(MMSContext *mms, const uint8_t *src) + { +- ByteIOContext bic; ++ AVIOContext bic; + int size = mms->write_out_ptr - mms->out_buffer; + int len; +- init_put_byte(&bic, mms->write_out_ptr, ++ ffio_init_context(&bic, mms->write_out_ptr, + sizeof(mms->out_buffer) - size, 1, NULL, NULL, NULL, NULL); + + len = avio_put_str16le(&bic, src); +@@ -239,7 +241,7 @@ + MMSSCPacketType packet_type= -1; + MMSContext *mms = &mmst->mms; + for(;;) { +- read_result = url_read_complete(mms->mms_hd, mms->in_buffer, 8); ++ read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer, 8); + if (read_result != 8) { + if(read_result < 0) { + av_log(NULL, AV_LOG_ERROR, +@@ -259,14 +261,14 @@ + int length_remaining, hr; + + mmst->incoming_flags= mms->in_buffer[3]; +- read_result= url_read_complete(mms->mms_hd, mms->in_buffer+8, 4); ++ read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer+8, 4); + if(read_result != 4) { + av_log(NULL, AV_LOG_ERROR, + "Reading command packet length failed: %d (%s)\n", + read_result, + read_result < 0 ? strerror(read_result) : + "The server closed the connection"); +- return read_result < 0 ? read_result : AVERROR_IO; ++ return read_result < 0 ? read_result : AVERROR(EIO); + } + + length_remaining= AV_RL32(mms->in_buffer+8) + 4; +@@ -279,7 +281,7 @@ + length_remaining, sizeof(mms->in_buffer) - 12); + return AVERROR_INVALIDDATA; + } +- read_result = url_read_complete(mms->mms_hd, mms->in_buffer + 12, ++ read_result = ffurl_read_complete(mms->mms_hd, mms->in_buffer + 12, + length_remaining) ; + if (read_result != length_remaining) { + av_log(NULL, AV_LOG_ERROR, +@@ -287,13 +289,13 @@ + length_remaining, read_result, + read_result < 0 ? strerror(read_result) : + "The server closed the connection"); +- return read_result < 0 ? read_result : AVERROR_IO; ++ return read_result < 0 ? read_result : AVERROR(EIO); + } + packet_type= AV_RL16(mms->in_buffer+36); + if (read_result >= 44 && (hr = AV_RL32(mms->in_buffer + 40))) { + av_log(NULL, AV_LOG_ERROR, +- "Server sent an error status code: 0x%08x\n", hr); +- return AVERROR_UNKNOWN; ++ "Server sent a message with packet type 0x%x and error status code 0x%08x\n", packet_type, hr); ++ return AVERROR(EINVAL); + } + } else { + int length_remaining; +@@ -317,14 +319,14 @@ + } + mms->remaining_in_len = length_remaining; + mms->read_in_ptr = mms->in_buffer; +- read_result= url_read_complete(mms->mms_hd, mms->in_buffer, length_remaining); ++ read_result= ffurl_read_complete(mms->mms_hd, mms->in_buffer, length_remaining); + if(read_result != length_remaining) { + av_log(NULL, AV_LOG_ERROR, + "Failed to read packet data of size %d: %d (%s)\n", + length_remaining, read_result, + read_result < 0 ? strerror(read_result) : + "The server closed the connection"); +- return read_result < 0 ? read_result : AVERROR_IO; ++ return read_result < 0 ? read_result : AVERROR(EIO); + } + + // if we successfully read everything. +@@ -462,13 +464,12 @@ + MMSContext *mms = &mmst->mms; + if(mms->mms_hd) { + send_close_packet(mmst); +- url_close(mms->mms_hd); ++ ffurl_close(mms->mms_hd); + } + + /* free all separately allocated pointers in mms */ + av_free(mms->streams); + av_free(mms->asf_header); +- av_freep(&h->priv_data); + + return 0; + } +@@ -500,15 +501,12 @@ + + static int mms_open(URLContext *h, const char *uri, int flags) + { +- MMSTContext *mmst; ++ MMSTContext *mmst = h->priv_data; + MMSContext *mms; + int port, err; + char tcpname[256]; + + h->is_streamed = 1; +- mmst = h->priv_data = av_mallocz(sizeof(MMSTContext)); +- if (!h->priv_data) +- return AVERROR(ENOMEM); + mms = &mmst->mms; + + // only for MMS over TCP, so set proto = NULL +@@ -521,7 +519,8 @@ + + // establish tcp connection. + ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, mmst->host, port, NULL); +- err = url_open(&mms->mms_hd, tcpname, URL_RDWR); ++ err = ffurl_open(&mms->mms_hd, tcpname, AVIO_FLAG_READ_WRITE, ++ &h->interrupt_callback, NULL); + if (err) + goto fail; + +@@ -548,7 +547,7 @@ + if((mmst->incoming_flags != 0X08) && (mmst->incoming_flags != 0X0C)) { + av_log(NULL, AV_LOG_ERROR, + "The server does not support MMST (try MMSH or RTSP)\n"); +- err = AVERROR_NOFMT; ++ err = AVERROR(EINVAL); + goto fail; + } + err = ff_mms_asf_header_parser(mms); +@@ -602,12 +601,12 @@ + av_log(NULL, AV_LOG_ERROR, + "Incoming pktlen %d is larger than ASF pktsize %d\n", + mms->remaining_in_len, mms->asf_packet_len); +- result= AVERROR_IO; ++ result= AVERROR(EIO); + } else { + // copy the data to the packet buffer. + result = ff_mms_read_data(mms, buf, size); + if (result == 0) { +- av_dlog(NULL, "read asf media paket size is zero!\n"); ++ av_dlog(NULL, "Read ASF media packet size is zero!\n"); + break; + } + } +@@ -621,10 +620,10 @@ + } + + URLProtocol ff_mmst_protocol = { +- "mmst", +- mms_open, +- mms_read, +- NULL, // write +- NULL, // seek +- mms_close, ++ .name = "mmst", ++ .url_open = mms_open, ++ .url_read = mms_read, ++ .url_close = mms_close, ++ .priv_data_size = sizeof(MMSTContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov.c 2012-05-14 14:08:55.037354131 +0200 +@@ -23,15 +23,25 @@ + #include + + //#define DEBUG +-//#define DEBUG_METADATA + //#define MOV_EXPORT_ALL_METADATA + ++#include "libavutil/audioconvert.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/mathematics.h" + #include "libavutil/avstring.h" ++#include "libavutil/dict.h" ++#include "libavutil/opt.h" ++#include "libavcodec/ac3tab.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "riff.h" + #include "isom.h" + #include "libavcodec/get_bits.h" ++#include "libavcodec/timecode.h" ++#include "id3v1.h" ++#include "mov_chan.h" + + #if CONFIG_ZLIB + #include +@@ -40,21 +50,6 @@ + /* + * First version by Francois Revol revol@free.fr + * Seek function by Gael Chardon gael.dev@4now.net +- * +- * Features and limitations: +- * - reads most of the QT files I have (at least the structure), +- * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html +- * - the code is quite ugly... maybe I won't do it recursive next time :-) +- * +- * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/ +- * when coding this :) (it's a writer anyway) +- * +- * Reference documents: +- * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt +- * Apple: +- * http://developer.apple.com/documentation/QuickTime/QTFF/ +- * http://developer.apple.com/documentation/QuickTime/QTFF/qtff.pdf +- * QuickTime is a trademark of Apple (AFAIK :)) + */ + + #include "qtpalette.h" +@@ -63,30 +58,74 @@ + #undef NDEBUG + #include + +-/* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ +- + /* those functions parse an atom */ +-/* return code: +- 0: continue to parse next atom +- <0: error occurred, exit +-*/ + /* links atom IDs to parse functions */ + typedef struct MOVParseTableEntry { + uint32_t type; +- int (*parse)(MOVContext *ctx, ByteIOContext *pb, MOVAtom atom); ++ int (*parse)(MOVContext *ctx, AVIOContext *pb, MOVAtom atom); + } MOVParseTableEntry; + + static const MOVParseTableEntry mov_default_parse_table[]; + +-static int mov_metadata_trkn(MOVContext *c, ByteIOContext *pb, unsigned len) ++static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb, ++ unsigned len, const char *key) ++{ ++ char buf[16]; ++ ++ short current, total = 0; ++ avio_rb16(pb); // unknown ++ current = avio_rb16(pb); ++ if (len >= 6) ++ total = avio_rb16(pb); ++ if (!total) ++ snprintf(buf, sizeof(buf), "%d", current); ++ else ++ snprintf(buf, sizeof(buf), "%d/%d", current, total); ++ av_dict_set(&c->fc->metadata, key, buf, 0); ++ ++ return 0; ++} ++ ++static int mov_metadata_int8_bypass_padding(MOVContext *c, AVIOContext *pb, ++ unsigned len, const char *key) + { + char buf[16]; + +- get_be16(pb); // unknown +- snprintf(buf, sizeof(buf), "%d", get_be16(pb)); +- av_metadata_set2(&c->fc->metadata, "track", buf, 0); ++ /* bypass padding bytes */ ++ avio_r8(pb); ++ avio_r8(pb); ++ avio_r8(pb); + +- get_be16(pb); // total tracks ++ snprintf(buf, sizeof(buf), "%d", avio_r8(pb)); ++ av_dict_set(&c->fc->metadata, key, buf, 0); ++ ++ return 0; ++} ++ ++static int mov_metadata_int8_no_padding(MOVContext *c, AVIOContext *pb, ++ unsigned len, const char *key) ++{ ++ char buf[16]; ++ ++ snprintf(buf, sizeof(buf), "%d", avio_r8(pb)); ++ av_dict_set(&c->fc->metadata, key, buf, 0); ++ ++ return 0; ++} ++ ++static int mov_metadata_gnre(MOVContext *c, AVIOContext *pb, ++ unsigned len, const char *key) ++{ ++ short genre; ++ char buf[20]; ++ ++ avio_r8(pb); // unknown ++ ++ genre = avio_r8(pb); ++ if (genre < 1 || genre > ID3v1_GENRE_MAX) ++ return 0; ++ snprintf(buf, sizeof(buf), "%s", ff_id3v1_genre_str[genre-1]); ++ av_dict_set(&c->fc->metadata, key, buf, 0); + + return 0; + } +@@ -110,7 +149,7 @@ + 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7, + }; + +-static int mov_read_mac_string(MOVContext *c, ByteIOContext *pb, int len, ++static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len, + char *dst, int dstlen) + { + char *p = dst; +@@ -118,7 +157,7 @@ + int i; + + for (i = 0; i < len; i++) { +- uint8_t t, c = get_byte(pb); ++ uint8_t t, c = avio_r8(pb); + if (c < 0x80 && p < end) + *p++ = c; + else +@@ -128,7 +167,7 @@ + return p - dst; + } + +-static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + #ifdef MOV_EXPORT_ALL_METADATA + char tmp_key[5]; +@@ -137,20 +176,25 @@ + const char *key = NULL; + uint16_t str_size, langcode = 0; + uint32_t data_type = 0; +- int (*parse)(MOVContext*, ByteIOContext*, unsigned) = NULL; ++ int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL; + + switch (atom.type) { + case MKTAG(0xa9,'n','a','m'): key = "title"; break; + case MKTAG(0xa9,'a','u','t'): + case MKTAG(0xa9,'A','R','T'): key = "artist"; break; ++ case MKTAG( 'a','A','R','T'): key = "album_artist"; break; + case MKTAG(0xa9,'w','r','t'): key = "composer"; break; + case MKTAG( 'c','p','r','t'): + case MKTAG(0xa9,'c','p','y'): key = "copyright"; break; ++ case MKTAG(0xa9,'g','r','p'): key = "grouping"; break; ++ case MKTAG(0xa9,'l','y','r'): key = "lyrics"; break; + case MKTAG(0xa9,'c','m','t'): + case MKTAG(0xa9,'i','n','f'): key = "comment"; break; + case MKTAG(0xa9,'a','l','b'): key = "album"; break; + case MKTAG(0xa9,'d','a','y'): key = "date"; break; + case MKTAG(0xa9,'g','e','n'): key = "genre"; break; ++ case MKTAG( 'g','n','r','e'): key = "genre"; ++ parse = mov_metadata_gnre; break; + case MKTAG(0xa9,'t','o','o'): + case MKTAG(0xa9,'s','w','r'): key = "encoder"; break; + case MKTAG(0xa9,'e','n','c'): key = "encoder"; break; +@@ -160,21 +204,33 @@ + case MKTAG( 't','v','e','n'): key = "episode_id";break; + case MKTAG( 't','v','n','n'): key = "network"; break; + case MKTAG( 't','r','k','n'): key = "track"; +- parse = mov_metadata_trkn; break; ++ parse = mov_metadata_track_or_disc_number; break; ++ case MKTAG( 'd','i','s','k'): key = "disc"; ++ parse = mov_metadata_track_or_disc_number; break; ++ case MKTAG( 't','v','e','s'): key = "episode_sort"; ++ parse = mov_metadata_int8_bypass_padding; break; ++ case MKTAG( 't','v','s','n'): key = "season_number"; ++ parse = mov_metadata_int8_bypass_padding; break; ++ case MKTAG( 's','t','i','k'): key = "media_type"; ++ parse = mov_metadata_int8_no_padding; break; ++ case MKTAG( 'h','d','v','d'): key = "hd_video"; ++ parse = mov_metadata_int8_no_padding; break; ++ case MKTAG( 'p','g','a','p'): key = "gapless_playback"; ++ parse = mov_metadata_int8_no_padding; break; + } + + if (c->itunes_metadata && atom.size > 8) { +- int data_size = get_be32(pb); +- int tag = get_le32(pb); ++ int data_size = avio_rb32(pb); ++ int tag = avio_rl32(pb); + if (tag == MKTAG('d','a','t','a')) { +- data_type = get_be32(pb); // type +- get_be32(pb); // unknown ++ data_type = avio_rb32(pb); // type ++ avio_rb32(pb); // unknown + str_size = data_size - 16; + atom.size -= 16; + } else return 0; + } else if (atom.size > 4 && key && !c->itunes_metadata) { +- str_size = get_be16(pb); // string length +- langcode = get_be16(pb); ++ str_size = avio_rb16(pb); // string length ++ langcode = avio_rb16(pb); + ff_mov_lang_to_iso639(langcode, language); + atom.size -= 4; + } else +@@ -190,35 +246,33 @@ + if (!key) + return 0; + if (atom.size < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + + str_size = FFMIN3(sizeof(str)-1, str_size, atom.size); + + if (parse) +- parse(c, pb, str_size); ++ parse(c, pb, str_size, key); + else { + if (data_type == 3 || (data_type == 0 && langcode < 0x800)) { // MAC Encoded + mov_read_mac_string(c, pb, str_size, str, sizeof(str)); + } else { +- get_buffer(pb, str, str_size); ++ avio_read(pb, str, str_size); + str[str_size] = 0; + } +- av_metadata_set2(&c->fc->metadata, key, str, 0); ++ av_dict_set(&c->fc->metadata, key, str, 0); + if (*language && strcmp(language, "und")) { + snprintf(key2, sizeof(key2), "%s-%s", key, language); +- av_metadata_set2(&c->fc->metadata, key2, str, 0); ++ av_dict_set(&c->fc->metadata, key2, str, 0); + } + } +-#ifdef DEBUG_METADATA +- av_log(c->fc, AV_LOG_DEBUG, "lang \"%3s\" ", language); +- av_log(c->fc, AV_LOG_DEBUG, "tag \"%s\" value \"%s\" atom \"%.4s\" %d %lld\n", +- key, str, (char*)&atom.type, str_size, atom.size); +-#endif ++ av_dlog(c->fc, "lang \"%3s\" ", language); ++ av_dlog(c->fc, "tag \"%s\" value \"%s\" atom \"%.4s\" %d %"PRId64"\n", ++ key, str, (char*)&atom.type, str_size, atom.size); + + return 0; + } + +-static int mov_read_chpl(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_chpl(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int64_t start; + int i, nb_chapters, str_len, version; +@@ -227,30 +281,30 @@ + if ((atom.size -= 5) < 0) + return 0; + +- version = get_byte(pb); +- get_be24(pb); ++ version = avio_r8(pb); ++ avio_rb24(pb); + if (version) +- get_be32(pb); // ??? +- nb_chapters = get_byte(pb); ++ avio_rb32(pb); // ??? ++ nb_chapters = avio_r8(pb); + + for (i = 0; i < nb_chapters; i++) { + if (atom.size < 9) + return 0; + +- start = get_be64(pb); +- str_len = get_byte(pb); ++ start = avio_rb64(pb); ++ str_len = avio_r8(pb); + + if ((atom.size -= 9+str_len) < 0) + return 0; + +- get_buffer(pb, str, str_len); ++ avio_read(pb, str, str_len); + str[str_len] = 0; +- ff_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str); ++ avpriv_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str); + } + return 0; + } + +-static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int64_t total_size = 0; + MOVAtom a; +@@ -258,28 +312,26 @@ + + if (atom.size < 0) + atom.size = INT64_MAX; +- while (total_size + 8 < atom.size && !url_feof(pb)) { +- int (*parse)(MOVContext*, ByteIOContext*, MOVAtom) = NULL; ++ while (total_size + 8 <= atom.size && !url_feof(pb)) { ++ int (*parse)(MOVContext*, AVIOContext*, MOVAtom) = NULL; + a.size = atom.size; + a.type=0; +- if(atom.size >= 8) { +- a.size = get_be32(pb); +- a.type = get_le32(pb); ++ if (atom.size >= 8) { ++ a.size = avio_rb32(pb); ++ a.type = avio_rl32(pb); ++ total_size += 8; ++ if (a.size == 1) { /* 64 bit extended size */ ++ a.size = avio_rb64(pb) - 8; ++ total_size += 8; ++ } + } + av_dlog(c->fc, "type: %08x '%.4s' parent:'%.4s' sz: %"PRId64" %"PRId64" %"PRId64"\n", + a.type, (char*)&a.type, (char*)&atom.type, a.size, total_size, atom.size); +- total_size += 8; +- if (a.size == 1) { /* 64 bit extended size */ +- a.size = get_be64(pb) - 8; +- total_size += 8; +- } + if (a.size == 0) { +- a.size = atom.size - total_size; +- if (a.size <= 8) +- break; ++ a.size = atom.size - total_size + 8; + } + a.size -= 8; +- if(a.size < 0) ++ if (a.size < 0) + break; + a.size = FFMIN(a.size, atom.size - total_size); + +@@ -295,31 +347,31 @@ + parse = mov_read_udta_string; + + if (!parse) { /* skip leaf atoms data */ +- url_fskip(pb, a.size); ++ avio_skip(pb, a.size); + } else { +- int64_t start_pos = url_ftell(pb); ++ int64_t start_pos = avio_tell(pb); + int64_t left; + int err = parse(c, pb, a); + if (err < 0) + return err; + if (c->found_moov && c->found_mdat && +- (url_is_streamed(pb) || start_pos + a.size == url_fsize(pb))) ++ (!pb->seekable || start_pos + a.size == avio_size(pb))) + return 0; +- left = a.size - url_ftell(pb) + start_pos; ++ left = a.size - avio_tell(pb) + start_pos; + if (left > 0) /* skip garbage at atom end */ +- url_fskip(pb, left); ++ avio_skip(pb, left); + } + + total_size += a.size; + } + + if (total_size < atom.size && atom.size < 0x7ffff) +- url_fskip(pb, atom.size - total_size); ++ avio_skip(pb, atom.size - total_size); + + return 0; + } + +-static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -330,10 +382,10 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_be32(pb); // version + flags +- entries = get_be32(pb); ++ avio_rb32(pb); // version + flags ++ entries = avio_rb32(pb); + if (entries >= UINT_MAX / sizeof(*sc->drefs)) +- return -1; ++ return AVERROR_INVALIDDATA; + sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); + if (!sc->drefs) + return AVERROR(ENOMEM); +@@ -341,14 +393,14 @@ + + for (i = 0; i < sc->drefs_count; i++) { + MOVDref *dref = &sc->drefs[i]; +- uint32_t size = get_be32(pb); +- int64_t next = url_ftell(pb) + size - 4; ++ uint32_t size = avio_rb32(pb); ++ int64_t next = avio_tell(pb) + size - 4; + + if (size < 12) +- return -1; ++ return AVERROR_INVALIDDATA; + +- dref->type = get_le32(pb); +- get_be32(pb); // version + flags ++ dref->type = avio_rl32(pb); ++ avio_rb32(pb); // version + flags + av_dlog(c->fc, "type %.4s size %d\n", (char*)&dref->type, size); + + if (dref->type == MKTAG('a','l','i','s') && size > 150) { +@@ -356,35 +408,37 @@ + uint16_t volume_len, len; + int16_t type; + +- url_fskip(pb, 10); ++ avio_skip(pb, 10); + +- volume_len = get_byte(pb); ++ volume_len = avio_r8(pb); + volume_len = FFMIN(volume_len, 27); +- get_buffer(pb, dref->volume, 27); ++ avio_read(pb, dref->volume, 27); + dref->volume[volume_len] = 0; + av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len); + +- url_fskip(pb, 12); ++ avio_skip(pb, 12); + +- len = get_byte(pb); ++ len = avio_r8(pb); + len = FFMIN(len, 63); +- get_buffer(pb, dref->filename, 63); ++ avio_read(pb, dref->filename, 63); + dref->filename[len] = 0; + av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len); + +- url_fskip(pb, 16); ++ avio_skip(pb, 16); + + /* read next level up_from_alias/down_to_target */ +- dref->nlvl_from = get_be16(pb); +- dref->nlvl_to = get_be16(pb); ++ dref->nlvl_from = avio_rb16(pb); ++ dref->nlvl_to = avio_rb16(pb); + av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n", + dref->nlvl_from, dref->nlvl_to); + +- url_fskip(pb, 16); ++ avio_skip(pb, 16); + +- for (type = 0; type != -1 && url_ftell(pb) < next; ) { +- type = get_be16(pb); +- len = get_be16(pb); ++ for (type = 0; type != -1 && avio_tell(pb) < next; ) { ++ if(url_feof(pb)) ++ return AVERROR_EOF; ++ type = avio_rb16(pb); ++ len = avio_rb16(pb); + av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len); + if (len&1) + len += 1; +@@ -393,7 +447,7 @@ + dref->path = av_mallocz(len+1); + if (!dref->path) + return AVERROR(ENOMEM); +- get_buffer(pb, dref->path, len); ++ avio_read(pb, dref->path, len); + if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) { + len -= volume_len; + memmove(dref->path, dref->path+volume_len, len); +@@ -408,107 +462,191 @@ + dref->dir = av_malloc(len+1); + if (!dref->dir) + return AVERROR(ENOMEM); +- get_buffer(pb, dref->dir, len); ++ avio_read(pb, dref->dir, len); + dref->dir[len] = 0; + for (j = 0; j < len; j++) + if (dref->dir[j] == ':') + dref->dir[j] = '/'; + av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir); + } else +- url_fskip(pb, len); ++ avio_skip(pb, len); + } + } +- url_fseek(pb, next, SEEK_SET); ++ avio_seek(pb, next, SEEK_SET); + } + return 0; + } + +-static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + uint32_t type; +- uint32_t ctype; ++ uint32_t av_unused ctype; ++ int title_size; ++ char *title_str; + + if (c->fc->nb_streams < 1) // meta before first trak + return 0; + + st = c->fc->streams[c->fc->nb_streams-1]; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + + /* component type */ +- ctype = get_le32(pb); +- type = get_le32(pb); /* component subtype */ ++ ctype = avio_rl32(pb); ++ type = avio_rl32(pb); /* component subtype */ + + av_dlog(c->fc, "ctype= %.4s (0x%08x)\n", (char*)&ctype, ctype); + av_dlog(c->fc, "stype= %.4s\n", (char*)&type); + + if (type == MKTAG('v','i','d','e')) + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- else if(type == MKTAG('s','o','u','n')) ++ else if (type == MKTAG('s','o','u','n')) + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- else if(type == MKTAG('m','1','a',' ')) ++ else if (type == MKTAG('m','1','a',' ')) + st->codec->codec_id = CODEC_ID_MP2; +- else if(type == MKTAG('s','u','b','p')) ++ else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p'))) + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + +- get_be32(pb); /* component manufacture */ +- get_be32(pb); /* component flags */ +- get_be32(pb); /* component flags mask */ ++ avio_rb32(pb); /* component manufacture */ ++ avio_rb32(pb); /* component flags */ ++ avio_rb32(pb); /* component flags mask */ ++ ++ title_size = atom.size - 24; ++ if (title_size > 0) { ++ title_str = av_malloc(title_size + 1); /* Add null terminator */ ++ if (!title_str) ++ return AVERROR(ENOMEM); ++ avio_read(pb, title_str, title_size); ++ title_str[title_size] = 0; ++ av_dict_set(&st->metadata, "handler_name", title_str, 0); ++ av_freep(&title_str); ++ } + + return 0; + } + +-int ff_mov_read_esds(AVFormatContext *fc, ByteIOContext *pb, MOVAtom atom) ++int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; +- int tag, len; ++ int tag; + + if (fc->nb_streams < 1) + return 0; + st = fc->streams[fc->nb_streams-1]; + +- get_be32(pb); /* version + flags */ +- len = ff_mp4_read_descr(fc, pb, &tag); ++ avio_rb32(pb); /* version + flags */ ++ ff_mp4_read_descr(fc, pb, &tag); + if (tag == MP4ESDescrTag) { +- get_be16(pb); /* ID */ +- get_byte(pb); /* priority */ ++ ff_mp4_parse_es_descr(pb, NULL); + } else +- get_be16(pb); /* ID */ ++ avio_rb16(pb); /* ID */ + +- len = ff_mp4_read_descr(fc, pb, &tag); ++ ff_mp4_read_descr(fc, pb, &tag); + if (tag == MP4DecConfigDescrTag) + ff_mp4_read_dec_config_descr(fc, st, pb); + return 0; + } + +-static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_esds(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + return ff_mov_read_esds(c->fc, pb, atom); + } + +-static int mov_read_dac3(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; +- int ac3info, acmod, lfeon; ++ int ac3info, acmod, lfeon, bsmod; + + if (c->fc->nb_streams < 1) + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- ac3info = get_be24(pb); ++ ac3info = avio_rb24(pb); ++ bsmod = (ac3info >> 14) & 0x7; + acmod = (ac3info >> 11) & 0x7; + lfeon = (ac3info >> 10) & 0x1; + st->codec->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon; ++ st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod]; ++ if (lfeon) ++ st->codec->channel_layout |= AV_CH_LOW_FREQUENCY; ++ st->codec->audio_service_type = bsmod; ++ if (st->codec->channels > 1 && bsmod == 0x7) ++ st->codec->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE; + + return 0; + } + +-static int mov_read_pasp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { +- const int num = get_be32(pb); +- const int den = get_be32(pb); ++ AVStream *st; ++ uint8_t version; ++ uint32_t flags, layout_tag, bitmap, num_descr, label_mask; ++ int i; ++ ++ if (c->fc->nb_streams < 1) ++ return 0; ++ st = c->fc->streams[c->fc->nb_streams-1]; ++ ++ if (atom.size < 16) ++ return 0; ++ ++ version = avio_r8(pb); ++ flags = avio_rb24(pb); ++ ++ layout_tag = avio_rb32(pb); ++ bitmap = avio_rb32(pb); ++ num_descr = avio_rb32(pb); ++ ++ if (atom.size < 16ULL + num_descr * 20ULL) ++ return 0; ++ ++ av_dlog(c->fc, "chan: size=%" PRId64 " version=%u flags=%u layout=%u bitmap=%u num_descr=%u\n", ++ atom.size, version, flags, layout_tag, bitmap, num_descr); ++ ++ label_mask = 0; ++ for (i = 0; i < num_descr; i++) { ++ uint32_t label, cflags; ++ label = avio_rb32(pb); // mChannelLabel ++ cflags = avio_rb32(pb); // mChannelFlags ++ avio_rl32(pb); // mCoordinates[0] ++ avio_rl32(pb); // mCoordinates[1] ++ avio_rl32(pb); // mCoordinates[2] ++ if (layout_tag == 0) { ++ uint32_t mask_incr = ff_mov_get_channel_label(label); ++ if (mask_incr == 0) { ++ label_mask = 0; ++ break; ++ } ++ label_mask |= mask_incr; ++ } ++ } ++ if (layout_tag == 0) ++ st->codec->channel_layout = label_mask; ++ else ++ st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap); ++ ++ return 0; ++} ++ ++static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ AVStream *st; ++ ++ if (c->fc->nb_streams < 1) ++ return 0; ++ st = c->fc->streams[c->fc->nb_streams-1]; ++ ++ ff_get_wav_header(pb, st->codec, atom.size); ++ ++ return 0; ++} ++ ++static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ const int num = avio_rb32(pb); ++ const int den = avio_rb32(pb); + AVStream *st; + + if (c->fc->nb_streams < 1) +@@ -529,16 +667,16 @@ + } + + /* this atom contains actual media data */ +-static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_mdat(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { +- if(atom.size == 0) /* wrong one (MP4) */ ++ if (atom.size == 0) /* wrong one (MP4) */ + return 0; + c->found_mdat=1; + return 0; /* now go for moov */ + } + + /* read major brand, minor version and compatible brands and store them as metadata */ +-static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + uint32_t minor_ver; + int comp_brand_size; +@@ -546,48 +684,50 @@ + char* comp_brands_str; + uint8_t type[5] = {0}; + +- get_buffer(pb, type, 4); ++ avio_read(pb, type, 4); + if (strcmp(type, "qt ")) + c->isom = 1; + av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type); +- av_metadata_set2(&c->fc->metadata, "major_brand", type, 0); +- minor_ver = get_be32(pb); /* minor version */ ++ av_dict_set(&c->fc->metadata, "major_brand", type, 0); ++ minor_ver = avio_rb32(pb); /* minor version */ + snprintf(minor_ver_str, sizeof(minor_ver_str), "%d", minor_ver); +- av_metadata_set2(&c->fc->metadata, "minor_version", minor_ver_str, 0); ++ av_dict_set(&c->fc->metadata, "minor_version", minor_ver_str, 0); + + comp_brand_size = atom.size - 8; + if (comp_brand_size < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + comp_brands_str = av_malloc(comp_brand_size + 1); /* Add null terminator */ + if (!comp_brands_str) + return AVERROR(ENOMEM); +- get_buffer(pb, comp_brands_str, comp_brand_size); ++ avio_read(pb, comp_brands_str, comp_brand_size); + comp_brands_str[comp_brand_size] = 0; +- av_metadata_set2(&c->fc->metadata, "compatible_brands", comp_brands_str, 0); ++ av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, 0); + av_freep(&comp_brands_str); + + return 0; + } + + /* this atom should contain all header atoms */ +-static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { +- if (mov_read_default(c, pb, atom) < 0) +- return -1; ++ int ret; ++ ++ if ((ret = mov_read_default(c, pb, atom)) < 0) ++ return ret; + /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */ + /* so we don't parse the whole file if over a network */ + c->found_moov=1; + return 0; /* now go for mdat */ + } + +-static int mov_read_moof(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { +- c->fragment.moof_offset = url_ftell(pb) - 8; +- av_dlog(c->fc, "moof offset %llx\n", c->fragment.moof_offset); ++ c->fragment.moof_offset = avio_tell(pb) - 8; ++ av_dlog(c->fc, "moof offset %"PRIx64"\n", c->fragment.moof_offset); + return mov_read_default(c, pb, atom); + } + +-static void mov_metadata_creation_time(AVMetadata **metadata, time_t time) ++static void mov_metadata_creation_time(AVDictionary **metadata, time_t time) + { + char buffer[32]; + if (time) { +@@ -596,11 +736,11 @@ + ptm = gmtime(&time); + if (!ptm) return; + strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm); +- av_metadata_set2(metadata, "creation_time", buffer, 0); ++ av_dict_set(metadata, "creation_time", buffer, 0); + } + } + +-static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -614,70 +754,73 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- version = get_byte(pb); +- if (version > 1) +- return -1; /* unsupported */ +- +- get_be24(pb); /* flags */ ++ version = avio_r8(pb); ++ if (version > 1) { ++ av_log_ask_for_sample(c, "unsupported version %d\n", version); ++ return AVERROR_PATCHWELCOME; ++ } ++ avio_rb24(pb); /* flags */ + if (version == 1) { +- creation_time = get_be64(pb); +- get_be64(pb); ++ creation_time = avio_rb64(pb); ++ avio_rb64(pb); + } else { +- creation_time = get_be32(pb); +- get_be32(pb); /* modification time */ ++ creation_time = avio_rb32(pb); ++ avio_rb32(pb); /* modification time */ + } + mov_metadata_creation_time(&st->metadata, creation_time); + +- sc->time_scale = get_be32(pb); +- st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ ++ sc->time_scale = avio_rb32(pb); ++ st->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */ + +- lang = get_be16(pb); /* language */ ++ lang = avio_rb16(pb); /* language */ + if (ff_mov_lang_to_iso639(lang, language)) +- av_metadata_set2(&st->metadata, "language", language, 0); +- get_be16(pb); /* quality */ ++ av_dict_set(&st->metadata, "language", language, 0); ++ avio_rb16(pb); /* quality */ + + return 0; + } + +-static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + time_t creation_time; +- int version = get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ int version = avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + + if (version == 1) { +- creation_time = get_be64(pb); +- get_be64(pb); ++ creation_time = avio_rb64(pb); ++ avio_rb64(pb); + } else { +- creation_time = get_be32(pb); +- get_be32(pb); /* modification time */ ++ creation_time = avio_rb32(pb); ++ avio_rb32(pb); /* modification time */ + } + mov_metadata_creation_time(&c->fc->metadata, creation_time); +- c->time_scale = get_be32(pb); /* time scale */ ++ c->time_scale = avio_rb32(pb); /* time scale */ + + av_dlog(c->fc, "time scale = %i\n", c->time_scale); + +- c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ +- get_be32(pb); /* preferred scale */ +- +- get_be16(pb); /* preferred volume */ ++ c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb); /* duration */ ++ // set the AVCodecContext duration because the duration of individual tracks ++ // may be inaccurate ++ c->fc->duration = av_rescale(c->duration, AV_TIME_BASE, c->time_scale); ++ avio_rb32(pb); /* preferred scale */ + +- url_fskip(pb, 10); /* reserved */ ++ avio_rb16(pb); /* preferred volume */ + +- url_fskip(pb, 36); /* display matrix */ ++ avio_skip(pb, 10); /* reserved */ + +- get_be32(pb); /* preview time */ +- get_be32(pb); /* preview duration */ +- get_be32(pb); /* poster time */ +- get_be32(pb); /* selection time */ +- get_be32(pb); /* selection duration */ +- get_be32(pb); /* current time */ +- get_be32(pb); /* next track ID */ ++ avio_skip(pb, 36); /* display matrix */ + ++ avio_rb32(pb); /* preview time */ ++ avio_rb32(pb); /* preview duration */ ++ avio_rb32(pb); /* poster time */ ++ avio_rb32(pb); /* selection time */ ++ avio_rb32(pb); /* selection duration */ ++ avio_rb32(pb); /* current time */ ++ avio_rb32(pb); /* next track ID */ + return 0; + } + +-static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + +@@ -685,8 +828,8 @@ + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- if((uint64_t)atom.size > (1<<30)) +- return -1; ++ if ((uint64_t)atom.size > (1<<30)) ++ return AVERROR_INVALIDDATA; + + // currently SVQ3 decoder expect full STSD header - so let's fake it + // this should be fixed and just SMI header should be passed +@@ -696,12 +839,12 @@ + return AVERROR(ENOMEM); + st->codec->extradata_size = 0x5a + atom.size; + memcpy(st->codec->extradata, "SVQ3", 4); // fake +- get_buffer(pb, st->codec->extradata + 0x5a, atom.size); ++ avio_read(pb, st->codec->extradata + 0x5a, atom.size); + av_dlog(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a); + return 0; + } + +-static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + int little_endian; +@@ -710,7 +853,7 @@ + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- little_endian = get_be16(pb); ++ little_endian = avio_rb16(pb) & 0xFF; + av_dlog(c->fc, "enda %d\n", little_endian); + if (little_endian == 1) { + switch (st->codec->codec_id) { +@@ -733,8 +876,43 @@ + return 0; + } + ++static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ AVStream *st; ++ unsigned mov_field_order; ++ enum AVFieldOrder decoded_field_order = AV_FIELD_UNKNOWN; ++ ++ if (c->fc->nb_streams < 1) // will happen with jp2 files ++ return 0; ++ st = c->fc->streams[c->fc->nb_streams-1]; ++ if (atom.size < 2) ++ return AVERROR_INVALIDDATA; ++ mov_field_order = avio_rb16(pb); ++ if ((mov_field_order & 0xFF00) == 0x0100) ++ decoded_field_order = AV_FIELD_PROGRESSIVE; ++ else if ((mov_field_order & 0xFF00) == 0x0200) { ++ switch (mov_field_order & 0xFF) { ++ case 0x01: decoded_field_order = AV_FIELD_TT; ++ break; ++ case 0x06: decoded_field_order = AV_FIELD_BB; ++ break; ++ case 0x09: decoded_field_order = AV_FIELD_TB; ++ break; ++ case 0x0E: decoded_field_order = AV_FIELD_BT; ++ break; ++ } ++ } ++ if (decoded_field_order == AV_FIELD_UNKNOWN && mov_field_order) { ++ av_log(NULL, AV_LOG_ERROR, "Unknown MOV field order 0x%04x\n", mov_field_order); ++ } ++ st->codec->field_order = decoded_field_order; ++ ++ return 0; ++} ++ + /* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */ +-static int mov_read_extradata(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom, ++ enum CodecID codec_id) + { + AVStream *st; + uint64_t size; +@@ -743,22 +921,42 @@ + if (c->fc->nb_streams < 1) // will happen with jp2 files + return 0; + st= c->fc->streams[c->fc->nb_streams-1]; ++ ++ if (st->codec->codec_id != codec_id) ++ return 0; /* unexpected codec_id - don't mess with extradata */ ++ + size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE; +- if(size > INT_MAX || (uint64_t)atom.size > INT_MAX) +- return -1; ++ if (size > INT_MAX || (uint64_t)atom.size > INT_MAX) ++ return AVERROR_INVALIDDATA; + buf= av_realloc(st->codec->extradata, size); +- if(!buf) +- return -1; ++ if (!buf) ++ return AVERROR(ENOMEM); + st->codec->extradata= buf; + buf+= st->codec->extradata_size; + st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE; + AV_WB32( buf , atom.size + 8); + AV_WL32( buf + 4, atom.type); +- get_buffer(pb, buf + 8, atom.size); ++ avio_read(pb, buf + 8, atom.size); + return 0; + } + +-static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++/* wrapper functions for reading ALAC/AVS/MJPEG/MJPEG2000 extradata atoms only for those codecs */ ++static int mov_read_alac(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ return mov_read_extradata(c, pb, atom, CODEC_ID_ALAC); ++} ++ ++static int mov_read_avss(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ return mov_read_extradata(c, pb, atom, CODEC_ID_AVS); ++} ++ ++static int mov_read_jp2h(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ return mov_read_extradata(c, pb, atom, CODEC_ID_JPEG2000); ++} ++ ++static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + +@@ -766,22 +964,23 @@ + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- if((uint64_t)atom.size > (1<<30)) +- return -1; ++ if ((uint64_t)atom.size > (1<<30)) ++ return AVERROR_INVALIDDATA; + +- if (st->codec->codec_id == CODEC_ID_QDM2) { +- // pass all frma atom to codec, needed at least for QDM2 ++ if (st->codec->codec_id == CODEC_ID_QDM2 || st->codec->codec_id == CODEC_ID_QDMC) { ++ // pass all frma atom to codec, needed at least for QDMC and QDM2 + av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = atom.size; +- get_buffer(pb, st->codec->extradata, atom.size); ++ avio_read(pb, st->codec->extradata, atom.size); + } else if (atom.size > 8) { /* to read frma, esds atoms */ +- if (mov_read_default(c, pb, atom) < 0) +- return -1; ++ int ret; ++ if ((ret = mov_read_default(c, pb, atom)) < 0) ++ return ret; + } else +- url_fskip(pb, atom.size); ++ avio_skip(pb, atom.size); + return 0; + } + +@@ -789,7 +988,7 @@ + * This function reads atom content and puts data in extradata without tag + * nor size unlike mov_read_extradata. + */ +-static int mov_read_glbl(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + +@@ -797,15 +996,24 @@ + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- if((uint64_t)atom.size > (1<<30)) +- return -1; ++ if ((uint64_t)atom.size > (1<<30)) ++ return AVERROR_INVALIDDATA; + ++ if (atom.size >= 10) { ++ // Broken files created by legacy versions of Libav and FFmpeg will ++ // wrap a whole fiel atom inside of a glbl atom. ++ unsigned size = avio_rb32(pb); ++ unsigned type = avio_rl32(pb); ++ avio_seek(pb, -8, SEEK_CUR); ++ if (type == MKTAG('f','i','e','l') && size == atom.size) ++ return mov_read_default(c, pb, atom); ++ } + av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = atom.size; +- get_buffer(pb, st->codec->extradata, atom.size); ++ avio_read(pb, st->codec->extradata, atom.size); + return 0; + } + +@@ -814,7 +1022,7 @@ + * but can have extradata appended at the end after the 40 bytes belonging + * to the struct. + */ +-static int mov_read_strf(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + +@@ -824,20 +1032,20 @@ + return 0; + st = c->fc->streams[c->fc->nb_streams-1]; + +- if((uint64_t)atom.size > (1<<30)) +- return -1; ++ if ((uint64_t)atom.size > (1<<30)) ++ return AVERROR_INVALIDDATA; + + av_free(st->codec->extradata); + st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE); + if (!st->codec->extradata) + return AVERROR(ENOMEM); + st->codec->extradata_size = atom.size - 40; +- url_fskip(pb, 40); +- get_buffer(pb, st->codec->extradata, atom.size - 40); ++ avio_skip(pb, 40); ++ avio_read(pb, st->codec->extradata, atom.size - 40); + return 0; + } + +-static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -848,13 +1056,15 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + +- entries = get_be32(pb); ++ entries = avio_rb32(pb); + +- if(entries >= UINT_MAX/sizeof(int64_t)) +- return -1; ++ if (!entries) ++ return 0; ++ if (entries >= UINT_MAX/sizeof(int64_t)) ++ return AVERROR_INVALIDDATA; + + sc->chunk_offsets = av_malloc(entries * sizeof(int64_t)); + if (!sc->chunk_offsets) +@@ -862,13 +1072,13 @@ + sc->chunk_count = entries; + + if (atom.type == MKTAG('s','t','c','o')) +- for(i=0; ichunk_offsets[i] = get_be32(pb); ++ for (i=0; ichunk_offsets[i] = avio_rb32(pb); + else if (atom.type == MKTAG('c','o','6','4')) +- for(i=0; ichunk_offsets[i] = get_be64(pb); ++ for (i=0; ichunk_offsets[i] = avio_rb64(pb); + else +- return -1; ++ return AVERROR_INVALIDDATA; + + return 0; + } +@@ -908,7 +1118,7 @@ + return CODEC_ID_NONE; + } + +-int ff_mov_read_stsd_entries(MOVContext *c, ByteIOContext *pb, int entries) ++int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries) + { + AVStream *st; + MOVStreamContext *sc; +@@ -919,19 +1129,22 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- for(pseudo_stream_id=0; pseudo_stream_id= 16) { +- get_be32(pb); /* reserved */ +- get_be16(pb); /* reserved */ +- dref_id = get_be16(pb); ++ avio_rb32(pb); /* reserved */ ++ avio_rb16(pb); /* reserved */ ++ dref_id = avio_rb16(pb); ++ }else if (size <= 0){ ++ av_log(c->fc, AV_LOG_ERROR, "invalid size %d in stsd\n", size); ++ return -1; + } + + if (st->codec->codec_tag && +@@ -944,7 +1157,7 @@ + * in the MOV demuxer, patch welcome. */ + multiple_stsd: + av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n"); +- url_fskip(pb, size - (url_ftell(pb) - start_pos)); ++ avio_skip(pb, size - (avio_tell(pb) - start_pos)); + continue; + } + /* we cannot demux concatenated h264 streams because of different extradata */ +@@ -967,9 +1180,9 @@ + id = ff_codec_get_id(ff_codec_bmp_tags, format); + if (id > 0) + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- else if(st->codec->codec_type == AVMEDIA_TYPE_DATA){ ++ else if (st->codec->codec_type == AVMEDIA_TYPE_DATA){ + id = ff_codec_get_id(ff_codec_movsubtitle_tags, format); +- if(id > 0) ++ if (id > 0) + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + } + } +@@ -978,37 +1191,37 @@ + (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, + (format >> 24) & 0xff, st->codec->codec_type); + +- if(st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { ++ if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) { + unsigned int color_depth, len; + int color_greyscale; + + st->codec->codec_id = id; +- get_be16(pb); /* version */ +- get_be16(pb); /* revision level */ +- get_be32(pb); /* vendor */ +- get_be32(pb); /* temporal quality */ +- get_be32(pb); /* spatial quality */ +- +- st->codec->width = get_be16(pb); /* width */ +- st->codec->height = get_be16(pb); /* height */ +- +- get_be32(pb); /* horiz resolution */ +- get_be32(pb); /* vert resolution */ +- get_be32(pb); /* data size, always 0 */ +- get_be16(pb); /* frames per samples */ ++ avio_rb16(pb); /* version */ ++ avio_rb16(pb); /* revision level */ ++ avio_rb32(pb); /* vendor */ ++ avio_rb32(pb); /* temporal quality */ ++ avio_rb32(pb); /* spatial quality */ ++ ++ st->codec->width = avio_rb16(pb); /* width */ ++ st->codec->height = avio_rb16(pb); /* height */ ++ ++ avio_rb32(pb); /* horiz resolution */ ++ avio_rb32(pb); /* vert resolution */ ++ avio_rb32(pb); /* data size, always 0 */ ++ avio_rb16(pb); /* frames per samples */ + +- len = get_byte(pb); /* codec name, pascal string */ ++ len = avio_r8(pb); /* codec name, pascal string */ + if (len > 31) + len = 31; + mov_read_mac_string(c, pb, len, st->codec->codec_name, 32); + if (len < 31) +- url_fskip(pb, 31 - len); ++ avio_skip(pb, 31 - len); + /* codec_tag YV12 triggers an UV swap in rawdec.c */ + if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25)) + st->codec->codec_tag=MKTAG('I', '4', '2', '0'); + +- st->codec->bits_per_coded_sample = get_be16(pb); /* depth */ +- st->codec->color_table_id = get_be16(pb); /* colortable id */ ++ st->codec->bits_per_coded_sample = avio_rb16(pb); /* depth */ ++ st->codec->color_table_id = avio_rb16(pb); /* colortable id */ + av_dlog(c->fc, "depth %d, ctab id %d\n", + st->codec->bits_per_coded_sample, st->codec->color_table_id); + /* figure out the palette situation */ +@@ -1020,9 +1233,8 @@ + (color_depth == 8)) { + /* for palette traversal */ + unsigned int color_start, color_count, color_end; +- unsigned char r, g, b; ++ unsigned char a, r, g, b; + +- st->codec->palctrl = av_malloc(sizeof(*st->codec->palctrl)); + if (color_greyscale) { + int color_index, color_dec; + /* compute the greyscale palette */ +@@ -1031,9 +1243,12 @@ + color_index = 255; + color_dec = 256 / (color_count - 1); + for (j = 0; j < color_count; j++) { ++ if (id == CODEC_ID_CINEPAK){ ++ r = g = b = color_count - 1 - color_index; ++ }else + r = g = b = color_index; +- st->codec->palctrl->palette[j] = +- (r << 16) | (g << 8) | (b); ++ sc->palette[j] = ++ (0xFFU << 24) | (r << 16) | (g << 8) | (b); + color_index -= color_dec; + if (color_index < 0) + color_index = 0; +@@ -1053,69 +1268,68 @@ + r = color_table[j * 3 + 0]; + g = color_table[j * 3 + 1]; + b = color_table[j * 3 + 2]; +- st->codec->palctrl->palette[j] = +- (r << 16) | (g << 8) | (b); ++ sc->palette[j] = ++ (0xFFU << 24) | (r << 16) | (g << 8) | (b); + } + } else { + /* load the palette from the file */ +- color_start = get_be32(pb); +- color_count = get_be16(pb); +- color_end = get_be16(pb); ++ color_start = avio_rb32(pb); ++ color_count = avio_rb16(pb); ++ color_end = avio_rb16(pb); + if ((color_start <= 255) && + (color_end <= 255)) { + for (j = color_start; j <= color_end; j++) { +- /* each R, G, or B component is 16 bits; +- * only use the top 8 bits; skip alpha bytes +- * up front */ +- get_byte(pb); +- get_byte(pb); +- r = get_byte(pb); +- get_byte(pb); +- g = get_byte(pb); +- get_byte(pb); +- b = get_byte(pb); +- get_byte(pb); +- st->codec->palctrl->palette[j] = +- (r << 16) | (g << 8) | (b); ++ /* each A, R, G, or B component is 16 bits; ++ * only use the top 8 bits */ ++ a = avio_r8(pb); ++ avio_r8(pb); ++ r = avio_r8(pb); ++ avio_r8(pb); ++ g = avio_r8(pb); ++ avio_r8(pb); ++ b = avio_r8(pb); ++ avio_r8(pb); ++ sc->palette[j] = ++ (a << 24 ) | (r << 16) | (g << 8) | (b); + } + } + } +- st->codec->palctrl->palette_changed = 1; ++ sc->has_palette = 1; + } +- } else if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { ++ } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) { + int bits_per_sample, flags; +- uint16_t version = get_be16(pb); ++ uint16_t version = avio_rb16(pb); + + st->codec->codec_id = id; +- get_be16(pb); /* revision level */ +- get_be32(pb); /* vendor */ ++ avio_rb16(pb); /* revision level */ ++ avio_rb32(pb); /* vendor */ + +- st->codec->channels = get_be16(pb); /* channel count */ ++ st->codec->channels = avio_rb16(pb); /* channel count */ + av_dlog(c->fc, "audio channels %d\n", st->codec->channels); +- st->codec->bits_per_coded_sample = get_be16(pb); /* sample size */ ++ st->codec->bits_per_coded_sample = avio_rb16(pb); /* sample size */ + +- sc->audio_cid = get_be16(pb); +- get_be16(pb); /* packet size = 0 */ ++ sc->audio_cid = avio_rb16(pb); ++ avio_rb16(pb); /* packet size = 0 */ + +- st->codec->sample_rate = ((get_be32(pb) >> 16)); ++ st->codec->sample_rate = ((avio_rb32(pb) >> 16)); + + //Read QT version 1 fields. In version 0 these do not exist. + av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom); +- if(!c->isom) { +- if(version==1) { +- sc->samples_per_frame = get_be32(pb); +- get_be32(pb); /* bytes per packet */ +- sc->bytes_per_frame = get_be32(pb); +- get_be32(pb); /* bytes per sample */ +- } else if(version==2) { +- get_be32(pb); /* sizeof struct only */ +- st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */ +- st->codec->channels = get_be32(pb); +- get_be32(pb); /* always 0x7F000000 */ +- st->codec->bits_per_coded_sample = get_be32(pb); /* bits per channel if sound is uncompressed */ +- flags = get_be32(pb); /* lpcm format specific flag */ +- sc->bytes_per_frame = get_be32(pb); /* bytes per audio packet if constant */ +- sc->samples_per_frame = get_be32(pb); /* lpcm frames per audio packet if constant */ ++ if (!c->isom) { ++ if (version==1) { ++ sc->samples_per_frame = avio_rb32(pb); ++ avio_rb32(pb); /* bytes per packet */ ++ sc->bytes_per_frame = avio_rb32(pb); ++ avio_rb32(pb); /* bytes per sample */ ++ } else if (version==2) { ++ avio_rb32(pb); /* sizeof struct only */ ++ st->codec->sample_rate = av_int2double(avio_rb64(pb)); /* float 64 */ ++ st->codec->channels = avio_rb32(pb); ++ avio_rb32(pb); /* always 0x7F000000 */ ++ st->codec->bits_per_coded_sample = avio_rb32(pb); /* bits per channel if sound is uncompressed */ ++ flags = avio_rb32(pb); /* lpcm format specific flag */ ++ sc->bytes_per_frame = avio_rb32(pb); /* bytes per audio packet if constant */ ++ sc->samples_per_frame = avio_rb32(pb); /* lpcm frames per audio packet if constant */ + if (format == MKTAG('l','p','c','m')) + st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); + } +@@ -1162,29 +1376,41 @@ + st->codec->bits_per_coded_sample = bits_per_sample; + sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; + } +- } else if(st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ ++ } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){ + // ttxt stsd contains display flags, justification, background + // color, fonts, and default styles, so fake an atom to read it +- MOVAtom fake_atom = { .size = size - (url_ftell(pb) - start_pos) }; ++ MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) }; + if (format != AV_RL32("mp4s")) // mp4s contains a regular esds atom + mov_read_glbl(c, pb, fake_atom); + st->codec->codec_id= id; + st->codec->width = sc->width; + st->codec->height = sc->height; + } else { +- /* other codec type, just skip (rtp, mp4s, tmcd ...) */ +- url_fskip(pb, size - (url_ftell(pb) - start_pos)); ++ if (st->codec->codec_tag == MKTAG('t','m','c','d')) { ++ int val; ++ avio_rb32(pb); /* reserved */ ++ val = avio_rb32(pb); /* flags */ ++ if (val & 1) ++ st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE; ++ avio_rb32(pb); /* time scale */ ++ avio_rb32(pb); /* frame duration */ ++ st->codec->time_base.den = avio_r8(pb); /* number of frame */ ++ st->codec->time_base.num = 1; ++ } ++ /* other codec type, just skip (rtp, mp4s, ...) */ ++ avio_skip(pb, size - (avio_tell(pb) - start_pos)); + } + /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ +- a.size = size - (url_ftell(pb) - start_pos); ++ a.size = size - (avio_tell(pb) - start_pos); + if (a.size > 8) { +- if (mov_read_default(c, pb, a) < 0) +- return -1; ++ int ret; ++ if ((ret = mov_read_default(c, pb, a)) < 0) ++ return ret; + } else if (a.size > 0) +- url_fskip(pb, a.size); ++ avio_skip(pb, a.size); + } + +- if(st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) ++ if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) + st->codec->sample_rate= sc->time_scale; + + /* special codec parameters handling */ +@@ -1192,10 +1418,10 @@ + #if CONFIG_DV_DEMUXER + case CODEC_ID_DVAUDIO: + c->dv_fctx = avformat_alloc_context(); +- c->dv_demux = dv_init_demux(c->dv_fctx); ++ c->dv_demux = avpriv_dv_init_demux(c->dv_fctx); + if (!c->dv_demux) { + av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); +- return -1; ++ return AVERROR(ENOMEM); + } + sc->dv_audio_container = 1; + st->codec->codec_id = CODEC_ID_PCM_S16LE; +@@ -1210,14 +1436,16 @@ + st->codec->channels= 1; /* really needed */ + break; + case CODEC_ID_AMR_NB: +- case CODEC_ID_AMR_WB: +- st->codec->frame_size= sc->samples_per_frame; + st->codec->channels= 1; /* really needed */ + /* force sample rate for amr, stsd in 3gp does not store sample rate */ +- if (st->codec->codec_id == CODEC_ID_AMR_NB) +- st->codec->sample_rate = 8000; +- else if (st->codec->codec_id == CODEC_ID_AMR_WB) +- st->codec->sample_rate = 16000; ++ st->codec->sample_rate = 8000; ++ /* force frame_size, too, samples_per_frame isn't always set properly */ ++ st->codec->frame_size = 160; ++ break; ++ case CODEC_ID_AMR_WB: ++ st->codec->channels = 1; ++ st->codec->sample_rate = 16000; ++ st->codec->frame_size = 320; + break; + case CODEC_ID_MP2: + case CODEC_ID_MP3: +@@ -1237,6 +1465,12 @@ + st->codec->sample_rate = AV_RB32(st->codec->extradata+32); + } + break; ++ case CODEC_ID_AC3: ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ break; ++ case CODEC_ID_MPEG1VIDEO: ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ break; + default: + break; + } +@@ -1244,18 +1478,18 @@ + return 0; + } + +-static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int entries; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ +- entries = get_be32(pb); ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ ++ entries = avio_rb32(pb); + + return ff_mov_read_stsd_entries(c, pb, entries); + } + +-static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1266,29 +1500,31 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + +- entries = get_be32(pb); ++ entries = avio_rb32(pb); + + av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); + +- if(entries >= UINT_MAX / sizeof(*sc->stsc_data)) +- return -1; ++ if (!entries) ++ return 0; ++ if (entries >= UINT_MAX / sizeof(*sc->stsc_data)) ++ return AVERROR_INVALIDDATA; + sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data)); + if (!sc->stsc_data) + return AVERROR(ENOMEM); + sc->stsc_count = entries; + +- for(i=0; istsc_data[i].first = get_be32(pb); +- sc->stsc_data[i].count = get_be32(pb); +- sc->stsc_data[i].id = get_be32(pb); ++ for (i=0; istsc_data[i].first = avio_rb32(pb); ++ sc->stsc_data[i].count = avio_rb32(pb); ++ sc->stsc_data[i].id = avio_rb32(pb); + } + return 0; + } + +-static int mov_read_stps(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1299,25 +1535,25 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_be32(pb); // version + flags ++ avio_rb32(pb); // version + flags + +- entries = get_be32(pb); ++ entries = avio_rb32(pb); + if (entries >= UINT_MAX / sizeof(*sc->stps_data)) +- return -1; ++ return AVERROR_INVALIDDATA; + sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data)); + if (!sc->stps_data) + return AVERROR(ENOMEM); + sc->stps_count = entries; + + for (i = 0; i < entries; i++) { +- sc->stps_data[i] = get_be32(pb); ++ sc->stps_data[i] = avio_rb32(pb); + //av_dlog(c->fc, "stps %d\n", sc->stps_data[i]); + } + + return 0; + } + +-static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1328,28 +1564,30 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + +- entries = get_be32(pb); ++ entries = avio_rb32(pb); + + av_dlog(c->fc, "keyframe_count = %d\n", entries); + +- if(entries >= UINT_MAX / sizeof(int)) +- return -1; ++ if (!entries) ++ return 0; ++ if (entries >= UINT_MAX / sizeof(int)) ++ return AVERROR_INVALIDDATA; + sc->keyframes = av_malloc(entries * sizeof(int)); + if (!sc->keyframes) + return AVERROR(ENOMEM); + sc->keyframe_count = entries; + +- for(i=0; ikeyframes[i] = get_be32(pb); ++ for (i=0; ikeyframes[i] = avio_rb32(pb); + //av_dlog(c->fc, "keyframes[]=%d\n", sc->keyframes[i]); + } + return 0; + } + +-static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1362,20 +1600,20 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ + + if (atom.type == MKTAG('s','t','s','z')) { +- sample_size = get_be32(pb); ++ sample_size = avio_rb32(pb); + if (!sc->sample_size) /* do not overwrite value computed in stsd */ + sc->sample_size = sample_size; + field_size = 32; + } else { + sample_size = 0; +- get_be24(pb); /* reserved */ +- field_size = get_byte(pb); ++ avio_rb24(pb); /* reserved */ ++ field_size = avio_r8(pb); + } +- entries = get_be32(pb); ++ entries = avio_rb32(pb); + + av_dlog(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries); + +@@ -1385,11 +1623,13 @@ + + if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) { + av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size); +- return -1; ++ return AVERROR_INVALIDDATA; + } + ++ if (!entries) ++ return 0; + if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size) +- return -1; ++ return AVERROR_INVALIDDATA; + sc->sample_sizes = av_malloc(entries * sizeof(int)); + if (!sc->sample_sizes) + return AVERROR(ENOMEM); +@@ -1402,22 +1642,24 @@ + return AVERROR(ENOMEM); + } + +- if (get_buffer(pb, buf, num_bytes) < num_bytes) { ++ if (avio_read(pb, buf, num_bytes) < num_bytes) { + av_freep(&sc->sample_sizes); + av_free(buf); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + init_get_bits(&gb, buf, 8*num_bytes); + +- for(i=0; isample_sizes[i] = get_bits_long(&gb, field_size); ++ sc->data_size += sc->sample_sizes[i]; ++ } + + av_free(buf); + return 0; + } + +-static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1430,41 +1672,50 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ +- entries = get_be32(pb); ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ ++ entries = avio_rb32(pb); + +- av_dlog(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); ++ av_dlog(c->fc, "track[%i].stts.entries = %i\n", ++ c->fc->nb_streams-1, entries); + +- if(entries >= UINT_MAX / sizeof(*sc->stts_data)) ++ if (entries >= UINT_MAX / sizeof(*sc->stts_data)) + return -1; ++ + sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data)); + if (!sc->stts_data) + return AVERROR(ENOMEM); ++ + sc->stts_count = entries; + +- for(i=0; ifc, AV_LOG_ERROR, "Invalid SampleDelta in STTS %d\n", sample_duration); ++ sample_duration = 1; ++ } + sc->stts_data[i].count= sample_count; + sc->stts_data[i].duration= sample_duration; + +- av_dlog(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); ++ av_dlog(c->fc, "sample_count=%d, sample_duration=%d\n", ++ sample_count, sample_duration); + + duration+=(int64_t)sample_duration*sample_count; + total_sample_count+=sample_count; + } + + st->nb_frames= total_sample_count; +- if(duration) ++ if (duration) + st->duration= duration; + return 0; + } + +-static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; +@@ -1475,26 +1726,28 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ +- entries = get_be32(pb); ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ ++ entries = avio_rb32(pb); + + av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries); + +- if(entries >= UINT_MAX / sizeof(*sc->ctts_data)) +- return -1; ++ if (!entries) ++ return 0; ++ if (entries >= UINT_MAX / sizeof(*sc->ctts_data)) ++ return AVERROR_INVALIDDATA; + sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data)); + if (!sc->ctts_data) + return AVERROR(ENOMEM); + sc->ctts_count = entries; + +- for(i=0; ictts_data[i].count = count; + sc->ctts_data[i].duration= duration; +- if (duration < 0) ++ if (duration < 0 && i+2dts_shift = FFMAX(sc->dts_shift, -duration); + } + +@@ -1516,11 +1769,13 @@ + uint64_t stream_size = 0; + + /* adjust first dts according to edit list */ +- if (sc->time_offset && mov->time_scale > 0) { +- int rescaled = sc->time_offset < 0 ? av_rescale(sc->time_offset, sc->time_scale, mov->time_scale) : sc->time_offset; +- current_dts = -rescaled; ++ if ((sc->empty_duration || sc->start_time) && mov->time_scale > 0) { ++ if (sc->empty_duration) ++ sc->empty_duration = av_rescale(sc->empty_duration, sc->time_scale, mov->time_scale); ++ sc->time_offset = sc->start_time - sc->empty_duration; ++ current_dts = -sc->time_offset; + if (sc->ctts_data && sc->stts_data && +- sc->ctts_data[0].duration / sc->stts_data[0].duration > 16) { ++ sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) { + /* more than 16 frames delay, dts are likely wrong + this happens with files created by iMovie */ + sc->wrong_dts = 1; +@@ -1539,6 +1794,8 @@ + + current_dts -= sc->dts_shift; + ++ if (!sc->sample_count) ++ return; + if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries)) + return; + st->index_entries = av_malloc(sc->sample_count*sizeof(*st->index_entries)); +@@ -1548,7 +1805,7 @@ + + for (i = 0; i < sc->chunk_count; i++) { + current_offset = sc->chunk_offsets[i]; +- if (stsc_index + 1 < sc->stsc_count && ++ while (stsc_index + 1 < sc->stsc_count && + i + 1 == sc->stsc_data[stsc_index + 1].first) + stsc_index++; + for (j = 0; j < sc->stsc_data[stsc_index].count; j++) { +@@ -1570,7 +1827,7 @@ + if (keyframe) + distance = 0; + sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; +- if(sc->pseudo_stream_id == -1 || ++ if (sc->pseudo_stream_id == -1 || + sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { + AVIndexEntry *e = &st->index_entries[st->nb_index_entries++]; + e->pos = current_offset; +@@ -1605,7 +1862,8 @@ + unsigned count, chunk_count; + + chunk_samples = sc->stsc_data[i].count; +- if (sc->samples_per_frame && chunk_samples % sc->samples_per_frame) { ++ if (i != sc->stsc_count - 1 && ++ sc->samples_per_frame && chunk_samples % sc->samples_per_frame) { + av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n"); + return; + } +@@ -1682,13 +1940,14 @@ + } + } + +-static int mov_open_dref(ByteIOContext **pb, char *src, MOVDref *ref) ++static int mov_open_dref(AVIOContext **pb, const char *src, MOVDref *ref, ++ AVIOInterruptCB *int_cb, int use_absolute_path, AVFormatContext *fc) + { + /* try relative path, we do not try the absolute because it can leak information about our + system to an attacker */ + if (ref->nlvl_to > 0 && ref->nlvl_from > 0) { + char filename[1024]; +- char *src_path; ++ const char *src_path; + int i, l; + + /* find a source dir */ +@@ -1717,22 +1976,28 @@ + + av_strlcat(filename, ref->path + l + 1, 1024); + +- if (!url_fopen(pb, filename, URL_RDONLY)) ++ if (!avio_open2(pb, filename, AVIO_FLAG_READ, int_cb, NULL)) + return 0; + } ++ } else if (use_absolute_path) { ++ av_log(fc, AV_LOG_WARNING, "Using absolute path on user request, " ++ "this is a possible security issue\n"); ++ if (!avio_open2(pb, ref->path, AVIO_FLAG_READ, int_cb, NULL)) ++ return 0; + } + + return AVERROR(ENOENT); +-}; ++} + +-static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + AVStream *st; + MOVStreamContext *sc; + int ret; + +- st = av_new_stream(c->fc, c->fc->nb_streams); ++ st = avformat_new_stream(c->fc, NULL); + if (!st) return AVERROR(ENOMEM); ++ st->id = c->fc->nb_streams; + sc = av_mallocz(sizeof(MOVStreamContext)); + if (!sc) return AVERROR(ENOMEM); + +@@ -1758,7 +2023,7 @@ + sc->time_scale = 1; + } + +- av_set_pts_info(st, 64, 1, sc->time_scale); ++ avpriv_set_pts_info(st, 64, 1, sc->time_scale); + + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + !st->codec->frame_size && sc->stts_count == 1) { +@@ -1771,7 +2036,8 @@ + + if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { + MOVDref *dref = &sc->drefs[sc->dref_id - 1]; +- if (mov_open_dref(&sc->pb, c->fc->filename, dref) < 0) ++ if (mov_open_dref(&sc->pb, c->fc->filename, dref, &c->fc->interrupt_callback, ++ c->use_absolute_path, c->fc) < 0) + av_log(c->fc, AV_LOG_ERROR, + "stream %d, error opening alias: path='%s', dir='%s', " + "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n", +@@ -1824,7 +2090,7 @@ + return 0; + } + +-static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_ilst(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int ret; + c->itunes_metadata = 1; +@@ -1833,13 +2099,13 @@ + return ret; + } + +-static int mov_read_meta(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + while (atom.size > 8) { +- uint32_t tag = get_le32(pb); ++ uint32_t tag = avio_rl32(pb); + atom.size -= 4; + if (tag == MKTAG('h','d','l','r')) { +- url_fseek(pb, -8, SEEK_CUR); ++ avio_seek(pb, -8, SEEK_CUR); + atom.size += 8; + return mov_read_default(c, pb, atom); + } +@@ -1847,7 +2113,7 @@ + return 0; + } + +-static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int i; + int width; +@@ -1863,8 +2129,8 @@ + st = c->fc->streams[c->fc->nb_streams-1]; + sc = st->priv_data; + +- version = get_byte(pb); +- get_be24(pb); /* flags */ ++ version = avio_r8(pb); ++ avio_rb24(pb); /* flags */ + /* + MOV_TRACK_ENABLED 0x0001 + MOV_TRACK_IN_MOVIE 0x0002 +@@ -1873,39 +2139,54 @@ + */ + + if (version == 1) { +- get_be64(pb); +- get_be64(pb); ++ avio_rb64(pb); ++ avio_rb64(pb); + } else { +- get_be32(pb); /* creation time */ +- get_be32(pb); /* modification time */ ++ avio_rb32(pb); /* creation time */ ++ avio_rb32(pb); /* modification time */ + } +- st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ +- get_be32(pb); /* reserved */ ++ st->id = (int)avio_rb32(pb); /* track id (NOT 0 !)*/ ++ avio_rb32(pb); /* reserved */ + + /* highlevel (considering edits) duration in movie timebase */ +- (version == 1) ? get_be64(pb) : get_be32(pb); +- get_be32(pb); /* reserved */ +- get_be32(pb); /* reserved */ +- +- get_be16(pb); /* layer */ +- get_be16(pb); /* alternate group */ +- get_be16(pb); /* volume */ +- get_be16(pb); /* reserved */ ++ (version == 1) ? avio_rb64(pb) : avio_rb32(pb); ++ avio_rb32(pb); /* reserved */ ++ avio_rb32(pb); /* reserved */ ++ ++ avio_rb16(pb); /* layer */ ++ avio_rb16(pb); /* alternate group */ ++ avio_rb16(pb); /* volume */ ++ avio_rb16(pb); /* reserved */ + + //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2) + // they're kept in fixed point format through all calculations + // ignore u,v,z b/c we don't need the scale factor to calc aspect ratio + for (i = 0; i < 3; i++) { +- display_matrix[i][0] = get_be32(pb); // 16.16 fixed point +- display_matrix[i][1] = get_be32(pb); // 16.16 fixed point +- get_be32(pb); // 2.30 fixed point (not used) ++ display_matrix[i][0] = avio_rb32(pb); // 16.16 fixed point ++ display_matrix[i][1] = avio_rb32(pb); // 16.16 fixed point ++ avio_rb32(pb); // 2.30 fixed point (not used) + } + +- width = get_be32(pb); // 16.16 fixed point track width +- height = get_be32(pb); // 16.16 fixed point track height ++ width = avio_rb32(pb); // 16.16 fixed point track width ++ height = avio_rb32(pb); // 16.16 fixed point track height + sc->width = width >> 16; + sc->height = height >> 16; + ++ //Assign clockwise rotate values based on transform matrix so that ++ //we can compensate for iPhone orientation during capture. ++ ++ if (display_matrix[1][0] == -65536 && display_matrix[0][1] == 65536) { ++ av_dict_set(&st->metadata, "rotate", "90", 0); ++ } ++ ++ if (display_matrix[0][0] == -65536 && display_matrix[1][1] == -65536) { ++ av_dict_set(&st->metadata, "rotate", "180", 0); ++ } ++ ++ if (display_matrix[1][0] == 65536 && display_matrix[0][1] == -65536) { ++ av_dict_set(&st->metadata, "rotate", "270", 0); ++ } ++ + // transform the display width/height according to the matrix + // skip this if the display matrix is the default identity matrix + // or if it is rotating the picture, ex iPhone 3GS +@@ -1930,18 +2211,18 @@ + return 0; + } + +-static int mov_read_tfhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + MOVFragment *frag = &c->fragment; + MOVTrackExt *trex = NULL; + int flags, track_id, i; + +- get_byte(pb); /* version */ +- flags = get_be24(pb); ++ avio_r8(pb); /* version */ ++ flags = avio_rb24(pb); + +- track_id = get_be32(pb); ++ track_id = avio_rb32(pb); + if (!track_id) +- return -1; ++ return AVERROR_INVALIDDATA; + frag->track_id = track_id; + for (i = 0; i < c->trex_count; i++) + if (c->trex_data[i].track_id == frag->track_id) { +@@ -1950,53 +2231,57 @@ + } + if (!trex) { + av_log(c->fc, AV_LOG_ERROR, "could not find corresponding trex\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (flags & 0x01) frag->base_data_offset = get_be64(pb); ++ if (flags & 0x01) frag->base_data_offset = avio_rb64(pb); + else frag->base_data_offset = frag->moof_offset; +- if (flags & 0x02) frag->stsd_id = get_be32(pb); ++ if (flags & 0x02) frag->stsd_id = avio_rb32(pb); + else frag->stsd_id = trex->stsd_id; + +- frag->duration = flags & 0x08 ? get_be32(pb) : trex->duration; +- frag->size = flags & 0x10 ? get_be32(pb) : trex->size; +- frag->flags = flags & 0x20 ? get_be32(pb) : trex->flags; ++ frag->duration = flags & 0x08 ? avio_rb32(pb) : trex->duration; ++ frag->size = flags & 0x10 ? avio_rb32(pb) : trex->size; ++ frag->flags = flags & 0x20 ? avio_rb32(pb) : trex->flags; + av_dlog(c->fc, "frag flags 0x%x\n", frag->flags); + return 0; + } + +-static int mov_read_chap(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { +- c->chapter_track = get_be32(pb); ++ c->chapter_track = avio_rb32(pb); + return 0; + } + +-static int mov_read_trex(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + MOVTrackExt *trex; + + if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data)) +- return -1; ++ return AVERROR_INVALIDDATA; + trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data)); + if (!trex) + return AVERROR(ENOMEM); ++ ++ c->fc->duration = AV_NOPTS_VALUE; // the duration from mvhd is not representing the whole file when fragments are used. ++ + c->trex_data = trex; + trex = &c->trex_data[c->trex_count++]; +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ +- trex->track_id = get_be32(pb); +- trex->stsd_id = get_be32(pb); +- trex->duration = get_be32(pb); +- trex->size = get_be32(pb); +- trex->flags = get_be32(pb); ++ avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ ++ trex->track_id = avio_rb32(pb); ++ trex->stsd_id = avio_rb32(pb); ++ trex->duration = avio_rb32(pb); ++ trex->size = avio_rb32(pb); ++ trex->flags = avio_rb32(pb); + return 0; + } + +-static int mov_read_trun(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + MOVFragment *frag = &c->fragment; + AVStream *st = NULL; + MOVStreamContext *sc; ++ MOVStts *ctts_data; + uint64_t offset; + int64_t dts; + int data_offset = 0; +@@ -2011,28 +2296,43 @@ + } + if (!st) { + av_log(c->fc, AV_LOG_ERROR, "could not find corresponding track id %d\n", frag->track_id); +- return -1; ++ return AVERROR_INVALIDDATA; + } + sc = st->priv_data; + if (sc->pseudo_stream_id+1 != frag->stsd_id) + return 0; +- get_byte(pb); /* version */ +- flags = get_be24(pb); +- entries = get_be32(pb); ++ avio_r8(pb); /* version */ ++ flags = avio_rb24(pb); ++ entries = avio_rb32(pb); + av_dlog(c->fc, "flags 0x%x entries %d\n", flags, entries); +- if (flags & 0x001) data_offset = get_be32(pb); +- if (flags & 0x004) first_sample_flags = get_be32(pb); +- if (flags & 0x800) { +- MOVStts *ctts_data; +- if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data)) +- return -1; +- ctts_data = av_realloc(sc->ctts_data, +- (entries+sc->ctts_count)*sizeof(*sc->ctts_data)); ++ ++ /* Always assume the presence of composition time offsets. ++ * Without this assumption, for instance, we cannot deal with a track in fragmented movies that meet the following. ++ * 1) in the initial movie, there are no samples. ++ * 2) in the first movie fragment, there is only one sample without composition time offset. ++ * 3) in the subsequent movie fragments, there are samples with composition time offset. */ ++ if (!sc->ctts_count && sc->sample_count) ++ { ++ /* Complement ctts table if moov atom doesn't have ctts atom. */ ++ ctts_data = av_malloc(sizeof(*sc->ctts_data)); + if (!ctts_data) + return AVERROR(ENOMEM); + sc->ctts_data = ctts_data; +- } +- dts = st->duration; ++ sc->ctts_data[sc->ctts_count].count = sc->sample_count; ++ sc->ctts_data[sc->ctts_count].duration = 0; ++ sc->ctts_count++; ++ } ++ if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data)) ++ return AVERROR_INVALIDDATA; ++ ctts_data = av_realloc(sc->ctts_data, ++ (entries+sc->ctts_count)*sizeof(*sc->ctts_data)); ++ if (!ctts_data) ++ return AVERROR(ENOMEM); ++ sc->ctts_data = ctts_data; ++ ++ if (flags & 0x001) data_offset = avio_rb32(pb); ++ if (flags & 0x004) first_sample_flags = avio_rb32(pb); ++ dts = st->duration - sc->time_offset; + offset = frag->base_data_offset + data_offset; + distance = 0; + av_dlog(c->fc, "first sample flags 0x%x\n", first_sample_flags); +@@ -2042,14 +2342,12 @@ + unsigned sample_duration = frag->duration; + int keyframe; + +- if (flags & 0x100) sample_duration = get_be32(pb); +- if (flags & 0x200) sample_size = get_be32(pb); +- if (flags & 0x400) sample_flags = get_be32(pb); +- if (flags & 0x800) { +- sc->ctts_data[sc->ctts_count].count = 1; +- sc->ctts_data[sc->ctts_count].duration = get_be32(pb); +- sc->ctts_count++; +- } ++ if (flags & 0x100) sample_duration = avio_rb32(pb); ++ if (flags & 0x200) sample_size = avio_rb32(pb); ++ if (flags & 0x400) sample_flags = avio_rb32(pb); ++ sc->ctts_data[sc->ctts_count].count = 1; ++ sc->ctts_data[sc->ctts_count].duration = (flags & 0x800) ? avio_rb32(pb) : 0; ++ sc->ctts_count++; + if ((keyframe = st->codec->codec_type == AVMEDIA_TYPE_AUDIO || + (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000)) + distance = 0; +@@ -2061,55 +2359,56 @@ + distance++; + dts += sample_duration; + offset += sample_size; ++ sc->data_size += sample_size; + } + frag->moof_offset = offset; +- st->duration = dts; ++ st->duration = dts + sc->time_offset; + return 0; + } + + /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */ + /* like the files created with Adobe Premiere 5.0, for samples see */ + /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */ +-static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_wide(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + int err; + + if (atom.size < 8) + return 0; /* continue */ +- if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */ +- url_fskip(pb, atom.size - 4); ++ if (avio_rb32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */ ++ avio_skip(pb, atom.size - 4); + return 0; + } +- atom.type = get_le32(pb); ++ atom.type = avio_rl32(pb); + atom.size -= 8; + if (atom.type != MKTAG('m','d','a','t')) { +- url_fskip(pb, atom.size); ++ avio_skip(pb, atom.size); + return 0; + } + err = mov_read_mdat(c, pb, atom); + return err; + } + +-static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + #if CONFIG_ZLIB +- ByteIOContext ctx; ++ AVIOContext ctx; + uint8_t *cmov_data; + uint8_t *moov_data; /* uncompressed data */ + long cmov_len, moov_len; + int ret = -1; + +- get_be32(pb); /* dcom atom */ +- if (get_le32(pb) != MKTAG('d','c','o','m')) +- return -1; +- if (get_le32(pb) != MKTAG('z','l','i','b')) { ++ avio_rb32(pb); /* dcom atom */ ++ if (avio_rl32(pb) != MKTAG('d','c','o','m')) ++ return AVERROR_INVALIDDATA; ++ if (avio_rl32(pb) != MKTAG('z','l','i','b')) { + av_log(c->fc, AV_LOG_ERROR, "unknown compression for cmov atom !"); +- return -1; ++ return AVERROR_INVALIDDATA; + } +- get_be32(pb); /* cmvd atom */ +- if (get_le32(pb) != MKTAG('c','m','v','d')) +- return -1; +- moov_len = get_be32(pb); /* uncompressed size */ ++ avio_rb32(pb); /* cmvd atom */ ++ if (avio_rl32(pb) != MKTAG('c','m','v','d')) ++ return AVERROR_INVALIDDATA; ++ moov_len = avio_rb32(pb); /* uncompressed size */ + cmov_len = atom.size - 6 * 4; + + cmov_data = av_malloc(cmov_len); +@@ -2120,16 +2419,13 @@ + av_free(cmov_data); + return AVERROR(ENOMEM); + } +- get_buffer(pb, cmov_data, cmov_len); +- if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) ++ avio_read(pb, cmov_data, cmov_len); ++ if (uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) + goto free_and_return; +- if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0) ++ if (ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0) + goto free_and_return; + atom.type = MKTAG('m','o','o','v'); + atom.size = moov_len; +-#ifdef DEBUG +-// { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); } +-#endif + ret = mov_read_default(c, &ctx, atom); + free_and_return: + av_free(moov_data); +@@ -2137,38 +2433,46 @@ + return ret; + #else + av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n"); +- return -1; ++ return AVERROR(ENOSYS); + #endif + } + + /* edit list atom */ +-static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) ++static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom) + { + MOVStreamContext *sc; +- int i, edit_count; ++ int i, edit_count, version, edit_start_index = 0; + + if (c->fc->nb_streams < 1) + return 0; + sc = c->fc->streams[c->fc->nb_streams-1]->priv_data; + +- get_byte(pb); /* version */ +- get_be24(pb); /* flags */ +- edit_count = get_be32(pb); /* entries */ +- +- if((uint64_t)edit_count*12+8 > atom.size) +- return -1; +- +- for(i=0; i= -1) { +- sc->time_offset = time != -1 ? time : -duration; ++ version = avio_r8(pb); /* version */ ++ avio_rb24(pb); /* flags */ ++ edit_count = avio_rb32(pb); /* entries */ ++ ++ if ((uint64_t)edit_count*12+8 > atom.size) ++ return AVERROR_INVALIDDATA; ++ ++ for (i=0; iempty_duration = duration; ++ edit_start_index = 1; ++ } else if (i == edit_start_index && time >= 0) ++ sc->start_time = time; + } + +- if(edit_count > 1) ++ if (edit_count > 1) + av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, " + "a/v desync might occur, patch welcome\n"); + +@@ -2176,8 +2480,17 @@ + return 0; + } + ++static int mov_read_chan2(MOVContext *c, AVIOContext *pb, MOVAtom atom) ++{ ++ if (atom.size < 16) ++ return 0; ++ avio_skip(pb, 4); ++ ff_mov_read_chan(c->fc, atom.size - 4, c->fc->streams[0]->codec); ++ return 0; ++} ++ + static const MOVParseTableEntry mov_default_parse_table[] = { +-{ MKTAG('a','v','s','s'), mov_read_extradata }, ++{ MKTAG('a','v','s','s'), mov_read_avss }, + { MKTAG('c','h','p','l'), mov_read_chpl }, + { MKTAG('c','o','6','4'), mov_read_stco }, + { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */ +@@ -2186,12 +2499,12 @@ + { MKTAG('e','d','t','s'), mov_read_default }, + { MKTAG('e','l','s','t'), mov_read_elst }, + { MKTAG('e','n','d','a'), mov_read_enda }, +-{ MKTAG('f','i','e','l'), mov_read_extradata }, ++{ MKTAG('f','i','e','l'), mov_read_fiel }, + { MKTAG('f','t','y','p'), mov_read_ftyp }, + { MKTAG('g','l','b','l'), mov_read_glbl }, + { MKTAG('h','d','l','r'), mov_read_hdlr }, + { MKTAG('i','l','s','t'), mov_read_ilst }, +-{ MKTAG('j','p','2','h'), mov_read_extradata }, ++{ MKTAG('j','p','2','h'), mov_read_jp2h }, + { MKTAG('m','d','a','t'), mov_read_mdat }, + { MKTAG('m','d','h','d'), mov_read_mdhd }, + { MKTAG('m','d','i','a'), mov_read_default }, +@@ -2202,7 +2515,7 @@ + { MKTAG('m','v','e','x'), mov_read_default }, + { MKTAG('m','v','h','d'), mov_read_mvhd }, + { MKTAG('S','M','I',' '), mov_read_smi }, /* Sorenson extension ??? */ +-{ MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */ ++{ MKTAG('a','l','a','c'), mov_read_alac }, /* alac specific atom */ + { MKTAG('a','v','c','C'), mov_read_glbl }, + { MKTAG('p','a','s','p'), mov_read_pasp }, + { MKTAG('s','t','b','l'), mov_read_default }, +@@ -2228,7 +2541,9 @@ + { MKTAG('e','s','d','s'), mov_read_esds }, + { MKTAG('d','a','c','3'), mov_read_dac3 }, /* AC-3 info */ + { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ ++{ MKTAG('w','f','e','x'), mov_read_wfex }, + { MKTAG('c','m','o','v'), mov_read_cmov }, ++{ MKTAG('c','h','a','n'), mov_read_chan }, /* channel layout */ + { 0, NULL } + }; + +@@ -2240,7 +2555,7 @@ + + /* check file header */ + offset = 0; +- for(;;) { ++ for (;;) { + /* ignore invalid offset */ + if ((offset + 8) > (unsigned int)p->buf_size) + return score; +@@ -2274,7 +2589,6 @@ + return score; + } + } +- return score; + } + + // must be done after parsing all trak because there's no order requirement +@@ -2298,7 +2612,7 @@ + + st->discard = AVDISCARD_ALL; + sc = st->priv_data; +- cur_pos = url_ftell(sc->pb); ++ cur_pos = avio_tell(sc->pb); + + for (i = 0; i < st->nb_index_entries; i++) { + AVIndexEntry *sample = &st->index_entries[i]; +@@ -2307,13 +2621,13 @@ + uint16_t ch; + int len, title_len; + +- if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { ++ if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { + av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i); + goto finish; + } + + // the first two bytes are the length of the title +- len = get_be16(sc->pb); ++ len = avio_rb16(sc->pb); + if (len > sample->size-2) + continue; + title_len = 2*len + 1; +@@ -2323,34 +2637,81 @@ + // The samples could theoretically be in any encoding if there's an encd + // atom following, but in practice are only utf-8 or utf-16, distinguished + // instead by the presence of a BOM +- ch = get_be16(sc->pb); +- if (ch == 0xfeff) +- avio_get_str16be(sc->pb, len, title, title_len); +- else if (ch == 0xfffe) +- avio_get_str16le(sc->pb, len, title, title_len); +- else { +- AV_WB16(title, ch); +- get_strz(sc->pb, title + 2, len - 1); ++ if (!len) { ++ title[0] = 0; ++ } else { ++ ch = avio_rb16(sc->pb); ++ if (ch == 0xfeff) ++ avio_get_str16be(sc->pb, len, title, title_len); ++ else if (ch == 0xfffe) ++ avio_get_str16le(sc->pb, len, title, title_len); ++ else { ++ AV_WB16(title, ch); ++ if (len == 1 || len == 2) ++ title[len] = 0; ++ else ++ avio_get_str(sc->pb, INT_MAX, title + 2, len - 1); ++ } + } + +- ff_new_chapter(s, i, st->time_base, sample->timestamp, end, title); ++ avpriv_new_chapter(s, i, st->time_base, sample->timestamp, end, title); + av_freep(&title); + } + finish: +- url_fseek(sc->pb, cur_pos, SEEK_SET); ++ avio_seek(sc->pb, cur_pos, SEEK_SET); ++} ++ ++static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st, ++ uint32_t value) ++{ ++ char buf[16]; ++ struct ff_timecode tc = { ++ .drop = st->codec->flags2 & CODEC_FLAG2_DROP_FRAME_TIMECODE, ++ .rate = (AVRational){st->codec->time_base.den, ++ st->codec->time_base.num}, ++ }; ++ ++ if (avpriv_check_timecode_rate(s, tc.rate, tc.drop) < 0) ++ return AVERROR(EINVAL); ++ av_dict_set(&st->metadata, "timecode", ++ avpriv_timecode_to_string(buf, &tc, value), 0); ++ return 0; ++} ++ ++static int mov_read_timecode_track(AVFormatContext *s, AVStream *st) ++{ ++ MOVStreamContext *sc = st->priv_data; ++ int64_t cur_pos = avio_tell(sc->pb); ++ uint32_t value; ++ ++ if (!st->nb_index_entries) ++ return -1; ++ ++ avio_seek(sc->pb, st->index_entries->pos, SEEK_SET); ++ value = avio_rb32(s->pb); ++ ++ /* Assume Counter flag is set to 1 in tmcd track (even though it is likely ++ * not the case) and thus assume "frame number format" instead of QT one. ++ * No sample with tmcd track can be found with a QT timecode at the moment, ++ * despite what the tmcd track "suggests" (Counter flag set to 0 means QT ++ * format). */ ++ parse_timecode_in_framenum_format(s, st, value); ++ ++ avio_seek(sc->pb, cur_pos, SEEK_SET); ++ return 0; + } + + static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + MOVContext *mov = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int err; + MOVAtom atom = { AV_RL32("root") }; + + mov->fc = s; + /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ +- if(!url_is_streamed(pb)) +- atom.size = url_fsize(pb); ++ if (pb->seekable) ++ atom.size = avio_size(pb); + else + atom.size = INT64_MAX; + +@@ -2361,12 +2722,28 @@ + } + if (!mov->found_moov) { + av_log(s, AV_LOG_ERROR, "moov atom not found\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } +- av_dlog(mov->fc, "on_parse_exit_offset=%lld\n", url_ftell(pb)); ++ av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb)); + +- if (!url_is_streamed(pb) && mov->chapter_track > 0) +- mov_read_chapters(s); ++ if (pb->seekable) { ++ int i; ++ if (mov->chapter_track > 0) ++ mov_read_chapters(s); ++ for (i = 0; i < s->nb_streams; i++) ++ if (s->streams[i]->codec->codec_tag == AV_RL32("tmcd")) ++ mov_read_timecode_track(s, s->streams[i]); ++ } ++ ++ if (mov->trex_data) { ++ int i; ++ for (i = 0; i < s->nb_streams; i++) { ++ AVStream *st = s->streams[i]; ++ MOVStreamContext *sc = st->priv_data; ++ if (st->duration) ++ st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration; ++ } ++ } + + return 0; + } +@@ -2383,8 +2760,8 @@ + AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample]; + int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale); + av_dlog(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); +- if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || +- (!url_is_streamed(s->pb) && ++ if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) || ++ (s->pb->seekable && + ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && + ((FFABS(best_dts - dts) <= 8*AV_TIME_BASE && current_sample->pos < sample->pos) || + (FFABS(best_dts - dts) > 8*AV_TIME_BASE && dts < best_dts)))))) { +@@ -2404,15 +2781,16 @@ + AVIndexEntry *sample; + AVStream *st = NULL; + int ret; ++ mov->fc = s; + retry: + sample = mov_find_next_sample(s, &st); + if (!sample) { + mov->found_mdat = 0; +- if (!url_is_streamed(s->pb) || ++ if (s->pb->seekable|| + mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 || + url_feof(s->pb)) + return AVERROR_EOF; +- av_dlog(s, "read fragments, offset 0x%llx\n", url_ftell(s->pb)); ++ av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb)); + goto retry; + } + sc = st->priv_data; +@@ -2420,20 +2798,31 @@ + sc->current_sample++; + + if (st->discard != AVDISCARD_ALL) { +- if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { ++ if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { + av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", + sc->ffindex, sample->pos); +- return -1; ++ return AVERROR_INVALIDDATA; + } + ret = av_get_packet(sc->pb, pkt, sample->size); + if (ret < 0) + return ret; ++ if (sc->has_palette) { ++ uint8_t *pal; ++ ++ pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE); ++ if (!pal) { ++ av_log(mov->fc, AV_LOG_ERROR, "Cannot append palette to packet\n"); ++ } else { ++ memcpy(pal, sc->palette, AVPALETTE_SIZE); ++ sc->has_palette = 0; ++ } ++ } + #if CONFIG_DV_DEMUXER + if (mov->dv_demux && sc->dv_audio_container) { +- dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); ++ avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size, pkt->pos); + av_free(pkt->data); + pkt->size = 0; +- ret = dv_get_packet(mov->dv_demux, pkt); ++ ret = avpriv_dv_get_packet(mov->dv_demux, pkt); + if (ret < 0) + return ret; + } +@@ -2479,7 +2868,7 @@ + if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp) + sample = 0; + if (sample < 0) /* not sure what to do */ +- return -1; ++ return AVERROR_INVALIDDATA; + sc->current_sample = sample; + av_dlog(s, "stream %d, found sample %d\n", st->index, sc->current_sample); + /* adjust ctts index */ +@@ -2506,14 +2895,14 @@ + int i; + + if (stream_index >= s->nb_streams) +- return -1; ++ return AVERROR_INVALIDDATA; + if (sample_time < 0) + sample_time = 0; + + st = s->streams[stream_index]; + sample = mov_seek_stream(s, st, sample_time, flags); + if (sample < 0) +- return -1; ++ return sample; + + /* adjust seek timestamp to found sample timestamp */ + seek_timestamp = st->index_entries[sample].timestamp; +@@ -2545,13 +2934,11 @@ + } + av_freep(&sc->drefs); + if (sc->pb && sc->pb != s->pb) +- url_fclose(sc->pb); +- +- av_freep(&st->codec->palctrl); ++ avio_close(sc->pb); + } + + if (mov->dv_demux) { +- for(i = 0; i < mov->dv_fctx->nb_streams; i++) { ++ for (i = 0; i < mov->dv_fctx->nb_streams; i++) { + av_freep(&mov->dv_fctx->streams[i]->codec); + av_freep(&mov->dv_fctx->streams[i]); + } +@@ -2564,13 +2951,23 @@ + return 0; + } + ++static const AVOption options[] = { ++ {"use_absolute_path", ++ "allow using absolute path when opening alias, this is a possible security issue", ++ offsetof(MOVContext, use_absolute_path), FF_OPT_TYPE_INT, {.dbl = 0}, ++ 0, 1, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM}, ++ {NULL} ++}; ++static const AVClass class = {"mov,mp4,m4a,3gp,3g2,mj2", av_default_item_name, options, LIBAVUTIL_VERSION_INT}; ++ + AVInputFormat ff_mov_demuxer = { +- "mov,mp4,m4a,3gp,3g2,mj2", +- NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"), +- sizeof(MOVContext), +- mov_probe, +- mov_read_header, +- mov_read_packet, +- mov_read_close, +- mov_read_seek, ++ .name = "mov,mp4,m4a,3gp,3g2,mj2", ++ .long_name = NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"), ++ .priv_data_size = sizeof(MOVContext), ++ .read_probe = mov_probe, ++ .read_header = mov_read_header, ++ .read_packet = mov_read_packet, ++ .read_close = mov_read_close, ++ .read_seek = mov_read_seek, ++ .priv_class = &class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov_chan.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov_chan.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov_chan.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov_chan.c 2012-05-14 14:08:55.039354171 +0200 +@@ -0,0 +1,517 @@ ++/* ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * mov 'chan' tag reading/writing. ++ * @author Justin Ruggles ++ */ ++ ++#include ++ ++#include "libavutil/audioconvert.h" ++#include "libavcodec/avcodec.h" ++#include "mov_chan.h" ++ ++/** ++ * Channel Layout Tag ++ * This tells which channels are present in the audio stream and the order in ++ * which they appear. ++ * ++ * @note We're using the channel layout tag to indicate channel order ++ * when the value is greater than 0x10000. The Apple documentation has ++ * some contradictions as to how this is actually supposed to be handled. ++ * ++ * Core Audio File Format Spec: ++ * "The high 16 bits indicates a specific ordering of the channels." ++ * Core Audio Data Types Reference: ++ * "These identifiers specify the channels included in a layout but ++ * do not specify a particular ordering of those channels." ++ */ ++enum MovChannelLayoutTag { ++ MOV_CH_LAYOUT_UNKNOWN = 0xFFFF0000, ++ MOV_CH_LAYOUT_USE_DESCRIPTIONS = ( 0 << 16) | 0, ++ MOV_CH_LAYOUT_USE_BITMAP = ( 1 << 16) | 0, ++ MOV_CH_LAYOUT_DISCRETEINORDER = (147 << 16) | 0, ++ MOV_CH_LAYOUT_MONO = (100 << 16) | 1, ++ MOV_CH_LAYOUT_STEREO = (101 << 16) | 2, ++ MOV_CH_LAYOUT_STEREOHEADPHONES = (102 << 16) | 2, ++ MOV_CH_LAYOUT_MATRIXSTEREO = (103 << 16) | 2, ++ MOV_CH_LAYOUT_MIDSIDE = (104 << 16) | 2, ++ MOV_CH_LAYOUT_XY = (105 << 16) | 2, ++ MOV_CH_LAYOUT_BINAURAL = (106 << 16) | 2, ++ MOV_CH_LAYOUT_AMBISONIC_B_FORMAT = (107 << 16) | 4, ++ MOV_CH_LAYOUT_QUADRAPHONIC = (108 << 16) | 4, ++ MOV_CH_LAYOUT_PENTAGONAL = (109 << 16) | 5, ++ MOV_CH_LAYOUT_HEXAGONAL = (110 << 16) | 6, ++ MOV_CH_LAYOUT_OCTAGONAL = (111 << 16) | 8, ++ MOV_CH_LAYOUT_CUBE = (112 << 16) | 8, ++ MOV_CH_LAYOUT_MPEG_3_0_A = (113 << 16) | 3, ++ MOV_CH_LAYOUT_MPEG_3_0_B = (114 << 16) | 3, ++ MOV_CH_LAYOUT_MPEG_4_0_A = (115 << 16) | 4, ++ MOV_CH_LAYOUT_MPEG_4_0_B = (116 << 16) | 4, ++ MOV_CH_LAYOUT_MPEG_5_0_A = (117 << 16) | 5, ++ MOV_CH_LAYOUT_MPEG_5_0_B = (118 << 16) | 5, ++ MOV_CH_LAYOUT_MPEG_5_0_C = (119 << 16) | 5, ++ MOV_CH_LAYOUT_MPEG_5_0_D = (120 << 16) | 5, ++ MOV_CH_LAYOUT_MPEG_5_1_A = (121 << 16) | 6, ++ MOV_CH_LAYOUT_MPEG_5_1_B = (122 << 16) | 6, ++ MOV_CH_LAYOUT_MPEG_5_1_C = (123 << 16) | 6, ++ MOV_CH_LAYOUT_MPEG_5_1_D = (124 << 16) | 6, ++ MOV_CH_LAYOUT_MPEG_6_1_A = (125 << 16) | 7, ++ MOV_CH_LAYOUT_MPEG_7_1_A = (126 << 16) | 8, ++ MOV_CH_LAYOUT_MPEG_7_1_B = (127 << 16) | 8, ++ MOV_CH_LAYOUT_MPEG_7_1_C = (128 << 16) | 8, ++ MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1 = (129 << 16) | 8, ++ MOV_CH_LAYOUT_SMPTE_DTV = (130 << 16) | 8, ++ MOV_CH_LAYOUT_ITU_2_1 = (131 << 16) | 3, ++ MOV_CH_LAYOUT_ITU_2_2 = (132 << 16) | 4, ++ MOV_CH_LAYOUT_DVD_4 = (133 << 16) | 3, ++ MOV_CH_LAYOUT_DVD_5 = (134 << 16) | 4, ++ MOV_CH_LAYOUT_DVD_6 = (135 << 16) | 5, ++ MOV_CH_LAYOUT_DVD_10 = (136 << 16) | 4, ++ MOV_CH_LAYOUT_DVD_11 = (137 << 16) | 5, ++ MOV_CH_LAYOUT_DVD_18 = (138 << 16) | 5, ++ MOV_CH_LAYOUT_AUDIOUNIT_6_0 = (139 << 16) | 6, ++ MOV_CH_LAYOUT_AUDIOUNIT_7_0 = (140 << 16) | 7, ++ MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT = (148 << 16) | 7, ++ MOV_CH_LAYOUT_AAC_6_0 = (141 << 16) | 6, ++ MOV_CH_LAYOUT_AAC_6_1 = (142 << 16) | 7, ++ MOV_CH_LAYOUT_AAC_7_0 = (143 << 16) | 7, ++ MOV_CH_LAYOUT_AAC_OCTAGONAL = (144 << 16) | 8, ++ MOV_CH_LAYOUT_TMH_10_2_STD = (145 << 16) | 16, ++ MOV_CH_LAYOUT_TMH_10_2_FULL = (146 << 16) | 21, ++ MOV_CH_LAYOUT_AC3_1_0_1 = (149 << 16) | 2, ++ MOV_CH_LAYOUT_AC3_3_0 = (150 << 16) | 3, ++ MOV_CH_LAYOUT_AC3_3_1 = (151 << 16) | 4, ++ MOV_CH_LAYOUT_AC3_3_0_1 = (152 << 16) | 4, ++ MOV_CH_LAYOUT_AC3_2_1_1 = (153 << 16) | 4, ++ MOV_CH_LAYOUT_AC3_3_1_1 = (154 << 16) | 5, ++ MOV_CH_LAYOUT_EAC3_6_0_A = (155 << 16) | 6, ++ MOV_CH_LAYOUT_EAC3_7_0_A = (156 << 16) | 7, ++ MOV_CH_LAYOUT_EAC3_6_1_A = (157 << 16) | 7, ++ MOV_CH_LAYOUT_EAC3_6_1_B = (158 << 16) | 7, ++ MOV_CH_LAYOUT_EAC3_6_1_C = (159 << 16) | 7, ++ MOV_CH_LAYOUT_EAC3_7_1_A = (160 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_B = (161 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_C = (162 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_D = (163 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_E = (164 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_F = (165 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_G = (166 << 16) | 8, ++ MOV_CH_LAYOUT_EAC3_7_1_H = (167 << 16) | 8, ++ MOV_CH_LAYOUT_DTS_3_1 = (168 << 16) | 4, ++ MOV_CH_LAYOUT_DTS_4_1 = (169 << 16) | 5, ++ MOV_CH_LAYOUT_DTS_6_0_A = (170 << 16) | 6, ++ MOV_CH_LAYOUT_DTS_6_0_B = (171 << 16) | 6, ++ MOV_CH_LAYOUT_DTS_6_0_C = (172 << 16) | 6, ++ MOV_CH_LAYOUT_DTS_6_1_A = (173 << 16) | 7, ++ MOV_CH_LAYOUT_DTS_6_1_B = (174 << 16) | 7, ++ MOV_CH_LAYOUT_DTS_6_1_C = (175 << 16) | 7, ++ MOV_CH_LAYOUT_DTS_6_1_D = (182 << 16) | 7, ++ MOV_CH_LAYOUT_DTS_7_0 = (176 << 16) | 7, ++ MOV_CH_LAYOUT_DTS_7_1 = (177 << 16) | 8, ++ MOV_CH_LAYOUT_DTS_8_0_A = (178 << 16) | 8, ++ MOV_CH_LAYOUT_DTS_8_0_B = (179 << 16) | 8, ++ MOV_CH_LAYOUT_DTS_8_1_A = (180 << 16) | 9, ++ MOV_CH_LAYOUT_DTS_8_1_B = (181 << 16) | 9, ++}; ++ ++struct MovChannelLayoutMap { ++ uint32_t tag; ++ uint64_t layout; ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_misc[] = { ++ { MOV_CH_LAYOUT_USE_DESCRIPTIONS, 0 }, ++ { MOV_CH_LAYOUT_USE_BITMAP, 0 }, ++ { MOV_CH_LAYOUT_DISCRETEINORDER, 0 }, ++ { MOV_CH_LAYOUT_UNKNOWN, 0 }, ++ { MOV_CH_LAYOUT_TMH_10_2_STD, 0 }, // L, R, C, Vhc, Lsd, Rsd, ++ // Ls, Rs, Vhl, Vhr, Lw, Rw, ++ // Csd, Cs, LFE1, LFE2 ++ { MOV_CH_LAYOUT_TMH_10_2_FULL, 0 }, // L, R, C, Vhc, Lsd, Rsd, ++ // Ls, Rs, Vhl, Vhr, Lw, Rw, ++ // Csd, Cs, LFE1, LFE2, Lc, Rc, ++ // HI, VI, Haptic ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_1ch[] = { ++ { MOV_CH_LAYOUT_MONO, AV_CH_LAYOUT_MONO }, // C ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_2ch[] = { ++ { MOV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO }, // L, R ++ { MOV_CH_LAYOUT_STEREOHEADPHONES, AV_CH_LAYOUT_STEREO }, // L, R ++ { MOV_CH_LAYOUT_BINAURAL, AV_CH_LAYOUT_STEREO }, // L, R ++ { MOV_CH_LAYOUT_MIDSIDE, AV_CH_LAYOUT_STEREO }, // C, sides ++ { MOV_CH_LAYOUT_XY, AV_CH_LAYOUT_STEREO }, // X (left), Y (right) ++ ++ { MOV_CH_LAYOUT_MATRIXSTEREO, AV_CH_LAYOUT_STEREO_DOWNMIX }, // Lt, Rt ++ ++ { MOV_CH_LAYOUT_AC3_1_0_1, AV_CH_LAYOUT_MONO | // C, LFE ++ AV_CH_LOW_FREQUENCY }, ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_3ch[] = { ++ { MOV_CH_LAYOUT_MPEG_3_0_A, AV_CH_LAYOUT_SURROUND }, // L, R, C ++ { MOV_CH_LAYOUT_MPEG_3_0_B, AV_CH_LAYOUT_SURROUND }, // C, L, R ++ { MOV_CH_LAYOUT_AC3_3_0, AV_CH_LAYOUT_SURROUND }, // L, C, R ++ ++ { MOV_CH_LAYOUT_ITU_2_1, AV_CH_LAYOUT_2_1 }, // L, R, Cs ++ ++ { MOV_CH_LAYOUT_DVD_4, AV_CH_LAYOUT_2POINT1 }, // L, R, LFE ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_4ch[] = { ++ { MOV_CH_LAYOUT_AMBISONIC_B_FORMAT, 0 }, // W, X, Y, Z ++ ++ { MOV_CH_LAYOUT_QUADRAPHONIC, AV_CH_LAYOUT_QUAD }, // L, R, Rls, Rrs ++ ++ { MOV_CH_LAYOUT_MPEG_4_0_A, AV_CH_LAYOUT_4POINT0 }, // L, R, C, Cs ++ { MOV_CH_LAYOUT_MPEG_4_0_B, AV_CH_LAYOUT_4POINT0 }, // C, L, R, Cs ++ { MOV_CH_LAYOUT_AC3_3_1, AV_CH_LAYOUT_4POINT0 }, // L, C, R, Cs ++ ++ { MOV_CH_LAYOUT_ITU_2_2, AV_CH_LAYOUT_2_2 }, // L, R, Ls, Rs ++ ++ { MOV_CH_LAYOUT_DVD_5, AV_CH_LAYOUT_2_1 | // L, R, LFE, Cs ++ AV_CH_LOW_FREQUENCY }, ++ { MOV_CH_LAYOUT_AC3_2_1_1, AV_CH_LAYOUT_2_1 | // L, R, Cs, LFE ++ AV_CH_LOW_FREQUENCY }, ++ ++ { MOV_CH_LAYOUT_DVD_10, AV_CH_LAYOUT_3POINT1 }, // L, R, C, LFE ++ { MOV_CH_LAYOUT_AC3_3_0_1, AV_CH_LAYOUT_3POINT1 }, // L, C, R, LFE ++ { MOV_CH_LAYOUT_DTS_3_1, AV_CH_LAYOUT_3POINT1 }, // C, L, R, LFE ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_5ch[] = { ++ { MOV_CH_LAYOUT_PENTAGONAL, AV_CH_LAYOUT_5POINT0_BACK }, // L, R, Rls, Rrs, C ++ ++ { MOV_CH_LAYOUT_MPEG_5_0_A, AV_CH_LAYOUT_5POINT0 }, // L, R, C, Ls, Rs ++ { MOV_CH_LAYOUT_MPEG_5_0_B, AV_CH_LAYOUT_5POINT0 }, // L, R, Ls, Rs, C ++ { MOV_CH_LAYOUT_MPEG_5_0_C, AV_CH_LAYOUT_5POINT0 }, // L, C, R, Ls, Rs ++ { MOV_CH_LAYOUT_MPEG_5_0_D, AV_CH_LAYOUT_5POINT0 }, // C, L, R, Ls, Rs ++ ++ { MOV_CH_LAYOUT_DVD_6, AV_CH_LAYOUT_2_2 | // L, R, LFE, Ls, Rs ++ AV_CH_LOW_FREQUENCY }, ++ { MOV_CH_LAYOUT_DVD_18, AV_CH_LAYOUT_2_2 | // L, R, Ls, Rs, LFE ++ AV_CH_LOW_FREQUENCY }, ++ ++ { MOV_CH_LAYOUT_DVD_11, AV_CH_LAYOUT_4POINT1 }, // L, R, C, LFE, Cs ++ { MOV_CH_LAYOUT_AC3_3_1_1, AV_CH_LAYOUT_4POINT1 }, // L, C, R, Cs, LFE ++ { MOV_CH_LAYOUT_DTS_4_1, AV_CH_LAYOUT_4POINT1 }, // C, L, R, Cs, LFE ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_6ch[] = { ++ { MOV_CH_LAYOUT_HEXAGONAL, AV_CH_LAYOUT_HEXAGONAL }, // L, R, Rls, Rrs, C, Cs ++ { MOV_CH_LAYOUT_DTS_6_0_C, AV_CH_LAYOUT_HEXAGONAL }, // C, Cs, L, R, Rls, Rrs ++ ++ { MOV_CH_LAYOUT_MPEG_5_1_A, AV_CH_LAYOUT_5POINT1 }, // L, R, C, LFE, Ls, Rs ++ { MOV_CH_LAYOUT_MPEG_5_1_B, AV_CH_LAYOUT_5POINT1 }, // L, R, Ls, Rs, C, LFE ++ { MOV_CH_LAYOUT_MPEG_5_1_C, AV_CH_LAYOUT_5POINT1 }, // L, C, R, Ls, Rs, LFE ++ { MOV_CH_LAYOUT_MPEG_5_1_D, AV_CH_LAYOUT_5POINT1 }, // C, L, R, Ls, Rs, LFE ++ ++ { MOV_CH_LAYOUT_AUDIOUNIT_6_0, AV_CH_LAYOUT_6POINT0 }, // L, R, Ls, Rs, C, Cs ++ { MOV_CH_LAYOUT_AAC_6_0, AV_CH_LAYOUT_6POINT0 }, // C, L, R, Ls, Rs, Cs ++ { MOV_CH_LAYOUT_EAC3_6_0_A, AV_CH_LAYOUT_6POINT0 }, // L, C, R, Ls, Rs, Cs ++ ++ { MOV_CH_LAYOUT_DTS_6_0_A, AV_CH_LAYOUT_6POINT0_FRONT }, // Lc, Rc, L, R, Ls, Rs ++ ++ { MOV_CH_LAYOUT_DTS_6_0_B, AV_CH_LAYOUT_5POINT0_BACK | // C, L, R, Rls, Rrs, Ts ++ AV_CH_TOP_CENTER }, ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_7ch[] = { ++ { MOV_CH_LAYOUT_MPEG_6_1_A, AV_CH_LAYOUT_6POINT1 }, // L, R, C, LFE, Ls, Rs, Cs ++ { MOV_CH_LAYOUT_AAC_6_1, AV_CH_LAYOUT_6POINT1 }, // C, L, R, Ls, Rs, Cs, LFE ++ { MOV_CH_LAYOUT_EAC3_6_1_A, AV_CH_LAYOUT_6POINT1 }, // L, C, R, Ls, Rs, LFE, Cs ++ { MOV_CH_LAYOUT_DTS_6_1_D, AV_CH_LAYOUT_6POINT1 }, // C, L, R, Ls, Rs, LFE, Cs ++ ++ { MOV_CH_LAYOUT_AUDIOUNIT_7_0, AV_CH_LAYOUT_7POINT0 }, // L, R, Ls, Rs, C, Rls, Rrs ++ { MOV_CH_LAYOUT_AAC_7_0, AV_CH_LAYOUT_7POINT0 }, // C, L, R, Ls, Rs, Rls, Rrs ++ { MOV_CH_LAYOUT_EAC3_7_0_A, AV_CH_LAYOUT_7POINT0 }, // L, C, R, Ls, Rs, Rls, Rrs ++ ++ { MOV_CH_LAYOUT_AUDIOUNIT_7_0_FRONT, AV_CH_LAYOUT_7POINT0_FRONT }, // L, R, Ls, Rs, C, Lc, Rc ++ { MOV_CH_LAYOUT_DTS_7_0, AV_CH_LAYOUT_7POINT0_FRONT }, // Lc, C, Rc, L, R, Ls, Rs ++ ++ { MOV_CH_LAYOUT_EAC3_6_1_B, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Ts ++ AV_CH_TOP_CENTER }, ++ ++ { MOV_CH_LAYOUT_EAC3_6_1_C, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Vhc ++ AV_CH_TOP_FRONT_CENTER }, ++ ++ { MOV_CH_LAYOUT_DTS_6_1_A, AV_CH_LAYOUT_6POINT1_FRONT }, // Lc, Rc, L, R, Ls, Rs, LFE ++ ++ { MOV_CH_LAYOUT_DTS_6_1_B, AV_CH_LAYOUT_5POINT1_BACK | // C, L, R, Rls, Rrs, Ts, LFE ++ AV_CH_TOP_CENTER }, ++ ++ { MOV_CH_LAYOUT_DTS_6_1_C, AV_CH_LAYOUT_6POINT1_BACK }, // C, Cs, L, R, Rls, Rrs, LFE ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_8ch[] = { ++ { MOV_CH_LAYOUT_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL }, // L, R, Rls, Rrs, C, Cs, Ls, Rs ++ { MOV_CH_LAYOUT_AAC_OCTAGONAL, AV_CH_LAYOUT_OCTAGONAL }, // C, L, R, Ls, Rs, Rls, Rrs, Cs ++ ++ { MOV_CH_LAYOUT_CUBE, AV_CH_LAYOUT_QUAD | // L, R, Rls, Rrs, Vhl, Vhr, Rlt, Rrt ++ AV_CH_TOP_FRONT_LEFT | ++ AV_CH_TOP_FRONT_RIGHT | ++ AV_CH_TOP_BACK_LEFT | ++ AV_CH_TOP_BACK_RIGHT }, ++ ++ { MOV_CH_LAYOUT_MPEG_7_1_A, AV_CH_LAYOUT_7POINT1_WIDE }, // L, R, C, LFE, Ls, Rs, Lc, Rc ++ { MOV_CH_LAYOUT_MPEG_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE }, // C, Lc, Rc, L, R, Ls, Rs, LFE ++ { MOV_CH_LAYOUT_EMAGIC_DEFAULT_7_1, AV_CH_LAYOUT_7POINT1_WIDE }, // L, R, Ls, Rs, C, LFE, Lc, Rc ++ { MOV_CH_LAYOUT_EAC3_7_1_B, AV_CH_LAYOUT_7POINT1_WIDE }, // L, C, R, Ls, Rs, LFE, Lc, Rc ++ { MOV_CH_LAYOUT_DTS_7_1, AV_CH_LAYOUT_7POINT1_WIDE }, // Lc, C, Rc, L, R, Ls, Rs, LFE ++ ++ { MOV_CH_LAYOUT_MPEG_7_1_C, AV_CH_LAYOUT_7POINT1 }, // L, R, C, LFE, Ls, Rs, Rls, Rrs ++ { MOV_CH_LAYOUT_EAC3_7_1_A, AV_CH_LAYOUT_7POINT1 }, // L, C, R, Ls, Rs, LFE, Rls, Rrs ++ ++ { MOV_CH_LAYOUT_SMPTE_DTV, AV_CH_LAYOUT_5POINT1 | // L, R, C, LFE, Ls, Rs, Lt, Rt ++ AV_CH_LAYOUT_STEREO_DOWNMIX }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_C, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Lsd, Rsd ++ AV_CH_SURROUND_DIRECT_LEFT | ++ AV_CH_SURROUND_DIRECT_RIGHT }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_D, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Lw, Rw ++ AV_CH_WIDE_LEFT | ++ AV_CH_WIDE_RIGHT }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_E, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Vhl, Vhr ++ AV_CH_TOP_FRONT_LEFT | ++ AV_CH_TOP_FRONT_RIGHT }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_F, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Cs, Ts ++ AV_CH_BACK_CENTER | ++ AV_CH_TOP_CENTER }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_G, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Cs, Vhc ++ AV_CH_BACK_CENTER | ++ AV_CH_TOP_FRONT_CENTER }, ++ ++ { MOV_CH_LAYOUT_EAC3_7_1_H, AV_CH_LAYOUT_5POINT1 | // L, C, R, Ls, Rs, LFE, Ts, Vhc ++ AV_CH_TOP_CENTER | ++ AV_CH_TOP_FRONT_CENTER }, ++ ++ { MOV_CH_LAYOUT_DTS_8_0_A, AV_CH_LAYOUT_2_2 | // Lc, Rc, L, R, Ls, Rs, Rls, Rrs ++ AV_CH_BACK_LEFT | ++ AV_CH_BACK_RIGHT | ++ AV_CH_FRONT_LEFT_OF_CENTER | ++ AV_CH_FRONT_RIGHT_OF_CENTER }, ++ ++ { MOV_CH_LAYOUT_DTS_8_0_B, AV_CH_LAYOUT_5POINT0 | // Lc, C, Rc, L, R, Ls, Cs, Rs ++ AV_CH_FRONT_LEFT_OF_CENTER | ++ AV_CH_FRONT_RIGHT_OF_CENTER | ++ AV_CH_BACK_CENTER }, ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap mov_ch_layout_map_9ch[] = { ++ { MOV_CH_LAYOUT_DTS_8_1_A, AV_CH_LAYOUT_2_2 | // Lc, Rc, L, R, Ls, Rs, Rls, Rrs, LFE ++ AV_CH_BACK_LEFT | ++ AV_CH_BACK_RIGHT | ++ AV_CH_FRONT_LEFT_OF_CENTER | ++ AV_CH_FRONT_RIGHT_OF_CENTER | ++ AV_CH_LOW_FREQUENCY }, ++ ++ { MOV_CH_LAYOUT_DTS_8_1_B, AV_CH_LAYOUT_7POINT1_WIDE | // Lc, C, Rc, L, R, Ls, Cs, Rs, LFE ++ AV_CH_BACK_CENTER }, ++ { 0, 0 }, ++}; ++ ++static const struct MovChannelLayoutMap *mov_ch_layout_map[] = { ++ mov_ch_layout_map_misc, ++ mov_ch_layout_map_1ch, ++ mov_ch_layout_map_2ch, ++ mov_ch_layout_map_3ch, ++ mov_ch_layout_map_4ch, ++ mov_ch_layout_map_5ch, ++ mov_ch_layout_map_6ch, ++ mov_ch_layout_map_7ch, ++ mov_ch_layout_map_8ch, ++ mov_ch_layout_map_9ch, ++}; ++ ++static const enum MovChannelLayoutTag mov_ch_layouts_aac[] = { ++ MOV_CH_LAYOUT_MONO, ++ MOV_CH_LAYOUT_STEREO, ++ MOV_CH_LAYOUT_AC3_1_0_1, ++ MOV_CH_LAYOUT_MPEG_3_0_B, ++ MOV_CH_LAYOUT_ITU_2_1, ++ MOV_CH_LAYOUT_DVD_4, ++ MOV_CH_LAYOUT_QUADRAPHONIC, ++ MOV_CH_LAYOUT_MPEG_4_0_B, ++ MOV_CH_LAYOUT_ITU_2_2, ++ MOV_CH_LAYOUT_AC3_2_1_1, ++ MOV_CH_LAYOUT_DTS_3_1, ++ MOV_CH_LAYOUT_MPEG_5_0_D, ++ MOV_CH_LAYOUT_DVD_18, ++ MOV_CH_LAYOUT_DTS_4_1, ++ MOV_CH_LAYOUT_MPEG_5_1_D, ++ MOV_CH_LAYOUT_AAC_6_0, ++ MOV_CH_LAYOUT_DTS_6_0_A, ++ MOV_CH_LAYOUT_AAC_6_1, ++ MOV_CH_LAYOUT_AAC_7_0, ++ MOV_CH_LAYOUT_DTS_6_1_A, ++ MOV_CH_LAYOUT_AAC_OCTAGONAL, ++ MOV_CH_LAYOUT_MPEG_7_1_B, ++ MOV_CH_LAYOUT_DTS_8_0_A, ++ 0, ++}; ++ ++static const enum MovChannelLayoutTag mov_ch_layouts_ac3[] = { ++ MOV_CH_LAYOUT_MONO, ++ MOV_CH_LAYOUT_STEREO, ++ MOV_CH_LAYOUT_AC3_1_0_1, ++ MOV_CH_LAYOUT_AC3_3_0, ++ MOV_CH_LAYOUT_ITU_2_1, ++ MOV_CH_LAYOUT_DVD_4, ++ MOV_CH_LAYOUT_AC3_3_1, ++ MOV_CH_LAYOUT_ITU_2_2, ++ MOV_CH_LAYOUT_AC3_2_1_1, ++ MOV_CH_LAYOUT_AC3_3_0_1, ++ MOV_CH_LAYOUT_MPEG_5_0_C, ++ MOV_CH_LAYOUT_DVD_18, ++ MOV_CH_LAYOUT_AC3_3_1_1, ++ MOV_CH_LAYOUT_MPEG_5_1_C, ++ 0, ++}; ++ ++static const enum MovChannelLayoutTag mov_ch_layouts_alac[] = { ++ MOV_CH_LAYOUT_MONO, ++ MOV_CH_LAYOUT_STEREO, ++ MOV_CH_LAYOUT_MPEG_3_0_B, ++ MOV_CH_LAYOUT_MPEG_4_0_B, ++ MOV_CH_LAYOUT_MPEG_5_0_D, ++ MOV_CH_LAYOUT_MPEG_5_1_D, ++ MOV_CH_LAYOUT_AAC_6_1, ++ MOV_CH_LAYOUT_MPEG_7_1_B, ++ 0, ++}; ++ ++static const struct { ++ enum CodecID codec_id; ++ const enum MovChannelLayoutTag *layouts; ++} mov_codec_ch_layouts[] = { ++ { CODEC_ID_AAC, mov_ch_layouts_aac }, ++ { CODEC_ID_AC3, mov_ch_layouts_ac3 }, ++ { CODEC_ID_ALAC, mov_ch_layouts_alac }, ++ { CODEC_ID_NONE, NULL }, ++}; ++ ++uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap) ++{ ++ int i, channels; ++ const struct MovChannelLayoutMap *layout_map; ++ ++ /* use ff_mov_get_channel_label() to build a layout instead */ ++ if (tag == MOV_CH_LAYOUT_USE_DESCRIPTIONS) ++ return 0; ++ ++ /* handle the use of the channel bitmap */ ++ if (tag == MOV_CH_LAYOUT_USE_BITMAP) ++ return bitmap < 0x40000 ? bitmap : 0; ++ ++ /* get the layout map based on the channel count for the specified layout tag */ ++ channels = tag & 0xFFFF; ++ if (channels > 9) ++ channels = 0; ++ layout_map = mov_ch_layout_map[channels]; ++ ++ /* find the channel layout for the specified layout tag */ ++ for (i = 0; layout_map[i].tag != 0; i++) { ++ if (layout_map[i].tag == tag) ++ break; ++ } ++ return layout_map[i].layout; ++} ++ ++uint32_t ff_mov_get_channel_label(uint32_t label) ++{ ++ if (label == 0) ++ return 0; ++ if (label <= 18) ++ return 1U << (label - 1); ++ if (label == 38) ++ return AV_CH_STEREO_LEFT; ++ if (label == 39) ++ return AV_CH_STEREO_RIGHT; ++ return 0; ++} ++ ++uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, ++ uint64_t channel_layout, ++ uint32_t *bitmap) ++{ ++ int i, j; ++ uint32_t tag = 0; ++ const enum MovChannelLayoutTag *layouts = NULL; ++ ++ /* find the layout list for the specified codec */ ++ for (i = 0; mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE; i++) { ++ if (mov_codec_ch_layouts[i].codec_id == codec_id) ++ break; ++ } ++ if (mov_codec_ch_layouts[i].codec_id != CODEC_ID_NONE) ++ layouts = mov_codec_ch_layouts[i].layouts; ++ ++ if (layouts) { ++ int channels; ++ const struct MovChannelLayoutMap *layout_map; ++ ++ /* get the layout map based on the channel count */ ++ channels = av_get_channel_layout_nb_channels(channel_layout); ++ if (channels > 9) ++ channels = 0; ++ layout_map = mov_ch_layout_map[channels]; ++ ++ /* find the layout tag for the specified channel layout */ ++ for (i = 0; layouts[i] != 0; i++) { ++ if (layouts[i] & 0xFFFF != channels) ++ continue; ++ for (j = 0; layout_map[j].tag != 0; j++) { ++ if (layout_map[j].tag == layouts[i] && ++ layout_map[j].layout == channel_layout) ++ break; ++ } ++ if (layout_map[j].tag) ++ break; ++ } ++ tag = layouts[i]; ++ } ++ ++ /* if no tag was found, use channel bitmap as a backup if possible */ ++ if (tag == 0 && channel_layout > 0 && channel_layout < 0x40000) { ++ tag = MOV_CH_LAYOUT_USE_BITMAP; ++ *bitmap = (uint32_t)channel_layout; ++ } else ++ *bitmap = 0; ++ ++ /* TODO: set channel descriptions as a secondary backup */ ++ ++ return tag; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov_chan.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov_chan.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mov_chan.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mov_chan.h 2012-05-14 14:08:55.039354171 +0200 +@@ -0,0 +1,63 @@ ++/* ++ * Copyright (c) 2011 Justin Ruggles ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * mov 'chan' tag reading/writing. ++ * @author Justin Ruggles ++ */ ++ ++#ifndef AVFORMAT_MOV_CHAN_H ++#define AVFORMAT_MOV_CHAN_H ++ ++#include ++ ++#include "libavcodec/avcodec.h" ++ ++/** ++ * Get the channel layout for the specified channel layout tag. ++ * ++ * @param[in] tag channel layout tag ++ * @param[out] bitmap channel bitmap (only used if needed) ++ * @return channel layout ++ */ ++uint64_t ff_mov_get_channel_layout(uint32_t tag, uint32_t bitmap); ++ ++/** ++ * Get the channel layout for the specified channel layout tag. ++ * ++ * @param[in] tag channel label ++ * @return channel layout mask fragment ++ */ ++uint32_t ff_mov_get_channel_label(uint32_t label); ++ ++/** ++ * Get the channel layout tag for the specified codec id and channel layout. ++ * If the layout tag was not found, use a channel bitmap if possible. ++ * ++ * @param[in] codec_id codec id ++ * @param[in] channel_layout channel layout ++ * @param[out] bitmap channel bitmap ++ * @return channel layout tag ++ */ ++uint32_t ff_mov_get_channel_layout_tag(enum CodecID codec_id, ++ uint64_t channel_layout, ++ uint32_t *bitmap); ++ ++#endif /* AVFORMAT_MOV_CHAN_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenc.c 2012-05-14 14:08:55.049354372 +0200 +@@ -23,6 +23,7 @@ + + #include "movenc.h" + #include "avformat.h" ++#include "avio_internal.h" + #include "riff.h" + #include "avio.h" + #include "isom.h" +@@ -31,54 +32,88 @@ + #include "libavcodec/put_bits.h" + #include "internal.h" + #include "libavutil/avstring.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" ++#include "libavutil/dict.h" ++#include "rtpenc.h" ++#include "mov_chan.h" + + #undef NDEBUG + #include + ++static const AVOption options[] = { ++ { "movflags", "MOV muxer flags", offsetof(MOVMuxContext, flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ { "rtphint", "Add RTP hint tracks", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_RTP_HINT}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ { "moov_size", "maximum moov size so it can be placed at the begin", offsetof(MOVMuxContext, reserved_moov_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, 0 }, ++ { "empty_moov", "Make the initial moov atom empty (not supported by QuickTime)", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_EMPTY_MOOV}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ { "frag_keyframe", "Fragment at video keyframes", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_FRAG_KEYFRAME}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ { "separate_moof", "Write separate moof/mdat atoms for each track", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_SEPARATE_MOOF}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ { "frag_custom", "Flush fragments on caller requests", 0, AV_OPT_TYPE_CONST, {.dbl = FF_MOV_FLAG_FRAG_CUSTOM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "movflags" }, ++ FF_RTP_FLAG_OPTS(MOVMuxContext, rtp_flags), ++ { "skip_iods", "Skip writing iods atom.", offsetof(MOVMuxContext, iods_skip), AV_OPT_TYPE_INT, {.dbl = 1}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "iods_audio_profile", "iods audio profile atom.", offsetof(MOVMuxContext, iods_audio_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "iods_video_profile", "iods video profile atom.", offsetof(MOVMuxContext, iods_video_profile), AV_OPT_TYPE_INT, {.dbl = -1}, -1, 255, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "frag_duration", "Maximum fragment duration", offsetof(MOVMuxContext, max_fragment_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "frag_size", "Maximum fragment size", offsetof(MOVMuxContext, max_fragment_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "ism_lookahead", "Number of lookahead entries for ISM files", offsetof(MOVMuxContext, ism_lookahead), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, ++ { NULL }, ++}; ++ ++#define MOV_CLASS(flavor)\ ++static const AVClass flavor ## _muxer_class = {\ ++ .class_name = #flavor " muxer",\ ++ .item_name = av_default_item_name,\ ++ .option = options,\ ++ .version = LIBAVUTIL_VERSION_INT,\ ++}; ++ + //FIXME support 64 bit variant with wide placeholders +-static int64_t updateSize(ByteIOContext *pb, int64_t pos) ++static int64_t updateSize(AVIOContext *pb, int64_t pos) + { +- int64_t curpos = url_ftell(pb); +- url_fseek(pb, pos, SEEK_SET); +- put_be32(pb, curpos - pos); /* rewrite size */ +- url_fseek(pb, curpos, SEEK_SET); ++ int64_t curpos = avio_tell(pb); ++ avio_seek(pb, pos, SEEK_SET); ++ avio_wb32(pb, curpos - pos); /* rewrite size */ ++ avio_seek(pb, curpos, SEEK_SET); + + return curpos - pos; + } + + /* Chunk offset atom */ +-static int mov_write_stco_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_stco_tag(AVIOContext *pb, MOVTrack *track) + { + int i; + int mode64 = 0; // use 32 bit size variant if possible +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ + if (pos > UINT32_MAX) { + mode64 = 1; +- put_tag(pb, "co64"); ++ ffio_wfourcc(pb, "co64"); + } else +- put_tag(pb, "stco"); +- put_be32(pb, 0); /* version & flags */ +- put_be32(pb, track->entry); /* entry count */ ++ ffio_wfourcc(pb, "stco"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb32(pb, track->chunkCount); /* entry count */ + for (i=0; ientry; i++) { ++ if(!track->cluster[i].chunkNum) ++ continue; + if(mode64 == 1) +- put_be64(pb, track->cluster[i].pos); ++ avio_wb64(pb, track->cluster[i].pos); + else +- put_be32(pb, track->cluster[i].pos); ++ avio_wb32(pb, track->cluster[i].pos); + } + return updateSize(pb, pos); + } + + /* Sample size atom */ +-static int mov_write_stsz_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_stsz_tag(AVIOContext *pb, MOVTrack *track) + { + int equalChunks = 1; + int i, j, entries = 0, tst = -1, oldtst = -1; + +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "stsz"); +- put_be32(pb, 0); /* version & flags */ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "stsz"); ++ avio_wb32(pb, 0); /* version & flags */ + + for (i=0; ientry; i++) { + tst = track->cluster[i].size/track->cluster[i].entries; +@@ -88,17 +123,18 @@ + oldtst = tst; + entries += track->cluster[i].entries; + } +- if (equalChunks) { +- int sSize = track->cluster[0].size/track->cluster[0].entries; +- put_be32(pb, sSize); // sample size +- put_be32(pb, entries); // sample count ++ if (equalChunks && track->entry) { ++ int sSize = track->entry ? track->cluster[0].size/track->cluster[0].entries : 0; ++ sSize = FFMAX(1, sSize); // adpcm mono case could make sSize == 0 ++ avio_wb32(pb, sSize); // sample size ++ avio_wb32(pb, entries); // sample count + } + else { +- put_be32(pb, 0); // sample size +- put_be32(pb, entries); // sample count ++ avio_wb32(pb, 0); // sample size ++ avio_wb32(pb, entries); // sample count + for (i=0; ientry; i++) { + for (j=0; jcluster[i].entries; j++) { +- put_be32(pb, track->cluster[i].size / ++ avio_wb32(pb, track->cluster[i].size / + track->cluster[i].entries); + } + } +@@ -107,74 +143,74 @@ + } + + /* Sample to chunk atom */ +-static int mov_write_stsc_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_stsc_tag(AVIOContext *pb, MOVTrack *track) + { + int index = 0, oldval = -1, i; + int64_t entryPos, curpos; + +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "stsc"); +- put_be32(pb, 0); // version & flags +- entryPos = url_ftell(pb); +- put_be32(pb, track->entry); // entry count ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "stsc"); ++ avio_wb32(pb, 0); // version & flags ++ entryPos = avio_tell(pb); ++ avio_wb32(pb, track->chunkCount); // entry count + for (i=0; ientry; i++) { +- if(oldval != track->cluster[i].samplesInChunk) ++ if(oldval != track->cluster[i].samplesInChunk && track->cluster[i].chunkNum) + { +- put_be32(pb, i+1); // first chunk +- put_be32(pb, track->cluster[i].samplesInChunk); // samples per chunk +- put_be32(pb, 0x1); // sample description index ++ avio_wb32(pb, track->cluster[i].chunkNum); // first chunk ++ avio_wb32(pb, track->cluster[i].samplesInChunk); // samples per chunk ++ avio_wb32(pb, 0x1); // sample description index + oldval = track->cluster[i].samplesInChunk; + index++; + } + } +- curpos = url_ftell(pb); +- url_fseek(pb, entryPos, SEEK_SET); +- put_be32(pb, index); // rewrite size +- url_fseek(pb, curpos, SEEK_SET); ++ curpos = avio_tell(pb); ++ avio_seek(pb, entryPos, SEEK_SET); ++ avio_wb32(pb, index); // rewrite size ++ avio_seek(pb, curpos, SEEK_SET); + + return updateSize(pb, pos); + } + + /* Sync sample atom */ +-static int mov_write_stss_tag(ByteIOContext *pb, MOVTrack *track, uint32_t flag) ++static int mov_write_stss_tag(AVIOContext *pb, MOVTrack *track, uint32_t flag) + { + int64_t curpos, entryPos; + int i, index = 0; +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); // size +- put_tag(pb, flag == MOV_SYNC_SAMPLE ? "stss" : "stps"); +- put_be32(pb, 0); // version & flags +- entryPos = url_ftell(pb); +- put_be32(pb, track->entry); // entry count ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); // size ++ ffio_wfourcc(pb, flag == MOV_SYNC_SAMPLE ? "stss" : "stps"); ++ avio_wb32(pb, 0); // version & flags ++ entryPos = avio_tell(pb); ++ avio_wb32(pb, track->entry); // entry count + for (i=0; ientry; i++) { + if (track->cluster[i].flags & flag) { +- put_be32(pb, i+1); ++ avio_wb32(pb, i+1); + index++; + } + } +- curpos = url_ftell(pb); +- url_fseek(pb, entryPos, SEEK_SET); +- put_be32(pb, index); // rewrite size +- url_fseek(pb, curpos, SEEK_SET); ++ curpos = avio_tell(pb); ++ avio_seek(pb, entryPos, SEEK_SET); ++ avio_wb32(pb, index); // rewrite size ++ avio_seek(pb, curpos, SEEK_SET); + return updateSize(pb, pos); + } + +-static int mov_write_amr_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_amr_tag(AVIOContext *pb, MOVTrack *track) + { +- put_be32(pb, 0x11); /* size */ +- if (track->mode == MODE_MOV) put_tag(pb, "samr"); +- else put_tag(pb, "damr"); +- put_tag(pb, "FFMP"); +- put_byte(pb, 0); /* decoder version */ ++ avio_wb32(pb, 0x11); /* size */ ++ if (track->mode == MODE_MOV) ffio_wfourcc(pb, "samr"); ++ else ffio_wfourcc(pb, "damr"); ++ ffio_wfourcc(pb, "FFMP"); ++ avio_w8(pb, 0); /* decoder version */ + +- put_be16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ +- put_byte(pb, 0x00); /* Mode change period (no restriction) */ +- put_byte(pb, 0x01); /* Frames per sample */ ++ avio_wb16(pb, 0x81FF); /* Mode set (all modes for AMR_NB) */ ++ avio_w8(pb, 0x00); /* Mode change period (no restriction) */ ++ avio_w8(pb, 0x01); /* Frames per sample */ + return 0x11; + } + +-static int mov_write_ac3_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_ac3_tag(AVIOContext *pb, MOVTrack *track) + { + GetBitContext gbc; + PutBitContext pbc; +@@ -184,10 +220,10 @@ + if (track->vosLen < 7) + return -1; + +- put_be32(pb, 11); +- put_tag(pb, "dac3"); ++ avio_wb32(pb, 11); ++ ffio_wfourcc(pb, "dac3"); + +- init_get_bits(&gbc, track->vosData+4, track->vosLen-4); ++ init_get_bits(&gbc, track->vosData+4, (track->vosLen-4) * 8); + fscod = get_bits(&gbc, 2); + frmsizecod = get_bits(&gbc, 6); + bsid = get_bits(&gbc, 5); +@@ -213,59 +249,61 @@ + put_bits(&pbc, 5, 0); // reserved + + flush_put_bits(&pbc); +- put_buffer(pb, buf, sizeof(buf)); ++ avio_write(pb, buf, sizeof(buf)); + + return 11; + } + + /** + * This function writes extradata "as is". +- * Extradata must be formated like a valid atom (with size and tag) ++ * Extradata must be formatted like a valid atom (with size and tag). + */ +-static int mov_write_extradata_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_extradata_tag(AVIOContext *pb, MOVTrack *track) + { +- put_buffer(pb, track->enc->extradata, track->enc->extradata_size); ++ avio_write(pb, track->enc->extradata, track->enc->extradata_size); + return track->enc->extradata_size; + } + +-static int mov_write_enda_tag(ByteIOContext *pb) ++static int mov_write_enda_tag(AVIOContext *pb) + { +- put_be32(pb, 10); +- put_tag(pb, "enda"); +- put_be16(pb, 1); /* little endian */ ++ avio_wb32(pb, 10); ++ ffio_wfourcc(pb, "enda"); ++ avio_wb16(pb, 1); /* little endian */ + return 10; + } + +-static unsigned int descrLength(unsigned int len) ++static void putDescr(AVIOContext *pb, int tag, unsigned int size) + { +- int i; +- for(i=1; len>>(7*i); i++); +- return len + 1 + i; ++ int i = 3; ++ avio_w8(pb, tag); ++ for(; i>0; i--) ++ avio_w8(pb, (size>>(7*i)) | 0x80); ++ avio_w8(pb, size & 0x7F); + } + +-static void putDescr(ByteIOContext *pb, int tag, unsigned int size) ++static unsigned compute_avg_bitrate(MOVTrack *track) + { +- int i= descrLength(size) - size - 2; +- put_byte(pb, tag); +- for(; i>0; i--) +- put_byte(pb, (size>>(7*i)) | 0x80); +- put_byte(pb, size & 0x7F); ++ uint64_t size = 0; ++ int i; ++ for (i = 0; i < track->entry; i++) ++ size += track->cluster[i].size; ++ return size * 8 * track->timescale / track->trackDuration; + } + +-static int mov_write_esds_tag(ByteIOContext *pb, MOVTrack *track) // Basic ++static int mov_write_esds_tag(AVIOContext *pb, MOVTrack *track) // Basic + { +- int64_t pos = url_ftell(pb); +- int decoderSpecificInfoLen = track->vosLen ? descrLength(track->vosLen):0; ++ int64_t pos = avio_tell(pb); ++ int decoderSpecificInfoLen = track->vosLen ? 5+track->vosLen : 0; ++ unsigned avg_bitrate; + +- put_be32(pb, 0); // size +- put_tag(pb, "esds"); +- put_be32(pb, 0); // Version ++ avio_wb32(pb, 0); // size ++ ffio_wfourcc(pb, "esds"); ++ avio_wb32(pb, 0); // Version + + // ES descriptor +- putDescr(pb, 0x03, 3 + descrLength(13 + decoderSpecificInfoLen) + +- descrLength(1)); +- put_be16(pb, track->trackID); +- put_byte(pb, 0x00); // flags (= no flags) ++ putDescr(pb, 0x03, 3 + 5+13 + decoderSpecificInfoLen + 5+1); ++ avio_wb16(pb, track->trackID); ++ avio_w8(pb, 0x00); // flags (= no flags) + + // DecoderConfig descriptor + putDescr(pb, 0x04, 13 + decoderSpecificInfoLen); +@@ -274,35 +312,34 @@ + if ((track->enc->codec_id == CODEC_ID_MP2 || + track->enc->codec_id == CODEC_ID_MP3) && + track->enc->sample_rate > 24000) +- put_byte(pb, 0x6B); // 11172-3 ++ avio_w8(pb, 0x6B); // 11172-3 + else +- put_byte(pb, ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)); ++ avio_w8(pb, ff_codec_get_tag(ff_mp4_obj_type, track->enc->codec_id)); + + // the following fields is made of 6 bits to identify the streamtype (4 for video, 5 for audio) + // plus 1 bit to indicate upstream and 1 bit set to 1 (reserved) + if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO) +- put_byte(pb, 0x15); // flags (= Audiostream) ++ avio_w8(pb, 0x15); // flags (= Audiostream) + else +- put_byte(pb, 0x11); // flags (= Visualstream) ++ avio_w8(pb, 0x11); // flags (= Visualstream) + +- put_byte(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits) +- put_be16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB ++ avio_w8(pb, track->enc->rc_buffer_size>>(3+16)); // Buffersize DB (24 bits) ++ avio_wb16(pb, (track->enc->rc_buffer_size>>3)&0xFFFF); // Buffersize DB + +- put_be32(pb, FFMAX(track->enc->bit_rate, track->enc->rc_max_rate)); // maxbitrate (FIXME should be max rate in any 1 sec window) +- if(track->enc->rc_max_rate != track->enc->rc_min_rate || track->enc->rc_min_rate==0) +- put_be32(pb, 0); // vbr +- else +- put_be32(pb, track->enc->rc_max_rate); // avg bitrate ++ avg_bitrate = compute_avg_bitrate(track); ++ // maxbitrate (FIXME should be max rate in any 1 sec window) ++ avio_wb32(pb, FFMAX3(track->enc->bit_rate, track->enc->rc_max_rate, avg_bitrate)); ++ avio_wb32(pb, avg_bitrate); + + if (track->vosLen) { + // DecoderSpecific info descriptor + putDescr(pb, 0x05, track->vosLen); +- put_buffer(pb, track->vosData, track->vosLen); ++ avio_write(pb, track->vosData, track->vosLen); + } + + // SL descriptor + putDescr(pb, 0x06, 1); +- put_byte(pb, 0x02); ++ avio_w8(pb, 0x02); + return updateSize(pb, pos); + } + +@@ -314,38 +351,64 @@ + codec_id == CODEC_ID_PCM_F64LE; + } + +-static int mov_write_ms_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_ms_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); +- put_le32(pb, track->tag); // store it byteswapped ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); ++ avio_wl32(pb, track->tag); // store it byteswapped + track->enc->codec_tag = av_bswap16(track->tag >> 16); + ff_put_wav_header(pb, track->enc); + return updateSize(pb, pos); + } + +-static int mov_write_wave_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_chan_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); ++ uint32_t layout_tag, bitmap; ++ int64_t pos = avio_tell(pb); + +- put_be32(pb, 0); /* size */ +- put_tag(pb, "wave"); ++ layout_tag = ff_mov_get_channel_layout_tag(track->enc->codec_id, ++ track->enc->channel_layout, ++ &bitmap); ++ if (!layout_tag) { ++ av_log(track->enc, AV_LOG_WARNING, "not writing 'chan' tag due to " ++ "lack of channel information\n"); ++ return 0; ++ } + +- put_be32(pb, 12); /* size */ +- put_tag(pb, "frma"); +- put_le32(pb, track->tag); ++ avio_wb32(pb, 0); // Size ++ ffio_wfourcc(pb, "chan"); // Type ++ avio_w8(pb, 0); // Version ++ avio_wb24(pb, 0); // Flags ++ avio_wb32(pb, layout_tag); // mChannelLayoutTag ++ avio_wb32(pb, bitmap); // mChannelBitmap ++ avio_wb32(pb, 0); // mNumberChannelDescriptions ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_wave_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ int64_t pos = avio_tell(pb); ++ ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "wave"); ++ ++ avio_wb32(pb, 12); /* size */ ++ ffio_wfourcc(pb, "frma"); ++ avio_wl32(pb, track->tag); + + if (track->enc->codec_id == CODEC_ID_AAC) { + /* useless atom needed by mplayer, ipod, not needed by quicktime */ +- put_be32(pb, 12); /* size */ +- put_tag(pb, "mp4a"); +- put_be32(pb, 0); ++ avio_wb32(pb, 12); /* size */ ++ ffio_wfourcc(pb, "mp4a"); ++ avio_wb32(pb, 0); + mov_write_esds_tag(pb, track); + } else if (mov_pcm_le_gt16(track->enc->codec_id)) { + mov_write_enda_tag(pb); + } else if (track->enc->codec_id == CODEC_ID_AMR_NB) { + mov_write_amr_tag(pb, track); + } else if (track->enc->codec_id == CODEC_ID_AC3) { ++ mov_write_chan_tag(pb, track); + mov_write_ac3_tag(pb, track); + } else if (track->enc->codec_id == CODEC_ID_ALAC) { + mov_write_extradata_tag(pb, track); +@@ -354,17 +417,17 @@ + mov_write_ms_tag(pb, track); + } + +- put_be32(pb, 8); /* size */ +- put_be32(pb, 0); /* null tag */ ++ avio_wb32(pb, 8); /* size */ ++ avio_wb32(pb, 0); /* null tag */ + + return updateSize(pb, pos); + } + +-static int mov_write_glbl_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_glbl_tag(AVIOContext *pb, MOVTrack *track) + { +- put_be32(pb, track->vosLen+8); +- put_tag(pb, "glbl"); +- put_buffer(pb, track->vosData, track->vosLen); ++ avio_wb32(pb, track->vosLen+8); ++ ffio_wfourcc(pb, "glbl"); ++ avio_write(pb, track->vosData, track->vosLen); + return 8+track->vosLen; + } + +@@ -397,9 +460,9 @@ + } + } + +-static int mov_write_audio_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_audio_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + int version = 0; + uint32_t tag = track->tag; + +@@ -415,56 +478,56 @@ + } + } + +- put_be32(pb, 0); /* size */ +- put_le32(pb, tag); // store it byteswapped +- put_be32(pb, 0); /* Reserved */ +- put_be16(pb, 0); /* Reserved */ +- put_be16(pb, 1); /* Data-reference index, XXX == 1 */ ++ avio_wb32(pb, 0); /* size */ ++ avio_wl32(pb, tag); // store it byteswapped ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb16(pb, 0); /* Reserved */ ++ avio_wb16(pb, 1); /* Data-reference index, XXX == 1 */ + + /* SoundDescription */ +- put_be16(pb, version); /* Version */ +- put_be16(pb, 0); /* Revision level */ +- put_be32(pb, 0); /* Reserved */ ++ avio_wb16(pb, version); /* Version */ ++ avio_wb16(pb, 0); /* Revision level */ ++ avio_wb32(pb, 0); /* Reserved */ + + if (version == 2) { +- put_be16(pb, 3); +- put_be16(pb, 16); +- put_be16(pb, 0xfffe); +- put_be16(pb, 0); +- put_be32(pb, 0x00010000); +- put_be32(pb, 72); +- put_be64(pb, av_dbl2int(track->timescale)); +- put_be32(pb, track->enc->channels); +- put_be32(pb, 0x7F000000); +- put_be32(pb, av_get_bits_per_sample(track->enc->codec_id)); +- put_be32(pb, mov_get_lpcm_flags(track->enc->codec_id)); +- put_be32(pb, track->sampleSize); +- put_be32(pb, track->enc->frame_size); ++ avio_wb16(pb, 3); ++ avio_wb16(pb, 16); ++ avio_wb16(pb, 0xfffe); ++ avio_wb16(pb, 0); ++ avio_wb32(pb, 0x00010000); ++ avio_wb32(pb, 72); ++ avio_wb64(pb, av_double2int(track->enc->sample_rate)); ++ avio_wb32(pb, track->enc->channels); ++ avio_wb32(pb, 0x7F000000); ++ avio_wb32(pb, av_get_bits_per_sample(track->enc->codec_id)); ++ avio_wb32(pb, mov_get_lpcm_flags(track->enc->codec_id)); ++ avio_wb32(pb, track->sampleSize); ++ avio_wb32(pb, track->enc->frame_size); + } else { + if (track->mode == MODE_MOV) { +- put_be16(pb, track->enc->channels); ++ avio_wb16(pb, track->enc->channels); + if (track->enc->codec_id == CODEC_ID_PCM_U8 || + track->enc->codec_id == CODEC_ID_PCM_S8) +- put_be16(pb, 8); /* bits per sample */ ++ avio_wb16(pb, 8); /* bits per sample */ + else +- put_be16(pb, 16); +- put_be16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ ++ avio_wb16(pb, 16); ++ avio_wb16(pb, track->audio_vbr ? -2 : 0); /* compression ID */ + } else { /* reserved for mp4/3gp */ +- put_be16(pb, 2); +- put_be16(pb, 16); +- put_be16(pb, 0); ++ avio_wb16(pb, 2); ++ avio_wb16(pb, 16); ++ avio_wb16(pb, 0); + } + +- put_be16(pb, 0); /* packet size (= 0) */ +- put_be16(pb, track->timescale); /* Time scale */ +- put_be16(pb, 0); /* Reserved */ ++ avio_wb16(pb, 0); /* packet size (= 0) */ ++ avio_wb16(pb, track->enc->sample_rate); ++ avio_wb16(pb, 0); /* Reserved */ + } + + if(version == 1) { /* SoundDescription V1 extended info */ +- put_be32(pb, track->enc->frame_size); /* Samples per packet */ +- put_be32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */ +- put_be32(pb, track->sampleSize); /* Bytes per frame */ +- put_be32(pb, 2); /* Bytes per sample */ ++ avio_wb32(pb, track->enc->frame_size); /* Samples per packet */ ++ avio_wb32(pb, track->sampleSize / track->enc->channels); /* Bytes per packet */ ++ avio_wb32(pb, track->sampleSize); /* Bytes per frame */ ++ avio_wb32(pb, 2); /* Bytes per sample */ + } + + if(track->mode == MODE_MOV && +@@ -490,86 +553,86 @@ + return updateSize(pb, pos); + } + +-static int mov_write_d263_tag(ByteIOContext *pb) ++static int mov_write_d263_tag(AVIOContext *pb) + { +- put_be32(pb, 0xf); /* size */ +- put_tag(pb, "d263"); +- put_tag(pb, "FFMP"); +- put_byte(pb, 0); /* decoder version */ ++ avio_wb32(pb, 0xf); /* size */ ++ ffio_wfourcc(pb, "d263"); ++ ffio_wfourcc(pb, "FFMP"); ++ avio_w8(pb, 0); /* decoder version */ + /* FIXME use AVCodecContext level/profile, when encoder will set values */ +- put_byte(pb, 0xa); /* level */ +- put_byte(pb, 0); /* profile */ ++ avio_w8(pb, 0xa); /* level */ ++ avio_w8(pb, 0); /* profile */ + return 0xf; + } + + /* TODO: No idea about these values */ +-static int mov_write_svq3_tag(ByteIOContext *pb) ++static int mov_write_svq3_tag(AVIOContext *pb) + { +- put_be32(pb, 0x15); +- put_tag(pb, "SMI "); +- put_tag(pb, "SEQH"); +- put_be32(pb, 0x5); +- put_be32(pb, 0xe2c0211d); +- put_be32(pb, 0xc0000000); +- put_byte(pb, 0); ++ avio_wb32(pb, 0x15); ++ ffio_wfourcc(pb, "SMI "); ++ ffio_wfourcc(pb, "SEQH"); ++ avio_wb32(pb, 0x5); ++ avio_wb32(pb, 0xe2c0211d); ++ avio_wb32(pb, 0xc0000000); ++ avio_w8(pb, 0); + return 0x15; + } + +-static int mov_write_avcc_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_avcc_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + +- put_be32(pb, 0); +- put_tag(pb, "avcC"); ++ avio_wb32(pb, 0); ++ ffio_wfourcc(pb, "avcC"); + ff_isom_write_avcc(pb, track->vosData, track->vosLen); + return updateSize(pb, pos); + } + + /* also used by all avid codecs (dv, imx, meridien) and their variants */ +-static int mov_write_avid_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_avid_tag(AVIOContext *pb, MOVTrack *track) + { + int i; +- put_be32(pb, 24); /* size */ +- put_tag(pb, "ACLR"); +- put_tag(pb, "ACLR"); +- put_tag(pb, "0001"); +- put_be32(pb, 1); /* yuv 1 / rgb 2 ? */ +- put_be32(pb, 0); /* unknown */ +- +- put_be32(pb, 24); /* size */ +- put_tag(pb, "APRG"); +- put_tag(pb, "APRG"); +- put_tag(pb, "0001"); +- put_be32(pb, 1); /* unknown */ +- put_be32(pb, 0); /* unknown */ +- +- put_be32(pb, 120); /* size */ +- put_tag(pb, "ARES"); +- put_tag(pb, "ARES"); +- put_tag(pb, "0001"); +- put_be32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */ +- put_be32(pb, track->enc->width); ++ avio_wb32(pb, 24); /* size */ ++ ffio_wfourcc(pb, "ACLR"); ++ ffio_wfourcc(pb, "ACLR"); ++ ffio_wfourcc(pb, "0001"); ++ avio_wb32(pb, 2); /* yuv range: full 1 / normal 2 */ ++ avio_wb32(pb, 0); /* unknown */ ++ ++ avio_wb32(pb, 24); /* size */ ++ ffio_wfourcc(pb, "APRG"); ++ ffio_wfourcc(pb, "APRG"); ++ ffio_wfourcc(pb, "0001"); ++ avio_wb32(pb, 1); /* unknown */ ++ avio_wb32(pb, 0); /* unknown */ ++ ++ avio_wb32(pb, 120); /* size */ ++ ffio_wfourcc(pb, "ARES"); ++ ffio_wfourcc(pb, "ARES"); ++ ffio_wfourcc(pb, "0001"); ++ avio_wb32(pb, AV_RB32(track->vosData + 0x28)); /* dnxhd cid, some id ? */ ++ avio_wb32(pb, track->enc->width); + /* values below are based on samples created with quicktime and avid codecs */ + if (track->vosData[5] & 2) { // interlaced +- put_be32(pb, track->enc->height/2); +- put_be32(pb, 2); /* unknown */ +- put_be32(pb, 0); /* unknown */ +- put_be32(pb, 4); /* unknown */ ++ avio_wb32(pb, track->enc->height/2); ++ avio_wb32(pb, 2); /* unknown */ ++ avio_wb32(pb, 0); /* unknown */ ++ avio_wb32(pb, 4); /* unknown */ + } else { +- put_be32(pb, track->enc->height); +- put_be32(pb, 1); /* unknown */ +- put_be32(pb, 0); /* unknown */ ++ avio_wb32(pb, track->enc->height); ++ avio_wb32(pb, 1); /* unknown */ ++ avio_wb32(pb, 0); /* unknown */ + if (track->enc->height == 1080) +- put_be32(pb, 5); /* unknown */ ++ avio_wb32(pb, 5); /* unknown */ + else +- put_be32(pb, 6); /* unknown */ ++ avio_wb32(pb, 6); /* unknown */ + } + /* padding */ + for (i = 0; i < 10; i++) +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + + /* extra padding for stsd needed */ +- put_be32(pb, 0); ++ avio_wb32(pb, 0); + return 0; + } + +@@ -622,12 +685,23 @@ + { + int tag; + +- if (track->enc->height == 480) /* NTSC */ +- if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); +- else tag = MKTAG('d','v','c',' '); +- else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); +- else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); +- else tag = MKTAG('d','v','p','p'); ++ if (track->enc->width == 720) /* SD */ ++ if (track->enc->height == 480) /* NTSC */ ++ if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','n'); ++ else tag = MKTAG('d','v','c',' '); ++ else if (track->enc->pix_fmt == PIX_FMT_YUV422P) tag = MKTAG('d','v','5','p'); ++ else if (track->enc->pix_fmt == PIX_FMT_YUV420P) tag = MKTAG('d','v','c','p'); ++ else tag = MKTAG('d','v','p','p'); ++ else if (track->enc->height == 720) /* HD 720 line */ ++ if (track->enc->time_base.den == 50) tag = MKTAG('d','v','h','q'); ++ else tag = MKTAG('d','v','h','p'); ++ else if (track->enc->height == 1080) /* HD 1080 line */ ++ if (track->enc->time_base.den == 25) tag = MKTAG('d','v','h','5'); ++ else tag = MKTAG('d','v','h','6'); ++ else { ++ av_log(s, AV_LOG_ERROR, "unsupported height for dv codec\n"); ++ return 0; ++ } + + return tag; + } +@@ -687,7 +761,7 @@ + if (!tag) { // if no mac fcc found, try with Microsoft tags + tag = ff_codec_get_tag(ff_codec_bmp_tags, track->enc->codec_id); + if (tag) +- av_log(s, AV_LOG_INFO, "Warning, using MS style video codec tag, " ++ av_log(s, AV_LOG_WARNING, "Using MS style video codec tag, " + "the file may be unplayable!\n"); + } + } else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) { +@@ -696,7 +770,7 @@ + int ms_tag = ff_codec_get_tag(ff_codec_wav_tags, track->enc->codec_id); + if (ms_tag) { + tag = MKTAG('m', 's', ((ms_tag >> 8) & 0xff), (ms_tag & 0xff)); +- av_log(s, AV_LOG_INFO, "Warning, using MS style audio codec tag, " ++ av_log(s, AV_LOG_WARNING, "Using MS style audio codec tag, " + "the file may be unplayable!\n"); + } + } +@@ -722,7 +796,7 @@ + { + int tag = track->enc->codec_tag; + +- if (track->mode == MODE_MP4 || track->mode == MODE_PSP) ++ if (track->mode == MODE_MP4 || track->mode == MODE_PSP || track->mode == MODE_ISM) + tag = mp4_get_codec_tag(s, track); + else if (track->mode == MODE_IPOD) + tag = ipod_get_codec_tag(s, track); +@@ -738,92 +812,109 @@ + * Needed to make file play in iPods running newest firmware + * goes after avcC atom in moov.trak.mdia.minf.stbl.stsd.avc1 + */ +-static int mov_write_uuid_tag_ipod(ByteIOContext *pb) ++static int mov_write_uuid_tag_ipod(AVIOContext *pb) + { +- put_be32(pb, 28); +- put_tag(pb, "uuid"); +- put_be32(pb, 0x6b6840f2); +- put_be32(pb, 0x5f244fc5); +- put_be32(pb, 0xba39a51b); +- put_be32(pb, 0xcf0323f3); +- put_be32(pb, 0x0); ++ avio_wb32(pb, 28); ++ ffio_wfourcc(pb, "uuid"); ++ avio_wb32(pb, 0x6b6840f2); ++ avio_wb32(pb, 0x5f244fc5); ++ avio_wb32(pb, 0xba39a51b); ++ avio_wb32(pb, 0xcf0323f3); ++ avio_wb32(pb, 0x0); + return 28; + } + +-static int mov_write_subtitle_tag(ByteIOContext *pb, MOVTrack *track) ++static const uint16_t fiel_data[] = { ++ 0x0000, 0x0100, 0x0201, 0x0206, 0x0209, 0x020e ++}; ++ ++static int mov_write_fiel_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ unsigned mov_field_order = 0; ++ if (track->enc->field_order < FF_ARRAY_ELEMS(fiel_data)) ++ mov_field_order = fiel_data[track->enc->field_order]; ++ else ++ return 0; ++ avio_wb32(pb, 10); ++ ffio_wfourcc(pb, "fiel"); ++ avio_wb16(pb, mov_field_order); ++ return 10; ++} ++ ++static int mov_write_subtitle_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_le32(pb, track->tag); // store it byteswapped +- put_be32(pb, 0); /* Reserved */ +- put_be16(pb, 0); /* Reserved */ +- put_be16(pb, 1); /* Data-reference index */ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ avio_wl32(pb, track->tag); // store it byteswapped ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb16(pb, 0); /* Reserved */ ++ avio_wb16(pb, 1); /* Data-reference index */ + + if (track->enc->extradata_size) +- put_buffer(pb, track->enc->extradata, track->enc->extradata_size); ++ avio_write(pb, track->enc->extradata, track->enc->extradata_size); + + return updateSize(pb, pos); + } + +-static int mov_write_pasp_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_pasp_tag(AVIOContext *pb, MOVTrack *track) + { + AVRational sar; + av_reduce(&sar.num, &sar.den, track->enc->sample_aspect_ratio.num, + track->enc->sample_aspect_ratio.den, INT_MAX); + +- put_be32(pb, 16); +- put_tag(pb, "pasp"); +- put_be32(pb, sar.num); +- put_be32(pb, sar.den); ++ avio_wb32(pb, 16); ++ ffio_wfourcc(pb, "pasp"); ++ avio_wb32(pb, sar.num); ++ avio_wb32(pb, sar.den); + return 16; + } + +-static int mov_write_video_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_video_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + char compressor_name[32]; + +- put_be32(pb, 0); /* size */ +- put_le32(pb, track->tag); // store it byteswapped +- put_be32(pb, 0); /* Reserved */ +- put_be16(pb, 0); /* Reserved */ +- put_be16(pb, 1); /* Data-reference index */ ++ avio_wb32(pb, 0); /* size */ ++ avio_wl32(pb, track->tag); // store it byteswapped ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb16(pb, 0); /* Reserved */ ++ avio_wb16(pb, 1); /* Data-reference index */ + +- put_be16(pb, 0); /* Codec stream version */ +- put_be16(pb, 0); /* Codec stream revision (=0) */ ++ avio_wb16(pb, 0); /* Codec stream version */ ++ avio_wb16(pb, 0); /* Codec stream revision (=0) */ + if (track->mode == MODE_MOV) { +- put_tag(pb, "FFMP"); /* Vendor */ ++ ffio_wfourcc(pb, "FFMP"); /* Vendor */ + if(track->enc->codec_id == CODEC_ID_RAWVIDEO) { +- put_be32(pb, 0); /* Temporal Quality */ +- put_be32(pb, 0x400); /* Spatial Quality = lossless*/ ++ avio_wb32(pb, 0); /* Temporal Quality */ ++ avio_wb32(pb, 0x400); /* Spatial Quality = lossless*/ + } else { +- put_be32(pb, 0x200); /* Temporal Quality = normal */ +- put_be32(pb, 0x200); /* Spatial Quality = normal */ ++ avio_wb32(pb, 0x200); /* Temporal Quality = normal */ ++ avio_wb32(pb, 0x200); /* Spatial Quality = normal */ + } + } else { +- put_be32(pb, 0); /* Reserved */ +- put_be32(pb, 0); /* Reserved */ +- put_be32(pb, 0); /* Reserved */ +- } +- put_be16(pb, track->enc->width); /* Video width */ +- put_be16(pb, track->height); /* Video height */ +- put_be32(pb, 0x00480000); /* Horizontal resolution 72dpi */ +- put_be32(pb, 0x00480000); /* Vertical resolution 72dpi */ +- put_be32(pb, 0); /* Data size (= 0) */ +- put_be16(pb, 1); /* Frame count (= 1) */ ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb32(pb, 0); /* Reserved */ ++ } ++ avio_wb16(pb, track->enc->width); /* Video width */ ++ avio_wb16(pb, track->height); /* Video height */ ++ avio_wb32(pb, 0x00480000); /* Horizontal resolution 72dpi */ ++ avio_wb32(pb, 0x00480000); /* Vertical resolution 72dpi */ ++ avio_wb32(pb, 0); /* Data size (= 0) */ ++ avio_wb16(pb, 1); /* Frame count (= 1) */ + + memset(compressor_name,0,32); + /* FIXME not sure, ISO 14496-1 draft where it shall be set to 0 */ + if (track->mode == MODE_MOV && track->enc->codec && track->enc->codec->name) +- strncpy(compressor_name,track->enc->codec->name,31); +- put_byte(pb, strlen(compressor_name)); +- put_buffer(pb, compressor_name, 31); ++ av_strlcpy(compressor_name,track->enc->codec->name,32); ++ avio_w8(pb, strlen(compressor_name)); ++ avio_write(pb, compressor_name, 31); + + if (track->mode == MODE_MOV && track->enc->bits_per_coded_sample) +- put_be16(pb, track->enc->bits_per_coded_sample); ++ avio_wb16(pb, track->enc->bits_per_coded_sample); + else +- put_be16(pb, 0x18); /* Reserved */ +- put_be16(pb, 0xffff); /* Reserved */ ++ avio_wb16(pb, 0x18); /* Reserved */ ++ avio_wb16(pb, 0xffff); /* Reserved */ + if(track->tag == MKTAG('m','p','4','v')) + mov_write_esds_tag(pb, track); + else if(track->enc->codec_id == CODEC_ID_H263) +@@ -836,11 +927,12 @@ + mov_write_avcc_tag(pb, track); + if(track->mode == MODE_IPOD) + mov_write_uuid_tag_ipod(pb); +- } else if(track->vosLen > 0) ++ } else if (track->enc->field_order != AV_FIELD_UNKNOWN) ++ mov_write_fiel_tag(pb, track); ++ else if(track->vosLen > 0) + mov_write_glbl_tag(pb, track); + +- if (track->mode == MODE_MOV && +- track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num && ++ if (track->enc->sample_aspect_ratio.den && track->enc->sample_aspect_ratio.num && + track->enc->sample_aspect_ratio.den != track->enc->sample_aspect_ratio.num) { + mov_write_pasp_tag(pb, track); + } +@@ -848,33 +940,33 @@ + return updateSize(pb, pos); + } + +-static int mov_write_rtp_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_rtp_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "rtp "); +- put_be32(pb, 0); /* Reserved */ +- put_be16(pb, 0); /* Reserved */ +- put_be16(pb, 1); /* Data-reference index */ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "rtp "); ++ avio_wb32(pb, 0); /* Reserved */ ++ avio_wb16(pb, 0); /* Reserved */ ++ avio_wb16(pb, 1); /* Data-reference index */ + +- put_be16(pb, 1); /* Hint track version */ +- put_be16(pb, 1); /* Highest compatible version */ +- put_be32(pb, track->max_packet_size); /* Max packet size */ ++ avio_wb16(pb, 1); /* Hint track version */ ++ avio_wb16(pb, 1); /* Highest compatible version */ ++ avio_wb32(pb, track->max_packet_size); /* Max packet size */ + +- put_be32(pb, 12); /* size */ +- put_tag(pb, "tims"); +- put_be32(pb, track->timescale); ++ avio_wb32(pb, 12); /* size */ ++ ffio_wfourcc(pb, "tims"); ++ avio_wb32(pb, track->timescale); + + return updateSize(pb, pos); + } + +-static int mov_write_stsd_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_stsd_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "stsd"); +- put_be32(pb, 0); /* version & flags */ +- put_be32(pb, 1); /* entry count */ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "stsd"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb32(pb, 1); /* entry count */ + if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + mov_write_video_tag(pb, track); + else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) +@@ -886,7 +978,7 @@ + return updateSize(pb, pos); + } + +-static int mov_write_ctts_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_ctts_tag(AVIOContext *pb, MOVTrack *track) + { + MOVStts *ctts_entries; + uint32_t entries = 0; +@@ -907,20 +999,20 @@ + } + entries++; /* last one */ + atom_size = 16 + (entries * 8); +- put_be32(pb, atom_size); /* size */ +- put_tag(pb, "ctts"); +- put_be32(pb, 0); /* version & flags */ +- put_be32(pb, entries); /* entry count */ ++ avio_wb32(pb, atom_size); /* size */ ++ ffio_wfourcc(pb, "ctts"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb32(pb, entries); /* entry count */ + for (i=0; ientry * sizeof(*stts_entries)); /* worst case */ ++ stts_entries = track->entry ? ++ av_malloc(track->entry * sizeof(*stts_entries)) : /* worst case */ ++ NULL; + for (i=0; ientry; i++) { + int64_t duration = i + 1 == track->entry ? +- track->trackDuration - track->cluster[i].dts + track->cluster[0].dts : /* readjusting */ ++ track->trackDuration - track->cluster[i].dts + track->start_dts : /* readjusting */ + track->cluster[i+1].dts - track->cluster[i].dts; + if (i && duration == stts_entries[entries].duration) { + stts_entries[entries].count++; /* compress */ +@@ -949,37 +1043,38 @@ + entries++; /* last one */ + } + atom_size = 16 + (entries * 8); +- put_be32(pb, atom_size); /* size */ +- put_tag(pb, "stts"); +- put_be32(pb, 0); /* version & flags */ +- put_be32(pb, entries); /* entry count */ ++ avio_wb32(pb, atom_size); /* size */ ++ ffio_wfourcc(pb, "stts"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb32(pb, entries); /* entry count */ + for (i=0; ienc->codec_type == AVMEDIA_TYPE_VIDEO || +@@ -997,62 +1092,62 @@ + return updateSize(pb, pos); + } + +-static int mov_write_dinf_tag(ByteIOContext *pb) ++static int mov_write_dinf_tag(AVIOContext *pb) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "dinf"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "dinf"); + mov_write_dref_tag(pb); + return updateSize(pb, pos); + } + +-static int mov_write_nmhd_tag(ByteIOContext *pb) ++static int mov_write_nmhd_tag(AVIOContext *pb) + { +- put_be32(pb, 12); +- put_tag(pb, "nmhd"); +- put_be32(pb, 0); ++ avio_wb32(pb, 12); ++ ffio_wfourcc(pb, "nmhd"); ++ avio_wb32(pb, 0); + return 12; + } + +-static int mov_write_gmhd_tag(ByteIOContext *pb) ++static int mov_write_gmhd_tag(AVIOContext *pb) + { +- put_be32(pb, 0x20); /* size */ +- put_tag(pb, "gmhd"); +- put_be32(pb, 0x18); /* gmin size */ +- put_tag(pb, "gmin"); /* generic media info */ +- put_be32(pb, 0); /* version & flags */ +- put_be16(pb, 0x40); /* graphics mode = */ +- put_be16(pb, 0x8000); /* opColor (r?) */ +- put_be16(pb, 0x8000); /* opColor (g?) */ +- put_be16(pb, 0x8000); /* opColor (b?) */ +- put_be16(pb, 0); /* balance */ +- put_be16(pb, 0); /* reserved */ ++ avio_wb32(pb, 0x20); /* size */ ++ ffio_wfourcc(pb, "gmhd"); ++ avio_wb32(pb, 0x18); /* gmin size */ ++ ffio_wfourcc(pb, "gmin");/* generic media info */ ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb16(pb, 0x40); /* graphics mode = */ ++ avio_wb16(pb, 0x8000); /* opColor (r?) */ ++ avio_wb16(pb, 0x8000); /* opColor (g?) */ ++ avio_wb16(pb, 0x8000); /* opColor (b?) */ ++ avio_wb16(pb, 0); /* balance */ ++ avio_wb16(pb, 0); /* reserved */ + return 0x20; + } + +-static int mov_write_smhd_tag(ByteIOContext *pb) ++static int mov_write_smhd_tag(AVIOContext *pb) + { +- put_be32(pb, 16); /* size */ +- put_tag(pb, "smhd"); +- put_be32(pb, 0); /* version & flags */ +- put_be16(pb, 0); /* reserved (balance, normally = 0) */ +- put_be16(pb, 0); /* reserved */ ++ avio_wb32(pb, 16); /* size */ ++ ffio_wfourcc(pb, "smhd"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb16(pb, 0); /* reserved (balance, normally = 0) */ ++ avio_wb16(pb, 0); /* reserved */ + return 16; + } + +-static int mov_write_vmhd_tag(ByteIOContext *pb) ++static int mov_write_vmhd_tag(AVIOContext *pb) + { +- put_be32(pb, 0x14); /* size (always 0x14) */ +- put_tag(pb, "vmhd"); +- put_be32(pb, 0x01); /* version & flags */ +- put_be64(pb, 0); /* reserved (graphics mode = copy) */ ++ avio_wb32(pb, 0x14); /* size (always 0x14) */ ++ ffio_wfourcc(pb, "vmhd"); ++ avio_wb32(pb, 0x01); /* version & flags */ ++ avio_wb64(pb, 0); /* reserved (graphics mode = copy) */ + return 0x14; + } + +-static int mov_write_hdlr_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_hdlr_tag(AVIOContext *pb, MOVTrack *track) + { + const char *hdlr, *descr = NULL, *hdlr_type = NULL; +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + + if (!track) { /* no media --> data handler */ + hdlr = "dhlr"; +@@ -1076,42 +1171,42 @@ + } + } + +- put_be32(pb, 0); /* size */ +- put_tag(pb, "hdlr"); +- put_be32(pb, 0); /* Version & flags */ +- put_buffer(pb, hdlr, 4); /* handler */ +- put_tag(pb, hdlr_type); /* handler type */ +- put_be32(pb ,0); /* reserved */ +- put_be32(pb ,0); /* reserved */ +- put_be32(pb ,0); /* reserved */ ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "hdlr"); ++ avio_wb32(pb, 0); /* Version & flags */ ++ avio_write(pb, hdlr, 4); /* handler */ ++ ffio_wfourcc(pb, hdlr_type); /* handler type */ ++ avio_wb32(pb ,0); /* reserved */ ++ avio_wb32(pb ,0); /* reserved */ ++ avio_wb32(pb ,0); /* reserved */ + if (!track || track->mode == MODE_MOV) +- put_byte(pb, strlen(descr)); /* pascal string */ +- put_buffer(pb, descr, strlen(descr)); /* handler description */ ++ avio_w8(pb, strlen(descr)); /* pascal string */ ++ avio_write(pb, descr, strlen(descr)); /* handler description */ + if (track && track->mode != MODE_MOV) +- put_byte(pb, 0); /* c string */ ++ avio_w8(pb, 0); /* c string */ + return updateSize(pb, pos); + } + +-static int mov_write_hmhd_tag(ByteIOContext *pb) ++static int mov_write_hmhd_tag(AVIOContext *pb) + { + /* This atom must be present, but leaving the values at zero + * seems harmless. */ +- put_be32(pb, 28); /* size */ +- put_tag(pb, "hmhd"); +- put_be32(pb, 0); /* version, flags */ +- put_be16(pb, 0); /* maxPDUsize */ +- put_be16(pb, 0); /* avgPDUsize */ +- put_be32(pb, 0); /* maxbitrate */ +- put_be32(pb, 0); /* avgbitrate */ +- put_be32(pb, 0); /* reserved */ ++ avio_wb32(pb, 28); /* size */ ++ ffio_wfourcc(pb, "hmhd"); ++ avio_wb32(pb, 0); /* version, flags */ ++ avio_wb16(pb, 0); /* maxPDUsize */ ++ avio_wb16(pb, 0); /* avgPDUsize */ ++ avio_wb32(pb, 0); /* maxbitrate */ ++ avio_wb32(pb, 0); /* avgbitrate */ ++ avio_wb32(pb, 0); /* reserved */ + return 28; + } + +-static int mov_write_minf_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_minf_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "minf"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "minf"); + if(track->enc->codec_type == AVMEDIA_TYPE_VIDEO) + mov_write_vmhd_tag(pb); + else if (track->enc->codec_type == AVMEDIA_TYPE_AUDIO) +@@ -1129,25 +1224,25 @@ + return updateSize(pb, pos); + } + +-static int mov_write_mdhd_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_mdhd_tag(AVIOContext *pb, MOVTrack *track) + { + int version = track->trackDuration < INT32_MAX ? 0 : 1; + +- (version == 1) ? put_be32(pb, 44) : put_be32(pb, 32); /* size */ +- put_tag(pb, "mdhd"); +- put_byte(pb, version); +- put_be24(pb, 0); /* flags */ ++ (version == 1) ? avio_wb32(pb, 44) : avio_wb32(pb, 32); /* size */ ++ ffio_wfourcc(pb, "mdhd"); ++ avio_w8(pb, version); ++ avio_wb24(pb, 0); /* flags */ + if (version == 1) { +- put_be64(pb, track->time); +- put_be64(pb, track->time); ++ avio_wb64(pb, track->time); ++ avio_wb64(pb, track->time); + } else { +- put_be32(pb, track->time); /* creation time */ +- put_be32(pb, track->time); /* modification time */ ++ avio_wb32(pb, track->time); /* creation time */ ++ avio_wb32(pb, track->time); /* modification time */ + } +- put_be32(pb, track->timescale); /* time scale (sample rate for audio) */ +- (version == 1) ? put_be64(pb, track->trackDuration) : put_be32(pb, track->trackDuration); /* duration */ +- put_be16(pb, track->language); /* language */ +- put_be16(pb, 0); /* reserved (quality) */ ++ avio_wb32(pb, track->timescale); /* time scale (sample rate for audio) */ ++ (version == 1) ? avio_wb64(pb, track->trackDuration) : avio_wb32(pb, track->trackDuration); /* duration */ ++ avio_wb16(pb, track->language); /* language */ ++ avio_wb16(pb, 0); /* reserved (quality) */ + + if(version!=0 && track->mode == MODE_MOV){ + av_log(NULL, AV_LOG_ERROR, +@@ -1159,177 +1254,280 @@ + return 32; + } + +-static int mov_write_mdia_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_mdia_tag(AVIOContext *pb, MOVTrack *track) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "mdia"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "mdia"); + mov_write_mdhd_tag(pb, track); + mov_write_hdlr_tag(pb, track); + mov_write_minf_tag(pb, track); + return updateSize(pb, pos); + } + +-static int mov_write_tkhd_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) ++static int mov_write_tkhd_tag(AVIOContext *pb, MOVTrack *track, AVStream *st) + { + int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, + track->timescale, AV_ROUND_UP); + int version = duration < INT32_MAX ? 0 : 1; + +- (version == 1) ? put_be32(pb, 104) : put_be32(pb, 92); /* size */ +- put_tag(pb, "tkhd"); +- put_byte(pb, version); +- put_be24(pb, 0xf); /* flags (track enabled) */ ++ (version == 1) ? avio_wb32(pb, 104) : avio_wb32(pb, 92); /* size */ ++ ffio_wfourcc(pb, "tkhd"); ++ avio_w8(pb, version); ++ avio_wb24(pb, 0xf); /* flags (track enabled) */ + if (version == 1) { +- put_be64(pb, track->time); +- put_be64(pb, track->time); ++ avio_wb64(pb, track->time); ++ avio_wb64(pb, track->time); + } else { +- put_be32(pb, track->time); /* creation time */ +- put_be32(pb, track->time); /* modification time */ ++ avio_wb32(pb, track->time); /* creation time */ ++ avio_wb32(pb, track->time); /* modification time */ + } +- put_be32(pb, track->trackID); /* track-id */ +- put_be32(pb, 0); /* reserved */ +- (version == 1) ? put_be64(pb, duration) : put_be32(pb, duration); +- +- put_be32(pb, 0); /* reserved */ +- put_be32(pb, 0); /* reserved */ +- put_be32(pb, 0x0); /* reserved (Layer & Alternate group) */ ++ avio_wb32(pb, track->trackID); /* track-id */ ++ avio_wb32(pb, 0); /* reserved */ ++ (version == 1) ? avio_wb64(pb, duration) : avio_wb32(pb, duration); ++ ++ avio_wb32(pb, 0); /* reserved */ ++ avio_wb32(pb, 0); /* reserved */ ++ avio_wb16(pb, 0); /* layer */ ++ avio_wb16(pb, st ? st->codec->codec_type : 0); /* alternate group) */ + /* Volume, only for audio */ + if(track->enc->codec_type == AVMEDIA_TYPE_AUDIO) +- put_be16(pb, 0x0100); ++ avio_wb16(pb, 0x0100); + else +- put_be16(pb, 0); +- put_be16(pb, 0); /* reserved */ ++ avio_wb16(pb, 0); ++ avio_wb16(pb, 0); /* reserved */ + + /* Matrix structure */ +- put_be32(pb, 0x00010000); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x00010000); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x40000000); /* reserved */ ++ avio_wb32(pb, 0x00010000); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x00010000); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x40000000); /* reserved */ + + /* Track width and height, for visual only */ + if(st && (track->enc->codec_type == AVMEDIA_TYPE_VIDEO || + track->enc->codec_type == AVMEDIA_TYPE_SUBTITLE)) { +- double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); +- if(!sample_aspect_ratio || track->height != track->enc->height) +- sample_aspect_ratio = 1; +- put_be32(pb, sample_aspect_ratio * track->enc->width*0x10000); +- put_be32(pb, track->height*0x10000); ++ if(track->mode == MODE_MOV) { ++ avio_wb32(pb, track->enc->width << 16); ++ avio_wb32(pb, track->height << 16); ++ } else { ++ double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); ++ if(!sample_aspect_ratio || track->height != track->enc->height) ++ sample_aspect_ratio = 1; ++ avio_wb32(pb, sample_aspect_ratio * track->enc->width*0x10000); ++ avio_wb32(pb, track->height*0x10000); ++ } + } + else { +- put_be32(pb, 0); +- put_be32(pb, 0); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); + } + return 0x5c; + } + ++static int mov_write_tapt_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ int32_t width = av_rescale(track->enc->sample_aspect_ratio.num, track->enc->width, ++ track->enc->sample_aspect_ratio.den); ++ ++ int64_t pos = avio_tell(pb); ++ ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "tapt"); ++ ++ avio_wb32(pb, 20); ++ ffio_wfourcc(pb, "clef"); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, width << 16); ++ avio_wb32(pb, track->enc->height << 16); ++ ++ avio_wb32(pb, 20); ++ ffio_wfourcc(pb, "enof"); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, track->enc->width << 16); ++ avio_wb32(pb, track->enc->height << 16); ++ ++ return updateSize(pb, pos); ++} ++ + // This box seems important for the psp playback ... without it the movie seems to hang +-static int mov_write_edts_tag(ByteIOContext *pb, MOVTrack *track) ++static int mov_write_edts_tag(AVIOContext *pb, MOVTrack *track) + { +- put_be32(pb, 0x24); /* size */ +- put_tag(pb, "edts"); +- put_be32(pb, 0x1c); /* size */ +- put_tag(pb, "elst"); +- put_be32(pb, 0x0); +- put_be32(pb, 0x1); +- +- /* duration ... doesn't seem to effect psp */ +- put_be32(pb, av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, +- track->timescale, AV_ROUND_UP)); +- +- put_be32(pb, track->cluster[0].cts); /* first pts is cts since dts is 0 */ +- put_be32(pb, 0x00010000); +- return 0x24; +-} +- +-static int mov_write_tref_tag(ByteIOContext *pb, MOVTrack *track) +-{ +- put_be32(pb, 20); // size +- put_tag(pb, "tref"); +- put_be32(pb, 12); // size (subatom) +- put_le32(pb, track->tref_tag); +- put_be32(pb, track->tref_id); ++ int64_t duration = av_rescale_rnd(track->trackDuration, MOV_TIMESCALE, ++ track->timescale, AV_ROUND_UP); ++ int version = duration < INT32_MAX ? 0 : 1; ++ int entry_size, entry_count, size; ++ int64_t delay, start_ct = track->cluster[0].cts; ++ delay = av_rescale_rnd(track->cluster[0].dts + start_ct, MOV_TIMESCALE, ++ track->timescale, AV_ROUND_DOWN); ++ version |= delay < INT32_MAX ? 0 : 1; ++ ++ entry_size = (version == 1) ? 20 : 12; ++ entry_count = 1 + (delay > 0); ++ size = 24 + entry_count * entry_size; ++ ++ /* write the atom data */ ++ avio_wb32(pb, size); ++ ffio_wfourcc(pb, "edts"); ++ avio_wb32(pb, size - 8); ++ ffio_wfourcc(pb, "elst"); ++ avio_w8(pb, version); ++ avio_wb24(pb, 0); /* flags */ ++ ++ avio_wb32(pb, entry_count); ++ if (delay > 0) { /* add an empty edit to delay presentation */ ++ if (version == 1) { ++ avio_wb64(pb, delay); ++ avio_wb64(pb, -1); ++ } else { ++ avio_wb32(pb, delay); ++ avio_wb32(pb, -1); ++ } ++ avio_wb32(pb, 0x00010000); ++ } ++ ++ /* duration */ ++ if (version == 1) { ++ avio_wb64(pb, duration); ++ avio_wb64(pb, start_ct); ++ } else { ++ avio_wb32(pb, duration); ++ avio_wb32(pb, start_ct); ++ } ++ avio_wb32(pb, 0x00010000); ++ return size; ++} ++ ++static int mov_write_tref_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ avio_wb32(pb, 20); // size ++ ffio_wfourcc(pb, "tref"); ++ avio_wb32(pb, 12); // size (subatom) ++ avio_wl32(pb, track->tref_tag); ++ avio_wb32(pb, track->tref_id); + return 20; + } + + // goes at the end of each track! ... Critical for PSP playback ("Incompatible data" without it) +-static int mov_write_uuid_tag_psp(ByteIOContext *pb, MOVTrack *mov) ++static int mov_write_uuid_tag_psp(AVIOContext *pb, MOVTrack *mov) + { +- put_be32(pb, 0x34); /* size ... reports as 28 in mp4box! */ +- put_tag(pb, "uuid"); +- put_tag(pb, "USMT"); +- put_be32(pb, 0x21d24fce); +- put_be32(pb, 0xbb88695c); +- put_be32(pb, 0xfac9c740); +- put_be32(pb, 0x1c); // another size here! +- put_tag(pb, "MTDT"); +- put_be32(pb, 0x00010012); +- put_be32(pb, 0x0a); +- put_be32(pb, 0x55c40000); +- put_be32(pb, 0x1); +- put_be32(pb, 0x0); ++ avio_wb32(pb, 0x34); /* size ... reports as 28 in mp4box! */ ++ ffio_wfourcc(pb, "uuid"); ++ ffio_wfourcc(pb, "USMT"); ++ avio_wb32(pb, 0x21d24fce); ++ avio_wb32(pb, 0xbb88695c); ++ avio_wb32(pb, 0xfac9c740); ++ avio_wb32(pb, 0x1c); // another size here! ++ ffio_wfourcc(pb, "MTDT"); ++ avio_wb32(pb, 0x00010012); ++ avio_wb32(pb, 0x0a); ++ avio_wb32(pb, 0x55c40000); ++ avio_wb32(pb, 0x1); ++ avio_wb32(pb, 0x0); + return 0x34; + } + +-static int mov_write_udta_sdp(ByteIOContext *pb, AVCodecContext *ctx, int index) ++static int mov_write_udta_sdp(AVIOContext *pb, AVFormatContext *ctx, int index) + { + char buf[1000] = ""; + int len; + +- ff_sdp_write_media(buf, sizeof(buf), ctx, NULL, NULL, 0, 0); ++ ff_sdp_write_media(buf, sizeof(buf), ctx->streams[0]->codec, NULL, NULL, 0, 0, ctx); + av_strlcatf(buf, sizeof(buf), "a=control:streamid=%d\r\n", index); + len = strlen(buf); + +- put_be32(pb, len + 24); +- put_tag (pb, "udta"); +- put_be32(pb, len + 16); +- put_tag (pb, "hnti"); +- put_be32(pb, len + 8); +- put_tag (pb, "sdp "); +- put_buffer(pb, buf, len); ++ avio_wb32(pb, len + 24); ++ ffio_wfourcc(pb, "udta"); ++ avio_wb32(pb, len + 16); ++ ffio_wfourcc(pb, "hnti"); ++ avio_wb32(pb, len + 8); ++ ffio_wfourcc(pb, "sdp "); ++ avio_write(pb, buf, len); + return len + 24; + } + +-static int mov_write_trak_tag(ByteIOContext *pb, MOVTrack *track, AVStream *st) ++static int mov_write_trak_tag(AVIOContext *pb, MOVMuxContext *mov, ++ MOVTrack *track, AVStream *st) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "trak"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "trak"); + mov_write_tkhd_tag(pb, track, st); +- if (track->mode == MODE_PSP || track->flags & MOV_TRACK_CTTS) +- mov_write_edts_tag(pb, track); // PSP Movies require edts box ++ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) // EDTS with fragments is tricky as we dont know the duration when its written ++ mov_write_edts_tag(pb, track); // PSP Movies and several other cases require edts box + if (track->tref_tag) + mov_write_tref_tag(pb, track); + mov_write_mdia_tag(pb, track); + if (track->mode == MODE_PSP) + mov_write_uuid_tag_psp(pb,track); // PSP Movies require this uuid box + if (track->tag == MKTAG('r','t','p',' ')) +- mov_write_udta_sdp(pb, track->rtp_ctx->streams[0]->codec, track->trackID); ++ mov_write_udta_sdp(pb, track->rtp_ctx, track->trackID); ++ if (track->enc->codec_type == AVMEDIA_TYPE_VIDEO && track->mode == MODE_MOV) { ++ double sample_aspect_ratio = av_q2d(st->sample_aspect_ratio); ++ if (0.0 != sample_aspect_ratio && 1.0 != sample_aspect_ratio) ++ mov_write_tapt_tag(pb, track); ++ }; + return updateSize(pb, pos); + } + +-#if 0 +-/* TODO: Not sorted out, but not necessary either */ +-static int mov_write_iods_tag(ByteIOContext *pb, MOVMuxContext *mov) +-{ +- put_be32(pb, 0x15); /* size */ +- put_tag(pb, "iods"); +- put_be32(pb, 0); /* version & flags */ +- put_be16(pb, 0x1007); +- put_byte(pb, 0); +- put_be16(pb, 0x4fff); +- put_be16(pb, 0xfffe); +- put_be16(pb, 0x01ff); +- return 0x15; ++static int mov_write_iods_tag(AVIOContext *pb, MOVMuxContext *mov) ++{ ++ int i, has_audio = 0, has_video = 0; ++ int64_t pos = avio_tell(pb); ++ int audio_profile = mov->iods_audio_profile; ++ int video_profile = mov->iods_video_profile; ++ for (i = 0; i < mov->nb_streams; i++) { ++ if(mov->tracks[i].entry > 0) { ++ has_audio |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_AUDIO; ++ has_video |= mov->tracks[i].enc->codec_type == AVMEDIA_TYPE_VIDEO; ++ } ++ } ++ if (audio_profile < 0) ++ audio_profile = 0xFF - has_audio; ++ if (video_profile < 0) ++ video_profile = 0xFF - has_video; ++ avio_wb32(pb, 0x0); /* size */ ++ ffio_wfourcc(pb, "iods"); ++ avio_wb32(pb, 0); /* version & flags */ ++ putDescr(pb, 0x10, 7); ++ avio_wb16(pb, 0x004f); ++ avio_w8(pb, 0xff); ++ avio_w8(pb, 0xff); ++ avio_w8(pb, audio_profile); ++ avio_w8(pb, video_profile); ++ avio_w8(pb, 0xff); ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_trex_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ avio_wb32(pb, 0x20); /* size */ ++ ffio_wfourcc(pb, "trex"); ++ avio_wb32(pb, 0); /* version & flags */ ++ avio_wb32(pb, track->trackID); /* track ID */ ++ avio_wb32(pb, 1); /* default sample description index */ ++ avio_wb32(pb, 0); /* default sample duration */ ++ avio_wb32(pb, 0); /* default sample size */ ++ avio_wb32(pb, 0); /* default sample flags */ ++ return 0; + } +-#endif + +-static int mov_write_mvhd_tag(ByteIOContext *pb, MOVMuxContext *mov) ++static int mov_write_mvex_tag(AVIOContext *pb, MOVMuxContext *mov) ++{ ++ int64_t pos = avio_tell(pb); ++ int i; ++ avio_wb32(pb, 0x0); /* size */ ++ ffio_wfourcc(pb, "mvex"); ++ for (i = 0; i < mov->nb_streams; i++) ++ mov_write_trex_tag(pb, &mov->tracks[i]); ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_mvhd_tag(AVIOContext *pb, MOVMuxContext *mov) + { + int maxTrackID = 1, i; + int64_t maxTrackLenTemp, maxTrackLen = 0; +@@ -1349,109 +1547,109 @@ + } + + version = maxTrackLen < UINT32_MAX ? 0 : 1; +- (version == 1) ? put_be32(pb, 120) : put_be32(pb, 108); /* size */ +- put_tag(pb, "mvhd"); +- put_byte(pb, version); +- put_be24(pb, 0); /* flags */ ++ (version == 1) ? avio_wb32(pb, 120) : avio_wb32(pb, 108); /* size */ ++ ffio_wfourcc(pb, "mvhd"); ++ avio_w8(pb, version); ++ avio_wb24(pb, 0); /* flags */ + if (version == 1) { +- put_be64(pb, mov->time); +- put_be64(pb, mov->time); ++ avio_wb64(pb, mov->time); ++ avio_wb64(pb, mov->time); + } else { +- put_be32(pb, mov->time); /* creation time */ +- put_be32(pb, mov->time); /* modification time */ ++ avio_wb32(pb, mov->time); /* creation time */ ++ avio_wb32(pb, mov->time); /* modification time */ + } +- put_be32(pb, MOV_TIMESCALE); +- (version == 1) ? put_be64(pb, maxTrackLen) : put_be32(pb, maxTrackLen); /* duration of longest track */ ++ avio_wb32(pb, MOV_TIMESCALE); ++ (version == 1) ? avio_wb64(pb, maxTrackLen) : avio_wb32(pb, maxTrackLen); /* duration of longest track */ + +- put_be32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */ +- put_be16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */ +- put_be16(pb, 0); /* reserved */ +- put_be32(pb, 0); /* reserved */ +- put_be32(pb, 0); /* reserved */ ++ avio_wb32(pb, 0x00010000); /* reserved (preferred rate) 1.0 = normal */ ++ avio_wb16(pb, 0x0100); /* reserved (preferred volume) 1.0 = normal */ ++ avio_wb16(pb, 0); /* reserved */ ++ avio_wb32(pb, 0); /* reserved */ ++ avio_wb32(pb, 0); /* reserved */ + + /* Matrix structure */ +- put_be32(pb, 0x00010000); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x00010000); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x0); /* reserved */ +- put_be32(pb, 0x40000000); /* reserved */ +- +- put_be32(pb, 0); /* reserved (preview time) */ +- put_be32(pb, 0); /* reserved (preview duration) */ +- put_be32(pb, 0); /* reserved (poster time) */ +- put_be32(pb, 0); /* reserved (selection time) */ +- put_be32(pb, 0); /* reserved (selection duration) */ +- put_be32(pb, 0); /* reserved (current time) */ +- put_be32(pb, maxTrackID+1); /* Next track id */ ++ avio_wb32(pb, 0x00010000); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x00010000); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x0); /* reserved */ ++ avio_wb32(pb, 0x40000000); /* reserved */ ++ ++ avio_wb32(pb, 0); /* reserved (preview time) */ ++ avio_wb32(pb, 0); /* reserved (preview duration) */ ++ avio_wb32(pb, 0); /* reserved (poster time) */ ++ avio_wb32(pb, 0); /* reserved (selection time) */ ++ avio_wb32(pb, 0); /* reserved (selection duration) */ ++ avio_wb32(pb, 0); /* reserved (current time) */ ++ avio_wb32(pb, maxTrackID+1); /* Next track id */ + return 0x6c; + } + +-static int mov_write_itunes_hdlr_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static int mov_write_itunes_hdlr_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { +- put_be32(pb, 33); /* size */ +- put_tag(pb, "hdlr"); +- put_be32(pb, 0); +- put_be32(pb, 0); +- put_tag(pb, "mdir"); +- put_tag(pb, "appl"); +- put_be32(pb, 0); +- put_be32(pb, 0); +- put_byte(pb, 0); ++ avio_wb32(pb, 33); /* size */ ++ ffio_wfourcc(pb, "hdlr"); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); ++ ffio_wfourcc(pb, "mdir"); ++ ffio_wfourcc(pb, "appl"); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); ++ avio_w8(pb, 0); + return 33; + } + + /* helper function to write a data tag with the specified string as data */ +-static int mov_write_string_data_tag(ByteIOContext *pb, const char *data, int lang, int long_style) ++static int mov_write_string_data_tag(AVIOContext *pb, const char *data, int lang, int long_style) + { + if(long_style){ + int size = 16 + strlen(data); +- put_be32(pb, size); /* size */ +- put_tag(pb, "data"); +- put_be32(pb, 1); +- put_be32(pb, 0); +- put_buffer(pb, data, strlen(data)); ++ avio_wb32(pb, size); /* size */ ++ ffio_wfourcc(pb, "data"); ++ avio_wb32(pb, 1); ++ avio_wb32(pb, 0); ++ avio_write(pb, data, strlen(data)); + return size; + }else{ + if (!lang) + lang = ff_mov_iso639_to_lang("und", 1); +- put_be16(pb, strlen(data)); /* string length */ +- put_be16(pb, lang); +- put_buffer(pb, data, strlen(data)); ++ avio_wb16(pb, strlen(data)); /* string length */ ++ avio_wb16(pb, lang); ++ avio_write(pb, data, strlen(data)); + return strlen(data) + 4; + } + } + +-static int mov_write_string_tag(ByteIOContext *pb, const char *name, const char *value, int lang, int long_style){ ++static int mov_write_string_tag(AVIOContext *pb, const char *name, const char *value, int lang, int long_style){ + int size = 0; + if (value && value[0]) { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, name); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, name); + mov_write_string_data_tag(pb, value, lang, long_style); + size= updateSize(pb, pos); + } + return size; + } + +-static int mov_write_string_metadata(AVFormatContext *s, ByteIOContext *pb, ++static int mov_write_string_metadata(AVFormatContext *s, AVIOContext *pb, + const char *name, const char *tag, + int long_style) + { + int l, lang = 0, len, len2; +- AVMetadataTag *t, *t2 = NULL; ++ AVDictionaryEntry *t, *t2 = NULL; + char tag2[16]; + +- if (!(t = av_metadata_get(s->metadata, tag, NULL, 0))) ++ if (!(t = av_dict_get(s->metadata, tag, NULL, 0))) + return 0; + + len = strlen(t->key); + snprintf(tag2, sizeof(tag2), "%s-", tag); +- while ((t2 = av_metadata_get(s->metadata, tag2, t2, AV_METADATA_IGNORE_SUFFIX))) { ++ while ((t2 = av_dict_get(s->metadata, tag2, t2, AV_DICT_IGNORE_SUFFIX))) { + len2 = strlen(t2->key); + if (len2 == len+4 && !strcmp(t->value, t2->value) + && (l=ff_mov_iso639_to_lang(&t2->key[len2-3], 1)) >= 0) { +@@ -1463,34 +1661,34 @@ + } + + /* iTunes track number */ +-static int mov_write_trkn_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static int mov_write_trkn_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { +- AVMetadataTag *t = av_metadata_get(s->metadata, "track", NULL, 0); ++ AVDictionaryEntry *t = av_dict_get(s->metadata, "track", NULL, 0); + int size = 0, track = t ? atoi(t->value) : 0; + if (track) { +- put_be32(pb, 32); /* size */ +- put_tag(pb, "trkn"); +- put_be32(pb, 24); /* size */ +- put_tag(pb, "data"); +- put_be32(pb, 0); // 8 bytes empty +- put_be32(pb, 0); +- put_be16(pb, 0); // empty +- put_be16(pb, track); // track number +- put_be16(pb, 0); // total track number +- put_be16(pb, 0); // empty ++ avio_wb32(pb, 32); /* size */ ++ ffio_wfourcc(pb, "trkn"); ++ avio_wb32(pb, 24); /* size */ ++ ffio_wfourcc(pb, "data"); ++ avio_wb32(pb, 0); // 8 bytes empty ++ avio_wb32(pb, 0); ++ avio_wb16(pb, 0); // empty ++ avio_wb16(pb, track); // track number ++ avio_wb16(pb, 0); // total track number ++ avio_wb16(pb, 0); // empty + size = 32; + } + return size; + } + + /* iTunes meta data list */ +-static int mov_write_ilst_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static int mov_write_ilst_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "ilst"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "ilst"); + mov_write_string_metadata(s, pb, "\251nam", "title" , 1); + mov_write_string_metadata(s, pb, "\251ART", "artist" , 1); + mov_write_string_metadata(s, pb, "aART", "album_artist", 1); +@@ -1513,14 +1711,14 @@ + } + + /* iTunes meta data tag */ +-static int mov_write_meta_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static int mov_write_meta_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { + int size = 0; +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size */ +- put_tag(pb, "meta"); +- put_be32(pb, 0); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "meta"); ++ avio_wb32(pb, 0); + mov_write_itunes_hdlr_tag(pb, mov, s); + mov_write_ilst_tag(pb, mov, s); + size = updateSize(pb, pos); +@@ -1538,14 +1736,14 @@ + return len; + } + +-static int ascii_to_wc(ByteIOContext *pb, const uint8_t *b) ++static int ascii_to_wc(AVIOContext *pb, const uint8_t *b) + { + int val; + while(*b){ + GET_UTF8(val, *b++, return -1;) +- put_be16(pb, val); ++ avio_wb16(pb, val); + } +- put_be16(pb, 0x00); ++ avio_wb16(pb, 0x00); + return 0; + } + +@@ -1554,58 +1752,58 @@ + return (((str[0]-0x60) & 0x1F) << 10) + (((str[1]-0x60) & 0x1F) << 5) + ((str[2]-0x60) & 0x1F); + } + +-static int mov_write_3gp_udta_tag(ByteIOContext *pb, AVFormatContext *s, ++static int mov_write_3gp_udta_tag(AVIOContext *pb, AVFormatContext *s, + const char *tag, const char *str) + { +- int64_t pos = url_ftell(pb); +- AVMetadataTag *t = av_metadata_get(s->metadata, str, NULL, 0); ++ int64_t pos = avio_tell(pb); ++ AVDictionaryEntry *t = av_dict_get(s->metadata, str, NULL, 0); + if (!t || !utf8len(t->value)) + return 0; +- put_be32(pb, 0); /* size */ +- put_tag (pb, tag); /* type */ +- put_be32(pb, 0); /* version + flags */ ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, tag); /* type */ ++ avio_wb32(pb, 0); /* version + flags */ + if (!strcmp(tag, "yrrc")) +- put_be16(pb, atoi(t->value)); ++ avio_wb16(pb, atoi(t->value)); + else { +- put_be16(pb, language_code("eng")); /* language */ +- put_buffer(pb, t->value, strlen(t->value)+1); /* UTF8 string value */ ++ avio_wb16(pb, language_code("eng")); /* language */ ++ avio_write(pb, t->value, strlen(t->value)+1); /* UTF8 string value */ + if (!strcmp(tag, "albm") && +- (t = av_metadata_get(s->metadata, "track", NULL, 0))) +- put_byte(pb, atoi(t->value)); ++ (t = av_dict_get(s->metadata, "track", NULL, 0))) ++ avio_w8(pb, atoi(t->value)); + } + return updateSize(pb, pos); + } + +-static int mov_write_chpl_tag(ByteIOContext *pb, AVFormatContext *s) ++static int mov_write_chpl_tag(AVIOContext *pb, AVFormatContext *s) + { +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + int i, nb_chapters = FFMIN(s->nb_chapters, 255); + +- put_be32(pb, 0); // size +- put_tag (pb, "chpl"); +- put_be32(pb, 0x01000000); // version + flags +- put_be32(pb, 0); // unknown +- put_byte(pb, nb_chapters); ++ avio_wb32(pb, 0); // size ++ ffio_wfourcc(pb, "chpl"); ++ avio_wb32(pb, 0x01000000); // version + flags ++ avio_wb32(pb, 0); // unknown ++ avio_w8(pb, nb_chapters); + + for (i = 0; i < nb_chapters; i++) { + AVChapter *c = s->chapters[i]; +- AVMetadataTag *t; +- put_be64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000})); ++ AVDictionaryEntry *t; ++ avio_wb64(pb, av_rescale_q(c->start, c->time_base, (AVRational){1,10000000})); + +- if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { ++ if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { + int len = FFMIN(strlen(t->value), 255); +- put_byte(pb, len); +- put_buffer(pb, t->value, len); ++ avio_w8(pb, len); ++ avio_write(pb, t->value, len); + } else +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + return updateSize(pb, pos); + } + +-static int mov_write_udta_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static int mov_write_udta_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { +- ByteIOContext *pb_buf; ++ AVIOContext *pb_buf; + int i, ret, size; + uint8_t *buf; + +@@ -1614,85 +1812,85 @@ + return 0; + } + +- ret = url_open_dyn_buf(&pb_buf); ++ ret = avio_open_dyn_buf(&pb_buf); + if(ret < 0) + return ret; + +- if (mov->mode & MODE_3GP) { +- mov_write_3gp_udta_tag(pb_buf, s, "perf", "artist"); +- mov_write_3gp_udta_tag(pb_buf, s, "titl", "title"); +- mov_write_3gp_udta_tag(pb_buf, s, "auth", "author"); +- mov_write_3gp_udta_tag(pb_buf, s, "gnre", "genre"); +- mov_write_3gp_udta_tag(pb_buf, s, "dscp", "comment"); +- mov_write_3gp_udta_tag(pb_buf, s, "albm", "album"); +- mov_write_3gp_udta_tag(pb_buf, s, "cprt", "copyright"); +- mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "date"); +- } else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4 +- mov_write_string_metadata(s, pb_buf, "\251ART", "artist" , 0); +- mov_write_string_metadata(s, pb_buf, "\251nam", "title" , 0); +- mov_write_string_metadata(s, pb_buf, "\251aut", "author" , 0); +- mov_write_string_metadata(s, pb_buf, "\251alb", "album" , 0); +- mov_write_string_metadata(s, pb_buf, "\251day", "date" , 0); +- mov_write_string_metadata(s, pb_buf, "\251swr", "encoder" , 0); +- mov_write_string_metadata(s, pb_buf, "\251des", "comment" , 0); +- mov_write_string_metadata(s, pb_buf, "\251gen", "genre" , 0); +- mov_write_string_metadata(s, pb_buf, "\251cpy", "copyright" , 0); +- } else { +- /* iTunes meta data */ +- mov_write_meta_tag(pb_buf, mov, s); +- } ++ if (mov->mode & MODE_3GP) { ++ mov_write_3gp_udta_tag(pb_buf, s, "perf", "artist"); ++ mov_write_3gp_udta_tag(pb_buf, s, "titl", "title"); ++ mov_write_3gp_udta_tag(pb_buf, s, "auth", "author"); ++ mov_write_3gp_udta_tag(pb_buf, s, "gnre", "genre"); ++ mov_write_3gp_udta_tag(pb_buf, s, "dscp", "comment"); ++ mov_write_3gp_udta_tag(pb_buf, s, "albm", "album"); ++ mov_write_3gp_udta_tag(pb_buf, s, "cprt", "copyright"); ++ mov_write_3gp_udta_tag(pb_buf, s, "yrrc", "date"); ++ } else if (mov->mode == MODE_MOV) { // the title field breaks gtkpod with mp4 and my suspicion is that stuff is not valid in mp4 ++ mov_write_string_metadata(s, pb_buf, "\251ART", "artist" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251nam", "title" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251aut", "author" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251alb", "album" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251day", "date" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251swr", "encoder" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251des", "comment" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251gen", "genre" , 0); ++ mov_write_string_metadata(s, pb_buf, "\251cpy", "copyright" , 0); ++ } else { ++ /* iTunes meta data */ ++ mov_write_meta_tag(pb_buf, mov, s); ++ } + +- if (s->nb_chapters) +- mov_write_chpl_tag(pb_buf, s); ++ if (s->nb_chapters) ++ mov_write_chpl_tag(pb_buf, s); + +- if ((size = url_close_dyn_buf(pb_buf, &buf)) > 0) { +- put_be32(pb, size+8); +- put_tag(pb, "udta"); +- put_buffer(pb, buf, size); ++ if ((size = avio_close_dyn_buf(pb_buf, &buf)) > 0) { ++ avio_wb32(pb, size+8); ++ ffio_wfourcc(pb, "udta"); ++ avio_write(pb, buf, size); + } + av_free(buf); + + return 0; + } + +-static void mov_write_psp_udta_tag(ByteIOContext *pb, ++static void mov_write_psp_udta_tag(AVIOContext *pb, + const char *str, const char *lang, int type) + { + int len = utf8len(str)+1; + if(len<=0) + return; +- put_be16(pb, len*2+10); /* size */ +- put_be32(pb, type); /* type */ +- put_be16(pb, language_code(lang)); /* language */ +- put_be16(pb, 0x01); /* ? */ ++ avio_wb16(pb, len*2+10); /* size */ ++ avio_wb32(pb, type); /* type */ ++ avio_wb16(pb, language_code(lang)); /* language */ ++ avio_wb16(pb, 0x01); /* ? */ + ascii_to_wc(pb, str); + } + +-static int mov_write_uuidusmt_tag(ByteIOContext *pb, AVFormatContext *s) ++static int mov_write_uuidusmt_tag(AVIOContext *pb, AVFormatContext *s) + { +- AVMetadataTag *title = av_metadata_get(s->metadata, "title", NULL, 0); ++ AVDictionaryEntry *title = av_dict_get(s->metadata, "title", NULL, 0); + int64_t pos, pos2; + + if (title) { +- pos = url_ftell(pb); +- put_be32(pb, 0); /* size placeholder*/ +- put_tag(pb, "uuid"); +- put_tag(pb, "USMT"); +- put_be32(pb, 0x21d24fce); /* 96 bit UUID */ +- put_be32(pb, 0xbb88695c); +- put_be32(pb, 0xfac9c740); +- +- pos2 = url_ftell(pb); +- put_be32(pb, 0); /* size placeholder*/ +- put_tag(pb, "MTDT"); +- put_be16(pb, 4); ++ pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size placeholder*/ ++ ffio_wfourcc(pb, "uuid"); ++ ffio_wfourcc(pb, "USMT"); ++ avio_wb32(pb, 0x21d24fce); /* 96 bit UUID */ ++ avio_wb32(pb, 0xbb88695c); ++ avio_wb32(pb, 0xfac9c740); ++ ++ pos2 = avio_tell(pb); ++ avio_wb32(pb, 0); /* size placeholder*/ ++ ffio_wfourcc(pb, "MTDT"); ++ avio_wb16(pb, 4); + + // ? +- put_be16(pb, 0x0C); /* size */ +- put_be32(pb, 0x0B); /* type */ +- put_be16(pb, language_code("und")); /* language */ +- put_be16(pb, 0x0); /* ? */ +- put_be16(pb, 0x021C); /* data */ ++ avio_wb16(pb, 0x0C); /* size */ ++ avio_wb32(pb, 0x0B); /* type */ ++ avio_wb16(pb, language_code("und")); /* language */ ++ avio_wb16(pb, 0x0); /* ? */ ++ avio_wb16(pb, 0x021C); /* data */ + + mov_write_psp_udta_tag(pb, LIBAVCODEC_IDENT, "eng", 0x04); + mov_write_psp_udta_tag(pb, title->value, "eng", 0x01); +@@ -1706,19 +1904,43 @@ + return 0; + } + +-static int mov_write_moov_tag(ByteIOContext *pb, MOVMuxContext *mov, ++static void build_chunks(MOVTrack *trk) ++{ ++ int i; ++ MOVIentry *chunk= &trk->cluster[0]; ++ uint64_t chunkSize = chunk->size; ++ chunk->chunkNum= 1; ++ trk->chunkCount= 1; ++ for(i=1; ientry; i++){ ++ if(chunk->pos + chunkSize == trk->cluster[i].pos && ++ chunkSize + trk->cluster[i].size < (1<<20)){ ++ chunkSize += trk->cluster[i].size; ++ chunk->samplesInChunk += trk->cluster[i].entries; ++ }else{ ++ trk->cluster[i].chunkNum = chunk->chunkNum+1; ++ chunk=&trk->cluster[i]; ++ chunkSize = chunk->size; ++ trk->chunkCount++; ++ } ++ } ++} ++ ++static int mov_write_moov_tag(AVIOContext *pb, MOVMuxContext *mov, + AVFormatContext *s) + { + int i; +- int64_t pos = url_ftell(pb); +- put_be32(pb, 0); /* size placeholder*/ +- put_tag(pb, "moov"); ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size placeholder*/ ++ ffio_wfourcc(pb, "moov"); + + for (i=0; inb_streams; i++) { +- if(mov->tracks[i].entry <= 0) continue; ++ if (mov->tracks[i].entry <= 0 && !(mov->flags & FF_MOV_FLAG_FRAGMENT)) ++ continue; + + mov->tracks[i].time = mov->time; + mov->tracks[i].trackID = i+1; ++ ++ build_chunks(&mov->tracks[i]); + } + + if (mov->chapter_track) +@@ -1735,12 +1957,15 @@ + } + + mov_write_mvhd_tag(pb, mov); +- //mov_write_iods_tag(pb, mov); ++ if (mov->mode != MODE_MOV && !mov->iods_skip) ++ mov_write_iods_tag(pb, mov); + for (i=0; inb_streams; i++) { +- if(mov->tracks[i].entry > 0) { +- mov_write_trak_tag(pb, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); ++ if (mov->tracks[i].entry > 0 || mov->flags & FF_MOV_FLAG_FRAGMENT) { ++ mov_write_trak_tag(pb, mov, &(mov->tracks[i]), i < s->nb_streams ? s->streams[i] : NULL); + } + } ++ if (mov->flags & FF_MOV_FLAG_FRAGMENT) ++ mov_write_mvex_tag(pb, mov); /* QuickTime requires trak to precede this */ + + if (mov->mode == MODE_PSP) + mov_write_uuidusmt_tag(pb, s); +@@ -1750,22 +1975,307 @@ + return updateSize(pb, pos); + } + +-static int mov_write_mdat_tag(ByteIOContext *pb, MOVMuxContext *mov) ++static int mov_write_mfhd_tag(AVIOContext *pb, MOVMuxContext *mov) ++{ ++ avio_wb32(pb, 16); ++ ffio_wfourcc(pb, "mfhd"); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, mov->fragments); ++ return 0; ++} ++ ++static int mov_write_tfhd_tag(AVIOContext *pb, MOVTrack *track, ++ int64_t moof_offset) ++{ ++ int64_t pos = avio_tell(pb); ++ /* default-sample-size + default-sample-duration + base-data-offset */ ++ uint32_t flags = 0x19; ++ if (!track->entry) { ++ flags |= 0x010000; /* duration-is-empty */ ++ } else { ++ flags |= 0x20; /* default-sample-flags-present */ ++ } ++ ++ /* Don't set a default sample size when creating data for silverlight, ++ * the player refuses to play files with that set. */ ++ if (track->mode == MODE_ISM) ++ flags &= ~0x10; ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "tfhd"); ++ avio_w8(pb, 0); /* version */ ++ avio_wb24(pb, flags); ++ ++ avio_wb32(pb, track->trackID); /* track-id */ ++ if (flags & 0x01) ++ avio_wb64(pb, moof_offset); ++ if (flags & 0x08) { ++ track->default_duration = track->audio_vbr ? track->enc->frame_size : 1; ++ avio_wb32(pb, track->default_duration); ++ } ++ if (flags & 0x10) { ++ track->default_size = track->entry ? track->cluster[0].size : 1; ++ avio_wb32(pb, track->default_size); ++ } else ++ track->default_size = -1; ++ ++ if (flags & 0x20) { ++ track->default_sample_flags = ++ track->enc->codec_type == AVMEDIA_TYPE_VIDEO ? ++ 0x01010000 : 0x02000000; ++ avio_wb32(pb, track->default_sample_flags); ++ } ++ ++ return updateSize(pb, pos); ++} ++ ++static uint32_t get_sample_flags(MOVTrack *track, MOVIentry *entry) ++{ ++ return entry->flags & MOV_SYNC_SAMPLE ? 0x02000000 : 0x01010000; ++} ++ ++static int mov_write_trun_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ int64_t pos = avio_tell(pb); ++ uint32_t flags = 1; /* data-offset-present */ ++ int i; ++ ++ for (i = 0; i < track->entry; i++) { ++ int64_t duration = i + 1 == track->entry ? ++ track->trackDuration - track->cluster[i].dts + track->start_dts : ++ track->cluster[i + 1].dts - track->cluster[i].dts; ++ if (duration != track->default_duration) ++ flags |= 0x100; /* sample-duration-present */ ++ if (track->cluster[i].size != track->default_size) ++ flags |= 0x200; /* sample-size-present */ ++ if (i > 0 && get_sample_flags(track, &track->cluster[i]) != track->default_sample_flags) ++ flags |= 0x400; /* sample-flags-present */ ++ } ++ if (!(flags & 0x400)) ++ flags |= 0x4; /* first-sample-flags-present */ ++ if (track->flags & MOV_TRACK_CTTS) ++ flags |= 0x800; /* sample-composition-time-offsets-present */ ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "trun"); ++ avio_w8(pb, 0); /* version */ ++ avio_wb24(pb, flags); ++ ++ avio_wb32(pb, track->entry); /* sample count */ ++ track->moof_size_offset = avio_tell(pb); ++ avio_wb32(pb, 0); /* data offset */ ++ if (flags & 0x4) /* first sample flags */ ++ avio_wb32(pb, get_sample_flags(track, &track->cluster[0])); ++ ++ for (i = 0; i < track->entry; i++) { ++ int64_t duration = i + 1 == track->entry ? ++ track->trackDuration - track->cluster[i].dts + track->start_dts : ++ track->cluster[i + 1].dts - track->cluster[i].dts; ++ if (flags & 0x100) ++ avio_wb32(pb, duration); ++ if (flags & 0x200) ++ avio_wb32(pb, track->cluster[i].size); ++ if (flags & 0x400) ++ avio_wb32(pb, get_sample_flags(track, &track->cluster[i])); ++ if (flags & 0x800) ++ avio_wb32(pb, track->cluster[i].cts); ++ } ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_tfxd_tag(AVIOContext *pb, MOVTrack *track) ++{ ++ int64_t pos = avio_tell(pb); ++ const uint8_t uuid[] = { ++ 0x6d, 0x1d, 0x9b, 0x05, 0x42, 0xd5, 0x44, 0xe6, ++ 0x80, 0xe2, 0x14, 0x1d, 0xaf, 0xf7, 0x57, 0xb2 ++ }; ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "uuid"); ++ avio_write(pb, uuid, sizeof(uuid)); ++ avio_w8(pb, 1); ++ avio_wb24(pb, 0); ++ avio_wb64(pb, track->frag_start); ++ avio_wb64(pb, track->start_dts + track->trackDuration - ++ track->cluster[0].dts); ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_tfrf_tag(AVIOContext *pb, MOVMuxContext *mov, ++ MOVTrack *track, int entry) ++{ ++ int n = track->nb_frag_info - 1 - entry, i; ++ int size = 8 + 16 + 4 + 1 + 16*n; ++ const uint8_t uuid[] = { ++ 0xd4, 0x80, 0x7e, 0xf2, 0xca, 0x39, 0x46, 0x95, ++ 0x8e, 0x54, 0x26, 0xcb, 0x9e, 0x46, 0xa7, 0x9f ++ }; ++ ++ if (entry < 0) ++ return 0; ++ ++ avio_seek(pb, track->frag_info[entry].tfrf_offset, SEEK_SET); ++ avio_wb32(pb, size); ++ ffio_wfourcc(pb, "uuid"); ++ avio_write(pb, uuid, sizeof(uuid)); ++ avio_w8(pb, 1); ++ avio_wb24(pb, 0); ++ avio_w8(pb, n); ++ for (i = 0; i < n; i++) { ++ int index = entry + 1 + i; ++ avio_wb64(pb, track->frag_info[index].time); ++ avio_wb64(pb, track->frag_info[index].duration); ++ } ++ if (n < mov->ism_lookahead) { ++ int free_size = 16*(mov->ism_lookahead - n); ++ avio_wb32(pb, free_size); ++ ffio_wfourcc(pb, "free"); ++ for (i = 0; i < free_size - 8; i++) ++ avio_w8(pb, 0); ++ } ++ ++ return 0; ++} ++ ++static int mov_write_tfrf_tags(AVIOContext *pb, MOVMuxContext *mov, ++ MOVTrack *track) ++{ ++ int64_t pos = avio_tell(pb); ++ int i; ++ for (i = 0; i < mov->ism_lookahead; i++) { ++ /* Update the tfrf tag for the last ism_lookahead fragments, ++ * nb_frag_info - 1 is the next fragment to be written. */ ++ mov_write_tfrf_tag(pb, mov, track, track->nb_frag_info - 2 - i); ++ } ++ avio_seek(pb, pos, SEEK_SET); ++ return 0; ++} ++ ++static int mov_write_traf_tag(AVIOContext *pb, MOVMuxContext *mov, ++ MOVTrack *track, int64_t moof_offset) ++{ ++ int64_t pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "traf"); ++ ++ mov_write_tfhd_tag(pb, track, moof_offset); ++ mov_write_trun_tag(pb, track); ++ if (mov->mode == MODE_ISM) { ++ mov_write_tfxd_tag(pb, track); ++ ++ if (mov->ism_lookahead) { ++ int i, size = 16 + 4 + 1 + 16*mov->ism_lookahead; ++ ++ track->tfrf_offset = avio_tell(pb); ++ avio_wb32(pb, 8 + size); ++ ffio_wfourcc(pb, "free"); ++ for (i = 0; i < size; i++) ++ avio_w8(pb, 0); ++ } ++ } ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_moof_tag(AVIOContext *pb, MOVMuxContext *mov, int tracks) ++{ ++ int64_t pos = avio_tell(pb), end; ++ int i, moof_size; ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "moof"); ++ ++ mov_write_mfhd_tag(pb, mov); ++ for (i = 0; i < mov->nb_streams; i++) { ++ MOVTrack *track = &mov->tracks[i]; ++ if (tracks >= 0 && i != tracks) ++ continue; ++ if (!track->entry) ++ continue; ++ mov_write_traf_tag(pb, mov, track, pos); ++ } ++ ++ end = avio_tell(pb); ++ moof_size = end - pos; ++ for (i = 0; i < mov->nb_streams; i++) { ++ MOVTrack *track = &mov->tracks[i]; ++ if (tracks >= 0 && i != tracks) ++ continue; ++ if (!track->entry) ++ continue; ++ avio_seek(pb, mov->tracks[i].moof_size_offset, SEEK_SET); ++ avio_wb32(pb, moof_size + 8 + mov->tracks[i].data_offset); ++ } ++ avio_seek(pb, end, SEEK_SET); ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_tfra_tag(AVIOContext *pb, MOVTrack *track) + { +- put_be32(pb, 8); // placeholder for extended size field (64 bit) +- put_tag(pb, mov->mode == MODE_MOV ? "wide" : "free"); ++ int64_t pos = avio_tell(pb); ++ int i; ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "tfra"); ++ avio_w8(pb, 1); /* version */ ++ avio_wb24(pb, 0); ++ ++ avio_wb32(pb, track->trackID); ++ avio_wb32(pb, 0); /* length of traf/trun/sample num */ ++ avio_wb32(pb, track->nb_frag_info); ++ for (i = 0; i < track->nb_frag_info; i++) { ++ avio_wb64(pb, track->frag_info[i].time); ++ avio_wb64(pb, track->frag_info[i].offset); ++ avio_w8(pb, 1); /* traf number */ ++ avio_w8(pb, 1); /* trun number */ ++ avio_w8(pb, 1); /* sample number */ ++ } ++ ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_mfra_tag(AVIOContext *pb, MOVMuxContext *mov) ++{ ++ int64_t pos = avio_tell(pb); ++ int i; ++ ++ avio_wb32(pb, 0); /* size placeholder */ ++ ffio_wfourcc(pb, "mfra"); ++ ++ for (i = 0; i < mov->nb_streams; i++) { ++ MOVTrack *track = &mov->tracks[i]; ++ if (track->nb_frag_info) ++ mov_write_tfra_tag(pb, track); ++ } ++ ++ avio_wb32(pb, 16); ++ ffio_wfourcc(pb, "mfro"); ++ avio_wb32(pb, 0); /* version + flags */ ++ avio_wb32(pb, avio_tell(pb) + 4 - pos); + +- mov->mdat_pos = url_ftell(pb); +- put_be32(pb, 0); /* size placeholder*/ +- put_tag(pb, "mdat"); ++ return updateSize(pb, pos); ++} ++ ++static int mov_write_mdat_tag(AVIOContext *pb, MOVMuxContext *mov) ++{ ++ avio_wb32(pb, 8); // placeholder for extended size field (64 bit) ++ ffio_wfourcc(pb, mov->mode == MODE_MOV ? "wide" : "free"); ++ ++ mov->mdat_pos = avio_tell(pb); ++ avio_wb32(pb, 0); /* size placeholder*/ ++ ffio_wfourcc(pb, "mdat"); + return 0; + } + + /* TODO: This needs to be more general */ +-static int mov_write_ftyp_tag(ByteIOContext *pb, AVFormatContext *s) ++static int mov_write_ftyp_tag(AVIOContext *pb, AVFormatContext *s) + { + MOVMuxContext *mov = s->priv_data; +- int64_t pos = url_ftell(pb); ++ int64_t pos = avio_tell(pb); + int has_h264 = 0, has_video = 0; + int minor = 0x200; + int i; +@@ -1778,47 +2288,52 @@ + has_h264 = 1; + } + +- put_be32(pb, 0); /* size */ +- put_tag(pb, "ftyp"); ++ avio_wb32(pb, 0); /* size */ ++ ffio_wfourcc(pb, "ftyp"); + + if (mov->mode == MODE_3GP) { +- put_tag(pb, has_h264 ? "3gp6" : "3gp4"); ++ ffio_wfourcc(pb, has_h264 ? "3gp6" : "3gp4"); + minor = has_h264 ? 0x100 : 0x200; + } else if (mov->mode & MODE_3G2) { +- put_tag(pb, has_h264 ? "3g2b" : "3g2a"); ++ ffio_wfourcc(pb, has_h264 ? "3g2b" : "3g2a"); + minor = has_h264 ? 0x20000 : 0x10000; + }else if (mov->mode == MODE_PSP) +- put_tag(pb, "MSNV"); ++ ffio_wfourcc(pb, "MSNV"); + else if (mov->mode == MODE_MP4) +- put_tag(pb, "isom"); ++ ffio_wfourcc(pb, "isom"); + else if (mov->mode == MODE_IPOD) +- put_tag(pb, has_video ? "M4V ":"M4A "); ++ ffio_wfourcc(pb, has_video ? "M4V ":"M4A "); ++ else if (mov->mode == MODE_ISM) ++ ffio_wfourcc(pb, "isml"); + else +- put_tag(pb, "qt "); ++ ffio_wfourcc(pb, "qt "); + +- put_be32(pb, minor); ++ avio_wb32(pb, minor); + + if(mov->mode == MODE_MOV) +- put_tag(pb, "qt "); +- else{ +- put_tag(pb, "isom"); +- put_tag(pb, "iso2"); ++ ffio_wfourcc(pb, "qt "); ++ else if (mov->mode == MODE_ISM) { ++ ffio_wfourcc(pb, "piff"); ++ ffio_wfourcc(pb, "iso2"); ++ } else { ++ ffio_wfourcc(pb, "isom"); ++ ffio_wfourcc(pb, "iso2"); + if(has_h264) +- put_tag(pb, "avc1"); ++ ffio_wfourcc(pb, "avc1"); + } + + if (mov->mode == MODE_3GP) +- put_tag(pb, has_h264 ? "3gp6":"3gp4"); ++ ffio_wfourcc(pb, has_h264 ? "3gp6":"3gp4"); + else if (mov->mode & MODE_3G2) +- put_tag(pb, has_h264 ? "3g2b":"3g2a"); ++ ffio_wfourcc(pb, has_h264 ? "3g2b":"3g2a"); + else if (mov->mode == MODE_PSP) +- put_tag(pb, "MSNV"); ++ ffio_wfourcc(pb, "MSNV"); + else if (mov->mode == MODE_MP4) +- put_tag(pb, "mp41"); ++ ffio_wfourcc(pb, "mp41"); + return updateSize(pb, pos); + } + +-static void mov_write_uuidprof_tag(ByteIOContext *pb, AVFormatContext *s) ++static void mov_write_uuidprof_tag(AVIOContext *pb, AVFormatContext *s) + { + AVCodecContext *VideoCodec = s->streams[0]->codec; + AVCodecContext *AudioCodec = s->streams[1]->codec; +@@ -1827,56 +2342,56 @@ + int audio_kbitrate= AudioCodec->bit_rate / 1000; + int video_kbitrate= FFMIN(VideoCodec->bit_rate / 1000, 800 - audio_kbitrate); + +- put_be32(pb, 0x94); /* size */ +- put_tag(pb, "uuid"); +- put_tag(pb, "PROF"); +- +- put_be32(pb, 0x21d24fce); /* 96 bit UUID */ +- put_be32(pb, 0xbb88695c); +- put_be32(pb, 0xfac9c740); +- +- put_be32(pb, 0x0); /* ? */ +- put_be32(pb, 0x3); /* 3 sections ? */ +- +- put_be32(pb, 0x14); /* size */ +- put_tag(pb, "FPRF"); +- put_be32(pb, 0x0); /* ? */ +- put_be32(pb, 0x0); /* ? */ +- put_be32(pb, 0x0); /* ? */ +- +- put_be32(pb, 0x2c); /* size */ +- put_tag(pb, "APRF"); /* audio */ +- put_be32(pb, 0x0); +- put_be32(pb, 0x2); /* TrackID */ +- put_tag(pb, "mp4a"); +- put_be32(pb, 0x20f); +- put_be32(pb, 0x0); +- put_be32(pb, audio_kbitrate); +- put_be32(pb, audio_kbitrate); +- put_be32(pb, AudioRate); +- put_be32(pb, AudioCodec->channels); +- +- put_be32(pb, 0x34); /* size */ +- put_tag(pb, "VPRF"); /* video */ +- put_be32(pb, 0x0); +- put_be32(pb, 0x1); /* TrackID */ ++ avio_wb32(pb, 0x94); /* size */ ++ ffio_wfourcc(pb, "uuid"); ++ ffio_wfourcc(pb, "PROF"); ++ ++ avio_wb32(pb, 0x21d24fce); /* 96 bit UUID */ ++ avio_wb32(pb, 0xbb88695c); ++ avio_wb32(pb, 0xfac9c740); ++ ++ avio_wb32(pb, 0x0); /* ? */ ++ avio_wb32(pb, 0x3); /* 3 sections ? */ ++ ++ avio_wb32(pb, 0x14); /* size */ ++ ffio_wfourcc(pb, "FPRF"); ++ avio_wb32(pb, 0x0); /* ? */ ++ avio_wb32(pb, 0x0); /* ? */ ++ avio_wb32(pb, 0x0); /* ? */ ++ ++ avio_wb32(pb, 0x2c); /* size */ ++ ffio_wfourcc(pb, "APRF");/* audio */ ++ avio_wb32(pb, 0x0); ++ avio_wb32(pb, 0x2); /* TrackID */ ++ ffio_wfourcc(pb, "mp4a"); ++ avio_wb32(pb, 0x20f); ++ avio_wb32(pb, 0x0); ++ avio_wb32(pb, audio_kbitrate); ++ avio_wb32(pb, audio_kbitrate); ++ avio_wb32(pb, AudioRate); ++ avio_wb32(pb, AudioCodec->channels); ++ ++ avio_wb32(pb, 0x34); /* size */ ++ ffio_wfourcc(pb, "VPRF"); /* video */ ++ avio_wb32(pb, 0x0); ++ avio_wb32(pb, 0x1); /* TrackID */ + if (VideoCodec->codec_id == CODEC_ID_H264) { +- put_tag(pb, "avc1"); +- put_be16(pb, 0x014D); +- put_be16(pb, 0x0015); ++ ffio_wfourcc(pb, "avc1"); ++ avio_wb16(pb, 0x014D); ++ avio_wb16(pb, 0x0015); + } else { +- put_tag(pb, "mp4v"); +- put_be16(pb, 0x0000); +- put_be16(pb, 0x0103); +- } +- put_be32(pb, 0x0); +- put_be32(pb, video_kbitrate); +- put_be32(pb, video_kbitrate); +- put_be32(pb, FrameRate); +- put_be32(pb, FrameRate); +- put_be16(pb, VideoCodec->width); +- put_be16(pb, VideoCodec->height); +- put_be32(pb, 0x010001); /* ? */ ++ ffio_wfourcc(pb, "mp4v"); ++ avio_wb16(pb, 0x0000); ++ avio_wb16(pb, 0x0103); ++ } ++ avio_wb32(pb, 0x0); ++ avio_wb32(pb, video_kbitrate); ++ avio_wb32(pb, video_kbitrate); ++ avio_wb32(pb, FrameRate); ++ avio_wb32(pb, FrameRate); ++ avio_wb16(pb, VideoCodec->width); ++ avio_wb16(pb, VideoCodec->height); ++ avio_wb32(pb, 0x010001); /* ? */ + } + + static int mov_parse_mpeg2_frame(AVPacket *pkt, uint32_t *flags) +@@ -1900,22 +2415,148 @@ + return 0; + } + +-int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) ++static int mov_flush_fragment(AVFormatContext *s) ++{ ++ MOVMuxContext *mov = s->priv_data; ++ int i, first_track = -1; ++ int64_t mdat_size = 0; ++ ++ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) ++ return 0; ++ ++ if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV) && mov->fragments == 0) { ++ int64_t pos = avio_tell(s->pb); ++ ++ for (i = 0; i < mov->nb_streams; i++) ++ if (!mov->tracks[i].entry) ++ break; ++ /* Don't write the initial moov unless all tracks have data */ ++ if (i < mov->nb_streams) ++ return 0; ++ avio_seek(s->pb, mov->mdat_pos, SEEK_SET); ++ avio_wb32(s->pb, mov->mdat_size + 8); ++ avio_seek(s->pb, pos, SEEK_SET); ++ mov_write_moov_tag(s->pb, mov, s); ++ mov->fragments++; ++ mov->mdat_size = 0; ++ for (i = 0; i < mov->nb_streams; i++) { ++ if (mov->tracks[i].entry) ++ mov->tracks[i].frag_start += mov->tracks[i].start_dts + ++ mov->tracks[i].trackDuration - ++ mov->tracks[i].cluster[0].dts; ++ mov->tracks[i].entry = 0; ++ } ++ return 0; ++ } ++ ++ for (i = 0; i < mov->nb_streams; i++) { ++ MOVTrack *track = &mov->tracks[i]; ++ if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) ++ track->data_offset = 0; ++ else ++ track->data_offset = mdat_size; ++ if (!track->mdat_buf) ++ continue; ++ mdat_size += avio_tell(track->mdat_buf); ++ if (first_track < 0) ++ first_track = i; ++ } ++ ++ if (!mdat_size) ++ return 0; ++ ++ for (i = 0; i < mov->nb_streams; i++) { ++ MOVTrack *track = &mov->tracks[i]; ++ int buf_size, write_moof = 1, moof_tracks = -1; ++ uint8_t *buf; ++ int64_t duration = 0; ++ ++ if (track->entry) ++ duration = track->start_dts + track->trackDuration - ++ track->cluster[0].dts; ++ if (mov->flags & FF_MOV_FLAG_SEPARATE_MOOF) { ++ if (!track->mdat_buf) ++ continue; ++ mdat_size = avio_tell(track->mdat_buf); ++ moof_tracks = i; ++ } else { ++ write_moof = i == first_track; ++ } ++ ++ if (write_moof) { ++ MOVFragmentInfo *info; ++ track->nb_frag_info++; ++ track->frag_info = av_realloc(track->frag_info, ++ sizeof(*track->frag_info) * ++ track->nb_frag_info); ++ info = &track->frag_info[track->nb_frag_info - 1]; ++ info->offset = avio_tell(s->pb); ++ info->time = mov->tracks[i].frag_start; ++ info->duration = duration; ++ mov_write_tfrf_tags(s->pb, mov, track); ++ ++ mov_write_moof_tag(s->pb, mov, moof_tracks); ++ info->tfrf_offset = track->tfrf_offset; ++ mov->fragments++; ++ ++ avio_wb32(s->pb, mdat_size + 8); ++ ffio_wfourcc(s->pb, "mdat"); ++ } ++ ++ if (track->entry) ++ track->frag_start += duration; ++ track->entry = 0; ++ if (!track->mdat_buf) ++ continue; ++ buf_size = avio_close_dyn_buf(track->mdat_buf, &buf); ++ track->mdat_buf = NULL; ++ ++ avio_write(s->pb, buf, buf_size); ++ av_free(buf); ++ } ++ ++ mov->mdat_size = 0; ++ ++ return 0; ++} ++ ++static int mov_write_packet_internal(AVFormatContext *s, AVPacket *pkt) + { + MOVMuxContext *mov = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + MOVTrack *trk = &mov->tracks[pkt->stream_index]; + AVCodecContext *enc = trk->enc; + unsigned int samplesInChunk = 0; + int size= pkt->size; ++ uint8_t *reformatted_data = NULL; + +- if (url_is_streamed(s->pb)) return 0; /* Can't handle that */ ++ if (!s->pb->seekable) return 0; /* Can't handle that */ + if (!size) return 0; /* Discard 0 sized packets */ + ++ if ((mov->max_fragment_duration && trk->entry && ++ av_rescale_q(pkt->dts - trk->cluster[0].dts, ++ s->streams[pkt->stream_index]->time_base, ++ AV_TIME_BASE_Q) >= mov->max_fragment_duration) || ++ (mov->max_fragment_size && mov->mdat_size + size >= mov->max_fragment_size) || ++ (mov->flags & FF_MOV_FLAG_FRAG_KEYFRAME && ++ enc->codec_type == AVMEDIA_TYPE_VIDEO && ++ trk->entry && pkt->flags & AV_PKT_FLAG_KEY)) { ++ mov_flush_fragment(s); ++ } ++ ++ if (mov->flags & FF_MOV_FLAG_FRAGMENT && mov->fragments > 0) { ++ if (!trk->mdat_buf) { ++ int ret; ++ if ((ret = avio_open_dyn_buf(&trk->mdat_buf)) < 0) ++ return ret; ++ } ++ pb = trk->mdat_buf; ++ } ++ + if (enc->codec_id == CODEC_ID_AMR_NB) { + /* We must find out how many AMR blocks there are in one packet */ + static uint16_t packed_size[16] = +- {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 0}; ++ {13, 14, 16, 18, 20, 21, 27, 32, 6, 0, 0, 0, 0, 0, 0, 1}; + int len = 0; + + while (len < size && samplesInChunk < 100) { +@@ -1944,9 +2585,19 @@ + if (enc->codec_id == CODEC_ID_H264 && trk->vosLen > 0 && *(uint8_t *)trk->vosData != 1) { + /* from x264 or from bytestream h264 */ + /* nal reformating needed */ +- size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size); ++ if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) { ++ ff_avc_parse_nal_units_buf(pkt->data, &reformatted_data, ++ &size); ++ avio_write(pb, reformatted_data, size); ++ } else { ++ size = ff_avc_parse_nal_units(pb, pkt->data, pkt->size); ++ } ++ } else if (enc->codec_id == CODEC_ID_AAC && pkt->size > 2 && ++ (AV_RB16(pkt->data) & 0xfff0) == 0xfff0) { ++ av_log(s, AV_LOG_ERROR, "malformated aac bitstream, use -absf aac_adtstoasc\n"); ++ return -1; + } else { +- put_buffer(pb, pkt->data, size); ++ avio_write(pb, pkt->data, size); + } + + if ((enc->codec_id == CODEC_ID_DNXHD || +@@ -1960,17 +2611,27 @@ + } + + if (!(trk->entry % MOV_INDEX_CLUSTER_SIZE)) { +- trk->cluster = av_realloc(trk->cluster, (trk->entry + MOV_INDEX_CLUSTER_SIZE) * sizeof(*trk->cluster)); ++ trk->cluster = av_realloc_f(trk->cluster, sizeof(*trk->cluster), (trk->entry + MOV_INDEX_CLUSTER_SIZE)); + if (!trk->cluster) + return -1; + } + +- trk->cluster[trk->entry].pos = url_ftell(pb) - size; ++ trk->cluster[trk->entry].pos = avio_tell(pb) - size; + trk->cluster[trk->entry].samplesInChunk = samplesInChunk; ++ trk->cluster[trk->entry].chunkNum = 0; + trk->cluster[trk->entry].size = size; + trk->cluster[trk->entry].entries = samplesInChunk; + trk->cluster[trk->entry].dts = pkt->dts; +- trk->trackDuration = pkt->dts - trk->cluster[0].dts + pkt->duration; ++ if (!trk->entry && trk->start_dts != AV_NOPTS_VALUE) { ++ /* First packet of a new fragment. We already wrote the duration ++ * of the last packet of the previous fragment based on trackDuration, ++ * which might not exactly match our dts. Therefore adjust the dts ++ * of this packet to be what the previous packets duration implies. */ ++ trk->cluster[trk->entry].dts = trk->start_dts + trk->trackDuration; ++ } ++ if (trk->start_dts == AV_NOPTS_VALUE) ++ trk->start_dts = pkt->dts; ++ trk->trackDuration = pkt->dts - trk->start_dts + pkt->duration; + + if (pkt->pts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_WARNING, "pts has no value\n"); +@@ -1981,7 +2642,8 @@ + trk->cluster[trk->entry].cts = pkt->pts - pkt->dts; + trk->cluster[trk->entry].flags = 0; + if (pkt->flags & AV_PKT_FLAG_KEY) { +- if (mov->mode == MODE_MOV && enc->codec_id == CODEC_ID_MPEG2VIDEO) { ++ if (mov->mode == MODE_MOV && enc->codec_id == CODEC_ID_MPEG2VIDEO && ++ trk->entry > 0) { // force sync sample for the first key frame + mov_parse_mpeg2_frame(pkt, &trk->cluster[trk->entry].flags); + if (trk->cluster[trk->entry].flags & MOV_PARTIAL_SYNC_SAMPLE) + trk->flags |= MOV_TRACK_STPS; +@@ -1995,13 +2657,25 @@ + trk->sampleCount += samplesInChunk; + mov->mdat_size += size; + +- put_flush_packet(pb); ++ avio_flush(pb); + + if (trk->hint_track >= 0 && trk->hint_track < mov->nb_streams) +- ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry); ++ ff_mov_add_hinted_packet(s, pkt, trk->hint_track, trk->entry, ++ reformatted_data, size); ++ av_free(reformatted_data); + return 0; + } + ++int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ if (!pkt) { ++ mov_flush_fragment(s); ++ return 1; ++ } else { ++ return mov_write_packet_internal(s, pkt); ++ } ++} ++ + // QuickTime chapters involve an additional text track with the chapter names + // as samples, and a tref pointing from the other tracks to the chapter one. + static void mov_create_chapter_track(AVFormatContext *s, int tracknum) +@@ -2014,18 +2688,18 @@ + track->mode = mov->mode; + track->tag = MKTAG('t','e','x','t'); + track->timescale = MOV_TIMESCALE; +- track->enc = avcodec_alloc_context(); ++ track->enc = avcodec_alloc_context3(NULL); + track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE; + + for (i = 0; i < s->nb_chapters; i++) { + AVChapter *c = s->chapters[i]; +- AVMetadataTag *t; ++ AVDictionaryEntry *t; + + int64_t end = av_rescale_q(c->end, c->time_base, (AVRational){1,MOV_TIMESCALE}); + pkt.pts = pkt.dts = av_rescale_q(c->start, c->time_base, (AVRational){1,MOV_TIMESCALE}); + pkt.duration = end - pkt.dts; + +- if ((t = av_metadata_get(c->metadata, "title", NULL, 0))) { ++ if ((t = av_dict_get(c->metadata, "title", NULL, 0))) { + len = strlen(t->value); + pkt.size = len+2; + pkt.data = av_malloc(pkt.size); +@@ -2039,11 +2713,12 @@ + + static int mov_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + MOVMuxContext *mov = s->priv_data; ++ AVDictionaryEntry *t; + int i, hint_track = 0; + +- if (url_is_streamed(s->pb)) { ++ if (!s->pb->seekable) { + av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); + return -1; + } +@@ -2057,6 +2732,7 @@ + else if (!strcmp("mov", s->oformat->name)) mov->mode = MODE_MOV; + else if (!strcmp("psp", s->oformat->name)) mov->mode = MODE_PSP; + else if (!strcmp("ipod",s->oformat->name)) mov->mode = MODE_IPOD; ++ else if (!strcmp("ismv",s->oformat->name)) mov->mode = MODE_ISM; + + mov_write_ftyp_tag(pb,s); + if (mov->mode == MODE_PSP) { +@@ -2072,7 +2748,15 @@ + if (mov->mode & (MODE_MOV|MODE_IPOD) && s->nb_chapters) + mov->chapter_track = mov->nb_streams++; + ++#if FF_API_FLAG_RTP_HINT + if (s->flags & AVFMT_FLAG_RTP_HINT) { ++ av_log(s, AV_LOG_WARNING, "The RTP_HINT flag is deprecated, enable it " ++ "via the -movflags rtphint muxer option " ++ "instead.\n"); ++ mov->flags |= FF_MOV_FLAG_RTP_HINT; ++ } ++#endif ++ if (mov->flags & FF_MOV_FLAG_RTP_HINT) { + /* Add hint tracks for each audio and video stream */ + hint_track = mov->nb_streams; + for (i = 0; i < s->nb_streams; i++) { +@@ -2091,7 +2775,7 @@ + for(i=0; inb_streams; i++){ + AVStream *st= s->streams[i]; + MOVTrack *track= &mov->tracks[i]; +- AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0); ++ AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); + + track->enc = st->codec; + track->language = ff_mov_iso639_to_lang(lang?lang->value:"und", mov->mode!=MODE_MOV); +@@ -2107,6 +2791,7 @@ + /* If hinting of this track is enabled by a later hint track, + * this is updated. */ + track->hint_track = -1; ++ track->start_dts = AV_NOPTS_VALUE; + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ + if (track->tag == MKTAG('m','x','3','p') || track->tag == MKTAG('m','x','3','n') || + track->tag == MKTAG('m','x','4','p') || track->tag == MKTAG('m','x','4','n') || +@@ -2158,17 +2843,60 @@ + } + if (!track->height) + track->height = st->codec->height; ++ /* The ism specific timescale isn't mandatory, but is assumed by ++ * some tools, such as mp4split. */ ++ if (mov->mode == MODE_ISM) ++ track->timescale = 10000000; + +- av_set_pts_info(st, 64, 1, track->timescale); ++ avpriv_set_pts_info(st, 64, 1, track->timescale); ++ ++ /* copy extradata if it exists */ ++ if (st->codec->extradata_size) { ++ track->vosLen = st->codec->extradata_size; ++ track->vosData = av_malloc(track->vosLen); ++ memcpy(track->vosData, st->codec->extradata, track->vosLen); ++ } + } + +- mov_write_mdat_tag(pb, mov); +- mov->time = s->timestamp + 0x7C25B080; //1970 based -> 1904 based ++ if (mov->mode == MODE_ISM) { ++ /* If no fragmentation options have been set, set a default. */ ++ if (!(mov->flags & (FF_MOV_FLAG_FRAG_KEYFRAME | ++ FF_MOV_FLAG_FRAG_CUSTOM)) && ++ !mov->max_fragment_duration && !mov->max_fragment_size) ++ mov->max_fragment_duration = 5000000; ++ mov->flags |= FF_MOV_FLAG_EMPTY_MOOV | FF_MOV_FLAG_SEPARATE_MOOF; ++ } ++ ++ if(mov->reserved_moov_size){ ++ mov->reserved_moov_pos= avio_tell(pb); ++ avio_skip(pb, mov->reserved_moov_size); ++ } ++ ++ /* Set the FRAGMENT flag if any of the fragmentation methods are ++ * enabled. */ ++ if (mov->max_fragment_duration || mov->max_fragment_size || ++ mov->flags & (FF_MOV_FLAG_EMPTY_MOOV | ++ FF_MOV_FLAG_FRAG_KEYFRAME | ++ FF_MOV_FLAG_FRAG_CUSTOM)) ++ mov->flags |= FF_MOV_FLAG_FRAGMENT; ++ ++ if (!(mov->flags & FF_MOV_FLAG_EMPTY_MOOV)) ++ mov_write_mdat_tag(pb, mov); ++ ++#if FF_API_TIMESTAMP ++ if (s->timestamp) ++ mov->time = s->timestamp; ++ else ++#endif ++ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) ++ mov->time = ff_iso8601_to_unix_time(t->value); ++ if (mov->time) ++ mov->time += 0x7C25B080; // 1970 based -> 1904 based + + if (mov->chapter_track) + mov_create_chapter_track(s, mov->chapter_track); + +- if (s->flags & AVFMT_FLAG_RTP_HINT) { ++ if (mov->flags & FF_MOV_FLAG_RTP_HINT) { + /* Initialize the hint tracks for each audio and video stream */ + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; +@@ -2180,7 +2908,12 @@ + } + } + +- put_flush_packet(pb); ++ avio_flush(pb); ++ ++ if (mov->flags & FF_MOV_FLAG_EMPTY_MOOV) { ++ mov_write_moov_tag(pb, mov, s); ++ mov->fragments++; ++ } + + return 0; + error: +@@ -2191,26 +2924,45 @@ + static int mov_write_trailer(AVFormatContext *s) + { + MOVMuxContext *mov = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int res = 0; + int i; + +- int64_t moov_pos = url_ftell(pb); ++ int64_t moov_pos = avio_tell(pb); + +- /* Write size of mdat tag */ +- if (mov->mdat_size+8 <= UINT32_MAX) { +- url_fseek(pb, mov->mdat_pos, SEEK_SET); +- put_be32(pb, mov->mdat_size+8); ++ if (!(mov->flags & FF_MOV_FLAG_FRAGMENT)) { ++ /* Write size of mdat tag */ ++ if (mov->mdat_size + 8 <= UINT32_MAX) { ++ avio_seek(pb, mov->mdat_pos, SEEK_SET); ++ avio_wb32(pb, mov->mdat_size + 8); ++ } else { ++ /* overwrite 'wide' placeholder atom */ ++ avio_seek(pb, mov->mdat_pos - 8, SEEK_SET); ++ /* special value: real atom size will be 64 bit value after ++ * tag field */ ++ avio_wb32(pb, 1); ++ ffio_wfourcc(pb, "mdat"); ++ avio_wb64(pb, mov->mdat_size + 16); ++ } ++ avio_seek(pb, mov->reserved_moov_size ? mov->reserved_moov_pos : moov_pos, SEEK_SET); ++ ++ mov_write_moov_tag(pb, mov, s); ++ if(mov->reserved_moov_size){ ++ int64_t size= mov->reserved_moov_size - (avio_tell(pb) - mov->reserved_moov_pos); ++ if(size < 8){ ++ av_log(s, AV_LOG_ERROR, "reserved_moov_size is too small, needed %"PRId64" additional\n", 8-size); ++ return -1; ++ } ++ avio_wb32(pb, size); ++ ffio_wfourcc(pb, "free"); ++ for(i=0; imdat_pos - 8, SEEK_SET); +- put_be32(pb, 1); /* special value: real atom size will be 64 bit value after tag field */ +- put_tag(pb, "mdat"); +- put_be64(pb, mov->mdat_size+16); ++ mov_flush_fragment(s); ++ mov_write_mfra_tag(pb, mov); + } +- url_fseek(pb, moov_pos, SEEK_SET); +- +- mov_write_moov_tag(pb, mov, s); + + if (mov->chapter_track) + av_freep(&mov->tracks[mov->chapter_track].enc); +@@ -2219,12 +2971,13 @@ + if (mov->tracks[i].tag == MKTAG('r','t','p',' ')) + ff_mov_close_hinting(&mov->tracks[i]); + av_freep(&mov->tracks[i].cluster); ++ av_freep(&mov->tracks[i].frag_info); + + if(mov->tracks[i].vosLen) av_free(mov->tracks[i].vosData); + + } + +- put_flush_packet(pb); ++ avio_flush(pb); + + av_freep(&mov->tracks); + +@@ -2232,98 +2985,136 @@ + } + + #if CONFIG_MOV_MUXER ++MOV_CLASS(mov) + AVOutputFormat ff_mov_muxer = { +- "mov", +- NULL_IF_CONFIG_SMALL("MOV format"), +- NULL, +- "mov", +- sizeof(MOVMuxContext), +- CODEC_ID_AAC, +- CODEC_ID_MPEG4, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "mov", ++ .long_name = NULL_IF_CONFIG_SMALL("MOV format"), ++ .extensions = "mov", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AAC, ++#if CONFIG_LIBX264_ENCODER ++ .video_codec = CODEC_ID_H264, ++#else ++ .video_codec = CODEC_ID_MPEG4, ++#endif ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){codec_movvideo_tags, codec_movaudio_tags, 0}, ++ .priv_class = &mov_muxer_class, + }; + #endif + #if CONFIG_TGP_MUXER ++MOV_CLASS(tgp) + AVOutputFormat ff_tgp_muxer = { +- "3gp", +- NULL_IF_CONFIG_SMALL("3GP format"), +- NULL, +- "3gp", +- sizeof(MOVMuxContext), +- CODEC_ID_AMR_NB, +- CODEC_ID_H263, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "3gp", ++ .long_name = NULL_IF_CONFIG_SMALL("3GP format"), ++ .extensions = "3gp", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AMR_NB, ++ .video_codec = CODEC_ID_H263, ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, ++ .priv_class = &tgp_muxer_class, + }; + #endif + #if CONFIG_MP4_MUXER ++MOV_CLASS(mp4) + AVOutputFormat ff_mp4_muxer = { +- "mp4", +- NULL_IF_CONFIG_SMALL("MP4 format"), +- "application/mp4", +- "mp4", +- sizeof(MOVMuxContext), +- CODEC_ID_AAC, +- CODEC_ID_MPEG4, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "mp4", ++ .long_name = NULL_IF_CONFIG_SMALL("MP4 format"), ++ .mime_type = "application/mp4", ++ .extensions = "mp4", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AAC, ++#if CONFIG_LIBX264_ENCODER ++ .video_codec = CODEC_ID_H264, ++#else ++ .video_codec = CODEC_ID_MPEG4, ++#endif ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, ++ .priv_class = &mp4_muxer_class, + }; + #endif + #if CONFIG_PSP_MUXER ++MOV_CLASS(psp) + AVOutputFormat ff_psp_muxer = { +- "psp", +- NULL_IF_CONFIG_SMALL("PSP MP4 format"), +- NULL, +- "mp4,psp", +- sizeof(MOVMuxContext), +- CODEC_ID_AAC, +- CODEC_ID_MPEG4, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "psp", ++ .long_name = NULL_IF_CONFIG_SMALL("PSP MP4 format"), ++ .extensions = "mp4,psp", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AAC, ++#if CONFIG_LIBX264_ENCODER ++ .video_codec = CODEC_ID_H264, ++#else ++ .video_codec = CODEC_ID_MPEG4, ++#endif ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, ++ .priv_class = &psp_muxer_class, + }; + #endif + #if CONFIG_TG2_MUXER ++MOV_CLASS(tg2) + AVOutputFormat ff_tg2_muxer = { +- "3g2", +- NULL_IF_CONFIG_SMALL("3GP2 format"), +- NULL, +- "3g2", +- sizeof(MOVMuxContext), +- CODEC_ID_AMR_NB, +- CODEC_ID_H263, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "3g2", ++ .long_name = NULL_IF_CONFIG_SMALL("3GP2 format"), ++ .extensions = "3g2", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AMR_NB, ++ .video_codec = CODEC_ID_H263, ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){codec_3gp_tags, 0}, ++ .priv_class = &tg2_muxer_class, + }; + #endif + #if CONFIG_IPOD_MUXER ++MOV_CLASS(ipod) + AVOutputFormat ff_ipod_muxer = { +- "ipod", +- NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"), +- "application/mp4", +- "m4v,m4a", +- sizeof(MOVMuxContext), +- CODEC_ID_AAC, +- CODEC_ID_H264, +- mov_write_header, +- ff_mov_write_packet, +- mov_write_trailer, +- .flags = AVFMT_GLOBALHEADER, ++ .name = "ipod", ++ .long_name = NULL_IF_CONFIG_SMALL("iPod H.264 MP4 format"), ++ .mime_type = "application/mp4", ++ .extensions = "m4v,m4a", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_H264, ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, + .codec_tag = (const AVCodecTag* const []){codec_ipod_tags, 0}, ++ .priv_class = &ipod_muxer_class, ++}; ++#endif ++#if CONFIG_ISMV_MUXER ++MOV_CLASS(ismv) ++AVOutputFormat ff_ismv_muxer = { ++ .name = "ismv", ++ .long_name = NULL_IF_CONFIG_SMALL("ISMV/ISMA (Smooth Streaming) format"), ++ .mime_type = "application/mp4", ++ .extensions = "ismv,isma", ++ .priv_data_size = sizeof(MOVMuxContext), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_H264, ++ .write_header = mov_write_header, ++ .write_packet = ff_mov_write_packet, ++ .write_trailer = mov_write_trailer, ++ .flags = AVFMT_GLOBALHEADER | AVFMT_ALLOW_FLUSH, ++ .codec_tag = (const AVCodecTag* const []){ff_mp4_obj_type, 0}, ++ .priv_class = &ismv_muxer_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenc.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenc.h 2012-05-14 14:08:55.050354392 +0200 +@@ -38,14 +38,16 @@ + // ffmpeg -i testinput.avi -f psp -r 14.985 -s 320x240 -b 768 -ar 24000 -ab 32 M4V00001.MP4 + #define MODE_3G2 0x10 + #define MODE_IPOD 0x20 ++#define MODE_ISM 0x40 + + typedef struct MOVIentry { +- unsigned int size; + uint64_t pos; ++ int64_t dts; ++ unsigned int size; + unsigned int samplesInChunk; ++ unsigned int chunkNum; ///< Chunk number if the current entry is a chunk start otherwise 0 + unsigned int entries; + int cts; +- int64_t dts; + #define MOV_SYNC_SAMPLE 0x0001 + #define MOV_PARTIAL_SYNC_SAMPLE 0x0002 + uint32_t flags; +@@ -65,6 +67,13 @@ + HintSample *samples; + } HintSampleQueue; + ++typedef struct { ++ int64_t offset; ++ int64_t time; ++ int64_t duration; ++ int64_t tfrf_offset; ++} MOVFragmentInfo; ++ + typedef struct MOVIndex { + int mode; + int entry; +@@ -73,6 +82,7 @@ + int64_t trackDuration; + long sampleCount; + long sampleSize; ++ long chunkCount; + int hasKeyframes; + #define MOV_TRACK_CTTS 0x0001 + #define MOV_TRACK_STPS 0x0002 +@@ -89,6 +99,7 @@ + int height; ///< active picture (w/o VBI) height for D-10/IMX + uint32_t tref_tag; + int tref_id; ///< trackID of the referenced track ++ int64_t start_dts; + + int hint_track; ///< the track that hints this track, -1 if no hint track is set + int src_track; ///< the track that this hint track describes +@@ -97,10 +108,24 @@ + int64_t cur_rtp_ts_unwrapped; + uint32_t max_packet_size; + ++ int64_t default_duration; ++ uint32_t default_sample_flags; ++ uint32_t default_size; ++ + HintSampleQueue sample_queue; ++ ++ AVIOContext *mdat_buf; ++ int64_t moof_size_offset; ++ int64_t data_offset; ++ int64_t frag_start; ++ int64_t tfrf_offset; ++ ++ int nb_frag_info; ++ MOVFragmentInfo *frag_info; + } MOVTrack; + + typedef struct MOVMuxContext { ++ const AVClass *av_class; + int mode; + int64_t time; + int nb_streams; +@@ -108,13 +133,35 @@ + int64_t mdat_pos; + uint64_t mdat_size; + MOVTrack *tracks; ++ ++ int flags; ++ int rtp_flags; ++ int reserved_moov_size; ++ int64_t reserved_moov_pos; ++ ++ int iods_skip; ++ int iods_video_profile; ++ int iods_audio_profile; ++ ++ int fragments; ++ int max_fragment_duration; ++ int max_fragment_size; ++ int ism_lookahead; + } MOVMuxContext; + ++#define FF_MOV_FLAG_RTP_HINT 1 ++#define FF_MOV_FLAG_FRAGMENT 2 ++#define FF_MOV_FLAG_EMPTY_MOOV 4 ++#define FF_MOV_FLAG_FRAG_KEYFRAME 8 ++#define FF_MOV_FLAG_SEPARATE_MOOF 16 ++#define FF_MOV_FLAG_FRAG_CUSTOM 32 ++ + int ff_mov_write_packet(AVFormatContext *s, AVPacket *pkt); + + int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index); + int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, +- int track_index, int sample); ++ int track_index, int sample, ++ uint8_t *sample_data, int sample_size); + void ff_mov_close_hinting(MOVTrack *track); + + #endif /* AVFORMAT_MOVENC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenchint.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenchint.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/movenchint.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/movenchint.c 2012-05-14 14:08:55.052354432 +0200 +@@ -22,6 +22,8 @@ + #include "movenc.h" + #include "libavutil/intreadwrite.h" + #include "internal.h" ++#include "rtpenc_chain.h" ++#include "avio_internal.h" + + int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index) + { +@@ -30,44 +32,20 @@ + MOVTrack *src_track = &mov->tracks[src_index]; + AVStream *src_st = s->streams[src_index]; + int ret = AVERROR(ENOMEM); +- AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); + + track->tag = MKTAG('r','t','p',' '); + track->src_track = src_index; + +- if (!rtp_format) { +- ret = AVERROR(ENOENT); +- goto fail; +- } +- +- track->enc = avcodec_alloc_context(); ++ track->enc = avcodec_alloc_context3(NULL); + if (!track->enc) + goto fail; + track->enc->codec_type = AVMEDIA_TYPE_DATA; + track->enc->codec_tag = track->tag; + +- track->rtp_ctx = avformat_alloc_context(); ++ track->rtp_ctx = ff_rtp_chain_mux_open(s, src_st, NULL, ++ RTP_MAX_PACKET_SIZE); + if (!track->rtp_ctx) + goto fail; +- track->rtp_ctx->oformat = rtp_format; +- if (!av_new_stream(track->rtp_ctx, 0)) +- goto fail; +- +- /* Copy stream parameters */ +- track->rtp_ctx->streams[0]->sample_aspect_ratio = +- src_st->sample_aspect_ratio; +- +- /* Remove the allocated codec context, link to the original one +- * instead, to give the rtp muxer access to codec parameters. */ +- av_free(track->rtp_ctx->streams[0]->codec); +- track->rtp_ctx->streams[0]->codec = src_st->codec; +- +- if ((ret = url_open_dyn_packet_buf(&track->rtp_ctx->pb, +- RTP_MAX_PACKET_SIZE)) < 0) +- goto fail; +- ret = av_write_header(track->rtp_ctx); +- if (ret) +- goto fail; + + /* Copy the RTP AVStream timebase back to the hint AVStream */ + track->timescale = track->rtp_ctx->streams[0]->time_base.den; +@@ -79,22 +57,8 @@ + fail: + av_log(s, AV_LOG_WARNING, + "Unable to initialize hinting of stream %d\n", src_index); +- if (track->rtp_ctx && track->rtp_ctx->pb) { +- uint8_t *buf; +- url_close_dyn_buf(track->rtp_ctx->pb, &buf); +- av_free(buf); +- } +- if (track->rtp_ctx && track->rtp_ctx->streams[0]) { +- av_metadata_free(&track->rtp_ctx->streams[0]->metadata); +- av_free(track->rtp_ctx->streams[0]); +- } +- if (track->rtp_ctx) { +- av_metadata_free(&track->rtp_ctx->metadata); +- av_free(track->rtp_ctx->priv_data); +- av_freep(&track->rtp_ctx); +- } + av_freep(&track->enc); +- /* Set a default timescale, to avoid crashes in dump_format */ ++ /* Set a default timescale, to avoid crashes in av_dump_format */ + track->timescale = 90000; + return ret; + } +@@ -131,11 +95,12 @@ + * not copied. sample_queue_retain should be called before pkt->data + * is reused/freed. + */ +-static void sample_queue_push(HintSampleQueue *queue, AVPacket *pkt, int sample) ++static void sample_queue_push(HintSampleQueue *queue, uint8_t *data, int size, ++ int sample) + { + /* No need to keep track of smaller samples, since describing them + * with immediates is more efficient. */ +- if (pkt->size <= 14) ++ if (size <= 14) + return; + if (!queue->samples || queue->len >= queue->size) { + HintSample* samples; +@@ -145,8 +110,8 @@ + return; + queue->samples = samples; + } +- queue->samples[queue->len].data = pkt->data; +- queue->samples[queue->len].size = pkt->size; ++ queue->samples[queue->len].data = data; ++ queue->samples[queue->len].size = size; + queue->samples[queue->len].sample_number = sample; + queue->samples[queue->len].offset = 0; + queue->samples[queue->len].own_data = 0; +@@ -282,40 +247,40 @@ + } + + static void output_immediate(const uint8_t *data, int size, +- ByteIOContext *out, int *entries) ++ AVIOContext *out, int *entries) + { + while (size > 0) { + int len = size; + if (len > 14) + len = 14; +- put_byte(out, 1); /* immediate constructor */ +- put_byte(out, len); /* amount of valid data */ +- put_buffer(out, data, len); ++ avio_w8(out, 1); /* immediate constructor */ ++ avio_w8(out, len); /* amount of valid data */ ++ avio_write(out, data, len); + data += len; + size -= len; + + for (; len < 14; len++) +- put_byte(out, 0); ++ avio_w8(out, 0); + + (*entries)++; + } + } + +-static void output_match(ByteIOContext *out, int match_sample, ++static void output_match(AVIOContext *out, int match_sample, + int match_offset, int match_len, int *entries) + { +- put_byte(out, 2); /* sample constructor */ +- put_byte(out, 0); /* track reference */ +- put_be16(out, match_len); +- put_be32(out, match_sample); +- put_be32(out, match_offset); +- put_be16(out, 1); /* bytes per block */ +- put_be16(out, 1); /* samples per block */ ++ avio_w8(out, 2); /* sample constructor */ ++ avio_w8(out, 0); /* track reference */ ++ avio_wb16(out, match_len); ++ avio_wb32(out, match_sample); ++ avio_wb32(out, match_offset); ++ avio_wb16(out, 1); /* bytes per block */ ++ avio_wb16(out, 1); /* samples per block */ + (*entries)++; + } + + static void describe_payload(const uint8_t *data, int size, +- ByteIOContext *out, int *entries, ++ AVIOContext *out, int *entries, + HintSampleQueue *queue) + { + /* Describe the payload using different constructors */ +@@ -346,17 +311,17 @@ + * @param pts pointer where the timestamp for the written RTP hint is stored + * @return the number of RTP packets in the written hint + */ +-static int write_hint_packets(ByteIOContext *out, const uint8_t *data, ++static int write_hint_packets(AVIOContext *out, const uint8_t *data, + int size, MOVTrack *trk, int64_t *pts) + { + int64_t curpos; + int64_t count_pos, entries_pos; + int count = 0, entries; + +- count_pos = url_ftell(out); ++ count_pos = avio_tell(out); + /* RTPsample header */ +- put_be16(out, 0); /* packet count */ +- put_be16(out, 0); /* reserved */ ++ avio_wb16(out, 0); /* packet count */ ++ avio_wb16(out, 0); /* reserved */ + + while (size > 4) { + uint32_t packet_len = AV_RB32(data); +@@ -391,12 +356,12 @@ + + count++; + /* RTPpacket header */ +- put_be32(out, 0); /* relative_time */ +- put_buffer(out, data, 2); /* RTP header */ +- put_be16(out, seq); /* RTPsequenceseed */ +- put_be16(out, 0); /* reserved + flags */ +- entries_pos = url_ftell(out); +- put_be16(out, 0); /* entry count */ ++ avio_wb32(out, 0); /* relative_time */ ++ avio_write(out, data, 2); /* RTP header */ ++ avio_wb16(out, seq); /* RTPsequenceseed */ ++ avio_wb16(out, 0); /* reserved + flags */ ++ entries_pos = avio_tell(out); ++ avio_wb16(out, 0); /* entry count */ + + data += 12; + size -= 12; +@@ -408,28 +373,29 @@ + data += packet_len; + size -= packet_len; + +- curpos = url_ftell(out); +- url_fseek(out, entries_pos, SEEK_SET); +- put_be16(out, entries); +- url_fseek(out, curpos, SEEK_SET); ++ curpos = avio_tell(out); ++ avio_seek(out, entries_pos, SEEK_SET); ++ avio_wb16(out, entries); ++ avio_seek(out, curpos, SEEK_SET); + } + +- curpos = url_ftell(out); +- url_fseek(out, count_pos, SEEK_SET); +- put_be16(out, count); +- url_fseek(out, curpos, SEEK_SET); ++ curpos = avio_tell(out); ++ avio_seek(out, count_pos, SEEK_SET); ++ avio_wb16(out, count); ++ avio_seek(out, curpos, SEEK_SET); + return count; + } + + int ff_mov_add_hinted_packet(AVFormatContext *s, AVPacket *pkt, +- int track_index, int sample) ++ int track_index, int sample, ++ uint8_t *sample_data, int sample_size) + { + MOVMuxContext *mov = s->priv_data; + MOVTrack *trk = &mov->tracks[track_index]; + AVFormatContext *rtp_ctx = trk->rtp_ctx; + uint8_t *buf = NULL; + int size; +- ByteIOContext *hintbuf = NULL; ++ AVIOContext *hintbuf = NULL; + AVPacket hint_pkt; + int ret = 0, count; + +@@ -438,15 +404,18 @@ + if (!rtp_ctx->pb) + return AVERROR(ENOMEM); + +- sample_queue_push(&trk->sample_queue, pkt, sample); ++ if (sample_data) ++ sample_queue_push(&trk->sample_queue, sample_data, sample_size, sample); ++ else ++ sample_queue_push(&trk->sample_queue, pkt->data, pkt->size, sample); + + /* Feed the packet to the RTP muxer */ + ff_write_chained(rtp_ctx, 0, pkt, s); + + /* Fetch the output from the RTP muxer, open a new output buffer + * for next time. */ +- size = url_close_dyn_buf(rtp_ctx->pb, &buf); +- if ((ret = url_open_dyn_packet_buf(&rtp_ctx->pb, ++ size = avio_close_dyn_buf(rtp_ctx->pb, &buf); ++ if ((ret = ffio_open_dyn_packet_buf(&rtp_ctx->pb, + RTP_MAX_PACKET_SIZE)) < 0) + goto done; + +@@ -454,14 +423,14 @@ + goto done; + + /* Open a buffer for writing the hint */ +- if ((ret = url_open_dyn_buf(&hintbuf)) < 0) ++ if ((ret = avio_open_dyn_buf(&hintbuf)) < 0) + goto done; + av_init_packet(&hint_pkt); + count = write_hint_packets(hintbuf, buf, size, trk, &hint_pkt.dts); + av_freep(&buf); + + /* Write the hint data into the hint track */ +- hint_pkt.size = size = url_close_dyn_buf(hintbuf, &buf); ++ hint_pkt.size = size = avio_close_dyn_buf(hintbuf, &buf); + hint_pkt.data = buf; + hint_pkt.pts = hint_pkt.dts; + hint_pkt.stream_index = track_index; +@@ -485,12 +454,9 @@ + return; + if (rtp_ctx->pb) { + av_write_trailer(rtp_ctx); +- url_close_dyn_buf(rtp_ctx->pb, &ptr); ++ avio_close_dyn_buf(rtp_ctx->pb, &ptr); + av_free(ptr); + } +- av_metadata_free(&rtp_ctx->streams[0]->metadata); +- av_metadata_free(&rtp_ctx->metadata); +- av_free(rtp_ctx->streams[0]); +- av_freep(&rtp_ctx); ++ avformat_free_context(rtp_ctx); + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mp3dec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mp3dec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mp3dec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mp3dec.c 2012-05-14 14:08:55.053354452 +0200 +@@ -21,7 +21,10 @@ + + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "avformat.h" ++#include "internal.h" + #include "id3v2.h" + #include "id3v1.h" + #include "libavcodec/mpegaudiodecheader.h" +@@ -49,7 +52,7 @@ + + for(frames = 0; buf2 < end; frames++) { + header = AV_RB32(buf2); +- fsize = ff_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); ++ fsize = avpriv_mpa_decode_header(&avctx, header, &sample_rate, &sample_rate, &sample_rate, &sample_rate); + if(fsize < 0) + break; + buf2 += fsize; +@@ -61,7 +64,7 @@ + // keep this in sync with ac3 probe, both need to avoid + // issues with MPEG-files! + if (first_frames>=4) return AVPROBE_SCORE_MAX/2+1; +- else if(max_frames>500)return AVPROBE_SCORE_MAX/2; ++ else if(max_frames>200)return AVPROBE_SCORE_MAX/2; + else if(max_frames>=4) return AVPROBE_SCORE_MAX/4; + else if(max_frames>=1) return 1; + else return 0; +@@ -80,36 +83,36 @@ + MPADecodeHeader c; + int vbrtag_size = 0; + +- v = get_be32(s->pb); ++ v = avio_rb32(s->pb); + if(ff_mpa_check_header(v) < 0) + return -1; + +- if (ff_mpegaudio_decode_header(&c, v) == 0) ++ if (avpriv_mpegaudio_decode_header(&c, v) == 0) + vbrtag_size = c.frame_size; + if(c.layer != 3) + return -1; + + /* Check for Xing / Info tag */ +- url_fseek(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1], SEEK_CUR); +- v = get_be32(s->pb); ++ avio_skip(s->pb, xing_offtbl[c.lsf == 1][c.nb_channels == 1]); ++ v = avio_rb32(s->pb); + if(v == MKBETAG('X', 'i', 'n', 'g') || v == MKBETAG('I', 'n', 'f', 'o')) { +- v = get_be32(s->pb); ++ v = avio_rb32(s->pb); + if(v & 0x1) +- frames = get_be32(s->pb); ++ frames = avio_rb32(s->pb); + if(v & 0x2) +- size = get_be32(s->pb); ++ size = avio_rb32(s->pb); + } + + /* Check for VBRI tag (always 32 bytes after end of mpegaudio header) */ +- url_fseek(s->pb, base + 4 + 32, SEEK_SET); +- v = get_be32(s->pb); ++ avio_seek(s->pb, base + 4 + 32, SEEK_SET); ++ v = avio_rb32(s->pb); + if(v == MKBETAG('V', 'B', 'R', 'I')) { + /* Check tag version */ +- if(get_be16(s->pb) == 1) { ++ if(avio_rb16(s->pb) == 1) { + /* skip delay and quality */ +- url_fseek(s->pb, 4, SEEK_CUR); +- frames = get_be32(s->pb); +- size = get_be32(s->pb); ++ avio_skip(s->pb, 4); ++ size = avio_rb32(s->pb); ++ frames = avio_rb32(s->pb); + } + } + +@@ -117,7 +120,7 @@ + return -1; + + /* Skip the vbr tag frame */ +- url_fseek(s->pb, base + vbrtag_size, SEEK_SET); ++ avio_seek(s->pb, base + vbrtag_size, SEEK_SET); + + spf = c.lsf ? 576 : 1152; /* Samples per frame, layer 3 */ + if(frames) +@@ -135,7 +138,7 @@ + AVStream *st; + int64_t off; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -145,15 +148,15 @@ + st->start_time = 0; + + // lcm of all mp3 sample rates +- av_set_pts_info(st, 64, 1, 14112000); ++ avpriv_set_pts_info(st, 64, 1, 14112000); + +- off = url_ftell(s->pb); ++ off = avio_tell(s->pb); + +- if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ++ if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + ff_id3v1_read(s); + + if (mp3_parse_vbr_tags(s, st, off) < 0) +- url_fseek(s->pb, off, SEEK_SET); ++ avio_seek(s->pb, off, SEEK_SET); + + /* the parameters will be extracted from the compressed bitstream */ + return 0; +@@ -172,7 +175,9 @@ + + pkt->stream_index = 0; + if (ret <= 0) { +- return AVERROR(EIO); ++ if(ret<0) ++ return ret; ++ return AVERROR_EOF; + } + + if (ret > ID3v1_TAG_SIZE && +@@ -186,12 +191,11 @@ + } + + AVInputFormat ff_mp3_demuxer = { +- "mp3", +- NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"), +- 0, +- mp3_read_probe, +- mp3_read_header, +- mp3_read_packet, ++ .name = "mp3", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2/3"), ++ .read_probe = mp3_read_probe, ++ .read_header = mp3_read_header, ++ .read_packet = mp3_read_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "mp2,mp3,m2a", /* XXX: use probe */ + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mp3enc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mp3enc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mp3enc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mp3enc.c 2012-05-14 14:08:55.054354472 +0200 +@@ -19,45 +19,56 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include + #include "avformat.h" ++#include "avio_internal.h" + #include "id3v1.h" + #include "id3v2.h" ++#include "rawenc.h" ++#include "libavutil/avstring.h" ++#include "libavcodec/mpegaudio.h" ++#include "libavcodec/mpegaudiodata.h" ++#include "libavcodec/mpegaudiodecheader.h" + #include "libavutil/intreadwrite.h" + #include "libavutil/opt.h" ++#include "libavcodec/mpegaudio.h" ++#include "libavcodec/mpegaudiodata.h" ++#include "libavcodec/mpegaudiodecheader.h" ++#include "libavformat/avio_internal.h" ++#include "libavutil/dict.h" + + static int id3v1_set_string(AVFormatContext *s, const char *key, + uint8_t *buf, int buf_size) + { +- AVMetadataTag *tag; +- if ((tag = av_metadata_get(s->metadata, key, NULL, 0))) +- strncpy(buf, tag->value, buf_size); ++ AVDictionaryEntry *tag; ++ if ((tag = av_dict_get(s->metadata, key, NULL, 0))) ++ av_strlcpy(buf, tag->value, buf_size); + return !!tag; + } + + static int id3v1_create_tag(AVFormatContext *s, uint8_t *buf) + { +- AVMetadataTag *tag; ++ AVDictionaryEntry *tag; + int i, count = 0; + + memset(buf, 0, ID3v1_TAG_SIZE); /* fail safe */ + buf[0] = 'T'; + buf[1] = 'A'; + buf[2] = 'G'; +- count += id3v1_set_string(s, "TIT2", buf + 3, 30); //title +- count += id3v1_set_string(s, "TPE1", buf + 33, 30); //author|artist +- count += id3v1_set_string(s, "TALB", buf + 63, 30); //album +- count += id3v1_set_string(s, "TDRL", buf + 93, 4); //date +- count += id3v1_set_string(s, "comment", buf + 97, 30); +- if ((tag = av_metadata_get(s->metadata, "TRCK", NULL, 0))) { //track ++ /* we knowingly overspecify each tag length by one byte to compensate for the mandatory null byte added by av_strlcpy */ ++ count += id3v1_set_string(s, "TIT2", buf + 3, 30 + 1); //title ++ count += id3v1_set_string(s, "TPE1", buf + 33, 30 + 1); //author|artist ++ count += id3v1_set_string(s, "TALB", buf + 63, 30 + 1); //album ++ count += id3v1_set_string(s, "TDRL", buf + 93, 4 + 1); //date ++ count += id3v1_set_string(s, "comment", buf + 97, 30 + 1); ++ if ((tag = av_dict_get(s->metadata, "TRCK", NULL, 0))) { //track + buf[125] = 0; + buf[126] = atoi(tag->value); + count++; + } + buf[127] = 0xFF; /* default to unknown genre */ +- if ((tag = av_metadata_get(s->metadata, "TCON", NULL, 0))) { //genre ++ if ((tag = av_dict_get(s->metadata, "TCON", NULL, 0))) { //genre + for(i = 0; i <= ID3v1_GENRE_MAX; i++) { +- if (!strcasecmp(tag->value, ff_id3v1_genre_str[i])) { ++ if (!av_strcasecmp(tag->value, ff_id3v1_genre_str[i])) { + buf[127] = i; + count++; + break; +@@ -67,119 +78,219 @@ + return count; + } + +-/* simple formats */ ++#define VBR_NUM_BAGS 400 ++#define VBR_TOC_SIZE 100 + +-static void id3v2_put_size(AVFormatContext *s, int size) +-{ +- put_byte(s->pb, size >> 21 & 0x7f); +- put_byte(s->pb, size >> 14 & 0x7f); +- put_byte(s->pb, size >> 7 & 0x7f); +- put_byte(s->pb, size & 0x7f); +-} +- +-/** +- * Write a text frame with one (normal frames) or two (TXXX frames) strings +- * according to encoding (only UTF-8 or UTF-16+BOM supported). +- * @return number of bytes written or a negative error code. +- */ +-static int id3v2_put_ttag(AVFormatContext *s, const char *str1, const char *str2, +- uint32_t tag, enum ID3v2Encoding enc) +-{ +- int len; +- uint8_t *pb; +- int (*put)(ByteIOContext*, const char*); +- ByteIOContext *dyn_buf; +- if (url_open_dyn_buf(&dyn_buf) < 0) +- return AVERROR(ENOMEM); +- +- put_byte(dyn_buf, enc); +- if (enc == ID3v2_ENCODING_UTF16BOM) { +- put_le16(dyn_buf, 0xFEFF); /* BOM */ +- put = avio_put_str16le; +- } else +- put = avio_put_str; +- +- put(dyn_buf, str1); +- if (str2) +- put(dyn_buf, str2); +- len = url_close_dyn_buf(dyn_buf, &pb); +- +- put_be32(s->pb, tag); +- id3v2_put_size(s, len); +- put_be16(s->pb, 0); +- put_buffer(s->pb, pb, len); +- +- av_freep(&pb); +- return len + ID3v2_HEADER_SIZE; +-} +- +- +-static int mp3_write_packet(struct AVFormatContext *s, AVPacket *pkt) +-{ +- put_buffer(s->pb, pkt->data, pkt->size); +- put_flush_packet(s->pb); +- return 0; +-} ++typedef struct MP3Context { ++ const AVClass *class; ++ int id3v2_version; ++ int write_id3v1; ++ int64_t frames_offset; ++ int32_t frames; ++ int32_t size; ++ uint32_t want; ++ uint32_t seen; ++ uint32_t pos; ++ uint64_t bag[VBR_NUM_BAGS]; ++} MP3Context; + +-static int mp3_write_trailer(struct AVFormatContext *s) ++static int mp2_write_trailer(struct AVFormatContext *s) + { + uint8_t buf[ID3v1_TAG_SIZE]; ++ MP3Context *mp3 = s->priv_data; + + /* write the id3v1 tag */ +- if (id3v1_create_tag(s, buf) > 0) { +- put_buffer(s->pb, buf, ID3v1_TAG_SIZE); +- put_flush_packet(s->pb); ++ if (mp3 && mp3->write_id3v1 && id3v1_create_tag(s, buf) > 0) { ++ avio_write(s->pb, buf, ID3v1_TAG_SIZE); ++ } ++ ++ /* write number of frames */ ++ if (mp3 && mp3->frames_offset) { ++ avio_seek(s->pb, mp3->frames_offset, SEEK_SET); ++ avio_wb32(s->pb, s->streams[0]->nb_frames); ++ avio_seek(s->pb, 0, SEEK_END); + } ++ ++ avio_flush(s->pb); ++ + return 0; + } + + #if CONFIG_MP2_MUXER + AVOutputFormat ff_mp2_muxer = { +- "mp2", +- NULL_IF_CONFIG_SMALL("MPEG audio layer 2"), +- "audio/x-mpeg", +- "mp2,m2a", +- 0, +- CODEC_ID_MP2, +- CODEC_ID_NONE, +- NULL, +- mp3_write_packet, +- mp3_write_trailer, ++ .name = "mp2", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 2"), ++ .mime_type = "audio/x-mpeg", ++ .extensions = "mp2,m2a", ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, ++ .write_trailer = mp2_write_trailer, ++ .flags = AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_MP3_MUXER +-typedef struct MP3Context { +- const AVClass *class; +- int id3v2_version; +-} MP3Context; + + static const AVOption options[] = { + { "id3v2_version", "Select ID3v2 version to write. Currently 3 and 4 are supported.", +- offsetof(MP3Context, id3v2_version), FF_OPT_TYPE_INT, 4, 3, 4, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MP3Context, id3v2_version), AV_OPT_TYPE_INT, {.dbl = 4}, 3, 4, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "write_id3v1", "Enable ID3v1 writing. ID3v1 tags are written in UTF-8 which may not be supported by most software.", ++ offsetof(MP3Context, write_id3v1), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 1, AV_OPT_FLAG_ENCODING_PARAM}, + { NULL }, + }; + + static const AVClass mp3_muxer_class = { +- "MP3 muxer", +- av_default_item_name, +- options, +- LIBAVUTIL_VERSION_INT, ++ .class_name = "MP3 muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, + }; + +-static int id3v2_check_write_tag(AVFormatContext *s, AVMetadataTag *t, const char table[][4], +- enum ID3v2Encoding enc) ++static const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; ++ ++/* ++ * Write an empty XING header and initialize respective data. ++ */ ++static int mp3_write_xing(AVFormatContext *s) + { +- uint32_t tag; ++ AVCodecContext *codec = s->streams[0]->codec; ++ MP3Context *mp3 = s->priv_data; ++ int bitrate_idx; ++ int best_bitrate_idx; ++ int best_bitrate_error= INT_MAX; ++ int64_t xing_offset; ++ int32_t header, mask; ++ MPADecodeHeader c; ++ int srate_idx, i, channels; ++ int needed; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(avpriv_mpa_freq_tab); i++) ++ if (avpriv_mpa_freq_tab[i] == codec->sample_rate) { ++ srate_idx = i; ++ break; ++ } ++ if (i == FF_ARRAY_ELEMS(avpriv_mpa_freq_tab)) { ++ av_log(s, AV_LOG_ERROR, "Unsupported sample rate.\n"); ++ return -1; ++ } ++ ++ switch (codec->channels) { ++ case 1: channels = MPA_MONO; break; ++ case 2: channels = MPA_STEREO; break; ++ default: av_log(s, AV_LOG_ERROR, "Unsupported number of channels.\n"); return -1; ++ } ++ ++ /* dummy MPEG audio header */ ++ header = 0xff << 24; // sync ++ header |= (0x7 << 5 | 0x3 << 3 | 0x1 << 1 | 0x1) << 16; // sync/mpeg-1/layer 3/no crc*/ ++ header |= (srate_idx << 2) << 8; ++ header |= channels << 6; ++ ++ for (bitrate_idx=1; bitrate_idx<15; bitrate_idx++) { ++ int error; ++ avpriv_mpegaudio_decode_header(&c, header | (bitrate_idx << (4+8))); ++ error= FFABS(c.bit_rate - codec->bit_rate); ++ if(error < best_bitrate_error){ ++ best_bitrate_error= error; ++ best_bitrate_idx = bitrate_idx; ++ } ++ } ++ ++ for (bitrate_idx= best_bitrate_idx;; bitrate_idx++) { ++ if (15 == bitrate_idx) ++ return -1; ++ mask = bitrate_idx << (4+8); ++ header |= mask; ++ avpriv_mpegaudio_decode_header(&c, header); ++ xing_offset=xing_offtbl[c.lsf == 1][c.nb_channels == 1]; ++ needed = 4 // header ++ + xing_offset ++ + 4 // xing tag ++ + 4 // frames/size/toc flags ++ + 4 // frames ++ + 4 // size ++ + VBR_TOC_SIZE; // toc ++ ++ if (needed <= c.frame_size) ++ break; ++ header &= ~mask; ++ } ++ ++ avio_wb32(s->pb, header); ++ ffio_fill(s->pb, 0, xing_offset); ++ avio_wb32(s->pb, MKBETAG('X', 'i', 'n', 'g')); ++ avio_wb32(s->pb, 0x01 | 0x02 | 0x04); // frames/size/toc ++ ++ mp3->frames_offset = avio_tell(s->pb); ++ mp3->size = c.frame_size; ++ mp3->want=1; ++ mp3->seen=0; ++ mp3->pos=0; ++ ++ avio_wb32(s->pb, 0); // frames ++ avio_wb32(s->pb, 0); // size ++ ++ // toc ++ for (i = 0; i < VBR_TOC_SIZE; ++i) ++ avio_w8(s->pb, (uint8_t)(255 * i / VBR_TOC_SIZE)); ++ ++ ffio_fill(s->pb, 0, c.frame_size - needed); ++ avio_flush(s->pb); ++ ++ return 0; ++} ++ ++/* ++ * Add a frame to XING data. ++ * Following lame's "VbrTag.c". ++ */ ++static void mp3_xing_add_frame(AVFormatContext *s, AVPacket *pkt) ++{ ++ MP3Context *mp3 = s->priv_data; + int i; + +- if (t->key[0] != 'T' || strlen(t->key) != 4) +- return -1; +- tag = AV_RB32(t->key); +- for (i = 0; *table[i]; i++) +- if (tag == AV_RB32(table[i])) +- return id3v2_put_ttag(s, t->value, NULL, tag, enc); +- return -1; ++ ++mp3->frames; ++ mp3->size += pkt->size; ++ ++ if (mp3->want == ++mp3->seen) { ++ mp3->bag[mp3->pos] = mp3->size; ++ ++ if (VBR_NUM_BAGS == ++mp3->pos) { ++ /* shrink table to half size by throwing away each second bag. */ ++ for (i = 1; i < VBR_NUM_BAGS; i += 2) ++ mp3->bag[i >> 1] = mp3->bag[i]; ++ ++ /* double wanted amount per bag. */ ++ mp3->want <<= 1; ++ /* adjust current position to half of table size. */ ++ mp3->pos >>= 1; ++ } ++ ++ mp3->seen = 0; ++ } ++} ++ ++static void mp3_fix_xing(AVFormatContext *s) ++{ ++ MP3Context *mp3 = s->priv_data; ++ int i; ++ ++ avio_flush(s->pb); ++ avio_seek(s->pb, mp3->frames_offset, SEEK_SET); ++ avio_wb32(s->pb, mp3->frames); ++ avio_wb32(s->pb, mp3->size); ++ ++ avio_w8(s->pb, 0); // first toc entry has to be zero. ++ ++ for (i = 1; i < VBR_TOC_SIZE; ++i) { ++ int j = i * mp3->pos / VBR_TOC_SIZE; ++ int seek_point = 256LL * mp3->bag[j] / mp3->size; ++ avio_w8(s->pb, FFMIN(seek_point, 255)); ++ } ++ ++ avio_flush(s->pb); ++ avio_seek(s->pb, 0, SEEK_END); + } + + /** +@@ -189,62 +300,80 @@ + static int mp3_write_header(struct AVFormatContext *s) + { + MP3Context *mp3 = s->priv_data; +- AVMetadataTag *t = NULL; +- int totlen = 0, enc = mp3->id3v2_version == 3 ? ID3v2_ENCODING_UTF16BOM : +- ID3v2_ENCODING_UTF8; +- int64_t size_pos, cur_pos; +- +- put_be32(s->pb, MKBETAG('I', 'D', '3', mp3->id3v2_version)); +- put_byte(s->pb, 0); +- put_byte(s->pb, 0); /* flags */ +- +- /* reserve space for size */ +- size_pos = url_ftell(s->pb); +- put_be32(s->pb, 0); +- +- ff_metadata_conv(&s->metadata, ff_id3v2_34_metadata_conv, NULL); +- if (mp3->id3v2_version == 4) +- ff_metadata_conv(&s->metadata, ff_id3v2_4_metadata_conv, NULL); +- +- while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) { +- int ret; +- +- if ((ret = id3v2_check_write_tag(s, t, ff_id3v2_tags, enc)) > 0) { +- totlen += ret; +- continue; +- } +- if ((ret = id3v2_check_write_tag(s, t, mp3->id3v2_version == 3 ? +- ff_id3v2_3_tags : ff_id3v2_4_tags, enc)) > 0) { +- totlen += ret; +- continue; ++ int ret; ++ ++ ret = ff_id3v2_write(s, mp3->id3v2_version, ID3v2_DEFAULT_MAGIC); ++ if (ret < 0) ++ return ret; ++ ++ if (s->pb->seekable) ++ mp3_write_xing(s); ++ ++ return 0; ++} ++ ++static int mp3_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ if (! pkt || ! pkt->data || pkt->size < 4) ++ return ff_raw_write_packet(s, pkt); ++ else { ++ MP3Context *mp3 = s->priv_data; ++#ifdef FILTER_VBR_HEADERS ++ MPADecodeHeader c; ++ int base; ++ ++ ff_mpegaudio_decode_header(&c, AV_RB32(pkt->data)); ++ ++ /* filter out XING and INFO headers. */ ++ base = 4 + xing_offtbl[c.lsf == 1][c.nb_channels == 1]; ++ ++ if (base + 4 <= pkt->size) { ++ uint32_t v = AV_RB32(pkt->data + base); ++ ++ if (MKBETAG('X','i','n','g') == v || MKBETAG('I','n','f','o') == v) ++ return 0; + } + +- /* unknown tag, write as TXXX frame */ +- if ((ret = id3v2_put_ttag(s, t->key, t->value, MKBETAG('T', 'X', 'X', 'X'), enc)) < 0) +- return ret; +- totlen += ret; ++ /* filter out VBRI headers. */ ++ base = 4 + 32; ++ ++ if (base + 4 <= pkt->size && MKBETAG('V','B','R','I') == AV_RB32(pkt->data + base)) ++ return 0; ++#endif ++ ++ if (mp3->frames_offset) ++ mp3_xing_add_frame(s, pkt); ++ ++ return ff_raw_write_packet(s, pkt); + } ++} ++ ++static int mp3_write_trailer(AVFormatContext *s) ++{ ++ MP3Context *mp3 = s->priv_data; ++ int ret=mp2_write_trailer(s); ++ ++ if (ret < 0) ++ return ret; + +- cur_pos = url_ftell(s->pb); +- url_fseek(s->pb, size_pos, SEEK_SET); +- id3v2_put_size(s, totlen); +- url_fseek(s->pb, cur_pos, SEEK_SET); ++ if (mp3->frames_offset) ++ mp3_fix_xing(s); + + return 0; + } + + AVOutputFormat ff_mp3_muxer = { +- "mp3", +- NULL_IF_CONFIG_SMALL("MPEG audio layer 3"), +- "audio/x-mpeg", +- "mp3", +- sizeof(MP3Context), +- CODEC_ID_MP3, +- CODEC_ID_NONE, +- mp3_write_header, +- mp3_write_packet, +- mp3_write_trailer, +- AVFMT_NOTIMESTAMPS, ++ .name = "mp3", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG audio layer 3"), ++ .mime_type = "audio/x-mpeg", ++ .extensions = "mp3", ++ .priv_data_size = sizeof(MP3Context), ++ .audio_codec = CODEC_ID_MP3, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = mp3_write_header, ++ .write_packet = mp3_write_packet, ++ .write_trailer = mp3_write_trailer, ++ .flags = AVFMT_NOTIMESTAMPS, + .priv_class = &mp3_muxer_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpc8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpc8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpc8.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpc8.c 2012-05-14 14:08:55.056354513 +0200 +@@ -22,6 +22,8 @@ + #include "libavcodec/get_bits.h" + #include "libavcodec/unary.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + /// Two-byte MPC tag + #define MKMPCTAG(a, b) (a | (b << 8)) +@@ -117,13 +119,13 @@ + return v; + } + +-static void mpc8_get_chunk_header(ByteIOContext *pb, int *tag, int64_t *size) ++static void mpc8_get_chunk_header(AVIOContext *pb, int *tag, int64_t *size) + { + int64_t pos; +- pos = url_ftell(pb); +- *tag = get_le16(pb); +- *size = ff_get_v(pb); +- *size -= url_ftell(pb) - pos; ++ pos = avio_tell(pb); ++ *tag = avio_rl16(pb); ++ *size = ffio_read_varlen(pb); ++ *size -= avio_tell(pb) - pos; + } + + static void mpc8_parse_seektable(AVFormatContext *s, int64_t off) +@@ -135,7 +137,7 @@ + int i, t, seekd; + GetBitContext gb; + +- url_fseek(s->pb, off, SEEK_SET); ++ avio_seek(s->pb, off, SEEK_SET); + mpc8_get_chunk_header(s->pb, &tag, &size); + if(tag != TAG_SEEKTABLE){ + av_log(s, AV_LOG_ERROR, "No seek table at given position\n"); +@@ -143,7 +145,7 @@ + } + if(!(buf = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE))) + return; +- get_buffer(s->pb, buf, size); ++ avio_read(s->pb, buf, size); + init_get_bits(&gb, buf, size * 8); + size = gb_get_v(&gb); + if(size > UINT_MAX/4 || size > c->samples/1152){ +@@ -171,37 +173,37 @@ + + static void mpc8_handle_chunk(AVFormatContext *s, int tag, int64_t chunk_pos, int64_t size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos, off; + + switch(tag){ + case TAG_SEEKTBLOFF: +- pos = url_ftell(pb) + size; +- off = ff_get_v(pb); ++ pos = avio_tell(pb) + size; ++ off = ffio_read_varlen(pb); + mpc8_parse_seektable(s, chunk_pos + off); +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + break; + default: +- url_fskip(pb, size); ++ avio_skip(pb, size); + } + } + + static int mpc8_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + MPCContext *c = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + int tag = 0; + int64_t size, pos; + +- c->header_pos = url_ftell(pb); +- if(get_le32(pb) != TAG_MPCK){ ++ c->header_pos = avio_tell(pb); ++ if(avio_rl32(pb) != TAG_MPCK){ + av_log(s, AV_LOG_ERROR, "Not a Musepack8 file\n"); + return -1; + } + + while(!url_feof(pb)){ +- pos = url_ftell(pb); ++ pos = avio_tell(pb); + mpc8_get_chunk_header(pb, &tag, &size); + if(tag == TAG_STREAMHDR) + break; +@@ -211,17 +213,17 @@ + av_log(s, AV_LOG_ERROR, "Stream header not found\n"); + return -1; + } +- pos = url_ftell(pb); +- url_fskip(pb, 4); //CRC +- c->ver = get_byte(pb); ++ pos = avio_tell(pb); ++ avio_skip(pb, 4); //CRC ++ c->ver = avio_r8(pb); + if(c->ver != 8){ + av_log(s, AV_LOG_ERROR, "Unknown stream version %d\n", c->ver); + return -1; + } +- c->samples = ff_get_v(pb); +- ff_get_v(pb); //silence samples at the beginning ++ c->samples = ffio_read_varlen(pb); ++ ffio_read_varlen(pb); //silence samples at the beginning + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -230,13 +232,13 @@ + + st->codec->extradata_size = 2; + st->codec->extradata = av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- get_buffer(pb, st->codec->extradata, st->codec->extradata_size); ++ avio_read(pb, st->codec->extradata, st->codec->extradata_size); + + st->codec->channels = (st->codec->extradata[1] >> 4) + 1; + st->codec->sample_rate = mpc8_rate[st->codec->extradata[0] >> 5]; +- av_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1152 << (st->codec->extradata[1]&3)*2, st->codec->sample_rate); + st->duration = c->samples / (1152 << (st->codec->extradata[1]&3)*2); +- size -= url_ftell(pb) - pos; ++ size -= avio_tell(pb) - pos; + + return 0; + } +@@ -248,7 +250,7 @@ + int64_t pos, size; + + while(!url_feof(s->pb)){ +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + mpc8_get_chunk_header(s->pb, &tag, &size); + if (size < 0) + return -1; +@@ -263,7 +265,7 @@ + return AVERROR(EIO); + mpc8_handle_chunk(s, tag, pos, size); + } +- return 0; ++ return AVERROR_EOF; + } + + static int mpc8_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +@@ -273,19 +275,19 @@ + int index = av_index_search_timestamp(st, timestamp, flags); + + if(index < 0) return -1; +- url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); ++ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) ++ return -1; + c->frame = st->index_entries[index].timestamp; + return 0; + } + + + AVInputFormat ff_mpc8_demuxer = { +- "mpc8", +- NULL_IF_CONFIG_SMALL("Musepack SV8"), +- sizeof(MPCContext), +- mpc8_probe, +- mpc8_read_header, +- mpc8_read_packet, +- NULL, +- mpc8_read_seek, ++ .name = "mpc8", ++ .long_name = NULL_IF_CONFIG_SMALL("Musepack SV8"), ++ .priv_data_size = sizeof(MPCContext), ++ .read_probe = mpc8_probe, ++ .read_header = mpc8_read_header, ++ .read_packet = mpc8_read_packet, ++ .read_seek = mpc8_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpc.c 2012-05-14 14:08:55.055354492 +0200 +@@ -21,8 +21,10 @@ + + #include "libavcodec/get_bits.h" + #include "avformat.h" ++#include "internal.h" + #include "apetag.h" + #include "id3v1.h" ++#include "libavutil/dict.h" + + #define MPC_FRAMESIZE 1152 + #define DELAY_FRAMES 32 +@@ -55,27 +57,35 @@ + MPCContext *c = s->priv_data; + AVStream *st; + +- if(get_le24(s->pb) != MKTAG('M', 'P', '+', 0)){ ++ if(avio_rl24(s->pb) != MKTAG('M', 'P', '+', 0)){ + av_log(s, AV_LOG_ERROR, "Not a Musepack file\n"); + return -1; + } +- c->ver = get_byte(s->pb); ++ c->ver = avio_r8(s->pb); + if(c->ver != 0x07 && c->ver != 0x17){ + av_log(s, AV_LOG_ERROR, "Can demux Musepack SV7, got version %02X\n", c->ver); + return -1; + } +- c->fcount = get_le32(s->pb); ++ c->fcount = avio_rl32(s->pb); + if((int64_t)c->fcount * sizeof(MPCFrame) >= UINT_MAX){ + av_log(s, AV_LOG_ERROR, "Too many frames, seeking is not possible\n"); + return -1; + } +- c->frames = av_malloc(c->fcount * sizeof(MPCFrame)); ++ if(c->fcount){ ++ c->frames = av_malloc(c->fcount * sizeof(MPCFrame)); ++ if(!c->frames){ ++ av_log(s, AV_LOG_ERROR, "Cannot allocate seektable\n"); ++ return AVERROR(ENOMEM); ++ } ++ }else{ ++ av_log(s, AV_LOG_WARNING, "Container reports no frames\n"); ++ } + c->curframe = 0; + c->lastframe = -1; + c->curbits = 8; + c->frames_noted = 0; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -85,20 +95,20 @@ + + st->codec->extradata_size = 16; + st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); +- get_buffer(s->pb, st->codec->extradata, 16); ++ avio_read(s->pb, st->codec->extradata, 16); + st->codec->sample_rate = mpc_rate[st->codec->extradata[2] & 3]; +- av_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, MPC_FRAMESIZE, st->codec->sample_rate); + /* scan for seekpoints */ + st->start_time = 0; + st->duration = c->fcount; + + /* try to read APE tags */ +- if (!url_is_streamed(s->pb)) { +- int64_t pos = url_ftell(s->pb); ++ if (s->pb->seekable) { ++ int64_t pos = avio_tell(s->pb); + ff_ape_parse_tag(s); +- if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ++ if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + ff_id3v1_read(s); +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + } + + return 0; +@@ -108,31 +118,31 @@ + { + MPCContext *c = s->priv_data; + int ret, size, size2, curbits, cur = c->curframe; +- int64_t tmp, pos; ++ unsigned tmp; ++ int64_t pos; + +- if (c->curframe >= c->fcount) ++ if (c->curframe >= c->fcount && c->fcount) + return -1; + + if(c->curframe != c->lastframe + 1){ +- url_fseek(s->pb, c->frames[c->curframe].pos, SEEK_SET); ++ avio_seek(s->pb, c->frames[c->curframe].pos, SEEK_SET); + c->curbits = c->frames[c->curframe].skip; + } + c->lastframe = c->curframe; + c->curframe++; + curbits = c->curbits; +- pos = url_ftell(s->pb); +- tmp = get_le32(s->pb); ++ pos = avio_tell(s->pb); ++ tmp = avio_rl32(s->pb); + if(curbits <= 12){ + size2 = (tmp >> (12 - curbits)) & 0xFFFFF; + }else{ +- tmp = (tmp << 32) | get_le32(s->pb); +- size2 = (tmp >> (44 - curbits)) & 0xFFFFF; ++ size2 = (tmp << (curbits - 12) | avio_rl32(s->pb) >> (44 - curbits)) & 0xFFFFF; + } + curbits += 20; +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + + size = ((size2 + curbits + 31) & ~31) >> 3; +- if(cur == c->frames_noted){ ++ if(cur == c->frames_noted && c->fcount){ + c->frames[cur].pos = pos; + c->frames[cur].size = size; + c->frames[cur].skip = curbits - 20; +@@ -145,15 +155,15 @@ + return AVERROR(EIO); + + pkt->data[0] = curbits; +- pkt->data[1] = (c->curframe > c->fcount); ++ pkt->data[1] = (c->curframe > c->fcount) && c->fcount; + pkt->data[2] = 0; + pkt->data[3] = 0; + + pkt->stream_index = 0; + pkt->pts = cur; +- ret = get_buffer(s->pb, pkt->data + 4, size); ++ ret = avio_read(s->pb, pkt->data + 4, size); + if(c->curbits) +- url_fseek(s->pb, -4, SEEK_CUR); ++ avio_seek(s->pb, -4, SEEK_CUR); + if(ret < size){ + av_free_packet(pkt); + return AVERROR(EIO); +@@ -213,13 +223,13 @@ + + + AVInputFormat ff_mpc_demuxer = { +- "mpc", +- NULL_IF_CONFIG_SMALL("Musepack"), +- sizeof(MPCContext), +- mpc_probe, +- mpc_read_header, +- mpc_read_packet, +- mpc_read_close, +- mpc_read_seek, ++ .name = "mpc", ++ .long_name = NULL_IF_CONFIG_SMALL("Musepack"), ++ .priv_data_size = sizeof(MPCContext), ++ .read_probe = mpc_probe, ++ .read_header = mpc_read_header, ++ .read_packet = mpc_read_packet, ++ .read_close = mpc_read_close, ++ .read_seek = mpc_read_seek, + .extensions = "mpc", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpeg.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpeg.c 2012-05-14 14:08:55.058354553 +0200 +@@ -20,10 +20,9 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "mpeg.h" + +-//#define DEBUG_SEEK +- + #undef NDEBUG + #include + +@@ -50,16 +49,8 @@ + return pes1||pes2; + } + +-static int cdxa_probe(AVProbeData *p) +-{ +- /* check file header */ +- if (p->buf[0] == 'R' && p->buf[1] == 'I' && +- p->buf[2] == 'F' && p->buf[3] == 'F' && +- p->buf[8] == 'C' && p->buf[9] == 'D' && +- p->buf[10] == 'X' && p->buf[11] == 'A') +- return AVPROBE_SCORE_MAX; +- else +- return 0; ++static int check_pack_header(const uint8_t *buf) { ++ return (buf[1] & 0xC0) == 0x40 || (buf[1] & 0xF0) == 0x20; + } + + static int mpegps_probe(AVProbeData *p) +@@ -69,23 +60,21 @@ + int i; + int score=0; + +- score = cdxa_probe(p); +- if (score > 0) return score; +- +- /* Search for MPEG stream */ + for(i=0; ibuf_size; i++){ + code = (code<<8) + p->buf[i]; + if ((code & 0xffffff00) == 0x100) { + int len= p->buf[i+1] << 8 | p->buf[i+2]; + int pes= check_pes(p->buf+i, p->buf+p->buf_size); ++ int pack = check_pack_header(p->buf+i); + + if(code == SYSTEM_HEADER_START_CODE) sys++; +- else if(code == PACK_START_CODE) pspack++; ++ else if(code == PACK_START_CODE && pack) pspack++; + else if((code & 0xf0) == VIDEO_ID && pes) vid++; + // skip pes payload to avoid start code emulation for private + // and audio streams + else if((code & 0xe0) == AUDIO_ID && pes) {audio++; i+=len;} + else if(code == PRIVATE_STREAM_1 && pes) {priv1++; i+=len;} ++ else if(code == 0x1fd && pes) vid++; //VC1 + + else if((code & 0xf0) == VIDEO_ID && !pes) invalid++; + else if((code & 0xe0) == AUDIO_ID && !pes) invalid++; +@@ -93,7 +82,7 @@ + } + } + +- if(vid+audio > invalid) /* invalid VDR files nd short PES streams */ ++ if(vid+audio > invalid+1) /* invalid VDR files nd short PES streams */ + score= AVPROBE_SCORE_MAX/4; + + //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d %d %d len:%d\n", sys, priv1, pspack,vid, audio, invalid, p->buf_size); +@@ -122,34 +111,37 @@ + MpegDemuxContext *m = s->priv_data; + const char *sofdec = "Sofdec"; + int v, i = 0; ++ int64_t last_pos = avio_tell(s->pb); + + m->header_state = 0xff; + s->ctx_flags |= AVFMTCTX_NOHEADER; + + m->sofdec = -1; + do { +- v = get_byte(s->pb); +- m->header_state = m->header_state << 8 | v; ++ v = avio_r8(s->pb); + m->sofdec++; + } while (v == sofdec[i] && i++ < 6); + + m->sofdec = (m->sofdec == 6) ? 1 : 0; + ++ if (!m->sofdec) ++ avio_seek(s->pb, last_pos, SEEK_SET); ++ + /* no need to do more */ + return 0; + } + +-static int64_t get_pts(ByteIOContext *pb, int c) ++static int64_t get_pts(AVIOContext *pb, int c) + { + uint8_t buf[5]; + +- buf[0] = c<0 ? get_byte(pb) : c; +- get_buffer(pb, buf+1, 4); ++ buf[0] = c<0 ? avio_r8(pb) : c; ++ avio_read(pb, buf+1, 4); + + return ff_parse_pes_pts(buf); + } + +-static int find_next_start_code(ByteIOContext *pb, int *size_ptr, ++static int find_next_start_code(AVIOContext *pb, int *size_ptr, + int32_t *header_state) + { + unsigned int state, v; +@@ -160,7 +152,7 @@ + while (n > 0) { + if (url_feof(pb)) + break; +- v = get_byte(pb); ++ v = avio_r8(pb); + n--; + if (state == 0x000001) { + state = ((state << 8) | v) & 0xffffff; +@@ -178,20 +170,20 @@ + + #if 0 /* unused, remove? */ + /* XXX: optimize */ +-static int find_prev_start_code(ByteIOContext *pb, int *size_ptr) ++static int find_prev_start_code(AVIOContext *pb, int *size_ptr) + { + int64_t pos, pos_start; + int max_size, start_code; + + max_size = *size_ptr; +- pos_start = url_ftell(pb); ++ pos_start = avio_tell(pb); + + /* in order to go faster, we fill the buffer */ + pos = pos_start - 16386; + if (pos < 0) + pos = 0; +- url_fseek(pb, pos, SEEK_SET); +- get_byte(pb); ++ avio_seek(pb, pos, SEEK_SET); ++ avio_r8(pb); + + pos = pos_start; + for(;;) { +@@ -200,8 +192,8 @@ + start_code = -1; + goto the_end; + } +- url_fseek(pb, pos, SEEK_SET); +- start_code = get_be32(pb); ++ avio_seek(pb, pos, SEEK_SET); ++ start_code = avio_rb32(pb); + if ((start_code & 0xffffff00) == 0x100) + break; + } +@@ -217,31 +209,31 @@ + * + * @return number of bytes occupied by PSM in the bitstream + */ +-static long mpegps_psm_parse(MpegDemuxContext *m, ByteIOContext *pb) ++static long mpegps_psm_parse(MpegDemuxContext *m, AVIOContext *pb) + { + int psm_length, ps_info_length, es_map_length; + +- psm_length = get_be16(pb); +- get_byte(pb); +- get_byte(pb); +- ps_info_length = get_be16(pb); ++ psm_length = avio_rb16(pb); ++ avio_r8(pb); ++ avio_r8(pb); ++ ps_info_length = avio_rb16(pb); + + /* skip program_stream_info */ +- url_fskip(pb, ps_info_length); +- es_map_length = get_be16(pb); ++ avio_skip(pb, ps_info_length); ++ es_map_length = avio_rb16(pb); + + /* at least one es available? */ + while (es_map_length >= 4){ +- unsigned char type = get_byte(pb); +- unsigned char es_id = get_byte(pb); +- uint16_t es_info_length = get_be16(pb); ++ unsigned char type = avio_r8(pb); ++ unsigned char es_id = avio_r8(pb); ++ uint16_t es_info_length = avio_rb16(pb); + /* remember mapping from stream id to stream type */ + m->psm_es_type[es_id] = type; + /* skip program_stream_info */ +- url_fskip(pb, es_info_length); ++ avio_skip(pb, es_info_length); + es_map_length -= 4 + es_info_length; + } +- get_be32(pb); /* crc32 */ ++ avio_rb32(pb); /* crc32 */ + return 2 + psm_length; + } + +@@ -256,17 +248,17 @@ + int len, size, startcode, c, flags, header_len; + int pes_ext, ext2_len, id_ext, skip; + int64_t pts, dts; +- int64_t last_sync= url_ftell(s->pb); ++ int64_t last_sync= avio_tell(s->pb); + + error_redo: +- url_fseek(s->pb, last_sync, SEEK_SET); ++ avio_seek(s->pb, last_sync, SEEK_SET); + redo: + /* next start code (should be immediately after) */ + m->header_state = 0xff; + size = MAX_SYNC_SIZE; + startcode = find_next_start_code(s->pb, &size, &m->header_state); +- last_sync = url_ftell(s->pb); +- //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, url_ftell(s->pb)); ++ last_sync = avio_tell(s->pb); ++ //printf("startcode=%x pos=0x%"PRIx64"\n", startcode, avio_tell(s->pb)); + if (startcode < 0){ + if(url_feof(s->pb)) + return AVERROR_EOF; +@@ -279,16 +271,16 @@ + if (startcode == SYSTEM_HEADER_START_CODE) + goto redo; + if (startcode == PADDING_STREAM) { +- url_fskip(s->pb, get_be16(s->pb)); ++ avio_skip(s->pb, avio_rb16(s->pb)); + goto redo; + } + if (startcode == PRIVATE_STREAM_2) { +- len = get_be16(s->pb); ++ len = avio_rb16(s->pb); + if (!m->sofdec) { + while (len-- >= 6) { +- if (get_byte(s->pb) == 'S') { ++ if (avio_r8(s->pb) == 'S') { + uint8_t buf[5]; +- get_buffer(s->pb, buf, sizeof(buf)); ++ avio_read(s->pb, buf, sizeof(buf)); + m->sofdec = !memcmp(buf, "ofdec", 5); + len -= sizeof(buf); + break; +@@ -296,7 +288,7 @@ + } + m->sofdec -= !m->sofdec; + } +- url_fskip(s->pb, len); ++ avio_skip(s->pb, len); + goto redo; + } + if (startcode == PROGRAM_STREAM_MAP) { +@@ -310,16 +302,16 @@ + (startcode == 0x1bd) || (startcode == 0x1fd))) + goto redo; + if (ppos) { +- *ppos = url_ftell(s->pb) - 4; ++ *ppos = avio_tell(s->pb) - 4; + } +- len = get_be16(s->pb); ++ len = avio_rb16(s->pb); + pts = + dts = AV_NOPTS_VALUE; + /* stuffing */ + for(;;) { + if (len < 1) + goto error_redo; +- c = get_byte(s->pb); ++ c = avio_r8(s->pb); + len--; + /* XXX: for mpeg1, should test only bit 7 */ + if (c != 0xff) +@@ -327,8 +319,8 @@ + } + if ((c & 0xc0) == 0x40) { + /* buffer scale & size */ +- get_byte(s->pb); +- c = get_byte(s->pb); ++ avio_r8(s->pb); ++ c = avio_r8(s->pb); + len -= 2; + } + if ((c & 0xe0) == 0x20) { +@@ -346,8 +338,8 @@ + goto redo; + } + #endif +- flags = get_byte(s->pb); +- header_len = get_byte(s->pb); ++ flags = avio_r8(s->pb); ++ header_len = avio_r8(s->pb); + len -= 2; + if (header_len > len) + goto error_redo; +@@ -365,7 +357,7 @@ + av_log(s, AV_LOG_WARNING, "Further flags set but no bytes left\n"); + } + if (flags & 0x01) { /* PES extension */ +- pes_ext = get_byte(s->pb); ++ pes_ext = avio_r8(s->pb); + header_len--; + /* Skip PES private data, program packet sequence counter and P-STD buffer */ + skip = (pes_ext >> 4) & 0xb; +@@ -374,14 +366,14 @@ + av_log(s, AV_LOG_WARNING, "pes_ext %X is invalid\n", pes_ext); + pes_ext=skip=0; + } +- url_fskip(s->pb, skip); ++ avio_skip(s->pb, skip); + header_len -= skip; + + if (pes_ext & 0x01) { /* PES extension 2 */ +- ext2_len = get_byte(s->pb); ++ ext2_len = avio_r8(s->pb); + header_len--; + if ((ext2_len & 0x7f) > 0) { +- id_ext = get_byte(s->pb); ++ id_ext = avio_r8(s->pb); + if ((id_ext & 0x80) == 0) + startcode = ((startcode & 0xff) << 8) | id_ext; + header_len--; +@@ -390,23 +382,23 @@ + } + if(header_len < 0) + goto error_redo; +- url_fskip(s->pb, header_len); ++ avio_skip(s->pb, header_len); + } + else if( c!= 0xf ) + goto redo; + + if (startcode == PRIVATE_STREAM_1 && !m->psm_es_type[startcode & 0xff]) { +- startcode = get_byte(s->pb); ++ startcode = avio_r8(s->pb); + len--; + if (startcode >= 0x80 && startcode <= 0xcf) { + /* audio: skip header */ +- get_byte(s->pb); +- get_byte(s->pb); +- get_byte(s->pb); ++ avio_r8(s->pb); ++ avio_r8(s->pb); ++ avio_r8(s->pb); + len -= 3; + if (startcode >= 0xb0 && startcode <= 0xbf) { + /* MLP/TrueHD audio has a 4-byte header */ +- get_byte(s->pb); ++ avio_r8(s->pb); + len--; + } + } +@@ -417,7 +409,7 @@ + int i; + for(i=0; inb_streams; i++){ + if(startcode == s->streams[i]->id && +- !url_is_streamed(s->pb) /* index useless on streams anyway */) { ++ s->pb->seekable /* index useless on streams anyway */) { + ff_reduce_index(s, i); + av_add_index_entry(s->streams[i], *ppos, dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); + } +@@ -435,7 +427,8 @@ + { + MpegDemuxContext *m = s->priv_data; + AVStream *st; +- int len, startcode, i, es_type; ++ int len, startcode, i, es_type, ret; ++ int request_probe= 0; + enum CodecID codec_id = CODEC_ID_NONE; + enum AVMediaType type; + int64_t pts, dts, dummy_pos; //dummy_pos is needed for the index building to work +@@ -447,8 +440,8 @@ + return len; + + if(startcode == 0x1bd) { +- dvdaudio_substream_type = get_byte(s->pb); +- url_fskip(s->pb, 3); ++ dvdaudio_substream_type = avio_r8(s->pb); ++ avio_skip(s->pb, 3); + len -= 4; + } + +@@ -489,12 +482,12 @@ + } else if (startcode >= 0x1e0 && startcode <= 0x1ef) { + static const unsigned char avs_seqh[4] = { 0, 0, 1, 0xb0 }; + unsigned char buf[8]; +- get_buffer(s->pb, buf, 8); +- url_fseek(s->pb, -8, SEEK_CUR); ++ avio_read(s->pb, buf, 8); ++ avio_seek(s->pb, -8, SEEK_CUR); + if(!memcmp(buf, avs_seqh, 4) && (buf[6] != 0 || buf[7] != 1)) + codec_id = CODEC_ID_CAVS; + else +- codec_id = CODEC_ID_PROBE; ++ request_probe= 1; + type = AVMEDIA_TYPE_VIDEO; + } else if (startcode >= 0x1c0 && startcode <= 0x1df) { + type = AVMEDIA_TYPE_AUDIO; +@@ -540,15 +533,17 @@ + } else { + skip: + /* skip packet */ +- url_fskip(s->pb, len); ++ avio_skip(s->pb, len); + goto redo; + } + /* no stream found: add a new stream */ +- st = av_new_stream(s, startcode); ++ st = avformat_new_stream(s, NULL); + if (!st) + goto skip; ++ st->id = startcode; + st->codec->codec_type = type; + st->codec->codec_id = codec_id; ++ st->request_probe = request_probe; + if (codec_id != CODEC_ID_PCM_S16BE) + st->need_parsing = AVSTREAM_PARSE_FULL; + found: +@@ -562,9 +557,9 @@ + audio data */ + if (len <= 3) + goto skip; +- get_byte(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */ +- b1 = get_byte(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */ +- get_byte(s->pb); /* dynamic range control (0x80 = off) */ ++ avio_r8(s->pb); /* emphasis (1), muse(1), reserved(1), frame number(5) */ ++ b1 = avio_r8(s->pb); /* quant (2), freq(2), reserved(1), channels(3) */ ++ avio_r8(s->pb); /* dynamic range control (0x80 = off) */ + len -= 3; + freq = (b1 >> 4) & 3; + st->codec->sample_rate = lpcm_freq_tab[freq]; +@@ -578,18 +573,16 @@ + else if (st->codec->bits_per_coded_sample == 28) + return AVERROR(EINVAL); + } +- av_new_packet(pkt, len); +- get_buffer(s->pb, pkt->data, pkt->size); ++ ret = av_get_packet(s->pb, pkt, len); + pkt->pts = pts; + pkt->dts = dts; + pkt->pos = dummy_pos; + pkt->stream_index = st->index; +-#if 0 +- av_log(s, AV_LOG_DEBUG, "%d: pts=%0.3f dts=%0.3f size=%d\n", +- pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, pkt->size); +-#endif ++ av_dlog(s, "%d: pts=%0.3f dts=%0.3f size=%d\n", ++ pkt->stream_index, pkt->pts / 90000.0, pkt->dts / 90000.0, ++ pkt->size); + +- return 0; ++ return (ret < 0) ? ret : 0; + } + + static int64_t mpegps_read_dts(AVFormatContext *s, int stream_index, +@@ -599,42 +592,34 @@ + int64_t pos, pts, dts; + + pos = *ppos; +-#ifdef DEBUG_SEEK +- printf("read_dts: pos=0x%"PRIx64" next=%d -> ", pos, find_next); +-#endif +- if (url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) + return AV_NOPTS_VALUE; + + for(;;) { + len = mpegps_read_pes_header(s, &pos, &startcode, &pts, &dts); + if (len < 0) { +-#ifdef DEBUG_SEEK +- printf("none (ret=%d)\n", len); +-#endif ++ av_dlog(s, "none (ret=%d)\n", len); + return AV_NOPTS_VALUE; + } + if (startcode == s->streams[stream_index]->id && + dts != AV_NOPTS_VALUE) { + break; + } +- url_fskip(s->pb, len); ++ avio_skip(s->pb, len); + } +-#ifdef DEBUG_SEEK +- printf("pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n", pos, dts, dts / 90000.0); +-#endif ++ av_dlog(s, "pos=0x%"PRIx64" dts=0x%"PRIx64" %0.3f\n", ++ pos, dts, dts / 90000.0); + *ppos = pos; + return dts; + } + + AVInputFormat ff_mpegps_demuxer = { +- "mpeg", +- NULL_IF_CONFIG_SMALL("MPEG-PS format"), +- sizeof(MpegDemuxContext), +- mpegps_probe, +- mpegps_read_header, +- mpegps_read_packet, +- NULL, +- NULL, //mpegps_read_seek, +- mpegps_read_dts, ++ .name = "mpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-PS format"), ++ .priv_data_size = sizeof(MpegDemuxContext), ++ .read_probe = mpegps_probe, ++ .read_header = mpegps_read_header, ++ .read_packet = mpegps_read_packet, ++ .read_timestamp = mpegps_read_dts, + .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegenc.c 2012-05-14 14:08:55.061354613 +0200 +@@ -20,12 +20,15 @@ + */ + + #include "libavutil/fifo.h" ++#include "libavutil/log.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" + #include "libavcodec/put_bits.h" + #include "avformat.h" ++#include "internal.h" + #include "mpeg.h" + + #define MAX_PAYLOAD_SIZE 4096 +-//#define DEBUG_SEEK + + #undef NDEBUG + #include +@@ -56,6 +59,7 @@ + } StreamInfo; + + typedef struct { ++ const AVClass *class; + int packet_size; /* required packet size */ + int packet_number; + int pack_header_freq; /* frequency (in packets^-1) at which we send pack headers */ +@@ -74,6 +78,7 @@ + double vcd_padding_bitrate; //FIXME floats + int64_t vcd_padding_bytes_written; + ++ int preload; + } MpegMuxContext; + + extern AVOutputFormat ff_mpeg1vcd_muxer; +@@ -332,7 +337,7 @@ + goto fail; + st->priv_data = stream; + +- av_set_pts_info(st, 64, 1, 90000); ++ avpriv_set_pts_info(st, 64, 1, 90000); + + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: +@@ -416,12 +421,15 @@ + video_bitrate += codec_rate; + } + ++#if FF_API_MUXRATE + if(ctx->mux_rate){ + s->mux_rate= (ctx->mux_rate + (8 * 50) - 1) / (8 * 50); +- } else { ++ } else ++#endif ++ if (!s->mux_rate) { + /* we increase slightly the bitrate to take into account the + headers. XXX: compute it exactly */ +- bitrate += bitrate*5/100; ++ bitrate += bitrate / 20; + bitrate += 10000; + s->mux_rate = (bitrate + (8 * 50) - 1) / (8 * 50); + } +@@ -491,14 +499,14 @@ + return AVERROR(ENOMEM); + } + +-static inline void put_timestamp(ByteIOContext *pb, int id, int64_t timestamp) ++static inline void put_timestamp(AVIOContext *pb, int id, int64_t timestamp) + { +- put_byte(pb, ++ avio_w8(pb, + (id << 4) | + (((timestamp >> 30) & 0x07) << 1) | + 1); +- put_be16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1)); +- put_be16(pb, (uint16_t)((((timestamp ) & 0x7fff) << 1) | 1)); ++ avio_wb16(pb, (uint16_t)((((timestamp >> 15) & 0x7fff) << 1) | 1)); ++ avio_wb16(pb, (uint16_t)((((timestamp ) & 0x7fff) << 1) | 1)); + } + + +@@ -613,21 +621,21 @@ + #endif + + /* Write an MPEG padding packet header. */ +-static void put_padding_packet(AVFormatContext *ctx, ByteIOContext *pb,int packet_bytes) ++static void put_padding_packet(AVFormatContext *ctx, AVIOContext *pb,int packet_bytes) + { + MpegMuxContext *s = ctx->priv_data; + int i; + +- put_be32(pb, PADDING_STREAM); +- put_be16(pb, packet_bytes - 6); ++ avio_wb32(pb, PADDING_STREAM); ++ avio_wb16(pb, packet_bytes - 6); + if (!s->is_mpeg2) { +- put_byte(pb, 0x0f); ++ avio_w8(pb, 0x0f); + packet_bytes -= 7; + } else + packet_bytes -= 6; + + for(i=0;iid; + +-#if 0 +- printf("packet ID=%2x PTS=%0.3f\n", +- id, pts / 90000.0); +-#endif ++ av_dlog(ctx, "packet ID=%2x PTS=%0.3f\n", id, pts / 90000.0); + + buf_ptr = buffer; + +@@ -699,19 +704,19 @@ + size = put_system_header(ctx, buf_ptr, 0); + buf_ptr += size; + size = buf_ptr - buffer; +- put_buffer(ctx->pb, buffer, size); ++ avio_write(ctx->pb, buffer, size); + +- put_be32(ctx->pb, PRIVATE_STREAM_2); +- put_be16(ctx->pb, 0x03d4); // length +- put_byte(ctx->pb, 0x00); // substream ID, 00=PCI ++ avio_wb32(ctx->pb, PRIVATE_STREAM_2); ++ avio_wb16(ctx->pb, 0x03d4); // length ++ avio_w8(ctx->pb, 0x00); // substream ID, 00=PCI + for (i = 0; i < 979; i++) +- put_byte(ctx->pb, 0x00); ++ avio_w8(ctx->pb, 0x00); + +- put_be32(ctx->pb, PRIVATE_STREAM_2); +- put_be16(ctx->pb, 0x03fa); // length +- put_byte(ctx->pb, 0x01); // substream ID, 01=DSI ++ avio_wb32(ctx->pb, PRIVATE_STREAM_2); ++ avio_wb16(ctx->pb, 0x03fa); // length ++ avio_w8(ctx->pb, 0x01); // substream ID, 01=DSI + for (i = 0; i < 1017; i++) +- put_byte(ctx->pb, 0x00); ++ avio_w8(ctx->pb, 0x00); + + memset(buffer, 0, 128); + buf_ptr = buffer; +@@ -734,7 +739,7 @@ + } + } + size = buf_ptr - buffer; +- put_buffer(ctx->pb, buffer, size); ++ avio_write(ctx->pb, buffer, size); + + packet_size = s->packet_size - size; + +@@ -839,16 +844,16 @@ + + nb_frames= get_nb_frames(ctx, stream, payload_size - stuffing_size); + +- put_be32(ctx->pb, startcode); ++ avio_wb32(ctx->pb, startcode); + +- put_be16(ctx->pb, packet_size); ++ avio_wb16(ctx->pb, packet_size); + + if (!s->is_mpeg2) + for(i=0;ipb, 0xff); ++ avio_w8(ctx->pb, 0xff); + + if (s->is_mpeg2) { +- put_byte(ctx->pb, 0x80); /* mpeg2 id */ ++ avio_w8(ctx->pb, 0x80); /* mpeg2 id */ + + pes_flags=0; + +@@ -865,8 +870,8 @@ + if (stream->packet_number == 0) + pes_flags |= 0x01; + +- put_byte(ctx->pb, pes_flags); /* flags */ +- put_byte(ctx->pb, header_len - 3 + stuffing_size); ++ avio_w8(ctx->pb, pes_flags); /* flags */ ++ avio_w8(ctx->pb, header_len - 3 + stuffing_size); + + if (pes_flags & 0x80) /*write pts*/ + put_timestamp(ctx->pb, (pes_flags & 0x40) ? 0x03 : 0x02, pts); +@@ -874,13 +879,13 @@ + put_timestamp(ctx->pb, 0x01, dts); + + if (pes_flags & 0x01) { /*write pes extension*/ +- put_byte(ctx->pb, 0x10); /* flags */ ++ avio_w8(ctx->pb, 0x10); /* flags */ + + /* P-STD buffer info */ + if ((id & 0xe0) == AUDIO_ID) +- put_be16(ctx->pb, 0x4000 | stream->max_buffer_size/ 128); ++ avio_wb16(ctx->pb, 0x4000 | stream->max_buffer_size/ 128); + else +- put_be16(ctx->pb, 0x6000 | stream->max_buffer_size/1024); ++ avio_wb16(ctx->pb, 0x6000 | stream->max_buffer_size/1024); + } + + } else { +@@ -892,38 +897,38 @@ + put_timestamp(ctx->pb, 0x02, pts); + } + } else { +- put_byte(ctx->pb, 0x0f); ++ avio_w8(ctx->pb, 0x0f); + } + } + + if (s->is_mpeg2) { + /* special stuffing byte that is always written + to prevent accidental generation of start codes. */ +- put_byte(ctx->pb, 0xff); ++ avio_w8(ctx->pb, 0xff); + + for(i=0;ipb, 0xff); ++ avio_w8(ctx->pb, 0xff); + } + + if (startcode == PRIVATE_STREAM_1) { +- put_byte(ctx->pb, id); ++ avio_w8(ctx->pb, id); + if (id >= 0xa0) { + /* LPCM (XXX: check nb_frames) */ +- put_byte(ctx->pb, 7); +- put_be16(ctx->pb, 4); /* skip 3 header bytes */ +- put_byte(ctx->pb, stream->lpcm_header[0]); +- put_byte(ctx->pb, stream->lpcm_header[1]); +- put_byte(ctx->pb, stream->lpcm_header[2]); ++ avio_w8(ctx->pb, 7); ++ avio_wb16(ctx->pb, 4); /* skip 3 header bytes */ ++ avio_w8(ctx->pb, stream->lpcm_header[0]); ++ avio_w8(ctx->pb, stream->lpcm_header[1]); ++ avio_w8(ctx->pb, stream->lpcm_header[2]); + } else if (id >= 0x40) { + /* AC-3 */ +- put_byte(ctx->pb, nb_frames); +- put_be16(ctx->pb, trailer_size+1); ++ avio_w8(ctx->pb, nb_frames); ++ avio_wb16(ctx->pb, trailer_size+1); + } + } + + /* output data */ + assert(payload_size - stuffing_size <= av_fifo_size(stream->fifo)); +- av_fifo_generic_read(stream->fifo, ctx->pb, payload_size - stuffing_size, &put_buffer); ++ av_fifo_generic_read(stream->fifo, ctx->pb, payload_size - stuffing_size, (void*)avio_write); + stream->bytes_to_iframe -= payload_size - stuffing_size; + }else{ + payload_size= +@@ -934,9 +939,9 @@ + put_padding_packet(ctx,ctx->pb, pad_packet_bytes); + + for(i=0;ipb, 0x00); ++ avio_w8(ctx->pb, 0x00); + +- put_flush_packet(ctx->pb); ++ avio_flush(ctx->pb); + + s->packet_number++; + +@@ -961,11 +966,11 @@ + int i; + + for(i=0;ipacket_size;i++) +- put_byte(ctx->pb, 0); ++ avio_w8(ctx->pb, 0); + + s->vcd_padding_bytes_written += s->packet_size; + +- put_flush_packet(ctx->pb); ++ avio_flush(ctx->pb); + + /* increasing the packet number is correct. The SCR of the following packs + is calculated from the packet_number and it has to include the padding +@@ -1042,7 +1047,7 @@ + StreamInfo *stream = st->priv_data; + const int avail_data= av_fifo_size(stream->fifo); + const int space= stream->max_buffer_size - stream->buffer_index; +- int rel_space= 1024*space / stream->max_buffer_size; ++ int rel_space= 1024LL*space / stream->max_buffer_size; + PacketDesc *next_pkt= stream->premux_packet; + + /* for subtitle, a single PES packet must be generated, +@@ -1078,10 +1083,8 @@ + best_dts= pkt_desc->dts; + } + +-#if 0 +- av_log(ctx, AV_LOG_DEBUG, "bumping scr, scr:%f, dts:%f\n", +- scr/90000.0, best_dts/90000.0); +-#endif ++ av_dlog(ctx, "bumping scr, scr:%f, dts:%f\n", ++ scr / 90000.0, best_dts / 90000.0); + if(best_dts == INT64_MAX) + return 0; + +@@ -1157,9 +1160,15 @@ + StreamInfo *stream = st->priv_data; + int64_t pts, dts; + PacketDesc *pkt_desc; +- const int preload= av_rescale(ctx->preload, 90000, AV_TIME_BASE); ++ int preload; + const int is_iframe = st->codec->codec_type == AVMEDIA_TYPE_VIDEO && (pkt->flags & AV_PKT_FLAG_KEY); + ++#if FF_API_PRELOAD ++ if (ctx->preload) ++ s->preload = ctx->preload; ++#endif ++ preload = av_rescale(s->preload, 90000, AV_TIME_BASE); ++ + pts= pkt->pts; + dts= pkt->dts; + +@@ -1220,8 +1229,8 @@ + /* End header according to MPEG1 systems standard. We do not write + it as it is usually not needed by decoders and because it + complicates MPEG stream concatenation. */ +- //put_be32(ctx->pb, ISO_11172_END_CODE); +- //put_flush_packet(ctx->pb); ++ //avio_wb32(ctx->pb, ISO_11172_END_CODE); ++ //avio_flush(ctx->pb); + + for(i=0;inb_streams;i++) { + stream = ctx->streams[i]->priv_data; +@@ -1232,77 +1241,102 @@ + return 0; + } + ++#define OFFSET(x) offsetof(MpegMuxContext, x) ++#define E AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "muxrate", NULL, OFFSET(mux_rate), AV_OPT_TYPE_INT, {0}, 0, INT_MAX, E }, ++ { "preload", "Initial demux-decode delay in microseconds.", OFFSET(preload), AV_OPT_TYPE_INT, {500000}, 0, INT_MAX, E}, ++ { NULL }, ++}; ++ ++#define MPEGENC_CLASS(flavor)\ ++static const AVClass flavor ## _class = {\ ++ .class_name = #flavor " muxer",\ ++ .item_name = av_default_item_name,\ ++ .version = LIBAVUTIL_VERSION_INT,\ ++ .option = options,\ ++}; ++ + #if CONFIG_MPEG1SYSTEM_MUXER ++MPEGENC_CLASS(mpeg) + AVOutputFormat ff_mpeg1system_muxer = { +- "mpeg", +- NULL_IF_CONFIG_SMALL("MPEG-1 System format"), +- "video/mpeg", +- "mpg,mpeg", +- sizeof(MpegMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG1VIDEO, +- mpeg_mux_init, +- mpeg_mux_write_packet, +- mpeg_mux_end, ++ .name = "mpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 System format"), ++ .mime_type = "video/mpeg", ++ .extensions = "mpg,mpeg", ++ .priv_data_size = sizeof(MpegMuxContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG1VIDEO, ++ .write_header = mpeg_mux_init, ++ .write_packet = mpeg_mux_write_packet, ++ .write_trailer = mpeg_mux_end, ++ .priv_class = &mpeg_class, + }; + #endif + #if CONFIG_MPEG1VCD_MUXER ++MPEGENC_CLASS(vcd) + AVOutputFormat ff_mpeg1vcd_muxer = { +- "vcd", +- NULL_IF_CONFIG_SMALL("MPEG-1 System format (VCD)"), +- "video/mpeg", +- NULL, +- sizeof(MpegMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG1VIDEO, +- mpeg_mux_init, +- mpeg_mux_write_packet, +- mpeg_mux_end, ++ .name = "vcd", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 System format (VCD)"), ++ .mime_type = "video/mpeg", ++ .priv_data_size = sizeof(MpegMuxContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG1VIDEO, ++ .write_header = mpeg_mux_init, ++ .write_packet = mpeg_mux_write_packet, ++ .write_trailer = mpeg_mux_end, ++ .priv_class = &vcd_class, + }; + #endif + #if CONFIG_MPEG2VOB_MUXER ++MPEGENC_CLASS(vob) + AVOutputFormat ff_mpeg2vob_muxer = { +- "vob", +- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"), +- "video/mpeg", +- "vob", +- sizeof(MpegMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG2VIDEO, +- mpeg_mux_init, +- mpeg_mux_write_packet, +- mpeg_mux_end, ++ .name = "vob", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"), ++ .mime_type = "video/mpeg", ++ .extensions = "vob", ++ .priv_data_size = sizeof(MpegMuxContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mpeg_mux_init, ++ .write_packet = mpeg_mux_write_packet, ++ .write_trailer = mpeg_mux_end, ++ .priv_class = &vob_class, + }; + #endif + + /* Same as mpeg2vob_mux except that the pack size is 2324 */ + #if CONFIG_MPEG2SVCD_MUXER ++MPEGENC_CLASS(svcd) + AVOutputFormat ff_mpeg2svcd_muxer = { +- "svcd", +- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"), +- "video/mpeg", +- "vob", +- sizeof(MpegMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG2VIDEO, +- mpeg_mux_init, +- mpeg_mux_write_packet, +- mpeg_mux_end, ++ .name = "svcd", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (VOB)"), ++ .mime_type = "video/mpeg", ++ .extensions = "vob", ++ .priv_data_size = sizeof(MpegMuxContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mpeg_mux_init, ++ .write_packet = mpeg_mux_write_packet, ++ .write_trailer = mpeg_mux_end, ++ .priv_class = &svcd_class, + }; + #endif + + /* Same as mpeg2vob_mux except the 'is_dvd' flag is set to produce NAV pkts */ + #if CONFIG_MPEG2DVD_MUXER ++MPEGENC_CLASS(dvd) + AVOutputFormat ff_mpeg2dvd_muxer = { +- "dvd", +- NULL_IF_CONFIG_SMALL("MPEG-2 PS format (DVD VOB)"), +- "video/mpeg", +- "dvd", +- sizeof(MpegMuxContext), +- CODEC_ID_MP2, +- CODEC_ID_MPEG2VIDEO, +- mpeg_mux_init, +- mpeg_mux_write_packet, +- mpeg_mux_end, ++ .name = "dvd", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 PS format (DVD VOB)"), ++ .mime_type = "video/mpeg", ++ .extensions = "dvd", ++ .priv_data_size = sizeof(MpegMuxContext), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mpeg_mux_init, ++ .write_packet = mpeg_mux_write_packet, ++ .write_trailer = mpeg_mux_end, ++ .priv_class = &dvd_class, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegts.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegts.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegts.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegts.c 2012-05-14 14:08:55.066354715 +0200 +@@ -19,29 +19,33 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-//#define DEBUG +-//#define DEBUG_SEEK + //#define USE_SYNCPOINT_SEARCH + + #include "libavutil/crc.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/log.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" ++#include "libavutil/avassert.h" + #include "libavcodec/bytestream.h" ++#include "libavcodec/get_bits.h" + #include "avformat.h" + #include "mpegts.h" + #include "internal.h" ++#include "avio_internal.h" + #include "seek.h" + #include "mpeg.h" + #include "isom.h" + +-/* 1.0 second at 24Mbit/s */ +-#define MAX_SCAN_PACKETS 32000 +- + /* maximum size in which we look for synchronisation if + synchronisation is lost */ + #define MAX_RESYNC_SIZE 65536 + + #define MAX_PES_PAYLOAD 200*1024 + ++#define MAX_MP4_DESCR_COUNT 16 ++ + enum MpegTSFilterType { + MPEGTS_PES, + MPEGTS_SECTION, +@@ -72,6 +76,7 @@ + + struct MpegTSFilter { + int pid; ++ int es_id; + int last_cc; /* last cc code (-1 if first packet) */ + int last_version; /* last version of data on this pid */ + enum MpegTSFilterType type; +@@ -89,6 +94,7 @@ + }; + + struct MpegTSContext { ++ const AVClass *class; + /* user data */ + AVFormatContext *stream; + /** raw packet size, including FEC if present */ +@@ -125,6 +131,19 @@ + MpegTSFilter *pids[NB_PID_MAX]; + }; + ++static const AVOption options[] = { ++ {"compute_pcr", "Compute exact PCR for each transport stream packet.", offsetof(MpegTSContext, mpeg2ts_compute_pcr), AV_OPT_TYPE_INT, ++ {.dbl = 0}, 0, 1, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass mpegtsraw_class = { ++ .class_name = "mpegtsraw demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + /* TS stream handling */ + + enum MpegTSState { +@@ -151,6 +170,7 @@ + enum MpegTSState state; + /* used to get the format */ + int data_index; ++ int flags; /**< copied to the AVPacket flags */ + int total_size; + int pes_header_size; + int extended_stream_id; +@@ -158,6 +178,7 @@ + int64_t ts_packet_pos; /**< position of first TS packet of this PES packet */ + uint8_t header[MAX_PES_HEADER_SIZE]; + uint8_t *buffer; ++ SLConfigDescr sl; + } PESContext; + + extern AVInputFormat ff_mpegts_demuxer; +@@ -208,12 +229,23 @@ + p->pids[p->nb_pids++] = pid; + } + ++static void set_pcr_pid(AVFormatContext *s, unsigned int programid, unsigned int pid) ++{ ++ int i; ++ for(i=0; inb_programs; i++) { ++ if(s->programs[i]->id == programid) { ++ s->programs[i]->pcr_pid = pid; ++ break; ++ } ++ } ++} ++ + /** +- * \brief discard_pid() decides if the pid is to be discarded according ++ * @brief discard_pid() decides if the pid is to be discarded according + * to caller's programs selection +- * \param ts : - TS context +- * \param pid : - pid +- * \return 1 if the pid is only comprised in programs that have .discard=AVDISCARD_ALL ++ * @param ts : - TS context ++ * @param pid : - pid ++ * @return 1 if the pid is only comprised in programs that have .discard=AVDISCARD_ALL + * 0 otherwise + */ + static int discard_pid(MpegTSContext *ts, unsigned int pid) +@@ -301,6 +333,7 @@ + ts->pids[pid] = filter; + filter->type = MPEGTS_SECTION; + filter->pid = pid; ++ filter->es_id = -1; + filter->last_cc = -1; + filter->last_version = -1; + sec = &filter->u.section_filter; +@@ -330,6 +363,7 @@ + ts->pids[pid] = filter; + filter->type = MPEGTS_PES; + filter->pid = pid; ++ filter->es_id = -1; + filter->last_cc = -1; + pes = &filter->u.pes_filter; + pes->pes_cb = pes_cb; +@@ -348,7 +382,7 @@ + PESContext *pes = filter->u.pes_filter.opaque; + av_freep(&pes->buffer); + /* referenced private data will be freed later in +- * av_close_input_stream */ ++ * avformat_close_input */ + if (!((PESContext *)filter->u.pes_filter.opaque)->st) { + av_freep(&filter->u.pes_filter.opaque); + } +@@ -367,7 +401,7 @@ + memset(stat, 0, packet_size*sizeof(int)); + + for(x=i=0; i best_score){ + best_score= stat[x]; +@@ -437,7 +471,7 @@ + return c; + } + +-/* read and allocate a DVB string preceeded by its length */ ++/* read and allocate a DVB string preceded by its length */ + static char *getstr8(const uint8_t **pp, const uint8_t *p_end) + { + int len; +@@ -503,7 +537,9 @@ + { 0x04, AVMEDIA_TYPE_AUDIO, CODEC_ID_MP3 }, + { 0x0f, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC }, + { 0x10, AVMEDIA_TYPE_VIDEO, CODEC_ID_MPEG4 }, +- { 0x11, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */ ++ /* Makito encoder sets stream type 0x11 for AAC, ++ * so auto-detect LOAS/LATM instead of hardcoding it. */ ++// { 0x11, AVMEDIA_TYPE_AUDIO, CODEC_ID_AAC_LATM }, /* LATM syntax */ + { 0x1b, AVMEDIA_TYPE_VIDEO, CODEC_ID_H264 }, + { 0xd1, AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC }, + { 0xea, AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 }, +@@ -518,6 +554,8 @@ + { 0x84, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, + { 0x85, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD */ + { 0x86, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD MASTER*/ ++ { 0xa1, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, /* E-AC3 Secondary Audio */ ++ { 0xa2, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS Express Secondary Audio */ + { 0x90, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE }, + { 0 }, + }; +@@ -532,6 +570,7 @@ + static const StreamType REGD_types[] = { + { MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC }, + { MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, ++ { MKTAG('B','S','S','D'), AVMEDIA_TYPE_AUDIO, CODEC_ID_S302M }, + { MKTAG('D','T','S','1'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, + { MKTAG('D','T','S','2'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, + { MKTAG('D','T','S','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +@@ -558,6 +597,7 @@ + if (stream_type == types->stream_type) { + st->codec->codec_type = types->codec_type; + st->codec->codec_id = types->codec_id; ++ st->request_probe = 0; + return; + } + } +@@ -566,7 +606,9 @@ + static int mpegts_set_stream_info(AVStream *st, PESContext *pes, + uint32_t stream_type, uint32_t prog_reg_desc) + { +- av_set_pts_info(st, 33, 1, 90000); ++ int old_codec_type= st->codec->codec_type; ++ int old_codec_id = st->codec->codec_id; ++ avpriv_set_pts_info(st, 33, 1, 90000); + st->priv_data = pes; + st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codec->codec_id = CODEC_ID_NONE; +@@ -581,7 +623,8 @@ + st->codec->codec_tag = pes->stream_type; + + mpegts_find_stream_type(st, pes->stream_type, ISO_types); +- if (prog_reg_desc == AV_RL32("HDMV") && ++ if ((prog_reg_desc == AV_RL32("HDMV") || ++ prog_reg_desc == AV_RL32("HDPR")) && + st->codec->codec_id == CODEC_ID_NONE) { + mpegts_find_stream_type(st, pes->stream_type, HDMV_types); + if (pes->stream_type == 0x83) { +@@ -594,13 +637,14 @@ + return AVERROR(ENOMEM); + memcpy(sub_pes, pes, sizeof(*sub_pes)); + +- sub_st = av_new_stream(pes->stream, pes->pid); ++ sub_st = avformat_new_stream(pes->stream, NULL); + if (!sub_st) { + av_free(sub_pes); + return AVERROR(ENOMEM); + } + +- av_set_pts_info(sub_st, 33, 1, 90000); ++ sub_st->id = pes->pid; ++ avpriv_set_pts_info(sub_st, 33, 1, 90000); + sub_st->priv_data = sub_pes; + sub_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + sub_st->codec->codec_id = CODEC_ID_AC3; +@@ -610,6 +654,10 @@ + } + if (st->codec->codec_id == CODEC_ID_NONE) + mpegts_find_stream_type(st, pes->stream_type, MISC_types); ++ if (st->codec->codec_id == CODEC_ID_NONE){ ++ st->codec->codec_id = old_codec_id; ++ st->codec->codec_type= old_codec_type; ++ } + + return 0; + } +@@ -625,6 +673,12 @@ + pkt->destruct = av_destruct_packet; + pkt->data = pes->buffer; + pkt->size = pes->data_index; ++ ++ if(pes->total_size != MAX_PES_PAYLOAD && ++ pes->pes_header_size + pes->data_index != pes->total_size + PES_START_SIZE) { ++ av_log(pes->stream, AV_LOG_WARNING, "PES packet size mismatch\n"); ++ pes->flags |= AV_PKT_FLAG_CORRUPT; ++ } + memset(pkt->data+pkt->size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + + // Separate out the AC3 substream from an HDMV combined TrueHD/AC3 PID +@@ -636,12 +690,92 @@ + pkt->dts = pes->dts; + /* store position of first TS packet of this PES packet */ + pkt->pos = pes->ts_packet_pos; ++ pkt->flags = pes->flags; + + /* reset pts values */ + pes->pts = AV_NOPTS_VALUE; + pes->dts = AV_NOPTS_VALUE; + pes->buffer = NULL; + pes->data_index = 0; ++ pes->flags = 0; ++} ++ ++static uint64_t get_bits64(GetBitContext *gb, int bits) ++{ ++ uint64_t ret = 0; ++ while (bits > 17) { ++ ret <<= 17; ++ ret |= get_bits(gb, 17); ++ bits -= 17; ++ } ++ ret <<= bits; ++ ret |= get_bits(gb, bits); ++ return ret; ++} ++ ++static int read_sl_header(PESContext *pes, SLConfigDescr *sl, const uint8_t *buf, int buf_size) ++{ ++ GetBitContext gb; ++ int au_start_flag = 0, au_end_flag = 0, ocr_flag = 0, idle_flag = 0; ++ int padding_flag = 0, padding_bits = 0, inst_bitrate_flag = 0; ++ int dts_flag = -1, cts_flag = -1; ++ int64_t dts = AV_NOPTS_VALUE, cts = AV_NOPTS_VALUE; ++ init_get_bits(&gb, buf, buf_size*8); ++ ++ if (sl->use_au_start) ++ au_start_flag = get_bits1(&gb); ++ if (sl->use_au_end) ++ au_end_flag = get_bits1(&gb); ++ if (!sl->use_au_start && !sl->use_au_end) ++ au_start_flag = au_end_flag = 1; ++ if (sl->ocr_len > 0) ++ ocr_flag = get_bits1(&gb); ++ if (sl->use_idle) ++ idle_flag = get_bits1(&gb); ++ if (sl->use_padding) ++ padding_flag = get_bits1(&gb); ++ if (padding_flag) ++ padding_bits = get_bits(&gb, 3); ++ ++ if (!idle_flag && (!padding_flag || padding_bits != 0)) { ++ if (sl->packet_seq_num_len) ++ skip_bits_long(&gb, sl->packet_seq_num_len); ++ if (sl->degr_prior_len) ++ if (get_bits1(&gb)) ++ skip_bits(&gb, sl->degr_prior_len); ++ if (ocr_flag) ++ skip_bits_long(&gb, sl->ocr_len); ++ if (au_start_flag) { ++ if (sl->use_rand_acc_pt) ++ get_bits1(&gb); ++ if (sl->au_seq_num_len > 0) ++ skip_bits_long(&gb, sl->au_seq_num_len); ++ if (sl->use_timestamps) { ++ dts_flag = get_bits1(&gb); ++ cts_flag = get_bits1(&gb); ++ } ++ } ++ if (sl->inst_bitrate_len) ++ inst_bitrate_flag = get_bits1(&gb); ++ if (dts_flag == 1) ++ dts = get_bits64(&gb, sl->timestamp_len); ++ if (cts_flag == 1) ++ cts = get_bits64(&gb, sl->timestamp_len); ++ if (sl->au_len > 0) ++ skip_bits_long(&gb, sl->au_len); ++ if (inst_bitrate_flag) ++ skip_bits_long(&gb, sl->inst_bitrate_len); ++ } ++ ++ if (dts != AV_NOPTS_VALUE) ++ pes->dts = dts; ++ if (cts != AV_NOPTS_VALUE) ++ pes->pts = cts; ++ ++ if (sl->timestamp_len && sl->timestamp_res) ++ avpriv_set_pts_info(pes->st, sl->timestamp_len, 1, sl->timestamp_res); ++ ++ return (get_bits_count(&gb) + 7) >> 3; + } + + /* return non zero if a packet could be constructed */ +@@ -680,9 +814,6 @@ + if (pes->data_index == PES_START_SIZE) { + /* we got all the PES or section header. We can now + decide */ +-#if 0 +- av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index); +-#endif + if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && + pes->header[2] == 0x01) { + /* it must be an mpeg2 PES stream */ +@@ -693,16 +824,12 @@ + code == 0x1be) /* padding_stream */ + goto skip; + +-#if FF_API_MAX_STREAMS +- if (!pes->st && pes->stream->nb_streams == MAX_STREAMS) +- goto skip; +-#endif +- + /* stream not present in PMT */ + if (ts->auto_guess && !pes->st) { +- pes->st = av_new_stream(ts->stream, pes->pid); ++ pes->st = avformat_new_stream(ts->stream, NULL); + if (!pes->st) + return AVERROR(ENOMEM); ++ pes->st->id = pes->pid; + mpegts_set_stream_info(pes->st, pes, 0, 0); + } + +@@ -722,10 +849,10 @@ + code != 0x1ff && code != 0x1f2 && /* program_stream_directory, DSMCC_stream */ + code != 0x1f8) { /* ITU-T Rec. H.222.1 type E stream */ + pes->state = MPEGTS_PESHEADER; +- if (pes->st->codec->codec_id == CODEC_ID_NONE) { ++ if (pes->st->codec->codec_id == CODEC_ID_NONE && !pes->st->request_probe) { + av_dlog(pes->stream, "pid=%x stream_type=%x probing\n", + pes->pid, pes->stream_type); +- pes->st->codec->codec_id = CODEC_ID_PROBE; ++ pes->st->request_probe= 1; + } + } else { + pes->state = MPEGTS_PAYLOAD; +@@ -802,6 +929,12 @@ + /* we got the full header. We parse it and get the payload */ + pes->state = MPEGTS_PAYLOAD; + pes->data_index = 0; ++ if (pes->stream_type == 0x12 && buf_size > 0) { ++ int sl_header_bytes = read_sl_header(pes, &pes->sl, p, buf_size); ++ pes->pes_header_size += sl_header_bytes; ++ p += sl_header_bytes; ++ buf_size -= sl_header_bytes; ++ } + } + break; + case MPEGTS_PAYLOAD: +@@ -826,9 +959,9 @@ + * decreases demuxer delay for infrequent packets like subtitles from + * a couple of seconds to milliseconds for properly muxed files. + * total_size is the number of bytes following pes_packet_length +- * in the pes header, i.e. not counting the first 6 bytes */ +- if (pes->total_size < MAX_PES_PAYLOAD && +- pes->pes_header_size + pes->data_index == pes->total_size + 6) { ++ * in the pes header, i.e. not counting the first PES_START_SIZE bytes */ ++ if (!ts->stop_parse && pes->total_size < MAX_PES_PAYLOAD && ++ pes->pes_header_size + pes->data_index == pes->total_size + PES_START_SIZE) { + ts->stop_parse = 1; + new_pes_packet(pes, ts->pkt); + } +@@ -866,50 +999,291 @@ + return pes; + } + +-static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, +- int *es_id, uint8_t **dec_config_descr, +- int *dec_config_descr_size) ++#define MAX_LEVEL 4 ++typedef struct { ++ AVFormatContext *s; ++ AVIOContext pb; ++ Mp4Descr *descr; ++ Mp4Descr *active_descr; ++ int descr_count; ++ int max_descr_count; ++ int level; ++} MP4DescrParseContext; ++ ++static int init_MP4DescrParseContext( ++ MP4DescrParseContext *d, AVFormatContext *s, const uint8_t *buf, ++ unsigned size, Mp4Descr *descr, int max_descr_count) + { +- ByteIOContext pb; ++ int ret; ++ if (size > (1<<30)) ++ return AVERROR_INVALIDDATA; ++ ++ if ((ret = ffio_init_context(&d->pb, (unsigned char*)buf, size, 0, ++ NULL, NULL, NULL, NULL)) < 0) ++ return ret; ++ ++ d->s = s; ++ d->level = 0; ++ d->descr_count = 0; ++ d->descr = descr; ++ d->active_descr = NULL; ++ d->max_descr_count = max_descr_count; ++ ++ return 0; ++} ++ ++static void update_offsets(AVIOContext *pb, int64_t *off, int *len) { ++ int64_t new_off = avio_tell(pb); ++ (*len) -= new_off - *off; ++ *off = new_off; ++} ++ ++static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, ++ int target_tag); ++ ++static int parse_mp4_descr_arr(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ while (len > 0) { ++ if (parse_mp4_descr(d, off, len, 0) < 0) ++ return -1; ++ update_offsets(&d->pb, &off, &len); ++ } ++ return 0; ++} ++ ++static int parse_MP4IODescrTag(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ avio_rb16(&d->pb); // ID ++ avio_r8(&d->pb); ++ avio_r8(&d->pb); ++ avio_r8(&d->pb); ++ avio_r8(&d->pb); ++ avio_r8(&d->pb); ++ update_offsets(&d->pb, &off, &len); ++ return parse_mp4_descr_arr(d, off, len); ++} ++ ++static int parse_MP4ODescrTag(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ int id_flags; ++ if (len < 2) ++ return 0; ++ id_flags = avio_rb16(&d->pb); ++ if (!(id_flags & 0x0020)) { //URL_Flag ++ update_offsets(&d->pb, &off, &len); ++ return parse_mp4_descr_arr(d, off, len); //ES_Descriptor[] ++ } else { ++ return 0; ++ } ++} ++ ++static int parse_MP4ESDescrTag(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ int es_id = 0; ++ if (d->descr_count >= d->max_descr_count) ++ return -1; ++ ff_mp4_parse_es_descr(&d->pb, &es_id); ++ d->active_descr = d->descr + (d->descr_count++); ++ ++ d->active_descr->es_id = es_id; ++ update_offsets(&d->pb, &off, &len); ++ parse_mp4_descr(d, off, len, MP4DecConfigDescrTag); ++ update_offsets(&d->pb, &off, &len); ++ if (len > 0) ++ parse_mp4_descr(d, off, len, MP4SLDescrTag); ++ d->active_descr = NULL; ++ return 0; ++} ++ ++static int parse_MP4DecConfigDescrTag(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ Mp4Descr *descr = d->active_descr; ++ if (!descr) ++ return -1; ++ d->active_descr->dec_config_descr = av_malloc(len); ++ if (!descr->dec_config_descr) ++ return AVERROR(ENOMEM); ++ descr->dec_config_descr_len = len; ++ avio_read(&d->pb, descr->dec_config_descr, len); ++ return 0; ++} ++ ++static int parse_MP4SLDescrTag(MP4DescrParseContext *d, int64_t off, int len) ++{ ++ Mp4Descr *descr = d->active_descr; ++ int predefined; ++ if (!descr) ++ return -1; ++ ++ predefined = avio_r8(&d->pb); ++ if (!predefined) { ++ int lengths; ++ int flags = avio_r8(&d->pb); ++ descr->sl.use_au_start = !!(flags & 0x80); ++ descr->sl.use_au_end = !!(flags & 0x40); ++ descr->sl.use_rand_acc_pt = !!(flags & 0x20); ++ descr->sl.use_padding = !!(flags & 0x08); ++ descr->sl.use_timestamps = !!(flags & 0x04); ++ descr->sl.use_idle = !!(flags & 0x02); ++ descr->sl.timestamp_res = avio_rb32(&d->pb); ++ avio_rb32(&d->pb); ++ descr->sl.timestamp_len = avio_r8(&d->pb); ++ descr->sl.ocr_len = avio_r8(&d->pb); ++ descr->sl.au_len = avio_r8(&d->pb); ++ descr->sl.inst_bitrate_len = avio_r8(&d->pb); ++ lengths = avio_rb16(&d->pb); ++ descr->sl.degr_prior_len = lengths >> 12; ++ descr->sl.au_seq_num_len = (lengths >> 7) & 0x1f; ++ descr->sl.packet_seq_num_len = (lengths >> 2) & 0x1f; ++ } else { ++ av_log_missing_feature(d->s, "Predefined SLConfigDescriptor\n", 0); ++ } ++ return 0; ++} ++ ++static int parse_mp4_descr(MP4DescrParseContext *d, int64_t off, int len, ++ int target_tag) { + int tag; +- unsigned len; ++ int len1 = ff_mp4_read_descr(d->s, &d->pb, &tag); ++ update_offsets(&d->pb, &off, &len); ++ if (len < 0 || len1 > len || len1 <= 0) { ++ av_log(d->s, AV_LOG_ERROR, "Tag %x length violation new length %d bytes remaining %d\n", tag, len1, len); ++ return -1; ++ } ++ ++ if (d->level++ >= MAX_LEVEL) { ++ av_log(d->s, AV_LOG_ERROR, "Maximum MP4 descriptor level exceeded\n"); ++ goto done; ++ } ++ ++ if (target_tag && tag != target_tag) { ++ av_log(d->s, AV_LOG_ERROR, "Found tag %x expected %x\n", tag, target_tag); ++ goto done; ++ } ++ ++ switch (tag) { ++ case MP4IODescrTag: ++ parse_MP4IODescrTag(d, off, len1); ++ break; ++ case MP4ODescrTag: ++ parse_MP4ODescrTag(d, off, len1); ++ break; ++ case MP4ESDescrTag: ++ parse_MP4ESDescrTag(d, off, len1); ++ break; ++ case MP4DecConfigDescrTag: ++ parse_MP4DecConfigDescrTag(d, off, len1); ++ break; ++ case MP4SLDescrTag: ++ parse_MP4SLDescrTag(d, off, len1); ++ break; ++ } ++ ++done: ++ d->level--; ++ avio_seek(&d->pb, off + len1, SEEK_SET); ++ return 0; ++} ++ ++static int mp4_read_iods(AVFormatContext *s, const uint8_t *buf, unsigned size, ++ Mp4Descr *descr, int *descr_count, int max_descr_count) ++{ ++ MP4DescrParseContext d; ++ if (init_MP4DescrParseContext(&d, s, buf, size, descr, max_descr_count) < 0) ++ return -1; ++ ++ parse_mp4_descr(&d, avio_tell(&d.pb), size, MP4IODescrTag); ++ ++ *descr_count = d.descr_count; ++ return 0; ++} ++ ++static int mp4_read_od(AVFormatContext *s, const uint8_t *buf, unsigned size, ++ Mp4Descr *descr, int *descr_count, int max_descr_count) ++{ ++ MP4DescrParseContext d; ++ if (init_MP4DescrParseContext(&d, s, buf, size, descr, max_descr_count) < 0) ++ return -1; ++ ++ parse_mp4_descr_arr(&d, avio_tell(&d.pb), size); ++ ++ *descr_count = d.descr_count; ++ return 0; ++} ++ ++static void m4sl_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) ++{ ++ MpegTSContext *ts = filter->u.section_filter.opaque; ++ SectionHeader h; ++ const uint8_t *p, *p_end; ++ AVIOContext pb; ++ Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = {{ 0 }}; ++ int mp4_descr_count = 0; ++ int i, pid; ++ AVFormatContext *s = ts->stream; ++ ++ p_end = section + section_len - 4; ++ p = section; ++ if (parse_section_header(&h, &p, p_end) < 0) ++ return; ++ if (h.tid != M4OD_TID) ++ return; ++ ++ mp4_read_od(s, p, (unsigned)(p_end - p), mp4_descr, &mp4_descr_count, MAX_MP4_DESCR_COUNT); ++ ++ for (pid = 0; pid < NB_PID_MAX; pid++) { ++ if (!ts->pids[pid]) ++ continue; ++ for (i = 0; i < mp4_descr_count; i++) { ++ PESContext *pes; ++ AVStream *st; ++ if (ts->pids[pid]->es_id != mp4_descr[i].es_id) ++ continue; ++ if (!(ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES)) { ++ av_log(s, AV_LOG_ERROR, "pid %x is not PES\n", pid); ++ continue; ++ } ++ pes = ts->pids[pid]->u.pes_filter.opaque; ++ st = pes->st; ++ if (!st) { ++ continue; ++ } ++ ++ pes->sl = mp4_descr[i].sl; + +- init_put_byte(&pb, buf, size, 0, NULL, NULL, NULL, NULL); ++ ffio_init_context(&pb, mp4_descr[i].dec_config_descr, ++ mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ++ ff_mp4_read_dec_config_descr(s, st, &pb); ++ if (st->codec->codec_id == CODEC_ID_AAC && ++ st->codec->extradata_size > 0) ++ st->need_parsing = 0; ++ if (st->codec->codec_id == CODEC_ID_H264 && ++ st->codec->extradata_size > 0) ++ st->need_parsing = 0; + +- len = ff_mp4_read_descr(s, &pb, &tag); +- if (tag == MP4IODescrTag) { +- get_be16(&pb); // ID +- get_byte(&pb); +- get_byte(&pb); +- get_byte(&pb); +- get_byte(&pb); +- get_byte(&pb); +- len = ff_mp4_read_descr(s, &pb, &tag); +- if (tag == MP4ESDescrTag) { +- *es_id = get_be16(&pb); /* ES_ID */ +- av_dlog(s, "ES_ID %#x\n", *es_id); +- get_byte(&pb); /* priority */ +- len = ff_mp4_read_descr(s, &pb, &tag); +- if (tag == MP4DecConfigDescrTag) { +- *dec_config_descr = av_malloc(len); +- if (!*dec_config_descr) +- return AVERROR(ENOMEM); +- *dec_config_descr_size = len; +- get_buffer(&pb, *dec_config_descr, len); ++ if (st->codec->codec_id <= CODEC_ID_NONE) { ++ } else if (st->codec->codec_id < CODEC_ID_FIRST_AUDIO) { ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ } else if (st->codec->codec_id < CODEC_ID_FIRST_SUBTITLE) { ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ } else if (st->codec->codec_id < CODEC_ID_FIRST_UNKNOWN) { ++ st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + } + } + } +- return 0; ++ for (i = 0; i < mp4_descr_count; i++) ++ av_free(mp4_descr[i].dec_config_descr); + } + + int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, + const uint8_t **pp, const uint8_t *desc_list_end, +- int mp4_dec_config_descr_len, int mp4_es_id, int pid, +- uint8_t *mp4_dec_config_descr) ++ Mp4Descr *mp4_descr, int mp4_descr_count, int pid, ++ MpegTSContext *ts) + { + const uint8_t *desc_end; +- int desc_len, desc_tag; +- char language[4]; ++ int desc_len, desc_tag, desc_es_id; ++ char language[252]; ++ int i; + + desc_tag = get8(pp, desc_list_end); + if (desc_tag < 0) +@@ -928,17 +1302,37 @@ + mpegts_find_stream_type(st, desc_tag, DESC_types); + + switch(desc_tag) { +- case 0x1F: /* FMC descriptor */ +- get16(pp, desc_end); +- if (st->codec->codec_id == CODEC_ID_AAC_LATM && +- mp4_dec_config_descr_len && mp4_es_id == pid) { +- ByteIOContext pb; +- init_put_byte(&pb, mp4_dec_config_descr, +- mp4_dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ++ case 0x1E: /* SL descriptor */ ++ desc_es_id = get16(pp, desc_end); ++ if (ts && ts->pids[pid]) ++ ts->pids[pid]->es_id = desc_es_id; ++ for (i = 0; i < mp4_descr_count; i++) ++ if (mp4_descr[i].dec_config_descr_len && ++ mp4_descr[i].es_id == desc_es_id) { ++ AVIOContext pb; ++ ffio_init_context(&pb, mp4_descr[i].dec_config_descr, ++ mp4_descr[i].dec_config_descr_len, 0, NULL, NULL, NULL, NULL); + ff_mp4_read_dec_config_descr(fc, st, &pb); + if (st->codec->codec_id == CODEC_ID_AAC && + st->codec->extradata_size > 0) + st->need_parsing = 0; ++ if (st->codec->codec_id == CODEC_ID_MPEG4SYSTEMS) ++ mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1); ++ } ++ break; ++ case 0x1F: /* FMC descriptor */ ++ get16(pp, desc_end); ++ if (mp4_descr_count > 0 && (st->codec->codec_id == CODEC_ID_AAC_LATM || st->request_probe>0) && ++ mp4_descr->dec_config_descr_len && mp4_descr->es_id == pid) { ++ AVIOContext pb; ++ ffio_init_context(&pb, mp4_descr->dec_config_descr, ++ mp4_descr->dec_config_descr_len, 0, NULL, NULL, NULL, NULL); ++ ff_mp4_read_dec_config_descr(fc, st, &pb); ++ if (st->codec->codec_id == CODEC_ID_AAC && ++ st->codec->extradata_size > 0){ ++ st->request_probe= st->need_parsing = 0; ++ st->codec->codec_type= AVMEDIA_TYPE_AUDIO; ++ } + } + break; + case 0x56: /* DVB teletext descriptor */ +@@ -946,14 +1340,24 @@ + language[1] = get8(pp, desc_end); + language[2] = get8(pp, desc_end); + language[3] = 0; +- av_metadata_set2(&st->metadata, "language", language, 0); ++ av_dict_set(&st->metadata, "language", language, 0); + break; + case 0x59: /* subtitling descriptor */ + language[0] = get8(pp, desc_end); + language[1] = get8(pp, desc_end); + language[2] = get8(pp, desc_end); + language[3] = 0; +- get8(pp, desc_end); ++ /* hearing impaired subtitles detection */ ++ switch(get8(pp, desc_end)) { ++ case 0x20: /* DVB subtitles (for the hard of hearing) with no monitor aspect ratio criticality */ ++ case 0x21: /* DVB subtitles (for the hard of hearing) for display on 4:3 aspect ratio monitor */ ++ case 0x22: /* DVB subtitles (for the hard of hearing) for display on 16:9 aspect ratio monitor */ ++ case 0x23: /* DVB subtitles (for the hard of hearing) for display on 2.21:1 aspect ratio monitor */ ++ case 0x24: /* DVB subtitles (for the hard of hearing) for display on a high definition monitor */ ++ case 0x25: /* DVB subtitles (for the hard of hearing) with plano-stereoscopic disparity for display on a high definition monitor */ ++ st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED; ++ break; ++ } + if (st->codec->extradata) { + if (st->codec->extradata_size == 4 && memcmp(st->codec->extradata, *pp, 4)) + av_log_ask_for_sample(fc, "DVB sub with multiple IDs\n"); +@@ -965,14 +1369,24 @@ + } + } + *pp += 4; +- av_metadata_set2(&st->metadata, "language", language, 0); ++ av_dict_set(&st->metadata, "language", language, 0); + break; + case 0x0a: /* ISO 639 language descriptor */ +- language[0] = get8(pp, desc_end); +- language[1] = get8(pp, desc_end); +- language[2] = get8(pp, desc_end); +- language[3] = 0; +- av_metadata_set2(&st->metadata, "language", language, 0); ++ for (i = 0; i + 4 <= desc_len; i += 4) { ++ language[i + 0] = get8(pp, desc_end); ++ language[i + 1] = get8(pp, desc_end); ++ language[i + 2] = get8(pp, desc_end); ++ language[i + 3] = ','; ++ switch (get8(pp, desc_end)) { ++ case 0x01: st->disposition |= AV_DISPOSITION_CLEAN_EFFECTS; break; ++ case 0x02: st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED; break; ++ case 0x03: st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED; break; ++ } ++ } ++ if (i) { ++ language[i - 1] = 0; ++ av_dict_set(&st->metadata, "language", language, 0); ++ } + break; + case 0x05: /* registration descriptor */ + st->codec->codec_tag = bytestream_get_le32(pp); +@@ -981,6 +1395,9 @@ + stream_type == STREAM_TYPE_PRIVATE_DATA) + mpegts_find_stream_type(st, st->codec->codec_tag, REGD_types); + break; ++ case 0x52: /* stream identifier descriptor */ ++ st->stream_identifier = 1 + get8(pp, desc_end); ++ break; + default: + break; + } +@@ -998,14 +1415,13 @@ + int program_info_length, pcr_pid, pid, stream_type; + int desc_list_len; + uint32_t prog_reg_desc = 0; /* registration descriptor */ +- uint8_t *mp4_dec_config_descr = NULL; +- int mp4_dec_config_descr_len = 0; +- int mp4_es_id = 0; + +-#ifdef DEBUG ++ Mp4Descr mp4_descr[MAX_MP4_DESCR_COUNT] = {{ 0 }}; ++ int mp4_descr_count = 0; ++ int i; ++ + av_dlog(ts->stream, "PMT: len %i\n", section_len); +- av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); +-#endif ++ hex_dump_debug(ts->stream, (uint8_t *)section, section_len); + + p_end = section + section_len - 4; + p = section; +@@ -1023,6 +1439,7 @@ + if (pcr_pid < 0) + return; + add_pid_to_pmt(ts, h->id, pcr_pid); ++ set_pcr_pid(ts->stream, h->id, pcr_pid); + + av_dlog(ts->stream, "pcr_pid=0x%x\n", pcr_pid); + +@@ -1044,8 +1461,8 @@ + get8(&p, p_end); // scope + get8(&p, p_end); // label + len -= 2; +- mp4_read_iods(ts->stream, p, len, &mp4_es_id, +- &mp4_dec_config_descr, &mp4_dec_config_descr_len); ++ mp4_read_iods(ts->stream, p, len, mp4_descr + mp4_descr_count, ++ &mp4_descr_count, MAX_MP4_DESCR_COUNT); + } else if (tag == 0x05 && len >= 4) { // registration descriptor + prog_reg_desc = bytestream_get_le32(&p); + len -= 4; +@@ -1058,10 +1475,11 @@ + + // stop parsing after pmt, we found header + if (!ts->stream->nb_streams) +- ts->stop_parse = 1; ++ ts->stop_parse = 2; + + for(;;) { + st = 0; ++ pes = NULL; + stream_type = get8(&p, p_end); + if (stream_type < 0) + break; +@@ -1069,23 +1487,36 @@ + if (pid < 0) + break; + +- /* now create ffmpeg stream */ ++ /* now create stream */ + if (ts->pids[pid] && ts->pids[pid]->type == MPEGTS_PES) { + pes = ts->pids[pid]->u.pes_filter.opaque; +- if (!pes->st) +- pes->st = av_new_stream(pes->stream, pes->pid); ++ if (!pes->st) { ++ pes->st = avformat_new_stream(pes->stream, NULL); ++ pes->st->id = pes->pid; ++ } + st = pes->st; +- } else { ++ } else if (stream_type != 0x13) { + if (ts->pids[pid]) mpegts_close_filter(ts, ts->pids[pid]); //wrongly added sdt filter probably + pes = add_pes_stream(ts, pid, pcr_pid); +- if (pes) +- st = av_new_stream(pes->stream, pes->pid); ++ if (pes) { ++ st = avformat_new_stream(pes->stream, NULL); ++ st->id = pes->pid; ++ } ++ } else { ++ int idx = ff_find_stream_index(ts->stream, pid); ++ if (idx >= 0) { ++ st = ts->stream->streams[idx]; ++ } else { ++ st = avformat_new_stream(ts->stream, NULL); ++ st->id = pid; ++ st->codec->codec_type = AVMEDIA_TYPE_DATA; ++ } + } + + if (!st) + goto out; + +- if (!pes->stream_type) ++ if (pes && !pes->stream_type) + mpegts_set_stream_info(st, pes, stream_type, prog_reg_desc); + + add_pid_to_pmt(ts, h->id, pid); +@@ -1100,10 +1531,10 @@ + break; + for(;;) { + if (ff_parse_mpeg2_descriptor(ts->stream, st, stream_type, &p, desc_list_end, +- mp4_dec_config_descr_len, mp4_es_id, pid, mp4_dec_config_descr) < 0) ++ mp4_descr, mp4_descr_count, pid, ts) < 0) + break; + +- if (prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) { ++ if (pes && prog_reg_desc == AV_RL32("HDMV") && stream_type == 0x83 && pes->sub_st) { + ff_program_add_stream_index(ts->stream, h->id, pes->sub_st->index); + pes->sub_st->codec->codec_tag = st->codec->codec_tag; + } +@@ -1112,7 +1543,8 @@ + } + + out: +- av_free(mp4_dec_config_descr); ++ for (i = 0; i < mp4_descr_count; i++) ++ av_free(mp4_descr[i].dec_config_descr); + } + + static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len) +@@ -1121,11 +1553,11 @@ + SectionHeader h1, *h = &h1; + const uint8_t *p, *p_end; + int sid, pmt_pid; ++ AVProgram *program; + +-#ifdef DEBUG + av_dlog(ts->stream, "PAT:\n"); +- av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); +-#endif ++ hex_dump_debug(ts->stream, (uint8_t *)section, section_len); ++ + p_end = section + section_len - 4; + p = section; + if (parse_section_header(h, &p, p_end) < 0) +@@ -1139,6 +1571,8 @@ + filter->last_version = h->version; + av_dlog(ts->stream, "version=%d\n", filter->last_version); + ++ ts->stream->ts_id = h->id; ++ + clear_programs(ts); + for(;;) { + sid = get16(&p, p_end); +@@ -1153,7 +1587,9 @@ + if (sid == 0x0000) { + /* NIT info */ + } else { +- av_new_program(ts->stream, sid); ++ program = av_new_program(ts->stream, sid); ++ program->program_num = sid; ++ program->pmt_pid = pmt_pid; + if (ts->pids[pmt_pid]) + mpegts_close_filter(ts, ts->pids[pmt_pid]); + mpegts_open_section_filter(ts, pmt_pid, pmt_cb, ts, 1); +@@ -1172,10 +1608,8 @@ + int onid, val, sid, desc_list_len, desc_tag, desc_len, service_type; + char *name, *provider_name; + +-#ifdef DEBUG + av_dlog(ts->stream, "SDT:\n"); +- av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); +-#endif ++ hex_dump_debug(ts->stream, (uint8_t *)section, section_len); + + p_end = section + section_len - 4; + p = section; +@@ -1226,8 +1660,8 @@ + if (name) { + AVProgram *program = av_new_program(ts->stream, sid); + if(program) { +- av_metadata_set2(&program->metadata, "service_name", name, 0); +- av_metadata_set2(&program->metadata, "service_provider", provider_name, 0); ++ av_dict_set(&program->metadata, "service_name", name, 0); ++ av_dict_set(&program->metadata, "service_provider", provider_name, 0); + } + } + av_free(name); +@@ -1247,7 +1681,8 @@ + { + AVFormatContext *s = ts->stream; + MpegTSFilter *tss; +- int len, pid, cc, cc_ok, afc, is_start; ++ int len, pid, cc, expected_cc, cc_ok, afc, is_start, is_discontinuity, ++ has_adaptation, has_payload; + const uint8_t *p, *p_end; + int64_t pos; + +@@ -1263,20 +1698,39 @@ + if (!tss) + return 0; + ++ afc = (packet[3] >> 4) & 3; ++ if (afc == 0) /* reserved value */ ++ return 0; ++ has_adaptation = afc & 2; ++ has_payload = afc & 1; ++ is_discontinuity = has_adaptation ++ && packet[4] != 0 /* with length > 0 */ ++ && (packet[5] & 0x80); /* and discontinuity indicated */ ++ + /* continuity check (currently not used) */ + cc = (packet[3] & 0xf); +- cc_ok = (tss->last_cc < 0) || ((((tss->last_cc + 1) & 0x0f) == cc)); ++ expected_cc = has_payload ? (tss->last_cc + 1) & 0x0f : tss->last_cc; ++ cc_ok = pid == 0x1FFF // null packet PID ++ || is_discontinuity ++ || tss->last_cc < 0 ++ || expected_cc == cc; ++ + tss->last_cc = cc; ++ if (!cc_ok) { ++ av_log(ts->stream, AV_LOG_DEBUG, ++ "Continuity check failed for pid %d expected %d got %d\n", ++ pid, expected_cc, cc); ++ if(tss->type == MPEGTS_PES) { ++ PESContext *pc = tss->u.pes_filter.opaque; ++ pc->flags |= AV_PKT_FLAG_CORRUPT; ++ } ++ } + +- /* skip adaptation field */ +- afc = (packet[3] >> 4) & 3; +- p = packet + 4; +- if (afc == 0) /* reserved value */ +- return 0; +- if (afc == 2) /* adaptation field only */ ++ if (!has_payload) + return 0; +- if (afc == 3) { +- /* skip adapation field */ ++ p = packet + 4; ++ if (has_adaptation) { ++ /* skip adaptation field */ + p += p[0] + 1; + } + /* if past the end of packet, ignore */ +@@ -1284,7 +1738,7 @@ + if (p >= p_end) + return 0; + +- pos = url_ftell(ts->stream->pb); ++ pos = avio_tell(ts->stream->pb); + ts->pos47= pos % ts->raw_packet_size; + + if (tss->type == MPEGTS_SECTION) { +@@ -1327,15 +1781,15 @@ + get_packet_size() ?) */ + static int mpegts_resync(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int c, i; + + for(i = 0;i < MAX_RESYNC_SIZE; i++) { +- c = url_fgetc(pb); +- if (c < 0) ++ c = avio_r8(pb); ++ if (url_feof(pb)) + return -1; + if (c == 0x47) { +- url_fseek(pb, -1, SEEK_CUR); ++ avio_seek(pb, -1, SEEK_CUR); + return 0; + } + } +@@ -1347,17 +1801,17 @@ + /* return -1 if error or EOF. Return 0 if OK. */ + static int read_packet(AVFormatContext *s, uint8_t *buf, int raw_packet_size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int skip, len; + + for(;;) { +- len = get_buffer(pb, buf, TS_PACKET_SIZE); ++ len = avio_read(pb, buf, TS_PACKET_SIZE); + if (len != TS_PACKET_SIZE) +- return AVERROR(EIO); +- /* check paquet sync byte */ ++ return len < 0 ? len : AVERROR_EOF; ++ /* check packet sync byte */ + if (buf[0] != 0x47) { + /* find a new packet start */ +- url_fseek(pb, -TS_PACKET_SIZE, SEEK_CUR); ++ avio_seek(pb, -TS_PACKET_SIZE, SEEK_CUR); + if (mpegts_resync(s) < 0) + return AVERROR(EAGAIN); + else +@@ -1365,7 +1819,7 @@ + } else { + skip = raw_packet_size - TS_PACKET_SIZE; + if (skip > 0) +- url_fskip(pb, skip); ++ avio_skip(pb, skip); + break; + } + } +@@ -1375,25 +1829,48 @@ + static int handle_packets(MpegTSContext *ts, int nb_packets) + { + AVFormatContext *s = ts->stream; +- uint8_t packet[TS_PACKET_SIZE]; +- int packet_num, ret; ++ uint8_t packet[TS_PACKET_SIZE+FF_INPUT_BUFFER_PADDING_SIZE]; ++ int packet_num, ret = 0; ++ ++ if (avio_tell(s->pb) != ts->last_pos) { ++ int i; ++ av_dlog(ts->stream, "Skipping after seek\n"); ++ /* seek detected, flush pes buffer */ ++ for (i = 0; i < NB_PID_MAX; i++) { ++ if (ts->pids[i]) { ++ if (ts->pids[i]->type == MPEGTS_PES) { ++ PESContext *pes = ts->pids[i]->u.pes_filter.opaque; ++ av_freep(&pes->buffer); ++ pes->data_index = 0; ++ pes->state = MPEGTS_SKIP; /* skip until pes header */ ++ } ++ ts->pids[i]->last_cc = -1; ++ } ++ } ++ } + + ts->stop_parse = 0; + packet_num = 0; ++ memset(packet + TS_PACKET_SIZE, 0, FF_INPUT_BUFFER_PADDING_SIZE); + for(;;) { +- if (ts->stop_parse>0) +- break; + packet_num++; +- if (nb_packets != 0 && packet_num >= nb_packets) ++ if (nb_packets != 0 && packet_num >= nb_packets || ++ ts->stop_parse > 1) { ++ ret = AVERROR(EAGAIN); ++ break; ++ } ++ if (ts->stop_parse > 0) + break; ++ + ret = read_packet(s, packet, ts->raw_packet_size); + if (ret != 0) +- return ret; ++ break; + ret = handle_packet(ts, packet); + if (ret != 0) +- return ret; ++ break; + } +- return 0; ++ ts->last_pos = avio_tell(s->pb); ++ return ret; + } + + static int mpegts_probe(AVProbeData *p) +@@ -1497,36 +1974,33 @@ + AVFormatParameters *ap) + { + MpegTSContext *ts = s->priv_data; +- ByteIOContext *pb = s->pb; +- uint8_t buf[5*1024]; ++ AVIOContext *pb = s->pb; ++ uint8_t buf[8*1024]; + int len; + int64_t pos; + +- if (ap) { +- ts->mpeg2ts_compute_pcr = ap->mpeg2ts_compute_pcr; +- if(ap->mpeg2ts_raw){ +- av_log(s, AV_LOG_ERROR, "use mpegtsraw_demuxer!\n"); +- return -1; +- } +- } +- +- /* read the first 1024 bytes to get packet size */ +- pos = url_ftell(pb); +- len = get_buffer(pb, buf, sizeof(buf)); ++ /* read the first 8192 bytes to get packet size */ ++ pos = avio_tell(pb); ++ len = avio_read(pb, buf, sizeof(buf)); + if (len != sizeof(buf)) + goto fail; + ts->raw_packet_size = get_packet_size(buf, sizeof(buf)); +- if (ts->raw_packet_size <= 0) +- goto fail; ++ if (ts->raw_packet_size <= 0) { ++ av_log(s, AV_LOG_WARNING, "Could not detect TS packet size, defaulting to non-FEC/DVHS\n"); ++ ts->raw_packet_size = TS_PACKET_SIZE; ++ } + ts->stream = s; + ts->auto_guess = 0; + + if (s->iformat == &ff_mpegts_demuxer) { + /* normal demux */ + +- /* first do a scaning to get all the services */ +- if (url_fseek(pb, pos, SEEK_SET) < 0) +- av_log(s, AV_LOG_ERROR, "Unable to seek back to the start\n"); ++ /* first do a scan to get all the services */ ++ /* NOTE: We attempt to seek on non-seekable files as well, as the ++ * probe buffer usually is big enough. Only warn if the seek failed ++ * on files where the seek should work. */ ++ if (avio_seek(pb, pos, SEEK_SET) < 0) ++ av_log(s, pb->seekable ? AV_LOG_ERROR : AV_LOG_INFO, "Unable to seek back to the start\n"); + + mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); + +@@ -1552,10 +2026,10 @@ + + /* only read packets */ + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + goto fail; +- av_set_pts_info(st, 60, 1, 27000000); ++ avpriv_set_pts_info(st, 60, 1, 27000000); + st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->codec->codec_id = CODEC_ID_MPEG2TS; + +@@ -1587,13 +2061,11 @@ + s->bit_rate = (TS_PACKET_SIZE * 8) * 27e6 / ts->pcr_incr; + st->codec->bit_rate = s->bit_rate; + st->start_time = ts->cur_pcr; +-#if 0 +- av_log(ts->stream, AV_LOG_DEBUG, "start=%0.3f pcr=%0.3f incr=%d\n", +- st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); +-#endif ++ av_dlog(ts->stream, "start=%0.3f pcr=%0.3f incr=%d\n", ++ st->start_time / 1000000.0, pcrs[0] / 27e6, ts->pcr_incr); + } + +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + return 0; + fail: + return -1; +@@ -1612,7 +2084,7 @@ + + if (av_new_packet(pkt, TS_PACKET_SIZE) < 0) + return AVERROR(ENOMEM); +- pkt->pos= url_ftell(s->pb); ++ pkt->pos= avio_tell(s->pb); + ret = read_packet(s, pkt->data, ts->raw_packet_size); + if (ret < 0) { + av_free_packet(pkt); +@@ -1622,10 +2094,10 @@ + /* compute exact PCR for each packet */ + if (parse_pcr(&pcr_h, &pcr_l, pkt->data) == 0) { + /* we read the next PCR (XXX: optimize it by using a bigger buffer */ +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + for(i = 0; i < MAX_PACKET_READAHEAD; i++) { +- url_fseek(s->pb, pos + i * ts->raw_packet_size, SEEK_SET); +- get_buffer(s->pb, pcr_buf, 12); ++ avio_seek(s->pb, pos + i * ts->raw_packet_size, SEEK_SET); ++ avio_read(s->pb, pcr_buf, 12); + if (parse_pcr(&next_pcr_h, &next_pcr_l, pcr_buf) == 0) { + /* XXX: not precise enough */ + ts->pcr_incr = ((next_pcr_h - pcr_h) * 300 + (next_pcr_l - pcr_l)) / +@@ -1633,7 +2105,7 @@ + break; + } + } +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + /* no next PCR found: we use previous increment */ + ts->cur_pcr = pcr_h * 300 + pcr_l; + } +@@ -1651,18 +2123,6 @@ + MpegTSContext *ts = s->priv_data; + int ret, i; + +- if (url_ftell(s->pb) != ts->last_pos) { +- /* seek detected, flush pes buffer */ +- for (i = 0; i < NB_PID_MAX; i++) { +- if (ts->pids[i] && ts->pids[i]->type == MPEGTS_PES) { +- PESContext *pes = ts->pids[i]->u.pes_filter.opaque; +- av_freep(&pes->buffer); +- pes->data_index = 0; +- pes->state = MPEGTS_SKIP; /* skip until pes header */ +- } +- } +- } +- + ts->pkt = pkt; + ts->pkt->data = NULL; + +@@ -1682,8 +2142,6 @@ + } + } + +- ts->last_pos = url_ftell(s->pb); +- + return ret; + } + +@@ -1710,31 +2168,58 @@ + int pid = ((PESContext*)s->streams[stream_index]->priv_data)->pid; + pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; + while(pos < pos_limit) { +- if (url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) ++ return AV_NOPTS_VALUE; ++ if (avio_read(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) + return AV_NOPTS_VALUE; +- if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) +- return AV_NOPTS_VALUE; + if (buf[0] != 0x47) { +- url_fseek(s->pb, -TS_PACKET_SIZE, SEEK_CUR); + if (mpegts_resync(s) < 0) + return AV_NOPTS_VALUE; +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + continue; +- } +- if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && +- parse_pcr(×tamp, &pcr_l, buf) == 0) { ++ } ++ if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && ++ parse_pcr(×tamp, &pcr_l, buf) == 0) { + *ppos = pos; + return timestamp; +- } +- ++ } + if ((pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pid) && + parse_timestamp(×tamp, buf) == 0) { +- *ppos = pos; ++ *ppos = pos; ++ return timestamp; ++ } ++ pos += ts->raw_packet_size; ++ } + +- return timestamp; ++ return AV_NOPTS_VALUE; + } + +- pos += ts->raw_packet_size; ++static int64_t mpegts_get_dts(AVFormatContext *s, int stream_index, ++ int64_t *ppos, int64_t pos_limit) ++{ ++ MpegTSContext *ts = s->priv_data; ++ int64_t pos; ++ pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; ++ ff_read_frame_flush(s); ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) ++ return AV_NOPTS_VALUE; ++ while(pos < pos_limit) { ++ int ret; ++ AVPacket pkt; ++ av_init_packet(&pkt); ++ ret= av_read_frame(s, &pkt); ++ if(ret < 0) ++ return AV_NOPTS_VALUE; ++ av_free_packet(&pkt); ++ if(pkt.dts != AV_NOPTS_VALUE && pkt.pos >= 0){ ++ ff_reduce_index(s, pkt.stream_index); ++ av_add_index_entry(s->streams[pkt.stream_index], pkt.pos, pkt.dts, 0, 0, AVINDEX_KEYFRAME /* FIXME keyframe? */); ++ if(pkt.stream_index == stream_index){ ++ *ppos= pkt.pos; ++ return pkt.dts; ++ } ++ } ++ pos = pkt.pos; + } + + return AV_NOPTS_VALUE; +@@ -1783,7 +2268,7 @@ + ts_adj = target_ts; + stream_index_gen_search = stream_index; + } +- pos = av_gen_search(s, stream_index_gen_search, ts_adj, ++ pos = ff_gen_search(s, stream_index_gen_search, ts_adj, + 0, INT64_MAX, -1, + AV_NOPTS_VALUE, + AV_NOPTS_VALUE, +@@ -1824,30 +2309,6 @@ + return ret; + } + +-#else +- +-static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ +- MpegTSContext *ts = s->priv_data; +- uint8_t buf[TS_PACKET_SIZE]; +- int64_t pos; +- +- if(av_seek_frame_binary(s, stream_index, target_ts, flags) < 0) +- return -1; +- +- pos= url_ftell(s->pb); +- +- for(;;) { +- url_fseek(s->pb, pos, SEEK_SET); +- if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) +- return -1; +-// pid = AV_RB16(buf + 1) & 0x1fff; +- if(buf[1] & 0x40) break; +- pos += ts->raw_packet_size; +- } +- +- return 0; +-} +- + #endif + + /**************************************************************/ +@@ -1879,11 +2340,8 @@ + + len1 = len; + ts->pkt = pkt; +- ts->pkt->data = NULL; +- ts->stop_parse = 0; + for(;;) { +- if (ts->stop_parse>0) +- break; ++ ts->stop_parse = 0; + if (len < TS_PACKET_SIZE) + return -1; + if (buf[0] != 0x47) { +@@ -1893,6 +2351,8 @@ + handle_packet(ts, buf); + buf += TS_PACKET_SIZE; + len -= TS_PACKET_SIZE; ++ if (ts->stop_parse == 1) ++ break; + } + } + return len1 - len; +@@ -1908,15 +2368,14 @@ + } + + AVInputFormat ff_mpegts_demuxer = { +- "mpegts", +- NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), +- sizeof(MpegTSContext), +- mpegts_probe, +- mpegts_read_header, +- mpegts_read_packet, +- mpegts_read_close, +- NULL, +- mpegts_get_pcr, ++ .name = "mpegts", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), ++ .priv_data_size = sizeof(MpegTSContext), ++ .read_probe = mpegts_probe, ++ .read_header = mpegts_read_header, ++ .read_packet = mpegts_read_packet, ++ .read_close = mpegts_read_close, ++ .read_timestamp = mpegts_get_pcr, + .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, + #ifdef USE_SYNCPOINT_SEARCH + .read_seek2 = read_seek2, +@@ -1924,17 +2383,16 @@ + }; + + AVInputFormat ff_mpegtsraw_demuxer = { +- "mpegtsraw", +- NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"), +- sizeof(MpegTSContext), +- NULL, +- mpegts_read_header, +- mpegts_raw_read_packet, +- mpegts_read_close, +- NULL, +- mpegts_get_pcr, ++ .name = "mpegtsraw", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 raw transport stream format"), ++ .priv_data_size = sizeof(MpegTSContext), ++ .read_header = mpegts_read_header, ++ .read_packet = mpegts_raw_read_packet, ++ .read_close = mpegts_read_close, ++ .read_timestamp = mpegts_get_pcr, + .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, + #ifdef USE_SYNCPOINT_SEARCH + .read_seek2 = read_seek2, + #endif ++ .priv_class = &mpegtsraw_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegtsenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegtsenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegtsenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegtsenc.c 2012-05-14 14:08:55.069354775 +0200 +@@ -21,7 +21,10 @@ + + #include "libavutil/bswap.h" + #include "libavutil/crc.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "libavutil/opt.h" ++#include "libavutil/avassert.h" + #include "libavcodec/mpegvideo.h" + #include "avformat.h" + #include "internal.h" +@@ -53,6 +56,7 @@ + } MpegTSService; + + typedef struct MpegTSWrite { ++ const AVClass *av_class; + MpegTSSection pat; /* MPEG2 pat table */ + MpegTSSection sdt; /* MPEG2 sdt table context */ + MpegTSService **services; +@@ -65,6 +69,7 @@ + int tsid; + int64_t first_pcr; + int mux_rate; ///< set to 1 when VBR ++ int pes_payload_size; + + int transport_stream_id; + int original_network_id; +@@ -72,27 +77,38 @@ + + int pmt_start_pid; + int start_pid; ++ int m2ts_mode; + } MpegTSWrite; + ++/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ ++#define DEFAULT_PES_HEADER_FREQ 16 ++#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) ++ + static const AVOption options[] = { + { "mpegts_transport_stream_id", "Set transport_stream_id field.", +- offsetof(MpegTSWrite, transport_stream_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MpegTSWrite, transport_stream_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, + { "mpegts_original_network_id", "Set original_network_id field.", +- offsetof(MpegTSWrite, original_network_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MpegTSWrite, original_network_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, + { "mpegts_service_id", "Set service_id field.", +- offsetof(MpegTSWrite, service_id), FF_OPT_TYPE_INT, 0x0001, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MpegTSWrite, service_id), AV_OPT_TYPE_INT, {.dbl = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM}, + { "mpegts_pmt_start_pid", "Set the first pid of the PMT.", +- offsetof(MpegTSWrite, pmt_start_pid), FF_OPT_TYPE_INT, 0x1000, 0x1000, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MpegTSWrite, pmt_start_pid), AV_OPT_TYPE_INT, {.dbl = 0x1000 }, 0x0010, 0x1f00, AV_OPT_FLAG_ENCODING_PARAM}, + { "mpegts_start_pid", "Set the first pid.", +- offsetof(MpegTSWrite, start_pid), FF_OPT_TYPE_INT, 0x0100, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM}, ++ offsetof(MpegTSWrite, start_pid), AV_OPT_TYPE_INT, {.dbl = 0x0100 }, 0x0100, 0x0f00, AV_OPT_FLAG_ENCODING_PARAM}, ++ {"mpegts_m2ts_mode", "Enable m2ts mode.", ++ offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_INT, {.dbl = -1 }, ++ -1,1, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "muxrate", NULL, offsetof(MpegTSWrite, mux_rate), AV_OPT_TYPE_INT, {1}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, ++ { "pes_payload_size", "Minimum PES packet payload in bytes", ++ offsetof(MpegTSWrite, pes_payload_size), AV_OPT_TYPE_INT, {DEFAULT_PES_PAYLOAD_SIZE}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM}, + { NULL }, + }; + + static const AVClass mpegts_muxer_class = { +- "MPEGTS muxer", +- av_default_item_name, +- options, +- LIBAVUTIL_VERSION_INT, ++ .class_name = "MPEGTS muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, + }; + + /* NOTE: 4 bytes must be left at the end for the crc32 */ +@@ -163,7 +179,7 @@ + tot_len = 3 + 5 + len + 4; + /* check if not too big */ + if (tot_len > 1024) +- return -1; ++ return AVERROR_INVALIDDATA; + + q = section; + *q++ = tid; +@@ -184,10 +200,6 @@ + #define DEFAULT_PROVIDER_NAME "FFmpeg" + #define DEFAULT_SERVICE_NAME "Service01" + +-/* a PES packet header is generated every DEFAULT_PES_HEADER_FREQ packets */ +-#define DEFAULT_PES_HEADER_FREQ 16 +-#define DEFAULT_PES_PAYLOAD_SIZE ((DEFAULT_PES_HEADER_FREQ - 1) * 184 + 170) +- + /* we retransmit the SI info at this rate */ + #define SDT_RETRANS_TIME 500 + #define PAT_RETRANS_TIME 100 +@@ -197,11 +209,12 @@ + struct MpegTSService *service; + int pid; /* stream associated pid */ + int cc; +- int payload_index; ++ int payload_size; + int first_pts_check; ///< first pts check needed + int64_t payload_pts; + int64_t payload_dts; +- uint8_t payload[DEFAULT_PES_PAYLOAD_SIZE]; ++ int payload_flags; ++ uint8_t *payload; + ADTSContext *adts; + } MpegTSWriteStream; + +@@ -243,7 +256,7 @@ + for(i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MpegTSWriteStream *ts_st = st->priv_data; +- AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL,0); ++ AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL,0); + switch(st->codec->codec_id) { + case CODEC_ID_MPEG1VIDEO: + case CODEC_ID_MPEG2VIDEO: +@@ -283,13 +296,44 @@ + /* write optional descriptors here */ + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_AUDIO: +- if (lang && strlen(lang->value) == 3) { ++ if(st->codec->codec_id==CODEC_ID_EAC3){ ++ *q++=0x7a; // EAC3 descriptor see A038 DVB SI ++ *q++=1; // 1 byte, all flags sets to 0 ++ *q++=0; // omit all fields... ++ } ++ ++ if (lang) { ++ char *p; ++ char *next = lang->value; ++ uint8_t *len_ptr; ++ + *q++ = 0x0a; /* ISO 639 language descriptor */ +- *q++ = 4; +- *q++ = lang->value[0]; +- *q++ = lang->value[1]; +- *q++ = lang->value[2]; +- *q++ = 0; /* undefined type */ ++ len_ptr = q++; ++ *len_ptr = 0; ++ ++ for (p = lang->value; next && *len_ptr < 255 / 4 * 4; p = next + 1) { ++ next = strchr(p, ','); ++ if (strlen(p) != 3 && (!next || next != p + 3)) ++ continue; /* not a 3-letter code */ ++ ++ *q++ = *p++; ++ *q++ = *p++; ++ *q++ = *p++; ++ ++ if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS) ++ *q++ = 0x01; ++ else if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) ++ *q++ = 0x02; ++ else if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED) ++ *q++ = 0x03; ++ else ++ *q++ = 0; /* undefined type */ ++ ++ *len_ptr += 4; ++ } ++ ++ if (*len_ptr == 0) ++ q -= 2; /* no language codes were written */ + } + break; + case AVMEDIA_TYPE_SUBTITLE: +@@ -396,7 +440,7 @@ + service = av_mallocz(sizeof(MpegTSService)); + if (!service) + return NULL; +- service->pmt.pid = ts->pmt_start_pid + ts->nb_services - 1; ++ service->pmt.pid = ts->pmt_start_pid + ts->nb_services; + service->sid = sid; + service->provider_name = av_strdup(provider_name); + service->name = av_strdup(name); +@@ -405,10 +449,29 @@ + return service; + } + ++static int64_t get_pcr(const MpegTSWrite *ts, AVIOContext *pb) ++{ ++ return av_rescale(avio_tell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + ++ ts->first_pcr; ++} ++ ++static void mpegts_prefix_m2ts_header(AVFormatContext *s) ++{ ++ MpegTSWrite *ts = s->priv_data; ++ if (ts->m2ts_mode) { ++ int64_t pcr = get_pcr(s->priv_data, s->pb); ++ uint32_t tp_extra_header = pcr % 0x3fffffff; ++ tp_extra_header = AV_RB32(&tp_extra_header); ++ avio_write(s->pb, (unsigned char *) &tp_extra_header, ++ sizeof(tp_extra_header)); ++ } ++} ++ + static void section_write_packet(MpegTSSection *s, const uint8_t *packet) + { + AVFormatContext *ctx = s->opaque; +- put_buffer(ctx->pb, packet, TS_PACKET_SIZE); ++ mpegts_prefix_m2ts_header(ctx); ++ avio_write(ctx->pb, packet, TS_PACKET_SIZE); + } + + static int mpegts_write_header(AVFormatContext *s) +@@ -417,20 +480,23 @@ + MpegTSWriteStream *ts_st; + MpegTSService *service; + AVStream *st, *pcr_st = NULL; +- AVMetadataTag *title, *provider; ++ AVDictionaryEntry *title, *provider; + int i, j; + const char *service_name; + const char *provider_name; + int *pids; + ++ // round up to a whole number of TS packets ++ ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14; ++ + ts->tsid = ts->transport_stream_id; + ts->onid = ts->original_network_id; + /* allocate a single DVB service */ +- title = av_metadata_get(s->metadata, "service_name", NULL, 0); ++ title = av_dict_get(s->metadata, "service_name", NULL, 0); + if (!title) +- title = av_metadata_get(s->metadata, "title", NULL, 0); ++ title = av_dict_get(s->metadata, "title", NULL, 0); + service_name = title ? title->value : DEFAULT_SERVICE_NAME; +- provider = av_metadata_get(s->metadata, "service_provider", NULL, 0); ++ provider = av_dict_get(s->metadata, "service_provider", NULL, 0); + provider_name = provider ? provider->value : DEFAULT_PROVIDER_NAME; + service = mpegts_add_service(ts, ts->service_id, provider_name, service_name); + service->pmt.write_packet = section_write_packet; +@@ -454,10 +520,14 @@ + /* assign pids to each stream */ + for(i = 0;i < s->nb_streams; i++) { + st = s->streams[i]; ++ avpriv_set_pts_info(st, 33, 1, 90000); + ts_st = av_mallocz(sizeof(MpegTSWriteStream)); + if (!ts_st) + goto fail; + st->priv_data = ts_st; ++ ts_st->payload = av_mallocz(ts->pes_payload_size); ++ if (!ts_st->payload) ++ goto fail; + ts_st->service = service; + /* MPEG pid values < 16 are reserved. Applications which set st->id in + * this range are assigned a calculated pid. */ +@@ -493,10 +563,10 @@ + st->codec->extradata_size > 0) { + ts_st->adts = av_mallocz(sizeof(*ts_st->adts)); + if (!ts_st->adts) +- return AVERROR(ENOMEM); ++ goto fail; + if (ff_adts_decode_extradata(s, ts_st->adts, st->codec->extradata, + st->codec->extradata_size) < 0) +- return -1; ++ goto fail; + } + } + +@@ -509,7 +579,10 @@ + service->pcr_pid = ts_st->pid; + } + +- ts->mux_rate = s->mux_rate ? s->mux_rate : 1; ++#if FF_API_MUXRATE ++ if (s->mux_rate) ++ ts->mux_rate = s->mux_rate; ++#endif + + if (ts->mux_rate > 1) { + service->pcr_packet_period = (ts->mux_rate * PCR_RETRANS_TIME) / +@@ -554,17 +627,31 @@ + service->pcr_packet_period, + ts->sdt_packet_period, ts->pat_packet_period); + +- put_flush_packet(s->pb); ++ if (ts->m2ts_mode == -1) { ++ if (av_match_ext(s->filename, "m2ts")) { ++ ts->m2ts_mode = 1; ++ } else { ++ ts->m2ts_mode = 0; ++ } ++ } ++ ++ avio_flush(s->pb); + + return 0; + + fail: + av_free(pids); + for(i = 0;i < s->nb_streams; i++) { ++ MpegTSWriteStream *ts_st; + st = s->streams[i]; +- av_free(st->priv_data); ++ ts_st = st->priv_data; ++ if (ts_st) { ++ av_freep(&ts_st->payload); ++ av_freep(&ts_st->adts); ++ } ++ av_freep(&st->priv_data); + } +- return -1; ++ return AVERROR(EINVAL); + } + + /* send SDT, PAT and PMT tables regulary */ +@@ -586,13 +673,7 @@ + } + } + +-static int64_t get_pcr(const MpegTSWrite *ts, ByteIOContext *pb) +-{ +- return av_rescale(url_ftell(pb) + 11, 8 * PCR_TIME_BASE, ts->mux_rate) + +- ts->first_pcr; +-} +- +-static uint8_t* write_pcr_bits(uint8_t *buf, int64_t pcr) ++static int write_pcr_bits(uint8_t *buf, int64_t pcr) + { + int64_t pcr_low = pcr % 300, pcr_high = pcr / 300; + +@@ -603,7 +684,7 @@ + *buf++ = pcr_high << 7 | pcr_low >> 8 | 0x7e; + *buf++ = pcr_low; + +- return buf; ++ return 6; + } + + /* Write a single null transport stream packet */ +@@ -618,7 +699,8 @@ + *q++ = 0xff; + *q++ = 0x10; + memset(q, 0x0FF, TS_PACKET_SIZE - (q - buf)); +- put_buffer(s->pb, buf, TS_PACKET_SIZE); ++ mpegts_prefix_m2ts_header(s); ++ avio_write(s->pb, buf, TS_PACKET_SIZE); + } + + /* Write a single transport stream packet with a PCR and no payload */ +@@ -639,11 +721,12 @@ + *q++ = 0x10; /* Adaptation flags: PCR present */ + + /* PCR coded into 6 bytes */ +- q = write_pcr_bits(q, get_pcr(ts, s->pb)); ++ q += write_pcr_bits(q, get_pcr(ts, s->pb)); + + /* stuffing bytes */ + memset(q, 0xFF, TS_PACKET_SIZE - (q - buf)); +- put_buffer(s->pb, buf, TS_PACKET_SIZE); ++ mpegts_prefix_m2ts_header(s); ++ avio_write(s->pb, buf, TS_PACKET_SIZE); + } + + static void write_pts(uint8_t *q, int fourbits, int64_t pts) +@@ -660,6 +743,39 @@ + *q++ = val; + } + ++/* Set an adaptation field flag in an MPEG-TS packet*/ ++static void set_af_flag(uint8_t *pkt, int flag) ++{ ++ // expect at least one flag to set ++ assert(flag); ++ ++ if ((pkt[3] & 0x20) == 0) { ++ // no AF yet, set adaptation field flag ++ pkt[3] |= 0x20; ++ // 1 byte length, no flags ++ pkt[4] = 1; ++ pkt[5] = 0; ++ } ++ pkt[5] |= flag; ++} ++ ++/* Extend the adaptation field by size bytes */ ++static void extend_af(uint8_t *pkt, int size) ++{ ++ // expect already existing adaptation field ++ assert(pkt[3] & 0x20); ++ pkt[4] += size; ++} ++ ++/* Get a pointer to MPEG-TS payload (right after TS packet header) */ ++static uint8_t *get_ts_payload_start(uint8_t *pkt) ++{ ++ if (pkt[3] & 0x20) ++ return pkt + 5 + pkt[4]; ++ else ++ return pkt + 4; ++} ++ + /* Add a pes header to the front of payload, and segment into an integer number of + * ts packets. The final ts packet is padded using an over-sized adaptation header + * to exactly fill the last ts packet. +@@ -667,7 +783,7 @@ + */ + static void mpegts_write_pes(AVFormatContext *s, AVStream *st, + const uint8_t *payload, int payload_size, +- int64_t pts, int64_t dts) ++ int64_t pts, int64_t dts, int key) + { + MpegTSWriteStream *ts_st = st->priv_data; + MpegTSWrite *ts = s->priv_data; +@@ -712,8 +828,17 @@ + *q++ = val; + *q++ = ts_st->pid; + ts_st->cc = (ts_st->cc + 1) & 0xf; +- *q++ = 0x10 | ts_st->cc | (write_pcr ? 0x20 : 0); ++ *q++ = 0x10 | ts_st->cc; // payload indicator + CC ++ if (key && is_start && pts != AV_NOPTS_VALUE) { ++ // set Random Access for key frames ++ if (ts_st->pid == ts_st->service->pcr_pid) ++ write_pcr = 1; ++ set_af_flag(buf, 0x40); ++ q = get_ts_payload_start(buf); ++ } + if (write_pcr) { ++ set_af_flag(buf, 0x10); ++ q = get_ts_payload_start(buf); + // add 11, pcr references the last byte of program clock reference base + if (ts->mux_rate > 1) + pcr = get_pcr(ts, s->pb); +@@ -721,9 +846,8 @@ + pcr = (dts - delay)*300; + if (dts != AV_NOPTS_VALUE && dts < pcr / 300) + av_log(s, AV_LOG_WARNING, "dts < pcr, TS is invalid\n"); +- *q++ = 7; /* AFC length */ +- *q++ = 0x10; /* flags: PCR present */ +- q = write_pcr_bits(q, pcr); ++ extend_af(buf, write_pcr_bits(q, pcr)); ++ q = get_ts_payload_start(buf); + } + if (is_start) { + int pes_extension = 0; +@@ -739,7 +863,8 @@ + *q++ = 0xe0; + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + (st->codec->codec_id == CODEC_ID_MP2 || +- st->codec->codec_id == CODEC_ID_MP3)) { ++ st->codec->codec_id == CODEC_ID_MP3 || ++ st->codec->codec_id == CODEC_ID_AAC)) { + *q++ = 0xc0; + } else { + *q++ = 0xbd; +@@ -837,9 +962,10 @@ + memcpy(buf + TS_PACKET_SIZE - len, payload, len); + payload += len; + payload_size -= len; +- put_buffer(s->pb, buf, TS_PACKET_SIZE); ++ mpegts_prefix_m2ts_header(s); ++ avio_write(s->pb, buf, TS_PACKET_SIZE); + } +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + } + + static int mpegts_write_packet(AVFormatContext *s, AVPacket *pkt) +@@ -848,6 +974,7 @@ + int size = pkt->size; + uint8_t *buf= pkt->data; + uint8_t *data= NULL; ++ MpegTSWrite *ts = s->priv_data; + MpegTSWriteStream *ts_st = st->priv_data; + const uint64_t delay = av_rescale(s->max_delay, 90000, AV_TIME_BASE)*2; + int64_t dts = AV_NOPTS_VALUE, pts = AV_NOPTS_VALUE; +@@ -859,7 +986,7 @@ + + if (ts_st->first_pts_check && pts == AV_NOPTS_VALUE) { + av_log(s, AV_LOG_ERROR, "first pts value must set\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + ts_st->first_pts_check = 0; + +@@ -868,13 +995,13 @@ + uint32_t state = -1; + + if (pkt->size < 5 || AV_RB32(pkt->data) != 0x0000001) { +- av_log(s, AV_LOG_ERROR, "h264 bitstream malformated, " +- "no startcode found, use -vbsf h264_mp4toannexb\n"); +- return -1; ++ av_log(s, AV_LOG_ERROR, "H.264 bitstream malformed, " ++ "no startcode found, use the h264_mp4toannexb bitstream filter\n"); ++ return AVERROR_INVALIDDATA; + } + + do { +- p = ff_find_start_code(p, buf_end, &state); ++ p = avpriv_mpv_find_start_code(p, buf_end, &state); + //av_log(s, AV_LOG_INFO, "nal %d\n", state & 0x1f); + } while (p < buf_end && (state & 0x1f) != 9 && + (state & 0x1f) != 5 && (state & 0x1f) != 1); +@@ -882,7 +1009,7 @@ + if ((state & 0x1f) != 9) { // AUD NAL + data = av_malloc(pkt->size+6); + if (!data) +- return -1; ++ return AVERROR(ENOMEM); + memcpy(data+6, pkt->data, pkt->size); + AV_WB32(data, 0x00000001); + data[4] = 0x09; +@@ -892,22 +1019,27 @@ + } + } else if (st->codec->codec_id == CODEC_ID_AAC) { + if (pkt->size < 2) +- return -1; ++ return AVERROR_INVALIDDATA; + if ((AV_RB16(pkt->data) & 0xfff0) != 0xfff0) { + ADTSContext *adts = ts_st->adts; +- int new_size; ++ int new_size, err; + if (!adts) { +- av_log(s, AV_LOG_ERROR, "aac bitstream not in adts format " ++ av_log(s, AV_LOG_ERROR, "AAC bitstream not in ADTS format " + "and extradata missing\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + new_size = ADTS_HEADER_SIZE+adts->pce_size+pkt->size; + if ((unsigned)new_size >= INT_MAX) +- return -1; ++ return AVERROR_INVALIDDATA; + data = av_malloc(new_size); + if (!data) + return AVERROR(ENOMEM); +- ff_adts_write_frame_header(adts, data, pkt->size, adts->pce_size); ++ err = ff_adts_write_frame_header(adts, data, pkt->size, ++ adts->pce_size); ++ if (err < 0) { ++ av_free(data); ++ return err; ++ } + if (adts->pce_size) { + memcpy(data+ADTS_HEADER_SIZE, adts->pce_data, adts->pce_size); + adts->pce_size = 0; +@@ -918,26 +1050,29 @@ + } + } + +- if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO) { ++ if (ts_st->payload_size && ts_st->payload_size + size > ts->pes_payload_size) { ++ mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size, ++ ts_st->payload_pts, ts_st->payload_dts, ++ ts_st->payload_flags & AV_PKT_FLAG_KEY); ++ ts_st->payload_size = 0; ++ } ++ ++ if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO || size > ts->pes_payload_size) { ++ av_assert0(!ts_st->payload_size); + // for video and subtitle, write a single pes packet +- mpegts_write_pes(s, st, buf, size, pts, dts); ++ mpegts_write_pes(s, st, buf, size, pts, dts, pkt->flags & AV_PKT_FLAG_KEY); + av_free(data); + return 0; + } + +- if (ts_st->payload_index + size > DEFAULT_PES_PAYLOAD_SIZE) { +- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, +- ts_st->payload_pts, ts_st->payload_dts); +- ts_st->payload_index = 0; +- } +- +- if (!ts_st->payload_index) { ++ if (!ts_st->payload_size) { + ts_st->payload_pts = pts; + ts_st->payload_dts = dts; ++ ts_st->payload_flags = pkt->flags; + } + +- memcpy(ts_st->payload + ts_st->payload_index, buf, size); +- ts_st->payload_index += size; ++ memcpy(ts_st->payload + ts_st->payload_size, buf, size); ++ ts_st->payload_size += size; + + av_free(data); + +@@ -956,13 +1091,15 @@ + for(i = 0; i < s->nb_streams; i++) { + st = s->streams[i]; + ts_st = st->priv_data; +- if (ts_st->payload_index > 0) { +- mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_index, +- ts_st->payload_pts, ts_st->payload_dts); ++ if (ts_st->payload_size > 0) { ++ mpegts_write_pes(s, st, ts_st->payload, ts_st->payload_size, ++ ts_st->payload_pts, ts_st->payload_dts, ++ ts_st->payload_flags & AV_PKT_FLAG_KEY); + } ++ av_freep(&ts_st->payload); + av_freep(&ts_st->adts); + } +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + for(i = 0; i < ts->nb_services; i++) { + service = ts->services[i]; +@@ -976,15 +1113,15 @@ + } + + AVOutputFormat ff_mpegts_muxer = { +- "mpegts", +- NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), +- "video/x-mpegts", +- "ts,m2t", +- sizeof(MpegTSWrite), +- CODEC_ID_MP2, +- CODEC_ID_MPEG2VIDEO, +- mpegts_write_header, +- mpegts_write_packet, +- mpegts_write_end, ++ .name = "mpegts", ++ .long_name = NULL_IF_CONFIG_SMALL("MPEG-2 transport stream format"), ++ .mime_type = "video/x-mpegts", ++ .extensions = "ts,m2t,m2ts,mts", ++ .priv_data_size = sizeof(MpegTSWrite), ++ .audio_codec = CODEC_ID_MP2, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mpegts_write_header, ++ .write_packet = mpegts_write_packet, ++ .write_trailer = mpegts_write_end, + .priv_class = &mpegts_muxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegts.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegts.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegts.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegts.h 2012-05-14 14:08:55.066354715 +0200 +@@ -39,6 +39,7 @@ + /* table ids */ + #define PAT_TID 0x00 + #define PMT_TID 0x02 ++#define M4OD_TID 0x05 + #define SDT_TID 0x42 + + #define STREAM_TYPE_VIDEO_MPEG1 0x01 +@@ -64,6 +65,30 @@ + const uint8_t *buf, int len); + void ff_mpegts_parse_close(MpegTSContext *ts); + ++typedef struct { ++ int use_au_start; ++ int use_au_end; ++ int use_rand_acc_pt; ++ int use_padding; ++ int use_timestamps; ++ int use_idle; ++ int timestamp_res; ++ int timestamp_len; ++ int ocr_len; ++ int au_len; ++ int inst_bitrate_len; ++ int degr_prior_len; ++ int au_seq_num_len; ++ int packet_seq_num_len; ++} SLConfigDescr; ++ ++typedef struct { ++ int es_id; ++ int dec_config_descr_len; ++ uint8_t *dec_config_descr; ++ SLConfigDescr sl; ++} Mp4Descr; ++ + /** + * Parse an MPEG-2 descriptor + * @param[in] fc Format context (used for logging only) +@@ -79,7 +104,7 @@ + */ + int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type, + const uint8_t **pp, const uint8_t *desc_list_end, +- int mp4_dec_config_descr_len, int mp4_es_id, int pid, +- uint8_t *mp4_dec_config_descr); ++ Mp4Descr *mp4_descr, int mp4_descr_count, int pid, ++ MpegTSContext *ts); + + #endif /* AVFORMAT_MPEGTS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegvideodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegvideodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpegvideodec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpegvideodec.c 2012-05-14 14:08:55.070354795 +0200 +@@ -34,7 +34,7 @@ + static int mpegvideo_probe(AVProbeData *p) + { + uint32_t code= -1; +- int pic=0, seq=0, slice=0, pspack=0, pes=0; ++ int pic=0, seq=0, slice=0, pspack=0, vpes=0, apes=0; + int i; + + for(i=0; ibuf_size; i++){ +@@ -43,25 +43,17 @@ + switch(code){ + case SEQ_START_CODE: seq++; break; + case PICTURE_START_CODE: pic++; break; +- case SLICE_START_CODE: slice++; break; + case PACK_START_CODE: pspack++; break; + } +- if ((code & 0x1f0) == VIDEO_ID) pes++; +- else if((code & 0x1e0) == AUDIO_ID) pes++; ++ if (code >= SLICE_START_CODE && code <= 0x1af) slice++; ++ if ((code & 0x1f0) == VIDEO_ID) vpes++; ++ else if((code & 0x1e0) == AUDIO_ID) apes++; + } + } +- if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !pes) +- return pic>1 ? AVPROBE_SCORE_MAX/2+1 : AVPROBE_SCORE_MAX/4; // +1 for .mpg ++ if(seq && seq*9<=pic*10 && pic*9<=slice*10 && !pspack && !apes) ++ if(vpes) return AVPROBE_SCORE_MAX/8; ++ else return pic>1 ? AVPROBE_SCORE_MAX/2+1 : AVPROBE_SCORE_MAX/4; // +1 for .mpg + return 0; + } + +-AVInputFormat ff_mpegvideo_demuxer = { +- "mpegvideo", +- NULL_IF_CONFIG_SMALL("raw MPEG video"), +- 0, +- mpegvideo_probe, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .value = CODEC_ID_MPEG1VIDEO, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(mpegvideo, "raw MPEG video", mpegvideo_probe, NULL, CODEC_ID_MPEG1VIDEO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpjpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpjpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mpjpeg.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mpjpeg.c 2012-05-14 14:08:55.070354795 +0200 +@@ -29,8 +29,8 @@ + uint8_t buf1[256]; + + snprintf(buf1, sizeof(buf1), "--%s\n", BOUNDARY_TAG); +- put_buffer(s->pb, buf1, strlen(buf1)); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf1, strlen(buf1)); ++ avio_flush(s->pb); + return 0; + } + +@@ -39,12 +39,12 @@ + uint8_t buf1[256]; + + snprintf(buf1, sizeof(buf1), "Content-type: image/jpeg\n\n"); +- put_buffer(s->pb, buf1, strlen(buf1)); +- put_buffer(s->pb, pkt->data, pkt->size); ++ avio_write(s->pb, buf1, strlen(buf1)); ++ avio_write(s->pb, pkt->data, pkt->size); + + snprintf(buf1, sizeof(buf1), "\n--%s\n", BOUNDARY_TAG); +- put_buffer(s->pb, buf1, strlen(buf1)); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf1, strlen(buf1)); ++ avio_flush(s->pb); + return 0; + } + +@@ -54,14 +54,13 @@ + } + + AVOutputFormat ff_mpjpeg_muxer = { +- "mpjpeg", +- NULL_IF_CONFIG_SMALL("MIME multipart JPEG format"), +- "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG, +- "mjpg", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_MJPEG, +- mpjpeg_write_header, +- mpjpeg_write_packet, +- mpjpeg_write_trailer, ++ .name = "mpjpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("MIME multipart JPEG format"), ++ .mime_type = "multipart/x-mixed-replace;boundary=" BOUNDARY_TAG, ++ .extensions = "mjpg", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_MJPEG, ++ .write_header = mpjpeg_write_header, ++ .write_packet = mpjpeg_write_packet, ++ .write_trailer = mpjpeg_write_trailer, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/msnwc_tcp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/msnwc_tcp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/msnwc_tcp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/msnwc_tcp.c 2012-05-14 14:08:55.071354815 +0200 +@@ -1,5 +1,5 @@ + /* +- * Copyright (C) 2008 Ramiro Polla ++ * Copyright (C) 2008 Ramiro Polla + * + * This file is part of FFmpeg. + * +@@ -20,6 +20,7 @@ + + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + + #define HEADER_SIZE 24 + +@@ -71,11 +72,11 @@ + + static int msnwc_tcp_read_header(AVFormatContext *ctx, AVFormatParameters *ap) + { +- ByteIOContext *pb = ctx->pb; ++ AVIOContext *pb = ctx->pb; + AVCodecContext *codec; + AVStream *st; + +- st = av_new_stream(ctx, 0); ++ st = avformat_new_stream(ctx, NULL); + if(!st) + return AVERROR(ENOMEM); + +@@ -84,11 +85,11 @@ + codec->codec_id = CODEC_ID_MIMIC; + codec->codec_tag = MKTAG('M', 'L', '2', '0'); + +- av_set_pts_info(st, 32, 1, 1000); ++ avpriv_set_pts_info(st, 32, 1, 1000); + + /* Some files start with "connected\r\n\r\n". + * So skip until we find the first byte of struct size */ +- while(get_byte(pb) != HEADER_SIZE && !url_feof(pb)); ++ while(avio_r8(pb) != HEADER_SIZE && !url_feof(pb)); + + if(url_feof(pb)) { + av_log(ctx, AV_LOG_ERROR, "Could not find valid start."); +@@ -100,23 +101,23 @@ + + static int msnwc_tcp_read_packet(AVFormatContext *ctx, AVPacket *pkt) + { +- ByteIOContext *pb = ctx->pb; ++ AVIOContext *pb = ctx->pb; + uint16_t keyframe; + uint32_t size, timestamp; + +- url_fskip(pb, 1); /* one byte has been read ahead */ +- url_fskip(pb, 2); +- url_fskip(pb, 2); +- keyframe = get_le16(pb); +- size = get_le32(pb); +- url_fskip(pb, 4); +- url_fskip(pb, 4); +- timestamp = get_le32(pb); ++ avio_skip(pb, 1); /* one byte has been read ahead */ ++ avio_skip(pb, 2); ++ avio_skip(pb, 2); ++ keyframe = avio_rl16(pb); ++ size = avio_rl32(pb); ++ avio_skip(pb, 4); ++ avio_skip(pb, 4); ++ timestamp = avio_rl32(pb); + + if(!size || av_get_packet(pb, pkt, size) != size) + return -1; + +- url_fskip(pb, 1); /* Read ahead one byte of struct size like read_header */ ++ avio_skip(pb, 1); /* Read ahead one byte of struct size like read_header */ + + pkt->pts = timestamp; + pkt->dts = timestamp; +@@ -131,10 +132,9 @@ + } + + AVInputFormat ff_msnwc_tcp_demuxer = { +- "msnwctcp", +- NULL_IF_CONFIG_SMALL("MSN TCP Webcam stream"), +- 0, +- msnwc_tcp_probe, +- msnwc_tcp_read_header, +- msnwc_tcp_read_packet, ++ .name = "msnwctcp", ++ .long_name = NULL_IF_CONFIG_SMALL("MSN TCP Webcam stream"), ++ .read_probe = msnwc_tcp_probe, ++ .read_header = msnwc_tcp_read_header, ++ .read_packet = msnwc_tcp_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mtv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mtv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mtv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mtv.c 2012-05-14 14:08:55.072354835 +0200 +@@ -27,13 +27,12 @@ + #include "libavutil/bswap.h" + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define MTV_ASUBCHUNK_DATA_SIZE 500 + #define MTV_HEADER_SIZE 512 + #define MTV_AUDIO_PADDING_SIZE 12 + #define AUDIO_SAMPLING_RATE 44100 +-#define VIDEO_SID 0 +-#define AUDIO_SID 1 + + typedef struct MTVDemuxContext { + +@@ -54,7 +53,7 @@ + static int mtv_probe(AVProbeData *p) + { + /* Magic is 'AMV' */ +- if(*(p->buf) != 'A' || *(p->buf+1) != 'M' || *(p->buf+2) != 'V') ++ if (*p->buf != 'A' || *(p->buf + 1) != 'M' || *(p->buf + 2) != 'V') + return 0; + + /* Check for nonzero in bpp and (width|height) header fields */ +@@ -79,34 +78,46 @@ + static int mtv_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + MTVDemuxContext *mtv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + unsigned int audio_subsegments; + +- url_fskip(pb, 3); +- mtv->file_size = get_le32(pb); +- mtv->segments = get_le32(pb); +- url_fskip(pb, 32); +- mtv->audio_identifier = get_le24(pb); +- mtv->audio_br = get_le16(pb); +- mtv->img_colorfmt = get_le24(pb); +- mtv->img_bpp = get_byte(pb); +- mtv->img_width = get_le16(pb); +- mtv->img_height = get_le16(pb); +- mtv->img_segment_size = get_le16(pb); ++ avio_skip(pb, 3); ++ mtv->file_size = avio_rl32(pb); ++ mtv->segments = avio_rl32(pb); ++ avio_skip(pb, 32); ++ mtv->audio_identifier = avio_rl24(pb); ++ mtv->audio_br = avio_rl16(pb); ++ mtv->img_colorfmt = avio_rl24(pb); ++ mtv->img_bpp = avio_r8(pb); ++ mtv->img_width = avio_rl16(pb); ++ mtv->img_height = avio_rl16(pb); ++ mtv->img_segment_size = avio_rl16(pb); + + /* Calculate width and height if missing from header */ + +- if(!mtv->img_width) ++ if(mtv->img_bpp>>3){ ++ if(!mtv->img_width && mtv->img_height) + mtv->img_width=mtv->img_segment_size / (mtv->img_bpp>>3) + / mtv->img_height; + +- if(!mtv->img_height) ++ if(!mtv->img_height && mtv->img_width) + mtv->img_height=mtv->img_segment_size / (mtv->img_bpp>>3) + / mtv->img_width; ++ } ++ if(!mtv->img_height || !mtv->img_width){ ++ av_log(s, AV_LOG_ERROR, "width or height is invalid and I cannot calculate them from other information\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ avio_skip(pb, 4); ++ audio_subsegments = avio_rl16(pb); ++ ++ if (audio_subsegments == 0) { ++ av_log_ask_for_sample(s, "MTV files without audio are not supported\n"); ++ return AVERROR_INVALIDDATA; ++ } + +- url_fskip(pb, 4); +- audio_subsegments = get_le16(pb); + mtv->full_segment_size = + audio_subsegments * (MTV_AUDIO_PADDING_SIZE + MTV_ASUBCHUNK_DATA_SIZE) + + mtv->img_segment_size; +@@ -118,11 +129,11 @@ + + // video - raw rgb565 + +- st = av_new_stream(s, VIDEO_SID); ++ st = avformat_new_stream(s, NULL); + if(!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 64, 1, mtv->video_fps); ++ avpriv_set_pts_info(st, 64, 1, mtv->video_fps); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_RAWVIDEO; + st->codec->pix_fmt = PIX_FMT_RGB565; +@@ -134,11 +145,11 @@ + + // audio - mp3 + +- st = av_new_stream(s, AUDIO_SID); ++ st = avformat_new_stream(s, NULL); + if(!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); ++ avpriv_set_pts_info(st, 64, 1, AUDIO_SAMPLING_RATE); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MP3; + st->codec->bit_rate = mtv->audio_br; +@@ -146,7 +157,7 @@ + + // Jump over header + +- if(url_fseek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) ++ if(avio_seek(pb, MTV_HEADER_SIZE, SEEK_SET) != MTV_HEADER_SIZE) + return AVERROR(EIO); + + return 0; +@@ -156,22 +167,22 @@ + static int mtv_read_packet(AVFormatContext *s, AVPacket *pkt) + { + MTVDemuxContext *mtv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret; + #if !HAVE_BIGENDIAN + int i; + #endif + +- if((url_ftell(pb) - s->data_offset + mtv->img_segment_size) % mtv->full_segment_size) ++ if((avio_tell(pb) - s->data_offset + mtv->img_segment_size) % mtv->full_segment_size) + { +- url_fskip(pb, MTV_AUDIO_PADDING_SIZE); ++ avio_skip(pb, MTV_AUDIO_PADDING_SIZE); + + ret = av_get_packet(pb, pkt, MTV_ASUBCHUNK_DATA_SIZE); + if(ret < 0) + return ret; + + pkt->pos -= MTV_AUDIO_PADDING_SIZE; +- pkt->stream_index = AUDIO_SID; ++ pkt->stream_index = 1; + + }else + { +@@ -187,20 +198,20 @@ + * just swap bytes as they come + */ + +- for(i=0;iimg_segment_size/2;i++) ++ for(i=0;idata+i) = av_bswap16(*((uint16_t *)pkt->data+i)); + #endif +- pkt->stream_index = VIDEO_SID; ++ pkt->stream_index = 0; + } + + return ret; + } + + AVInputFormat ff_mtv_demuxer = { +- "MTV", +- NULL_IF_CONFIG_SMALL("MTV format"), +- sizeof(MTVDemuxContext), +- mtv_probe, +- mtv_read_header, +- mtv_read_packet, ++ .name = "MTV", ++ .long_name = NULL_IF_CONFIG_SMALL("MTV format"), ++ .priv_data_size = sizeof(MTVDemuxContext), ++ .read_probe = mtv_probe, ++ .read_header = mtv_read_header, ++ .read_packet = mtv_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mvi.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mvi.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mvi.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mvi.c 2012-05-14 14:08:55.073354855 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + + #define MVI_FRAC_BITS 10 + +@@ -27,7 +28,7 @@ + #define MVI_VIDEO_STREAM_INDEX 1 + + typedef struct MviDemuxContext { +- unsigned int (*get_int)(ByteIOContext *); ++ unsigned int (*get_int)(AVIOContext *); + uint32_t audio_data_size; + uint64_t audio_size_counter; + uint64_t audio_frame_size; +@@ -38,35 +39,35 @@ + static int read_header(AVFormatContext *s, AVFormatParameters *ap) + { + MviDemuxContext *mvi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *ast, *vst; + unsigned int version, frames_count, msecs_per_frame, player_version; + +- ast = av_new_stream(s, 0); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + +- vst = av_new_stream(s, 0); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + + vst->codec->extradata_size = 2; + vst->codec->extradata = av_mallocz(2 + FF_INPUT_BUFFER_PADDING_SIZE); + +- version = get_byte(pb); +- vst->codec->extradata[0] = get_byte(pb); +- vst->codec->extradata[1] = get_byte(pb); +- frames_count = get_le32(pb); +- msecs_per_frame = get_le32(pb); +- vst->codec->width = get_le16(pb); +- vst->codec->height = get_le16(pb); +- get_byte(pb); +- ast->codec->sample_rate = get_le16(pb); +- mvi->audio_data_size = get_le32(pb); +- get_byte(pb); +- player_version = get_le32(pb); +- get_le16(pb); +- get_byte(pb); ++ version = avio_r8(pb); ++ vst->codec->extradata[0] = avio_r8(pb); ++ vst->codec->extradata[1] = avio_r8(pb); ++ frames_count = avio_rl32(pb); ++ msecs_per_frame = avio_rl32(pb); ++ vst->codec->width = avio_rl16(pb); ++ vst->codec->height = avio_rl16(pb); ++ avio_r8(pb); ++ ast->codec->sample_rate = avio_rl16(pb); ++ mvi->audio_data_size = avio_rl32(pb); ++ avio_r8(pb); ++ player_version = avio_rl32(pb); ++ avio_rl16(pb); ++ avio_r8(pb); + + if (frames_count == 0 || mvi->audio_data_size == 0) + return AVERROR_INVALIDDATA; +@@ -76,18 +77,18 @@ + return AVERROR_INVALIDDATA; + } + +- av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); ++ avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codec->codec_id = CODEC_ID_PCM_U8; + ast->codec->channels = 1; + ast->codec->bits_per_coded_sample = 8; + ast->codec->bit_rate = ast->codec->sample_rate * 8; + +- av_set_pts_info(vst, 64, msecs_per_frame, 1000000); ++ avpriv_set_pts_info(vst, 64, msecs_per_frame, 1000000); + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_MOTIONPIXELS; + +- mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? get_le16 : get_le24; ++ mvi->get_int = (vst->codec->width * vst->codec->height < (1 << 16)) ? avio_rl16 : avio_rl24; + + mvi->audio_frame_size = ((uint64_t)mvi->audio_data_size << MVI_FRAC_BITS) / frames_count; + mvi->audio_size_counter = (ast->codec->sample_rate * 830 / mvi->audio_frame_size - 1) * mvi->audio_frame_size; +@@ -100,7 +101,7 @@ + { + int ret, count; + MviDemuxContext *mvi = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (mvi->video_frame_size == 0) { + mvi->video_frame_size = (mvi->get_int)(pb); +@@ -124,11 +125,10 @@ + } + + AVInputFormat ff_mvi_demuxer = { +- "mvi", +- NULL_IF_CONFIG_SMALL("Motion Pixels MVI format"), +- sizeof(MviDemuxContext), +- NULL, +- read_header, +- read_packet, ++ .name = "mvi", ++ .long_name = NULL_IF_CONFIG_SMALL("Motion Pixels MVI format"), ++ .priv_data_size = sizeof(MviDemuxContext), ++ .read_header = read_header, ++ .read_packet = read_packet, + .extensions = "mvi" + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxf.c 2012-05-14 14:08:55.074354875 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/common.h" + #include "mxf.h" + + /** +@@ -41,6 +42,8 @@ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x07,0x04,0x01,0x02,0x02,0x03,0x01,0x01,0x00 }, 14, CODEC_ID_JPEG2000 }, /* JPEG2000 Codestream */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_RAWVIDEO }, /* Uncompressed */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x01,0x02,0x02,0x03,0x02,0x00,0x00 }, 14, CODEC_ID_DNXHD }, /* SMPTE VC-3/DNxHD */ ++ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x02,0x01,0x32,0x00,0x00 }, 14, CODEC_ID_H264 }, /* H.264/MPEG-4 AVC Intra */ ++ { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x0A,0x04,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, 15, CODEC_ID_V210 }, /* V210 */ + /* SoundEssenceCompression */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x00,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, /* Uncompressed */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x04,0x02,0x02,0x01,0x7F,0x00,0x00,0x00 }, 13, CODEC_ID_PCM_S16LE }, +@@ -80,7 +83,7 @@ + {PIX_FMT_PAL8, {'P', 8 }}, + }; + +-static const int num_pixel_layouts = sizeof(ff_mxf_pixel_layouts) / sizeof(*ff_mxf_pixel_layouts); ++static const int num_pixel_layouts = FF_ARRAY_ELEMS(ff_mxf_pixel_layouts); + + int ff_mxf_decode_pixel_layout(const char pixel_layout[16], enum PixelFormat *pix_fmt) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxfdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxfdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxfdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxfdec.c 2012-05-14 14:08:55.080354995 +0200 +@@ -46,10 +46,48 @@ + //#define DEBUG + + #include "libavutil/aes.h" ++#include "libavutil/mathematics.h" + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + #include "mxf.h" + ++typedef enum { ++ Header, ++ BodyPartition, ++ Footer ++} MXFPartitionType; ++ ++typedef enum { ++ OP1a = 1, ++ OP1b, ++ OP1c, ++ OP2a, ++ OP2b, ++ OP2c, ++ OP3a, ++ OP3b, ++ OP3c, ++ OPAtom, ++ OPSONYOpt, /* FATE sample, violates the spec in places */ ++} MXFOP; ++ ++typedef struct { ++ int closed; ++ int complete; ++ MXFPartitionType type; ++ uint64_t previous_partition; ++ int index_sid; ++ int body_sid; ++ int64_t this_partition; ++ int64_t essence_offset; ///< absolute offset of essence ++ int64_t essence_length; ++ int32_t kag_size; ++ int64_t header_byte_count; ++ int64_t index_byte_count; ++ int pack_length; ++} MXFPartition; ++ + typedef struct { + UID uid; + enum MXFMetadataSetType type; +@@ -107,6 +145,16 @@ + typedef struct { + UID uid; + enum MXFMetadataSetType type; ++ int edit_unit_byte_count; ++ int index_sid; ++ int body_sid; ++ AVRational index_edit_rate; ++ uint64_t index_start_position; ++ uint64_t index_duration; ++ int8_t *temporal_offset_entries; ++ int *flag_entries; ++ uint64_t *stream_offset_entries; ++ int nb_index_entries; + } MXFIndexTableSegment; + + typedef struct { +@@ -124,7 +172,22 @@ + enum MXFMetadataSetType type; + } MXFMetadataSet; + ++/* decoded index table */ + typedef struct { ++ int index_sid; ++ int body_sid; ++ int nb_ptses; /* number of PTSes or total duration of index */ ++ int64_t first_dts; /* DTS = EditUnit + first_dts */ ++ int64_t *ptses; /* maps EditUnit -> PTS */ ++ int nb_segments; ++ MXFIndexTableSegment **segments; /* sorted by IndexStartPosition */ ++ AVIndexEntry *fake_index; /* used for calling ff_index_search_timestamp() */ ++} MXFIndexTable; ++ ++typedef struct { ++ MXFPartition *partitions; ++ unsigned partitions_count; ++ MXFOP op; + UID *packages_refs; + int packages_count; + MXFMetadataSet **metadata_sets; +@@ -133,6 +196,18 @@ + struct AVAES *aesc; + uint8_t *local_tags; + int local_tags_count; ++ uint64_t footer_partition; ++ KLVPacket current_klv_data; ++ int current_klv_index; ++ int run_in; ++ MXFPartition *current_partition; ++ int parsing_backward; ++ int64_t last_forward_tell; ++ int last_forward_partition; ++ int current_edit_unit; ++ int nb_index_tables; ++ MXFIndexTable *index_tables; ++ int edit_units_per_packet; ///< how many edit units to read at a time (PCM, OPAtom) + } MXFContext; + + enum MXFWrappingScheme { +@@ -140,7 +215,8 @@ + Clip, + }; + +-typedef int MXFMetadataReadFunc(void *arg, ByteIOContext *pb, int tag, int size, UID uid); ++/* NOTE: klv_offset is not set (-1) for local keys */ ++typedef int MXFMetadataReadFunc(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset); + + typedef struct { + const UID key; +@@ -152,6 +228,8 @@ + /* partial keys to match */ + static const uint8_t mxf_header_partition_pack_key[] = { 0x06,0x0e,0x2b,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02 }; + static const uint8_t mxf_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01 }; ++static const uint8_t mxf_avid_essence_element_key[] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0e,0x04,0x03,0x01 }; ++static const uint8_t mxf_system_item_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04 }; + static const uint8_t mxf_klv_key[] = { 0x06,0x0e,0x2b,0x34 }; + /* complete keys to match */ + static const uint8_t mxf_crypto_source_container_ul[] = { 0x06,0x0e,0x2b,0x34,0x01,0x01,0x01,0x09,0x06,0x01,0x01,0x02,0x02,0x00,0x00,0x00 }; +@@ -161,26 +239,26 @@ + + #define IS_KLV_KEY(x, y) (!memcmp(x, y, sizeof(y))) + +-static int64_t klv_decode_ber_length(ByteIOContext *pb) ++static int64_t klv_decode_ber_length(AVIOContext *pb) + { +- uint64_t size = get_byte(pb); ++ uint64_t size = avio_r8(pb); + if (size & 0x80) { /* long form */ + int bytes_num = size & 0x7f; + /* SMPTE 379M 5.3.4 guarantee that bytes_num must not exceed 8 bytes */ + if (bytes_num > 8) +- return -1; ++ return AVERROR_INVALIDDATA; + size = 0; + while (bytes_num--) +- size = size << 8 | get_byte(pb); ++ size = size << 8 | avio_r8(pb); + } + return size; + } + +-static int mxf_read_sync(ByteIOContext *pb, const uint8_t *key, unsigned size) ++static int mxf_read_sync(AVIOContext *pb, const uint8_t *key, unsigned size) + { + int i, b; + for (i = 0; i < size && !url_feof(pb); i++) { +- b = get_byte(pb); ++ b = avio_r8(pb); + if (b == key[0]) + i = 0; + else if (b != key[i]) +@@ -189,13 +267,13 @@ + return i == size; + } + +-static int klv_read_packet(KLVPacket *klv, ByteIOContext *pb) ++static int klv_read_packet(KLVPacket *klv, AVIOContext *pb) + { + if (!mxf_read_sync(pb, mxf_klv_key, 4)) +- return -1; +- klv->offset = url_ftell(pb) - 4; ++ return AVERROR_INVALIDDATA; ++ klv->offset = avio_tell(pb) - 4; + memcpy(klv->key, mxf_klv_key, 4); +- get_buffer(pb, klv->key + 4, 12); ++ avio_read(pb, klv->key + 4, 12); + klv->length = klv_decode_ber_length(pb); + return klv->length == -1 ? -1 : 0; + } +@@ -215,20 +293,21 @@ + } + + /* XXX: use AVBitStreamFilter */ +-static int mxf_get_d10_aes3_packet(ByteIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length) ++static int mxf_get_d10_aes3_packet(AVIOContext *pb, AVStream *st, AVPacket *pkt, int64_t length) + { + const uint8_t *buf_ptr, *end_ptr; + uint8_t *data_ptr; + int i; + + if (length > 61444) /* worst case PAL 1920 samples 8 channels */ +- return -1; +- av_new_packet(pkt, length); +- get_buffer(pb, pkt->data, length); ++ return AVERROR_INVALIDDATA; ++ length = av_get_packet(pb, pkt, length); ++ if (length < 0) ++ return length; + data_ptr = pkt->data; + end_ptr = pkt->data + length; + buf_ptr = pkt->data + 4; /* skip SMPTE 331M header */ +- for (; buf_ptr < end_ptr; ) { ++ for (; buf_ptr + st->codec->channels*4 < end_ptr; ) { + for (i = 0; i < st->codec->channels; i++) { + uint32_t sample = bytestream_get_le32(&buf_ptr); + if (st->codec->bits_per_coded_sample == 24) +@@ -238,7 +317,7 @@ + } + buf_ptr += 32 - st->codec->channels*4; // always 8 channels stored SMPTE 331M + } +- pkt->size = data_ptr - pkt->data; ++ av_shrink_packet(pkt, data_ptr - pkt->data); + return 0; + } + +@@ -246,9 +325,9 @@ + { + static const uint8_t checkv[16] = {0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b, 0x43, 0x48, 0x55, 0x4b}; + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; +- int64_t end = url_ftell(pb) + klv->length; +- uint64_t size; ++ AVIOContext *pb = s->pb; ++ int64_t end = avio_tell(pb) + klv->length; ++ int64_t size; + uint64_t orig_size; + uint64_t plaintext_size; + uint8_t ivec[16]; +@@ -258,284 +337,420 @@ + if (!mxf->aesc && s->key && s->keylen == 16) { + mxf->aesc = av_malloc(av_aes_size); + if (!mxf->aesc) +- return -1; ++ return AVERROR(ENOMEM); + av_aes_init(mxf->aesc, s->key, 128, 1); + } + // crypto context +- url_fskip(pb, klv_decode_ber_length(pb)); ++ avio_skip(pb, klv_decode_ber_length(pb)); + // plaintext offset + klv_decode_ber_length(pb); +- plaintext_size = get_be64(pb); ++ plaintext_size = avio_rb64(pb); + // source klv key + klv_decode_ber_length(pb); +- get_buffer(pb, klv->key, 16); ++ avio_read(pb, klv->key, 16); + if (!IS_KLV_KEY(klv, mxf_essence_element_key)) +- return -1; ++ return AVERROR_INVALIDDATA; + index = mxf_get_stream_index(s, klv); + if (index < 0) +- return -1; ++ return AVERROR_INVALIDDATA; + // source size + klv_decode_ber_length(pb); +- orig_size = get_be64(pb); ++ orig_size = avio_rb64(pb); + if (orig_size < plaintext_size) +- return -1; ++ return AVERROR_INVALIDDATA; + // enc. code + size = klv_decode_ber_length(pb); + if (size < 32 || size - 32 < orig_size) +- return -1; +- get_buffer(pb, ivec, 16); +- get_buffer(pb, tmpbuf, 16); ++ return AVERROR_INVALIDDATA; ++ avio_read(pb, ivec, 16); ++ avio_read(pb, tmpbuf, 16); + if (mxf->aesc) + av_aes_crypt(mxf->aesc, tmpbuf, tmpbuf, 1, ivec, 1); + if (memcmp(tmpbuf, checkv, 16)) + av_log(s, AV_LOG_ERROR, "probably incorrect decryption key\n"); + size -= 32; +- av_get_packet(pb, pkt, size); ++ size = av_get_packet(pb, pkt, size); ++ if (size < 0) ++ return size; ++ else if (size < plaintext_size) ++ return AVERROR_INVALIDDATA; + size -= plaintext_size; + if (mxf->aesc) + av_aes_crypt(mxf->aesc, &pkt->data[plaintext_size], + &pkt->data[plaintext_size], size >> 4, ivec, 1); +- pkt->size = orig_size; ++ av_shrink_packet(pkt, orig_size); + pkt->stream_index = index; +- url_fskip(pb, end - url_ftell(pb)); ++ avio_skip(pb, end - avio_tell(pb)); + return 0; + } + +-static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) +-{ +- KLVPacket klv; +- +- while (!url_feof(s->pb)) { +- if (klv_read_packet(&klv, s->pb) < 0) +- return -1; +- PRINT_KEY(s, "read packet", klv.key); +- av_dlog(s, "size %lld offset %#llx\n", klv.length, klv.offset); +- if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) { +- int res = mxf_decrypt_triplet(s, pkt, &klv); +- if (res < 0) { +- av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n"); +- return -1; +- } +- return 0; +- } +- if (IS_KLV_KEY(klv.key, mxf_essence_element_key)) { +- int index = mxf_get_stream_index(s, &klv); +- if (index < 0) { +- av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", AV_RB32(klv.key+12)); +- goto skip; +- } +- if (s->streams[index]->discard == AVDISCARD_ALL) +- goto skip; +- /* check for 8 channels AES3 element */ +- if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) { +- if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) { +- av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n"); +- return -1; +- } +- } else +- av_get_packet(s->pb, pkt, klv.length); +- pkt->stream_index = index; +- pkt->pos = klv.offset; +- return 0; +- } else +- skip: +- url_fskip(s->pb, klv.length); +- } +- return AVERROR_EOF; +-} +- +-static int mxf_read_primer_pack(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_primer_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFContext *mxf = arg; +- int item_num = get_be32(pb); +- int item_len = get_be32(pb); ++ int item_num = avio_rb32(pb); ++ int item_len = avio_rb32(pb); + + if (item_len != 18) { +- av_log(mxf->fc, AV_LOG_ERROR, "unsupported primer pack item length\n"); +- return -1; ++ av_log_ask_for_sample(pb, "unsupported primer pack item length %d\n", ++ item_len); ++ return AVERROR_PATCHWELCOME; + } + if (item_num > UINT_MAX / item_len) +- return -1; ++ return AVERROR_INVALIDDATA; + mxf->local_tags_count = item_num; + mxf->local_tags = av_malloc(item_num*item_len); + if (!mxf->local_tags) +- return -1; +- get_buffer(pb, mxf->local_tags, item_num*item_len); ++ return AVERROR(ENOMEM); ++ avio_read(pb, mxf->local_tags, item_num*item_len); ++ return 0; ++} ++ ++static int mxf_read_partition_pack(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) ++{ ++ MXFContext *mxf = arg; ++ MXFPartition *partition, *tmp_part; ++ UID op; ++ uint64_t footer_partition; ++ uint32_t nb_essence_containers; ++ ++ if (mxf->partitions_count+1 >= UINT_MAX / sizeof(*mxf->partitions)) ++ return AVERROR(ENOMEM); ++ ++ tmp_part = av_realloc(mxf->partitions, (mxf->partitions_count + 1) * sizeof(*mxf->partitions)); ++ if (!tmp_part) ++ return AVERROR(ENOMEM); ++ mxf->partitions = tmp_part; ++ ++ if (mxf->parsing_backward) { ++ /* insert the new partition pack in the middle ++ * this makes the entries in mxf->partitions sorted by offset */ ++ memmove(&mxf->partitions[mxf->last_forward_partition+1], ++ &mxf->partitions[mxf->last_forward_partition], ++ (mxf->partitions_count - mxf->last_forward_partition)*sizeof(*mxf->partitions)); ++ partition = mxf->current_partition = &mxf->partitions[mxf->last_forward_partition]; ++ } else { ++ mxf->last_forward_partition++; ++ partition = mxf->current_partition = &mxf->partitions[mxf->partitions_count]; ++ } ++ ++ memset(partition, 0, sizeof(*partition)); ++ mxf->partitions_count++; ++ partition->pack_length = avio_tell(pb) - klv_offset + size; ++ ++ switch(uid[13]) { ++ case 2: ++ partition->type = Header; ++ break; ++ case 3: ++ partition->type = BodyPartition; ++ break; ++ case 4: ++ partition->type = Footer; ++ break; ++ default: ++ av_log(mxf->fc, AV_LOG_ERROR, "unknown partition type %i\n", uid[13]); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ /* consider both footers to be closed (there is only Footer and CompleteFooter) */ ++ partition->closed = partition->type == Footer || !(uid[14] & 1); ++ partition->complete = uid[14] > 2; ++ avio_skip(pb, 4); ++ partition->kag_size = avio_rb32(pb); ++ partition->this_partition = avio_rb64(pb); ++ partition->previous_partition = avio_rb64(pb); ++ footer_partition = avio_rb64(pb); ++ partition->header_byte_count = avio_rb64(pb); ++ partition->index_byte_count = avio_rb64(pb); ++ partition->index_sid = avio_rb32(pb); ++ avio_skip(pb, 8); ++ partition->body_sid = avio_rb32(pb); ++ avio_read(pb, op, sizeof(UID)); ++ nb_essence_containers = avio_rb32(pb); ++ ++ /* some files don'thave FooterPartition set in every partition */ ++ if (footer_partition) { ++ if (mxf->footer_partition && mxf->footer_partition != footer_partition) { ++ av_log(mxf->fc, AV_LOG_ERROR, "inconsistent FooterPartition value: %" PRIi64 " != %" PRIi64 "\n", ++ mxf->footer_partition, footer_partition); ++ } else { ++ mxf->footer_partition = footer_partition; ++ } ++ } ++ ++ av_dlog(mxf->fc, "PartitionPack: ThisPartition = 0x%" PRIx64 ", PreviousPartition = 0x%" PRIx64 ", " ++ "FooterPartition = 0x%" PRIx64 ", IndexSID = %i, BodySID = %i\n", ++ partition->this_partition, ++ partition->previous_partition, footer_partition, ++ partition->index_sid, partition->body_sid); ++ ++ /* sanity check PreviousPartition if set */ ++ if (partition->previous_partition && ++ mxf->run_in + partition->previous_partition >= klv_offset) { ++ av_log(mxf->fc, AV_LOG_ERROR, "PreviousPartition points to this partition or forward\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (op[12] == 1 && op[13] == 1) mxf->op = OP1a; ++ else if (op[12] == 1 && op[13] == 2) mxf->op = OP1b; ++ else if (op[12] == 1 && op[13] == 3) mxf->op = OP1c; ++ else if (op[12] == 2 && op[13] == 1) mxf->op = OP2a; ++ else if (op[12] == 2 && op[13] == 2) mxf->op = OP2b; ++ else if (op[12] == 2 && op[13] == 3) mxf->op = OP2c; ++ else if (op[12] == 3 && op[13] == 1) mxf->op = OP3a; ++ else if (op[12] == 3 && op[13] == 2) mxf->op = OP3b; ++ else if (op[12] == 3 && op[13] == 3) mxf->op = OP3c; ++ else if (op[12] == 64&& op[13] == 1) mxf->op = OPSONYOpt; ++ else if (op[12] == 0x10) { ++ /* SMPTE 390m: "There shall be exactly one essence container" ++ * 2011_DCPTEST_24FPS.V.mxf violates this and is frame wrapped, hence why we assume OP1a */ ++ if (nb_essence_containers != 1) { ++ /* only nag once */ ++ if (!mxf->op) ++ av_log(mxf->fc, AV_LOG_WARNING, "\"OPAtom\" with %u ECs - assuming OP1a\n", nb_essence_containers); ++ ++ mxf->op = OP1a; ++ } else ++ mxf->op = OPAtom; ++ } else { ++ av_log(mxf->fc, AV_LOG_ERROR, "unknown operational pattern: %02xh %02xh - guessing OP1a\n", op[12], op[13]); ++ mxf->op = OP1a; ++ } ++ ++ if (partition->kag_size <= 0 || partition->kag_size > (1 << 20)) { ++ av_log(mxf->fc, AV_LOG_WARNING, "invalid KAGSize %i - guessing ", partition->kag_size); ++ ++ if (mxf->op == OPSONYOpt) ++ partition->kag_size = 512; ++ else ++ partition->kag_size = 1; ++ ++ av_log(mxf->fc, AV_LOG_WARNING, "%i\n", partition->kag_size); ++ } ++ + return 0; + } + + static int mxf_add_metadata_set(MXFContext *mxf, void *metadata_set) + { ++ MXFMetadataSet **tmp; + if (mxf->metadata_sets_count+1 >= UINT_MAX / sizeof(*mxf->metadata_sets)) + return AVERROR(ENOMEM); +- mxf->metadata_sets = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets)); +- if (!mxf->metadata_sets) +- return -1; ++ tmp = av_realloc(mxf->metadata_sets, (mxf->metadata_sets_count + 1) * sizeof(*mxf->metadata_sets)); ++ if (!tmp) ++ return AVERROR(ENOMEM); ++ mxf->metadata_sets = tmp; + mxf->metadata_sets[mxf->metadata_sets_count] = metadata_set; + mxf->metadata_sets_count++; + return 0; + } + +-static int mxf_read_cryptographic_context(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_cryptographic_context(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFCryptoContext *cryptocontext = arg; + if (size != 16) +- return -1; ++ return AVERROR_INVALIDDATA; + if (IS_KLV_KEY(uid, mxf_crypto_source_container_ul)) +- get_buffer(pb, cryptocontext->source_container_ul, 16); ++ avio_read(pb, cryptocontext->source_container_ul, 16); + return 0; + } + +-static int mxf_read_content_storage(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_content_storage(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFContext *mxf = arg; + switch (tag) { + case 0x1901: +- mxf->packages_count = get_be32(pb); ++ mxf->packages_count = avio_rb32(pb); + if (mxf->packages_count >= UINT_MAX / sizeof(UID)) +- return -1; ++ return AVERROR_INVALIDDATA; + mxf->packages_refs = av_malloc(mxf->packages_count * sizeof(UID)); + if (!mxf->packages_refs) +- return -1; +- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ +- get_buffer(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID)); ++ return AVERROR(ENOMEM); ++ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ ++ avio_read(pb, (uint8_t *)mxf->packages_refs, mxf->packages_count * sizeof(UID)); + break; + } + return 0; + } + +-static int mxf_read_source_clip(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_source_clip(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFStructuralComponent *source_clip = arg; + switch(tag) { + case 0x0202: +- source_clip->duration = get_be64(pb); ++ source_clip->duration = avio_rb64(pb); + break; + case 0x1201: +- source_clip->start_position = get_be64(pb); ++ source_clip->start_position = avio_rb64(pb); + break; + case 0x1101: + /* UMID, only get last 16 bytes */ +- url_fskip(pb, 16); +- get_buffer(pb, source_clip->source_package_uid, 16); ++ avio_skip(pb, 16); ++ avio_read(pb, source_clip->source_package_uid, 16); + break; + case 0x1102: +- source_clip->source_track_id = get_be32(pb); ++ source_clip->source_track_id = avio_rb32(pb); + break; + } + return 0; + } + +-static int mxf_read_material_package(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_material_package(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFPackage *package = arg; + switch(tag) { + case 0x4403: +- package->tracks_count = get_be32(pb); ++ package->tracks_count = avio_rb32(pb); + if (package->tracks_count >= UINT_MAX / sizeof(UID)) +- return -1; ++ return AVERROR_INVALIDDATA; + package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); + if (!package->tracks_refs) +- return -1; +- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ +- get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); ++ return AVERROR(ENOMEM); ++ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ ++ avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); + break; + } + return 0; + } + +-static int mxf_read_track(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_track(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFTrack *track = arg; + switch(tag) { + case 0x4801: +- track->track_id = get_be32(pb); ++ track->track_id = avio_rb32(pb); + break; + case 0x4804: +- get_buffer(pb, track->track_number, 4); ++ avio_read(pb, track->track_number, 4); + break; + case 0x4B01: +- track->edit_rate.den = get_be32(pb); +- track->edit_rate.num = get_be32(pb); ++ track->edit_rate.den = avio_rb32(pb); ++ track->edit_rate.num = avio_rb32(pb); + break; + case 0x4803: +- get_buffer(pb, track->sequence_ref, 16); ++ avio_read(pb, track->sequence_ref, 16); + break; + } + return 0; + } + +-static int mxf_read_sequence(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_sequence(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFSequence *sequence = arg; + switch(tag) { + case 0x0202: +- sequence->duration = get_be64(pb); ++ sequence->duration = avio_rb64(pb); + break; + case 0x0201: +- get_buffer(pb, sequence->data_definition_ul, 16); ++ avio_read(pb, sequence->data_definition_ul, 16); + break; + case 0x1001: +- sequence->structural_components_count = get_be32(pb); ++ sequence->structural_components_count = avio_rb32(pb); + if (sequence->structural_components_count >= UINT_MAX / sizeof(UID)) +- return -1; ++ return AVERROR_INVALIDDATA; + sequence->structural_components_refs = av_malloc(sequence->structural_components_count * sizeof(UID)); + if (!sequence->structural_components_refs) +- return -1; +- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ +- get_buffer(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID)); ++ return AVERROR(ENOMEM); ++ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ ++ avio_read(pb, (uint8_t *)sequence->structural_components_refs, sequence->structural_components_count * sizeof(UID)); + break; + } + return 0; + } + +-static int mxf_read_source_package(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_source_package(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFPackage *package = arg; + switch(tag) { + case 0x4403: +- package->tracks_count = get_be32(pb); ++ package->tracks_count = avio_rb32(pb); + if (package->tracks_count >= UINT_MAX / sizeof(UID)) +- return -1; ++ return AVERROR_INVALIDDATA; + package->tracks_refs = av_malloc(package->tracks_count * sizeof(UID)); + if (!package->tracks_refs) +- return -1; +- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ +- get_buffer(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); ++ return AVERROR(ENOMEM); ++ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ ++ avio_read(pb, (uint8_t *)package->tracks_refs, package->tracks_count * sizeof(UID)); + break; + case 0x4401: + /* UMID, only get last 16 bytes */ +- url_fskip(pb, 16); +- get_buffer(pb, package->package_uid, 16); ++ avio_skip(pb, 16); ++ avio_read(pb, package->package_uid, 16); + break; + case 0x4701: +- get_buffer(pb, package->descriptor_ref, 16); ++ avio_read(pb, package->descriptor_ref, 16); + break; + } + return 0; + } + +-static int mxf_read_index_table_segment(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_index_entry_array(AVIOContext *pb, MXFIndexTableSegment *segment) ++{ ++ int i, length; ++ ++ segment->nb_index_entries = avio_rb32(pb); ++ length = avio_rb32(pb); ++ ++ if (!(segment->temporal_offset_entries=av_calloc(segment->nb_index_entries, sizeof(*segment->temporal_offset_entries))) || ++ !(segment->flag_entries = av_calloc(segment->nb_index_entries, sizeof(*segment->flag_entries))) || ++ !(segment->stream_offset_entries = av_calloc(segment->nb_index_entries, sizeof(*segment->stream_offset_entries)))) ++ return AVERROR(ENOMEM); ++ ++ for (i = 0; i < segment->nb_index_entries; i++) { ++ segment->temporal_offset_entries[i] = avio_r8(pb); ++ avio_r8(pb); /* KeyFrameOffset */ ++ segment->flag_entries[i] = avio_r8(pb); ++ segment->stream_offset_entries[i] = avio_rb64(pb); ++ avio_skip(pb, length - 11); ++ } ++ return 0; ++} ++ ++static int mxf_read_index_table_segment(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { ++ MXFIndexTableSegment *segment = arg; + switch(tag) { +- case 0x3F05: av_dlog(NULL, "EditUnitByteCount %d\n", get_be32(pb)); break; +- case 0x3F06: av_dlog(NULL, "IndexSID %d\n", get_be32(pb)); break; +- case 0x3F07: av_dlog(NULL, "BodySID %d\n", get_be32(pb)); break; +- case 0x3F0B: av_dlog(NULL, "IndexEditRate %d/%d\n", get_be32(pb), get_be32(pb)); break; +- case 0x3F0C: av_dlog(NULL, "IndexStartPosition %lld\n", get_be64(pb)); break; +- case 0x3F0D: av_dlog(NULL, "IndexDuration %lld\n", get_be64(pb)); break; ++ case 0x3F05: ++ segment->edit_unit_byte_count = avio_rb32(pb); ++ av_dlog(NULL, "EditUnitByteCount %d\n", segment->edit_unit_byte_count); ++ break; ++ case 0x3F06: ++ segment->index_sid = avio_rb32(pb); ++ av_dlog(NULL, "IndexSID %d\n", segment->index_sid); ++ break; ++ case 0x3F07: ++ segment->body_sid = avio_rb32(pb); ++ av_dlog(NULL, "BodySID %d\n", segment->body_sid); ++ break; ++ case 0x3F0A: ++ av_dlog(NULL, "IndexEntryArray found\n"); ++ return mxf_read_index_entry_array(pb, segment); ++ case 0x3F0B: ++ segment->index_edit_rate.num = avio_rb32(pb); ++ segment->index_edit_rate.den = avio_rb32(pb); ++ av_dlog(NULL, "IndexEditRate %d/%d\n", segment->index_edit_rate.num, ++ segment->index_edit_rate.den); ++ break; ++ case 0x3F0C: ++ segment->index_start_position = avio_rb64(pb); ++ av_dlog(NULL, "IndexStartPosition %"PRId64"\n", segment->index_start_position); ++ break; ++ case 0x3F0D: ++ segment->index_duration = avio_rb64(pb); ++ av_dlog(NULL, "IndexDuration %"PRId64"\n", segment->index_duration); ++ break; + } + return 0; + } + +-static void mxf_read_pixel_layout(ByteIOContext *pb, MXFDescriptor *descriptor) ++static void mxf_read_pixel_layout(AVIOContext *pb, MXFDescriptor *descriptor) + { + int code, value, ofs = 0; + char layout[16] = {0}; + + do { +- code = get_byte(pb); +- value = get_byte(pb); ++ code = avio_r8(pb); ++ value = avio_r8(pb); + av_dlog(NULL, "pixel layout: code %#x\n", code); + + if (ofs < 16) { +@@ -547,51 +762,51 @@ + ff_mxf_decode_pixel_layout(layout, &descriptor->pix_fmt); + } + +-static int mxf_read_generic_descriptor(void *arg, ByteIOContext *pb, int tag, int size, UID uid) ++static int mxf_read_generic_descriptor(void *arg, AVIOContext *pb, int tag, int size, UID uid, int64_t klv_offset) + { + MXFDescriptor *descriptor = arg; + switch(tag) { + case 0x3F01: +- descriptor->sub_descriptors_count = get_be32(pb); ++ descriptor->sub_descriptors_count = avio_rb32(pb); + if (descriptor->sub_descriptors_count >= UINT_MAX / sizeof(UID)) +- return -1; ++ return AVERROR_INVALIDDATA; + descriptor->sub_descriptors_refs = av_malloc(descriptor->sub_descriptors_count * sizeof(UID)); + if (!descriptor->sub_descriptors_refs) +- return -1; +- url_fskip(pb, 4); /* useless size of objects, always 16 according to specs */ +- get_buffer(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID)); ++ return AVERROR(ENOMEM); ++ avio_skip(pb, 4); /* useless size of objects, always 16 according to specs */ ++ avio_read(pb, (uint8_t *)descriptor->sub_descriptors_refs, descriptor->sub_descriptors_count * sizeof(UID)); + break; + case 0x3004: +- get_buffer(pb, descriptor->essence_container_ul, 16); ++ avio_read(pb, descriptor->essence_container_ul, 16); + break; + case 0x3006: +- descriptor->linked_track_id = get_be32(pb); ++ descriptor->linked_track_id = avio_rb32(pb); + break; + case 0x3201: /* PictureEssenceCoding */ +- get_buffer(pb, descriptor->essence_codec_ul, 16); ++ avio_read(pb, descriptor->essence_codec_ul, 16); + break; + case 0x3203: +- descriptor->width = get_be32(pb); ++ descriptor->width = avio_rb32(pb); + break; + case 0x3202: +- descriptor->height = get_be32(pb); ++ descriptor->height = avio_rb32(pb); + break; + case 0x320E: +- descriptor->aspect_ratio.num = get_be32(pb); +- descriptor->aspect_ratio.den = get_be32(pb); ++ descriptor->aspect_ratio.num = avio_rb32(pb); ++ descriptor->aspect_ratio.den = avio_rb32(pb); + break; + case 0x3D03: +- descriptor->sample_rate.num = get_be32(pb); +- descriptor->sample_rate.den = get_be32(pb); ++ descriptor->sample_rate.num = avio_rb32(pb); ++ descriptor->sample_rate.den = avio_rb32(pb); + break; + case 0x3D06: /* SoundEssenceCompression */ +- get_buffer(pb, descriptor->essence_codec_ul, 16); ++ avio_read(pb, descriptor->essence_codec_ul, 16); + break; + case 0x3D07: +- descriptor->channels = get_be32(pb); ++ descriptor->channels = avio_rb32(pb); + break; + case 0x3D01: +- descriptor->bits_per_sample = get_be32(pb); ++ descriptor->bits_per_sample = avio_rb32(pb); + break; + case 0x3401: + mxf_read_pixel_layout(pb, descriptor); +@@ -599,11 +814,11 @@ + default: + /* Private uid used by SONY C0023S01.mxf */ + if (IS_KLV_KEY(uid, mxf_sony_mpeg4_extradata)) { +- descriptor->extradata = av_malloc(size); ++ descriptor->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!descriptor->extradata) +- return -1; ++ return AVERROR(ENOMEM); + descriptor->extradata_size = size; +- get_buffer(pb, descriptor->extradata, size); ++ avio_read(pb, descriptor->extradata, size); + } + break; + } +@@ -649,22 +864,375 @@ + return NULL; + } + +-static const MXFCodecUL mxf_essence_container_uls[] = { ++static const MXFCodecUL mxf_picture_essence_container_uls[] = { + // video essence container uls + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x60,0x01 }, 14, CODEC_ID_MPEG2VIDEO }, /* MPEG-ES Frame wrapped */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x02,0x41,0x01 }, 14, CODEC_ID_DVVIDEO }, /* DV 625 25mbps */ ++ { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE }, ++}; ++static const MXFCodecUL mxf_sound_essence_container_uls[] = { + // sound essence container uls + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x06,0x01,0x00 }, 14, CODEC_ID_PCM_S16LE }, /* BWF Frame wrapped */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x02,0x0D,0x01,0x03,0x01,0x02,0x04,0x40,0x01 }, 14, CODEC_ID_MP2 }, /* MPEG-ES Frame wrapped, 0x40 ??? stream id */ + { { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x01,0x0D,0x01,0x03,0x01,0x02,0x01,0x01,0x01 }, 14, CODEC_ID_PCM_S16LE }, /* D-10 Mapping 50Mbps PAL Extended Template */ ++ { { 0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0xFF,0x4B,0x46,0x41,0x41,0x00,0x0D,0x4D,0x4F }, 14, CODEC_ID_PCM_S16LE }, /* 0001GL00.MXF.A1.mxf_opatom.mxf */ + { { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, 0, CODEC_ID_NONE }, + }; + ++static int mxf_get_sorted_table_segments(MXFContext *mxf, int *nb_sorted_segments, MXFIndexTableSegment ***sorted_segments) ++{ ++ int i, j, nb_segments = 0; ++ MXFIndexTableSegment **unsorted_segments; ++ int last_body_sid = -1, last_index_sid = -1, last_index_start = -1; ++ ++ /* count number of segments, allocate arrays and copy unsorted segments */ ++ for (i = 0; i < mxf->metadata_sets_count; i++) ++ if (mxf->metadata_sets[i]->type == IndexTableSegment) ++ nb_segments++; ++ ++ if (!(unsorted_segments = av_calloc(nb_segments, sizeof(*unsorted_segments))) || ++ !(*sorted_segments = av_calloc(nb_segments, sizeof(**sorted_segments)))) { ++ av_freep(sorted_segments); ++ av_free(unsorted_segments); ++ return AVERROR(ENOMEM); ++ } ++ ++ for (i = j = 0; i < mxf->metadata_sets_count; i++) ++ if (mxf->metadata_sets[i]->type == IndexTableSegment) ++ unsorted_segments[j++] = (MXFIndexTableSegment*)mxf->metadata_sets[i]; ++ ++ *nb_sorted_segments = 0; ++ ++ /* sort segments by {BodySID, IndexSID, IndexStartPosition}, remove duplicates while we're at it */ ++ for (i = 0; i < nb_segments; i++) { ++ int best = -1, best_body_sid = -1, best_index_sid = -1, best_index_start = -1; ++ ++ for (j = 0; j < nb_segments; j++) { ++ MXFIndexTableSegment *s = unsorted_segments[j]; ++ ++ /* Require larger BosySID, IndexSID or IndexStartPosition then the previous entry. This removes duplicates. ++ * We want the smallest values for the keys than what we currently have, unless this is the first such entry this time around. ++ */ ++ if ((i == 0 || s->body_sid > last_body_sid || s->index_sid > last_index_sid || s->index_start_position > last_index_start) && ++ (best == -1 || s->body_sid < best_body_sid || s->index_sid < best_index_sid || s->index_start_position < best_index_start)) { ++ best = j; ++ best_body_sid = s->body_sid; ++ best_index_sid = s->index_sid; ++ best_index_start = s->index_start_position; ++ } ++ } ++ ++ /* no suitable entry found -> we're done */ ++ if (best == -1) ++ break; ++ ++ (*sorted_segments)[(*nb_sorted_segments)++] = unsorted_segments[best]; ++ last_body_sid = best_body_sid; ++ last_index_sid = best_index_sid; ++ last_index_start = best_index_start; ++ } ++ ++ av_free(unsorted_segments); ++ ++ return 0; ++} ++ ++/** ++ * Computes the absolute file offset of the given essence container offset ++ */ ++static int mxf_absolute_bodysid_offset(MXFContext *mxf, int body_sid, int64_t offset, int64_t *offset_out) ++{ ++ int x; ++ int64_t offset_in = offset; /* for logging */ ++ ++ for (x = 0; x < mxf->partitions_count; x++) { ++ MXFPartition *p = &mxf->partitions[x]; ++ ++ if (p->body_sid != body_sid) ++ continue; ++ ++ if (offset < p->essence_length || !p->essence_length) { ++ *offset_out = p->essence_offset + offset; ++ return 0; ++ } ++ ++ offset -= p->essence_length; ++ } ++ ++ av_log(mxf->fc, AV_LOG_ERROR, "failed to find absolute offset of %" PRIx64" in BodySID %i - partial file?\n", ++ offset_in, body_sid); ++ ++ return AVERROR_INVALIDDATA; ++} ++ ++/** ++ * Returns the end position of the essence container with given BodySID, or zero if unknown ++ */ ++static int64_t mxf_essence_container_end(MXFContext *mxf, int body_sid) ++{ ++ int x; ++ int64_t ret = 0; ++ ++ for (x = 0; x < mxf->partitions_count; x++) { ++ MXFPartition *p = &mxf->partitions[x]; ++ ++ if (p->body_sid != body_sid) ++ continue; ++ ++ if (!p->essence_length) ++ return 0; ++ ++ ret = p->essence_offset + p->essence_length; ++ } ++ ++ return ret; ++} ++ ++/* EditUnit -> absolute offset */ ++static int mxf_edit_unit_absolute_offset(MXFContext *mxf, MXFIndexTable *index_table, int64_t edit_unit, int64_t *edit_unit_out, int64_t *offset_out, int nag) ++{ ++ int i; ++ int64_t offset_temp = 0; ++ ++ for (i = 0; i < index_table->nb_segments; i++) { ++ MXFIndexTableSegment *s = index_table->segments[i]; ++ ++ edit_unit = FFMAX(edit_unit, s->index_start_position); /* clamp if trying to seek before start */ ++ ++ if (edit_unit < s->index_start_position + s->index_duration) { ++ int64_t index = edit_unit - s->index_start_position; ++ ++ if (s->edit_unit_byte_count) ++ offset_temp += s->edit_unit_byte_count * index; ++ else if (s->nb_index_entries) { ++ if (s->nb_index_entries == 2 * s->index_duration + 1) ++ index *= 2; /* Avid index */ ++ ++ if (index < 0 || index > s->nb_index_entries) { ++ av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" IndexEntryArray too small\n", ++ index_table->index_sid, s->index_start_position); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ offset_temp = s->stream_offset_entries[index]; ++ } else { ++ av_log(mxf->fc, AV_LOG_ERROR, "IndexSID %i segment at %"PRId64" missing EditUnitByteCount and IndexEntryArray\n", ++ index_table->index_sid, s->index_start_position); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (edit_unit_out) ++ *edit_unit_out = edit_unit; ++ ++ return mxf_absolute_bodysid_offset(mxf, index_table->body_sid, offset_temp, offset_out); ++ } else { ++ /* EditUnitByteCount == 0 for VBR indexes, which is fine since they use explicit StreamOffsets */ ++ offset_temp += s->edit_unit_byte_count * s->index_duration; ++ } ++ } ++ ++ if (nag) ++ av_log(mxf->fc, AV_LOG_ERROR, "failed to map EditUnit %"PRId64" in IndexSID %i to an offset\n", edit_unit, index_table->index_sid); ++ ++ return AVERROR_INVALIDDATA; ++} ++ ++static int mxf_compute_ptses_fake_index(MXFContext *mxf, MXFIndexTable *index_table) ++{ ++ int i, j, x; ++ int8_t max_temporal_offset = -128; ++ ++ /* first compute how many entries we have */ ++ for (i = 0; i < index_table->nb_segments; i++) { ++ MXFIndexTableSegment *s = index_table->segments[i]; ++ ++ if (!s->nb_index_entries) { ++ index_table->nb_ptses = 0; ++ return 0; /* no TemporalOffsets */ ++ } ++ ++ index_table->nb_ptses += s->index_duration; ++ } ++ ++ /* paranoid check */ ++ if (index_table->nb_ptses <= 0) ++ return 0; ++ ++ if (!(index_table->ptses = av_calloc(index_table->nb_ptses, sizeof(int64_t))) || ++ !(index_table->fake_index = av_calloc(index_table->nb_ptses, sizeof(AVIndexEntry)))) { ++ av_freep(&index_table->ptses); ++ return AVERROR(ENOMEM); ++ } ++ ++ /* we may have a few bad TemporalOffsets ++ * make sure the corresponding PTSes don't have the bogus value 0 */ ++ for (x = 0; x < index_table->nb_ptses; x++) ++ index_table->ptses[x] = AV_NOPTS_VALUE; ++ ++ /** ++ * We have this: ++ * ++ * x TemporalOffset ++ * 0: 0 ++ * 1: 1 ++ * 2: 1 ++ * 3: -2 ++ * 4: 1 ++ * 5: 1 ++ * 6: -2 ++ * ++ * We want to transform it into this: ++ * ++ * x DTS PTS ++ * 0: -1 0 ++ * 1: 0 3 ++ * 2: 1 1 ++ * 3: 2 2 ++ * 4: 3 6 ++ * 5: 4 4 ++ * 6: 5 5 ++ * ++ * We do this by bucket sorting x by x+TemporalOffset[x] into mxf->ptses, ++ * then settings mxf->first_dts = -max(TemporalOffset[x]). ++ * The latter makes DTS <= PTS. ++ */ ++ for (i = x = 0; i < index_table->nb_segments; i++) { ++ MXFIndexTableSegment *s = index_table->segments[i]; ++ int index_delta = 1; ++ int n = s->nb_index_entries; ++ ++ if (s->nb_index_entries == 2 * s->index_duration + 1) { ++ index_delta = 2; /* Avid index */ ++ ++ /* ignore the last entry - it's the size of the essence container */ ++ n--; ++ } ++ ++ for (j = 0; j < n; j += index_delta, x++) { ++ int offset = s->temporal_offset_entries[j] / index_delta; ++ int index = x + offset; ++ ++ if (x >= index_table->nb_ptses) { ++ av_log(mxf->fc, AV_LOG_ERROR, "x >= nb_ptses - IndexEntryCount %i < IndexDuration %"PRId64"?\n", ++ s->nb_index_entries, s->index_duration); ++ break; ++ } ++ ++ index_table->fake_index[x].timestamp = x; ++ index_table->fake_index[x].flags = !(s->flag_entries[j] & 0x30) ? AVINDEX_KEYFRAME : 0; ++ ++ if (index < 0 || index >= index_table->nb_ptses) { ++ av_log(mxf->fc, AV_LOG_ERROR, ++ "index entry %i + TemporalOffset %i = %i, which is out of bounds\n", ++ x, offset, index); ++ continue; ++ } ++ ++ index_table->ptses[index] = x; ++ max_temporal_offset = FFMAX(max_temporal_offset, offset); ++ } ++ } ++ ++ index_table->first_dts = -max_temporal_offset; ++ ++ return 0; ++} ++ ++/** ++ * Sorts and collects index table segments into index tables. ++ * Also computes PTSes if possible. ++ */ ++static int mxf_compute_index_tables(MXFContext *mxf) ++{ ++ int i, j, k, ret, nb_sorted_segments; ++ MXFIndexTableSegment **sorted_segments = NULL; ++ ++ if ((ret = mxf_get_sorted_table_segments(mxf, &nb_sorted_segments, &sorted_segments)) || ++ nb_sorted_segments <= 0) { ++ av_log(mxf->fc, AV_LOG_WARNING, "broken or empty index\n"); ++ return 0; ++ } ++ ++ /* sanity check and count unique BodySIDs/IndexSIDs */ ++ for (i = 0; i < nb_sorted_segments; i++) { ++ if (i == 0 || sorted_segments[i-1]->index_sid != sorted_segments[i]->index_sid) ++ mxf->nb_index_tables++; ++ else if (sorted_segments[i-1]->body_sid != sorted_segments[i]->body_sid) { ++ av_log(mxf->fc, AV_LOG_ERROR, "found inconsistent BodySID\n"); ++ ret = AVERROR_INVALIDDATA; ++ goto finish_decoding_index; ++ } ++ } ++ ++ if (!(mxf->index_tables = av_calloc(mxf->nb_index_tables, sizeof(MXFIndexTable)))) { ++ av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate index tables\n"); ++ ret = AVERROR(ENOMEM); ++ goto finish_decoding_index; ++ } ++ ++ /* distribute sorted segments to index tables */ ++ for (i = j = 0; i < nb_sorted_segments; i++) { ++ if (i != 0 && sorted_segments[i-1]->index_sid != sorted_segments[i]->index_sid) { ++ /* next IndexSID */ ++ j++; ++ } ++ ++ mxf->index_tables[j].nb_segments++; ++ } ++ ++ for (i = j = 0; j < mxf->nb_index_tables; i += mxf->index_tables[j++].nb_segments) { ++ MXFIndexTable *t = &mxf->index_tables[j]; ++ ++ if (!(t->segments = av_calloc(t->nb_segments, sizeof(MXFIndexTableSegment*)))) { ++ av_log(mxf->fc, AV_LOG_ERROR, "failed to allocate IndexTableSegment pointer array\n"); ++ ret = AVERROR(ENOMEM); ++ goto finish_decoding_index; ++ } ++ ++ if (sorted_segments[i]->index_start_position) ++ av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i starts at EditUnit %"PRId64" - seeking may not work as expected\n", ++ sorted_segments[i]->index_sid, sorted_segments[i]->index_start_position); ++ ++ memcpy(t->segments, &sorted_segments[i], t->nb_segments * sizeof(MXFIndexTableSegment*)); ++ t->index_sid = sorted_segments[i]->index_sid; ++ t->body_sid = sorted_segments[i]->body_sid; ++ ++ if ((ret = mxf_compute_ptses_fake_index(mxf, t)) < 0) ++ goto finish_decoding_index; ++ ++ /* fix zero IndexDurations */ ++ for (k = 0; k < t->nb_segments; k++) { ++ if (t->segments[k]->index_duration) ++ continue; ++ ++ if (t->nb_segments > 1) ++ av_log(mxf->fc, AV_LOG_WARNING, "IndexSID %i segment %i has zero IndexDuration and there's more than one segment\n", ++ t->index_sid, k); ++ ++ if (mxf->fc->nb_streams <= 0) { ++ av_log(mxf->fc, AV_LOG_WARNING, "no streams?\n"); ++ break; ++ } ++ ++ /* assume the first stream's duration is reasonable ++ * leave index_duration = 0 on further segments in case we have any (unlikely) ++ */ ++ t->segments[k]->index_duration = mxf->fc->streams[0]->duration; ++ break; ++ } ++ } ++ ++ ret = 0; ++finish_decoding_index: ++ av_free(sorted_segments); ++ return ret; ++} ++ + static int mxf_parse_structural_metadata(MXFContext *mxf) + { + MXFPackage *material_package = NULL; + MXFPackage *temp_package = NULL; +- int i, j, k; ++ int i, j, k, ret; + + av_dlog(mxf->fc, "metadata sets count %d\n", mxf->metadata_sets_count); + /* TODO: handle multiple material packages (OP3x) */ +@@ -674,7 +1242,7 @@ + } + if (!material_package) { + av_log(mxf->fc, AV_LOG_ERROR, "no material package found\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + + for (i = 0; i < material_package->tracks_count; i++) { +@@ -716,13 +1284,14 @@ + } + } + if (!source_package) { +- av_log(mxf->fc, AV_LOG_ERROR, "material track %d: no corresponding source package found\n", material_track->track_id); ++ av_dlog(mxf->fc, "material track %d: no corresponding source package found\n", material_track->track_id); + break; + } + for (k = 0; k < source_package->tracks_count; k++) { + if (!(temp_track = mxf_resolve_strong_ref(mxf, &source_package->tracks_refs[k], Track))) { + av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track strong ref\n"); +- return -1; ++ ret = AVERROR_INVALIDDATA; ++ goto fail_and_free; + } + if (temp_track->track_id == component->source_track_id) { + source_track = temp_track; +@@ -734,25 +1303,35 @@ + break; + } + } +- if (!source_track) ++ if (!source_track || !component) + continue; + +- st = av_new_stream(mxf->fc, source_track->track_id); ++ if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) { ++ av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n"); ++ ret = AVERROR_INVALIDDATA; ++ goto fail_and_free; ++ } ++ ++ /* 0001GL00.MXF.A1.mxf_opatom.mxf has the same SourcePackageID as 0001GL.MXF.V1.mxf_opatom.mxf ++ * This would result in both files appearing to have two streams. Work around this by sanity checking DataDefinition */ ++ if (memcmp(material_track->sequence->data_definition_ul, source_track->sequence->data_definition_ul, 16)) { ++ av_log(mxf->fc, AV_LOG_ERROR, "material track %d: DataDefinition mismatch\n", material_track->track_id); ++ continue; ++ } ++ ++ st = avformat_new_stream(mxf->fc, NULL); + if (!st) { + av_log(mxf->fc, AV_LOG_ERROR, "could not allocate stream\n"); +- return -1; ++ ret = AVERROR(ENOMEM); ++ goto fail_and_free; + } ++ st->id = source_track->track_id; + st->priv_data = source_track; + st->duration = component->duration; + if (st->duration == -1) + st->duration = AV_NOPTS_VALUE; + st->start_time = component->start_position; +- av_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den); +- +- if (!(source_track->sequence = mxf_resolve_strong_ref(mxf, &source_track->sequence_ref, Sequence))) { +- av_log(mxf->fc, AV_LOG_ERROR, "could not resolve source track sequence strong ref\n"); +- return -1; +- } ++ avpriv_set_pts_info(st, 64, material_track->edit_rate.num, material_track->edit_rate.den); + + PRINT_KEY(mxf->fc, "data definition ul", source_track->sequence->data_definition_ul); + codec_ul = mxf_get_codec_ul(ff_mxf_data_definition_uls, &source_track->sequence->data_definition_ul); +@@ -795,6 +1374,7 @@ + } + } + } ++ + /* TODO: drop PictureEssenceCoding and SoundEssenceCompression, only check EssenceContainer */ + codec_ul = mxf_get_codec_ul(ff_mxf_codec_uls, &descriptor->essence_codec_ul); + st->codec->codec_id = codec_ul->id; +@@ -803,7 +1383,7 @@ + st->codec->extradata_size = descriptor->extradata_size; + } + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- container_ul = mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul); ++ container_ul = mxf_get_codec_ul(mxf_picture_essence_container_uls, essence_container_ul); + if (st->codec->codec_id == CODEC_ID_NONE) + st->codec->codec_id = container_ul->id; + st->codec->width = descriptor->width; +@@ -812,20 +1392,21 @@ + st->codec->pix_fmt = descriptor->pix_fmt; + st->need_parsing = AVSTREAM_PARSE_HEADERS; + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- container_ul = mxf_get_codec_ul(mxf_essence_container_uls, essence_container_ul); ++ container_ul = mxf_get_codec_ul(mxf_sound_essence_container_uls, essence_container_ul); + if (st->codec->codec_id == CODEC_ID_NONE) + st->codec->codec_id = container_ul->id; + st->codec->channels = descriptor->channels; + st->codec->bits_per_coded_sample = descriptor->bits_per_sample; ++ if (descriptor->sample_rate.den > 0) + st->codec->sample_rate = descriptor->sample_rate.num / descriptor->sample_rate.den; + /* TODO: implement CODEC_ID_RAWAUDIO */ + if (st->codec->codec_id == CODEC_ID_PCM_S16LE) { +- if (descriptor->bits_per_sample == 24) ++ if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) + st->codec->codec_id = CODEC_ID_PCM_S24LE; + else if (descriptor->bits_per_sample == 32) + st->codec->codec_id = CODEC_ID_PCM_S32LE; + } else if (st->codec->codec_id == CODEC_ID_PCM_S16BE) { +- if (descriptor->bits_per_sample == 24) ++ if (descriptor->bits_per_sample > 16 && descriptor->bits_per_sample <= 24) + st->codec->codec_id = CODEC_ID_PCM_S24BE; + else if (descriptor->bits_per_sample == 32) + st->codec->codec_id = CODEC_ID_PCM_S32BE; +@@ -834,15 +1415,28 @@ + } + } + if (st->codec->codec_type != AVMEDIA_TYPE_DATA && (*essence_container_ul)[15] > 0x01) { +- av_log(mxf->fc, AV_LOG_WARNING, "only frame wrapped mappings are correctly supported\n"); +- st->need_parsing = AVSTREAM_PARSE_FULL; ++ /* TODO: decode timestamps */ ++ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; + } + } +- return 0; ++ ++ ret = 0; ++fail_and_free: ++ return ret; + } + + static const MXFMetadataReadTableEntry mxf_metadata_read_table[] = { + { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x05,0x01,0x00 }, mxf_read_primer_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x01,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x02,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x03,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x02,0x04,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x01,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x02,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x03,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x03,0x04,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x02,0x00 }, mxf_read_partition_pack }, ++ { { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0d,0x01,0x02,0x01,0x01,0x04,0x04,0x00 }, mxf_read_partition_pack }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x18,0x00 }, mxf_read_content_storage, 0, AnyType }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x37,0x00 }, mxf_read_source_package, sizeof(MXFPackage), SourcePackage }, + { { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x36,0x00 }, mxf_read_material_package, sizeof(MXFPackage), MaterialPackage }, +@@ -864,16 +1458,17 @@ + + static int mxf_read_local_tags(MXFContext *mxf, KLVPacket *klv, MXFMetadataReadFunc *read_child, int ctx_size, enum MXFMetadataSetType type) + { +- ByteIOContext *pb = mxf->fc->pb; ++ AVIOContext *pb = mxf->fc->pb; + MXFMetadataSet *ctx = ctx_size ? av_mallocz(ctx_size) : mxf; +- uint64_t klv_end = url_ftell(pb) + klv->length; ++ uint64_t klv_end = avio_tell(pb) + klv->length; + + if (!ctx) +- return -1; +- while (url_ftell(pb) + 4 < klv_end) { +- int tag = get_be16(pb); +- int size = get_be16(pb); /* KLV specified by 0x53 */ +- uint64_t next = url_ftell(pb) + size; ++ return AVERROR(ENOMEM); ++ while (avio_tell(pb) + 4 < klv_end && !url_feof(pb)) { ++ int ret; ++ int tag = avio_rb16(pb); ++ int size = avio_rb16(pb); /* KLV specified by 0x53 */ ++ uint64_t next = avio_tell(pb) + size; + UID uid = {0}; + + av_dlog(mxf->fc, "local tag %#04x size %d\n", tag, size); +@@ -893,39 +1488,243 @@ + } + } + if (ctx_size && tag == 0x3C0A) +- get_buffer(pb, ctx->uid, 16); +- else if (read_child(ctx, pb, tag, size, uid) < 0) +- return -1; +- +- url_fseek(pb, next, SEEK_SET); ++ avio_read(pb, ctx->uid, 16); ++ else if ((ret = read_child(ctx, pb, tag, size, uid, -1)) < 0) ++ return ret; ++ ++ /* accept the 64k local set limit being exceeded (Avid) ++ * don't accept it extending past the end of the KLV though (zzuf5.mxf) */ ++ if (avio_tell(pb) > klv_end) { ++ av_log(mxf->fc, AV_LOG_ERROR, "local tag %#04x extends past end of local set @ %#"PRIx64"\n", ++ tag, klv->offset); ++ return AVERROR_INVALIDDATA; ++ } else if (avio_tell(pb) <= next) /* only seek forward, else this can loop for a long time */ ++ avio_seek(pb, next, SEEK_SET); + } + if (ctx_size) ctx->type = type; + return ctx_size ? mxf_add_metadata_set(mxf, ctx) : 0; + } + ++/** ++ * Seeks to the previous partition, if possible ++ * @return <= 0 if we should stop parsing, > 0 if we should keep going ++ */ ++static int mxf_seek_to_previous_partition(MXFContext *mxf) ++{ ++ AVIOContext *pb = mxf->fc->pb; ++ ++ if (!mxf->current_partition || ++ mxf->run_in + mxf->current_partition->previous_partition <= mxf->last_forward_tell) ++ return 0; /* we've parsed all partitions */ ++ ++ /* seek to previous partition */ ++ avio_seek(pb, mxf->run_in + mxf->current_partition->previous_partition, SEEK_SET); ++ mxf->current_partition = NULL; ++ ++ av_dlog(mxf->fc, "seeking to previous partition\n"); ++ ++ return 1; ++} ++ ++/** ++ * Called when essence is encountered ++ * @return <= 0 if we should stop parsing, > 0 if we should keep going ++ */ ++static int mxf_parse_handle_essence(MXFContext *mxf) ++{ ++ AVIOContext *pb = mxf->fc->pb; ++ int64_t ret; ++ ++ if (mxf->parsing_backward) { ++ return mxf_seek_to_previous_partition(mxf); ++ } else { ++ if (!mxf->footer_partition) { ++ av_dlog(mxf->fc, "no footer\n"); ++ return 0; ++ } ++ ++ av_dlog(mxf->fc, "seeking to footer\n"); ++ ++ /* remember where we were so we don't end up seeking further back than this */ ++ mxf->last_forward_tell = avio_tell(pb); ++ ++ if (!pb->seekable) { ++ av_log(mxf->fc, AV_LOG_INFO, "file is not seekable - not parsing footer\n"); ++ return -1; ++ } ++ ++ /* seek to footer partition and parse backward */ ++ if ((ret = avio_seek(pb, mxf->run_in + mxf->footer_partition, SEEK_SET)) < 0) { ++ av_log(mxf->fc, AV_LOG_ERROR, "failed to seek to footer @ 0x%"PRIx64" (%"PRId64") - partial file?\n", ++ mxf->run_in + mxf->footer_partition, ret); ++ return ret; ++ } ++ ++ mxf->current_partition = NULL; ++ mxf->parsing_backward = 1; ++ } ++ ++ return 1; ++} ++ ++/** ++ * Called when the next partition or EOF is encountered ++ * @return <= 0 if we should stop parsing, > 0 if we should keep going ++ */ ++static int mxf_parse_handle_partition_or_eof(MXFContext *mxf) ++{ ++ return mxf->parsing_backward ? mxf_seek_to_previous_partition(mxf) : 1; ++} ++ ++/** ++ * Figures out the proper offset and length of the essence container in each partition ++ */ ++static void mxf_compute_essence_containers(MXFContext *mxf) ++{ ++ int x; ++ ++ /* everything is already correct */ ++ if (mxf->op == OPAtom) ++ return; ++ ++ for (x = 0; x < mxf->partitions_count; x++) { ++ MXFPartition *p = &mxf->partitions[x]; ++ ++ if (!p->body_sid) ++ continue; /* BodySID == 0 -> no essence */ ++ ++ if (x >= mxf->partitions_count - 1) ++ break; /* last partition - can't compute length (and we don't need to) */ ++ ++ /* essence container spans to the next partition */ ++ p->essence_length = mxf->partitions[x+1].this_partition - p->essence_offset; ++ ++ if (p->essence_length < 0) { ++ /* next ThisPartition < essence_offset */ ++ p->essence_length = 0; ++ av_log(mxf->fc, AV_LOG_ERROR, "partition %i: bad ThisPartition = %" PRIx64 "\n", ++ x+1, mxf->partitions[x+1].this_partition); ++ } ++ } ++} ++ ++static int64_t round_to_kag(int64_t position, int kag_size) ++{ ++ /* TODO: account for run-in? the spec isn't clear whether KAG should account for it */ ++ /* NOTE: kag_size may be any integer between 1 - 2^10 */ ++ int64_t ret = (position / kag_size) * kag_size; ++ return ret == position ? ret : ret + kag_size; ++} ++ ++static int is_pcm(enum CodecID codec_id) ++{ ++ /* we only care about "normal" PCM codecs until we get samples */ ++ return codec_id >= CODEC_ID_PCM_S16LE && codec_id < CODEC_ID_PCM_S24DAUD; ++} ++ ++/** ++ * Deals with the case where for some audio atoms EditUnitByteCount is very small (2, 4..). ++ * In those cases we should read more than one sample per call to mxf_read_packet(). ++ */ ++static void mxf_handle_small_eubc(AVFormatContext *s) ++{ ++ MXFContext *mxf = s->priv_data; ++ ++ /* assuming non-OPAtom == frame wrapped ++ * no sane writer would wrap 2 byte PCM packets with 20 byte headers.. */ ++ if (mxf->op != OPAtom) ++ return; ++ ++ /* expect PCM with exactly one index table segment and a small (< 32) EUBC */ ++ if (s->nb_streams != 1 || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO || ++ !is_pcm(s->streams[0]->codec->codec_id) || mxf->nb_index_tables != 1 || ++ mxf->index_tables[0].nb_segments != 1 || ++ mxf->index_tables[0].segments[0]->edit_unit_byte_count >= 32) ++ return; ++ ++ /* arbitrarily default to 48 kHz PAL audio frame size */ ++ /* TODO: we could compute this from the ratio between the audio and video edit rates ++ * for 48 kHz NTSC we could use the 1802-1802-1802-1802-1801 pattern */ ++ mxf->edit_units_per_packet = 1920; ++} ++ + static int mxf_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + MXFContext *mxf = s->priv_data; + KLVPacket klv; ++ int64_t essence_offset = 0; ++ int ret; ++ ++ mxf->last_forward_tell = INT64_MAX; ++ mxf->edit_units_per_packet = 1; + + if (!mxf_read_sync(s->pb, mxf_header_partition_pack_key, 14)) { + av_log(s, AV_LOG_ERROR, "could not find header partition pack key\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } +- url_fseek(s->pb, -14, SEEK_CUR); ++ avio_seek(s->pb, -14, SEEK_CUR); + mxf->fc = s; ++ mxf->run_in = avio_tell(s->pb); ++ + while (!url_feof(s->pb)) { + const MXFMetadataReadTableEntry *metadata; + +- if (klv_read_packet(&klv, s->pb) < 0) +- return -1; ++ if (klv_read_packet(&klv, s->pb) < 0) { ++ /* EOF - seek to previous partition or stop */ ++ if(mxf_parse_handle_partition_or_eof(mxf) <= 0) ++ break; ++ else ++ continue; ++ } ++ + PRINT_KEY(s, "read header", klv.key); +- av_dlog(s, "size %lld offset %#llx\n", klv.length, klv.offset); ++ av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); + if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key) || +- IS_KLV_KEY(klv.key, mxf_essence_element_key)) { +- /* FIXME avoid seek */ +- url_fseek(s->pb, klv.offset, SEEK_SET); +- break; ++ IS_KLV_KEY(klv.key, mxf_essence_element_key) || ++ IS_KLV_KEY(klv.key, mxf_avid_essence_element_key) || ++ IS_KLV_KEY(klv.key, mxf_system_item_key)) { ++ ++ if (!mxf->current_partition) { ++ av_log(mxf->fc, AV_LOG_ERROR, "found essence prior to first PartitionPack\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (!mxf->current_partition->essence_offset) { ++ /* for OP1a we compute essence_offset ++ * for OPAtom we point essence_offset after the KL (usually op1a_essence_offset + 20 or 25) ++ * TODO: for OP1a we could eliminate this entire if statement, always stopping parsing at op1a_essence_offset ++ * for OPAtom we still need the actual essence_offset though (the KL's length can vary) ++ */ ++ int64_t op1a_essence_offset = ++ round_to_kag(mxf->current_partition->this_partition + ++ mxf->current_partition->pack_length, mxf->current_partition->kag_size) + ++ round_to_kag(mxf->current_partition->header_byte_count, mxf->current_partition->kag_size) + ++ round_to_kag(mxf->current_partition->index_byte_count, mxf->current_partition->kag_size); ++ ++ if (mxf->op == OPAtom) { ++ /* point essence_offset to the actual data ++ * OPAtom has all the essence in one big KLV ++ */ ++ mxf->current_partition->essence_offset = avio_tell(s->pb); ++ mxf->current_partition->essence_length = klv.length; ++ } else { ++ /* NOTE: op1a_essence_offset may be less than to klv.offset (C0023S01.mxf) */ ++ mxf->current_partition->essence_offset = op1a_essence_offset; ++ } ++ } ++ ++ if (!essence_offset) ++ essence_offset = klv.offset; ++ ++ /* seek to footer, previous partition or stop */ ++ if (mxf_parse_handle_essence(mxf) <= 0) ++ break; ++ continue; ++ } else if (!memcmp(klv.key, mxf_header_partition_pack_key, 13) && ++ klv.key[13] >= 2 && klv.key[13] <= 4 && mxf->current_partition) { ++ /* next partition pack - keep going, seek to previous partition or stop */ ++ if(mxf_parse_handle_partition_or_eof(mxf) <= 0) ++ break; + } + + for (metadata = mxf_metadata_read_table; metadata->read; metadata++) { +@@ -933,24 +1732,210 @@ + int res; + if (klv.key[5] == 0x53) { + res = mxf_read_local_tags(mxf, &klv, metadata->read, metadata->ctx_size, metadata->type); +- } else +- res = metadata->read(mxf, s->pb, 0, 0, NULL); ++ } else { ++ uint64_t next = avio_tell(s->pb) + klv.length; ++ res = metadata->read(mxf, s->pb, 0, klv.length, klv.key, klv.offset); ++ ++ /* only seek forward, else this can loop for a long time */ ++ if (avio_tell(s->pb) > next) { ++ av_log(s, AV_LOG_ERROR, "read past end of KLV @ %#"PRIx64"\n", ++ klv.offset); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avio_seek(s->pb, next, SEEK_SET); ++ } + if (res < 0) { + av_log(s, AV_LOG_ERROR, "error reading header metadata\n"); +- return -1; ++ return res; + } + break; + } + } + if (!metadata->read) +- url_fskip(s->pb, klv.length); ++ avio_skip(s->pb, klv.length); ++ } ++ /* FIXME avoid seek */ ++ if (!essence_offset) { ++ av_log(s, AV_LOG_ERROR, "no essence\n"); ++ return AVERROR_INVALIDDATA; + } +- return mxf_parse_structural_metadata(mxf); ++ avio_seek(s->pb, essence_offset, SEEK_SET); ++ ++ mxf_compute_essence_containers(mxf); ++ ++ /* we need to do this before computing the index tables ++ * to be able to fill in zero IndexDurations with st->duration */ ++ if ((ret = mxf_parse_structural_metadata(mxf)) < 0) ++ return ret; ++ ++ if ((ret = mxf_compute_index_tables(mxf)) < 0) ++ return ret; ++ ++ if (mxf->nb_index_tables > 1) { ++ /* TODO: look up which IndexSID to use via EssenceContainerData */ ++ av_log(mxf->fc, AV_LOG_INFO, "got %i index tables - only the first one (IndexSID %i) will be used\n", ++ mxf->nb_index_tables, mxf->index_tables[0].index_sid); ++ } else if (mxf->nb_index_tables == 0 && mxf->op == OPAtom) { ++ av_log(mxf->fc, AV_LOG_ERROR, "cannot demux OPAtom without an index\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ mxf_handle_small_eubc(s); ++ ++ return 0; ++} ++ ++/** ++ * Computes DTS and PTS for the given video packet based on its offset. ++ */ ++static void mxf_packet_timestamps(MXFContext *mxf, AVPacket *pkt) ++{ ++ int64_t last_ofs = -1, next_ofs; ++ MXFIndexTable *t = &mxf->index_tables[0]; ++ ++ /* this is called from the OP1a demuxing logic, which means there may be no index tables */ ++ if (mxf->nb_index_tables <= 0) ++ return; ++ ++ /* find mxf->current_edit_unit so that the next edit unit starts ahead of pkt->pos */ ++ while (mxf->current_edit_unit >= 0) { ++ if (mxf_edit_unit_absolute_offset(mxf, t, mxf->current_edit_unit + 1, NULL, &next_ofs, 0) < 0) ++ break; ++ ++ if (next_ofs <= last_ofs) { ++ /* large next_ofs didn't change or current_edit_unit wrapped around ++ * this fixes the infinite loop on zzuf3.mxf */ ++ av_log(mxf->fc, AV_LOG_ERROR, "next_ofs didn't change. not deriving packet timestamps\n"); ++ return; ++ } ++ ++ if (next_ofs > pkt->pos) ++ break; ++ ++ last_ofs = next_ofs; ++ mxf->current_edit_unit++; ++ } ++ ++ if (mxf->current_edit_unit < 0 || mxf->current_edit_unit >= t->nb_ptses) ++ return; ++ ++ pkt->dts = mxf->current_edit_unit + t->first_dts; ++ pkt->pts = t->ptses[mxf->current_edit_unit]; ++} ++ ++static int mxf_read_packet_old(AVFormatContext *s, AVPacket *pkt) ++{ ++ KLVPacket klv; ++ ++ while (!url_feof(s->pb)) { ++ int ret; ++ if (klv_read_packet(&klv, s->pb) < 0) ++ return -1; ++ PRINT_KEY(s, "read packet", klv.key); ++ av_dlog(s, "size %"PRIu64" offset %#"PRIx64"\n", klv.length, klv.offset); ++ if (IS_KLV_KEY(klv.key, mxf_encrypted_triplet_key)) { ++ ret = mxf_decrypt_triplet(s, pkt, &klv); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "invalid encoded triplet\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ return 0; ++ } ++ if (IS_KLV_KEY(klv.key, mxf_essence_element_key) || ++ IS_KLV_KEY(klv.key, mxf_avid_essence_element_key)) { ++ int index = mxf_get_stream_index(s, &klv); ++ if (index < 0) { ++ av_log(s, AV_LOG_ERROR, "error getting stream index %d\n", AV_RB32(klv.key+12)); ++ goto skip; ++ } ++ if (s->streams[index]->discard == AVDISCARD_ALL) ++ goto skip; ++ /* check for 8 channels AES3 element */ ++ if (klv.key[12] == 0x06 && klv.key[13] == 0x01 && klv.key[14] == 0x10) { ++ if (mxf_get_d10_aes3_packet(s->pb, s->streams[index], pkt, klv.length) < 0) { ++ av_log(s, AV_LOG_ERROR, "error reading D-10 aes3 frame\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ } else { ++ ret = av_get_packet(s->pb, pkt, klv.length); ++ if (ret < 0) ++ return ret; ++ } ++ pkt->stream_index = index; ++ pkt->pos = klv.offset; ++ ++ if (s->streams[index]->codec->codec_type == AVMEDIA_TYPE_VIDEO) ++ mxf_packet_timestamps(s->priv_data, pkt); /* offset -> EditUnit -> DTS/PTS */ ++ ++ return 0; ++ } else ++ skip: ++ avio_skip(s->pb, klv.length); ++ } ++ return AVERROR_EOF; ++} ++ ++static int mxf_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ MXFContext *mxf = s->priv_data; ++ int ret, size; ++ int64_t ret64, pos, next_pos; ++ AVStream *st; ++ MXFIndexTable *t; ++ int edit_units; ++ ++ if (mxf->op != OPAtom) ++ return mxf_read_packet_old(s, pkt); ++ ++ /* OPAtom - clip wrapped demuxing */ ++ /* NOTE: mxf_read_header() makes sure nb_index_tables > 0 for OPAtom */ ++ st = s->streams[0]; ++ t = &mxf->index_tables[0]; ++ ++ if (mxf->current_edit_unit >= st->duration) ++ return AVERROR_EOF; ++ ++ edit_units = FFMIN(mxf->edit_units_per_packet, st->duration - mxf->current_edit_unit); ++ ++ if ((ret = mxf_edit_unit_absolute_offset(mxf, t, mxf->current_edit_unit, NULL, &pos, 1)) < 0) ++ return ret; ++ ++ /* compute size by finding the next edit unit or the end of the essence container ++ * not pretty, but it works */ ++ if ((ret = mxf_edit_unit_absolute_offset(mxf, t, mxf->current_edit_unit + edit_units, NULL, &next_pos, 0)) < 0 && ++ (next_pos = mxf_essence_container_end(mxf, t->body_sid)) <= 0) { ++ av_log(s, AV_LOG_ERROR, "unable to compute the size of the last packet\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((size = next_pos - pos) <= 0) { ++ av_log(s, AV_LOG_ERROR, "bad size: %i\n", size); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((ret64 = avio_seek(s->pb, pos, SEEK_SET)) < 0) ++ return ret64; ++ ++ if ((ret = av_get_packet(s->pb, pkt, size)) != size) ++ return ret < 0 ? ret : AVERROR_EOF; ++ ++ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && t->ptses && ++ mxf->current_edit_unit >= 0 && mxf->current_edit_unit < t->nb_ptses) { ++ pkt->dts = mxf->current_edit_unit + t->first_dts; ++ pkt->pts = t->ptses[mxf->current_edit_unit]; ++ } ++ ++ pkt->stream_index = 0; ++ mxf->current_edit_unit += edit_units; ++ ++ return 0; + } + + static int mxf_read_close(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; ++ MXFIndexTableSegment *seg; + int i; + + av_freep(&mxf->packages_refs); +@@ -970,14 +1955,29 @@ + case MaterialPackage: + av_freep(&((MXFPackage *)mxf->metadata_sets[i])->tracks_refs); + break; ++ case IndexTableSegment: ++ seg = (MXFIndexTableSegment *)mxf->metadata_sets[i]; ++ av_freep(&seg->temporal_offset_entries); ++ av_freep(&seg->flag_entries); ++ av_freep(&seg->stream_offset_entries); ++ break; + default: + break; + } + av_freep(&mxf->metadata_sets[i]); + } ++ av_freep(&mxf->partitions); + av_freep(&mxf->metadata_sets); + av_freep(&mxf->aesc); + av_freep(&mxf->local_tags); ++ ++ for (i = 0; i < mxf->nb_index_tables; i++) { ++ av_freep(&mxf->index_tables[i].segments); ++ av_freep(&mxf->index_tables[i].ptses); ++ av_freep(&mxf->index_tables[i].fake_index); ++ } ++ av_freep(&mxf->index_tables); ++ + return 0; + } + +@@ -1003,24 +2003,55 @@ + { + AVStream *st = s->streams[stream_index]; + int64_t seconds; ++ MXFContext* mxf = s->priv_data; ++ int64_t seekpos; ++ int ret; ++ MXFIndexTable *t; + ++ if (mxf->index_tables <= 0) { + if (!s->bit_rate) +- return -1; ++ return AVERROR_INVALIDDATA; + if (sample_time < 0) + sample_time = 0; + seconds = av_rescale(sample_time, st->time_base.num, st->time_base.den); +- url_fseek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET); +- av_update_cur_dts(s, st, sample_time); ++ ++ if ((ret = avio_seek(s->pb, (s->bit_rate * seconds) >> 3, SEEK_SET)) < 0) ++ return ret; ++ ff_update_cur_dts(s, st, sample_time); ++ } else { ++ t = &mxf->index_tables[0]; ++ ++ /* clamp above zero, else ff_index_search_timestamp() returns negative ++ * this also means we allow seeking before the start */ ++ sample_time = FFMAX(sample_time, 0); ++ ++ if (t->fake_index) { ++ /* behave as if we have a proper index */ ++ if ((sample_time = ff_index_search_timestamp(t->fake_index, t->nb_ptses, sample_time, flags)) < 0) ++ return sample_time; ++ } else { ++ /* no IndexEntryArray (one or more CBR segments) ++ * make sure we don't seek past the end */ ++ sample_time = FFMIN(sample_time, st->duration - 1); ++ } ++ ++ if ((ret = mxf_edit_unit_absolute_offset(mxf, t, sample_time, &sample_time, &seekpos, 1)) << 0) ++ return ret; ++ ++ ff_update_cur_dts(s, st, sample_time); ++ mxf->current_edit_unit = sample_time; ++ avio_seek(s->pb, seekpos, SEEK_SET); ++ } + return 0; + } + + AVInputFormat ff_mxf_demuxer = { +- "mxf", +- NULL_IF_CONFIG_SMALL("Material eXchange Format"), +- sizeof(MXFContext), +- mxf_probe, +- mxf_read_header, +- mxf_read_packet, +- mxf_read_close, +- mxf_read_seek, ++ .name = "mxf", ++ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"), ++ .priv_data_size = sizeof(MXFContext), ++ .read_probe = mxf_probe, ++ .read_header = mxf_read_header, ++ .read_packet = mxf_read_packet, ++ .read_close = mxf_read_close, ++ .read_seek = mxf_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxfenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxfenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxfenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxfenc.c 2012-05-14 14:08:55.085355097 +0200 +@@ -35,10 +35,13 @@ + #include + #include + ++#include "libavutil/opt.h" + #include "libavutil/random_seed.h" + #include "libavcodec/bytestream.h" ++#include "libavcodec/timecode.h" + #include "audiointerleave.h" + #include "avformat.h" ++#include "internal.h" + #include "mxf.h" + + static const int NTSC_samples_per_frame[] = { 1602, 1601, 1602, 1601, 1602, 0 }; +@@ -67,7 +70,7 @@ + int index; ///< index in mxf_essence_container_uls table + const UID *codec_ul; + int order; ///< interleaving order if dts are equal +- int interlaced; ///< wether picture is interlaced ++ int interlaced; ///< whether picture is interlaced + int temporal_reordering; + AVRational aspect_ratio; ///< display aspect ratio + int closed_gop; ///< gop is closed, used in mpeg-2 frame parsing +@@ -170,6 +173,7 @@ + }; + + typedef struct MXFContext { ++ AVClass *av_class; + int64_t footer_partition_offset; + int essence_container_count; + AVRational time_base; +@@ -183,10 +187,9 @@ + unsigned body_partitions_count; + int last_key_index; ///< index of last key frame + uint64_t duration; ++ struct ff_timecode tc; + AVStream *timecode_track; + int timecode_base; ///< rounded time code base (25 or 30) +- int timecode_start; ///< frame number computed from mpeg-2 gop header timecode +- int timecode_drop_frame; ///< time code use drop frame method frop mpeg-2 essence gop header + int edit_unit_byte_count; ///< fixed edit unit byte count + uint64_t body_offset; + uint32_t instance_number; +@@ -305,26 +308,26 @@ + { 0x3D0A, {0x06,0x0E,0x2B,0x34,0x01,0x01,0x01,0x05,0x04,0x02,0x03,0x02,0x01,0x00,0x00,0x00}}, /* Block Align */ + }; + +-static void mxf_write_uuid(ByteIOContext *pb, enum MXFMetadataSetType type, int value) ++static void mxf_write_uuid(AVIOContext *pb, enum MXFMetadataSetType type, int value) + { +- put_buffer(pb, uuid_base, 12); +- put_be16(pb, type); +- put_be16(pb, value); ++ avio_write(pb, uuid_base, 12); ++ avio_wb16(pb, type); ++ avio_wb16(pb, value); + } + + static void mxf_write_umid(AVFormatContext *s, int type) + { + MXFContext *mxf = s->priv_data; +- put_buffer(s->pb, umid_ul, 13); +- put_be24(s->pb, mxf->instance_number); +- put_buffer(s->pb, mxf->umid, 15); +- put_byte(s->pb, type); ++ avio_write(s->pb, umid_ul, 13); ++ avio_wb24(s->pb, mxf->instance_number); ++ avio_write(s->pb, mxf->umid, 15); ++ avio_w8(s->pb, type); + } + +-static void mxf_write_refs_count(ByteIOContext *pb, int ref_count) ++static void mxf_write_refs_count(AVIOContext *pb, int ref_count) + { +- put_be32(pb, ref_count); +- put_be32(pb, 16); ++ avio_wb32(pb, ref_count); ++ avio_wb32(pb, 16); + } + + static int klv_ber_length(uint64_t len) +@@ -335,31 +338,31 @@ + return (av_log2(len) >> 3) + 2; + } + +-static int klv_encode_ber_length(ByteIOContext *pb, uint64_t len) ++static int klv_encode_ber_length(AVIOContext *pb, uint64_t len) + { + // Determine the best BER size + int size; + if (len < 128) { + //short form +- put_byte(pb, len); ++ avio_w8(pb, len); + return 1; + } + + size = (av_log2(len) >> 3) + 1; + + // long form +- put_byte(pb, 0x80 + size); ++ avio_w8(pb, 0x80 + size); + while(size) { + size--; +- put_byte(pb, len >> 8 * size & 0xff); ++ avio_w8(pb, len >> 8 * size & 0xff); + } + return 0; + } + +-static void klv_encode_ber4_length(ByteIOContext *pb, int len) ++static void klv_encode_ber4_length(AVIOContext *pb, int len) + { +- put_byte(pb, 0x80 + 3); +- put_be24(pb, len); ++ avio_w8(pb, 0x80 + 3); ++ avio_wb24(pb, len); + } + + /* +@@ -376,33 +379,33 @@ + + static void mxf_write_primer_pack(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int local_tag_number, i = 0; + + local_tag_number = FF_ARRAY_ELEMS(mxf_local_tag_batch); + +- put_buffer(pb, primer_pack_key, 16); ++ avio_write(pb, primer_pack_key, 16); + klv_encode_ber_length(pb, local_tag_number * 18 + 8); + +- put_be32(pb, local_tag_number); // local_tag num +- put_be32(pb, 18); // item size, always 18 according to the specs ++ avio_wb32(pb, local_tag_number); // local_tag num ++ avio_wb32(pb, 18); // item size, always 18 according to the specs + + for (i = 0; i < local_tag_number; i++) { +- put_be16(pb, mxf_local_tag_batch[i].local_tag); +- put_buffer(pb, mxf_local_tag_batch[i].uid, 16); ++ avio_wb16(pb, mxf_local_tag_batch[i].local_tag); ++ avio_write(pb, mxf_local_tag_batch[i].uid, 16); + } + } + +-static void mxf_write_local_tag(ByteIOContext *pb, int size, int tag) ++static void mxf_write_local_tag(AVIOContext *pb, int size, int tag) + { +- put_be16(pb, tag); +- put_be16(pb, size); ++ avio_wb16(pb, tag); ++ avio_wb16(pb, size); + } + +-static void mxf_write_metadata_key(ByteIOContext *pb, unsigned int value) ++static void mxf_write_metadata_key(AVIOContext *pb, unsigned int value) + { +- put_buffer(pb, header_metadata_key, 13); +- put_be24(pb, value); ++ avio_write(pb, header_metadata_key, 13); ++ avio_wb24(pb, value); + } + + static void mxf_free(AVFormatContext *s) +@@ -429,21 +432,21 @@ + static void mxf_write_essence_container_refs(AVFormatContext *s) + { + MXFContext *c = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i; + + mxf_write_refs_count(pb, c->essence_container_count); + av_log(s,AV_LOG_DEBUG, "essence container count:%d\n", c->essence_container_count); + for (i = 0; i < c->essence_container_count; i++) { + MXFStreamContext *sc = s->streams[i]->priv_data; +- put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); ++ avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16); + } + } + + static void mxf_write_preface(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_metadata_key(pb, 0x012f00); + PRINT_KEY(s, "preface key", pb->buf_ptr - 16); +@@ -456,11 +459,11 @@ + + // last modified date + mxf_write_local_tag(pb, 8, 0x3B02); +- put_be64(pb, mxf->timestamp); ++ avio_wb64(pb, mxf->timestamp); + + // write version + mxf_write_local_tag(pb, 2, 0x3B05); +- put_be16(pb, 258); // v1.2 ++ avio_wb16(pb, 258); // v1.2 + + // write identification_refs + mxf_write_local_tag(pb, 16 + 8, 0x3B06); +@@ -473,7 +476,7 @@ + + // operational pattern + mxf_write_local_tag(pb, 16, 0x3B09); +- put_buffer(pb, op1a_ul, 16); ++ avio_write(pb, op1a_ul, 16); + + // write essence_container_refs + mxf_write_local_tag(pb, 8 + 16 * mxf->essence_container_count, 0x3B0A); +@@ -481,24 +484,24 @@ + + // write dm_scheme_refs + mxf_write_local_tag(pb, 8, 0x3B0B); +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + } + + /* + * Write a local tag containing an ascii string as utf-16 + */ +-static void mxf_write_local_tag_utf16(ByteIOContext *pb, int tag, const char *value) ++static void mxf_write_local_tag_utf16(AVIOContext *pb, int tag, const char *value) + { + int i, size = strlen(value); + mxf_write_local_tag(pb, size*2, tag); + for (i = 0; i < size; i++) +- put_be16(pb, value[i]); ++ avio_wb16(pb, value[i]); + } + + static void mxf_write_identification(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + const char *company = "FFmpeg"; + const char *product = "OP1a Muxer"; + const char *version; +@@ -531,12 +534,12 @@ + + // modification date + mxf_write_local_tag(pb, 8, 0x3C06); +- put_be64(pb, mxf->timestamp); ++ avio_wb64(pb, mxf->timestamp); + } + + static void mxf_write_content_storage(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_metadata_key(pb, 0x011800); + PRINT_KEY(s, "content storage key", pb->buf_ptr - 16); +@@ -562,7 +565,7 @@ + static void mxf_write_track(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + MXFStreamContext *sc = st->priv_data; + + mxf_write_metadata_key(pb, 0x013b00); +@@ -576,22 +579,22 @@ + + // write track id + mxf_write_local_tag(pb, 4, 0x4801); +- put_be32(pb, st->index+2); ++ avio_wb32(pb, st->index+2); + + // write track number + mxf_write_local_tag(pb, 4, 0x4804); + if (type == MaterialPackage) +- put_be32(pb, 0); // track number of material package is 0 ++ avio_wb32(pb, 0); // track number of material package is 0 + else +- put_buffer(pb, sc->track_essence_element_key + 12, 4); ++ avio_write(pb, sc->track_essence_element_key + 12, 4); + + mxf_write_local_tag(pb, 8, 0x4B01); +- put_be32(pb, mxf->time_base.den); +- put_be32(pb, mxf->time_base.num); ++ avio_wb32(pb, mxf->time_base.den); ++ avio_wb32(pb, mxf->time_base.num); + + // write origin + mxf_write_local_tag(pb, 8, 0x4B02); +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + + // write sequence refs + mxf_write_local_tag(pb, 16, 0x4803); +@@ -603,26 +606,26 @@ + static void mxf_write_common_fields(AVFormatContext *s, AVStream *st) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + // find data define uls + mxf_write_local_tag(pb, 16, 0x0201); + if (st == mxf->timecode_track) +- put_buffer(pb, smpte_12m_timecode_track_data_ul, 16); ++ avio_write(pb, smpte_12m_timecode_track_data_ul, 16); + else { + const MXFCodecUL *data_def_ul = mxf_get_data_definition_ul(st->codec->codec_type); +- put_buffer(pb, data_def_ul->uid, 16); ++ avio_write(pb, data_def_ul->uid, 16); + } + + // write duration + mxf_write_local_tag(pb, 8, 0x0202); +- put_be64(pb, mxf->duration); ++ avio_wb64(pb, mxf->duration); + } + + static void mxf_write_sequence(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + enum MXFMetadataSetType component; + + mxf_write_metadata_key(pb, 0x010f00); +@@ -650,7 +653,7 @@ + static void mxf_write_timecode_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_metadata_key(pb, 0x011400); + klv_encode_ber_length(pb, 75); +@@ -664,20 +667,20 @@ + + // Start Time Code + mxf_write_local_tag(pb, 8, 0x1501); +- put_be64(pb, mxf->timecode_start); ++ avio_wb64(pb, mxf->tc.start); + + // Rounded Time Code Base + mxf_write_local_tag(pb, 2, 0x1502); +- put_be16(pb, mxf->timecode_base); ++ avio_wb16(pb, mxf->timecode_base); + + // Drop Frame + mxf_write_local_tag(pb, 1, 0x1503); +- put_byte(pb, mxf->timecode_drop_frame); ++ avio_w8(pb, mxf->tc.drop); + } + + static void mxf_write_structural_component(AVFormatContext *s, AVStream *st, enum MXFMetadataSetType type) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i; + + mxf_write_metadata_key(pb, 0x011100); +@@ -693,28 +696,28 @@ + + // write start_position + mxf_write_local_tag(pb, 8, 0x1201); +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + + // write source package uid, end of the reference + mxf_write_local_tag(pb, 32, 0x1101); + if (type == SourcePackage) { + for (i = 0; i < 4; i++) +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + } else + mxf_write_umid(s, 1); + + // write source track id + mxf_write_local_tag(pb, 4, 0x1102); + if (type == SourcePackage) +- put_be32(pb, 0); ++ avio_wb32(pb, 0); + else +- put_be32(pb, st->index+2); ++ avio_wb32(pb, st->index+2); + } + + static void mxf_write_multi_descriptor(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + const uint8_t *ul; + int i; + +@@ -728,8 +731,8 @@ + + // write sample rate + mxf_write_local_tag(pb, 8, 0x3001); +- put_be32(pb, mxf->time_base.den); +- put_be32(pb, mxf->time_base.num); ++ avio_wb32(pb, mxf->time_base.den); ++ avio_wb32(pb, mxf->time_base.num); + + // write essence container ul + mxf_write_local_tag(pb, 16, 0x3004); +@@ -739,7 +742,7 @@ + MXFStreamContext *sc = s->streams[0]->priv_data; + ul = mxf_essence_container_uls[sc->index].container_ul; + } +- put_buffer(pb, ul, 16); ++ avio_write(pb, ul, 16); + + // write sub descriptor refs + mxf_write_local_tag(pb, s->nb_streams * 16 + 8, 0x3F01); +@@ -752,23 +755,23 @@ + { + MXFContext *mxf = s->priv_data; + MXFStreamContext *sc = st->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- put_buffer(pb, key, 16); ++ avio_write(pb, key, 16); + klv_encode_ber4_length(pb, size+20+8+12+20); + + mxf_write_local_tag(pb, 16, 0x3C0A); + mxf_write_uuid(pb, SubDescriptor, st->index); + + mxf_write_local_tag(pb, 4, 0x3006); +- put_be32(pb, st->index+2); ++ avio_wb32(pb, st->index+2); + + mxf_write_local_tag(pb, 8, 0x3001); +- put_be32(pb, mxf->time_base.den); +- put_be32(pb, mxf->time_base.num); ++ avio_wb32(pb, mxf->time_base.den); ++ avio_wb32(pb, mxf->time_base.num); + + mxf_write_local_tag(pb, 16, 0x3004); +- put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); ++ avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16); + } + + static const UID mxf_mpegvideo_descriptor_key = { 0x06,0x0E,0x2B,0x34,0x02,0x53,0x01,0x01,0x0d,0x01,0x01,0x01,0x01,0x01,0x51,0x00 }; +@@ -780,7 +783,7 @@ + static void mxf_write_cdci_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) + { + MXFStreamContext *sc = st->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int stored_height = (st->codec->height+15)/16*16; + int display_height; + int f1, f2; +@@ -788,13 +791,13 @@ + mxf_write_generic_desc(s, st, key, size+8+8+8+8+8+8+5+16+sc->interlaced*4+12+20); + + mxf_write_local_tag(pb, 4, 0x3203); +- put_be32(pb, st->codec->width); ++ avio_wb32(pb, st->codec->width); + + mxf_write_local_tag(pb, 4, 0x3202); +- put_be32(pb, stored_height>>sc->interlaced); ++ avio_wb32(pb, stored_height>>sc->interlaced); + + mxf_write_local_tag(pb, 4, 0x3209); +- put_be32(pb, st->codec->width); ++ avio_wb32(pb, st->codec->width); + + if (st->codec->height == 608) // PAL + VBI + display_height = 576; +@@ -804,19 +807,19 @@ + display_height = st->codec->height; + + mxf_write_local_tag(pb, 4, 0x3208); +- put_be32(pb, display_height>>sc->interlaced); ++ avio_wb32(pb, display_height>>sc->interlaced); + + // component depth + mxf_write_local_tag(pb, 4, 0x3301); +- put_be32(pb, 8); ++ avio_wb32(pb, 8); + + // horizontal subsampling + mxf_write_local_tag(pb, 4, 0x3302); +- put_be32(pb, 2); ++ avio_wb32(pb, 2); + + // frame layout + mxf_write_local_tag(pb, 1, 0x320C); +- put_byte(pb, sc->interlaced); ++ avio_w8(pb, sc->interlaced); + + // video line map + switch (st->codec->height) { +@@ -835,18 +838,18 @@ + } + + mxf_write_local_tag(pb, 12+sc->interlaced*4, 0x320D); +- put_be32(pb, sc->interlaced ? 2 : 1); +- put_be32(pb, 4); +- put_be32(pb, f1); ++ avio_wb32(pb, sc->interlaced ? 2 : 1); ++ avio_wb32(pb, 4); ++ avio_wb32(pb, f1); + if (sc->interlaced) +- put_be32(pb, f2); ++ avio_wb32(pb, f2); + + mxf_write_local_tag(pb, 8, 0x320E); +- put_be32(pb, sc->aspect_ratio.num); +- put_be32(pb, sc->aspect_ratio.den); ++ avio_wb32(pb, sc->aspect_ratio.num); ++ avio_wb32(pb, sc->aspect_ratio.den); + + mxf_write_local_tag(pb, 16, 0x3201); +- put_buffer(pb, *sc->codec_ul, 16); ++ avio_write(pb, *sc->codec_ul, 16); + } + + static void mxf_write_cdci_desc(AVFormatContext *s, AVStream *st) +@@ -856,56 +859,56 @@ + + static void mxf_write_mpegvideo_desc(AVFormatContext *s, AVStream *st) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int profile_and_level = (st->codec->profile<<4) | st->codec->level; + + mxf_write_cdci_common(s, st, mxf_mpegvideo_descriptor_key, 8+5); + + // bit rate + mxf_write_local_tag(pb, 4, 0x8000); +- put_be32(pb, st->codec->bit_rate); ++ avio_wb32(pb, st->codec->bit_rate); + + // profile and level + mxf_write_local_tag(pb, 1, 0x8007); + if (!st->codec->profile) + profile_and_level |= 0x80; // escape bit +- put_byte(pb, profile_and_level); ++ avio_w8(pb, profile_and_level); + } + + static void mxf_write_generic_sound_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_generic_desc(s, st, key, size+5+12+8+8); + + // audio locked + mxf_write_local_tag(pb, 1, 0x3D02); +- put_byte(pb, 1); ++ avio_w8(pb, 1); + + // write audio sampling rate + mxf_write_local_tag(pb, 8, 0x3D03); +- put_be32(pb, st->codec->sample_rate); +- put_be32(pb, 1); ++ avio_wb32(pb, st->codec->sample_rate); ++ avio_wb32(pb, 1); + + mxf_write_local_tag(pb, 4, 0x3D07); +- put_be32(pb, st->codec->channels); ++ avio_wb32(pb, st->codec->channels); + + mxf_write_local_tag(pb, 4, 0x3D01); +- put_be32(pb, av_get_bits_per_sample(st->codec->codec_id)); ++ avio_wb32(pb, av_get_bits_per_sample(st->codec->codec_id)); + } + + static void mxf_write_wav_common(AVFormatContext *s, AVStream *st, const UID key, unsigned size) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_generic_sound_common(s, st, key, size+6+8); + + mxf_write_local_tag(pb, 2, 0x3D0A); +- put_be16(pb, st->codec->block_align); ++ avio_wb16(pb, st->codec->block_align); + + // avg bytes per sec + mxf_write_local_tag(pb, 4, 0x3D09); +- put_be32(pb, st->codec->block_align*st->codec->sample_rate); ++ avio_wb32(pb, st->codec->block_align*st->codec->sample_rate); + } + + static void mxf_write_wav_desc(AVFormatContext *s, AVStream *st) +@@ -926,7 +929,7 @@ + static void mxf_write_package(AVFormatContext *s, enum MXFMetadataSetType type) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i, track_count = s->nb_streams+1; + + if (type == MaterialPackage) { +@@ -952,11 +955,11 @@ + + // package creation date + mxf_write_local_tag(pb, 8, 0x4405); +- put_be64(pb, mxf->timestamp); ++ avio_wb64(pb, mxf->timestamp); + + // package modified date + mxf_write_local_tag(pb, 8, 0x4404); +- put_be64(pb, mxf->timestamp); ++ avio_wb64(pb, mxf->timestamp); + + // write track refs + mxf_write_local_tag(pb, track_count*16 + 8, 0x4403); +@@ -996,7 +999,7 @@ + + static int mxf_write_essence_container_data(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf_write_metadata_key(pb, 0x012300); + klv_encode_ber_length(pb, 72); +@@ -1008,10 +1011,10 @@ + mxf_write_umid(s, 1); + + mxf_write_local_tag(pb, 4, 0x3F07); // BodySID +- put_be32(pb, 1); ++ avio_wb32(pb, 1); + + mxf_write_local_tag(pb, 4, 0x3F06); // IndexSID +- put_be32(pb, 2); ++ avio_wb32(pb, 2); + + return 0; + } +@@ -1039,7 +1042,7 @@ + static void mxf_write_index_table_segment(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int i, j, temporal_reordering = 0; + int key_index = mxf->last_key_index; + +@@ -1048,7 +1051,7 @@ + if (!mxf->edit_units_count && !mxf->edit_unit_byte_count) + return; + +- put_buffer(pb, index_table_segment_key, 16); ++ avio_write(pb, index_table_segment_key, 16); + + if (mxf->edit_unit_byte_count) { + klv_encode_ber_length(pb, 80); +@@ -1063,65 +1066,65 @@ + + // index edit rate + mxf_write_local_tag(pb, 8, 0x3F0B); +- put_be32(pb, mxf->time_base.den); +- put_be32(pb, mxf->time_base.num); ++ avio_wb32(pb, mxf->time_base.den); ++ avio_wb32(pb, mxf->time_base.num); + + // index start position + mxf_write_local_tag(pb, 8, 0x3F0C); +- put_be64(pb, mxf->last_indexed_edit_unit); ++ avio_wb64(pb, mxf->last_indexed_edit_unit); + + // index duration + mxf_write_local_tag(pb, 8, 0x3F0D); + if (mxf->edit_unit_byte_count) +- put_be64(pb, 0); // index table covers whole container ++ avio_wb64(pb, 0); // index table covers whole container + else +- put_be64(pb, mxf->edit_units_count); ++ avio_wb64(pb, mxf->edit_units_count); + + // edit unit byte count + mxf_write_local_tag(pb, 4, 0x3F05); +- put_be32(pb, mxf->edit_unit_byte_count); ++ avio_wb32(pb, mxf->edit_unit_byte_count); + + // index sid + mxf_write_local_tag(pb, 4, 0x3F06); +- put_be32(pb, 2); ++ avio_wb32(pb, 2); + + // body sid + mxf_write_local_tag(pb, 4, 0x3F07); +- put_be32(pb, 1); ++ avio_wb32(pb, 1); + + if (!mxf->edit_unit_byte_count) { + // real slice count - 1 + mxf_write_local_tag(pb, 1, 0x3F08); +- put_byte(pb, mxf->slice_count); ++ avio_w8(pb, mxf->slice_count); + + // delta entry array + mxf_write_local_tag(pb, 8 + (s->nb_streams+1)*6, 0x3F09); +- put_be32(pb, s->nb_streams+1); // num of entries +- put_be32(pb, 6); // size of one entry ++ avio_wb32(pb, s->nb_streams+1); // num of entries ++ avio_wb32(pb, 6); // size of one entry + // write system item delta entry +- put_byte(pb, 0); +- put_byte(pb, 0); // slice entry +- put_be32(pb, 0); // element delta ++ avio_w8(pb, 0); ++ avio_w8(pb, 0); // slice entry ++ avio_wb32(pb, 0); // element delta + for (i = 0; i < s->nb_streams; i++) { + AVStream *st = s->streams[i]; + MXFStreamContext *sc = st->priv_data; +- put_byte(pb, sc->temporal_reordering); ++ avio_w8(pb, sc->temporal_reordering); + if (sc->temporal_reordering) + temporal_reordering = 1; + if (i == 0) { // video track +- put_byte(pb, 0); // slice number +- put_be32(pb, KAG_SIZE); // system item size including klv fill ++ avio_w8(pb, 0); // slice number ++ avio_wb32(pb, KAG_SIZE); // system item size including klv fill + } else { // audio track + unsigned audio_frame_size = sc->aic.samples[0]*sc->aic.sample_size; + audio_frame_size += klv_fill_size(audio_frame_size); +- put_byte(pb, 1); +- put_be32(pb, (i-1)*audio_frame_size); // element delta ++ avio_w8(pb, 1); ++ avio_wb32(pb, (i-1)*audio_frame_size); // element delta + } + } + + mxf_write_local_tag(pb, 8 + mxf->edit_units_count*(11+mxf->slice_count*4), 0x3F0A); +- put_be32(pb, mxf->edit_units_count); // num of entries +- put_be32(pb, 11+mxf->slice_count*4); // size of one entry ++ avio_wb32(pb, mxf->edit_units_count); // num of entries ++ avio_wb32(pb, 11+mxf->slice_count*4); // size of one entry + + for (i = 0; i < mxf->edit_units_count; i++) { + int temporal_offset = 0; +@@ -1143,12 +1146,12 @@ + temporal_offset = j - key_index - pic_num_in_gop; + } + } +- put_byte(pb, temporal_offset); ++ avio_w8(pb, temporal_offset); + + if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction +- put_byte(pb, mxf->last_key_index - i); ++ avio_w8(pb, mxf->last_key_index - i); + } else { +- put_byte(pb, key_index - i); // key frame offset ++ avio_w8(pb, key_index - i); // key frame offset + if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward + mxf->last_key_index = key_index; + } +@@ -1156,11 +1159,11 @@ + if (!(mxf->index_entries[i].flags & 0x33) && // I frame + mxf->index_entries[i].flags & 0x40 && !temporal_offset) + mxf->index_entries[i].flags |= 0x80; // random access +- put_byte(pb, mxf->index_entries[i].flags); ++ avio_w8(pb, mxf->index_entries[i].flags); + // stream offset +- put_be64(pb, mxf->index_entries[i].offset); ++ avio_wb64(pb, mxf->index_entries[i].offset); + if (s->nb_streams > 1) +- put_be32(pb, mxf->index_entries[i].slice_offset); ++ avio_wb32(pb, mxf->index_entries[i].slice_offset); + } + + mxf->last_key_index = key_index - mxf->edit_units_count; +@@ -1171,14 +1174,14 @@ + + static void mxf_write_klv_fill(AVFormatContext *s) + { +- unsigned pad = klv_fill_size(url_ftell(s->pb)); ++ unsigned pad = klv_fill_size(avio_tell(s->pb)); + if (pad) { +- put_buffer(s->pb, klv_fill_key, 16); ++ avio_write(s->pb, klv_fill_key, 16); + pad -= 16 + 4; + klv_encode_ber4_length(s->pb, pad); + for (; pad; pad--) +- put_byte(s->pb, 0); +- assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); ++ avio_w8(s->pb, 0); ++ assert(!(avio_tell(s->pb) & (KAG_SIZE-1))); + } + } + +@@ -1187,10 +1190,10 @@ + const uint8_t *key, int write_metadata) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t header_byte_count_offset; + unsigned index_byte_count = 0; +- uint64_t partition_offset = url_ftell(pb); ++ uint64_t partition_offset = avio_tell(pb); + + if (!mxf->edit_unit_byte_count && mxf->edit_units_count) + index_byte_count = 85 + 12+(s->nb_streams+1)*6 + +@@ -1213,43 +1216,43 @@ + } + + // write klv +- put_buffer(pb, key, 16); ++ avio_write(pb, key, 16); + klv_encode_ber_length(pb, 88 + 16 * mxf->essence_container_count); + + // write partition value +- put_be16(pb, 1); // majorVersion +- put_be16(pb, 2); // minorVersion +- put_be32(pb, KAG_SIZE); // KAGSize ++ avio_wb16(pb, 1); // majorVersion ++ avio_wb16(pb, 2); // minorVersion ++ avio_wb32(pb, KAG_SIZE); // KAGSize + +- put_be64(pb, partition_offset); // ThisPartition ++ avio_wb64(pb, partition_offset); // ThisPartition + + if (!memcmp(key, body_partition_key, 16) && mxf->body_partitions_count > 1) +- put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition ++ avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-2]); // PreviousPartition + else if (!memcmp(key, footer_partition_key, 16) && mxf->body_partitions_count) +- put_be64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition ++ avio_wb64(pb, mxf->body_partition_offset[mxf->body_partitions_count-1]); // PreviousPartition + else +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + +- put_be64(pb, mxf->footer_partition_offset); // footerPartition ++ avio_wb64(pb, mxf->footer_partition_offset); // footerPartition + + // set offset +- header_byte_count_offset = url_ftell(pb); +- put_be64(pb, 0); // headerByteCount, update later ++ header_byte_count_offset = avio_tell(pb); ++ avio_wb64(pb, 0); // headerByteCount, update later + + // indexTable +- put_be64(pb, index_byte_count); // indexByteCount +- put_be32(pb, index_byte_count ? indexsid : 0); // indexSID ++ avio_wb64(pb, index_byte_count); // indexByteCount ++ avio_wb32(pb, index_byte_count ? indexsid : 0); // indexSID + + // BodyOffset + if (bodysid && mxf->edit_units_count && mxf->body_partitions_count) { +- put_be64(pb, mxf->body_offset); ++ avio_wb64(pb, mxf->body_offset); + } else +- put_be64(pb, 0); ++ avio_wb64(pb, 0); + +- put_be32(pb, bodysid); // bodySID ++ avio_wb32(pb, bodysid); // bodySID + + // operational pattern +- put_buffer(pb, op1a_ul, 16); ++ avio_write(pb, op1a_ul, 16); + + // essence container + mxf_write_essence_container_refs(s); +@@ -1260,19 +1263,19 @@ + unsigned header_byte_count; + + mxf_write_klv_fill(s); +- start = url_ftell(s->pb); ++ start = avio_tell(s->pb); + mxf_write_primer_pack(s); + mxf_write_header_metadata_sets(s); +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + header_byte_count = pos - start + klv_fill_size(pos); + + // update header_byte_count +- url_fseek(pb, header_byte_count_offset, SEEK_SET); +- put_be64(pb, header_byte_count); +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, header_byte_count_offset, SEEK_SET); ++ avio_wb64(pb, header_byte_count); ++ avio_seek(pb, pos, SEEK_SET); + } + +- put_flush_packet(pb); ++ avio_flush(pb); + } + + static const UID mxf_mpeg2_codec_uls[] = { +@@ -1284,6 +1287,8 @@ + { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x03,0x03,0x00 }, // MP-HL Long GOP + { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x02,0x00 }, // 422P-HL I-Frame + { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x04,0x03,0x00 }, // 422P-HL Long GOP ++ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x02,0x00 }, // MP@H-14 I-Frame ++ { 0x06,0x0E,0x2B,0x34,0x04,0x01,0x01,0x03,0x04,0x01,0x02,0x02,0x01,0x05,0x03,0x00 }, // MP@H-14 Long GOP + }; + + static const UID *mxf_get_mpeg2_codec_ul(AVCodecContext *avctx) +@@ -1295,6 +1300,8 @@ + return &mxf_mpeg2_codec_uls[0+long_gop]; + else if (avctx->level == 4) // High + return &mxf_mpeg2_codec_uls[4+long_gop]; ++ else if (avctx->level == 6) // High 14 ++ return &mxf_mpeg2_codec_uls[8+long_gop]; + } else if (avctx->profile == 0) { // 422 + if (avctx->level == 5) // Main + return &mxf_mpeg2_codec_uls[2+long_gop]; +@@ -1308,7 +1315,6 @@ + AVPacket *pkt, MXFIndexEntry *e) + { + MXFStreamContext *sc = st->priv_data; +- MXFContext *mxf = s->priv_data; + uint32_t c = -1; + int i; + +@@ -1328,21 +1334,6 @@ + if (e->flags & 0x40) // sequence header present + e->flags |= 0x80; // random access + } +- if (!mxf->header_written) { +- unsigned hours = (pkt->data[i+1]>>2) & 0x1f; +- unsigned minutes = ((pkt->data[i+1] & 0x03) << 4) | (pkt->data[i+2]>>4); +- unsigned seconds = ((pkt->data[i+2] & 0x07) << 3) | (pkt->data[i+3]>>5); +- unsigned frames = ((pkt->data[i+3] & 0x1f) << 1) | (pkt->data[i+4]>>7); +- mxf->timecode_drop_frame = !!(pkt->data[i+1] & 0x80); +- mxf->timecode_start = (hours*3600 + minutes*60 + seconds) * +- mxf->timecode_base + frames; +- if (mxf->timecode_drop_frame) { +- unsigned tminutes = 60 * hours + minutes; +- mxf->timecode_start -= 2 * (tminutes - tminutes / 10); +- } +- av_log(s, AV_LOG_DEBUG, "frame %d %d:%d:%d%c%d\n", mxf->timecode_start, +- hours, minutes, seconds, mxf->timecode_drop_frame ? ';':':', frames); +- } + } else if (c == 0x1b3) { // seq + e->flags |= 0x40; + switch ((pkt->data[i+4]>>4) & 0xf) { +@@ -1407,6 +1398,8 @@ + int i; + uint8_t present[FF_ARRAY_ELEMS(mxf_essence_container_uls)] = {0}; + const int *samples_per_frame = NULL; ++ AVDictionaryEntry *t; ++ int64_t timestamp = 0; + + if (!s->nb_streams) + return -1; +@@ -1435,7 +1428,13 @@ + av_log(s, AV_LOG_ERROR, "unsupported video frame rate\n"); + return -1; + } +- av_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); ++ avpriv_set_pts_info(st, 64, mxf->time_base.num, mxf->time_base.den); ++ if (mxf->tc.str) { ++ mxf->tc.rate.num = mxf->time_base.den; ++ mxf->tc.rate.den = mxf->time_base.num; ++ if (avpriv_init_smpte_timecode(s, &mxf->tc) < 0) ++ return -1; ++ } + if (s->oformat == &ff_mxf_d10_muxer) { + if (st->codec->bit_rate == 50000000) + if (mxf->time_base.den == 25) sc->index = 3; +@@ -1463,7 +1462,7 @@ + av_log(s, AV_LOG_ERROR, "only 48khz is implemented\n"); + return -1; + } +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + if (s->oformat == &ff_mxf_d10_muxer) { + if (st->index != 1) { + av_log(s, AV_LOG_ERROR, "MXF D-10 only support one audio track\n"); +@@ -1512,8 +1511,15 @@ + sc->order = AV_RB32(sc->track_essence_element_key+12); + } + ++#if FF_API_TIMESTAMP + if (s->timestamp) +- mxf->timestamp = mxf_parse_timestamp(s->timestamp); ++ timestamp = s->timestamp; ++ else ++#endif ++ if (t = av_dict_get(s->metadata, "creation_time", NULL, 0)) ++ timestamp = ff_iso8601_to_unix_time(t->value); ++ if (timestamp) ++ mxf->timestamp = mxf_parse_timestamp(timestamp); + mxf->duration = -1; + + mxf->timecode_track = av_mallocz(sizeof(*mxf->timecode_track)); +@@ -1536,69 +1542,55 @@ + static const uint8_t system_metadata_pack_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x05,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x01,0x00 }; + static const uint8_t system_metadata_package_set_key[] = { 0x06,0x0E,0x2B,0x34,0x02,0x43,0x01,0x01,0x0D,0x01,0x03,0x01,0x04,0x01,0x02,0x01 }; + +-static uint32_t ff_framenum_to_12m_time_code(unsigned frame, int drop, int fps) +-{ +- return (0 << 31) | // color frame flag +- (0 << 30) | // drop frame flag +- ( ((frame % fps) / 10) << 28) | // tens of frames +- ( ((frame % fps) % 10) << 24) | // units of frames +- (0 << 23) | // field phase (NTSC), b0 (PAL) +- ((((frame / fps) % 60) / 10) << 20) | // tens of seconds +- ((((frame / fps) % 60) % 10) << 16) | // units of seconds +- (0 << 15) | // b0 (NTSC), b2 (PAL) +- ((((frame / (fps * 60)) % 60) / 10) << 12) | // tens of minutes +- ((((frame / (fps * 60)) % 60) % 10) << 8) | // units of minutes +- (0 << 7) | // b1 +- (0 << 6) | // b2 (NSC), field phase (PAL) +- ((((frame / (fps * 3600) % 24)) / 10) << 4) | // tens of hours +- ( (frame / (fps * 3600) % 24)) % 10; // units of hours +-} +- + static void mxf_write_system_item(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned frame; + uint32_t time_code; + +- frame = mxf->timecode_start + mxf->last_indexed_edit_unit + mxf->edit_units_count; ++ frame = mxf->tc.start + mxf->last_indexed_edit_unit + mxf->edit_units_count; + + // write system metadata pack +- put_buffer(pb, system_metadata_pack_key, 16); ++ avio_write(pb, system_metadata_pack_key, 16); + klv_encode_ber4_length(pb, 57); +- put_byte(pb, 0x5c); // UL, user date/time stamp, picture and sound item present +- put_byte(pb, 0x04); // content package rate +- put_byte(pb, 0x00); // content package type +- put_be16(pb, 0x00); // channel handle +- put_be16(pb, frame); // continuity count ++ avio_w8(pb, 0x5c); // UL, user date/time stamp, picture and sound item present ++ avio_w8(pb, 0x04); // content package rate ++ avio_w8(pb, 0x00); // content package type ++ avio_wb16(pb, 0x00); // channel handle ++ avio_wb16(pb, frame); // continuity count + if (mxf->essence_container_count > 1) +- put_buffer(pb, multiple_desc_ul, 16); ++ avio_write(pb, multiple_desc_ul, 16); + else { + MXFStreamContext *sc = s->streams[0]->priv_data; +- put_buffer(pb, mxf_essence_container_uls[sc->index].container_ul, 16); ++ avio_write(pb, mxf_essence_container_uls[sc->index].container_ul, 16); + } +- put_byte(pb, 0); +- put_be64(pb, 0); +- put_be64(pb, 0); // creation date/time stamp +- +- put_byte(pb, 0x81); // SMPTE 12M time code +- time_code = ff_framenum_to_12m_time_code(frame, mxf->timecode_drop_frame, mxf->timecode_base); +- put_be32(pb, time_code); +- put_be32(pb, 0); // binary group data +- put_be64(pb, 0); ++ avio_w8(pb, 0); ++ avio_wb64(pb, 0); ++ avio_wb64(pb, 0); // creation date/time stamp ++ ++ avio_w8(pb, 0x81); // SMPTE 12M time code ++ time_code = frame; ++ if (mxf->tc.drop) ++ time_code = avpriv_framenum_to_drop_timecode(time_code); ++ time_code = avpriv_framenum_to_smpte_timecode(time_code, mxf->timecode_base, ++ mxf->tc.drop); ++ avio_wb32(pb, time_code); ++ avio_wb32(pb, 0); // binary group data ++ avio_wb64(pb, 0); + + // write system metadata package set +- put_buffer(pb, system_metadata_package_set_key, 16); ++ avio_write(pb, system_metadata_package_set_key, 16); + klv_encode_ber4_length(pb, 35); +- put_byte(pb, 0x83); // UMID +- put_be16(pb, 0x20); ++ avio_w8(pb, 0x83); // UMID ++ avio_wb16(pb, 0x20); + mxf_write_umid(s, 1); + } + + static void mxf_write_d10_video_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int packet_size = (uint64_t)st->codec->bit_rate*mxf->time_base.num / + (8*mxf->time_base.den); // frame size + int pad; +@@ -1607,28 +1599,28 @@ + packet_size += klv_fill_size(packet_size); + + klv_encode_ber4_length(pb, pkt->size); +- put_buffer(pb, pkt->data, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); + + // ensure CBR muxing by padding to correct video frame size + pad = packet_size - pkt->size - 16 - 4; + if (pad > 20) { +- put_buffer(s->pb, klv_fill_key, 16); ++ avio_write(s->pb, klv_fill_key, 16); + pad -= 16 + 4; + klv_encode_ber4_length(s->pb, pad); + for (; pad; pad--) +- put_byte(s->pb, 0); +- assert(!(url_ftell(s->pb) & (KAG_SIZE-1))); ++ avio_w8(s->pb, 0); ++ assert(!(avio_tell(s->pb) & (KAG_SIZE-1))); + } else { + av_log(s, AV_LOG_WARNING, "cannot fill d-10 video packet\n"); + for (; pad > 0; pad--) +- put_byte(s->pb, 0); ++ avio_w8(s->pb, 0); + } + } + + static void mxf_write_d10_audio_packet(AVFormatContext *s, AVStream *st, AVPacket *pkt) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int frame_size = pkt->size / st->codec->block_align; + uint8_t *samples = pkt->data; + uint8_t *end = pkt->data + pkt->size; +@@ -1636,9 +1628,9 @@ + + klv_encode_ber4_length(pb, 4 + frame_size*4*8); + +- put_byte(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); +- put_le16(pb, frame_size); +- put_byte(pb, (1<codec->channels)-1); ++ avio_w8(pb, (frame_size == 1920 ? 0 : (mxf->edit_units_count-1) % 5 + 1)); ++ avio_wl16(pb, frame_size); ++ avio_w8(pb, (1<codec->channels)-1); + + while (samples < end) { + for (i = 0; i < st->codec->channels; i++) { +@@ -1650,17 +1642,17 @@ + sample = AV_RL16(samples)<<12; + samples += 2; + } +- put_le32(pb, sample | i); ++ avio_wl32(pb, sample | i); + } + for (; i < 8; i++) +- put_le32(pb, i); ++ avio_wl32(pb, i); + } + } + + static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = s->streams[pkt->stream_index]; + MXFStreamContext *sc = st->priv_data; + MXFIndexEntry ie = {0}; +@@ -1719,7 +1711,7 @@ + } + + mxf_write_klv_fill(s); +- put_buffer(pb, sc->track_essence_element_key, 16); // write key ++ avio_write(pb, sc->track_essence_element_key, 16); // write key + if (s->oformat == &ff_mxf_d10_muxer) { + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + mxf_write_d10_video_packet(s, st, pkt); +@@ -1727,11 +1719,11 @@ + mxf_write_d10_audio_packet(s, st, pkt); + } else { + klv_encode_ber4_length(pb, pkt->size); // write length +- put_buffer(pb, pkt->data, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); + mxf->body_offset += 16+4+pkt->size + klv_fill_size(16+4+pkt->size); + } + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } +@@ -1739,39 +1731,39 @@ + static void mxf_write_random_index_pack(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; +- uint64_t pos = url_ftell(pb); ++ AVIOContext *pb = s->pb; ++ uint64_t pos = avio_tell(pb); + int i; + +- put_buffer(pb, random_index_pack_key, 16); ++ avio_write(pb, random_index_pack_key, 16); + klv_encode_ber_length(pb, 28 + 12*mxf->body_partitions_count); + + if (mxf->edit_unit_byte_count) +- put_be32(pb, 1); // BodySID of header partition ++ avio_wb32(pb, 1); // BodySID of header partition + else +- put_be32(pb, 0); +- put_be64(pb, 0); // offset of header partition ++ avio_wb32(pb, 0); ++ avio_wb64(pb, 0); // offset of header partition + + for (i = 0; i < mxf->body_partitions_count; i++) { +- put_be32(pb, 1); // BodySID +- put_be64(pb, mxf->body_partition_offset[i]); ++ avio_wb32(pb, 1); // BodySID ++ avio_wb64(pb, mxf->body_partition_offset[i]); + } + +- put_be32(pb, 0); // BodySID of footer partition +- put_be64(pb, mxf->footer_partition_offset); ++ avio_wb32(pb, 0); // BodySID of footer partition ++ avio_wb64(pb, mxf->footer_partition_offset); + +- put_be32(pb, url_ftell(pb) - pos + 4); ++ avio_wb32(pb, avio_tell(pb) - pos + 4); + } + + static int mxf_write_footer(AVFormatContext *s) + { + MXFContext *mxf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + mxf->duration = mxf->last_indexed_edit_unit + mxf->edit_units_count; + + mxf_write_klv_fill(s); +- mxf->footer_partition_offset = url_ftell(pb); ++ mxf->footer_partition_offset = avio_tell(pb); + if (mxf->edit_unit_byte_count) { // no need to repeat index + mxf_write_partition(s, 0, 0, footer_partition_key, 0); + } else { +@@ -1784,8 +1776,8 @@ + mxf_write_klv_fill(s); + mxf_write_random_index_pack(s); + +- if (!url_is_streamed(s->pb)) { +- url_fseek(pb, 0, SEEK_SET); ++ if (s->pb->seekable) { ++ avio_seek(pb, 0, SEEK_SET); + if (mxf->edit_unit_byte_count) { + mxf_write_partition(s, 1, 2, header_closed_partition_key, 1); + mxf_write_klv_fill(s); +@@ -1795,7 +1787,7 @@ + } + } + +- put_flush_packet(pb); ++ avio_flush(pb); + + ff_audio_interleave_close(s); + +@@ -1879,34 +1871,53 @@ + mxf_interleave_get_packet, mxf_compare_timestamps); + } + ++static const AVClass mxf_class = { ++ .class_name = "mxf", ++ .item_name = av_default_item_name, ++ .version = LIBAVUTIL_VERSION_INT, ++ .option = (const AVOption[]){ ++ {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)}, ++ {NULL} ++ }, ++}; ++ ++static const AVClass mxf_d10_class = { ++ .class_name = "mxf_d10", ++ .item_name = av_default_item_name, ++ .version = LIBAVUTIL_VERSION_INT, ++ .option = (const AVOption[]){ ++ {TIMECODE_OPT(MXFContext, AV_OPT_FLAG_ENCODING_PARAM)}, ++ {NULL} ++ }, ++}; ++ + AVOutputFormat ff_mxf_muxer = { +- "mxf", +- NULL_IF_CONFIG_SMALL("Material eXchange Format"), +- "application/mxf", +- "mxf", +- sizeof(MXFContext), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_MPEG2VIDEO, +- mxf_write_header, +- mxf_write_packet, +- mxf_write_footer, +- AVFMT_NOTIMESTAMPS, +- NULL, +- mxf_interleave, ++ .name = "mxf", ++ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format"), ++ .mime_type = "application/mxf", ++ .extensions = "mxf", ++ .priv_data_size = sizeof(MXFContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mxf_write_header, ++ .write_packet = mxf_write_packet, ++ .write_trailer = mxf_write_footer, ++ .flags = AVFMT_NOTIMESTAMPS, ++ .interleave_packet = mxf_interleave, ++ .priv_class = &mxf_class, + }; + + AVOutputFormat ff_mxf_d10_muxer = { +- "mxf_d10", +- NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"), +- "application/mxf", +- NULL, +- sizeof(MXFContext), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_MPEG2VIDEO, +- mxf_write_header, +- mxf_write_packet, +- mxf_write_footer, +- AVFMT_NOTIMESTAMPS, +- NULL, +- mxf_interleave, ++ .name = "mxf_d10", ++ .long_name = NULL_IF_CONFIG_SMALL("Material eXchange Format, D-10 Mapping"), ++ .mime_type = "application/mxf", ++ .priv_data_size = sizeof(MXFContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = mxf_write_header, ++ .write_packet = mxf_write_packet, ++ .write_trailer = mxf_write_footer, ++ .flags = AVFMT_NOTIMESTAMPS, ++ .interleave_packet = mxf_interleave, ++ .priv_class = &mxf_d10_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/mxg.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/mxg.c 2012-05-14 14:08:55.086355117 +0200 +@@ -22,10 +22,9 @@ + #include "libavutil/intreadwrite.h" + #include "libavcodec/mjpeg.h" + #include "avformat.h" ++#include "internal.h" + #include "avio.h" + +-#define VIDEO_STREAM_INDEX 0 +-#define AUDIO_STREAM_INDEX 1 + #define DEFAULT_PACKET_SIZE 1024 + #define OVERREAD_SIZE 3 + +@@ -44,14 +43,14 @@ + MXGContext *mxg = s->priv_data; + + /* video parameters will be extracted from the compressed bitstream */ +- video_st = av_new_stream(s, VIDEO_STREAM_INDEX); ++ video_st = avformat_new_stream(s, NULL); + if (!video_st) + return AVERROR(ENOMEM); + video_st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + video_st->codec->codec_id = CODEC_ID_MXPEG; +- av_set_pts_info(video_st, 64, 1, 1000000); ++ avpriv_set_pts_info(video_st, 64, 1, 1000000); + +- audio_st = av_new_stream(s, AUDIO_STREAM_INDEX); ++ audio_st = avformat_new_stream(s, NULL); + if (!audio_st) + return AVERROR(ENOMEM); + audio_st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -60,7 +59,7 @@ + audio_st->codec->sample_rate = 8000; + audio_st->codec->bits_per_coded_sample = 8; + audio_st->codec->block_align = 1; +- av_set_pts_info(audio_st, 64, 1, 1000000); ++ avpriv_set_pts_info(audio_st, 64, 1, 1000000); + + mxg->soi_ptr = mxg->buffer_ptr = mxg->buffer = 0; + mxg->buffer_size = 0; +@@ -105,7 +104,7 @@ + /* reallocate internal buffer */ + if (current_pos > current_pos + cache_size) + return AVERROR(ENOMEM); +- if (mxg->soi_ptr) soi_pos = mxg->soi_ptr - mxg->buffer; ++ soi_pos = mxg->soi_ptr - mxg->buffer; + mxg->buffer = av_fast_realloc(mxg->buffer, &mxg->buffer_size, + current_pos + cache_size + + FF_INPUT_BUFFER_PADDING_SIZE); +@@ -115,7 +114,7 @@ + if (mxg->soi_ptr) mxg->soi_ptr = mxg->buffer + soi_pos; + + /* get data */ +- ret = get_buffer(s->pb, mxg->buffer_ptr + mxg->cache_size, ++ ret = avio_read(s->pb, mxg->buffer_ptr + mxg->cache_size, + cache_size - mxg->cache_size); + if (ret < 0) + return ret; +@@ -132,7 +131,7 @@ + uint8_t *startmarker_ptr, *end, *search_end, marker; + MXGContext *mxg = s->priv_data; + +- while (!url_feof(s->pb) && !url_ferror(s->pb)){ ++ while (!url_feof(s->pb) && !s->pb->error){ + if (mxg->cache_size <= OVERREAD_SIZE) { + /* update internal buffer */ + ret = mxg_update_cache(s, DEFAULT_PACKET_SIZE + OVERREAD_SIZE); +@@ -166,7 +165,7 @@ + } + + pkt->pts = pkt->dts = mxg->dts; +- pkt->stream_index = VIDEO_STREAM_INDEX; ++ pkt->stream_index = 0; + pkt->destruct = NULL; + pkt->size = mxg->buffer_ptr - mxg->soi_ptr; + pkt->data = mxg->soi_ptr; +@@ -204,7 +203,7 @@ + if (marker == APP13 && size >= 16) { /* audio data */ + /* time (GMT) of first sample in usec since 1970, little-endian */ + pkt->pts = pkt->dts = AV_RL64(startmarker_ptr + 8); +- pkt->stream_index = AUDIO_STREAM_INDEX; ++ pkt->stream_index = 1; + pkt->destruct = NULL; + pkt->size = size - 14; + pkt->data = startmarker_ptr + 16; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ncdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ncdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/ncdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/ncdec.c 2012-05-14 14:08:55.086355117 +0200 +@@ -22,6 +22,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define NC_VIDEO_FLAG 0x1A5 + +@@ -45,7 +46,7 @@ + + static int nc_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + + if (!st) + return AVERROR(ENOMEM); +@@ -54,7 +55,7 @@ + st->codec->codec_id = CODEC_ID_MPEG4; + st->need_parsing = AVSTREAM_PARSE_FULL; + +- av_set_pts_info(st, 64, 1, 100); ++ avpriv_set_pts_info(st, 64, 1, 100); + + return 0; + } +@@ -68,12 +69,12 @@ + while (state != NC_VIDEO_FLAG) { + if (url_feof(s->pb)) + return AVERROR(EIO); +- state = (state<<8) + get_byte(s->pb); ++ state = (state<<8) + avio_r8(s->pb); + } + +- get_byte(s->pb); +- size = get_le16(s->pb); +- url_fskip(s->pb, 9); ++ avio_r8(s->pb); ++ size = avio_rl16(s->pb); ++ avio_skip(s->pb, 9); + + if (size == 0) { + av_log(s, AV_LOG_DEBUG, "Next packet size is zero\n"); +@@ -91,11 +92,10 @@ + } + + AVInputFormat ff_nc_demuxer = { +- "nc", +- NULL_IF_CONFIG_SMALL("NC camera feed format"), +- 0, +- nc_probe, +- nc_read_header, +- nc_read_packet, ++ .name = "nc", ++ .long_name = NULL_IF_CONFIG_SMALL("NC camera feed format"), ++ .read_probe = nc_probe, ++ .read_header = nc_read_header, ++ .read_packet = nc_read_packet, + .extensions = "v", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/network.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/network.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/network.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/network.c 2012-05-14 14:08:55.088355157 +0200 +@@ -0,0 +1,186 @@ ++/* ++ * Copyright (c) 2007 The Libav Project ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/avutil.h" ++#include "network.h" ++#include "libavcodec/internal.h" ++ ++#define THREADS (HAVE_PTHREADS || (defined(WIN32) && !defined(__MINGW32CE__))) ++ ++#if THREADS ++#if HAVE_PTHREADS ++#include ++#else ++#include "libavcodec/w32pthreads.h" ++#endif ++#endif ++ ++#if CONFIG_OPENSSL ++#include ++static int openssl_init; ++#if THREADS ++#include ++#include "libavutil/avutil.h" ++pthread_mutex_t *openssl_mutexes; ++static void openssl_lock(int mode, int type, const char *file, int line) ++{ ++ if (mode & CRYPTO_LOCK) ++ pthread_mutex_lock(&openssl_mutexes[type]); ++ else ++ pthread_mutex_unlock(&openssl_mutexes[type]); ++} ++#if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000 ++static unsigned long openssl_thread_id(void) ++{ ++ return (intptr_t) pthread_self(); ++} ++#endif ++#endif ++#endif ++#if CONFIG_GNUTLS ++#include ++#if THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00 ++#include ++#include ++#undef malloc ++#undef free ++GCRY_THREAD_OPTION_PTHREAD_IMPL; ++#endif ++#endif ++ ++void ff_tls_init(void) ++{ ++ avpriv_lock_avformat(); ++#if CONFIG_OPENSSL ++ if (!openssl_init) { ++ SSL_library_init(); ++ SSL_load_error_strings(); ++#if THREADS ++ if (!CRYPTO_get_locking_callback()) { ++ int i; ++ openssl_mutexes = av_malloc(sizeof(pthread_mutex_t) * CRYPTO_num_locks()); ++ for (i = 0; i < CRYPTO_num_locks(); i++) ++ pthread_mutex_init(&openssl_mutexes[i], NULL); ++ CRYPTO_set_locking_callback(openssl_lock); ++#if !defined(WIN32) && OPENSSL_VERSION_NUMBER < 0x10000000 ++ CRYPTO_set_id_callback(openssl_thread_id); ++#endif ++ } ++#endif ++ } ++ openssl_init++; ++#endif ++#if CONFIG_GNUTLS ++#if THREADS && GNUTLS_VERSION_NUMBER < 0x020b00 ++ if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) ++ gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); ++#endif ++ gnutls_global_init(); ++#endif ++ avpriv_unlock_avformat(); ++} ++ ++void ff_tls_deinit(void) ++{ ++ avpriv_lock_avformat(); ++#if CONFIG_OPENSSL ++ openssl_init--; ++ if (!openssl_init) { ++#if THREADS ++ if (CRYPTO_get_locking_callback() == openssl_lock) { ++ int i; ++ CRYPTO_set_locking_callback(NULL); ++ for (i = 0; i < CRYPTO_num_locks(); i++) ++ pthread_mutex_destroy(&openssl_mutexes[i]); ++ av_free(openssl_mutexes); ++ } ++#endif ++ } ++#endif ++#if CONFIG_GNUTLS ++ gnutls_global_deinit(); ++#endif ++ avpriv_unlock_avformat(); ++} ++ ++int ff_network_inited_globally; ++ ++int ff_network_init(void) ++{ ++#if HAVE_WINSOCK2_H ++ WSADATA wsaData; ++#endif ++ ++ if (!ff_network_inited_globally) ++ av_log(NULL, AV_LOG_WARNING, "Using network protocols without global " ++ "network initialization. Please use " ++ "avformat_network_init(), this will " ++ "become mandatory later.\n"); ++#if HAVE_WINSOCK2_H ++ if (WSAStartup(MAKEWORD(1,1), &wsaData)) ++ return 0; ++#endif ++ return 1; ++} ++ ++int ff_network_wait_fd(int fd, int write) ++{ ++ int ev = write ? POLLOUT : POLLIN; ++ struct pollfd p = { .fd = fd, .events = ev, .revents = 0 }; ++ int ret; ++ ret = poll(&p, 1, 100); ++ return ret < 0 ? ff_neterrno() : p.revents & (ev | POLLERR | POLLHUP) ? 0 : AVERROR(EAGAIN); ++} ++ ++void ff_network_close(void) ++{ ++#if HAVE_WINSOCK2_H ++ WSACleanup(); ++#endif ++} ++ ++#if HAVE_WINSOCK2_H ++int ff_neterrno(void) ++{ ++ int err = WSAGetLastError(); ++ switch (err) { ++ case WSAEWOULDBLOCK: ++ return AVERROR(EAGAIN); ++ case WSAEINTR: ++ return AVERROR(EINTR); ++ } ++ return -err; ++} ++#endif ++ ++int ff_is_multicast_address(struct sockaddr *addr) ++{ ++ if (addr->sa_family == AF_INET) { ++ return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); ++ } ++#if HAVE_STRUCT_SOCKADDR_IN6 ++ if (addr->sa_family == AF_INET6) { ++ return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); ++ } ++#endif ++ ++ return 0; ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/network.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/network.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/network.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/network.h 2012-05-14 14:08:55.088355157 +0200 +@@ -21,15 +21,22 @@ + #ifndef AVFORMAT_NETWORK_H + #define AVFORMAT_NETWORK_H + ++#include ++ + #include "config.h" ++#include "libavutil/error.h" ++#include "os_support.h" + + #if HAVE_WINSOCK2_H + #include + #include + +-#define ff_neterrno() (-WSAGetLastError()) +-#define FF_NETERROR(err) (-WSA##err) +-#define WSAEAGAIN WSAEWOULDBLOCK ++#define EPROTONOSUPPORT WSAEPROTONOSUPPORT ++#define ETIMEDOUT WSAETIMEDOUT ++#define ECONNREFUSED WSAECONNREFUSED ++#define EINPROGRESS WSAEINPROGRESS ++ ++int ff_neterrno(void); + #else + #include + #include +@@ -37,31 +44,26 @@ + #include + + #define ff_neterrno() AVERROR(errno) +-#define FF_NETERROR(err) AVERROR(err) + #endif + + #if HAVE_ARPA_INET_H + #include + #endif + ++#if HAVE_POLL_H ++#include ++#endif ++ + int ff_socket_nonblock(int socket, int enable); + +-static inline int ff_network_init(void) +-{ +-#if HAVE_WINSOCK2_H +- WSADATA wsaData; +- if (WSAStartup(MAKEWORD(1,1), &wsaData)) +- return 0; +-#endif +- return 1; +-} ++extern int ff_network_inited_globally; ++int ff_network_init(void); ++void ff_network_close(void); + +-static inline void ff_network_close(void) +-{ +-#if HAVE_WINSOCK2_H +- WSACleanup(); +-#endif +-} ++void ff_tls_init(void); ++void ff_tls_deinit(void); ++ ++int ff_network_wait_fd(int fd, int write); + + int ff_inet_aton (const char * str, struct in_addr * add); + +@@ -162,18 +164,6 @@ + #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) + #endif + +-static inline int ff_is_multicast_address(struct sockaddr *addr) +-{ +- if (addr->sa_family == AF_INET) { +- return IN_MULTICAST(ntohl(((struct sockaddr_in *)addr)->sin_addr.s_addr)); +- } +-#if HAVE_STRUCT_SOCKADDR_IN6 +- if (addr->sa_family == AF_INET6) { +- return IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *)addr)->sin6_addr); +- } +-#endif +- +- return 0; +-} ++int ff_is_multicast_address(struct sockaddr *addr); + + #endif /* AVFORMAT_NETWORK_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nsvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nsvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nsvdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nsvdec.c 2012-05-14 14:08:55.091355217 +0200 +@@ -18,12 +18,15 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ ++ ++#include "libavutil/mathematics.h" + #include "avformat.h" ++#include "internal.h" + #include "riff.h" ++#include "libavutil/dict.h" ++#include "libavutil/intreadwrite.h" + +-//#define DEBUG + //#define DEBUG_DUMP_INDEX // XXX dumbdriving-271.nsv breaks with it commented!! +-//#define DEBUG_SEEK + #define CHECK_SUBSEQUENT_NSVS + //#define DISABLE_AUDIO + +@@ -81,12 +84,6 @@ + * - seek + */ + +-#ifdef DEBUG +-#define PRINT(_v) printf _v +-#else +-#define PRINT(_v) +-#endif +- + #if 0 + struct NSVf_header { + uint32_t chunk_tag; /* 'NSVf' */ +@@ -195,6 +192,7 @@ + { CODEC_ID_VP6, MKTAG('V', 'P', '6', '0') }, + { CODEC_ID_VP6, MKTAG('V', 'P', '6', '1') }, + { CODEC_ID_VP6, MKTAG('V', 'P', '6', '2') }, ++ { CODEC_ID_VP8, MKTAG('V', 'P', '8', '0') }, + /* + { CODEC_ID_VP4, MKTAG('V', 'P', '4', ' ') }, + { CODEC_ID_VP4, MKTAG('V', 'P', '4', '0') }, +@@ -208,6 +206,7 @@ + { CODEC_ID_MP3, MKTAG('M', 'P', '3', ' ') }, + { CODEC_ID_AAC, MKTAG('A', 'A', 'C', ' ') }, + { CODEC_ID_AAC, MKTAG('A', 'A', 'C', 'P') }, ++ { CODEC_ID_AAC, MKTAG('V', 'L', 'B', ' ') }, + { CODEC_ID_SPEEX, MKTAG('S', 'P', 'X', ' ') }, + { CODEC_ID_PCM_U16LE, MKTAG('P', 'C', 'M', ' ') }, + { CODEC_ID_NONE, 0 }, +@@ -216,102 +215,97 @@ + //static int nsv_load_index(AVFormatContext *s); + static int nsv_read_chunk(AVFormatContext *s, int fill_header); + +-#ifdef DEBUG +-static void print_tag(const char *str, unsigned int tag, int size) +-{ +- printf("%s: tag=%c%c%c%c\n", +- str, tag & 0xff, +- (tag >> 8) & 0xff, +- (tag >> 16) & 0xff, +- (tag >> 24) & 0xff); +-} +-#endif ++#define print_tag(str, tag, size) \ ++ av_dlog(NULL, "%s: tag=%c%c%c%c\n", \ ++ str, tag & 0xff, \ ++ (tag >> 8) & 0xff, \ ++ (tag >> 16) & 0xff, \ ++ (tag >> 24) & 0xff); + + /* try to find something we recognize, and set the state accordingly */ + static int nsv_resync(AVFormatContext *s) + { + NSVContext *nsv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint32_t v = 0; + int i; + +- PRINT(("%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, url_ftell(pb), nsv->state)); ++ av_dlog(s, "%s(), offset = %"PRId64", state = %d\n", __FUNCTION__, avio_tell(pb), nsv->state); + + //nsv->state = NSV_UNSYNC; + + for (i = 0; i < NSV_MAX_RESYNC; i++) { + if (url_feof(pb)) { +- PRINT(("NSV EOF\n")); ++ av_dlog(s, "NSV EOF\n"); + nsv->state = NSV_UNSYNC; + return -1; + } + v <<= 8; +- v |= get_byte(pb); +-/* ++ v |= avio_r8(pb); + if (i < 8) { +- PRINT(("NSV resync: [%d] = %02x\n", i, v & 0x0FF)); ++ av_dlog(s, "NSV resync: [%d] = %02x\n", i, v & 0x0FF); + } +-*/ + + if ((v & 0x0000ffff) == 0xefbe) { /* BEEF */ +- PRINT(("NSV resynced on BEEF after %d bytes\n", i+1)); ++ av_dlog(s, "NSV resynced on BEEF after %d bytes\n", i+1); + nsv->state = NSV_FOUND_BEEF; + return 0; + } + /* we read as big endian, thus the MK*BE* */ + if (v == TB_NSVF) { /* NSVf */ +- PRINT(("NSV resynced on NSVf after %d bytes\n", i+1)); ++ av_dlog(s, "NSV resynced on NSVf after %d bytes\n", i+1); + nsv->state = NSV_FOUND_NSVF; + return 0; + } + if (v == MKBETAG('N', 'S', 'V', 's')) { /* NSVs */ +- PRINT(("NSV resynced on NSVs after %d bytes\n", i+1)); ++ av_dlog(s, "NSV resynced on NSVs after %d bytes\n", i+1); + nsv->state = NSV_FOUND_NSVS; + return 0; + } + + } +- PRINT(("NSV sync lost\n")); ++ av_dlog(s, "NSV sync lost\n"); + return -1; + } + + static int nsv_parse_NSVf_header(AVFormatContext *s, AVFormatParameters *ap) + { + NSVContext *nsv = s->priv_data; +- ByteIOContext *pb = s->pb; +- unsigned int file_size, size; ++ AVIOContext *pb = s->pb; ++ unsigned int av_unused file_size; ++ unsigned int size; + int64_t duration; + int strings_size; + int table_entries; + int table_entries_used; + +- PRINT(("%s()\n", __FUNCTION__)); ++ av_dlog(s, "%s()\n", __FUNCTION__); + + nsv->state = NSV_UNSYNC; /* in case we fail */ + +- size = get_le32(pb); ++ size = avio_rl32(pb); + if (size < 28) + return -1; + nsv->NSVf_end = size; + +- //s->file_size = (uint32_t)get_le32(pb); +- file_size = (uint32_t)get_le32(pb); +- PRINT(("NSV NSVf chunk_size %u\n", size)); +- PRINT(("NSV NSVf file_size %u\n", file_size)); ++ //s->file_size = (uint32_t)avio_rl32(pb); ++ file_size = (uint32_t)avio_rl32(pb); ++ av_dlog(s, "NSV NSVf chunk_size %u\n", size); ++ av_dlog(s, "NSV NSVf file_size %u\n", file_size); + +- nsv->duration = duration = get_le32(pb); /* in ms */ +- PRINT(("NSV NSVf duration %"PRId64" ms\n", duration)); ++ nsv->duration = duration = avio_rl32(pb); /* in ms */ ++ av_dlog(s, "NSV NSVf duration %"PRId64" ms\n", duration); + // XXX: store it in AVStreams + +- strings_size = get_le32(pb); +- table_entries = get_le32(pb); +- table_entries_used = get_le32(pb); +- PRINT(("NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", +- strings_size, table_entries, table_entries_used)); ++ strings_size = avio_rl32(pb); ++ table_entries = avio_rl32(pb); ++ table_entries_used = avio_rl32(pb); ++ av_dlog(s, "NSV NSVf info-strings size: %d, table entries: %d, bis %d\n", ++ strings_size, table_entries, table_entries_used); + if (url_feof(pb)) + return -1; + +- PRINT(("NSV got header; filepos %"PRId64"\n", url_ftell(pb))); ++ av_dlog(s, "NSV got header; filepos %"PRId64"\n", avio_tell(pb)); + + if (strings_size > 0) { + char *strings; /* last byte will be '\0' to play safe with str*() */ +@@ -319,9 +313,11 @@ + char *token, *value; + char quote; + +- p = strings = av_mallocz(strings_size + 1); ++ p = strings = av_mallocz((size_t)strings_size + 1); ++ if (!p) ++ return AVERROR(ENOMEM); + endp = strings + strings_size; +- get_buffer(pb, strings, strings_size); ++ avio_read(pb, strings, strings_size); + while (p < endp) { + while (*p == ' ') + p++; /* strip out spaces */ +@@ -338,15 +334,15 @@ + if (!p || p >= endp) + break; + *p++ = '\0'; +- PRINT(("NSV NSVf INFO: %s='%s'\n", token, value)); +- av_metadata_set2(&s->metadata, token, value, 0); ++ av_dlog(s, "NSV NSVf INFO: %s='%s'\n", token, value); ++ av_dict_set(&s->metadata, token, value, 0); + } + av_free(strings); + } + if (url_feof(pb)) + return -1; + +- PRINT(("NSV got infos; filepos %"PRId64"\n", url_ftell(pb))); ++ av_dlog(s, "NSV got infos; filepos %"PRId64"\n", avio_tell(pb)); + + if (table_entries_used > 0) { + int i; +@@ -354,41 +350,45 @@ + if((unsigned)table_entries_used >= UINT_MAX / sizeof(uint32_t)) + return -1; + nsv->nsvs_file_offset = av_malloc((unsigned)table_entries_used * sizeof(uint32_t)); ++ if (!nsv->nsvs_file_offset) ++ return AVERROR(ENOMEM); + + for(i=0;insvs_file_offset[i] = get_le32(pb) + size; ++ nsv->nsvs_file_offset[i] = avio_rl32(pb) + size; + + if(table_entries > table_entries_used && +- get_le32(pb) == MKTAG('T','O','C','2')) { ++ avio_rl32(pb) == MKTAG('T','O','C','2')) { + nsv->nsvs_timestamps = av_malloc((unsigned)table_entries_used*sizeof(uint32_t)); ++ if (!nsv->nsvs_timestamps) ++ return AVERROR(ENOMEM); + for(i=0;insvs_timestamps[i] = get_le32(pb); ++ nsv->nsvs_timestamps[i] = avio_rl32(pb); + } + } + } + +- PRINT(("NSV got index; filepos %"PRId64"\n", url_ftell(pb))); ++ av_dlog(s, "NSV got index; filepos %"PRId64"\n", avio_tell(pb)); + + #ifdef DEBUG_DUMP_INDEX + #define V(v) ((v<0x20 || v > 127)?'.':v) + /* dump index */ +- PRINT(("NSV %d INDEX ENTRIES:\n", table_entries)); +- PRINT(("NSV [dataoffset][fileoffset]\n", table_entries)); ++ av_dlog(s, "NSV %d INDEX ENTRIES:\n", table_entries); ++ av_dlog(s, "NSV [dataoffset][fileoffset]\n", table_entries); + for (i = 0; i < table_entries; i++) { + unsigned char b[8]; +- url_fseek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET); +- get_buffer(pb, b, 8); +- PRINT(("NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x" ++ avio_seek(pb, size + nsv->nsvs_file_offset[i], SEEK_SET); ++ avio_read(pb, b, 8); ++ av_dlog(s, "NSV [0x%08lx][0x%08lx]: %02x %02x %02x %02x %02x %02x %02x %02x" + "%c%c%c%c%c%c%c%c\n", + nsv->nsvs_file_offset[i], size + nsv->nsvs_file_offset[i], + b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7], +- V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) )); ++ V(b[0]), V(b[1]), V(b[2]), V(b[3]), V(b[4]), V(b[5]), V(b[6]), V(b[7]) ); + } +- //url_fseek(pb, size, SEEK_SET); /* go back to end of header */ ++ //avio_seek(pb, size, SEEK_SET); /* go back to end of header */ + #undef V + #endif + +- url_fseek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */ ++ avio_seek(pb, nsv->base_offset + size, SEEK_SET); /* required for dumbdriving-271.nsv (2 extra bytes) */ + + if (url_feof(pb)) + return -1; +@@ -399,22 +399,22 @@ + static int nsv_parse_NSVs_header(AVFormatContext *s, AVFormatParameters *ap) + { + NSVContext *nsv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint32_t vtag, atag; + uint16_t vwidth, vheight; + AVRational framerate; + int i; + AVStream *st; + NSVStream *nst; +- PRINT(("%s()\n", __FUNCTION__)); ++ av_dlog(s, "%s()\n", __FUNCTION__); + +- vtag = get_le32(pb); +- atag = get_le32(pb); +- vwidth = get_le16(pb); +- vheight = get_le16(pb); +- i = get_byte(pb); ++ vtag = avio_rl32(pb); ++ atag = avio_rl32(pb); ++ vwidth = avio_rl16(pb); ++ vheight = avio_rl16(pb); ++ i = avio_r8(pb); + +- PRINT(("NSV NSVs framerate code %2x\n", i)); ++ av_dlog(s, "NSV NSVs framerate code %2x\n", i); + if(i&0x80) { /* odd way of giving native framerates from docs */ + int t=(i & 0x7F)>>2; + if(t<16) framerate = (AVRational){1, t+1}; +@@ -432,13 +432,12 @@ + else + framerate= (AVRational){i, 1}; + +- nsv->avsync = get_le16(pb); ++ nsv->avsync = avio_rl16(pb); + nsv->framerate = framerate; +-#ifdef DEBUG ++ + print_tag("NSV NSVs vtag", vtag, 0); + print_tag("NSV NSVs atag", atag, 0); +- PRINT(("NSV NSVs vsize %dx%d\n", vwidth, vheight)); +-#endif ++ av_dlog(s, "NSV NSVs vsize %dx%d\n", vwidth, vheight); + + /* XXX change to ap != NULL ? */ + if (s->nb_streams == 0) { /* streams not yet published, let's do that */ +@@ -448,10 +447,11 @@ + nsv->vheight = vwidth; + if (vtag != T_NONE) { + int i; +- st = av_new_stream(s, NSV_ST_VIDEO); ++ st = avformat_new_stream(s, NULL); + if (!st) + goto fail; + ++ st->id = NSV_ST_VIDEO; + nst = av_mallocz(sizeof(NSVStream)); + if (!nst) + goto fail; +@@ -463,7 +463,7 @@ + st->codec->height = vheight; + st->codec->bits_per_coded_sample = 24; /* depth XXX */ + +- av_set_pts_info(st, 64, framerate.den, framerate.num); ++ avpriv_set_pts_info(st, 64, framerate.den, framerate.num); + st->start_time = 0; + st->duration = av_rescale(nsv->duration, framerate.num, 1000*framerate.den); + +@@ -479,10 +479,11 @@ + } + if (atag != T_NONE) { + #ifndef DISABLE_AUDIO +- st = av_new_stream(s, NSV_ST_AUDIO); ++ st = avformat_new_stream(s, NULL); + if (!st) + goto fail; + ++ st->id = NSV_ST_AUDIO; + nst = av_mallocz(sizeof(NSVStream)); + if (!nst) + goto fail; +@@ -494,7 +495,7 @@ + st->need_parsing = AVSTREAM_PARSE_FULL; /* for PCM we will read a chunk later and put correct info */ + + /* set timebase to common denominator of ms and framerate */ +- av_set_pts_info(st, 64, 1, framerate.num*1000); ++ avpriv_set_pts_info(st, 64, 1, framerate.num*1000); + st->start_time = 0; + st->duration = (int64_t)nsv->duration * framerate.num; + #endif +@@ -502,7 +503,7 @@ + #ifdef CHECK_SUBSEQUENT_NSVS + } else { + if (nsv->vtag != vtag || nsv->atag != atag || nsv->vwidth != vwidth || nsv->vheight != vwidth) { +- PRINT(("NSV NSVs header values differ from the first one!!!\n")); ++ av_dlog(s, "NSV NSVs header values differ from the first one!!!\n"); + //return -1; + } + #endif /* CHECK_SUBSEQUENT_NSVS */ +@@ -521,8 +522,8 @@ + NSVContext *nsv = s->priv_data; + int i, err; + +- PRINT(("%s()\n", __FUNCTION__)); +- PRINT(("filename '%s'\n", s->filename)); ++ av_dlog(s, "%s()\n", __FUNCTION__); ++ av_dlog(s, "filename '%s'\n", s->filename); + + nsv->state = NSV_UNSYNC; + nsv->ahead[0].data = nsv->ahead[1].data = NULL; +@@ -530,11 +531,16 @@ + for (i = 0; i < NSV_MAX_RESYNC_TRIES; i++) { + if (nsv_resync(s) < 0) + return -1; +- if (nsv->state == NSV_FOUND_NSVF) ++ if (nsv->state == NSV_FOUND_NSVF) { + err = nsv_parse_NSVf_header(s, ap); ++ if (err < 0) ++ return err; ++ } + /* we need the first NSVs also... */ + if (nsv->state == NSV_FOUND_NSVS) { + err = nsv_parse_NSVs_header(s, ap); ++ if (err < 0) ++ return err; + break; /* we just want the first one */ + } + } +@@ -543,14 +549,14 @@ + /* now read the first chunk, so we can attempt to decode more info */ + err = nsv_read_chunk(s, 1); + +- PRINT(("parsed header\n")); +- return 0; ++ av_dlog(s, "parsed header\n"); ++ return err; + } + + static int nsv_read_chunk(AVFormatContext *s, int fill_header) + { + NSVContext *nsv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st[2] = {NULL, NULL}; + NSVStream *nst; + AVPacket *pkt; +@@ -559,9 +565,9 @@ + uint32_t vsize; + uint16_t asize; + uint16_t auxsize; +- uint32_t auxtag; ++ uint32_t av_unused auxtag; + +- PRINT(("%s(%d)\n", __FUNCTION__, fill_header)); ++ av_dlog(s, "%s(%d)\n", __FUNCTION__, fill_header); + + if (nsv->ahead[0].data || nsv->ahead[1].data) + return 0; //-1; /* hey! eat what you've in your plate first! */ +@@ -581,23 +587,23 @@ + if (nsv->state != NSV_HAS_READ_NSVS && nsv->state != NSV_FOUND_BEEF) + return -1; + +- auxcount = get_byte(pb); +- vsize = get_le16(pb); +- asize = get_le16(pb); ++ auxcount = avio_r8(pb); ++ vsize = avio_rl16(pb); ++ asize = avio_rl16(pb); + vsize = (vsize << 4) | (auxcount >> 4); + auxcount &= 0x0f; +- PRINT(("NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize)); ++ av_dlog(s, "NSV CHUNK %d aux, %u bytes video, %d bytes audio\n", auxcount, vsize, asize); + /* skip aux stuff */ + for (i = 0; i < auxcount; i++) { +- auxsize = get_le16(pb); +- auxtag = get_le32(pb); +- PRINT(("NSV aux data: '%c%c%c%c', %d bytes\n", ++ auxsize = avio_rl16(pb); ++ auxtag = avio_rl32(pb); ++ av_dlog(s, "NSV aux data: '%c%c%c%c', %d bytes\n", + (auxtag & 0x0ff), + ((auxtag >> 8) & 0x0ff), + ((auxtag >> 16) & 0x0ff), + ((auxtag >> 24) & 0x0ff), +- auxsize)); +- url_fskip(pb, auxsize); ++ auxsize); ++ avio_skip(pb, auxsize); + vsize -= auxsize + sizeof(uint16_t) + sizeof(uint32_t); /* that's becoming braindead */ + } + +@@ -609,27 +615,25 @@ + } + + /* map back streams to v,a */ +- if (s->streams[0]) ++ if (s->nb_streams > 0) + st[s->streams[0]->id] = s->streams[0]; +- if (s->streams[1]) ++ if (s->nb_streams > 1) + st[s->streams[1]->id] = s->streams[1]; + +- if (vsize/* && st[NSV_ST_VIDEO]*/) { ++ if (vsize && st[NSV_ST_VIDEO]) { + nst = st[NSV_ST_VIDEO]->priv_data; + pkt = &nsv->ahead[NSV_ST_VIDEO]; + av_get_packet(pb, pkt, vsize); + pkt->stream_index = st[NSV_ST_VIDEO]->index;//NSV_ST_VIDEO; + pkt->dts = nst->frame_offset; + pkt->flags |= nsv->state == NSV_HAS_READ_NSVS ? AV_PKT_FLAG_KEY : 0; /* keyframe only likely on a sync frame */ +-/* +- for (i = 0; i < MIN(8, vsize); i++) +- PRINT(("NSV video: [%d] = %02x\n", i, pkt->data[i])); +-*/ ++ for (i = 0; i < FFMIN(8, vsize); i++) ++ av_dlog(s, "NSV video: [%d] = %02x\n", i, pkt->data[i]); + } + if(st[NSV_ST_VIDEO]) + ((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset++; + +- if (asize/*st[NSV_ST_AUDIO]*/) { ++ if (asize && st[NSV_ST_AUDIO]) { + nst = st[NSV_ST_AUDIO]->priv_data; + pkt = &nsv->ahead[NSV_ST_AUDIO]; + /* read raw audio specific header on the first audio chunk... */ +@@ -638,15 +642,15 @@ + uint8_t bps; + uint8_t channels; + uint16_t samplerate; +- bps = get_byte(pb); +- channels = get_byte(pb); +- samplerate = get_le16(pb); ++ bps = avio_r8(pb); ++ channels = avio_r8(pb); ++ samplerate = avio_rl16(pb); + asize-=4; +- PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate)); ++ av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); + if (fill_header) { + st[NSV_ST_AUDIO]->need_parsing = AVSTREAM_PARSE_NONE; /* we know everything */ + if (bps != 16) { +- PRINT(("NSV AUDIO bit/sample != 16 (%d)!!!\n", bps)); ++ av_dlog(s, "NSV AUDIO bit/sample != 16 (%d)!!!\n", bps); + } + bps /= channels; // ??? + if (bps == 8) +@@ -655,7 +659,7 @@ + channels = 1; + st[NSV_ST_AUDIO]->codec->channels = channels; + st[NSV_ST_AUDIO]->codec->sample_rate = samplerate; +- PRINT(("NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate)); ++ av_dlog(s, "NSV RAWAUDIO: bps %d, nchan %d, srate %d\n", bps, channels, samplerate); + } + } + av_get_packet(pb, pkt, asize); +@@ -666,7 +670,7 @@ + pkt->dts = (((NSVStream*)st[NSV_ST_VIDEO]->priv_data)->frame_offset-1); + pkt->dts *= (int64_t)1000 * nsv->framerate.den; + pkt->dts += (int64_t)nsv->avsync * nsv->framerate.num; +- PRINT(("NSV AUDIO: sync:%d, dts:%"PRId64, nsv->avsync, pkt->dts)); ++ av_dlog(s, "NSV AUDIO: sync:%d, dts:%"PRId64, nsv->avsync, pkt->dts); + } + nst->frame_offset++; + } +@@ -681,7 +685,7 @@ + NSVContext *nsv = s->priv_data; + int i, err = 0; + +- PRINT(("%s()\n", __FUNCTION__)); ++ av_dlog(s, "%s()\n", __FUNCTION__); + + /* in case we don't already have something to eat ... */ + if (nsv->ahead[0].data == NULL && nsv->ahead[1].data == NULL) +@@ -692,7 +696,7 @@ + /* now pick one of the plates */ + for (i = 0; i < 2; i++) { + if (nsv->ahead[i].data) { +- PRINT(("%s: using cached packet[%d]\n", __FUNCTION__, i)); ++ av_dlog(s, "%s: using cached packet[%d]\n", __FUNCTION__, i); + /* avoid the cost of new_packet + memcpy(->data) */ + memcpy(pkt, &nsv->ahead[i], sizeof(AVPacket)); + nsv->ahead[i].data = NULL; /* we ate that one */ +@@ -715,7 +719,9 @@ + if(index < 0) + return -1; + +- url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); ++ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) ++ return -1; ++ + nst->frame_offset = st->index_entries[index].timestamp; + nsv->state = NSV_UNSYNC; + return 0; +@@ -751,8 +757,9 @@ + + static int nsv_probe(AVProbeData *p) + { +- int i; +-// PRINT(("nsv_probe(), buf_size %d\n", p->buf_size)); ++ int i, score = 0; ++ ++ av_dlog(NULL, "nsv_probe(), buf_size %d\n", p->buf_size); + /* check file header */ + /* streamed files might not have any header */ + if (p->buf[0] == 'N' && p->buf[1] == 'S' && +@@ -763,24 +770,30 @@ + /* seems the servers don't bother starting clean chunks... */ + /* sometimes even the first header is at 9KB or something :^) */ + for (i = 1; i < p->buf_size - 3; i++) { +- if (p->buf[i+0] == 'N' && p->buf[i+1] == 'S' && +- p->buf[i+2] == 'V' && p->buf[i+3] == 's') +- return AVPROBE_SCORE_MAX-20; ++ if (AV_RL32(p->buf + i) == AV_RL32("NSVs")) { ++ /* Get the chunk size and check if at the end we are getting 0xBEEF */ ++ int vsize = AV_RL24(p->buf+i+19) >> 4; ++ int asize = AV_RL16(p->buf+i+22); ++ int offset = i + 23 + asize + vsize + 1; ++ if (offset <= p->buf_size - 2 && AV_RL16(p->buf + offset) == 0xBEEF) ++ return 4*AVPROBE_SCORE_MAX/5; ++ score = AVPROBE_SCORE_MAX/5; ++ } + } + /* so we'll have more luck on extension... */ + if (av_match_ext(p->filename, "nsv")) + return AVPROBE_SCORE_MAX/2; + /* FIXME: add mime-type check */ +- return 0; ++ return score; + } + + AVInputFormat ff_nsv_demuxer = { +- "nsv", +- NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"), +- sizeof(NSVContext), +- nsv_probe, +- nsv_read_header, +- nsv_read_packet, +- nsv_read_close, +- nsv_read_seek, ++ .name = "nsv", ++ .long_name = NULL_IF_CONFIG_SMALL("Nullsoft Streaming Video"), ++ .priv_data_size = sizeof(NSVContext), ++ .read_probe = nsv_probe, ++ .read_header = nsv_read_header, ++ .read_packet = nsv_read_packet, ++ .read_close = nsv_read_close, ++ .read_seek = nsv_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nullenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nullenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nullenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nullenc.c 2012-05-14 14:08:55.092355237 +0200 +@@ -27,14 +27,10 @@ + } + + AVOutputFormat ff_null_muxer = { +- "null", +- NULL_IF_CONFIG_SMALL("raw null video format"), +- NULL, +- NULL, +- 0, +- AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), +- CODEC_ID_RAWVIDEO, +- NULL, +- null_write_packet, +- .flags = AVFMT_NOFILE | AVFMT_RAWPICTURE | AVFMT_NOTIMESTAMPS, ++ .name = "null", ++ .long_name = NULL_IF_CONFIG_SMALL("raw null video format"), ++ .audio_codec = AV_NE(CODEC_ID_PCM_S16BE, CODEC_ID_PCM_S16LE), ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_packet = null_write_packet, ++ .flags = AVFMT_NOFILE | AVFMT_NOTIMESTAMPS | AVFMT_RAWPICTURE, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nut.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nut.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nut.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nut.c 2012-05-14 14:08:55.092355237 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "libavutil/tree.h" + #include "nut.h" + #include "internal.h" +@@ -65,8 +66,16 @@ + { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 4 ) }, + { CODEC_ID_RAWVIDEO, MKTAG('B', '4', 'B', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('R', '4', 'B', 'Y') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('B', 'G', 'R', 48 ) }, + { CODEC_ID_RAWVIDEO, MKTAG('R', 'G', 'B', 48 ) }, ++ { CODEC_ID_RAWVIDEO, MKTAG(48 , 'B', 'G', 'R') }, + { CODEC_ID_RAWVIDEO, MKTAG(48 , 'R', 'G', 'B') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 10 ) }, ++ { CODEC_ID_RAWVIDEO, MKTAG(10 , 11 , '3', 'Y') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 10 , 10 ) }, ++ { CODEC_ID_RAWVIDEO, MKTAG(10 , 10 , '3', 'Y') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 0 , 10 ) }, ++ { CODEC_ID_RAWVIDEO, MKTAG(10 , 0 , '3', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', '1', 0 , 16 ) }, + { CODEC_ID_RAWVIDEO, MKTAG(16 , 0 , '1', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', '3', 11 , 16 ) }, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nutdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nutdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nutdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nutdec.c 2012-05-14 14:08:55.096355318 +0200 +@@ -20,28 +20,26 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include + #include "libavutil/avstring.h" + #include "libavutil/bswap.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "libavutil/tree.h" ++#include "avio_internal.h" + #include "nut.h" + + #undef NDEBUG + #include + +-#if FF_API_MAX_STREAMS +-#define NUT_MAX_STREAMS MAX_STREAMS +-#else + #define NUT_MAX_STREAMS 256 /* arbitrary sanity check value */ +-#endif + +-static int get_str(ByteIOContext *bc, char *string, unsigned int maxlen){ +- unsigned int len= ff_get_v(bc); ++static int get_str(AVIOContext *bc, char *string, unsigned int maxlen){ ++ unsigned int len= ffio_read_varlen(bc); + + if(len && maxlen) +- get_buffer(bc, string, FFMIN(len, maxlen)); ++ avio_read(bc, string, FFMIN(len, maxlen)); + while(len > maxlen){ +- get_byte(bc); ++ avio_r8(bc); + len--; + } + +@@ -54,75 +52,75 @@ + return 0; + } + +-static int64_t get_s(ByteIOContext *bc){ +- int64_t v = ff_get_v(bc) + 1; ++static int64_t get_s(AVIOContext *bc){ ++ int64_t v = ffio_read_varlen(bc) + 1; + + if (v&1) return -(v>>1); + else return (v>>1); + } + +-static uint64_t get_fourcc(ByteIOContext *bc){ +- unsigned int len= ff_get_v(bc); ++static uint64_t get_fourcc(AVIOContext *bc){ ++ unsigned int len= ffio_read_varlen(bc); + +- if (len==2) return get_le16(bc); +- else if(len==4) return get_le32(bc); ++ if (len==2) return avio_rl16(bc); ++ else if(len==4) return avio_rl32(bc); + else return -1; + } + + #ifdef TRACE +-static inline uint64_t get_v_trace(ByteIOContext *bc, char *file, char *func, int line){ +- uint64_t v= ff_get_v(bc); ++static inline uint64_t get_v_trace(AVIOContext *bc, char *file, char *func, int line){ ++ uint64_t v= ffio_read_varlen(bc); + + av_log(NULL, AV_LOG_DEBUG, "get_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + return v; + } + +-static inline int64_t get_s_trace(ByteIOContext *bc, char *file, char *func, int line){ ++static inline int64_t get_s_trace(AVIOContext *bc, char *file, char *func, int line){ + int64_t v= get_s(bc); + + av_log(NULL, AV_LOG_DEBUG, "get_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + return v; + } + +-static inline uint64_t get_vb_trace(ByteIOContext *bc, char *file, char *func, int line){ ++static inline uint64_t get_vb_trace(AVIOContext *bc, char *file, char *func, int line){ + uint64_t v= get_vb(bc); + + av_log(NULL, AV_LOG_DEBUG, "get_vb %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + return v; + } +-#define ff_get_v(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) ++#define ffio_read_varlen(bc) get_v_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) + #define get_s(bc) get_s_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) + #define get_vb(bc) get_vb_trace(bc, __FILE__, __PRETTY_FUNCTION__, __LINE__) + #endif + +-static int get_packetheader(NUTContext *nut, ByteIOContext *bc, int calculate_checksum, uint64_t startcode) ++static int get_packetheader(NUTContext *nut, AVIOContext *bc, int calculate_checksum, uint64_t startcode) + { + int64_t size; +-// start= url_ftell(bc) - 8; ++// start= avio_tell(bc) - 8; + + startcode= av_be2ne64(startcode); + startcode= ff_crc04C11DB7_update(0, (uint8_t*)&startcode, 8); + +- init_checksum(bc, ff_crc04C11DB7_update, startcode); +- size= ff_get_v(bc); ++ ffio_init_checksum(bc, ff_crc04C11DB7_update, startcode); ++ size= ffio_read_varlen(bc); + if(size > 4096) +- get_be32(bc); +- if(get_checksum(bc) && size > 4096) ++ avio_rb32(bc); ++ if(ffio_get_checksum(bc) && size > 4096) + return -1; + +- init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0); ++ ffio_init_checksum(bc, calculate_checksum ? ff_crc04C11DB7_update : NULL, 0); + + return size; + } + +-static uint64_t find_any_startcode(ByteIOContext *bc, int64_t pos){ ++static uint64_t find_any_startcode(AVIOContext *bc, int64_t pos){ + uint64_t state=0; + + if(pos >= 0) +- url_fseek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we currently are ++ avio_seek(bc, pos, SEEK_SET); //note, this may fail if the stream is not seekable, but that should not matter, as in this case we simply start where we currently are + + while(!url_feof(bc)){ +- state= (state<<8) | get_byte(bc); ++ state= (state<<8) | avio_r8(bc); + if((state>>56) != 'N') + continue; + switch(state){ +@@ -144,11 +142,11 @@ + * @param pos the start position of the search, or -1 if the current position + * @return the position of the startcode or -1 if not found + */ +-static int64_t find_startcode(ByteIOContext *bc, uint64_t code, int64_t pos){ ++static int64_t find_startcode(AVIOContext *bc, uint64_t code, int64_t pos){ + for(;;){ + uint64_t startcode= find_any_startcode(bc, pos); + if(startcode == code) +- return url_ftell(bc) - 8; ++ return avio_tell(bc) - 8; + else if(startcode == 0) + return -1; + pos=-1; +@@ -168,40 +166,39 @@ + } + + #define GET_V(dst, check) \ +- tmp= ff_get_v(bc);\ ++ tmp= ffio_read_varlen(bc);\ + if(!(check)){\ + av_log(s, AV_LOG_ERROR, "Error " #dst " is (%"PRId64")\n", tmp);\ + return -1;\ + }\ + dst= tmp; + +-static int skip_reserved(ByteIOContext *bc, int64_t pos){ +- pos -= url_ftell(bc); ++static int skip_reserved(AVIOContext *bc, int64_t pos){ ++ pos -= avio_tell(bc); + if(pos<0){ +- url_fseek(bc, pos, SEEK_CUR); ++ avio_seek(bc, pos, SEEK_CUR); + return -1; + }else{ + while(pos--) +- get_byte(bc); ++ avio_r8(bc); + return 0; + } + } + + static int decode_main_header(NUTContext *nut){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + uint64_t tmp, end; + unsigned int stream_count; + int i, j, tmp_stream, tmp_mul, tmp_pts, tmp_size, count, tmp_res, tmp_head_idx; +- int64_t tmp_match; + + end= get_packetheader(nut, bc, 1, MAIN_STARTCODE); +- end += url_ftell(bc); ++ end += avio_tell(bc); + + GET_V(tmp , tmp >=2 && tmp <= 3) + GET_V(stream_count , tmp > 0 && tmp <= NUT_MAX_STREAMS) + +- nut->max_distance = ff_get_v(bc); ++ nut->max_distance = ffio_read_varlen(bc); + if(nut->max_distance > 65536){ + av_log(s, AV_LOG_DEBUG, "max_distance %d\n", nut->max_distance); + nut->max_distance= 65536; +@@ -221,25 +218,24 @@ + tmp_pts=0; + tmp_mul=1; + tmp_stream=0; +- tmp_match= 1-(1LL<<62); + tmp_head_idx= 0; + for(i=0; i<256;){ +- int tmp_flags = ff_get_v(bc); +- int tmp_fields= ff_get_v(bc); ++ int tmp_flags = ffio_read_varlen(bc); ++ int tmp_fields= ffio_read_varlen(bc); + if(tmp_fields>0) tmp_pts = get_s(bc); +- if(tmp_fields>1) tmp_mul = ff_get_v(bc); +- if(tmp_fields>2) tmp_stream= ff_get_v(bc); +- if(tmp_fields>3) tmp_size = ff_get_v(bc); ++ if(tmp_fields>1) tmp_mul = ffio_read_varlen(bc); ++ if(tmp_fields>2) tmp_stream= ffio_read_varlen(bc); ++ if(tmp_fields>3) tmp_size = ffio_read_varlen(bc); + else tmp_size = 0; +- if(tmp_fields>4) tmp_res = ff_get_v(bc); ++ if(tmp_fields>4) tmp_res = ffio_read_varlen(bc); + else tmp_res = 0; +- if(tmp_fields>5) count = ff_get_v(bc); ++ if(tmp_fields>5) count = ffio_read_varlen(bc); + else count = tmp_mul - tmp_size; +- if(tmp_fields>6) tmp_match = get_s(bc); +- if(tmp_fields>7) tmp_head_idx= ff_get_v(bc); ++ if(tmp_fields>6) get_s(bc); ++ if(tmp_fields>7) tmp_head_idx= ffio_read_varlen(bc); + + while(tmp_fields-- > 8) +- ff_get_v(bc); ++ ffio_read_varlen(bc); + + if(count == 0 || i+count > 256){ + av_log(s, AV_LOG_ERROR, "illegal count %d at %d\n", count, i); +@@ -267,7 +263,7 @@ + } + assert(nut->frame_code['N'].flags == FLAG_INVALID); + +- if(end > url_ftell(bc) + 4){ ++ if(end > avio_tell(bc) + 4){ + int rem= 1024; + GET_V(nut->header_count, tmp<128U) + nut->header_count++; +@@ -279,19 +275,19 @@ + return AVERROR_INVALIDDATA; + } + nut->header[i]= av_malloc(nut->header_len[i]); +- get_buffer(bc, nut->header[i], nut->header_len[i]); ++ avio_read(bc, nut->header[i], nut->header_len[i]); + } + assert(nut->header_len[0]==0); + } + +- if(skip_reserved(bc, end) || get_checksum(bc)){ ++ if(skip_reserved(bc, end) || ffio_get_checksum(bc)){ + av_log(s, AV_LOG_ERROR, "main header checksum mismatch\n"); + return AVERROR_INVALIDDATA; + } + + nut->stream = av_mallocz(sizeof(StreamContext)*stream_count); + for(i=0; iavf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + StreamContext *stc; + int class, stream_id; + uint64_t tmp, end; + AVStream *st; + + end= get_packetheader(nut, bc, 1, STREAM_STARTCODE); +- end += url_ftell(bc); ++ end += avio_tell(bc); + + GET_V(stream_id, tmp < s->nb_streams && !nut->stream[tmp].time_base); + stc= &nut->stream[stream_id]; +@@ -315,7 +311,7 @@ + if (!st) + return AVERROR(ENOMEM); + +- class = ff_get_v(bc); ++ class = ffio_read_varlen(bc); + tmp = get_fourcc(bc); + st->codec->codec_tag= tmp; + switch(class) +@@ -347,38 +343,38 @@ + + GET_V(stc->time_base_id , tmp < nut->time_base_count); + GET_V(stc->msb_pts_shift , tmp < 16); +- stc->max_pts_distance= ff_get_v(bc); ++ stc->max_pts_distance= ffio_read_varlen(bc); + GET_V(stc->decode_delay , tmp < 1000); //sanity limit, raise this if Moore's law is true + st->codec->has_b_frames= stc->decode_delay; +- ff_get_v(bc); //stream flags ++ ffio_read_varlen(bc); //stream flags + + GET_V(st->codec->extradata_size, tmp < (1<<30)); + if(st->codec->extradata_size){ + st->codec->extradata= av_mallocz(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- get_buffer(bc, st->codec->extradata, st->codec->extradata_size); ++ avio_read(bc, st->codec->extradata, st->codec->extradata_size); + } + + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ + GET_V(st->codec->width , tmp > 0) + GET_V(st->codec->height, tmp > 0) +- st->sample_aspect_ratio.num= ff_get_v(bc); +- st->sample_aspect_ratio.den= ff_get_v(bc); ++ st->sample_aspect_ratio.num= ffio_read_varlen(bc); ++ st->sample_aspect_ratio.den= ffio_read_varlen(bc); + if((!st->sample_aspect_ratio.num) != (!st->sample_aspect_ratio.den)){ + av_log(s, AV_LOG_ERROR, "invalid aspect ratio %d/%d\n", st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); + return -1; + } +- ff_get_v(bc); /* csp type */ ++ ffio_read_varlen(bc); /* csp type */ + }else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO){ + GET_V(st->codec->sample_rate , tmp > 0) +- ff_get_v(bc); // samplerate_den ++ ffio_read_varlen(bc); // samplerate_den + GET_V(st->codec->channels, tmp > 0) + } +- if(skip_reserved(bc, end) || get_checksum(bc)){ ++ if(skip_reserved(bc, end) || ffio_get_checksum(bc)){ + av_log(s, AV_LOG_ERROR, "stream header %d checksum mismatch\n", stream_id); + return -1; + } + stc->time_base= &nut->time_base[stc->time_base_id]; +- av_set_pts_info(s->streams[stream_id], 63, stc->time_base->num, stc->time_base->den); ++ avpriv_set_pts_info(s->streams[stream_id], 63, stc->time_base->num, stc->time_base->den); + return 0; + } + +@@ -397,7 +393,7 @@ + + static int decode_info_header(NUTContext *nut){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + uint64_t tmp, chapter_start, chapter_len; + unsigned int stream_id_plus1, count; + int chapter_id, i; +@@ -406,20 +402,20 @@ + const char *type; + AVChapter *chapter= NULL; + AVStream *st= NULL; +- AVMetadata **metadata = NULL; ++ AVDictionary **metadata = NULL; + + end= get_packetheader(nut, bc, 1, INFO_STARTCODE); +- end += url_ftell(bc); ++ end += avio_tell(bc); + + GET_V(stream_id_plus1, tmp <= s->nb_streams) + chapter_id = get_s(bc); +- chapter_start= ff_get_v(bc); +- chapter_len = ff_get_v(bc); +- count = ff_get_v(bc); ++ chapter_start= ffio_read_varlen(bc); ++ chapter_len = ffio_read_varlen(bc); ++ count = ffio_read_varlen(bc); + + if(chapter_id && !stream_id_plus1){ + int64_t start= chapter_start / nut->time_base_count; +- chapter= ff_new_chapter(s, chapter_id, ++ chapter= avpriv_new_chapter(s, chapter_id, + nut->time_base[chapter_start % nut->time_base_count], + start, start + chapter_len, NULL); + metadata = &chapter->metadata; +@@ -444,7 +440,7 @@ + value= get_s(bc); + }else if(value == -4){ + type= "t"; +- value= ff_get_v(bc); ++ value= ffio_read_varlen(bc); + }else if(value < -4){ + type= "r"; + get_s(bc); +@@ -462,13 +458,13 @@ + set_disposition_bits(s, str_value, stream_id_plus1 - 1); + continue; + } +- if(metadata && strcasecmp(name,"Uses") +- && strcasecmp(name,"Depends") && strcasecmp(name,"Replaces")) +- av_metadata_set2(metadata, name, str_value, 0); ++ if(metadata && av_strcasecmp(name,"Uses") ++ && av_strcasecmp(name,"Depends") && av_strcasecmp(name,"Replaces")) ++ av_dict_set(metadata, name, str_value, 0); + } + } + +- if(skip_reserved(bc, end) || get_checksum(bc)){ ++ if(skip_reserved(bc, end) || ffio_get_checksum(bc)){ + av_log(s, AV_LOG_ERROR, "info header checksum mismatch\n"); + return -1; + } +@@ -477,22 +473,22 @@ + + static int decode_syncpoint(NUTContext *nut, int64_t *ts, int64_t *back_ptr){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int64_t end, tmp; + +- nut->last_syncpoint_pos= url_ftell(bc)-8; ++ nut->last_syncpoint_pos= avio_tell(bc)-8; + + end= get_packetheader(nut, bc, 1, SYNCPOINT_STARTCODE); +- end += url_ftell(bc); ++ end += avio_tell(bc); + +- tmp= ff_get_v(bc); +- *back_ptr= nut->last_syncpoint_pos - 16*ff_get_v(bc); ++ tmp= ffio_read_varlen(bc); ++ *back_ptr= nut->last_syncpoint_pos - 16*ffio_read_varlen(bc); + if(*back_ptr < 0) + return -1; + + ff_nut_reset_ts(nut, nut->time_base[tmp % nut->time_base_count], tmp / nut->time_base_count); + +- if(skip_reserved(bc, end) || get_checksum(bc)){ ++ if(skip_reserved(bc, end) || ffio_get_checksum(bc)){ + av_log(s, AV_LOG_ERROR, "sync point checksum mismatch\n"); + return -1; + } +@@ -505,30 +501,30 @@ + + static int find_and_decode_index(NUTContext *nut){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + uint64_t tmp, end; + int i, j, syncpoint_count; +- int64_t filesize= url_fsize(bc); ++ int64_t filesize= avio_size(bc); + int64_t *syncpoints; + int8_t *has_keyframe; + int ret= -1; + +- url_fseek(bc, filesize-12, SEEK_SET); +- url_fseek(bc, filesize-get_be64(bc), SEEK_SET); +- if(get_be64(bc) != INDEX_STARTCODE){ ++ avio_seek(bc, filesize-12, SEEK_SET); ++ avio_seek(bc, filesize-avio_rb64(bc), SEEK_SET); ++ if(avio_rb64(bc) != INDEX_STARTCODE){ + av_log(s, AV_LOG_ERROR, "no index at the end\n"); + return -1; + } + + end= get_packetheader(nut, bc, 1, INDEX_STARTCODE); +- end += url_ftell(bc); ++ end += avio_tell(bc); + +- ff_get_v(bc); //max_pts ++ ffio_read_varlen(bc); //max_pts + GET_V(syncpoint_count, tmp < INT_MAX/8 && tmp > 0) + syncpoints= av_malloc(sizeof(int64_t)*syncpoint_count); + has_keyframe= av_malloc(sizeof(int8_t)*(syncpoint_count+1)); + for(i=0; inb_streams; i++){ + int64_t last_pts= -1; + for(j=0; j>=1; +@@ -569,10 +565,10 @@ + assert(n<=syncpoint_count+1); + for(; jpriv_data; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int64_t pos; + int initialized_stream_count; + +@@ -635,7 +631,7 @@ + pos=0; + for(;;){ + uint64_t startcode= find_any_startcode(bc, pos); +- pos= url_ftell(bc); ++ pos= avio_tell(bc); + + if(startcode==0){ + av_log(s, AV_LOG_ERROR, "EOF before video frames\n"); +@@ -652,10 +648,10 @@ + + s->data_offset= pos-8; + +- if(!url_is_streamed(bc)){ +- int64_t orig_pos= url_ftell(bc); ++ if(bc->seekable){ ++ int64_t orig_pos= avio_tell(bc); + find_and_decode_index(nut); +- url_fseek(bc, orig_pos, SEEK_SET); ++ avio_seek(bc, orig_pos, SEEK_SET); + } + assert(nut->next_startcode == SYNCPOINT_STARTCODE); + +@@ -666,13 +662,13 @@ + + static int decode_frame_header(NUTContext *nut, int64_t *pts, int *stream_id, uint8_t *header_idx, int frame_code){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + StreamContext *stc; + int size, flags, size_mul, pts_delta, i, reserved_count; + uint64_t tmp; + +- if(url_ftell(bc) > nut->last_syncpoint_pos + nut->max_distance){ +- av_log(s, AV_LOG_ERROR, "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n", url_ftell(bc), nut->last_syncpoint_pos, nut->max_distance); ++ if(avio_tell(bc) > nut->last_syncpoint_pos + nut->max_distance){ ++ av_log(s, AV_LOG_ERROR, "Last frame must have been damaged %"PRId64" > %"PRId64" + %d\n", avio_tell(bc), nut->last_syncpoint_pos, nut->max_distance); + return AVERROR_INVALIDDATA; + } + +@@ -687,13 +683,13 @@ + if(flags & FLAG_INVALID) + return AVERROR_INVALIDDATA; + if(flags & FLAG_CODED) +- flags ^= ff_get_v(bc); ++ flags ^= ffio_read_varlen(bc); + if(flags & FLAG_STREAM_ID){ + GET_V(*stream_id, tmp < s->nb_streams) + } + stc= &nut->stream[*stream_id]; + if(flags&FLAG_CODED_PTS){ +- int coded_pts= ff_get_v(bc); ++ int coded_pts= ffio_read_varlen(bc); + //FIXME check last_pts validity? + if(coded_pts < (1<msb_pts_shift)){ + *pts=ff_lsb2full(stc, coded_pts); +@@ -702,16 +698,16 @@ + }else + *pts= stc->last_pts + pts_delta; + if(flags&FLAG_SIZE_MSB){ +- size += size_mul*ff_get_v(bc); ++ size += size_mul*ffio_read_varlen(bc); + } + if(flags&FLAG_MATCH_TIME) + get_s(bc); + if(flags&FLAG_HEADER_IDX) +- *header_idx= ff_get_v(bc); ++ *header_idx= ffio_read_varlen(bc); + if(flags&FLAG_RESERVED) +- reserved_count= ff_get_v(bc); ++ reserved_count= ffio_read_varlen(bc); + for(i=0; i= (unsigned)nut->header_count){ + av_log(s, AV_LOG_ERROR, "header_idx invalid\n"); +@@ -722,7 +718,7 @@ + size -= nut->header_len[*header_idx]; + + if(flags&FLAG_CHECKSUM){ +- get_be32(bc); //FIXME check this ++ avio_rb32(bc); //FIXME check this + }else if(size > 2*nut->max_distance || FFABS(stc->last_pts - *pts) > stc->max_pts_distance){ + av_log(s, AV_LOG_ERROR, "frame size > 2max_distance and no checksum\n"); + return AVERROR_INVALIDDATA; +@@ -736,7 +732,7 @@ + + static int decode_frame(NUTContext *nut, AVPacket *pkt, int frame_code){ + AVFormatContext *s= nut->avf; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int size, stream_id, discard; + int64_t pts, last_IP_pts; + StreamContext *stc; +@@ -757,14 +753,14 @@ + ||(discard >= AVDISCARD_BIDIR && last_IP_pts != AV_NOPTS_VALUE && last_IP_pts > pts) + || discard >= AVDISCARD_ALL + || stc->skip_until_key_frame){ +- url_fskip(bc, size); ++ avio_skip(bc, size); + return 1; + } + + av_new_packet(pkt, size + nut->header_len[header_idx]); + memcpy(pkt->data, nut->header[header_idx], nut->header_len[header_idx]); +- pkt->pos= url_ftell(bc); //FIXME +- get_buffer(bc, pkt->data + nut->header_len[header_idx], size); ++ pkt->pos= avio_tell(bc); //FIXME ++ avio_read(bc, pkt->data + nut->header_len[header_idx], size); + + pkt->stream_index = stream_id; + if (stc->last_flags & FLAG_KEY) +@@ -777,25 +773,25 @@ + static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) + { + NUTContext *nut = s->priv_data; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int i, frame_code=0, ret, skip; + int64_t ts, back_ptr; + + for(;;){ +- int64_t pos= url_ftell(bc); ++ int64_t pos= avio_tell(bc); + uint64_t tmp= nut->next_startcode; + nut->next_startcode=0; + + if(tmp){ + pos-=8; + }else{ +- frame_code = get_byte(bc); ++ frame_code = avio_r8(bc); + if(url_feof(bc)) + return -1; + if(frame_code == 'N'){ + tmp= frame_code; + for(i=1; i<8; i++) +- tmp = (tmp<<8) + get_byte(bc); ++ tmp = (tmp<<8) + avio_r8(bc); + } + } + switch(tmp){ +@@ -803,7 +799,7 @@ + case STREAM_STARTCODE: + case INDEX_STARTCODE: + skip= get_packetheader(nut, bc, 0, tmp); +- url_fseek(bc, skip, SEEK_CUR); ++ avio_skip(bc, skip); + break; + case INFO_STARTCODE: + if(decode_info_header(nut)<0) +@@ -812,7 +808,7 @@ + case SYNCPOINT_STARTCODE: + if(decode_syncpoint(nut, &ts, &back_ptr)<0) + goto resync; +- frame_code = get_byte(bc); ++ frame_code = avio_r8(bc); + case 0: + ret= decode_frame(nut, pkt, frame_code); + if(ret==0) +@@ -833,7 +829,7 @@ + + static int64_t nut_read_timestamp(AVFormatContext *s, int stream_index, int64_t *pos_arg, int64_t pos_limit){ + NUTContext *nut = s->priv_data; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int64_t pos, pts, back_ptr; + av_log(s, AV_LOG_DEBUG, "read_timestamp(X,%d,%"PRId64",%"PRId64")\n", stream_index, *pos_arg, pos_limit); + +@@ -877,16 +873,16 @@ + (void **) next_node); + av_log(s, AV_LOG_DEBUG, "%"PRIu64"-%"PRIu64" %"PRId64"-%"PRId64"\n", next_node[0]->pos, next_node[1]->pos, + next_node[0]->ts , next_node[1]->ts); +- pos= av_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, +- next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); ++ pos = ff_gen_search(s, -1, dummy.ts, next_node[0]->pos, next_node[1]->pos, next_node[1]->pos, ++ next_node[0]->ts , next_node[1]->ts, AVSEEK_FLAG_BACKWARD, &ts, nut_read_timestamp); + + if(!(flags & AVSEEK_FLAG_BACKWARD)){ + dummy.pos= pos+16; + next_node[1]= &nopts_sp; + av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, + (void **) next_node); +- pos2= av_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos, +- next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); ++ pos2 = ff_gen_search(s, -2, dummy.pos, next_node[0]->pos , next_node[1]->pos, next_node[1]->pos, ++ next_node[0]->back_ptr, next_node[1]->back_ptr, flags, &ts, nut_read_timestamp); + if(pos2>=0) + pos= pos2; + //FIXME dir but I think it does not matter +@@ -900,7 +896,7 @@ + } + av_log(NULL, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos2); + pos= find_startcode(s->pb, SYNCPOINT_STARTCODE, pos2); +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + av_log(NULL, AV_LOG_DEBUG, "SP: %"PRId64"\n", pos); + if(pos2 > pos || pos2 + 15 < pos){ + av_log(NULL, AV_LOG_ERROR, "no syncpoint at backptr pos\n"); +@@ -927,14 +923,14 @@ + + #if CONFIG_NUT_DEMUXER + AVInputFormat ff_nut_demuxer = { +- "nut", +- NULL_IF_CONFIG_SMALL("NUT format"), +- sizeof(NUTContext), +- nut_probe, +- nut_read_header, +- nut_read_packet, +- nut_read_close, +- read_seek, ++ .name = "nut", ++ .long_name = NULL_IF_CONFIG_SMALL("NUT format"), ++ .priv_data_size = sizeof(NUTContext), ++ .read_probe = nut_probe, ++ .read_header = nut_read_header, ++ .read_packet = nut_read_packet, ++ .read_close = nut_read_close, ++ .read_seek = read_seek, + .extensions = "nut", + .codec_tag = (const AVCodecTag * const []) { ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 }, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nutenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nutenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nutenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nutenc.c 2012-05-14 14:08:55.098355358 +0200 +@@ -20,10 +20,13 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "libavutil/tree.h" ++#include "libavutil/dict.h" + #include "libavcodec/mpegaudiodata.h" + #include "nut.h" + #include "internal.h" ++#include "avio_internal.h" + + static int find_expected_header(AVCodecContext *c, int size, int key_frame, uint8_t out[64]){ + int sample_rate= c->sample_rate; +@@ -56,10 +59,10 @@ + else if(sample_rate < (44100 + 48000)/2) sample_rate_index=0; + else sample_rate_index=1; + +- sample_rate= ff_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); ++ sample_rate= avpriv_mpa_freq_tab[sample_rate_index] >> (lsf + mpeg25); + + for(bitrate_index=2; bitrate_index<30; bitrate_index++){ +- frame_size = ff_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; ++ frame_size = avpriv_mpa_bitrate_tab[lsf][layer-1][bitrate_index>>1]; + frame_size = (frame_size * 144000) / (sample_rate << lsf) + (bitrate_index&1); + + if(frame_size == size) +@@ -241,34 +244,34 @@ + nut->frame_code['N'].flags= FLAG_INVALID; + } + +-static void put_tt(NUTContext *nut, StreamContext *nus, ByteIOContext *bc, uint64_t val){ ++static void put_tt(NUTContext *nut, AVRational *time_base, AVIOContext *bc, uint64_t val){ + val *= nut->time_base_count; +- val += nus->time_base - nut->time_base; ++ val += time_base - nut->time_base; + ff_put_v(bc, val); + } + + /** + * Store a string as vb. + */ +-static void put_str(ByteIOContext *bc, const char *string){ ++static void put_str(AVIOContext *bc, const char *string){ + int len= strlen(string); + + ff_put_v(bc, len); +- put_buffer(bc, string, len); ++ avio_write(bc, string, len); + } + +-static void put_s(ByteIOContext *bc, int64_t val){ ++static void put_s(AVIOContext *bc, int64_t val){ + ff_put_v(bc, 2*FFABS(val) - (val>0)); + } + + #ifdef TRACE +-static inline void ff_put_v_trace(ByteIOContext *bc, uint64_t v, char *file, char *func, int line){ ++static inline void ff_put_v_trace(AVIOContext *bc, uint64_t v, char *file, char *func, int line){ + av_log(NULL, AV_LOG_DEBUG, "ff_put_v %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + + ff_put_v(bc, v); + } + +-static inline void put_s_trace(ByteIOContext *bc, int64_t v, char *file, char *func, int line){ ++static inline void put_s_trace(AVIOContext *bc, int64_t v, char *file, char *func, int line){ + av_log(NULL, AV_LOG_DEBUG, "put_s %5"PRId64" / %"PRIX64" in %s %s:%d\n", v, v, file, func, line); + + put_s(bc, v); +@@ -278,28 +281,28 @@ + #endif + + //FIXME remove calculate_checksum +-static void put_packet(NUTContext *nut, ByteIOContext *bc, ByteIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){ ++static void put_packet(NUTContext *nut, AVIOContext *bc, AVIOContext *dyn_bc, int calculate_checksum, uint64_t startcode){ + uint8_t *dyn_buf=NULL; +- int dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf); ++ int dyn_size= avio_close_dyn_buf(dyn_bc, &dyn_buf); + int forw_ptr= dyn_size + 4*calculate_checksum; + + if(forw_ptr > 4096) +- init_checksum(bc, ff_crc04C11DB7_update, 0); +- put_be64(bc, startcode); ++ ffio_init_checksum(bc, ff_crc04C11DB7_update, 0); ++ avio_wb64(bc, startcode); + ff_put_v(bc, forw_ptr); + if(forw_ptr > 4096) +- put_le32(bc, get_checksum(bc)); ++ avio_wl32(bc, ffio_get_checksum(bc)); + + if(calculate_checksum) +- init_checksum(bc, ff_crc04C11DB7_update, 0); +- put_buffer(bc, dyn_buf, dyn_size); ++ ffio_init_checksum(bc, ff_crc04C11DB7_update, 0); ++ avio_write(bc, dyn_buf, dyn_size); + if(calculate_checksum) +- put_le32(bc, get_checksum(bc)); ++ avio_wl32(bc, ffio_get_checksum(bc)); + + av_free(dyn_buf); + } + +-static void write_mainheader(NUTContext *nut, ByteIOContext *bc){ ++static void write_mainheader(NUTContext *nut, AVIOContext *bc){ + int i, j, tmp_pts, tmp_flags, tmp_stream, tmp_mul, tmp_size, tmp_fields, tmp_head_idx; + int64_t tmp_match; + +@@ -366,11 +369,11 @@ + ff_put_v(bc, nut->header_count-1); + for(i=1; iheader_count; i++){ + ff_put_v(bc, nut->header_len[i]); +- put_buffer(bc, nut->header[i], nut->header_len[i]); ++ avio_write(bc, nut->header[i], nut->header_len[i]); + } + } + +-static int write_streamheader(AVFormatContext *avctx, ByteIOContext *bc, AVStream *st, int i){ ++static int write_streamheader(AVFormatContext *avctx, AVIOContext *bc, AVStream *st, int i){ + NUTContext *nut = avctx->priv_data; + AVCodecContext *codec = st->codec; + ff_put_v(bc, i); +@@ -382,7 +385,7 @@ + } + ff_put_v(bc, 4); + if (codec->codec_tag){ +- put_le32(bc, codec->codec_tag); ++ avio_wl32(bc, codec->codec_tag); + } else { + av_log(avctx, AV_LOG_ERROR, "No codec tag defined for stream %d\n", i); + return AVERROR(EINVAL); +@@ -392,10 +395,10 @@ + ff_put_v(bc, nut->stream[i].msb_pts_shift); + ff_put_v(bc, nut->stream[i].max_pts_distance); + ff_put_v(bc, codec->has_b_frames); +- put_byte(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ ++ avio_w8(bc, 0); /* flags: 0x1 - fixed_fps, 0x2 - index_present */ + + ff_put_v(bc, codec->extradata_size); +- put_buffer(bc, codec->extradata, codec->extradata_size); ++ avio_write(bc, codec->extradata, codec->extradata_size); + + switch(codec->codec_type){ + case AVMEDIA_TYPE_AUDIO: +@@ -422,24 +425,24 @@ + return 0; + } + +-static int add_info(ByteIOContext *bc, const char *type, const char *value){ ++static int add_info(AVIOContext *bc, const char *type, const char *value){ + put_str(bc, type); + put_s(bc, -1); + put_str(bc, value); + return 1; + } + +-static int write_globalinfo(NUTContext *nut, ByteIOContext *bc){ ++static int write_globalinfo(NUTContext *nut, AVIOContext *bc){ + AVFormatContext *s= nut->avf; +- AVMetadataTag *t = NULL; +- ByteIOContext *dyn_bc; ++ AVDictionaryEntry *t = NULL; ++ AVIOContext *dyn_bc; + uint8_t *dyn_buf=NULL; + int count=0, dyn_size; +- int ret = url_open_dyn_buf(&dyn_bc); ++ int ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + +- while ((t = av_metadata_get(s->metadata, "", t, AV_METADATA_IGNORE_SUFFIX))) ++ while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) + count += add_info(dyn_bc, t->key, t->value); + + ff_put_v(bc, 0); //stream_if_plus1 +@@ -449,19 +452,19 @@ + + ff_put_v(bc, count); + +- dyn_size= url_close_dyn_buf(dyn_bc, &dyn_buf); +- put_buffer(bc, dyn_buf, dyn_size); ++ dyn_size= avio_close_dyn_buf(dyn_bc, &dyn_buf); ++ avio_write(bc, dyn_buf, dyn_size); + av_free(dyn_buf); + return 0; + } + +-static int write_streaminfo(NUTContext *nut, ByteIOContext *bc, int stream_id){ ++static int write_streaminfo(NUTContext *nut, AVIOContext *bc, int stream_id){ + AVFormatContext *s= nut->avf; + AVStream* st = s->streams[stream_id]; +- ByteIOContext *dyn_bc; ++ AVIOContext *dyn_bc; + uint8_t *dyn_buf=NULL; + int count=0, dyn_size, i; +- int ret = url_open_dyn_buf(&dyn_bc); ++ int ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + +@@ -469,7 +472,7 @@ + if (st->disposition & ff_nut_dispositions[i].flag) + count += add_info(dyn_bc, "Disposition", ff_nut_dispositions[i].str); + } +- dyn_size = url_close_dyn_buf(dyn_bc, &dyn_buf); ++ dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); + + if (count) { + ff_put_v(bc, stream_id + 1); //stream_id_plus1 +@@ -479,28 +482,56 @@ + + ff_put_v(bc, count); + +- put_buffer(bc, dyn_buf, dyn_size); ++ avio_write(bc, dyn_buf, dyn_size); + } + + av_free(dyn_buf); + return count; + } + +-static int write_headers(AVFormatContext *avctx, ByteIOContext *bc){ ++static int write_chapter(NUTContext *nut, AVIOContext *bc, int id) ++{ ++ AVIOContext *dyn_bc; ++ uint8_t *dyn_buf = NULL; ++ AVDictionaryEntry *t = NULL; ++ AVChapter *ch = nut->avf->chapters[id]; ++ int ret, dyn_size, count = 0; ++ ++ ret = avio_open_dyn_buf(&dyn_bc); ++ if (ret < 0) ++ return ret; ++ ++ ff_put_v(bc, 0); // stream_id_plus1 ++ put_s(bc, id + 1); // chapter_id ++ put_tt(nut, nut->chapter[id].time_base, bc, ch->start); // chapter_start ++ ff_put_v(bc, ch->end - ch->start); // chapter_len ++ ++ while ((t = av_dict_get(ch->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) ++ count += add_info(dyn_bc, t->key, t->value); ++ ++ ff_put_v(bc, count); ++ ++ dyn_size = avio_close_dyn_buf(dyn_bc, &dyn_buf); ++ avio_write(bc, dyn_buf, dyn_size); ++ av_freep(&dyn_buf); ++ return 0; ++} ++ ++static int write_headers(AVFormatContext *avctx, AVIOContext *bc){ + NUTContext *nut = avctx->priv_data; +- ByteIOContext *dyn_bc; ++ AVIOContext *dyn_bc; + int i, ret; + + ff_metadata_conv_ctx(avctx, ff_nut_metadata_conv, NULL); + +- ret = url_open_dyn_buf(&dyn_bc); ++ ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + write_mainheader(nut, dyn_bc); + put_packet(nut, bc, dyn_bc, 1, MAIN_STARTCODE); + + for (i=0; i < nut->avf->nb_streams; i++){ +- ret = url_open_dyn_buf(&dyn_bc); ++ ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + if ((ret = write_streamheader(avctx, dyn_bc, nut->avf->streams[i], i)) < 0) +@@ -508,14 +539,14 @@ + put_packet(nut, bc, dyn_bc, 1, STREAM_STARTCODE); + } + +- ret = url_open_dyn_buf(&dyn_bc); ++ ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + write_globalinfo(nut, dyn_bc); + put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); + + for (i = 0; i < nut->avf->nb_streams; i++) { +- ret = url_open_dyn_buf(&dyn_bc); ++ ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; + ret = write_streaminfo(nut, dyn_bc, i); +@@ -525,25 +556,47 @@ + put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); + else { + uint8_t* buf; +- url_close_dyn_buf(dyn_bc, &buf); ++ avio_close_dyn_buf(dyn_bc, &buf); + av_free(buf); + } + } + ++ for (i = 0; i < nut->avf->nb_chapters; i++) { ++ ret = avio_open_dyn_buf(&dyn_bc); ++ if (ret < 0) ++ return ret; ++ ret = write_chapter(nut, dyn_bc, i); ++ if (ret < 0) { ++ uint8_t *buf; ++ avio_close_dyn_buf(dyn_bc, &buf); ++ av_freep(&buf); ++ return ret; ++ } ++ put_packet(nut, bc, dyn_bc, 1, INFO_STARTCODE); ++ } ++ + nut->last_syncpoint_pos= INT_MIN; + nut->header_count++; + return 0; + } + +-static int write_header(AVFormatContext *s){ ++static int nut_write_header(AVFormatContext *s){ + NUTContext *nut = s->priv_data; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int i, j, ret; + + nut->avf= s; + + nut->stream = av_mallocz(sizeof(StreamContext)*s->nb_streams); +- nut->time_base= av_mallocz(sizeof(AVRational )*s->nb_streams); ++ nut->chapter = av_mallocz(sizeof(ChapterContext)*s->nb_chapters); ++ nut->time_base= av_mallocz(sizeof(AVRational )*(s->nb_streams + ++ s->nb_chapters)); ++ if (!nut->stream || !nut->chapter || !nut->time_base) { ++ av_freep(&nut->stream); ++ av_freep(&nut->chapter); ++ av_freep(&nut->time_base); ++ return AVERROR(ENOMEM); ++ } + + for(i=0; inb_streams; i++){ + AVStream *st= s->streams[i]; +@@ -551,7 +604,7 @@ + AVRational time_base; + ff_parse_specific_params(st->codec, &time_base.den, &ssize, &time_base.num); + +- av_set_pts_info(st, 64, time_base.num, time_base.den); ++ avpriv_set_pts_info(st, 64, time_base.num, time_base.den); + + for(j=0; jtime_base_count; j++){ + if(!memcmp(&time_base, &nut->time_base[j], sizeof(AVRational))){ +@@ -570,18 +623,32 @@ + nut->stream[i].max_pts_distance= FFMAX(time_base.den, time_base.num) / time_base.num; + } + ++ for (i = 0; i < s->nb_chapters; i++) { ++ AVChapter *ch = s->chapters[i]; ++ ++ for (j = 0; j < nut->time_base_count; j++) { ++ if (!memcmp(&ch->time_base, &nut->time_base[j], sizeof(AVRational))) ++ break; ++ } ++ ++ nut->time_base[j] = ch->time_base; ++ nut->chapter[i].time_base = &nut->time_base[j]; ++ if(j == nut->time_base_count) ++ nut->time_base_count++; ++ } ++ + nut->max_distance = MAX_DISTANCE; + build_elision_headers(s); + build_frame_code(s); + assert(nut->frame_code['N'].flags == FLAG_INVALID); + +- put_buffer(bc, ID_STRING, strlen(ID_STRING)); +- put_byte(bc, 0); ++ avio_write(bc, ID_STRING, strlen(ID_STRING)); ++ avio_w8(bc, 0); + + if ((ret = write_headers(s, bc)) < 0) + return ret; + +- put_flush_packet(bc); ++ avio_flush(bc); + + //FIXME index + +@@ -625,10 +692,10 @@ + return best_i; + } + +-static int write_packet(AVFormatContext *s, AVPacket *pkt){ ++static int nut_write_packet(AVFormatContext *s, AVPacket *pkt){ + NUTContext *nut = s->priv_data; + StreamContext *nus= &nut->stream[pkt->stream_index]; +- ByteIOContext *bc = s->pb, *dyn_bc; ++ AVIOContext *bc = s->pb, *dyn_bc; + FrameCode *fc; + int64_t coded_pts; + int best_length, frame_code, flags, needed_flags, i, header_idx, best_header_idx; +@@ -639,13 +706,13 @@ + if(pkt->pts < 0) + return -1; + +- if(1LL<<(20+3*nut->header_count) <= url_ftell(bc)) ++ if(1LL<<(20+3*nut->header_count) <= avio_tell(bc)) + write_headers(s, bc); + + if(key_frame && !(nus->last_flags & FLAG_KEY)) + store_sp= 1; + +- if(pkt->size + 30/*FIXME check*/ + url_ftell(bc) >= nut->last_syncpoint_pos + nut->max_distance) ++ if(pkt->size + 30/*FIXME check*/ + avio_tell(bc) >= nut->last_syncpoint_pos + nut->max_distance) + store_sp= 1; + + //FIXME: Ensure store_sp is 1 in the first place. +@@ -668,11 +735,11 @@ + sp= av_tree_find(nut->syncpoints, &dummy, (void *) ff_nut_sp_pos_cmp, + NULL); + +- nut->last_syncpoint_pos= url_ftell(bc); +- ret = url_open_dyn_buf(&dyn_bc); ++ nut->last_syncpoint_pos= avio_tell(bc); ++ ret = avio_open_dyn_buf(&dyn_bc); + if(ret < 0) + return ret; +- put_tt(nut, nus, dyn_bc, pkt->dts); ++ put_tt(nut, nus->time_base, dyn_bc, pkt->dts); + ff_put_v(dyn_bc, sp ? (nut->last_syncpoint_pos - sp->pos)>>4 : 0); + put_packet(nut, bc, dyn_bc, 1, SYNCPOINT_STARTCODE); + +@@ -748,8 +815,8 @@ + needed_flags= get_needed_flags(nut, nus, fc, pkt); + header_idx= fc->header_idx; + +- init_checksum(bc, ff_crc04C11DB7_update, 0); +- put_byte(bc, frame_code); ++ ffio_init_checksum(bc, ff_crc04C11DB7_update, 0); ++ avio_w8(bc, frame_code); + if(flags & FLAG_CODED){ + ff_put_v(bc, (flags^needed_flags) & ~(FLAG_CODED)); + flags = needed_flags; +@@ -759,10 +826,10 @@ + if(flags & FLAG_SIZE_MSB) ff_put_v(bc, pkt->size / fc->size_mul); + if(flags & FLAG_HEADER_IDX) ff_put_v(bc, header_idx= best_header_idx); + +- if(flags & FLAG_CHECKSUM) put_le32(bc, get_checksum(bc)); +- else get_checksum(bc); ++ if(flags & FLAG_CHECKSUM) avio_wl32(bc, ffio_get_checksum(bc)); ++ else ffio_get_checksum(bc); + +- put_buffer(bc, pkt->data + nut->header_len[header_idx], pkt->size - nut->header_len[header_idx]); ++ avio_write(bc, pkt->data + nut->header_len[header_idx], pkt->size - nut->header_len[header_idx]); + nus->last_flags= flags; + nus->last_pts= pkt->pts; + +@@ -779,37 +846,38 @@ + return 0; + } + +-static int write_trailer(AVFormatContext *s){ ++static int nut_write_trailer(AVFormatContext *s){ + NUTContext *nut= s->priv_data; +- ByteIOContext *bc= s->pb; ++ AVIOContext *bc= s->pb; + + while(nut->header_count<3) + write_headers(s, bc); +- put_flush_packet(bc); ++ avio_flush(bc); + ff_nut_free_sp(nut); + av_freep(&nut->stream); ++ av_freep(&nut->chapter); + av_freep(&nut->time_base); + + return 0; + } + + AVOutputFormat ff_nut_muxer = { +- "nut", +- NULL_IF_CONFIG_SMALL("NUT format"), +- "video/x-nut", +- "nut", +- sizeof(NUTContext), ++ .name = "nut", ++ .long_name = NULL_IF_CONFIG_SMALL("NUT format"), ++ .mime_type = "video/x-nut", ++ .extensions = "nut", ++ .priv_data_size = sizeof(NUTContext), + #if CONFIG_LIBVORBIS +- CODEC_ID_VORBIS, ++ .audio_codec = CODEC_ID_VORBIS, + #elif CONFIG_LIBMP3LAME +- CODEC_ID_MP3, ++ .audio_codec = CODEC_ID_MP3, + #else +- CODEC_ID_MP2, ++ .audio_codec = CODEC_ID_MP2, + #endif +- CODEC_ID_MPEG4, +- write_header, +- write_packet, +- write_trailer, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = nut_write_header, ++ .write_packet = nut_write_packet, ++ .write_trailer = nut_write_trailer, + .flags = AVFMT_GLOBALHEADER | AVFMT_VARIABLE_FPS, + .codec_tag = (const AVCodecTag * const []){ ff_codec_bmp_tags, ff_nut_video_tags, ff_codec_wav_tags, ff_nut_subtitle_tags, 0 }, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nut.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nut.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nut.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nut.h 2012-05-14 14:08:55.093355257 +0200 +@@ -82,6 +82,10 @@ + } StreamContext; + + typedef struct { ++ AVRational *time_base; ++} ChapterContext; ++ ++typedef struct { + AVFormatContext *avf; + // int written_packet_size; + // int64_t packet_start; +@@ -90,6 +94,7 @@ + const uint8_t *header[128]; + uint64_t next_startcode; ///< stores the next startcode if it has already been parsed but the stream is not seekable + StreamContext *stream; ++ ChapterContext *chapter; + unsigned int max_distance; + unsigned int time_base_count; + int64_t last_syncpoint_pos; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nuv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nuv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/nuv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/nuv.c 2012-05-14 14:08:55.100355398 +0200 +@@ -20,7 +20,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + + typedef struct { +@@ -45,114 +47,114 @@ + return 0; + } + +-//! little macro to sanitize packet size ++/// little macro to sanitize packet size + #define PKTSIZE(s) (s & 0xffffff) + + /** +- * \brief read until we found all data needed for decoding +- * \param vst video stream of which to change parameters +- * \param ast video stream of which to change parameters +- * \param myth set if this is a MythTVVideo format file +- * \return 1 if all required codec data was found ++ * @brief read until we found all data needed for decoding ++ * @param vst video stream of which to change parameters ++ * @param ast video stream of which to change parameters ++ * @param myth set if this is a MythTVVideo format file ++ * @return 1 if all required codec data was found + */ +-static int get_codec_data(ByteIOContext *pb, AVStream *vst, ++static int get_codec_data(AVIOContext *pb, AVStream *vst, + AVStream *ast, int myth) { + nuv_frametype frametype; + if (!vst && !myth) + return 1; // no codec data needed + while (!url_feof(pb)) { + int size, subtype; +- frametype = get_byte(pb); ++ frametype = avio_r8(pb); + switch (frametype) { + case NUV_EXTRADATA: +- subtype = get_byte(pb); +- url_fskip(pb, 6); +- size = PKTSIZE(get_le32(pb)); ++ subtype = avio_r8(pb); ++ avio_skip(pb, 6); ++ size = PKTSIZE(avio_rl32(pb)); + if (vst && subtype == 'R') { + vst->codec->extradata_size = size; + vst->codec->extradata = av_malloc(size); +- get_buffer(pb, vst->codec->extradata, size); ++ avio_read(pb, vst->codec->extradata, size); + size = 0; + if (!myth) + return 1; + } + break; + case NUV_MYTHEXT: +- url_fskip(pb, 7); +- size = PKTSIZE(get_le32(pb)); ++ avio_skip(pb, 7); ++ size = PKTSIZE(avio_rl32(pb)); + if (size != 128 * 4) + break; +- get_le32(pb); // version ++ avio_rl32(pb); // version + if (vst) { +- vst->codec->codec_tag = get_le32(pb); ++ vst->codec->codec_tag = avio_rl32(pb); + vst->codec->codec_id = + ff_codec_get_id(ff_codec_bmp_tags, vst->codec->codec_tag); + if (vst->codec->codec_tag == MKTAG('R', 'J', 'P', 'G')) + vst->codec->codec_id = CODEC_ID_NUV; + } else +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + + if (ast) { +- ast->codec->codec_tag = get_le32(pb); +- ast->codec->sample_rate = get_le32(pb); +- ast->codec->bits_per_coded_sample = get_le32(pb); +- ast->codec->channels = get_le32(pb); ++ ast->codec->codec_tag = avio_rl32(pb); ++ ast->codec->sample_rate = avio_rl32(pb); ++ ast->codec->bits_per_coded_sample = avio_rl32(pb); ++ ast->codec->channels = avio_rl32(pb); + ast->codec->codec_id = + ff_wav_codec_get_id(ast->codec->codec_tag, + ast->codec->bits_per_coded_sample); + ast->need_parsing = AVSTREAM_PARSE_FULL; + } else +- url_fskip(pb, 4 * 4); ++ avio_skip(pb, 4 * 4); + + size -= 6 * 4; +- url_fskip(pb, size); ++ avio_skip(pb, size); + return 1; + case NUV_SEEKP: + size = 11; + break; + default: +- url_fskip(pb, 7); +- size = PKTSIZE(get_le32(pb)); ++ avio_skip(pb, 7); ++ size = PKTSIZE(avio_rl32(pb)); + break; + } +- url_fskip(pb, size); ++ avio_skip(pb, size); + } + return 0; + } + + static int nuv_header(AVFormatContext *s, AVFormatParameters *ap) { + NUVContext *ctx = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + char id_string[12]; + double aspect, fps; + int is_mythtv, width, height, v_packs, a_packs; + int stream_nr = 0; + AVStream *vst = NULL, *ast = NULL; +- get_buffer(pb, id_string, 12); ++ avio_read(pb, id_string, 12); + is_mythtv = !memcmp(id_string, "MythTVVideo", 12); +- url_fskip(pb, 5); // version string +- url_fskip(pb, 3); // padding +- width = get_le32(pb); +- height = get_le32(pb); +- get_le32(pb); // unused, "desiredwidth" +- get_le32(pb); // unused, "desiredheight" +- get_byte(pb); // 'P' == progressive, 'I' == interlaced +- url_fskip(pb, 3); // padding +- aspect = av_int2dbl(get_le64(pb)); ++ avio_skip(pb, 5); // version string ++ avio_skip(pb, 3); // padding ++ width = avio_rl32(pb); ++ height = avio_rl32(pb); ++ avio_rl32(pb); // unused, "desiredwidth" ++ avio_rl32(pb); // unused, "desiredheight" ++ avio_r8(pb); // 'P' == progressive, 'I' == interlaced ++ avio_skip(pb, 3); // padding ++ aspect = av_int2double(avio_rl64(pb)); + if (aspect > 0.9999 && aspect < 1.0001) + aspect = 4.0 / 3.0; +- fps = av_int2dbl(get_le64(pb)); ++ fps = av_int2double(avio_rl64(pb)); + + // number of packets per stream type, -1 means unknown, e.g. streaming +- v_packs = get_le32(pb); +- a_packs = get_le32(pb); +- get_le32(pb); // text ++ v_packs = avio_rl32(pb); ++ a_packs = avio_rl32(pb); ++ avio_rl32(pb); // text + +- get_le32(pb); // keyframe distance (?) ++ avio_rl32(pb); // keyframe distance (?) + + if (v_packs) { + ctx->v_id = stream_nr++; +- vst = av_new_stream(s, ctx->v_id); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -162,13 +164,13 @@ + vst->codec->bits_per_coded_sample = 10; + vst->sample_aspect_ratio = av_d2q(aspect * height / width, 10000); + vst->r_frame_rate = av_d2q(fps, 60000); +- av_set_pts_info(vst, 32, 1, 1000); ++ avpriv_set_pts_info(vst, 32, 1, 1000); + } else + ctx->v_id = -1; + + if (a_packs) { + ctx->a_id = stream_nr++; +- ast = av_new_stream(s, ctx->a_id); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -178,7 +180,7 @@ + ast->codec->bit_rate = 2 * 2 * 44100 * 8; + ast->codec->block_align = 2 * 2; + ast->codec->bits_per_coded_sample = 16; +- av_set_pts_info(ast, 32, 1, 1000); ++ avpriv_set_pts_info(ast, 32, 1, 1000); + } else + ctx->a_id = -1; + +@@ -191,14 +193,14 @@ + + static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { + NUVContext *ctx = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t hdr[HDRSIZE]; + nuv_frametype frametype; + int ret, size; + while (!url_feof(pb)) { + int copyhdrsize = ctx->rtjpg_video ? HDRSIZE : 0; +- uint64_t pos = url_ftell(pb); +- ret = get_buffer(pb, hdr, HDRSIZE); ++ uint64_t pos = avio_tell(pb); ++ ret = avio_read(pb, hdr, HDRSIZE); + if (ret < HDRSIZE) + return ret < 0 ? ret : AVERROR(EIO); + frametype = hdr[0]; +@@ -206,32 +208,25 @@ + switch (frametype) { + case NUV_EXTRADATA: + if (!ctx->rtjpg_video) { +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + case NUV_VIDEO: + if (ctx->v_id < 0) { + av_log(s, AV_LOG_ERROR, "Video packet in file without video stream!\n"); +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + ret = av_new_packet(pkt, copyhdrsize + size); + if (ret < 0) + return ret; + +- // HACK: we have no idea if it is a keyframe, +- // but if we mark none seeking will not work at all. +- pkt->flags |= AV_PKT_FLAG_KEY; + pkt->pos = pos; ++ pkt->flags |= hdr[2] == 0 ? AV_PKT_FLAG_KEY : 0; + pkt->pts = AV_RL32(&hdr[4]); + pkt->stream_index = ctx->v_id; +- if(hdr[2] == 0) { +- AVStream *st = s->streams[pkt->stream_index]; +- pkt->flags |= PKT_FLAG_KEY; +- av_add_index_entry(st, pkt->pos, pkt->pts, size + HDRSIZE, 0, AVINDEX_KEYFRAME); +- } + memcpy(pkt->data, hdr, copyhdrsize); +- ret = get_buffer(pb, pkt->data + copyhdrsize, size); ++ ret = avio_read(pb, pkt->data + copyhdrsize, size); + if (ret < 0) { + av_free_packet(pkt); + return ret; +@@ -242,7 +237,7 @@ + case NUV_AUDIO: + if (ctx->a_id < 0) { + av_log(s, AV_LOG_ERROR, "Audio packet in file without audio stream!\n"); +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + ret = av_get_packet(pb, pkt, size); +@@ -256,7 +251,7 @@ + // contains no data, size value is invalid + break; + default: +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + } +@@ -265,27 +260,17 @@ + + /** + * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading +- * \return TRUE if the syncword is found. ++ * \return 1 if the syncword is found 0 otherwise. + */ + static int nuv_resync(AVFormatContext *s, int64_t pos_limit) { +- ByteIOContext *pb = s->pb; +- uint32_t tag; +- +- tag = get_be32(pb); +- while(!url_feof(pb) && url_ftell(pb) < pos_limit) { +- if(tag != MKBETAG('R','T','j','j')) { +- tag = (tag << 8) | get_byte(pb); +- continue; +- } +- tag = get_be32(pb); +- if(tag != MKBETAG('j','j','j','j')) +- continue; +- +- tag = get_be32(pb); +- if(tag != MKBETAG('j','j','j','j')) +- continue; +- +- return 1; ++ AVIOContext *pb = s->pb; ++ uint32_t tag = 0; ++ while(!url_feof(pb) && avio_tell(pb) < pos_limit) { ++ tag = (tag << 8) | avio_r8(pb); ++ if (tag == MKBETAG('R','T','j','j') && ++ (tag = avio_rb32(pb)) == MKBETAG('j','j','j','j') && ++ (tag = avio_rb32(pb)) == MKBETAG('j','j','j','j')) ++ return 1; + } + return 0; + } +@@ -295,23 +280,23 @@ + * \return timestamp if successfull and AV_NOPTS_VALUE if failure + */ + static int64_t nuv_read_dts(AVFormatContext *s, int stream_index, +- int64_t *ppos, int64_t pos_limit) ++ int64_t *ppos, int64_t pos_limit) + { + NUVContext *ctx = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + uint8_t hdr[HDRSIZE]; + nuv_frametype frametype; +- int size; ++ int size, key, idx; + int64_t pos, dts; + +- if (url_fseek(pb, *ppos, SEEK_SET) < 0) ++ if (avio_seek(pb, *ppos, SEEK_SET) < 0) + return AV_NOPTS_VALUE; + + if (!nuv_resync(s, pos_limit)) + return AV_NOPTS_VALUE; + +- while (!url_feof(pb) && url_ftell(pb) < pos_limit) { +- if (get_buffer(pb, hdr, HDRSIZE) <= 0) ++ while (!url_feof(pb) && avio_tell(pb) < pos_limit) { ++ if (avio_read(pb, hdr, HDRSIZE) < HDRSIZE) + return AV_NOPTS_VALUE; + frametype = hdr[0]; + size = PKTSIZE(AV_RL32(&hdr[8])); +@@ -320,19 +305,27 @@ + break; + case NUV_AUDIO: + case NUV_VIDEO: +- pos = url_ftell(s->pb) - HDRSIZE; +- dts = AV_RL32(&hdr[4]); +- // TODO - add general support in av_gen_search, so it adds positions after reading timestamps +- av_add_index_entry(s->streams[frametype == NUV_VIDEO ? ctx->v_id : ctx->a_id] +- , pos, dts, size + HDRSIZE, 0, hdr[2] == 0 ? AVINDEX_KEYFRAME : 0); ++ if (frametype == NUV_VIDEO) { ++ idx = ctx->v_id; ++ key = hdr[2] == 0; ++ } else { ++ idx = ctx->a_id; ++ key = 1; ++ } ++ if (stream_index == idx) { ++ ++ pos = avio_tell(s->pb) - HDRSIZE; ++ dts = AV_RL32(&hdr[4]); ++ ++ // TODO - add general support in av_gen_search, so it adds positions after reading timestamps ++ av_add_index_entry(s->streams[stream_index], pos, dts, size + HDRSIZE, 0, ++ key ? AVINDEX_KEYFRAME : 0); + +- if ((frametype == NUV_VIDEO && stream_index == ctx->v_id) || +- (frametype == NUV_AUDIO && stream_index == ctx->a_id)) { + *ppos = pos; + return dts; + } + default: +- url_fskip(pb, size); ++ avio_skip(pb, size); + break; + } + } +@@ -341,14 +334,12 @@ + + + AVInputFormat ff_nuv_demuxer = { +- "nuv", +- NULL_IF_CONFIG_SMALL("NuppelVideo format"), +- sizeof(NUVContext), +- nuv_probe, +- nuv_header, +- nuv_packet, +- NULL, +- NULL, +- nuv_read_dts, ++ .name = "nuv", ++ .long_name = NULL_IF_CONFIG_SMALL("NuppelVideo format"), ++ .priv_data_size = sizeof(NUVContext), ++ .read_probe = nuv_probe, ++ .read_header = nuv_header, ++ .read_packet = nuv_packet, ++ .read_timestamp = nuv_read_dts, + .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggdec.c 2012-05-14 14:08:55.102355438 +0200 +@@ -2,10 +2,9 @@ + * Ogg bitstream support + * Luca Barbato + * Based on tcvp implementation +- * + */ + +-/** ++/* + Copyright (C) 2005 Michael Ahlberg, MÃ¥ns RullgÃ¥rd + + Permission is hereby granted, free of charge, to any person +@@ -27,12 +26,12 @@ + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + DEALINGS IN THE SOFTWARE. +-**/ +- ++ */ + + #include + #include "oggdec.h" + #include "avformat.h" ++#include "internal.h" + #include "vorbiscomment.h" + + #define MAX_PAGE_SIZE 65307 +@@ -45,6 +44,7 @@ + &ff_vorbis_codec, + &ff_theora_codec, + &ff_flac_codec, ++ &ff_celt_codec, + &ff_old_dirac_codec, + &ff_old_flac_codec, + &ff_ogm_video_codec, +@@ -55,14 +55,13 @@ + }; + + //FIXME We could avoid some structure duplication +-static int +-ogg_save (AVFormatContext * s) ++static int ogg_save(AVFormatContext *s) + { + struct ogg *ogg = s->priv_data; + struct ogg_state *ost = + av_malloc(sizeof (*ost) + (ogg->nstreams-1) * sizeof (*ogg->streams)); + int i; +- ost->pos = url_ftell (s->pb); ++ ost->pos = avio_tell (s->pb); + ost->curidx = ogg->curidx; + ost->next = ogg->state; + ost->nstreams = ogg->nstreams; +@@ -80,11 +79,10 @@ + return 0; + } + +-static int +-ogg_restore (AVFormatContext * s, int discard) ++static int ogg_restore(AVFormatContext *s, int discard) + { + struct ogg *ogg = s->priv_data; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + struct ogg_state *ost = ogg->state; + int i; + +@@ -94,14 +92,24 @@ + ogg->state = ost->next; + + if (!discard){ ++ struct ogg_stream *old_streams = ogg->streams; ++ + for (i = 0; i < ogg->nstreams; i++) + av_free (ogg->streams[i].buf); + +- url_fseek (bc, ost->pos, SEEK_SET); ++ avio_seek (bc, ost->pos, SEEK_SET); + ogg->curidx = ost->curidx; + ogg->nstreams = ost->nstreams; +- memcpy(ogg->streams, ost->streams, +- ost->nstreams * sizeof(*ogg->streams)); ++ ogg->streams = av_realloc (ogg->streams, ++ ogg->nstreams * sizeof (*ogg->streams)); ++ ++ if (ogg->streams) { ++ memcpy(ogg->streams, ost->streams, ++ ost->nstreams * sizeof(*ogg->streams)); ++ } else { ++ av_free(old_streams); ++ ogg->nstreams = 0; ++ } + } + + av_free (ost); +@@ -109,8 +117,7 @@ + return 0; + } + +-static int +-ogg_reset (struct ogg * ogg) ++static int ogg_reset(struct ogg *ogg) + { + int i; + +@@ -134,8 +141,7 @@ + return 0; + } + +-static const struct ogg_codec * +-ogg_find_codec (uint8_t * buf, int size) ++static const struct ogg_codec *ogg_find_codec(uint8_t *buf, int size) + { + int i; + +@@ -147,8 +153,7 @@ + return NULL; + } + +-static int +-ogg_new_stream (AVFormatContext * s, uint32_t serial) ++static int ogg_new_stream(AVFormatContext *s, uint32_t serial, int new_avstream) + { + + struct ogg *ogg = s->priv_data; +@@ -165,17 +170,19 @@ + os->buf = av_malloc(os->bufsize); + os->header = -1; + +- st = av_new_stream (s, idx); +- if (!st) +- return AVERROR(ENOMEM); ++ if (new_avstream) { ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); + +- av_set_pts_info(st, 64, 1, 1000000); ++ st->id = idx; ++ avpriv_set_pts_info(st, 64, 1, 1000000); ++ } + + return idx; + } + +-static int +-ogg_new_buf(struct ogg *ogg, int idx) ++static int ogg_new_buf(struct ogg *ogg, int idx) + { + struct ogg_stream *os = ogg->streams + idx; + uint8_t *nb = av_malloc(os->bufsize); +@@ -191,24 +198,22 @@ + return 0; + } + +-static int +-ogg_read_page (AVFormatContext * s, int *str) ++static int ogg_read_page(AVFormatContext *s, int *str) + { +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + struct ogg *ogg = s->priv_data; + struct ogg_stream *os; +- int i = 0; ++ int ret, i = 0; + int flags, nsegs; + uint64_t gp; + uint32_t serial; +- uint32_t seq; +- uint32_t crc; + int size, idx; + uint8_t sync[4]; + int sp = 0; + +- if (get_buffer (bc, sync, 4) < 4) +- return -1; ++ ret = avio_read(bc, sync, 4); ++ if (ret < 4) ++ return ret < 0 ? ret : AVERROR_EOF; + + do{ + int c; +@@ -218,42 +223,55 @@ + sync[(sp + 2) & 3] == 'g' && sync[(sp + 3) & 3] == 'S') + break; + +- c = url_fgetc (bc); +- if (c < 0) +- return -1; ++ c = avio_r8(bc); ++ if (url_feof(bc)) ++ return AVERROR_EOF; + sync[sp++ & 3] = c; + }while (i++ < MAX_PAGE_SIZE); + + if (i >= MAX_PAGE_SIZE){ + av_log (s, AV_LOG_INFO, "ogg, can't find sync word\n"); +- return -1; ++ return AVERROR_INVALIDDATA; + } + +- if (url_fgetc (bc) != 0) /* version */ +- return -1; ++ if (avio_r8(bc) != 0) /* version */ ++ return AVERROR_INVALIDDATA; + +- flags = url_fgetc (bc); +- gp = get_le64 (bc); +- serial = get_le32 (bc); +- seq = get_le32 (bc); +- crc = get_le32 (bc); +- nsegs = url_fgetc (bc); ++ flags = avio_r8(bc); ++ gp = avio_rl64 (bc); ++ serial = avio_rl32 (bc); ++ avio_skip(bc, 8); /* seq, crc */ ++ nsegs = avio_r8(bc); + + idx = ogg_find_stream (ogg, serial); + if (idx < 0){ +- idx = ogg_new_stream (s, serial); ++ if (ogg->headers) { ++ int n; ++ ++ for (n = 0; n < ogg->nstreams; n++) { ++ av_freep(&ogg->streams[n].buf); ++ if (!ogg->state || ogg->state->streams[n].private != ogg->streams[n].private) ++ av_freep(&ogg->streams[n].private); ++ } ++ ogg->curidx = -1; ++ ogg->nstreams = 0; ++ idx = ogg_new_stream(s, serial, 0); ++ } else { ++ idx = ogg_new_stream(s, serial, 1); ++ } + if (idx < 0) +- return -1; ++ return idx; + } + + os = ogg->streams + idx; +- os->page_pos = url_ftell(bc) - 27; ++ os->page_pos = avio_tell(bc) - 27; + + if(os->psize > 0) + ogg_new_buf(ogg, idx); + +- if (get_buffer (bc, os->segments, nsegs) < nsegs) +- return -1; ++ ret = avio_read(bc, os->segments, nsegs); ++ if (ret < nsegs) ++ return ret < 0 ? ret : AVERROR_EOF; + + os->nsegs = nsegs; + os->segp = 0; +@@ -284,8 +302,9 @@ + os->buf = nb; + } + +- if (get_buffer (bc, os->buf + os->bufpos, size) < size) +- return -1; ++ ret = avio_read(bc, os->buf + os->bufpos, size); ++ if (ret < size) ++ return ret < 0 ? ret : AVERROR_EOF; + + os->bufpos += size; + os->granule = gp; +@@ -297,39 +316,36 @@ + return 0; + } + +-static int +-ogg_packet (AVFormatContext * s, int *str, int *dstart, int *dsize, int64_t *fpos) ++static int ogg_packet(AVFormatContext *s, int *str, int *dstart, int *dsize, ++ int64_t *fpos) + { + struct ogg *ogg = s->priv_data; +- int idx, i; ++ int idx, i, ret; + struct ogg_stream *os; + int complete = 0; + int segp = 0, psize = 0; + +-#if 0 +- av_log (s, AV_LOG_DEBUG, "ogg_packet: curidx=%i\n", ogg->curidx); +-#endif ++ av_dlog(s, "ogg_packet: curidx=%i\n", ogg->curidx); + + do{ + idx = ogg->curidx; + + while (idx < 0){ +- if (ogg_read_page (s, &idx) < 0) +- return -1; ++ ret = ogg_read_page(s, &idx); ++ if (ret < 0) ++ return ret; + } + + os = ogg->streams + idx; + +-#if 0 +- av_log (s, AV_LOG_DEBUG, +- "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n", ++ av_dlog(s, "ogg_packet: idx=%d pstart=%d psize=%d segp=%d nsegs=%d\n", + idx, os->pstart, os->psize, os->segp, os->nsegs); +-#endif + + if (!os->codec){ + if (os->header < 0){ + os->codec = ogg_find_codec (os->buf, os->bufpos); + if (!os->codec){ ++ av_log(s, AV_LOG_WARNING, "Codec not found\n"); + os->header = 0; + return 0; + } +@@ -356,11 +372,6 @@ + } + }while (!complete); + +-#if 0 +- av_log (s, AV_LOG_DEBUG, +- "ogg_packet: idx %i, frame size %i, start %i\n", +- idx, os->psize, os->pstart); +-#endif + + if (os->granule == -1) + av_log(s, AV_LOG_WARNING, "Page at %"PRId64" is missing granule\n", os->page_pos); +@@ -374,20 +385,17 @@ + os->segp = segp; + os->psize = psize; + +- // We have reached the first non-header packet. All header +- // packets must be complete before the first non-header +- // one, so everything that follows must be non-header. ++ // We have reached the first non-header packet in this stream. ++ // Unfortunately more header packets may still follow for others, ++ // but if we continue with header parsing we may lose data packets. + ogg->headers = 1; + + // Update the header state for all streams and + // compute the data_offset. +- s->data_offset = os->sync_pos; ++ if (!s->data_offset) ++ s->data_offset = os->sync_pos; + for (i = 0; i < ogg->nstreams; i++) { + struct ogg_stream *cur_os = ogg->streams + i; +- // Set stream header state to 0 if its last packet +- // was a header. +- if (cur_os->header > 0) +- cur_os->header = 0; + + // if we have a partial non-header packet, its start is + // obviously at or after the data start +@@ -413,6 +421,8 @@ + *fpos = os->sync_pos; + os->pstart += os->psize; + os->psize = 0; ++ if(os->pstart == os->bufpos) ++ os->bufpos = os->pstart = 0; + os->sync_pos = os->page_pos; + } + +@@ -431,71 +441,92 @@ + return 0; + } + +-static int +-ogg_get_headers (AVFormatContext * s) ++static int ogg_get_headers(AVFormatContext *s) + { + struct ogg *ogg = s->priv_data; ++ int ret; + + do{ +- if (ogg_packet (s, NULL, NULL, NULL, NULL) < 0) +- return -1; ++ ret = ogg_packet(s, NULL, NULL, NULL, NULL); ++ if (ret < 0) ++ return ret; + }while (!ogg->headers); + +-#if 0 +- av_log (s, AV_LOG_DEBUG, "found headers\n"); +-#endif ++ av_dlog(s, "found headers\n"); + + return 0; + } + +-static int +-ogg_get_length (AVFormatContext * s) ++static int ogg_get_length(AVFormatContext *s) + { + struct ogg *ogg = s->priv_data; + int i; + int64_t size, end; ++ int streams_left=0; + +- if(url_is_streamed(s->pb)) ++ if(!s->pb->seekable) + return 0; + + // already set + if (s->duration != AV_NOPTS_VALUE) + return 0; + +- size = url_fsize(s->pb); ++ size = avio_size(s->pb); + if(size < 0) + return 0; + end = size > MAX_PAGE_SIZE? size - MAX_PAGE_SIZE: 0; + + ogg_save (s); +- url_fseek (s->pb, end, SEEK_SET); ++ avio_seek (s->pb, end, SEEK_SET); + + while (!ogg_read_page (s, &i)){ + if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && + ogg->streams[i].codec) { + s->streams[i]->duration = + ogg_gptopts (s, i, ogg->streams[i].granule, NULL); +- if (s->streams[i]->start_time != AV_NOPTS_VALUE) ++ if (s->streams[i]->start_time != AV_NOPTS_VALUE){ + s->streams[i]->duration -= s->streams[i]->start_time; ++ streams_left-= (ogg->streams[i].got_start==-1); ++ ogg->streams[i].got_start= 1; ++ }else if(!ogg->streams[i].got_start){ ++ ogg->streams[i].got_start= -1; ++ streams_left++; ++ } + } + } + + ogg_restore (s, 0); + ++ ogg_save (s); ++ avio_seek (s->pb, 0, SEEK_SET); ++ while (!ogg_read_page (s, &i)){ ++ if (ogg->streams[i].granule != -1 && ogg->streams[i].granule != 0 && ++ ogg->streams[i].codec) { ++ if(s->streams[i]->duration && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){ ++ int64_t start= ogg_gptopts (s, i, ogg->streams[i].granule, NULL); ++ if(av_rescale_q(start, s->streams[i]->time_base, AV_TIME_BASE_Q) > AV_TIME_BASE) ++ s->streams[i]->duration -= start; ++ ogg->streams[i].got_start= 1; ++ streams_left--; ++ } ++ if(streams_left<=0) ++ break; ++ } ++ } ++ ogg_restore (s, 0); ++ + return 0; + } + +- +-static int +-ogg_read_header (AVFormatContext * s, AVFormatParameters * ap) ++static int ogg_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + struct ogg *ogg = s->priv_data; +- int i; ++ int ret, i; + ogg->curidx = -1; + //linear headers seek from start +- if (ogg_get_headers (s) < 0){ +- return -1; +- } ++ ret = ogg_get_headers(s); ++ if (ret < 0) ++ return ret; + + for (i = 0; i < ogg->nstreams; i++) + if (ogg->streams[i].header < 0) +@@ -538,20 +569,20 @@ + return pts; + } + +-static int +-ogg_read_packet (AVFormatContext * s, AVPacket * pkt) ++static int ogg_read_packet(AVFormatContext *s, AVPacket *pkt) + { + struct ogg *ogg; + struct ogg_stream *os; +- int idx = -1; ++ int idx = -1, ret; + int pstart, psize; + int64_t fpos, pts, dts; + + //Get an ogg packet + retry: + do{ +- if (ogg_packet (s, &idx, &pstart, &psize, &fpos) < 0) +- return AVERROR(EIO); ++ ret = ogg_packet(s, &idx, &pstart, &psize, &fpos); ++ if (ret < 0) ++ return ret; + }while (idx < 0 || !s->streams[idx]); + + ogg = s->priv_data; +@@ -565,8 +596,9 @@ + os->keyframe_seek = 0; + + //Alloc a pkt +- if (av_new_packet (pkt, psize) < 0) +- return AVERROR(EIO); ++ ret = av_new_packet(pkt, psize); ++ if (ret < 0) ++ return ret; + pkt->stream_index = idx; + memcpy (pkt->data, os->buf + pstart, psize); + +@@ -579,9 +611,7 @@ + return psize; + } + +- +-static int +-ogg_read_close (AVFormatContext * s) ++static int ogg_read_close(AVFormatContext *s) + { + struct ogg *ogg = s->priv_data; + int i; +@@ -594,21 +624,19 @@ + return 0; + } + +- +-static int64_t +-ogg_read_timestamp (AVFormatContext * s, int stream_index, int64_t * pos_arg, +- int64_t pos_limit) ++static int64_t ogg_read_timestamp(AVFormatContext *s, int stream_index, ++ int64_t *pos_arg, int64_t pos_limit) + { + struct ogg *ogg = s->priv_data; +- struct ogg_stream *os = ogg->streams + stream_index; +- ByteIOContext *bc = s->pb; ++ AVIOContext *bc = s->pb; + int64_t pts = AV_NOPTS_VALUE; +- int i; +- url_fseek(bc, *pos_arg, SEEK_SET); ++ int i = -1; ++ avio_seek(bc, *pos_arg, SEEK_SET); + ogg_reset(ogg); + +- while (url_ftell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) { ++ while (avio_tell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) { + if (i == stream_index) { ++ struct ogg_stream *os = ogg->streams + stream_index; + pts = ogg_calc_pts(s, i, NULL); + if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY)) + pts = AV_NOPTS_VALUE; +@@ -620,7 +648,8 @@ + return pts; + } + +-static int ogg_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) ++static int ogg_read_seek(AVFormatContext *s, int stream_index, ++ int64_t timestamp, int flags) + { + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + stream_index; +@@ -632,32 +661,32 @@ + && !(flags & AVSEEK_FLAG_ANY)) + os->keyframe_seek = 1; + +- ret = av_seek_frame_binary(s, stream_index, timestamp, flags); +- if (ret < 0) ++ ret = ff_seek_frame_binary(s, stream_index, timestamp, flags); ++ os = ogg->streams + stream_index; ++ if (ret < 0) { + os->keyframe_seek = 0; ++ ret = AVERROR(ENOSYS); ++ } + return ret; + } + + static int ogg_probe(AVProbeData *p) + { +- if (p->buf[0] == 'O' && p->buf[1] == 'g' && +- p->buf[2] == 'g' && p->buf[3] == 'S' && +- p->buf[4] == 0x0 && p->buf[5] <= 0x7 ) ++ if (!memcmp("OggS", p->buf, 5) && p->buf[5] <= 0x7) + return AVPROBE_SCORE_MAX; +- else +- return 0; ++ return 0; + } + + AVInputFormat ff_ogg_demuxer = { +- "ogg", +- NULL_IF_CONFIG_SMALL("Ogg"), +- sizeof (struct ogg), +- ogg_probe, +- ogg_read_header, +- ogg_read_packet, +- ogg_read_close, +- ogg_read_seek, +- ogg_read_timestamp, +- .extensions = "ogg", +- .flags = AVFMT_GENERIC_INDEX, ++ .name = "ogg", ++ .long_name = NULL_IF_CONFIG_SMALL("Ogg"), ++ .priv_data_size = sizeof(struct ogg), ++ .read_probe = ogg_probe, ++ .read_header = ogg_read_header, ++ .read_packet = ogg_read_packet, ++ .read_close = ogg_read_close, ++ .read_seek = ogg_read_seek, ++ .read_timestamp = ogg_read_timestamp, ++ .extensions = "ogg", ++ .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggdec.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggdec.h 2012-05-14 14:08:55.103355458 +0200 +@@ -75,6 +75,7 @@ + int incomplete; ///< whether we're expecting a continuation in the next page + int page_end; ///< current packet is the last one completed in the page + int keyframe_seek; ++ int got_start; + void *private; + }; + +@@ -98,6 +99,7 @@ + #define OGG_FLAG_BOS 2 + #define OGG_FLAG_EOS 4 + ++extern const struct ogg_codec ff_celt_codec; + extern const struct ogg_codec ff_dirac_codec; + extern const struct ogg_codec ff_flac_codec; + extern const struct ogg_codec ff_ogm_audio_codec; +@@ -111,7 +113,7 @@ + extern const struct ogg_codec ff_theora_codec; + extern const struct ogg_codec ff_vorbis_codec; + +-int ff_vorbis_comment(AVFormatContext *ms, AVMetadata **m, const uint8_t *buf, int size); ++int ff_vorbis_comment(AVFormatContext *ms, AVDictionary **m, const uint8_t *buf, int size); + + static inline int + ogg_find_stream (struct ogg * ogg, int serial) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggenc.c 2012-05-14 14:08:55.104355479 +0200 +@@ -20,11 +20,14 @@ + */ + + #include "libavutil/crc.h" ++#include "libavutil/opt.h" ++#include "libavutil/mathematics.h" + #include "libavutil/random_seed.h" + #include "libavcodec/xiph.h" + #include "libavcodec/bytestream.h" + #include "libavcodec/flac.h" + #include "avformat.h" ++#include "avio_internal.h" + #include "internal.h" + #include "vorbiscomment.h" + +@@ -61,51 +64,68 @@ + } OGGPageList; + + typedef struct { ++ const AVClass *class; + OGGPageList *page_list; ++ int pref_size; ///< preferred page size (0 => fill all segments) + } OGGContext; + +-static void ogg_update_checksum(AVFormatContext *s, ByteIOContext *pb, int64_t crc_offset) ++ ++static const AVOption options[] = { ++ { "oggpagesize", "Set preferred Ogg page size.", ++ offsetof(OGGContext, pref_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, MAX_PAGE_SIZE, AV_OPT_FLAG_ENCODING_PARAM}, ++ { NULL }, ++}; ++ ++static const AVClass ogg_muxer_class = { ++ "Ogg muxer", ++ av_default_item_name, ++ options, ++ LIBAVUTIL_VERSION_INT, ++}; ++ ++ ++static void ogg_update_checksum(AVFormatContext *s, AVIOContext *pb, int64_t crc_offset) + { +- int64_t pos = url_ftell(pb); +- uint32_t checksum = get_checksum(pb); +- url_fseek(pb, crc_offset, SEEK_SET); +- put_be32(pb, checksum); +- url_fseek(pb, pos, SEEK_SET); ++ int64_t pos = avio_tell(pb); ++ uint32_t checksum = ffio_get_checksum(pb); ++ avio_seek(pb, crc_offset, SEEK_SET); ++ avio_wb32(pb, checksum); ++ avio_seek(pb, pos, SEEK_SET); + } + + static int ogg_write_page(AVFormatContext *s, OGGPage *page, int extra_flags) + { + OGGStreamContext *oggstream = s->streams[page->stream_index]->priv_data; +- ByteIOContext *pb; ++ AVIOContext *pb; + int64_t crc_offset; + int ret, size; + uint8_t *buf; + +- ret = url_open_dyn_buf(&pb); ++ ret = avio_open_dyn_buf(&pb); + if (ret < 0) + return ret; +- init_checksum(pb, ff_crc04C11DB7_update, 0); +- put_tag(pb, "OggS"); +- put_byte(pb, 0); +- put_byte(pb, page->flags | extra_flags); +- put_le64(pb, page->granule); +- put_le32(pb, oggstream->serial_num); +- put_le32(pb, oggstream->page_counter++); +- crc_offset = url_ftell(pb); +- put_le32(pb, 0); // crc +- put_byte(pb, page->segments_count); +- put_buffer(pb, page->segments, page->segments_count); +- put_buffer(pb, page->data, page->size); ++ ffio_init_checksum(pb, ff_crc04C11DB7_update, 0); ++ ffio_wfourcc(pb, "OggS"); ++ avio_w8(pb, 0); ++ avio_w8(pb, page->flags | extra_flags); ++ avio_wl64(pb, page->granule); ++ avio_wl32(pb, oggstream->serial_num); ++ avio_wl32(pb, oggstream->page_counter++); ++ crc_offset = avio_tell(pb); ++ avio_wl32(pb, 0); // crc ++ avio_w8(pb, page->segments_count); ++ avio_write(pb, page->segments, page->segments_count); ++ avio_write(pb, page->data, page->size); + + ogg_update_checksum(s, pb, crc_offset); +- put_flush_packet(pb); ++ avio_flush(pb); + +- size = url_close_dyn_buf(pb, &buf); ++ size = avio_close_dyn_buf(pb, &buf); + if (size < 0) + return size; + +- put_buffer(s->pb, buf, size); +- put_flush_packet(s->pb); ++ avio_write(s->pb, buf, size); ++ avio_flush(s->pb); + av_free(buf); + oggstream->page_count--; + return 0; +@@ -173,6 +193,7 @@ + uint8_t *data, unsigned size, int64_t granule) + { + OGGStreamContext *oggstream = st->priv_data; ++ OGGContext *ogg = s->priv_data; + int total_segments = size / 255 + 1; + uint8_t *p = data; + int i, segments, len, flush = 0; +@@ -208,8 +229,9 @@ + if (i == total_segments) + page->granule = granule; + +- if (page->segments_count == 255) { +- ogg_buffer_page(s, oggstream); ++ if(page->segments_count == 255 || ++ (ogg->pref_size > 0 && page->size >= ogg->pref_size)) { ++ ogg_buffer_page(s, oggstream); + } + } + +@@ -220,7 +242,7 @@ + } + + static uint8_t *ogg_write_vorbiscomment(int offset, int bitexact, +- int *header_len, AVMetadata **m, int framing_bit) ++ int *header_len, AVDictionary **m, int framing_bit) + { + const char *vendor = bitexact ? "ffmpeg" : LIBAVFORMAT_IDENT; + int size; +@@ -246,13 +268,13 @@ + + static int ogg_build_flac_headers(AVCodecContext *avctx, + OGGStreamContext *oggstream, int bitexact, +- AVMetadata **m) ++ AVDictionary **m) + { + enum FLACExtradataFormat format; + uint8_t *streaminfo; + uint8_t *p; + +- if (!ff_flac_is_extradata_valid(avctx, &format, &streaminfo)) ++ if (!avpriv_flac_is_extradata_valid(avctx, &format, &streaminfo)) + return -1; + + // first packet: STREAMINFO +@@ -286,7 +308,7 @@ + + static int ogg_build_speex_headers(AVCodecContext *avctx, + OGGStreamContext *oggstream, int bitexact, +- AVMetadata **m) ++ AVDictionary **m) + { + uint8_t *p; + +@@ -321,9 +343,9 @@ + unsigned serial_num = i; + + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + else if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) +- av_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); ++ avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + if (st->codec->codec_id != CODEC_ID_VORBIS && + st->codec->codec_id != CODEC_ID_THEORA && + st->codec->codec_id != CODEC_ID_SPEEX && +@@ -375,7 +397,7 @@ + int header_type = st->codec->codec_id == CODEC_ID_VORBIS ? 3 : 0x81; + int framing_bit = st->codec->codec_id == CODEC_ID_VORBIS ? 1 : 0; + +- if (ff_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, ++ if (avpriv_split_xiph_headers(st->codec->extradata, st->codec->extradata_size, + st->codec->codec_id == CODEC_ID_VORBIS ? 30 : 42, + oggstream->header, oggstream->header_len) < 0) { + av_log(s, AV_LOG_ERROR, "Extradata corrupted\n"); +@@ -494,23 +516,26 @@ + OGGStreamContext *oggstream = st->priv_data; + if (st->codec->codec_id == CODEC_ID_FLAC || + st->codec->codec_id == CODEC_ID_SPEEX) { +- av_free(oggstream->header[0]); +- av_free(oggstream->header[1]); ++ av_freep(&oggstream->header[0]); ++ av_freep(&oggstream->header[1]); + } ++ else ++ av_freep(&oggstream->header[1]); + av_freep(&st->priv_data); + } + return 0; + } + + AVOutputFormat ff_ogg_muxer = { +- "ogg", +- NULL_IF_CONFIG_SMALL("Ogg"), +- "application/ogg", +- "ogg,ogv,spx", +- sizeof(OGGContext), +- CODEC_ID_FLAC, +- CODEC_ID_THEORA, +- ogg_write_header, +- ogg_write_packet, +- ogg_write_trailer, ++ .name = "ogg", ++ .long_name = NULL_IF_CONFIG_SMALL("Ogg"), ++ .mime_type = "application/ogg", ++ .extensions = "ogg,ogv,spx", ++ .priv_data_size = sizeof(OGGContext), ++ .audio_codec = CODEC_ID_FLAC, ++ .video_codec = CODEC_ID_THEORA, ++ .write_header = ogg_write_header, ++ .write_packet = ogg_write_packet, ++ .write_trailer = ogg_write_trailer, ++ .priv_class = &ogg_muxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsecelt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsecelt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsecelt.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsecelt.c 2012-05-14 14:08:55.105355499 +0200 +@@ -0,0 +1,96 @@ ++/* ++ * Xiph CELT parser for Ogg ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++#include "oggdec.h" ++ ++struct oggcelt_private { ++ int extra_headers_left; ++}; ++ ++static int celt_header(AVFormatContext *s, int idx) ++{ ++ struct ogg *ogg = s->priv_data; ++ struct ogg_stream *os = ogg->streams + idx; ++ AVStream *st = s->streams[idx]; ++ struct oggcelt_private *priv = os->private; ++ uint8_t *p = os->buf + os->pstart; ++ ++ if (os->psize == 60 && ++ !memcmp(p, ff_celt_codec.magic, ff_celt_codec.magicsize)) { ++ /* Main header */ ++ ++ uint32_t version, sample_rate, nb_channels, frame_size; ++ uint32_t overlap, extra_headers; ++ uint8_t *extradata; ++ ++ extradata = av_malloc(2 * sizeof(uint32_t) + ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ priv = av_malloc(sizeof(struct oggcelt_private)); ++ if (!extradata || !priv) { ++ av_free(extradata); ++ av_free(priv); ++ return AVERROR(ENOMEM); ++ } ++ version = AV_RL32(p + 28); ++ /* unused header size field skipped */ ++ sample_rate = AV_RL32(p + 36); ++ nb_channels = AV_RL32(p + 40); ++ frame_size = AV_RL32(p + 44); ++ overlap = AV_RL32(p + 48); ++ /* unused bytes per packet field skipped */ ++ extra_headers = AV_RL32(p + 56); ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = CODEC_ID_CELT; ++ st->codec->sample_rate = sample_rate; ++ st->codec->channels = nb_channels; ++ st->codec->frame_size = frame_size; ++ av_free(st->codec->extradata); ++ st->codec->extradata = extradata; ++ st->codec->extradata_size = 2 * sizeof(uint32_t); ++ if (sample_rate) ++ avpriv_set_pts_info(st, 64, 1, sample_rate); ++ priv->extra_headers_left = 1 + extra_headers; ++ av_free(os->private); ++ os->private = priv; ++ AV_WL32(extradata + 0, overlap); ++ AV_WL32(extradata + 4, version); ++ return 1; ++ } else if (priv && priv->extra_headers_left) { ++ /* Extra headers (vorbiscomment) */ ++ ++ ff_vorbis_comment(s, &st->metadata, p, os->psize); ++ priv->extra_headers_left--; ++ return 1; ++ } else { ++ return 0; ++ } ++} ++ ++const struct ogg_codec ff_celt_codec = { ++ .magic = "CELT ", ++ .magicsize = 8, ++ .header = celt_header, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsedirac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsedirac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsedirac.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsedirac.c 2012-05-14 14:08:55.105355499 +0200 +@@ -21,6 +21,7 @@ + #include "libavcodec/get_bits.h" + #include "libavcodec/dirac.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + + static int dirac_header(AVFormatContext *s, int idx) +@@ -36,13 +37,13 @@ + return 0; + + init_get_bits(&gb, os->buf + os->pstart + 13, (os->psize - 13) * 8); +- if (ff_dirac_parse_sequence_header(st->codec, &gb, &source) < 0) ++ if (avpriv_dirac_parse_sequence_header(st->codec, &gb, &source) < 0) + return -1; + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_DIRAC; + // dirac in ogg always stores timestamps as though the video were interlaced +- st->time_base = (AVRational){st->codec->time_base.num, 2*st->codec->time_base.den}; ++ avpriv_set_pts_info(st, 64, st->codec->time_base.num, 2*st->codec->time_base.den); + return 1; + } + +@@ -79,8 +80,7 @@ + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_DIRAC; +- st->time_base.den = AV_RB32(buf+8); +- st->time_base.num = AV_RB32(buf+12); ++ avpriv_set_pts_info(st, 64, AV_RB32(buf+12), AV_RB32(buf+8)); + return 1; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseflac.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseflac.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseflac.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseflac.c 2012-05-14 14:08:55.106355519 +0200 +@@ -22,6 +22,7 @@ + #include "libavcodec/get_bits.h" + #include "libavcodec/flac.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + + #define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F +@@ -55,7 +56,7 @@ + if (get_bits_long(&gb, 32) != FLAC_STREAMINFO_SIZE) + return -1; + +- ff_flac_parse_streaminfo(st->codec, &si, streaminfo_start); ++ avpriv_flac_parse_streaminfo(st->codec, &si, streaminfo_start); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_FLAC; +@@ -65,8 +66,7 @@ + memcpy(st->codec->extradata, streaminfo_start, FLAC_STREAMINFO_SIZE); + st->codec->extradata_size = FLAC_STREAMINFO_SIZE; + +- st->time_base.num = 1; +- st->time_base.den = st->codec->sample_rate; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + } else if (mdt == FLAC_METADATA_TYPE_VORBIS_COMMENT) { + ff_vorbis_comment (s, &st->metadata, os->buf + os->pstart + 4, os->psize - 4); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseogm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseogm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseogm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseogm.c 2012-05-14 14:08:55.107355539 +0200 +@@ -27,6 +27,7 @@ + #include "libavcodec/get_bits.h" + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + #include "riff.h" + +@@ -39,7 +40,6 @@ + const uint8_t *p = os->buf + os->pstart; + uint64_t time_unit; + uint64_t spu; +- uint32_t default_len; + + if(!(*p & 1)) + return 0; +@@ -74,8 +74,7 @@ + + time_unit = bytestream_get_le64(&p); + spu = bytestream_get_le64(&p); +- default_len = bytestream_get_le32(&p); +- ++ p += 4; /* default_len */ + p += 8; /* buffersize + bits_per_sample */ + + if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO){ +@@ -83,14 +82,13 @@ + st->codec->height = bytestream_get_le32(&p); + st->codec->time_base.den = spu * 10000000; + st->codec->time_base.num = time_unit; +- st->time_base = st->codec->time_base; ++ avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + } else { + st->codec->channels = bytestream_get_le16(&p); + p += 2; /* block_align */ + st->codec->bit_rate = bytestream_get_le32(&p) * 8; + st->codec->sample_rate = spu * 10000000 / time_unit; +- st->time_base.num = 1; +- st->time_base.den = st->codec->sample_rate; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + } + } else if (*p == 3) { + if (os->psize > 8) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseskeleton.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseskeleton.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparseskeleton.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparseskeleton.c 2012-05-14 14:08:55.108355559 +0200 +@@ -20,6 +20,7 @@ + + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + + static int skeleton_header(AVFormatContext *s, int idx) +@@ -60,8 +61,9 @@ + start_den = AV_RL64(buf+20); + + if (start_den) { +- av_reduce(&start_time, &st->time_base.den, start_num, start_den, INT_MAX); +- st->time_base.num = 1; ++ int base_den; ++ av_reduce(&start_time, &base_den, start_num, start_den, INT_MAX); ++ avpriv_set_pts_info(st, 64, 1, base_den); + os->lastpts = + st->start_time = start_time; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsespeex.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsespeex.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsespeex.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsespeex.c 2012-05-14 14:08:55.108355559 +0200 +@@ -28,9 +28,11 @@ + #include "libavcodec/get_bits.h" + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + + struct speex_params { ++ int packet_size; + int final_packet_duration; + int seq; + }; +@@ -58,22 +60,17 @@ + st->codec->sample_rate = AV_RL32(p + 36); + st->codec->channels = AV_RL32(p + 48); + +- /* We treat the whole Speex packet as a single frame everywhere Speex +- is handled in FFmpeg. This avoids the complexities of splitting +- and joining individual Speex frames, which are not always +- byte-aligned. */ +- st->codec->frame_size = AV_RL32(p + 56); +- frames_per_packet = AV_RL32(p + 64); ++ spxp->packet_size = AV_RL32(p + 56); ++ frames_per_packet = AV_RL32(p + 64); + if (frames_per_packet) +- st->codec->frame_size *= frames_per_packet; ++ spxp->packet_size *= frames_per_packet; + + st->codec->extradata_size = os->psize; + st->codec->extradata = av_malloc(st->codec->extradata_size + + FF_INPUT_BUFFER_PADDING_SIZE); + memcpy(st->codec->extradata, p, st->codec->extradata_size); + +- st->time_base.num = 1; +- st->time_base.den = st->codec->sample_rate; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + } else + ff_vorbis_comment(s, &st->metadata, p, os->psize); + +@@ -96,7 +93,7 @@ + struct ogg *ogg = s->priv_data; + struct ogg_stream *os = ogg->streams + idx; + struct speex_params *spxp = os->private; +- int packet_size = s->streams[idx]->codec->frame_size; ++ int packet_size = spxp->packet_size; + + if (os->flags & OGG_FLAG_EOS && os->lastpts != AV_NOPTS_VALUE && + os->granule > 0) { +@@ -109,9 +106,10 @@ + + if (!os->lastpts && os->granule > 0) + /* first packet */ +- os->pduration = os->granule - packet_size * (ogg_page_packets(os) - 1); +- else if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs && +- spxp->final_packet_duration) ++ os->lastpts = os->lastdts = os->granule - packet_size * ++ ogg_page_packets(os); ++ if (os->flags & OGG_FLAG_EOS && os->segp == os->nsegs && ++ spxp->final_packet_duration) + /* final packet */ + os->pduration = spxp->final_packet_duration; + else +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsetheora.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsetheora.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsetheora.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsetheora.c 2012-05-14 14:08:55.109355579 +0200 +@@ -26,6 +26,7 @@ + #include "libavutil/bswap.h" + #include "libavcodec/get_bits.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + + struct theora_params { +@@ -91,7 +92,7 @@ + st->codec->time_base.num = 1; + st->codec->time_base.den = 25; + } +- st->time_base = st->codec->time_base; ++ avpriv_set_pts_info(st, 64, st->codec->time_base.num, st->codec->time_base.den); + + st->sample_aspect_ratio.num = get_bits_long(&gb, 24); + st->sample_aspect_ratio.den = get_bits_long(&gb, 24); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsevorbis.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsevorbis.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oggparsevorbis.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oggparsevorbis.c 2012-05-14 14:08:55.110355599 +0200 +@@ -25,9 +25,11 @@ + #include + #include "libavutil/avstring.h" + #include "libavutil/bswap.h" ++#include "libavutil/dict.h" + #include "libavcodec/get_bits.h" + #include "libavcodec/bytestream.h" + #include "avformat.h" ++#include "internal.h" + #include "oggdec.h" + #include "vorbiscomment.h" + +@@ -43,7 +45,7 @@ + if (sscanf(val, "%02d:%02d:%02d.%03d", &h, &m, &s, &ms) < 4) + return 0; + +- ff_new_chapter(as, cnum, (AVRational){1,1000}, ++ avpriv_new_chapter(as, cnum, (AVRational){1,1000}, + ms + 1000*(s + 60*(m + 60*h)), + AV_NOPTS_VALUE, NULL); + av_free(val); +@@ -56,8 +58,8 @@ + if (!chapter) + return 0; + +- av_metadata_set2(&chapter->metadata, "title", val, +- AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&chapter->metadata, "title", val, ++ AV_DICT_DONT_STRDUP_VAL); + } else + return 0; + +@@ -66,7 +68,7 @@ + } + + int +-ff_vorbis_comment(AVFormatContext * as, AVMetadata **m, const uint8_t *buf, int size) ++ff_vorbis_comment(AVFormatContext * as, AVDictionary **m, const uint8_t *buf, int size) + { + const uint8_t *p = buf; + const uint8_t *end = buf + size; +@@ -126,9 +128,9 @@ + ct[vl] = 0; + + if (!ogm_chapter(as, tt, ct)) +- av_metadata_set2(m, tt, ct, +- AV_METADATA_DONT_STRDUP_KEY | +- AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(m, tt, ct, ++ AV_DICT_DONT_STRDUP_KEY | ++ AV_DICT_DONT_STRDUP_VAL); + } + } + +@@ -252,8 +254,7 @@ + + if (srate > 0) { + st->codec->sample_rate = srate; +- st->time_base.num = 1; +- st->time_base.den = srate; ++ avpriv_set_pts_info(st, 64, 1, srate); + } + } else if (os->buf[os->pstart] == 3) { + if (os->psize > 8 && +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oma.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oma.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oma.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oma.c 2012-05-14 14:08:55.111355619 +0200 +@@ -1,8 +1,5 @@ + /* +- * Sony OpenMG (OMA) demuxer +- * +- * Copyright (c) 2008 Maxim Poliakovski +- * 2008 Benjamin Larsson ++ * Sony OpenMG (OMA) common data + * + * This file is part of FFmpeg. + * +@@ -21,185 +18,17 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/** +- * @file +- * This is a demuxer for Sony OpenMG Music files +- * +- * Known file extensions: ".oma", "aa3" +- * The format of such files consists of three parts: +- * - "ea3" header carrying overall info and metadata. Except for starting with +- * "ea" instead of "ID", it's an ID3v2 header. +- * - "EA3" header is a Sony-specific header containing information about +- * the OpenMG file: codec type (usually ATRAC, can also be MP3 or WMA), +- * codec specific info (packet size, sample rate, channels and so on) +- * and DRM related info (file encryption, content id). +- * - Sound data organized in packets follow the EA3 header +- * (can be encrypted using the Sony DRM!). +- * +- * LIMITATIONS: This version supports only plain (unencrypted) OMA files. +- * If any DRM-protected (encrypted) file is encountered you will get the +- * corresponding error message. Try to remove the encryption using any +- * Sony software (for example SonicStage). +- * CODEC SUPPORT: Only ATRAC3 codec is currently supported! +- */ +- +-#include "avformat.h" +-#include "libavutil/intreadwrite.h" +-#include "pcm.h" +-#include "riff.h" +-#include "id3v2.h" +- +-#define EA3_HEADER_SIZE 96 +- +-enum { +- OMA_CODECID_ATRAC3 = 0, +- OMA_CODECID_ATRAC3P = 1, +- OMA_CODECID_MP3 = 3, +- OMA_CODECID_LPCM = 4, +- OMA_CODECID_WMA = 5, +-}; +- +-static const AVCodecTag codec_oma_tags[] = { +- { CODEC_ID_ATRAC3, OMA_CODECID_ATRAC3 }, +- { CODEC_ID_ATRAC3P, OMA_CODECID_ATRAC3P }, +- { CODEC_ID_MP3, OMA_CODECID_MP3 }, +-}; +- +-#define ID3v2_EA3_MAGIC "ea3" +- +-static int oma_read_header(AVFormatContext *s, +- AVFormatParameters *ap) +-{ +- static const uint16_t srate_tab[6] = {320,441,480,882,960,0}; +- int ret, framesize, jsflag, samplerate; +- uint32_t codec_params; +- int16_t eid; +- uint8_t buf[EA3_HEADER_SIZE]; +- uint8_t *edata; +- AVStream *st; +- +- ff_id3v2_read(s, ID3v2_EA3_MAGIC); +- ret = get_buffer(s->pb, buf, EA3_HEADER_SIZE); +- +- if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}),3) || buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) { +- av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n"); +- return -1; +- } +- +- eid = AV_RB16(&buf[6]); +- if (eid != -1 && eid != -128) { +- av_log(s, AV_LOG_ERROR, "Encrypted file! Eid: %d\n", eid); +- return -1; +- } +- +- codec_params = AV_RB24(&buf[33]); +- +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- +- st->start_time = 0; +- st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- st->codec->codec_tag = buf[32]; +- st->codec->codec_id = ff_codec_get_id(codec_oma_tags, st->codec->codec_tag); +- +- switch (buf[32]) { +- case OMA_CODECID_ATRAC3: +- samplerate = srate_tab[(codec_params >> 13) & 7]*100; +- if (samplerate != 44100) +- av_log(s, AV_LOG_ERROR, "Unsupported sample rate, send sample file to developers: %d\n", samplerate); +- +- framesize = (codec_params & 0x3FF) * 8; +- jsflag = (codec_params >> 17) & 1; /* get stereo coding mode, 1 for joint-stereo */ +- st->codec->channels = 2; +- st->codec->sample_rate = samplerate; +- st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024; +- +- /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */ +- st->codec->extradata_size = 14; +- edata = av_mallocz(14 + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!edata) +- return AVERROR(ENOMEM); +- +- st->codec->extradata = edata; +- AV_WL16(&edata[0], 1); // always 1 +- AV_WL32(&edata[2], samplerate); // samples rate +- AV_WL16(&edata[6], jsflag); // coding mode +- AV_WL16(&edata[8], jsflag); // coding mode +- AV_WL16(&edata[10], 1); // always 1 +- // AV_WL16(&edata[12], 0); // always 0 +- +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); +- break; +- case OMA_CODECID_ATRAC3P: +- st->codec->channels = (codec_params >> 10) & 7; +- framesize = ((codec_params & 0x3FF) * 8) + 8; +- st->codec->sample_rate = srate_tab[(codec_params >> 13) & 7]*100; +- st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024; +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); +- av_log(s, AV_LOG_ERROR, "Unsupported codec ATRAC3+!\n"); +- break; +- case OMA_CODECID_MP3: +- st->need_parsing = AVSTREAM_PARSE_FULL; +- framesize = 1024; +- break; +- default: +- av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n",buf[32]); +- return -1; +- break; +- } +- +- st->codec->block_align = framesize; +- +- return 0; +-} +- +- +-static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) +-{ +- int ret = av_get_packet(s->pb, pkt, s->streams[0]->codec->block_align); +- +- pkt->stream_index = 0; +- if (ret <= 0) +- return AVERROR(EIO); +- +- return ret; +-} +- +-static int oma_read_probe(AVProbeData *p) +-{ +- const uint8_t *buf; +- unsigned tag_len = 0; +- +- buf = p->buf; +- /* version must be 3 and flags byte zero */ +- if (ff_id3v2_match(buf, ID3v2_EA3_MAGIC) && buf[3] == 3 && !buf[4]) +- tag_len = ff_id3v2_tag_len(buf); +- +- // This check cannot overflow as tag_len has at most 28 bits +- if (p->buf_size < tag_len + 5) +- return 0; +- +- buf += tag_len; +- +- if (!memcmp(buf, "EA3", 3) && !buf[4] && buf[5] == EA3_HEADER_SIZE) +- return AVPROBE_SCORE_MAX; +- else +- return 0; +-} +- +- +-AVInputFormat ff_oma_demuxer = { +- "oma", +- NULL_IF_CONFIG_SMALL("Sony OpenMG audio"), +- 0, +- oma_read_probe, +- oma_read_header, +- oma_read_packet, +- 0, +- pcm_read_seek, +- .flags= AVFMT_GENERIC_INDEX, +- .extensions = "oma,aa3", +- .codec_tag= (const AVCodecTag* const []){codec_oma_tags, 0}, ++#include "internal.h" ++#include "oma.h" ++#include "libavcodec/avcodec.h" ++ ++const uint16_t ff_oma_srate_tab[6] = { 320, 441, 480, 882, 960, 0 }; ++ ++const AVCodecTag ff_oma_codec_tags[] = { ++ { CODEC_ID_ATRAC3, OMA_CODECID_ATRAC3 }, ++ { CODEC_ID_ATRAC3P, OMA_CODECID_ATRAC3P }, ++ { CODEC_ID_MP3, OMA_CODECID_MP3 }, ++ { CODEC_ID_PCM_S16BE, OMA_CODECID_LPCM }, ++ { 0 }, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/omadec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/omadec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/omadec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/omadec.c 2012-05-14 14:08:55.113355660 +0200 +@@ -0,0 +1,449 @@ ++/* ++ * Sony OpenMG (OMA) demuxer ++ * ++ * Copyright (c) 2008 Maxim Poliakovski ++ * 2008 Benjamin Larsson ++ * 2011 David Goldwich ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * This is a demuxer for Sony OpenMG Music files ++ * ++ * Known file extensions: ".oma", "aa3" ++ * The format of such files consists of three parts: ++ * - "ea3" header carrying overall info and metadata. Except for starting with ++ * "ea" instead of "ID", it's an ID3v2 header. ++ * - "EA3" header is a Sony-specific header containing information about ++ * the OpenMG file: codec type (usually ATRAC, can also be MP3 or WMA), ++ * codec specific info (packet size, sample rate, channels and so on) ++ * and DRM related info (file encryption, content id). ++ * - Sound data organized in packets follow the EA3 header ++ * (can be encrypted using the Sony DRM!). ++ * ++ * CODEC SUPPORT: Only ATRAC3 codec is currently supported! ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/des.h" ++#include "oma.h" ++#include "pcm.h" ++#include "riff.h" ++#include "id3v2.h" ++ ++ ++static const uint64_t leaf_table[] = { ++ 0xd79e8283acea4620, 0x7a9762f445afd0d8, ++ 0x354d60a60b8c79f1, 0x584e1cde00b07aee, ++ 0x1573cd93da7df623, 0x47f98d79620dd535 ++}; ++ ++typedef struct OMAContext { ++ uint64_t content_start; ++ int encrypted; ++ uint16_t k_size; ++ uint16_t e_size; ++ uint16_t i_size; ++ uint16_t s_size; ++ uint32_t rid; ++ uint8_t r_val[24]; ++ uint8_t n_val[24]; ++ uint8_t m_val[8]; ++ uint8_t s_val[8]; ++ uint8_t sm_val[8]; ++ uint8_t e_val[8]; ++ uint8_t iv[8]; ++ struct AVDES av_des; ++} OMAContext; ++ ++static void hex_log(AVFormatContext *s, int level, const char *name, const uint8_t *value, int len) ++{ ++ char buf[33]; ++ len = FFMIN(len, 16); ++ if (av_log_get_level() < level) ++ return; ++ ff_data_to_hex(buf, value, len, 1); ++ buf[len<<1] = '\0'; ++ av_log(s, level, "%s: %s\n", name, buf); ++} ++ ++static int kset(AVFormatContext *s, const uint8_t *r_val, const uint8_t *n_val, int len) ++{ ++ OMAContext *oc = s->priv_data; ++ ++ if (!r_val && !n_val) ++ return -1; ++ ++ len = FFMIN(len, 16); ++ ++ /* use first 64 bits in the third round again */ ++ if (r_val) { ++ if (r_val != oc->r_val) { ++ memset(oc->r_val, 0, 24); ++ memcpy(oc->r_val, r_val, len); ++ } ++ memcpy(&oc->r_val[16], r_val, 8); ++ } ++ if (n_val) { ++ if (n_val != oc->n_val) { ++ memset(oc->n_val, 0, 24); ++ memcpy(oc->n_val, n_val, len); ++ } ++ memcpy(&oc->n_val[16], n_val, 8); ++ } ++ ++ return 0; ++} ++ ++static int rprobe(AVFormatContext *s, uint8_t *enc_header, const uint8_t *r_val) ++{ ++ OMAContext *oc = s->priv_data; ++ unsigned int pos; ++ struct AVDES av_des; ++ ++ if (!enc_header || !r_val) ++ return -1; ++ ++ /* m_val */ ++ av_des_init(&av_des, r_val, 192, 1); ++ av_des_crypt(&av_des, oc->m_val, &enc_header[48], 1, NULL, 1); ++ ++ /* s_val */ ++ av_des_init(&av_des, oc->m_val, 64, 0); ++ av_des_crypt(&av_des, oc->s_val, NULL, 1, NULL, 0); ++ ++ /* sm_val */ ++ pos = OMA_ENC_HEADER_SIZE + oc->k_size + oc->e_size; ++ av_des_init(&av_des, oc->s_val, 64, 0); ++ av_des_mac(&av_des, oc->sm_val, &enc_header[pos], (oc->i_size >> 3)); ++ ++ pos += oc->i_size; ++ ++ return memcmp(&enc_header[pos], oc->sm_val, 8) ? -1 : 0; ++} ++ ++static int nprobe(AVFormatContext *s, uint8_t *enc_header, int size, const uint8_t *n_val) ++{ ++ OMAContext *oc = s->priv_data; ++ uint32_t pos, taglen, datalen; ++ struct AVDES av_des; ++ ++ if (!enc_header || !n_val) ++ return -1; ++ ++ pos = OMA_ENC_HEADER_SIZE + oc->k_size; ++ if (!memcmp(&enc_header[pos], "EKB ", 4)) ++ pos += 32; ++ ++ if (AV_RB32(&enc_header[pos]) != oc->rid) ++ av_log(s, AV_LOG_DEBUG, "Mismatching RID\n"); ++ ++ taglen = AV_RB32(&enc_header[pos+32]); ++ datalen = AV_RB32(&enc_header[pos+36]) >> 4; ++ ++ if(taglen + (((uint64_t)datalen)<<4) + 44 > size) ++ return -1; ++ ++ pos += 44 + taglen; ++ ++ av_des_init(&av_des, n_val, 192, 1); ++ while (datalen-- > 0) { ++ av_des_crypt(&av_des, oc->r_val, &enc_header[pos], 2, NULL, 1); ++ kset(s, oc->r_val, NULL, 16); ++ if (!rprobe(s, enc_header, oc->r_val)) ++ return 0; ++ pos += 16; ++ } ++ ++ return -1; ++} ++ ++static int decrypt_init(AVFormatContext *s, ID3v2ExtraMeta *em, uint8_t *header) ++{ ++ OMAContext *oc = s->priv_data; ++ ID3v2ExtraMetaGEOB *geob = NULL; ++ uint8_t *gdata; ++ ++ oc->encrypted = 1; ++ av_log(s, AV_LOG_INFO, "File is encrypted\n"); ++ ++ /* find GEOB metadata */ ++ while (em) { ++ if (!strcmp(em->tag, "GEOB") && ++ (geob = em->data) && ++ (!strcmp(geob->description, "OMG_LSI") || ++ !strcmp(geob->description, "OMG_BKLSI"))) { ++ break; ++ } ++ em = em->next; ++ } ++ if (!em) { ++ av_log(s, AV_LOG_ERROR, "No encryption header found\n"); ++ return -1; ++ } ++ ++ if (geob->datasize < 64) { ++ av_log(s, AV_LOG_ERROR, "Invalid GEOB data size: %u\n", geob->datasize); ++ return -1; ++ } ++ ++ gdata = geob->data; ++ ++ if (AV_RB16(gdata) != 1) ++ av_log(s, AV_LOG_WARNING, "Unknown version in encryption header\n"); ++ ++ oc->k_size = AV_RB16(&gdata[2]); ++ oc->e_size = AV_RB16(&gdata[4]); ++ oc->i_size = AV_RB16(&gdata[6]); ++ oc->s_size = AV_RB16(&gdata[8]); ++ ++ if (memcmp(&gdata[OMA_ENC_HEADER_SIZE], "KEYRING ", 12)) { ++ av_log(s, AV_LOG_ERROR, "Invalid encryption header\n"); ++ return -1; ++ } ++ oc->rid = AV_RB32(&gdata[OMA_ENC_HEADER_SIZE + 28]); ++ av_log(s, AV_LOG_DEBUG, "RID: %.8x\n", oc->rid); ++ ++ memcpy(oc->iv, &header[0x58], 8); ++ hex_log(s, AV_LOG_DEBUG, "IV", oc->iv, 8); ++ ++ hex_log(s, AV_LOG_DEBUG, "CBC-MAC", &gdata[OMA_ENC_HEADER_SIZE+oc->k_size+oc->e_size+oc->i_size], 8); ++ ++ if (s->keylen > 0) { ++ kset(s, s->key, s->key, s->keylen); ++ } ++ if (!memcmp(oc->r_val, (const uint8_t[8]){0}, 8) || ++ rprobe(s, gdata, oc->r_val) < 0 && ++ nprobe(s, gdata, geob->datasize, oc->n_val) < 0) { ++ int i; ++ for (i = 0; i < FF_ARRAY_ELEMS(leaf_table); i += 2) { ++ uint8_t buf[16]; ++ AV_WL64(buf, leaf_table[i]); ++ AV_WL64(&buf[8], leaf_table[i+1]); ++ kset(s, buf, buf, 16); ++ if (!rprobe(s, gdata, oc->r_val) || !nprobe(s, gdata, geob->datasize, oc->n_val)) ++ break; ++ } ++ if (i >= sizeof(leaf_table)) { ++ av_log(s, AV_LOG_ERROR, "Invalid key\n"); ++ return -1; ++ } ++ } ++ ++ /* e_val */ ++ av_des_init(&oc->av_des, oc->m_val, 64, 0); ++ av_des_crypt(&oc->av_des, oc->e_val, &gdata[OMA_ENC_HEADER_SIZE + 40], 1, NULL, 0); ++ hex_log(s, AV_LOG_DEBUG, "EK", oc->e_val, 8); ++ ++ /* init e_val */ ++ av_des_init(&oc->av_des, oc->e_val, 64, 1); ++ ++ return 0; ++} ++ ++static int oma_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ int ret, framesize, jsflag, samplerate; ++ uint32_t codec_params; ++ int16_t eid; ++ uint8_t buf[EA3_HEADER_SIZE]; ++ uint8_t *edata; ++ AVStream *st; ++ ID3v2ExtraMeta *extra_meta = NULL; ++ OMAContext *oc = s->priv_data; ++ ++ ff_id3v2_read_all(s, ID3v2_EA3_MAGIC, &extra_meta); ++ ret = avio_read(s->pb, buf, EA3_HEADER_SIZE); ++ if (ret < EA3_HEADER_SIZE) ++ return -1; ++ ++ if (memcmp(buf, ((const uint8_t[]){'E', 'A', '3'}),3) || buf[4] != 0 || buf[5] != EA3_HEADER_SIZE) { ++ av_log(s, AV_LOG_ERROR, "Couldn't find the EA3 header !\n"); ++ return -1; ++ } ++ ++ oc->content_start = avio_tell(s->pb); ++ ++ /* encrypted file */ ++ eid = AV_RB16(&buf[6]); ++ if (eid != -1 && eid != -128 && decrypt_init(s, extra_meta, buf) < 0) { ++ ff_id3v2_free_extra_meta(&extra_meta); ++ return -1; ++ } ++ ++ ff_id3v2_free_extra_meta(&extra_meta); ++ ++ codec_params = AV_RB24(&buf[33]); ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ st->start_time = 0; ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_tag = buf[32]; ++ st->codec->codec_id = ff_codec_get_id(ff_oma_codec_tags, st->codec->codec_tag); ++ ++ switch (buf[32]) { ++ case OMA_CODECID_ATRAC3: ++ samplerate = ff_oma_srate_tab[(codec_params >> 13) & 7]*100; ++ if (samplerate != 44100) ++ av_log_ask_for_sample(s, "Unsupported sample rate: %d\n", ++ samplerate); ++ ++ framesize = (codec_params & 0x3FF) * 8; ++ jsflag = (codec_params >> 17) & 1; /* get stereo coding mode, 1 for joint-stereo */ ++ st->codec->channels = 2; ++ st->codec->sample_rate = samplerate; ++ st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024; ++ ++ /* fake the atrac3 extradata (wav format, makes stream copy to wav work) */ ++ st->codec->extradata_size = 14; ++ edata = av_mallocz(14 + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!edata) ++ return AVERROR(ENOMEM); ++ ++ st->codec->extradata = edata; ++ AV_WL16(&edata[0], 1); // always 1 ++ AV_WL32(&edata[2], samplerate); // samples rate ++ AV_WL16(&edata[6], jsflag); // coding mode ++ AV_WL16(&edata[8], jsflag); // coding mode ++ AV_WL16(&edata[10], 1); // always 1 ++ // AV_WL16(&edata[12], 0); // always 0 ++ ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ break; ++ case OMA_CODECID_ATRAC3P: ++ st->codec->channels = (codec_params >> 10) & 7; ++ framesize = ((codec_params & 0x3FF) * 8) + 8; ++ st->codec->sample_rate = ff_oma_srate_tab[(codec_params >> 13) & 7]*100; ++ st->codec->bit_rate = st->codec->sample_rate * framesize * 8 / 1024; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ av_log(s, AV_LOG_ERROR, "Unsupported codec ATRAC3+!\n"); ++ break; ++ case OMA_CODECID_MP3: ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ framesize = 1024; ++ break; ++ case OMA_CODECID_LPCM: ++ /* PCM 44.1 kHz 16 bit stereo big-endian */ ++ st->codec->channels = 2; ++ st->codec->sample_rate = 44100; ++ framesize = 1024; ++ /* bit rate = sample rate x PCM block align (= 4) x 8 */ ++ st->codec->bit_rate = st->codec->sample_rate * 32; ++ st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ break; ++ default: ++ av_log(s, AV_LOG_ERROR, "Unsupported codec %d!\n",buf[32]); ++ return -1; ++ } ++ ++ st->codec->block_align = framesize; ++ ++ return 0; ++} ++ ++ ++static int oma_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ OMAContext *oc = s->priv_data; ++ int packet_size = s->streams[0]->codec->block_align; ++ int ret = av_get_packet(s->pb, pkt, packet_size); ++ ++ if (ret <= 0) ++ return AVERROR(EIO); ++ ++ pkt->stream_index = 0; ++ ++ if (oc->encrypted) { ++ /* previous unencrypted block saved in IV for the next packet (CBC mode) */ ++ av_des_crypt(&oc->av_des, pkt->data, pkt->data, (packet_size >> 3), oc->iv, 1); ++ } ++ ++ return ret; ++} ++ ++static int oma_read_probe(AVProbeData *p) ++{ ++ const uint8_t *buf; ++ unsigned tag_len = 0; ++ ++ buf = p->buf; ++ ++ if (p->buf_size < ID3v2_HEADER_SIZE || ++ !ff_id3v2_match(buf, ID3v2_EA3_MAGIC) || ++ buf[3] != 3 || // version must be 3 ++ buf[4]) // flags byte zero ++ return 0; ++ ++ tag_len = ff_id3v2_tag_len(buf); ++ ++ /* This check cannot overflow as tag_len has at most 28 bits */ ++ if (p->buf_size < tag_len + 5) ++ /* EA3 header comes late, might be outside of the probe buffer */ ++ return AVPROBE_SCORE_MAX / 2; ++ ++ buf += tag_len; ++ ++ if (!memcmp(buf, "EA3", 3) && !buf[4] && buf[5] == EA3_HEADER_SIZE) ++ return AVPROBE_SCORE_MAX; ++ else ++ return 0; ++} ++ ++static int oma_read_seek(struct AVFormatContext *s, int stream_index, int64_t timestamp, int flags) ++{ ++ OMAContext *oc = s->priv_data; ++ ++ pcm_read_seek(s, stream_index, timestamp, flags); ++ ++ if (oc->encrypted) { ++ /* readjust IV for CBC */ ++ int64_t pos = avio_tell(s->pb); ++ if (pos < oc->content_start) ++ memset(oc->iv, 0, 8); ++ else { ++ if (avio_seek(s->pb, -8, SEEK_CUR) < 0 || avio_read(s->pb, oc->iv, 8) < 8) { ++ memset(oc->iv, 0, 8); ++ return -1; ++ } ++ } ++ } ++ ++ return 0; ++} ++ ++AVInputFormat ff_oma_demuxer = { ++ .name = "oma", ++ .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"), ++ .priv_data_size = sizeof(OMAContext), ++ .read_probe = oma_read_probe, ++ .read_header = oma_read_header, ++ .read_packet = oma_read_packet, ++ .read_seek = oma_read_seek, ++ .flags = AVFMT_GENERIC_INDEX, ++ .extensions = "oma,omg,aa3", ++ .codec_tag = (const AVCodecTag* const []){ff_oma_codec_tags, 0}, ++}; ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/omaenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/omaenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/omaenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/omaenc.c 2012-05-14 14:08:55.113355660 +0200 +@@ -0,0 +1,105 @@ ++/* ++ * Sony OpenMG (OMA) muxer ++ * ++ * Copyright (c) 2011 Michael Karcher ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "avio_internal.h" ++#include "id3v2.h" ++#include "internal.h" ++#include "oma.h" ++#include "rawenc.h" ++ ++static av_cold int oma_write_header(AVFormatContext *s) ++{ ++ int i; ++ AVCodecContext *format; ++ int srate_index; ++ int isjointstereo; ++ ++ format = s->streams[0]->codec; ++ /* check for support of the format first */ ++ ++ for (srate_index = 0; ; srate_index++) { ++ if (ff_oma_srate_tab[srate_index] == 0) { ++ av_log(s, AV_LOG_ERROR, "Sample rate %d not supported in OpenMG audio\n", ++ format->sample_rate); ++ return AVERROR(EINVAL); ++ } ++ ++ if (ff_oma_srate_tab[srate_index] * 100 == format->sample_rate) ++ break; ++ } ++ ++ /* Metadata; OpenMG does not support ID3v2.4 */ ++ ff_id3v2_write(s, 3, ID3v2_EA3_MAGIC); ++ ++ ffio_wfourcc(s->pb, "EA3\0"); ++ avio_w8(s->pb, EA3_HEADER_SIZE >> 7); ++ avio_w8(s->pb, EA3_HEADER_SIZE & 0x7F); ++ avio_wl16(s->pb, 0xFFFF); /* not encrypted */ ++ for (i = 0; i < 6; i++) ++ avio_wl32(s->pb, 0); /* Padding + DRM id */ ++ ++ switch(format->codec_tag) { ++ case OMA_CODECID_ATRAC3: ++ if (format->channels != 2) { ++ av_log(s, AV_LOG_ERROR, "ATRAC3 in OMA is only supported with 2 channels"); ++ return AVERROR(EINVAL); ++ } ++ if (format->extradata_size == 14) /* WAV format extradata */ ++ isjointstereo = format->extradata[6] != 0; ++ else if(format->extradata_size == 10) /* RM format extradata */ ++ isjointstereo = format->extradata[8] == 0x12; ++ else { ++ av_log(s, AV_LOG_ERROR, "ATRAC3: Unsupported extradata size\n"); ++ return AVERROR(EINVAL); ++ } ++ avio_wb32(s->pb, (OMA_CODECID_ATRAC3 << 24) | ++ (isjointstereo << 17) | ++ (srate_index << 13) | ++ (format->block_align/8)); ++ break; ++ case OMA_CODECID_ATRAC3P: ++ avio_wb32(s->pb, (OMA_CODECID_ATRAC3P << 24) | ++ (srate_index << 13) | ++ (format->channels << 10) | ++ (format->block_align/8 - 1)); ++ break; ++ default: ++ av_log(s, AV_LOG_ERROR, "OMA: unsupported codec tag %d for write\n", ++ format->codec_tag); ++ } ++ for (i = 0; i < (EA3_HEADER_SIZE - 36)/4; i++) ++ avio_wl32(s->pb, 0); /* Padding */ ++ ++ return 0; ++} ++ ++AVOutputFormat ff_oma_muxer = { ++ .name = "oma", ++ .long_name = NULL_IF_CONFIG_SMALL("Sony OpenMG audio"), ++ .mime_type = "audio/x-oma", ++ .extensions = "oma", ++ .audio_codec = CODEC_ID_ATRAC3, ++ .write_header = oma_write_header, ++ .write_packet = ff_raw_write_packet, ++ .codec_tag = (const AVCodecTag* const []){ff_oma_codec_tags, 0}, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oma.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oma.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/oma.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/oma.h 2012-05-14 14:08:55.111355619 +0200 +@@ -0,0 +1,44 @@ ++/* ++ * Sony OpenMG (OMA) common data ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFORMAT_OMA_H ++#define AVFORMAT_OMA_H ++ ++#include ++ ++#include "internal.h" ++ ++#define EA3_HEADER_SIZE 96 ++#define ID3v2_EA3_MAGIC "ea3" ++#define OMA_ENC_HEADER_SIZE 16 ++ ++enum { ++ OMA_CODECID_ATRAC3 = 0, ++ OMA_CODECID_ATRAC3P = 1, ++ OMA_CODECID_MP3 = 3, ++ OMA_CODECID_LPCM = 4, ++ OMA_CODECID_WMA = 5, ++}; ++ ++extern const uint16_t ff_oma_srate_tab[6]; ++ ++extern const AVCodecTag ff_oma_codec_tags[]; ++ ++#endif /* AVFORMAT_OMA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/options.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/options.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/options.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/options.c 2012-05-14 14:08:55.115355700 +0200 +@@ -18,6 +18,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "avio_internal.h" + #include "libavutil/opt.h" + + /** +@@ -33,6 +34,52 @@ + else return "NULL"; + } + ++static void *format_child_next(void *obj, void *prev) ++{ ++ AVFormatContext *s = obj; ++ if (!prev && s->priv_data && ++ ((s->iformat && s->iformat->priv_class) || ++ s->oformat && s->oformat->priv_class)) ++ return s->priv_data; ++#if !FF_API_OLD_AVIO ++ if (s->pb && s->pb->av_class && prev != s->pb) ++ return s->pb; ++#endif ++ return NULL; ++} ++ ++static const AVClass *format_child_class_next(const AVClass *prev) ++{ ++ AVInputFormat *ifmt = NULL; ++ AVOutputFormat *ofmt = NULL; ++ ++ if (!prev) ++#if !FF_API_OLD_AVIO ++ return &ffio_url_class; ++#else ++ prev = (void *)&ifmt; // Dummy pointer; ++#endif ++ ++ while ((ifmt = av_iformat_next(ifmt))) ++ if (ifmt->priv_class == prev) ++ break; ++ ++ if (!ifmt) ++ while ((ofmt = av_oformat_next(ofmt))) ++ if (ofmt->priv_class == prev) ++ break; ++ if (!ofmt) ++ while (ifmt = av_iformat_next(ifmt)) ++ if (ifmt->priv_class) ++ return ifmt->priv_class; ++ ++ while (ofmt = av_oformat_next(ofmt)) ++ if (ofmt->priv_class) ++ return ofmt->priv_class; ++ ++ return NULL; ++} ++ + #define OFFSET(x) offsetof(AVFormatContext,x) + #define DEFAULT 0 //should be NAN but it does not work as it is not a constant in glibc as required by ANSI/ISO C + //these names are too long to be readable +@@ -40,27 +87,46 @@ + #define D AV_OPT_FLAG_DECODING_PARAM + + static const AVOption options[]={ +-{"probesize", "set probing size", OFFSET(probesize), FF_OPT_TYPE_INT, 5000000, 32, INT_MAX, D}, +-{"muxrate", "set mux rate", OFFSET(mux_rate), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +-{"packetsize", "set packet size", OFFSET(packet_size), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +-{"fflags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, D|E, "fflags"}, +-{"ignidx", "ignore index", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNIDX, INT_MIN, INT_MAX, D, "fflags"}, +-{"genpts", "generate pts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_GENPTS, INT_MIN, INT_MAX, D, "fflags"}, +-{"nofillin", "do not fill in missing values that can be exactly calculated", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_NOFILLIN, INT_MIN, INT_MAX, D, "fflags"}, +-{"noparse", "disable AVParsers, this needs nofillin too", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_NOPARSE, INT_MIN, INT_MAX, D, "fflags"}, +-{"igndts", "ignore dts", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_IGNDTS, INT_MIN, INT_MAX, D, "fflags"}, +-{"rtphint", "add rtp hinting", 0, FF_OPT_TYPE_CONST, AVFMT_FLAG_RTP_HINT, INT_MIN, INT_MAX, E, "fflags"}, +-#if FF_API_OLD_METADATA +-{"track", " set the track number", OFFSET(track), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E}, +-{"year", "set the year", OFFSET(year), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, E}, ++{"probesize", "set probing size", OFFSET(probesize), AV_OPT_TYPE_INT, {.dbl = 5000000 }, 32, INT_MAX, D}, ++#if FF_API_MUXRATE ++{"muxrate", "set mux rate", OFFSET(mux_rate), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E}, + #endif +-{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), FF_OPT_TYPE_INT, 5*AV_TIME_BASE, 0, INT_MAX, D}, +-{"cryptokey", "decryption key", OFFSET(key), FF_OPT_TYPE_BINARY, 0, 0, 0, D}, +-{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), FF_OPT_TYPE_INT, 1<<20, 0, INT_MAX, D}, +-{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), FF_OPT_TYPE_INT, 3041280, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */ +-{"fdebug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, E|D, "fdebug"}, +-{"ts", NULL, 0, FF_OPT_TYPE_CONST, FF_FDEBUG_TS, INT_MIN, INT_MAX, E|D, "fdebug"}, +-{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, E|D}, ++{"packetsize", "set packet size", OFFSET(packet_size), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E}, ++{"fflags", NULL, OFFSET(flags), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, INT_MIN, INT_MAX, D|E, "fflags"}, ++{"ignidx", "ignore index", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNIDX }, INT_MIN, INT_MAX, D, "fflags"}, ++{"genpts", "generate pts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_GENPTS }, INT_MIN, INT_MAX, D, "fflags"}, ++{"nofillin", "do not fill in missing values that can be exactly calculated", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOFILLIN }, INT_MIN, INT_MAX, D, "fflags"}, ++{"noparse", "disable AVParsers, this needs nofillin too", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_NOPARSE }, INT_MIN, INT_MAX, D, "fflags"}, ++{"igndts", "ignore dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_IGNDTS }, INT_MIN, INT_MAX, D, "fflags"}, ++#if FF_API_FLAG_RTP_HINT ++{"rtphint", "add rtp hinting (deprecated, use the -movflags rtphint option instead)", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_RTP_HINT }, INT_MIN, INT_MAX, E, "fflags"}, ++#endif ++{"discardcorrupt", "discard corrupted frames", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_DISCARD_CORRUPT }, INT_MIN, INT_MAX, D, "fflags"}, ++{"sortdts", "try to interleave outputted packets by dts", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_SORT_DTS }, INT_MIN, INT_MAX, D, "fflags"}, ++{"keepside", "dont merge side data", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_KEEP_SIDE_DATA }, INT_MIN, INT_MAX, D, "fflags"}, ++{"latm", "enable RTP MP4A-LATM payload", 0, AV_OPT_TYPE_CONST, {.dbl = AVFMT_FLAG_MP4A_LATM }, INT_MIN, INT_MAX, E, "fflags"}, ++{"analyzeduration", "how many microseconds are analyzed to estimate duration", OFFSET(max_analyze_duration), AV_OPT_TYPE_INT, {.dbl = 5*AV_TIME_BASE }, 0, INT_MAX, D}, ++{"cryptokey", "decryption key", OFFSET(key), AV_OPT_TYPE_BINARY, {.dbl = 0}, 0, 0, D}, ++{"indexmem", "max memory used for timestamp index (per stream)", OFFSET(max_index_size), AV_OPT_TYPE_INT, {.dbl = 1<<20 }, 0, INT_MAX, D}, ++{"rtbufsize", "max memory used for buffering real-time frames", OFFSET(max_picture_buffer), AV_OPT_TYPE_INT, {.dbl = 3041280 }, 0, INT_MAX, D}, /* defaults to 1s of 15fps 352x288 YUYV422 video */ ++{"fdebug", "print specific debug info", OFFSET(debug), AV_OPT_TYPE_FLAGS, {.dbl = DEFAULT }, 0, INT_MAX, E|D, "fdebug"}, ++{"ts", NULL, 0, AV_OPT_TYPE_CONST, {.dbl = FF_FDEBUG_TS }, INT_MIN, INT_MAX, E|D, "fdebug"}, ++{"max_delay", "maximum muxing or demuxing delay in microseconds", OFFSET(max_delay), AV_OPT_TYPE_INT, {.dbl = DEFAULT }, 0, INT_MAX, E|D}, ++{"fpsprobesize", "number of frames used to probe fps", OFFSET(fps_probe_size), AV_OPT_TYPE_INT, {.dbl = -1}, -1, INT_MAX-1, D}, ++{"audio_preload", "microseconds by which audio packets should be interleaved earlier", OFFSET(audio_preload), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E}, ++{"chunk_duration", "microseconds for each chunk", OFFSET(max_chunk_duration), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E}, ++{"chunk_size", "size in bytes for each chunk", OFFSET(max_chunk_size), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX-1, E}, ++/* this is a crutch for avconv, since it cannot deal with identically named options in different contexts. ++ * to be removed when avconv is fixed */ ++{"f_err_detect", "set error detection flags (deprecated; use err_detect, save via avconv)", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"err_detect", "set error detection flags", OFFSET(error_recognition), AV_OPT_TYPE_FLAGS, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"crccheck", "verify embedded CRCs", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CRCCHECK }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"bitstream", "detect bitstream specification deviations", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BITSTREAM }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"buffer", "detect improper bitstream length", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_BUFFER }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"explode", "abort decoding on minor error detection", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_EXPLODE }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"careful", "consider things that violate the spec and have not been seen in the wild as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_CAREFUL }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"compliant", "consider all spec non compliancies as errors", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_COMPLIANT }, INT_MIN, INT_MAX, D, "err_detect"}, ++{"aggressive", "consider things that a sane encoder shouldnt do as an error", 0, AV_OPT_TYPE_CONST, {.dbl = AV_EF_AGGRESSIVE }, INT_MIN, INT_MAX, D, "err_detect"}, + {NULL}, + }; + +@@ -68,7 +134,14 @@ + #undef D + #undef DEFAULT + +-static const AVClass av_format_context_class = { "AVFormatContext", format_to_name, options, LIBAVUTIL_VERSION_INT }; ++static const AVClass av_format_context_class = { ++ .class_name = "AVFormatContext", ++ .item_name = format_to_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++ .child_next = format_child_next, ++ .child_class_next = format_child_class_next, ++}; + + static void avformat_get_context_defaults(AVFormatContext *s) + { +@@ -85,13 +158,10 @@ + ic = av_malloc(sizeof(AVFormatContext)); + if (!ic) return ic; + avformat_get_context_defaults(ic); +- ic->av_class = &av_format_context_class; + return ic; + } + +-#if FF_API_ALLOC_FORMAT_CONTEXT +-AVFormatContext *av_alloc_format_context(void) ++const AVClass *avformat_get_class(void) + { +- return avformat_alloc_context(); ++ return &av_format_context_class; + } +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/os_support.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/os_support.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/os_support.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/os_support.c 2012-05-14 14:08:55.115355700 +0200 +@@ -1,5 +1,5 @@ + /* +- * Various utilities for ffmpeg system ++ * various OS-feature replacement utilities + * Copyright (c) 2000, 2001, 2002 Fabrice Bellard + * copyright (c) 2002 Francois Revol + * +@@ -22,12 +22,39 @@ + + /* needed by inet_aton() */ + #define _SVID_SOURCE +-#define _DARWIN_C_SOURCE + + #include "config.h" + #include "avformat.h" + #include "os_support.h" + ++#if defined(_WIN32) && !defined(__MINGW32CE__) ++#include ++ ++#undef open ++int ff_win32_open(const char *filename_utf8, int oflag, int pmode) ++{ ++ int fd; ++ int num_chars; ++ wchar_t *filename_w; ++ ++ /* convert UTF-8 to wide chars */ ++ num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, NULL, 0); ++ if (num_chars <= 0) ++ return -1; ++ filename_w = av_mallocz(sizeof(wchar_t) * num_chars); ++ MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, filename_w, num_chars); ++ ++ fd = _wopen(filename_w, oflag, pmode); ++ av_freep(&filename_w); ++ ++ /* filename maybe be in CP_ACP */ ++ if (fd == -1 && !(oflag & O_CREAT)) ++ return open(filename_utf8, oflag, pmode); ++ ++ return fd; ++} ++#endif ++ + #if CONFIG_NETWORK + #include + #include +@@ -44,7 +71,6 @@ + + #if !HAVE_INET_ATON + #include +-#include + + int ff_inet_aton (const char * str, struct in_addr * add) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/os_support.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/os_support.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/os_support.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/os_support.h 2012-05-14 14:08:55.116355720 +0200 +@@ -1,5 +1,5 @@ + /* +- * various utilities for ffmpeg system ++ * various OS-feature replacement utilities + * copyright (c) 2000, 2001, 2002 Fabrice Bellard + * + * This file is part of FFmpeg. +@@ -45,6 +45,11 @@ + return 0; + } + ++#if defined(_WIN32) && !defined(__MINGW32CE__) ++int ff_win32_open(const char *filename, int oflag, int pmode); ++#define open ff_win32_open ++#endif ++ + #if CONFIG_NETWORK + #if !HAVE_SOCKLEN_T + typedef int socklen_t; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/output-example.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/output-example.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/output-example.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/output-example.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,555 +0,0 @@ +-/* +- * Libavformat API example: Output a media file in any supported +- * libavformat format. The default codecs are used. +- * +- * Copyright (c) 2003 Fabrice Bellard +- * +- * Permission is hereby granted, free of charge, to any person obtaining a copy +- * of this software and associated documentation files (the "Software"), to deal +- * in the Software without restriction, including without limitation the rights +- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +- * copies of the Software, and to permit persons to whom the Software is +- * furnished to do so, subject to the following conditions: +- * +- * The above copyright notice and this permission notice shall be included in +- * all copies or substantial portions of the Software. +- * +- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +- * THE SOFTWARE. +- */ +-#include +-#include +-#include +-#include +- +-#include "libavformat/avformat.h" +-#include "libswscale/swscale.h" +- +-#undef exit +- +-/* 5 seconds stream duration */ +-#define STREAM_DURATION 5.0 +-#define STREAM_FRAME_RATE 25 /* 25 images/s */ +-#define STREAM_NB_FRAMES ((int)(STREAM_DURATION * STREAM_FRAME_RATE)) +-#define STREAM_PIX_FMT PIX_FMT_YUV420P /* default pix_fmt */ +- +-static int sws_flags = SWS_BICUBIC; +- +-/**************************************************************/ +-/* audio output */ +- +-float t, tincr, tincr2; +-int16_t *samples; +-uint8_t *audio_outbuf; +-int audio_outbuf_size; +-int audio_input_frame_size; +- +-/* +- * add an audio output stream +- */ +-static AVStream *add_audio_stream(AVFormatContext *oc, enum CodecID codec_id) +-{ +- AVCodecContext *c; +- AVStream *st; +- +- st = av_new_stream(oc, 1); +- if (!st) { +- fprintf(stderr, "Could not alloc stream\n"); +- exit(1); +- } +- +- c = st->codec; +- c->codec_id = codec_id; +- c->codec_type = AVMEDIA_TYPE_AUDIO; +- +- /* put sample parameters */ +- c->sample_fmt = AV_SAMPLE_FMT_S16; +- c->bit_rate = 64000; +- c->sample_rate = 44100; +- c->channels = 2; +- +- // some formats want stream headers to be separate +- if(oc->oformat->flags & AVFMT_GLOBALHEADER) +- c->flags |= CODEC_FLAG_GLOBAL_HEADER; +- +- return st; +-} +- +-static void open_audio(AVFormatContext *oc, AVStream *st) +-{ +- AVCodecContext *c; +- AVCodec *codec; +- +- c = st->codec; +- +- /* find the audio encoder */ +- codec = avcodec_find_encoder(c->codec_id); +- if (!codec) { +- fprintf(stderr, "codec not found\n"); +- exit(1); +- } +- +- /* open it */ +- if (avcodec_open(c, codec) < 0) { +- fprintf(stderr, "could not open codec\n"); +- exit(1); +- } +- +- /* init signal generator */ +- t = 0; +- tincr = 2 * M_PI * 110.0 / c->sample_rate; +- /* increment frequency by 110 Hz per second */ +- tincr2 = 2 * M_PI * 110.0 / c->sample_rate / c->sample_rate; +- +- audio_outbuf_size = 10000; +- audio_outbuf = av_malloc(audio_outbuf_size); +- +- /* ugly hack for PCM codecs (will be removed ASAP with new PCM +- support to compute the input frame size in samples */ +- if (c->frame_size <= 1) { +- audio_input_frame_size = audio_outbuf_size / c->channels; +- switch(st->codec->codec_id) { +- case CODEC_ID_PCM_S16LE: +- case CODEC_ID_PCM_S16BE: +- case CODEC_ID_PCM_U16LE: +- case CODEC_ID_PCM_U16BE: +- audio_input_frame_size >>= 1; +- break; +- default: +- break; +- } +- } else { +- audio_input_frame_size = c->frame_size; +- } +- samples = av_malloc(audio_input_frame_size * 2 * c->channels); +-} +- +-/* prepare a 16 bit dummy audio frame of 'frame_size' samples and +- 'nb_channels' channels */ +-static void get_audio_frame(int16_t *samples, int frame_size, int nb_channels) +-{ +- int j, i, v; +- int16_t *q; +- +- q = samples; +- for(j=0;jcodec; +- +- get_audio_frame(samples, audio_input_frame_size, c->channels); +- +- pkt.size= avcodec_encode_audio(c, audio_outbuf, audio_outbuf_size, samples); +- +- if (c->coded_frame && c->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); +- pkt.flags |= AV_PKT_FLAG_KEY; +- pkt.stream_index= st->index; +- pkt.data= audio_outbuf; +- +- /* write the compressed frame in the media file */ +- if (av_interleaved_write_frame(oc, &pkt) != 0) { +- fprintf(stderr, "Error while writing audio frame\n"); +- exit(1); +- } +-} +- +-static void close_audio(AVFormatContext *oc, AVStream *st) +-{ +- avcodec_close(st->codec); +- +- av_free(samples); +- av_free(audio_outbuf); +-} +- +-/**************************************************************/ +-/* video output */ +- +-AVFrame *picture, *tmp_picture; +-uint8_t *video_outbuf; +-int frame_count, video_outbuf_size; +- +-/* add a video output stream */ +-static AVStream *add_video_stream(AVFormatContext *oc, enum CodecID codec_id) +-{ +- AVCodecContext *c; +- AVStream *st; +- +- st = av_new_stream(oc, 0); +- if (!st) { +- fprintf(stderr, "Could not alloc stream\n"); +- exit(1); +- } +- +- c = st->codec; +- c->codec_id = codec_id; +- c->codec_type = AVMEDIA_TYPE_VIDEO; +- +- /* put sample parameters */ +- c->bit_rate = 400000; +- /* resolution must be a multiple of two */ +- c->width = 352; +- c->height = 288; +- /* time base: this is the fundamental unit of time (in seconds) in terms +- of which frame timestamps are represented. for fixed-fps content, +- timebase should be 1/framerate and timestamp increments should be +- identically 1. */ +- c->time_base.den = STREAM_FRAME_RATE; +- c->time_base.num = 1; +- c->gop_size = 12; /* emit one intra frame every twelve frames at most */ +- c->pix_fmt = STREAM_PIX_FMT; +- if (c->codec_id == CODEC_ID_MPEG2VIDEO) { +- /* just for testing, we also add B frames */ +- c->max_b_frames = 2; +- } +- if (c->codec_id == CODEC_ID_MPEG1VIDEO){ +- /* Needed to avoid using macroblocks in which some coeffs overflow. +- This does not happen with normal video, it just happens here as +- the motion of the chroma plane does not match the luma plane. */ +- c->mb_decision=2; +- } +- // some formats want stream headers to be separate +- if(oc->oformat->flags & AVFMT_GLOBALHEADER) +- c->flags |= CODEC_FLAG_GLOBAL_HEADER; +- +- return st; +-} +- +-static AVFrame *alloc_picture(enum PixelFormat pix_fmt, int width, int height) +-{ +- AVFrame *picture; +- uint8_t *picture_buf; +- int size; +- +- picture = avcodec_alloc_frame(); +- if (!picture) +- return NULL; +- size = avpicture_get_size(pix_fmt, width, height); +- picture_buf = av_malloc(size); +- if (!picture_buf) { +- av_free(picture); +- return NULL; +- } +- avpicture_fill((AVPicture *)picture, picture_buf, +- pix_fmt, width, height); +- return picture; +-} +- +-static void open_video(AVFormatContext *oc, AVStream *st) +-{ +- AVCodec *codec; +- AVCodecContext *c; +- +- c = st->codec; +- +- /* find the video encoder */ +- codec = avcodec_find_encoder(c->codec_id); +- if (!codec) { +- fprintf(stderr, "codec not found\n"); +- exit(1); +- } +- +- /* open the codec */ +- if (avcodec_open(c, codec) < 0) { +- fprintf(stderr, "could not open codec\n"); +- exit(1); +- } +- +- video_outbuf = NULL; +- if (!(oc->oformat->flags & AVFMT_RAWPICTURE)) { +- /* allocate output buffer */ +- /* XXX: API change will be done */ +- /* buffers passed into lav* can be allocated any way you prefer, +- as long as they're aligned enough for the architecture, and +- they're freed appropriately (such as using av_free for buffers +- allocated with av_malloc) */ +- video_outbuf_size = 200000; +- video_outbuf = av_malloc(video_outbuf_size); +- } +- +- /* allocate the encoded raw picture */ +- picture = alloc_picture(c->pix_fmt, c->width, c->height); +- if (!picture) { +- fprintf(stderr, "Could not allocate picture\n"); +- exit(1); +- } +- +- /* if the output format is not YUV420P, then a temporary YUV420P +- picture is needed too. It is then converted to the required +- output format */ +- tmp_picture = NULL; +- if (c->pix_fmt != PIX_FMT_YUV420P) { +- tmp_picture = alloc_picture(PIX_FMT_YUV420P, c->width, c->height); +- if (!tmp_picture) { +- fprintf(stderr, "Could not allocate temporary picture\n"); +- exit(1); +- } +- } +-} +- +-/* prepare a dummy image */ +-static void fill_yuv_image(AVFrame *pict, int frame_index, int width, int height) +-{ +- int x, y, i; +- +- i = frame_index; +- +- /* Y */ +- for(y=0;ydata[0][y * pict->linesize[0] + x] = x + y + i * 3; +- } +- } +- +- /* Cb and Cr */ +- for(y=0;ydata[1][y * pict->linesize[1] + x] = 128 + y + i * 2; +- pict->data[2][y * pict->linesize[2] + x] = 64 + x + i * 5; +- } +- } +-} +- +-static void write_video_frame(AVFormatContext *oc, AVStream *st) +-{ +- int out_size, ret; +- AVCodecContext *c; +- static struct SwsContext *img_convert_ctx; +- +- c = st->codec; +- +- if (frame_count >= STREAM_NB_FRAMES) { +- /* no more frame to compress. The codec has a latency of a few +- frames if using B frames, so we get the last frames by +- passing the same picture again */ +- } else { +- if (c->pix_fmt != PIX_FMT_YUV420P) { +- /* as we only generate a YUV420P picture, we must convert it +- to the codec pixel format if needed */ +- if (img_convert_ctx == NULL) { +- img_convert_ctx = sws_getContext(c->width, c->height, +- PIX_FMT_YUV420P, +- c->width, c->height, +- c->pix_fmt, +- sws_flags, NULL, NULL, NULL); +- if (img_convert_ctx == NULL) { +- fprintf(stderr, "Cannot initialize the conversion context\n"); +- exit(1); +- } +- } +- fill_yuv_image(tmp_picture, frame_count, c->width, c->height); +- sws_scale(img_convert_ctx, tmp_picture->data, tmp_picture->linesize, +- 0, c->height, picture->data, picture->linesize); +- } else { +- fill_yuv_image(picture, frame_count, c->width, c->height); +- } +- } +- +- +- if (oc->oformat->flags & AVFMT_RAWPICTURE) { +- /* raw video case. The API will change slightly in the near +- futur for that */ +- AVPacket pkt; +- av_init_packet(&pkt); +- +- pkt.flags |= AV_PKT_FLAG_KEY; +- pkt.stream_index= st->index; +- pkt.data= (uint8_t *)picture; +- pkt.size= sizeof(AVPicture); +- +- ret = av_interleaved_write_frame(oc, &pkt); +- } else { +- /* encode the image */ +- out_size = avcodec_encode_video(c, video_outbuf, video_outbuf_size, picture); +- /* if zero size, it means the image was buffered */ +- if (out_size > 0) { +- AVPacket pkt; +- av_init_packet(&pkt); +- +- if (c->coded_frame->pts != AV_NOPTS_VALUE) +- pkt.pts= av_rescale_q(c->coded_frame->pts, c->time_base, st->time_base); +- if(c->coded_frame->key_frame) +- pkt.flags |= AV_PKT_FLAG_KEY; +- pkt.stream_index= st->index; +- pkt.data= video_outbuf; +- pkt.size= out_size; +- +- /* write the compressed frame in the media file */ +- ret = av_interleaved_write_frame(oc, &pkt); +- } else { +- ret = 0; +- } +- } +- if (ret != 0) { +- fprintf(stderr, "Error while writing video frame\n"); +- exit(1); +- } +- frame_count++; +-} +- +-static void close_video(AVFormatContext *oc, AVStream *st) +-{ +- avcodec_close(st->codec); +- av_free(picture->data[0]); +- av_free(picture); +- if (tmp_picture) { +- av_free(tmp_picture->data[0]); +- av_free(tmp_picture); +- } +- av_free(video_outbuf); +-} +- +-/**************************************************************/ +-/* media file output */ +- +-int main(int argc, char **argv) +-{ +- const char *filename; +- AVOutputFormat *fmt; +- AVFormatContext *oc; +- AVStream *audio_st, *video_st; +- double audio_pts, video_pts; +- int i; +- +- /* initialize libavcodec, and register all codecs and formats */ +- av_register_all(); +- +- if (argc != 2) { +- printf("usage: %s output_file\n" +- "API example program to output a media file with libavformat.\n" +- "The output format is automatically guessed according to the file extension.\n" +- "Raw images can also be output by using '%%d' in the filename\n" +- "\n", argv[0]); +- exit(1); +- } +- +- filename = argv[1]; +- +- /* auto detect the output format from the name. default is +- mpeg. */ +- fmt = av_guess_format(NULL, filename, NULL); +- if (!fmt) { +- printf("Could not deduce output format from file extension: using MPEG.\n"); +- fmt = av_guess_format("mpeg", NULL, NULL); +- } +- if (!fmt) { +- fprintf(stderr, "Could not find suitable output format\n"); +- exit(1); +- } +- +- /* allocate the output media context */ +- oc = avformat_alloc_context(); +- if (!oc) { +- fprintf(stderr, "Memory error\n"); +- exit(1); +- } +- oc->oformat = fmt; +- snprintf(oc->filename, sizeof(oc->filename), "%s", filename); +- +- /* add the audio and video streams using the default format codecs +- and initialize the codecs */ +- video_st = NULL; +- audio_st = NULL; +- if (fmt->video_codec != CODEC_ID_NONE) { +- video_st = add_video_stream(oc, fmt->video_codec); +- } +- if (fmt->audio_codec != CODEC_ID_NONE) { +- audio_st = add_audio_stream(oc, fmt->audio_codec); +- } +- +- /* set the output parameters (must be done even if no +- parameters). */ +- if (av_set_parameters(oc, NULL) < 0) { +- fprintf(stderr, "Invalid output format parameters\n"); +- exit(1); +- } +- +- dump_format(oc, 0, filename, 1); +- +- /* now that all the parameters are set, we can open the audio and +- video codecs and allocate the necessary encode buffers */ +- if (video_st) +- open_video(oc, video_st); +- if (audio_st) +- open_audio(oc, audio_st); +- +- /* open the output file, if needed */ +- if (!(fmt->flags & AVFMT_NOFILE)) { +- if (url_fopen(&oc->pb, filename, URL_WRONLY) < 0) { +- fprintf(stderr, "Could not open '%s'\n", filename); +- exit(1); +- } +- } +- +- /* write the stream header, if any */ +- av_write_header(oc); +- +- for(;;) { +- /* compute current audio and video time */ +- if (audio_st) +- audio_pts = (double)audio_st->pts.val * audio_st->time_base.num / audio_st->time_base.den; +- else +- audio_pts = 0.0; +- +- if (video_st) +- video_pts = (double)video_st->pts.val * video_st->time_base.num / video_st->time_base.den; +- else +- video_pts = 0.0; +- +- if ((!audio_st || audio_pts >= STREAM_DURATION) && +- (!video_st || video_pts >= STREAM_DURATION)) +- break; +- +- /* write interleaved audio and video frames */ +- if (!video_st || (video_st && audio_st && audio_pts < video_pts)) { +- write_audio_frame(oc, audio_st); +- } else { +- write_video_frame(oc, video_st); +- } +- } +- +- /* write the trailer, if any. the trailer must be written +- * before you close the CodecContexts open when you wrote the +- * header; otherwise write_trailer may try to use memory that +- * was freed on av_codec_close() */ +- av_write_trailer(oc); +- +- /* close each codec */ +- if (video_st) +- close_video(oc, video_st); +- if (audio_st) +- close_audio(oc, audio_st); +- +- /* free the streams */ +- for(i = 0; i < oc->nb_streams; i++) { +- av_freep(&oc->streams[i]->codec); +- av_freep(&oc->streams[i]); +- } +- +- if (!(fmt->flags & AVFMT_NOFILE)) { +- /* close the output file */ +- url_fclose(oc->pb); +- } +- +- /* free the stream */ +- av_free(oc); +- +- return 0; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcm.c 2012-05-14 14:08:55.118355760 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "avformat.h" + #include "pcm.h" + +@@ -49,7 +50,7 @@ + + /* recompute exact position */ + st->cur_dts = av_rescale(pos, st->time_base.den, byte_rate * (int64_t)st->time_base.num); +- if ((ret = url_fseek(s->pb, pos + s->data_offset, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, pos + s->data_offset, SEEK_SET)) < 0) + return ret; + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcmdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcmdec.c 2012-05-14 14:08:55.119355780 +0200 +@@ -22,6 +22,8 @@ + #include "avformat.h" + #include "rawdec.h" + #include "pcm.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" + + #define RAW_SAMPLES 1024 + +@@ -46,19 +48,30 @@ + return ret; + } + +-#define PCMDEF(name, long_name, ext, codec) \ +-AVInputFormat ff_pcm_ ## name ## _demuxer = {\ +- #name,\ +- NULL_IF_CONFIG_SMALL(long_name),\ +- 0,\ +- NULL,\ +- ff_raw_read_header,\ +- raw_read_packet,\ +- NULL,\ +- pcm_read_seek,\ +- .flags= AVFMT_GENERIC_INDEX,\ +- .extensions = ext,\ +- .value = codec,\ ++static const AVOption pcm_options[] = { ++ { "sample_rate", "", offsetof(RawAudioDemuxerContext, sample_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { "channels", "", offsetof(RawAudioDemuxerContext, channels), AV_OPT_TYPE_INT, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++#define PCMDEF(name_, long_name_, ext, codec) \ ++static const AVClass name_ ## _demuxer_class = { \ ++ .class_name = #name_ " demuxer", \ ++ .item_name = av_default_item_name, \ ++ .option = pcm_options, \ ++ .version = LIBAVUTIL_VERSION_INT, \ ++}; \ ++AVInputFormat ff_pcm_ ## name_ ## _demuxer = { \ ++ .name = #name_, \ ++ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ ++ .priv_data_size = sizeof(RawAudioDemuxerContext), \ ++ .read_header = ff_raw_read_header, \ ++ .read_packet = raw_read_packet, \ ++ .read_seek = pcm_read_seek, \ ++ .flags = AVFMT_GENERIC_INDEX, \ ++ .extensions = ext, \ ++ .value = codec, \ ++ .priv_class = &name_ ## _demuxer_class, \ + }; + + PCMDEF(f64be, "PCM 64 bit floating-point big-endian format", +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pcmenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pcmenc.c 2012-05-14 14:08:55.119355780 +0200 +@@ -22,18 +22,15 @@ + #include "avformat.h" + #include "rawenc.h" + +-#define PCMDEF(name, long_name, ext, codec) \ +-AVOutputFormat ff_pcm_ ## name ## _muxer = {\ +- #name,\ +- NULL_IF_CONFIG_SMALL(long_name),\ +- NULL,\ +- ext,\ +- 0,\ +- codec,\ +- CODEC_ID_NONE,\ +- NULL,\ +- ff_raw_write_packet,\ +- .flags= AVFMT_NOTIMESTAMPS,\ ++#define PCMDEF(name_, long_name_, ext, codec) \ ++AVOutputFormat ff_pcm_ ## name_ ## _muxer = { \ ++ .name = #name_, \ ++ .long_name = NULL_IF_CONFIG_SMALL(long_name_), \ ++ .extensions = ext, \ ++ .audio_codec = codec, \ ++ .video_codec = CODEC_ID_NONE, \ ++ .write_packet = ff_raw_write_packet, \ ++ .flags = AVFMT_NOTIMESTAMPS, \ + }; + + PCMDEF(f64be, "PCM 64 bit floating-point big-endian format", +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pmpdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pmpdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pmpdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pmpdec.c 2012-05-14 14:08:55.120355801 +0200 +@@ -0,0 +1,179 @@ ++/* ++ * PMP demuxer. ++ * Copyright (c) 2011 Reimar Döffinger ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++ ++typedef struct { ++ int cur_stream; ++ int num_streams; ++ int audio_packets; ++ int current_packet; ++ uint32_t *packet_sizes; ++ int packet_sizes_alloc; ++} PMPContext; ++ ++static int pmp_probe(AVProbeData *p) { ++ if (AV_RN32(p->buf) == AV_RN32("pmpm") && ++ AV_RL32(p->buf + 4) == 1) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int pmp_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ PMPContext *pmp = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int tb_num, tb_den; ++ int index_cnt; ++ int audio_codec_id = CODEC_ID_NONE; ++ int srate, channels; ++ int i; ++ uint64_t pos; ++ AVStream *vst = avformat_new_stream(s, NULL); ++ if (!vst) ++ return AVERROR(ENOMEM); ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ avio_skip(pb, 8); ++ switch (avio_rl32(pb)) { ++ case 0: ++ vst->codec->codec_id = CODEC_ID_MPEG4; ++ break; ++ case 1: ++ vst->codec->codec_id = CODEC_ID_H264; ++ break; ++ default: ++ av_log(s, AV_LOG_ERROR, "Unsupported video format\n"); ++ break; ++ } ++ index_cnt = avio_rl32(pb); ++ vst->codec->width = avio_rl32(pb); ++ vst->codec->height = avio_rl32(pb); ++ ++ tb_num = avio_rl32(pb); ++ tb_den = avio_rl32(pb); ++ avpriv_set_pts_info(vst, 32, tb_num, tb_den); ++ vst->nb_frames = index_cnt; ++ vst->duration = index_cnt; ++ ++ switch (avio_rl32(pb)) { ++ case 0: ++ audio_codec_id = CODEC_ID_MP3; ++ break; ++ case 1: ++ av_log(s, AV_LOG_ERROR, "AAC not yet correctly supported\n"); ++ audio_codec_id = CODEC_ID_AAC; ++ break; ++ default: ++ av_log(s, AV_LOG_ERROR, "Unsupported audio format\n"); ++ break; ++ } ++ pmp->num_streams = avio_rl16(pb) + 1; ++ avio_skip(pb, 10); ++ srate = avio_rl32(pb); ++ channels = avio_rl32(pb) + 1; ++ for (i = 1; i < pmp->num_streams; i++) { ++ AVStream *ast = avformat_new_stream(s, NULL); ++ if (!ast) ++ return AVERROR(ENOMEM); ++ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ast->codec->codec_id = audio_codec_id; ++ ast->codec->channels = channels; ++ ast->codec->sample_rate = srate; ++ avpriv_set_pts_info(ast, 32, 1, srate); ++ } ++ pos = avio_tell(pb) + 4*index_cnt; ++ for (i = 0; i < index_cnt; i++) { ++ int size = avio_rl32(pb); ++ int flags = size & 1 ? AVINDEX_KEYFRAME : 0; ++ size >>= 1; ++ av_add_index_entry(vst, pos, i, size, 0, flags); ++ pos += size; ++ } ++ return 0; ++} ++ ++static int pmp_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ PMPContext *pmp = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int ret = 0; ++ int i; ++ ++ if (url_feof(pb)) ++ return AVERROR_EOF; ++ if (pmp->cur_stream == 0) { ++ int num_packets; ++ pmp->audio_packets = avio_r8(pb); ++ num_packets = (pmp->num_streams - 1) * pmp->audio_packets + 1; ++ avio_skip(pb, 8); ++ pmp->current_packet = 0; ++ av_fast_malloc(&pmp->packet_sizes, ++ &pmp->packet_sizes_alloc, ++ num_packets * sizeof(*pmp->packet_sizes)); ++ if (!pmp->packet_sizes_alloc) { ++ av_log(s, AV_LOG_ERROR, "Cannot (re)allocate packet buffer\n"); ++ return AVERROR(ENOMEM); ++ } ++ for (i = 0; i < num_packets; i++) ++ pmp->packet_sizes[i] = avio_rl32(pb); ++ } ++ ret = av_get_packet(pb, pkt, pmp->packet_sizes[pmp->current_packet]); ++ if (ret >= 0) { ++ ret = 0; ++ // FIXME: this is a hack that should be removed once ++ // compute_pkt_fields() can handle timestamps properly ++ if (pmp->cur_stream == 0) ++ pkt->dts = s->streams[0]->cur_dts++; ++ pkt->stream_index = pmp->cur_stream; ++ } ++ if (pmp->current_packet % pmp->audio_packets == 0) ++ pmp->cur_stream = (pmp->cur_stream + 1) % pmp->num_streams; ++ pmp->current_packet++; ++ return ret; ++} ++ ++static int pmp_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags) ++{ ++ PMPContext *pmp = s->priv_data; ++ pmp->cur_stream = 0; ++ // fallback to default seek now ++ return AVERROR(ENOSYS); ++} ++ ++static int pmp_close(AVFormatContext *s) ++{ ++ PMPContext *pmp = s->priv_data; ++ av_freep(&pmp->packet_sizes); ++ return 0; ++} ++ ++AVInputFormat ff_pmp_demuxer = { ++ .name = "pmp", ++ .long_name = NULL_IF_CONFIG_SMALL("Playstation Portable PMP format"), ++ .priv_data_size = sizeof(PMPContext), ++ .read_probe = pmp_probe, ++ .read_header = pmp_header, ++ .read_packet = pmp_packet, ++ .read_seek = pmp_seek, ++ .read_close = pmp_close, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/psxstr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/psxstr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/psxstr.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/psxstr.c 2012-05-14 14:08:55.121355822 +0200 +@@ -31,6 +31,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define RIFF_TAG MKTAG('R', 'I', 'F', 'F') + #define CDXA_TAG MKTAG('C', 'D', 'X', 'A') +@@ -68,6 +69,8 @@ + static int str_probe(AVProbeData *p) + { + uint8_t *sector= p->buf; ++ uint8_t *end= sector + p->buf_size; ++ int aud=0, vid=0; + + if (p->buf_size < RAW_CD_SECTOR_SIZE) + return 0; +@@ -79,40 +82,72 @@ + sector += RIFF_HEADER_SIZE; + } + +- /* look for CD sync header (00, 0xFF x 10, 00) */ +- if (memcmp(sector,sync_header,sizeof(sync_header))) +- return 0; ++ while (end - sector >= RAW_CD_SECTOR_SIZE) { ++ /* look for CD sync header (00, 0xFF x 10, 00) */ ++ if (memcmp(sector,sync_header,sizeof(sync_header))) ++ return 0; + +- if(sector[0x11] >= 32) +- return 0; +- if( (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_VIDEO +- && (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_AUDIO +- && (sector[0x12] & CDXA_TYPE_MASK) != CDXA_TYPE_DATA) +- return 0; ++ if (sector[0x11] >= 32) ++ return 0; ++ ++ switch (sector[0x12] & CDXA_TYPE_MASK) { ++ case CDXA_TYPE_DATA: ++ case CDXA_TYPE_VIDEO: { ++ int current_sector = AV_RL16(§or[0x1C]); ++ int sector_count = AV_RL16(§or[0x1E]); ++ int frame_size = AV_RL32(§or[0x24]); + ++ if(!( frame_size>=0 ++ && current_sector < sector_count ++ && sector_count*VIDEO_DATA_CHUNK_SIZE >=frame_size)){ ++ return 0; ++ } ++ ++ /*st->codec->width = AV_RL16(§or[0x28]); ++ st->codec->height = AV_RL16(§or[0x2A]);*/ ++ ++// if (current_sector == sector_count-1) { ++ vid++; ++// } ++ ++ } ++ break; ++ case CDXA_TYPE_AUDIO: ++ if(sector[0x13]&0x2A) ++ return 0; ++ aud++; ++ break; ++ default: ++ if(sector[0x12] & CDXA_TYPE_MASK) ++ return 0; ++ } ++ sector += RAW_CD_SECTOR_SIZE; ++ } + /* MPEG files (like those ripped from VCDs) can also look like this; + * only return half certainty */ +- return 50; ++ if(vid+aud > 3) return 50; ++ else if(vid+aud) return 1; ++ else return 0; + } + + static int str_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + StrDemuxContext *str = s->priv_data; + unsigned char sector[RAW_CD_SECTOR_SIZE]; + int start; + int i; + + /* skip over any RIFF header */ +- if (get_buffer(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE) ++ if (avio_read(pb, sector, RIFF_HEADER_SIZE) != RIFF_HEADER_SIZE) + return AVERROR(EIO); + if (AV_RL32(§or[0]) == RIFF_TAG) + start = RIFF_HEADER_SIZE; + else + start = 0; + +- url_fseek(pb, start, SEEK_SET); ++ avio_seek(pb, start, SEEK_SET); + + for(i=0; i<32; i++){ + str->channels[i].video_stream_index= +@@ -127,7 +162,7 @@ + static int str_read_packet(AVFormatContext *s, + AVPacket *ret_pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + StrDemuxContext *str = s->priv_data; + unsigned char sector[RAW_CD_SECTOR_SIZE]; + int channel; +@@ -136,7 +171,7 @@ + + while (1) { + +- if (get_buffer(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) ++ if (avio_read(pb, sector, RAW_CD_SECTOR_SIZE) != RAW_CD_SECTOR_SIZE) + return AVERROR(EIO); + + channel = sector[0x11]; +@@ -162,10 +197,10 @@ + + if(str->channels[channel].video_stream_index < 0){ + /* allocate a new AVStream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 64, 1, 15); ++ avpriv_set_pts_info(st, 64, 1, 15); + + str->channels[channel].video_stream_index = st->index; + +@@ -186,7 +221,7 @@ + if (av_new_packet(pkt, sector_count*VIDEO_DATA_CHUNK_SIZE)) + return AVERROR(EIO); + +- pkt->pos= url_ftell(pb) - RAW_CD_SECTOR_SIZE; ++ pkt->pos= avio_tell(pb) - RAW_CD_SECTOR_SIZE; + pkt->stream_index = + str->channels[channel].video_stream_index; + } +@@ -210,7 +245,7 @@ + if(str->channels[channel].audio_stream_index < 0){ + int fmt = sector[0x13]; + /* allocate a new AVStream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -224,7 +259,7 @@ + // st->codec->bit_rate = 0; //FIXME; + st->codec->block_align = 128; + +- av_set_pts_info(st, 64, 128, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 128, st->codec->sample_rate); + } + pkt = ret_pkt; + if (av_new_packet(pkt, 2304)) +@@ -234,7 +269,6 @@ + pkt->stream_index = + str->channels[channel].audio_stream_index; + return 0; +- break; + default: + av_log(s, AV_LOG_WARNING, "Unknown sector type %02X\n", sector[0x12]); + /* drop the sector and move on */ +@@ -259,11 +293,11 @@ + } + + AVInputFormat ff_str_demuxer = { +- "psxstr", +- NULL_IF_CONFIG_SMALL("Sony Playstation STR format"), +- sizeof(StrDemuxContext), +- str_probe, +- str_read_header, +- str_read_packet, +- str_read_close, ++ .name = "psxstr", ++ .long_name = NULL_IF_CONFIG_SMALL("Sony Playstation STR format"), ++ .priv_data_size = sizeof(StrDemuxContext), ++ .read_probe = str_probe, ++ .read_header = str_read_header, ++ .read_packet = str_read_packet, ++ .read_close = str_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pva.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pva.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/pva.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/pva.c 2012-05-14 14:08:55.122355842 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "mpeg.h" + + #define PVA_MAX_PAYLOAD_LENGTH 0x17f8 +@@ -31,32 +32,45 @@ + int continue_pes; + } PVAContext; + ++static int pva_check(uint8_t *p) { ++ int length = AV_RB16(p + 6); ++ if (AV_RB16(p) != PVA_MAGIC || !p[2] || p[2] > 2 || p[4] != 0x55 || ++ (p[5] & 0xe0) || length > PVA_MAX_PAYLOAD_LENGTH) ++ return -1; ++ return length + 8; ++} ++ + static int pva_probe(AVProbeData * pd) { + unsigned char *buf = pd->buf; ++ int len = pva_check(buf); + +- if (AV_RB16(buf) == PVA_MAGIC && buf[2] && buf[2] < 3 && buf[4] == 0x55) ++ if (len < 0) ++ return 0; ++ ++ if (pd->buf_size >= len + 8 && ++ pva_check(buf + len) >= 0) + return AVPROBE_SCORE_MAX / 2; + +- return 0; ++ return AVPROBE_SCORE_MAX / 4; + } + + static int pva_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + +- if (!(st = av_new_stream(s, 0))) ++ if (!(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_MPEG2VIDEO; + st->need_parsing = AVSTREAM_PARSE_FULL; +- av_set_pts_info(st, 32, 1, 90000); ++ avpriv_set_pts_info(st, 32, 1, 90000); + av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); + +- if (!(st = av_new_stream(s, 1))) ++ if (!(st = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_MP2; + st->need_parsing = AVSTREAM_PARSE_FULL; +- av_set_pts_info(st, 33, 1, 90000); ++ avpriv_set_pts_info(st, 33, 1, 90000); + av_add_index_entry(st, 0, 0, 0, 0, AVINDEX_KEYFRAME); + + /* the parameters will be extracted from the compressed bitstream */ +@@ -67,20 +81,20 @@ + + static int read_part_of_packet(AVFormatContext *s, int64_t *pts, + int *len, int *strid, int read_packet) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + PVAContext *pvactx = s->priv_data; + int syncword, streamid, reserved, flags, length, pts_flag; + int64_t pva_pts = AV_NOPTS_VALUE, startpos; + + recover: +- startpos = url_ftell(pb); ++ startpos = avio_tell(pb); + +- syncword = get_be16(pb); +- streamid = get_byte(pb); +- get_byte(pb); /* counter not used */ +- reserved = get_byte(pb); +- flags = get_byte(pb); +- length = get_be16(pb); ++ syncword = avio_rb16(pb); ++ streamid = avio_r8(pb); ++ avio_r8(pb); /* counter not used */ ++ reserved = avio_r8(pb); ++ flags = avio_r8(pb); ++ length = avio_rb16(pb); + + pts_flag = flags & 0x10; + +@@ -101,7 +115,7 @@ + } + + if (streamid == PVA_VIDEO_PAYLOAD && pts_flag) { +- pva_pts = get_be32(pb); ++ pva_pts = avio_rb32(pb); + length -= 4; + } else if (streamid == PVA_AUDIO_PAYLOAD) { + /* PVA Audio Packets either start with a signaled PES packet or +@@ -113,22 +127,22 @@ + pes_flags; + unsigned char pes_header_data[256]; + +- pes_signal = get_be24(pb); +- get_byte(pb); +- pes_packet_length = get_be16(pb); +- pes_flags = get_be16(pb); +- pes_header_data_length = get_byte(pb); ++ pes_signal = avio_rb24(pb); ++ avio_r8(pb); ++ pes_packet_length = avio_rb16(pb); ++ pes_flags = avio_rb16(pb); ++ pes_header_data_length = avio_r8(pb); + + if (pes_signal != 1) { + pva_log(s, AV_LOG_WARNING, "expected signaled PES packet, " + "trying to recover\n"); +- url_fskip(pb, length - 9); ++ avio_skip(pb, length - 9); + if (!read_packet) + return AVERROR(EIO); + goto recover; + } + +- get_buffer(pb, pes_header_data, pes_header_data_length); ++ avio_read(pb, pes_header_data, pes_header_data_length); + length -= 9 + pes_header_data_length; + + pes_packet_length -= 3 + pes_header_data_length; +@@ -157,7 +171,7 @@ + } + + static int pva_read_packet(AVFormatContext *s, AVPacket *pkt) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pva_pts; + int ret, length, streamid; + +@@ -173,7 +187,7 @@ + + static int64_t pva_read_timestamp(struct AVFormatContext *s, int stream_index, + int64_t *pos, int64_t pos_limit) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + PVAContext *pvactx = s->priv_data; + int length, streamid; + int64_t res = AV_NOPTS_VALUE; +@@ -182,7 +196,7 @@ + + while (*pos < pos_limit) { + res = AV_NOPTS_VALUE; +- url_fseek(pb, *pos, SEEK_SET); ++ avio_seek(pb, *pos, SEEK_SET); + + pvactx->continue_pes = 0; + if (read_part_of_packet(s, &res, &length, &streamid, 0)) { +@@ -190,7 +204,7 @@ + continue; + } + if (streamid - 1 != stream_index || res == AV_NOPTS_VALUE) { +- *pos = url_ftell(pb) + length; ++ *pos = avio_tell(pb) + length; + continue; + } + break; +@@ -201,11 +215,11 @@ + } + + AVInputFormat ff_pva_demuxer = { +- "pva", +- NULL_IF_CONFIG_SMALL("TechnoTrend PVA file and stream format"), +- sizeof(PVAContext), +- pva_probe, +- pva_read_header, +- pva_read_packet, ++ .name = "pva", ++ .long_name = NULL_IF_CONFIG_SMALL("TechnoTrend PVA file and stream format"), ++ .priv_data_size = sizeof(PVAContext), ++ .read_probe = pva_probe, ++ .read_header = pva_read_header, ++ .read_packet = pva_read_packet, + .read_timestamp = pva_read_timestamp + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/qcp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/qcp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/qcp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/qcp.c 2012-05-14 14:08:55.123355862 +0200 +@@ -23,7 +23,7 @@ + * @file + * QCP format (.qcp) demuxer + * @author Kenan Gillet +- * @sa RFC 3625: "The QCP File Format and Media Types for Speech Data" ++ * @see RFC 3625: "The QCP File Format and Media Types for Speech Data" + * http://tools.ietf.org/html/rfc3625 + */ + +@@ -82,22 +82,21 @@ + + static int qcp_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + QCPContext *c = s->priv_data; +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + uint8_t buf[16]; + int i, nb_rates; + + if (!st) + return AVERROR(ENOMEM); + +- get_be32(pb); // "RIFF" +- s->file_size = get_le32(pb) + 8; +- url_fskip(pb, 8 + 4 + 1 + 1); // "QLCMfmt " + chunk-size + major-version + minor-version ++ avio_rb32(pb); // "RIFF" ++ avio_skip(pb, 4 + 8 + 4 + 1 + 1); // filesize + "QLCMfmt " + chunk-size + major-version + minor-version + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->channels = 1; +- get_buffer(pb, buf, 16); ++ avio_read(pb, buf, 16); + if (is_qcelp_13k_guid(buf)) { + st->codec->codec_id = CODEC_ID_QCELP; + } else if (!memcmp(buf, guid_evrc, 16)) { +@@ -110,39 +109,39 @@ + av_log(s, AV_LOG_ERROR, "Unknown codec GUID.\n"); + return AVERROR_INVALIDDATA; + } +- url_fskip(pb, 2 + 80); // codec-version + codec-name +- st->codec->bit_rate = get_le16(pb); ++ avio_skip(pb, 2 + 80); // codec-version + codec-name ++ st->codec->bit_rate = avio_rl16(pb); + +- s->packet_size = get_le16(pb); +- url_fskip(pb, 2); // block-size +- st->codec->sample_rate = get_le16(pb); +- url_fskip(pb, 2); // sample-size ++ s->packet_size = avio_rl16(pb); ++ avio_skip(pb, 2); // block-size ++ st->codec->sample_rate = avio_rl16(pb); ++ avio_skip(pb, 2); // sample-size + + memset(c->rates_per_mode, -1, sizeof(c->rates_per_mode)); +- nb_rates = get_le32(pb); ++ nb_rates = avio_rl32(pb); + nb_rates = FFMIN(nb_rates, 8); + for (i=0; i QCP_MAX_MODE) { + av_log(s, AV_LOG_WARNING, "Unknown entry %d=>%d in rate-map-table.\n ", mode, size); + } else + c->rates_per_mode[mode] = size; + } +- url_fskip(pb, 16 - 2*nb_rates + 20); // empty entries of rate-map-table + reserved ++ avio_skip(pb, 16 - 2*nb_rates + 20); // empty entries of rate-map-table + reserved + + return 0; + } + + static int qcp_read_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + QCPContext *c = s->priv_data; + unsigned int chunk_size, tag; + + while(!url_feof(pb)) { + if (c->data_size) { +- int pkt_size, ret, mode = get_byte(pb); ++ int pkt_size, ret, mode = avio_r8(pb); + + if (s->packet_size) { + pkt_size = s->packet_size - 1; +@@ -165,23 +164,23 @@ + return ret; + } + +- if (url_ftell(pb) & 1 && get_byte(pb)) ++ if (avio_tell(pb) & 1 && avio_r8(pb)) + av_log(s, AV_LOG_WARNING, "Padding should be 0.\n"); + +- tag = get_le32(pb); +- chunk_size = get_le32(pb); ++ tag = avio_rl32(pb); ++ chunk_size = avio_rl32(pb); + switch (tag) { + case MKTAG('v', 'r', 'a', 't'): +- if (get_le32(pb)) // var-rate-flag ++ if (avio_rl32(pb)) // var-rate-flag + s->packet_size = 0; +- url_fskip(pb, 4); // size-in-packets ++ avio_skip(pb, 4); // size-in-packets + break; + case MKTAG('d', 'a', 't', 'a'): + c->data_size = chunk_size; + break; + + default: +- url_fskip(pb, chunk_size); ++ avio_skip(pb, chunk_size); + } + } + return AVERROR_EOF; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/r3d.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/r3d.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/r3d.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/r3d.c 2012-05-14 14:08:55.125355902 +0200 +@@ -22,7 +22,10 @@ + //#define DEBUG + + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" + #include "avformat.h" ++#include "internal.h" + + typedef struct { + unsigned video_offsets_count; +@@ -38,66 +41,67 @@ + + static int read_atom(AVFormatContext *s, Atom *atom) + { +- atom->offset = url_ftell(s->pb); +- atom->size = get_be32(s->pb); ++ atom->offset = avio_tell(s->pb); ++ atom->size = avio_rb32(s->pb); + if (atom->size < 8) + return -1; +- atom->tag = get_le32(s->pb); +- av_dlog(s, "atom %d %.4s offset %#llx\n", ++ atom->tag = avio_rl32(s->pb); ++ av_dlog(s, "atom %u %.4s offset %#"PRIx64"\n", + atom->size, (char*)&atom->tag, atom->offset); + return atom->size; + } + + static int r3d_read_red1(AVFormatContext *s) + { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + char filename[258]; +- int tmp, tmp2; ++ int tmp; ++ int av_unused tmp2; + + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_JPEG2000; + +- tmp = get_byte(s->pb); // major version +- tmp2 = get_byte(s->pb); // minor version ++ tmp = avio_r8(s->pb); // major version ++ tmp2 = avio_r8(s->pb); // minor version + av_dlog(s, "version %d.%d\n", tmp, tmp2); + +- tmp = get_be16(s->pb); // unknown ++ tmp = avio_rb16(s->pb); // unknown + av_dlog(s, "unknown1 %d\n", tmp); + +- tmp = get_be32(s->pb); +- av_set_pts_info(st, 32, 1, tmp); ++ tmp = avio_rb32(s->pb); ++ avpriv_set_pts_info(st, 32, 1, tmp); + +- tmp = get_be32(s->pb); // filenum ++ tmp = avio_rb32(s->pb); // filenum + av_dlog(s, "filenum %d\n", tmp); + +- url_fskip(s->pb, 32); // unknown ++ avio_skip(s->pb, 32); // unknown + +- st->codec->width = get_be32(s->pb); +- st->codec->height = get_be32(s->pb); ++ st->codec->width = avio_rb32(s->pb); ++ st->codec->height = avio_rb32(s->pb); + +- tmp = get_be16(s->pb); // unknown ++ tmp = avio_rb16(s->pb); // unknown + av_dlog(s, "unknown2 %d\n", tmp); + +- st->codec->time_base.den = get_be16(s->pb); +- st->codec->time_base.num = get_be16(s->pb); ++ st->codec->time_base.den = avio_rb16(s->pb); ++ st->codec->time_base.num = avio_rb16(s->pb); + +- tmp = get_byte(s->pb); // audio channels ++ tmp = avio_r8(s->pb); // audio channels + av_dlog(s, "audio channels %d\n", tmp); + if (tmp > 0) { +- AVStream *ast = av_new_stream(s, 1); ++ AVStream *ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codec->codec_id = CODEC_ID_PCM_S32BE; + ast->codec->channels = tmp; +- av_set_pts_info(ast, 32, 1, st->time_base.den); ++ avpriv_set_pts_info(ast, 32, 1, st->time_base.den); + } + +- get_buffer(s->pb, filename, 257); ++ avio_read(s->pb, filename, 257); + filename[sizeof(filename)-1] = 0; +- av_metadata_set2(&st->metadata, "filename", filename, 0); ++ av_dict_set(&st->metadata, "filename", filename, 0); + + av_dlog(s, "filename %s\n", filename); + av_dlog(s, "resolution %dx%d\n", st->codec->width, st->codec->height); +@@ -120,7 +124,7 @@ + return AVERROR(ENOMEM); + + for (i = 0; i < r3d->video_offsets_count; i++) { +- r3d->video_offsets[i] = get_be32(s->pb); ++ r3d->video_offsets[i] = avio_rb32(s->pb); + if (!r3d->video_offsets[i]) { + r3d->video_offsets_count = i; + break; +@@ -131,7 +135,7 @@ + if (st->codec->time_base.den) + st->duration = (uint64_t)r3d->video_offsets_count* + st->time_base.den*st->codec->time_base.num/st->codec->time_base.den; +- av_dlog(s, "duration %lld\n", st->duration); ++ av_dlog(s, "duration %"PRId64"\n", st->duration); + + return 0; + } +@@ -139,20 +143,20 @@ + static void r3d_read_reos(AVFormatContext *s) + { + R3DContext *r3d = s->priv_data; +- int tmp; ++ int av_unused tmp; + +- r3d->rdvo_offset = get_be32(s->pb); +- get_be32(s->pb); // rdvs offset +- get_be32(s->pb); // rdao offset +- get_be32(s->pb); // rdas offset ++ r3d->rdvo_offset = avio_rb32(s->pb); ++ avio_rb32(s->pb); // rdvs offset ++ avio_rb32(s->pb); // rdao offset ++ avio_rb32(s->pb); // rdas offset + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "num video chunks %d\n", tmp); + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "num audio chunks %d\n", tmp); + +- url_fskip(s->pb, 6*4); ++ avio_skip(s->pb, 6*4); + } + + static int r3d_read_header(AVFormatContext *s, AVFormatParameters *ap) +@@ -175,12 +179,12 @@ + return -1; + } + +- s->data_offset = url_ftell(s->pb); +- av_dlog(s, "data offset %#llx\n", s->data_offset); +- if (url_is_streamed(s->pb)) ++ s->data_offset = avio_tell(s->pb); ++ av_dlog(s, "data offset %#"PRIx64"\n", s->data_offset); ++ if (!s->pb->seekable) + return 0; + // find REOB/REOF/REOS to load index +- url_fseek(s->pb, url_fsize(s->pb)-48-8, SEEK_SET); ++ avio_seek(s->pb, avio_size(s->pb)-48-8, SEEK_SET); + if (read_atom(s, &atom) < 0) + av_log(s, AV_LOG_ERROR, "error reading end atom\n"); + +@@ -192,7 +196,7 @@ + r3d_read_reos(s); + + if (r3d->rdvo_offset) { +- url_fseek(s->pb, r3d->rdvo_offset, SEEK_SET); ++ avio_seek(s->pb, r3d->rdvo_offset, SEEK_SET); + if (read_atom(s, &atom) < 0) + av_log(s, AV_LOG_ERROR, "error reading 'rdvo' atom\n"); + if (atom.tag == MKTAG('R','D','V','O')) { +@@ -202,46 +206,47 @@ + } + + out: +- url_fseek(s->pb, s->data_offset, SEEK_SET); ++ avio_seek(s->pb, s->data_offset, SEEK_SET); + return 0; + } + + static int r3d_read_redv(AVFormatContext *s, AVPacket *pkt, Atom *atom) + { + AVStream *st = s->streams[0]; +- int tmp, tmp2; +- uint64_t pos = url_ftell(s->pb); ++ int tmp; ++ int av_unused tmp2; ++ uint64_t pos = avio_tell(s->pb); + unsigned dts; + int ret; + +- dts = get_be32(s->pb); ++ dts = avio_rb32(s->pb); + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "frame num %d\n", tmp); + +- tmp = get_byte(s->pb); // major version +- tmp2 = get_byte(s->pb); // minor version ++ tmp = avio_r8(s->pb); // major version ++ tmp2 = avio_r8(s->pb); // minor version + av_dlog(s, "version %d.%d\n", tmp, tmp2); + +- tmp = get_be16(s->pb); // unknown ++ tmp = avio_rb16(s->pb); // unknown + av_dlog(s, "unknown %d\n", tmp); + + if (tmp > 4) { +- tmp = get_be16(s->pb); // unknown ++ tmp = avio_rb16(s->pb); // unknown + av_dlog(s, "unknown %d\n", tmp); + +- tmp = get_be16(s->pb); // unknown ++ tmp = avio_rb16(s->pb); // unknown + av_dlog(s, "unknown %d\n", tmp); + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "width %d\n", tmp); +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "height %d\n", tmp); + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "metadata len %d\n", tmp); + } +- tmp = atom->size - 8 - (url_ftell(s->pb) - pos); ++ tmp = atom->size - 8 - (avio_tell(s->pb) - pos); + if (tmp < 0) + return -1; + ret = av_get_packet(s->pb, pkt, tmp); +@@ -255,7 +260,7 @@ + if (st->codec->time_base.den) + pkt->duration = (uint64_t)st->time_base.den* + st->codec->time_base.num/st->codec->time_base.den; +- av_dlog(s, "pkt dts %lld duration %d\n", pkt->dts, pkt->duration); ++ av_dlog(s, "pkt dts %"PRId64" duration %d\n", pkt->dts, pkt->duration); + + return 0; + } +@@ -263,31 +268,32 @@ + static int r3d_read_reda(AVFormatContext *s, AVPacket *pkt, Atom *atom) + { + AVStream *st = s->streams[1]; +- int tmp, tmp2, samples, size; +- uint64_t pos = url_ftell(s->pb); ++ int av_unused tmp, tmp2; ++ int samples, size; ++ uint64_t pos = avio_tell(s->pb); + unsigned dts; + int ret; + +- dts = get_be32(s->pb); ++ dts = avio_rb32(s->pb); + +- st->codec->sample_rate = get_be32(s->pb); ++ st->codec->sample_rate = avio_rb32(s->pb); + +- samples = get_be32(s->pb); ++ samples = avio_rb32(s->pb); + +- tmp = get_be32(s->pb); ++ tmp = avio_rb32(s->pb); + av_dlog(s, "packet num %d\n", tmp); + +- tmp = get_be16(s->pb); // unkown ++ tmp = avio_rb16(s->pb); // unkown + av_dlog(s, "unknown %d\n", tmp); + +- tmp = get_byte(s->pb); // major version +- tmp2 = get_byte(s->pb); // minor version ++ tmp = avio_r8(s->pb); // major version ++ tmp2 = avio_r8(s->pb); // minor version + av_dlog(s, "version %d.%d\n", tmp, tmp2); + +- tmp = get_be32(s->pb); // unknown ++ tmp = avio_rb32(s->pb); // unknown + av_dlog(s, "unknown %d\n", tmp); + +- size = atom->size - 8 - (url_ftell(s->pb) - pos); ++ size = atom->size - 8 - (avio_tell(s->pb) - pos); + if (size < 0) + return -1; + ret = av_get_packet(s->pb, pkt, size); +@@ -299,7 +305,7 @@ + pkt->stream_index = 1; + pkt->dts = dts; + pkt->duration = av_rescale(samples, st->time_base.den, st->codec->sample_rate); +- av_dlog(s, "pkt dts %lld duration %d samples %d sample rate %d\n", ++ av_dlog(s, "pkt dts %"PRId64" duration %d samples %d sample rate %d\n", + pkt->dts, pkt->duration, samples, st->codec->sample_rate); + + return 0; +@@ -332,7 +338,7 @@ + break; + default: + skip: +- url_fskip(s->pb, atom.size-8); ++ avio_skip(s->pb, atom.size-8); + } + } + return err; +@@ -352,14 +358,16 @@ + int frame_num; + + if (!st->codec->time_base.num || !st->time_base.den) +- return -1; ++ return AVERROR(ENOSYS); + + frame_num = sample_time*st->codec->time_base.den/ + ((int64_t)st->codec->time_base.num*st->time_base.den); +- av_dlog(s, "seek frame num %d timestamp %lld\n", frame_num, sample_time); ++ av_dlog(s, "seek frame num %d timestamp %"PRId64"\n", ++ frame_num, sample_time); + + if (frame_num < r3d->video_offsets_count) { +- url_fseek(s->pb, r3d->video_offsets_count, SEEK_SET); ++ if (avio_seek(s->pb, r3d->video_offsets_count, SEEK_SET) < 0) ++ return -1; + } else { + av_log(s, AV_LOG_ERROR, "could not seek to frame %d\n", frame_num); + return -1; +@@ -378,12 +386,12 @@ + } + + AVInputFormat ff_r3d_demuxer = { +- "r3d", +- NULL_IF_CONFIG_SMALL("REDCODE R3D format"), +- sizeof(R3DContext), +- r3d_probe, +- r3d_read_header, +- r3d_read_packet, +- r3d_close, +- r3d_seek, ++ .name = "r3d", ++ .long_name = NULL_IF_CONFIG_SMALL("REDCODE R3D format"), ++ .priv_data_size = sizeof(R3DContext), ++ .read_probe = r3d_probe, ++ .read_header = r3d_read_header, ++ .read_packet = r3d_read_packet, ++ .read_close = r3d_close, ++ .read_seek = r3d_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawdec.c 2012-05-14 14:08:55.126355922 +0200 +@@ -21,7 +21,12 @@ + */ + + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "rawdec.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/pixdesc.h" + + /* raw input */ + int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap) +@@ -29,7 +34,7 @@ + AVStream *st; + enum CodecID id; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -42,26 +47,57 @@ + st->codec->codec_id = id; + + switch(st->codec->codec_type) { +- case AVMEDIA_TYPE_AUDIO: +- st->codec->sample_rate = ap->sample_rate; +- if(ap->channels) st->codec->channels = ap->channels; +- else st->codec->channels = 1; ++ case AVMEDIA_TYPE_AUDIO: { ++ RawAudioDemuxerContext *s1 = s->priv_data; ++ ++ st->codec->channels = 1; ++ ++ if (id == CODEC_ID_ADPCM_G722) ++ st->codec->sample_rate = 16000; ++ ++ if (s1 && s1->sample_rate) ++ st->codec->sample_rate = s1->sample_rate; ++ if (st->codec->sample_rate <= 0) { ++ av_log(s, AV_LOG_WARNING, "Invalid sample rate %d specified using default of 44100\n", ++ st->codec->sample_rate); ++ st->codec->sample_rate= 44100; ++ } ++ ++ if (s1 && s1->channels) ++ st->codec->channels = s1->channels; ++ + st->codec->bits_per_coded_sample = av_get_bits_per_sample(st->codec->codec_id); + assert(st->codec->bits_per_coded_sample > 0); + st->codec->block_align = st->codec->bits_per_coded_sample*st->codec->channels/8; +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); +- break; +- case AVMEDIA_TYPE_VIDEO: +- if(ap->time_base.num) +- av_set_pts_info(st, 64, ap->time_base.num, ap->time_base.den); +- else +- av_set_pts_info(st, 64, 1, 25); +- st->codec->width = ap->width; +- st->codec->height = ap->height; +- st->codec->pix_fmt = ap->pix_fmt; +- if(st->codec->pix_fmt == PIX_FMT_NONE) +- st->codec->pix_fmt= PIX_FMT_YUV420P; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + break; ++ } ++ case AVMEDIA_TYPE_VIDEO: { ++ FFRawVideoDemuxerContext *s1 = s->priv_data; ++ int width = 0, height = 0, ret = 0; ++ enum PixelFormat pix_fmt; ++ AVRational framerate; ++ ++ if (s1->video_size && (ret = av_parse_video_size(&width, &height, s1->video_size)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Couldn't parse video size.\n"); ++ goto fail; ++ } ++ if ((pix_fmt = av_get_pix_fmt(s1->pixel_format)) == PIX_FMT_NONE) { ++ av_log(s, AV_LOG_ERROR, "No such pixel format: %s.\n", s1->pixel_format); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate); ++ goto fail; ++ } ++ avpriv_set_pts_info(st, 64, framerate.den, framerate.num); ++ st->codec->width = width; ++ st->codec->height = height; ++ st->codec->pix_fmt = pix_fmt; ++fail: ++ return ret; ++ } + default: + return -1; + } +@@ -79,26 +115,27 @@ + if (av_new_packet(pkt, size) < 0) + return AVERROR(ENOMEM); + +- pkt->pos= url_ftell(s->pb); ++ pkt->pos= avio_tell(s->pb); + pkt->stream_index = 0; +- ret = get_partial_buffer(s->pb, pkt->data, size); ++ ret = ffio_read_partial(s->pb, pkt->data, size); + if (ret < 0) { + av_free_packet(pkt); + return ret; + } +- pkt->size = ret; ++ av_shrink_packet(pkt, ret); + return ret; + } + + int ff_raw_audio_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = s->iformat->value; + st->need_parsing = AVSTREAM_PARSE_FULL; ++ st->start_time = 0; + /* the parameters will be extracted from the compressed bitstream */ + + return 0; +@@ -109,84 +146,76 @@ + AVFormatParameters *ap) + { + AVStream *st; ++ FFRawVideoDemuxerContext *s1 = s->priv_data; ++ AVRational framerate; ++ int ret = 0; + +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } + + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = s->iformat->value; + st->need_parsing = AVSTREAM_PARSE_FULL; + +- /* for MJPEG, specify frame rate */ +- /* for MPEG-4 specify it, too (most MPEG-4 streams do not have the fixed_vop_rate set ...)*/ +- if (ap->time_base.num) { +- st->codec->time_base= ap->time_base; +- } else if ( st->codec->codec_id == CODEC_ID_MJPEG || +- st->codec->codec_id == CODEC_ID_MPEG4 || +- st->codec->codec_id == CODEC_ID_DIRAC || +- st->codec->codec_id == CODEC_ID_DNXHD || +- st->codec->codec_id == CODEC_ID_VC1 || +- st->codec->codec_id == CODEC_ID_H264) { +- st->codec->time_base= (AVRational){1,25}; ++ if ((ret = av_parse_video_rate(&framerate, s1->framerate)) < 0) { ++ av_log(s, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s1->framerate); ++ goto fail; + } +- av_set_pts_info(st, 64, 1, 1200000); + +- return 0; ++ st->codec->time_base = (AVRational){framerate.den, framerate.num}; ++ avpriv_set_pts_info(st, 64, 1, 1200000); ++ ++fail: ++ return ret; + } + + /* Note: Do not forget to add new entries to the Makefile as well. */ + ++#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++const AVOption ff_rawvideo_options[] = { ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC}, ++ { NULL }, ++}; ++ + #if CONFIG_G722_DEMUXER + AVInputFormat ff_g722_demuxer = { +- "g722", +- NULL_IF_CONFIG_SMALL("raw G.722"), +- 0, +- NULL, +- ff_raw_read_header, +- ff_raw_read_partial_packet, ++ .name = "g722", ++ .long_name = NULL_IF_CONFIG_SMALL("raw G.722"), ++ .read_header = ff_raw_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "g722,722", + .value = CODEC_ID_ADPCM_G722, + }; + #endif + +-#if CONFIG_GSM_DEMUXER +-AVInputFormat ff_gsm_demuxer = { +- "gsm", +- NULL_IF_CONFIG_SMALL("raw GSM"), +- 0, +- NULL, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++#if CONFIG_LATM_DEMUXER ++AVInputFormat ff_latm_demuxer = { ++ .name = "latm", ++ .long_name = NULL_IF_CONFIG_SMALL("raw LOAS/LATM"), ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, +- .extensions = "gsm", +- .value = CODEC_ID_GSM, ++ .extensions = "latm", ++ .value = CODEC_ID_AAC_LATM, + }; + #endif + + #if CONFIG_MJPEG_DEMUXER +-AVInputFormat ff_mjpeg_demuxer = { +- "mjpeg", +- NULL_IF_CONFIG_SMALL("raw MJPEG video"), +- 0, +- NULL, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, +- .extensions = "mjpg,mjpeg", +- .value = CODEC_ID_MJPEG, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(mjpeg, "raw MJPEG video", NULL, "mjpg,mjpeg,mpo", CODEC_ID_MJPEG) + #endif + + #if CONFIG_MLP_DEMUXER + AVInputFormat ff_mlp_demuxer = { +- "mlp", +- NULL_IF_CONFIG_SMALL("raw MLP"), +- 0, +- NULL, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++ .name = "mlp", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MLP"), ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "mlp", + .value = CODEC_ID_MLP, +@@ -195,12 +224,10 @@ + + #if CONFIG_TRUEHD_DEMUXER + AVInputFormat ff_truehd_demuxer = { +- "truehd", +- NULL_IF_CONFIG_SMALL("raw TrueHD"), +- 0, +- NULL, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, ++ .name = "truehd", ++ .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"), ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "thd", + .value = CODEC_ID_TRUEHD, +@@ -209,27 +236,16 @@ + + #if CONFIG_SHORTEN_DEMUXER + AVInputFormat ff_shorten_demuxer = { +- "shn", +- NULL_IF_CONFIG_SMALL("raw Shorten"), +- 0, +- NULL, +- ff_raw_audio_read_header, +- ff_raw_read_partial_packet, +- .flags= AVFMT_GENERIC_INDEX, ++ .name = "shn", ++ .long_name = NULL_IF_CONFIG_SMALL("raw Shorten"), ++ .read_header = ff_raw_audio_read_header, ++ .read_packet = ff_raw_read_partial_packet, ++ .flags = AVFMT_NOBINSEARCH | AVFMT_NOGENSEARCH | AVFMT_NO_BYTE_SEEK, + .extensions = "shn", + .value = CODEC_ID_SHORTEN, + }; + #endif + + #if CONFIG_VC1_DEMUXER +-AVInputFormat ff_vc1_demuxer = { +- "vc1", +- NULL_IF_CONFIG_SMALL("raw VC-1"), +- 0, +- NULL /* vc1_probe */, +- ff_raw_video_read_header, +- ff_raw_read_partial_packet, +- .extensions = "vc1", +- .value = CODEC_ID_VC1, +-}; ++FF_DEF_RAWVIDEO_DEMUXER(vc1, "raw VC-1", NULL, "vc1", CODEC_ID_VC1) + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawdec.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawdec.h 2012-05-14 14:08:55.127355942 +0200 +@@ -23,6 +23,23 @@ + #define AVFORMAT_RAWDEC_H + + #include "avformat.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ ++typedef struct RawAudioDemuxerContext { ++ AVClass *class; ++ int sample_rate; ++ int channels; ++} RawAudioDemuxerContext; ++ ++typedef struct FFRawVideoDemuxerContext { ++ const AVClass *class; /**< Class for private options. */ ++ char *video_size; /**< String describing video size, set by a private option. */ ++ char *pixel_format; /**< Set by a private option. */ ++ char *framerate; /**< String describing framerate, set by a private option. */ ++} FFRawVideoDemuxerContext; ++ ++extern const AVOption ff_rawvideo_options[]; + + int ff_raw_read_header(AVFormatContext *s, AVFormatParameters *ap); + +@@ -32,4 +49,27 @@ + + int ff_raw_video_read_header(AVFormatContext *s, AVFormatParameters *ap); + ++#define FF_RAWVIDEO_DEMUXER_CLASS(name)\ ++static const AVClass name ## _demuxer_class = {\ ++ .class_name = #name " demuxer",\ ++ .item_name = av_default_item_name,\ ++ .option = ff_rawvideo_options,\ ++ .version = LIBAVUTIL_VERSION_INT,\ ++}; ++ ++#define FF_DEF_RAWVIDEO_DEMUXER(shortname, longname, probe, ext, id)\ ++FF_RAWVIDEO_DEMUXER_CLASS(shortname)\ ++AVInputFormat ff_ ## shortname ## _demuxer = {\ ++ .name = #shortname,\ ++ .long_name = NULL_IF_CONFIG_SMALL(longname),\ ++ .read_probe = probe,\ ++ .read_header = ff_raw_video_read_header,\ ++ .read_packet = ff_raw_read_partial_packet,\ ++ .extensions = ext,\ ++ .flags = AVFMT_GENERIC_INDEX,\ ++ .value = id,\ ++ .priv_data_size = sizeof(FFRawVideoDemuxerContext),\ ++ .priv_class = &shortname ## _demuxer_class,\ ++}; ++ + #endif /* AVFORMAT_RAWDEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawenc.c 2012-05-14 14:08:55.128355962 +0200 +@@ -25,8 +25,8 @@ + + int ff_raw_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- put_buffer(s->pb, pkt->data, pkt->size); +- put_flush_packet(s->pb); ++ avio_write(s->pb, pkt->data, pkt->size); ++ avio_flush(s->pb); + return 0; + } + +@@ -34,195 +34,188 @@ + + #if CONFIG_AC3_MUXER + AVOutputFormat ff_ac3_muxer = { +- "ac3", +- NULL_IF_CONFIG_SMALL("raw AC-3"), +- "audio/x-ac3", +- "ac3", +- 0, +- CODEC_ID_AC3, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "ac3", ++ .long_name = NULL_IF_CONFIG_SMALL("raw AC-3"), ++ .mime_type = "audio/x-ac3", ++ .extensions = "ac3", ++ .audio_codec = CODEC_ID_AC3, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + ++#if CONFIG_ADX_MUXER ++AVOutputFormat ff_adx_muxer = { ++ .name = "adx", ++ .long_name = NULL_IF_CONFIG_SMALL("CRI ADX"), ++ .extensions = "adx", ++ .audio_codec = CODEC_ID_ADPCM_ADX, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, ++ .flags = AVFMT_NOTIMESTAMPS, ++}; ++#endif ++ + #if CONFIG_DIRAC_MUXER + AVOutputFormat ff_dirac_muxer = { +- "dirac", +- NULL_IF_CONFIG_SMALL("raw Dirac"), +- NULL, +- "drc", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_DIRAC, +- NULL, +- ff_raw_write_packet, ++ .name = "dirac", ++ .long_name = NULL_IF_CONFIG_SMALL("raw Dirac"), ++ .extensions = "drc", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_DIRAC, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_DNXHD_MUXER + AVOutputFormat ff_dnxhd_muxer = { +- "dnxhd", +- NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"), +- NULL, +- "dnxhd", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_DNXHD, +- NULL, +- ff_raw_write_packet, ++ .name = "dnxhd", ++ .long_name = NULL_IF_CONFIG_SMALL("raw DNxHD (SMPTE VC-3)"), ++ .extensions = "dnxhd", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_DNXHD, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_DTS_MUXER + AVOutputFormat ff_dts_muxer = { +- "dts", +- NULL_IF_CONFIG_SMALL("raw DTS"), +- "audio/x-dca", +- "dts", +- 0, +- CODEC_ID_DTS, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "dts", ++ .long_name = NULL_IF_CONFIG_SMALL("raw DTS"), ++ .mime_type = "audio/x-dca", ++ .extensions = "dts", ++ .audio_codec = CODEC_ID_DTS, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_EAC3_MUXER + AVOutputFormat ff_eac3_muxer = { +- "eac3", +- NULL_IF_CONFIG_SMALL("raw E-AC-3"), +- "audio/x-eac3", +- "eac3", +- 0, +- CODEC_ID_EAC3, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "eac3", ++ .long_name = NULL_IF_CONFIG_SMALL("raw E-AC-3"), ++ .mime_type = "audio/x-eac3", ++ .extensions = "eac3", ++ .audio_codec = CODEC_ID_EAC3, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_G722_MUXER + AVOutputFormat ff_g722_muxer = { +- "g722", +- NULL_IF_CONFIG_SMALL("raw G.722"), +- "audio/G722", +- "g722", +- 0, +- CODEC_ID_ADPCM_G722, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "g722", ++ .long_name = NULL_IF_CONFIG_SMALL("raw G.722"), ++ .mime_type = "audio/G722", ++ .extensions = "g722", ++ .audio_codec = CODEC_ID_ADPCM_G722, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, ++ .flags= AVFMT_NOTIMESTAMPS, ++}; ++#endif ++ ++#if CONFIG_G723_1_MUXER ++AVOutputFormat ff_g723_1_muxer = { ++ .name = "g723_1", ++ .long_name = NULL_IF_CONFIG_SMALL("raw G.723.1"), ++ .mime_type = "audio/g723", ++ .extensions = "tco,rco", ++ .audio_codec = CODEC_ID_G723_1, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_H261_MUXER + AVOutputFormat ff_h261_muxer = { +- "h261", +- NULL_IF_CONFIG_SMALL("raw H.261"), +- "video/x-h261", +- "h261", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_H261, +- NULL, +- ff_raw_write_packet, ++ .name = "h261", ++ .long_name = NULL_IF_CONFIG_SMALL("raw H.261"), ++ .mime_type = "video/x-h261", ++ .extensions = "h261", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_H261, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_H263_MUXER + AVOutputFormat ff_h263_muxer = { +- "h263", +- NULL_IF_CONFIG_SMALL("raw H.263"), +- "video/x-h263", +- "h263", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_H263, +- NULL, +- ff_raw_write_packet, ++ .name = "h263", ++ .long_name = NULL_IF_CONFIG_SMALL("raw H.263"), ++ .mime_type = "video/x-h263", ++ .extensions = "h263", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_H263, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_H264_MUXER + AVOutputFormat ff_h264_muxer = { +- "h264", +- NULL_IF_CONFIG_SMALL("raw H.264 video format"), +- NULL, +- "h264", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_H264, +- NULL, +- ff_raw_write_packet, ++ .name = "h264", ++ .long_name = NULL_IF_CONFIG_SMALL("raw H.264 video format"), ++ .extensions = "h264", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_H264, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_CAVSVIDEO_MUXER + AVOutputFormat ff_cavsvideo_muxer = { +- "cavsvideo", +- NULL_IF_CONFIG_SMALL("raw Chinese AVS video"), +- NULL, +- "cavs", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_CAVS, +- NULL, +- ff_raw_write_packet, ++ .name = "cavsvideo", ++ .long_name = NULL_IF_CONFIG_SMALL("raw Chinese AVS video"), ++ .extensions = "cavs", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_CAVS, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_M4V_MUXER + AVOutputFormat ff_m4v_muxer = { +- "m4v", +- NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"), +- NULL, +- "m4v", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_MPEG4, +- NULL, +- ff_raw_write_packet, ++ .name = "m4v", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-4 video format"), ++ .extensions = "m4v", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_MJPEG_MUXER + AVOutputFormat ff_mjpeg_muxer = { +- "mjpeg", +- NULL_IF_CONFIG_SMALL("raw MJPEG video"), +- "video/x-mjpeg", +- "mjpg,mjpeg", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_MJPEG, +- NULL, +- ff_raw_write_packet, ++ .name = "mjpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MJPEG video"), ++ .mime_type = "video/x-mjpeg", ++ .extensions = "mjpg,mjpeg", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_MJPEG, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_MLP_MUXER + AVOutputFormat ff_mlp_muxer = { +- "mlp", +- NULL_IF_CONFIG_SMALL("raw MLP"), +- NULL, +- "mlp", +- 0, +- CODEC_ID_MLP, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "mlp", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MLP"), ++ .extensions = "mlp", ++ .audio_codec = CODEC_ID_MLP, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif +@@ -241,60 +234,49 @@ + + #if CONFIG_TRUEHD_MUXER + AVOutputFormat ff_truehd_muxer = { +- "truehd", +- NULL_IF_CONFIG_SMALL("raw TrueHD"), +- NULL, +- "thd", +- 0, +- CODEC_ID_TRUEHD, +- CODEC_ID_NONE, +- NULL, +- ff_raw_write_packet, ++ .name = "truehd", ++ .long_name = NULL_IF_CONFIG_SMALL("raw TrueHD"), ++ .extensions = "thd", ++ .audio_codec = CODEC_ID_TRUEHD, ++ .video_codec = CODEC_ID_NONE, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_MPEG1VIDEO_MUXER + AVOutputFormat ff_mpeg1video_muxer = { +- "mpeg1video", +- NULL_IF_CONFIG_SMALL("raw MPEG-1 video"), +- "video/x-mpeg", +- "mpg,mpeg,m1v", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_MPEG1VIDEO, +- NULL, +- ff_raw_write_packet, ++ .name = "mpeg1video", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-1 video"), ++ .mime_type = "video/x-mpeg", ++ .extensions = "mpg,mpeg,m1v", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_MPEG1VIDEO, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_MPEG2VIDEO_MUXER + AVOutputFormat ff_mpeg2video_muxer = { +- "mpeg2video", +- NULL_IF_CONFIG_SMALL("raw MPEG-2 video"), +- NULL, +- "m2v", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_MPEG2VIDEO, +- NULL, +- ff_raw_write_packet, ++ .name = "mpeg2video", ++ .long_name = NULL_IF_CONFIG_SMALL("raw MPEG-2 video"), ++ .extensions = "m2v", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif + + #if CONFIG_RAWVIDEO_MUXER + AVOutputFormat ff_rawvideo_muxer = { +- "rawvideo", +- NULL_IF_CONFIG_SMALL("raw video format"), +- NULL, +- "yuv,rgb", +- 0, +- CODEC_ID_NONE, +- CODEC_ID_RAWVIDEO, +- NULL, +- ff_raw_write_packet, ++ .name = "rawvideo", ++ .long_name = NULL_IF_CONFIG_SMALL("raw video format"), ++ .extensions = "yuv,rgb", ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_packet = ff_raw_write_packet, + .flags= AVFMT_NOTIMESTAMPS, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawvideodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawvideodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rawvideodec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rawvideodec.c 2012-05-14 14:08:55.129355982 +0200 +@@ -44,14 +44,30 @@ + return 0; + } + ++#define OFFSET(x) offsetof(FFRawVideoDemuxerContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption rawvideo_options[] = { ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "pixel_format", "", OFFSET(pixel_format), AV_OPT_TYPE_STRING, {.str = "yuv420p"}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass rawvideo_demuxer_class = { ++ .class_name = "rawvideo demuxer", ++ .item_name = av_default_item_name, ++ .option = rawvideo_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_rawvideo_demuxer = { +- "rawvideo", +- NULL_IF_CONFIG_SMALL("raw video format"), +- 0, +- NULL, +- ff_raw_read_header, +- rawvideo_read_packet, ++ .name = "rawvideo", ++ .long_name = NULL_IF_CONFIG_SMALL("raw video format"), ++ .priv_data_size = sizeof(FFRawVideoDemuxerContext), ++ .read_header = ff_raw_read_header, ++ .read_packet = rawvideo_read_packet, + .flags= AVFMT_GENERIC_INDEX, + .extensions = "yuv,cif,qcif,rgb", + .value = CODEC_ID_RAWVIDEO, ++ .priv_class = &rawvideo_demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rdt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rdt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rdt.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rdt.c 2012-05-14 14:08:55.130356002 +0200 +@@ -33,6 +33,7 @@ + #include "libavutil/md5.h" + #include "rm.h" + #include "internal.h" ++#include "avio_internal.h" + #include "libavcodec/get_bits.h" + + struct RDTDemuxContext { +@@ -63,7 +64,7 @@ + do { + s->n_streams++; + } while (first_stream_of_set_idx + s->n_streams < ic->nb_streams && +- s->streams[s->n_streams]->priv_data == s->streams[0]->priv_data); ++ s->streams[s->n_streams]->id == s->streams[0]->id); + s->prev_set_id = -1; + s->prev_stream_id = -1; + s->prev_timestamp = -1; +@@ -76,11 +77,6 @@ + void + ff_rdt_parse_close(RDTDemuxContext *s) + { +- int i; +- +- for (i = 1; i < s->n_streams; i++) +- s->streams[i]->priv_data = NULL; +- + av_free(s); + } + +@@ -135,7 +131,7 @@ + static int + rdt_load_mdpr (PayloadContext *rdt, AVStream *st, int rule_nr) + { +- ByteIOContext pb; ++ AVIOContext pb; + int size; + uint32_t tag; + +@@ -155,30 +151,30 @@ + */ + if (!rdt->mlti_data) + return -1; +- init_put_byte(&pb, rdt->mlti_data, rdt->mlti_data_size, 0, ++ ffio_init_context(&pb, rdt->mlti_data, rdt->mlti_data_size, 0, + NULL, NULL, NULL, NULL); +- tag = get_le32(&pb); ++ tag = avio_rl32(&pb); + if (tag == MKTAG('M', 'L', 'T', 'I')) { + int num, chunk_nr; + + /* read index of MDPR chunk numbers */ +- num = get_be16(&pb); ++ num = avio_rb16(&pb); + if (rule_nr < 0 || rule_nr >= num) + return -1; +- url_fskip(&pb, rule_nr * 2); +- chunk_nr = get_be16(&pb); +- url_fskip(&pb, (num - 1 - rule_nr) * 2); ++ avio_skip(&pb, rule_nr * 2); ++ chunk_nr = avio_rb16(&pb); ++ avio_skip(&pb, (num - 1 - rule_nr) * 2); + + /* read MDPR chunks */ +- num = get_be16(&pb); ++ num = avio_rb16(&pb); + if (chunk_nr >= num) + return -1; + while (chunk_nr--) +- url_fskip(&pb, get_be32(&pb)); +- size = get_be32(&pb); ++ avio_skip(&pb, avio_rb32(&pb)); ++ size = avio_rb32(&pb); + } else { + size = rdt->mlti_data_size; +- url_fseek(&pb, 0, SEEK_SET); ++ avio_seek(&pb, 0, SEEK_SET); + } + if (ff_rm_read_mdpr_codecdata(rdt->rmctx, &pb, st, rdt->rmst[st->index], size) < 0) + return -1; +@@ -300,22 +296,22 @@ + const uint8_t *buf, int len, int flags) + { + int seq = 1, res; +- ByteIOContext pb; ++ AVIOContext pb; + + if (rdt->audio_pkt_cnt == 0) { + int pos; + +- init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL); ++ ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL); + flags = (flags & RTP_FLAG_KEY) ? 2 : 0; + res = ff_rm_parse_packet (rdt->rmctx, &pb, st, rdt->rmst[st->index], len, pkt, + &seq, flags, *timestamp); +- pos = url_ftell(&pb); ++ pos = avio_tell(&pb); + if (res < 0) + return res; + if (res > 0) { + if (st->codec->codec_id == CODEC_ID_AAC) { + memcpy (rdt->buffer, buf + pos, len - pos); +- rdt->rmctx->pb = av_alloc_put_byte (rdt->buffer, len - pos, 0, ++ rdt->rmctx->pb = avio_alloc_context (rdt->buffer, len - pos, 0, + NULL, NULL, NULL, NULL); + } + goto get_cache; +@@ -422,7 +418,7 @@ + int n, first = -1; + + for (n = 0; n < s->nb_streams; n++) +- if (s->streams[n]->priv_data == stream->priv_data) { ++ if (s->streams[n]->id == stream->id) { + int count = s->streams[n]->index + 1; + if (first == -1) first = n; + if (rdt->nb_rmst < count) { +@@ -463,10 +459,10 @@ + { + AVStream *st; + +- if (!(st = av_new_stream(s, 0))) ++ if (!(st = avformat_new_stream(s, NULL))) + return NULL; ++ st->id = orig_st->id; + st->codec->codec_type = orig_st->codec->codec_type; +- st->priv_data = orig_st->priv_data; + st->first_dts = orig_st->first_dts; + + return st; +@@ -488,7 +484,7 @@ + * is set and once for if it isn't. We only read the first because we + * don't care much (that's what the "odd" variable is for). + * Each rule contains a set of one or more statements, optionally +- * preceeded by a single condition. If there's a condition, the rule ++ * preceded by a single condition. If there's a condition, the rule + * starts with a '#'. Multiple conditions are merged between brackets, + * so there are never multiple conditions spread out over separate + * statements. Generally, these conditions are bitrate limits (min/max) +@@ -528,7 +524,11 @@ + { + PayloadContext *rdt = av_mallocz(sizeof(PayloadContext)); + +- av_open_input_stream(&rdt->rmctx, NULL, "", &ff_rdt_demuxer, NULL); ++ int ret = avformat_open_input(&rdt->rmctx, "", &ff_rdt_demuxer, NULL); ++ if (ret < 0) { ++ av_free(rdt); ++ return NULL; ++ } + + return rdt; + } +@@ -544,7 +544,7 @@ + av_freep(&rdt->rmst[i]); + } + if (rdt->rmctx) +- av_close_input_stream(rdt->rmctx); ++ avformat_close_input(&rdt->rmctx); + av_freep(&rdt->mlti_data); + av_freep(&rdt->rmst); + av_free(rdt); +@@ -556,10 +556,10 @@ + .codec_type = t, \ + .codec_id = CODEC_ID_NONE, \ + .parse_sdp_a_line = rdt_parse_sdp_line, \ +- .open = rdt_new_context, \ +- .close = rdt_free_context, \ ++ .alloc = rdt_new_context, \ ++ .free = rdt_free_context, \ + .parse_packet = rdt_parse_packet \ +-}; ++} + + RDT_HANDLER(live_video, "x-pn-multirate-realvideo-live", AVMEDIA_TYPE_VIDEO); + RDT_HANDLER(live_audio, "x-pn-multirate-realaudio-live", AVMEDIA_TYPE_AUDIO); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rdt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rdt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rdt.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rdt.h 2012-05-14 14:08:55.131356022 +0200 +@@ -80,16 +80,16 @@ + * + * @param buf input buffer + * @param len length of input buffer +- * @param set_id will be set to the set ID this packet belongs to +- * @param seq_no will be set to the sequence number of the packet +- * @param stream_id will be set to the stream ID this packet belongs to +- * @param is_keyframe will be whether this packet belongs to a keyframe +- * @param timestamp will be set to the timestamp of the packet ++ * @param pset_id will be set to the set ID this packet belongs to ++ * @param pseq_no will be set to the sequence number of the packet ++ * @param pstream_id will be set to the stream ID this packet belongs to ++ * @param pis_keyframe will be whether this packet belongs to a keyframe ++ * @param ptimestamp will be set to the timestamp of the packet + * @return the amount of bytes consumed, or negative on error + */ + int ff_rdt_parse_header(const uint8_t *buf, int len, +- int *set_id, int *seq_no, int *stream_id, +- int *is_keyframe, uint32_t *timestamp); ++ int *pset_id, int *pseq_no, int *pstream_id, ++ int *pis_keyframe, uint32_t *ptimestamp); + + /** + * Parse RDT-style packet data (header + media data). +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/riff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/riff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/riff.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/riff.c 2012-05-14 14:08:55.133356062 +0200 +@@ -19,8 +19,10 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/mathematics.h" + #include "libavcodec/avcodec.h" + #include "avformat.h" ++#include "avio_internal.h" + #include "riff.h" + #include "libavcodec/bytestream.h" + +@@ -32,13 +34,16 @@ + { CODEC_ID_H264, MKTAG('X', '2', '6', '4') }, + { CODEC_ID_H264, MKTAG('x', '2', '6', '4') }, + { CODEC_ID_H264, MKTAG('a', 'v', 'c', '1') }, ++ { CODEC_ID_H264, MKTAG('D', 'A', 'V', 'C') }, + { CODEC_ID_H264, MKTAG('V', 'S', 'S', 'H') }, ++ { CODEC_ID_H264, MKTAG('Q', '2', '6', '4') }, /* QNAP surveillance system */ + { CODEC_ID_H263, MKTAG('H', '2', '6', '3') }, + { CODEC_ID_H263, MKTAG('X', '2', '6', '3') }, + { CODEC_ID_H263, MKTAG('T', '2', '6', '3') }, + { CODEC_ID_H263, MKTAG('L', '2', '6', '3') }, + { CODEC_ID_H263, MKTAG('V', 'X', '1', 'K') }, + { CODEC_ID_H263, MKTAG('Z', 'y', 'G', 'o') }, ++ { CODEC_ID_H263, MKTAG('M', '2', '6', '3') }, + { CODEC_ID_H263P, MKTAG('H', '2', '6', '3') }, + { CODEC_ID_H263I, MKTAG('I', '2', '6', '3') }, /* intel h263 */ + { CODEC_ID_H261, MKTAG('H', '2', '6', '1') }, +@@ -82,6 +87,9 @@ + { CODEC_ID_MPEG4, MKTAG('U', 'L', 'D', 'X') }, + { CODEC_ID_MPEG4, MKTAG('G', 'E', 'O', 'V') }, + { CODEC_ID_MPEG4, MKTAG('S', 'I', 'P', 'P') }, /* Samsung SHR-6040 */ ++ { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'X') }, ++ { CODEC_ID_MPEG4, MKTAG('D', 'r', 'e', 'X') }, ++ { CODEC_ID_MPEG4, MKTAG('Q', 'M', 'P', '4') }, /* QNAP Systems */ + { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', '4', '3') }, + { CODEC_ID_MSMPEG4V3, MKTAG('D', 'I', 'V', '3') }, + { CODEC_ID_MSMPEG4V3, MKTAG('M', 'P', 'G', '3') }, +@@ -106,6 +114,7 @@ + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', '5', '0') }, + { CODEC_ID_DVVIDEO, MKTAG('c', 'd', 'v', 'c') }, /* Canopus DV */ + { CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', 'H') }, /* Canopus DV */ ++ { CODEC_ID_DVVIDEO, MKTAG('C', 'D', 'V', '5') }, /* Canopus DV */ + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 's') }, + { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'h', '1') }, +@@ -125,6 +134,9 @@ + { CODEC_ID_MPEG2VIDEO, MKTAG('s', 'l', 'i', 'f') }, + { CODEC_ID_MPEG2VIDEO, MKTAG('E', 'M', '2', 'V') }, + { CODEC_ID_MPEG2VIDEO, MKTAG('M', '7', '0', '1') }, /* Matrox MPEG2 intra-only */ ++ { CODEC_ID_MPEG2VIDEO, MKTAG('m', 'p', 'g', 'v') }, ++ { CODEC_ID_MPEG1VIDEO, MKTAG('B', 'W', '1', '0') }, ++ { CODEC_ID_MPEG1VIDEO, MKTAG('X', 'M', 'P', 'G') }, /* Xing MPEG intra only */ + { CODEC_ID_MJPEG, MKTAG('M', 'J', 'P', 'G') }, + { CODEC_ID_MJPEG, MKTAG('L', 'J', 'P', 'G') }, + { CODEC_ID_MJPEG, MKTAG('d', 'm', 'b', '1') }, +@@ -147,6 +159,7 @@ + { CODEC_ID_MJPEG, MKTAG('A', 'V', 'I', '2') }, + { CODEC_ID_MJPEG, MKTAG('M', 'T', 'S', 'J') }, + { CODEC_ID_MJPEG, MKTAG('Z', 'J', 'P', 'G') }, /* Paradigm Matrix M-JPEG Codec */ ++ { CODEC_ID_MJPEG, MKTAG('M', 'M', 'J', 'P') }, + { CODEC_ID_HUFFYUV, MKTAG('H', 'F', 'Y', 'U') }, + { CODEC_ID_FFVHUFF, MKTAG('F', 'F', 'V', 'H') }, + { CODEC_ID_CYUV, MKTAG('C', 'Y', 'U', 'V') }, +@@ -163,12 +176,16 @@ + { CODEC_ID_RAWVIDEO, MKTAG('2', 'V', 'u', '1') }, + { CODEC_ID_RAWVIDEO, MKTAG('2', 'v', 'u', 'y') }, + { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', 's') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('y', 'u', 'v', '2') }, + { CODEC_ID_RAWVIDEO, MKTAG('P', '4', '2', '2') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '2') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '1', '6') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', '2', '4') }, + { CODEC_ID_RAWVIDEO, MKTAG('U', 'Y', 'V', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('V', 'Y', 'U', 'Y') }, + { CODEC_ID_RAWVIDEO, MKTAG('I', 'Y', 'U', 'V') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', '0', '0') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('Y', '8', ' ', ' ') }, + { CODEC_ID_RAWVIDEO, MKTAG('H', 'D', 'Y', 'C') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') }, + { CODEC_ID_RAWVIDEO, MKTAG('V', 'D', 'T', 'Z') }, /* SoftLab-NSK VideoTizer */ +@@ -179,10 +196,14 @@ + { CODEC_ID_RAWVIDEO, MKTAG('Y', '4', '2', 'B') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'U', 'V', '9') }, + { CODEC_ID_RAWVIDEO, MKTAG('Y', 'V', 'U', '9') }, ++ { CODEC_ID_RAWVIDEO, MKTAG('a', 'u', 'v', '2') }, + { CODEC_ID_FRWU, MKTAG('F', 'R', 'W', 'U') }, + { CODEC_ID_R10K, MKTAG('R', '1', '0', 'k') }, + { CODEC_ID_R210, MKTAG('r', '2', '1', '0') }, + { CODEC_ID_V210, MKTAG('v', '2', '1', '0') }, ++ { CODEC_ID_V308, MKTAG('v', '3', '0', '8') }, ++ { CODEC_ID_V410, MKTAG('v', '4', '1', '0') }, ++ { CODEC_ID_YUV4, MKTAG('y', 'u', 'v', '4') }, + { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '1') }, + { CODEC_ID_INDEO3, MKTAG('I', 'V', '3', '2') }, + { CODEC_ID_INDEO4, MKTAG('I', 'V', '4', '1') }, +@@ -219,6 +240,7 @@ + { CODEC_ID_SNOW, MKTAG('S', 'N', 'O', 'W') }, + { CODEC_ID_4XM, MKTAG('4', 'X', 'M', 'V') }, + { CODEC_ID_FLV1, MKTAG('F', 'L', 'V', '1') }, ++ { CODEC_ID_FLV1, MKTAG('S', '2', '6', '3') }, + { CODEC_ID_FLASHSV, MKTAG('F', 'S', 'V', '1') }, + { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, + { CODEC_ID_TSCC, MKTAG('t', 's', 'c', 'c') }, +@@ -228,9 +250,10 @@ + { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '0') }, + { CODEC_ID_QPEG, MKTAG('Q', '1', '.', '1') }, + { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', '3') }, +- { CODEC_ID_WMV3, MKTAG('W', 'M', 'V', 'P') }, ++ { CODEC_ID_WMV3IMAGE, MKTAG('W', 'M', 'V', 'P') }, + { CODEC_ID_VC1, MKTAG('W', 'V', 'C', '1') }, + { CODEC_ID_VC1, MKTAG('W', 'M', 'V', 'A') }, ++ { CODEC_ID_VC1IMAGE, MKTAG('W', 'V', 'P', '2') }, + { CODEC_ID_LOCO, MKTAG('L', 'O', 'C', 'O') }, + { CODEC_ID_WNV1, MKTAG('W', 'N', 'V', '1') }, + { CODEC_ID_AASC, MKTAG('A', 'A', 'S', 'C') }, +@@ -242,12 +265,15 @@ + { CODEC_ID_ZMBV, MKTAG('Z', 'M', 'B', 'V') }, + { CODEC_ID_KMVC, MKTAG('K', 'M', 'V', 'C') }, + { CODEC_ID_CAVS, MKTAG('C', 'A', 'V', 'S') }, ++ { CODEC_ID_JPEG2000, MKTAG('m', 'j', 'p', '2') }, + { CODEC_ID_JPEG2000, MKTAG('M', 'J', '2', 'C') }, ++ { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'C') }, ++ { CODEC_ID_JPEG2000, MKTAG('L', 'J', '2', 'K') }, + { CODEC_ID_VMNC, MKTAG('V', 'M', 'n', 'c') }, + { CODEC_ID_TARGA, MKTAG('t', 'g', 'a', ' ') }, + { CODEC_ID_PNG, MKTAG('M', 'P', 'N', 'G') }, + { CODEC_ID_PNG, MKTAG('P', 'N', 'G', '1') }, +- { CODEC_ID_CLJR, MKTAG('c', 'l', 'j', 'r') }, ++ { CODEC_ID_CLJR, MKTAG('C', 'L', 'J', 'R') }, + { CODEC_ID_DIRAC, MKTAG('d', 'r', 'a', 'c') }, + { CODEC_ID_RPZA, MKTAG('a', 'z', 'p', 'r') }, + { CODEC_ID_RPZA, MKTAG('R', 'P', 'Z', 'A') }, +@@ -258,6 +284,18 @@ + { CODEC_ID_DPX, MKTAG('d', 'p', 'x', ' ') }, + { CODEC_ID_KGV1, MKTAG('K', 'G', 'V', '1') }, + { CODEC_ID_LAGARITH, MKTAG('L', 'A', 'G', 'S') }, ++ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '2') }, ++ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '3') }, ++ { CODEC_ID_G2M, MKTAG('G', '2', 'M', '4') }, ++ { CODEC_ID_AMV, MKTAG('A', 'M', 'V', 'F') }, ++ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'A') }, ++ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'R', 'G') }, ++ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '0') }, ++ { CODEC_ID_UTVIDEO, MKTAG('U', 'L', 'Y', '2') }, ++ { CODEC_ID_VBLE, MKTAG('V', 'B', 'L', 'E') }, ++ { CODEC_ID_ESCAPE130, MKTAG('E', '1', '3', '0') }, ++ { CODEC_ID_DXTORY, MKTAG('x', 't', 'o', 'r') }, ++ { CODEC_ID_Y41P, MKTAG('Y', '4', '1', 'P') }, + { CODEC_ID_NONE, 0 } + }; + +@@ -277,6 +315,7 @@ + { CODEC_ID_ADPCM_YAMAHA, 0x0020 }, + { CODEC_ID_TRUESPEECH, 0x0022 }, + { CODEC_ID_GSM_MS, 0x0031 }, ++ { CODEC_ID_AMR_NB, 0x0038 }, /* rogue format number */ + { CODEC_ID_ADPCM_G726, 0x0045 }, + { CODEC_ID_MP2, 0x0050 }, + { CODEC_ID_MP3, 0x0055 }, +@@ -298,6 +337,7 @@ + { CODEC_ID_IMC, 0x0401 }, + { CODEC_ID_GSM_MS, 0x1500 }, + { CODEC_ID_TRUESPEECH, 0x1501 }, ++ { CODEC_ID_AAC, 0x1600 }, /* ADTS AAC */ + { CODEC_ID_AAC_LATM, 0x1602 }, + { CODEC_ID_AC3, 0x2000 }, + { CODEC_ID_DTS, 0x2001 }, +@@ -306,6 +346,7 @@ + { CODEC_ID_PCM_MULAW, 0x6c75 }, + { CODEC_ID_AAC, 0x706d }, + { CODEC_ID_AAC, 0x4143 }, ++ { CODEC_ID_SPEEX, 0xA109 }, + { CODEC_ID_FLAC, 0xF1AC }, + { CODEC_ID_ADPCM_SWF, ('S'<<8)+'F' }, + { CODEC_ID_VORBIS, ('V'<<8)+'o' }, //HACK/FIXME, does vorbis in WAV/AVI have an (in)official id? +@@ -318,27 +359,57 @@ + { CODEC_ID_NONE, 0 }, + }; + ++const AVCodecGuid ff_codec_wav_guids[] = { ++ {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, ++ {CODEC_ID_ATRAC3P, {0xBF,0xAA,0x23,0xE9,0x58,0xCB,0x71,0x44,0xA1,0x19,0xFF,0xFA,0x01,0xE4,0xCE,0x62}}, ++ {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}}, ++ {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, ++ {CODEC_ID_NONE} ++}; ++ ++const AVMetadataConv ff_riff_info_conv[] = { ++ { "IART", "artist" }, ++ { "ICMT", "comment" }, ++ { "ICOP", "copyright" }, ++ { "ICRD", "date" }, ++ { "IGNR", "genre" }, ++ { "ILNG", "language" }, ++ { "INAM", "title" }, ++ { "IPRD", "album" }, ++ { "IPRT", "track" }, ++ { "ISFT", "encoder" }, ++ { "ITCH", "encoded_by"}, ++ { 0 }, ++}; ++ ++const char ff_riff_tags[][5] = { ++ "IARL", "IART", "ICMS", "ICMT", "ICOP", "ICRD", "ICRP", "IDIM", "IDPI", ++ "IENG", "IGNR", "IKEY", "ILGT", "ILNG", "IMED", "INAM", "IPLT", "IPRD", ++ "IPRT", "ISBJ", "ISFT", "ISHP", "ISRC", "ISRF", "ITCH", ++ {0} ++}; ++ + #if CONFIG_MUXERS +-int64_t ff_start_tag(ByteIOContext *pb, const char *tag) ++int64_t ff_start_tag(AVIOContext *pb, const char *tag) + { +- put_tag(pb, tag); +- put_le32(pb, 0); +- return url_ftell(pb); ++ ffio_wfourcc(pb, tag); ++ avio_wl32(pb, 0); ++ return avio_tell(pb); + } + +-void ff_end_tag(ByteIOContext *pb, int64_t start) ++void ff_end_tag(AVIOContext *pb, int64_t start) + { + int64_t pos; + +- pos = url_ftell(pb); +- url_fseek(pb, start - 4, SEEK_SET); +- put_le32(pb, (uint32_t)(pos - start)); +- url_fseek(pb, pos, SEEK_SET); ++ pos = avio_tell(pb); ++ avio_seek(pb, start - 4, SEEK_SET); ++ avio_wl32(pb, (uint32_t)(pos - start)); ++ avio_seek(pb, pos, SEEK_SET); + } + + /* WAVEFORMATEX header */ + /* returns the size or -1 on error */ +-int ff_put_wav_header(ByteIOContext *pb, AVCodecContext *enc) ++int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc) + { + int bps, blkalign, bytespersec; + int hdrsize = 18; +@@ -354,19 +425,21 @@ + || av_get_bits_per_sample(enc->codec_id) > 16; + + if (waveformatextensible) { +- put_le16(pb, 0xfffe); ++ avio_wl16(pb, 0xfffe); + } else { +- put_le16(pb, enc->codec_tag); ++ avio_wl16(pb, enc->codec_tag); + } +- put_le16(pb, enc->channels); +- put_le32(pb, enc->sample_rate); ++ avio_wl16(pb, enc->channels); ++ avio_wl32(pb, enc->sample_rate); + if (enc->codec_id == CODEC_ID_MP2 || enc->codec_id == CODEC_ID_MP3 || enc->codec_id == CODEC_ID_GSM_MS) { + bps = 0; +- } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { +- bps = 4; + } else { +- if (!(bps = av_get_bits_per_sample(enc->codec_id))) +- bps = 16; // default to 16 ++ if (!(bps = av_get_bits_per_sample(enc->codec_id))) { ++ if (enc->bits_per_coded_sample) ++ bps = enc->bits_per_coded_sample; ++ else ++ bps = 16; // default to 16 ++ } + } + if(bps != enc->bits_per_coded_sample && enc->bits_per_coded_sample){ + av_log(enc, AV_LOG_WARNING, "requested bits_per_coded_sample (%d) and actually stored (%d) differ\n", enc->bits_per_coded_sample, bps); +@@ -377,12 +450,10 @@ + //blkalign = 144 * enc->bit_rate/enc->sample_rate; + } else if (enc->codec_id == CODEC_ID_AC3) { + blkalign = 3840; //maximum bytes per frame +- } else if (enc->codec_id == CODEC_ID_ADPCM_G726) { // +- blkalign = 1; + } else if (enc->block_align != 0) { /* specified by the codec */ + blkalign = enc->block_align; + } else +- blkalign = enc->channels*bps >> 3; ++ blkalign = bps * enc->channels / av_gcd(8, bps); + if (enc->codec_id == CODEC_ID_PCM_U8 || + enc->codec_id == CODEC_ID_PCM_S24LE || + enc->codec_id == CODEC_ID_PCM_S32LE || +@@ -393,9 +464,9 @@ + } else { + bytespersec = enc->bit_rate / 8; + } +- put_le32(pb, bytespersec); /* bytes per second */ +- put_le16(pb, blkalign); /* block align */ +- put_le16(pb, bps); /* bits per sample */ ++ avio_wl32(pb, bytespersec); /* bytes per second */ ++ avio_wl16(pb, blkalign); /* block align */ ++ avio_wl16(pb, bps); /* bits per sample */ + if (enc->codec_id == CODEC_ID_MP3) { + hdrsize += 12; + bytestream_put_le16(&riff_extradata, 1); /* wID */ +@@ -420,52 +491,50 @@ + riff_extradata_start= enc->extradata; + riff_extradata= enc->extradata + enc->extradata_size; + hdrsize += enc->extradata_size; +- } else if (!waveformatextensible){ +- hdrsize -= 2; + } + if(waveformatextensible) { /* write WAVEFORMATEXTENSIBLE extensions */ + hdrsize += 22; +- put_le16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */ +- put_le16(pb, enc->bits_per_coded_sample); /* ValidBitsPerSample || SamplesPerBlock || Reserved */ +- put_le32(pb, enc->channel_layout); /* dwChannelMask */ +- put_le32(pb, enc->codec_tag); /* GUID + next 3 */ +- put_le32(pb, 0x00100000); +- put_le32(pb, 0xAA000080); +- put_le32(pb, 0x719B3800); +- } else if(riff_extradata - riff_extradata_start) { +- put_le16(pb, riff_extradata - riff_extradata_start); ++ avio_wl16(pb, riff_extradata - riff_extradata_start + 22); /* 22 is WAVEFORMATEXTENSIBLE size */ ++ avio_wl16(pb, bps); /* ValidBitsPerSample || SamplesPerBlock || Reserved */ ++ avio_wl32(pb, enc->channel_layout); /* dwChannelMask */ ++ avio_wl32(pb, enc->codec_tag); /* GUID + next 3 */ ++ avio_wl32(pb, 0x00100000); ++ avio_wl32(pb, 0xAA000080); ++ avio_wl32(pb, 0x719B3800); ++ } else { ++ avio_wl16(pb, riff_extradata - riff_extradata_start); /* cbSize */ + } +- put_buffer(pb, riff_extradata_start, riff_extradata - riff_extradata_start); ++ avio_write(pb, riff_extradata_start, riff_extradata - riff_extradata_start); + if(hdrsize&1){ + hdrsize++; +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + + return hdrsize; + } + + /* BITMAPINFOHEADER header */ +-void ff_put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf) ++void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf) + { +- put_le32(pb, 40 + enc->extradata_size); /* size */ +- put_le32(pb, enc->width); ++ avio_wl32(pb, 40 + enc->extradata_size); /* size */ ++ avio_wl32(pb, enc->width); + //We always store RGB TopDown +- put_le32(pb, enc->codec_tag ? enc->height : -enc->height); +- put_le16(pb, 1); /* planes */ ++ avio_wl32(pb, enc->codec_tag ? enc->height : -enc->height); ++ avio_wl16(pb, 1); /* planes */ + +- put_le16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); /* depth */ ++ avio_wl16(pb, enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24); /* depth */ + /* compression type */ +- put_le32(pb, enc->codec_tag); +- put_le32(pb, enc->width * enc->height * 3); +- put_le32(pb, 0); +- put_le32(pb, 0); +- put_le32(pb, 0); +- put_le32(pb, 0); ++ avio_wl32(pb, enc->codec_tag); ++ avio_wl32(pb, (enc->width * enc->height * (enc->bits_per_coded_sample ? enc->bits_per_coded_sample : 24)+7) / 8); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); + +- put_buffer(pb, enc->extradata, enc->extradata_size); ++ avio_write(pb, enc->extradata, enc->extradata_size); + + if (!for_asf && enc->extradata_size & 1) +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + #endif //CONFIG_MUXERS + +@@ -477,50 +546,70 @@ + * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself + * an openended structure. + */ +-void ff_get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size) ++int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size) + { + int id; + +- id = get_le16(pb); ++ id = avio_rl16(pb); + codec->codec_type = AVMEDIA_TYPE_AUDIO; +- codec->codec_tag = id; +- codec->channels = get_le16(pb); +- codec->sample_rate = get_le32(pb); +- codec->bit_rate = get_le32(pb) * 8; +- codec->block_align = get_le16(pb); ++ codec->channels = avio_rl16(pb); ++ codec->sample_rate = avio_rl32(pb); ++ codec->bit_rate = avio_rl32(pb) * 8; ++ codec->block_align = avio_rl16(pb); + if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */ + codec->bits_per_coded_sample = 8; + }else +- codec->bits_per_coded_sample = get_le16(pb); ++ codec->bits_per_coded_sample = avio_rl16(pb); ++ if (id == 0xFFFE) { ++ codec->codec_tag = 0; ++ } else { ++ codec->codec_tag = id; ++ codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); ++ } + if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */ +- int cbSize = get_le16(pb); /* cbSize */ ++ int cbSize = avio_rl16(pb); /* cbSize */ + size -= 18; + cbSize = FFMIN(size, cbSize); + if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */ +- codec->bits_per_coded_sample = get_le16(pb); +- codec->channel_layout = get_le32(pb); /* dwChannelMask */ +- id = get_le32(pb); /* 4 first bytes of GUID */ +- url_fskip(pb, 12); /* skip end of GUID */ ++ ff_asf_guid subformat; ++ codec->bits_per_coded_sample = avio_rl16(pb); ++ codec->channel_layout = avio_rl32(pb); /* dwChannelMask */ ++ ff_get_guid(pb, &subformat); ++ if (!memcmp(subformat + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { ++ codec->codec_tag = AV_RL32(subformat); ++ codec->codec_id = ff_wav_codec_get_id(codec->codec_tag, codec->bits_per_coded_sample); ++ } else { ++ codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat); ++ if (!codec->codec_id) ++ av_log(codec, AV_LOG_WARNING, "unknown subformat:"FF_PRI_GUID"\n", FF_ARG_GUID(subformat)); ++ } + cbSize -= 22; + size -= 22; + } + codec->extradata_size = cbSize; + if (cbSize > 0) { ++ av_free(codec->extradata); + codec->extradata = av_mallocz(codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); +- get_buffer(pb, codec->extradata, codec->extradata_size); ++ if (!codec->extradata) ++ return AVERROR(ENOMEM); ++ avio_read(pb, codec->extradata, codec->extradata_size); + size -= cbSize; + } + + /* It is possible for the chunk to contain garbage at the end */ + if (size > 0) +- url_fskip(pb, size); ++ avio_skip(pb, size); + } +- codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample); + if (codec->codec_id == CODEC_ID_AAC_LATM) { + /* channels and sample_rate values are those prior to applying SBR and/or PS */ + codec->channels = 0; + codec->sample_rate = 0; + } ++ /* override bits_per_coded_sample for G.726 */ ++ if (codec->codec_id == CODEC_ID_ADPCM_G726) ++ codec->bits_per_coded_sample = codec->bit_rate / codec->sample_rate; ++ ++ return 0; + } + + +@@ -544,20 +633,20 @@ + return id; + } + +-int ff_get_bmp_header(ByteIOContext *pb, AVStream *st) ++int ff_get_bmp_header(AVIOContext *pb, AVStream *st) + { + int tag1; +- get_le32(pb); /* size */ +- st->codec->width = get_le32(pb); +- st->codec->height = (int32_t)get_le32(pb); +- get_le16(pb); /* planes */ +- st->codec->bits_per_coded_sample= get_le16(pb); /* depth */ +- tag1 = get_le32(pb); +- get_le32(pb); /* ImageSize */ +- get_le32(pb); /* XPelsPerMeter */ +- get_le32(pb); /* YPelsPerMeter */ +- get_le32(pb); /* ClrUsed */ +- get_le32(pb); /* ClrImportant */ ++ avio_rl32(pb); /* size */ ++ st->codec->width = avio_rl32(pb); ++ st->codec->height = (int32_t)avio_rl32(pb); ++ avio_rl16(pb); /* planes */ ++ st->codec->bits_per_coded_sample= avio_rl16(pb); /* depth */ ++ tag1 = avio_rl32(pb); ++ avio_rl32(pb); /* ImageSize */ ++ avio_rl32(pb); /* XPelsPerMeter */ ++ avio_rl32(pb); /* YPelsPerMeter */ ++ avio_rl32(pb); /* ClrUsed */ ++ avio_rl32(pb); /* ClrImportant */ + return tag1; + } + #endif // CONFIG_DEMUXERS +@@ -571,6 +660,7 @@ + *au_scale=stream->frame_size; + *au_rate= stream->sample_rate; + }else if(stream->codec_type == AVMEDIA_TYPE_VIDEO || ++ stream->codec_type == AVMEDIA_TYPE_DATA || + stream->codec_type == AVMEDIA_TYPE_SUBTITLE){ + *au_scale= stream->time_base.num; + *au_rate = stream->time_base.den; +@@ -582,3 +672,65 @@ + *au_scale /= gcd; + *au_rate /= gcd; + } ++ ++void ff_get_guid(AVIOContext *s, ff_asf_guid *g) ++{ ++ assert(sizeof(*g) == 16); ++ if (avio_read(s, *g, sizeof(*g)) < (int)sizeof(*g)) ++ memset(*g, 0, sizeof(*g)); ++} ++ ++enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid) ++{ ++ int i; ++ for (i = 0; guids[i].id != CODEC_ID_NONE; i++) { ++ if (!ff_guidcmp(guids[i].guid, guid)) ++ return guids[i].id; ++ } ++ return CODEC_ID_NONE; ++} ++ ++int ff_read_riff_info(AVFormatContext *s, int64_t size) ++{ ++ int64_t start, end, cur; ++ AVIOContext *pb = s->pb; ++ ++ start = avio_tell(pb); ++ end = start + size; ++ ++ while ((cur = avio_tell(pb)) >= 0 && cur <= end - 8 /* = tag + size */) { ++ uint32_t chunk_code; ++ int64_t chunk_size; ++ char key[5] = {0}; ++ char *value; ++ ++ chunk_code = avio_rl32(pb); ++ chunk_size = avio_rl32(pb); ++ if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) { ++ av_log(s, AV_LOG_ERROR, "too big INFO subchunk\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ chunk_size += (chunk_size & 1); ++ ++ value = av_malloc(chunk_size + 1); ++ if (!value) { ++ av_log(s, AV_LOG_ERROR, "out of memory, unable to read INFO tag\n"); ++ return AVERROR(ENOMEM); ++ } ++ ++ AV_WL32(key, chunk_code); ++ ++ if (avio_read(pb, value, chunk_size) != chunk_size) { ++ av_freep(&value); ++ av_log(s, AV_LOG_ERROR, "premature end of file while reading INFO tag\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ value[chunk_size] = 0; ++ ++ av_dict_set(&s->metadata, key, value, AV_DICT_DONT_STRDUP_VAL); ++ } ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/riff.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/riff.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/riff.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/riff.h 2012-05-14 14:08:55.134356082 +0200 +@@ -31,21 +31,25 @@ + #include "libavcodec/avcodec.h" + #include "avio.h" + #include "internal.h" ++#include "metadata.h" + +-int64_t ff_start_tag(ByteIOContext *pb, const char *tag); +-void ff_end_tag(ByteIOContext *pb, int64_t start); ++extern const AVMetadataConv ff_riff_info_conv[]; ++extern const char ff_riff_tags[][5]; ++ ++int64_t ff_start_tag(AVIOContext *pb, const char *tag); ++void ff_end_tag(AVIOContext *pb, int64_t start); + + /** + * Read BITMAPINFOHEADER structure and set AVStream codec width, height and + * bits_per_encoded_sample fields. Does not read extradata. + * @return codec tag + */ +-int ff_get_bmp_header(ByteIOContext *pb, AVStream *st); ++int ff_get_bmp_header(AVIOContext *pb, AVStream *st); + +-void ff_put_bmp_header(ByteIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf); +-int ff_put_wav_header(ByteIOContext *pb, AVCodecContext *enc); ++void ff_put_bmp_header(AVIOContext *pb, AVCodecContext *enc, const AVCodecTag *tags, int for_asf); ++int ff_put_wav_header(AVIOContext *pb, AVCodecContext *enc); + enum CodecID ff_wav_codec_get_id(unsigned int tag, int bps); +-void ff_get_wav_header(ByteIOContext *pb, AVCodecContext *codec, int size); ++int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size); + + extern const AVCodecTag ff_codec_bmp_tags[]; + extern const AVCodecTag ff_codec_wav_tags[]; +@@ -54,4 +58,32 @@ + enum CodecID ff_codec_get_id(const AVCodecTag *tags, unsigned int tag); + void ff_parse_specific_params(AVCodecContext *stream, int *au_rate, int *au_ssize, int *au_scale); + ++typedef uint8_t ff_asf_guid[16]; ++ ++int ff_read_riff_info(AVFormatContext *s, int64_t size); ++ ++#define FF_PRI_GUID \ ++ "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" ++#define FF_ARG_GUID(g) \ ++ g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7],g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15] ++ ++static av_always_inline int ff_guidcmp(const void *g1, const void *g2) ++{ ++ return memcmp(g1, g2, sizeof(ff_asf_guid)); ++} ++ ++void ff_get_guid(AVIOContext *s, ff_asf_guid *g); ++ ++typedef struct { ++ enum CodecID id; ++ ff_asf_guid guid; ++} AVCodecGuid; ++ ++enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid); ++ ++extern const AVCodecGuid ff_codec_wav_guids[]; ++ ++#define FF_MEDIASUBTYPE_BASE_GUID \ ++ 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71 ++ + #endif /* AVFORMAT_RIFF_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rl2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rl2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rl2.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rl2.c 2012-05-14 14:08:55.135356102 +0200 +@@ -23,8 +23,7 @@ + * RL2 file demuxer + * @file + * @author Sascha Sommer (saschasommer@freenet.de) +- * For more information regarding the RL2 file format, visit: +- * http://wiki.multimedia.cx/index.php?title=RL2 ++ * @see http://wiki.multimedia.cx/index.php?title=RL2 + * + * extradata: + * 2 byte le initial drawing offset within 320x200 viewport +@@ -34,7 +33,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "avformat.h" ++#include "internal.h" + + #define EXTRADATA1_SIZE (6 + 256 * 3) ///< video base, clr, palette + +@@ -74,14 +75,12 @@ + static av_cold int rl2_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + unsigned int frame_count; + unsigned int audio_frame_counter = 0; + unsigned int video_frame_counter = 0; + unsigned int back_size; +- int data_size; +- unsigned short encoding_method; + unsigned short sound_rate; + unsigned short rate; + unsigned short channels; +@@ -95,24 +94,24 @@ + int i; + int ret = 0; + +- url_fskip(pb,4); /* skip FORM tag */ +- back_size = get_le32(pb); /**< get size of the background frame */ +- signature = get_be32(pb); +- data_size = get_be32(pb); +- frame_count = get_le32(pb); ++ avio_skip(pb,4); /* skip FORM tag */ ++ back_size = avio_rl32(pb); /**< get size of the background frame */ ++ signature = avio_rb32(pb); ++ avio_skip(pb, 4); /* data size */ ++ frame_count = avio_rl32(pb); + + /* disallow back_sizes and frame_counts that may lead to overflows later */ + if(back_size > INT_MAX/2 || frame_count > INT_MAX / sizeof(uint32_t)) + return AVERROR_INVALIDDATA; + +- encoding_method = get_le16(pb); +- sound_rate = get_le16(pb); +- rate = get_le16(pb); +- channels = get_le16(pb); +- def_sound_size = get_le16(pb); ++ avio_skip(pb, 2); /* encoding mentod */ ++ sound_rate = avio_rl16(pb); ++ rate = avio_rl16(pb); ++ channels = avio_rl16(pb); ++ def_sound_size = avio_rl16(pb); + + /** setup video stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if(!st) + return AVERROR(ENOMEM); + +@@ -133,16 +132,19 @@ + if(!st->codec->extradata) + return AVERROR(ENOMEM); + +- if(get_buffer(pb,st->codec->extradata,st->codec->extradata_size) != ++ if(avio_read(pb,st->codec->extradata,st->codec->extradata_size) != + st->codec->extradata_size) + return AVERROR(EIO); + + /** setup audio stream if present */ + if(sound_rate){ ++ if(channels <= 0) ++ return AVERROR_INVALIDDATA; ++ + pts_num = def_sound_size; + pts_den = rate; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -155,10 +157,10 @@ + st->codec->bits_per_coded_sample; + st->codec->block_align = st->codec->channels * + st->codec->bits_per_coded_sample / 8; +- av_set_pts_info(st,32,1,rate); ++ avpriv_set_pts_info(st,32,1,rate); + } + +- av_set_pts_info(s->streams[0], 32, pts_num, pts_den); ++ avpriv_set_pts_info(s->streams[0], 32, pts_num, pts_den); + + chunk_size = av_malloc(frame_count * sizeof(uint32_t)); + audio_size = av_malloc(frame_count * sizeof(uint32_t)); +@@ -173,11 +175,11 @@ + + /** read offset and size tables */ + for(i=0; i < frame_count;i++) +- chunk_size[i] = get_le32(pb); ++ chunk_size[i] = avio_rl32(pb); + for(i=0; i < frame_count;i++) +- chunk_offset[i] = get_le32(pb); ++ chunk_offset[i] = avio_rl32(pb); + for(i=0; i < frame_count;i++) +- audio_size[i] = get_le32(pb) & 0xFFFF; ++ audio_size[i] = avio_rl32(pb) & 0xFFFF; + + /** build the sample index */ + for(i=0;ipriv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVIndexEntry *sample = NULL; + int i; + int ret = 0; +@@ -237,7 +239,7 @@ + ++rl2->index_pos[stream_id]; + + /** position the stream (will probably be there anyway) */ +- url_fseek(pb, sample->pos, SEEK_SET); ++ avio_seek(pb, sample->pos, SEEK_SET); + + /** fill the packet */ + ret = av_get_packet(pb, pkt, sample->size); +@@ -288,13 +290,12 @@ + } + + AVInputFormat ff_rl2_demuxer = { +- "rl2", +- NULL_IF_CONFIG_SMALL("RL2 format"), +- sizeof(Rl2DemuxContext), +- rl2_probe, +- rl2_read_header, +- rl2_read_packet, +- NULL, +- rl2_read_seek, ++ .name = "rl2", ++ .long_name = NULL_IF_CONFIG_SMALL("RL2 format"), ++ .priv_data_size = sizeof(Rl2DemuxContext), ++ .read_probe = rl2_probe, ++ .read_header = rl2_read_header, ++ .read_packet = rl2_read_packet, ++ .read_seek = rl2_read_seek, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rmdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rmdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rmdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rmdec.c 2012-05-14 14:08:55.139356184 +0200 +@@ -21,10 +21,19 @@ + + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + #include "riff.h" + #include "rm.h" + ++#define DEINT_ID_GENR MKTAG('g', 'e', 'n', 'r') ///< interleaving for Cooker/Atrac ++#define DEINT_ID_INT0 MKTAG('I', 'n', 't', '0') ///< no interleaving needed ++#define DEINT_ID_INT4 MKTAG('I', 'n', 't', '4') ///< interleaving for 28.8 ++#define DEINT_ID_SIPR MKTAG('s', 'i', 'p', 'r') ///< interleaving for Sipro ++#define DEINT_ID_VBRF MKTAG('v', 'b', 'r', 'f') ///< VBR case for AAC ++#define DEINT_ID_VBRS MKTAG('v', 'b', 'r', 's') ///< VBR case for AAC ++ + struct RMStream { + AVPacket pkt; ///< place to store merged video frame / reordered audio data + int videobufsize; ///< current assembled frame size +@@ -38,6 +47,7 @@ + int sub_packet_size, sub_packet_h, coded_framesize; ///< Descrambling parameters from container + int audio_framesize; /// Audio frame size from container + int sub_packet_lengths[16]; /// Length of each subpacket ++ int32_t deint_id; ///< deinterleaver used in audio stream + }; + + typedef struct { +@@ -64,33 +74,33 @@ + + const unsigned char ff_sipr_subpk_size[4] = { 29, 19, 37, 20 }; + +-static inline void get_strl(ByteIOContext *pb, char *buf, int buf_size, int len) ++static inline void get_strl(AVIOContext *pb, char *buf, int buf_size, int len) + { + int i; + char *q, r; + + q = buf; + for(i=0;i 0) *q = '\0'; + } + +-static void get_str8(ByteIOContext *pb, char *buf, int buf_size) ++static void get_str8(AVIOContext *pb, char *buf, int buf_size) + { +- get_strl(pb, buf, buf_size, get_byte(pb)); ++ get_strl(pb, buf, buf_size, avio_r8(pb)); + } + +-static int rm_read_extradata(ByteIOContext *pb, AVCodecContext *avctx, unsigned size) ++static int rm_read_extradata(AVIOContext *pb, AVCodecContext *avctx, unsigned size) + { + if (size >= 1<<24) + return -1; + avctx->extradata = av_malloc(size + FF_INPUT_BUFFER_PADDING_SIZE); + if (!avctx->extradata) + return AVERROR(ENOMEM); +- avctx->extradata_size = get_buffer(pb, avctx->extradata, size); ++ avctx->extradata_size = avio_read(pb, avctx->extradata, size); + memset(avctx->extradata + avctx->extradata_size, 0, FF_INPUT_BUFFER_PADDING_SIZE); + if (avctx->extradata_size != size) + return AVERROR(EIO); +@@ -102,9 +112,9 @@ + char buf[1024]; + int i; + for (i=0; ipb) : get_byte(s->pb); ++ int len = wide ? avio_rb16(s->pb) : avio_r8(s->pb); + get_strl(s->pb, buf, sizeof(buf), len); +- av_metadata_set2(&s->metadata, ff_rm_metadata[i], buf, 0); ++ av_dict_set(&s->metadata, ff_rm_metadata[i], buf, 0); + } + } + +@@ -120,7 +130,7 @@ + av_free_packet(&rms->pkt); + } + +-static int rm_read_audio_stream_info(AVFormatContext *s, ByteIOContext *pb, ++static int rm_read_audio_stream_info(AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *ast, int read_all) + { + char buf[256]; +@@ -128,60 +138,63 @@ + int ret; + + /* ra type header */ +- version = get_be16(pb); /* version */ ++ version = avio_rb16(pb); /* version */ + if (version == 3) { +- int header_size = get_be16(pb); +- int64_t startpos = url_ftell(pb); +- url_fskip(pb, 14); ++ int header_size = avio_rb16(pb); ++ int64_t startpos = avio_tell(pb); ++ avio_skip(pb, 14); + rm_read_metadata(s, 0); +- if ((startpos + header_size) >= url_ftell(pb) + 2) { ++ if ((startpos + header_size) >= avio_tell(pb) + 2) { + // fourcc (should always be "lpcJ") +- get_byte(pb); ++ avio_r8(pb); + get_str8(pb, buf, sizeof(buf)); + } + // Skip extra header crap (this should never happen) +- if ((startpos + header_size) > url_ftell(pb)) +- url_fskip(pb, header_size + startpos - url_ftell(pb)); ++ if ((startpos + header_size) > avio_tell(pb)) ++ avio_skip(pb, header_size + startpos - avio_tell(pb)); + st->codec->sample_rate = 8000; + st->codec->channels = 1; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_RA_144; ++ ast->deint_id = DEINT_ID_INT0; + } else { + int flavor, sub_packet_h, coded_framesize, sub_packet_size; + int codecdata_length; + /* old version (4) */ +- url_fskip(pb, 2); /* unused */ +- get_be32(pb); /* .ra4 */ +- get_be32(pb); /* data size */ +- get_be16(pb); /* version2 */ +- get_be32(pb); /* header size */ +- flavor= get_be16(pb); /* add codec info / flavor */ +- ast->coded_framesize = coded_framesize = get_be32(pb); /* coded frame size */ +- get_be32(pb); /* ??? */ +- get_be32(pb); /* ??? */ +- get_be32(pb); /* ??? */ +- ast->sub_packet_h = sub_packet_h = get_be16(pb); /* 1 */ +- st->codec->block_align= get_be16(pb); /* frame size */ +- ast->sub_packet_size = sub_packet_size = get_be16(pb); /* sub packet size */ +- get_be16(pb); /* ??? */ ++ avio_skip(pb, 2); /* unused */ ++ avio_rb32(pb); /* .ra4 */ ++ avio_rb32(pb); /* data size */ ++ avio_rb16(pb); /* version2 */ ++ avio_rb32(pb); /* header size */ ++ flavor= avio_rb16(pb); /* add codec info / flavor */ ++ ast->coded_framesize = coded_framesize = avio_rb32(pb); /* coded frame size */ ++ avio_rb32(pb); /* ??? */ ++ avio_rb32(pb); /* ??? */ ++ avio_rb32(pb); /* ??? */ ++ ast->sub_packet_h = sub_packet_h = avio_rb16(pb); /* 1 */ ++ st->codec->block_align= avio_rb16(pb); /* frame size */ ++ ast->sub_packet_size = sub_packet_size = avio_rb16(pb); /* sub packet size */ ++ avio_rb16(pb); /* ??? */ + if (version == 5) { +- get_be16(pb); get_be16(pb); get_be16(pb); ++ avio_rb16(pb); avio_rb16(pb); avio_rb16(pb); + } +- st->codec->sample_rate = get_be16(pb); +- get_be32(pb); +- st->codec->channels = get_be16(pb); ++ st->codec->sample_rate = avio_rb16(pb); ++ avio_rb32(pb); ++ st->codec->channels = avio_rb16(pb); + if (version == 5) { +- get_be32(pb); +- get_buffer(pb, buf, 4); ++ ast->deint_id = avio_rl32(pb); ++ avio_read(pb, buf, 4); + buf[4] = 0; + } else { + get_str8(pb, buf, sizeof(buf)); /* desc */ ++ ast->deint_id = AV_RL32(buf); + get_str8(pb, buf, sizeof(buf)); /* desc */ + } + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_tag = AV_RL32(buf); + st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags, + st->codec->codec_tag); ++ + switch (st->codec->codec_id) { + case CODEC_ID_AC3: + st->need_parsing = AVSTREAM_PARSE_FULL; +@@ -190,21 +203,14 @@ + st->codec->extradata_size= 0; + ast->audio_framesize = st->codec->block_align; + st->codec->block_align = coded_framesize; +- +- if(ast->audio_framesize >= UINT_MAX / sub_packet_h){ +- av_log(s, AV_LOG_ERROR, "ast->audio_framesize * sub_packet_h too large\n"); +- return -1; +- } +- +- av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h); + break; + case CODEC_ID_COOK: + case CODEC_ID_ATRAC3: + case CODEC_ID_SIPR: +- get_be16(pb); get_byte(pb); ++ avio_rb16(pb); avio_r8(pb); + if (version == 5) +- get_byte(pb); +- codecdata_length = get_be32(pb); ++ avio_r8(pb); ++ codecdata_length = avio_rb32(pb); + if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ + av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); + return -1; +@@ -228,24 +234,18 @@ + if ((ret = rm_read_extradata(pb, st->codec, codecdata_length)) < 0) + return ret; + +- if(ast->audio_framesize >= UINT_MAX / sub_packet_h){ +- av_log(s, AV_LOG_ERROR, "rm->audio_framesize * sub_packet_h too large\n"); +- return -1; +- } +- +- av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h); + break; + case CODEC_ID_AAC: +- get_be16(pb); get_byte(pb); ++ avio_rb16(pb); avio_r8(pb); + if (version == 5) +- get_byte(pb); +- codecdata_length = get_be32(pb); ++ avio_r8(pb); ++ codecdata_length = avio_rb32(pb); + if(codecdata_length + FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)codecdata_length){ + av_log(s, AV_LOG_ERROR, "codecdata_length too large\n"); + return -1; + } + if (codecdata_length >= 1) { +- get_byte(pb); ++ avio_r8(pb); + if ((ret = rm_read_extradata(pb, st->codec, codecdata_length - 1)) < 0) + return ret; + } +@@ -253,10 +253,42 @@ + default: + av_strlcpy(st->codec->codec_name, buf, sizeof(st->codec->codec_name)); + } ++ if (ast->deint_id == DEINT_ID_INT4 || ++ ast->deint_id == DEINT_ID_GENR || ++ ast->deint_id == DEINT_ID_SIPR) { ++ if (st->codec->block_align <= 0 || ++ ast->audio_framesize * sub_packet_h > (unsigned)INT_MAX || ++ ast->audio_framesize * sub_packet_h < st->codec->block_align) ++ return AVERROR_INVALIDDATA; ++ if (av_new_packet(&ast->pkt, ast->audio_framesize * sub_packet_h) < 0) ++ return AVERROR(ENOMEM); ++ } ++ switch (ast->deint_id) { ++ case DEINT_ID_INT4: ++ if (ast->coded_framesize > ast->audio_framesize || ++ sub_packet_h <= 1 || ++ ast->coded_framesize * sub_packet_h > (2 + (sub_packet_h & 1)) * ast->audio_framesize) ++ return AVERROR_INVALIDDATA; ++ break; ++ case DEINT_ID_GENR: ++ if (ast->sub_packet_size <= 0 || ++ ast->sub_packet_size > ast->audio_framesize) ++ return AVERROR_INVALIDDATA; ++ break; ++ case DEINT_ID_SIPR: ++ case DEINT_ID_INT0: ++ case DEINT_ID_VBRS: ++ case DEINT_ID_VBRF: ++ break; ++ default: ++ av_log(NULL,0,"Unknown interleaver %X\n", ast->deint_id); ++ return AVERROR_INVALIDDATA; ++ } ++ + if (read_all) { +- get_byte(pb); +- get_byte(pb); +- get_byte(pb); ++ avio_r8(pb); ++ avio_r8(pb); ++ avio_r8(pb); + rm_read_metadata(s, 0); + } + } +@@ -264,7 +296,7 @@ + } + + int +-ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb, ++ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *rst, int codec_data_size) + { + unsigned int v; +@@ -272,55 +304,46 @@ + int64_t codec_pos; + int ret; + +- av_set_pts_info(st, 64, 1, 1000); +- codec_pos = url_ftell(pb); +- v = get_be32(pb); ++ avpriv_set_pts_info(st, 64, 1, 1000); ++ codec_pos = avio_tell(pb); ++ v = avio_rb32(pb); + if (v == MKTAG(0xfd, 'a', 'r', '.')) { + /* ra type header */ + if (rm_read_audio_stream_info(s, pb, st, rst, 0)) + return -1; + } else { +- int fps, fps2; +- if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { ++ int fps; ++ if (avio_rl32(pb) != MKTAG('V', 'I', 'D', 'O')) { + fail1: +- av_log(st->codec, AV_LOG_ERROR, "Unsupported video codec\n"); ++ av_log(s, AV_LOG_WARNING, "Unsupported stream type %08x\n", v); + goto skip; + } +- st->codec->codec_tag = get_le32(pb); ++ st->codec->codec_tag = avio_rl32(pb); + st->codec->codec_id = ff_codec_get_id(ff_rm_codec_tags, + st->codec->codec_tag); + // av_log(s, AV_LOG_DEBUG, "%X %X\n", st->codec->codec_tag, MKTAG('R', 'V', '2', '0')); + if (st->codec->codec_id == CODEC_ID_NONE) + goto fail1; +- st->codec->width = get_be16(pb); +- st->codec->height = get_be16(pb); +- st->codec->time_base.num= 1 << 16; +- fps= get_be16(pb); ++ st->codec->width = avio_rb16(pb); ++ st->codec->height = avio_rb16(pb); ++ avio_skip(pb, 2); // looks like bits per sample ++ avio_skip(pb, 4); // always zero? + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- get_be32(pb); +- fps2= get_be32(pb); ++ st->need_parsing = AVSTREAM_PARSE_TIMESTAMPS; ++ fps = avio_rb32(pb); + +- if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (url_ftell(pb) - codec_pos))) < 0) ++ if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (avio_tell(pb) - codec_pos))) < 0) + return ret; + +-// av_log(s, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2); +- st->codec->time_base.den = fps2; +- //XXX: do we really need that? +- switch(st->codec->extradata[4]>>4){ +- case 1: st->codec->codec_id = CODEC_ID_RV10; break; +- case 2: st->codec->codec_id = CODEC_ID_RV20; break; +- case 3: st->codec->codec_id = CODEC_ID_RV30; break; +- case 4: st->codec->codec_id = CODEC_ID_RV40; break; +- default: +- av_log(st->codec, AV_LOG_ERROR, "extra:%02X %02X %02X %02X %02X\n", st->codec->extradata[0], st->codec->extradata[1], st->codec->extradata[2], st->codec->extradata[3], st->codec->extradata[4]); +- goto fail1; +- } ++ av_reduce(&st->r_frame_rate.den, &st->r_frame_rate.num, ++ 0x10000, fps, (1 << 30) - 1); ++ st->avg_frame_rate = st->r_frame_rate; + } + + skip: + /* skip codec info */ +- size = url_ftell(pb) - codec_pos; +- url_fskip(pb, codec_data_size - size); ++ size = avio_tell(pb) - codec_pos; ++ avio_skip(pb, codec_data_size - size); + + return 0; + } +@@ -329,53 +352,67 @@ + * of the INDX chunk, and will bail out if not. */ + static int rm_read_index(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int size, n_pkts, str_id, next_off, n, pos, pts; + AVStream *st; + + do { +- if (get_le32(pb) != MKTAG('I','N','D','X')) ++ if (avio_rl32(pb) != MKTAG('I','N','D','X')) + return -1; +- size = get_be32(pb); ++ size = avio_rb32(pb); + if (size < 20) + return -1; +- url_fskip(pb, 2); +- n_pkts = get_be32(pb); +- str_id = get_be16(pb); +- next_off = get_be32(pb); ++ avio_skip(pb, 2); ++ n_pkts = avio_rb32(pb); ++ str_id = avio_rb16(pb); ++ next_off = avio_rb32(pb); + for (n = 0; n < s->nb_streams; n++) + if (s->streams[n]->id == str_id) { + st = s->streams[n]; + break; + } +- if (n == s->nb_streams) ++ if (n == s->nb_streams) { ++ av_log(s, AV_LOG_ERROR, ++ "Invalid stream index %d for index at pos %"PRId64"\n", ++ str_id, avio_tell(pb)); + goto skip; ++ } else if ((avio_size(pb) - avio_tell(pb)) / 14 < n_pkts) { ++ av_log(s, AV_LOG_ERROR, ++ "Nr. of packets in packet index for stream index %d " ++ "exceeds filesize (%"PRId64" at %"PRId64" = %d)\n", ++ str_id, avio_size(pb), avio_tell(pb), ++ (avio_size(pb) - avio_tell(pb)) / 14); ++ goto skip; ++ } + + for (n = 0; n < n_pkts; n++) { +- url_fskip(pb, 2); +- pts = get_be32(pb); +- pos = get_be32(pb); +- url_fskip(pb, 4); /* packet no. */ ++ avio_skip(pb, 2); ++ pts = avio_rb32(pb); ++ pos = avio_rb32(pb); ++ avio_skip(pb, 4); /* packet no. */ + + av_add_index_entry(st, pos, pts, 0, 0, AVINDEX_KEYFRAME); + } + + skip: +- if (next_off && url_ftell(pb) != next_off && +- url_fseek(pb, next_off, SEEK_SET) < 0) ++ if (next_off && avio_tell(pb) < next_off && ++ avio_seek(pb, next_off, SEEK_SET) < 0) { ++ av_log(s, AV_LOG_ERROR, ++ "Non-linear index detected, not supported\n"); + return -1; ++ } + } while (next_off); + + return 0; + } + +-static int rm_read_header_old(AVFormatContext *s, AVFormatParameters *ap) ++static int rm_read_header_old(AVFormatContext *s) + { + RMDemuxContext *rm = s->priv_data; + AVStream *st; + + rm->old_format = 1; +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + st->priv_data = ff_rm_alloc_rmstream(); +@@ -386,7 +423,7 @@ + { + RMDemuxContext *rm = s->priv_data; + AVStream *st; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int tag; + int tag_size; + unsigned int start_time, duration; +@@ -394,66 +431,64 @@ + char buf[128]; + int flags = 0; + +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag == MKTAG('.', 'r', 'a', 0xfd)) { + /* very old .ra format */ +- return rm_read_header_old(s, ap); ++ return rm_read_header_old(s); + } else if (tag != MKTAG('.', 'R', 'M', 'F')) { + return AVERROR(EIO); + } + +- get_be32(pb); /* header size */ +- get_be16(pb); +- get_be32(pb); +- get_be32(pb); /* number of headers */ ++ avio_rb32(pb); /* header size */ ++ avio_rb16(pb); ++ avio_rb32(pb); ++ avio_rb32(pb); /* number of headers */ + + for(;;) { + if (url_feof(pb)) + return -1; +- tag = get_le32(pb); +- tag_size = get_be32(pb); +- get_be16(pb); +-#if 0 +- printf("tag=%c%c%c%c (%08x) size=%d\n", +- (tag) & 0xff, +- (tag >> 8) & 0xff, +- (tag >> 16) & 0xff, +- (tag >> 24) & 0xff, +- tag, +- tag_size); +-#endif ++ tag = avio_rl32(pb); ++ tag_size = avio_rb32(pb); ++ avio_rb16(pb); ++ av_dlog(s, "tag=%c%c%c%c (%08x) size=%d\n", ++ (tag ) & 0xff, ++ (tag >> 8) & 0xff, ++ (tag >> 16) & 0xff, ++ (tag >> 24) & 0xff, ++ tag, ++ tag_size); + if (tag_size < 10 && tag != MKTAG('D', 'A', 'T', 'A')) + return -1; + switch(tag) { + case MKTAG('P', 'R', 'O', 'P'): + /* file header */ +- get_be32(pb); /* max bit rate */ +- get_be32(pb); /* avg bit rate */ +- get_be32(pb); /* max packet size */ +- get_be32(pb); /* avg packet size */ +- get_be32(pb); /* nb packets */ +- get_be32(pb); /* duration */ +- get_be32(pb); /* preroll */ +- indx_off = get_be32(pb); /* index offset */ +- data_off = get_be32(pb); /* data offset */ +- get_be16(pb); /* nb streams */ +- flags = get_be16(pb); /* flags */ ++ avio_rb32(pb); /* max bit rate */ ++ avio_rb32(pb); /* avg bit rate */ ++ avio_rb32(pb); /* max packet size */ ++ avio_rb32(pb); /* avg packet size */ ++ avio_rb32(pb); /* nb packets */ ++ avio_rb32(pb); /* duration */ ++ avio_rb32(pb); /* preroll */ ++ indx_off = avio_rb32(pb); /* index offset */ ++ data_off = avio_rb32(pb); /* data offset */ ++ avio_rb16(pb); /* nb streams */ ++ flags = avio_rb16(pb); /* flags */ + break; + case MKTAG('C', 'O', 'N', 'T'): + rm_read_metadata(s, 1); + break; + case MKTAG('M', 'D', 'P', 'R'): +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- st->id = get_be16(pb); +- get_be32(pb); /* max bit rate */ +- st->codec->bit_rate = get_be32(pb); /* bit rate */ +- get_be32(pb); /* max packet size */ +- get_be32(pb); /* avg packet size */ +- start_time = get_be32(pb); /* start time */ +- get_be32(pb); /* preroll */ +- duration = get_be32(pb); /* duration */ ++ st->id = avio_rb16(pb); ++ avio_rb32(pb); /* max bit rate */ ++ st->codec->bit_rate = avio_rb32(pb); /* bit rate */ ++ avio_rb32(pb); /* max packet size */ ++ avio_rb32(pb); /* avg packet size */ ++ start_time = avio_rb32(pb); /* start time */ ++ avio_rb32(pb); /* preroll */ ++ duration = avio_rb32(pb); /* duration */ + st->start_time = start_time; + st->duration = duration; + get_str8(pb, buf, sizeof(buf)); /* desc */ +@@ -461,45 +496,45 @@ + st->codec->codec_type = AVMEDIA_TYPE_DATA; + st->priv_data = ff_rm_alloc_rmstream(); + if (ff_rm_read_mdpr_codecdata(s, s->pb, st, st->priv_data, +- get_be32(pb)) < 0) ++ avio_rb32(pb)) < 0) + return -1; + break; + case MKTAG('D', 'A', 'T', 'A'): + goto header_end; + default: + /* unknown tag: skip it */ +- url_fskip(pb, tag_size - 10); ++ avio_skip(pb, tag_size - 10); + break; + } + } + header_end: +- rm->nb_packets = get_be32(pb); /* number of packets */ ++ rm->nb_packets = avio_rb32(pb); /* number of packets */ + if (!rm->nb_packets && (flags & 4)) + rm->nb_packets = 3600 * 25; +- get_be32(pb); /* next data header */ ++ avio_rb32(pb); /* next data header */ + + if (!data_off) +- data_off = url_ftell(pb) - 18; +- if (indx_off && !url_is_streamed(pb) && !(s->flags & AVFMT_FLAG_IGNIDX) && +- url_fseek(pb, indx_off, SEEK_SET) >= 0) { ++ data_off = avio_tell(pb) - 18; ++ if (indx_off && pb->seekable && !(s->flags & AVFMT_FLAG_IGNIDX) && ++ avio_seek(pb, indx_off, SEEK_SET) >= 0) { + rm_read_index(s); +- url_fseek(pb, data_off + 18, SEEK_SET); ++ avio_seek(pb, data_off + 18, SEEK_SET); + } + + return 0; + } + +-static int get_num(ByteIOContext *pb, int *len) ++static int get_num(AVIOContext *pb, int *len) + { + int n, n1; + +- n = get_be16(pb); ++ n = avio_rb16(pb); + (*len)-=2; + n &= 0x7FFF; + if (n >= 0x4000) { + return n - 0x4000; + } else { +- n1 = get_be16(pb); ++ n1 = avio_rb16(pb); + (*len)-=2; + return (n << 16) | n1; + } +@@ -510,26 +545,26 @@ + + static int sync(AVFormatContext *s, int64_t *timestamp, int *flags, int *stream_index, int64_t *pos){ + RMDemuxContext *rm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + uint32_t state=0xFFFFFFFF; + + while(!url_feof(pb)){ + int len, num, i; +- *pos= url_ftell(pb) - 3; ++ *pos= avio_tell(pb) - 3; + if(rm->remaining_len > 0){ + num= rm->current_stream; + len= rm->remaining_len; + *timestamp = AV_NOPTS_VALUE; + *flags= 0; + }else{ +- state= (state<<8) + get_byte(pb); ++ state= (state<<8) + avio_r8(pb); + + if(state == MKBETAG('I', 'N', 'D', 'X')){ + int n_pkts, expected_len; +- len = get_be32(pb); +- url_fskip(pb, 2); +- n_pkts = get_be32(pb); ++ len = avio_rb32(pb); ++ avio_skip(pb, 2); ++ n_pkts = avio_rb32(pb); + expected_len = 20 + n_pkts * 14; + if (len == 20) + /* some files don't add index entries to chunk size... */ +@@ -552,10 +587,10 @@ + len=state - 12; + state= 0xFFFFFFFF; + +- num = get_be16(pb); +- *timestamp = get_be32(pb); +- get_byte(pb); /* reserved */ +- *flags = get_byte(pb); /* flags */ ++ num = avio_rb16(pb); ++ *timestamp = avio_rb32(pb); ++ avio_r8(pb); /* reserved */ ++ *flags = avio_r8(pb); /* flags */ + } + for(i=0;inb_streams;i++) { + st = s->streams[i]; +@@ -565,7 +600,7 @@ + if (i == s->nb_streams) { + skip: + /* skip packet if unknown number */ +- url_fskip(pb, len); ++ avio_skip(pb, len); + rm->remaining_len = 0; + continue; + } +@@ -576,30 +611,33 @@ + return -1; + } + +-static int rm_assemble_video_frame(AVFormatContext *s, ByteIOContext *pb, ++static int rm_assemble_video_frame(AVFormatContext *s, AVIOContext *pb, + RMDemuxContext *rm, RMStream *vst, +- AVPacket *pkt, int len, int *pseq) ++ AVPacket *pkt, int len, int *pseq, ++ int64_t *timestamp) + { + int hdr, seq, pic_num, len2, pos; + int type; + +- hdr = get_byte(pb); len--; ++ hdr = avio_r8(pb); len--; + type = hdr >> 6; + + if(type != 3){ // not frame as a part of packet +- seq = get_byte(pb); len--; ++ seq = avio_r8(pb); len--; + } + if(type != 1){ // not whole frame + len2 = get_num(pb, &len); + pos = get_num(pb, &len); +- pic_num = get_byte(pb); len--; ++ pic_num = avio_r8(pb); len--; + } + if(len<0) + return -1; + rm->remaining_len = len; + if(type&1){ // frame, not slice +- if(type == 3) // frame as a part of packet ++ if(type == 3){ // frame as a part of packet + len= len2; ++ *timestamp = pos; ++ } + if(rm->remaining_len < len) + return -1; + rm->remaining_len -= len; +@@ -608,7 +646,7 @@ + pkt->data[0] = 0; + AV_WL32(pkt->data + 1, 1); + AV_WL32(pkt->data + 5, 0); +- get_buffer(pb, pkt->data + 9, len); ++ avio_read(pb, pkt->data + 9, len); + return 0; + } + //now we have to deal with single slice +@@ -623,7 +661,7 @@ + vst->videobufpos = 8*vst->slices + 1; + vst->cur_slice = 0; + vst->curpic_num = pic_num; +- vst->pktpos = url_ftell(pb); ++ vst->pktpos = avio_tell(pb); + } + if(type == 2) + len = FFMIN(len, pos); +@@ -634,12 +672,12 @@ + AV_WL32(vst->pkt.data - 3 + 8*vst->cur_slice, vst->videobufpos - 8*vst->slices - 1); + if(vst->videobufpos + len > vst->videobufsize) + return 1; +- if (get_buffer(pb, vst->pkt.data + vst->videobufpos, len) != len) ++ if (avio_read(pb, vst->pkt.data + vst->videobufpos, len) != len) + return AVERROR(EIO); + vst->videobufpos += len; + rm->remaining_len-= len; + +- if(type == 2 || (vst->videobufpos) == vst->videobufsize){ ++ if (type == 2 || vst->videobufpos == vst->videobufsize) { + vst->pkt.data[0] = vst->cur_slice-1; + *pkt= vst->pkt; + vst->pkt.data= NULL; +@@ -699,7 +737,7 @@ + } + + int +-ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, ++ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *ast, int len, AVPacket *pkt, + int *seq, int flags, int64_t timestamp) + { +@@ -707,13 +745,12 @@ + + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { + rm->current_stream= st->id; +- if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq)) ++ if(rm_assemble_video_frame(s, pb, rm, ast, pkt, len, seq, ×tamp)) + return -1; //got partial frame + } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- if ((st->codec->codec_id == CODEC_ID_RA_288) || +- (st->codec->codec_id == CODEC_ID_COOK) || +- (st->codec->codec_id == CODEC_ID_ATRAC3) || +- (st->codec->codec_id == CODEC_ID_SIPR)) { ++ if ((ast->deint_id == DEINT_ID_GENR) || ++ (ast->deint_id == DEINT_ID_INT4) || ++ (ast->deint_id == DEINT_ID_SIPR)) { + int x; + int sps = ast->sub_packet_size; + int cfs = ast->coded_framesize; +@@ -726,36 +763,36 @@ + if (!y) + ast->audiotimestamp = timestamp; + +- switch(st->codec->codec_id) { +- case CODEC_ID_RA_288: ++ switch (ast->deint_id) { ++ case DEINT_ID_INT4: + for (x = 0; x < h/2; x++) +- get_buffer(pb, ast->pkt.data+x*2*w+y*cfs, cfs); ++ avio_read(pb, ast->pkt.data+x*2*w+y*cfs, cfs); + break; +- case CODEC_ID_ATRAC3: +- case CODEC_ID_COOK: ++ case DEINT_ID_GENR: + for (x = 0; x < w/sps; x++) +- get_buffer(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); ++ avio_read(pb, ast->pkt.data+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), sps); + break; +- case CODEC_ID_SIPR: +- get_buffer(pb, ast->pkt.data + y * w, w); ++ case DEINT_ID_SIPR: ++ avio_read(pb, ast->pkt.data + y * w, w); + break; + } + + if (++(ast->sub_packet_cnt) < h) + return -1; +- if (st->codec->codec_id == CODEC_ID_SIPR) ++ if (ast->deint_id == DEINT_ID_SIPR) + ff_rm_reorder_sipr_data(ast->pkt.data, h, w); + + ast->sub_packet_cnt = 0; + rm->audio_stream_num = st->index; + rm->audio_pkt_cnt = h * w / st->codec->block_align; +- } else if (st->codec->codec_id == CODEC_ID_AAC) { ++ } else if ((ast->deint_id == DEINT_ID_VBRF) || ++ (ast->deint_id == DEINT_ID_VBRS)) { + int x; + rm->audio_stream_num = st->index; +- ast->sub_packet_cnt = (get_be16(pb) & 0xf0) >> 4; ++ ast->sub_packet_cnt = (avio_rb16(pb) & 0xf0) >> 4; + if (ast->sub_packet_cnt) { + for (x = 0; x < ast->sub_packet_cnt; x++) +- ast->sub_packet_lengths[x] = get_be16(pb); ++ ast->sub_packet_lengths[x] = avio_rb16(pb); + rm->audio_pkt_cnt = ast->sub_packet_cnt; + ast->audiotimestamp = timestamp; + } else +@@ -782,7 +819,7 @@ + } + #endif + +- pkt->pts= timestamp; ++ pkt->pts = timestamp; + if (flags & 2) + pkt->flags |= AV_PKT_FLAG_KEY; + +@@ -790,14 +827,15 @@ + } + + int +-ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb, ++ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *ast, AVPacket *pkt) + { + RMDemuxContext *rm = s->priv_data; + + assert (rm->audio_pkt_cnt > 0); + +- if (st->codec->codec_id == CODEC_ID_AAC) ++ if (ast->deint_id == DEINT_ID_VBRF || ++ ast->deint_id == DEINT_ID_VBRS) + av_get_packet(pb, pkt, ast->sub_packet_lengths[ast->sub_packet_cnt - rm->audio_pkt_cnt]); + else { + av_new_packet(pkt, st->codec->block_align); +@@ -840,7 +878,7 @@ + len = !ast->audio_framesize ? RAW_PACKET_SIZE : + ast->coded_framesize * ast->sub_packet_h / 2; + flags = (seq++ == 1) ? 2 : 0; +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + } else { + len=sync(s, ×tamp, &flags, &i, &pos); + if (len > 0) +@@ -903,7 +941,7 @@ + if(rm->old_format) + return AV_NOPTS_VALUE; + +- if (url_fseek(s->pb, pos, SEEK_SET) < 0) ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) + return AV_NOPTS_VALUE; + + rm->remaining_len=0; +@@ -917,9 +955,9 @@ + + st = s->streams[stream_index2]; + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- h= get_byte(s->pb); len--; ++ h= avio_r8(s->pb); len--; + if(!(h & 0x40)){ +- seq = get_byte(s->pb); len--; ++ seq = avio_r8(s->pb); len--; + } + } + +@@ -930,30 +968,27 @@ + break; + } + +- url_fskip(s->pb, len); ++ avio_skip(s->pb, len); + } + *ppos = pos; + return dts; + } + + AVInputFormat ff_rm_demuxer = { +- "rm", +- NULL_IF_CONFIG_SMALL("RealMedia format"), +- sizeof(RMDemuxContext), +- rm_probe, +- rm_read_header, +- rm_read_packet, +- rm_read_close, +- NULL, +- rm_read_dts, ++ .name = "rm", ++ .long_name = NULL_IF_CONFIG_SMALL("RealMedia format"), ++ .priv_data_size = sizeof(RMDemuxContext), ++ .read_probe = rm_probe, ++ .read_header = rm_read_header, ++ .read_packet = rm_read_packet, ++ .read_close = rm_read_close, ++ .read_timestamp = rm_read_dts, + }; + + AVInputFormat ff_rdt_demuxer = { +- "rdt", +- NULL_IF_CONFIG_SMALL("RDT demuxer"), +- sizeof(RMDemuxContext), +- NULL, +- NULL, +- NULL, +- rm_read_close, ++ .name = "rdt", ++ .long_name = NULL_IF_CONFIG_SMALL("RDT demuxer"), ++ .priv_data_size = sizeof(RMDemuxContext), ++ .read_close = rm_read_close, ++ .flags = AVFMT_NOFILE, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rmenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rmenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rmenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rmenc.c 2012-05-14 14:08:55.147356344 +0200 +@@ -19,7 +19,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "avio_internal.h" + #include "rm.h" ++#include "libavutil/dict.h" + + typedef struct { + int nb_packets; +@@ -44,19 +46,19 @@ + #define BUFFER_DURATION 0 + + +-static void put_str(ByteIOContext *s, const char *tag) ++static void put_str(AVIOContext *s, const char *tag) + { +- put_be16(s,strlen(tag)); ++ avio_wb16(s,strlen(tag)); + while (*tag) { +- put_byte(s, *tag++); ++ avio_w8(s, *tag++); + } + } + +-static void put_str8(ByteIOContext *s, const char *tag) ++static void put_str8(AVIOContext *s, const char *tag) + { +- put_byte(s, strlen(tag)); ++ avio_w8(s, strlen(tag)); + while (*tag) { +- put_byte(s, *tag++); ++ avio_w8(s, *tag++); + } + } + +@@ -64,25 +66,25 @@ + int data_size, int index_pos) + { + RMMuxContext *rm = ctx->priv_data; +- ByteIOContext *s = ctx->pb; ++ AVIOContext *s = ctx->pb; + StreamInfo *stream; + unsigned char *data_offset_ptr, *start_ptr; + const char *desc, *mimetype; + int nb_packets, packet_total_size, packet_max_size, size, packet_avg_size, i; + int bit_rate, v, duration, flags, data_pos; +- AVMetadataTag *tag; ++ AVDictionaryEntry *tag; + + start_ptr = s->buf_ptr; + +- put_tag(s, ".RMF"); +- put_be32(s,18); /* header size */ +- put_be16(s,0); +- put_be32(s,0); +- put_be32(s,4 + ctx->nb_streams); /* num headers */ +- +- put_tag(s,"PROP"); +- put_be32(s, 50); +- put_be16(s, 0); ++ ffio_wfourcc(s, ".RMF"); ++ avio_wb32(s,18); /* header size */ ++ avio_wb16(s,0); ++ avio_wb32(s,0); ++ avio_wb32(s,4 + ctx->nb_streams); /* num headers */ ++ ++ ffio_wfourcc(s,"PROP"); ++ avio_wb32(s, 50); ++ avio_wb16(s, 0); + packet_max_size = 0; + packet_total_size = 0; + nb_packets = 0; +@@ -100,39 +102,39 @@ + if (v > duration) + duration = v; + } +- put_be32(s, bit_rate); /* max bit rate */ +- put_be32(s, bit_rate); /* avg bit rate */ +- put_be32(s, packet_max_size); /* max packet size */ ++ avio_wb32(s, bit_rate); /* max bit rate */ ++ avio_wb32(s, bit_rate); /* avg bit rate */ ++ avio_wb32(s, packet_max_size); /* max packet size */ + if (nb_packets > 0) + packet_avg_size = packet_total_size / nb_packets; + else + packet_avg_size = 0; +- put_be32(s, packet_avg_size); /* avg packet size */ +- put_be32(s, nb_packets); /* num packets */ +- put_be32(s, duration); /* duration */ +- put_be32(s, BUFFER_DURATION); /* preroll */ +- put_be32(s, index_pos); /* index offset */ ++ avio_wb32(s, packet_avg_size); /* avg packet size */ ++ avio_wb32(s, nb_packets); /* num packets */ ++ avio_wb32(s, duration); /* duration */ ++ avio_wb32(s, BUFFER_DURATION); /* preroll */ ++ avio_wb32(s, index_pos); /* index offset */ + /* computation of data the data offset */ + data_offset_ptr = s->buf_ptr; +- put_be32(s, 0); /* data offset : will be patched after */ +- put_be16(s, ctx->nb_streams); /* num streams */ ++ avio_wb32(s, 0); /* data offset : will be patched after */ ++ avio_wb16(s, ctx->nb_streams); /* num streams */ + flags = 1 | 2; /* save allowed & perfect play */ +- if (url_is_streamed(s)) ++ if (!s->seekable) + flags |= 4; /* live broadcast */ +- put_be16(s, flags); ++ avio_wb16(s, flags); + + /* comments */ + +- put_tag(s,"CONT"); ++ ffio_wfourcc(s,"CONT"); + size = 4 * 2 + 10; + for(i=0; imetadata, ff_rm_metadata[i], NULL, 0); ++ tag = av_dict_get(ctx->metadata, ff_rm_metadata[i], NULL, 0); + if(tag) size += strlen(tag->value); + } +- put_be32(s,size); +- put_be16(s,0); ++ avio_wb32(s,size); ++ avio_wb16(s,0); + for(i=0; imetadata, ff_rm_metadata[i], NULL, 0); ++ tag = av_dict_get(ctx->metadata, ff_rm_metadata[i], NULL, 0); + put_str(s, tag ? tag->value : ""); + } + +@@ -151,31 +153,31 @@ + codec_data_size = 34; + } + +- put_tag(s,"MDPR"); ++ ffio_wfourcc(s,"MDPR"); + size = 10 + 9 * 4 + strlen(desc) + strlen(mimetype) + codec_data_size; +- put_be32(s, size); +- put_be16(s, 0); ++ avio_wb32(s, size); ++ avio_wb16(s, 0); + +- put_be16(s, i); /* stream number */ +- put_be32(s, stream->bit_rate); /* max bit rate */ +- put_be32(s, stream->bit_rate); /* avg bit rate */ +- put_be32(s, stream->packet_max_size); /* max packet size */ ++ avio_wb16(s, i); /* stream number */ ++ avio_wb32(s, stream->bit_rate); /* max bit rate */ ++ avio_wb32(s, stream->bit_rate); /* avg bit rate */ ++ avio_wb32(s, stream->packet_max_size); /* max packet size */ + if (stream->nb_packets > 0) + packet_avg_size = stream->packet_total_size / + stream->nb_packets; + else + packet_avg_size = 0; +- put_be32(s, packet_avg_size); /* avg packet size */ +- put_be32(s, 0); /* start time */ +- put_be32(s, BUFFER_DURATION); /* preroll */ ++ avio_wb32(s, packet_avg_size); /* avg packet size */ ++ avio_wb32(s, 0); /* start time */ ++ avio_wb32(s, BUFFER_DURATION); /* preroll */ + /* duration */ +- if (url_is_streamed(s) || !stream->total_frames) +- put_be32(s, (int)(3600 * 1000)); ++ if (!s->seekable || !stream->total_frames) ++ avio_wb32(s, (int)(3600 * 1000)); + else +- put_be32(s, (int)(stream->total_frames * 1000 / stream->frame_rate)); ++ avio_wb32(s, (int)(stream->total_frames * 1000 / stream->frame_rate)); + put_str8(s, desc); + put_str8(s, mimetype); +- put_be32(s, codec_data_size); ++ avio_wb32(s, codec_data_size); + + if (stream->enc->codec_type == AVMEDIA_TYPE_AUDIO) { + int coded_frame_size, fscode, sample_rate; +@@ -183,13 +185,13 @@ + coded_frame_size = (stream->enc->bit_rate * + stream->enc->frame_size) / (8 * sample_rate); + /* audio codec info */ +- put_tag(s, ".ra"); +- put_byte(s, 0xfd); +- put_be32(s, 0x00040000); /* version */ +- put_tag(s, ".ra4"); +- put_be32(s, 0x01b53530); /* stream length */ +- put_be16(s, 4); /* unknown */ +- put_be32(s, 0x39); /* header size */ ++ avio_write(s, ".ra", 3); ++ avio_w8(s, 0xfd); ++ avio_wb32(s, 0x00040000); /* version */ ++ ffio_wfourcc(s, ".ra4"); ++ avio_wb32(s, 0x01b53530); /* stream length */ ++ avio_wb16(s, 4); /* unknown */ ++ avio_wb32(s, 0x39); /* header size */ + + switch(sample_rate) { + case 48000: +@@ -208,56 +210,57 @@ + case 8000: + fscode = 3; + } +- put_be16(s, fscode); /* codec additional info, for AC-3, seems ++ avio_wb16(s, fscode); /* codec additional info, for AC-3, seems + to be a frequency code */ + /* special hack to compensate rounding errors... */ + if (coded_frame_size == 557) + coded_frame_size--; +- put_be32(s, coded_frame_size); /* frame length */ +- put_be32(s, 0x51540); /* unknown */ +- put_be32(s, 0x249f0); /* unknown */ +- put_be32(s, 0x249f0); /* unknown */ +- put_be16(s, 0x01); ++ avio_wb32(s, coded_frame_size); /* frame length */ ++ avio_wb32(s, 0x51540); /* unknown */ ++ avio_wb32(s, 0x249f0); /* unknown */ ++ avio_wb32(s, 0x249f0); /* unknown */ ++ avio_wb16(s, 0x01); + /* frame length : seems to be very important */ +- put_be16(s, coded_frame_size); +- put_be32(s, 0); /* unknown */ +- put_be16(s, stream->enc->sample_rate); /* sample rate */ +- put_be32(s, 0x10); /* unknown */ +- put_be16(s, stream->enc->channels); ++ avio_wb16(s, coded_frame_size); ++ avio_wb32(s, 0); /* unknown */ ++ avio_wb16(s, stream->enc->sample_rate); /* sample rate */ ++ avio_wb32(s, 0x10); /* unknown */ ++ avio_wb16(s, stream->enc->channels); + put_str8(s, "Int0"); /* codec name */ + if (stream->enc->codec_tag) { +- put_byte(s, 4); /* tag length */ +- put_le32(s, stream->enc->codec_tag); ++ avio_w8(s, 4); /* tag length */ ++ avio_wl32(s, stream->enc->codec_tag); + } else { + av_log(ctx, AV_LOG_ERROR, "Invalid codec tag\n"); + return -1; + } +- put_be16(s, 0); /* title length */ +- put_be16(s, 0); /* author length */ +- put_be16(s, 0); /* copyright length */ +- put_byte(s, 0); /* end of header */ ++ avio_wb16(s, 0); /* title length */ ++ avio_wb16(s, 0); /* author length */ ++ avio_wb16(s, 0); /* copyright length */ ++ avio_w8(s, 0); /* end of header */ + } else { + /* video codec info */ +- put_be32(s,34); /* size */ ++ avio_wb32(s,34); /* size */ ++ ffio_wfourcc(s, "VIDO"); + if(stream->enc->codec_id == CODEC_ID_RV10) +- put_tag(s,"VIDORV10"); ++ ffio_wfourcc(s,"RV10"); + else +- put_tag(s,"VIDORV20"); +- put_be16(s, stream->enc->width); +- put_be16(s, stream->enc->height); +- put_be16(s, (int) stream->frame_rate); /* frames per seconds ? */ +- put_be32(s,0); /* unknown meaning */ +- put_be16(s, (int) stream->frame_rate); /* unknown meaning */ +- put_be32(s,0); /* unknown meaning */ +- put_be16(s, 8); /* unknown meaning */ ++ ffio_wfourcc(s,"RV20"); ++ avio_wb16(s, stream->enc->width); ++ avio_wb16(s, stream->enc->height); ++ avio_wb16(s, (int) stream->frame_rate); /* frames per seconds ? */ ++ avio_wb32(s,0); /* unknown meaning */ ++ avio_wb16(s, (int) stream->frame_rate); /* unknown meaning */ ++ avio_wb32(s,0); /* unknown meaning */ ++ avio_wb16(s, 8); /* unknown meaning */ + /* Seems to be the codec version: only use basic H263. The next + versions seems to add a diffential DC coding as in + MPEG... nothing new under the sun */ + if(stream->enc->codec_id == CODEC_ID_RV10) +- put_be32(s,0x10000000); ++ avio_wb32(s,0x10000000); + else +- put_be32(s,0x20103001); +- //put_be32(s,0x10003000); ++ avio_wb32(s,0x20103001); ++ //avio_wb32(s,0x10003000); + } + } + +@@ -270,12 +273,12 @@ + data_offset_ptr[3] = data_pos; + + /* data stream */ +- put_tag(s,"DATA"); +- put_be32(s,data_size + 10 + 8); +- put_be16(s,0); ++ ffio_wfourcc(s, "DATA"); ++ avio_wb32(s,data_size + 10 + 8); ++ avio_wb16(s,0); + +- put_be32(s, nb_packets); /* number of packets */ +- put_be32(s,0); /* next data header */ ++ avio_wb32(s, nb_packets); /* number of packets */ ++ avio_wb32(s,0); /* next data header */ + return 0; + } + +@@ -283,20 +286,20 @@ + int length, int key_frame) + { + int timestamp; +- ByteIOContext *s = ctx->pb; ++ AVIOContext *s = ctx->pb; + + stream->nb_packets++; + stream->packet_total_size += length; + if (length > stream->packet_max_size) + stream->packet_max_size = length; + +- put_be16(s,0); /* version */ +- put_be16(s,length + 12); +- put_be16(s, stream->num); /* stream number */ ++ avio_wb16(s,0); /* version */ ++ avio_wb16(s,length + 12); ++ avio_wb16(s, stream->num); /* stream number */ + timestamp = (1000 * (float)stream->nb_frames) / stream->frame_rate; +- put_be32(s, timestamp); /* timestamp */ +- put_byte(s, 0); /* reserved */ +- put_byte(s, key_frame ? 2 : 0); /* flags */ ++ avio_wb32(s, timestamp); /* timestamp */ ++ avio_w8(s, 0); /* reserved */ ++ avio_w8(s, key_frame ? 2 : 0); /* flags */ + } + + static int rm_write_header(AVFormatContext *s) +@@ -339,7 +342,7 @@ + + if (rv10_write_header(s, 0, 0)) + return AVERROR_INVALIDDATA; +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + +@@ -347,12 +350,12 @@ + { + uint8_t *buf1; + RMMuxContext *rm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + StreamInfo *stream = rm->audio_stream; + int i; + + /* XXX: suppress this malloc */ +- buf1= (uint8_t*) av_malloc( size * sizeof(uint8_t) ); ++ buf1 = av_malloc(size * sizeof(uint8_t)); + + write_packet_header(s, stream, size, !!(flags & AV_PKT_FLAG_KEY)); + +@@ -362,11 +365,11 @@ + buf1[i] = buf[i+1]; + buf1[i+1] = buf[i]; + } +- put_buffer(pb, buf1, size); ++ avio_write(pb, buf1, size); + } else { +- put_buffer(pb, buf, size); ++ avio_write(pb, buf, size); + } +- put_flush_packet(pb); ++ avio_flush(pb); + stream->nb_frames++; + av_free(buf1); + return 0; +@@ -375,7 +378,7 @@ + static int rm_write_video(AVFormatContext *s, const uint8_t *buf, int size, int flags) + { + RMMuxContext *rm = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + StreamInfo *stream = rm->video_stream; + int key_frame = !!(flags & AV_PKT_FLAG_KEY); + +@@ -386,32 +389,32 @@ + #if 1 + write_packet_header(s, stream, size + 7 + (size >= 0x4000)*4, key_frame); + /* bit 7: '1' if final packet of a frame converted in several packets */ +- put_byte(pb, 0x81); ++ avio_w8(pb, 0x81); + /* bit 7: '1' if I frame. bits 6..0 : sequence number in current + frame starting from 1 */ + if (key_frame) { +- put_byte(pb, 0x81); ++ avio_w8(pb, 0x81); + } else { +- put_byte(pb, 0x01); ++ avio_w8(pb, 0x01); + } + if(size >= 0x4000){ +- put_be32(pb, size); /* total frame size */ +- put_be32(pb, size); /* offset from the start or the end */ ++ avio_wb32(pb, size); /* total frame size */ ++ avio_wb32(pb, size); /* offset from the start or the end */ + }else{ +- put_be16(pb, 0x4000 | size); /* total frame size */ +- put_be16(pb, 0x4000 | size); /* offset from the start or the end */ ++ avio_wb16(pb, 0x4000 | size); /* total frame size */ ++ avio_wb16(pb, 0x4000 | size); /* offset from the start or the end */ + } + #else + /* full frame */ + write_packet_header(s, size + 6); +- put_byte(pb, 0xc0); +- put_be16(pb, 0x4000 + size); /* total frame size */ +- put_be16(pb, 0x4000 + packet_number * 126); /* position in stream */ ++ avio_w8(pb, 0xc0); ++ avio_wb16(pb, 0x4000 + size); /* total frame size */ ++ avio_wb16(pb, 0x4000 + packet_number * 126); /* position in stream */ + #endif +- put_byte(pb, stream->nb_frames & 0xff); ++ avio_w8(pb, stream->nb_frames & 0xff); + +- put_buffer(pb, buf, size); +- put_flush_packet(pb); ++ avio_write(pb, buf, size); ++ avio_flush(pb); + + stream->nb_frames++; + return 0; +@@ -430,43 +433,43 @@ + { + RMMuxContext *rm = s->priv_data; + int data_size, index_pos, i; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + /* end of file: finish to write header */ +- index_pos = url_fseek(pb, 0, SEEK_CUR); ++ index_pos = avio_tell(pb); + data_size = index_pos - rm->data_pos; + + /* FIXME: write index */ + + /* undocumented end header */ +- put_be32(pb, 0); +- put_be32(pb, 0); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); + +- url_fseek(pb, 0, SEEK_SET); ++ avio_seek(pb, 0, SEEK_SET); + for(i=0;inb_streams;i++) + rm->streams[i].total_frames = rm->streams[i].nb_frames; + rv10_write_header(s, data_size, 0); + } else { + /* undocumented end header */ +- put_be32(pb, 0); +- put_be32(pb, 0); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); + } +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + + + AVOutputFormat ff_rm_muxer = { +- "rm", +- NULL_IF_CONFIG_SMALL("RealMedia format"), +- "application/vnd.rn-realmedia", +- "rm,ra", +- sizeof(RMMuxContext), +- CODEC_ID_AC3, +- CODEC_ID_RV10, +- rm_write_header, +- rm_write_packet, +- rm_write_trailer, ++ .name = "rm", ++ .long_name = NULL_IF_CONFIG_SMALL("RealMedia format"), ++ .mime_type = "application/vnd.rn-realmedia", ++ .extensions = "rm,ra", ++ .priv_data_size = sizeof(RMMuxContext), ++ .audio_codec = CODEC_ID_AC3, ++ .video_codec = CODEC_ID_RV10, ++ .write_header = rm_write_header, ++ .write_packet = rm_write_packet, ++ .write_trailer = rm_write_trailer, + .codec_tag= (const AVCodecTag* const []){ff_rm_codec_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rm.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rm.h 2012-05-14 14:08:55.136356123 +0200 +@@ -41,7 +41,7 @@ + * Read the MDPR chunk, which contains stream-specific codec initialization + * parameters. + * +- * @param s context containing RMContext and ByteIOContext for stream reading ++ * @param s context containing RMContext and AVIOContext for stream reading + * @param pb context to read the data from + * @param st the stream that the MDPR chunk belongs to and where to store the + * parameters read from the chunk into +@@ -49,14 +49,14 @@ + * @param codec_data_size size of the MDPR chunk + * @return 0 on success, errno codes on error + */ +-int ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb, ++int ff_rm_read_mdpr_codecdata (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *rst, + int codec_data_size); + + /** + * Parse one rm-stream packet from the input bytestream. + * +- * @param s context containing RMContext and ByteIOContext for stream reading ++ * @param s context containing RMContext and AVIOContext for stream reading + * @param pb context to read the data from + * @param st stream to which the packet to be read belongs + * @param rst Real-specific stream information +@@ -70,7 +70,7 @@ + * value >0 means that no data was placed in pkt, but that cached + * data is available by calling ff_rm_retrieve_cache(). + */ +-int ff_rm_parse_packet (AVFormatContext *s, ByteIOContext *pb, ++int ff_rm_parse_packet (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *rst, int len, + AVPacket *pkt, int *seq, int flags, int64_t ts); + +@@ -82,7 +82,7 @@ + * a positive number, the amount of cached packets. Using this function, each + * of those packets can be retrieved sequentially. + * +- * @param s context containing RMContext and ByteIOContext for stream reading ++ * @param s context containing RMContext and AVIOContext for stream reading + * @param pb context to read the data from + * @param st stream that this packet belongs to + * @param rst Real-specific stream information +@@ -90,7 +90,7 @@ + * @return the number of samples left for subsequent calls to this same + * function, or 0 if all samples have been retrieved. + */ +-int ff_rm_retrieve_cache (AVFormatContext *s, ByteIOContext *pb, ++int ff_rm_retrieve_cache (AVFormatContext *s, AVIOContext *pb, + AVStream *st, RMStream *rst, AVPacket *pkt); + + /** +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rpl.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rpl.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rpl.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rpl.c 2012-05-14 14:08:55.148356364 +0200 +@@ -20,7 +20,9 @@ + */ + + #include "libavutil/avstring.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + #include + + #define RPL_SIGNATURE "ARMovie\x0A" +@@ -47,16 +49,16 @@ + uint32_t frame_in_part; + } RPLContext; + +-static int read_line(ByteIOContext * pb, char* line, int bufsize) ++static int read_line(AVIOContext * pb, char* line, int bufsize) + { + int i; + for (i = 0; i < bufsize - 1; i++) { +- int b = get_byte(pb); ++ int b = avio_r8(pb); + if (b == 0) + break; + if (b == '\n') { + line[i] = '\0'; +- return 0; ++ return url_feof(pb) ? -1 : 0; + } + line[i] = b; + } +@@ -76,7 +78,7 @@ + return result; + } + +-static int32_t read_line_and_int(ByteIOContext * pb, int* error) ++static int32_t read_line_and_int(AVIOContext * pb, int* error) + { + char line[RPL_LINE_LENGTH]; + const char *endptr; +@@ -110,7 +112,7 @@ + + static int rpl_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + RPLContext *rpl = s->priv_data; + AVStream *vst = NULL, *ast = NULL; + int total_audio_size; +@@ -131,14 +133,14 @@ + // for the text in a few cases; samples needed.) + error |= read_line(pb, line, sizeof(line)); // ARMovie + error |= read_line(pb, line, sizeof(line)); // movie name +- av_metadata_set2(&s->metadata, "title" , line, 0); ++ av_dict_set(&s->metadata, "title" , line, 0); + error |= read_line(pb, line, sizeof(line)); // date/copyright +- av_metadata_set2(&s->metadata, "copyright", line, 0); ++ av_dict_set(&s->metadata, "copyright", line, 0); + error |= read_line(pb, line, sizeof(line)); // author and other +- av_metadata_set2(&s->metadata, "author" , line, 0); ++ av_dict_set(&s->metadata, "author" , line, 0); + + // video headers +- vst = av_new_stream(s, 0); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -148,7 +150,7 @@ + vst->codec->bits_per_coded_sample = read_line_and_int(pb, &error); // video bits per sample + error |= read_line(pb, line, sizeof(line)); // video frames per second + fps = read_fps(line, &error); +- av_set_pts_info(vst, 32, fps.den, fps.num); ++ avpriv_set_pts_info(vst, 32, fps.den, fps.num); + + // Figure out the video codec + switch (vst->codec->codec_tag) { +@@ -162,11 +164,9 @@ + // The header is wrong here, at least sometimes + vst->codec->bits_per_coded_sample = 16; + break; +-#if 0 + case 130: + vst->codec->codec_id = CODEC_ID_ESCAPE130; + break; +-#endif + default: + av_log(s, AV_LOG_WARNING, + "RPL video format %i not supported yet!\n", +@@ -180,7 +180,7 @@ + // samples, though. This code will ignore additional tracks. + audio_format = read_line_and_int(pb, &error); // audio format ID + if (audio_format) { +- ast = av_new_stream(s, 0); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return AVERROR(ENOMEM); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -225,7 +225,7 @@ + "RPL audio format %i not supported yet!\n", + audio_format); + } +- av_set_pts_info(ast, 32, 1, ast->codec->bit_rate); ++ avpriv_set_pts_info(ast, 32, 1, ast->codec->bit_rate); + } else { + for (i = 0; i < 3; i++) + error |= read_line(pb, line, sizeof(line)); +@@ -250,9 +250,9 @@ + error |= read_line(pb, line, sizeof(line)); // offset to key frame list + + // Read the index +- url_fseek(pb, chunk_catalog_offset, SEEK_SET); ++ avio_seek(pb, chunk_catalog_offset, SEEK_SET); + total_audio_size = 0; +- for (i = 0; i < number_of_chunks; i++) { ++ for (i = 0; !error && i < number_of_chunks; i++) { + int64_t offset, video_size, audio_size; + error |= read_line(pb, line, sizeof(line)); + if (3 != sscanf(line, "%"PRId64" , %"PRId64" ; %"PRId64, +@@ -274,7 +274,7 @@ + static int rpl_read_packet(AVFormatContext *s, AVPacket *pkt) + { + RPLContext *rpl = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream* stream; + AVIndexEntry* index_entry; + uint32_t ret; +@@ -292,18 +292,18 @@ + index_entry = &stream->index_entries[rpl->chunk_number]; + + if (rpl->frame_in_part == 0) +- if (url_fseek(pb, index_entry->pos, SEEK_SET) < 0) ++ if (avio_seek(pb, index_entry->pos, SEEK_SET) < 0) + return AVERROR(EIO); + + if (stream->codec->codec_type == AVMEDIA_TYPE_VIDEO && + stream->codec->codec_tag == 124) { + // We have to split Escape 124 frames because there are + // multiple frames per chunk in Escape 124 samples. +- uint32_t frame_size, frame_flags; ++ uint32_t frame_size; + +- frame_flags = get_le32(pb); +- frame_size = get_le32(pb); +- if (url_fseek(pb, -8, SEEK_CUR) < 0) ++ avio_skip(pb, 4); /* flags */ ++ frame_size = avio_rl32(pb); ++ if (avio_seek(pb, -8, SEEK_CUR) < 0) + return AVERROR(EIO); + + ret = av_get_packet(pb, pkt, frame_size); +@@ -350,10 +350,10 @@ + } + + AVInputFormat ff_rpl_demuxer = { +- "rpl", +- NULL_IF_CONFIG_SMALL("RPL/ARMovie format"), +- sizeof(RPLContext), +- rpl_probe, +- rpl_read_header, +- rpl_read_packet, ++ .name = "rpl", ++ .long_name = NULL_IF_CONFIG_SMALL("RPL/ARMovie format"), ++ .priv_data_size = sizeof(RPLContext), ++ .read_probe = rpl_probe, ++ .read_header = rpl_read_header, ++ .read_packet = rpl_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rsodec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rsodec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rsodec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rsodec.c 2012-05-14 14:08:55.150356404 +0200 +@@ -29,16 +29,16 @@ + + static int rso_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int id, rate, bps; + unsigned int size; + enum CodecID codec; + AVStream *st; + +- id = get_be16(pb); +- size = get_be16(pb); +- rate = get_be16(pb); +- get_be16(pb); /* play mode ? (0x0000 = don't loop) */ ++ id = avio_rb16(pb); ++ size = avio_rb16(pb); ++ rate = avio_rb16(pb); ++ avio_rb16(pb); /* play mode ? (0x0000 = don't loop) */ + + codec = ff_codec_get_id(ff_codec_rso_tags, id); + +@@ -54,7 +54,7 @@ + } + + /* now we are ready: build format streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +@@ -65,7 +65,7 @@ + st->codec->channels = 1; + st->codec->sample_rate = rate; + +- av_set_pts_info(st, 64, 1, rate); ++ avpriv_set_pts_info(st, 64, 1, rate); + + return 0; + } +@@ -92,11 +92,8 @@ + .name = "rso", + .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO format"), + .extensions = "rso", +- .priv_data_size = 0, +- .read_probe = NULL, /* no magic value in this format */ + .read_header = rso_read_header, + .read_packet = rso_read_packet, +- .read_close = NULL, + .read_seek = pcm_read_seek, + .codec_tag = (const AVCodecTag* const []){ff_codec_rso_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rsoenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rsoenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rsoenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rsoenc.c 2012-05-14 14:08:55.150356404 +0200 +@@ -27,7 +27,7 @@ + + static int rso_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; + + if (!enc->codec_tag) +@@ -38,7 +38,7 @@ + return AVERROR_INVALIDDATA; + } + +- if (url_is_streamed(s->pb)) { ++ if (!s->pb->seekable) { + av_log(s, AV_LOG_ERROR, "muxer does not support non seekable output\n"); + return AVERROR_INVALIDDATA; + } +@@ -55,29 +55,29 @@ + } + + /* format header */ +- put_be16(pb, enc->codec_tag); /* codec ID */ +- put_be16(pb, 0); /* data size, will be written at EOF */ +- put_be16(pb, enc->sample_rate); +- put_be16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */ ++ avio_wb16(pb, enc->codec_tag); /* codec ID */ ++ avio_wb16(pb, 0); /* data size, will be written at EOF */ ++ avio_wb16(pb, enc->sample_rate); ++ avio_wb16(pb, 0x0000); /* play mode ? (0x0000 = don't loop) */ + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int rso_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- put_buffer(s->pb, pkt->data, pkt->size); ++ avio_write(s->pb, pkt->data, pkt->size); + return 0; + } + + static int rso_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t file_size; + uint16_t coded_file_size; + +- file_size = url_ftell(pb); ++ file_size = avio_tell(pb); + + if (file_size < 0) + return file_size; +@@ -91,11 +91,11 @@ + } + + /* update file size */ +- url_fseek(pb, 2, SEEK_SET); +- put_be16(pb, coded_file_size); +- url_fseek(pb, file_size, SEEK_SET); ++ avio_seek(pb, 2, SEEK_SET); ++ avio_wb16(pb, coded_file_size); ++ avio_seek(pb, file_size, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } +@@ -104,7 +104,6 @@ + .name = "rso", + .long_name = NULL_IF_CONFIG_SMALL("Lego Mindstorms RSO format"), + .extensions = "rso", +- .priv_data_size = 0, + .audio_codec = CODEC_ID_PCM_U8, + .video_codec = CODEC_ID_NONE, + .write_header = rso_write_header, +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rso.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rso.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rso.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rso.h 2012-05-14 14:08:55.149356384 +0200 +@@ -26,7 +26,7 @@ + + #define RSO_HEADER_SIZE 8 + +-/* The ffmpeg codecs we support, and the IDs they have in the file */ ++/* The libavcodec codecs we support, and the IDs they have in the file */ + extern const AVCodecTag ff_codec_rso_tags[]; + + #endif /* AVFORMAT_RSO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmppkt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmppkt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmppkt.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmppkt.c 2012-05-14 14:08:55.151356425 +0200 +@@ -21,10 +21,12 @@ + + #include "libavcodec/bytestream.h" + #include "libavutil/avstring.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" + + #include "rtmppkt.h" + #include "flv.h" ++#include "url.h" + + void ff_amf_write_bool(uint8_t **dst, int val) + { +@@ -35,7 +37,7 @@ + void ff_amf_write_number(uint8_t **dst, double val) + { + bytestream_put_byte(dst, AMF_DATA_TYPE_NUMBER); +- bytestream_put_be64(dst, av_dbl2int(val)); ++ bytestream_put_be64(dst, av_double2int(val)); + } + + void ff_amf_write_string(uint8_t **dst, const char *str) +@@ -78,14 +80,14 @@ + enum RTMPPacketType type; + int size = 0; + +- if (url_read(h, &hdr, 1) != 1) ++ if (ffurl_read(h, &hdr, 1) != 1) + return AVERROR(EIO); + size++; + channel_id = hdr & 0x3F; + + if (channel_id < 2) { //special case for channel number >= 64 + buf[1] = 0; +- if (url_read_complete(h, buf, channel_id + 1) != channel_id + 1) ++ if (ffurl_read_complete(h, buf, channel_id + 1) != channel_id + 1) + return AVERROR(EIO); + size += channel_id + 1; + channel_id = AV_RL16(buf) + 64; +@@ -98,28 +100,28 @@ + if (hdr == RTMP_PS_ONEBYTE) { + timestamp = prev_pkt[channel_id].ts_delta; + } else { +- if (url_read_complete(h, buf, 3) != 3) ++ if (ffurl_read_complete(h, buf, 3) != 3) + return AVERROR(EIO); + size += 3; + timestamp = AV_RB24(buf); + if (hdr != RTMP_PS_FOURBYTES) { +- if (url_read_complete(h, buf, 3) != 3) ++ if (ffurl_read_complete(h, buf, 3) != 3) + return AVERROR(EIO); + size += 3; + data_size = AV_RB24(buf); +- if (url_read_complete(h, buf, 1) != 1) ++ if (ffurl_read_complete(h, buf, 1) != 1) + return AVERROR(EIO); + size++; + type = buf[0]; + if (hdr == RTMP_PS_TWELVEBYTES) { +- if (url_read_complete(h, buf, 4) != 4) ++ if (ffurl_read_complete(h, buf, 4) != 4) + return AVERROR(EIO); + size += 4; + extra = AV_RL32(buf); + } + } + if (timestamp == 0xFFFFFF) { +- if (url_read_complete(h, buf, 4) != 4) ++ if (ffurl_read_complete(h, buf, 4) != 4) + return AVERROR(EIO); + timestamp = AV_RB32(buf); + } +@@ -139,7 +141,7 @@ + prev_pkt[channel_id].extra = extra; + while (data_size > 0) { + int toread = FFMIN(data_size, chunk_size); +- if (url_read_complete(h, p->data + offset, toread) != toread) { ++ if (ffurl_read_complete(h, p->data + offset, toread) != toread) { + ff_rtmp_packet_destroy(p); + return AVERROR(EIO); + } +@@ -147,7 +149,7 @@ + offset += chunk_size; + size += chunk_size; + if (data_size > 0) { +- url_read_complete(h, &t, 1); //marker ++ ffurl_read_complete(h, &t, 1); //marker + size++; + if (t != (0xC0 + channel_id)) + return -1; +@@ -214,15 +216,15 @@ + } + prev_pkt[pkt->channel_id].extra = pkt->extra; + +- url_write(h, pkt_hdr, p-pkt_hdr); ++ ffurl_write(h, pkt_hdr, p-pkt_hdr); + size = p - pkt_hdr + pkt->data_size; + while (off < pkt->data_size) { + int towrite = FFMIN(chunk_size, pkt->data_size - off); +- url_write(h, pkt->data + off, towrite); ++ ffurl_write(h, pkt->data + off, towrite); + off += towrite; + if (off < pkt->data_size) { + uint8_t marker = 0xC0 | pkt->channel_id; +- url_write(h, &marker, 1); ++ ffurl_write(h, &marker, 1); + size++; + } + } +@@ -232,9 +234,11 @@ + int ff_rtmp_packet_create(RTMPPacket *pkt, int channel_id, RTMPPacketType type, + int timestamp, int size) + { +- pkt->data = av_malloc(size); +- if (!pkt->data) +- return AVERROR(ENOMEM); ++ if (size) { ++ pkt->data = av_malloc(size); ++ if (!pkt->data) ++ return AVERROR(ENOMEM); ++ } + pkt->data_size = size; + pkt->channel_id = channel_id; + pkt->type = type; +@@ -314,7 +318,7 @@ + if (size == namelen && !memcmp(data-size, name, namelen)) { + switch (*data++) { + case AMF_DATA_TYPE_NUMBER: +- snprintf(dst, dst_size, "%g", av_int2dbl(AV_RB64(data))); ++ snprintf(dst, dst_size, "%g", av_int2double(AV_RB64(data))); + break; + case AMF_DATA_TYPE_BOOL: + snprintf(dst, dst_size, "%s", *data ? "true" : "false"); +@@ -366,7 +370,7 @@ + return; + switch (*data++) { + case AMF_DATA_TYPE_NUMBER: +- av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2dbl(AV_RB64(data))); ++ av_log(ctx, AV_LOG_DEBUG, " number %g\n", av_int2double(AV_RB64(data))); + return; + case AMF_DATA_TYPE_BOOL: + av_log(ctx, AV_LOG_DEBUG, " bool %d\n", *data); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmppkt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmppkt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmppkt.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmppkt.h 2012-05-14 14:08:55.152356445 +0200 +@@ -23,6 +23,7 @@ + #define AVFORMAT_RTMPPKT_H + + #include "avformat.h" ++#include "url.h" + + /** maximum possible number of different RTMP channels */ + #define RTMP_CHANNELS 65599 +@@ -137,7 +138,7 @@ + void ff_rtmp_packet_dump(void *ctx, RTMPPacket *p); + + /** +- * @defgroup amffuncs functions used to work with AMF format (which is also used in .flv) ++ * @name Functions used to work with the AMF format (which is also used in .flv) + * @see amf_* funcs in libavformat/flvdec.c + * @{ + */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmpproto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmpproto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtmpproto.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtmpproto.c 2012-05-14 14:08:55.154356485 +0200 +@@ -26,6 +26,7 @@ + + #include "libavcodec/bytestream.h" + #include "libavutil/avstring.h" ++#include "libavutil/intfloat.h" + #include "libavutil/lfg.h" + #include "libavutil/sha.h" + #include "avformat.h" +@@ -36,13 +37,7 @@ + #include "flv.h" + #include "rtmp.h" + #include "rtmppkt.h" +- +-/* we can't use av_log() with URLContext yet... */ +-#if FF_API_URL_CLASS +-#define LOG_CONTEXT s +-#else +-#define LOG_CONTEXT NULL +-#endif ++#include "url.h" + + //#define DEBUG + +@@ -76,6 +71,11 @@ + uint32_t client_report_size; ///< number of bytes after which client should report to server + uint32_t bytes_read; ///< number of bytes read from server + uint32_t last_bytes_read; ///< number of bytes read last reported to server ++ int skip_bytes; ///< number of bytes to skip from the input FLV stream in the next write call ++ uint8_t flv_header[11]; ///< partial incoming flv packet header ++ int flv_header_bytes; ///< number of initialized bytes in flv_header ++ int nb_invokes; ///< keeps track of invoke messages ++ int create_stream_invoke; ///< invoke id for the create stream command + } RTMPContext; + + #define PLAYER_KEY_OPEN_PART_LEN 30 ///< length of partial key used for first client digest signing +@@ -116,7 +116,7 @@ + + ff_url_join(tcurl, sizeof(tcurl), proto, NULL, host, port, "/%s", rt->app); + ff_amf_write_string(&p, "connect"); +- ff_amf_write_number(&p, 1.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_object_start(&p); + ff_amf_write_field_name(&p, "app"); + ff_amf_write_string(&p, rt->app); +@@ -165,10 +165,10 @@ + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 29 + strlen(rt->playpath)); + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Releasing stream...\n"); ++ av_log(s, AV_LOG_DEBUG, "Releasing stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "releaseStream"); +- ff_amf_write_number(&p, 2.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + +@@ -188,10 +188,10 @@ + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 25 + strlen(rt->playpath)); + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "FCPublish stream...\n"); ++ av_log(s, AV_LOG_DEBUG, "FCPublish stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "FCPublish"); +- ff_amf_write_number(&p, 3.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + +@@ -211,10 +211,10 @@ + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, + 27 + strlen(rt->playpath)); + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "UnPublishing stream...\n"); ++ av_log(s, AV_LOG_DEBUG, "UnPublishing stream...\n"); + p = pkt.data; + ff_amf_write_string(&p, "FCUnpublish"); +- ff_amf_write_number(&p, 5.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + +@@ -231,13 +231,14 @@ + RTMPPacket pkt; + uint8_t *p; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Creating stream...\n"); ++ av_log(s, AV_LOG_DEBUG, "Creating stream...\n"); + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 25); + + p = pkt.data; + ff_amf_write_string(&p, "createStream"); +- ff_amf_write_number(&p, rt->is_input ? 3.0 : 4.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); ++ rt->create_stream_invoke = rt->nb_invokes; + + ff_rtmp_packet_write(rt->stream, &pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&pkt); +@@ -253,12 +254,12 @@ + RTMPPacket pkt; + uint8_t *p; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Deleting stream...\n"); ++ av_log(s, AV_LOG_DEBUG, "Deleting stream...\n"); + ff_rtmp_packet_create(&pkt, RTMP_SYSTEM_CHANNEL, RTMP_PT_INVOKE, 0, 34); + + p = pkt.data; + ff_amf_write_string(&p, "deleteStream"); +- ff_amf_write_number(&p, 0.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_number(&p, rt->main_channel_id); + +@@ -275,14 +276,14 @@ + RTMPPacket pkt; + uint8_t *p; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending play command for '%s'\n", rt->playpath); ++ av_log(s, AV_LOG_DEBUG, "Sending play command for '%s'\n", rt->playpath); + ff_rtmp_packet_create(&pkt, RTMP_VIDEO_CHANNEL, RTMP_PT_INVOKE, 0, + 20 + strlen(rt->playpath)); + pkt.extra = rt->main_channel_id; + + p = pkt.data; + ff_amf_write_string(&p, "play"); +- ff_amf_write_number(&p, 0.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + +@@ -309,14 +310,14 @@ + RTMPPacket pkt; + uint8_t *p; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending publish command for '%s'\n", rt->playpath); ++ av_log(s, AV_LOG_DEBUG, "Sending publish command for '%s'\n", rt->playpath); + ff_rtmp_packet_create(&pkt, RTMP_SOURCE_CHANNEL, RTMP_PT_INVOKE, 0, + 30 + strlen(rt->playpath)); + pkt.extra = rt->main_channel_id; + + p = pkt.data; + ff_amf_write_string(&p, "publish"); +- ff_amf_write_number(&p, 0.0); ++ ff_amf_write_number(&p, ++rt->nb_invokes); + ff_amf_write_null(&p); + ff_amf_write_string(&p, rt->playpath); + ff_amf_write_string(&p, "live"); +@@ -477,7 +478,7 @@ + int server_pos, client_pos; + uint8_t digest[32]; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Handshaking...\n"); ++ av_log(s, AV_LOG_DEBUG, "Handshaking...\n"); + + av_lfg_init(&rnd, 0xDEADC0DE); + // generate handshake packet - 1536 bytes of pseudorandom data +@@ -485,19 +486,19 @@ + tosend[i] = av_lfg_get(&rnd) >> 24; + client_pos = rtmp_handshake_imprint_with_digest(tosend + 1); + +- url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); +- i = url_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); ++ ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE + 1); ++ i = ffurl_read_complete(rt->stream, serverdata, RTMP_HANDSHAKE_PACKET_SIZE + 1); + if (i != RTMP_HANDSHAKE_PACKET_SIZE + 1) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); ++ av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); + return -1; + } +- i = url_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); ++ i = ffurl_read_complete(rt->stream, clientdata, RTMP_HANDSHAKE_PACKET_SIZE); + if (i != RTMP_HANDSHAKE_PACKET_SIZE) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); ++ av_log(s, AV_LOG_ERROR, "Cannot read RTMP handshake response\n"); + return -1; + } + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", ++ av_log(s, AV_LOG_DEBUG, "Server version %d.%d.%d.%d\n", + serverdata[5], serverdata[6], serverdata[7], serverdata[8]); + + if (rt->is_input && serverdata[5] >= 3) { +@@ -505,7 +506,7 @@ + if (!server_pos) { + server_pos = rtmp_validate_digest(serverdata + 1, 8); + if (!server_pos) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Server response validating failed\n"); ++ av_log(s, AV_LOG_ERROR, "Server response validating failed\n"); + return -1; + } + } +@@ -517,7 +518,7 @@ + digest, 32, + digest); + if (memcmp(digest, clientdata + RTMP_HANDSHAKE_PACKET_SIZE - 32, 32)) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Signature mismatch\n"); ++ av_log(s, AV_LOG_ERROR, "Signature mismatch\n"); + return -1; + } + +@@ -531,9 +532,9 @@ + tosend + RTMP_HANDSHAKE_PACKET_SIZE - 32); + + // write reply back to the server +- url_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); ++ ffurl_write(rt->stream, tosend, RTMP_HANDSHAKE_PACKET_SIZE); + } else { +- url_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); ++ ffurl_write(rt->stream, serverdata+1, RTMP_HANDSHAKE_PACKET_SIZE); + } + + return 0; +@@ -551,13 +552,13 @@ + const uint8_t *data_end = pkt->data + pkt->data_size; + + #ifdef DEBUG +- ff_rtmp_packet_dump(LOG_CONTEXT, pkt); ++ ff_rtmp_packet_dump(s, pkt); + #endif + + switch (pkt->type) { + case RTMP_PT_CHUNK_SIZE: + if (pkt->data_size != 4) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, ++ av_log(s, AV_LOG_ERROR, + "Chunk size change packet is not 4 bytes long (%d)\n", pkt->data_size); + return -1; + } +@@ -565,10 +566,10 @@ + ff_rtmp_packet_write(rt->stream, pkt, rt->chunk_size, rt->prev_pkt[1]); + rt->chunk_size = AV_RB32(pkt->data); + if (rt->chunk_size <= 0) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size); ++ av_log(s, AV_LOG_ERROR, "Incorrect chunk size %d\n", rt->chunk_size); + return -1; + } +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size); ++ av_log(s, AV_LOG_DEBUG, "New chunk size = %d\n", rt->chunk_size); + break; + case RTMP_PT_PING: + t = AV_RB16(pkt->data); +@@ -577,12 +578,12 @@ + break; + case RTMP_PT_CLIENT_BW: + if (pkt->data_size < 4) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, ++ av_log(s, AV_LOG_ERROR, + "Client bandwidth report packet is less than 4 bytes long (%d)\n", + pkt->data_size); + return -1; + } +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data)); ++ av_log(s, AV_LOG_DEBUG, "Client bandwidth = %d\n", AV_RB32(pkt->data)); + rt->client_report_size = AV_RB32(pkt->data) >> 1; + break; + case RTMP_PT_INVOKE: +@@ -592,7 +593,7 @@ + + if (!ff_amf_get_field_value(pkt->data + 9, data_end, + "description", tmpstr, sizeof(tmpstr))) +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Server error: %s\n",tmpstr); ++ av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr); + return -1; + } else if (!memcmp(pkt->data, "\002\000\007_result", 10)) { + switch (rt->state) { +@@ -614,8 +615,8 @@ + /* hack for Wowza Media Server, it does not send result for + * releaseStream and FCPublish calls */ + if (!pkt->data[10]) { +- int pkt_id = (int) av_int2dbl(AV_RB64(pkt->data + 11)); +- if (pkt_id == 4) ++ int pkt_id = av_int2double(AV_RB64(pkt->data + 11)); ++ if (pkt_id == rt->create_stream_invoke) + rt->state = STATE_CONNECTING; + } + if (rt->state != STATE_CONNECTING) +@@ -623,9 +624,9 @@ + case STATE_CONNECTING: + //extract a number from the result + if (pkt->data[10] || pkt->data[19] != 5 || pkt->data[20]) { +- av_log(LOG_CONTEXT, AV_LOG_WARNING, "Unexpected reply on connect()\n"); ++ av_log(s, AV_LOG_WARNING, "Unexpected reply on connect()\n"); + } else { +- rt->main_channel_id = (int) av_int2dbl(AV_RB64(pkt->data + 21)); ++ rt->main_channel_id = av_int2double(AV_RB64(pkt->data + 21)); + } + if (rt->is_input) { + gen_play(s, rt); +@@ -650,7 +651,7 @@ + if (!t && !strcmp(tmpstr, "error")) { + if (!ff_amf_get_field_value(ptr, data_end, + "description", tmpstr, sizeof(tmpstr))) +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Server error: %s\n",tmpstr); ++ av_log(s, AV_LOG_ERROR, "Server error: %s\n",tmpstr); + return -1; + } + t = ff_amf_get_field_value(ptr, data_end, +@@ -689,7 +690,7 @@ + return AVERROR_EOF; + + for (;;) { +- RTMPPacket rpkt; ++ RTMPPacket rpkt = { 0 }; + if ((ret = ff_rtmp_packet_read(rt->stream, &rpkt, + rt->chunk_size, rt->prev_pkt[0])) <= 0) { + if (ret == 0) { +@@ -699,8 +700,8 @@ + } + } + rt->bytes_read += ret; +- if (rt->bytes_read > rt->last_bytes_read + rt->client_report_size) { +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Sending bytes read report\n"); ++ if (rt->bytes_read - rt->last_bytes_read > rt->client_report_size) { ++ av_log(s, AV_LOG_DEBUG, "Sending bytes read report\n"); + gen_bytes_read(s, rt, rpkt.timestamp + 1); + rt->last_bytes_read = rt->bytes_read; + } +@@ -767,7 +768,6 @@ + } + ff_rtmp_packet_destroy(&rpkt); + } +- return 0; + } + + static int rtmp_close(URLContext *h) +@@ -785,8 +785,7 @@ + gen_delete_stream(h, rt); + + av_freep(&rt->flv_data); +- url_close(rt->stream); +- av_free(rt); ++ ffurl_close(rt->stream); + return 0; + } + +@@ -801,17 +800,13 @@ + */ + static int rtmp_open(URLContext *s, const char *uri, int flags) + { +- RTMPContext *rt; ++ RTMPContext *rt = s->priv_data; + char proto[8], hostname[256], path[1024], *fname; + uint8_t buf[2048]; + int port; + int ret; + +- rt = av_mallocz(sizeof(RTMPContext)); +- if (!rt) +- return AVERROR(ENOMEM); +- s->priv_data = rt; +- rt->is_input = !(flags & URL_WRONLY); ++ rt->is_input = !(flags & AVIO_FLAG_WRITE); + + av_url_split(proto, sizeof(proto), NULL, 0, hostname, sizeof(hostname), &port, + path, sizeof(path), s->filename); +@@ -820,14 +815,15 @@ + port = RTMP_DEFAULT_PORT; + ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); + +- if (url_open(&rt->stream, buf, URL_RDWR) < 0) { +- av_log(LOG_CONTEXT, AV_LOG_ERROR, "Cannot open connection %s\n", buf); ++ if (ffurl_open(&rt->stream, buf, AVIO_FLAG_READ_WRITE, ++ &s->interrupt_callback, NULL) < 0) { ++ av_log(s , AV_LOG_ERROR, "Cannot open connection %s\n", buf); + goto fail; + } + + rt->state = STATE_START; + if (rtmp_handshake(s, rt)) +- return -1; ++ goto fail; + + rt->chunk_size = 128; + rt->state = STATE_HANDSHAKED; +@@ -865,7 +861,7 @@ + rt->bytes_read = 0; + rt->last_bytes_read = 0; + +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", ++ av_log(s, AV_LOG_DEBUG, "Proto = %s, path = %s, app = %s, fname = %s\n", + proto, path, rt->app, rt->playpath); + gen_connect(s, rt, proto, hostname, port); + +@@ -885,9 +881,10 @@ + rt->flv_size = 0; + rt->flv_data = NULL; + rt->flv_off = 0; ++ rt->skip_bytes = 13; + } + +- s->max_packet_size = url_get_max_packet_size(rt->stream); ++ s->max_packet_size = rt->stream->max_packet_size; + s->is_streamed = 1; + return 0; + +@@ -923,33 +920,37 @@ + return orig_size; + } + +-static int rtmp_write(URLContext *h, const uint8_t *buf, int size) ++static int rtmp_write(URLContext *s, const uint8_t *buf, int size) + { +- RTMPContext *rt = h->priv_data; ++ RTMPContext *rt = s->priv_data; + int size_temp = size; + int pktsize, pkttype; + uint32_t ts; + const uint8_t *buf_temp = buf; + +- if (size < 11) { +- av_log(LOG_CONTEXT, AV_LOG_DEBUG, "FLV packet too small %d\n", size); +- return 0; +- } +- + do { +- if (!rt->flv_off) { +- //skip flv header +- if (buf_temp[0] == 'F' && buf_temp[1] == 'L' && buf_temp[2] == 'V') { +- buf_temp += 9 + 4; +- size_temp -= 9 + 4; +- } ++ if (rt->skip_bytes) { ++ int skip = FFMIN(rt->skip_bytes, size_temp); ++ buf_temp += skip; ++ size_temp -= skip; ++ rt->skip_bytes -= skip; ++ continue; ++ } ++ ++ if (rt->flv_header_bytes < 11) { ++ const uint8_t *header = rt->flv_header; ++ int copy = FFMIN(11 - rt->flv_header_bytes, size_temp); ++ bytestream_get_buffer(&buf_temp, rt->flv_header + rt->flv_header_bytes, copy); ++ rt->flv_header_bytes += copy; ++ size_temp -= copy; ++ if (rt->flv_header_bytes < 11) ++ break; + +- pkttype = bytestream_get_byte(&buf_temp); +- pktsize = bytestream_get_be24(&buf_temp); +- ts = bytestream_get_be24(&buf_temp); +- ts |= bytestream_get_byte(&buf_temp) << 24; +- bytestream_get_be24(&buf_temp); +- size_temp -= 11; ++ pkttype = bytestream_get_byte(&header); ++ pktsize = bytestream_get_be24(&header); ++ ts = bytestream_get_be24(&header); ++ ts |= bytestream_get_byte(&header) << 24; ++ bytestream_get_be24(&header); + rt->flv_size = pktsize; + + //force 12bytes header +@@ -972,28 +973,32 @@ + if (rt->flv_size - rt->flv_off > size_temp) { + bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, size_temp); + rt->flv_off += size_temp; ++ size_temp = 0; + } else { + bytestream_get_buffer(&buf_temp, rt->flv_data + rt->flv_off, rt->flv_size - rt->flv_off); ++ size_temp -= rt->flv_size - rt->flv_off; + rt->flv_off += rt->flv_size - rt->flv_off; + } + + if (rt->flv_off == rt->flv_size) { +- bytestream_get_be32(&buf_temp); ++ rt->skip_bytes = 4; + + ff_rtmp_packet_write(rt->stream, &rt->out_pkt, rt->chunk_size, rt->prev_pkt[1]); + ff_rtmp_packet_destroy(&rt->out_pkt); + rt->flv_size = 0; + rt->flv_off = 0; ++ rt->flv_header_bytes = 0; + } +- } while (buf_temp - buf < size_temp); ++ } while (buf_temp - buf < size); + return size; + } + + URLProtocol ff_rtmp_protocol = { +- "rtmp", +- rtmp_open, +- rtmp_read, +- rtmp_write, +- NULL, /* seek */ +- rtmp_close, ++ .name = "rtmp", ++ .url_open = rtmp_open, ++ .url_read = rtmp_read, ++ .url_write = rtmp_write, ++ .url_close = rtmp_close, ++ .priv_data_size = sizeof(RTMPContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtp.c 2012-05-14 14:08:55.155356505 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include + #include "avformat.h" + + #include "rtp.h" +@@ -43,7 +44,7 @@ + { + {0, "PCMU", AVMEDIA_TYPE_AUDIO, CODEC_ID_PCM_MULAW, 8000, 1}, + {3, "GSM", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, +- {4, "G723", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, ++ {4, "G723", AVMEDIA_TYPE_AUDIO, CODEC_ID_G723_1, 8000, 1}, + {5, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, + {6, "DVI4", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 16000, 1}, + {7, "LPC", AVMEDIA_TYPE_AUDIO, CODEC_ID_NONE, 8000, 1}, +@@ -89,21 +90,32 @@ + return -1; + } + +-int ff_rtp_get_payload_type(AVCodecContext *codec) ++int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec) + { +- int i, payload_type; ++ int i; ++ AVOutputFormat *ofmt = fmt ? fmt->oformat : NULL; + +- /* compute the payload type */ +- for (payload_type = -1, i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) ++ /* Was the payload type already specified for the RTP muxer? */ ++ if (ofmt && ofmt->priv_class) { ++ int64_t payload_type; ++ if (av_opt_get_int(fmt->priv_data, "payload_type", 0, &payload_type) >= 0 && ++ payload_type >= 0) ++ return (int)payload_type; ++ } ++ ++ /* static payload type */ ++ for (i = 0; AVRtpPayloadTypes[i].pt >= 0; ++i) + if (AVRtpPayloadTypes[i].codec_id == codec->codec_id) { + if (codec->codec_id == CODEC_ID_H263) + continue; + if (codec->codec_id == CODEC_ID_PCM_S16BE) + if (codec->channels != AVRtpPayloadTypes[i].audio_channels) + continue; +- payload_type = AVRtpPayloadTypes[i].pt; ++ return AVRtpPayloadTypes[i].pt; + } +- return payload_type; ++ ++ /* dynamic payload type */ ++ return RTP_PT_PRIVATE + (codec->codec_type == AVMEDIA_TYPE_AUDIO); + } + + const char *ff_rtp_enc_name(int payload_type) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_amr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_amr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_amr.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_amr.c 2012-05-14 14:08:55.159356586 +0200 +@@ -191,8 +191,8 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AMR_NB, + .parse_sdp_a_line = amr_parse_sdp_line, +- .open = amr_new_context, +- .close = amr_free_context, ++ .alloc = amr_new_context, ++ .free = amr_free_context, + .parse_packet = amr_handle_packet, + }; + +@@ -201,8 +201,8 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AMR_WB, + .parse_sdp_a_line = amr_parse_sdp_line, +- .open = amr_new_context, +- .close = amr_free_context, ++ .alloc = amr_new_context, ++ .free = amr_free_context, + .parse_packet = amr_handle_packet, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_asf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_asf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_asf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_asf.c 2012-05-14 14:08:55.161356626 +0200 +@@ -32,6 +32,8 @@ + #include "rtpdec_formats.h" + #include "rtsp.h" + #include "asf.h" ++#include "avio_internal.h" ++#include "internal.h" + + /** + * From MSDN 2.2.1.4, we learn that ASF data packets over RTP should not +@@ -72,7 +74,7 @@ + } + + /** +- * The following code is basically a buffered ByteIOContext, ++ * The following code is basically a buffered AVIOContext, + * with the added benefit of returning -EAGAIN (instead of 0) + * on packet boundaries, such that the ASF demuxer can return + * safely and resume business at the next packet. +@@ -82,9 +84,9 @@ + return AVERROR(EAGAIN); + } + +-static void init_packetizer(ByteIOContext *pb, uint8_t *buf, int len) ++static void init_packetizer(AVIOContext *pb, uint8_t *buf, int len) + { +- init_put_byte(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL); ++ ffio_init_context(pb, buf, len, 0, NULL, packetizer_read, NULL, NULL); + + /* this "fills" the buffer with its current content */ + pb->pos = len; +@@ -95,7 +97,7 @@ + { + int ret = 0; + if (av_strstart(p, "pgmpu:data:application/vnd.ms.wms-hdr.asfv1;base64,", &p)) { +- ByteIOContext pb; ++ AVIOContext pb; + RTSPState *rt = s->priv_data; + int len = strlen(p) * 6 / 8; + char *buf = av_mallocz(len); +@@ -106,14 +108,16 @@ + "Failed to fix invalid RTSP-MS/ASF min_pktsize\n"); + init_packetizer(&pb, buf, len); + if (rt->asf_ctx) { +- av_close_input_stream(rt->asf_ctx); +- rt->asf_ctx = NULL; ++ avformat_close_input(&rt->asf_ctx); + } +- ret = av_open_input_stream(&rt->asf_ctx, &pb, "", &ff_asf_demuxer, NULL); ++ if (!(rt->asf_ctx = avformat_alloc_context())) ++ return AVERROR(ENOMEM); ++ rt->asf_ctx->pb = &pb; ++ ret = avformat_open_input(&rt->asf_ctx, "", &ff_asf_demuxer, NULL); + if (ret < 0) + return ret; +- av_metadata_copy(&s->metadata, rt->asf_ctx->metadata, 0); +- rt->asf_pb_pos = url_ftell(&pb); ++ av_dict_copy(&s->metadata, rt->asf_ctx->metadata, 0); ++ rt->asf_pb_pos = avio_tell(&pb); + av_free(buf); + rt->asf_ctx->pb = NULL; + } +@@ -137,7 +141,7 @@ + *rt->asf_ctx->streams[i]->codec; + rt->asf_ctx->streams[i]->codec->extradata_size = 0; + rt->asf_ctx->streams[i]->codec->extradata = NULL; +- av_set_pts_info(s->streams[stream_index], 32, 1, 1000); ++ avpriv_set_pts_info(s->streams[stream_index], 32, 1, 1000); + } + } + } +@@ -147,7 +151,7 @@ + } + + struct PayloadContext { +- ByteIOContext *pktbuf, pb; ++ AVIOContext *pktbuf, pb; + uint8_t *buf; + }; + +@@ -161,7 +165,7 @@ + uint32_t *timestamp, + const uint8_t *buf, int len, int flags) + { +- ByteIOContext *pb = &asf->pb; ++ AVIOContext *pb = &asf->pb; + int res, mflags, len_off; + RTSPState *rt = s->priv_data; + +@@ -176,22 +180,22 @@ + + av_freep(&asf->buf); + +- init_put_byte(pb, buf, len, 0, NULL, NULL, NULL, NULL); ++ ffio_init_context(pb, buf, len, 0, NULL, NULL, NULL, NULL); + +- while (url_ftell(pb) + 4 < len) { +- int start_off = url_ftell(pb); ++ while (avio_tell(pb) + 4 < len) { ++ int start_off = avio_tell(pb); + +- mflags = get_byte(pb); ++ mflags = avio_r8(pb); + if (mflags & 0x80) + flags |= RTP_FLAG_KEY; +- len_off = get_be24(pb); ++ len_off = avio_rb24(pb); + if (mflags & 0x20) /**< relative timestamp */ +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + if (mflags & 0x10) /**< has duration */ +- url_fskip(pb, 4); ++ avio_skip(pb, 4); + if (mflags & 0x8) /**< has location ID */ +- url_fskip(pb, 4); +- off = url_ftell(pb); ++ avio_skip(pb, 4); ++ off = avio_tell(pb); + + if (!(mflags & 0x40)) { + /** +@@ -200,23 +204,23 @@ + * ASF packet. This is used to spread one ASF packet over + * multiple RTP packets. + */ +- if (asf->pktbuf && len_off != url_ftell(asf->pktbuf)) { ++ if (asf->pktbuf && len_off != avio_tell(asf->pktbuf)) { + uint8_t *p; +- url_close_dyn_buf(asf->pktbuf, &p); ++ avio_close_dyn_buf(asf->pktbuf, &p); + asf->pktbuf = NULL; + av_free(p); + } + if (!len_off && !asf->pktbuf && +- (res = url_open_dyn_buf(&asf->pktbuf)) < 0) ++ (res = avio_open_dyn_buf(&asf->pktbuf)) < 0) + return res; + if (!asf->pktbuf) + return AVERROR(EIO); + +- put_buffer(asf->pktbuf, buf + off, len - off); +- url_fskip(pb, len - off); ++ avio_write(asf->pktbuf, buf + off, len - off); ++ avio_skip(pb, len - off); + if (!(flags & RTP_FLAG_MARKER)) + return -1; +- out_len = url_close_dyn_buf(asf->pktbuf, &asf->buf); ++ out_len = avio_close_dyn_buf(asf->pktbuf, &asf->buf); + asf->pktbuf = NULL; + } else { + /** +@@ -229,11 +233,17 @@ + + int cur_len = start_off + len_off - off; + int prev_len = out_len; ++ void *newmem; + out_len += cur_len; +- asf->buf = av_realloc(asf->buf, out_len); ++ if (FFMIN(cur_len, len - off) < 0) ++ return -1; ++ newmem = av_realloc(asf->buf, out_len); ++ if (!newmem) ++ return -1; ++ asf->buf = newmem; + memcpy(asf->buf + prev_len, buf + off, + FFMIN(cur_len, len - off)); +- url_fskip(pb, cur_len); ++ avio_skip(pb, cur_len); + } + } + +@@ -247,7 +257,7 @@ + int i; + + res = av_read_packet(rt->asf_ctx, pkt); +- rt->asf_pb_pos = url_ftell(pb); ++ rt->asf_pb_pos = avio_tell(pb); + if (res != 0) + break; + for (i = 0; i < s->nb_streams; i++) { +@@ -271,7 +281,7 @@ + { + if (asf->pktbuf) { + uint8_t *p = NULL; +- url_close_dyn_buf(asf->pktbuf, &p); ++ avio_close_dyn_buf(asf->pktbuf, &p); + asf->pktbuf = NULL; + av_free(p); + } +@@ -285,10 +295,10 @@ + .codec_type = t, \ + .codec_id = CODEC_ID_NONE, \ + .parse_sdp_a_line = asfrtp_parse_sdp_line, \ +- .open = asfrtp_new_context, \ +- .close = asfrtp_free_context, \ ++ .alloc = asfrtp_new_context, \ ++ .free = asfrtp_free_context, \ + .parse_packet = asfrtp_parse_packet, \ +-}; ++} + + RTP_ASF_HANDLER(asf_pfv, "x-asf-pf", AVMEDIA_TYPE_VIDEO); + RTP_ASF_HANDLER(asf_pfa, "x-asf-pf", AVMEDIA_TYPE_AUDIO); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec.c 2012-05-14 14:08:55.158356565 +0200 +@@ -19,15 +19,14 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/* needed for gethostname() */ +-#define _XOPEN_SOURCE 600 +- ++#include "libavutil/mathematics.h" ++#include "libavutil/avstring.h" + #include "libavcodec/get_bits.h" + #include "avformat.h" + #include "mpegts.h" ++#include "url.h" + + #include +-#include + #include "network.h" + + #include "rtpdec.h" +@@ -41,7 +40,7 @@ + buffer to 'rtp_write_packet' contains all the packets for ONE + frame. Each packet should have a four byte header containing + the length in big endian format (same trick as +- 'url_open_dyn_packet_buf') ++ 'ffio_open_dyn_packet_buf') + */ + + static RTPDynamicProtocolHandler ff_realmedia_mp3_dynamic_handler = { +@@ -84,6 +83,11 @@ + ff_register_dynamic_payload_handler(&ff_qt_rtp_vid_handler); + ff_register_dynamic_payload_handler(&ff_quicktime_rtp_aud_handler); + ff_register_dynamic_payload_handler(&ff_quicktime_rtp_vid_handler); ++ ++ ff_register_dynamic_payload_handler(&ff_g726_16_dynamic_handler); ++ ff_register_dynamic_payload_handler(&ff_g726_24_dynamic_handler); ++ ff_register_dynamic_payload_handler(&ff_g726_32_dynamic_handler); ++ ff_register_dynamic_payload_handler(&ff_g726_40_dynamic_handler); + } + + RTPDynamicProtocolHandler *ff_rtp_handler_find_by_name(const char *name, +@@ -92,7 +96,7 @@ + RTPDynamicProtocolHandler *handler; + for (handler = RTPFirstDynamicPayloadHandler; + handler; handler = handler->next) +- if (!strcasecmp(name, handler->enc_name) && ++ if (!av_strcasecmp(name, handler->enc_name) && + codec_type == handler->codec_type) + return handler; + return NULL; +@@ -113,14 +117,15 @@ + static int rtcp_parse_packet(RTPDemuxContext *s, const unsigned char *buf, int len) + { + int payload_len; +- while (len >= 2) { ++ while (len >= 4) { ++ payload_len = FFMIN(len, (AV_RB16(buf + 2) + 1) * 4); ++ + switch (buf[1]) { + case RTCP_SR: +- if (len < 16) { ++ if (payload_len < 20) { + av_log(NULL, AV_LOG_ERROR, "Invalid length for RTCP SR packet\n"); + return AVERROR_INVALIDDATA; + } +- payload_len = (AV_RB16(buf + 2) + 1) * 4; + + s->last_rtcp_ntp_time = AV_RB64(buf + 8); + s->last_rtcp_timestamp = AV_RB32(buf + 16); +@@ -131,14 +136,13 @@ + s->rtcp_ts_offset = s->last_rtcp_timestamp - s->base_timestamp; + } + +- buf += payload_len; +- len -= payload_len; + break; + case RTCP_BYE: + return -RTCP_BYE; +- default: +- return -1; + } ++ ++ buf += payload_len; ++ len -= payload_len; + } + return -1; + } +@@ -219,25 +223,9 @@ + return 1; + } + +-#if 0 +-/** +-* This function is currently unused; without a valid local ntp time, I don't see how we could calculate the +-* difference between the arrival and sent timestamp. As a result, the jitter and transit statistics values +-* never change. I left this in in case someone else can see a way. (rdm) +-*/ +-static void rtcp_update_jitter(RTPStatistics *s, uint32_t sent_timestamp, uint32_t arrival_timestamp) ++int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) + { +- uint32_t transit= arrival_timestamp - sent_timestamp; +- int d; +- s->transit= transit; +- d= FFABS(transit - s->transit); +- s->jitter += d - ((s->jitter + 8)>>4); +-} +-#endif +- +-int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count) +-{ +- ByteIOContext *pb; ++ AVIOContext *pb; + uint8_t *buf; + int len; + int rtcp_bytes; +@@ -264,16 +252,16 @@ + return -1; + s->last_octet_count = s->octet_count; + +- if (url_open_dyn_buf(&pb) < 0) ++ if (avio_open_dyn_buf(&pb) < 0) + return -1; + + // Receiver Report +- put_byte(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ +- put_byte(pb, RTCP_RR); +- put_be16(pb, 7); /* length in words - 1 */ ++ avio_w8(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ ++ avio_w8(pb, RTCP_RR); ++ avio_wb16(pb, 7); /* length in words - 1 */ + // our own SSRC: we use the server's SSRC + 1 to avoid conflicts +- put_be32(pb, s->ssrc + 1); +- put_be32(pb, s->ssrc); // server SSRC ++ avio_wb32(pb, s->ssrc + 1); ++ avio_wb32(pb, s->ssrc); // server SSRC + // some placeholders we should really fill... + // RFC 1889/p64 + extended_max= stats->cycles + stats->max_seq; +@@ -290,83 +278,83 @@ + + fraction= (fraction<<24) | lost; + +- put_be32(pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */ +- put_be32(pb, extended_max); /* max sequence received */ +- put_be32(pb, stats->jitter>>4); /* jitter */ ++ avio_wb32(pb, fraction); /* 8 bits of fraction, 24 bits of total packets lost */ ++ avio_wb32(pb, extended_max); /* max sequence received */ ++ avio_wb32(pb, stats->jitter>>4); /* jitter */ + + if(s->last_rtcp_ntp_time==AV_NOPTS_VALUE) + { +- put_be32(pb, 0); /* last SR timestamp */ +- put_be32(pb, 0); /* delay since last SR */ ++ avio_wb32(pb, 0); /* last SR timestamp */ ++ avio_wb32(pb, 0); /* delay since last SR */ + } else { + uint32_t middle_32_bits= s->last_rtcp_ntp_time>>16; // this is valid, right? do we need to handle 64 bit values special? + uint32_t delay_since_last= ntp_time - s->last_rtcp_ntp_time; + +- put_be32(pb, middle_32_bits); /* last SR timestamp */ +- put_be32(pb, delay_since_last); /* delay since last SR */ ++ avio_wb32(pb, middle_32_bits); /* last SR timestamp */ ++ avio_wb32(pb, delay_since_last); /* delay since last SR */ + } + + // CNAME +- put_byte(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ +- put_byte(pb, RTCP_SDES); ++ avio_w8(pb, (RTP_VERSION << 6) + 1); /* 1 report block */ ++ avio_w8(pb, RTCP_SDES); + len = strlen(s->hostname); +- put_be16(pb, (6 + len + 3) / 4); /* length in words - 1 */ +- put_be32(pb, s->ssrc); +- put_byte(pb, 0x01); +- put_byte(pb, len); +- put_buffer(pb, s->hostname, len); ++ avio_wb16(pb, (6 + len + 3) / 4); /* length in words - 1 */ ++ avio_wb32(pb, s->ssrc + 1); ++ avio_w8(pb, 0x01); ++ avio_w8(pb, len); ++ avio_write(pb, s->hostname, len); + // padding + for (len = (6 + len) % 4; len % 4; len++) { +- put_byte(pb, 0); ++ avio_w8(pb, 0); + } + +- put_flush_packet(pb); +- len = url_close_dyn_buf(pb, &buf); ++ avio_flush(pb); ++ len = avio_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) { +- int result; ++ int av_unused result; + av_dlog(s->ic, "sending %d bytes of RR\n", len); +- result= url_write(s->rtp_ctx, buf, len); +- av_dlog(s->ic, "result from url_write: %d\n", result); ++ result= ffurl_write(s->rtp_ctx, buf, len); ++ av_dlog(s->ic, "result from ffurl_write: %d\n", result); + av_free(buf); + } + return 0; + } + +-void rtp_send_punch_packets(URLContext* rtp_handle) ++void ff_rtp_send_punch_packets(URLContext* rtp_handle) + { +- ByteIOContext *pb; ++ AVIOContext *pb; + uint8_t *buf; + int len; + + /* Send a small RTP packet */ +- if (url_open_dyn_buf(&pb) < 0) ++ if (avio_open_dyn_buf(&pb) < 0) + return; + +- put_byte(pb, (RTP_VERSION << 6)); +- put_byte(pb, 0); /* Payload type */ +- put_be16(pb, 0); /* Seq */ +- put_be32(pb, 0); /* Timestamp */ +- put_be32(pb, 0); /* SSRC */ ++ avio_w8(pb, (RTP_VERSION << 6)); ++ avio_w8(pb, 0); /* Payload type */ ++ avio_wb16(pb, 0); /* Seq */ ++ avio_wb32(pb, 0); /* Timestamp */ ++ avio_wb32(pb, 0); /* SSRC */ + +- put_flush_packet(pb); +- len = url_close_dyn_buf(pb, &buf); ++ avio_flush(pb); ++ len = avio_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) +- url_write(rtp_handle, buf, len); ++ ffurl_write(rtp_handle, buf, len); + av_free(buf); + + /* Send a minimal RTCP RR */ +- if (url_open_dyn_buf(&pb) < 0) ++ if (avio_open_dyn_buf(&pb) < 0) + return; + +- put_byte(pb, (RTP_VERSION << 6)); +- put_byte(pb, RTCP_RR); /* receiver report */ +- put_be16(pb, 1); /* length in words - 1 */ +- put_be32(pb, 0); /* our own SSRC */ ++ avio_w8(pb, (RTP_VERSION << 6)); ++ avio_w8(pb, RTCP_RR); /* receiver report */ ++ avio_wb16(pb, 1); /* length in words - 1 */ ++ avio_wb32(pb, 0); /* our own SSRC */ + +- put_flush_packet(pb); +- len = url_close_dyn_buf(pb, &buf); ++ avio_flush(pb); ++ len = avio_close_dyn_buf(pb, &buf); + if ((len > 0) && buf) +- url_write(rtp_handle, buf, len); ++ ffurl_write(rtp_handle, buf, len); + av_free(buf); + } + +@@ -376,7 +364,7 @@ + * MPEG2TS streams to indicate that they should be demuxed inside the + * rtp demux (otherwise CODEC_ID_MPEG2TS packets are returned) + */ +-RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size) ++RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size) + { + RTPDemuxContext *s; + +@@ -424,8 +412,8 @@ + } + + void +-rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, +- RTPDynamicProtocolHandler *handler) ++ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, ++ RTPDynamicProtocolHandler *handler) + { + s->dynamic_protocol_context = ctx; + s->parse_packet = handler->parse_packet; +@@ -438,7 +426,10 @@ + { + if (pkt->pts != AV_NOPTS_VALUE || pkt->dts != AV_NOPTS_VALUE) + return; /* Timestamp already set by depacketizer */ +- if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && timestamp != RTP_NOTS_VALUE) { ++ if (timestamp == RTP_NOTS_VALUE) ++ return; ++ ++ if (s->last_rtcp_ntp_time != AV_NOPTS_VALUE && s->ic->nb_streams > 1) { + int64_t addend; + int delta_timestamp; + +@@ -450,11 +441,16 @@ + delta_timestamp; + return; + } +- if (timestamp == RTP_NOTS_VALUE) +- return; ++ + if (!s->base_timestamp) + s->base_timestamp = timestamp; +- pkt->pts = s->range_start_offset + timestamp - s->base_timestamp; ++ /* assume that the difference is INT32_MIN < x < INT32_MAX, but allow the first timestamp to exceed INT32_MAX */ ++ if (!s->timestamp) ++ s->unwrapped_timestamp += timestamp; ++ else ++ s->unwrapped_timestamp += (int32_t)(timestamp - s->timestamp); ++ s->timestamp = timestamp; ++ pkt->pts = s->unwrapped_timestamp + s->range_start_offset - s->base_timestamp; + } + + static int rtp_parse_packet_internal(RTPDemuxContext *s, AVPacket *pkt, +@@ -739,8 +735,8 @@ + * @return 0 if a packet is returned, 1 if a packet is returned and more can follow + * (use buf as NULL to read the next). -1 if no packet (error or no more packet). + */ +-int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, +- uint8_t **bufptr, int len) ++int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, ++ uint8_t **bufptr, int len) + { + int rv = rtp_parse_one_packet(s, pkt, bufptr, len); + s->prev_ret = rv; +@@ -749,7 +745,7 @@ + return rv ? rv : has_next_packet(s); + } + +-void rtp_parse_close(RTPDemuxContext *s) ++void ff_rtp_parse_close(RTPDemuxContext *s) + { + ff_rtp_reset_packet_queue(s); + if (!strcmp(ff_rtp_enc_name(s->payload_type), "MP2T")) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_formats.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_formats.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_formats.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_formats.h 2012-05-14 14:08:55.161356626 +0200 +@@ -33,6 +33,10 @@ + + extern RTPDynamicProtocolHandler ff_amr_nb_dynamic_handler; + extern RTPDynamicProtocolHandler ff_amr_wb_dynamic_handler; ++extern RTPDynamicProtocolHandler ff_g726_16_dynamic_handler; ++extern RTPDynamicProtocolHandler ff_g726_24_dynamic_handler; ++extern RTPDynamicProtocolHandler ff_g726_32_dynamic_handler; ++extern RTPDynamicProtocolHandler ff_g726_40_dynamic_handler; + extern RTPDynamicProtocolHandler ff_h263_1998_dynamic_handler; + extern RTPDynamicProtocolHandler ff_h263_2000_dynamic_handler; + extern RTPDynamicProtocolHandler ff_h264_dynamic_handler; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_g726.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_g726.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_g726.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_g726.c 2012-05-14 14:08:55.162356646 +0200 +@@ -0,0 +1,46 @@ ++/* ++ * Copyright (c) 2011 Miroslav Slugeň ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "rtpdec_formats.h" ++ ++#define RTP_G726_HANDLER(bitrate) \ ++static int g726_ ## bitrate ##_init(AVFormatContext *s, int st_index, PayloadContext *data) \ ++{ \ ++ AVStream *stream = s->streams[st_index]; \ ++ AVCodecContext *codec = stream->codec; \ ++\ ++ codec->bits_per_coded_sample = bitrate/8; \ ++ codec->bit_rate = codec->bits_per_coded_sample * codec->sample_rate; \ ++\ ++ return 0; \ ++} \ ++\ ++RTPDynamicProtocolHandler ff_g726_ ## bitrate ## _dynamic_handler = { \ ++ .enc_name = "G726-" #bitrate, \ ++ .codec_type = AVMEDIA_TYPE_AUDIO, \ ++ .codec_id = CODEC_ID_ADPCM_G726, \ ++ .init = g726_ ## bitrate ## _init, \ ++} ++ ++RTP_G726_HANDLER(16); ++RTP_G726_HANDLER(24); ++RTP_G726_HANDLER(32); ++RTP_G726_HANDLER(40); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec.h 2012-05-14 14:08:55.159356586 +0200 +@@ -25,6 +25,7 @@ + #include "libavcodec/avcodec.h" + #include "avformat.h" + #include "rtp.h" ++#include "url.h" + + typedef struct PayloadContext PayloadContext; + typedef struct RTPDynamicProtocolHandler_s RTPDynamicProtocolHandler; +@@ -37,18 +38,18 @@ + #define RTP_NOTS_VALUE ((uint32_t)-1) + + typedef struct RTPDemuxContext RTPDemuxContext; +-RTPDemuxContext *rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size); +-void rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, +- RTPDynamicProtocolHandler *handler); +-int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, +- uint8_t **buf, int len); +-void rtp_parse_close(RTPDemuxContext *s); ++RTPDemuxContext *ff_rtp_parse_open(AVFormatContext *s1, AVStream *st, URLContext *rtpc, int payload_type, int queue_size); ++void ff_rtp_parse_set_dynamic_protocol(RTPDemuxContext *s, PayloadContext *ctx, ++ RTPDynamicProtocolHandler *handler); ++int ff_rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, ++ uint8_t **buf, int len); ++void ff_rtp_parse_close(RTPDemuxContext *s); + int64_t ff_rtp_queued_packet_time(RTPDemuxContext *s); + void ff_rtp_reset_packet_queue(RTPDemuxContext *s); +-int rtp_get_local_rtp_port(URLContext *h); +-int rtp_get_local_rtcp_port(URLContext *h); ++int ff_rtp_get_local_rtp_port(URLContext *h); ++int ff_rtp_get_local_rtcp_port(URLContext *h); + +-int rtp_set_remote_url(URLContext *h, const char *uri); ++int ff_rtp_set_remote_url(URLContext *h, const char *uri); + + /** + * Send a dummy packet on both port pairs to set up the connection +@@ -61,19 +62,19 @@ + * The same routine is used with RDT too, even if RDT doesn't use normal + * RTP packets otherwise. + */ +-void rtp_send_punch_packets(URLContext* rtp_handle); ++void ff_rtp_send_punch_packets(URLContext* rtp_handle); + + /** + * some rtp servers assume client is dead if they don't hear from them... + * so we send a Receiver Report to the provided ByteIO context + * (we don't have access to the rtcp handle from here) + */ +-int rtp_check_and_send_back_rr(RTPDemuxContext *s, int count); ++int ff_rtp_check_and_send_back_rr(RTPDemuxContext *s, int count); + + /** + * Get the file handle for the RTCP socket. + */ +-int rtp_get_rtcp_file_handle(URLContext *h); ++int ff_rtp_get_rtcp_file_handle(URLContext *h); + + // these statistics are used for rtcp receiver reports... + typedef struct { +@@ -121,12 +122,13 @@ + * require any custom depacketization code. */ + + // may be null ++ int (*init)(AVFormatContext *s, int st_index, PayloadContext *priv_data); ///< Initialize dynamic protocol handler, called after the full rtpmap line is parsed + int (*parse_sdp_a_line) (AVFormatContext *s, + int st_index, + PayloadContext *priv_data, + const char *line); ///< Parse the a= line from the sdp field +- PayloadContext *(*open) (void); ///< allocate any data needed by the rtp parsing for this dynamic data. +- void (*close)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data. ++ PayloadContext *(*alloc) (void); ///< allocate any data needed by the rtp parsing for this dynamic data. ++ void (*free)(PayloadContext *protocol_data); ///< free any data needed by the rtp parsing for this dynamic data. + DynamicPayloadPacketHandlerProc parse_packet; ///< parse handler for this dynamic packet. + + struct RTPDynamicProtocolHandler_s *next; +@@ -150,6 +152,7 @@ + uint32_t timestamp; + uint32_t base_timestamp; + uint32_t cur_timestamp; ++ int64_t unwrapped_timestamp; + int64_t range_start_offset; + int max_payload_size; + struct MpegTSContext *ts; /* only used for MP2T payloads */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_h264.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_h264.c 2012-05-14 14:08:55.162356646 +0200 +@@ -398,7 +398,7 @@ + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_H264, + .parse_sdp_a_line = parse_h264_sdp_line, +- .open = h264_new_context, +- .close = h264_free_context, ++ .alloc = h264_new_context, ++ .free = h264_free_context, + .parse_packet = h264_handle_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_latm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_latm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_latm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_latm.c 2012-05-14 14:08:55.163356666 +0200 +@@ -23,10 +23,9 @@ + #include "internal.h" + #include "libavutil/avstring.h" + #include "libavcodec/get_bits.h" +-#include + + struct PayloadContext { +- ByteIOContext *dyn_buf; ++ AVIOContext *dyn_buf; + uint8_t *buf; + int pos, len; + uint32_t timestamp; +@@ -43,7 +42,7 @@ + return; + if (data->dyn_buf) { + uint8_t *p; +- url_close_dyn_buf(data->dyn_buf, &p); ++ avio_close_dyn_buf(data->dyn_buf, &p); + av_free(p); + } + av_free(data->buf); +@@ -60,20 +59,20 @@ + if (!data->dyn_buf || data->timestamp != *timestamp) { + av_freep(&data->buf); + if (data->dyn_buf) +- url_close_dyn_buf(data->dyn_buf, &data->buf); ++ avio_close_dyn_buf(data->dyn_buf, &data->buf); + data->dyn_buf = NULL; + av_freep(&data->buf); + + data->timestamp = *timestamp; +- if ((ret = url_open_dyn_buf(&data->dyn_buf)) < 0) ++ if ((ret = avio_open_dyn_buf(&data->dyn_buf)) < 0) + return ret; + } +- put_buffer(data->dyn_buf, buf, len); ++ avio_write(data->dyn_buf, buf, len); + + if (!(flags & RTP_FLAG_MARKER)) + return AVERROR(EAGAIN); + av_free(data->buf); +- data->len = url_close_dyn_buf(data->dyn_buf, &data->buf); ++ data->len = avio_close_dyn_buf(data->dyn_buf, &data->buf); + data->dyn_buf = NULL; + data->pos = 0; + } +@@ -108,8 +107,7 @@ + int len = ff_hex_to_data(NULL, value), i, ret = 0; + GetBitContext gb; + uint8_t *config; +- int audio_mux_version, same_time_framing, num_sub_frames, +- num_programs, num_layers; ++ int audio_mux_version, same_time_framing, num_programs, num_layers; + + /* Pad this buffer, too, to avoid out of bounds reads with get_bits below */ + config = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); +@@ -119,7 +117,7 @@ + init_get_bits(&gb, config, len*8); + audio_mux_version = get_bits(&gb, 1); + same_time_framing = get_bits(&gb, 1); +- num_sub_frames = get_bits(&gb, 6); ++ skip_bits(&gb, 6); /* num_sub_frames */ + num_programs = get_bits(&gb, 4); + num_layers = get_bits(&gb, 3); + if (audio_mux_version != 0 || same_time_framing != 1 || num_programs != 0 || +@@ -181,7 +179,7 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AAC, + .parse_sdp_a_line = latm_parse_sdp_line, +- .open = latm_new_context, +- .close = latm_free_context, ++ .alloc = latm_new_context, ++ .free = latm_free_context, + .parse_packet = latm_parse_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_mpeg4.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_mpeg4.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_mpeg4.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_mpeg4.c 2012-05-14 14:08:55.164356686 +0200 +@@ -31,7 +31,6 @@ + #include "internal.h" + #include "libavutil/avstring.h" + #include "libavcodec/get_bits.h" +-#include + + /** Structure listing useful vars to parse RTP packet payload*/ + struct PayloadContext +@@ -111,8 +110,7 @@ + { + /* decode the hexa encoded parameter */ + int len = ff_hex_to_data(NULL, value); +- if (codec->extradata) +- av_free(codec->extradata); ++ av_free(codec->extradata); + codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); + if (!codec->extradata) + return AVERROR(ENOMEM); +@@ -207,7 +205,7 @@ + if (codec->codec_id == CODEC_ID_AAC) { + /* Looking for a known attribute */ + for (i = 0; attr_names[i].str; ++i) { +- if (!strcasecmp(attr, attr_names[i].str)) { ++ if (!av_strcasecmp(attr, attr_names[i].str)) { + if (attr_names[i].type == ATTR_NAME_TYPE_INT) { + *(int *)((char *)data+ + attr_names[i].offset) = atoi(value); +@@ -236,9 +234,6 @@ + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_MPEG4, + .parse_sdp_a_line = parse_sdp_line, +- .open = NULL, +- .close = NULL, +- .parse_packet = NULL + }; + + RTPDynamicProtocolHandler ff_mpeg4_generic_dynamic_handler = { +@@ -246,7 +241,7 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_AAC, + .parse_sdp_a_line = parse_sdp_line, +- .open = new_context, +- .close = free_context, ++ .alloc = new_context, ++ .free = free_context, + .parse_packet = aac_parse_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qcelp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qcelp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qcelp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qcelp.c 2012-05-14 14:08:55.165356706 +0200 +@@ -223,7 +223,7 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_QCELP, + .static_payload_id = 12, +- .open = qcelp_new_context, +- .close = qcelp_free_context, ++ .alloc = qcelp_new_context, ++ .free = qcelp_free_context, + .parse_packet = qcelp_parse_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qdm2.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qdm2.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qdm2.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qdm2.c 2012-05-14 14:08:55.166356726 +0200 +@@ -52,8 +52,8 @@ + }; + + /** +- * Parses configuration (basically the codec-specific extradata) from +- * a RTP config subpacket (starts with 0xff). ++ * Parse configuration (basically the codec-specific extradata) from ++ * an RTP config subpacket (starts with 0xff). + * + * Layout of the config subpacket (in bytes): + * 1: 0xFF <- config ID +@@ -128,7 +128,7 @@ + } + + /** +- * Parses a single subpacket. We store this subpacket in an intermediate ++ * Parse a single subpacket. We store this subpacket in an intermediate + * buffer (position depends on the ID (byte[0]). When called, at least + * 4 bytes are available for reading (see qdm2_parse_packet()). + * +@@ -179,7 +179,7 @@ + } + + /** +- * Adds a superblock header around a set of subpackets. ++ * Add a superblock header around a set of subpackets. + * + * @return <0 on error, else 0. + */ +@@ -266,6 +266,8 @@ + * to the decoder that it is OK to initialize. */ + st->codec->codec_id = CODEC_ID_QDM2; + } ++ if (st->codec->codec_id == CODEC_ID_NONE) ++ return AVERROR(EAGAIN); + + /* subpackets */ + while (end - p >= 4) { +@@ -309,7 +311,7 @@ + .enc_name = "X-QDM", + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_NONE, +- .open = qdm2_extradata_new, +- .close = qdm2_extradata_free, ++ .alloc = qdm2_extradata_new, ++ .free = qdm2_extradata_free, + .parse_packet = qdm2_parse_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_qt.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_qt.c 2012-05-14 14:08:55.167356747 +0200 +@@ -26,6 +26,8 @@ + */ + + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "rtp.h" + #include "rtpdec.h" + #include "isom.h" +@@ -42,7 +44,7 @@ + uint32_t *timestamp, const uint8_t *buf, + int len, int flags) + { +- ByteIOContext pb; ++ AVIOContext pb; + GetBitContext gb; + int packing_scheme, has_payload_desc, has_packet_info, alen, + has_marker_bit = flags & RTP_FLAG_MARKER; +@@ -69,7 +71,7 @@ + * http://developer.apple.com/quicktime/icefloe/dispatch026.html + */ + init_get_bits(&gb, buf, len << 3); +- init_put_byte(&pb, buf, len, 0, NULL, NULL, NULL, NULL); ++ ffio_init_context(&pb, buf, len, 0, NULL, NULL, NULL, NULL); + + if (len < 4) + return AVERROR_INVALIDDATA; +@@ -97,27 +99,27 @@ + if (!is_start || !is_finish) { + av_log_missing_feature(s, "RTP-X-QT with payload description " + "split over several packets", 1); +- return AVERROR_NOTSUPP; ++ return AVERROR(ENOSYS); + } + skip_bits(&gb, 12); // reserved + data_len = get_bits(&gb, 16); + +- url_fseek(&pb, pos + 4, SEEK_SET); +- tag = get_le32(&pb); +- if ((st->codec->codec_type == CODEC_TYPE_VIDEO && ++ avio_seek(&pb, pos + 4, SEEK_SET); ++ tag = avio_rl32(&pb); ++ if ((st->codec->codec_type == AVMEDIA_TYPE_VIDEO && + tag != MKTAG('v','i','d','e')) || +- (st->codec->codec_type == CODEC_TYPE_AUDIO && ++ (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + tag != MKTAG('s','o','u','n'))) + return AVERROR_INVALIDDATA; +- av_set_pts_info(st, 32, 1, get_be32(&pb)); ++ avpriv_set_pts_info(st, 32, 1, avio_rb32(&pb)); + + if (pos + data_len > len) + return AVERROR_INVALIDDATA; + /* TLVs */ +- while (url_ftell(&pb) + 4 < pos + data_len) { +- int tlv_len = get_be16(&pb); +- tag = get_le16(&pb); +- if (url_ftell(&pb) + tlv_len > pos + data_len) ++ while (avio_tell(&pb) + 4 < pos + data_len) { ++ int tlv_len = avio_rb16(&pb); ++ tag = avio_rl16(&pb); ++ if (avio_tell(&pb) + tlv_len > pos + data_len) + return AVERROR_INVALIDDATA; + + #define MKTAG16(a,b) MKTAG(a,b,0,0) +@@ -148,22 +150,22 @@ + break; + } + default: +- url_fskip(&pb, tlv_len); ++ avio_skip(&pb, tlv_len); + break; + } + } + + /* 32-bit alignment */ +- url_fskip(&pb, ((url_ftell(&pb) + 3) & ~3) - url_ftell(&pb)); ++ avio_skip(&pb, ((avio_tell(&pb) + 3) & ~3) - avio_tell(&pb)); + } else +- url_fseek(&pb, 4, SEEK_SET); ++ avio_seek(&pb, 4, SEEK_SET); + + if (has_packet_info) { + av_log_missing_feature(s, "RTP-X-QT with packet specific info", 1); +- return AVERROR_NOTSUPP; ++ return AVERROR(ENOSYS); + } + +- alen = len - url_ftell(&pb); ++ alen = len - avio_tell(&pb); + if (alen <= 0) + return AVERROR_INVALIDDATA; + +@@ -181,7 +183,7 @@ + } + if (!qt->pkt.data) + return AVERROR(ENOMEM); +- memcpy(qt->pkt.data + qt->pkt.size, buf + url_ftell(&pb), alen); ++ memcpy(qt->pkt.data + qt->pkt.size, buf + avio_tell(&pb), alen); + qt->pkt.size += alen; + if (has_marker_bit) { + *pkt = qt->pkt; +@@ -202,7 +204,7 @@ + qt->remaining = (alen / qt->bytes_per_frame) - 1; + if (av_new_packet(pkt, qt->bytes_per_frame)) + return AVERROR(ENOMEM); +- memcpy(pkt->data, buf + url_ftell(&pb), qt->bytes_per_frame); ++ memcpy(pkt->data, buf + avio_tell(&pb), qt->bytes_per_frame); + pkt->flags = flags & RTP_FLAG_KEY ? AV_PKT_FLAG_KEY : 0; + pkt->stream_index = st->index; + if (qt->remaining > 0) { +@@ -214,7 +216,7 @@ + } + qt->pkt.size = qt->remaining * qt->bytes_per_frame; + memcpy(qt->pkt.data, +- buf + url_ftell(&pb) + qt->bytes_per_frame, ++ buf + avio_tell(&pb) + qt->bytes_per_frame, + qt->remaining * qt->bytes_per_frame); + qt->pkt.flags = pkt->flags; + return 1; +@@ -223,7 +225,7 @@ + + default: /* unimplemented */ + av_log_missing_feature(NULL, "RTP-X-QT with packing scheme 2", 1); +- return AVERROR_NOTSUPP; ++ return AVERROR(ENOSYS); + } + } + +@@ -243,12 +245,12 @@ + .enc_name = s, \ + .codec_type = t, \ + .codec_id = CODEC_ID_NONE, \ +- .open = qt_rtp_new, \ +- .close = qt_rtp_free, \ ++ .alloc = qt_rtp_new, \ ++ .free = qt_rtp_free, \ + .parse_packet = qt_rtp_parse_packet, \ +-}; ++} + +-RTP_QT_HANDLER(qt, vid, "X-QT", CODEC_TYPE_VIDEO); +-RTP_QT_HANDLER(qt, aud, "X-QT", CODEC_TYPE_AUDIO); +-RTP_QT_HANDLER(quicktime, vid, "X-QUICKTIME", CODEC_TYPE_VIDEO); +-RTP_QT_HANDLER(quicktime, aud, "X-QUICKTIME", CODEC_TYPE_AUDIO); ++RTP_QT_HANDLER(qt, vid, "X-QT", AVMEDIA_TYPE_VIDEO); ++RTP_QT_HANDLER(qt, aud, "X-QT", AVMEDIA_TYPE_AUDIO); ++RTP_QT_HANDLER(quicktime, vid, "X-QUICKTIME", AVMEDIA_TYPE_VIDEO); ++RTP_QT_HANDLER(quicktime, aud, "X-QUICKTIME", AVMEDIA_TYPE_AUDIO); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_svq3.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_svq3.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_svq3.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_svq3.c 2012-05-14 14:08:55.167356747 +0200 +@@ -22,8 +22,8 @@ + /** + * @file + * @brief RTP support for the SV3V (SVQ3) payload +- * (http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization) + * @author Ronald S. Bultje ++ * @see http://wiki.multimedia.cx/index.php?title=Sorenson_Video_3#Packetization + */ + + #include +@@ -33,7 +33,7 @@ + #include "rtpdec_formats.h" + + struct PayloadContext { +- ByteIOContext *pktbuf; ++ AVIOContext *pktbuf; + int64_t timestamp; + }; + +@@ -83,10 +83,10 @@ + + if (sv->pktbuf) { + uint8_t *tmp; +- url_close_dyn_buf(sv->pktbuf, &tmp); ++ avio_close_dyn_buf(sv->pktbuf, &tmp); + av_free(tmp); + } +- if ((res = url_open_dyn_buf(&sv->pktbuf)) < 0) ++ if ((res = avio_open_dyn_buf(&sv->pktbuf)) < 0) + return res; + sv->timestamp = *timestamp; + } +@@ -94,13 +94,13 @@ + if (!sv->pktbuf) + return AVERROR_INVALIDDATA; + +- put_buffer(sv->pktbuf, buf, len); ++ avio_write(sv->pktbuf, buf, len); + + if (end_packet) { + av_init_packet(pkt); + pkt->stream_index = st->index; + *timestamp = sv->timestamp; +- pkt->size = url_close_dyn_buf(sv->pktbuf, &pkt->data); ++ pkt->size = avio_close_dyn_buf(sv->pktbuf, &pkt->data); + pkt->destruct = av_destruct_packet; + sv->pktbuf = NULL; + return 0; +@@ -118,7 +118,7 @@ + { + if (sv->pktbuf) { + uint8_t *buf; +- url_close_dyn_buf(sv->pktbuf, &buf); ++ avio_close_dyn_buf(sv->pktbuf, &buf); + av_free(buf); + } + av_free(sv); +@@ -128,7 +128,7 @@ + .enc_name = "X-SV3V-ES", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_NONE, // see if (config_packet) above +- .open = svq3_extradata_new, +- .close = svq3_extradata_free, ++ .alloc = svq3_extradata_new, ++ .free = svq3_extradata_free, + .parse_packet = svq3_parse_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_vp8.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_vp8.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_vp8.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_vp8.c 2012-05-14 14:08:55.168356767 +0200 +@@ -23,7 +23,7 @@ + * @file + * @brief RTP support for the VP8 payload + * @author Josh Allmann +- * ( http://www.webmproject.org/code/specs/rtp/ ) ++ * @see http://www.webmproject.org/code/specs/rtp/ + */ + + #include "libavcodec/bytestream.h" +@@ -31,7 +31,7 @@ + #include "rtpdec_formats.h" + + struct PayloadContext { +- ByteIOContext *data; ++ AVIOContext *data; + uint32_t timestamp; + int is_keyframe; + }; +@@ -41,7 +41,7 @@ + av_init_packet(pkt); + pkt->stream_index = stream; + pkt->flags = vp8->is_keyframe ? AV_PKT_FLAG_KEY : 0; +- pkt->size = url_close_dyn_buf(vp8->data, &pkt->data); ++ pkt->size = avio_close_dyn_buf(vp8->data, &pkt->data); + pkt->destruct = av_destruct_packet; + vp8->data = NULL; + } +@@ -85,7 +85,7 @@ + // that for the next av_get_packet call + ret = end_packet ? 1 : 0; + } +- if ((res = url_open_dyn_buf(&vp8->data)) < 0) ++ if ((res = avio_open_dyn_buf(&vp8->data)) < 0) + return res; + vp8->is_keyframe = *buf & 1; + vp8->timestamp = ts; +@@ -111,7 +111,7 @@ + } + } + +- put_buffer(vp8->data, buf, au_len); ++ avio_write(vp8->data, buf, au_len); + buf += au_len; + len -= au_len; + } +@@ -138,7 +138,7 @@ + { + if (vp8->data) { + uint8_t *tmp; +- url_close_dyn_buf(vp8->data, &tmp); ++ avio_close_dyn_buf(vp8->data, &tmp); + av_free(tmp); + } + av_free(vp8); +@@ -148,7 +148,7 @@ + .enc_name = "VP8", + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_VP8, +- .open = vp8_new_context, +- .close = vp8_free_context, ++ .alloc = vp8_new_context, ++ .free = vp8_free_context, + .parse_packet = vp8_handle_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_xiph.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_xiph.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpdec_xiph.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpdec_xiph.c 2012-05-14 14:08:55.169356787 +0200 +@@ -42,7 +42,7 @@ + struct PayloadContext { + unsigned ident; ///< 24-bit stream configuration identifier + uint32_t timestamp; +- ByteIOContext* fragment; ///< buffer for split payloads ++ AVIOContext* fragment; ///< buffer for split payloads + uint8_t *split_buf; + int split_pos, split_buf_len, split_buf_size; + int split_pkts; +@@ -57,7 +57,7 @@ + { + if (data->fragment) { + uint8_t* p; +- url_close_dyn_buf(data->fragment, &p); ++ avio_close_dyn_buf(data->fragment, &p); + av_free(p); + data->fragment = NULL; + } +@@ -176,10 +176,10 @@ + // end packet has been lost somewhere, so drop buffered data + free_fragment_if_needed(data); + +- if((res = url_open_dyn_buf(&data->fragment)) < 0) ++ if((res = avio_open_dyn_buf(&data->fragment)) < 0) + return res; + +- put_buffer(data->fragment, buf, pkt_len); ++ avio_write(data->fragment, buf, pkt_len); + data->timestamp = *timestamp; + + } else { +@@ -198,12 +198,12 @@ + } + + // copy data to fragment buffer +- put_buffer(data->fragment, buf, pkt_len); ++ avio_write(data->fragment, buf, pkt_len); + + if (fragmented == 3) { + // end of xiph data packet + av_init_packet(pkt); +- pkt->size = url_close_dyn_buf(data->fragment, &pkt->data); ++ pkt->size = avio_close_dyn_buf(data->fragment, &pkt->data); + + if (pkt->size < 0) { + av_log(ctx, AV_LOG_ERROR, +@@ -389,8 +389,8 @@ + .codec_type = AVMEDIA_TYPE_VIDEO, + .codec_id = CODEC_ID_THEORA, + .parse_sdp_a_line = xiph_parse_sdp_line, +- .open = xiph_new_context, +- .close = xiph_free_context, ++ .alloc = xiph_new_context, ++ .free = xiph_free_context, + .parse_packet = xiph_handle_packet + }; + +@@ -399,7 +399,7 @@ + .codec_type = AVMEDIA_TYPE_AUDIO, + .codec_id = CODEC_ID_VORBIS, + .parse_sdp_a_line = xiph_parse_sdp_line, +- .open = xiph_new_context, +- .close = xiph_free_context, ++ .alloc = xiph_new_context, ++ .free = xiph_free_context, + .parse_packet = xiph_handle_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc.c 2012-05-14 14:08:55.171356827 +0200 +@@ -22,12 +22,27 @@ + #include "avformat.h" + #include "mpegts.h" + #include "internal.h" ++#include "libavutil/mathematics.h" + #include "libavutil/random_seed.h" ++#include "libavutil/opt.h" + + #include "rtpenc.h" + + //#define DEBUG + ++static const AVOption options[] = { ++ FF_RTP_FLAG_OPTS(RTPMuxContext, flags), ++ { "payload_type", "Specify RTP payload type", offsetof(RTPMuxContext, payload_type), AV_OPT_TYPE_INT, {.dbl = -1 }, -1, 127, AV_OPT_FLAG_ENCODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass rtp_muxer_class = { ++ .class_name = "RTP muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + #define RTCP_SR_SIZE 28 + + static int is_supported(enum CodecID id) +@@ -57,6 +72,7 @@ + case CODEC_ID_THEORA: + case CODEC_ID_VP8: + case CODEC_ID_ADPCM_G722: ++ case CODEC_ID_ADPCM_G726: + return 1; + default: + return 0; +@@ -73,15 +89,13 @@ + return -1; + st = s1->streams[0]; + if (!is_supported(st->codec->codec_id)) { +- av_log(s1, AV_LOG_ERROR, "Unsupported codec %x\n", st->codec->codec_id); ++ av_log(s1, AV_LOG_ERROR, "Unsupported codec %s\n", avcodec_get_name(st->codec->codec_id)); + + return -1; + } + +- s->payload_type = ff_rtp_get_payload_type(st->codec); + if (s->payload_type < 0) +- s->payload_type = RTP_PT_PRIVATE + (st->codec->codec_type == AVMEDIA_TYPE_AUDIO); +- ++ s->payload_type = ff_rtp_get_payload_type(s1, st->codec); + s->base_timestamp = av_get_random_seed(); + s->timestamp = s->base_timestamp; + s->cur_timestamp = 0; +@@ -93,7 +107,7 @@ + s->first_rtcp_ntp_time = (s1->start_time_realtime / 1000) * 1000 + + NTP_OFFSET_US; + +- max_packet_size = url_fget_max_packet_size(s1->pb); ++ max_packet_size = s1->pb->max_packet_size; + if (max_packet_size <= 12) + return AVERROR(EIO); + s->buf = av_malloc(max_packet_size); +@@ -108,7 +122,7 @@ + if (st->codec->frame_size == 0) { + av_log(s1, AV_LOG_ERROR, "Cannot respect max delay: frame size = 0\n"); + } else { +- s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * st->codec->frame_size, AV_ROUND_DOWN); ++ s->max_frames_per_packet = av_rescale_rnd(s1->max_delay, st->codec->sample_rate, AV_TIME_BASE * (int64_t)st->codec->frame_size, AV_ROUND_DOWN); + } + } + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +@@ -117,7 +131,7 @@ + } + } + +- av_set_pts_info(st, 32, 1, 90000); ++ avpriv_set_pts_info(st, 32, 1, 90000); + switch(st->codec->codec_id) { + case CODEC_ID_MP2: + case CODEC_ID_MP3: +@@ -153,7 +167,7 @@ + case CODEC_ID_ADPCM_G722: + /* Due to a historical error, the clock rate for G722 in RTP is + * 8000, even if the sample rate is 16000. See RFC 3551. */ +- av_set_pts_info(st, 32, 1, 8000); ++ avpriv_set_pts_info(st, 32, 1, 8000); + break; + case CODEC_ID_AMR_NB: + case CODEC_ID_AMR_WB: +@@ -177,7 +191,7 @@ + default: + defaultcase: + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { +- av_set_pts_info(st, 32, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + } + s->buf_ptr = s->buf; + break; +@@ -197,16 +211,16 @@ + s->last_rtcp_ntp_time = ntp_time; + rtp_ts = av_rescale_q(ntp_time - s->first_rtcp_ntp_time, (AVRational){1, 1000000}, + s1->streams[0]->time_base) + s->base_timestamp; +- put_byte(s1->pb, (RTP_VERSION << 6)); +- put_byte(s1->pb, RTCP_SR); +- put_be16(s1->pb, 6); /* length in words - 1 */ +- put_be32(s1->pb, s->ssrc); +- put_be32(s1->pb, ntp_time / 1000000); +- put_be32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000); +- put_be32(s1->pb, rtp_ts); +- put_be32(s1->pb, s->packet_count); +- put_be32(s1->pb, s->octet_count); +- put_flush_packet(s1->pb); ++ avio_w8(s1->pb, (RTP_VERSION << 6)); ++ avio_w8(s1->pb, RTCP_SR); ++ avio_wb16(s1->pb, 6); /* length in words - 1 */ ++ avio_wb32(s1->pb, s->ssrc); ++ avio_wb32(s1->pb, ntp_time / 1000000); ++ avio_wb32(s1->pb, ((ntp_time % 1000000) << 32) / 1000000); ++ avio_wb32(s1->pb, rtp_ts); ++ avio_wb32(s1->pb, s->packet_count); ++ avio_wb32(s1->pb, s->octet_count); ++ avio_flush(s1->pb); + } + + /* send an rtp packet. sequence number is incremented, but the caller +@@ -218,14 +232,14 @@ + av_dlog(s1, "rtp_send_data size=%d\n", len); + + /* build the RTP header */ +- put_byte(s1->pb, (RTP_VERSION << 6)); +- put_byte(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7)); +- put_be16(s1->pb, s->seq); +- put_be32(s1->pb, s->timestamp); +- put_be32(s1->pb, s->ssrc); ++ avio_w8(s1->pb, (RTP_VERSION << 6)); ++ avio_w8(s1->pb, (s->payload_type & 0x7f) | ((m & 0x01) << 7)); ++ avio_wb16(s1->pb, s->seq); ++ avio_wb32(s1->pb, s->timestamp); ++ avio_wb32(s1->pb, s->ssrc); + +- put_buffer(s1->pb, buf1, len); +- put_flush_packet(s1->pb); ++ avio_write(s1->pb, buf1, len); ++ avio_flush(s1->pb); + + s->seq++; + s->octet_count += len; +@@ -235,14 +249,16 @@ + /* send an integer number of samples and compute time stamp and fill + the rtp send buffer before sending. */ + static void rtp_send_samples(AVFormatContext *s1, +- const uint8_t *buf1, int size, int sample_size) ++ const uint8_t *buf1, int size, int sample_size_bits) + { + RTPMuxContext *s = s1->priv_data; + int len, max_packet_size, n; ++ /* Calculate the number of bytes to get samples aligned on a byte border */ ++ int aligned_samples_size = sample_size_bits/av_gcd(sample_size_bits, 8); + +- max_packet_size = (s->max_payload_size / sample_size) * sample_size; +- /* not needed, but who nows */ +- if ((size % sample_size) != 0) ++ max_packet_size = (s->max_payload_size / aligned_samples_size) * aligned_samples_size; ++ /* Not needed, but who knows. Don't check if samples aren't an even number of bytes. */ ++ if ((sample_size_bits % 8) == 0 && ((8 * size) % sample_size_bits) != 0) + av_abort(); + n = 0; + while (size > 0) { +@@ -254,7 +270,7 @@ + s->buf_ptr += len; + buf1 += len; + size -= len; +- s->timestamp = s->cur_timestamp + n / sample_size; ++ s->timestamp = s->cur_timestamp + n * 8 / sample_size_bits; + ff_rtp_send_data(s1, s->buf, s->buf_ptr - s->buf, 0); + n += (s->buf_ptr - s->buf); + } +@@ -381,19 +397,24 @@ + case CODEC_ID_PCM_ALAW: + case CODEC_ID_PCM_U8: + case CODEC_ID_PCM_S8: +- rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); ++ rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); + break; + case CODEC_ID_PCM_U16BE: + case CODEC_ID_PCM_U16LE: + case CODEC_ID_PCM_S16BE: + case CODEC_ID_PCM_S16LE: +- rtp_send_samples(s1, pkt->data, size, 2 * st->codec->channels); ++ rtp_send_samples(s1, pkt->data, size, 16 * st->codec->channels); + break; + case CODEC_ID_ADPCM_G722: + /* The actual sample size is half a byte per sample, but since the + * stream clock rate is 8000 Hz while the sample rate is 16000 Hz, +- * the correct parameter for send_samples is 1 byte per stream clock. */ +- rtp_send_samples(s1, pkt->data, size, 1 * st->codec->channels); ++ * the correct parameter for send_samples_bits is 8 bits per stream ++ * clock. */ ++ rtp_send_samples(s1, pkt->data, size, 8 * st->codec->channels); ++ break; ++ case CODEC_ID_ADPCM_G726: ++ rtp_send_samples(s1, pkt->data, size, ++ st->codec->bits_per_coded_sample * st->codec->channels); + break; + case CODEC_ID_MP2: + case CODEC_ID_MP3: +@@ -404,7 +425,10 @@ + ff_rtp_send_mpegvideo(s1, pkt->data, size); + break; + case CODEC_ID_AAC: +- ff_rtp_send_aac(s1, pkt->data, size); ++ if (s->flags & FF_RTP_FLAG_MP4A_LATM) ++ ff_rtp_send_latm(s1, pkt->data, size); ++ else ++ ff_rtp_send_aac(s1, pkt->data, size); + break; + case CODEC_ID_AMR_NB: + case CODEC_ID_AMR_WB: +@@ -445,14 +469,13 @@ + } + + AVOutputFormat ff_rtp_muxer = { +- "rtp", +- NULL_IF_CONFIG_SMALL("RTP output format"), +- NULL, +- NULL, +- sizeof(RTPMuxContext), +- CODEC_ID_PCM_MULAW, +- CODEC_ID_NONE, +- rtp_write_header, +- rtp_write_packet, +- rtp_write_trailer, ++ .name = "rtp", ++ .long_name = NULL_IF_CONFIG_SMALL("RTP output format"), ++ .priv_data_size = sizeof(RTPMuxContext), ++ .audio_codec = CODEC_ID_PCM_MULAW, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = rtp_write_header, ++ .write_packet = rtp_write_packet, ++ .write_trailer = rtp_write_trailer, ++ .priv_class = &rtp_muxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_chain.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_chain.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_chain.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_chain.c 2012-05-14 14:08:55.172356847 +0200 +@@ -20,7 +20,10 @@ + */ + + #include "avformat.h" ++#include "avio_internal.h" + #include "rtpenc_chain.h" ++#include "avio_internal.h" ++#include "libavutil/opt.h" + + AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, + URLContext *handle, int packet_size) +@@ -28,6 +31,8 @@ + AVFormatContext *rtpctx; + int ret; + AVOutputFormat *rtp_format = av_guess_format("rtp", NULL, NULL); ++ uint8_t *rtpflags; ++ AVDictionary *opts = NULL; + + if (!rtp_format) + return NULL; +@@ -38,45 +43,45 @@ + return NULL; + + rtpctx->oformat = rtp_format; +- if (!av_new_stream(rtpctx, 0)) { ++ if (!avformat_new_stream(rtpctx, NULL)) { + av_free(rtpctx); + return NULL; + } ++ /* Pass the interrupt callback on */ ++ rtpctx->interrupt_callback = s->interrupt_callback; + /* Copy the max delay setting; the rtp muxer reads this. */ + rtpctx->max_delay = s->max_delay; + /* Copy other stream parameters. */ + rtpctx->streams[0]->sample_aspect_ratio = st->sample_aspect_ratio; ++ rtpctx->flags |= s->flags & AVFMT_FLAG_MP4A_LATM; ++ ++ if (av_opt_get(s, "rtpflags", AV_OPT_SEARCH_CHILDREN, &rtpflags) >= 0) ++ av_dict_set(&opts, "rtpflags", rtpflags, AV_DICT_DONT_STRDUP_VAL); + + /* Set the synchronized start time. */ + rtpctx->start_time_realtime = s->start_time_realtime; + +- /* Remove the local codec, link to the original codec +- * context instead, to give the rtp muxer access to +- * codec parameters. */ +- av_free(rtpctx->streams[0]->codec); +- rtpctx->streams[0]->codec = st->codec; ++ avcodec_copy_context(rtpctx->streams[0]->codec, st->codec); + + if (handle) { +- url_fdopen(&rtpctx->pb, handle); ++ ffio_fdopen(&rtpctx->pb, handle); + } else +- url_open_dyn_packet_buf(&rtpctx->pb, packet_size); +- ret = av_write_header(rtpctx); ++ ffio_open_dyn_packet_buf(&rtpctx->pb, packet_size); ++ ret = avformat_write_header(rtpctx, &opts); ++ av_dict_free(&opts); + + if (ret) { + if (handle) { +- url_fclose(rtpctx->pb); ++ avio_close(rtpctx->pb); + } else { + uint8_t *ptr; +- url_close_dyn_buf(rtpctx->pb, &ptr); ++ avio_close_dyn_buf(rtpctx->pb, &ptr); + av_free(ptr); + } +- av_free(rtpctx->streams[0]); +- av_free(rtpctx); ++ avformat_free_context(rtpctx); + return NULL; + } + +- /* Copy the RTP AVStream timebase back to the original AVStream */ +- st->time_base = rtpctx->streams[0]->time_base; + return rtpctx; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_chain.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_chain.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_chain.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_chain.h 2012-05-14 14:08:55.173356867 +0200 +@@ -23,6 +23,7 @@ + #define AVFORMAT_RTPENC_CHAIN_H + + #include "avformat.h" ++#include "url.h" + + AVFormatContext *ff_rtp_chain_mux_open(AVFormatContext *s, AVStream *st, + URLContext *handle, int packet_size); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc.h 2012-05-14 14:08:55.171356827 +0200 +@@ -25,6 +25,7 @@ + #include "rtp.h" + + struct RTPMuxContext { ++ const AVClass *av_class; + AVFormatContext *ic; + AVStream *st; + int payload_type; +@@ -56,15 +57,24 @@ + * (1, 2 or 4) + */ + int nal_length_size; ++ ++ int flags; + }; + + typedef struct RTPMuxContext RTPMuxContext; + ++#define FF_RTP_FLAG_MP4A_LATM 1 ++ ++#define FF_RTP_FLAG_OPTS(ctx, fieldname) \ ++ { "rtpflags", "RTP muxer flags", offsetof(ctx, fieldname), AV_OPT_TYPE_FLAGS, {.dbl = 0}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" }, \ ++ { "latm", "Use MP4A-LATM packetization instead of MPEG4-GENERIC for AAC", 0, AV_OPT_TYPE_CONST, {.dbl = FF_RTP_FLAG_MP4A_LATM}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "rtpflags" } \ ++ + void ff_rtp_send_data(AVFormatContext *s1, const uint8_t *buf1, int len, int m); + + void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size); + void ff_rtp_send_h263(AVFormatContext *s1, const uint8_t *buf1, int size); + void ff_rtp_send_aac(AVFormatContext *s1, const uint8_t *buff, int size); ++void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size); + void ff_rtp_send_amr(AVFormatContext *s1, const uint8_t *buff, int size); + void ff_rtp_send_mpegvideo(AVFormatContext *s1, const uint8_t *buf1, int size); + void ff_rtp_send_xiph(AVFormatContext *s1, const uint8_t *buff, int size); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_h264.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_h264.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_h264.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_h264.c 2012-05-14 14:08:55.173356867 +0200 +@@ -29,6 +29,21 @@ + #include "avc.h" + #include "rtpenc.h" + ++static const uint8_t *avc_mp4_find_startcode(const uint8_t *start, const uint8_t *end, int nal_length_size) ++{ ++ int res = 0; ++ ++ if (end - start < nal_length_size) ++ return NULL; ++ while (nal_length_size--) ++ res = (res << 8) | *start++; ++ ++ if (start + res > end || res < 0 || start + res < start) ++ return NULL; ++ ++ return start + res; ++} ++ + static void nal_send(AVFormatContext *s1, const uint8_t *buf, int size, int last) + { + RTPMuxContext *s = s1->priv_data; +@@ -62,17 +77,27 @@ + + void ff_rtp_send_h264(AVFormatContext *s1, const uint8_t *buf1, int size) + { +- const uint8_t *r; ++ const uint8_t *r, *end = buf1 + size; + RTPMuxContext *s = s1->priv_data; + + s->timestamp = s->cur_timestamp; +- r = ff_avc_find_startcode(buf1, buf1 + size); +- while (r < buf1 + size) { ++ if (s->nal_length_size) ++ r = avc_mp4_find_startcode(buf1, end, s->nal_length_size) ? buf1 : end; ++ else ++ r = ff_avc_find_startcode(buf1, end); ++ while (r < end) { + const uint8_t *r1; + +- while(!*(r++)); +- r1 = ff_avc_find_startcode(r, buf1 + size); +- nal_send(s1, r, r1 - r, (r1 == buf1 + size)); ++ if (s->nal_length_size) { ++ r1 = avc_mp4_find_startcode(r, end, s->nal_length_size); ++ if (!r1) ++ r1 = end; ++ r += s->nal_length_size; ++ } else { ++ while (!*(r++)); ++ r1 = ff_avc_find_startcode(r, end); ++ } ++ nal_send(s1, r, r1 - r, r1 == end); + r = r1; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_latm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_latm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_latm.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_latm.c 2012-05-14 14:08:55.174356887 +0200 +@@ -0,0 +1,61 @@ ++/* ++ * RTP Packetization of MPEG-4 Audio (RFC 3016) ++ * Copyright (c) 2011 Juan Carlos Rodriguez ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "rtpenc.h" ++ ++void ff_rtp_send_latm(AVFormatContext *s1, const uint8_t *buff, int size) ++{ ++ /* MP4A-LATM ++ * The RTP payload format specification is described in RFC 3016 ++ * The encoding specifications are provided in ISO/IEC 14496-3 */ ++ ++ RTPMuxContext *s = s1->priv_data; ++ int header_size; ++ int offset = 0; ++ int len = 0; ++ ++ /* skip ADTS header, if present */ ++ if ((s1->streams[0]->codec->extradata_size) == 0) { ++ size -= 7; ++ buff += 7; ++ } ++ ++ /* PayloadLengthInfo() */ ++ header_size = size/0xFF + 1; ++ memset(s->buf, 0xFF, header_size - 1); ++ s->buf[header_size - 1] = size % 0xFF; ++ ++ s->timestamp = s->cur_timestamp; ++ ++ /* PayloadMux() */ ++ while (size > 0) { ++ len = FFMIN(size, s->max_payload_size - (!offset ? header_size : 0)); ++ size -= len; ++ if (!offset) { ++ memcpy(s->buf + header_size, buff, len); ++ ff_rtp_send_data(s1, s->buf, header_size + len, !size); ++ } else { ++ ff_rtp_send_data(s1, buff + offset, len, !size); ++ } ++ offset += len; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_mpv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_mpv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpenc_mpv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpenc_mpv.c 2012-05-14 14:08:55.174356887 +0200 +@@ -56,7 +56,7 @@ + r1 = buf1; + while (1) { + start_code = -1; +- r = ff_find_start_code(r1, end, &start_code); ++ r = avpriv_mpv_find_start_code(r1, end, &start_code); + if((start_code & 0xFFFFFF00) == 0x100) { + /* New start code found */ + if (start_code == 0x100) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtp.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtp.h 2012-05-14 14:08:55.156356525 +0200 +@@ -21,17 +21,17 @@ + #ifndef AVFORMAT_RTP_H + #define AVFORMAT_RTP_H + ++#include "libavformat/avformat.h" + #include "libavcodec/avcodec.h" + + /** +- * Return the payload type for a given codec. ++ * Return the payload type for a given codec used in the given format context. + * ++ * @param fmt The context of the format + * @param codec The context of the codec +- * @return In case of unknown payload type or dynamic payload type, a +- * negative value is returned; otherwise, the payload type (the 'PT' field +- * in the RTP header) is returned. ++ * @return The payload type (the 'PT' field in the RTP header). + */ +-int ff_rtp_get_payload_type(AVCodecContext *codec); ++int ff_rtp_get_payload_type(AVFormatContext *fmt, AVCodecContext *codec); + + /** + * Initialize a codec context based on the payload type. +@@ -72,7 +72,7 @@ + #define RTP_VERSION 2 + #define RTP_MAX_SDES 256 /**< maximum text length for SDES */ + +-/* RTCP paquets use 0.5 % of the bandwidth */ ++/* RTCP packets use 0.5% of the bandwidth */ + #define RTCP_TX_RATIO_NUM 5 + #define RTCP_TX_RATIO_DEN 1000 + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpproto.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpproto.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtpproto.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtpproto.c 2012-05-14 14:08:55.176356928 +0200 +@@ -24,9 +24,12 @@ + * RTP protocol + */ + ++#include "libavutil/parseutils.h" + #include "libavutil/avstring.h" + #include "avformat.h" ++#include "avio_internal.h" + #include "rtpdec.h" ++#include "url.h" + + #include + #include +@@ -57,7 +60,7 @@ + * @return zero if no error. + */ + +-int rtp_set_remote_url(URLContext *h, const char *uri) ++int ff_rtp_set_remote_url(URLContext *h, const char *uri) + { + RTPContext *s = h->priv_data; + char hostname[256]; +@@ -70,10 +73,10 @@ + path, sizeof(path), uri); + + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port, "%s", path); +- udp_set_remote_url(s->rtp_hd, buf); ++ ff_udp_set_remote_url(s->rtp_hd, buf); + + ff_url_join(buf, sizeof(buf), "udp", NULL, hostname, port + 1, "%s", path); +- udp_set_remote_url(s->rtcp_hd, buf); ++ ff_udp_set_remote_url(s->rtcp_hd, buf); + return 0; + } + +@@ -83,7 +86,7 @@ + * "http://host:port/path?option1=val1&option2=val2... + */ + +-static void url_add_option(char *buf, int buf_size, const char *fmt, ...) ++static av_printf_format(3, 4) void url_add_option(char *buf, int buf_size, const char *fmt, ...) + { + char buf1[1024]; + va_list ap; +@@ -112,6 +115,7 @@ + url_add_option(buf, buf_size, "pkt_size=%d", max_packet_size); + if (connect) + url_add_option(buf, buf_size, "connect=1"); ++ url_add_option(buf, buf_size, "fifo_size=0"); + } + + /** +@@ -133,22 +137,15 @@ + + static int rtp_open(URLContext *h, const char *uri, int flags) + { +- RTPContext *s; ++ RTPContext *s = h->priv_data; + int rtp_port, rtcp_port, +- is_output, ttl, connect, ++ ttl, connect, + local_rtp_port, local_rtcp_port, max_packet_size; + char hostname[256]; + char buf[1024]; + char path[1024]; + const char *p; + +- is_output = (flags & URL_WRONLY); +- +- s = av_mallocz(sizeof(RTPContext)); +- if (!s) +- return AVERROR(ENOMEM); +- h->priv_data = s; +- + av_url_split(NULL, 0, NULL, 0, hostname, sizeof(hostname), &rtp_port, + path, sizeof(path), uri); + /* extract parameters */ +@@ -161,25 +158,25 @@ + + p = strchr(uri, '?'); + if (p) { +- if (find_info_tag(buf, sizeof(buf), "ttl", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { + ttl = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "rtcpport", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "rtcpport", p)) { + rtcp_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "localport", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { + local_rtp_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "localrtpport", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "localrtpport", p)) { + local_rtp_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "localrtcpport", p)) { + local_rtcp_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { + max_packet_size = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "connect", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { + connect = strtol(buf, NULL, 10); + } + } +@@ -187,32 +184,31 @@ + build_udp_url(buf, sizeof(buf), + hostname, rtp_port, local_rtp_port, ttl, max_packet_size, + connect); +- if (url_open(&s->rtp_hd, buf, flags) < 0) ++ if (ffurl_open(&s->rtp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) + goto fail; + if (local_rtp_port>=0 && local_rtcp_port<0) +- local_rtcp_port = udp_get_local_port(s->rtp_hd) + 1; ++ local_rtcp_port = ff_udp_get_local_port(s->rtp_hd) + 1; + + build_udp_url(buf, sizeof(buf), + hostname, rtcp_port, local_rtcp_port, ttl, max_packet_size, + connect); +- if (url_open(&s->rtcp_hd, buf, flags) < 0) ++ if (ffurl_open(&s->rtcp_hd, buf, flags, &h->interrupt_callback, NULL) < 0) + goto fail; + + /* just to ease handle access. XXX: need to suppress direct handle + access */ +- s->rtp_fd = url_get_file_handle(s->rtp_hd); +- s->rtcp_fd = url_get_file_handle(s->rtcp_hd); ++ s->rtp_fd = ffurl_get_file_handle(s->rtp_hd); ++ s->rtcp_fd = ffurl_get_file_handle(s->rtcp_hd); + +- h->max_packet_size = url_get_max_packet_size(s->rtp_hd); ++ h->max_packet_size = s->rtp_hd->max_packet_size; + h->is_streamed = 1; + return 0; + + fail: + if (s->rtp_hd) +- url_close(s->rtp_hd); ++ ffurl_close(s->rtp_hd); + if (s->rtcp_hd) +- url_close(s->rtcp_hd); +- av_free(s); ++ ffurl_close(s->rtcp_hd); + return AVERROR(EIO); + } + +@@ -224,23 +220,9 @@ + int len, n; + struct pollfd p[2] = {{s->rtp_fd, POLLIN, 0}, {s->rtcp_fd, POLLIN, 0}}; + +-#if 0 + for(;;) { +- from_len = sizeof(from); +- len = recvfrom (s->rtp_fd, buf, size, 0, +- (struct sockaddr *)&from, &from_len); +- if (len < 0) { +- if (ff_neterrno() == FF_NETERROR(EAGAIN) || +- ff_neterrno() == FF_NETERROR(EINTR)) +- continue; +- return AVERROR(EIO); +- } +- break; +- } +-#else +- for(;;) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); ++ if (ff_check_interrupt(&h->interrupt_callback)) ++ return AVERROR_EXIT; + /* build fdset to listen to RTP and RTCP packets */ + n = poll(p, 2, 100); + if (n > 0) { +@@ -250,8 +232,8 @@ + len = recvfrom (s->rtcp_fd, buf, size, 0, + (struct sockaddr *)&from, &from_len); + if (len < 0) { +- if (ff_neterrno() == FF_NETERROR(EAGAIN) || +- ff_neterrno() == FF_NETERROR(EINTR)) ++ if (ff_neterrno() == AVERROR(EAGAIN) || ++ ff_neterrno() == AVERROR(EINTR)) + continue; + return AVERROR(EIO); + } +@@ -263,20 +245,19 @@ + len = recvfrom (s->rtp_fd, buf, size, 0, + (struct sockaddr *)&from, &from_len); + if (len < 0) { +- if (ff_neterrno() == FF_NETERROR(EAGAIN) || +- ff_neterrno() == FF_NETERROR(EINTR)) ++ if (ff_neterrno() == AVERROR(EAGAIN) || ++ ff_neterrno() == AVERROR(EINTR)) + continue; + return AVERROR(EIO); + } + break; + } + } else if (n < 0) { +- if (ff_neterrno() == FF_NETERROR(EINTR)) ++ if (ff_neterrno() == AVERROR(EINTR)) + continue; + return AVERROR(EIO); + } + } +-#endif + return len; + } + +@@ -294,15 +275,7 @@ + hd = s->rtp_hd; + } + +- ret = url_write(hd, buf, size); +-#if 0 +- { +- struct timespec ts; +- ts.tv_sec = 0; +- ts.tv_nsec = 10 * 1000000; +- nanosleep(&ts, NULL); +- } +-#endif ++ ret = ffurl_write(hd, buf, size); + return ret; + } + +@@ -310,9 +283,8 @@ + { + RTPContext *s = h->priv_data; + +- url_close(s->rtp_hd); +- url_close(s->rtcp_hd); +- av_free(s); ++ ffurl_close(s->rtp_hd); ++ ffurl_close(s->rtcp_hd); + return 0; + } + +@@ -322,10 +294,10 @@ + * @return the local port number + */ + +-int rtp_get_local_rtp_port(URLContext *h) ++int ff_rtp_get_local_rtp_port(URLContext *h) + { + RTPContext *s = h->priv_data; +- return udp_get_local_port(s->rtp_hd); ++ return ff_udp_get_local_port(s->rtp_hd); + } + + /** +@@ -334,10 +306,10 @@ + * @return the local port number + */ + +-int rtp_get_local_rtcp_port(URLContext *h) ++int ff_rtp_get_local_rtcp_port(URLContext *h) + { + RTPContext *s = h->priv_data; +- return udp_get_local_port(s->rtcp_hd); ++ return ff_udp_get_local_port(s->rtcp_hd); + } + + static int rtp_get_file_handle(URLContext *h) +@@ -346,17 +318,18 @@ + return s->rtp_fd; + } + +-int rtp_get_rtcp_file_handle(URLContext *h) { ++int ff_rtp_get_rtcp_file_handle(URLContext *h) { + RTPContext *s = h->priv_data; + return s->rtcp_fd; + } + + URLProtocol ff_rtp_protocol = { +- "rtp", +- rtp_open, +- rtp_read, +- rtp_write, +- NULL, /* seek */ +- rtp_close, ++ .name = "rtp", ++ .url_open = rtp_open, ++ .url_read = rtp_read, ++ .url_write = rtp_write, ++ .url_close = rtp_close, + .url_get_file_handle = rtp_get_file_handle, ++ .priv_data_size = sizeof(RTPContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtsp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtsp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtsp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtsp.c 2012-05-14 14:08:55.180357009 +0200 +@@ -22,14 +22,18 @@ + #include "libavutil/base64.h" + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/parseutils.h" + #include "libavutil/random_seed.h" ++#include "libavutil/dict.h" ++#include "libavutil/opt.h" + #include "avformat.h" ++#include "avio_internal.h" + + #include + #if HAVE_POLL_H + #include + #endif +-#include + #include "internal.h" + #include "network.h" + #include "os_support.h" +@@ -40,9 +44,10 @@ + #include "rdt.h" + #include "rtpdec_formats.h" + #include "rtpenc_chain.h" ++#include "url.h" ++#include "rtpenc.h" + + //#define DEBUG +-//#define DEBUG_RTP_TCP + + /* Timeout values for socket poll, in ms, + * and read_packet(), in seconds */ +@@ -52,6 +57,46 @@ + #define SDP_MAX_SIZE 16384 + #define RECVBUF_SIZE 10 * RTP_MAX_PACKET_LENGTH + ++#define OFFSET(x) offsetof(RTSPState, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++#define ENC AV_OPT_FLAG_ENCODING_PARAM ++ ++#define RTSP_FLAG_OPTS(name, longname) \ ++ { name, longname, OFFSET(rtsp_flags), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC, "rtsp_flags" }, \ ++ { "filter_src", "Only receive packets from the negotiated peer IP", 0, AV_OPT_TYPE_CONST, {RTSP_FLAG_FILTER_SRC}, 0, 0, DEC, "rtsp_flags" } ++ ++#define RTSP_MEDIATYPE_OPTS(name, longname) \ ++ { name, longname, OFFSET(media_type_mask), AV_OPT_TYPE_FLAGS, { (1 << (AVMEDIA_TYPE_DATA+1)) - 1 }, INT_MIN, INT_MAX, DEC, "allowed_media_types" }, \ ++ { "video", "Video", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_VIDEO}, 0, 0, DEC, "allowed_media_types" }, \ ++ { "audio", "Audio", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_AUDIO}, 0, 0, DEC, "allowed_media_types" }, \ ++ { "data", "Data", 0, AV_OPT_TYPE_CONST, {1 << AVMEDIA_TYPE_DATA}, 0, 0, DEC, "allowed_media_types" } ++ ++const AVOption ff_rtsp_options[] = { ++ { "initial_pause", "Don't start playing the stream immediately", OFFSET(initial_pause), AV_OPT_TYPE_INT, {0}, 0, 1, DEC }, ++ FF_RTP_FLAG_OPTS(RTSPState, rtp_muxer_flags), ++ { "rtsp_transport", "RTSP transport protocols", OFFSET(lower_transport_mask), AV_OPT_TYPE_FLAGS, {0}, INT_MIN, INT_MAX, DEC|ENC, "rtsp_transport" }, \ ++ { "udp", "UDP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP}, 0, 0, DEC|ENC, "rtsp_transport" }, \ ++ { "tcp", "TCP", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_TCP}, 0, 0, DEC|ENC, "rtsp_transport" }, \ ++ { "udp_multicast", "UDP multicast", 0, AV_OPT_TYPE_CONST, {1 << RTSP_LOWER_TRANSPORT_UDP_MULTICAST}, 0, 0, DEC, "rtsp_transport" }, ++ { "http", "HTTP tunneling", 0, AV_OPT_TYPE_CONST, {(1 << RTSP_LOWER_TRANSPORT_HTTP)}, 0, 0, DEC, "rtsp_transport" }, ++ RTSP_FLAG_OPTS("rtsp_flags", "RTSP flags"), ++ RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"), ++ { "min_port", "Minimum local UDP port", OFFSET(rtp_port_min), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MIN}, 0, 65535, DEC|ENC }, ++ { "max_port", "Maximum local UDP port", OFFSET(rtp_port_max), AV_OPT_TYPE_INT, {RTSP_RTP_PORT_MAX}, 0, 65535, DEC|ENC }, ++ { NULL }, ++}; ++ ++static const AVOption sdp_options[] = { ++ RTSP_FLAG_OPTS("sdp_flags", "SDP flags"), ++ RTSP_MEDIATYPE_OPTS("allowed_media_types", "Media types to accept from the server"), ++ { NULL }, ++}; ++ ++static const AVOption rtp_options[] = { ++ RTSP_FLAG_OPTS("rtp_flags", "RTP flags"), ++ { NULL }, ++}; ++ + static void get_word_until_chars(char *buf, int buf_size, + const char *sep, const char **pp) + { +@@ -99,11 +144,11 @@ + *end = AV_NOPTS_VALUE; + + get_word_sep(buf, sizeof(buf), "-", &p); +- *start = parse_date(buf, 1); ++ av_parse_time(start, buf, 1); + if (*p == '-') { + p++; + get_word_sep(buf, sizeof(buf), "-", &p); +- *end = parse_date(buf, 1); ++ av_parse_time(end, buf, 1); + } + // av_log(NULL, AV_LOG_DEBUG, "Range Start: %lld\n", *start); + // av_log(NULL, AV_LOG_DEBUG, "Range End: %lld\n", *end); +@@ -129,8 +174,11 @@ + return; + codec->codec_id = handler->codec_id; + rtsp_st->dynamic_handler = handler; +- if (handler->open) +- rtsp_st->dynamic_protocol_context = handler->open(); ++ if (handler->alloc) { ++ rtsp_st->dynamic_protocol_context = handler->alloc(); ++ if (!rtsp_st->dynamic_protocol_context) ++ rtsp_st->dynamic_handler = NULL; ++ } + } + + /* parse the rtpmap description: /[/] */ +@@ -182,7 +230,7 @@ + codec->channels = RTSP_DEFAULT_NB_AUDIO_CHANNELS; + if (i > 0) { + codec->sample_rate = i; +- av_set_pts_info(st, 32, 1, codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1, codec->sample_rate); + get_word_sep(buf, sizeof(buf), "/", &p); + i = atoi(buf); + if (i > 0) +@@ -200,11 +248,14 @@ + case AVMEDIA_TYPE_VIDEO: + av_log(s, AV_LOG_DEBUG, "video codec set to: %s\n", c_name); + if (i > 0) +- av_set_pts_info(st, 32, 1, i); ++ avpriv_set_pts_info(st, 32, 1, i); + break; + default: + break; + } ++ if (rtsp_st->dynamic_handler && rtsp_st->dynamic_handler->init) ++ rtsp_st->dynamic_handler->init(s, st->index, ++ rtsp_st->dynamic_protocol_context); + return 0; + } + +@@ -279,17 +330,18 @@ + } + break; + case 's': +- av_metadata_set2(&s->metadata, "title", p, 0); ++ av_dict_set(&s->metadata, "title", p, 0); + break; + case 'i': + if (s->nb_streams == 0) { +- av_metadata_set2(&s->metadata, "comment", p, 0); ++ av_dict_set(&s->metadata, "comment", p, 0); + break; + } + break; + case 'm': + /* new stream */ + s1->skip_media = 0; ++ codec_type = AVMEDIA_TYPE_UNKNOWN; + get_word(st_type, sizeof(st_type), &p); + if (!strcmp(st_type, "audio")) { + codec_type = AVMEDIA_TYPE_AUDIO; +@@ -297,7 +349,8 @@ + codec_type = AVMEDIA_TYPE_VIDEO; + } else if (!strcmp(st_type, "application")) { + codec_type = AVMEDIA_TYPE_DATA; +- } else { ++ } ++ if (codec_type == AVMEDIA_TYPE_UNKNOWN || !(rt->media_type_mask & (1 << codec_type))) { + s1->skip_media = 1; + return; + } +@@ -322,9 +375,10 @@ + if (!strcmp(ff_rtp_enc_name(rtsp_st->sdp_payload_type), "MP2T")) { + /* no corresponding stream */ + } else { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return; ++ st->id = rt->nb_rtsp_streams - 1; + rtsp_st->stream_index = st->index; + st->codec->codec_type = codec_type; + if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) { +@@ -333,11 +387,14 @@ + ff_rtp_get_codec_info(st->codec, rtsp_st->sdp_payload_type); + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && + st->codec->sample_rate > 0) +- av_set_pts_info(st, 32, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 32, 1, st->codec->sample_rate); + /* Even static payload types may need a custom depacketizer */ + handler = ff_rtp_handler_find_by_id( + rtsp_st->sdp_payload_type, st->codec->codec_type); + init_rtp_handler(handler, rtsp_st, st->codec); ++ if (handler && handler->init) ++ handler->init(s, st->index, ++ rtsp_st->dynamic_protocol_context); + } + } + /* put a default control url */ +@@ -425,11 +482,6 @@ + } + } + +-/** +- * Parse the sdp description and allocate the rtp streams and the +- * pollfd array used for udp ones. +- */ +- + int ff_sdp_parse(AVFormatContext *s, const char *content) + { + RTSPState *rt = s->priv_data; +@@ -493,23 +545,20 @@ + av_write_trailer(rtpctx); + if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) { + uint8_t *ptr; +- url_close_dyn_buf(rtpctx->pb, &ptr); ++ avio_close_dyn_buf(rtpctx->pb, &ptr); + av_free(ptr); + } else { +- url_fclose(rtpctx->pb); ++ avio_close(rtpctx->pb); + } +- av_metadata_free(&rtpctx->streams[0]->metadata); +- av_metadata_free(&rtpctx->metadata); +- av_free(rtpctx->streams[0]); +- av_free(rtpctx); ++ avformat_free_context(rtpctx); + } else if (rt->transport == RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) + ff_rdt_parse_close(rtsp_st->transport_priv); + else if (CONFIG_RTPDEC) +- rtp_parse_close(rtsp_st->transport_priv); ++ ff_rtp_parse_close(rtsp_st->transport_priv); + } + rtsp_st->transport_priv = NULL; + if (rtsp_st->rtp_handle) +- url_close(rtsp_st->rtp_handle); ++ ffurl_close(rtsp_st->rtp_handle); + rtsp_st->rtp_handle = NULL; + } + } +@@ -526,15 +575,14 @@ + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st) { + if (rtsp_st->dynamic_handler && rtsp_st->dynamic_protocol_context) +- rtsp_st->dynamic_handler->close( ++ rtsp_st->dynamic_handler->free( + rtsp_st->dynamic_protocol_context); + av_free(rtsp_st); + } + } + av_free(rt->rtsp_streams); + if (rt->asf_ctx) { +- av_close_input_stream (rt->asf_ctx); +- rt->asf_ctx = NULL; ++ avformat_close_input(&rt->asf_ctx); + } + av_free(rt->p); + av_free(rt->recvbuf); +@@ -562,7 +610,7 @@ + rtsp_st->dynamic_protocol_context, + rtsp_st->dynamic_handler); + else if (CONFIG_RTPDEC) +- rtsp_st->transport_priv = rtp_parse_open(s, st, rtsp_st->rtp_handle, ++ rtsp_st->transport_priv = ff_rtp_parse_open(s, st, rtsp_st->rtp_handle, + rtsp_st->sdp_payload_type, + (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP || !s->max_delay) + ? 0 : RTP_REORDER_QUEUE_DEFAULT_SIZE); +@@ -571,9 +619,9 @@ + return AVERROR(ENOMEM); + } else if (rt->transport != RTSP_TRANSPORT_RDT && CONFIG_RTPDEC) { + if (rtsp_st->dynamic_handler) { +- rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, +- rtsp_st->dynamic_protocol_context, +- rtsp_st->dynamic_handler); ++ ff_rtp_parse_set_dynamic_protocol(rtsp_st->transport_priv, ++ rtsp_st->dynamic_protocol_context, ++ rtsp_st->dynamic_handler); + } + } + +@@ -622,7 +670,7 @@ + + get_word_sep(transport_protocol, sizeof(transport_protocol), + "/", &p); +- if (!strcasecmp (transport_protocol, "rtp")) { ++ if (!av_strcasecmp (transport_protocol, "rtp")) { + get_word_sep(profile, sizeof(profile), "/;,", &p); + lower_transport[0] = '\0'; + /* rtp/avp/ */ +@@ -631,14 +679,14 @@ + ";,", &p); + } + th->transport = RTSP_TRANSPORT_RTP; +- } else if (!strcasecmp (transport_protocol, "x-pn-tng") || +- !strcasecmp (transport_protocol, "x-real-rdt")) { ++ } else if (!av_strcasecmp (transport_protocol, "x-pn-tng") || ++ !av_strcasecmp (transport_protocol, "x-real-rdt")) { + /* x-pn-tng/ */ + get_word_sep(lower_transport, sizeof(lower_transport), "/;,", &p); + profile[0] = '\0'; + th->transport = RTSP_TRANSPORT_RDT; + } +- if (!strcasecmp(lower_transport, "TCP")) ++ if (!av_strcasecmp(lower_transport, "TCP")) + th->lower_transport = RTSP_LOWER_TRANSPORT_TCP; + else + th->lower_transport = RTSP_LOWER_TRANSPORT_UDP; +@@ -744,9 +792,9 @@ + if (!strcmp(key, "url")) + av_strlcpy(url, value, sizeof(url)); + else if (!strcmp(key, "seq")) +- seq = strtol(value, NULL, 10); ++ seq = strtoul(value, NULL, 10); + else if (!strcmp(key, "rtptime")) +- rtptime = strtol(value, NULL, 10); ++ rtptime = strtoul(value, NULL, 10); + if (*p == ',') { + handle_rtp_info(rt, url, seq, rtptime); + url[0] = '\0'; +@@ -808,6 +856,13 @@ + p += strspn(p, SPACE_CHARS); + if (method && !strcmp(method, "PLAY")) + rtsp_parse_rtp_info(rt, p); ++ } else if (av_stristart(p, "Public:", &p) && rt) { ++ if (strstr(p, "GET_PARAMETER") && ++ method && !strcmp(method, "OPTIONS")) ++ rt->get_parameter_supported = 1; ++ } else if (av_stristart(p, "x-Accept-Dynamic-Rate:", &p) && rt) { ++ p += strspn(p, SPACE_CHARS); ++ rt->accept_dynamic_rate = atoi(p); + } + } + +@@ -818,7 +873,7 @@ + int ret, len, len1; + uint8_t buf[1024]; + +- ret = url_read_complete(rt->rtsp_hd, buf, 3); ++ ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); + if (ret != 3) + return; + len = AV_RB16(buf + 1); +@@ -830,7 +885,7 @@ + len1 = len; + if (len1 > sizeof(buf)) + len1 = sizeof(buf); +- ret = url_read_complete(rt->rtsp_hd, buf, len1); ++ ret = ffurl_read_complete(rt->rtsp_hd, buf, len1); + if (ret != len1) + return; + len -= len1; +@@ -855,10 +910,8 @@ + for (;;) { + q = buf; + for (;;) { +- ret = url_read_complete(rt->rtsp_hd, &ch, 1); +-#ifdef DEBUG_RTP_TCP ++ ret = ffurl_read_complete(rt->rtsp_hd, &ch, 1); + av_dlog(s, "ret=%d c=%02x [%c]\n", ret, ch, ch); +-#endif + if (ret != 1) + return AVERROR_EOF; + if (ch == '\n') +@@ -903,7 +956,7 @@ + if (content_length > 0) { + /* leave some room for a trailing '\0' (useful for simple parsing) */ + content = av_malloc(content_length + 1); +- (void)url_read_complete(rt->rtsp_hd, content, content_length); ++ ffurl_read_complete(rt->rtsp_hd, content, content_length); + content[content_length] = '\0'; + } + if (content_ptr) +@@ -983,14 +1036,14 @@ + + av_dlog(s, "Sending:\n%s--\n", buf); + +- url_write(rt->rtsp_hd_out, out_buf, strlen(out_buf)); ++ ffurl_write(rt->rtsp_hd_out, out_buf, strlen(out_buf)); + if (send_content_length > 0 && send_content) { + if (rt->control_transport == RTSP_MODE_TUNNEL) { + av_log(s, AV_LOG_ERROR, "tunneling of RTSP requests " + "with content data not supported\n"); + return AVERROR_PATCHWELCOME; + } +- url_write(rt->rtsp_hd_out, send_content, send_content_length); ++ ffurl_write(rt->rtsp_hd_out, send_content, send_content_length); + } + rt->last_cmd_time = av_gettime(); + +@@ -1048,14 +1101,11 @@ + return 0; + } + +-/** +- * @return 0 on success, <0 on error, 1 if protocol is unavailable. +- */ + int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, + int lower_transport, const char *real_challenge) + { + RTSPState *rt = s->priv_data; +- int rtx, j, i, err, interleave = 0; ++ int rtx = 0, j, i, err, interleave = 0, port_off; + RTSPStream *rtsp_st; + RTSPMessageHeader reply1, *reply = &reply1; + char cmd[2048]; +@@ -1069,14 +1119,17 @@ + /* default timeout: 1 minute */ + rt->timeout = 60; + +- /* for each stream, make the setup request */ +- /* XXX: we assume the same server is used for the control of each +- * RTSP stream */ ++ /* Choose a random starting offset within the first half of the ++ * port range, to allow for a number of ports to try even if the offset ++ * happens to be at the end of the random range. */ ++ port_off = av_get_random_seed() % ((rt->rtp_port_max - rt->rtp_port_min)/2); ++ /* even random offset */ ++ port_off -= port_off & 0x01; + +- for (j = RTSP_RTP_PORT_MIN, i = 0; i < rt->nb_rtsp_streams; ++i) { ++ for (j = rt->rtp_port_min + port_off, i = 0; i < rt->nb_rtsp_streams; ++i) { + char transport[2048]; + +- /** ++ /* + * WMS serves all UDP data over a single connection, the RTX, which + * isn't necessarily the first in the SDP but has to be the first + * to be set up, else the second/third SETUP will fail with a 461. +@@ -1110,31 +1163,21 @@ + } + + /* first try in specified port range */ +- if (RTSP_RTP_PORT_MIN != 0) { +- while (j <= RTSP_RTP_PORT_MAX) { +- ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1, +- "?localport=%d", j); +- /* we will use two ports per rtp stream (rtp and rtcp) */ +- j += 2; +- if (url_open(&rtsp_st->rtp_handle, buf, URL_RDWR) == 0) +- goto rtp_opened; +- } ++ while (j <= rt->rtp_port_max) { ++ ff_url_join(buf, sizeof(buf), "rtp", NULL, host, -1, ++ "?localport=%d", j); ++ /* we will use two ports per rtp stream (rtp and rtcp) */ ++ j += 2; ++ if (!ffurl_open(&rtsp_st->rtp_handle, buf, AVIO_FLAG_READ_WRITE, ++ &s->interrupt_callback, NULL)) ++ goto rtp_opened; + } +- +-#if 0 +- /* then try on any port */ +- if (url_open(&rtsp_st->rtp_handle, "rtp://", URL_RDONLY) < 0) { +- err = AVERROR_INVALIDDATA; +- goto fail; +- } +-#else + av_log(s, AV_LOG_ERROR, "Unable to open an input RTP port\n"); + err = AVERROR(EIO); + goto fail; +-#endif + + rtp_opened: +- port = rtp_get_local_rtp_port(rtsp_st->rtp_handle); ++ port = ff_rtp_get_local_rtp_port(rtsp_st->rtp_handle); + have_port: + snprintf(transport, sizeof(transport) - 1, + "%s/UDP;", trans_pref); +@@ -1149,7 +1192,7 @@ + + /* RTP/TCP */ + else if (lower_transport == RTSP_LOWER_TRANSPORT_TCP) { +- /** For WMS streams, the application streams are only used for ++ /* For WMS streams, the application streams are only used for + * UDP. When trying to set it up for TCP streams, the server + * will return an error. Therefore, we skip those streams. */ + if (rt->server_type == RTSP_SERVER_WMS && +@@ -1158,7 +1201,7 @@ + continue; + snprintf(transport, sizeof(transport) - 1, + "%s/TCP;", trans_pref); +- if (rt->server_type == RTSP_SERVER_WMS) ++ if (rt->transport != RTSP_TRANSPORT_RDT) + av_strlcat(transport, "unicast;", sizeof(transport)); + av_strlcatf(transport, sizeof(transport), + "interleaved=%d-%d", +@@ -1178,6 +1221,8 @@ + snprintf(cmd, sizeof(cmd), + "Transport: %s\r\n", + transport); ++ if (rt->accept_dynamic_rate) ++ av_strlcat(cmd, "x-Dynamic-Rate: 0\r\n", sizeof(cmd)); + if (i == 0 && rt->server_type == RTSP_SERVER_REAL && CONFIG_RTPDEC) { + char real_res[41], real_csum[9]; + ff_rdt_calc_response_and_checksum(real_res, real_csum, +@@ -1226,19 +1271,19 @@ + case RTSP_LOWER_TRANSPORT_UDP: { + char url[1024], options[30] = ""; + +- if (rt->filter_source) ++ if (rt->rtsp_flags & RTSP_FLAG_FILTER_SRC) + av_strlcpy(options, "?connect=1", sizeof(options)); + /* Use source address if specified */ + if (reply->transports[0].source[0]) { + ff_url_join(url, sizeof(url), "rtp", NULL, + reply->transports[0].source, +- reply->transports[0].server_port_min, options); ++ reply->transports[0].server_port_min, "%s", options); + } else { + ff_url_join(url, sizeof(url), "rtp", NULL, host, +- reply->transports[0].server_port_min, options); ++ reply->transports[0].server_port_min, "%s", options); + } + if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && +- rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { ++ ff_rtp_set_remote_url(rtsp_st->rtp_handle, url) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; + } +@@ -1248,7 +1293,7 @@ + */ + if (!(rt->server_type == RTSP_SERVER_WMS && i > 1) && s->iformat && + CONFIG_RTPDEC) +- rtp_send_punch_packets(rtsp_st->rtp_handle); ++ ff_rtp_send_punch_packets(rtsp_st->rtp_handle); + break; + } + case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: { +@@ -1269,7 +1314,8 @@ + namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); + ff_url_join(url, sizeof(url), "rtp", NULL, namebuf, + port, "?ttl=%d", ttl); +- if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { ++ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, ++ &s->interrupt_callback, NULL) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; + } +@@ -1297,8 +1343,8 @@ + void ff_rtsp_close_connections(AVFormatContext *s) + { + RTSPState *rt = s->priv_data; +- if (rt->rtsp_hd_out != rt->rtsp_hd) url_close(rt->rtsp_hd_out); +- url_close(rt->rtsp_hd); ++ if (rt->rtsp_hd_out != rt->rtsp_hd) ffurl_close(rt->rtsp_hd_out); ++ ffurl_close(rt->rtsp_hd); + rt->rtsp_hd = rt->rtsp_hd_out = NULL; + } + +@@ -1314,10 +1360,26 @@ + struct sockaddr_storage peer; + socklen_t peer_len = sizeof(peer); + ++ if (rt->rtp_port_max < rt->rtp_port_min) { ++ av_log(s, AV_LOG_ERROR, "Invalid UDP port range, max port %d less " ++ "than min port %d\n", rt->rtp_port_max, ++ rt->rtp_port_min); ++ return AVERROR(EINVAL); ++ } ++ + if (!ff_network_init()) + return AVERROR(EIO); +-redirect: ++ + rt->control_transport = RTSP_MODE_PLAIN; ++ if (rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_HTTP)) { ++ rt->lower_transport_mask = 1 << RTSP_LOWER_TRANSPORT_TCP; ++ rt->control_transport = RTSP_MODE_TUNNEL; ++ } ++ /* Only pass through valid flags from here */ ++ rt->lower_transport_mask &= (1 << RTSP_LOWER_TRANSPORT_NB) - 1; ++ ++redirect: ++ lower_transport_mask = rt->lower_transport_mask; + /* extract hostname and port */ + av_url_split(NULL, 0, auth, sizeof(auth), + host, sizeof(host), &port, path, sizeof(path), s->filename); +@@ -1327,6 +1389,7 @@ + if (port < 0) + port = RTSP_DEFAULT_PORT; + ++#if FF_API_RTSP_URL_OPTIONS + /* search for options */ + option_list = strrchr(path, '?'); + if (option_list) { +@@ -1334,6 +1397,7 @@ + * the options back into the same string. */ + filename = option_list; + while (option_list) { ++ int handled = 1; + /* move the option pointer */ + option = ++option_list; + option_list = strchr(option_list, '&'); +@@ -1351,7 +1415,7 @@ + lower_transport_mask |= (1<< RTSP_LOWER_TRANSPORT_TCP); + rt->control_transport = RTSP_MODE_TUNNEL; + } else if (!strcmp(option, "filter_src")) { +- rt->filter_source = 1; ++ rt->rtsp_flags |= RTSP_FLAG_FILTER_SRC; + } else { + /* Write options back into the buffer, using memmove instead + * of strcpy since the strings may overlap. */ +@@ -1359,10 +1423,16 @@ + memmove(++filename, option, len); + filename += len; + if (option_list) *filename = '&'; ++ handled = 0; + } ++ if (handled) ++ av_log(s, AV_LOG_WARNING, "Options passed via URL are " ++ "deprecated, use -rtsp_transport " ++ "and -rtsp_flags instead.\n"); + } + *filename = 0; + } ++#endif + + if (!lower_transport_mask) + lower_transport_mask = (1 << RTSP_LOWER_TRANSPORT_NB) - 1; +@@ -1396,7 +1466,8 @@ + av_get_random_seed(), av_get_random_seed()); + + /* GET requests */ +- if (url_alloc(&rt->rtsp_hd, httpname, URL_RDONLY) < 0) { ++ if (ffurl_alloc(&rt->rtsp_hd, httpname, AVIO_FLAG_READ, ++ &s->interrupt_callback) < 0) { + err = AVERROR(EIO); + goto fail; + } +@@ -1408,16 +1479,17 @@ + "Pragma: no-cache\r\n" + "Cache-Control: no-cache\r\n", + sessioncookie); +- ff_http_set_headers(rt->rtsp_hd, headers); ++ av_opt_set(rt->rtsp_hd->priv_data, "headers", headers, 0); + + /* complete the connection */ +- if (url_connect(rt->rtsp_hd)) { ++ if (ffurl_connect(rt->rtsp_hd, NULL)) { + err = AVERROR(EIO); + goto fail; + } + + /* POST requests */ +- if (url_alloc(&rt->rtsp_hd_out, httpname, URL_WRONLY) < 0 ) { ++ if (ffurl_alloc(&rt->rtsp_hd_out, httpname, AVIO_FLAG_WRITE, ++ &s->interrupt_callback) < 0 ) { + err = AVERROR(EIO); + goto fail; + } +@@ -1431,8 +1503,8 @@ + "Content-Length: 32767\r\n" + "Expires: Sun, 9 Jan 1972 00:00:00 GMT\r\n", + sessioncookie); +- ff_http_set_headers(rt->rtsp_hd_out, headers); +- ff_http_set_chunked_transfer_encoding(rt->rtsp_hd_out, 0); ++ av_opt_set(rt->rtsp_hd_out->priv_data, "headers", headers, 0); ++ av_opt_set(rt->rtsp_hd_out->priv_data, "chunked_post", "0", 0); + + /* Initialize the authentication state for the POST session. The HTTP + * protocol implementation doesn't properly handle multi-pass +@@ -1453,14 +1525,15 @@ + ff_http_init_auth_state(rt->rtsp_hd_out, rt->rtsp_hd); + + /* complete the connection */ +- if (url_connect(rt->rtsp_hd_out)) { ++ if (ffurl_connect(rt->rtsp_hd_out, NULL)) { + err = AVERROR(EIO); + goto fail; + } + } else { + /* open the tcp connection */ + ff_url_join(tcpname, sizeof(tcpname), "tcp", NULL, host, port, NULL); +- if (url_open(&rt->rtsp_hd, tcpname, URL_RDWR) < 0) { ++ if (ffurl_open(&rt->rtsp_hd, tcpname, AVIO_FLAG_READ_WRITE, ++ &s->interrupt_callback, NULL) < 0) { + err = AVERROR(EIO); + goto fail; + } +@@ -1468,7 +1541,7 @@ + } + rt->seq = 0; + +- tcp_fd = url_get_file_handle(rt->rtsp_hd); ++ tcp_fd = ffurl_get_file_handle(rt->rtsp_hd); + if (!getpeername(tcp_fd, (struct sockaddr*) &peer, &peer_len)) { + getnameinfo((struct sockaddr*) &peer, peer_len, host, sizeof(host), + NULL, 0, NI_NUMERICHOST); +@@ -1480,14 +1553,14 @@ + cmd[0] = 0; + if (rt->server_type == RTSP_SERVER_REAL) + av_strlcat(cmd, +- /** ++ /* + * The following entries are required for proper + * streaming from a Realmedia server. They are + * interdependent in some way although we currently + * don't quite understand how. Values were copied + * from mplayer SVN r23589. +- * @param CompanyID is a 16-byte ID in base64 +- * @param ClientChallenge is a 16-byte ID in hex ++ * ClientChallenge is a 16-byte ID in hex ++ * CompanyID is a 16-byte ID in base64 + */ + "ClientChallenge: 9e26d33f2984236010ef6253fb1887f7\r\n" + "PlayerStarttime: [28/03/2003:22:50:23 00:00]\r\n" +@@ -1504,7 +1577,7 @@ + if (rt->server_type != RTSP_SERVER_REAL && reply->real_challenge[0]) { + rt->server_type = RTSP_SERVER_REAL; + continue; +- } else if (!strncasecmp(reply->server, "WMServer/", 9)) { ++ } else if (!av_strncasecmp(reply->server, "WMServer/", 9)) { + rt->server_type = RTSP_SERVER_WMS; + } else if (rt->server_type == RTSP_SERVER_REAL) + strcpy(real_challenge, reply->real_challenge); +@@ -1529,7 +1602,7 @@ + goto fail; + lower_transport_mask &= ~(1 << lower_transport); + if (lower_transport_mask == 0 && err == 1) { +- err = FF_NETERROR(EPROTONOSUPPORT); ++ err = AVERROR(EPROTONOSUPPORT); + goto fail; + } + } while (err); +@@ -1565,13 +1638,13 @@ + struct pollfd *p = rt->p; + + for (;;) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); ++ if (ff_check_interrupt(&s->interrupt_callback)) ++ return AVERROR_EXIT; + if (wait_end && wait_end - av_gettime() < 0) + return AVERROR(EAGAIN); + max_p = 0; + if (rt->rtsp_hd) { +- tcp_fd = url_get_file_handle(rt->rtsp_hd); ++ tcp_fd = ffurl_get_file_handle(rt->rtsp_hd); + p[max_p].fd = tcp_fd; + p[max_p++].events = POLLIN; + } else { +@@ -1580,9 +1653,9 @@ + for (i = 0; i < rt->nb_rtsp_streams; i++) { + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st->rtp_handle) { +- p[max_p].fd = url_get_file_handle(rtsp_st->rtp_handle); ++ p[max_p].fd = ffurl_get_file_handle(rtsp_st->rtp_handle); + p[max_p++].events = POLLIN; +- p[max_p].fd = rtp_get_rtcp_file_handle(rtsp_st->rtp_handle); ++ p[max_p].fd = ff_rtp_get_rtcp_file_handle(rtsp_st->rtp_handle); + p[max_p++].events = POLLIN; + } + } +@@ -1594,7 +1667,7 @@ + rtsp_st = rt->rtsp_streams[i]; + if (rtsp_st->rtp_handle) { + if (p[j].revents & POLLIN || p[j+1].revents & POLLIN) { +- ret = url_read(rtsp_st->rtp_handle, buf, buf_size); ++ ret = ffurl_read(rtsp_st->rtp_handle, buf, buf_size); + if (ret > 0) { + *prtsp_st = rtsp_st; + return ret; +@@ -1616,7 +1689,7 @@ + } + #endif + } else if (n == 0 && ++timeout_cnt >= MAX_TIMEOUTS) { +- return FF_NETERROR(ETIMEDOUT); ++ return AVERROR(ETIMEDOUT); + } else if (n < 0 && errno != EINTR) + return AVERROR(errno); + } +@@ -1637,7 +1710,7 @@ + if (rt->transport == RTSP_TRANSPORT_RDT) { + ret = ff_rdt_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); + } else +- ret = rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); ++ ret = ff_rtp_parse_packet(rt->cur_transport_priv, pkt, NULL, 0); + if (ret == 0) { + rt->cur_transport_priv = NULL; + return 0; +@@ -1684,14 +1757,14 @@ + case RTSP_LOWER_TRANSPORT_UDP: + case RTSP_LOWER_TRANSPORT_UDP_MULTICAST: + len = udp_read_packet(s, &rtsp_st, rt->recvbuf, RECVBUF_SIZE, wait_end); +- if (len >=0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) +- rtp_check_and_send_back_rr(rtsp_st->transport_priv, len); ++ if (len > 0 && rtsp_st->transport_priv && rt->transport == RTSP_TRANSPORT_RTP) ++ ff_rtp_check_and_send_back_rr(rtsp_st->transport_priv, len); + break; + } + if (len == AVERROR(EAGAIN) && first_queue_st && + rt->transport == RTSP_TRANSPORT_RTP) { + rtsp_st = first_queue_st; +- ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0); ++ ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, NULL, 0); + goto end; + } + if (len < 0) +@@ -1701,7 +1774,7 @@ + if (rt->transport == RTSP_TRANSPORT_RDT) { + ret = ff_rdt_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); + } else { +- ret = rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); ++ ret = ff_rtp_parse_packet(rtsp_st->transport_priv, pkt, &rt->recvbuf, len); + if (ret < 0) { + /* Either bad packet, or a RTCP packet. Check if the + * first_rtcp_ntp_time field was initialized. */ +@@ -1785,7 +1858,7 @@ + /* read the whole sdp file */ + /* XXX: better loading */ + content = av_malloc(SDP_MAX_SIZE); +- size = get_buffer(s->pb, content, SDP_MAX_SIZE - 1); ++ size = avio_read(s->pb, content, SDP_MAX_SIZE - 1); + if (size <= 0) { + av_free(content); + return AVERROR_INVALIDDATA; +@@ -1805,9 +1878,11 @@ + namebuf, sizeof(namebuf), NULL, 0, NI_NUMERICHOST); + ff_url_join(url, sizeof(url), "rtp", NULL, + namebuf, rtsp_st->sdp_port, +- "?localport=%d&ttl=%d", rtsp_st->sdp_port, +- rtsp_st->sdp_ttl); +- if (url_open(&rtsp_st->rtp_handle, url, URL_RDWR) < 0) { ++ "?localport=%d&ttl=%d&connect=%d", rtsp_st->sdp_port, ++ rtsp_st->sdp_ttl, ++ rt->rtsp_flags & RTSP_FLAG_FILTER_SRC ? 1 : 0); ++ if (ffurl_open(&rtsp_st->rtp_handle, url, AVIO_FLAG_READ_WRITE, ++ &s->interrupt_callback, NULL) < 0) { + err = AVERROR_INVALIDDATA; + goto fail; + } +@@ -1828,14 +1903,22 @@ + return 0; + } + ++static const AVClass sdp_demuxer_class = { ++ .class_name = "SDP demuxer", ++ .item_name = av_default_item_name, ++ .option = sdp_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_sdp_demuxer = { +- "sdp", +- NULL_IF_CONFIG_SMALL("SDP"), +- sizeof(RTSPState), +- sdp_probe, +- sdp_read_header, +- ff_rtsp_fetch_packet, +- sdp_read_close, ++ .name = "sdp", ++ .long_name = NULL_IF_CONFIG_SMALL("SDP"), ++ .priv_data_size = sizeof(RTSPState), ++ .read_probe = sdp_probe, ++ .read_header = sdp_read_header, ++ .read_packet = ff_rtsp_fetch_packet, ++ .read_close = sdp_read_close, ++ .priv_class = &sdp_demuxer_class + }; + #endif /* CONFIG_SDP_DEMUXER */ + +@@ -1857,18 +1940,20 @@ + int payload_type; + AVCodecContext codec; + struct sockaddr_storage addr; +- ByteIOContext pb; ++ AVIOContext pb; + socklen_t addrlen = sizeof(addr); ++ RTSPState *rt = s->priv_data; + + if (!ff_network_init()) + return AVERROR(EIO); + +- ret = url_open(&in, s->filename, URL_RDONLY); ++ ret = ffurl_open(&in, s->filename, AVIO_FLAG_READ, ++ &s->interrupt_callback, NULL); + if (ret) + goto fail; + + while (1) { +- ret = url_read(in, recvbuf, sizeof(recvbuf)); ++ ret = ffurl_read(in, recvbuf, sizeof(recvbuf)); + if (ret == AVERROR(EAGAIN)) + continue; + if (ret < 0) +@@ -1887,8 +1972,8 @@ + payload_type = recvbuf[1] & 0x7f; + break; + } +- getsockname(url_get_file_handle(in), (struct sockaddr*) &addr, &addrlen); +- url_close(in); ++ getsockname(ffurl_get_file_handle(in), (struct sockaddr*) &addr, &addrlen); ++ ffurl_close(in); + in = NULL; + + memset(&codec, 0, sizeof(codec)); +@@ -1915,32 +2000,42 @@ + port, payload_type); + av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sdp); + +- init_put_byte(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL); ++ ffio_init_context(&pb, sdp, strlen(sdp), 0, NULL, NULL, NULL, NULL); + s->pb = &pb; + + /* sdp_read_header initializes this again */ + ff_network_close(); + ++ rt->media_type_mask = (1 << (AVMEDIA_TYPE_DATA+1)) - 1; ++ + ret = sdp_read_header(s, ap); + s->pb = NULL; + return ret; + + fail: + if (in) +- url_close(in); ++ ffurl_close(in); + ff_network_close(); + return ret; + } + ++static const AVClass rtp_demuxer_class = { ++ .class_name = "RTP demuxer", ++ .item_name = av_default_item_name, ++ .option = rtp_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_rtp_demuxer = { +- "rtp", +- NULL_IF_CONFIG_SMALL("RTP input format"), +- sizeof(RTSPState), +- rtp_probe, +- rtp_read_header, +- ff_rtsp_fetch_packet, +- sdp_read_close, ++ .name = "rtp", ++ .long_name = NULL_IF_CONFIG_SMALL("RTP input format"), ++ .priv_data_size = sizeof(RTSPState), ++ .read_probe = rtp_probe, ++ .read_header = rtp_read_header, ++ .read_packet = ff_rtsp_fetch_packet, ++ .read_close = sdp_read_close, + .flags = AVFMT_NOFILE, ++ .priv_class = &rtp_demuxer_class + }; + #endif /* CONFIG_RTP_DEMUXER */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtspdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtspdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtspdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtspdec.c 2012-05-14 14:08:55.183357069 +0200 +@@ -21,6 +21,7 @@ + + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" + #include "avformat.h" + + #include "internal.h" +@@ -28,9 +29,7 @@ + #include "os_support.h" + #include "rtsp.h" + #include "rdt.h" +- +-//#define DEBUG +-//#define DEBUG_RTP_TCP ++#include "url.h" + + static int rtsp_read_play(AVFormatContext *s) + { +@@ -53,6 +52,8 @@ + rtpctx->last_rtcp_ntp_time = AV_NOPTS_VALUE; + rtpctx->first_rtcp_ntp_time = AV_NOPTS_VALUE; + rtpctx->base_timestamp = 0; ++ rtpctx->timestamp = 0; ++ rtpctx->unwrapped_timestamp = 0; + rtpctx->rtcp_ts_offset = 0; + } + } +@@ -60,8 +61,9 @@ + cmd[0] = 0; + } else { + snprintf(cmd, sizeof(cmd), +- "Range: npt=%0.3f-\r\n", +- (double)rt->seek_timestamp / AV_TIME_BASE); ++ "Range: npt=%"PRId64".%03"PRId64"-\r\n", ++ rt->seek_timestamp / AV_TIME_BASE, ++ rt->seek_timestamp / (AV_TIME_BASE / 1000) % 1000); + } + ff_rtsp_send_cmd(s, "PLAY", rt->control_uri, cmd, reply, NULL); + if (reply->status_code != RTSP_STATUS_OK) { +@@ -163,7 +165,7 @@ + return AVERROR(ENOMEM); + rt->real_setup = rt->real_setup_cache + s->nb_streams; + +- if (ap->initial_pause) { ++ if (rt->initial_pause) { + /* do not start immediately */ + } else { + if (rtsp_read_play(s) < 0) { +@@ -183,9 +185,7 @@ + int id, len, i, ret; + RTSPStream *rtsp_st; + +-#ifdef DEBUG_RTP_TCP + av_dlog(s, "tcp_read_packet:\n"); +-#endif + redo: + for (;;) { + RTSPMessageHeader reply; +@@ -199,18 +199,16 @@ + if (rt->state != RTSP_STATE_STREAMING) + return 0; + } +- ret = url_read_complete(rt->rtsp_hd, buf, 3); ++ ret = ffurl_read_complete(rt->rtsp_hd, buf, 3); + if (ret != 3) + return -1; + id = buf[0]; + len = AV_RB16(buf + 1); +-#ifdef DEBUG_RTP_TCP + av_dlog(s, "id=%d len=%d\n", id, len); +-#endif +- if (len > buf_size || len < 12) ++ if (len > buf_size || len < 8) + goto redo; + /* get the data */ +- ret = url_read_complete(rt->rtsp_hd, buf, len); ++ ret = ffurl_read_complete(rt->rtsp_hd, buf, len); + if (ret != len) + return -1; + if (rt->transport == RTSP_TRANSPORT_RDT && +@@ -283,7 +281,7 @@ + for (i = 0; i < rt->nb_rtsp_streams; i++) { + rule_nr = 0; + for (r = 0; r < s->nb_streams; r++) { +- if (s->streams[r]->priv_data == rt->rtsp_streams[i]) { ++ if (s->streams[r]->id == i) { + if (s->streams[r]->discard != AVDISCARD_ALL) { + if (!first) + av_strlcat(rt->last_subscription, ",", +@@ -311,7 +309,7 @@ + + ret = ff_rtsp_fetch_packet(s, pkt); + if (ret < 0) { +- if (ret == FF_NETERROR(ETIMEDOUT) && !rt->packets) { ++ if (ret == AVERROR(ETIMEDOUT) && !rt->packets) { + if (rt->lower_transport == RTSP_LOWER_TRANSPORT_UDP && + rt->lower_transport_mask & (1 << RTSP_LOWER_TRANSPORT_TCP)) { + RTSPMessageHeader reply1, *reply = &reply1; +@@ -339,7 +337,9 @@ + + /* send dummy request to keep TCP connection alive */ + if ((av_gettime() - rt->last_cmd_time) / 1000000 >= rt->timeout / 2) { +- if (rt->server_type == RTSP_SERVER_WMS) { ++ if (rt->server_type == RTSP_SERVER_WMS || ++ (rt->server_type != RTSP_SERVER_REAL && ++ rt->get_parameter_supported)) { + ff_rtsp_send_cmd_async(s, "GET_PARAMETER", rt->control_uri, NULL); + } else { + ff_rtsp_send_cmd_async(s, "OPTIONS", "*", NULL); +@@ -379,12 +379,6 @@ + { + RTSPState *rt = s->priv_data; + +-#if 0 +- /* NOTE: it is valid to flush the buffer here */ +- if (rt->lower_transport == RTSP_LOWER_TRANSPORT_TCP) { +- url_fclose(&rt->rtsp_gb); +- } +-#endif + ff_rtsp_send_cmd_async(s, "TEARDOWN", rt->control_uri, NULL); + + ff_rtsp_close_streams(s); +@@ -395,16 +389,24 @@ + return 0; + } + ++const AVClass rtsp_demuxer_class = { ++ .class_name = "RTSP demuxer", ++ .item_name = av_default_item_name, ++ .option = ff_rtsp_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_rtsp_demuxer = { +- "rtsp", +- NULL_IF_CONFIG_SMALL("RTSP input format"), +- sizeof(RTSPState), +- rtsp_probe, +- rtsp_read_header, +- rtsp_read_packet, +- rtsp_read_close, +- rtsp_read_seek, ++ .name = "rtsp", ++ .long_name = NULL_IF_CONFIG_SMALL("RTSP input format"), ++ .priv_data_size = sizeof(RTSPState), ++ .read_probe = rtsp_probe, ++ .read_header = rtsp_read_header, ++ .read_packet = rtsp_read_packet, ++ .read_close = rtsp_read_close, ++ .read_seek = rtsp_read_seek, + .flags = AVFMT_NOFILE, + .read_play = rtsp_read_play, + .read_pause = rtsp_read_pause, ++ .priv_class = &rtsp_demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtspenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtspenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtspenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtspenc.c 2012-05-14 14:08:55.184357089 +0200 +@@ -29,11 +29,20 @@ + #include "os_support.h" + #include "rtsp.h" + #include "internal.h" ++#include "avio_internal.h" + #include "libavutil/intreadwrite.h" + #include "libavutil/avstring.h" ++#include "url.h" + + #define SDP_MAX_SIZE 16384 + ++static const AVClass rtsp_muxer_class = { ++ .class_name = "RTSP muxer", ++ .item_name = av_default_item_name, ++ .option = ff_rtsp_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr) + { + RTSPState *rt = s->priv_data; +@@ -64,7 +73,7 @@ + ff_url_join(sdp_ctx.filename, sizeof(sdp_ctx.filename), + "rtsp", NULL, addr, -1, NULL); + ctx_array[0] = &sdp_ctx; +- if (avf_sdp_create(ctx_array, 1, sdp, SDP_MAX_SIZE)) { ++ if (av_sdp_create(ctx_array, 1, sdp, SDP_MAX_SIZE)) { + av_free(sdp); + return AVERROR_INVALIDDATA; + } +@@ -103,8 +112,7 @@ + char cmd[1024]; + + snprintf(cmd, sizeof(cmd), +- "Range: npt=%0.3f-\r\n", +- (double) 0); ++ "Range: npt=0.000-\r\n"); + ff_rtsp_send_cmd(s, "RECORD", rt->control_uri, cmd, reply, NULL); + if (reply->status_code != RTSP_STATUS_OK) + return -1; +@@ -136,14 +144,14 @@ + int size; + uint8_t *interleave_header, *interleaved_packet; + +- size = url_close_dyn_buf(rtpctx->pb, &buf); ++ size = avio_close_dyn_buf(rtpctx->pb, &buf); + ptr = buf; + while (size > 4) { + uint32_t packet_len = AV_RB32(ptr); + int id; + /* The interleaving header is exactly 4 bytes, which happens to be + * the same size as the packet length header from +- * url_open_dyn_packet_buf. So by writing the interleaving header ++ * ffio_open_dyn_packet_buf. So by writing the interleaving header + * over these bytes, we get a consecutive interleaved packet + * that can be written in one call. */ + interleaved_packet = interleave_header = ptr; +@@ -158,12 +166,12 @@ + interleave_header[0] = '$'; + interleave_header[1] = id; + AV_WB16(interleave_header + 2, packet_len); +- url_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len); ++ ffurl_write(rt->rtsp_hd_out, interleaved_packet, 4 + packet_len); + ptr += packet_len; + size -= packet_len; + } + av_free(buf); +- url_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); ++ ffio_open_dyn_packet_buf(&rtpctx->pb, RTSP_TCP_MAX_PACKET_SIZE); + return 0; + } + +@@ -172,7 +180,7 @@ + RTSPState *rt = s->priv_data; + RTSPStream *rtsp_st; + int n; +- struct pollfd p = {url_get_file_handle(rt->rtsp_hd), POLLIN, 0}; ++ struct pollfd p = {ffurl_get_file_handle(rt->rtsp_hd), POLLIN, 0}; + AVFormatContext *rtpctx; + int ret; + +@@ -226,16 +234,15 @@ + } + + AVOutputFormat ff_rtsp_muxer = { +- "rtsp", +- NULL_IF_CONFIG_SMALL("RTSP output format"), +- NULL, +- NULL, +- sizeof(RTSPState), +- CODEC_ID_AAC, +- CODEC_ID_MPEG4, +- rtsp_write_header, +- rtsp_write_packet, +- rtsp_write_close, ++ .name = "rtsp", ++ .long_name = NULL_IF_CONFIG_SMALL("RTSP output format"), ++ .priv_data_size = sizeof(RTSPState), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = rtsp_write_header, ++ .write_packet = rtsp_write_packet, ++ .write_trailer = rtsp_write_close, + .flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER, ++ .priv_class = &rtsp_muxer_class, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtsp.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtsp.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/rtsp.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/rtsp.h 2012-05-14 14:08:55.182357049 +0200 +@@ -28,6 +28,9 @@ + #include "network.h" + #include "httpauth.h" + ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ + /** + * Network layer over which RTP/etc packet data will be transported. + */ +@@ -35,7 +38,10 @@ + RTSP_LOWER_TRANSPORT_UDP = 0, /**< UDP/unicast */ + RTSP_LOWER_TRANSPORT_TCP = 1, /**< TCP; interleaved in RTSP */ + RTSP_LOWER_TRANSPORT_UDP_MULTICAST = 2, /**< UDP/multicast */ +- RTSP_LOWER_TRANSPORT_NB ++ RTSP_LOWER_TRANSPORT_NB, ++ RTSP_LOWER_TRANSPORT_HTTP = 8, /**< HTTP tunneled - not a proper ++ transport mode as such, ++ only for use via AVOptions */ + }; + + /** +@@ -64,7 +70,7 @@ + #define RTSP_DEFAULT_NB_AUDIO_CHANNELS 1 + #define RTSP_DEFAULT_AUDIO_SAMPLERATE 44100 + #define RTSP_RTP_PORT_MIN 5000 +-#define RTSP_RTP_PORT_MAX 10000 ++#define RTSP_RTP_PORT_MAX 65000 + + /** + * This describes a single item in the "Transport:" line of one stream as +@@ -180,7 +186,7 @@ + }; + + /** +- * Identifies particular servers that require special handling, such as ++ * Identify particular servers that require special handling, such as + * standards-incompliant "Transport:" lines in the SETUP request. + */ + enum RTSPServerType { +@@ -193,9 +199,10 @@ + /** + * Private data for the RTSP demuxer. + * +- * @todo Use ByteIOContext instead of URLContext ++ * @todo Use AVIOContext instead of URLContext + */ + typedef struct RTSPState { ++ const AVClass *class; /**< Class for private options. */ + URLContext *rtsp_hd; /* RTSP TCP connection handle */ + + /** number of items in the 'rtsp_streams' variable */ +@@ -217,9 +224,6 @@ + * see rtsp_read_play() and rtsp_read_seek(). */ + int64_t seek_timestamp; + +- /* XXX: currently we use unbuffered input */ +- // ByteIOContext rtsp_gb; +- + int seq; /**< RTSP command sequence number */ + + /** copy of RTSPMessageHeader->session_id, i.e. the server-provided session +@@ -313,10 +317,6 @@ + /** Reusable buffer for receiving packets */ + uint8_t* recvbuf; + +- /** Filter incoming UDP packets - receive packets only from the right +- * source address and port. */ +- int filter_source; +- + /** + * A mask with all requested transport methods + */ +@@ -331,10 +331,47 @@ + * Polling array for udp + */ + struct pollfd *p; ++ ++ /** ++ * Whether the server supports the GET_PARAMETER method. ++ */ ++ int get_parameter_supported; ++ ++ /** ++ * Do not begin to play the stream immediately. ++ */ ++ int initial_pause; ++ ++ /** ++ * Option flags for the chained RTP muxer. ++ */ ++ int rtp_muxer_flags; ++ ++ /** Whether the server accepts the x-Dynamic-Rate header */ ++ int accept_dynamic_rate; ++ ++ /** ++ * Various option flags for the RTSP muxer/demuxer. ++ */ ++ int rtsp_flags; ++ ++ /** ++ * Mask of all requested media types ++ */ ++ int media_type_mask; ++ ++ /** ++ * Minimum and maximum local UDP ports. ++ */ ++ int rtp_port_min, rtp_port_max; + } RTSPState; + ++#define RTSP_FLAG_FILTER_SRC 0x1 /**< Filter incoming UDP packets - ++ receive packets only from the right ++ source address and port. */ ++ + /** +- * Describes a single stream, as identified by a single m= line block in the ++ * Describe a single stream, as identified by a single m= line block in the + * SDP content. In the case of RDT, one RTSPStream can represent multiple + * AVStreams. In this case, each AVStream in this set has similar content + * (but different codec/bitrate). +@@ -373,9 +410,6 @@ + void ff_rtsp_parse_line(RTSPMessageHeader *reply, const char *buf, + RTSPState *rt, const char *method); + +-extern int rtsp_rtp_port_min; +-extern int rtsp_rtp_port_max; +- + /** + * Send a command to the RTSP server without waiting for the reply. + * +@@ -470,9 +504,9 @@ + /** + * Close all connection handles within the RTSP (de)muxer + * +- * @param rt RTSP (de)muxer context ++ * @param s RTSP (de)muxer context + */ +-void ff_rtsp_close_connections(AVFormatContext *rt); ++void ff_rtsp_close_connections(AVFormatContext *s); + + /** + * Get the description of the stream and set up the RTSPStream child +@@ -487,8 +521,9 @@ + int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr); + + /** +- * Parse a SDP description of streams by populating an RTSPState struct +- * within the AVFormatContext. ++ * Parse an SDP description of streams by populating an RTSPState struct ++ * within the AVFormatContext; also allocate the RTP streams and the ++ * pollfd array used for UDP streams. + */ + int ff_sdp_parse(AVFormatContext *s, const char *content); + +@@ -507,6 +542,7 @@ + /** + * Do the SETUP requests for each stream for the chosen + * lower transport mode. ++ * @return 0 on success, <0 on error, 1 if protocol is unavailable + */ + int ff_rtsp_make_setup_request(AVFormatContext *s, const char *host, int port, + int lower_transport, const char *real_challenge); +@@ -517,4 +553,6 @@ + */ + void ff_rtsp_undo_setup(AVFormatContext *s); + ++extern const AVOption ff_rtsp_options[]; ++ + #endif /* AVFORMAT_RTSP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sapdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sapdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sapdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sapdec.c 2012-05-14 14:08:55.185357109 +0200 +@@ -25,6 +25,8 @@ + #include "network.h" + #include "os_support.h" + #include "internal.h" ++#include "avio_internal.h" ++#include "url.h" + #if HAVE_POLL_H + #include + #endif +@@ -33,7 +35,7 @@ + struct SAPState { + URLContext *ann_fd; + AVFormatContext *sdp_ctx; +- ByteIOContext sdp_pb; ++ AVIOContext sdp_pb; + uint16_t hash; + char *sdp; + int eof; +@@ -50,9 +52,9 @@ + { + struct SAPState *sap = s->priv_data; + if (sap->sdp_ctx) +- av_close_input_stream(sap->sdp_ctx); ++ avformat_close_input(&sap->sdp_ctx); + if (sap->ann_fd) +- url_close(sap->ann_fd); ++ ffurl_close(sap->ann_fd); + av_freep(&sap->sdp); + ff_network_close(); + return 0; +@@ -83,7 +85,8 @@ + + ff_url_join(url, sizeof(url), "udp", NULL, host, port, "?localport=%d", + port); +- ret = url_open(&sap->ann_fd, url, URL_RDONLY); ++ ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_READ, ++ &s->interrupt_callback, NULL); + if (ret) + goto fail; + +@@ -91,7 +94,7 @@ + int addr_type, auth_len; + int pos; + +- ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf) - 1); ++ ret = ffurl_read(sap->ann_fd, recvbuf, sizeof(recvbuf) - 1); + if (ret == AVERROR(EAGAIN)) + continue; + if (ret < 0) +@@ -142,7 +145,7 @@ + } + + av_log(s, AV_LOG_VERBOSE, "SDP:\n%s\n", sap->sdp); +- init_put_byte(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL, ++ ffio_init_context(&sap->sdp_pb, sap->sdp, strlen(sap->sdp), 0, NULL, NULL, + NULL, NULL); + + infmt = av_find_input_format("sdp"); +@@ -154,19 +157,20 @@ + goto fail; + } + sap->sdp_ctx->max_delay = s->max_delay; +- ap->prealloced_context = 1; +- ret = av_open_input_stream(&sap->sdp_ctx, &sap->sdp_pb, "temp.sdp", +- infmt, ap); ++ sap->sdp_ctx->pb = &sap->sdp_pb; ++ sap->sdp_ctx->interrupt_callback = s->interrupt_callback; ++ ret = avformat_open_input(&sap->sdp_ctx, "temp.sdp", infmt, NULL); + if (ret < 0) + goto fail; + if (sap->sdp_ctx->ctx_flags & AVFMTCTX_NOHEADER) + s->ctx_flags |= AVFMTCTX_NOHEADER; + for (i = 0; i < sap->sdp_ctx->nb_streams; i++) { +- AVStream *st = av_new_stream(s, i); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) { + ret = AVERROR(ENOMEM); + goto fail; + } ++ st->id = i; + avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec); + st->time_base = sap->sdp_ctx->streams[i]->time_base; + } +@@ -181,7 +185,7 @@ + static int sap_fetch_packet(AVFormatContext *s, AVPacket *pkt) + { + struct SAPState *sap = s->priv_data; +- int fd = url_get_file_handle(sap->ann_fd); ++ int fd = ffurl_get_file_handle(sap->ann_fd); + int n, ret; + struct pollfd p = {fd, POLLIN, 0}; + uint8_t recvbuf[1500]; +@@ -193,7 +197,7 @@ + n = poll(&p, 1, 0); + if (n <= 0 || !(p.revents & POLLIN)) + break; +- ret = url_read(sap->ann_fd, recvbuf, sizeof(recvbuf)); ++ ret = ffurl_read(sap->ann_fd, recvbuf, sizeof(recvbuf)); + if (ret >= 8) { + uint16_t hash = AV_RB16(&recvbuf[2]); + /* Should ideally check the source IP address, too */ +@@ -210,11 +214,12 @@ + if (s->ctx_flags & AVFMTCTX_NOHEADER) { + while (sap->sdp_ctx->nb_streams > s->nb_streams) { + int i = s->nb_streams; +- AVStream *st = av_new_stream(s, i); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) { + av_free_packet(pkt); + return AVERROR(ENOMEM); + } ++ st->id = i; + avcodec_copy_context(st->codec, sap->sdp_ctx->streams[i]->codec); + st->time_base = sap->sdp_ctx->streams[i]->time_base; + } +@@ -223,13 +228,13 @@ + } + + AVInputFormat ff_sap_demuxer = { +- "sap", +- NULL_IF_CONFIG_SMALL("SAP input format"), +- sizeof(struct SAPState), +- sap_probe, +- sap_read_header, +- sap_fetch_packet, +- sap_read_close, ++ .name = "sap", ++ .long_name = NULL_IF_CONFIG_SMALL("SAP input format"), ++ .priv_data_size = sizeof(struct SAPState), ++ .read_probe = sap_probe, ++ .read_header = sap_read_header, ++ .read_packet = sap_fetch_packet, ++ .read_close = sap_read_close, + .flags = AVFMT_NOFILE, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sapenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sapenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sapenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sapenc.c 2012-05-14 14:08:55.186357129 +0200 +@@ -20,6 +20,7 @@ + */ + + #include "avformat.h" ++#include "libavutil/parseutils.h" + #include "libavutil/random_seed.h" + #include "libavutil/avstring.h" + #include "libavutil/intreadwrite.h" +@@ -27,6 +28,7 @@ + #include "network.h" + #include "os_support.h" + #include "rtpenc_chain.h" ++#include "url.h" + + struct SAPState { + uint8_t *ann; +@@ -45,22 +47,19 @@ + if (!rtpctx) + continue; + av_write_trailer(rtpctx); +- url_fclose(rtpctx->pb); +- av_metadata_free(&rtpctx->streams[0]->metadata); +- av_metadata_free(&rtpctx->metadata); +- av_free(rtpctx->streams[0]); +- av_free(rtpctx); ++ avio_close(rtpctx->pb); ++ avformat_free_context(rtpctx); + s->streams[i]->priv_data = NULL; + } + + if (sap->last_time && sap->ann && sap->ann_fd) { + sap->ann[0] |= 4; /* Session deletion*/ +- url_write(sap->ann_fd, sap->ann, sap->ann_size); ++ ffurl_write(sap->ann_fd, sap->ann, sap->ann_size); + } + + av_freep(&sap->ann); + if (sap->ann_fd) +- url_close(sap->ann_fd); ++ ffurl_close(sap->ann_fd); + ff_network_close(); + return 0; + } +@@ -90,16 +89,16 @@ + option_list = strrchr(path, '?'); + if (option_list) { + char buf[50]; +- if (find_info_tag(buf, sizeof(buf), "announce_port", option_list)) { ++ if (av_find_info_tag(buf, sizeof(buf), "announce_port", option_list)) { + port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "same_port", option_list)) { ++ if (av_find_info_tag(buf, sizeof(buf), "same_port", option_list)) { + same_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "ttl", option_list)) { ++ if (av_find_info_tag(buf, sizeof(buf), "ttl", option_list)) { + ttl = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) { ++ if (av_find_info_tag(buf, sizeof(buf), "announce_addr", option_list)) { + av_strlcpy(announce_addr, buf, sizeof(announce_addr)); + } + } +@@ -147,7 +146,7 @@ + "?ttl=%d", ttl); + if (!same_port) + base_port += 2; +- ret = url_open(&fd, url, URL_WRONLY); ++ ret = ffurl_open(&fd, url, AVIO_FLAG_WRITE, &s->interrupt_callback, NULL); + if (ret) { + ret = AVERROR(EIO); + goto fail; +@@ -159,13 +158,14 @@ + + ff_url_join(url, sizeof(url), "udp", NULL, announce_addr, port, + "?ttl=%d&connect=1", ttl); +- ret = url_open(&sap->ann_fd, url, URL_WRONLY); ++ ret = ffurl_open(&sap->ann_fd, url, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL); + if (ret) { + ret = AVERROR(EIO); + goto fail; + } + +- udp_fd = url_get_file_handle(sap->ann_fd); ++ udp_fd = ffurl_get_file_handle(sap->ann_fd); + if (getsockname(udp_fd, (struct sockaddr*) &localaddr, &addrlen)) { + ret = AVERROR(EIO); + goto fail; +@@ -209,7 +209,7 @@ + av_strlcpy(&sap->ann[pos], "application/sdp", sap->ann_size - pos); + pos += strlen(&sap->ann[pos]) + 1; + +- if (avf_sdp_create(contexts, s->nb_streams, &sap->ann[pos], ++ if (av_sdp_create(contexts, s->nb_streams, &sap->ann[pos], + sap->ann_size - pos)) { + ret = AVERROR_INVALIDDATA; + goto fail; +@@ -219,7 +219,7 @@ + pos += strlen(&sap->ann[pos]); + sap->ann_size = pos; + +- if (sap->ann_size > url_get_max_packet_size(sap->ann_fd)) { ++ if (sap->ann_size > sap->ann_fd->max_packet_size) { + av_log(s, AV_LOG_ERROR, "Announcement too large to send in one " + "packet\n"); + goto fail; +@@ -240,9 +240,9 @@ + int64_t now = av_gettime(); + + if (!sap->last_time || now - sap->last_time > 5000000) { +- int ret = url_write(sap->ann_fd, sap->ann, sap->ann_size); ++ int ret = ffurl_write(sap->ann_fd, sap->ann, sap->ann_size); + /* Don't abort even if we get "Destination unreachable" */ +- if (ret < 0 && ret != FF_NETERROR(ECONNREFUSED)) ++ if (ret < 0 && ret != AVERROR(ECONNREFUSED)) + return ret; + sap->last_time = now; + } +@@ -251,16 +251,14 @@ + } + + AVOutputFormat ff_sap_muxer = { +- "sap", +- NULL_IF_CONFIG_SMALL("SAP output format"), +- NULL, +- NULL, +- sizeof(struct SAPState), +- CODEC_ID_AAC, +- CODEC_ID_MPEG4, +- sap_write_header, +- sap_write_packet, +- sap_write_close, ++ .name = "sap", ++ .long_name = NULL_IF_CONFIG_SMALL("SAP output format"), ++ .priv_data_size = sizeof(struct SAPState), ++ .audio_codec = CODEC_ID_AAC, ++ .video_codec = CODEC_ID_MPEG4, ++ .write_header = sap_write_header, ++ .write_packet = sap_write_packet, ++ .write_trailer = sap_write_close, + .flags = AVFMT_NOFILE | AVFMT_GLOBALHEADER, + }; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sauce.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sauce.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sauce.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sauce.c 2012-05-14 14:08:55.187357149 +0200 +@@ -25,40 +25,41 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" + #include "sauce.h" + + int ff_sauce_read(AVFormatContext *avctx, uint64_t *fsize, int *got_width, int get_height) + { +- ByteIOContext *pb = avctx->pb; ++ AVIOContext *pb = avctx->pb; + char buf[36]; +- int datatype, filetype, t1, t2, nb_comments, flags; +- uint64_t start_pos = url_fsize(pb) - 128; ++ int datatype, filetype, t1, t2, nb_comments; ++ uint64_t start_pos = avio_size(pb) - 128; + +- url_fseek(pb, start_pos, SEEK_SET); +- if (get_buffer(pb, buf, 7) != 7) ++ avio_seek(pb, start_pos, SEEK_SET); ++ if (avio_read(pb, buf, 7) != 7) + return -1; + if (memcmp(buf, "SAUCE00", 7)) + return -1; + + #define GET_SAUCE_META(name,size) \ +- if (get_buffer(pb, buf, size) == size && buf[0]) { \ ++ if (avio_read(pb, buf, size) == size && buf[0]) { \ + buf[size] = 0; \ +- av_metadata_set2(&avctx->metadata, name, buf, 0); \ ++ av_dict_set(&avctx->metadata, name, buf, 0); \ + } + + GET_SAUCE_META("title", 35) + GET_SAUCE_META("artist", 20) + GET_SAUCE_META("publisher", 20) + GET_SAUCE_META("date", 8) +- url_fskip(pb, 4); +- datatype = get_byte(pb); +- filetype = get_byte(pb); +- t1 = get_le16(pb); +- t2 = get_le16(pb); +- nb_comments = get_byte(pb); +- flags = get_byte(pb); +- url_fskip(pb, 4); ++ avio_skip(pb, 4); ++ datatype = avio_r8(pb); ++ filetype = avio_r8(pb); ++ t1 = avio_rl16(pb); ++ t2 = avio_rl16(pb); ++ nb_comments = avio_r8(pb); ++ avio_skip(pb, 1); /* flags */ ++ avio_skip(pb, 4); + GET_SAUCE_META("encoder", 22); + + if (got_width && datatype && filetype) { +@@ -82,20 +83,20 @@ + *fsize -= 128; + + if (nb_comments > 0) { +- url_fseek(pb, start_pos - 64*nb_comments - 5, SEEK_SET); +- if (get_buffer(pb, buf, 5) == 5 && !memcmp(buf, "COMNT", 5)) { ++ avio_seek(pb, start_pos - 64*nb_comments - 5, SEEK_SET); ++ if (avio_read(pb, buf, 5) == 5 && !memcmp(buf, "COMNT", 5)) { + int i; + char *str = av_malloc(65*nb_comments + 1); + *fsize -= 64*nb_comments + 5; + if (!str) + return 0; + for (i = 0; i < nb_comments; i++) { +- if (get_buffer(pb, str + 65*i, 64) != 64) ++ if (avio_read(pb, str + 65*i, 64) != 64) + break; + str[65*i + 64] = '\n'; + } + str[65*i] = 0; +- av_metadata_set2(&avctx->metadata, "comment", str, AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&avctx->metadata, "comment", str, AV_DICT_DONT_STRDUP_VAL); + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sbgdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sbgdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sbgdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sbgdec.c 2012-05-14 14:08:55.191357229 +0200 +@@ -0,0 +1,1518 @@ ++/* ++ * SBG (SBaGen) file format decoder ++ * Copyright (c) 2011 Nicolas George ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++#include "libavutil/intreadwrite.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define SBG_SCALE (1 << 16) ++#define DAY (24 * 60 * 60) ++#define DAY_TS ((int64_t)DAY * AV_TIME_BASE) ++ ++struct sbg_demuxer { ++ AVClass *class; ++ int sample_rate; ++ int frame_size; ++ int max_file_size; ++}; ++ ++struct sbg_string { ++ char *s; ++ char *e; ++}; ++ ++enum sbg_fade_type { ++ SBG_FADE_SILENCE = 0, ++ SBG_FADE_SAME = 1, ++ SBG_FADE_ADAPT = 3, ++}; ++ ++struct sbg_fade { ++ int8_t in, out, slide; ++}; ++ ++enum sbg_synth_type { ++ SBG_TYPE_NONE, ++ SBG_TYPE_SINE, ++ SBG_TYPE_NOISE, ++ SBG_TYPE_BELL, ++ SBG_TYPE_MIX, ++ SBG_TYPE_SPIN, ++}; ++ ++/* bell: freq constant, ampl decreases exponentially, can be approx lin */ ++ ++struct sbg_timestamp { ++ int64_t t; ++ char type; /* 0 for relative, 'N' for now, 'T' for absolute */ ++}; ++ ++struct sbg_script_definition { ++ char *name; ++ int name_len; ++ int elements, nb_elements; ++ char type; /* 'S' or 'B' */ ++}; ++ ++struct sbg_script_synth { ++ int carrier; ++ int beat; ++ int vol; ++ enum sbg_synth_type type; ++ struct { ++ int l, r; ++ } ref; ++}; ++ ++struct sbg_script_tseq { ++ struct sbg_timestamp ts; ++ char *name; ++ int name_len; ++ int lock; ++ struct sbg_fade fade; ++}; ++ ++struct sbg_script_event { ++ int64_t ts; ++ int64_t ts_int, ts_trans, ts_next; ++ int elements, nb_elements; ++ struct sbg_fade fade; ++}; ++ ++struct sbg_script { ++ struct sbg_script_definition *def; ++ struct sbg_script_synth *synth; ++ struct sbg_script_tseq *tseq; ++ struct sbg_script_tseq *block_tseq; ++ struct sbg_script_event *events; ++ int nb_def; ++ int nb_tseq; ++ int nb_events; ++ int nb_synth; ++ int64_t start_ts; ++ int64_t end_ts; ++ int64_t opt_fade_time; ++ int64_t opt_duration; ++ char *opt_mix; ++ int sample_rate; ++ uint8_t opt_start_at_first; ++ uint8_t opt_end_at_last; ++}; ++ ++struct sbg_parser { ++ void *log; ++ char *script, *end; ++ char *cursor; ++ struct sbg_script scs; ++ struct sbg_timestamp current_time; ++ int nb_block_tseq; ++ int nb_def_max, nb_synth_max, nb_tseq_max, nb_block_tseq_max; ++ int line_no; ++ char err_msg[128]; ++}; ++ ++enum ws_interval_type { ++ WS_SINE = MKTAG('S','I','N','E'), ++ WS_NOISE = MKTAG('N','O','I','S'), ++}; ++ ++struct ws_interval { ++ int64_t ts1, ts2; ++ enum ws_interval_type type; ++ uint32_t channels; ++ int32_t f1, f2; ++ int32_t a1, a2; ++ uint32_t phi; ++}; ++ ++struct ws_intervals { ++ struct ws_interval *inter; ++ int nb_inter; ++ int max_inter; ++}; ++ ++static void *alloc_array_elem(void **array, size_t elsize, ++ int *size, int *max_size) ++{ ++ void *ret; ++ ++ if (*size == *max_size) { ++ int m = FFMAX(32, FFMIN(*max_size, INT_MAX / 2) * 2); ++ if (*size >= m) ++ return NULL; ++ *array = av_realloc_f(*array, m, elsize); ++ if (!*array) ++ return NULL; ++ *max_size = m; ++ } ++ ret = (char *)*array + elsize * *size; ++ memset(ret, 0, elsize); ++ (*size)++; ++ return ret; ++} ++ ++static int str_to_time(const char *str, int64_t *rtime) ++{ ++ const char *cur = str; ++ char *end; ++ int hours, minutes; ++ double seconds = 0; ++ ++ if (*cur < '0' || *cur > '9') ++ return 0; ++ hours = strtol(cur, &end, 10); ++ if (end == cur || *end != ':' || end[1] < '0' || end[1] > '9') ++ return 0; ++ cur = end + 1; ++ minutes = strtol(cur, &end, 10); ++ if (end == cur) ++ return 0; ++ cur = end; ++ if (*end == ':'){ ++ seconds = strtod(cur + 1, &end); ++ if (end > cur + 1) ++ cur = end; ++ } ++ *rtime = (hours * 3600 + minutes * 60 + seconds) * AV_TIME_BASE; ++ return cur - str; ++} ++ ++static inline int is_space(char c) ++{ ++ return c == ' ' || c == '\t' || c == '\r'; ++} ++ ++static inline int scale_double(void *log, double d, double m, int *r) ++{ ++ m *= d * SBG_SCALE; ++ if (m < INT_MIN || m >= INT_MAX) { ++ if (log) ++ av_log(log, AV_LOG_ERROR, "%g is too large\n", d); ++ return AVERROR(EDOM); ++ } ++ *r = m; ++ return 0; ++} ++ ++static int lex_space(struct sbg_parser *p) ++{ ++ char *c = p->cursor; ++ ++ while (p->cursor < p->end && is_space(*p->cursor)) ++ p->cursor++; ++ return p->cursor > c; ++} ++ ++static int lex_char(struct sbg_parser *p, char c) ++{ ++ int r = p->cursor < p->end && *p->cursor == c; ++ ++ p->cursor += r; ++ return r; ++} ++ ++static int lex_double(struct sbg_parser *p, double *r) ++{ ++ double d; ++ char *end; ++ ++ if (p->cursor == p->end || is_space(*p->cursor) || *p->cursor == '\n') ++ return 0; ++ d = strtod(p->cursor, &end); ++ if (end > p->cursor) { ++ *r = d; ++ p->cursor = end; ++ return 1; ++ } ++ return 0; ++} ++ ++static int lex_fixed(struct sbg_parser *p, const char *t, int l) ++{ ++ if (p->end - p->cursor < l || memcmp(p->cursor, t, l)) ++ return 0; ++ p->cursor += l; ++ return 1; ++} ++ ++static int lex_line_end(struct sbg_parser *p) ++{ ++ if (p->cursor < p->end && *p->cursor == '#') { ++ p->cursor++; ++ while (p->cursor < p->end && *p->cursor != '\n') ++ p->cursor++; ++ } ++ if (p->cursor == p->end) ++ /* simulate final LF for files lacking it */ ++ return 1; ++ if (*p->cursor != '\n') ++ return 0; ++ p->cursor++; ++ p->line_no++; ++ lex_space(p); ++ return 1; ++} ++ ++static int lex_wsword(struct sbg_parser *p, struct sbg_string *rs) ++{ ++ char *s = p->cursor, *c = s; ++ ++ if (s == p->end || *s == '\n') ++ return 0; ++ while (c < p->end && *c != '\n' && !is_space(*c)) ++ c++; ++ rs->s = s; ++ rs->e = p->cursor = c; ++ lex_space(p); ++ return 1; ++} ++ ++static int lex_name(struct sbg_parser *p, struct sbg_string *rs) ++{ ++ char *s = p->cursor, *c = s; ++ ++ while (c < p->end && ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') ++ || (*c >= '0' && *c <= '9') || *c == '_' || *c == '-')) ++ c++; ++ if (c == s) ++ return 0; ++ rs->s = s; ++ rs->e = p->cursor = c; ++ return 1; ++} ++ ++static int lex_time(struct sbg_parser *p, int64_t *rt) ++{ ++ int r = str_to_time(p->cursor, rt); ++ p->cursor += r; ++ return r > 0; ++} ++ ++#define FORWARD_ERROR(c) \ ++ do { \ ++ int errcode = c; \ ++ if (errcode <= 0) \ ++ return errcode ? errcode : AVERROR_INVALIDDATA; \ ++ } while(0); ++ ++static int parse_immediate(struct sbg_parser *p) ++{ ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "immediate sequences not yet implemented"); ++ return AVERROR_PATCHWELCOME; ++} ++ ++static int parse_preprogrammed(struct sbg_parser *p) ++{ ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "preprogrammed sequences not yet implemented"); ++ return AVERROR_PATCHWELCOME; ++} ++ ++static int parse_optarg(struct sbg_parser *p, char o, struct sbg_string *r) ++{ ++ if (!lex_wsword(p, r)) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "option '%c' requires an argument", o); ++ return AVERROR_INVALIDDATA; ++ } ++ return 1; ++} ++ ++static int parse_options(struct sbg_parser *p) ++{ ++ struct sbg_string ostr, oarg; ++ char mode = 0; ++ int r; ++ char *tptr; ++ double v; ++ ++ if (p->cursor == p->end || *p->cursor != '-') ++ return 0; ++ while (lex_char(p, '-') && lex_wsword(p, &ostr)) { ++ for (; ostr.s < ostr.e; ostr.s++) { ++ char opt = *ostr.s; ++ switch (opt) { ++ case 'S': ++ p->scs.opt_start_at_first = 1; ++ break; ++ case 'E': ++ p->scs.opt_end_at_last = 1; ++ break; ++ case 'i': ++ mode = 'i'; ++ break; ++ case 'p': ++ mode = 'p'; ++ break; ++ case 'F': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ v = strtod(oarg.s, &tptr); ++ if (oarg.e != tptr) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "syntax error for option -F"); ++ return AVERROR_INVALIDDATA; ++ } ++ p->scs.opt_fade_time = v * AV_TIME_BASE / 1000; ++ break; ++ case 'L': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ r = str_to_time(oarg.s, &p->scs.opt_duration); ++ if (oarg.e != oarg.s + r) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "syntax error for option -L"); ++ return AVERROR_INVALIDDATA; ++ } ++ break; ++ case 'T': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ r = str_to_time(oarg.s, &p->scs.start_ts); ++ if (oarg.e != oarg.s + r) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "syntax error for option -T"); ++ return AVERROR_INVALIDDATA; ++ } ++ break; ++ case 'm': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ tptr = av_malloc(oarg.e - oarg.s + 1); ++ if (!tptr) ++ return AVERROR(ENOMEM); ++ memcpy(tptr, oarg.s, oarg.e - oarg.s); ++ tptr[oarg.e - oarg.s] = 0; ++ av_free(p->scs.opt_mix); ++ p->scs.opt_mix = tptr; ++ break; ++ case 'q': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ v = strtod(oarg.s, &tptr); ++ if (oarg.e != tptr) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "syntax error for option -q"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (v != 1) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "speed factor other than 1 not supported"); ++ return AVERROR_PATCHWELCOME; ++ } ++ break; ++ case 'r': ++ FORWARD_ERROR(parse_optarg(p, opt, &oarg)); ++ r = strtol(oarg.s, &tptr, 10); ++ if (oarg.e != tptr) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "syntax error for option -r"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (r < 40) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "invalid sample rate"); ++ return AVERROR_PATCHWELCOME; ++ } ++ p->scs.sample_rate = r; ++ break; ++ default: ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "unknown option: '%c'", *ostr.s); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ } ++ switch (mode) { ++ case 'i': ++ return parse_immediate(p); ++ case 'p': ++ return parse_preprogrammed(p); ++ case 0: ++ if (!lex_line_end(p)) ++ return AVERROR_INVALIDDATA; ++ return 1; ++ } ++ return AVERROR_BUG; ++} ++ ++static int parse_timestamp(struct sbg_parser *p, ++ struct sbg_timestamp *rts, int64_t *rrel) ++{ ++ int64_t abs = 0, rel = 0, dt; ++ char type = 0; ++ int r; ++ ++ if (lex_fixed(p, "NOW", 3)) { ++ type = 'N'; ++ r = 1; ++ } else { ++ r = lex_time(p, &abs); ++ if (r) ++ type = 'T'; ++ } ++ while (lex_char(p, '+')) { ++ if (!lex_time(p, &dt)) ++ return AVERROR_INVALIDDATA; ++ rel += dt; ++ r = 1; ++ } ++ if (r) { ++ if (!lex_space(p)) ++ return AVERROR_INVALIDDATA; ++ rts->type = type; ++ rts->t = abs; ++ *rrel = rel; ++ } ++ return r; ++} ++ ++static int parse_fade(struct sbg_parser *p, struct sbg_fade *fr) ++{ ++ struct sbg_fade f; ++ ++ if (lex_char(p, '<')) ++ f.in = SBG_FADE_SILENCE; ++ else if (lex_char(p, '-')) ++ f.in = SBG_FADE_SAME; ++ else if (lex_char(p, '=')) ++ f.in = SBG_FADE_ADAPT; ++ else ++ return 0; ++ if (lex_char(p, '>')) ++ f.out = SBG_FADE_SILENCE; ++ else if (lex_char(p, '-')) ++ f.out = SBG_FADE_SAME; ++ else if (lex_char(p, '=')) ++ f.out = SBG_FADE_ADAPT; ++ else ++ return AVERROR_INVALIDDATA; ++ *fr = f; ++ return 1; ++} ++ ++static int parse_time_sequence(struct sbg_parser *p, int inblock) ++{ ++ struct sbg_timestamp ts; ++ int64_t rel_ts; ++ int r; ++ struct sbg_fade fade = { SBG_FADE_SAME, SBG_FADE_SAME, 0 }; ++ struct sbg_string name; ++ struct sbg_script_tseq *tseq; ++ ++ r = parse_timestamp(p, &ts, &rel_ts); ++ if (!r) ++ return 0; ++ if (r < 0) ++ return r; ++ if (ts.type) { ++ if (inblock) ++ return AVERROR_INVALIDDATA; ++ p->current_time.type = ts.type; ++ p->current_time.t = ts.t; ++ } else if(!inblock && !p->current_time.type) { ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "relative time without previous absolute time"); ++ return AVERROR_INVALIDDATA; ++ } ++ ts.type = p->current_time.type; ++ ts.t = p->current_time.t + rel_ts; ++ r = parse_fade(p, &fade); ++ if (r < 0) ++ return r; ++ lex_space(p); ++ if (!lex_name(p, &name)) ++ return AVERROR_INVALIDDATA; ++ lex_space(p); ++ if (lex_fixed(p, "->", 2)) { ++ fade.slide = SBG_FADE_ADAPT; ++ lex_space(p); ++ } ++ if (!lex_line_end(p)) ++ return AVERROR_INVALIDDATA; ++ tseq = inblock ? ++ alloc_array_elem((void **)&p->scs.block_tseq, sizeof(*tseq), ++ &p->nb_block_tseq, &p->nb_block_tseq_max) : ++ alloc_array_elem((void **)&p->scs.tseq, sizeof(*tseq), ++ &p->scs.nb_tseq, &p->nb_tseq_max); ++ if (!tseq) ++ return AVERROR(ENOMEM); ++ tseq->ts = ts; ++ tseq->name = name.s; ++ tseq->name_len = name.e - name.s; ++ tseq->fade = fade; ++ return 1; ++} ++ ++static int parse_wave_def(struct sbg_parser *p, int wavenum) ++{ ++ snprintf(p->err_msg, sizeof(p->err_msg), ++ "waveform definitions not yet implemented"); ++ return AVERROR_PATCHWELCOME; ++} ++ ++static int parse_block_def(struct sbg_parser *p, ++ struct sbg_script_definition *def) ++{ ++ int r, tseq; ++ ++ lex_space(p); ++ if (!lex_line_end(p)) ++ return AVERROR_INVALIDDATA; ++ tseq = p->nb_block_tseq; ++ while (1) { ++ r = parse_time_sequence(p, 1); ++ if (r < 0) ++ return r; ++ if (!r) ++ break; ++ } ++ if (!lex_char(p, '}')) ++ return AVERROR_INVALIDDATA; ++ lex_space(p); ++ if (!lex_line_end(p)) ++ return AVERROR_INVALIDDATA; ++ def->type = 'B'; ++ def->elements = tseq; ++ def->nb_elements = p->nb_block_tseq - tseq; ++ if (!def->nb_elements) ++ return AVERROR_INVALIDDATA; ++ return 1; ++} ++ ++static int parse_volume(struct sbg_parser *p, int *vol) ++{ ++ double v; ++ ++ if (!lex_char(p, '/')) ++ return 0; ++ if (!lex_double(p, &v)) ++ return AVERROR_INVALIDDATA; ++ if (scale_double(p->log, v, 0.01, vol)) ++ return AVERROR(ERANGE); ++ return 1; ++} ++ ++static int parse_synth_channel_sine(struct sbg_parser *p, ++ struct sbg_script_synth *synth) ++{ ++ double carrierf, beatf; ++ int carrier, beat, vol; ++ ++ if (!lex_double(p, &carrierf)) ++ return 0; ++ if (!lex_double(p, &beatf)) ++ beatf = 0; ++ FORWARD_ERROR(parse_volume(p, &vol)); ++ if (scale_double(p->log, carrierf, 1, &carrier) < 0 || ++ scale_double(p->log, beatf, 1, &beat) < 0) ++ return AVERROR(EDOM); ++ synth->type = SBG_TYPE_SINE; ++ synth->carrier = carrier; ++ synth->beat = beat; ++ synth->vol = vol; ++ return 1; ++} ++ ++static int parse_synth_channel_pink(struct sbg_parser *p, ++ struct sbg_script_synth *synth) ++{ ++ int vol; ++ ++ if (!lex_fixed(p, "pink", 4)) ++ return 0; ++ FORWARD_ERROR(parse_volume(p, &vol)); ++ synth->type = SBG_TYPE_NOISE; ++ synth->vol = vol; ++ return 1; ++} ++ ++static int parse_synth_channel_bell(struct sbg_parser *p, ++ struct sbg_script_synth *synth) ++{ ++ double carrierf; ++ int carrier, vol; ++ ++ if (!lex_fixed(p, "bell", 4)) ++ return 0; ++ if (!lex_double(p, &carrierf)) ++ return AVERROR_INVALIDDATA; ++ FORWARD_ERROR(parse_volume(p, &vol)); ++ if (scale_double(p->log, carrierf, 1, &carrier) < 0) ++ return AVERROR(EDOM); ++ synth->type = SBG_TYPE_BELL; ++ synth->carrier = carrier; ++ synth->vol = vol; ++ return 1; ++} ++ ++static int parse_synth_channel_mix(struct sbg_parser *p, ++ struct sbg_script_synth *synth) ++{ ++ int vol; ++ ++ if (!lex_fixed(p, "mix", 3)) ++ return 0; ++ FORWARD_ERROR(parse_volume(p, &vol)); ++ synth->type = SBG_TYPE_MIX; ++ synth->vol = vol; ++ return 1; ++} ++ ++static int parse_synth_channel_spin(struct sbg_parser *p, ++ struct sbg_script_synth *synth) ++{ ++ double carrierf, beatf; ++ int carrier, beat, vol; ++ ++ if (!lex_fixed(p, "spin:", 5)) ++ return 0; ++ if (!lex_double(p, &carrierf)) ++ return AVERROR_INVALIDDATA; ++ if (!lex_double(p, &beatf)) ++ return AVERROR_INVALIDDATA; ++ FORWARD_ERROR(parse_volume(p, &vol)); ++ if (scale_double(p->log, carrierf, 1, &carrier) < 0 || ++ scale_double(p->log, beatf, 1, &beat) < 0) ++ return AVERROR(EDOM); ++ synth->type = SBG_TYPE_SPIN; ++ synth->carrier = carrier; ++ synth->beat = beat; ++ synth->vol = vol; ++ return 1; ++} ++ ++static int parse_synth_channel(struct sbg_parser *p) ++{ ++ int r; ++ struct sbg_script_synth *synth; ++ ++ synth = alloc_array_elem((void **)&p->scs.synth, sizeof(*synth), ++ &p->scs.nb_synth, &p->nb_synth_max); ++ if (!synth) ++ return AVERROR(ENOMEM); ++ r = lex_char(p, '-'); ++ if (!r) ++ r = parse_synth_channel_pink(p, synth); ++ if (!r) ++ r = parse_synth_channel_bell(p, synth); ++ if (!r) ++ r = parse_synth_channel_mix(p, synth); ++ if (!r) ++ r = parse_synth_channel_spin(p, synth); ++ /* Unimplemented: wave%d:%f%f/vol (carrier, beat) */ ++ if (!r) ++ r = parse_synth_channel_sine(p, synth); ++ if (r <= 0) ++ p->scs.nb_synth--; ++ return r; ++} ++ ++static int parse_synth_def(struct sbg_parser *p, ++ struct sbg_script_definition *def) ++{ ++ int r, synth; ++ ++ synth = p->scs.nb_synth; ++ while (1) { ++ r = parse_synth_channel(p); ++ if (r < 0) ++ return r; ++ if (!r || !lex_space(p)) ++ break; ++ } ++ lex_space(p); ++ if (synth == p->scs.nb_synth) ++ return AVERROR_INVALIDDATA; ++ if (!lex_line_end(p)) ++ return AVERROR_INVALIDDATA; ++ def->type = 'S'; ++ def->elements = synth; ++ def->nb_elements = p->scs.nb_synth - synth; ++ return 1; ++} ++ ++static int parse_named_def(struct sbg_parser *p) ++{ ++ char *cursor_save = p->cursor; ++ struct sbg_string name; ++ struct sbg_script_definition *def; ++ ++ if (!lex_name(p, &name) || !lex_char(p, ':') || !lex_space(p)) { ++ p->cursor = cursor_save; ++ return 0; ++ } ++ if (name.e - name.s == 6 && !memcmp(name.s, "wave", 4) && ++ name.s[4] >= '0' && name.s[4] <= '9' && ++ name.s[5] >= '0' && name.s[5] <= '9') { ++ int wavenum = (name.s[4] - '0') * 10 + (name.s[5] - '0'); ++ return parse_wave_def(p, wavenum); ++ } ++ def = alloc_array_elem((void **)&p->scs.def, sizeof(*def), ++ &p->scs.nb_def, &p->nb_def_max); ++ if (!def) ++ return AVERROR(ENOMEM); ++ def->name = name.s; ++ def->name_len = name.e - name.s; ++ if (lex_char(p, '{')) ++ return parse_block_def(p, def); ++ return parse_synth_def(p, def); ++} ++ ++static void free_script(struct sbg_script *s) ++{ ++ av_freep(&s->def); ++ av_freep(&s->synth); ++ av_freep(&s->tseq); ++ av_freep(&s->block_tseq); ++ av_freep(&s->events); ++ av_freep(&s->opt_mix); ++} ++ ++static int parse_script(void *log, char *script, int script_len, ++ struct sbg_script *rscript) ++{ ++ struct sbg_parser sp = { ++ .log = log, ++ .script = script, ++ .end = script + script_len, ++ .cursor = script, ++ .line_no = 1, ++ .err_msg = "", ++ .scs = { ++ /* default values */ ++ .start_ts = AV_NOPTS_VALUE, ++ .sample_rate = 44100, ++ .opt_fade_time = 60 * AV_TIME_BASE, ++ }, ++ }; ++ int r; ++ ++ lex_space(&sp); ++ while (sp.cursor < sp.end) { ++ r = parse_options(&sp); ++ if (r < 0) ++ goto fail; ++ if (!r && !lex_line_end(&sp)) ++ break; ++ } ++ while (sp.cursor < sp.end) { ++ r = parse_named_def(&sp); ++ if (!r) ++ r = parse_time_sequence(&sp, 0); ++ if (!r) ++ r = lex_line_end(&sp) ? 1 : AVERROR_INVALIDDATA; ++ if (r < 0) ++ goto fail; ++ } ++ *rscript = sp.scs; ++ return 1; ++fail: ++ free_script(&sp.scs); ++ if (!*sp.err_msg) ++ if (r == AVERROR_INVALIDDATA) ++ snprintf(sp.err_msg, sizeof(sp.err_msg), "syntax error"); ++ if (log && *sp.err_msg) { ++ const char *ctx = sp.cursor; ++ const char *ectx = av_x_if_null(memchr(ctx, '\n', sp.end - sp.cursor), ++ sp.end); ++ int lctx = ectx - ctx; ++ const char *quote = "\""; ++ if (lctx > 0 && ctx[lctx - 1] == '\r') ++ lctx--; ++ if (lctx == 0) { ++ ctx = "the end of line"; ++ lctx = strlen(ctx); ++ quote = ""; ++ } ++ av_log(log, AV_LOG_ERROR, "Error line %d: %s near %s%.*s%s.\n", ++ sp.line_no, sp.err_msg, quote, lctx, ctx, quote); ++ } ++ return r; ++} ++ ++static int read_whole_file(AVIOContext *io, int max_size, char **rbuf) ++{ ++ char *buf = NULL; ++ int size = 0, bufsize = 0, r; ++ ++ while (1) { ++ if (bufsize - size < 1024) { ++ bufsize = FFMIN(FFMAX(2 * bufsize, 8192), max_size); ++ if (bufsize - size < 2) { ++ size = AVERROR(EFBIG); ++ goto fail; ++ } ++ buf = av_realloc_f(buf, bufsize, 1); ++ if (!buf) { ++ size = AVERROR(ENOMEM); ++ goto fail; ++ } ++ } ++ r = avio_read(io, buf, bufsize - size - 1); ++ if (r == AVERROR_EOF) ++ break; ++ if (r < 0) ++ goto fail; ++ size += r; ++ } ++ buf[size] = 0; ++ *rbuf = buf; ++ return size; ++fail: ++ av_free(buf); ++ return size; ++} ++ ++static void expand_timestamps(void *log, struct sbg_script *s) ++{ ++ int i, nb_rel = 0; ++ int64_t now, cur_ts, delta = 0; ++ ++ for (i = 0; i < s->nb_tseq; i++) ++ nb_rel += s->tseq[i].ts.type == 'N'; ++ if (nb_rel == s->nb_tseq) { ++ /* All ts are relative to NOW: consider NOW = 0 */ ++ now = 0; ++ if (s->start_ts != AV_NOPTS_VALUE) ++ av_log(log, AV_LOG_WARNING, ++ "Start time ignored in a purely relative script.\n"); ++ } else if (nb_rel == 0 && s->start_ts != AV_NOPTS_VALUE || ++ s->opt_start_at_first) { ++ /* All ts are absolute and start time is specified */ ++ if (s->start_ts == AV_NOPTS_VALUE) ++ s->start_ts = s->tseq[0].ts.t; ++ now = s->start_ts; ++ } else { ++ /* Mixed relative/absolute ts: expand */ ++ time_t now0; ++ struct tm *tm; ++ ++ av_log(log, AV_LOG_WARNING, ++ "Scripts with mixed absolute and relative timestamps can give " ++ "unexpected results (pause, seeking, time zone change).\n"); ++#undef time ++ time(&now0); ++ tm = localtime(&now0); ++ now = tm ? tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec : ++ now0 % DAY; ++ av_log(log, AV_LOG_INFO, "Using %02d:%02d:%02d as NOW.\n", ++ (int)(now / 3600), (int)(now / 60) % 60, (int)now % 60); ++ now *= AV_TIME_BASE; ++ for (i = 0; i < s->nb_tseq; i++) { ++ if (s->tseq[i].ts.type == 'N') { ++ s->tseq[i].ts.t += now; ++ s->tseq[i].ts.type = 'T'; /* not necessary */ ++ } ++ } ++ } ++ if (s->start_ts == AV_NOPTS_VALUE) ++ s->start_ts = s->opt_start_at_first ? s->tseq[0].ts.t : now; ++ s->end_ts = s->opt_duration ? s->start_ts + s->opt_duration : ++ AV_NOPTS_VALUE; /* may be overridden later by -E option */ ++ cur_ts = now; ++ for (i = 0; i < s->nb_tseq; i++) { ++ if (s->tseq[i].ts.t + delta < cur_ts) ++ delta += DAY_TS; ++ cur_ts = s->tseq[i].ts.t += delta; ++ } ++} ++ ++static int expand_tseq(void *log, struct sbg_script *s, int *nb_ev_max, ++ int64_t t0, struct sbg_script_tseq *tseq) ++{ ++ int i, r; ++ struct sbg_script_definition *def; ++ struct sbg_script_tseq *be; ++ struct sbg_script_event *ev; ++ ++ if (tseq->lock++) { ++ av_log(log, 16, "Recursion loop on \"%.*s\"\n", ++ tseq->name_len, tseq->name); ++ return AVERROR(EINVAL); ++ } ++ t0 += tseq->ts.t; ++ for (i = 0; i < s->nb_def; i++) { ++ if (s->def[i].name_len == tseq->name_len && ++ !memcmp(s->def[i].name, tseq->name, tseq->name_len)) ++ break; ++ } ++ if (i >= s->nb_def) { ++ av_log(log, 16, "Tone-set \"%.*s\" not defined\n", ++ tseq->name_len, tseq->name); ++ return AVERROR(EINVAL); ++ } ++ def = &s->def[i]; ++ if (def->type == 'B') { ++ be = s->block_tseq + def->elements; ++ for (i = 0; i < def->nb_elements; i++) { ++ r = expand_tseq(log, s, nb_ev_max, t0, &be[i]); ++ if (r < 0) ++ return r; ++ } ++ } else { ++ ev = alloc_array_elem((void **)&s->events, sizeof(*ev), ++ &s->nb_events, nb_ev_max); ++ ev->ts = tseq->ts.t; ++ ev->elements = def->elements; ++ ev->nb_elements = def->nb_elements; ++ ev->fade = tseq->fade; ++ } ++ tseq->lock--; ++ return 0; ++} ++ ++static int expand_script(void *log, struct sbg_script *s) ++{ ++ int i, r, nb_events_max = 0; ++ ++ expand_timestamps(log, s); ++ for (i = 0; i < s->nb_tseq; i++) { ++ r = expand_tseq(log, s, &nb_events_max, 0, &s->tseq[i]); ++ if (r < 0) ++ return r; ++ } ++ if (!s->nb_events) { ++ av_log(log, AV_LOG_ERROR, "No events in script\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ if (s->opt_end_at_last) ++ s->end_ts = s->events[s->nb_events - 1].ts; ++ return 0; ++} ++ ++static int add_interval(struct ws_intervals *inter, ++ enum ws_interval_type type, uint32_t channels, int ref, ++ int64_t ts1, int32_t f1, int32_t a1, ++ int64_t ts2, int32_t f2, int32_t a2) ++{ ++ struct ws_interval *i, *ri; ++ ++ if (ref >= 0) { ++ ri = &inter->inter[ref]; ++ /* ref and new intervals are constant, identical and adjacent */ ++ if (ri->type == type && ri->channels == channels && ++ ri->f1 == ri->f2 && ri->f2 == f1 && f1 == f2 && ++ ri->a1 == ri->a2 && ri->a2 == a1 && a1 == a2 && ++ ri->ts2 == ts1) { ++ ri->ts2 = ts2; ++ return ref; ++ } ++ } ++ i = alloc_array_elem((void **)&inter->inter, sizeof(*i), ++ &inter->nb_inter, &inter->max_inter); ++ if (!i) ++ return AVERROR(ENOMEM); ++ i->ts1 = ts1; ++ i->ts2 = ts2; ++ i->type = type; ++ i->channels = channels; ++ i->f1 = f1; ++ i->f2 = f2; ++ i->a1 = a1; ++ i->a2 = a2; ++ i->phi = ref >= 0 ? ref | 0x80000000 : 0; ++ return i - inter->inter; ++} ++ ++static int add_bell(struct ws_intervals *inter, struct sbg_script *s, ++ int64_t ts1, int64_t ts2, int32_t f, int32_t a) ++{ ++ /* SBaGen uses an exponential decrease every 50ms. ++ We approximate it with piecewise affine segments. */ ++ int32_t cpoints[][2] = { ++ { 2, a }, ++ { 4, a - a / 4 }, ++ { 8, a / 2 }, ++ { 16, a / 4 }, ++ { 25, a / 10 }, ++ { 50, a / 80 }, ++ { 75, 0 }, ++ }; ++ int i, r; ++ int64_t dt = s->sample_rate / 20, ts3 = ts1, ts4; ++ for (i = 0; i < FF_ARRAY_ELEMS(cpoints); i++) { ++ ts4 = FFMIN(ts2, ts1 + cpoints[i][0] * dt); ++ r = add_interval(inter, WS_SINE, 3, -1, ++ ts3, f, a, ts4, f, cpoints[i][1]); ++ if (r < 0) ++ return r; ++ ts3 = ts4; ++ a = cpoints[i][1]; ++ } ++ return 0; ++} ++ ++static int generate_interval(void *log, struct sbg_script *s, ++ struct ws_intervals *inter, ++ int64_t ts1, int64_t ts2, ++ struct sbg_script_synth *s1, ++ struct sbg_script_synth *s2, ++ int transition) ++{ ++ int r; ++ ++ if (ts2 <= ts1 || (s1->vol == 0 && s2->vol == 0)) ++ return 0; ++ switch (s1->type) { ++ case SBG_TYPE_NONE: ++ break; ++ case SBG_TYPE_SINE: ++ if (s1->beat == 0 && s2->beat == 0) { ++ r = add_interval(inter, WS_SINE, 3, s1->ref.l, ++ ts1, s1->carrier, s1->vol, ++ ts2, s2->carrier, s2->vol); ++ if (r < 0) ++ return r; ++ s2->ref.l = s2->ref.r = r; ++ } else { ++ r = add_interval(inter, WS_SINE, 1, s1->ref.l, ++ ts1, s1->carrier + s1->beat / 2, s1->vol, ++ ts2, s2->carrier + s2->beat / 2, s2->vol); ++ if (r < 0) ++ return r; ++ s2->ref.l = r; ++ r = add_interval(inter, WS_SINE, 2, s1->ref.r, ++ ts1, s1->carrier - s1->beat / 2, s1->vol, ++ ts2, s2->carrier - s2->beat / 2, s2->vol); ++ if (r < 0) ++ return r; ++ s2->ref.r = r; ++ } ++ break; ++ ++ case SBG_TYPE_BELL: ++ if (transition == 2) { ++ r = add_bell(inter, s, ts1, ts2, s1->carrier, s2->vol); ++ if (r < 0) ++ return r; ++ } ++ break; ++ ++ case SBG_TYPE_SPIN: ++ av_log(log, AV_LOG_WARNING, "Spinning noise not implemented, " ++ "using pink noise instead.\n"); ++ /* fall through */ ++ case SBG_TYPE_NOISE: ++ /* SBaGen's pink noise generator uses: ++ - 1 band of white noise, mean square: 1/3; ++ - 9 bands of subsampled white noise with linear ++ interpolation, mean square: 2/3 each; ++ with 1/10 weight each: the total mean square is 7/300. ++ Our pink noise generator uses 8 bands of white noise with ++ rectangular subsampling: the total mean square is 1/24. ++ Therefore, to match SBaGen's volume, we must multiply vol by ++ sqrt((7/300) / (1/24)) = sqrt(14/25) =~ 0.748 ++ */ ++ r = add_interval(inter, WS_NOISE, 3, s1->ref.l, ++ ts1, 0, s1->vol - s1->vol / 4, ++ ts2, 0, s2->vol - s2->vol / 4); ++ if (r < 0) ++ return r; ++ s2->ref.l = s2->ref.r = r; ++ break; ++ ++ case SBG_TYPE_MIX: ++ /* Unimplemented: silence; warning present elsewhere */ ++ default: ++ av_log(log, AV_LOG_ERROR, ++ "Type %d is not implemented\n", s1->type); ++ return AVERROR_PATCHWELCOME; ++ } ++ return 0; ++} ++ ++static int generate_plateau(void *log, struct sbg_script *s, ++ struct ws_intervals *inter, ++ struct sbg_script_event *ev1) ++{ ++ int64_t ts1 = ev1->ts_int, ts2 = ev1->ts_trans; ++ int i, r; ++ struct sbg_script_synth *s1; ++ ++ for (i = 0; i < ev1->nb_elements; i++) { ++ s1 = &s->synth[ev1->elements + i]; ++ r = generate_interval(log, s, inter, ts1, ts2, s1, s1, 0); ++ if (r < 0) ++ return r; ++ } ++ return 0; ++} ++ ++/* ++ ++ ts1 ts2 ts1 tsmid ts2 ++ | | | | | ++ v v v | v ++____ ____ v ____ ++ ''''.... ''.. ..'' ++ ''''....____ ''....'' ++ ++ compatible transition incompatible transition ++ */ ++ ++static int generate_transition(void *log, struct sbg_script *s, ++ struct ws_intervals *inter, ++ struct sbg_script_event *ev1, ++ struct sbg_script_event *ev2) ++{ ++ int64_t ts1 = ev1->ts_trans, ts2 = ev1->ts_next; ++ /* (ts1 + ts2) / 2 without overflow */ ++ int64_t tsmid = (ts1 >> 1) + (ts2 >> 1) + (ts1 & ts2 & 1); ++ enum sbg_fade_type type = ev1->fade.slide | (ev1->fade.out & ev2->fade.in); ++ int nb_elements = FFMAX(ev1->nb_elements, ev2->nb_elements); ++ struct sbg_script_synth *s1, *s2, s1mod, s2mod, smid; ++ int pass, i, r; ++ ++ for (pass = 0; pass < 2; pass++) { ++ /* pass = 0 -> compatible and first half of incompatible ++ pass = 1 -> second half of incompatible ++ Using two passes like that ensures that the intervals are generated ++ in increasing order according to their start timestamp. ++ Otherwise it would be necessary to sort them ++ while keeping the mutual references. ++ */ ++ for (i = 0; i < nb_elements; i++) { ++ s1 = i < ev1->nb_elements ? &s->synth[ev1->elements + i] : &s1mod; ++ s2 = i < ev2->nb_elements ? &s->synth[ev2->elements + i] : &s2mod; ++ s1mod = s1 != &s1mod ? *s1 : (struct sbg_script_synth){ 0 }; ++ s2mod = s2 != &s2mod ? *s2 : (struct sbg_script_synth){ 0 }; ++ if (ev1->fade.slide) { ++ /* for slides, and only for slides, silence ("-") is equivalent ++ to anything with volume 0 */ ++ if (s1mod.type == SBG_TYPE_NONE) { ++ s1mod = s2mod; ++ s1mod.vol = 0; ++ } else if (s2mod.type == SBG_TYPE_NONE) { ++ s2mod = s1mod; ++ s2mod.vol = 0; ++ } ++ } ++ if (s1mod.type == s2mod.type && ++ s1mod.type != SBG_TYPE_BELL && ++ (type == SBG_FADE_ADAPT || ++ (s1mod.carrier == s2mod.carrier && ++ s1mod.beat == s2mod.beat))) { ++ /* compatible: single transition */ ++ if (!pass) { ++ r = generate_interval(log, s, inter, ++ ts1, ts2, &s1mod, &s2mod, 3); ++ if (r < 0) ++ return r; ++ s2->ref = s2mod.ref; ++ } ++ } else { ++ /* incompatible: silence at midpoint */ ++ if (!pass) { ++ smid = s1mod; ++ smid.vol = 0; ++ r = generate_interval(log, s, inter, ++ ts1, tsmid, &s1mod, &smid, 1); ++ if (r < 0) ++ return r; ++ } else { ++ smid = s2mod; ++ smid.vol = 0; ++ r = generate_interval(log, s, inter, ++ tsmid, ts2, &smid, &s2mod, 2); ++ if (r < 0) ++ return r; ++ s2->ref = s2mod.ref; ++ } ++ } ++ } ++ } ++ return 0; ++} ++ ++/* ++ ev1 trats ev2 intts endts ev3 ++ | | | | | | ++ v v v v v v ++ ________________ ++.... .... .... ++ '''....________________....''' '''...._______________ ++ ++\_________/\______________/\_________/\______________/\_________/\_____________/ ++ tr x->1 int1 tr 1->2 int2 tr 2->3 int3 ++ */ ++ ++static int generate_intervals(void *log, struct sbg_script *s, int sample_rate, ++ struct ws_intervals *inter) ++{ ++ int64_t trans_time = s->opt_fade_time / 2; ++ struct sbg_script_event ev0, *ev1, *ev2; ++ int64_t period; ++ int i, r; ++ ++ /* SBaGen handles the time before and after the extremal events, ++ and the corresponding transitions, as if the sequence were cyclic ++ with a 24-hours period. */ ++ period = s->events[s->nb_events - 1].ts - s->events[0].ts; ++ period = (period + (DAY_TS - 1)) / DAY_TS * DAY_TS; ++ period = FFMAX(period, DAY_TS); ++ ++ /* Prepare timestamps for transitions */ ++ for (i = 0; i < s->nb_events; i++) { ++ ev1 = &s->events[i]; ++ ev2 = &s->events[(i + 1) % s->nb_events]; ++ ev1->ts_int = ev1->ts; ++ ev1->ts_trans = ev1->fade.slide ? ev1->ts ++ : ev2->ts + (ev1 < ev2 ? 0 : period); ++ } ++ for (i = 0; i < s->nb_events; i++) { ++ ev1 = &s->events[i]; ++ ev2 = &s->events[(i + 1) % s->nb_events]; ++ if (!ev1->fade.slide) { ++ ev1->ts_trans = FFMAX(ev1->ts_int, ev1->ts_trans - trans_time); ++ ev2->ts_int = FFMIN(ev2->ts_trans, ev2->ts_int + trans_time); ++ } ++ ev1->ts_next = ev2->ts_int + (ev1 < ev2 ? 0 : period); ++ } ++ ++ /* Pseudo event before the first one */ ++ ev0 = s->events[s->nb_events - 1]; ++ ev0.ts_int -= period; ++ ev0.ts_trans -= period; ++ ev0.ts_next -= period; ++ ++ /* Convert timestamps */ ++ for (i = -1; i < s->nb_events; i++) { ++ ev1 = i < 0 ? &ev0 : &s->events[i]; ++ ev1->ts_int = av_rescale(ev1->ts_int, sample_rate, AV_TIME_BASE); ++ ev1->ts_trans = av_rescale(ev1->ts_trans, sample_rate, AV_TIME_BASE); ++ ev1->ts_next = av_rescale(ev1->ts_next, sample_rate, AV_TIME_BASE); ++ } ++ ++ /* Generate intervals */ ++ for (i = 0; i < s->nb_synth; i++) ++ s->synth[i].ref.l = s->synth[i].ref.r = -1; ++ for (i = -1; i < s->nb_events; i++) { ++ ev1 = i < 0 ? &ev0 : &s->events[i]; ++ ev2 = &s->events[(i + 1) % s->nb_events]; ++ r = generate_plateau(log, s, inter, ev1); ++ if (r < 0) ++ return r; ++ r = generate_transition(log, s, inter, ev1, ev2); ++ if (r < 0) ++ return r; ++ } ++ if (!inter->nb_inter) ++ av_log(log, AV_LOG_WARNING, "Completely silent script.\n"); ++ return 0; ++} ++ ++static int encode_intervals(struct sbg_script *s, AVCodecContext *avc, ++ struct ws_intervals *inter) ++{ ++ int i, edata_size = 4; ++ uint8_t *edata; ++ ++ for (i = 0; i < inter->nb_inter; i++) { ++ edata_size += inter->inter[i].type == WS_SINE ? 44 : ++ inter->inter[i].type == WS_NOISE ? 32 : 0; ++ if (edata_size < 0) ++ return AVERROR(ENOMEM); ++ } ++ edata = av_malloc(edata_size); ++ if (!edata) ++ return AVERROR(ENOMEM); ++ avc->extradata = edata; ++ avc->extradata_size = edata_size; ++ ++#define ADD_EDATA32(v) do { AV_WL32(edata, (v)); edata += 4; } while(0) ++#define ADD_EDATA64(v) do { AV_WL64(edata, (v)); edata += 8; } while(0) ++ ADD_EDATA32(inter->nb_inter); ++ for (i = 0; i < inter->nb_inter; i++) { ++ ADD_EDATA64(inter->inter[i].ts1); ++ ADD_EDATA64(inter->inter[i].ts2); ++ ADD_EDATA32(inter->inter[i].type); ++ ADD_EDATA32(inter->inter[i].channels); ++ switch (inter->inter[i].type) { ++ case WS_SINE: ++ ADD_EDATA32(inter->inter[i].f1); ++ ADD_EDATA32(inter->inter[i].f2); ++ ADD_EDATA32(inter->inter[i].a1); ++ ADD_EDATA32(inter->inter[i].a2); ++ ADD_EDATA32(inter->inter[i].phi); ++ break; ++ case WS_NOISE: ++ ADD_EDATA32(inter->inter[i].a1); ++ ADD_EDATA32(inter->inter[i].a2); ++ break; ++ } ++ } ++ if (edata != avc->extradata + edata_size) ++ return AVERROR_BUG; ++ return 0; ++} ++ ++static av_cold int sbg_read_probe(AVProbeData *p) ++{ ++ int r, score; ++ struct sbg_script script = { 0 }; ++ ++ r = parse_script(NULL, p->buf, p->buf_size, &script); ++ score = r < 0 || !script.nb_def || !script.nb_tseq ? 0 : ++ AVPROBE_SCORE_MAX / 3; ++ free_script(&script); ++ return score; ++} ++ ++static av_cold int sbg_read_header(AVFormatContext *avf, ++ AVFormatParameters *ap) ++{ ++ struct sbg_demuxer *sbg = avf->priv_data; ++ int r; ++ char *buf = NULL; ++ struct sbg_script script = { 0 }; ++ AVStream *st; ++ struct ws_intervals inter = { 0 }; ++ ++ r = read_whole_file(avf->pb, sbg->max_file_size, &buf); ++ if (r < 0) ++ goto fail; ++ r = parse_script(avf, buf, r, &script); ++ if (r < 0) ++ goto fail; ++ if (!sbg->sample_rate) ++ sbg->sample_rate = script.sample_rate; ++ else ++ script.sample_rate = sbg->sample_rate; ++ if (!sbg->frame_size) ++ sbg->frame_size = FFMAX(1, sbg->sample_rate / 10); ++ if (script.opt_mix) ++ av_log(avf, AV_LOG_WARNING, "Mix feature not implemented: " ++ "-m is ignored and mix channels will be silent.\n"); ++ r = expand_script(avf, &script); ++ if (r < 0) ++ goto fail; ++ av_freep(&buf); ++ r = generate_intervals(avf, &script, sbg->sample_rate, &inter); ++ if (r < 0) ++ goto fail; ++ ++ st = avformat_new_stream(avf, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->codec_id = CODEC_ID_FFWAVESYNTH; ++ st->codec->channels = 2; ++ st->codec->channel_layout = AV_CH_LAYOUT_STEREO; ++ st->codec->sample_rate = sbg->sample_rate; ++ st->codec->frame_size = sbg->frame_size; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ st->probe_packets = 0; ++ st->start_time = av_rescale(script.start_ts, ++ sbg->sample_rate, AV_TIME_BASE); ++ st->duration = script.end_ts == AV_NOPTS_VALUE ? AV_NOPTS_VALUE : ++ av_rescale(script.end_ts - script.start_ts, ++ sbg->sample_rate, AV_TIME_BASE); ++ st->cur_dts = st->start_time; ++ r = encode_intervals(&script, st->codec, &inter); ++ if (r < 0) ++ goto fail; ++ ++ av_free(inter.inter); ++ free_script(&script); ++ return 0; ++ ++fail: ++ av_free(inter.inter); ++ free_script(&script); ++ av_free(buf); ++ return r; ++} ++ ++static int sbg_read_packet(AVFormatContext *avf, AVPacket *packet) ++{ ++ int64_t ts, end_ts; ++ ++ ts = avf->streams[0]->cur_dts; ++ end_ts = ts + avf->streams[0]->codec->frame_size; ++ if (avf->streams[0]->duration != AV_NOPTS_VALUE) ++ end_ts = FFMIN(avf->streams[0]->start_time + avf->streams[0]->duration, ++ end_ts); ++ if (end_ts <= ts) ++ return AVERROR_EOF; ++ if (av_new_packet(packet, 12) < 0) ++ return AVERROR(ENOMEM); ++ packet->dts = packet->pts = ts; ++ packet->duration = end_ts - ts; ++ AV_WL64(packet->data + 0, ts); ++ AV_WL32(packet->data + 8, packet->duration); ++ return packet->size; ++} ++ ++static int sbg_read_seek2(AVFormatContext *avf, int stream_index, ++ int64_t min_ts, int64_t ts, int64_t max_ts, int flags) ++{ ++ if (flags || stream_index > 0) ++ return AVERROR(EINVAL); ++ if (stream_index < 0) ++ ts = av_rescale_q(ts, AV_TIME_BASE_Q, avf->streams[0]->time_base); ++ avf->streams[0]->cur_dts = ts; ++ return 0; ++} ++ ++#if FF_API_READ_SEEK ++static int sbg_read_seek(AVFormatContext *avf, int stream_index, ++ int64_t ts, int flags) ++{ ++ return sbg_read_seek2(avf, stream_index, ts, ts, ts, 0); ++} ++#endif ++ ++static const AVOption sbg_options[] = { ++ { "sample_rate", "", offsetof(struct sbg_demuxer, sample_rate), ++ AV_OPT_TYPE_INT, { .dbl = 0 }, 0, INT_MAX, ++ AV_OPT_FLAG_DECODING_PARAM }, ++ { "frame_size", "", offsetof(struct sbg_demuxer, frame_size), ++ AV_OPT_TYPE_INT, { .dbl = 0 }, 0, INT_MAX, ++ AV_OPT_FLAG_DECODING_PARAM }, ++ { "max_file_size", "", offsetof(struct sbg_demuxer, max_file_size), ++ AV_OPT_TYPE_INT, { .dbl = 5000000 }, 0, INT_MAX, ++ AV_OPT_FLAG_DECODING_PARAM }, ++ { NULL }, ++}; ++ ++static const AVClass sbg_demuxer_class = { ++ .class_name = "sbg_demuxer", ++ .item_name = av_default_item_name, ++ .option = sbg_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++AVInputFormat ff_sbg_demuxer = { ++ .name = "sbg", ++ .long_name = NULL_IF_CONFIG_SMALL("SBaGen binaural beats script"), ++ .priv_data_size = sizeof(struct sbg_demuxer), ++ .read_probe = sbg_read_probe, ++ .read_header = sbg_read_header, ++ .read_packet = sbg_read_packet, ++#if FF_API_READ_SEEK ++ .read_seek = sbg_read_seek, ++#endif ++ .read_seek2 = sbg_read_seek2, ++ .extensions = "sbg", ++ .priv_class = &sbg_demuxer_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sdp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sdp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sdp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sdp.c 2012-05-14 14:08:55.192357250 +0200 +@@ -21,7 +21,11 @@ + #include + #include "libavutil/avstring.h" + #include "libavutil/base64.h" ++#include "libavutil/dict.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/opt.h" + #include "libavcodec/xiph.h" ++#include "libavcodec/mpeg4audio.h" + #include "avformat.h" + #include "internal.h" + #include "avc.h" +@@ -136,7 +140,7 @@ + if (p) { + char buff[64]; + +- if (find_info_tag(buff, sizeof(buff), "ttl", p)) { ++ if (av_find_info_tag(buff, sizeof(buff), "ttl", p)) { + *ttl = strtol(buff, NULL, 10); + } else { + *ttl = 5; +@@ -152,6 +156,8 @@ + char *psets, *p; + const uint8_t *r; + const char *pset_string = "; sprop-parameter-sets="; ++ uint8_t *orig_extradata = NULL; ++ int orig_extradata_size = 0; + + if (c->extradata_size > MAX_EXTRADATA_SIZE) { + av_log(c, AV_LOG_ERROR, "Too much extradata!\n"); +@@ -168,6 +174,15 @@ + + return NULL; + } ++ ++ orig_extradata_size = c->extradata_size; ++ orig_extradata = av_mallocz(orig_extradata_size + ++ FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!orig_extradata) { ++ av_bitstream_filter_close(bsfc); ++ return NULL; ++ } ++ memcpy(orig_extradata, c->extradata, orig_extradata_size); + av_bitstream_filter_filter(bsfc, c, NULL, &dummy_p, &dummy_int, NULL, 0, 0); + av_bitstream_filter_close(bsfc); + } +@@ -175,6 +190,7 @@ + psets = av_mallocz(MAX_PSET_SIZE); + if (psets == NULL) { + av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the parameter sets.\n"); ++ av_free(orig_extradata); + return NULL; + } + memcpy(psets, pset_string, strlen(pset_string)); +@@ -204,6 +220,11 @@ + p += strlen(p); + r = r1; + } ++ if (orig_extradata) { ++ av_free(c->extradata); ++ c->extradata = orig_extradata; ++ c->extradata_size = orig_extradata_size; ++ } + + return psets; + } +@@ -248,7 +269,7 @@ + return NULL; + } + +- if (ff_split_xiph_headers(c->extradata, c->extradata_size, ++ if (avpriv_split_xiph_headers(c->extradata, c->extradata_size, + first_header_size, header_start, + header_len) < 0) { + av_log(c, AV_LOG_ERROR, "Extradata corrupt.\n"); +@@ -298,7 +319,72 @@ + return NULL; + } + +-static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type) ++static int latm_context2profilelevel(AVCodecContext *c) ++{ ++ /* MP4A-LATM ++ * The RTP payload format specification is described in RFC 3016 ++ * The encoding specifications are provided in ISO/IEC 14496-3 */ ++ ++ int profile_level = 0x2B; ++ ++ /* TODO: AAC Profile only supports AAC LC Object Type. ++ * Different Object Types should implement different Profile Levels */ ++ ++ if (c->sample_rate <= 24000) { ++ if (c->channels <= 2) ++ profile_level = 0x28; // AAC Profile, Level 1 ++ } else if (c->sample_rate <= 48000) { ++ if (c->channels <= 2) { ++ profile_level = 0x29; // AAC Profile, Level 2 ++ } else if (c->channels <= 5) { ++ profile_level = 0x2A; // AAC Profile, Level 4 ++ } ++ } else if (c->sample_rate <= 96000) { ++ if (c->channels <= 5) { ++ profile_level = 0x2B; // AAC Profile, Level 5 ++ } ++ } ++ ++ return profile_level; ++} ++ ++static char *latm_context2config(AVCodecContext *c) ++{ ++ /* MP4A-LATM ++ * The RTP payload format specification is described in RFC 3016 ++ * The encoding specifications are provided in ISO/IEC 14496-3 */ ++ ++ uint8_t config_byte[6]; ++ int rate_index; ++ char *config; ++ ++ for (rate_index = 0; rate_index < 16; rate_index++) ++ if (avpriv_mpeg4audio_sample_rates[rate_index] == c->sample_rate) ++ break; ++ if (rate_index == 16) { ++ av_log(c, AV_LOG_ERROR, "Unsupported sample rate\n"); ++ return NULL; ++ } ++ ++ config_byte[0] = 0x40; ++ config_byte[1] = 0; ++ config_byte[2] = 0x20 | rate_index; ++ config_byte[3] = c->channels << 4; ++ config_byte[4] = 0x3f; ++ config_byte[5] = 0xc0; ++ ++ config = av_malloc(6*2+1); ++ if (!config) { ++ av_log(c, AV_LOG_ERROR, "Cannot allocate memory for the config info.\n"); ++ return NULL; ++ } ++ ff_data_to_hex(config, config_byte, 6, 1); ++ config[12] = 0; ++ ++ return config; ++} ++ ++static char *sdp_write_media_attributes(char *buff, int size, AVCodecContext *c, int payload_type, AVFormatContext *fmt) + { + char *config = NULL; + +@@ -333,24 +419,35 @@ + payload_type, config ? config : ""); + break; + case CODEC_ID_AAC: +- if (c->extradata_size) { +- config = extradata2config(c); ++ if (fmt && fmt->oformat && fmt->oformat->priv_class && ++ av_opt_flag_is_set(fmt->priv_data, "rtpflags", "latm")) { ++ config = latm_context2config(c); ++ if (!config) ++ return NULL; ++ av_strlcatf(buff, size, "a=rtpmap:%d MP4A-LATM/%d/%d\r\n" ++ "a=fmtp:%d profile-level-id=%d;cpresent=0;config=%s\r\n", ++ payload_type, c->sample_rate, c->channels, ++ payload_type, latm_context2profilelevel(c), config); + } else { +- /* FIXME: maybe we can forge config information based on the +- * codec parameters... +- */ +- av_log(c, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); +- return NULL; +- } +- if (config == NULL) { +- return NULL; ++ if (c->extradata_size) { ++ config = extradata2config(c); ++ } else { ++ /* FIXME: maybe we can forge config information based on the ++ * codec parameters... ++ */ ++ av_log(c, AV_LOG_ERROR, "AAC with no global headers is currently not supported.\n"); ++ return NULL; ++ } ++ if (config == NULL) { ++ return NULL; ++ } ++ av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" ++ "a=fmtp:%d profile-level-id=1;" ++ "mode=AAC-hbr;sizelength=13;indexlength=3;" ++ "indexdeltalength=3%s\r\n", ++ payload_type, c->sample_rate, c->channels, ++ payload_type, config); + } +- av_strlcatf(buff, size, "a=rtpmap:%d MPEG4-GENERIC/%d/%d\r\n" +- "a=fmtp:%d profile-level-id=1;" +- "mode=AAC-hbr;sizelength=13;indexlength=3;" +- "indexdeltalength=3%s\r\n", +- payload_type, c->sample_rate, c->channels, +- payload_type, config); + break; + case CODEC_ID_PCM_S16BE: + if (payload_type >= RTP_PT_PRIVATE) +@@ -437,6 +534,14 @@ + payload_type, + 8000, c->channels); + break; ++ case CODEC_ID_ADPCM_G726: { ++ if (payload_type >= RTP_PT_PRIVATE) ++ av_strlcatf(buff, size, "a=rtpmap:%d G726-%d/%d\r\n", ++ payload_type, ++ c->bits_per_coded_sample*8, ++ c->sample_rate); ++ break; ++ } + default: + /* Nothing special to do here... */ + break; +@@ -447,15 +552,12 @@ + return buff; + } + +-void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, const char *dest_type, int port, int ttl) ++void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt) + { + const char *type; + int payload_type; + +- payload_type = ff_rtp_get_payload_type(c); +- if (payload_type < 0) { +- payload_type = RTP_PT_PRIVATE + (c->codec_type == AVMEDIA_TYPE_AUDIO); +- } ++ payload_type = ff_rtp_get_payload_type(fmt, c); + + switch (c->codec_type) { + case AVMEDIA_TYPE_VIDEO : type = "video" ; break; +@@ -470,17 +572,17 @@ + av_strlcatf(buff, size, "b=AS:%d\r\n", c->bit_rate / 1000); + } + +- sdp_write_media_attributes(buff, size, c, payload_type); ++ sdp_write_media_attributes(buff, size, c, payload_type, fmt); + } + +-int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) ++int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) + { +- AVMetadataTag *title = av_metadata_get(ac[0]->metadata, "title", NULL, 0); ++ AVDictionaryEntry *title = av_dict_get(ac[0]->metadata, "title", NULL, 0); + struct sdp_session_level s; + int i, j, port, ttl, is_multicast; + char dst[32], dst_type[5]; + +- memset(buff, 0, size); ++ memset(buf, 0, size); + memset(&s, 0, sizeof(struct sdp_session_level)); + s.user = "-"; + s.src_addr = "127.0.0.1"; /* FIXME: Properly set this */ +@@ -505,7 +607,7 @@ + } + } + } +- sdp_write_header(buff, size, &s); ++ sdp_write_header(buf, size, &s); + + dst[0] = 0; + for (i = 0; i < n_files; i++) { +@@ -517,11 +619,12 @@ + ttl = 0; + } + for (j = 0; j < ac[i]->nb_streams; j++) { +- ff_sdp_write_media(buff, size, ++ ff_sdp_write_media(buf, size, + ac[i]->streams[j]->codec, dst[0] ? dst : NULL, +- dst_type, (port > 0) ? port + j * 2 : 0, ttl); ++ dst_type, (port > 0) ? port + j * 2 : 0, ttl, ++ ac[i]); + if (port <= 0) { +- av_strlcatf(buff, size, ++ av_strlcatf(buf, size, + "a=control:streamid=%d\r\n", i + j); + } + } +@@ -530,12 +633,19 @@ + return 0; + } + #else +-int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) ++int av_sdp_create(AVFormatContext *ac[], int n_files, char *buf, int size) + { + return AVERROR(ENOSYS); + } + +-void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, const char *dest_type, int port, int ttl) ++void ff_sdp_write_media(char *buff, int size, AVCodecContext *c, const char *dest_addr, const char *dest_type, int port, int ttl, AVFormatContext *fmt) ++{ ++} ++#endif ++ ++#if FF_API_SDP_CREATE ++int avf_sdp_create(AVFormatContext *ac[], int n_files, char *buff, int size) + { ++ return av_sdp_create(ac, n_files, buff, size); + } + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/seek.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/seek.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/seek.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/seek.c 2012-05-14 14:08:55.194357291 +0200 +@@ -21,6 +21,7 @@ + */ + + #include "seek.h" ++#include "libavutil/mathematics.h" + #include "libavutil/mem.h" + #include "internal.h" + +@@ -313,7 +314,7 @@ + step = s->pb->buffer_size; + curpos = FFMAX(pos - step / 2, 0); + for (;;) { +- url_fseek(s->pb, curpos, SEEK_SET); ++ avio_seek(s->pb, curpos, SEEK_SET); + search_hi_lo_keyframes(s, + ts, time_base, + flags, +@@ -385,7 +386,7 @@ + } + } + +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + av_free(sync); + return pos; + } +@@ -405,7 +406,7 @@ + return NULL; + } + +- state->fpos = url_ftell(s->pb); ++ state->fpos = avio_tell(s->pb); + + // copy context structures + state->cur_st = s->cur_st; +@@ -456,7 +457,7 @@ + if (!state) + return; + +- url_fseek(s->pb, state->fpos, SEEK_SET); ++ avio_seek(s->pb, state->fpos, SEEK_SET); + + // copy context structures + s->cur_st = state->cur_st; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/seek-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/seek-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/seek-test.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/seek-test.c 2012-05-14 14:08:55.193357271 +0200 +@@ -0,0 +1,132 @@ ++/* ++ * Copyright (c) 2003 Fabrice Bellard ++ * Copyright (c) 2007 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++#include ++ ++#include "libavutil/common.h" ++#include "libavutil/mathematics.h" ++#include "libavformat/avformat.h" ++ ++#undef printf ++#undef fprintf ++ ++static char buffer[20]; ++ ++static const char *ret_str(int v) ++{ ++ switch (v) { ++ case AVERROR_EOF: return "-EOF"; ++ case AVERROR(EIO): return "-EIO"; ++ case AVERROR(ENOMEM): return "-ENOMEM"; ++ case AVERROR(EINVAL): return "-EINVAL"; ++ default: ++ snprintf(buffer, sizeof(buffer), "%2d", v); ++ return buffer; ++ } ++} ++ ++static void ts_str(char buffer[60], int64_t ts, AVRational base) ++{ ++ if (ts == AV_NOPTS_VALUE) { ++ strcpy(buffer, " NOPTS "); ++ return; ++ } ++ ts= av_rescale_q(ts, base, (AVRational){1, 1000000}); ++ snprintf(buffer, 60, "%c%"PRId64".%06"PRId64"", ts<0 ? '-' : ' ', FFABS(ts)/1000000, FFABS(ts)%1000000); ++} ++ ++int main(int argc, char **argv) ++{ ++ const char *filename; ++ AVFormatContext *ic = NULL; ++ int i, ret, stream_id; ++ int64_t timestamp; ++ AVDictionary *format_opts = NULL; ++ ++ av_dict_set(&format_opts, "channels", "1", 0); ++ av_dict_set(&format_opts, "sample_rate", "22050", 0); ++ ++ /* initialize libavcodec, and register all codecs and formats */ ++ av_register_all(); ++ ++ if (argc != 2) { ++ printf("usage: %s input_file\n" ++ "\n", argv[0]); ++ return 1; ++ } ++ ++ filename = argv[1]; ++ ++ ret = avformat_open_input(&ic, filename, NULL, &format_opts); ++ av_dict_free(&format_opts); ++ if (ret < 0) { ++ fprintf(stderr, "cannot open %s\n", filename); ++ return 1; ++ } ++ ++ ret = avformat_find_stream_info(ic, NULL); ++ if (ret < 0) { ++ fprintf(stderr, "%s: could not find codec parameters\n", filename); ++ return 1; ++ } ++ ++ for(i=0; ; i++){ ++ AVPacket pkt; ++ AVStream *av_uninit(st); ++ char ts_buf[60]; ++ ++ memset(&pkt, 0, sizeof(pkt)); ++ if(ret>=0){ ++ ret= av_read_frame(ic, &pkt); ++ if(ret>=0){ ++ char dts_buf[60]; ++ st= ic->streams[pkt.stream_index]; ++ ts_str(dts_buf, pkt.dts, st->time_base); ++ ts_str(ts_buf, pkt.pts, st->time_base); ++ printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size); ++ av_free_packet(&pkt); ++ } else ++ printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace ++ printf("\n"); ++ } ++ ++ if(i>25) break; ++ ++ stream_id= (i>>1)%(ic->nb_streams+1) - 1; ++ timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE; ++ if(stream_id>=0){ ++ st= ic->streams[stream_id]; ++ timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base); ++ } ++ //FIXME fully test the new seek API ++ if(i&1) ret = avformat_seek_file(ic, stream_id, INT64_MIN, timestamp, timestamp, 0); ++ else ret = avformat_seek_file(ic, stream_id, timestamp, timestamp, INT64_MAX, 0); ++ ts_str(ts_buf, timestamp, stream_id < 0 ? AV_TIME_BASE_Q : st->time_base); ++ printf("ret:%-10s st:%2d flags:%d ts:%s\n", ret_str(ret), stream_id, i&1, ts_buf); ++ } ++ ++ avformat_close_input(&ic); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/segafilm.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/segafilm.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/segafilm.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/segafilm.c 2012-05-14 14:08:55.195357311 +0200 +@@ -29,11 +29,14 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + #define FILM_TAG MKBETAG('F', 'I', 'L', 'M') + #define FDSC_TAG MKBETAG('F', 'D', 'S', 'C') + #define STAB_TAG MKBETAG('S', 'T', 'A', 'B') + #define CVID_TAG MKBETAG('c', 'v', 'i', 'd') ++#define RAW_TAG MKBETAG('r', 'a', 'w', ' ') + + typedef struct { + int stream; +@@ -77,7 +80,7 @@ + AVFormatParameters *ap) + { + FilmDemuxContext *film = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + unsigned char scratch[256]; + int i; +@@ -89,7 +92,7 @@ + film->stereo_buffer_size = 0; + + /* load the main FILM header */ +- if (get_buffer(pb, scratch, 16) != 16) ++ if (avio_read(pb, scratch, 16) != 16) + return AVERROR(EIO); + data_offset = AV_RB32(&scratch[4]); + film->version = AV_RB32(&scratch[8]); +@@ -97,7 +100,7 @@ + /* load the FDSC chunk */ + if (film->version == 0) { + /* special case for Lemmings .film files; 20-byte header */ +- if (get_buffer(pb, scratch, 20) != 20) ++ if (avio_read(pb, scratch, 20) != 20) + return AVERROR(EIO); + /* make some assumptions about the audio parameters */ + film->audio_type = CODEC_ID_PCM_S8; +@@ -106,16 +109,21 @@ + film->audio_bits = 8; + } else { + /* normal Saturn .cpk files; 32-byte header */ +- if (get_buffer(pb, scratch, 32) != 32) ++ if (avio_read(pb, scratch, 32) != 32) + return AVERROR(EIO); + film->audio_samplerate = AV_RB16(&scratch[24]); + film->audio_channels = scratch[21]; + film->audio_bits = scratch[22]; +- if (film->audio_bits == 8) +- film->audio_type = CODEC_ID_PCM_S8; +- else if (film->audio_bits == 16) +- film->audio_type = CODEC_ID_PCM_S16BE; +- else ++ if (scratch[23] == 2) ++ film->audio_type = CODEC_ID_ADPCM_ADX; ++ else if (film->audio_channels > 0) { ++ if (film->audio_bits == 8) ++ film->audio_type = CODEC_ID_PCM_S8; ++ else if (film->audio_bits == 16) ++ film->audio_type = CODEC_ID_PCM_S16BE; ++ else ++ film->audio_type = CODEC_ID_NONE; ++ } else + film->audio_type = CODEC_ID_NONE; + } + +@@ -124,12 +132,15 @@ + + if (AV_RB32(&scratch[8]) == CVID_TAG) { + film->video_type = CODEC_ID_CINEPAK; +- } else ++ } else if (AV_RB32(&scratch[8]) == RAW_TAG) { ++ film->video_type = CODEC_ID_RAWVIDEO; ++ } else { + film->video_type = CODEC_ID_NONE; ++ } + + /* initialize the decoder streams */ + if (film->video_type) { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + film->video_stream_index = st->index; +@@ -138,10 +149,19 @@ + st->codec->codec_tag = 0; /* no fourcc */ + st->codec->width = AV_RB32(&scratch[16]); + st->codec->height = AV_RB32(&scratch[12]); ++ ++ if (film->video_type == CODEC_ID_RAWVIDEO) { ++ if (scratch[20] == 24) { ++ st->codec->pix_fmt = PIX_FMT_RGB24; ++ } else { ++ av_log(s, AV_LOG_ERROR, "raw video is using unhandled %dbpp\n", scratch[20]); ++ return -1; ++ } ++ } + } + + if (film->audio_type) { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + film->audio_stream_index = st->index; +@@ -149,16 +169,24 @@ + st->codec->codec_id = film->audio_type; + st->codec->codec_tag = 1; + st->codec->channels = film->audio_channels; +- st->codec->bits_per_coded_sample = film->audio_bits; + st->codec->sample_rate = film->audio_samplerate; ++ ++ if (film->audio_type == CODEC_ID_ADPCM_ADX) { ++ st->codec->bits_per_coded_sample = 18 * 8 / 32; ++ st->codec->block_align = st->codec->channels * 18; ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ } else { ++ st->codec->bits_per_coded_sample = film->audio_bits; ++ st->codec->block_align = st->codec->channels * ++ st->codec->bits_per_coded_sample / 8; ++ } ++ + st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * + st->codec->bits_per_coded_sample; +- st->codec->block_align = st->codec->channels * +- st->codec->bits_per_coded_sample / 8; + } + + /* load the sample table */ +- if (get_buffer(pb, scratch, 16) != 16) ++ if (avio_read(pb, scratch, 16) != 16) + return AVERROR(EIO); + if (AV_RB32(&scratch[0]) != STAB_TAG) + return AVERROR_INVALIDDATA; +@@ -167,14 +195,16 @@ + if(film->sample_count >= UINT_MAX / sizeof(film_sample)) + return -1; + film->sample_table = av_malloc(film->sample_count * sizeof(film_sample)); ++ if (!film->sample_table) ++ return AVERROR(ENOMEM); + + for(i=0; inb_streams; i++) +- av_set_pts_info(s->streams[i], 33, 1, film->base_clock); ++ avpriv_set_pts_info(s->streams[i], 33, 1, film->base_clock); + + audio_frame_counter = 0; + for (i = 0; i < film->sample_count; i++) { + /* load the next sample record and transfer it to an internal struct */ +- if (get_buffer(pb, scratch, 16) != 16) { ++ if (avio_read(pb, scratch, 16) != 16) { + av_free(film->sample_table); + return AVERROR(EIO); + } +@@ -187,8 +217,12 @@ + film->sample_table[i].pts *= film->base_clock; + film->sample_table[i].pts /= film->audio_samplerate; + +- audio_frame_counter += (film->sample_table[i].sample_size / +- (film->audio_channels * film->audio_bits / 8)); ++ if (film->audio_type == CODEC_ID_ADPCM_ADX) ++ audio_frame_counter += (film->sample_table[i].sample_size * 32 / ++ (18 * film->audio_channels)); ++ else if (film->audio_type != CODEC_ID_NONE) ++ audio_frame_counter += (film->sample_table[i].sample_size / ++ (film->audio_channels * film->audio_bits / 8)); + } else { + film->sample_table[i].stream = film->video_stream_index; + film->sample_table[i].pts = AV_RB32(&scratch[8]) & 0x7FFFFFFF; +@@ -205,7 +239,7 @@ + AVPacket *pkt) + { + FilmDemuxContext *film = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + film_sample *sample; + int ret = 0; + int i; +@@ -217,19 +251,22 @@ + sample = &film->sample_table[film->current_sample]; + + /* position the stream (will probably be there anyway) */ +- url_fseek(pb, sample->sample_offset, SEEK_SET); ++ avio_seek(pb, sample->sample_offset, SEEK_SET); + + /* do a special song and dance when loading FILM Cinepak chunks */ + if ((sample->stream == film->video_stream_index) && + (film->video_type == CODEC_ID_CINEPAK)) { +- pkt->pos= url_ftell(pb); ++ pkt->pos= avio_tell(pb); + if (av_new_packet(pkt, sample->sample_size)) + return AVERROR(ENOMEM); +- get_buffer(pb, pkt->data, sample->sample_size); ++ avio_read(pb, pkt->data, sample->sample_size); + } else if ((sample->stream == film->audio_stream_index) && +- (film->audio_channels == 2)) { ++ (film->audio_channels == 2) && ++ (film->audio_type != CODEC_ID_ADPCM_ADX)) { + /* stereo PCM needs to be interleaved */ + ++ if (ffio_limit(pb, sample->sample_size) != sample->sample_size) ++ return AVERROR(EIO); + if (av_new_packet(pkt, sample->sample_size)) + return AVERROR(ENOMEM); + +@@ -238,10 +275,14 @@ + av_free(film->stereo_buffer); + film->stereo_buffer_size = sample->sample_size; + film->stereo_buffer = av_malloc(film->stereo_buffer_size); ++ if (!film->stereo_buffer) { ++ film->stereo_buffer_size = 0; ++ return AVERROR(ENOMEM); ++ } + } + +- pkt->pos= url_ftell(pb); +- ret = get_buffer(pb, film->stereo_buffer, sample->sample_size); ++ pkt->pos= avio_tell(pb); ++ ret = avio_read(pb, film->stereo_buffer, sample->sample_size); + if (ret != sample->sample_size) + ret = AVERROR(EIO); + +@@ -283,11 +324,11 @@ + } + + AVInputFormat ff_segafilm_demuxer = { +- "film_cpk", +- NULL_IF_CONFIG_SMALL("Sega FILM/CPK format"), +- sizeof(FilmDemuxContext), +- film_probe, +- film_read_header, +- film_read_packet, +- film_read_close, ++ .name = "film_cpk", ++ .long_name = NULL_IF_CONFIG_SMALL("Sega FILM/CPK format"), ++ .priv_data_size = sizeof(FilmDemuxContext), ++ .read_probe = film_probe, ++ .read_header = film_read_header, ++ .read_packet = film_read_packet, ++ .read_close = film_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/segment.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/segment.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/segment.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/segment.c 2012-05-14 14:08:55.196357331 +0200 +@@ -0,0 +1,273 @@ ++/* ++ * Generic segmenter ++ * Copyright (c) 2011, Luca Barbato ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++ ++#include "avformat.h" ++#include "internal.h" ++ ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++#include "libavutil/avstring.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/mathematics.h" ++ ++typedef struct { ++ const AVClass *class; /**< Class for private options. */ ++ int number; ++ AVFormatContext *avf; ++ char *format; /**< Set by a private option. */ ++ char *list; /**< Set by a private option. */ ++ float time; /**< Set by a private option. */ ++ int size; /**< Set by a private option. */ ++ int64_t offset_time; ++ int64_t recording_time; ++ int has_video; ++ AVIOContext *pb; ++} SegmentContext; ++ ++static int segment_start(AVFormatContext *s) ++{ ++ SegmentContext *c = s->priv_data; ++ AVFormatContext *oc = c->avf; ++ int err = 0; ++ ++ if (av_get_frame_filename(oc->filename, sizeof(oc->filename), ++ s->filename, c->number++) < 0) ++ return AVERROR(EINVAL); ++ ++ if ((err = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL)) < 0) ++ return err; ++ ++ if (!oc->priv_data && oc->oformat->priv_data_size > 0) { ++ oc->priv_data = av_mallocz(oc->oformat->priv_data_size); ++ if (!oc->priv_data) { ++ avio_close(oc->pb); ++ return AVERROR(ENOMEM); ++ } ++ if (oc->oformat->priv_class) { ++ *(const AVClass**)oc->priv_data = oc->oformat->priv_class; ++ av_opt_set_defaults(oc->priv_data); ++ } ++ } ++ ++ if ((err = oc->oformat->write_header(oc)) < 0) { ++ goto fail; ++ } ++ ++ return 0; ++ ++fail: ++ avio_close(oc->pb); ++ av_freep(&oc->priv_data); ++ ++ return err; ++} ++ ++static int segment_end(AVFormatContext *oc) ++{ ++ int ret = 0; ++ ++ if (oc->oformat->write_trailer) ++ ret = oc->oformat->write_trailer(oc); ++ ++ avio_close(oc->pb); ++ if (oc->oformat->priv_class) ++ av_opt_free(oc->priv_data); ++ av_freep(&oc->priv_data); ++ ++ return ret; ++} ++ ++static int seg_write_header(AVFormatContext *s) ++{ ++ SegmentContext *seg = s->priv_data; ++ AVFormatContext *oc; ++ int ret, i; ++ ++ seg->number = 0; ++ seg->offset_time = 0; ++ seg->recording_time = seg->time * 1000000; ++ ++ if (seg->list) ++ if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL)) < 0) ++ return ret; ++ ++ for (i = 0; i< s->nb_streams; i++) ++ seg->has_video += ++ (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO); ++ ++ if (seg->has_video > 1) ++ av_log(s, AV_LOG_WARNING, ++ "More than a single video stream present, " ++ "expect issues decoding it.\n"); ++ ++ oc = avformat_alloc_context(); ++ ++ if (!oc) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ ++ oc->oformat = av_guess_format(seg->format, s->filename, NULL); ++ ++ if (!oc->oformat) { ++ ret = AVERROR_MUXER_NOT_FOUND; ++ goto fail; ++ } ++ if (oc->oformat->flags & AVFMT_NOFILE) { ++ av_log(s, AV_LOG_ERROR, "format %s not supported.\n", ++ oc->oformat->name); ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ seg->avf = oc; ++ ++ oc->streams = s->streams; ++ oc->nb_streams = s->nb_streams; ++ ++ if (av_get_frame_filename(oc->filename, sizeof(oc->filename), ++ s->filename, seg->number++) < 0) { ++ ret = AVERROR(EINVAL); ++ goto fail; ++ } ++ ++ if ((ret = avio_open2(&oc->pb, oc->filename, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL)) < 0) ++ goto fail; ++ ++ if ((ret = avformat_write_header(oc, NULL)) < 0) { ++ avio_close(oc->pb); ++ goto fail; ++ } ++ ++ if (seg->list) { ++ avio_printf(seg->pb, "%s\n", oc->filename); ++ avio_flush(seg->pb); ++ } ++ ++fail: ++ if (ret) { ++ oc->streams = NULL; ++ oc->nb_streams = 0; ++ if (seg->list) ++ avio_close(seg->pb); ++ avformat_free_context(oc); ++ } ++ return ret; ++} ++ ++static int seg_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ SegmentContext *seg = s->priv_data; ++ AVFormatContext *oc = seg->avf; ++ AVStream *st = oc->streams[pkt->stream_index]; ++ int64_t end_pts = seg->recording_time * seg->number; ++ int ret; ++ ++ if ((seg->has_video && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) && ++ av_compare_ts(pkt->pts, st->time_base, ++ end_pts, AV_TIME_BASE_Q) >= 0 && ++ pkt->flags & AV_PKT_FLAG_KEY) { ++ ++ av_log(s, AV_LOG_DEBUG, "Next segment starts at %d %"PRId64"\n", ++ pkt->stream_index, pkt->pts); ++ ++ ret = segment_end(oc); ++ ++ if (!ret) ++ ret = segment_start(s); ++ ++ if (ret) ++ goto fail; ++ ++ if (seg->list) { ++ avio_printf(seg->pb, "%s\n", oc->filename); ++ avio_flush(seg->pb); ++ if (seg->size && !(seg->number % seg->size)) { ++ avio_close(seg->pb); ++ if ((ret = avio_open2(&seg->pb, seg->list, AVIO_FLAG_WRITE, ++ &s->interrupt_callback, NULL)) < 0) ++ goto fail; ++ ++ } ++ } ++ } ++ ++ ret = oc->oformat->write_packet(oc, pkt); ++ ++fail: ++ if (ret < 0) { ++ oc->streams = NULL; ++ oc->nb_streams = 0; ++ if (seg->list) ++ avio_close(seg->pb); ++ avformat_free_context(oc); ++ } ++ ++ return ret; ++} ++ ++static int seg_write_trailer(struct AVFormatContext *s) ++{ ++ SegmentContext *seg = s->priv_data; ++ AVFormatContext *oc = seg->avf; ++ int ret = segment_end(oc); ++ if (seg->list) ++ avio_close(seg->pb); ++ oc->streams = NULL; ++ oc->nb_streams = 0; ++ avformat_free_context(oc); ++ return ret; ++} ++ ++#define OFFSET(x) offsetof(SegmentContext, x) ++#define E AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "segment_format", "container format used for the segments", OFFSET(format), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, ++ { "segment_time", "segment length in seconds", OFFSET(time), AV_OPT_TYPE_FLOAT, {.dbl = 2}, 0, FLT_MAX, E }, ++ { "segment_list", "output the segment list", OFFSET(list), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, E }, ++ { "segment_list_size", "maximum number of playlist entries", OFFSET(size), AV_OPT_TYPE_INT, {.dbl = 5}, 0, INT_MAX, E }, ++ { NULL }, ++}; ++ ++static const AVClass seg_class = { ++ .class_name = "segment muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ ++ ++AVOutputFormat ff_segment_muxer = { ++ .name = "segment", ++ .long_name = NULL_IF_CONFIG_SMALL("segment muxer"), ++ .priv_data_size = sizeof(SegmentContext), ++ .flags = AVFMT_GLOBALHEADER | AVFMT_NOFILE, ++ .write_header = seg_write_header, ++ .write_packet = seg_write_packet, ++ .write_trailer = seg_write_trailer, ++ .priv_class = &seg_class, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sierravmd.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sierravmd.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sierravmd.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sierravmd.c 2012-05-14 14:08:55.199357391 +0200 +@@ -29,6 +29,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + #define VMD_HEADER_SIZE 0x0330 + #define BYTES_PER_FRAME_RECORD 16 +@@ -81,7 +83,7 @@ + AVFormatParameters *ap) + { + VmdDemuxContext *vmd = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st = NULL, *vst; + unsigned int toc_offset; + unsigned char *raw_frame_table; +@@ -95,19 +97,19 @@ + int sound_buffers; + + /* fetch the main header, including the 2 header length bytes */ +- url_fseek(pb, 0, SEEK_SET); +- if (get_buffer(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) ++ avio_seek(pb, 0, SEEK_SET); ++ if (avio_read(pb, vmd->vmd_header, VMD_HEADER_SIZE) != VMD_HEADER_SIZE) + return AVERROR(EIO); + +- if(vmd->vmd_header[16] == 'i' && vmd->vmd_header[17] == 'v' && vmd->vmd_header[18] == '3') ++ if(vmd->vmd_header[24] == 'i' && vmd->vmd_header[25] == 'v' && vmd->vmd_header[26] == '3') + vmd->is_indeo3 = 1; + else + vmd->is_indeo3 = 0; + /* start up the decoders */ +- vst = av_new_stream(s, 0); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return AVERROR(ENOMEM); +- av_set_pts_info(vst, 33, 1, 10); ++ avpriv_set_pts_info(vst, 33, 1, 10); + vmd->video_stream_index = vst->index; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = vmd->is_indeo3 ? CODEC_ID_INDEO3 : CODEC_ID_VMDVIDEO; +@@ -125,7 +127,7 @@ + /* if sample rate is 0, assume no audio */ + vmd->sample_rate = AV_RL16(&vmd->vmd_header[804]); + if (vmd->sample_rate) { +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + vmd->audio_stream_index = st->index; +@@ -148,14 +150,14 @@ + num = st->codec->block_align; + den = st->codec->sample_rate * st->codec->channels; + av_reduce(&den, &num, den, num, (1UL<<31)-1); +- av_set_pts_info(vst, 33, num, den); +- av_set_pts_info(st, 33, num, den); ++ avpriv_set_pts_info(vst, 33, num, den); ++ avpriv_set_pts_info(st, 33, num, den); + } + + toc_offset = AV_RL32(&vmd->vmd_header[812]); + vmd->frame_count = AV_RL16(&vmd->vmd_header[6]); + vmd->frames_per_block = AV_RL16(&vmd->vmd_header[18]); +- url_fseek(pb, toc_offset, SEEK_SET); ++ avio_seek(pb, toc_offset, SEEK_SET); + + raw_frame_table = NULL; + vmd->frame_table = NULL; +@@ -172,7 +174,7 @@ + av_free(vmd->frame_table); + return AVERROR(ENOMEM); + } +- if (get_buffer(pb, raw_frame_table, raw_frame_table_size) != ++ if (avio_read(pb, raw_frame_table, raw_frame_table_size) != + raw_frame_table_size) { + av_free(raw_frame_table); + av_free(vmd->frame_table); +@@ -189,7 +191,7 @@ + int type; + uint32_t size; + +- get_buffer(pb, chunk, BYTES_PER_FRAME_RECORD); ++ avio_read(pb, chunk, BYTES_PER_FRAME_RECORD); + type = chunk[0]; + size = AV_RL32(&chunk[2]); + if(!size && type != 1) +@@ -205,7 +207,7 @@ + vmd->frame_table[total_frames].pts = current_audio_pts; + total_frames++; + if(!current_audio_pts) +- current_audio_pts += sound_buffers; ++ current_audio_pts += sound_buffers - 1; + else + current_audio_pts++; + break; +@@ -234,7 +236,7 @@ + AVPacket *pkt) + { + VmdDemuxContext *vmd = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret = 0; + vmd_frame *frame; + +@@ -243,16 +245,18 @@ + + frame = &vmd->frame_table[vmd->current_frame]; + /* position the stream (will probably be there already) */ +- url_fseek(pb, frame->frame_offset, SEEK_SET); ++ avio_seek(pb, frame->frame_offset, SEEK_SET); + ++ if(ffio_limit(pb, frame->frame_size) != frame->frame_size) ++ return AVERROR(EIO); + if (av_new_packet(pkt, frame->frame_size + BYTES_PER_FRAME_RECORD)) + return AVERROR(ENOMEM); +- pkt->pos= url_ftell(pb); ++ pkt->pos= avio_tell(pb); + memcpy(pkt->data, frame->frame_record, BYTES_PER_FRAME_RECORD); +- if(vmd->is_indeo3) +- ret = get_buffer(pb, pkt->data, frame->frame_size); ++ if(vmd->is_indeo3 && frame->frame_record[0] == 0x02) ++ ret = avio_read(pb, pkt->data, frame->frame_size); + else +- ret = get_buffer(pb, pkt->data + BYTES_PER_FRAME_RECORD, ++ ret = avio_read(pb, pkt->data + BYTES_PER_FRAME_RECORD, + frame->frame_size); + + if (ret != frame->frame_size) { +@@ -281,11 +285,11 @@ + } + + AVInputFormat ff_vmd_demuxer = { +- "vmd", +- NULL_IF_CONFIG_SMALL("Sierra VMD format"), +- sizeof(VmdDemuxContext), +- vmd_probe, +- vmd_read_header, +- vmd_read_packet, +- vmd_read_close, ++ .name = "vmd", ++ .long_name = NULL_IF_CONFIG_SMALL("Sierra VMD format"), ++ .priv_data_size = sizeof(VmdDemuxContext), ++ .read_probe = vmd_probe, ++ .read_header = vmd_read_header, ++ .read_packet = vmd_read_packet, ++ .read_close = vmd_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/siff.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/siff.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/siff.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/siff.c 2012-05-14 14:08:55.200357411 +0200 +@@ -21,6 +21,8 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + + enum SIFFTags{ + TAG_SIFF = MKTAG('S', 'I', 'F', 'F'), +@@ -71,7 +73,7 @@ + static int create_audio_stream(AVFormatContext *s, SIFFContext *c) + { + AVStream *ast; +- ast = av_new_stream(s, 0); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return -1; + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -80,42 +82,42 @@ + ast->codec->bits_per_coded_sample = c->bits; + ast->codec->sample_rate = c->rate; + ast->codec->frame_size = c->block_align; +- av_set_pts_info(ast, 16, 1, c->rate); ++ avpriv_set_pts_info(ast, 16, 1, c->rate); + return 0; + } + +-static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb) ++static int siff_parse_vbv1(AVFormatContext *s, SIFFContext *c, AVIOContext *pb) + { + AVStream *st; + int width, height; + +- if (get_le32(pb) != TAG_VBHD){ ++ if (avio_rl32(pb) != TAG_VBHD){ + av_log(s, AV_LOG_ERROR, "Header chunk is missing\n"); + return -1; + } +- if(get_be32(pb) != 32){ ++ if(avio_rb32(pb) != 32){ + av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n"); + return -1; + } +- if(get_le16(pb) != 1){ ++ if(avio_rl16(pb) != 1){ + av_log(s, AV_LOG_ERROR, "Incorrect header version\n"); + return -1; + } +- width = get_le16(pb); +- height = get_le16(pb); +- url_fskip(pb, 4); +- c->frames = get_le16(pb); ++ width = avio_rl16(pb); ++ height = avio_rl16(pb); ++ avio_skip(pb, 4); ++ c->frames = avio_rl16(pb); + if(!c->frames){ + av_log(s, AV_LOG_ERROR, "File contains no frames ???\n"); + return -1; + } +- c->bits = get_le16(pb); +- c->rate = get_le16(pb); ++ c->bits = avio_rl16(pb); ++ c->rate = avio_rl16(pb); + c->block_align = c->rate * (c->bits >> 3); + +- url_fskip(pb, 16); //zeroes ++ avio_skip(pb, 16); //zeroes + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -124,7 +126,7 @@ + st->codec->width = width; + st->codec->height = height; + st->codec->pix_fmt = PIX_FMT_PAL8; +- av_set_pts_info(st, 16, 1, 12); ++ avpriv_set_pts_info(st, 16, 1, 12); + + c->cur_frame = 0; + c->has_video = 1; +@@ -135,33 +137,33 @@ + return 0; + } + +-static int siff_parse_soun(AVFormatContext *s, SIFFContext *c, ByteIOContext *pb) ++static int siff_parse_soun(AVFormatContext *s, SIFFContext *c, AVIOContext *pb) + { +- if (get_le32(pb) != TAG_SHDR){ ++ if (avio_rl32(pb) != TAG_SHDR){ + av_log(s, AV_LOG_ERROR, "Header chunk is missing\n"); + return -1; + } +- if(get_be32(pb) != 8){ ++ if(avio_rb32(pb) != 8){ + av_log(s, AV_LOG_ERROR, "Header chunk size is incorrect\n"); + return -1; + } +- url_fskip(pb, 4); //unknown value +- c->rate = get_le16(pb); +- c->bits = get_le16(pb); ++ avio_skip(pb, 4); //unknown value ++ c->rate = avio_rl16(pb); ++ c->bits = avio_rl16(pb); + c->block_align = c->rate * (c->bits >> 3); + return create_audio_stream(s, c); + } + + static int siff_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + SIFFContext *c = s->priv_data; + uint32_t tag; + +- if (get_le32(pb) != TAG_SIFF) ++ if (avio_rl32(pb) != TAG_SIFF) + return -1; +- url_fskip(pb, 4); //ignore size +- tag = get_le32(pb); ++ avio_skip(pb, 4); //ignore size ++ tag = avio_rl32(pb); + + if (tag != TAG_VBV1 && tag != TAG_SOUN){ + av_log(s, AV_LOG_ERROR, "Not a VBV file\n"); +@@ -172,11 +174,11 @@ + return -1; + if (tag == TAG_SOUN && siff_parse_soun(s, c, pb) < 0) + return -1; +- if (get_le32(pb) != MKTAG('B', 'O', 'D', 'Y')){ ++ if (avio_rl32(pb) != MKTAG('B', 'O', 'D', 'Y')){ + av_log(s, AV_LOG_ERROR, "'BODY' chunk is missing\n"); + return -1; + } +- url_fskip(pb, 4); //ignore size ++ avio_skip(pb, 4); //ignore size + + return 0; + } +@@ -190,23 +192,26 @@ + if (c->cur_frame >= c->frames) + return AVERROR(EIO); + if (c->curstrm == -1){ +- c->pktsize = get_le32(s->pb) - 4; +- c->flags = get_le16(s->pb); ++ c->pktsize = avio_rl32(s->pb) - 4; ++ c->flags = avio_rl16(s->pb); + c->gmcsize = (c->flags & VB_HAS_GMC) ? 4 : 0; + if (c->gmcsize) +- get_buffer(s->pb, c->gmc, c->gmcsize); +- c->sndsize = (c->flags & VB_HAS_AUDIO) ? get_le32(s->pb): 0; ++ avio_read(s->pb, c->gmc, c->gmcsize); ++ c->sndsize = (c->flags & VB_HAS_AUDIO) ? avio_rl32(s->pb): 0; + c->curstrm = !!(c->flags & VB_HAS_AUDIO); + } + + if (!c->curstrm){ +- size = c->pktsize - c->sndsize; +- if (av_new_packet(pkt, size) < 0) ++ size = c->pktsize - c->sndsize - c->gmcsize - 2; ++ size = ffio_limit(s->pb, size); ++ if(size < 0 || c->pktsize < c->sndsize) ++ return AVERROR_INVALIDDATA; ++ if (av_new_packet(pkt, size + c->gmcsize + 2) < 0) + return AVERROR(ENOMEM); + AV_WL16(pkt->data, c->flags); + if (c->gmcsize) + memcpy(pkt->data + 2, c->gmc, c->gmcsize); +- get_buffer(s->pb, pkt->data + 2 + c->gmcsize, size - c->gmcsize - 2); ++ avio_read(s->pb, pkt->data + 2 + c->gmcsize, size); + pkt->stream_index = 0; + c->curstrm = -1; + }else{ +@@ -228,11 +233,11 @@ + } + + AVInputFormat ff_siff_demuxer = { +- "siff", +- NULL_IF_CONFIG_SMALL("Beam Software SIFF"), +- sizeof(SIFFContext), +- siff_probe, +- siff_read_header, +- siff_read_packet, ++ .name = "siff", ++ .long_name = NULL_IF_CONFIG_SMALL("Beam Software SIFF"), ++ .priv_data_size = sizeof(SIFFContext), ++ .read_probe = siff_probe, ++ .read_header = siff_read_header, ++ .read_packet = siff_read_packet, + .extensions = "vb,son" + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smacker.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smacker.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smacker.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smacker.c 2012-05-14 14:08:55.202357451 +0200 +@@ -26,16 +26,17 @@ + #include "libavutil/bswap.h" + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define SMACKER_PAL 0x01 + #define SMACKER_FLAG_RING_FRAME 0x01 + + enum SAudFlags { +- SMK_AUD_PACKED = 0x80000000, +- SMK_AUD_16BITS = 0x20000000, +- SMK_AUD_STEREO = 0x10000000, +- SMK_AUD_BINKAUD = 0x08000000, +- SMK_AUD_USEDCT = 0x04000000 ++ SMK_AUD_PACKED = 0x80, ++ SMK_AUD_16BITS = 0x20, ++ SMK_AUD_STEREO = 0x10, ++ SMK_AUD_BINKAUD = 0x08, ++ SMK_AUD_USEDCT = 0x04 + }; + + typedef struct SmackerContext { +@@ -48,6 +49,7 @@ + uint32_t audio[7]; + uint32_t treesize; + uint32_t mmap_size, mclr_size, full_size, type_size; ++ uint8_t aflags[7]; + uint32_t rates[7]; + uint32_t pad; + /* frame info */ +@@ -98,26 +100,26 @@ + + static int smacker_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + SmackerContext *smk = s->priv_data; + AVStream *st, *ast[7]; + int i, ret; + int tbase; + + /* read and check header */ +- smk->magic = get_le32(pb); ++ smk->magic = avio_rl32(pb); + if (smk->magic != MKTAG('S', 'M', 'K', '2') && smk->magic != MKTAG('S', 'M', 'K', '4')) + return -1; +- smk->width = get_le32(pb); +- smk->height = get_le32(pb); +- smk->frames = get_le32(pb); +- smk->pts_inc = (int32_t)get_le32(pb); +- smk->flags = get_le32(pb); ++ smk->width = avio_rl32(pb); ++ smk->height = avio_rl32(pb); ++ smk->frames = avio_rl32(pb); ++ smk->pts_inc = (int32_t)avio_rl32(pb); ++ smk->flags = avio_rl32(pb); + if(smk->flags & SMACKER_FLAG_RING_FRAME) + smk->frames++; + for(i = 0; i < 7; i++) +- smk->audio[i] = get_le32(pb); +- smk->treesize = get_le32(pb); ++ smk->audio[i] = avio_rl32(pb); ++ smk->treesize = avio_rl32(pb); + + if(smk->treesize >= UINT_MAX/4){ // smk->treesize + 16 must not overflow (this check is probably redundant) + av_log(s, AV_LOG_ERROR, "treesize too large\n"); +@@ -125,13 +127,15 @@ + } + + //FIXME remove extradata "rebuilding" +- smk->mmap_size = get_le32(pb); +- smk->mclr_size = get_le32(pb); +- smk->full_size = get_le32(pb); +- smk->type_size = get_le32(pb); +- for(i = 0; i < 7; i++) +- smk->rates[i] = get_le32(pb); +- smk->pad = get_le32(pb); ++ smk->mmap_size = avio_rl32(pb); ++ smk->mclr_size = avio_rl32(pb); ++ smk->full_size = avio_rl32(pb); ++ smk->type_size = avio_rl32(pb); ++ for(i = 0; i < 7; i++) { ++ smk->rates[i] = avio_rl24(pb); ++ smk->aflags[i] = avio_r8(pb); ++ } ++ smk->pad = avio_rl32(pb); + /* setup data */ + if(smk->frames > 0xFFFFFF) { + av_log(s, AV_LOG_ERROR, "Too many frames: %i\n", smk->frames); +@@ -144,14 +148,14 @@ + + /* read frame info */ + for(i = 0; i < smk->frames; i++) { +- smk->frm_size[i] = get_le32(pb); ++ smk->frm_size[i] = avio_rl32(pb); + } + for(i = 0; i < smk->frames; i++) { +- smk->frm_flags[i] = get_byte(pb); ++ smk->frm_flags[i] = avio_r8(pb); + } + + /* init video codec */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + smk->videoindex = st->index; +@@ -168,31 +172,31 @@ + smk->pts_inc *= 100; + tbase = 100000; + av_reduce(&tbase, &smk->pts_inc, tbase, smk->pts_inc, (1UL<<31)-1); +- av_set_pts_info(st, 33, smk->pts_inc, tbase); ++ avpriv_set_pts_info(st, 33, smk->pts_inc, tbase); + st->duration = smk->frames; + /* handle possible audio streams */ + for(i = 0; i < 7; i++) { + smk->indexes[i] = -1; +- if(smk->rates[i] & 0xFFFFFF){ +- ast[i] = av_new_stream(s, 0); ++ if (smk->rates[i]) { ++ ast[i] = avformat_new_stream(s, NULL); + smk->indexes[i] = ast[i]->index; + ast[i]->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- if (smk->rates[i] & SMK_AUD_BINKAUD) { ++ if (smk->aflags[i] & SMK_AUD_BINKAUD) { + ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_RDFT; +- } else if (smk->rates[i] & SMK_AUD_USEDCT) { ++ } else if (smk->aflags[i] & SMK_AUD_USEDCT) { + ast[i]->codec->codec_id = CODEC_ID_BINKAUDIO_DCT; +- } else if (smk->rates[i] & SMK_AUD_PACKED){ ++ } else if (smk->aflags[i] & SMK_AUD_PACKED){ + ast[i]->codec->codec_id = CODEC_ID_SMACKAUDIO; + ast[i]->codec->codec_tag = MKTAG('S', 'M', 'K', 'A'); + } else { + ast[i]->codec->codec_id = CODEC_ID_PCM_U8; + } +- ast[i]->codec->channels = (smk->rates[i] & SMK_AUD_STEREO) ? 2 : 1; +- ast[i]->codec->sample_rate = smk->rates[i] & 0xFFFFFF; +- ast[i]->codec->bits_per_coded_sample = (smk->rates[i] & SMK_AUD_16BITS) ? 16 : 8; ++ ast[i]->codec->channels = (smk->aflags[i] & SMK_AUD_STEREO) ? 2 : 1; ++ ast[i]->codec->sample_rate = smk->rates[i]; ++ ast[i]->codec->bits_per_coded_sample = (smk->aflags[i] & SMK_AUD_16BITS) ? 16 : 8; + if(ast[i]->codec->bits_per_coded_sample == 16 && ast[i]->codec->codec_id == CODEC_ID_PCM_U8) + ast[i]->codec->codec_id = CODEC_ID_PCM_S16LE; +- av_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate ++ avpriv_set_pts_info(ast[i], 64, 1, ast[i]->codec->sample_rate + * ast[i]->codec->channels * ast[i]->codec->bits_per_coded_sample / 8); + } + } +@@ -207,7 +211,7 @@ + av_free(smk->frm_flags); + return -1; + } +- ret = get_buffer(pb, st->codec->extradata + 16, st->codec->extradata_size - 16); ++ ret = avio_read(pb, st->codec->extradata + 16, st->codec->extradata_size - 16); + if(ret != st->codec->extradata_size - 16){ + av_free(smk->frm_size); + av_free(smk->frm_flags); +@@ -219,7 +223,7 @@ + ((int32_t*)st->codec->extradata)[3] = av_le2ne32(smk->type_size); + + smk->curstream = -1; +- smk->nextpos = url_ftell(pb); ++ smk->nextpos = avio_tell(pb); + + return 0; + } +@@ -233,38 +237,45 @@ + int i; + int frame_size = 0; + int palchange = 0; +- int pos; + + if (url_feof(s->pb) || smk->cur_frame >= smk->frames) + return AVERROR_EOF; + + /* if we demuxed all streams, pass another frame */ + if(smk->curstream < 0) { +- url_fseek(s->pb, smk->nextpos, 0); ++ avio_seek(s->pb, smk->nextpos, 0); + frame_size = smk->frm_size[smk->cur_frame] & (~3); + flags = smk->frm_flags[smk->cur_frame]; + /* handle palette change event */ +- pos = url_ftell(s->pb); + if(flags & SMACKER_PAL){ + int size, sz, t, off, j, pos; + uint8_t *pal = smk->pal; + uint8_t oldpal[768]; + + memcpy(oldpal, pal, 768); +- size = get_byte(s->pb); ++ size = avio_r8(s->pb); + size = size * 4 - 1; ++ if(size + 1 > frame_size) ++ return AVERROR_INVALIDDATA; + frame_size -= size; + frame_size--; + sz = 0; +- pos = url_ftell(s->pb) + size; ++ pos = avio_tell(s->pb) + size; + while(sz < 256){ +- t = get_byte(s->pb); ++ t = avio_r8(s->pb); + if(t & 0x80){ /* skip palette entries */ + sz += (t & 0x7F) + 1; + pal += ((t & 0x7F) + 1) * 3; + } else if(t & 0x40){ /* copy with offset */ +- off = get_byte(s->pb) * 3; ++ off = avio_r8(s->pb); + j = (t & 0x3F) + 1; ++ if (off + j > 0xff) { ++ av_log(s, AV_LOG_ERROR, ++ "Invalid palette update, offset=%d length=%d extends beyond palette size\n", ++ off, j); ++ return AVERROR_INVALIDDATA; ++ } ++ off *= 3; + while(j-- && sz < 256) { + *pal++ = oldpal[off + 0]; + *pal++ = oldpal[off + 1]; +@@ -274,12 +285,12 @@ + } + } else { /* new entries */ + *pal++ = smk_pal[t]; +- *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; +- *pal++ = smk_pal[get_byte(s->pb) & 0x3F]; ++ *pal++ = smk_pal[avio_r8(s->pb) & 0x3F]; ++ *pal++ = smk_pal[avio_r8(s->pb) & 0x3F]; + sz++; + } + } +- url_fseek(s->pb, pos, 0); ++ avio_seek(s->pb, pos, 0); + palchange |= 1; + } + flags >>= 1; +@@ -287,33 +298,42 @@ + /* if audio chunks are present, put them to stack and retrieve later */ + for(i = 0; i < 7; i++) { + if(flags & 1) { +- int size; +- size = get_le32(s->pb) - 4; ++ unsigned int size; ++ uint8_t *tmpbuf; ++ ++ size = avio_rl32(s->pb) - 4; ++ if(size + 4L > frame_size) ++ return AVERROR_INVALIDDATA; + frame_size -= size; + frame_size -= 4; + smk->curstream++; +- smk->bufs[smk->curstream] = av_realloc(smk->bufs[smk->curstream], size); ++ tmpbuf = av_realloc(smk->bufs[smk->curstream], size); ++ if (!tmpbuf) ++ return AVERROR(ENOMEM); ++ smk->bufs[smk->curstream] = tmpbuf; + smk->buf_sizes[smk->curstream] = size; +- ret = get_buffer(s->pb, smk->bufs[smk->curstream], size); ++ ret = avio_read(s->pb, smk->bufs[smk->curstream], size); + if(ret != size) + return AVERROR(EIO); + smk->stream_id[smk->curstream] = smk->indexes[i]; + } + flags >>= 1; + } +- if (av_new_packet(pkt, frame_size + 768)) ++ if (frame_size < 0) ++ return AVERROR_INVALIDDATA; ++ if (av_new_packet(pkt, frame_size + 769)) + return AVERROR(ENOMEM); + if(smk->frm_size[smk->cur_frame] & 1) + palchange |= 2; + pkt->data[0] = palchange; + memcpy(pkt->data + 1, smk->pal, 768); +- ret = get_buffer(s->pb, pkt->data + 769, frame_size); ++ ret = avio_read(s->pb, pkt->data + 769, frame_size); + if(ret != frame_size) + return AVERROR(EIO); + pkt->stream_index = smk->videoindex; + pkt->size = ret + 769; + smk->cur_frame++; +- smk->nextpos = url_ftell(s->pb); ++ smk->nextpos = avio_tell(s->pb); + } else { + if (av_new_packet(pkt, smk->buf_sizes[smk->curstream])) + return AVERROR(ENOMEM); +@@ -334,22 +354,19 @@ + int i; + + for(i = 0; i < 7; i++) +- if(smk->bufs[i]) +- av_free(smk->bufs[i]); +- if(smk->frm_size) +- av_free(smk->frm_size); +- if(smk->frm_flags) +- av_free(smk->frm_flags); ++ av_free(smk->bufs[i]); ++ av_free(smk->frm_size); ++ av_free(smk->frm_flags); + + return 0; + } + + AVInputFormat ff_smacker_demuxer = { +- "smk", +- NULL_IF_CONFIG_SMALL("Smacker video"), +- sizeof(SmackerContext), +- smacker_probe, +- smacker_read_header, +- smacker_read_packet, +- smacker_read_close, ++ .name = "smk", ++ .long_name = NULL_IF_CONFIG_SMALL("Smacker video"), ++ .priv_data_size = sizeof(SmackerContext), ++ .read_probe = smacker_probe, ++ .read_header = smacker_read_header, ++ .read_packet = smacker_read_packet, ++ .read_close = smacker_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpeg.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpeg.c 2012-05-14 14:08:55.203357471 +0200 +@@ -0,0 +1,40 @@ ++/* ++ * SMJPEG common code ++ * Copyright (c) 2011-2012 Paul B Mahol ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * SMJPEG common code ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "smjpeg.h" ++ ++const AVCodecTag ff_codec_smjpeg_video_tags[] = { ++ { CODEC_ID_MJPEG, MKTAG('J', 'F', 'I', 'F') }, ++ { CODEC_ID_NONE, 0 }, ++}; ++ ++const AVCodecTag ff_codec_smjpeg_audio_tags[] = { ++ { CODEC_ID_ADPCM_IMA_SMJPEG, MKTAG('A', 'P', 'C', 'M') }, ++ { CODEC_ID_PCM_S16LE, MKTAG('N', 'O', 'N', 'E') }, ++ { CODEC_ID_NONE, 0 }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpegdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpegdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpegdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpegdec.c 2012-05-14 14:08:55.204357491 +0200 +@@ -0,0 +1,177 @@ ++/* ++ * SMJPEG demuxer ++ * Copyright (c) 2011 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * This is a demuxer for Loki SDL Motion JPEG files ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "riff.h" ++#include "smjpeg.h" ++ ++typedef struct SMJPEGContext { ++ int audio_stream_index; ++ int video_stream_index; ++} SMJPEGContext; ++ ++static int smjpeg_probe(AVProbeData *p) ++{ ++ if (!memcmp(p->buf, SMJPEG_MAGIC, 8)) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int smjpeg_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ SMJPEGContext *sc = s->priv_data; ++ AVStream *ast = NULL, *vst = NULL; ++ AVIOContext *pb = s->pb; ++ uint32_t version, htype, hlength, duration; ++ char *comment; ++ ++ avio_skip(pb, 8); // magic ++ version = avio_rb32(pb); ++ if (version) ++ av_log_ask_for_sample(s, "unknown version %d\n", version); ++ ++ duration = avio_rb32(pb); // in msec ++ ++ while (!pb->eof_reached) { ++ htype = avio_rl32(pb); ++ switch (htype) { ++ case SMJPEG_TXT: ++ hlength = avio_rb32(pb); ++ if (!hlength || hlength > 512) ++ return AVERROR_INVALIDDATA; ++ comment = av_malloc(hlength + 1); ++ if (!comment) ++ return AVERROR(ENOMEM); ++ if (avio_read(pb, comment, hlength) != hlength) { ++ av_freep(&comment); ++ av_log(s, AV_LOG_ERROR, "error when reading comment\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ comment[hlength] = 0; ++ av_dict_set(&s->metadata, "comment", comment, ++ AV_DICT_DONT_STRDUP_VAL); ++ break; ++ case SMJPEG_SND: ++ if (ast) { ++ av_log_ask_for_sample(s, "multiple audio streams not supported\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ hlength = avio_rb32(pb); ++ if (hlength < 8) ++ return AVERROR_INVALIDDATA; ++ ast = avformat_new_stream(s, 0); ++ if (!ast) ++ return AVERROR(ENOMEM); ++ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ast->codec->sample_rate = avio_rb16(pb); ++ ast->codec->bits_per_coded_sample = avio_r8(pb); ++ ast->codec->channels = avio_r8(pb); ++ ast->codec->codec_tag = avio_rl32(pb); ++ ast->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_audio_tags, ++ ast->codec->codec_tag); ++ ast->duration = duration; ++ sc->audio_stream_index = ast->index; ++ avpriv_set_pts_info(ast, 32, 1, 1000); ++ avio_skip(pb, hlength - 8); ++ break; ++ case SMJPEG_VID: ++ if (vst) { ++ av_log_ask_for_sample(s, "multiple video streams not supported\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ hlength = avio_rb32(pb); ++ if (hlength < 12) ++ return AVERROR_INVALIDDATA; ++ avio_skip(pb, 4); // number of frames ++ vst = avformat_new_stream(s, 0); ++ if (!vst) ++ return AVERROR(ENOMEM); ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->width = avio_rb16(pb); ++ vst->codec->height = avio_rb16(pb); ++ vst->codec->codec_tag = avio_rl32(pb); ++ vst->codec->codec_id = ff_codec_get_id(ff_codec_smjpeg_video_tags, ++ vst->codec->codec_tag); ++ vst->duration = duration; ++ sc->video_stream_index = vst->index; ++ avpriv_set_pts_info(vst, 32, 1, 1000); ++ avio_skip(pb, hlength - 12); ++ break; ++ case SMJPEG_HEND: ++ return 0; ++ default: ++ av_log(s, AV_LOG_ERROR, "unknown header %x\n", htype); ++ return AVERROR_INVALIDDATA; ++ } ++ } ++ ++ return AVERROR_EOF; ++} ++ ++static int smjpeg_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ SMJPEGContext *sc = s->priv_data; ++ uint32_t dtype, ret, size, timestamp; ++ ++ if (s->pb->eof_reached) ++ return AVERROR_EOF; ++ dtype = avio_rl32(s->pb); ++ switch (dtype) { ++ case SMJPEG_SNDD: ++ timestamp = avio_rb32(s->pb); ++ size = avio_rb32(s->pb); ++ ret = av_get_packet(s->pb, pkt, size); ++ pkt->stream_index = sc->audio_stream_index; ++ pkt->pts = timestamp; ++ break; ++ case SMJPEG_VIDD: ++ timestamp = avio_rb32(s->pb); ++ size = avio_rb32(s->pb); ++ ret = av_get_packet(s->pb, pkt, size); ++ pkt->stream_index = sc->video_stream_index; ++ pkt->pts = timestamp; ++ break; ++ case SMJPEG_DONE: ++ ret = AVERROR_EOF; ++ break; ++ default: ++ av_log(s, AV_LOG_ERROR, "unknown chunk %x\n", dtype); ++ ret = AVERROR_INVALIDDATA; ++ break; ++ } ++ return ret; ++} ++ ++AVInputFormat ff_smjpeg_demuxer = { ++ .name = "smjpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"), ++ .priv_data_size = sizeof(SMJPEGContext), ++ .read_probe = smjpeg_probe, ++ .read_header = smjpeg_read_header, ++ .read_packet = smjpeg_read_packet, ++ .extensions = "mjpg", ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpegenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpegenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpegenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpegenc.c 2012-05-14 14:08:55.205357511 +0200 +@@ -0,0 +1,149 @@ ++/* ++ * SMJPEG muxer ++ * Copyright (c) 2012 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * This is a muxer for Loki SDL Motion JPEG files ++ */ ++ ++#include "avformat.h" ++#include "internal.h" ++#include "riff.h" ++#include "smjpeg.h" ++ ++typedef struct SMJPEGMuxContext { ++ uint32_t duration; ++} SMJPEGMuxContext; ++ ++static int smjpeg_write_header(AVFormatContext *s) ++{ ++ AVDictionaryEntry *t = NULL; ++ AVIOContext *pb = s->pb; ++ int n, tag; ++ ++ if (s->nb_streams > 2) { ++ av_log(s, AV_LOG_ERROR, "more than >2 streams are not supported\n"); ++ return AVERROR(EINVAL); ++ } ++ avio_write(pb, SMJPEG_MAGIC, 8); ++ avio_wb32(pb, 0); ++ avio_wb32(pb, 0); ++ ++ while ((t = av_dict_get(s->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) { ++ avio_wl32(pb, SMJPEG_TXT); ++ avio_wb32(pb, strlen(t->key) + strlen(t->value) + 3); ++ avio_write(pb, t->key, strlen(t->key)); ++ avio_write(pb, " = ", 3); ++ avio_write(pb, t->value, strlen(t->value)); ++ } ++ ++ for (n = 0; n < s->nb_streams; n++) { ++ AVStream *st = s->streams[n]; ++ AVCodecContext *codec = st->codec; ++ if (codec->codec_type == AVMEDIA_TYPE_AUDIO) { ++ tag = ff_codec_get_tag(ff_codec_smjpeg_audio_tags, codec->codec_id); ++ if (!tag) { ++ av_log(s, AV_LOG_ERROR, "unsupported audio codec\n"); ++ return AVERROR(EINVAL); ++ } ++ avio_wl32(pb, SMJPEG_SND); ++ avio_wb32(pb, 8); ++ avio_wb16(pb, codec->sample_rate); ++ avio_w8(pb, av_get_bits_per_sample(codec->codec_id)); ++ avio_w8(pb, codec->channels); ++ avio_wl32(pb, tag); ++ avpriv_set_pts_info(st, 32, 1, 1000); ++ } else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ tag = ff_codec_get_tag(ff_codec_smjpeg_video_tags, codec->codec_id); ++ if (!tag) { ++ av_log(s, AV_LOG_ERROR, "unsupported video codec\n"); ++ return AVERROR(EINVAL); ++ } ++ avio_wl32(pb, SMJPEG_VID); ++ avio_wb32(pb, 12); ++ avio_wb32(pb, 0); ++ avio_wb16(pb, codec->width); ++ avio_wb16(pb, codec->height); ++ avio_wl32(pb, tag); ++ avpriv_set_pts_info(st, 32, 1, 1000); ++ } ++ } ++ ++ avio_wl32(pb, SMJPEG_HEND); ++ avio_flush(pb); ++ ++ return 0; ++} ++ ++static int smjpeg_write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ SMJPEGMuxContext *smc = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *st = s->streams[pkt->stream_index]; ++ AVCodecContext *codec = st->codec; ++ ++ if (codec->codec_type == AVMEDIA_TYPE_AUDIO) ++ avio_wl32(pb, SMJPEG_SNDD); ++ else if (codec->codec_type == AVMEDIA_TYPE_VIDEO) ++ avio_wl32(pb, SMJPEG_VIDD); ++ else ++ return 0; ++ ++ avio_wb32(pb, pkt->pts); ++ avio_wb32(pb, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); ++ avio_flush(pb); ++ ++ smc->duration = FFMAX(smc->duration, pkt->pts + pkt->duration); ++ return 0; ++} ++ ++static int smjpeg_write_trailer(AVFormatContext *s) ++{ ++ SMJPEGMuxContext *smc = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int64_t currentpos; ++ ++ if (pb->seekable) { ++ currentpos = avio_tell(pb); ++ avio_seek(pb, 12, SEEK_SET); ++ avio_wb32(pb, smc->duration); ++ avio_seek(pb, currentpos, SEEK_SET); ++ } ++ ++ avio_wl32(pb, SMJPEG_DONE); ++ avio_flush(pb); ++ ++ return 0; ++} ++ ++AVOutputFormat ff_smjpeg_muxer = { ++ .name = "smjpeg", ++ .long_name = NULL_IF_CONFIG_SMALL("Loki SDL MJPEG"), ++ .priv_data_size = sizeof(SMJPEGMuxContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_MJPEG, ++ .write_header = smjpeg_write_header, ++ .write_packet = smjpeg_write_packet, ++ .write_trailer = smjpeg_write_trailer, ++ .flags = AVFMT_GLOBALHEADER, ++ .codec_tag = (const AVCodecTag *const []){ ff_codec_smjpeg_video_tags, ff_codec_smjpeg_audio_tags, 0 }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpeg.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpeg.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/smjpeg.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/smjpeg.h 2012-05-14 14:08:55.203357471 +0200 +@@ -0,0 +1,45 @@ ++/* ++ * SMJPEG common code ++ * Copyright (c) 2011-2012 Paul B Mahol ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * SMJPEG common code ++ */ ++ ++#ifndef AVFORMAT_SMJPEG_H ++#define AVFORMAT_SMJPEG_H ++ ++#include "internal.h" ++ ++#define SMJPEG_MAGIC "\x0\xaSMJPEG" ++ ++#define SMJPEG_DONE MKTAG('D', 'O', 'N', 'E') ++#define SMJPEG_HEND MKTAG('H', 'E', 'N', 'D') ++#define SMJPEG_SND MKTAG('_', 'S', 'N', 'D') ++#define SMJPEG_SNDD MKTAG('s', 'n', 'd', 'D') ++#define SMJPEG_TXT MKTAG('_', 'T', 'X', 'T') ++#define SMJPEG_VID MKTAG('_', 'V', 'I', 'D') ++#define SMJPEG_VIDD MKTAG('v', 'i', 'd', 'D') ++ ++extern const AVCodecTag ff_codec_smjpeg_video_tags[]; ++extern const AVCodecTag ff_codec_smjpeg_audio_tags[]; ++ ++#endif /* AVFORMAT_SMJPEG_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sol.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sol.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/sol.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/sol.c 2012-05-14 14:08:55.206357531 +0200 +@@ -23,8 +23,9 @@ + * Based on documents from Game Audio Player and own research + */ + +-#include "libavutil/bswap.h" ++#include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + #include "pcm.h" + + /* if we don't know the size in advance */ +@@ -33,8 +34,7 @@ + static int sol_probe(AVProbeData *p) + { + /* check file header */ +- uint16_t magic; +- magic=av_le2ne16(*((uint16_t*)p->buf)); ++ uint16_t magic = AV_RL32(p->buf); + if ((magic == 0x0B8D || magic == 0x0C0D || magic == 0x0C8D) && + p->buf[2] == 'S' && p->buf[3] == 'O' && + p->buf[4] == 'L' && p->buf[5] == 0) +@@ -85,23 +85,22 @@ + static int sol_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- int size; + unsigned int magic,tag; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int id, channels, rate, type; + enum CodecID codec; + AVStream *st; + + /* check ".snd" header */ +- magic = get_le16(pb); +- tag = get_le32(pb); ++ magic = avio_rl16(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('S', 'O', 'L', 0)) + return -1; +- rate = get_le16(pb); +- type = get_byte(pb); +- size = get_le32(pb); ++ rate = avio_rl16(pb); ++ type = avio_r8(pb); ++ avio_skip(pb, 4); /* size */ + if (magic != 0x0B8D) +- get_byte(pb); /* newer SOLs contain padding byte */ ++ avio_r8(pb); /* newer SOLs contain padding byte */ + + codec = sol_codec_id(magic, type); + channels = sol_channels(magic, type); +@@ -111,7 +110,7 @@ + else id = 0; + + /* now we are ready: build format streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -119,7 +118,7 @@ + st->codec->codec_id = codec; + st->codec->channels = channels; + st->codec->sample_rate = rate; +- av_set_pts_info(st, 64, 1, rate); ++ avpriv_set_pts_info(st, 64, 1, rate); + return 0; + } + +@@ -133,6 +132,8 @@ + if (url_feof(s->pb)) + return AVERROR(EIO); + ret= av_get_packet(s->pb, pkt, MAX_SIZE); ++ if (ret < 0) ++ return ret; + pkt->stream_index = 0; + + /* note: we need to modify the packet size here to handle the last +@@ -142,12 +143,10 @@ + } + + AVInputFormat ff_sol_demuxer = { +- "sol", +- NULL_IF_CONFIG_SMALL("Sierra SOL format"), +- 0, +- sol_probe, +- sol_read_header, +- sol_read_packet, +- NULL, +- pcm_read_seek, ++ .name = "sol", ++ .long_name = NULL_IF_CONFIG_SMALL("Sierra SOL format"), ++ .read_probe = sol_probe, ++ .read_header = sol_read_header, ++ .read_packet = sol_read_packet, ++ .read_seek = pcm_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/soxdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/soxdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/soxdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/soxdec.c 2012-05-14 14:08:55.215357713 +0200 +@@ -23,14 +23,17 @@ + */ + + /** +- * SoX native format demuxer + * @file ++ * SoX native format demuxer + * @author Daniel Verkamp +- * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format ++ * @see http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + #include "pcm.h" + #include "sox.h" + +@@ -44,31 +47,31 @@ + static int sox_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned header_size, comment_size; + double sample_rate, sample_rate_frac; + AVStream *st; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + +- if (get_le32(pb) == SOX_TAG) { ++ if (avio_rl32(pb) == SOX_TAG) { + st->codec->codec_id = CODEC_ID_PCM_S32LE; +- header_size = get_le32(pb); +- url_fskip(pb, 8); /* sample count */ +- sample_rate = av_int2dbl(get_le64(pb)); +- st->codec->channels = get_le32(pb); +- comment_size = get_le32(pb); ++ header_size = avio_rl32(pb); ++ avio_skip(pb, 8); /* sample count */ ++ sample_rate = av_int2double(avio_rl64(pb)); ++ st->codec->channels = avio_rl32(pb); ++ comment_size = avio_rl32(pb); + } else { + st->codec->codec_id = CODEC_ID_PCM_S32BE; +- header_size = get_be32(pb); +- url_fskip(pb, 8); /* sample count */ +- sample_rate = av_int2dbl(get_be64(pb)); +- st->codec->channels = get_be32(pb); +- comment_size = get_be32(pb); ++ header_size = avio_rb32(pb); ++ avio_skip(pb, 8); /* sample count */ ++ sample_rate = av_int2double(avio_rb64(pb)); ++ st->codec->channels = avio_rb32(pb); ++ comment_size = avio_rb32(pb); + } + + if (comment_size > 0xFFFFFFFFU - SOX_FIXED_HDR - 4U) { +@@ -95,17 +98,19 @@ + + if (comment_size && comment_size < UINT_MAX) { + char *comment = av_malloc(comment_size+1); +- if (get_buffer(pb, comment, comment_size) != comment_size) { ++ if(!comment) ++ return AVERROR(ENOMEM); ++ if (avio_read(pb, comment, comment_size) != comment_size) { + av_freep(&comment); + return AVERROR(EIO); + } + comment[comment_size] = 0; + +- av_metadata_set2(&s->metadata, "comment", comment, +- AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&s->metadata, "comment", comment, ++ AV_DICT_DONT_STRDUP_VAL); + } + +- url_fskip(pb, header_size - SOX_FIXED_HDR - comment_size); ++ avio_skip(pb, header_size - SOX_FIXED_HDR - comment_size); + + st->codec->sample_rate = sample_rate; + st->codec->bits_per_coded_sample = 32; +@@ -115,7 +120,7 @@ + st->codec->block_align = st->codec->bits_per_coded_sample * + st->codec->channels / 8; + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; + } +@@ -141,12 +146,10 @@ + } + + AVInputFormat ff_sox_demuxer = { +- "sox", +- NULL_IF_CONFIG_SMALL("SoX native format"), +- 0, +- sox_probe, +- sox_read_header, +- sox_read_packet, +- NULL, +- pcm_read_seek, ++ .name = "sox", ++ .long_name = NULL_IF_CONFIG_SMALL("SoX native format"), ++ .read_probe = sox_probe, ++ .read_header = sox_read_header, ++ .read_packet = sox_read_packet, ++ .read_seek = pcm_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/soxenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/soxenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/soxenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/soxenc.c 2012-05-14 14:08:55.216357733 +0200 +@@ -23,14 +23,17 @@ + */ + + /** +- * SoX native format muxer + * @file ++ * SoX native format muxer + * @author Daniel Verkamp +- * @sa http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format ++ * @see http://wiki.multimedia.cx/index.php?title=SoX_native_intermediate_format + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "avio_internal.h" + #include "sox.h" + + typedef struct { +@@ -40,12 +43,12 @@ + static int sox_write_header(AVFormatContext *s) + { + SoXContext *sox = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; +- AVMetadataTag *comment; ++ AVDictionaryEntry *comment; + size_t comment_len = 0, comment_size; + +- comment = av_metadata_get(s->metadata, "comment", NULL, 0); ++ comment = av_dict_get(s->metadata, "comment", NULL, 0); + if (comment) + comment_len = strlen(comment->value); + comment_size = (comment_len + 7) & ~7; +@@ -53,74 +56,73 @@ + sox->header_size = SOX_FIXED_HDR + comment_size; + + if (enc->codec_id == CODEC_ID_PCM_S32LE) { +- put_tag(pb, ".SoX"); +- put_le32(pb, sox->header_size); +- put_le64(pb, 0); /* number of samples */ +- put_le64(pb, av_dbl2int(enc->sample_rate)); +- put_le32(pb, enc->channels); +- put_le32(pb, comment_size); ++ ffio_wfourcc(pb, ".SoX"); ++ avio_wl32(pb, sox->header_size); ++ avio_wl64(pb, 0); /* number of samples */ ++ avio_wl64(pb, av_double2int(enc->sample_rate)); ++ avio_wl32(pb, enc->channels); ++ avio_wl32(pb, comment_size); + } else if (enc->codec_id == CODEC_ID_PCM_S32BE) { +- put_tag(pb, "XoS."); +- put_be32(pb, sox->header_size); +- put_be64(pb, 0); /* number of samples */ +- put_be64(pb, av_dbl2int(enc->sample_rate)); +- put_be32(pb, enc->channels); +- put_be32(pb, comment_size); ++ ffio_wfourcc(pb, "XoS."); ++ avio_wb32(pb, sox->header_size); ++ avio_wb64(pb, 0); /* number of samples */ ++ avio_wb64(pb, av_double2int(enc->sample_rate)); ++ avio_wb32(pb, enc->channels); ++ avio_wb32(pb, comment_size); + } else { + av_log(s, AV_LOG_ERROR, "invalid codec; use pcm_s32le or pcm_s32be\n"); + return -1; + } + + if (comment_len) +- put_buffer(pb, comment->value, comment_len); ++ avio_write(pb, comment->value, comment_len); + + for ( ; comment_size > comment_len; comment_len++) +- put_byte(pb, 0); ++ avio_w8(pb, 0); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int sox_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; +- put_buffer(pb, pkt->data, pkt->size); ++ AVIOContext *pb = s->pb; ++ avio_write(pb, pkt->data, pkt->size); + return 0; + } + + static int sox_write_trailer(AVFormatContext *s) + { + SoXContext *sox = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc = s->streams[0]->codec; + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + /* update number of samples */ +- int64_t file_size = url_ftell(pb); ++ int64_t file_size = avio_tell(pb); + int64_t num_samples = (file_size - sox->header_size - 4LL) >> 2LL; +- url_fseek(pb, 8, SEEK_SET); ++ avio_seek(pb, 8, SEEK_SET); + if (enc->codec_id == CODEC_ID_PCM_S32LE) { +- put_le64(pb, num_samples); ++ avio_wl64(pb, num_samples); + } else +- put_be64(pb, num_samples); +- url_fseek(pb, file_size, SEEK_SET); ++ avio_wb64(pb, num_samples); ++ avio_seek(pb, file_size, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + } + + return 0; + } + + AVOutputFormat ff_sox_muxer = { +- "sox", +- NULL_IF_CONFIG_SMALL("SoX native format"), +- NULL, +- "sox", +- sizeof(SoXContext), +- CODEC_ID_PCM_S32LE, +- CODEC_ID_NONE, +- sox_write_header, +- sox_write_packet, +- sox_write_trailer, ++ .name = "sox", ++ .long_name = NULL_IF_CONFIG_SMALL("SoX native format"), ++ .extensions = "sox", ++ .priv_data_size = sizeof(SoXContext), ++ .audio_codec = CODEC_ID_PCM_S32LE, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = sox_write_header, ++ .write_packet = sox_write_packet, ++ .write_trailer = sox_write_trailer, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdifdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdifdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdifdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdifdec.c 2012-05-14 14:08:55.218357773 +0200 +@@ -57,7 +57,7 @@ + break; + case IEC61937_MPEG2_AAC: + init_get_bits(&gbc, buf, AAC_ADTS_HEADER_SIZE * 8); +- if (ff_aac_parse_header(&gbc, &aac_hdr)) { ++ if (avpriv_aac_parse_header(&gbc, &aac_hdr)) { + if (s) /* be silent during a probe */ + av_log(s, AV_LOG_ERROR, "Invalid AAC packet in IEC 61937\n"); + return AVERROR_INVALIDDATA; +@@ -163,20 +163,20 @@ + + static int spdif_read_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + enum IEC61937DataType data_type; + enum CodecID codec_id; + uint32_t state = 0; + int pkt_size_bits, offset, ret; + + while (state != (AV_BSWAP16C(SYNCWORD1) << 16 | AV_BSWAP16C(SYNCWORD2))) { +- state = (state << 8) | get_byte(pb); ++ state = (state << 8) | avio_r8(pb); + if (url_feof(pb)) + return AVERROR_EOF; + } + +- data_type = get_le16(pb); +- pkt_size_bits = get_le16(pb); ++ data_type = avio_rl16(pb); ++ pkt_size_bits = avio_rl16(pb); + + if (pkt_size_bits % 16) + av_log_ask_for_sample(s, "Packet does not end to a 16-bit boundary."); +@@ -185,9 +185,9 @@ + if (ret) + return ret; + +- pkt->pos = url_ftell(pb) - BURST_HEADER_SIZE; ++ pkt->pos = avio_tell(pb) - BURST_HEADER_SIZE; + +- if (get_buffer(pb, pkt->data, pkt->size) < pkt->size) { ++ if (avio_read(pb, pkt->data, pkt->size) < pkt->size) { + av_free_packet(pkt); + return AVERROR_EOF; + } +@@ -201,11 +201,11 @@ + } + + /* skip over the padding to the beginning of the next frame */ +- url_fskip(pb, offset - pkt->size - BURST_HEADER_SIZE); ++ avio_skip(pb, offset - pkt->size - BURST_HEADER_SIZE); + + if (!s->nb_streams) { + /* first packet, create a stream */ +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) { + av_free_packet(pkt); + return AVERROR(ENOMEM); +@@ -226,11 +226,10 @@ + } + + AVInputFormat ff_spdif_demuxer = { +- "spdif", +- NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"), +- 0, +- spdif_probe, +- spdif_read_header, +- spdif_read_packet, ++ .name = "spdif", ++ .long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (compressed data in S/PDIF)"), ++ .read_probe = spdif_probe, ++ .read_header = spdif_read_header, ++ .read_packet = spdif_read_packet, + .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdifenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdifenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdifenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdifenc.c 2012-05-14 14:08:55.219357793 +0200 +@@ -45,13 +45,16 @@ + */ + + #include "avformat.h" ++#include "avio_internal.h" + #include "spdif.h" + #include "libavcodec/ac3.h" + #include "libavcodec/dca.h" ++#include "libavcodec/dcadata.h" + #include "libavcodec/aacadtsdec.h" + #include "libavutil/opt.h" + + typedef struct IEC61937Context { ++ const AVClass *av_class; + enum IEC61937DataType data_type;///< burst info - reference to type of payload of the data-burst + int length_code; ///< length code in bits or bytes, depending on data type + int pkt_offset; ///< data burst repetition period in bytes +@@ -69,7 +72,11 @@ + int hd_buf_count; ///< number of frames in the hd audio buffer + int hd_buf_filled; ///< amount of bytes in the hd audio buffer + ++ int dtshd_skip; ///< counter used for skipping DTS-HD frames ++ + /* AVOptions: */ ++ int dtshd_rate; ++ int dtshd_fallback; + #define SPDIF_FLAG_BIGENDIAN 0x01 + int spdif_flags; + +@@ -79,12 +86,19 @@ + } IEC61937Context; + + static const AVOption options[] = { +-{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), FF_OPT_TYPE_FLAGS, 0, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, +-{ "be", "output in big-endian format (for use as s16be)", 0, FF_OPT_TYPE_CONST, SPDIF_FLAG_BIGENDIAN, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, ++{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), AV_OPT_TYPE_FLAGS, {.dbl = 0}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, ++{ "be", "output in big-endian format (for use as s16be)", 0, AV_OPT_TYPE_CONST, {.dbl = SPDIF_FLAG_BIGENDIAN}, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, ++{ "dtshd_rate", "mux complete DTS frames in HD mode at the specified IEC958 rate (in Hz, default 0=disabled)", offsetof(IEC61937Context, dtshd_rate), AV_OPT_TYPE_INT, {.dbl = 0}, 0, 768000, AV_OPT_FLAG_ENCODING_PARAM }, ++{ "dtshd_fallback_time", "min secs to strip HD for after an overflow (-1: till the end, default 60)", offsetof(IEC61937Context, dtshd_fallback), AV_OPT_TYPE_INT, {.dbl = 60}, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM }, + { NULL }, + }; + +-static const AVClass class = { "spdif", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; ++static const AVClass class = { ++ .class_name = "spdif", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + + static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt) + { +@@ -127,15 +141,119 @@ + return 0; + } + ++/* ++ * DTS type IV (DTS-HD) can be transmitted with various frame repetition ++ * periods; longer repetition periods allow for longer packets and therefore ++ * higher bitrate. Longer repetition periods mean that the constant bitrate of ++ * the outputted IEC 61937 stream is higher. ++ * The repetition period is measured in IEC 60958 frames (4 bytes). ++ */ ++static int spdif_dts4_subtype(int period) ++{ ++ switch (period) { ++ case 512: return 0x0; ++ case 1024: return 0x1; ++ case 2048: return 0x2; ++ case 4096: return 0x3; ++ case 8192: return 0x4; ++ case 16384: return 0x5; ++ } ++ return -1; ++} ++ ++static int spdif_header_dts4(AVFormatContext *s, AVPacket *pkt, int core_size, ++ int sample_rate, int blocks) ++{ ++ IEC61937Context *ctx = s->priv_data; ++ static const char dtshd_start_code[10] = { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0xfe }; ++ int pkt_size = pkt->size; ++ int period; ++ int subtype; ++ ++ if (!core_size) { ++ av_log(s, AV_LOG_ERROR, "HD mode not supported for this format\n"); ++ return AVERROR(EINVAL); ++ } ++ ++ if (!sample_rate) { ++ av_log(s, AV_LOG_ERROR, "Unknown DTS sample rate for HD\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ period = ctx->dtshd_rate * (blocks << 5) / sample_rate; ++ subtype = spdif_dts4_subtype(period); ++ ++ if (subtype < 0) { ++ av_log(s, AV_LOG_ERROR, "Specified HD rate of %d Hz would require an " ++ "impossible repetition period of %d for the current DTS stream" ++ " (blocks = %d, sample rate = %d)\n", ctx->dtshd_rate, period, ++ blocks << 5, sample_rate); ++ return AVERROR(EINVAL); ++ } ++ ++ /* set pkt_offset and DTS IV subtype according to the requested output ++ * rate */ ++ ctx->pkt_offset = period * 4; ++ ctx->data_type = IEC61937_DTSHD | subtype << 8; ++ ++ /* If the bitrate is too high for transmitting at the selected ++ * repetition period setting, strip DTS-HD until a good amount ++ * of consecutive non-overflowing HD frames have been observed. ++ * This generally only happens if the caller is cramming a Master ++ * Audio stream into 192kHz IEC 60958 (which may or may not fit). */ ++ if (sizeof(dtshd_start_code) + 2 + pkt_size ++ > ctx->pkt_offset - BURST_HEADER_SIZE && core_size) { ++ if (!ctx->dtshd_skip) ++ av_log(s, AV_LOG_WARNING, "DTS-HD bitrate too high, " ++ "temporarily sending core only\n"); ++ if (ctx->dtshd_fallback > 0) ++ ctx->dtshd_skip = sample_rate * ctx->dtshd_fallback / (blocks << 5); ++ else ++ /* skip permanently (dtshd_fallback == -1) or just once ++ * (dtshd_fallback == 0) */ ++ ctx->dtshd_skip = 1; ++ } ++ if (ctx->dtshd_skip && core_size) { ++ pkt_size = core_size; ++ if (ctx->dtshd_fallback >= 0) ++ --ctx->dtshd_skip; ++ } ++ ++ ctx->out_bytes = sizeof(dtshd_start_code) + 2 + pkt_size; ++ ++ /* Align so that (length_code & 0xf) == 0x8. This is reportedly needed ++ * with some receivers, but the exact requirement is unconfirmed. */ ++ ctx->length_code = FFALIGN(ctx->out_bytes + 0x8, 0x10) - 0x8; ++ ++ av_fast_malloc(&ctx->hd_buf, &ctx->hd_buf_size, ctx->out_bytes); ++ if (!ctx->hd_buf) ++ return AVERROR(ENOMEM); ++ ++ ctx->out_buf = ctx->hd_buf; ++ ++ memcpy(ctx->hd_buf, dtshd_start_code, sizeof(dtshd_start_code)); ++ AV_WB16(ctx->hd_buf + sizeof(dtshd_start_code), pkt_size); ++ memcpy(ctx->hd_buf + sizeof(dtshd_start_code) + 2, pkt->data, pkt_size); ++ ++ return 0; ++} ++ + static int spdif_header_dts(AVFormatContext *s, AVPacket *pkt) + { + IEC61937Context *ctx = s->priv_data; + uint32_t syncword_dts = AV_RB32(pkt->data); + int blocks; ++ int sample_rate = 0; ++ int core_size = 0; ++ ++ if (pkt->size < 9) ++ return AVERROR_INVALIDDATA; + + switch (syncword_dts) { + case DCA_MARKER_RAW_BE: + blocks = (AV_RB16(pkt->data + 4) >> 2) & 0x7f; ++ core_size = ((AV_RB24(pkt->data + 5) >> 4) & 0x3fff) + 1; ++ sample_rate = dca_sample_rates[(pkt->data[8] >> 2) & 0x0f]; + break; + case DCA_MARKER_RAW_LE: + blocks = (AV_RL16(pkt->data + 4) >> 2) & 0x7f; +@@ -150,11 +268,22 @@ + (((pkt->data[4] & 0x07) << 4) | ((pkt->data[7] & 0x3f) >> 2)); + ctx->extra_bswap = 1; + break; ++ case DCA_HD_MARKER: ++ /* We only handle HD frames that are paired with core. However, ++ sometimes DTS-HD streams with core have a stray HD frame without ++ core in the beginning of the stream. */ ++ av_log(s, AV_LOG_ERROR, "stray DTS-HD frame\n"); ++ return AVERROR_INVALIDDATA; + default: + av_log(s, AV_LOG_ERROR, "bad DTS syncword 0x%x\n", syncword_dts); + return AVERROR_INVALIDDATA; + } + blocks++; ++ ++ if (ctx->dtshd_rate) ++ /* DTS type IV output requested */ ++ return spdif_header_dts4(s, pkt, core_size, sample_rate, blocks); ++ + switch (blocks) { + case 512 >> 5: ctx->data_type = IEC61937_DTS1; break; + case 1024 >> 5: ctx->data_type = IEC61937_DTS2; break; +@@ -164,6 +293,13 @@ + blocks << 5); + return AVERROR(ENOSYS); + } ++ ++ /* discard extraneous data by default */ ++ if (core_size && core_size < pkt->size) { ++ ctx->out_bytes = core_size; ++ ctx->length_code = core_size << 3; ++ } ++ + ctx->pkt_offset = blocks << 7; + + if (ctx->out_bytes == ctx->pkt_offset) { +@@ -171,6 +307,9 @@ + * preamble as it would not fit in there. This is the case for dts + * discs and dts-in-wav. */ + ctx->use_preamble = 0; ++ } else if (ctx->out_bytes > ctx->pkt_offset - BURST_HEADER_SIZE) { ++ av_log_ask_for_sample(s, "Unrecognized large DTS frame."); ++ /* This will fail with a "bitrate too high" in the caller */ + } + + return 0; +@@ -213,7 +352,7 @@ + int ret; + + init_get_bits(&gbc, pkt->data, AAC_ADTS_HEADER_SIZE * 8); +- ret = ff_aac_parse_header(&gbc, &hdr); ++ ret = avpriv_aac_parse_header(&gbc, &hdr); + if (ret < 0) { + av_log(s, AV_LOG_ERROR, "Wrong AAC file format\n"); + return AVERROR_INVALIDDATA; +@@ -342,13 +481,13 @@ + return 0; + } + +-static void spdif_put_16(struct AVFormatContext *s, unsigned int val) ++static av_always_inline void spdif_put_16(IEC61937Context *ctx, ++ AVIOContext *pb, unsigned int val) + { +- IEC61937Context *ctx = s->priv_data; + if (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN) +- put_be16(s->pb, val); ++ avio_wb16(pb, val); + else +- put_le16(s->pb, val); ++ avio_wl16(pb, val); + } + + static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) +@@ -375,45 +514,45 @@ + } + + if (ctx->use_preamble) { +- spdif_put_16(s, SYNCWORD1); //Pa +- spdif_put_16(s, SYNCWORD2); //Pb +- spdif_put_16(s, ctx->data_type); //Pc +- spdif_put_16(s, ctx->length_code);//Pd ++ spdif_put_16(ctx, s->pb, SYNCWORD1); //Pa ++ spdif_put_16(ctx, s->pb, SYNCWORD2); //Pb ++ spdif_put_16(ctx, s->pb, ctx->data_type); //Pc ++ spdif_put_16(ctx, s->pb, ctx->length_code);//Pd + } + + if (ctx->extra_bswap ^ (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN)) { +- put_buffer(s->pb, ctx->out_buf, ctx->out_bytes & ~1); ++ avio_write(s->pb, ctx->out_buf, ctx->out_bytes & ~1); + } else { +- av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE); +- if (!ctx->buffer) +- return AVERROR(ENOMEM); +- ff_spdif_bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)ctx->out_buf, ctx->out_bytes >> 1); +- put_buffer(s->pb, ctx->buffer, ctx->out_bytes & ~1); ++ av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!ctx->buffer) ++ return AVERROR(ENOMEM); ++ ff_spdif_bswap_buf16((uint16_t *)ctx->buffer, (uint16_t *)ctx->out_buf, ctx->out_bytes >> 1); ++ avio_write(s->pb, ctx->buffer, ctx->out_bytes & ~1); + } + + /* a final lone byte has to be MSB aligned */ + if (ctx->out_bytes & 1) +- spdif_put_16(s, ctx->out_buf[ctx->out_bytes - 1] << 8); ++ spdif_put_16(ctx, s->pb, ctx->out_buf[ctx->out_bytes - 1] << 8); + +- put_nbyte(s->pb, 0, padding); ++ ffio_fill(s->pb, 0, padding); + + av_log(s, AV_LOG_DEBUG, "type=%x len=%i pkt_offset=%i\n", + ctx->data_type, ctx->out_bytes, ctx->pkt_offset); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + + AVOutputFormat ff_spdif_muxer = { +- "spdif", +- NULL_IF_CONFIG_SMALL("IEC 61937 (used on S/PDIF - IEC958)"), +- NULL, +- "spdif", +- sizeof(IEC61937Context), +- CODEC_ID_AC3, +- CODEC_ID_NONE, +- spdif_write_header, +- spdif_write_packet, +- spdif_write_trailer, ++ .name = "spdif", ++ .long_name = NULL_IF_CONFIG_SMALL("IEC 61937 (used on S/PDIF - IEC958)"), ++ .extensions = "spdif", ++ .priv_data_size = sizeof(IEC61937Context), ++ .audio_codec = CODEC_ID_AC3, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = spdif_write_header, ++ .write_packet = spdif_write_packet, ++ .write_trailer = spdif_write_trailer, ++ .flags = AVFMT_NOTIMESTAMPS, + .priv_class = &class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdif.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdif.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/spdif.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/spdif.h 2012-05-14 14:08:55.217357753 +0200 +@@ -19,6 +19,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#ifndef AVFORMAT_SPDIF_H ++#define AVFORMAT_SPDIF_H ++ + #include + + #define SYNCWORD1 0xF872 +@@ -55,3 +58,5 @@ + }; + + void ff_spdif_bswap_buf16(uint16_t *dst, const uint16_t *src, int w); ++ ++#endif /* AVFORMAT_SPDIF_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/srtdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/srtdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/srtdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/srtdec.c 2012-05-14 14:08:55.220357813 +0200 +@@ -42,10 +42,10 @@ + + static int srt_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + if (!st) + return -1; +- av_set_pts_info(st, 64, 1, 1000); ++ avpriv_set_pts_info(st, 64, 1, 1000); + st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE; + st->codec->codec_id = CODEC_ID_SRT; + return 0; +@@ -75,7 +75,7 @@ + static int srt_read_packet(AVFormatContext *s, AVPacket *pkt) + { + char buffer[2048], *ptr = buffer, *ptr2; +- int64_t pos = url_ftell(s->pb); ++ int64_t pos = avio_tell(s->pb); + int res = AVERROR_EOF; + + do { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/swfdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/swfdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/swfdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/swfdec.c 2012-05-14 14:08:55.221357833 +0200 +@@ -23,18 +23,18 @@ + #include "libavutil/intreadwrite.h" + #include "swf.h" + +-static int get_swf_tag(ByteIOContext *pb, int *len_ptr) ++static int get_swf_tag(AVIOContext *pb, int *len_ptr) + { + int tag, len; + + if (url_feof(pb)) +- return -1; ++ return AVERROR_EOF; + +- tag = get_le16(pb); ++ tag = avio_rl16(pb); + len = tag & 0x3f; + tag = tag >> 6; + if (len == 0x3f) { +- len = get_le32(pb); ++ len = avio_rl32(pb); + } + // av_log(NULL, AV_LOG_DEBUG, "Tag: %d - Len: %d\n", tag, len); + *len_ptr = len; +@@ -55,10 +55,10 @@ + static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int nbits, len, tag; + +- tag = get_be32(pb) & 0xffffff00; ++ tag = avio_rb32(pb) & 0xffffff00; + + if (tag == MKBETAG('C', 'W', 'S', 0)) { + av_log(s, AV_LOG_ERROR, "Compressed SWF format not supported\n"); +@@ -66,13 +66,13 @@ + } + if (tag != MKBETAG('F', 'W', 'S', 0)) + return AVERROR(EIO); +- get_le32(pb); ++ avio_rl32(pb); + /* skip rectangle size */ +- nbits = get_byte(pb) >> 3; ++ nbits = avio_r8(pb) >> 3; + len = (4 * nbits - 3 + 7) / 8; +- url_fskip(pb, len); +- swf->frame_rate = get_le16(pb); /* 8.8 fixed */ +- get_le16(pb); /* frame count */ ++ avio_skip(pb, len); ++ swf->frame_rate = avio_rl16(pb); /* 8.8 fixed */ ++ avio_rl16(pb); /* frame count */ + + swf->samples_per_frame = 0; + s->ctx_flags |= AVFMTCTX_NOHEADER; +@@ -82,17 +82,17 @@ + static int swf_read_packet(AVFormatContext *s, AVPacket *pkt) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *vst = NULL, *ast = NULL, *st = 0; +- int tag, len, i, frame, v; ++ int tag, len, i, frame, v, res; + + for(;;) { +- uint64_t pos = url_ftell(pb); ++ uint64_t pos = avio_tell(pb); + tag = get_swf_tag(pb, &len); + if (tag < 0) +- return AVERROR(EIO); ++ return tag; + if (tag == TAG_VIDEOSTREAM) { +- int ch_id = get_le16(pb); ++ int ch_id = avio_rl16(pb); + len -= 2; + + for (i=0; inb_streams; i++) { +@@ -101,17 +101,18 @@ + goto skip; + } + +- get_le16(pb); +- get_le16(pb); +- get_le16(pb); +- get_byte(pb); ++ avio_rl16(pb); ++ avio_rl16(pb); ++ avio_rl16(pb); ++ avio_r8(pb); + /* Check for FLV1 */ +- vst = av_new_stream(s, ch_id); ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return -1; ++ vst->id = ch_id; + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, get_byte(pb)); +- av_set_pts_info(vst, 16, 256, swf->frame_rate); ++ vst->codec->codec_id = ff_codec_get_id(swf_codec_tags, avio_r8(pb)); ++ avpriv_set_pts_info(vst, 16, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + len -= 8; + } else if (tag == TAG_STREAMHEAD || tag == TAG_STREAMHEAD2) { +@@ -124,30 +125,33 @@ + goto skip; + } + +- get_byte(pb); +- v = get_byte(pb); +- swf->samples_per_frame = get_le16(pb); +- ast = av_new_stream(s, -1); /* -1 to avoid clash with video stream ch_id */ ++ avio_r8(pb); ++ v = avio_r8(pb); ++ swf->samples_per_frame = avio_rl16(pb); ++ ast = avformat_new_stream(s, NULL); + if (!ast) + return -1; ++ ast->id = -1; /* -1 to avoid clash with video stream ch_id */ + ast->codec->channels = 1 + (v&1); + ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; + ast->codec->codec_id = ff_codec_get_id(swf_audio_codec_tags, (v>>4) & 15); + ast->need_parsing = AVSTREAM_PARSE_FULL; + sample_rate_code= (v>>2) & 3; + if (!sample_rate_code) +- return AVERROR(EIO); +- ast->codec->sample_rate = 11025 << (sample_rate_code-1); +- av_set_pts_info(ast, 64, 1, ast->codec->sample_rate); ++ ast->codec->sample_rate = 5512; ++ else ++ ast->codec->sample_rate = 11025 << (sample_rate_code-1); ++ avpriv_set_pts_info(ast, 64, 1, ast->codec->sample_rate); + len -= 4; + } else if (tag == TAG_VIDEOFRAME) { +- int ch_id = get_le16(pb); ++ int ch_id = avio_rl16(pb); + len -= 2; + for(i=0; inb_streams; i++) { + st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO && st->id == ch_id) { +- frame = get_le16(pb); +- av_get_packet(pb, pkt, len-2); ++ frame = avio_rl16(pb); ++ if ((res = av_get_packet(pb, pkt, len-2)) < 0) ++ return res; + pkt->pos = pos; + pkt->pts = frame; + pkt->stream_index = st->index; +@@ -159,10 +163,12 @@ + st = s->streams[i]; + if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO && st->id == -1) { + if (st->codec->codec_id == CODEC_ID_MP3) { +- url_fskip(pb, 4); +- av_get_packet(pb, pkt, len-4); ++ avio_skip(pb, 4); ++ if ((res = av_get_packet(pb, pkt, len-4)) < 0) ++ return res; + } else { // ADPCM, PCM +- av_get_packet(pb, pkt, len); ++ if ((res = av_get_packet(pb, pkt, len)) < 0) ++ return res; + } + pkt->pos = pos; + pkt->stream_index = st->index; +@@ -176,42 +182,43 @@ + break; + } + if (i == s->nb_streams) { +- vst = av_new_stream(s, -2); /* -2 to avoid clash with video stream and audio stream */ ++ vst = avformat_new_stream(s, NULL); + if (!vst) + return -1; ++ vst->id = -2; /* -2 to avoid clash with video stream and audio stream */ + vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; + vst->codec->codec_id = CODEC_ID_MJPEG; +- av_set_pts_info(vst, 64, 256, swf->frame_rate); ++ avpriv_set_pts_info(vst, 64, 256, swf->frame_rate); + vst->codec->time_base = (AVRational){ 256, swf->frame_rate }; + st = vst; + } +- get_le16(pb); /* BITMAP_ID */ +- av_new_packet(pkt, len-2); +- get_buffer(pb, pkt->data, 4); ++ avio_rl16(pb); /* BITMAP_ID */ ++ if ((res = av_new_packet(pkt, len-2)) < 0) ++ return res; ++ avio_read(pb, pkt->data, 4); + if (AV_RB32(pkt->data) == 0xffd8ffd9 || + AV_RB32(pkt->data) == 0xffd9ffd8) { + /* old SWF files containing SOI/EOI as data start */ + /* files created by swink have reversed tag */ + pkt->size -= 4; +- get_buffer(pb, pkt->data, pkt->size); ++ avio_read(pb, pkt->data, pkt->size); + } else { +- get_buffer(pb, pkt->data + 4, pkt->size - 4); ++ avio_read(pb, pkt->data + 4, pkt->size - 4); + } + pkt->pos = pos; + pkt->stream_index = st->index; + return pkt->size; + } + skip: +- url_fskip(pb, len); ++ avio_skip(pb, len); + } +- return 0; + } + + AVInputFormat ff_swf_demuxer = { +- "swf", +- NULL_IF_CONFIG_SMALL("Flash format"), +- sizeof(SWFContext), +- swf_probe, +- swf_read_header, +- swf_read_packet, ++ .name = "swf", ++ .long_name = NULL_IF_CONFIG_SMALL("Flash format"), ++ .priv_data_size = sizeof(SWFContext), ++ .read_probe = swf_probe, ++ .read_header = swf_read_header, ++ .read_packet = swf_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/swfenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/swfenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/swfenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/swfenc.c 2012-05-14 14:08:55.223357874 +0200 +@@ -27,39 +27,39 @@ + static void put_swf_tag(AVFormatContext *s, int tag) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- swf->tag_pos = url_ftell(pb); ++ swf->tag_pos = avio_tell(pb); + swf->tag = tag; + /* reserve some room for the tag */ + if (tag & TAG_LONG) { +- put_le16(pb, 0); +- put_le32(pb, 0); ++ avio_wl16(pb, 0); ++ avio_wl32(pb, 0); + } else { +- put_le16(pb, 0); ++ avio_wl16(pb, 0); + } + } + + static void put_swf_end_tag(AVFormatContext *s) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t pos; + int tag_len, tag; + +- pos = url_ftell(pb); ++ pos = avio_tell(pb); + tag_len = pos - swf->tag_pos - 2; + tag = swf->tag; +- url_fseek(pb, swf->tag_pos, SEEK_SET); ++ avio_seek(pb, swf->tag_pos, SEEK_SET); + if (tag & TAG_LONG) { + tag &= ~TAG_LONG; +- put_le16(pb, (tag << 6) | 0x3f); +- put_le32(pb, tag_len - 4); ++ avio_wl16(pb, (tag << 6) | 0x3f); ++ avio_wl32(pb, tag_len - 4); + } else { + assert(tag_len < 0x3f); +- put_le16(pb, (tag << 6) | tag_len); ++ avio_wl16(pb, (tag << 6) | tag_len); + } +- url_fseek(pb, pos, SEEK_SET); ++ avio_seek(pb, pos, SEEK_SET); + } + + static inline void max_nbits(int *nbits_ptr, int val) +@@ -78,7 +78,7 @@ + *nbits_ptr = n; + } + +-static void put_swf_rect(ByteIOContext *pb, ++static void put_swf_rect(AVIOContext *pb, + int xmin, int xmax, int ymin, int ymax) + { + PutBitContext p; +@@ -102,7 +102,7 @@ + put_bits(&p, nbits, ymax & mask); + + flush_put_bits(&p); +- put_buffer(pb, buf, put_bits_ptr(&p) - p.buf); ++ avio_write(pb, buf, put_bits_ptr(&p) - p.buf); + } + + static void put_swf_line_edge(PutBitContext *pb, int dx, int dy) +@@ -134,7 +134,7 @@ + + #define FRAC_BITS 16 + +-static void put_swf_matrix(ByteIOContext *pb, ++static void put_swf_matrix(AVIOContext *pb, + int a, int b, int c, int d, int tx, int ty) + { + PutBitContext p; +@@ -167,13 +167,13 @@ + put_bits(&p, nbits, ty); + + flush_put_bits(&p); +- put_buffer(pb, buf, put_bits_ptr(&p) - p.buf); ++ avio_write(pb, buf, put_bits_ptr(&p) - p.buf); + } + + static int swf_write_header(AVFormatContext *s) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + PutBitContext p; + uint8_t buf1[256]; + int i, width, height, rate, rate_base; +@@ -229,7 +229,7 @@ + else + swf->samples_per_frame = (swf->audio_enc->sample_rate * rate_base) / rate; + +- put_tag(pb, "FWS"); ++ avio_write(pb, "FWS", 3); + + if (!strcmp("avm2", s->oformat->name)) + version = 9; +@@ -239,20 +239,20 @@ + version = 6; /* version 6 and above support FLV1 codec */ + else + version = 4; /* version 4 for mpeg audio support */ +- put_byte(pb, version); ++ avio_w8(pb, version); + +- put_le32(pb, DUMMY_FILE_SIZE); /* dummy size ++ avio_wl32(pb, DUMMY_FILE_SIZE); /* dummy size + (will be patched if not streamed) */ + + put_swf_rect(pb, 0, width * 20, 0, height * 20); +- put_le16(pb, (rate * 256) / rate_base); /* frame rate */ +- swf->duration_pos = url_ftell(pb); +- put_le16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */ ++ avio_wl16(pb, (rate * 256) / rate_base); /* frame rate */ ++ swf->duration_pos = avio_tell(pb); ++ avio_wl16(pb, (uint16_t)(DUMMY_DURATION * (int64_t)rate / rate_base)); /* frame count */ + + /* avm2/swf v9 (also v8?) files require a file attribute tag */ + if (version == 9) { + put_swf_tag(s, TAG_FILEATTRIBUTES); +- put_le32(pb, 1<<3); /* set ActionScript v3/AVM2 flag */ ++ avio_wl32(pb, 1<<3); /* set ActionScript v3/AVM2 flag */ + put_swf_end_tag(s); + } + +@@ -260,17 +260,17 @@ + if (swf->video_enc && swf->video_enc->codec_id == CODEC_ID_MJPEG) { + put_swf_tag(s, TAG_DEFINESHAPE); + +- put_le16(pb, SHAPE_ID); /* ID of shape */ ++ avio_wl16(pb, SHAPE_ID); /* ID of shape */ + /* bounding rectangle */ + put_swf_rect(pb, 0, width, 0, height); + /* style info */ +- put_byte(pb, 1); /* one fill style */ +- put_byte(pb, 0x41); /* clipped bitmap fill */ +- put_le16(pb, BITMAP_ID); /* bitmap ID */ ++ avio_w8(pb, 1); /* one fill style */ ++ avio_w8(pb, 0x41); /* clipped bitmap fill */ ++ avio_wl16(pb, BITMAP_ID); /* bitmap ID */ + /* position of the bitmap */ + put_swf_matrix(pb, (int)(1.0 * (1 << FRAC_BITS)), 0, + 0, (int)(1.0 * (1 << FRAC_BITS)), 0, 0); +- put_byte(pb, 0); /* no line style */ ++ avio_w8(pb, 0); /* no line style */ + + /* shape drawing */ + init_put_bits(&p, buf1, sizeof(buf1)); +@@ -295,7 +295,7 @@ + put_bits(&p, 5, 0); + + flush_put_bits(&p); +- put_buffer(pb, buf1, put_bits_ptr(&p) - p.buf); ++ avio_write(pb, buf1, put_bits_ptr(&p) - p.buf); + + put_swf_end_tag(s); + } +@@ -317,16 +317,16 @@ + v |= 0x02; /* 16 bit playback */ + if (swf->audio_enc->channels == 2) + v |= 0x01; /* stereo playback */ +- put_byte(s->pb, v); ++ avio_w8(s->pb, v); + v |= 0x20; /* mp3 compressed */ +- put_byte(s->pb, v); +- put_le16(s->pb, swf->samples_per_frame); /* avg samples per frame */ +- put_le16(s->pb, 0); ++ avio_w8(s->pb, v); ++ avio_wl16(s->pb, swf->samples_per_frame); /* avg samples per frame */ ++ avio_wl16(s->pb, 0); + + put_swf_end_tag(s); + } + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + return 0; + } + +@@ -334,7 +334,7 @@ + AVCodecContext *enc, const uint8_t *buf, int size) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + /* Flash Player limit */ + if (swf->swf_frame_number == 16000) +@@ -345,70 +345,70 @@ + if (swf->video_frame_number == 0) { + /* create a new video object */ + put_swf_tag(s, TAG_VIDEOSTREAM); +- put_le16(pb, VIDEO_ID); +- swf->vframes_pos = url_ftell(pb); +- put_le16(pb, 15000); /* hard flash player limit */ +- put_le16(pb, enc->width); +- put_le16(pb, enc->height); +- put_byte(pb, 0); +- put_byte(pb,ff_codec_get_tag(swf_codec_tags,enc->codec_id)); ++ avio_wl16(pb, VIDEO_ID); ++ swf->vframes_pos = avio_tell(pb); ++ avio_wl16(pb, 15000); /* hard flash player limit */ ++ avio_wl16(pb, enc->width); ++ avio_wl16(pb, enc->height); ++ avio_w8(pb, 0); ++ avio_w8(pb,ff_codec_get_tag(swf_codec_tags,enc->codec_id)); + put_swf_end_tag(s); + + /* place the video object for the first time */ + put_swf_tag(s, TAG_PLACEOBJECT2); +- put_byte(pb, 0x36); +- put_le16(pb, 1); +- put_le16(pb, VIDEO_ID); ++ avio_w8(pb, 0x36); ++ avio_wl16(pb, 1); ++ avio_wl16(pb, VIDEO_ID); + put_swf_matrix(pb, 1 << FRAC_BITS, 0, 0, 1 << FRAC_BITS, 0, 0); +- put_le16(pb, swf->video_frame_number); +- put_tag(pb, "video"); +- put_byte(pb, 0x00); ++ avio_wl16(pb, swf->video_frame_number); ++ avio_write(pb, "video", 5); ++ avio_w8(pb, 0x00); + put_swf_end_tag(s); + } else { + /* mark the character for update */ + put_swf_tag(s, TAG_PLACEOBJECT2); +- put_byte(pb, 0x11); +- put_le16(pb, 1); +- put_le16(pb, swf->video_frame_number); ++ avio_w8(pb, 0x11); ++ avio_wl16(pb, 1); ++ avio_wl16(pb, swf->video_frame_number); + put_swf_end_tag(s); + } + + /* set video frame data */ + put_swf_tag(s, TAG_VIDEOFRAME | TAG_LONG); +- put_le16(pb, VIDEO_ID); +- put_le16(pb, swf->video_frame_number++); +- put_buffer(pb, buf, size); ++ avio_wl16(pb, VIDEO_ID); ++ avio_wl16(pb, swf->video_frame_number++); ++ avio_write(pb, buf, size); + put_swf_end_tag(s); + } else if (enc->codec_id == CODEC_ID_MJPEG) { + if (swf->swf_frame_number > 0) { + /* remove the shape */ + put_swf_tag(s, TAG_REMOVEOBJECT); +- put_le16(pb, SHAPE_ID); /* shape ID */ +- put_le16(pb, 1); /* depth */ ++ avio_wl16(pb, SHAPE_ID); /* shape ID */ ++ avio_wl16(pb, 1); /* depth */ + put_swf_end_tag(s); + + /* free the bitmap */ + put_swf_tag(s, TAG_FREECHARACTER); +- put_le16(pb, BITMAP_ID); ++ avio_wl16(pb, BITMAP_ID); + put_swf_end_tag(s); + } + + put_swf_tag(s, TAG_JPEG2 | TAG_LONG); + +- put_le16(pb, BITMAP_ID); /* ID of the image */ ++ avio_wl16(pb, BITMAP_ID); /* ID of the image */ + + /* a dummy jpeg header seems to be required */ +- put_be32(pb, 0xffd8ffd9); ++ avio_wb32(pb, 0xffd8ffd9); + /* write the jpeg image */ +- put_buffer(pb, buf, size); ++ avio_write(pb, buf, size); + + put_swf_end_tag(s); + + /* draw the shape */ + + put_swf_tag(s, TAG_PLACEOBJECT); +- put_le16(pb, SHAPE_ID); /* shape ID */ +- put_le16(pb, 1); /* depth */ ++ avio_wl16(pb, SHAPE_ID); /* shape ID */ ++ avio_wl16(pb, 1); /* depth */ + put_swf_matrix(pb, 20 << FRAC_BITS, 0, 0, 20 << FRAC_BITS, 0, 0); + put_swf_end_tag(s); + } +@@ -419,9 +419,9 @@ + if (swf->audio_enc && av_fifo_size(swf->audio_fifo)) { + int frame_size = av_fifo_size(swf->audio_fifo); + put_swf_tag(s, TAG_STREAMBLOCK | TAG_LONG); +- put_le16(pb, swf->sound_samples); +- put_le16(pb, 0); // seek samples +- av_fifo_generic_read(swf->audio_fifo, pb, frame_size, &put_buffer); ++ avio_wl16(pb, swf->sound_samples); ++ avio_wl16(pb, 0); // seek samples ++ av_fifo_generic_read(swf->audio_fifo, pb, frame_size, (void*)avio_write); + put_swf_end_tag(s); + + /* update FIFO */ +@@ -432,7 +432,7 @@ + put_swf_tag(s, TAG_SHOWFRAME); + put_swf_end_tag(s); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + return 0; + } +@@ -473,7 +473,7 @@ + static int swf_write_trailer(AVFormatContext *s) + { + SWFContext *swf = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVCodecContext *enc, *video_enc; + int file_size, i; + +@@ -489,47 +489,46 @@ + put_swf_tag(s, TAG_END); + put_swf_end_tag(s); + +- put_flush_packet(s->pb); ++ avio_flush(s->pb); + + /* patch file size and number of frames if not streamed */ +- if (!url_is_streamed(s->pb) && video_enc) { +- file_size = url_ftell(pb); +- url_fseek(pb, 4, SEEK_SET); +- put_le32(pb, file_size); +- url_fseek(pb, swf->duration_pos, SEEK_SET); +- put_le16(pb, swf->video_frame_number); +- url_fseek(pb, swf->vframes_pos, SEEK_SET); +- put_le16(pb, swf->video_frame_number); +- url_fseek(pb, file_size, SEEK_SET); ++ if (s->pb->seekable && video_enc) { ++ file_size = avio_tell(pb); ++ avio_seek(pb, 4, SEEK_SET); ++ avio_wl32(pb, file_size); ++ avio_seek(pb, swf->duration_pos, SEEK_SET); ++ avio_wl16(pb, swf->video_frame_number); ++ avio_seek(pb, swf->vframes_pos, SEEK_SET); ++ avio_wl16(pb, swf->video_frame_number); ++ avio_seek(pb, file_size, SEEK_SET); + } + return 0; + } + + #if CONFIG_SWF_MUXER + AVOutputFormat ff_swf_muxer = { +- "swf", +- NULL_IF_CONFIG_SMALL("Flash format"), +- "application/x-shockwave-flash", +- "swf", +- sizeof(SWFContext), +- CODEC_ID_MP3, +- CODEC_ID_FLV1, +- swf_write_header, +- swf_write_packet, +- swf_write_trailer, ++ .name = "swf", ++ .long_name = NULL_IF_CONFIG_SMALL("Flash format"), ++ .mime_type = "application/x-shockwave-flash", ++ .extensions = "swf", ++ .priv_data_size = sizeof(SWFContext), ++ .audio_codec = CODEC_ID_MP3, ++ .video_codec = CODEC_ID_FLV1, ++ .write_header = swf_write_header, ++ .write_packet = swf_write_packet, ++ .write_trailer = swf_write_trailer, + }; + #endif + #if CONFIG_AVM2_MUXER + AVOutputFormat ff_avm2_muxer = { +- "avm2", +- NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"), +- "application/x-shockwave-flash", +- NULL, +- sizeof(SWFContext), +- CODEC_ID_MP3, +- CODEC_ID_FLV1, +- swf_write_header, +- swf_write_packet, +- swf_write_trailer, ++ .name = "avm2", ++ .long_name = NULL_IF_CONFIG_SMALL("Flash 9 (AVM2) format"), ++ .mime_type = "application/x-shockwave-flash", ++ .priv_data_size = sizeof(SWFContext), ++ .audio_codec = CODEC_ID_MP3, ++ .video_codec = CODEC_ID_FLV1, ++ .write_header = swf_write_header, ++ .write_packet = swf_write_packet, ++ .write_trailer = swf_write_trailer, + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tcp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tcp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tcp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tcp.c 2012-05-14 14:08:55.224357894 +0200 +@@ -19,10 +19,12 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "libavutil/parseutils.h" + #include + #include "internal.h" + #include "network.h" + #include "os_support.h" ++#include "url.h" + #if HAVE_POLL_H + #include + #endif +@@ -37,9 +39,13 @@ + { + struct addrinfo hints, *ai, *cur_ai; + int port, fd = -1; +- TCPContext *s = NULL; ++ TCPContext *s = h->priv_data; ++ int listen_socket = 0; ++ const char *p; ++ char buf[256]; + int ret; + socklen_t optlen; ++ int timeout = 50; + char hostname[1024],proto[1024],path[1024]; + char portstr[10]; + +@@ -48,13 +54,21 @@ + if (strcmp(proto,"tcp") || port <= 0 || port >= 65536) + return AVERROR(EINVAL); + ++ p = strchr(uri, '?'); ++ if (p) { ++ if (av_find_info_tag(buf, sizeof(buf), "listen", p)) ++ listen_socket = 1; ++ if (av_find_info_tag(buf, sizeof(buf), "timeout", p)) { ++ timeout = strtol(buf, NULL, 10); ++ } ++ } + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_socktype = SOCK_STREAM; + snprintf(portstr, sizeof(portstr), "%d", port); + ret = getaddrinfo(hostname, portstr, &hints, &ai); + if (ret) { +- av_log(NULL, AV_LOG_ERROR, ++ av_log(h, AV_LOG_ERROR, + "Failed to resolve hostname %s: %s\n", + hostname, gai_strerror(ret)); + return AVERROR(EIO); +@@ -63,51 +77,64 @@ + cur_ai = ai; + + restart: ++ ret = AVERROR(EIO); + fd = socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol); + if (fd < 0) + goto fail; +- ff_socket_nonblock(fd, 1); + ++ if (listen_socket) { ++ int fd1; ++ ret = bind(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); ++ listen(fd, 1); ++ fd1 = accept(fd, NULL, NULL); ++ closesocket(fd); ++ fd = fd1; ++ ff_socket_nonblock(fd, 1); ++ } else { + redo: +- ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); ++ ff_socket_nonblock(fd, 1); ++ ret = connect(fd, cur_ai->ai_addr, cur_ai->ai_addrlen); ++ } ++ + if (ret < 0) { + struct pollfd p = {fd, POLLOUT, 0}; +- if (ff_neterrno() == FF_NETERROR(EINTR)) { +- if (url_interrupt_cb()) ++ ret = ff_neterrno(); ++ if (ret == AVERROR(EINTR)) { ++ if (ff_check_interrupt(&h->interrupt_callback)) { ++ ret = AVERROR_EXIT; + goto fail1; ++ } + goto redo; + } +- if (ff_neterrno() != FF_NETERROR(EINPROGRESS) && +- ff_neterrno() != FF_NETERROR(EAGAIN)) ++ if (ret != AVERROR(EINPROGRESS) && ++ ret != AVERROR(EAGAIN)) + goto fail; + + /* wait until we are connected or until abort */ +- for(;;) { +- if (url_interrupt_cb()) { +- ret = AVERROR(EINTR); ++ while(timeout--) { ++ if (ff_check_interrupt(&h->interrupt_callback)) { ++ ret = AVERROR_EXIT; + goto fail1; + } + ret = poll(&p, 1, 100); + if (ret > 0) + break; + } +- ++ if (ret <= 0) { ++ ret = AVERROR(ETIMEDOUT); ++ goto fail; ++ } + /* test error */ + optlen = sizeof(ret); + getsockopt (fd, SOL_SOCKET, SO_ERROR, &ret, &optlen); + if (ret != 0) { +- av_log(NULL, AV_LOG_ERROR, ++ av_log(h, AV_LOG_ERROR, + "TCP connection to %s:%d failed: %s\n", + hostname, port, strerror(ret)); ++ ret = AVERROR(ret); + goto fail; + } + } +- s = av_malloc(sizeof(TCPContext)); +- if (!s) { +- freeaddrinfo(ai); +- return AVERROR(ENOMEM); +- } +- h->priv_data = s; + h->is_streamed = 1; + s->fd = fd; + freeaddrinfo(ai); +@@ -121,7 +148,6 @@ + closesocket(fd); + goto restart; + } +- ret = AVERROR(EIO); + fail1: + if (fd >= 0) + closesocket(fd); +@@ -132,63 +158,35 @@ + static int tcp_read(URLContext *h, uint8_t *buf, int size) + { + TCPContext *s = h->priv_data; +- struct pollfd p = {s->fd, POLLIN, 0}; +- int len, ret; ++ int ret; + +- for (;;) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); +- ret = poll(&p, 1, 100); +- if (ret == 1 && p.revents & POLLIN) { +- len = recv(s->fd, buf, size, 0); +- if (len < 0) { +- if (ff_neterrno() != FF_NETERROR(EINTR) && +- ff_neterrno() != FF_NETERROR(EAGAIN)) +- return ff_neterrno(); +- } else return len; +- } else if (ret < 0) { +- if (ff_neterrno() == FF_NETERROR(EINTR)) +- continue; +- return -1; +- } ++ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ++ ret = ff_network_wait_fd(s->fd, 0); ++ if (ret < 0) ++ return ret; + } ++ ret = recv(s->fd, buf, size, 0); ++ return ret < 0 ? ff_neterrno() : ret; + } + + static int tcp_write(URLContext *h, const uint8_t *buf, int size) + { + TCPContext *s = h->priv_data; +- int ret, size1, len; +- struct pollfd p = {s->fd, POLLOUT, 0}; ++ int ret; + +- size1 = size; +- while (size > 0) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); +- ret = poll(&p, 1, 100); +- if (ret == 1 && p.revents & POLLOUT) { +- len = send(s->fd, buf, size, 0); +- if (len < 0) { +- if (ff_neterrno() != FF_NETERROR(EINTR) && +- ff_neterrno() != FF_NETERROR(EAGAIN)) +- return ff_neterrno(); +- continue; +- } +- size -= len; +- buf += len; +- } else if (ret < 0) { +- if (ff_neterrno() == FF_NETERROR(EINTR)) +- continue; +- return -1; +- } ++ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ++ ret = ff_network_wait_fd(s->fd, 1); ++ if (ret < 0) ++ return ret; + } +- return size1 - size; ++ ret = send(s->fd, buf, size, 0); ++ return ret < 0 ? ff_neterrno() : ret; + } + + static int tcp_close(URLContext *h) + { + TCPContext *s = h->priv_data; + closesocket(s->fd); +- av_free(s); + return 0; + } + +@@ -199,11 +197,12 @@ + } + + URLProtocol ff_tcp_protocol = { +- "tcp", +- tcp_open, +- tcp_read, +- tcp_write, +- NULL, /* seek */ +- tcp_close, ++ .name = "tcp", ++ .url_open = tcp_open, ++ .url_read = tcp_read, ++ .url_write = tcp_write, ++ .url_close = tcp_close, + .url_get_file_handle = tcp_get_file_handle, ++ .priv_data_size = sizeof(TCPContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/thp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/thp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/thp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/thp.c 2012-05-14 14:08:55.225357914 +0200 +@@ -20,7 +20,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" + #include "avformat.h" ++#include "internal.h" + + typedef struct ThpDemuxContext { + int version; +@@ -39,7 +41,7 @@ + unsigned char components[16]; + AVStream* vst; + int has_audio; +- int audiosize; ++ unsigned audiosize; + } ThpDemuxContext; + + +@@ -57,35 +59,38 @@ + { + ThpDemuxContext *thp = s->priv_data; + AVStream *st; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; ++ int64_t fsize= avio_size(pb); + int i; + + /* Read the file header. */ +- get_be32(pb); /* Skip Magic. */ +- thp->version = get_be32(pb); ++ avio_rb32(pb); /* Skip Magic. */ ++ thp->version = avio_rb32(pb); + +- get_be32(pb); /* Max buf size. */ +- get_be32(pb); /* Max samples. */ ++ avio_rb32(pb); /* Max buf size. */ ++ avio_rb32(pb); /* Max samples. */ + +- thp->fps = av_d2q(av_int2flt(get_be32(pb)), INT_MAX); +- thp->framecnt = get_be32(pb); +- thp->first_framesz = get_be32(pb); +- get_be32(pb); /* Data size. */ +- +- thp->compoff = get_be32(pb); +- get_be32(pb); /* offsetDataOffset. */ +- thp->first_frame = get_be32(pb); +- thp->last_frame = get_be32(pb); ++ thp->fps = av_d2q(av_int2float(avio_rb32(pb)), INT_MAX); ++ thp->framecnt = avio_rb32(pb); ++ thp->first_framesz = avio_rb32(pb); ++ pb->maxsize = avio_rb32(pb); ++ if(fsize>0 && (!pb->maxsize || fsize < pb->maxsize)) ++ pb->maxsize= fsize; ++ ++ thp->compoff = avio_rb32(pb); ++ avio_rb32(pb); /* offsetDataOffset. */ ++ thp->first_frame = avio_rb32(pb); ++ thp->last_frame = avio_rb32(pb); + + thp->next_framesz = thp->first_framesz; + thp->next_frame = thp->first_frame; + + /* Read the component structure. */ +- url_fseek (pb, thp->compoff, SEEK_SET); +- thp->compcount = get_be32(pb); ++ avio_seek (pb, thp->compoff, SEEK_SET); ++ thp->compcount = avio_rb32(pb); + + /* Read the list of component types. */ +- get_buffer(pb, thp->components, 16); ++ avio_read(pb, thp->components, 16); + + for (i = 0; i < thp->compcount; i++) { + if (thp->components[i] == 0) { +@@ -93,40 +98,40 @@ + break; + + /* Video component. */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + /* The denominator and numerator are switched because 1/fps + is required. */ +- av_set_pts_info(st, 64, thp->fps.den, thp->fps.num); ++ avpriv_set_pts_info(st, 64, thp->fps.den, thp->fps.num); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_THP; + st->codec->codec_tag = 0; /* no fourcc */ +- st->codec->width = get_be32(pb); +- st->codec->height = get_be32(pb); ++ st->codec->width = avio_rb32(pb); ++ st->codec->height = avio_rb32(pb); + st->codec->sample_rate = av_q2d(thp->fps); + thp->vst = st; + thp->video_stream_index = st->index; + + if (thp->version == 0x11000) +- get_be32(pb); /* Unknown. */ ++ avio_rb32(pb); /* Unknown. */ + } else if (thp->components[i] == 1) { + if (thp->has_audio != 0) + break; + + /* Audio component. */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ADPCM_THP; + st->codec->codec_tag = 0; /* no fourcc */ +- st->codec->channels = get_be32(pb); /* numChannels. */ +- st->codec->sample_rate = get_be32(pb); /* Frequency. */ ++ st->codec->channels = avio_rb32(pb); /* numChannels. */ ++ st->codec->sample_rate = avio_rb32(pb); /* Frequency. */ + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + thp->audio_stream_index = st->index; + thp->has_audio = 1; +@@ -140,8 +145,8 @@ + AVPacket *pkt) + { + ThpDemuxContext *thp = s->priv_data; +- ByteIOContext *pb = s->pb; +- int size; ++ AVIOContext *pb = s->pb; ++ unsigned int size; + int ret; + + if (thp->audiosize == 0) { +@@ -149,19 +154,19 @@ + if (thp->frame >= thp->framecnt) + return AVERROR(EIO); + +- url_fseek(pb, thp->next_frame, SEEK_SET); ++ avio_seek(pb, thp->next_frame, SEEK_SET); + + /* Locate the next frame and read out its size. */ + thp->next_frame += thp->next_framesz; +- thp->next_framesz = get_be32(pb); ++ thp->next_framesz = avio_rb32(pb); + +- get_be32(pb); /* Previous total size. */ +- size = get_be32(pb); /* Total size of this frame. */ ++ avio_rb32(pb); /* Previous total size. */ ++ size = avio_rb32(pb); /* Total size of this frame. */ + + /* Store the audiosize so the next time this function is called, + the audio can be read. */ + if (thp->has_audio) +- thp->audiosize = get_be32(pb); /* Audio size. */ ++ thp->audiosize = avio_rb32(pb); /* Audio size. */ + else + thp->frame++; + +@@ -188,10 +193,10 @@ + } + + AVInputFormat ff_thp_demuxer = { +- "thp", +- NULL_IF_CONFIG_SMALL("THP"), +- sizeof(ThpDemuxContext), +- thp_probe, +- thp_read_header, +- thp_read_packet ++ .name = "thp", ++ .long_name = NULL_IF_CONFIG_SMALL("THP"), ++ .priv_data_size = sizeof(ThpDemuxContext), ++ .read_probe = thp_probe, ++ .read_header = thp_read_header, ++ .read_packet = thp_read_packet + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tiertexseq.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tiertexseq.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tiertexseq.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tiertexseq.c 2012-05-14 14:08:55.226357934 +0200 +@@ -25,6 +25,7 @@ + */ + + #include "avformat.h" ++#include "internal.h" + + #define SEQ_FRAME_SIZE 6144 + #define SEQ_FRAME_W 256 +@@ -78,15 +79,15 @@ + return AVPROBE_SCORE_MAX / 4; + } + +-static int seq_init_frame_buffers(SeqDemuxContext *seq, ByteIOContext *pb) ++static int seq_init_frame_buffers(SeqDemuxContext *seq, AVIOContext *pb) + { + int i, sz; + TiertexSeqFrameBuffer *seq_buffer; + +- url_fseek(pb, 256, SEEK_SET); ++ avio_seek(pb, 256, SEEK_SET); + + for (i = 0; i < SEQ_NUM_FRAME_BUFFERS; i++) { +- sz = get_le16(pb); ++ sz = avio_rl16(pb); + if (sz == 0) + break; + else { +@@ -102,7 +103,7 @@ + return 0; + } + +-static int seq_fill_buffer(SeqDemuxContext *seq, ByteIOContext *pb, int buffer_num, unsigned int data_offs, int data_size) ++static int seq_fill_buffer(SeqDemuxContext *seq, AVIOContext *pb, int buffer_num, unsigned int data_offs, int data_size) + { + TiertexSeqFrameBuffer *seq_buffer; + +@@ -113,25 +114,25 @@ + if (seq_buffer->fill_size + data_size > seq_buffer->data_size || data_size <= 0) + return AVERROR_INVALIDDATA; + +- url_fseek(pb, seq->current_frame_offs + data_offs, SEEK_SET); +- if (get_buffer(pb, seq_buffer->data + seq_buffer->fill_size, data_size) != data_size) ++ avio_seek(pb, seq->current_frame_offs + data_offs, SEEK_SET); ++ if (avio_read(pb, seq_buffer->data + seq_buffer->fill_size, data_size) != data_size) + return AVERROR(EIO); + + seq_buffer->fill_size += data_size; + return 0; + } + +-static int seq_parse_frame_data(SeqDemuxContext *seq, ByteIOContext *pb) ++static int seq_parse_frame_data(SeqDemuxContext *seq, AVIOContext *pb) + { + unsigned int offset_table[4], buffer_num[4]; + TiertexSeqFrameBuffer *seq_buffer; + int i, e, err; + + seq->current_frame_offs += SEQ_FRAME_SIZE; +- url_fseek(pb, seq->current_frame_offs, SEEK_SET); ++ avio_seek(pb, seq->current_frame_offs, SEEK_SET); + + /* sound data */ +- seq->current_audio_data_offs = get_le16(pb); ++ seq->current_audio_data_offs = avio_rl16(pb); + if (seq->current_audio_data_offs) { + seq->current_audio_data_size = SEQ_AUDIO_BUFFER_SIZE * 2; + } else { +@@ -139,7 +140,7 @@ + } + + /* palette data */ +- seq->current_pal_data_offs = get_le16(pb); ++ seq->current_pal_data_offs = avio_rl16(pb); + if (seq->current_pal_data_offs) { + seq->current_pal_data_size = 768; + } else { +@@ -148,10 +149,10 @@ + + /* video data */ + for (i = 0; i < 4; i++) +- buffer_num[i] = get_byte(pb); ++ buffer_num[i] = avio_r8(pb); + + for (i = 0; i < 4; i++) +- offset_table[i] = get_le16(pb); ++ offset_table[i] = avio_rl16(pb); + + for (i = 0; i < 3; i++) { + if (offset_table[i]) { +@@ -184,7 +185,7 @@ + { + int i, rc; + SeqDemuxContext *seq = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + + /* init internal buffers */ +@@ -206,11 +207,11 @@ + seq->audio_buffer_full = 0; + + /* initialize the video decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 32, 1, SEQ_FRAME_RATE); ++ avpriv_set_pts_info(st, 32, 1, SEQ_FRAME_RATE); + seq->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_TIERTEXSEQVIDEO; +@@ -219,11 +220,11 @@ + st->codec->height = SEQ_FRAME_H; + + /* initialize the audio decoder stream */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE); ++ avpriv_set_pts_info(st, 32, 1, SEQ_SAMPLE_RATE); + seq->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_PCM_S16BE; +@@ -241,7 +242,7 @@ + { + int rc; + SeqDemuxContext *seq = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (!seq->audio_buffer_full) { + rc = seq_parse_frame_data(seq, pb); +@@ -256,8 +257,8 @@ + pkt->data[0] = 0; + if (seq->current_pal_data_size) { + pkt->data[0] |= 1; +- url_fseek(pb, seq->current_frame_offs + seq->current_pal_data_offs, SEEK_SET); +- if (get_buffer(pb, &pkt->data[1], seq->current_pal_data_size) != seq->current_pal_data_size) ++ avio_seek(pb, seq->current_frame_offs + seq->current_pal_data_offs, SEEK_SET); ++ if (avio_read(pb, &pkt->data[1], seq->current_pal_data_size) != seq->current_pal_data_size) + return AVERROR(EIO); + } + if (seq->current_video_data_size) { +@@ -279,7 +280,7 @@ + if (seq->current_audio_data_offs == 0) /* end of data reached */ + return AVERROR(EIO); + +- url_fseek(pb, seq->current_frame_offs + seq->current_audio_data_offs, SEEK_SET); ++ avio_seek(pb, seq->current_frame_offs + seq->current_audio_data_offs, SEEK_SET); + rc = av_get_packet(pb, pkt, seq->current_audio_data_size); + if (rc < 0) + return rc; +@@ -303,11 +304,11 @@ + } + + AVInputFormat ff_tiertexseq_demuxer = { +- "tiertexseq", +- NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ format"), +- sizeof(SeqDemuxContext), +- seq_probe, +- seq_read_header, +- seq_read_packet, +- seq_read_close, ++ .name = "tiertexseq", ++ .long_name = NULL_IF_CONFIG_SMALL("Tiertex Limited SEQ format"), ++ .priv_data_size = sizeof(SeqDemuxContext), ++ .read_probe = seq_probe, ++ .read_header = seq_read_header, ++ .read_packet = seq_read_packet, ++ .read_close = seq_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/timefilter.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/timefilter.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/timefilter.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/timefilter.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,149 +0,0 @@ +-/* +- * Delay Locked Loop based time filter +- * Copyright (c) 2009 Samalyse +- * Copyright (c) 2009 Michael Niedermayer +- * Author: Olivier Guilyardi +- * Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +- +-#include "config.h" +-#include "avformat.h" +-#include "timefilter.h" +- +-struct TimeFilter { +- /// Delay Locked Loop data. These variables refer to mathematical +- /// concepts described in: http://www.kokkinizita.net/papers/usingdll.pdf +- double cycle_time; +- double feedback2_factor; +- double feedback3_factor; +- double clock_period; +- int count; +-}; +- +-TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor) +-{ +- TimeFilter *self = av_mallocz(sizeof(TimeFilter)); +- self->clock_period = clock_period; +- self->feedback2_factor = feedback2_factor; +- self->feedback3_factor = feedback3_factor; +- return self; +-} +- +-void ff_timefilter_destroy(TimeFilter *self) +-{ +- av_freep(&self); +-} +- +-void ff_timefilter_reset(TimeFilter *self) +-{ +- self->count = 0; +-} +- +-double ff_timefilter_update(TimeFilter *self, double system_time, double period) +-{ +- self->count++; +- if (self->count==1) { +- /// init loop +- self->cycle_time = system_time; +- } else { +- double loop_error; +- self->cycle_time += self->clock_period * period; +- /// calculate loop error +- loop_error = system_time - self->cycle_time; +- +- /// update loop +- self->cycle_time += FFMAX(self->feedback2_factor, 1.0/(self->count)) * loop_error; +- self->clock_period += self->feedback3_factor * loop_error / period; +- } +- return self->cycle_time; +-} +- +-#ifdef TEST +-#include "libavutil/lfg.h" +-#define LFG_MAX ((1LL << 32) - 1) +- +-int main(void) +-{ +- AVLFG prng; +- double n0,n1; +-#define SAMPLES 1000 +- double ideal[SAMPLES]; +- double samples[SAMPLES]; +-#if 1 +- for(n0= 0; n0<40; n0=2*n0+1){ +- for(n1= 0; n1<10; n1=2*n1+1){ +-#else +- {{ +- n0=7; +- n1=1; +-#endif +- double best_error= 1000000000; +- double bestpar0=1; +- double bestpar1=0.001; +- int better, i; +- +- av_lfg_init(&prng, 123); +- for(i=0; i +- * Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVFORMAT_TIMEFILTER_H +-#define AVFORMAT_TIMEFILTER_H +- +-/** +- * Opaque type representing a time filter state +- * +- * The purpose of this filter is to provide a way to compute accurate time +- * stamps that can be compared to wall clock time, especially when dealing +- * with two clocks: the system clock and a hardware device clock, such as +- * a soundcard. +- */ +-typedef struct TimeFilter TimeFilter; +- +- +-/** +- * Create a new Delay Locked Loop time filter +- * +- * feedback2_factor and feedback3_factor are the factors used for the +- * multiplications that are respectively performed in the second and third +- * feedback paths of the loop. +- * +- * Unless you know what you are doing, you should set these as follow: +- * +- * o = 2 * M_PI * bandwidth * period +- * feedback2_factor = sqrt(2 * o) +- * feedback3_factor = o * o +- * +- * Where bandwidth is up to you to choose. Smaller values will filter out more +- * of the jitter, but also take a longer time for the loop to settle. A good +- * starting point is something between 0.3 and 3 Hz. +- * +- * @param clock_period period of the hardware clock in seconds +- * (for example 1.0/44100) +- * +- * For more details about these parameters and background concepts please see: +- * http://www.kokkinizita.net/papers/usingdll.pdf +- */ +-TimeFilter * ff_timefilter_new(double clock_period, double feedback2_factor, double feedback3_factor); +- +-/** +- * Update the filter +- * +- * This function must be called in real time, at each process cycle. +- * +- * @param period the device cycle duration in clock_periods. For example, at +- * 44.1kHz and a buffer size of 512 frames, period = 512 when clock_period +- * was 1.0/44100, or 512/44100 if clock_period was 1. +- * +- * system_time, in seconds, should be the value of the system clock time, +- * at (or as close as possible to) the moment the device hardware interrupt +- * occured (or any other event the device clock raises at the beginning of a +- * cycle). +- * +- * @return the filtered time, in seconds +- */ +-double ff_timefilter_update(TimeFilter *self, double system_time, double period); +- +-/** +- * Reset the filter +- * +- * This function should mainly be called in case of XRUN. +- * +- * Warning: after calling this, the filter is in an undetermined state until +- * the next call to ff_timefilter_update() +- */ +-void ff_timefilter_reset(TimeFilter *); +- +-/** +- * Free all resources associated with the filter +- */ +-void ff_timefilter_destroy(TimeFilter *); +- +-#endif /* AVFORMAT_TIMEFILTER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tls.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tls.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tls.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tls.c 2012-05-14 14:08:55.228357974 +0200 +@@ -0,0 +1,252 @@ ++/* ++ * TLS/SSL Protocol ++ * Copyright (c) 2011 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avformat.h" ++#include "url.h" ++#include "libavutil/avstring.h" ++#if CONFIG_GNUTLS ++#include ++#define TLS_read(c, buf, size) gnutls_record_recv(c->session, buf, size) ++#define TLS_write(c, buf, size) gnutls_record_send(c->session, buf, size) ++#define TLS_shutdown(c) gnutls_bye(c->session, GNUTLS_SHUT_RDWR) ++#define TLS_free(c) do { \ ++ if (c->session) \ ++ gnutls_deinit(c->session); \ ++ if (c->cred) \ ++ gnutls_certificate_free_credentials(c->cred); \ ++ } while (0) ++#elif CONFIG_OPENSSL ++#include ++#include ++#include ++#define TLS_read(c, buf, size) SSL_read(c->ssl, buf, size) ++#define TLS_write(c, buf, size) SSL_write(c->ssl, buf, size) ++#define TLS_shutdown(c) SSL_shutdown(c->ssl) ++#define TLS_free(c) do { \ ++ if (c->ssl) \ ++ SSL_free(c->ssl); \ ++ if (c->ctx) \ ++ SSL_CTX_free(c->ctx); \ ++ } while (0) ++#endif ++#include "network.h" ++#include "os_support.h" ++#include "internal.h" ++#if HAVE_POLL_H ++#include ++#endif ++ ++typedef struct { ++ const AVClass *class; ++ URLContext *tcp; ++#if CONFIG_GNUTLS ++ gnutls_session_t session; ++ gnutls_certificate_credentials_t cred; ++#elif CONFIG_OPENSSL ++ SSL_CTX *ctx; ++ SSL *ssl; ++#endif ++ int fd; ++} TLSContext; ++ ++static int do_tls_poll(URLContext *h, int ret) ++{ ++ TLSContext *c = h->priv_data; ++ struct pollfd p = { c->fd, 0, 0 }; ++#if CONFIG_GNUTLS ++ if (ret != GNUTLS_E_AGAIN && ret != GNUTLS_E_INTERRUPTED) { ++ av_log(h, AV_LOG_ERROR, "%s\n", gnutls_strerror(ret)); ++ return AVERROR(EIO); ++ } ++ if (gnutls_record_get_direction(c->session)) ++ p.events = POLLOUT; ++ else ++ p.events = POLLIN; ++#elif CONFIG_OPENSSL ++ ret = SSL_get_error(c->ssl, ret); ++ if (ret == SSL_ERROR_WANT_READ) { ++ p.events = POLLIN; ++ } else if (ret == SSL_ERROR_WANT_WRITE) { ++ p.events = POLLOUT; ++ } else { ++ av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL)); ++ return AVERROR(EIO); ++ } ++#endif ++ if (h->flags & AVIO_FLAG_NONBLOCK) ++ return AVERROR(EAGAIN); ++ while (1) { ++ int n = poll(&p, 1, 100); ++ if (n > 0) ++ break; ++ if (ff_check_interrupt(&h->interrupt_callback)) ++ return AVERROR(EINTR); ++ } ++ return 0; ++} ++ ++static int tls_open(URLContext *h, const char *uri, int flags) ++{ ++ TLSContext *c = h->priv_data; ++ int ret; ++ int port; ++ char buf[200], host[200]; ++ int numerichost = 0; ++ struct addrinfo hints = { 0 }, *ai = NULL; ++ const char *proxy_path; ++ int use_proxy; ++ ++ ff_tls_init(); ++ ++ proxy_path = getenv("http_proxy"); ++ use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && ++ av_strstart(proxy_path, "http://", NULL); ++ ++ av_url_split(NULL, 0, NULL, 0, host, sizeof(host), &port, NULL, 0, uri); ++ ff_url_join(buf, sizeof(buf), "tcp", NULL, host, port, NULL); ++ ++ hints.ai_flags = AI_NUMERICHOST; ++ if (!getaddrinfo(host, NULL, &hints, &ai)) { ++ numerichost = 1; ++ freeaddrinfo(ai); ++ } ++ ++ if (use_proxy) { ++ char proxy_host[200], proxy_auth[200], dest[200]; ++ int proxy_port; ++ av_url_split(NULL, 0, proxy_auth, sizeof(proxy_auth), ++ proxy_host, sizeof(proxy_host), &proxy_port, NULL, 0, ++ proxy_path); ++ ff_url_join(dest, sizeof(dest), NULL, NULL, host, port, NULL); ++ ff_url_join(buf, sizeof(buf), "httpproxy", proxy_auth, proxy_host, ++ proxy_port, "/%s", dest); ++ } ++ ++ ret = ffurl_open(&c->tcp, buf, AVIO_FLAG_READ_WRITE, ++ &h->interrupt_callback, NULL); ++ if (ret) ++ goto fail; ++ c->fd = ffurl_get_file_handle(c->tcp); ++ ++#if CONFIG_GNUTLS ++ gnutls_init(&c->session, GNUTLS_CLIENT); ++ if (!numerichost) ++ gnutls_server_name_set(c->session, GNUTLS_NAME_DNS, host, strlen(host)); ++ gnutls_certificate_allocate_credentials(&c->cred); ++ gnutls_certificate_set_verify_flags(c->cred, 0); ++ gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, c->cred); ++ gnutls_transport_set_ptr(c->session, (gnutls_transport_ptr_t) ++ (intptr_t) c->fd); ++ gnutls_priority_set_direct(c->session, "NORMAL", NULL); ++ while (1) { ++ ret = gnutls_handshake(c->session); ++ if (ret == 0) ++ break; ++ if ((ret = do_tls_poll(h, ret)) < 0) ++ goto fail; ++ } ++#elif CONFIG_OPENSSL ++ c->ctx = SSL_CTX_new(TLSv1_client_method()); ++ if (!c->ctx) { ++ av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL)); ++ ret = AVERROR(EIO); ++ goto fail; ++ } ++ c->ssl = SSL_new(c->ctx); ++ if (!c->ssl) { ++ av_log(h, AV_LOG_ERROR, "%s\n", ERR_error_string(ERR_get_error(), NULL)); ++ ret = AVERROR(EIO); ++ goto fail; ++ } ++ SSL_set_fd(c->ssl, c->fd); ++ if (!numerichost) ++ SSL_set_tlsext_host_name(c->ssl, host); ++ while (1) { ++ ret = SSL_connect(c->ssl); ++ if (ret > 0) ++ break; ++ if (ret == 0) { ++ av_log(h, AV_LOG_ERROR, "Unable to negotiate TLS/SSL session\n"); ++ ret = AVERROR(EIO); ++ goto fail; ++ } ++ if ((ret = do_tls_poll(h, ret)) < 0) ++ goto fail; ++ } ++#endif ++ return 0; ++fail: ++ TLS_free(c); ++ if (c->tcp) ++ ffurl_close(c->tcp); ++ ff_tls_deinit(); ++ return ret; ++} ++ ++static int tls_read(URLContext *h, uint8_t *buf, int size) ++{ ++ TLSContext *c = h->priv_data; ++ while (1) { ++ int ret = TLS_read(c, buf, size); ++ if (ret > 0) ++ return ret; ++ if (ret == 0) ++ return AVERROR(EIO); ++ if ((ret = do_tls_poll(h, ret)) < 0) ++ return ret; ++ } ++ return 0; ++} ++ ++static int tls_write(URLContext *h, const uint8_t *buf, int size) ++{ ++ TLSContext *c = h->priv_data; ++ while (1) { ++ int ret = TLS_write(c, buf, size); ++ if (ret > 0) ++ return ret; ++ if (ret == 0) ++ return AVERROR(EIO); ++ if ((ret = do_tls_poll(h, ret)) < 0) ++ return ret; ++ } ++ return 0; ++} ++ ++static int tls_close(URLContext *h) ++{ ++ TLSContext *c = h->priv_data; ++ TLS_shutdown(c); ++ TLS_free(c); ++ ffurl_close(c->tcp); ++ ff_tls_deinit(); ++ return 0; ++} ++ ++URLProtocol ff_tls_protocol = { ++ .name = "tls", ++ .url_open = tls_open, ++ .url_read = tls_read, ++ .url_write = tls_write, ++ .url_close = tls_close, ++ .priv_data_size = sizeof(TLSContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tmv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tmv.c 2012-05-14 14:08:55.229357994 +0200 +@@ -20,14 +20,15 @@ + */ + + /** +- * 8088flex TMV file demuxer + * @file ++ * 8088flex TMV file demuxer + * @author Daniel Verkamp +- * @sa http://www.oldskool.org/pc/8088_Corruption ++ * @see http://www.oldskool.org/pc/8088_Corruption + */ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + enum { + TMV_PADDING = 0x01, +@@ -65,44 +66,44 @@ + static int tmv_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + TMVContext *tmv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *vst, *ast; + AVRational fps; + unsigned comp_method, char_cols, char_rows, features; + +- if (get_le32(pb) != TMV_TAG) ++ if (avio_rl32(pb) != TMV_TAG) + return -1; + +- if (!(vst = av_new_stream(s, 0))) ++ if (!(vst = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + +- if (!(ast = av_new_stream(s, 0))) ++ if (!(ast = avformat_new_stream(s, NULL))) + return AVERROR(ENOMEM); + +- ast->codec->sample_rate = get_le16(pb); ++ ast->codec->sample_rate = avio_rl16(pb); + if (!ast->codec->sample_rate) { + av_log(s, AV_LOG_ERROR, "invalid sample rate\n"); + return -1; + } + +- tmv->audio_chunk_size = get_le16(pb); ++ tmv->audio_chunk_size = avio_rl16(pb); + if (!tmv->audio_chunk_size) { + av_log(s, AV_LOG_ERROR, "invalid audio chunk size\n"); + return -1; + } + +- comp_method = get_byte(pb); ++ comp_method = avio_r8(pb); + if (comp_method) { + av_log(s, AV_LOG_ERROR, "unsupported compression method %d\n", + comp_method); + return -1; + } + +- char_cols = get_byte(pb); +- char_rows = get_byte(pb); ++ char_cols = avio_r8(pb); ++ char_rows = avio_r8(pb); + tmv->video_chunk_size = char_cols * char_rows * 2; + +- features = get_byte(pb); ++ features = avio_r8(pb); + if (features & ~(TMV_PADDING | TMV_STEREO)) { + av_log(s, AV_LOG_ERROR, "unsupported features 0x%02x\n", + features & ~(TMV_PADDING | TMV_STEREO)); +@@ -115,7 +116,7 @@ + ast->codec->bits_per_coded_sample = 8; + ast->codec->bit_rate = ast->codec->sample_rate * + ast->codec->bits_per_coded_sample; +- av_set_pts_info(ast, 32, 1, ast->codec->sample_rate); ++ avpriv_set_pts_info(ast, 32, 1, ast->codec->sample_rate); + + fps.num = ast->codec->sample_rate * ast->codec->channels; + fps.den = tmv->audio_chunk_size; +@@ -126,7 +127,7 @@ + vst->codec->pix_fmt = PIX_FMT_PAL8; + vst->codec->width = char_cols * 8; + vst->codec->height = char_rows * 8; +- av_set_pts_info(vst, 32, fps.den, fps.num); ++ avpriv_set_pts_info(vst, 32, fps.den, fps.num); + + if (features & TMV_PADDING) + tmv->padding = +@@ -142,7 +143,7 @@ + static int tmv_read_packet(AVFormatContext *s, AVPacket *pkt) + { + TMVContext *tmv = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int ret, pkt_size = tmv->stream_index ? + tmv->audio_chunk_size : tmv->video_chunk_size; + +@@ -152,7 +153,7 @@ + ret = av_get_packet(pb, pkt, pkt_size); + + if (tmv->stream_index) +- url_fskip(pb, tmv->padding); ++ avio_skip(pb, tmv->padding); + + pkt->stream_index = tmv->stream_index; + tmv->stream_index ^= 1; +@@ -173,19 +174,19 @@ + pos = timestamp * + (tmv->audio_chunk_size + tmv->video_chunk_size + tmv->padding); + +- url_fseek(s->pb, pos + TMV_HEADER_SIZE, SEEK_SET); ++ if (avio_seek(s->pb, pos + TMV_HEADER_SIZE, SEEK_SET) < 0) ++ return -1; + tmv->stream_index = 0; + return 0; + } + + AVInputFormat ff_tmv_demuxer = { +- "tmv", +- NULL_IF_CONFIG_SMALL("8088flex TMV"), +- sizeof(TMVContext), +- tmv_probe, +- tmv_read_header, +- tmv_read_packet, +- NULL, +- tmv_read_seek, ++ .name = "tmv", ++ .long_name = NULL_IF_CONFIG_SMALL("8088flex TMV"), ++ .priv_data_size = sizeof(TMVContext), ++ .read_probe = tmv_probe, ++ .read_header = tmv_read_header, ++ .read_packet = tmv_read_packet, ++ .read_seek = tmv_read_seek, + .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tta.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tta.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tta.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tta.c 2012-05-14 14:08:55.230358014 +0200 +@@ -21,7 +21,9 @@ + + #include "libavcodec/get_bits.h" + #include "avformat.h" ++#include "internal.h" + #include "id3v1.h" ++#include "libavutil/dict.h" + + typedef struct { + int totalframes, currentframe; +@@ -43,55 +45,55 @@ + int i, channels, bps, samplerate, datalen, framelen; + uint64_t framepos, start_offset; + +- if (!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ++ if (!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + ff_id3v1_read(s); + +- start_offset = url_ftell(s->pb); +- if (get_le32(s->pb) != AV_RL32("TTA1")) ++ start_offset = avio_tell(s->pb); ++ if (avio_rl32(s->pb) != AV_RL32("TTA1")) + return -1; // not tta file + +- url_fskip(s->pb, 2); // FIXME: flags +- channels = get_le16(s->pb); +- bps = get_le16(s->pb); +- samplerate = get_le32(s->pb); ++ avio_skip(s->pb, 2); // FIXME: flags ++ channels = avio_rl16(s->pb); ++ bps = avio_rl16(s->pb); ++ samplerate = avio_rl32(s->pb); + if(samplerate <= 0 || samplerate > 1000000){ + av_log(s, AV_LOG_ERROR, "nonsense samplerate\n"); + return -1; + } + +- datalen = get_le32(s->pb); ++ datalen = avio_rl32(s->pb); + if(datalen < 0){ + av_log(s, AV_LOG_ERROR, "nonsense datalen\n"); + return -1; + } + +- url_fskip(s->pb, 4); // header crc ++ avio_skip(s->pb, 4); // header crc + + framelen = samplerate*256/245; + c->totalframes = datalen / framelen + ((datalen % framelen) ? 1 : 0); + c->currentframe = 0; + +- if(c->totalframes >= UINT_MAX/sizeof(uint32_t)){ +- av_log(s, AV_LOG_ERROR, "totalframes too large\n"); ++ if(c->totalframes >= UINT_MAX/sizeof(uint32_t) || c->totalframes <= 0){ ++ av_log(s, AV_LOG_ERROR, "totalframes %d invalid\n", c->totalframes); + return -1; + } + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + +- av_set_pts_info(st, 64, 1, samplerate); ++ avpriv_set_pts_info(st, 64, 1, samplerate); + st->start_time = 0; + st->duration = datalen; + +- framepos = url_ftell(s->pb) + 4*c->totalframes + 4; ++ framepos = avio_tell(s->pb) + 4*c->totalframes + 4; + + for (i = 0; i < c->totalframes; i++) { +- uint32_t size = get_le32(s->pb); ++ uint32_t size = avio_rl32(s->pb); + av_add_index_entry(st, framepos, i*framelen, size, 0, AVINDEX_KEYFRAME); + framepos += size; + } +- url_fskip(s->pb, 4); // seektable crc ++ avio_skip(s->pb, 4); // seektable crc + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_TTA; +@@ -99,15 +101,19 @@ + st->codec->sample_rate = samplerate; + st->codec->bits_per_coded_sample = bps; + +- st->codec->extradata_size = url_ftell(s->pb) - start_offset; ++ st->codec->extradata_size = avio_tell(s->pb) - start_offset; + if(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE <= (unsigned)st->codec->extradata_size){ +- //this check is redundant as get_buffer should fail ++ //this check is redundant as avio_read should fail + av_log(s, AV_LOG_ERROR, "extradata_size too large\n"); + return -1; + } + st->codec->extradata = av_mallocz(st->codec->extradata_size+FF_INPUT_BUFFER_PADDING_SIZE); +- url_fseek(s->pb, start_offset, SEEK_SET); +- get_buffer(s->pb, st->codec->extradata, st->codec->extradata_size); ++ if (!st->codec->extradata) { ++ st->codec->extradata_size = 0; ++ return AVERROR(ENOMEM); ++ } ++ avio_seek(s->pb, start_offset, SEEK_SET); ++ avio_read(s->pb, st->codec->extradata, st->codec->extradata_size); + + return 0; + } +@@ -119,8 +125,8 @@ + int size, ret; + + // FIXME! +- if (c->currentframe > c->totalframes) +- return -1; ++ if (c->currentframe >= c->totalframes) ++ return AVERROR_EOF; + + size = st->index_entries[c->currentframe].size; + +@@ -136,21 +142,21 @@ + int index = av_index_search_timestamp(st, timestamp, flags); + if (index < 0) + return -1; ++ if (avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET) < 0) ++ return -1; + + c->currentframe = index; +- url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); + + return 0; + } + + AVInputFormat ff_tta_demuxer = { +- "tta", +- NULL_IF_CONFIG_SMALL("True Audio"), +- sizeof(TTAContext), +- tta_probe, +- tta_read_header, +- tta_read_packet, +- NULL, +- tta_read_seek, ++ .name = "tta", ++ .long_name = NULL_IF_CONFIG_SMALL("True Audio"), ++ .priv_data_size = sizeof(TTAContext), ++ .read_probe = tta_probe, ++ .read_header = tta_read_header, ++ .read_packet = tta_read_packet, ++ .read_seek = tta_read_seek, + .extensions = "tta", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tty.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tty.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/tty.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/tty.c 2012-05-14 14:08:55.231358035 +0200 +@@ -26,14 +26,20 @@ + + #include "libavutil/intreadwrite.h" + #include "libavutil/avstring.h" ++#include "libavutil/log.h" ++#include "libavutil/dict.h" ++#include "libavutil/opt.h" ++#include "libavutil/parseutils.h" + #include "avformat.h" ++#include "internal.h" + #include "sauce.h" + +-#define LINE_RATE 6000 /* characters per second */ +- + typedef struct { ++ AVClass *class; + int chars_per_frame; + uint64_t fsize; /**< file size less metadata buffer */ ++ char *video_size;/**< A string describing video size, set by a private option. */ ++ char *framerate; /**< Set by a private option. */ + } TtyDemuxContext; + + /** +@@ -42,21 +48,21 @@ + static int efi_read(AVFormatContext *avctx, uint64_t start_pos) + { + TtyDemuxContext *s = avctx->priv_data; +- ByteIOContext *pb = avctx->pb; ++ AVIOContext *pb = avctx->pb; + char buf[37]; + int len; + +- url_fseek(pb, start_pos, SEEK_SET); +- if (get_byte(pb) != 0x1A) ++ avio_seek(pb, start_pos, SEEK_SET); ++ if (avio_r8(pb) != 0x1A) + return -1; + + #define GET_EFI_META(name,size) \ +- len = get_byte(pb); \ ++ len = avio_r8(pb); \ + if (len < 1 || len > size) \ + return -1; \ +- if (get_buffer(pb, buf, size) == size) { \ ++ if (avio_read(pb, buf, size) == size) { \ + buf[len] = 0; \ +- av_metadata_set2(&avctx->metadata, name, buf, 0); \ ++ av_dict_set(&avctx->metadata, name, buf, 0); \ + } + + GET_EFI_META("filename", 12) +@@ -70,35 +76,45 @@ + AVFormatParameters *ap) + { + TtyDemuxContext *s = avctx->priv_data; +- AVStream *st = av_new_stream(avctx, 0); +- if (!st) +- return AVERROR(ENOMEM); ++ int width = 0, height = 0, ret = 0; ++ AVStream *st = avformat_new_stream(avctx, NULL); ++ AVRational framerate; ++ ++ if (!st) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } + st->codec->codec_tag = 0; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_ANSI; +- if (ap->width) st->codec->width = ap->width; +- if (ap->height) st->codec->height = ap->height; + +- if (!ap->time_base.num) { +- av_set_pts_info(st, 60, 1, 25); +- } else { +- av_set_pts_info(st, 60, ap->time_base.num, ap->time_base.den); ++ if (s->video_size && (ret = av_parse_video_size(&width, &height, s->video_size)) < 0) { ++ av_log (avctx, AV_LOG_ERROR, "Couldn't parse video size.\n"); ++ goto fail; + } ++ if ((ret = av_parse_video_rate(&framerate, s->framerate)) < 0) { ++ av_log(avctx, AV_LOG_ERROR, "Could not parse framerate: %s.\n", s->framerate); ++ goto fail; ++ } ++ st->codec->width = width; ++ st->codec->height = height; ++ avpriv_set_pts_info(st, 60, framerate.den, framerate.num); + + /* simulate tty display speed */ +- s->chars_per_frame = FFMAX(av_q2d(st->time_base) * (ap->sample_rate ? ap->sample_rate : LINE_RATE), 1); ++ s->chars_per_frame = FFMAX(av_q2d(st->time_base)*s->chars_per_frame, 1); + +- if (!url_is_streamed(avctx->pb)) { +- s->fsize = url_fsize(avctx->pb); ++ if (avctx->pb->seekable) { ++ s->fsize = avio_size(avctx->pb); + st->duration = (s->fsize + s->chars_per_frame - 1) / s->chars_per_frame; + + if (ff_sauce_read(avctx, &s->fsize, 0, 0) < 0) + efi_read(avctx, s->fsize - 51); + +- url_fseek(avctx->pb, 0, SEEK_SET); ++ avio_seek(avctx->pb, 0, SEEK_SET); + } + +- return 0; ++fail: ++ return ret; + } + + static int read_packet(AVFormatContext *avctx, AVPacket *pkt) +@@ -112,7 +128,7 @@ + n = s->chars_per_frame; + if (s->fsize) { + // ignore metadata buffer +- uint64_t p = url_ftell(avctx->pb); ++ uint64_t p = avio_tell(avctx->pb); + if (p + s->chars_per_frame > s->fsize) + n = s->fsize - p; + } +@@ -120,10 +136,26 @@ + pkt->size = av_get_packet(avctx->pb, pkt, n); + if (pkt->size <= 0) + return AVERROR(EIO); +- pkt->flags |= PKT_FLAG_KEY; ++ pkt->flags |= AV_PKT_FLAG_KEY; + return 0; + } + ++#define OFFSET(x) offsetof(TtyDemuxContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption options[] = { ++ { "chars_per_frame", "", offsetof(TtyDemuxContext, chars_per_frame), AV_OPT_TYPE_INT, {.dbl = 6000}, 1, INT_MAX, AV_OPT_FLAG_DECODING_PARAM}, ++ { "video_size", "A string describing frame size, such as 640x480 or hd720.", OFFSET(video_size), AV_OPT_TYPE_STRING, {.str = NULL}, 0, 0, DEC }, ++ { "framerate", "", OFFSET(framerate), AV_OPT_TYPE_STRING, {.str = "25"}, 0, 0, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass tty_demuxer_class = { ++ .class_name = "TTY demuxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVInputFormat ff_tty_demuxer = { + .name = "tty", + .long_name = NULL_IF_CONFIG_SMALL("Tele-typewriter"), +@@ -131,4 +163,5 @@ + .read_header = read_header, + .read_packet = read_packet, + .extensions = "ans,art,asc,diz,ice,nfo,txt,vt", ++ .priv_class = &tty_demuxer_class, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/txd.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/txd.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/txd.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/txd.c 2012-05-14 14:08:55.232358056 +0200 +@@ -40,7 +40,7 @@ + static int txd_read_header(AVFormatContext *s, AVFormatParameters *ap) { + AVStream *st; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +@@ -48,18 +48,19 @@ + st->codec->time_base.den = 5; + st->codec->time_base.num = 1; + /* the parameters will be extracted from the compressed bitstream */ ++ + return 0; + } + + static int txd_read_packet(AVFormatContext *s, AVPacket *pkt) { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int id, chunk_size, marker; + int ret; + + next_chunk: +- id = get_le32(pb); +- chunk_size = get_le32(pb); +- marker = get_le32(pb); ++ id = avio_rl32(pb); ++ chunk_size = avio_rl32(pb); ++ marker = avio_rl32(pb); + + if (url_feof(s->pb)) + return AVERROR_EOF; +@@ -73,7 +74,7 @@ + if (chunk_size > 100) + break; + case TXD_EXTRA: +- url_fskip(s->pb, chunk_size); ++ avio_skip(s->pb, chunk_size); + case TXD_FILE: + case TXD_TEXTURE: + goto next_chunk; +@@ -90,12 +91,10 @@ + return 0; + } + +-AVInputFormat ff_txd_demuxer = +-{ +- "txd", +- NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"), +- 0, +- txd_probe, +- txd_read_header, +- txd_read_packet, ++AVInputFormat ff_txd_demuxer = { ++ .name = "txd", ++ .long_name = NULL_IF_CONFIG_SMALL("Renderware TeXture Dictionary"), ++ .read_probe = txd_probe, ++ .read_header = txd_read_header, ++ .read_packet = txd_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/udp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/udp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/udp.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/udp.c 2012-05-14 14:08:55.234358096 +0200 +@@ -25,15 +25,23 @@ + */ + + #define _BSD_SOURCE /* Needed for using struct ip_mreq with recent glibc */ +-#define _DARWIN_C_SOURCE /* Needed for using IP_MULTICAST_TTL on OS X */ ++ + #include "avformat.h" ++#include "avio_internal.h" ++#include "libavutil/parseutils.h" ++#include "libavutil/fifo.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/avstring.h" + #include + #include "internal.h" + #include "network.h" + #include "os_support.h" +-#if HAVE_POLL_H +-#include ++#include "url.h" ++ ++#if HAVE_PTHREADS ++#include + #endif ++ + #include + + #ifndef IPV6_ADD_MEMBERSHIP +@@ -41,6 +49,9 @@ + #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP + #endif + ++#define UDP_TX_BUF_SIZE 32768 ++#define UDP_MAX_PKT_SIZE 65536 ++ + typedef struct { + int udp_fd; + int ttl; +@@ -51,10 +62,21 @@ + struct sockaddr_storage dest_addr; + int dest_addr_len; + int is_connected; +-} UDPContext; + +-#define UDP_TX_BUF_SIZE 32768 +-#define UDP_MAX_PKT_SIZE 65536 ++ /* Circular Buffer variables for use in UDP receive code */ ++ int circular_buffer_size; ++ AVFifoBuffer *fifo; ++ int circular_buffer_error; ++#if HAVE_PTHREADS ++ pthread_t circular_buffer_thread; ++ pthread_mutex_t mutex; ++ pthread_cond_t cond; ++ int thread_started; ++ volatile int exit_thread; ++#endif ++ uint8_t tmp[UDP_MAX_PKT_SIZE+4]; ++ int remaining_in_dg; ++} UDPContext; + + static int udp_set_multicast_ttl(int sockfd, int mcastTTL, + struct sockaddr *addr) +@@ -178,8 +200,8 @@ + return addr_len; + } + +-static int udp_socket_create(UDPContext *s, +- struct sockaddr_storage *addr, int *addr_len) ++static int udp_socket_create(UDPContext *s, struct sockaddr_storage *addr, ++ int *addr_len, const char *localaddr) + { + int udp_fd = -1; + struct addrinfo *res0 = NULL, *res = NULL; +@@ -187,7 +209,8 @@ + + if (((struct sockaddr *) &s->dest_addr)->sa_family) + family = ((struct sockaddr *) &s->dest_addr)->sa_family; +- res0 = udp_resolve_host(0, s->local_port, SOCK_DGRAM, family, AI_PASSIVE); ++ res0 = udp_resolve_host(localaddr[0] ? localaddr : NULL, s->local_port, ++ SOCK_DGRAM, family, AI_PASSIVE); + if (res0 == 0) + goto fail; + for (res = res0; res; res=res->ai_next) { +@@ -242,7 +265,7 @@ + * @param uri of the remote server + * @return zero if no error. + */ +-int udp_set_remote_url(URLContext *h, const char *uri) ++int ff_udp_set_remote_url(URLContext *h, const char *uri) + { + UDPContext *s = h->priv_data; + char hostname[256], buf[10]; +@@ -259,14 +282,14 @@ + s->is_multicast = ff_is_multicast_address((struct sockaddr*) &s->dest_addr); + p = strchr(uri, '?'); + if (p) { +- if (find_info_tag(buf, sizeof(buf), "connect", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { + int was_connected = s->is_connected; + s->is_connected = strtol(buf, NULL, 10); + if (s->is_connected && !was_connected) { + if (connect(s->udp_fd, (struct sockaddr *) &s->dest_addr, + s->dest_addr_len)) { + s->is_connected = 0; +- av_log(NULL, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); ++ av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); + return AVERROR(EIO); + } + } +@@ -281,7 +304,7 @@ + * @param h media file context + * @return the local port number + */ +-int udp_get_local_port(URLContext *h) ++int ff_udp_get_local_port(URLContext *h) + { + UDPContext *s = h->priv_data; + return s->local_port; +@@ -292,59 +315,134 @@ + * streams at the same time. + * @param h media file context + */ +-#if !FF_API_UDP_GET_FILE +-static +-#endif +-int udp_get_file_handle(URLContext *h) ++static int udp_get_file_handle(URLContext *h) + { + UDPContext *s = h->priv_data; + return s->udp_fd; + } + ++#if HAVE_PTHREADS ++static void *circular_buffer_task( void *_URLContext) ++{ ++ URLContext *h = _URLContext; ++ UDPContext *s = h->priv_data; ++ fd_set rfds; ++ struct timeval tv; ++ ++ while(!s->exit_thread) { ++ int left; ++ int ret; ++ int len; ++ ++ if (ff_check_interrupt(&h->interrupt_callback)) { ++ s->circular_buffer_error = EINTR; ++ goto end; ++ } ++ ++ FD_ZERO(&rfds); ++ FD_SET(s->udp_fd, &rfds); ++ tv.tv_sec = 1; ++ tv.tv_usec = 0; ++ ret = select(s->udp_fd + 1, &rfds, NULL, NULL, &tv); ++ if (ret < 0) { ++ if (ff_neterrno() == AVERROR(EINTR)) ++ continue; ++ s->circular_buffer_error = EIO; ++ goto end; ++ } ++ ++ if (!(ret > 0 && FD_ISSET(s->udp_fd, &rfds))) ++ continue; ++ ++ /* How much do we have left to the end of the buffer */ ++ /* Whats the minimum we can read so that we dont comletely fill the buffer */ ++ left = av_fifo_space(s->fifo); ++ ++ /* No Space left, error, what do we do now */ ++ if(left < UDP_MAX_PKT_SIZE + 4) { ++ av_log(h, AV_LOG_ERROR, "circular_buffer: OVERRUN\n"); ++ s->circular_buffer_error = EIO; ++ goto end; ++ } ++ left = FFMIN(left, s->fifo->end - s->fifo->wptr); ++ len = recv(s->udp_fd, s->tmp+4, sizeof(s->tmp)-4, 0); ++ if (len < 0) { ++ if (ff_neterrno() != AVERROR(EAGAIN) && ff_neterrno() != AVERROR(EINTR)) { ++ s->circular_buffer_error = EIO; ++ goto end; ++ } ++ continue; ++ } ++ AV_WL32(s->tmp, len); ++ pthread_mutex_lock(&s->mutex); ++ av_fifo_generic_write(s->fifo, s->tmp, len+4, NULL); ++ pthread_cond_signal(&s->cond); ++ pthread_mutex_unlock(&s->mutex); ++ } ++ ++end: ++ pthread_mutex_lock(&s->mutex); ++ pthread_cond_signal(&s->cond); ++ pthread_mutex_unlock(&s->mutex); ++ return NULL; ++} ++#endif ++ + /* put it in UDP context */ + /* return non zero if error */ + static int udp_open(URLContext *h, const char *uri, int flags) + { +- char hostname[1024]; ++ char hostname[1024], localaddr[1024] = ""; + int port, udp_fd = -1, tmp, bind_ret = -1; +- UDPContext *s = NULL; ++ UDPContext *s = h->priv_data; + int is_output; + const char *p; + char buf[256]; + struct sockaddr_storage my_addr; + int len; ++ int reuse_specified = 0; + + h->is_streamed = 1; + h->max_packet_size = 1472; + +- is_output = (flags & URL_WRONLY); ++ is_output = !(flags & AVIO_FLAG_READ); + +- s = av_mallocz(sizeof(UDPContext)); +- if (!s) +- return AVERROR(ENOMEM); +- +- h->priv_data = s; + s->ttl = 16; + s->buffer_size = is_output ? UDP_TX_BUF_SIZE : UDP_MAX_PKT_SIZE; + ++ s->circular_buffer_size = 7*188*4096; ++ + p = strchr(uri, '?'); + if (p) { +- s->reuse_socket = find_info_tag(buf, sizeof(buf), "reuse", p); +- if (find_info_tag(buf, sizeof(buf), "ttl", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "reuse", p)) { ++ char *endptr = NULL; ++ s->reuse_socket = strtol(buf, &endptr, 10); ++ /* assume if no digits were found it is a request to enable it */ ++ if (buf == endptr) ++ s->reuse_socket = 1; ++ reuse_specified = 1; ++ } ++ if (av_find_info_tag(buf, sizeof(buf), "ttl", p)) { + s->ttl = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "localport", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "localport", p)) { + s->local_port = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "pkt_size", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "pkt_size", p)) { + h->max_packet_size = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "buffer_size", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "buffer_size", p)) { + s->buffer_size = strtol(buf, NULL, 10); + } +- if (find_info_tag(buf, sizeof(buf), "connect", p)) { ++ if (av_find_info_tag(buf, sizeof(buf), "connect", p)) { + s->is_connected = strtol(buf, NULL, 10); + } ++ if (av_find_info_tag(buf, sizeof(buf), "fifo_size", p)) { ++ s->circular_buffer_size = strtol(buf, NULL, 10)*188; ++ } ++ if (av_find_info_tag(buf, sizeof(buf), "localaddr", p)) { ++ av_strlcpy(localaddr, buf, sizeof(localaddr)); ++ } + } + + /* fill the dest addr */ +@@ -353,26 +451,31 @@ + /* XXX: fix av_url_split */ + if (hostname[0] == '\0' || hostname[0] == '?') { + /* only accepts null hostname if input */ +- if (flags & URL_WRONLY) ++ if (!(flags & AVIO_FLAG_READ)) + goto fail; + } else { +- if (udp_set_remote_url(h, uri) < 0) ++ if (ff_udp_set_remote_url(h, uri) < 0) + goto fail; + } + +- if (s->is_multicast && !(h->flags & URL_WRONLY)) ++ if ((s->is_multicast || !s->local_port) && (h->flags & AVIO_FLAG_READ)) + s->local_port = port; +- udp_fd = udp_socket_create(s, &my_addr, &len); ++ udp_fd = udp_socket_create(s, &my_addr, &len, localaddr); + if (udp_fd < 0) + goto fail; + +- if (s->reuse_socket) ++ /* Follow the requested reuse option, unless it's multicast in which ++ * case enable reuse unless explicitly disabled. ++ */ ++ if (s->reuse_socket || (s->is_multicast && !reuse_specified)) { ++ s->reuse_socket = 1; + if (setsockopt (udp_fd, SOL_SOCKET, SO_REUSEADDR, &(s->reuse_socket), sizeof(s->reuse_socket)) != 0) + goto fail; ++ } + + /* the bind is needed to give a port to the socket now */ + /* if multicast, try the multicast address bind first */ +- if (s->is_multicast && !(h->flags & URL_WRONLY)) { ++ if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) { + bind_ret = bind(udp_fd,(struct sockaddr *)&s->dest_addr, len); + } + /* bind to the local address if not multicast or if the multicast +@@ -385,7 +488,7 @@ + s->local_port = udp_port(&my_addr, len); + + if (s->is_multicast) { +- if (h->flags & URL_WRONLY) { ++ if (!(h->flags & AVIO_FLAG_READ)) { + /* output */ + if (udp_set_multicast_ttl(udp_fd, s->ttl, (struct sockaddr *)&s->dest_addr) < 0) + goto fail; +@@ -400,7 +503,7 @@ + /* limit the tx buf size to limit latency */ + tmp = s->buffer_size; + if (setsockopt(udp_fd, SOL_SOCKET, SO_SNDBUF, &tmp, sizeof(tmp)) < 0) { +- av_log(NULL, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno)); ++ av_log(h, AV_LOG_ERROR, "setsockopt(SO_SNDBUF): %s\n", strerror(errno)); + goto fail; + } + } else { +@@ -408,55 +511,106 @@ + * avoid losing data on OSes that set this too low by default. */ + tmp = s->buffer_size; + if (setsockopt(udp_fd, SOL_SOCKET, SO_RCVBUF, &tmp, sizeof(tmp)) < 0) { +- av_log(NULL, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno)); ++ av_log(h, AV_LOG_WARNING, "setsockopt(SO_RECVBUF): %s\n", strerror(errno)); + } + /* make the socket non-blocking */ + ff_socket_nonblock(udp_fd, 1); + } + if (s->is_connected) { + if (connect(udp_fd, (struct sockaddr *) &s->dest_addr, s->dest_addr_len)) { +- av_log(NULL, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); ++ av_log(h, AV_LOG_ERROR, "connect: %s\n", strerror(errno)); + goto fail; + } + } + + s->udp_fd = udp_fd; ++ ++#if HAVE_PTHREADS ++ if (!is_output && s->circular_buffer_size) { ++ int ret; ++ ++ /* start the task going */ ++ s->fifo = av_fifo_alloc(s->circular_buffer_size); ++ ret = pthread_mutex_init(&s->mutex, NULL); ++ if (ret != 0) { ++ av_log(h, AV_LOG_ERROR, "pthread_mutex_init failed : %s\n", strerror(ret)); ++ goto fail; ++ } ++ ret = pthread_cond_init(&s->cond, NULL); ++ if (ret != 0) { ++ av_log(h, AV_LOG_ERROR, "pthread_cond_init failed : %s\n", strerror(ret)); ++ goto cond_fail; ++ } ++ ret = pthread_create(&s->circular_buffer_thread, NULL, circular_buffer_task, h); ++ if (ret != 0) { ++ av_log(h, AV_LOG_ERROR, "pthread_create failed : %s\n", strerror(ret)); ++ goto thread_fail; ++ } ++ s->thread_started = 1; ++ } ++#endif ++ + return 0; ++#if HAVE_PTHREADS ++ thread_fail: ++ pthread_cond_destroy(&s->cond); ++ cond_fail: ++ pthread_mutex_destroy(&s->mutex); ++#endif + fail: + if (udp_fd >= 0) + closesocket(udp_fd); +- av_free(s); ++ av_fifo_free(s->fifo); + return AVERROR(EIO); + } + + static int udp_read(URLContext *h, uint8_t *buf, int size) + { + UDPContext *s = h->priv_data; +- struct pollfd p = {s->udp_fd, POLLIN, 0}; +- int len; + int ret; ++ int avail; + +- for(;;) { +- if (url_interrupt_cb()) +- return AVERROR(EINTR); +- ret = poll(&p, 1, 100); +- if (ret < 0) { +- if (ff_neterrno() == FF_NETERROR(EINTR)) +- continue; +- return AVERROR(EIO); +- } +- if (!(ret == 1 && p.revents & POLLIN)) +- continue; +- len = recv(s->udp_fd, buf, size, 0); +- if (len < 0) { +- if (ff_neterrno() != FF_NETERROR(EAGAIN) && +- ff_neterrno() != FF_NETERROR(EINTR)) +- return AVERROR(EIO); +- } else { +- break; +- } ++#if HAVE_PTHREADS ++ if (s->fifo) { ++ pthread_mutex_lock(&s->mutex); ++ do { ++ avail = av_fifo_size(s->fifo); ++ if (avail) { // >=size) { ++ uint8_t tmp[4]; ++ pthread_mutex_unlock(&s->mutex); ++ ++ av_fifo_generic_read(s->fifo, tmp, 4, NULL); ++ avail= AV_RL32(tmp); ++ if(avail > size){ ++ av_log(h, AV_LOG_WARNING, "Part of datagram lost due to insufficient buffer size\n"); ++ avail= size; ++ } ++ ++ av_fifo_generic_read(s->fifo, buf, avail, NULL); ++ av_fifo_drain(s->fifo, AV_RL32(tmp) - avail); ++ return avail; ++ } else if(s->circular_buffer_error){ ++ pthread_mutex_unlock(&s->mutex); ++ return s->circular_buffer_error; ++ } else if(h->flags & AVIO_FLAG_NONBLOCK) { ++ pthread_mutex_unlock(&s->mutex); ++ return AVERROR(EAGAIN); ++ } ++ else { ++ pthread_cond_wait(&s->cond, &s->mutex); ++ } ++ } while( 1); + } +- return len; ++#endif ++ ++ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ++ ret = ff_network_wait_fd(s->udp_fd, 0); ++ if (ret < 0) ++ return ret; ++ } ++ ret = recv(s->udp_fd, buf, size, 0); ++ ++ return ret < 0 ? ff_neterrno() : ret; + } + + static int udp_write(URLContext *h, const uint8_t *buf, int size) +@@ -464,41 +618,52 @@ + UDPContext *s = h->priv_data; + int ret; + +- for(;;) { +- if (!s->is_connected) { +- ret = sendto (s->udp_fd, buf, size, 0, +- (struct sockaddr *) &s->dest_addr, +- s->dest_addr_len); +- } else +- ret = send(s->udp_fd, buf, size, 0); +- if (ret < 0) { +- if (ff_neterrno() != FF_NETERROR(EINTR) && +- ff_neterrno() != FF_NETERROR(EAGAIN)) +- return ff_neterrno(); +- } else { +- break; +- } ++ if (!(h->flags & AVIO_FLAG_NONBLOCK)) { ++ ret = ff_network_wait_fd(s->udp_fd, 1); ++ if (ret < 0) ++ return ret; + } +- return size; ++ ++ if (!s->is_connected) { ++ ret = sendto (s->udp_fd, buf, size, 0, ++ (struct sockaddr *) &s->dest_addr, ++ s->dest_addr_len); ++ } else ++ ret = send(s->udp_fd, buf, size, 0); ++ ++ return ret < 0 ? ff_neterrno() : ret; + } + + static int udp_close(URLContext *h) + { + UDPContext *s = h->priv_data; ++ int ret; + +- if (s->is_multicast && !(h->flags & URL_WRONLY)) ++ if (s->is_multicast && (h->flags & AVIO_FLAG_READ)) + udp_leave_multicast_group(s->udp_fd, (struct sockaddr *)&s->dest_addr); + closesocket(s->udp_fd); +- av_free(s); ++ av_fifo_free(s->fifo); ++#if HAVE_PTHREADS ++ if (s->thread_started) { ++ s->exit_thread = 1; ++ ret = pthread_join(s->circular_buffer_thread, NULL); ++ if (ret != 0) ++ av_log(h, AV_LOG_ERROR, "pthread_join(): %s\n", strerror(ret)); ++ } ++ ++ pthread_mutex_destroy(&s->mutex); ++ pthread_cond_destroy(&s->cond); ++#endif + return 0; + } + + URLProtocol ff_udp_protocol = { +- "udp", +- udp_open, +- udp_read, +- udp_write, +- NULL, /* seek */ +- udp_close, ++ .name = "udp", ++ .url_open = udp_open, ++ .url_read = udp_read, ++ .url_write = udp_write, ++ .url_close = udp_close, + .url_get_file_handle = udp_get_file_handle, ++ .priv_data_size = sizeof(UDPContext), ++ .flags = URL_PROTOCOL_FLAG_NETWORK, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/url.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/url.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/url.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/url.h 2012-05-14 14:08:55.235358116 +0200 +@@ -0,0 +1,216 @@ ++/* ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * unbuffered private I/O API ++ */ ++ ++#ifndef AVFORMAT_URL_H ++#define AVFORMAT_URL_H ++ ++#include "avio.h" ++#include "libavformat/version.h" ++ ++#include "libavutil/dict.h" ++#include "libavutil/log.h" ++ ++#if !FF_API_OLD_AVIO ++#define URL_PROTOCOL_FLAG_NESTED_SCHEME 1 /*< The protocol name can be the first part of a nested protocol scheme */ ++#define URL_PROTOCOL_FLAG_NETWORK 2 /*< The protocol uses network */ ++ ++extern int (*url_interrupt_cb)(void); ++ ++extern const AVClass ffurl_context_class; ++ ++typedef struct URLContext { ++ const AVClass *av_class; /**< information for av_log(). Set by url_open(). */ ++ struct URLProtocol *prot; ++ void *priv_data; ++ char *filename; /**< specified URL */ ++ int flags; ++ int max_packet_size; /**< if non zero, the stream is packetized with this max packet size */ ++ int is_streamed; /**< true if streamed (no seek possible), default = false */ ++ int is_connected; ++ AVIOInterruptCB interrupt_callback; ++} URLContext; ++ ++typedef struct URLProtocol { ++ const char *name; ++ int (*url_open)( URLContext *h, const char *url, int flags); ++ /** ++ * This callback is to be used by protocols which open further nested ++ * protocols. options are then to be passed to ffurl_open()/ffurl_connect() ++ * for those nested protocols. ++ */ ++ int (*url_open2)(URLContext *h, const char *url, int flags, AVDictionary **options); ++ int (*url_read)( URLContext *h, unsigned char *buf, int size); ++ int (*url_write)(URLContext *h, const unsigned char *buf, int size); ++ int64_t (*url_seek)( URLContext *h, int64_t pos, int whence); ++ int (*url_close)(URLContext *h); ++ struct URLProtocol *next; ++ int (*url_read_pause)(URLContext *h, int pause); ++ int64_t (*url_read_seek)(URLContext *h, int stream_index, ++ int64_t timestamp, int flags); ++ int (*url_get_file_handle)(URLContext *h); ++ int priv_data_size; ++ const AVClass *priv_data_class; ++ int flags; ++ int (*url_check)(URLContext *h, int mask); ++} URLProtocol; ++#endif ++ ++/** ++ * Create a URLContext for accessing to the resource indicated by ++ * url, but do not initiate the connection yet. ++ * ++ * @param puc pointer to the location where, in case of success, the ++ * function puts the pointer to the created URLContext ++ * @param flags flags which control how the resource indicated by url ++ * is to be opened ++ * @param int_cb interrupt callback to use for the URLContext, may be ++ * NULL ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code in case of failure ++ */ ++int ffurl_alloc(URLContext **puc, const char *filename, int flags, ++ const AVIOInterruptCB *int_cb); ++ ++/** ++ * Connect an URLContext that has been allocated by ffurl_alloc ++ * ++ * @param options A dictionary filled with options for nested protocols, ++ * i.e. it will be passed to url_open2() for protocols implementing it. ++ * This parameter will be destroyed and replaced with a dict containing options ++ * that were not found. May be NULL. ++ */ ++int ffurl_connect(URLContext *uc, AVDictionary **options); ++ ++/** ++ * Create an URLContext for accessing to the resource indicated by ++ * url, and open it. ++ * ++ * @param puc pointer to the location where, in case of success, the ++ * function puts the pointer to the created URLContext ++ * @param flags flags which control how the resource indicated by url ++ * is to be opened ++ * @param int_cb interrupt callback to use for the URLContext, may be ++ * NULL ++ * @param options A dictionary filled with protocol-private options. On return ++ * this parameter will be destroyed and replaced with a dict containing options ++ * that were not found. May be NULL. ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code in case of failure ++ */ ++int ffurl_open(URLContext **puc, const char *filename, int flags, ++ const AVIOInterruptCB *int_cb, AVDictionary **options); ++ ++/** ++ * Read up to size bytes from the resource accessed by h, and store ++ * the read bytes in buf. ++ * ++ * @return The number of bytes actually read, or a negative value ++ * corresponding to an AVERROR code in case of error. A value of zero ++ * indicates that it is not possible to read more from the accessed ++ * resource (except if the value of the size argument is also zero). ++ */ ++int ffurl_read(URLContext *h, unsigned char *buf, int size); ++ ++/** ++ * Read as many bytes as possible (up to size), calling the ++ * read function multiple times if necessary. ++ * This makes special short-read handling in applications ++ * unnecessary, if the return value is < size then it is ++ * certain there was either an error or the end of file was reached. ++ */ ++int ffurl_read_complete(URLContext *h, unsigned char *buf, int size); ++ ++/** ++ * Write size bytes from buf to the resource accessed by h. ++ * ++ * @return the number of bytes actually written, or a negative value ++ * corresponding to an AVERROR code in case of failure ++ */ ++int ffurl_write(URLContext *h, const unsigned char *buf, int size); ++ ++/** ++ * Change the position that will be used by the next read/write ++ * operation on the resource accessed by h. ++ * ++ * @param pos specifies the new position to set ++ * @param whence specifies how pos should be interpreted, it must be ++ * one of SEEK_SET (seek from the beginning), SEEK_CUR (seek from the ++ * current position), SEEK_END (seek from the end), or AVSEEK_SIZE ++ * (return the filesize of the requested resource, pos is ignored). ++ * @return a negative value corresponding to an AVERROR code in case ++ * of failure, or the resulting file position, measured in bytes from ++ * the beginning of the file. You can use this feature together with ++ * SEEK_CUR to read the current file position. ++ */ ++int64_t ffurl_seek(URLContext *h, int64_t pos, int whence); ++ ++/** ++ * Close the resource accessed by the URLContext h, and free the ++ * memory used by it. ++ * ++ * @return a negative value if an error condition occurred, 0 ++ * otherwise ++ */ ++int ffurl_close(URLContext *h); ++ ++/** ++ * Return the filesize of the resource accessed by h, AVERROR(ENOSYS) ++ * if the operation is not supported by h, or another negative value ++ * corresponding to an AVERROR error code in case of failure. ++ */ ++int64_t ffurl_size(URLContext *h); ++ ++/** ++ * Return the file descriptor associated with this URL. For RTP, this ++ * will return only the RTP file descriptor, not the RTCP file descriptor. ++ * ++ * @return the file descriptor associated with this URL, or <0 on error. ++ */ ++int ffurl_get_file_handle(URLContext *h); ++ ++/** ++ * Register the URLProtocol protocol. ++ * ++ * @param size the size of the URLProtocol struct referenced ++ */ ++int ffurl_register_protocol(URLProtocol *protocol, int size); ++ ++/** ++ * Check if the user has requested to interrup a blocking function ++ * associated with cb. ++ */ ++int ff_check_interrupt(AVIOInterruptCB *cb); ++ ++/** ++ * Iterate over all available protocols. ++ * ++ * @param prev result of the previous call to this functions or NULL. ++ */ ++URLProtocol *ffurl_protocol_next(URLProtocol *prev); ++ ++/* udp.c */ ++int ff_udp_set_remote_url(URLContext *h, const char *uri); ++int ff_udp_get_local_port(URLContext *h); ++ ++#endif /* AVFORMAT_URL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/utils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/utils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/utils.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/utils.c 2012-05-14 14:08:55.246358336 +0200 +@@ -18,18 +18,30 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ ++ ++/* #define DEBUG */ ++ + #include "avformat.h" ++#include "avio_internal.h" + #include "internal.h" + #include "libavcodec/internal.h" ++#include "libavcodec/raw.h" ++#include "libavcodec/bytestream.h" ++#include "libavutil/avassert.h" + #include "libavutil/opt.h" ++#include "libavutil/dict.h" ++#include "libavutil/pixdesc.h" + #include "metadata.h" + #include "id3v2.h" ++#include "libavutil/avassert.h" + #include "libavutil/avstring.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/parseutils.h" + #include "riff.h" + #include "audiointerleave.h" ++#include "url.h" + #include + #include +-#include + #include + #if CONFIG_NETWORK + #include "network.h" +@@ -45,6 +57,7 @@ + + unsigned avformat_version(void) + { ++ av_assert0(LIBAVFORMAT_VERSION_MICRO >= 100); + return LIBAVFORMAT_VERSION_INT; + } + +@@ -71,7 +84,7 @@ + * @param num must be >= 0 + * @param den must be >= 1 + */ +-static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) ++static void frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den) + { + num += (den >> 1); + if (num >= den) { +@@ -89,7 +102,7 @@ + * @param f fractional number + * @param incr increment, can be positive or negative + */ +-static void av_frac_add(AVFrac *f, int64_t incr) ++static void frac_add(AVFrac *f, int64_t incr) + { + int64_t num, den; + +@@ -110,15 +123,9 @@ + } + + /** head of registered input format linked list */ +-#if !FF_API_FIRST_FORMAT +-static +-#endif +-AVInputFormat *first_iformat = NULL; ++static AVInputFormat *first_iformat = NULL; + /** head of registered output format linked list */ +-#if !FF_API_FIRST_FORMAT +-static +-#endif +-AVOutputFormat *first_oformat = NULL; ++static AVOutputFormat *first_oformat = NULL; + + AVInputFormat *av_iformat_next(AVInputFormat *f) + { +@@ -167,7 +174,7 @@ + while (*p != '\0' && *p != ',' && q-ext1name); +- stream_fmt = av_guess_format(stream_format_name, NULL, NULL); +- +- if (stream_fmt) +- fmt = stream_fmt; +- } +- +- return fmt; +-} +-#endif +- + enum CodecID av_guess_codec(AVOutputFormat *fmt, const char *short_name, + const char *filename, const char *mime_type, enum AVMediaType type){ + if(type == AVMEDIA_TYPE_VIDEO){ +@@ -266,7 +244,7 @@ + + #if CONFIG_IMAGE2_MUXER + if(!strcmp(fmt->name, "image2") || !strcmp(fmt->name, "image2pipe")){ +- codec_id= av_guess_image2_codec(filename); ++ codec_id= ff_guess_image2_codec(filename); + } + #endif + if(codec_id == CODEC_ID_NONE) +@@ -290,49 +268,39 @@ + return NULL; + } + +-#if FF_API_SYMVER && CONFIG_SHARED && HAVE_SYMVER +-FF_SYMVER(void, av_destruct_packet_nofree, (AVPacket *pkt), "LIBAVFORMAT_52") +-{ +- av_destruct_packet_nofree(pkt); +-} +- +-FF_SYMVER(void, av_destruct_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +-{ +- av_destruct_packet(pkt); +-} +- +-FF_SYMVER(int, av_new_packet, (AVPacket *pkt, int size), "LIBAVFORMAT_52") +-{ +- return av_new_packet(pkt, size); +-} +- +-FF_SYMVER(int, av_dup_packet, (AVPacket *pkt), "LIBAVFORMAT_52") ++int ffio_limit(AVIOContext *s, int size) + { +- return av_dup_packet(pkt); +-} ++ if(s->maxsize>=0){ ++ int64_t remaining= s->maxsize - avio_tell(s); ++ if(remaining < size){ ++ int64_t newsize= avio_size(s); ++ if(!s->maxsize || s->maxsizemaxsize= newsize - !newsize; ++ remaining= s->maxsize - avio_tell(s); ++ remaining= FFMAX(remaining, 0); ++ } + +-FF_SYMVER(void, av_free_packet, (AVPacket *pkt), "LIBAVFORMAT_52") +-{ +- av_free_packet(pkt); ++ if(s->maxsize>=0 && remaining+1 < size){ ++ av_log(0, AV_LOG_ERROR, "Truncating packet of size %d to %"PRId64"\n", size, remaining+1); ++ size= remaining+1; ++ } ++ } ++ return size; + } + +-FF_SYMVER(void, av_init_packet, (AVPacket *pkt), "LIBAVFORMAT_52") ++int av_get_packet(AVIOContext *s, AVPacket *pkt, int size) + { +- av_log(NULL, AV_LOG_WARNING, "Diverting av_*_packet function calls to libavcodec. Recompile to improve performance\n"); +- av_init_packet(pkt); +-} +-#endif ++ int ret; ++ size= ffio_limit(s, size); + +-int av_get_packet(ByteIOContext *s, AVPacket *pkt, int size) +-{ +- int ret= av_new_packet(pkt, size); ++ ret= av_new_packet(pkt, size); + + if(ret<0) + return ret; + +- pkt->pos= url_ftell(s); ++ pkt->pos= avio_tell(s); + +- ret= get_buffer(s, pkt->data, size); ++ ret= avio_read(s, pkt->data, size); + if(ret<=0) + av_free_packet(pkt); + else +@@ -341,7 +309,7 @@ + return ret; + } + +-int av_append_packet(ByteIOContext *s, AVPacket *pkt, int size) ++int av_append_packet(AVIOContext *s, AVPacket *pkt, int size) + { + int ret; + int old_size; +@@ -351,7 +319,7 @@ + ret = av_grow_packet(pkt, size); + if (ret < 0) + return ret; +- ret = get_buffer(s, pkt->data + old_size, size); ++ ret = avio_read(s, pkt->data + old_size, size); + av_shrink_packet(pkt, old_size + FFMAX(ret, 0)); + return ret; + } +@@ -363,18 +331,19 @@ + return filename && (av_get_frame_filename(buf, sizeof(buf), filename, 1)>=0); + } + +-AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max) ++AVInputFormat *av_probe_input_format3(AVProbeData *pd, int is_opened, int *score_ret) + { + AVProbeData lpd = *pd; + AVInputFormat *fmt1 = NULL, *fmt; +- int score; ++ int score, nodat = 0, score_max=0; + + if (lpd.buf_size > 10 && ff_id3v2_match(lpd.buf, ID3v2_DEFAULT_MAGIC)) { + int id3len = ff_id3v2_tag_len(lpd.buf); + if (lpd.buf_size > id3len + 16) { + lpd.buf += id3len; + lpd.buf_size -= id3len; +- } ++ }else ++ nodat = 1; + } + + fmt = NULL; +@@ -384,26 +353,41 @@ + score = 0; + if (fmt1->read_probe) { + score = fmt1->read_probe(&lpd); ++ if(fmt1->extensions && av_match_ext(lpd.filename, fmt1->extensions)) ++ score = FFMAX(score, nodat ? AVPROBE_SCORE_MAX/4-1 : 1); + } else if (fmt1->extensions) { + if (av_match_ext(lpd.filename, fmt1->extensions)) { + score = 50; + } + } +- if (score > *score_max) { +- *score_max = score; ++ if (score > score_max) { ++ score_max = score; + fmt = fmt1; +- }else if (score == *score_max) ++ }else if (score == score_max) + fmt = NULL; + } ++ *score_ret= score_max; ++ + return fmt; + } + ++AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max) ++{ ++ int score_ret; ++ AVInputFormat *fmt= av_probe_input_format3(pd, is_opened, &score_ret); ++ if(score_ret > *score_max){ ++ *score_max= score_ret; ++ return fmt; ++ }else ++ return NULL; ++} ++ + AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened){ + int score=0; + return av_probe_input_format2(pd, is_opened, &score); + } + +-static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd, int score) ++static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeData *pd) + { + static const struct { + const char *name; enum CodecID id; enum AVMediaType type; +@@ -413,12 +397,14 @@ + { "dts" , CODEC_ID_DTS , AVMEDIA_TYPE_AUDIO }, + { "eac3" , CODEC_ID_EAC3 , AVMEDIA_TYPE_AUDIO }, + { "h264" , CODEC_ID_H264 , AVMEDIA_TYPE_VIDEO }, ++ { "loas" , CODEC_ID_AAC_LATM , AVMEDIA_TYPE_AUDIO }, + { "m4v" , CODEC_ID_MPEG4 , AVMEDIA_TYPE_VIDEO }, + { "mp3" , CODEC_ID_MP3 , AVMEDIA_TYPE_AUDIO }, + { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO }, + { 0 } + }; +- AVInputFormat *fmt = av_probe_input_format2(pd, 1, &score); ++ int score; ++ AVInputFormat *fmt = av_probe_input_format3(pd, 1, &score); + + if (fmt) { + int i; +@@ -432,20 +418,67 @@ + } + } + } +- return !!fmt; ++ return score; + } + + /************************************************************/ + /* input media file */ + ++#if FF_API_FORMAT_PARAMETERS ++static AVDictionary *convert_format_parameters(AVFormatParameters *ap) ++{ ++ char buf[1024]; ++ AVDictionary *opts = NULL; ++ ++ if (!ap) ++ return NULL; ++ ++ AV_NOWARN_DEPRECATED( ++ if (ap->time_base.num) { ++ snprintf(buf, sizeof(buf), "%d/%d", ap->time_base.den, ap->time_base.num); ++ av_dict_set(&opts, "framerate", buf, 0); ++ } ++ if (ap->sample_rate) { ++ snprintf(buf, sizeof(buf), "%d", ap->sample_rate); ++ av_dict_set(&opts, "sample_rate", buf, 0); ++ } ++ if (ap->channels) { ++ snprintf(buf, sizeof(buf), "%d", ap->channels); ++ av_dict_set(&opts, "channels", buf, 0); ++ } ++ if (ap->width || ap->height) { ++ snprintf(buf, sizeof(buf), "%dx%d", ap->width, ap->height); ++ av_dict_set(&opts, "video_size", buf, 0); ++ } ++ if (ap->pix_fmt != PIX_FMT_NONE) { ++ av_dict_set(&opts, "pixel_format", av_get_pix_fmt_name(ap->pix_fmt), 0); ++ } ++ if (ap->channel) { ++ snprintf(buf, sizeof(buf), "%d", ap->channel); ++ av_dict_set(&opts, "channel", buf, 0); ++ } ++ if (ap->standard) { ++ av_dict_set(&opts, "standard", ap->standard, 0); ++ } ++ if (ap->mpeg2ts_compute_pcr) { ++ av_dict_set(&opts, "mpeg2ts_compute_pcr", "1", 0); ++ } ++ if (ap->initial_pause) { ++ av_dict_set(&opts, "initial_pause", "1", 0); ++ } ++ ) ++ return opts; ++} ++ + /** + * Open a media file from an IO stream. 'fmt' must be specified. + */ + int av_open_input_stream(AVFormatContext **ic_ptr, +- ByteIOContext *pb, const char *filename, ++ AVIOContext *pb, const char *filename, + AVInputFormat *fmt, AVFormatParameters *ap) + { + int err; ++ AVDictionary *opts; + AVFormatContext *ic; + AVFormatParameters default_ap; + +@@ -453,78 +486,56 @@ + ap=&default_ap; + memset(ap, 0, sizeof(default_ap)); + } ++ opts = convert_format_parameters(ap); + ++ AV_NOWARN_DEPRECATED( + if(!ap->prealloced_context) +- ic = avformat_alloc_context(); ++ *ic_ptr = ic = avformat_alloc_context(); + else + ic = *ic_ptr; ++ ) + if (!ic) { + err = AVERROR(ENOMEM); + goto fail; + } +- ic->iformat = fmt; +- ic->pb = pb; +- ic->duration = AV_NOPTS_VALUE; +- ic->start_time = AV_NOPTS_VALUE; +- av_strlcpy(ic->filename, filename, sizeof(ic->filename)); ++ if (pb && fmt && fmt->flags & AVFMT_NOFILE) ++ av_log(ic, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " ++ "will be ignored with AVFMT_NOFILE format.\n"); ++ else ++ ic->pb = pb; + +- /* allocate private data */ +- if (fmt->priv_data_size > 0) { +- ic->priv_data = av_mallocz(fmt->priv_data_size); +- if (!ic->priv_data) { +- err = AVERROR(ENOMEM); +- goto fail; +- } +- } else { +- ic->priv_data = NULL; +- } ++ if ((err = avformat_open_input(&ic, filename, fmt, &opts)) < 0) ++ goto fail; ++ ic->pb = ic->pb ? ic->pb : pb; // don't leak custom pb if it wasn't set above ++ ++fail: ++ *ic_ptr = ic; ++ av_dict_free(&opts); ++ return err; ++} ++#endif + +- // e.g. AVFMT_NOFILE formats will not have a ByteIOContext +- if (ic->pb) +- ff_id3v2_read(ic, ID3v2_DEFAULT_MAGIC); ++int av_demuxer_open(AVFormatContext *ic, AVFormatParameters *ap){ ++ int err; + + if (ic->iformat->read_header) { + err = ic->iformat->read_header(ic, ap); + if (err < 0) +- goto fail; ++ return err; + } + +- if (pb && !ic->data_offset) +- ic->data_offset = url_ftell(ic->pb); +- +-#if FF_API_OLD_METADATA +- ff_metadata_demux_compat(ic); +-#endif +- +- ic->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; ++ if (ic->pb && !ic->data_offset) ++ ic->data_offset = avio_tell(ic->pb); + +- *ic_ptr = ic; + return 0; +- fail: +- if (ic) { +- int i; +- av_freep(&ic->priv_data); +- for(i=0;inb_streams;i++) { +- AVStream *st = ic->streams[i]; +- if (st) { +- av_free(st->priv_data); +- av_free(st->codec->extradata); +- av_free(st->codec); +- av_free(st->info); +- } +- av_free(st); +- } +- } +- av_free(ic); +- *ic_ptr = NULL; +- return err; + } + ++ + /** size of probe buffer, for guessing file type from file contents */ + #define PROBE_BUF_MIN 2048 + #define PROBE_BUF_MAX (1<<20) + +-int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, ++int av_probe_input_buffer(AVIOContext *pb, AVInputFormat **fmt, + const char *filename, void *logctx, + unsigned int offset, unsigned int max_probe_size) + { +@@ -544,18 +555,24 @@ + return AVERROR(EINVAL); + } + +- for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt && ret >= 0; ++ for(probe_size= PROBE_BUF_MIN; probe_size<=max_probe_size && !*fmt; + probe_size = FFMIN(probe_size<<1, FFMAX(max_probe_size, probe_size+1))) { +- int ret, score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX/4 : 0; ++ int score = probe_size < max_probe_size ? AVPROBE_SCORE_MAX/4 : 0; + int buf_offset = (probe_size == PROBE_BUF_MIN) ? 0 : probe_size>>1; ++ void *buftmp; + + if (probe_size < offset) { + continue; + } + + /* read probe data */ +- buf = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE); +- if ((ret = get_buffer(pb, buf + buf_offset, probe_size - buf_offset)) < 0) { ++ buftmp = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE); ++ if(!buftmp){ ++ av_free(buf); ++ return AVERROR(ENOMEM); ++ } ++ buf=buftmp; ++ if ((ret = avio_read(pb, buf + buf_offset, probe_size - buf_offset)) < 0) { + /* fail if error was not end of file, otherwise, lower score */ + if (ret != AVERROR_EOF) { + av_free(buf); +@@ -573,9 +590,9 @@ + *fmt = av_probe_input_format2(&pd, 1, &score); + if(*fmt){ + if(score <= AVPROBE_SCORE_MAX/4){ //this can only be true in the last iteration +- av_log(logctx, AV_LOG_WARNING, "Format detected only with low score of %d, misdetection possible!\n", score); ++ av_log(logctx, AV_LOG_WARNING, "Format %s detected only with low score of %d, misdetection possible!\n", (*fmt)->name, score); + }else +- av_log(logctx, AV_LOG_DEBUG, "Probed with size=%d and score=%d\n", probe_size, score); ++ av_log(logctx, AV_LOG_DEBUG, "Format %s probed with size=%d and score=%d\n", (*fmt)->name, probe_size, score); + } + } + +@@ -585,74 +602,134 @@ + } + + /* rewind. reuse probe buffer to avoid seeking */ +- if ((ret = ff_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) ++ if ((ret = ffio_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) + av_free(buf); + + return ret; + } + ++#if FF_API_FORMAT_PARAMETERS + int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, + AVInputFormat *fmt, + int buf_size, + AVFormatParameters *ap) + { + int err; +- AVProbeData probe_data, *pd = &probe_data; +- ByteIOContext *pb = NULL; +- void *logctx= ap && ap->prealloced_context ? *ic_ptr : NULL; ++ AVDictionary *opts = convert_format_parameters(ap); + +- pd->filename = ""; +- if (filename) +- pd->filename = filename; +- pd->buf = NULL; +- pd->buf_size = 0; +- +- if (!fmt) { +- /* guess format if no file can be opened */ +- fmt = av_probe_input_format(pd, 0); ++ AV_NOWARN_DEPRECATED( ++ if (!ap || !ap->prealloced_context) ++ *ic_ptr = NULL; ++ ) ++ ++ err = avformat_open_input(ic_ptr, filename, fmt, &opts); ++ ++ av_dict_free(&opts); ++ return err; ++} ++#endif ++ ++/* open input file and probe the format if necessary */ ++static int init_input(AVFormatContext *s, const char *filename, AVDictionary **options) ++{ ++ int ret; ++ AVProbeData pd = {filename, NULL, 0}; ++ ++ if (s->pb) { ++ s->flags |= AVFMT_FLAG_CUSTOM_IO; ++ if (!s->iformat) ++ return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0); ++ else if (s->iformat->flags & AVFMT_NOFILE) ++ av_log(s, AV_LOG_WARNING, "Custom AVIOContext makes no sense and " ++ "will be ignored with AVFMT_NOFILE format.\n"); ++ return 0; + } + +- /* Do not open file if the format does not need it. XXX: specific +- hack needed to handle RTSP/TCP */ +- if (!fmt || !(fmt->flags & AVFMT_NOFILE)) { +- /* if no file needed do not try to open one */ +- if ((err=url_fopen(&pb, filename, URL_RDONLY)) < 0) { ++ if ( (s->iformat && s->iformat->flags & AVFMT_NOFILE) || ++ (!s->iformat && (s->iformat = av_probe_input_format(&pd, 0)))) ++ return 0; ++ ++ if ((ret = avio_open2(&s->pb, filename, AVIO_FLAG_READ, ++ &s->interrupt_callback, options)) < 0) ++ return ret; ++ if (s->iformat) ++ return 0; ++ return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0); ++} ++ ++int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options) ++{ ++ AVFormatContext *s = *ps; ++ int ret = 0; ++ AVFormatParameters ap = { { 0 } }; ++ AVDictionary *tmp = NULL; ++ ++ if (!s && !(s = avformat_alloc_context())) ++ return AVERROR(ENOMEM); ++ if (fmt) ++ s->iformat = fmt; ++ ++ if (options) ++ av_dict_copy(&tmp, *options, 0); ++ ++ if ((ret = av_opt_set_dict(s, &tmp)) < 0) ++ goto fail; ++ ++ if ((ret = init_input(s, filename, &tmp)) < 0) ++ goto fail; ++ ++ /* check filename in case an image number is expected */ ++ if (s->iformat->flags & AVFMT_NEEDNUMBER) { ++ if (!av_filename_number_test(filename)) { ++ ret = AVERROR(EINVAL); + goto fail; + } +- if (buf_size > 0) { +- url_setbufsize(pb, buf_size); +- } +- if (!fmt && (err = av_probe_input_buffer(pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { ++ } ++ ++ s->duration = s->start_time = AV_NOPTS_VALUE; ++ av_strlcpy(s->filename, filename, sizeof(s->filename)); ++ ++ /* allocate private data */ ++ if (s->iformat->priv_data_size > 0) { ++ if (!(s->priv_data = av_mallocz(s->iformat->priv_data_size))) { ++ ret = AVERROR(ENOMEM); + goto fail; + } ++ if (s->iformat->priv_class) { ++ *(const AVClass**)s->priv_data = s->iformat->priv_class; ++ av_opt_set_defaults(s->priv_data); ++ if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) ++ goto fail; ++ } + } + +- /* if still no format found, error */ +- if (!fmt) { +- err = AVERROR_INVALIDDATA; +- goto fail; +- } ++ /* e.g. AVFMT_NOFILE formats will not have a AVIOContext */ ++ if (s->pb) ++ ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC); + +- /* check filename in case an image number is expected */ +- if (fmt->flags & AVFMT_NEEDNUMBER) { +- if (!av_filename_number_test(filename)) { +- err = AVERROR_NUMEXPECTED; ++ if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->iformat->read_header) ++ if ((ret = s->iformat->read_header(s, &ap)) < 0) + goto fail; +- } ++ ++ if (!(s->flags&AVFMT_FLAG_PRIV_OPT) && s->pb && !s->data_offset) ++ s->data_offset = avio_tell(s->pb); ++ ++ s->raw_packet_buffer_remaining_size = RAW_PACKET_BUFFER_SIZE; ++ ++ if (options) { ++ av_dict_free(options); ++ *options = tmp; + } +- err = av_open_input_stream(ic_ptr, pb, filename, fmt, ap); +- if (err) +- goto fail; ++ *ps = s; + return 0; +- fail: +- av_freep(&pd->buf); +- if (pb) +- url_fclose(pb); +- if (ap && ap->prealloced_context) +- av_free(*ic_ptr); +- *ic_ptr = NULL; +- return err; + ++fail: ++ av_dict_free(&tmp); ++ if (s->pb && !(s->flags & AVFMT_FLAG_CUSTOM_IO)) ++ avio_close(s->pb); ++ avformat_free_context(s); ++ *ps = NULL; ++ return ret; + } + + /*******************************************************/ +@@ -684,12 +761,7 @@ + + if (pktl) { + *pkt = pktl->pkt; +- if(s->streams[pkt->stream_index]->codec->codec_id != CODEC_ID_PROBE || +- !s->streams[pkt->stream_index]->probe_packets || +- s->raw_packet_buffer_remaining_size < pkt->size){ +- AVProbeData *pd = &s->streams[pkt->stream_index]->probe_data; +- av_freep(&pd->buf); +- pd->buf_size = 0; ++ if(s->streams[pkt->stream_index]->request_probe <= 0){ + s->raw_packet_buffer = pktl->next; + s->raw_packet_buffer_remaining_size += pkt->size; + av_free(pktl); +@@ -703,9 +775,28 @@ + if (!pktl || ret == AVERROR(EAGAIN)) + return ret; + for (i = 0; i < s->nb_streams; i++) +- s->streams[i]->probe_packets = 0; ++ if(s->streams[i]->request_probe > 0) ++ s->streams[i]->request_probe = -1; ++ continue; ++ } ++ ++ if ((s->flags & AVFMT_FLAG_DISCARD_CORRUPT) && ++ (pkt->flags & AV_PKT_FLAG_CORRUPT)) { ++ av_log(s, AV_LOG_WARNING, ++ "Dropped corrupted packet (stream = %d)\n", ++ pkt->stream_index); ++ av_free_packet(pkt); ++ continue; ++ } ++ ++ if(!(s->flags & AVFMT_FLAG_KEEP_SIDE_DATA)) ++ av_packet_merge_side_data(pkt); ++ ++ if(pkt->stream_index >= (unsigned)s->nb_streams){ ++ av_log(s, AV_LOG_ERROR, "Invalid stream index %d\n", pkt->stream_index); + continue; + } ++ + st= s->streams[pkt->stream_index]; + + switch(st->codec->codec_type){ +@@ -720,16 +811,16 @@ + break; + } + +- if(!pktl && (st->codec->codec_id != CODEC_ID_PROBE || +- !st->probe_packets)) ++ if(!pktl && st->request_probe <= 0) + return ret; + + add_to_pktbuf(&s->raw_packet_buffer, pkt, &s->raw_packet_buffer_end); + s->raw_packet_buffer_remaining_size -= pkt->size; + +- if(st->codec->codec_id == CODEC_ID_PROBE){ ++ if(st->request_probe>0){ + AVProbeData *pd = &st->probe_data; +- av_log(s, AV_LOG_DEBUG, "probing stream %d\n", st->index); ++ int end; ++ av_log(s, AV_LOG_DEBUG, "probing stream %d pp:%d\n", st->index, st->probe_packets); + --st->probe_packets; + + pd->buf = av_realloc(pd->buf, pd->buf_size+pkt->size+AVPROBE_PADDING_SIZE); +@@ -737,13 +828,20 @@ + pd->buf_size += pkt->size; + memset(pd->buf+pd->buf_size, 0, AVPROBE_PADDING_SIZE); + +- if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ +- //FIXME we dont reduce score to 0 for the case of running out of buffer space in bytes +- set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4-1 : 0); +- if(st->codec->codec_id != CODEC_ID_PROBE){ ++ end= s->raw_packet_buffer_remaining_size <= 0 ++ || st->probe_packets<=0; ++ ++ if(end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ ++ int score= set_codec_from_probe_data(s, st, pd); ++ if( (st->codec->codec_id != CODEC_ID_NONE && score > AVPROBE_SCORE_MAX/4) ++ || end){ + pd->buf_size=0; + av_freep(&pd->buf); ++ st->request_probe= -1; ++ if(st->codec->codec_id != CODEC_ID_NONE){ + av_log(s, AV_LOG_DEBUG, "probed stream %d\n", st->index); ++ }else ++ av_log(s, AV_LOG_WARNING, "probed stream %d failed\n", st->index); + } + } + } +@@ -794,7 +892,10 @@ + *pden = 0; + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: +- if(st->time_base.num*1000LL > st->time_base.den){ ++ if (st->r_frame_rate.num && !pc) { ++ *pnum = st->r_frame_rate.den; ++ *pden = st->r_frame_rate.num; ++ } else if(st->time_base.num*1000LL > st->time_base.den) { + *pnum = st->time_base.num; + *pden = st->time_base.den; + }else if(st->codec->time_base.num*1000LL > st->codec->time_base.den){ +@@ -830,6 +931,7 @@ + case CODEC_ID_MJPEG: + case CODEC_ID_MJPEGB: + case CODEC_ID_LJPEG: ++ case CODEC_ID_PRORES: + case CODEC_ID_RAWVIDEO: + case CODEC_ID_DVVIDEO: + case CODEC_ID_HUFFYUV: +@@ -923,21 +1025,21 @@ + if((s->flags & AVFMT_FLAG_IGNDTS) && pkt->pts != AV_NOPTS_VALUE) + pkt->dts= AV_NOPTS_VALUE; + +- if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == FF_B_TYPE) ++ if (st->codec->codec_id != CODEC_ID_H264 && pc && pc->pict_type == AV_PICTURE_TYPE_B) + //FIXME Set low_delay = 0 when has_b_frames = 1 + st->codec->has_b_frames = 1; + + /* do we have a video B-frame ? */ + delay= st->codec->has_b_frames; + presentation_delayed = 0; ++ + /* XXX: need has_b_frame, but cannot get it if the codec is + not initialized */ + if (delay && +- pc && pc->pict_type != FF_B_TYPE) ++ pc && pc->pict_type != AV_PICTURE_TYPE_B) + presentation_delayed = 1; + +- if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts > pkt->pts && st->pts_wrap_bits<63 +- /*&& pkt->dts-(1LL<pts_wrap_bits) < pkt->pts*/){ ++ if(pkt->pts != AV_NOPTS_VALUE && pkt->dts != AV_NOPTS_VALUE && pkt->dts - (1LL<<(st->pts_wrap_bits-1)) > pkt->pts && st->pts_wrap_bits<63){ + pkt->dts -= 1LL<pts_wrap_bits; + } + +@@ -945,8 +1047,8 @@ + // we take the conservative approach and discard both + // Note, if this is misbehaving for a H.264 file then possibly presentation_delayed is not set correctly. + if(delay==1 && pkt->dts == pkt->pts && pkt->dts != AV_NOPTS_VALUE && presentation_delayed){ +- av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination\n"); +- pkt->dts= pkt->pts= AV_NOPTS_VALUE; ++ av_log(s, AV_LOG_DEBUG, "invalid dts/pts combination %"PRIi64"\n", pkt->dts); ++ pkt->dts= AV_NOPTS_VALUE; + } + + if (pkt->duration == 0) { +@@ -1044,7 +1146,7 @@ + FFSWAP(int64_t, st->pts_buffer[i], st->pts_buffer[i+1]); + if(pkt->dts == AV_NOPTS_VALUE) + pkt->dts= st->pts_buffer[0]; +- if(st->codec->codec_id == CODEC_ID_H264){ //we skiped it above so we try here ++ if(st->codec->codec_id == CODEC_ID_H264){ // we skipped it above so we try here + update_initial_timestamps(s, pkt->stream_index, pkt->dts, pkt->pts); // this should happen on the first packet + } + if(pkt->dts > st->cur_dts) +@@ -1061,7 +1163,7 @@ + /* keyframe computation */ + if (pc->key_frame == 1) + pkt->flags |= AV_PKT_FLAG_KEY; +- else if (pc->key_frame == -1 && pc->pict_type == FF_I_TYPE) ++ else if (pc->key_frame == -1 && pc->pict_type == AV_PICTURE_TYPE_I) + pkt->flags |= AV_PKT_FLAG_KEY; + } + if (pc) +@@ -1069,7 +1171,7 @@ + } + + +-static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) ++static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) + { + AVStream *st; + int len, ret, i; +@@ -1083,7 +1185,10 @@ + if (!st->need_parsing || !st->parser) { + /* no parsing needed: we just output the packet as is */ + /* raw data support */ +- *pkt = st->cur_pkt; st->cur_pkt.data= NULL; ++ *pkt = st->cur_pkt; ++ st->cur_pkt.data= NULL; ++ st->cur_pkt.side_data_elems = 0; ++ st->cur_pkt.side_data = NULL; + compute_pkt_fields(s, st, NULL, pkt); + s->cur_st = NULL; + if ((s->iformat->flags & AVFMT_GENERIC_INDEX) && +@@ -1092,7 +1197,7 @@ + av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); + } + break; +- } else if (st->cur_len > 0 && st->cur_ptr && st->discard < AVDISCARD_ALL) { ++ } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) { + len = av_parser_parse2(st->parser, st->codec, &pkt->data, &pkt->size, + st->cur_ptr, st->cur_len, + st->cur_pkt.pts, st->cur_pkt.dts, +@@ -1118,13 +1223,14 @@ + st->cur_pkt.data = NULL; + assert(st->cur_len == 0); + }else{ +- pkt->destruct = NULL; ++ pkt->destruct = NULL; + } + compute_pkt_fields(s, st, st->parser, pkt); + + if((s->iformat->flags & AVFMT_GENERIC_INDEX) && pkt->flags & AV_PKT_FLAG_KEY){ ++ int64_t pos= (st->parser->flags & PARSER_FLAG_COMPLETE_FRAMES) ? pkt->pos : st->parser->frame_offset; + ff_reduce_index(s, st->index); +- av_add_index_entry(st, st->parser->frame_offset, pkt->dts, ++ av_add_index_entry(st, pos, pkt->dts, + 0, 0, AVINDEX_KEYFRAME); + } + +@@ -1142,7 +1248,7 @@ + if (ret < 0) { + if (ret == AVERROR(EAGAIN)) + return ret; +- if (ret == AVERROR_IO) ++ if (ret == AVERROR(EIO)) + return ret; + /* return the last frames, if any */ + for(i = 0; i < s->nb_streams; i++) { +@@ -1190,6 +1296,9 @@ + if (st->need_parsing && !st->parser && !(s->flags & AVFMT_FLAG_NOPARSE)) { + st->parser = av_parser_init(st->codec->codec_id); + if (!st->parser) { ++ av_log(s, AV_LOG_VERBOSE, "parser not found for codec " ++ "%s, packets or times may be invalid.\n", ++ avcodec_get_name(st->codec->codec_id)); + /* no parser available: just output the raw packets */ + st->need_parsing = AVSTREAM_PARSE_NONE; + }else if(st->need_parsing == AVSTREAM_PARSE_HEADERS){ +@@ -1201,7 +1310,7 @@ + } + } + if(s->debug & FF_FDEBUG_TS) +- av_log(s, AV_LOG_DEBUG, "av_read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", ++ av_log(s, AV_LOG_DEBUG, "read_frame_internal stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", + pkt->stream_index, + pkt->pts, + pkt->dts, +@@ -1212,57 +1321,63 @@ + return 0; + } + ++static int read_from_packet_buffer(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVPacketList *pktl = s->packet_buffer; ++ av_assert0(pktl); ++ *pkt = pktl->pkt; ++ s->packet_buffer = pktl->next; ++ av_freep(&pktl); ++ return 0; ++} ++ + int av_read_frame(AVFormatContext *s, AVPacket *pkt) + { +- AVPacketList *pktl; +- int eof=0; +- const int genpts= s->flags & AVFMT_FLAG_GENPTS; ++ const int genpts = s->flags & AVFMT_FLAG_GENPTS; ++ int eof = 0; ++ ++ if (!genpts) ++ return s->packet_buffer ? read_from_packet_buffer(s, pkt) : ++ read_frame_internal(s, pkt); ++ ++ for (;;) { ++ int ret; ++ AVPacketList *pktl = s->packet_buffer; + +- for(;;){ +- pktl = s->packet_buffer; + if (pktl) { +- AVPacket *next_pkt= &pktl->pkt; ++ AVPacket *next_pkt = &pktl->pkt; + +- if(genpts && next_pkt->dts != AV_NOPTS_VALUE){ ++ if (next_pkt->dts != AV_NOPTS_VALUE) { + int wrap_bits = s->streams[next_pkt->stream_index]->pts_wrap_bits; +- while(pktl && next_pkt->pts == AV_NOPTS_VALUE){ +- if( pktl->pkt.stream_index == next_pkt->stream_index +- && (0 > av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) +- && av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) { //not b frame +- next_pkt->pts= pktl->pkt.dts; ++ while (pktl && next_pkt->pts == AV_NOPTS_VALUE) { ++ if (pktl->pkt.stream_index == next_pkt->stream_index && ++ (av_compare_mod(next_pkt->dts, pktl->pkt.dts, 2LL << (wrap_bits - 1)) < 0) && ++ av_compare_mod(pktl->pkt.pts, pktl->pkt.dts, 2LL << (wrap_bits - 1))) { //not b frame ++ next_pkt->pts = pktl->pkt.dts; + } +- pktl= pktl->next; ++ pktl = pktl->next; + } + pktl = s->packet_buffer; + } + +- if( next_pkt->pts != AV_NOPTS_VALUE +- || next_pkt->dts == AV_NOPTS_VALUE +- || !genpts || eof){ +- /* read packet from packet buffer, if there is data */ +- *pkt = *next_pkt; +- s->packet_buffer = pktl->next; +- av_free(pktl); +- return 0; +- } ++ /* read packet from packet buffer, if there is data */ ++ if (!(next_pkt->pts == AV_NOPTS_VALUE && ++ next_pkt->dts != AV_NOPTS_VALUE && !eof)) ++ return read_from_packet_buffer(s, pkt); + } +- if(genpts){ +- int ret= av_read_frame_internal(s, pkt); +- if(ret<0){ +- if(pktl && ret != AVERROR(EAGAIN)){ +- eof=1; +- continue; +- }else +- return ret; +- } + +- if(av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt, +- &s->packet_buffer_end)) < 0) +- return AVERROR(ENOMEM); +- }else{ +- assert(!s->packet_buffer); +- return av_read_frame_internal(s, pkt); ++ ret = read_frame_internal(s, pkt); ++ if (ret < 0) { ++ if (pktl && ret != AVERROR(EAGAIN)) { ++ eof = 1; ++ continue; ++ } else ++ return ret; + } ++ ++ if (av_dup_packet(add_to_pktbuf(&s->packet_buffer, pkt, ++ &s->packet_buffer_end)) < 0) ++ return AVERROR(ENOMEM); + } + } + +@@ -1334,7 +1449,8 @@ + av_free_packet(&st->cur_pkt); + } + st->last_IP_pts = AV_NOPTS_VALUE; +- st->cur_dts = AV_NOPTS_VALUE; /* we set the current DTS to an unspecified origin */ ++ if(st->first_dts == AV_NOPTS_VALUE) st->cur_dts = 0; ++ else st->cur_dts = AV_NOPTS_VALUE; /* we set the current DTS to an unspecified origin */ + st->reference_dts = AV_NOPTS_VALUE; + /* fail safe */ + st->cur_ptr = NULL; +@@ -1347,7 +1463,20 @@ + } + } + +-void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp){ ++void av_read_frame_flush(AVFormatContext *s) ++{ ++ ff_read_frame_flush(s); ++} ++ ++#if FF_API_SEEK_PUBLIC ++void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) ++{ ++ ff_update_cur_dts(s, ref_st, timestamp); ++} ++#endif ++ ++void ff_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) ++{ + int i; + + for(i = 0; i < s->nb_streams; i++) { +@@ -1372,28 +1501,30 @@ + } + } + +-int av_add_index_entry(AVStream *st, +- int64_t pos, int64_t timestamp, int size, int distance, int flags) ++int ff_add_index_entry(AVIndexEntry **index_entries, ++ int *nb_index_entries, ++ unsigned int *index_entries_allocated_size, ++ int64_t pos, int64_t timestamp, int size, int distance, int flags) + { + AVIndexEntry *entries, *ie; + int index; + +- if((unsigned)st->nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) ++ if((unsigned)*nb_index_entries + 1 >= UINT_MAX / sizeof(AVIndexEntry)) + return -1; + +- entries = av_fast_realloc(st->index_entries, +- &st->index_entries_allocated_size, +- (st->nb_index_entries + 1) * ++ entries = av_fast_realloc(*index_entries, ++ index_entries_allocated_size, ++ (*nb_index_entries + 1) * + sizeof(AVIndexEntry)); + if(!entries) + return -1; + +- st->index_entries= entries; ++ *index_entries= entries; + +- index= av_index_search_timestamp(st, timestamp, AVSEEK_FLAG_ANY); ++ index= ff_index_search_timestamp(*index_entries, *nb_index_entries, timestamp, AVSEEK_FLAG_ANY); + + if(index<0){ +- index= st->nb_index_entries++; ++ index= (*nb_index_entries)++; + ie= &entries[index]; + assert(index==0 || ie[-1].timestamp < timestamp); + }else{ +@@ -1401,8 +1532,8 @@ + if(ie->timestamp != timestamp){ + if(ie->timestamp <= timestamp) + return -1; +- memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(st->nb_index_entries - index)); +- st->nb_index_entries++; ++ memmove(entries + index + 1, entries + index, sizeof(AVIndexEntry)*(*nb_index_entries - index)); ++ (*nb_index_entries)++; + }else if(ie->pos == pos && distance < ie->min_distance) //do not reduce the distance + distance= ie->min_distance; + } +@@ -1416,11 +1547,17 @@ + return index; + } + +-int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, +- int flags) ++int av_add_index_entry(AVStream *st, ++ int64_t pos, int64_t timestamp, int size, int distance, int flags) ++{ ++ return ff_add_index_entry(&st->index_entries, &st->nb_index_entries, ++ &st->index_entries_allocated_size, pos, ++ timestamp, size, distance, flags); ++} ++ ++int ff_index_search_timestamp(const AVIndexEntry *entries, int nb_entries, ++ int64_t wanted_timestamp, int flags) + { +- AVIndexEntry *entries= st->index_entries; +- int nb_entries= st->nb_index_entries; + int a, b, m; + int64_t timestamp; + +@@ -1452,9 +1589,21 @@ + return m; + } + +-#define DEBUG_SEEK ++int av_index_search_timestamp(AVStream *st, int64_t wanted_timestamp, ++ int flags) ++{ ++ return ff_index_search_timestamp(st->index_entries, st->nb_index_entries, ++ wanted_timestamp, flags); ++} + ++#if FF_API_SEEK_PUBLIC + int av_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags){ ++ return ff_seek_frame_binary(s, stream_index, target_ts, flags); ++} ++#endif ++ ++int ff_seek_frame_binary(AVFormatContext *s, int stream_index, int64_t target_ts, int flags) ++{ + AVInputFormat *avif= s->iformat; + int64_t av_uninit(pos_min), av_uninit(pos_max), pos, pos_limit; + int64_t ts_min, ts_max, ts; +@@ -1465,9 +1614,7 @@ + if (stream_index < 0) + return -1; + +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "read_seek: %d %"PRId64"\n", stream_index, target_ts); +-#endif ++ av_dlog(s, "read_seek: %d %"PRId64"\n", stream_index, target_ts); + + ts_max= + ts_min= AV_NOPTS_VALUE; +@@ -1484,10 +1631,8 @@ + if(e->timestamp <= target_ts || e->pos == e->min_distance){ + pos_min= e->pos; + ts_min= e->timestamp; +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n", +- pos_min,ts_min); +-#endif ++ av_dlog(s, "using cached pos_min=0x%"PRIx64" dts_min=%"PRId64"\n", ++ pos_min,ts_min); + }else{ + assert(index==0); + } +@@ -1500,34 +1645,47 @@ + pos_max= e->pos; + ts_max= e->timestamp; + pos_limit= pos_max - e->min_distance; +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n", +- pos_max,pos_limit, ts_max); +-#endif ++ av_dlog(s, "using cached pos_max=0x%"PRIx64" pos_limit=0x%"PRIx64" dts_max=%"PRId64"\n", ++ pos_max,pos_limit, ts_max); + } + } + +- pos= av_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp); ++ pos= ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, pos_limit, ts_min, ts_max, flags, &ts, avif->read_timestamp); + if(pos<0) + return -1; + + /* do the seek */ +- if ((ret = url_fseek(s->pb, pos, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, pos, SEEK_SET)) < 0) + return ret; + +- av_update_cur_dts(s, st, ts); ++ ff_read_frame_flush(s); ++ ff_update_cur_dts(s, st, ts); + + return 0; + } + +-int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, int64_t pos_min, int64_t pos_max, int64_t pos_limit, int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )){ ++#if FF_API_SEEK_PUBLIC ++int64_t av_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, ++ int64_t pos_min, int64_t pos_max, int64_t pos_limit, ++ int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, ++ int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) ++{ ++ return ff_gen_search(s, stream_index, target_ts, pos_min, pos_max, ++ pos_limit, ts_min, ts_max, flags, ts_ret, ++ read_timestamp); ++} ++#endif ++ ++int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, ++ int64_t pos_min, int64_t pos_max, int64_t pos_limit, ++ int64_t ts_min, int64_t ts_max, int flags, int64_t *ts_ret, ++ int64_t (*read_timestamp)(struct AVFormatContext *, int , int64_t *, int64_t )) ++{ + int64_t pos, ts; + int64_t start_pos, filesize; + int no_change; + +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "gen_seek: %d %"PRId64"\n", stream_index, target_ts); +-#endif ++ av_dlog(s, "gen_seek: %d %"PRId64"\n", stream_index, target_ts); + + if(ts_min == AV_NOPTS_VALUE){ + pos_min = s->data_offset; +@@ -1536,9 +1694,14 @@ + return -1; + } + ++ if(ts_min >= target_ts){ ++ *ts_ret= ts_min; ++ return pos_min; ++ } ++ + if(ts_max == AV_NOPTS_VALUE){ + int step= 1024; +- filesize = url_fsize(s->pb); ++ filesize = avio_size(s->pb); + pos_max = filesize - 1; + do{ + pos_max -= step; +@@ -1561,6 +1724,11 @@ + pos_limit= pos_max; + } + ++ if(ts_max <= target_ts){ ++ *ts_ret= ts_max; ++ return pos_max; ++ } ++ + if(ts_min > ts_max){ + return -1; + }else if(ts_min == ts_max){ +@@ -1569,11 +1737,8 @@ + + no_change=0; + while (pos_min < pos_limit) { +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n", +- pos_min, pos_max, +- ts_min, ts_max); +-#endif ++ av_dlog(s, "pos_min=0x%"PRIx64" pos_max=0x%"PRIx64" dts_min=%"PRId64" dts_max=%"PRId64"\n", ++ pos_min, pos_max, ts_min, ts_max); + assert(pos_limit <= pos_max); + + if(no_change==0){ +@@ -1600,11 +1765,9 @@ + no_change++; + else + no_change=0; +-#ifdef DEBUG_SEEK +- av_log(s, AV_LOG_DEBUG, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", +- pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, pos_limit, +- start_pos, no_change); +-#endif ++ av_dlog(s, "%"PRId64" %"PRId64" %"PRId64" / %"PRId64" %"PRId64" %"PRId64" target:%"PRId64" limit:%"PRId64" start:%"PRId64" noc:%d\n", ++ pos_min, pos, pos_max, ts_min, ts, ts_max, target_ts, ++ pos_limit, start_pos, no_change); + if(ts == AV_NOPTS_VALUE){ + av_log(s, AV_LOG_ERROR, "read_timestamp() failed in the middle\n"); + return -1; +@@ -1623,19 +1786,19 @@ + + pos = (flags & AVSEEK_FLAG_BACKWARD) ? pos_min : pos_max; + ts = (flags & AVSEEK_FLAG_BACKWARD) ? ts_min : ts_max; +-#ifdef DEBUG_SEEK ++#if 0 + pos_min = pos; + ts_min = read_timestamp(s, stream_index, &pos_min, INT64_MAX); + pos_min++; + ts_max = read_timestamp(s, stream_index, &pos_min, INT64_MAX); +- av_log(s, AV_LOG_DEBUG, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n", +- pos, ts_min, target_ts, ts_max); ++ av_dlog(s, "pos=0x%"PRIx64" %"PRId64"<=%"PRId64"<=%"PRId64"\n", ++ pos, ts_min, target_ts, ts_max); + #endif + *ts_ret= ts; + return pos; + } + +-static int av_seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){ ++static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){ + int64_t pos_min, pos_max; + #if 0 + AVStream *st; +@@ -1647,12 +1810,12 @@ + #endif + + pos_min = s->data_offset; +- pos_max = url_fsize(s->pb) - 1; ++ pos_max = avio_size(s->pb) - 1; + + if (pos < pos_min) pos= pos_min; + else if(pos > pos_max) pos= pos_max; + +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + + #if 0 + av_update_cur_dts(s, st, ts); +@@ -1660,7 +1823,7 @@ + return 0; + } + +-static int av_seek_frame_generic(AVFormatContext *s, ++static int seek_frame_generic(AVFormatContext *s, + int stream_index, int64_t timestamp, int flags) + { + int index; +@@ -1676,30 +1839,34 @@ + return -1; + + if(index < 0 || index==st->nb_index_entries-1){ +- int i; + AVPacket pkt; ++ int nonkey=0; + + if(st->nb_index_entries){ + assert(st->index_entries); + ie= &st->index_entries[st->nb_index_entries-1]; +- if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) + return ret; +- av_update_cur_dts(s, st, ie->timestamp); ++ ff_update_cur_dts(s, st, ie->timestamp); + }else{ +- if ((ret = url_fseek(s->pb, s->data_offset, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, s->data_offset, SEEK_SET)) < 0) + return ret; + } +- for(i=0;; i++) { +- int ret; ++ for (;;) { ++ int read_status; + do{ +- ret = av_read_frame(s, &pkt); +- }while(ret == AVERROR(EAGAIN)); +- if(ret<0) ++ read_status = av_read_frame(s, &pkt); ++ } while (read_status == AVERROR(EAGAIN)); ++ if (read_status < 0) + break; + av_free_packet(&pkt); +- if(stream_index == pkt.stream_index){ +- if((pkt.flags & AV_PKT_FLAG_KEY) && pkt.dts > timestamp) ++ if(stream_index == pkt.stream_index && pkt.dts > timestamp){ ++ if(pkt.flags & AV_PKT_FLAG_KEY) + break; ++ if(nonkey++ > 1000 && st->codec->codec_id != CODEC_ID_CDGRAPHICS){ ++ av_log(s, AV_LOG_ERROR,"seek_frame_generic failed as this stream seems to contain no keyframes after the target timestamp, %d non keyframes found\n", nonkey); ++ break; ++ } + } + } + index = av_index_search_timestamp(st, timestamp, flags); +@@ -1708,14 +1875,16 @@ + return -1; + + ff_read_frame_flush(s); ++ AV_NOWARN_DEPRECATED( + if (s->iformat->read_seek){ + if(s->iformat->read_seek(s, stream_index, timestamp, flags) >= 0) + return 0; + } ++ ) + ie = &st->index_entries[index]; +- if ((ret = url_fseek(s->pb, ie->pos, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, ie->pos, SEEK_SET)) < 0) + return ret; +- av_update_cur_dts(s, st, ie->timestamp); ++ ff_update_cur_dts(s, st, ie->timestamp); + + return 0; + } +@@ -1725,10 +1894,12 @@ + int ret; + AVStream *st; + +- ff_read_frame_flush(s); +- +- if(flags & AVSEEK_FLAG_BYTE) +- return av_seek_frame_byte(s, stream_index, timestamp, flags); ++ if (flags & AVSEEK_FLAG_BYTE) { ++ if (s->iformat->flags & AVFMT_NO_BYTE_SEEK) ++ return -1; ++ ff_read_frame_flush(s); ++ return seek_frame_byte(s, stream_index, timestamp, flags); ++ } + + if(stream_index < 0){ + stream_index= av_find_default_stream_index(s); +@@ -1736,23 +1907,33 @@ + return -1; + + st= s->streams[stream_index]; +- /* timestamp for default must be expressed in AV_TIME_BASE units */ ++ /* timestamp for default must be expressed in AV_TIME_BASE units */ + timestamp = av_rescale(timestamp, st->time_base.den, AV_TIME_BASE * (int64_t)st->time_base.num); + } + + /* first, we try the format specific seek */ +- if (s->iformat->read_seek) ++ AV_NOWARN_DEPRECATED( ++ if (s->iformat->read_seek) { ++ ff_read_frame_flush(s); + ret = s->iformat->read_seek(s, stream_index, timestamp, flags); +- else +- ret = -1; ++ } else ++ ret = AVERROR(ENOSYS); ++ ) + if (ret >= 0) { + return 0; + } ++ if (ret != AVERROR(ENOSYS)) ++ return ret; + +- if(s->iformat->read_timestamp) +- return av_seek_frame_binary(s, stream_index, timestamp, flags); ++ if (s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) { ++ ff_read_frame_flush(s); ++ return ff_seek_frame_binary(s, stream_index, timestamp, flags); ++ } else if (!(s->iformat->flags & AVFMT_NOGENSEARCH)) { ++ ff_read_frame_flush(s); ++ return seek_frame_generic(s, stream_index, timestamp, flags); ++ } + else +- return av_seek_frame_generic(s, stream_index, timestamp, flags); ++ return -1; + } + + int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) +@@ -1760,10 +1941,10 @@ + if(min_ts > ts || max_ts < ts) + return -1; + +- ff_read_frame_flush(s); +- +- if (s->iformat->read_seek2) ++ if (s->iformat->read_seek2) { ++ ff_read_frame_flush(s); + return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); ++ } + + if(s->iformat->read_timestamp){ + //try to seek via read_timestamp() +@@ -1771,10 +1952,12 @@ + + //Fallback to old API if new is not implemented but old is + //Note the old has somewat different sematics ++ AV_NOWARN_DEPRECATED( + if(s->iformat->read_seek || 1) + return av_seek_frame(s, stream_index, ts, flags | (ts - min_ts > (uint64_t)(max_ts - ts) ? AVSEEK_FLAG_BACKWARD : 0)); ++ ) + +- // try some generic seek like av_seek_frame_generic() but with new ts semantics ++ // try some generic seek like seek_frame_generic() but with new ts semantics + } + + /*******************************************************/ +@@ -1784,7 +1967,7 @@ + * + * @return TRUE if the stream has accurate duration for at least one component. + */ +-static int av_has_duration(AVFormatContext *ic) ++static int has_duration(AVFormatContext *ic) + { + int i; + AVStream *st; +@@ -1804,48 +1987,50 @@ + * + * Also computes the global bitrate if possible. + */ +-static void av_update_stream_timings(AVFormatContext *ic) ++static void update_stream_timings(AVFormatContext *ic) + { +- int64_t start_time, start_time1, end_time, end_time1; +- int64_t duration, duration1; ++ int64_t start_time, start_time1, start_time_text, end_time, end_time1; ++ int64_t duration, duration1, filesize; + int i; + AVStream *st; + + start_time = INT64_MAX; ++ start_time_text = INT64_MAX; + end_time = INT64_MIN; + duration = INT64_MIN; + for(i = 0;i < ic->nb_streams; i++) { + st = ic->streams[i]; + if (st->start_time != AV_NOPTS_VALUE && st->time_base.den) { + start_time1= av_rescale_q(st->start_time, st->time_base, AV_TIME_BASE_Q); +- if (start_time1 < start_time) +- start_time = start_time1; ++ if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { ++ if (start_time1 < start_time_text) ++ start_time_text = start_time1; ++ } else ++ start_time = FFMIN(start_time, start_time1); + if (st->duration != AV_NOPTS_VALUE) { + end_time1 = start_time1 + + av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q); +- if (end_time1 > end_time) +- end_time = end_time1; ++ end_time = FFMAX(end_time, end_time1); + } + } + if (st->duration != AV_NOPTS_VALUE) { + duration1 = av_rescale_q(st->duration, st->time_base, AV_TIME_BASE_Q); +- if (duration1 > duration) +- duration = duration1; ++ duration = FFMAX(duration, duration1); + } + } ++ if (start_time == INT64_MAX || (start_time > start_time_text && start_time - start_time_text < AV_TIME_BASE)) ++ start_time = start_time_text; + if (start_time != INT64_MAX) { + ic->start_time = start_time; +- if (end_time != INT64_MIN) { +- if (end_time - start_time > duration) +- duration = end_time - start_time; +- } ++ if (end_time != INT64_MIN) ++ duration = FFMAX(duration, end_time - start_time); + } + if (duration != INT64_MIN && ic->duration == AV_NOPTS_VALUE) { + ic->duration = duration; + } +- if (ic->file_size > 0 && ic->duration != AV_NOPTS_VALUE) { ++ if (ic->pb && (filesize = avio_size(ic->pb)) > 0 && ic->duration != AV_NOPTS_VALUE) { + /* compute the bitrate */ +- ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / ++ ic->bit_rate = (double)filesize * 8.0 * AV_TIME_BASE / + (double)ic->duration; + } + } +@@ -1855,7 +2040,7 @@ + int i; + AVStream *st; + +- av_update_stream_timings(ic); ++ update_stream_timings(ic); + for(i = 0;i < ic->nb_streams; i++) { + st = ic->streams[i]; + if (st->start_time == AV_NOPTS_VALUE) { +@@ -1867,7 +2052,7 @@ + } + } + +-static void av_estimate_timings_from_bit_rate(AVFormatContext *ic) ++static void estimate_timings_from_bit_rate(AVFormatContext *ic) + { + int64_t filesize, duration; + int bit_rate, i; +@@ -1886,9 +2071,8 @@ + + /* if duration is already set, we believe it */ + if (ic->duration == AV_NOPTS_VALUE && +- ic->bit_rate != 0 && +- ic->file_size != 0) { +- filesize = ic->file_size; ++ ic->bit_rate != 0) { ++ filesize = ic->pb ? avio_size(ic->pb) : 0; + if (filesize > 0) { + for(i = 0; i < ic->nb_streams; i++) { + st = ic->streams[i]; +@@ -1903,28 +2087,63 @@ + #define DURATION_MAX_READ_SIZE 250000 + #define DURATION_MAX_RETRY 3 + +-/* only usable for MPEG-PS streams */ +-static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ++static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset) + { +- AVPacket pkt1, *pkt = &pkt1; + AVStream *st; +- int read_size, i, ret; +- int64_t end_time; +- int64_t filesize, offset, duration; +- int retry=0; +- +- ic->cur_st = NULL; +- +- /* flush packet queue */ +- flush_packet_queue(ic); ++ int i, step= 1024; ++ int64_t ts, pos; + +- for (i=0; inb_streams; i++) { ++ for(i=0;inb_streams;i++) { + st = ic->streams[i]; +- if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE) +- av_log(st->codec, AV_LOG_WARNING, "start time is not set in av_estimate_timings_from_pts\n"); + +- if (st->parser) { +- av_parser_close(st->parser); ++ pos = 0; ++ ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE); ++ if (ts == AV_NOPTS_VALUE) ++ continue; ++ if (st->start_time > ts || st->start_time == AV_NOPTS_VALUE) ++ st->start_time = ts; ++ ++ pos = url_fsize(ic->pb) - 1; ++ do { ++ pos -= step; ++ ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step); ++ step += step; ++ } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE); ++ ++ if (ts == AV_NOPTS_VALUE) ++ continue; ++ ++ if (st->duration < ts - st->start_time || st->duration == AV_NOPTS_VALUE) ++ st->duration = ts - st->start_time; ++ } ++ ++ fill_all_stream_timings(ic); ++ ++ avio_seek(ic->pb, old_offset, SEEK_SET); ++} ++ ++/* only usable for MPEG-PS streams */ ++static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ++{ ++ AVPacket pkt1, *pkt = &pkt1; ++ AVStream *st; ++ int read_size, i, ret; ++ int64_t end_time; ++ int64_t filesize, offset, duration; ++ int retry=0; ++ ++ ic->cur_st = NULL; ++ ++ /* flush packet queue */ ++ flush_packet_queue(ic); ++ ++ for (i=0; inb_streams; i++) { ++ st = ic->streams[i]; ++ if (st->start_time == AV_NOPTS_VALUE && st->first_dts == AV_NOPTS_VALUE) ++ av_log(st->codec, AV_LOG_WARNING, "start time is not set in estimate_timings_from_pts\n"); ++ ++ if (st->parser) { ++ av_parser_close(st->parser); + st->parser= NULL; + av_free_packet(&st->cur_pkt); + } +@@ -1932,94 +2151,59 @@ + + /* estimate the end time (duration) */ + /* XXX: may need to support wrapping */ +- filesize = ic->file_size; ++ filesize = ic->pb ? avio_size(ic->pb) : 0; + end_time = AV_NOPTS_VALUE; + do{ +- offset = filesize - (DURATION_MAX_READ_SIZE<pb, offset, SEEK_SET); +- read_size = 0; +- for(;;) { +- if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0))) +- break; ++ avio_seek(ic->pb, offset, SEEK_SET); ++ read_size = 0; ++ for(;;) { ++ if (read_size >= DURATION_MAX_READ_SIZE<<(FFMAX(retry-1,0))) ++ break; + +- do{ +- ret = av_read_packet(ic, pkt); +- }while(ret == AVERROR(EAGAIN)); +- if (ret != 0) +- break; +- read_size += pkt->size; +- st = ic->streams[pkt->stream_index]; +- if (pkt->pts != AV_NOPTS_VALUE && +- (st->start_time != AV_NOPTS_VALUE || +- st->first_dts != AV_NOPTS_VALUE)) { +- duration = end_time = pkt->pts; +- if (st->start_time != AV_NOPTS_VALUE) duration -= st->start_time; +- else duration -= st->first_dts; +- if (duration < 0) +- duration += 1LL<pts_wrap_bits; +- if (duration > 0) { +- if (st->duration == AV_NOPTS_VALUE || +- st->duration < duration) +- st->duration = duration; ++ do { ++ ret = av_read_packet(ic, pkt); ++ } while(ret == AVERROR(EAGAIN)); ++ if (ret != 0) ++ break; ++ read_size += pkt->size; ++ st = ic->streams[pkt->stream_index]; ++ if (pkt->pts != AV_NOPTS_VALUE && ++ (st->start_time != AV_NOPTS_VALUE || ++ st->first_dts != AV_NOPTS_VALUE)) { ++ duration = end_time = pkt->pts; ++ if (st->start_time != AV_NOPTS_VALUE) ++ duration -= st->start_time; ++ else ++ duration -= st->first_dts; ++ if (duration < 0) ++ duration += 1LL<pts_wrap_bits; ++ if (duration > 0) { ++ if (st->duration == AV_NOPTS_VALUE || st->duration < duration) ++ st->duration = duration; ++ } + } ++ av_free_packet(pkt); + } +- av_free_packet(pkt); +- } + }while( end_time==AV_NOPTS_VALUE + && filesize > (DURATION_MAX_READ_SIZE<pb, old_offset, SEEK_SET); ++ avio_seek(ic->pb, old_offset, SEEK_SET); + for (i=0; inb_streams; i++) { + st= ic->streams[i]; + st->cur_dts= st->first_dts; + st->last_IP_pts = AV_NOPTS_VALUE; ++ st->reference_dts = AV_NOPTS_VALUE; + } + } + +-static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset) +-{ +- AVStream *st; +- int i, step= 1024; +- int64_t ts, pos; +- +- for(i=0;inb_streams;i++) { +- st = ic->streams[i]; +- +- pos = 0; +- ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE); +- if (ts == AV_NOPTS_VALUE) +- continue; +- if (st->start_time == AV_NOPTS_VALUE || +- st->start_time > ts) +- st->start_time = ts; +- +- pos = url_fsize(ic->pb) - 1; +- do { +- pos -= step; +- ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step); +- step += step; +- } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE); +- +- if (ts == AV_NOPTS_VALUE) +- continue; +- +- if (st->duration == AV_NOPTS_VALUE +- || st->duration < ts - st->start_time) +- st->duration = ts - st->start_time; +- } +- +- fill_all_stream_timings(ic); +- +- url_fseek(ic->pb, old_offset, SEEK_SET); +-} +- +-static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset) ++static void estimate_timings(AVFormatContext *ic, int64_t old_offset) + { + int64_t file_size; + +@@ -2027,118 +2211,134 @@ + if (ic->iformat->flags & AVFMT_NOFILE) { + file_size = 0; + } else { +- file_size = url_fsize(ic->pb); +- if (file_size < 0) +- file_size = 0; ++ file_size = avio_size(ic->pb); ++ file_size = FFMAX(0, file_size); + } +- ic->file_size = file_size; + + if ((!strcmp(ic->iformat->name, "mpeg") || + !strcmp(ic->iformat->name, "mpegts")) && +- file_size && !url_is_streamed(ic->pb)) { ++ file_size && ic->pb->seekable) { + /* get accurate estimate from the PTSes */ +- av_estimate_timings_from_pts(ic, old_offset); +- } else if (av_has_duration(ic)) { ++ estimate_timings_from_pts(ic, old_offset); ++ } else if (has_duration(ic)) { + /* at least one component has timings - we use them for all + the components */ + fill_all_stream_timings(ic); + } else if (ic->iformat->read_timestamp && +- file_size && !url_is_streamed(ic->pb)) { ++ file_size && ic->pb->seekable) { + /* get accurate estimate from the PTSes */ + av_estimate_timings_from_pts2(ic, old_offset); + } else { + av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\n"); + /* less precise: use bitrate info */ +- av_estimate_timings_from_bit_rate(ic); ++ estimate_timings_from_bit_rate(ic); + } +- av_update_stream_timings(ic); ++ update_stream_timings(ic); + +-#if 0 + { + int i; +- AVStream *st; ++ AVStream av_unused *st; + for(i = 0;i < ic->nb_streams; i++) { + st = ic->streams[i]; +- printf("%d: start_time: %0.3f duration: %0.3f\n", +- i, (double)st->start_time / AV_TIME_BASE, +- (double)st->duration / AV_TIME_BASE); ++ av_dlog(ic, "%d: start_time: %0.3f duration: %0.3f\n", i, ++ (double) st->start_time / AV_TIME_BASE, ++ (double) st->duration / AV_TIME_BASE); + } +- printf("stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n", +- (double)ic->start_time / AV_TIME_BASE, +- (double)ic->duration / AV_TIME_BASE, +- ic->bit_rate / 1000); ++ av_dlog(ic, "stream: start_time: %0.3f duration: %0.3f bitrate=%d kb/s\n", ++ (double) ic->start_time / AV_TIME_BASE, ++ (double) ic->duration / AV_TIME_BASE, ++ ic->bit_rate / 1000); + } +-#endif + } + +-static int has_codec_parameters(AVCodecContext *enc) ++static int has_codec_parameters(AVCodecContext *avctx) + { + int val; +- switch(enc->codec_type) { ++ switch (avctx->codec_type) { + case AVMEDIA_TYPE_AUDIO: +- val = enc->sample_rate && enc->channels && enc->sample_fmt != AV_SAMPLE_FMT_NONE; +- if(!enc->frame_size && +- (enc->codec_id == CODEC_ID_VORBIS || +- enc->codec_id == CODEC_ID_AAC || +- enc->codec_id == CODEC_ID_MP1 || +- enc->codec_id == CODEC_ID_MP2 || +- enc->codec_id == CODEC_ID_MP3 || +- enc->codec_id == CODEC_ID_SPEEX)) ++ val = avctx->sample_rate && avctx->channels && avctx->sample_fmt != AV_SAMPLE_FMT_NONE; ++ if (!avctx->frame_size && ++ (avctx->codec_id == CODEC_ID_VORBIS || ++ avctx->codec_id == CODEC_ID_AAC || ++ avctx->codec_id == CODEC_ID_MP1 || ++ avctx->codec_id == CODEC_ID_MP2 || ++ avctx->codec_id == CODEC_ID_MP3 || ++ avctx->codec_id == CODEC_ID_CELT)) + return 0; + break; + case AVMEDIA_TYPE_VIDEO: +- val = enc->width && enc->pix_fmt != PIX_FMT_NONE; ++ val = avctx->width && avctx->pix_fmt != PIX_FMT_NONE; + break; ++ case AVMEDIA_TYPE_DATA: ++ if(avctx->codec_id == CODEC_ID_NONE) return 1; + default: + val = 1; + break; + } +- return enc->codec_id != CODEC_ID_PROBE && val != 0; ++ return avctx->codec_id != CODEC_ID_NONE && val != 0; + } + + static int has_decode_delay_been_guessed(AVStream *st) + { + return st->codec->codec_id != CODEC_ID_H264 || +- st->codec_info_nb_frames >= 6 + st->codec->has_b_frames; ++ st->info->nb_decoded_frames >= 6; + } + +-static int try_decode_frame(AVStream *st, AVPacket *avpkt) ++/* returns 1 or 0 if or if not decoded data was returned, or a negative error */ ++static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **options) + { +- int16_t *samples; + AVCodec *codec; +- int got_picture, data_size, ret=0; ++ int got_picture = 1, ret = 0; + AVFrame picture; ++ AVPacket pkt = *avpkt; ++ ++ if (!avcodec_is_open(st->codec)) { ++ AVDictionary *thread_opt = NULL; ++ ++ codec = st->codec->codec ? st->codec->codec : ++ avcodec_find_decoder(st->codec->codec_id); + +- if(!st->codec->codec){ +- codec = avcodec_find_decoder(st->codec->codec_id); + if (!codec) + return -1; +- ret = avcodec_open(st->codec, codec); ++ ++ /* force thread count to 1 since the h264 decoder will not extract SPS ++ * and PPS to extradata during multi-threaded decoding */ ++ av_dict_set(options ? options : &thread_opt, "threads", "1", 0); ++ ret = avcodec_open2(st->codec, codec, options ? options : &thread_opt); ++ if (!options) ++ av_dict_free(&thread_opt); + if (ret < 0) + return ret; + } + +- if(!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)){ ++ while ((pkt.size > 0 || (!pkt.data && got_picture)) && ++ ret >= 0 && ++ (!has_codec_parameters(st->codec) || ++ !has_decode_delay_been_guessed(st) || ++ (!st->codec_info_nb_frames && st->codec->codec->capabilities & CODEC_CAP_CHANNEL_CONF))) { ++ got_picture = 0; ++ avcodec_get_frame_defaults(&picture); + switch(st->codec->codec_type) { + case AVMEDIA_TYPE_VIDEO: +- avcodec_get_frame_defaults(&picture); + ret = avcodec_decode_video2(st->codec, &picture, +- &got_picture, avpkt); ++ &got_picture, &pkt); + break; + case AVMEDIA_TYPE_AUDIO: +- data_size = FFMAX(avpkt->size, AVCODEC_MAX_AUDIO_FRAME_SIZE); +- samples = av_malloc(data_size); +- if (!samples) +- goto fail; +- ret = avcodec_decode_audio3(st->codec, samples, +- &data_size, avpkt); +- av_free(samples); ++ ret = avcodec_decode_audio4(st->codec, &picture, &got_picture, &pkt); + break; + default: + break; + } ++ if (ret >= 0) { ++ if (got_picture) ++ st->info->nb_decoded_frames++; ++ pkt.data += ret; ++ pkt.size -= ret; ++ ret = got_picture; ++ } + } +- fail: ++ if(!pkt.data && !got_picture) ++ return -1; + return ret; + } + +@@ -2160,7 +2360,7 @@ + return tags[i].id; + } + for(i=0; tags[i].id != CODEC_ID_NONE; i++) { +- if (ff_toupper4(tag) == ff_toupper4(tags[i].tag)) ++ if (avpriv_toupper4(tag) == avpriv_toupper4(tags[i].tag)) + return tags[i].id; + } + return CODEC_ID_NONE; +@@ -2188,22 +2388,23 @@ + + static void compute_chapters_end(AVFormatContext *s) + { +- unsigned int i; ++ unsigned int i, j; ++ int64_t max_time = s->duration + ((s->start_time == AV_NOPTS_VALUE) ? 0 : s->start_time); + +- for (i=0; i+1nb_chapters; i++) ++ for (i = 0; i < s->nb_chapters; i++) + if (s->chapters[i]->end == AV_NOPTS_VALUE) { +- assert(s->chapters[i]->start <= s->chapters[i+1]->start); +- assert(!av_cmp_q(s->chapters[i]->time_base, s->chapters[i+1]->time_base)); +- s->chapters[i]->end = s->chapters[i+1]->start; ++ AVChapter *ch = s->chapters[i]; ++ int64_t end = max_time ? av_rescale_q(max_time, AV_TIME_BASE_Q, ch->time_base) ++ : INT64_MAX; ++ ++ for (j = 0; j < s->nb_chapters; j++) { ++ AVChapter *ch1 = s->chapters[j]; ++ int64_t next_start = av_rescale_q(ch1->start, ch1->time_base, ch->time_base); ++ if (j != i && next_start > ch->start && next_start < end) ++ end = next_start; ++ } ++ ch->end = (end == INT64_MAX) ? ch->start : end; + } +- +- if (s->nb_chapters && s->chapters[i]->end == AV_NOPTS_VALUE) { +- assert(s->start_time != AV_NOPTS_VALUE); +- assert(s->duration > 0); +- s->chapters[i]->end = av_rescale_q(s->start_time + s->duration, +- AV_TIME_BASE_Q, +- s->chapters[i]->time_base); +- } + } + + static int get_std_framerate(int i){ +@@ -2231,21 +2432,27 @@ + return 0; + } + ++#if FF_API_FORMAT_PARAMETERS + int av_find_stream_info(AVFormatContext *ic) + { ++ return avformat_find_stream_info(ic, NULL); ++} ++#endif ++ ++int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) ++{ + int i, count, ret, read_size, j; + AVStream *st; + AVPacket pkt1, *pkt; +- int64_t old_offset = url_ftell(ic->pb); ++ int64_t old_offset = avio_tell(ic->pb); ++ int orig_nb_streams = ic->nb_streams; // new streams might appear, no options for those ++ int flush_codecs = 1; + + for(i=0;inb_streams;i++) { + AVCodec *codec; ++ AVDictionary *thread_opt = NULL; + st = ic->streams[i]; +- if (st->codec->codec_id == CODEC_ID_AAC) { +- st->codec->sample_rate = 0; +- st->codec->frame_size = 0; +- st->codec->channels = 0; +- } ++ + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || + st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { + /* if(!st->time_base.num) +@@ -2260,26 +2467,27 @@ + st->parser->flags |= PARSER_FLAG_COMPLETE_FRAMES; + } + } +- assert(!st->codec->codec); +- codec = avcodec_find_decoder(st->codec->codec_id); ++ codec = st->codec->codec ? st->codec->codec : ++ avcodec_find_decoder(st->codec->codec_id); + +- /* Force decoding of at least one frame of codec data +- * this makes sure the codec initializes the channel configuration +- * and does not trust the values from the container. +- */ +- if (codec && codec->capabilities & CODEC_CAP_CHANNEL_CONF) +- st->codec->channels = 0; ++ /* force thread count to 1 since the h264 decoder will not extract SPS ++ * and PPS to extradata during multi-threaded decoding */ ++ av_dict_set(options ? &options[i] : &thread_opt, "threads", "1", 0); + + /* Ensure that subtitle_header is properly set. */ + if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE + && codec && !st->codec->codec) +- avcodec_open(st->codec, codec); ++ avcodec_open2(st->codec, codec, options ? &options[i] ++ : &thread_opt); + + //try to just open decoders, in case this is enough to get parameters + if(!has_codec_parameters(st->codec)){ + if (codec && !st->codec->codec) +- avcodec_open(st->codec, codec); ++ avcodec_open2(st->codec, codec, options ? &options[i] ++ : &thread_opt); + } ++ if (!options) ++ av_dict_free(&thread_opt); + } + + for (i=0; inb_streams; i++) { +@@ -2289,20 +2497,30 @@ + count = 0; + read_size = 0; + for(;;) { +- if(url_interrupt_cb()){ +- ret= AVERROR(EINTR); ++ if (ff_check_interrupt(&ic->interrupt_callback)){ ++ ret= AVERROR_EXIT; + av_log(ic, AV_LOG_DEBUG, "interrupted\n"); + break; + } + + /* check if one codec still needs to be handled */ + for(i=0;inb_streams;i++) { ++ int fps_analyze_framecount = 20; ++ + st = ic->streams[i]; + if (!has_codec_parameters(st->codec)) + break; ++ /* if the timebase is coarse (like the usual millisecond precision ++ of mkv), we need to analyze more frames to reliably arrive at ++ the correct fps */ ++ if (av_q2d(st->time_base) > 0.0005) ++ fps_analyze_framecount *= 2; ++ if (ic->fps_probe_size >= 0) ++ fps_analyze_framecount = ic->fps_probe_size; + /* variable fps and no guess at the real fps */ + if( tb_unreliable(st->codec) && !(st->r_frame_rate.num && st->avg_frame_rate.num) +- && st->info->duration_count<20 && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) ++ && st->info->duration_count < fps_analyze_framecount ++ && st->codec->codec_type == AVMEDIA_TYPE_VIDEO) + break; + if(st->parser && st->parser->parser->split && !st->codec->extradata) + break; +@@ -2317,6 +2535,7 @@ + /* if we found the info for all the codecs, we can stop */ + ret = count; + av_log(ic, AV_LOG_DEBUG, "All info found\n"); ++ flush_codecs = 0; + break; + } + } +@@ -2329,26 +2548,15 @@ + + /* NOTE: a new stream can be added there if no header in file + (AVFMTCTX_NOHEADER) */ +- ret = av_read_frame_internal(ic, &pkt1); +- if (ret < 0 && ret != AVERROR(EAGAIN)) { +- /* EOF or error */ +- ret = -1; /* we could not have all the codec parameters before EOF */ +- for(i=0;inb_streams;i++) { +- st = ic->streams[i]; +- if (!has_codec_parameters(st->codec)){ +- char buf[256]; +- avcodec_string(buf, sizeof(buf), st->codec, 0); +- av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf); +- } else { +- ret = 0; +- } +- } +- break; +- } +- ++ ret = read_frame_internal(ic, &pkt1); + if (ret == AVERROR(EAGAIN)) + continue; + ++ if (ret < 0) { ++ /* EOF or error*/ ++ break; ++ } ++ + pkt= add_to_pktbuf(&ic->packet_buffer, &pkt1, &ic->packet_buffer_end); + if ((ret = av_dup_packet(pkt)) < 0) + goto find_stream_info_err; +@@ -2357,28 +2565,36 @@ + + st = ic->streams[pkt->stream_index]; + if (st->codec_info_nb_frames>1) { +- if (st->time_base.den > 0 && av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q) >= ic->max_analyze_duration) { +- av_log(ic, AV_LOG_WARNING, "max_analyze_duration reached\n"); ++ int64_t t=0; ++ if (st->time_base.den > 0) ++ t = av_rescale_q(st->info->codec_info_duration, st->time_base, AV_TIME_BASE_Q); ++ if (st->avg_frame_rate.num > 0) ++ t = FFMAX(t, av_rescale_q(st->codec_info_nb_frames, (AVRational){st->avg_frame_rate.den, st->avg_frame_rate.num}, AV_TIME_BASE_Q)); ++ ++ if (t >= ic->max_analyze_duration) { ++ av_log(ic, AV_LOG_WARNING, "max_analyze_duration %d reached at %"PRId64"\n", ic->max_analyze_duration, t); + break; + } + st->info->codec_info_duration += pkt->duration; + } + { + int64_t last = st->info->last_dts; +- int64_t duration= pkt->dts - last; +- +- if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && duration>0){ +- double dur= duration * av_q2d(st->time_base); + +-// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) +-// av_log(NULL, AV_LOG_ERROR, "%f\n", dur); +- if (st->info->duration_count < 2) +- memset(st->info->duration_error, 0, sizeof(st->info->duration_error)); +- for (i=1; iinfo->duration_error); i++) { ++ if(pkt->dts != AV_NOPTS_VALUE && last != AV_NOPTS_VALUE && pkt->dts > last){ ++ double dts= pkt->dts * av_q2d(st->time_base); ++ int64_t duration= pkt->dts - last; ++ ++// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) ++// av_log(NULL, AV_LOG_ERROR, "%f\n", dts); ++ for (i=1; iinfo->duration_error[0][0]); i++) { + int framerate= get_std_framerate(i); +- int ticks= lrintf(dur*framerate/(1001*12)); +- double error= dur - ticks*1001*12/(double)framerate; +- st->info->duration_error[i] += error*error; ++ double sdts= dts*framerate/(1001*12); ++ for(j=0; j<2; j++){ ++ int ticks= lrintf(sdts+j*0.5); ++ double error= sdts - ticks + j*0.5; ++ st->info->duration_error[j][0][i] += error; ++ st->info->duration_error[j][1][i] += error*error; ++ } + } + st->info->duration_count++; + // ignore the first 4 values, they might have some random jitter +@@ -2390,9 +2606,11 @@ + } + if(st->parser && st->parser->parser->split && !st->codec->extradata){ + int i= st->parser->parser->split(st->codec, pkt->data, pkt->size); +- if(i){ ++ if (i > 0 && i < FF_MAX_EXTRADATA_SIZE) { + st->codec->extradata_size= i; + st->codec->extradata= av_malloc(st->codec->extradata_size + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); + memcpy(st->codec->extradata, pkt->data, st->codec->extradata_size); + memset(st->codec->extradata + i, 0, FF_INPUT_BUFFER_PADDING_SIZE); + } +@@ -2401,19 +2619,52 @@ + /* if still no information, we try to open the codec and to + decompress the frame. We try to avoid that in most cases as + it takes longer and uses more memory. For MPEG-4, we need to +- decompress for QuickTime. */ +- if (!has_codec_parameters(st->codec) || !has_decode_delay_been_guessed(st)) +- try_decode_frame(st, pkt); ++ decompress for QuickTime. ++ ++ If CODEC_CAP_CHANNEL_CONF is set this will force decoding of at ++ least one frame of codec data, this makes sure the codec initializes ++ the channel configuration and does not only trust the values from the container. ++ */ ++ try_decode_frame(st, pkt, (options && i < orig_nb_streams ) ? &options[i] : NULL); + + st->codec_info_nb_frames++; + count++; + } + ++ if (flush_codecs) { ++ AVPacket empty_pkt = { 0 }; ++ int err; ++ av_init_packet(&empty_pkt); ++ ++ ret = -1; /* we could not have all the codec parameters before EOF */ ++ for(i=0;inb_streams;i++) { ++ st = ic->streams[i]; ++ ++ /* flush the decoders */ ++ do { ++ err = try_decode_frame(st, &empty_pkt, ++ (options && i < orig_nb_streams) ? ++ &options[i] : NULL); ++ } while (err > 0 && !has_codec_parameters(st->codec)); ++ ++ if (err < 0) { ++ av_log(ic, AV_LOG_WARNING, ++ "decoding for stream %d failed\n", st->index); ++ } ++ if (!has_codec_parameters(st->codec)){ ++ char buf[256]; ++ avcodec_string(buf, sizeof(buf), st->codec, 0); ++ av_log(ic, AV_LOG_WARNING, "Could not find codec parameters (%s)\n", buf); ++ } else { ++ ret = 0; ++ } ++ } ++ } ++ + // close codecs which were opened in try_decode_frame() + for(i=0;inb_streams;i++) { + st = ic->streams[i]; +- if(st->codec->codec) +- avcodec_close(st->codec); ++ avcodec_close(st->codec); + } + for(i=0;inb_streams;i++) { + st = ic->streams[i]; +@@ -2422,29 +2673,42 @@ + (st->codec_info_nb_frames-2)*(int64_t)st->time_base.den, + st->info->codec_info_duration*(int64_t)st->time_base.num, 60000); + if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { +- if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample) +- st->codec->codec_tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); ++ if(st->codec->codec_id == CODEC_ID_RAWVIDEO && !st->codec->codec_tag && !st->codec->bits_per_coded_sample){ ++ uint32_t tag= avcodec_pix_fmt_to_codec_tag(st->codec->pix_fmt); ++ if(ff_find_pix_fmt(ff_raw_pix_fmt_tags, tag) == st->codec->pix_fmt) ++ st->codec->codec_tag= tag; ++ } + + // the check for tb_unreliable() is not completely correct, since this is not about handling + // a unreliable/inexact time base, but a time base that is finer than necessary, as e.g. + // ipmovie.c produces. +- if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > 1 && !st->r_frame_rate.num) ++ if (tb_unreliable(st->codec) && st->info->duration_count > 15 && st->info->duration_gcd > FFMAX(1, st->time_base.den/(500LL*st->time_base.num)) && !st->r_frame_rate.num) + av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den, st->time_base.den, st->time_base.num * st->info->duration_gcd, INT_MAX); + if (st->info->duration_count && !st->r_frame_rate.num + && tb_unreliable(st->codec) /*&& + //FIXME we should not special-case MPEG-2, but this needs testing with non-MPEG-2 ... + st->time_base.num*duration_sum[i]/st->info->duration_count*101LL > st->time_base.den*/){ + int num = 0; +- double best_error= 2*av_q2d(st->time_base); +- best_error = best_error*best_error*st->info->duration_count*1000*12*30; ++ double best_error= 0.01; ++ ++ for (j=1; jinfo->duration_error[0][0]); j++) { ++ int k; + +- for (j=1; jinfo->duration_error); j++) { +- double error = st->info->duration_error[j] * get_std_framerate(j); +-// if(st->codec->codec_type == AVMEDIA_TYPE_VIDEO) +-// av_log(NULL, AV_LOG_ERROR, "%f %f\n", get_std_framerate(j) / 12.0/1001, error); +- if(error < best_error){ +- best_error= error; +- num = get_std_framerate(j); ++ if(st->info->codec_info_duration && st->info->codec_info_duration*av_q2d(st->time_base) < (1001*12.0)/get_std_framerate(j)) ++ continue; ++ if(!st->info->codec_info_duration && 1.0 < (1001*12.0)/get_std_framerate(j)) ++ continue; ++ for(k=0; k<2; k++){ ++ int n= st->info->duration_count; ++ double a= st->info->duration_error[k][0][j] / n; ++ double error= st->info->duration_error[k][1][j]/n - a*a; ++ ++ if(error < best_error && best_error> 0.000000001){ ++ best_error= error; ++ num = get_std_framerate(j); ++ } ++ if(error < 0.02) ++ av_log(NULL, AV_LOG_DEBUG, "rfps: %f %f\n", get_std_framerate(j) / 12.0/1001, error); + } + } + // do not increase frame rate by more than 1 % in order to match a standard rate. +@@ -2465,10 +2729,23 @@ + }else if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { + if(!st->codec->bits_per_coded_sample) + st->codec->bits_per_coded_sample= av_get_bits_per_sample(st->codec->codec_id); ++ // set stream disposition based on audio service type ++ switch (st->codec->audio_service_type) { ++ case AV_AUDIO_SERVICE_TYPE_EFFECTS: ++ st->disposition = AV_DISPOSITION_CLEAN_EFFECTS; break; ++ case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED: ++ st->disposition = AV_DISPOSITION_VISUAL_IMPAIRED; break; ++ case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED: ++ st->disposition = AV_DISPOSITION_HEARING_IMPAIRED; break; ++ case AV_AUDIO_SERVICE_TYPE_COMMENTARY: ++ st->disposition = AV_DISPOSITION_COMMENT; break; ++ case AV_AUDIO_SERVICE_TYPE_KARAOKE: ++ st->disposition = AV_DISPOSITION_KARAOKE; break; ++ } + } + } + +- av_estimate_timings(ic, old_offset); ++ estimate_timings(ic, old_offset); + + compute_chapters_end(ic); + +@@ -2498,19 +2775,28 @@ + #endif + + find_stream_info_err: +- for (i=0; i < ic->nb_streams; i++) ++ for (i=0; i < ic->nb_streams; i++) { ++ if (ic->streams[i]->codec) ++ ic->streams[i]->codec->thread_count = 0; + av_freep(&ic->streams[i]->info); ++ } + return ret; + } + +-static AVProgram *find_program_from_stream(AVFormatContext *ic, int s) ++AVProgram *av_find_program_from_stream(AVFormatContext *ic, AVProgram *last, int s) + { + int i, j; + +- for (i = 0; i < ic->nb_programs; i++) +- for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++) +- if (ic->programs[i]->stream_index[j] == s) +- return ic->programs[i]; ++ for (i = 0; i < ic->nb_programs; i++) { ++ if (ic->programs[i] == last) { ++ last = NULL; ++ } else { ++ if (!last) ++ for (j = 0; j < ic->programs[i]->nb_stream_indexes; j++) ++ if (ic->programs[i]->stream_index[j] == s) ++ return ic->programs[i]; ++ } ++ } + return NULL; + } + +@@ -2521,27 +2807,30 @@ + AVCodec **decoder_ret, + int flags) + { +- int i, nb_streams = ic->nb_streams, stream_number = 0; ++ int i, nb_streams = ic->nb_streams; + int ret = AVERROR_STREAM_NOT_FOUND, best_count = -1; + unsigned *program = NULL; + AVCodec *decoder = NULL, *best_decoder = NULL; + + if (related_stream >= 0 && wanted_stream_nb < 0) { +- AVProgram *p = find_program_from_stream(ic, related_stream); ++ AVProgram *p = av_find_program_from_stream(ic, NULL, related_stream); + if (p) { + program = p->stream_index; + nb_streams = p->nb_stream_indexes; + } + } + for (i = 0; i < nb_streams; i++) { +- AVStream *st = ic->streams[program ? program[i] : i]; ++ int real_stream_index = program ? program[i] : i; ++ AVStream *st = ic->streams[real_stream_index]; + AVCodecContext *avctx = st->codec; + if (avctx->codec_type != type) + continue; +- if (wanted_stream_nb >= 0 && stream_number++ != wanted_stream_nb) ++ if (wanted_stream_nb >= 0 && real_stream_index != wanted_stream_nb) ++ continue; ++ if (st->disposition & (AV_DISPOSITION_HEARING_IMPAIRED|AV_DISPOSITION_VISUAL_IMPAIRED)) + continue; + if (decoder_ret) { +- decoder = avcodec_find_decoder(ic->streams[i]->codec->codec_id); ++ decoder = avcodec_find_decoder(st->codec->codec_id); + if (!decoder) { + if (ret < 0) + ret = AVERROR_DECODER_NOT_FOUND; +@@ -2551,7 +2840,7 @@ + if (best_count >= st->codec_info_nb_frames) + continue; + best_count = st->codec_info_nb_frames; +- ret = i; ++ ret = real_stream_index; + best_decoder = decoder; + if (program && i == nb_streams - 1 && ret < 0) { + program = NULL; +@@ -2571,7 +2860,7 @@ + if (s->iformat->read_play) + return s->iformat->read_play(s); + if (s->pb) +- return av_url_read_fpause(s->pb, 0); ++ return avio_pause(s->pb, 0); + return AVERROR(ENOSYS); + } + +@@ -2580,18 +2869,29 @@ + if (s->iformat->read_pause) + return s->iformat->read_pause(s); + if (s->pb) +- return av_url_read_fpause(s->pb, 1); ++ return avio_pause(s->pb, 1); + return AVERROR(ENOSYS); + } + ++#if FF_API_FORMAT_PARAMETERS + void av_close_input_stream(AVFormatContext *s) + { +- int i; +- AVStream *st; +- + flush_packet_queue(s); + if (s->iformat->read_close) + s->iformat->read_close(s); ++ avformat_free_context(s); ++} ++#endif ++ ++void avformat_free_context(AVFormatContext *s) ++{ ++ int i; ++ AVStream *st; ++ ++ av_opt_free(s); ++ if (s->iformat && s->iformat->priv_class && s->priv_data) ++ av_opt_free(s->priv_data); ++ + for(i=0;inb_streams;i++) { + /* free all data in a stream component */ + st = s->streams[i]; +@@ -2599,61 +2899,67 @@ + av_parser_close(st->parser); + av_free_packet(&st->cur_pkt); + } +- av_metadata_free(&st->metadata); +- av_free(st->index_entries); +- av_free(st->codec->extradata); +- av_free(st->codec->subtitle_header); +- av_free(st->codec); +-#if FF_API_OLD_METADATA +- av_free(st->filename); +-#endif +- av_free(st->priv_data); +- av_free(st->info); +- av_free(st); ++ av_dict_free(&st->metadata); ++ av_freep(&st->index_entries); ++ av_freep(&st->codec->extradata); ++ av_freep(&st->codec->subtitle_header); ++ av_freep(&st->codec); ++ av_freep(&st->priv_data); ++ av_freep(&st->info); ++ av_freep(&st); + } + for(i=s->nb_programs-1; i>=0; i--) { +-#if FF_API_OLD_METADATA +- av_freep(&s->programs[i]->provider_name); +- av_freep(&s->programs[i]->name); +-#endif +- av_metadata_free(&s->programs[i]->metadata); ++ av_dict_free(&s->programs[i]->metadata); + av_freep(&s->programs[i]->stream_index); + av_freep(&s->programs[i]); + } + av_freep(&s->programs); + av_freep(&s->priv_data); + while(s->nb_chapters--) { +-#if FF_API_OLD_METADATA +- av_free(s->chapters[s->nb_chapters]->title); +-#endif +- av_metadata_free(&s->chapters[s->nb_chapters]->metadata); +- av_free(s->chapters[s->nb_chapters]); ++ av_dict_free(&s->chapters[s->nb_chapters]->metadata); ++ av_freep(&s->chapters[s->nb_chapters]); + } + av_freep(&s->chapters); +- av_metadata_free(&s->metadata); +- av_freep(&s->key); ++ av_dict_free(&s->metadata); ++ av_freep(&s->streams); + av_free(s); + } + ++#if FF_API_CLOSE_INPUT_FILE + void av_close_input_file(AVFormatContext *s) + { +- ByteIOContext *pb = s->iformat->flags & AVFMT_NOFILE ? NULL : s->pb; +- av_close_input_stream(s); ++ avformat_close_input(&s); ++} ++#endif ++ ++void avformat_close_input(AVFormatContext **ps) ++{ ++ AVFormatContext *s = *ps; ++ AVIOContext *pb = (s->iformat && (s->iformat->flags & AVFMT_NOFILE)) || (s->flags & AVFMT_FLAG_CUSTOM_IO) ? ++ NULL : s->pb; ++ flush_packet_queue(s); ++ if (s->iformat && (s->iformat->read_close)) ++ s->iformat->read_close(s); ++ avformat_free_context(s); ++ *ps = NULL; + if (pb) +- url_fclose(pb); ++ avio_close(pb); + } + ++#if FF_API_NEW_STREAM + AVStream *av_new_stream(AVFormatContext *s, int id) + { ++ AVStream *st = avformat_new_stream(s, NULL); ++ if (st) ++ st->id = id; ++ return st; ++} ++#endif ++ ++AVStream *avformat_new_stream(AVFormatContext *s, AVCodec *c) ++{ + AVStream *st; + int i; +- +-#if FF_API_MAX_STREAMS +- if (s->nb_streams >= MAX_STREAMS){ +- av_log(s, AV_LOG_ERROR, "Too many streams\n"); +- return NULL; +- } +-#else + AVStream **streams; + + if (s->nb_streams >= INT_MAX/sizeof(*streams)) +@@ -2662,7 +2968,6 @@ + if (!streams) + return NULL; + s->streams = streams; +-#endif + + st = av_mallocz(sizeof(AVStream)); + if (!st) +@@ -2672,13 +2977,12 @@ + return NULL; + } + +- st->codec= avcodec_alloc_context(); ++ st->codec = avcodec_alloc_context3(c); + if (s->iformat) { + /* no default bitrate if decoding */ + st->codec->bit_rate = 0; + } + st->index = s->nb_streams; +- st->id = id; + st->start_time = AV_NOPTS_VALUE; + st->duration = AV_NOPTS_VALUE; + /* we set the current DTS to 0 so that formats without any timestamps +@@ -2690,7 +2994,7 @@ + st->probe_packets = MAX_PROBE_PACKETS; + + /* default pts setting is MPEG-like */ +- av_set_pts_info(st, 33, 1, 90000); ++ avpriv_set_pts_info(st, 33, 1, 90000); + st->last_IP_pts = AV_NOPTS_VALUE; + for(i=0; ipts_buffer[i]= AV_NOPTS_VALUE; +@@ -2707,9 +3011,7 @@ + AVProgram *program=NULL; + int i; + +-#ifdef DEBUG_SI +- av_log(ac, AV_LOG_DEBUG, "new_program: id=0x%04x\n", id); +-#endif ++ av_dlog(ac, "new_program: id=0x%04x\n", id); + + for(i=0; inb_programs; i++) + if(ac->programs[i]->id == id) +@@ -2727,7 +3029,7 @@ + return program; + } + +-AVChapter *ff_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title) ++AVChapter *avpriv_new_chapter(AVFormatContext *s, int id, AVRational time_base, int64_t start, int64_t end, const char *title) + { + AVChapter *chapter = NULL; + int i; +@@ -2742,10 +3044,7 @@ + return NULL; + dynarray_add(&s->chapters, &s->nb_chapters, chapter); + } +-#if FF_API_OLD_METADATA +- av_free(chapter->title); +-#endif +- av_metadata_set2(&chapter->metadata, "title", title, 0); ++ av_dict_set(&chapter->metadata, "title", title, 0); + chapter->id = id; + chapter->time_base= time_base; + chapter->start = start; +@@ -2757,10 +3056,9 @@ + /************************************************************/ + /* output media file */ + ++#if FF_API_FORMAT_PARAMETERS + int av_set_parameters(AVFormatContext *s, AVFormatParameters *ap) + { +- int ret; +- + if (s->oformat->priv_data_size > 0) { + s->priv_data = av_mallocz(s->oformat->priv_data_size); + if (!s->priv_data) +@@ -2772,13 +3070,72 @@ + } else + s->priv_data = NULL; + +- if (s->oformat->set_parameters) { +- ret = s->oformat->set_parameters(s, ap); +- if (ret < 0) +- return ret; ++ return 0; ++} ++#endif ++ ++int avformat_alloc_output_context2(AVFormatContext **avctx, AVOutputFormat *oformat, ++ const char *format, const char *filename) ++{ ++ AVFormatContext *s = avformat_alloc_context(); ++ int ret = 0; ++ ++ *avctx = NULL; ++ if (!s) ++ goto nomem; ++ ++ if (!oformat) { ++ if (format) { ++ oformat = av_guess_format(format, NULL, NULL); ++ if (!oformat) { ++ av_log(s, AV_LOG_ERROR, "Requested output format '%s' is not a suitable output format\n", format); ++ ret = AVERROR(EINVAL); ++ goto error; ++ } ++ } else { ++ oformat = av_guess_format(NULL, filename, NULL); ++ if (!oformat) { ++ ret = AVERROR(EINVAL); ++ av_log(s, AV_LOG_ERROR, "Unable to find a suitable output format for '%s'\n", ++ filename); ++ goto error; ++ } ++ } + } ++ ++ s->oformat = oformat; ++ if (s->oformat->priv_data_size > 0) { ++ s->priv_data = av_mallocz(s->oformat->priv_data_size); ++ if (!s->priv_data) ++ goto nomem; ++ if (s->oformat->priv_class) { ++ *(const AVClass**)s->priv_data= s->oformat->priv_class; ++ av_opt_set_defaults(s->priv_data); ++ } ++ } else ++ s->priv_data = NULL; ++ ++ if (filename) ++ av_strlcpy(s->filename, filename, sizeof(s->filename)); ++ *avctx = s; + return 0; ++nomem: ++ av_log(s, AV_LOG_ERROR, "Out of memory\n"); ++ ret = AVERROR(ENOMEM); ++error: ++ avformat_free_context(s); ++ return ret; ++} ++ ++#if FF_API_ALLOC_OUTPUT_CONTEXT ++AVFormatContext *avformat_alloc_output_context(const char *format, ++ AVOutputFormat *oformat, const char *filename) ++{ ++ AVFormatContext *avctx; ++ int ret = avformat_alloc_output_context2(&avctx, oformat, format, filename); ++ return ret < 0 ? NULL : avctx; + } ++#endif + + static int validate_codec_tag(AVFormatContext *s, AVStream *st) + { +@@ -2796,7 +3153,7 @@ + for (n = 0; s->oformat->codec_tag[n]; n++) { + avctag = s->oformat->codec_tag[n]; + while (avctag->id != CODEC_ID_NONE) { +- if (ff_toupper4(avctag->tag) == ff_toupper4(st->codec->codec_tag)) { ++ if (avpriv_toupper4(avctag->tag) == avpriv_toupper4(st->codec->codec_tag)) { + id = avctag->id; + if (id == st->codec->codec_id) + return 1; +@@ -2813,15 +3170,32 @@ + return 1; + } + ++#if FF_API_FORMAT_PARAMETERS + int av_write_header(AVFormatContext *s) + { +- int ret, i; ++ return avformat_write_header(s, NULL); ++} ++#endif ++ ++int avformat_write_header(AVFormatContext *s, AVDictionary **options) ++{ ++ int ret = 0, i; + AVStream *st; ++ AVDictionary *tmp = NULL; ++ ++ if (options) ++ av_dict_copy(&tmp, *options, 0); ++ if ((ret = av_opt_set_dict(s, &tmp)) < 0) ++ goto fail; ++ if (s->priv_data && s->oformat->priv_class && *(const AVClass**)s->priv_data==s->oformat->priv_class && ++ (ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) ++ goto fail; + + // some sanity checks + if (s->nb_streams == 0 && !(s->oformat->flags & AVFMT_NOSTREAMS)) { + av_log(s, AV_LOG_ERROR, "no streams\n"); +- return AVERROR(EINVAL); ++ ret = AVERROR(EINVAL); ++ goto fail; + } + + for(i=0;inb_streams;i++) { +@@ -2831,7 +3205,8 @@ + case AVMEDIA_TYPE_AUDIO: + if(st->codec->sample_rate<=0){ + av_log(s, AV_LOG_ERROR, "sample rate not set\n"); +- return AVERROR(EINVAL); ++ ret = AVERROR(EINVAL); ++ goto fail; + } + if(!st->codec->block_align) + st->codec->block_align = st->codec->channels * +@@ -2840,15 +3215,20 @@ + case AVMEDIA_TYPE_VIDEO: + if(st->codec->time_base.num<=0 || st->codec->time_base.den<=0){ //FIXME audio too? + av_log(s, AV_LOG_ERROR, "time base not set\n"); +- return AVERROR(EINVAL); ++ ret = AVERROR(EINVAL); ++ goto fail; + } + if((st->codec->width<=0 || st->codec->height<=0) && !(s->oformat->flags & AVFMT_NODIMENSIONS)){ + av_log(s, AV_LOG_ERROR, "dimensions not set\n"); +- return AVERROR(EINVAL); ++ ret = AVERROR(EINVAL); ++ goto fail; + } +- if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)){ ++ if(av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio) ++ && FFABS(av_q2d(st->sample_aspect_ratio) - av_q2d(st->codec->sample_aspect_ratio)) > 0.004*av_q2d(st->sample_aspect_ratio) ++ ){ + av_log(s, AV_LOG_ERROR, "Aspect ratio mismatch between encoder and muxer layer\n"); +- return AVERROR(EINVAL); ++ ret = AVERROR(EINVAL); ++ goto fail; + } + break; + } +@@ -2865,7 +3245,8 @@ + av_log(s, AV_LOG_ERROR, + "Tag %s/0x%08x incompatible with output codec id '%d'\n", + tagbuf, st->codec->codec_tag, st->codec->codec_id); +- return AVERROR_INVALIDDATA; ++ ret = AVERROR_INVALIDDATA; ++ goto fail; + } + }else + st->codec->codec_tag= av_codec_get_tag(s->oformat->codec_tag, st->codec->codec_id); +@@ -2878,23 +3259,27 @@ + + if (!s->priv_data && s->oformat->priv_data_size > 0) { + s->priv_data = av_mallocz(s->oformat->priv_data_size); +- if (!s->priv_data) +- return AVERROR(ENOMEM); ++ if (!s->priv_data) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ if (s->oformat->priv_class) { ++ *(const AVClass**)s->priv_data= s->oformat->priv_class; ++ av_opt_set_defaults(s->priv_data); ++ if ((ret = av_opt_set_dict(s->priv_data, &tmp)) < 0) ++ goto fail; ++ } + } + +-#if FF_API_OLD_METADATA +- ff_metadata_mux_compat(s); +-#endif +- + /* set muxer identification string */ + if (s->nb_streams && !(s->streams[0]->codec->flags & CODEC_FLAG_BITEXACT)) { +- av_metadata_set2(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0); ++ av_dict_set(&s->metadata, "encoder", LIBAVFORMAT_IDENT, 0); + } + + if(s->oformat->write_header){ + ret = s->oformat->write_header(s); + if (ret < 0) +- return ret; ++ goto fail; + } + + /* init PTS generation */ +@@ -2913,12 +3298,22 @@ + break; + } + if (den != AV_NOPTS_VALUE) { +- if (den <= 0) +- return AVERROR_INVALIDDATA; +- av_frac_init(&st->pts, 0, 0, den); ++ if (den <= 0) { ++ ret = AVERROR_INVALIDDATA; ++ goto fail; ++ } ++ frac_init(&st->pts, 0, 0, den); + } + } ++ ++ if (options) { ++ av_dict_free(options); ++ *options = tmp; ++ } + return 0; ++fail: ++ av_dict_free(&tmp); ++ return ret; + } + + //FIXME merge with compute_pkt_fields +@@ -2926,10 +3321,8 @@ + int delay = FFMAX(st->codec->has_b_frames, !!st->codec->max_b_frames); + int num, den, frame_size, i; + +-// av_log(s, AV_LOG_DEBUG, "av_write_frame: pts:%"PRId64" dts:%"PRId64" cur_dts:%"PRId64" b:%d size:%d st:%d\n", pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); +- +-/* if(pkt->pts == AV_NOPTS_VALUE && pkt->dts == AV_NOPTS_VALUE) +- return -1;*/ ++ av_dlog(s, "compute_pkt_fields2: pts:%"PRId64" dts:%"PRId64" cur_dts:%"PRId64" b:%d size:%d st:%d\n", ++ pkt->pts, pkt->dts, st->cur_dts, delay, pkt->size, pkt->stream_index); + + /* duration field */ + if (pkt->duration == 0) { +@@ -2960,15 +3353,15 @@ + pkt->dts= st->pts_buffer[0]; + } + +- if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && st->cur_dts >= pkt->dts){ ++ if(st->cur_dts && st->cur_dts != AV_NOPTS_VALUE && ((!(s->oformat->flags & AVFMT_TS_NONSTRICT) && st->cur_dts >= pkt->dts) || st->cur_dts > pkt->dts)){ + av_log(s, AV_LOG_ERROR, + "Application provided invalid, non monotonically increasing dts to muxer in stream %d: %"PRId64" >= %"PRId64"\n", + st->index, st->cur_dts, pkt->dts); +- return -1; ++ return AVERROR(EINVAL); + } + if(pkt->dts != AV_NOPTS_VALUE && pkt->pts != AV_NOPTS_VALUE && pkt->pts < pkt->dts){ + av_log(s, AV_LOG_ERROR, "pts < dts in stream %d\n", st->index); +- return -1; ++ return AVERROR(EINVAL); + } + + // av_log(s, AV_LOG_DEBUG, "av_write_frame: pts2:%"PRId64" dts2:%"PRId64"\n", pkt->pts, pkt->dts); +@@ -2984,11 +3377,11 @@ + likely equal to the encoder delay, but it would be better if we + had the real timestamps from the encoder */ + if (frame_size >= 0 && (pkt->size || st->pts.num!=st->pts.den>>1 || st->pts.val)) { +- av_frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); ++ frac_add(&st->pts, (int64_t)st->time_base.den * frame_size); + } + break; + case AVMEDIA_TYPE_VIDEO: +- av_frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num); ++ frac_add(&st->pts, (int64_t)st->time_base.den * st->codec->time_base.num); + break; + default: + break; +@@ -2998,38 +3391,71 @@ + + int av_write_frame(AVFormatContext *s, AVPacket *pkt) + { +- int ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); ++ int ret; ++ ++ if (!pkt) { ++ if (s->oformat->flags & AVFMT_ALLOW_FLUSH) ++ return s->oformat->write_packet(s, pkt); ++ return 1; ++ } ++ ++ ret = compute_pkt_fields2(s, s->streams[pkt->stream_index], pkt); + + if(ret<0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) + return ret; + + ret= s->oformat->write_packet(s, pkt); +- if(!ret) +- ret= url_ferror(s->pb); ++ ++ if (ret >= 0) ++ s->streams[pkt->stream_index]->nb_frames++; + return ret; + } + +-void ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, ++#define CHUNK_START 0x1000 ++ ++int ff_interleave_add_packet(AVFormatContext *s, AVPacket *pkt, + int (*compare)(AVFormatContext *, AVPacket *, AVPacket *)) + { + AVPacketList **next_point, *this_pktl; ++ AVStream *st= s->streams[pkt->stream_index]; ++ int chunked= s->max_chunk_size || s->max_chunk_duration; + + this_pktl = av_mallocz(sizeof(AVPacketList)); ++ if (!this_pktl) ++ return AVERROR(ENOMEM); + this_pktl->pkt= *pkt; + pkt->destruct= NULL; // do not free original but only the copy + av_dup_packet(&this_pktl->pkt); // duplicate the packet if it uses non-alloced memory + + if(s->streams[pkt->stream_index]->last_in_packet_buffer){ +- next_point = &(s->streams[pkt->stream_index]->last_in_packet_buffer->next); +- }else ++ next_point = &(st->last_in_packet_buffer->next); ++ }else{ + next_point = &s->packet_buffer; ++ } + + if(*next_point){ ++ if(chunked){ ++ uint64_t max= av_rescale_q(s->max_chunk_duration, AV_TIME_BASE_Q, st->time_base); ++ if( st->interleaver_chunk_size + pkt->size <= s->max_chunk_size-1U ++ && st->interleaver_chunk_duration + pkt->duration <= max-1U){ ++ st->interleaver_chunk_size += pkt->size; ++ st->interleaver_chunk_duration += pkt->duration; ++ goto next_non_null; ++ }else{ ++ st->interleaver_chunk_size = ++ st->interleaver_chunk_duration = 0; ++ this_pktl->pkt.flags |= CHUNK_START; ++ } ++ } ++ + if(compare(s, &s->packet_buffer_end->pkt, pkt)){ +- while(!compare(s, &(*next_point)->pkt, pkt)){ ++ while( *next_point ++ && ((chunked && !((*next_point)->pkt.flags&CHUNK_START)) ++ || !compare(s, &(*next_point)->pkt, pkt))){ + next_point= &(*next_point)->next; + } +- goto next_non_null; ++ if(*next_point) ++ goto next_non_null; + }else{ + next_point = &(s->packet_buffer_end->next); + } +@@ -3043,30 +3469,73 @@ + + s->streams[pkt->stream_index]->last_in_packet_buffer= + *next_point= this_pktl; ++ return 0; + } + + static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacket *pkt) + { + AVStream *st = s->streams[ pkt ->stream_index]; + AVStream *st2= s->streams[ next->stream_index]; +- int64_t a= st2->time_base.num * (int64_t)st ->time_base.den; +- int64_t b= st ->time_base.num * (int64_t)st2->time_base.den; +- return av_rescale_rnd(pkt->dts, b, a, AV_ROUND_DOWN) < next->dts; ++ int comp = av_compare_ts(next->dts, st2->time_base, pkt->dts, ++ st->time_base); ++ if(s->audio_preload && ((st->codec->codec_type == AVMEDIA_TYPE_AUDIO) != (st2->codec->codec_type == AVMEDIA_TYPE_AUDIO))){ ++ int64_t ts = av_rescale_q(pkt ->dts, st ->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO); ++ int64_t ts2= av_rescale_q(next->dts, st2->time_base, AV_TIME_BASE_Q) - s->audio_preload*(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO); ++ if(ts == ts2){ ++ ts= ( pkt ->dts* st->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st ->codec->codec_type == AVMEDIA_TYPE_AUDIO)* st->time_base.den)*st2->time_base.den ++ -( next->dts*st2->time_base.num*AV_TIME_BASE - s->audio_preload*(int64_t)(st2->codec->codec_type == AVMEDIA_TYPE_AUDIO)*st2->time_base.den)* st->time_base.den; ++ ts2=0; ++ } ++ comp= (ts>ts2) - (tsstream_index < next->stream_index; ++ return comp > 0; + } + + int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ + AVPacketList *pktl; +- int stream_count=0; +- int i; ++ int stream_count=0, noninterleaved_count=0; ++ int64_t delta_dts_max = 0; ++ int i, ret; + + if(pkt){ +- ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts); ++ ret = ff_interleave_add_packet(s, pkt, ff_interleave_compare_dts); ++ if (ret < 0) ++ return ret; + } + +- for(i=0; i < s->nb_streams; i++) +- stream_count+= !!s->streams[i]->last_in_packet_buffer; ++ for(i=0; i < s->nb_streams; i++) { ++ if (s->streams[i]->last_in_packet_buffer) { ++ ++stream_count; ++ } else if(s->streams[i]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { ++ ++noninterleaved_count; ++ } ++ } + +- if(stream_count && (s->nb_streams == stream_count || flush)){ ++ if (s->nb_streams == stream_count) { ++ flush = 1; ++ } else if (!flush){ ++ for(i=0; i < s->nb_streams; i++) { ++ if (s->streams[i]->last_in_packet_buffer) { ++ int64_t delta_dts = ++ av_rescale_q(s->streams[i]->last_in_packet_buffer->pkt.dts, ++ s->streams[i]->time_base, ++ AV_TIME_BASE_Q) - ++ av_rescale_q(s->packet_buffer->pkt.dts, ++ s->streams[s->packet_buffer->pkt.stream_index]->time_base, ++ AV_TIME_BASE_Q); ++ delta_dts_max= FFMAX(delta_dts_max, delta_dts); ++ } ++ } ++ if(s->nb_streams == stream_count+noninterleaved_count && ++ delta_dts_max > 20*AV_TIME_BASE) { ++ av_log(s, AV_LOG_DEBUG, "flushing with %d noninterleaved\n", noninterleaved_count); ++ flush = 1; ++ } ++ } ++ if(stream_count && flush){ + pktl= s->packet_buffer; + *out= pktl->pkt; + +@@ -3093,42 +3562,49 @@ + * @return 1 if a packet was output, 0 if no packet could be output, + * < 0 if an error occurred + */ +-static int av_interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){ +- if(s->oformat->interleave_packet) +- return s->oformat->interleave_packet(s, out, in, flush); +- else ++static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, int flush){ ++ if (s->oformat->interleave_packet) { ++ int ret = s->oformat->interleave_packet(s, out, in, flush); ++ if (in) ++ av_free_packet(in); ++ return ret; ++ } else + return av_interleave_packet_per_dts(s, out, in, flush); + } + + int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){ + AVStream *st= s->streams[ pkt->stream_index]; ++ int ret; + + //FIXME/XXX/HACK drop zero sized packets + if(st->codec->codec_type == AVMEDIA_TYPE_AUDIO && pkt->size==0) + return 0; + +-//av_log(NULL, AV_LOG_DEBUG, "av_interleaved_write_frame %d %"PRId64" %"PRId64"\n", pkt->size, pkt->dts, pkt->pts); +- if(compute_pkt_fields2(s, st, pkt) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) +- return -1; ++ av_dlog(s, "av_interleaved_write_frame size:%d dts:%"PRId64" pts:%"PRId64"\n", ++ pkt->size, pkt->dts, pkt->pts); ++ if((ret = compute_pkt_fields2(s, st, pkt)) < 0 && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) ++ return ret; + + if(pkt->dts == AV_NOPTS_VALUE && !(s->oformat->flags & AVFMT_NOTIMESTAMPS)) +- return -1; ++ return AVERROR(EINVAL); + + for(;;){ + AVPacket opkt; +- int ret= av_interleave_packet(s, &opkt, pkt, 0); ++ int ret= interleave_packet(s, &opkt, pkt, 0); + if(ret<=0) //FIXME cleanup needed for ret<0 ? + return ret; + + ret= s->oformat->write_packet(s, &opkt); ++ if (ret >= 0) ++ s->streams[opkt.stream_index]->nb_frames++; + + av_free_packet(&opkt); + pkt= NULL; + + if(ret<0) + return ret; +- if(url_ferror(s->pb)) +- return url_ferror(s->pb); ++ if(s->pb && s->pb->error) ++ return s->pb->error; + } + } + +@@ -3138,19 +3614,21 @@ + + for(;;){ + AVPacket pkt; +- ret= av_interleave_packet(s, &pkt, NULL, 1); ++ ret= interleave_packet(s, &pkt, NULL, 1); + if(ret<0) //FIXME cleanup needed for ret<0 ? + goto fail; + if(!ret) + break; + + ret= s->oformat->write_packet(s, &pkt); ++ if (ret >= 0) ++ s->streams[pkt.stream_index]->nb_frames++; + + av_free_packet(&pkt); + + if(ret<0) + goto fail; +- if(url_ferror(s->pb)) ++ if(s->pb && s->pb->error) + goto fail; + } + +@@ -3158,15 +3636,26 @@ + ret = s->oformat->write_trailer(s); + fail: + if(ret == 0) +- ret=url_ferror(s->pb); ++ ret = s->pb ? s->pb->error : 0; + for(i=0;inb_streams;i++) { + av_freep(&s->streams[i]->priv_data); + av_freep(&s->streams[i]->index_entries); + } ++ if (s->oformat->priv_class) ++ av_opt_free(s->priv_data); + av_freep(&s->priv_data); + return ret; + } + ++int av_get_output_timestamp(struct AVFormatContext *s, int stream, ++ int64_t *dts, int64_t *wall) ++{ ++ if (!s->oformat || !s->oformat->get_output_timestamp) ++ return AVERROR(ENOSYS); ++ s->oformat->get_output_timestamp(s, stream, dts, wall); ++ return 0; ++} ++ + void ff_program_add_stream_index(AVFormatContext *ac, int progid, unsigned int idx) + { + int i, j; +@@ -3202,15 +3691,20 @@ + else av_log(NULL, AV_LOG_INFO, ", %1.0fk %s", d/1000, postfix); + } + +-static void dump_metadata(void *ctx, AVMetadata *m, const char *indent) ++static void dump_metadata(void *ctx, AVDictionary *m, const char *indent) + { +- if(m && !(m->count == 1 && av_metadata_get(m, "language", NULL, 0))){ +- AVMetadataTag *tag=NULL; ++ if(m && !(m->count == 1 && av_dict_get(m, "language", NULL, 0))){ ++ AVDictionaryEntry *tag=NULL; + + av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); +- while((tag=av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX))) { +- if(strcmp("language", tag->key)) +- av_log(ctx, AV_LOG_INFO, "%s %-16s: %s\n", indent, tag->key, tag->value); ++ while((tag=av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) { ++ if(strcmp("language", tag->key)){ ++ char tmp[256]; ++ int i; ++ av_strlcpy(tmp, tag->value, sizeof(tmp)); ++ for(i=0; ikey, tmp); ++ } + } + } + } +@@ -3222,9 +3716,9 @@ + int flags = (is_output ? ic->oformat->flags : ic->iformat->flags); + AVStream *st = ic->streams[i]; + int g = av_gcd(st->time_base.num, st->time_base.den); +- AVMetadataTag *lang = av_metadata_get(st->metadata, "language", NULL, 0); ++ AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0); + avcodec_string(buf, sizeof(buf), st->codec, is_output); +- av_log(NULL, AV_LOG_INFO, " Stream #%d.%d", index, i); ++ av_log(NULL, AV_LOG_INFO, " Stream #%d:%d", index, i); + /* the pid is an important information, so we display it */ + /* XXX: add a generic system */ + if (flags & AVFMT_SHOW_IDS) +@@ -3240,7 +3734,7 @@ + st->codec->width*st->sample_aspect_ratio.num, + st->codec->height*st->sample_aspect_ratio.den, + 1024*1024); +- av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d", ++ av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d", + st->sample_aspect_ratio.num, st->sample_aspect_ratio.den, + display_aspect_ratio.num, display_aspect_ratio.den); + } +@@ -3254,17 +3748,47 @@ + if(st->codec->time_base.den && st->codec->time_base.num) + print_fps(1/av_q2d(st->codec->time_base), "tbc"); + } ++ if (st->disposition & AV_DISPOSITION_DEFAULT) ++ av_log(NULL, AV_LOG_INFO, " (default)"); ++ if (st->disposition & AV_DISPOSITION_DUB) ++ av_log(NULL, AV_LOG_INFO, " (dub)"); ++ if (st->disposition & AV_DISPOSITION_ORIGINAL) ++ av_log(NULL, AV_LOG_INFO, " (original)"); ++ if (st->disposition & AV_DISPOSITION_COMMENT) ++ av_log(NULL, AV_LOG_INFO, " (comment)"); ++ if (st->disposition & AV_DISPOSITION_LYRICS) ++ av_log(NULL, AV_LOG_INFO, " (lyrics)"); ++ if (st->disposition & AV_DISPOSITION_KARAOKE) ++ av_log(NULL, AV_LOG_INFO, " (karaoke)"); ++ if (st->disposition & AV_DISPOSITION_FORCED) ++ av_log(NULL, AV_LOG_INFO, " (forced)"); ++ if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED) ++ av_log(NULL, AV_LOG_INFO, " (hearing impaired)"); ++ if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED) ++ av_log(NULL, AV_LOG_INFO, " (visual impaired)"); ++ if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS) ++ av_log(NULL, AV_LOG_INFO, " (clean effects)"); + av_log(NULL, AV_LOG_INFO, "\n"); + dump_metadata(NULL, st->metadata, " "); + } + ++#if FF_API_DUMP_FORMAT + void dump_format(AVFormatContext *ic, + int index, + const char *url, + int is_output) + { ++ av_dump_format(ic, index, url, is_output); ++} ++#endif ++ ++void av_dump_format(AVFormatContext *ic, ++ int index, ++ const char *url, ++ int is_output) ++{ + int i; +- uint8_t *printed = av_mallocz(ic->nb_streams); ++ uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL; + if (ic->nb_streams && !printed) + return; + +@@ -3316,7 +3840,7 @@ + if(ic->nb_programs) { + int j, k, total = 0; + for(j=0; jnb_programs; j++) { +- AVMetadataTag *name = av_metadata_get(ic->programs[j]->metadata, ++ AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata, + "name", NULL, 0); + av_log(NULL, AV_LOG_INFO, " Program %d %s\n", ic->programs[j]->id, + name ? name->value : ""); +@@ -3337,24 +3861,6 @@ + av_free(printed); + } + +-#if FF_API_PARSE_FRAME_PARAM +-#include "libavcore/parseutils.h" +- +-int parse_image_size(int *width_ptr, int *height_ptr, const char *str) +-{ +- return av_parse_video_size(width_ptr, height_ptr, str); +-} +- +-int parse_frame_rate(int *frame_rate_num, int *frame_rate_den, const char *arg) +-{ +- AVRational frame_rate; +- int ret = av_parse_video_rate(&frame_rate, arg); +- *frame_rate_num= frame_rate.num; +- *frame_rate_den= frame_rate.den; +- return ret; +-} +-#endif +- + int64_t av_gettime(void) + { + struct timeval tv; +@@ -3367,163 +3873,25 @@ + return (av_gettime() / 1000) * 1000 + NTP_OFFSET_US; + } + +-int64_t parse_date(const char *datestr, int duration) +-{ +- const char *p; +- int64_t t; +- struct tm dt; +- int i; +- static const char * const date_fmt[] = { +- "%Y-%m-%d", +- "%Y%m%d", +- }; +- static const char * const time_fmt[] = { +- "%H:%M:%S", +- "%H%M%S", +- }; +- const char *q; +- int is_utc, len; +- char lastch; +- int negative = 0; +- +-#undef time +- time_t now = time(0); +- +- len = strlen(datestr); +- if (len > 0) +- lastch = datestr[len - 1]; +- else +- lastch = '\0'; +- is_utc = (lastch == 'z' || lastch == 'Z'); +- +- memset(&dt, 0, sizeof(dt)); +- +- p = datestr; +- q = NULL; +- if (!duration) { +- if (!strncasecmp(datestr, "now", len)) +- return (int64_t) now * 1000000; +- +- /* parse the year-month-day part */ +- for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) { +- q = small_strptime(p, date_fmt[i], &dt); +- if (q) { +- break; +- } +- } ++#if FF_API_PARSE_DATE ++#include "libavutil/parseutils.h" + +- /* if the year-month-day part is missing, then take the +- * current year-month-day time */ +- if (!q) { +- if (is_utc) { +- dt = *gmtime(&now); +- } else { +- dt = *localtime(&now); +- } +- dt.tm_hour = dt.tm_min = dt.tm_sec = 0; +- } else { +- p = q; +- } +- +- if (*p == 'T' || *p == 't' || *p == ' ') +- p++; +- +- /* parse the hour-minute-second part */ +- for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) { +- q = small_strptime(p, time_fmt[i], &dt); +- if (q) { +- break; +- } +- } +- } else { +- /* parse datestr as a duration */ +- if (p[0] == '-') { +- negative = 1; +- ++p; +- } +- /* parse datestr as HH:MM:SS */ +- q = small_strptime(p, time_fmt[0], &dt); +- if (!q) { +- /* parse datestr as S+ */ +- dt.tm_sec = strtol(p, (char **)&q, 10); +- if (q == p) +- /* the parsing didn't succeed */ +- return INT64_MIN; +- dt.tm_min = 0; +- dt.tm_hour = 0; +- } +- } +- +- /* Now we have all the fields that we can get */ +- if (!q) { +- return INT64_MIN; +- } +- +- if (duration) { +- t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; +- } else { +- dt.tm_isdst = -1; /* unknown */ +- if (is_utc) { +- t = mktimegm(&dt); +- } else { +- t = mktime(&dt); +- } +- } +- +- t *= 1000000; +- +- /* parse the .m... part */ +- if (*q == '.') { +- int val, n; +- q++; +- for (val = 0, n = 100000; n >= 1; n /= 10, q++) { +- if (!isdigit(*q)) +- break; +- val += n * (*q - '0'); +- } +- t += val; +- } +- return negative ? -t : t; ++int64_t parse_date(const char *timestr, int duration) ++{ ++ int64_t timeval; ++ av_parse_time(&timeval, timestr, duration); ++ return timeval; + } ++#endif ++ ++#if FF_API_FIND_INFO_TAG ++#include "libavutil/parseutils.h" + + int find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) + { +- const char *p; +- char tag[128], *q; +- +- p = info; +- if (*p == '?') +- p++; +- for(;;) { +- q = tag; +- while (*p != '\0' && *p != '=' && *p != '&') { +- if ((q - tag) < sizeof(tag) - 1) +- *q++ = *p; +- p++; +- } +- *q = '\0'; +- q = arg; +- if (*p == '=') { +- p++; +- while (*p != '&' && *p != '\0') { +- if ((q - arg) < arg_size - 1) { +- if (*p == '+') +- *q++ = ' '; +- else +- *q++ = *p; +- } +- p++; +- } +- } +- *q = '\0'; +- if (!strcmp(tag, tag1)) +- return 1; +- if (*p != '&') +- break; +- p++; +- } +- return 0; ++ return av_find_info_tag(arg, arg_size, tag1, info); + } ++#endif + + int av_get_frame_filename(char *buf, int buf_size, + const char *path, int number) +@@ -3619,26 +3987,25 @@ + hex_dump_internal(avcl, NULL, level, buf, size); + } + +- //FIXME needs to know the time_base +-static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, int dump_payload) ++static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, int dump_payload, AVRational time_base) + { + #undef fprintf + #define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0) + PRINT("stream #%d:\n", pkt->stream_index); + PRINT(" keyframe=%d\n", ((pkt->flags & AV_PKT_FLAG_KEY) != 0)); +- PRINT(" duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); ++ PRINT(" duration=%0.3f\n", pkt->duration * av_q2d(time_base)); + /* DTS is _always_ valid after av_read_frame() */ + PRINT(" dts="); + if (pkt->dts == AV_NOPTS_VALUE) + PRINT("N/A"); + else +- PRINT("%0.3f", (double)pkt->dts / AV_TIME_BASE); ++ PRINT("%0.3f", pkt->dts * av_q2d(time_base)); + /* PTS may not be known if B-frames are present. */ + PRINT(" pts="); + if (pkt->pts == AV_NOPTS_VALUE) + PRINT("N/A"); + else +- PRINT("%0.3f", (double)pkt->pts / AV_TIME_BASE); ++ PRINT("%0.3f", pkt->pts * av_q2d(time_base)); + PRINT("\n"); + PRINT(" size=%d\n", pkt->size); + #undef PRINT +@@ -3646,34 +4013,33 @@ + av_hex_dump(f, pkt->data, pkt->size); + } + ++#if FF_API_PKT_DUMP + void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) + { +- pkt_dump_internal(NULL, f, 0, pkt, dump_payload); ++ AVRational tb = { 1, AV_TIME_BASE }; ++ pkt_dump_internal(NULL, f, 0, pkt, dump_payload, tb); + } ++#endif + +-void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) ++void av_pkt_dump2(FILE *f, AVPacket *pkt, int dump_payload, AVStream *st) + { +- pkt_dump_internal(avcl, NULL, level, pkt, dump_payload); ++ pkt_dump_internal(NULL, f, 0, pkt, dump_payload, st->time_base); + } + +-#if FF_API_URL_SPLIT +-attribute_deprecated +-void ff_url_split(char *proto, int proto_size, +- char *authorization, int authorization_size, +- char *hostname, int hostname_size, +- int *port_ptr, +- char *path, int path_size, +- const char *url) ++#if FF_API_PKT_DUMP ++void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) + { +- av_url_split(proto, proto_size, +- authorization, authorization_size, +- hostname, hostname_size, +- port_ptr, +- path, path_size, +- url); ++ AVRational tb = { 1, AV_TIME_BASE }; ++ pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, tb); + } + #endif + ++void av_pkt_dump_log2(void *avcl, int level, AVPacket *pkt, int dump_payload, ++ AVStream *st) ++{ ++ pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base); ++} ++ + void av_url_split(char *proto, int proto_size, + char *authorization, int authorization_size, + char *hostname, int hostname_size, +@@ -3784,19 +4150,30 @@ + return len; + } + ++#if FF_API_SET_PTS_INFO + void av_set_pts_info(AVStream *s, int pts_wrap_bits, + unsigned int pts_num, unsigned int pts_den) + { +- s->pts_wrap_bits = pts_wrap_bits; ++ avpriv_set_pts_info(s, pts_wrap_bits, pts_num, pts_den); ++} ++#endif + +- if(av_reduce(&s->time_base.num, &s->time_base.den, pts_num, pts_den, INT_MAX)){ +- if(s->time_base.num != pts_num) +- av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", s->index, pts_num/s->time_base.num); ++void avpriv_set_pts_info(AVStream *s, int pts_wrap_bits, ++ unsigned int pts_num, unsigned int pts_den) ++{ ++ AVRational new_tb; ++ if(av_reduce(&new_tb.num, &new_tb.den, pts_num, pts_den, INT_MAX)){ ++ if(new_tb.num != pts_num) ++ av_log(NULL, AV_LOG_DEBUG, "st:%d removing common factor %d from timebase\n", s->index, pts_num/new_tb.num); + }else + av_log(NULL, AV_LOG_WARNING, "st:%d has too large timebase, reducing\n", s->index); + +- if(!s->time_base.num || !s->time_base.den) +- s->time_base.num= s->time_base.den= 0; ++ if(new_tb.num <= 0 || new_tb.den <= 0) { ++ av_log(NULL, AV_LOG_ERROR, "Ignoring attempt to set invalid timebase for st:%d\n", s->index); ++ return; ++ } ++ s->time_base = new_tb; ++ s->pts_wrap_bits = pts_wrap_bits; + } + + int ff_url_join(char *str, int size, const char *proto, +@@ -3925,3 +4302,158 @@ + } + return -1; + } ++ ++void ff_make_absolute_url(char *buf, int size, const char *base, ++ const char *rel) ++{ ++ char *sep; ++ /* Absolute path, relative to the current server */ ++ if (base && strstr(base, "://") && rel[0] == '/') { ++ if (base != buf) ++ av_strlcpy(buf, base, size); ++ sep = strstr(buf, "://"); ++ if (sep) { ++ sep += 3; ++ sep = strchr(sep, '/'); ++ if (sep) ++ *sep = '\0'; ++ } ++ av_strlcat(buf, rel, size); ++ return; ++ } ++ /* If rel actually is an absolute url, just copy it */ ++ if (!base || strstr(rel, "://") || rel[0] == '/') { ++ av_strlcpy(buf, rel, size); ++ return; ++ } ++ if (base != buf) ++ av_strlcpy(buf, base, size); ++ /* Remove the file name from the base url */ ++ sep = strrchr(buf, '/'); ++ if (sep) ++ sep[1] = '\0'; ++ else ++ buf[0] = '\0'; ++ while (av_strstart(rel, "../", NULL) && sep) { ++ /* Remove the path delimiter at the end */ ++ sep[0] = '\0'; ++ sep = strrchr(buf, '/'); ++ /* If the next directory name to pop off is "..", break here */ ++ if (!strcmp(sep ? &sep[1] : buf, "..")) { ++ /* Readd the slash we just removed */ ++ av_strlcat(buf, "/", size); ++ break; ++ } ++ /* Cut off the directory name */ ++ if (sep) ++ sep[1] = '\0'; ++ else ++ buf[0] = '\0'; ++ rel += 3; ++ } ++ av_strlcat(buf, rel, size); ++} ++ ++int64_t ff_iso8601_to_unix_time(const char *datestr) ++{ ++#if HAVE_STRPTIME ++ struct tm time1 = {0}, time2 = {0}; ++ char *ret1, *ret2; ++ ret1 = strptime(datestr, "%Y - %m - %d %T", &time1); ++ ret2 = strptime(datestr, "%Y - %m - %dT%T", &time2); ++ if (ret2 && !ret1) ++ return av_timegm(&time2); ++ else ++ return av_timegm(&time1); ++#else ++ av_log(NULL, AV_LOG_WARNING, "strptime() unavailable on this system, cannot convert " ++ "the date string.\n"); ++ return 0; ++#endif ++} ++ ++int avformat_query_codec(AVOutputFormat *ofmt, enum CodecID codec_id, int std_compliance) ++{ ++ if (ofmt) { ++ if (ofmt->query_codec) ++ return ofmt->query_codec(codec_id, std_compliance); ++ else if (ofmt->codec_tag) ++ return !!av_codec_get_tag(ofmt->codec_tag, codec_id); ++ else if (codec_id == ofmt->video_codec || codec_id == ofmt->audio_codec || ++ codec_id == ofmt->subtitle_codec) ++ return 1; ++ } ++ return AVERROR_PATCHWELCOME; ++} ++ ++int avformat_network_init(void) ++{ ++#if CONFIG_NETWORK ++ int ret; ++ ff_network_inited_globally = 1; ++ if ((ret = ff_network_init()) < 0) ++ return ret; ++ ff_tls_init(); ++#endif ++ return 0; ++} ++ ++int avformat_network_deinit(void) ++{ ++#if CONFIG_NETWORK ++ ff_network_close(); ++ ff_tls_deinit(); ++#endif ++ return 0; ++} ++ ++int ff_add_param_change(AVPacket *pkt, int32_t channels, ++ uint64_t channel_layout, int32_t sample_rate, ++ int32_t width, int32_t height) ++{ ++ uint32_t flags = 0; ++ int size = 4; ++ uint8_t *data; ++ if (!pkt) ++ return AVERROR(EINVAL); ++ if (channels) { ++ size += 4; ++ flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT; ++ } ++ if (channel_layout) { ++ size += 8; ++ flags |= AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT; ++ } ++ if (sample_rate) { ++ size += 4; ++ flags |= AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE; ++ } ++ if (width || height) { ++ size += 8; ++ flags |= AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS; ++ } ++ data = av_packet_new_side_data(pkt, AV_PKT_DATA_PARAM_CHANGE, size); ++ if (!data) ++ return AVERROR(ENOMEM); ++ bytestream_put_le32(&data, flags); ++ if (channels) ++ bytestream_put_le32(&data, channels); ++ if (channel_layout) ++ bytestream_put_le64(&data, channel_layout); ++ if (sample_rate) ++ bytestream_put_le32(&data, sample_rate); ++ if (width || height) { ++ bytestream_put_le32(&data, width); ++ bytestream_put_le32(&data, height); ++ } ++ return 0; ++} ++ ++const struct AVCodecTag *avformat_get_riff_video_tags(void) ++{ ++ return ff_codec_bmp_tags; ++} ++const struct AVCodecTag *avformat_get_riff_audio_tags(void) ++{ ++ return ff_codec_wav_tags; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vc1test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vc1test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vc1test.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vc1test.c 2012-05-14 14:08:55.247358357 +0200 +@@ -28,6 +28,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define VC1_EXTRADATA_SIZE 4 + +@@ -44,17 +45,17 @@ + static int vc1t_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + int frames; + uint32_t fps; + +- frames = get_le24(pb); +- if(get_byte(pb) != 0xC5 || get_le32(pb) != 4) ++ frames = avio_rl24(pb); ++ if(avio_r8(pb) != 0xC5 || avio_rl32(pb) != 4) + return -1; + + /* init video codec */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + +@@ -63,21 +64,21 @@ + + st->codec->extradata = av_malloc(VC1_EXTRADATA_SIZE); + st->codec->extradata_size = VC1_EXTRADATA_SIZE; +- get_buffer(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); +- st->codec->height = get_le32(pb); +- st->codec->width = get_le32(pb); +- if(get_le32(pb) != 0xC) ++ avio_read(pb, st->codec->extradata, VC1_EXTRADATA_SIZE); ++ st->codec->height = avio_rl32(pb); ++ st->codec->width = avio_rl32(pb); ++ if(avio_rl32(pb) != 0xC) + return -1; +- url_fskip(pb, 8); +- fps = get_le32(pb); ++ avio_skip(pb, 8); ++ fps = avio_rl32(pb); + if(fps == 0xFFFFFFFF) +- av_set_pts_info(st, 32, 1, 1000); ++ avpriv_set_pts_info(st, 32, 1, 1000); + else{ + if (!fps) { + av_log(s, AV_LOG_ERROR, "Zero FPS specified, defaulting to 1 FPS\n"); + fps = 1; + } +- av_set_pts_info(st, 24, 1, fps); ++ avpriv_set_pts_info(st, 24, 1, fps); + st->duration = frames; + } + +@@ -87,7 +88,7 @@ + static int vc1t_read_packet(AVFormatContext *s, + AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int frame_size; + int keyframe = 0; + uint32_t pts; +@@ -95,10 +96,10 @@ + if(url_feof(pb)) + return AVERROR(EIO); + +- frame_size = get_le24(pb); +- if(get_byte(pb) & 0x80) ++ frame_size = avio_rl24(pb); ++ if(avio_r8(pb) & 0x80) + keyframe = 1; +- pts = get_le32(pb); ++ pts = avio_rl32(pb); + if(av_get_packet(pb, pkt, frame_size) < 0) + return AVERROR(EIO); + if(s->streams[0]->time_base.den == 1000) +@@ -110,11 +111,10 @@ + } + + AVInputFormat ff_vc1t_demuxer = { +- "vc1test", +- NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"), +- 0, +- vc1t_probe, +- vc1t_read_header, +- vc1t_read_packet, ++ .name = "vc1test", ++ .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream format"), ++ .read_probe = vc1t_probe, ++ .read_header = vc1t_read_header, ++ .read_packet = vc1t_read_packet, + .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vc1testenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vc1testenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vc1testenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vc1testenc.c 2012-05-14 14:08:55.248358378 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "internal.h" + + typedef struct RCVContext { + int frames; +@@ -27,27 +28,27 @@ + static int vc1test_write_header(AVFormatContext *s) + { + AVCodecContext *avc = s->streams[0]->codec; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (avc->codec_id != CODEC_ID_WMV3) { + av_log(s, AV_LOG_ERROR, "Only WMV3 is accepted!\n"); + return -1; + } +- put_le24(pb, 0); //frames count will be here +- put_byte(pb, 0xC5); +- put_le32(pb, 4); +- put_buffer(pb, avc->extradata, 4); +- put_le32(pb, avc->height); +- put_le32(pb, avc->width); +- put_le32(pb, 0xC); +- put_le24(pb, 0); // hrd_buffer +- put_byte(pb, 0x80); // level|cbr|res1 +- put_le32(pb, 0); // hrd_rate ++ avio_wl24(pb, 0); //frames count will be here ++ avio_w8(pb, 0xC5); ++ avio_wl32(pb, 4); ++ avio_write(pb, avc->extradata, 4); ++ avio_wl32(pb, avc->height); ++ avio_wl32(pb, avc->width); ++ avio_wl32(pb, 0xC); ++ avio_wl24(pb, 0); // hrd_buffer ++ avio_w8(pb, 0x80); // level|cbr|res1 ++ avio_wl32(pb, 0); // hrd_rate + if (s->streams[0]->r_frame_rate.den && s->streams[0]->r_frame_rate.num == 1) +- put_le32(pb, s->streams[0]->r_frame_rate.den); ++ avio_wl32(pb, s->streams[0]->r_frame_rate.den); + else +- put_le32(pb, 0xFFFFFFFF); //variable framerate +- av_set_pts_info(s->streams[0], 32, 1, 1000); ++ avio_wl32(pb, 0xFFFFFFFF); //variable framerate ++ avpriv_set_pts_info(s->streams[0], 32, 1, 1000); + + return 0; + } +@@ -55,14 +56,14 @@ + static int vc1test_write_packet(AVFormatContext *s, AVPacket *pkt) + { + RCVContext *ctx = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (!pkt->size) + return 0; +- put_le32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); +- put_le32(pb, pkt->pts); +- put_buffer(pb, pkt->data, pkt->size); +- put_flush_packet(pb); ++ avio_wl32(pb, pkt->size | ((pkt->flags & AV_PKT_FLAG_KEY) ? 0x80000000 : 0)); ++ avio_wl32(pb, pkt->pts); ++ avio_write(pb, pkt->data, pkt->size); ++ avio_flush(pb); + ctx->frames++; + + return 0; +@@ -71,25 +72,24 @@ + static int vc1test_write_trailer(AVFormatContext *s) + { + RCVContext *ctx = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + +- if (!url_is_streamed(s->pb)) { +- url_fseek(pb, 0, SEEK_SET); +- put_le24(pb, ctx->frames); +- put_flush_packet(pb); ++ if (s->pb->seekable) { ++ avio_seek(pb, 0, SEEK_SET); ++ avio_wl24(pb, ctx->frames); ++ avio_flush(pb); + } + return 0; + } + + AVOutputFormat ff_vc1t_muxer = { +- "rcv", +- NULL_IF_CONFIG_SMALL("VC-1 test bitstream"), +- "", +- "rcv", +- sizeof(RCVContext), +- CODEC_ID_NONE, +- CODEC_ID_WMV3, +- vc1test_write_header, +- vc1test_write_packet, +- vc1test_write_trailer, ++ .name = "rcv", ++ .long_name = NULL_IF_CONFIG_SMALL("VC-1 test bitstream"), ++ .extensions = "rcv", ++ .priv_data_size = sizeof(RCVContext), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_WMV3, ++ .write_header = vc1test_write_header, ++ .write_packet = vc1test_write_packet, ++ .write_trailer = vc1test_write_trailer, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/version.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/version.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/version.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/version.h 2012-05-14 14:08:55.249358398 +0200 +@@ -21,11 +21,17 @@ + #ifndef AVFORMAT_VERSION_H + #define AVFORMAT_VERSION_H + ++/** ++ * @file ++ * @ingroup libavf ++ * Libavformat version macros ++ */ ++ + #include "libavutil/avutil.h" + +-#define LIBAVFORMAT_VERSION_MAJOR 52 +-#define LIBAVFORMAT_VERSION_MINOR 94 +-#define LIBAVFORMAT_VERSION_MICRO 0 ++#define LIBAVFORMAT_VERSION_MAJOR 53 ++#define LIBAVFORMAT_VERSION_MINOR 32 ++#define LIBAVFORMAT_VERSION_MICRO 100 + + #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \ + LIBAVFORMAT_VERSION_MINOR, \ +@@ -41,53 +47,83 @@ + * Those FF_API_* defines are not part of public API. + * They may change, break or disappear at any time. + */ +-#ifndef FF_API_MAX_STREAMS +-#define FF_API_MAX_STREAMS (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_OLD_METADATA2 ++#define FF_API_OLD_METADATA2 (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_AVIO ++#define FF_API_OLD_AVIO (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_OLD_METADATA +-#define FF_API_OLD_METADATA (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_DUMP_FORMAT ++#define FF_API_DUMP_FORMAT (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_URL_CLASS +-#define FF_API_URL_CLASS (LIBAVFORMAT_VERSION_MAJOR >= 53) ++#ifndef FF_API_PARSE_DATE ++#define FF_API_PARSE_DATE (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_URL_RESETBUF +-#define FF_API_URL_RESETBUF (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_FIND_INFO_TAG ++#define FF_API_FIND_INFO_TAG (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_REGISTER_PROTOCOL +-#define FF_API_REGISTER_PROTOCOL (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_PKT_DUMP ++#define FF_API_PKT_DUMP (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_GUESS_FORMAT +-#define FF_API_GUESS_FORMAT (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_GUESS_IMG2_CODEC ++#define FF_API_GUESS_IMG2_CODEC (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_UDP_GET_FILE +-#define FF_API_UDP_GET_FILE (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_SDP_CREATE ++#define FF_API_SDP_CREATE (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_URL_SPLIT +-#define FF_API_URL_SPLIT (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_ALLOC_OUTPUT_CONTEXT ++#define FF_API_ALLOC_OUTPUT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_ALLOC_FORMAT_CONTEXT +-#define FF_API_ALLOC_FORMAT_CONTEXT (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_FORMAT_PARAMETERS ++#define FF_API_FORMAT_PARAMETERS (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_PARSE_FRAME_PARAM +-#define FF_API_PARSE_FRAME_PARAM (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_FLAG_RTP_HINT ++#define FF_API_FLAG_RTP_HINT (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_READ_SEEK +-#define FF_API_READ_SEEK (LIBAVFORMAT_VERSION_MAJOR < 54) ++#ifndef FF_API_AVSTREAM_QUALITY ++#define FF_API_AVSTREAM_QUALITY (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_LAVF_UNUSED +-#define FF_API_LAVF_UNUSED (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_LOOP_INPUT ++#define FF_API_LOOP_INPUT (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_PARAMETERS_CODEC_ID +-#define FF_API_PARAMETERS_CODEC_ID (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_LOOP_OUTPUT ++#define FF_API_LOOP_OUTPUT (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_FIRST_FORMAT +-#define FF_API_FIRST_FORMAT (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_TIMESTAMP ++#define FF_API_TIMESTAMP (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_SYMVER +-#define FF_API_SYMVER (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_FILESIZE ++#define FF_API_FILESIZE (LIBAVFORMAT_VERSION_MAJOR < 54) + #endif +-#ifndef FF_API_OLD_AVIO +-#define FF_API_OLD_AVIO (LIBAVFORMAT_VERSION_MAJOR < 53) ++#ifndef FF_API_MUXRATE ++#define FF_API_MUXRATE (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_RTSP_URL_OPTIONS ++#define FF_API_RTSP_URL_OPTIONS (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_NEW_STREAM ++#define FF_API_NEW_STREAM (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_PRELOAD ++#define FF_API_PRELOAD (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_STREAM_COPY ++#define FF_API_STREAM_COPY (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_SEEK_PUBLIC ++#define FF_API_SEEK_PUBLIC (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_REORDER_PRIVATE ++#define FF_API_REORDER_PRIVATE (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_OLD_INTERRUPT_CB ++#define FF_API_OLD_INTERRUPT_CB (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_SET_PTS_INFO ++#define FF_API_SET_PTS_INFO (LIBAVFORMAT_VERSION_MAJOR < 54) ++#endif ++#ifndef FF_API_CLOSE_INPUT_FILE ++#define FF_API_CLOSE_INPUT_FILE (LIBAVFORMAT_VERSION_MAJOR < 55) + #endif + +-#endif //AVFORMAT_VERSION_H ++#endif /* AVFORMAT_VERSION_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vocdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vocdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vocdec.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vocdec.c 2012-05-14 14:08:55.250358418 +0200 +@@ -41,18 +41,18 @@ + static int voc_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + VocDecContext *voc = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int header_size; + AVStream *st; + +- url_fskip(pb, 20); +- header_size = get_le16(pb) - 22; ++ avio_skip(pb, 20); ++ header_size = avio_rl16(pb) - 22; + if (header_size != 4) { + av_log(s, AV_LOG_ERROR, "unknown header size: %d\n", header_size); + return AVERROR(ENOSYS); + } +- url_fskip(pb, header_size); +- st = av_new_stream(s, 0); ++ avio_skip(pb, header_size); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -66,31 +66,31 @@ + { + VocDecContext *voc = s->priv_data; + AVCodecContext *dec = st->codec; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + VocType type; + int size, tmp_codec=-1; + int sample_rate = 0; + int channels = 1; + + while (!voc->remaining_size) { +- type = get_byte(pb); ++ type = avio_r8(pb); + if (type == VOC_TYPE_EOF) + return AVERROR(EIO); +- voc->remaining_size = get_le24(pb); ++ voc->remaining_size = avio_rl24(pb); + if (!voc->remaining_size) { +- if (url_is_streamed(s->pb)) ++ if (!s->pb->seekable) + return AVERROR(EIO); +- voc->remaining_size = url_fsize(pb) - url_ftell(pb); ++ voc->remaining_size = avio_size(pb) - avio_tell(pb); + } + max_size -= 4; + + switch (type) { + case VOC_TYPE_VOICE_DATA: +- dec->sample_rate = 1000000 / (256 - get_byte(pb)); ++ dec->sample_rate = 1000000 / (256 - avio_r8(pb)); + if (sample_rate) + dec->sample_rate = sample_rate; + dec->channels = channels; +- tmp_codec = get_byte(pb); ++ tmp_codec = avio_r8(pb); + dec->bits_per_coded_sample = av_get_bits_per_sample(dec->codec_id); + voc->remaining_size -= 2; + max_size -= 2; +@@ -101,26 +101,26 @@ + break; + + case VOC_TYPE_EXTENDED: +- sample_rate = get_le16(pb); +- get_byte(pb); +- channels = get_byte(pb) + 1; ++ sample_rate = avio_rl16(pb); ++ avio_r8(pb); ++ channels = avio_r8(pb) + 1; + sample_rate = 256000000 / (channels * (65536 - sample_rate)); + voc->remaining_size = 0; + max_size -= 4; + break; + + case VOC_TYPE_NEW_VOICE_DATA: +- dec->sample_rate = get_le32(pb); +- dec->bits_per_coded_sample = get_byte(pb); +- dec->channels = get_byte(pb); +- tmp_codec = get_le16(pb); +- url_fskip(pb, 4); ++ dec->sample_rate = avio_rl32(pb); ++ dec->bits_per_coded_sample = avio_r8(pb); ++ dec->channels = avio_r8(pb); ++ tmp_codec = avio_rl16(pb); ++ avio_skip(pb, 4); + voc->remaining_size -= 12; + max_size -= 12; + break; + + default: +- url_fskip(pb, voc->remaining_size); ++ avio_skip(pb, voc->remaining_size); + max_size -= voc->remaining_size; + voc->remaining_size = 0; + break; +@@ -142,7 +142,7 @@ + } + } + +- dec->bit_rate = dec->sample_rate * dec->bits_per_coded_sample; ++ dec->bit_rate = dec->sample_rate * dec->channels * dec->bits_per_coded_sample; + + if (max_size <= 0) + max_size = 2048; +@@ -157,11 +157,11 @@ + } + + AVInputFormat ff_voc_demuxer = { +- "voc", +- NULL_IF_CONFIG_SMALL("Creative Voice file format"), +- sizeof(VocDecContext), +- voc_probe, +- voc_read_header, +- voc_read_packet, ++ .name = "voc", ++ .long_name = NULL_IF_CONFIG_SMALL("Creative Voice file format"), ++ .priv_data_size = sizeof(VocDecContext), ++ .read_probe = voc_probe, ++ .read_header = voc_read_header, ++ .read_packet = voc_read_packet, + .codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vocenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vocenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vocenc.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vocenc.c 2012-05-14 14:08:55.251358438 +0200 +@@ -29,7 +29,7 @@ + + static int voc_write_header(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + const int header_size = 26; + const int version = 0x0114; + +@@ -37,10 +37,10 @@ + || s->streams[0]->codec->codec_type != AVMEDIA_TYPE_AUDIO) + return AVERROR_PATCHWELCOME; + +- put_buffer(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1); +- put_le16(pb, header_size); +- put_le16(pb, version); +- put_le16(pb, ~version + 0x1234); ++ avio_write(pb, ff_voc_magic, sizeof(ff_voc_magic) - 1); ++ avio_wl16(pb, header_size); ++ avio_wl16(pb, version); ++ avio_wl16(pb, ~version + 0x1234); + + return 0; + } +@@ -49,56 +49,56 @@ + { + VocEncContext *voc = s->priv_data; + AVCodecContext *enc = s->streams[0]->codec; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + if (!voc->param_written) { + if (enc->codec_tag > 0xFF) { +- put_byte(pb, VOC_TYPE_NEW_VOICE_DATA); +- put_le24(pb, pkt->size + 12); +- put_le32(pb, enc->sample_rate); +- put_byte(pb, enc->bits_per_coded_sample); +- put_byte(pb, enc->channels); +- put_le16(pb, enc->codec_tag); +- put_le32(pb, 0); ++ avio_w8(pb, VOC_TYPE_NEW_VOICE_DATA); ++ avio_wl24(pb, pkt->size + 12); ++ avio_wl32(pb, enc->sample_rate); ++ avio_w8(pb, enc->bits_per_coded_sample); ++ avio_w8(pb, enc->channels); ++ avio_wl16(pb, enc->codec_tag); ++ avio_wl32(pb, 0); + } else { + if (s->streams[0]->codec->channels > 1) { +- put_byte(pb, VOC_TYPE_EXTENDED); +- put_le24(pb, 4); +- put_le16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); +- put_byte(pb, enc->codec_tag); +- put_byte(pb, enc->channels - 1); ++ avio_w8(pb, VOC_TYPE_EXTENDED); ++ avio_wl24(pb, 4); ++ avio_wl16(pb, 65536-256000000/(enc->sample_rate*enc->channels)); ++ avio_w8(pb, enc->codec_tag); ++ avio_w8(pb, enc->channels - 1); + } +- put_byte(pb, VOC_TYPE_VOICE_DATA); +- put_le24(pb, pkt->size + 2); +- put_byte(pb, 256 - 1000000 / enc->sample_rate); +- put_byte(pb, enc->codec_tag); ++ avio_w8(pb, VOC_TYPE_VOICE_DATA); ++ avio_wl24(pb, pkt->size + 2); ++ avio_w8(pb, 256 - 1000000 / enc->sample_rate); ++ avio_w8(pb, enc->codec_tag); + } + voc->param_written = 1; + } else { +- put_byte(pb, VOC_TYPE_VOICE_DATA_CONT); +- put_le24(pb, pkt->size); ++ avio_w8(pb, VOC_TYPE_VOICE_DATA_CONT); ++ avio_wl24(pb, pkt->size); + } + +- put_buffer(pb, pkt->data, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); + return 0; + } + + static int voc_write_trailer(AVFormatContext *s) + { +- put_byte(s->pb, 0); ++ avio_w8(s->pb, 0); + return 0; + } + + AVOutputFormat ff_voc_muxer = { +- "voc", +- NULL_IF_CONFIG_SMALL("Creative Voice file format"), +- "audio/x-voc", +- "voc", +- sizeof(VocEncContext), +- CODEC_ID_PCM_U8, +- CODEC_ID_NONE, +- voc_write_header, +- voc_write_packet, +- voc_write_trailer, ++ .name = "voc", ++ .long_name = NULL_IF_CONFIG_SMALL("Creative Voice file format"), ++ .mime_type = "audio/x-voc", ++ .extensions = "voc", ++ .priv_data_size = sizeof(VocEncContext), ++ .audio_codec = CODEC_ID_PCM_U8, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = voc_write_header, ++ .write_packet = voc_write_packet, ++ .write_trailer = voc_write_trailer, + .codec_tag=(const AVCodecTag* const []){ff_voc_codec_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vorbiscomment.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vorbiscomment.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vorbiscomment.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vorbiscomment.c 2012-05-14 14:08:55.251358438 +0200 +@@ -23,6 +23,7 @@ + #include "metadata.h" + #include "vorbiscomment.h" + #include "libavcodec/bytestream.h" ++#include "libavutil/dict.h" + + /** + * VorbisComment metadata conversion mapping. +@@ -36,15 +37,15 @@ + { 0 } + }; + +-int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string, ++int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, + unsigned *count) + { + int len = 8; + len += strlen(vendor_string); + *count = 0; + if (m) { +- AVMetadataTag *tag = NULL; +- while ((tag = av_metadata_get(m, "", tag, AV_METADATA_IGNORE_SUFFIX))) { ++ AVDictionaryEntry *tag = NULL; ++ while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) { + len += 4 +strlen(tag->key) + 1 + strlen(tag->value); + (*count)++; + } +@@ -52,15 +53,15 @@ + return len; + } + +-int ff_vorbiscomment_write(uint8_t **p, AVMetadata **m, ++int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, + const char *vendor_string, const unsigned count) + { + bytestream_put_le32(p, strlen(vendor_string)); + bytestream_put_buffer(p, vendor_string, strlen(vendor_string)); + if (*m) { +- AVMetadataTag *tag = NULL; ++ AVDictionaryEntry *tag = NULL; + bytestream_put_le32(p, count); +- while ((tag = av_metadata_get(*m, "", tag, AV_METADATA_IGNORE_SUFFIX))) { ++ while ((tag = av_dict_get(*m, "", tag, AV_DICT_IGNORE_SUFFIX))) { + unsigned int len1 = strlen(tag->key); + unsigned int len2 = strlen(tag->value); + bytestream_put_le32(p, len1+1+len2); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vorbiscomment.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vorbiscomment.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vorbiscomment.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vorbiscomment.h 2012-05-14 14:08:55.252358458 +0200 +@@ -35,13 +35,13 @@ + * @param count Pointer to store the number of tags in m because m->count is "not allowed" + * @return The length in bytes. + */ +-int ff_vorbiscomment_length(AVMetadata *m, const char *vendor_string, ++int ff_vorbiscomment_length(AVDictionary *m, const char *vendor_string, + unsigned *count); + + /** +- * Writes a VorbisComment into a buffer. The buffer, p, must have enough ++ * Write a VorbisComment into a buffer. The buffer, p, must have enough + * data to hold the whole VorbisComment. The minimum size required can be +- * obtained by passing the same AVMetadata and vendor_string to ++ * obtained by passing the same AVDictionary and vendor_string to + * ff_vorbiscomment_length() + * + * @param p The buffer in which to write. +@@ -49,7 +49,7 @@ + * @param vendor_string The vendor string to write. + * @param count The number of tags in m because m->count is "not allowed" + */ +-int ff_vorbiscomment_write(uint8_t **p, AVMetadata **m, ++int ff_vorbiscomment_write(uint8_t **p, AVDictionary **m, + const char *vendor_string, const unsigned count); + + extern const AVMetadataConv ff_vorbiscomment_metadata_conv[]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vqf.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vqf.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/vqf.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/vqf.c 2012-05-14 14:08:55.253358478 +0200 +@@ -20,7 +20,11 @@ + */ + + #include "avformat.h" ++#include "internal.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" ++#include "libavutil/mathematics.h" ++#include "riff.h" + + typedef struct VqfContext { + int frame_bit_len; +@@ -42,11 +46,11 @@ + return AVPROBE_SCORE_MAX/2; + } + +-static void add_metadata(AVFormatContext *s, const char *tag, ++static void add_metadata(AVFormatContext *s, uint32_t tag, + unsigned int tag_len, unsigned int remaining) + { + int len = FFMIN(tag_len, remaining); +- char *buf; ++ char *buf, key[5] = {0}; + + if (len == UINT_MAX) + return; +@@ -54,27 +58,51 @@ + buf = av_malloc(len+1); + if (!buf) + return; +- get_buffer(s->pb, buf, len); ++ avio_read(s->pb, buf, len); + buf[len] = 0; +- av_metadata_set2(&s->metadata, tag, buf, AV_METADATA_DONT_STRDUP_VAL); ++ AV_WL32(key, tag); ++ av_dict_set(&s->metadata, key, buf, AV_DICT_DONT_STRDUP_VAL); + } + ++static const AVMetadataConv vqf_metadata_conv[] = { ++ { "(c) ", "copyright" }, ++ { "ARNG", "arranger" }, ++ { "AUTH", "author" }, ++ { "BAND", "band" }, ++ { "CDCT", "conductor" }, ++ { "COMT", "comment" }, ++ { "FILE", "filename" }, ++ { "GENR", "genre" }, ++ { "LABL", "publisher" }, ++ { "MUSC", "composer" }, ++ { "NAME", "title" }, ++ { "NOTE", "note" }, ++ { "PROD", "producer" }, ++ { "PRSN", "personnel" }, ++ { "REMX", "remixer" }, ++ { "SING", "singer" }, ++ { "TRCK", "track" }, ++ { "WORD", "words" }, ++ { 0 }, ++}; ++ + static int vqf_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + VqfContext *c = s->priv_data; +- AVStream *st = av_new_stream(s, 0); ++ AVStream *st = avformat_new_stream(s, NULL); + int chunk_tag; + int rate_flag = -1; + int header_size; + int read_bitrate = 0; + int size; ++ uint8_t comm_chunk[12]; + + if (!st) + return AVERROR(ENOMEM); + +- url_fskip(s->pb, 12); ++ avio_skip(s->pb, 12); + +- header_size = get_be32(s->pb); ++ header_size = avio_rb32(s->pb); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_TWINVQ; +@@ -82,12 +110,12 @@ + + do { + int len; +- chunk_tag = get_le32(s->pb); ++ chunk_tag = avio_rl32(s->pb); + + if (chunk_tag == MKTAG('D','A','T','A')) + break; + +- len = get_be32(s->pb); ++ len = avio_rb32(s->pb); + + if ((unsigned) len > INT_MAX/2) { + av_log(s, AV_LOG_ERROR, "Malformed header\n"); +@@ -98,49 +126,33 @@ + + switch(chunk_tag){ + case MKTAG('C','O','M','M'): +- st->codec->channels = get_be32(s->pb) + 1; +- read_bitrate = get_be32(s->pb); +- rate_flag = get_be32(s->pb); +- url_fskip(s->pb, len-12); ++ avio_read(s->pb, comm_chunk, 12); ++ st->codec->channels = AV_RB32(comm_chunk ) + 1; ++ read_bitrate = AV_RB32(comm_chunk + 4); ++ rate_flag = AV_RB32(comm_chunk + 8); ++ avio_skip(s->pb, len-12); + + st->codec->bit_rate = read_bitrate*1000; +- st->codec->bits_per_coded_sample = 16; +- break; +- case MKTAG('N','A','M','E'): +- add_metadata(s, "title" , len, header_size); +- break; +- case MKTAG('(','c',')',' '): +- add_metadata(s, "copyright", len, header_size); +- break; +- case MKTAG('A','U','T','H'): +- add_metadata(s, "author" , len, header_size); +- break; +- case MKTAG('A','L','B','M'): +- add_metadata(s, "album" , len, header_size); +- break; +- case MKTAG('T','R','C','K'): +- add_metadata(s, "track" , len, header_size); +- break; +- case MKTAG('C','O','M','T'): +- add_metadata(s, "comment" , len, header_size); + break; +- case MKTAG('F','I','L','E'): +- add_metadata(s, "filename" , len, header_size); +- break; +- case MKTAG('D','S','I','Z'): +- add_metadata(s, "size" , len, header_size); +- break; +- case MKTAG('D','A','T','E'): +- add_metadata(s, "date" , len, header_size); ++ case MKTAG('D','S','I','Z'): // size of compressed data ++ { ++ char buf[8] = {0}; ++ int size = avio_rb32(s->pb); ++ ++ snprintf(buf, sizeof(buf), "%d", size); ++ av_dict_set(&s->metadata, "size", buf, 0); ++ } + break; +- case MKTAG('G','E','N','R'): +- add_metadata(s, "genre" , len, header_size); ++ case MKTAG('Y','E','A','R'): // recording date ++ case MKTAG('E','N','C','D'): // compression date ++ case MKTAG('E','X','T','R'): // reserved ++ case MKTAG('_','Y','M','H'): // reserved ++ case MKTAG('_','N','T','T'): // reserved ++ case MKTAG('_','I','D','3'): // reserved for ID3 tags ++ avio_skip(s->pb, FFMIN(len, header_size)); + break; + default: +- av_log(s, AV_LOG_ERROR, "Unknown chunk: %c%c%c%c\n", +- ((char*)&chunk_tag)[0], ((char*)&chunk_tag)[1], +- ((char*)&chunk_tag)[2], ((char*)&chunk_tag)[3]); +- url_fskip(s->pb, FFMIN(len, header_size)); ++ add_metadata(s, chunk_tag, len, header_size); + break; + } + +@@ -189,7 +201,15 @@ + return -1; + } + c->frame_bit_len = st->codec->bit_rate*size/st->codec->sample_rate; +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ ++ /* put first 12 bytes of COMM chunk in extradata */ ++ if (!(st->codec->extradata = av_malloc(12 + FF_INPUT_BUFFER_PADDING_SIZE))) ++ return AVERROR(ENOMEM); ++ st->codec->extradata_size = 12; ++ memcpy(st->codec->extradata, comm_chunk, 12); ++ ++ ff_metadata_conv_ctx(s, NULL, vqf_metadata_conv); + + return 0; + } +@@ -200,7 +220,7 @@ + int ret; + int size = (c->frame_bit_len - c->remaining_bits + 7)>>3; + +- pkt->pos = url_ftell(s->pb); ++ pkt->pos = avio_tell(s->pb); + pkt->stream_index = 0; + + if (av_new_packet(pkt, size+2) < 0) +@@ -208,7 +228,7 @@ + + pkt->data[0] = 8 - c->remaining_bits; // Number of bits to skip + pkt->data[1] = c->last_frame_bits; +- ret = get_buffer(s->pb, pkt->data+2, size); ++ ret = avio_read(s->pb, pkt->data+2, size); + + if (ret<=0) { + av_free_packet(pkt); +@@ -240,7 +260,7 @@ + st->cur_dts = av_rescale(pos, st->time_base.den, + st->codec->bit_rate * (int64_t)st->time_base.num); + +- if ((ret = url_fseek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0) ++ if ((ret = avio_seek(s->pb, ((pos-7) >> 3) + s->data_offset, SEEK_SET)) < 0) + return ret; + + c->remaining_bits = -7 - ((pos-7)&7); +@@ -248,13 +268,12 @@ + } + + AVInputFormat ff_vqf_demuxer = { +- "vqf", +- NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"), +- sizeof(VqfContext), +- vqf_probe, +- vqf_read_header, +- vqf_read_packet, +- NULL, +- vqf_read_seek, +- .extensions = "vqf", ++ .name = "vqf", ++ .long_name = NULL_IF_CONFIG_SMALL("Nippon Telegraph and Telephone Corporation (NTT) TwinVQ"), ++ .priv_data_size = sizeof(VqfContext), ++ .read_probe = vqf_probe, ++ .read_header = vqf_read_header, ++ .read_packet = vqf_read_packet, ++ .read_seek = vqf_read_seek, ++ .extensions = "vqf,vql,vqe", + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wav.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wav.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wav.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wav.c 2012-05-14 14:08:55.256358538 +0200 +@@ -22,64 +22,140 @@ + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ ++ ++#include "libavutil/avassert.h" ++#include "libavutil/dict.h" ++#include "libavutil/log.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/opt.h" + #include "avformat.h" ++#include "internal.h" ++#include "avio_internal.h" + #include "pcm.h" + #include "riff.h" ++#include "avio.h" ++#include "metadata.h" + + typedef struct { ++ const AVClass *class; + int64_t data; + int64_t data_end; + int64_t minpts; + int64_t maxpts; + int last_duration; + int w64; ++ int write_bext; ++ int64_t smv_data_ofs; ++ int smv_block_size; ++ int smv_frames_per_jpeg; ++ int smv_block; ++ int smv_last_stream; ++ int smv_eof; ++ int audio_eof; ++ int ignore_length; + } WAVContext; + + #if CONFIG_WAV_MUXER ++static inline void bwf_write_bext_string(AVFormatContext *s, const char *key, int maxlen) ++{ ++ AVDictionaryEntry *tag; ++ int len = 0; ++ ++ if (tag = av_dict_get(s->metadata, key, NULL, 0)) { ++ len = strlen(tag->value); ++ len = FFMIN(len, maxlen); ++ avio_write(s->pb, tag->value, len); ++ } ++ ++ ffio_fill(s->pb, 0, maxlen - len); ++} ++ ++static void bwf_write_bext_chunk(AVFormatContext *s) ++{ ++ AVDictionaryEntry *tmp_tag; ++ uint64_t time_reference = 0; ++ int64_t bext = ff_start_tag(s->pb, "bext"); ++ ++ bwf_write_bext_string(s, "description", 256); ++ bwf_write_bext_string(s, "originator", 32); ++ bwf_write_bext_string(s, "originator_reference", 32); ++ bwf_write_bext_string(s, "origination_date", 10); ++ bwf_write_bext_string(s, "origination_time", 8); ++ ++ if (tmp_tag = av_dict_get(s->metadata, "time_reference", NULL, 0)) ++ time_reference = strtoll(tmp_tag->value, NULL, 10); ++ avio_wl64(s->pb, time_reference); ++ avio_wl16(s->pb, 1); // set version to 1 ++ ++ if (tmp_tag = av_dict_get(s->metadata, "umid", NULL, 0)) { ++ unsigned char umidpart_str[17] = {0}; ++ int i; ++ uint64_t umidpart; ++ int len = strlen(tmp_tag->value+2); ++ ++ for (i = 0; i < len/16; i++) { ++ memcpy(umidpart_str, tmp_tag->value + 2 + (i*16), 16); ++ umidpart = strtoll(umidpart_str, NULL, 16); ++ avio_wb64(s->pb, umidpart); ++ } ++ ffio_fill(s->pb, 0, 64 - i*8); ++ } else ++ ffio_fill(s->pb, 0, 64); // zero UMID ++ ++ ffio_fill(s->pb, 0, 190); // Reserved ++ ++ if (tmp_tag = av_dict_get(s->metadata, "coding_history", NULL, 0)) ++ avio_put_str(s->pb, tmp_tag->value); ++ ++ ff_end_tag(s->pb, bext); ++} ++ + static int wav_write_header(AVFormatContext *s) + { + WAVContext *wav = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + int64_t fmt, fact; + +- put_tag(pb, "RIFF"); +- put_le32(pb, 0); /* file length */ +- put_tag(pb, "WAVE"); ++ ffio_wfourcc(pb, "RIFF"); ++ avio_wl32(pb, 0); /* file length */ ++ ffio_wfourcc(pb, "WAVE"); + + /* format header */ + fmt = ff_start_tag(pb, "fmt "); + if (ff_put_wav_header(pb, s->streams[0]->codec) < 0) { + av_log(s, AV_LOG_ERROR, "%s codec not supported in WAVE format\n", + s->streams[0]->codec->codec ? s->streams[0]->codec->codec->name : "NONE"); +- av_free(wav); + return -1; + } + ff_end_tag(pb, fmt); + + if (s->streams[0]->codec->codec_tag != 0x01 /* hence for all other than PCM */ +- && !url_is_streamed(s->pb)) { ++ && s->pb->seekable) { + fact = ff_start_tag(pb, "fact"); +- put_le32(pb, 0); ++ avio_wl32(pb, 0); + ff_end_tag(pb, fact); + } + +- av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); ++ if (wav->write_bext) ++ bwf_write_bext_chunk(s); ++ ++ avpriv_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate); + wav->maxpts = wav->last_duration = 0; + wav->minpts = INT64_MAX; + + /* data header */ + wav->data = ff_start_tag(pb, "data"); + +- put_flush_packet(pb); ++ avio_flush(pb); + + return 0; + } + + static int wav_write_packet(AVFormatContext *s, AVPacket *pkt) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + WAVContext *wav = s->priv_data; +- put_buffer(pb, pkt->data, pkt->size); ++ avio_write(pb, pkt->data, pkt->size); + if(pkt->pts != AV_NOPTS_VALUE) { + wav->minpts = FFMIN(wav->minpts, pkt->pts); + wav->maxpts = FFMAX(wav->maxpts, pkt->pts); +@@ -91,22 +167,22 @@ + + static int wav_write_trailer(AVFormatContext *s) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + WAVContext *wav = s->priv_data; + int64_t file_size; + +- put_flush_packet(pb); ++ avio_flush(pb); + +- if (!url_is_streamed(s->pb)) { ++ if (s->pb->seekable) { + ff_end_tag(pb, wav->data); + + /* update file size */ +- file_size = url_ftell(pb); +- url_fseek(pb, 4, SEEK_SET); +- put_le32(pb, (uint32_t)(file_size - 8)); +- url_fseek(pb, file_size, SEEK_SET); ++ file_size = avio_tell(pb); ++ avio_seek(pb, 4, SEEK_SET); ++ avio_wl32(pb, (uint32_t)(file_size - 8)); ++ avio_seek(pb, file_size, SEEK_SET); + +- put_flush_packet(pb); ++ avio_flush(pb); + + if(s->streams[0]->codec->codec_tag != 0x01) { + /* Update num_samps in fact chunk */ +@@ -114,41 +190,56 @@ + number_of_samples = av_rescale(wav->maxpts - wav->minpts + wav->last_duration, + s->streams[0]->codec->sample_rate * (int64_t)s->streams[0]->time_base.num, + s->streams[0]->time_base.den); +- url_fseek(pb, wav->data-12, SEEK_SET); +- put_le32(pb, number_of_samples); +- url_fseek(pb, file_size, SEEK_SET); +- put_flush_packet(pb); ++ avio_seek(pb, wav->data-12, SEEK_SET); ++ avio_wl32(pb, number_of_samples); ++ avio_seek(pb, file_size, SEEK_SET); ++ avio_flush(pb); + } + } + return 0; + } + ++#define OFFSET(x) offsetof(WAVContext, x) ++#define ENC AV_OPT_FLAG_ENCODING_PARAM ++static const AVOption options[] = { ++ { "write_bext", "Write BEXT chunk.", OFFSET(write_bext), AV_OPT_TYPE_INT, { 0 }, 0, 1, ENC }, ++ { NULL }, ++}; ++ ++static const AVClass wav_muxer_class = { ++ .class_name = "WAV muxer", ++ .item_name = av_default_item_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; ++ + AVOutputFormat ff_wav_muxer = { +- "wav", +- NULL_IF_CONFIG_SMALL("WAV format"), +- "audio/x-wav", +- "wav", +- sizeof(WAVContext), +- CODEC_ID_PCM_S16LE, +- CODEC_ID_NONE, +- wav_write_header, +- wav_write_packet, +- wav_write_trailer, ++ .name = "wav", ++ .long_name = NULL_IF_CONFIG_SMALL("WAV format"), ++ .mime_type = "audio/x-wav", ++ .extensions = "wav", ++ .priv_data_size = sizeof(WAVContext), ++ .audio_codec = CODEC_ID_PCM_S16LE, ++ .video_codec = CODEC_ID_NONE, ++ .write_header = wav_write_header, ++ .write_packet = wav_write_packet, ++ .write_trailer = wav_write_trailer, + .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, ++ .priv_class = &wav_muxer_class, + }; + #endif /* CONFIG_WAV_MUXER */ + + + #if CONFIG_WAV_DEMUXER + +-static int64_t next_tag(ByteIOContext *pb, unsigned int *tag) ++static int64_t next_tag(AVIOContext *pb, uint32_t *tag) + { +- *tag = get_le32(pb); +- return get_le32(pb); ++ *tag = avio_rl32(pb); ++ return avio_rl32(pb); + } + + /* return the size of the found tag */ +-static int64_t find_tag(ByteIOContext *pb, uint32_t tag1) ++static int64_t find_tag(AVIOContext *pb, uint32_t tag1) + { + unsigned int tag; + int64_t size; +@@ -159,7 +250,7 @@ + size = next_tag(pb, &tag); + if (tag == tag1) + break; +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + } + return size; + } +@@ -184,6 +275,117 @@ + return 0; + } + ++static int wav_parse_fmt_tag(AVFormatContext *s, int64_t size, AVStream **st) ++{ ++ AVIOContext *pb = s->pb; ++ int ret; ++ ++ /* parse fmt header */ ++ *st = avformat_new_stream(s, NULL); ++ if (!*st) ++ return AVERROR(ENOMEM); ++ ++ ret = ff_get_wav_header(pb, (*st)->codec, size); ++ if (ret < 0) ++ return ret; ++ (*st)->need_parsing = AVSTREAM_PARSE_FULL; ++ ++ avpriv_set_pts_info(*st, 64, 1, (*st)->codec->sample_rate); ++ ++ return 0; ++} ++ ++static inline int wav_parse_bext_string(AVFormatContext *s, const char *key, ++ int length) ++{ ++ char temp[257]; ++ int ret; ++ ++ av_assert0(length <= sizeof(temp)); ++ if ((ret = avio_read(s->pb, temp, length)) < 0) ++ return ret; ++ ++ temp[length] = 0; ++ ++ if (strlen(temp)) ++ return av_dict_set(&s->metadata, key, temp, 0); ++ ++ return 0; ++} ++ ++static int wav_parse_bext_tag(AVFormatContext *s, int64_t size) ++{ ++ char temp[131], *coding_history; ++ int ret, x; ++ uint64_t time_reference; ++ int64_t umid_parts[8], umid_mask = 0; ++ ++ if ((ret = wav_parse_bext_string(s, "description", 256)) < 0 || ++ (ret = wav_parse_bext_string(s, "originator", 32)) < 0 || ++ (ret = wav_parse_bext_string(s, "originator_reference", 32)) < 0 || ++ (ret = wav_parse_bext_string(s, "origination_date", 10)) < 0 || ++ (ret = wav_parse_bext_string(s, "origination_time", 8)) < 0) ++ return ret; ++ ++ time_reference = avio_rl64(s->pb); ++ snprintf(temp, sizeof(temp), "%"PRIu64, time_reference); ++ if ((ret = av_dict_set(&s->metadata, "time_reference", temp, 0)) < 0) ++ return ret; ++ ++ /* check if version is >= 1, in which case an UMID may be present */ ++ if (avio_rl16(s->pb) >= 1) { ++ for (x = 0; x < 8; x++) ++ umid_mask |= umid_parts[x] = avio_rb64(s->pb); ++ ++ if (umid_mask) { ++ /* the string formatting below is per SMPTE 330M-2004 Annex C */ ++ if (umid_parts[4] == 0 && umid_parts[5] == 0 && umid_parts[6] == 0 && umid_parts[7] == 0) { ++ /* basic UMID */ ++ snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64, ++ umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3]); ++ } else { ++ /* extended UMID */ ++ snprintf(temp, sizeof(temp), "0x%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64 ++ "%016"PRIX64"%016"PRIX64"%016"PRIX64"%016"PRIX64, ++ umid_parts[0], umid_parts[1], umid_parts[2], umid_parts[3], ++ umid_parts[4], umid_parts[5], umid_parts[6], umid_parts[7]); ++ } ++ ++ if ((ret = av_dict_set(&s->metadata, "umid", temp, 0)) < 0) ++ return ret; ++ } ++ ++ avio_skip(s->pb, 190); ++ } else ++ avio_skip(s->pb, 254); ++ ++ if (size > 602) { ++ /* CodingHistory present */ ++ size -= 602; ++ ++ if (!(coding_history = av_malloc(size+1))) ++ return AVERROR(ENOMEM); ++ ++ if ((ret = avio_read(s->pb, coding_history, size)) < 0) ++ return ret; ++ ++ coding_history[size] = 0; ++ if ((ret = av_dict_set(&s->metadata, "coding_history", coding_history, ++ AV_DICT_DONT_STRDUP_VAL)) < 0) ++ return ret; ++ } ++ ++ return 0; ++} ++ ++static const AVMetadataConv wav_metadata_conv[] = { ++ {"description", "comment" }, ++ {"originator", "encoded_by" }, ++ {"origination_date", "date" }, ++ {"origination_time", "creation_time"}, ++ {0}, ++}; ++ + /* wav input */ + static int wav_read_header(AVFormatContext *s, + AVFormatParameters *ap) +@@ -191,91 +393,173 @@ + int64_t size, av_uninit(data_size); + int64_t sample_count=0; + int rf64; +- unsigned int tag; +- ByteIOContext *pb = s->pb; +- AVStream *st; ++ uint32_t tag, list_type; ++ AVIOContext *pb = s->pb; ++ AVStream *st = NULL; + WAVContext *wav = s->priv_data; ++ int ret, got_fmt = 0; ++ int64_t next_tag_ofs, data_ofs = -1; ++ ++ wav->smv_data_ofs = -1; + + /* check RIFF header */ +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + + rf64 = tag == MKTAG('R', 'F', '6', '4'); + if (!rf64 && tag != MKTAG('R', 'I', 'F', 'F')) + return -1; +- get_le32(pb); /* file size */ +- tag = get_le32(pb); ++ avio_rl32(pb); /* file size */ ++ tag = avio_rl32(pb); + if (tag != MKTAG('W', 'A', 'V', 'E')) + return -1; + + if (rf64) { +- if (get_le32(pb) != MKTAG('d', 's', '6', '4')) ++ if (avio_rl32(pb) != MKTAG('d', 's', '6', '4')) + return -1; +- size = get_le32(pb); +- if (size < 16) ++ size = avio_rl32(pb); ++ if (size < 24) + return -1; +- get_le64(pb); /* RIFF size */ +- data_size = get_le64(pb); +- sample_count = get_le64(pb); +- url_fskip(pb, size - 16); /* skip rest of ds64 chunk */ ++ avio_rl64(pb); /* RIFF size */ ++ data_size = avio_rl64(pb); ++ sample_count = avio_rl64(pb); ++ if (data_size < 0 || sample_count < 0) { ++ av_log(s, AV_LOG_ERROR, "negative data_size and/or sample_count in " ++ "ds64: data_size = %"PRId64", sample_count = %"PRId64"\n", ++ data_size, sample_count); ++ return AVERROR_INVALIDDATA; ++ } ++ avio_skip(pb, size - 24); /* skip rest of ds64 chunk */ ++ + } + +- /* parse fmt header */ +- size = find_tag(pb, MKTAG('f', 'm', 't', ' ')); +- if (size < 0) +- return -1; +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); ++ for (;;) { ++ AVStream *vst; ++ size = next_tag(pb, &tag); ++ next_tag_ofs = avio_tell(pb) + size; + +- ff_get_wav_header(pb, st->codec, size); +- st->need_parsing = AVSTREAM_PARSE_FULL; ++ if (url_feof(pb)) ++ break; + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ switch (tag) { ++ case MKTAG('f', 'm', 't', ' '): ++ /* only parse the first 'fmt ' tag found */ ++ if (!got_fmt && (ret = wav_parse_fmt_tag(s, size, &st)) < 0) { ++ return ret; ++ } else if (got_fmt) ++ av_log(s, AV_LOG_WARNING, "found more than one 'fmt ' tag\n"); + +- for (;;) { +- if (url_feof(pb)) +- return -1; +- size = next_tag(pb, &tag); +- if (tag == MKTAG('d', 'a', 't', 'a')){ ++ got_fmt = 1; ++ break; ++ case MKTAG('d', 'a', 't', 'a'): ++ if (!got_fmt) { ++ av_log(s, AV_LOG_ERROR, "found no 'fmt ' tag before the 'data' tag\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if (rf64) { ++ next_tag_ofs = wav->data_end = avio_tell(pb) + data_size; ++ } else { ++ data_size = size; ++ next_tag_ofs = wav->data_end = size ? next_tag_ofs : INT64_MAX; ++ } ++ ++ data_ofs = avio_tell(pb); ++ ++ /* don't look for footer metadata if we can't seek or if we don't ++ * know where the data tag ends ++ */ ++ if (!pb->seekable || (!rf64 && !size)) ++ goto break_loop; ++ break; ++ case MKTAG('f','a','c','t'): ++ if (!sample_count) ++ sample_count = avio_rl32(pb); ++ break; ++ case MKTAG('b','e','x','t'): ++ if ((ret = wav_parse_bext_tag(s, size)) < 0) ++ return ret; ++ break; ++ case MKTAG('S','M','V','0'): ++ // SMV file, a wav file with video appended. ++ if (size != MKTAG('0','2','0','0')) { ++ av_log(s, AV_LOG_ERROR, "Unknown SMV version found\n"); ++ goto break_loop; ++ } ++ av_log(s, AV_LOG_DEBUG, "Found SMV data\n"); ++ vst = avformat_new_stream(s, NULL); ++ if (!vst) ++ return AVERROR(ENOMEM); ++ avio_r8(pb); ++ vst->id = 1; ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->codec_id = CODEC_ID_MJPEG; ++ vst->codec->width = avio_rl24(pb); ++ vst->codec->height = avio_rl24(pb); ++ size = avio_rl24(pb); ++ wav->smv_data_ofs = avio_tell(pb) + (size - 5) * 3; ++ avio_rl24(pb); ++ wav->smv_block_size = avio_rl24(pb); ++ avpriv_set_pts_info(vst, 32, 1, avio_rl24(pb)); ++ vst->duration = avio_rl24(pb); ++ avio_rl24(pb); ++ avio_rl24(pb); ++ wav->smv_frames_per_jpeg = avio_rl24(pb); ++ goto break_loop; ++ case MKTAG('L', 'I', 'S', 'T'): ++ list_type = avio_rl32(pb); ++ if (size < 4) { ++ av_log(s, AV_LOG_ERROR, "too short LIST tag\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ switch (list_type) { ++ case MKTAG('I', 'N', 'F', 'O'): ++ if ((ret = ff_read_riff_info(s, size - 4)) < 0) ++ return ret; ++ } ++ break; ++ } ++ ++ /* seek to next tag unless we know that we'll run into EOF */ ++ if ((avio_size(pb) > 0 && next_tag_ofs >= avio_size(pb)) || ++ avio_seek(pb, next_tag_ofs, SEEK_SET) < 0) { + break; +- }else if (tag == MKTAG('f','a','c','t') && !sample_count){ +- sample_count = get_le32(pb); +- size -= 4; + } +- url_fseek(pb, size, SEEK_CUR); + } +- if (rf64) +- size = data_size; +- if (size < 0) +- return -1; +- if (!size) { +- wav->data_end = INT64_MAX; +- } else +- wav->data_end= url_ftell(pb) + size; ++break_loop: ++ if (data_ofs < 0) { ++ av_log(s, AV_LOG_ERROR, "no 'data' tag found\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ avio_seek(pb, data_ofs, SEEK_SET); + + if (!sample_count && st->codec->channels && av_get_bits_per_sample(st->codec->codec_id)) +- sample_count = (size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id)); ++ sample_count = (data_size<<3) / (st->codec->channels * (uint64_t)av_get_bits_per_sample(st->codec->codec_id)); + if (sample_count) + st->duration = sample_count; ++ ++ ff_metadata_conv_ctx(s, NULL, wav_metadata_conv); ++ ff_metadata_conv_ctx(s, NULL, ff_riff_info_conv); ++ + return 0; + } + + /** Find chunk with w64 GUID by skipping over other chunks + * @return the size of the found chunk + */ +-static int64_t find_guid(ByteIOContext *pb, const uint8_t guid1[16]) ++static int64_t find_guid(AVIOContext *pb, const uint8_t guid1[16]) + { + uint8_t guid[16]; + int64_t size; + + while (!url_feof(pb)) { +- get_buffer(pb, guid, 16); +- size = get_le64(pb); ++ avio_read(pb, guid, 16); ++ size = avio_rl64(pb); + if (size <= 24) + return -1; + if (!memcmp(guid, guid1, 16)) + return size; +- url_fskip(pb, FFALIGN(size, INT64_C(8)) - 24); ++ avio_skip(pb, FFALIGN(size, INT64_C(8)) - 24); + } + return -1; + } +@@ -293,17 +577,62 @@ + AVStream *st; + WAVContext *wav = s->priv_data; + ++ if (wav->smv_data_ofs > 0) { ++ int64_t audio_dts, video_dts; ++smv_retry: ++ audio_dts = s->streams[0]->cur_dts; ++ video_dts = s->streams[1]->cur_dts; ++ if (audio_dts != AV_NOPTS_VALUE && video_dts != AV_NOPTS_VALUE) { ++ audio_dts = av_rescale_q(audio_dts, s->streams[0]->time_base, AV_TIME_BASE_Q); ++ video_dts = av_rescale_q(video_dts, s->streams[1]->time_base, AV_TIME_BASE_Q); ++ wav->smv_last_stream = video_dts >= audio_dts; ++ } ++ wav->smv_last_stream = !wav->smv_last_stream; ++ wav->smv_last_stream |= wav->audio_eof; ++ wav->smv_last_stream &= !wav->smv_eof; ++ if (wav->smv_last_stream) { ++ uint64_t old_pos = avio_tell(s->pb); ++ uint64_t new_pos = wav->smv_data_ofs + ++ wav->smv_block * wav->smv_block_size; ++ if (avio_seek(s->pb, new_pos, SEEK_SET) < 0) { ++ ret = AVERROR_EOF; ++ goto smv_out; ++ } ++ size = avio_rl24(s->pb); ++ ret = av_get_packet(s->pb, pkt, size); ++ if (ret < 0) ++ goto smv_out; ++ pkt->pos -= 3; ++ pkt->pts = wav->smv_block * wav->smv_frames_per_jpeg; ++ wav->smv_block++; ++ pkt->stream_index = 1; ++smv_out: ++ avio_seek(s->pb, old_pos, SEEK_SET); ++ if (ret == AVERROR_EOF) { ++ wav->smv_eof = 1; ++ goto smv_retry; ++ } ++ return ret; ++ } ++ } ++ + st = s->streams[0]; + +- left = wav->data_end - url_ftell(s->pb); ++ left = wav->data_end - avio_tell(s->pb); ++ if (wav->ignore_length) ++ left= INT_MAX; + if (left <= 0){ + if (CONFIG_W64_DEMUXER && wav->w64) + left = find_guid(s->pb, guid_data) - 24; + else + left = find_tag(s->pb, MKTAG('d', 'a', 't', 'a')); +- if (left < 0) ++ if (left < 0) { ++ wav->audio_eof = 1; ++ if (wav->smv_data_ofs > 0 && !wav->smv_eof) ++ goto smv_retry; + return AVERROR_EOF; +- wav->data_end= url_ftell(s->pb) + left; ++ } ++ wav->data_end= avio_tell(s->pb) + left; + } + + size = MAX_SIZE; +@@ -324,7 +653,18 @@ + static int wav_read_seek(AVFormatContext *s, + int stream_index, int64_t timestamp, int flags) + { ++ WAVContext *wav = s->priv_data; + AVStream *st; ++ wav->smv_eof = 0; ++ wav->audio_eof = 0; ++ if (wav->smv_data_ofs > 0) { ++ int64_t smv_timestamp = timestamp; ++ if (stream_index == 0) ++ smv_timestamp = av_rescale_q(timestamp, s->streams[0]->time_base, s->streams[1]->time_base); ++ else ++ timestamp = av_rescale_q(smv_timestamp, s->streams[1]->time_base, s->streams[0]->time_base); ++ wav->smv_block = smv_timestamp / wav->smv_frames_per_jpeg; ++ } + + st = s->streams[0]; + switch (st->codec->codec_id) { +@@ -340,17 +680,30 @@ + return pcm_read_seek(s, stream_index, timestamp, flags); + } + ++#define OFFSET(x) offsetof(WAVContext, x) ++#define DEC AV_OPT_FLAG_DECODING_PARAM ++static const AVOption demux_options[] = { ++ { "ignore_length", "Ignore length", OFFSET(ignore_length), AV_OPT_TYPE_INT, { 0 }, 0, 1, DEC }, ++ { NULL }, ++}; ++ ++static const AVClass wav_demuxer_class = { ++ .class_name = "WAV demuxer", ++ .item_name = av_default_item_name, ++ .option = demux_options, ++ .version = LIBAVUTIL_VERSION_INT, ++}; + AVInputFormat ff_wav_demuxer = { +- "wav", +- NULL_IF_CONFIG_SMALL("WAV format"), +- sizeof(WAVContext), +- wav_probe, +- wav_read_header, +- wav_read_packet, +- NULL, +- wav_read_seek, ++ .name = "wav", ++ .long_name = NULL_IF_CONFIG_SMALL("WAV format"), ++ .priv_data_size = sizeof(WAVContext), ++ .read_probe = wav_probe, ++ .read_header = wav_read_header, ++ .read_packet = wav_read_packet, ++ .read_seek = wav_read_seek, + .flags= AVFMT_GENERIC_INDEX, + .codec_tag= (const AVCodecTag* const []){ff_codec_wav_tags, 0}, ++ .priv_class = &wav_demuxer_class, + }; + #endif /* CONFIG_WAV_DEMUXER */ + +@@ -379,19 +732,20 @@ + static int w64_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + int64_t size; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + WAVContext *wav = s->priv_data; + AVStream *st; + uint8_t guid[16]; ++ int ret; + +- get_buffer(pb, guid, 16); ++ avio_read(pb, guid, 16); + if (memcmp(guid, guid_riff, 16)) + return -1; + +- if (get_le64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */ ++ if (avio_rl64(pb) < 16 + 8 + 16 + 8 + 16 + 8) /* riff + wave + fmt + sizes */ + return -1; + +- get_buffer(pb, guid, 16); ++ avio_read(pb, guid, 16); + if (memcmp(guid, guid_wave, 16)) { + av_log(s, AV_LOG_ERROR, "could not find wave guid\n"); + return -1; +@@ -403,38 +757,39 @@ + return -1; + } + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + /* subtract chunk header size - normal wav file doesn't count it */ +- ff_get_wav_header(pb, st->codec, size - 24); +- url_fskip(pb, FFALIGN(size, INT64_C(8)) - size); ++ ret = ff_get_wav_header(pb, st->codec, size - 24); ++ if (ret < 0) ++ return ret; ++ avio_skip(pb, FFALIGN(size, INT64_C(8)) - size); + + st->need_parsing = AVSTREAM_PARSE_FULL; + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + size = find_guid(pb, guid_data); + if (size < 0) { + av_log(s, AV_LOG_ERROR, "could not find data guid\n"); + return -1; + } +- wav->data_end = url_ftell(pb) + size - 24; ++ wav->data_end = avio_tell(pb) + size - 24; + wav->w64 = 1; + + return 0; + } + + AVInputFormat ff_w64_demuxer = { +- "w64", +- NULL_IF_CONFIG_SMALL("Sony Wave64 format"), +- sizeof(WAVContext), +- w64_probe, +- w64_read_header, +- wav_read_packet, +- NULL, +- wav_read_seek, ++ .name = "w64", ++ .long_name = NULL_IF_CONFIG_SMALL("Sony Wave64 format"), ++ .priv_data_size = sizeof(WAVContext), ++ .read_probe = w64_probe, ++ .read_header = w64_read_header, ++ .read_packet = wav_read_packet, ++ .read_seek = wav_read_seek, + .flags = AVFMT_GENERIC_INDEX, + .codec_tag = (const AVCodecTag* const []){ff_codec_wav_tags, 0}, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wc3movie.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wc3movie.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wc3movie.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wc3movie.c 2012-05-14 14:08:55.257358558 +0200 +@@ -28,7 +28,9 @@ + */ + + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + + #define FORM_TAG MKTAG('F', 'O', 'R', 'M') + #define MOVE_TAG MKTAG('M', 'O', 'V', 'E') +@@ -85,7 +87,7 @@ + AVFormatParameters *ap) + { + Wc3DemuxContext *wc3 = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int fourcc_tag; + unsigned int size; + AVStream *st; +@@ -101,12 +103,12 @@ + wc3->vpkt.data = NULL; wc3->vpkt.size = 0; + + /* skip the first 3 32-bit numbers */ +- url_fseek(pb, 12, SEEK_CUR); ++ avio_skip(pb, 12); + + /* traverse through the chunks and load the header information before + * the first BRCH tag */ +- fourcc_tag = get_le32(pb); +- size = (get_be32(pb) + 1) & (~1); ++ fourcc_tag = avio_rl32(pb); ++ size = (avio_rb32(pb) + 1) & (~1); + + do { + switch (fourcc_tag) { +@@ -114,12 +116,12 @@ + case SOND_TAG: + case INDX_TAG: + /* SOND unknown, INDX unnecessary; ignore both */ +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + break; + + case PC__TAG: + /* number of palettes, unneeded */ +- url_fseek(pb, 12, SEEK_CUR); ++ avio_skip(pb, 12); + break; + + case BNAM_TAG: +@@ -127,22 +129,22 @@ + buffer = av_malloc(size+1); + if (!buffer) + return AVERROR(ENOMEM); +- if ((ret = get_buffer(pb, buffer, size)) != size) ++ if ((ret = avio_read(pb, buffer, size)) != size) + return AVERROR(EIO); + buffer[size] = 0; +- av_metadata_set2(&s->metadata, "title", buffer, +- AV_METADATA_DONT_STRDUP_VAL); ++ av_dict_set(&s->metadata, "title", buffer, ++ AV_DICT_DONT_STRDUP_VAL); + break; + + case SIZE_TAG: + /* video resolution override */ +- wc3->width = get_le32(pb); +- wc3->height = get_le32(pb); ++ wc3->width = avio_rl32(pb); ++ wc3->height = avio_rl32(pb); + break; + + case PALT_TAG: + /* one of several palettes */ +- url_fseek(pb, -8, SEEK_CUR); ++ avio_seek(pb, -8, SEEK_CUR); + av_append_packet(pb, &wc3->vpkt, 8 + PALETTE_SIZE); + break; + +@@ -151,22 +153,21 @@ + (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24), + (uint8_t)fourcc_tag, (uint8_t)(fourcc_tag >> 8), (uint8_t)(fourcc_tag >> 16), (uint8_t)(fourcc_tag >> 24)); + return AVERROR_INVALIDDATA; +- break; + } + +- fourcc_tag = get_le32(pb); ++ fourcc_tag = avio_rl32(pb); + /* chunk sizes are 16-bit aligned */ +- size = (get_be32(pb) + 1) & (~1); ++ size = (avio_rb32(pb) + 1) & (~1); + if (url_feof(pb)) + return AVERROR(EIO); + + } while (fourcc_tag != BRCH_TAG); + + /* initialize the decoder streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, WC3_FRAME_FPS); ++ avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS); + wc3->video_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_VIDEO; + st->codec->codec_id = CODEC_ID_XAN_WC3; +@@ -174,10 +175,10 @@ + st->codec->width = wc3->width; + st->codec->height = wc3->height; + +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, WC3_FRAME_FPS); ++ avpriv_set_pts_info(st, 33, 1, WC3_FRAME_FPS); + wc3->audio_stream_index = st->index; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_PCM_S16LE; +@@ -196,7 +197,7 @@ + AVPacket *pkt) + { + Wc3DemuxContext *wc3 = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int fourcc_tag; + unsigned int size; + int packet_read = 0; +@@ -205,9 +206,9 @@ + + while (!packet_read) { + +- fourcc_tag = get_le32(pb); ++ fourcc_tag = avio_rl32(pb); + /* chunk sizes are 16-bit aligned */ +- size = (get_be32(pb) + 1) & (~1); ++ size = (avio_rb32(pb) + 1) & (~1); + if (url_feof(pb)) + return AVERROR(EIO); + +@@ -219,13 +220,13 @@ + + case SHOT_TAG: + /* load up new palette */ +- url_fseek(pb, -8, SEEK_CUR); ++ avio_seek(pb, -8, SEEK_CUR); + av_append_packet(pb, &wc3->vpkt, 8 + 4); + break; + + case VGA__TAG: + /* send out video chunk */ +- url_fseek(pb, -8, SEEK_CUR); ++ avio_seek(pb, -8, SEEK_CUR); + ret= av_append_packet(pb, &wc3->vpkt, 8 + size); + // ignore error if we have some data + if (wc3->vpkt.size > 0) +@@ -240,9 +241,9 @@ + case TEXT_TAG: + /* subtitle chunk */ + #if 0 +- url_fseek(pb, size, SEEK_CUR); ++ avio_skip(pb, size); + #else +- if ((unsigned)size > sizeof(text) || (ret = get_buffer(pb, text, size)) != size) ++ if ((unsigned)size > sizeof(text) || (ret = avio_read(pb, text, size)) != size) + ret = AVERROR(EIO); + else { + int i = 0; +@@ -292,11 +293,11 @@ + } + + AVInputFormat ff_wc3_demuxer = { +- "wc3movie", +- NULL_IF_CONFIG_SMALL("Wing Commander III movie format"), +- sizeof(Wc3DemuxContext), +- wc3_probe, +- wc3_read_header, +- wc3_read_packet, +- wc3_read_close, ++ .name = "wc3movie", ++ .long_name = NULL_IF_CONFIG_SMALL("Wing Commander III movie format"), ++ .priv_data_size = sizeof(Wc3DemuxContext), ++ .read_probe = wc3_probe, ++ .read_header = wc3_read_header, ++ .read_packet = wc3_read_packet, ++ .read_close = wc3_read_close, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood_aud.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood_aud.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood_aud.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood_aud.c 2012-05-14 14:08:55.259358598 +0200 +@@ -0,0 +1,181 @@ ++/* ++ * Westwood Studios AUD Format Demuxer ++ * Copyright (c) 2003 The ffmpeg Project ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Westwood Studios AUD file demuxer ++ * by Mike Melanson (melanson@pcisys.net) ++ * for more information on the Westwood file formats, visit: ++ * http://www.pcisys.net/~melanson/codecs/ ++ * http://www.geocities.com/SiliconValley/8682/aud3.txt ++ * ++ * Implementation note: There is no definite file signature for AUD files. ++ * The demuxer uses a probabilistic strategy for content detection. This ++ * entails performing sanity checks on certain header values in order to ++ * qualify a file. Refer to wsaud_probe() for the precise parameters. ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define AUD_HEADER_SIZE 12 ++#define AUD_CHUNK_PREAMBLE_SIZE 8 ++#define AUD_CHUNK_SIGNATURE 0x0000DEAF ++ ++static int wsaud_probe(AVProbeData *p) ++{ ++ int field; ++ ++ /* Probabilistic content detection strategy: There is no file signature ++ * so perform sanity checks on various header parameters: ++ * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers ++ * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers ++ * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers ++ * first audio chunk signature (32 bits) ==> 1 acceptable number ++ * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 = ++ * 320008 acceptable number combinations. ++ */ ++ ++ if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE) ++ return 0; ++ ++ /* check sample rate */ ++ field = AV_RL16(&p->buf[0]); ++ if ((field < 8000) || (field > 48000)) ++ return 0; ++ ++ /* enforce the rule that the top 6 bits of this flags field are reserved (0); ++ * this might not be true, but enforce it until deemed unnecessary */ ++ if (p->buf[10] & 0xFC) ++ return 0; ++ ++ /* note: only check for WS IMA (type 99) right now since there is no ++ * support for type 1 */ ++ if (p->buf[11] != 99 && p->buf[11] != 1) ++ return 0; ++ ++ /* read ahead to the first audio chunk and validate the first header signature */ ++ if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE) ++ return 0; ++ ++ /* return 1/2 certainty since this file check is a little sketchy */ ++ return AVPROBE_SCORE_MAX / 2; ++} ++ ++static int wsaud_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ unsigned char header[AUD_HEADER_SIZE]; ++ int sample_rate, channels, codec; ++ ++ if (avio_read(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) ++ return AVERROR(EIO); ++ ++ sample_rate = AV_RL16(&header[0]); ++ channels = (header[10] & 0x1) + 1; ++ codec = header[11]; ++ ++ /* initialize the audio decoder stream */ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ switch (codec) { ++ case 1: ++ if (channels != 1) { ++ av_log_ask_for_sample(s, "Stereo WS-SND1 is not supported.\n"); ++ return AVERROR_PATCHWELCOME; ++ } ++ st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; ++ break; ++ case 99: ++ st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; ++ st->codec->bits_per_coded_sample = 4; ++ st->codec->bit_rate = channels * sample_rate * 4; ++ break; ++ default: ++ av_log_ask_for_sample(s, "Unknown codec: %d\n", codec); ++ return AVERROR_PATCHWELCOME; ++ } ++ avpriv_set_pts_info(st, 64, 1, sample_rate); ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ st->codec->channels = channels; ++ st->codec->sample_rate = sample_rate; ++ ++ return 0; ++} ++ ++static int wsaud_read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; ++ unsigned int chunk_size; ++ int ret = 0; ++ AVStream *st = s->streams[0]; ++ ++ if (avio_read(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != ++ AUD_CHUNK_PREAMBLE_SIZE) ++ return AVERROR(EIO); ++ ++ /* validate the chunk */ ++ if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) ++ return AVERROR_INVALIDDATA; ++ ++ chunk_size = AV_RL16(&preamble[0]); ++ ++ if (st->codec->codec_id == CODEC_ID_WESTWOOD_SND1) { ++ /* For Westwood SND1 audio we need to add the output size and input ++ size to the start of the packet to match what is in VQA. ++ Specifically, this is needed to signal when a packet should be ++ decoding as raw 8-bit pcm or variable-size ADPCM. */ ++ int out_size = AV_RL16(&preamble[2]); ++ if ((ret = av_new_packet(pkt, chunk_size + 4))) ++ return ret; ++ if ((ret = avio_read(pb, &pkt->data[4], chunk_size)) != chunk_size) ++ return ret < 0 ? ret : AVERROR(EIO); ++ AV_WL16(&pkt->data[0], out_size); ++ AV_WL16(&pkt->data[2], chunk_size); ++ ++ pkt->duration = out_size; ++ } else { ++ ret = av_get_packet(pb, pkt, chunk_size); ++ if (ret != chunk_size) ++ return AVERROR(EIO); ++ ++ /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ ++ pkt->duration = (chunk_size * 2) / st->codec->channels; ++ } ++ pkt->stream_index = st->index; ++ ++ return ret; ++} ++ ++AVInputFormat ff_wsaud_demuxer = { ++ .name = "wsaud", ++ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios audio format"), ++ .read_probe = wsaud_probe, ++ .read_header = wsaud_read_header, ++ .read_packet = wsaud_read_packet, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,388 +0,0 @@ +-/* +- * Westwood Studios Multimedia Formats Demuxer (VQA, AUD) +- * Copyright (c) 2003 The ffmpeg Project +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-/** +- * @file +- * Westwood Studios VQA & AUD file demuxers +- * by Mike Melanson (melanson@pcisys.net) +- * for more information on the Westwood file formats, visit: +- * http://www.pcisys.net/~melanson/codecs/ +- * http://www.geocities.com/SiliconValley/8682/aud3.txt +- * +- * Implementation note: There is no definite file signature for AUD files. +- * The demuxer uses a probabilistic strategy for content detection. This +- * entails performing sanity checks on certain header values in order to +- * qualify a file. Refer to wsaud_probe() for the precise parameters. +- */ +- +-#include "libavutil/intreadwrite.h" +-#include "avformat.h" +- +-#define AUD_HEADER_SIZE 12 +-#define AUD_CHUNK_PREAMBLE_SIZE 8 +-#define AUD_CHUNK_SIGNATURE 0x0000DEAF +- +-#define FORM_TAG MKBETAG('F', 'O', 'R', 'M') +-#define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A') +-#define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D') +-#define FINF_TAG MKBETAG('F', 'I', 'N', 'F') +-#define SND0_TAG MKBETAG('S', 'N', 'D', '0') +-#define SND1_TAG MKBETAG('S', 'N', 'D', '1') +-#define SND2_TAG MKBETAG('S', 'N', 'D', '2') +-#define VQFR_TAG MKBETAG('V', 'Q', 'F', 'R') +- +-/* don't know what these tags are for, but acknowledge their existence */ +-#define CINF_TAG MKBETAG('C', 'I', 'N', 'F') +-#define CINH_TAG MKBETAG('C', 'I', 'N', 'H') +-#define CIND_TAG MKBETAG('C', 'I', 'N', 'D') +-#define PINF_TAG MKBETAG('P', 'I', 'N', 'F') +-#define PINH_TAG MKBETAG('P', 'I', 'N', 'H') +-#define PIND_TAG MKBETAG('P', 'I', 'N', 'D') +-#define CMDS_TAG MKBETAG('C', 'M', 'D', 'S') +- +-#define VQA_HEADER_SIZE 0x2A +-#define VQA_FRAMERATE 15 +-#define VQA_PREAMBLE_SIZE 8 +- +-typedef struct WsAudDemuxContext { +- int audio_samplerate; +- int audio_channels; +- int audio_bits; +- enum CodecID audio_type; +- int audio_stream_index; +- int64_t audio_frame_counter; +-} WsAudDemuxContext; +- +-typedef struct WsVqaDemuxContext { +- int audio_samplerate; +- int audio_channels; +- int audio_bits; +- +- int audio_stream_index; +- int video_stream_index; +- +- int64_t audio_frame_counter; +-} WsVqaDemuxContext; +- +-static int wsaud_probe(AVProbeData *p) +-{ +- int field; +- +- /* Probabilistic content detection strategy: There is no file signature +- * so perform sanity checks on various header parameters: +- * 8000 <= sample rate (16 bits) <= 48000 ==> 40001 acceptable numbers +- * flags <= 0x03 (2 LSBs are used) ==> 4 acceptable numbers +- * compression type (8 bits) = 1 or 99 ==> 2 acceptable numbers +- * first audio chunk signature (32 bits) ==> 1 acceptable number +- * The number space contains 2^64 numbers. There are 40001 * 4 * 2 * 1 = +- * 320008 acceptable number combinations. +- */ +- +- if (p->buf_size < AUD_HEADER_SIZE + AUD_CHUNK_PREAMBLE_SIZE) +- return 0; +- +- /* check sample rate */ +- field = AV_RL16(&p->buf[0]); +- if ((field < 8000) || (field > 48000)) +- return 0; +- +- /* enforce the rule that the top 6 bits of this flags field are reserved (0); +- * this might not be true, but enforce it until deemed unnecessary */ +- if (p->buf[10] & 0xFC) +- return 0; +- +- /* note: only check for WS IMA (type 99) right now since there is no +- * support for type 1 */ +- if (p->buf[11] != 99) +- return 0; +- +- /* read ahead to the first audio chunk and validate the first header signature */ +- if (AV_RL32(&p->buf[16]) != AUD_CHUNK_SIGNATURE) +- return 0; +- +- /* return 1/2 certainty since this file check is a little sketchy */ +- return AVPROBE_SCORE_MAX / 2; +-} +- +-static int wsaud_read_header(AVFormatContext *s, +- AVFormatParameters *ap) +-{ +- WsAudDemuxContext *wsaud = s->priv_data; +- ByteIOContext *pb = s->pb; +- AVStream *st; +- unsigned char header[AUD_HEADER_SIZE]; +- +- if (get_buffer(pb, header, AUD_HEADER_SIZE) != AUD_HEADER_SIZE) +- return AVERROR(EIO); +- wsaud->audio_samplerate = AV_RL16(&header[0]); +- if (header[11] == 99) +- wsaud->audio_type = CODEC_ID_ADPCM_IMA_WS; +- else +- return AVERROR_INVALIDDATA; +- +- /* flag 0 indicates stereo */ +- wsaud->audio_channels = (header[10] & 0x1) + 1; +- /* flag 1 indicates 16 bit audio */ +- wsaud->audio_bits = (((header[10] & 0x2) >> 1) + 1) * 8; +- +- /* initialize the audio decoder stream */ +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, wsaud->audio_samplerate); +- st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- st->codec->codec_id = wsaud->audio_type; +- st->codec->codec_tag = 0; /* no tag */ +- st->codec->channels = wsaud->audio_channels; +- st->codec->sample_rate = wsaud->audio_samplerate; +- st->codec->bits_per_coded_sample = wsaud->audio_bits; +- st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * +- st->codec->bits_per_coded_sample / 4; +- st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; +- +- wsaud->audio_stream_index = st->index; +- wsaud->audio_frame_counter = 0; +- +- return 0; +-} +- +-static int wsaud_read_packet(AVFormatContext *s, +- AVPacket *pkt) +-{ +- WsAudDemuxContext *wsaud = s->priv_data; +- ByteIOContext *pb = s->pb; +- unsigned char preamble[AUD_CHUNK_PREAMBLE_SIZE]; +- unsigned int chunk_size; +- int ret = 0; +- +- if (get_buffer(pb, preamble, AUD_CHUNK_PREAMBLE_SIZE) != +- AUD_CHUNK_PREAMBLE_SIZE) +- return AVERROR(EIO); +- +- /* validate the chunk */ +- if (AV_RL32(&preamble[4]) != AUD_CHUNK_SIGNATURE) +- return AVERROR_INVALIDDATA; +- +- chunk_size = AV_RL16(&preamble[0]); +- ret= av_get_packet(pb, pkt, chunk_size); +- if (ret != chunk_size) +- return AVERROR(EIO); +- pkt->stream_index = wsaud->audio_stream_index; +- pkt->pts = wsaud->audio_frame_counter; +- pkt->pts /= wsaud->audio_samplerate; +- +- /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ +- wsaud->audio_frame_counter += (chunk_size * 2) / wsaud->audio_channels; +- +- return ret; +-} +- +-static int wsvqa_probe(AVProbeData *p) +-{ +- /* need 12 bytes to qualify */ +- if (p->buf_size < 12) +- return 0; +- +- /* check for the VQA signatures */ +- if ((AV_RB32(&p->buf[0]) != FORM_TAG) || +- (AV_RB32(&p->buf[8]) != WVQA_TAG)) +- return 0; +- +- return AVPROBE_SCORE_MAX; +-} +- +-static int wsvqa_read_header(AVFormatContext *s, +- AVFormatParameters *ap) +-{ +- WsVqaDemuxContext *wsvqa = s->priv_data; +- ByteIOContext *pb = s->pb; +- AVStream *st; +- unsigned char *header; +- unsigned char scratch[VQA_PREAMBLE_SIZE]; +- unsigned int chunk_tag; +- unsigned int chunk_size; +- +- /* initialize the video decoder stream */ +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, VQA_FRAMERATE); +- wsvqa->video_stream_index = st->index; +- st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_id = CODEC_ID_WS_VQA; +- st->codec->codec_tag = 0; /* no fourcc */ +- +- /* skip to the start of the VQA header */ +- url_fseek(pb, 20, SEEK_SET); +- +- /* the VQA header needs to go to the decoder */ +- st->codec->extradata_size = VQA_HEADER_SIZE; +- st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); +- header = (unsigned char *)st->codec->extradata; +- if (get_buffer(pb, st->codec->extradata, VQA_HEADER_SIZE) != +- VQA_HEADER_SIZE) { +- av_free(st->codec->extradata); +- return AVERROR(EIO); +- } +- st->codec->width = AV_RL16(&header[6]); +- st->codec->height = AV_RL16(&header[8]); +- +- /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */ +- if (AV_RL16(&header[24]) || (AV_RL16(&header[0]) == 1 && AV_RL16(&header[2]) == 1)) { +- st = av_new_stream(s, 0); +- if (!st) +- return AVERROR(ENOMEM); +- av_set_pts_info(st, 33, 1, VQA_FRAMERATE); +- st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +- if (AV_RL16(&header[0]) == 1) +- st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; +- else +- st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; +- st->codec->codec_tag = 0; /* no tag */ +- st->codec->sample_rate = AV_RL16(&header[24]); +- if (!st->codec->sample_rate) +- st->codec->sample_rate = 22050; +- st->codec->channels = header[26]; +- if (!st->codec->channels) +- st->codec->channels = 1; +- st->codec->bits_per_coded_sample = 16; +- st->codec->bit_rate = st->codec->channels * st->codec->sample_rate * +- st->codec->bits_per_coded_sample / 4; +- st->codec->block_align = st->codec->channels * st->codec->bits_per_coded_sample; +- +- wsvqa->audio_stream_index = st->index; +- wsvqa->audio_samplerate = st->codec->sample_rate; +- wsvqa->audio_channels = st->codec->channels; +- wsvqa->audio_frame_counter = 0; +- } +- +- /* there are 0 or more chunks before the FINF chunk; iterate until +- * FINF has been skipped and the file will be ready to be demuxed */ +- do { +- if (get_buffer(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) { +- av_free(st->codec->extradata); +- return AVERROR(EIO); +- } +- chunk_tag = AV_RB32(&scratch[0]); +- chunk_size = AV_RB32(&scratch[4]); +- +- /* catch any unknown header tags, for curiousity */ +- switch (chunk_tag) { +- case CINF_TAG: +- case CINH_TAG: +- case CIND_TAG: +- case PINF_TAG: +- case PINH_TAG: +- case PIND_TAG: +- case FINF_TAG: +- case CMDS_TAG: +- break; +- +- default: +- av_log (s, AV_LOG_ERROR, " note: unknown chunk seen (%c%c%c%c)\n", +- scratch[0], scratch[1], +- scratch[2], scratch[3]); +- break; +- } +- +- url_fseek(pb, chunk_size, SEEK_CUR); +- } while (chunk_tag != FINF_TAG); +- +- return 0; +-} +- +-static int wsvqa_read_packet(AVFormatContext *s, +- AVPacket *pkt) +-{ +- WsVqaDemuxContext *wsvqa = s->priv_data; +- ByteIOContext *pb = s->pb; +- int ret = -1; +- unsigned char preamble[VQA_PREAMBLE_SIZE]; +- unsigned int chunk_type; +- unsigned int chunk_size; +- int skip_byte; +- +- while (get_buffer(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) { +- chunk_type = AV_RB32(&preamble[0]); +- chunk_size = AV_RB32(&preamble[4]); +- skip_byte = chunk_size & 0x01; +- +- if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) { +- +- if (av_new_packet(pkt, chunk_size)) +- return AVERROR(EIO); +- ret = get_buffer(pb, pkt->data, chunk_size); +- if (ret != chunk_size) { +- av_free_packet(pkt); +- return AVERROR(EIO); +- } +- +- if (chunk_type == SND2_TAG) { +- pkt->stream_index = wsvqa->audio_stream_index; +- /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ +- wsvqa->audio_frame_counter += (chunk_size * 2) / wsvqa->audio_channels; +- } else if(chunk_type == SND1_TAG) { +- pkt->stream_index = wsvqa->audio_stream_index; +- /* unpacked size is stored in header */ +- wsvqa->audio_frame_counter += AV_RL16(pkt->data) / wsvqa->audio_channels; +- } else { +- pkt->stream_index = wsvqa->video_stream_index; +- } +- /* stay on 16-bit alignment */ +- if (skip_byte) +- url_fseek(pb, 1, SEEK_CUR); +- +- return ret; +- } else { +- switch(chunk_type){ +- case CMDS_TAG: +- case SND0_TAG: +- break; +- default: +- av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type); +- } +- url_fseek(pb, chunk_size + skip_byte, SEEK_CUR); +- } +- } +- +- return ret; +-} +- +-#if CONFIG_WSAUD_DEMUXER +-AVInputFormat ff_wsaud_demuxer = { +- "wsaud", +- NULL_IF_CONFIG_SMALL("Westwood Studios audio format"), +- sizeof(WsAudDemuxContext), +- wsaud_probe, +- wsaud_read_header, +- wsaud_read_packet, +-}; +-#endif +-#if CONFIG_WSVQA_DEMUXER +-AVInputFormat ff_wsvqa_demuxer = { +- "wsvqa", +- NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"), +- sizeof(WsVqaDemuxContext), +- wsvqa_probe, +- wsvqa_read_header, +- wsvqa_read_packet, +-}; +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood_vqa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood_vqa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/westwood_vqa.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/westwood_vqa.c 2012-05-14 14:08:55.260358618 +0200 +@@ -0,0 +1,267 @@ ++/* ++ * Westwood Studios VQA Format Demuxer ++ * Copyright (c) 2003 The ffmpeg Project ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Westwood Studios VQA file demuxer ++ * by Mike Melanson (melanson@pcisys.net) ++ * for more information on the Westwood file formats, visit: ++ * http://www.pcisys.net/~melanson/codecs/ ++ * http://www.geocities.com/SiliconValley/8682/aud3.txt ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "avformat.h" ++#include "internal.h" ++ ++#define FORM_TAG MKBETAG('F', 'O', 'R', 'M') ++#define WVQA_TAG MKBETAG('W', 'V', 'Q', 'A') ++#define VQHD_TAG MKBETAG('V', 'Q', 'H', 'D') ++#define FINF_TAG MKBETAG('F', 'I', 'N', 'F') ++#define SND0_TAG MKBETAG('S', 'N', 'D', '0') ++#define SND1_TAG MKBETAG('S', 'N', 'D', '1') ++#define SND2_TAG MKBETAG('S', 'N', 'D', '2') ++#define VQFR_TAG MKBETAG('V', 'Q', 'F', 'R') ++ ++/* don't know what these tags are for, but acknowledge their existence */ ++#define CINF_TAG MKBETAG('C', 'I', 'N', 'F') ++#define CINH_TAG MKBETAG('C', 'I', 'N', 'H') ++#define CIND_TAG MKBETAG('C', 'I', 'N', 'D') ++#define PINF_TAG MKBETAG('P', 'I', 'N', 'F') ++#define PINH_TAG MKBETAG('P', 'I', 'N', 'H') ++#define PIND_TAG MKBETAG('P', 'I', 'N', 'D') ++#define CMDS_TAG MKBETAG('C', 'M', 'D', 'S') ++ ++#define VQA_HEADER_SIZE 0x2A ++#define VQA_PREAMBLE_SIZE 8 ++ ++typedef struct WsVqaDemuxContext { ++ int audio_channels; ++ int audio_stream_index; ++ int video_stream_index; ++} WsVqaDemuxContext; ++ ++static int wsvqa_probe(AVProbeData *p) ++{ ++ /* need 12 bytes to qualify */ ++ if (p->buf_size < 12) ++ return 0; ++ ++ /* check for the VQA signatures */ ++ if ((AV_RB32(&p->buf[0]) != FORM_TAG) || ++ (AV_RB32(&p->buf[8]) != WVQA_TAG)) ++ return 0; ++ ++ return AVPROBE_SCORE_MAX; ++} ++ ++static int wsvqa_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ WsVqaDemuxContext *wsvqa = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ unsigned char *header; ++ unsigned char scratch[VQA_PREAMBLE_SIZE]; ++ unsigned int chunk_tag; ++ unsigned int chunk_size; ++ int fps, version, flags, sample_rate, channels; ++ ++ /* initialize the video decoder stream */ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->start_time = 0; ++ wsvqa->video_stream_index = st->index; ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_WS_VQA; ++ st->codec->codec_tag = 0; /* no fourcc */ ++ ++ /* skip to the start of the VQA header */ ++ avio_seek(pb, 20, SEEK_SET); ++ ++ /* the VQA header needs to go to the decoder */ ++ st->codec->extradata_size = VQA_HEADER_SIZE; ++ st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); ++ header = (unsigned char *)st->codec->extradata; ++ if (avio_read(pb, st->codec->extradata, VQA_HEADER_SIZE) != ++ VQA_HEADER_SIZE) { ++ av_free(st->codec->extradata); ++ return AVERROR(EIO); ++ } ++ st->codec->width = AV_RL16(&header[6]); ++ st->codec->height = AV_RL16(&header[8]); ++ fps = header[12]; ++ if (fps < 1 || fps > 30) { ++ av_log(s, AV_LOG_ERROR, "invalid fps: %d\n", fps); ++ return AVERROR_INVALIDDATA; ++ } ++ avpriv_set_pts_info(st, 64, 1, fps); ++ ++ /* initialize the audio decoder stream for VQA v1 or nonzero samplerate */ ++ version = AV_RL16(&header[ 0]); ++ flags = AV_RL16(&header[ 2]); ++ sample_rate = AV_RL16(&header[24]); ++ channels = header[26]; ++ if (sample_rate || (version == 1 && flags == 1)) { ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ st->start_time = 0; ++ st->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ++ st->codec->extradata_size = VQA_HEADER_SIZE; ++ st->codec->extradata = av_mallocz(VQA_HEADER_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ memcpy(st->codec->extradata, header, VQA_HEADER_SIZE); ++ ++ if (!sample_rate) ++ sample_rate = 22050; ++ st->codec->sample_rate = sample_rate; ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ ++ if (!channels) ++ channels = 1; ++ st->codec->channels = channels; ++ ++ switch (version) { ++ case 1: ++ st->codec->codec_id = CODEC_ID_WESTWOOD_SND1; ++ break; ++ case 2: ++ case 3: ++ st->codec->codec_id = CODEC_ID_ADPCM_IMA_WS; ++ st->codec->bits_per_coded_sample = 4; ++ st->codec->bit_rate = channels * sample_rate * 4; ++ break; ++ default: ++ /* NOTE: version 0 is supposedly raw pcm_u8 or pcm_s16le, but we do ++ not have any samples to validate this */ ++ av_log_ask_for_sample(s, "VQA version %d audio\n", version); ++ return AVERROR_PATCHWELCOME; ++ } ++ ++ wsvqa->audio_stream_index = st->index; ++ wsvqa->audio_channels = st->codec->channels; ++ } ++ ++ /* there are 0 or more chunks before the FINF chunk; iterate until ++ * FINF has been skipped and the file will be ready to be demuxed */ ++ do { ++ if (avio_read(pb, scratch, VQA_PREAMBLE_SIZE) != VQA_PREAMBLE_SIZE) ++ return AVERROR(EIO); ++ chunk_tag = AV_RB32(&scratch[0]); ++ chunk_size = AV_RB32(&scratch[4]); ++ ++ /* catch any unknown header tags, for curiousity */ ++ switch (chunk_tag) { ++ case CINF_TAG: ++ case CINH_TAG: ++ case CIND_TAG: ++ case PINF_TAG: ++ case PINH_TAG: ++ case PIND_TAG: ++ case FINF_TAG: ++ case CMDS_TAG: ++ break; ++ ++ default: ++ av_log (s, AV_LOG_ERROR, " note: unknown chunk seen (%c%c%c%c)\n", ++ scratch[0], scratch[1], ++ scratch[2], scratch[3]); ++ break; ++ } ++ ++ avio_skip(pb, chunk_size); ++ } while (chunk_tag != FINF_TAG); ++ ++ return 0; ++} ++ ++static int wsvqa_read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ WsVqaDemuxContext *wsvqa = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int ret = -1; ++ unsigned char preamble[VQA_PREAMBLE_SIZE]; ++ unsigned int chunk_type; ++ unsigned int chunk_size; ++ int skip_byte; ++ ++ while (avio_read(pb, preamble, VQA_PREAMBLE_SIZE) == VQA_PREAMBLE_SIZE) { ++ chunk_type = AV_RB32(&preamble[0]); ++ chunk_size = AV_RB32(&preamble[4]); ++ ++ skip_byte = chunk_size & 0x01; ++ ++ if ((chunk_type == SND2_TAG || chunk_type == SND1_TAG) && wsvqa->audio_channels == 0) { ++ av_log(s, AV_LOG_ERROR, "audio chunk without any audio header information found\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ if ((chunk_type == SND1_TAG) || (chunk_type == SND2_TAG) || (chunk_type == VQFR_TAG)) { ++ ++ ret= av_get_packet(pb, pkt, chunk_size); ++ if (ret<0) ++ return AVERROR(EIO); ++ ++ if (chunk_type == SND2_TAG) { ++ pkt->stream_index = wsvqa->audio_stream_index; ++ /* 2 samples/byte, 1 or 2 samples per frame depending on stereo */ ++ pkt->duration = (chunk_size * 2) / wsvqa->audio_channels; ++ } else if(chunk_type == SND1_TAG) { ++ pkt->stream_index = wsvqa->audio_stream_index; ++ /* unpacked size is stored in header */ ++ pkt->duration = AV_RL16(pkt->data) / wsvqa->audio_channels; ++ } else { ++ pkt->stream_index = wsvqa->video_stream_index; ++ pkt->duration = 1; ++ } ++ /* stay on 16-bit alignment */ ++ if (skip_byte) ++ avio_skip(pb, 1); ++ ++ return ret; ++ } else { ++ switch(chunk_type){ ++ case CMDS_TAG: ++ case SND0_TAG: ++ break; ++ default: ++ av_log(s, AV_LOG_INFO, "Skipping unknown chunk 0x%08X\n", chunk_type); ++ } ++ avio_skip(pb, chunk_size + skip_byte); ++ } ++ } ++ ++ return ret; ++} ++ ++AVInputFormat ff_wsvqa_demuxer = { ++ .name = "wsvqa", ++ .long_name = NULL_IF_CONFIG_SMALL("Westwood Studios VQA format"), ++ .priv_data_size = sizeof(WsVqaDemuxContext), ++ .read_probe = wsvqa_probe, ++ .read_header = wsvqa_read_header, ++ .read_packet = wsvqa_read_packet, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtv.c 2012-05-14 14:08:55.262358659 +0200 +@@ -1,6 +1,6 @@ + /* +- * Windows Television (WTV) demuxer +- * Copyright (c) 2010 Peter Ross ++ * Windows Television (WTV) ++ * Copyright (c) 2010-2011 Peter Ross + * + * This file is part of FFmpeg. + * +@@ -19,589 +19,58 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/** +- * @file +- * Windows Television (WTV) demuxer +- * @author Peter Ross +- */ +- +-#include "libavutil/intreadwrite.h" +-#include "avformat.h" +-#include "riff.h" +-#include "asf.h" +-#include "mpegts.h" +- +-/* Macros for formating GUIDs */ +-#define PRI_GUID \ +- "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" +-#define ARG_GUID(g) \ +- g[0],g[1],g[2],g[3],g[4],g[5],g[6],g[7],g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15] +- +-typedef struct { +- int seen_data; +-} WtvStream; +- +-typedef struct WtvContext { +- uint64_t pts; +-} WtvContext; +- +-static int is_zero(uint8_t *v, int n) +-{ +- int i; +- for (i = 0; i < n; i++) +- if (v[i]) return 0; +- return 1; +-} +- +-typedef struct { +- enum CodecID id; +- ff_asf_guid guid; +-} AVCodecGuid; +- +-static enum CodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid) +-{ +- int i; +- for (i = 0; guids[i].id != CODEC_ID_NONE; i++) { +- if (!ff_guidcmp(guids[i].guid, guid)) +- return guids[i].id; +- } +- return CODEC_ID_NONE; +-} ++#include "wtv.h" + +-/* WTV GUIDs */ +-static const ff_asf_guid wtv_guid = ++/* WTV GUIDs*/ ++const ff_asf_guid ff_dir_entry_guid = ++ {0x92,0xB7,0x74,0x91,0x59,0x70,0x70,0x44,0x88,0xDF,0x06,0x3B,0x82,0xCC,0x21,0x3D}; ++const ff_asf_guid ff_wtv_guid = + {0xB7,0xD8,0x00,0x20,0x37,0x49,0xDA,0x11,0xA6,0x4E,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; +-static const ff_asf_guid meta_guid = +- {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53}; +-static const ff_asf_guid timestamp_guid = ++const ff_asf_guid ff_timestamp_guid = + {0x5B,0x05,0xE6,0x1B,0x97,0xA9,0x49,0x43,0x88,0x17,0x1A,0x65,0x5A,0x29,0x8A,0x97}; +-static const ff_asf_guid data_guid = ++const ff_asf_guid ff_data_guid = + {0x95,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; +-static const ff_asf_guid stream_guid = ++const ff_asf_guid ff_stream_guid = + {0xED,0xA4,0x13,0x23,0x2D,0xBF,0x4F,0x45,0xAD,0x8A,0xD9,0x5B,0xA7,0xF9,0x1F,0xEE}; +-static const ff_asf_guid stream2_guid = +- {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; +-static const ff_asf_guid EVENTID_SubtitleSpanningEvent = +- {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A}; +-static const ff_asf_guid EVENTID_LanguageSpanningEvent = +- {0x6D,0x66,0x92,0xE2,0x02,0x9C,0x8D,0x44,0xAA,0x8D,0x78,0x1A,0x93,0xFD,0xC3,0x95}; +-static const ff_asf_guid EVENTID_AudioDescriptorSpanningEvent = +- {0x1C,0xD4,0x7B,0x10,0xDA,0xA6,0x91,0x46,0x83,0x69,0x11,0xB2,0xCD,0xAA,0x28,0x8E}; +-static const ff_asf_guid EVENTID_CtxADescriptorSpanningEvent = +- {0xE6,0xA2,0xB4,0x3A,0x47,0x42,0x34,0x4B,0x89,0x6C,0x30,0xAF,0xA5,0xD2,0x1C,0x24}; +-static const ff_asf_guid EVENTID_CSDescriptorSpanningEvent = +- {0xD9,0x79,0xE7,0xEf,0xF0,0x97,0x86,0x47,0x80,0x0D,0x95,0xCF,0x50,0x5D,0xDC,0x66}; +-static const ff_asf_guid EVENTID_DVBScramblingControlSpanningEvent = +- {0xC4,0xE1,0xD4,0x4B,0xA1,0x90,0x09,0x41,0x82,0x36,0x27,0xF0,0x0E,0x7D,0xCC,0x5B}; +-static const ff_asf_guid EVENTID_StreamIDSpanningEvent = +- {0x68,0xAB,0xF1,0xCA,0x53,0xE1,0x41,0x4D,0xA6,0xB3,0xA7,0xC9,0x98,0xDB,0x75,0xEE}; +-static const ff_asf_guid EVENTID_TeletextSpanningEvent = +- {0x50,0xD9,0x99,0x95,0x33,0x5F,0x17,0x46,0xAF,0x7C,0x1E,0x54,0xB5,0x10,0xDA,0xA3}; +- +-/* Windows media GUIDs */ +- +-#define MEDIASUBTYPE_BASE_GUID \ +- 0x00,0x00,0x10,0x00,0x80,0x00,0x00,0xAA,0x00,0x38,0x9B,0x71 ++const ff_asf_guid ff_mediatype_audio = ++ {'a','u','d','s',FF_MEDIASUBTYPE_BASE_GUID}; ++const ff_asf_guid ff_mediatype_video = ++ {'v','i','d','s',FF_MEDIASUBTYPE_BASE_GUID}; ++const ff_asf_guid ff_format_none = ++ {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96}; + +-/* Media types */ +-static const ff_asf_guid mediatype_audio = +- {'a','u','d','s',MEDIASUBTYPE_BASE_GUID}; +-static const ff_asf_guid mediatype_video = +- {'v','i','d','s',MEDIASUBTYPE_BASE_GUID}; +-static const ff_asf_guid mediasubtype_mpeg1payload = +- {0x81,0xEB,0x36,0xE4,0x4F,0x52,0xCE,0x11,0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}; +-static const ff_asf_guid mediatype_mpeg2_sections = +- {0x6C,0x17,0x5F,0x45,0x06,0x4B,0xCE,0x47,0x9A,0xEF,0x8C,0xAE,0xF7,0x3D,0xF7,0xB5}; +-static const ff_asf_guid mediatype_mpeg2_pes = +- {0x20,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}; +-static const ff_asf_guid mediatype_mstvcaption = +- {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1}; ++/* declare utf16le strings */ ++#define _ , 0, ++const uint8_t ff_timeline_le16[] = ++ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e', 0}; ++const uint8_t ff_timeline_table_0_entries_Events_le16[] = ++ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0}; ++const uint8_t ff_table_0_entries_legacy_attrib_le16[] = ++ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0}; ++const uint8_t ff_table_0_entries_time_le16[] = ++ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'e'_'n'_'t'_'r'_'i'_'e'_'s'_'.'_'t'_'i'_'m'_'e', 0}; ++#undef _ ++ ++const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES = ++ {0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A}; ++const ff_asf_guid ff_metadata_guid = ++ {0x5A,0xFE,0xD7,0x6D,0xC8,0x1D,0x8F,0x4A,0x99,0x22,0xFA,0xB1,0x1C,0x38,0x14,0x53}; ++const ff_asf_guid ff_stream2_guid = ++ {0xA2,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; + + /* Media subtypes */ +-static const ff_asf_guid mediasubtype_cpfilters_processed = ++const ff_asf_guid ff_mediasubtype_cpfilters_processed = + {0x28,0xBD,0xAD,0x46,0xD0,0x6F,0x96,0x47,0x93,0xB2,0x15,0x5C,0x51,0xDC,0x04,0x8D}; +-static const ff_asf_guid mediasubtype_dvb_subtitle = +- {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F}; +-static const ff_asf_guid mediasubtype_teletext = +- {0xE3,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA}; +-static const ff_asf_guid mediasubtype_dtvccdata = +- {0xAA,0xDD,0x2A,0xF5,0xF0,0x36,0xF5,0x43,0x95,0xEA,0x6D,0x86,0x64,0x84,0x26,0x2A}; +-static const ff_asf_guid mediasubtype_mpeg2_sections = +- {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61}; + + /* Formats */ +-static const ff_asf_guid format_cpfilters_processed = ++const ff_asf_guid ff_format_cpfilters_processed = + {0x6F,0xB3,0x39,0x67,0x5F,0x1D,0xC2,0x4A,0x81,0x92,0x28,0xBB,0x0E,0x73,0xD1,0x6A}; +-static const ff_asf_guid format_waveformatex = ++const ff_asf_guid ff_format_waveformatex = + {0x81,0x9F,0x58,0x05,0x56,0xC3,0xCE,0x11,0xBF,0x01,0x00,0xAA,0x00,0x55,0x59,0x5A}; +-static const ff_asf_guid format_videoinfo2 = +- {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA}; +-static const ff_asf_guid format_mpeg2_video = ++const ff_asf_guid ff_format_mpeg2_video = + {0xE3,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}; +-static const ff_asf_guid format_none = +- {0xD6,0x17,0x64,0x0F,0x18,0xC3,0xD0,0x11,0xA4,0x3F,0x00,0xA0,0xC9,0x22,0x31,0x96}; + +-static const AVCodecGuid video_guids[] = { ++const AVCodecGuid ff_video_guids[] = { + {CODEC_ID_MPEG2VIDEO, {0x26,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, + {CODEC_ID_NONE} + }; +- +-static const AVCodecGuid audio_guids[] = { +- {CODEC_ID_AC3, {0x2C,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, +- {CODEC_ID_EAC3, {0xAF,0x87,0xFB,0xA7,0x02,0x2D,0xFB,0x42,0xA4,0xD4,0x05,0xCD,0x93,0x84,0x3B,0xDD}}, +- {CODEC_ID_MP2, {0x2B,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}}, +- {CODEC_ID_NONE} +-}; +- +-static int read_probe(AVProbeData *p) +-{ +- return ff_guidcmp(p->buf, wtv_guid) ? 0 : AVPROBE_SCORE_MAX; +-} +- +-/** +- * parse VIDEOINFOHEADER2 structure +- * @return bytes consumed +- */ +-static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st) +-{ +- ByteIOContext *pb = s->pb; +- +- url_fskip(pb, 72); // picture aspect ratio is unreliable +- ff_get_bmp_header(pb, st); +- +- return 72 + 40; +-} +- +-/** +- * Parse MPEG1WAVEFORMATEX extradata structure +- */ +-static void parse_mpeg1waveformatex(AVStream *st) +-{ +- /* fwHeadLayer */ +- switch (AV_RL16(st->codec->extradata)) { +- case 0x0001 : st->codec->codec_id = CODEC_ID_MP1; break; +- case 0x0002 : st->codec->codec_id = CODEC_ID_MP2; break; +- case 0x0004 : st->codec->codec_id = CODEC_ID_MP3; break; +- } +- +- st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */ +- +- /* dwHeadMode */ +- switch (AV_RL16(st->codec->extradata + 6)) { +- case 1 : case 2 : case 4 : st->codec->channels = 2; break; +- case 8 : st->codec->channels = 1; break; +- } +-} +- +-/** +- * Initialise stream +- * @param st Stream to initialise, or NULL to create and initialise new stream +- * @return NULL on error +- */ +-static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int codec_type) +-{ +- if (st) { +- if (st->codec->extradata) { +- av_freep(&st->codec->extradata); +- st->codec->extradata_size = 0; +- } +- } else { +- WtvStream *wst = av_mallocz(sizeof(WtvStream)); +- if (!wst) +- return NULL; +- st = av_new_stream(s, sid); +- if (!st) +- return NULL; +- st->priv_data = wst; +- } +- st->codec->codec_type = codec_type; +- st->need_parsing = AVSTREAM_PARSE_FULL; +- av_set_pts_info(st, 64, 1, 10000000); +- return st; +-} +- +-/** +- * parse Media Type structure and populate stream +- * @param st Stream, or NULL to create new stream +- * @param mediatype Mediatype GUID +- * @param subtype Subtype GUID +- * @param formattype Format GUID +- * @param size Size of format buffer +- * @return NULL on error +- */ +-static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, +- ff_asf_guid mediatype, ff_asf_guid subtype, +- ff_asf_guid formattype, int size) +-{ +- ByteIOContext *pb = s->pb; +- if (!ff_guidcmp(subtype, mediasubtype_cpfilters_processed) && +- !ff_guidcmp(formattype, format_cpfilters_processed)) { +- ff_asf_guid actual_subtype; +- ff_asf_guid actual_formattype; +- +- if (size < 32) { +- av_log(s, AV_LOG_WARNING, "format buffer size underflow\n"); +- url_fskip(pb, size); +- return NULL; +- } +- +- url_fskip(pb, size - 32); +- ff_get_guid(pb, &actual_subtype); +- ff_get_guid(pb, &actual_formattype); +- url_fseek(pb, -size, SEEK_CUR); +- +- st = parse_media_type(s, st, sid, mediatype, actual_subtype, actual_formattype, size - 32); +- url_fskip(pb, 32); +- return st; +- } else if (!ff_guidcmp(mediatype, mediatype_audio)) { +- st = new_stream(s, st, sid, AVMEDIA_TYPE_AUDIO); +- if (!st) +- return NULL; +- if (!ff_guidcmp(formattype, format_waveformatex)) { +- ff_get_wav_header(pb, st->codec, size); +- } else { +- if (ff_guidcmp(formattype, format_none)) +- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype)); +- url_fskip(pb, size); +- } +- +- if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) { +- st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample); +- } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) { +- if (st->codec->extradata && st->codec->extradata_size >= 22) +- parse_mpeg1waveformatex(st); +- else +- av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n"); +- } else { +- st->codec->codec_id = ff_codec_guid_get_id(audio_guids, subtype); +- if (st->codec->codec_id == CODEC_ID_NONE) +- av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype)); +- } +- return st; +- } else if (!ff_guidcmp(mediatype, mediatype_video)) { +- st = new_stream(s, st, sid, AVMEDIA_TYPE_VIDEO); +- if (!st) +- return NULL; +- if (!ff_guidcmp(formattype, format_videoinfo2)) { +- int consumed = parse_videoinfoheader2(s, st); +- url_fskip(pb, FFMAX(size - consumed, 0)); +- } else if (!ff_guidcmp(formattype, format_mpeg2_video)) { +- int consumed = parse_videoinfoheader2(s, st); +- url_fskip(pb, FFMAX(size - consumed, 0)); +- } else { +- if (ff_guidcmp(formattype, format_none)) +- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype)); +- url_fskip(pb, size); +- } +- +- if (!memcmp(subtype + 4, (const uint8_t[]){MEDIASUBTYPE_BASE_GUID}, 12)) { +- st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype)); +- } else { +- st->codec->codec_id = ff_codec_guid_get_id(video_guids, subtype); +- } +- if (st->codec->codec_id == CODEC_ID_NONE) +- av_log(s, AV_LOG_WARNING, "unknown subtype:"PRI_GUID"\n", ARG_GUID(subtype)); +- return st; +- } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) && +- !ff_guidcmp(subtype, mediasubtype_dvb_subtitle)) { +- st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE); +- if (!st) +- return NULL; +- if (ff_guidcmp(formattype, format_none)) +- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype)); +- url_fskip(pb, size); +- st->codec->codec_id = CODEC_ID_DVB_SUBTITLE; +- return st; +- } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) && +- (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) { +- st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE); +- if (!st) +- return NULL; +- if (ff_guidcmp(formattype, format_none)) +- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype)); +- url_fskip(pb, size); +- st->codec->codec_id = CODEC_ID_DVB_TELETEXT; +- return st; +- } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) && +- !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) { +- if (ff_guidcmp(formattype, format_none)) +- av_log(s, AV_LOG_WARNING, "unknown formattype:"PRI_GUID"\n", ARG_GUID(formattype)); +- url_fskip(pb, size); +- return NULL; +- } +- +- av_log(s, AV_LOG_WARNING, "unknown media type, mediatype:"PRI_GUID +- ", subtype:"PRI_GUID", formattype:"PRI_GUID"\n", +- ARG_GUID(mediatype), ARG_GUID(subtype), ARG_GUID(formattype)); +- url_fskip(pb, size); +- return NULL; +-} +- +-enum { +- SEEK_TO_DATA = 0, +- SEEK_TO_BYTE, +- SEEK_TO_PTS, +-}; +- +-/** +- * Parse WTV chunks +- * @param mode SEEK_TO_DATA, SEEK_TO_BYTE, SEEK_TO_PTS +- * @param seekts either byte position or timestamp +- * @param[out] len Length of data chunk +- * @return stream index of data chunk, or <0 on error +- */ +-static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_ptr) +-{ +- WtvContext *wtv = s->priv_data; +- ByteIOContext *pb = s->pb; +- while (!url_feof(pb)) { +- ff_asf_guid g; +- int len, sid, consumed; +- +- if (mode == SEEK_TO_BYTE && url_ftell(pb) >= seekts) +- return 0; +- +- ff_get_guid(pb, &g); +- if (is_zero(g, sizeof(ff_asf_guid))) +- return AVERROR_EOF; +- +- len = get_le32(pb); +- if (len < 32) +- break; +- sid = get_le32(pb) & 0x7FFF; +- url_fskip(pb, 8); +- consumed = 32; +- +- if (!ff_guidcmp(g, stream_guid)) { +- if (ff_find_stream_index(s, sid) < 0) { +- ff_asf_guid mediatype, subtype, formattype; +- int size; +- consumed += 20; +- url_fskip(pb, 16); +- if (get_le32(pb)) { +- url_fskip(pb, 8); +- ff_get_guid(pb, &mediatype); +- ff_get_guid(pb, &subtype); +- url_fskip(pb, 12); +- ff_get_guid(pb, &formattype); +- size = get_le32(pb); +- parse_media_type(s, 0, sid, mediatype, subtype, formattype, size); +- consumed += 72 + size; +- } +- } +- } else if (!ff_guidcmp(g, stream2_guid)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (stream_index >= 0 && !((WtvStream*)s->streams[stream_index]->priv_data)->seen_data) { +- ff_asf_guid mediatype, subtype, formattype; +- int size; +- url_fskip(pb, 12); +- ff_get_guid(pb, &mediatype); +- ff_get_guid(pb, &subtype); +- url_fskip(pb, 12); +- ff_get_guid(pb, &formattype); +- size = get_le32(pb); +- parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size); +- consumed += 76 + size; +- } +- } else if (!ff_guidcmp(g, EVENTID_AudioDescriptorSpanningEvent) || +- !ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) || +- !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent) || +- !ff_guidcmp(g, EVENTID_StreamIDSpanningEvent) || +- !ff_guidcmp(g, EVENTID_SubtitleSpanningEvent) || +- !ff_guidcmp(g, EVENTID_TeletextSpanningEvent)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (stream_index >= 0) { +- AVStream *st = s->streams[stream_index]; +- uint8_t buf[258]; +- const uint8_t *pbuf = buf; +- int buf_size; +- +- url_fskip(pb, 8); +- consumed += 8; +- if (!ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) || +- !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent)) { +- url_fskip(pb, 6); +- consumed += 6; +- } +- +- buf_size = FFMIN(len - consumed, sizeof(buf)); +- get_buffer(pb, buf, buf_size); +- consumed += buf_size; +- ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, 0, 0, 0, 0); +- } +- } else if (!ff_guidcmp(g, EVENTID_DVBScramblingControlSpanningEvent)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (stream_index >= 0) { +- url_fskip(pb, 12); +- if (get_le32(pb)) +- av_log(s, AV_LOG_WARNING, "DVB scrambled stream detected (st:%d), decoding will likely fail\n", stream_index); +- consumed += 16; +- } +- } else if (!ff_guidcmp(g, EVENTID_LanguageSpanningEvent)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (stream_index >= 0) { +- AVStream *st = s->streams[stream_index]; +- uint8_t language[4]; +- url_fskip(pb, 12); +- get_buffer(pb, language, 3); +- if (language[0]) { +- language[3] = 0; +- av_metadata_set2(&st->metadata, "language", language, 0); +- } +- consumed += 15; +- } +- } else if (!ff_guidcmp(g, timestamp_guid)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (stream_index >= 0) { +- url_fskip(pb, 8); +- wtv->pts = get_le64(pb); +- consumed += 16; +- if (wtv->pts == -1) +- wtv->pts = AV_NOPTS_VALUE; +- if (mode == SEEK_TO_PTS && wtv->pts >= seekts) { +-#define WTV_PAD8(x) (((x) + 7) & ~7) +- url_fskip(pb, WTV_PAD8(len) - consumed); +- return 0; +- } +- } +- } else if (!ff_guidcmp(g, data_guid)) { +- int stream_index = ff_find_stream_index(s, sid); +- if (mode == SEEK_TO_DATA && stream_index >= 0) { +- WtvStream *wst = s->streams[stream_index]->priv_data; +- wst->seen_data = 1; +- if (len_ptr) { +- *len_ptr = len; +- } +- if (wtv->pts != AV_NOPTS_VALUE) +- av_add_index_entry(s->streams[stream_index], url_ftell(pb) - consumed, wtv->pts, 0, 0, AVINDEX_KEYFRAME); +- return stream_index; +- } +- } else if ( +- !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) || +- !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) || +- !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ (const ff_asf_guid){0x12,0xF6,0x22,0xB6,0xAD,0x47,0x71,0x46,0xAD,0x6C,0x05,0xA9,0x8E,0x65,0xDE,0x3A}) || +- !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) || +- !ff_guidcmp(g, /* EVENTID_AudioTypeSpanningEvent */ (const ff_asf_guid){0xBE,0xBF,0x1C,0x50,0x49,0xB8,0xCE,0x42,0x9B,0xE9,0x3D,0xB8,0x69,0xFB,0x82,0xB3}) || +- !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) || +- !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) || +- !ff_guidcmp(g, /* EVENTID_ChannelTypeSpanningEvent */ (const ff_asf_guid){0x51,0x1D,0xAB,0x72,0xD2,0x87,0x9B,0x48,0xBA,0x11,0x0E,0x08,0xDC,0x21,0x02,0x43}) || +- !ff_guidcmp(g, /* EVENTID_PIDListSpanningEvent */ (const ff_asf_guid){0x65,0x8F,0xFC,0x47,0xBB,0xE2,0x34,0x46,0x9C,0xEF,0xFD,0xBF,0xE6,0x26,0x1D,0x5C}) || +- !ff_guidcmp(g, /* EVENTID_SignalAndServiceStatusSpanningEvent */ (const ff_asf_guid){0xCB,0xC5,0x68,0x80,0x04,0x3C,0x2B,0x49,0xB4,0x7D,0x03,0x08,0x82,0x0D,0xCE,0x51}) || +- !ff_guidcmp(g, /* EVENTID_StreamTypeSpanningEvent */ (const ff_asf_guid){0xBC,0x2E,0xAF,0x82,0xA6,0x30,0x64,0x42,0xA8,0x0B,0xAD,0x2E,0x13,0x72,0xAC,0x60}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x1E,0xBE,0xC3,0xC5,0x43,0x92,0xDC,0x11,0x85,0xE5,0x00,0x12,0x3F,0x6F,0x73,0xB9}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x3B,0x86,0xA2,0xB1,0xEB,0x1E,0xC3,0x44,0x8C,0x88,0x1C,0xA3,0xFF,0xE3,0xE7,0x6A}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x4E,0x7F,0x4C,0x5B,0xC4,0xD0,0x38,0x4B,0xA8,0x3E,0x21,0x7F,0x7B,0xBF,0x52,0xE7}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x63,0x36,0xEB,0xFE,0xA1,0x7E,0xD9,0x11,0x83,0x08,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x70,0xE9,0xF1,0xF8,0x89,0xA4,0x4C,0x4D,0x83,0x73,0xB8,0x12,0xE0,0xD5,0xF8,0x1E}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x96,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || +- !ff_guidcmp(g, (const ff_asf_guid){0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || +- !ff_guidcmp(g, (const ff_asf_guid){0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D})) { +- //ignore known guids +- } else +- av_log(s, AV_LOG_WARNING, "unsupported chunk:"PRI_GUID"\n", ARG_GUID(g)); +- +- url_fskip(pb, WTV_PAD8(len) - consumed); +- } +- return AVERROR_EOF; +-} +- +-#define WTV_CHUNK_START 0x40000 +- +-static int read_header(AVFormatContext *s, AVFormatParameters *ap) +-{ +- ByteIOContext *pb = s->pb; +- int ret; +- +- url_fseek(pb, WTV_CHUNK_START, SEEK_SET); +- ret = parse_chunks(s, SEEK_TO_DATA, 0, 0); +- if (ret < 0) +- return ret; +- +- url_fseek(pb, -32, SEEK_CUR); +- return 0; +-} +- +-static int read_packet(AVFormatContext *s, AVPacket *pkt) +-{ +- WtvContext *wtv = s->priv_data; +- ByteIOContext *pb = s->pb; +- int stream_index, len, ret; +- +- stream_index = parse_chunks(s, SEEK_TO_DATA, 0, &len); +- if (stream_index < 0) +- return stream_index; +- +- ret = av_get_packet(pb, pkt, len - 32); +- if (ret < 0) +- return ret; +- pkt->stream_index = stream_index; +- pkt->pts = wtv->pts; +- url_fskip(pb, WTV_PAD8(len) - len); +- return 0; +-} +- +-static int read_seek2(AVFormatContext *s, int stream_index, +- int64_t min_ts, int64_t ts, int64_t max_ts, int flags) +-{ +- WtvContext *wtv = s->priv_data; +- ByteIOContext *pb = s->pb; +- AVStream *st; +- int i; +- +- if (stream_index < 0) { +- stream_index = av_find_default_stream_index(s); +- if (stream_index < 0) +- return -1; +- } +- st = s->streams[stream_index]; +- +- if ((flags & AVSEEK_FLAG_FRAME)) { +- return AVERROR_NOTSUPP; +- } else if ((flags & AVSEEK_FLAG_BYTE)) { +- if (ts < url_ftell(pb)) { +- for (i = st->nb_index_entries - 1; i >= 0; i--) { +- if (st->index_entries[i].pos <= ts) { +- wtv->pts = st->index_entries[i].timestamp; +- url_fseek(pb, st->index_entries[i].pos, SEEK_SET); +- break; +- } +- } +- if (i < 0) { +- wtv->pts = 0; +- url_fseek(pb, WTV_CHUNK_START, SEEK_SET); +- } +- } +- if (parse_chunks(s, SEEK_TO_BYTE, ts, 0) < 0) +- return AVERROR(ERANGE); +- return 0; +- } else { +- ts *= 10; +- i = av_index_search_timestamp(st, ts, flags); +- if (i < 0) { +- if (st->nb_index_entries > 0) { +- wtv->pts = st->index_entries[st->nb_index_entries - 1].timestamp; +- url_fseek(pb, st->index_entries[st->nb_index_entries - 1].pos, SEEK_SET); +- } else { +- wtv->pts = 0; +- url_fseek(pb, WTV_CHUNK_START, SEEK_SET); +- } +- if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0) +- return AVERROR(ERANGE); +- return 0; +- } +- wtv->pts = st->index_entries[i].timestamp; +- url_fseek(pb, st->index_entries[i].pos, SEEK_SET); +- return 0; +- } +-} +- +-AVInputFormat ff_wtv_demuxer = { +- .name = "wtv", +- .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"), +- .priv_data_size = sizeof(WtvContext), +- .read_probe = read_probe, +- .read_header = read_header, +- .read_packet = read_packet, +- .read_seek2 = read_seek2, +- .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, +-}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtvdec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtvdec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtvdec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtvdec.c 2012-05-14 14:08:55.265358719 +0200 +@@ -0,0 +1,1042 @@ ++/* ++ * Windows Television (WTV) demuxer ++ * Copyright (c) 2010-2011 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Windows Television (WTV) demuxer ++ * @author Peter Ross ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/intfloat.h" ++#include "avformat.h" ++#include "internal.h" ++#include "wtv.h" ++#include "mpegts.h" ++#include ++ ++/* Macros for formating GUIDs */ ++#define PRI_PRETTY_GUID \ ++ "%08x-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x" ++#define ARG_PRETTY_GUID(g) \ ++ AV_RL32(g),AV_RL16(g+4),AV_RL16(g+6),g[8],g[9],g[10],g[11],g[12],g[13],g[14],g[15] ++#define LEN_PRETTY_GUID 34 ++ ++/* ++ * ++ * File system routines ++ * ++ */ ++ ++typedef struct { ++ AVIOContext *pb_filesystem; /** file system (AVFormatContext->pb) */ ++ ++ int sector_bits; /** sector shift bits; used to convert sector number into pb_filesystem offset */ ++ uint32_t *sectors; /** file allocation table */ ++ int nb_sectors; /** number of sectors */ ++ ++ int error; ++ int64_t position; ++ int64_t length; ++} WtvFile; ++ ++/** ++ * @return bytes read, 0 on end of file, or <0 on error ++ */ ++static int wtvfile_read_packet(void *opaque, uint8_t *buf, int buf_size) ++{ ++ WtvFile *wf = opaque; ++ AVIOContext *pb = wf->pb_filesystem; ++ int nread = 0; ++ ++ if (wf->error || pb->error) ++ return -1; ++ if (wf->position >= wf->length || url_feof(pb)) ++ return 0; ++ ++ buf_size = FFMIN(buf_size, wf->length - wf->position); ++ while(nread < buf_size) { ++ int n; ++ int remaining_in_sector = (1 << wf->sector_bits) - (wf->position & ((1 << wf->sector_bits) - 1)); ++ int read_request = FFMIN(buf_size - nread, remaining_in_sector); ++ ++ n = avio_read(pb, buf, read_request); ++ if (n <= 0) ++ break; ++ nread += n; ++ buf += n; ++ wf->position += n; ++ if (n == remaining_in_sector) { ++ int i = wf->position >> wf->sector_bits; ++ if (i >= wf->nb_sectors || ++ (wf->sectors[i] != wf->sectors[i - 1] + (1 << (wf->sector_bits - WTV_SECTOR_BITS)) && ++ avio_seek(pb, (int64_t)wf->sectors[i] << WTV_SECTOR_BITS, SEEK_SET) < 0)) { ++ wf->error = 1; ++ break; ++ } ++ } ++ } ++ return nread; ++} ++ ++/** ++ * @return position (or file length) ++ */ ++static int64_t wtvfile_seek(void *opaque, int64_t offset, int whence) ++{ ++ WtvFile *wf = opaque; ++ AVIOContext *pb = wf->pb_filesystem; ++ ++ if (whence == AVSEEK_SIZE) ++ return wf->length; ++ else if (whence == SEEK_CUR) ++ offset = wf->position + offset; ++ else if (whence == SEEK_END) ++ offset = wf->length; ++ ++ wf->error = offset < 0 || offset >= wf->length || ++ avio_seek(pb, ((int64_t)wf->sectors[offset >> wf->sector_bits] << WTV_SECTOR_BITS) ++ + (offset & ((1 << wf->sector_bits) - 1)), SEEK_SET) < 0; ++ wf->position = offset; ++ return offset; ++} ++ ++/** ++ * read non-zero integers (le32) from input stream ++ * @param pb ++ * @param[out] data destination ++ * @param count maximum number of integers to read ++ * @return total number of integers read ++ */ ++static int read_ints(AVIOContext *pb, uint32_t *data, int count) ++{ ++ int i, total = 0; ++ for (i = 0; i < count; i++) { ++ if ((data[total] = avio_rl32(pb))) ++ total++; ++ } ++ return total; ++} ++ ++/** ++ * Open file ++ * @param first_sector First sector ++ * @param length Length of file (bytes) ++ * @param depth File allocation table depth ++ * @return NULL on error ++ */ ++static AVIOContext * wtvfile_open_sector(int first_sector, uint64_t length, int depth, AVFormatContext *s) ++{ ++ AVIOContext *pb; ++ WtvFile *wf; ++ uint8_t *buffer; ++ ++ if (avio_seek(s->pb, first_sector << WTV_SECTOR_BITS, SEEK_SET) < 0) ++ return NULL; ++ ++ wf = av_mallocz(sizeof(WtvFile)); ++ if (!wf) ++ return NULL; ++ ++ if (depth == 0) { ++ wf->sectors = av_malloc(sizeof(uint32_t)); ++ if (!wf->sectors) { ++ av_free(wf); ++ return NULL; ++ } ++ wf->sectors[0] = first_sector; ++ wf->nb_sectors = 1; ++ } else if (depth == 1) { ++ wf->sectors = av_malloc(WTV_SECTOR_SIZE); ++ if (!wf->sectors) { ++ av_free(wf); ++ return NULL; ++ } ++ wf->nb_sectors = read_ints(s->pb, wf->sectors, WTV_SECTOR_SIZE / 4); ++ } else if (depth == 2) { ++ uint32_t sectors1[WTV_SECTOR_SIZE / 4]; ++ int nb_sectors1 = read_ints(s->pb, sectors1, WTV_SECTOR_SIZE / 4); ++ int i; ++ ++ wf->sectors = av_malloc(nb_sectors1 << WTV_SECTOR_BITS); ++ if (!wf->sectors) { ++ av_free(wf); ++ return NULL; ++ } ++ wf->nb_sectors = 0; ++ for (i = 0; i < nb_sectors1; i++) { ++ if (avio_seek(s->pb, (int64_t)sectors1[i] << WTV_SECTOR_BITS, SEEK_SET) < 0) ++ break; ++ wf->nb_sectors += read_ints(s->pb, wf->sectors + i * WTV_SECTOR_SIZE / 4, WTV_SECTOR_SIZE / 4); ++ } ++ } else { ++ av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (0x%x)\n", depth); ++ av_free(wf); ++ return NULL; ++ } ++ wf->sector_bits = length & (1ULL<<63) ? WTV_SECTOR_BITS : WTV_BIGSECTOR_BITS; ++ ++ if (!wf->nb_sectors) { ++ av_free(wf->sectors); ++ av_free(wf); ++ return NULL; ++ } ++ ++ /* check length */ ++ length &= 0xFFFFFFFFFFFF; ++ if (length > ((int64_t)wf->nb_sectors << wf->sector_bits)) { ++ av_log(s, AV_LOG_WARNING, "reported file length (0x%"PRIx64") exceeds number of available sectors (0x%"PRIx64")\n", length, (int64_t)wf->nb_sectors << wf->sector_bits); ++ length = (int64_t)wf->nb_sectors << wf->sector_bits; ++ } ++ wf->length = length; ++ ++ /* seek to intial sector */ ++ wf->position = 0; ++ if (avio_seek(s->pb, (int64_t)wf->sectors[0] << WTV_SECTOR_BITS, SEEK_SET) < 0) { ++ av_free(wf->sectors); ++ av_free(wf); ++ return NULL; ++ } ++ ++ wf->pb_filesystem = s->pb; ++ buffer = av_malloc(1 << wf->sector_bits); ++ if (!buffer) { ++ av_free(wf->sectors); ++ av_free(wf); ++ return NULL; ++ } ++ ++ pb = avio_alloc_context(buffer, 1 << wf->sector_bits, 0, wf, ++ wtvfile_read_packet, NULL, wtvfile_seek); ++ if (!pb) { ++ av_free(buffer); ++ av_free(wf->sectors); ++ av_free(wf); ++ } ++ return pb; ++} ++ ++/** ++ * Open file using filename ++ * @param[in] buf directory buffer ++ * @param buf_size directory buffer size ++ * @param[in] filename ++ * @param filename_size size of filename ++ * @return NULL on error ++ */ ++static AVIOContext * wtvfile_open2(AVFormatContext *s, const uint8_t *buf, int buf_size, const uint8_t *filename, int filename_size) ++{ ++ const uint8_t *buf_end = buf + buf_size; ++ ++ while(buf + 48 <= buf_end) { ++ int dir_length, name_size, first_sector, depth; ++ uint64_t file_length; ++ const uint8_t *name; ++ if (ff_guidcmp(buf, ff_dir_entry_guid)) { ++ av_log(s, AV_LOG_ERROR, "unknown guid "FF_PRI_GUID", expected dir_entry_guid; " ++ "remaining directory entries ignored\n", FF_ARG_GUID(buf)); ++ break; ++ } ++ dir_length = AV_RL16(buf + 16); ++ file_length = AV_RL64(buf + 24); ++ name_size = 2 * AV_RL32(buf + 32); ++ if (buf + 48 + name_size > buf_end) { ++ av_log(s, AV_LOG_ERROR, "filename exceeds buffer size; remaining directory entries ignored\n"); ++ break; ++ } ++ first_sector = AV_RL32(buf + 40 + name_size); ++ depth = AV_RL32(buf + 44 + name_size); ++ ++ /* compare file name; test optional null terminator */ ++ name = buf + 40; ++ if (name_size >= filename_size && ++ !memcmp(name, filename, filename_size) && ++ (name_size < filename_size + 2 || !AV_RN16(name + filename_size))) ++ return wtvfile_open_sector(first_sector, file_length, depth, s); ++ ++ buf += dir_length; ++ } ++ return 0; ++} ++ ++#define wtvfile_open(s, buf, buf_size, filename) \ ++ wtvfile_open2(s, buf, buf_size, filename, sizeof(filename)) ++ ++/** ++ * Close file opened with wtvfile_open_sector(), or wtv_open() ++ */ ++static void wtvfile_close(AVIOContext *pb) ++{ ++ WtvFile *wf = pb->opaque; ++ av_free(wf->sectors); ++ av_freep(&pb->opaque); ++ av_freep(&pb->buffer); ++ av_free(pb); ++} ++ ++/* ++ * ++ * Main demuxer ++ * ++ */ ++ ++typedef struct { ++ int seen_data; ++} WtvStream; ++ ++typedef struct { ++ AVIOContext *pb; /** timeline file */ ++ int64_t epoch; ++ int64_t pts; /** pts for next data chunk */ ++ int64_t last_valid_pts; /** latest valid pts, used for interative seeking */ ++ ++ /* maintain private seek index, as the AVIndexEntry->pos is relative to the ++ start of the 'timeline' file, not the file system (AVFormatContext->pb) */ ++ AVIndexEntry *index_entries; ++ int nb_index_entries; ++ unsigned int index_entries_allocated_size; ++} WtvContext; ++ ++/* WTV GUIDs */ ++static const ff_asf_guid EVENTID_SubtitleSpanningEvent = ++ {0x48,0xC0,0xCE,0x5D,0xB9,0xD0,0x63,0x41,0x87,0x2C,0x4F,0x32,0x22,0x3B,0xE8,0x8A}; ++static const ff_asf_guid EVENTID_LanguageSpanningEvent = ++ {0x6D,0x66,0x92,0xE2,0x02,0x9C,0x8D,0x44,0xAA,0x8D,0x78,0x1A,0x93,0xFD,0xC3,0x95}; ++static const ff_asf_guid EVENTID_AudioDescriptorSpanningEvent = ++ {0x1C,0xD4,0x7B,0x10,0xDA,0xA6,0x91,0x46,0x83,0x69,0x11,0xB2,0xCD,0xAA,0x28,0x8E}; ++static const ff_asf_guid EVENTID_CtxADescriptorSpanningEvent = ++ {0xE6,0xA2,0xB4,0x3A,0x47,0x42,0x34,0x4B,0x89,0x6C,0x30,0xAF,0xA5,0xD2,0x1C,0x24}; ++static const ff_asf_guid EVENTID_CSDescriptorSpanningEvent = ++ {0xD9,0x79,0xE7,0xEf,0xF0,0x97,0x86,0x47,0x80,0x0D,0x95,0xCF,0x50,0x5D,0xDC,0x66}; ++static const ff_asf_guid EVENTID_DVBScramblingControlSpanningEvent = ++ {0xC4,0xE1,0xD4,0x4B,0xA1,0x90,0x09,0x41,0x82,0x36,0x27,0xF0,0x0E,0x7D,0xCC,0x5B}; ++static const ff_asf_guid EVENTID_StreamIDSpanningEvent = ++ {0x68,0xAB,0xF1,0xCA,0x53,0xE1,0x41,0x4D,0xA6,0xB3,0xA7,0xC9,0x98,0xDB,0x75,0xEE}; ++static const ff_asf_guid EVENTID_TeletextSpanningEvent = ++ {0x50,0xD9,0x99,0x95,0x33,0x5F,0x17,0x46,0xAF,0x7C,0x1E,0x54,0xB5,0x10,0xDA,0xA3}; ++static const ff_asf_guid EVENTID_AudioTypeSpanningEvent = ++ {0xBE,0xBF,0x1C,0x50,0x49,0xB8,0xCE,0x42,0x9B,0xE9,0x3D,0xB8,0x69,0xFB,0x82,0xB3}; ++ ++/* Windows media GUIDs */ ++ ++/* Media types */ ++static const ff_asf_guid mediasubtype_mpeg1payload = ++ {0x81,0xEB,0x36,0xE4,0x4F,0x52,0xCE,0x11,0x9F,0x53,0x00,0x20,0xAF,0x0B,0xA7,0x70}; ++static const ff_asf_guid mediatype_mpeg2_sections = ++ {0x6C,0x17,0x5F,0x45,0x06,0x4B,0xCE,0x47,0x9A,0xEF,0x8C,0xAE,0xF7,0x3D,0xF7,0xB5}; ++static const ff_asf_guid mediatype_mpeg2_pes = ++ {0x20,0x80,0x6D,0xE0,0x46,0xDB,0xCF,0x11,0xB4,0xD1,0x00,0x80,0x5F,0x6C,0xBB,0xEA}; ++static const ff_asf_guid mediatype_mstvcaption = ++ {0x89,0x8A,0x8B,0xB8,0x49,0xB0,0x80,0x4C,0xAD,0xCF,0x58,0x98,0x98,0x5E,0x22,0xC1}; ++ ++/* Media subtypes */ ++static const ff_asf_guid mediasubtype_dvb_subtitle = ++ {0xC3,0xCB,0xFF,0x34,0xB3,0xD5,0x71,0x41,0x90,0x02,0xD4,0xC6,0x03,0x01,0x69,0x7F}; ++static const ff_asf_guid mediasubtype_teletext = ++ {0xE3,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA}; ++static const ff_asf_guid mediasubtype_dtvccdata = ++ {0xAA,0xDD,0x2A,0xF5,0xF0,0x36,0xF5,0x43,0x95,0xEA,0x6D,0x86,0x64,0x84,0x26,0x2A}; ++static const ff_asf_guid mediasubtype_mpeg2_sections = ++ {0x79,0x85,0x9F,0x4A,0xF8,0x6B,0x92,0x43,0x8A,0x6D,0xD2,0xDD,0x09,0xFA,0x78,0x61}; ++ ++/* Formats */ ++static const ff_asf_guid format_videoinfo2 = ++ {0xA0,0x76,0x2A,0xF7,0x0A,0xEB,0xD0,0x11,0xAC,0xE4,0x00,0x00,0xC0,0xCC,0x16,0xBA}; ++ ++static int read_probe(AVProbeData *p) ++{ ++ return ff_guidcmp(p->buf, ff_wtv_guid) ? 0 : AVPROBE_SCORE_MAX; ++} ++ ++/** ++ * Convert win32 FILETIME to ISO-8601 string ++ */ ++static void filetime_to_iso8601(char *buf, int buf_size, int64_t value) ++{ ++ time_t t = (value / 10000000LL) - 11644473600LL; ++ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t)); ++} ++ ++/** ++ * Convert crazy time (100ns since 1 Jan 0001) to ISO-8601 string ++ */ ++static void crazytime_to_iso8601(char *buf, int buf_size, int64_t value) ++{ ++ time_t t = (value / 10000000LL) - 719162LL*86400LL; ++ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", gmtime(&t)); ++} ++ ++/** ++ * Convert OLE DATE to ISO-8601 string ++ * @return <0 on error ++ */ ++static int oledate_to_iso8601(char *buf, int buf_size, int64_t value) ++{ ++ time_t t = (av_int2double(value) - 25569.0) * 86400; ++ struct tm *result= gmtime(&t); ++ if (!result) ++ return -1; ++ strftime(buf, buf_size, "%Y-%m-%d %H:%M:%S", result); ++ return 0; ++} ++ ++static void get_attachment(AVFormatContext *s, AVIOContext *pb, int length) ++{ ++ char mime[1024]; ++ char description[1024]; ++ unsigned int filesize; ++ AVStream *st; ++ int64_t pos = avio_tell(pb); ++ ++ avio_get_str16le(pb, INT_MAX, mime, sizeof(mime)); ++ if (strcmp(mime, "image/jpeg")) ++ goto done; ++ ++ avio_r8(pb); ++ avio_get_str16le(pb, INT_MAX, description, sizeof(description)); ++ filesize = avio_rl32(pb); ++ if (!filesize) ++ goto done; ++ ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ goto done; ++ av_dict_set(&st->metadata, "title", description, 0); ++ st->codec->codec_id = CODEC_ID_MJPEG; ++ st->codec->codec_type = AVMEDIA_TYPE_ATTACHMENT; ++ st->codec->extradata = av_mallocz(filesize); ++ if (!st->codec->extradata) ++ goto done; ++ st->codec->extradata_size = filesize; ++ avio_read(pb, st->codec->extradata, filesize); ++done: ++ avio_seek(pb, pos + length, SEEK_SET); ++} ++ ++static void get_tag(AVFormatContext *s, AVIOContext *pb, const char *key, int type, int length) ++{ ++ int buf_size = FFMAX(2*length, LEN_PRETTY_GUID) + 1; ++ char *buf = av_malloc(buf_size); ++ if (!buf) ++ return; ++ ++ if (type == 0 && length == 4) { ++ snprintf(buf, buf_size, "%"PRIi32, avio_rl32(pb)); ++ } else if (type == 1) { ++ avio_get_str16le(pb, length, buf, buf_size); ++ if (!strlen(buf)) { ++ av_free(buf); ++ return; ++ } ++ } else if (type == 3 && length == 4) { ++ strcpy(buf, avio_rl32(pb) ? "true" : "false"); ++ } else if (type == 4 && length == 8) { ++ int64_t num = avio_rl64(pb); ++ if (!strcmp(key, "WM/EncodingTime") || ++ !strcmp(key, "WM/MediaOriginalBroadcastDateTime")) ++ filetime_to_iso8601(buf, buf_size, num); ++ else if (!strcmp(key, "WM/WMRVEncodeTime") || ++ !strcmp(key, "WM/WMRVEndTime")) ++ crazytime_to_iso8601(buf, buf_size, num); ++ else if (!strcmp(key, "WM/WMRVExpirationDate")) { ++ if (oledate_to_iso8601(buf, buf_size, num) < 0 ) { ++ av_free(buf); ++ return; ++ } ++ } else if (!strcmp(key, "WM/WMRVBitrate")) ++ snprintf(buf, buf_size, "%f", av_int2double(num)); ++ else ++ snprintf(buf, buf_size, "%"PRIi64, num); ++ } else if (type == 5 && length == 2) { ++ snprintf(buf, buf_size, "%"PRIi16, avio_rl16(pb)); ++ } else if (type == 6 && length == 16) { ++ ff_asf_guid guid; ++ avio_read(pb, guid, 16); ++ snprintf(buf, buf_size, PRI_PRETTY_GUID, ARG_PRETTY_GUID(guid)); ++ } else if (type == 2 && !strcmp(key, "WM/Picture")) { ++ get_attachment(s, pb, length); ++ av_freep(&buf); ++ return; ++ } else { ++ av_freep(&buf); ++ av_log(s, AV_LOG_WARNING, "unsupported metadata entry; key:%s, type:%d, length:0x%x\n", key, type, length); ++ avio_skip(pb, length); ++ return; ++ } ++ ++ av_dict_set(&s->metadata, key, buf, 0); ++ av_freep(&buf); ++} ++ ++/** ++ * Parse metadata entries ++ */ ++static void parse_legacy_attrib(AVFormatContext *s, AVIOContext *pb) ++{ ++ ff_asf_guid guid; ++ int length, type; ++ while(!url_feof(pb)) { ++ char key[1024]; ++ ff_get_guid(pb, &guid); ++ type = avio_rl32(pb); ++ length = avio_rl32(pb); ++ if (!length) ++ break; ++ if (ff_guidcmp(&guid, ff_metadata_guid)) { ++ av_log(s, AV_LOG_WARNING, "unknown guid "FF_PRI_GUID", expected metadata_guid; " ++ "remaining metadata entries ignored\n", FF_ARG_GUID(guid)); ++ break; ++ } ++ avio_get_str16le(pb, INT_MAX, key, sizeof(key)); ++ get_tag(s, pb, key, type, length); ++ } ++ ++ ff_metadata_conv(&s->metadata, NULL, ff_asf_metadata_conv); ++} ++ ++/** ++ * parse VIDEOINFOHEADER2 structure ++ * @return bytes consumed ++ */ ++static int parse_videoinfoheader2(AVFormatContext *s, AVStream *st) ++{ ++ WtvContext *wtv = s->priv_data; ++ AVIOContext *pb = wtv->pb; ++ ++ avio_skip(pb, 72); // picture aspect ratio is unreliable ++ ff_get_bmp_header(pb, st); ++ ++ return 72 + 40; ++} ++ ++/** ++ * Parse MPEG1WAVEFORMATEX extradata structure ++ */ ++static void parse_mpeg1waveformatex(AVStream *st) ++{ ++ /* fwHeadLayer */ ++ switch (AV_RL16(st->codec->extradata)) { ++ case 0x0001 : st->codec->codec_id = CODEC_ID_MP1; break; ++ case 0x0002 : st->codec->codec_id = CODEC_ID_MP2; break; ++ case 0x0004 : st->codec->codec_id = CODEC_ID_MP3; break; ++ } ++ ++ st->codec->bit_rate = AV_RL32(st->codec->extradata + 2); /* dwHeadBitrate */ ++ ++ /* dwHeadMode */ ++ switch (AV_RL16(st->codec->extradata + 6)) { ++ case 1 : case 2 : case 4 : st->codec->channels = 2; break; ++ case 8 : st->codec->channels = 1; break; ++ } ++} ++ ++/** ++ * Initialise stream ++ * @param st Stream to initialise, or NULL to create and initialise new stream ++ * @return NULL on error ++ */ ++static AVStream * new_stream(AVFormatContext *s, AVStream *st, int sid, int codec_type) ++{ ++ if (st) { ++ if (st->codec->extradata) { ++ av_freep(&st->codec->extradata); ++ st->codec->extradata_size = 0; ++ } ++ } else { ++ WtvStream *wst = av_mallocz(sizeof(WtvStream)); ++ if (!wst) ++ return NULL; ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return NULL; ++ st->id = sid; ++ st->priv_data = wst; ++ } ++ st->codec->codec_type = codec_type; ++ st->need_parsing = AVSTREAM_PARSE_FULL; ++ avpriv_set_pts_info(st, 64, 1, 10000000); ++ return st; ++} ++ ++/** ++ * parse Media Type structure and populate stream ++ * @param st Stream, or NULL to create new stream ++ * @param mediatype Mediatype GUID ++ * @param subtype Subtype GUID ++ * @param formattype Format GUID ++ * @param size Size of format buffer ++ * @return NULL on error ++ */ ++static AVStream * parse_media_type(AVFormatContext *s, AVStream *st, int sid, ++ ff_asf_guid mediatype, ff_asf_guid subtype, ++ ff_asf_guid formattype, int size) ++{ ++ WtvContext *wtv = s->priv_data; ++ AVIOContext *pb = wtv->pb; ++ if (!ff_guidcmp(subtype, ff_mediasubtype_cpfilters_processed) && ++ !ff_guidcmp(formattype, ff_format_cpfilters_processed)) { ++ ff_asf_guid actual_subtype; ++ ff_asf_guid actual_formattype; ++ ++ if (size < 32) { ++ av_log(s, AV_LOG_WARNING, "format buffer size underflow\n"); ++ avio_skip(pb, size); ++ return NULL; ++ } ++ ++ avio_skip(pb, size - 32); ++ ff_get_guid(pb, &actual_subtype); ++ ff_get_guid(pb, &actual_formattype); ++ avio_seek(pb, -size, SEEK_CUR); ++ ++ st = parse_media_type(s, st, sid, mediatype, actual_subtype, actual_formattype, size - 32); ++ avio_skip(pb, 32); ++ return st; ++ } else if (!ff_guidcmp(mediatype, ff_mediatype_audio)) { ++ st = new_stream(s, st, sid, AVMEDIA_TYPE_AUDIO); ++ if (!st) ++ return NULL; ++ if (!ff_guidcmp(formattype, ff_format_waveformatex)) { ++ int ret = ff_get_wav_header(pb, st->codec, size); ++ if (ret < 0) ++ return NULL; ++ } else { ++ if (ff_guidcmp(formattype, ff_format_none)) ++ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ } ++ ++ if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { ++ st->codec->codec_id = ff_wav_codec_get_id(AV_RL32(subtype), st->codec->bits_per_coded_sample); ++ } else if (!ff_guidcmp(subtype, mediasubtype_mpeg1payload)) { ++ if (st->codec->extradata && st->codec->extradata_size >= 22) ++ parse_mpeg1waveformatex(st); ++ else ++ av_log(s, AV_LOG_WARNING, "MPEG1WAVEFORMATEX underflow\n"); ++ } else { ++ st->codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subtype); ++ if (st->codec->codec_id == CODEC_ID_NONE) ++ av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype)); ++ } ++ return st; ++ } else if (!ff_guidcmp(mediatype, ff_mediatype_video)) { ++ st = new_stream(s, st, sid, AVMEDIA_TYPE_VIDEO); ++ if (!st) ++ return NULL; ++ if (!ff_guidcmp(formattype, format_videoinfo2)) { ++ int consumed = parse_videoinfoheader2(s, st); ++ avio_skip(pb, FFMAX(size - consumed, 0)); ++ } else if (!ff_guidcmp(formattype, ff_format_mpeg2_video)) { ++ int consumed = parse_videoinfoheader2(s, st); ++ avio_skip(pb, FFMAX(size - consumed, 0)); ++ } else { ++ if (ff_guidcmp(formattype, ff_format_none)) ++ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ } ++ ++ if (!memcmp(subtype + 4, (const uint8_t[]){FF_MEDIASUBTYPE_BASE_GUID}, 12)) { ++ st->codec->codec_id = ff_codec_get_id(ff_codec_bmp_tags, AV_RL32(subtype)); ++ } else { ++ st->codec->codec_id = ff_codec_guid_get_id(ff_video_guids, subtype); ++ } ++ if (st->codec->codec_id == CODEC_ID_NONE) ++ av_log(s, AV_LOG_WARNING, "unknown subtype:"FF_PRI_GUID"\n", FF_ARG_GUID(subtype)); ++ return st; ++ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_pes) && ++ !ff_guidcmp(subtype, mediasubtype_dvb_subtitle)) { ++ st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE); ++ if (!st) ++ return NULL; ++ if (ff_guidcmp(formattype, ff_format_none)) ++ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ st->codec->codec_id = CODEC_ID_DVB_SUBTITLE; ++ return st; ++ } else if (!ff_guidcmp(mediatype, mediatype_mstvcaption) && ++ (!ff_guidcmp(subtype, mediasubtype_teletext) || !ff_guidcmp(subtype, mediasubtype_dtvccdata))) { ++ st = new_stream(s, st, sid, AVMEDIA_TYPE_SUBTITLE); ++ if (!st) ++ return NULL; ++ if (ff_guidcmp(formattype, ff_format_none)) ++ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ st->codec->codec_id = CODEC_ID_DVB_TELETEXT; ++ return st; ++ } else if (!ff_guidcmp(mediatype, mediatype_mpeg2_sections) && ++ !ff_guidcmp(subtype, mediasubtype_mpeg2_sections)) { ++ if (ff_guidcmp(formattype, ff_format_none)) ++ av_log(s, AV_LOG_WARNING, "unknown formattype:"FF_PRI_GUID"\n", FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ return NULL; ++ } ++ ++ av_log(s, AV_LOG_WARNING, "unknown media type, mediatype:"FF_PRI_GUID ++ ", subtype:"FF_PRI_GUID", formattype:"FF_PRI_GUID"\n", ++ FF_ARG_GUID(mediatype), FF_ARG_GUID(subtype), FF_ARG_GUID(formattype)); ++ avio_skip(pb, size); ++ return NULL; ++} ++ ++enum { ++ SEEK_TO_DATA = 0, ++ SEEK_TO_PTS, ++}; ++ ++/** ++ * Parse WTV chunks ++ * @param mode SEEK_TO_DATA or SEEK_TO_PTS ++ * @param seekts timestamp ++ * @param[out] len_ptr Length of data chunk ++ * @return stream index of data chunk, or <0 on error ++ */ ++static int parse_chunks(AVFormatContext *s, int mode, int64_t seekts, int *len_ptr) ++{ ++ WtvContext *wtv = s->priv_data; ++ AVIOContext *pb = wtv->pb; ++ while (!url_feof(pb)) { ++ ff_asf_guid g; ++ int len, sid, consumed; ++ ++ ff_get_guid(pb, &g); ++ len = avio_rl32(pb); ++ if (len < 32) ++ break; ++ sid = avio_rl32(pb) & 0x7FFF; ++ avio_skip(pb, 8); ++ consumed = 32; ++ ++ if (!ff_guidcmp(g, ff_stream_guid)) { ++ if (ff_find_stream_index(s, sid) < 0) { ++ ff_asf_guid mediatype, subtype, formattype; ++ int size; ++ avio_skip(pb, 28); ++ ff_get_guid(pb, &mediatype); ++ ff_get_guid(pb, &subtype); ++ avio_skip(pb, 12); ++ ff_get_guid(pb, &formattype); ++ size = avio_rl32(pb); ++ parse_media_type(s, 0, sid, mediatype, subtype, formattype, size); ++ consumed += 92 + size; ++ } ++ } else if (!ff_guidcmp(g, ff_stream2_guid)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0 && !((WtvStream*)s->streams[stream_index]->priv_data)->seen_data) { ++ ff_asf_guid mediatype, subtype, formattype; ++ int size; ++ avio_skip(pb, 12); ++ ff_get_guid(pb, &mediatype); ++ ff_get_guid(pb, &subtype); ++ avio_skip(pb, 12); ++ ff_get_guid(pb, &formattype); ++ size = avio_rl32(pb); ++ parse_media_type(s, s->streams[stream_index], sid, mediatype, subtype, formattype, size); ++ consumed += 76 + size; ++ } ++ } else if (!ff_guidcmp(g, EVENTID_AudioDescriptorSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_StreamIDSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_SubtitleSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_TeletextSpanningEvent)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0) { ++ AVStream *st = s->streams[stream_index]; ++ uint8_t buf[258]; ++ const uint8_t *pbuf = buf; ++ int buf_size; ++ ++ avio_skip(pb, 8); ++ consumed += 8; ++ if (!ff_guidcmp(g, EVENTID_CtxADescriptorSpanningEvent) || ++ !ff_guidcmp(g, EVENTID_CSDescriptorSpanningEvent)) { ++ avio_skip(pb, 6); ++ consumed += 6; ++ } ++ ++ buf_size = FFMIN(len - consumed, sizeof(buf)); ++ avio_read(pb, buf, buf_size); ++ consumed += buf_size; ++ ff_parse_mpeg2_descriptor(s, st, 0, &pbuf, buf + buf_size, NULL, 0, 0, NULL); ++ } ++ } else if (!ff_guidcmp(g, EVENTID_AudioTypeSpanningEvent)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0) { ++ AVStream *st = s->streams[stream_index]; ++ int audio_type; ++ avio_skip(pb, 8); ++ audio_type = avio_r8(pb); ++ if (audio_type == 2) ++ st->disposition |= AV_DISPOSITION_HEARING_IMPAIRED; ++ else if (audio_type == 3) ++ st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED; ++ consumed += 9; ++ } ++ } else if (!ff_guidcmp(g, EVENTID_DVBScramblingControlSpanningEvent)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0) { ++ avio_skip(pb, 12); ++ if (avio_rl32(pb)) ++ av_log(s, AV_LOG_WARNING, "DVB scrambled stream detected (st:%d), decoding will likely fail\n", stream_index); ++ consumed += 16; ++ } ++ } else if (!ff_guidcmp(g, EVENTID_LanguageSpanningEvent)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0) { ++ AVStream *st = s->streams[stream_index]; ++ uint8_t language[4]; ++ avio_skip(pb, 12); ++ avio_read(pb, language, 3); ++ if (language[0]) { ++ language[3] = 0; ++ av_dict_set(&st->metadata, "language", language, 0); ++ if (!strcmp(language, "nar") || !strcmp(language, "NAR")) ++ st->disposition |= AV_DISPOSITION_VISUAL_IMPAIRED; ++ } ++ consumed += 15; ++ } ++ } else if (!ff_guidcmp(g, ff_timestamp_guid)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (stream_index >= 0) { ++ avio_skip(pb, 8); ++ wtv->pts = avio_rl64(pb); ++ consumed += 16; ++ if (wtv->pts == -1) ++ wtv->pts = AV_NOPTS_VALUE; ++ else { ++ wtv->last_valid_pts = wtv->pts; ++ if (wtv->epoch == AV_NOPTS_VALUE || wtv->pts < wtv->epoch) ++ wtv->epoch = wtv->pts; ++ if (mode == SEEK_TO_PTS && wtv->pts >= seekts) { ++ avio_skip(pb, WTV_PAD8(len) - consumed); ++ return 0; ++ } ++ } ++ } ++ } else if (!ff_guidcmp(g, ff_data_guid)) { ++ int stream_index = ff_find_stream_index(s, sid); ++ if (mode == SEEK_TO_DATA && stream_index >= 0 && len > 32) { ++ WtvStream *wst = s->streams[stream_index]->priv_data; ++ wst->seen_data = 1; ++ if (len_ptr) { ++ *len_ptr = len; ++ } ++ return stream_index; ++ } ++ } else if ( ++ !ff_guidcmp(g, /* DSATTRIB_CAPTURE_STREAMTIME */ (const ff_asf_guid){0x14,0x56,0x1A,0x0C,0xCD,0x30,0x40,0x4F,0xBC,0xBF,0xD0,0x3E,0x52,0x30,0x62,0x07}) || ++ !ff_guidcmp(g, /* DSATTRIB_PicSampleSeq */ (const ff_asf_guid){0x02,0xAE,0x5B,0x2F,0x8F,0x7B,0x60,0x4F,0x82,0xD6,0xE4,0xEA,0x2F,0x1F,0x4C,0x99}) || ++ !ff_guidcmp(g, /* DSATTRIB_TRANSPORT_PROPERTIES */ ff_DSATTRIB_TRANSPORT_PROPERTIES) || ++ !ff_guidcmp(g, /* dvr_ms_vid_frame_rep_data */ (const ff_asf_guid){0xCC,0x32,0x64,0xDD,0x29,0xE2,0xDB,0x40,0x80,0xF6,0xD2,0x63,0x28,0xD2,0x76,0x1F}) || ++ !ff_guidcmp(g, /* EVENTID_ChannelChangeSpanningEvent */ (const ff_asf_guid){0xE5,0xC5,0x67,0x90,0x5C,0x4C,0x05,0x42,0x86,0xC8,0x7A,0xFE,0x20,0xFE,0x1E,0xFA}) || ++ !ff_guidcmp(g, /* EVENTID_ChannelInfoSpanningEvent */ (const ff_asf_guid){0x80,0x6D,0xF3,0x41,0x32,0x41,0xC2,0x4C,0xB1,0x21,0x01,0xA4,0x32,0x19,0xD8,0x1B}) || ++ !ff_guidcmp(g, /* EVENTID_ChannelTypeSpanningEvent */ (const ff_asf_guid){0x51,0x1D,0xAB,0x72,0xD2,0x87,0x9B,0x48,0xBA,0x11,0x0E,0x08,0xDC,0x21,0x02,0x43}) || ++ !ff_guidcmp(g, /* EVENTID_PIDListSpanningEvent */ (const ff_asf_guid){0x65,0x8F,0xFC,0x47,0xBB,0xE2,0x34,0x46,0x9C,0xEF,0xFD,0xBF,0xE6,0x26,0x1D,0x5C}) || ++ !ff_guidcmp(g, /* EVENTID_SignalAndServiceStatusSpanningEvent */ (const ff_asf_guid){0xCB,0xC5,0x68,0x80,0x04,0x3C,0x2B,0x49,0xB4,0x7D,0x03,0x08,0x82,0x0D,0xCE,0x51}) || ++ !ff_guidcmp(g, /* EVENTID_StreamTypeSpanningEvent */ (const ff_asf_guid){0xBC,0x2E,0xAF,0x82,0xA6,0x30,0x64,0x42,0xA8,0x0B,0xAD,0x2E,0x13,0x72,0xAC,0x60}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x1E,0xBE,0xC3,0xC5,0x43,0x92,0xDC,0x11,0x85,0xE5,0x00,0x12,0x3F,0x6F,0x73,0xB9}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x3B,0x86,0xA2,0xB1,0xEB,0x1E,0xC3,0x44,0x8C,0x88,0x1C,0xA3,0xFF,0xE3,0xE7,0x6A}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x4E,0x7F,0x4C,0x5B,0xC4,0xD0,0x38,0x4B,0xA8,0x3E,0x21,0x7F,0x7B,0xBF,0x52,0xE7}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x63,0x36,0xEB,0xFE,0xA1,0x7E,0xD9,0x11,0x83,0x08,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x70,0xE9,0xF1,0xF8,0x89,0xA4,0x4C,0x4D,0x83,0x73,0xB8,0x12,0xE0,0xD5,0xF8,0x1E}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x96,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}) || ++ !ff_guidcmp(g, (const ff_asf_guid){0xF7,0x10,0x02,0xB9,0xEE,0x7C,0xED,0x4E,0xBD,0x7F,0x05,0x40,0x35,0x86,0x18,0xA1})) { ++ //ignore known guids ++ } else ++ av_log(s, AV_LOG_WARNING, "unsupported chunk:"FF_PRI_GUID"\n", FF_ARG_GUID(g)); ++ ++ avio_skip(pb, WTV_PAD8(len) - consumed); ++ } ++ return AVERROR_EOF; ++} ++ ++static int read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ WtvContext *wtv = s->priv_data; ++ int root_sector, root_size; ++ uint8_t root[WTV_SECTOR_SIZE]; ++ AVIOContext *pb; ++ int64_t timeline_pos; ++ int ret; ++ ++ wtv->epoch = ++ wtv->pts = ++ wtv->last_valid_pts = AV_NOPTS_VALUE; ++ ++ /* read root directory sector */ ++ avio_skip(s->pb, 0x30); ++ root_size = avio_rl32(s->pb); ++ if (root_size > sizeof(root)) { ++ av_log(s, AV_LOG_ERROR, "root directory size exceeds sector size\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ avio_skip(s->pb, 4); ++ root_sector = avio_rl32(s->pb); ++ ++ avio_seek(s->pb, root_sector << WTV_SECTOR_BITS, SEEK_SET); ++ root_size = avio_read(s->pb, root, root_size); ++ if (root_size < 0) ++ return AVERROR_INVALIDDATA; ++ ++ /* parse chunks up until first data chunk */ ++ wtv->pb = wtvfile_open(s, root, root_size, ff_timeline_le16); ++ if (!wtv->pb) { ++ av_log(s, AV_LOG_ERROR, "timeline data missing\n"); ++ return AVERROR_INVALIDDATA; ++ } ++ ++ ret = parse_chunks(s, SEEK_TO_DATA, 0, 0); ++ if (ret < 0) ++ return ret; ++ avio_seek(wtv->pb, -32, SEEK_CUR); ++ ++ timeline_pos = avio_tell(s->pb); // save before opening another file ++ ++ /* read metadata */ ++ pb = wtvfile_open(s, root, root_size, ff_table_0_entries_legacy_attrib_le16); ++ if (pb) { ++ parse_legacy_attrib(s, pb); ++ wtvfile_close(pb); ++ } ++ ++ /* read seek index */ ++ if (s->nb_streams) { ++ AVStream *st = s->streams[0]; ++ pb = wtvfile_open(s, root, root_size, ff_table_0_entries_time_le16); ++ if (pb) { ++ while(1) { ++ uint64_t timestamp = avio_rl64(pb); ++ uint64_t frame_nb = avio_rl64(pb); ++ if (url_feof(pb)) ++ break; ++ ff_add_index_entry(&wtv->index_entries, &wtv->nb_index_entries, &wtv->index_entries_allocated_size, ++ 0, timestamp, frame_nb, 0, AVINDEX_KEYFRAME); ++ } ++ wtvfile_close(pb); ++ ++ if (wtv->nb_index_entries) { ++ pb = wtvfile_open(s, root, root_size, ff_timeline_table_0_entries_Events_le16); ++ if (pb) { ++ int i; ++ while (1) { ++ uint64_t frame_nb = avio_rl64(pb); ++ uint64_t position = avio_rl64(pb); ++ if (url_feof(pb)) ++ break; ++ for (i = wtv->nb_index_entries - 1; i >= 0; i--) { ++ AVIndexEntry *e = wtv->index_entries + i; ++ if (frame_nb > e->size) ++ break; ++ if (position > e->pos) ++ e->pos = position; ++ } ++ } ++ wtvfile_close(pb); ++ st->duration = wtv->index_entries[wtv->nb_index_entries - 1].timestamp; ++ } ++ } ++ } ++ } ++ ++ avio_seek(s->pb, timeline_pos, SEEK_SET); ++ return 0; ++} ++ ++static int read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ WtvContext *wtv = s->priv_data; ++ AVIOContext *pb = wtv->pb; ++ int stream_index, len, ret; ++ ++ stream_index = parse_chunks(s, SEEK_TO_DATA, 0, &len); ++ if (stream_index < 0) ++ return stream_index; ++ ++ ret = av_get_packet(pb, pkt, len - 32); ++ if (ret < 0) ++ return ret; ++ pkt->stream_index = stream_index; ++ pkt->pts = wtv->pts; ++ avio_skip(pb, WTV_PAD8(len) - len); ++ return 0; ++} ++ ++static int read_seek(AVFormatContext *s, int stream_index, ++ int64_t ts, int flags) ++{ ++ WtvContext *wtv = s->priv_data; ++ AVIOContext *pb = wtv->pb; ++ AVStream *st = s->streams[0]; ++ int64_t ts_relative; ++ int i; ++ ++ if ((flags & AVSEEK_FLAG_FRAME) || (flags & AVSEEK_FLAG_BYTE)) ++ return AVERROR(ENOSYS); ++ ++ /* timestamp adjustment is required because wtv->pts values are absolute, ++ * whereas AVIndexEntry->timestamp values are relative to epoch. */ ++ ts_relative = ts; ++ if (wtv->epoch != AV_NOPTS_VALUE) ++ ts_relative -= wtv->epoch; ++ ++ i = ff_index_search_timestamp(wtv->index_entries, wtv->nb_index_entries, ts_relative, flags); ++ if (i < 0) { ++ if (wtv->last_valid_pts == AV_NOPTS_VALUE || ts < wtv->last_valid_pts) { ++ if (avio_seek(pb, 0, SEEK_SET) < 0) ++ return -1; ++ } else if (st->duration != AV_NOPTS_VALUE && ts_relative > st->duration && wtv->nb_index_entries) { ++ if (avio_seek(pb, wtv->index_entries[wtv->nb_index_entries - 1].pos, SEEK_SET) < 0) ++ return -1; ++ } ++ if (parse_chunks(s, SEEK_TO_PTS, ts, 0) < 0) ++ return AVERROR(ERANGE); ++ return 0; ++ } ++ if (avio_seek(pb, wtv->index_entries[i].pos, SEEK_SET) < 0) ++ return -1; ++ wtv->pts = wtv->index_entries[i].timestamp; ++ if (wtv->epoch != AV_NOPTS_VALUE) ++ wtv->pts += wtv->epoch; ++ wtv->last_valid_pts = wtv->pts; ++ return 0; ++} ++ ++static int read_close(AVFormatContext *s) ++{ ++ WtvContext *wtv = s->priv_data; ++ av_freep(&wtv->index_entries); ++ wtvfile_close(wtv->pb); ++ return 0; ++} ++ ++AVInputFormat ff_wtv_demuxer = { ++ .name = "wtv", ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"), ++ .priv_data_size = sizeof(WtvContext), ++ .read_probe = read_probe, ++ .read_header = read_header, ++ .read_packet = read_packet, ++ .read_seek = read_seek, ++ .read_close = read_close, ++ .flags = AVFMT_SHOW_IDS, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtvenc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtvenc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtvenc.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtvenc.c 2012-05-14 14:08:55.268358779 +0200 +@@ -0,0 +1,723 @@ ++/* ++ * Windows Television (WTV) muxer ++ * Copyright (c) 2011 Zhentan Feng ++ * Copyright (c) 2011 Peter Ross ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Windows Television (WTV) demuxer ++ * @author Zhentan Feng ++ */ ++ ++#include "libavutil/intreadwrite.h" ++#include "libavutil/avassert.h" ++#include "avformat.h" ++#include "internal.h" ++#include "wtv.h" ++#include "asf.h" ++ ++#define WTV_BIGSECTOR_SIZE (1 << WTV_BIGSECTOR_BITS) ++#define INDEX_BASE 0x2 ++#define MAX_NB_INDEX 10 ++ ++/* declare utf16le strings */ ++#define _ , 0, ++static const uint8_t timeline_table_0_header_events[] = ++ {'t'_'i'_'m'_'e'_'l'_'i'_'n'_'e'_'.'_'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'E'_'v'_'e'_'n'_'t'_'s', 0}; ++static const uint8_t table_0_header_legacy_attrib[] = ++ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0}; ++static const uint8_t table_0_redirector_legacy_attrib[] = ++ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'r'_'e'_'d'_'i'_'r'_'e'_'c'_'t'_'o'_'r'_'.'_'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0}; ++static const uint8_t table_0_header_time[] = ++ {'t'_'a'_'b'_'l'_'e'_'.'_'0'_'.'_'h'_'e'_'a'_'d'_'e'_'r'_'.'_'t'_'i'_'m'_'e', 0}; ++static const uint8_t legacy_attrib[] = ++ {'l'_'e'_'g'_'a'_'c'_'y'_'_'_'a'_'t'_'t'_'r'_'i'_'b', 0}; ++#undef _ ++ ++static const ff_asf_guid sub_wtv_guid = ++ {0x8C,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; ++static const ff_asf_guid stream1_guid = ++ {0xA1,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; ++static const ff_asf_guid sync_guid = ++ {0x97,0xC3,0xD2,0xC2,0x7E,0x9A,0xDA,0x11,0x8B,0xF7,0x00,0x07,0xE9,0x5E,0xAD,0x8D}; ++static const ff_asf_guid index_guid = ++ {0x96,0xc3,0xd2,0xc2,0x7e,0x9a,0xda,0x11,0x8b,0xf7,0x00,0x07,0xe9,0x5e,0xad,0x8d}; ++ ++enum WtvFileIndex { ++ WTV_TIMELINE_TABLE_0_HEADER_EVENTS = 0, ++ WTV_TIMELINE_TABLE_0_ENTRIES_EVENTS, ++ WTV_TIMELINE, ++ WTV_TABLE_0_HEADER_LEGACY_ATTRIB, ++ WTV_TABLE_0_ENTRIES_LEGACY_ATTRIB, ++ WTV_TABLE_0_REDIRECTOR_LEGACY_ATTRIB, ++ WTV_TABLE_0_HEADER_TIME, ++ WTV_TABLE_0_ENTRIES_TIME, ++ WTV_FILES ++}; ++ ++typedef struct { ++ int64_t length; ++ const void *header; ++ int depth; ++ int first_sector; ++} WtvFile; ++ ++typedef struct { ++ int64_t pos; ++ int64_t serial; ++ const ff_asf_guid * guid; ++ int stream_id; ++} WtvChunkEntry; ++ ++typedef struct { ++ int64_t timeline_start_pos; ++ WtvFile file[WTV_FILES]; ++ int64_t serial; /** chunk serial number */ ++ int64_t last_chunk_pos; /** last chunk position */ ++ int64_t frame_nb; ++ ++ WtvChunkEntry index[MAX_NB_INDEX]; ++ int nb_index; ++ int first_video_flag; ++ int64_t sync_pos; ++} WtvContext; ++ ++typedef int WTVHeaderWriteFunc(AVIOContext *pb); ++ ++typedef struct { ++ const uint8_t *header; ++ int header_size; ++ WTVHeaderWriteFunc *write_header; ++} WTVRootEntryTable; ++ ++static int write_pad(AVIOContext *pb, int size) ++{ ++ for (; size > 0; size--) ++ avio_w8(pb, 0); ++ return 0; ++} ++ ++static const ff_asf_guid *get_codec_guid(enum CodecID id, const AVCodecGuid *av_guid) ++{ ++ int i; ++ for (i = 0; av_guid[i].id != CODEC_ID_NONE; i++) { ++ if (id == av_guid[i].id) ++ return &(av_guid[i].guid); ++ } ++ return NULL; ++} ++ ++/** ++ * Write chunk header. If header chunk (0x80000000 set) then add to list of header chunks ++ */ ++static void write_chunk_header(AVFormatContext *s, const ff_asf_guid *guid, int length, int stream_id) ++{ ++ WtvContext *wctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ++ wctx->last_chunk_pos = avio_tell(pb) - wctx->timeline_start_pos; ++ ff_put_guid(pb, guid); ++ avio_wl32(pb, 32 + length); ++ avio_wl32(pb, stream_id); ++ avio_wl64(pb, wctx->serial); ++ ++ if ((stream_id & 0x80000000) && guid != &index_guid) { ++ WtvChunkEntry *t = wctx->index + wctx->nb_index; ++ av_assert0(wctx->nb_index < MAX_NB_INDEX); ++ t->pos = wctx->last_chunk_pos; ++ t->serial = wctx->serial; ++ t->guid = guid; ++ t->stream_id = stream_id & 0x3FFFFFFF; ++ wctx->nb_index++; ++ } ++} ++ ++static void write_chunk_header2(AVFormatContext *s, const ff_asf_guid *guid, int stream_id) ++{ ++ WtvContext *wctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ++ int64_t last_chunk_pos = wctx->last_chunk_pos; ++ write_chunk_header(s, guid, 0, stream_id); // length updated later ++ avio_wl64(pb, last_chunk_pos); ++} ++ ++static void finish_chunk_noindex(AVFormatContext *s) ++{ ++ WtvContext *wctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ++ // update the chunk_len field and pad. ++ int64_t chunk_len = avio_tell(pb) - (wctx->last_chunk_pos + wctx->timeline_start_pos); ++ avio_seek(pb, -(chunk_len - 16), SEEK_CUR); ++ avio_wl32(pb, chunk_len); ++ avio_seek(pb, chunk_len - (16 + 4), SEEK_CUR); ++ ++ write_pad(pb, WTV_PAD8(chunk_len) - chunk_len); ++ wctx->serial++; ++} ++ ++static void write_index(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ int i; ++ ++ write_chunk_header2(s, &index_guid, 0x80000000); ++ avio_wl32(pb, 0); ++ avio_wl32(pb, 0); ++ ++ for (i = 0; i < wctx->nb_index; i++) { ++ WtvChunkEntry *t = wctx->index + i; ++ ff_put_guid(pb, t->guid); ++ avio_wl64(pb, t->pos); ++ avio_wl32(pb, t->stream_id); ++ avio_wl32(pb, 0); // checksum? ++ avio_wl64(pb, t->serial); ++ } ++ wctx->nb_index = 0; // reset index ++ finish_chunk_noindex(s); ++} ++ ++static void finish_chunk(AVFormatContext *s) ++{ ++ WtvContext *wctx = s->priv_data; ++ finish_chunk_noindex(s); ++ if (wctx->nb_index == MAX_NB_INDEX) ++ write_index(s); ++} ++ ++static int write_stream_codec_info(AVFormatContext *s, AVStream *st) ++{ ++ WtvContext *wctx = s->priv_data; ++ const ff_asf_guid *g, *media_type, *format_type; ++ AVIOContext *pb = s->pb; ++ int64_t hdr_pos_start; ++ int hdr_size = 0; ++ ++ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ g = get_codec_guid(st->codec->codec_id, ff_video_guids); ++ media_type = &ff_mediatype_video; ++ format_type = &ff_format_mpeg2_video; ++ } else if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO) { ++ g = get_codec_guid(st->codec->codec_id, ff_codec_wav_guids); ++ media_type = &ff_mediatype_audio; ++ format_type = &ff_format_waveformatex; ++ } else { ++ av_log(s, AV_LOG_ERROR, "unknown codec_type (0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ ++ if (g == NULL) { ++ av_log(s, AV_LOG_ERROR, "can't get video codec_id (0x%x) guid.\n", st->codec->codec_id); ++ return -1; ++ } ++ ++ ff_put_guid(pb, media_type); // mediatype ++ ff_put_guid(pb, &ff_mediasubtype_cpfilters_processed); // subtype ++ write_pad(pb, 12); ++ ff_put_guid(pb,&ff_format_cpfilters_processed); // format type ++ avio_wl32(pb, 0); // size ++ ++ hdr_pos_start = avio_tell(pb); ++ if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { ++ if (wctx->first_video_flag) { ++ write_pad(pb, 216); //The size is sensitive. ++ wctx->first_video_flag = 0; ++ } else { ++ write_pad(pb, 72); // aspect ratio ++ ff_put_bmp_header(pb, st->codec, ff_codec_bmp_tags, 0); ++ } ++ } else { ++ ff_put_wav_header(pb, st->codec); ++ } ++ hdr_size = avio_tell(pb) - hdr_pos_start; ++ ++ // seek back write hdr_size ++ avio_seek(pb, -(hdr_size + 4), SEEK_CUR); ++ avio_wl32(pb, hdr_size + 32); ++ avio_seek(pb, hdr_size, SEEK_CUR); ++ ff_put_guid(pb, g); // actual_subtype ++ ff_put_guid(pb, format_type); // actual_formattype ++ ++ return 0; ++} ++ ++static int write_stream_codec(AVFormatContext *s, AVStream * st) ++{ ++ AVIOContext *pb = s->pb; ++ int ret; ++ write_chunk_header2(s, &stream1_guid, 0x80000000 | 0x01); ++ ++ avio_wl32(pb, 0x01); ++ write_pad(pb, 4); ++ write_pad(pb, 4); ++ ++ ret = write_stream_codec_info(s, st); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "write stream codec info failed codec_type(0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ ++ finish_chunk(s); ++ return 0; ++} ++ ++static void write_sync(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ int64_t last_chunk_pos = wctx->last_chunk_pos; ++ wctx->sync_pos = avio_tell(pb) - wctx->timeline_start_pos; ++ ++ write_chunk_header(s, &sync_guid, 0x18, 0); ++ write_pad(pb, 24); ++ ++ finish_chunk(s); ++ ++ wctx->last_chunk_pos = last_chunk_pos; ++} ++ ++static void write_DSATTRIB_TRANSPORT_PROPERTIES_init(AVFormatContext *s, int stream_index) ++{ ++ AVIOContext *pb = s->pb; ++ write_chunk_header2(s, &ff_DSATTRIB_TRANSPORT_PROPERTIES, 0x80000000 | stream_index); ++ avio_wl64(pb, stream_index); ++ avio_wl64(pb, -1); ++ avio_wl64(pb, 0); ++ finish_chunk(s); ++} ++ ++static int write_stream_data(AVFormatContext *s, AVStream *st, int flag) ++{ ++ AVIOContext *pb = s->pb; ++ int ret; ++ ++ if (!flag) { ++ write_chunk_header2(s, &ff_stream_guid, 0x80000000 | (st->index + INDEX_BASE)); ++ avio_wl32(pb, 0x00000001); ++ avio_wl32(pb, st->index + INDEX_BASE); //stream_id ++ avio_wl32(pb, 0x00000001); ++ write_pad(pb, 8); ++ } else { ++ write_chunk_header2(s, &ff_stream2_guid, 0x80000000 | (st->index + INDEX_BASE)); ++ write_pad(pb, 4); ++ } ++ ++ ret = write_stream_codec_info(s, st); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "write stream codec info failed codec_type(0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ finish_chunk(s); ++ ++ avpriv_set_pts_info(st, 64, 1, 10000000); ++ ++ return 0; ++} ++ ++static int write_header(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ int i, pad, ret; ++ AVStream *st; ++ ++ ff_put_guid(pb, &ff_wtv_guid); ++ ff_put_guid(pb, &sub_wtv_guid); ++ ++ avio_wl32(pb, 0x01); ++ avio_wl32(pb, 0x02); ++ avio_wl32(pb, 1 << WTV_SECTOR_BITS); ++ avio_wl32(pb, 1 << WTV_BIGSECTOR_BITS); ++ ++ //write initial root fields ++ avio_wl32(pb, 0); // root_size, update later ++ write_pad(pb, 4); ++ avio_wl32(pb, 0); // root_sector, update it later. ++ ++ write_pad(pb, 32); ++ avio_wl32(pb, 0); // file ends pointer, update it later. ++ ++ pad = (1 << WTV_SECTOR_BITS) - avio_tell(pb); ++ write_pad(pb, pad); ++ wctx->timeline_start_pos = avio_tell(pb); ++ ++ wctx->serial = 1; ++ wctx->last_chunk_pos = -1; ++ wctx->first_video_flag = 1; ++ ++ for (i = 0; i < s->nb_streams; i++) { ++ st = s->streams[i]; ++ ret = write_stream_codec(s, st); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "write stream codec failed codec_type(0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ if (i + 1 < s->nb_streams) { ++ write_sync(s); ++ } ++ } ++ ++ for (i = 0; i < s->nb_streams; i++) { ++ st = s->streams[i]; ++ ret = write_stream_data(s, st, 0); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "write stream data failed codec_type(0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ ret = write_stream_data(s, st, 1); ++ if (ret < 0) { ++ av_log(s, AV_LOG_ERROR, "write stream2 data failed codec_type(0x%x)\n", st->codec->codec_type); ++ return -1; ++ } ++ } ++ ++ for (i = 0; i < s->nb_streams; i++) ++ write_DSATTRIB_TRANSPORT_PROPERTIES_init(s, INDEX_BASE + i); ++ ++ if (wctx->nb_index) ++ write_index(s); ++ ++ return 0; ++} ++ ++static void write_timestamp(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ AVCodecContext *enc = s->streams[pkt->stream_index]->codec; ++ int flag = 0; ++ int64_t frame_number = 0; ++ ++ if (enc->codec_type == AVMEDIA_TYPE_VIDEO) { ++ wctx->frame_nb++; ++ frame_number = wctx->frame_nb; ++ flag = pkt->flags & AV_PKT_FLAG_KEY ? 1 : 0; ++ } ++ write_chunk_header(s, &ff_timestamp_guid, 56, 0x40000000 | (INDEX_BASE + pkt->stream_index)); ++ write_pad(pb, 8); ++ avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts); ++ avio_wl64(pb, pkt->pts == AV_NOPTS_VALUE ? -1 : pkt->pts); ++ ++ avio_wl64(pb, frame_number); ++ avio_wl64(pb, 0); ++ avio_wl64(pb, flag); ++ avio_wl64(pb, 0); ++} ++ ++static int write_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ ++ // write timestamp chunk ++ write_timestamp(s, pkt); ++ ++ write_chunk_header(s, &ff_data_guid, pkt->size, INDEX_BASE + pkt->stream_index); ++ avio_write(pb, pkt->data, pkt->size); ++ write_pad(pb, WTV_PAD8(pkt->size) - pkt->size); ++ ++ wctx->serial++; ++ avio_flush(pb); ++ return 0; ++} ++ ++static int write_table0_header_envents(AVIOContext *pb) ++{ ++ avio_wl32(pb, 0x10); ++ write_pad(pb, 84); ++ avio_wl64(pb, 0x32); ++ return 96; ++} ++ ++static int write_table0_header_legacy_attrib(AVIOContext *pb) ++{ ++ int pad = 0; ++ avio_wl32(pb, 0xFFFFFFFF); ++ write_pad(pb, 12); ++ avio_write(pb, legacy_attrib, sizeof(legacy_attrib)); ++ pad = WTV_PAD8(sizeof(legacy_attrib)) - sizeof(legacy_attrib); ++ write_pad(pb, pad); ++ write_pad(pb, 32); ++ return 48 + WTV_PAD8(sizeof(legacy_attrib)); ++} ++ ++static int write_table0_header_time(AVIOContext *pb) ++{ ++ avio_wl32(pb, 0x10); ++ write_pad(pb, 76); ++ avio_wl64(pb, 0x40); ++ return 88; ++} ++ ++static const WTVRootEntryTable wtv_root_entry_table[] = { ++ { timeline_table_0_header_events, sizeof(timeline_table_0_header_events), write_table0_header_envents}, ++ { ff_timeline_table_0_entries_Events_le16, sizeof(ff_timeline_table_0_entries_Events_le16), NULL}, ++ { ff_timeline_le16, sizeof(ff_timeline_le16), NULL}, ++ { table_0_header_legacy_attrib, sizeof(table_0_header_legacy_attrib), write_table0_header_legacy_attrib}, ++ { ff_table_0_entries_legacy_attrib_le16, sizeof(ff_table_0_entries_legacy_attrib_le16), NULL}, ++ { table_0_redirector_legacy_attrib, sizeof(table_0_redirector_legacy_attrib), NULL}, ++ { table_0_header_time, sizeof(table_0_header_time), write_table0_header_time}, ++ { ff_table_0_entries_time_le16, sizeof(ff_table_0_entries_time_le16), NULL}, ++}; ++ ++static int write_root_table(AVFormatContext *s, int64_t sector_pos) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ int size, pad; ++ int i; ++ ++ const WTVRootEntryTable *h = wtv_root_entry_table; ++ for (i = 0; i < sizeof(wtv_root_entry_table)/sizeof(WTVRootEntryTable); i++, h++) { ++ WtvFile *w = &wctx->file[i]; ++ int filename_padding = WTV_PAD8(h->header_size) - h->header_size; ++ WTVHeaderWriteFunc *write = h->write_header; ++ int len = 0; ++ int64_t len_pos; ++ ++ ff_put_guid(pb, &ff_dir_entry_guid); ++ len_pos = avio_tell(pb); ++ avio_wl16(pb, 40 + h->header_size + filename_padding + 8); // maybe updated later ++ write_pad(pb, 6); ++ avio_wl64(pb, write ? 0 : w->length);// maybe update later ++ avio_wl32(pb, (h->header_size + filename_padding) >> 1); ++ write_pad(pb, 4); ++ ++ avio_write(pb, h->header, h->header_size); ++ write_pad(pb, filename_padding); ++ ++ if (write) { ++ len = write(pb); ++ // update length field ++ avio_seek(pb, len_pos, SEEK_SET); ++ avio_wl64(pb, 40 + h->header_size + filename_padding + len); ++ avio_wl64(pb, len |(1ULL<<62) | (1ULL<<60)); ++ avio_seek(pb, 8 + h->header_size + filename_padding + len, SEEK_CUR); ++ } else { ++ avio_wl32(pb, w->first_sector); ++ avio_wl32(pb, w->depth); ++ } ++ } ++ ++ // caculate root table size ++ size = avio_tell(pb) - sector_pos; ++ pad = WTV_SECTOR_SIZE- size; ++ write_pad(pb, pad); ++ ++ return size; ++} ++ ++static void write_fat(AVIOContext *pb, int start_sector, int nb_sectors, int shift) ++{ ++ int i; ++ for (i = 0; i < nb_sectors; i++) { ++ avio_wl32(pb, start_sector + (i << shift)); ++ } ++ // pad left sector pointer size ++ write_pad(pb, WTV_SECTOR_SIZE - ((nb_sectors << 2) % WTV_SECTOR_SIZE)); ++} ++ ++static int write_fat_sector(AVFormatContext *s, int64_t start_pos, int nb_sectors, int sector_bits, int depth) ++{ ++ int64_t start_sector = start_pos >> WTV_SECTOR_BITS; ++ int shift = sector_bits - WTV_SECTOR_BITS; ++ ++ int64_t fat = avio_tell(s->pb); ++ write_fat(s->pb, start_sector, nb_sectors, shift); ++ ++ if (depth == 2) { ++ int64_t start_sector1 = fat >> WTV_SECTOR_BITS; ++ int nb_sectors1 = ((nb_sectors << 2) + WTV_SECTOR_SIZE - 1) / WTV_SECTOR_SIZE; ++ int64_t fat1 = avio_tell(s->pb); ++ ++ write_fat(s->pb, start_sector1, nb_sectors1, 0); ++ return fat1; ++ } ++ ++ return fat; ++} ++ ++static void write_table_entries_events(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ WtvContext *wctx = s->priv_data; ++ ++ //FIXME: output frame_nb, position pairs. ++ //We only set the first sync_chunk position here. ++ avio_wl64(pb, 0x2); avio_wl64(pb, wctx->sync_pos); ++} ++ ++static void write_tag(AVIOContext *pb, const char *key, const char *value) ++{ ++ ff_put_guid(pb, &ff_metadata_guid); ++ avio_wl32(pb, 1); ++ avio_wl32(pb, strlen(value)*2 + 2); ++ avio_put_str16le(pb, key); ++ avio_put_str16le(pb, value); ++} ++ ++static void write_table_entries_attrib(AVFormatContext *s) ++{ ++ AVDictionaryEntry *tag = 0; ++ ++ //FIXME: translate special tags (e.g. WM/Bitrate) to binary representation ++ ff_metadata_conv(&s->metadata, ff_asf_metadata_conv, NULL); ++ while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) ++ write_tag(s->pb, tag->key, tag->value); ++} ++ ++static void write_table_redirector_legacy_attrib(AVFormatContext *s) ++{ ++ AVIOContext *pb = s->pb; ++ AVDictionaryEntry *tag = 0; ++ int64_t pos = 0; ++ ++ //FIXME: translate special tags to binary representation ++ while ((tag = av_dict_get(s->metadata, "", tag, AV_DICT_IGNORE_SUFFIX))) { ++ avio_wl64(pb, pos); ++ pos += 16 + 4 + 4 + strlen(tag->key)*2 + 2 + strlen(tag->value)*2 + 2; ++ } ++} ++ ++/** ++ * Pad the remainder of a file ++ * Write out fat table ++ * @return <0 on error ++ */ ++static int finish_file(AVFormatContext *s, enum WtvFileIndex index, int64_t start_pos) ++{ ++ WtvContext *wctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ WtvFile *w = &wctx->file[index]; ++ int64_t end_pos = avio_tell(pb); ++ int sector_bits, nb_sectors, pad; ++ ++ av_assert0(index < WTV_FILES); ++ ++ w->length = (end_pos - start_pos); ++ ++ // determine optimal fat table depth, sector_bits, nb_sectors ++ if (w->length <= WTV_SECTOR_SIZE) { ++ w->depth = 0; ++ sector_bits = WTV_SECTOR_BITS; ++ } else if (w->length <= (WTV_SECTOR_SIZE / 4) * WTV_SECTOR_SIZE) { ++ w->depth = 1; ++ sector_bits = WTV_SECTOR_BITS; ++ } else if (w->length <= (WTV_SECTOR_SIZE / 4) * WTV_BIGSECTOR_SIZE) { ++ w->depth = 1; ++ sector_bits = WTV_BIGSECTOR_BITS; ++ } else if (w->length <= (int64_t)(WTV_SECTOR_SIZE / 4) * (WTV_SECTOR_SIZE / 4) * WTV_SECTOR_SIZE) { ++ w->depth = 2; ++ sector_bits = WTV_SECTOR_BITS; ++ } else if (w->length <= (int64_t)(WTV_SECTOR_SIZE / 4) * (WTV_SECTOR_SIZE / 4) * WTV_BIGSECTOR_SIZE) { ++ w->depth = 2; ++ sector_bits = WTV_BIGSECTOR_BITS; ++ } else { ++ av_log(s, AV_LOG_ERROR, "unsupported file allocation table depth (%"PRIi64" bytes)\n", w->length); ++ return -1; ++ } ++ ++ // determine the nb_sectors ++ nb_sectors = (int)(w->length >> sector_bits); ++ ++ // pad sector of timeline ++ pad = (1 << sector_bits) - (w->length % (1 << sector_bits)); ++ if (pad) { ++ nb_sectors++; ++ write_pad(pb, pad); ++ } ++ ++ //write fat table ++ if (w->depth > 0) { ++ w->first_sector = write_fat_sector(s, start_pos, nb_sectors, sector_bits, w->depth); ++ } else { ++ w->first_sector = start_pos; ++ } ++ w->first_sector >>= WTV_SECTOR_BITS; ++ ++ w->length |= 1ULL<<60; ++ if (sector_bits == WTV_SECTOR_BITS) ++ w->length |= 1ULL<<63; ++ ++ return 0; ++} ++ ++static int write_trailer(AVFormatContext *s) ++{ ++ WtvContext *wctx = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int root_size; ++ int64_t sector_pos; ++ int64_t start_pos, file_end_pos; ++ ++ if (finish_file(s, WTV_TIMELINE, wctx->timeline_start_pos) < 0) ++ return -1; ++ ++ start_pos = avio_tell(pb); ++ write_table_entries_events(s); ++ if (finish_file(s, WTV_TIMELINE_TABLE_0_ENTRIES_EVENTS, start_pos) < 0) ++ return -1; ++ ++ start_pos = avio_tell(pb); ++ write_table_entries_attrib(s); ++ if (finish_file(s, WTV_TABLE_0_ENTRIES_LEGACY_ATTRIB, start_pos) < 0) ++ return -1; ++ ++ start_pos = avio_tell(pb); ++ write_table_redirector_legacy_attrib(s); ++ if (finish_file(s, WTV_TABLE_0_REDIRECTOR_LEGACY_ATTRIB, start_pos) < 0) ++ return -1; ++ ++ start_pos = avio_tell(pb); ++ //FIXME: output timestamp, frame_nb pairs here. ++ if (finish_file(s, WTV_TABLE_0_ENTRIES_TIME, start_pos) < 0) ++ return -1; ++ ++ // write root table ++ sector_pos = avio_tell(pb); ++ root_size = write_root_table(s, sector_pos); ++ ++ file_end_pos = avio_tell(pb); ++ // update root value ++ avio_seek(pb, 0x30, SEEK_SET); ++ avio_wl32(pb, root_size); ++ avio_seek(pb, 4, SEEK_CUR); ++ avio_wl32(pb, sector_pos >> WTV_SECTOR_BITS); ++ avio_seek(pb, 0x5c, SEEK_SET); ++ avio_wl32(pb, file_end_pos >> WTV_SECTOR_BITS); ++ ++ avio_flush(pb); ++ return 0; ++} ++ ++AVOutputFormat ff_wtv_muxer = { ++ .name = "wtv", ++ .long_name = NULL_IF_CONFIG_SMALL("Windows Television (WTV)"), ++ .extensions = "wtv", ++ .priv_data_size = sizeof(WtvContext), ++ .audio_codec = CODEC_ID_AC3, ++ .video_codec = CODEC_ID_MPEG2VIDEO, ++ .write_header = write_header, ++ .write_packet = write_packet, ++ .write_trailer = write_trailer, ++ .codec_tag = (const AVCodecTag* const []){ ff_codec_bmp_tags, ++ ff_codec_wav_tags, 0 }, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtv.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtv.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wtv.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wtv.h 2012-05-14 14:08:55.263358679 +0200 +@@ -0,0 +1,55 @@ ++/* ++ * Windows Television (WTV) ++ * Copyright (c) 2010-2011 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVFORMAT_WTV_H ++#define AVFORMAT_WTV_H ++ ++#include "riff.h" ++#include "asf.h" ++ ++#define WTV_SECTOR_BITS 12 ++#define WTV_SECTOR_SIZE (1 << WTV_SECTOR_BITS) ++#define WTV_BIGSECTOR_BITS 18 ++#define WTV_PAD8(x) (((x) + 7) & ~7) ++ ++extern const uint8_t ff_timeline_le16[16]; ++extern const uint8_t ff_timeline_table_0_entries_Events_le16[62]; ++extern const uint8_t ff_table_0_entries_legacy_attrib_le16[58]; ++extern const uint8_t ff_table_0_entries_time_le16[40]; ++ ++extern const ff_asf_guid ff_dir_entry_guid; ++extern const ff_asf_guid ff_wtv_guid; ++extern const ff_asf_guid ff_timestamp_guid; ++extern const ff_asf_guid ff_data_guid; ++extern const ff_asf_guid ff_stream_guid; ++extern const ff_asf_guid ff_mediatype_audio; ++extern const ff_asf_guid ff_mediatype_video; ++extern const ff_asf_guid ff_format_none; ++extern const AVCodecGuid ff_video_guids[]; ++ ++extern const ff_asf_guid ff_DSATTRIB_TRANSPORT_PROPERTIES; ++extern const ff_asf_guid ff_metadata_guid; ++extern const ff_asf_guid ff_stream2_guid; ++extern const ff_asf_guid ff_mediasubtype_cpfilters_processed; ++extern const ff_asf_guid ff_format_cpfilters_processed; ++extern const ff_asf_guid ff_format_waveformatex; ++extern const ff_asf_guid ff_format_mpeg2_video; ++#endif /* AVFORMAT_WTV_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/wv.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/wv.c 2012-05-14 14:08:55.269358799 +0200 +@@ -19,8 +19,11 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#include "libavutil/audioconvert.h" + #include "libavutil/intreadwrite.h" ++#include "libavutil/dict.h" + #include "avformat.h" ++#include "internal.h" + #include "apetag.h" + #include "id3v1.h" + +@@ -75,7 +78,7 @@ + return 0; + } + +-static int wv_read_block_header(AVFormatContext *ctx, ByteIOContext *pb, int append) ++static int wv_read_block_header(AVFormatContext *ctx, AVIOContext *pb, int append) + { + WVContext *wc = ctx->priv_data; + uint32_t tag, ver; +@@ -83,35 +86,38 @@ + int rate, bpp, chan; + uint32_t chmask; + +- wc->pos = url_ftell(pb); ++ wc->pos = avio_tell(pb); + if(!append){ +- tag = get_le32(pb); ++ tag = avio_rl32(pb); + if (tag != MKTAG('w', 'v', 'p', 'k')) + return -1; +- size = get_le32(pb); ++ size = avio_rl32(pb); + if(size < 24 || size > WV_BLOCK_LIMIT){ + av_log(ctx, AV_LOG_ERROR, "Incorrect block size %i\n", size); + return -1; + } + wc->blksize = size; +- ver = get_le16(pb); ++ ver = avio_rl16(pb); + if(ver < 0x402 || ver > 0x410){ + av_log(ctx, AV_LOG_ERROR, "Unsupported version %03X\n", ver); + return -1; + } +- get_byte(pb); // track no +- get_byte(pb); // track sub index +- wc->samples = get_le32(pb); // total samples in file +- wc->soff = get_le32(pb); // offset in samples of current block +- get_buffer(pb, wc->extra, WV_EXTRA_SIZE); ++ avio_r8(pb); // track no ++ avio_r8(pb); // track sub index ++ wc->samples = avio_rl32(pb); // total samples in file ++ wc->soff = avio_rl32(pb); // offset in samples of current block ++ avio_read(pb, wc->extra, WV_EXTRA_SIZE); + }else{ + size = wc->blksize; + } + wc->flags = AV_RL32(wc->extra + 4); ++ // blocks with zero samples don't contain actual audio information and should be ignored ++ if (!AV_RN32(wc->extra)) ++ return 0; + //parse flags + bpp = ((wc->flags & 3) + 1) << 3; + chan = 1 + !(wc->flags & WV_MONO); +- chmask = wc->flags & WV_MONO ? CH_LAYOUT_MONO : CH_LAYOUT_STEREO; ++ chmask = wc->flags & WV_MONO ? AV_CH_LAYOUT_MONO : AV_CH_LAYOUT_STEREO; + rate = wv_rates[(wc->flags >> 23) & 0xF]; + wc->multichannel = !!((wc->flags & WV_SINGLE_BLOCK) != WV_SINGLE_BLOCK); + if(wc->multichannel){ +@@ -119,15 +125,15 @@ + chmask = wc->chmask; + } + if((rate == -1 || !chan) && !wc->block_parsed){ +- int64_t block_end = url_ftell(pb) + wc->blksize - 24; +- if(url_is_streamed(pb)){ ++ int64_t block_end = avio_tell(pb) + wc->blksize - 24; ++ if(!pb->seekable){ + av_log(ctx, AV_LOG_ERROR, "Cannot determine additional parameters\n"); + return -1; + } +- while(url_ftell(pb) < block_end){ ++ while(avio_tell(pb) < block_end){ + int id, size; +- id = get_byte(pb); +- size = (id & 0x80) ? get_le24(pb) : get_byte(pb); ++ id = avio_r8(pb); ++ size = (id & 0x80) ? avio_rl24(pb) : avio_r8(pb); + size <<= 1; + if(id&0x40) + size--; +@@ -137,24 +143,24 @@ + av_log(ctx, AV_LOG_ERROR, "Insufficient channel information\n"); + return -1; + } +- chan = get_byte(pb); ++ chan = avio_r8(pb); + switch(size - 2){ + case 0: +- chmask = get_byte(pb); ++ chmask = avio_r8(pb); + break; + case 1: +- chmask = get_le16(pb); ++ chmask = avio_rl16(pb); + break; + case 2: +- chmask = get_le24(pb); ++ chmask = avio_rl24(pb); + break; + case 3: +- chmask = get_le32(pb); ++ chmask = avio_rl32(pb); + break; + case 5: +- url_fskip(pb, 1); +- chan |= (get_byte(pb) & 0xF) << 8; +- chmask = get_le24(pb); ++ avio_skip(pb, 1); ++ chan |= (avio_r8(pb) & 0xF) << 8; ++ chmask = avio_rl24(pb); + break; + default: + av_log(ctx, AV_LOG_ERROR, "Invalid channel info size %d\n", size); +@@ -162,19 +168,19 @@ + } + break; + case 0x27: +- rate = get_le24(pb); ++ rate = avio_rl24(pb); + break; + default: +- url_fskip(pb, size); ++ avio_skip(pb, size); + } + if(id&0x40) +- url_fskip(pb, 1); ++ avio_skip(pb, 1); + } + if(rate == -1){ + av_log(ctx, AV_LOG_ERROR, "Cannot determine custom sampling rate\n"); + return -1; + } +- url_fseek(pb, block_end - wc->blksize + 24, SEEK_SET); ++ avio_seek(pb, block_end - wc->blksize + 24, SEEK_SET); + } + if(!wc->bpp) wc->bpp = bpp; + if(!wc->chan) wc->chan = chan; +@@ -200,16 +206,22 @@ + static int wv_read_header(AVFormatContext *s, + AVFormatParameters *ap) + { +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + WVContext *wc = s->priv_data; + AVStream *st; + + wc->block_parsed = 0; +- if(wv_read_block_header(s, pb, 0) < 0) +- return -1; ++ for(;;){ ++ if(wv_read_block_header(s, pb, 0) < 0) ++ return -1; ++ if(!AV_RN32(wc->extra)) ++ avio_skip(pb, wc->blksize - 24); ++ else ++ break; ++ } + + /* now we are ready: build format streams */ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return -1; + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; +@@ -218,16 +230,16 @@ + st->codec->channel_layout = wc->chmask; + st->codec->sample_rate = wc->rate; + st->codec->bits_per_coded_sample = wc->bpp; +- av_set_pts_info(st, 64, 1, wc->rate); ++ avpriv_set_pts_info(st, 64, 1, wc->rate); + st->start_time = 0; + st->duration = wc->samples; + +- if(!url_is_streamed(s->pb)) { +- int64_t cur = url_ftell(s->pb); ++ if(s->pb->seekable) { ++ int64_t cur = avio_tell(s->pb); + ff_ape_parse_tag(s); +- if(!av_metadata_get(s->metadata, "", NULL, AV_METADATA_IGNORE_SUFFIX)) ++ if(!av_dict_get(s->metadata, "", NULL, AV_DICT_IGNORE_SUFFIX)) + ff_id3v1_read(s); +- url_fseek(s->pb, cur, SEEK_SET); ++ avio_seek(s->pb, cur, SEEK_SET); + } + + return 0; +@@ -239,6 +251,7 @@ + WVContext *wc = s->priv_data; + int ret; + int size, ver, off; ++ int64_t pos; + + if (url_feof(s->pb)) + return AVERROR(EIO); +@@ -247,19 +260,20 @@ + return -1; + } + ++ pos = wc->pos; + off = wc->multichannel ? 4 : 0; + if(av_new_packet(pkt, wc->blksize + WV_EXTRA_SIZE + off) < 0) + return AVERROR(ENOMEM); + if(wc->multichannel) + AV_WL32(pkt->data, wc->blksize + WV_EXTRA_SIZE + 12); + memcpy(pkt->data + off, wc->extra, WV_EXTRA_SIZE); +- ret = get_buffer(s->pb, pkt->data + WV_EXTRA_SIZE + off, wc->blksize); ++ ret = avio_read(s->pb, pkt->data + WV_EXTRA_SIZE + off, wc->blksize); + if(ret != wc->blksize){ + av_free_packet(pkt); + return AVERROR(EIO); + } + while(!(wc->flags & WV_END_BLOCK)){ +- if(get_le32(s->pb) != MKTAG('w', 'v', 'p', 'k')){ ++ if(avio_rl32(s->pb) != MKTAG('w', 'v', 'p', 'k')){ + av_free_packet(pkt); + return -1; + } +@@ -274,16 +288,16 @@ + return -1; + } + wc->blksize = size; +- ver = get_le16(s->pb); ++ ver = avio_rl16(s->pb); + if(ver < 0x402 || ver > 0x410){ + av_free_packet(pkt); + av_log(s, AV_LOG_ERROR, "Unsupported version %03X\n", ver); + return -1; + } +- get_byte(s->pb); // track no +- get_byte(s->pb); // track sub index +- wc->samples = get_le32(s->pb); // total samples in file +- wc->soff = get_le32(s->pb); // offset in samples of current block ++ avio_r8(s->pb); // track no ++ avio_r8(s->pb); // track sub index ++ wc->samples = avio_rl32(s->pb); // total samples in file ++ wc->soff = avio_rl32(s->pb); // offset in samples of current block + if((ret = av_append_packet(s->pb, pkt, WV_EXTRA_SIZE)) < 0){ + av_free_packet(pkt); + return ret; +@@ -303,7 +317,7 @@ + pkt->stream_index = 0; + wc->block_parsed = 1; + pkt->pts = wc->soff; +- av_add_index_entry(s->streams[0], wc->pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME); ++ av_add_index_entry(s->streams[0], pos, pkt->pts, 0, 0, AVINDEX_KEYFRAME); + return 0; + } + +@@ -317,20 +331,21 @@ + int64_t pos, pts; + + /* if found, seek there */ +- if (index >= 0){ ++ if (index >= 0 && ++ timestamp <= st->index_entries[st->nb_index_entries - 1].timestamp) { + wc->block_parsed = 1; +- url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); ++ avio_seek(s->pb, st->index_entries[index].pos, SEEK_SET); + return 0; + } + /* if timestamp is out of bounds, return error */ + if(timestamp < 0 || timestamp >= s->duration) + return -1; + +- pos = url_ftell(s->pb); ++ pos = avio_tell(s->pb); + do{ + ret = av_read_frame(s, pkt); + if (ret < 0){ +- url_fseek(s->pb, pos, SEEK_SET); ++ avio_seek(s->pb, pos, SEEK_SET); + return -1; + } + pts = pkt->pts; +@@ -340,12 +355,11 @@ + } + + AVInputFormat ff_wv_demuxer = { +- "wv", +- NULL_IF_CONFIG_SMALL("WavPack"), +- sizeof(WVContext), +- wv_probe, +- wv_read_header, +- wv_read_packet, +- NULL, +- wv_read_seek, ++ .name = "wv", ++ .long_name = NULL_IF_CONFIG_SMALL("WavPack"), ++ .priv_data_size = sizeof(WVContext), ++ .read_probe = wv_probe, ++ .read_header = wv_read_header, ++ .read_packet = wv_read_packet, ++ .read_seek = wv_read_seek, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xa.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xa.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xa.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xa.c 2012-05-14 14:08:55.270358820 +0200 +@@ -29,6 +29,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + #define XA00_TAG MKTAG('X', 'A', 0, 0) + #define XAI0_TAG MKTAG('X', 'A', 'I', 0) +@@ -66,27 +67,27 @@ + AVFormatParameters *ap) + { + MaxisXADemuxContext *xa = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVStream *st; + + /*Set up the XA Audio Decoder*/ +- st = av_new_stream(s, 0); ++ st = avformat_new_stream(s, NULL); + if (!st) + return AVERROR(ENOMEM); + + st->codec->codec_type = AVMEDIA_TYPE_AUDIO; + st->codec->codec_id = CODEC_ID_ADPCM_EA_MAXIS_XA; +- url_fskip(pb, 4); /* Skip the XA ID */ +- xa->out_size = get_le32(pb); +- url_fskip(pb, 2); /* Skip the tag */ +- st->codec->channels = get_le16(pb); +- st->codec->sample_rate = get_le32(pb); ++ avio_skip(pb, 4); /* Skip the XA ID */ ++ xa->out_size = avio_rl32(pb); ++ avio_skip(pb, 2); /* Skip the tag */ ++ st->codec->channels = avio_rl16(pb); ++ st->codec->sample_rate = avio_rl32(pb); + /* Value in file is average byte rate*/ +- st->codec->bit_rate = get_le32(pb) * 8; +- st->codec->block_align = get_le16(pb); +- st->codec->bits_per_coded_sample = get_le16(pb); ++ st->codec->bit_rate = avio_rl32(pb) * 8; ++ st->codec->block_align = avio_rl16(pb); ++ st->codec->bits_per_coded_sample = avio_rl16(pb); + +- av_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); + + return 0; + } +@@ -96,7 +97,7 @@ + { + MaxisXADemuxContext *xa = s->priv_data; + AVStream *st = s->streams[0]; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + unsigned int packet_size; + int ret; + +@@ -119,10 +120,10 @@ + } + + AVInputFormat ff_xa_demuxer = { +- "xa", +- NULL_IF_CONFIG_SMALL("Maxis XA File Format"), +- sizeof(MaxisXADemuxContext), +- xa_probe, +- xa_read_header, +- xa_read_packet, ++ .name = "xa", ++ .long_name = NULL_IF_CONFIG_SMALL("Maxis XA File Format"), ++ .priv_data_size = sizeof(MaxisXADemuxContext), ++ .read_probe = xa_probe, ++ .read_header = xa_read_header, ++ .read_packet = xa_read_packet, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xmv.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xmv.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xmv.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xmv.c 2012-05-14 14:08:55.271358840 +0200 +@@ -0,0 +1,558 @@ ++/* ++ * Microsoft XMV demuxer ++ * Copyright (c) 2011 Sven Hesse ++ * Copyright (c) 2011 Matthew Hoops ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Microsoft XMV demuxer ++ */ ++ ++#include ++ ++#include "libavutil/intreadwrite.h" ++ ++#include "avformat.h" ++#include "internal.h" ++#include "riff.h" ++ ++/** The min size of an XMV header. */ ++#define XMV_MIN_HEADER_SIZE 36 ++ ++/** Audio flag: ADPCM'd 5.1 stream, front left / right channels */ ++#define XMV_AUDIO_ADPCM51_FRONTLEFTRIGHT 1 ++/** Audio flag: ADPCM'd 5.1 stream, front center / low frequency channels */ ++#define XMV_AUDIO_ADPCM51_FRONTCENTERLOW 2 ++/** Audio flag: ADPCM'd 5.1 stream, rear left / right channels */ ++#define XMV_AUDIO_ADPCM51_REARLEFTRIGHT 4 ++ ++/** Audio flag: Any of the ADPCM'd 5.1 stream flags. */ ++#define XMV_AUDIO_ADPCM51 (XMV_AUDIO_ADPCM51_FRONTLEFTRIGHT | \ ++ XMV_AUDIO_ADPCM51_FRONTCENTERLOW | \ ++ XMV_AUDIO_ADPCM51_REARLEFTRIGHT) ++ ++/** A video packet with an XMV file. */ ++typedef struct XMVVideoPacket { ++ int stream_index; ///< The decoder stream index for this video packet. ++ ++ uint32_t data_size; ///< The size of the remaining video data. ++ uint64_t data_offset; ///< The offset of the video data within the file. ++ ++ uint32_t current_frame; ///< The current frame within this video packet. ++ uint32_t frame_count; ///< The amount of frames within this video packet. ++ ++ int has_extradata; ///< Does the video packet contain extra data? ++ uint8_t extradata[4]; ///< The extra data ++ ++ int64_t last_pts; ///< PTS of the last video frame. ++ int64_t pts; ///< PTS of the most current video frame. ++} XMVVideoPacket; ++ ++/** An audio packet with an XMV file. */ ++typedef struct XMVAudioPacket { ++ int stream_index; ///< The decoder stream index for this audio packet. ++ ++ /* Stream format properties. */ ++ uint16_t compression; ///< The type of compression. ++ uint16_t channels; ///< Number of channels. ++ uint32_t sample_rate; ///< Sampling rate. ++ uint16_t bits_per_sample; ///< Bits per compressed sample. ++ uint32_t bit_rate; ///< Bits of compressed data per second. ++ uint16_t flags; ///< Flags ++ uint16_t block_align; ///< Bytes per compressed block. ++ uint16_t block_samples; ///< Decompressed samples per compressed block. ++ ++ enum CodecID codec_id; ///< The codec ID of the compression scheme. ++ ++ uint32_t data_size; ///< The size of the remaining audio data. ++ uint64_t data_offset; ///< The offset of the audio data within the file. ++ ++ uint32_t frame_size; ///< Number of bytes to put into an audio frame. ++ ++ uint64_t block_count; ///< Running counter of decompressed audio block. ++} XMVAudioPacket; ++ ++/** Context for demuxing an XMV file. */ ++typedef struct XMVDemuxContext { ++ uint16_t audio_track_count; ///< Number of audio track in this file. ++ ++ uint32_t this_packet_size; ///< Size of the current packet. ++ uint32_t next_packet_size; ///< Size of the next packet. ++ ++ uint64_t this_packet_offset; ///< Offset of the current packet. ++ uint64_t next_packet_offset; ///< Offset of the next packet. ++ ++ uint16_t current_stream; ///< The index of the stream currently handling. ++ uint16_t stream_count; ///< The number of streams in this file. ++ ++ XMVVideoPacket video; ///< The video packet contained in each packet. ++ XMVAudioPacket *audio; ///< The audio packets contained in each packet. ++} XMVDemuxContext; ++ ++static int xmv_probe(AVProbeData *p) ++{ ++ uint32_t file_version; ++ ++ if (p->buf_size < XMV_MIN_HEADER_SIZE) ++ return 0; ++ ++ file_version = AV_RL32(p->buf + 16); ++ if ((file_version == 0) || (file_version > 4)) ++ return 0; ++ ++ if (!memcmp(p->buf + 12, "xobX", 4)) ++ return AVPROBE_SCORE_MAX; ++ ++ return 0; ++} ++ ++static int xmv_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ AVStream *vst = NULL; ++ ++ uint32_t file_version; ++ uint32_t this_packet_size; ++ uint16_t audio_track; ++ ++ avio_skip(pb, 4); /* Next packet size */ ++ ++ this_packet_size = avio_rl32(pb); ++ ++ avio_skip(pb, 4); /* Max packet size */ ++ avio_skip(pb, 4); /* "xobX" */ ++ ++ file_version = avio_rl32(pb); ++ if ((file_version != 4) && (file_version != 2)) ++ av_log_ask_for_sample(s, "Found uncommon version %d\n", file_version); ++ ++ ++ /* Video track */ ++ ++ vst = avformat_new_stream(s, NULL); ++ if (!vst) ++ return AVERROR(ENOMEM); ++ ++ avpriv_set_pts_info(vst, 32, 1, 1000); ++ ++ vst->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ vst->codec->codec_id = CODEC_ID_WMV2; ++ vst->codec->codec_tag = MKBETAG('W', 'M', 'V', '2'); ++ vst->codec->width = avio_rl32(pb); ++ vst->codec->height = avio_rl32(pb); ++ ++ vst->duration = avio_rl32(pb); ++ ++ xmv->video.stream_index = vst->index; ++ ++ /* Audio tracks */ ++ ++ xmv->audio_track_count = avio_rl16(pb); ++ ++ avio_skip(pb, 2); /* Unknown (padding?) */ ++ ++ xmv->audio = av_malloc(xmv->audio_track_count * sizeof(XMVAudioPacket)); ++ if (!xmv->audio) ++ return AVERROR(ENOMEM); ++ ++ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) { ++ XMVAudioPacket *packet = &xmv->audio[audio_track]; ++ AVStream *ast = NULL; ++ ++ packet->compression = avio_rl16(pb); ++ packet->channels = avio_rl16(pb); ++ packet->sample_rate = avio_rl32(pb); ++ packet->bits_per_sample = avio_rl16(pb); ++ packet->flags = avio_rl16(pb); ++ ++ packet->bit_rate = packet->bits_per_sample * ++ packet->sample_rate * ++ packet->channels; ++ packet->block_align = 36 * packet->channels; ++ packet->block_samples = 64; ++ packet->codec_id = ff_wav_codec_get_id(packet->compression, ++ packet->bits_per_sample); ++ ++ packet->stream_index = -1; ++ ++ packet->frame_size = 0; ++ packet->block_count = 0; ++ ++ /* TODO: ADPCM'd 5.1 sound is encoded in three separate streams. ++ * Those need to be interleaved to a proper 5.1 stream. */ ++ if (packet->flags & XMV_AUDIO_ADPCM51) ++ av_log(s, AV_LOG_WARNING, "Unsupported 5.1 ADPCM audio stream " ++ "(0x%04X)\n", packet->flags); ++ ++ ast = avformat_new_stream(s, NULL); ++ if (!ast) ++ return AVERROR(ENOMEM); ++ ++ ast->codec->codec_type = AVMEDIA_TYPE_AUDIO; ++ ast->codec->codec_id = packet->codec_id; ++ ast->codec->codec_tag = packet->compression; ++ ast->codec->channels = packet->channels; ++ ast->codec->sample_rate = packet->sample_rate; ++ ast->codec->bits_per_coded_sample = packet->bits_per_sample; ++ ast->codec->bit_rate = packet->bit_rate; ++ ast->codec->block_align = 36 * packet->channels; ++ ++ avpriv_set_pts_info(ast, 32, packet->block_samples, packet->sample_rate); ++ ++ packet->stream_index = ast->index; ++ ++ ast->duration = vst->duration; ++ } ++ ++ ++ /* Initialize the packet context */ ++ ++ xmv->next_packet_offset = avio_tell(pb); ++ xmv->next_packet_size = this_packet_size - xmv->next_packet_offset; ++ xmv->stream_count = xmv->audio_track_count + 1; ++ ++ return 0; ++} ++ ++static void xmv_read_extradata(uint8_t *extradata, AVIOContext *pb) ++{ ++ /* Read the XMV extradata */ ++ ++ uint32_t data = avio_rl32(pb); ++ ++ int mspel_bit = !!(data & 0x01); ++ int loop_filter = !!(data & 0x02); ++ int abt_flag = !!(data & 0x04); ++ int j_type_bit = !!(data & 0x08); ++ int top_left_mv_flag = !!(data & 0x10); ++ int per_mb_rl_bit = !!(data & 0x20); ++ int slice_count = (data >> 6) & 7; ++ ++ /* Write it back as standard WMV2 extradata */ ++ ++ data = 0; ++ ++ data |= mspel_bit << 15; ++ data |= loop_filter << 14; ++ data |= abt_flag << 13; ++ data |= j_type_bit << 12; ++ data |= top_left_mv_flag << 11; ++ data |= per_mb_rl_bit << 10; ++ data |= slice_count << 7; ++ ++ AV_WB32(extradata, data); ++} ++ ++static int xmv_process_packet_header(AVFormatContext *s) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ ++ uint8_t data[8]; ++ uint16_t audio_track; ++ uint64_t data_offset; ++ ++ /* Next packet size */ ++ xmv->next_packet_size = avio_rl32(pb); ++ ++ /* Packet video header */ ++ ++ if (avio_read(pb, data, 8) != 8) ++ return AVERROR(EIO); ++ ++ xmv->video.data_size = AV_RL32(data) & 0x007FFFFF; ++ ++ xmv->video.current_frame = 0; ++ xmv->video.frame_count = (AV_RL32(data) >> 23) & 0xFF; ++ ++ xmv->video.has_extradata = (data[3] & 0x80) != 0; ++ ++ /* Adding the audio data sizes and the video data size keeps you 4 bytes ++ * short for every audio track. But as playing around with XMV files with ++ * ADPCM audio showed, taking the extra 4 bytes from the audio data gives ++ * you either completely distorted audio or click (when skipping the ++ * remaining 68 bytes of the ADPCM block). Substracting 4 bytes for every ++ * audio track from the video data works at least for the audio. Probably ++ * some alignment thing? ++ * The video data has (always?) lots of padding, so it should work out... ++ */ ++ xmv->video.data_size -= xmv->audio_track_count * 4; ++ ++ xmv->current_stream = 0; ++ if (!xmv->video.frame_count) { ++ xmv->video.frame_count = 1; ++ xmv->current_stream = 1; ++ } ++ ++ /* Packet audio header */ ++ ++ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) { ++ XMVAudioPacket *packet = &xmv->audio[audio_track]; ++ ++ if (avio_read(pb, data, 4) != 4) ++ return AVERROR(EIO); ++ ++ packet->data_size = AV_RL32(data) & 0x007FFFFF; ++ if ((packet->data_size == 0) && (audio_track != 0)) ++ /* This happens when I create an XMV with several identical audio ++ * streams. From the size calculations, duplicating the previous ++ * stream's size works out, but the track data itself is silent. ++ * Maybe this should also redirect the offset to the previous track? ++ */ ++ packet->data_size = xmv->audio[audio_track - 1].data_size; ++ ++ /* Carve up the audio data in frame_count slices */ ++ packet->frame_size = packet->data_size / xmv->video.frame_count; ++ packet->frame_size -= packet->frame_size % packet->block_align; ++ } ++ ++ /* Packet data offsets */ ++ ++ data_offset = avio_tell(pb); ++ ++ xmv->video.data_offset = data_offset; ++ data_offset += xmv->video.data_size; ++ ++ for (audio_track = 0; audio_track < xmv->audio_track_count; audio_track++) { ++ xmv->audio[audio_track].data_offset = data_offset; ++ data_offset += xmv->audio[audio_track].data_size; ++ } ++ ++ /* Video frames header */ ++ ++ /* Read new video extra data */ ++ if (xmv->video.data_size > 0) { ++ if (xmv->video.has_extradata) { ++ xmv_read_extradata(xmv->video.extradata, pb); ++ ++ xmv->video.data_size -= 4; ++ xmv->video.data_offset += 4; ++ ++ if (xmv->video.stream_index >= 0) { ++ AVStream *vst = s->streams[xmv->video.stream_index]; ++ ++ assert(xmv->video.stream_index < s->nb_streams); ++ ++ if (vst->codec->extradata_size < 4) { ++ av_free(vst->codec->extradata); ++ ++ vst->codec->extradata = ++ av_malloc(4 + FF_INPUT_BUFFER_PADDING_SIZE); ++ vst->codec->extradata_size = 4; ++ } ++ ++ memcpy(vst->codec->extradata, xmv->video.extradata, 4); ++ } ++ } ++ } ++ ++ return 0; ++} ++ ++static int xmv_fetch_new_packet(AVFormatContext *s) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ int result; ++ ++ /* Seek to it */ ++ xmv->this_packet_offset = xmv->next_packet_offset; ++ if (avio_seek(pb, xmv->this_packet_offset, SEEK_SET) != xmv->this_packet_offset) ++ return AVERROR(EIO); ++ ++ /* Update the size */ ++ xmv->this_packet_size = xmv->next_packet_size; ++ if (xmv->this_packet_size < (12 + xmv->audio_track_count * 4)) ++ return AVERROR(EIO); ++ ++ /* Process the header */ ++ result = xmv_process_packet_header(s); ++ if (result) ++ return result; ++ ++ /* Update the offset */ ++ xmv->next_packet_offset = xmv->this_packet_offset + xmv->this_packet_size; ++ ++ return 0; ++} ++ ++static int xmv_fetch_audio_packet(AVFormatContext *s, ++ AVPacket *pkt, uint32_t stream) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ XMVAudioPacket *audio = &xmv->audio[stream]; ++ ++ uint32_t data_size; ++ uint32_t block_count; ++ int result; ++ ++ /* Seek to it */ ++ if (avio_seek(pb, audio->data_offset, SEEK_SET) != audio->data_offset) ++ return AVERROR(EIO); ++ ++ if ((xmv->video.current_frame + 1) < xmv->video.frame_count) ++ /* Not the last frame, get at most frame_size bytes. */ ++ data_size = FFMIN(audio->frame_size, audio->data_size); ++ else ++ /* Last frame, get the rest. */ ++ data_size = audio->data_size; ++ ++ /* Read the packet */ ++ result = av_get_packet(pb, pkt, data_size); ++ if (result <= 0) ++ return result; ++ ++ pkt->stream_index = audio->stream_index; ++ ++ /* Calculate the PTS */ ++ ++ block_count = data_size / audio->block_align; ++ ++ pkt->duration = block_count; ++ pkt->pts = audio->block_count; ++ pkt->dts = AV_NOPTS_VALUE; ++ ++ audio->block_count += block_count; ++ ++ /* Advance offset */ ++ audio->data_size -= data_size; ++ audio->data_offset += data_size; ++ ++ return 0; ++} ++ ++static int xmv_fetch_video_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ AVIOContext *pb = s->pb; ++ XMVVideoPacket *video = &xmv->video; ++ ++ int result; ++ uint32_t frame_header; ++ uint32_t frame_size, frame_timestamp; ++ uint8_t *data, *end; ++ ++ /* Seek to it */ ++ if (avio_seek(pb, video->data_offset, SEEK_SET) != video->data_offset) ++ return AVERROR(EIO); ++ ++ /* Read the frame header */ ++ frame_header = avio_rl32(pb); ++ ++ frame_size = (frame_header & 0x1FFFF) * 4 + 4; ++ frame_timestamp = (frame_header >> 17); ++ ++ if ((frame_size + 4) > video->data_size) ++ return AVERROR(EIO); ++ ++ /* Get the packet data */ ++ result = av_get_packet(pb, pkt, frame_size); ++ if (result != frame_size) ++ return result; ++ ++ /* Contrary to normal WMV2 video, the bit stream in XMV's ++ * WMV2 is little-endian. ++ * TODO: This manual swap is of course suboptimal. ++ */ ++ for (data = pkt->data, end = pkt->data + frame_size; data < end; data += 4) ++ AV_WB32(data, AV_RL32(data)); ++ ++ pkt->stream_index = video->stream_index; ++ ++ /* Calculate the PTS */ ++ ++ video->last_pts = frame_timestamp + video->pts; ++ ++ pkt->duration = 0; ++ pkt->pts = video->last_pts; ++ pkt->dts = AV_NOPTS_VALUE; ++ ++ video->pts += frame_timestamp; ++ ++ /* Keyframe? */ ++ pkt->flags = (pkt->data[0] & 0x80) ? 0 : AV_PKT_FLAG_KEY; ++ ++ /* Advance offset */ ++ video->data_size -= frame_size + 4; ++ video->data_offset += frame_size + 4; ++ ++ return 0; ++} ++ ++static int xmv_read_packet(AVFormatContext *s, ++ AVPacket *pkt) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ int result; ++ ++ if (xmv->video.current_frame == xmv->video.frame_count) { ++ /* No frames left in this packet, so we fetch a new one */ ++ ++ result = xmv_fetch_new_packet(s); ++ if (result) ++ return result; ++ } ++ ++ if (xmv->current_stream == 0) { ++ /* Fetch a video frame */ ++ ++ result = xmv_fetch_video_packet(s, pkt); ++ if (result) ++ return result; ++ ++ } else { ++ /* Fetch an audio frame */ ++ ++ result = xmv_fetch_audio_packet(s, pkt, xmv->current_stream - 1); ++ if (result) ++ return result; ++ } ++ ++ /* Increase our counters */ ++ if (++xmv->current_stream >= xmv->stream_count) { ++ xmv->current_stream = 0; ++ xmv->video.current_frame += 1; ++ } ++ ++ return 0; ++} ++ ++static int xmv_read_close(AVFormatContext *s) ++{ ++ XMVDemuxContext *xmv = s->priv_data; ++ ++ av_free(xmv->audio); ++ ++ return 0; ++} ++ ++AVInputFormat ff_xmv_demuxer = { ++ .name = "xmv", ++ .long_name = NULL_IF_CONFIG_SMALL("Microsoft XMV"), ++ .priv_data_size = sizeof(XMVDemuxContext), ++ .read_probe = xmv_probe, ++ .read_header = xmv_read_header, ++ .read_packet = xmv_read_packet, ++ .read_close = xmv_read_close, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xwma.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xwma.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/xwma.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/xwma.c 2012-05-14 14:08:55.272358860 +0200 +@@ -0,0 +1,262 @@ ++/* ++ * xWMA demuxer ++ * Copyright (c) 2011 Max Horn ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "avformat.h" ++#include "internal.h" ++#include "riff.h" ++ ++/* ++ * Demuxer for xWMA, a Microsoft audio container used by XAudio 2. ++ */ ++ ++typedef struct { ++ int64_t data_end; ++} XWMAContext; ++ ++static int xwma_probe(AVProbeData *p) ++{ ++ if (!memcmp(p->buf, "RIFF", 4) && !memcmp(p->buf + 8, "XWMA", 4)) ++ return AVPROBE_SCORE_MAX; ++ return 0; ++} ++ ++static int xwma_read_header(AVFormatContext *s, AVFormatParameters *ap) ++{ ++ int64_t size, av_uninit(data_size); ++ int ret; ++ uint32_t dpds_table_size = 0; ++ uint32_t *dpds_table = 0; ++ unsigned int tag; ++ AVIOContext *pb = s->pb; ++ AVStream *st; ++ XWMAContext *xwma = s->priv_data; ++ int i; ++ ++ /* The following code is mostly copied from wav.c, with some ++ * minor alterations. ++ */ ++ ++ /* check RIFF header */ ++ tag = avio_rl32(pb); ++ if (tag != MKTAG('R', 'I', 'F', 'F')) ++ return -1; ++ avio_rl32(pb); /* file size */ ++ tag = avio_rl32(pb); ++ if (tag != MKTAG('X', 'W', 'M', 'A')) ++ return -1; ++ ++ /* parse fmt header */ ++ tag = avio_rl32(pb); ++ if (tag != MKTAG('f', 'm', 't', ' ')) ++ return -1; ++ size = avio_rl32(pb); ++ st = avformat_new_stream(s, NULL); ++ if (!st) ++ return AVERROR(ENOMEM); ++ ++ ret = ff_get_wav_header(pb, st->codec, size); ++ if (ret < 0) ++ return ret; ++ st->need_parsing = AVSTREAM_PARSE_NONE; ++ ++ /* All xWMA files I have seen contained WMAv2 data. If there are files ++ * using WMA Pro or some other codec, then we need to figure out the right ++ * extradata for that. Thus, ask the user for feedback, but try to go on ++ * anyway. ++ */ ++ if (st->codec->codec_id != CODEC_ID_WMAV2) { ++ av_log(s, AV_LOG_WARNING, "unexpected codec (tag 0x04%x; id %d)\n", ++ st->codec->codec_tag, st->codec->codec_id); ++ av_log_ask_for_sample(s, NULL); ++ } else { ++ /* In all xWMA files I have seen, there is no extradata. But the WMA ++ * codecs require extradata, so we provide our own fake extradata. ++ * ++ * First, check that there really was no extradata in the header. If ++ * there was, then try to use it, after asking the user to provide a ++ * sample of this unusual file. ++ */ ++ if (st->codec->extradata_size != 0) { ++ /* Surprise, surprise: We *did* get some extradata. No idea ++ * if it will work, but just go on and try it, after asking ++ * the user for a sample. ++ */ ++ av_log(s, AV_LOG_WARNING, "unexpected extradata (%d bytes)\n", ++ st->codec->extradata_size); ++ av_log_ask_for_sample(s, NULL); ++ } else { ++ st->codec->extradata_size = 6; ++ st->codec->extradata = av_mallocz(6 + FF_INPUT_BUFFER_PADDING_SIZE); ++ if (!st->codec->extradata) ++ return AVERROR(ENOMEM); ++ ++ /* setup extradata with our experimentally obtained value */ ++ st->codec->extradata[4] = 31; ++ } ++ } ++ ++ /* set the sample rate */ ++ avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate); ++ ++ /* parse the remaining RIFF chunks */ ++ for (;;) { ++ if (pb->eof_reached) ++ return -1; ++ /* read next chunk tag */ ++ tag = avio_rl32(pb); ++ size = avio_rl32(pb); ++ if (tag == MKTAG('d', 'a', 't', 'a')) { ++ /* We assume that the data chunk comes last. */ ++ break; ++ } else if (tag == MKTAG('d','p','d','s')) { ++ /* Quoting the MSDN xWMA docs on the dpds chunk: "Contains the ++ * decoded packet cumulative data size array, each element is the ++ * number of bytes accumulated after the corresponding xWMA packet ++ * is decoded in order." ++ * ++ * Each packet has size equal to st->codec->block_align, which in ++ * all cases I saw so far was always 2230. Thus, we can use the ++ * dpds data to compute a seeking index. ++ */ ++ ++ /* Error out if there is more than one dpds chunk. */ ++ if (dpds_table) { ++ av_log(s, AV_LOG_ERROR, "two dpds chunks present\n"); ++ return -1; ++ } ++ ++ /* Compute the number of entries in the dpds chunk. */ ++ if (size & 3) { /* Size should be divisible by four */ ++ av_log(s, AV_LOG_WARNING, ++ "dpds chunk size %"PRId64" not divisible by 4\n", size); ++ } ++ dpds_table_size = size / 4; ++ if (dpds_table_size == 0 || dpds_table_size >= INT_MAX / 4) { ++ av_log(s, AV_LOG_ERROR, ++ "dpds chunk size %"PRId64" invalid\n", size); ++ return -1; ++ } ++ ++ /* Allocate some temporary storage to keep the dpds data around. ++ * for processing later on. ++ */ ++ dpds_table = av_malloc(dpds_table_size * sizeof(uint32_t)); ++ if (!dpds_table) { ++ return AVERROR(ENOMEM); ++ } ++ ++ for (i = 0; i < dpds_table_size; ++i) { ++ dpds_table[i] = avio_rl32(pb); ++ size -= 4; ++ } ++ } ++ avio_skip(pb, size); ++ } ++ ++ /* Determine overall data length */ ++ if (size < 0) ++ return -1; ++ if (!size) { ++ xwma->data_end = INT64_MAX; ++ } else ++ xwma->data_end = avio_tell(pb) + size; ++ ++ ++ if (dpds_table && dpds_table_size) { ++ int64_t cur_pos; ++ const uint32_t bytes_per_sample ++ = (st->codec->channels * st->codec->bits_per_coded_sample) >> 3; ++ ++ /* Estimate the duration from the total number of output bytes. */ ++ const uint64_t total_decoded_bytes = dpds_table[dpds_table_size - 1]; ++ st->duration = total_decoded_bytes / bytes_per_sample; ++ ++ /* Use the dpds data to build a seek table. We can only do this after ++ * we know the offset to the data chunk, as we need that to determine ++ * the actual offset to each input block. ++ * Note: If we allowed ourselves to assume that the data chunk always ++ * follows immediately after the dpds block, we could of course guess ++ * the data block's start offset already while reading the dpds chunk. ++ * I decided against that, just in case other chunks ever are ++ * discovered. ++ */ ++ cur_pos = avio_tell(pb); ++ for (i = 0; i < dpds_table_size; ++i) { ++ /* From the number of output bytes that would accumulate in the ++ * output buffer after decoding the first (i+1) packets, we compute ++ * an offset / timestamp pair. ++ */ ++ av_add_index_entry(st, ++ cur_pos + (i+1) * st->codec->block_align, /* pos */ ++ dpds_table[i] / bytes_per_sample, /* timestamp */ ++ st->codec->block_align, /* size */ ++ 0, /* duration */ ++ AVINDEX_KEYFRAME); ++ } ++ } else if (st->codec->bit_rate) { ++ /* No dpds chunk was present (or only an empty one), so estimate ++ * the total duration using the average bits per sample and the ++ * total data length. ++ */ ++ st->duration = (size<<3) * st->codec->sample_rate / st->codec->bit_rate; ++ } ++ ++ av_free(dpds_table); ++ ++ return 0; ++} ++ ++static int xwma_read_packet(AVFormatContext *s, AVPacket *pkt) ++{ ++ int ret, size; ++ int64_t left; ++ AVStream *st; ++ XWMAContext *xwma = s->priv_data; ++ ++ st = s->streams[0]; ++ ++ left = xwma->data_end - avio_tell(s->pb); ++ if (left <= 0) { ++ return AVERROR_EOF; ++ } ++ ++ /* read a single block; the default block size is 2230. */ ++ size = (st->codec->block_align > 1) ? st->codec->block_align : 2230; ++ size = FFMIN(size, left); ++ ++ ret = av_get_packet(s->pb, pkt, size); ++ if (ret < 0) ++ return ret; ++ ++ pkt->stream_index = 0; ++ return ret; ++} ++ ++AVInputFormat ff_xwma_demuxer = { ++ .name = "xwma", ++ .long_name = NULL_IF_CONFIG_SMALL("Microsoft xWMA"), ++ .priv_data_size = sizeof(XWMAContext), ++ .read_probe = xwma_probe, ++ .read_header = xwma_read_header, ++ .read_packet = xwma_read_packet, ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/yop.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/yop.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/yop.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/yop.c 2012-05-14 14:08:55.273358880 +0200 +@@ -1,5 +1,4 @@ +-/** +- * @file ++/* + * Psygnosis YOP demuxer + * + * Copyright (C) 2010 Mohamed Naufal Basheer +@@ -25,6 +24,7 @@ + + #include "libavutil/intreadwrite.h" + #include "avformat.h" ++#include "internal.h" + + typedef struct yop_dec_context { + AVPacket video_packet; +@@ -50,15 +50,15 @@ + static int yop_read_header(AVFormatContext *s, AVFormatParameters *ap) + { + YopDecContext *yop = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + AVCodecContext *audio_dec, *video_dec; + AVStream *audio_stream, *video_stream; + + int frame_rate, ret; + +- audio_stream = av_new_stream(s, 0); +- video_stream = av_new_stream(s, 1); ++ audio_stream = avformat_new_stream(s, NULL); ++ video_stream = avformat_new_stream(s, NULL); + + // Extra data that will be passed to the decoder + video_stream->codec->extradata_size = 8; +@@ -72,7 +72,7 @@ + // Audio + audio_dec = audio_stream->codec; + audio_dec->codec_type = AVMEDIA_TYPE_AUDIO; +- audio_dec->codec_id = CODEC_ID_ADPCM_IMA_WS; ++ audio_dec->codec_id = CODEC_ID_ADPCM_IMA_APC; + audio_dec->channels = 1; + audio_dec->sample_rate = 22050; + +@@ -81,16 +81,16 @@ + video_dec->codec_type = AVMEDIA_TYPE_VIDEO; + video_dec->codec_id = CODEC_ID_YOP; + +- url_fskip(pb, 6); ++ avio_skip(pb, 6); + +- frame_rate = get_byte(pb); +- yop->frame_size = get_byte(pb) * 2048; +- video_dec->width = get_le16(pb); +- video_dec->height = get_le16(pb); ++ frame_rate = avio_r8(pb); ++ yop->frame_size = avio_r8(pb) * 2048; ++ video_dec->width = avio_rl16(pb); ++ video_dec->height = avio_rl16(pb); + + video_stream->sample_aspect_ratio = (AVRational){1, 2}; + +- ret = get_buffer(pb, video_dec->extradata, 8); ++ ret = avio_read(pb, video_dec->extradata, 8); + if (ret < 8) + return ret < 0 ? ret : AVERROR_EOF; + +@@ -104,9 +104,9 @@ + return AVERROR_INVALIDDATA; + } + +- url_fseek(pb, 2048, SEEK_SET); ++ avio_seek(pb, 2048, SEEK_SET); + +- av_set_pts_info(video_stream, 32, 1, frame_rate); ++ avpriv_set_pts_info(video_stream, 32, 1, frame_rate); + + return 0; + } +@@ -114,7 +114,7 @@ + static int yop_read_packet(AVFormatContext *s, AVPacket *pkt) + { + YopDecContext *yop = s->priv_data; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + + int ret; + int actual_video_data_size = yop->frame_size - +@@ -136,9 +136,9 @@ + if (ret < 0) + return ret; + +- yop->video_packet.pos = url_ftell(pb); ++ yop->video_packet.pos = avio_tell(pb); + +- ret = get_buffer(pb, yop->video_packet.data, yop->palette_size); ++ ret = avio_read(pb, yop->video_packet.data, yop->palette_size); + if (ret < 0) { + goto err_out; + }else if (ret < yop->palette_size) { +@@ -153,9 +153,9 @@ + // Set position to the start of the frame + pkt->pos = yop->video_packet.pos; + +- url_fskip(pb, yop->audio_block_length - ret); ++ avio_skip(pb, yop->audio_block_length - ret); + +- ret = get_buffer(pb, yop->video_packet.data + yop->palette_size, ++ ret = avio_read(pb, yop->video_packet.data + yop->palette_size, + actual_video_data_size); + if (ret < 0) + goto err_out; +@@ -184,33 +184,35 @@ + int64_t frame_pos, pos_min, pos_max; + int frame_count; + +- av_free_packet(&yop->video_packet); +- + if (!stream_index) + return -1; + + pos_min = s->data_offset; +- pos_max = url_fsize(s->pb) - yop->frame_size; ++ pos_max = avio_size(s->pb) - yop->frame_size; + frame_count = (pos_max - pos_min) / yop->frame_size; + + timestamp = FFMAX(0, FFMIN(frame_count, timestamp)); + + frame_pos = timestamp * yop->frame_size + pos_min; ++ ++ if (avio_seek(s->pb, frame_pos, SEEK_SET) < 0) ++ return -1; ++ ++ av_free_packet(&yop->video_packet); + yop->odd_frame = timestamp & 1; + +- url_fseek(s->pb, frame_pos, SEEK_SET); + return 0; + } + + AVInputFormat ff_yop_demuxer = { +- "yop", +- NULL_IF_CONFIG_SMALL("Psygnosis YOP Format"), +- sizeof(YopDecContext), +- yop_probe, +- yop_read_header, +- yop_read_packet, +- yop_read_close, +- yop_read_seek, ++ .name = "yop", ++ .long_name = NULL_IF_CONFIG_SMALL("Psygnosis YOP Format"), ++ .priv_data_size = sizeof(YopDecContext), ++ .read_probe = yop_probe, ++ .read_header = yop_read_header, ++ .read_packet = yop_read_packet, ++ .read_close = yop_read_close, ++ .read_seek = yop_read_seek, + .extensions = "yop", + .flags = AVFMT_GENERIC_INDEX, + }; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/yuv4mpeg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/yuv4mpeg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavformat/yuv4mpeg.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavformat/yuv4mpeg.c 2012-05-14 14:08:55.275358920 +0200 +@@ -19,6 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + #include "avformat.h" ++#include "internal.h" + + #define Y4M_MAGIC "YUV4MPEG2" + #define Y4M_FRAME_MAGIC "FRAME" +@@ -38,23 +39,24 @@ + char inter; + const char *colorspace = ""; + +- st = s->streams[0]; +- width = st->codec->width; ++ st = s->streams[0]; ++ width = st->codec->width; + height = st->codec->height; + +- av_reduce(&raten, &rated, st->codec->time_base.den, st->codec->time_base.num, (1UL<<31)-1); ++ av_reduce(&raten, &rated, st->codec->time_base.den, ++ st->codec->time_base.num, (1UL << 31) - 1); + + aspectn = st->sample_aspect_ratio.num; + aspectd = st->sample_aspect_ratio.den; + +- if ( aspectn == 0 && aspectd == 1 ) aspectd = 0; // 0:0 means unknown ++ if (aspectn == 0 && aspectd == 1) ++ aspectd = 0; // 0:0 means unknown + + inter = 'p'; /* progressive is the default */ +- if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) { ++ if (st->codec->coded_frame && st->codec->coded_frame->interlaced_frame) + inter = st->codec->coded_frame->top_field_first ? 't' : 'b'; +- } + +- switch(st->codec->pix_fmt) { ++ switch (st->codec->pix_fmt) { + case PIX_FMT_GRAY8: + colorspace = " Cmono"; + break; +@@ -62,9 +64,11 @@ + colorspace = " C411 XYSCSS=411"; + break; + case PIX_FMT_YUV420P: +- colorspace = (st->codec->chroma_sample_location == AVCHROMA_LOC_TOPLEFT)?" C420paldv XYSCSS=420PALDV": +- (st->codec->chroma_sample_location == AVCHROMA_LOC_LEFT) ?" C420mpeg2 XYSCSS=420MPEG2": +- " C420jpeg XYSCSS=420JPEG"; ++ switch (st->codec->chroma_sample_location) { ++ case AVCHROMA_LOC_TOPLEFT: colorspace = " C420paldv XYSCSS=420PALDV"; break; ++ case AVCHROMA_LOC_LEFT: colorspace = " C420mpeg2 XYSCSS=420MPEG2"; break; ++ default: colorspace = " C420jpeg XYSCSS=420JPEG"; break; ++ } + break; + case PIX_FMT_YUV422P: + colorspace = " C422 XYSCSS=422"; +@@ -76,13 +80,8 @@ + + /* construct stream header, if this is the first frame */ + n = snprintf(buf, Y4M_LINE_MAX, "%s W%d H%d F%d:%d I%c A%d:%d%s\n", +- Y4M_MAGIC, +- width, +- height, +- raten, rated, +- inter, +- aspectn, aspectd, +- colorspace); ++ Y4M_MAGIC, width, height, raten, rated, inter, ++ aspectn, aspectd, colorspace); + + return n; + } +@@ -90,12 +89,12 @@ + static int yuv4_write_packet(AVFormatContext *s, AVPacket *pkt) + { + AVStream *st = s->streams[pkt->stream_index]; +- ByteIOContext *pb = s->pb; ++ AVIOContext *pb = s->pb; + AVPicture *picture; + int* first_pkt = s->priv_data; + int width, height, h_chroma_shift, v_chroma_shift; +- int i, m; +- char buf2[Y4M_LINE_MAX+1]; ++ int i; ++ char buf2[Y4M_LINE_MAX + 1]; + char buf1[20]; + uint8_t *ptr, *ptr1, *ptr2; + +@@ -105,63 +104,73 @@ + if (*first_pkt) { + *first_pkt = 0; + if (yuv4_generate_header(s, buf2) < 0) { +- av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n"); ++ av_log(s, AV_LOG_ERROR, ++ "Error. YUV4MPEG stream header write failed.\n"); + return AVERROR(EIO); + } else { +- put_buffer(pb, buf2, strlen(buf2)); ++ avio_write(pb, buf2, strlen(buf2)); + } + } + + /* construct frame header */ + +- m = snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); +- put_buffer(pb, buf1, strlen(buf1)); ++ snprintf(buf1, sizeof(buf1), "%s\n", Y4M_FRAME_MAGIC); ++ avio_write(pb, buf1, strlen(buf1)); + +- width = st->codec->width; ++ width = st->codec->width; + height = st->codec->height; + + ptr = picture->data[0]; +- for(i=0;ilinesize[0]; + } + +- if (st->codec->pix_fmt != PIX_FMT_GRAY8){ +- // Adjust for smaller Cb and Cr planes +- avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, &v_chroma_shift); +- width >>= h_chroma_shift; +- height >>= v_chroma_shift; +- +- ptr1 = picture->data[1]; +- ptr2 = picture->data[2]; +- for(i=0;ilinesize[1]; +- } +- for(i=0;icodec->pix_fmt != PIX_FMT_GRAY8) { ++ // Adjust for smaller Cb and Cr planes ++ avcodec_get_chroma_sub_sample(st->codec->pix_fmt, &h_chroma_shift, ++ &v_chroma_shift); ++ width >>= h_chroma_shift; ++ height >>= v_chroma_shift; ++ ++ ptr1 = picture->data[1]; ++ ptr2 = picture->data[2]; ++ for (i = 0; i < height; i++) { /* Cb */ ++ avio_write(pb, ptr1, width); ++ ptr1 += picture->linesize[1]; ++ } ++ for (i = 0; i < height; i++) { /* Cr */ ++ avio_write(pb, ptr2, width); + ptr2 += picture->linesize[2]; ++ } + } +- } +- put_flush_packet(pb); ++ avio_flush(pb); + return 0; + } + + static int yuv4_write_header(AVFormatContext *s) + { +- int* first_pkt = s->priv_data; ++ int *first_pkt = s->priv_data; + + if (s->nb_streams != 1) + return AVERROR(EIO); + +- if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) { +- av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV stream, some mjpegtools might not work.\n"); ++ if (s->streams[0]->codec->codec_id != CODEC_ID_RAWVIDEO) { ++ av_log(s, AV_LOG_ERROR, ++ "A non-rawvideo stream was selected, but yuv4mpeg only handles rawvideo streams\n"); ++ return AVERROR(EINVAL); + } +- else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) && +- (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) && +- (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) && +- (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) { +- av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, yuv422p, yuv420p, yuv411p and gray pixel formats. Use -pix_fmt to select one.\n"); ++ ++ if (s->streams[0]->codec->pix_fmt == PIX_FMT_YUV411P) { ++ av_log(s, AV_LOG_ERROR, "Warning: generating rarely used 4:1:1 YUV " ++ "stream, some mjpegtools might not work.\n"); ++ } else if ((s->streams[0]->codec->pix_fmt != PIX_FMT_YUV420P) && ++ (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV422P) && ++ (s->streams[0]->codec->pix_fmt != PIX_FMT_GRAY8) && ++ (s->streams[0]->codec->pix_fmt != PIX_FMT_YUV444P)) { ++ av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles yuv444p, " ++ "yuv422p, yuv420p, yuv411p and gray pixel formats. " ++ "Use -pix_fmt to select one.\n"); + return AVERROR(EIO); + } + +@@ -170,16 +179,15 @@ + } + + AVOutputFormat ff_yuv4mpegpipe_muxer = { +- "yuv4mpegpipe", +- NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"), +- "", +- "y4m", +- sizeof(int), +- CODEC_ID_NONE, +- CODEC_ID_RAWVIDEO, +- yuv4_write_header, +- yuv4_write_packet, +- .flags = AVFMT_RAWPICTURE, ++ .name = "yuv4mpegpipe", ++ .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"), ++ .extensions = "y4m", ++ .priv_data_size = sizeof(int), ++ .audio_codec = CODEC_ID_NONE, ++ .video_codec = CODEC_ID_RAWVIDEO, ++ .write_header = yuv4_write_header, ++ .write_packet = yuv4_write_packet, ++ .flags = AVFMT_RAWPICTURE, + }; + #endif + +@@ -189,85 +197,96 @@ + + static int yuv4_read_header(AVFormatContext *s, AVFormatParameters *ap) + { +- char header[MAX_YUV4_HEADER+10]; // Include headroom for the longest option +- char *tokstart,*tokend,*header_end; ++ char header[MAX_YUV4_HEADER + 10]; // Include headroom for ++ // the longest option ++ char *tokstart, *tokend, *header_end; + int i; +- ByteIOContext *pb = s->pb; +- int width=-1, height=-1, raten=0, rated=0, aspectn=0, aspectd=0; +- enum PixelFormat pix_fmt=PIX_FMT_NONE,alt_pix_fmt=PIX_FMT_NONE; ++ AVIOContext *pb = s->pb; ++ int width = -1, height = -1, raten = 0, ++ rated = 0, aspectn = 0, aspectd = 0; ++ enum PixelFormat pix_fmt = PIX_FMT_NONE, alt_pix_fmt = PIX_FMT_NONE; + enum AVChromaLocation chroma_sample_location = AVCHROMA_LOC_UNSPECIFIED; + AVStream *st; + struct frame_attributes *s1 = s->priv_data; + +- for (i=0; iinterlaced_frame = 0; + s1->top_field_first = 0; +- header_end = &header[i+1]; // Include space +- for(tokstart = &header[strlen(Y4M_MAGIC) + 1]; tokstart < header_end; tokstart++) { +- if (*tokstart==0x20) continue; ++ header_end = &header[i + 1]; // Include space ++ for (tokstart = &header[strlen(Y4M_MAGIC) + 1]; ++ tokstart < header_end; tokstart++) { ++ if (*tokstart == 0x20) ++ continue; + switch (*tokstart++) { + case 'W': // Width. Required. +- width = strtol(tokstart, &tokend, 10); +- tokstart=tokend; ++ width = strtol(tokstart, &tokend, 10); ++ tokstart = tokend; + break; + case 'H': // Height. Required. +- height = strtol(tokstart, &tokend, 10); +- tokstart=tokend; ++ height = strtol(tokstart, &tokend, 10); ++ tokstart = tokend; + break; + case 'C': // Color space +- if (strncmp("420jpeg",tokstart,7)==0) { ++ if (strncmp("420jpeg", tokstart, 7) == 0) { + pix_fmt = PIX_FMT_YUV420P; + chroma_sample_location = AVCHROMA_LOC_CENTER; +- } else if (strncmp("420mpeg2",tokstart,8)==0) { ++ } else if (strncmp("420mpeg2", tokstart, 8) == 0) { + pix_fmt = PIX_FMT_YUV420P; + chroma_sample_location = AVCHROMA_LOC_LEFT; +- } else if (strncmp("420paldv", tokstart, 8)==0) { ++ } else if (strncmp("420paldv", tokstart, 8) == 0) { + pix_fmt = PIX_FMT_YUV420P; + chroma_sample_location = AVCHROMA_LOC_TOPLEFT; +- } else if (strncmp("411", tokstart, 3)==0) ++ } else if (strncmp("411", tokstart, 3) == 0) + pix_fmt = PIX_FMT_YUV411P; +- else if (strncmp("422", tokstart, 3)==0) ++ else if (strncmp("422", tokstart, 3) == 0) + pix_fmt = PIX_FMT_YUV422P; +- else if (strncmp("444alpha", tokstart, 8)==0) { +- av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 YUV4MPEG stream.\n"); ++ else if (strncmp("444alpha", tokstart, 8) == 0 ) { ++ av_log(s, AV_LOG_ERROR, "Cannot handle 4:4:4:4 " ++ "YUV4MPEG stream.\n"); + return -1; +- } else if (strncmp("444", tokstart, 3)==0) ++ } else if (strncmp("444", tokstart, 3) == 0) + pix_fmt = PIX_FMT_YUV444P; +- else if (strncmp("mono",tokstart, 4)==0) { ++ else if (strncmp("mono", tokstart, 4) == 0) { + pix_fmt = PIX_FMT_GRAY8; + } else { +- av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown pixel format.\n"); ++ av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains an unknown " ++ "pixel format.\n"); + return -1; + } +- while(tokstartinterlaced_frame=0; ++ s1->interlaced_frame = 0; + break; + case 't': +- s1->interlaced_frame=1; +- s1->top_field_first=1; ++ s1->interlaced_frame = 1; ++ s1->top_field_first = 1; + break; + case 'b': +- s1->interlaced_frame=1; +- s1->top_field_first=0; ++ s1->interlaced_frame = 1; ++ s1->top_field_first = 0; + break; + case 'm': +- av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed interlaced and non-interlaced frames.\n"); ++ av_log(s, AV_LOG_ERROR, "YUV4MPEG stream contains mixed " ++ "interlaced and non-interlaced frames.\n"); + return -1; + default: + av_log(s, AV_LOG_ERROR, "YUV4MPEG has invalid header.\n"); +@@ -275,36 +294,39 @@ + } + break; + case 'F': // Frame rate +- sscanf(tokstart,"%d:%d",&raten,&rated); // 0:0 if unknown +- while(tokstartcodec->width = width; ++ st->codec->width = width; + st->codec->height = height; +- av_reduce(&raten, &rated, raten, rated, (1UL<<31)-1); +- av_set_pts_info(st, 64, rated, raten); +- st->codec->pix_fmt = pix_fmt; +- st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- st->codec->codec_id = CODEC_ID_RAWVIDEO; +- st->sample_aspect_ratio= (AVRational){aspectn, aspectd}; ++ av_reduce(&raten, &rated, raten, rated, (1UL << 31) - 1); ++ avpriv_set_pts_info(st, 64, rated, raten); ++ st->codec->pix_fmt = pix_fmt; ++ st->codec->codec_type = AVMEDIA_TYPE_VIDEO; ++ st->codec->codec_id = CODEC_ID_RAWVIDEO; ++ st->sample_aspect_ratio = (AVRational){ aspectn, aspectd }; + st->codec->chroma_sample_location = chroma_sample_location; + + return 0; +@@ -351,17 +373,19 @@ + AVStream *st = s->streams[0]; + struct frame_attributes *s1 = s->priv_data; + +- for (i=0; ipb); ++ for (i = 0; i < MAX_FRAME_HEADER; i++) { ++ header[i] = avio_r8(s->pb); + if (header[i] == '\n') { +- header[i+1] = 0; ++ header[i + 1] = 0; + break; + } + } +- if (i == MAX_FRAME_HEADER) return -1; +- if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) return -1; ++ if (i == MAX_FRAME_HEADER) ++ return -1; ++ if (strncmp(header, Y4M_FRAME_MAGIC, strlen(Y4M_FRAME_MAGIC))) ++ return -1; + +- width = st->codec->width; ++ width = st->codec->width; + height = st->codec->height; + + packet_size = avpicture_get_size(st->codec->pix_fmt, width, height); +@@ -371,9 +395,9 @@ + if (av_get_packet(s->pb, pkt, packet_size) != packet_size) + return AVERROR(EIO); + +- if (s->streams[0]->codec->coded_frame) { +- s->streams[0]->codec->coded_frame->interlaced_frame = s1->interlaced_frame; +- s->streams[0]->codec->coded_frame->top_field_first = s1->top_field_first; ++ if (st->codec->coded_frame) { ++ st->codec->coded_frame->interlaced_frame = s1->interlaced_frame; ++ st->codec->coded_frame->top_field_first = s1->top_field_first; + } + + pkt->stream_index = 0; +@@ -383,7 +407,7 @@ + static int yuv4_probe(AVProbeData *pd) + { + /* check file header */ +- if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC)-1)==0) ++ if (strncmp(pd->buf, Y4M_MAGIC, sizeof(Y4M_MAGIC) - 1) == 0) + return AVPROBE_SCORE_MAX; + else + return 0; +@@ -391,12 +415,12 @@ + + #if CONFIG_YUV4MPEGPIPE_DEMUXER + AVInputFormat ff_yuv4mpegpipe_demuxer = { +- "yuv4mpegpipe", +- NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"), +- sizeof(struct frame_attributes), +- yuv4_probe, +- yuv4_read_header, +- yuv4_read_packet, +- .extensions = "y4m" ++ .name = "yuv4mpegpipe", ++ .long_name = NULL_IF_CONFIG_SMALL("YUV4MPEG pipe format"), ++ .priv_data_size = sizeof(struct frame_attributes), ++ .read_probe = yuv4_probe, ++ .read_header = yuv4_read_header, ++ .read_packet = yuv4_read_packet, ++ .extensions = "y4m" + }; + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/adler32.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/adler32.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/adler32.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/adler32.c 2012-05-14 14:08:55.277358960 +0200 +@@ -26,24 +26,28 @@ + + #define BASE 65521L /* largest prime smaller than 65536 */ + +-#define DO1(buf) {s1 += *buf++; s2 += s1;} ++#define DO1(buf) { s1 += *buf++; s2 += s1; } + #define DO4(buf) DO1(buf); DO1(buf); DO1(buf); DO1(buf); + #define DO16(buf) DO4(buf); DO4(buf); DO4(buf); DO4(buf); + +-unsigned long av_adler32_update(unsigned long adler, const uint8_t *buf, unsigned int len) ++unsigned long av_adler32_update(unsigned long adler, const uint8_t * buf, ++ unsigned int len) + { + unsigned long s1 = adler & 0xffff; + unsigned long s2 = adler >> 16; + +- while (len>0) { ++ while (len > 0) { + #if CONFIG_SMALL +- while(len>4 && s2 < (1U<<31)){ +- DO4(buf); len-=4; ++ while (len > 4 && s2 < (1U << 31)) { ++ DO4(buf); ++ len -= 4; ++ } + #else +- while(len>16 && s2 < (1U<<31)){ +- DO16(buf); len-=16; +-#endif ++ while (len > 16 && s2 < (1U << 31)) { ++ DO16(buf); ++ len -= 16; + } ++#endif + DO1(buf); len--; + s1 %= BASE; + s2 %= BASE; +@@ -52,22 +56,36 @@ + } + + #ifdef TEST ++// LCOV_EXCL_START ++#include + #include "log.h" + #include "timer.h" + #define LEN 7001 +-volatile int checksum; +-int main(void){ ++ ++static volatile int checksum; ++ ++int main(int argc, char **argv) ++{ + int i; + char data[LEN]; ++ + av_log_set_level(AV_LOG_DEBUG); +- for(i=0; i>3) + 123*i; +- for(i=0; i<1000; i++){ +- START_TIMER +- checksum= av_adler32_update(1, data, LEN); +- STOP_TIMER("adler") ++ ++ for (i = 0; i < LEN; i++) ++ data[i] = ((i * i) >> 3) + 123 * i; ++ ++ if (argc > 1 && !strcmp(argv[1], "-t")) { ++ for (i = 0; i < 1000; i++) { ++ START_TIMER; ++ checksum = av_adler32_update(1, data, LEN); ++ STOP_TIMER("adler"); ++ } ++ } else { ++ checksum = av_adler32_update(1, data, LEN); + } +- av_log(NULL, AV_LOG_DEBUG, "%X == 50E6E508\n", checksum); +- return 0; ++ ++ av_log(NULL, AV_LOG_DEBUG, "%X (expected 50E6E508)\n", checksum); ++ return checksum == 0x50e6e508 ? 0 : 1; + } ++// LCOV_EXCL_STOP + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/adler32.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/adler32.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/adler32.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/adler32.h 2012-05-14 14:08:55.278358980 +0200 +@@ -25,6 +25,7 @@ + #include "attributes.h" + + /** ++ * @ingroup lavu_crypto + * Calculate the Adler32 checksum of a buffer. + * + * Passing the return value to a subsequent av_adler32_update() call +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/aes.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/aes.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/aes.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/aes.c 2012-05-14 14:08:55.279359001 +0200 +@@ -22,6 +22,7 @@ + + #include "common.h" + #include "aes.h" ++#include "intreadwrite.h" + + typedef union { + uint64_t u64[2]; +@@ -30,13 +31,13 @@ + uint8_t u8[16]; + } av_aes_block; + +-typedef struct AVAES{ ++typedef struct AVAES { + // Note: round_key[16] is accessed in the init code, but this only +- // overwrites state, which does not matter (see also r7471). ++ // overwrites state, which does not matter (see also commit ba554c0). + av_aes_block round_key[15]; + av_aes_block state[2]; + int rounds; +-}AVAES; ++} AVAES; + + const int av_aes_size= sizeof(AVAES); + +@@ -54,23 +55,58 @@ + static uint32_t dec_multbl[4][256]; + #endif + +-static inline void addkey(av_aes_block *dst, const av_aes_block *src, const av_aes_block *round_key){ ++#if HAVE_BIGENDIAN ++# define ROT(x, s) ((x >> s) | (x << (32-s))) ++#else ++# define ROT(x, s) ((x << s) | (x >> (32-s))) ++#endif ++ ++static inline void addkey(av_aes_block *dst, const av_aes_block *src, ++ const av_aes_block *round_key) ++{ + dst->u64[0] = src->u64[0] ^ round_key->u64[0]; + dst->u64[1] = src->u64[1] ^ round_key->u64[1]; + } + +-static void subshift(av_aes_block s0[2], int s, const uint8_t *box){ +- av_aes_block *s1= (av_aes_block *)(s0[0].u8 - s); +- av_aes_block *s3= (av_aes_block *)(s0[0].u8 + s); +- s0[0].u8[0]=box[s0[1].u8[ 0]]; s0[0].u8[ 4]=box[s0[1].u8[ 4]]; s0[0].u8[ 8]=box[s0[1].u8[ 8]]; s0[0].u8[12]=box[s0[1].u8[12]]; +- s1[0].u8[3]=box[s1[1].u8[ 7]]; s1[0].u8[ 7]=box[s1[1].u8[11]]; s1[0].u8[11]=box[s1[1].u8[15]]; s1[0].u8[15]=box[s1[1].u8[ 3]]; +- s0[0].u8[2]=box[s0[1].u8[10]]; s0[0].u8[10]=box[s0[1].u8[ 2]]; s0[0].u8[ 6]=box[s0[1].u8[14]]; s0[0].u8[14]=box[s0[1].u8[ 6]]; +- s3[0].u8[1]=box[s3[1].u8[13]]; s3[0].u8[13]=box[s3[1].u8[ 9]]; s3[0].u8[ 9]=box[s3[1].u8[ 5]]; s3[0].u8[ 5]=box[s3[1].u8[ 1]]; ++static inline void addkey_s(av_aes_block *dst, const uint8_t *src, ++ const av_aes_block *round_key) ++{ ++ dst->u64[0] = AV_RN64(src) ^ round_key->u64[0]; ++ dst->u64[1] = AV_RN64(src + 8) ^ round_key->u64[1]; ++} ++ ++static inline void addkey_d(uint8_t *dst, const av_aes_block *src, ++ const av_aes_block *round_key) ++{ ++ AV_WN64(dst, src->u64[0] ^ round_key->u64[0]); ++ AV_WN64(dst + 8, src->u64[1] ^ round_key->u64[1]); ++} ++ ++static void subshift(av_aes_block s0[2], int s, const uint8_t *box) ++{ ++ av_aes_block *s1 = (av_aes_block *) (s0[0].u8 - s); ++ av_aes_block *s3 = (av_aes_block *) (s0[0].u8 + s); ++ ++ s0[0].u8[ 0] = box[s0[1].u8[ 0]]; ++ s0[0].u8[ 4] = box[s0[1].u8[ 4]]; ++ s0[0].u8[ 8] = box[s0[1].u8[ 8]]; ++ s0[0].u8[12] = box[s0[1].u8[12]]; ++ s1[0].u8[ 3] = box[s1[1].u8[ 7]]; ++ s1[0].u8[ 7] = box[s1[1].u8[11]]; ++ s1[0].u8[11] = box[s1[1].u8[15]]; ++ s1[0].u8[15] = box[s1[1].u8[ 3]]; ++ s0[0].u8[ 2] = box[s0[1].u8[10]]; ++ s0[0].u8[10] = box[s0[1].u8[ 2]]; ++ s0[0].u8[ 6] = box[s0[1].u8[14]]; ++ s0[0].u8[14] = box[s0[1].u8[ 6]]; ++ s3[0].u8[ 1] = box[s3[1].u8[13]]; ++ s3[0].u8[13] = box[s3[1].u8[ 9]]; ++ s3[0].u8[ 9] = box[s3[1].u8[ 5]]; ++ s3[0].u8[ 5] = box[s3[1].u8[ 1]]; + } + + static inline int mix_core(uint32_t multbl[][256], int a, int b, int c, int d){ + #if CONFIG_SMALL +-#define ROT(x,s) ((x<>(32-s))) + return multbl[0][a] ^ ROT(multbl[0][b], 8) ^ ROT(multbl[0][c], 16) ^ ROT(multbl[0][d], 24); + #else + return multbl[0][a] ^ multbl[1][b] ^ multbl[2][c] ^ multbl[3][d]; +@@ -85,117 +121,137 @@ + state[0].u32[3] = mix_core(multbl, src[3][0], src[s1-1][1], src[1][2], src[s3-1][3]); + } + +-static inline void crypt(AVAES *a, int s, const uint8_t *sbox, uint32_t multbl[][256]){ ++static inline void crypt(AVAES *a, int s, const uint8_t *sbox, ++ uint32_t multbl[][256]) ++{ + int r; + +- for(r=a->rounds-1; r>0; r--){ +- mix(a->state, multbl, 3-s, 1+s); ++ for (r = a->rounds - 1; r > 0; r--) { ++ mix(a->state, multbl, 3 - s, 1 + s); + addkey(&a->state[1], &a->state[0], &a->round_key[r]); + } ++ + subshift(&a->state[0], s, sbox); + } + +-void av_aes_crypt(AVAES *a, uint8_t *dst_, const uint8_t *src_, int count, uint8_t *iv_, int decrypt){ +- av_aes_block *dst = (av_aes_block *)dst_; +- const av_aes_block *src = (const av_aes_block *)src_; +- av_aes_block *iv = (av_aes_block *)iv_; +- while(count--){ +- addkey(&a->state[1], src, &a->round_key[a->rounds]); +- if(decrypt) { ++void av_aes_crypt(AVAES *a, uint8_t *dst, const uint8_t *src, ++ int count, uint8_t *iv, int decrypt) ++{ ++ while (count--) { ++ addkey_s(&a->state[1], src, &a->round_key[a->rounds]); ++ if (decrypt) { + crypt(a, 0, inv_sbox, dec_multbl); +- if(iv){ +- addkey(&a->state[0], &a->state[0], iv); ++ if (iv) { ++ addkey_s(&a->state[0], iv, &a->state[0]); + memcpy(iv, src, 16); + } +- addkey(dst, &a->state[0], &a->round_key[0]); +- }else{ +- if(iv) addkey(&a->state[1], &a->state[1], iv); +- crypt(a, 2, sbox, enc_multbl); +- addkey(dst, &a->state[0], &a->round_key[0]); +- if(iv) memcpy(iv, dst, 16); ++ addkey_d(dst, &a->state[0], &a->round_key[0]); ++ } else { ++ if (iv) ++ addkey_s(&a->state[1], iv, &a->state[1]); ++ crypt(a, 2, sbox, enc_multbl); ++ addkey_d(dst, &a->state[0], &a->round_key[0]); ++ if (iv) ++ memcpy(iv, dst, 16); + } +- src++; +- dst++; ++ src += 16; ++ dst += 16; + } + } + +-static void init_multbl2(uint8_t tbl[1024], const int c[4], const uint8_t *log8, const uint8_t *alog8, const uint8_t *sbox){ +- int i, j; +- for(i=0; i<1024; i++){ +- int x= sbox[i>>2]; +- if(x) tbl[i]= alog8[ log8[x] + log8[c[i&3]] ]; +- } ++static void init_multbl2(uint32_t tbl[][256], const int c[4], ++ const uint8_t *log8, const uint8_t *alog8, ++ const uint8_t *sbox) ++{ ++ int i; ++ ++ for (i = 0; i < 256; i++) { ++ int x = sbox[i]; ++ if (x) { ++ int k, l, m, n; ++ x = log8[x]; ++ k = alog8[x + log8[c[0]]]; ++ l = alog8[x + log8[c[1]]]; ++ m = alog8[x + log8[c[2]]]; ++ n = alog8[x + log8[c[3]]]; ++ tbl[0][i] = AV_NE(MKBETAG(k,l,m,n), MKTAG(k,l,m,n)); + #if !CONFIG_SMALL +- for(j=256; j<1024; j++) +- for(i=0; i<4; i++) +- tbl[4*j+i]= tbl[4*j + ((i-1)&3) - 1024]; ++ tbl[1][i] = ROT(tbl[0][i], 8); ++ tbl[2][i] = ROT(tbl[0][i], 16); ++ tbl[3][i] = ROT(tbl[0][i], 24); + #endif ++ } ++ } + } + + // this is based on the reference AES code by Paulo Barreto and Vincent Rijmen +-int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) { ++int av_aes_init(AVAES *a, const uint8_t *key, int key_bits, int decrypt) ++{ + int i, j, t, rconpointer = 0; + uint8_t tk[8][4]; +- int KC= key_bits>>5; +- int rounds= KC + 6; +- uint8_t log8[256]; ++ int KC = key_bits >> 5; ++ int rounds = KC + 6; ++ uint8_t log8[256]; + uint8_t alog8[512]; + +- if(!enc_multbl[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[0])-1]){ +- j=1; +- for(i=0; i<255; i++){ +- alog8[i]= +- alog8[i+255]= j; +- log8[j]= i; +- j^= j+j; +- if(j>255) j^= 0x11B; +- } +- for(i=0; i<256; i++){ +- j= i ? alog8[255-log8[i]] : 0; +- j ^= (j<<1) ^ (j<<2) ^ (j<<3) ^ (j<<4); +- j = (j ^ (j>>8) ^ 99) & 255; +- inv_sbox[j]= i; +- sbox [i]= j; ++ if (!enc_multbl[FF_ARRAY_ELEMS(enc_multbl)-1][FF_ARRAY_ELEMS(enc_multbl[0])-1]) { ++ j = 1; ++ for (i = 0; i < 255; i++) { ++ alog8[i] = alog8[i + 255] = j; ++ log8[j] = i; ++ j ^= j + j; ++ if (j > 255) ++ j ^= 0x11B; + } +- init_multbl2(dec_multbl[0], (const int[4]){0xe, 0x9, 0xd, 0xb}, log8, alog8, inv_sbox); +- init_multbl2(enc_multbl[0], (const int[4]){0x2, 0x1, 0x1, 0x3}, log8, alog8, sbox); ++ for (i = 0; i < 256; i++) { ++ j = i ? alog8[255 - log8[i]] : 0; ++ j ^= (j << 1) ^ (j << 2) ^ (j << 3) ^ (j << 4); ++ j = (j ^ (j >> 8) ^ 99) & 255; ++ inv_sbox[j] = i; ++ sbox[i] = j; ++ } ++ init_multbl2(dec_multbl, (const int[4]) { 0xe, 0x9, 0xd, 0xb }, ++ log8, alog8, inv_sbox); ++ init_multbl2(enc_multbl, (const int[4]) { 0x2, 0x1, 0x1, 0x3 }, ++ log8, alog8, sbox); + } + +- if(key_bits!=128 && key_bits!=192 && key_bits!=256) ++ if (key_bits != 128 && key_bits != 192 && key_bits != 256) + return -1; + +- a->rounds= rounds; +- +- memcpy(tk, key, KC*4); ++ a->rounds = rounds; + +- for(t= 0; t < (rounds+1)*16;) { +- memcpy(a->round_key[0].u8+t, tk, KC*4); +- t+= KC*4; ++ memcpy(tk, key, KC * 4); ++ memcpy(a->round_key[0].u8, key, KC * 4); + +- for(i = 0; i < 4; i++) +- tk[0][i] ^= sbox[tk[KC-1][(i+1)&3]]; ++ for (t = KC * 4; t < (rounds + 1) * 16; t += KC * 4) { ++ for (i = 0; i < 4; i++) ++ tk[0][i] ^= sbox[tk[KC - 1][(i + 1) & 3]]; + tk[0][0] ^= rcon[rconpointer++]; + +- for(j = 1; j < KC; j++){ +- if(KC != 8 || j != KC>>1) +- for(i = 0; i < 4; i++) tk[j][i] ^= tk[j-1][i]; ++ for (j = 1; j < KC; j++) { ++ if (KC != 8 || j != KC >> 1) ++ for (i = 0; i < 4; i++) ++ tk[j][i] ^= tk[j - 1][i]; + else +- for(i = 0; i < 4; i++) tk[j][i] ^= sbox[tk[j-1][i]]; ++ for (i = 0; i < 4; i++) ++ tk[j][i] ^= sbox[tk[j - 1][i]]; + } ++ ++ memcpy(a->round_key[0].u8 + t, tk, KC * 4); + } + +- if(decrypt){ +- for(i=1; iround_key[i], 16); ++ tmp[2] = a->round_key[i]; + subshift(&tmp[1], 0, sbox); + mix(tmp, dec_multbl, 1, 3); +- memcpy(&a->round_key[i], &tmp[0], 16); ++ a->round_key[i] = tmp[0]; + } +- }else{ +- for(i=0; i<(rounds+1)>>1; i++){ +- for(j=0; j<16; j++) +- FFSWAP(int, a->round_key[i].u8[j], a->round_key[rounds-i].u8[j]); ++ } else { ++ for (i = 0; i < (rounds + 1) >> 1; i++) { ++ FFSWAP(av_aes_block, a->round_key[i], a->round_key[rounds-i]); + } + } + +@@ -203,53 +259,78 @@ + } + + #ifdef TEST ++// LCOV_EXCL_START ++#include + #include "lfg.h" + #include "log.h" + +-int main(void){ +- int i,j; +- AVAES ae, ad, b; +- uint8_t rkey[2][16]= { +- {0}, +- {0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59}}; ++int main(int argc, char **argv) ++{ ++ int i, j; ++ AVAES b; ++ uint8_t rkey[2][16] = { ++ { 0 }, ++ { 0x10, 0xa5, 0x88, 0x69, 0xd7, 0x4b, 0xe5, 0xa3, ++ 0x74, 0xcf, 0x86, 0x7c, 0xfb, 0x47, 0x38, 0x59 } ++ }; + uint8_t pt[16], rpt[2][16]= { +- {0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3}, +- {0}}; ++ { 0x6a, 0x84, 0x86, 0x7c, 0xd7, 0x7e, 0x12, 0xad, ++ 0x07, 0xea, 0x1b, 0xe8, 0x95, 0xc5, 0x3f, 0xa3 }, ++ { 0 } ++ }; + uint8_t rct[2][16]= { +- {0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf}, +- {0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65}}; ++ { 0x73, 0x22, 0x81, 0xc0, 0xa0, 0xaa, 0xb8, 0xf7, ++ 0xa5, 0x4a, 0x0c, 0x67, 0xa0, 0xc4, 0x5e, 0xcf }, ++ { 0x6d, 0x25, 0x1e, 0x69, 0x44, 0xb0, 0x51, 0xe0, ++ 0x4e, 0xaa, 0x6f, 0xb4, 0xdb, 0xf7, 0x84, 0x65 } ++ }; + uint8_t temp[16]; +- AVLFG prng; ++ int err = 0; + +- av_aes_init(&ae, "PI=3.141592654..", 128, 0); +- av_aes_init(&ad, "PI=3.141592654..", 128, 1); + av_log_set_level(AV_LOG_DEBUG); +- av_lfg_init(&prng, 1); + +- for(i=0; i<2; i++){ ++ for (i = 0; i < 2; i++) { + av_aes_init(&b, rkey[i], 128, 1); + av_aes_crypt(&b, temp, rct[i], 1, NULL, 1); +- for(j=0; j<16; j++) +- if(rpt[i][j] != temp[j]) +- av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", j, rpt[i][j], temp[j]); +- } +- +- for(i=0; i<10000; i++){ +- for(j=0; j<16; j++){ +- pt[j] = av_lfg_get(&prng); +- } +-{START_TIMER +- av_aes_crypt(&ae, temp, pt, 1, NULL, 0); +- if(!(i&(i-1))) +- av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", temp[0], temp[5], temp[10], temp[15]); +- av_aes_crypt(&ad, temp, temp, 1, NULL, 1); +-STOP_TIMER("aes")} +- for(j=0; j<16; j++){ +- if(pt[j] != temp[j]){ +- av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", i,j, pt[j], temp[j]); ++ for (j = 0; j < 16; j++) { ++ if (rpt[i][j] != temp[j]) { ++ av_log(NULL, AV_LOG_ERROR, "%d %02X %02X\n", ++ j, rpt[i][j], temp[j]); ++ err = 1; + } + } + } +- return 0; ++ ++ if (argc > 1 && !strcmp(argv[1], "-t")) { ++ AVAES ae, ad; ++ AVLFG prng; ++ ++ av_aes_init(&ae, "PI=3.141592654..", 128, 0); ++ av_aes_init(&ad, "PI=3.141592654..", 128, 1); ++ av_lfg_init(&prng, 1); ++ ++ for (i = 0; i < 10000; i++) { ++ for (j = 0; j < 16; j++) { ++ pt[j] = av_lfg_get(&prng); ++ } ++ { ++ START_TIMER; ++ av_aes_crypt(&ae, temp, pt, 1, NULL, 0); ++ if (!(i & (i - 1))) ++ av_log(NULL, AV_LOG_ERROR, "%02X %02X %02X %02X\n", ++ temp[0], temp[5], temp[10], temp[15]); ++ av_aes_crypt(&ad, temp, temp, 1, NULL, 1); ++ STOP_TIMER("aes"); ++ } ++ for (j = 0; j < 16; j++) { ++ if (pt[j] != temp[j]) { ++ av_log(NULL, AV_LOG_ERROR, "%d %d %02X %02X\n", ++ i, j, pt[j], temp[j]); ++ } ++ } ++ } ++ } ++ return err; + } ++// LCOV_EXCL_STOP + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/aes.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/aes.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/aes.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/aes.h 2012-05-14 14:08:55.280359022 +0200 +@@ -23,6 +23,12 @@ + + #include + ++/** ++ * @defgroup lavu_aes AES ++ * @ingroup lavu_crypto ++ * @{ ++ */ ++ + extern const int av_aes_size; + + struct AVAES; +@@ -44,4 +50,8 @@ + */ + void av_aes_crypt(struct AVAES *a, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_AES_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/bswap.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/bswap.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/bswap.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/bswap.h 2012-05-14 14:08:55.280359022 +0200 +@@ -51,6 +51,7 @@ + } + #endif + ++#if !AV_GCC_VERSION_AT_LEAST(4,5) + #define av_bswap32 av_bswap32 + static av_always_inline av_const uint32_t av_bswap32(uint32_t x) + { +@@ -66,6 +67,7 @@ + #endif /* HAVE_ARMV6 */ + return x; + } ++#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */ + + #endif /* __ARMCC_VERSION */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/intmath.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/intmath.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/intmath.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/intmath.h 2012-05-14 14:08:55.281359042 +0200 +@@ -31,70 +31,82 @@ + #if HAVE_ARMV6 + + #define FASTDIV FASTDIV +-static inline av_const int FASTDIV(int a, int b) ++static av_always_inline av_const int FASTDIV(int a, int b) + { +- int r, t; +- __asm__ volatile("cmp %3, #2 \n\t" +- "ldr %1, [%4, %3, lsl #2] \n\t" +- "lsrle %0, %2, #1 \n\t" +- "smmulgt %0, %1, %2 \n\t" +- : "=&r"(r), "=&r"(t) : "r"(a), "r"(b), "r"(ff_inverse)); ++ int r; ++ __asm__ ("cmp %2, #2 \n\t" ++ "ldr %0, [%3, %2, lsl #2] \n\t" ++ "ite le \n\t" ++ "lsrle %0, %1, #1 \n\t" ++ "smmulgt %0, %0, %1 \n\t" ++ : "=&r"(r) : "r"(a), "r"(b), "r"(ff_inverse) : "cc"); + return r; + } + + #define av_clip_uint8 av_clip_uint8_arm +-static inline av_const uint8_t av_clip_uint8_arm(int a) ++static av_always_inline av_const uint8_t av_clip_uint8_arm(int a) + { + unsigned x; +- __asm__ volatile ("usat %0, #8, %1" : "=r"(x) : "r"(a)); ++ __asm__ ("usat %0, #8, %1" : "=r"(x) : "r"(a)); + return x; + } + + #define av_clip_int8 av_clip_int8_arm +-static inline av_const uint8_t av_clip_int8_arm(int a) ++static av_always_inline av_const uint8_t av_clip_int8_arm(int a) + { + unsigned x; +- __asm__ volatile ("ssat %0, #8, %1" : "=r"(x) : "r"(a)); ++ __asm__ ("ssat %0, #8, %1" : "=r"(x) : "r"(a)); + return x; + } + + #define av_clip_uint16 av_clip_uint16_arm +-static inline av_const uint16_t av_clip_uint16_arm(int a) ++static av_always_inline av_const uint16_t av_clip_uint16_arm(int a) + { + unsigned x; +- __asm__ volatile ("usat %0, #16, %1" : "=r"(x) : "r"(a)); ++ __asm__ ("usat %0, #16, %1" : "=r"(x) : "r"(a)); + return x; + } + + #define av_clip_int16 av_clip_int16_arm +-static inline av_const int16_t av_clip_int16_arm(int a) ++static av_always_inline av_const int16_t av_clip_int16_arm(int a) + { + int x; +- __asm__ volatile ("ssat %0, #16, %1" : "=r"(x) : "r"(a)); ++ __asm__ ("ssat %0, #16, %1" : "=r"(x) : "r"(a)); + return x; + } + ++#define av_clip_uintp2 av_clip_uintp2_arm ++static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p) ++{ ++ unsigned x; ++ __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p)); ++ return x; ++} ++ ++ + #else /* HAVE_ARMV6 */ + + #define FASTDIV FASTDIV +-static inline av_const int FASTDIV(int a, int b) ++static av_always_inline av_const int FASTDIV(int a, int b) + { + int r, t; +- __asm__ volatile("umull %1, %0, %2, %3" +- : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b])); ++ __asm__ ("umull %1, %0, %2, %3" ++ : "=&r"(r), "=&r"(t) : "r"(a), "r"(ff_inverse[b])); + return r; + } + + #endif /* HAVE_ARMV6 */ + + #define av_clipl_int32 av_clipl_int32_arm +-static inline av_const int32_t av_clipl_int32_arm(int64_t a) ++static av_always_inline av_const int32_t av_clipl_int32_arm(int64_t a) + { + int x, y; +- __asm__ volatile ("adds %1, %R2, %Q2, lsr #31 \n\t" +- "mvnne %1, #1<<31 \n\t" +- "eorne %0, %1, %R2, asr #31 \n\t" +- : "=r"(x), "=&r"(y) : "r"(a)); ++ __asm__ ("adds %1, %R2, %Q2, lsr #31 \n\t" ++ "itet ne \n\t" ++ "mvnne %1, #1<<31 \n\t" ++ "moveq %0, %Q2 \n\t" ++ "eorne %0, %1, %R2, asr #31 \n\t" ++ : "=r"(x), "=&r"(y) : "r"(a):"cc"); + return x; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/intreadwrite.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/intreadwrite.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/arm/intreadwrite.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/arm/intreadwrite.h 2012-05-14 14:08:55.282359062 +0200 +@@ -55,22 +55,21 @@ + #define AV_RN64 AV_RN64 + static av_always_inline uint64_t AV_RN64(const void *p) + { +- union { uint64_t v; uint32_t hl[2]; } v; +- __asm__ ("ldr %0, %2 \n\t" +- "ldr %1, %3 \n\t" +- : "=&r"(v.hl[0]), "=r"(v.hl[1]) ++ uint64_t v; ++ __asm__ ("ldr %Q0, %1 \n\t" ++ "ldr %R0, %2 \n\t" ++ : "=&r"(v) + : "m"(*(const uint32_t*)p), "m"(*((const uint32_t*)p+1))); +- return v.v; ++ return v; + } + + #define AV_WN64 AV_WN64 + static av_always_inline void AV_WN64(void *p, uint64_t v) + { +- union { uint64_t v; uint32_t hl[2]; } vv = { v }; +- __asm__ ("str %2, %0 \n\t" +- "str %3, %1 \n\t" ++ __asm__ ("str %Q2, %0 \n\t" ++ "str %R2, %1 \n\t" + : "=m"(*(uint32_t*)p), "=m"(*((uint32_t*)p+1)) +- : "r"(vv.hl[0]), "r"(vv.hl[1])); ++ : "r"(v)); + } + + #endif /* HAVE_INLINE_ASM */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/attributes.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/attributes.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/attributes.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/attributes.h 2012-05-14 14:08:55.282359062 +0200 +@@ -40,6 +40,14 @@ + #endif + #endif + ++#ifndef av_noreturn ++#if AV_GCC_VERSION_AT_LEAST(2,5) ++# define av_noreturn __attribute__((noreturn)) ++#else ++# define av_noreturn ++#endif ++#endif ++ + #ifndef av_noinline + #if AV_GCC_VERSION_AT_LEAST(3,1) + # define av_noinline __attribute__((noinline)) +@@ -65,7 +73,7 @@ + #endif + + #ifndef av_cold +-#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,3) ++#if AV_GCC_VERSION_AT_LEAST(4,3) + # define av_cold __attribute__((cold)) + #else + # define av_cold +@@ -73,7 +81,7 @@ + #endif + + #ifndef av_flatten +-#if (!defined(__ICC) || __ICC > 1110) && AV_GCC_VERSION_AT_LEAST(4,1) ++#if AV_GCC_VERSION_AT_LEAST(4,1) + # define av_flatten __attribute__((flatten)) + #else + # define av_flatten +@@ -88,6 +96,24 @@ + #endif + #endif + ++/** ++ * Disable warnings about deprecated features ++ * This is useful for sections of code kept for backward compatibility and ++ * scheduled for removal. ++ */ ++#ifndef AV_NOWARN_DEPRECATED ++#if AV_GCC_VERSION_AT_LEAST(4,6) ++# define AV_NOWARN_DEPRECATED(code) \ ++ _Pragma("GCC diagnostic push") \ ++ _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") \ ++ code \ ++ _Pragma("GCC diagnostic pop") ++#else ++# define AV_NOWARN_DEPRECATED(code) code ++#endif ++#endif ++ ++ + #ifndef av_unused + #if defined(__GNUC__) + # define av_unused __attribute__((unused)) +@@ -110,7 +136,7 @@ + #endif + + #ifndef av_alias +-#if (!defined(__ICC) || __ICC > 1200) && AV_GCC_VERSION_AT_LEAST(3,3) ++#if AV_GCC_VERSION_AT_LEAST(3,3) + # define av_alias __attribute__((may_alias)) + #else + # define av_alias +@@ -118,7 +144,7 @@ + #endif + + #ifndef av_uninit +-#if defined(__GNUC__) && !defined(__ICC) ++#if defined(__GNUC__) && !defined(__INTEL_COMPILER) + # define av_uninit(x) x=x + #else + # define av_uninit(x) x +@@ -127,8 +153,10 @@ + + #ifdef __GNUC__ + # define av_builtin_constant_p __builtin_constant_p ++# define av_printf_format(fmtpos, attrpos) __attribute__((__format__(__printf__, fmtpos, attrpos))) + #else + # define av_builtin_constant_p(x) 0 ++# define av_printf_format(fmtpos, attrpos) + #endif + + #endif /* AVUTIL_ATTRIBUTES_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/audioconvert.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/audioconvert.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/audioconvert.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/audioconvert.c 2012-05-14 14:08:55.283359082 +0200 +@@ -0,0 +1,171 @@ ++/* ++ * Copyright (c) 2006 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio conversion routines ++ */ ++ ++#include "avstring.h" ++#include "avutil.h" ++#include "audioconvert.h" ++ ++static const char * const channel_names[] = { ++ [0] = "FL", /* front left */ ++ [1] = "FR", /* front right */ ++ [2] = "FC", /* front center */ ++ [3] = "LFE", /* low frequency */ ++ [4] = "BL", /* back left */ ++ [5] = "BR", /* back right */ ++ [6] = "FLC", /* front left-of-center */ ++ [7] = "FRC", /* front right-of-center */ ++ [8] = "BC", /* back-center */ ++ [9] = "SL", /* side left */ ++ [10] = "SR", /* side right */ ++ [11] = "TC", /* top center */ ++ [12] = "TFL", /* top front left */ ++ [13] = "TFC", /* top front center */ ++ [14] = "TFR", /* top front right */ ++ [15] = "TBL", /* top back left */ ++ [16] = "TBC", /* top back center */ ++ [17] = "TBR", /* top back right */ ++ [29] = "DL", /* downmix left */ ++ [30] = "DR", /* downmix right */ ++}; ++ ++static const char *get_channel_name(int channel_id) ++{ ++ if (channel_id < 0 || channel_id >= FF_ARRAY_ELEMS(channel_names)) ++ return NULL; ++ return channel_names[channel_id]; ++} ++ ++static const struct { ++ const char *name; ++ int nb_channels; ++ uint64_t layout; ++} channel_layout_map[] = { ++ { "mono", 1, AV_CH_LAYOUT_MONO }, ++ { "stereo", 2, AV_CH_LAYOUT_STEREO }, ++ { "2.1", 3, AV_CH_LAYOUT_2POINT1 }, ++ { "4.0", 4, AV_CH_LAYOUT_4POINT0 }, ++ { "quad", 4, AV_CH_LAYOUT_QUAD }, ++ { "5.0", 5, AV_CH_LAYOUT_5POINT0_BACK }, ++ { "5.0(side)", 5, AV_CH_LAYOUT_5POINT0 }, ++ { "5.1", 6, AV_CH_LAYOUT_5POINT1_BACK }, ++ { "5.1(side)", 6, AV_CH_LAYOUT_5POINT1 }, ++ { "7.1", 8, AV_CH_LAYOUT_7POINT1 }, ++ { "7.1(wide)", 8, AV_CH_LAYOUT_7POINT1_WIDE }, ++ { "downmix", 2, AV_CH_LAYOUT_STEREO_DOWNMIX, }, ++ { 0 } ++}; ++ ++static uint64_t get_channel_layout_single(const char *name, int name_len) ++{ ++ int i; ++ char *end; ++ int64_t layout; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(channel_layout_map) - 1; i++) { ++ if (strlen(channel_layout_map[i].name) == name_len && ++ !memcmp(channel_layout_map[i].name, name, name_len)) ++ return channel_layout_map[i].layout; ++ } ++ for (i = 0; i < FF_ARRAY_ELEMS(channel_names); i++) ++ if (channel_names[i] && ++ strlen(channel_names[i]) == name_len && ++ !memcmp(channel_names[i], name, name_len)) ++ return (int64_t)1 << i; ++ i = strtol(name, &end, 10); ++ if (end - name == name_len || ++ (end + 1 - name == name_len && *end == 'c')) ++ return av_get_default_channel_layout(i); ++ layout = strtoll(name, &end, 0); ++ if (end - name == name_len) ++ return FFMAX(layout, 0); ++ return 0; ++} ++ ++uint64_t av_get_channel_layout(const char *name) ++{ ++ const char *n, *e; ++ const char *name_end = name + strlen(name); ++ int64_t layout = 0, layout_single; ++ ++ for (n = name; n < name_end; n = e + 1) { ++ for (e = n; e < name_end && *e != '+' && *e != '|'; e++); ++ layout_single = get_channel_layout_single(n, e - n); ++ if (!layout_single) ++ return 0; ++ layout |= layout_single; ++ } ++ return layout; ++} ++ ++void av_get_channel_layout_string(char *buf, int buf_size, ++ int nb_channels, uint64_t channel_layout) ++{ ++ int i; ++ ++ if (nb_channels <= 0) ++ nb_channels = av_get_channel_layout_nb_channels(channel_layout); ++ ++ for (i = 0; channel_layout_map[i].name; i++) ++ if (nb_channels == channel_layout_map[i].nb_channels && ++ channel_layout == channel_layout_map[i].layout) { ++ av_strlcpy(buf, channel_layout_map[i].name, buf_size); ++ return; ++ } ++ ++ snprintf(buf, buf_size, "%d channels", nb_channels); ++ if (channel_layout) { ++ int i, ch; ++ av_strlcat(buf, " (", buf_size); ++ for (i = 0, ch = 0; i < 64; i++) { ++ if ((channel_layout & (UINT64_C(1) << i))) { ++ const char *name = get_channel_name(i); ++ if (name) { ++ if (ch > 0) ++ av_strlcat(buf, "+", buf_size); ++ av_strlcat(buf, name, buf_size); ++ } ++ ch++; ++ } ++ } ++ av_strlcat(buf, ")", buf_size); ++ } ++} ++ ++int av_get_channel_layout_nb_channels(uint64_t channel_layout) ++{ ++ int count; ++ uint64_t x = channel_layout; ++ for (count = 0; x; count++) ++ x &= x-1; // unset lowest set bit ++ return count; ++} ++ ++int64_t av_get_default_channel_layout(int nb_channels) { ++ int i; ++ for (i = 0; channel_layout_map[i].name; i++) ++ if (nb_channels == channel_layout_map[i].nb_channels) ++ return channel_layout_map[i].layout; ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/audioconvert.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/audioconvert.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/audioconvert.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/audioconvert.h 2012-05-14 14:08:55.284359102 +0200 +@@ -0,0 +1,147 @@ ++/* ++ * Copyright (c) 2006 Michael Niedermayer ++ * Copyright (c) 2008 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVUTIL_AUDIOCONVERT_H ++#define AVUTIL_AUDIOCONVERT_H ++ ++#include ++ ++/** ++ * @file ++ * audio conversion routines ++ */ ++ ++/** ++ * @addtogroup lavu_audio ++ * @{ ++ */ ++ ++/** ++ * @defgroup channel_masks Audio channel masks ++ * @{ ++ */ ++#define AV_CH_FRONT_LEFT 0x00000001 ++#define AV_CH_FRONT_RIGHT 0x00000002 ++#define AV_CH_FRONT_CENTER 0x00000004 ++#define AV_CH_LOW_FREQUENCY 0x00000008 ++#define AV_CH_BACK_LEFT 0x00000010 ++#define AV_CH_BACK_RIGHT 0x00000020 ++#define AV_CH_FRONT_LEFT_OF_CENTER 0x00000040 ++#define AV_CH_FRONT_RIGHT_OF_CENTER 0x00000080 ++#define AV_CH_BACK_CENTER 0x00000100 ++#define AV_CH_SIDE_LEFT 0x00000200 ++#define AV_CH_SIDE_RIGHT 0x00000400 ++#define AV_CH_TOP_CENTER 0x00000800 ++#define AV_CH_TOP_FRONT_LEFT 0x00001000 ++#define AV_CH_TOP_FRONT_CENTER 0x00002000 ++#define AV_CH_TOP_FRONT_RIGHT 0x00004000 ++#define AV_CH_TOP_BACK_LEFT 0x00008000 ++#define AV_CH_TOP_BACK_CENTER 0x00010000 ++#define AV_CH_TOP_BACK_RIGHT 0x00020000 ++#define AV_CH_STEREO_LEFT 0x20000000 ///< Stereo downmix. ++#define AV_CH_STEREO_RIGHT 0x40000000 ///< See AV_CH_STEREO_LEFT. ++#define AV_CH_WIDE_LEFT 0x0000000080000000ULL ++#define AV_CH_WIDE_RIGHT 0x0000000100000000ULL ++#define AV_CH_SURROUND_DIRECT_LEFT 0x0000000200000000ULL ++#define AV_CH_SURROUND_DIRECT_RIGHT 0x0000000400000000ULL ++ ++/** Channel mask value used for AVCodecContext.request_channel_layout ++ to indicate that the user requests the channel order of the decoder output ++ to be the native codec channel order. */ ++#define AV_CH_LAYOUT_NATIVE 0x8000000000000000ULL ++ ++/** ++ * @} ++ * @defgroup channel_mask_c Audio channel convenience macros ++ * @{ ++ * */ ++#define AV_CH_LAYOUT_MONO (AV_CH_FRONT_CENTER) ++#define AV_CH_LAYOUT_STEREO (AV_CH_FRONT_LEFT|AV_CH_FRONT_RIGHT) ++#define AV_CH_LAYOUT_2POINT1 (AV_CH_LAYOUT_STEREO|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_2_1 (AV_CH_LAYOUT_STEREO|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_SURROUND (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) ++#define AV_CH_LAYOUT_3POINT1 (AV_CH_LAYOUT_SURROUND|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_4POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_4POINT1 (AV_CH_LAYOUT_4POINT0|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_2_2 (AV_CH_LAYOUT_STEREO|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT) ++#define AV_CH_LAYOUT_QUAD (AV_CH_LAYOUT_STEREO|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) ++#define AV_CH_LAYOUT_5POINT0 (AV_CH_LAYOUT_SURROUND|AV_CH_SIDE_LEFT|AV_CH_SIDE_RIGHT) ++#define AV_CH_LAYOUT_5POINT1 (AV_CH_LAYOUT_5POINT0|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_5POINT0_BACK (AV_CH_LAYOUT_SURROUND|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) ++#define AV_CH_LAYOUT_5POINT1_BACK (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_6POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_6POINT0_FRONT (AV_CH_LAYOUT_2_2|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER) ++#define AV_CH_LAYOUT_HEXAGONAL (AV_CH_LAYOUT_5POINT0_BACK|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_6POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_6POINT1_BACK (AV_CH_LAYOUT_5POINT1_BACK|AV_CH_BACK_CENTER) ++#define AV_CH_LAYOUT_6POINT1_FRONT (AV_CH_LAYOUT_6POINT0_FRONT|AV_CH_LOW_FREQUENCY) ++#define AV_CH_LAYOUT_7POINT0 (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) ++#define AV_CH_LAYOUT_7POINT0_FRONT (AV_CH_LAYOUT_5POINT0|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER) ++#define AV_CH_LAYOUT_7POINT1 (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_LEFT|AV_CH_BACK_RIGHT) ++#define AV_CH_LAYOUT_7POINT1_WIDE (AV_CH_LAYOUT_5POINT1|AV_CH_FRONT_LEFT_OF_CENTER|AV_CH_FRONT_RIGHT_OF_CENTER) ++#define AV_CH_LAYOUT_OCTAGONAL (AV_CH_LAYOUT_5POINT0|AV_CH_BACK_LEFT|AV_CH_BACK_CENTER|AV_CH_BACK_RIGHT) ++#define AV_CH_LAYOUT_STEREO_DOWNMIX (AV_CH_STEREO_LEFT|AV_CH_STEREO_RIGHT) ++ ++/** ++ * @} ++ */ ++ ++/** ++ * Return a channel layout id that matches name, 0 if no match. ++ * name can be one or several of the following notations, ++ * separated by '+' or '|': ++ * - the name of an usual channel layout (mono, stereo, 4.0, quad, 5.0, ++ * 5.0(side), 5.1, 5.1(side), 7.1, 7.1(wide), downmix); ++ * - the name of a single channel (FL, FR, FC, LFE, BL, BR, FLC, FRC, BC, ++ * SL, SR, TC, TFL, TFC, TFR, TBL, TBC, TBR, DL, DR); ++ * - a number of channels, in decimal, optionnally followed by 'c', yielding ++ * the default channel layout for that number of channels (@see ++ * av_get_default_channel_layout); ++ * - a channel layout mask, in hexadecimal starting with "0x" (see the ++ * AV_CH_* macros). ++ + Example: "stereo+FC" = "2+FC" = "2c+1c" = "0x7" ++ */ ++uint64_t av_get_channel_layout(const char *name); ++ ++/** ++ * Return a description of a channel layout. ++ * If nb_channels is <= 0, it is guessed from the channel_layout. ++ * ++ * @param buf put here the string containing the channel layout ++ * @param buf_size size in bytes of the buffer ++ */ ++void av_get_channel_layout_string(char *buf, int buf_size, int nb_channels, uint64_t channel_layout); ++ ++/** ++ * Return the number of channels in the channel layout. ++ */ ++int av_get_channel_layout_nb_channels(uint64_t channel_layout); ++ ++/** ++ * Return default channel layout for a given number of channels. ++ */ ++int64_t av_get_default_channel_layout(int nb_channels); ++ ++/** ++ * @} ++ */ ++ ++#endif /* AVUTIL_AUDIOCONVERT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avassert.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avassert.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avassert.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avassert.h 2012-05-14 14:08:55.285359122 +0200 +@@ -63,4 +63,4 @@ + #define av_assert2(cond) ((void)0) + #endif + +-#endif ++#endif /* AVUTIL_AVASSERT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avstring.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avstring.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avstring.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avstring.c 2012-05-14 14:08:55.285359122 +0200 +@@ -51,11 +51,11 @@ + char *av_stristr(const char *s1, const char *s2) + { + if (!*s2) +- return s1; ++ return (char*)(intptr_t)s1; + + do { + if (av_stristart(s1, s2, NULL)) +- return s1; ++ return (char*)(intptr_t)s1; + } while (*s1++); + + return NULL; +@@ -91,6 +91,32 @@ + return len; + } + ++char *av_asprintf(const char *fmt, ...) ++{ ++ char *p = NULL; ++ va_list va; ++ int len; ++ ++ va_start(va, fmt); ++ len = vsnprintf(NULL, 0, fmt, va); ++ va_end(va); ++ if (len < 0) ++ goto end; ++ ++ p = av_malloc(len + 1); ++ if (!p) ++ goto end; ++ ++ va_start(va, fmt); ++ len = vsnprintf(p, len + 1, fmt, va); ++ va_end(va); ++ if (len < 0) ++ av_freep(&p); ++ ++end: ++ return p; ++} ++ + char *av_d2str(double d) + { + char *str= av_malloc(16); +@@ -134,6 +160,56 @@ + return ret; + } + ++char *av_strtok(char *s, const char *delim, char **saveptr) ++{ ++ char *tok; ++ ++ if (!s && !(s = *saveptr)) ++ return NULL; ++ ++ /* skip leading delimiters */ ++ s += strspn(s, delim); ++ ++ /* s now points to the first non delimiter char, or to the end of the string */ ++ if (!*s) { ++ *saveptr = NULL; ++ return NULL; ++ } ++ tok = s++; ++ ++ /* skip non delimiters */ ++ s += strcspn(s, delim); ++ if (*s) { ++ *s = 0; ++ *saveptr = s+1; ++ } else { ++ *saveptr = NULL; ++ } ++ ++ return tok; ++} ++ ++int av_strcasecmp(const char *a, const char *b) ++{ ++ uint8_t c1, c2; ++ do { ++ c1 = av_tolower(*a++); ++ c2 = av_tolower(*b++); ++ } while (c1 && c1 == c2); ++ return c1 - c2; ++} ++ ++int av_strncasecmp(const char *a, const char *b, size_t n) ++{ ++ const char *end = a + n; ++ uint8_t c1, c2; ++ do { ++ c1 = av_tolower(*a++); ++ c2 = av_tolower(*b++); ++ } while (a < end && c1 && c1 == c2); ++ return c1 - c2; ++} ++ + #ifdef TEST + + #undef printf +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avstring.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avstring.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avstring.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avstring.h 2012-05-14 14:08:55.286359142 +0200 +@@ -22,6 +22,12 @@ + #define AVUTIL_AVSTRING_H + + #include ++#include "attributes.h" ++ ++/** ++ * @addtogroup lavu_string ++ * @{ ++ */ + + /** + * Return non-zero if pfx is a prefix of str. If it is, *ptr is set to +@@ -71,7 +77,7 @@ + * @param size size of destination buffer + * @return the length of src + * +- * WARNING: since the return value is the length of src, src absolutely ++ * @warning since the return value is the length of src, src absolutely + * _must_ be a properly 0-terminated string, otherwise this will read beyond + * the end of the buffer and possibly crash. + */ +@@ -89,9 +95,9 @@ + * @param size size of destination buffer + * @return the total length of src and dst + * +- * WARNING: since the return value use the length of src and dst, these absolutely +- * _must_ be a properly 0-terminated strings, otherwise this will read beyond +- * the end of the buffer and possibly crash. ++ * @warning since the return value use the length of src and dst, these ++ * absolutely _must_ be a properly 0-terminated strings, otherwise this ++ * will read beyond the end of the buffer and possibly crash. + */ + size_t av_strlcat(char *dst, const char *src, size_t size); + +@@ -107,7 +113,17 @@ + * @return the length of the string that would have been generated + * if enough space had been available + */ +-size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...); ++size_t av_strlcatf(char *dst, size_t size, const char *fmt, ...) av_printf_format(3, 4); ++ ++/** ++ * Print arguments following specified format into a large enough auto ++ * allocated buffer. It is similar to GNU asprintf(). ++ * @param fmt printf-compatible format string, specifying how the ++ * following parameters are used. ++ * @return the allocated string ++ * @note You have to free the string yourself with av_free(). ++ */ ++char *av_asprintf(const char *fmt, ...) av_printf_format(1, 2); + + /** + * Convert a number to a av_malloced string. +@@ -130,4 +146,64 @@ + */ + char *av_get_token(const char **buf, const char *term); + ++/** ++ * Split the string into several tokens which can be accessed by ++ * successive calls to av_strtok(). ++ * ++ * A token is defined as a sequence of characters not belonging to the ++ * set specified in delim. ++ * ++ * On the first call to av_strtok(), s should point to the string to ++ * parse, and the value of saveptr is ignored. In subsequent calls, s ++ * should be NULL, and saveptr should be unchanged since the previous ++ * call. ++ * ++ * This function is similar to strtok_r() defined in POSIX.1. ++ * ++ * @param s the string to parse, may be NULL ++ * @param delim 0-terminated list of token delimiters, must be non-NULL ++ * @param saveptr user-provided pointer which points to stored ++ * information necessary for av_strtok() to continue scanning the same ++ * string. saveptr is updated to point to the next character after the ++ * first delimiter found, or to NULL if the string was terminated ++ * @return the found token, or NULL when no token is found ++ */ ++char *av_strtok(char *s, const char *delim, char **saveptr); ++ ++/** ++ * Locale-independent conversion of ASCII characters to uppercase. ++ */ ++static inline int av_toupper(int c) ++{ ++ if (c >= 'a' && c <= 'z') ++ c ^= 0x20; ++ return c; ++} ++ ++/** ++ * Locale-independent conversion of ASCII characters to lowercase. ++ */ ++static inline int av_tolower(int c) ++{ ++ if (c >= 'A' && c <= 'Z') ++ c ^= 0x20; ++ return c; ++} ++ ++/** ++ * Locale-independent case-insensitive compare. ++ * @note This means only ASCII-range characters are case-insensitive ++ */ ++int av_strcasecmp(const char *a, const char *b); ++ ++/** ++ * Locale-independent case-insensitive compare. ++ * @note This means only ASCII-range characters are case-insensitive ++ */ ++int av_strncasecmp(const char *a, const char *b, size_t n); ++ ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_AVSTRING_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avutil.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avutil.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/avutil.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/avutil.h 2012-05-14 14:08:55.288359182 +0200 +@@ -26,6 +26,96 @@ + * external API header + */ + ++/** ++ * @mainpage ++ * ++ * @section libav_intro Introduction ++ * ++ * This document describe the usage of the different libraries ++ * provided by FFmpeg. ++ * ++ * @li @ref libavc "libavcodec" encoding/decoding library ++ * @li @subpage libavfilter graph based frame editing library ++ * @li @ref libavf "libavformat" I/O and muxing/demuxing library ++ * @li @ref lavd "libavdevice" special devices muxing/demuxing library ++ * @li @ref lavu "libavutil" common utility library ++ * @li @subpage libpostproc post processing library ++ * @li @subpage libswscale color conversion and scaling library ++ * ++ */ ++ ++/** ++ * @defgroup lavu Common utility functions ++ * ++ * @brief ++ * libavutil contains the code shared across all the other FFmpeg ++ * libraries ++ * ++ * @note In order to use the functions provided by avutil you must include ++ * the specific header. ++ * ++ * @{ ++ * ++ * @defgroup lavu_crypto Crypto and Hashing ++ * ++ * @{ ++ * @} ++ * ++ * @defgroup lavu_math Maths ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_string String Manipulation ++ * ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_mem Memory Management ++ * ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_data Data Structures ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_audio Audio related ++ * ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_error Error Codes ++ * ++ * @{ ++ * ++ * @} ++ * ++ * @defgroup lavu_misc Other ++ * ++ * @{ ++ * ++ * @defgroup lavu_internal Internal ++ * ++ * Not exported functions, for internal usage only ++ * ++ * @{ ++ * ++ * @} ++ */ ++ ++ ++/** ++ * @defgroup preproc_misc Preprocessor String Macros ++ * ++ * String manipulation macros ++ * ++ * @{ ++ */ + + #define AV_STRINGIFY(s) AV_TOSTRING(s) + #define AV_TOSTRING(s) #s +@@ -35,13 +125,37 @@ + + #define AV_PRAGMA(s) _Pragma(#s) + ++/** ++ * @} ++ */ ++ ++/** ++ * @defgroup version_utils Library Version Macros ++ * ++ * Useful to check and match library version in order to maintain ++ * backward compatibility. ++ * ++ * @{ ++ */ ++ + #define AV_VERSION_INT(a, b, c) (a<<16 | b<<8 | c) + #define AV_VERSION_DOT(a, b, c) a ##.## b ##.## c + #define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c) + +-#define LIBAVUTIL_VERSION_MAJOR 50 +-#define LIBAVUTIL_VERSION_MINOR 36 +-#define LIBAVUTIL_VERSION_MICRO 0 ++/** ++ * @} ++ * ++ * @defgroup lavu_ver Version and Build diagnostics ++ * ++ * Macros and function useful to check at compiletime and at runtime ++ * which version of libavutil is in use. ++ * ++ * @{ ++ */ ++ ++#define LIBAVUTIL_VERSION_MAJOR 51 ++#define LIBAVUTIL_VERSION_MINOR 35 ++#define LIBAVUTIL_VERSION_MICRO 100 + + #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ + LIBAVUTIL_VERSION_MINOR, \ +@@ -54,12 +168,41 @@ + #define LIBAVUTIL_IDENT "Lavu" AV_STRINGIFY(LIBAVUTIL_VERSION) + + /** ++ * @} ++ * ++ * @defgroup depr_guards Deprecation guards + * Those FF_API_* defines are not part of public API. + * They may change, break or disappear at any time. ++ * ++ * They are used mostly internally to mark code that will be removed ++ * on the next major version. ++ * ++ * @{ + */ + #ifndef FF_API_OLD_EVAL_NAMES +-#define FF_API_OLD_EVAL_NAMES (LIBAVUTIL_VERSION_MAJOR < 51) ++#define FF_API_OLD_EVAL_NAMES (LIBAVUTIL_VERSION_MAJOR < 52) + #endif ++#ifndef FF_API_GET_BITS_PER_SAMPLE_FMT ++#define FF_API_GET_BITS_PER_SAMPLE_FMT (LIBAVUTIL_VERSION_MAJOR < 52) ++#endif ++#ifndef FF_API_FIND_OPT ++#define FF_API_FIND_OPT (LIBAVUTIL_VERSION_MAJOR < 52) ++#endif ++#ifndef FF_API_AV_FIFO_PEEK ++#define FF_API_AV_FIFO_PEEK (LIBAVUTIL_VERSION_MAJOR < 52) ++#endif ++#ifndef FF_API_OLD_AVOPTIONS ++#define FF_API_OLD_AVOPTIONS (LIBAVUTIL_VERSION_MAJOR < 52) ++#endif ++ ++/** ++ * @} ++ */ ++ ++/** ++ * @addtogroup lavu_ver ++ * @{ ++ */ + + /** + * Return the LIBAVUTIL_VERSION_INT constant. +@@ -76,16 +219,41 @@ + */ + const char *avutil_license(void); + ++/** ++ * @} ++ */ ++ ++/** ++ * @addtogroup lavu_media Media Type ++ * @brief Media Type ++ */ ++ + enum AVMediaType { +- AVMEDIA_TYPE_UNKNOWN = -1, ++ AVMEDIA_TYPE_UNKNOWN = -1, ///< Usually treated as AVMEDIA_TYPE_DATA + AVMEDIA_TYPE_VIDEO, + AVMEDIA_TYPE_AUDIO, +- AVMEDIA_TYPE_DATA, ++ AVMEDIA_TYPE_DATA, ///< Opaque data information usually continuous + AVMEDIA_TYPE_SUBTITLE, +- AVMEDIA_TYPE_ATTACHMENT, ++ AVMEDIA_TYPE_ATTACHMENT, ///< Opaque data information usually sparse + AVMEDIA_TYPE_NB + }; + ++/** ++ * Return a string describing the media_type enum, NULL if media_type ++ * is unknown. ++ */ ++const char *av_get_media_type_string(enum AVMediaType media_type); ++ ++/** ++ * @defgroup lavu_const Constants ++ * @{ ++ * ++ * @defgroup lavu_enc Encoding specific ++ * ++ * @note those definition should move to avcodec ++ * @{ ++ */ ++ + #define FF_LAMBDA_SHIFT 7 + #define FF_LAMBDA_SCALE (1<=FF_ARRAY_ELEMS(map2) || map2[index] == 0xff) +- return -1; +- v = (v << 6) + map2[index]; +- if (i & 3) { +- if (dst - out < out_size) { +- *dst++ = v >> (6 - 2 * (i & 3)); +- } +- } +- } +- +- return dst - out; ++ uint8_t *end = out + out_size; ++ // no sign extension ++ const uint8_t *in = in_str; ++ unsigned bits = 0xff; ++ unsigned v; ++ ++ while (end - dst > 3) { ++ BASE64_DEC_STEP(0); ++ BASE64_DEC_STEP(1); ++ BASE64_DEC_STEP(2); ++ BASE64_DEC_STEP(3); ++ // Using AV_WB32 directly confuses compiler ++ v = av_be2ne32(v << 8); ++ AV_WN32(dst, v); ++ dst += 3; ++ in += 4; ++ } ++ if (end - dst) { ++ BASE64_DEC_STEP(0); ++ BASE64_DEC_STEP(1); ++ BASE64_DEC_STEP(2); ++ BASE64_DEC_STEP(3); ++ *dst++ = v >> 16; ++ if (end - dst) ++ *dst++ = v >> 8; ++ if (end - dst) ++ *dst++ = v; ++ in += 4; ++ } ++ while (1) { ++ BASE64_DEC_STEP(0); ++ in++; ++ BASE64_DEC_STEP(0); ++ in++; ++ BASE64_DEC_STEP(0); ++ in++; ++ BASE64_DEC_STEP(0); ++ in++; ++ } ++ ++out3: ++ *dst++ = v >> 10; ++ v <<= 2; ++out2: ++ *dst++ = v >> 4; ++out1: ++out0: ++ return bits & 1 ? -1 : dst - out; + } + + /***************************************************************************** +@@ -82,15 +147,23 @@ + out_size < AV_BASE64_SIZE(in_size)) + return NULL; + ret = dst = out; ++ while (bytes_remaining > 3) { ++ i_bits = AV_RB32(in); ++ in += 3; bytes_remaining -= 3; ++ *dst++ = b64[ i_bits>>26 ]; ++ *dst++ = b64[(i_bits>>20) & 0x3F]; ++ *dst++ = b64[(i_bits>>14) & 0x3F]; ++ *dst++ = b64[(i_bits>>8 ) & 0x3F]; ++ } ++ i_bits = 0; + while (bytes_remaining) { + i_bits = (i_bits << 8) + *in++; + bytes_remaining--; + i_shift += 8; +- +- do { +- *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; +- i_shift -= 6; +- } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); ++ } ++ while (i_shift > 0) { ++ *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; ++ i_shift -= 6; + } + while ((dst - ret) & 3) + *dst++ = '='; +@@ -100,6 +173,7 @@ + } + + #ifdef TEST ++// LCOV_EXCL_START + + #undef printf + +@@ -123,21 +197,40 @@ + return 1; + } + +- if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) < 0) { ++ if ((data2_size = av_base64_decode(data2, encoded, max_data2_size)) != data_size) { + printf("Failed: cannot decode the encoded string\n" + "Encoded:\n%s\n", encoded); + return 1; + } ++ if ((data2_size = av_base64_decode(data2, encoded, data_size)) != data_size) { ++ printf("Failed: cannot decode with minimal buffer\n" ++ "Encoded:\n%s\n", encoded); ++ return 1; ++ } + if (memcmp(data2, data, data_size)) { + printf("Failed: encoded/decoded data differs from original data\n"); + return 1; + } ++ if (av_base64_decode(NULL, encoded, 0) != 0) { ++ printf("Failed: decode to NULL buffer\n"); ++ return 1; ++ } ++ if (strlen(encoded)) { ++ char *end = strchr(encoded, '='); ++ if (!end) ++ end = encoded + strlen(encoded) - 1; ++ *end = '%'; ++ if (av_base64_decode(NULL, encoded, 0) >= 0) { ++ printf("Failed: error detection\n"); ++ return 1; ++ } ++ } + + printf("Passed!\n"); + return 0; + } + +-int main(void) ++int main(int argc, char ** argv) + { + int i, error_count = 0; + struct test { +@@ -153,12 +246,34 @@ + { "666666", "NjY2NjY2"}, + { "abc:def", "YWJjOmRlZg=="}, + }; ++ char in[1024], out[2048]; + + printf("Encoding/decoding tests\n"); + for (i = 0; i < FF_ARRAY_ELEMS(tests); i++) + error_count += test_encode_decode(tests[i].data, strlen(tests[i].data), tests[i].encoded_ref); + ++ if (argc>1 && !strcmp(argv[1], "-t")) { ++ memset(in, 123, sizeof(in)); ++ for(i=0; i<10000; i++){ ++ START_TIMER ++ av_base64_encode(out, sizeof(out), in, sizeof(in)); ++ STOP_TIMER("encode") ++ } ++ for(i=0; i<10000; i++){ ++ START_TIMER ++ av_base64_decode(in, out, sizeof(in)); ++ STOP_TIMER("decode") ++ } ++ ++ for(i=0; i<10000; i++){ ++ START_TIMER ++ av_base64_decode(NULL, out, 0); ++ STOP_TIMER("syntax check") ++ } ++ } ++ + return error_count; + } + ++// LCOV_EXCL_STOP + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/base64.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/base64.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/base64.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/base64.h 2012-05-14 14:08:55.289359202 +0200 +@@ -24,6 +24,13 @@ + #include + + /** ++ * @defgroup lavu_base64 Base64 ++ * @ingroup lavu_crypto ++ * @{ ++ */ ++ ++ ++/** + * Decode a base64-encoded string. + * + * @param out buffer for decoded data +@@ -51,4 +58,8 @@ + */ + #define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) + ++ /** ++ * @} ++ */ ++ + #endif /* AVUTIL_BASE64_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/bswap.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/bswap.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/bswap.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/bswap.h 2012-05-14 14:08:55.290359222 +0200 +@@ -65,29 +65,14 @@ + #ifndef av_bswap32 + static av_always_inline av_const uint32_t av_bswap32(uint32_t x) + { +- x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); +- x= (x>>16) | (x<<16); +- return x; ++ return AV_BSWAP32C(x); + } + #endif + + #ifndef av_bswap64 + static inline uint64_t av_const av_bswap64(uint64_t x) + { +-#if 0 +- x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); +- x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); +- return (x>>32) | (x<<32); +-#else +- union { +- uint64_t ll; +- uint32_t l[2]; +- } w, r; +- w.ll = x; +- r.l[0] = av_bswap32 (w.l[1]); +- r.l[1] = av_bswap32 (w.l[0]); +- return r.ll; +-#endif ++ return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32); + } + #endif + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/common.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/common.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/common.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/common.h 2012-05-14 14:08:55.291359242 +0200 +@@ -48,6 +48,8 @@ + #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) + /* assume b>0 */ + #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) ++#define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b)) ++#define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b)) + #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) + #define FFSIGN(a) ((a) > 0 ? 1 : -1) + +@@ -65,7 +67,7 @@ + + extern const uint8_t av_reverse[256]; + +-static inline av_const int av_log2_c(unsigned int v) ++static av_always_inline av_const int av_log2_c(unsigned int v) + { + int n = 0; + if (v & 0xffff0000) { +@@ -81,7 +83,7 @@ + return n; + } + +-static inline av_const int av_log2_16bit_c(unsigned int v) ++static av_always_inline av_const int av_log2_16bit_c(unsigned int v) + { + int n = 0; + if (v & 0xff00) { +@@ -108,7 +110,7 @@ + * @param amax maximum value of the clip range + * @return clipped value + */ +-static inline av_const int av_clip_c(int a, int amin, int amax) ++static av_always_inline av_const int av_clip_c(int a, int amin, int amax) + { + if (a < amin) return amin; + else if (a > amax) return amax; +@@ -120,7 +122,7 @@ + * @param a value to clip + * @return clipped value + */ +-static inline av_const uint8_t av_clip_uint8_c(int a) ++static av_always_inline av_const uint8_t av_clip_uint8_c(int a) + { + if (a&(~0xFF)) return (-a)>>31; + else return a; +@@ -131,7 +133,7 @@ + * @param a value to clip + * @return clipped value + */ +-static inline av_const int8_t av_clip_int8_c(int a) ++static av_always_inline av_const int8_t av_clip_int8_c(int a) + { + if ((a+0x80) & ~0xFF) return (a>>31) ^ 0x7F; + else return a; +@@ -142,7 +144,7 @@ + * @param a value to clip + * @return clipped value + */ +-static inline av_const uint16_t av_clip_uint16_c(int a) ++static av_always_inline av_const uint16_t av_clip_uint16_c(int a) + { + if (a&(~0xFFFF)) return (-a)>>31; + else return a; +@@ -153,7 +155,7 @@ + * @param a value to clip + * @return clipped value + */ +-static inline av_const int16_t av_clip_int16_c(int a) ++static av_always_inline av_const int16_t av_clip_int16_c(int a) + { + if ((a+0x8000) & ~0xFFFF) return (a>>31) ^ 0x7FFF; + else return a; +@@ -164,20 +166,32 @@ + * @param a value to clip + * @return clipped value + */ +-static inline av_const int32_t av_clipl_int32_c(int64_t a) ++static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a) + { + if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (a>>63) ^ 0x7FFFFFFF; + else return a; + } + + /** ++ * Clip a signed integer to an unsigned power of two range. ++ * @param a value to clip ++ * @param p bit position to clip at ++ * @return clipped value ++ */ ++static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p) ++{ ++ if (a & ~((1<> 31 & ((1< amax) return amax; +@@ -188,7 +202,7 @@ + * @param x value used to compute ceil(log2(x)) + * @return computed ceiling of log2(x) + */ +-static inline av_const int av_ceil_log2_c(int x) ++static av_always_inline av_const int av_ceil_log2_c(int x) + { + return av_log2((x - 1) << 1); + } +@@ -198,7 +212,7 @@ + * @param x value to count bits of + * @return the number of bits set to one in x + */ +-static inline av_const int av_popcount_c(uint32_t x) ++static av_always_inline av_const int av_popcount_c(uint32_t x) + { + x -= (x >> 1) & 0x55555555; + x = (x & 0x33333333) + ((x >> 2) & 0x33333333); +@@ -207,8 +221,18 @@ + return (x + (x >> 16)) & 0x3F; + } + +-#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((d) << 24)) +-#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((a) << 24)) ++/** ++ * Count number of bits set to one in x ++ * @param x value to count bits of ++ * @return the number of bits set to one in x ++ */ ++static av_always_inline av_const int av_popcount64_c(uint64_t x) ++{ ++ return av_popcount(x) + av_popcount(x >> 32); ++} ++ ++#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24)) ++#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24)) + + /** + * Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form. +@@ -257,16 +281,16 @@ + }\ + }\ + +-/*! +- * \def PUT_UTF8(val, tmp, PUT_BYTE) ++/** ++ * @def PUT_UTF8(val, tmp, PUT_BYTE) + * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). +- * \param val is an input-only argument and should be of type uint32_t. It holds ++ * @param val is an input-only argument and should be of type uint32_t. It holds + * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If + * val is given as a function it is executed only once. +- * \param tmp is a temporary variable and should be of type uint8_t. It ++ * @param tmp is a temporary variable and should be of type uint8_t. It + * represents an intermediate value during conversion that is to be + * output by PUT_BYTE. +- * \param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. ++ * @param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. + * It could be a function or a statement, and uses tmp as the input byte. + * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be + * executed up to 4 times for values in the valid UTF-8 range and up to +@@ -293,16 +317,16 @@ + }\ + } + +-/*! +- * \def PUT_UTF16(val, tmp, PUT_16BIT) ++/** ++ * @def PUT_UTF16(val, tmp, PUT_16BIT) + * Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes). +- * \param val is an input-only argument and should be of type uint32_t. It holds ++ * @param val is an input-only argument and should be of type uint32_t. It holds + * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If + * val is given as a function it is executed only once. +- * \param tmp is a temporary variable and should be of type uint16_t. It ++ * @param tmp is a temporary variable and should be of type uint16_t. It + * represents an intermediate value during conversion that is to be + * output by PUT_16BIT. +- * \param PUT_16BIT writes the converted UTF-16 data to any proper destination ++ * @param PUT_16BIT writes the converted UTF-16 data to any proper destination + * in desired endianness. It could be a function or a statement, and uses tmp + * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" + * PUT_BYTE will be executed 1 or 2 times depending on input character. +@@ -363,9 +387,15 @@ + #ifndef av_clipl_int32 + # define av_clipl_int32 av_clipl_int32_c + #endif ++#ifndef av_clip_uintp2 ++# define av_clip_uintp2 av_clip_uintp2_c ++#endif + #ifndef av_clipf + # define av_clipf av_clipf_c + #endif + #ifndef av_popcount + # define av_popcount av_popcount_c + #endif ++#ifndef av_popcount64 ++# define av_popcount64 av_popcount64_c ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/cpu.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/cpu.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/cpu.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/cpu.c 2012-05-14 14:08:55.292359262 +0200 +@@ -19,10 +19,15 @@ + #include "cpu.h" + #include "config.h" + ++static int flags, checked; ++ ++void av_force_cpu_flags(int arg){ ++ flags = arg; ++ checked = 1; ++} ++ + int av_get_cpu_flags(void) + { +- static int flags, checked; +- + if (checked) + return flags; + +@@ -39,30 +44,47 @@ + #undef printf + #include + ++static const struct { ++ int flag; ++ const char *name; ++} cpu_flag_tab[] = { ++#if ARCH_ARM ++ { AV_CPU_FLAG_IWMMXT, "iwmmxt" }, ++#elif ARCH_PPC ++ { AV_CPU_FLAG_ALTIVEC, "altivec" }, ++#elif ARCH_X86 ++ { AV_CPU_FLAG_MMX, "mmx" }, ++ { AV_CPU_FLAG_MMX2, "mmx2" }, ++ { AV_CPU_FLAG_SSE, "sse" }, ++ { AV_CPU_FLAG_SSE2, "sse2" }, ++ { AV_CPU_FLAG_SSE2SLOW, "sse2(slow)" }, ++ { AV_CPU_FLAG_SSE3, "sse3" }, ++ { AV_CPU_FLAG_SSE3SLOW, "sse3(slow)" }, ++ { AV_CPU_FLAG_SSSE3, "ssse3" }, ++ { AV_CPU_FLAG_ATOM, "atom" }, ++ { AV_CPU_FLAG_SSE4, "sse4.1" }, ++ { AV_CPU_FLAG_SSE42, "sse4.2" }, ++ { AV_CPU_FLAG_AVX, "avx" }, ++ { AV_CPU_FLAG_XOP, "xop" }, ++ { AV_CPU_FLAG_FMA4, "fma4" }, ++ { AV_CPU_FLAG_3DNOW, "3dnow" }, ++ { AV_CPU_FLAG_3DNOWEXT, "3dnowext" }, ++#endif ++ { 0 } ++}; ++ + int main(void) + { + int cpu_flags = av_get_cpu_flags(); ++ int i; + + printf("cpu_flags = 0x%08X\n", cpu_flags); +- printf("cpu_flags = %s%s%s%s%s%s%s%s%s%s%s%s\n", +-#if ARCH_ARM +- cpu_flags & AV_CPU_FLAG_IWMMXT ? "IWMMXT " : "", +-#elif ARCH_PPC +- cpu_flags & AV_CPU_FLAG_ALTIVEC ? "ALTIVEC " : "", +-#elif ARCH_X86 +- cpu_flags & AV_CPU_FLAG_MMX ? "MMX " : "", +- cpu_flags & AV_CPU_FLAG_MMX2 ? "MMX2 " : "", +- cpu_flags & AV_CPU_FLAG_SSE ? "SSE " : "", +- cpu_flags & AV_CPU_FLAG_SSE2 ? "SSE2 " : "", +- cpu_flags & AV_CPU_FLAG_SSE2SLOW ? "SSE2(slow) " : "", +- cpu_flags & AV_CPU_FLAG_SSE3 ? "SSE3 " : "", +- cpu_flags & AV_CPU_FLAG_SSE3SLOW ? "SSE3(slow) " : "", +- cpu_flags & AV_CPU_FLAG_SSSE3 ? "SSSE3 " : "", +- cpu_flags & AV_CPU_FLAG_SSE4 ? "SSE4.1 " : "", +- cpu_flags & AV_CPU_FLAG_SSE42 ? "SSE4.2 " : "", +- cpu_flags & AV_CPU_FLAG_3DNOW ? "3DNow " : "", +- cpu_flags & AV_CPU_FLAG_3DNOWEXT ? "3DNowExt " : ""); +-#endif ++ printf("cpu_flags ="); ++ for (i = 0; cpu_flag_tab[i].flag; i++) ++ if (cpu_flags & cpu_flag_tab[i].flag) ++ printf(" %s", cpu_flag_tab[i].name); ++ printf("\n"); ++ + return 0; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/cpu.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/cpu.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/cpu.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/cpu.h 2012-05-14 14:08:55.293359282 +0200 +@@ -34,8 +34,12 @@ + #define AV_CPU_FLAG_SSE3 0x0040 ///< Prescott SSE3 functions + #define AV_CPU_FLAG_SSE3SLOW 0x20000000 ///< SSE3 supported, but usually not faster + #define AV_CPU_FLAG_SSSE3 0x0080 ///< Conroe SSSE3 functions ++#define AV_CPU_FLAG_ATOM 0x10000000 ///< Atom processor, some SSSE3 instructions are slower + #define AV_CPU_FLAG_SSE4 0x0100 ///< Penryn SSE4.1 functions + #define AV_CPU_FLAG_SSE42 0x0200 ///< Nehalem SSE4.2 functions ++#define AV_CPU_FLAG_AVX 0x4000 ///< AVX functions: requires OS support even if YMM registers aren't used ++#define AV_CPU_FLAG_XOP 0x0400 ///< Bulldozer XOP functions ++#define AV_CPU_FLAG_FMA4 0x0800 ///< Bulldozer FMA4 functions + #define AV_CPU_FLAG_IWMMXT 0x0100 ///< XScale IWMMXT + #define AV_CPU_FLAG_ALTIVEC 0x0001 ///< standard + +@@ -44,9 +48,16 @@ + */ + int av_get_cpu_flags(void); + ++ ++/** ++ * Disables cpu detection and forces the specified flags. ++ */ ++void av_force_cpu_flags(int flags); ++ ++ + /* The following CPU-specific functions shall not be called directly. */ + int ff_get_cpu_flags_arm(void); + int ff_get_cpu_flags_ppc(void); + int ff_get_cpu_flags_x86(void); + +-#endif /* AVUTIL_CPU_H */ ++#endif /* AVUTIL_CPU_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/crc.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/crc.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/crc.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/crc.c 2012-05-14 14:08:55.294359302 +0200 +@@ -56,32 +56,34 @@ + * @param ctx_size size of ctx in bytes + * @return <0 on failure + */ +-int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size){ +- int i, j; ++int av_crc_init(AVCRC *ctx, int le, int bits, uint32_t poly, int ctx_size) ++{ ++ unsigned i, j; + uint32_t c; + +- if (bits < 8 || bits > 32 || poly >= (1LL< 32 || poly >= (1LL << bits)) + return -1; +- if (ctx_size != sizeof(AVCRC)*257 && ctx_size != sizeof(AVCRC)*1024) ++ if (ctx_size != sizeof(AVCRC) * 257 && ctx_size != sizeof(AVCRC) * 1024) + return -1; + + for (i = 0; i < 256; i++) { + if (le) { + for (c = i, j = 0; j < 8; j++) +- c = (c>>1)^(poly & (-(c&1))); ++ c = (c >> 1) ^ (poly & (-(c & 1))); + ctx[i] = c; + } else { + for (c = i << 24, j = 0; j < 8; j++) +- c = (c<<1) ^ ((poly<<(32-bits)) & (((int32_t)c)>>31) ); ++ c = (c << 1) ^ ((poly << (32 - bits)) & (((int32_t) c) >> 31)); + ctx[i] = av_bswap32(c); + } + } +- ctx[256]=1; ++ ctx[256] = 1; + #if !CONFIG_SMALL +- if(ctx_size >= sizeof(AVCRC)*1024) ++ if (ctx_size >= sizeof(AVCRC) * 1024) + for (i = 0; i < 256; i++) +- for(j=0; j<3; j++) +- ctx[256*(j+1) + i]= (ctx[256*j + i]>>8) ^ ctx[ ctx[256*j + i]&0xFF ]; ++ for (j = 0; j < 3; j++) ++ ctx[256 *(j + 1) + i] = ++ (ctx[256 * j + i] >> 8) ^ ctx[ctx[256 * j + i] & 0xFF]; + #endif + + return 0; +@@ -92,9 +94,10 @@ + * @param crc_id ID of a standard CRC + * @return a pointer to the CRC table or NULL on failure + */ +-const AVCRC *av_crc_get_table(AVCRCId crc_id){ ++const AVCRC *av_crc_get_table(AVCRCId crc_id) ++{ + #if !CONFIG_HARDCODED_TABLES +- if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id])-1]) ++ if (!av_crc_table[crc_id][FF_ARRAY_ELEMS(av_crc_table[crc_id]) - 1]) + if (av_crc_init(av_crc_table[crc_id], + av_crc_table_params[crc_id].le, + av_crc_table_params[crc_id].bits, +@@ -112,46 +115,50 @@ + * + * @see av_crc_init() "le" parameter + */ +-uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length){ +- const uint8_t *end= buffer+length; ++uint32_t av_crc(const AVCRC *ctx, uint32_t crc, ++ const uint8_t *buffer, size_t length) ++{ ++ const uint8_t *end = buffer + length; + + #if !CONFIG_SMALL +- if(!ctx[256]) { +- while(((intptr_t) buffer & 3) && buffer < end) +- crc = ctx[((uint8_t)crc) ^ *buffer++] ^ (crc >> 8); +- +- while(buffer>8 )&0xFF)] +- ^ctx[1*256 + ((crc>>16)&0xFF)] +- ^ctx[0*256 + ((crc>>24) )]; ++ if (!ctx[256]) { ++ while (((intptr_t) buffer & 3) && buffer < end) ++ crc = ctx[((uint8_t) crc) ^ *buffer++] ^ (crc >> 8); ++ ++ while (buffer < end - 3) { ++ crc ^= av_le2ne32(*(const uint32_t *) buffer); buffer += 4; ++ crc = ctx[3 * 256 + ( crc & 0xFF)] ^ ++ ctx[2 * 256 + ((crc >> 8 ) & 0xFF)] ^ ++ ctx[1 * 256 + ((crc >> 16) & 0xFF)] ^ ++ ctx[0 * 256 + ((crc >> 24) )]; + } + } + #endif +- while(buffer> 8); ++ while (buffer < end) ++ crc = ctx[((uint8_t) crc) ^ *buffer++] ^ (crc >> 8); + + return crc; + } + + #ifdef TEST + #undef printf +-int main(void){ ++int main(void) ++{ + uint8_t buf[1999]; + int i; +- int p[4][3]={{AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04}, +- {AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0}, +- {AV_CRC_16_ANSI , 0x8005, 0x1FBB }, +- {AV_CRC_8_ATM , 0x07, 0xE3 },}; ++ int p[4][3] = { { AV_CRC_32_IEEE_LE, 0xEDB88320, 0x3D5CDD04 }, ++ { AV_CRC_32_IEEE , 0x04C11DB7, 0xC0F5BAE0 }, ++ { AV_CRC_16_ANSI , 0x8005 , 0x1FBB }, ++ { AV_CRC_8_ATM , 0x07 , 0xE3 } ++ }; + const AVCRC *ctx; + +- for(i=0; i 0) { + uint64_t dst_val; +- uint64_t src_val = src ? av_be2ne64(*(const uint64_t *)src) : 0; ++ uint64_t src_val = src ? AV_RB64(src) : 0; + if (decrypt) { + uint64_t tmp = src_val; + if (d->triple_des) { +@@ -317,15 +319,25 @@ + } + iv_val = iv ? dst_val : 0; + } +- *(uint64_t *)dst = av_be2ne64(dst_val); ++ AV_WB64(dst, dst_val); + src += 8; +- dst += 8; ++ if (!mac) ++ dst += 8; + } + if (iv) +- *(uint64_t *)iv = av_be2ne64(iv_val); ++ AV_WB64(iv, iv_val); ++} ++ ++void av_des_crypt(AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt) { ++ av_des_crypt_mac(d, dst, src, count, iv, decrypt, 0); ++} ++ ++void av_des_mac(AVDES *d, uint8_t *dst, const uint8_t *src, int count) { ++ av_des_crypt_mac(d, dst, src, count, (uint8_t[8]){0}, 0, 1); + } + + #ifdef TEST ++// LCOV_EXCL_START + #undef printf + #undef rand + #undef srand +@@ -402,7 +414,7 @@ + printf("Partial Monte-Carlo test failed\n"); + return 1; + } +- for (i = 0; i < 1000000; i++) { ++ for (i = 0; i < 1000; i++) { + key[0] = rand64(); key[1] = rand64(); key[2] = rand64(); + data = rand64(); + av_des_init(&d, key, 192, 0); +@@ -432,4 +444,5 @@ + #endif + return 0; + } ++// LCOV_EXCL_STOP + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/des.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/des.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/des.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/des.h 2012-05-14 14:08:55.295359323 +0200 +@@ -30,23 +30,32 @@ + }; + + /** +- * \brief Initializes an AVDES context. ++ * @brief Initializes an AVDES context. + * +- * \param key_bits must be 64 or 192 +- * \param decrypt 0 for encryption, 1 for decryption ++ * @param key_bits must be 64 or 192 ++ * @param decrypt 0 for encryption/CBC-MAC, 1 for decryption + */ + int av_des_init(struct AVDES *d, const uint8_t *key, int key_bits, int decrypt); + + /** +- * \brief Encrypts / decrypts using the DES algorithm. ++ * @brief Encrypts / decrypts using the DES algorithm. + * +- * \param count number of 8 byte blocks +- * \param dst destination array, can be equal to src, must be 8-byte aligned +- * \param src source array, can be equal to dst, must be 8-byte aligned, may be NULL +- * \param iv initialization vector for CBC mode, if NULL then ECB will be used, ++ * @param count number of 8 byte blocks ++ * @param dst destination array, can be equal to src, must be 8-byte aligned ++ * @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL ++ * @param iv initialization vector for CBC mode, if NULL then ECB will be used, + * must be 8-byte aligned +- * \param decrypt 0 for encryption, 1 for decryption ++ * @param decrypt 0 for encryption, 1 for decryption + */ + void av_des_crypt(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt); + ++/** ++ * @brief Calculates CBC-MAC using the DES algorithm. ++ * ++ * @param count number of 8 byte blocks ++ * @param dst destination array, can be equal to src, must be 8-byte aligned ++ * @param src source array, can be equal to dst, must be 8-byte aligned, may be NULL ++ */ ++void av_des_mac(struct AVDES *d, uint8_t *dst, const uint8_t *src, int count); ++ + #endif /* AVUTIL_DES_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/dict.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/dict.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/dict.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/dict.c 2012-05-14 14:08:55.296359344 +0200 +@@ -0,0 +1,120 @@ ++/* ++ * copyright (c) 2009 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "avstring.h" ++#include "dict.h" ++#include "internal.h" ++#include "mem.h" ++ ++AVDictionaryEntry * ++av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags) ++{ ++ unsigned int i, j; ++ ++ if(!m) ++ return NULL; ++ ++ if(prev) i= prev - m->elems + 1; ++ else i= 0; ++ ++ for(; icount; i++){ ++ const char *s= m->elems[i].key; ++ if(flags & AV_DICT_MATCH_CASE) for(j=0; s[j] == key[j] && key[j]; j++); ++ else for(j=0; toupper(s[j]) == toupper(key[j]) && key[j]; j++); ++ if(key[j]) ++ continue; ++ if(s[j] && !(flags & AV_DICT_IGNORE_SUFFIX)) ++ continue; ++ return &m->elems[i]; ++ } ++ return NULL; ++} ++ ++int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags) ++{ ++ AVDictionary *m = *pm; ++ AVDictionaryEntry *tag = av_dict_get(m, key, NULL, flags); ++ char *oldval = NULL; ++ ++ if(!m) ++ m = *pm = av_mallocz(sizeof(*m)); ++ ++ if(tag) { ++ if (flags & AV_DICT_DONT_OVERWRITE) ++ return 0; ++ if (flags & AV_DICT_APPEND) ++ oldval = tag->value; ++ else ++ av_free(tag->value); ++ av_free(tag->key); ++ *tag = m->elems[--m->count]; ++ } else { ++ AVDictionaryEntry *tmp = av_realloc(m->elems, (m->count+1) * sizeof(*m->elems)); ++ if(tmp) { ++ m->elems = tmp; ++ } else ++ return AVERROR(ENOMEM); ++ } ++ if (value) { ++ if (flags & AV_DICT_DONT_STRDUP_KEY) { ++ m->elems[m->count].key = (char*)(intptr_t)key; ++ } else ++ m->elems[m->count].key = av_strdup(key ); ++ if (flags & AV_DICT_DONT_STRDUP_VAL) { ++ m->elems[m->count].value = (char*)(intptr_t)value; ++ } else if (oldval && flags & AV_DICT_APPEND) { ++ int len = strlen(oldval) + strlen(value) + 1; ++ if (!(oldval = av_realloc(oldval, len))) ++ return AVERROR(ENOMEM); ++ av_strlcat(oldval, value, len); ++ m->elems[m->count].value = oldval; ++ } else ++ m->elems[m->count].value = av_strdup(value); ++ m->count++; ++ } ++ if (!m->count) { ++ av_free(m->elems); ++ av_freep(pm); ++ } ++ ++ return 0; ++} ++ ++void av_dict_free(AVDictionary **pm) ++{ ++ AVDictionary *m = *pm; ++ ++ if (m) { ++ while(m->count--) { ++ av_free(m->elems[m->count].key); ++ av_free(m->elems[m->count].value); ++ } ++ av_free(m->elems); ++ } ++ av_freep(pm); ++} ++ ++void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags) ++{ ++ AVDictionaryEntry *t = NULL; ++ ++ while ((t = av_dict_get(src, "", t, AV_DICT_IGNORE_SUFFIX))) ++ av_dict_set(dst, t->key, t->value, flags); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/dict.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/dict.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/dict.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/dict.h 2012-05-14 14:08:55.297359364 +0200 +@@ -0,0 +1,127 @@ ++/* ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * Public dictionary API. ++ * @deprecated ++ * AVDictionary is provided for compatibility with libav. It is both in ++ * implementation as well as API inefficient. It does not scale and is ++ * extremely slow with large dictionaries. ++ * It is recommended that new code uses our tree container from tree.c/h ++ * where applicable, which uses AVL trees to achieve O(log n) performance. ++ */ ++ ++#ifndef AVUTIL_DICT_H ++#define AVUTIL_DICT_H ++ ++/** ++ * @addtogroup lavu_dict AVDictionary ++ * @ingroup lavu_data ++ * ++ * @brief Simple key:value store ++ * ++ * @{ ++ * Dictionaries are used for storing key:value pairs. To create ++ * an AVDictionary, simply pass an address of a NULL pointer to ++ * av_dict_set(). NULL can be used as an empty dictionary wherever ++ * a pointer to an AVDictionary is required. ++ * Use av_dict_get() to retrieve an entry or iterate over all ++ * entries and finally av_dict_free() to free the dictionary ++ * and all its contents. ++ * ++ * @code ++ * AVDictionary *d = NULL; // "create" an empty dictionary ++ * av_dict_set(&d, "foo", "bar", 0); // add an entry ++ * ++ * char *k = av_strdup("key"); // if your strings are already allocated, ++ * char *v = av_strdup("value"); // you can avoid copying them like this ++ * av_dict_set(&d, k, v, AV_DICT_DONT_STRDUP_KEY | AV_DICT_DONT_STRDUP_VAL); ++ * ++ * AVDictionaryEntry *t = NULL; ++ * while (t = av_dict_get(d, "", t, AV_DICT_IGNORE_SUFFIX)) { ++ * <....> // iterate over all entries in d ++ * } ++ * ++ * av_dict_free(&d); ++ * @endcode ++ * ++ */ ++ ++#define AV_DICT_MATCH_CASE 1 ++#define AV_DICT_IGNORE_SUFFIX 2 ++#define AV_DICT_DONT_STRDUP_KEY 4 /**< Take ownership of a key that's been ++ allocated with av_malloc() and children. */ ++#define AV_DICT_DONT_STRDUP_VAL 8 /**< Take ownership of a value that's been ++ allocated with av_malloc() and chilren. */ ++#define AV_DICT_DONT_OVERWRITE 16 ///< Don't overwrite existing entries. ++#define AV_DICT_APPEND 32 /**< If the entry already exists, append to it. Note that no ++ delimiter is added, the strings are simply concatenated. */ ++ ++typedef struct { ++ char *key; ++ char *value; ++} AVDictionaryEntry; ++ ++typedef struct AVDictionary AVDictionary; ++ ++/** ++ * Get a dictionary entry with matching key. ++ * ++ * @param prev Set to the previous matching element to find the next. ++ * If set to NULL the first matching element is returned. ++ * @param flags Allows case as well as suffix-insensitive comparisons. ++ * @return Found entry or NULL, changing key or value leads to undefined behavior. ++ */ ++AVDictionaryEntry * ++av_dict_get(AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags); ++ ++/** ++ * Set the given entry in *pm, overwriting an existing entry. ++ * ++ * @param pm pointer to a pointer to a dictionary struct. If *pm is NULL ++ * a dictionary struct is allocated and put in *pm. ++ * @param key entry key to add to *pm (will be av_strduped depending on flags) ++ * @param value entry value to add to *pm (will be av_strduped depending on flags). ++ * Passing a NULL value will cause an existing tag to be deleted. ++ * @return >= 0 on success otherwise an error code <0 ++ */ ++int av_dict_set(AVDictionary **pm, const char *key, const char *value, int flags); ++ ++/** ++ * Copy entries from one AVDictionary struct into another. ++ * @param dst pointer to a pointer to a AVDictionary struct. If *dst is NULL, ++ * this function will allocate a struct for you and put it in *dst ++ * @param src pointer to source AVDictionary struct ++ * @param flags flags to use when setting entries in *dst ++ * @note metadata is read using the AV_DICT_IGNORE_SUFFIX flag ++ */ ++void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags); ++ ++/** ++ * Free all the memory allocated for an AVDictionary struct ++ * and all keys and values. ++ */ ++void av_dict_free(AVDictionary **m); ++ ++/** ++ * @} ++ */ ++ ++#endif // AVUTIL_DICT_H +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/error.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/error.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/error.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/error.c 2012-05-14 14:08:55.297359364 +0200 +@@ -16,6 +16,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++#undef _GNU_SOURCE + #include "avutil.h" + #include "avstring.h" + +@@ -25,18 +26,22 @@ + const char *errstr = NULL; + + switch (errnum) { +- case AVERROR_EOF: errstr = "End of file"; break; +- case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input"; break; +- case AVERROR_NUMEXPECTED: errstr = "Number syntax expected in filename"; break; ++ case AVERROR_BSF_NOT_FOUND: errstr = "Bitstream filter not found" ; break; ++ case AVERROR_BUG2: ++ case AVERROR_BUG: errstr = "Internal bug, should not have happened" ; break; ++ case AVERROR_DECODER_NOT_FOUND: errstr = "Decoder not found" ; break; ++ case AVERROR_DEMUXER_NOT_FOUND: errstr = "Demuxer not found" ; break; ++ case AVERROR_ENCODER_NOT_FOUND: errstr = "Encoder not found" ; break; ++ case AVERROR_EOF: errstr = "End of file" ; break; ++ case AVERROR_EXIT: errstr = "Immediate exit requested" ; break; ++ case AVERROR_FILTER_NOT_FOUND: errstr = "Filter not found" ; break; ++ case AVERROR_INVALIDDATA: errstr = "Invalid data found when processing input" ; break; ++ case AVERROR_MUXER_NOT_FOUND: errstr = "Muxer not found" ; break; ++ case AVERROR_OPTION_NOT_FOUND: errstr = "Option not found" ; break; + case AVERROR_PATCHWELCOME: errstr = "Not yet implemented in FFmpeg, patches welcome"; break; +- case AVERROR_DEMUXER_NOT_FOUND: errstr = "Demuxer not found"; break; +- case AVERROR_MUXER_NOT_FOUND: errstr = "Muxer not found"; break; +- case AVERROR_DECODER_NOT_FOUND: errstr = "Decoder not found"; break; +- case AVERROR_ENCODER_NOT_FOUND: errstr = "Encoder not found"; break; +- case AVERROR_PROTOCOL_NOT_FOUND:errstr = "Protocol not found"; break; +- case AVERROR_FILTER_NOT_FOUND: errstr = "Filter not found"; break; +- case AVERROR_BSF_NOT_FOUND: errstr = "Bitstream filter not found"; break; +- case AVERROR_STREAM_NOT_FOUND: errstr = "Stream not found"; break; ++ case AVERROR_PROTOCOL_NOT_FOUND:errstr = "Protocol not found" ; break; ++ case AVERROR_STREAM_NOT_FOUND: errstr = "Stream not found" ; break; ++ case AVERROR_UNKNOWN: errstr = "Unknown error occurred" ; break; + } + + if (errstr) { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/error.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/error.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/error.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/error.h 2012-05-14 14:08:55.298359384 +0200 +@@ -27,6 +27,13 @@ + #include + #include "avutil.h" + ++/** ++ * @addtogroup lavu_error ++ * ++ * @{ ++ */ ++ ++ + /* error handling */ + #if EDOM > 0 + #define AVERROR(e) (-(e)) ///< Returns a negative error code from a POSIX error code, to return from library functions. +@@ -37,36 +44,29 @@ + #define AVUNERROR(e) (e) + #endif + +-#if LIBAVUTIL_VERSION_MAJOR < 51 +-#define AVERROR_INVALIDDATA AVERROR(EINVAL) ///< Invalid data found when processing input +-#define AVERROR_IO AVERROR(EIO) ///< I/O error +-#define AVERROR_NOENT AVERROR(ENOENT) ///< No such file or directory +-#define AVERROR_NOFMT AVERROR(EILSEQ) ///< Unknown format +-#define AVERROR_NOMEM AVERROR(ENOMEM) ///< Not enough memory +-#define AVERROR_NOTSUPP AVERROR(ENOSYS) ///< Operation not supported +-#define AVERROR_NUMEXPECTED AVERROR(EDOM) ///< Number syntax expected in filename +-#define AVERROR_UNKNOWN AVERROR(EINVAL) ///< Unknown error +-#endif +- +-#define AVERROR_EOF AVERROR(EPIPE) ///< End of file +- +-#define AVERROR_PATCHWELCOME (-MKTAG('P','A','W','E')) ///< Not yet implemented in FFmpeg, patches welcome +- +-#if LIBAVUTIL_VERSION_MAJOR > 50 +-#define AVERROR_INVALIDDATA (-MKTAG('I','N','D','A')) ///< Invalid data found when processing input +-#define AVERROR_NUMEXPECTED (-MKTAG('N','U','E','X')) ///< Number syntax expected in filename +-#endif +- +-#define AVERROR_DEMUXER_NOT_FOUND (-MKTAG(0xF8,'D','E','M')) ///< Demuxer not found +-#define AVERROR_MUXER_NOT_FOUND (-MKTAG(0xF8,'M','U','X')) ///< Muxer not found ++#define AVERROR_BSF_NOT_FOUND (-MKTAG(0xF8,'B','S','F')) ///< Bitstream filter not found ++#define AVERROR_BUG (-MKTAG( 'B','U','G','!')) ///< Internal bug, also see AVERROR_BUG2 + #define AVERROR_DECODER_NOT_FOUND (-MKTAG(0xF8,'D','E','C')) ///< Decoder not found ++#define AVERROR_DEMUXER_NOT_FOUND (-MKTAG(0xF8,'D','E','M')) ///< Demuxer not found + #define AVERROR_ENCODER_NOT_FOUND (-MKTAG(0xF8,'E','N','C')) ///< Encoder not found +-#define AVERROR_PROTOCOL_NOT_FOUND (-MKTAG(0xF8,'P','R','O')) ///< Protocol not found ++#define AVERROR_EOF (-MKTAG( 'E','O','F',' ')) ///< End of file ++#define AVERROR_EXIT (-MKTAG( 'E','X','I','T')) ///< Immediate exit was requested; the called function should not be restarted + #define AVERROR_FILTER_NOT_FOUND (-MKTAG(0xF8,'F','I','L')) ///< Filter not found +-#define AVERROR_BSF_NOT_FOUND (-MKTAG(0xF8,'B','S','F')) ///< Bitstream filter not found ++#define AVERROR_INVALIDDATA (-MKTAG( 'I','N','D','A')) ///< Invalid data found when processing input ++#define AVERROR_MUXER_NOT_FOUND (-MKTAG(0xF8,'M','U','X')) ///< Muxer not found ++#define AVERROR_OPTION_NOT_FOUND (-MKTAG(0xF8,'O','P','T')) ///< Option not found ++#define AVERROR_PATCHWELCOME (-MKTAG( 'P','A','W','E')) ///< Not yet implemented in FFmpeg, patches welcome ++#define AVERROR_PROTOCOL_NOT_FOUND (-MKTAG(0xF8,'P','R','O')) ///< Protocol not found + #define AVERROR_STREAM_NOT_FOUND (-MKTAG(0xF8,'S','T','R')) ///< Stream not found + + /** ++ * This is semantically identical to AVERROR_BUG ++ * it has been introduced in Libav after our AVERROR_BUG and with a modified value. ++ */ ++#define AVERROR_BUG2 (-MKTAG( 'B','U','G',' ')) ++#define AVERROR_UNKNOWN (-MKTAG( 'U','N','K','N')) ///< Unknown error, typically from an external library ++ ++/** + * Put a description of the AVERROR code errnum in errbuf. + * In case of failure the global variable errno is set to indicate the + * error. Even in case of failure av_strerror() will print a generic +@@ -80,4 +80,8 @@ + */ + int av_strerror(int errnum, char *errbuf, size_t errbuf_size); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_ERROR_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/eval.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/eval.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/eval.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/eval.c 2012-05-14 14:08:55.300359424 +0200 +@@ -26,8 +26,9 @@ + * see http://joe.hotchkiss.com/programming/eval/eval.html + */ + +-#include "libavutil/avutil.h" ++#include "avutil.h" + #include "eval.h" ++#include "log.h" + + typedef struct Parser { + const AVClass *class; +@@ -43,7 +44,7 @@ + int log_offset; + void *log_ctx; + #define VARS 10 +- double var[VARS]; ++ double *var; + } Parser; + + static const AVClass class = { "Eval", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(Parser,log_offset), offsetof(Parser,log_ctx) }; +@@ -71,11 +72,23 @@ + ['Y'-'E']= 24, + }; + ++static const struct { ++ const char *name; ++ double value; ++} constants[] = { ++ { "E", M_E }, ++ { "PI", M_PI }, ++ { "PHI", M_PHI }, ++}; ++ + double av_strtod(const char *numstr, char **tail) + { + double d; + char *next; +- d = strtod(numstr, &next); ++ if(numstr[0]=='0' && (numstr[1]|0x20)=='x') { ++ d = strtoul(numstr, &next, 16); ++ } else ++ d = strtod(numstr, &next); + /* if parsing succeeded, check for and interpret postfixes */ + if (next!=numstr) { + if (*next >= 'E' && *next <= 'z') { +@@ -121,7 +134,9 @@ + e_squish, e_gauss, e_ld, e_isnan, + e_mod, e_max, e_min, e_eq, e_gt, e_gte, + e_pow, e_mul, e_div, e_add, +- e_last, e_st, e_while, ++ e_last, e_st, e_while, e_floor, e_ceil, e_trunc, ++ e_sqrt, e_not, e_random, e_hypot, e_gcd, ++ e_if, e_ifnot, + } type; + double value; // is sign in other types + union { +@@ -131,6 +146,7 @@ + double (*func2)(void *, double, double); + } a; + struct AVExpr *param[2]; ++ double *var; + }; + + static double eval_expr(Parser *p, AVExpr *e) +@@ -145,6 +161,20 @@ + case e_gauss: { double d = eval_expr(p, e->param[0]); return exp(-d*d/2)/sqrt(2*M_PI); } + case e_ld: return e->value * p->var[av_clip(eval_expr(p, e->param[0]), 0, VARS-1)]; + case e_isnan: return e->value * !!isnan(eval_expr(p, e->param[0])); ++ case e_floor: return e->value * floor(eval_expr(p, e->param[0])); ++ case e_ceil : return e->value * ceil (eval_expr(p, e->param[0])); ++ case e_trunc: return e->value * trunc(eval_expr(p, e->param[0])); ++ case e_sqrt: return e->value * sqrt (eval_expr(p, e->param[0])); ++ case e_not: return e->value * (eval_expr(p, e->param[0]) == 0); ++ case e_if: return e->value * ( eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0); ++ case e_ifnot: return e->value * (!eval_expr(p, e->param[0]) ? eval_expr(p, e->param[1]) : 0); ++ case e_random:{ ++ int idx= av_clip(eval_expr(p, e->param[0]), 0, VARS-1); ++ uint64_t r= isnan(p->var[idx]) ? 0 : p->var[idx]; ++ r= r*1664525+1013904223; ++ p->var[idx]= r; ++ return e->value * (r * (1.0/UINT64_MAX)); ++ } + case e_while: { + double d = NAN; + while (eval_expr(p, e->param[0])) +@@ -156,6 +186,7 @@ + double d2 = eval_expr(p, e->param[1]); + switch (e->type) { + case e_mod: return e->value * (d - floor(d/d2)*d2); ++ case e_gcd: return e->value * av_gcd(d,d2); + case e_max: return e->value * (d > d2 ? d : d2); + case e_min: return e->value * (d < d2 ? d : d2); + case e_eq: return e->value * (d == d2 ? 1.0 : 0.0); +@@ -167,6 +198,7 @@ + case e_add: return e->value * (d + d2); + case e_last:return e->value * d2; + case e_st : return e->value * (p->var[av_clip(d, 0, VARS-1)]= d2); ++ case e_hypot:return e->value * (sqrt(d*d + d2*d2)); + } + } + } +@@ -180,6 +212,7 @@ + if (!e) return; + av_expr_free(e->param[0]); + av_expr_free(e->param[1]); ++ av_freep(&e->var); + av_freep(&e); + } + +@@ -212,6 +245,15 @@ + return 0; + } + } ++ for (i = 0; i < FF_ARRAY_ELEMS(constants); i++) { ++ if (strmatch(p->s, constants[i].name)) { ++ p->s += strlen(constants[i].name); ++ d->type = e_value; ++ d->value = constants[i].value; ++ *e = d; ++ return 0; ++ } ++ } + + p->s= strchr(p->s, '('); + if (p->s==NULL) { +@@ -276,6 +318,17 @@ + else if (strmatch(next, "isnan" )) d->type = e_isnan; + else if (strmatch(next, "st" )) d->type = e_st; + else if (strmatch(next, "while" )) d->type = e_while; ++ else if (strmatch(next, "floor" )) d->type = e_floor; ++ else if (strmatch(next, "ceil" )) d->type = e_ceil; ++ else if (strmatch(next, "trunc" )) d->type = e_trunc; ++ else if (strmatch(next, "sqrt" )) d->type = e_sqrt; ++ else if (strmatch(next, "not" )) d->type = e_not; ++ else if (strmatch(next, "pow" )) d->type = e_pow; ++ else if (strmatch(next, "random")) d->type = e_random; ++ else if (strmatch(next, "hypot" )) d->type = e_hypot; ++ else if (strmatch(next, "gcd" )) d->type = e_gcd; ++ else if (strmatch(next, "if" )) d->type = e_if; ++ else if (strmatch(next, "ifnot" )) d->type = e_ifnot; + else { + for (i=0; p->func1_names && p->func1_names[i]; i++) { + if (strmatch(next, p->func1_names[i])) { +@@ -439,7 +492,14 @@ + case e_squish: + case e_ld: + case e_gauss: +- case e_isnan: return verify_expr(e->param[0]); ++ case e_isnan: ++ case e_floor: ++ case e_ceil: ++ case e_trunc: ++ case e_sqrt: ++ case e_not: ++ case e_random: ++ return verify_expr(e->param[0]); + default: return verify_expr(e->param[0]) && verify_expr(e->param[1]); + } + } +@@ -450,7 +510,7 @@ + const char * const *func2_names, double (* const *funcs2)(void *, double, double), + int log_offset, void *log_ctx) + { +- Parser p; ++ Parser p = { 0 }; + AVExpr *e = NULL; + char *w = av_malloc(strlen(s) + 1); + char *wp = w; +@@ -478,6 +538,7 @@ + if ((ret = parse_expr(&e, &p)) < 0) + goto end; + if (*p.s) { ++ av_expr_free(e); + av_log(&p, AV_LOG_ERROR, "Invalid chars '%s' at the end of expression '%s'\n", p.s, s0); + ret = AVERROR(EINVAL); + goto end; +@@ -487,6 +548,7 @@ + ret = AVERROR(EINVAL); + goto end; + } ++ e->var= av_mallocz(sizeof(double) *VARS); + *expr = e; + end: + av_free(w); +@@ -495,7 +557,8 @@ + + double av_expr_eval(AVExpr *e, const double *const_values, void *opaque) + { +- Parser p; ++ Parser p = { 0 }; ++ p.var= e->var; + + p.const_values = const_values; + p.opaque = opaque; +@@ -521,6 +584,7 @@ + } + + #if FF_API_OLD_EVAL_NAMES ++// LCOV_EXCL_START + int av_parse_expr(AVExpr **expr, const char *s, + const char * const *const_names, + const char * const *func1_names, double (* const *funcs1)(void *, double), +@@ -550,10 +614,14 @@ + { + av_expr_free(e); + } ++// LCOV_EXCL_STOP + #endif /* FF_API_OLD_EVAL_NAMES */ + + #ifdef TEST ++// LCOV_EXCL_START + #undef printf ++#include ++ + static double const_values[] = { + M_PI, + M_E, +@@ -566,7 +634,7 @@ + 0 + }; + +-int main(void) ++int main(int argc, char **argv) + { + int i; + double d; +@@ -577,7 +645,7 @@ + "-PI", + "+PI", + "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", +- "80G/80Gi" ++ "80G/80Gi", + "1k", + "1Gi", + "1gi", +@@ -611,6 +679,25 @@ + "st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))", + "isnan(1)", + "isnan(NAN)", ++ "floor(NAN)", ++ "floor(123.123)", ++ "floor(-123.123)", ++ "trunc(123.123)", ++ "trunc(-123.123)", ++ "ceil(123.123)", ++ "ceil(-123.123)", ++ "sqrt(1764)", ++ "isnan(sqrt(-1))", ++ "not(1)", ++ "not(NAN)", ++ "not(0)", ++ "pow(0,1.23)", ++ "pow(PI,1.23)", ++ "PI^1.23", ++ "pow(-1,1.23)", ++ "if(1, 2)", ++ "ifnot(0, 23)", ++ "ifnot(1, NaN) + if(0, 1)", + NULL + }; + +@@ -619,7 +706,11 @@ + av_expr_parse_and_eval(&d, *expr, + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); +- printf("'%s' -> %f\n\n", *expr, d); ++ if(isnan(d)){ ++ printf("'%s' -> nan\n\n", *expr); ++ }else{ ++ printf("'%s' -> %f\n\n", *expr, d); ++ } + } + + av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", +@@ -631,13 +722,17 @@ + NULL, NULL, NULL, NULL, NULL, 0, NULL); + printf("%f == 0.931322575\n", d); + +- for (i=0; i<1050; i++) { +- START_TIMER ++ if (argc > 1 && !strcmp(argv[1], "-t")) { ++ for (i = 0; i < 1050; i++) { ++ START_TIMER; + av_expr_parse_and_eval(&d, "1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)", + const_names, const_values, + NULL, NULL, NULL, NULL, NULL, 0, NULL); +- STOP_TIMER("av_expr_parse_and_eval") ++ STOP_TIMER("av_expr_parse_and_eval"); ++ } + } ++ + return 0; + } ++// LCOV_EXCL_STOP + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/eval.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/eval.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/eval.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/eval.h 2012-05-14 14:08:55.300359424 +0200 +@@ -58,7 +58,7 @@ + * Parse an expression. + * + * @param expr a pointer where is put an AVExpr containing the parsed +- * value in case of successfull parsing, or NULL otherwise. ++ * value in case of successful parsing, or NULL otherwise. + * The pointed to AVExpr must be freed with av_expr_free() by the user + * when it is not needed anymore. + * @param s expression as a zero terminated string, for example "1+2^3+5*5+sin(2/3)" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/fifo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/fifo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/fifo.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/fifo.c 2012-05-14 14:08:55.301359444 +0200 +@@ -25,7 +25,7 @@ + AVFifoBuffer *av_fifo_alloc(unsigned int size) + { + AVFifoBuffer *f= av_mallocz(sizeof(AVFifoBuffer)); +- if(!f) ++ if (!f) + return NULL; + f->buffer = av_malloc(size); + f->end = f->buffer + size; +@@ -37,8 +37,8 @@ + + void av_fifo_free(AVFifoBuffer *f) + { +- if(f){ +- av_free(f->buffer); ++ if (f) { ++ av_freep(&f->buffer); + av_free(f); + } + } +@@ -59,20 +59,21 @@ + return f->end - f->buffer - av_fifo_size(f); + } + +-int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) { +- unsigned int old_size= f->end - f->buffer; ++int av_fifo_realloc2(AVFifoBuffer *f, unsigned int new_size) ++{ ++ unsigned int old_size = f->end - f->buffer; + +- if(old_size < new_size){ +- int len= av_fifo_size(f); +- AVFifoBuffer *f2= av_fifo_alloc(new_size); ++ if (old_size < new_size) { ++ int len = av_fifo_size(f); ++ AVFifoBuffer *f2 = av_fifo_alloc(new_size); + + if (!f2) +- return -1; ++ return AVERROR(ENOMEM); + av_fifo_generic_read(f, f2->buffer, len, NULL); + f2->wptr += len; + f2->wndx += len; + av_free(f->buffer); +- *f= *f2; ++ *f = *f2; + av_free(f2); + } + return 0; +@@ -82,22 +83,27 @@ + int av_fifo_generic_write(AVFifoBuffer *f, void *src, int size, int (*func)(void*, void*, int)) + { + int total = size; ++ uint32_t wndx= f->wndx; ++ uint8_t *wptr= f->wptr; ++ + do { +- int len = FFMIN(f->end - f->wptr, size); +- if(func) { +- if(func(src, f->wptr, len) <= 0) ++ int len = FFMIN(f->end - wptr, size); ++ if (func) { ++ if (func(src, wptr, len) <= 0) + break; + } else { +- memcpy(f->wptr, src, len); ++ memcpy(wptr, src, len); + src = (uint8_t*)src + len; + } + // Write memory barrier needed for SMP here in theory +- f->wptr += len; +- if (f->wptr >= f->end) +- f->wptr = f->buffer; +- f->wndx += len; ++ wptr += len; ++ if (wptr >= f->end) ++ wptr = f->buffer; ++ wndx += len; + size -= len; + } while (size > 0); ++ f->wndx= wndx; ++ f->wptr= wptr; + return total - size; + } + +@@ -127,3 +133,39 @@ + f->rptr -= f->end - f->buffer; + f->rndx += size; + } ++ ++#ifdef TEST ++ ++#undef printf ++ ++int main(void) ++{ ++ /* create a FIFO buffer */ ++ AVFifoBuffer *fifo = av_fifo_alloc(13 * sizeof(int)); ++ int i, j, n; ++ ++ /* fill data */ ++ for (i = 0; av_fifo_space(fifo) >= sizeof(int); i++) ++ av_fifo_generic_write(fifo, &i, sizeof(int), NULL); ++ ++ /* peek at FIFO */ ++ n = av_fifo_size(fifo)/sizeof(int); ++ for (i = -n+1; i < n; i++) { ++ int *v = (int *)av_fifo_peek2(fifo, i*sizeof(int)); ++ printf("%d: %d\n", i, *v); ++ } ++ printf("\n"); ++ ++ /* read data */ ++ for (i = 0; av_fifo_size(fifo) >= sizeof(int); i++) { ++ av_fifo_generic_read(fifo, &j, sizeof(int), NULL); ++ printf("%d ", j); ++ } ++ printf("\n"); ++ ++ av_fifo_free(fifo); ++ ++ return 0; ++} ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/fifo.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/fifo.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/fifo.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/fifo.h 2012-05-14 14:08:55.302359464 +0200 +@@ -25,6 +25,7 @@ + #define AVUTIL_FIFO_H + + #include ++#include "avutil.h" + + typedef struct AVFifoBuffer { + uint8_t *buffer; +@@ -41,20 +42,20 @@ + + /** + * Free an AVFifoBuffer. +- * @param *f AVFifoBuffer to free ++ * @param f AVFifoBuffer to free + */ + void av_fifo_free(AVFifoBuffer *f); + + /** + * Reset the AVFifoBuffer to the state right after av_fifo_alloc, in particular it is emptied. +- * @param *f AVFifoBuffer to reset ++ * @param f AVFifoBuffer to reset + */ + void av_fifo_reset(AVFifoBuffer *f); + + /** + * Return the amount of data in bytes in the AVFifoBuffer, that is the + * amount of data you can read from it. +- * @param *f AVFifoBuffer to read from ++ * @param f AVFifoBuffer to read from + * @return size + */ + int av_fifo_size(AVFifoBuffer *f); +@@ -62,27 +63,27 @@ + /** + * Return the amount of space in bytes in the AVFifoBuffer, that is the + * amount of data you can write into it. +- * @param *f AVFifoBuffer to write into ++ * @param f AVFifoBuffer to write into + * @return size + */ + int av_fifo_space(AVFifoBuffer *f); + + /** + * Feed data from an AVFifoBuffer to a user-supplied callback. +- * @param *f AVFifoBuffer to read from ++ * @param f AVFifoBuffer to read from + * @param buf_size number of bytes to read +- * @param *func generic read function +- * @param *dest data destination ++ * @param func generic read function ++ * @param dest data destination + */ + int av_fifo_generic_read(AVFifoBuffer *f, void *dest, int buf_size, void (*func)(void*, void*, int)); + + /** + * Feed data from a user-supplied callback to an AVFifoBuffer. +- * @param *f AVFifoBuffer to write to +- * @param *src data source; non-const since it may be used as a ++ * @param f AVFifoBuffer to write to ++ * @param src data source; non-const since it may be used as a + * modifiable context by the function defined in func + * @param size number of bytes to write +- * @param *func generic write function; the first parameter is src, ++ * @param func generic write function; the first parameter is src, + * the second is dest_buf, the third is dest_buf_size. + * func must return the number of bytes written to dest_buf, or <= 0 to + * indicate no more data available to write. +@@ -93,7 +94,9 @@ + + /** + * Resize an AVFifoBuffer. +- * @param *f AVFifoBuffer to resize ++ * In case of reallocation failure, the old FIFO is kept unchanged. ++ * ++ * @param f AVFifoBuffer to resize + * @param size new AVFifoBuffer size in bytes + * @return <0 for failure, >=0 otherwise + */ +@@ -101,16 +104,40 @@ + + /** + * Read and discard the specified amount of data from an AVFifoBuffer. +- * @param *f AVFifoBuffer to read from ++ * @param f AVFifoBuffer to read from + * @param size amount of data to read in bytes + */ + void av_fifo_drain(AVFifoBuffer *f, int size); + +-static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs) ++/** ++ * Return a pointer to the data stored in a FIFO buffer at a certain offset. ++ * The FIFO buffer is not modified. ++ * ++ * @param f AVFifoBuffer to peek at, f must be non-NULL ++ * @param offs an offset in bytes, its absolute value must be less ++ * than the used buffer size or the returned pointer will ++ * point outside to the buffer data. ++ * The used buffer size can be checked with av_fifo_size(). ++ */ ++static inline uint8_t *av_fifo_peek2(const AVFifoBuffer *f, int offs) + { + uint8_t *ptr = f->rptr + offs; + if (ptr >= f->end) +- ptr -= f->end - f->buffer; +- return *ptr; ++ ptr = f->buffer + (ptr - f->end); ++ else if (ptr < f->buffer) ++ ptr = f->end - (f->buffer - ptr); ++ return ptr; ++} ++ ++#if FF_API_AV_FIFO_PEEK ++/** ++ * @deprecated Use av_fifo_peek2() instead. ++ */ ++attribute_deprecated ++static inline uint8_t av_fifo_peek(AVFifoBuffer *f, int offs) ++{ ++ return *av_fifo_peek2(f, offs); + } ++#endif ++ + #endif /* AVUTIL_FIFO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/file.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/file.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/file.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/file.c 2012-05-14 14:08:55.303359484 +0200 +@@ -17,6 +17,7 @@ + */ + + #include "file.h" ++#include "log.h" + #include + #include + #include +@@ -47,7 +48,6 @@ + av_unused void *ptr; + off_t off_size; + char errbuf[128]; +- size_t max_size = HAVE_MMAP ? SIZE_MAX : FF_INTERNAL_MEM_TYPE_MAX_VALUE; + *bufptr = NULL; + + if (fd < 0) { +@@ -66,7 +66,7 @@ + } + + off_size = st.st_size; +- if (off_size > max_size) { ++ if (off_size > SIZE_MAX) { + av_log(&file_log_ctx, AV_LOG_ERROR, + "File size for file '%s' is too big\n", filename); + close(fd); +@@ -76,7 +76,7 @@ + + #if HAVE_MMAP + ptr = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); +- if ((int)(ptr) == -1) { ++ if (ptr == MAP_FAILED) { + err = AVERROR(errno); + av_strerror(err, errbuf, sizeof(errbuf)); + av_log(&file_log_ctx, AV_LOG_ERROR, "Error occurred in mmap(): %s\n", errbuf); +@@ -130,6 +130,52 @@ + #endif + } + ++int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx) { ++ FileLogContext file_log_ctx = { &file_log_ctx_class, log_offset, log_ctx }; ++ int fd=-1; ++#if !HAVE_MKSTEMP ++ void *ptr= tempnam(NULL, prefix); ++ if(!ptr) ++ ptr= tempnam(".", prefix); ++ *filename = av_strdup(ptr); ++#undef free ++ free(ptr); ++#else ++ size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */ ++ *filename = av_malloc(len); ++#endif ++ /* -----common section-----*/ ++ if (*filename == NULL) { ++ av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n"); ++ return AVERROR(ENOMEM); ++ } ++#if !HAVE_MKSTEMP ++# ifndef O_BINARY ++# define O_BINARY 0 ++# endif ++# ifndef O_EXCL ++# define O_EXCL 0 ++# endif ++ fd = open(*filename, O_RDWR | O_BINARY | O_CREAT | O_EXCL, 0600); ++#else ++ snprintf(*filename, len, "/tmp/%sXXXXXX", prefix); ++ fd = mkstemp(*filename); ++#ifdef _WIN32 ++ if (fd < 0) { ++ snprintf(*filename, len, "./%sXXXXXX", prefix); ++ fd = mkstemp(*filename); ++ } ++#endif ++#endif ++ /* -----common section-----*/ ++ if (fd < 0) { ++ int err = AVERROR(errno); ++ av_log(&file_log_ctx, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename); ++ return err; ++ } ++ return fd; /* success */ ++} ++ + #ifdef TEST + + #undef printf +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/file.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/file.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/file.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/file.h 2012-05-14 14:08:55.303359484 +0200 +@@ -22,7 +22,8 @@ + #include "avutil.h" + + /** +- * @file misc file utilities ++ * @file ++ * Misc file utilities. + */ + + /** +@@ -48,4 +49,13 @@ + */ + void av_file_unmap(uint8_t *bufptr, size_t size); + ++/** ++ * Wrapper to work around the lack of mkstemp() on mingw. ++ * Also, tries to create file in /tmp first, if possible. ++ * *prefix can be a character constant; *filename will be allocated internally. ++ * @return file descriptor of opened file (or -1 on error) ++ * and opened file name in **filename. ++ */ ++int av_tempfile(const char *prefix, char **filename, int log_offset, void *log_ctx); ++ + #endif /* AVUTIL_FILE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/imgutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/imgutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/imgutils.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/imgutils.c 2012-05-14 14:08:55.304359504 +0200 +@@ -0,0 +1,277 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * misc image utilities ++ */ ++ ++#include "imgutils.h" ++#include "internal.h" ++#include "log.h" ++#include "pixdesc.h" ++ ++void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], ++ const AVPixFmtDescriptor *pixdesc) ++{ ++ int i; ++ memset(max_pixsteps, 0, 4*sizeof(max_pixsteps[0])); ++ if (max_pixstep_comps) ++ memset(max_pixstep_comps, 0, 4*sizeof(max_pixstep_comps[0])); ++ ++ for (i = 0; i < 4; i++) { ++ const AVComponentDescriptor *comp = &(pixdesc->comp[i]); ++ if ((comp->step_minus1+1) > max_pixsteps[comp->plane]) { ++ max_pixsteps[comp->plane] = comp->step_minus1+1; ++ if (max_pixstep_comps) ++ max_pixstep_comps[comp->plane] = i; ++ } ++ } ++} ++ ++static inline ++int image_get_linesize(int width, int plane, ++ int max_step, int max_step_comp, ++ const AVPixFmtDescriptor *desc) ++{ ++ int s, shifted_w, linesize; ++ ++ if (width < 0) ++ return AVERROR(EINVAL); ++ s = (max_step_comp == 1 || max_step_comp == 2) ? desc->log2_chroma_w : 0; ++ shifted_w = ((width + (1 << s) - 1)) >> s; ++ if (shifted_w && max_step > INT_MAX / shifted_w) ++ return AVERROR(EINVAL); ++ linesize = max_step * shifted_w; ++ if (desc->flags & PIX_FMT_BITSTREAM) ++ linesize = (linesize + 7) >> 3; ++ return linesize; ++} ++ ++int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane) ++{ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ int max_step [4]; /* max pixel step for each plane */ ++ int max_step_comp[4]; /* the component for each plane which has the max pixel step */ ++ ++ if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) ++ return AVERROR(EINVAL); ++ ++ av_image_fill_max_pixsteps(max_step, max_step_comp, desc); ++ return image_get_linesize(width, plane, max_step[plane], max_step_comp[plane], desc); ++} ++ ++int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width) ++{ ++ int i, ret; ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ int max_step [4]; /* max pixel step for each plane */ ++ int max_step_comp[4]; /* the component for each plane which has the max pixel step */ ++ ++ memset(linesizes, 0, 4*sizeof(linesizes[0])); ++ ++ if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) ++ return AVERROR(EINVAL); ++ ++ av_image_fill_max_pixsteps(max_step, max_step_comp, desc); ++ for (i = 0; i < 4; i++) { ++ if ((ret = image_get_linesize(width, i, max_step[i], max_step_comp[i], desc)) < 0) ++ return ret; ++ linesizes[i] = ret; ++ } ++ ++ return 0; ++} ++ ++int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, ++ uint8_t *ptr, const int linesizes[4]) ++{ ++ int i, total_size, size[4], has_plane[4]; ++ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ memset(data , 0, sizeof(data[0])*4); ++ memset(size , 0, sizeof(size)); ++ memset(has_plane, 0, sizeof(has_plane)); ++ ++ if ((unsigned)pix_fmt >= PIX_FMT_NB || desc->flags & PIX_FMT_HWACCEL) ++ return AVERROR(EINVAL); ++ ++ data[0] = ptr; ++ if (linesizes[0] > (INT_MAX - 1024) / height) ++ return AVERROR(EINVAL); ++ size[0] = linesizes[0] * height; ++ ++ if (desc->flags & PIX_FMT_PAL) { ++ size[0] = (size[0] + 3) & ~3; ++ data[1] = ptr + size[0]; /* palette is stored here as 256 32 bits words */ ++ return size[0] + 256 * 4; ++ } ++ ++ for (i = 0; i < 4; i++) ++ has_plane[desc->comp[i].plane] = 1; ++ ++ total_size = size[0]; ++ for (i = 1; i < 4 && has_plane[i]; i++) { ++ int h, s = (i == 1 || i == 2) ? desc->log2_chroma_h : 0; ++ data[i] = data[i-1] + size[i-1]; ++ h = (height + (1 << s) - 1) >> s; ++ if (linesizes[i] > INT_MAX / h) ++ return AVERROR(EINVAL); ++ size[i] = h * linesizes[i]; ++ if (total_size > INT_MAX - size[i]) ++ return AVERROR(EINVAL); ++ total_size += size[i]; ++ } ++ ++ return total_size; ++} ++ ++int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt) ++{ ++ int i; ++ ++ for (i = 0; i < 256; i++) { ++ int r, g, b; ++ ++ switch (pix_fmt) { ++ case PIX_FMT_RGB8: ++ r = (i>>5 )*36; ++ g = ((i>>2)&7)*36; ++ b = (i&3 )*85; ++ break; ++ case PIX_FMT_BGR8: ++ b = (i>>6 )*85; ++ g = ((i>>3)&7)*36; ++ r = (i&7 )*36; ++ break; ++ case PIX_FMT_RGB4_BYTE: ++ r = (i>>3 )*255; ++ g = ((i>>1)&3)*85; ++ b = (i&1 )*255; ++ break; ++ case PIX_FMT_BGR4_BYTE: ++ b = (i>>3 )*255; ++ g = ((i>>1)&3)*85; ++ r = (i&1 )*255; ++ break; ++ case PIX_FMT_GRAY8: ++ r = b = g = i; ++ break; ++ default: ++ return AVERROR(EINVAL); ++ } ++ pal[i] = b + (g<<8) + (r<<16) + (0xFF<<24); ++ } ++ ++ return 0; ++} ++ ++int av_image_alloc(uint8_t *pointers[4], int linesizes[4], ++ int w, int h, enum PixelFormat pix_fmt, int align) ++{ ++ int i, ret; ++ uint8_t *buf; ++ ++ if ((ret = av_image_check_size(w, h, 0, NULL)) < 0) ++ return ret; ++ if ((ret = av_image_fill_linesizes(linesizes, pix_fmt, w)) < 0) ++ return ret; ++ ++ for (i = 0; i < 4; i++) ++ linesizes[i] = FFALIGN(linesizes[i], align); ++ ++ if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, NULL, linesizes)) < 0) ++ return ret; ++ buf = av_malloc(ret + align); ++ if (!buf) ++ return AVERROR(ENOMEM); ++ if ((ret = av_image_fill_pointers(pointers, pix_fmt, h, buf, linesizes)) < 0) { ++ av_free(buf); ++ return ret; ++ } ++ if (av_pix_fmt_descriptors[pix_fmt].flags & PIX_FMT_PAL) ++ ff_set_systematic_pal2((uint32_t*)pointers[1], pix_fmt); ++ ++ return ret; ++} ++ ++typedef struct ImgUtils { ++ const AVClass *class; ++ int log_offset; ++ void *log_ctx; ++} ImgUtils; ++ ++static const AVClass imgutils_class = { "IMGUTILS", av_default_item_name, NULL, LIBAVUTIL_VERSION_INT, offsetof(ImgUtils, log_offset), offsetof(ImgUtils, log_ctx) }; ++ ++int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx) ++{ ++ ImgUtils imgutils = { &imgutils_class, log_offset, log_ctx }; ++ ++ if ((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8) ++ return 0; ++ ++ av_log(&imgutils, AV_LOG_ERROR, "Picture size %ux%u is invalid\n", w, h); ++ return AVERROR(EINVAL); ++} ++ ++void av_image_copy_plane(uint8_t *dst, int dst_linesize, ++ const uint8_t *src, int src_linesize, ++ int bytewidth, int height) ++{ ++ if (!dst || !src) ++ return; ++ for (;height > 0; height--) { ++ memcpy(dst, src, bytewidth); ++ dst += dst_linesize; ++ src += src_linesize; ++ } ++} ++ ++void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], ++ const uint8_t *src_data[4], const int src_linesizes[4], ++ enum PixelFormat pix_fmt, int width, int height) ++{ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ ++ if (desc->flags & PIX_FMT_HWACCEL) ++ return; ++ ++ if (desc->flags & PIX_FMT_PAL) { ++ av_image_copy_plane(dst_data[0], dst_linesizes[0], ++ src_data[0], src_linesizes[0], ++ width, height); ++ /* copy the palette */ ++ memcpy(dst_data[1], src_data[1], 4*256); ++ } else { ++ int i, planes_nb = 0; ++ ++ for (i = 0; i < desc->nb_components; i++) ++ planes_nb = FFMAX(planes_nb, desc->comp[i].plane + 1); ++ ++ for (i = 0; i < planes_nb; i++) { ++ int h = height; ++ int bwidth = av_image_get_linesize(pix_fmt, width, i); ++ if (i == 1 || i == 2) { ++ h= -((-height)>>desc->log2_chroma_h); ++ } ++ av_image_copy_plane(dst_data[i], dst_linesizes[i], ++ src_data[i], src_linesizes[i], ++ bwidth, h); ++ } ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/imgutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/imgutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/imgutils.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/imgutils.h 2012-05-14 14:08:55.305359524 +0200 +@@ -0,0 +1,138 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVUTIL_IMGUTILS_H ++#define AVUTIL_IMGUTILS_H ++ ++/** ++ * @file ++ * misc image utilities ++ * ++ * @addtogroup lavu_picture ++ * @{ ++ */ ++ ++#include "avutil.h" ++#include "pixdesc.h" ++ ++/** ++ * Compute the max pixel step for each plane of an image with a ++ * format described by pixdesc. ++ * ++ * The pixel step is the distance in bytes between the first byte of ++ * the group of bytes which describe a pixel component and the first ++ * byte of the successive group in the same plane for the same ++ * component. ++ * ++ * @param max_pixsteps an array which is filled with the max pixel step ++ * for each plane. Since a plane may contain different pixel ++ * components, the computed max_pixsteps[plane] is relative to the ++ * component in the plane with the max pixel step. ++ * @param max_pixstep_comps an array which is filled with the component ++ * for each plane which has the max pixel step. May be NULL. ++ */ ++void av_image_fill_max_pixsteps(int max_pixsteps[4], int max_pixstep_comps[4], ++ const AVPixFmtDescriptor *pixdesc); ++ ++/** ++ * Compute the size of an image line with format pix_fmt and width ++ * width for the plane plane. ++ * ++ * @return the computed size in bytes ++ */ ++int av_image_get_linesize(enum PixelFormat pix_fmt, int width, int plane); ++ ++/** ++ * Fill plane linesizes for an image with pixel format pix_fmt and ++ * width width. ++ * ++ * @param linesizes array to be filled with the linesize for each plane ++ * @return >= 0 in case of success, a negative error code otherwise ++ */ ++int av_image_fill_linesizes(int linesizes[4], enum PixelFormat pix_fmt, int width); ++ ++/** ++ * Fill plane data pointers for an image with pixel format pix_fmt and ++ * height height. ++ * ++ * @param data pointers array to be filled with the pointer for each image plane ++ * @param ptr the pointer to a buffer which will contain the image ++ * @param linesizes the array containing the linesize for each ++ * plane, should be filled by av_image_fill_linesizes() ++ * @return the size in bytes required for the image buffer, a negative ++ * error code in case of failure ++ */ ++int av_image_fill_pointers(uint8_t *data[4], enum PixelFormat pix_fmt, int height, ++ uint8_t *ptr, const int linesizes[4]); ++ ++/** ++ * Allocate an image with size w and h and pixel format pix_fmt, and ++ * fill pointers and linesizes accordingly. ++ * The allocated image buffer has to be freed by using ++ * av_freep(&pointers[0]). ++ * ++ * @param align the value to use for buffer size alignment ++ * @return the size in bytes required for the image buffer, a negative ++ * error code in case of failure ++ */ ++int av_image_alloc(uint8_t *pointers[4], int linesizes[4], ++ int w, int h, enum PixelFormat pix_fmt, int align); ++ ++/** ++ * Copy image plane from src to dst. ++ * That is, copy "height" number of lines of "bytewidth" bytes each. ++ * The first byte of each successive line is separated by *_linesize ++ * bytes. ++ * ++ * @param dst_linesize linesize for the image plane in dst ++ * @param src_linesize linesize for the image plane in src ++ */ ++void av_image_copy_plane(uint8_t *dst, int dst_linesize, ++ const uint8_t *src, int src_linesize, ++ int bytewidth, int height); ++ ++/** ++ * Copy image in src_data to dst_data. ++ * ++ * @param dst_linesizes linesizes for the image in dst_data ++ * @param src_linesizes linesizes for the image in src_data ++ */ ++void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], ++ const uint8_t *src_data[4], const int src_linesizes[4], ++ enum PixelFormat pix_fmt, int width, int height); ++ ++/** ++ * Check if the given dimension of an image is valid, meaning that all ++ * bytes of the image can be addressed with a signed int. ++ * ++ * @param w the width of the picture ++ * @param h the height of the picture ++ * @param log_offset the offset to sum to the log level for logging with log_ctx ++ * @param log_ctx the parent logging context, it may be NULL ++ * @return >= 0 if valid, a negative error code otherwise ++ */ ++int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx); ++ ++int ff_set_systematic_pal2(uint32_t pal[256], enum PixelFormat pix_fmt); ++ ++/** ++ * @} ++ */ ++ ++ ++#endif /* AVUTIL_IMGUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/internal.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/internal.h 2012-05-14 14:08:55.306359544 +0200 +@@ -37,9 +37,16 @@ + #include "config.h" + #include "attributes.h" + #include "timer.h" ++#include "cpu.h" ++#include "dict.h" ++ ++struct AVDictionary { ++ int count; ++ AVDictionaryEntry *elems; ++}; + + #ifndef attribute_align_arg +-#if ARCH_X86_32 && (!defined(__ICC) || __ICC > 1200) && AV_GCC_VERSION_AT_LEAST(4,2) ++#if ARCH_X86_32 && AV_GCC_VERSION_AT_LEAST(4,2) + # define attribute_align_arg __attribute__((force_align_arg_pointer)) + #else + # define attribute_align_arg +@@ -137,9 +144,10 @@ + #define sprintf sprintf_is_forbidden_due_to_security_issues_use_snprintf + #undef strcat + #define strcat strcat_is_forbidden_due_to_security_issues_use_av_strlcat ++#undef strncpy ++#define strncpy strncpy_is_forbidden_due_to_security_issues_use_av_strlcpy + #undef exit + #define exit exit_is_forbidden +-#ifndef LIBAVFORMAT_BUILD + #undef printf + #define printf please_use_av_log_instead_of_printf + #undef fprintf +@@ -148,7 +156,10 @@ + #define puts please_use_av_log_instead_of_puts + #undef perror + #define perror please_use_av_log_instead_of_perror +-#endif ++#undef strcasecmp ++#define strcasecmp please_use_av_strcasecmp ++#undef strncasecmp ++#define strncasecmp please_use_av_strncasecmp + + #define FF_ALLOC_OR_GOTO(ctx, p, size, label)\ + {\ +@@ -181,7 +192,6 @@ + # define NULL_IF_CONFIG_SMALL(x) x + #endif + +- + /** + * Define a function with only the non-default version specified. + * +@@ -210,4 +220,30 @@ + type ff_##name args + #endif + ++/** ++ * Return NULL if a threading library has not been enabled. ++ * Used to disable threading functions in AVCodec definitions ++ * when not needed. ++ */ ++#if HAVE_THREADS ++# define ONLY_IF_THREADS_ENABLED(x) x ++#else ++# define ONLY_IF_THREADS_ENABLED(x) NULL ++#endif ++ ++#if HAVE_MMX ++/** ++ * Empty mmx state. ++ * this must be called between any dsp function and float/double code. ++ * for example sin(); dsp->idct_put(); emms_c(); cos() ++ */ ++static av_always_inline void emms_c(void) ++{ ++ if(av_get_cpu_flags() & AV_CPU_FLAG_MMX) ++ __asm__ volatile ("emms" ::: "memory"); ++} ++#else /* HAVE_MMX */ ++#define emms_c() ++#endif /* HAVE_MMX */ ++ + #endif /* AVUTIL_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat.h 2012-05-14 14:08:55.306359544 +0200 +@@ -0,0 +1,73 @@ ++/* ++ * Copyright (c) 2011 Mans Rullgard ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVUTIL_INTFLOAT_H ++#define AVUTIL_INTFLOAT_H ++ ++#include ++#include "attributes.h" ++ ++union av_intfloat32 { ++ uint32_t i; ++ float f; ++}; ++ ++union av_intfloat64 { ++ uint64_t i; ++ double f; ++}; ++ ++/** ++ * Reinterpret a 32-bit integer as a float. ++ */ ++static av_always_inline float av_int2float(uint32_t i) ++{ ++ union av_intfloat32 v = { .i = i }; ++ return v.f; ++} ++ ++/** ++ * Reinterpret a float as a 32-bit integer. ++ */ ++static av_always_inline uint32_t av_float2int(float f) ++{ ++ union av_intfloat32 v = { .f = f }; ++ return v.i; ++} ++ ++/** ++ * Reinterpret a 64-bit integer as a double. ++ */ ++static av_always_inline double av_int2double(uint64_t i) ++{ ++ union av_intfloat64 v = { .i = i }; ++ return v.f; ++} ++ ++/** ++ * Reinterpret a double as a 64-bit integer. ++ */ ++static av_always_inline uint64_t av_double2int(double f) ++{ ++ union av_intfloat64 v = { .f = f }; ++ return v.i; ++} ++ ++#endif /* AVUTIL_INTFLOAT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat_readwrite.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat_readwrite.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat_readwrite.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat_readwrite.c 2012-05-14 14:08:55.307359564 +0200 +@@ -30,13 +30,13 @@ + #include "intfloat_readwrite.h" + + double av_int2dbl(int64_t v){ +- if(v+v > 0xFFEULL<<52) ++ if((uint64_t)v+v > 0xFFEULL<<52) + return NAN; + return ldexp(((v&((1LL<<52)-1)) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); + } + + float av_int2flt(int32_t v){ +- if(v+v > 0xFF000000U) ++ if((uint32_t)v+v > 0xFF000000U) + return NAN; + return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat_readwrite.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat_readwrite.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intfloat_readwrite.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intfloat_readwrite.h 2012-05-14 14:08:55.307359564 +0200 +@@ -30,11 +30,11 @@ + uint8_t mantissa[8]; + } AVExtFloat; + +-double av_int2dbl(int64_t v) av_const; +-float av_int2flt(int32_t v) av_const; +-double av_ext2dbl(const AVExtFloat ext) av_const; +-int64_t av_dbl2int(double d) av_const; +-int32_t av_flt2int(float d) av_const; +-AVExtFloat av_dbl2ext(double d) av_const; ++attribute_deprecated double av_int2dbl(int64_t v) av_const; ++attribute_deprecated float av_int2flt(int32_t v) av_const; ++attribute_deprecated double av_ext2dbl(const AVExtFloat ext) av_const; ++attribute_deprecated int64_t av_dbl2int(double d) av_const; ++attribute_deprecated int32_t av_flt2int(float d) av_const; ++attribute_deprecated AVExtFloat av_dbl2ext(double d) av_const; + + #endif /* AVUTIL_INTFLOAT_READWRITE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intmath.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intmath.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intmath.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intmath.h 2012-05-14 14:08:55.308359584 +0200 +@@ -25,6 +25,11 @@ + #include "config.h" + #include "attributes.h" + ++/** ++ * @addtogroup lavu_internal ++ * @{ ++ */ ++ + extern const uint32_t ff_inverse[257]; + + #if ARCH_ARM +@@ -76,4 +81,7 @@ + return b - (a < b * b); + } + ++/** ++ * @} ++ */ + #endif /* AVUTIL_INTMATH_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intreadwrite.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intreadwrite.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/intreadwrite.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/intreadwrite.h 2012-05-14 14:08:55.309359604 +0200 +@@ -229,11 +229,11 @@ + #endif + + #ifndef AV_RB32 +-# define AV_RB32(x) \ +- ((((const uint8_t*)(x))[0] << 24) | \ +- (((const uint8_t*)(x))[1] << 16) | \ +- (((const uint8_t*)(x))[2] << 8) | \ +- ((const uint8_t*)(x))[3]) ++# define AV_RB32(x) \ ++ (((uint32_t)((const uint8_t*)(x))[0] << 24) | \ ++ (((const uint8_t*)(x))[1] << 16) | \ ++ (((const uint8_t*)(x))[2] << 8) | \ ++ ((const uint8_t*)(x))[3]) + #endif + #ifndef AV_WB32 + # define AV_WB32(p, d) do { \ +@@ -245,11 +245,11 @@ + #endif + + #ifndef AV_RL32 +-# define AV_RL32(x) \ +- ((((const uint8_t*)(x))[3] << 24) | \ +- (((const uint8_t*)(x))[2] << 16) | \ +- (((const uint8_t*)(x))[1] << 8) | \ +- ((const uint8_t*)(x))[0]) ++# define AV_RL32(x) \ ++ (((uint32_t)((const uint8_t*)(x))[3] << 24) | \ ++ (((const uint8_t*)(x))[2] << 16) | \ ++ (((const uint8_t*)(x))[1] << 8) | \ ++ ((const uint8_t*)(x))[0]) + #endif + #ifndef AV_WL32 + # define AV_WL32(p, d) do { \ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/inverse.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/inverse.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/inverse.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/inverse.c 2012-05-14 14:08:55.309359604 +0200 +@@ -19,7 +19,7 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include "libavutil/intmath.h" ++#include + + /* a*inverse[b]>>32 == a/b for all 0<=a<=16909558 && 2<=b<=256 + * for a>16909558, is an overestimate by less than 1 part in 1<<24 */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lfg.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lfg.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lfg.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lfg.c 2012-05-14 14:08:55.310359625 +0200 +@@ -27,19 +27,21 @@ + #include "intreadwrite.h" + #include "attributes.h" + +-void av_cold av_lfg_init(AVLFG *c, unsigned int seed){ +- uint8_t tmp[16]={0}; ++void av_cold av_lfg_init(AVLFG *c, unsigned int seed) ++{ ++ uint8_t tmp[16] = { 0 }; + int i; + +- for(i=8; i<64; i+=4){ +- AV_WL32(tmp, seed); tmp[4]=i; +- av_md5_sum(tmp, tmp, 16); +- c->state[i ]= AV_RL32(tmp); +- c->state[i+1]= AV_RL32(tmp+4); +- c->state[i+2]= AV_RL32(tmp+8); +- c->state[i+3]= AV_RL32(tmp+12); ++ for (i = 8; i < 64; i += 4) { ++ AV_WL32(tmp, seed); ++ tmp[4] = i; ++ av_md5_sum(tmp, tmp, 16); ++ c->state[i ] = AV_RL32(tmp); ++ c->state[i + 1] = AV_RL32(tmp + 4); ++ c->state[i + 2] = AV_RL32(tmp + 8); ++ c->state[i + 3] = AV_RL32(tmp + 12); + } +- c->index=0; ++ c->index = 0; + } + + void av_bmg_get(AVLFG *lfg, double out[2]) +@@ -47,9 +49,9 @@ + double x1, x2, w; + + do { +- x1 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0; +- x2 = 2.0/UINT_MAX*av_lfg_get(lfg) - 1.0; +- w = x1*x1 + x2*x2; ++ x1 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0; ++ x2 = 2.0 / UINT_MAX * av_lfg_get(lfg) - 1.0; ++ w = x1 * x1 + x2 * x2; + } while (w >= 1.0); + + w = sqrt((-2.0 * log(w)) / w); +@@ -63,7 +65,7 @@ + + int main(void) + { +- int x=0; ++ int x = 0; + int i, j; + AVLFG state; + +@@ -71,8 +73,8 @@ + for (j = 0; j < 10000; j++) { + START_TIMER + for (i = 0; i < 624; i++) { +-// av_log(NULL,AV_LOG_ERROR, "%X\n", av_lfg_get(&state)); +- x+=av_lfg_get(&state); ++ //av_log(NULL, AV_LOG_ERROR, "%X\n", av_lfg_get(&state)); ++ x += av_lfg_get(&state); + } + STOP_TIMER("624 calls of av_lfg_get"); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lfg.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lfg.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lfg.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lfg.h 2012-05-14 14:08:55.311359645 +0200 +@@ -55,7 +55,7 @@ + * Get the next two numbers generated by a Box-Muller Gaussian + * generator using the random numbers issued by lfg. + * +- * @param out[2] array where the two generated numbers are placed ++ * @param out array where the two generated numbers are placed + */ + void av_bmg_get(AVLFG *lfg, double out[2]); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/libm.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/libm.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/libm.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/libm.h 2012-05-14 14:08:55.311359645 +0200 +@@ -28,6 +28,11 @@ + #include "config.h" + #include "attributes.h" + ++#if !HAVE_CBRTF ++#undef cbrtf ++#define cbrtf(x) powf(x, 1.0/3.0) ++#endif /* HAVE_CBRTF */ ++ + #if !HAVE_EXP2 + #undef exp2 + #define exp2(x) exp((x) * 0.693147180559945) +@@ -86,6 +91,13 @@ + } + #endif /* HAVE_ROUNDF */ + ++#if !HAVE_TRUNC ++static av_always_inline av_const double trunc(double x) ++{ ++ return (x > 0) ? floor(x) : ceil(x); ++} ++#endif /* HAVE_TRUNC */ ++ + #if !HAVE_TRUNCF + static av_always_inline av_const float truncf(float x) + { +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lls.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lls.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lls.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lls.c 2012-05-14 14:08:55.312359665 +0200 +@@ -30,105 +30,123 @@ + + #include "lls.h" + +-void av_init_lls(LLSModel *m, int indep_count){ ++void av_init_lls(LLSModel *m, int indep_count) ++{ + memset(m, 0, sizeof(LLSModel)); +- +- m->indep_count= indep_count; ++ m->indep_count = indep_count; + } + +-void av_update_lls(LLSModel *m, double *var, double decay){ +- int i,j; ++void av_update_lls(LLSModel *m, double *var, double decay) ++{ ++ int i, j; + +- for(i=0; i<=m->indep_count; i++){ +- for(j=i; j<=m->indep_count; j++){ ++ for (i = 0; i <= m->indep_count; i++) { ++ for (j = i; j <= m->indep_count; j++) { + m->covariance[i][j] *= decay; +- m->covariance[i][j] += var[i]*var[j]; ++ m->covariance[i][j] += var[i] * var[j]; + } + } + } + +-void av_solve_lls(LLSModel *m, double threshold, int min_order){ +- int i,j,k; +- double (*factor)[MAX_VARS+1]= (void*)&m->covariance[1][0]; +- double (*covar )[MAX_VARS+1]= (void*)&m->covariance[1][1]; +- double *covar_y = m->covariance[0]; +- int count= m->indep_count; +- +- for(i=0; i=0; k--) +- sum -= factor[i][k]*factor[j][k]; +- +- if(i==j){ +- if(sum < threshold) +- sum= 1.0; +- factor[i][i]= sqrt(sum); +- }else +- factor[j][i]= sum / factor[i][i]; ++void av_solve_lls(LLSModel *m, double threshold, int min_order) ++{ ++ int i, j, k; ++ double (*factor)[MAX_VARS + 1] = (void *) &m->covariance[1][0]; ++ double (*covar) [MAX_VARS + 1] = (void *) &m->covariance[1][1]; ++ double *covar_y = m->covariance[0]; ++ int count = m->indep_count; ++ ++ for (i = 0; i < count; i++) { ++ for (j = i; j < count; j++) { ++ double sum = covar[i][j]; ++ ++ for (k = i - 1; k >= 0; k--) ++ sum -= factor[i][k] * factor[j][k]; ++ ++ if (i == j) { ++ if (sum < threshold) ++ sum = 1.0; ++ factor[i][i] = sqrt(sum); ++ } else { ++ factor[j][i] = sum / factor[i][i]; ++ } + } + } +- for(i=0; i=0; k--) +- sum -= factor[i][k]*m->coeff[0][k]; +- m->coeff[0][i]= sum / factor[i][i]; ++ ++ for (i = 0; i < count; i++) { ++ double sum = covar_y[i + 1]; ++ ++ for (k = i - 1; k >= 0; k--) ++ sum -= factor[i][k] * m->coeff[0][k]; ++ ++ m->coeff[0][i] = sum / factor[i][i]; + } + +- for(j=count-1; j>=min_order; j--){ +- for(i=j; i>=0; i--){ +- double sum= m->coeff[0][i]; +- for(k=i+1; k<=j; k++) +- sum -= factor[k][i]*m->coeff[j][k]; +- m->coeff[j][i]= sum / factor[i][i]; ++ for (j = count - 1; j >= min_order; j--) { ++ for (i = j; i >= 0; i--) { ++ double sum = m->coeff[0][i]; ++ ++ for (k = i + 1; k <= j; k++) ++ sum -= factor[k][i] * m->coeff[j][k]; ++ ++ m->coeff[j][i] = sum / factor[i][i]; + } + +- m->variance[j]= covar_y[0]; +- for(i=0; i<=j; i++){ +- double sum= m->coeff[j][i]*covar[i][i] - 2*covar_y[i+1]; +- for(k=0; kcoeff[j][k]*covar[k][i]; +- m->variance[j] += m->coeff[j][i]*sum; ++ m->variance[j] = covar_y[0]; ++ ++ for (i = 0; i <= j; i++) { ++ double sum = m->coeff[j][i] * covar[i][i] - 2 * covar_y[i + 1]; ++ ++ for (k = 0; k < i; k++) ++ sum += 2 * m->coeff[j][k] * covar[k][i]; ++ ++ m->variance[j] += m->coeff[j][i] * sum; + } + } + } + +-double av_evaluate_lls(LLSModel *m, double *param, int order){ ++double av_evaluate_lls(LLSModel *m, double *param, int order) ++{ + int i; +- double out= 0; ++ double out = 0; + +- for(i=0; i<=order; i++) +- out+= param[i]*m->coeff[order][i]; ++ for (i = 0; i <= order; i++) ++ out += param[i] * m->coeff[order][i]; + + return out; + } + + #ifdef TEST + +-#include + #include ++#include ++#include "lfg.h" + +-int main(void){ ++int main(void) ++{ + LLSModel m; + int i, order; ++ AVLFG lfg; + ++ av_lfg_init(&lfg, 1); + av_init_lls(&m, 3); + +- for(i=0; i<100; i++){ ++ for (i = 0; i < 100; i++) { + double var[4]; + double eval; +- var[0] = (rand() / (double)RAND_MAX - 0.5)*2; +- var[1] = var[0] + rand() / (double)RAND_MAX - 0.5; +- var[2] = var[1] + rand() / (double)RAND_MAX - 0.5; +- var[3] = var[2] + rand() / (double)RAND_MAX - 0.5; ++ ++ var[0] = (av_lfg_get(&lfg) / (double) UINT_MAX - 0.5) * 2; ++ var[1] = var[0] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; ++ var[2] = var[1] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; ++ var[3] = var[2] + av_lfg_get(&lfg) / (double) UINT_MAX - 0.5; + av_update_lls(&m, var, 0.99); + av_solve_lls(&m, 0.001, 0); +- for(order=0; order<3; order++){ +- eval= av_evaluate_lls(&m, var+1, order); ++ for (order = 0; order < 3; order++) { ++ eval = av_evaluate_lls(&m, var + 1, order); + printf("real:%9f order:%d pred:%9f var:%f coeffs:%f %9f %9f\n", +- var[0], order, eval, sqrt(m.variance[order] / (i+1)), +- m.coeff[order][0], m.coeff[order][1], m.coeff[order][2]); ++ var[0], order, eval, sqrt(m.variance[order] / (i + 1)), ++ m.coeff[order][0], m.coeff[order][1], ++ m.coeff[order][2]); + } + } + return 0; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/log.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/log.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/log.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/log.c 2012-05-14 14:08:55.313359685 +0200 +@@ -29,111 +29,136 @@ + #include "avutil.h" + #include "log.h" + +-#if LIBAVUTIL_VERSION_MAJOR > 50 +-static +-#endif +-int av_log_level = AV_LOG_INFO; ++static int av_log_level = AV_LOG_INFO; + static int flags; + + #if defined(_WIN32) && !defined(__MINGW32CE__) + #include +-static const uint8_t color[] = {12,12,12,14,7,7,7}; ++static const uint8_t color[] = { 12, 12, 12, 14, 7, 7, 10 }; + static int16_t background, attr_orig; + static HANDLE con; + #define set_color(x) SetConsoleTextAttribute(con, background | color[x]) + #define reset_color() SetConsoleTextAttribute(con, attr_orig) + #else +-static const uint8_t color[]={0x41,0x41,0x11,0x03,9,9,9}; +-#define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x]>>4, color[x]&15) ++static const uint8_t color[] = { 0x41, 0x41, 0x11, 0x03, 9, 9, 2 }; ++#define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x] >> 4, color[x]&15) + #define reset_color() fprintf(stderr, "\033[0m") + #endif +-static int use_color=-1; ++static int use_color = -1; + + #undef fprintf +-static void colored_fputs(int level, const char *str){ +- if(use_color<0){ ++static void colored_fputs(int level, const char *str) ++{ ++ if (use_color < 0) { + #if defined(_WIN32) && !defined(__MINGW32CE__) + CONSOLE_SCREEN_BUFFER_INFO con_info; + con = GetStdHandle(STD_ERROR_HANDLE); +- use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); ++ use_color = (con != INVALID_HANDLE_VALUE) && !getenv("NO_COLOR") && ++ !getenv("AV_LOG_FORCE_NOCOLOR"); + if (use_color) { + GetConsoleScreenBufferInfo(con, &con_info); + attr_orig = con_info.wAttributes; + background = attr_orig & 0xF0; + } + #elif HAVE_ISATTY +- use_color= !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR") && +- (getenv("TERM") && isatty(2) || getenv("FFMPEG_FORCE_COLOR")); ++ use_color = !getenv("NO_COLOR") && !getenv("AV_LOG_FORCE_NOCOLOR") && ++ (getenv("TERM") && isatty(2) || ++ getenv("AV_LOG_FORCE_COLOR")); + #else +- use_color= getenv("FFMPEG_FORCE_COLOR") && !getenv("NO_COLOR") && !getenv("FFMPEG_FORCE_NOCOLOR"); ++ use_color = getenv("AV_LOG_FORCE_COLOR") && !getenv("NO_COLOR") && ++ !getenv("AV_LOG_FORCE_NOCOLOR"); + #endif + } + +- if(use_color){ ++ if (use_color) { + set_color(level); + } + fputs(str, stderr); +- if(use_color){ ++ if (use_color) { + reset_color(); + } + } + +-const char* av_default_item_name(void* ptr){ +- return (*(AVClass**)ptr)->class_name; ++const char *av_default_item_name(void *ptr) ++{ ++ return (*(AVClass **) ptr)->class_name; + } + +-void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) ++static void sanitize(uint8_t *line){ ++ while(*line){ ++ if(*line < 0x08 || (*line > 0x0D && *line < 0x20)) ++ *line='?'; ++ line++; ++ } ++} ++ ++void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, ++ char *line, int line_size, int *print_prefix) + { +- static int print_prefix=1; +- static int count; +- static char line[1024], prev[1024]; +- static int is_atty; +- AVClass* avc= ptr ? *(AVClass**)ptr : NULL; +- if(level>av_log_level) +- return; +- line[0]=0; +-#undef fprintf +- if(print_prefix && avc) { +- if(avc->version >= (50<<16 | 15<<8 | 3) && avc->parent_log_context_offset){ +- AVClass** parent= *(AVClass***)(((uint8_t*)ptr) + avc->parent_log_context_offset); +- if(parent && *parent){ +- snprintf(line, sizeof(line), "[%s @ %p] ", (*parent)->item_name(parent), parent); ++ AVClass* avc = ptr ? *(AVClass **) ptr : NULL; ++ line[0] = 0; ++ if (*print_prefix && avc) { ++ if (avc->parent_log_context_offset) { ++ AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) + ++ avc->parent_log_context_offset); ++ if (parent && *parent) { ++ snprintf(line, line_size, "[%s @ %p] ", ++ (*parent)->item_name(parent), parent); + } + } +- snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ", avc->item_name(ptr), ptr); ++ snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ", ++ avc->item_name(ptr), ptr); + } + +- vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl); ++ vsnprintf(line + strlen(line), line_size - strlen(line), fmt, vl); ++ ++ *print_prefix = strlen(line) && line[strlen(line) - 1] == '\n'; ++} ++ ++void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) ++{ ++ static int print_prefix = 1; ++ static int count; ++ static char prev[1024]; ++ char line[1024]; ++ static int is_atty; + +- print_prefix= line[strlen(line)-1] == '\n'; ++ if (level > av_log_level) ++ return; ++ av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix); + + #if HAVE_ISATTY +- if(!is_atty) is_atty= isatty(2) ? 1 : -1; ++ if (!is_atty) ++ is_atty = isatty(2) ? 1 : -1; + #endif + +- if(print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ ++#undef fprintf ++ if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){ + count++; +- if(is_atty==1) ++ if (is_atty == 1) + fprintf(stderr, " Last message repeated %d times\r", count); + return; + } +- if(count>0){ ++ if (count > 0) { + fprintf(stderr, " Last message repeated %d times\n", count); +- count=0; ++ count = 0; + } +- colored_fputs(av_clip(level>>3, 0, 6), line); + strcpy(prev, line); ++ sanitize(line); ++ colored_fputs(av_clip(level >> 3, 0, 6), line); + } + +-static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; ++static void (*av_log_callback)(void*, int, const char*, va_list) = ++ av_log_default_callback; + + void av_log(void* avcl, int level, const char *fmt, ...) + { +- AVClass* avc= avcl ? *(AVClass**)avcl : NULL; ++ AVClass* avc = avcl ? *(AVClass **) avcl : NULL; + va_list vl; + va_start(vl, fmt); +- if(avc && avc->version >= (50<<16 | 15<<8 | 2) && avc->log_level_offset_offset && level>=AV_LOG_FATAL) +- level += *(int*)(((uint8_t*)avcl) + avc->log_level_offset_offset); ++ if (avc && avc->version >= (50 << 16 | 15 << 8 | 2) && ++ avc->log_level_offset_offset && level >= AV_LOG_FATAL) ++ level += *(int *) (((uint8_t *) avcl) + avc->log_level_offset_offset); + av_vlog(avcl, level, fmt, vl); + va_end(vl); + } +@@ -155,7 +180,7 @@ + + void av_log_set_flags(int arg) + { +- flags= arg; ++ flags = arg; + } + + void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/log.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/log.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/log.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/log.h 2012-05-14 14:08:55.314359705 +0200 +@@ -23,13 +23,14 @@ + + #include + #include "avutil.h" ++#include "attributes.h" + + /** + * Describe the class of an AVClass context structure. That is an + * arbitrary struct of which the first field is a pointer to an + * AVClass struct (e.g. AVCodecContext, AVFormatContext etc.). + */ +-typedef struct { ++typedef struct AVClass { + /** + * The name of the class; usually it is the same name as the + * context structure type to which the AVClass is associated. +@@ -70,6 +71,21 @@ + * can be NULL of course + */ + int parent_log_context_offset; ++ ++ /** ++ * Return next AVOptions-enabled child or NULL ++ */ ++ void* (*child_next)(void *obj, void *prev); ++ ++ /** ++ * Return an AVClass corresponding to next potential ++ * AVOptions-enabled child. ++ * ++ * The difference between child_next and this is that ++ * child_next iterates over _already existing_ objects, while ++ * child_class_next iterates over _all possible_ children. ++ */ ++ const struct AVClass* (*child_class_next)(const struct AVClass *prev); + } AVClass; + + /* av_log API */ +@@ -122,11 +138,7 @@ + * subsequent arguments are converted to output. + * @see av_vlog + */ +-#ifdef __GNUC__ +-void av_log(void *avcl, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); +-#else +-void av_log(void *avcl, int level, const char *fmt, ...); +-#endif ++void av_log(void *avcl, int level, const char *fmt, ...) av_printf_format(3, 4); + + void av_vlog(void *avcl, int level, const char *fmt, va_list); + int av_log_get_level(void); +@@ -136,6 +148,16 @@ + const char* av_default_item_name(void* ctx); + + /** ++ * Format a line of log the same way as the default callback. ++ * @param line buffer to receive the formated line ++ * @param line_size size of the buffer ++ * @param print_prefix used to store whether the prefix must be printed; ++ * must point to a persistent integer initially set to 1 ++ */ ++void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, ++ char *line, int line_size, int *print_prefix); ++ ++/** + * av_dlog macros + * Useful to print debug messages that shouldn't get compiled in normally. + */ +@@ -143,7 +165,7 @@ + #ifdef DEBUG + # define av_dlog(pctx, ...) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__) + #else +-# define av_dlog(pctx, ...) ++# define av_dlog(pctx, ...) do { if (0) av_log(pctx, AV_LOG_DEBUG, __VA_ARGS__); } while (0) + #endif + + /** +@@ -152,7 +174,7 @@ + * "Last message repeated x times" messages below (f)printf messages with some + * bad luck. + * Also to receive the last, "last repeated" line if any, the user app must +- * call av_log(NULL, AV_LOG_QUIET, ""); at the end ++ * call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end + */ + #define AV_LOG_SKIP_REPEATED 1 + void av_log_set_flags(int arg); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lzo.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lzo.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lzo.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lzo.c 2012-05-14 14:08:55.315359725 +0200 +@@ -21,14 +21,14 @@ + + #include "avutil.h" + #include "common.h" +-//! Avoid e.g. MPlayers fast_memcpy, it slows things down here. ++/// Avoid e.g. MPlayers fast_memcpy, it slows things down here. + #undef memcpy + #include + #include "lzo.h" + +-//! Define if we may write up to 12 bytes beyond the output buffer. ++/// Define if we may write up to 12 bytes beyond the output buffer. + #define OUTBUF_PADDED 1 +-//! Define if we may read up to 8 bytes beyond the input buffer. ++/// Define if we may read up to 8 bytes beyond the input buffer. + #define INBUF_PADDED 1 + typedef struct LZOContext { + const uint8_t *in, *in_end; +@@ -37,8 +37,8 @@ + } LZOContext; + + /** +- * \brief Reads one byte from the input buffer, avoiding an overrun. +- * \return byte read ++ * @brief Reads one byte from the input buffer, avoiding an overrun. ++ * @return byte read + */ + static inline int get_byte(LZOContext *c) { + if (c->in < c->in_end) +@@ -54,10 +54,10 @@ + #endif + + /** +- * \brief Decodes a length value in the coding used by lzo. +- * \param x previous byte value +- * \param mask bits used from x +- * \return decoded length value ++ * @brief Decodes a length value in the coding used by lzo. ++ * @param x previous byte value ++ * @param mask bits used from x ++ * @return decoded length value + */ + static inline int get_len(LZOContext *c, int x, int mask) { + int cnt = x & mask; +@@ -82,8 +82,8 @@ + #endif + + /** +- * \brief Copies bytes from input to output buffer with checking. +- * \param cnt number of bytes to copy, must be >= 0 ++ * @brief Copies bytes from input to output buffer with checking. ++ * @param cnt number of bytes to copy, must be >= 0 + */ + static inline void copy(LZOContext *c, int cnt) { + register const uint8_t *src = c->in; +@@ -111,9 +111,9 @@ + static inline void memcpy_backptr(uint8_t *dst, int back, int cnt); + + /** +- * \brief Copies previously decoded bytes to current position. +- * \param back how many bytes back we start +- * \param cnt number of bytes to copy, must be >= 0 ++ * @brief Copies previously decoded bytes to current position. ++ * @param back how many bytes back we start, must be > 0 ++ * @param cnt number of bytes to copy, must be >= 0 + * + * cnt > back is valid, this will copy the bytes we just copied, + * thus creating a repeating pattern with a period length of back. +@@ -135,7 +135,7 @@ + + static inline void memcpy_backptr(uint8_t *dst, int back, int cnt) { + const uint8_t *src = &dst[-back]; +- if (back == 1) { ++ if (back <= 1) { + memset(dst, *src, cnt); + } else { + #ifdef OUTBUF_PADDED +@@ -175,11 +175,11 @@ + int state= 0; + int x; + LZOContext c; +- if (!*outlen || !*inlen) { ++ if (*outlen <= 0 || *inlen <= 0) { + int res = 0; +- if (!*outlen) ++ if (*outlen <= 0) + res |= AV_LZO_OUTPUT_FULL; +- if (!*inlen) ++ if (*inlen <= 0) + res |= AV_LZO_INPUT_DEPLETED; + return res; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lzo.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lzo.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/lzo.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/lzo.h 2012-05-14 14:08:55.316359745 +0200 +@@ -22,30 +22,37 @@ + #ifndef AVUTIL_LZO_H + #define AVUTIL_LZO_H + ++/** ++ * @defgroup lavu_lzo LZO ++ * @ingroup lavu_crypto ++ * ++ * @{ ++ */ ++ + #include + +-/** \defgroup errflags Error flags returned by av_lzo1x_decode +- * \{ */ +-//! end of the input buffer reached before decoding finished ++/** @name Error flags returned by av_lzo1x_decode ++ * @{ */ ++/// end of the input buffer reached before decoding finished + #define AV_LZO_INPUT_DEPLETED 1 +-//! decoded data did not fit into output buffer ++/// decoded data did not fit into output buffer + #define AV_LZO_OUTPUT_FULL 2 +-//! a reference to previously decoded data was wrong ++/// a reference to previously decoded data was wrong + #define AV_LZO_INVALID_BACKPTR 4 +-//! a non-specific error in the compressed bitstream ++/// a non-specific error in the compressed bitstream + #define AV_LZO_ERROR 8 +-/** \} */ ++/** @} */ + + #define AV_LZO_INPUT_PADDING 8 + #define AV_LZO_OUTPUT_PADDING 12 + + /** +- * \brief Decodes LZO 1x compressed data. +- * \param out output buffer +- * \param outlen size of output buffer, number of bytes left are returned here +- * \param in input buffer +- * \param inlen size of input buffer, number of bytes left are returned here +- * \return 0 on success, otherwise a combination of the error flags above ++ * @brief Decodes LZO 1x compressed data. ++ * @param out output buffer ++ * @param outlen size of output buffer, number of bytes left are returned here ++ * @param in input buffer ++ * @param inlen size of input buffer, number of bytes left are returned here ++ * @return 0 on success, otherwise a combination of the error flags above + * + * Make sure all buffers are appropriately padded, in must provide + * AV_LZO_INPUT_PADDING, out must provide AV_LZO_OUTPUT_PADDING additional bytes. +@@ -53,14 +60,18 @@ + int av_lzo1x_decode(void *out, int *outlen, const void *in, int *inlen); + + /** +- * \brief deliberately overlapping memcpy implementation +- * \param dst destination buffer; must be padded with 12 additional bytes +- * \param back how many bytes back we start (the initial size of the overlapping window) +- * \param cnt number of bytes to copy, must be >= 0 ++ * @brief deliberately overlapping memcpy implementation ++ * @param dst destination buffer; must be padded with 12 additional bytes ++ * @param back how many bytes back we start (the initial size of the overlapping window), must be > 0 ++ * @param cnt number of bytes to copy, must be >= 0 + * + * cnt > back is valid, this will copy the bytes we just copied, + * thus creating a repeating pattern with a period length of back. + */ + void av_memcpy_backptr(uint8_t *dst, int back, int cnt); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_LZO_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/Makefile 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/Makefile 2012-05-14 14:08:55.276358940 +0200 +@@ -3,7 +3,9 @@ + NAME = avutil + + HEADERS = adler32.h \ ++ aes.h \ + attributes.h \ ++ audioconvert.h \ + avassert.h \ + avstring.h \ + avutil.h \ +@@ -16,6 +18,8 @@ + eval.h \ + fifo.h \ + file.h \ ++ imgutils.h \ ++ intfloat.h \ + intfloat_readwrite.h \ + intreadwrite.h \ + lfg.h \ +@@ -24,17 +28,21 @@ + mathematics.h \ + md5.h \ + mem.h \ ++ dict.h \ + opt.h \ ++ parseutils.h \ + pixdesc.h \ + pixfmt.h \ + random_seed.h \ + rational.h \ +- sha1.h \ ++ samplefmt.h \ ++ sha.h \ + + BUILT_HEADERS = avconfig.h + + OBJS = adler32.o \ + aes.o \ ++ audioconvert.o \ + avstring.o \ + base64.o \ + cpu.o \ +@@ -44,6 +52,7 @@ + eval.o \ + fifo.o \ + file.o \ ++ imgutils.o \ + intfloat_readwrite.o \ + inverse.o \ + lfg.o \ +@@ -53,11 +62,14 @@ + mathematics.o \ + md5.o \ + mem.o \ ++ dict.o \ + opt.o \ ++ parseutils.o \ + pixdesc.o \ + random_seed.o \ + rational.o \ + rc4.o \ ++ samplefmt.o \ + sha.o \ + tree.o \ + utils.o \ +@@ -66,13 +78,15 @@ + OBJS-$(ARCH_PPC) += ppc/cpu.o + OBJS-$(ARCH_X86) += x86/cpu.o + +-TESTPROGS = adler32 aes base64 cpu crc des lls md5 pca sha softfloat tree ++ ++TESTPROGS = adler32 aes avstring base64 cpu crc des eval file fifo lfg lls \ ++ md5 opt pca parseutils rational sha tree + TESTPROGS-$(HAVE_LZO1X_999_COMPRESS) += lzo + ++TOOLS = ffeval ++ + DIRS = arm bfin sh4 x86 + + ARCH_HEADERS = bswap.h intmath.h intreadwrite.h timer.h + +-include $(SUBDIR)../subdir.mak +- + $(SUBDIR)lzo-test$(EXESUF): ELIBS = -llzo2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mathematics.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mathematics.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mathematics.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mathematics.c 2012-05-14 14:08:55.316359745 +0200 +@@ -27,6 +27,7 @@ + #include + #include + #include "mathematics.h" ++#include "libavutil/common.h" + + const uint8_t ff_sqrt_tab[256]={ + 0, 16, 23, 28, 32, 36, 40, 43, 46, 48, 51, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90, +@@ -139,6 +140,8 @@ + int av_compare_ts(int64_t ts_a, AVRational tb_a, int64_t ts_b, AVRational tb_b){ + int64_t a= tb_a.num * (int64_t)tb_b.den; + int64_t b= tb_b.num * (int64_t)tb_a.den; ++ if((FFABS(ts_a)|a|FFABS(ts_b)|b)<=INT_MAX) ++ return (ts_a*a > ts_b*b) - (ts_a*a < ts_b*b); + if (av_rescale_rnd(ts_a, a, b, AV_ROUND_DOWN) < ts_b) return -1; + if (av_rescale_rnd(ts_b, b, a, AV_ROUND_DOWN) < ts_a) return 1; + return 0; +@@ -150,32 +153,3 @@ + c-= mod; + return c; + } +- +-#ifdef TEST +-#include "integer.h" +-#undef printf +-int main(void){ +- int64_t a,b,c,d,e; +- +- for(a=7; a<(1LL<<62); a+=a/3+1){ +- for(b=3; b<(1LL<<62); b+=b/4+1){ +- for(c=9; c<(1LL<<62); c+=(c*2)/5+3){ +- int64_t r= c/2; +- AVInteger ai; +- ai= av_mul_i(av_int2i(a), av_int2i(b)); +- ai= av_add_i(ai, av_int2i(r)); +- +- d= av_i2int(av_div_i(ai, av_int2i(c))); +- +- e= av_rescale(a,b,c); +- +- if((double)a * (double)b / (double)c > (1LL<<63)) +- continue; +- +- if(d!=e) printf("%"PRId64"*%"PRId64"/%"PRId64"= %"PRId64"=%"PRId64"\n", a, b, c, d, e); +- } +- } +- } +- return 0; +-} +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mathematics.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mathematics.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mathematics.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mathematics.h 2012-05-14 14:08:55.317359765 +0200 +@@ -57,6 +57,12 @@ + #define INFINITY (1.0/0.0) + #endif + ++/** ++ * @addtogroup lavu_math ++ * @{ ++ */ ++ ++ + enum AVRounding { + AV_ROUND_ZERO = 0, ///< Round toward zero. + AV_ROUND_INF = 1, ///< Round away from zero. +@@ -109,4 +115,8 @@ + */ + int64_t av_compare_mod(uint64_t a, uint64_t b, uint64_t mod); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_MATHEMATICS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/md5.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/md5.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/md5.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/md5.c 2012-05-14 14:08:55.318359786 +0200 +@@ -30,8 +30,9 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-#include ++#include + #include "bswap.h" ++#include "intreadwrite.h" + #include "md5.h" + + typedef struct AVMD5{ +@@ -40,7 +41,7 @@ + uint32_t ABCD[4]; + } AVMD5; + +-const int av_md5_size= sizeof(AVMD5); ++const int av_md5_size = sizeof(AVMD5); + + static const uint8_t S[4][4] = { + { 7, 12, 17, 22 }, /* round 1 */ +@@ -71,42 +72,49 @@ + 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391, + }; + +-#define CORE(i, a, b, c, d) \ +- t = S[i>>4][i&3];\ +- a += T[i];\ +-\ +- if(i<32){\ +- if(i<16) a += (d ^ (b&(c^d))) + X[ i &15 ];\ +- else a += (c ^ (d&(c^b))) + X[ (1+5*i)&15 ];\ +- }else{\ +- if(i<48) a += (b^c^d) + X[ (5+3*i)&15 ];\ +- else a += (c^(b|~d)) + X[ ( 7*i)&15 ];\ +- }\ +- a = b + (( a << t ) | ( a >> (32 - t) )); +- +-static void body(uint32_t ABCD[4], uint32_t X[16]){ ++#define CORE(i, a, b, c, d) do { \ ++ t = S[i >> 4][i & 3]; \ ++ a += T[i]; \ ++ \ ++ if (i < 32) { \ ++ if (i < 16) a += (d ^ (b & (c ^ d))) + X[ i & 15]; \ ++ else a += (c ^ (d & (c ^ b))) + X[(1 + 5*i) & 15]; \ ++ } else { \ ++ if (i < 48) a += (b ^ c ^ d) + X[(5 + 3*i) & 15]; \ ++ else a += (c ^ (b | ~d)) + X[( 7*i) & 15]; \ ++ } \ ++ a = b + (a << t | a >> (32 - t)); \ ++ } while (0) + ++static void body(uint32_t ABCD[4], uint32_t X[16]) ++{ + int t; + int i av_unused; +- unsigned int a= ABCD[3]; +- unsigned int b= ABCD[2]; +- unsigned int c= ABCD[1]; +- unsigned int d= ABCD[0]; ++ unsigned int a = ABCD[3]; ++ unsigned int b = ABCD[2]; ++ unsigned int c = ABCD[1]; ++ unsigned int d = ABCD[0]; + + #if HAVE_BIGENDIAN +- for(i=0; i<16; i++) +- X[i]= av_bswap32(X[i]); ++ for (i = 0; i < 16; i++) ++ X[i] = av_bswap32(X[i]); + #endif + + #if CONFIG_SMALL +- for( i = 0; i < 64; i++ ){ +- CORE(i,a,b,c,d) +- t=d; d=c; c=b; b=a; a=t; ++ for (i = 0; i < 64; i++) { ++ CORE(i, a, b, c, d); ++ t = d; ++ d = c; ++ c = b; ++ b = a; ++ a = t; + } + #else +-#define CORE2(i) CORE(i,a,b,c,d) CORE((i+1),d,a,b,c) CORE((i+2),c,d,a,b) CORE((i+3),b,c,d,a) +-#define CORE4(i) CORE2(i) CORE2((i+4)) CORE2((i+8)) CORE2((i+12)) +-CORE4(0) CORE4(16) CORE4(32) CORE4(48) ++#define CORE2(i) \ ++ CORE( i, a,b,c,d); CORE((i+1),d,a,b,c); \ ++ CORE((i+2),c,d,a,b); CORE((i+3),b,c,d,a) ++#define CORE4(i) CORE2(i); CORE2((i+4)); CORE2((i+8)); CORE2((i+12)) ++ CORE4(0); CORE4(16); CORE4(32); CORE4(48); + #endif + + ABCD[0] += d; +@@ -115,8 +123,9 @@ + ABCD[3] += a; + } + +-void av_md5_init(AVMD5 *ctx){ +- ctx->len = 0; ++void av_md5_init(AVMD5 *ctx) ++{ ++ ctx->len = 0; + + ctx->ABCD[0] = 0x10325476; + ctx->ABCD[1] = 0x98badcfe; +@@ -124,59 +133,72 @@ + ctx->ABCD[3] = 0x67452301; + } + +-void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len){ ++void av_md5_update(AVMD5 *ctx, const uint8_t *src, const int len) ++{ + int i, j; + +- j= ctx->len & 63; ++ j = ctx->len & 63; + ctx->len += len; + +- for( i = 0; i < len; i++ ){ ++ for (i = 0; i < len; i++) { + ctx->block[j++] = src[i]; +- if( 64 == j ){ +- body(ctx->ABCD, (uint32_t*) ctx->block); ++ if (j == 64) { ++ body(ctx->ABCD, (uint32_t *) ctx->block); + j = 0; + } + } + } + +-void av_md5_final(AVMD5 *ctx, uint8_t *dst){ ++void av_md5_final(AVMD5 *ctx, uint8_t *dst) ++{ + int i; +- uint64_t finalcount= av_le2ne64(ctx->len<<3); ++ uint64_t finalcount = av_le2ne64(ctx->len << 3); + + av_md5_update(ctx, "\200", 1); +- while((ctx->len & 63)!=56) ++ while ((ctx->len & 63) != 56) + av_md5_update(ctx, "", 1); + +- av_md5_update(ctx, (uint8_t*)&finalcount, 8); ++ av_md5_update(ctx, (uint8_t *)&finalcount, 8); + +- for(i=0; i<4; i++) +- ((uint32_t*)dst)[i]= av_le2ne32(ctx->ABCD[3-i]); ++ for (i = 0; i < 4; i++) ++ AV_WL32(dst + 4*i, ctx->ABCD[3 - i]); + } + +-void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len){ +- AVMD5 ctx[1]; ++void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len) ++{ ++ AVMD5 ctx; + +- av_md5_init(ctx); +- av_md5_update(ctx, src, len); +- av_md5_final(ctx, dst); ++ av_md5_init(&ctx); ++ av_md5_update(&ctx, src, len); ++ av_md5_final(&ctx, dst); + } + + #ifdef TEST +-#include +-#include + #undef printf ++#include ++ ++static void print_md5(uint8_t *md5) ++{ ++ int i; ++ for (i = 0; i < 16; i++) ++ printf("%02x", md5[i]); ++ printf("\n"); ++} ++ + int main(void){ +- uint64_t md5val; ++ uint8_t md5val[16]; + int i; + uint8_t in[1000]; + +- for(i=0; i<1000; i++) in[i]= i*i; +- av_md5_sum( (uint8_t*)&md5val, in, 1000); printf("%"PRId64"\n", md5val); +- av_md5_sum( (uint8_t*)&md5val, in, 63); printf("%"PRId64"\n", md5val); +- av_md5_sum( (uint8_t*)&md5val, in, 64); printf("%"PRId64"\n", md5val); +- av_md5_sum( (uint8_t*)&md5val, in, 65); printf("%"PRId64"\n", md5val); +- for(i=0; i<1000; i++) in[i]= i % 127; +- av_md5_sum( (uint8_t*)&md5val, in, 999); printf("%"PRId64"\n", md5val); ++ for (i = 0; i < 1000; i++) ++ in[i] = i * i; ++ av_md5_sum(md5val, in, 1000); print_md5(md5val); ++ av_md5_sum(md5val, in, 63); print_md5(md5val); ++ av_md5_sum(md5val, in, 64); print_md5(md5val); ++ av_md5_sum(md5val, in, 65); print_md5(md5val); ++ for (i = 0; i < 1000; i++) ++ in[i] = i % 127; ++ av_md5_sum(md5val, in, 999); print_md5(md5val); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/md5.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/md5.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/md5.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/md5.h 2012-05-14 14:08:55.318359786 +0200 +@@ -23,6 +23,12 @@ + + #include + ++/** ++ * @defgroup lavu_md5 MD5 ++ * @ingroup lavu_crypto ++ * @{ ++ */ ++ + extern const int av_md5_size; + + struct AVMD5; +@@ -32,5 +38,9 @@ + void av_md5_final(struct AVMD5 *ctx, uint8_t *dst); + void av_md5_sum(uint8_t *dst, const uint8_t *src, const int len); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_MD5_H */ + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mem.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mem.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mem.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mem.c 2012-05-14 14:08:55.319359806 +0200 +@@ -24,6 +24,8 @@ + * default memory allocator for libavutil + */ + ++#define _XOPEN_SOURCE 600 ++ + #include "config.h" + + #include +@@ -57,11 +59,19 @@ + + #endif /* MALLOC_PREFIX */ + ++#define ALIGN (HAVE_AVX ? 32 : 16) ++ + /* You can redefine av_malloc and av_free in your project to use your + memory allocator. You do not need to suppress this file because the + linker will do it automatically. */ + +-void *av_malloc(FF_INTERNAL_MEM_TYPE size) ++static size_t max_alloc_size= INT_MAX; ++ ++void av_max_alloc(size_t max){ ++ max_alloc_size = max; ++} ++ ++void *av_malloc(size_t size) + { + void *ptr = NULL; + #if CONFIG_MEMALIGN_HACK +@@ -69,21 +79,22 @@ + #endif + + /* let's disallow possible ambiguous cases */ +- if(size > (INT_MAX-16) ) ++ if (size > (max_alloc_size-32)) + return NULL; + + #if CONFIG_MEMALIGN_HACK +- ptr = malloc(size+16); ++ ptr = malloc(size+ALIGN); + if(!ptr) + return ptr; +- diff= ((-(long)ptr - 1)&15) + 1; ++ diff= ((-(long)ptr - 1)&(ALIGN-1)) + 1; + ptr = (char*)ptr + diff; + ((char*)ptr)[-1]= diff; + #elif HAVE_POSIX_MEMALIGN +- if (posix_memalign(&ptr,16,size)) ++ if (size) //OS X on SDK 10.6 has a broken posix_memalign implementation ++ if (posix_memalign(&ptr,ALIGN,size)) + ptr = NULL; + #elif HAVE_MEMALIGN +- ptr = memalign(16,size); ++ ptr = memalign(ALIGN,size); + /* Why 64? + Indeed, we should align it: + on 4 for 386 +@@ -93,10 +104,8 @@ + Because L1 and L2 caches are aligned on those values. + But I don't want to code such logic here! + */ +- /* Why 16? +- Because some CPUs need alignment, for example SSE2 on P4, & most RISC CPUs +- it will just trigger an exception and the unaligned load will be done in the +- exception handler or it will just segfault (SSE2 on P4). ++ /* Why 32? ++ For AVX ASM. SSE / NEON needs only 16. + Why not larger? Because I did not see a difference in benchmarks ... + */ + /* benchmarks with P3 +@@ -113,37 +122,55 @@ + #else + ptr = malloc(size); + #endif ++ if(!ptr && !size) ++ ptr= av_malloc(1); + return ptr; + } + +-void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size) ++void *av_realloc(void *ptr, size_t size) + { + #if CONFIG_MEMALIGN_HACK + int diff; + #endif + + /* let's disallow possible ambiguous cases */ +- if(size > (INT_MAX-16) ) ++ if (size > (max_alloc_size-32)) + return NULL; + + #if CONFIG_MEMALIGN_HACK + //FIXME this isn't aligned correctly, though it probably isn't needed + if(!ptr) return av_malloc(size); + diff= ((char*)ptr)[-1]; +- return (char*)realloc((char*)ptr - diff, size + diff) + diff; ++ ptr= realloc((char*)ptr - diff, size + diff); ++ if(ptr) ptr = (char*)ptr + diff; ++ return ptr; + #else +- return realloc(ptr, size); ++ return realloc(ptr, size + !size); + #endif + } + ++void *av_realloc_f(void *ptr, size_t nelem, size_t elsize) ++{ ++ size_t size; ++ void *r; ++ ++ if (av_size_mult(elsize, nelem, &size)) { ++ av_free(ptr); ++ return NULL; ++ } ++ r = av_realloc(ptr, size); ++ if (!r && size) ++ av_free(ptr); ++ return r; ++} ++ + void av_free(void *ptr) + { +- /* XXX: this test should not be needed on most libcs */ +- if (ptr) + #if CONFIG_MEMALIGN_HACK ++ if (ptr) + free((char*)ptr - ((char*)ptr)[-1]); + #else +- free(ptr); ++ free(ptr); + #endif + } + +@@ -154,7 +181,7 @@ + *ptr = NULL; + } + +-void *av_mallocz(FF_INTERNAL_MEM_TYPE size) ++void *av_mallocz(size_t size) + { + void *ptr = av_malloc(size); + if (ptr) +@@ -162,6 +189,13 @@ + return ptr; + } + ++void *av_calloc(size_t nmemb, size_t size) ++{ ++ if (size <= 0 || nmemb >= INT_MAX / size) ++ return NULL; ++ return av_mallocz(nmemb * size); ++} ++ + char *av_strdup(const char *s) + { + char *ptr= NULL; +@@ -174,3 +208,23 @@ + return ptr; + } + ++/* add one element to a dynamic array */ ++void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem) ++{ ++ /* see similar ffmpeg.c:grow_array() */ ++ int nb, nb_alloc; ++ intptr_t *tab; ++ ++ nb = *nb_ptr; ++ tab = *(intptr_t**)tab_ptr; ++ if ((nb & (nb - 1)) == 0) { ++ if (nb == 0) ++ nb_alloc = 1; ++ else ++ nb_alloc = nb * 2; ++ tab = av_realloc(tab, nb_alloc * sizeof(intptr_t)); ++ *(intptr_t**)tab_ptr = tab; ++ } ++ tab[nb++] = (intptr_t)elem; ++ *nb_ptr = nb; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mem.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mem.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/mem.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/mem.h 2012-05-14 14:08:55.320359826 +0200 +@@ -27,9 +27,16 @@ + #define AVUTIL_MEM_H + + #include "attributes.h" ++#include "error.h" + #include "avutil.h" + +-#if defined(__ICC) && _ICC < 1200 || defined(__SUNPRO_C) ++/** ++ * @addtogroup lavu_mem ++ * @{ ++ */ ++ ++ ++#if defined(__INTEL_COMPILER) && __INTEL_COMPILER < 1110 || defined(__SUNPRO_C) + #define DECLARE_ALIGNED(n,t,v) t __attribute__ ((aligned (n))) v + #define DECLARE_ASM_CONST(n,t,v) const t __attribute__ ((aligned (n))) v + #elif defined(__TI_COMPILER_VERSION__) +@@ -56,20 +63,12 @@ + #define av_malloc_attrib + #endif + +-#if (!defined(__ICC) || __ICC > 1200) && AV_GCC_VERSION_AT_LEAST(4,3) ++#if AV_GCC_VERSION_AT_LEAST(4,3) + #define av_alloc_size(n) __attribute__((alloc_size(n))) + #else + #define av_alloc_size(n) + #endif + +-#if LIBAVUTIL_VERSION_MAJOR < 51 +-# define FF_INTERNAL_MEM_TYPE unsigned int +-# define FF_INTERNAL_MEM_TYPE_MAX_VALUE UINT_MAX +-#else +-# define FF_INTERNAL_MEM_TYPE size_t +-# define FF_INTERNAL_MEM_TYPE_MAX_VALUE SIZE_MAX +-#endif +- + /** + * Allocate a block of size bytes with alignment suitable for all + * memory accesses (including vectors if available on the CPU). +@@ -78,21 +77,31 @@ + * be allocated. + * @see av_mallocz() + */ +-void *av_malloc(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1); ++void *av_malloc(size_t size) av_malloc_attrib av_alloc_size(1); + + /** + * Allocate or reallocate a block of memory. + * If ptr is NULL and size > 0, allocate a new block. If + * size is zero, free the memory block pointed to by ptr. +- * @param size Size in bytes for the memory block to be allocated or +- * reallocated. + * @param ptr Pointer to a memory block already allocated with + * av_malloc(z)() or av_realloc() or NULL. ++ * @param size Size in bytes for the memory block to be allocated or ++ * reallocated. + * @return Pointer to a newly reallocated block or NULL if the block + * cannot be reallocated or the function is used to free the memory block. + * @see av_fast_realloc() + */ +-void *av_realloc(void *ptr, FF_INTERNAL_MEM_TYPE size) av_alloc_size(2); ++void *av_realloc(void *ptr, size_t size) av_alloc_size(2); ++ ++/** ++ * Allocate or reallocate a block of memory. ++ * This function does the same thing as av_realloc, except: ++ * - It takes two arguments and checks the result of the multiplication for ++ * integer overflow. ++ * - It frees the input block in case of failure, thus avoiding the memory ++ * leak with the classic "buf = realloc(buf); if (!buf) return -1;". ++ */ ++void *av_realloc_f(void *ptr, size_t nelem, size_t elsize); + + /** + * Free a memory block which has been allocated with av_malloc(z)() or +@@ -112,7 +121,19 @@ + * @return Pointer to the allocated block, NULL if it cannot be allocated. + * @see av_malloc() + */ +-void *av_mallocz(FF_INTERNAL_MEM_TYPE size) av_malloc_attrib av_alloc_size(1); ++void *av_mallocz(size_t size) av_malloc_attrib av_alloc_size(1); ++ ++/** ++ * Allocate a block of nmemb * size bytes with alignment suitable for all ++ * memory accesses (including vectors if available on the CPU) and ++ * zero all the bytes of the block. ++ * The allocation will fail if nmemb * size is greater than or equal ++ * to INT_MAX. ++ * @param nmemb ++ * @param size ++ * @return Pointer to the allocated block, NULL if it cannot be allocated. ++ */ ++void *av_calloc(size_t nmemb, size_t size) av_malloc_attrib; + + /** + * Duplicate the string s. +@@ -131,4 +152,37 @@ + */ + void av_freep(void *ptr); + ++/** ++ * Add an element to a dynamic array. ++ * ++ * @param tab_ptr Pointer to the array. ++ * @param nb_ptr Pointer to the number of elements in the array. ++ * @param elem Element to be added. ++ */ ++void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem); ++ ++/** ++ * Multiply two size_t values checking for overflow. ++ * @return 0 if success, AVERROR(EINVAL) if overflow. ++ */ ++static inline int av_size_mult(size_t a, size_t b, size_t *r) ++{ ++ size_t t = a * b; ++ /* Hack inspired from glibc: only try the division if nelem and elsize ++ * are both greater than sqrt(SIZE_MAX). */ ++ if ((a | b) >= ((size_t)1 << (sizeof(size_t) * 4)) && a && t / a != b) ++ return AVERROR(EINVAL); ++ *r = t; ++ return 0; ++} ++ ++/** ++ * Set the maximum size that may me allocated in one block. ++ */ ++void av_max_alloc(size_t max); ++ ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_MEM_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/opt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/opt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/opt.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/opt.c 2012-05-14 14:08:55.323359886 +0200 +@@ -29,50 +29,68 @@ + #include "avstring.h" + #include "opt.h" + #include "eval.h" ++#include "dict.h" ++#include "log.h" + ++#if FF_API_FIND_OPT + //FIXME order them and do a bin search + const AVOption *av_find_opt(void *v, const char *name, const char *unit, int mask, int flags) + { +- AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass +- const AVOption *o= c->option; ++ const AVOption *o = NULL; + +- for (; o && o->name; o++) { ++ while ((o = av_next_option(v, o))) { + if (!strcmp(o->name, name) && (!unit || (o->unit && !strcmp(o->unit, unit))) && (o->flags & mask) == flags) + return o; + } + return NULL; + } ++#endif + ++#if FF_API_OLD_AVOPTIONS + const AVOption *av_next_option(void *obj, const AVOption *last) + { +- if (last && last[1].name) return ++last; +- else if (last) return NULL; +- else return (*(AVClass**)obj)->option; ++ return av_opt_next(obj, last); + } ++#endif + +-static int av_set_number2(void *obj, const char *name, double num, int den, int64_t intnum, const AVOption **o_out) ++const AVOption *av_opt_next(void *obj, const AVOption *last) + { +- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); +- void *dst; +- if (o_out) +- *o_out= o; +- if (!o || o->offset<=0) +- return AVERROR(ENOENT); ++ AVClass *class = *(AVClass**)obj; ++ if (!last && class->option[0].name) return class->option; ++ if (last && last[1].name) return ++last; ++ return NULL; ++} ++ ++static int read_number(const AVOption *o, void *dst, double *num, int *den, int64_t *intnum) ++{ ++ switch (o->type) { ++ case AV_OPT_TYPE_FLAGS: *intnum = *(unsigned int*)dst;return 0; ++ case AV_OPT_TYPE_INT: *intnum = *(int *)dst;return 0; ++ case AV_OPT_TYPE_INT64: *intnum = *(int64_t *)dst;return 0; ++ case AV_OPT_TYPE_FLOAT: *num = *(float *)dst;return 0; ++ case AV_OPT_TYPE_DOUBLE: *num = *(double *)dst;return 0; ++ case AV_OPT_TYPE_RATIONAL: *intnum = ((AVRational*)dst)->num; ++ *den = ((AVRational*)dst)->den; ++ return 0; ++ case AV_OPT_TYPE_CONST: *num = o->default_val.dbl; return 0; ++ } ++ return AVERROR(EINVAL); ++} + ++static int write_number(void *obj, const AVOption *o, void *dst, double num, int den, int64_t intnum) ++{ + if (o->max*den < num*intnum || o->min*den > num*intnum) { +- av_log(obj, AV_LOG_ERROR, "Value %lf for parameter '%s' out of range\n", num, name); ++ av_log(obj, AV_LOG_ERROR, "Value %f for parameter '%s' out of range\n", num*intnum/den, o->name); + return AVERROR(ERANGE); + } + +- dst= ((uint8_t*)obj) + o->offset; +- + switch (o->type) { +- case FF_OPT_TYPE_FLAGS: +- case FF_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break; +- case FF_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break; +- case FF_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; +- case FF_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; +- case FF_OPT_TYPE_RATIONAL: ++ case AV_OPT_TYPE_FLAGS: ++ case AV_OPT_TYPE_INT: *(int *)dst= llrint(num/den)*intnum; break; ++ case AV_OPT_TYPE_INT64: *(int64_t *)dst= llrint(num/den)*intnum; break; ++ case AV_OPT_TYPE_FLOAT: *(float *)dst= num*intnum/den; break; ++ case AV_OPT_TYPE_DOUBLE:*(double *)dst= num*intnum/den; break; ++ case AV_OPT_TYPE_RATIONAL: + if ((int)num == num) *(AVRational*)dst= (AVRational){num*intnum, den}; + else *(AVRational*)dst= av_d2q(num*intnum/den, 1<<24); + break; +@@ -82,15 +100,6 @@ + return 0; + } + +-static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum) +-{ +- const AVOption *o = NULL; +- if (av_set_number2(obj, name, num, den, intnum, &o) < 0) +- return NULL; +- else +- return o; +-} +- + static const double const_values[] = { + M_PI, + M_E, +@@ -112,114 +121,202 @@ + return -1; + } + +-int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out) ++static int set_string_binary(void *obj, const AVOption *o, const char *val, uint8_t **dst) + { +- int ret; +- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); +- if (o_out) +- *o_out = o; +- if (!o) +- return AVERROR(ENOENT); +- if (!val || o->offset<=0) ++ int *lendst = (int *)(dst + 1); ++ uint8_t *bin, *ptr; ++ int len = strlen(val); ++ ++ av_freep(dst); ++ *lendst = 0; ++ ++ if (len & 1) + return AVERROR(EINVAL); ++ len /= 2; + +- if (o->type == FF_OPT_TYPE_BINARY) { +- uint8_t **dst = (uint8_t **)(((uint8_t*)obj) + o->offset); +- int *lendst = (int *)(dst + 1); +- uint8_t *bin, *ptr; +- int len = strlen(val); +- av_freep(dst); +- *lendst = 0; +- if (len & 1) return AVERROR(EINVAL); +- len /= 2; +- ptr = bin = av_malloc(len); +- while (*val) { +- int a = hexchar2int(*val++); +- int b = hexchar2int(*val++); +- if (a < 0 || b < 0) { +- av_free(bin); +- return AVERROR(EINVAL); +- } +- *ptr++ = (a << 4) | b; ++ ptr = bin = av_malloc(len); ++ while (*val) { ++ int a = hexchar2int(*val++); ++ int b = hexchar2int(*val++); ++ if (a < 0 || b < 0) { ++ av_free(bin); ++ return AVERROR(EINVAL); + } +- *dst = bin; +- *lendst = len; +- return 0; ++ *ptr++ = (a << 4) | b; + } +- if (o->type != FF_OPT_TYPE_STRING) { +- int notfirst=0; +- for (;;) { +- int i; +- char buf[256]; +- int cmd=0; +- double d; +- +- if (*val == '+' || *val == '-') +- cmd= *(val++); +- +- for (i=0; iunit, 0, 0); +- if (o_named && o_named->type == FF_OPT_TYPE_CONST) +- d= o_named->default_val; +- else if (!strcmp(buf, "default")) d= o->default_val; +- else if (!strcmp(buf, "max" )) d= o->max; +- else if (!strcmp(buf, "min" )) d= o->min; +- else if (!strcmp(buf, "none" )) d= 0; +- else if (!strcmp(buf, "all" )) d= ~0; +- else { +- int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); +- if (res < 0) { +- av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val); +- return res; +- } ++ *dst = bin; ++ *lendst = len; ++ ++ return 0; ++} ++ ++static int set_string(void *obj, const AVOption *o, const char *val, uint8_t **dst) ++{ ++ av_freep(dst); ++ *dst = av_strdup(val); ++ return 0; ++} ++ ++static int set_string_number(void *obj, const AVOption *o, const char *val, void *dst) ++{ ++ int ret = 0, notfirst = 0; ++ for (;;) { ++ int i, den = 1; ++ char buf[256]; ++ int cmd = 0; ++ double d, num = 1; ++ int64_t intnum = 1; ++ ++ if (*val == '+' || *val == '-') ++ cmd = *(val++); ++ ++ for (i = 0; i < sizeof(buf) - 1 && val[i] && val[i] != '+' && val[i] != '-'; i++) ++ buf[i] = val[i]; ++ buf[i] = 0; ++ ++ { ++ const AVOption *o_named = av_opt_find(obj, buf, o->unit, 0, 0); ++ if (o_named && o_named->type == AV_OPT_TYPE_CONST) ++ d = o_named->default_val.dbl; ++ else if (!strcmp(buf, "default")) d = o->default_val.dbl; ++ else if (!strcmp(buf, "max" )) d = o->max; ++ else if (!strcmp(buf, "min" )) d = o->min; ++ else if (!strcmp(buf, "none" )) d = 0; ++ else if (!strcmp(buf, "all" )) d = ~0; ++ else { ++ int res = av_expr_parse_and_eval(&d, buf, const_names, const_values, NULL, NULL, NULL, NULL, NULL, 0, obj); ++ if (res < 0) { ++ av_log(obj, AV_LOG_ERROR, "Unable to parse option value \"%s\"\n", val); ++ return res; + } + } +- if (o->type == FF_OPT_TYPE_FLAGS) { +- if (cmd=='+') d= av_get_int(obj, name, NULL) | (int64_t)d; +- else if (cmd=='-') d= av_get_int(obj, name, NULL) &~(int64_t)d; +- } else { +- if (cmd=='+') d= notfirst*av_get_double(obj, name, NULL) + d; +- else if (cmd=='-') d= notfirst*av_get_double(obj, name, NULL) - d; +- } +- +- if ((ret = av_set_number2(obj, name, d, 1, 1, o_out)) < 0) +- return ret; +- val+= i; +- if (!*val) +- return 0; +- notfirst=1; + } ++ if (o->type == AV_OPT_TYPE_FLAGS) { ++ read_number(o, dst, NULL, NULL, &intnum); ++ if (cmd == '+') d = intnum | (int64_t)d; ++ else if (cmd == '-') d = intnum &~(int64_t)d; ++ } else { ++ read_number(o, dst, &num, &den, &intnum); ++ if (cmd == '+') d = notfirst*num*intnum/den + d; ++ else if (cmd == '-') d = notfirst*num*intnum/den - d; ++ } ++ ++ if ((ret = write_number(obj, o, dst, d, 1, 1)) < 0) ++ return ret; ++ val += i; ++ if (!*val) ++ return 0; ++ notfirst = 1; ++ } ++ ++ return 0; ++} ++ ++#if FF_API_OLD_AVOPTIONS ++int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out) ++{ ++ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0); ++ if (o_out) ++ *o_out = o; ++ return av_opt_set(obj, name, val, 0); ++} ++#endif ++ ++int av_opt_set(void *obj, const char *name, const char *val, int search_flags) ++{ ++ void *dst, *target_obj; ++ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); ++ if (!o || !target_obj) ++ return AVERROR_OPTION_NOT_FOUND; ++ if (!val && o->type != AV_OPT_TYPE_STRING) + return AVERROR(EINVAL); ++ ++ dst = ((uint8_t*)target_obj) + o->offset; ++ switch (o->type) { ++ case AV_OPT_TYPE_STRING: return set_string(obj, o, val, dst); ++ case AV_OPT_TYPE_BINARY: return set_string_binary(obj, o, val, dst); ++ case AV_OPT_TYPE_FLAGS: ++ case AV_OPT_TYPE_INT: ++ case AV_OPT_TYPE_INT64: ++ case AV_OPT_TYPE_FLOAT: ++ case AV_OPT_TYPE_DOUBLE: ++ case AV_OPT_TYPE_RATIONAL: return set_string_number(obj, o, val, dst); + } + +- if (alloc) { +- av_free(*(void**)(((uint8_t*)obj) + o->offset)); +- val= av_strdup(val); ++ av_log(obj, AV_LOG_ERROR, "Invalid option type.\n"); ++ return AVERROR(EINVAL); ++} ++ ++#define OPT_EVAL_NUMBER(name, opttype, vartype)\ ++ int av_opt_eval_ ## name(void *obj, const AVOption *o, const char *val, vartype *name ## _out)\ ++ {\ ++ if (!o || o->type != opttype)\ ++ return AVERROR(EINVAL);\ ++ return set_string_number(obj, o, val, name ## _out);\ + } + +- memcpy(((uint8_t*)obj) + o->offset, &val, sizeof(val)); +- return 0; ++OPT_EVAL_NUMBER(flags, AV_OPT_TYPE_FLAGS, int) ++OPT_EVAL_NUMBER(int, AV_OPT_TYPE_INT, int) ++OPT_EVAL_NUMBER(int64, AV_OPT_TYPE_INT64, int64_t) ++OPT_EVAL_NUMBER(float, AV_OPT_TYPE_FLOAT, float) ++OPT_EVAL_NUMBER(double, AV_OPT_TYPE_DOUBLE, double) ++OPT_EVAL_NUMBER(q, AV_OPT_TYPE_RATIONAL, AVRational) ++ ++static int set_number(void *obj, const char *name, double num, int den, int64_t intnum, ++ int search_flags) ++{ ++ void *dst, *target_obj; ++ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); ++ ++ if (!o || !target_obj) ++ return AVERROR_OPTION_NOT_FOUND; ++ ++ dst = ((uint8_t*)target_obj) + o->offset; ++ return write_number(obj, o, dst, num, den, intnum); + } + ++#if FF_API_OLD_AVOPTIONS + const AVOption *av_set_double(void *obj, const char *name, double n) + { +- return av_set_number(obj, name, n, 1, 1); ++ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0); ++ if (set_number(obj, name, n, 1, 1, 0) < 0) ++ return NULL; ++ return o; + } + + const AVOption *av_set_q(void *obj, const char *name, AVRational n) + { +- return av_set_number(obj, name, n.num, n.den, 1); ++ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0); ++ if (set_number(obj, name, n.num, n.den, 1, 0) < 0) ++ return NULL; ++ return o; + } + + const AVOption *av_set_int(void *obj, const char *name, int64_t n) + { +- return av_set_number(obj, name, 1, 1, n); ++ const AVOption *o = av_opt_find(obj, name, NULL, 0, 0); ++ if (set_number(obj, name, 1, 1, n, 0) < 0) ++ return NULL; ++ return o; ++} ++#endif ++ ++int av_opt_set_int(void *obj, const char *name, int64_t val, int search_flags) ++{ ++ return set_number(obj, name, 1, 1, val, search_flags); ++} ++ ++int av_opt_set_double(void *obj, const char *name, double val, int search_flags) ++{ ++ return set_number(obj, name, val, 1, 1, search_flags); + } + ++int av_opt_set_q(void *obj, const char *name, AVRational val, int search_flags) ++{ ++ return set_number(obj, name, val.num, val.den, 1, search_flags); ++} ++ ++#if FF_API_OLD_AVOPTIONS + /** + * + * @param buf a buffer which is used for returning non string values as strings, can be NULL +@@ -227,27 +324,28 @@ + */ + const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len) + { +- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); ++ const AVOption *o = av_opt_find(obj, name, NULL, 0, AV_OPT_SEARCH_CHILDREN); + void *dst; + uint8_t *bin; + int len, i; +- if (!o || o->offset<=0) ++ if (!o) + return NULL; +- if (o->type != FF_OPT_TYPE_STRING && (!buf || !buf_len)) ++ if (o->type != AV_OPT_TYPE_STRING && (!buf || !buf_len)) + return NULL; + + dst= ((uint8_t*)obj) + o->offset; + if (o_out) *o_out= o; + + switch (o->type) { +- case FF_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; +- case FF_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; +- case FF_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; +- case FF_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; +- case FF_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; +- case FF_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; +- case FF_OPT_TYPE_STRING: return *(void**)dst; +- case FF_OPT_TYPE_BINARY: ++ case AV_OPT_TYPE_FLAGS: snprintf(buf, buf_len, "0x%08X",*(int *)dst);break; ++ case AV_OPT_TYPE_INT: snprintf(buf, buf_len, "%d" , *(int *)dst);break; ++ case AV_OPT_TYPE_INT64: snprintf(buf, buf_len, "%"PRId64, *(int64_t*)dst);break; ++ case AV_OPT_TYPE_FLOAT: snprintf(buf, buf_len, "%f" , *(float *)dst);break; ++ case AV_OPT_TYPE_DOUBLE: snprintf(buf, buf_len, "%f" , *(double *)dst);break; ++ case AV_OPT_TYPE_RATIONAL: snprintf(buf, buf_len, "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; ++ case AV_OPT_TYPE_CONST: snprintf(buf, buf_len, "%f" , o->default_val.dbl);break; ++ case AV_OPT_TYPE_STRING: return *(void**)dst; ++ case AV_OPT_TYPE_BINARY: + len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); + if (len >= (buf_len + 1)/2) return NULL; + bin = *(uint8_t**)dst; +@@ -257,40 +355,83 @@ + } + return buf; + } ++#endif + +-static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum) ++int av_opt_get(void *obj, const char *name, int search_flags, uint8_t **out_val) + { +- const AVOption *o= av_find_opt(obj, name, NULL, 0, 0); +- void *dst; +- if (!o || o->offset<=0) +- goto error; ++ void *dst, *target_obj; ++ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); ++ uint8_t *bin, buf[128]; ++ int len, i, ret; + +- dst= ((uint8_t*)obj) + o->offset; ++ if (!o || !target_obj || (o->offset<=0 && o->type != AV_OPT_TYPE_CONST)) ++ return AVERROR_OPTION_NOT_FOUND; + +- if (o_out) *o_out= o; ++ dst = (uint8_t*)target_obj + o->offset; + ++ buf[0] = 0; + switch (o->type) { +- case FF_OPT_TYPE_FLAGS: *intnum= *(unsigned int*)dst;return 0; +- case FF_OPT_TYPE_INT: *intnum= *(int *)dst;return 0; +- case FF_OPT_TYPE_INT64: *intnum= *(int64_t*)dst;return 0; +- case FF_OPT_TYPE_FLOAT: *num= *(float *)dst;return 0; +- case FF_OPT_TYPE_DOUBLE: *num= *(double *)dst;return 0; +- case FF_OPT_TYPE_RATIONAL: *intnum= ((AVRational*)dst)->num; +- *den = ((AVRational*)dst)->den; +- return 0; ++ case AV_OPT_TYPE_FLAGS: ret = snprintf(buf, sizeof(buf), "0x%08X", *(int *)dst);break; ++ case AV_OPT_TYPE_INT: ret = snprintf(buf, sizeof(buf), "%d" , *(int *)dst);break; ++ case AV_OPT_TYPE_INT64: ret = snprintf(buf, sizeof(buf), "%"PRId64, *(int64_t*)dst);break; ++ case AV_OPT_TYPE_FLOAT: ret = snprintf(buf, sizeof(buf), "%f" , *(float *)dst);break; ++ case AV_OPT_TYPE_DOUBLE: ret = snprintf(buf, sizeof(buf), "%f" , *(double *)dst);break; ++ case AV_OPT_TYPE_RATIONAL: ret = snprintf(buf, sizeof(buf), "%d/%d", ((AVRational*)dst)->num, ((AVRational*)dst)->den);break; ++ case AV_OPT_TYPE_CONST: ret = snprintf(buf, sizeof(buf), "%f" , o->default_val.dbl);break; ++ case AV_OPT_TYPE_STRING: ++ if (*(uint8_t**)dst) ++ *out_val = av_strdup(*(uint8_t**)dst); ++ else ++ *out_val = av_strdup(""); ++ return 0; ++ case AV_OPT_TYPE_BINARY: ++ len = *(int*)(((uint8_t *)dst) + sizeof(uint8_t *)); ++ if ((uint64_t)len*2 + 1 > INT_MAX) ++ return AVERROR(EINVAL); ++ if (!(*out_val = av_malloc(len*2 + 1))) ++ return AVERROR(ENOMEM); ++ bin = *(uint8_t**)dst; ++ for (i = 0; i < len; i++) ++ snprintf(*out_val + i*2, 3, "%02X", bin[i]); ++ return 0; ++ default: ++ return AVERROR(EINVAL); + } ++ ++ if (ret >= sizeof(buf)) ++ return AVERROR(EINVAL); ++ *out_val = av_strdup(buf); ++ return 0; ++} ++ ++static int get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum, ++ int search_flags) ++{ ++ void *dst, *target_obj; ++ const AVOption *o = av_opt_find2(obj, name, NULL, 0, search_flags, &target_obj); ++ if (!o || !target_obj) ++ goto error; ++ ++ dst = ((uint8_t*)target_obj) + o->offset; ++ ++ if (o_out) *o_out= o; ++ ++ return read_number(o, dst, num, den, intnum); ++ + error: + *den=*intnum=0; + return -1; + } + ++#if FF_API_OLD_AVOPTIONS + double av_get_double(void *obj, const char *name, const AVOption **o_out) + { + int64_t intnum=1; + double num=1; + int den=1; + +- av_get_number(obj, name, o_out, &num, &den, &intnum); ++ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0) ++ return NAN; + return num*intnum/den; + } + +@@ -300,7 +441,8 @@ + double num=1; + int den=1; + +- av_get_number(obj, name, o_out, &num, &den, &intnum); ++ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0) ++ return (AVRational){0, 0}; + if (num == 1.0 && (int)intnum == intnum) + return (AVRational){intnum, den}; + else +@@ -313,16 +455,71 @@ + double num=1; + int den=1; + +- av_get_number(obj, name, o_out, &num, &den, &intnum); ++ if (get_number(obj, name, o_out, &num, &den, &intnum, 0) < 0) ++ return -1; + return num*intnum/den; + } ++#endif ++ ++int av_opt_get_int(void *obj, const char *name, int search_flags, int64_t *out_val) ++{ ++ int64_t intnum = 1; ++ double num = 1; ++ int ret, den = 1; ++ ++ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0) ++ return ret; ++ *out_val = num*intnum/den; ++ return 0; ++} ++ ++int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val) ++{ ++ int64_t intnum = 1; ++ double num = 1; ++ int ret, den = 1; ++ ++ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0) ++ return ret; ++ *out_val = num*intnum/den; ++ return 0; ++} ++ ++int av_opt_get_q(void *obj, const char *name, int search_flags, AVRational *out_val) ++{ ++ int64_t intnum = 1; ++ double num = 1; ++ int ret, den = 1; ++ ++ if ((ret = get_number(obj, name, NULL, &num, &den, &intnum, search_flags)) < 0) ++ return ret; ++ ++ if (num == 1.0 && (int)intnum == intnum) ++ *out_val = (AVRational){intnum, den}; ++ else ++ *out_val = av_d2q(num*intnum/den, 1<<24); ++ return 0; ++} ++ ++int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name) ++{ ++ const AVOption *field = av_opt_find(obj, field_name, NULL, 0, 0); ++ const AVOption *flag = av_opt_find(obj, flag_name, ++ field ? field->unit : NULL, 0, 0); ++ int64_t res; ++ ++ if (!field || !flag || flag->type != AV_OPT_TYPE_CONST || ++ av_opt_get_int(obj, field_name, 0, &res) < 0) ++ return 0; ++ return res & (int) flag->default_val.dbl; ++} + + static void opt_list(void *obj, void *av_log_obj, const char *unit, + int req_flags, int rej_flags) + { + const AVOption *opt=NULL; + +- while ((opt= av_next_option(obj, opt))) { ++ while ((opt = av_opt_next(obj, opt))) { + if (!(opt->flags & req_flags) || (opt->flags & rej_flags)) + continue; + +@@ -330,43 +527,43 @@ + * Don't print anything but CONST's on level two. + * Only print items from the requested unit. + */ +- if (!unit && opt->type==FF_OPT_TYPE_CONST) ++ if (!unit && opt->type==AV_OPT_TYPE_CONST) + continue; +- else if (unit && opt->type!=FF_OPT_TYPE_CONST) ++ else if (unit && opt->type!=AV_OPT_TYPE_CONST) + continue; +- else if (unit && opt->type==FF_OPT_TYPE_CONST && strcmp(unit, opt->unit)) ++ else if (unit && opt->type==AV_OPT_TYPE_CONST && strcmp(unit, opt->unit)) + continue; +- else if (unit && opt->type == FF_OPT_TYPE_CONST) ++ else if (unit && opt->type == AV_OPT_TYPE_CONST) + av_log(av_log_obj, AV_LOG_INFO, " %-15s ", opt->name); + else + av_log(av_log_obj, AV_LOG_INFO, "-%-17s ", opt->name); + + switch (opt->type) { +- case FF_OPT_TYPE_FLAGS: ++ case AV_OPT_TYPE_FLAGS: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_INT: ++ case AV_OPT_TYPE_INT: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_INT64: ++ case AV_OPT_TYPE_INT64: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_DOUBLE: ++ case AV_OPT_TYPE_DOUBLE: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_FLOAT: ++ case AV_OPT_TYPE_FLOAT: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_STRING: ++ case AV_OPT_TYPE_STRING: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_RATIONAL: ++ case AV_OPT_TYPE_RATIONAL: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_BINARY: ++ case AV_OPT_TYPE_BINARY: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +- case FF_OPT_TYPE_CONST: ++ case AV_OPT_TYPE_CONST: + default: + av_log(av_log_obj, AV_LOG_INFO, "%-7s ", ""); + break; +@@ -380,7 +577,7 @@ + if (opt->help) + av_log(av_log_obj, AV_LOG_INFO, " %s", opt->help); + av_log(av_log_obj, AV_LOG_INFO, "\n"); +- if (opt->unit && opt->type != FF_OPT_TYPE_CONST) { ++ if (opt->unit && opt->type != AV_OPT_TYPE_CONST) { + opt_list(obj, av_log_obj, opt->unit, req_flags, rej_flags); + } + } +@@ -398,50 +595,55 @@ + return 0; + } + +-/** Set the values of the AVCodecContext or AVFormatContext structure. +- * They are set to the defaults specified in the according AVOption options +- * array default_val field. +- * +- * @param s AVCodecContext or AVFormatContext for which the defaults will be set +- */ ++void av_opt_set_defaults(void *s) ++{ ++#if FF_API_OLD_AVOPTIONS ++ av_opt_set_defaults2(s, 0, 0); ++} ++ + void av_opt_set_defaults2(void *s, int mask, int flags) + { ++#endif + const AVOption *opt = NULL; +- while ((opt = av_next_option(s, opt)) != NULL) { ++ while ((opt = av_opt_next(s, opt)) != NULL) { ++#if FF_API_OLD_AVOPTIONS + if ((opt->flags & mask) != flags) + continue; ++#endif + switch (opt->type) { +- case FF_OPT_TYPE_CONST: ++ case AV_OPT_TYPE_CONST: + /* Nothing to be done here */ + break; +- case FF_OPT_TYPE_FLAGS: +- case FF_OPT_TYPE_INT: { ++ case AV_OPT_TYPE_FLAGS: ++ case AV_OPT_TYPE_INT: { + int val; +- val = opt->default_val; +- av_set_int(s, opt->name, val); ++ val = opt->default_val.dbl; ++ av_opt_set_int(s, opt->name, val, 0); + } + break; +- case FF_OPT_TYPE_INT64: +- if ((double)(opt->default_val+0.6) == opt->default_val) ++ case AV_OPT_TYPE_INT64: ++ if ((double)(opt->default_val.dbl+0.6) == opt->default_val.dbl) + av_log(s, AV_LOG_DEBUG, "loss of precision in default of %s\n", opt->name); +- av_set_int(s, opt->name, opt->default_val); ++ av_opt_set_int(s, opt->name, opt->default_val.dbl, 0); + break; +- case FF_OPT_TYPE_DOUBLE: +- case FF_OPT_TYPE_FLOAT: { ++ case AV_OPT_TYPE_DOUBLE: ++ case AV_OPT_TYPE_FLOAT: { + double val; +- val = opt->default_val; +- av_set_double(s, opt->name, val); ++ val = opt->default_val.dbl; ++ av_opt_set_double(s, opt->name, val, 0); + } + break; +- case FF_OPT_TYPE_RATIONAL: { ++ case AV_OPT_TYPE_RATIONAL: { + AVRational val; +- val = av_d2q(opt->default_val, INT_MAX); +- av_set_q(s, opt->name, val); ++ val = av_d2q(opt->default_val.dbl, INT_MAX); ++ av_opt_set_q(s, opt->name, val, 0); + } + break; +- case FF_OPT_TYPE_STRING: +- case FF_OPT_TYPE_BINARY: +- /* Cannot set default for string as default_val is of type * double */ ++ case AV_OPT_TYPE_STRING: ++ av_opt_set(s, opt->name, opt->default_val.str, 0); ++ break; ++ case AV_OPT_TYPE_BINARY: ++ /* Cannot set default for binary */ + break; + default: + av_log(s, AV_LOG_DEBUG, "AVOption type %d of option %s not implemented yet\n", opt->type, opt->name); +@@ -449,11 +651,6 @@ + } + } + +-void av_opt_set_defaults(void *s) +-{ +- av_opt_set_defaults2(s, 0, 0); +-} +- + /** + * Store the value in the field in ctx that is named like key. + * ctx must be an AVClass context, storing is done using AVOptions. +@@ -468,7 +665,7 @@ + * set, or a negative value corresponding to an AVERROR code in case + * of error: + * AVERROR(EINVAL) if the key/value pair cannot be parsed, +- * the error code issued by av_set_string3() if the key/value pair ++ * the error code issued by av_opt_set() if the key/value pair + * cannot be set + */ + static int parse_key_value_pair(void *ctx, const char **buf, +@@ -489,8 +686,8 @@ + + av_log(ctx, AV_LOG_DEBUG, "Setting value '%s' for key '%s'\n", val, key); + +- ret = av_set_string3(ctx, key, val, 1, NULL); +- if (ret == AVERROR(ENOENT)) ++ ret = av_opt_set(ctx, key, val, 0); ++ if (ret == AVERROR_OPTION_NOT_FOUND) + av_log(ctx, AV_LOG_ERROR, "Key '%s' not found.\n", key); + + av_free(key); +@@ -503,6 +700,9 @@ + { + int ret, count = 0; + ++ if (!opts) ++ return 0; ++ + while (*opts) { + if ((ret = parse_key_value_pair(ctx, &opts, key_val_sep, pairs_sep)) < 0) + return ret; +@@ -515,6 +715,105 @@ + return count; + } + ++void av_opt_free(void *obj) ++{ ++ const AVOption *o = NULL; ++ while ((o = av_opt_next(obj, o))) ++ if (o->type == AV_OPT_TYPE_STRING || o->type == AV_OPT_TYPE_BINARY) ++ av_freep((uint8_t *)obj + o->offset); ++} ++ ++int av_opt_set_dict(void *obj, AVDictionary **options) ++{ ++ AVDictionaryEntry *t = NULL; ++ AVDictionary *tmp = NULL; ++ int ret = 0; ++ ++ while ((t = av_dict_get(*options, "", t, AV_DICT_IGNORE_SUFFIX))) { ++ ret = av_opt_set(obj, t->key, t->value, 0); ++ if (ret == AVERROR_OPTION_NOT_FOUND) ++ av_dict_set(&tmp, t->key, t->value, 0); ++ else if (ret < 0) { ++ av_log(obj, AV_LOG_ERROR, "Error setting option %s to value %s.\n", t->key, t->value); ++ break; ++ } ++ ret = 0; ++ } ++ av_dict_free(options); ++ *options = tmp; ++ return ret; ++} ++ ++const AVOption *av_opt_find(void *obj, const char *name, const char *unit, ++ int opt_flags, int search_flags) ++{ ++ return av_opt_find2(obj, name, unit, opt_flags, search_flags, NULL); ++} ++ ++const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, ++ int opt_flags, int search_flags, void **target_obj) ++{ ++ const AVClass *c; ++ const AVOption *o = NULL; ++ ++ if(!obj) ++ return NULL; ++ ++ c= *(AVClass**)obj; ++ ++ if (search_flags & AV_OPT_SEARCH_CHILDREN) { ++ if (search_flags & AV_OPT_SEARCH_FAKE_OBJ) { ++ const AVClass *child = NULL; ++ while (child = av_opt_child_class_next(c, child)) ++ if (o = av_opt_find2(&child, name, unit, opt_flags, search_flags, NULL)) ++ return o; ++ } else { ++ void *child = NULL; ++ while (child = av_opt_child_next(obj, child)) ++ if (o = av_opt_find2(child, name, unit, opt_flags, search_flags, target_obj)) ++ return o; ++ } ++ } ++ ++ while (o = av_opt_next(obj, o)) { ++ if (!strcmp(o->name, name) && (o->flags & opt_flags) == opt_flags && ++ ((!unit && o->type != AV_OPT_TYPE_CONST) || ++ (unit && o->type == AV_OPT_TYPE_CONST && o->unit && !strcmp(o->unit, unit)))) { ++ if (target_obj) { ++ if (!(search_flags & AV_OPT_SEARCH_FAKE_OBJ)) ++ *target_obj = obj; ++ else ++ *target_obj = NULL; ++ } ++ return o; ++ } ++ } ++ return NULL; ++} ++ ++void *av_opt_child_next(void *obj, void *prev) ++{ ++ const AVClass *c = *(AVClass**)obj; ++ if (c->child_next) ++ return c->child_next(obj, prev); ++ return NULL; ++} ++ ++const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev) ++{ ++ if (parent->child_class_next) ++ return parent->child_class_next(prev); ++ return NULL; ++} ++ ++void *av_opt_ptr(const AVClass *class, void *obj, const char *name) ++{ ++ const AVOption *opt= av_opt_find2(&class, name, NULL, 0, AV_OPT_SEARCH_FAKE_OBJ, NULL); ++ if(!opt) ++ return NULL; ++ return (uint8_t*)obj + opt->offset; ++} ++ + #ifdef TEST + + #undef printf +@@ -536,14 +835,14 @@ + #define TEST_FLAG_MU 04 + + static const AVOption test_options[]= { +-{"num", "set num", OFFSET(num), FF_OPT_TYPE_INT, 0, 0, 100 }, +-{"toggle", "set toggle", OFFSET(toggle), FF_OPT_TYPE_INT, 0, 0, 1 }, +-{"rational", "set rational", OFFSET(rational), FF_OPT_TYPE_RATIONAL, 0, 0, 10 }, +-{"string", "set string", OFFSET(string), FF_OPT_TYPE_STRING, 0, CHAR_MIN, CHAR_MAX }, +-{"flags", "set flags", OFFSET(flags), FF_OPT_TYPE_FLAGS, 0, 0, INT_MAX, 0, "flags" }, +-{"cool", "set cool flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_COOL, INT_MIN, INT_MAX, 0, "flags" }, +-{"lame", "set lame flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_LAME, INT_MIN, INT_MAX, 0, "flags" }, +-{"mu", "set mu flag ", 0, FF_OPT_TYPE_CONST, TEST_FLAG_MU, INT_MIN, INT_MAX, 0, "flags" }, ++{"num", "set num", OFFSET(num), AV_OPT_TYPE_INT, {0}, 0, 100 }, ++{"toggle", "set toggle", OFFSET(toggle), AV_OPT_TYPE_INT, {0}, 0, 1 }, ++{"rational", "set rational", OFFSET(rational), AV_OPT_TYPE_RATIONAL, {0}, 0, 10 }, ++{"string", "set string", OFFSET(string), AV_OPT_TYPE_STRING, {0}, CHAR_MIN, CHAR_MAX }, ++{"flags", "set flags", OFFSET(flags), AV_OPT_TYPE_FLAGS, {0}, 0, INT_MAX, 0, "flags" }, ++{"cool", "set cool flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_COOL}, INT_MIN, INT_MAX, 0, "flags" }, ++{"lame", "set lame flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_LAME}, INT_MIN, INT_MAX, 0, "flags" }, ++{"mu", "set mu flag ", 0, AV_OPT_TYPE_CONST, {TEST_FLAG_MU}, INT_MIN, INT_MAX, 0, "flags" }, + {NULL}, + }; + +@@ -588,7 +887,7 @@ + }; + + test_ctx.class = &test_class; +- av_opt_set_defaults2(&test_ctx, 0, 0); ++ av_opt_set_defaults(&test_ctx); + test_ctx.string = av_strdup("default"); + + av_log_set_level(AV_LOG_DEBUG); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/opt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/opt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/opt.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/opt.h 2012-05-14 14:08:55.326359947 +0200 +@@ -29,9 +29,204 @@ + + #include "rational.h" + #include "avutil.h" ++#include "dict.h" ++#include "log.h" ++ ++/** ++ * @defgroup avoptions AVOptions ++ * @ingroup lavu_data ++ * @{ ++ * AVOptions provide a generic system to declare options on arbitrary structs ++ * ("objects"). An option can have a help text, a type and a range of possible ++ * values. Options may then be enumerated, read and written to. ++ * ++ * @section avoptions_implement Implementing AVOptions ++ * This section describes how to add AVOptions capabilities to a struct. ++ * ++ * All AVOptions-related information is stored in an AVClass. Therefore ++ * the first member of the struct must be a pointer to an AVClass describing it. ++ * The option field of the AVClass must be set to a NULL-terminated static array ++ * of AVOptions. Each AVOption must have a non-empty name, a type, a default ++ * value and for number-type AVOptions also a range of allowed values. It must ++ * also declare an offset in bytes from the start of the struct, where the field ++ * associated with this AVOption is located. Other fields in the AVOption struct ++ * should also be set when applicable, but are not required. ++ * ++ * The following example illustrates an AVOptions-enabled struct: ++ * @code ++ * typedef struct test_struct { ++ * AVClass *class; ++ * int int_opt; ++ * char *str_opt; ++ * uint8_t *bin_opt; ++ * int bin_len; ++ * } test_struct; ++ * ++ * static const AVOption options[] = { ++ * { "test_int", "This is a test option of int type.", offsetof(test_struct, int_opt), ++ * AV_OPT_TYPE_INT, { -1 }, INT_MIN, INT_MAX }, ++ * { "test_str", "This is a test option of string type.", offsetof(test_struct, str_opt), ++ * AV_OPT_TYPE_STRING }, ++ * { "test_bin", "This is a test option of binary type.", offsetof(test_struct, bin_opt), ++ * AV_OPT_TYPE_BINARY }, ++ * { NULL }, ++ * }; ++ * ++ * static const AVClass test_class = { ++ * .class_name = "test class", ++ * .item_name = av_default_item_name, ++ * .option = options, ++ * .version = LIBAVUTIL_VERSION_INT, ++ * }; ++ * @endcode ++ * ++ * Next, when allocating your struct, you must ensure that the AVClass pointer ++ * is set to the correct value. Then, av_opt_set_defaults() must be called to ++ * initialize defaults. After that the struct is ready to be used with the ++ * AVOptions API. ++ * ++ * When cleaning up, you may use the av_opt_free() function to automatically ++ * free all the allocated string and binary options. ++ * ++ * Continuing with the above example: ++ * ++ * @code ++ * test_struct *alloc_test_struct(void) ++ * { ++ * test_struct *ret = av_malloc(sizeof(*ret)); ++ * ret->class = &test_class; ++ * av_opt_set_defaults(ret); ++ * return ret; ++ * } ++ * void free_test_struct(test_struct **foo) ++ * { ++ * av_opt_free(*foo); ++ * av_freep(foo); ++ * } ++ * @endcode ++ * ++ * @subsection avoptions_implement_nesting Nesting ++ * It may happen that an AVOptions-enabled struct contains another ++ * AVOptions-enabled struct as a member (e.g. AVCodecContext in ++ * libavcodec exports generic options, while its priv_data field exports ++ * codec-specific options). In such a case, it is possible to set up the ++ * parent struct to export a child's options. To do that, simply ++ * implement AVClass.child_next() and AVClass.child_class_next() in the ++ * parent struct's AVClass. ++ * Assuming that the test_struct from above now also contains a ++ * child_struct field: ++ * ++ * @code ++ * typedef struct child_struct { ++ * AVClass *class; ++ * int flags_opt; ++ * } child_struct; ++ * static const AVOption child_opts[] = { ++ * { "test_flags", "This is a test option of flags type.", ++ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX }, ++ * { NULL }, ++ * }; ++ * static const AVClass child_class = { ++ * .class_name = "child class", ++ * .item_name = av_default_item_name, ++ * .option = child_opts, ++ * .version = LIBAVUTIL_VERSION_INT, ++ * }; ++ * ++ * void *child_next(void *obj, void *prev) ++ * { ++ * test_struct *t = obj; ++ * if (!prev && t->child_struct) ++ * return t->child_struct; ++ * return NULL ++ * } ++ * const AVClass child_class_next(const AVClass *prev) ++ * { ++ * return prev ? NULL : &child_class; ++ * } ++ * @endcode ++ * Putting child_next() and child_class_next() as defined above into ++ * test_class will now make child_struct's options accessible through ++ * test_struct (again, proper setup as described above needs to be done on ++ * child_struct right after it is created). ++ * ++ * From the above example it might not be clear why both child_next() ++ * and child_class_next() are needed. The distinction is that child_next() ++ * iterates over actually existing objects, while child_class_next() ++ * iterates over all possible child classes. E.g. if an AVCodecContext ++ * was initialized to use a codec which has private options, then its ++ * child_next() will return AVCodecContext.priv_data and finish ++ * iterating. OTOH child_class_next() on AVCodecContext.av_class will ++ * iterate over all available codecs with private options. ++ * ++ * @subsection avoptions_implement_named_constants Named constants ++ * It is possible to create named constants for options. Simply set the unit ++ * field of the option the constants should apply to to a string and ++ * create the constants themselves as options of type AV_OPT_TYPE_CONST ++ * with their unit field set to the same string. ++ * Their default_val field should contain the value of the named ++ * constant. ++ * For example, to add some named constants for the test_flags option ++ * above, put the following into the child_opts array: ++ * @code ++ * { "test_flags", "This is a test option of flags type.", ++ * offsetof(child_struct, flags_opt), AV_OPT_TYPE_FLAGS, { 0 }, INT_MIN, INT_MAX, "test_unit" }, ++ * { "flag1", "This is a flag with value 16", 0, AV_OPT_TYPE_CONST, { 16 }, 0, 0, "test_unit" }, ++ * @endcode ++ * ++ * @section avoptions_use Using AVOptions ++ * This section deals with accessing options in an AVOptions-enabled struct. ++ * Such structs in FFmpeg are e.g. AVCodecContext in libavcodec or ++ * AVFormatContext in libavformat. ++ * ++ * @subsection avoptions_use_examine Examining AVOptions ++ * The basic functions for examining options are av_opt_next(), which iterates ++ * over all options defined for one object, and av_opt_find(), which searches ++ * for an option with the given name. ++ * ++ * The situation is more complicated with nesting. An AVOptions-enabled struct ++ * may have AVOptions-enabled children. Passing the AV_OPT_SEARCH_CHILDREN flag ++ * to av_opt_find() will make the function search children recursively. ++ * ++ * For enumerating there are basically two cases. The first is when you want to ++ * get all options that may potentially exist on the struct and its children ++ * (e.g. when constructing documentation). In that case you should call ++ * av_opt_child_class_next() recursively on the parent struct's AVClass. The ++ * second case is when you have an already initialized struct with all its ++ * children and you want to get all options that can be actually written or read ++ * from it. In that case you should call av_opt_child_next() recursively (and ++ * av_opt_next() on each result). ++ * ++ * @subsection avoptions_use_get_set Reading and writing AVOptions ++ * When setting options, you often have a string read directly from the ++ * user. In such a case, simply passing it to av_opt_set() is enough. For ++ * non-string type options, av_opt_set() will parse the string according to the ++ * option type. ++ * ++ * Similarly av_opt_get() will read any option type and convert it to a string ++ * which will be returned. Do not forget that the string is allocated, so you ++ * have to free it with av_free(). ++ * ++ * In some cases it may be more convenient to put all options into an ++ * AVDictionary and call av_opt_set_dict() on it. A specific case of this ++ * are the format/codec open functions in lavf/lavc which take a dictionary ++ * filled with option as a parameter. This allows to set some options ++ * that cannot be set otherwise, since e.g. the input file format is not known ++ * before the file is actually opened. ++ */ + + enum AVOptionType{ +- FF_OPT_TYPE_FLAGS, ++ AV_OPT_TYPE_FLAGS, ++ AV_OPT_TYPE_INT, ++ AV_OPT_TYPE_INT64, ++ AV_OPT_TYPE_DOUBLE, ++ AV_OPT_TYPE_FLOAT, ++ AV_OPT_TYPE_STRING, ++ AV_OPT_TYPE_RATIONAL, ++ AV_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length ++ AV_OPT_TYPE_CONST = 128, ++#if FF_API_OLD_AVOPTIONS ++ FF_OPT_TYPE_FLAGS = 0, + FF_OPT_TYPE_INT, + FF_OPT_TYPE_INT64, + FF_OPT_TYPE_DOUBLE, +@@ -40,6 +235,7 @@ + FF_OPT_TYPE_RATIONAL, + FF_OPT_TYPE_BINARY, ///< offset must point to a pointer immediately followed by an int for the length + FF_OPT_TYPE_CONST=128, ++#endif + }; + + /** +@@ -64,69 +260,23 @@ + /** + * the default value for scalar options + */ +- double default_val; +- double min; ///< minimum valid value for the option +- double max; ///< maximum valid value for the option +- +- int flags; +-#define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding +-#define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding +-#define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ... +-#define AV_OPT_FLAG_AUDIO_PARAM 8 +-#define AV_OPT_FLAG_VIDEO_PARAM 16 +-#define AV_OPT_FLAG_SUBTITLE_PARAM 32 +-//FIXME think about enc-audio, ... style flags +- +- /** +- * The logical unit to which the option belongs. Non-constant +- * options and corresponding named constants share the same +- * unit. May be NULL. +- */ +- const char *unit; +-} AVOption; +- +-/** +- * AVOption2. +- * THIS IS NOT PART OF THE API/ABI YET! +- * This is identical to AVOption except that default_val was replaced by +- * an union, it should be compatible with AVOption on normal platforms. +- */ +-typedef struct AVOption2 { +- const char *name; +- +- /** +- * short English help text +- * @todo What about other languages? +- */ +- const char *help; +- +- /** +- * The offset relative to the context structure where the option +- * value is stored. It should be 0 for named constants. +- */ +- int offset; +- enum AVOptionType type; +- +- /** +- * the default value for scalar options +- */ + union { + double dbl; + const char *str; ++ /* TODO those are unused now */ ++ int64_t i64; ++ AVRational q; + } default_val; +- + double min; ///< minimum valid value for the option + double max; ///< maximum valid value for the option + + int flags; +-/* + #define AV_OPT_FLAG_ENCODING_PARAM 1 ///< a generic parameter which can be set by the user for muxing or encoding + #define AV_OPT_FLAG_DECODING_PARAM 2 ///< a generic parameter which can be set by the user for demuxing or decoding + #define AV_OPT_FLAG_METADATA 4 ///< some data extracted or inserted into the file like title, comment, ... + #define AV_OPT_FLAG_AUDIO_PARAM 8 + #define AV_OPT_FLAG_VIDEO_PARAM 16 + #define AV_OPT_FLAG_SUBTITLE_PARAM 32 +-*/ + //FIXME think about enc-audio, ... style flags + + /** +@@ -135,9 +285,9 @@ + * unit. May be NULL. + */ + const char *unit; +-} AVOption2; +- ++} AVOption; + ++#if FF_API_FIND_OPT + /** + * Look for an option in obj. Look only for the options which + * have the flags set as specified in mask and flags (that is, +@@ -149,9 +299,14 @@ + * @param[in] unit the unit of the option to look for, or any if NULL + * @return a pointer to the option found, or NULL if no option + * has been found ++ * ++ * @deprecated use av_opt_find. + */ ++attribute_deprecated + const AVOption *av_find_opt(void *obj, const char *name, const char *unit, int mask, int flags); ++#endif + ++#if FF_API_OLD_AVOPTIONS + /** + * Set the field of obj with the given name to value. + * +@@ -170,25 +325,27 @@ + * similarly, '-' unsets a flag. + * @param[out] o_out if non-NULL put here a pointer to the AVOption + * found +- * @param alloc when 1 then the old value will be av_freed() and the +- * new av_strduped() +- * when 0 then no av_free() nor av_strdup() will be used ++ * @param alloc this parameter is currently ignored + * @return 0 if the value has been set, or an AVERROR code in case of + * error: +- * AVERROR(ENOENT) if no matching option exists ++ * AVERROR_OPTION_NOT_FOUND if no matching option exists + * AVERROR(ERANGE) if the value is out of range + * AVERROR(EINVAL) if the value is not valid ++ * @deprecated use av_opt_set() + */ ++attribute_deprecated + int av_set_string3(void *obj, const char *name, const char *val, int alloc, const AVOption **o_out); + +-const AVOption *av_set_double(void *obj, const char *name, double n); +-const AVOption *av_set_q(void *obj, const char *name, AVRational n); +-const AVOption *av_set_int(void *obj, const char *name, int64_t n); ++attribute_deprecated const AVOption *av_set_double(void *obj, const char *name, double n); ++attribute_deprecated const AVOption *av_set_q(void *obj, const char *name, AVRational n); ++attribute_deprecated const AVOption *av_set_int(void *obj, const char *name, int64_t n); ++ + double av_get_double(void *obj, const char *name, const AVOption **o_out); + AVRational av_get_q(void *obj, const char *name, const AVOption **o_out); + int64_t av_get_int(void *obj, const char *name, const AVOption **o_out); +-const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len); +-const AVOption *av_next_option(void *obj, const AVOption *last); ++attribute_deprecated const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len); ++attribute_deprecated const AVOption *av_next_option(void *obj, const AVOption *last); ++#endif + + /** + * Show the obj options. +@@ -201,8 +358,17 @@ + */ + int av_opt_show2(void *obj, void *av_log_obj, int req_flags, int rej_flags); + ++/** ++ * Set the values of all AVOption fields to their default values. ++ * ++ * @param s an AVOption-enabled struct (its first member must be a pointer to AVClass) ++ */ + void av_opt_set_defaults(void *s); ++ ++#if FF_API_OLD_AVOPTIONS ++attribute_deprecated + void av_opt_set_defaults2(void *s, int mask, int flags); ++#endif + + /** + * Parse the key/value pairs list in opts. For each key/value pair +@@ -210,6 +376,7 @@ + * key. ctx must be an AVClass context, storing is done using + * AVOptions. + * ++ * @param opts options string to parse, may be NULL + * @param key_val_sep a 0-terminated list of characters used to + * separate key from value + * @param pairs_sep a 0-terminated list of characters used to separate +@@ -223,4 +390,214 @@ + int av_set_options_string(void *ctx, const char *opts, + const char *key_val_sep, const char *pairs_sep); + ++/** ++ * Free all string and binary options in obj. ++ */ ++void av_opt_free(void *obj); ++ ++/** ++ * Check whether a particular flag is set in a flags field. ++ * ++ * @param field_name the name of the flag field option ++ * @param flag_name the name of the flag to check ++ * @return non-zero if the flag is set, zero if the flag isn't set, ++ * isn't of the right type, or the flags field doesn't exist. ++ */ ++int av_opt_flag_is_set(void *obj, const char *field_name, const char *flag_name); ++ ++/* ++ * Set all the options from a given dictionary on an object. ++ * ++ * @param obj a struct whose first element is a pointer to AVClass ++ * @param options options to process. This dictionary will be freed and replaced ++ * by a new one containing all options not found in obj. ++ * Of course this new dictionary needs to be freed by caller ++ * with av_dict_free(). ++ * ++ * @return 0 on success, a negative AVERROR if some option was found in obj, ++ * but could not be set. ++ * ++ * @see av_dict_copy() ++ */ ++int av_opt_set_dict(void *obj, struct AVDictionary **options); ++ ++/** ++ * @defgroup opt_eval_funcs Evaluating option strings ++ * @{ ++ * This group of functions can be used to evaluate option strings ++ * and get numbers out of them. They do the same thing as av_opt_set(), ++ * except the result is written into the caller-supplied pointer. ++ * ++ * @param obj a struct whose first element is a pointer to AVClass. ++ * @param o an option for which the string is to be evaluated. ++ * @param val string to be evaluated. ++ * @param *_out value of the string will be written here. ++ * ++ * @return 0 on success, a negative number on failure. ++ */ ++int av_opt_eval_flags (void *obj, const AVOption *o, const char *val, int *flags_out); ++int av_opt_eval_int (void *obj, const AVOption *o, const char *val, int *int_out); ++int av_opt_eval_int64 (void *obj, const AVOption *o, const char *val, int64_t *int64_out); ++int av_opt_eval_float (void *obj, const AVOption *o, const char *val, float *float_out); ++int av_opt_eval_double(void *obj, const AVOption *o, const char *val, double *double_out); ++int av_opt_eval_q (void *obj, const AVOption *o, const char *val, AVRational *q_out); ++/** ++ * @} ++ */ ++ ++#define AV_OPT_SEARCH_CHILDREN 0x0001 /**< Search in possible children of the ++ given object first. */ ++/** ++ * The obj passed to av_opt_find() is fake -- only a double pointer to AVClass ++ * instead of a required pointer to a struct containing AVClass. This is ++ * useful for searching for options without needing to allocate the corresponding ++ * object. ++ */ ++#define AV_OPT_SEARCH_FAKE_OBJ 0x0002 ++ ++/** ++ * Look for an option in an object. Consider only options which ++ * have all the specified flags set. ++ * ++ * @param[in] obj A pointer to a struct whose first element is a ++ * pointer to an AVClass. ++ * Alternatively a double pointer to an AVClass, if ++ * AV_OPT_SEARCH_FAKE_OBJ search flag is set. ++ * @param[in] name The name of the option to look for. ++ * @param[in] unit When searching for named constants, name of the unit ++ * it belongs to. ++ * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG). ++ * @param search_flags A combination of AV_OPT_SEARCH_*. ++ * ++ * @return A pointer to the option found, or NULL if no option ++ * was found. ++ * ++ * @note Options found with AV_OPT_SEARCH_CHILDREN flag may not be settable ++ * directly with av_set_string3(). Use special calls which take an options ++ * AVDictionary (e.g. avformat_open_input()) to set options found with this ++ * flag. ++ */ ++const AVOption *av_opt_find(void *obj, const char *name, const char *unit, ++ int opt_flags, int search_flags); ++ ++/** ++ * Look for an option in an object. Consider only options which ++ * have all the specified flags set. ++ * ++ * @param[in] obj A pointer to a struct whose first element is a ++ * pointer to an AVClass. ++ * Alternatively a double pointer to an AVClass, if ++ * AV_OPT_SEARCH_FAKE_OBJ search flag is set. ++ * @param[in] name The name of the option to look for. ++ * @param[in] unit When searching for named constants, name of the unit ++ * it belongs to. ++ * @param opt_flags Find only options with all the specified flags set (AV_OPT_FLAG). ++ * @param search_flags A combination of AV_OPT_SEARCH_*. ++ * @param[out] target_obj if non-NULL, an object to which the option belongs will be ++ * written here. It may be different from obj if AV_OPT_SEARCH_CHILDREN is present ++ * in search_flags. This parameter is ignored if search_flags contain ++ * AV_OPT_SEARCH_FAKE_OBJ. ++ * ++ * @return A pointer to the option found, or NULL if no option ++ * was found. ++ */ ++const AVOption *av_opt_find2(void *obj, const char *name, const char *unit, ++ int opt_flags, int search_flags, void **target_obj); ++ ++/** ++ * Iterate over all AVOptions belonging to obj. ++ * ++ * @param obj an AVOptions-enabled struct or a double pointer to an ++ * AVClass describing it. ++ * @param prev result of the previous call to av_opt_next() on this object ++ * or NULL ++ * @return next AVOption or NULL ++ */ ++const AVOption *av_opt_next(void *obj, const AVOption *prev); ++ ++/** ++ * Iterate over AVOptions-enabled children of obj. ++ * ++ * @param prev result of a previous call to this function or NULL ++ * @return next AVOptions-enabled child or NULL ++ */ ++void *av_opt_child_next(void *obj, void *prev); ++ ++/** ++ * Iterate over potential AVOptions-enabled children of parent. ++ * ++ * @param prev result of a previous call to this function or NULL ++ * @return AVClass corresponding to next potential child or NULL ++ */ ++const AVClass *av_opt_child_class_next(const AVClass *parent, const AVClass *prev); ++ ++/** ++ * @defgroup opt_set_funcs Option setting functions ++ * @{ ++ * Those functions set the field of obj with the given name to value. ++ * ++ * @param[in] obj A struct whose first element is a pointer to an AVClass. ++ * @param[in] name the name of the field to set ++ * @param[in] val The value to set. In case of av_opt_set() if the field is not ++ * of a string type, then the given string is parsed. ++ * SI postfixes and some named scalars are supported. ++ * If the field is of a numeric type, it has to be a numeric or named ++ * scalar. Behavior with more than one scalar and +- infix operators ++ * is undefined. ++ * If the field is of a flags type, it has to be a sequence of numeric ++ * scalars or named flags separated by '+' or '-'. Prefixing a flag ++ * with '+' causes it to be set without affecting the other flags; ++ * similarly, '-' unsets a flag. ++ * @param search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN ++ * is passed here, then the option may be set on a child of obj. ++ * ++ * @return 0 if the value has been set, or an AVERROR code in case of ++ * error: ++ * AVERROR_OPTION_NOT_FOUND if no matching option exists ++ * AVERROR(ERANGE) if the value is out of range ++ * AVERROR(EINVAL) if the value is not valid ++ */ ++int av_opt_set (void *obj, const char *name, const char *val, int search_flags); ++int av_opt_set_int (void *obj, const char *name, int64_t val, int search_flags); ++int av_opt_set_double(void *obj, const char *name, double val, int search_flags); ++int av_opt_set_q (void *obj, const char *name, AVRational val, int search_flags); ++/** ++ * @} ++ */ ++ ++/** ++ * @defgroup opt_get_funcs Option getting functions ++ * @{ ++ * Those functions get a value of the option with the given name from an object. ++ * ++ * @param[in] obj a struct whose first element is a pointer to an AVClass. ++ * @param[in] name name of the option to get. ++ * @param[in] search_flags flags passed to av_opt_find2. I.e. if AV_OPT_SEARCH_CHILDREN ++ * is passed here, then the option may be found in a child of obj. ++ * @param[out] out_val value of the option will be written here ++ * @return 0 on success, a negative error code otherwise ++ */ ++/** ++ * @note the returned string will av_malloc()ed and must be av_free()ed by the caller ++ */ ++int av_opt_get (void *obj, const char *name, int search_flags, uint8_t **out_val); ++int av_opt_get_int (void *obj, const char *name, int search_flags, int64_t *out_val); ++int av_opt_get_double(void *obj, const char *name, int search_flags, double *out_val); ++int av_opt_get_q (void *obj, const char *name, int search_flags, AVRational *out_val); ++/** ++ * @} ++ */ ++/** ++ * Gets a pointer to the requested field in a struct. ++ * This function allows accessing a struct even when its fields are moved or ++ * renamed since the application making the access has been compiled, ++ * ++ * @returns a pointer to the field, it can be cast to the correct type and read ++ * or written to. ++ */ ++void *av_opt_ptr(const AVClass *avclass, void *obj, const char *name); ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_OPT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/parseutils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/parseutils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/parseutils.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/parseutils.c 2012-05-14 14:08:55.328359987 +0200 +@@ -0,0 +1,757 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * misc parsing utilities ++ */ ++ ++#include ++#include ++ ++#include "avstring.h" ++#include "avutil.h" ++#include "eval.h" ++#include "log.h" ++#include "random_seed.h" ++#include "parseutils.h" ++ ++typedef struct { ++ const char *abbr; ++ int width, height; ++} VideoSizeAbbr; ++ ++typedef struct { ++ const char *abbr; ++ AVRational rate; ++} VideoRateAbbr; ++ ++static const VideoSizeAbbr video_size_abbrs[] = { ++ { "ntsc", 720, 480 }, ++ { "pal", 720, 576 }, ++ { "qntsc", 352, 240 }, /* VCD compliant NTSC */ ++ { "qpal", 352, 288 }, /* VCD compliant PAL */ ++ { "sntsc", 640, 480 }, /* square pixel NTSC */ ++ { "spal", 768, 576 }, /* square pixel PAL */ ++ { "film", 352, 240 }, ++ { "ntsc-film", 352, 240 }, ++ { "sqcif", 128, 96 }, ++ { "qcif", 176, 144 }, ++ { "cif", 352, 288 }, ++ { "4cif", 704, 576 }, ++ { "16cif", 1408,1152 }, ++ { "qqvga", 160, 120 }, ++ { "qvga", 320, 240 }, ++ { "vga", 640, 480 }, ++ { "svga", 800, 600 }, ++ { "xga", 1024, 768 }, ++ { "uxga", 1600,1200 }, ++ { "qxga", 2048,1536 }, ++ { "sxga", 1280,1024 }, ++ { "qsxga", 2560,2048 }, ++ { "hsxga", 5120,4096 }, ++ { "wvga", 852, 480 }, ++ { "wxga", 1366, 768 }, ++ { "wsxga", 1600,1024 }, ++ { "wuxga", 1920,1200 }, ++ { "woxga", 2560,1600 }, ++ { "wqsxga", 3200,2048 }, ++ { "wquxga", 3840,2400 }, ++ { "whsxga", 6400,4096 }, ++ { "whuxga", 7680,4800 }, ++ { "cga", 320, 200 }, ++ { "ega", 640, 350 }, ++ { "hd480", 852, 480 }, ++ { "hd720", 1280, 720 }, ++ { "hd1080", 1920,1080 }, ++}; ++ ++static const VideoRateAbbr video_rate_abbrs[]= { ++ { "ntsc", { 30000, 1001 } }, ++ { "pal", { 25, 1 } }, ++ { "qntsc", { 30000, 1001 } }, /* VCD compliant NTSC */ ++ { "qpal", { 25, 1 } }, /* VCD compliant PAL */ ++ { "sntsc", { 30000, 1001 } }, /* square pixel NTSC */ ++ { "spal", { 25, 1 } }, /* square pixel PAL */ ++ { "film", { 24, 1 } }, ++ { "ntsc-film", { 24000, 1001 } }, ++}; ++ ++int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str) ++{ ++ int i; ++ int n = FF_ARRAY_ELEMS(video_size_abbrs); ++ const char *p; ++ int width = 0, height = 0; ++ ++ for (i = 0; i < n; i++) { ++ if (!strcmp(video_size_abbrs[i].abbr, str)) { ++ width = video_size_abbrs[i].width; ++ height = video_size_abbrs[i].height; ++ break; ++ } ++ } ++ if (i == n) { ++ p = str; ++ width = strtol(p, (void*)&p, 10); ++ if (*p) ++ p++; ++ height = strtol(p, (void*)&p, 10); ++ } ++ if (width <= 0 || height <= 0) ++ return AVERROR(EINVAL); ++ *width_ptr = width; ++ *height_ptr = height; ++ return 0; ++} ++ ++int av_parse_video_rate(AVRational *rate, const char *arg) ++{ ++ int i, ret; ++ int n = FF_ARRAY_ELEMS(video_rate_abbrs); ++ double res; ++ ++ /* First, we check our abbreviation table */ ++ for (i = 0; i < n; ++i) ++ if (!strcmp(video_rate_abbrs[i].abbr, arg)) { ++ *rate = video_rate_abbrs[i].rate; ++ return 0; ++ } ++ ++ /* Then, we try to parse it as fraction */ ++ if ((ret = av_expr_parse_and_eval(&res, arg, NULL, NULL, NULL, NULL, NULL, NULL, ++ NULL, 0, NULL)) < 0) ++ return ret; ++ *rate = av_d2q(res, 1001000); ++ if (rate->num <= 0 || rate->den <= 0) ++ return AVERROR(EINVAL); ++ return 0; ++} ++ ++typedef struct { ++ const char *name; ///< a string representing the name of the color ++ uint8_t rgb_color[3]; ///< RGB values for the color ++} ColorEntry; ++ ++static const ColorEntry color_table[] = { ++ { "AliceBlue", { 0xF0, 0xF8, 0xFF } }, ++ { "AntiqueWhite", { 0xFA, 0xEB, 0xD7 } }, ++ { "Aqua", { 0x00, 0xFF, 0xFF } }, ++ { "Aquamarine", { 0x7F, 0xFF, 0xD4 } }, ++ { "Azure", { 0xF0, 0xFF, 0xFF } }, ++ { "Beige", { 0xF5, 0xF5, 0xDC } }, ++ { "Bisque", { 0xFF, 0xE4, 0xC4 } }, ++ { "Black", { 0x00, 0x00, 0x00 } }, ++ { "BlanchedAlmond", { 0xFF, 0xEB, 0xCD } }, ++ { "Blue", { 0x00, 0x00, 0xFF } }, ++ { "BlueViolet", { 0x8A, 0x2B, 0xE2 } }, ++ { "Brown", { 0xA5, 0x2A, 0x2A } }, ++ { "BurlyWood", { 0xDE, 0xB8, 0x87 } }, ++ { "CadetBlue", { 0x5F, 0x9E, 0xA0 } }, ++ { "Chartreuse", { 0x7F, 0xFF, 0x00 } }, ++ { "Chocolate", { 0xD2, 0x69, 0x1E } }, ++ { "Coral", { 0xFF, 0x7F, 0x50 } }, ++ { "CornflowerBlue", { 0x64, 0x95, 0xED } }, ++ { "Cornsilk", { 0xFF, 0xF8, 0xDC } }, ++ { "Crimson", { 0xDC, 0x14, 0x3C } }, ++ { "Cyan", { 0x00, 0xFF, 0xFF } }, ++ { "DarkBlue", { 0x00, 0x00, 0x8B } }, ++ { "DarkCyan", { 0x00, 0x8B, 0x8B } }, ++ { "DarkGoldenRod", { 0xB8, 0x86, 0x0B } }, ++ { "DarkGray", { 0xA9, 0xA9, 0xA9 } }, ++ { "DarkGreen", { 0x00, 0x64, 0x00 } }, ++ { "DarkKhaki", { 0xBD, 0xB7, 0x6B } }, ++ { "DarkMagenta", { 0x8B, 0x00, 0x8B } }, ++ { "DarkOliveGreen", { 0x55, 0x6B, 0x2F } }, ++ { "Darkorange", { 0xFF, 0x8C, 0x00 } }, ++ { "DarkOrchid", { 0x99, 0x32, 0xCC } }, ++ { "DarkRed", { 0x8B, 0x00, 0x00 } }, ++ { "DarkSalmon", { 0xE9, 0x96, 0x7A } }, ++ { "DarkSeaGreen", { 0x8F, 0xBC, 0x8F } }, ++ { "DarkSlateBlue", { 0x48, 0x3D, 0x8B } }, ++ { "DarkSlateGray", { 0x2F, 0x4F, 0x4F } }, ++ { "DarkTurquoise", { 0x00, 0xCE, 0xD1 } }, ++ { "DarkViolet", { 0x94, 0x00, 0xD3 } }, ++ { "DeepPink", { 0xFF, 0x14, 0x93 } }, ++ { "DeepSkyBlue", { 0x00, 0xBF, 0xFF } }, ++ { "DimGray", { 0x69, 0x69, 0x69 } }, ++ { "DodgerBlue", { 0x1E, 0x90, 0xFF } }, ++ { "FireBrick", { 0xB2, 0x22, 0x22 } }, ++ { "FloralWhite", { 0xFF, 0xFA, 0xF0 } }, ++ { "ForestGreen", { 0x22, 0x8B, 0x22 } }, ++ { "Fuchsia", { 0xFF, 0x00, 0xFF } }, ++ { "Gainsboro", { 0xDC, 0xDC, 0xDC } }, ++ { "GhostWhite", { 0xF8, 0xF8, 0xFF } }, ++ { "Gold", { 0xFF, 0xD7, 0x00 } }, ++ { "GoldenRod", { 0xDA, 0xA5, 0x20 } }, ++ { "Gray", { 0x80, 0x80, 0x80 } }, ++ { "Green", { 0x00, 0x80, 0x00 } }, ++ { "GreenYellow", { 0xAD, 0xFF, 0x2F } }, ++ { "HoneyDew", { 0xF0, 0xFF, 0xF0 } }, ++ { "HotPink", { 0xFF, 0x69, 0xB4 } }, ++ { "IndianRed", { 0xCD, 0x5C, 0x5C } }, ++ { "Indigo", { 0x4B, 0x00, 0x82 } }, ++ { "Ivory", { 0xFF, 0xFF, 0xF0 } }, ++ { "Khaki", { 0xF0, 0xE6, 0x8C } }, ++ { "Lavender", { 0xE6, 0xE6, 0xFA } }, ++ { "LavenderBlush", { 0xFF, 0xF0, 0xF5 } }, ++ { "LawnGreen", { 0x7C, 0xFC, 0x00 } }, ++ { "LemonChiffon", { 0xFF, 0xFA, 0xCD } }, ++ { "LightBlue", { 0xAD, 0xD8, 0xE6 } }, ++ { "LightCoral", { 0xF0, 0x80, 0x80 } }, ++ { "LightCyan", { 0xE0, 0xFF, 0xFF } }, ++ { "LightGoldenRodYellow", { 0xFA, 0xFA, 0xD2 } }, ++ { "LightGrey", { 0xD3, 0xD3, 0xD3 } }, ++ { "LightGreen", { 0x90, 0xEE, 0x90 } }, ++ { "LightPink", { 0xFF, 0xB6, 0xC1 } }, ++ { "LightSalmon", { 0xFF, 0xA0, 0x7A } }, ++ { "LightSeaGreen", { 0x20, 0xB2, 0xAA } }, ++ { "LightSkyBlue", { 0x87, 0xCE, 0xFA } }, ++ { "LightSlateGray", { 0x77, 0x88, 0x99 } }, ++ { "LightSteelBlue", { 0xB0, 0xC4, 0xDE } }, ++ { "LightYellow", { 0xFF, 0xFF, 0xE0 } }, ++ { "Lime", { 0x00, 0xFF, 0x00 } }, ++ { "LimeGreen", { 0x32, 0xCD, 0x32 } }, ++ { "Linen", { 0xFA, 0xF0, 0xE6 } }, ++ { "Magenta", { 0xFF, 0x00, 0xFF } }, ++ { "Maroon", { 0x80, 0x00, 0x00 } }, ++ { "MediumAquaMarine", { 0x66, 0xCD, 0xAA } }, ++ { "MediumBlue", { 0x00, 0x00, 0xCD } }, ++ { "MediumOrchid", { 0xBA, 0x55, 0xD3 } }, ++ { "MediumPurple", { 0x93, 0x70, 0xD8 } }, ++ { "MediumSeaGreen", { 0x3C, 0xB3, 0x71 } }, ++ { "MediumSlateBlue", { 0x7B, 0x68, 0xEE } }, ++ { "MediumSpringGreen", { 0x00, 0xFA, 0x9A } }, ++ { "MediumTurquoise", { 0x48, 0xD1, 0xCC } }, ++ { "MediumVioletRed", { 0xC7, 0x15, 0x85 } }, ++ { "MidnightBlue", { 0x19, 0x19, 0x70 } }, ++ { "MintCream", { 0xF5, 0xFF, 0xFA } }, ++ { "MistyRose", { 0xFF, 0xE4, 0xE1 } }, ++ { "Moccasin", { 0xFF, 0xE4, 0xB5 } }, ++ { "NavajoWhite", { 0xFF, 0xDE, 0xAD } }, ++ { "Navy", { 0x00, 0x00, 0x80 } }, ++ { "OldLace", { 0xFD, 0xF5, 0xE6 } }, ++ { "Olive", { 0x80, 0x80, 0x00 } }, ++ { "OliveDrab", { 0x6B, 0x8E, 0x23 } }, ++ { "Orange", { 0xFF, 0xA5, 0x00 } }, ++ { "OrangeRed", { 0xFF, 0x45, 0x00 } }, ++ { "Orchid", { 0xDA, 0x70, 0xD6 } }, ++ { "PaleGoldenRod", { 0xEE, 0xE8, 0xAA } }, ++ { "PaleGreen", { 0x98, 0xFB, 0x98 } }, ++ { "PaleTurquoise", { 0xAF, 0xEE, 0xEE } }, ++ { "PaleVioletRed", { 0xD8, 0x70, 0x93 } }, ++ { "PapayaWhip", { 0xFF, 0xEF, 0xD5 } }, ++ { "PeachPuff", { 0xFF, 0xDA, 0xB9 } }, ++ { "Peru", { 0xCD, 0x85, 0x3F } }, ++ { "Pink", { 0xFF, 0xC0, 0xCB } }, ++ { "Plum", { 0xDD, 0xA0, 0xDD } }, ++ { "PowderBlue", { 0xB0, 0xE0, 0xE6 } }, ++ { "Purple", { 0x80, 0x00, 0x80 } }, ++ { "Red", { 0xFF, 0x00, 0x00 } }, ++ { "RosyBrown", { 0xBC, 0x8F, 0x8F } }, ++ { "RoyalBlue", { 0x41, 0x69, 0xE1 } }, ++ { "SaddleBrown", { 0x8B, 0x45, 0x13 } }, ++ { "Salmon", { 0xFA, 0x80, 0x72 } }, ++ { "SandyBrown", { 0xF4, 0xA4, 0x60 } }, ++ { "SeaGreen", { 0x2E, 0x8B, 0x57 } }, ++ { "SeaShell", { 0xFF, 0xF5, 0xEE } }, ++ { "Sienna", { 0xA0, 0x52, 0x2D } }, ++ { "Silver", { 0xC0, 0xC0, 0xC0 } }, ++ { "SkyBlue", { 0x87, 0xCE, 0xEB } }, ++ { "SlateBlue", { 0x6A, 0x5A, 0xCD } }, ++ { "SlateGray", { 0x70, 0x80, 0x90 } }, ++ { "Snow", { 0xFF, 0xFA, 0xFA } }, ++ { "SpringGreen", { 0x00, 0xFF, 0x7F } }, ++ { "SteelBlue", { 0x46, 0x82, 0xB4 } }, ++ { "Tan", { 0xD2, 0xB4, 0x8C } }, ++ { "Teal", { 0x00, 0x80, 0x80 } }, ++ { "Thistle", { 0xD8, 0xBF, 0xD8 } }, ++ { "Tomato", { 0xFF, 0x63, 0x47 } }, ++ { "Turquoise", { 0x40, 0xE0, 0xD0 } }, ++ { "Violet", { 0xEE, 0x82, 0xEE } }, ++ { "Wheat", { 0xF5, 0xDE, 0xB3 } }, ++ { "White", { 0xFF, 0xFF, 0xFF } }, ++ { "WhiteSmoke", { 0xF5, 0xF5, 0xF5 } }, ++ { "Yellow", { 0xFF, 0xFF, 0x00 } }, ++ { "YellowGreen", { 0x9A, 0xCD, 0x32 } }, ++}; ++ ++static int color_table_compare(const void *lhs, const void *rhs) ++{ ++ return av_strcasecmp(lhs, ((const ColorEntry *)rhs)->name); ++} ++ ++#define ALPHA_SEP '@' ++ ++int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, ++ void *log_ctx) ++{ ++ char *tail, color_string2[128]; ++ const ColorEntry *entry; ++ int len, hex_offset = 0; ++ ++ if (color_string[0] == '#') { ++ hex_offset = 1; ++ } else if (!strncmp(color_string, "0x", 2)) ++ hex_offset = 2; ++ ++ if (slen < 0) ++ slen = strlen(color_string); ++ av_strlcpy(color_string2, color_string + hex_offset, ++ FFMIN(slen-hex_offset+1, sizeof(color_string2))); ++ if ((tail = strchr(color_string2, ALPHA_SEP))) ++ *tail++ = 0; ++ len = strlen(color_string2); ++ rgba_color[3] = 255; ++ ++ if (!av_strcasecmp(color_string2, "random") || !av_strcasecmp(color_string2, "bikeshed")) { ++ int rgba = av_get_random_seed(); ++ rgba_color[0] = rgba >> 24; ++ rgba_color[1] = rgba >> 16; ++ rgba_color[2] = rgba >> 8; ++ rgba_color[3] = rgba; ++ } else if (hex_offset || ++ strspn(color_string2, "0123456789ABCDEFabcdef") == len) { ++ char *tail; ++ unsigned int rgba = strtoul(color_string2, &tail, 16); ++ ++ if (*tail || (len != 6 && len != 8)) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid 0xRRGGBB[AA] color string: '%s'\n", color_string2); ++ return AVERROR(EINVAL); ++ } ++ if (len == 8) { ++ rgba_color[3] = rgba; ++ rgba >>= 8; ++ } ++ rgba_color[0] = rgba >> 16; ++ rgba_color[1] = rgba >> 8; ++ rgba_color[2] = rgba; ++ } else { ++ entry = bsearch(color_string2, ++ color_table, ++ FF_ARRAY_ELEMS(color_table), ++ sizeof(ColorEntry), ++ color_table_compare); ++ if (!entry) { ++ av_log(log_ctx, AV_LOG_ERROR, "Cannot find color '%s'\n", color_string2); ++ return AVERROR(EINVAL); ++ } ++ memcpy(rgba_color, entry->rgb_color, 3); ++ } ++ ++ if (tail) { ++ unsigned long int alpha; ++ const char *alpha_string = tail; ++ if (!strncmp(alpha_string, "0x", 2)) { ++ alpha = strtoul(alpha_string, &tail, 16); ++ } else { ++ alpha = 255 * strtod(alpha_string, &tail); ++ } ++ ++ if (tail == alpha_string || *tail || alpha > 255) { ++ av_log(log_ctx, AV_LOG_ERROR, "Invalid alpha value specifier '%s' in '%s'\n", ++ alpha_string, color_string); ++ return AVERROR(EINVAL); ++ } ++ rgba_color[3] = alpha; ++ } ++ ++ return 0; ++} ++ ++/* get a positive number between n_min and n_max, for a maximum length ++ of len_max. Return -1 if error. */ ++static int date_get_num(const char **pp, ++ int n_min, int n_max, int len_max) ++{ ++ int i, val, c; ++ const char *p; ++ ++ p = *pp; ++ val = 0; ++ for(i = 0; i < len_max; i++) { ++ c = *p; ++ if (!isdigit(c)) ++ break; ++ val = (val * 10) + c - '0'; ++ p++; ++ } ++ /* no number read ? */ ++ if (p == *pp) ++ return -1; ++ if (val < n_min || val > n_max) ++ return -1; ++ *pp = p; ++ return val; ++} ++ ++/** ++ * Parse the input string p according to the format string fmt and ++ * store its results in the structure dt. ++ * This implementation supports only a subset of the formats supported ++ * by the standard strptime(). ++ * ++ * @return a pointer to the first character not processed in this ++ * function call, or NULL in case the function fails to match all of ++ * the fmt string and therefore an error occurred ++ */ ++static const char *small_strptime(const char *p, const char *fmt, struct tm *dt) ++{ ++ int c, val; ++ ++ for(;;) { ++ c = *fmt++; ++ if (c == '\0') { ++ return p; ++ } else if (c == '%') { ++ c = *fmt++; ++ switch(c) { ++ case 'H': ++ val = date_get_num(&p, 0, 23, 2); ++ if (val == -1) ++ return NULL; ++ dt->tm_hour = val; ++ break; ++ case 'M': ++ val = date_get_num(&p, 0, 59, 2); ++ if (val == -1) ++ return NULL; ++ dt->tm_min = val; ++ break; ++ case 'S': ++ val = date_get_num(&p, 0, 59, 2); ++ if (val == -1) ++ return NULL; ++ dt->tm_sec = val; ++ break; ++ case 'Y': ++ val = date_get_num(&p, 0, 9999, 4); ++ if (val == -1) ++ return NULL; ++ dt->tm_year = val - 1900; ++ break; ++ case 'm': ++ val = date_get_num(&p, 1, 12, 2); ++ if (val == -1) ++ return NULL; ++ dt->tm_mon = val - 1; ++ break; ++ case 'd': ++ val = date_get_num(&p, 1, 31, 2); ++ if (val == -1) ++ return NULL; ++ dt->tm_mday = val; ++ break; ++ case '%': ++ goto match; ++ default: ++ return NULL; ++ } ++ } else { ++ match: ++ if (c != *p) ++ return NULL; ++ p++; ++ } ++ } ++} ++ ++time_t av_timegm(struct tm *tm) ++{ ++ time_t t; ++ ++ int y = tm->tm_year + 1900, m = tm->tm_mon + 1, d = tm->tm_mday; ++ ++ if (m < 3) { ++ m += 12; ++ y--; ++ } ++ ++ t = 86400 * ++ (d + (153 * m - 457) / 5 + 365 * y + y / 4 - y / 100 + y / 400 - 719469); ++ ++ t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec; ++ ++ return t; ++} ++ ++int av_parse_time(int64_t *timeval, const char *timestr, int duration) ++{ ++ const char *p; ++ int64_t t; ++ struct tm dt; ++ int i; ++ static const char * const date_fmt[] = { ++ "%Y-%m-%d", ++ "%Y%m%d", ++ }; ++ static const char * const time_fmt[] = { ++ "%H:%M:%S", ++ "%H%M%S", ++ }; ++ const char *q; ++ int is_utc, len; ++ char lastch; ++ int negative = 0; ++ ++#undef time ++ time_t now = time(0); ++ ++ len = strlen(timestr); ++ if (len > 0) ++ lastch = timestr[len - 1]; ++ else ++ lastch = '\0'; ++ is_utc = (lastch == 'z' || lastch == 'Z'); ++ ++ memset(&dt, 0, sizeof(dt)); ++ ++ p = timestr; ++ q = NULL; ++ if (!duration) { ++ if (!av_strncasecmp(timestr, "now", len)) { ++ *timeval = (int64_t) now * 1000000; ++ return 0; ++ } ++ ++ /* parse the year-month-day part */ ++ for (i = 0; i < FF_ARRAY_ELEMS(date_fmt); i++) { ++ q = small_strptime(p, date_fmt[i], &dt); ++ if (q) { ++ break; ++ } ++ } ++ ++ /* if the year-month-day part is missing, then take the ++ * current year-month-day time */ ++ if (!q) { ++ if (is_utc) { ++ dt = *gmtime(&now); ++ } else { ++ dt = *localtime(&now); ++ } ++ dt.tm_hour = dt.tm_min = dt.tm_sec = 0; ++ } else { ++ p = q; ++ } ++ ++ if (*p == 'T' || *p == 't' || *p == ' ') ++ p++; ++ ++ /* parse the hour-minute-second part */ ++ for (i = 0; i < FF_ARRAY_ELEMS(time_fmt); i++) { ++ q = small_strptime(p, time_fmt[i], &dt); ++ if (q) { ++ break; ++ } ++ } ++ } else { ++ /* parse timestr as a duration */ ++ if (p[0] == '-') { ++ negative = 1; ++ ++p; ++ } ++ /* parse timestr as HH:MM:SS */ ++ q = small_strptime(p, time_fmt[0], &dt); ++ if (!q) { ++ /* parse timestr as S+ */ ++ dt.tm_sec = strtol(p, (void *)&q, 10); ++ if (q == p) { ++ /* the parsing didn't succeed */ ++ *timeval = INT64_MIN; ++ return AVERROR(EINVAL); ++ } ++ dt.tm_min = 0; ++ dt.tm_hour = 0; ++ } ++ } ++ ++ /* Now we have all the fields that we can get */ ++ if (!q) { ++ *timeval = INT64_MIN; ++ return AVERROR(EINVAL); ++ } ++ ++ if (duration) { ++ t = dt.tm_hour * 3600 + dt.tm_min * 60 + dt.tm_sec; ++ } else { ++ dt.tm_isdst = -1; /* unknown */ ++ if (is_utc) { ++ t = av_timegm(&dt); ++ } else { ++ t = mktime(&dt); ++ } ++ } ++ ++ t *= 1000000; ++ ++ /* parse the .m... part */ ++ if (*q == '.') { ++ int val, n; ++ q++; ++ for (val = 0, n = 100000; n >= 1; n /= 10, q++) { ++ if (!isdigit(*q)) ++ break; ++ val += n * (*q - '0'); ++ } ++ t += val; ++ } ++ *timeval = negative ? -t : t; ++ return 0; ++} ++ ++int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info) ++{ ++ const char *p; ++ char tag[128], *q; ++ ++ p = info; ++ if (*p == '?') ++ p++; ++ for(;;) { ++ q = tag; ++ while (*p != '\0' && *p != '=' && *p != '&') { ++ if ((q - tag) < sizeof(tag) - 1) ++ *q++ = *p; ++ p++; ++ } ++ *q = '\0'; ++ q = arg; ++ if (*p == '=') { ++ p++; ++ while (*p != '&' && *p != '\0') { ++ if ((q - arg) < arg_size - 1) { ++ if (*p == '+') ++ *q++ = ' '; ++ else ++ *q++ = *p; ++ } ++ p++; ++ } ++ } ++ *q = '\0'; ++ if (!strcmp(tag, tag1)) ++ return 1; ++ if (*p != '&') ++ break; ++ p++; ++ } ++ return 0; ++} ++ ++#ifdef TEST ++ ++#undef printf ++ ++int main(void) ++{ ++ printf("Testing av_parse_video_rate()\n"); ++ { ++ int i; ++ const char *rates[] = { ++ "-inf", ++ "inf", ++ "nan", ++ "123/0", ++ "-123 / 0", ++ "", ++ "/", ++ " 123 / 321", ++ "foo/foo", ++ "foo/1", ++ "1/foo", ++ "0/0", ++ "/0", ++ "1/", ++ "1", ++ "0", ++ "-123/123", ++ "-foo", ++ "123.23", ++ ".23", ++ "-.23", ++ "-0.234", ++ "-0.0000001", ++ " 21332.2324 ", ++ " -21332.2324 ", ++ }; ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(rates); i++) { ++ int ret; ++ AVRational q = (AVRational){0, 0}; ++ ret = av_parse_video_rate(&q, rates[i]), ++ printf("'%s' -> %d/%d ret:%d\n", ++ rates[i], q.num, q.den, ret); ++ } ++ } ++ ++ printf("\nTesting av_parse_color()\n"); ++ { ++ int i; ++ uint8_t rgba[4]; ++ const char *color_names[] = { ++ "bikeshed", ++ "RaNdOm", ++ "foo", ++ "red", ++ "Red ", ++ "RED", ++ "Violet", ++ "Yellow", ++ "Red", ++ "0x000000", ++ "0x0000000", ++ "0xff000000", ++ "0x3e34ff", ++ "0x3e34ffaa", ++ "0xffXXee", ++ "0xfoobar", ++ "0xffffeeeeeeee", ++ "#ff0000", ++ "#ffXX00", ++ "ff0000", ++ "ffXX00", ++ "red@foo", ++ "random@10", ++ "0xff0000@1.0", ++ "red@", ++ "red@0xfff", ++ "red@0xf", ++ "red@2", ++ "red@0.1", ++ "red@-1", ++ "red@0.5", ++ "red@1.0", ++ "red@256", ++ "red@10foo", ++ "red@-1.0", ++ "red@-0.0", ++ }; ++ ++ av_log_set_level(AV_LOG_DEBUG); ++ ++ for (i = 0; i < FF_ARRAY_ELEMS(color_names); i++) { ++ if (av_parse_color(rgba, color_names[i], -1, NULL) >= 0) ++ printf("%s -> R(%d) G(%d) B(%d) A(%d)\n", color_names[i], rgba[0], rgba[1], rgba[2], rgba[3]); ++ } ++ } ++ ++ return 0; ++} ++ ++#endif /* TEST */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/parseutils.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/parseutils.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/parseutils.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/parseutils.h 2012-05-14 14:08:55.328359987 +0200 +@@ -0,0 +1,124 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVUTIL_PARSEUTILS_H ++#define AVUTIL_PARSEUTILS_H ++ ++#include ++ ++#include "rational.h" ++ ++/** ++ * @file ++ * misc parsing utilities ++ */ ++ ++/** ++ * Parse str and put in width_ptr and height_ptr the detected values. ++ * ++ * @param[in,out] width_ptr pointer to the variable which will contain the detected ++ * width value ++ * @param[in,out] height_ptr pointer to the variable which will contain the detected ++ * height value ++ * @param[in] str the string to parse: it has to be a string in the format ++ * width x height or a valid video size abbreviation. ++ * @return >= 0 on success, a negative error code otherwise ++ */ ++int av_parse_video_size(int *width_ptr, int *height_ptr, const char *str); ++ ++/** ++ * Parse str and store the detected values in *rate. ++ * ++ * @param[in,out] rate pointer to the AVRational which will contain the detected ++ * frame rate ++ * @param[in] str the string to parse: it has to be a string in the format ++ * rate_num / rate_den, a float number or a valid video rate abbreviation ++ * @return >= 0 on success, a negative error code otherwise ++ */ ++int av_parse_video_rate(AVRational *rate, const char *str); ++ ++/** ++ * Put the RGBA values that correspond to color_string in rgba_color. ++ * ++ * @param color_string a string specifying a color. It can be the name of ++ * a color (case insensitive match) or a [0x|#]RRGGBB[AA] sequence, ++ * possibly followed by "@" and a string representing the alpha ++ * component. ++ * The alpha component may be a string composed by "0x" followed by an ++ * hexadecimal number or a decimal number between 0.0 and 1.0, which ++ * represents the opacity value (0x00/0.0 means completely transparent, ++ * 0xff/1.0 completely opaque). ++ * If the alpha component is not specified then 0xff is assumed. ++ * The string "random" will result in a random color. ++ * @param slen length of the initial part of color_string containing the ++ * color. It can be set to -1 if color_string is a null terminated string ++ * containing nothing else than the color. ++ * @return >= 0 in case of success, a negative value in case of ++ * failure (for example if color_string cannot be parsed). ++ */ ++int av_parse_color(uint8_t *rgba_color, const char *color_string, int slen, ++ void *log_ctx); ++ ++/** ++ * Parse timestr and return in *time a corresponding number of ++ * microseconds. ++ * ++ * @param timeval puts here the number of microseconds corresponding ++ * to the string in timestr. If the string represents a duration, it ++ * is the number of microseconds contained in the time interval. If ++ * the string is a date, is the number of microseconds since 1st of ++ * January, 1970 up to the time of the parsed date. If timestr cannot ++ * be successfully parsed, set *time to INT64_MIN. ++ ++ * @param timestr a string representing a date or a duration. ++ * - If a date the syntax is: ++ * @code ++ * [{YYYY-MM-DD|YYYYMMDD}[T|t| ]]{{HH[:MM[:SS[.m...]]]}|{HH[MM[SS[.m...]]]}}[Z] ++ * now ++ * @endcode ++ * If the value is "now" it takes the current time. ++ * Time is local time unless Z is appended, in which case it is ++ * interpreted as UTC. ++ * If the year-month-day part is not specified it takes the current ++ * year-month-day. ++ * - If a duration the syntax is: ++ * @code ++ * [-]HH[:MM[:SS[.m...]]] ++ * [-]S+[.m...] ++ * @endcode ++ * @param duration flag which tells how to interpret timestr, if not ++ * zero timestr is interpreted as a duration, otherwise as a date ++ * @return 0 in case of success, a negative value corresponding to an ++ * AVERROR code otherwise ++ */ ++int av_parse_time(int64_t *timeval, const char *timestr, int duration); ++ ++/** ++ * Attempt to find a specific tag in a URL. ++ * ++ * syntax: '?tag1=val1&tag2=val2...'. Little URL decoding is done. ++ * Return 1 if found. ++ */ ++int av_find_info_tag(char *arg, int arg_size, const char *tag1, const char *info); ++ ++/** ++ * Convert the decomposed UTC time in tm to a time_t value. ++ */ ++time_t av_timegm(struct tm *tm); ++ ++#endif /* AVUTIL_PARSEUTILS_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pca.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pca.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pca.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pca.c 2012-05-14 14:08:55.329360007 +0200 +@@ -218,7 +218,6 @@ + printf("\n"); + } + +-#if 1 + for(i=0; icomp[c]; +- int plane= comp.plane; +- int depth= comp.depth_minus1+1; +- int mask = (1<flags; +- +- if (flags & PIX_FMT_BITSTREAM){ +- int skip = x*step + comp.offset_plus1-1; +- const uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); +- int shift = 8 - depth - (skip&7); ++ AVComponentDescriptor comp = desc->comp[c]; ++ int plane = comp.plane; ++ int depth = comp.depth_minus1 + 1; ++ int mask = (1 << depth) - 1; ++ int shift = comp.shift; ++ int step = comp.step_minus1 + 1; ++ int flags = desc->flags; ++ ++ if (flags & PIX_FMT_BITSTREAM) { ++ int skip = x * step + comp.offset_plus1 - 1; ++ const uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3); ++ int shift = 8 - depth - (skip & 7); + +- while(w--){ ++ while (w--) { + int val = (*p >> shift) & mask; +- if(read_pal_component) +- val= data[1][4*val + c]; ++ if (read_pal_component) ++ val = data[1][4*val + c]; + shift -= step; +- p -= shift>>3; ++ p -= shift >> 3; + shift &= 7; +- *dst++= val; ++ *dst++ = val; + } + } else { +- const uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; ++ const uint8_t *p = data[plane] + y * linesize[plane] + x * step + comp.offset_plus1 - 1; + int is_8bit = shift + depth <= 8; + + if (is_8bit) + p += !!(flags & PIX_FMT_BE); + +- while(w--){ ++ while (w--) { + int val = is_8bit ? *p : + flags & PIX_FMT_BE ? AV_RB16(p) : AV_RL16(p); +- val = (val>>shift) & mask; +- if(read_pal_component) +- val= data[1][4*val + c]; +- p+= step; +- *dst++= val; ++ val = (val >> shift) & mask; ++ if (read_pal_component) ++ val = data[1][4 * val + c]; ++ p += step; ++ *dst++ = val; + } + } + } +@@ -75,41 +76,41 @@ + { + AVComponentDescriptor comp = desc->comp[c]; + int plane = comp.plane; +- int depth = comp.depth_minus1+1; +- int step = comp.step_minus1+1; ++ int depth = comp.depth_minus1 + 1; ++ int step = comp.step_minus1 + 1; + int flags = desc->flags; + + if (flags & PIX_FMT_BITSTREAM) { +- int skip = x*step + comp.offset_plus1-1; +- uint8_t *p = data[plane] + y*linesize[plane] + (skip>>3); +- int shift = 8 - depth - (skip&7); ++ int skip = x * step + comp.offset_plus1 - 1; ++ uint8_t *p = data[plane] + y * linesize[plane] + (skip >> 3); ++ int shift = 8 - depth - (skip & 7); + + while (w--) { + *p |= *src++ << shift; + shift -= step; +- p -= shift>>3; ++ p -= shift >> 3; + shift &= 7; + } + } else { + int shift = comp.shift; +- uint8_t *p = data[plane]+ y*linesize[plane] + x*step + comp.offset_plus1-1; ++ uint8_t *p = data[plane] + y * linesize[plane] + x * step + comp.offset_plus1 - 1; + + if (shift + depth <= 8) { + p += !!(flags & PIX_FMT_BE); + while (w--) { +- *p |= (*src++<log2_chroma_w + pixdesc->log2_chroma_h; + + for (c = 0; c < pixdesc->nb_components; c++) { +- int s = c==1 || c==2 ? 0 : log2_pixels; +- bits += (pixdesc->comp[c].depth_minus1+1) << s; ++ int s = c == 1 || c == 2 ? 0 : log2_pixels; ++ bits += (pixdesc->comp[c].depth_minus1 + 1) << s; + } + + return bits >> log2_pixels; +@@ -856,11 +1266,11 @@ + { + /* print header */ + if (pix_fmt < 0) { +- snprintf (buf, buf_size, "name " " nb_components" " nb_bits"); ++ snprintf (buf, buf_size, "name" " nb_components" " nb_bits"); + } else { + const AVPixFmtDescriptor *pixdesc = &av_pix_fmt_descriptors[pix_fmt]; +- snprintf(buf, buf_size, "%-11s %7d %10d", +- pixdesc->name, pixdesc->nb_components, av_get_bits_per_pixel(pixdesc)); ++ snprintf(buf, buf_size, "%-11s %7d %10d", pixdesc->name, ++ pixdesc->nb_components, av_get_bits_per_pixel(pixdesc)); + } + + return buf; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pixdesc.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pixdesc.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.h 2012-05-14 14:08:55.334360108 +0200 +@@ -23,6 +23,7 @@ + #define AVUTIL_PIXDESC_H + + #include ++#include "pixfmt.h" + + typedef struct AVComponentDescriptor{ + uint16_t plane :2; ///< which of the 4 planes contains the component +@@ -86,6 +87,8 @@ + #define PIX_FMT_PAL 2 ///< Pixel format has a palette in data[1], values are indexes in this palette. + #define PIX_FMT_BITSTREAM 4 ///< All values of a component are bit-wise packed end to end. + #define PIX_FMT_HWACCEL 8 ///< Pixel format is an HW accelerated format. ++#define PIX_FMT_PLANAR 16 ///< At least one pixel component is not in the first data plane ++#define PIX_FMT_RGB 32 ///< The pixel format contains RGB-like data (as opposed to YUV/grayscale) + + /** + * The array of all the pixel format descriptors. +@@ -142,6 +145,14 @@ + enum PixelFormat av_get_pix_fmt(const char *name); + + /** ++ * Return the short name for a pixel format, NULL in case pix_fmt is ++ * unknown. ++ * ++ * @see av_get_pix_fmt(), av_get_pix_fmt_string() ++ */ ++const char *av_get_pix_fmt_name(enum PixelFormat pix_fmt); ++ ++/** + * Print in buf the string corresponding to the pixel format with + * number pix_fmt, or an header if pix_fmt is negative. + * +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pixfmt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/pixfmt.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h 2012-05-14 14:08:55.335360129 +0200 +@@ -25,21 +25,21 @@ + * @file + * pixel format definitions + * +- * @warning This file has to be considered an internal but installed +- * header, so it should not be directly included in your projects. + */ + + #include "libavutil/avconfig.h" + + /** +- * Pixel format. Notes: ++ * Pixel format. + * ++ * @note + * PIX_FMT_RGB32 is handled in an endian-specific manner. An RGBA + * color is put together as: + * (A << 24) | (R << 16) | (G << 8) | B + * This is stored as BGRA on little-endian CPU architectures and ARGB on + * big-endian CPUs. + * ++ * @par + * When the pixel format is palettized RGB (PIX_FMT_PAL8), the palettized + * image data is stored in AVFrame.data[0]. The palette is transported in + * AVFrame.data[1], is 1024 bytes long (256 4-byte entries) and is +@@ -49,13 +49,15 @@ + * This is important as many custom PAL8 video codecs that were designed + * to run on the IBM VGA graphics adapter use 6-bit palette components. + * ++ * @par + * For all the 8bit per pixel formats, an RGB32 palette is in data[1] like + * for pal8. This palette is filled in automatically by the function + * allocating the picture. + * +- * Note, make sure that all newly added big endian formats have pix_fmt&1==1 +- * and that all newly added little endian formats have pix_fmt&1==0 +- * this allows simpler detection of big vs little endian. ++ * @note ++ * make sure that all newly added big endian formats have pix_fmt&1==1 ++ * and that all newly added little endian formats have pix_fmt&1==0 ++ * this allows simpler detection of big vs little endian. + */ + enum PixelFormat { + PIX_FMT_NONE= -1, +@@ -128,14 +130,61 @@ + PIX_FMT_VDPAU_MPEG4, ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers + PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer + +- PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 + PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 +- PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1 ++ PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 + PIX_FMT_BGR444LE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), little-endian, most significant bits to 1 +- PIX_FMT_Y400A, ///< 8bit gray, 8bit alpha ++ PIX_FMT_BGR444BE, ///< packed BGR 4:4:4, 16bpp, (msb)4A 4B 4G 4R(lsb), big-endian, most significant bits to 1 ++ PIX_FMT_GRAY8A, ///< 8bit gray, 8bit alpha ++ PIX_FMT_BGR48BE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as big-endian ++ PIX_FMT_BGR48LE, ///< packed RGB 16:16:16, 48bpp, 16B, 16G, 16R, the 2-byte value for each R/G/B component is stored as little-endian ++ ++ //the following 10 formats have the disadvantage of needing 1 format for each bit depth, thus ++ //If you want to support multiple bit depths, then using PIX_FMT_YUV420P16* with the bpp stored seperately ++ //is better ++ PIX_FMT_YUV420P9BE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian ++ PIX_FMT_YUV420P9LE, ///< planar YUV 4:2:0, 13.5bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian ++ PIX_FMT_YUV420P10BE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), big-endian ++ PIX_FMT_YUV420P10LE,///< planar YUV 4:2:0, 15bpp, (1 Cr & Cb sample per 2x2 Y samples), little-endian ++ PIX_FMT_YUV422P10BE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian ++ PIX_FMT_YUV422P10LE,///< planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian ++ PIX_FMT_YUV444P9BE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian ++ PIX_FMT_YUV444P9LE, ///< planar YUV 4:4:4, 27bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian ++ PIX_FMT_YUV444P10BE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian ++ PIX_FMT_YUV444P10LE,///< planar YUV 4:4:4, 30bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian ++ PIX_FMT_YUV422P9BE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian ++ PIX_FMT_YUV422P9LE, ///< planar YUV 4:2:2, 18bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian ++ PIX_FMT_VDA_VLD, ///< hardware decoding through VDA ++ ++#ifdef AV_PIX_FMT_ABI_GIT_MASTER ++ PIX_FMT_RGBA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian ++ PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian ++ PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian ++ PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian ++#endif ++ PIX_FMT_GBRP, ///< planar GBR 4:4:4 24bpp ++ PIX_FMT_GBRP9BE, ///< planar GBR 4:4:4 27bpp, big endian ++ PIX_FMT_GBRP9LE, ///< planar GBR 4:4:4 27bpp, little endian ++ PIX_FMT_GBRP10BE, ///< planar GBR 4:4:4 30bpp, big endian ++ PIX_FMT_GBRP10LE, ///< planar GBR 4:4:4 30bpp, little endian ++ PIX_FMT_GBRP16BE, ///< planar GBR 4:4:4 48bpp, big endian ++ PIX_FMT_GBRP16LE, ///< planar GBR 4:4:4 48bpp, little endian ++ ++#ifndef AV_PIX_FMT_ABI_GIT_MASTER ++ PIX_FMT_RGBA64BE=0x123, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian ++ PIX_FMT_RGBA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16R, 16G, 16B, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian ++ PIX_FMT_BGRA64BE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as big-endian ++ PIX_FMT_BGRA64LE, ///< packed RGBA 16:16:16:16, 64bpp, 16B, 16G, 16R, 16A, the 2-byte value for each R/G/B/A component is stored as little-endian ++#endif ++ PIX_FMT_0RGB=0x123+4, ///< packed RGB 8:8:8, 32bpp, 0RGB0RGB... ++ PIX_FMT_RGB0, ///< packed RGB 8:8:8, 32bpp, RGB0RGB0... ++ PIX_FMT_0BGR, ///< packed BGR 8:8:8, 32bpp, 0BGR0BGR... ++ PIX_FMT_BGR0, ///< packed BGR 8:8:8, 32bpp, BGR0BGR0... + PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions + }; + ++#define PIX_FMT_Y400A PIX_FMT_GRAY8A ++#define PIX_FMT_GBR24P PIX_FMT_GBRP ++ + #if AV_HAVE_BIGENDIAN + # define PIX_FMT_NE(be, le) PIX_FMT_##be + #else +@@ -146,18 +195,33 @@ + #define PIX_FMT_RGB32_1 PIX_FMT_NE(RGBA, ABGR) + #define PIX_FMT_BGR32 PIX_FMT_NE(ABGR, RGBA) + #define PIX_FMT_BGR32_1 PIX_FMT_NE(BGRA, ARGB) ++#define PIX_FMT_0RGB32 PIX_FMT_NE(0RGB, BGR0) ++#define PIX_FMT_0BGR32 PIX_FMT_NE(0BGR, RGB0) + + #define PIX_FMT_GRAY16 PIX_FMT_NE(GRAY16BE, GRAY16LE) + #define PIX_FMT_RGB48 PIX_FMT_NE(RGB48BE, RGB48LE) + #define PIX_FMT_RGB565 PIX_FMT_NE(RGB565BE, RGB565LE) + #define PIX_FMT_RGB555 PIX_FMT_NE(RGB555BE, RGB555LE) + #define PIX_FMT_RGB444 PIX_FMT_NE(RGB444BE, RGB444LE) ++#define PIX_FMT_BGR48 PIX_FMT_NE(BGR48BE, BGR48LE) + #define PIX_FMT_BGR565 PIX_FMT_NE(BGR565BE, BGR565LE) + #define PIX_FMT_BGR555 PIX_FMT_NE(BGR555BE, BGR555LE) + #define PIX_FMT_BGR444 PIX_FMT_NE(BGR444BE, BGR444LE) + ++#define PIX_FMT_YUV420P9 PIX_FMT_NE(YUV420P9BE , YUV420P9LE) ++#define PIX_FMT_YUV422P9 PIX_FMT_NE(YUV422P9BE , YUV422P9LE) ++#define PIX_FMT_YUV444P9 PIX_FMT_NE(YUV444P9BE , YUV444P9LE) ++#define PIX_FMT_YUV420P10 PIX_FMT_NE(YUV420P10BE, YUV420P10LE) ++#define PIX_FMT_YUV422P10 PIX_FMT_NE(YUV422P10BE, YUV422P10LE) ++#define PIX_FMT_YUV444P10 PIX_FMT_NE(YUV444P10BE, YUV444P10LE) + #define PIX_FMT_YUV420P16 PIX_FMT_NE(YUV420P16BE, YUV420P16LE) + #define PIX_FMT_YUV422P16 PIX_FMT_NE(YUV422P16BE, YUV422P16LE) + #define PIX_FMT_YUV444P16 PIX_FMT_NE(YUV444P16BE, YUV444P16LE) + ++#define PIX_FMT_RGBA64 PIX_FMT_NE(RGBA64BE, RGBA64LE) ++#define PIX_FMT_BGRA64 PIX_FMT_NE(BGRA64BE, BGRA64LE) ++#define PIX_FMT_GBRP9 PIX_FMT_NE(GBRP9BE , GBRP9LE) ++#define PIX_FMT_GBRP10 PIX_FMT_NE(GBRP10BE, GBRP10LE) ++#define PIX_FMT_GBRP16 PIX_FMT_NE(GBRP16BE, GBRP16LE) ++ + #endif /* AVUTIL_PIXFMT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/ppc/cpu.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/ppc/cpu.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/ppc/cpu.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/ppc/cpu.c 2012-05-14 14:08:55.335360129 +0200 +@@ -17,7 +17,6 @@ + */ + + #ifdef __APPLE__ +-#undef _POSIX_C_SOURCE + #include + #elif defined(__OpenBSD__) + #include +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/random_seed.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/random_seed.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/random_seed.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/random_seed.c 2012-05-14 14:08:55.336360149 +0200 +@@ -20,10 +20,10 @@ + + #include + #include ++#include ++#include + #include "timer.h" +-#include "time.h" + #include "random_seed.h" +-#include "avutil.h" + + static int read_random(uint32_t *dst, const char *file) + { +@@ -40,24 +40,24 @@ + + static uint32_t get_generic_seed(void) + { +- clock_t last_t=0; +- int bits=0; +- uint64_t random=0; ++ clock_t last_t = 0; ++ int bits = 0; ++ uint64_t random = 0; + unsigned i; +- float s=0.000000000001; ++ float s = 0.000000000001; + +- for(i=0;bits<64;i++){ +- clock_t t= clock(); +- if(last_t && fabs(t-last_t)>s || t==(clock_t)-1){ +- if(i<10000 && s<(1<<24)){ +- s+=s; +- i=t=0; +- }else{ +- random= 2*random + (i&1); ++ for (i = 0; bits < 64; i++) { ++ clock_t t = clock(); ++ if (last_t && fabs(t - last_t) > s || t == (clock_t) -1) { ++ if (i < 10000 && s < (1 << 24)) { ++ s += s; ++ i = t = 0; ++ } else { ++ random = 2 * random + (i & 1); + bits++; + } + } +- last_t= t; ++ last_t = t; + } + #ifdef AV_READ_TIME + random ^= AV_READ_TIME(); +@@ -65,7 +65,7 @@ + random ^= clock(); + #endif + +- random += random>>32; ++ random += random >> 32; + + return random; + } +@@ -80,11 +80,3 @@ + return seed; + return get_generic_seed(); + } +- +-#if LIBAVUTIL_VERSION_MAJOR < 51 +-attribute_deprecated uint32_t ff_random_get_seed(void); +-uint32_t ff_random_get_seed(void) +-{ +- return av_get_random_seed(); +-} +-#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/random_seed.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/random_seed.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/random_seed.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/random_seed.h 2012-05-14 14:08:55.337360169 +0200 +@@ -22,10 +22,22 @@ + #define AVUTIL_RANDOM_SEED_H + + #include ++/** ++ * @addtogroup lavu_crypto ++ * @{ ++ */ + + /** + * Get a seed to use in conjunction with random functions. ++ * This function tries to provide a good seed at a best effort bases. ++ * Its possible to call this function multiple times if more bits are needed. ++ * It can be quite slow, which is why it should only be used as seed for a faster ++ * PRNG. The quality of the seed depends on the platform. + */ + uint32_t av_get_random_seed(void); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_RANDOM_SEED_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rational.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rational.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rational.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rational.c 2012-05-14 14:08:55.338360189 +0200 +@@ -33,75 +33,86 @@ + #include "mathematics.h" + #include "rational.h" + +-int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max){ +- AVRational a0={0,1}, a1={1,0}; +- int sign= (num<0) ^ (den<0); +- int64_t gcd= av_gcd(FFABS(num), FFABS(den)); +- +- if(gcd){ +- num = FFABS(num)/gcd; +- den = FFABS(den)/gcd; ++int av_reduce(int *dst_num, int *dst_den, ++ int64_t num, int64_t den, int64_t max) ++{ ++ AVRational a0 = { 0, 1 }, a1 = { 1, 0 }; ++ int sign = (num < 0) ^ (den < 0); ++ int64_t gcd = av_gcd(FFABS(num), FFABS(den)); ++ ++ if (gcd) { ++ num = FFABS(num) / gcd; ++ den = FFABS(den) / gcd; + } +- if(num<=max && den<=max){ +- a1= (AVRational){num, den}; +- den=0; ++ if (num <= max && den <= max) { ++ a1 = (AVRational) { num, den }; ++ den = 0; + } + +- while(den){ +- uint64_t x = num / den; +- int64_t next_den= num - den*x; +- int64_t a2n= x*a1.num + a0.num; +- int64_t a2d= x*a1.den + a0.den; +- +- if(a2n > max || a2d > max){ +- if(a1.num) x= (max - a0.num) / a1.num; +- if(a1.den) x= FFMIN(x, (max - a0.den) / a1.den); ++ while (den) { ++ uint64_t x = num / den; ++ int64_t next_den = num - den * x; ++ int64_t a2n = x * a1.num + a0.num; ++ int64_t a2d = x * a1.den + a0.den; ++ ++ if (a2n > max || a2d > max) { ++ if (a1.num) x = (max - a0.num) / a1.num; ++ if (a1.den) x = FFMIN(x, (max - a0.den) / a1.den); + +- if (den*(2*x*a1.den + a0.den) > num*a1.den) +- a1 = (AVRational){x*a1.num + a0.num, x*a1.den + a0.den}; ++ if (den * (2 * x * a1.den + a0.den) > num * a1.den) ++ a1 = (AVRational) { x * a1.num + a0.num, x * a1.den + a0.den }; + break; + } + +- a0= a1; +- a1= (AVRational){a2n, a2d}; +- num= den; +- den= next_den; ++ a0 = a1; ++ a1 = (AVRational) { a2n, a2d }; ++ num = den; ++ den = next_den; + } + av_assert2(av_gcd(a1.num, a1.den) <= 1U); + + *dst_num = sign ? -a1.num : a1.num; + *dst_den = a1.den; + +- return den==0; ++ return den == 0; + } + +-AVRational av_mul_q(AVRational b, AVRational c){ +- av_reduce(&b.num, &b.den, b.num * (int64_t)c.num, b.den * (int64_t)c.den, INT_MAX); ++AVRational av_mul_q(AVRational b, AVRational c) ++{ ++ av_reduce(&b.num, &b.den, ++ b.num * (int64_t) c.num, ++ b.den * (int64_t) c.den, INT_MAX); + return b; + } + +-AVRational av_div_q(AVRational b, AVRational c){ +- return av_mul_q(b, (AVRational){c.den, c.num}); ++AVRational av_div_q(AVRational b, AVRational c) ++{ ++ return av_mul_q(b, (AVRational) { c.den, c.num }); + } + +-AVRational av_add_q(AVRational b, AVRational c){ +- av_reduce(&b.num, &b.den, b.num * (int64_t)c.den + c.num * (int64_t)b.den, b.den * (int64_t)c.den, INT_MAX); ++AVRational av_add_q(AVRational b, AVRational c) { ++ av_reduce(&b.num, &b.den, ++ b.num * (int64_t) c.den + ++ c.num * (int64_t) b.den, ++ b.den * (int64_t) c.den, INT_MAX); + return b; + } + +-AVRational av_sub_q(AVRational b, AVRational c){ +- return av_add_q(b, (AVRational){-c.num, c.den}); ++AVRational av_sub_q(AVRational b, AVRational c) ++{ ++ return av_add_q(b, (AVRational) { -c.num, c.den }); + } + +-AVRational av_d2q(double d, int max){ ++AVRational av_d2q(double d, int max) ++{ + AVRational a; + #define LOG2 0.69314718055994530941723212145817656807550013436025 + int exponent; + int64_t den; + if (isnan(d)) +- return (AVRational){0,0}; ++ return (AVRational) { 0,0 }; + if (isinf(d)) +- return (AVRational){ d<0 ? -1:1, 0 }; ++ return (AVRational) { d < 0 ? -1 : 1, 0 }; + exponent = FFMAX( (int)(log(fabs(d) + 1e-20)/LOG2), 0); + den = 1LL << (61 - exponent); + av_reduce(&a.num, &a.den, (int64_t)(d * den + 0.5), den, max); +@@ -127,7 +138,7 @@ + int av_find_nearest_q_idx(AVRational q, const AVRational* q_list) + { + int i, nearest_q_idx = 0; +- for(i=0; q_list[i].den; i++) ++ for (i = 0; q_list[i].den; i++) + if (av_nearer_q(q, q_list[i], q_list[nearest_q_idx]) > 0) + nearest_q_idx = i; + +@@ -135,21 +146,26 @@ + } + + #ifdef TEST +-main(){ ++int main(void) ++{ + AVRational a,b; +- for(a.num=-2; a.num<=2; a.num++){ +- for(a.den=-2; a.den<=2; a.den++){ +- for(b.num=-2; b.num<=2; b.num++){ +- for(b.den=-2; b.den<=2; b.den++){ +- int c= av_cmp_q(a,b); +- double d= av_q2d(a) == av_q2d(b) ? 0 : (av_q2d(a) - av_q2d(b)); +- if(d>0) d=1; +- else if(d<0) d=-1; +- else if(d != d) d= INT_MIN; +- if(c!=d) av_log(0, AV_LOG_ERROR, "%d/%d %d/%d, %d %f\n", a.num, a.den, b.num, b.den, c,d); ++ for (a.num = -2; a.num <= 2; a.num++) { ++ for (a.den = -2; a.den <= 2; a.den++) { ++ for (b.num = -2; b.num <= 2; b.num++) { ++ for (b.den = -2; b.den <= 2; b.den++) { ++ int c = av_cmp_q(a,b); ++ double d = av_q2d(a) == av_q2d(b) ? ++ 0 : (av_q2d(a) - av_q2d(b)); ++ if (d > 0) d = 1; ++ else if (d < 0) d = -1; ++ else if (d != d) d = INT_MIN; ++ if (c != d) ++ av_log(0, AV_LOG_ERROR, "%d/%d %d/%d, %d %f\n", a.num, ++ a.den, b.num, b.den, c,d); + } + } + } + } ++ return 0; + } + #endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rational.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rational.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rational.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rational.h 2012-05-14 14:08:55.338360189 +0200 +@@ -33,6 +33,11 @@ + #include "attributes.h" + + /** ++ * @addtogroup lavu_math ++ * @{ ++ */ ++ ++/** + * rational number numerator/denominator + */ + typedef struct AVRational{ +@@ -132,4 +137,8 @@ + */ + int av_find_nearest_q_idx(AVRational q, const AVRational* q_list); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_RATIONAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rc4.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rc4.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/rc4.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/rc4.h 2012-05-14 14:08:55.339360209 +0200 +@@ -29,21 +29,21 @@ + }; + + /** +- * \brief Initializes an AVRC4 context. ++ * @brief Initializes an AVRC4 context. + * +- * \param key_bits must be a multiple of 8 +- * \param decrypt 0 for encryption, 1 for decryption, currently has no effect ++ * @param key_bits must be a multiple of 8 ++ * @param decrypt 0 for encryption, 1 for decryption, currently has no effect + */ + int av_rc4_init(struct AVRC4 *d, const uint8_t *key, int key_bits, int decrypt); + + /** +- * \brief Encrypts / decrypts using the RC4 algorithm. ++ * @brief Encrypts / decrypts using the RC4 algorithm. + * +- * \param count number of bytes +- * \param dst destination array, can be equal to src +- * \param src source array, can be equal to dst, may be NULL +- * \param iv not (yet) used for RC4, should be NULL +- * \param decrypt 0 for encryption, 1 for decryption, not (yet) used ++ * @param count number of bytes ++ * @param dst destination array, can be equal to src ++ * @param src source array, can be equal to dst, may be NULL ++ * @param iv not (yet) used for RC4, should be NULL ++ * @param decrypt 0 for encryption, 1 for decryption, not (yet) used + */ + void av_rc4_crypt(struct AVRC4 *d, uint8_t *dst, const uint8_t *src, int count, uint8_t *iv, int decrypt); + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/samplefmt.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/samplefmt.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/samplefmt.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/samplefmt.c 2012-05-14 14:08:55.340360229 +0200 +@@ -0,0 +1,169 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "samplefmt.h" ++ ++#include ++#include ++#include ++ ++typedef struct SampleFmtInfo { ++ char name[8]; ++ int bits; ++ int planar; ++ enum AVSampleFormat altform; ///< planar<->packed alternative form ++} SampleFmtInfo; ++ ++/** this table gives more information about formats */ ++static const SampleFmtInfo sample_fmt_info[AV_SAMPLE_FMT_NB] = { ++ [AV_SAMPLE_FMT_U8] = { .name = "u8", .bits = 8, .planar = 0, .altform = AV_SAMPLE_FMT_U8P }, ++ [AV_SAMPLE_FMT_S16] = { .name = "s16", .bits = 16, .planar = 0, .altform = AV_SAMPLE_FMT_S16P }, ++ [AV_SAMPLE_FMT_S32] = { .name = "s32", .bits = 32, .planar = 0, .altform = AV_SAMPLE_FMT_S32P }, ++ [AV_SAMPLE_FMT_FLT] = { .name = "flt", .bits = 32, .planar = 0, .altform = AV_SAMPLE_FMT_FLTP }, ++ [AV_SAMPLE_FMT_DBL] = { .name = "dbl", .bits = 64, .planar = 0, .altform = AV_SAMPLE_FMT_DBLP }, ++ [AV_SAMPLE_FMT_U8P] = { .name = "u8p", .bits = 8, .planar = 1, .altform = AV_SAMPLE_FMT_U8 }, ++ [AV_SAMPLE_FMT_S16P] = { .name = "s16p", .bits = 16, .planar = 1, .altform = AV_SAMPLE_FMT_S16 }, ++ [AV_SAMPLE_FMT_S32P] = { .name = "s32p", .bits = 32, .planar = 1, .altform = AV_SAMPLE_FMT_S32 }, ++ [AV_SAMPLE_FMT_FLTP] = { .name = "fltp", .bits = 32, .planar = 1, .altform = AV_SAMPLE_FMT_FLT }, ++ [AV_SAMPLE_FMT_DBLP] = { .name = "dblp", .bits = 64, .planar = 1, .altform = AV_SAMPLE_FMT_DBL }, ++}; ++ ++const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt) ++{ ++ if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) ++ return NULL; ++ return sample_fmt_info[sample_fmt].name; ++} ++ ++enum AVSampleFormat av_get_sample_fmt(const char *name) ++{ ++ int i; ++ ++ for (i = 0; i < AV_SAMPLE_FMT_NB; i++) ++ if (!strcmp(sample_fmt_info[i].name, name)) ++ return i; ++ return AV_SAMPLE_FMT_NONE; ++} ++ ++enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar) ++{ ++ if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) ++ return AV_SAMPLE_FMT_NONE; ++ if (sample_fmt_info[sample_fmt].planar == planar) ++ return sample_fmt; ++ return sample_fmt_info[sample_fmt].altform; ++} ++ ++char *av_get_sample_fmt_string (char *buf, int buf_size, enum AVSampleFormat sample_fmt) ++{ ++ /* print header */ ++ if (sample_fmt < 0) ++ snprintf(buf, buf_size, "name " " depth"); ++ else if (sample_fmt < AV_SAMPLE_FMT_NB) { ++ SampleFmtInfo info = sample_fmt_info[sample_fmt]; ++ snprintf (buf, buf_size, "%-6s" " %2d ", info.name, info.bits); ++ } ++ ++ return buf; ++} ++ ++int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt) ++{ ++ return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? ++ 0 : sample_fmt_info[sample_fmt].bits >> 3; ++} ++ ++#if FF_API_GET_BITS_PER_SAMPLE_FMT ++int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt) ++{ ++ return sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB ? ++ 0 : sample_fmt_info[sample_fmt].bits; ++} ++#endif ++ ++int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt) ++{ ++ if (sample_fmt < 0 || sample_fmt >= AV_SAMPLE_FMT_NB) ++ return 0; ++ return sample_fmt_info[sample_fmt].planar; ++} ++ ++int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, ++ enum AVSampleFormat sample_fmt, int align) ++{ ++ int line_size; ++ int sample_size = av_get_bytes_per_sample(sample_fmt); ++ int planar = av_sample_fmt_is_planar(sample_fmt); ++ ++ /* validate parameter ranges */ ++ if (!sample_size || nb_samples <= 0 || nb_channels <= 0) ++ return AVERROR(EINVAL); ++ ++ /* check for integer overflow */ ++ if (nb_channels > INT_MAX / align || ++ (int64_t)nb_channels * nb_samples > (INT_MAX - (align * nb_channels)) / sample_size) ++ return AVERROR(EINVAL); ++ ++ line_size = planar ? FFALIGN(nb_samples * sample_size, align) : ++ FFALIGN(nb_samples * sample_size * nb_channels, align); ++ if (linesize) ++ *linesize = line_size; ++ ++ return planar ? line_size * nb_channels : line_size; ++} ++ ++int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, ++ uint8_t *buf, int nb_channels, int nb_samples, ++ enum AVSampleFormat sample_fmt, int align) ++{ ++ int ch, planar, buf_size; ++ ++ planar = av_sample_fmt_is_planar(sample_fmt); ++ buf_size = av_samples_get_buffer_size(linesize, nb_channels, nb_samples, ++ sample_fmt, align); ++ if (buf_size < 0) ++ return buf_size; ++ ++ audio_data[0] = buf; ++ for (ch = 1; planar && ch < nb_channels; ch++) ++ audio_data[ch] = audio_data[ch-1] + *linesize; ++ ++ return 0; ++} ++ ++int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels, ++ int nb_samples, enum AVSampleFormat sample_fmt, int align) ++{ ++ uint8_t *buf; ++ int size = av_samples_get_buffer_size(NULL, nb_channels, nb_samples, ++ sample_fmt, align); ++ if (size < 0) ++ return size; ++ ++ buf = av_mallocz(size); ++ if (!buf) ++ return AVERROR(ENOMEM); ++ ++ size = av_samples_fill_arrays(audio_data, linesize, buf, nb_channels, ++ nb_samples, sample_fmt, align); ++ if (size < 0) { ++ av_free(buf); ++ return size; ++ } ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/samplefmt.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/samplefmt.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/samplefmt.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/samplefmt.h 2012-05-14 14:08:55.340360229 +0200 +@@ -0,0 +1,156 @@ ++/* ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVUTIL_SAMPLEFMT_H ++#define AVUTIL_SAMPLEFMT_H ++ ++#include "avutil.h" ++ ++/** ++ * all in native-endian format ++ */ ++enum AVSampleFormat { ++ AV_SAMPLE_FMT_NONE = -1, ++ AV_SAMPLE_FMT_U8, ///< unsigned 8 bits ++ AV_SAMPLE_FMT_S16, ///< signed 16 bits ++ AV_SAMPLE_FMT_S32, ///< signed 32 bits ++ AV_SAMPLE_FMT_FLT, ///< float ++ AV_SAMPLE_FMT_DBL, ///< double ++ ++ AV_SAMPLE_FMT_U8P, ///< unsigned 8 bits, planar ++ AV_SAMPLE_FMT_S16P, ///< signed 16 bits, planar ++ AV_SAMPLE_FMT_S32P, ///< signed 32 bits, planar ++ AV_SAMPLE_FMT_FLTP, ///< float, planar ++ AV_SAMPLE_FMT_DBLP, ///< double, planar ++ ++ AV_SAMPLE_FMT_NB ///< Number of sample formats. DO NOT USE if linking dynamically ++}; ++ ++/** ++ * Return the name of sample_fmt, or NULL if sample_fmt is not ++ * recognized. ++ */ ++const char *av_get_sample_fmt_name(enum AVSampleFormat sample_fmt); ++ ++/** ++ * Return a sample format corresponding to name, or AV_SAMPLE_FMT_NONE ++ * on error. ++ */ ++enum AVSampleFormat av_get_sample_fmt(const char *name); ++ ++/** ++ * Return the planar<->packed alternative form of the given sample format, or ++ * AV_SAMPLE_FMT_NONE on error. If the passed sample_fmt is already in the ++ * requested planar/packed format, the format returned is the same as the ++ * input. ++ */ ++enum AVSampleFormat av_get_alt_sample_fmt(enum AVSampleFormat sample_fmt, int planar); ++ ++/** ++ * Generate a string corresponding to the sample format with ++ * sample_fmt, or a header if sample_fmt is negative. ++ * ++ * @param buf the buffer where to write the string ++ * @param buf_size the size of buf ++ * @param sample_fmt the number of the sample format to print the ++ * corresponding info string, or a negative value to print the ++ * corresponding header. ++ * @return the pointer to the filled buffer or NULL if sample_fmt is ++ * unknown or in case of other errors ++ */ ++char *av_get_sample_fmt_string(char *buf, int buf_size, enum AVSampleFormat sample_fmt); ++ ++#if FF_API_GET_BITS_PER_SAMPLE_FMT ++/** ++ * @deprecated Use av_get_bytes_per_sample() instead. ++ */ ++attribute_deprecated ++int av_get_bits_per_sample_fmt(enum AVSampleFormat sample_fmt); ++#endif ++ ++/** ++ * Return number of bytes per sample. ++ * ++ * @param sample_fmt the sample format ++ * @return number of bytes per sample or zero if unknown for the given ++ * sample format ++ */ ++int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt); ++ ++/** ++ * Check if the sample format is planar. ++ * ++ * @param sample_fmt the sample format to inspect ++ * @return 1 if the sample format is planar, 0 if it is interleaved ++ */ ++int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt); ++ ++/** ++ * Get the required buffer size for the given audio parameters. ++ * ++ * @param[out] linesize calculated linesize, may be NULL ++ * @param nb_channels the number of channels ++ * @param nb_samples the number of samples in a single channel ++ * @param sample_fmt the sample format ++ * @return required buffer size, or negative error code on failure ++ */ ++int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, ++ enum AVSampleFormat sample_fmt, int align); ++ ++/** ++ * Fill channel data pointers and linesize for samples with sample ++ * format sample_fmt. ++ * ++ * The pointers array is filled with the pointers to the samples data: ++ * for planar, set the start point of each channel's data within the buffer, ++ * for packed, set the start point of the entire buffer only. ++ * ++ * The linesize array is filled with the aligned size of each channel's data ++ * buffer for planar layout, or the aligned size of the buffer for all channels ++ * for packed layout. ++ * ++ * @param[out] audio_data array to be filled with the pointer for each channel ++ * @param[out] linesize calculated linesize ++ * @param buf the pointer to a buffer containing the samples ++ * @param nb_channels the number of channels ++ * @param nb_samples the number of samples in a single channel ++ * @param sample_fmt the sample format ++ * @param align buffer size alignment (1 = no alignment required) ++ * @return 0 on success or a negative error code on failure ++ */ ++int av_samples_fill_arrays(uint8_t **audio_data, int *linesize, uint8_t *buf, ++ int nb_channels, int nb_samples, ++ enum AVSampleFormat sample_fmt, int align); ++ ++/** ++ * Allocate a samples buffer for nb_samples samples, and fill data pointers and ++ * linesize accordingly. ++ * The allocated samples buffer can be freed by using av_freep(&audio_data[0]) ++ * ++ * @param[out] audio_data array to be filled with the pointer for each channel ++ * @param[out] linesize aligned size for audio buffer(s) ++ * @param nb_channels number of audio channels ++ * @param nb_samples number of samples per channel ++ * @param align buffer size alignment (1 = no alignment required) ++ * @return 0 on success or a negative error code on failure ++ * @see av_samples_fill_arrays() ++ */ ++int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels, ++ int nb_samples, enum AVSampleFormat sample_fmt, int align); ++ ++#endif /* AVUTIL_SAMPLEFMT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha1.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha1.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha1.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha1.h 1970-01-01 01:00:00.000000000 +0100 +@@ -1,57 +0,0 @@ +-/* +- * Copyright (C) 2007 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#ifndef AVUTIL_SHA1_H +-#define AVUTIL_SHA1_H +- +-#include +- +-extern const int av_sha1_size; +- +-struct AVSHA1; +- +-/** +- * Initialize SHA-1 hashing. +- * +- * @param context pointer to the function context (of size av_sha_size) +- * @deprecated use av_sha_init() instead +- */ +-void av_sha1_init(struct AVSHA1* context); +- +-/** +- * Update hash value. +- * +- * @param context hash function context +- * @param data input data to update hash with +- * @param len input data length +- * @deprecated use av_sha_update() instead +- */ +-void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len); +- +-/** +- * Finish hashing and output digest value. +- * +- * @param context hash function context +- * @param digest buffer where output digest value is stored +- * @deprecated use av_sha_final() instead +- */ +-void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]); +- +-#endif /* AVUTIL_SHA1_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha.c 2012-05-14 14:08:55.341360249 +0200 +@@ -25,7 +25,6 @@ + #include "avutil.h" + #include "bswap.h" + #include "sha.h" +-#include "sha1.h" + #include "intreadwrite.h" + + /** hash context */ +@@ -43,7 +42,7 @@ + #define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + + /* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +-#define blk0(i) (block[i] = av_be2ne32(((const uint32_t*)buffer)[i])) ++#define blk0(i) (block[i] = AV_RB32(buffer + 4 * (i))) + #define blk(i) (block[i] = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1)) + + #define R0(v,w,x,y,z,i) z += ((w&(x^y))^y) + blk0(i) + 0x5A827999 + rol(v, 5); w = rol(w, 30); +@@ -68,7 +67,7 @@ + for (i = 0; i < 80; i++) { + int t; + if (i < 16) +- t = av_be2ne32(((uint32_t*)buffer)[i]); ++ t = AV_RB32(buffer + 4 * i); + else + t = rol(block[i-3] ^ block[i-8] ^ block[i-14] ^ block[i-16], 1); + block[i] = t; +@@ -324,29 +323,6 @@ + AV_WB32(digest + i*4, ctx->state[i]); + } + +-#if LIBAVUTIL_VERSION_MAJOR < 51 +-struct AVSHA1 { +- AVSHA sha; +-}; +- +-const int av_sha1_size = sizeof(struct AVSHA1); +- +-void av_sha1_init(struct AVSHA1* context) +-{ +- av_sha_init(&context->sha, 160); +-} +- +-void av_sha1_update(struct AVSHA1* context, const uint8_t* data, unsigned int len) +-{ +- av_sha_update(&context->sha, data, len); +-} +- +-void av_sha1_final(struct AVSHA1* context, uint8_t digest[20]) +-{ +- av_sha_final(&context->sha, digest); +-} +-#endif +- + #ifdef TEST + #include + #undef printf +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/sha.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/sha.h 2012-05-14 14:08:55.342360269 +0200 +@@ -23,6 +23,12 @@ + + #include + ++/** ++ * @defgroup lavu_sha SHA ++ * @ingroup lavu_crypto ++ * @{ ++ */ ++ + extern const int av_sha_size; + + struct AVSHA; +@@ -53,4 +59,8 @@ + */ + void av_sha_final(struct AVSHA* context, uint8_t *digest); + ++/** ++ * @} ++ */ ++ + #endif /* AVUTIL_SHA_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/timer.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/timer.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/timer.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/timer.h 2012-05-14 14:08:55.343360289 +0200 +@@ -1,7 +1,4 @@ +-/** +- * @file +- * high precision timer, useful to profile code +- * ++/* + * copyright (c) 2006 Michael Niedermayer + * + * This file is part of FFmpeg. +@@ -21,11 +18,17 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + ++/** ++ * @file ++ * high precision timer, useful to profile code ++ */ ++ + #ifndef AVUTIL_TIMER_H + #define AVUTIL_TIMER_H + + #include + #include ++ + #include "config.h" + + #if ARCH_ARM +@@ -43,29 +46,32 @@ + #endif + + #ifdef AV_READ_TIME +-#define START_TIMER \ +-uint64_t tend;\ +-uint64_t tstart= AV_READ_TIME();\ +- +-#define STOP_TIMER(id) \ +-tend= AV_READ_TIME();\ +-{\ +- static uint64_t tsum=0;\ +- static int tcount=0;\ +- static int tskip_count=0;\ +- if(tcount<2 || tend - tstart < 8*tsum/tcount || tend - tstart < 2000){\ +- tsum+= tend - tstart;\ +- tcount++;\ +- }else\ +- tskip_count++;\ +- if(((tcount+tskip_count)&(tcount+tskip_count-1))==0){\ +- av_log(NULL, AV_LOG_ERROR, "%"PRIu64" dezicycles in %s, %d runs, %d skips\n",\ +- tsum*10/tcount, id, tcount, tskip_count);\ +- }\ +-} ++#define START_TIMER \ ++ uint64_t tend; \ ++ uint64_t tstart = AV_READ_TIME(); \ ++ ++#define STOP_TIMER(id) \ ++ tend = AV_READ_TIME(); \ ++ { \ ++ static uint64_t tsum = 0; \ ++ static int tcount = 0; \ ++ static int tskip_count = 0; \ ++ if (tcount < 2 || \ ++ tend - tstart < 8 * tsum / tcount || \ ++ tend - tstart < 2000) { \ ++ tsum+= tend - tstart; \ ++ tcount++; \ ++ } else \ ++ tskip_count++; \ ++ if (((tcount + tskip_count) & (tcount + tskip_count - 1)) == 0) { \ ++ av_log(NULL, AV_LOG_ERROR, \ ++ "%"PRIu64" decicycles in %s, %d runs, %d skips\n", \ ++ tsum * 10 / tcount, id, tcount, tskip_count); \ ++ } \ ++ } + #else + #define START_TIMER +-#define STOP_TIMER(id) {} ++#define STOP_TIMER(id) { } + #endif + + #endif /* AVUTIL_TIMER_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/tree.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/tree.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/tree.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/tree.c 2012-05-14 14:08:55.344360309 +0200 +@@ -21,22 +21,24 @@ + #include "log.h" + #include "tree.h" + +-typedef struct AVTreeNode{ ++typedef struct AVTreeNode { + struct AVTreeNode *child[2]; + void *elem; + int state; +-}AVTreeNode; ++} AVTreeNode; + + const int av_tree_node_size = sizeof(AVTreeNode); + +-void *av_tree_find(const AVTreeNode *t, void *key, int (*cmp)(void *key, const void *b), void *next[2]){ +- if(t){ +- unsigned int v= cmp(key, t->elem); +- if(v){ +- if(next) next[v>>31]= t->elem; +- return av_tree_find(t->child[(v>>31)^1], key, cmp, next); +- }else{ +- if(next){ ++void *av_tree_find(const AVTreeNode *t, void *key, ++ int (*cmp)(void *key, const void *b), void *next[2]) ++{ ++ if (t) { ++ unsigned int v = cmp(key, t->elem); ++ if (v) { ++ if (next) next[v >> 31] = t->elem; ++ return av_tree_find(t->child[(v >> 31) ^ 1], key, cmp, next); ++ } else { ++ if (next) { + av_tree_find(t->child[0], key, cmp, next); + av_tree_find(t->child[1], key, cmp, next); + } +@@ -46,41 +48,43 @@ + return NULL; + } + +-void *av_tree_insert(AVTreeNode **tp, void *key, int (*cmp)(void *key, const void *b), AVTreeNode **next){ +- AVTreeNode *t= *tp; +- if(t){ +- unsigned int v= cmp(t->elem, key); ++void *av_tree_insert(AVTreeNode **tp, void *key, ++ int (*cmp)(void *key, const void *b), AVTreeNode **next) ++{ ++ AVTreeNode *t = *tp; ++ if (t) { ++ unsigned int v = cmp(t->elem, key); + void *ret; +- if(!v){ +- if(*next) ++ if (!v) { ++ if (*next) + return t->elem; +- else if(t->child[0]||t->child[1]){ +- int i= !t->child[0]; ++ else if (t->child[0] || t->child[1]) { ++ int i = !t->child[0]; + void *next_elem[2]; + av_tree_find(t->child[i], key, cmp, next_elem); +- key= t->elem= next_elem[i]; +- v= -i; +- }else{ +- *next= t; +- *tp=NULL; ++ key = t->elem = next_elem[i]; ++ v = -i; ++ } else { ++ *next = t; ++ *tp = NULL; + return NULL; + } + } +- ret= av_tree_insert(&t->child[v>>31], key, cmp, next); +- if(!ret){ +- int i= (v>>31) ^ !!*next; +- AVTreeNode **child= &t->child[i]; +- t->state += 2*i - 1; ++ ret = av_tree_insert(&t->child[v >> 31], key, cmp, next); ++ if (!ret) { ++ int i = (v >> 31) ^ !!*next; ++ AVTreeNode **child = &t->child[i]; ++ t->state += 2 * i - 1; + +- if(!(t->state&1)){ +- if(t->state){ ++ if (!(t->state & 1)) { ++ if (t->state) { + /* The following code is equivalent to + if((*child)->state*2 == -t->state) + rotate(child, i^1); + rotate(tp, i); + + with rotate(): +- static void rotate(AVTreeNode **tp, int i){ ++ static void rotate(AVTreeNode **tp, int i) { + AVTreeNode *t= *tp; + + *tp= t->child[i]; +@@ -92,54 +96,62 @@ + } + but such a rotate function is both bigger and slower + */ +- if((*child)->state*2 == -t->state){ +- *tp= (*child)->child[i^1]; +- (*child)->child[i^1]= (*tp)->child[i]; +- (*tp)->child[i]= *child; +- *child= (*tp)->child[i^1]; +- (*tp)->child[i^1]= t; +- +- (*tp)->child[0]->state= -((*tp)->state>0); +- (*tp)->child[1]->state= (*tp)->state<0 ; +- (*tp)->state=0; +- }else{ +- *tp= *child; +- *child= (*child)->child[i^1]; +- (*tp)->child[i^1]= t; +- if((*tp)->state) t->state = 0; +- else t->state>>= 1; +- (*tp)->state= -t->state; ++ if (( *child )->state * 2 == -t->state) { ++ *tp = (*child)->child[i ^ 1]; ++ (*child)->child[i ^ 1] = (*tp)->child[i]; ++ (*tp)->child[i] = *child; ++ *child = ( *tp )->child[i ^ 1]; ++ (*tp)->child[i ^ 1] = t; ++ ++ (*tp)->child[0]->state = -((*tp)->state > 0); ++ (*tp)->child[1]->state = (*tp)->state < 0; ++ (*tp)->state = 0; ++ } else { ++ *tp = *child; ++ *child = (*child)->child[i ^ 1]; ++ (*tp)->child[i ^ 1] = t; ++ if ((*tp)->state) t->state = 0; ++ else t->state >>= 1; ++ (*tp)->state = -t->state; + } + } + } +- if(!(*tp)->state ^ !!*next) ++ if (!(*tp)->state ^ !!*next) + return key; + } + return ret; +- }else{ +- *tp= *next; *next= NULL; +- if(*tp){ +- (*tp)->elem= key; ++ } else { ++ *tp = *next; ++ *next = NULL; ++ if (*tp) { ++ (*tp)->elem = key; + return NULL; +- }else ++ } else + return key; + } + } + +-void av_tree_destroy(AVTreeNode *t){ +- if(t){ ++void av_tree_destroy(AVTreeNode *t) ++{ ++ if (t) { + av_tree_destroy(t->child[0]); + av_tree_destroy(t->child[1]); + av_free(t); + } + } + +-void av_tree_enumerate(AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)){ +- if(t){ +- int v= cmp ? cmp(opaque, t->elem) : 0; +- if(v>=0) av_tree_enumerate(t->child[0], opaque, cmp, enu); +- if(v==0) enu(opaque, t->elem); +- if(v<=0) av_tree_enumerate(t->child[1], opaque, cmp, enu); ++void av_tree_enumerate(AVTreeNode *t, void *opaque, ++ int (*cmp)(void *opaque, void *elem), ++ int (*enu)(void *opaque, void *elem)) ++{ ++ if (t) { ++ int v = cmp ? cmp(opaque, t->elem) : 0; ++ if (v >= 0) ++ av_tree_enumerate(t->child[0], opaque, cmp, enu); ++ if (v == 0) ++ enu(opaque, t->elem); ++ if (v <= 0) ++ av_tree_enumerate(t->child[1], opaque, cmp, enu); + } + } + +@@ -147,64 +159,68 @@ + + #include "lfg.h" + +-static int check(AVTreeNode *t){ +- if(t){ +- int left= check(t->child[0]); +- int right= check(t->child[1]); ++static int check(AVTreeNode *t) ++{ ++ if (t) { ++ int left = check(t->child[0]); ++ int right = check(t->child[1]); + +- if(left>999 || right>999) ++ if (left>999 || right>999) + return 1000; +- if(right - left != t->state) ++ if (right - left != t->state) + return 1000; +- if(t->state>1 || t->state<-1) ++ if (t->state>1 || t->state<-1) + return 1000; +- return FFMAX(left, right)+1; ++ return FFMAX(left, right) + 1; + } + return 0; + } + +-static void print(AVTreeNode *t, int depth){ ++static void print(AVTreeNode *t, int depth) ++{ + int i; +- for(i=0; istate, t->elem); +- print(t->child[0], depth+1); +- print(t->child[1], depth+1); +- }else ++ print(t->child[0], depth + 1); ++ print(t->child[1], depth + 1); ++ } else + av_log(NULL, AV_LOG_ERROR, "NULL\n"); + } + +-static int cmp(void *a, const void *b){ +- return (uint8_t*)a-(const uint8_t*)b; ++static int cmp(void *a, const void *b) ++{ ++ return (uint8_t *) a - (const uint8_t *) b; + } + +-int main(void){ ++int main (void) ++{ + int i; + void *k; +- AVTreeNode *root= NULL, *node=NULL; ++ AVTreeNode *root = NULL, *node = NULL; + AVLFG prng; + + av_lfg_init(&prng, 1); + +- for(i=0; i<10000; i++){ ++ for (i = 0; i < 10000; i++) { + int j = av_lfg_get(&prng) % 86294; +- if(check(root) > 999){ ++ if (check(root) > 999) { + av_log(NULL, AV_LOG_ERROR, "FATAL error %d\n", i); + print(root, 0); + return -1; + } + av_log(NULL, AV_LOG_ERROR, "inserting %4d\n", j); +- if(!node) +- node= av_mallocz(av_tree_node_size); +- av_tree_insert(&root, (void*)(j+1), cmp, &node); ++ if (!node) ++ node = av_mallocz(av_tree_node_size); ++ av_tree_insert(&root, (void *) (j + 1), cmp, &node); + + j = av_lfg_get(&prng) % 86294; + { +- AVTreeNode *node2=NULL; ++ AVTreeNode *node2 = NULL; + av_log(NULL, AV_LOG_ERROR, "removing %4d\n", j); +- av_tree_insert(&root, (void*)(j+1), cmp, &node2); +- k= av_tree_find(root, (void*)(j+1), cmp, NULL); +- if(k) ++ av_tree_insert(&root, (void *) (j + 1), cmp, &node2); ++ k = av_tree_find(root, (void *) (j + 1), cmp, NULL); ++ if (k) + av_log(NULL, AV_LOG_ERROR, "removal failure %d\n", i); + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/tree.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/tree.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/tree.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/tree.h 2012-05-14 14:08:55.345360329 +0200 +@@ -21,14 +21,24 @@ + /** + * @file + * A tree container. +- * Insertion, removal, finding equal, largest which is smaller than and +- * smallest which is larger than, all have O(log n) worst case complexity. + * @author Michael Niedermayer + */ + + #ifndef AVUTIL_TREE_H + #define AVUTIL_TREE_H + ++/** ++ * @addtogroup lavu_tree AVTree ++ * @ingroup lavu_data ++ * ++ * Low complexity tree container ++ * ++ * Insertion, removal, finding equal, largest which is smaller than and ++ * smallest which is larger than, all have O(log n) worst case complexity. ++ * @{ ++ */ ++ ++ + struct AVTreeNode; + extern const int av_tree_node_size; + +@@ -67,7 +77,7 @@ + * return av_tree_insert(rootp, key, cmp, next); + * } + * void *tree_remove(struct AVTreeNode **rootp, void *key, int (*cmp)(void *key, const void *b, AVTreeNode **next)){ +- * if(*next) av_freep(next); ++ * av_freep(next); + * return av_tree_insert(rootp, key, cmp, next); + * } + * @endcode +@@ -91,5 +101,8 @@ + */ + void av_tree_enumerate(struct AVTreeNode *t, void *opaque, int (*cmp)(void *opaque, void *elem), int (*enu)(void *opaque, void *elem)); + ++/** ++ * @} ++ */ + + #endif /* AVUTIL_TREE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/utils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/utils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/utils.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/utils.c 2012-05-14 14:08:55.346360349 +0200 +@@ -18,6 +18,8 @@ + + #include "config.h" + #include "avutil.h" ++#include "avassert.h" ++#include "samplefmt.h" + + /** + * @file +@@ -26,6 +28,12 @@ + + unsigned avutil_version(void) + { ++ av_assert0(PIX_FMT_VDA_VLD == 81); //check if the pix fmt enum has not had anything inserted or removed by mistake ++ av_assert0(AV_SAMPLE_FMT_DBLP == 9); ++ av_assert0(AVMEDIA_TYPE_ATTACHMENT == 4); ++ av_assert0(AV_PICTURE_TYPE_BI == 7); ++ av_assert0(LIBAVUTIL_VERSION_MICRO >= 100); ++ + return LIBAVUTIL_VERSION_INT; + } + +@@ -39,3 +47,29 @@ + #define LICENSE_PREFIX "libavutil license: " + return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; + } ++ ++const char *av_get_media_type_string(enum AVMediaType media_type) ++{ ++ switch (media_type) { ++ case AVMEDIA_TYPE_VIDEO: return "video"; ++ case AVMEDIA_TYPE_AUDIO: return "audio"; ++ case AVMEDIA_TYPE_DATA: return "data"; ++ case AVMEDIA_TYPE_SUBTITLE: return "subtitle"; ++ case AVMEDIA_TYPE_ATTACHMENT: return "attachment"; ++ default: return NULL; ++ } ++} ++ ++char av_get_picture_type_char(enum AVPictureType pict_type) ++{ ++ switch (pict_type) { ++ case AV_PICTURE_TYPE_I: return 'I'; ++ case AV_PICTURE_TYPE_P: return 'P'; ++ case AV_PICTURE_TYPE_B: return 'B'; ++ case AV_PICTURE_TYPE_S: return 'S'; ++ case AV_PICTURE_TYPE_SI: return 'i'; ++ case AV_PICTURE_TYPE_SP: return 'p'; ++ case AV_PICTURE_TYPE_BI: return 'b'; ++ default: return '?'; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/bswap.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/bswap.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/bswap.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/bswap.h 2012-05-14 14:08:55.346360349 +0200 +@@ -28,24 +28,20 @@ + #include "config.h" + #include "libavutil/attributes.h" + ++#if !AV_GCC_VERSION_AT_LEAST(4,1) + #define av_bswap16 av_bswap16 +-static av_always_inline av_const uint16_t av_bswap16(uint16_t x) ++static av_always_inline av_const unsigned av_bswap16(unsigned x) + { +- __asm__("rorw $8, %0" : "+r"(x)); ++ __asm__("rorw $8, %w0" : "+r"(x)); + return x; + } ++#endif /* !AV_GCC_VERSION_AT_LEAST(4,1) */ + ++#if !AV_GCC_VERSION_AT_LEAST(4,5) + #define av_bswap32 av_bswap32 + static av_always_inline av_const uint32_t av_bswap32(uint32_t x) + { +-#if HAVE_BSWAP + __asm__("bswap %0" : "+r" (x)); +-#else +- __asm__("rorw $8, %w0 \n\t" +- "rorl $16, %0 \n\t" +- "rorw $8, %w0" +- : "+r"(x)); +-#endif + return x; + } + +@@ -57,5 +53,6 @@ + return x; + } + #endif ++#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */ + + #endif /* AVUTIL_X86_BSWAP_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/cpu.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/cpu.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/cpu.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/cpu.c 2012-05-14 14:08:55.347360369 +0200 +@@ -35,6 +35,9 @@ + "=c" (ecx), "=d" (edx)\ + : "0" (index)); + ++#define xgetbv(index,eax,edx) \ ++ __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c" (index)) ++ + /* Function to test if multimedia instructions are supported... */ + int ff_get_cpu_flags_x86(void) + { +@@ -71,7 +74,10 @@ + return 0; /* CPUID not supported */ + #endif + +- cpuid(0, max_std_level, vendor.i[0], vendor.i[2], vendor.i[1]); ++ cpuid(0, max_std_level, ebx, ecx, edx); ++ vendor.i[0] = ebx; ++ vendor.i[1] = edx; ++ vendor.i[2] = ecx; + + if(max_std_level >= 1){ + cpuid(1, eax, ebx, ecx, std_caps); +@@ -93,6 +99,15 @@ + rval |= AV_CPU_FLAG_SSE4; + if (ecx & 0x00100000 ) + rval |= AV_CPU_FLAG_SSE42; ++#if HAVE_AVX ++ /* Check OXSAVE and AVX bits */ ++ if ((ecx & 0x18000000) == 0x18000000) { ++ /* Check for OS support */ ++ xgetbv(0, eax, edx); ++ if ((eax & 0x6) == 0x6) ++ rval |= AV_CPU_FLAG_AVX; ++ } ++#endif + #endif + ; + } +@@ -101,7 +116,7 @@ + + if(max_ext_level >= 0x80000001){ + cpuid(0x80000001, eax, ebx, ecx, ext_caps); +- if (ext_caps & (1<<31)) ++ if (ext_caps & (1U<<31)) + rval |= AV_CPU_FLAG_3DNOW; + if (ext_caps & (1<<30)) + rval |= AV_CPU_FLAG_3DNOWEXT; +@@ -109,15 +124,47 @@ + rval |= AV_CPU_FLAG_MMX; + if (ext_caps & (1<<22)) + rval |= AV_CPU_FLAG_MMX2; ++ ++ /* Allow for selectively disabling SSE2 functions on AMD processors ++ with SSE2 support but not SSE4a. This includes Athlon64, some ++ Opteron, and some Sempron processors. MMX, SSE, or 3DNow! are faster ++ than SSE2 often enough to utilize this special-case flag. ++ AV_CPU_FLAG_SSE2 and AV_CPU_FLAG_SSE2SLOW are both set in this case ++ so that SSE2 is used unless explicitly disabled by checking ++ AV_CPU_FLAG_SSE2SLOW. */ ++ if (!strncmp(vendor.c, "AuthenticAMD", 12) && ++ rval & AV_CPU_FLAG_SSE2 && !(ecx & 0x00000040)) { ++ rval |= AV_CPU_FLAG_SSE2SLOW; ++ } ++ ++ /* XOP and FMA4 use the AVX instruction coding scheme, so they can't be ++ * used unless the OS has AVX support. */ ++ if (rval & AV_CPU_FLAG_AVX) { ++ if (ecx & 0x00000800) ++ rval |= AV_CPU_FLAG_XOP; ++ if (ecx & 0x00010000) ++ rval |= AV_CPU_FLAG_FMA4; ++ } + } + +- if (!strncmp(vendor.c, "GenuineIntel", 12) && +- family == 6 && (model == 9 || model == 13 || model == 14)) { +- /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and 6/14 (core1 "yonah") +- * theoretically support sse2, but it's usually slower than mmx, +- * so let's just pretend they don't. */ +- if (rval & AV_CPU_FLAG_SSE2) rval ^= AV_CPU_FLAG_SSE2SLOW|AV_CPU_FLAG_SSE2; +- if (rval & AV_CPU_FLAG_SSE3) rval ^= AV_CPU_FLAG_SSE3SLOW|AV_CPU_FLAG_SSE3; ++ if (!strncmp(vendor.c, "GenuineIntel", 12)) { ++ if (family == 6 && (model == 9 || model == 13 || model == 14)) { ++ /* 6/9 (pentium-m "banias"), 6/13 (pentium-m "dothan"), and 6/14 (core1 "yonah") ++ * theoretically support sse2, but it's usually slower than mmx, ++ * so let's just pretend they don't. AV_CPU_FLAG_SSE2 is disabled and ++ * AV_CPU_FLAG_SSE2SLOW is enabled so that SSE2 is not used unless ++ * explicitly enabled by checking AV_CPU_FLAG_SSE2SLOW. The same ++ * situation applies for AV_CPU_FLAG_SSE3 and AV_CPU_FLAG_SSE3SLOW. */ ++ if (rval & AV_CPU_FLAG_SSE2) rval ^= AV_CPU_FLAG_SSE2SLOW|AV_CPU_FLAG_SSE2; ++ if (rval & AV_CPU_FLAG_SSE3) rval ^= AV_CPU_FLAG_SSE3SLOW|AV_CPU_FLAG_SSE3; ++ } ++ /* The Atom processor has SSSE3 support, which is useful in many cases, ++ * but sometimes the SSSE3 version is slower than the SSE2 equivalent ++ * on the Atom, but is generally faster on other processors supporting ++ * SSSE3. This flag allows for selectively disabling certain SSSE3 ++ * functions on the Atom. */ ++ if (family == 6 && model == 28) ++ rval |= AV_CPU_FLAG_ATOM; + } + + return rval; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/x86inc.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/x86inc.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/x86inc.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/x86inc.asm 2012-05-14 14:08:55.349360409 +0200 +@@ -0,0 +1,1084 @@ ++;***************************************************************************** ++;* x86inc.asm: x264asm abstraction layer ++;***************************************************************************** ++;* Copyright (C) 2005-2011 x264 project ++;* ++;* Authors: Loren Merritt ++;* Anton Mitrofanov ++;* Jason Garrett-Glaser ++;* ++;* Permission to use, copy, modify, and/or distribute this software for any ++;* purpose with or without fee is hereby granted, provided that the above ++;* copyright notice and this permission notice appear in all copies. ++;* ++;* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES ++;* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF ++;* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ++;* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES ++;* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ++;* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF ++;* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ++;***************************************************************************** ++ ++; This is a header file for the x264ASM assembly language, which uses ++; NASM/YASM syntax combined with a large number of macros to provide easy ++; abstraction between different calling conventions (x86_32, win64, linux64). ++; It also has various other useful features to simplify writing the kind of ++; DSP functions that are most often used in x264. ++ ++; Unlike the rest of x264, this file is available under an ISC license, as it ++; has significant usefulness outside of x264 and we want it to be available ++; to the largest audience possible. Of course, if you modify it for your own ++; purposes to add a new feature, we strongly encourage contributing a patch ++; as this feature might be useful for others as well. Send patches or ideas ++; to x264-devel@videolan.org . ++ ++%define program_name ff ++ ++%ifdef ARCH_X86_64 ++ %ifidn __OUTPUT_FORMAT__,win32 ++ %define WIN64 ++ %else ++ %define UNIX64 ++ %endif ++%endif ++ ++%ifdef PREFIX ++ %define mangle(x) _ %+ x ++%else ++ %define mangle(x) x ++%endif ++ ++; FIXME: All of the 64bit asm functions that take a stride as an argument ++; via register, assume that the high dword of that register is filled with 0. ++; This is true in practice (since we never do any 64bit arithmetic on strides, ++; and x264's strides are all positive), but is not guaranteed by the ABI. ++ ++; Name of the .rodata section. ++; Kludge: Something on OS X fails to align .rodata even given an align attribute, ++; so use a different read-only section. ++%macro SECTION_RODATA 0-1 16 ++ %ifidn __OUTPUT_FORMAT__,macho64 ++ SECTION .text align=%1 ++ %elifidn __OUTPUT_FORMAT__,macho ++ SECTION .text align=%1 ++ fakegot: ++ %elifidn __OUTPUT_FORMAT__,aout ++ section .text ++ %else ++ SECTION .rodata align=%1 ++ %endif ++%endmacro ++ ++; aout does not support align= ++%macro SECTION_TEXT 0-1 16 ++ %ifidn __OUTPUT_FORMAT__,aout ++ SECTION .text ++ %else ++ SECTION .text align=%1 ++ %endif ++%endmacro ++ ++%ifdef WIN64 ++ %define PIC ++%elifndef ARCH_X86_64 ++; x86_32 doesn't require PIC. ++; Some distros prefer shared objects to be PIC, but nothing breaks if ++; the code contains a few textrels, so we'll skip that complexity. ++ %undef PIC ++%endif ++%ifdef PIC ++ default rel ++%endif ++ ++; Macros to eliminate most code duplication between x86_32 and x86_64: ++; Currently this works only for leaf functions which load all their arguments ++; into registers at the start, and make no other use of the stack. Luckily that ++; covers most of x264's asm. ++ ++; PROLOGUE: ++; %1 = number of arguments. loads them from stack if needed. ++; %2 = number of registers used. pushes callee-saved regs if needed. ++; %3 = number of xmm registers used. pushes callee-saved xmm regs if needed. ++; %4 = list of names to define to registers ++; PROLOGUE can also be invoked by adding the same options to cglobal ++ ++; e.g. ++; cglobal foo, 2,3,0, dst, src, tmp ++; declares a function (foo), taking two args (dst and src) and one local variable (tmp) ++ ++; TODO Some functions can use some args directly from the stack. If they're the ++; last args then you can just not declare them, but if they're in the middle ++; we need more flexible macro. ++ ++; RET: ++; Pops anything that was pushed by PROLOGUE, and returns. ++ ++; REP_RET: ++; Same, but if it doesn't pop anything it becomes a 2-byte ret, for athlons ++; which are slow when a normal ret follows a branch. ++ ++; registers: ++; rN and rNq are the native-size register holding function argument N ++; rNd, rNw, rNb are dword, word, and byte size ++; rNm is the original location of arg N (a register or on the stack), dword ++; rNmp is native size ++ ++%macro DECLARE_REG 6 ++ %define r%1q %2 ++ %define r%1d %3 ++ %define r%1w %4 ++ %define r%1b %5 ++ %define r%1m %6 ++ %ifid %6 ; i.e. it's a register ++ %define r%1mp %2 ++ %elifdef ARCH_X86_64 ; memory ++ %define r%1mp qword %6 ++ %else ++ %define r%1mp dword %6 ++ %endif ++ %define r%1 %2 ++%endmacro ++ ++%macro DECLARE_REG_SIZE 2 ++ %define r%1q r%1 ++ %define e%1q r%1 ++ %define r%1d e%1 ++ %define e%1d e%1 ++ %define r%1w %1 ++ %define e%1w %1 ++ %define r%1b %2 ++ %define e%1b %2 ++%ifndef ARCH_X86_64 ++ %define r%1 e%1 ++%endif ++%endmacro ++ ++DECLARE_REG_SIZE ax, al ++DECLARE_REG_SIZE bx, bl ++DECLARE_REG_SIZE cx, cl ++DECLARE_REG_SIZE dx, dl ++DECLARE_REG_SIZE si, sil ++DECLARE_REG_SIZE di, dil ++DECLARE_REG_SIZE bp, bpl ++ ++; t# defines for when per-arch register allocation is more complex than just function arguments ++ ++%macro DECLARE_REG_TMP 1-* ++ %assign %%i 0 ++ %rep %0 ++ CAT_XDEFINE t, %%i, r%1 ++ %assign %%i %%i+1 ++ %rotate 1 ++ %endrep ++%endmacro ++ ++%macro DECLARE_REG_TMP_SIZE 0-* ++ %rep %0 ++ %define t%1q t%1 %+ q ++ %define t%1d t%1 %+ d ++ %define t%1w t%1 %+ w ++ %define t%1b t%1 %+ b ++ %rotate 1 ++ %endrep ++%endmacro ++ ++DECLARE_REG_TMP_SIZE 0,1,2,3,4,5,6,7,8,9 ++ ++%ifdef ARCH_X86_64 ++ %define gprsize 8 ++%else ++ %define gprsize 4 ++%endif ++ ++%macro PUSH 1 ++ push %1 ++ %assign stack_offset stack_offset+gprsize ++%endmacro ++ ++%macro POP 1 ++ pop %1 ++ %assign stack_offset stack_offset-gprsize ++%endmacro ++ ++%macro SUB 2 ++ sub %1, %2 ++ %ifidn %1, rsp ++ %assign stack_offset stack_offset+(%2) ++ %endif ++%endmacro ++ ++%macro ADD 2 ++ add %1, %2 ++ %ifidn %1, rsp ++ %assign stack_offset stack_offset-(%2) ++ %endif ++%endmacro ++ ++%macro movifnidn 2 ++ %ifnidn %1, %2 ++ mov %1, %2 ++ %endif ++%endmacro ++ ++%macro movsxdifnidn 2 ++ %ifnidn %1, %2 ++ movsxd %1, %2 ++ %endif ++%endmacro ++ ++%macro ASSERT 1 ++ %if (%1) == 0 ++ %error assert failed ++ %endif ++%endmacro ++ ++%macro DEFINE_ARGS 0-* ++ %ifdef n_arg_names ++ %assign %%i 0 ++ %rep n_arg_names ++ CAT_UNDEF arg_name %+ %%i, q ++ CAT_UNDEF arg_name %+ %%i, d ++ CAT_UNDEF arg_name %+ %%i, w ++ CAT_UNDEF arg_name %+ %%i, b ++ CAT_UNDEF arg_name %+ %%i, m ++ CAT_UNDEF arg_name, %%i ++ %assign %%i %%i+1 ++ %endrep ++ %endif ++ ++ %assign %%i 0 ++ %rep %0 ++ %xdefine %1q r %+ %%i %+ q ++ %xdefine %1d r %+ %%i %+ d ++ %xdefine %1w r %+ %%i %+ w ++ %xdefine %1b r %+ %%i %+ b ++ %xdefine %1m r %+ %%i %+ m ++ CAT_XDEFINE arg_name, %%i, %1 ++ %assign %%i %%i+1 ++ %rotate 1 ++ %endrep ++ %assign n_arg_names %%i ++%endmacro ++ ++%ifdef WIN64 ; Windows x64 ;================================================= ++ ++DECLARE_REG 0, rcx, ecx, cx, cl, ecx ++DECLARE_REG 1, rdx, edx, dx, dl, edx ++DECLARE_REG 2, r8, r8d, r8w, r8b, r8d ++DECLARE_REG 3, r9, r9d, r9w, r9b, r9d ++DECLARE_REG 4, rdi, edi, di, dil, [rsp + stack_offset + 40] ++DECLARE_REG 5, rsi, esi, si, sil, [rsp + stack_offset + 48] ++DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 56] ++%define r7m [rsp + stack_offset + 64] ++%define r8m [rsp + stack_offset + 72] ++ ++%macro LOAD_IF_USED 2 ; reg_id, number_of_args ++ %if %1 < %2 ++ mov r%1, [rsp + stack_offset + 8 + %1*8] ++ %endif ++%endmacro ++ ++%macro PROLOGUE 2-4+ 0 ; #args, #regs, #xmm_regs, arg_names... ++ ASSERT %2 >= %1 ++ %assign regs_used %2 ++ ASSERT regs_used <= 7 ++ %if regs_used > 4 ++ push r4 ++ push r5 ++ %assign stack_offset stack_offset+16 ++ %endif ++ WIN64_SPILL_XMM %3 ++ LOAD_IF_USED 4, %1 ++ LOAD_IF_USED 5, %1 ++ LOAD_IF_USED 6, %1 ++ DEFINE_ARGS %4 ++%endmacro ++ ++%macro WIN64_SPILL_XMM 1 ++ %assign xmm_regs_used %1 ++ %if mmsize == 8 ++ %assign xmm_regs_used 0 ++ %endif ++ ASSERT xmm_regs_used <= 16 ++ %if xmm_regs_used > 6 ++ sub rsp, (xmm_regs_used-6)*16+16 ++ %assign stack_offset stack_offset+(xmm_regs_used-6)*16+16 ++ %assign %%i xmm_regs_used ++ %rep (xmm_regs_used-6) ++ %assign %%i %%i-1 ++ movdqa [rsp + (%%i-6)*16+8], xmm %+ %%i ++ %endrep ++ %endif ++%endmacro ++ ++%macro WIN64_RESTORE_XMM_INTERNAL 1 ++ %if xmm_regs_used > 6 ++ %assign %%i xmm_regs_used ++ %rep (xmm_regs_used-6) ++ %assign %%i %%i-1 ++ movdqa xmm %+ %%i, [%1 + (%%i-6)*16+8] ++ %endrep ++ add %1, (xmm_regs_used-6)*16+16 ++ %endif ++%endmacro ++ ++%macro WIN64_RESTORE_XMM 1 ++ WIN64_RESTORE_XMM_INTERNAL %1 ++ %assign stack_offset stack_offset-(xmm_regs_used-6)*16+16 ++ %assign xmm_regs_used 0 ++%endmacro ++ ++%macro RET 0 ++ WIN64_RESTORE_XMM_INTERNAL rsp ++ %if regs_used > 4 ++ pop r5 ++ pop r4 ++ %endif ++ ret ++%endmacro ++ ++%macro REP_RET 0 ++ %if regs_used > 4 || xmm_regs_used > 6 ++ RET ++ %else ++ rep ret ++ %endif ++%endmacro ++ ++%elifdef ARCH_X86_64 ; *nix x64 ;============================================= ++ ++DECLARE_REG 0, rdi, edi, di, dil, edi ++DECLARE_REG 1, rsi, esi, si, sil, esi ++DECLARE_REG 2, rdx, edx, dx, dl, edx ++DECLARE_REG 3, rcx, ecx, cx, cl, ecx ++DECLARE_REG 4, r8, r8d, r8w, r8b, r8d ++DECLARE_REG 5, r9, r9d, r9w, r9b, r9d ++DECLARE_REG 6, rax, eax, ax, al, [rsp + stack_offset + 8] ++%define r7m [rsp + stack_offset + 16] ++%define r8m [rsp + stack_offset + 24] ++ ++%macro LOAD_IF_USED 2 ; reg_id, number_of_args ++ %if %1 < %2 ++ mov r%1, [rsp - 40 + %1*8] ++ %endif ++%endmacro ++ ++%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names... ++ ASSERT %2 >= %1 ++ ASSERT %2 <= 7 ++ LOAD_IF_USED 6, %1 ++ DEFINE_ARGS %4 ++%endmacro ++ ++%macro RET 0 ++ ret ++%endmacro ++ ++%macro REP_RET 0 ++ rep ret ++%endmacro ++ ++%else ; X86_32 ;============================================================== ++ ++DECLARE_REG 0, eax, eax, ax, al, [esp + stack_offset + 4] ++DECLARE_REG 1, ecx, ecx, cx, cl, [esp + stack_offset + 8] ++DECLARE_REG 2, edx, edx, dx, dl, [esp + stack_offset + 12] ++DECLARE_REG 3, ebx, ebx, bx, bl, [esp + stack_offset + 16] ++DECLARE_REG 4, esi, esi, si, null, [esp + stack_offset + 20] ++DECLARE_REG 5, edi, edi, di, null, [esp + stack_offset + 24] ++DECLARE_REG 6, ebp, ebp, bp, null, [esp + stack_offset + 28] ++%define r7m [esp + stack_offset + 32] ++%define r8m [esp + stack_offset + 36] ++%define rsp esp ++ ++%macro PUSH_IF_USED 1 ; reg_id ++ %if %1 < regs_used ++ push r%1 ++ %assign stack_offset stack_offset+4 ++ %endif ++%endmacro ++ ++%macro POP_IF_USED 1 ; reg_id ++ %if %1 < regs_used ++ pop r%1 ++ %endif ++%endmacro ++ ++%macro LOAD_IF_USED 2 ; reg_id, number_of_args ++ %if %1 < %2 ++ mov r%1, [esp + stack_offset + 4 + %1*4] ++ %endif ++%endmacro ++ ++%macro PROLOGUE 2-4+ ; #args, #regs, #xmm_regs, arg_names... ++ ASSERT %2 >= %1 ++ %assign regs_used %2 ++ ASSERT regs_used <= 7 ++ PUSH_IF_USED 3 ++ PUSH_IF_USED 4 ++ PUSH_IF_USED 5 ++ PUSH_IF_USED 6 ++ LOAD_IF_USED 0, %1 ++ LOAD_IF_USED 1, %1 ++ LOAD_IF_USED 2, %1 ++ LOAD_IF_USED 3, %1 ++ LOAD_IF_USED 4, %1 ++ LOAD_IF_USED 5, %1 ++ LOAD_IF_USED 6, %1 ++ DEFINE_ARGS %4 ++%endmacro ++ ++%macro RET 0 ++ POP_IF_USED 6 ++ POP_IF_USED 5 ++ POP_IF_USED 4 ++ POP_IF_USED 3 ++ ret ++%endmacro ++ ++%macro REP_RET 0 ++ %if regs_used > 3 ++ RET ++ %else ++ rep ret ++ %endif ++%endmacro ++ ++%endif ;====================================================================== ++ ++%ifndef WIN64 ++%macro WIN64_SPILL_XMM 1 ++%endmacro ++%macro WIN64_RESTORE_XMM 1 ++%endmacro ++%endif ++ ++ ++ ++;============================================================================= ++; arch-independent part ++;============================================================================= ++ ++%assign function_align 16 ++ ++; Begin a function. ++; Applies any symbol mangling needed for C linkage, and sets up a define such that ++; subsequent uses of the function name automatically refer to the mangled version. ++; Appends cpuflags to the function name if cpuflags has been specified. ++%macro cglobal 1-2+ ; name, [PROLOGUE args] ++%if %0 == 1 ++ ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10 ++ %ifndef cpuname ++ cglobal_internal %1 ++ %else ++ cglobal_internal %1 %+ SUFFIX ++ %endif ++%else ++ ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10 ++ %ifndef cpuname ++ cglobal_internal %1, %2 ++ %else ++ cglobal_internal %1 %+ SUFFIX, %2 ++ %endif ++%endif ++%endmacro ++%macro cglobal_internal 1-2+ ++ %ifndef cglobaled_%1 ++ %xdefine %1 mangle(program_name %+ _ %+ %1) ++ %xdefine %1.skip_prologue %1 %+ .skip_prologue ++ CAT_XDEFINE cglobaled_, %1, 1 ++ %endif ++ %xdefine current_function %1 ++ %ifidn __OUTPUT_FORMAT__,elf ++ global %1:function hidden ++ %else ++ global %1 ++ %endif ++ align function_align ++ %1: ++ RESET_MM_PERMUTATION ; not really needed, but makes disassembly somewhat nicer ++ %assign stack_offset 0 ++ %if %0 > 1 ++ PROLOGUE %2 ++ %endif ++%endmacro ++ ++%macro cextern 1 ++ %xdefine %1 mangle(program_name %+ _ %+ %1) ++ CAT_XDEFINE cglobaled_, %1, 1 ++ extern %1 ++%endmacro ++ ++; like cextern, but without the prefix ++%macro cextern_naked 1 ++ %xdefine %1 mangle(%1) ++ CAT_XDEFINE cglobaled_, %1, 1 ++ extern %1 ++%endmacro ++ ++%macro const 2+ ++ %xdefine %1 mangle(program_name %+ _ %+ %1) ++ global %1 ++ %1: %2 ++%endmacro ++ ++; This is needed for ELF, otherwise the GNU linker assumes the stack is ++; executable by default. ++%ifidn __OUTPUT_FORMAT__,elf ++SECTION .note.GNU-stack noalloc noexec nowrite progbits ++%endif ++ ++; cpuflags ++ ++%assign cpuflags_mmx (1<<0) ++%assign cpuflags_mmx2 (1<<1) | cpuflags_mmx ++%assign cpuflags_3dnow (1<<2) | cpuflags_mmx ++%assign cpuflags_3dnow2 (1<<3) | cpuflags_3dnow ++%assign cpuflags_sse (1<<4) | cpuflags_mmx2 ++%assign cpuflags_sse2 (1<<5) | cpuflags_sse ++%assign cpuflags_sse2slow (1<<6) | cpuflags_sse2 ++%assign cpuflags_sse3 (1<<7) | cpuflags_sse2 ++%assign cpuflags_ssse3 (1<<8) | cpuflags_sse3 ++%assign cpuflags_sse4 (1<<9) | cpuflags_ssse3 ++%assign cpuflags_sse42 (1<<10)| cpuflags_sse4 ++%assign cpuflags_avx (1<<11)| cpuflags_sse42 ++%assign cpuflags_xop (1<<12)| cpuflags_avx ++%assign cpuflags_fma4 (1<<13)| cpuflags_avx ++ ++%assign cpuflags_cache32 (1<<16) ++%assign cpuflags_cache64 (1<<17) ++%assign cpuflags_slowctz (1<<18) ++%assign cpuflags_lzcnt (1<<19) ++%assign cpuflags_misalign (1<<20) ++%assign cpuflags_aligned (1<<21) ; not a cpu feature, but a function variant ++%assign cpuflags_atom (1<<22) ++ ++%define cpuflag(x) ((cpuflags & (cpuflags_ %+ x)) == (cpuflags_ %+ x)) ++%define notcpuflag(x) ((cpuflags & (cpuflags_ %+ x)) != (cpuflags_ %+ x)) ++ ++; Takes up to 2 cpuflags from the above list. ++; All subsequent functions (up to the next INIT_CPUFLAGS) is built for the specified cpu. ++; You shouldn't need to invoke this macro directly, it's a subroutine for INIT_MMX &co. ++%macro INIT_CPUFLAGS 0-2 ++ %if %0 >= 1 ++ %xdefine cpuname %1 ++ %assign cpuflags cpuflags_%1 ++ %if %0 >= 2 ++ %xdefine cpuname %1_%2 ++ %assign cpuflags cpuflags | cpuflags_%2 ++ %endif ++ %xdefine SUFFIX _ %+ cpuname ++ %if cpuflag(avx) ++ %assign avx_enabled 1 ++ %endif ++ %if mmsize == 16 && notcpuflag(sse2) ++ %define mova movaps ++ %define movu movups ++ %define movnta movntps ++ %endif ++ %if cpuflag(aligned) ++ %define movu mova ++ %elifidn %1, sse3 ++ %define movu lddqu ++ %endif ++ %else ++ %xdefine SUFFIX ++ %undef cpuname ++ %undef cpuflags ++ %endif ++%endmacro ++ ++; merge mmx and sse* ++ ++%macro CAT_XDEFINE 3 ++ %xdefine %1%2 %3 ++%endmacro ++ ++%macro CAT_UNDEF 2 ++ %undef %1%2 ++%endmacro ++ ++%macro INIT_MMX 0-1+ ++ %assign avx_enabled 0 ++ %define RESET_MM_PERMUTATION INIT_MMX %1 ++ %define mmsize 8 ++ %define num_mmregs 8 ++ %define mova movq ++ %define movu movq ++ %define movh movd ++ %define movnta movntq ++ %assign %%i 0 ++ %rep 8 ++ CAT_XDEFINE m, %%i, mm %+ %%i ++ CAT_XDEFINE nmm, %%i, %%i ++ %assign %%i %%i+1 ++ %endrep ++ %rep 8 ++ CAT_UNDEF m, %%i ++ CAT_UNDEF nmm, %%i ++ %assign %%i %%i+1 ++ %endrep ++ INIT_CPUFLAGS %1 ++%endmacro ++ ++%macro INIT_XMM 0-1+ ++ %assign avx_enabled 0 ++ %define RESET_MM_PERMUTATION INIT_XMM %1 ++ %define mmsize 16 ++ %define num_mmregs 8 ++ %ifdef ARCH_X86_64 ++ %define num_mmregs 16 ++ %endif ++ %define mova movdqa ++ %define movu movdqu ++ %define movh movq ++ %define movnta movntdq ++ %assign %%i 0 ++ %rep num_mmregs ++ CAT_XDEFINE m, %%i, xmm %+ %%i ++ CAT_XDEFINE nxmm, %%i, %%i ++ %assign %%i %%i+1 ++ %endrep ++ INIT_CPUFLAGS %1 ++%endmacro ++ ++; FIXME: INIT_AVX can be replaced by INIT_XMM avx ++%macro INIT_AVX 0 ++ INIT_XMM ++ %assign avx_enabled 1 ++ %define PALIGNR PALIGNR_SSSE3 ++ %define RESET_MM_PERMUTATION INIT_AVX ++%endmacro ++ ++%macro INIT_YMM 0-1+ ++ %assign avx_enabled 1 ++ %define RESET_MM_PERMUTATION INIT_YMM %1 ++ %define mmsize 32 ++ %define num_mmregs 8 ++ %ifdef ARCH_X86_64 ++ %define num_mmregs 16 ++ %endif ++ %define mova vmovaps ++ %define movu vmovups ++ %undef movh ++ %define movnta vmovntps ++ %assign %%i 0 ++ %rep num_mmregs ++ CAT_XDEFINE m, %%i, ymm %+ %%i ++ CAT_XDEFINE nymm, %%i, %%i ++ %assign %%i %%i+1 ++ %endrep ++ INIT_CPUFLAGS %1 ++%endmacro ++ ++INIT_XMM ++ ++; I often want to use macros that permute their arguments. e.g. there's no ++; efficient way to implement butterfly or transpose or dct without swapping some ++; arguments. ++; ++; I would like to not have to manually keep track of the permutations: ++; If I insert a permutation in the middle of a function, it should automatically ++; change everything that follows. For more complex macros I may also have multiple ++; implementations, e.g. the SSE2 and SSSE3 versions may have different permutations. ++; ++; Hence these macros. Insert a PERMUTE or some SWAPs at the end of a macro that ++; permutes its arguments. It's equivalent to exchanging the contents of the ++; registers, except that this way you exchange the register names instead, so it ++; doesn't cost any cycles. ++ ++%macro PERMUTE 2-* ; takes a list of pairs to swap ++%rep %0/2 ++ %xdefine tmp%2 m%2 ++ %xdefine ntmp%2 nm%2 ++ %rotate 2 ++%endrep ++%rep %0/2 ++ %xdefine m%1 tmp%2 ++ %xdefine nm%1 ntmp%2 ++ %undef tmp%2 ++ %undef ntmp%2 ++ %rotate 2 ++%endrep ++%endmacro ++ ++%macro SWAP 2-* ; swaps a single chain (sometimes more concise than pairs) ++%rep %0-1 ++%ifdef m%1 ++ %xdefine tmp m%1 ++ %xdefine m%1 m%2 ++ %xdefine m%2 tmp ++ CAT_XDEFINE n, m%1, %1 ++ CAT_XDEFINE n, m%2, %2 ++%else ++ ; If we were called as "SWAP m0,m1" rather than "SWAP 0,1" infer the original numbers here. ++ ; Be careful using this mode in nested macros though, as in some cases there may be ++ ; other copies of m# that have already been dereferenced and don't get updated correctly. ++ %xdefine %%n1 n %+ %1 ++ %xdefine %%n2 n %+ %2 ++ %xdefine tmp m %+ %%n1 ++ CAT_XDEFINE m, %%n1, m %+ %%n2 ++ CAT_XDEFINE m, %%n2, tmp ++ CAT_XDEFINE n, m %+ %%n1, %%n1 ++ CAT_XDEFINE n, m %+ %%n2, %%n2 ++%endif ++ %undef tmp ++ %rotate 1 ++%endrep ++%endmacro ++ ++; If SAVE_MM_PERMUTATION is placed at the end of a function, then any later ++; calls to that function will automatically load the permutation, so values can ++; be returned in mmregs. ++%macro SAVE_MM_PERMUTATION 0-1 ++ %if %0 ++ %xdefine %%f %1_m ++ %else ++ %xdefine %%f current_function %+ _m ++ %endif ++ %assign %%i 0 ++ %rep num_mmregs ++ CAT_XDEFINE %%f, %%i, m %+ %%i ++ %assign %%i %%i+1 ++ %endrep ++%endmacro ++ ++%macro LOAD_MM_PERMUTATION 1 ; name to load from ++ %ifdef %1_m0 ++ %assign %%i 0 ++ %rep num_mmregs ++ CAT_XDEFINE m, %%i, %1_m %+ %%i ++ CAT_XDEFINE n, m %+ %%i, %%i ++ %assign %%i %%i+1 ++ %endrep ++ %endif ++%endmacro ++ ++; Append cpuflags to the callee's name iff the appended name is known and the plain name isn't ++%macro call 1 ++ ; HACK: work around %+ broken with empty SUFFIX for nasm 2.09.10 ++ %ifndef cpuname ++ call_internal %1, %1 ++ %else ++ call_internal %1, %1 %+ SUFFIX ++ %endif ++%endmacro ++%macro call_internal 2 ++ %xdefine %%i %1 ++ %ifndef cglobaled_%1 ++ %ifdef cglobaled_%2 ++ %xdefine %%i %2 ++ %endif ++ %endif ++ call %%i ++ LOAD_MM_PERMUTATION %%i ++%endmacro ++ ++; Substitutions that reduce instruction size but are functionally equivalent ++%macro add 2 ++ %ifnum %2 ++ %if %2==128 ++ sub %1, -128 ++ %else ++ add %1, %2 ++ %endif ++ %else ++ add %1, %2 ++ %endif ++%endmacro ++ ++%macro sub 2 ++ %ifnum %2 ++ %if %2==128 ++ add %1, -128 ++ %else ++ sub %1, %2 ++ %endif ++ %else ++ sub %1, %2 ++ %endif ++%endmacro ++ ++;============================================================================= ++; AVX abstraction layer ++;============================================================================= ++ ++%assign i 0 ++%rep 16 ++ %if i < 8 ++ CAT_XDEFINE sizeofmm, i, 8 ++ %endif ++ CAT_XDEFINE sizeofxmm, i, 16 ++ CAT_XDEFINE sizeofymm, i, 32 ++%assign i i+1 ++%endrep ++%undef i ++ ++;%1 == instruction ++;%2 == 1 if float, 0 if int ++;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 3-operand (xmm, xmm, xmm) ++;%4 == number of operands given ++;%5+: operands ++%macro RUN_AVX_INSTR 6-7+ ++ %ifid %5 ++ %define %%size sizeof%5 ++ %else ++ %define %%size mmsize ++ %endif ++ %if %%size==32 ++ v%1 %5, %6, %7 ++ %else ++ %if %%size==8 ++ %define %%regmov movq ++ %elif %2 ++ %define %%regmov movaps ++ %else ++ %define %%regmov movdqa ++ %endif ++ ++ %if %4>=3+%3 ++ %ifnidn %5, %6 ++ %if avx_enabled && sizeof%5==16 ++ v%1 %5, %6, %7 ++ %else ++ %%regmov %5, %6 ++ %1 %5, %7 ++ %endif ++ %else ++ %1 %5, %7 ++ %endif ++ %elif %3 ++ %1 %5, %6, %7 ++ %else ++ %1 %5, %6 ++ %endif ++ %endif ++%endmacro ++ ++; 3arg AVX ops with a memory arg can only have it in src2, ++; whereas SSE emulation of 3arg prefers to have it in src1 (i.e. the mov). ++; So, if the op is symmetric and the wrong one is memory, swap them. ++%macro RUN_AVX_INSTR1 8 ++ %assign %%swap 0 ++ %if avx_enabled ++ %ifnid %6 ++ %assign %%swap 1 ++ %endif ++ %elifnidn %5, %6 ++ %ifnid %7 ++ %assign %%swap 1 ++ %endif ++ %endif ++ %if %%swap && %3 == 0 && %8 == 1 ++ RUN_AVX_INSTR %1, %2, %3, %4, %5, %7, %6 ++ %else ++ RUN_AVX_INSTR %1, %2, %3, %4, %5, %6, %7 ++ %endif ++%endmacro ++ ++;%1 == instruction ++;%2 == 1 if float, 0 if int ++;%3 == 1 if 4-operand (xmm, xmm, xmm, imm), 0 if 3-operand (xmm, xmm, xmm) ++;%4 == 1 if symmetric (i.e. doesn't matter which src arg is which), 0 if not ++%macro AVX_INSTR 4 ++ %macro %1 2-9 fnord, fnord, fnord, %1, %2, %3, %4 ++ %ifidn %3, fnord ++ RUN_AVX_INSTR %6, %7, %8, 2, %1, %2 ++ %elifidn %4, fnord ++ RUN_AVX_INSTR1 %6, %7, %8, 3, %1, %2, %3, %9 ++ %elifidn %5, fnord ++ RUN_AVX_INSTR %6, %7, %8, 4, %1, %2, %3, %4 ++ %else ++ RUN_AVX_INSTR %6, %7, %8, 5, %1, %2, %3, %4, %5 ++ %endif ++ %endmacro ++%endmacro ++ ++AVX_INSTR addpd, 1, 0, 1 ++AVX_INSTR addps, 1, 0, 1 ++AVX_INSTR addsd, 1, 0, 1 ++AVX_INSTR addss, 1, 0, 1 ++AVX_INSTR addsubpd, 1, 0, 0 ++AVX_INSTR addsubps, 1, 0, 0 ++AVX_INSTR andpd, 1, 0, 1 ++AVX_INSTR andps, 1, 0, 1 ++AVX_INSTR andnpd, 1, 0, 0 ++AVX_INSTR andnps, 1, 0, 0 ++AVX_INSTR blendpd, 1, 0, 0 ++AVX_INSTR blendps, 1, 0, 0 ++AVX_INSTR blendvpd, 1, 0, 0 ++AVX_INSTR blendvps, 1, 0, 0 ++AVX_INSTR cmppd, 1, 0, 0 ++AVX_INSTR cmpps, 1, 0, 0 ++AVX_INSTR cmpsd, 1, 0, 0 ++AVX_INSTR cmpss, 1, 0, 0 ++AVX_INSTR divpd, 1, 0, 0 ++AVX_INSTR divps, 1, 0, 0 ++AVX_INSTR divsd, 1, 0, 0 ++AVX_INSTR divss, 1, 0, 0 ++AVX_INSTR dppd, 1, 1, 0 ++AVX_INSTR dpps, 1, 1, 0 ++AVX_INSTR haddpd, 1, 0, 0 ++AVX_INSTR haddps, 1, 0, 0 ++AVX_INSTR hsubpd, 1, 0, 0 ++AVX_INSTR hsubps, 1, 0, 0 ++AVX_INSTR maxpd, 1, 0, 1 ++AVX_INSTR maxps, 1, 0, 1 ++AVX_INSTR maxsd, 1, 0, 1 ++AVX_INSTR maxss, 1, 0, 1 ++AVX_INSTR minpd, 1, 0, 1 ++AVX_INSTR minps, 1, 0, 1 ++AVX_INSTR minsd, 1, 0, 1 ++AVX_INSTR minss, 1, 0, 1 ++AVX_INSTR movhlps, 1, 0, 0 ++AVX_INSTR movlhps, 1, 0, 0 ++AVX_INSTR movsd, 1, 0, 0 ++AVX_INSTR movss, 1, 0, 0 ++AVX_INSTR mpsadbw, 0, 1, 0 ++AVX_INSTR mulpd, 1, 0, 1 ++AVX_INSTR mulps, 1, 0, 1 ++AVX_INSTR mulsd, 1, 0, 1 ++AVX_INSTR mulss, 1, 0, 1 ++AVX_INSTR orpd, 1, 0, 1 ++AVX_INSTR orps, 1, 0, 1 ++AVX_INSTR packsswb, 0, 0, 0 ++AVX_INSTR packssdw, 0, 0, 0 ++AVX_INSTR packuswb, 0, 0, 0 ++AVX_INSTR packusdw, 0, 0, 0 ++AVX_INSTR paddb, 0, 0, 1 ++AVX_INSTR paddw, 0, 0, 1 ++AVX_INSTR paddd, 0, 0, 1 ++AVX_INSTR paddq, 0, 0, 1 ++AVX_INSTR paddsb, 0, 0, 1 ++AVX_INSTR paddsw, 0, 0, 1 ++AVX_INSTR paddusb, 0, 0, 1 ++AVX_INSTR paddusw, 0, 0, 1 ++AVX_INSTR palignr, 0, 1, 0 ++AVX_INSTR pand, 0, 0, 1 ++AVX_INSTR pandn, 0, 0, 0 ++AVX_INSTR pavgb, 0, 0, 1 ++AVX_INSTR pavgw, 0, 0, 1 ++AVX_INSTR pblendvb, 0, 0, 0 ++AVX_INSTR pblendw, 0, 1, 0 ++AVX_INSTR pcmpestri, 0, 0, 0 ++AVX_INSTR pcmpestrm, 0, 0, 0 ++AVX_INSTR pcmpistri, 0, 0, 0 ++AVX_INSTR pcmpistrm, 0, 0, 0 ++AVX_INSTR pcmpeqb, 0, 0, 1 ++AVX_INSTR pcmpeqw, 0, 0, 1 ++AVX_INSTR pcmpeqd, 0, 0, 1 ++AVX_INSTR pcmpeqq, 0, 0, 1 ++AVX_INSTR pcmpgtb, 0, 0, 0 ++AVX_INSTR pcmpgtw, 0, 0, 0 ++AVX_INSTR pcmpgtd, 0, 0, 0 ++AVX_INSTR pcmpgtq, 0, 0, 0 ++AVX_INSTR phaddw, 0, 0, 0 ++AVX_INSTR phaddd, 0, 0, 0 ++AVX_INSTR phaddsw, 0, 0, 0 ++AVX_INSTR phsubw, 0, 0, 0 ++AVX_INSTR phsubd, 0, 0, 0 ++AVX_INSTR phsubsw, 0, 0, 0 ++AVX_INSTR pmaddwd, 0, 0, 1 ++AVX_INSTR pmaddubsw, 0, 0, 0 ++AVX_INSTR pmaxsb, 0, 0, 1 ++AVX_INSTR pmaxsw, 0, 0, 1 ++AVX_INSTR pmaxsd, 0, 0, 1 ++AVX_INSTR pmaxub, 0, 0, 1 ++AVX_INSTR pmaxuw, 0, 0, 1 ++AVX_INSTR pmaxud, 0, 0, 1 ++AVX_INSTR pminsb, 0, 0, 1 ++AVX_INSTR pminsw, 0, 0, 1 ++AVX_INSTR pminsd, 0, 0, 1 ++AVX_INSTR pminub, 0, 0, 1 ++AVX_INSTR pminuw, 0, 0, 1 ++AVX_INSTR pminud, 0, 0, 1 ++AVX_INSTR pmulhuw, 0, 0, 1 ++AVX_INSTR pmulhrsw, 0, 0, 1 ++AVX_INSTR pmulhw, 0, 0, 1 ++AVX_INSTR pmullw, 0, 0, 1 ++AVX_INSTR pmulld, 0, 0, 1 ++AVX_INSTR pmuludq, 0, 0, 1 ++AVX_INSTR pmuldq, 0, 0, 1 ++AVX_INSTR por, 0, 0, 1 ++AVX_INSTR psadbw, 0, 0, 1 ++AVX_INSTR pshufb, 0, 0, 0 ++AVX_INSTR psignb, 0, 0, 0 ++AVX_INSTR psignw, 0, 0, 0 ++AVX_INSTR psignd, 0, 0, 0 ++AVX_INSTR psllw, 0, 0, 0 ++AVX_INSTR pslld, 0, 0, 0 ++AVX_INSTR psllq, 0, 0, 0 ++AVX_INSTR pslldq, 0, 0, 0 ++AVX_INSTR psraw, 0, 0, 0 ++AVX_INSTR psrad, 0, 0, 0 ++AVX_INSTR psrlw, 0, 0, 0 ++AVX_INSTR psrld, 0, 0, 0 ++AVX_INSTR psrlq, 0, 0, 0 ++AVX_INSTR psrldq, 0, 0, 0 ++AVX_INSTR psubb, 0, 0, 0 ++AVX_INSTR psubw, 0, 0, 0 ++AVX_INSTR psubd, 0, 0, 0 ++AVX_INSTR psubq, 0, 0, 0 ++AVX_INSTR psubsb, 0, 0, 0 ++AVX_INSTR psubsw, 0, 0, 0 ++AVX_INSTR psubusb, 0, 0, 0 ++AVX_INSTR psubusw, 0, 0, 0 ++AVX_INSTR punpckhbw, 0, 0, 0 ++AVX_INSTR punpckhwd, 0, 0, 0 ++AVX_INSTR punpckhdq, 0, 0, 0 ++AVX_INSTR punpckhqdq, 0, 0, 0 ++AVX_INSTR punpcklbw, 0, 0, 0 ++AVX_INSTR punpcklwd, 0, 0, 0 ++AVX_INSTR punpckldq, 0, 0, 0 ++AVX_INSTR punpcklqdq, 0, 0, 0 ++AVX_INSTR pxor, 0, 0, 1 ++AVX_INSTR shufps, 1, 1, 0 ++AVX_INSTR subpd, 1, 0, 0 ++AVX_INSTR subps, 1, 0, 0 ++AVX_INSTR subsd, 1, 0, 0 ++AVX_INSTR subss, 1, 0, 0 ++AVX_INSTR unpckhpd, 1, 0, 0 ++AVX_INSTR unpckhps, 1, 0, 0 ++AVX_INSTR unpcklpd, 1, 0, 0 ++AVX_INSTR unpcklps, 1, 0, 0 ++AVX_INSTR xorpd, 1, 0, 1 ++AVX_INSTR xorps, 1, 0, 1 ++ ++; 3DNow instructions, for sharing code between AVX, SSE and 3DN ++AVX_INSTR pfadd, 1, 0, 1 ++AVX_INSTR pfsub, 1, 0, 0 ++AVX_INSTR pfmul, 1, 0, 1 ++ ++; base-4 constants for shuffles ++%assign i 0 ++%rep 256 ++ %assign j ((i>>6)&3)*1000 + ((i>>4)&3)*100 + ((i>>2)&3)*10 + (i&3) ++ %if j < 10 ++ CAT_XDEFINE q000, j, i ++ %elif j < 100 ++ CAT_XDEFINE q00, j, i ++ %elif j < 1000 ++ CAT_XDEFINE q0, j, i ++ %else ++ CAT_XDEFINE q, j, i ++ %endif ++%assign i i+1 ++%endrep ++%undef i ++%undef j ++ ++%macro FMA_INSTR 3 ++ %macro %1 4-7 %1, %2, %3 ++ %if cpuflag(xop) ++ v%5 %1, %2, %3, %4 ++ %else ++ %6 %1, %2, %3 ++ %7 %1, %4 ++ %endif ++ %endmacro ++%endmacro ++ ++FMA_INSTR pmacsdd, pmulld, paddd ++FMA_INSTR pmacsww, pmullw, paddw ++FMA_INSTR pmadcswd, pmaddwd, paddd +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/x86util.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/x86util.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libavutil/x86/x86util.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libavutil/x86/x86util.asm 2012-05-14 14:08:55.351360451 +0200 +@@ -0,0 +1,587 @@ ++;***************************************************************************** ++;* x86util.asm ++;***************************************************************************** ++;* Copyright (C) 2008-2010 x264 project ++;* ++;* Authors: Loren Merritt ++;* Holger Lubitz ++;* ++;* This file is part of FFmpeg. ++;* ++;* FFmpeg is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* FFmpeg 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with FFmpeg; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%macro SBUTTERFLY 4 ++%if avx_enabled == 0 ++ mova m%4, m%2 ++ punpckl%1 m%2, m%3 ++ punpckh%1 m%4, m%3 ++%else ++ punpckh%1 m%4, m%2, m%3 ++ punpckl%1 m%2, m%3 ++%endif ++ SWAP %3, %4 ++%endmacro ++ ++%macro SBUTTERFLY2 4 ++ punpckl%1 m%4, m%2, m%3 ++ punpckh%1 m%2, m%2, m%3 ++ SWAP %2, %4, %3 ++%endmacro ++ ++%macro SBUTTERFLYPS 3 ++ movaps m%3, m%1 ++ unpcklps m%1, m%2 ++ unpckhps m%3, m%2 ++ SWAP %2, %3 ++%endmacro ++ ++%macro TRANSPOSE4x4B 5 ++ SBUTTERFLY bw, %1, %2, %5 ++ SBUTTERFLY bw, %3, %4, %5 ++ SBUTTERFLY wd, %1, %3, %5 ++ SBUTTERFLY wd, %2, %4, %5 ++ SWAP %2, %3 ++%endmacro ++ ++%macro TRANSPOSE4x4W 5 ++ SBUTTERFLY wd, %1, %2, %5 ++ SBUTTERFLY wd, %3, %4, %5 ++ SBUTTERFLY dq, %1, %3, %5 ++ SBUTTERFLY dq, %2, %4, %5 ++ SWAP %2, %3 ++%endmacro ++ ++%macro TRANSPOSE2x4x4W 5 ++ SBUTTERFLY wd, %1, %2, %5 ++ SBUTTERFLY wd, %3, %4, %5 ++ SBUTTERFLY dq, %1, %3, %5 ++ SBUTTERFLY dq, %2, %4, %5 ++ SBUTTERFLY qdq, %1, %2, %5 ++ SBUTTERFLY qdq, %3, %4, %5 ++%endmacro ++ ++%macro TRANSPOSE4x4D 5 ++ SBUTTERFLY dq, %1, %2, %5 ++ SBUTTERFLY dq, %3, %4, %5 ++ SBUTTERFLY qdq, %1, %3, %5 ++ SBUTTERFLY qdq, %2, %4, %5 ++ SWAP %2, %3 ++%endmacro ++ ++; identical behavior to TRANSPOSE4x4D, but using SSE1 float ops ++%macro TRANSPOSE4x4PS 5 ++ SBUTTERFLYPS %1, %2, %5 ++ SBUTTERFLYPS %3, %4, %5 ++ movaps m%5, m%1 ++ movlhps m%1, m%3 ++ movhlps m%3, m%5 ++ movaps m%5, m%2 ++ movlhps m%2, m%4 ++ movhlps m%4, m%5 ++ SWAP %2, %3 ++%endmacro ++ ++%macro TRANSPOSE8x8W 9-11 ++%ifdef ARCH_X86_64 ++ SBUTTERFLY wd, %1, %2, %9 ++ SBUTTERFLY wd, %3, %4, %9 ++ SBUTTERFLY wd, %5, %6, %9 ++ SBUTTERFLY wd, %7, %8, %9 ++ SBUTTERFLY dq, %1, %3, %9 ++ SBUTTERFLY dq, %2, %4, %9 ++ SBUTTERFLY dq, %5, %7, %9 ++ SBUTTERFLY dq, %6, %8, %9 ++ SBUTTERFLY qdq, %1, %5, %9 ++ SBUTTERFLY qdq, %2, %6, %9 ++ SBUTTERFLY qdq, %3, %7, %9 ++ SBUTTERFLY qdq, %4, %8, %9 ++ SWAP %2, %5 ++ SWAP %4, %7 ++%else ++; in: m0..m7, unless %11 in which case m6 is in %9 ++; out: m0..m7, unless %11 in which case m4 is in %10 ++; spills into %9 and %10 ++%if %0<11 ++ movdqa %9, m%7 ++%endif ++ SBUTTERFLY wd, %1, %2, %7 ++ movdqa %10, m%2 ++ movdqa m%7, %9 ++ SBUTTERFLY wd, %3, %4, %2 ++ SBUTTERFLY wd, %5, %6, %2 ++ SBUTTERFLY wd, %7, %8, %2 ++ SBUTTERFLY dq, %1, %3, %2 ++ movdqa %9, m%3 ++ movdqa m%2, %10 ++ SBUTTERFLY dq, %2, %4, %3 ++ SBUTTERFLY dq, %5, %7, %3 ++ SBUTTERFLY dq, %6, %8, %3 ++ SBUTTERFLY qdq, %1, %5, %3 ++ SBUTTERFLY qdq, %2, %6, %3 ++ movdqa %10, m%2 ++ movdqa m%3, %9 ++ SBUTTERFLY qdq, %3, %7, %2 ++ SBUTTERFLY qdq, %4, %8, %2 ++ SWAP %2, %5 ++ SWAP %4, %7 ++%if %0<11 ++ movdqa m%5, %10 ++%endif ++%endif ++%endmacro ++ ++; PABSW macros assume %1 != %2, while ABS1/2 macros work in-place ++%macro PABSW_MMX 2 ++ pxor %1, %1 ++ pcmpgtw %1, %2 ++ pxor %2, %1 ++ psubw %2, %1 ++ SWAP %1, %2 ++%endmacro ++ ++%macro PSIGNW_MMX 2 ++ pxor %1, %2 ++ psubw %1, %2 ++%endmacro ++ ++%macro PABSW_MMX2 2 ++ pxor %1, %1 ++ psubw %1, %2 ++ pmaxsw %1, %2 ++%endmacro ++ ++%macro PABSW_SSSE3 2 ++ pabsw %1, %2 ++%endmacro ++ ++%macro PSIGNW_SSSE3 2 ++ psignw %1, %2 ++%endmacro ++ ++%macro ABS1_MMX 2 ; a, tmp ++ pxor %2, %2 ++ pcmpgtw %2, %1 ++ pxor %1, %2 ++ psubw %1, %2 ++%endmacro ++ ++%macro ABS2_MMX 4 ; a, b, tmp0, tmp1 ++ pxor %3, %3 ++ pxor %4, %4 ++ pcmpgtw %3, %1 ++ pcmpgtw %4, %2 ++ pxor %1, %3 ++ pxor %2, %4 ++ psubw %1, %3 ++ psubw %2, %4 ++%endmacro ++ ++%macro ABS1_MMX2 2 ; a, tmp ++ pxor %2, %2 ++ psubw %2, %1 ++ pmaxsw %1, %2 ++%endmacro ++ ++%macro ABS2_MMX2 4 ; a, b, tmp0, tmp1 ++ pxor %3, %3 ++ pxor %4, %4 ++ psubw %3, %1 ++ psubw %4, %2 ++ pmaxsw %1, %3 ++ pmaxsw %2, %4 ++%endmacro ++ ++%macro ABS1_SSSE3 2 ++ pabsw %1, %1 ++%endmacro ++ ++%macro ABS2_SSSE3 4 ++ pabsw %1, %1 ++ pabsw %2, %2 ++%endmacro ++ ++%macro ABSB_MMX 2 ++ pxor %2, %2 ++ psubb %2, %1 ++ pminub %1, %2 ++%endmacro ++ ++%macro ABSB2_MMX 4 ++ pxor %3, %3 ++ pxor %4, %4 ++ psubb %3, %1 ++ psubb %4, %2 ++ pminub %1, %3 ++ pminub %2, %4 ++%endmacro ++ ++%macro ABSD2_MMX 4 ++ pxor %3, %3 ++ pxor %4, %4 ++ pcmpgtd %3, %1 ++ pcmpgtd %4, %2 ++ pxor %1, %3 ++ pxor %2, %4 ++ psubd %1, %3 ++ psubd %2, %4 ++%endmacro ++ ++%macro ABSB_SSSE3 2 ++ pabsb %1, %1 ++%endmacro ++ ++%macro ABSB2_SSSE3 4 ++ pabsb %1, %1 ++ pabsb %2, %2 ++%endmacro ++ ++%macro ABS4 6 ++ ABS2 %1, %2, %5, %6 ++ ABS2 %3, %4, %5, %6 ++%endmacro ++ ++%define ABS1 ABS1_MMX ++%define ABS2 ABS2_MMX ++%define ABSB ABSB_MMX ++%define ABSB2 ABSB2_MMX ++ ++%macro SPLATB_MMX 3 ++ movd %1, [%2-3] ;to avoid crossing a cacheline ++ punpcklbw %1, %1 ++ SPLATW %1, %1, 3 ++%endmacro ++ ++%macro SPLATB_SSSE3 3 ++ movd %1, [%2-3] ++ pshufb %1, %3 ++%endmacro ++ ++%macro PALIGNR_MMX 4-5 ; [dst,] src1, src2, imm, tmp ++ %define %%dst %1 ++%if %0==5 ++%ifnidn %1, %2 ++ mova %%dst, %2 ++%endif ++ %rotate 1 ++%endif ++%ifnidn %4, %2 ++ mova %4, %2 ++%endif ++%if mmsize==8 ++ psllq %%dst, (8-%3)*8 ++ psrlq %4, %3*8 ++%else ++ pslldq %%dst, 16-%3 ++ psrldq %4, %3 ++%endif ++ por %%dst, %4 ++%endmacro ++ ++%macro PALIGNR_SSSE3 4-5 ++%if %0==5 ++ palignr %1, %2, %3, %4 ++%else ++ palignr %1, %2, %3 ++%endif ++%endmacro ++ ++%macro DEINTB 5 ; mask, reg1, mask, reg2, optional src to fill masks from ++%ifnum %5 ++ pand m%3, m%5, m%4 ; src .. y6 .. y4 ++ pand m%1, m%5, m%2 ; dst .. y6 .. y4 ++%else ++ mova m%1, %5 ++ pand m%3, m%1, m%4 ; src .. y6 .. y4 ++ pand m%1, m%1, m%2 ; dst .. y6 .. y4 ++%endif ++ psrlw m%2, 8 ; dst .. y7 .. y5 ++ psrlw m%4, 8 ; src .. y7 .. y5 ++%endmacro ++ ++%macro SUMSUB_BA 3-4 ++%if %0==3 ++ padd%1 m%2, m%3 ++ padd%1 m%3, m%3 ++ psub%1 m%3, m%2 ++%else ++%if avx_enabled == 0 ++ mova m%4, m%2 ++ padd%1 m%2, m%3 ++ psub%1 m%3, m%4 ++%else ++ padd%1 m%4, m%2, m%3 ++ psub%1 m%3, m%2 ++ SWAP %2, %4 ++%endif ++%endif ++%endmacro ++ ++%macro SUMSUB_BADC 5-6 ++%if %0==6 ++ SUMSUB_BA %1, %2, %3, %6 ++ SUMSUB_BA %1, %4, %5, %6 ++%else ++ padd%1 m%2, m%3 ++ padd%1 m%4, m%5 ++ padd%1 m%3, m%3 ++ padd%1 m%5, m%5 ++ psub%1 m%3, m%2 ++ psub%1 m%5, m%4 ++%endif ++%endmacro ++ ++%macro SUMSUB2_AB 4 ++%ifnum %3 ++ psub%1 m%4, m%2, m%3 ++ psub%1 m%4, m%3 ++ padd%1 m%2, m%2 ++ padd%1 m%2, m%3 ++%else ++ mova m%4, m%2 ++ padd%1 m%2, m%2 ++ padd%1 m%2, %3 ++ psub%1 m%4, %3 ++ psub%1 m%4, %3 ++%endif ++%endmacro ++ ++%macro SUMSUB2_BA 4 ++%if avx_enabled == 0 ++ mova m%4, m%2 ++ padd%1 m%2, m%3 ++ padd%1 m%2, m%3 ++ psub%1 m%3, m%4 ++ psub%1 m%3, m%4 ++%else ++ padd%1 m%4, m%2, m%3 ++ padd%1 m%4, m%3 ++ psub%1 m%3, m%2 ++ psub%1 m%3, m%2 ++ SWAP %2, %4 ++%endif ++%endmacro ++ ++%macro SUMSUBD2_AB 5 ++%ifnum %4 ++ psra%1 m%5, m%2, 1 ; %3: %3>>1 ++ psra%1 m%4, m%3, 1 ; %2: %2>>1 ++ padd%1 m%4, m%2 ; %3: %3>>1+%2 ++ psub%1 m%5, m%3 ; %2: %2>>1-%3 ++ SWAP %2, %5 ++ SWAP %3, %4 ++%else ++ mova %5, m%2 ++ mova %4, m%3 ++ psra%1 m%3, 1 ; %3: %3>>1 ++ psra%1 m%2, 1 ; %2: %2>>1 ++ padd%1 m%3, %5 ; %3: %3>>1+%2 ++ psub%1 m%2, %4 ; %2: %2>>1-%3 ++%endif ++%endmacro ++ ++%macro DCT4_1D 5 ++%ifnum %5 ++ SUMSUB_BADC w, %4, %1, %3, %2, %5 ++ SUMSUB_BA w, %3, %4, %5 ++ SUMSUB2_AB w, %1, %2, %5 ++ SWAP %1, %3, %4, %5, %2 ++%else ++ SUMSUB_BADC w, %4, %1, %3, %2 ++ SUMSUB_BA w, %3, %4 ++ mova [%5], m%2 ++ SUMSUB2_AB w, %1, [%5], %2 ++ SWAP %1, %3, %4, %2 ++%endif ++%endmacro ++ ++%macro IDCT4_1D 6-7 ++%ifnum %6 ++ SUMSUBD2_AB %1, %3, %5, %7, %6 ++ ; %3: %3>>1-%5 %5: %3+%5>>1 ++ SUMSUB_BA %1, %4, %2, %7 ++ ; %4: %2+%4 %2: %2-%4 ++ SUMSUB_BADC %1, %5, %4, %3, %2, %7 ++ ; %5: %2+%4 + (%3+%5>>1) ++ ; %4: %2+%4 - (%3+%5>>1) ++ ; %3: %2-%4 + (%3>>1-%5) ++ ; %2: %2-%4 - (%3>>1-%5) ++%else ++%ifidn %1, w ++ SUMSUBD2_AB %1, %3, %5, [%6], [%6+16] ++%else ++ SUMSUBD2_AB %1, %3, %5, [%6], [%6+32] ++%endif ++ SUMSUB_BA %1, %4, %2 ++ SUMSUB_BADC %1, %5, %4, %3, %2 ++%endif ++ SWAP %2, %5, %4 ++ ; %2: %2+%4 + (%3+%5>>1) row0 ++ ; %3: %2-%4 + (%3>>1-%5) row1 ++ ; %4: %2-%4 - (%3>>1-%5) row2 ++ ; %5: %2+%4 - (%3+%5>>1) row3 ++%endmacro ++ ++ ++%macro LOAD_DIFF 5 ++%ifidn %3, none ++ movh %1, %4 ++ movh %2, %5 ++ punpcklbw %1, %2 ++ punpcklbw %2, %2 ++ psubw %1, %2 ++%else ++ movh %1, %4 ++ punpcklbw %1, %3 ++ movh %2, %5 ++ punpcklbw %2, %3 ++ psubw %1, %2 ++%endif ++%endmacro ++ ++%macro STORE_DCT 6 ++ movq [%5+%6+ 0], m%1 ++ movq [%5+%6+ 8], m%2 ++ movq [%5+%6+16], m%3 ++ movq [%5+%6+24], m%4 ++ movhps [%5+%6+32], m%1 ++ movhps [%5+%6+40], m%2 ++ movhps [%5+%6+48], m%3 ++ movhps [%5+%6+56], m%4 ++%endmacro ++ ++%macro LOAD_DIFF_8x4P 7-10 r0,r2,0 ; 4x dest, 2x temp, 2x pointer, increment? ++ LOAD_DIFF m%1, m%5, m%7, [%8], [%9] ++ LOAD_DIFF m%2, m%6, m%7, [%8+r1], [%9+r3] ++ LOAD_DIFF m%3, m%5, m%7, [%8+2*r1], [%9+2*r3] ++ LOAD_DIFF m%4, m%6, m%7, [%8+r4], [%9+r5] ++%if %10 ++ lea %8, [%8+4*r1] ++ lea %9, [%9+4*r3] ++%endif ++%endmacro ++ ++%macro DIFFx2 6-7 ++ movh %3, %5 ++ punpcklbw %3, %4 ++ psraw %1, 6 ++ paddsw %1, %3 ++ movh %3, %6 ++ punpcklbw %3, %4 ++ psraw %2, 6 ++ paddsw %2, %3 ++ packuswb %2, %1 ++%endmacro ++ ++%macro STORE_DIFF 4 ++ movh %2, %4 ++ punpcklbw %2, %3 ++ psraw %1, 6 ++ paddsw %1, %2 ++ packuswb %1, %1 ++ movh %4, %1 ++%endmacro ++ ++%macro STORE_DIFFx2 8 ; add1, add2, reg1, reg2, zero, shift, source, stride ++ movh %3, [%7] ++ movh %4, [%7+%8] ++ psraw %1, %6 ++ psraw %2, %6 ++ punpcklbw %3, %5 ++ punpcklbw %4, %5 ++ paddw %3, %1 ++ paddw %4, %2 ++ packuswb %3, %5 ++ packuswb %4, %5 ++ movh [%7], %3 ++ movh [%7+%8], %4 ++%endmacro ++ ++%macro PMINUB_MMX 3 ; dst, src, tmp ++ mova %3, %1 ++ psubusb %3, %2 ++ psubb %1, %3 ++%endmacro ++ ++%macro PMINUB_MMXEXT 3 ; dst, src, ignored ++ pminub %1, %2 ++%endmacro ++ ++%macro SPLATW 2-3 0 ++%if mmsize == 16 ++ pshuflw %1, %2, (%3)*0x55 ++ punpcklqdq %1, %1 ++%else ++ pshufw %1, %2, (%3)*0x55 ++%endif ++%endmacro ++ ++%macro SPLATD 2-3 0 ++%if mmsize == 16 ++ pshufd %1, %2, (%3)*0x55 ++%else ++ pshufw %1, %2, (%3)*0x11 + ((%3)+1)*0x44 ++%endif ++%endmacro ++ ++%macro SPLATD_MMX 1 ++ punpckldq %1, %1 ++%endmacro ++ ++%macro SPLATD_SSE 1 ++ shufps %1, %1, 0 ++%endmacro ++ ++%macro SPLATD_SSE2 1 ++ pshufd %1, %1, 0 ++%endmacro ++ ++%macro CLIPW 3 ;(dst, min, max) ++ pmaxsw %1, %2 ++ pminsw %1, %3 ++%endmacro ++ ++%macro PMINSD_MMX 3 ; dst, src, tmp ++ mova %3, %2 ++ pcmpgtd %3, %1 ++ pxor %1, %2 ++ pand %1, %3 ++ pxor %1, %2 ++%endmacro ++ ++%macro PMAXSD_MMX 3 ; dst, src, tmp ++ mova %3, %1 ++ pcmpgtd %3, %2 ++ pand %1, %3 ++ pandn %3, %2 ++ por %1, %3 ++%endmacro ++ ++%macro CLIPD_MMX 3-4 ; src/dst, min, max, tmp ++ PMINSD_MMX %1, %3, %4 ++ PMAXSD_MMX %1, %2, %4 ++%endmacro ++ ++%macro CLIPD_SSE2 3-4 ; src/dst, min (float), max (float), unused ++ cvtdq2ps %1, %1 ++ minps %1, %3 ++ maxps %1, %2 ++ cvtps2dq %1, %1 ++%endmacro ++ ++%macro CLIPD_SSE41 3-4 ; src/dst, min, max, unused ++ pminsd %1, %3 ++ pmaxsd %1, %2 ++%endmacro +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/Makefile 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/Makefile 2012-05-14 14:08:55.351360451 +0200 +@@ -6,5 +6,3 @@ + HEADERS = postprocess.h + + OBJS = postprocess.o +- +-include $(SUBDIR)../subdir.mak +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_altivec_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_altivec_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_altivec_template.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_altivec_template.c 2012-05-14 14:08:55.356360551 +0200 +@@ -530,6 +530,39 @@ + } + + static inline void dering_altivec(uint8_t src[], int stride, PPContext *c) { ++ const vector signed int vsint32_8 = vec_splat_s32(8); ++ const vector unsigned int vuint32_4 = vec_splat_u32(4); ++ const vector signed char neg1 = vec_splat_s8(-1); ++ ++ const vector unsigned char permA1 = (vector unsigned char) ++ {0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F, ++ 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; ++ const vector unsigned char permA2 = (vector unsigned char) ++ {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, ++ 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; ++ const vector unsigned char permA1inc = (vector unsigned char) ++ {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ++ const vector unsigned char permA2inc = (vector unsigned char) ++ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, ++ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ++ const vector unsigned char magic = (vector unsigned char) ++ {0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, ++ 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ++ const vector unsigned char extractPerm = (vector unsigned char) ++ {0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01, ++ 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01}; ++ const vector unsigned char extractPermInc = (vector unsigned char) ++ {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, ++ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01}; ++ const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0); ++ const vector unsigned char tenRight = (vector unsigned char) ++ {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; ++ const vector unsigned char eightLeft = (vector unsigned char) ++ {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}; ++ + /* + this code makes no assumption on src or stride. + One could remove the recomputation of the perm +@@ -539,11 +572,9 @@ + src & stride :-( + */ + uint8_t *srcCopy = src; +- DECLARE_ALIGNED(16, uint8_t, dt)[16]; ++ DECLARE_ALIGNED(16, uint8_t, dt)[16] = { deringThreshold }; + const vector signed int zero = vec_splat_s32(0); +- vector unsigned char v_dt; +- dt[0] = deringThreshold; +- v_dt = vec_splat(vec_ld(0, dt), 0); ++ vector unsigned char v_dt = vec_splat(vec_ld(0, dt), 0); + + #define LOAD_LINE(i) \ + const vector unsigned char perm##i = \ +@@ -565,6 +596,11 @@ + #undef LOAD_LINE + + vector unsigned char v_avg; ++ DECLARE_ALIGNED(16, signed int, S)[8]; ++ DECLARE_ALIGNED(16, int, tQP2)[4] = { c->QP/2 + 1 }; ++ vector signed int vQP2 = vec_ld(0, tQP2); ++ vQP2 = vec_splat(vQP2, 0); ++ + { + const vector unsigned char trunc_perm = (vector unsigned char) + {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, +@@ -575,21 +611,22 @@ + const vector unsigned char trunc_src78 = vec_perm(src7, src8, trunc_perm); + + #define EXTRACT(op) do { \ +- const vector unsigned char s##op##_1 = vec_##op(trunc_src12, trunc_src34); \ +- const vector unsigned char s##op##_2 = vec_##op(trunc_src56, trunc_src78); \ +- const vector unsigned char s##op##_6 = vec_##op(s##op##_1, s##op##_2); \ +- const vector unsigned char s##op##_8h = vec_mergeh(s##op##_6, s##op##_6); \ +- const vector unsigned char s##op##_8l = vec_mergel(s##op##_6, s##op##_6); \ +- const vector unsigned char s##op##_9 = vec_##op(s##op##_8h, s##op##_8l); \ +- const vector unsigned char s##op##_9h = vec_mergeh(s##op##_9, s##op##_9); \ +- const vector unsigned char s##op##_9l = vec_mergel(s##op##_9, s##op##_9); \ +- const vector unsigned char s##op##_10 = vec_##op(s##op##_9h, s##op##_9l); \ +- const vector unsigned char s##op##_10h = vec_mergeh(s##op##_10, s##op##_10); \ +- const vector unsigned char s##op##_10l = vec_mergel(s##op##_10, s##op##_10); \ +- const vector unsigned char s##op##_11 = vec_##op(s##op##_10h, s##op##_10l); \ +- const vector unsigned char s##op##_11h = vec_mergeh(s##op##_11, s##op##_11); \ +- const vector unsigned char s##op##_11l = vec_mergel(s##op##_11, s##op##_11); \ +- v_##op = vec_##op(s##op##_11h, s##op##_11l); } while (0) ++ const vector unsigned char s_1 = vec_##op(trunc_src12, trunc_src34); \ ++ const vector unsigned char s_2 = vec_##op(trunc_src56, trunc_src78); \ ++ const vector unsigned char s_6 = vec_##op(s_1, s_2); \ ++ const vector unsigned char s_8h = vec_mergeh(s_6, s_6); \ ++ const vector unsigned char s_8l = vec_mergel(s_6, s_6); \ ++ const vector unsigned char s_9 = vec_##op(s_8h, s_8l); \ ++ const vector unsigned char s_9h = vec_mergeh(s_9, s_9); \ ++ const vector unsigned char s_9l = vec_mergel(s_9, s_9); \ ++ const vector unsigned char s_10 = vec_##op(s_9h, s_9l); \ ++ const vector unsigned char s_10h = vec_mergeh(s_10, s_10); \ ++ const vector unsigned char s_10l = vec_mergel(s_10, s_10); \ ++ const vector unsigned char s_11 = vec_##op(s_10h, s_10l); \ ++ const vector unsigned char s_11h = vec_mergeh(s_11, s_11); \ ++ const vector unsigned char s_11l = vec_mergel(s_11, s_11); \ ++ v_##op = vec_##op(s_11h, s_11l); \ ++} while (0) + + vector unsigned char v_min; + vector unsigned char v_max; +@@ -603,7 +640,6 @@ + v_avg = vec_avg(v_min, v_max); + } + +- DECLARE_ALIGNED(16, signed int, S)[8]; + { + const vector unsigned short mask1 = (vector unsigned short) + {0x0001, 0x0002, 0x0004, 0x0008, +@@ -615,22 +651,27 @@ + const vector unsigned int vuint32_16 = vec_sl(vec_splat_u32(1), vec_splat_u32(4)); + const vector unsigned int vuint32_1 = vec_splat_u32(1); + ++ vector signed int sumA2; ++ vector signed int sumB2; ++ vector signed int sum0, sum1, sum2, sum3, sum4; ++ vector signed int sum5, sum6, sum7, sum8, sum9; ++ + #define COMPARE(i) \ +- vector signed int sum##i; \ + do { \ +- const vector unsigned char cmp##i = \ ++ const vector unsigned char cmp = \ + (vector unsigned char)vec_cmpgt(src##i, v_avg); \ +- const vector unsigned short cmpHi##i = \ +- (vector unsigned short)vec_mergeh(cmp##i, cmp##i); \ +- const vector unsigned short cmpLi##i = \ +- (vector unsigned short)vec_mergel(cmp##i, cmp##i); \ +- const vector signed short cmpHf##i = \ +- (vector signed short)vec_and(cmpHi##i, mask1); \ +- const vector signed short cmpLf##i = \ +- (vector signed short)vec_and(cmpLi##i, mask2); \ +- const vector signed int sump##i = vec_sum4s(cmpHf##i, zero); \ +- const vector signed int sumq##i = vec_sum4s(cmpLf##i, sump##i); \ +- sum##i = vec_sums(sumq##i, zero); } while (0) ++ const vector unsigned short cmpHi = \ ++ (vector unsigned short)vec_mergeh(cmp, cmp); \ ++ const vector unsigned short cmpLi = \ ++ (vector unsigned short)vec_mergel(cmp, cmp); \ ++ const vector signed short cmpHf = \ ++ (vector signed short)vec_and(cmpHi, mask1); \ ++ const vector signed short cmpLf = \ ++ (vector signed short)vec_and(cmpLi, mask2); \ ++ const vector signed int sump = vec_sum4s(cmpHf, zero); \ ++ const vector signed int sumq = vec_sum4s(cmpLf, sump); \ ++ sum##i = vec_sums(sumq, zero); \ ++ } while (0) + + COMPARE(0); + COMPARE(1); +@@ -644,8 +685,6 @@ + COMPARE(9); + #undef COMPARE + +- vector signed int sumA2; +- vector signed int sumB2; + { + const vector signed int sump02 = vec_mergel(sum0, sum2); + const vector signed int sump13 = vec_mergel(sum1, sum3); +@@ -699,86 +738,43 @@ + /* I'm not sure the following is actually faster + than straight, unvectorized C code :-( */ + +- DECLARE_ALIGNED(16, int, tQP2)[4]; +- tQP2[0]= c->QP/2 + 1; +- vector signed int vQP2 = vec_ld(0, tQP2); +- vQP2 = vec_splat(vQP2, 0); +- const vector signed int vsint32_8 = vec_splat_s32(8); +- const vector unsigned int vuint32_4 = vec_splat_u32(4); +- +- const vector unsigned char permA1 = (vector unsigned char) +- {0x00, 0x01, 0x02, 0x10, 0x11, 0x12, 0x1F, 0x1F, +- 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; +- const vector unsigned char permA2 = (vector unsigned char) +- {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x10, 0x11, +- 0x12, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F}; +- const vector unsigned char permA1inc = (vector unsigned char) +- {0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00, +- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +- const vector unsigned char permA2inc = (vector unsigned char) +- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, +- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +- const vector unsigned char magic = (vector unsigned char) +- {0x01, 0x02, 0x01, 0x02, 0x04, 0x02, 0x01, 0x02, +- 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +- const vector unsigned char extractPerm = (vector unsigned char) +- {0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01, +- 0x10, 0x10, 0x10, 0x01, 0x10, 0x10, 0x10, 0x01}; +- const vector unsigned char extractPermInc = (vector unsigned char) +- {0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, +- 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01}; +- const vector unsigned char identity = vec_lvsl(0,(unsigned char *)0); +- const vector unsigned char tenRight = (vector unsigned char) +- {0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +- const vector unsigned char eightLeft = (vector unsigned char) +- {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08}; +- +- +-#define F_INIT(i) \ +- vector unsigned char tenRightM##i = tenRight; \ +- vector unsigned char permA1M##i = permA1; \ +- vector unsigned char permA2M##i = permA2; \ +- vector unsigned char extractPermM##i = extractPerm ++#define F_INIT() \ ++ vector unsigned char tenRightM = tenRight; \ ++ vector unsigned char permA1M = permA1; \ ++ vector unsigned char permA2M = permA2; \ ++ vector unsigned char extractPermM = extractPerm + + #define F2(i, j, k, l) \ + if (S[i] & (1 << (l+1))) { \ +- const vector unsigned char a_##j##_A##l = \ +- vec_perm(src##i, src##j, permA1M##i); \ +- const vector unsigned char a_##j##_B##l = \ +- vec_perm(a_##j##_A##l, src##k, permA2M##i); \ +- const vector signed int a_##j##_sump##l = \ +- (vector signed int)vec_msum(a_##j##_B##l, magic, \ +- (vector unsigned int)zero); \ +- vector signed int F_##j##_##l = \ +- vec_sr(vec_sums(a_##j##_sump##l, vsint32_8), vuint32_4); \ +- F_##j##_##l = vec_splat(F_##j##_##l, 3); \ +- const vector signed int p_##j##_##l = \ +- (vector signed int)vec_perm(src##j, \ +- (vector unsigned char)zero, \ +- extractPermM##i); \ +- const vector signed int sum_##j##_##l = vec_add( p_##j##_##l, vQP2);\ +- const vector signed int diff_##j##_##l = vec_sub( p_##j##_##l, vQP2);\ +- vector signed int newpm_##j##_##l; \ +- if (vec_all_lt(sum_##j##_##l, F_##j##_##l)) \ +- newpm_##j##_##l = sum_##j##_##l; \ +- else if (vec_all_gt(diff_##j##_##l, F_##j##_##l)) \ +- newpm_##j##_##l = diff_##j##_##l; \ +- else newpm_##j##_##l = F_##j##_##l; \ +- const vector unsigned char newpm2_##j##_##l = \ +- vec_splat((vector unsigned char)newpm_##j##_##l, 15); \ +- const vector unsigned char mask##j##l = vec_add(identity, \ +- tenRightM##i); \ +- src##j = vec_perm(src##j, newpm2_##j##_##l, mask##j##l); \ ++ const vector unsigned char a_A = vec_perm(src##i, src##j, permA1M); \ ++ const vector unsigned char a_B = vec_perm(a_A, src##k, permA2M); \ ++ const vector signed int a_sump = \ ++ (vector signed int)vec_msum(a_B, magic, (vector unsigned int)zero);\ ++ vector signed int F = vec_sr(vec_sums(a_sump, vsint32_8), vuint32_4); \ ++ const vector signed int p = \ ++ (vector signed int)vec_perm(src##j, (vector unsigned char)zero, \ ++ extractPermM); \ ++ const vector signed int sum = vec_add(p, vQP2); \ ++ const vector signed int diff = vec_sub(p, vQP2); \ ++ vector signed int newpm; \ ++ vector unsigned char newpm2, mask; \ ++ F = vec_splat(F, 3); \ ++ if (vec_all_lt(sum, F)) \ ++ newpm = sum; \ ++ else if (vec_all_gt(diff, F)) \ ++ newpm = diff; \ ++ else newpm = F; \ ++ newpm2 = vec_splat((vector unsigned char)newpm, 15); \ ++ mask = vec_add(identity, tenRightM); \ ++ src##j = vec_perm(src##j, newpm2, mask); \ + } \ +- permA1M##i = vec_add(permA1M##i, permA1inc); \ +- permA2M##i = vec_add(permA2M##i, permA2inc); \ +- tenRightM##i = vec_sro(tenRightM##i, eightLeft); \ +- extractPermM##i = vec_add(extractPermM##i, extractPermInc) ++ permA1M = vec_add(permA1M, permA1inc); \ ++ permA2M = vec_add(permA2M, permA2inc); \ ++ tenRightM = vec_sro(tenRightM, eightLeft); \ ++ extractPermM = vec_add(extractPermM, extractPermInc) + +-#define ITER(i, j, k) \ +- F_INIT(i); \ ++#define ITER(i, j, k) do { \ ++ F_INIT(); \ + F2(i, j, k, 0); \ + F2(i, j, k, 1); \ + F2(i, j, k, 2); \ +@@ -786,7 +782,8 @@ + F2(i, j, k, 4); \ + F2(i, j, k, 5); \ + F2(i, j, k, 6); \ +- F2(i, j, k, 7) ++ F2(i, j, k, 7); \ ++} while (0) + + ITER(0, 1, 2); + ITER(1, 2, 3); +@@ -797,19 +794,18 @@ + ITER(6, 7, 8); + ITER(7, 8, 9); + +- const vector signed char neg1 = vec_splat_s8(-1); +- +-#define STORE_LINE(i) \ +- const vector unsigned char permST##i = \ ++#define STORE_LINE(i) do { \ ++ const vector unsigned char permST = \ + vec_lvsr(i * stride, srcCopy); \ +- const vector unsigned char maskST##i = \ ++ const vector unsigned char maskST = \ + vec_perm((vector unsigned char)zero, \ +- (vector unsigned char)neg1, permST##i);\ +- src##i = vec_perm(src##i ,src##i, permST##i); \ +- sA##i= vec_sel(sA##i, src##i, maskST##i); \ +- sB##i= vec_sel(src##i, sB##i, maskST##i); \ ++ (vector unsigned char)neg1, permST); \ ++ src##i = vec_perm(src##i ,src##i, permST); \ ++ sA##i= vec_sel(sA##i, src##i, maskST); \ ++ sB##i= vec_sel(src##i, sB##i, maskST); \ + vec_st(sA##i, i * stride, srcCopy); \ +- vec_st(sB##i, i * stride + 16, srcCopy) ++ vec_st(sB##i, i * stride + 16, srcCopy); \ ++} while (0) + + STORE_LINE(1); + STORE_LINE(2); +@@ -832,16 +828,16 @@ + static inline void RENAME(tempNoiseReducer)(uint8_t *src, int stride, + uint8_t *tempBlurred, uint32_t *tempBlurredPast, int *maxNoise) + { ++ const vector signed char neg1 = vec_splat_s8(-1); ++ const vector unsigned char permHH = (const vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, ++ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}; ++ + const vector signed int zero = vec_splat_s32(0); + const vector signed short vsint16_1 = vec_splat_s16(1); + vector signed int v_dp = zero; + vector signed int v_sysdp = zero; + int d, sysd, i; + +- tempBlurredPast[127]= maxNoise[0]; +- tempBlurredPast[128]= maxNoise[1]; +- tempBlurredPast[129]= maxNoise[2]; +- + #define LOAD_LINE(src, i) \ + register int j##src##i = i * stride; \ + vector unsigned char perm##src##i = vec_lvsl(j##src##i, src); \ +@@ -872,11 +868,12 @@ + LOAD_LINE(tempBlurred, 7); + #undef LOAD_LINE + +-#define ACCUMULATE_DIFFS(i) \ +- vector signed short v_d##i = vec_sub(v_tempBlurredAss##i, \ +- v_srcAss##i); \ +- v_dp = vec_msums(v_d##i, v_d##i, v_dp); \ +- v_sysdp = vec_msums(v_d##i, vsint16_1, v_sysdp) ++#define ACCUMULATE_DIFFS(i) do { \ ++ vector signed short v_d = vec_sub(v_tempBlurredAss##i, \ ++ v_srcAss##i); \ ++ v_dp = vec_msums(v_d, v_d, v_dp); \ ++ v_sysdp = vec_msums(v_d, vsint16_1, v_sysdp); \ ++ } while (0) + + ACCUMULATE_DIFFS(0); + ACCUMULATE_DIFFS(1); +@@ -888,6 +885,10 @@ + ACCUMULATE_DIFFS(7); + #undef ACCUMULATE_DIFFS + ++ tempBlurredPast[127]= maxNoise[0]; ++ tempBlurredPast[128]= maxNoise[1]; ++ tempBlurredPast[129]= maxNoise[2]; ++ + v_dp = vec_sums(v_dp, zero); + v_sysdp = vec_sums(v_sysdp, zero); + +@@ -938,13 +939,12 @@ + const vector signed short vsint16_4 = vec_splat_s16(4); + const vector unsigned short vuint16_3 = vec_splat_u16(3); + +-#define OP(i) \ +- const vector signed short v_temp##i = \ +- vec_mladd(v_tempBlurredAss##i, \ +- vsint16_7, v_srcAss##i); \ +- const vector signed short v_temp2##i = \ +- vec_add(v_temp##i, vsint16_4); \ +- v_tempBlurredAss##i = vec_sr(v_temp2##i, vuint16_3) ++#define OP(i) do { \ ++ const vector signed short v_temp = \ ++ vec_mladd(v_tempBlurredAss##i, vsint16_7, v_srcAss##i); \ ++ const vector signed short v_temp2 = vec_add(v_temp, vsint16_4); \ ++ v_tempBlurredAss##i = vec_sr(v_temp2, vuint16_3); \ ++ } while (0) + + OP(0); + OP(1); +@@ -959,13 +959,13 @@ + const vector signed short vsint16_3 = vec_splat_s16(3); + const vector signed short vsint16_2 = vec_splat_s16(2); + +-#define OP(i) \ +- const vector signed short v_temp##i = \ +- vec_mladd(v_tempBlurredAss##i, \ +- vsint16_3, v_srcAss##i); \ +- const vector signed short v_temp2##i = \ +- vec_add(v_temp##i, vsint16_2); \ +- v_tempBlurredAss##i = vec_sr(v_temp2##i, (vector unsigned short)vsint16_2) ++#define OP(i) do { \ ++ const vector signed short v_temp = \ ++ vec_mladd(v_tempBlurredAss##i, vsint16_3, v_srcAss##i); \ ++ const vector signed short v_temp2 = vec_add(v_temp, vsint16_2); \ ++ v_tempBlurredAss##i = \ ++ vec_sr(v_temp2, (vector unsigned short)vsint16_2); \ ++ } while (0) + + OP(0); + OP(1); +@@ -979,27 +979,19 @@ + } + } + +- const vector signed char neg1 = vec_splat_s8(-1); +- const vector unsigned char permHH = (const vector unsigned char){0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, +- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F}; +- +-#define PACK_AND_STORE(src, i) \ +- const vector unsigned char perms##src##i = \ +- vec_lvsr(i * stride, src); \ +- const vector unsigned char vf##src##i = \ +- vec_packsu(v_tempBlurredAss##i, (vector signed short)zero); \ +- const vector unsigned char vg##src##i = \ +- vec_perm(vf##src##i, v_##src##A##i, permHH); \ +- const vector unsigned char mask##src##i = \ +- vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms##src##i); \ +- const vector unsigned char vg2##src##i = \ +- vec_perm(vg##src##i, vg##src##i, perms##src##i); \ +- const vector unsigned char svA##src##i = \ +- vec_sel(v_##src##A1##i, vg2##src##i, mask##src##i); \ +- const vector unsigned char svB##src##i = \ +- vec_sel(vg2##src##i, v_##src##A2##i, mask##src##i); \ +- vec_st(svA##src##i, i * stride, src); \ +- vec_st(svB##src##i, i * stride + 16, src) ++#define PACK_AND_STORE(src, i) do { \ ++ const vector unsigned char perms = vec_lvsr(i * stride, src); \ ++ const vector unsigned char vf = \ ++ vec_packsu(v_tempBlurredAss##1, (vector signed short)zero); \ ++ const vector unsigned char vg = vec_perm(vf, v_##src##A##i, permHH); \ ++ const vector unsigned char mask = \ ++ vec_perm((vector unsigned char)zero, (vector unsigned char)neg1, perms); \ ++ const vector unsigned char vg2 = vec_perm(vg, vg, perms); \ ++ const vector unsigned char svA = vec_sel(v_##src##A1##i, vg2, mask); \ ++ const vector unsigned char svB = vec_sel(vg2, v_##src##A2##i, mask); \ ++ vec_st(svA, i * stride, src); \ ++ vec_st(svB, i * stride + 16, src); \ ++} while (0) + + PACK_AND_STORE(src, 0); + PACK_AND_STORE(src, 1); +@@ -1127,6 +1119,7 @@ + + static inline void transpose_8x16_char_fromPackedAlign_altivec(unsigned char* dst, unsigned char* src, int stride) { + const vector unsigned char zero = vec_splat_u8(0); ++ const vector signed char neg1 = vec_splat_s8(-1); + + #define LOAD_DOUBLE_LINE(i, j) \ + vector unsigned char src##i = vec_ld(i * 16, src); \ +@@ -1187,26 +1180,28 @@ + temp7 = vec_mergel(tempD, tempL); + + +- const vector signed char neg1 = vec_splat_s8(-1); +-#define STORE_DOUBLE_LINE(i, j) \ +- vector unsigned char dstA##i = vec_ld(i * stride, dst); \ +- vector unsigned char dstB##i = vec_ld(i * stride + 16, dst); \ +- vector unsigned char dstA##j = vec_ld(j * stride, dst); \ +- vector unsigned char dstB##j = vec_ld(j * stride+ 16, dst); \ +- vector unsigned char align##i = vec_lvsr(i * stride, dst); \ +- vector unsigned char align##j = vec_lvsr(j * stride, dst); \ +- vector unsigned char mask##i = vec_perm(zero, (vector unsigned char)neg1, align##i); \ +- vector unsigned char mask##j = vec_perm(zero, (vector unsigned char)neg1, align##j); \ +- vector unsigned char dstR##i = vec_perm(temp##i, temp##i, align##i);\ +- vector unsigned char dstR##j = vec_perm(temp##j, temp##j, align##j);\ +- vector unsigned char dstAF##i = vec_sel(dstA##i, dstR##i, mask##i); \ +- vector unsigned char dstBF##i = vec_sel(dstR##i, dstB##i, mask##i); \ +- vector unsigned char dstAF##j = vec_sel(dstA##j, dstR##j, mask##j); \ +- vector unsigned char dstBF##j = vec_sel(dstR##j, dstB##j, mask##j); \ +- vec_st(dstAF##i, i * stride, dst); \ +- vec_st(dstBF##i, i * stride + 16, dst); \ +- vec_st(dstAF##j, j * stride, dst); \ +- vec_st(dstBF##j, j * stride + 16, dst) ++#define STORE_DOUBLE_LINE(i, j) do { \ ++ vector unsigned char dstAi = vec_ld(i * stride, dst); \ ++ vector unsigned char dstBi = vec_ld(i * stride + 16, dst); \ ++ vector unsigned char dstAj = vec_ld(j * stride, dst); \ ++ vector unsigned char dstBj = vec_ld(j * stride+ 16, dst); \ ++ vector unsigned char aligni = vec_lvsr(i * stride, dst); \ ++ vector unsigned char alignj = vec_lvsr(j * stride, dst); \ ++ vector unsigned char maski = \ ++ vec_perm(zero, (vector unsigned char)neg1, aligni); \ ++ vector unsigned char maskj = \ ++ vec_perm(zero, (vector unsigned char)neg1, alignj); \ ++ vector unsigned char dstRi = vec_perm(temp##i, temp##i, aligni); \ ++ vector unsigned char dstRj = vec_perm(temp##j, temp##j, alignj); \ ++ vector unsigned char dstAFi = vec_sel(dstAi, dstRi, maski); \ ++ vector unsigned char dstBFi = vec_sel(dstRi, dstBi, maski); \ ++ vector unsigned char dstAFj = vec_sel(dstAj, dstRj, maskj); \ ++ vector unsigned char dstBFj = vec_sel(dstRj, dstBj, maskj); \ ++ vec_st(dstAFi, i * stride, dst); \ ++ vec_st(dstBFi, i * stride + 16, dst); \ ++ vec_st(dstAFj, j * stride, dst); \ ++ vec_st(dstBFj, j * stride + 16, dst); \ ++} while (0) + + STORE_DOUBLE_LINE(0,1); + STORE_DOUBLE_LINE(2,3); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess.c 2012-05-14 14:08:55.353360491 +0200 +@@ -71,10 +71,11 @@ + ... + */ + +-//Changelog: use the Subversion log ++//Changelog: use git log + + #include "config.h" + #include "libavutil/avutil.h" ++#include "libavutil/avassert.h" + #include + #include + #include +@@ -86,9 +87,11 @@ + //#define DEBUG_BRIGHTNESS + #include "postprocess.h" + #include "postprocess_internal.h" ++#include "libavutil/avstring.h" + + unsigned postproc_version(void) + { ++ av_assert0(LIBPOSTPROC_VERSION_MICRO >= 100); + return LIBPOSTPROC_VERSION_INT; + } + +@@ -245,7 +248,6 @@ + static inline int isHorizMinMaxOk_C(uint8_t src[], int stride, int QP) + { + int i; +-#if 1 + for(i=0; i<2; i++){ + if((unsigned)(src[0] - src[5] + 2*QP) > 4*QP) return 0; + src += stride; +@@ -256,19 +258,11 @@ + if((unsigned)(src[6] - src[3] + 2*QP) > 4*QP) return 0; + src += stride; + } +-#else +- for(i=0; i<8; i++){ +- if((unsigned)(src[0] - src[7] + 2*QP) > 4*QP) return 0; +- src += stride; +- } +-#endif + return 1; + } + + static inline int isVertMinMaxOk_C(uint8_t src[], int stride, int QP) + { +-#if 1 +-#if 1 + int x; + src+= stride*4; + for(x=0; x 4*QP) return 0; + if((unsigned)(src[3+x + 6*stride] - src[3+x + 3*stride] + 2*QP) > 4*QP) return 0; + } +-#else +- int x; +- src+= stride*3; +- for(x=0; x 4*QP) return 0; +- } +-#endif + return 1; +-#else +- int x; +- src+= stride*4; +- for(x=0; xmax) max=v; +- if(v 2*QP) return 0; +- } +- return 1; +-#endif + } + + static inline int horizClassify_C(uint8_t src[], int stride, PPContext *c) +@@ -675,7 +646,7 @@ + #endif + postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); + #endif +-#else //CONFIG_RUNTIME_CPUDETECT ++#else /* CONFIG_RUNTIME_CPUDETECT */ + #if HAVE_MMX2 + postProcess_MMX2(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); + #elif HAVE_AMD3DNOW +@@ -687,7 +658,7 @@ + #else + postProcess_C(src, srcStride, dst, dstStride, width, height, QPs, QPStride, isColor, c); + #endif +-#endif //!CONFIG_RUNTIME_CPUDETECT ++#endif /* !CONFIG_RUNTIME_CPUDETECT */ + } + + //static void postProcess(uint8_t src[], int srcStride, uint8_t dst[], int dstStride, int width, int height, +@@ -766,7 +737,8 @@ + ppMode->maxClippedThreshold= 0.01; + ppMode->error=0; + +- strncpy(temp, name, GET_MODE_BUFFER_SIZE); ++ memset(temp, 0, GET_MODE_BUFFER_SIZE); ++ av_strlcpy(temp, name, GET_MODE_BUFFER_SIZE - 1); + + av_log(NULL, AV_LOG_DEBUG, "pp: %s\n", name); + +@@ -817,12 +789,11 @@ + int plen; + int spaceLeft; + +- if(p==NULL) p= temp, *p=0; //last filter +- else p--, *p=','; //not last filter ++ p--, *p=','; + + plen= strlen(p); + spaceLeft= p - temp + plen; +- if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE){ ++ if(spaceLeft + newlen >= GET_MODE_BUFFER_SIZE - 1){ + ppMode->error++; + break; + } +@@ -943,7 +914,7 @@ + c->yHistogram[i]= width*height/64*15/256; + + for(i=0; i<3; i++){ +- //Note: The +17*1024 is just there so i do not have to worry about r/w over the end. ++ //Note: The +17*1024 is just there so I do not have to worry about r/w over the end. + reallocAlign((void **)&c->tempBlurred[i], 8, stride*mbHeight*16 + 17*1024); + reallocAlign((void **)&c->tempBlurredPast[i], 8, 256*((height+7)&(~7))/2 + 17*1024);//FIXME size + } +@@ -1103,4 +1074,3 @@ + } + } + } +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess.h 2012-05-14 14:08:55.353360491 +0200 +@@ -29,9 +29,11 @@ + + #include "libavutil/avutil.h" + +-#define LIBPOSTPROC_VERSION_MAJOR 51 +-#define LIBPOSTPROC_VERSION_MINOR 2 +-#define LIBPOSTPROC_VERSION_MICRO 0 ++#ifndef LIBPOSTPROC_VERSION_MAJOR ++#define LIBPOSTPROC_VERSION_MAJOR 52 ++#define LIBPOSTPROC_VERSION_MINOR 0 ++#define LIBPOSTPROC_VERSION_MICRO 100 ++#endif + + #define LIBPOSTPROC_VERSION_INT AV_VERSION_INT(LIBPOSTPROC_VERSION_MAJOR, \ + LIBPOSTPROC_VERSION_MINOR, \ +@@ -83,9 +85,10 @@ + + + /** +- * returns a pp_mode or NULL if an error occurred +- * name is the string after "-pp" on the command line +- * quality is a number from 0 to PP_QUALITY_MAX ++ * Return a pp_mode or NULL if an error occurred. ++ * ++ * @param name the string after "-pp" on the command line ++ * @param quality a number from 0 to PP_QUALITY_MAX + */ + pp_mode *pp_get_mode_by_name_and_quality(const char *name, int quality); + void pp_free_mode(pp_mode *mode); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_internal.h 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_internal.h 2012-05-14 14:08:55.357360571 +0200 +@@ -28,6 +28,7 @@ + + #include + #include "libavutil/avutil.h" ++#include "libavutil/log.h" + #include "postprocess.h" + + #define V_DEBLOCK 0x01 +@@ -99,7 +100,7 @@ + + int minAllowedY; ///< for brigtness correction + int maxAllowedY; ///< for brihtness correction +- float maxClippedThreshold; ///< amount of "black" u r willing to loose to get a brightness corrected picture ++ float maxClippedThreshold; ///< amount of "black" you are willing to lose to get a brightness-corrected picture + + int maxTmpNoise[3]; ///< for Temporal Noise Reducing filter (Maximal sum of abs differences) + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libpostproc/postprocess_template.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libpostproc/postprocess_template.c 2012-05-14 14:08:55.361360651 +0200 +@@ -25,8 +25,6 @@ + + #include "libavutil/x86_cpu.h" + +-#define ALIGN_MASK "$-8" +- + #undef REAL_PAVGB + #undef PAVGB + #undef PMINUB +@@ -767,11 +765,10 @@ + } + */ + #elif HAVE_MMX ++ DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars + src+= stride*4; + __asm__ volatile( + "pxor %%mm7, %%mm7 \n\t" +- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars +- "and "ALIGN_MASK", %%"REG_c" \n\t" // align + // 0 1 2 3 4 5 6 7 + // %0 %0+%1 %0+2%1 eax+2%1 %0+4%1 eax+4%1 edx+%1 edx+2%1 + // %0 eax eax+%1 eax+2%1 %0+4%1 edx edx+%1 edx+2%1 +@@ -813,8 +810,8 @@ + "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3 + "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 + "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 +- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3 +- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3 ++ "movq %%mm0, (%3) \n\t" // 2L0 - 5L1 + 5L2 - 2L3 ++ "movq %%mm1, 8(%3) \n\t" // 2H0 - 5H1 + 5H2 - 2H3 + + "movq (%%"REG_a", %1, 2), %%mm0 \n\t" + "movq %%mm0, %%mm1 \n\t" +@@ -823,8 +820,8 @@ + + "psubw %%mm0, %%mm2 \n\t" // L3 - L4 + "psubw %%mm1, %%mm3 \n\t" // H3 - H4 +- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4 +- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4 ++ "movq %%mm2, 16(%3) \n\t" // L3 - L4 ++ "movq %%mm3, 24(%3) \n\t" // H3 - H4 + "paddw %%mm4, %%mm4 \n\t" // 2L2 + "paddw %%mm5, %%mm5 \n\t" // 2H2 + "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4 +@@ -872,8 +869,8 @@ + "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7 + "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7 + +- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 +- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 ++ "movq (%3), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 ++ "movq 8(%3), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 + + #if HAVE_MMX2 + "movq %%mm7, %%mm6 \n\t" // 0 +@@ -951,8 +948,8 @@ + "psrlw $6, %%mm4 \n\t" + "psrlw $6, %%mm5 \n\t" + +- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4 +- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4 ++ "movq 16(%3), %%mm0 \n\t" // L3 - L4 ++ "movq 24(%3), %%mm1 \n\t" // H3 - H4 + + "pxor %%mm2, %%mm2 \n\t" + "pxor %%mm3, %%mm3 \n\t" +@@ -995,8 +992,8 @@ + "movq %%mm0, (%0, %1) \n\t" + + : "+r" (src) +- : "r" ((x86_reg)stride), "m" (c->pQPb) +- : "%"REG_a, "%"REG_c ++ : "r" ((x86_reg)stride), "m" (c->pQPb), "r"(tmp) ++ : "%"REG_a + ); + #else //HAVE_MMX2 || HAVE_AMD3DNOW + const int l1= stride; +@@ -1044,6 +1041,7 @@ + static inline void RENAME(dering)(uint8_t src[], int stride, PPContext *c) + { + #if HAVE_MMX2 || HAVE_AMD3DNOW ++ DECLARE_ALIGNED(8, uint64_t, tmp)[3]; + __asm__ volatile( + "pxor %%mm6, %%mm6 \n\t" + "pcmpeqb %%mm7, %%mm7 \n\t" +@@ -1134,16 +1132,16 @@ + #endif + "movq %%mm6, %%mm0 \n\t" // max + "psubb %%mm7, %%mm6 \n\t" // max - min +- "movd %%mm6, %%ecx \n\t" +- "cmpb "MANGLE(deringThreshold)", %%cl \n\t" ++ "push %4 \n\t" ++ "movd %%mm6, %k4 \n\t" ++ "cmpb "MANGLE(deringThreshold)", %b4 \n\t" ++ "pop %4 \n\t" + " jb 1f \n\t" +- "lea -24(%%"REG_SP"), %%"REG_c" \n\t" +- "and "ALIGN_MASK", %%"REG_c" \n\t" + PAVGB(%%mm0, %%mm7) // a=(max + min)/2 + "punpcklbw %%mm7, %%mm7 \n\t" + "punpcklbw %%mm7, %%mm7 \n\t" + "punpcklbw %%mm7, %%mm7 \n\t" +- "movq %%mm7, (%%"REG_c") \n\t" ++ "movq %%mm7, (%4) \n\t" + + "movq (%0), %%mm0 \n\t" // L10 + "movq %%mm0, %%mm1 \n\t" // L10 +@@ -1207,8 +1205,8 @@ + PAVGB(t0, lx) /* (src[-1] + src[+1])/2 */\ + PAVGB(sx, lx) /* (src[-1] + 2src[0] + src[+1])/4 */\ + PAVGB(lx, pplx) \ +- "movq " #lx ", 8(%%"REG_c") \n\t"\ +- "movq (%%"REG_c"), " #lx " \n\t"\ ++ "movq " #lx ", 8(%4) \n\t"\ ++ "movq (%4), " #lx " \n\t"\ + "psubusb " #lx ", " #t1 " \n\t"\ + "psubusb " #lx ", " #t0 " \n\t"\ + "psubusb " #lx ", " #sx " \n\t"\ +@@ -1235,7 +1233,7 @@ + "pandn " #dst ", " #ppsx " \n\t"\ + "por " #pplx ", " #ppsx " \n\t"\ + "movq " #ppsx ", " #dst " \n\t"\ +- "movq 8(%%"REG_c"), " #lx " \n\t" ++ "movq 8(%4), " #lx " \n\t" + + #define DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) \ + REAL_DERING_CORE(dst,src,ppsx,psx,sx,pplx,plx,lx,t0,t1) +@@ -1265,8 +1263,8 @@ + DERING_CORE((%0, %1, 8) ,(%%REGd, %1, 4),%%mm2,%%mm4,%%mm0,%%mm3,%%mm5,%%mm1,%%mm6,%%mm7) + + "1: \n\t" +- : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2) +- : "%"REG_a, "%"REG_d, "%"REG_c ++ : : "r" (src), "r" ((x86_reg)stride), "m" (c->pQPb), "m"(c->pQPb2), "q"(tmp) ++ : "%"REG_a, "%"REG_d + ); + #else //HAVE_MMX2 || HAVE_AMD3DNOW + int y; +@@ -1912,7 +1910,7 @@ + + #if HAVE_MMX + /** +- * transposes and shift the given 8x8 Block into dst1 and dst2 ++ * Transpose and shift the given 8x8 Block into dst1 and dst2. + */ + static inline void RENAME(transpose1)(uint8_t *dst1, uint8_t *dst2, uint8_t *src, int srcStride) + { +@@ -1997,7 +1995,7 @@ + } + + /** +- * transposes the given 8x8 block ++ * Transpose the given 8x8 block. + */ + static inline void RENAME(transpose2)(uint8_t *dst, int dstStride, uint8_t *src) + { +@@ -2472,7 +2470,7 @@ + int64_t dc_mask, eq_mask, both_masks; + int64_t sums[10*8*2]; + src+= step*3; // src points to begin of the 8x8 Block +-//START_TIMER ++ //{ START_TIMER + __asm__ volatile( + "movq %0, %%mm7 \n\t" + "movq %1, %%mm6 \n\t" +@@ -2762,10 +2760,9 @@ + + if(eq_mask != -1LL){ + uint8_t *temp_src= src; ++ DECLARE_ALIGNED(8, uint64_t, tmp)[4]; // make space for 4 8-byte vars + __asm__ volatile( + "pxor %%mm7, %%mm7 \n\t" +- "lea -40(%%"REG_SP"), %%"REG_c" \n\t" // make space for 4 8-byte vars +- "and "ALIGN_MASK", %%"REG_c" \n\t" // align + // 0 1 2 3 4 5 6 7 8 9 + // %0 eax eax+%1 eax+2%1 %0+4%1 ecx ecx+%1 ecx+2%1 %1+8%1 ecx+4%1 + +@@ -2806,8 +2803,8 @@ + "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - H3 + "psubw %%mm2, %%mm0 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 + "psubw %%mm3, %%mm1 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 +- "movq %%mm0, (%%"REG_c") \n\t" // 2L0 - 5L1 + 5L2 - 2L3 +- "movq %%mm1, 8(%%"REG_c") \n\t" // 2H0 - 5H1 + 5H2 - 2H3 ++ "movq %%mm0, (%4) \n\t" // 2L0 - 5L1 + 5L2 - 2L3 ++ "movq %%mm1, 8(%4) \n\t" // 2H0 - 5H1 + 5H2 - 2H3 + + "movq (%%"REG_a", %1, 2), %%mm0 \n\t" + "movq %%mm0, %%mm1 \n\t" +@@ -2816,8 +2813,8 @@ + + "psubw %%mm0, %%mm2 \n\t" // L3 - L4 + "psubw %%mm1, %%mm3 \n\t" // H3 - H4 +- "movq %%mm2, 16(%%"REG_c") \n\t" // L3 - L4 +- "movq %%mm3, 24(%%"REG_c") \n\t" // H3 - H4 ++ "movq %%mm2, 16(%4) \n\t" // L3 - L4 ++ "movq %%mm3, 24(%4) \n\t" // H3 - H4 + "paddw %%mm4, %%mm4 \n\t" // 2L2 + "paddw %%mm5, %%mm5 \n\t" // 2H2 + "psubw %%mm2, %%mm4 \n\t" // 2L2 - L3 + L4 +@@ -2865,8 +2862,8 @@ + "psubw %%mm2, %%mm0 \n\t" // 2L4 - 5L5 + 5L6 - 2L7 + "psubw %%mm3, %%mm1 \n\t" // 2H4 - 5H5 + 5H6 - 2H7 + +- "movq (%%"REG_c"), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 +- "movq 8(%%"REG_c"), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 ++ "movq (%4), %%mm2 \n\t" // 2L0 - 5L1 + 5L2 - 2L3 ++ "movq 8(%4), %%mm3 \n\t" // 2H0 - 5H1 + 5H2 - 2H3 + + #if HAVE_MMX2 + "movq %%mm7, %%mm6 \n\t" // 0 +@@ -2944,8 +2941,8 @@ + "psrlw $6, %%mm4 \n\t" + "psrlw $6, %%mm5 \n\t" + +- "movq 16(%%"REG_c"), %%mm0 \n\t" // L3 - L4 +- "movq 24(%%"REG_c"), %%mm1 \n\t" // H3 - H4 ++ "movq 16(%4), %%mm0 \n\t" // L3 - L4 ++ "movq 24(%4), %%mm1 \n\t" // H3 - H4 + + "pxor %%mm2, %%mm2 \n\t" + "pxor %%mm3, %%mm3 \n\t" +@@ -2990,15 +2987,16 @@ + "movq %%mm0, (%0, %1) \n\t" + + : "+r" (temp_src) +- : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask) +- : "%"REG_a, "%"REG_c ++ : "r" ((x86_reg)step), "m" (c->pQPb), "m"(eq_mask), "r"(tmp) ++ : "%"REG_a + ); + } + /*if(step==16){ + STOP_TIMER("step16") + }else{ + STOP_TIMER("stepX") +-}*/ ++} ++ } */ + } + #endif //HAVE_MMX + +@@ -3372,14 +3370,14 @@ + linecpy(tempSrc + srcStride*copyAhead, srcBlock + srcStride*copyAhead, + FFMAX(height-y-copyAhead, 0), srcStride); + +- /* duplicate last line of src to fill the void upto line (copyAhead+7) */ ++ /* duplicate last line of src to fill the void up to line (copyAhead+7) */ + for(i=FFMAX(height-y, 8); i $(@:.o=.d) ++ $(YASM) $(YASMFLAGS) -I $( ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio conversion ++ * @author Michael Niedermayer ++ */ ++ ++#include "libavutil/avstring.h" ++#include "libavutil/avassert.h" ++#include "libavutil/libm.h" ++#include "libavutil/samplefmt.h" ++#include "audioconvert.h" ++ ++ ++typedef void (conv_func_type)(uint8_t *po, const uint8_t *pi, int is, int os, uint8_t *end); ++ ++struct AudioConvert { ++ int channels; ++ conv_func_type *conv_f; ++ const int *ch_map; ++ uint8_t silence[8]; ///< silence input sample ++}; ++ ++#define CONV_FUNC_NAME(dst_fmt, src_fmt) conv_ ## src_fmt ## _to_ ## dst_fmt ++ ++//FIXME rounding ? ++#define CONV_FUNC(ofmt, otype, ifmt, expr)\ ++static void CONV_FUNC_NAME(ofmt, ifmt)(uint8_t *po, const uint8_t *pi, int is, int os, uint8_t *end)\ ++{\ ++ do{\ ++ *(otype*)po = expr; pi += is; po += os;\ ++ }while(po < end);\ ++} ++ ++//FIXME put things below under ifdefs so we do not waste space for cases no codec will need ++CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_U8 , *(const uint8_t*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<8) ++CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)<<24) ++CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) ++CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_U8 , (*(const uint8_t*)pi - 0x80)*(1.0 / (1<<7))) ++CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S16, (*(const int16_t*)pi>>8) + 0x80) ++CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S16, *(const int16_t*)pi<<16) ++CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) ++CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S16, *(const int16_t*)pi*(1.0 / (1<<15))) ++CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_S32, (*(const int32_t*)pi>>24) + 0x80) ++CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi>>16) ++CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_S32, *(const int32_t*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) ++CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_S32, *(const int32_t*)pi*(1.0 / (1U<<31))) ++CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8( lrintf(*(const float*)pi * (1<<7)) + 0x80)) ++CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16( lrintf(*(const float*)pi * (1<<15)))) ++CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float*)pi * (1U<<31)))) ++CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_FLT, *(const float*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_FLT, *(const float*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_U8 , uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8( lrint(*(const double*)pi * (1<<7)) + 0x80)) ++CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16( lrint(*(const double*)pi * (1<<15)))) ++CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double*)pi * (1U<<31)))) ++CONV_FUNC(AV_SAMPLE_FMT_FLT, float , AV_SAMPLE_FMT_DBL, *(const double*)pi) ++CONV_FUNC(AV_SAMPLE_FMT_DBL, double , AV_SAMPLE_FMT_DBL, *(const double*)pi) ++ ++#define FMT_PAIR_FUNC(out, in) [out + AV_SAMPLE_FMT_NB*in] = CONV_FUNC_NAME(out, in) ++ ++static conv_func_type * const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB*AV_SAMPLE_FMT_NB] = { ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_U8 ), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8 ), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8 ), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8 ), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8 ), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_S16), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_S32), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_FLT), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8 , AV_SAMPLE_FMT_DBL), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), ++ FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), ++}; ++ ++AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, ++ enum AVSampleFormat in_fmt, ++ int channels, const int *ch_map, ++ int flags) ++{ ++ AudioConvert *ctx; ++ conv_func_type *f = fmt_pair_to_conv_functions[out_fmt + AV_SAMPLE_FMT_NB*in_fmt]; ++ ++ if (!f) ++ return NULL; ++ ctx = av_mallocz(sizeof(*ctx)); ++ if (!ctx) ++ return NULL; ++ ctx->channels = channels; ++ ctx->conv_f = f; ++ ctx->ch_map = ch_map; ++ if (in_fmt == AV_SAMPLE_FMT_U8) ++ memset(ctx->silence, 0x80, sizeof(ctx->silence)); ++ return ctx; ++} ++ ++void swri_audio_convert_free(AudioConvert **ctx) ++{ ++ av_freep(ctx); ++} ++ ++int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) ++{ ++ int ch; ++ ++ av_assert0(ctx->channels == out->ch_count); ++ ++ //FIXME optimize common cases ++ ++ for(ch=0; chchannels; ch++){ ++ const int ich= ctx->ch_map ? ctx->ch_map[ch] : ch; ++ const int is= ich < 0 ? 0 : (in->planar ? 1 : in->ch_count) * in->bps; ++ const int os= (out->planar ? 1 :out->ch_count) *out->bps; ++ const uint8_t *pi= ich < 0 ? ctx->silence : in->ch[ich]; ++ uint8_t *po= out->ch[ch]; ++ uint8_t *end= po + os*len; ++ if(!po) ++ continue; ++ ctx->conv_f(po, pi, is, os, end); ++ } ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/audioconvert.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/audioconvert.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/audioconvert.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/audioconvert.h 2012-05-14 14:08:55.364360711 +0200 +@@ -0,0 +1,68 @@ ++/* ++ * audio conversion ++ * Copyright (c) 2006 Michael Niedermayer ++ * Copyright (c) 2008 Peter Ross ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef SWR_AUDIOCONVERT_H ++#define SWR_AUDIOCONVERT_H ++ ++/** ++ * @file ++ * Audio format conversion routines ++ */ ++ ++ ++#include "swresample_internal.h" ++#include "libavutil/cpu.h" ++#include "libavutil/audioconvert.h" ++ ++struct AudioConvert; ++typedef struct AudioConvert AudioConvert; ++ ++/** ++ * Create an audio sample format converter context ++ * @param out_fmt Output sample format ++ * @param in_fmt Input sample format ++ * @param channels Number of channels ++ * @param flags See AV_CPU_FLAG_xx ++ * @param ch_map list of the channels id to pick from the source stream, NULL ++ * if all channels must be selected ++ * @return NULL on error ++ */ ++AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, ++ enum AVSampleFormat in_fmt, ++ int channels, const int *ch_map, ++ int flags); ++ ++/** ++ * Free audio sample format converter context. ++ * and set the pointer to NULL ++ */ ++void swri_audio_convert_free(AudioConvert **ctx); ++ ++/** ++ * Convert between audio sample formats ++ * @param[in] out array of output buffers for each channel. set to NULL to ignore processing of the given channel. ++ * @param[in] in array of input buffers for each channel ++ * @param len length of audio frame size (measured in samples) ++ */ ++int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len); ++ ++#endif /* AUDIOCONVERT_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/libswresample.v xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/libswresample.v +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/libswresample.v 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/libswresample.v 2012-05-14 14:08:55.364360711 +0200 +@@ -0,0 +1,4 @@ ++LIBSWRESAMPLE_$MAJOR { ++ global: swr_*; ff_*; swresample_*; ++ local: *; ++}; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/Makefile 2012-05-14 14:08:55.362360671 +0200 +@@ -0,0 +1,10 @@ ++include $(SUBDIR)../config.mak ++ ++NAME = swresample ++FFLIBS = avutil ++ ++HEADERS = swresample.h ++ ++OBJS = swresample.o audioconvert.o resample.o rematrix.o ++ ++TESTPROGS = swresample_test +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/rematrix.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/rematrix.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/rematrix.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/rematrix.c 2012-05-14 14:08:55.365360732 +0200 +@@ -0,0 +1,295 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * libswresample 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "swresample_internal.h" ++#include "libavutil/audioconvert.h" ++#include "libavutil/avassert.h" ++ ++#define ONE (1.0) ++#define R(x) x ++#define SAMPLE float ++#define COEFF float ++#define RENAME(x) x ## _float ++#include "rematrix_template.c" ++#undef SAMPLE ++#undef RENAME ++#undef R ++#undef ONE ++#undef COEFF ++ ++#define ONE (-32768) ++#define R(x) (((x) + 16384)>>15) ++#define SAMPLE int16_t ++#define COEFF int ++#define RENAME(x) x ## _s16 ++#include "rematrix_template.c" ++ ++ ++#define FRONT_LEFT 0 ++#define FRONT_RIGHT 1 ++#define FRONT_CENTER 2 ++#define LOW_FREQUENCY 3 ++#define BACK_LEFT 4 ++#define BACK_RIGHT 5 ++#define FRONT_LEFT_OF_CENTER 6 ++#define FRONT_RIGHT_OF_CENTER 7 ++#define BACK_CENTER 8 ++#define SIDE_LEFT 9 ++#define SIDE_RIGHT 10 ++#define TOP_CENTER 11 ++#define TOP_FRONT_LEFT 12 ++#define TOP_FRONT_CENTER 13 ++#define TOP_FRONT_RIGHT 14 ++#define TOP_BACK_LEFT 15 ++#define TOP_BACK_CENTER 16 ++#define TOP_BACK_RIGHT 17 ++ ++static int even(int64_t layout){ ++ if(!layout) return 1; ++ if(layout&(layout-1)) return 1; ++ return 0; ++} ++ ++static int sane_layout(int64_t layout){ ++ if(!(layout & AV_CH_LAYOUT_SURROUND)) // at least 1 front speaker ++ return 0; ++ if(!even(layout & (AV_CH_FRONT_LEFT | AV_CH_FRONT_RIGHT))) // no asymetric front ++ return 0; ++ if(!even(layout & (AV_CH_SIDE_LEFT | AV_CH_SIDE_RIGHT))) // no asymetric side ++ return 0; ++ if(!even(layout & (AV_CH_BACK_LEFT | AV_CH_BACK_RIGHT))) ++ return 0; ++ if(!even(layout & (AV_CH_FRONT_LEFT_OF_CENTER | AV_CH_FRONT_RIGHT_OF_CENTER))) ++ return 0; ++ if(av_get_channel_layout_nb_channels(layout) >= SWR_CH_MAX) ++ return 0; ++ ++ return 1; ++} ++ ++int swri_rematrix_init(SwrContext *s){ ++ int i, j, out_i; ++ double matrix[64][64]={{0}}; ++ int64_t unaccounted= s->in_ch_layout & ~s->out_ch_layout; ++ double maxcoef=0; ++ ++ for(i=0; i<64; i++){ ++ if(s->in_ch_layout & s->out_ch_layout & (1LL<in_ch_layout)){ ++ av_log(s, AV_LOG_ERROR, "Input channel layout isnt supported\n"); ++ return AVERROR(EINVAL); ++ } ++ if(!sane_layout(s->out_ch_layout)){ ++ av_log(s, AV_LOG_ERROR, "Output channel layout isnt supported\n"); ++ return AVERROR(EINVAL); ++ } ++ ++//FIXME implement dolby surround ++//FIXME implement full ac3 ++ ++ ++ if(unaccounted & AV_CH_FRONT_CENTER){ ++ if((s->out_ch_layout & AV_CH_LAYOUT_STEREO) == AV_CH_LAYOUT_STEREO){ ++ matrix[ FRONT_LEFT][FRONT_CENTER]+= M_SQRT1_2; ++ matrix[FRONT_RIGHT][FRONT_CENTER]+= M_SQRT1_2; ++ }else ++ av_assert0(0); ++ } ++ if(unaccounted & AV_CH_LAYOUT_STEREO){ ++ if(s->out_ch_layout & AV_CH_FRONT_CENTER){ ++ matrix[FRONT_CENTER][ FRONT_LEFT]+= M_SQRT1_2; ++ matrix[FRONT_CENTER][FRONT_RIGHT]+= M_SQRT1_2; ++ if(s->in_ch_layout & AV_CH_FRONT_CENTER) ++ matrix[FRONT_CENTER][ FRONT_CENTER] = s->clev*sqrt(2); ++ }else ++ av_assert0(0); ++ } ++ ++ if(unaccounted & AV_CH_BACK_CENTER){ ++ if(s->out_ch_layout & AV_CH_BACK_LEFT){ ++ matrix[ BACK_LEFT][BACK_CENTER]+= M_SQRT1_2; ++ matrix[BACK_RIGHT][BACK_CENTER]+= M_SQRT1_2; ++ }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){ ++ matrix[ SIDE_LEFT][BACK_CENTER]+= M_SQRT1_2; ++ matrix[SIDE_RIGHT][BACK_CENTER]+= M_SQRT1_2; ++ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ ++ matrix[ FRONT_LEFT][BACK_CENTER]+= s->slev*M_SQRT1_2; ++ matrix[FRONT_RIGHT][BACK_CENTER]+= s->slev*M_SQRT1_2; ++ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ ++ matrix[ FRONT_CENTER][BACK_CENTER]+= s->slev*M_SQRT1_2; ++ }else ++ av_assert0(0); ++ } ++ if(unaccounted & AV_CH_BACK_LEFT){ ++ if(s->out_ch_layout & AV_CH_BACK_CENTER){ ++ matrix[BACK_CENTER][ BACK_LEFT]+= M_SQRT1_2; ++ matrix[BACK_CENTER][BACK_RIGHT]+= M_SQRT1_2; ++ }else if(s->out_ch_layout & AV_CH_SIDE_LEFT){ ++ if(s->in_ch_layout & AV_CH_SIDE_LEFT){ ++ matrix[ SIDE_LEFT][ BACK_LEFT]+= M_SQRT1_2; ++ matrix[SIDE_RIGHT][BACK_RIGHT]+= M_SQRT1_2; ++ }else{ ++ matrix[ SIDE_LEFT][ BACK_LEFT]+= 1.0; ++ matrix[SIDE_RIGHT][BACK_RIGHT]+= 1.0; ++ } ++ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ ++ matrix[ FRONT_LEFT][ BACK_LEFT]+= s->slev; ++ matrix[FRONT_RIGHT][BACK_RIGHT]+= s->slev; ++ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ ++ matrix[ FRONT_CENTER][BACK_LEFT ]+= s->slev*M_SQRT1_2; ++ matrix[ FRONT_CENTER][BACK_RIGHT]+= s->slev*M_SQRT1_2; ++ }else ++ av_assert0(0); ++ } ++ ++ if(unaccounted & AV_CH_SIDE_LEFT){ ++ if(s->out_ch_layout & AV_CH_BACK_LEFT){ ++ matrix[ BACK_LEFT][ SIDE_LEFT]+= 1.0; ++ matrix[BACK_RIGHT][SIDE_RIGHT]+= 1.0; ++ }else if(s->out_ch_layout & AV_CH_BACK_CENTER){ ++ matrix[BACK_CENTER][ SIDE_LEFT]+= M_SQRT1_2; ++ matrix[BACK_CENTER][SIDE_RIGHT]+= M_SQRT1_2; ++ }else if(s->out_ch_layout & AV_CH_FRONT_LEFT){ ++ matrix[ FRONT_LEFT][ SIDE_LEFT]+= s->slev; ++ matrix[FRONT_RIGHT][SIDE_RIGHT]+= s->slev; ++ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ ++ matrix[ FRONT_CENTER][SIDE_LEFT ]+= s->slev*M_SQRT1_2; ++ matrix[ FRONT_CENTER][SIDE_RIGHT]+= s->slev*M_SQRT1_2; ++ }else ++ av_assert0(0); ++ } ++ ++ if(unaccounted & AV_CH_FRONT_LEFT_OF_CENTER){ ++ if(s->out_ch_layout & AV_CH_FRONT_LEFT){ ++ matrix[ FRONT_LEFT][ FRONT_LEFT_OF_CENTER]+= 1.0; ++ matrix[FRONT_RIGHT][FRONT_RIGHT_OF_CENTER]+= 1.0; ++ }else if(s->out_ch_layout & AV_CH_FRONT_CENTER){ ++ matrix[ FRONT_CENTER][ FRONT_LEFT_OF_CENTER]+= M_SQRT1_2; ++ matrix[ FRONT_CENTER][FRONT_RIGHT_OF_CENTER]+= M_SQRT1_2; ++ }else ++ av_assert0(0); ++ } ++ ++ //FIXME quantize for integeres ++ for(out_i=i=0; i<64; i++){ ++ double sum=0; ++ int in_i=0; ++ int ch_in=0; ++ for(j=0; j<64; j++){ ++ s->matrix[out_i][in_i]= matrix[i][j]; ++ s->matrix32[out_i][in_i]= lrintf(matrix[i][j] * 32768); ++ if(matrix[i][j]){ ++ s->matrix_ch[out_i][++ch_in]= in_i; ++ sum += fabs(matrix[i][j]); ++ } ++ if(s->in_ch_layout & (1ULL<matrix_ch[out_i][0]= ch_in; ++ maxcoef= FFMAX(maxcoef, sum); ++ if(s->out_ch_layout & (1ULL<rematrix_volume < 0) ++ maxcoef = -s->rematrix_volume; ++ ++ if(( s->out_sample_fmt < AV_SAMPLE_FMT_FLT ++ || s->int_sample_fmt < AV_SAMPLE_FMT_FLT) && maxcoef > 1.0){ ++ for(i=0; imatrix[i][j] /= maxcoef; ++ s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768); ++ } ++ } ++ ++ if(s->rematrix_volume > 0){ ++ for(i=0; imatrix[i][j] *= s->rematrix_volume; ++ s->matrix32[i][j]= lrintf(s->matrix[i][j] * 32768); ++ } ++ } ++ ++ for(i=0; iout_ch_layout); i++){ ++ for(j=0; jin_ch_layout); j++){ ++ av_log(NULL, AV_LOG_DEBUG, "%f ", s->matrix[i][j]); ++ } ++ av_log(NULL, AV_LOG_DEBUG, "\n"); ++ } ++ return 0; ++} ++ ++int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy){ ++ int out_i, in_i, i, j; ++ ++ av_assert0(out->ch_count == av_get_channel_layout_nb_channels(s->out_ch_layout)); ++ av_assert0(in ->ch_count == av_get_channel_layout_nb_channels(s-> in_ch_layout)); ++ ++ for(out_i=0; out_ich_count; out_i++){ ++ switch(s->matrix_ch[out_i][0]){ ++ case 1: ++ in_i= s->matrix_ch[out_i][1]; ++ if(mustcopy || s->matrix[out_i][in_i]!=1.0){ ++ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){ ++ copy_float((float *)out->ch[out_i], (const float *)in->ch[in_i], s->matrix [out_i][in_i], len); ++ }else ++ copy_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[in_i], s->matrix32[out_i][in_i], len); ++ }else{ ++ out->ch[out_i]= in->ch[in_i]; ++ } ++ break; ++ case 2: ++ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){ ++ sum2_float((float *)out->ch[out_i], (const float *)in->ch[ s->matrix_ch[out_i][1] ], (const float *)in->ch[ s->matrix_ch[out_i][2] ], ++ s->matrix[out_i][ s->matrix_ch[out_i][1] ], s->matrix[out_i][ s->matrix_ch[out_i][2] ], ++ len); ++ }else{ ++ sum2_s16 ((int16_t*)out->ch[out_i], (const int16_t*)in->ch[ s->matrix_ch[out_i][1] ], (const int16_t*)in->ch[ s->matrix_ch[out_i][2] ], ++ s->matrix32[out_i][ s->matrix_ch[out_i][1] ], s->matrix32[out_i][ s->matrix_ch[out_i][2] ], ++ len); ++ } ++ break; ++ default: ++ if(s->int_sample_fmt == AV_SAMPLE_FMT_FLT){ ++ for(i=0; imatrix_ch[out_i][0]; j++){ ++ in_i= s->matrix_ch[out_i][1+j]; ++ v+= ((float*)in->ch[in_i])[i] * s->matrix[out_i][in_i]; ++ } ++ ((float*)out->ch[out_i])[i]= v; ++ } ++ }else{ ++ for(i=0; imatrix_ch[out_i][0]; j++){ ++ in_i= s->matrix_ch[out_i][1+j]; ++ v+= ((int16_t*)in->ch[in_i])[i] * s->matrix32[out_i][in_i]; ++ } ++ ((int16_t*)out->ch[out_i])[i]= (v + 16384)>>15; ++ } ++ } ++ } ++ } ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/rematrix_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/rematrix_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/rematrix_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/rematrix_template.c 2012-05-14 14:08:55.366360752 +0200 +@@ -0,0 +1,38 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * libswresample 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++ ++static void RENAME(sum2)(SAMPLE *out, const SAMPLE *in1, const SAMPLE *in2, COEFF coeff1, COEFF coeff2, int len){ ++ int i; ++ ++ for(i=0; i ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * audio resampling ++ * @author Michael Niedermayer ++ */ ++ ++#include "libavutil/log.h" ++#include "swresample_internal.h" ++ ++#ifndef CONFIG_RESAMPLE_HP ++#define FILTER_SHIFT 15 ++ ++#define FELEM int16_t ++#define FELEM2 int32_t ++#define FELEML int64_t ++#define FELEM_MAX INT16_MAX ++#define FELEM_MIN INT16_MIN ++#define WINDOW_TYPE 9 ++#elif !defined(CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE) ++#define FILTER_SHIFT 30 ++ ++#define FELEM int32_t ++#define FELEM2 int64_t ++#define FELEML int64_t ++#define FELEM_MAX INT32_MAX ++#define FELEM_MIN INT32_MIN ++#define WINDOW_TYPE 12 ++#else ++#define FILTER_SHIFT 0 ++ ++#define FELEM double ++#define FELEM2 double ++#define FELEML double ++#define WINDOW_TYPE 24 ++#endif ++ ++ ++typedef struct ResampleContext { ++ const AVClass *av_class; ++ FELEM *filter_bank; ++ int filter_length; ++ int ideal_dst_incr; ++ int dst_incr; ++ int index; ++ int frac; ++ int src_incr; ++ int compensation_distance; ++ int phase_shift; ++ int phase_mask; ++ int linear; ++ double factor; ++} ResampleContext; ++ ++/** ++ * 0th order modified bessel function of the first kind. ++ */ ++static double bessel(double x){ ++ double v=1; ++ double lastv=0; ++ double t=1; ++ int i; ++ static const double inv[100]={ ++ 1.0/( 1* 1), 1.0/( 2* 2), 1.0/( 3* 3), 1.0/( 4* 4), 1.0/( 5* 5), 1.0/( 6* 6), 1.0/( 7* 7), 1.0/( 8* 8), 1.0/( 9* 9), 1.0/(10*10), ++ 1.0/(11*11), 1.0/(12*12), 1.0/(13*13), 1.0/(14*14), 1.0/(15*15), 1.0/(16*16), 1.0/(17*17), 1.0/(18*18), 1.0/(19*19), 1.0/(20*20), ++ 1.0/(21*21), 1.0/(22*22), 1.0/(23*23), 1.0/(24*24), 1.0/(25*25), 1.0/(26*26), 1.0/(27*27), 1.0/(28*28), 1.0/(29*29), 1.0/(30*30), ++ 1.0/(31*31), 1.0/(32*32), 1.0/(33*33), 1.0/(34*34), 1.0/(35*35), 1.0/(36*36), 1.0/(37*37), 1.0/(38*38), 1.0/(39*39), 1.0/(40*40), ++ 1.0/(41*41), 1.0/(42*42), 1.0/(43*43), 1.0/(44*44), 1.0/(45*45), 1.0/(46*46), 1.0/(47*47), 1.0/(48*48), 1.0/(49*49), 1.0/(50*50), ++ 1.0/(51*51), 1.0/(52*52), 1.0/(53*53), 1.0/(54*54), 1.0/(55*55), 1.0/(56*56), 1.0/(57*57), 1.0/(58*58), 1.0/(59*59), 1.0/(60*60), ++ 1.0/(61*61), 1.0/(62*62), 1.0/(63*63), 1.0/(64*64), 1.0/(65*65), 1.0/(66*66), 1.0/(67*67), 1.0/(68*68), 1.0/(69*69), 1.0/(70*70), ++ 1.0/(71*71), 1.0/(72*72), 1.0/(73*73), 1.0/(74*74), 1.0/(75*75), 1.0/(76*76), 1.0/(77*77), 1.0/(78*78), 1.0/(79*79), 1.0/(80*80), ++ 1.0/(81*81), 1.0/(82*82), 1.0/(83*83), 1.0/(84*84), 1.0/(85*85), 1.0/(86*86), 1.0/(87*87), 1.0/(88*88), 1.0/(89*89), 1.0/(90*90), ++ 1.0/(91*91), 1.0/(92*92), 1.0/(93*93), 1.0/(94*94), 1.0/(95*95), 1.0/(96*96), 1.0/(97*97), 1.0/(98*98), 1.0/(99*99), 1.0/(10000) ++ }; ++ ++ x= x*x/4; ++ for(i=0; v != lastv; i++){ ++ lastv=v; ++ t *= x*inv[i]; ++ v += t; ++ } ++ return v; ++} ++ ++/** ++ * builds a polyphase filterbank. ++ * @param factor resampling factor ++ * @param scale wanted sum of coefficients for each filter ++ * @param type 0->cubic, 1->blackman nuttall windowed sinc, 2..16->kaiser windowed sinc beta=2..16 ++ * @return 0 on success, negative on error ++ */ ++static int build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ ++ int ph, i; ++ double x, y, w; ++ double *tab = av_malloc(tap_count * sizeof(*tab)); ++ const int center= (tap_count-1)/2; ++ ++ if (!tab) ++ return AVERROR(ENOMEM); ++ ++ /* if upsampling, only need to interpolate, no filter */ ++ if (factor > 1.0) ++ factor = 1.0; ++ ++ for(ph=0;phphase_shift != phase_shift || c->linear!=linear || c->factor != factor ++ || c->filter_length != FFMAX((int)ceil(filter_size/factor), 1)) { ++ c = av_mallocz(sizeof(*c)); ++ if (!c) ++ return NULL; ++ ++ c->phase_shift = phase_shift; ++ c->phase_mask = phase_count - 1; ++ c->linear = linear; ++ c->factor = factor; ++ c->filter_length = FFMAX((int)ceil(filter_size/factor), 1); ++ c->filter_bank = av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM)); ++ if (!c->filter_bank) ++ goto error; ++ if (build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM)); ++ c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1]; ++ } ++ ++ c->compensation_distance= 0; ++ if(!av_reduce(&c->src_incr, &c->dst_incr, out_rate, in_rate * (int64_t)phase_count, INT32_MAX/2)) ++ goto error; ++ c->ideal_dst_incr= c->dst_incr; ++ ++ c->index= -phase_count*((c->filter_length-1)/2); ++ c->frac= 0; ++ ++ return c; ++error: ++ av_free(c->filter_bank); ++ av_free(c); ++ return NULL; ++} ++ ++void swri_resample_free(ResampleContext **c){ ++ if(!*c) ++ return; ++ av_freep(&(*c)->filter_bank); ++ av_freep(c); ++} ++ ++int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance){ ++ ResampleContext *c; ++ int ret; ++ ++ if (!s || compensation_distance < 0) ++ return AVERROR(EINVAL); ++ if (!compensation_distance && sample_delta) ++ return AVERROR(EINVAL); ++ if (!s->resample) { ++ s->flags |= SWR_FLAG_RESAMPLE; ++ ret = swr_init(s); ++ if (ret < 0) ++ return ret; ++ } ++ c= s->resample; ++ c->compensation_distance= compensation_distance; ++ if (compensation_distance) ++ c->dst_incr = c->ideal_dst_incr - c->ideal_dst_incr * (int64_t)sample_delta / compensation_distance; ++ else ++ c->dst_incr = c->ideal_dst_incr; ++ return 0; ++} ++ ++int swri_resample(ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx){ ++ int dst_index, i; ++ int index= c->index; ++ int frac= c->frac; ++ int dst_incr_frac= c->dst_incr % c->src_incr; ++ int dst_incr= c->dst_incr / c->src_incr; ++ int compensation_distance= c->compensation_distance; ++ ++ if(compensation_distance == 0 && c->filter_length == 1 && c->phase_shift==0){ ++ int64_t index2= ((int64_t)index)<<32; ++ int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr; ++ dst_size= FFMIN(dst_size, (src_size-1-index) * (int64_t)c->src_incr / c->dst_incr); ++ ++ for(dst_index=0; dst_index < dst_size; dst_index++){ ++ dst[dst_index] = src[index2>>32]; ++ index2 += incr; ++ } ++ index += dst_index * dst_incr; ++ index += (frac + dst_index * (int64_t)dst_incr_frac) / c->src_incr; ++ frac = (frac + dst_index * (int64_t)dst_incr_frac) % c->src_incr; ++ }else{ ++ for(dst_index=0; dst_index < dst_size; dst_index++){ ++ FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); ++ int sample_index= index >> c->phase_shift; ++ FELEM2 val=0; ++ ++ if(sample_index < 0){ ++ for(i=0; ifilter_length; i++) ++ val += src[FFABS(sample_index + i) % src_size] * filter[i]; ++ }else if(sample_index + c->filter_length > src_size){ ++ break; ++ }else if(c->linear){ ++ FELEM2 v2=0; ++ for(i=0; ifilter_length; i++){ ++ val += src[sample_index + i] * (FELEM2)filter[i]; ++ v2 += src[sample_index + i] * (FELEM2)filter[i + c->filter_length]; ++ } ++ val+=(v2-val)*(FELEML)frac / c->src_incr; ++ }else{ ++ for(i=0; ifilter_length; i++){ ++ val += src[sample_index + i] * (FELEM2)filter[i]; ++ } ++ } ++ ++#ifdef CONFIG_RESAMPLE_AUDIOPHILE_KIDDY_MODE ++ dst[dst_index] = av_clip_int16(lrintf(val)); ++#else ++ val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; ++ dst[dst_index] = (unsigned)(val + 32768) > 65535 ? (val>>31) ^ 32767 : val; ++#endif ++ ++ frac += dst_incr_frac; ++ index += dst_incr; ++ if(frac >= c->src_incr){ ++ frac -= c->src_incr; ++ index++; ++ } ++ ++ if(dst_index + 1 == compensation_distance){ ++ compensation_distance= 0; ++ dst_incr_frac= c->ideal_dst_incr % c->src_incr; ++ dst_incr= c->ideal_dst_incr / c->src_incr; ++ } ++ } ++ } ++ *consumed= FFMAX(index, 0) >> c->phase_shift; ++ if(index>=0) index &= c->phase_mask; ++ ++ if(compensation_distance){ ++ compensation_distance -= dst_index; ++ assert(compensation_distance > 0); ++ } ++ if(update_ctx){ ++ c->frac= frac; ++ c->index= index; ++ c->dst_incr= dst_incr_frac + c->src_incr*dst_incr; ++ c->compensation_distance= compensation_distance; ++ } ++#if 0 ++ if(update_ctx && !c->compensation_distance){ ++#undef rand ++ av_resample_compensate(c, rand() % (8000*2) - 8000, 8000*2); ++av_log(NULL, AV_LOG_DEBUG, "%d %d %d\n", c->dst_incr, c->ideal_dst_incr, c->compensation_distance); ++ } ++#endif ++ ++ return dst_index; ++} ++ ++int swri_multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed){ ++ int i, ret= -1; ++ ++ for(i=0; ich_count; i++){ ++ ret= swri_resample(c, (int16_t*)dst->ch[i], (const int16_t*)src->ch[i], consumed, src_size, dst_size, i+1==dst->ch_count); ++ } ++ ++ return ret; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample.c 2012-05-14 14:08:55.368360792 +0200 +@@ -0,0 +1,527 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * libswresample 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/opt.h" ++#include "swresample_internal.h" ++#include "audioconvert.h" ++#include "libavutil/avassert.h" ++#include "libavutil/audioconvert.h" ++ ++#define C30DB M_SQRT2 ++#define C15DB 1.189207115 ++#define C__0DB 1.0 ++#define C_15DB 0.840896415 ++#define C_30DB M_SQRT1_2 ++#define C_45DB 0.594603558 ++#define C_60DB 0.5 ++ ++ ++//TODO split options array out? ++#define OFFSET(x) offsetof(SwrContext,x) ++static const AVOption options[]={ ++{"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 0, SWR_CH_MAX, 0}, ++{"och", "output channel count", OFFSET(out.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 0, SWR_CH_MAX, 0}, ++{"uch", "used channel count", OFFSET(used_ch_count ), AV_OPT_TYPE_INT, {.dbl=0}, 0, SWR_CH_MAX, 0}, ++{"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, ++{"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0}, ++//{"ip" , "input planar" , OFFSET( in.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0}, ++//{"op" , "output planar" , OFFSET(out.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0}, ++{"isf", "input sample format", OFFSET( in_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0}, ++{"osf", "output sample format", OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0}, ++{"tsf", "internal sample format", OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_FLT, 0}, ++{"icl", "input channel layout" , OFFSET( in_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"}, ++{"ocl", "output channel layout", OFFSET(out_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"}, ++{"clev", "center mix level" , OFFSET(clev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0}, ++{"slev", "sourround mix level" , OFFSET(slev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0}, ++{"rmvol", "rematrix volume" , OFFSET(rematrix_volume), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, -1000, 1000, 0}, ++{"flags", NULL , OFFSET(flags) , AV_OPT_TYPE_FLAGS, {.dbl=0}, 0, UINT_MAX, 0, "flags"}, ++{"res", "force resampling", 0, AV_OPT_TYPE_CONST, {.dbl=SWR_FLAG_RESAMPLE}, INT_MIN, INT_MAX, 0, "flags"}, ++ ++{0} ++}; ++ ++static const char* context_to_name(void* ptr) { ++ return "SWR"; ++} ++ ++static const AVClass av_class = { ++ .class_name = "SwrContext", ++ .item_name = context_to_name, ++ .option = options, ++ .version = LIBAVUTIL_VERSION_INT, ++ .log_level_offset_offset = OFFSET(log_level_offset), ++ .parent_log_context_offset = OFFSET(log_ctx), ++}; ++ ++unsigned swresample_version(void) ++{ ++ av_assert0(LIBSWRESAMPLE_VERSION_MICRO >= 100); ++ return LIBSWRESAMPLE_VERSION_INT; ++} ++ ++const char *swresample_configuration(void) ++{ ++ return FFMPEG_CONFIGURATION; ++} ++ ++const char *swresample_license(void) ++{ ++#define LICENSE_PREFIX "libswresample license: " ++ return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; ++} ++ ++int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){ ++ if(!s || s->in_convert) // s needs to be allocated but not initialized ++ return AVERROR(EINVAL); ++ s->channel_map = channel_map; ++ return 0; ++} ++ ++struct SwrContext *swr_alloc(void){ ++ SwrContext *s= av_mallocz(sizeof(SwrContext)); ++ if(s){ ++ s->av_class= &av_class; ++ av_opt_set_defaults(s); ++ } ++ return s; ++} ++ ++struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, ++ int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, ++ int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, ++ int log_offset, void *log_ctx){ ++ if(!s) s= swr_alloc(); ++ if(!s) return NULL; ++ ++ s->log_level_offset= log_offset; ++ s->log_ctx= log_ctx; ++ ++ av_opt_set_int(s, "ocl", out_ch_layout, 0); ++ av_opt_set_int(s, "osf", out_sample_fmt, 0); ++ av_opt_set_int(s, "osr", out_sample_rate, 0); ++ av_opt_set_int(s, "icl", in_ch_layout, 0); ++ av_opt_set_int(s, "isf", in_sample_fmt, 0); ++ av_opt_set_int(s, "isr", in_sample_rate, 0); ++ av_opt_set_int(s, "tsf", AV_SAMPLE_FMT_S16, 0); ++ av_opt_set_int(s, "ich", av_get_channel_layout_nb_channels(s-> in_ch_layout), 0); ++ av_opt_set_int(s, "och", av_get_channel_layout_nb_channels(s->out_ch_layout), 0); ++ av_opt_set_int(s, "uch", 0, 0); ++ return s; ++} ++ ++ ++static void free_temp(AudioData *a){ ++ av_free(a->data); ++ memset(a, 0, sizeof(*a)); ++} ++ ++void swr_free(SwrContext **ss){ ++ SwrContext *s= *ss; ++ if(s){ ++ free_temp(&s->postin); ++ free_temp(&s->midbuf); ++ free_temp(&s->preout); ++ free_temp(&s->in_buffer); ++ swri_audio_convert_free(&s-> in_convert); ++ swri_audio_convert_free(&s->out_convert); ++ swri_audio_convert_free(&s->full_convert); ++ swri_resample_free(&s->resample); ++ } ++ ++ av_freep(ss); ++} ++ ++int swr_init(struct SwrContext *s){ ++ s->in_buffer_index= 0; ++ s->in_buffer_count= 0; ++ s->resample_in_constraint= 0; ++ free_temp(&s->postin); ++ free_temp(&s->midbuf); ++ free_temp(&s->preout); ++ free_temp(&s->in_buffer); ++ swri_audio_convert_free(&s-> in_convert); ++ swri_audio_convert_free(&s->out_convert); ++ swri_audio_convert_free(&s->full_convert); ++ ++ s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt); ++ s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt); ++ s-> in_sample_fmt= av_get_alt_sample_fmt(s-> in_sample_fmt, 0); ++ s->out_sample_fmt= av_get_alt_sample_fmt(s->out_sample_fmt, 0); ++ ++ if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){ ++ av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt); ++ return AVERROR(EINVAL); ++ } ++ if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){ ++ av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt); ++ return AVERROR(EINVAL); ++ } ++ ++ if( s->int_sample_fmt != AV_SAMPLE_FMT_S16 ++ &&s->int_sample_fmt != AV_SAMPLE_FMT_FLT){ ++ av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, only float & S16 is supported\n", av_get_sample_fmt_name(s->int_sample_fmt)); ++ return AVERROR(EINVAL); ++ } ++ ++ //FIXME should we allow/support using FLT on material that doesnt need it ? ++ if(s->in_sample_fmt <= AV_SAMPLE_FMT_S16 || s->int_sample_fmt==AV_SAMPLE_FMT_S16){ ++ s->int_sample_fmt= AV_SAMPLE_FMT_S16; ++ }else ++ s->int_sample_fmt= AV_SAMPLE_FMT_FLT; ++ ++ ++ if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){ ++ s->resample = swri_resample_init(s->resample, s->out_sample_rate, s->in_sample_rate, 16, 10, 0, 0.8); ++ }else ++ swri_resample_free(&s->resample); ++ if(s->int_sample_fmt != AV_SAMPLE_FMT_S16 && s->resample){ ++ av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16 currently\n"); //FIXME ++ return -1; ++ } ++ ++ if(!s->used_ch_count) ++ s->used_ch_count= s->in.ch_count; ++ ++ if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){ ++ av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n"); ++ s-> in_ch_layout= 0; ++ } ++ ++ if(!s-> in_ch_layout) ++ s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count); ++ if(!s->out_ch_layout) ++ s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count); ++ ++ s->rematrix= s->out_ch_layout !=s->in_ch_layout || s->rematrix_volume!=1.0; ++ ++#define RSC 1 //FIXME finetune ++ if(!s-> in.ch_count) ++ s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout); ++ if(!s->used_ch_count) ++ s->used_ch_count= s->in.ch_count; ++ if(!s->out.ch_count) ++ s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout); ++ ++ if(!s-> in.ch_count){ ++ av_assert0(!s->in_ch_layout); ++ av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n"); ++ return -1; ++ } ++ ++av_assert0(s->used_ch_count); ++av_assert0(s->out.ch_count); ++ s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0; ++ ++ s-> in.bps= av_get_bytes_per_sample(s-> in_sample_fmt); ++ s->int_bps= av_get_bytes_per_sample(s->int_sample_fmt); ++ s->out.bps= av_get_bytes_per_sample(s->out_sample_fmt); ++ ++ if(!s->resample && !s->rematrix && !s->channel_map){ ++ s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt, ++ s-> in_sample_fmt, s-> in.ch_count, NULL, 0); ++ return 0; ++ } ++ ++ s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt, ++ s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0); ++ s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt, ++ s->int_sample_fmt, s->out.ch_count, NULL, 0); ++ ++ ++ s->postin= s->in; ++ s->preout= s->out; ++ s->midbuf= s->in; ++ s->in_buffer= s->in; ++ if(s->channel_map){ ++ s->postin.ch_count= ++ s->midbuf.ch_count= ++ s->in_buffer.ch_count= s->used_ch_count; ++ } ++ if(!s->resample_first){ ++ s->midbuf.ch_count= s->out.ch_count; ++ s->in_buffer.ch_count = s->out.ch_count; ++ } ++ ++ s->in_buffer.bps = s->postin.bps = s->midbuf.bps = s->preout.bps = s->int_bps; ++ s->in_buffer.planar = s->postin.planar = s->midbuf.planar = s->preout.planar = 1; ++ ++ ++ if(s->rematrix) ++ return swri_rematrix_init(s); ++ ++ return 0; ++} ++ ++static int realloc_audio(AudioData *a, int count){ ++ int i, countb; ++ AudioData old; ++ ++ if(a->count >= count) ++ return 0; ++ ++ count*=2; ++ ++ countb= FFALIGN(count*a->bps, 32); ++ old= *a; ++ ++ av_assert0(a->planar); ++ av_assert0(a->bps); ++ av_assert0(a->ch_count); ++ ++ a->data= av_malloc(countb*a->ch_count); ++ if(!a->data) ++ return AVERROR(ENOMEM); ++ for(i=0; ich_count; i++){ ++ a->ch[i]= a->data + i*(a->planar ? countb : a->bps); ++ if(a->planar) memcpy(a->ch[i], old.ch[i], a->count*a->bps); ++ } ++ av_free(old.data); ++ a->count= count; ++ ++ return 1; ++} ++ ++static void copy(AudioData *out, AudioData *in, ++ int count){ ++ av_assert0(out->planar == in->planar); ++ av_assert0(out->bps == in->bps); ++ av_assert0(out->ch_count == in->ch_count); ++ if(out->planar){ ++ int ch; ++ for(ch=0; chch_count; ch++) ++ memcpy(out->ch[ch], in->ch[ch], count*out->bps); ++ }else ++ memcpy(out->ch[0], in->ch[0], count*out->ch_count*out->bps); ++} ++ ++static void fill_audiodata(AudioData *out, uint8_t *in_arg [SWR_CH_MAX]){ ++ int i; ++ if(out->planar){ ++ for(i=0; ich_count; i++) ++ out->ch[i]= in_arg[i]; ++ }else{ ++ for(i=0; ich_count; i++) ++ out->ch[i]= in_arg[0] + i*out->bps; ++ } ++} ++ ++/** ++ * ++ * out may be equal in. ++ */ ++static void buf_set(AudioData *out, AudioData *in, int count){ ++ if(in->planar){ ++ int ch; ++ for(ch=0; chch_count; ch++) ++ out->ch[ch]= in->ch[ch] + count*out->bps; ++ }else ++ out->ch[0]= in->ch[0] + count*out->ch_count*out->bps; ++} ++ ++/** ++ * ++ * @return number of samples output per channel ++ */ ++static int resample(SwrContext *s, AudioData *out_param, int out_count, ++ const AudioData * in_param, int in_count){ ++ AudioData in, out, tmp; ++ int ret_sum=0; ++ int border=0; ++ ++ tmp=out=*out_param; ++ in = *in_param; ++ ++ do{ ++ int ret, size, consumed; ++ if(!s->resample_in_constraint && s->in_buffer_count){ ++ buf_set(&tmp, &s->in_buffer, s->in_buffer_index); ++ ret= swri_multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &consumed); ++ out_count -= ret; ++ ret_sum += ret; ++ buf_set(&out, &out, ret); ++ s->in_buffer_count -= consumed; ++ s->in_buffer_index += consumed; ++ ++ if(!in_count) ++ break; ++ if(s->in_buffer_count <= border){ ++ buf_set(&in, &in, -s->in_buffer_count); ++ in_count += s->in_buffer_count; ++ s->in_buffer_count=0; ++ s->in_buffer_index=0; ++ border = 0; ++ } ++ } ++ ++ if(in_count && !s->in_buffer_count){ ++ s->in_buffer_index=0; ++ ret= swri_multiple_resample(s->resample, &out, out_count, &in, in_count, &consumed); ++ out_count -= ret; ++ ret_sum += ret; ++ buf_set(&out, &out, ret); ++ in_count -= consumed; ++ buf_set(&in, &in, consumed); ++ } ++ ++ //TODO is this check sane considering the advanced copy avoidance below ++ size= s->in_buffer_index + s->in_buffer_count + in_count; ++ if( size > s->in_buffer.count ++ && s->in_buffer_count + in_count <= s->in_buffer_index){ ++ buf_set(&tmp, &s->in_buffer, s->in_buffer_index); ++ copy(&s->in_buffer, &tmp, s->in_buffer_count); ++ s->in_buffer_index=0; ++ }else ++ if((ret=realloc_audio(&s->in_buffer, size)) < 0) ++ return ret; ++ ++ if(in_count){ ++ int count= in_count; ++ if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2; ++ ++ buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count); ++ copy(&tmp, &in, /*in_*/count); ++ s->in_buffer_count += count; ++ in_count -= count; ++ border += count; ++ buf_set(&in, &in, count); ++ s->resample_in_constraint= 0; ++ if(s->in_buffer_count != count || in_count) ++ continue; ++ } ++ break; ++ }while(1); ++ ++ s->resample_in_constraint= !!out_count; ++ ++ return ret_sum; ++} ++ ++int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count, ++ const uint8_t *in_arg [SWR_CH_MAX], int in_count){ ++ AudioData *postin, *midbuf, *preout; ++ int ret/*, in_max*/; ++ AudioData * in= &s->in; ++ AudioData *out= &s->out; ++ AudioData preout_tmp, midbuf_tmp; ++ ++ if(!s->resample){ ++ if(in_count > out_count) ++ return -1; ++ out_count = in_count; ++ } ++ ++ if(!in_arg){ ++ if(s->in_buffer_count){ ++ AudioData *a= &s->in_buffer; ++ int i, j, ret; ++ if((ret=realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0) ++ return ret; ++ av_assert0(a->planar); ++ for(i=0; ich_count; i++){ ++ for(j=0; jin_buffer_count; j++){ ++ memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j )*a->bps, ++ a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps, a->bps); ++ } ++ } ++ s->in_buffer_count += (s->in_buffer_count+1)/2; ++ s->resample_in_constraint = 0; ++ }else{ ++ return 0; ++ } ++ }else ++ fill_audiodata(in , (void*)in_arg); ++ fill_audiodata(out, out_arg); ++ ++ if(s->full_convert){ ++ av_assert0(!s->resample); ++ swri_audio_convert(s->full_convert, out, in, in_count); ++ return out_count; ++ } ++ ++// in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps; ++// in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count); ++ ++ if((ret=realloc_audio(&s->postin, in_count))<0) ++ return ret; ++ if(s->resample_first){ ++ av_assert0(s->midbuf.ch_count == s->used_ch_count); ++ if((ret=realloc_audio(&s->midbuf, out_count))<0) ++ return ret; ++ }else{ ++ av_assert0(s->midbuf.ch_count == s->out.ch_count); ++ if((ret=realloc_audio(&s->midbuf, in_count))<0) ++ return ret; ++ } ++ if((ret=realloc_audio(&s->preout, out_count))<0) ++ return ret; ++ ++ postin= &s->postin; ++ ++ midbuf_tmp= s->midbuf; ++ midbuf= &midbuf_tmp; ++ preout_tmp= s->preout; ++ preout= &preout_tmp; ++ ++ if(s->int_sample_fmt == s-> in_sample_fmt && s->in.planar) ++ postin= in; ++ ++ if(s->resample_first ? !s->resample : !s->rematrix) ++ midbuf= postin; ++ ++ if(s->resample_first ? !s->rematrix : !s->resample) ++ preout= midbuf; ++ ++ if(s->int_sample_fmt == s->out_sample_fmt && s->out.planar){ ++ if(preout==in){ ++ out_count= FFMIN(out_count, in_count); //TODO check at teh end if this is needed or redundant ++ av_assert0(s->in.planar); //we only support planar internally so it has to be, we support copying non planar though ++ copy(out, in, out_count); ++ return out_count; ++ } ++ else if(preout==postin) preout= midbuf= postin= out; ++ else if(preout==midbuf) preout= midbuf= out; ++ else preout= out; ++ } ++ ++ if(in != postin){ ++ swri_audio_convert(s->in_convert, postin, in, in_count); ++ } ++ ++ if(s->resample_first){ ++ if(postin != midbuf) ++ out_count= resample(s, midbuf, out_count, postin, in_count); ++ if(midbuf != preout) ++ swri_rematrix(s, preout, midbuf, out_count, preout==out); ++ }else{ ++ if(postin != midbuf) ++ swri_rematrix(s, midbuf, postin, in_count, midbuf==out); ++ if(midbuf != preout) ++ out_count= resample(s, preout, out_count, midbuf, in_count); ++ } ++ ++ if(preout != out){ ++//FIXME packed doesnt need more than 1 chan here! ++ swri_audio_convert(s->out_convert, out, preout, out_count); ++ } ++ if(!in_arg) ++ s->in_buffer_count = 0; ++ return out_count; ++} ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample.h 2012-05-14 14:08:55.369360812 +0200 +@@ -0,0 +1,144 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * libswresample 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/** ++ * @file ++ * libswresample public header ++ */ ++ ++#ifndef SWR_H ++#define SWR_H ++ ++#include ++#include "libavutil/samplefmt.h" ++ ++#define LIBSWRESAMPLE_VERSION_MAJOR 0 ++#define LIBSWRESAMPLE_VERSION_MINOR 6 ++#define LIBSWRESAMPLE_VERSION_MICRO 100 ++ ++#define LIBSWRESAMPLE_VERSION_INT AV_VERSION_INT(LIBSWRESAMPLE_VERSION_MAJOR, \ ++ LIBSWRESAMPLE_VERSION_MINOR, \ ++ LIBSWRESAMPLE_VERSION_MICRO) ++ ++#define SWR_CH_MAX 16 ///< Maximum number of channels ++ ++#define SWR_FLAG_RESAMPLE 1 ///< Force resampling even if equal sample rate ++//TODO use int resample ? ++//long term TODO can we enable this dynamically? ++ ++ ++struct SwrContext; ++ ++/** ++ * Allocate SwrContext. ++ * ++ * If you use this function you will need to set the parameters (manually or ++ * with swr_alloc_set_opts()) before calling swr_init(). ++ * ++ * @see swr_alloc_set_opts(), swr_init(), swr_free() ++ * @return NULL on error, allocated context otherwise ++ */ ++struct SwrContext *swr_alloc(void); ++ ++/** ++ * Initialize context after user parameters have been set. ++ * ++ * @return AVERROR error code in case of failure. ++ */ ++int swr_init(struct SwrContext *s); ++ ++/** ++ * Allocate SwrContext if needed and set/reset common parameters. ++ * ++ * This function does not require s to be allocated with swr_alloc(). On the ++ * other hand, swr_alloc() can use swr_alloc_set_opts() to set the parameters ++ * on the allocated context. ++ * ++ * @param s Swr context, can be NULL ++ * @param out_ch_layout output channel layout (AV_CH_LAYOUT_*) ++ * @param out_sample_fmt output sample format (AV_SAMPLE_FMT_*). ++ * @param out_sample_rate output sample rate (frequency in Hz) ++ * @param in_ch_layout input channel layout (AV_CH_LAYOUT_*) ++ * @param in_sample_fmt input sample format (AV_SAMPLE_FMT_*). ++ * @param in_sample_rate input sample rate (frequency in Hz) ++ * @param log_offset logging level offset ++ * @param log_ctx parent logging context, can be NULL ++ * ++ * @see swr_init(), swr_free() ++ * @return NULL on error, allocated context otherwise ++ */ ++struct SwrContext *swr_alloc_set_opts(struct SwrContext *s, ++ int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate, ++ int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate, ++ int log_offset, void *log_ctx); ++ ++/** ++ * Free the given SwrContext and set the pointer to NULL. ++ */ ++void swr_free(struct SwrContext **s); ++ ++/** ++ * Convert audio. ++ * ++ * in and in_count can be set to 0 to flush the last few samples out at the ++ * end. ++ * ++ * @param s allocated Swr context, with parameters set ++ * @param out output buffers, only the first one need be set in case of packed audio ++ * @param out_count amount of space available for output in samples per channel ++ * @param in input buffers, only the first one need to be set in case of packed audio ++ * @param in_count number of input samples available in one channel ++ * ++ * @return number of samples output per channel ++ */ ++int swr_convert(struct SwrContext *s, uint8_t *out[SWR_CH_MAX], int out_count, ++ const uint8_t *in [SWR_CH_MAX], int in_count); ++ ++/** ++ * Activate resampling compensation. ++ */ ++int swr_set_compensation(struct SwrContext *s, int sample_delta, int compensation_distance); ++ ++/** ++ * Set a customized input channel mapping. ++ * ++ * @param s allocated Swr context, not yet initialized ++ * @param channel_map customized input channel mapping (array of channel ++ * indexes, -1 for a muted channel) ++ * @return AVERROR error code in case of failure. ++ */ ++int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map); ++ ++/** ++ * Return the LIBSWRESAMPLE_VERSION_INT constant. ++ */ ++unsigned swresample_version(void); ++ ++/** ++ * Return the swr build-time configuration. ++ */ ++const char *swresample_configuration(void); ++ ++/** ++ * Return the swr license. ++ */ ++const char *swresample_license(void); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample_internal.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample_internal.h 2012-05-14 14:08:55.370360832 +0200 +@@ -0,0 +1,88 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * libswresample 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef SWR_INTERNAL_H ++#define SWR_INTERNAL_H ++ ++#include "swresample.h" ++ ++typedef struct AudioData{ ++ uint8_t *ch[SWR_CH_MAX]; ///< samples buffer per channel ++ uint8_t *data; ///< samples buffer ++ int ch_count; ///< number of channels ++ int bps; ///< bytes per sample ++ int count; ///< number of samples ++ int planar; ///< 1 if planar audio, 0 otherwise ++} AudioData; ++ ++typedef struct SwrContext { ++ const AVClass *av_class; ///< AVClass used for AVOption and av_log() ++ int log_level_offset; ///< logging level offset ++ void *log_ctx; ///< parent logging context ++ enum AVSampleFormat in_sample_fmt; ///< input sample format ++ enum AVSampleFormat int_sample_fmt; ///< internal sample format (AV_SAMPLE_FMT_FLT or AV_SAMPLE_FMT_S16) ++ enum AVSampleFormat out_sample_fmt; ///< output sample format ++ int64_t in_ch_layout; ///< input channel layout ++ int64_t out_ch_layout; ///< output channel layout ++ int in_sample_rate; ///< input sample rate ++ int out_sample_rate; ///< output sample rate ++ int flags; ///< miscellaneous flags such as SWR_FLAG_RESAMPLE ++ float slev; ///< surround mixing level ++ float clev; ///< center mixing level ++ float rematrix_volume; ///< rematrixing volume coefficient ++ const int *channel_map; ///< channel index (or -1 if muted channel) map ++ int used_ch_count; ///< number of used input channels (mapped channel count if channel_map, otherwise in.ch_count) ++ ++ int int_bps; ///< internal bytes per sample ++ int resample_first; ///< 1 if resampling must come first, 0 if rematrixing ++ int rematrix; ///< flag to indicate if rematrixing is needed (basically if input and output layouts mismatch) ++ ++ AudioData in; ///< input audio data ++ AudioData postin; ///< post-input audio data: used for rematrix/resample ++ AudioData midbuf; ///< intermediate audio data (postin/preout) ++ AudioData preout; ///< pre-output audio data: used for rematrix/resample ++ AudioData out; ///< converted output audio data ++ AudioData in_buffer; ///< cached audio data (convert and resample purpose) ++ int in_buffer_index; ///< cached buffer position ++ int in_buffer_count; ///< cached buffer length ++ int resample_in_constraint; ///< 1 if the input end was reach before the output end, 0 otherwise ++ ++ struct AudioConvert *in_convert; ///< input conversion context ++ struct AudioConvert *out_convert; ///< output conversion context ++ struct AudioConvert *full_convert; ///< full conversion context (single conversion for input and output) ++ struct ResampleContext *resample; ///< resampling context ++ ++ float matrix[SWR_CH_MAX][SWR_CH_MAX]; ///< floating point rematrixing coefficients ++ int32_t matrix32[SWR_CH_MAX][SWR_CH_MAX]; ///< 17.15 fixed point rematrixing coefficients ++ uint8_t matrix_ch[SWR_CH_MAX][SWR_CH_MAX+1]; ///< Lists of input channels per output channel that have non zero rematrixing coefficients ++ ++ /* TODO: callbacks for ASM optimizations */ ++}SwrContext; ++ ++struct ResampleContext *swri_resample_init(struct ResampleContext *, int out_rate, int in_rate, int filter_size, int phase_shift, int linear, double cutoff); ++void swri_resample_free(struct ResampleContext **c); ++int swri_multiple_resample(struct ResampleContext *c, AudioData *dst, int dst_size, AudioData *src, int src_size, int *consumed); ++void swri_resample_compensate(struct ResampleContext *c, int sample_delta, int compensation_distance); ++int swri_resample(struct ResampleContext *c, int16_t *dst, const int16_t *src, int *consumed, int src_size, int dst_size, int update_ctx); ++ ++int swri_rematrix_init(SwrContext *s); ++int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mustcopy); ++ ++#endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample_test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample_test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswresample/swresample_test.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswresample/swresample_test.c 2012-05-14 14:08:55.371360852 +0200 +@@ -0,0 +1,216 @@ ++/* ++ * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at) ++ * ++ * This file is part of libswresample ++ * ++ * libswresample 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. ++ * ++ * libswresample 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 libswresample; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "libavutil/avassert.h" ++#include "libavutil/common.h" ++#include "libavutil/audioconvert.h" ++#include "swresample.h" ++#undef fprintf ++ ++#define SAMPLES 1000 ++ ++#define ASSERT_LEVEL 2 ++ ++static double get(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f){ ++ const uint8_t *p; ++ if(av_sample_fmt_is_planar(f)){ ++ f= av_get_alt_sample_fmt(f, 0); ++ p= a[ch]; ++ }else{ ++ p= a[0]; ++ index= ch + index*ch_count; ++ } ++ ++ switch(f){ ++ case AV_SAMPLE_FMT_U8 : return ((const uint8_t*)p)[index]/255.0*2-1.0; ++ case AV_SAMPLE_FMT_S16: return ((const int16_t*)p)[index]/32767.0; ++ case AV_SAMPLE_FMT_S32: return ((const int32_t*)p)[index]/2147483647.0; ++ case AV_SAMPLE_FMT_FLT: return ((const float *)p)[index]; ++ case AV_SAMPLE_FMT_DBL: return ((const double *)p)[index]; ++ default: av_assert0(0); ++ } ++} ++ ++static void set(uint8_t *a[], int ch, int index, int ch_count, enum AVSampleFormat f, double v){ ++ uint8_t *p; ++ if(av_sample_fmt_is_planar(f)){ ++ f= av_get_alt_sample_fmt(f, 0); ++ p= a[ch]; ++ }else{ ++ p= a[0]; ++ index= ch + index*ch_count; ++ } ++ switch(f){ ++ case AV_SAMPLE_FMT_U8 : ((uint8_t*)p)[index]= (v+1.0)*255.0/2; break; ++ case AV_SAMPLE_FMT_S16: ((int16_t*)p)[index]= v*32767; break; ++ case AV_SAMPLE_FMT_S32: ((int32_t*)p)[index]= v*2147483647; break; ++ case AV_SAMPLE_FMT_FLT: ((float *)p)[index]= v; break; ++ case AV_SAMPLE_FMT_DBL: ((double *)p)[index]= v; break; ++ default: av_assert2(0); ++ } ++} ++ ++uint64_t layouts[]={ ++AV_CH_LAYOUT_MONO , ++AV_CH_LAYOUT_STEREO , ++AV_CH_LAYOUT_2_1 , ++AV_CH_LAYOUT_SURROUND , ++AV_CH_LAYOUT_4POINT0 , ++AV_CH_LAYOUT_2_2 , ++AV_CH_LAYOUT_QUAD , ++AV_CH_LAYOUT_5POINT0 , ++AV_CH_LAYOUT_5POINT1 , ++AV_CH_LAYOUT_5POINT0_BACK , ++AV_CH_LAYOUT_5POINT1_BACK , ++AV_CH_LAYOUT_7POINT0 , ++AV_CH_LAYOUT_7POINT1 , ++AV_CH_LAYOUT_7POINT1_WIDE , ++0 ++}; ++ ++static void setup_array(uint8_t *out[SWR_CH_MAX], uint8_t *in, enum AVSampleFormat format, int samples){ ++ if(av_sample_fmt_is_planar(format)){ ++ int i; ++ int plane_size= av_get_bytes_per_sample(format&0xFF)*samples; ++ format&=0xFF; ++ for(i=0; i%d, rate:%5d->%5d, fmt:%s->%s", ++ in_ch_count, out_ch_count, ++ in_sample_rate, out_sample_rate, ++ av_get_sample_fmt_name(in_sample_fmt), av_get_sample_fmt_name(out_sample_fmt)); ++ forw_ctx = swr_alloc_set_opts(forw_ctx, out_ch_layout, av_get_alt_sample_fmt(out_sample_fmt, 1), out_sample_rate, ++ in_ch_layout, av_get_alt_sample_fmt( in_sample_fmt, 1), in_sample_rate, ++ 0, 0); ++ backw_ctx = swr_alloc_set_opts(backw_ctx, in_ch_layout, in_sample_fmt, in_sample_rate, ++ out_ch_layout, av_get_alt_sample_fmt(out_sample_fmt, 1), out_sample_rate, ++ 0, 0); ++ if(swr_init( forw_ctx) < 0) ++ fprintf(stderr, "swr_init(->) failed\n"); ++ if(swr_init(backw_ctx) < 0) ++ fprintf(stderr, "swr_init(<-) failed\n"); ++ if(!forw_ctx) ++ fprintf(stderr, "Failed to init forw_cts\n"); ++ if(!backw_ctx) ++ fprintf(stderr, "Failed to init backw_ctx\n"); ++ //FIXME test planar ++ setup_array(ain , array_in , av_get_alt_sample_fmt( in_sample_fmt, 1), SAMPLES); ++ setup_array(amid, array_mid, av_get_alt_sample_fmt(out_sample_fmt, 1), 3*SAMPLES); ++ setup_array(aout, array_out, in_sample_fmt , SAMPLES); ++ for(ch=0; chswScale; +- if (c->flags & SWS_CPU_CAPS_BFIN) +- if (c->dstFormat == PIX_FMT_YUV420P) +- if (c->srcFormat == PIX_FMT_UYVY422) { +- av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized uyvytoyv12_unscaled\n"); +- c->swScale = uyvytoyv12_unscaled; +- } +- if (c->dstFormat == PIX_FMT_YUV420P) +- if (c->srcFormat == PIX_FMT_YUYV422) { +- av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized yuyvtoyv12_unscaled\n"); +- c->swScale = yuyvtoyv12_unscaled; +- } ++ if (c->dstFormat == PIX_FMT_YUV420P && c->srcFormat == PIX_FMT_UYVY422) { ++ av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized uyvytoyv12_unscaled\n"); ++ c->swScale = uyvytoyv12_unscaled; ++ } ++ if (c->dstFormat == PIX_FMT_YUV420P && c->srcFormat == PIX_FMT_YUYV422) { ++ av_log (NULL, AV_LOG_VERBOSE, "selecting Blackfin optimized yuyvtoyv12_unscaled\n"); ++ c->swScale = yuyvtoyv12_unscaled; ++ } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/bfin/yuv2rgb_bfin.c 2012-05-14 14:08:55.374360913 +0200 +@@ -28,6 +28,7 @@ + #include + #include "config.h" + #include ++#include "libavutil/pixdesc.h" + #include "libswscale/rgb2rgb.h" + #include "libswscale/swscale.h" + #include "libswscale/swscale_internal.h" +@@ -197,7 +198,7 @@ + } + + av_log(c, AV_LOG_INFO, "BlackFin accelerated color space converter %s\n", +- sws_format_name (c->dstFormat)); ++ av_get_pix_fmt_name(c->dstFormat)); + + return f; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/colorspace-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/colorspace-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/colorspace-test.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/colorspace-test.c 2012-05-14 14:08:55.375360933 +0200 +@@ -27,59 +27,32 @@ + #include "swscale.h" + #include "rgb2rgb.h" + +-#define SIZE 1000 ++#define SIZE 1000 + #define srcByte 0x55 + #define dstByte 0xBB + +-#define FUNC(s,d,n) {s,d,#n,n} +- +-static int cpu_caps; +- +-static char *args_parse(int argc, char *argv[]) +-{ +- int o; +- +- while ((o = getopt(argc, argv, "m23")) != -1) { +- switch (o) { +- case 'm': +- cpu_caps |= SWS_CPU_CAPS_MMX; +- break; +- case '2': +- cpu_caps |= SWS_CPU_CAPS_MMX2; +- break; +- case '3': +- cpu_caps |= SWS_CPU_CAPS_3DNOW; +- break; +- default: +- av_log(NULL, AV_LOG_ERROR, "Unknown option %c\n", o); +- } +- } +- +- return argv[optind]; +-} ++#define FUNC(s, d, n) { s, d, #n, n } + + int main(int argc, char **argv) + { + int i, funcNum; +- uint8_t *srcBuffer= (uint8_t*)av_malloc(SIZE); +- uint8_t *dstBuffer= (uint8_t*)av_malloc(SIZE); +- int failedNum=0; +- int passedNum=0; ++ uint8_t *srcBuffer = av_malloc(SIZE); ++ uint8_t *dstBuffer = av_malloc(SIZE); ++ int failedNum = 0; ++ int passedNum = 0; + + if (!srcBuffer || !dstBuffer) + return -1; + + av_log(NULL, AV_LOG_INFO, "memory corruption test ...\n"); +- args_parse(argc, argv); +- av_log(NULL, AV_LOG_INFO, "CPU capabilities forced to %x\n", cpu_caps); +- sws_rgb2rgb_init(cpu_caps); ++ sws_rgb2rgb_init(); + +- for(funcNum=0; ; funcNum++) { ++ for (funcNum = 0; ; funcNum++) { + struct func_info_s { + int src_bpp; + int dst_bpp; + const char *name; +- void (*func)(const uint8_t *src, uint8_t *dst, long src_size); ++ void (*func)(const uint8_t *src, uint8_t *dst, int src_size); + } func_info[] = { + FUNC(2, 2, rgb15to16), + FUNC(2, 3, rgb15to24), +@@ -112,67 +85,78 @@ + FUNC(0, 0, NULL) + }; + int width; +- int failed=0; +- int srcBpp=0; +- int dstBpp=0; ++ int failed = 0; ++ int srcBpp = 0; ++ int dstBpp = 0; + +- if (!func_info[funcNum].func) break; ++ if (!func_info[funcNum].func) ++ break; + +- av_log(NULL, AV_LOG_INFO,"."); ++ av_log(NULL, AV_LOG_INFO, "."); + memset(srcBuffer, srcByte, SIZE); + +- for(width=63; width>0; width--) { ++ for (width = 63; width > 0; width--) { + int dstOffset; +- for(dstOffset=128; dstOffset<196; dstOffset+=4) { ++ for (dstOffset = 128; dstOffset < 196; dstOffset += 4) { + int srcOffset; + memset(dstBuffer, dstByte, SIZE); + +- for(srcOffset=128; srcOffset<196; srcOffset+=4) { +- uint8_t *src= srcBuffer+srcOffset; +- uint8_t *dst= dstBuffer+dstOffset; +- const char *name=NULL; +- +- if(failed) break; //don't fill the screen with shit ... ++ for (srcOffset = 128; srcOffset < 196; srcOffset += 4) { ++ uint8_t *src = srcBuffer + srcOffset; ++ uint8_t *dst = dstBuffer + dstOffset; ++ const char *name = NULL; ++ ++ // don't fill the screen with shit ... ++ if (failed) ++ break; + + srcBpp = func_info[funcNum].src_bpp; + dstBpp = func_info[funcNum].dst_bpp; + name = func_info[funcNum].name; + +- func_info[funcNum].func(src, dst, width*srcBpp); ++ func_info[funcNum].func(src, dst, width * srcBpp); + +- if(!srcBpp) break; ++ if (!srcBpp) ++ break; + +- for(i=0; i ++ * based on the equivalent C code in swscale.c ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "config.h" ++#include "libswscale/swscale.h" ++#include "libswscale/swscale_internal.h" ++#include "libavutil/cpu.h" ++#include "yuv2rgb_altivec.h" ++ ++#define vzero vec_splat_s32(0) ++ ++static inline void ++altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) ++{ ++ register int i; ++ vector unsigned int altivec_vectorShiftInt19 = ++ vec_add(vec_splat_u32(10), vec_splat_u32(9)); ++ if ((uintptr_t)dest % 16) { ++ /* badly aligned store, we force store alignment */ ++ /* and will handle load misalignment on val w/ vec_perm */ ++ vector unsigned char perm1; ++ vector signed int v1; ++ for (i = 0 ; (i < dstW) && ++ (((uintptr_t)dest + i) % 16) ; i++) { ++ int t = val[i] >> 19; ++ dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); ++ } ++ perm1 = vec_lvsl(i << 2, val); ++ v1 = vec_ld(i << 2, val); ++ for ( ; i < (dstW - 15); i+=16) { ++ int offset = i << 2; ++ vector signed int v2 = vec_ld(offset + 16, val); ++ vector signed int v3 = vec_ld(offset + 32, val); ++ vector signed int v4 = vec_ld(offset + 48, val); ++ vector signed int v5 = vec_ld(offset + 64, val); ++ vector signed int v12 = vec_perm(v1, v2, perm1); ++ vector signed int v23 = vec_perm(v2, v3, perm1); ++ vector signed int v34 = vec_perm(v3, v4, perm1); ++ vector signed int v45 = vec_perm(v4, v5, perm1); ++ ++ vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); ++ vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); ++ vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); ++ vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); ++ vector unsigned short vs1 = vec_packsu(vA, vB); ++ vector unsigned short vs2 = vec_packsu(vC, vD); ++ vector unsigned char vf = vec_packsu(vs1, vs2); ++ vec_st(vf, i, dest); ++ v1 = v5; ++ } ++ } else { // dest is properly aligned, great ++ for (i = 0; i < (dstW - 15); i+=16) { ++ int offset = i << 2; ++ vector signed int v1 = vec_ld(offset, val); ++ vector signed int v2 = vec_ld(offset + 16, val); ++ vector signed int v3 = vec_ld(offset + 32, val); ++ vector signed int v4 = vec_ld(offset + 48, val); ++ vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); ++ vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); ++ vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); ++ vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); ++ vector unsigned short vs1 = vec_packsu(v5, v6); ++ vector unsigned short vs2 = vec_packsu(v7, v8); ++ vector unsigned char vf = vec_packsu(vs1, vs2); ++ vec_st(vf, i, dest); ++ } ++ } ++ for ( ; i < dstW ; i++) { ++ int t = val[i] >> 19; ++ dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); ++ } ++} ++ ++//FIXME remove the usage of scratch buffers. ++static void ++yuv2planeX_altivec(const int16_t *filter, int filterSize, ++ const int16_t **src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset) ++{ ++ register int i, j; ++ DECLARE_ALIGNED(16, int, val)[dstW]; ++ ++ for (i=0; i>7, (1<<15)-1); ++ } ++ } ++ else ++ switch (filterSize) { ++ case 4: ++ for (i=0; i 12) { ++ src_v1 = vec_ld(srcPos + 16, src); ++ } ++ src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); ++ ++ src_v = // vec_unpackh sign-extends... ++ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); ++ // now put our elements in the even slots ++ src_v = vec_mergeh(src_v, (vector signed short)vzero); ++ ++ filter_v = vec_ld(i << 3, filter); ++ // The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2). ++ ++ // The neat trick: We only care for half the elements, ++ // high or low depending on (i<<3)%16 (it's 0 or 8 here), ++ // and we're going to use vec_mule, so we choose ++ // carefully how to "unpack" the elements into the even slots. ++ if ((i << 3) % 16) ++ filter_v = vec_mergel(filter_v, (vector signed short)vzero); ++ else ++ filter_v = vec_mergeh(filter_v, (vector signed short)vzero); ++ ++ val_vEven = vec_mule(src_v, filter_v); ++ val_s = vec_sums(val_vEven, vzero); ++ vec_st(val_s, 0, tempo); ++ dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); ++ } ++ break; ++ ++ case 8: ++ for (i=0; i 8) { ++ src_v1 = vec_ld(srcPos + 16, src); ++ } ++ src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); ++ ++ src_v = // vec_unpackh sign-extends... ++ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); ++ filter_v = vec_ld(i << 4, filter); ++ // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2) ++ ++ val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); ++ val_s = vec_sums(val_v, vzero); ++ vec_st(val_s, 0, tempo); ++ dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); ++ } ++ break; ++ ++ case 16: ++ for (i=0; i>7, (1<<15)-1); ++ } ++ break; ++ ++ default: ++ for (i=0; i 8) { ++ src_v1 = vec_ld(srcPos + j + 16, src); ++ } ++ src_vF = vec_perm(src_v0, src_v1, permS); ++ ++ src_v = // vec_unpackh sign-extends... ++ (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); ++ // loading filter_v0R is useless, it's already done above ++ //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); ++ filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); ++ filter_v = vec_perm(filter_v0R, filter_v1R, permF); ++ ++ val_v = vec_msums(src_v, filter_v, val_v); ++ } ++ ++ val_s = vec_sums(val_v, vzero); ++ ++ vec_st(val_s, 0, tempo); ++ dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); ++ } ++ ++ } ++} ++ ++void ff_sws_init_swScale_altivec(SwsContext *c) ++{ ++ enum PixelFormat dstFormat = c->dstFormat; ++ ++ if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) ++ return; ++ ++ if (c->srcBpc == 8 && c->dstBpc <= 10) { ++ c->hyScale = c->hcScale = hScale_altivec_real; ++ } ++ if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && ++ dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 && ++ !c->alpPixBuf) { ++ c->yuv2planeX = yuv2planeX_altivec; ++ } ++ ++ /* The following list of supported dstFormat values should ++ * match what's found in the body of ff_yuv2packedX_altivec() */ ++ if (!(c->flags & (SWS_BITEXACT | SWS_FULL_CHR_H_INT)) && !c->alpPixBuf) { ++ switch (c->dstFormat) { ++ case PIX_FMT_ABGR: c->yuv2packedX = ff_yuv2abgr_X_altivec; break; ++ case PIX_FMT_BGRA: c->yuv2packedX = ff_yuv2bgra_X_altivec; break; ++ case PIX_FMT_ARGB: c->yuv2packedX = ff_yuv2argb_X_altivec; break; ++ case PIX_FMT_RGBA: c->yuv2packedX = ff_yuv2rgba_X_altivec; break; ++ case PIX_FMT_BGR24: c->yuv2packedX = ff_yuv2bgr24_X_altivec; break; ++ case PIX_FMT_RGB24: c->yuv2packedX = ff_yuv2rgb24_X_altivec; break; ++ } ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/swscale_altivec_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/swscale_altivec_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/swscale_altivec_template.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/swscale_altivec_template.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,545 +0,0 @@ +-/* +- * AltiVec-enhanced yuv2yuvX +- * +- * Copyright (C) 2004 Romain Dolbeau +- * based on the equivalent C code in swscale.c +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#define vzero vec_splat_s32(0) +- +-static inline void +-altivec_packIntArrayToCharArray(int *val, uint8_t* dest, int dstW) +-{ +- register int i; +- vector unsigned int altivec_vectorShiftInt19 = +- vec_add(vec_splat_u32(10), vec_splat_u32(9)); +- if ((unsigned long)dest % 16) { +- /* badly aligned store, we force store alignment */ +- /* and will handle load misalignment on val w/ vec_perm */ +- vector unsigned char perm1; +- vector signed int v1; +- for (i = 0 ; (i < dstW) && +- (((unsigned long)dest + i) % 16) ; i++) { +- int t = val[i] >> 19; +- dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); +- } +- perm1 = vec_lvsl(i << 2, val); +- v1 = vec_ld(i << 2, val); +- for ( ; i < (dstW - 15); i+=16) { +- int offset = i << 2; +- vector signed int v2 = vec_ld(offset + 16, val); +- vector signed int v3 = vec_ld(offset + 32, val); +- vector signed int v4 = vec_ld(offset + 48, val); +- vector signed int v5 = vec_ld(offset + 64, val); +- vector signed int v12 = vec_perm(v1, v2, perm1); +- vector signed int v23 = vec_perm(v2, v3, perm1); +- vector signed int v34 = vec_perm(v3, v4, perm1); +- vector signed int v45 = vec_perm(v4, v5, perm1); +- +- vector signed int vA = vec_sra(v12, altivec_vectorShiftInt19); +- vector signed int vB = vec_sra(v23, altivec_vectorShiftInt19); +- vector signed int vC = vec_sra(v34, altivec_vectorShiftInt19); +- vector signed int vD = vec_sra(v45, altivec_vectorShiftInt19); +- vector unsigned short vs1 = vec_packsu(vA, vB); +- vector unsigned short vs2 = vec_packsu(vC, vD); +- vector unsigned char vf = vec_packsu(vs1, vs2); +- vec_st(vf, i, dest); +- v1 = v5; +- } +- } else { // dest is properly aligned, great +- for (i = 0; i < (dstW - 15); i+=16) { +- int offset = i << 2; +- vector signed int v1 = vec_ld(offset, val); +- vector signed int v2 = vec_ld(offset + 16, val); +- vector signed int v3 = vec_ld(offset + 32, val); +- vector signed int v4 = vec_ld(offset + 48, val); +- vector signed int v5 = vec_sra(v1, altivec_vectorShiftInt19); +- vector signed int v6 = vec_sra(v2, altivec_vectorShiftInt19); +- vector signed int v7 = vec_sra(v3, altivec_vectorShiftInt19); +- vector signed int v8 = vec_sra(v4, altivec_vectorShiftInt19); +- vector unsigned short vs1 = vec_packsu(v5, v6); +- vector unsigned short vs2 = vec_packsu(v7, v8); +- vector unsigned char vf = vec_packsu(vs1, vs2); +- vec_st(vf, i, dest); +- } +- } +- for ( ; i < dstW ; i++) { +- int t = val[i] >> 19; +- dest[i] = (t < 0) ? 0 : ((t > 255) ? 255 : t); +- } +-} +- +-static inline void +-yuv2yuvX_altivec_real(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, uint8_t *uDest, uint8_t *vDest, int dstW, int chrDstW) +-{ +- const vector signed int vini = {(1 << 18), (1 << 18), (1 << 18), (1 << 18)}; +- register int i, j; +- { +- DECLARE_ALIGNED(16, int, val)[dstW]; +- +- for (i = 0; i < (dstW -7); i+=4) { +- vec_st(vini, i << 2, val); +- } +- for (; i < dstW; i++) { +- val[i] = (1 << 18); +- } +- +- for (j = 0; j < lumFilterSize; j++) { +- vector signed short l1, vLumFilter = vec_ld(j << 1, lumFilter); +- vector unsigned char perm, perm0 = vec_lvsl(j << 1, lumFilter); +- vLumFilter = vec_perm(vLumFilter, vLumFilter, perm0); +- vLumFilter = vec_splat(vLumFilter, 0); // lumFilter[j] is loaded 8 times in vLumFilter +- +- perm = vec_lvsl(0, lumSrc[j]); +- l1 = vec_ld(0, lumSrc[j]); +- +- for (i = 0; i < (dstW - 7); i+=8) { +- int offset = i << 2; +- vector signed short l2 = vec_ld((i << 1) + 16, lumSrc[j]); +- +- vector signed int v1 = vec_ld(offset, val); +- vector signed int v2 = vec_ld(offset + 16, val); +- +- vector signed short ls = vec_perm(l1, l2, perm); // lumSrc[j][i] ... lumSrc[j][i+7] +- +- vector signed int i1 = vec_mule(vLumFilter, ls); +- vector signed int i2 = vec_mulo(vLumFilter, ls); +- +- vector signed int vf1 = vec_mergeh(i1, i2); +- vector signed int vf2 = vec_mergel(i1, i2); // lumSrc[j][i] * lumFilter[j] ... lumSrc[j][i+7] * lumFilter[j] +- +- vector signed int vo1 = vec_add(v1, vf1); +- vector signed int vo2 = vec_add(v2, vf2); +- +- vec_st(vo1, offset, val); +- vec_st(vo2, offset + 16, val); +- +- l1 = l2; +- } +- for ( ; i < dstW; i++) { +- val[i] += lumSrc[j][i] * lumFilter[j]; +- } +- } +- altivec_packIntArrayToCharArray(val, dest, dstW); +- } +- if (uDest != 0) { +- DECLARE_ALIGNED(16, int, u)[chrDstW]; +- DECLARE_ALIGNED(16, int, v)[chrDstW]; +- +- for (i = 0; i < (chrDstW -7); i+=4) { +- vec_st(vini, i << 2, u); +- vec_st(vini, i << 2, v); +- } +- for (; i < chrDstW; i++) { +- u[i] = (1 << 18); +- v[i] = (1 << 18); +- } +- +- for (j = 0; j < chrFilterSize; j++) { +- vector signed short l1, l1_V, vChrFilter = vec_ld(j << 1, chrFilter); +- vector unsigned char perm, perm0 = vec_lvsl(j << 1, chrFilter); +- vChrFilter = vec_perm(vChrFilter, vChrFilter, perm0); +- vChrFilter = vec_splat(vChrFilter, 0); // chrFilter[j] is loaded 8 times in vChrFilter +- +- perm = vec_lvsl(0, chrSrc[j]); +- l1 = vec_ld(0, chrSrc[j]); +- l1_V = vec_ld(2048 << 1, chrSrc[j]); +- +- for (i = 0; i < (chrDstW - 7); i+=8) { +- int offset = i << 2; +- vector signed short l2 = vec_ld((i << 1) + 16, chrSrc[j]); +- vector signed short l2_V = vec_ld(((i + 2048) << 1) + 16, chrSrc[j]); +- +- vector signed int v1 = vec_ld(offset, u); +- vector signed int v2 = vec_ld(offset + 16, u); +- vector signed int v1_V = vec_ld(offset, v); +- vector signed int v2_V = vec_ld(offset + 16, v); +- +- vector signed short ls = vec_perm(l1, l2, perm); // chrSrc[j][i] ... chrSrc[j][i+7] +- vector signed short ls_V = vec_perm(l1_V, l2_V, perm); // chrSrc[j][i+2048] ... chrSrc[j][i+2055] +- +- vector signed int i1 = vec_mule(vChrFilter, ls); +- vector signed int i2 = vec_mulo(vChrFilter, ls); +- vector signed int i1_V = vec_mule(vChrFilter, ls_V); +- vector signed int i2_V = vec_mulo(vChrFilter, ls_V); +- +- vector signed int vf1 = vec_mergeh(i1, i2); +- vector signed int vf2 = vec_mergel(i1, i2); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] +- vector signed int vf1_V = vec_mergeh(i1_V, i2_V); +- vector signed int vf2_V = vec_mergel(i1_V, i2_V); // chrSrc[j][i] * chrFilter[j] ... chrSrc[j][i+7] * chrFilter[j] +- +- vector signed int vo1 = vec_add(v1, vf1); +- vector signed int vo2 = vec_add(v2, vf2); +- vector signed int vo1_V = vec_add(v1_V, vf1_V); +- vector signed int vo2_V = vec_add(v2_V, vf2_V); +- +- vec_st(vo1, offset, u); +- vec_st(vo2, offset + 16, u); +- vec_st(vo1_V, offset, v); +- vec_st(vo2_V, offset + 16, v); +- +- l1 = l2; +- l1_V = l2_V; +- } +- for ( ; i < chrDstW; i++) { +- u[i] += chrSrc[j][i] * chrFilter[j]; +- v[i] += chrSrc[j][i + 2048] * chrFilter[j]; +- } +- } +- altivec_packIntArrayToCharArray(u, uDest, chrDstW); +- altivec_packIntArrayToCharArray(v, vDest, chrDstW); +- } +-} +- +-static inline void hScale_altivec_real(int16_t *dst, int dstW, +- const uint8_t *src, int srcW, +- int xInc, const int16_t *filter, +- const int16_t *filterPos, int filterSize) +-{ +- register int i; +- DECLARE_ALIGNED(16, int, tempo)[4]; +- +- if (filterSize % 4) { +- for (i=0; i>7, (1<<15)-1); +- } +- } +- else +- switch (filterSize) { +- case 4: +- { +- for (i=0; i 12) { +- src_v1 = vec_ld(srcPos + 16, src); +- } +- src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); +- +- src_v = // vec_unpackh sign-extends... +- (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); +- // now put our elements in the even slots +- src_v = vec_mergeh(src_v, (vector signed short)vzero); +- +- filter_v = vec_ld(i << 3, filter); +- // The 3 above is 2 (filterSize == 4) + 1 (sizeof(short) == 2). +- +- // The neat trick: We only care for half the elements, +- // high or low depending on (i<<3)%16 (it's 0 or 8 here), +- // and we're going to use vec_mule, so we choose +- // carefully how to "unpack" the elements into the even slots. +- if ((i << 3) % 16) +- filter_v = vec_mergel(filter_v, (vector signed short)vzero); +- else +- filter_v = vec_mergeh(filter_v, (vector signed short)vzero); +- +- val_vEven = vec_mule(src_v, filter_v); +- val_s = vec_sums(val_vEven, vzero); +- vec_st(val_s, 0, tempo); +- dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); +- } +- } +- break; +- +- case 8: +- { +- for (i=0; i 8) { +- src_v1 = vec_ld(srcPos + 16, src); +- } +- src_vF = vec_perm(src_v0, src_v1, vec_lvsl(srcPos, src)); +- +- src_v = // vec_unpackh sign-extends... +- (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); +- filter_v = vec_ld(i << 4, filter); +- // the 4 above is 3 (filterSize == 8) + 1 (sizeof(short) == 2) +- +- val_v = vec_msums(src_v, filter_v, (vector signed int)vzero); +- val_s = vec_sums(val_v, vzero); +- vec_st(val_s, 0, tempo); +- dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); +- } +- } +- break; +- +- case 16: +- { +- for (i=0; i>7, (1<<15)-1); +- } +- } +- break; +- +- default: +- { +- for (i=0; i 8) { +- src_v1 = vec_ld(srcPos + j + 16, src); +- } +- src_vF = vec_perm(src_v0, src_v1, permS); +- +- src_v = // vec_unpackh sign-extends... +- (vector signed short)(vec_mergeh((vector unsigned char)vzero, src_vF)); +- // loading filter_v0R is useless, it's already done above +- //vector signed short filter_v0R = vec_ld((i * 2 * filterSize) + j, filter); +- filter_v1R = vec_ld((i * 2 * filterSize) + (j * 2) + 16, filter); +- filter_v = vec_perm(filter_v0R, filter_v1R, permF); +- +- val_v = vec_msums(src_v, filter_v, val_v); +- } +- +- val_s = vec_sums(val_v, vzero); +- +- vec_st(val_s, 0, tempo); +- dst[i] = FFMIN(tempo[3]>>7, (1<<15)-1); +- } +- +- } +- } +-} +- +-static inline int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) +-{ +- uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; +- // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); +- const uint8_t *ysrc = src[0]; +- const uint8_t *usrc = src[1]; +- const uint8_t *vsrc = src[2]; +- const int width = c->srcW; +- const int height = srcSliceH; +- const int lumStride = srcStride[0]; +- const int chromStride = srcStride[1]; +- const int dstStride = dstStride_a[0]; +- const vector unsigned char yperm = vec_lvsl(0, ysrc); +- const int vertLumPerChroma = 2; +- register unsigned int y; +- +- if (width&15) { +- yv12toyuy2(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); +- return srcSliceH; +- } +- +- /* This code assumes: +- +- 1) dst is 16 bytes-aligned +- 2) dstStride is a multiple of 16 +- 3) width is a multiple of 16 +- 4) lum & chrom stride are multiples of 8 +- */ +- +- for (y=0; y> 1; +- vector unsigned char v_yA = vec_ld(i, ysrc); +- vector unsigned char v_yB = vec_ld(i + 16, ysrc); +- vector unsigned char v_yC = vec_ld(i + 32, ysrc); +- vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); +- vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); +- vector unsigned char v_uA = vec_ld(j, usrc); +- vector unsigned char v_uB = vec_ld(j + 16, usrc); +- vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); +- vector unsigned char v_vA = vec_ld(j, vsrc); +- vector unsigned char v_vB = vec_ld(j + 16, vsrc); +- vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); +- vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); +- vector unsigned char v_uv_b = vec_mergel(v_u, v_v); +- vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); +- vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); +- vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); +- vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); +- vec_st(v_yuy2_0, (i << 1), dst); +- vec_st(v_yuy2_1, (i << 1) + 16, dst); +- vec_st(v_yuy2_2, (i << 1) + 32, dst); +- vec_st(v_yuy2_3, (i << 1) + 48, dst); +- } +- if (i < width) { +- const unsigned int j = i >> 1; +- vector unsigned char v_y1 = vec_ld(i, ysrc); +- vector unsigned char v_u = vec_ld(j, usrc); +- vector unsigned char v_v = vec_ld(j, vsrc); +- vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); +- vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); +- vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); +- vec_st(v_yuy2_0, (i << 1), dst); +- vec_st(v_yuy2_1, (i << 1) + 16, dst); +- } +- if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { +- usrc += chromStride; +- vsrc += chromStride; +- } +- ysrc += lumStride; +- dst += dstStride; +- } +- +- return srcSliceH; +-} +- +-static inline int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride_a[]) +-{ +- uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; +- // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); +- const uint8_t *ysrc = src[0]; +- const uint8_t *usrc = src[1]; +- const uint8_t *vsrc = src[2]; +- const int width = c->srcW; +- const int height = srcSliceH; +- const int lumStride = srcStride[0]; +- const int chromStride = srcStride[1]; +- const int dstStride = dstStride_a[0]; +- const int vertLumPerChroma = 2; +- const vector unsigned char yperm = vec_lvsl(0, ysrc); +- register unsigned int y; +- +- if (width&15) { +- yv12touyvy(ysrc, usrc, vsrc, dst, c->srcW, srcSliceH, lumStride, chromStride, dstStride); +- return srcSliceH; +- } +- +- /* This code assumes: +- +- 1) dst is 16 bytes-aligned +- 2) dstStride is a multiple of 16 +- 3) width is a multiple of 16 +- 4) lum & chrom stride are multiples of 8 +- */ +- +- for (y=0; y> 1; +- vector unsigned char v_yA = vec_ld(i, ysrc); +- vector unsigned char v_yB = vec_ld(i + 16, ysrc); +- vector unsigned char v_yC = vec_ld(i + 32, ysrc); +- vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); +- vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); +- vector unsigned char v_uA = vec_ld(j, usrc); +- vector unsigned char v_uB = vec_ld(j + 16, usrc); +- vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); +- vector unsigned char v_vA = vec_ld(j, vsrc); +- vector unsigned char v_vB = vec_ld(j + 16, vsrc); +- vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); +- vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); +- vector unsigned char v_uv_b = vec_mergel(v_u, v_v); +- vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); +- vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); +- vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); +- vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); +- vec_st(v_uyvy_0, (i << 1), dst); +- vec_st(v_uyvy_1, (i << 1) + 16, dst); +- vec_st(v_uyvy_2, (i << 1) + 32, dst); +- vec_st(v_uyvy_3, (i << 1) + 48, dst); +- } +- if (i < width) { +- const unsigned int j = i >> 1; +- vector unsigned char v_y1 = vec_ld(i, ysrc); +- vector unsigned char v_u = vec_ld(j, usrc); +- vector unsigned char v_v = vec_ld(j, vsrc); +- vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); +- vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); +- vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); +- vec_st(v_uyvy_0, (i << 1), dst); +- vec_st(v_uyvy_1, (i << 1) + 16, dst); +- } +- if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { +- usrc += chromStride; +- vsrc += chromStride; +- } +- ysrc += lumStride; +- dst += dstStride; +- } +- return srcSliceH; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.c 2012-05-14 14:08:55.381361054 +0200 +@@ -94,6 +94,9 @@ + #include "libswscale/rgb2rgb.h" + #include "libswscale/swscale.h" + #include "libswscale/swscale_internal.h" ++#include "libavutil/cpu.h" ++#include "libavutil/pixdesc.h" ++#include "yuv2rgb_altivec.h" + + #undef PROFILE_THE_BEAST + #undef INC_SCALING +@@ -296,7 +299,7 @@ + vector signed short R1,G1,B1; \ + vector unsigned char R,G,B; \ + \ +- vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \ ++ const vector unsigned char *y1ivP, *y2ivP, *uivP, *vivP; \ + vector unsigned char align_perm; \ + \ + vector signed short \ +@@ -333,10 +336,10 @@ + \ + for (j=0;jsrcW; +- int h = srcSliceH; +- int i,j; +- int instrides_scl[3]; +- vector unsigned char y0,y1; +- +- vector signed char u,v; +- +- vector signed short Y0,Y1,Y2,Y3; +- vector signed short U,V; +- vector signed short vx,ux,uvx; +- vector signed short vx0,ux0,uvx0; +- vector signed short vx1,ux1,uvx1; +- vector signed short R0,G0,B0; +- vector signed short R1,G1,B1; +- vector unsigned char R,G,B; +- +- vector unsigned char *uivP, *vivP; +- vector unsigned char align_perm; +- +- vector signed short +- lCY = c->CY, +- lOY = c->OY, +- lCRV = c->CRV, +- lCBU = c->CBU, +- lCGU = c->CGU, +- lCGV = c->CGV; +- +- vector unsigned short lCSHIFT = c->CSHIFT; +- +- ubyte *y1i = in[0]; +- ubyte *y2i = in[0]+w; +- ubyte *ui = in[1]; +- ubyte *vi = in[2]; +- +- vector unsigned char *oute +- = (vector unsigned char *) +- (oplanes[0]+srcSliceY*outstrides[0]); +- vector unsigned char *outo +- = (vector unsigned char *) +- (oplanes[0]+srcSliceY*outstrides[0]+outstrides[0]); +- +- +- instrides_scl[0] = instrides[0]; +- instrides_scl[1] = instrides[1]-w/2; /* the loop moves ui by w/2 */ +- instrides_scl[2] = instrides[2]-w/2; /* the loop moves vi by w/2 */ +- +- +- for (i=0;i>15 */ +- ux = vec_sl (U, lCSHIFT); +- ux = vec_mradds (ux, lCBU, (vector signed short){0}); +- ux0 = vec_mergeh (ux,ux); +- ux1 = vec_mergel (ux,ux); +- +- /* vx = (CRV*(v<>15; */ +- vx = vec_sl (V, lCSHIFT); +- vx = vec_mradds (vx, lCRV, (vector signed short){0}); +- vx0 = vec_mergeh (vx,vx); +- vx1 = vec_mergel (vx,vx); +- /* uvx = ((CGU*u) + (CGV*v))>>15 */ +- uvx = vec_mradds (U, lCGU, (vector signed short){0}); +- uvx = vec_mradds (V, lCGV, uvx); +- uvx0 = vec_mergeh (uvx,uvx); +- uvx1 = vec_mergel (uvx,uvx); +- R0 = vec_add (Y0,vx0); +- G0 = vec_add (Y0,uvx0); +- B0 = vec_add (Y0,ux0); +- R1 = vec_add (Y1,vx1); +- G1 = vec_add (Y1,uvx1); +- B1 = vec_add (Y1,ux1); +- R = vec_packclp (R0,R1); +- G = vec_packclp (G0,G1); +- B = vec_packclp (B0,B1); +- +- out_argb(R,G,B,oute); +- R0 = vec_add (Y2,vx0); +- G0 = vec_add (Y2,uvx0); +- B0 = vec_add (Y2,ux0); +- R1 = vec_add (Y3,vx1); +- G1 = vec_add (Y3,uvx1); +- B1 = vec_add (Y3,ux1); +- R = vec_packclp (R0,R1); +- G = vec_packclp (G0,G1); +- B = vec_packclp (B0,B1); +- +- out_argb(R,G,B,outo); +- y1i += 16; +- y2i += 16; +- ui += 8; +- vi += 8; +- +- } +- +- outo += (outstrides[0])>>4; +- oute += (outstrides[0])>>4; +- +- ui += instrides_scl[1]; +- vi += instrides_scl[2]; +- y1i += instrides_scl[0]; +- y2i += instrides_scl[0]; +- } +- return srcSliceH; +-} +- +-#endif +- +- + DEFCSP420_CVT (yuv2_rgba, out_rgba) + DEFCSP420_CVT (yuv2_argb, out_argb) + DEFCSP420_CVT (yuv2_rgb24, out_rgb24) +@@ -692,7 +543,7 @@ + */ + SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c) + { +- if (!(c->flags & SWS_CPU_CAPS_ALTIVEC)) ++ if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC)) + return NULL; + + /* +@@ -776,11 +627,13 @@ + } + + +-void +-ff_yuv2packedX_altivec(SwsContext *c, +- const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, int dstW, int dstY) ++static av_always_inline void ++ff_yuv2packedX_altivec(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, ++ int dstW, int dstY, enum PixelFormat target) + { + int i,j; + vector signed short X,X0,X1,Y0,U0,V0,Y1,U1,V1,U,V; +@@ -791,7 +644,7 @@ + + vector signed short RND = vec_splat_s16(1<<3); + vector unsigned short SCL = vec_splat_u16(4); +- DECLARE_ALIGNED(16, unsigned long, scratch)[16]; ++ DECLARE_ALIGNED(16, unsigned int, scratch)[16]; + + vector signed short *YCoeffs, *CCoeffs; + +@@ -815,9 +668,9 @@ + V = RND; + /* extract 8 coeffs from U,V */ + for (j=0; jdstFormat) { ++ switch(target) { + case PIX_FMT_ABGR: out_abgr (R,G,B,out); break; + case PIX_FMT_BGRA: out_bgra (R,G,B,out); break; + case PIX_FMT_RGBA: out_rgba (R,G,B,out); break; +@@ -868,7 +721,7 @@ + static int printed_error_message; + if (!printed_error_message) { + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", +- sws_format_name(c->dstFormat)); ++ av_get_pix_fmt_name(c->dstFormat)); + printed_error_message=1; + } + return; +@@ -893,9 +746,9 @@ + V = RND; + /* extract 8 coeffs from U,V */ + for (j=0; jdstFormat) { ++ switch(target) { + case PIX_FMT_ABGR: out_abgr (R,G,B,nout); break; + case PIX_FMT_BGRA: out_bgra (R,G,B,nout); break; + case PIX_FMT_RGBA: out_rgba (R,G,B,nout); break; +@@ -943,7 +796,7 @@ + default: + /* Unreachable, I think. */ + av_log(c, AV_LOG_ERROR, "altivec_yuv2packedX doesn't support %s output\n", +- sws_format_name(c->dstFormat)); ++ av_get_pix_fmt_name(c->dstFormat)); + return; + } + +@@ -951,3 +804,23 @@ + } + + } ++ ++#define YUV2PACKEDX_WRAPPER(suffix, pixfmt) \ ++void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, const int16_t *lumFilter, \ ++ const int16_t **lumSrc, int lumFilterSize, \ ++ const int16_t *chrFilter, const int16_t **chrUSrc, \ ++ const int16_t **chrVSrc, int chrFilterSize, \ ++ const int16_t **alpSrc, uint8_t *dest, \ ++ int dstW, int dstY) \ ++{ \ ++ ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, \ ++ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ ++ alpSrc, dest, dstW, dstY, pixfmt); \ ++} ++ ++YUV2PACKEDX_WRAPPER(abgr, PIX_FMT_ABGR); ++YUV2PACKEDX_WRAPPER(bgra, PIX_FMT_BGRA); ++YUV2PACKEDX_WRAPPER(argb, PIX_FMT_ARGB); ++YUV2PACKEDX_WRAPPER(rgba, PIX_FMT_RGBA); ++YUV2PACKEDX_WRAPPER(rgb24, PIX_FMT_RGB24); ++YUV2PACKEDX_WRAPPER(bgr24, PIX_FMT_BGR24); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2rgb_altivec.h 2012-05-14 14:08:55.391361256 +0200 +@@ -0,0 +1,47 @@ ++/* ++ * AltiVec-enhanced yuv2yuvX ++ * ++ * Copyright (C) 2004 Romain Dolbeau ++ * based on the equivalent C code in swscale.c ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef SWSCALE_PPC_YUV2RGB_ALTIVEC_H ++#define SWSCALE_PPC_YUV2RGB_ALTIVEC_H ++ ++#define YUV2PACKEDX_HEADER(suffix) \ ++ void ff_yuv2 ## suffix ## _X_altivec(SwsContext *c, \ ++ const int16_t *lumFilter, \ ++ const int16_t **lumSrc, \ ++ int lumFilterSize, \ ++ const int16_t *chrFilter, \ ++ const int16_t **chrUSrc, \ ++ const int16_t **chrVSrc, \ ++ int chrFilterSize, \ ++ const int16_t **alpSrc, \ ++ uint8_t *dest, \ ++ int dstW, int dstY); ++ ++YUV2PACKEDX_HEADER(abgr); ++YUV2PACKEDX_HEADER(bgra); ++YUV2PACKEDX_HEADER(argb); ++YUV2PACKEDX_HEADER(rgba); ++YUV2PACKEDX_HEADER(rgb24); ++YUV2PACKEDX_HEADER(bgr24); ++ ++#endif /* SWSCALE_PPC_YUV2RGB_ALTIVEC_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2yuv_altivec.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2yuv_altivec.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/ppc/yuv2yuv_altivec.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/ppc/yuv2yuv_altivec.c 2012-05-14 14:08:55.392361276 +0200 +@@ -0,0 +1,191 @@ ++/* ++ * AltiVec-enhanced yuv-to-yuv convertion routines. ++ * ++ * Copyright (C) 2004 Romain Dolbeau ++ * based on the equivalent C code in swscale.c ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "config.h" ++#include "libswscale/swscale.h" ++#include "libswscale/swscale_internal.h" ++#include "libavutil/cpu.h" ++ ++static int yv12toyuy2_unscaled_altivec(SwsContext *c, const uint8_t* src[], ++ int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t* dstParam[], ++ int dstStride_a[]) ++{ ++ uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; ++ // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); ++ const uint8_t *ysrc = src[0]; ++ const uint8_t *usrc = src[1]; ++ const uint8_t *vsrc = src[2]; ++ const int width = c->srcW; ++ const int height = srcSliceH; ++ const int lumStride = srcStride[0]; ++ const int chromStride = srcStride[1]; ++ const int dstStride = dstStride_a[0]; ++ const vector unsigned char yperm = vec_lvsl(0, ysrc); ++ const int vertLumPerChroma = 2; ++ register unsigned int y; ++ ++ /* This code assumes: ++ ++ 1) dst is 16 bytes-aligned ++ 2) dstStride is a multiple of 16 ++ 3) width is a multiple of 16 ++ 4) lum & chrom stride are multiples of 8 ++ */ ++ ++ for (y=0; y> 1; ++ vector unsigned char v_yA = vec_ld(i, ysrc); ++ vector unsigned char v_yB = vec_ld(i + 16, ysrc); ++ vector unsigned char v_yC = vec_ld(i + 32, ysrc); ++ vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); ++ vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); ++ vector unsigned char v_uA = vec_ld(j, usrc); ++ vector unsigned char v_uB = vec_ld(j + 16, usrc); ++ vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); ++ vector unsigned char v_vA = vec_ld(j, vsrc); ++ vector unsigned char v_vB = vec_ld(j + 16, vsrc); ++ vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); ++ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); ++ vector unsigned char v_uv_b = vec_mergel(v_u, v_v); ++ vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); ++ vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); ++ vector unsigned char v_yuy2_2 = vec_mergeh(v_y2, v_uv_b); ++ vector unsigned char v_yuy2_3 = vec_mergel(v_y2, v_uv_b); ++ vec_st(v_yuy2_0, (i << 1), dst); ++ vec_st(v_yuy2_1, (i << 1) + 16, dst); ++ vec_st(v_yuy2_2, (i << 1) + 32, dst); ++ vec_st(v_yuy2_3, (i << 1) + 48, dst); ++ } ++ if (i < width) { ++ const unsigned int j = i >> 1; ++ vector unsigned char v_y1 = vec_ld(i, ysrc); ++ vector unsigned char v_u = vec_ld(j, usrc); ++ vector unsigned char v_v = vec_ld(j, vsrc); ++ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); ++ vector unsigned char v_yuy2_0 = vec_mergeh(v_y1, v_uv_a); ++ vector unsigned char v_yuy2_1 = vec_mergel(v_y1, v_uv_a); ++ vec_st(v_yuy2_0, (i << 1), dst); ++ vec_st(v_yuy2_1, (i << 1) + 16, dst); ++ } ++ if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { ++ usrc += chromStride; ++ vsrc += chromStride; ++ } ++ ysrc += lumStride; ++ dst += dstStride; ++ } ++ ++ return srcSliceH; ++} ++ ++static int yv12touyvy_unscaled_altivec(SwsContext *c, const uint8_t* src[], ++ int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t* dstParam[], ++ int dstStride_a[]) ++{ ++ uint8_t *dst=dstParam[0] + dstStride_a[0]*srcSliceY; ++ // yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); ++ const uint8_t *ysrc = src[0]; ++ const uint8_t *usrc = src[1]; ++ const uint8_t *vsrc = src[2]; ++ const int width = c->srcW; ++ const int height = srcSliceH; ++ const int lumStride = srcStride[0]; ++ const int chromStride = srcStride[1]; ++ const int dstStride = dstStride_a[0]; ++ const int vertLumPerChroma = 2; ++ const vector unsigned char yperm = vec_lvsl(0, ysrc); ++ register unsigned int y; ++ ++ /* This code assumes: ++ ++ 1) dst is 16 bytes-aligned ++ 2) dstStride is a multiple of 16 ++ 3) width is a multiple of 16 ++ 4) lum & chrom stride are multiples of 8 ++ */ ++ ++ for (y=0; y> 1; ++ vector unsigned char v_yA = vec_ld(i, ysrc); ++ vector unsigned char v_yB = vec_ld(i + 16, ysrc); ++ vector unsigned char v_yC = vec_ld(i + 32, ysrc); ++ vector unsigned char v_y1 = vec_perm(v_yA, v_yB, yperm); ++ vector unsigned char v_y2 = vec_perm(v_yB, v_yC, yperm); ++ vector unsigned char v_uA = vec_ld(j, usrc); ++ vector unsigned char v_uB = vec_ld(j + 16, usrc); ++ vector unsigned char v_u = vec_perm(v_uA, v_uB, vec_lvsl(j, usrc)); ++ vector unsigned char v_vA = vec_ld(j, vsrc); ++ vector unsigned char v_vB = vec_ld(j + 16, vsrc); ++ vector unsigned char v_v = vec_perm(v_vA, v_vB, vec_lvsl(j, vsrc)); ++ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); ++ vector unsigned char v_uv_b = vec_mergel(v_u, v_v); ++ vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); ++ vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); ++ vector unsigned char v_uyvy_2 = vec_mergeh(v_uv_b, v_y2); ++ vector unsigned char v_uyvy_3 = vec_mergel(v_uv_b, v_y2); ++ vec_st(v_uyvy_0, (i << 1), dst); ++ vec_st(v_uyvy_1, (i << 1) + 16, dst); ++ vec_st(v_uyvy_2, (i << 1) + 32, dst); ++ vec_st(v_uyvy_3, (i << 1) + 48, dst); ++ } ++ if (i < width) { ++ const unsigned int j = i >> 1; ++ vector unsigned char v_y1 = vec_ld(i, ysrc); ++ vector unsigned char v_u = vec_ld(j, usrc); ++ vector unsigned char v_v = vec_ld(j, vsrc); ++ vector unsigned char v_uv_a = vec_mergeh(v_u, v_v); ++ vector unsigned char v_uyvy_0 = vec_mergeh(v_uv_a, v_y1); ++ vector unsigned char v_uyvy_1 = vec_mergel(v_uv_a, v_y1); ++ vec_st(v_uyvy_0, (i << 1), dst); ++ vec_st(v_uyvy_1, (i << 1) + 16, dst); ++ } ++ if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { ++ usrc += chromStride; ++ vsrc += chromStride; ++ } ++ ysrc += lumStride; ++ dst += dstStride; ++ } ++ return srcSliceH; ++} ++ ++void ff_swscale_get_unscaled_altivec(SwsContext *c) ++{ ++ if ((av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) && !(c->srcW & 15) && ++ !(c->flags & SWS_BITEXACT) && c->srcFormat == PIX_FMT_YUV420P) { ++ enum PixelFormat dstFormat = c->dstFormat; ++ ++ // unscaled YV12 -> packed YUV, we want speed ++ if (dstFormat == PIX_FMT_YUYV422) ++ c->swScale= yv12toyuy2_unscaled_altivec; ++ else if (dstFormat == PIX_FMT_UYVY422) ++ c->swScale= yv12touyvy_unscaled_altivec; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb.c 2012-05-14 14:08:55.394361316 +0200 +@@ -24,117 +24,75 @@ + */ + #include + #include "config.h" +-#include "libavutil/x86_cpu.h" + #include "libavutil/bswap.h" + #include "rgb2rgb.h" + #include "swscale.h" + #include "swscale_internal.h" + +-#define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients +- +-void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb32to16)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb16to15)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +-void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); ++void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); ++void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); + + void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +- long width, long height, +- long lumStride, long chromStride, long srcStride); +-void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, +- long srcStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); ++void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, ++ int srcStride, int dstStride); + void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, +- long width, long height, long src1Stride, +- long src2Stride, long dstStride); ++ int width, int height, int src1Stride, ++ int src2Stride, int dstStride); + void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, + uint8_t *dst1, uint8_t *dst2, +- long width, long height, +- long srcStride1, long srcStride2, +- long dstStride1, long dstStride2); ++ int width, int height, ++ int srcStride1, int srcStride2, ++ int dstStride1, int dstStride2); + void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, + uint8_t *dst, +- long width, long height, +- long srcStride1, long srcStride2, +- long srcStride3, long dstStride); ++ int width, int height, ++ int srcStride1, int srcStride2, ++ int srcStride3, int dstStride); + void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); +- +- +-#if ARCH_X86 +-DECLARE_ASM_CONST(8, uint64_t, mmx_ff) = 0x00000000000000FFULL; +-DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL; +-DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL; +-DECLARE_ASM_CONST(8, uint64_t, mask32g) = 0x0000FF000000FF00ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask32r) = 0x00FF000000FF0000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask32a) = 0xFF000000FF000000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask32) = 0x00FFFFFF00FFFFFFULL; +-DECLARE_ASM_CONST(8, uint64_t, mask3216br) = 0x00F800F800F800F8ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask3216g) = 0x0000FC000000FC00ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask3215g) = 0x0000F8000000F800ULL; +-DECLARE_ASM_CONST(8, uint64_t, mul3216) = 0x2000000420000004ULL; +-DECLARE_ASM_CONST(8, uint64_t, mul3215) = 0x2000000820000008ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24b) = 0x00FF0000FF0000FFULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24g) = 0xFF0000FF0000FF00ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24r) = 0x0000FF0000FF0000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24l) = 0x0000000000FFFFFFULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24h) = 0x0000FFFFFF000000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24hh) = 0xffff000000000000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24hhh) = 0xffffffff00000000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask24hhhh) = 0xffffffffffff0000ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask15b) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ +-DECLARE_ASM_CONST(8, uint64_t, mask15rg) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ +-DECLARE_ASM_CONST(8, uint64_t, mask15s) = 0xFFE0FFE0FFE0FFE0ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask15g) = 0x03E003E003E003E0ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask15r) = 0x7C007C007C007C00ULL; +-#define mask16b mask15b +-DECLARE_ASM_CONST(8, uint64_t, mask16g) = 0x07E007E007E007E0ULL; +-DECLARE_ASM_CONST(8, uint64_t, mask16r) = 0xF800F800F800F800ULL; +-DECLARE_ASM_CONST(8, uint64_t, red_16mask) = 0x0000f8000000f800ULL; +-DECLARE_ASM_CONST(8, uint64_t, green_16mask) = 0x000007e0000007e0ULL; +-DECLARE_ASM_CONST(8, uint64_t, blue_16mask) = 0x0000001f0000001fULL; +-DECLARE_ASM_CONST(8, uint64_t, red_15mask) = 0x00007c0000007c00ULL; +-DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL; +-DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; +-#endif /* ARCH_X86 */ ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + + #define RGB2YUV_SHIFT 8 + #define BY ((int)( 0.098*(1<RGB16 original by Strepto/Astral +@@ -199,54 +116,17 @@ + 32-bit C version, and and&add trick by Michael Niedermayer + */ + +-void sws_rgb2rgb_init(int flags) +-{ +-#if HAVE_MMX2 || HAVE_AMD3DNOW || HAVE_MMX +- if (flags & SWS_CPU_CAPS_SSE2) +- rgb2rgb_init_SSE2(); +- else if (flags & SWS_CPU_CAPS_MMX2) +- rgb2rgb_init_MMX2(); +- else if (flags & SWS_CPU_CAPS_3DNOW) +- rgb2rgb_init_3DNOW(); +- else if (flags & SWS_CPU_CAPS_MMX) +- rgb2rgb_init_MMX(); +- else +-#endif /* HAVE_MMX2 || HAVE_AMD3DNOW || HAVE_MMX */ +- rgb2rgb_init_C(); +-} +- +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++void sws_rgb2rgb_init(void) + { +- sws_convertPalette8ToPacked32(src, dst, num_pixels, palette); ++ rgb2rgb_init_c(); ++ if (HAVE_MMX) ++ rgb2rgb_init_x86(); + } + +-void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size) + { +- sws_convertPalette8ToPacked24(src, dst, num_pixels, palette); +-} +- +-/** +- * Palette is assumed to contain BGR16, see rgb32to16 to convert the palette. +- */ +-void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) +-{ +- long i; +- for (i=0; i> 2; ++ int i; ++ int num_pixels = src_size >> 2; + for (i=0; i BGR24 (= B,G,R) */ +@@ -261,9 +141,9 @@ + } + } + +-void rgb24to32(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size) + { +- long i; ++ int i; + for (i=0; 3*i BGR32 (= A,R,G,B) */ +@@ -280,7 +160,7 @@ + } + } + +-void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; + uint8_t *d = dst; +@@ -291,19 +171,38 @@ + bgr = *s++; + #if HAVE_BIGENDIAN + *d++ = 255; +- *d++ = (bgr&0x1F)<<3; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0xF800)>>8; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); + #else +- *d++ = (bgr&0xF800)>>8; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0x1F)<<3; ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); + *d++ = 255; + #endif + } + } + +-void rgb16to24(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint16_t *end; ++ uint16_t *d = (uint16_t *)dst; ++ const uint16_t *s = (const uint16_t *)src; ++ uint16_t rgb, r, g, b; ++ end = s + src_size / 2; ++ while (s < end) { ++ rgb = *s++; ++ r = rgb & 0xF00; ++ g = rgb & 0x0F0; ++ b = rgb & 0x00F; ++ r = (r << 3) | ((r & 0x800) >> 1); ++ g = (g << 2) | ((g & 0x080) >> 2); ++ b = (b << 1) | ( b >> 3); ++ *d++ = r | g | b; ++ } ++} ++ ++void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; + uint8_t *d = dst; +@@ -312,16 +211,16 @@ + while (s < end) { + register uint16_t bgr; + bgr = *s++; +- *d++ = (bgr&0xF800)>>8; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0x1F)<<3; ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); + } + } + +-void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size) + { +- long i; +- long num_pixels = src_size >> 1; ++ int i; ++ int num_pixels = src_size >> 1; + + for (i=0; i> 1; ++ int i; ++ int num_pixels = src_size >> 1; + + for (i=0; i>2; +- *d++ = (bgr&0x7C00)>>7; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); + #else +- *d++ = (bgr&0x7C00)>>7; +- *d++ = (bgr&0x3E0)>>2; +- *d++ = (bgr&0x1F)<<3; ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); + *d++ = 255; + #endif + } + } + +-void rgb15to24(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; + uint8_t *d = dst; +@@ -372,16 +271,16 @@ + while (s < end) { + register uint16_t bgr; + bgr = *s++; +- *d++ = (bgr&0x7C00)>>7; +- *d++ = (bgr&0x3E0)>>2; +- *d++ = (bgr&0x1F)<<3; ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); + } + } + +-void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size) ++void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size) + { +- long i; +- long num_pixels = src_size >> 1; ++ int i; ++ int num_pixels = src_size >> 1; + + for (i=0; i> 1; ++ int i; ++ int num_pixels = src_size >> 1; + + for (i=0; i>3; +- b = (rgb&0xC0)>>6; +- dst[i] = ((b<<1)&0x07) | ((g&0x07)<<3) | ((r&0x03)<<6); ++ uint16_t *d = (uint16_t*)dst; ++ uint16_t *s = (uint16_t*)src; ++ int i; ++ int num_pixels = src_size >> 1; ++ ++ for (i = 0; i < num_pixels; i++) { ++ unsigned rgb = s[i]; ++ d[i] = (rgb << 8 | rgb & 0xF0 | rgb >> 8) & 0xFFF; + } + } + + #define DEFINE_SHUFFLE_BYTES(a, b, c, d) \ +-void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, long src_size) \ ++void shuffle_bytes_##a##b##c##d(const uint8_t *src, uint8_t *dst, int src_size) \ + { \ +- long i; \ ++ int i; \ + \ + for (i = 0; i < src_size; i+=4) { \ + dst[i + 0] = src[i + a]; \ +@@ -430,8 +327,8 @@ + } \ + } + +-DEFINE_SHUFFLE_BYTES(0, 3, 2, 1); +-DEFINE_SHUFFLE_BYTES(1, 2, 3, 0); +-DEFINE_SHUFFLE_BYTES(3, 0, 1, 2); +-DEFINE_SHUFFLE_BYTES(3, 2, 1, 0); ++DEFINE_SHUFFLE_BYTES(0, 3, 2, 1) ++DEFINE_SHUFFLE_BYTES(1, 2, 3, 0) ++DEFINE_SHUFFLE_BYTES(3, 0, 1, 2) ++DEFINE_SHUFFLE_BYTES(3, 2, 1, 0) + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb.h 2012-05-14 14:08:55.395361336 +0200 +@@ -32,97 +32,85 @@ + #include "libavutil/avutil.h" + + /* A full collection of RGB to RGB(BGR) converters */ +-extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb32to16) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb32to15) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb15to16) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb15to32) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb16to15) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb16to32) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb24to16) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb24to15) (const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size); +-extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size); +- +-void rgb24to32 (const uint8_t *src, uint8_t *dst, long src_size); +-void rgb32to24 (const uint8_t *src, uint8_t *dst, long src_size); +-void rgb16tobgr32(const uint8_t *src, uint8_t *dst, long src_size); +-void rgb16to24 (const uint8_t *src, uint8_t *dst, long src_size); +-void rgb16tobgr16(const uint8_t *src, uint8_t *dst, long src_size); +-void rgb16tobgr15(const uint8_t *src, uint8_t *dst, long src_size); +-void rgb15tobgr32(const uint8_t *src, uint8_t *dst, long src_size); +-void rgb15to24 (const uint8_t *src, uint8_t *dst, long src_size); +-void rgb15tobgr16(const uint8_t *src, uint8_t *dst, long src_size); +-void rgb15tobgr15(const uint8_t *src, uint8_t *dst, long src_size); +-void bgr8torgb8 (const uint8_t *src, uint8_t *dst, long src_size); +- +-void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, long src_size); +-void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, long src_size); +-void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, long src_size); +-void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, long src_size); +- +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-/* deprecated, use the public versions in swscale.h */ +-attribute_deprecated void palette8topacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +-attribute_deprecated void palette8topacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +- +-/* totally deprecated, please fix code that uses this */ +-attribute_deprecated void palette8torgb16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +-attribute_deprecated void palette8tobgr16(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); +-#endif +- +-/** +- * Height should be a multiple of 2 and width should be a multiple of 16. +- * (If this is a problem for anyone then tell me, and I will fix it.) +- * Chrominance data is only taken from every second line, others are ignored. +- * FIXME: Write high quality version. +- */ +-//void uyvytoyv12(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, ++extern void (*rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb16to15)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size); ++extern void (*rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size); ++ ++extern void (*shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size); ++ ++void rgb24to32(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb32to24(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb16tobgr32(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb16to24(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb16tobgr16(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb16tobgr15(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb15tobgr32(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb15to24(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb15tobgr16(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb15tobgr15(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb12tobgr12(const uint8_t *src, uint8_t *dst, int src_size); ++void rgb12to15(const uint8_t *src, uint8_t *dst, int src_size); ++ ++void shuffle_bytes_0321(const uint8_t *src, uint8_t *dst, int src_size); ++void shuffle_bytes_1230(const uint8_t *src, uint8_t *dst, int src_size); ++void shuffle_bytes_3012(const uint8_t *src, uint8_t *dst, int src_size); ++void shuffle_bytes_3210(const uint8_t *src, uint8_t *dst, int src_size); ++ ++void rgb24toyv12_c(const uint8_t *src, uint8_t *ydst, uint8_t *udst, ++ uint8_t *vdst, int width, int height, int lumStride, ++ int chromStride, int srcStride); + + /** + * Height should be a multiple of 2 and width should be a multiple of 16. + * (If this is a problem for anyone then tell me, and I will fix it.) + */ + extern void (*yv12toyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + + /** + * Width should be a multiple of 16. + */ + extern void (*yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + + /** + * Height should be a multiple of 2 and width should be a multiple of 16. + * (If this is a problem for anyone then tell me, and I will fix it.) + */ + extern void (*yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + + /** + * Height should be a multiple of 2 and width should be a multiple of 16. + * (If this is a problem for anyone then tell me, and I will fix it.) + */ + extern void (*yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + + /** + * Width should be a multiple of 16. + */ + extern void (*yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int dstStride); + + /** + * Height should be a multiple of 2 and width should be a multiple of 2. +@@ -131,41 +119,42 @@ + * FIXME: Write high quality version. + */ + extern void (*rgb24toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +- long width, long height, +- long lumStride, long chromStride, long srcStride); +-extern void (*planar2x)(const uint8_t *src, uint8_t *dst, long width, long height, +- long srcStride, long dstStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); ++extern void (*planar2x)(const uint8_t *src, uint8_t *dst, int width, int height, ++ int srcStride, int dstStride); + + extern void (*interleaveBytes)(const uint8_t *src1, const uint8_t *src2, uint8_t *dst, +- long width, long height, long src1Stride, +- long src2Stride, long dstStride); ++ int width, int height, int src1Stride, ++ int src2Stride, int dstStride); + + extern void (*vu9_to_vu12)(const uint8_t *src1, const uint8_t *src2, + uint8_t *dst1, uint8_t *dst2, +- long width, long height, +- long srcStride1, long srcStride2, +- long dstStride1, long dstStride2); ++ int width, int height, ++ int srcStride1, int srcStride2, ++ int dstStride1, int dstStride2); + + extern void (*yvu9_to_yuy2)(const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, + uint8_t *dst, +- long width, long height, +- long srcStride1, long srcStride2, +- long srcStride3, long dstStride); +- ++ int width, int height, ++ int srcStride1, int srcStride2, ++ int srcStride3, int dstStride); + + extern void (*uyvytoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + extern void (*uyvytoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + extern void (*yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); + extern void (*yuyvtoyuv422)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride); ++ int width, int height, ++ int lumStride, int chromStride, int srcStride); ++ ++void sws_rgb2rgb_init(void); + +-void sws_rgb2rgb_init(int flags); ++void rgb2rgb_init_x86(void); + + #endif /* SWSCALE_RGB2RGB_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/rgb2rgb_template.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/rgb2rgb_template.c 2012-05-14 14:08:55.404361516 +0200 +@@ -26,85 +26,13 @@ + + #include + +-#undef PREFETCH +-#undef MOVNTQ +-#undef EMMS +-#undef SFENCE +-#undef MMREG_SIZE +-#undef PAVGB +- +-#if COMPILE_TEMPLATE_SSE2 +-#define MMREG_SIZE 16 +-#else +-#define MMREG_SIZE 8 +-#endif +- +-#if COMPILE_TEMPLATE_AMD3DNOW +-#define PREFETCH "prefetch" +-#define PAVGB "pavgusb" +-#elif COMPILE_TEMPLATE_MMX2 +-#define PREFETCH "prefetchnta" +-#define PAVGB "pavgb" +-#else +-#define PREFETCH " # nop" +-#endif +- +-#if COMPILE_TEMPLATE_AMD3DNOW +-/* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ +-#define EMMS "femms" +-#else +-#define EMMS "emms" +-#endif +- +-#if COMPILE_TEMPLATE_MMX2 +-#define MOVNTQ "movntq" +-#define SFENCE "sfence" +-#else +-#define MOVNTQ "movq" +-#define SFENCE " # nop" +-#endif +- +-static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24tobgr32_c(const uint8_t *src, uint8_t *dst, int src_size) + { + uint8_t *dest = dst; + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- mm_end = end - 23; +- __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory"); +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "punpckldq 3%1, %%mm0 \n\t" +- "movd 6%1, %%mm1 \n\t" +- "punpckldq 9%1, %%mm1 \n\t" +- "movd 12%1, %%mm2 \n\t" +- "punpckldq 15%1, %%mm2 \n\t" +- "movd 18%1, %%mm3 \n\t" +- "punpckldq 21%1, %%mm3 \n\t" +- "por %%mm7, %%mm0 \n\t" +- "por %%mm7, %%mm1 \n\t" +- "por %%mm7, %%mm2 \n\t" +- "por %%mm7, %%mm3 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- MOVNTQ" %%mm1, 8%0 \n\t" +- MOVNTQ" %%mm2, 16%0 \n\t" +- MOVNTQ" %%mm3, 24%0" +- :"=m"(*dest) +- :"m"(*s) +- :"memory"); +- dest += 32; +- s += 24; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif ++ + while (s < end) { + #if HAVE_BIGENDIAN + /* RGB24 (= R,G,B) -> RGB32 (= A,B,G,R) */ +@@ -122,76 +50,14 @@ + } + } + +-#define STORE_BGR24_MMX \ +- "psrlq $8, %%mm2 \n\t" \ +- "psrlq $8, %%mm3 \n\t" \ +- "psrlq $8, %%mm6 \n\t" \ +- "psrlq $8, %%mm7 \n\t" \ +- "pand "MANGLE(mask24l)", %%mm0\n\t" \ +- "pand "MANGLE(mask24l)", %%mm1\n\t" \ +- "pand "MANGLE(mask24l)", %%mm4\n\t" \ +- "pand "MANGLE(mask24l)", %%mm5\n\t" \ +- "pand "MANGLE(mask24h)", %%mm2\n\t" \ +- "pand "MANGLE(mask24h)", %%mm3\n\t" \ +- "pand "MANGLE(mask24h)", %%mm6\n\t" \ +- "pand "MANGLE(mask24h)", %%mm7\n\t" \ +- "por %%mm2, %%mm0 \n\t" \ +- "por %%mm3, %%mm1 \n\t" \ +- "por %%mm6, %%mm4 \n\t" \ +- "por %%mm7, %%mm5 \n\t" \ +- \ +- "movq %%mm1, %%mm2 \n\t" \ +- "movq %%mm4, %%mm3 \n\t" \ +- "psllq $48, %%mm2 \n\t" \ +- "psllq $32, %%mm3 \n\t" \ +- "pand "MANGLE(mask24hh)", %%mm2\n\t" \ +- "pand "MANGLE(mask24hhh)", %%mm3\n\t" \ +- "por %%mm2, %%mm0 \n\t" \ +- "psrlq $16, %%mm1 \n\t" \ +- "psrlq $32, %%mm4 \n\t" \ +- "psllq $16, %%mm5 \n\t" \ +- "por %%mm3, %%mm1 \n\t" \ +- "pand "MANGLE(mask24hhhh)", %%mm5\n\t" \ +- "por %%mm5, %%mm4 \n\t" \ +- \ +- MOVNTQ" %%mm0, %0 \n\t" \ +- MOVNTQ" %%mm1, 8%0 \n\t" \ +- MOVNTQ" %%mm4, 16%0" +- +- +-static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb32tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) + { + uint8_t *dest = dst; + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif ++ + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- mm_end = end - 31; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movq %1, %%mm0 \n\t" +- "movq 8%1, %%mm1 \n\t" +- "movq 16%1, %%mm4 \n\t" +- "movq 24%1, %%mm5 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm1, %%mm3 \n\t" +- "movq %%mm4, %%mm6 \n\t" +- "movq %%mm5, %%mm7 \n\t" +- STORE_BGR24_MMX +- :"=m"(*dest) +- :"m"(*s) +- :"memory"); +- dest += 24; +- s += 32; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif ++ + while (s < end) { + #if HAVE_BIGENDIAN + /* RGB32 (= A,B,G,R) -> RGB24 (= R,G,B) */ +@@ -215,39 +81,13 @@ + MMX2, 3DNOW optimization by Nick Kurshev + 32-bit C version, and and&add trick by Michael Niedermayer + */ +-static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb15to16_c(const uint8_t *src, uint8_t *dst, int src_size) + { + register const uint8_t* s=src; + register uint8_t* d=dst; + register const uint8_t *end; + const uint8_t *mm_end; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s)); +- __asm__ volatile("movq %0, %%mm4"::"m"(mask15s)); +- mm_end = end - 15; +- while (s>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8); + } + } + +-static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb32tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_16mask),"m"(green_16mask)); +- mm_end = end - 15; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 4%1, %%mm3 \n\t" +- "punpckldq 8%1, %%mm0 \n\t" +- "punpckldq 12%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psllq $8, %%mm0 \n\t" +- "psllq $8, %%mm3 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "psrlq $5, %%mm1 \n\t" +- "psrlq $5, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $19, %%mm2 \n\t" +- "psrlq $19, %%mm5 \n\t" +- "pand %2, %%mm2 \n\t" +- "pand %2, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); +- d += 4; +- s += 16; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register int rgb = *(const uint32_t*)s; s += 4; + *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); + } + } + +-static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb32to15_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- mm_end = end - 15; +-#if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster) +- __asm__ volatile( +- "movq %3, %%mm5 \n\t" +- "movq %4, %%mm6 \n\t" +- "movq %5, %%mm7 \n\t" +- "jmp 2f \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- PREFETCH" 32(%1) \n\t" +- "movd (%1), %%mm0 \n\t" +- "movd 4(%1), %%mm3 \n\t" +- "punpckldq 8(%1), %%mm0 \n\t" +- "punpckldq 12(%1), %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "pand %%mm6, %%mm0 \n\t" +- "pand %%mm6, %%mm3 \n\t" +- "pmaddwd %%mm7, %%mm0 \n\t" +- "pmaddwd %%mm7, %%mm3 \n\t" +- "pand %%mm5, %%mm1 \n\t" +- "pand %%mm5, %%mm4 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "psrld $6, %%mm0 \n\t" +- "pslld $10, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, (%0) \n\t" +- "add $16, %1 \n\t" +- "add $8, %0 \n\t" +- "2: \n\t" +- "cmp %2, %1 \n\t" +- " jb 1b \n\t" +- : "+r" (d), "+r"(s) +- : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215) +- ); +-#else +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_15mask),"m"(green_15mask)); +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 4%1, %%mm3 \n\t" +- "punpckldq 8%1, %%mm0 \n\t" +- "punpckldq 12%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psrlq $3, %%mm0 \n\t" +- "psrlq $3, %%mm3 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %2, %%mm3 \n\t" +- "psrlq $6, %%mm1 \n\t" +- "psrlq $6, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $9, %%mm2 \n\t" +- "psrlq $9, %%mm5 \n\t" +- "pand %%mm7, %%mm2 \n\t" +- "pand %%mm7, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); +- d += 4; +- s += 16; +- } +-#endif +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register int rgb = *(const uint32_t*)s; s += 4; + *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); + } + } + +-static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb32tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_15mask),"m"(green_15mask)); +- mm_end = end - 15; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 4%1, %%mm3 \n\t" +- "punpckldq 8%1, %%mm0 \n\t" +- "punpckldq 12%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psllq $7, %%mm0 \n\t" +- "psllq $7, %%mm3 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "psrlq $6, %%mm1 \n\t" +- "psrlq $6, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $19, %%mm2 \n\t" +- "psrlq $19, %%mm5 \n\t" +- "pand %2, %%mm2 \n\t" +- "pand %2, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); +- d += 4; +- s += 16; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register int rgb = *(const uint32_t*)s; s += 4; + *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); + } + } + +-static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24tobgr16_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_16mask),"m"(green_16mask)); +- mm_end = end - 11; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 3%1, %%mm3 \n\t" +- "punpckldq 6%1, %%mm0 \n\t" +- "punpckldq 9%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psrlq $3, %%mm0 \n\t" +- "psrlq $3, %%mm3 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %2, %%mm3 \n\t" +- "psrlq $5, %%mm1 \n\t" +- "psrlq $5, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $8, %%mm2 \n\t" +- "psrlq $8, %%mm5 \n\t" +- "pand %%mm7, %%mm2 \n\t" +- "pand %%mm7, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); +- d += 4; +- s += 12; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + const int b = *s++; + const int g = *s++; +@@ -683,59 +185,12 @@ + } + } + +-static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24to16_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_16mask),"m"(green_16mask)); +- mm_end = end - 15; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 3%1, %%mm3 \n\t" +- "punpckldq 6%1, %%mm0 \n\t" +- "punpckldq 9%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psllq $8, %%mm0 \n\t" +- "psllq $8, %%mm3 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "psrlq $5, %%mm1 \n\t" +- "psrlq $5, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $19, %%mm2 \n\t" +- "psrlq $19, %%mm5 \n\t" +- "pand %2, %%mm2 \n\t" +- "pand %2, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); +- d += 4; +- s += 12; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + const int r = *s++; + const int g = *s++; +@@ -744,59 +199,12 @@ + } + } + +-static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24tobgr15_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_15mask),"m"(green_15mask)); +- mm_end = end - 11; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 3%1, %%mm3 \n\t" +- "punpckldq 6%1, %%mm0 \n\t" +- "punpckldq 9%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psrlq $3, %%mm0 \n\t" +- "psrlq $3, %%mm3 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %2, %%mm3 \n\t" +- "psrlq $6, %%mm1 \n\t" +- "psrlq $6, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $9, %%mm2 \n\t" +- "psrlq $9, %%mm5 \n\t" +- "pand %%mm7, %%mm2 \n\t" +- "pand %%mm7, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); +- d += 4; +- s += 12; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + const int b = *s++; + const int g = *s++; +@@ -805,59 +213,12 @@ + } + } + +-static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24to15_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint8_t *s = src; + const uint8_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint8_t *mm_end; +-#endif + uint16_t *d = (uint16_t *)dst; + end = s + src_size; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); +- __asm__ volatile( +- "movq %0, %%mm7 \n\t" +- "movq %1, %%mm6 \n\t" +- ::"m"(red_15mask),"m"(green_15mask)); +- mm_end = end - 15; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movd %1, %%mm0 \n\t" +- "movd 3%1, %%mm3 \n\t" +- "punpckldq 6%1, %%mm0 \n\t" +- "punpckldq 9%1, %%mm3 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm3, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "psllq $7, %%mm0 \n\t" +- "psllq $7, %%mm3 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "psrlq $6, %%mm1 \n\t" +- "psrlq $6, %%mm4 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "psrlq $19, %%mm2 \n\t" +- "psrlq $19, %%mm5 \n\t" +- "pand %2, %%mm2 \n\t" +- "pand %2, %%mm5 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm5, %%mm3 \n\t" +- "psllq $16, %%mm3 \n\t" +- "por %%mm3, %%mm0 \n\t" +- MOVNTQ" %%mm0, %0 \n\t" +- :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); +- d += 4; +- s += 12; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + const int r = *s++; + const int g = *s++; +@@ -866,422 +227,87 @@ + } + } + +-/* +- I use less accurate approximation here by simply left-shifting the input +- value and filling the low order bits with zeroes. This method improves PNG +- compression but this scheme cannot reproduce white exactly, since it does +- not generate an all-ones maximum value; the net effect is to darken the +- image slightly. +- +- The better method should be "left bit replication": +- +- 4 3 2 1 0 +- --------- +- 1 1 0 1 1 +- +- 7 6 5 4 3 2 1 0 +- ---------------- +- 1 1 0 1 1 1 1 0 +- |=======| |===| +- | leftmost bits repeated to fill open bits +- | +- original bits +-*/ +-static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb15tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint16_t *mm_end; +-#endif + uint8_t *d = dst; + const uint16_t *s = (const uint16_t*)src; + end = s + src_size/2; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- mm_end = end - 7; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movq %1, %%mm0 \n\t" +- "movq %1, %%mm1 \n\t" +- "movq %1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $2, %%mm1 \n\t" +- "psrlq $7, %%mm2 \n\t" +- "movq %%mm0, %%mm3 \n\t" +- "movq %%mm1, %%mm4 \n\t" +- "movq %%mm2, %%mm5 \n\t" +- "punpcklwd %5, %%mm0 \n\t" +- "punpcklwd %5, %%mm1 \n\t" +- "punpcklwd %5, %%mm2 \n\t" +- "punpckhwd %5, %%mm3 \n\t" +- "punpckhwd %5, %%mm4 \n\t" +- "punpckhwd %5, %%mm5 \n\t" +- "psllq $8, %%mm1 \n\t" +- "psllq $16, %%mm2 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "psllq $8, %%mm4 \n\t" +- "psllq $16, %%mm5 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm5, %%mm3 \n\t" +- +- "movq %%mm0, %%mm6 \n\t" +- "movq %%mm3, %%mm7 \n\t" +- +- "movq 8%1, %%mm0 \n\t" +- "movq 8%1, %%mm1 \n\t" +- "movq 8%1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $2, %%mm1 \n\t" +- "psrlq $7, %%mm2 \n\t" +- "movq %%mm0, %%mm3 \n\t" +- "movq %%mm1, %%mm4 \n\t" +- "movq %%mm2, %%mm5 \n\t" +- "punpcklwd %5, %%mm0 \n\t" +- "punpcklwd %5, %%mm1 \n\t" +- "punpcklwd %5, %%mm2 \n\t" +- "punpckhwd %5, %%mm3 \n\t" +- "punpckhwd %5, %%mm4 \n\t" +- "punpckhwd %5, %%mm5 \n\t" +- "psllq $8, %%mm1 \n\t" +- "psllq $16, %%mm2 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "psllq $8, %%mm4 \n\t" +- "psllq $16, %%mm5 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm5, %%mm3 \n\t" +- +- :"=m"(*d) +- :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r), "m"(mmx_null) +- :"memory"); +- /* borrowed 32 to 24 */ +- __asm__ volatile( +- "movq %%mm0, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "movq %%mm6, %%mm0 \n\t" +- "movq %%mm7, %%mm1 \n\t" +- +- "movq %%mm4, %%mm6 \n\t" +- "movq %%mm5, %%mm7 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm1, %%mm3 \n\t" +- +- STORE_BGR24_MMX +- +- :"=m"(*d) +- :"m"(*s) +- :"memory"); +- d += 24; +- s += 8; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register uint16_t bgr; + bgr = *s++; +- *d++ = (bgr&0x1F)<<3; +- *d++ = (bgr&0x3E0)>>2; +- *d++ = (bgr&0x7C00)>>7; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); + } + } + +-static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb16tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint16_t *mm_end; +-#endif + uint8_t *d = (uint8_t *)dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- mm_end = end - 7; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movq %1, %%mm0 \n\t" +- "movq %1, %%mm1 \n\t" +- "movq %1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $3, %%mm1 \n\t" +- "psrlq $8, %%mm2 \n\t" +- "movq %%mm0, %%mm3 \n\t" +- "movq %%mm1, %%mm4 \n\t" +- "movq %%mm2, %%mm5 \n\t" +- "punpcklwd %5, %%mm0 \n\t" +- "punpcklwd %5, %%mm1 \n\t" +- "punpcklwd %5, %%mm2 \n\t" +- "punpckhwd %5, %%mm3 \n\t" +- "punpckhwd %5, %%mm4 \n\t" +- "punpckhwd %5, %%mm5 \n\t" +- "psllq $8, %%mm1 \n\t" +- "psllq $16, %%mm2 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "psllq $8, %%mm4 \n\t" +- "psllq $16, %%mm5 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm5, %%mm3 \n\t" +- +- "movq %%mm0, %%mm6 \n\t" +- "movq %%mm3, %%mm7 \n\t" +- +- "movq 8%1, %%mm0 \n\t" +- "movq 8%1, %%mm1 \n\t" +- "movq 8%1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $3, %%mm1 \n\t" +- "psrlq $8, %%mm2 \n\t" +- "movq %%mm0, %%mm3 \n\t" +- "movq %%mm1, %%mm4 \n\t" +- "movq %%mm2, %%mm5 \n\t" +- "punpcklwd %5, %%mm0 \n\t" +- "punpcklwd %5, %%mm1 \n\t" +- "punpcklwd %5, %%mm2 \n\t" +- "punpckhwd %5, %%mm3 \n\t" +- "punpckhwd %5, %%mm4 \n\t" +- "punpckhwd %5, %%mm5 \n\t" +- "psllq $8, %%mm1 \n\t" +- "psllq $16, %%mm2 \n\t" +- "por %%mm1, %%mm0 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "psllq $8, %%mm4 \n\t" +- "psllq $16, %%mm5 \n\t" +- "por %%mm4, %%mm3 \n\t" +- "por %%mm5, %%mm3 \n\t" +- :"=m"(*d) +- :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null) +- :"memory"); +- /* borrowed 32 to 24 */ +- __asm__ volatile( +- "movq %%mm0, %%mm4 \n\t" +- "movq %%mm3, %%mm5 \n\t" +- "movq %%mm6, %%mm0 \n\t" +- "movq %%mm7, %%mm1 \n\t" +- +- "movq %%mm4, %%mm6 \n\t" +- "movq %%mm5, %%mm7 \n\t" +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm1, %%mm3 \n\t" +- +- STORE_BGR24_MMX +- +- :"=m"(*d) +- :"m"(*s) +- :"memory"); +- d += 24; +- s += 8; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register uint16_t bgr; + bgr = *s++; +- *d++ = (bgr&0x1F)<<3; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0xF800)>>8; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); + } + } + +-/* +- * mm0 = 00 B3 00 B2 00 B1 00 B0 +- * mm1 = 00 G3 00 G2 00 G1 00 G0 +- * mm2 = 00 R3 00 R2 00 R1 00 R0 +- * mm6 = FF FF FF FF FF FF FF FF +- * mm7 = 00 00 00 00 00 00 00 00 +- */ +-#define PACK_RGB32 \ +- "packuswb %%mm7, %%mm0 \n\t" /* 00 00 00 00 B3 B2 B1 B0 */ \ +- "packuswb %%mm7, %%mm1 \n\t" /* 00 00 00 00 G3 G2 G1 G0 */ \ +- "packuswb %%mm7, %%mm2 \n\t" /* 00 00 00 00 R3 R2 R1 R0 */ \ +- "punpcklbw %%mm1, %%mm0 \n\t" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \ +- "punpcklbw %%mm6, %%mm2 \n\t" /* FF R3 FF R2 FF R1 FF R0 */ \ +- "movq %%mm0, %%mm3 \n\t" \ +- "punpcklwd %%mm2, %%mm0 \n\t" /* FF R1 G1 B1 FF R0 G0 B0 */ \ +- "punpckhwd %%mm2, %%mm3 \n\t" /* FF R3 G3 B3 FF R2 G2 B2 */ \ +- MOVNTQ" %%mm0, %0 \n\t" \ +- MOVNTQ" %%mm3, 8%0 \n\t" \ +- +-static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb15to32_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint16_t *mm_end; +-#endif + uint8_t *d = dst; + const uint16_t *s = (const uint16_t *)src; + end = s + src_size/2; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); +- __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory"); +- mm_end = end - 3; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movq %1, %%mm0 \n\t" +- "movq %1, %%mm1 \n\t" +- "movq %1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $2, %%mm1 \n\t" +- "psrlq $7, %%mm2 \n\t" +- PACK_RGB32 +- :"=m"(*d) +- :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r) +- :"memory"); +- d += 16; +- s += 4; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register uint16_t bgr; + bgr = *s++; + #if HAVE_BIGENDIAN + *d++ = 255; +- *d++ = (bgr&0x7C00)>>7; +- *d++ = (bgr&0x3E0)>>2; +- *d++ = (bgr&0x1F)<<3; +-#else +- *d++ = (bgr&0x1F)<<3; +- *d++ = (bgr&0x3E0)>>2; +- *d++ = (bgr&0x7C00)>>7; ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++#else ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); + *d++ = 255; + #endif + } + } + +-static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb16to32_c(const uint8_t *src, uint8_t *dst, int src_size) + { + const uint16_t *end; +-#if COMPILE_TEMPLATE_MMX +- const uint16_t *mm_end; +-#endif + uint8_t *d = dst; + const uint16_t *s = (const uint16_t*)src; + end = s + src_size/2; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); +- __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); +- __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory"); +- mm_end = end - 3; +- while (s < mm_end) { +- __asm__ volatile( +- PREFETCH" 32%1 \n\t" +- "movq %1, %%mm0 \n\t" +- "movq %1, %%mm1 \n\t" +- "movq %1, %%mm2 \n\t" +- "pand %2, %%mm0 \n\t" +- "pand %3, %%mm1 \n\t" +- "pand %4, %%mm2 \n\t" +- "psllq $3, %%mm0 \n\t" +- "psrlq $3, %%mm1 \n\t" +- "psrlq $8, %%mm2 \n\t" +- PACK_RGB32 +- :"=m"(*d) +- :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r) +- :"memory"); +- d += 16; +- s += 4; +- } +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +-#endif + while (s < end) { + register uint16_t bgr; + bgr = *s++; + #if HAVE_BIGENDIAN + *d++ = 255; +- *d++ = (bgr&0xF800)>>8; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0x1F)<<3; +-#else +- *d++ = (bgr&0x1F)<<3; +- *d++ = (bgr&0x7E0)>>3; +- *d++ = (bgr&0xF800)>>8; ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++#else ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); + *d++ = 255; + #endif + } + } + +-static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void shuffle_bytes_2103_c(const uint8_t *src, uint8_t *dst, int src_size) + { +- x86_reg idx = 15 - src_size; ++ int idx = 15 - src_size; + const uint8_t *s = src-idx; + uint8_t *d = dst-idx; +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile( +- "test %0, %0 \n\t" +- "jns 2f \n\t" +- PREFETCH" (%1, %0) \n\t" +- "movq %3, %%mm7 \n\t" +- "pxor %4, %%mm7 \n\t" +- "movq %%mm7, %%mm6 \n\t" +- "pxor %5, %%mm7 \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- PREFETCH" 32(%1, %0) \n\t" +- "movq (%1, %0), %%mm0 \n\t" +- "movq 8(%1, %0), %%mm1 \n\t" +-# if COMPILE_TEMPLATE_MMX2 +- "pshufw $177, %%mm0, %%mm3 \n\t" +- "pshufw $177, %%mm1, %%mm5 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm6, %%mm3 \n\t" +- "pand %%mm7, %%mm1 \n\t" +- "pand %%mm6, %%mm5 \n\t" +- "por %%mm3, %%mm0 \n\t" +- "por %%mm5, %%mm1 \n\t" +-# else +- "movq %%mm0, %%mm2 \n\t" +- "movq %%mm1, %%mm4 \n\t" +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm6, %%mm2 \n\t" +- "pand %%mm7, %%mm1 \n\t" +- "pand %%mm6, %%mm4 \n\t" +- "movq %%mm2, %%mm3 \n\t" +- "movq %%mm4, %%mm5 \n\t" +- "pslld $16, %%mm2 \n\t" +- "psrld $16, %%mm3 \n\t" +- "pslld $16, %%mm4 \n\t" +- "psrld $16, %%mm5 \n\t" +- "por %%mm2, %%mm0 \n\t" +- "por %%mm4, %%mm1 \n\t" +- "por %%mm3, %%mm0 \n\t" +- "por %%mm5, %%mm1 \n\t" +-# endif +- MOVNTQ" %%mm0, (%2, %0) \n\t" +- MOVNTQ" %%mm1, 8(%2, %0) \n\t" +- "add $16, %0 \n\t" +- "js 1b \n\t" +- SFENCE" \n\t" +- EMMS" \n\t" +- "2: \n\t" +- : "+&r"(idx) +- : "r" (s), "r" (d), "m" (mask32b), "m" (mask32r), "m" (mmx_one) +- : "memory"); +-#endif + for (; idx<15; idx+=4) { + register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00; + v &= 0xff00ff; +@@ -1289,66 +315,9 @@ + } + } + +-static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, long src_size) ++static inline void rgb24tobgr24_c(const uint8_t *src, uint8_t *dst, int src_size) + { + unsigned i; +-#if COMPILE_TEMPLATE_MMX +- x86_reg mmx_size= 23 - src_size; +- __asm__ volatile ( +- "test %%"REG_a", %%"REG_a" \n\t" +- "jns 2f \n\t" +- "movq "MANGLE(mask24r)", %%mm5 \n\t" +- "movq "MANGLE(mask24g)", %%mm6 \n\t" +- "movq "MANGLE(mask24b)", %%mm7 \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- PREFETCH" 32(%1, %%"REG_a") \n\t" +- "movq (%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG +- "movq (%1, %%"REG_a"), %%mm1 \n\t" // BGR BGR BG +- "movq 2(%1, %%"REG_a"), %%mm2 \n\t" // R BGR BGR B +- "psllq $16, %%mm0 \n\t" // 00 BGR BGR +- "pand %%mm5, %%mm0 \n\t" +- "pand %%mm6, %%mm1 \n\t" +- "pand %%mm7, %%mm2 \n\t" +- "por %%mm0, %%mm1 \n\t" +- "por %%mm2, %%mm1 \n\t" +- "movq 6(%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG +- MOVNTQ" %%mm1, (%2, %%"REG_a") \n\t" // RGB RGB RG +- "movq 8(%1, %%"REG_a"), %%mm1 \n\t" // R BGR BGR B +- "movq 10(%1, %%"REG_a"), %%mm2 \n\t" // GR BGR BGR +- "pand %%mm7, %%mm0 \n\t" +- "pand %%mm5, %%mm1 \n\t" +- "pand %%mm6, %%mm2 \n\t" +- "por %%mm0, %%mm1 \n\t" +- "por %%mm2, %%mm1 \n\t" +- "movq 14(%1, %%"REG_a"), %%mm0 \n\t" // R BGR BGR B +- MOVNTQ" %%mm1, 8(%2, %%"REG_a") \n\t" // B RGB RGB R +- "movq 16(%1, %%"REG_a"), %%mm1 \n\t" // GR BGR BGR +- "movq 18(%1, %%"REG_a"), %%mm2 \n\t" // BGR BGR BG +- "pand %%mm6, %%mm0 \n\t" +- "pand %%mm7, %%mm1 \n\t" +- "pand %%mm5, %%mm2 \n\t" +- "por %%mm0, %%mm1 \n\t" +- "por %%mm2, %%mm1 \n\t" +- MOVNTQ" %%mm1, 16(%2, %%"REG_a") \n\t" +- "add $24, %%"REG_a" \n\t" +- " js 1b \n\t" +- "2: \n\t" +- : "+a" (mmx_size) +- : "r" (src-mmx_size), "r"(dst-mmx_size) +- ); +- +- __asm__ volatile(SFENCE:::"memory"); +- __asm__ volatile(EMMS:::"memory"); +- +- if (mmx_size==23) return; //finished, was multiple of 8 +- +- src+= src_size; +- dst+= src_size; +- src_size= 23-mmx_size; +- src-= src_size; +- dst-= src_size; +-#endif + for (i=0; i>1; ++ int y; ++ const int chromWidth = width >> 1; + for (y=0; y>1; ++ int y; ++ const int chromWidth = width >> 1; + for (y=0; yyuy2 +- + #if HAVE_FAST_64BIT + int i; + uint64_t *ldst = (uint64_t *) dst; +@@ -1585,7 +433,6 @@ + vc++; + } + #endif +-#endif + if ((y&(vertLumPerChroma-1)) == vertLumPerChroma-1) { + usrc += chromStride; + vsrc += chromStride; +@@ -1593,140 +440,63 @@ + ysrc += lumStride; + dst += dstStride; + } +-#if COMPILE_TEMPLATE_MMX +- __asm__(EMMS" \n\t" +- SFENCE" \n\t" +- :::"memory"); +-#endif + } + + /** + * Height should be a multiple of 2 and width should be a multiple of 16 + * (If this is a problem for anyone then tell me, and I will fix it.) + */ +-static inline void RENAME(yv12touyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride) ++static inline void yv12touyvy_c(const uint8_t *ysrc, const uint8_t *usrc, ++ const uint8_t *vsrc, uint8_t *dst, ++ int width, int height, ++ int lumStride, int chromStride, ++ int dstStride) + { + //FIXME interpolate chroma +- RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 2); ++ yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride, ++ chromStride, dstStride, 2); + } + + /** + * Width should be a multiple of 16. + */ +-static inline void RENAME(yuv422ptouyvy)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride) ++static inline void yuv422ptouyvy_c(const uint8_t *ysrc, const uint8_t *usrc, ++ const uint8_t *vsrc, uint8_t *dst, ++ int width, int height, ++ int lumStride, int chromStride, ++ int dstStride) + { +- RENAME(yuvPlanartouyvy)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1); ++ yuvPlanartouyvy_c(ysrc, usrc, vsrc, dst, width, height, lumStride, ++ chromStride, dstStride, 1); + } + + /** + * Width should be a multiple of 16. + */ +-static inline void RENAME(yuv422ptoyuy2)(const uint8_t *ysrc, const uint8_t *usrc, const uint8_t *vsrc, uint8_t *dst, +- long width, long height, +- long lumStride, long chromStride, long dstStride) ++static inline void yuv422ptoyuy2_c(const uint8_t *ysrc, const uint8_t *usrc, ++ const uint8_t *vsrc, uint8_t *dst, ++ int width, int height, ++ int lumStride, int chromStride, ++ int dstStride) + { +- RENAME(yuvPlanartoyuy2)(ysrc, usrc, vsrc, dst, width, height, lumStride, chromStride, dstStride, 1); ++ yuvPlanartoyuy2_c(ysrc, usrc, vsrc, dst, width, height, lumStride, ++ chromStride, dstStride, 1); + } + + /** + * Height should be a multiple of 2 and width should be a multiple of 16. + * (If this is a problem for anyone then tell me, and I will fix it.) + */ +-static inline void RENAME(yuy2toyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, +- long width, long height, +- long lumStride, long chromStride, long srcStride) ++static inline void yuy2toyv12_c(const uint8_t *src, uint8_t *ydst, ++ uint8_t *udst, uint8_t *vdst, ++ int width, int height, ++ int lumStride, int chromStride, ++ int srcStride) + { +- long y; +- const x86_reg chromWidth= width>>1; ++ int y; ++ const int chromWidth = width >> 1; + for (y=0; y>2; + dst[dstStride]= ( src[0] + 3*src[srcStride])>>2; +-#endif + + for (x=mmxSize-1; x>2; +@@ -1844,7 +553,6 @@ + } + + // last line +-#if 1 + dst[0]= src[0]; + + for (x=0; x>2; + } + dst[2*srcWidth-1]= src[srcWidth-1]; +-#else +- for (x=0; x>1; ++ int y; ++ const int chromWidth = width >> 1; + for (y=0; y>1; +-#if COMPILE_TEMPLATE_MMX +- for (y=0; y> 1; + y=0; +-#endif + for (; y>1); + uint8_t* d=dst1+dstStride1*y; + x=0; +-#if COMPILE_TEMPLATE_MMX +- for (;x>1); + uint8_t* d=dst2+dstStride2*y; + x=0; +-#if COMPILE_TEMPLATE_MMX +- for (;x>2); + uint8_t* d=dst+dstStride*y; + x=0; +-#if COMPILE_TEMPLATE_MMX +- for (;x>1; + dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1; +@@ -2698,47 +775,13 @@ + } + } + +-static void RENAME(extract_odd2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count) ++static void extract_odd2_c(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, ++ int count) + { + dst0+= count; + dst1+= count; + src += 4*count; + count= - count; +-#if COMPILE_TEMPLATE_MMX +- if(count <= -8) { +- count += 7; +- __asm__ volatile( +- "pcmpeqw %%mm7, %%mm7 \n\t" +- "psrlw $8, %%mm7 \n\t" +- "1: \n\t" +- "movq -28(%1, %0, 4), %%mm0 \n\t" +- "movq -20(%1, %0, 4), %%mm1 \n\t" +- "movq -12(%1, %0, 4), %%mm2 \n\t" +- "movq -4(%1, %0, 4), %%mm3 \n\t" +- "psrlw $8, %%mm0 \n\t" +- "psrlw $8, %%mm1 \n\t" +- "psrlw $8, %%mm2 \n\t" +- "psrlw $8, %%mm3 \n\t" +- "packuswb %%mm1, %%mm0 \n\t" +- "packuswb %%mm3, %%mm2 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm2, %%mm3 \n\t" +- "psrlw $8, %%mm0 \n\t" +- "psrlw $8, %%mm2 \n\t" +- "pand %%mm7, %%mm1 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "packuswb %%mm2, %%mm0 \n\t" +- "packuswb %%mm3, %%mm1 \n\t" +- MOVNTQ" %%mm0,- 7(%3, %0) \n\t" +- MOVNTQ" %%mm1,- 7(%2, %0) \n\t" +- "add $8, %0 \n\t" +- " js 1b \n\t" +- : "+r"(count) +- : "r"(src), "r"(dst0), "r"(dst1) +- ); +- count -= 7; +- } +-#endif + src++; + while(count<0) { + dst0[count]= src[4*count+0]; +@@ -2747,52 +790,14 @@ + } + } + +-static void RENAME(extract_odd2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count) ++static void extract_odd2avg_c(const uint8_t *src0, const uint8_t *src1, ++ uint8_t *dst0, uint8_t *dst1, int count) + { + dst0 += count; + dst1 += count; + src0 += 4*count; + src1 += 4*count; + count= - count; +-#ifdef PAVGB +- if(count <= -8) { +- count += 7; +- __asm__ volatile( +- "pcmpeqw %%mm7, %%mm7 \n\t" +- "psrlw $8, %%mm7 \n\t" +- "1: \n\t" +- "movq -28(%1, %0, 4), %%mm0 \n\t" +- "movq -20(%1, %0, 4), %%mm1 \n\t" +- "movq -12(%1, %0, 4), %%mm2 \n\t" +- "movq -4(%1, %0, 4), %%mm3 \n\t" +- PAVGB" -28(%2, %0, 4), %%mm0 \n\t" +- PAVGB" -20(%2, %0, 4), %%mm1 \n\t" +- PAVGB" -12(%2, %0, 4), %%mm2 \n\t" +- PAVGB" - 4(%2, %0, 4), %%mm3 \n\t" +- "psrlw $8, %%mm0 \n\t" +- "psrlw $8, %%mm1 \n\t" +- "psrlw $8, %%mm2 \n\t" +- "psrlw $8, %%mm3 \n\t" +- "packuswb %%mm1, %%mm0 \n\t" +- "packuswb %%mm3, %%mm2 \n\t" +- "movq %%mm0, %%mm1 \n\t" +- "movq %%mm2, %%mm3 \n\t" +- "psrlw $8, %%mm0 \n\t" +- "psrlw $8, %%mm2 \n\t" +- "pand %%mm7, %%mm1 \n\t" +- "pand %%mm7, %%mm3 \n\t" +- "packuswb %%mm2, %%mm0 \n\t" +- "packuswb %%mm3, %%mm1 \n\t" +- MOVNTQ" %%mm0,- 7(%4, %0) \n\t" +- MOVNTQ" %%mm1,- 7(%3, %0) \n\t" +- "add $8, %0 \n\t" +- " js 1b \n\t" +- : "+r"(count) +- : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1) +- ); +- count -= 7; +- } +-#endif + src0++; + src1++; + while(count<0) { +@@ -2802,17 +807,17 @@ + } + } + +-static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, +- long width, long height, +- long lumStride, long chromStride, long srcStride) ++static void yuyvtoyuv420_c(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, ++ const uint8_t *src, int width, int height, ++ int lumStride, int chromStride, int srcStride) + { +- long y; +- const long chromWidth= -((-width)>>1); ++ int y; ++ const int chromWidth= -((-width)>>1); + + for (y=0; y>1); ++ int y; ++ const int chromWidth= -((-width)>>1); + + for (y=0; y>1); ++ int y; ++ const int chromWidth= -((-width)>>1); + + for (y=0; y>1); ++ int y; ++ const int chromWidth= -((-width)>>1); + + for (y=0; y ++ * Copyright (C) 2001-2011 Michael Niedermayer + * + * This file is part of FFmpeg. + * +@@ -18,39 +18,6 @@ + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +-/* +- supported Input formats: YV12, I420/IYUV, YUY2, UYVY, BGR32, BGR32_1, BGR24, BGR16, BGR15, RGB32, RGB32_1, RGB24, Y8/Y800, YVU9/IF09, PAL8 +- supported output formats: YV12, I420/IYUV, YUY2, UYVY, {BGR,RGB}{1,4,8,15,16,24,32}, Y8/Y800, YVU9/IF09 +- {BGR,RGB}{1,4,8,15,16} support dithering +- +- unscaled special converters (YV12=I420=IYUV, Y800=Y8) +- YV12 -> {BGR,RGB}{1,4,8,12,15,16,24,32} +- x -> x +- YUV9 -> YV12 +- YUV9/YV12 -> Y800 +- Y800 -> YUV9/YV12 +- BGR24 -> BGR32 & RGB24 -> RGB32 +- BGR32 -> BGR24 & RGB32 -> RGB24 +- BGR15 -> BGR16 +-*/ +- +-/* +-tested special converters (most are tested actually, but I did not write it down ...) +- YV12 -> BGR12/BGR16 +- YV12 -> YV12 +- BGR15 -> BGR16 +- BGR16 -> BGR16 +- YVU9 -> YV12 +- +-untested special converters +- YV12/I420 -> BGR15/BGR24/BGR32 (it is the yuv2rgb stuff, so it should be OK) +- YV12/I420 -> YV12/I420 +- YUY2/BGR15/BGR24/BGR32/RGB24/RGB32 -> same format +- BGR24 -> BGR32 & RGB24 -> RGB32 +- BGR32 -> BGR24 & RGB32 -> RGB24 +- BGR24 -> YV12 +-*/ +- + #include + #include + #include +@@ -60,31 +27,14 @@ + #include "swscale.h" + #include "swscale_internal.h" + #include "rgb2rgb.h" ++#include "libavutil/avassert.h" + #include "libavutil/intreadwrite.h" +-#include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" + #include "libavutil/avutil.h" + #include "libavutil/mathematics.h" + #include "libavutil/bswap.h" + #include "libavutil/pixdesc.h" + +-#undef MOVNTQ +-#undef PAVGB +- +-//#undef HAVE_MMX2 +-//#define HAVE_AMD3DNOW +-//#undef HAVE_MMX +-//#undef ARCH_X86 +-#define DITHER1XBPP +- +-#define FAST_BGR2YV12 // use 7 bit coefficients instead of 15 bit +- +-#define isPacked(x) ( \ +- (x)==PIX_FMT_PAL8 \ +- || (x)==PIX_FMT_YUYV422 \ +- || (x)==PIX_FMT_UYVY422 \ +- || (x)==PIX_FMT_Y400A \ +- || isAnyRGB(x) \ +- ) + + #define RGB2YUV_SHIFT 15 + #define BY ( (int)(0.114*219/255*(1<BGR scaler + */ + +-#if ARCH_X86 +-DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; +-DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; +-DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; +-DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL; +-DECLARE_ASM_CONST(8, uint64_t, bm00001111)=0x00000000FFFFFFFFLL; +-DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL; +-DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL; +-DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL; +- +-const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = { +- 0x0103010301030103LL, +- 0x0200020002000200LL,}; +- +-const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = { +- 0x0602060206020602LL, +- 0x0004000400040004LL,}; +- +-DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL; +-DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL; +-DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL; +-DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL; +-DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL; +-DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL; +- +-DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL; +-DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL; +-DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL; +- +-#ifdef FAST_BGR2YV12 +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL; +-#else +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL; +-#endif /* FAST_BGR2YV12 */ +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL; +-DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; +- +-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY1Coeff) = 0x0C88000040870C88ULL; +-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY2Coeff) = 0x20DE4087000020DEULL; +-DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY1Coeff) = 0x20DE0000408720DEULL; +-DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY2Coeff) = 0x0C88408700000C88ULL; +-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008400000084000ULL; +- +-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV)[2][4] = { +- {0x38380000DAC83838ULL, 0xECFFDAC80000ECFFULL, 0xF6E40000D0E3F6E4ULL, 0x3838D0E300003838ULL}, +- {0xECFF0000DAC8ECFFULL, 0x3838DAC800003838ULL, 0x38380000D0E33838ULL, 0xF6E4D0E30000F6E4ULL}, +-}; +- +-DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040400000404000ULL; +- +-#endif /* ARCH_X86 */ +- + DECLARE_ALIGNED(8, static const uint8_t, dither_2x2_4)[2][8]={ + { 1, 3, 1, 3, 1, 3, 1, 3, }, + { 2, 0, 2, 0, 2, 0, 2, 0, }, +@@ -267,1796 +149,2906 @@ + { 77, 23, 60, 15, 72, 21, 56, 14, }, + }; + #endif ++DECLARE_ALIGNED(8, const uint8_t, dither_8x8_128)[8][8] = { ++{ 36, 68, 60, 92, 34, 66, 58, 90,}, ++{ 100, 4,124, 28, 98, 2,122, 26,}, ++{ 52, 84, 44, 76, 50, 82, 42, 74,}, ++{ 116, 20,108, 12,114, 18,106, 10,}, ++{ 32, 64, 56, 88, 38, 70, 62, 94,}, ++{ 96, 0,120, 24,102, 6,126, 30,}, ++{ 48, 80, 40, 72, 54, 86, 46, 78,}, ++{ 112, 16,104, 8,118, 22,110, 14,}, ++}; ++DECLARE_ALIGNED(8, const uint8_t, ff_sws_pb_64)[8] = ++{ 64, 64, 64, 64, 64, 64, 64, 64 }; ++ ++DECLARE_ALIGNED(8, const uint8_t, dithers)[8][8][8]={ ++{ ++ { 0, 1, 0, 1, 0, 1, 0, 1,}, ++ { 1, 0, 1, 0, 1, 0, 1, 0,}, ++ { 0, 1, 0, 1, 0, 1, 0, 1,}, ++ { 1, 0, 1, 0, 1, 0, 1, 0,}, ++ { 0, 1, 0, 1, 0, 1, 0, 1,}, ++ { 1, 0, 1, 0, 1, 0, 1, 0,}, ++ { 0, 1, 0, 1, 0, 1, 0, 1,}, ++ { 1, 0, 1, 0, 1, 0, 1, 0,}, ++},{ ++ { 1, 2, 1, 2, 1, 2, 1, 2,}, ++ { 3, 0, 3, 0, 3, 0, 3, 0,}, ++ { 1, 2, 1, 2, 1, 2, 1, 2,}, ++ { 3, 0, 3, 0, 3, 0, 3, 0,}, ++ { 1, 2, 1, 2, 1, 2, 1, 2,}, ++ { 3, 0, 3, 0, 3, 0, 3, 0,}, ++ { 1, 2, 1, 2, 1, 2, 1, 2,}, ++ { 3, 0, 3, 0, 3, 0, 3, 0,}, ++},{ ++ { 2, 4, 3, 5, 2, 4, 3, 5,}, ++ { 6, 0, 7, 1, 6, 0, 7, 1,}, ++ { 3, 5, 2, 4, 3, 5, 2, 4,}, ++ { 7, 1, 6, 0, 7, 1, 6, 0,}, ++ { 2, 4, 3, 5, 2, 4, 3, 5,}, ++ { 6, 0, 7, 1, 6, 0, 7, 1,}, ++ { 3, 5, 2, 4, 3, 5, 2, 4,}, ++ { 7, 1, 6, 0, 7, 1, 6, 0,}, ++},{ ++ { 4, 8, 7, 11, 4, 8, 7, 11,}, ++ { 12, 0, 15, 3, 12, 0, 15, 3,}, ++ { 6, 10, 5, 9, 6, 10, 5, 9,}, ++ { 14, 2, 13, 1, 14, 2, 13, 1,}, ++ { 4, 8, 7, 11, 4, 8, 7, 11,}, ++ { 12, 0, 15, 3, 12, 0, 15, 3,}, ++ { 6, 10, 5, 9, 6, 10, 5, 9,}, ++ { 14, 2, 13, 1, 14, 2, 13, 1,}, ++},{ ++ { 9, 17, 15, 23, 8, 16, 14, 22,}, ++ { 25, 1, 31, 7, 24, 0, 30, 6,}, ++ { 13, 21, 11, 19, 12, 20, 10, 18,}, ++ { 29, 5, 27, 3, 28, 4, 26, 2,}, ++ { 8, 16, 14, 22, 9, 17, 15, 23,}, ++ { 24, 0, 30, 6, 25, 1, 31, 7,}, ++ { 12, 20, 10, 18, 13, 21, 11, 19,}, ++ { 28, 4, 26, 2, 29, 5, 27, 3,}, ++},{ ++ { 18, 34, 30, 46, 17, 33, 29, 45,}, ++ { 50, 2, 62, 14, 49, 1, 61, 13,}, ++ { 26, 42, 22, 38, 25, 41, 21, 37,}, ++ { 58, 10, 54, 6, 57, 9, 53, 5,}, ++ { 16, 32, 28, 44, 19, 35, 31, 47,}, ++ { 48, 0, 60, 12, 51, 3, 63, 15,}, ++ { 24, 40, 20, 36, 27, 43, 23, 39,}, ++ { 56, 8, 52, 4, 59, 11, 55, 7,}, ++},{ ++ { 18, 34, 30, 46, 17, 33, 29, 45,}, ++ { 50, 2, 62, 14, 49, 1, 61, 13,}, ++ { 26, 42, 22, 38, 25, 41, 21, 37,}, ++ { 58, 10, 54, 6, 57, 9, 53, 5,}, ++ { 16, 32, 28, 44, 19, 35, 31, 47,}, ++ { 48, 0, 60, 12, 51, 3, 63, 15,}, ++ { 24, 40, 20, 36, 27, 43, 23, 39,}, ++ { 56, 8, 52, 4, 59, 11, 55, 7,}, ++},{ ++ { 36, 68, 60, 92, 34, 66, 58, 90,}, ++ { 100, 4,124, 28, 98, 2,122, 26,}, ++ { 52, 84, 44, 76, 50, 82, 42, 74,}, ++ { 116, 20,108, 12,114, 18,106, 10,}, ++ { 32, 64, 56, 88, 38, 70, 62, 94,}, ++ { 96, 0,120, 24,102, 6,126, 30,}, ++ { 48, 80, 40, 72, 54, 86, 46, 78,}, ++ { 112, 16,104, 8,118, 22,110, 14,}, ++}}; ++ ++static const uint8_t flat64[8]={64,64,64,64,64,64,64,64}; ++ ++const uint16_t dither_scale[15][16]={ ++{ 2, 3, 3, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,}, ++{ 2, 3, 7, 7, 13, 13, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,}, ++{ 3, 3, 4, 15, 15, 29, 57, 57, 57, 113, 113, 113, 113, 113, 113, 113,}, ++{ 3, 4, 4, 5, 31, 31, 61, 121, 241, 241, 241, 241, 481, 481, 481, 481,}, ++{ 3, 4, 5, 5, 6, 63, 63, 125, 249, 497, 993, 993, 993, 993, 993, 1985,}, ++{ 3, 5, 6, 6, 6, 7, 127, 127, 253, 505, 1009, 2017, 4033, 4033, 4033, 4033,}, ++{ 3, 5, 6, 7, 7, 7, 8, 255, 255, 509, 1017, 2033, 4065, 8129,16257,16257,}, ++{ 3, 5, 6, 8, 8, 8, 8, 9, 511, 511, 1021, 2041, 4081, 8161,16321,32641,}, ++{ 3, 5, 7, 8, 9, 9, 9, 9, 10, 1023, 1023, 2045, 4089, 8177,16353,32705,}, ++{ 3, 5, 7, 8, 10, 10, 10, 10, 10, 11, 2047, 2047, 4093, 8185,16369,32737,}, ++{ 3, 5, 7, 8, 10, 11, 11, 11, 11, 11, 12, 4095, 4095, 8189,16377,32753,}, ++{ 3, 5, 7, 9, 10, 12, 12, 12, 12, 12, 12, 13, 8191, 8191,16381,32761,}, ++{ 3, 5, 7, 9, 10, 12, 13, 13, 13, 13, 13, 13, 14,16383,16383,32765,}, ++{ 3, 5, 7, 9, 10, 12, 14, 14, 14, 14, 14, 14, 14, 15,32767,32767,}, ++{ 3, 5, 7, 9, 11, 12, 14, 15, 15, 15, 15, 15, 15, 15, 16,65535,}, ++}; ++ ++#define output_pixel(pos, val, bias, signedness) \ ++ if (big_endian) { \ ++ AV_WB16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \ ++ } else { \ ++ AV_WL16(pos, bias + av_clip_ ## signedness ## 16(val >> shift)); \ ++ } ++ ++static av_always_inline void ++yuv2plane1_16_c_template(const int32_t *src, uint16_t *dest, int dstW, ++ int big_endian, int output_bits) ++{ ++ int i; ++ int shift = 3; ++ av_assert0(output_bits == 16); ++ ++ for (i = 0; i < dstW; i++) { ++ int val = src[i] + (1 << (shift - 1)); ++ output_pixel(&dest[i], val, 0, uint); ++ } ++} + +-static av_always_inline void yuv2yuvX16inC_template(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint16_t *dest, uint16_t *uDest, uint16_t *vDest, uint16_t *aDest, +- int dstW, int chrDstW, int big_endian) ++static av_always_inline void ++yuv2planeX_16_c_template(const int16_t *filter, int filterSize, ++ const int32_t **src, uint16_t *dest, int dstW, ++ int big_endian, int output_bits) + { +- //FIXME Optimize (just quickly written not optimized..) + int i; ++ int shift = 15; ++ av_assert0(output_bits == 16); + + for (i = 0; i < dstW; i++) { +- int val = 1 << 10; ++ int val = 1 << (shift - 1); + int j; + +- for (j = 0; j < lumFilterSize; j++) +- val += lumSrc[j][i] * lumFilter[j]; ++ /* range of val is [0,0x7FFFFFFF], so 31 bits, but with lanczos/spline ++ * filters (or anything with negative coeffs, the range can be slightly ++ * wider in both directions. To account for this overflow, we subtract ++ * a constant so it always fits in the signed range (assuming a ++ * reasonable filterSize), and re-add that at the end. */ ++ val -= 0x40000000; ++ for (j = 0; j < filterSize; j++) ++ val += src[j][i] * filter[j]; + +- if (big_endian) { +- AV_WB16(&dest[i], av_clip_uint16(val >> 11)); +- } else { +- AV_WL16(&dest[i], av_clip_uint16(val >> 11)); +- } ++ output_pixel(&dest[i], val, 0x8000, int); + } ++} + +- if (uDest) { +- for (i = 0; i < chrDstW; i++) { +- int u = 1 << 10; +- int v = 1 << 10; +- int j; +- +- for (j = 0; j < chrFilterSize; j++) { +- u += chrSrc[j][i ] * chrFilter[j]; +- v += chrSrc[j][i + VOFW] * chrFilter[j]; +- } ++#undef output_pixel + +- if (big_endian) { +- AV_WB16(&uDest[i], av_clip_uint16(u >> 11)); +- AV_WB16(&vDest[i], av_clip_uint16(v >> 11)); +- } else { +- AV_WL16(&uDest[i], av_clip_uint16(u >> 11)); +- AV_WL16(&vDest[i], av_clip_uint16(v >> 11)); +- } +- } ++#define output_pixel(pos, val) \ ++ if (big_endian) { \ ++ AV_WB16(pos, av_clip_uintp2(val >> shift, output_bits)); \ ++ } else { \ ++ AV_WL16(pos, av_clip_uintp2(val >> shift, output_bits)); \ + } + +- if (CONFIG_SWSCALE_ALPHA && aDest) { +- for (i = 0; i < dstW; i++) { +- int val = 1 << 10; +- int j; +- +- for (j = 0; j < lumFilterSize; j++) +- val += alpSrc[j][i] * lumFilter[j]; ++static av_always_inline void ++yuv2plane1_10_c_template(const int16_t *src, uint16_t *dest, int dstW, ++ int big_endian, int output_bits) ++{ ++ int i; ++ int shift = 15 - output_bits; + +- if (big_endian) { +- AV_WB16(&aDest[i], av_clip_uint16(val >> 11)); +- } else { +- AV_WL16(&aDest[i], av_clip_uint16(val >> 11)); +- } +- } ++ for (i = 0; i < dstW; i++) { ++ int val = src[i] + (1 << (shift - 1)); ++ output_pixel(&dest[i], val); + } + } + +-static inline void yuv2yuvX16inC(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint16_t *dest, uint16_t *uDest, uint16_t *vDest, uint16_t *aDest, int dstW, int chrDstW, +- enum PixelFormat dstFormat) +-{ +- if (isBE(dstFormat)) { +- yuv2yuvX16inC_template(lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- alpSrc, +- dest, uDest, vDest, aDest, +- dstW, chrDstW, 1); +- } else { +- yuv2yuvX16inC_template(lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- alpSrc, +- dest, uDest, vDest, aDest, +- dstW, chrDstW, 0); ++static av_always_inline void ++yuv2planeX_10_c_template(const int16_t *filter, int filterSize, ++ const int16_t **src, uint16_t *dest, int dstW, ++ int big_endian, int output_bits) ++{ ++ int i; ++ int shift = 11 + 16 - output_bits; ++ ++ for (i = 0; i < dstW; i++) { ++ int val = 1 << (shift - 1); ++ int j; ++ ++ for (j = 0; j < filterSize; j++) ++ val += src[j][i] * filter[j]; ++ ++ output_pixel(&dest[i], val); + } + } + +-static inline void yuv2yuvXinC(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, int dstW, int chrDstW) ++#undef output_pixel ++ ++#define yuv2NBPS(bits, BE_LE, is_be, template_size, typeX_t) \ ++static void yuv2plane1_ ## bits ## BE_LE ## _c(const int16_t *src, \ ++ uint8_t *dest, int dstW, \ ++ const uint8_t *dither, int offset)\ ++{ \ ++ yuv2plane1_ ## template_size ## _c_template((const typeX_t *) src, \ ++ (uint16_t *) dest, dstW, is_be, bits); \ ++}\ ++static void yuv2planeX_ ## bits ## BE_LE ## _c(const int16_t *filter, int filterSize, \ ++ const int16_t **src, uint8_t *dest, int dstW, \ ++ const uint8_t *dither, int offset)\ ++{ \ ++ yuv2planeX_## template_size ## _c_template(filter, \ ++ filterSize, (const typeX_t **) src, \ ++ (uint16_t *) dest, dstW, is_be, bits); \ ++} ++yuv2NBPS( 9, BE, 1, 10, int16_t) ++yuv2NBPS( 9, LE, 0, 10, int16_t) ++yuv2NBPS(10, BE, 1, 10, int16_t) ++yuv2NBPS(10, LE, 0, 10, int16_t) ++yuv2NBPS(16, BE, 1, 16, int32_t) ++yuv2NBPS(16, LE, 0, 16, int32_t) ++ ++static void yuv2planeX_8_c(const int16_t *filter, int filterSize, ++ const int16_t **src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset) + { +- //FIXME Optimize (just quickly written not optimized..) + int i; + for (i=0; i>19); + } +- +- if (uDest) +- for (i=0; i>19); +- vDest[i]= av_clip_uint8(v>>19); +- } +- +- if (CONFIG_SWSCALE_ALPHA && aDest) +- for (i=0; i>19); +- } +- + } + +-static inline void yuv2nv12XinC(const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, int dstFormat) ++static void yuv2plane1_8_c(const int16_t *src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset) + { +- //FIXME Optimize (just quickly written not optimized..) + int i; + for (i=0; i>19); ++ int val = (src[i] + dither[(i + offset) & 7]) >> 7; ++ dest[i]= av_clip_uint8(val); + } ++} + +- if (!uDest) +- return; ++static void yuv2nv12cX_c(SwsContext *c, const int16_t *chrFilter, int chrFilterSize, ++ const int16_t **chrUSrc, const int16_t **chrVSrc, ++ uint8_t *dest, int chrDstW) ++{ ++ enum PixelFormat dstFormat = c->dstFormat; ++ const uint8_t *chrDither = c->chrDither8; ++ int i; + + if (dstFormat == PIX_FMT_NV12) + for (i=0; i>19); +- uDest[2*i+1]= av_clip_uint8(v>>19); ++ dest[2*i]= av_clip_uint8(u>>19); ++ dest[2*i+1]= av_clip_uint8(v>>19); + } + else + for (i=0; i>19); +- uDest[2*i+1]= av_clip_uint8(u>>19); ++ dest[2*i]= av_clip_uint8(v>>19); ++ dest[2*i+1]= av_clip_uint8(u>>19); + } + } + +-#define YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha) \ +- for (i=0; i<(dstW>>1); i++) {\ +- int j;\ +- int Y1 = 1<<18;\ +- int Y2 = 1<<18;\ +- int U = 1<<18;\ +- int V = 1<<18;\ +- int av_unused A1, A2;\ +- type av_unused *r, *b, *g;\ +- const int i2= 2*i;\ +- \ +- for (j=0; j>=19;\ +- Y2>>=19;\ +- U >>=19;\ +- V >>=19;\ +- if (alpha) {\ +- A1 = 1<<18;\ +- A2 = 1<<18;\ +- for (j=0; j>=19;\ +- A2>>=19;\ +- } +- +-#define YSCALE_YUV_2_PACKEDX_C(type,alpha) \ +- YSCALE_YUV_2_PACKEDX_NOCLIP_C(type,alpha)\ +- if ((Y1|Y2|U|V)&256) {\ +- if (Y1>255) Y1=255; \ +- else if (Y1<0)Y1=0; \ +- if (Y2>255) Y2=255; \ +- else if (Y2<0)Y2=0; \ +- if (U>255) U=255; \ +- else if (U<0) U=0; \ +- if (V>255) V=255; \ +- else if (V<0) V=0; \ +- }\ +- if (alpha && ((A1|A2)&256)) {\ +- A1=av_clip_uint8(A1);\ +- A2=av_clip_uint8(A2);\ +- } +- +-#define YSCALE_YUV_2_PACKEDX_FULL_C(rnd,alpha) \ +- for (i=0; i>=10;\ +- U >>=10;\ +- V >>=10;\ +- if (alpha) {\ +- A = rnd;\ +- for (j=0; j>=19;\ +- if (A&256)\ +- A = av_clip_uint8(A);\ +- } +- +-#define YSCALE_YUV_2_RGBX_FULL_C(rnd,alpha) \ +- YSCALE_YUV_2_PACKEDX_FULL_C(rnd>>3,alpha)\ +- Y-= c->yuv2rgb_y_offset;\ +- Y*= c->yuv2rgb_y_coeff;\ +- Y+= rnd;\ +- R= Y + V*c->yuv2rgb_v2r_coeff;\ +- G= Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff;\ +- B= Y + U*c->yuv2rgb_u2b_coeff;\ +- if ((R|G|B)&(0xC0000000)) {\ +- if (R>=(256<<22)) R=(256<<22)-1; \ +- else if (R<0)R=0; \ +- if (G>=(256<<22)) G=(256<<22)-1; \ +- else if (G<0)G=0; \ +- if (B>=(256<<22)) B=(256<<22)-1; \ +- else if (B<0)B=0; \ +- } +- +-#define YSCALE_YUV_2_GRAY16_C \ +- for (i=0; i<(dstW>>1); i++) {\ +- int j;\ +- int Y1 = 1<<18;\ +- int Y2 = 1<<18;\ +- int U = 1<<18;\ +- int V = 1<<18;\ +- \ +- const int i2= 2*i;\ +- \ +- for (j=0; j>=11;\ +- Y2>>=11;\ +- if ((Y1|Y2|U|V)&65536) {\ +- if (Y1>65535) Y1=65535; \ +- else if (Y1<0)Y1=0; \ +- if (Y2>65535) Y2=65535; \ +- else if (Y2<0)Y2=0; \ +- } +- +-#define YSCALE_YUV_2_RGBX_C(type,alpha) \ +- YSCALE_YUV_2_PACKEDX_C(type,alpha) /* FIXME fix tables so that clipping is not needed and then use _NOCLIP*/\ +- r = (type *)c->table_rV[V]; \ +- g = (type *)(c->table_gU[U] + c->table_gV[V]); \ +- b = (type *)c->table_bU[U]; +- +-#define YSCALE_YUV_2_PACKED2_C(type,alpha) \ +- for (i=0; i<(dstW>>1); i++) { \ +- const int i2= 2*i; \ +- int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>19; \ +- int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>19; \ +- int U= (uvbuf0[i ]*uvalpha1+uvbuf1[i ]*uvalpha)>>19; \ +- int V= (uvbuf0[i+VOFW]*uvalpha1+uvbuf1[i+VOFW]*uvalpha)>>19; \ +- type av_unused *r, *b, *g; \ +- int av_unused A1, A2; \ +- if (alpha) {\ +- A1= (abuf0[i2 ]*yalpha1+abuf1[i2 ]*yalpha)>>19; \ +- A2= (abuf0[i2+1]*yalpha1+abuf1[i2+1]*yalpha)>>19; \ +- } +- +-#define YSCALE_YUV_2_GRAY16_2_C \ +- for (i=0; i<(dstW>>1); i++) { \ +- const int i2= 2*i; \ +- int Y1= (buf0[i2 ]*yalpha1+buf1[i2 ]*yalpha)>>11; \ +- int Y2= (buf0[i2+1]*yalpha1+buf1[i2+1]*yalpha)>>11; +- +-#define YSCALE_YUV_2_RGB2_C(type,alpha) \ +- YSCALE_YUV_2_PACKED2_C(type,alpha)\ +- r = (type *)c->table_rV[V];\ +- g = (type *)(c->table_gU[U] + c->table_gV[V]);\ +- b = (type *)c->table_bU[U]; +- +-#define YSCALE_YUV_2_PACKED1_C(type,alpha) \ +- for (i=0; i<(dstW>>1); i++) {\ +- const int i2= 2*i;\ +- int Y1= buf0[i2 ]>>7;\ +- int Y2= buf0[i2+1]>>7;\ +- int U= (uvbuf1[i ])>>7;\ +- int V= (uvbuf1[i+VOFW])>>7;\ +- type av_unused *r, *b, *g;\ +- int av_unused A1, A2;\ +- if (alpha) {\ +- A1= abuf0[i2 ]>>7;\ +- A2= abuf0[i2+1]>>7;\ +- } +- +-#define YSCALE_YUV_2_GRAY16_1_C \ +- for (i=0; i<(dstW>>1); i++) {\ +- const int i2= 2*i;\ +- int Y1= buf0[i2 ]<<1;\ +- int Y2= buf0[i2+1]<<1; +- +-#define YSCALE_YUV_2_RGB1_C(type,alpha) \ +- YSCALE_YUV_2_PACKED1_C(type,alpha)\ +- r = (type *)c->table_rV[V];\ +- g = (type *)(c->table_gU[U] + c->table_gV[V]);\ +- b = (type *)c->table_bU[U]; +- +-#define YSCALE_YUV_2_PACKED1B_C(type,alpha) \ +- for (i=0; i<(dstW>>1); i++) {\ +- const int i2= 2*i;\ +- int Y1= buf0[i2 ]>>7;\ +- int Y2= buf0[i2+1]>>7;\ +- int U= (uvbuf0[i ] + uvbuf1[i ])>>8;\ +- int V= (uvbuf0[i+VOFW] + uvbuf1[i+VOFW])>>8;\ +- type av_unused *r, *b, *g;\ +- int av_unused A1, A2;\ +- if (alpha) {\ +- A1= abuf0[i2 ]>>7;\ +- A2= abuf0[i2+1]>>7;\ +- } +- +-#define YSCALE_YUV_2_RGB1B_C(type,alpha) \ +- YSCALE_YUV_2_PACKED1B_C(type,alpha)\ +- r = (type *)c->table_rV[V];\ +- g = (type *)(c->table_gU[U] + c->table_gV[V]);\ +- b = (type *)c->table_bU[U]; +- +-#define YSCALE_YUV_2_MONO2_C \ +- const uint8_t * const d128=dither_8x8_220[y&7];\ +- uint8_t *g= c->table_gU[128] + c->table_gV[128];\ +- for (i=0; i>19) + d128[0]];\ +- acc+= acc + g[((buf0[i+1]*yalpha1+buf1[i+1]*yalpha)>>19) + d128[1]];\ +- acc+= acc + g[((buf0[i+2]*yalpha1+buf1[i+2]*yalpha)>>19) + d128[2]];\ +- acc+= acc + g[((buf0[i+3]*yalpha1+buf1[i+3]*yalpha)>>19) + d128[3]];\ +- acc+= acc + g[((buf0[i+4]*yalpha1+buf1[i+4]*yalpha)>>19) + d128[4]];\ +- acc+= acc + g[((buf0[i+5]*yalpha1+buf1[i+5]*yalpha)>>19) + d128[5]];\ +- acc+= acc + g[((buf0[i+6]*yalpha1+buf1[i+6]*yalpha)>>19) + d128[6]];\ +- acc+= acc + g[((buf0[i+7]*yalpha1+buf1[i+7]*yalpha)>>19) + d128[7]];\ +- ((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\ +- dest++;\ +- } +- +-#define YSCALE_YUV_2_MONOX_C \ +- const uint8_t * const d128=dither_8x8_220[y&7];\ +- uint8_t *g= c->table_gU[128] + c->table_gV[128];\ +- int acc=0;\ +- for (i=0; i>=19;\ +- Y2>>=19;\ +- if ((Y1|Y2)&256) {\ +- if (Y1>255) Y1=255;\ +- else if (Y1<0)Y1=0;\ +- if (Y2>255) Y2=255;\ +- else if (Y2<0)Y2=0;\ +- }\ +- acc+= acc + g[Y1+d128[(i+0)&7]];\ +- acc+= acc + g[Y2+d128[(i+1)&7]];\ +- if ((i&7)==6) {\ +- ((uint8_t*)dest)[0]= c->dstFormat == PIX_FMT_MONOBLACK ? acc : ~acc;\ +- dest++;\ +- }\ +- } +- +-#define YSCALE_YUV_2_ANYRGB_C(func, func2, func_g16, func_monoblack)\ +- switch(c->dstFormat) {\ +- case PIX_FMT_RGB48BE:\ +- case PIX_FMT_RGB48LE:\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[ 0]= r[Y1];\ +- ((uint8_t*)dest)[ 1]= r[Y1];\ +- ((uint8_t*)dest)[ 2]= g[Y1];\ +- ((uint8_t*)dest)[ 3]= g[Y1];\ +- ((uint8_t*)dest)[ 4]= b[Y1];\ +- ((uint8_t*)dest)[ 5]= b[Y1];\ +- ((uint8_t*)dest)[ 6]= r[Y2];\ +- ((uint8_t*)dest)[ 7]= r[Y2];\ +- ((uint8_t*)dest)[ 8]= g[Y2];\ +- ((uint8_t*)dest)[ 9]= g[Y2];\ +- ((uint8_t*)dest)[10]= b[Y2];\ +- ((uint8_t*)dest)[11]= b[Y2];\ +- dest+=12;\ +- }\ +- break;\ +- case PIX_FMT_RGBA:\ +- case PIX_FMT_BGRA:\ +- if (CONFIG_SMALL) {\ +- int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\ +- func(uint32_t,needAlpha)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? (A1<<24) : 0);\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? (A2<<24) : 0);\ +- }\ +- } else {\ +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\ +- func(uint32_t,1)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (A1<<24);\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (A2<<24);\ +- }\ +- } else {\ +- func(uint32_t,0)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ +- }\ +- }\ +- }\ +- break;\ +- case PIX_FMT_ARGB:\ +- case PIX_FMT_ABGR:\ +- if (CONFIG_SMALL) {\ +- int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf;\ +- func(uint32_t,needAlpha)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + (needAlpha ? A1 : 0);\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + (needAlpha ? A2 : 0);\ +- }\ +- } else {\ +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) {\ +- func(uint32_t,1)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1] + A1;\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2] + A2;\ +- }\ +- } else {\ +- func(uint32_t,0)\ +- ((uint32_t*)dest)[i2+0]= r[Y1] + g[Y1] + b[Y1];\ +- ((uint32_t*)dest)[i2+1]= r[Y2] + g[Y2] + b[Y2];\ +- }\ +- }\ +- } \ +- break;\ +- case PIX_FMT_RGB24:\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[0]= r[Y1];\ +- ((uint8_t*)dest)[1]= g[Y1];\ +- ((uint8_t*)dest)[2]= b[Y1];\ +- ((uint8_t*)dest)[3]= r[Y2];\ +- ((uint8_t*)dest)[4]= g[Y2];\ +- ((uint8_t*)dest)[5]= b[Y2];\ +- dest+=6;\ +- }\ +- break;\ +- case PIX_FMT_BGR24:\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[0]= b[Y1];\ +- ((uint8_t*)dest)[1]= g[Y1];\ +- ((uint8_t*)dest)[2]= r[Y1];\ +- ((uint8_t*)dest)[3]= b[Y2];\ +- ((uint8_t*)dest)[4]= g[Y2];\ +- ((uint8_t*)dest)[5]= r[Y2];\ +- dest+=6;\ +- }\ +- break;\ +- case PIX_FMT_RGB565BE:\ +- case PIX_FMT_RGB565LE:\ +- case PIX_FMT_BGR565BE:\ +- case PIX_FMT_BGR565LE:\ +- {\ +- const int dr1= dither_2x2_8[y&1 ][0];\ +- const int dg1= dither_2x2_4[y&1 ][0];\ +- const int db1= dither_2x2_8[(y&1)^1][0];\ +- const int dr2= dither_2x2_8[y&1 ][1];\ +- const int dg2= dither_2x2_4[y&1 ][1];\ +- const int db2= dither_2x2_8[(y&1)^1][1];\ +- func(uint16_t,0)\ +- ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ +- ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ +- }\ +- }\ +- break;\ +- case PIX_FMT_RGB555BE:\ +- case PIX_FMT_RGB555LE:\ +- case PIX_FMT_BGR555BE:\ +- case PIX_FMT_BGR555LE:\ +- {\ +- const int dr1= dither_2x2_8[y&1 ][0];\ +- const int dg1= dither_2x2_8[y&1 ][1];\ +- const int db1= dither_2x2_8[(y&1)^1][0];\ +- const int dr2= dither_2x2_8[y&1 ][1];\ +- const int dg2= dither_2x2_8[y&1 ][0];\ +- const int db2= dither_2x2_8[(y&1)^1][1];\ +- func(uint16_t,0)\ +- ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ +- ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ +- }\ +- }\ +- break;\ +- case PIX_FMT_RGB444BE:\ +- case PIX_FMT_RGB444LE:\ +- case PIX_FMT_BGR444BE:\ +- case PIX_FMT_BGR444LE:\ +- {\ +- const int dr1= dither_4x4_16[y&3 ][0];\ +- const int dg1= dither_4x4_16[y&3 ][1];\ +- const int db1= dither_4x4_16[(y&3)^3][0];\ +- const int dr2= dither_4x4_16[y&3 ][1];\ +- const int dg2= dither_4x4_16[y&3 ][0];\ +- const int db2= dither_4x4_16[(y&3)^3][1];\ +- func(uint16_t,0)\ +- ((uint16_t*)dest)[i2+0]= r[Y1+dr1] + g[Y1+dg1] + b[Y1+db1];\ +- ((uint16_t*)dest)[i2+1]= r[Y2+dr2] + g[Y2+dg2] + b[Y2+db2];\ +- }\ +- }\ +- break;\ +- case PIX_FMT_RGB8:\ +- case PIX_FMT_BGR8:\ +- {\ +- const uint8_t * const d64= dither_8x8_73[y&7];\ +- const uint8_t * const d32= dither_8x8_32[y&7];\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[i2+0]= r[Y1+d32[(i2+0)&7]] + g[Y1+d32[(i2+0)&7]] + b[Y1+d64[(i2+0)&7]];\ +- ((uint8_t*)dest)[i2+1]= r[Y2+d32[(i2+1)&7]] + g[Y2+d32[(i2+1)&7]] + b[Y2+d64[(i2+1)&7]];\ +- }\ +- }\ +- break;\ +- case PIX_FMT_RGB4:\ +- case PIX_FMT_BGR4:\ +- {\ +- const uint8_t * const d64= dither_8x8_73 [y&7];\ +- const uint8_t * const d128=dither_8x8_220[y&7];\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[i]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]]\ +- + ((r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]])<<4);\ +- }\ +- }\ +- break;\ +- case PIX_FMT_RGB4_BYTE:\ +- case PIX_FMT_BGR4_BYTE:\ +- {\ +- const uint8_t * const d64= dither_8x8_73 [y&7];\ +- const uint8_t * const d128=dither_8x8_220[y&7];\ +- func(uint8_t,0)\ +- ((uint8_t*)dest)[i2+0]= r[Y1+d128[(i2+0)&7]] + g[Y1+d64[(i2+0)&7]] + b[Y1+d128[(i2+0)&7]];\ +- ((uint8_t*)dest)[i2+1]= r[Y2+d128[(i2+1)&7]] + g[Y2+d64[(i2+1)&7]] + b[Y2+d128[(i2+1)&7]];\ +- }\ +- }\ +- break;\ +- case PIX_FMT_MONOBLACK:\ +- case PIX_FMT_MONOWHITE:\ +- {\ +- func_monoblack\ +- }\ +- break;\ +- case PIX_FMT_YUYV422:\ +- func2\ +- ((uint8_t*)dest)[2*i2+0]= Y1;\ +- ((uint8_t*)dest)[2*i2+1]= U;\ +- ((uint8_t*)dest)[2*i2+2]= Y2;\ +- ((uint8_t*)dest)[2*i2+3]= V;\ +- } \ +- break;\ +- case PIX_FMT_UYVY422:\ +- func2\ +- ((uint8_t*)dest)[2*i2+0]= U;\ +- ((uint8_t*)dest)[2*i2+1]= Y1;\ +- ((uint8_t*)dest)[2*i2+2]= V;\ +- ((uint8_t*)dest)[2*i2+3]= Y2;\ +- } \ +- break;\ +- case PIX_FMT_GRAY16BE:\ +- func_g16\ +- ((uint8_t*)dest)[2*i2+0]= Y1>>8;\ +- ((uint8_t*)dest)[2*i2+1]= Y1;\ +- ((uint8_t*)dest)[2*i2+2]= Y2>>8;\ +- ((uint8_t*)dest)[2*i2+3]= Y2;\ +- } \ +- break;\ +- case PIX_FMT_GRAY16LE:\ +- func_g16\ +- ((uint8_t*)dest)[2*i2+0]= Y1;\ +- ((uint8_t*)dest)[2*i2+1]= Y1>>8;\ +- ((uint8_t*)dest)[2*i2+2]= Y2;\ +- ((uint8_t*)dest)[2*i2+3]= Y2>>8;\ +- } \ +- break;\ +- } +- +-static inline void yuv2packedXinC(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint8_t *dest, int dstW, int y) +-{ +- int i; +- YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGBX_C, YSCALE_YUV_2_PACKEDX_C(void,0), YSCALE_YUV_2_GRAY16_C, YSCALE_YUV_2_MONOX_C) +-} +- +-static inline void yuv2rgbXinC_full(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint8_t *dest, int dstW, int y) +-{ +- int i; +- int step= c->dstFormatBpp/8; +- int aidx= 3; +- +- switch(c->dstFormat) { +- case PIX_FMT_ARGB: +- dest++; +- aidx= 0; +- case PIX_FMT_RGB24: +- aidx--; +- case PIX_FMT_RGBA: +- if (CONFIG_SMALL) { +- int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf; +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha) +- dest[aidx]= needAlpha ? A : 255; +- dest[0]= R>>22; +- dest[1]= G>>22; +- dest[2]= B>>22; +- dest+= step; +- } +- } else { +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1) +- dest[aidx]= A; +- dest[0]= R>>22; +- dest[1]= G>>22; +- dest[2]= B>>22; +- dest+= step; +- } +- } else { +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0) +- dest[aidx]= 255; +- dest[0]= R>>22; +- dest[1]= G>>22; +- dest[2]= B>>22; +- dest+= step; +- } +- } +- } +- break; +- case PIX_FMT_ABGR: +- dest++; +- aidx= 0; +- case PIX_FMT_BGR24: +- aidx--; +- case PIX_FMT_BGRA: +- if (CONFIG_SMALL) { +- int needAlpha = CONFIG_SWSCALE_ALPHA && c->alpPixBuf; +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, needAlpha) +- dest[aidx]= needAlpha ? A : 255; +- dest[0]= B>>22; +- dest[1]= G>>22; +- dest[2]= R>>22; +- dest+= step; +- } +- } else { +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, 1) +- dest[aidx]= A; +- dest[0]= B>>22; +- dest[1]= G>>22; +- dest[2]= R>>22; +- dest+= step; +- } +- } else { +- YSCALE_YUV_2_RGBX_FULL_C(1<<21, 0) +- dest[aidx]= 255; +- dest[0]= B>>22; +- dest[1]= G>>22; +- dest[2]= R>>22; +- dest+= step; +- } +- } ++#define output_pixel(pos, val) \ ++ if (target == PIX_FMT_GRAY16BE) { \ ++ AV_WB16(pos, val); \ ++ } else { \ ++ AV_WL16(pos, val); \ + } +- break; +- default: +- assert(0); +- } +-} + +-static void fillPlane(uint8_t* plane, int stride, int width, int height, int y, uint8_t val) ++static av_always_inline void ++yuv2gray16_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int32_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int32_t **chrUSrc, ++ const int32_t **chrVSrc, int chrFilterSize, ++ const int32_t **alpSrc, uint16_t *dest, int dstW, ++ int y, enum PixelFormat target) + { + int i; +- uint8_t *ptr = plane + stride*y; +- for (i=0; i> 1); i++) { ++ int j; ++ int Y1 = (1 << 14) - 0x40000000; ++ int Y2 = (1 << 14) - 0x40000000; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y1 += lumSrc[j][i * 2] * lumFilter[j]; ++ Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; ++ } ++ Y1 >>= 15; ++ Y2 >>= 15; ++ Y1 = av_clip_int16(Y1); ++ Y2 = av_clip_int16(Y2); ++ output_pixel(&dest[i * 2 + 0], 0x8000 + Y1); ++ output_pixel(&dest[i * 2 + 1], 0x8000 + Y2); + } + } + +-static inline void rgb48ToY(uint8_t *dst, const uint8_t *src, long width, +- uint32_t *unused) ++static av_always_inline void ++yuv2gray16_2_c_template(SwsContext *c, const int32_t *buf[2], ++ const int32_t *ubuf[2], const int32_t *vbuf[2], ++ const int32_t *abuf[2], uint16_t *dest, int dstW, ++ int yalpha, int uvalpha, int y, ++ enum PixelFormat target) + { ++ int yalpha1 = 4095 - yalpha; + int i; +- for (i = 0; i < width; i++) { +- int r = src[i*6+0]; +- int g = src[i*6+2]; +- int b = src[i*6+4]; ++ const int32_t *buf0 = buf[0], *buf1 = buf[1]; ++ ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2 ] * yalpha1 + buf1[i * 2 ] * yalpha) >> 15; ++ int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 15; + +- dst[i] = (RY*r + GY*g + BY*b + (33<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ output_pixel(&dest[i * 2 + 0], Y1); ++ output_pixel(&dest[i * 2 + 1], Y2); + } + } + +-static inline void rgb48ToUV(uint8_t *dstU, uint8_t *dstV, +- const uint8_t *src1, const uint8_t *src2, +- long width, uint32_t *unused) ++static av_always_inline void ++yuv2gray16_1_c_template(SwsContext *c, const int32_t *buf0, ++ const int32_t *ubuf[2], const int32_t *vbuf[2], ++ const int32_t *abuf0, uint16_t *dest, int dstW, ++ int uvalpha, int y, enum PixelFormat target) + { + int i; +- assert(src1==src2); +- for (i = 0; i < width; i++) { +- int r = src1[6*i + 0]; +- int g = src1[6*i + 2]; +- int b = src1[6*i + 4]; + +- dstU[i] = (RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; +- dstV[i] = (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; +- } +-} +- +-static inline void rgb48ToUV_half(uint8_t *dstU, uint8_t *dstV, +- const uint8_t *src1, const uint8_t *src2, +- long width, uint32_t *unused) ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2 ]+4)>>3; ++ int Y2 = (buf0[i * 2 + 1]+4)>>3; ++ ++ output_pixel(&dest[i * 2 + 0], Y1); ++ output_pixel(&dest[i * 2 + 1], Y2); ++ } ++} ++ ++#undef output_pixel ++ ++#define YUV2PACKED16WRAPPER(name, base, ext, fmt) \ ++static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ ++ const int16_t **_lumSrc, int lumFilterSize, \ ++ const int16_t *chrFilter, const int16_t **_chrUSrc, \ ++ const int16_t **_chrVSrc, int chrFilterSize, \ ++ const int16_t **_alpSrc, uint8_t *_dest, int dstW, \ ++ int y) \ ++{ \ ++ const int32_t **lumSrc = (const int32_t **) _lumSrc, \ ++ **chrUSrc = (const int32_t **) _chrUSrc, \ ++ **chrVSrc = (const int32_t **) _chrVSrc, \ ++ **alpSrc = (const int32_t **) _alpSrc; \ ++ uint16_t *dest = (uint16_t *) _dest; \ ++ name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \ ++ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ ++ alpSrc, dest, dstW, y, fmt); \ ++} \ ++ \ ++static void name ## ext ## _2_c(SwsContext *c, const int16_t *_buf[2], \ ++ const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ ++ const int16_t *_abuf[2], uint8_t *_dest, int dstW, \ ++ int yalpha, int uvalpha, int y) \ ++{ \ ++ const int32_t **buf = (const int32_t **) _buf, \ ++ **ubuf = (const int32_t **) _ubuf, \ ++ **vbuf = (const int32_t **) _vbuf, \ ++ **abuf = (const int32_t **) _abuf; \ ++ uint16_t *dest = (uint16_t *) _dest; \ ++ name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \ ++ dest, dstW, yalpha, uvalpha, y, fmt); \ ++} \ ++ \ ++static void name ## ext ## _1_c(SwsContext *c, const int16_t *_buf0, \ ++ const int16_t *_ubuf[2], const int16_t *_vbuf[2], \ ++ const int16_t *_abuf0, uint8_t *_dest, int dstW, \ ++ int uvalpha, int y) \ ++{ \ ++ const int32_t *buf0 = (const int32_t *) _buf0, \ ++ **ubuf = (const int32_t **) _ubuf, \ ++ **vbuf = (const int32_t **) _vbuf, \ ++ *abuf0 = (const int32_t *) _abuf0; \ ++ uint16_t *dest = (uint16_t *) _dest; \ ++ name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \ ++ dstW, uvalpha, y, fmt); \ ++} ++ ++YUV2PACKED16WRAPPER(yuv2gray16,, LE, PIX_FMT_GRAY16LE) ++YUV2PACKED16WRAPPER(yuv2gray16,, BE, PIX_FMT_GRAY16BE) ++ ++#define output_pixel(pos, acc) \ ++ if (target == PIX_FMT_MONOBLACK) { \ ++ pos = acc; \ ++ } else { \ ++ pos = ~acc; \ ++ } ++ ++static av_always_inline void ++yuv2mono_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, int dstW, ++ int y, enum PixelFormat target) + { ++ const uint8_t * const d128=dither_8x8_220[y&7]; ++ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; + int i; +- assert(src1==src2); +- for (i = 0; i < width; i++) { +- int r= src1[12*i + 0] + src1[12*i + 6]; +- int g= src1[12*i + 2] + src1[12*i + 8]; +- int b= src1[12*i + 4] + src1[12*i + 10]; +- +- dstU[i]= (RU*r + GU*g + BU*b + (257<> (RGB2YUV_SHIFT+1); +- dstV[i]= (RV*r + GV*g + BV*b + (257<> (RGB2YUV_SHIFT+1); ++ unsigned acc = 0; ++ ++ for (i = 0; i < dstW - 1; i += 2) { ++ int j; ++ int Y1 = 1 << 18; ++ int Y2 = 1 << 18; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y1 += lumSrc[j][i] * lumFilter[j]; ++ Y2 += lumSrc[j][i+1] * lumFilter[j]; ++ } ++ Y1 >>= 19; ++ Y2 >>= 19; ++ if ((Y1 | Y2) & 0x100) { ++ Y1 = av_clip_uint8(Y1); ++ Y2 = av_clip_uint8(Y2); ++ } ++ acc += acc + g[Y1 + d128[(i + 0) & 7]]; ++ acc += acc + g[Y2 + d128[(i + 1) & 7]]; ++ if ((i & 7) == 6) { ++ output_pixel(*dest++, acc); ++ } + } + } + +-#define BGR2Y(type, name, shr, shg, shb, maskr, maskg, maskb, RY, GY, BY, S)\ +-static inline void name(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused)\ +-{\ +- int i;\ +- for (i=0; i>shb)&maskb;\ +- int g= (((const type*)src)[i]>>shg)&maskg;\ +- int r= (((const type*)src)[i]>>shr)&maskr;\ +-\ +- dst[i]= (((RY)*r + (GY)*g + (BY)*b + (33<<((S)-1)))>>(S));\ +- }\ +-} +- +-BGR2Y(uint32_t, bgr32ToY,16, 0, 0, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8) +-BGR2Y(uint32_t,bgr321ToY,16,16, 0, 0xFF00, 0x00FF, 0xFF00, RY , GY<<8, BY , RGB2YUV_SHIFT+8) +-BGR2Y(uint32_t, rgb32ToY, 0, 0,16, 0x00FF, 0xFF00, 0x00FF, RY<< 8, GY , BY<< 8, RGB2YUV_SHIFT+8) +-BGR2Y(uint32_t,rgb321ToY, 0,16,16, 0xFF00, 0x00FF, 0xFF00, RY , GY<<8, BY , RGB2YUV_SHIFT+8) +-BGR2Y(uint16_t, bgr16ToY, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RY<<11, GY<<5, BY , RGB2YUV_SHIFT+8) +-BGR2Y(uint16_t, bgr15ToY, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RY<<10, GY<<5, BY , RGB2YUV_SHIFT+7) +-BGR2Y(uint16_t, rgb16ToY, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RY , GY<<5, BY<<11, RGB2YUV_SHIFT+8) +-BGR2Y(uint16_t, rgb15ToY, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RY , GY<<5, BY<<10, RGB2YUV_SHIFT+7) +- +-static inline void abgrToA(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +-{ ++static av_always_inline void ++yuv2mono_2_c_template(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, int dstW, ++ int yalpha, int uvalpha, int y, ++ enum PixelFormat target) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1]; ++ const uint8_t * const d128 = dither_8x8_220[y & 7]; ++ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; ++ int yalpha1 = 4095 - yalpha; + int i; +- for (i=0; i> 19) + d128[0]]; ++ acc += acc + g[((buf0[i + 1] * yalpha1 + buf1[i + 1] * yalpha) >> 19) + d128[1]]; ++ acc += acc + g[((buf0[i + 2] * yalpha1 + buf1[i + 2] * yalpha) >> 19) + d128[2]]; ++ acc += acc + g[((buf0[i + 3] * yalpha1 + buf1[i + 3] * yalpha) >> 19) + d128[3]]; ++ acc += acc + g[((buf0[i + 4] * yalpha1 + buf1[i + 4] * yalpha) >> 19) + d128[4]]; ++ acc += acc + g[((buf0[i + 5] * yalpha1 + buf1[i + 5] * yalpha) >> 19) + d128[5]]; ++ acc += acc + g[((buf0[i + 6] * yalpha1 + buf1[i + 6] * yalpha) >> 19) + d128[6]]; ++ acc += acc + g[((buf0[i + 7] * yalpha1 + buf1[i + 7] * yalpha) >> 19) + d128[7]]; ++ output_pixel(*dest++, acc); + } + } + +-#define BGR2UV(type, name, shr, shg, shb, shp, maskr, maskg, maskb, RU, GU, BU, RV, GV, BV, S) \ +-static inline void name(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ +-{\ +- int i;\ +- for (i=0; i>shp)&maskb)>>shb;\ +- int g= ((((const type*)src)[i]>>shp)&maskg)>>shg;\ +- int r= ((((const type*)src)[i]>>shp)&maskr)>>shr;\ +-\ +- dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<((S)-1)))>>(S);\ +- dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<((S)-1)))>>(S);\ +- }\ +-}\ +-static inline void name ## _half(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, const uint8_t *dummy, long width, uint32_t *unused)\ +-{\ +- int i;\ +- for (i=0; i>shp;\ +- int pix1= ((const type*)src)[2*i+1]>>shp;\ +- int g= (pix0&~(maskr|maskb))+(pix1&~(maskr|maskb));\ +- int b= ((pix0+pix1-g)&(maskb|(2*maskb)))>>shb;\ +- int r= ((pix0+pix1-g)&(maskr|(2*maskr)))>>shr;\ +- g&= maskg|(2*maskg);\ +-\ +- g>>=shg;\ +-\ +- dstU[i]= ((RU)*r + (GU)*g + (BU)*b + (257<<(S)))>>((S)+1);\ +- dstV[i]= ((RV)*r + (GV)*g + (BV)*b + (257<<(S)))>>((S)+1);\ +- }\ +-} +- +-BGR2UV(uint32_t, bgr32ToUV,16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) +-BGR2UV(uint32_t,bgr321ToUV,16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) +-BGR2UV(uint32_t, rgb32ToUV, 0, 0,16, 0, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) +-BGR2UV(uint32_t,rgb321ToUV, 0, 0,16, 8, 0x00FF, 0xFF00, 0xFF0000, RU<< 8, GU , BU<< 8, RV<< 8, GV , BV<< 8, RGB2YUV_SHIFT+8) +-BGR2UV(uint16_t, bgr16ToUV, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, RU<<11, GU<<5, BU , RV<<11, GV<<5, BV , RGB2YUV_SHIFT+8) +-BGR2UV(uint16_t, bgr15ToUV, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, RU<<10, GU<<5, BU , RV<<10, GV<<5, BV , RGB2YUV_SHIFT+7) +-BGR2UV(uint16_t, rgb16ToUV, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, RU , GU<<5, BU<<11, RV , GV<<5, BV<<11, RGB2YUV_SHIFT+8) +-BGR2UV(uint16_t, rgb15ToUV, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, RU , GU<<5, BU<<10, RV , GV<<5, BV<<10, RGB2YUV_SHIFT+7) ++static av_always_inline void ++yuv2mono_1_c_template(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf0, uint8_t *dest, int dstW, ++ int uvalpha, int y, enum PixelFormat target) ++{ ++ const uint8_t * const d128 = dither_8x8_220[y & 7]; ++ uint8_t *g = c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; ++ int i; + +-static inline void palToY(uint8_t *dst, const uint8_t *src, long width, uint32_t *pal) ++ for (i = 0; i < dstW - 7; i += 8) { ++ int acc = g[(buf0[i ] >> 7) + d128[0]]; ++ acc += acc + g[(buf0[i + 1] >> 7) + d128[1]]; ++ acc += acc + g[(buf0[i + 2] >> 7) + d128[2]]; ++ acc += acc + g[(buf0[i + 3] >> 7) + d128[3]]; ++ acc += acc + g[(buf0[i + 4] >> 7) + d128[4]]; ++ acc += acc + g[(buf0[i + 5] >> 7) + d128[5]]; ++ acc += acc + g[(buf0[i + 6] >> 7) + d128[6]]; ++ acc += acc + g[(buf0[i + 7] >> 7) + d128[7]]; ++ output_pixel(*dest++, acc); ++ } ++} ++ ++#undef output_pixel ++ ++#define YUV2PACKEDWRAPPER(name, base, ext, fmt) \ ++static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ ++ const int16_t **lumSrc, int lumFilterSize, \ ++ const int16_t *chrFilter, const int16_t **chrUSrc, \ ++ const int16_t **chrVSrc, int chrFilterSize, \ ++ const int16_t **alpSrc, uint8_t *dest, int dstW, \ ++ int y) \ ++{ \ ++ name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \ ++ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ ++ alpSrc, dest, dstW, y, fmt); \ ++} \ ++ \ ++static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ ++ const int16_t *ubuf[2], const int16_t *vbuf[2], \ ++ const int16_t *abuf[2], uint8_t *dest, int dstW, \ ++ int yalpha, int uvalpha, int y) \ ++{ \ ++ name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \ ++ dest, dstW, yalpha, uvalpha, y, fmt); \ ++} \ ++ \ ++static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \ ++ const int16_t *ubuf[2], const int16_t *vbuf[2], \ ++ const int16_t *abuf0, uint8_t *dest, int dstW, \ ++ int uvalpha, int y) \ ++{ \ ++ name ## base ## _1_c_template(c, buf0, ubuf, vbuf, \ ++ abuf0, dest, dstW, uvalpha, \ ++ y, fmt); \ ++} ++ ++YUV2PACKEDWRAPPER(yuv2mono,, white, PIX_FMT_MONOWHITE) ++YUV2PACKEDWRAPPER(yuv2mono,, black, PIX_FMT_MONOBLACK) ++ ++#define output_pixels(pos, Y1, U, Y2, V) \ ++ if (target == PIX_FMT_YUYV422) { \ ++ dest[pos + 0] = Y1; \ ++ dest[pos + 1] = U; \ ++ dest[pos + 2] = Y2; \ ++ dest[pos + 3] = V; \ ++ } else { \ ++ dest[pos + 0] = U; \ ++ dest[pos + 1] = Y1; \ ++ dest[pos + 2] = V; \ ++ dest[pos + 3] = Y2; \ ++ } ++ ++static av_always_inline void ++yuv2422_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, int dstW, ++ int y, enum PixelFormat target) + { + int i; +- for (i=0; i> 1); i++) { ++ int j; ++ int Y1 = 1 << 18; ++ int Y2 = 1 << 18; ++ int U = 1 << 18; ++ int V = 1 << 18; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y1 += lumSrc[j][i * 2] * lumFilter[j]; ++ Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; ++ } ++ for (j = 0; j < chrFilterSize; j++) { ++ U += chrUSrc[j][i] * chrFilter[j]; ++ V += chrVSrc[j][i] * chrFilter[j]; ++ } ++ Y1 >>= 19; ++ Y2 >>= 19; ++ U >>= 19; ++ V >>= 19; ++ if ((Y1 | Y2 | U | V) & 0x100) { ++ Y1 = av_clip_uint8(Y1); ++ Y2 = av_clip_uint8(Y2); ++ U = av_clip_uint8(U); ++ V = av_clip_uint8(V); ++ } ++ output_pixels(4*i, Y1, U, Y2, V); + } + } + +-static inline void palToUV(uint8_t *dstU, uint8_t *dstV, +- const uint8_t *src1, const uint8_t *src2, +- long width, uint32_t *pal) +-{ ++static av_always_inline void ++yuv2422_2_c_template(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, int dstW, ++ int yalpha, int uvalpha, int y, ++ enum PixelFormat target) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; ++ int yalpha1 = 4095 - yalpha; ++ int uvalpha1 = 4095 - uvalpha; + int i; +- assert(src1 == src2); +- for (i=0; i>8; +- dstV[i]= p>>16; +- } +-} ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; ++ int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; ++ int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; ++ int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; + +-static inline void monowhite2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +-{ +- int i, j; +- for (i=0; i>(7-j))&1)*255; ++ output_pixels(i * 4, Y1, U, Y2, V); + } + } + +-static inline void monoblack2Y(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) ++static av_always_inline void ++yuv2422_1_c_template(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf0, uint8_t *dest, int dstW, ++ int uvalpha, int y, enum PixelFormat target) + { +- int i, j; +- for (i=0; i>(7-j))&1)*255; +- } +-} +- +-//Note: we have C, MMX, MMX2, 3DNOW versions, there is no 3DNOW+MMX2 one +-//Plain C versions +-#if CONFIG_RUNTIME_CPUDETECT +-# define COMPILE_C 1 +-# if ARCH_X86 +-# define COMPILE_MMX HAVE_MMX +-# define COMPILE_MMX2 HAVE_MMX2 +-# define COMPILE_3DNOW HAVE_AMD3DNOW +-# elif ARCH_PPC +-# define COMPILE_ALTIVEC HAVE_ALTIVEC +-# endif +-#else /* CONFIG_RUNTIME_CPUDETECT */ +-# if ARCH_X86 +-# if HAVE_MMX2 +-# define COMPILE_MMX2 1 +-# elif HAVE_AMD3DNOW +-# define COMPILE_3DNOW 1 +-# elif HAVE_MMX +-# define COMPILE_MMX 1 +-# else +-# define COMPILE_C 1 +-# endif +-# elif ARCH_PPC && HAVE_ALTIVEC +-# define COMPILE_ALTIVEC 1 +-# else +-# define COMPILE_C 1 +-# endif +-#endif +- +-#ifndef COMPILE_C +-# define COMPILE_C 0 +-#endif +-#ifndef COMPILE_MMX +-# define COMPILE_MMX 0 +-#endif +-#ifndef COMPILE_MMX2 +-# define COMPILE_MMX2 0 +-#endif +-#ifndef COMPILE_3DNOW +-# define COMPILE_3DNOW 0 +-#endif +-#ifndef COMPILE_ALTIVEC +-# define COMPILE_ALTIVEC 0 +-#endif +- +-#define COMPILE_TEMPLATE_MMX 0 +-#define COMPILE_TEMPLATE_MMX2 0 +-#define COMPILE_TEMPLATE_AMD3DNOW 0 +-#define COMPILE_TEMPLATE_ALTIVEC 0 +- +-#if COMPILE_C +-#define RENAME(a) a ## _C +-#include "swscale_template.c" +-#endif ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; ++ int i; + +-#if COMPILE_ALTIVEC +-#undef RENAME +-#undef COMPILE_TEMPLATE_ALTIVEC +-#define COMPILE_TEMPLATE_ALTIVEC 1 +-#define RENAME(a) a ## _altivec +-#include "swscale_template.c" +-#endif ++ if (uvalpha < 2048) { ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = buf0[i * 2] >> 7; ++ int Y2 = buf0[i * 2 + 1] >> 7; ++ int U = ubuf1[i] >> 7; ++ int V = vbuf1[i] >> 7; + +-#if ARCH_X86 ++ output_pixels(i * 4, Y1, U, Y2, V); ++ } ++ } else { ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = buf0[i * 2] >> 7; ++ int Y2 = buf0[i * 2 + 1] >> 7; ++ int U = (ubuf0[i] + ubuf1[i]) >> 8; ++ int V = (vbuf0[i] + vbuf1[i]) >> 8; + +-//MMX versions +-#if COMPILE_MMX +-#undef RENAME +-#undef COMPILE_TEMPLATE_MMX +-#undef COMPILE_TEMPLATE_MMX2 +-#undef COMPILE_TEMPLATE_AMD3DNOW +-#define COMPILE_TEMPLATE_MMX 1 +-#define COMPILE_TEMPLATE_MMX2 0 +-#define COMPILE_TEMPLATE_AMD3DNOW 0 +-#define RENAME(a) a ## _MMX +-#include "swscale_template.c" +-#endif ++ output_pixels(i * 4, Y1, U, Y2, V); ++ } ++ } ++} + +-//MMX2 versions +-#if COMPILE_MMX2 +-#undef RENAME +-#undef COMPILE_TEMPLATE_MMX +-#undef COMPILE_TEMPLATE_MMX2 +-#undef COMPILE_TEMPLATE_AMD3DNOW +-#define COMPILE_TEMPLATE_MMX 1 +-#define COMPILE_TEMPLATE_MMX2 1 +-#define COMPILE_TEMPLATE_AMD3DNOW 0 +-#define RENAME(a) a ## _MMX2 +-#include "swscale_template.c" +-#endif ++#undef output_pixels + +-//3DNOW versions +-#if COMPILE_3DNOW +-#undef RENAME +-#undef COMPILE_TEMPLATE_MMX +-#undef COMPILE_TEMPLATE_MMX2 +-#undef COMPILE_TEMPLATE_AMD3DNOW +-#define COMPILE_TEMPLATE_MMX 1 +-#define COMPILE_TEMPLATE_MMX2 0 +-#define COMPILE_TEMPLATE_AMD3DNOW 1 +-#define RENAME(a) a ## _3DNow +-#include "swscale_template.c" +-#endif ++YUV2PACKEDWRAPPER(yuv2, 422, yuyv422, PIX_FMT_YUYV422) ++YUV2PACKEDWRAPPER(yuv2, 422, uyvy422, PIX_FMT_UYVY422) + +-#endif //ARCH_X86 ++#define R_B ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? R : B) ++#define B_R ((target == PIX_FMT_RGB48LE || target == PIX_FMT_RGB48BE) ? B : R) ++#define output_pixel(pos, val) \ ++ if (isBE(target)) { \ ++ AV_WB16(pos, val); \ ++ } else { \ ++ AV_WL16(pos, val); \ ++ } + +-SwsFunc ff_getSwsFunc(SwsContext *c) ++static av_always_inline void ++yuv2rgb48_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int32_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int32_t **chrUSrc, ++ const int32_t **chrVSrc, int chrFilterSize, ++ const int32_t **alpSrc, uint16_t *dest, int dstW, ++ int y, enum PixelFormat target) + { +-#if CONFIG_RUNTIME_CPUDETECT +- int flags = c->flags; ++ int i; + +-#if ARCH_X86 +- // ordered per speed fastest first +-#if COMPILE_MMX2 +- if (flags & SWS_CPU_CAPS_MMX2) { +- sws_init_swScale_MMX2(c); +- return swScale_MMX2; +- } +-#endif +-#if COMPILE_3DNOW +- if (flags & SWS_CPU_CAPS_3DNOW) { +- sws_init_swScale_3DNow(c); +- return swScale_3DNow; +- } +-#endif +-#if COMPILE_MMX +- if (flags & SWS_CPU_CAPS_MMX) { +- sws_init_swScale_MMX(c); +- return swScale_MMX; ++ for (i = 0; i < (dstW >> 1); i++) { ++ int j; ++ int Y1 = -0x40000000; ++ int Y2 = -0x40000000; ++ int U = -128 << 23; // 19 ++ int V = -128 << 23; ++ int R, G, B; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y1 += lumSrc[j][i * 2] * lumFilter[j]; ++ Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; ++ } ++ for (j = 0; j < chrFilterSize; j++) { ++ U += chrUSrc[j][i] * chrFilter[j]; ++ V += chrVSrc[j][i] * chrFilter[j]; ++ } ++ ++ // 8bit: 12+15=27; 16-bit: 12+19=31 ++ Y1 >>= 14; // 10 ++ Y1 += 0x10000; ++ Y2 >>= 14; ++ Y2 += 0x10000; ++ U >>= 14; ++ V >>= 14; ++ ++ // 8bit: 27 -> 17bit, 16bit: 31 - 14 = 17bit ++ Y1 -= c->yuv2rgb_y_offset; ++ Y2 -= c->yuv2rgb_y_offset; ++ Y1 *= c->yuv2rgb_y_coeff; ++ Y2 *= c->yuv2rgb_y_coeff; ++ Y1 += 1 << 13; // 21 ++ Y2 += 1 << 13; ++ // 8bit: 17 + 13bit = 30bit, 16bit: 17 + 13bit = 30bit ++ ++ R = V * c->yuv2rgb_v2r_coeff; ++ G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; ++ B = U * c->yuv2rgb_u2b_coeff; ++ ++ // 8bit: 30 - 22 = 8bit, 16bit: 30bit - 14 = 16bit ++ output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); ++ output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); ++ output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); ++ output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); ++ output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); ++ output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); ++ dest += 6; + } +-#endif +- sws_init_swScale_C(c); +- return swScale_C; ++} + +-#else +-#if COMPILE_ALTIVEC +- if (flags & SWS_CPU_CAPS_ALTIVEC) { +- sws_init_swScale_altivec(c); +- return swScale_altivec; +- } else { +- sws_init_swScale_C(c); +- return swScale_C; ++static av_always_inline void ++yuv2rgb48_2_c_template(SwsContext *c, const int32_t *buf[2], ++ const int32_t *ubuf[2], const int32_t *vbuf[2], ++ const int32_t *abuf[2], uint16_t *dest, int dstW, ++ int yalpha, int uvalpha, int y, ++ enum PixelFormat target) ++{ ++ const int32_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; ++ int yalpha1 = 4095 - yalpha; ++ int uvalpha1 = 4095 - uvalpha; ++ int i; ++ ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 14; ++ int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 14; ++ int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha + (-128 << 23)) >> 14; ++ int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha + (-128 << 23)) >> 14; ++ int R, G, B; ++ ++ Y1 -= c->yuv2rgb_y_offset; ++ Y2 -= c->yuv2rgb_y_offset; ++ Y1 *= c->yuv2rgb_y_coeff; ++ Y2 *= c->yuv2rgb_y_coeff; ++ Y1 += 1 << 13; ++ Y2 += 1 << 13; ++ ++ R = V * c->yuv2rgb_v2r_coeff; ++ G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; ++ B = U * c->yuv2rgb_u2b_coeff; ++ ++ output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); ++ output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); ++ output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); ++ output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); ++ output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); ++ output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); ++ dest += 6; + } +-#endif +- sws_init_swScale_C(c); +- return swScale_C; +-#endif /* ARCH_X86 */ +-#else //CONFIG_RUNTIME_CPUDETECT +-#if COMPILE_TEMPLATE_MMX2 +- sws_init_swScale_MMX2(c); +- return swScale_MMX2; +-#elif COMPILE_TEMPLATE_AMD3DNOW +- sws_init_swScale_3DNow(c); +- return swScale_3DNow; +-#elif COMPILE_TEMPLATE_MMX +- sws_init_swScale_MMX(c); +- return swScale_MMX; +-#elif COMPILE_TEMPLATE_ALTIVEC +- sws_init_swScale_altivec(c); +- return swScale_altivec; +-#else +- sws_init_swScale_C(c); +- return swScale_C; +-#endif +-#endif //!CONFIG_RUNTIME_CPUDETECT + } + +-static void copyPlane(const uint8_t *src, int srcStride, +- int srcSliceY, int srcSliceH, int width, +- uint8_t *dst, int dstStride) ++static av_always_inline void ++yuv2rgb48_1_c_template(SwsContext *c, const int32_t *buf0, ++ const int32_t *ubuf[2], const int32_t *vbuf[2], ++ const int32_t *abuf0, uint16_t *dest, int dstW, ++ int uvalpha, int y, enum PixelFormat target) + { +- dst += dstStride * srcSliceY; +- if (dstStride == srcStride && srcStride > 0) { +- memcpy(dst, src, srcSliceH * dstStride); ++ const int32_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; ++ int i; ++ ++ if (uvalpha < 2048) { ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2] ) >> 2; ++ int Y2 = (buf0[i * 2 + 1]) >> 2; ++ int U = (ubuf0[i] + (-128 << 11)) >> 2; ++ int V = (vbuf0[i] + (-128 << 11)) >> 2; ++ int R, G, B; ++ ++ Y1 -= c->yuv2rgb_y_offset; ++ Y2 -= c->yuv2rgb_y_offset; ++ Y1 *= c->yuv2rgb_y_coeff; ++ Y2 *= c->yuv2rgb_y_coeff; ++ Y1 += 1 << 13; ++ Y2 += 1 << 13; ++ ++ R = V * c->yuv2rgb_v2r_coeff; ++ G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; ++ B = U * c->yuv2rgb_u2b_coeff; ++ ++ output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); ++ output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); ++ output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); ++ output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); ++ output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); ++ output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); ++ dest += 6; ++ } + } else { +- int i; +- for (i=0; i> 1); i++) { ++ int Y1 = (buf0[i * 2] ) >> 2; ++ int Y2 = (buf0[i * 2 + 1]) >> 2; ++ int U = (ubuf0[i] + ubuf1[i] + (-128 << 12)) >> 3; ++ int V = (vbuf0[i] + vbuf1[i] + (-128 << 12)) >> 3; ++ int R, G, B; ++ ++ Y1 -= c->yuv2rgb_y_offset; ++ Y2 -= c->yuv2rgb_y_offset; ++ Y1 *= c->yuv2rgb_y_coeff; ++ Y2 *= c->yuv2rgb_y_coeff; ++ Y1 += 1 << 13; ++ Y2 += 1 << 13; ++ ++ R = V * c->yuv2rgb_v2r_coeff; ++ G = V * c->yuv2rgb_v2g_coeff + U * c->yuv2rgb_u2g_coeff; ++ B = U * c->yuv2rgb_u2b_coeff; ++ ++ output_pixel(&dest[0], av_clip_uintp2(R_B + Y1, 30) >> 14); ++ output_pixel(&dest[1], av_clip_uintp2( G + Y1, 30) >> 14); ++ output_pixel(&dest[2], av_clip_uintp2(B_R + Y1, 30) >> 14); ++ output_pixel(&dest[3], av_clip_uintp2(R_B + Y2, 30) >> 14); ++ output_pixel(&dest[4], av_clip_uintp2( G + Y2, 30) >> 14); ++ output_pixel(&dest[5], av_clip_uintp2(B_R + Y2, 30) >> 14); ++ dest += 6; + } + } + } + +-static int planarToNv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) +-{ +- uint8_t *dst = dstParam[1] + dstStride[1]*srcSliceY/2; +- +- copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, +- dstParam[0], dstStride[0]); ++#undef output_pixel ++#undef r_b ++#undef b_r ++ ++YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48be, PIX_FMT_RGB48BE) ++YUV2PACKED16WRAPPER(yuv2, rgb48, rgb48le, PIX_FMT_RGB48LE) ++YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48be, PIX_FMT_BGR48BE) ++YUV2PACKED16WRAPPER(yuv2, rgb48, bgr48le, PIX_FMT_BGR48LE) + +- if (c->dstFormat == PIX_FMT_NV12) +- interleaveBytes(src[1], src[2], dst, c->srcW/2, srcSliceH/2, srcStride[1], srcStride[2], dstStride[0]); +- else +- interleaveBytes(src[2], src[1], dst, c->srcW/2, srcSliceH/2, srcStride[2], srcStride[1], dstStride[0]); ++/* ++ * Write out 2 RGB pixels in the target pixel format. This function takes a ++ * R/G/B LUT as generated by ff_yuv2rgb_c_init_tables(), which takes care of ++ * things like endianness conversion and shifting. The caller takes care of ++ * setting the correct offset in these tables from the chroma (U/V) values. ++ * This function then uses the luminance (Y1/Y2) values to write out the ++ * correct RGB values into the destination buffer. ++ */ ++static av_always_inline void ++yuv2rgb_write(uint8_t *_dest, int i, int Y1, int Y2, ++ unsigned A1, unsigned A2, ++ const void *_r, const void *_g, const void *_b, int y, ++ enum PixelFormat target, int hasAlpha) ++{ ++ if (target == PIX_FMT_ARGB || target == PIX_FMT_RGBA || ++ target == PIX_FMT_ABGR || target == PIX_FMT_BGRA) { ++ uint32_t *dest = (uint32_t *) _dest; ++ const uint32_t *r = (const uint32_t *) _r; ++ const uint32_t *g = (const uint32_t *) _g; ++ const uint32_t *b = (const uint32_t *) _b; + +- return srcSliceH; +-} ++#if CONFIG_SMALL ++ int sh = hasAlpha ? ((target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24) : 0; + +-static int planarToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) +-{ +- uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; ++ dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (hasAlpha ? A1 << sh : 0); ++ dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (hasAlpha ? A2 << sh : 0); ++#else ++ if (hasAlpha) { ++ int sh = (target == PIX_FMT_RGB32_1 || target == PIX_FMT_BGR32_1) ? 0 : 24; + +- yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); ++ dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1] + (A1 << sh); ++ dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2] + (A2 << sh); ++ } else { ++ dest[i * 2 + 0] = r[Y1] + g[Y1] + b[Y1]; ++ dest[i * 2 + 1] = r[Y2] + g[Y2] + b[Y2]; ++ } ++#endif ++ } else if (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) { ++ uint8_t *dest = (uint8_t *) _dest; ++ const uint8_t *r = (const uint8_t *) _r; ++ const uint8_t *g = (const uint8_t *) _g; ++ const uint8_t *b = (const uint8_t *) _b; ++ ++#define r_b ((target == PIX_FMT_RGB24) ? r : b) ++#define b_r ((target == PIX_FMT_RGB24) ? b : r) ++ ++ dest[i * 6 + 0] = r_b[Y1]; ++ dest[i * 6 + 1] = g[Y1]; ++ dest[i * 6 + 2] = b_r[Y1]; ++ dest[i * 6 + 3] = r_b[Y2]; ++ dest[i * 6 + 4] = g[Y2]; ++ dest[i * 6 + 5] = b_r[Y2]; ++#undef r_b ++#undef b_r ++ } else if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565 || ++ target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555 || ++ target == PIX_FMT_RGB444 || target == PIX_FMT_BGR444) { ++ uint16_t *dest = (uint16_t *) _dest; ++ const uint16_t *r = (const uint16_t *) _r; ++ const uint16_t *g = (const uint16_t *) _g; ++ const uint16_t *b = (const uint16_t *) _b; ++ int dr1, dg1, db1, dr2, dg2, db2; ++ ++ if (target == PIX_FMT_RGB565 || target == PIX_FMT_BGR565) { ++ dr1 = dither_2x2_8[ y & 1 ][0]; ++ dg1 = dither_2x2_4[ y & 1 ][0]; ++ db1 = dither_2x2_8[(y & 1) ^ 1][0]; ++ dr2 = dither_2x2_8[ y & 1 ][1]; ++ dg2 = dither_2x2_4[ y & 1 ][1]; ++ db2 = dither_2x2_8[(y & 1) ^ 1][1]; ++ } else if (target == PIX_FMT_RGB555 || target == PIX_FMT_BGR555) { ++ dr1 = dither_2x2_8[ y & 1 ][0]; ++ dg1 = dither_2x2_8[ y & 1 ][1]; ++ db1 = dither_2x2_8[(y & 1) ^ 1][0]; ++ dr2 = dither_2x2_8[ y & 1 ][1]; ++ dg2 = dither_2x2_8[ y & 1 ][0]; ++ db2 = dither_2x2_8[(y & 1) ^ 1][1]; ++ } else { ++ dr1 = dither_4x4_16[ y & 3 ][0]; ++ dg1 = dither_4x4_16[ y & 3 ][1]; ++ db1 = dither_4x4_16[(y & 3) ^ 3][0]; ++ dr2 = dither_4x4_16[ y & 3 ][1]; ++ dg2 = dither_4x4_16[ y & 3 ][0]; ++ db2 = dither_4x4_16[(y & 3) ^ 3][1]; ++ } ++ ++ dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1]; ++ dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]; ++ } else /* 8/4-bit */ { ++ uint8_t *dest = (uint8_t *) _dest; ++ const uint8_t *r = (const uint8_t *) _r; ++ const uint8_t *g = (const uint8_t *) _g; ++ const uint8_t *b = (const uint8_t *) _b; ++ int dr1, dg1, db1, dr2, dg2, db2; ++ ++ if (target == PIX_FMT_RGB8 || target == PIX_FMT_BGR8) { ++ const uint8_t * const d64 = dither_8x8_73[y & 7]; ++ const uint8_t * const d32 = dither_8x8_32[y & 7]; ++ dr1 = dg1 = d32[(i * 2 + 0) & 7]; ++ db1 = d64[(i * 2 + 0) & 7]; ++ dr2 = dg2 = d32[(i * 2 + 1) & 7]; ++ db2 = d64[(i * 2 + 1) & 7]; ++ } else { ++ const uint8_t * const d64 = dither_8x8_73 [y & 7]; ++ const uint8_t * const d128 = dither_8x8_220[y & 7]; ++ dr1 = db1 = d128[(i * 2 + 0) & 7]; ++ dg1 = d64[(i * 2 + 0) & 7]; ++ dr2 = db2 = d128[(i * 2 + 1) & 7]; ++ dg2 = d64[(i * 2 + 1) & 7]; ++ } + +- return srcSliceH; ++ if (target == PIX_FMT_RGB4 || target == PIX_FMT_BGR4) { ++ dest[i] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1] + ++ ((r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]) << 4); ++ } else { ++ dest[i * 2 + 0] = r[Y1 + dr1] + g[Y1 + dg1] + b[Y1 + db1]; ++ dest[i * 2 + 1] = r[Y2 + dr2] + g[Y2 + dg2] + b[Y2 + db2]; ++ } ++ } + } + +-static int planarToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) ++static av_always_inline void ++yuv2rgb_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, int dstW, ++ int y, enum PixelFormat target, int hasAlpha) + { +- uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; ++ int i; + +- yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], srcStride[1], dstStride[0]); ++ for (i = 0; i < (dstW >> 1); i++) { ++ int j; ++ int Y1 = 1 << 18; ++ int Y2 = 1 << 18; ++ int U = 1 << 18; ++ int V = 1 << 18; ++ int av_unused A1, A2; ++ const void *r, *g, *b; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y1 += lumSrc[j][i * 2] * lumFilter[j]; ++ Y2 += lumSrc[j][i * 2 + 1] * lumFilter[j]; ++ } ++ for (j = 0; j < chrFilterSize; j++) { ++ U += chrUSrc[j][i] * chrFilter[j]; ++ V += chrVSrc[j][i] * chrFilter[j]; ++ } ++ Y1 >>= 19; ++ Y2 >>= 19; ++ U >>= 19; ++ V >>= 19; ++ if (hasAlpha) { ++ A1 = 1 << 18; ++ A2 = 1 << 18; ++ for (j = 0; j < lumFilterSize; j++) { ++ A1 += alpSrc[j][i * 2 ] * lumFilter[j]; ++ A2 += alpSrc[j][i * 2 + 1] * lumFilter[j]; ++ } ++ A1 >>= 19; ++ A2 >>= 19; ++ if ((A1 | A2) & 0x100) { ++ A1 = av_clip_uint8(A1); ++ A2 = av_clip_uint8(A2); ++ } ++ } + +- return srcSliceH; ++ r = c->table_rV[V + YUVRGB_TABLE_HEADROOM]; ++ g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]); ++ b = c->table_bU[U + YUVRGB_TABLE_HEADROOM]; ++ ++ yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, ++ r, g, b, y, target, hasAlpha); ++ } + } + +-static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) +-{ +- uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; +- +- yuv422ptoyuy2(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]); ++static av_always_inline void ++yuv2rgb_2_c_template(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, int dstW, ++ int yalpha, int uvalpha, int y, ++ enum PixelFormat target, int hasAlpha) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1], ++ *abuf0 = hasAlpha ? abuf[0] : NULL, ++ *abuf1 = hasAlpha ? abuf[1] : NULL; ++ int yalpha1 = 4095 - yalpha; ++ int uvalpha1 = 4095 - uvalpha; ++ int i; + +- return srcSliceH; ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = (buf0[i * 2] * yalpha1 + buf1[i * 2] * yalpha) >> 19; ++ int Y2 = (buf0[i * 2 + 1] * yalpha1 + buf1[i * 2 + 1] * yalpha) >> 19; ++ int U = (ubuf0[i] * uvalpha1 + ubuf1[i] * uvalpha) >> 19; ++ int V = (vbuf0[i] * uvalpha1 + vbuf1[i] * uvalpha) >> 19; ++ int A1, A2; ++ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM], ++ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]), ++ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM]; ++ ++ if (hasAlpha) { ++ A1 = (abuf0[i * 2 ] * yalpha1 + abuf1[i * 2 ] * yalpha) >> 19; ++ A2 = (abuf0[i * 2 + 1] * yalpha1 + abuf1[i * 2 + 1] * yalpha) >> 19; ++ } ++ ++ yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, ++ r, g, b, y, target, hasAlpha); ++ } + } + +-static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) ++static av_always_inline void ++yuv2rgb_1_c_template(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf0, uint8_t *dest, int dstW, ++ int uvalpha, int y, enum PixelFormat target, ++ int hasAlpha) + { +- uint8_t *dst=dstParam[0] + dstStride[0]*srcSliceY; ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1], ++ *vbuf0 = vbuf[0], *vbuf1 = vbuf[1]; ++ int i; + +- yuv422ptouyvy(src[0],src[1],src[2],dst,c->srcW,srcSliceH,srcStride[0],srcStride[1],dstStride[0]); ++ if (uvalpha < 2048) { ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = buf0[i * 2] >> 7; ++ int Y2 = buf0[i * 2 + 1] >> 7; ++ int U = ubuf1[i] >> 7; ++ int V = vbuf1[i] >> 7; ++ int A1, A2; ++ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM], ++ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]), ++ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM]; ++ ++ if (hasAlpha) { ++ A1 = abuf0[i * 2 ] >> 7; ++ A2 = abuf0[i * 2 + 1] >> 7; ++ } ++ ++ yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, ++ r, g, b, y, target, hasAlpha); ++ } ++ } else { ++ for (i = 0; i < (dstW >> 1); i++) { ++ int Y1 = buf0[i * 2] >> 7; ++ int Y2 = buf0[i * 2 + 1] >> 7; ++ int U = (ubuf0[i] + ubuf1[i]) >> 8; ++ int V = (vbuf0[i] + vbuf1[i]) >> 8; ++ int A1, A2; ++ const void *r = c->table_rV[V + YUVRGB_TABLE_HEADROOM], ++ *g = (c->table_gU[U + YUVRGB_TABLE_HEADROOM] + c->table_gV[V + YUVRGB_TABLE_HEADROOM]), ++ *b = c->table_bU[U + YUVRGB_TABLE_HEADROOM]; ++ ++ if (hasAlpha) { ++ A1 = abuf0[i * 2 ] >> 7; ++ A2 = abuf0[i * 2 + 1] >> 7; ++ } + +- return srcSliceH; ++ yuv2rgb_write(dest, i, Y1, Y2, hasAlpha ? A1 : 0, hasAlpha ? A2 : 0, ++ r, g, b, y, target, hasAlpha); ++ } ++ } + } + +-static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) ++#define YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ ++static void name ## ext ## _X_c(SwsContext *c, const int16_t *lumFilter, \ ++ const int16_t **lumSrc, int lumFilterSize, \ ++ const int16_t *chrFilter, const int16_t **chrUSrc, \ ++ const int16_t **chrVSrc, int chrFilterSize, \ ++ const int16_t **alpSrc, uint8_t *dest, int dstW, \ ++ int y) \ ++{ \ ++ name ## base ## _X_c_template(c, lumFilter, lumSrc, lumFilterSize, \ ++ chrFilter, chrUSrc, chrVSrc, chrFilterSize, \ ++ alpSrc, dest, dstW, y, fmt, hasAlpha); \ ++} ++#define YUV2RGBWRAPPER(name, base, ext, fmt, hasAlpha) \ ++YUV2RGBWRAPPERX(name, base, ext, fmt, hasAlpha) \ ++static void name ## ext ## _2_c(SwsContext *c, const int16_t *buf[2], \ ++ const int16_t *ubuf[2], const int16_t *vbuf[2], \ ++ const int16_t *abuf[2], uint8_t *dest, int dstW, \ ++ int yalpha, int uvalpha, int y) \ ++{ \ ++ name ## base ## _2_c_template(c, buf, ubuf, vbuf, abuf, \ ++ dest, dstW, yalpha, uvalpha, y, fmt, hasAlpha); \ ++} \ ++ \ ++static void name ## ext ## _1_c(SwsContext *c, const int16_t *buf0, \ ++ const int16_t *ubuf[2], const int16_t *vbuf[2], \ ++ const int16_t *abuf0, uint8_t *dest, int dstW, \ ++ int uvalpha, int y) \ ++{ \ ++ name ## base ## _1_c_template(c, buf0, ubuf, vbuf, abuf0, dest, \ ++ dstW, uvalpha, y, fmt, hasAlpha); \ ++} ++ ++#if CONFIG_SMALL ++YUV2RGBWRAPPER(yuv2rgb,, 32_1, PIX_FMT_RGB32_1, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++YUV2RGBWRAPPER(yuv2rgb,, 32, PIX_FMT_RGB32, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++#else ++#if CONFIG_SWSCALE_ALPHA ++YUV2RGBWRAPPER(yuv2rgb,, a32_1, PIX_FMT_RGB32_1, 1) ++YUV2RGBWRAPPER(yuv2rgb,, a32, PIX_FMT_RGB32, 1) ++#endif ++YUV2RGBWRAPPER(yuv2rgb,, x32_1, PIX_FMT_RGB32_1, 0) ++YUV2RGBWRAPPER(yuv2rgb,, x32, PIX_FMT_RGB32, 0) ++#endif ++YUV2RGBWRAPPER(yuv2, rgb, rgb24, PIX_FMT_RGB24, 0) ++YUV2RGBWRAPPER(yuv2, rgb, bgr24, PIX_FMT_BGR24, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 16, PIX_FMT_RGB565, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 15, PIX_FMT_RGB555, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 12, PIX_FMT_RGB444, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 8, PIX_FMT_RGB8, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 4, PIX_FMT_RGB4, 0) ++YUV2RGBWRAPPER(yuv2rgb,, 4b, PIX_FMT_RGB4_BYTE, 0) ++ ++static av_always_inline void ++yuv2rgb_full_X_c_template(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, ++ int dstW, int y, enum PixelFormat target, int hasAlpha) + { +- uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; +- uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY/2; +- uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY/2; +- +- yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); +- +- if (dstParam[3]) +- fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++ int i; ++ int step = (target == PIX_FMT_RGB24 || target == PIX_FMT_BGR24) ? 3 : 4; + +- return srcSliceH; ++ for (i = 0; i < dstW; i++) { ++ int j; ++ int Y = 1<<9; ++ int U = (1<<9)-(128 << 19); ++ int V = (1<<9)-(128 << 19); ++ int av_unused A; ++ int R, G, B; ++ ++ for (j = 0; j < lumFilterSize; j++) { ++ Y += lumSrc[j][i] * lumFilter[j]; ++ } ++ for (j = 0; j < chrFilterSize; j++) { ++ U += chrUSrc[j][i] * chrFilter[j]; ++ V += chrVSrc[j][i] * chrFilter[j]; ++ } ++ Y >>= 10; ++ U >>= 10; ++ V >>= 10; ++ if (hasAlpha) { ++ A = 1 << 18; ++ for (j = 0; j < lumFilterSize; j++) { ++ A += alpSrc[j][i] * lumFilter[j]; ++ } ++ A >>= 19; ++ if (A & 0x100) ++ A = av_clip_uint8(A); ++ } ++ Y -= c->yuv2rgb_y_offset; ++ Y *= c->yuv2rgb_y_coeff; ++ Y += 1 << 21; ++ R = Y + V*c->yuv2rgb_v2r_coeff; ++ G = Y + V*c->yuv2rgb_v2g_coeff + U*c->yuv2rgb_u2g_coeff; ++ B = Y + U*c->yuv2rgb_u2b_coeff; ++ if ((R | G | B) & 0xC0000000) { ++ R = av_clip_uintp2(R, 30); ++ G = av_clip_uintp2(G, 30); ++ B = av_clip_uintp2(B, 30); ++ } ++ ++ switch(target) { ++ case PIX_FMT_ARGB: ++ dest[0] = hasAlpha ? A : 255; ++ dest[1] = R >> 22; ++ dest[2] = G >> 22; ++ dest[3] = B >> 22; ++ break; ++ case PIX_FMT_RGB24: ++ dest[0] = R >> 22; ++ dest[1] = G >> 22; ++ dest[2] = B >> 22; ++ break; ++ case PIX_FMT_RGBA: ++ dest[0] = R >> 22; ++ dest[1] = G >> 22; ++ dest[2] = B >> 22; ++ dest[3] = hasAlpha ? A : 255; ++ break; ++ case PIX_FMT_ABGR: ++ dest[0] = hasAlpha ? A : 255; ++ dest[1] = B >> 22; ++ dest[2] = G >> 22; ++ dest[3] = R >> 22; ++ break; ++ case PIX_FMT_BGR24: ++ dest[0] = B >> 22; ++ dest[1] = G >> 22; ++ dest[2] = R >> 22; ++ break; ++ case PIX_FMT_BGRA: ++ dest[0] = B >> 22; ++ dest[1] = G >> 22; ++ dest[2] = R >> 22; ++ dest[3] = hasAlpha ? A : 255; ++ break; ++ } ++ dest += step; ++ } + } + +-static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) ++#if CONFIG_SMALL ++YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, CONFIG_SWSCALE_ALPHA && c->alpPixBuf) ++#else ++#if CONFIG_SWSCALE_ALPHA ++YUV2RGBWRAPPERX(yuv2, rgb_full, bgra32_full, PIX_FMT_BGRA, 1) ++YUV2RGBWRAPPERX(yuv2, rgb_full, abgr32_full, PIX_FMT_ABGR, 1) ++YUV2RGBWRAPPERX(yuv2, rgb_full, rgba32_full, PIX_FMT_RGBA, 1) ++YUV2RGBWRAPPERX(yuv2, rgb_full, argb32_full, PIX_FMT_ARGB, 1) ++#endif ++YUV2RGBWRAPPERX(yuv2, rgb_full, bgrx32_full, PIX_FMT_BGRA, 0) ++YUV2RGBWRAPPERX(yuv2, rgb_full, xbgr32_full, PIX_FMT_ABGR, 0) ++YUV2RGBWRAPPERX(yuv2, rgb_full, rgbx32_full, PIX_FMT_RGBA, 0) ++YUV2RGBWRAPPERX(yuv2, rgb_full, xrgb32_full, PIX_FMT_ARGB, 0) ++#endif ++YUV2RGBWRAPPERX(yuv2, rgb_full, bgr24_full, PIX_FMT_BGR24, 0) ++YUV2RGBWRAPPERX(yuv2, rgb_full, rgb24_full, PIX_FMT_RGB24, 0) ++ ++static av_always_inline void fillPlane(uint8_t* plane, int stride, ++ int width, int height, ++ int y, uint8_t val) + { +- uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; +- uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY; +- uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY; +- +- yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); +- +- return srcSliceH; ++ int i; ++ uint8_t *ptr = plane + stride*y; ++ for (i=0; isrcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); ++#define r ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? b_r : r_b) ++#define b ((origin == PIX_FMT_BGR48BE || origin == PIX_FMT_BGR48LE) ? r_b : b_r) + +- if (dstParam[3]) +- fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++static av_always_inline void ++rgb48ToY_c_template(uint16_t *dst, const uint16_t *src, int width, ++ enum PixelFormat origin) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ unsigned int r_b = input_pixel(&src[i*3+0]); ++ unsigned int g = input_pixel(&src[i*3+1]); ++ unsigned int b_r = input_pixel(&src[i*3+2]); + +- return srcSliceH; ++ dst[i] = (RY*r + GY*g + BY*b + (0x2001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ } + } + +-static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dstParam[], int dstStride[]) ++static av_always_inline void ++rgb48ToUV_c_template(uint16_t *dstU, uint16_t *dstV, ++ const uint16_t *src1, const uint16_t *src2, ++ int width, enum PixelFormat origin) + { +- uint8_t *ydst=dstParam[0] + dstStride[0]*srcSliceY; +- uint8_t *udst=dstParam[1] + dstStride[1]*srcSliceY; +- uint8_t *vdst=dstParam[2] + dstStride[2]*srcSliceY; +- +- uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], dstStride[1], srcStride[0]); ++ int i; ++ assert(src1==src2); ++ for (i = 0; i < width; i++) { ++ int r_b = input_pixel(&src1[i*3+0]); ++ int g = input_pixel(&src1[i*3+1]); ++ int b_r = input_pixel(&src1[i*3+2]); + +- return srcSliceH; ++ dstU[i] = (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ dstV[i] = (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ } + } + +-static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++static av_always_inline void ++rgb48ToUV_half_c_template(uint16_t *dstU, uint16_t *dstV, ++ const uint16_t *src1, const uint16_t *src2, ++ int width, enum PixelFormat origin) + { +- long i; +- for (i=0; i> 1; ++ int g = (input_pixel(&src1[6 * i + 1]) + input_pixel(&src1[6 * i + 4]) + 1) >> 1; ++ int b_r = (input_pixel(&src1[6 * i + 2]) + input_pixel(&src1[6 * i + 5]) + 1) >> 1; ++ ++ dstU[i]= (RU*r + GU*g + BU*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ dstV[i]= (RV*r + GV*g + BV*b + (0x10001<<(RGB2YUV_SHIFT-1))) >> RGB2YUV_SHIFT; ++ } + } + +-static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++#undef r ++#undef b ++#undef input_pixel ++ ++#define rgb48funcs(pattern, BE_LE, origin) \ ++static void pattern ## 48 ## BE_LE ## ToY_c(uint8_t *_dst, const uint8_t *_src, const uint8_t *unused0, const uint8_t *unused1,\ ++ int width, uint32_t *unused) \ ++{ \ ++ const uint16_t *src = (const uint16_t *) _src; \ ++ uint16_t *dst = (uint16_t *) _dst; \ ++ rgb48ToY_c_template(dst, src, width, origin); \ ++} \ ++ \ ++static void pattern ## 48 ## BE_LE ## ToUV_c(uint8_t *_dstU, uint8_t *_dstV, \ ++ const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \ ++ int width, uint32_t *unused) \ ++{ \ ++ const uint16_t *src1 = (const uint16_t *) _src1, \ ++ *src2 = (const uint16_t *) _src2; \ ++ uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \ ++ rgb48ToUV_c_template(dstU, dstV, src1, src2, width, origin); \ ++} \ ++ \ ++static void pattern ## 48 ## BE_LE ## ToUV_half_c(uint8_t *_dstU, uint8_t *_dstV, \ ++ const uint8_t *unused0, const uint8_t *_src1, const uint8_t *_src2, \ ++ int width, uint32_t *unused) \ ++{ \ ++ const uint16_t *src1 = (const uint16_t *) _src1, \ ++ *src2 = (const uint16_t *) _src2; \ ++ uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; \ ++ rgb48ToUV_half_c_template(dstU, dstV, src1, src2, width, origin); \ ++} ++ ++rgb48funcs(rgb, LE, PIX_FMT_RGB48LE) ++rgb48funcs(rgb, BE, PIX_FMT_RGB48BE) ++rgb48funcs(bgr, LE, PIX_FMT_BGR48LE) ++rgb48funcs(bgr, BE, PIX_FMT_BGR48BE) ++ ++#define input_pixel(i) ((origin == PIX_FMT_RGBA || origin == PIX_FMT_BGRA || \ ++ origin == PIX_FMT_ARGB || origin == PIX_FMT_ABGR) ? AV_RN32A(&src[(i)*4]) : \ ++ (isBE(origin) ? AV_RB16(&src[(i)*2]) : AV_RL16(&src[(i)*2]))) ++ ++static av_always_inline void ++rgb16_32ToY_c_template(int16_t *dst, const uint8_t *src, ++ int width, enum PixelFormat origin, ++ int shr, int shg, int shb, int shp, ++ int maskr, int maskg, int maskb, ++ int rsh, int gsh, int bsh, int S) + { +- long i; ++ const int ry = RY << rsh, gy = GY << gsh, by = BY << bsh; ++ const unsigned rnd = (32<<((S)-1)) + (1<<(S-7)); ++ int i; + +- for (i=0; i> shp; ++ int b = (px & maskb) >> shb; ++ int g = (px & maskg) >> shg; ++ int r = (px & maskr) >> shr; ++ ++ dst[i] = (ry * r + gy * g + by * b + rnd) >> ((S)-6); ++ } + } + +-static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) +-{ +- long i; ++static av_always_inline void ++rgb16_32ToUV_c_template(int16_t *dstU, int16_t *dstV, ++ const uint8_t *src, int width, ++ enum PixelFormat origin, ++ int shr, int shg, int shb, int shp, ++ int maskr, int maskg, int maskb, ++ int rsh, int gsh, int bsh, int S) ++{ ++ const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, ++ rv = RV << rsh, gv = GV << gsh, bv = BV << bsh; ++ const unsigned rnd = (256u<<((S)-1)) + (1<<(S-7)); ++ int i; + +- for (i=0; i> shp; ++ int b = (px & maskb) >> shb; ++ int g = (px & maskg) >> shg; ++ int r = (px & maskr) >> shr; ++ ++ dstU[i] = (ru * r + gu * g + bu * b + rnd) >> ((S)-6); ++ dstV[i] = (rv * r + gv * g + bv * b + rnd) >> ((S)-6); + } + } + +-static int palToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) +-{ +- const enum PixelFormat srcFormat= c->srcFormat; +- const enum PixelFormat dstFormat= c->dstFormat; +- void (*conv)(const uint8_t *src, uint8_t *dst, long num_pixels, +- const uint8_t *palette)=NULL; ++static av_always_inline void ++rgb16_32ToUV_half_c_template(int16_t *dstU, int16_t *dstV, ++ const uint8_t *src, int width, ++ enum PixelFormat origin, ++ int shr, int shg, int shb, int shp, ++ int maskr, int maskg, int maskb, ++ int rsh, int gsh, int bsh, int S) ++{ ++ const int ru = RU << rsh, gu = GU << gsh, bu = BU << bsh, ++ rv = RV << rsh, gv = GV << gsh, bv = BV << bsh, ++ maskgx = ~(maskr | maskb); ++ const unsigned rnd = (256U<<(S)) + (1<<(S-6)); + int i; +- uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; +- const uint8_t *srcPtr= src[0]; + +- if (srcFormat == PIX_FMT_Y400A) { +- switch (dstFormat) { +- case PIX_FMT_RGB32 : conv = gray8aToPacked32; break; +- case PIX_FMT_BGR32 : conv = gray8aToPacked32; break; +- case PIX_FMT_BGR32_1: conv = gray8aToPacked32_1; break; +- case PIX_FMT_RGB32_1: conv = gray8aToPacked32_1; break; +- case PIX_FMT_RGB24 : conv = gray8aToPacked24; break; +- case PIX_FMT_BGR24 : conv = gray8aToPacked24; break; +- } +- } else if (usePal(srcFormat)) { +- switch (dstFormat) { +- case PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break; +- case PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break; +- case PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break; +- case PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break; +- case PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break; +- case PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break; ++ maskr |= maskr << 1; maskb |= maskb << 1; maskg |= maskg << 1; ++ for (i = 0; i < width; i++) { ++ int px0 = input_pixel(2 * i + 0) >> shp; ++ int px1 = input_pixel(2 * i + 1) >> shp; ++ int b, r, g = (px0 & maskgx) + (px1 & maskgx); ++ int rb = px0 + px1 - g; ++ ++ b = (rb & maskb) >> shb; ++ if (shp || origin == PIX_FMT_BGR565LE || origin == PIX_FMT_BGR565BE || ++ origin == PIX_FMT_RGB565LE || origin == PIX_FMT_RGB565BE) { ++ g >>= shg; ++ } else { ++ g = (g & maskg) >> shg; + } +- } ++ r = (rb & maskr) >> shr; + +- if (!conv) +- av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", +- sws_format_name(srcFormat), sws_format_name(dstFormat)); +- else { +- for (i=0; isrcW, (uint8_t *) c->pal_rgb); +- srcPtr+= srcStride[0]; +- dstPtr+= dstStride[0]; +- } ++ dstU[i] = (ru * r + gu * g + bu * b + (unsigned)rnd) >> ((S)-6+1); ++ dstV[i] = (rv * r + gv * g + bv * b + (unsigned)rnd) >> ((S)-6+1); + } ++} ++ ++#undef input_pixel ++ ++#define rgb16_32_wrapper(fmt, name, shr, shg, shb, shp, maskr, \ ++ maskg, maskb, rsh, gsh, bsh, S) \ ++static void name ## ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, \ ++ int width, uint32_t *unused) \ ++{ \ ++ rgb16_32ToY_c_template((int16_t*)dst, src, width, fmt, \ ++ shr, shg, shb, shp, \ ++ maskr, maskg, maskb, rsh, gsh, bsh, S); \ ++} \ ++ \ ++static void name ## ToUV_c(uint8_t *dstU, uint8_t *dstV, \ ++ const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \ ++ int width, uint32_t *unused) \ ++{ \ ++ rgb16_32ToUV_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \ ++ shr, shg, shb, shp, \ ++ maskr, maskg, maskb, rsh, gsh, bsh, S); \ ++} \ ++ \ ++static void name ## ToUV_half_c(uint8_t *dstU, uint8_t *dstV, \ ++ const uint8_t *unused0, const uint8_t *src, const uint8_t *dummy, \ ++ int width, uint32_t *unused) \ ++{ \ ++ rgb16_32ToUV_half_c_template((int16_t*)dstU, (int16_t*)dstV, src, width, fmt, \ ++ shr, shg, shb, shp, \ ++ maskr, maskg, maskb, rsh, gsh, bsh, S); \ ++} ++ ++rgb16_32_wrapper(PIX_FMT_BGR32, bgr32, 16, 0, 0, 0, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_BGR32_1, bgr321, 16, 0, 0, 8, 0xFF0000, 0xFF00, 0x00FF, 8, 0, 8, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_RGB32, rgb32, 0, 0, 16, 0, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_RGB32_1, rgb321, 0, 0, 16, 8, 0x00FF, 0xFF00, 0xFF0000, 8, 0, 8, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_BGR565LE, bgr16le, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_BGR555LE, bgr15le, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7) ++rgb16_32_wrapper(PIX_FMT_BGR444LE, bgr12le, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT+4) ++rgb16_32_wrapper(PIX_FMT_RGB565LE, rgb16le, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_RGB555LE, rgb15le, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7) ++rgb16_32_wrapper(PIX_FMT_RGB444LE, rgb12le, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT+4) ++rgb16_32_wrapper(PIX_FMT_BGR565BE, bgr16be, 0, 0, 0, 0, 0x001F, 0x07E0, 0xF800, 11, 5, 0, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_BGR555BE, bgr15be, 0, 0, 0, 0, 0x001F, 0x03E0, 0x7C00, 10, 5, 0, RGB2YUV_SHIFT+7) ++rgb16_32_wrapper(PIX_FMT_BGR444BE, bgr12be, 0, 0, 0, 0, 0x000F, 0x00F0, 0x0F00, 8, 4, 0, RGB2YUV_SHIFT+4) ++rgb16_32_wrapper(PIX_FMT_RGB565BE, rgb16be, 0, 0, 0, 0, 0xF800, 0x07E0, 0x001F, 0, 5, 11, RGB2YUV_SHIFT+8) ++rgb16_32_wrapper(PIX_FMT_RGB555BE, rgb15be, 0, 0, 0, 0, 0x7C00, 0x03E0, 0x001F, 0, 5, 10, RGB2YUV_SHIFT+7) ++rgb16_32_wrapper(PIX_FMT_RGB444BE, rgb12be, 0, 0, 0, 0, 0x0F00, 0x00F0, 0x000F, 0, 4, 8, RGB2YUV_SHIFT+4) ++ ++static void gbr24pToUV_half_c(uint16_t *dstU, uint16_t *dstV, ++ const uint8_t *gsrc, const uint8_t *bsrc, const uint8_t *rsrc, ++ int width, enum PixelFormat origin) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ unsigned int g = gsrc[2*i] + gsrc[2*i+1]; ++ unsigned int b = bsrc[2*i] + bsrc[2*i+1]; ++ unsigned int r = rsrc[2*i] + rsrc[2*i+1]; + +- return srcSliceH; ++ dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1); ++ dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-6))) >> (RGB2YUV_SHIFT-6+1); ++ } + } + +-#define isRGBA32(x) ( \ +- (x) == PIX_FMT_ARGB \ +- || (x) == PIX_FMT_RGBA \ +- || (x) == PIX_FMT_BGRA \ +- || (x) == PIX_FMT_ABGR \ +- ) ++static void abgrToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused) ++{ ++ int i; ++ for (i=0; i {RGB,BGR}{15,16,24,32} */ +-static int rgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) ++static void rgbaToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused) + { +- const enum PixelFormat srcFormat= c->srcFormat; +- const enum PixelFormat dstFormat= c->dstFormat; +- const int srcBpp= (c->srcFormatBpp + 7) >> 3; +- const int dstBpp= (c->dstFormatBpp + 7) >> 3; +- const int srcId= c->srcFormatBpp >> 2; /* 1:0, 4:1, 8:2, 15:3, 16:4, 24:6, 32:8 */ +- const int dstId= c->dstFormatBpp >> 2; +- void (*conv)(const uint8_t *src, uint8_t *dst, long src_size)=NULL; +- +-#define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst) +- +- if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) { +- if ( CONV_IS(ABGR, RGBA) +- || CONV_IS(ARGB, BGRA) +- || CONV_IS(BGRA, ARGB) +- || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210; +- else if (CONV_IS(ABGR, ARGB) +- || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321; +- else if (CONV_IS(ABGR, BGRA) +- || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230; +- else if (CONV_IS(BGRA, RGBA) +- || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103; +- else if (CONV_IS(BGRA, ABGR) +- || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012; +- } else +- /* BGR -> BGR */ +- if ( (isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) +- || (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) { +- switch(srcId | (dstId<<4)) { +- case 0x34: conv= rgb16to15; break; +- case 0x36: conv= rgb24to15; break; +- case 0x38: conv= rgb32to15; break; +- case 0x43: conv= rgb15to16; break; +- case 0x46: conv= rgb24to16; break; +- case 0x48: conv= rgb32to16; break; +- case 0x63: conv= rgb15to24; break; +- case 0x64: conv= rgb16to24; break; +- case 0x68: conv= rgb32to24; break; +- case 0x83: conv= rgb15to32; break; +- case 0x84: conv= rgb16to32; break; +- case 0x86: conv= rgb24to32; break; +- } +- } else if ( (isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) +- || (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) { +- switch(srcId | (dstId<<4)) { +- case 0x33: conv= rgb15tobgr15; break; +- case 0x34: conv= rgb16tobgr15; break; +- case 0x36: conv= rgb24tobgr15; break; +- case 0x38: conv= rgb32tobgr15; break; +- case 0x43: conv= rgb15tobgr16; break; +- case 0x44: conv= rgb16tobgr16; break; +- case 0x46: conv= rgb24tobgr16; break; +- case 0x48: conv= rgb32tobgr16; break; +- case 0x63: conv= rgb15tobgr24; break; +- case 0x64: conv= rgb16tobgr24; break; +- case 0x66: conv= rgb24tobgr24; break; +- case 0x68: conv= rgb32tobgr24; break; +- case 0x83: conv= rgb15tobgr32; break; +- case 0x84: conv= rgb16tobgr32; break; +- case 0x86: conv= rgb24tobgr32; break; +- } ++ int i; ++ for (i=0; i %s converter\n", +- sws_format_name(srcFormat), sws_format_name(dstFormat)); +- } else { +- const uint8_t *srcPtr= src[0]; +- uint8_t *dstPtr= dst[0]; +- if ((srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) && !isRGBA32(dstFormat)) +- srcPtr += ALT32_CORR; +- +- if ((dstFormat == PIX_FMT_RGB32_1 || dstFormat == PIX_FMT_BGR32_1) && !isRGBA32(srcFormat)) +- dstPtr += ALT32_CORR; +- +- if (dstStride[0]*srcBpp == srcStride[0]*dstBpp && srcStride[0] > 0) +- conv(srcPtr, dstPtr + dstStride[0]*srcSliceY, srcSliceH*srcStride[0]); +- else { +- int i; +- dstPtr += dstStride[0]*srcSliceY; +- +- for (i=0; isrcW*srcBpp); +- srcPtr+= srcStride[0]; +- dstPtr+= dstStride[0]; +- } +- } ++static void palToA_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *pal) ++{ ++ int i; ++ for (i=0; i> 24)<<6; + } +- return srcSliceH; + } + +-static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) ++static void palToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, long width, uint32_t *pal) + { +- rgb24toyv12( +- src[0], +- dst[0]+ srcSliceY *dstStride[0], +- dst[1]+(srcSliceY>>1)*dstStride[1], +- dst[2]+(srcSliceY>>1)*dstStride[2], +- c->srcW, srcSliceH, +- dstStride[0], dstStride[1], srcStride[0]); +- if (dst[3]) +- fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); +- return srcSliceH; +-} +- +-static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) +-{ +- copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, +- dst[0], dstStride[0]); +- +- planar2x(src[1], dst[1] + dstStride[1]*(srcSliceY >> 1), c->chrSrcW, +- srcSliceH >> 2, srcStride[1], dstStride[1]); +- planar2x(src[2], dst[2] + dstStride[2]*(srcSliceY >> 1), c->chrSrcW, +- srcSliceH >> 2, srcStride[2], dstStride[2]); +- if (dst[3]) +- fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); +- return srcSliceH; +-} +- +-/* unscaled copy like stuff (assumes nearly identical formats) */ +-static int packedCopyWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) +-{ +- if (dstStride[0]==srcStride[0] && srcStride[0] > 0) +- memcpy(dst[0] + dstStride[0]*srcSliceY, src[0], srcSliceH*dstStride[0]); +- else { +- int i; +- const uint8_t *srcPtr= src[0]; +- uint8_t *dstPtr= dst[0] + dstStride[0]*srcSliceY; +- int length=0; +- +- /* universal length finder */ +- while(length+c->srcW <= FFABS(dstStride[0]) +- && length+c->srcW <= FFABS(srcStride[0])) length+= c->srcW; +- assert(length!=0); +- +- for (i=0; isrcW : -((-c->srcW )>>c->chrDstHSubSample); +- int y= (plane==0 || plane==3) ? srcSliceY: -((-srcSliceY)>>c->chrDstVSubSample); +- int height= (plane==0 || plane==3) ? srcSliceH: -((-srcSliceH)>>c->chrDstVSubSample); +- const uint8_t *srcPtr= src[plane]; +- uint8_t *dstPtr= dst[plane] + dstStride[plane]*y; +- +- if (!dst[plane]) continue; +- // ignore palette for GRAY8 +- if (plane == 1 && !dst[2]) continue; +- if (!src[plane] || (plane == 1 && !src[2])) { +- if(is16BPS(c->dstFormat)) +- length*=2; +- fillPlane(dst[plane], dstStride[plane], length, height, y, (plane==3) ? 255 : 128); +- } else { +- if(is16BPS(c->srcFormat) && !is16BPS(c->dstFormat)) { +- if (!isBE(c->srcFormat)) srcPtr++; +- for (i=0; isrcFormat) && is16BPS(c->dstFormat)) { +- for (i=0; isrcFormat) && is16BPS(c->dstFormat) +- && isBE(c->srcFormat) != isBE(c->dstFormat)) { ++ int i; ++ for (i=0; i 0 && srcStride[plane] == length) { +- memcpy(dst[plane] + dstStride[plane]*y, src[plane], +- height*dstStride[plane]); +- } else { +- if(is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) +- length*=2; +- for (i=0; i> 8)<<6; ++ dstV[i]= (uint8_t)(p>>16)<<6; ++ } + } + +-void ff_get_unscaled_swscale(SwsContext *c) ++static void monowhite2Y_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused) + { +- const enum PixelFormat srcFormat = c->srcFormat; +- const enum PixelFormat dstFormat = c->dstFormat; +- const int flags = c->flags; +- const int dstH = c->dstH; +- int needsDither; +- +- needsDither= isAnyRGB(dstFormat) +- && c->dstFormatBpp < 24 +- && (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat))); +- +- /* yv12_to_nv12 */ +- if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) { +- c->swScale= planarToNv12Wrapper; +- } +- /* yuv2bgr */ +- if ((srcFormat==PIX_FMT_YUV420P || srcFormat==PIX_FMT_YUV422P || srcFormat==PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) +- && !(flags & SWS_ACCURATE_RND) && !(dstH&1)) { +- c->swScale= ff_yuv2rgb_get_func_ptr(c); +- } +- +- if (srcFormat==PIX_FMT_YUV410P && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_BITEXACT)) { +- c->swScale= yvu9ToYv12Wrapper; +- } +- +- /* bgr24toYV12 */ +- if (srcFormat==PIX_FMT_BGR24 && (dstFormat==PIX_FMT_YUV420P || dstFormat==PIX_FMT_YUVA420P) && !(flags & SWS_ACCURATE_RND)) +- c->swScale= bgr24ToYv12Wrapper; +- +- /* RGB/BGR -> RGB/BGR (no dither needed forms) */ +- if ( isAnyRGB(srcFormat) +- && isAnyRGB(dstFormat) +- && srcFormat != PIX_FMT_BGR8 && dstFormat != PIX_FMT_BGR8 +- && srcFormat != PIX_FMT_RGB8 && dstFormat != PIX_FMT_RGB8 +- && srcFormat != PIX_FMT_BGR4 && dstFormat != PIX_FMT_BGR4 +- && srcFormat != PIX_FMT_RGB4 && dstFormat != PIX_FMT_RGB4 +- && srcFormat != PIX_FMT_BGR4_BYTE && dstFormat != PIX_FMT_BGR4_BYTE +- && srcFormat != PIX_FMT_RGB4_BYTE && dstFormat != PIX_FMT_RGB4_BYTE +- && srcFormat != PIX_FMT_MONOBLACK && dstFormat != PIX_FMT_MONOBLACK +- && srcFormat != PIX_FMT_MONOWHITE && dstFormat != PIX_FMT_MONOWHITE +- && srcFormat != PIX_FMT_RGB48LE && dstFormat != PIX_FMT_RGB48LE +- && srcFormat != PIX_FMT_RGB48BE && dstFormat != PIX_FMT_RGB48BE +- && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) +- c->swScale= rgbToRgbWrapper; +- +- if ((usePal(srcFormat) && ( +- dstFormat == PIX_FMT_RGB32 || +- dstFormat == PIX_FMT_RGB32_1 || +- dstFormat == PIX_FMT_RGB24 || +- dstFormat == PIX_FMT_BGR32 || +- dstFormat == PIX_FMT_BGR32_1 || +- dstFormat == PIX_FMT_BGR24))) +- c->swScale= palToRgbWrapper; +- +- if (srcFormat == PIX_FMT_YUV422P) { +- if (dstFormat == PIX_FMT_YUYV422) +- c->swScale= yuv422pToYuy2Wrapper; +- else if (dstFormat == PIX_FMT_UYVY422) +- c->swScale= yuv422pToUyvyWrapper; +- } +- +- /* LQ converters if -sws 0 or -sws 4*/ +- if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { +- /* yv12_to_yuy2 */ +- if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) { +- if (dstFormat == PIX_FMT_YUYV422) +- c->swScale= planarToYuy2Wrapper; +- else if (dstFormat == PIX_FMT_UYVY422) +- c->swScale= planarToUyvyWrapper; +- } +- } +- if(srcFormat == PIX_FMT_YUYV422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) +- c->swScale= yuyvToYuv420Wrapper; +- if(srcFormat == PIX_FMT_UYVY422 && (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) +- c->swScale= uyvyToYuv420Wrapper; +- if(srcFormat == PIX_FMT_YUYV422 && dstFormat == PIX_FMT_YUV422P) +- c->swScale= yuyvToYuv422Wrapper; +- if(srcFormat == PIX_FMT_UYVY422 && dstFormat == PIX_FMT_YUV422P) +- c->swScale= uyvyToYuv422Wrapper; +- +-#if COMPILE_ALTIVEC +- if ((c->flags & SWS_CPU_CAPS_ALTIVEC) && +- !(c->flags & SWS_BITEXACT) && +- srcFormat == PIX_FMT_YUV420P) { +- // unscaled YV12 -> packed YUV, we want speed +- if (dstFormat == PIX_FMT_YUYV422) +- c->swScale= yv12toyuy2_unscaled_altivec; +- else if (dstFormat == PIX_FMT_UYVY422) +- c->swScale= yv12touyvy_unscaled_altivec; ++ int i, j; ++ for (i=0; i>(7-j))&1)*16383; + } +-#endif ++ if(width&7){ ++ int d= ~src[i]; ++ for(j=0; j<(width&7); j++) ++ dst[8*i+j]= ((d>>(7-j))&1)*16383; ++ } ++} + +- /* simple copy */ +- if ( srcFormat == dstFormat +- || (srcFormat == PIX_FMT_YUVA420P && dstFormat == PIX_FMT_YUV420P) +- || (srcFormat == PIX_FMT_YUV420P && dstFormat == PIX_FMT_YUVA420P) +- || (isPlanarYUV(srcFormat) && isGray(dstFormat)) +- || (isPlanarYUV(dstFormat) && isGray(srcFormat)) +- || (isGray(dstFormat) && isGray(srcFormat)) +- || (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) +- && c->chrDstHSubSample == c->chrSrcHSubSample +- && c->chrDstVSubSample == c->chrSrcVSubSample +- && dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 +- && srcFormat != PIX_FMT_NV12 && srcFormat != PIX_FMT_NV21)) +- { +- if (isPacked(c->srcFormat)) +- c->swScale= packedCopyWrapper; +- else /* Planar YUV or gray */ +- c->swScale= planarCopyWrapper; +- } +-#if ARCH_BFIN +- if (flags & SWS_CPU_CAPS_BFIN) +- ff_bfin_get_unscaled_swscale (c); +-#endif ++static void monoblack2Y_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, uint32_t *unused) ++{ ++ int i, j; ++ for (i=0; i>(7-j))&1)*16383; ++ } ++ if(width&7){ ++ int d= src[i]; ++ for(j=0; j<(width&7); j++) ++ dst[8*i+j]= ((d>>(7-j))&1)*16383; ++ } + } + +-static void reset_ptr(const uint8_t* src[], int format) ++//FIXME yuy2* can read up to 7 samples too much ++ ++static void yuy2ToY_c(uint8_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, ++ uint32_t *unused) + { +- if(!isALPHA(format)) +- src[3]=NULL; +- if(!isPlanarYUV(format)) { +- src[3]=src[2]=NULL; ++ int i; ++ for (i=0; icomp[i].plane; +- if (!data[plane] || !linesizes[plane]) +- return 0; ++static void bswap16UV_c(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *unused0, const uint8_t *_src1, ++ const uint8_t *_src2, int width, uint32_t *unused) ++{ ++ int i; ++ const uint16_t *src1 = (const uint16_t *) _src1, ++ *src2 = (const uint16_t *) _src2; ++ uint16_t *dstU = (uint16_t *) _dstU, *dstV = (uint16_t *) _dstV; ++ for (i=0; isrcFormat, srcStride)) { +- av_log(c, AV_LOG_ERROR, "bad src image pointers\n"); +- return 0; +- } +- if (!check_image_pointers(dst, c->dstFormat, dstStride)) { +- av_log(c, AV_LOG_ERROR, "bad dst image pointers\n"); +- return 0; +- } +- +- if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { +- av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); +- return 0; +- } +- if (c->sliceDir == 0) { +- if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; +- } +- +- if (usePal(c->srcFormat)) { +- for (i=0; i<256; i++) { +- int p, r, g, b,y,u,v; +- if(c->srcFormat == PIX_FMT_PAL8) { +- p=((const uint32_t*)(src[1]))[i]; +- r= (p>>16)&0xFF; +- g= (p>> 8)&0xFF; +- b= p &0xFF; +- } else if(c->srcFormat == PIX_FMT_RGB8) { +- r= (i>>5 )*36; +- g= ((i>>2)&7)*36; +- b= (i&3 )*85; +- } else if(c->srcFormat == PIX_FMT_BGR8) { +- b= (i>>6 )*85; +- g= ((i>>3)&7)*36; +- r= (i&7 )*36; +- } else if(c->srcFormat == PIX_FMT_RGB4_BYTE) { +- r= (i>>3 )*255; +- g= ((i>>1)&3)*85; +- b= (i&1 )*255; +- } else if(c->srcFormat == PIX_FMT_GRAY8 || c->srcFormat == PIX_FMT_Y400A) { +- r = g = b = i; +- } else { +- assert(c->srcFormat == PIX_FMT_BGR4_BYTE); +- b= (i>>3 )*255; +- g= ((i>>1)&3)*85; +- r= (i&1 )*255; +- } +- y= av_clip_uint8((RY*r + GY*g + BY*b + ( 33<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); +- u= av_clip_uint8((RU*r + GU*g + BU*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); +- v= av_clip_uint8((RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT); +- c->pal_yuv[i]= y + (u<<8) + (v<<16); +- +- switch(c->dstFormat) { +- case PIX_FMT_BGR32: +-#if !HAVE_BIGENDIAN +- case PIX_FMT_RGB24: +-#endif +- c->pal_rgb[i]= r + (g<<8) + (b<<16); ++static av_always_inline void nvXXtoUV_c(uint8_t *dst1, uint8_t *dst2, ++ const uint8_t *src, int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ dst1[i] = src[2*i+0]; ++ dst2[i] = src[2*i+1]; ++ } ++} ++ ++static void nv12ToUV_c(uint8_t *dstU, uint8_t *dstV, ++ const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2, ++ int width, uint32_t *unused) ++{ ++ nvXXtoUV_c(dstU, dstV, src1, width); ++} ++ ++static void nv21ToUV_c(uint8_t *dstU, uint8_t *dstV, ++ const uint8_t *unused0, const uint8_t *src1, const uint8_t *src2, ++ int width, uint32_t *unused) ++{ ++ nvXXtoUV_c(dstV, dstU, src1, width); ++} ++ ++#define input_pixel(pos) (isBE(origin) ? AV_RB16(pos) : AV_RL16(pos)) ++ ++static void bgr24ToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, ++ int width, uint32_t *unused) ++{ ++ int i; ++ for (i=0; i>(RGB2YUV_SHIFT-6)); ++ } ++} ++ ++static void bgr24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1, ++ const uint8_t *src2, int width, uint32_t *unused) ++{ ++ int i; ++ for (i=0; i>(RGB2YUV_SHIFT-6); ++ dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6); ++ } ++ assert(src1 == src2); ++} ++ ++static void bgr24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1, ++ const uint8_t *src2, int width, uint32_t *unused) ++{ ++ int i; ++ for (i=0; i>(RGB2YUV_SHIFT-5); ++ dstV[i]= (RV*r + GV*g + BV*b + (256<>(RGB2YUV_SHIFT-5); ++ } ++ assert(src1 == src2); ++} ++ ++static void rgb24ToY_c(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, int width, ++ uint32_t *unused) ++{ ++ int i; ++ for (i=0; i>(RGB2YUV_SHIFT-6)); ++ } ++} ++ ++static void rgb24ToUV_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1, ++ const uint8_t *src2, int width, uint32_t *unused) ++{ ++ int i; ++ assert(src1==src2); ++ for (i=0; i>(RGB2YUV_SHIFT-6); ++ dstV[i]= (RV*r + GV*g + BV*b + (256<<(RGB2YUV_SHIFT-1)) + (1<<(RGB2YUV_SHIFT-7)))>>(RGB2YUV_SHIFT-6); ++ } ++} ++ ++static void rgb24ToUV_half_c(int16_t *dstU, int16_t *dstV, const uint8_t *unused0, const uint8_t *src1, ++ const uint8_t *src2, int width, uint32_t *unused) ++{ ++ int i; ++ assert(src1==src2); ++ for (i=0; i>(RGB2YUV_SHIFT-5); ++ dstV[i]= (RV*r + GV*g + BV*b + (256<>(RGB2YUV_SHIFT-5); ++ } ++} ++ ++static void planar_rgb_to_y(uint16_t *dst, const uint8_t *src[4], int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ int g = src[0][i]; ++ int b = src[1][i]; ++ int r = src[2][i]; ++ ++ dst[i] = (RY*r + GY*g + BY*b + (0x801<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); ++ } ++} ++ ++static void planar_rgb16le_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) ++{ ++ int i; ++ const uint16_t **src = (const uint16_t **) _src; ++ uint16_t *dst = (uint16_t *) _dst; ++ for (i = 0; i < width; i++) { ++ int g = AV_RL16(src[0] + i); ++ int b = AV_RL16(src[1] + i); ++ int r = AV_RL16(src[2] + i); ++ ++ dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); ++ } ++} ++ ++static void planar_rgb16be_to_y(uint8_t *_dst, const uint8_t *_src[4], int width) ++{ ++ int i; ++ const uint16_t **src = (const uint16_t **) _src; ++ uint16_t *dst = (uint16_t *) _dst; ++ for (i = 0; i < width; i++) { ++ int g = AV_RB16(src[0] + i); ++ int b = AV_RB16(src[1] + i); ++ int r = AV_RB16(src[2] + i); ++ ++ dst[i] = ((RY * r + GY * g + BY * b + (33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); ++ } ++} ++ ++static void planar_rgb_to_uv(uint16_t *dstU, uint16_t *dstV, const uint8_t *src[4], int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ int g = src[0][i]; ++ int b = src[1][i]; ++ int r = src[2][i]; ++ ++ dstU[i] = (RU*r + GU*g + BU*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); ++ dstV[i] = (RV*r + GV*g + BV*b + (0x4001<<(RGB2YUV_SHIFT-7))) >> (RGB2YUV_SHIFT-6); ++ } ++} ++ ++static void planar_rgb16le_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width) ++{ ++ int i; ++ const uint16_t **src = (const uint16_t **) _src; ++ uint16_t *dstU = (uint16_t *) _dstU; ++ uint16_t *dstV = (uint16_t *) _dstV; ++ for (i = 0; i < width; i++) { ++ int g = AV_RL16(src[0] + i); ++ int b = AV_RL16(src[1] + i); ++ int r = AV_RL16(src[2] + i); ++ ++ dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); ++ dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); ++ } ++} ++ ++static void planar_rgb16be_to_uv(uint8_t *_dstU, uint8_t *_dstV, const uint8_t *_src[4], int width) ++{ ++ int i; ++ const uint16_t **src = (const uint16_t **) _src; ++ uint16_t *dstU = (uint16_t *) _dstU; ++ uint16_t *dstV = (uint16_t *) _dstV; ++ for (i = 0; i < width; i++) { ++ int g = AV_RB16(src[0] + i); ++ int b = AV_RB16(src[1] + i); ++ int r = AV_RB16(src[2] + i); ++ ++ dstU[i] = (RU * r + GU * g + BU * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); ++ dstV[i] = (RV * r + GV * g + BV * b + (257 << RGB2YUV_SHIFT)) >> (RGB2YUV_SHIFT + 1); ++ } ++} ++ ++static void hScale16To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *_src, ++ const int16_t *filter, ++ const int32_t *filterPos, int filterSize) ++{ ++ int i; ++ int32_t *dst = (int32_t *) _dst; ++ const uint16_t *src = (const uint16_t *) _src; ++ int bits = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1; ++ int sh = bits - 4; ++ ++ if((isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15) ++ sh= 9; ++ ++ for (i = 0; i < dstW; i++) { ++ int j; ++ int srcPos = filterPos[i]; ++ int val = 0; ++ ++ for (j = 0; j < filterSize; j++) { ++ val += src[srcPos + j] * filter[filterSize * i + j]; ++ } ++ // filter=14 bit, input=16 bit, output=30 bit, >> 11 makes 19 bit ++ dst[i] = FFMIN(val >> sh, (1 << 19) - 1); ++ } ++} ++ ++static void hScale16To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *_src, ++ const int16_t *filter, ++ const int32_t *filterPos, int filterSize) ++{ ++ int i; ++ const uint16_t *src = (const uint16_t *) _src; ++ int sh = av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1; ++ ++ if(sh<15) ++ sh= isAnyRGB(c->srcFormat) || c->srcFormat==PIX_FMT_PAL8 ? 13 : av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1; ++ ++ for (i = 0; i < dstW; i++) { ++ int j; ++ int srcPos = filterPos[i]; ++ int val = 0; ++ ++ for (j = 0; j < filterSize; j++) { ++ val += src[srcPos + j] * filter[filterSize * i + j]; ++ } ++ // filter=14 bit, input=16 bit, output=30 bit, >> 15 makes 15 bit ++ dst[i] = FFMIN(val >> sh, (1 << 15) - 1); ++ } ++} ++ ++// bilinear / bicubic scaling ++static void hScale8To15_c(SwsContext *c, int16_t *dst, int dstW, const uint8_t *src, ++ const int16_t *filter, const int32_t *filterPos, ++ int filterSize) ++{ ++ int i; ++ for (i=0; i>7, (1<<15)-1); // the cubic equation does overflow ... ++ //dst[i] = val>>7; ++ } ++} ++ ++static void hScale8To19_c(SwsContext *c, int16_t *_dst, int dstW, const uint8_t *src, ++ const int16_t *filter, const int32_t *filterPos, ++ int filterSize) ++{ ++ int i; ++ int32_t *dst = (int32_t *) _dst; ++ for (i=0; i>3, (1<<19)-1); // the cubic equation does overflow ... ++ //dst[i] = val>>7; ++ } ++} ++ ++//FIXME all pal and rgb srcFormats could do this convertion as well ++//FIXME all scalers more complex than bilinear could do half of this transform ++static void chrRangeToJpeg_c(int16_t *dstU, int16_t *dstV, int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ dstU[i] = (FFMIN(dstU[i],30775)*4663 - 9289992)>>12; //-264 ++ dstV[i] = (FFMIN(dstV[i],30775)*4663 - 9289992)>>12; //-264 ++ } ++} ++static void chrRangeFromJpeg_c(int16_t *dstU, int16_t *dstV, int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) { ++ dstU[i] = (dstU[i]*1799 + 4081085)>>11; //1469 ++ dstV[i] = (dstV[i]*1799 + 4081085)>>11; //1469 ++ } ++} ++static void lumRangeToJpeg_c(int16_t *dst, int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) ++ dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14; ++} ++static void lumRangeFromJpeg_c(int16_t *dst, int width) ++{ ++ int i; ++ for (i = 0; i < width; i++) ++ dst[i] = (dst[i]*14071 + 33561947)>>14; ++} ++ ++static void chrRangeToJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width) ++{ ++ int i; ++ int32_t *dstU = (int32_t *) _dstU; ++ int32_t *dstV = (int32_t *) _dstV; ++ for (i = 0; i < width; i++) { ++ dstU[i] = (FFMIN(dstU[i],30775<<4)*4663 - (9289992<<4))>>12; //-264 ++ dstV[i] = (FFMIN(dstV[i],30775<<4)*4663 - (9289992<<4))>>12; //-264 ++ } ++} ++static void chrRangeFromJpeg16_c(int16_t *_dstU, int16_t *_dstV, int width) ++{ ++ int i; ++ int32_t *dstU = (int32_t *) _dstU; ++ int32_t *dstV = (int32_t *) _dstV; ++ for (i = 0; i < width; i++) { ++ dstU[i] = (dstU[i]*1799 + (4081085<<4))>>11; //1469 ++ dstV[i] = (dstV[i]*1799 + (4081085<<4))>>11; //1469 ++ } ++} ++static void lumRangeToJpeg16_c(int16_t *_dst, int width) ++{ ++ int i; ++ int32_t *dst = (int32_t *) _dst; ++ for (i = 0; i < width; i++) ++ dst[i] = (FFMIN(dst[i],30189<<4)*4769 - (39057361<<2))>>12; ++} ++static void lumRangeFromJpeg16_c(int16_t *_dst, int width) ++{ ++ int i; ++ int32_t *dst = (int32_t *) _dst; ++ for (i = 0; i < width; i++) ++ dst[i] = (dst[i]*(14071/4) + (33561947<<4)/4)>>12; ++} ++ ++static void hyscale_fast_c(SwsContext *c, int16_t *dst, int dstWidth, ++ const uint8_t *src, int srcW, int xInc) ++{ ++ int i; ++ unsigned int xpos=0; ++ for (i=0;i>16; ++ register unsigned int xalpha=(xpos&0xFFFF)>>9; ++ dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha; ++ xpos+=xInc; ++ } ++ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) ++ dst[i] = src[srcW-1]*128; ++} ++ ++// *** horizontal scale Y line to temp buffer ++static av_always_inline void hyscale(SwsContext *c, int16_t *dst, int dstWidth, ++ const uint8_t *src_in[4], int srcW, int xInc, ++ const int16_t *hLumFilter, ++ const int32_t *hLumFilterPos, int hLumFilterSize, ++ uint8_t *formatConvBuffer, ++ uint32_t *pal, int isAlpha) ++{ ++ void (*toYV12)(uint8_t *, const uint8_t *, const uint8_t *, const uint8_t *, int, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12; ++ void (*convertRange)(int16_t *, int) = isAlpha ? NULL : c->lumConvertRange; ++ const uint8_t *src = src_in[isAlpha ? 3 : 0]; ++ ++ if (toYV12) { ++ toYV12(formatConvBuffer, src, src_in[1], src_in[2], srcW, pal); ++ src= formatConvBuffer; ++ } else if (c->readLumPlanar && !isAlpha) { ++ c->readLumPlanar(formatConvBuffer, src_in, srcW); ++ src = formatConvBuffer; ++ } ++ ++ if (!c->hyscale_fast) { ++ c->hyScale(c, dst, dstWidth, src, hLumFilter, hLumFilterPos, hLumFilterSize); ++ } else { // fast bilinear upscale / crap downscale ++ c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc); ++ } ++ ++ if (convertRange) ++ convertRange(dst, dstWidth); ++} ++ ++static void hcscale_fast_c(SwsContext *c, int16_t *dst1, int16_t *dst2, ++ int dstWidth, const uint8_t *src1, ++ const uint8_t *src2, int srcW, int xInc) ++{ ++ int i; ++ unsigned int xpos=0; ++ for (i=0;i>16; ++ register unsigned int xalpha=(xpos&0xFFFF)>>9; ++ dst1[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha); ++ dst2[i]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha); ++ xpos+=xInc; ++ } ++ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { ++ dst1[i] = src1[srcW-1]*128; ++ dst2[i] = src2[srcW-1]*128; ++ } ++} ++ ++static av_always_inline void hcscale(SwsContext *c, int16_t *dst1, int16_t *dst2, int dstWidth, ++ const uint8_t *src_in[4], ++ int srcW, int xInc, const int16_t *hChrFilter, ++ const int32_t *hChrFilterPos, int hChrFilterSize, ++ uint8_t *formatConvBuffer, uint32_t *pal) ++{ ++ const uint8_t *src1 = src_in[1], *src2 = src_in[2]; ++ if (c->chrToYV12) { ++ uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW*2+78, 16); ++ c->chrToYV12(formatConvBuffer, buf2, src_in[0], src1, src2, srcW, pal); ++ src1= formatConvBuffer; ++ src2= buf2; ++ } else if (c->readChrPlanar) { ++ uint8_t *buf2 = formatConvBuffer + FFALIGN(srcW*2+78, 16); ++ c->readChrPlanar(formatConvBuffer, buf2, src_in, srcW); ++ src1= formatConvBuffer; ++ src2= buf2; ++ } ++ ++ if (!c->hcscale_fast) { ++ c->hcScale(c, dst1, dstWidth, src1, hChrFilter, hChrFilterPos, hChrFilterSize); ++ c->hcScale(c, dst2, dstWidth, src2, hChrFilter, hChrFilterPos, hChrFilterSize); ++ } else { // fast bilinear upscale / crap downscale ++ c->hcscale_fast(c, dst1, dst2, dstWidth, src1, src2, srcW, xInc); ++ } ++ ++ if (c->chrConvertRange) ++ c->chrConvertRange(dst1, dst2, dstWidth); ++} ++ ++static av_always_inline void ++find_c_packed_planar_out_funcs(SwsContext *c, ++ yuv2planar1_fn *yuv2plane1, yuv2planarX_fn *yuv2planeX, ++ yuv2interleavedX_fn *yuv2nv12cX, ++ yuv2packed1_fn *yuv2packed1, yuv2packed2_fn *yuv2packed2, ++ yuv2packedX_fn *yuv2packedX) ++{ ++ enum PixelFormat dstFormat = c->dstFormat; ++ ++ if (is16BPS(dstFormat)) { ++ *yuv2planeX = isBE(dstFormat) ? yuv2planeX_16BE_c : yuv2planeX_16LE_c; ++ *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_16BE_c : yuv2plane1_16LE_c; ++ } else if (is9_OR_10BPS(dstFormat)) { ++ if (av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1 == 8) { ++ *yuv2planeX = isBE(dstFormat) ? yuv2planeX_9BE_c : yuv2planeX_9LE_c; ++ *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_9BE_c : yuv2plane1_9LE_c; ++ } else { ++ *yuv2planeX = isBE(dstFormat) ? yuv2planeX_10BE_c : yuv2planeX_10LE_c; ++ *yuv2plane1 = isBE(dstFormat) ? yuv2plane1_10BE_c : yuv2plane1_10LE_c; ++ } ++ } else { ++ *yuv2plane1 = yuv2plane1_8_c; ++ *yuv2planeX = yuv2planeX_8_c; ++ if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) ++ *yuv2nv12cX = yuv2nv12cX_c; ++ } ++ ++ if(c->flags & SWS_FULL_CHR_H_INT) { ++ switch (dstFormat) { ++ case PIX_FMT_RGBA: ++#if CONFIG_SMALL ++ *yuv2packedX = yuv2rgba32_full_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packedX = yuv2rgba32_full_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packedX = yuv2rgbx32_full_X_c; ++ } ++#endif /* !CONFIG_SMALL */ + break; +- case PIX_FMT_BGR32_1: +-#if HAVE_BIGENDIAN +- case PIX_FMT_BGR24: +-#endif +- c->pal_rgb[i]= (r + (g<<8) + (b<<16)) << 8; ++ case PIX_FMT_ARGB: ++#if CONFIG_SMALL ++ *yuv2packedX = yuv2argb32_full_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packedX = yuv2argb32_full_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packedX = yuv2xrgb32_full_X_c; ++ } ++#endif /* !CONFIG_SMALL */ ++ break; ++ case PIX_FMT_BGRA: ++#if CONFIG_SMALL ++ *yuv2packedX = yuv2bgra32_full_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packedX = yuv2bgra32_full_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packedX = yuv2bgrx32_full_X_c; ++ } ++#endif /* !CONFIG_SMALL */ ++ break; ++ case PIX_FMT_ABGR: ++#if CONFIG_SMALL ++ *yuv2packedX = yuv2abgr32_full_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packedX = yuv2abgr32_full_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packedX = yuv2xbgr32_full_X_c; ++ } ++#endif /* !CONFIG_SMALL */ + break; +- case PIX_FMT_RGB32_1: +-#if HAVE_BIGENDIAN + case PIX_FMT_RGB24: +-#endif +- c->pal_rgb[i]= (b + (g<<8) + (r<<16)) << 8; ++ *yuv2packedX = yuv2rgb24_full_X_c; ++ break; ++ case PIX_FMT_BGR24: ++ *yuv2packedX = yuv2bgr24_full_X_c; ++ break; ++ } ++ if(!*yuv2packedX) ++ goto YUV_PACKED; ++ } else { ++ YUV_PACKED: ++ switch (dstFormat) { ++ case PIX_FMT_RGB48LE: ++ *yuv2packed1 = yuv2rgb48le_1_c; ++ *yuv2packed2 = yuv2rgb48le_2_c; ++ *yuv2packedX = yuv2rgb48le_X_c; ++ break; ++ case PIX_FMT_RGB48BE: ++ *yuv2packed1 = yuv2rgb48be_1_c; ++ *yuv2packed2 = yuv2rgb48be_2_c; ++ *yuv2packedX = yuv2rgb48be_X_c; ++ break; ++ case PIX_FMT_BGR48LE: ++ *yuv2packed1 = yuv2bgr48le_1_c; ++ *yuv2packed2 = yuv2bgr48le_2_c; ++ *yuv2packedX = yuv2bgr48le_X_c; ++ break; ++ case PIX_FMT_BGR48BE: ++ *yuv2packed1 = yuv2bgr48be_1_c; ++ *yuv2packed2 = yuv2bgr48be_2_c; ++ *yuv2packedX = yuv2bgr48be_X_c; ++ break; ++ case PIX_FMT_RGB32: ++ case PIX_FMT_BGR32: ++#if CONFIG_SMALL ++ *yuv2packed1 = yuv2rgb32_1_c; ++ *yuv2packed2 = yuv2rgb32_2_c; ++ *yuv2packedX = yuv2rgb32_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packed1 = yuv2rgba32_1_c; ++ *yuv2packed2 = yuv2rgba32_2_c; ++ *yuv2packedX = yuv2rgba32_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packed1 = yuv2rgbx32_1_c; ++ *yuv2packed2 = yuv2rgbx32_2_c; ++ *yuv2packedX = yuv2rgbx32_X_c; ++ } ++#endif /* !CONFIG_SMALL */ ++ break; ++ case PIX_FMT_RGB32_1: ++ case PIX_FMT_BGR32_1: ++#if CONFIG_SMALL ++ *yuv2packed1 = yuv2rgb32_1_1_c; ++ *yuv2packed2 = yuv2rgb32_1_2_c; ++ *yuv2packedX = yuv2rgb32_1_X_c; ++#else ++#if CONFIG_SWSCALE_ALPHA ++ if (c->alpPixBuf) { ++ *yuv2packed1 = yuv2rgba32_1_1_c; ++ *yuv2packed2 = yuv2rgba32_1_2_c; ++ *yuv2packedX = yuv2rgba32_1_X_c; ++ } else ++#endif /* CONFIG_SWSCALE_ALPHA */ ++ { ++ *yuv2packed1 = yuv2rgbx32_1_1_c; ++ *yuv2packed2 = yuv2rgbx32_1_2_c; ++ *yuv2packedX = yuv2rgbx32_1_X_c; ++ } ++#endif /* !CONFIG_SMALL */ + break; +- case PIX_FMT_RGB32: +-#if !HAVE_BIGENDIAN +- case PIX_FMT_BGR24: +-#endif +- default: +- c->pal_rgb[i]= b + (g<<8) + (r<<16); ++ case PIX_FMT_RGB24: ++ *yuv2packed1 = yuv2rgb24_1_c; ++ *yuv2packed2 = yuv2rgb24_2_c; ++ *yuv2packedX = yuv2rgb24_X_c; ++ break; ++ case PIX_FMT_BGR24: ++ *yuv2packed1 = yuv2bgr24_1_c; ++ *yuv2packed2 = yuv2bgr24_2_c; ++ *yuv2packedX = yuv2bgr24_X_c; ++ break; ++ case PIX_FMT_RGB565LE: ++ case PIX_FMT_RGB565BE: ++ case PIX_FMT_BGR565LE: ++ case PIX_FMT_BGR565BE: ++ *yuv2packed1 = yuv2rgb16_1_c; ++ *yuv2packed2 = yuv2rgb16_2_c; ++ *yuv2packedX = yuv2rgb16_X_c; ++ break; ++ case PIX_FMT_RGB555LE: ++ case PIX_FMT_RGB555BE: ++ case PIX_FMT_BGR555LE: ++ case PIX_FMT_BGR555BE: ++ *yuv2packed1 = yuv2rgb15_1_c; ++ *yuv2packed2 = yuv2rgb15_2_c; ++ *yuv2packedX = yuv2rgb15_X_c; ++ break; ++ case PIX_FMT_RGB444LE: ++ case PIX_FMT_RGB444BE: ++ case PIX_FMT_BGR444LE: ++ case PIX_FMT_BGR444BE: ++ *yuv2packed1 = yuv2rgb12_1_c; ++ *yuv2packed2 = yuv2rgb12_2_c; ++ *yuv2packedX = yuv2rgb12_X_c; ++ break; ++ case PIX_FMT_RGB8: ++ case PIX_FMT_BGR8: ++ *yuv2packed1 = yuv2rgb8_1_c; ++ *yuv2packed2 = yuv2rgb8_2_c; ++ *yuv2packedX = yuv2rgb8_X_c; ++ break; ++ case PIX_FMT_RGB4: ++ case PIX_FMT_BGR4: ++ *yuv2packed1 = yuv2rgb4_1_c; ++ *yuv2packed2 = yuv2rgb4_2_c; ++ *yuv2packedX = yuv2rgb4_X_c; ++ break; ++ case PIX_FMT_RGB4_BYTE: ++ case PIX_FMT_BGR4_BYTE: ++ *yuv2packed1 = yuv2rgb4b_1_c; ++ *yuv2packed2 = yuv2rgb4b_2_c; ++ *yuv2packedX = yuv2rgb4b_X_c; ++ break; ++ } ++ } ++ switch (dstFormat) { ++ case PIX_FMT_GRAY16BE: ++ *yuv2packed1 = yuv2gray16BE_1_c; ++ *yuv2packed2 = yuv2gray16BE_2_c; ++ *yuv2packedX = yuv2gray16BE_X_c; ++ break; ++ case PIX_FMT_GRAY16LE: ++ *yuv2packed1 = yuv2gray16LE_1_c; ++ *yuv2packed2 = yuv2gray16LE_2_c; ++ *yuv2packedX = yuv2gray16LE_X_c; ++ break; ++ case PIX_FMT_MONOWHITE: ++ *yuv2packed1 = yuv2monowhite_1_c; ++ *yuv2packed2 = yuv2monowhite_2_c; ++ *yuv2packedX = yuv2monowhite_X_c; ++ break; ++ case PIX_FMT_MONOBLACK: ++ *yuv2packed1 = yuv2monoblack_1_c; ++ *yuv2packed2 = yuv2monoblack_2_c; ++ *yuv2packedX = yuv2monoblack_X_c; ++ break; ++ case PIX_FMT_YUYV422: ++ *yuv2packed1 = yuv2yuyv422_1_c; ++ *yuv2packed2 = yuv2yuyv422_2_c; ++ *yuv2packedX = yuv2yuyv422_X_c; ++ break; ++ case PIX_FMT_UYVY422: ++ *yuv2packed1 = yuv2uyvy422_1_c; ++ *yuv2packed2 = yuv2uyvy422_2_c; ++ *yuv2packedX = yuv2uyvy422_X_c; ++ break; ++ } ++} ++ ++#define DEBUG_SWSCALE_BUFFERS 0 ++#define DEBUG_BUFFERS(...) if (DEBUG_SWSCALE_BUFFERS) av_log(c, AV_LOG_DEBUG, __VA_ARGS__) ++ ++static int swScale(SwsContext *c, const uint8_t* src[], ++ int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t* dst[], int dstStride[]) ++{ ++ /* load a few things into local vars to make the code more readable? and faster */ ++ const int srcW= c->srcW; ++ const int dstW= c->dstW; ++ const int dstH= c->dstH; ++ const int chrDstW= c->chrDstW; ++ const int chrSrcW= c->chrSrcW; ++ const int lumXInc= c->lumXInc; ++ const int chrXInc= c->chrXInc; ++ const enum PixelFormat dstFormat= c->dstFormat; ++ const int flags= c->flags; ++ int32_t *vLumFilterPos= c->vLumFilterPos; ++ int32_t *vChrFilterPos= c->vChrFilterPos; ++ int32_t *hLumFilterPos= c->hLumFilterPos; ++ int32_t *hChrFilterPos= c->hChrFilterPos; ++ int16_t *hLumFilter= c->hLumFilter; ++ int16_t *hChrFilter= c->hChrFilter; ++ int32_t *lumMmxFilter= c->lumMmxFilter; ++ int32_t *chrMmxFilter= c->chrMmxFilter; ++ int32_t av_unused *alpMmxFilter= c->alpMmxFilter; ++ const int vLumFilterSize= c->vLumFilterSize; ++ const int vChrFilterSize= c->vChrFilterSize; ++ const int hLumFilterSize= c->hLumFilterSize; ++ const int hChrFilterSize= c->hChrFilterSize; ++ int16_t **lumPixBuf= c->lumPixBuf; ++ int16_t **chrUPixBuf= c->chrUPixBuf; ++ int16_t **chrVPixBuf= c->chrVPixBuf; ++ int16_t **alpPixBuf= c->alpPixBuf; ++ const int vLumBufSize= c->vLumBufSize; ++ const int vChrBufSize= c->vChrBufSize; ++ uint8_t *formatConvBuffer= c->formatConvBuffer; ++ const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; ++ const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); ++ int lastDstY; ++ uint32_t *pal=c->pal_yuv; ++ int should_dither= isNBPS(c->srcFormat) || is16BPS(c->srcFormat); ++ ++ yuv2planar1_fn yuv2plane1 = c->yuv2plane1; ++ yuv2planarX_fn yuv2planeX = c->yuv2planeX; ++ yuv2interleavedX_fn yuv2nv12cX = c->yuv2nv12cX; ++ yuv2packed1_fn yuv2packed1 = c->yuv2packed1; ++ yuv2packed2_fn yuv2packed2 = c->yuv2packed2; ++ yuv2packedX_fn yuv2packedX = c->yuv2packedX; ++ ++ /* vars which will change and which we need to store back in the context */ ++ int dstY= c->dstY; ++ int lumBufIndex= c->lumBufIndex; ++ int chrBufIndex= c->chrBufIndex; ++ int lastInLumBuf= c->lastInLumBuf; ++ int lastInChrBuf= c->lastInChrBuf; ++ ++ if (isPacked(c->srcFormat)) { ++ src[0]= ++ src[1]= ++ src[2]= ++ src[3]= src[0]; ++ srcStride[0]= ++ srcStride[1]= ++ srcStride[2]= ++ srcStride[3]= srcStride[0]; ++ } ++ srcStride[1]<<= c->vChrDrop; ++ srcStride[2]<<= c->vChrDrop; ++ ++ DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n", ++ src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3], ++ dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]); ++ DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n", ++ srcSliceY, srcSliceH, dstY, dstH); ++ DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n", ++ vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize); ++ ++ if (dstStride[0]%16 !=0 || dstStride[1]%16 !=0 || dstStride[2]%16 !=0 || dstStride[3]%16 != 0) { ++ static int warnedAlready=0; //FIXME move this into the context perhaps ++ if (flags & SWS_PRINT_INFO && !warnedAlready) { ++ av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n" ++ " ->cannot do aligned memory accesses anymore\n"); ++ warnedAlready=1; ++ } ++ } ++ ++ if ((int)dst[0]%16 || (int)dst[1]%16 || (int)dst[2]%16 || (int)src[0]%16 || (int)src[1]%16 || (int)src[2]%16 ++ || dstStride[0]%16 || dstStride[1]%16 || dstStride[2]%16 || dstStride[3]%16 ++ || srcStride[0]%16 || srcStride[1]%16 || srcStride[2]%16 || srcStride[3]%16 ++ ) { ++ static int warnedAlready=0; ++ int cpu_flags = av_get_cpu_flags(); ++ if (HAVE_MMX2 && (cpu_flags & AV_CPU_FLAG_SSE2) && !warnedAlready){ ++ av_log(c, AV_LOG_WARNING, "Warning: data is not aligned! This can lead to a speedloss\n"); ++ warnedAlready=1; ++ } ++ } ++ ++ /* Note the user might start scaling the picture in the middle so this ++ will not get executed. This is not really intended but works ++ currently, so people might do it. */ ++ if (srcSliceY ==0) { ++ lumBufIndex=-1; ++ chrBufIndex=-1; ++ dstY=0; ++ lastInLumBuf= -1; ++ lastInChrBuf= -1; ++ } ++ ++ if (!should_dither) { ++ c->chrDither8 = c->lumDither8 = ff_sws_pb_64; ++ } ++ lastDstY= dstY; ++ ++ for (;dstY < dstH; dstY++) { ++ const int chrDstY= dstY>>c->chrDstVSubSample; ++ uint8_t *dest[4] = { ++ dst[0] + dstStride[0] * dstY, ++ dst[1] + dstStride[1] * chrDstY, ++ dst[2] + dstStride[2] * chrDstY, ++ (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3] + dstStride[3] * dstY : NULL, ++ }; ++ int use_mmx_vfilter= c->use_mmx_vfilter; ++ ++ const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input ++ const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<chrDstVSubSample) - 1), dstH-1)]; ++ const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input ++ int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input ++ int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input ++ int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input ++ int enough_lines; ++ ++ //handle holes (FAST_BILINEAR & weird filters) ++ if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; ++ if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; ++ assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1); ++ assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1); ++ ++ DEBUG_BUFFERS("dstY: %d\n", dstY); ++ DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n", ++ firstLumSrcY, lastLumSrcY, lastInLumBuf); ++ DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n", ++ firstChrSrcY, lastChrSrcY, lastInChrBuf); ++ ++ // Do we have enough lines in this slice to output the dstY line ++ enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample); ++ ++ if (!enough_lines) { ++ lastLumSrcY = srcSliceY + srcSliceH - 1; ++ lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1; ++ DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n", ++ lastLumSrcY, lastChrSrcY); ++ } ++ ++ //Do horizontal scaling ++ while(lastInLumBuf < lastLumSrcY) { ++ const uint8_t *src1[4] = { ++ src[0] + (lastInLumBuf + 1 - srcSliceY) * srcStride[0], ++ src[1] + (lastInLumBuf + 1 - srcSliceY) * srcStride[1], ++ src[2] + (lastInLumBuf + 1 - srcSliceY) * srcStride[2], ++ src[3] + (lastInLumBuf + 1 - srcSliceY) * srcStride[3], ++ }; ++ lumBufIndex++; ++ assert(lumBufIndex < 2*vLumBufSize); ++ assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); ++ assert(lastInLumBuf + 1 - srcSliceY >= 0); ++ hyscale(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc, ++ hLumFilter, hLumFilterPos, hLumFilterSize, ++ formatConvBuffer, ++ pal, 0); ++ if (CONFIG_SWSCALE_ALPHA && alpPixBuf) ++ hyscale(c, alpPixBuf[ lumBufIndex ], dstW, src1, srcW, ++ lumXInc, hLumFilter, hLumFilterPos, hLumFilterSize, ++ formatConvBuffer, ++ pal, 1); ++ lastInLumBuf++; ++ DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n", ++ lumBufIndex, lastInLumBuf); ++ } ++ while(lastInChrBuf < lastChrSrcY) { ++ const uint8_t *src1[4] = { ++ src[0] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[0], ++ src[1] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[1], ++ src[2] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[2], ++ src[3] + (lastInChrBuf + 1 - chrSrcSliceY) * srcStride[3], ++ }; ++ chrBufIndex++; ++ assert(chrBufIndex < 2*vChrBufSize); ++ assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)); ++ assert(lastInChrBuf + 1 - chrSrcSliceY >= 0); ++ //FIXME replace parameters through context struct (some at least) ++ ++ if (c->needs_hcscale) ++ hcscale(c, chrUPixBuf[chrBufIndex], chrVPixBuf[chrBufIndex], ++ chrDstW, src1, chrSrcW, chrXInc, ++ hChrFilter, hChrFilterPos, hChrFilterSize, ++ formatConvBuffer, pal); ++ lastInChrBuf++; ++ DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n", ++ chrBufIndex, lastInChrBuf); ++ } ++ //wrap buf index around to stay inside the ring buffer ++ if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; ++ if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; ++ if (!enough_lines) ++ break; //we can't output a dstY line so let's try with the next slice ++ ++#if HAVE_MMX ++ updateMMXDitherTables(c, dstY, lumBufIndex, chrBufIndex, lastInLumBuf, lastInChrBuf); ++#endif ++ if (should_dither) { ++ c->chrDither8 = dither_8x8_128[chrDstY & 7]; ++ c->lumDither8 = dither_8x8_128[dstY & 7]; ++ } ++ if (dstY >= dstH-2) { ++ // hmm looks like we can't use MMX here without overwriting this array's tail ++ find_c_packed_planar_out_funcs(c, &yuv2plane1, &yuv2planeX, &yuv2nv12cX, ++ &yuv2packed1, &yuv2packed2, &yuv2packedX); ++ use_mmx_vfilter= 0; ++ } ++ ++ { ++ const int16_t **lumSrcPtr= (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; ++ const int16_t **chrUSrcPtr= (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; ++ const int16_t **chrVSrcPtr= (const int16_t **)(void*) chrVPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; ++ const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; ++ int16_t *vLumFilter= c->vLumFilter; ++ int16_t *vChrFilter= c->vChrFilter; ++ ++ if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like ++ const int chrSkipMask= (1<chrDstVSubSample)-1; ++ ++ vLumFilter += dstY * vLumFilterSize; ++ vChrFilter += chrDstY * vChrFilterSize; ++ ++ av_assert0(use_mmx_vfilter != ( ++ yuv2planeX == yuv2planeX_10BE_c ++ || yuv2planeX == yuv2planeX_10LE_c ++ || yuv2planeX == yuv2planeX_9BE_c ++ || yuv2planeX == yuv2planeX_9LE_c ++ || yuv2planeX == yuv2planeX_16BE_c ++ || yuv2planeX == yuv2planeX_16LE_c ++ || yuv2planeX == yuv2planeX_8_c) || !ARCH_X86); ++ ++ if(use_mmx_vfilter){ ++ vLumFilter= c->lumMmxFilter; ++ vChrFilter= c->chrMmxFilter; ++ } ++ ++ if (vLumFilterSize == 1) { ++ yuv2plane1(lumSrcPtr[0], dest[0], dstW, c->lumDither8, 0); ++ } else { ++ yuv2planeX(vLumFilter, vLumFilterSize, ++ lumSrcPtr, dest[0], dstW, c->lumDither8, 0); ++ } ++ ++ if (!((dstY&chrSkipMask) || isGray(dstFormat))) { ++ if (yuv2nv12cX) { ++ yuv2nv12cX(c, vChrFilter, vChrFilterSize, chrUSrcPtr, chrVSrcPtr, dest[1], chrDstW); ++ } else if (vChrFilterSize == 1) { ++ yuv2plane1(chrUSrcPtr[0], dest[1], chrDstW, c->chrDither8, 0); ++ yuv2plane1(chrVSrcPtr[0], dest[2], chrDstW, c->chrDither8, 3); ++ } else { ++ yuv2planeX(vChrFilter, vChrFilterSize, ++ chrUSrcPtr, dest[1], chrDstW, c->chrDither8, 0); ++ yuv2planeX(vChrFilter, vChrFilterSize, ++ chrVSrcPtr, dest[2], chrDstW, c->chrDither8, use_mmx_vfilter ? (c->uv_offx2 >> 1) : 3); ++ } ++ } ++ ++ if (CONFIG_SWSCALE_ALPHA && alpPixBuf){ ++ if(use_mmx_vfilter){ ++ vLumFilter= c->alpMmxFilter; ++ } ++ if (vLumFilterSize == 1) { ++ yuv2plane1(alpSrcPtr[0], dest[3], dstW, c->lumDither8, 0); ++ } else { ++ yuv2planeX(vLumFilter, vLumFilterSize, ++ alpSrcPtr, dest[3], dstW, c->lumDither8, 0); ++ } ++ } ++ } else { ++ assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); ++ assert(chrUSrcPtr + vChrFilterSize - 1 < chrUPixBuf + vChrBufSize*2); ++ if (c->yuv2packed1 && vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB ++ int chrAlpha = vChrFilter[2 * dstY + 1]; ++ yuv2packed1(c, *lumSrcPtr, chrUSrcPtr, chrVSrcPtr, ++ alpPixBuf ? *alpSrcPtr : NULL, ++ dest[0], dstW, chrAlpha, dstY); ++ } else if (c->yuv2packed2 && vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB ++ int lumAlpha = vLumFilter[2 * dstY + 1]; ++ int chrAlpha = vChrFilter[2 * dstY + 1]; ++ lumMmxFilter[2] = ++ lumMmxFilter[3] = vLumFilter[2 * dstY ] * 0x10001; ++ chrMmxFilter[2] = ++ chrMmxFilter[3] = vChrFilter[2 * chrDstY] * 0x10001; ++ yuv2packed2(c, lumSrcPtr, chrUSrcPtr, chrVSrcPtr, ++ alpPixBuf ? alpSrcPtr : NULL, ++ dest[0], dstW, lumAlpha, chrAlpha, dstY); ++ } else { //general RGB ++ yuv2packedX(c, vLumFilter + dstY * vLumFilterSize, ++ lumSrcPtr, vLumFilterSize, ++ vChrFilter + dstY * vChrFilterSize, ++ chrUSrcPtr, chrVSrcPtr, vChrFilterSize, ++ alpSrcPtr, dest[0], dstW, dstY); ++ } + } + } + } + +- // copy strides, so they can safely be modified +- if (c->sliceDir == 1) { +- // slices go from top to bottom +- int srcStride2[4]= {srcStride[0], srcStride[1], srcStride[2], srcStride[3]}; +- int dstStride2[4]= {dstStride[0], dstStride[1], dstStride[2], dstStride[3]}; +- +- reset_ptr(src2, c->srcFormat); +- reset_ptr((const uint8_t**)dst2, c->dstFormat); +- +- /* reset slice direction at end of frame */ +- if (srcSliceY + srcSliceH == c->srcH) +- c->sliceDir = 0; ++ if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf) ++ fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255); + +- return c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2, dstStride2); ++#if HAVE_MMX2 ++ if (av_get_cpu_flags() & AV_CPU_FLAG_MMX2) ++ __asm__ volatile("sfence":::"memory"); ++#endif ++ emms_c(); ++ ++ /* store changed local vars back in the context */ ++ c->dstY= dstY; ++ c->lumBufIndex= lumBufIndex; ++ c->chrBufIndex= chrBufIndex; ++ c->lastInLumBuf= lastInLumBuf; ++ c->lastInChrBuf= lastInChrBuf; ++ ++ return dstY - lastDstY; ++} ++ ++static av_cold void sws_init_swScale_c(SwsContext *c) ++{ ++ enum PixelFormat srcFormat = c->srcFormat; ++ ++ find_c_packed_planar_out_funcs(c, &c->yuv2plane1, &c->yuv2planeX, ++ &c->yuv2nv12cX, &c->yuv2packed1, &c->yuv2packed2, ++ &c->yuv2packedX); ++ ++ c->chrToYV12 = NULL; ++ switch(srcFormat) { ++ case PIX_FMT_YUYV422 : c->chrToYV12 = yuy2ToUV_c; break; ++ case PIX_FMT_UYVY422 : c->chrToYV12 = uyvyToUV_c; break; ++ case PIX_FMT_NV12 : c->chrToYV12 = nv12ToUV_c; break; ++ case PIX_FMT_NV21 : c->chrToYV12 = nv21ToUV_c; break; ++ case PIX_FMT_RGB8 : ++ case PIX_FMT_BGR8 : ++ case PIX_FMT_PAL8 : ++ case PIX_FMT_BGR4_BYTE: ++ case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV_c; break; ++ case PIX_FMT_GBRP9LE: ++ case PIX_FMT_GBRP10LE: ++ case PIX_FMT_GBRP16LE: c->readChrPlanar = planar_rgb16le_to_uv; break; ++ case PIX_FMT_GBRP9BE: ++ case PIX_FMT_GBRP10BE: ++ case PIX_FMT_GBRP16BE: c->readChrPlanar = planar_rgb16be_to_uv; break; ++ case PIX_FMT_GBRP: c->readChrPlanar = planar_rgb_to_uv; break; ++#if HAVE_BIGENDIAN ++ case PIX_FMT_YUV444P9LE: ++ case PIX_FMT_YUV422P9LE: ++ case PIX_FMT_YUV420P9LE: ++ case PIX_FMT_YUV422P10LE: ++ case PIX_FMT_YUV420P10LE: ++ case PIX_FMT_YUV444P10LE: ++ case PIX_FMT_YUV420P16LE: ++ case PIX_FMT_YUV422P16LE: ++ case PIX_FMT_YUV444P16LE: c->chrToYV12 = bswap16UV_c; break; ++#else ++ case PIX_FMT_YUV444P9BE: ++ case PIX_FMT_YUV422P9BE: ++ case PIX_FMT_YUV420P9BE: ++ case PIX_FMT_YUV444P10BE: ++ case PIX_FMT_YUV422P10BE: ++ case PIX_FMT_YUV420P10BE: ++ case PIX_FMT_YUV420P16BE: ++ case PIX_FMT_YUV422P16BE: ++ case PIX_FMT_YUV444P16BE: c->chrToYV12 = bswap16UV_c; break; ++#endif ++ } ++ if (c->chrSrcHSubSample) { ++ switch(srcFormat) { ++ case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_half_c; break; ++ case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_half_c; break; ++ case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_half_c; break; ++ case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_half_c; break; ++ case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half_c; break; ++ case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_half_c; break; ++ case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_half_c; break; ++ case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_half_c; break; ++ case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_half_c; break; ++ case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_half_c; break; ++ case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_half_c; break; ++ case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_half_c; break; ++ case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_half_c; break; ++ case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half_c; break; ++ case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_half_c; break; ++ case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_half_c; break; ++ case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_half_c; break; ++ case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_half_c; break; ++ case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_half_c; break; ++ case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_half_c; break; ++ case PIX_FMT_GBR24P : c->chrToYV12 = gbr24pToUV_half_c; break; ++ case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_half_c; break; ++ case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_half_c; break; ++ } + } else { +- // slices go from bottom to top => we flip the image internally +- int srcStride2[4]= {-srcStride[0], -srcStride[1], -srcStride[2], -srcStride[3]}; +- int dstStride2[4]= {-dstStride[0], -dstStride[1], -dstStride[2], -dstStride[3]}; ++ switch(srcFormat) { ++ case PIX_FMT_RGB48BE : c->chrToYV12 = rgb48BEToUV_c; break; ++ case PIX_FMT_RGB48LE : c->chrToYV12 = rgb48LEToUV_c; break; ++ case PIX_FMT_BGR48BE : c->chrToYV12 = bgr48BEToUV_c; break; ++ case PIX_FMT_BGR48LE : c->chrToYV12 = bgr48LEToUV_c; break; ++ case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_c; break; ++ case PIX_FMT_RGB32_1 : c->chrToYV12 = bgr321ToUV_c; break; ++ case PIX_FMT_BGR24 : c->chrToYV12 = bgr24ToUV_c; break; ++ case PIX_FMT_BGR565LE: c->chrToYV12 = bgr16leToUV_c; break; ++ case PIX_FMT_BGR565BE: c->chrToYV12 = bgr16beToUV_c; break; ++ case PIX_FMT_BGR555LE: c->chrToYV12 = bgr15leToUV_c; break; ++ case PIX_FMT_BGR555BE: c->chrToYV12 = bgr15beToUV_c; break; ++ case PIX_FMT_BGR444LE: c->chrToYV12 = bgr12leToUV_c; break; ++ case PIX_FMT_BGR444BE: c->chrToYV12 = bgr12beToUV_c; break; ++ case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_c; break; ++ case PIX_FMT_BGR32_1 : c->chrToYV12 = rgb321ToUV_c; break; ++ case PIX_FMT_RGB24 : c->chrToYV12 = rgb24ToUV_c; break; ++ case PIX_FMT_RGB565LE: c->chrToYV12 = rgb16leToUV_c; break; ++ case PIX_FMT_RGB565BE: c->chrToYV12 = rgb16beToUV_c; break; ++ case PIX_FMT_RGB555LE: c->chrToYV12 = rgb15leToUV_c; break; ++ case PIX_FMT_RGB555BE: c->chrToYV12 = rgb15beToUV_c; break; ++ case PIX_FMT_RGB444LE: c->chrToYV12 = rgb12leToUV_c; break; ++ case PIX_FMT_RGB444BE: c->chrToYV12 = rgb12beToUV_c; break; ++ } ++ } + +- src2[0] += (srcSliceH-1)*srcStride[0]; +- if (!usePal(c->srcFormat)) +- src2[1] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[1]; +- src2[2] += ((srcSliceH>>c->chrSrcVSubSample)-1)*srcStride[2]; +- src2[3] += (srcSliceH-1)*srcStride[3]; +- dst2[0] += ( c->dstH -1)*dstStride[0]; +- dst2[1] += ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[1]; +- dst2[2] += ((c->dstH>>c->chrDstVSubSample)-1)*dstStride[2]; +- dst2[3] += ( c->dstH -1)*dstStride[3]; ++ c->lumToYV12 = NULL; ++ c->alpToYV12 = NULL; ++ switch (srcFormat) { ++ case PIX_FMT_GBRP9LE: ++ case PIX_FMT_GBRP10LE: ++ case PIX_FMT_GBRP16LE: c->readLumPlanar = planar_rgb16le_to_y; break; ++ case PIX_FMT_GBRP9BE: ++ case PIX_FMT_GBRP10BE: ++ case PIX_FMT_GBRP16BE: c->readLumPlanar = planar_rgb16be_to_y; break; ++ case PIX_FMT_GBRP: c->readLumPlanar = planar_rgb_to_y; break; ++#if HAVE_BIGENDIAN ++ case PIX_FMT_YUV444P9LE: ++ case PIX_FMT_YUV422P9LE: ++ case PIX_FMT_YUV420P9LE: ++ case PIX_FMT_YUV422P10LE: ++ case PIX_FMT_YUV420P10LE: ++ case PIX_FMT_YUV444P10LE: ++ case PIX_FMT_YUV420P16LE: ++ case PIX_FMT_YUV422P16LE: ++ case PIX_FMT_YUV444P16LE: ++ case PIX_FMT_GRAY16LE: c->lumToYV12 = bswap16Y_c; break; ++#else ++ case PIX_FMT_YUV444P9BE: ++ case PIX_FMT_YUV422P9BE: ++ case PIX_FMT_YUV420P9BE: ++ case PIX_FMT_YUV444P10BE: ++ case PIX_FMT_YUV422P10BE: ++ case PIX_FMT_YUV420P10BE: ++ case PIX_FMT_YUV420P16BE: ++ case PIX_FMT_YUV422P16BE: ++ case PIX_FMT_YUV444P16BE: ++ case PIX_FMT_GRAY16BE: c->lumToYV12 = bswap16Y_c; break; ++#endif ++ case PIX_FMT_YUYV422 : ++ case PIX_FMT_Y400A : c->lumToYV12 = yuy2ToY_c; break; ++ case PIX_FMT_UYVY422 : c->lumToYV12 = uyvyToY_c; break; ++ case PIX_FMT_BGR24 : c->lumToYV12 = bgr24ToY_c; break; ++ case PIX_FMT_BGR565LE : c->lumToYV12 = bgr16leToY_c; break; ++ case PIX_FMT_BGR565BE : c->lumToYV12 = bgr16beToY_c; break; ++ case PIX_FMT_BGR555LE : c->lumToYV12 = bgr15leToY_c; break; ++ case PIX_FMT_BGR555BE : c->lumToYV12 = bgr15beToY_c; break; ++ case PIX_FMT_BGR444LE : c->lumToYV12 = bgr12leToY_c; break; ++ case PIX_FMT_BGR444BE : c->lumToYV12 = bgr12beToY_c; break; ++ case PIX_FMT_RGB24 : c->lumToYV12 = rgb24ToY_c; break; ++ case PIX_FMT_RGB565LE : c->lumToYV12 = rgb16leToY_c; break; ++ case PIX_FMT_RGB565BE : c->lumToYV12 = rgb16beToY_c; break; ++ case PIX_FMT_RGB555LE : c->lumToYV12 = rgb15leToY_c; break; ++ case PIX_FMT_RGB555BE : c->lumToYV12 = rgb15beToY_c; break; ++ case PIX_FMT_RGB444LE : c->lumToYV12 = rgb12leToY_c; break; ++ case PIX_FMT_RGB444BE : c->lumToYV12 = rgb12beToY_c; break; ++ case PIX_FMT_RGB8 : ++ case PIX_FMT_BGR8 : ++ case PIX_FMT_PAL8 : ++ case PIX_FMT_BGR4_BYTE: ++ case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY_c; break; ++ case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y_c; break; ++ case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y_c; break; ++ case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY_c; break; ++ case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY_c; break; ++ case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY_c; break; ++ case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY_c; break; ++ case PIX_FMT_RGB48BE: c->lumToYV12 = rgb48BEToY_c; break; ++ case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48LEToY_c; break; ++ case PIX_FMT_BGR48BE: c->lumToYV12 = bgr48BEToY_c; break; ++ case PIX_FMT_BGR48LE: c->lumToYV12 = bgr48LEToY_c; break; ++ } ++ if (c->alpPixBuf) { ++ switch (srcFormat) { ++ case PIX_FMT_BGRA: ++ case PIX_FMT_RGBA: c->alpToYV12 = rgbaToA_c; break; ++ case PIX_FMT_ABGR: ++ case PIX_FMT_ARGB: c->alpToYV12 = abgrToA_c; break; ++ case PIX_FMT_Y400A: c->alpToYV12 = uyvyToY_c; break; ++ case PIX_FMT_PAL8 : c->alpToYV12 = palToA_c; break; ++ } ++ } + +- reset_ptr(src2, c->srcFormat); +- reset_ptr((const uint8_t**)dst2, c->dstFormat); + +- /* reset slice direction at end of frame */ +- if (!srcSliceY) +- c->sliceDir = 0; ++ if (c->srcBpc == 8) { ++ if (c->dstBpc <= 10) { ++ c->hyScale = c->hcScale = hScale8To15_c; ++ if (c->flags & SWS_FAST_BILINEAR) { ++ c->hyscale_fast = hyscale_fast_c; ++ c->hcscale_fast = hcscale_fast_c; ++ } ++ } else { ++ c->hyScale = c->hcScale = hScale8To19_c; ++ } ++ } else { ++ c->hyScale = c->hcScale = c->dstBpc > 10 ? hScale16To19_c : hScale16To15_c; ++ } + +- return c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, srcSliceH, dst2, dstStride2); ++ if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { ++ if (c->dstBpc <= 10) { ++ if (c->srcRange) { ++ c->lumConvertRange = lumRangeFromJpeg_c; ++ c->chrConvertRange = chrRangeFromJpeg_c; ++ } else { ++ c->lumConvertRange = lumRangeToJpeg_c; ++ c->chrConvertRange = chrRangeToJpeg_c; ++ } ++ } else { ++ if (c->srcRange) { ++ c->lumConvertRange = lumRangeFromJpeg16_c; ++ c->chrConvertRange = chrRangeFromJpeg16_c; ++ } else { ++ c->lumConvertRange = lumRangeToJpeg16_c; ++ c->chrConvertRange = chrRangeToJpeg16_c; ++ } ++ } + } +-} + +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-int sws_scale_ordered(SwsContext *c, const uint8_t* const src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) +-{ +- return sws_scale(c, src, srcStride, srcSliceY, srcSliceH, dst, dstStride); ++ if (!(isGray(srcFormat) || isGray(c->dstFormat) || ++ srcFormat == PIX_FMT_MONOBLACK || srcFormat == PIX_FMT_MONOWHITE)) ++ c->needs_hcscale = 1; + } +-#endif + +-/* Convert the palette to the same packed 32-bit format as the palette */ +-void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) ++SwsFunc ff_getSwsFunc(SwsContext *c) + { +- long i; ++ sws_init_swScale_c(c); + +- for (i=0; i dst format: ABC */ +-void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette) +-{ +- long i; +- +- for (i=0; i ++ * Copyright (C) 2001-2011 Michael Niedermayer + * + * This file is part of FFmpeg. + * +@@ -28,10 +28,12 @@ + */ + + #include "libavutil/avutil.h" ++#include "libavutil/log.h" ++#include "libavutil/pixfmt.h" + +-#define LIBSWSCALE_VERSION_MAJOR 0 +-#define LIBSWSCALE_VERSION_MINOR 12 +-#define LIBSWSCALE_VERSION_MICRO 0 ++#define LIBSWSCALE_VERSION_MAJOR 2 ++#define LIBSWSCALE_VERSION_MINOR 1 ++#define LIBSWSCALE_VERSION_MICRO 100 + + #define LIBSWSCALE_VERSION_INT AV_VERSION_INT(LIBSWSCALE_VERSION_MAJOR, \ + LIBSWSCALE_VERSION_MINOR, \ +@@ -48,21 +50,27 @@ + * They may change, break or disappear at any time. + */ + #ifndef FF_API_SWS_GETCONTEXT +-#define FF_API_SWS_GETCONTEXT (LIBSWSCALE_VERSION_MAJOR < 1) ++#define FF_API_SWS_GETCONTEXT (LIBSWSCALE_VERSION_MAJOR < 3) ++#endif ++#ifndef FF_API_SWS_CPU_CAPS ++#define FF_API_SWS_CPU_CAPS (LIBSWSCALE_VERSION_MAJOR < 3) ++#endif ++#ifndef FF_API_SWS_FORMAT_NAME ++#define FF_API_SWS_FORMAT_NAME (LIBSWSCALE_VERSION_MAJOR < 3) + #endif + + /** +- * Returns the LIBSWSCALE_VERSION_INT constant. ++ * Return the LIBSWSCALE_VERSION_INT constant. + */ + unsigned swscale_version(void); + + /** +- * Returns the libswscale build-time configuration. ++ * Return the libswscale build-time configuration. + */ + const char *swscale_configuration(void); + + /** +- * Returns the libswscale license. ++ * Return the libswscale license. + */ + const char *swscale_license(void); + +@@ -95,12 +103,18 @@ + #define SWS_ACCURATE_RND 0x40000 + #define SWS_BITEXACT 0x80000 + ++#if FF_API_SWS_CPU_CAPS ++/** ++ * CPU caps are autodetected now, those flags ++ * are only provided for API compatibility. ++ */ + #define SWS_CPU_CAPS_MMX 0x80000000 + #define SWS_CPU_CAPS_MMX2 0x20000000 + #define SWS_CPU_CAPS_3DNOW 0x40000000 + #define SWS_CPU_CAPS_ALTIVEC 0x10000000 + #define SWS_CPU_CAPS_BFIN 0x01000000 + #define SWS_CPU_CAPS_SSE2 0x02000000 ++#endif + + #define SWS_MAX_REDUCE_CUTOFF 0.002 + +@@ -113,7 +127,7 @@ + #define SWS_CS_DEFAULT 5 + + /** +- * Returns a pointer to yuv<->rgb coefficients for the given colorspace ++ * Return a pointer to yuv<->rgb coefficients for the given colorspace + * suitable for sws_setColorspaceDetails(). + * + * @param colorspace One of the SWS_CS_* macros. If invalid, +@@ -121,7 +135,6 @@ + */ + const int *sws_getCoefficients(int colorspace); + +- + // when used for filters they must have an odd number of elements + // coeffs cannot be shared between vectors + typedef struct { +@@ -140,26 +153,26 @@ + struct SwsContext; + + /** +- * Returns a positive value if pix_fmt is a supported input format, 0 ++ * Return a positive value if pix_fmt is a supported input format, 0 + * otherwise. + */ + int sws_isSupportedInput(enum PixelFormat pix_fmt); + + /** +- * Returns a positive value if pix_fmt is a supported output format, 0 ++ * Return a positive value if pix_fmt is a supported output format, 0 + * otherwise. + */ + int sws_isSupportedOutput(enum PixelFormat pix_fmt); + + /** +- * Allocates an empty SwsContext. This must be filled and passed to ++ * Allocate an empty SwsContext. This must be filled and passed to + * sws_init_context(). For filling see AVOptions, options.c and + * sws_setColorspaceDetails(). + */ + struct SwsContext *sws_alloc_context(void); + + /** +- * Initializes the swscaler context sws_context. ++ * Initialize the swscaler context sws_context. + * + * @return zero or positive value on success, a negative value on + * error +@@ -167,14 +180,14 @@ + int sws_init_context(struct SwsContext *sws_context, SwsFilter *srcFilter, SwsFilter *dstFilter); + + /** +- * Frees the swscaler context swsContext. ++ * Free the swscaler context swsContext. + * If swsContext is NULL, then does nothing. + */ + void sws_freeContext(struct SwsContext *swsContext); + + #if FF_API_SWS_GETCONTEXT + /** +- * Allocates and returns a SwsContext. You need it to perform ++ * Allocate and return an SwsContext. You need it to perform + * scaling/conversion operations using sws_scale(). + * + * @param srcW the width of the source image +@@ -185,9 +198,10 @@ + * @param dstFormat the destination image format + * @param flags specify which algorithm and options to use for rescaling + * @return a pointer to an allocated context, or NULL in case of error +- * @deprecated use sws_alloc_context() and sws_init_context() ++ * @note this function is to be removed after a saner alternative is ++ * written ++ * @deprecated Use sws_getCachedContext() instead. + */ +-attribute_deprecated + struct SwsContext *sws_getContext(int srcW, int srcH, enum PixelFormat srcFormat, + int dstW, int dstH, enum PixelFormat dstFormat, + int flags, SwsFilter *srcFilter, +@@ -195,7 +209,7 @@ + #endif + + /** +- * Scales the image slice in srcSlice and puts the resulting scaled ++ * Scale the image slice in srcSlice and put the resulting scaled + * slice in the image in dst. A slice is a sequence of consecutive + * rows in an image. + * +@@ -203,7 +217,7 @@ + * top-bottom or bottom-top order. If slices are provided in + * non-sequential order the behavior of the function is undefined. + * +- * @param context the scaling context previously created with ++ * @param c the scaling context previously created with + * sws_getContext() + * @param srcSlice the array containing the pointers to the planes of + * the source slice +@@ -220,21 +234,12 @@ + * the destination image + * @return the height of the output slice + */ +-int sws_scale(struct SwsContext *context, const uint8_t* const srcSlice[], const int srcStride[], +- int srcSliceY, int srcSliceH, uint8_t* const dst[], const int dstStride[]); +- +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-/** +- * @deprecated Use sws_scale() instead. +- */ +-int sws_scale_ordered(struct SwsContext *context, const uint8_t* const src[], +- int srcStride[], int srcSliceY, int srcSliceH, +- uint8_t* dst[], int dstStride[]) attribute_deprecated; +-#endif ++int sws_scale(struct SwsContext *c, const uint8_t *const srcSlice[], ++ const int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *const dst[], const int dstStride[]); + + /** + * @param inv_table the yuv2rgb coefficients, normally ff_yuv2rgb_coeffs[x] +- * @param fullRange if 1 then the luma range is 0..255 if 0 it is 16..235 + * @return -1 if not supported + */ + int sws_setColorspaceDetails(struct SwsContext *c, const int inv_table[4], +@@ -249,35 +254,35 @@ + int *brightness, int *contrast, int *saturation); + + /** +- * Allocates and returns an uninitialized vector with length coefficients. ++ * Allocate and return an uninitialized vector with length coefficients. + */ + SwsVector *sws_allocVec(int length); + + /** +- * Returns a normalized Gaussian curve used to filter stuff +- * quality=3 is high quality, lower is lower quality. ++ * Return a normalized Gaussian curve used to filter stuff ++ * quality = 3 is high quality, lower is lower quality. + */ + SwsVector *sws_getGaussianVec(double variance, double quality); + + /** +- * Allocates and returns a vector with length coefficients, all ++ * Allocate and return a vector with length coefficients, all + * with the same value c. + */ + SwsVector *sws_getConstVec(double c, int length); + + /** +- * Allocates and returns a vector with just one coefficient, with ++ * Allocate and return a vector with just one coefficient, with + * value 1.0. + */ + SwsVector *sws_getIdentityVec(void); + + /** +- * Scales all the coefficients of a by the scalar value. ++ * Scale all the coefficients of a by the scalar value. + */ + void sws_scaleVec(SwsVector *a, double scalar); + + /** +- * Scales all the coefficients of a so that their sum equals height. ++ * Scale all the coefficients of a so that their sum equals height. + */ + void sws_normalizeVec(SwsVector *a, double height); + void sws_convVec(SwsVector *a, SwsVector *b); +@@ -286,20 +291,13 @@ + void sws_shiftVec(SwsVector *a, int shift); + + /** +- * Allocates and returns a clone of the vector a, that is a vector ++ * Allocate and return a clone of the vector a, that is a vector + * with the same coefficients as a. + */ + SwsVector *sws_cloneVec(SwsVector *a); + +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-/** +- * @deprecated Use sws_printVec2() instead. +- */ +-attribute_deprecated void sws_printVec(SwsVector *a); +-#endif +- + /** +- * Prints with av_log() a textual representation of the vector a ++ * Print with av_log() a textual representation of the vector a + * if log_level <= av_log_level. + */ + void sws_printVec2(SwsVector *a, AVClass *log_ctx, int log_level); +@@ -313,8 +311,7 @@ + void sws_freeFilter(SwsFilter *filter); + + /** +- * Checks if context can be reused, otherwise reallocates a new +- * one. ++ * Check if context can be reused, otherwise reallocate a new one. + * + * If context is NULL, just calls sws_getContext() to get a new + * context. Otherwise, checks if the parameters are the ones already +@@ -332,7 +329,7 @@ + SwsFilter *dstFilter, const double *param); + + /** +- * Converts an 8bit paletted frame into a frame with a color depth of 32-bits. ++ * Convert an 8-bit paletted frame into a frame with a color depth of 32 bits. + * + * The output frame will have the same packed format as the palette. + * +@@ -341,10 +338,10 @@ + * @param num_pixels number of pixels to convert + * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src + */ +-void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); ++void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); + + /** +- * Converts an 8bit paletted frame into a frame with a color depth of 24 bits. ++ * Convert an 8-bit paletted frame into a frame with a color depth of 24 bits. + * + * With the palette format "ABCD", the destination frame ends up with the format "ABC". + * +@@ -353,7 +350,14 @@ + * @param num_pixels number of pixels to convert + * @param palette array with [256] entries, which must match color arrangement (RGB or BGR) of src + */ +-void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, long num_pixels, const uint8_t *palette); ++void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, const uint8_t *palette); + ++/** ++ * Get the AVClass for swsContext. It can be used in combination with ++ * AV_OPT_SEARCH_FAKE_OBJ for examining options. ++ * ++ * @see av_opt_find(). ++ */ ++const AVClass *sws_get_class(void); + + #endif /* SWSCALE_SWSCALE_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale_internal.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale_internal.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale_internal.h 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale_internal.h 2012-05-14 14:08:55.435362140 +0200 +@@ -1,5 +1,5 @@ + /* +- * Copyright (C) 2001-2003 Michael Niedermayer ++ * Copyright (C) 2001-2011 Michael Niedermayer + * + * This file is part of FFmpeg. + * +@@ -28,18 +28,19 @@ + #endif + + #include "libavutil/avutil.h" ++#include "libavutil/log.h" ++#include "libavutil/pixfmt.h" ++#include "libavutil/pixdesc.h" + +-#define STR(s) AV_TOSTRING(s) //AV_STRINGIFY is too long ++#define STR(s) AV_TOSTRING(s) // AV_STRINGIFY is too long + +-#define MAX_FILTER_SIZE 256 ++#define YUVRGB_TABLE_HEADROOM 128 + +-#if ARCH_X86 +-#define VOFW 5120 +-#else +-#define VOFW 2048 // faster on PPC and not tested on others +-#endif ++#define FAST_BGR2YV12 // use 7-bit instead of 15-bit coefficients ++ ++#define MAX_FILTER_SIZE 256 + +-#define VOF (VOFW*2) ++#define DITHER1XBPP + + #if HAVE_BIGENDIAN + #define ALT32_CORR (-1) +@@ -48,20 +49,176 @@ + #endif + + #if ARCH_X86_64 +-# define APCK_PTR2 8 ++# define APCK_PTR2 8 + # define APCK_COEF 16 + # define APCK_SIZE 24 + #else +-# define APCK_PTR2 4 +-# define APCK_COEF 8 ++# define APCK_PTR2 4 ++# define APCK_COEF 8 + # define APCK_SIZE 16 + #endif + + struct SwsContext; + +-typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t* src[], ++typedef int (*SwsFunc)(struct SwsContext *context, const uint8_t *src[], + int srcStride[], int srcSliceY, int srcSliceH, +- uint8_t* dst[], int dstStride[]); ++ uint8_t *dst[], int dstStride[]); ++ ++/** ++ * Write one line of horizontally scaled data to planar output ++ * without any additional vertical scaling (or point-scaling). ++ * ++ * @param src scaled source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param dest pointer to the output plane. For >8bit ++ * output, this is in uint16_t ++ * @param dstW width of destination in pixels ++ * @param dither ordered dither array of type int16_t and size 8 ++ * @param offset Dither offset ++ */ ++typedef void (*yuv2planar1_fn)(const int16_t *src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset); ++ ++/** ++ * Write one line of horizontally scaled data to planar output ++ * with multi-point vertical scaling between input pixels. ++ * ++ * @param filter vertical luma/alpha scaling coefficients, 12bit [0,4096] ++ * @param src scaled luma (Y) or alpha (A) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param filterSize number of vertical input lines to scale ++ * @param dest pointer to output plane. For >8bit ++ * output, this is in uint16_t ++ * @param dstW width of destination pixels ++ * @param offset Dither offset ++ */ ++typedef void (*yuv2planarX_fn)(const int16_t *filter, int filterSize, ++ const int16_t **src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset); ++ ++/** ++ * Write one line of horizontally scaled chroma to interleaved output ++ * with multi-point vertical scaling between input pixels. ++ * ++ * @param c SWS scaling context ++ * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096] ++ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrFilterSize number of vertical chroma input lines to scale ++ * @param dest pointer to the output plane. For >8bit ++ * output, this is in uint16_t ++ * @param dstW width of chroma planes ++ */ ++typedef void (*yuv2interleavedX_fn)(struct SwsContext *c, ++ const int16_t *chrFilter, ++ int chrFilterSize, ++ const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ uint8_t *dest, int dstW); ++ ++/** ++ * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB ++ * output without any additional vertical scaling (or point-scaling). Note ++ * that this function may do chroma scaling, see the "uvalpha" argument. ++ * ++ * @param c SWS scaling context ++ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param dest pointer to the output plane. For 16bit output, this is ++ * uint16_t ++ * @param dstW width of lumSrc and alpSrc in pixels, number of pixels ++ * to write into dest[] ++ * @param uvalpha chroma scaling coefficient for the second line of chroma ++ * pixels, either 2048 or 0. If 0, one chroma input is used ++ * for 2 output pixels (or if the SWS_FLAG_FULL_CHR_INT flag ++ * is set, it generates 1 output pixel). If 2048, two chroma ++ * input pixels should be averaged for 2 output pixels (this ++ * only happens if SWS_FLAG_FULL_CHR_INT is not set) ++ * @param y vertical line number for this output. This does not need ++ * to be used to calculate the offset in the destination, ++ * but can be used to generate comfort noise using dithering ++ * for some output formats. ++ */ ++typedef void (*yuv2packed1_fn)(struct SwsContext *c, const int16_t *lumSrc, ++ const int16_t *chrUSrc[2], ++ const int16_t *chrVSrc[2], ++ const int16_t *alpSrc, uint8_t *dest, ++ int dstW, int uvalpha, int y); ++/** ++ * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB ++ * output by doing bilinear scaling between two input lines. ++ * ++ * @param c SWS scaling context ++ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param dest pointer to the output plane. For 16bit output, this is ++ * uint16_t ++ * @param dstW width of lumSrc and alpSrc in pixels, number of pixels ++ * to write into dest[] ++ * @param yalpha luma/alpha scaling coefficients for the second input line. ++ * The first line's coefficients can be calculated by using ++ * 4096 - yalpha ++ * @param uvalpha chroma scaling coefficient for the second input line. The ++ * first line's coefficients can be calculated by using ++ * 4096 - uvalpha ++ * @param y vertical line number for this output. This does not need ++ * to be used to calculate the offset in the destination, ++ * but can be used to generate comfort noise using dithering ++ * for some output formats. ++ */ ++typedef void (*yuv2packed2_fn)(struct SwsContext *c, const int16_t *lumSrc[2], ++ const int16_t *chrUSrc[2], ++ const int16_t *chrVSrc[2], ++ const int16_t *alpSrc[2], ++ uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y); ++/** ++ * Write one line of horizontally scaled Y/U/V/A to packed-pixel YUV/RGB ++ * output by doing multi-point vertical scaling between input pixels. ++ * ++ * @param c SWS scaling context ++ * @param lumFilter vertical luma/alpha scaling coefficients, 12bit [0,4096] ++ * @param lumSrc scaled luma (Y) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param lumFilterSize number of vertical luma/alpha input lines to scale ++ * @param chrFilter vertical chroma scaling coefficients, 12bit [0,4096] ++ * @param chrUSrc scaled chroma (U) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrVSrc scaled chroma (V) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param chrFilterSize number of vertical chroma input lines to scale ++ * @param alpSrc scaled alpha (A) source data, 15bit for 8-10bit output, ++ * 19-bit for 16bit output (in int32_t) ++ * @param dest pointer to the output plane. For 16bit output, this is ++ * uint16_t ++ * @param dstW width of lumSrc and alpSrc in pixels, number of pixels ++ * to write into dest[] ++ * @param y vertical line number for this output. This does not need ++ * to be used to calculate the offset in the destination, ++ * but can be used to generate comfort noise using dithering ++ * or some output formats. ++ */ ++typedef void (*yuv2packedX_fn)(struct SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, ++ const int16_t **chrUSrc, ++ const int16_t **chrVSrc, int chrFilterSize, ++ const int16_t **alpSrc, uint8_t *dest, ++ int dstW, int y); + + /* This struct should be aligned on at least a 32-byte boundary. */ + typedef struct SwsContext { +@@ -88,6 +245,7 @@ + enum PixelFormat srcFormat; ///< Source pixel format. + int dstFormatBpp; ///< Number of bits per pixel of the destination pixel format. + int srcFormatBpp; ///< Number of bits per pixel of the source pixel format. ++ int dstBpc, srcBpc; + int chrSrcHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in source image. + int chrSrcVSubSample; ///< Binary logarithm of vertical subsampling factor between luma/alpha and chroma planes in source image. + int chrDstHSubSample; ///< Binary logarithm of horizontal subsampling factor between luma/alpha and chroma planes in destination image. +@@ -110,17 +268,18 @@ + */ + //@{ + int16_t **lumPixBuf; ///< Ring buffer for scaled horizontal luma plane lines to be fed to the vertical scaler. +- int16_t **chrPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. ++ int16_t **chrUPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. ++ int16_t **chrVPixBuf; ///< Ring buffer for scaled horizontal chroma plane lines to be fed to the vertical scaler. + int16_t **alpPixBuf; ///< Ring buffer for scaled horizontal alpha plane lines to be fed to the vertical scaler. +- int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer. +- int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer. +- int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer. +- int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer. +- int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source. +- int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source. ++ int vLumBufSize; ///< Number of vertical luma/alpha lines allocated in the ring buffer. ++ int vChrBufSize; ///< Number of vertical chroma lines allocated in the ring buffer. ++ int lastInLumBuf; ///< Last scaled horizontal luma/alpha line from source in the ring buffer. ++ int lastInChrBuf; ///< Last scaled horizontal chroma line from source in the ring buffer. ++ int lumBufIndex; ///< Index in ring buffer of the last scaled horizontal luma/alpha line from source. ++ int chrBufIndex; ///< Index in ring buffer of the last scaled horizontal chroma line from source. + //@} + +- uint8_t formatConvBuffer[VOF]; //FIXME dynamic allocation, but we have to change a lot of code for this to be useful ++ uint8_t *formatConvBuffer; + + /** + * @name Horizontal and vertical filters. +@@ -140,14 +299,14 @@ + int16_t *hChrFilter; ///< Array of horizontal filter coefficients for chroma planes. + int16_t *vLumFilter; ///< Array of vertical filter coefficients for luma/alpha planes. + int16_t *vChrFilter; ///< Array of vertical filter coefficients for chroma planes. +- int16_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes. +- int16_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes. +- int16_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes. +- int16_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes. +- int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels. +- int hChrFilterSize; ///< Horizontal filter size for chroma pixels. +- int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels. +- int vChrFilterSize; ///< Vertical filter size for chroma pixels. ++ int32_t *hLumFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for luma/alpha planes. ++ int32_t *hChrFilterPos; ///< Array of horizontal filter starting positions for each dst[i] for chroma planes. ++ int32_t *vLumFilterPos; ///< Array of vertical filter starting positions for each dst[i] for luma/alpha planes. ++ int32_t *vChrFilterPos; ///< Array of vertical filter starting positions for each dst[i] for chroma planes. ++ int hLumFilterSize; ///< Horizontal filter size for luma/alpha pixels. ++ int hChrFilterSize; ///< Horizontal filter size for chroma pixels. ++ int vLumFilterSize; ///< Vertical filter size for luma/alpha pixels. ++ int vChrFilterSize; ///< Vertical filter size for chroma pixels. + //@} + + int lumMmx2FilterCodeSize; ///< Runtime-generated MMX2 horizontal fast bilinear scaler code size for luma/alpha planes. +@@ -159,11 +318,11 @@ + + int dstY; ///< Last destination vertical line output from last slice. + int flags; ///< Flags passed by the user to select scaler algorithm, optimizations, subsampling, etc... +- void * yuvTable; // pointer to the yuv->rgb table start so it can be freed() +- uint8_t * table_rV[256]; +- uint8_t * table_gU[256]; +- int table_gV[256]; +- uint8_t * table_bU[256]; ++ void *yuvTable; // pointer to the yuv->rgb table start so it can be freed() ++ uint8_t *table_rV[256 + 2*YUVRGB_TABLE_HEADROOM]; ++ uint8_t *table_gU[256 + 2*YUVRGB_TABLE_HEADROOM]; ++ int table_gV[256 + 2*YUVRGB_TABLE_HEADROOM]; ++ uint8_t *table_bU[256 + 2*YUVRGB_TABLE_HEADROOM]; + + //Colorspace stuff + int contrast, brightness, saturation; // for sws_getColorspaceDetails +@@ -171,6 +330,8 @@ + int dstColorspaceTable[4]; + int srcRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (source image). + int dstRange; ///< 0 = MPG YUV range, 1 = JPG YUV range (destination image). ++ int src0Alpha; ++ int dst0Alpha; + int yuv2rgb_y_offset; + int yuv2rgb_y_coeff; + int yuv2rgb_v2r_coeff; +@@ -198,6 +359,10 @@ + #define V_TEMP "11*8+4*4*256*2+32" + #define Y_TEMP "11*8+4*4*256*2+40" + #define ALP_MMX_FILTER_OFFSET "11*8+4*4*256*2+48" ++#define UV_OFF_PX "11*8+4*4*256*3+48" ++#define UV_OFF_BYTE "11*8+4*4*256*3+56" ++#define DITHER16 "11*8+4*4*256*3+64" ++#define DITHER32 "11*8+4*4*256*3+80" + + DECLARE_ALIGNED(8, uint64_t, redDither); + DECLARE_ALIGNED(8, uint64_t, greenDither); +@@ -211,15 +376,24 @@ + DECLARE_ALIGNED(8, uint64_t, yOffset); + DECLARE_ALIGNED(8, uint64_t, uOffset); + DECLARE_ALIGNED(8, uint64_t, vOffset); +- int32_t lumMmxFilter[4*MAX_FILTER_SIZE]; +- int32_t chrMmxFilter[4*MAX_FILTER_SIZE]; ++ int32_t lumMmxFilter[4 * MAX_FILTER_SIZE]; ++ int32_t chrMmxFilter[4 * MAX_FILTER_SIZE]; + int dstW; ///< Width of destination luma/alpha planes. + DECLARE_ALIGNED(8, uint64_t, esp); + DECLARE_ALIGNED(8, uint64_t, vRounder); + DECLARE_ALIGNED(8, uint64_t, u_temp); + DECLARE_ALIGNED(8, uint64_t, v_temp); + DECLARE_ALIGNED(8, uint64_t, y_temp); +- int32_t alpMmxFilter[4*MAX_FILTER_SIZE]; ++ int32_t alpMmxFilter[4 * MAX_FILTER_SIZE]; ++ // alignment of these values is not necessary, but merely here ++ // to maintain the same offset across x8632 and x86-64. Once we ++ // use proper offset macros in the asm, they can be removed. ++ DECLARE_ALIGNED(8, ptrdiff_t, uv_off); ///< offset (in pixels) between u and v planes ++ DECLARE_ALIGNED(8, ptrdiff_t, uv_offx2); ///< offset (in bytes) between u and v planes ++ DECLARE_ALIGNED(8, uint16_t, dither16)[8]; ++ DECLARE_ALIGNED(8, uint32_t, dither32)[8]; ++ ++ const uint8_t *chrDither8, *lumDither8; + + #if HAVE_ALTIVEC + vector signed short CY; +@@ -229,7 +403,7 @@ + vector signed short CGV; + vector signed short OY; + vector unsigned short CSHIFT; +- vector signed short *vYCoeffsBank, *vCCoeffsBank; ++ vector signed short *vYCoeffsBank, *vCCoeffsBank; + #endif + + #if ARCH_BFIN +@@ -249,71 +423,110 @@ + #if HAVE_VIS + DECLARE_ALIGNED(8, uint64_t, sparc_coeffs)[10]; + #endif ++ int use_mmx_vfilter; + + /* function pointers for swScale() */ +- void (*yuv2nv12X )(struct SwsContext *c, +- const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, uint8_t *uDest, +- int dstW, int chrDstW, int dstFormat); +- void (*yuv2yuv1 )(struct SwsContext *c, +- const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc, +- uint8_t *dest, +- uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, +- long dstW, long chrDstW); +- void (*yuv2yuvX )(struct SwsContext *c, +- const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, +- uint8_t *dest, +- uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, +- long dstW, long chrDstW); +- void (*yuv2packed1)(struct SwsContext *c, +- const uint16_t *buf0, +- const uint16_t *uvbuf0, const uint16_t *uvbuf1, +- const uint16_t *abuf0, +- uint8_t *dest, +- int dstW, int uvalpha, int dstFormat, int flags, int y); +- void (*yuv2packed2)(struct SwsContext *c, +- const uint16_t *buf0, const uint16_t *buf1, +- const uint16_t *uvbuf0, const uint16_t *uvbuf1, +- const uint16_t *abuf0, const uint16_t *abuf1, +- uint8_t *dest, +- int dstW, int yalpha, int uvalpha, int y); +- void (*yuv2packedX)(struct SwsContext *c, +- const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint8_t *dest, +- long dstW, long dstY); +- +- void (*lumToYV12)(uint8_t *dst, const uint8_t *src, +- long width, uint32_t *pal); ///< Unscaled conversion of luma plane to YV12 for horizontal scaler. +- void (*alpToYV12)(uint8_t *dst, const uint8_t *src, +- long width, uint32_t *pal); ///< Unscaled conversion of alpha plane to YV12 for horizontal scaler. ++ yuv2planar1_fn yuv2plane1; ++ yuv2planarX_fn yuv2planeX; ++ yuv2interleavedX_fn yuv2nv12cX; ++ yuv2packed1_fn yuv2packed1; ++ yuv2packed2_fn yuv2packed2; ++ yuv2packedX_fn yuv2packedX; ++ ++ /// Unscaled conversion of luma plane to YV12 for horizontal scaler. ++ void (*lumToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, ++ int width, uint32_t *pal); ++ /// Unscaled conversion of alpha plane to YV12 for horizontal scaler. ++ void (*alpToYV12)(uint8_t *dst, const uint8_t *src, const uint8_t *src2, const uint8_t *src3, ++ int width, uint32_t *pal); ++ /// Unscaled conversion of chroma planes to YV12 for horizontal scaler. + void (*chrToYV12)(uint8_t *dstU, uint8_t *dstV, +- const uint8_t *src1, const uint8_t *src2, +- long width, uint32_t *pal); ///< Unscaled conversion of chroma planes to YV12 for horizontal scaler. ++ const uint8_t *src1, const uint8_t *src2, const uint8_t *src3, ++ int width, uint32_t *pal); ++ ++ /** ++ * Functions to read planar input, such as planar RGB, and convert ++ * internally to Y/UV. ++ */ ++ /** @{ */ ++ void (*readLumPlanar)(uint8_t *dst, const uint8_t *src[4], int width); ++ void (*readChrPlanar)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src[4], ++ int width); ++ /** @} */ ++ ++ /** ++ * Scale one horizontal line of input data using a bilinear filter ++ * to produce one line of output data. Compared to SwsContext->hScale(), ++ * please take note of the following caveats when using these: ++ * - Scaling is done using only 7bit instead of 14bit coefficients. ++ * - You can use no more than 5 input pixels to produce 4 output ++ * pixels. Therefore, this filter should not be used for downscaling ++ * by more than ~20% in width (because that equals more than 5/4th ++ * downscaling and thus more than 5 pixels input per 4 pixels output). ++ * - In general, bilinear filters create artifacts during downscaling ++ * (even when <20%), because one output pixel will span more than one ++ * input pixel, and thus some pixels will need edges of both neighbor ++ * pixels to interpolate the output pixel. Since you can use at most ++ * two input pixels per output pixel in bilinear scaling, this is ++ * impossible and thus downscaling by any size will create artifacts. ++ * To enable this type of scaling, set SWS_FLAG_FAST_BILINEAR ++ * in SwsContext->flags. ++ */ ++ /** @{ */ + void (*hyscale_fast)(struct SwsContext *c, +- int16_t *dst, long dstWidth, ++ int16_t *dst, int dstWidth, + const uint8_t *src, int srcW, int xInc); + void (*hcscale_fast)(struct SwsContext *c, +- int16_t *dst, long dstWidth, ++ int16_t *dst1, int16_t *dst2, int dstWidth, + const uint8_t *src1, const uint8_t *src2, + int srcW, int xInc); ++ /** @} */ + +- void (*hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, +- int xInc, const int16_t *filter, const int16_t *filterPos, +- long filterSize); +- +- void (*lumConvertRange)(uint16_t *dst, int width); ///< Color range conversion function for luma plane if needed. +- void (*chrConvertRange)(uint16_t *dst, int width); ///< Color range conversion function for chroma planes if needed. +- +- int lumSrcOffset; ///< Offset given to luma src pointers passed to horizontal input functions. +- int chrSrcOffset; ///< Offset given to chroma src pointers passed to horizontal input functions. +- int alpSrcOffset; ///< Offset given to alpha src pointers passed to horizontal input functions. ++ /** ++ * Scale one horizontal line of input data using a filter over the input ++ * lines, to produce one (differently sized) line of output data. ++ * ++ * @param dst pointer to destination buffer for horizontally scaled ++ * data. If the number of bits per component of one ++ * destination pixel (SwsContext->dstBpc) is <= 10, data ++ * will be 15bpc in 16bits (int16_t) width. Else (i.e. ++ * SwsContext->dstBpc == 16), data will be 19bpc in ++ * 32bits (int32_t) width. ++ * @param dstW width of destination image ++ * @param src pointer to source data to be scaled. If the number of ++ * bits per component of a source pixel (SwsContext->srcBpc) ++ * is 8, this is 8bpc in 8bits (uint8_t) width. Else ++ * (i.e. SwsContext->dstBpc > 8), this is native depth ++ * in 16bits (uint16_t) width. In other words, for 9-bit ++ * YUV input, this is 9bpc, for 10-bit YUV input, this is ++ * 10bpc, and for 16-bit RGB or YUV, this is 16bpc. ++ * @param filter filter coefficients to be used per output pixel for ++ * scaling. This contains 14bpp filtering coefficients. ++ * Guaranteed to contain dstW * filterSize entries. ++ * @param filterPos position of the first input pixel to be used for ++ * each output pixel during scaling. Guaranteed to ++ * contain dstW entries. ++ * @param filterSize the number of input coefficients to be used (and ++ * thus the number of input pixels to be used) for ++ * creating a single output pixel. Is aligned to 4 ++ * (and input coefficients thus padded with zeroes) ++ * to simplify creating SIMD code. ++ */ ++ /** @{ */ ++ void (*hyScale)(struct SwsContext *c, int16_t *dst, int dstW, ++ const uint8_t *src, const int16_t *filter, ++ const int32_t *filterPos, int filterSize); ++ void (*hcScale)(struct SwsContext *c, int16_t *dst, int dstW, ++ const uint8_t *src, const int16_t *filter, ++ const int32_t *filterPos, int filterSize); ++ /** @} */ ++ ++ /// Color range conversion function for luma plane if needed. ++ void (*lumConvertRange)(int16_t *dst, int width); ++ /// Color range conversion function for chroma planes if needed. ++ void (*chrConvertRange)(int16_t *dst1, int16_t *dst2, int width); + + int needs_hcscale; ///< Set if there are chroma planes to be converted. +- + } SwsContext; + //FIXME check init (where 0) + +@@ -324,148 +537,176 @@ + + void ff_yuv2rgb_init_tables_altivec(SwsContext *c, const int inv_table[4], + int brightness, int contrast, int saturation); ++void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, ++ int lastInLumBuf, int lastInChrBuf); ++ + SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c); + SwsFunc ff_yuv2rgb_init_vis(SwsContext *c); + SwsFunc ff_yuv2rgb_init_mlib(SwsContext *c); + SwsFunc ff_yuv2rgb_init_altivec(SwsContext *c); + SwsFunc ff_yuv2rgb_get_func_ptr_bfin(SwsContext *c); + void ff_bfin_get_unscaled_swscale(SwsContext *c); +-void ff_yuv2packedX_altivec(SwsContext *c, +- const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, int dstW, int dstY); + ++#if FF_API_SWS_FORMAT_NAME ++/** ++ * @deprecated Use av_get_pix_fmt_name() instead. ++ */ ++attribute_deprecated + const char *sws_format_name(enum PixelFormat format); ++#endif + +-//FIXME replace this with something faster +-#define is16BPS(x) ( \ +- (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- || (x)==PIX_FMT_RGB48BE \ +- || (x)==PIX_FMT_RGB48LE \ +- || (x)==PIX_FMT_YUV420P16LE \ +- || (x)==PIX_FMT_YUV422P16LE \ +- || (x)==PIX_FMT_YUV444P16LE \ +- || (x)==PIX_FMT_YUV420P16BE \ +- || (x)==PIX_FMT_YUV422P16BE \ +- || (x)==PIX_FMT_YUV444P16BE \ +- ) +-#define isBE(x) ((x)&1) +-#define isPlanar8YUV(x) ( \ +- (x)==PIX_FMT_YUV410P \ +- || (x)==PIX_FMT_YUV420P \ +- || (x)==PIX_FMT_YUVA420P \ +- || (x)==PIX_FMT_YUV411P \ +- || (x)==PIX_FMT_YUV422P \ +- || (x)==PIX_FMT_YUV444P \ +- || (x)==PIX_FMT_YUV440P \ +- || (x)==PIX_FMT_NV12 \ +- || (x)==PIX_FMT_NV21 \ +- ) +-#define isPlanarYUV(x) ( \ +- isPlanar8YUV(x) \ +- || (x)==PIX_FMT_YUV420P16LE \ +- || (x)==PIX_FMT_YUV422P16LE \ +- || (x)==PIX_FMT_YUV444P16LE \ +- || (x)==PIX_FMT_YUV420P16BE \ +- || (x)==PIX_FMT_YUV422P16BE \ +- || (x)==PIX_FMT_YUV444P16BE \ +- ) +-#define isYUV(x) ( \ +- (x)==PIX_FMT_UYVY422 \ +- || (x)==PIX_FMT_YUYV422 \ +- || isPlanarYUV(x) \ +- ) +-#define isGray(x) ( \ +- (x)==PIX_FMT_GRAY8 \ +- || (x)==PIX_FMT_Y400A \ +- || (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- ) +-#define isGray16(x) ( \ +- (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- ) +-#define isRGBinInt(x) ( \ +- (x)==PIX_FMT_RGB48BE \ +- || (x)==PIX_FMT_RGB48LE \ +- || (x)==PIX_FMT_RGB32 \ +- || (x)==PIX_FMT_RGB32_1 \ +- || (x)==PIX_FMT_RGB24 \ +- || (x)==PIX_FMT_RGB565BE \ +- || (x)==PIX_FMT_RGB565LE \ +- || (x)==PIX_FMT_RGB555BE \ +- || (x)==PIX_FMT_RGB555LE \ +- || (x)==PIX_FMT_RGB444BE \ +- || (x)==PIX_FMT_RGB444LE \ +- || (x)==PIX_FMT_RGB8 \ +- || (x)==PIX_FMT_RGB4 \ +- || (x)==PIX_FMT_RGB4_BYTE \ +- || (x)==PIX_FMT_MONOBLACK \ +- || (x)==PIX_FMT_MONOWHITE \ +- ) +-#define isBGRinInt(x) ( \ +- (x)==PIX_FMT_BGR32 \ +- || (x)==PIX_FMT_BGR32_1 \ +- || (x)==PIX_FMT_BGR24 \ +- || (x)==PIX_FMT_BGR565BE \ +- || (x)==PIX_FMT_BGR565LE \ +- || (x)==PIX_FMT_BGR555BE \ +- || (x)==PIX_FMT_BGR555LE \ +- || (x)==PIX_FMT_BGR444BE \ +- || (x)==PIX_FMT_BGR444LE \ +- || (x)==PIX_FMT_BGR8 \ +- || (x)==PIX_FMT_BGR4 \ +- || (x)==PIX_FMT_BGR4_BYTE \ +- || (x)==PIX_FMT_MONOBLACK \ +- || (x)==PIX_FMT_MONOWHITE \ ++#define is16BPS(x) \ ++ (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 15) ++ ++#define is9_OR_10BPS(x) \ ++ (av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 8 || \ ++ av_pix_fmt_descriptors[x].comp[0].depth_minus1 == 9) ++ ++#define isNBPS(x) is9_OR_10BPS(x) ++ ++#define isBE(x) \ ++ (av_pix_fmt_descriptors[x].flags & PIX_FMT_BE) ++ ++#define isYUV(x) \ ++ (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) && \ ++ av_pix_fmt_descriptors[x].nb_components >= 2) ++ ++#define isPlanarYUV(x) \ ++ ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR) && \ ++ isYUV(x)) ++ ++#define isRGB(x) \ ++ (av_pix_fmt_descriptors[x].flags & PIX_FMT_RGB) ++#if 0 // FIXME ++#define isGray(x) \ ++ (!(av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) && \ ++ av_pix_fmt_descriptors[x].nb_components <= 2) ++#else ++#define isGray(x) \ ++ ((x) == PIX_FMT_GRAY8 || \ ++ (x) == PIX_FMT_Y400A || \ ++ (x) == PIX_FMT_GRAY16BE || \ ++ (x) == PIX_FMT_GRAY16LE) ++#endif ++ ++#define isRGBinInt(x) \ ++ ( \ ++ (x)==PIX_FMT_RGB48BE || \ ++ (x)==PIX_FMT_RGB48LE || \ ++ (x)==PIX_FMT_RGBA64BE || \ ++ (x)==PIX_FMT_RGBA64LE || \ ++ (x)==PIX_FMT_RGB32 || \ ++ (x)==PIX_FMT_RGB32_1 || \ ++ (x)==PIX_FMT_RGB24 || \ ++ (x)==PIX_FMT_RGB565BE || \ ++ (x)==PIX_FMT_RGB565LE || \ ++ (x)==PIX_FMT_RGB555BE || \ ++ (x)==PIX_FMT_RGB555LE || \ ++ (x)==PIX_FMT_RGB444BE || \ ++ (x)==PIX_FMT_RGB444LE || \ ++ (x)==PIX_FMT_RGB8 || \ ++ (x)==PIX_FMT_RGB4 || \ ++ (x)==PIX_FMT_RGB4_BYTE || \ ++ (x)==PIX_FMT_MONOBLACK || \ ++ (x)==PIX_FMT_MONOWHITE \ ++ ) ++#define isBGRinInt(x) \ ++ ( \ ++ (x)==PIX_FMT_BGR48BE || \ ++ (x)==PIX_FMT_BGR48LE || \ ++ (x)==PIX_FMT_BGRA64BE || \ ++ (x)==PIX_FMT_BGRA64LE || \ ++ (x)==PIX_FMT_BGR32 || \ ++ (x)==PIX_FMT_BGR32_1 || \ ++ (x)==PIX_FMT_BGR24 || \ ++ (x)==PIX_FMT_BGR565BE || \ ++ (x)==PIX_FMT_BGR565LE || \ ++ (x)==PIX_FMT_BGR555BE || \ ++ (x)==PIX_FMT_BGR555LE || \ ++ (x)==PIX_FMT_BGR444BE || \ ++ (x)==PIX_FMT_BGR444LE || \ ++ (x)==PIX_FMT_BGR8 || \ ++ (x)==PIX_FMT_BGR4 || \ ++ (x)==PIX_FMT_BGR4_BYTE|| \ ++ (x)==PIX_FMT_MONOBLACK|| \ ++ (x)==PIX_FMT_MONOWHITE \ + ) ++ + #define isRGBinBytes(x) ( \ + (x)==PIX_FMT_RGB48BE \ + || (x)==PIX_FMT_RGB48LE \ ++ || (x)==PIX_FMT_RGBA64BE \ ++ || (x)==PIX_FMT_RGBA64LE \ + || (x)==PIX_FMT_RGBA \ + || (x)==PIX_FMT_ARGB \ + || (x)==PIX_FMT_RGB24 \ + ) + #define isBGRinBytes(x) ( \ +- (x)==PIX_FMT_BGRA \ ++ (x)==PIX_FMT_BGR48BE \ ++ || (x)==PIX_FMT_BGR48LE \ ++ || (x)==PIX_FMT_BGRA64BE \ ++ || (x)==PIX_FMT_BGRA64LE \ ++ || (x)==PIX_FMT_BGRA \ + || (x)==PIX_FMT_ABGR \ + || (x)==PIX_FMT_BGR24 \ + ) +-#define isAnyRGB(x) ( \ +- isRGBinInt(x) \ +- || isBGRinInt(x) \ ++ ++#define isAnyRGB(x) \ ++ ( \ ++ isRGBinInt(x) || \ ++ isBGRinInt(x) || \ ++ (x)==PIX_FMT_GBR24P \ + ) +-#define isALPHA(x) ( \ +- (x)==PIX_FMT_BGR32 \ +- || (x)==PIX_FMT_BGR32_1 \ +- || (x)==PIX_FMT_RGB32 \ +- || (x)==PIX_FMT_RGB32_1 \ ++ ++#define isALPHA(x) \ ++ (av_pix_fmt_descriptors[x].nb_components == 2 || \ ++ av_pix_fmt_descriptors[x].nb_components == 4) ++ ++#if 1 ++#define isPacked(x) ( \ ++ (x)==PIX_FMT_PAL8 \ ++ || (x)==PIX_FMT_YUYV422 \ ++ || (x)==PIX_FMT_UYVY422 \ + || (x)==PIX_FMT_Y400A \ +- || (x)==PIX_FMT_YUVA420P \ ++ || isRGBinInt(x) \ ++ || isBGRinInt(x) \ + ) ++#else ++#define isPacked(x) \ ++ ((av_pix_fmt_descriptors[x].nb_components >= 2 && \ ++ !(av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) || \ ++ (x) == PIX_FMT_PAL8) ++ ++#endif ++#define isPlanar(x) \ ++ (av_pix_fmt_descriptors[x].nb_components >= 2 && \ ++ (av_pix_fmt_descriptors[x].flags & PIX_FMT_PLANAR)) ++ + #define usePal(x) ((av_pix_fmt_descriptors[x].flags & PIX_FMT_PAL) || (x) == PIX_FMT_Y400A) + + extern const uint64_t ff_dither4[2]; + extern const uint64_t ff_dither8[2]; ++extern const uint8_t dithers[8][8][8]; ++extern const uint16_t dither_scale[15][16]; ++ + + extern const AVClass sws_context_class; + + /** +- * Sets c->swScale to an unscaled converter if one exists for the specific ++ * Set c->swScale to an unscaled converter if one exists for the specific + * source and destination formats, bit depths, flags, etc. + */ + void ff_get_unscaled_swscale(SwsContext *c); + +-/** +- * Returns the SWS_CPU_CAPS for the optimized code compiled into swscale. +- */ +-int ff_hardcodedcpuflags(void); ++void ff_swscale_get_unscaled_altivec(SwsContext *c); + + /** +- * Returns function pointer to fastest main scaler path function depending ++ * Return function pointer to fastest main scaler path function depending + * on architecture and available optimizations. + */ + SwsFunc ff_getSwsFunc(SwsContext *c); + ++void ff_sws_init_swScale_altivec(SwsContext *c); ++void ff_sws_init_swScale_mmx(SwsContext *c); ++ + #endif /* SWSCALE_SWSCALE_INTERNAL_H */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale_template.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale_template.c 1970-01-01 01:00:00.000000000 +0100 +@@ -1,3069 +0,0 @@ +-/* +- * Copyright (C) 2001-2003 Michael Niedermayer +- * +- * This file is part of FFmpeg. +- * +- * FFmpeg is free software; you can redistribute it and/or +- * modify it under the terms of the GNU Lesser General Public +- * License as published by the Free Software Foundation; either +- * version 2.1 of the License, or (at your option) any later version. +- * +- * FFmpeg 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 +- * Lesser General Public License for more details. +- * +- * You should have received a copy of the GNU Lesser General Public +- * License along with FFmpeg; if not, write to the Free Software +- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +- */ +- +-#undef REAL_MOVNTQ +-#undef MOVNTQ +-#undef PAVGB +-#undef PREFETCH +- +-#if COMPILE_TEMPLATE_AMD3DNOW +-#define PREFETCH "prefetch" +-#elif COMPILE_TEMPLATE_MMX2 +-#define PREFETCH "prefetchnta" +-#else +-#define PREFETCH " # nop" +-#endif +- +-#if COMPILE_TEMPLATE_MMX2 +-#define PAVGB(a,b) "pavgb " #a ", " #b " \n\t" +-#elif COMPILE_TEMPLATE_AMD3DNOW +-#define PAVGB(a,b) "pavgusb " #a ", " #b " \n\t" +-#endif +- +-#if COMPILE_TEMPLATE_MMX2 +-#define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t" +-#else +-#define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t" +-#endif +-#define MOVNTQ(a,b) REAL_MOVNTQ(a,b) +- +-#if COMPILE_TEMPLATE_ALTIVEC +-#include "ppc/swscale_altivec_template.c" +-#endif +- +-#define YSCALEYUV2YV12X(x, offset, dest, width) \ +- __asm__ volatile(\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ +- "movq %%mm3, %%mm4 \n\t"\ +- "lea " offset "(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- ".p2align 4 \n\t" /* FIXME Unroll? */\ +- "1: \n\t"\ +- "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ +- "movq " x "(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* srcData */\ +- "movq 8+" x "(%%"REG_S", %%"REG_a", 2), %%mm5 \n\t" /* srcData */\ +- "add $16, %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- "pmulhw %%mm0, %%mm2 \n\t"\ +- "pmulhw %%mm0, %%mm5 \n\t"\ +- "paddw %%mm2, %%mm3 \n\t"\ +- "paddw %%mm5, %%mm4 \n\t"\ +- " jnz 1b \n\t"\ +- "psraw $3, %%mm3 \n\t"\ +- "psraw $3, %%mm4 \n\t"\ +- "packuswb %%mm4, %%mm3 \n\t"\ +- MOVNTQ(%%mm3, (%1, %%REGa))\ +- "add $8, %%"REG_a" \n\t"\ +- "cmp %2, %%"REG_a" \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ +- "movq %%mm3, %%mm4 \n\t"\ +- "lea " offset "(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "jb 1b \n\t"\ +- :: "r" (&c->redDither),\ +- "r" (dest), "g" ((x86_reg)width)\ +- : "%"REG_a, "%"REG_d, "%"REG_S\ +- ); +- +-#define YSCALEYUV2YV12X_ACCURATE(x, offset, dest, width) \ +- __asm__ volatile(\ +- "lea " offset "(%0), %%"REG_d" \n\t"\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- "pxor %%mm4, %%mm4 \n\t"\ +- "pxor %%mm5, %%mm5 \n\t"\ +- "pxor %%mm6, %%mm6 \n\t"\ +- "pxor %%mm7, %%mm7 \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq " x "(%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* srcData */\ +- "movq 8+" x "(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* srcData */\ +- "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "movq " x "(%%"REG_S", %%"REG_a", 2), %%mm1 \n\t" /* srcData */\ +- "movq %%mm0, %%mm3 \n\t"\ +- "punpcklwd %%mm1, %%mm0 \n\t"\ +- "punpckhwd %%mm1, %%mm3 \n\t"\ +- "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm1 \n\t" /* filterCoeff */\ +- "pmaddwd %%mm1, %%mm0 \n\t"\ +- "pmaddwd %%mm1, %%mm3 \n\t"\ +- "paddd %%mm0, %%mm4 \n\t"\ +- "paddd %%mm3, %%mm5 \n\t"\ +- "movq 8+" x "(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* srcData */\ +- "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "punpcklwd %%mm3, %%mm2 \n\t"\ +- "punpckhwd %%mm3, %%mm0 \n\t"\ +- "pmaddwd %%mm1, %%mm2 \n\t"\ +- "pmaddwd %%mm1, %%mm0 \n\t"\ +- "paddd %%mm2, %%mm6 \n\t"\ +- "paddd %%mm0, %%mm7 \n\t"\ +- " jnz 1b \n\t"\ +- "psrad $16, %%mm4 \n\t"\ +- "psrad $16, %%mm5 \n\t"\ +- "psrad $16, %%mm6 \n\t"\ +- "psrad $16, %%mm7 \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ +- "packssdw %%mm5, %%mm4 \n\t"\ +- "packssdw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm0, %%mm4 \n\t"\ +- "paddw %%mm0, %%mm6 \n\t"\ +- "psraw $3, %%mm4 \n\t"\ +- "psraw $3, %%mm6 \n\t"\ +- "packuswb %%mm6, %%mm4 \n\t"\ +- MOVNTQ(%%mm4, (%1, %%REGa))\ +- "add $8, %%"REG_a" \n\t"\ +- "cmp %2, %%"REG_a" \n\t"\ +- "lea " offset "(%0), %%"REG_d" \n\t"\ +- "pxor %%mm4, %%mm4 \n\t"\ +- "pxor %%mm5, %%mm5 \n\t"\ +- "pxor %%mm6, %%mm6 \n\t"\ +- "pxor %%mm7, %%mm7 \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "jb 1b \n\t"\ +- :: "r" (&c->redDither),\ +- "r" (dest), "g" ((x86_reg)width)\ +- : "%"REG_a, "%"REG_d, "%"REG_S\ +- ); +- +-#define YSCALEYUV2YV121 \ +- "mov %2, %%"REG_a" \n\t"\ +- ".p2align 4 \n\t" /* FIXME Unroll? */\ +- "1: \n\t"\ +- "movq (%0, %%"REG_a", 2), %%mm0 \n\t"\ +- "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"\ +- "psraw $7, %%mm0 \n\t"\ +- "psraw $7, %%mm1 \n\t"\ +- "packuswb %%mm1, %%mm0 \n\t"\ +- MOVNTQ(%%mm0, (%1, %%REGa))\ +- "add $8, %%"REG_a" \n\t"\ +- "jnc 1b \n\t" +- +-#define YSCALEYUV2YV121_ACCURATE \ +- "mov %2, %%"REG_a" \n\t"\ +- "pcmpeqw %%mm7, %%mm7 \n\t"\ +- "psrlw $15, %%mm7 \n\t"\ +- "psllw $6, %%mm7 \n\t"\ +- ".p2align 4 \n\t" /* FIXME Unroll? */\ +- "1: \n\t"\ +- "movq (%0, %%"REG_a", 2), %%mm0 \n\t"\ +- "movq 8(%0, %%"REG_a", 2), %%mm1 \n\t"\ +- "paddsw %%mm7, %%mm0 \n\t"\ +- "paddsw %%mm7, %%mm1 \n\t"\ +- "psraw $7, %%mm0 \n\t"\ +- "psraw $7, %%mm1 \n\t"\ +- "packuswb %%mm1, %%mm0 \n\t"\ +- MOVNTQ(%%mm0, (%1, %%REGa))\ +- "add $8, %%"REG_a" \n\t"\ +- "jnc 1b \n\t" +- +-/* +- :: "m" (-lumFilterSize), "m" (-chrFilterSize), +- "m" (lumMmxFilter+lumFilterSize*4), "m" (chrMmxFilter+chrFilterSize*4), +- "r" (dest), "m" (dstW_reg), +- "m" (lumSrc+lumFilterSize), "m" (chrSrc+chrFilterSize) +- : "%eax", "%ebx", "%ecx", "%edx", "%esi" +-*/ +-#define YSCALEYUV2PACKEDX_UV \ +- __asm__ volatile(\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- ".p2align 4 \n\t"\ +- "nop \n\t"\ +- "1: \n\t"\ +- "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ +- "movq %%mm3, %%mm4 \n\t"\ +- ".p2align 4 \n\t"\ +- "2: \n\t"\ +- "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ +- "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\ +- "movq "AV_STRINGIFY(VOF)"(%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\ +- "add $16, %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "pmulhw %%mm0, %%mm2 \n\t"\ +- "pmulhw %%mm0, %%mm5 \n\t"\ +- "paddw %%mm2, %%mm3 \n\t"\ +- "paddw %%mm5, %%mm4 \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- " jnz 2b \n\t"\ +- +-#define YSCALEYUV2PACKEDX_YA(offset,coeff,src1,src2,dst1,dst2) \ +- "lea "offset"(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), "#dst1" \n\t"\ +- "movq "#dst1", "#dst2" \n\t"\ +- ".p2align 4 \n\t"\ +- "2: \n\t"\ +- "movq 8(%%"REG_d"), "#coeff" \n\t" /* filterCoeff */\ +- "movq (%%"REG_S", %%"REG_a", 2), "#src1" \n\t" /* Y1srcData */\ +- "movq 8(%%"REG_S", %%"REG_a", 2), "#src2" \n\t" /* Y2srcData */\ +- "add $16, %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "pmulhw "#coeff", "#src1" \n\t"\ +- "pmulhw "#coeff", "#src2" \n\t"\ +- "paddw "#src1", "#dst1" \n\t"\ +- "paddw "#src2", "#dst2" \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- " jnz 2b \n\t"\ +- +-#define YSCALEYUV2PACKEDX \ +- YSCALEYUV2PACKEDX_UV \ +- YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET,%%mm0,%%mm2,%%mm5,%%mm1,%%mm7) \ +- +-#define YSCALEYUV2PACKEDX_END \ +- :: "r" (&c->redDither), \ +- "m" (dummy), "m" (dummy), "m" (dummy),\ +- "r" (dest), "m" (dstW_reg) \ +- : "%"REG_a, "%"REG_d, "%"REG_S \ +- ); +- +-#define YSCALEYUV2PACKEDX_ACCURATE_UV \ +- __asm__ volatile(\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- ".p2align 4 \n\t"\ +- "nop \n\t"\ +- "1: \n\t"\ +- "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "pxor %%mm4, %%mm4 \n\t"\ +- "pxor %%mm5, %%mm5 \n\t"\ +- "pxor %%mm6, %%mm6 \n\t"\ +- "pxor %%mm7, %%mm7 \n\t"\ +- ".p2align 4 \n\t"\ +- "2: \n\t"\ +- "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\ +- "movq "AV_STRINGIFY(VOF)"(%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\ +- "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\ +- "movq %%mm0, %%mm3 \n\t"\ +- "punpcklwd %%mm1, %%mm0 \n\t"\ +- "punpckhwd %%mm1, %%mm3 \n\t"\ +- "movq "STR(APCK_COEF)"(%%"REG_d"),%%mm1 \n\t" /* filterCoeff */\ +- "pmaddwd %%mm1, %%mm0 \n\t"\ +- "pmaddwd %%mm1, %%mm3 \n\t"\ +- "paddd %%mm0, %%mm4 \n\t"\ +- "paddd %%mm3, %%mm5 \n\t"\ +- "movq "AV_STRINGIFY(VOF)"(%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\ +- "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "punpcklwd %%mm3, %%mm2 \n\t"\ +- "punpckhwd %%mm3, %%mm0 \n\t"\ +- "pmaddwd %%mm1, %%mm2 \n\t"\ +- "pmaddwd %%mm1, %%mm0 \n\t"\ +- "paddd %%mm2, %%mm6 \n\t"\ +- "paddd %%mm0, %%mm7 \n\t"\ +- " jnz 2b \n\t"\ +- "psrad $16, %%mm4 \n\t"\ +- "psrad $16, %%mm5 \n\t"\ +- "psrad $16, %%mm6 \n\t"\ +- "psrad $16, %%mm7 \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ +- "packssdw %%mm5, %%mm4 \n\t"\ +- "packssdw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm0, %%mm4 \n\t"\ +- "paddw %%mm0, %%mm6 \n\t"\ +- "movq %%mm4, "U_TEMP"(%0) \n\t"\ +- "movq %%mm6, "V_TEMP"(%0) \n\t"\ +- +-#define YSCALEYUV2PACKEDX_ACCURATE_YA(offset) \ +- "lea "offset"(%0), %%"REG_d" \n\t"\ +- "mov (%%"REG_d"), %%"REG_S" \n\t"\ +- "pxor %%mm1, %%mm1 \n\t"\ +- "pxor %%mm5, %%mm5 \n\t"\ +- "pxor %%mm7, %%mm7 \n\t"\ +- "pxor %%mm6, %%mm6 \n\t"\ +- ".p2align 4 \n\t"\ +- "2: \n\t"\ +- "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\ +- "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\ +- "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\ +- "movq %%mm0, %%mm3 \n\t"\ +- "punpcklwd %%mm4, %%mm0 \n\t"\ +- "punpckhwd %%mm4, %%mm3 \n\t"\ +- "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\ +- "pmaddwd %%mm4, %%mm0 \n\t"\ +- "pmaddwd %%mm4, %%mm3 \n\t"\ +- "paddd %%mm0, %%mm1 \n\t"\ +- "paddd %%mm3, %%mm5 \n\t"\ +- "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\ +- "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\ +- "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\ +- "test %%"REG_S", %%"REG_S" \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "punpcklwd %%mm3, %%mm2 \n\t"\ +- "punpckhwd %%mm3, %%mm0 \n\t"\ +- "pmaddwd %%mm4, %%mm2 \n\t"\ +- "pmaddwd %%mm4, %%mm0 \n\t"\ +- "paddd %%mm2, %%mm7 \n\t"\ +- "paddd %%mm0, %%mm6 \n\t"\ +- " jnz 2b \n\t"\ +- "psrad $16, %%mm1 \n\t"\ +- "psrad $16, %%mm5 \n\t"\ +- "psrad $16, %%mm7 \n\t"\ +- "psrad $16, %%mm6 \n\t"\ +- "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ +- "packssdw %%mm5, %%mm1 \n\t"\ +- "packssdw %%mm6, %%mm7 \n\t"\ +- "paddw %%mm0, %%mm1 \n\t"\ +- "paddw %%mm0, %%mm7 \n\t"\ +- "movq "U_TEMP"(%0), %%mm3 \n\t"\ +- "movq "V_TEMP"(%0), %%mm4 \n\t"\ +- +-#define YSCALEYUV2PACKEDX_ACCURATE \ +- YSCALEYUV2PACKEDX_ACCURATE_UV \ +- YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET) +- +-#define YSCALEYUV2RGBX \ +- "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\ +- "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\ +- "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ +- "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ +- "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\ +- "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\ +- /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ +- "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\ +- "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\ +- "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\ +- "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\ +- "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\ +- "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\ +- /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ +- "paddw %%mm3, %%mm4 \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "movq %%mm5, %%mm6 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +- "punpcklwd %%mm2, %%mm2 \n\t"\ +- "punpcklwd %%mm5, %%mm5 \n\t"\ +- "punpcklwd %%mm4, %%mm4 \n\t"\ +- "paddw %%mm1, %%mm2 \n\t"\ +- "paddw %%mm1, %%mm5 \n\t"\ +- "paddw %%mm1, %%mm4 \n\t"\ +- "punpckhwd %%mm0, %%mm0 \n\t"\ +- "punpckhwd %%mm6, %%mm6 \n\t"\ +- "punpckhwd %%mm3, %%mm3 \n\t"\ +- "paddw %%mm7, %%mm0 \n\t"\ +- "paddw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm7, %%mm3 \n\t"\ +- /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ +- "packuswb %%mm0, %%mm2 \n\t"\ +- "packuswb %%mm6, %%mm5 \n\t"\ +- "packuswb %%mm3, %%mm4 \n\t"\ +- +-#define REAL_YSCALEYUV2PACKED(index, c) \ +- "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ +- "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\ +- "psraw $3, %%mm0 \n\t"\ +- "psraw $3, %%mm1 \n\t"\ +- "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\ +- "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ +- "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ +- "movq "AV_STRINGIFY(VOF)"(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ +- "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ +- "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ +- "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ +- "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ +- "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ +- "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ +- "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ +- "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ +- "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ +- "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ +- "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ +- "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ +- "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ +- "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ +- "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ +- "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ +- "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ +- "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ +- "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ +- +-#define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c) +- +-#define REAL_YSCALEYUV2RGB_UV(index, c) \ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ +- "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ +- "movq "AV_STRINGIFY(VOF)"(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ +- "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ +- "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ +- "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ +- "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ +- "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ +- "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ +- "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ +- "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ +- "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ +- "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ +- "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ +- "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ +- "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ +- "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ +- "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ +- /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ +- +-#define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \ +- "movq ("#b1", "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ +- "movq ("#b2", "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ +- "movq 8("#b1", "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ +- "movq 8("#b2", "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ +- "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ +- "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ +- "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ +- "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ +- "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ +- "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ +- +-#define REAL_YSCALEYUV2RGB_COEFF(c) \ +- "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ +- "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ +- "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ +- "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ +- "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ +- "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ +- /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ +- "paddw %%mm3, %%mm4 \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "movq %%mm5, %%mm6 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +- "punpcklwd %%mm2, %%mm2 \n\t"\ +- "punpcklwd %%mm5, %%mm5 \n\t"\ +- "punpcklwd %%mm4, %%mm4 \n\t"\ +- "paddw %%mm1, %%mm2 \n\t"\ +- "paddw %%mm1, %%mm5 \n\t"\ +- "paddw %%mm1, %%mm4 \n\t"\ +- "punpckhwd %%mm0, %%mm0 \n\t"\ +- "punpckhwd %%mm6, %%mm6 \n\t"\ +- "punpckhwd %%mm3, %%mm3 \n\t"\ +- "paddw %%mm7, %%mm0 \n\t"\ +- "paddw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm7, %%mm3 \n\t"\ +- /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ +- "packuswb %%mm0, %%mm2 \n\t"\ +- "packuswb %%mm6, %%mm5 \n\t"\ +- "packuswb %%mm3, %%mm4 \n\t"\ +- +-#define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) +- +-#define YSCALEYUV2RGB(index, c) \ +- REAL_YSCALEYUV2RGB_UV(index, c) \ +- REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \ +- REAL_YSCALEYUV2RGB_COEFF(c) +- +-#define REAL_YSCALEYUV2PACKED1(index, c) \ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ +- "psraw $7, %%mm3 \n\t" \ +- "psraw $7, %%mm4 \n\t" \ +- "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ +- "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ +- "psraw $7, %%mm1 \n\t" \ +- "psraw $7, %%mm7 \n\t" \ +- +-#define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c) +- +-#define REAL_YSCALEYUV2RGB1(index, c) \ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ +- "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ +- "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ +- "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ +- "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ +- "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ +- "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ +- "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ +- "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ +- /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ +- "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ +- "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ +- "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ +- "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ +- "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ +- "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ +- "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ +- "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ +- /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ +- "paddw %%mm3, %%mm4 \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "movq %%mm5, %%mm6 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +- "punpcklwd %%mm2, %%mm2 \n\t"\ +- "punpcklwd %%mm5, %%mm5 \n\t"\ +- "punpcklwd %%mm4, %%mm4 \n\t"\ +- "paddw %%mm1, %%mm2 \n\t"\ +- "paddw %%mm1, %%mm5 \n\t"\ +- "paddw %%mm1, %%mm4 \n\t"\ +- "punpckhwd %%mm0, %%mm0 \n\t"\ +- "punpckhwd %%mm6, %%mm6 \n\t"\ +- "punpckhwd %%mm3, %%mm3 \n\t"\ +- "paddw %%mm7, %%mm0 \n\t"\ +- "paddw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm7, %%mm3 \n\t"\ +- /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ +- "packuswb %%mm0, %%mm2 \n\t"\ +- "packuswb %%mm6, %%mm5 \n\t"\ +- "packuswb %%mm3, %%mm4 \n\t"\ +- +-#define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c) +- +-#define REAL_YSCALEYUV2PACKED1b(index, c) \ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ +- "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ +- "movq "AV_STRINGIFY(VOF)"(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ +- "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ +- "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ +- "psrlw $8, %%mm3 \n\t" \ +- "psrlw $8, %%mm4 \n\t" \ +- "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ +- "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ +- "psraw $7, %%mm1 \n\t" \ +- "psraw $7, %%mm7 \n\t" +-#define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c) +- +-// do vertical chrominance interpolation +-#define REAL_YSCALEYUV2RGB1b(index, c) \ +- "xor "#index", "#index" \n\t"\ +- ".p2align 4 \n\t"\ +- "1: \n\t"\ +- "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ +- "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ +- "movq "AV_STRINGIFY(VOF)"(%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ +- "movq "AV_STRINGIFY(VOF)"(%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ +- "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ +- "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ +- "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\ +- "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\ +- "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ +- "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ +- "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ +- "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ +- "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ +- "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ +- /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ +- "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ +- "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ +- "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ +- "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ +- "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ +- "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ +- "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ +- "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ +- "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ +- /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ +- "paddw %%mm3, %%mm4 \n\t"\ +- "movq %%mm2, %%mm0 \n\t"\ +- "movq %%mm5, %%mm6 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +- "punpcklwd %%mm2, %%mm2 \n\t"\ +- "punpcklwd %%mm5, %%mm5 \n\t"\ +- "punpcklwd %%mm4, %%mm4 \n\t"\ +- "paddw %%mm1, %%mm2 \n\t"\ +- "paddw %%mm1, %%mm5 \n\t"\ +- "paddw %%mm1, %%mm4 \n\t"\ +- "punpckhwd %%mm0, %%mm0 \n\t"\ +- "punpckhwd %%mm6, %%mm6 \n\t"\ +- "punpckhwd %%mm3, %%mm3 \n\t"\ +- "paddw %%mm7, %%mm0 \n\t"\ +- "paddw %%mm7, %%mm6 \n\t"\ +- "paddw %%mm7, %%mm3 \n\t"\ +- /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ +- "packuswb %%mm0, %%mm2 \n\t"\ +- "packuswb %%mm6, %%mm5 \n\t"\ +- "packuswb %%mm3, %%mm4 \n\t"\ +- +-#define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c) +- +-#define REAL_YSCALEYUV2RGB1_ALPHA(index) \ +- "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\ +- "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\ +- "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\ +- "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\ +- "packuswb %%mm1, %%mm7 \n\t" +-#define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index) +- +-#define REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) \ +- "movq "#b", "#q2" \n\t" /* B */\ +- "movq "#r", "#t" \n\t" /* R */\ +- "punpcklbw "#g", "#b" \n\t" /* GBGBGBGB 0 */\ +- "punpcklbw "#a", "#r" \n\t" /* ARARARAR 0 */\ +- "punpckhbw "#g", "#q2" \n\t" /* GBGBGBGB 2 */\ +- "punpckhbw "#a", "#t" \n\t" /* ARARARAR 2 */\ +- "movq "#b", "#q0" \n\t" /* GBGBGBGB 0 */\ +- "movq "#q2", "#q3" \n\t" /* GBGBGBGB 2 */\ +- "punpcklwd "#r", "#q0" \n\t" /* ARGBARGB 0 */\ +- "punpckhwd "#r", "#b" \n\t" /* ARGBARGB 1 */\ +- "punpcklwd "#t", "#q2" \n\t" /* ARGBARGB 2 */\ +- "punpckhwd "#t", "#q3" \n\t" /* ARGBARGB 3 */\ +-\ +- MOVNTQ( q0, (dst, index, 4))\ +- MOVNTQ( b, 8(dst, index, 4))\ +- MOVNTQ( q2, 16(dst, index, 4))\ +- MOVNTQ( q3, 24(dst, index, 4))\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +-#define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) +- +-#define REAL_WRITERGB16(dst, dstw, index) \ +- "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ +- "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\ +- "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ +- "psrlq $3, %%mm2 \n\t"\ +-\ +- "movq %%mm2, %%mm1 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +-\ +- "punpcklbw %%mm7, %%mm3 \n\t"\ +- "punpcklbw %%mm5, %%mm2 \n\t"\ +- "punpckhbw %%mm7, %%mm4 \n\t"\ +- "punpckhbw %%mm5, %%mm1 \n\t"\ +-\ +- "psllq $3, %%mm3 \n\t"\ +- "psllq $3, %%mm4 \n\t"\ +-\ +- "por %%mm3, %%mm2 \n\t"\ +- "por %%mm4, %%mm1 \n\t"\ +-\ +- MOVNTQ(%%mm2, (dst, index, 2))\ +- MOVNTQ(%%mm1, 8(dst, index, 2))\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +-#define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index) +- +-#define REAL_WRITERGB15(dst, dstw, index) \ +- "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ +- "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\ +- "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ +- "psrlq $3, %%mm2 \n\t"\ +- "psrlq $1, %%mm5 \n\t"\ +-\ +- "movq %%mm2, %%mm1 \n\t"\ +- "movq %%mm4, %%mm3 \n\t"\ +-\ +- "punpcklbw %%mm7, %%mm3 \n\t"\ +- "punpcklbw %%mm5, %%mm2 \n\t"\ +- "punpckhbw %%mm7, %%mm4 \n\t"\ +- "punpckhbw %%mm5, %%mm1 \n\t"\ +-\ +- "psllq $2, %%mm3 \n\t"\ +- "psllq $2, %%mm4 \n\t"\ +-\ +- "por %%mm3, %%mm2 \n\t"\ +- "por %%mm4, %%mm1 \n\t"\ +-\ +- MOVNTQ(%%mm2, (dst, index, 2))\ +- MOVNTQ(%%mm1, 8(dst, index, 2))\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +-#define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index) +- +-#define WRITEBGR24OLD(dst, dstw, index) \ +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ +- "movq %%mm2, %%mm1 \n\t" /* B */\ +- "movq %%mm5, %%mm6 \n\t" /* R */\ +- "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ +- "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ +- "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ +- "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ +- "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ +- "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ +- "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ +- "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ +- "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ +- "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ +-\ +- "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ +- "psrlq $8, %%mm0 \n\t" /* 00RGB0RG 0 */\ +- "pand "MANGLE(bm00000111)", %%mm4 \n\t" /* 00000RGB 0 */\ +- "pand "MANGLE(bm11111000)", %%mm0 \n\t" /* 00RGB000 0.5 */\ +- "por %%mm4, %%mm0 \n\t" /* 00RGBRGB 0 */\ +- "movq %%mm2, %%mm4 \n\t" /* 0RGB0RGB 1 */\ +- "psllq $48, %%mm2 \n\t" /* GB000000 1 */\ +- "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ +-\ +- "movq %%mm4, %%mm2 \n\t" /* 0RGB0RGB 1 */\ +- "psrld $16, %%mm4 \n\t" /* 000R000R 1 */\ +- "psrlq $24, %%mm2 \n\t" /* 0000RGB0 1.5 */\ +- "por %%mm4, %%mm2 \n\t" /* 000RRGBR 1 */\ +- "pand "MANGLE(bm00001111)", %%mm2 \n\t" /* 0000RGBR 1 */\ +- "movq %%mm1, %%mm4 \n\t" /* 0RGB0RGB 2 */\ +- "psrlq $8, %%mm1 \n\t" /* 00RGB0RG 2 */\ +- "pand "MANGLE(bm00000111)", %%mm4 \n\t" /* 00000RGB 2 */\ +- "pand "MANGLE(bm11111000)", %%mm1 \n\t" /* 00RGB000 2.5 */\ +- "por %%mm4, %%mm1 \n\t" /* 00RGBRGB 2 */\ +- "movq %%mm1, %%mm4 \n\t" /* 00RGBRGB 2 */\ +- "psllq $32, %%mm1 \n\t" /* BRGB0000 2 */\ +- "por %%mm1, %%mm2 \n\t" /* BRGBRGBR 1 */\ +-\ +- "psrlq $32, %%mm4 \n\t" /* 000000RG 2.5 */\ +- "movq %%mm3, %%mm5 \n\t" /* 0RGB0RGB 3 */\ +- "psrlq $8, %%mm3 \n\t" /* 00RGB0RG 3 */\ +- "pand "MANGLE(bm00000111)", %%mm5 \n\t" /* 00000RGB 3 */\ +- "pand "MANGLE(bm11111000)", %%mm3 \n\t" /* 00RGB000 3.5 */\ +- "por %%mm5, %%mm3 \n\t" /* 00RGBRGB 3 */\ +- "psllq $16, %%mm3 \n\t" /* RGBRGB00 3 */\ +- "por %%mm4, %%mm3 \n\t" /* RGBRGBRG 2.5 */\ +-\ +- MOVNTQ(%%mm0, (dst))\ +- MOVNTQ(%%mm2, 8(dst))\ +- MOVNTQ(%%mm3, 16(dst))\ +- "add $24, "#dst" \n\t"\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +- +-#define WRITEBGR24MMX(dst, dstw, index) \ +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ +- "movq %%mm2, %%mm1 \n\t" /* B */\ +- "movq %%mm5, %%mm6 \n\t" /* R */\ +- "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ +- "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ +- "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ +- "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ +- "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ +- "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ +- "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ +- "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ +- "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ +- "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ +-\ +- "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ +- "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\ +- "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\ +- "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\ +-\ +- "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\ +- "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\ +- "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\ +- "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ +-\ +- "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\ +- "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\ +- "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\ +- "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\ +-\ +- "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\ +- "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\ +- "psllq $40, %%mm2 \n\t" /* GB000000 1 */\ +- "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ +- MOVNTQ(%%mm0, (dst))\ +-\ +- "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ +- "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\ +- "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\ +- "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\ +- MOVNTQ(%%mm6, 8(dst))\ +-\ +- "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\ +- "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ +- "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\ +- MOVNTQ(%%mm5, 16(dst))\ +-\ +- "add $24, "#dst" \n\t"\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +- +-#define WRITEBGR24MMX2(dst, dstw, index) \ +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ +- "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\ +- "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\ +- "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ +- "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ +- "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ +-\ +- "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\ +- "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\ +- "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ +-\ +- "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ +- "por %%mm1, %%mm6 \n\t"\ +- "por %%mm3, %%mm6 \n\t"\ +- MOVNTQ(%%mm6, (dst))\ +-\ +- "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ +- "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ +- "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ +- "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ +-\ +- "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5 B4 B3 */\ +- "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ +- "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\ +-\ +- "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ +- "por %%mm3, %%mm6 \n\t"\ +- MOVNTQ(%%mm6, 8(dst))\ +-\ +- "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ +- "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ +- "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ +-\ +- "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\ +- "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\ +- "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ +-\ +- "por %%mm1, %%mm3 \n\t"\ +- "por %%mm3, %%mm6 \n\t"\ +- MOVNTQ(%%mm6, 16(dst))\ +-\ +- "add $24, "#dst" \n\t"\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +- +-#if COMPILE_TEMPLATE_MMX2 +-#undef WRITEBGR24 +-#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index) +-#else +-#undef WRITEBGR24 +-#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index) +-#endif +- +-#define REAL_WRITEYUY2(dst, dstw, index) \ +- "packuswb %%mm3, %%mm3 \n\t"\ +- "packuswb %%mm4, %%mm4 \n\t"\ +- "packuswb %%mm7, %%mm1 \n\t"\ +- "punpcklbw %%mm4, %%mm3 \n\t"\ +- "movq %%mm1, %%mm7 \n\t"\ +- "punpcklbw %%mm3, %%mm1 \n\t"\ +- "punpckhbw %%mm3, %%mm7 \n\t"\ +-\ +- MOVNTQ(%%mm1, (dst, index, 2))\ +- MOVNTQ(%%mm7, 8(dst, index, 2))\ +-\ +- "add $8, "#index" \n\t"\ +- "cmp "#dstw", "#index" \n\t"\ +- " jb 1b \n\t" +-#define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index) +- +- +-static inline void RENAME(yuv2yuvX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, const int16_t **alpSrc, +- uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW) +-{ +-#if COMPILE_TEMPLATE_MMX +- if(!(c->flags & SWS_BITEXACT)) { +- if (c->flags & SWS_ACCURATE_RND) { +- if (uDest) { +- YSCALEYUV2YV12X_ACCURATE( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW) +- YSCALEYUV2YV12X_ACCURATE(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW) +- } +- if (CONFIG_SWSCALE_ALPHA && aDest) { +- YSCALEYUV2YV12X_ACCURATE( "0", ALP_MMX_FILTER_OFFSET, aDest, dstW) +- } +- +- YSCALEYUV2YV12X_ACCURATE("0", LUM_MMX_FILTER_OFFSET, dest, dstW) +- } else { +- if (uDest) { +- YSCALEYUV2YV12X( "0", CHR_MMX_FILTER_OFFSET, uDest, chrDstW) +- YSCALEYUV2YV12X(AV_STRINGIFY(VOF), CHR_MMX_FILTER_OFFSET, vDest, chrDstW) +- } +- if (CONFIG_SWSCALE_ALPHA && aDest) { +- YSCALEYUV2YV12X( "0", ALP_MMX_FILTER_OFFSET, aDest, dstW) +- } +- +- YSCALEYUV2YV12X("0", LUM_MMX_FILTER_OFFSET, dest, dstW) +- } +- return; +- } +-#endif +-#if COMPILE_TEMPLATE_ALTIVEC +- yuv2yuvX_altivec_real(lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- dest, uDest, vDest, dstW, chrDstW); +-#else //COMPILE_TEMPLATE_ALTIVEC +- yuv2yuvXinC(lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- alpSrc, dest, uDest, vDest, aDest, dstW, chrDstW); +-#endif //!COMPILE_TEMPLATE_ALTIVEC +-} +- +-static inline void RENAME(yuv2nv12X)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- uint8_t *dest, uint8_t *uDest, int dstW, int chrDstW, enum PixelFormat dstFormat) +-{ +- yuv2nv12XinC(lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- dest, uDest, dstW, chrDstW, dstFormat); +-} +- +-static inline void RENAME(yuv2yuv1)(SwsContext *c, const int16_t *lumSrc, const int16_t *chrSrc, const int16_t *alpSrc, +- uint8_t *dest, uint8_t *uDest, uint8_t *vDest, uint8_t *aDest, long dstW, long chrDstW) +-{ +- int i; +-#if COMPILE_TEMPLATE_MMX +- if(!(c->flags & SWS_BITEXACT)) { +- long p= 4; +- const uint8_t *src[4]= {alpSrc + dstW, lumSrc + dstW, chrSrc + chrDstW, chrSrc + VOFW + chrDstW}; +- uint8_t *dst[4]= {aDest, dest, uDest, vDest}; +- x86_reg counter[4]= {dstW, dstW, chrDstW, chrDstW}; +- +- if (c->flags & SWS_ACCURATE_RND) { +- while(p--) { +- if (dst[p]) { +- __asm__ volatile( +- YSCALEYUV2YV121_ACCURATE +- :: "r" (src[p]), "r" (dst[p] + counter[p]), +- "g" (-counter[p]) +- : "%"REG_a +- ); +- } +- } +- } else { +- while(p--) { +- if (dst[p]) { +- __asm__ volatile( +- YSCALEYUV2YV121 +- :: "r" (src[p]), "r" (dst[p] + counter[p]), +- "g" (-counter[p]) +- : "%"REG_a +- ); +- } +- } +- } +- return; +- } +-#endif +- for (i=0; i>7; +- +- if (val&256) { +- if (val<0) val=0; +- else val=255; +- } +- +- dest[i]= val; +- } +- +- if (uDest) +- for (i=0; i>7; +- int v=(chrSrc[i + VOFW]+64)>>7; +- +- if ((u|v)&256) { +- if (u<0) u=0; +- else if (u>255) u=255; +- if (v<0) v=0; +- else if (v>255) v=255; +- } +- +- uDest[i]= u; +- vDest[i]= v; +- } +- +- if (CONFIG_SWSCALE_ALPHA && aDest) +- for (i=0; i>7; +- aDest[i]= av_clip_uint8(val); +- } +-} +- +- +-/** +- * vertical scale YV12 to RGB +- */ +-static inline void RENAME(yuv2packedX)(SwsContext *c, const int16_t *lumFilter, const int16_t **lumSrc, int lumFilterSize, +- const int16_t *chrFilter, const int16_t **chrSrc, int chrFilterSize, +- const int16_t **alpSrc, uint8_t *dest, long dstW, long dstY) +-{ +-#if COMPILE_TEMPLATE_MMX +- x86_reg dummy=0; +- x86_reg dstW_reg = dstW; +- if(!(c->flags & SWS_BITEXACT)) { +- if (c->flags & SWS_ACCURATE_RND) { +- switch(c->dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- YSCALEYUV2PACKEDX_ACCURATE +- YSCALEYUV2RGBX +- "movq %%mm2, "U_TEMP"(%0) \n\t" +- "movq %%mm4, "V_TEMP"(%0) \n\t" +- "movq %%mm5, "Y_TEMP"(%0) \n\t" +- YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET) +- "movq "Y_TEMP"(%0), %%mm5 \n\t" +- "psraw $3, %%mm1 \n\t" +- "psraw $3, %%mm7 \n\t" +- "packuswb %%mm7, %%mm1 \n\t" +- WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6) +- +- YSCALEYUV2PACKEDX_END +- } else { +- YSCALEYUV2PACKEDX_ACCURATE +- YSCALEYUV2RGBX +- "pcmpeqd %%mm7, %%mm7 \n\t" +- WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- +- YSCALEYUV2PACKEDX_END +- } +- return; +- case PIX_FMT_BGR24: +- YSCALEYUV2PACKEDX_ACCURATE +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize +- "add %4, %%"REG_c" \n\t" +- WRITEBGR24(%%REGc, %5, %%REGa) +- +- +- :: "r" (&c->redDither), +- "m" (dummy), "m" (dummy), "m" (dummy), +- "r" (dest), "m" (dstW_reg) +- : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S +- ); +- return; +- case PIX_FMT_RGB555: +- YSCALEYUV2PACKEDX_ACCURATE +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%0), %%mm2\n\t" +- "paddusb "GREEN_DITHER"(%0), %%mm4\n\t" +- "paddusb "RED_DITHER"(%0), %%mm5\n\t" +-#endif +- +- WRITERGB15(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- case PIX_FMT_RGB565: +- YSCALEYUV2PACKEDX_ACCURATE +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%0), %%mm2\n\t" +- "paddusb "GREEN_DITHER"(%0), %%mm4\n\t" +- "paddusb "RED_DITHER"(%0), %%mm5\n\t" +-#endif +- +- WRITERGB16(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- case PIX_FMT_YUYV422: +- YSCALEYUV2PACKEDX_ACCURATE +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +- +- "psraw $3, %%mm3 \n\t" +- "psraw $3, %%mm4 \n\t" +- "psraw $3, %%mm1 \n\t" +- "psraw $3, %%mm7 \n\t" +- WRITEYUY2(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- } +- } else { +- switch(c->dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- YSCALEYUV2PACKEDX +- YSCALEYUV2RGBX +- YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7) +- "psraw $3, %%mm1 \n\t" +- "psraw $3, %%mm7 \n\t" +- "packuswb %%mm7, %%mm1 \n\t" +- WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) +- YSCALEYUV2PACKEDX_END +- } else { +- YSCALEYUV2PACKEDX +- YSCALEYUV2RGBX +- "pcmpeqd %%mm7, %%mm7 \n\t" +- WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- YSCALEYUV2PACKEDX_END +- } +- return; +- case PIX_FMT_BGR24: +- YSCALEYUV2PACKEDX +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize +- "add %4, %%"REG_c" \n\t" +- WRITEBGR24(%%REGc, %5, %%REGa) +- +- :: "r" (&c->redDither), +- "m" (dummy), "m" (dummy), "m" (dummy), +- "r" (dest), "m" (dstW_reg) +- : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S +- ); +- return; +- case PIX_FMT_RGB555: +- YSCALEYUV2PACKEDX +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%0), %%mm5 \n\t" +-#endif +- +- WRITERGB15(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- case PIX_FMT_RGB565: +- YSCALEYUV2PACKEDX +- YSCALEYUV2RGBX +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%0), %%mm5 \n\t" +-#endif +- +- WRITERGB16(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- case PIX_FMT_YUYV422: +- YSCALEYUV2PACKEDX +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +- +- "psraw $3, %%mm3 \n\t" +- "psraw $3, %%mm4 \n\t" +- "psraw $3, %%mm1 \n\t" +- "psraw $3, %%mm7 \n\t" +- WRITEYUY2(%4, %5, %%REGa) +- YSCALEYUV2PACKEDX_END +- return; +- } +- } +- } +-#endif /* COMPILE_TEMPLATE_MMX */ +-#if COMPILE_TEMPLATE_ALTIVEC +- /* The following list of supported dstFormat values should +- match what's found in the body of ff_yuv2packedX_altivec() */ +- if (!(c->flags & SWS_BITEXACT) && !c->alpPixBuf && +- (c->dstFormat==PIX_FMT_ABGR || c->dstFormat==PIX_FMT_BGRA || +- c->dstFormat==PIX_FMT_BGR24 || c->dstFormat==PIX_FMT_RGB24 || +- c->dstFormat==PIX_FMT_RGBA || c->dstFormat==PIX_FMT_ARGB)) +- ff_yuv2packedX_altivec(c, lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- dest, dstW, dstY); +- else +-#endif +- yuv2packedXinC(c, lumFilter, lumSrc, lumFilterSize, +- chrFilter, chrSrc, chrFilterSize, +- alpSrc, dest, dstW, dstY); +-} +- +-/** +- * vertical bilinear scale YV12 to RGB +- */ +-static inline void RENAME(yuv2packed2)(SwsContext *c, const uint16_t *buf0, const uint16_t *buf1, const uint16_t *uvbuf0, const uint16_t *uvbuf1, +- const uint16_t *abuf0, const uint16_t *abuf1, uint8_t *dest, int dstW, int yalpha, int uvalpha, int y) +-{ +- int yalpha1=4095- yalpha; +- int uvalpha1=4095-uvalpha; +- int i; +- +-#if COMPILE_TEMPLATE_MMX +- if(!(c->flags & SWS_BITEXACT)) { +- switch(c->dstFormat) { +- //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +-#if ARCH_X86_64 +- __asm__ volatile( +- YSCALEYUV2RGB(%%r8, %5) +- YSCALEYUV2RGB_YA(%%r8, %5, %6, %7) +- "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ +- "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ +- "packuswb %%mm7, %%mm1 \n\t" +- WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "r" (dest), +- "a" (&c->redDither) +- ,"r" (abuf0), "r" (abuf1) +- : "%r8" +- ); +-#else +- *(const uint16_t **)(&c->u_temp)=abuf0; +- *(const uint16_t **)(&c->v_temp)=abuf1; +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB(%%REGBP, %5) +- "push %0 \n\t" +- "push %1 \n\t" +- "mov "U_TEMP"(%5), %0 \n\t" +- "mov "V_TEMP"(%5), %1 \n\t" +- YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1) +- "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ +- "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ +- "packuswb %%mm7, %%mm1 \n\t" +- "pop %1 \n\t" +- "pop %0 \n\t" +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +-#endif +- } else { +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB(%%REGBP, %5) +- "pcmpeqd %%mm7, %%mm7 \n\t" +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- } +- return; +- case PIX_FMT_BGR24: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- WRITEBGR24(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB555: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- +- WRITERGB15(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB565: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- +- WRITERGB16(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_YUYV422: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2PACKED(%%REGBP, %5) +- WRITEYUY2(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- default: break; +- } +- } +-#endif //COMPILE_TEMPLATE_MMX +- YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB2_C, YSCALE_YUV_2_PACKED2_C(void,0), YSCALE_YUV_2_GRAY16_2_C, YSCALE_YUV_2_MONO2_C) +-} +- +-/** +- * YV12 to RGB without scaling or interpolating +- */ +-static inline void RENAME(yuv2packed1)(SwsContext *c, const uint16_t *buf0, const uint16_t *uvbuf0, const uint16_t *uvbuf1, +- const uint16_t *abuf0, uint8_t *dest, int dstW, int uvalpha, enum PixelFormat dstFormat, int flags, int y) +-{ +- const int yalpha1=0; +- int i; +- +- const uint16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 +- const int yalpha= 4096; //FIXME ... +- +- if (flags&SWS_FULL_CHR_H_INT) { +- c->yuv2packed2(c, buf0, buf0, uvbuf0, uvbuf1, abuf0, abuf0, dest, dstW, 0, uvalpha, y); +- return; +- } +- +-#if COMPILE_TEMPLATE_MMX +- if(!(flags & SWS_BITEXACT)) { +- if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster +- switch(dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1(%%REGBP, %5) +- YSCALEYUV2RGB1_ALPHA(%%REGBP) +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (abuf0), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- } else { +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1(%%REGBP, %5) +- "pcmpeqd %%mm7, %%mm7 \n\t" +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- } +- return; +- case PIX_FMT_BGR24: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- WRITEBGR24(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB555: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- WRITERGB15(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB565: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- +- WRITERGB16(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_YUYV422: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2PACKED1(%%REGBP, %5) +- WRITEYUY2(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- } +- } else { +- switch(dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1b(%%REGBP, %5) +- YSCALEYUV2RGB1_ALPHA(%%REGBP) +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (abuf0), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- } else { +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1b(%%REGBP, %5) +- "pcmpeqd %%mm7, %%mm7 \n\t" +- WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- } +- return; +- case PIX_FMT_BGR24: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1b(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- WRITEBGR24(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB555: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1b(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- WRITERGB15(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_RGB565: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2RGB1b(%%REGBP, %5) +- "pxor %%mm7, %%mm7 \n\t" +- /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ +-#ifdef DITHER1XBPP +- "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" +- "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" +- "paddusb "RED_DITHER"(%5), %%mm5 \n\t" +-#endif +- +- WRITERGB16(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- case PIX_FMT_YUYV422: +- __asm__ volatile( +- "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" +- "mov %4, %%"REG_b" \n\t" +- "push %%"REG_BP" \n\t" +- YSCALEYUV2PACKED1b(%%REGBP, %5) +- WRITEYUY2(%%REGb, 8280(%5), %%REGBP) +- "pop %%"REG_BP" \n\t" +- "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" +- +- :: "c" (buf0), "d" (buf1), "S" (uvbuf0), "D" (uvbuf1), "m" (dest), +- "a" (&c->redDither) +- ); +- return; +- } +- } +- } +-#endif /* COMPILE_TEMPLATE_MMX */ +- if (uvalpha < 2048) { +- YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1_C, YSCALE_YUV_2_PACKED1_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C) +- } else { +- YSCALE_YUV_2_ANYRGB_C(YSCALE_YUV_2_RGB1B_C, YSCALE_YUV_2_PACKED1B_C(void,0), YSCALE_YUV_2_GRAY16_1_C, YSCALE_YUV_2_MONO2_C) +- } +-} +- +-//FIXME yuy2* can read up to 7 samples too much +- +-static inline void RENAME(yuy2ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +-{ +-#if COMPILE_TEMPLATE_MMX +- __asm__ volatile( +- "movq "MANGLE(bm01010101)", %%mm2 \n\t" +- "mov %0, %%"REG_a" \n\t" +- "1: \n\t" +- "movq (%1, %%"REG_a",2), %%mm0 \n\t" +- "movq 8(%1, %%"REG_a",2), %%mm1 \n\t" +- "pand %%mm2, %%mm0 \n\t" +- "pand %%mm2, %%mm1 \n\t" +- "packuswb %%mm1, %%mm0 \n\t" +- "movq %%mm0, (%2, %%"REG_a") \n\t" +- "add $8, %%"REG_a" \n\t" +- " js 1b \n\t" +- : : "g" ((x86_reg)-width), "r" (src+width*2), "r" (dst+width) +- : "%"REG_a +- ); +-#else +- int i; +- for (i=0; i>RGB2YUV_SHIFT); +- } +-#endif /* COMPILE_TEMPLATE_MMX */ +-} +- +-static inline void RENAME(bgr24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +-{ +-#if COMPILE_TEMPLATE_MMX +- RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24); +-#else +- int i; +- for (i=0; i>RGB2YUV_SHIFT; +- dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; +- } +-#endif /* COMPILE_TEMPLATE_MMX */ +- assert(src1 == src2); +-} +- +-static inline void RENAME(bgr24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +-{ +- int i; +- for (i=0; i>(RGB2YUV_SHIFT+1); +- dstV[i]= (RV*r + GV*g + BV*b + (257<>(RGB2YUV_SHIFT+1); +- } +- assert(src1 == src2); +-} +- +-static inline void RENAME(rgb24ToY)(uint8_t *dst, const uint8_t *src, long width, uint32_t *unused) +-{ +-#if COMPILE_TEMPLATE_MMX +- RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24); +-#else +- int i; +- for (i=0; i>RGB2YUV_SHIFT); +- } +-#endif +-} +- +-static inline void RENAME(rgb24ToUV)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +-{ +-#if COMPILE_TEMPLATE_MMX +- assert(src1==src2); +- RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24); +-#else +- int i; +- assert(src1==src2); +- for (i=0; i>RGB2YUV_SHIFT; +- dstV[i]= (RV*r + GV*g + BV*b + (257<<(RGB2YUV_SHIFT-1)))>>RGB2YUV_SHIFT; +- } +-#endif +-} +- +-static inline void RENAME(rgb24ToUV_half)(uint8_t *dstU, uint8_t *dstV, const uint8_t *src1, const uint8_t *src2, long width, uint32_t *unused) +-{ +- int i; +- assert(src1==src2); +- for (i=0; i>(RGB2YUV_SHIFT+1); +- dstV[i]= (RV*r + GV*g + BV*b + (257<>(RGB2YUV_SHIFT+1); +- } +-} +- +- +-// bilinear / bicubic scaling +-static inline void RENAME(hScale)(int16_t *dst, int dstW, const uint8_t *src, int srcW, int xInc, +- const int16_t *filter, const int16_t *filterPos, long filterSize) +-{ +-#if COMPILE_TEMPLATE_MMX +- assert(filterSize % 4 == 0 && filterSize>0); +- if (filterSize==4) { // Always true for upscaling, sometimes for down, too. +- x86_reg counter= -2*dstW; +- filter-= counter*2; +- filterPos-= counter/2; +- dst-= counter/2; +- __asm__ volatile( +-#if defined(PIC) +- "push %%"REG_b" \n\t" +-#endif +- "pxor %%mm7, %%mm7 \n\t" +- "push %%"REG_BP" \n\t" // we use 7 regs here ... +- "mov %%"REG_a", %%"REG_BP" \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- "movzwl (%2, %%"REG_BP"), %%eax \n\t" +- "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t" +- "movq (%1, %%"REG_BP", 4), %%mm1 \n\t" +- "movq 8(%1, %%"REG_BP", 4), %%mm3 \n\t" +- "movd (%3, %%"REG_a"), %%mm0 \n\t" +- "movd (%3, %%"REG_b"), %%mm2 \n\t" +- "punpcklbw %%mm7, %%mm0 \n\t" +- "punpcklbw %%mm7, %%mm2 \n\t" +- "pmaddwd %%mm1, %%mm0 \n\t" +- "pmaddwd %%mm2, %%mm3 \n\t" +- "movq %%mm0, %%mm4 \n\t" +- "punpckldq %%mm3, %%mm0 \n\t" +- "punpckhdq %%mm3, %%mm4 \n\t" +- "paddd %%mm4, %%mm0 \n\t" +- "psrad $7, %%mm0 \n\t" +- "packssdw %%mm0, %%mm0 \n\t" +- "movd %%mm0, (%4, %%"REG_BP") \n\t" +- "add $4, %%"REG_BP" \n\t" +- " jnc 1b \n\t" +- +- "pop %%"REG_BP" \n\t" +-#if defined(PIC) +- "pop %%"REG_b" \n\t" +-#endif +- : "+a" (counter) +- : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) +-#if !defined(PIC) +- : "%"REG_b +-#endif +- ); +- } else if (filterSize==8) { +- x86_reg counter= -2*dstW; +- filter-= counter*4; +- filterPos-= counter/2; +- dst-= counter/2; +- __asm__ volatile( +-#if defined(PIC) +- "push %%"REG_b" \n\t" +-#endif +- "pxor %%mm7, %%mm7 \n\t" +- "push %%"REG_BP" \n\t" // we use 7 regs here ... +- "mov %%"REG_a", %%"REG_BP" \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- "movzwl (%2, %%"REG_BP"), %%eax \n\t" +- "movzwl 2(%2, %%"REG_BP"), %%ebx \n\t" +- "movq (%1, %%"REG_BP", 8), %%mm1 \n\t" +- "movq 16(%1, %%"REG_BP", 8), %%mm3 \n\t" +- "movd (%3, %%"REG_a"), %%mm0 \n\t" +- "movd (%3, %%"REG_b"), %%mm2 \n\t" +- "punpcklbw %%mm7, %%mm0 \n\t" +- "punpcklbw %%mm7, %%mm2 \n\t" +- "pmaddwd %%mm1, %%mm0 \n\t" +- "pmaddwd %%mm2, %%mm3 \n\t" +- +- "movq 8(%1, %%"REG_BP", 8), %%mm1 \n\t" +- "movq 24(%1, %%"REG_BP", 8), %%mm5 \n\t" +- "movd 4(%3, %%"REG_a"), %%mm4 \n\t" +- "movd 4(%3, %%"REG_b"), %%mm2 \n\t" +- "punpcklbw %%mm7, %%mm4 \n\t" +- "punpcklbw %%mm7, %%mm2 \n\t" +- "pmaddwd %%mm1, %%mm4 \n\t" +- "pmaddwd %%mm2, %%mm5 \n\t" +- "paddd %%mm4, %%mm0 \n\t" +- "paddd %%mm5, %%mm3 \n\t" +- "movq %%mm0, %%mm4 \n\t" +- "punpckldq %%mm3, %%mm0 \n\t" +- "punpckhdq %%mm3, %%mm4 \n\t" +- "paddd %%mm4, %%mm0 \n\t" +- "psrad $7, %%mm0 \n\t" +- "packssdw %%mm0, %%mm0 \n\t" +- "movd %%mm0, (%4, %%"REG_BP") \n\t" +- "add $4, %%"REG_BP" \n\t" +- " jnc 1b \n\t" +- +- "pop %%"REG_BP" \n\t" +-#if defined(PIC) +- "pop %%"REG_b" \n\t" +-#endif +- : "+a" (counter) +- : "c" (filter), "d" (filterPos), "S" (src), "D" (dst) +-#if !defined(PIC) +- : "%"REG_b +-#endif +- ); +- } else { +- const uint8_t *offset = src+filterSize; +- x86_reg counter= -2*dstW; +- //filter-= counter*filterSize/2; +- filterPos-= counter/2; +- dst-= counter/2; +- __asm__ volatile( +- "pxor %%mm7, %%mm7 \n\t" +- ".p2align 4 \n\t" +- "1: \n\t" +- "mov %2, %%"REG_c" \n\t" +- "movzwl (%%"REG_c", %0), %%eax \n\t" +- "movzwl 2(%%"REG_c", %0), %%edx \n\t" +- "mov %5, %%"REG_c" \n\t" +- "pxor %%mm4, %%mm4 \n\t" +- "pxor %%mm5, %%mm5 \n\t" +- "2: \n\t" +- "movq (%1), %%mm1 \n\t" +- "movq (%1, %6), %%mm3 \n\t" +- "movd (%%"REG_c", %%"REG_a"), %%mm0 \n\t" +- "movd (%%"REG_c", %%"REG_d"), %%mm2 \n\t" +- "punpcklbw %%mm7, %%mm0 \n\t" +- "punpcklbw %%mm7, %%mm2 \n\t" +- "pmaddwd %%mm1, %%mm0 \n\t" +- "pmaddwd %%mm2, %%mm3 \n\t" +- "paddd %%mm3, %%mm5 \n\t" +- "paddd %%mm0, %%mm4 \n\t" +- "add $8, %1 \n\t" +- "add $4, %%"REG_c" \n\t" +- "cmp %4, %%"REG_c" \n\t" +- " jb 2b \n\t" +- "add %6, %1 \n\t" +- "movq %%mm4, %%mm0 \n\t" +- "punpckldq %%mm5, %%mm4 \n\t" +- "punpckhdq %%mm5, %%mm0 \n\t" +- "paddd %%mm0, %%mm4 \n\t" +- "psrad $7, %%mm4 \n\t" +- "packssdw %%mm4, %%mm4 \n\t" +- "mov %3, %%"REG_a" \n\t" +- "movd %%mm4, (%%"REG_a", %0) \n\t" +- "add $4, %0 \n\t" +- " jnc 1b \n\t" +- +- : "+r" (counter), "+r" (filter) +- : "m" (filterPos), "m" (dst), "m"(offset), +- "m" (src), "r" ((x86_reg)filterSize*2) +- : "%"REG_a, "%"REG_c, "%"REG_d +- ); +- } +-#else +-#if COMPILE_TEMPLATE_ALTIVEC +- hScale_altivec_real(dst, dstW, src, srcW, xInc, filter, filterPos, filterSize); +-#else +- int i; +- for (i=0; i>7, (1<<15)-1); // the cubic equation does overflow ... +- //dst[i] = val>>7; +- } +-#endif /* COMPILE_TEMPLATE_ALTIVEC */ +-#endif /* COMPILE_MMX */ +-} +- +-//FIXME all pal and rgb srcFormats could do this convertion as well +-//FIXME all scalers more complex than bilinear could do half of this transform +-static void RENAME(chrRangeToJpeg)(uint16_t *dst, int width) +-{ +- int i; +- for (i = 0; i < width; i++) { +- dst[i ] = (FFMIN(dst[i ],30775)*4663 - 9289992)>>12; //-264 +- dst[i+VOFW] = (FFMIN(dst[i+VOFW],30775)*4663 - 9289992)>>12; //-264 +- } +-} +-static void RENAME(chrRangeFromJpeg)(uint16_t *dst, int width) +-{ +- int i; +- for (i = 0; i < width; i++) { +- dst[i ] = (dst[i ]*1799 + 4081085)>>11; //1469 +- dst[i+VOFW] = (dst[i+VOFW]*1799 + 4081085)>>11; //1469 +- } +-} +-static void RENAME(lumRangeToJpeg)(uint16_t *dst, int width) +-{ +- int i; +- for (i = 0; i < width; i++) +- dst[i] = (FFMIN(dst[i],30189)*19077 - 39057361)>>14; +-} +-static void RENAME(lumRangeFromJpeg)(uint16_t *dst, int width) +-{ +- int i; +- for (i = 0; i < width; i++) +- dst[i] = (dst[i]*14071 + 33561947)>>14; +-} +- +-#define FAST_BILINEAR_X86 \ +- "subl %%edi, %%esi \n\t" /* src[xx+1] - src[xx] */ \ +- "imull %%ecx, %%esi \n\t" /* (src[xx+1] - src[xx])*xalpha */ \ +- "shll $16, %%edi \n\t" \ +- "addl %%edi, %%esi \n\t" /* src[xx+1]*xalpha + src[xx]*(1-xalpha) */ \ +- "mov %1, %%"REG_D"\n\t" \ +- "shrl $9, %%esi \n\t" \ +- +-static inline void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, +- long dstWidth, const uint8_t *src, int srcW, +- int xInc) +-{ +-#if ARCH_X86 +-#if COMPILE_TEMPLATE_MMX2 +- int32_t *filterPos = c->hLumFilterPos; +- int16_t *filter = c->hLumFilter; +- int canMMX2BeUsed = c->canMMX2BeUsed; +- void *mmx2FilterCode= c->lumMmx2FilterCode; +- int i; +-#if defined(PIC) +- DECLARE_ALIGNED(8, uint64_t, ebxsave); +-#endif +- if (canMMX2BeUsed) { +- __asm__ volatile( +-#if defined(PIC) +- "mov %%"REG_b", %5 \n\t" +-#endif +- "pxor %%mm7, %%mm7 \n\t" +- "mov %0, %%"REG_c" \n\t" +- "mov %1, %%"REG_D" \n\t" +- "mov %2, %%"REG_d" \n\t" +- "mov %3, %%"REG_b" \n\t" +- "xor %%"REG_a", %%"REG_a" \n\t" // i +- PREFETCH" (%%"REG_c") \n\t" +- PREFETCH" 32(%%"REG_c") \n\t" +- PREFETCH" 64(%%"REG_c") \n\t" +- +-#if ARCH_X86_64 +- +-#define CALL_MMX2_FILTER_CODE \ +- "movl (%%"REG_b"), %%esi \n\t"\ +- "call *%4 \n\t"\ +- "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ +- "add %%"REG_S", %%"REG_c" \n\t"\ +- "add %%"REG_a", %%"REG_D" \n\t"\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- +-#else +- +-#define CALL_MMX2_FILTER_CODE \ +- "movl (%%"REG_b"), %%esi \n\t"\ +- "call *%4 \n\t"\ +- "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ +- "add %%"REG_a", %%"REG_D" \n\t"\ +- "xor %%"REG_a", %%"REG_a" \n\t"\ +- +-#endif /* ARCH_X86_64 */ +- +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- +-#if defined(PIC) +- "mov %5, %%"REG_b" \n\t" +-#endif +- :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos), +- "m" (mmx2FilterCode) +-#if defined(PIC) +- ,"m" (ebxsave) +-#endif +- : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D +-#if !defined(PIC) +- ,"%"REG_b +-#endif +- ); +- for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) dst[i] = src[srcW-1]*128; +- } else { +-#endif /* COMPILE_TEMPLATE_MMX2 */ +- x86_reg xInc_shr16 = xInc >> 16; +- uint16_t xInc_mask = xInc & 0xffff; +- x86_reg dstWidth_reg = dstWidth; +- //NO MMX just normal asm ... +- __asm__ volatile( +- "xor %%"REG_a", %%"REG_a" \n\t" // i +- "xor %%"REG_d", %%"REG_d" \n\t" // xx +- "xorl %%ecx, %%ecx \n\t" // xalpha +- ".p2align 4 \n\t" +- "1: \n\t" +- "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] +- "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] +- FAST_BILINEAR_X86 +- "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" +- "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF +- "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry +- +- "movzbl (%0, %%"REG_d"), %%edi \n\t" //src[xx] +- "movzbl 1(%0, %%"REG_d"), %%esi \n\t" //src[xx+1] +- FAST_BILINEAR_X86 +- "movw %%si, 2(%%"REG_D", %%"REG_a", 2) \n\t" +- "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF +- "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry +- +- +- "add $2, %%"REG_a" \n\t" +- "cmp %2, %%"REG_a" \n\t" +- " jb 1b \n\t" +- +- +- :: "r" (src), "m" (dst), "m" (dstWidth_reg), "m" (xInc_shr16), "m" (xInc_mask) +- : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" +- ); +-#if COMPILE_TEMPLATE_MMX2 +- } //if MMX2 can't be used +-#endif +-#else +- int i; +- unsigned int xpos=0; +- for (i=0;i>16; +- register unsigned int xalpha=(xpos&0xFFFF)>>9; +- dst[i]= (src[xx]<<7) + (src[xx+1] - src[xx])*xalpha; +- xpos+=xInc; +- } +-#endif /* ARCH_X86 */ +-} +- +- // *** horizontal scale Y line to temp buffer +-static inline void RENAME(hyscale)(SwsContext *c, uint16_t *dst, long dstWidth, const uint8_t *src, int srcW, int xInc, +- const int16_t *hLumFilter, +- const int16_t *hLumFilterPos, int hLumFilterSize, +- uint8_t *formatConvBuffer, +- uint32_t *pal, int isAlpha) +-{ +- void (*toYV12)(uint8_t *, const uint8_t *, long, uint32_t *) = isAlpha ? c->alpToYV12 : c->lumToYV12; +- void (*convertRange)(uint16_t *, int) = isAlpha ? NULL : c->lumConvertRange; +- +- src += isAlpha ? c->alpSrcOffset : c->lumSrcOffset; +- +- if (toYV12) { +- toYV12(formatConvBuffer, src, srcW, pal); +- src= formatConvBuffer; +- } +- +- if (!c->hyscale_fast) { +- c->hScale(dst, dstWidth, src, srcW, xInc, hLumFilter, hLumFilterPos, hLumFilterSize); +- } else { // fast bilinear upscale / crap downscale +- c->hyscale_fast(c, dst, dstWidth, src, srcW, xInc); +- } +- +- if (convertRange) +- convertRange(dst, dstWidth); +-} +- +-static inline void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst, +- long dstWidth, const uint8_t *src1, +- const uint8_t *src2, int srcW, int xInc) +-{ +-#if ARCH_X86 +-#if COMPILE_TEMPLATE_MMX2 +- int32_t *filterPos = c->hChrFilterPos; +- int16_t *filter = c->hChrFilter; +- int canMMX2BeUsed = c->canMMX2BeUsed; +- void *mmx2FilterCode= c->chrMmx2FilterCode; +- int i; +-#if defined(PIC) +- DECLARE_ALIGNED(8, uint64_t, ebxsave); +-#endif +- if (canMMX2BeUsed) { +- __asm__ volatile( +-#if defined(PIC) +- "mov %%"REG_b", %6 \n\t" +-#endif +- "pxor %%mm7, %%mm7 \n\t" +- "mov %0, %%"REG_c" \n\t" +- "mov %1, %%"REG_D" \n\t" +- "mov %2, %%"REG_d" \n\t" +- "mov %3, %%"REG_b" \n\t" +- "xor %%"REG_a", %%"REG_a" \n\t" // i +- PREFETCH" (%%"REG_c") \n\t" +- PREFETCH" 32(%%"REG_c") \n\t" +- PREFETCH" 64(%%"REG_c") \n\t" +- +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- "xor %%"REG_a", %%"REG_a" \n\t" // i +- "mov %5, %%"REG_c" \n\t" // src +- "mov %1, %%"REG_D" \n\t" // buf1 +- "add $"AV_STRINGIFY(VOF)", %%"REG_D" \n\t" +- PREFETCH" (%%"REG_c") \n\t" +- PREFETCH" 32(%%"REG_c") \n\t" +- PREFETCH" 64(%%"REG_c") \n\t" +- +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- CALL_MMX2_FILTER_CODE +- +-#if defined(PIC) +- "mov %6, %%"REG_b" \n\t" +-#endif +- :: "m" (src1), "m" (dst), "m" (filter), "m" (filterPos), +- "m" (mmx2FilterCode), "m" (src2) +-#if defined(PIC) +- ,"m" (ebxsave) +-#endif +- : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D +-#if !defined(PIC) +- ,"%"REG_b +-#endif +- ); +- for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { +- //printf("%d %d %d\n", dstWidth, i, srcW); +- dst[i] = src1[srcW-1]*128; +- dst[i+VOFW] = src2[srcW-1]*128; +- } +- } else { +-#endif /* COMPILE_TEMPLATE_MMX2 */ +- x86_reg xInc_shr16 = (x86_reg) (xInc >> 16); +- uint16_t xInc_mask = xInc & 0xffff; +- x86_reg dstWidth_reg = dstWidth; +- __asm__ volatile( +- "xor %%"REG_a", %%"REG_a" \n\t" // i +- "xor %%"REG_d", %%"REG_d" \n\t" // xx +- "xorl %%ecx, %%ecx \n\t" // xalpha +- ".p2align 4 \n\t" +- "1: \n\t" +- "mov %0, %%"REG_S" \n\t" +- "movzbl (%%"REG_S", %%"REG_d"), %%edi \n\t" //src[xx] +- "movzbl 1(%%"REG_S", %%"REG_d"), %%esi \n\t" //src[xx+1] +- FAST_BILINEAR_X86 +- "movw %%si, (%%"REG_D", %%"REG_a", 2) \n\t" +- +- "movzbl (%5, %%"REG_d"), %%edi \n\t" //src[xx] +- "movzbl 1(%5, %%"REG_d"), %%esi \n\t" //src[xx+1] +- FAST_BILINEAR_X86 +- "movw %%si, "AV_STRINGIFY(VOF)"(%%"REG_D", %%"REG_a", 2) \n\t" +- +- "addw %4, %%cx \n\t" //xalpha += xInc&0xFFFF +- "adc %3, %%"REG_d" \n\t" //xx+= xInc>>16 + carry +- "add $1, %%"REG_a" \n\t" +- "cmp %2, %%"REG_a" \n\t" +- " jb 1b \n\t" +- +-/* GCC 3.3 makes MPlayer crash on IA-32 machines when using "g" operand here, +-which is needed to support GCC 4.0. */ +-#if ARCH_X86_64 && AV_GCC_VERSION_AT_LEAST(3,4) +- :: "m" (src1), "m" (dst), "g" (dstWidth_reg), "m" (xInc_shr16), "m" (xInc_mask), +-#else +- :: "m" (src1), "m" (dst), "m" (dstWidth_reg), "m" (xInc_shr16), "m" (xInc_mask), +-#endif +- "r" (src2) +- : "%"REG_a, "%"REG_d, "%ecx", "%"REG_D, "%esi" +- ); +-#if COMPILE_TEMPLATE_MMX2 +- } //if MMX2 can't be used +-#endif +-#else +- int i; +- unsigned int xpos=0; +- for (i=0;i>16; +- register unsigned int xalpha=(xpos&0xFFFF)>>9; +- dst[i]=(src1[xx]*(xalpha^127)+src1[xx+1]*xalpha); +- dst[i+VOFW]=(src2[xx]*(xalpha^127)+src2[xx+1]*xalpha); +- /* slower +- dst[i]= (src1[xx]<<7) + (src1[xx+1] - src1[xx])*xalpha; +- dst[i+VOFW]=(src2[xx]<<7) + (src2[xx+1] - src2[xx])*xalpha; +- */ +- xpos+=xInc; +- } +-#endif /* ARCH_X86 */ +-} +- +-inline static void RENAME(hcscale)(SwsContext *c, uint16_t *dst, long dstWidth, const uint8_t *src1, const uint8_t *src2, +- int srcW, int xInc, const int16_t *hChrFilter, +- const int16_t *hChrFilterPos, int hChrFilterSize, +- uint8_t *formatConvBuffer, +- uint32_t *pal) +-{ +- +- src1 += c->chrSrcOffset; +- src2 += c->chrSrcOffset; +- +- if (c->chrToYV12) { +- c->chrToYV12(formatConvBuffer, formatConvBuffer+VOFW, src1, src2, srcW, pal); +- src1= formatConvBuffer; +- src2= formatConvBuffer+VOFW; +- } +- +- if (!c->hcscale_fast) { +- c->hScale(dst , dstWidth, src1, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); +- c->hScale(dst+VOFW, dstWidth, src2, srcW, xInc, hChrFilter, hChrFilterPos, hChrFilterSize); +- } else { // fast bilinear upscale / crap downscale +- c->hcscale_fast(c, dst, dstWidth, src1, src2, srcW, xInc); +- } +- +- if (c->chrConvertRange) +- c->chrConvertRange(dst, dstWidth); +-} +- +-#define DEBUG_SWSCALE_BUFFERS 0 +-#define DEBUG_BUFFERS(...) if (DEBUG_SWSCALE_BUFFERS) av_log(c, AV_LOG_DEBUG, __VA_ARGS__) +- +-static int RENAME(swScale)(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, +- int srcSliceH, uint8_t* dst[], int dstStride[]) +-{ +- /* load a few things into local vars to make the code more readable? and faster */ +- const int srcW= c->srcW; +- const int dstW= c->dstW; +- const int dstH= c->dstH; +- const int chrDstW= c->chrDstW; +- const int chrSrcW= c->chrSrcW; +- const int lumXInc= c->lumXInc; +- const int chrXInc= c->chrXInc; +- const enum PixelFormat dstFormat= c->dstFormat; +- const int flags= c->flags; +- int16_t *vLumFilterPos= c->vLumFilterPos; +- int16_t *vChrFilterPos= c->vChrFilterPos; +- int16_t *hLumFilterPos= c->hLumFilterPos; +- int16_t *hChrFilterPos= c->hChrFilterPos; +- int16_t *vLumFilter= c->vLumFilter; +- int16_t *vChrFilter= c->vChrFilter; +- int16_t *hLumFilter= c->hLumFilter; +- int16_t *hChrFilter= c->hChrFilter; +- int32_t *lumMmxFilter= c->lumMmxFilter; +- int32_t *chrMmxFilter= c->chrMmxFilter; +- int32_t av_unused *alpMmxFilter= c->alpMmxFilter; +- const int vLumFilterSize= c->vLumFilterSize; +- const int vChrFilterSize= c->vChrFilterSize; +- const int hLumFilterSize= c->hLumFilterSize; +- const int hChrFilterSize= c->hChrFilterSize; +- int16_t **lumPixBuf= c->lumPixBuf; +- int16_t **chrPixBuf= c->chrPixBuf; +- int16_t **alpPixBuf= c->alpPixBuf; +- const int vLumBufSize= c->vLumBufSize; +- const int vChrBufSize= c->vChrBufSize; +- uint8_t *formatConvBuffer= c->formatConvBuffer; +- const int chrSrcSliceY= srcSliceY >> c->chrSrcVSubSample; +- const int chrSrcSliceH= -((-srcSliceH) >> c->chrSrcVSubSample); +- int lastDstY; +- uint32_t *pal=c->pal_yuv; +- +- /* vars which will change and which we need to store back in the context */ +- int dstY= c->dstY; +- int lumBufIndex= c->lumBufIndex; +- int chrBufIndex= c->chrBufIndex; +- int lastInLumBuf= c->lastInLumBuf; +- int lastInChrBuf= c->lastInChrBuf; +- +- if (isPacked(c->srcFormat)) { +- src[0]= +- src[1]= +- src[2]= +- src[3]= src[0]; +- srcStride[0]= +- srcStride[1]= +- srcStride[2]= +- srcStride[3]= srcStride[0]; +- } +- srcStride[1]<<= c->vChrDrop; +- srcStride[2]<<= c->vChrDrop; +- +- DEBUG_BUFFERS("swScale() %p[%d] %p[%d] %p[%d] %p[%d] -> %p[%d] %p[%d] %p[%d] %p[%d]\n", +- src[0], srcStride[0], src[1], srcStride[1], src[2], srcStride[2], src[3], srcStride[3], +- dst[0], dstStride[0], dst[1], dstStride[1], dst[2], dstStride[2], dst[3], dstStride[3]); +- DEBUG_BUFFERS("srcSliceY: %d srcSliceH: %d dstY: %d dstH: %d\n", +- srcSliceY, srcSliceH, dstY, dstH); +- DEBUG_BUFFERS("vLumFilterSize: %d vLumBufSize: %d vChrFilterSize: %d vChrBufSize: %d\n", +- vLumFilterSize, vLumBufSize, vChrFilterSize, vChrBufSize); +- +- if (dstStride[0]%8 !=0 || dstStride[1]%8 !=0 || dstStride[2]%8 !=0 || dstStride[3]%8 != 0) { +- static int warnedAlready=0; //FIXME move this into the context perhaps +- if (flags & SWS_PRINT_INFO && !warnedAlready) { +- av_log(c, AV_LOG_WARNING, "Warning: dstStride is not aligned!\n" +- " ->cannot do aligned memory accesses anymore\n"); +- warnedAlready=1; +- } +- } +- +- /* Note the user might start scaling the picture in the middle so this +- will not get executed. This is not really intended but works +- currently, so people might do it. */ +- if (srcSliceY ==0) { +- lumBufIndex=-1; +- chrBufIndex=-1; +- dstY=0; +- lastInLumBuf= -1; +- lastInChrBuf= -1; +- } +- +- lastDstY= dstY; +- +- for (;dstY < dstH; dstY++) { +- unsigned char *dest =dst[0]+dstStride[0]*dstY; +- const int chrDstY= dstY>>c->chrDstVSubSample; +- unsigned char *uDest=dst[1]+dstStride[1]*chrDstY; +- unsigned char *vDest=dst[2]+dstStride[2]*chrDstY; +- unsigned char *aDest=(CONFIG_SWSCALE_ALPHA && alpPixBuf) ? dst[3]+dstStride[3]*dstY : NULL; +- +- const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input +- const int firstLumSrcY2= vLumFilterPos[FFMIN(dstY | ((1<chrDstVSubSample) - 1), dstH-1)]; +- const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input +- int lastLumSrcY= firstLumSrcY + vLumFilterSize -1; // Last line needed as input +- int lastLumSrcY2=firstLumSrcY2+ vLumFilterSize -1; // Last line needed as input +- int lastChrSrcY= firstChrSrcY + vChrFilterSize -1; // Last line needed as input +- int enough_lines; +- +- //handle holes (FAST_BILINEAR & weird filters) +- if (firstLumSrcY > lastInLumBuf) lastInLumBuf= firstLumSrcY-1; +- if (firstChrSrcY > lastInChrBuf) lastInChrBuf= firstChrSrcY-1; +- assert(firstLumSrcY >= lastInLumBuf - vLumBufSize + 1); +- assert(firstChrSrcY >= lastInChrBuf - vChrBufSize + 1); +- +- DEBUG_BUFFERS("dstY: %d\n", dstY); +- DEBUG_BUFFERS("\tfirstLumSrcY: %d lastLumSrcY: %d lastInLumBuf: %d\n", +- firstLumSrcY, lastLumSrcY, lastInLumBuf); +- DEBUG_BUFFERS("\tfirstChrSrcY: %d lastChrSrcY: %d lastInChrBuf: %d\n", +- firstChrSrcY, lastChrSrcY, lastInChrBuf); +- +- // Do we have enough lines in this slice to output the dstY line +- enough_lines = lastLumSrcY2 < srcSliceY + srcSliceH && lastChrSrcY < -((-srcSliceY - srcSliceH)>>c->chrSrcVSubSample); +- +- if (!enough_lines) { +- lastLumSrcY = srcSliceY + srcSliceH - 1; +- lastChrSrcY = chrSrcSliceY + chrSrcSliceH - 1; +- DEBUG_BUFFERS("buffering slice: lastLumSrcY %d lastChrSrcY %d\n", +- lastLumSrcY, lastChrSrcY); +- } +- +- //Do horizontal scaling +- while(lastInLumBuf < lastLumSrcY) { +- const uint8_t *src1= src[0]+(lastInLumBuf + 1 - srcSliceY)*srcStride[0]; +- const uint8_t *src2= src[3]+(lastInLumBuf + 1 - srcSliceY)*srcStride[3]; +- lumBufIndex++; +- assert(lumBufIndex < 2*vLumBufSize); +- assert(lastInLumBuf + 1 - srcSliceY < srcSliceH); +- assert(lastInLumBuf + 1 - srcSliceY >= 0); +- RENAME(hyscale)(c, lumPixBuf[ lumBufIndex ], dstW, src1, srcW, lumXInc, +- hLumFilter, hLumFilterPos, hLumFilterSize, +- formatConvBuffer, +- pal, 0); +- if (CONFIG_SWSCALE_ALPHA && alpPixBuf) +- RENAME(hyscale)(c, alpPixBuf[ lumBufIndex ], dstW, src2, srcW, lumXInc, +- hLumFilter, hLumFilterPos, hLumFilterSize, +- formatConvBuffer, +- pal, 1); +- lastInLumBuf++; +- DEBUG_BUFFERS("\t\tlumBufIndex %d: lastInLumBuf: %d\n", +- lumBufIndex, lastInLumBuf); +- } +- while(lastInChrBuf < lastChrSrcY) { +- const uint8_t *src1= src[1]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[1]; +- const uint8_t *src2= src[2]+(lastInChrBuf + 1 - chrSrcSliceY)*srcStride[2]; +- chrBufIndex++; +- assert(chrBufIndex < 2*vChrBufSize); +- assert(lastInChrBuf + 1 - chrSrcSliceY < (chrSrcSliceH)); +- assert(lastInChrBuf + 1 - chrSrcSliceY >= 0); +- //FIXME replace parameters through context struct (some at least) +- +- if (c->needs_hcscale) +- RENAME(hcscale)(c, chrPixBuf[ chrBufIndex ], chrDstW, src1, src2, chrSrcW, chrXInc, +- hChrFilter, hChrFilterPos, hChrFilterSize, +- formatConvBuffer, +- pal); +- lastInChrBuf++; +- DEBUG_BUFFERS("\t\tchrBufIndex %d: lastInChrBuf: %d\n", +- chrBufIndex, lastInChrBuf); +- } +- //wrap buf index around to stay inside the ring buffer +- if (lumBufIndex >= vLumBufSize) lumBufIndex-= vLumBufSize; +- if (chrBufIndex >= vChrBufSize) chrBufIndex-= vChrBufSize; +- if (!enough_lines) +- break; //we can't output a dstY line so let's try with the next slice +- +-#if COMPILE_TEMPLATE_MMX +- c->blueDither= ff_dither8[dstY&1]; +- if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) +- c->greenDither= ff_dither8[dstY&1]; +- else +- c->greenDither= ff_dither4[dstY&1]; +- c->redDither= ff_dither8[(dstY+1)&1]; +-#endif +- if (dstY < dstH-2) { +- const int16_t **lumSrcPtr= (const int16_t **) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; +- const int16_t **chrSrcPtr= (const int16_t **) chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; +- const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; +-#if COMPILE_TEMPLATE_MMX +- int i; +- if (flags & SWS_ACCURATE_RND) { +- int s= APCK_SIZE / 8; +- for (i=0; i1)]; +- lumMmxFilter[s*i+APCK_COEF/4 ]= +- lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] +- + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); +- if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { +- *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; +- *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; +- alpMmxFilter[s*i+APCK_COEF/4 ]= +- alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; +- } +- } +- for (i=0; i1)]; +- chrMmxFilter[s*i+APCK_COEF/4 ]= +- chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] +- + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); +- } +- } else { +- for (i=0; i> 32; +- lumMmxFilter[4*i+2]= +- lumMmxFilter[4*i+3]= +- ((uint16_t)vLumFilter[dstY*vLumFilterSize + i])*0x10001; +- if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { +- alpMmxFilter[4*i+0]= (int32_t)alpSrcPtr[i]; +- alpMmxFilter[4*i+1]= (uint64_t)alpSrcPtr[i] >> 32; +- alpMmxFilter[4*i+2]= +- alpMmxFilter[4*i+3]= lumMmxFilter[4*i+2]; +- } +- } +- for (i=0; i> 32; +- chrMmxFilter[4*i+2]= +- chrMmxFilter[4*i+3]= +- ((uint16_t)vChrFilter[chrDstY*vChrFilterSize + i])*0x10001; +- } +- } +-#endif +- if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) { +- const int chrSkipMask= (1<chrDstVSubSample)-1; +- if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi +- c->yuv2nv12X(c, +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- dest, uDest, dstW, chrDstW, dstFormat); +- } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 like +- const int chrSkipMask= (1<chrDstVSubSample)-1; +- if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi +- if (is16BPS(dstFormat)) { +- yuv2yuvX16inC( +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW, +- dstFormat); +- } else if (vLumFilterSize == 1 && vChrFilterSize == 1) { // unscaled YV12 +- const int16_t *lumBuf = lumSrcPtr[0]; +- const int16_t *chrBuf= chrSrcPtr[0]; +- const int16_t *alpBuf= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? alpSrcPtr[0] : NULL; +- c->yuv2yuv1(c, lumBuf, chrBuf, alpBuf, dest, uDest, vDest, aDest, dstW, chrDstW); +- } else { //General YV12 +- c->yuv2yuvX(c, +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW); +- } +- } else { +- assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); +- assert(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); +- if (vLumFilterSize == 1 && vChrFilterSize == 2) { //unscaled RGB +- int chrAlpha= vChrFilter[2*dstY+1]; +- if(flags & SWS_FULL_CHR_H_INT) { +- yuv2rgbXinC_full(c, //FIXME write a packed1_full function +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } else { +- c->yuv2packed1(c, *lumSrcPtr, *chrSrcPtr, *(chrSrcPtr+1), +- alpPixBuf ? *alpSrcPtr : NULL, +- dest, dstW, chrAlpha, dstFormat, flags, dstY); +- } +- } else if (vLumFilterSize == 2 && vChrFilterSize == 2) { //bilinear upscale RGB +- int lumAlpha= vLumFilter[2*dstY+1]; +- int chrAlpha= vChrFilter[2*dstY+1]; +- lumMmxFilter[2]= +- lumMmxFilter[3]= vLumFilter[2*dstY ]*0x10001; +- chrMmxFilter[2]= +- chrMmxFilter[3]= vChrFilter[2*chrDstY]*0x10001; +- if(flags & SWS_FULL_CHR_H_INT) { +- yuv2rgbXinC_full(c, //FIXME write a packed2_full function +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } else { +- c->yuv2packed2(c, *lumSrcPtr, *(lumSrcPtr+1), *chrSrcPtr, *(chrSrcPtr+1), +- alpPixBuf ? *alpSrcPtr : NULL, alpPixBuf ? *(alpSrcPtr+1) : NULL, +- dest, dstW, lumAlpha, chrAlpha, dstY); +- } +- } else { //general RGB +- if(flags & SWS_FULL_CHR_H_INT) { +- yuv2rgbXinC_full(c, +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } else { +- c->yuv2packedX(c, +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } +- } +- } +- } else { // hmm looks like we can't use MMX here without overwriting this array's tail +- const int16_t **lumSrcPtr= (const int16_t **)lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; +- const int16_t **chrSrcPtr= (const int16_t **)chrPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; +- const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; +- if (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21) { +- const int chrSkipMask= (1<chrDstVSubSample)-1; +- if (dstY&chrSkipMask) uDest= NULL; //FIXME split functions in lumi / chromi +- yuv2nv12XinC( +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- dest, uDest, dstW, chrDstW, dstFormat); +- } else if (isPlanarYUV(dstFormat) || dstFormat==PIX_FMT_GRAY8) { //YV12 +- const int chrSkipMask= (1<chrDstVSubSample)-1; +- if ((dstY&chrSkipMask) || isGray(dstFormat)) uDest=vDest= NULL; //FIXME split functions in lumi / chromi +- if (is16BPS(dstFormat)) { +- yuv2yuvX16inC( +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, (uint16_t *) dest, (uint16_t *) uDest, (uint16_t *) vDest, (uint16_t *) aDest, dstW, chrDstW, +- dstFormat); +- } else { +- yuv2yuvXinC( +- vLumFilter+dstY*vLumFilterSize , lumSrcPtr, vLumFilterSize, +- vChrFilter+chrDstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, uDest, vDest, aDest, dstW, chrDstW); +- } +- } else { +- assert(lumSrcPtr + vLumFilterSize - 1 < lumPixBuf + vLumBufSize*2); +- assert(chrSrcPtr + vChrFilterSize - 1 < chrPixBuf + vChrBufSize*2); +- if(flags & SWS_FULL_CHR_H_INT) { +- yuv2rgbXinC_full(c, +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } else { +- yuv2packedXinC(c, +- vLumFilter+dstY*vLumFilterSize, lumSrcPtr, vLumFilterSize, +- vChrFilter+dstY*vChrFilterSize, chrSrcPtr, vChrFilterSize, +- alpSrcPtr, dest, dstW, dstY); +- } +- } +- } +- } +- +- if ((dstFormat == PIX_FMT_YUVA420P) && !alpPixBuf) +- fillPlane(dst[3], dstStride[3], dstW, dstY-lastDstY, lastDstY, 255); +- +-#if COMPILE_TEMPLATE_MMX +- if (flags & SWS_CPU_CAPS_MMX2 ) __asm__ volatile("sfence":::"memory"); +- /* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ +- if (flags & SWS_CPU_CAPS_3DNOW) __asm__ volatile("femms" :::"memory"); +- else __asm__ volatile("emms" :::"memory"); +-#endif +- /* store changed local vars back in the context */ +- c->dstY= dstY; +- c->lumBufIndex= lumBufIndex; +- c->chrBufIndex= chrBufIndex; +- c->lastInLumBuf= lastInLumBuf; +- c->lastInChrBuf= lastInChrBuf; +- +- return dstY - lastDstY; +-} +- +-static void RENAME(sws_init_swScale)(SwsContext *c) +-{ +- enum PixelFormat srcFormat = c->srcFormat; +- +- c->yuv2nv12X = RENAME(yuv2nv12X ); +- c->yuv2yuv1 = RENAME(yuv2yuv1 ); +- c->yuv2yuvX = RENAME(yuv2yuvX ); +- c->yuv2packed1 = RENAME(yuv2packed1 ); +- c->yuv2packed2 = RENAME(yuv2packed2 ); +- c->yuv2packedX = RENAME(yuv2packedX ); +- +- c->hScale = RENAME(hScale ); +- +-#if COMPILE_TEMPLATE_MMX +- // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). +- if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed) +-#else +- if (c->flags & SWS_FAST_BILINEAR) +-#endif +- { +- c->hyscale_fast = RENAME(hyscale_fast); +- c->hcscale_fast = RENAME(hcscale_fast); +- } +- +- c->chrToYV12 = NULL; +- switch(srcFormat) { +- case PIX_FMT_YUYV422 : c->chrToYV12 = RENAME(yuy2ToUV); break; +- case PIX_FMT_UYVY422 : c->chrToYV12 = RENAME(uyvyToUV); break; +- case PIX_FMT_NV12 : c->chrToYV12 = RENAME(nv12ToUV); break; +- case PIX_FMT_NV21 : c->chrToYV12 = RENAME(nv21ToUV); break; +- case PIX_FMT_RGB8 : +- case PIX_FMT_BGR8 : +- case PIX_FMT_PAL8 : +- case PIX_FMT_BGR4_BYTE: +- case PIX_FMT_RGB4_BYTE: c->chrToYV12 = palToUV; break; +- case PIX_FMT_YUV420P16BE: +- case PIX_FMT_YUV422P16BE: +- case PIX_FMT_YUV444P16BE: c->chrToYV12 = RENAME(BEToUV); break; +- case PIX_FMT_YUV420P16LE: +- case PIX_FMT_YUV422P16LE: +- case PIX_FMT_YUV444P16LE: c->chrToYV12 = RENAME(LEToUV); break; +- } +- if (c->chrSrcHSubSample) { +- switch(srcFormat) { +- case PIX_FMT_RGB48BE: +- case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV_half; break; +- case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV_half; break; +- case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV_half; break; +- case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV_half); break; +- case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV_half; break; +- case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV_half; break; +- case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV_half; break; +- case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV_half; break; +- case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV_half); break; +- case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV_half; break; +- case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV_half; break; +- } +- } else { +- switch(srcFormat) { +- case PIX_FMT_RGB48BE: +- case PIX_FMT_RGB48LE: c->chrToYV12 = rgb48ToUV; break; +- case PIX_FMT_RGB32 : c->chrToYV12 = bgr32ToUV; break; +- case PIX_FMT_RGB32_1: c->chrToYV12 = bgr321ToUV; break; +- case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break; +- case PIX_FMT_BGR565 : c->chrToYV12 = bgr16ToUV; break; +- case PIX_FMT_BGR555 : c->chrToYV12 = bgr15ToUV; break; +- case PIX_FMT_BGR32 : c->chrToYV12 = rgb32ToUV; break; +- case PIX_FMT_BGR32_1: c->chrToYV12 = rgb321ToUV; break; +- case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break; +- case PIX_FMT_RGB565 : c->chrToYV12 = rgb16ToUV; break; +- case PIX_FMT_RGB555 : c->chrToYV12 = rgb15ToUV; break; +- } +- } +- +- c->lumToYV12 = NULL; +- c->alpToYV12 = NULL; +- switch (srcFormat) { +- case PIX_FMT_YUYV422 : +- case PIX_FMT_YUV420P16BE: +- case PIX_FMT_YUV422P16BE: +- case PIX_FMT_YUV444P16BE: +- case PIX_FMT_Y400A : +- case PIX_FMT_GRAY16BE : c->lumToYV12 = RENAME(yuy2ToY); break; +- case PIX_FMT_UYVY422 : +- case PIX_FMT_YUV420P16LE: +- case PIX_FMT_YUV422P16LE: +- case PIX_FMT_YUV444P16LE: +- case PIX_FMT_GRAY16LE : c->lumToYV12 = RENAME(uyvyToY); break; +- case PIX_FMT_BGR24 : c->lumToYV12 = RENAME(bgr24ToY); break; +- case PIX_FMT_BGR565 : c->lumToYV12 = bgr16ToY; break; +- case PIX_FMT_BGR555 : c->lumToYV12 = bgr15ToY; break; +- case PIX_FMT_RGB24 : c->lumToYV12 = RENAME(rgb24ToY); break; +- case PIX_FMT_RGB565 : c->lumToYV12 = rgb16ToY; break; +- case PIX_FMT_RGB555 : c->lumToYV12 = rgb15ToY; break; +- case PIX_FMT_RGB8 : +- case PIX_FMT_BGR8 : +- case PIX_FMT_PAL8 : +- case PIX_FMT_BGR4_BYTE: +- case PIX_FMT_RGB4_BYTE: c->lumToYV12 = palToY; break; +- case PIX_FMT_MONOBLACK: c->lumToYV12 = monoblack2Y; break; +- case PIX_FMT_MONOWHITE: c->lumToYV12 = monowhite2Y; break; +- case PIX_FMT_RGB32 : c->lumToYV12 = bgr32ToY; break; +- case PIX_FMT_RGB32_1: c->lumToYV12 = bgr321ToY; break; +- case PIX_FMT_BGR32 : c->lumToYV12 = rgb32ToY; break; +- case PIX_FMT_BGR32_1: c->lumToYV12 = rgb321ToY; break; +- case PIX_FMT_RGB48BE: +- case PIX_FMT_RGB48LE: c->lumToYV12 = rgb48ToY; break; +- } +- if (c->alpPixBuf) { +- switch (srcFormat) { +- case PIX_FMT_RGB32 : +- case PIX_FMT_RGB32_1: +- case PIX_FMT_BGR32 : +- case PIX_FMT_BGR32_1: c->alpToYV12 = abgrToA; break; +- case PIX_FMT_Y400A : c->alpToYV12 = RENAME(yuy2ToY); break; +- } +- } +- +- switch (srcFormat) { +- case PIX_FMT_Y400A : +- c->alpSrcOffset = 1; +- break; +- case PIX_FMT_RGB32 : +- case PIX_FMT_BGR32 : +- c->alpSrcOffset = 3; +- break; +- case PIX_FMT_RGB48LE: +- c->lumSrcOffset = 1; +- c->chrSrcOffset = 1; +- c->alpSrcOffset = 1; +- break; +- } +- +- if (c->srcRange != c->dstRange && !isAnyRGB(c->dstFormat)) { +- if (c->srcRange) { +- c->lumConvertRange = RENAME(lumRangeFromJpeg); +- c->chrConvertRange = RENAME(chrRangeFromJpeg); +- } else { +- c->lumConvertRange = RENAME(lumRangeToJpeg); +- c->chrConvertRange = RENAME(chrRangeToJpeg); +- } +- } +- +- if (!(isGray(srcFormat) || isGray(c->dstFormat) || +- srcFormat == PIX_FMT_MONOBLACK || srcFormat == PIX_FMT_MONOWHITE)) +- c->needs_hcscale = 1; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale-test.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale-test.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/swscale-test.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/swscale-test.c 2012-05-14 14:08:55.408361598 +0200 +@@ -1,5 +1,5 @@ + /* +- * Copyright (C) 2003 Michael Niedermayer ++ * Copyright (C) 2003-2011 Michael Niedermayer + * + * This file is part of FFmpeg. + * +@@ -25,7 +25,7 @@ + #include + + #undef HAVE_AV_CONFIG_H +-#include "libavcore/imgutils.h" ++#include "libavutil/imgutils.h" + #include "libavutil/mem.h" + #include "libavutil/avutil.h" + #include "libavutil/crc.h" +@@ -35,38 +35,33 @@ + + /* HACK Duplicated from swscale_internal.h. + * Should be removed when a cleaner pixel format system exists. */ +-#define isGray(x) ( \ +- (x)==PIX_FMT_GRAY8 \ +- || (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- ) +-#define hasChroma(x) (!( \ +- isGray(x) \ +- || (x)==PIX_FMT_MONOBLACK \ +- || (x)==PIX_FMT_MONOWHITE \ +- )) +-#define isALPHA(x) ( \ +- (x)==PIX_FMT_BGR32 \ +- || (x)==PIX_FMT_BGR32_1 \ +- || (x)==PIX_FMT_RGB32 \ +- || (x)==PIX_FMT_RGB32_1 \ +- || (x)==PIX_FMT_YUVA420P \ +- ) ++#define isGray(x) \ ++ ((x) == PIX_FMT_GRAY8 || \ ++ (x) == PIX_FMT_Y400A || \ ++ (x) == PIX_FMT_GRAY16BE || \ ++ (x) == PIX_FMT_GRAY16LE) ++#define hasChroma(x) \ ++ (!(isGray(x) || \ ++ (x) == PIX_FMT_MONOBLACK || \ ++ (x) == PIX_FMT_MONOWHITE)) ++#define isALPHA(x) \ ++ ((x) == PIX_FMT_BGR32 || \ ++ (x) == PIX_FMT_BGR32_1 || \ ++ (x) == PIX_FMT_RGB32 || \ ++ (x) == PIX_FMT_RGB32_1 || \ ++ (x) == PIX_FMT_YUVA420P) + +-static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, int stride2, int w, int h) ++static uint64_t getSSD(uint8_t *src1, uint8_t *src2, int stride1, ++ int stride2, int w, int h) + { +- int x,y; +- uint64_t ssd=0; +- +-//printf("%d %d\n", w, h); ++ int x, y; ++ uint64_t ssd = 0; + +- for (y=0; y %s\n", + av_pix_fmt_descriptors[srcFormat].name, + av_pix_fmt_descriptors[dstFormat].name); + res = -1; +- + goto end; + } +-// printf("test %X %X %X -> %X %X %X\n", (int)ref[0], (int)ref[1], (int)ref[2], +-// (int)src[0], (int)src[1], (int)src[2]); + + printf(" %s %dx%d -> %s %3dx%3d flags=%2d", + av_pix_fmt_descriptors[srcFormat].name, srcW, srcH, +@@ -174,9 +166,9 @@ + + sws_scale(dstContext, src, srcStride, 0, srcH, dst, dstStride); + +- for (i = 0; i < 4 && dstStride[i]; i++) { +- crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], dstStride[i] * dstH); +- } ++ for (i = 0; i < 4 && dstStride[i]; i++) ++ crc = av_crc(av_crc_get_table(AV_CRC_32_IEEE), crc, dst[i], ++ dstStride[i] * dstH); + + if (r && crc == r->crc) { + ssdY = r->ssdY; +@@ -184,60 +176,60 @@ + ssdV = r->ssdV; + ssdA = r->ssdA; + } else { +- for (i=0; i<4; i++) { ++ for (i = 0; i < 4; i++) { ++ refStride[i] = FFALIGN(refStride[i], 16); + if (refStride[i]) +- out[i]= av_mallocz(refStride[i]*h); ++ out[i] = av_mallocz(refStride[i] * h); + if (refStride[i] && !out[i]) { + perror("Malloc"); + res = -1; +- + goto end; + } + } +- outContext= sws_getContext(dstW, dstH, dstFormat, w, h, PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); ++ outContext = sws_getContext(dstW, dstH, dstFormat, w, h, ++ PIX_FMT_YUVA420P, SWS_BILINEAR, ++ NULL, NULL, NULL); + if (!outContext) { + fprintf(stderr, "Failed to get %s ---> %s\n", + av_pix_fmt_descriptors[dstFormat].name, + av_pix_fmt_descriptors[PIX_FMT_YUVA420P].name); + res = -1; +- + goto end; + } + sws_scale(outContext, dst, dstStride, 0, dstH, out, refStride); + +- ssdY= getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); ++ ssdY = getSSD(ref[0], out[0], refStride[0], refStride[0], w, h); + if (hasChroma(srcFormat) && hasChroma(dstFormat)) { + //FIXME check that output is really gray +- ssdU= getSSD(ref[1], out[1], refStride[1], refStride[1], (w+1)>>1, (h+1)>>1); +- ssdV= getSSD(ref[2], out[2], refStride[2], refStride[2], (w+1)>>1, (h+1)>>1); ++ ssdU = getSSD(ref[1], out[1], refStride[1], refStride[1], ++ (w + 1) >> 1, (h + 1) >> 1); ++ ssdV = getSSD(ref[2], out[2], refStride[2], refStride[2], ++ (w + 1) >> 1, (h + 1) >> 1); + } + if (isALPHA(srcFormat) && isALPHA(dstFormat)) +- ssdA= getSSD(ref[3], out[3], refStride[3], refStride[3], w, h); ++ ssdA = getSSD(ref[3], out[3], refStride[3], refStride[3], w, h); + +- ssdY/= w*h; +- ssdU/= w*h/4; +- ssdV/= w*h/4; +- ssdA/= w*h; ++ ssdY /= w * h; ++ ssdU /= w * h / 4; ++ ssdV /= w * h / 4; ++ ssdA /= w * h; + + sws_freeContext(outContext); + +- for (i=0; i<4; i++) { ++ for (i = 0; i < 4; i++) + if (refStride[i]) + av_free(out[i]); +- } + } + +- printf(" CRC=%08x SSD=%5"PRId64",%5"PRId64",%5"PRId64",%5"PRId64"\n", ++ printf(" CRC=%08x SSD=%5"PRId64 ",%5"PRId64 ",%5"PRId64 ",%5"PRId64 "\n", + crc, ssdY, ssdU, ssdV, ssdA); + + end: +- + sws_freeContext(dstContext); + +- for (i=0; i<4; i++) { ++ for (i = 0; i < 4; i++) + if (dstStride[i]) + av_free(dst[i]); +- } + + return res; + } +@@ -246,18 +238,18 @@ + enum PixelFormat srcFormat_in, + enum PixelFormat dstFormat_in) + { +- const int flags[] = { SWS_FAST_BILINEAR, +- SWS_BILINEAR, SWS_BICUBIC, +- SWS_X , SWS_POINT , SWS_AREA, 0 }; +- const int srcW = w; +- const int srcH = h; +- const int dstW[] = { srcW - srcW/3, srcW, srcW + srcW/3, 0 }; +- const int dstH[] = { srcH - srcH/3, srcH, srcH + srcH/3, 0 }; ++ const int flags[] = { SWS_FAST_BILINEAR, SWS_BILINEAR, SWS_BICUBIC, ++ SWS_X, SWS_POINT, SWS_AREA, 0 }; ++ const int srcW = w; ++ const int srcH = h; ++ const int dstW[] = { srcW - srcW / 3, srcW, srcW + srcW / 3, 0 }; ++ const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 }; + enum PixelFormat srcFormat, dstFormat; + + for (srcFormat = srcFormat_in != PIX_FMT_NONE ? srcFormat_in : 0; + srcFormat < PIX_FMT_NB; srcFormat++) { +- if (!sws_isSupportedInput(srcFormat) || !sws_isSupportedOutput(srcFormat)) ++ if (!sws_isSupportedInput(srcFormat) || ++ !sws_isSupportedOutput(srcFormat)) + continue; + + for (dstFormat = dstFormat_in != PIX_FMT_NONE ? dstFormat_in : 0; +@@ -265,7 +257,8 @@ + int i, j, k; + int res = 0; + +- if (!sws_isSupportedInput(dstFormat) || !sws_isSupportedOutput(dstFormat)) ++ if (!sws_isSupportedInput(dstFormat) || ++ !sws_isSupportedOutput(dstFormat)) + continue; + + printf("%s -> %s\n", +@@ -273,14 +266,13 @@ + av_pix_fmt_descriptors[dstFormat].name); + fflush(stdout); + +- for (k = 0; flags[k] && !res; k++) { ++ for (k = 0; flags[k] && !res; k++) + for (i = 0; dstW[i] && !res; i++) + for (j = 0; dstH[j] && !res; j++) + res = doTest(ref, refStride, w, h, + srcFormat, dstFormat, + srcW, srcH, dstW[i], dstH[j], flags[k], + NULL); +- } + if (dstFormat_in != PIX_FMT_NONE) + break; + } +@@ -306,13 +298,14 @@ + int flags; + int ret; + +- ret = sscanf(buf, " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x" +- " SSD=%"PRId64", %"PRId64", %"PRId64", %"PRId64"\n", +- srcStr, &srcW, &srcH, dstStr, &dstW, &dstH, +- &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA); ++ ret = sscanf(buf, ++ " %12s %dx%d -> %12s %dx%d flags=%d CRC=%x" ++ " SSD=%"PRId64 ", %"PRId64 ", %"PRId64 ", %"PRId64 "\n", ++ srcStr, &srcW, &srcH, dstStr, &dstW, &dstH, ++ &flags, &r.crc, &r.ssdY, &r.ssdU, &r.ssdV, &r.ssdA); + if (ret != 12) { + srcStr[0] = dstStr[0] = 0; +- ret = sscanf(buf, "%12s -> %12s\n", srcStr, dstStr); ++ ret = sscanf(buf, "%12s -> %12s\n", srcStr, dstStr); + } + + srcFormat = av_get_pix_fmt(srcStr); +@@ -346,12 +339,12 @@ + { + enum PixelFormat srcFormat = PIX_FMT_NONE; + enum PixelFormat dstFormat = PIX_FMT_NONE; +- uint8_t *rgb_data = av_malloc (W*H*4); +- uint8_t *rgb_src[3]= {rgb_data, NULL, NULL}; +- int rgb_stride[3]={4*W, 0, 0}; +- uint8_t *data = av_malloc (4*W*H); +- uint8_t *src[4]= {data, data+W*H, data+W*H*2, data+W*H*3}; +- int stride[4]={W, W, W, W}; ++ uint8_t *rgb_data = av_malloc(W * H * 4); ++ uint8_t *rgb_src[4] = { rgb_data, NULL, NULL, NULL }; ++ int rgb_stride[4] = { 4 * W, 0, 0, 0 }; ++ uint8_t *data = av_malloc(4 * W * H); ++ uint8_t *src[4] = { data, data + W * H, data + W * H * 2, data + W * H * 3 }; ++ int stride[4] = { W, W, W, W }; + int x, y; + struct SwsContext *sws; + AVLFG rand; +@@ -361,41 +354,40 @@ + if (!rgb_data || !data) + return -1; + +- sws= sws_getContext(W/12, H/12, PIX_FMT_RGB32, W, H, PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); ++ sws = sws_getContext(W / 12, H / 12, PIX_FMT_RGB32, W, H, ++ PIX_FMT_YUVA420P, SWS_BILINEAR, NULL, NULL, NULL); + + av_lfg_init(&rand, 1); + +- for (y=0; y ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include "config.h" ++#include ++#include "swscale.h" ++#include "swscale_internal.h" ++#include "rgb2rgb.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/cpu.h" ++#include "libavutil/avutil.h" ++#include "libavutil/mathematics.h" ++#include "libavutil/bswap.h" ++#include "libavutil/pixdesc.h" ++ ++#define RGB2YUV_SHIFT 15 ++#define BY ( (int) (0.114 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define BV (-(int) (0.081 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define BU ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define GY ( (int) (0.587 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define GV (-(int) (0.419 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define GU (-(int) (0.331 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define RY ( (int) (0.299 * 219 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define RV ( (int) (0.500 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++#define RU (-(int) (0.169 * 224 / 255 * (1 << RGB2YUV_SHIFT) + 0.5)) ++ ++static void fillPlane(uint8_t *plane, int stride, int width, int height, int y, ++ uint8_t val) ++{ ++ int i; ++ uint8_t *ptr = plane + stride * y; ++ for (i = 0; i < height; i++) { ++ memset(ptr, val, width); ++ ptr += stride; ++ } ++} ++ ++static void fillPlane16(uint8_t *plane, int stride, int width, int height, int y, ++ int alpha, int bits) ++{ ++ int i, j; ++ uint8_t *ptr = plane + stride * y; ++ int v = alpha ? -1 : (1< 0) { ++ memcpy(dst, src, srcSliceH * dstStride); ++ } else { ++ int i; ++ for (i = 0; i < srcSliceH; i++) { ++ memcpy(dst, src, width); ++ src += srcStride; ++ dst += dstStride; ++ } ++ } ++} ++ ++static int planarToNv12Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t *dstParam[], ++ int dstStride[]) ++{ ++ uint8_t *dst = dstParam[1] + dstStride[1] * srcSliceY / 2; ++ ++ copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, ++ dstParam[0], dstStride[0]); ++ ++ if (c->dstFormat == PIX_FMT_NV12) ++ interleaveBytes(src[1], src[2], dst, c->srcW / 2, srcSliceH / 2, ++ srcStride[1], srcStride[2], dstStride[0]); ++ else ++ interleaveBytes(src[2], src[1], dst, c->srcW / 2, srcSliceH / 2, ++ srcStride[2], srcStride[1], dstStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int planarToYuy2Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; ++ ++ yv12toyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], ++ srcStride[1], dstStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int planarToUyvyWrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; ++ ++ yv12touyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], ++ srcStride[1], dstStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int yuv422pToYuy2Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; ++ ++ yuv422ptoyuy2(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], ++ srcStride[1], dstStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int yuv422pToUyvyWrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *dst = dstParam[0] + dstStride[0] * srcSliceY; ++ ++ yuv422ptouyvy(src[0], src[1], src[2], dst, c->srcW, srcSliceH, srcStride[0], ++ srcStride[1], dstStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int yuyvToYuv420Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY; ++ uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2; ++ uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2; ++ ++ yuyvtoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], ++ dstStride[1], srcStride[0]); ++ ++ if (dstParam[3]) ++ fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++ ++ return srcSliceH; ++} ++ ++static int yuyvToYuv422Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY; ++ uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY; ++ uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY; ++ ++ yuyvtoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], ++ dstStride[1], srcStride[0]); ++ ++ return srcSliceH; ++} ++ ++static int uyvyToYuv420Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY; ++ uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY / 2; ++ uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY / 2; ++ ++ uyvytoyuv420(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], ++ dstStride[1], srcStride[0]); ++ ++ if (dstParam[3]) ++ fillPlane(dstParam[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++ ++ return srcSliceH; ++} ++ ++static int uyvyToYuv422Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dstParam[], int dstStride[]) ++{ ++ uint8_t *ydst = dstParam[0] + dstStride[0] * srcSliceY; ++ uint8_t *udst = dstParam[1] + dstStride[1] * srcSliceY; ++ uint8_t *vdst = dstParam[2] + dstStride[2] * srcSliceY; ++ ++ uyvytoyuv422(ydst, udst, vdst, src[0], c->srcW, srcSliceH, dstStride[0], ++ dstStride[1], srcStride[0]); ++ ++ return srcSliceH; ++} ++ ++static void gray8aToPacked32(const uint8_t *src, uint8_t *dst, int num_pixels, ++ const uint8_t *palette) ++{ ++ int i; ++ for (i = 0; i < num_pixels; i++) ++ ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | (src[(i << 1) + 1] << 24); ++} ++ ++static void gray8aToPacked32_1(const uint8_t *src, uint8_t *dst, int num_pixels, ++ const uint8_t *palette) ++{ ++ int i; ++ ++ for (i = 0; i < num_pixels; i++) ++ ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i << 1]] | src[(i << 1) + 1]; ++} ++ ++static void gray8aToPacked24(const uint8_t *src, uint8_t *dst, int num_pixels, ++ const uint8_t *palette) ++{ ++ int i; ++ ++ for (i = 0; i < num_pixels; i++) { ++ //FIXME slow? ++ dst[0] = palette[src[i << 1] * 4 + 0]; ++ dst[1] = palette[src[i << 1] * 4 + 1]; ++ dst[2] = palette[src[i << 1] * 4 + 2]; ++ dst += 3; ++ } ++} ++ ++static int packed_16bpc_bswap(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dst[], int dstStride[]) ++{ ++ int i, j; ++ int srcstr = srcStride[0] >> 1; ++ int dststr = dstStride[0] >> 1; ++ uint16_t *dstPtr = (uint16_t *) dst[0]; ++ const uint16_t *srcPtr = (const uint16_t *) src[0]; ++ int min_stride = FFMIN(srcstr, dststr); ++ ++ for (i = 0; i < srcSliceH; i++) { ++ for (j = 0; j < min_stride; j++) { ++ dstPtr[j] = av_bswap16(srcPtr[j]); ++ } ++ srcPtr += srcstr; ++ dstPtr += dststr; ++ } ++ ++ return srcSliceH; ++} ++ ++static int palToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], ++ int srcSliceY, int srcSliceH, uint8_t *dst[], ++ int dstStride[]) ++{ ++ const enum PixelFormat srcFormat = c->srcFormat; ++ const enum PixelFormat dstFormat = c->dstFormat; ++ void (*conv)(const uint8_t *src, uint8_t *dst, int num_pixels, ++ const uint8_t *palette) = NULL; ++ int i; ++ uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY; ++ const uint8_t *srcPtr = src[0]; ++ ++ if (srcFormat == PIX_FMT_GRAY8A) { ++ switch (dstFormat) { ++ case PIX_FMT_RGB32 : conv = gray8aToPacked32; break; ++ case PIX_FMT_BGR32 : conv = gray8aToPacked32; break; ++ case PIX_FMT_BGR32_1: conv = gray8aToPacked32_1; break; ++ case PIX_FMT_RGB32_1: conv = gray8aToPacked32_1; break; ++ case PIX_FMT_RGB24 : conv = gray8aToPacked24; break; ++ case PIX_FMT_BGR24 : conv = gray8aToPacked24; break; ++ } ++ } else if (usePal(srcFormat)) { ++ switch (dstFormat) { ++ case PIX_FMT_RGB32 : conv = sws_convertPalette8ToPacked32; break; ++ case PIX_FMT_BGR32 : conv = sws_convertPalette8ToPacked32; break; ++ case PIX_FMT_BGR32_1: conv = sws_convertPalette8ToPacked32; break; ++ case PIX_FMT_RGB32_1: conv = sws_convertPalette8ToPacked32; break; ++ case PIX_FMT_RGB24 : conv = sws_convertPalette8ToPacked24; break; ++ case PIX_FMT_BGR24 : conv = sws_convertPalette8ToPacked24; break; ++ } ++ } ++ ++ if (!conv) ++ av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", ++ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); ++ else { ++ for (i = 0; i < srcSliceH; i++) { ++ conv(srcPtr, dstPtr, c->srcW, (uint8_t *) c->pal_rgb); ++ srcPtr += srcStride[0]; ++ dstPtr += dstStride[0]; ++ } ++ } ++ ++ return srcSliceH; ++} ++ ++static void gbr24ptopacked24(const uint8_t* src[], int srcStride[], uint8_t* dst, int dstStride, int srcSliceH, int width) ++{ ++ int x, h, i; ++ for (h = 0; h < srcSliceH; h++) { ++ uint8_t *dest = dst + dstStride * h; ++ for (x = 0; x < width; x++) { ++ *dest++ = src[0][x]; ++ *dest++ = src[1][x]; ++ *dest++ = src[2][x]; ++ } ++ ++ for (i = 0; i < 3; i++) ++ src[i] += srcStride[i]; ++ } ++} ++ ++static void gbr24ptopacked32(const uint8_t* src[], int srcStride[], uint8_t* dst, int dstStride, int srcSliceH, int alpha_first, int width) ++{ ++ int x, h, i; ++ for (h = 0; h < srcSliceH; h++) { ++ uint8_t *dest = dst + dstStride * h; ++ ++ if (alpha_first) { ++ for (x = 0; x < width; x++) { ++ *dest++ = 0xff; ++ *dest++ = src[0][x]; ++ *dest++ = src[1][x]; ++ *dest++ = src[2][x]; ++ } ++ } else { ++ for (x = 0; x < width; x++) { ++ *dest++ = src[0][x]; ++ *dest++ = src[1][x]; ++ *dest++ = src[2][x]; ++ *dest++ = 0xff; ++ } ++ } ++ ++ for (i = 0; i < 3; i++) ++ src[i] += srcStride[i]; ++ } ++} ++ ++static int planarRgbToRgbWrapper(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t* dst[], int dstStride[]) ++{ ++ int alpha_first = 0; ++ if (c->srcFormat != PIX_FMT_GBR24P) { ++ av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", ++ av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat)); ++ return srcSliceH; ++ } ++ ++ switch (c->dstFormat) { ++ case PIX_FMT_BGR24: ++ gbr24ptopacked24((const uint8_t* []) {src[1], src[0], src[2]}, (int []) {srcStride[1], srcStride[0], srcStride[2]}, ++ dst[0] + srcSliceY * dstStride[0], dstStride[0], srcSliceH, c->srcW); ++ break; ++ ++ case PIX_FMT_RGB24: ++ gbr24ptopacked24((const uint8_t* []) {src[2], src[0], src[1]}, (int []) {srcStride[2], srcStride[0], srcStride[1]}, ++ dst[0] + srcSliceY * dstStride[0], dstStride[0], srcSliceH, c->srcW); ++ break; ++ ++ case PIX_FMT_ARGB: ++ alpha_first = 1; ++ case PIX_FMT_RGBA: ++ gbr24ptopacked32((const uint8_t* []) {src[2], src[0], src[1]}, (int []) {srcStride[2], srcStride[0], srcStride[1]}, ++ dst[0] + srcSliceY * dstStride[0], dstStride[0], srcSliceH, alpha_first, c->srcW); ++ break; ++ ++ case PIX_FMT_ABGR: ++ alpha_first = 1; ++ case PIX_FMT_BGRA: ++ gbr24ptopacked32((const uint8_t* []) {src[1], src[0], src[2]}, (int []) {srcStride[1], srcStride[0], srcStride[2]}, ++ dst[0] + srcSliceY * dstStride[0], dstStride[0], srcSliceH, alpha_first, c->srcW); ++ break; ++ ++ default: ++ av_log(c, AV_LOG_ERROR, "unsupported planar RGB conversion %s -> %s\n", ++ av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat)); ++ } ++ ++ return srcSliceH; ++} ++ ++#define isRGBA32(x) ( \ ++ (x) == PIX_FMT_ARGB \ ++ || (x) == PIX_FMT_RGBA \ ++ || (x) == PIX_FMT_BGRA \ ++ || (x) == PIX_FMT_ABGR \ ++ ) ++ ++/* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ ++typedef void (* rgbConvFn) (const uint8_t *, uint8_t *, int); ++static rgbConvFn findRgbConvFn(SwsContext *c) ++{ ++ const enum PixelFormat srcFormat = c->srcFormat; ++ const enum PixelFormat dstFormat = c->dstFormat; ++ const int srcId = c->srcFormatBpp; ++ const int dstId = c->dstFormatBpp; ++ rgbConvFn conv = NULL; ++ ++#define IS_NOT_NE(bpp, fmt) \ ++ (((bpp + 7) >> 3) == 2 && \ ++ (!(av_pix_fmt_descriptors[fmt].flags & PIX_FMT_BE) != !HAVE_BIGENDIAN)) ++ ++ /* if this is non-native rgb444/555/565, don't handle it here. */ ++ if (IS_NOT_NE(srcId, srcFormat) || IS_NOT_NE(dstId, dstFormat)) ++ return NULL; ++ ++#define CONV_IS(src, dst) (srcFormat == PIX_FMT_##src && dstFormat == PIX_FMT_##dst) ++ ++ if (isRGBA32(srcFormat) && isRGBA32(dstFormat)) { ++ if ( CONV_IS(ABGR, RGBA) ++ || CONV_IS(ARGB, BGRA) ++ || CONV_IS(BGRA, ARGB) ++ || CONV_IS(RGBA, ABGR)) conv = shuffle_bytes_3210; ++ else if (CONV_IS(ABGR, ARGB) ++ || CONV_IS(ARGB, ABGR)) conv = shuffle_bytes_0321; ++ else if (CONV_IS(ABGR, BGRA) ++ || CONV_IS(ARGB, RGBA)) conv = shuffle_bytes_1230; ++ else if (CONV_IS(BGRA, RGBA) ++ || CONV_IS(RGBA, BGRA)) conv = shuffle_bytes_2103; ++ else if (CONV_IS(BGRA, ABGR) ++ || CONV_IS(RGBA, ARGB)) conv = shuffle_bytes_3012; ++ } else ++ /* BGR -> BGR */ ++ if ((isBGRinInt(srcFormat) && isBGRinInt(dstFormat)) || ++ (isRGBinInt(srcFormat) && isRGBinInt(dstFormat))) { ++ switch (srcId | (dstId << 16)) { ++ case 0x000F000C: conv = rgb12to15; break; ++ case 0x000F0010: conv = rgb16to15; break; ++ case 0x000F0018: conv = rgb24to15; break; ++ case 0x000F0020: conv = rgb32to15; break; ++ case 0x0010000F: conv = rgb15to16; break; ++ case 0x00100018: conv = rgb24to16; break; ++ case 0x00100020: conv = rgb32to16; break; ++ case 0x0018000F: conv = rgb15to24; break; ++ case 0x00180010: conv = rgb16to24; break; ++ case 0x00180020: conv = rgb32to24; break; ++ case 0x0020000F: conv = rgb15to32; break; ++ case 0x00200010: conv = rgb16to32; break; ++ case 0x00200018: conv = rgb24to32; break; ++ } ++ } else if ((isBGRinInt(srcFormat) && isRGBinInt(dstFormat)) || ++ (isRGBinInt(srcFormat) && isBGRinInt(dstFormat))) { ++ switch (srcId | (dstId << 16)) { ++ case 0x000C000C: conv = rgb12tobgr12; break; ++ case 0x000F000F: conv = rgb15tobgr15; break; ++ case 0x000F0010: conv = rgb16tobgr15; break; ++ case 0x000F0018: conv = rgb24tobgr15; break; ++ case 0x000F0020: conv = rgb32tobgr15; break; ++ case 0x0010000F: conv = rgb15tobgr16; break; ++ case 0x00100010: conv = rgb16tobgr16; break; ++ case 0x00100018: conv = rgb24tobgr16; break; ++ case 0x00100020: conv = rgb32tobgr16; break; ++ case 0x0018000F: conv = rgb15tobgr24; break; ++ case 0x00180010: conv = rgb16tobgr24; break; ++ case 0x00180018: conv = rgb24tobgr24; break; ++ case 0x00180020: conv = rgb32tobgr24; break; ++ case 0x0020000F: conv = rgb15tobgr32; break; ++ case 0x00200010: conv = rgb16tobgr32; break; ++ case 0x00200018: conv = rgb24tobgr32; break; ++ } ++ } ++ ++ return conv; ++} ++ ++/* {RGB,BGR}{15,16,24,32,32_1} -> {RGB,BGR}{15,16,24,32} */ ++static int rgbToRgbWrapper(SwsContext *c, const uint8_t *src[], int srcStride[], ++ int srcSliceY, int srcSliceH, uint8_t *dst[], ++ int dstStride[]) ++ ++{ ++ const enum PixelFormat srcFormat = c->srcFormat; ++ const enum PixelFormat dstFormat = c->dstFormat; ++ const int srcBpp = (c->srcFormatBpp + 7) >> 3; ++ const int dstBpp = (c->dstFormatBpp + 7) >> 3; ++ rgbConvFn conv = findRgbConvFn(c); ++ ++ if (!conv) { ++ av_log(c, AV_LOG_ERROR, "internal error %s -> %s converter\n", ++ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); ++ } else { ++ const uint8_t *srcPtr = src[0]; ++ uint8_t *dstPtr = dst[0]; ++ if ((srcFormat == PIX_FMT_RGB32_1 || srcFormat == PIX_FMT_BGR32_1) && ++ !isRGBA32(dstFormat)) ++ srcPtr += ALT32_CORR; ++ ++ if ((dstFormat == PIX_FMT_RGB32_1 || dstFormat == PIX_FMT_BGR32_1) && ++ !isRGBA32(srcFormat)) ++ dstPtr += ALT32_CORR; ++ ++ if (dstStride[0] * srcBpp == srcStride[0] * dstBpp && srcStride[0] > 0 && ++ !(srcStride[0] % srcBpp)) ++ conv(srcPtr, dstPtr + dstStride[0] * srcSliceY, ++ srcSliceH * srcStride[0]); ++ else { ++ int i; ++ dstPtr += dstStride[0] * srcSliceY; ++ ++ for (i = 0; i < srcSliceH; i++) { ++ conv(srcPtr, dstPtr, c->srcW * srcBpp); ++ srcPtr += srcStride[0]; ++ dstPtr += dstStride[0]; ++ } ++ } ++ } ++ return srcSliceH; ++} ++ ++static int bgr24ToYv12Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dst[], int dstStride[]) ++{ ++ rgb24toyv12( ++ src[0], ++ dst[0] + srcSliceY * dstStride[0], ++ dst[1] + (srcSliceY >> 1) * dstStride[1], ++ dst[2] + (srcSliceY >> 1) * dstStride[2], ++ c->srcW, srcSliceH, ++ dstStride[0], dstStride[1], srcStride[0]); ++ if (dst[3]) ++ fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++ return srcSliceH; ++} ++ ++static int yvu9ToYv12Wrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dst[], int dstStride[]) ++{ ++ copyPlane(src[0], srcStride[0], srcSliceY, srcSliceH, c->srcW, ++ dst[0], dstStride[0]); ++ ++ planar2x(src[1], dst[1] + dstStride[1] * (srcSliceY >> 1), c->chrSrcW, ++ srcSliceH >> 2, srcStride[1], dstStride[1]); ++ planar2x(src[2], dst[2] + dstStride[2] * (srcSliceY >> 1), c->chrSrcW, ++ srcSliceH >> 2, srcStride[2], dstStride[2]); ++ if (dst[3]) ++ fillPlane(dst[3], dstStride[3], c->srcW, srcSliceH, srcSliceY, 255); ++ return srcSliceH; ++} ++ ++/* unscaled copy like stuff (assumes nearly identical formats) */ ++static int packedCopyWrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dst[], int dstStride[]) ++{ ++ if (dstStride[0] == srcStride[0] && srcStride[0] > 0) ++ memcpy(dst[0] + dstStride[0] * srcSliceY, src[0], srcSliceH * dstStride[0]); ++ else { ++ int i; ++ const uint8_t *srcPtr = src[0]; ++ uint8_t *dstPtr = dst[0] + dstStride[0] * srcSliceY; ++ int length = 0; ++ ++ /* universal length finder */ ++ while (length + c->srcW <= FFABS(dstStride[0]) && ++ length + c->srcW <= FFABS(srcStride[0])) ++ length += c->srcW; ++ assert(length != 0); ++ ++ for (i = 0; i < srcSliceH; i++) { ++ memcpy(dstPtr, srcPtr, length); ++ srcPtr += srcStride[0]; ++ dstPtr += dstStride[0]; ++ } ++ } ++ return srcSliceH; ++} ++ ++#define DITHER_COPY(dst, dstStride, src, srcStride, bswap, dbswap)\ ++ uint16_t scale= dither_scale[dst_depth-1][src_depth-1];\ ++ int shift= src_depth-dst_depth + dither_scale[src_depth-2][dst_depth-1];\ ++ for (i = 0; i < height; i++) {\ ++ const uint8_t *dither= dithers[src_depth-9][i&7];\ ++ for (j = 0; j < length-7; j+=8){\ ++ dst[j+0] = dbswap((bswap(src[j+0]) + dither[0])*scale>>shift);\ ++ dst[j+1] = dbswap((bswap(src[j+1]) + dither[1])*scale>>shift);\ ++ dst[j+2] = dbswap((bswap(src[j+2]) + dither[2])*scale>>shift);\ ++ dst[j+3] = dbswap((bswap(src[j+3]) + dither[3])*scale>>shift);\ ++ dst[j+4] = dbswap((bswap(src[j+4]) + dither[4])*scale>>shift);\ ++ dst[j+5] = dbswap((bswap(src[j+5]) + dither[5])*scale>>shift);\ ++ dst[j+6] = dbswap((bswap(src[j+6]) + dither[6])*scale>>shift);\ ++ dst[j+7] = dbswap((bswap(src[j+7]) + dither[7])*scale>>shift);\ ++ }\ ++ for (; j < length; j++)\ ++ dst[j] = dbswap((bswap(src[j]) + dither[j&7])*scale>>shift);\ ++ dst += dstStride;\ ++ src += srcStride;\ ++ } ++ ++static int planarCopyWrapper(SwsContext *c, const uint8_t *src[], ++ int srcStride[], int srcSliceY, int srcSliceH, ++ uint8_t *dst[], int dstStride[]) ++{ ++ int plane, i, j; ++ for (plane = 0; plane < 4; plane++) { ++ int length = (plane == 0 || plane == 3) ? c->srcW : -((-c->srcW ) >> c->chrDstHSubSample); ++ int y = (plane == 0 || plane == 3) ? srcSliceY: -((-srcSliceY) >> c->chrDstVSubSample); ++ int height = (plane == 0 || plane == 3) ? srcSliceH: -((-srcSliceH) >> c->chrDstVSubSample); ++ const uint8_t *srcPtr = src[plane]; ++ uint8_t *dstPtr = dst[plane] + dstStride[plane] * y; ++ int shiftonly= plane==1 || plane==2 || (!c->srcRange && plane==0); ++ ++ if (!dst[plane]) ++ continue; ++ // ignore palette for GRAY8 ++ if (plane == 1 && !dst[2]) continue; ++ if (!src[plane] || (plane == 1 && !src[2])) { ++ if (is16BPS(c->dstFormat) || isNBPS(c->dstFormat)) { ++ fillPlane16(dst[plane], dstStride[plane], length, height, y, ++ plane == 3, av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1); ++ } else { ++ fillPlane(dst[plane], dstStride[plane], length, height, y, ++ (plane == 3) ? 255 : 128); ++ } ++ } else { ++ if(isNBPS(c->srcFormat) || isNBPS(c->dstFormat) ++ || (is16BPS(c->srcFormat) != is16BPS(c->dstFormat)) ++ ) { ++ const int src_depth = av_pix_fmt_descriptors[c->srcFormat].comp[plane].depth_minus1 + 1; ++ const int dst_depth = av_pix_fmt_descriptors[c->dstFormat].comp[plane].depth_minus1 + 1; ++ const uint16_t *srcPtr2 = (const uint16_t *) srcPtr; ++ uint16_t *dstPtr2 = (uint16_t*)dstPtr; ++ ++ if (dst_depth == 8) { ++ if(isBE(c->srcFormat) == HAVE_BIGENDIAN){ ++ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, , ) ++ } else { ++ DITHER_COPY(dstPtr, dstStride[plane], srcPtr2, srcStride[plane]/2, av_bswap16, ) ++ } ++ } else if (src_depth == 8) { ++ for (i = 0; i < height; i++) { ++ #define COPY816(w)\ ++ if(shiftonly){\ ++ for (j = 0; j < length; j++)\ ++ w(&dstPtr2[j], srcPtr[j]<<(dst_depth-8));\ ++ }else{\ ++ for (j = 0; j < length; j++)\ ++ w(&dstPtr2[j], (srcPtr[j]<<(dst_depth-8)) |\ ++ (srcPtr[j]>>(2*8-dst_depth)));\ ++ } ++ if(isBE(c->dstFormat)){ ++ COPY816(AV_WB16) ++ } else { ++ COPY816(AV_WL16) ++ } ++ dstPtr2 += dstStride[plane]/2; ++ srcPtr += srcStride[plane]; ++ } ++ } else if (src_depth <= dst_depth) { ++ for (i = 0; i < height; i++) { ++#define COPY_UP(r,w) \ ++ if(shiftonly){\ ++ for (j = 0; j < length; j++){ \ ++ unsigned int v= r(&srcPtr2[j]);\ ++ w(&dstPtr2[j], v<<(dst_depth-src_depth));\ ++ }\ ++ }else{\ ++ for (j = 0; j < length; j++){ \ ++ unsigned int v= r(&srcPtr2[j]);\ ++ w(&dstPtr2[j], (v<<(dst_depth-src_depth)) | \ ++ (v>>(2*src_depth-dst_depth)));\ ++ }\ ++ } ++ if(isBE(c->srcFormat)){ ++ if(isBE(c->dstFormat)){ ++ COPY_UP(AV_RB16, AV_WB16) ++ } else { ++ COPY_UP(AV_RB16, AV_WL16) ++ } ++ } else { ++ if(isBE(c->dstFormat)){ ++ COPY_UP(AV_RL16, AV_WB16) ++ } else { ++ COPY_UP(AV_RL16, AV_WL16) ++ } ++ } ++ dstPtr2 += dstStride[plane]/2; ++ srcPtr2 += srcStride[plane]/2; ++ } ++ } else { ++ if(isBE(c->srcFormat) == HAVE_BIGENDIAN){ ++ if(isBE(c->dstFormat) == HAVE_BIGENDIAN){ ++ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , ) ++ } else { ++ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, , av_bswap16) ++ } ++ }else{ ++ if(isBE(c->dstFormat) == HAVE_BIGENDIAN){ ++ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, ) ++ } else { ++ DITHER_COPY(dstPtr2, dstStride[plane]/2, srcPtr2, srcStride[plane]/2, av_bswap16, av_bswap16) ++ } ++ } ++ } ++ } else if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat) && ++ isBE(c->srcFormat) != isBE(c->dstFormat)) { ++ ++ for (i = 0; i < height; i++) { ++ for (j = 0; j < length; j++) ++ ((uint16_t *) dstPtr)[j] = av_bswap16(((const uint16_t *) srcPtr)[j]); ++ srcPtr += srcStride[plane]; ++ dstPtr += dstStride[plane]; ++ } ++ } else if (dstStride[plane] == srcStride[plane] && ++ srcStride[plane] > 0 && srcStride[plane] == length) { ++ memcpy(dst[plane] + dstStride[plane] * y, src[plane], ++ height * dstStride[plane]); ++ } else { ++ if (is16BPS(c->srcFormat) && is16BPS(c->dstFormat)) ++ length *= 2; ++ else if (!av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1) ++ length >>= 3; // monowhite/black ++ for (i = 0; i < height; i++) { ++ memcpy(dstPtr, srcPtr, length); ++ srcPtr += srcStride[plane]; ++ dstPtr += dstStride[plane]; ++ } ++ } ++ } ++ } ++ return srcSliceH; ++} ++ ++ ++#define IS_DIFFERENT_ENDIANESS(src_fmt, dst_fmt, pix_fmt) \ ++ ((src_fmt == pix_fmt ## BE && dst_fmt == pix_fmt ## LE) || \ ++ (src_fmt == pix_fmt ## LE && dst_fmt == pix_fmt ## BE)) ++ ++ ++void ff_get_unscaled_swscale(SwsContext *c) ++{ ++ const enum PixelFormat srcFormat = c->srcFormat; ++ const enum PixelFormat dstFormat = c->dstFormat; ++ const int flags = c->flags; ++ const int dstH = c->dstH; ++ int needsDither; ++ ++ needsDither = isAnyRGB(dstFormat) && ++ c->dstFormatBpp < 24 && ++ (c->dstFormatBpp < c->srcFormatBpp || (!isAnyRGB(srcFormat))); ++ ++ /* yv12_to_nv12 */ ++ if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) && ++ (dstFormat == PIX_FMT_NV12 || dstFormat == PIX_FMT_NV21)) { ++ c->swScale = planarToNv12Wrapper; ++ } ++ /* yuv2bgr */ ++ if ((srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUV422P || ++ srcFormat == PIX_FMT_YUVA420P) && isAnyRGB(dstFormat) && ++ !(flags & SWS_ACCURATE_RND) && !(dstH & 1)) { ++ c->swScale = ff_yuv2rgb_get_func_ptr(c); ++ } ++ ++ if (srcFormat == PIX_FMT_YUV410P && ++ (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P) && ++ !(flags & SWS_BITEXACT)) { ++ c->swScale = yvu9ToYv12Wrapper; ++ } ++ ++ /* bgr24toYV12 */ ++ if (srcFormat == PIX_FMT_BGR24 && ++ (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P) && ++ !(flags & SWS_ACCURATE_RND)) ++ c->swScale = bgr24ToYv12Wrapper; ++ ++ /* RGB/BGR -> RGB/BGR (no dither needed forms) */ ++ if (isAnyRGB(srcFormat) && isAnyRGB(dstFormat) && findRgbConvFn(c) ++ && (!needsDither || (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)))) ++ c->swScale= rgbToRgbWrapper; ++ ++#define isByteRGB(f) (\ ++ f == PIX_FMT_RGB32 ||\ ++ f == PIX_FMT_RGB32_1 ||\ ++ f == PIX_FMT_RGB24 ||\ ++ f == PIX_FMT_BGR32 ||\ ++ f == PIX_FMT_BGR32_1 ||\ ++ f == PIX_FMT_BGR24) ++ ++ if (isAnyRGB(srcFormat) && isPlanar(srcFormat) && isByteRGB(dstFormat)) ++ c->swScale= planarRgbToRgbWrapper; ++ ++ /* bswap 16 bits per pixel/component packed formats */ ++ if (IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_BGR444) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_BGR48) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_BGR555) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_BGR565) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_GRAY16) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_RGB444) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_RGB48) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_RGB555) || ++ IS_DIFFERENT_ENDIANESS(srcFormat, dstFormat, PIX_FMT_RGB565)) ++ c->swScale = packed_16bpc_bswap; ++ ++ if (usePal(srcFormat) && isByteRGB(dstFormat)) ++ c->swScale = palToRgbWrapper; ++ ++ if (srcFormat == PIX_FMT_YUV422P) { ++ if (dstFormat == PIX_FMT_YUYV422) ++ c->swScale = yuv422pToYuy2Wrapper; ++ else if (dstFormat == PIX_FMT_UYVY422) ++ c->swScale = yuv422pToUyvyWrapper; ++ } ++ ++ /* LQ converters if -sws 0 or -sws 4*/ ++ if (c->flags&(SWS_FAST_BILINEAR|SWS_POINT)) { ++ /* yv12_to_yuy2 */ ++ if (srcFormat == PIX_FMT_YUV420P || srcFormat == PIX_FMT_YUVA420P) { ++ if (dstFormat == PIX_FMT_YUYV422) ++ c->swScale = planarToYuy2Wrapper; ++ else if (dstFormat == PIX_FMT_UYVY422) ++ c->swScale = planarToUyvyWrapper; ++ } ++ } ++ if (srcFormat == PIX_FMT_YUYV422 && ++ (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) ++ c->swScale = yuyvToYuv420Wrapper; ++ if (srcFormat == PIX_FMT_UYVY422 && ++ (dstFormat == PIX_FMT_YUV420P || dstFormat == PIX_FMT_YUVA420P)) ++ c->swScale = uyvyToYuv420Wrapper; ++ if (srcFormat == PIX_FMT_YUYV422 && dstFormat == PIX_FMT_YUV422P) ++ c->swScale = yuyvToYuv422Wrapper; ++ if (srcFormat == PIX_FMT_UYVY422 && dstFormat == PIX_FMT_YUV422P) ++ c->swScale = uyvyToYuv422Wrapper; ++ ++#define isPlanarGray(x) (isGray(x) && (x) != PIX_FMT_GRAY8A) ++ /* simple copy */ ++ if ( srcFormat == dstFormat || ++ (srcFormat == PIX_FMT_YUVA420P && dstFormat == PIX_FMT_YUV420P) || ++ (srcFormat == PIX_FMT_YUV420P && dstFormat == PIX_FMT_YUVA420P) || ++ (isPlanarYUV(srcFormat) && isPlanarGray(dstFormat)) || ++ (isPlanarYUV(dstFormat) && isPlanarGray(srcFormat)) || ++ (isPlanarGray(dstFormat) && isPlanarGray(srcFormat)) || ++ (isPlanarYUV(srcFormat) && isPlanarYUV(dstFormat) && ++ c->chrDstHSubSample == c->chrSrcHSubSample && ++ c->chrDstVSubSample == c->chrSrcVSubSample && ++ dstFormat != PIX_FMT_NV12 && dstFormat != PIX_FMT_NV21 && ++ srcFormat != PIX_FMT_NV12 && srcFormat != PIX_FMT_NV21)) ++ { ++ if (isPacked(c->srcFormat)) ++ c->swScale = packedCopyWrapper; ++ else /* Planar YUV or gray */ ++ c->swScale = planarCopyWrapper; ++ } ++ ++ if (ARCH_BFIN) ++ ff_bfin_get_unscaled_swscale(c); ++ if (HAVE_ALTIVEC) ++ ff_swscale_get_unscaled_altivec(c); ++} ++ ++static void reset_ptr(const uint8_t *src[], int format) ++{ ++ if (!isALPHA(format)) ++ src[3] = NULL; ++ if (!isPlanar(format)) { ++ src[3] = src[2] = NULL; ++ ++ if (!usePal(format)) ++ src[1] = NULL; ++ } ++} ++ ++static int check_image_pointers(const uint8_t * const data[4], enum PixelFormat pix_fmt, ++ const int linesizes[4]) ++{ ++ const AVPixFmtDescriptor *desc = &av_pix_fmt_descriptors[pix_fmt]; ++ int i; ++ ++ for (i = 0; i < 4; i++) { ++ int plane = desc->comp[i].plane; ++ if (!data[plane] || !linesizes[plane]) ++ return 0; ++ } ++ ++ return 1; ++} ++ ++/** ++ * swscale wrapper, so we don't need to export the SwsContext. ++ * Assumes planar YUV to be in YUV order instead of YVU. ++ */ ++int attribute_align_arg sws_scale(struct SwsContext *c, ++ const uint8_t * const srcSlice[], ++ const int srcStride[], int srcSliceY, ++ int srcSliceH, uint8_t *const dst[], ++ const int dstStride[]) ++{ ++ int i, ret; ++ const uint8_t *src2[4] = { srcSlice[0], srcSlice[1], srcSlice[2], srcSlice[3] }; ++ uint8_t *dst2[4] = { dst[0], dst[1], dst[2], dst[3] }; ++ uint8_t *rgb0_tmp = NULL; ++ ++ // do not mess up sliceDir if we have a "trailing" 0-size slice ++ if (srcSliceH == 0) ++ return 0; ++ ++ if (!check_image_pointers(srcSlice, c->srcFormat, srcStride)) { ++ av_log(c, AV_LOG_ERROR, "bad src image pointers\n"); ++ return 0; ++ } ++ if (!check_image_pointers((const uint8_t* const*)dst, c->dstFormat, dstStride)) { ++ av_log(c, AV_LOG_ERROR, "bad dst image pointers\n"); ++ return 0; ++ } ++ ++ if (c->sliceDir == 0 && srcSliceY != 0 && srcSliceY + srcSliceH != c->srcH) { ++ av_log(c, AV_LOG_ERROR, "Slices start in the middle!\n"); ++ return 0; ++ } ++ if (c->sliceDir == 0) { ++ if (srcSliceY == 0) c->sliceDir = 1; else c->sliceDir = -1; ++ } ++ ++ if (usePal(c->srcFormat)) { ++ for (i = 0; i < 256; i++) { ++ int p, r, g, b, y, u, v, a = 0xff; ++ if (c->srcFormat == PIX_FMT_PAL8) { ++ p = ((const uint32_t *)(srcSlice[1]))[i]; ++ a = (p >> 24) & 0xFF; ++ r = (p >> 16) & 0xFF; ++ g = (p >> 8) & 0xFF; ++ b = p & 0xFF; ++ } else if (c->srcFormat == PIX_FMT_RGB8) { ++ r = ( i >> 5 ) * 36; ++ g = ((i >> 2) & 7) * 36; ++ b = ( i & 3) * 85; ++ } else if (c->srcFormat == PIX_FMT_BGR8) { ++ b = ( i >> 6 ) * 85; ++ g = ((i >> 3) & 7) * 36; ++ r = ( i & 7) * 36; ++ } else if (c->srcFormat == PIX_FMT_RGB4_BYTE) { ++ r = ( i >> 3 ) * 255; ++ g = ((i >> 1) & 3) * 85; ++ b = ( i & 1) * 255; ++ } else if (c->srcFormat == PIX_FMT_GRAY8 || c->srcFormat == PIX_FMT_GRAY8A) { ++ r = g = b = i; ++ } else { ++ assert(c->srcFormat == PIX_FMT_BGR4_BYTE); ++ b = ( i >> 3 ) * 255; ++ g = ((i >> 1) & 3) * 85; ++ r = ( i & 1) * 255; ++ } ++ y = av_clip_uint8((RY * r + GY * g + BY * b + ( 33 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); ++ u = av_clip_uint8((RU * r + GU * g + BU * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); ++ v = av_clip_uint8((RV * r + GV * g + BV * b + (257 << (RGB2YUV_SHIFT - 1))) >> RGB2YUV_SHIFT); ++ c->pal_yuv[i]= y + (u<<8) + (v<<16) + (a<<24); ++ ++ switch (c->dstFormat) { ++ case PIX_FMT_BGR32: ++#if !HAVE_BIGENDIAN ++ case PIX_FMT_RGB24: ++#endif ++ c->pal_rgb[i]= r + (g<<8) + (b<<16) + (a<<24); ++ break; ++ case PIX_FMT_BGR32_1: ++#if HAVE_BIGENDIAN ++ case PIX_FMT_BGR24: ++#endif ++ c->pal_rgb[i]= a + (r<<8) + (g<<16) + (b<<24); ++ break; ++ case PIX_FMT_RGB32_1: ++#if HAVE_BIGENDIAN ++ case PIX_FMT_RGB24: ++#endif ++ c->pal_rgb[i]= a + (b<<8) + (g<<16) + (r<<24); ++ break; ++ case PIX_FMT_RGB32: ++#if !HAVE_BIGENDIAN ++ case PIX_FMT_BGR24: ++#endif ++ default: ++ c->pal_rgb[i]= b + (g<<8) + (r<<16) + (a<<24); ++ } ++ } ++ } ++ ++ if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) { ++ uint8_t *base; ++ int x,y; ++ rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32); ++ base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp; ++ for (y=0; ysrcW); ++ for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) { ++ base[ srcStride[0]*y + x] = 0xFF; ++ } ++ } ++ src2[0] = base; ++ } ++ ++ // copy strides, so they can safely be modified ++ if (c->sliceDir == 1) { ++ // slices go from top to bottom ++ int srcStride2[4] = { srcStride[0], srcStride[1], srcStride[2], ++ srcStride[3] }; ++ int dstStride2[4] = { dstStride[0], dstStride[1], dstStride[2], ++ dstStride[3] }; ++ ++ reset_ptr(src2, c->srcFormat); ++ reset_ptr((void*)dst2, c->dstFormat); ++ ++ /* reset slice direction at end of frame */ ++ if (srcSliceY + srcSliceH == c->srcH) ++ c->sliceDir = 0; ++ ++ ret = c->swScale(c, src2, srcStride2, srcSliceY, srcSliceH, dst2, ++ dstStride2); ++ } else { ++ // slices go from bottom to top => we flip the image internally ++ int srcStride2[4] = { -srcStride[0], -srcStride[1], -srcStride[2], ++ -srcStride[3] }; ++ int dstStride2[4] = { -dstStride[0], -dstStride[1], -dstStride[2], ++ -dstStride[3] }; ++ ++ src2[0] += (srcSliceH - 1) * srcStride[0]; ++ if (!usePal(c->srcFormat)) ++ src2[1] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[1]; ++ src2[2] += ((srcSliceH >> c->chrSrcVSubSample) - 1) * srcStride[2]; ++ src2[3] += (srcSliceH - 1) * srcStride[3]; ++ dst2[0] += ( c->dstH - 1) * dstStride[0]; ++ dst2[1] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[1]; ++ dst2[2] += ((c->dstH >> c->chrDstVSubSample) - 1) * dstStride[2]; ++ dst2[3] += ( c->dstH - 1) * dstStride[3]; ++ ++ reset_ptr(src2, c->srcFormat); ++ reset_ptr((void*)dst2, c->dstFormat); ++ ++ /* reset slice direction at end of frame */ ++ if (!srcSliceY) ++ c->sliceDir = 0; ++ ++ ret = c->swScale(c, src2, srcStride2, c->srcH-srcSliceY-srcSliceH, ++ srcSliceH, dst2, dstStride2); ++ } ++ ++ av_free(rgb0_tmp); ++ return ret; ++} ++ ++/* Convert the palette to the same packed 32-bit format as the palette */ ++void sws_convertPalette8ToPacked32(const uint8_t *src, uint8_t *dst, ++ int num_pixels, const uint8_t *palette) ++{ ++ int i; ++ ++ for (i = 0; i < num_pixels; i++) ++ ((uint32_t *) dst)[i] = ((const uint32_t *) palette)[src[i]]; ++} ++ ++/* Palette format: ABCD -> dst format: ABC */ ++void sws_convertPalette8ToPacked24(const uint8_t *src, uint8_t *dst, ++ int num_pixels, const uint8_t *palette) ++{ ++ int i; ++ ++ for (i = 0; i < num_pixels; i++) { ++ //FIXME slow? ++ dst[0] = palette[src[i] * 4 + 0]; ++ dst[1] = palette[src[i] * 4 + 1]; ++ dst[2] = palette[src[i] * 4 + 2]; ++ dst += 3; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/utils.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/utils.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/utils.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/utils.c 2012-05-14 14:08:55.456362563 +0200 +@@ -41,13 +41,17 @@ + #include "rgb2rgb.h" + #include "libavutil/intreadwrite.h" + #include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" + #include "libavutil/avutil.h" + #include "libavutil/bswap.h" ++#include "libavutil/mathematics.h" + #include "libavutil/opt.h" + #include "libavutil/pixdesc.h" ++#include "libavutil/avassert.h" + + unsigned swscale_version(void) + { ++ av_assert0(LIBSWSCALE_VERSION_MICRO >= 100); + return LIBSWSCALE_VERSION_INT; + } + +@@ -64,105 +68,121 @@ + + #define RET 0xC3 //near return opcode for x86 + +-#define isSupportedIn(x) ( \ +- (x)==PIX_FMT_YUV420P \ +- || (x)==PIX_FMT_YUVA420P \ +- || (x)==PIX_FMT_YUYV422 \ +- || (x)==PIX_FMT_UYVY422 \ +- || (x)==PIX_FMT_RGB48BE \ +- || (x)==PIX_FMT_RGB48LE \ +- || (x)==PIX_FMT_RGB32 \ +- || (x)==PIX_FMT_RGB32_1 \ +- || (x)==PIX_FMT_BGR24 \ +- || (x)==PIX_FMT_BGR565 \ +- || (x)==PIX_FMT_BGR555 \ +- || (x)==PIX_FMT_BGR32 \ +- || (x)==PIX_FMT_BGR32_1 \ +- || (x)==PIX_FMT_RGB24 \ +- || (x)==PIX_FMT_RGB565 \ +- || (x)==PIX_FMT_RGB555 \ +- || (x)==PIX_FMT_GRAY8 \ +- || (x)==PIX_FMT_Y400A \ +- || (x)==PIX_FMT_YUV410P \ +- || (x)==PIX_FMT_YUV440P \ +- || (x)==PIX_FMT_NV12 \ +- || (x)==PIX_FMT_NV21 \ +- || (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- || (x)==PIX_FMT_YUV444P \ +- || (x)==PIX_FMT_YUV422P \ +- || (x)==PIX_FMT_YUV411P \ +- || (x)==PIX_FMT_YUVJ420P \ +- || (x)==PIX_FMT_YUVJ422P \ +- || (x)==PIX_FMT_YUVJ440P \ +- || (x)==PIX_FMT_YUVJ444P \ +- || (x)==PIX_FMT_PAL8 \ +- || (x)==PIX_FMT_BGR8 \ +- || (x)==PIX_FMT_RGB8 \ +- || (x)==PIX_FMT_BGR4_BYTE \ +- || (x)==PIX_FMT_RGB4_BYTE \ +- || (x)==PIX_FMT_YUV440P \ +- || (x)==PIX_FMT_MONOWHITE \ +- || (x)==PIX_FMT_MONOBLACK \ +- || (x)==PIX_FMT_YUV420P16LE \ +- || (x)==PIX_FMT_YUV422P16LE \ +- || (x)==PIX_FMT_YUV444P16LE \ +- || (x)==PIX_FMT_YUV420P16BE \ +- || (x)==PIX_FMT_YUV422P16BE \ +- || (x)==PIX_FMT_YUV444P16BE \ +- ) ++typedef struct FormatEntry { ++ int is_supported_in, is_supported_out; ++} FormatEntry; ++ ++static const FormatEntry format_entries[PIX_FMT_NB] = { ++ [PIX_FMT_YUV420P] = { 1 , 1 }, ++ [PIX_FMT_YUYV422] = { 1 , 1 }, ++ [PIX_FMT_RGB24] = { 1 , 1 }, ++ [PIX_FMT_BGR24] = { 1 , 1 }, ++ [PIX_FMT_YUV422P] = { 1 , 1 }, ++ [PIX_FMT_YUV444P] = { 1 , 1 }, ++ [PIX_FMT_YUV410P] = { 1 , 1 }, ++ [PIX_FMT_YUV411P] = { 1 , 1 }, ++ [PIX_FMT_GRAY8] = { 1 , 1 }, ++ [PIX_FMT_MONOWHITE] = { 1 , 1 }, ++ [PIX_FMT_MONOBLACK] = { 1 , 1 }, ++ [PIX_FMT_PAL8] = { 1 , 0 }, ++ [PIX_FMT_YUVJ420P] = { 1 , 1 }, ++ [PIX_FMT_YUVJ422P] = { 1 , 1 }, ++ [PIX_FMT_YUVJ444P] = { 1 , 1 }, ++ [PIX_FMT_UYVY422] = { 1 , 1 }, ++ [PIX_FMT_UYYVYY411] = { 0 , 0 }, ++ [PIX_FMT_BGR8] = { 1 , 1 }, ++ [PIX_FMT_BGR4] = { 0 , 1 }, ++ [PIX_FMT_BGR4_BYTE] = { 1 , 1 }, ++ [PIX_FMT_RGB8] = { 1 , 1 }, ++ [PIX_FMT_RGB4] = { 0 , 1 }, ++ [PIX_FMT_RGB4_BYTE] = { 1 , 1 }, ++ [PIX_FMT_NV12] = { 1 , 1 }, ++ [PIX_FMT_NV21] = { 1 , 1 }, ++ [PIX_FMT_ARGB] = { 1 , 1 }, ++ [PIX_FMT_RGBA] = { 1 , 1 }, ++ [PIX_FMT_ABGR] = { 1 , 1 }, ++ [PIX_FMT_BGRA] = { 1 , 1 }, ++ [PIX_FMT_0RGB] = { 1 , 1 }, ++ [PIX_FMT_RGB0] = { 1 , 1 }, ++ [PIX_FMT_0BGR] = { 1 , 1 }, ++ [PIX_FMT_BGR0] = { 1 , 1 }, ++ [PIX_FMT_GRAY16BE] = { 1 , 1 }, ++ [PIX_FMT_GRAY16LE] = { 1 , 1 }, ++ [PIX_FMT_YUV440P] = { 1 , 1 }, ++ [PIX_FMT_YUVJ440P] = { 1 , 1 }, ++ [PIX_FMT_YUVA420P] = { 1 , 1 }, ++ [PIX_FMT_RGB48BE] = { 1 , 1 }, ++ [PIX_FMT_RGB48LE] = { 1 , 1 }, ++ [PIX_FMT_RGBA64BE] = { 0 , 0 }, ++ [PIX_FMT_RGBA64LE] = { 0 , 0 }, ++ [PIX_FMT_RGB565BE] = { 1 , 1 }, ++ [PIX_FMT_RGB565LE] = { 1 , 1 }, ++ [PIX_FMT_RGB555BE] = { 1 , 1 }, ++ [PIX_FMT_RGB555LE] = { 1 , 1 }, ++ [PIX_FMT_BGR565BE] = { 1 , 1 }, ++ [PIX_FMT_BGR565LE] = { 1 , 1 }, ++ [PIX_FMT_BGR555BE] = { 1 , 1 }, ++ [PIX_FMT_BGR555LE] = { 1 , 1 }, ++ [PIX_FMT_YUV420P16LE] = { 1 , 1 }, ++ [PIX_FMT_YUV420P16BE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P16LE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P16BE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P16LE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P16BE] = { 1 , 1 }, ++ [PIX_FMT_RGB444LE] = { 1 , 1 }, ++ [PIX_FMT_RGB444BE] = { 1 , 1 }, ++ [PIX_FMT_BGR444LE] = { 1 , 1 }, ++ [PIX_FMT_BGR444BE] = { 1 , 1 }, ++ [PIX_FMT_Y400A] = { 1 , 0 }, ++ [PIX_FMT_BGR48BE] = { 1 , 1 }, ++ [PIX_FMT_BGR48LE] = { 1 , 1 }, ++ [PIX_FMT_BGRA64BE] = { 0 , 0 }, ++ [PIX_FMT_BGRA64LE] = { 0 , 0 }, ++ [PIX_FMT_YUV420P9BE] = { 1 , 1 }, ++ [PIX_FMT_YUV420P9LE] = { 1 , 1 }, ++ [PIX_FMT_YUV420P10BE] = { 1 , 1 }, ++ [PIX_FMT_YUV420P10LE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P9BE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P9LE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P10BE] = { 1 , 1 }, ++ [PIX_FMT_YUV422P10LE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P9BE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P9LE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P10BE] = { 1 , 1 }, ++ [PIX_FMT_YUV444P10LE] = { 1 , 1 }, ++ [PIX_FMT_GBR24P] = { 1 , 0 }, ++ [PIX_FMT_GBRP] = { 1 , 0 }, ++ [PIX_FMT_GBRP9LE] = { 1 , 0 }, ++ [PIX_FMT_GBRP9BE] = { 1 , 0 }, ++ [PIX_FMT_GBRP10LE] = { 1 , 0 }, ++ [PIX_FMT_GBRP10BE] = { 1 , 0 }, ++ [PIX_FMT_GBRP16LE] = { 1 , 0 }, ++ [PIX_FMT_GBRP16BE] = { 1 , 0 }, ++}; + + int sws_isSupportedInput(enum PixelFormat pix_fmt) + { +- return isSupportedIn(pix_fmt); ++ return (unsigned)pix_fmt < PIX_FMT_NB ? ++ format_entries[pix_fmt].is_supported_in : 0; + } + +-#define isSupportedOut(x) ( \ +- (x)==PIX_FMT_YUV420P \ +- || (x)==PIX_FMT_YUVA420P \ +- || (x)==PIX_FMT_YUYV422 \ +- || (x)==PIX_FMT_UYVY422 \ +- || (x)==PIX_FMT_YUV444P \ +- || (x)==PIX_FMT_YUV422P \ +- || (x)==PIX_FMT_YUV411P \ +- || (x)==PIX_FMT_YUVJ420P \ +- || (x)==PIX_FMT_YUVJ422P \ +- || (x)==PIX_FMT_YUVJ440P \ +- || (x)==PIX_FMT_YUVJ444P \ +- || isAnyRGB(x) \ +- || (x)==PIX_FMT_NV12 \ +- || (x)==PIX_FMT_NV21 \ +- || (x)==PIX_FMT_GRAY16BE \ +- || (x)==PIX_FMT_GRAY16LE \ +- || (x)==PIX_FMT_GRAY8 \ +- || (x)==PIX_FMT_YUV410P \ +- || (x)==PIX_FMT_YUV440P \ +- || (x)==PIX_FMT_YUV420P16LE \ +- || (x)==PIX_FMT_YUV422P16LE \ +- || (x)==PIX_FMT_YUV444P16LE \ +- || (x)==PIX_FMT_YUV420P16BE \ +- || (x)==PIX_FMT_YUV422P16BE \ +- || (x)==PIX_FMT_YUV444P16BE \ +- ) +- + int sws_isSupportedOutput(enum PixelFormat pix_fmt) + { +- return isSupportedOut(pix_fmt); ++ return (unsigned)pix_fmt < PIX_FMT_NB ? ++ format_entries[pix_fmt].is_supported_out : 0; + } + + extern const int32_t ff_yuv2rgb_coeffs[8][4]; + ++#if FF_API_SWS_FORMAT_NAME + const char *sws_format_name(enum PixelFormat format) + { +- if ((unsigned)format < PIX_FMT_NB && av_pix_fmt_descriptors[format].name) +- return av_pix_fmt_descriptors[format].name; +- else +- return "Unknown format"; ++ return av_get_pix_fmt_name(format); + } ++#endif + + static double getSplineCoeff(double a, double b, double c, double d, double dist) + { +-// printf("%f %f %f %f %f\n", a,b,c,d,dist); + if (dist<=1.0) return ((d*dist + c)*dist + b)*dist +a; + else return getSplineCoeff( 0.0, + b+ 2.0*c + 3.0*d, +@@ -171,8 +191,8 @@ + dist-1.0); + } + +-static int initFilter(int16_t **outFilter, int16_t **filterPos, int *outFilterSize, int xInc, +- int srcW, int dstW, int filterAlign, int one, int flags, ++static int initFilter(int16_t **outFilter, int32_t **filterPos, int *outFilterSize, int xInc, ++ int srcW, int dstW, int filterAlign, int one, int flags, int cpu_flags, + SwsVector *srcFilter, SwsVector *dstFilter, double param[2]) + { + int i; +@@ -183,13 +203,11 @@ + int64_t *filter2=NULL; + const int64_t fone= 1LL<<54; + int ret= -1; +-#if ARCH_X86 +- if (flags & SWS_CPU_CAPS_MMX) +- __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions) +-#endif + +- // NOTE: the +1 is for the MMX scaler which reads over the end +- FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+1)*sizeof(int16_t), fail); ++ emms_c(); //FIXME this should not be required but it IS (even for non-MMX versions) ++ ++ // NOTE: the +3 is for the MMX(+1)/SSE(+3) scaler which reads over the end ++ FF_ALLOC_OR_GOTO(NULL, *filterPos, (dstW+3)*sizeof(**filterPos), fail); + + if (FFABS(xInc - 0x10000) <10) { // unscaled + int i; +@@ -203,7 +221,7 @@ + + } else if (flags&SWS_POINT) { // lame looking point sampling mode + int i; +- int xDstInSrc; ++ int64_t xDstInSrc; + filterSize= 1; + FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + +@@ -217,7 +235,7 @@ + } + } else if ((xInc <= (1<<16) && (flags&SWS_AREA)) || (flags&SWS_FAST_BILINEAR)) { // bilinear upscale + int i; +- int xDstInSrc; ++ int64_t xDstInSrc; + filterSize= 2; + FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + +@@ -229,7 +247,7 @@ + (*filterPos)[i]= xx; + //bilinear upscale / linear interpolate / area averaging + for (j=0; j>16); ++ int64_t coeff= fone - FFABS(((int64_t)xx<<16) - xDstInSrc)*(fone>>16); + if (coeff<0) coeff=0; + filter[i*filterSize + j]= coeff; + xx++; +@@ -237,7 +255,7 @@ + xDstInSrc+= xInc; + } + } else { +- int xDstInSrc; ++ int64_t xDstInSrc; + int sizeFactor; + + if (flags&SWS_BICUBIC) sizeFactor= 4; +@@ -256,7 +274,7 @@ + if (xInc <= 1<<16) filterSize= 1 + sizeFactor; // upscale + else filterSize= 1 + (sizeFactor*srcW + dstW - 1)/ dstW; + +- if (filterSize > srcW-2) filterSize=srcW-2; ++ filterSize = av_clip(filterSize, 1, srcW - 2); + + FF_ALLOC_OR_GOTO(NULL, filter, dstW*sizeof(*filter)*filterSize, fail); + +@@ -266,7 +284,7 @@ + int j; + (*filterPos)[i]= xx; + for (j=0; j>30; +- int64_t ddd= (dd*d)>>30; + +- if (d < 1LL<<30) +- coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30); +- else if (d < 1LL<<31) +- coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30); +- else +- coeff=0.0; ++ if (d >= 1LL<<31) { ++ coeff = 0.0; ++ } else { ++ int64_t dd = (d * d) >> 30; ++ int64_t ddd = (dd * d) >> 30; ++ ++ if (d < 1LL<<30) ++ coeff = (12*(1<<24)-9*B-6*C)*ddd + (-18*(1<<24)+12*B+6*C)*dd + (6*(1<<24)-2*B)*(1<<30); ++ else ++ coeff = (-B-6*C)*ddd + (6*B+30*C)*dd + (-12*B-48*C)*d + (8*B+24*C)*(1<<30); ++ } + coeff *= fone>>(30+24); + } + /* else if (flags & SWS_X) { +@@ -403,7 +424,7 @@ + if (min>minFilterSize) minFilterSize= min; + } + +- if (flags & SWS_CPU_CAPS_ALTIVEC) { ++ if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) { + // we can handle the special case 4, + // so we don't want to go to the full 8 + if (minFilterSize < 5) +@@ -418,7 +439,7 @@ + filterAlign = 1; + } + +- if (flags & SWS_CPU_CAPS_MMX) { ++ if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) { + // special case for unscaled vertical filtering + if (minFilterSize == 1 && filterAlign == 2) + filterAlign= 1; +@@ -475,7 +496,7 @@ + + // Note the +1 is for the MMX scaler which reads over the end + /* align at 16 for AltiVec (needed by hScale_altivec_real) */ +- FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+1)*sizeof(int16_t), fail); ++ FF_ALLOCZ_OR_GOTO(NULL, *outFilter, *outFilterSize*(dstW+3)*sizeof(int16_t), fail); + + /* normalize & store in outFilter */ + for (i=0; isrcColorspaceTable, inv_table, sizeof(int)*4); + memcpy(c->dstColorspaceTable, table, sizeof(int)*4); +@@ -690,21 +715,20 @@ + + c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->dstFormat]); + c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[c->srcFormat]); +- c->flags = update_flags_cpu(c->flags); + + ff_yuv2rgb_c_init_tables(c, inv_table, srcRange, brightness, contrast, saturation); + //FIXME factorize + +-#if HAVE_ALTIVEC +- if (c->flags & SWS_CPU_CAPS_ALTIVEC) ++ if (HAVE_ALTIVEC && av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) + ff_yuv2rgb_init_tables_altivec(c, inv_table, brightness, contrast, saturation); +-#endif + return 0; + } + +-int sws_getColorspaceDetails(SwsContext *c, int **inv_table, int *srcRange, int **table, int *dstRange, int *brightness, int *contrast, int *saturation) ++int sws_getColorspaceDetails(struct SwsContext *c, int **inv_table, ++ int *srcRange, int **table, int *dstRange, ++ int *brightness, int *contrast, int *saturation) + { +- if (isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; ++ if (!c || isYUV(c->dstFormat) || isGray(c->dstFormat)) return -1; + + *inv_table = c->srcColorspaceTable; + *table = c->dstColorspaceTable; +@@ -728,18 +752,15 @@ + } + } + +-static int update_flags_cpu(int flags) ++static int handle_0alpha(enum PixelFormat *format) + { +-#if !CONFIG_RUNTIME_CPUDETECT //ensure that the flags match the compiled variant if cpudetect is off +- flags &= ~( SWS_CPU_CAPS_MMX +- |SWS_CPU_CAPS_MMX2 +- |SWS_CPU_CAPS_3DNOW +- |SWS_CPU_CAPS_SSE2 +- |SWS_CPU_CAPS_ALTIVEC +- |SWS_CPU_CAPS_BFIN); +- flags |= ff_hardcodedcpuflags(); +-#endif /* CONFIG_RUNTIME_CPUDETECT */ +- return flags; ++ switch (*format) { ++ case PIX_FMT_0BGR : *format = PIX_FMT_ABGR ; return 1; ++ case PIX_FMT_BGR0 : *format = PIX_FMT_BGRA ; return 4; ++ case PIX_FMT_0RGB : *format = PIX_FMT_ARGB ; return 1; ++ case PIX_FMT_RGB0 : *format = PIX_FMT_RGBA ; return 4; ++ default: return 0; ++ } + } + + SwsContext *sws_alloc_context(void) +@@ -754,7 +775,7 @@ + + int sws_init_context(SwsContext *c, SwsFilter *srcFilter, SwsFilter *dstFilter) + { +- int i; ++ int i, j; + int usesVFilter, usesHFilter; + int unscaled; + SwsFilter dummyFilter= {NULL, NULL, NULL, NULL}; +@@ -762,25 +783,35 @@ + int srcH= c->srcH; + int dstW= c->dstW; + int dstH= c->dstH; +- int flags; ++ int dst_stride = FFALIGN(dstW * sizeof(int16_t)+66, 16); ++ int flags, cpu_flags; + enum PixelFormat srcFormat= c->srcFormat; + enum PixelFormat dstFormat= c->dstFormat; + +- flags= c->flags = update_flags_cpu(c->flags); +-#if ARCH_X86 +- if (flags & SWS_CPU_CAPS_MMX) +- __asm__ volatile("emms\n\t"::: "memory"); +-#endif +- if (!rgb15to16) sws_rgb2rgb_init(flags); ++ cpu_flags = av_get_cpu_flags(); ++ flags = c->flags; ++ emms_c(); ++ if (!rgb15to16) sws_rgb2rgb_init(); + + unscaled = (srcW == dstW && srcH == dstH); + +- if (!isSupportedIn(srcFormat)) { +- av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as input pixel format\n", sws_format_name(srcFormat)); ++ handle_jpeg(&srcFormat); ++ handle_jpeg(&dstFormat); ++ handle_0alpha(&srcFormat); ++ handle_0alpha(&dstFormat); ++ ++ if(srcFormat!=c->srcFormat || dstFormat!=c->dstFormat){ ++ av_log(c, AV_LOG_WARNING, "deprecated pixel format used, make sure you did set range correctly\n"); ++ c->srcFormat= srcFormat; ++ c->dstFormat= dstFormat; ++ } ++ ++ if (!sws_isSupportedInput(srcFormat)) { ++ av_log(c, AV_LOG_ERROR, "%s is not supported as input pixel format\n", av_get_pix_fmt_name(srcFormat)); + return AVERROR(EINVAL); + } +- if (!isSupportedOut(dstFormat)) { +- av_log(NULL, AV_LOG_ERROR, "swScaler: %s is not supported as output pixel format\n", sws_format_name(dstFormat)); ++ if (!sws_isSupportedOutput(dstFormat)) { ++ av_log(c, AV_LOG_ERROR, "%s is not supported as output pixel format\n", av_get_pix_fmt_name(dstFormat)); + return AVERROR(EINVAL); + } + +@@ -796,25 +827,21 @@ + |SWS_SPLINE + |SWS_BICUBLIN); + if(!i || (i & (i-1))) { +- av_log(NULL, AV_LOG_ERROR, "swScaler: Exactly one scaler algorithm must be chosen\n"); ++ av_log(c, AV_LOG_ERROR, "Exactly one scaler algorithm must be chosen, got %X\n", i); + return AVERROR(EINVAL); + } + /* sanity check */ + if (srcW<4 || srcH<1 || dstW<8 || dstH<1) { //FIXME check if these are enough and try to lowwer them after fixing the relevant parts of the code +- av_log(NULL, AV_LOG_ERROR, "swScaler: %dx%d -> %dx%d is invalid scaling dimension\n", ++ av_log(c, AV_LOG_ERROR, "%dx%d -> %dx%d is invalid scaling dimension\n", + srcW, srcH, dstW, dstH); + return AVERROR(EINVAL); + } +- if(srcW > VOFW || dstW > VOFW) { +- av_log(NULL, AV_LOG_ERROR, "swScaler: Compile-time maximum width is "AV_STRINGIFY(VOFW)" change VOF/VOFW and recompile\n"); +- return AVERROR(EINVAL); +- } + + if (!dstFilter) dstFilter= &dummyFilter; + if (!srcFilter) srcFilter= &dummyFilter; + +- c->lumXInc= ((srcW<<16) + (dstW>>1))/dstW; +- c->lumYInc= ((srcH<<16) + (dstH>>1))/dstH; ++ c->lumXInc= (((int64_t)srcW<<16) + (dstW>>1))/dstW; ++ c->lumYInc= (((int64_t)srcH<<16) + (dstH>>1))/dstH; + c->dstFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[dstFormat]); + c->srcFormatBpp = av_get_bits_per_pixel(&av_pix_fmt_descriptors[srcFormat]); + c->vRounder= 4* 0x0001000100010001ULL; +@@ -832,7 +859,14 @@ + getSubSampleFactors(&c->chrDstHSubSample, &c->chrDstVSubSample, dstFormat); + + // reuse chroma for 2 pixels RGB/BGR unless user wants full chroma interpolation +- if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) c->chrDstHSubSample=1; ++ if (isAnyRGB(dstFormat) && !(flags&SWS_FULL_CHR_H_INT)) { ++ if (dstW&1) { ++ av_log(c, AV_LOG_DEBUG, "Forcing full internal H chroma due to odd output size\n"); ++ flags |= SWS_FULL_CHR_H_INT; ++ c->flags = flags; ++ } else ++ c->chrDstHSubSample = 1; ++ } + + // drop some chroma lines if the user wants it + c->vChrDrop= (flags&SWS_SRC_V_CHR_DROP_MASK)>>SWS_SRC_V_CHR_DROP_SHIFT; +@@ -859,24 +893,35 @@ + if (c->swScale) { + if (flags&SWS_PRINT_INFO) + av_log(c, AV_LOG_INFO, "using unscaled %s -> %s special converter\n", +- sws_format_name(srcFormat), sws_format_name(dstFormat)); ++ av_get_pix_fmt_name(srcFormat), av_get_pix_fmt_name(dstFormat)); + return 0; + } + } + +- if (flags & SWS_CPU_CAPS_MMX2) { ++ c->srcBpc = 1 + av_pix_fmt_descriptors[srcFormat].comp[0].depth_minus1; ++ if (c->srcBpc < 8) ++ c->srcBpc = 8; ++ c->dstBpc = 1 + av_pix_fmt_descriptors[dstFormat].comp[0].depth_minus1; ++ if (c->dstBpc < 8) ++ c->dstBpc = 8; ++ if (isAnyRGB(srcFormat) || srcFormat == PIX_FMT_PAL8) ++ c->srcBpc = 16; ++ if (c->dstBpc == 16) ++ dst_stride <<= 1; ++ FF_ALLOC_OR_GOTO(c, c->formatConvBuffer, FFALIGN(srcW*2+78, 16) * 2, fail); ++ if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2 && c->srcBpc == 8 && c->dstBpc <= 10) { + c->canMMX2BeUsed= (dstW >=srcW && (dstW&31)==0 && (srcW&15)==0) ? 1 : 0; + if (!c->canMMX2BeUsed && dstW >=srcW && (srcW&15)==0 && (flags&SWS_FAST_BILINEAR)) { + if (flags&SWS_PRINT_INFO) + av_log(c, AV_LOG_INFO, "output width is not a multiple of 32 -> no MMX2 scaler\n"); + } +- if (usesHFilter) c->canMMX2BeUsed=0; ++ if (usesHFilter || isNBPS(c->srcFormat) || is16BPS(c->srcFormat) || isAnyRGB(c->srcFormat)) c->canMMX2BeUsed=0; + } + else + c->canMMX2BeUsed=0; + +- c->chrXInc= ((c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; +- c->chrYInc= ((c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; ++ c->chrXInc= (((int64_t)c->chrSrcW<<16) + (c->chrDstW>>1))/c->chrDstW; ++ c->chrYInc= (((int64_t)c->chrSrcH<<16) + (c->chrDstH>>1))/c->chrDstH; + + // match pixel 0 of the src to pixel 0 of dst and match pixel n-2 of src to pixel n-2 of dst + // but only for the FAST_BILINEAR mode otherwise do correct scaling +@@ -890,15 +935,15 @@ + c->chrXInc+= 20; + } + //we don't use the x86 asm scaler if MMX is available +- else if (flags & SWS_CPU_CAPS_MMX) { +- c->lumXInc = ((srcW-2)<<16)/(dstW-2) - 20; +- c->chrXInc = ((c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; ++ else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX && c->dstBpc <= 10) { ++ c->lumXInc = ((int64_t)(srcW-2)<<16)/(dstW-2) - 20; ++ c->chrXInc = ((int64_t)(c->chrSrcW-2)<<16)/(c->chrDstW-2) - 20; + } + } + + /* precalculate horizontal scaler filter coefficients */ + { +-#if ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) ++#if HAVE_MMX2 + // can't downscale !!! + if (c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR)) { + c->lumMmx2FilterCodeSize = initMMX2HScaler( dstW, c->lumXInc, NULL, NULL, NULL, 8); +@@ -915,36 +960,43 @@ + c->chrMmx2FilterCode = av_malloc(c->chrMmx2FilterCodeSize); + #endif + ++#ifdef MAP_ANONYMOUS ++ if (c->lumMmx2FilterCode == MAP_FAILED || c->chrMmx2FilterCode == MAP_FAILED) ++#else + if (!c->lumMmx2FilterCode || !c->chrMmx2FilterCode) ++#endif ++ { ++ av_log(c, AV_LOG_ERROR, "Failed to allocate MMX2FilterCode\n"); + return AVERROR(ENOMEM); ++ } + FF_ALLOCZ_OR_GOTO(c, c->hLumFilter , (dstW /8+8)*sizeof(int16_t), fail); + FF_ALLOCZ_OR_GOTO(c, c->hChrFilter , (c->chrDstW /4+8)*sizeof(int16_t), fail); + FF_ALLOCZ_OR_GOTO(c, c->hLumFilterPos, (dstW /2/8+8)*sizeof(int32_t), fail); + FF_ALLOCZ_OR_GOTO(c, c->hChrFilterPos, (c->chrDstW/2/4+8)*sizeof(int32_t), fail); + +- initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, c->hLumFilterPos, 8); +- initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, c->hChrFilterPos, 4); ++ initMMX2HScaler( dstW, c->lumXInc, c->lumMmx2FilterCode, c->hLumFilter, (uint32_t*)c->hLumFilterPos, 8); ++ initMMX2HScaler(c->chrDstW, c->chrXInc, c->chrMmx2FilterCode, c->hChrFilter, (uint32_t*)c->hChrFilterPos, 4); + + #ifdef MAP_ANONYMOUS + mprotect(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize, PROT_EXEC | PROT_READ); + mprotect(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize, PROT_EXEC | PROT_READ); + #endif + } else +-#endif /* ARCH_X86 && (HAVE_MMX2 || CONFIG_RUNTIME_CPUDETECT) */ ++#endif /* HAVE_MMX2 */ + { + const int filterAlign= +- (flags & SWS_CPU_CAPS_MMX) ? 4 : +- (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : ++ (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 4 : ++ (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 : + 1; + + if (initFilter(&c->hLumFilter, &c->hLumFilterPos, &c->hLumFilterSize, c->lumXInc, + srcW , dstW, filterAlign, 1<<14, +- (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, ++ (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, cpu_flags, + srcFilter->lumH, dstFilter->lumH, c->param) < 0) + goto fail; + if (initFilter(&c->hChrFilter, &c->hChrFilterPos, &c->hChrFilterSize, c->chrXInc, + c->chrSrcW, c->chrDstW, filterAlign, 1<<14, +- (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, ++ (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags, + srcFilter->chrH, dstFilter->chrH, c->param) < 0) + goto fail; + } +@@ -953,18 +1005,18 @@ + /* precalculate vertical scaler filter coefficients */ + { + const int filterAlign= +- (flags & SWS_CPU_CAPS_MMX) && (flags & SWS_ACCURATE_RND) ? 2 : +- (flags & SWS_CPU_CAPS_ALTIVEC) ? 8 : ++ (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) ? 2 : ++ (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) ? 8 : + 1; + + if (initFilter(&c->vLumFilter, &c->vLumFilterPos, &c->vLumFilterSize, c->lumYInc, + srcH , dstH, filterAlign, (1<<12), +- (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, ++ (flags&SWS_BICUBLIN) ? (flags|SWS_BICUBIC) : flags, cpu_flags, + srcFilter->lumV, dstFilter->lumV, c->param) < 0) + goto fail; + if (initFilter(&c->vChrFilter, &c->vChrFilterPos, &c->vChrFilterSize, c->chrYInc, + c->chrSrcH, c->chrDstH, filterAlign, (1<<12), +- (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, ++ (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags, cpu_flags, + srcFilter->chrV, dstFilter->chrV, c->param) < 0) + goto fail; + +@@ -992,7 +1044,7 @@ + c->vLumBufSize= c->vLumFilterSize; + c->vChrBufSize= c->vChrFilterSize; + for (i=0; ichrDstH / dstH; ++ int chrI = (int64_t) i * c->chrDstH / dstH; + int nextSlice= FFMAX(c->vLumFilterPos[i ] + c->vLumFilterSize - 1, + ((c->vChrFilterPos[chrI] + c->vChrFilterSize - 1)<chrSrcVSubSample)); + +@@ -1007,29 +1059,39 @@ + // allocate pixbufs (we use dynamic allocation because otherwise we would need to + // allocate several megabytes to handle all possible cases) + FF_ALLOC_OR_GOTO(c, c->lumPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); +- FF_ALLOC_OR_GOTO(c, c->chrPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail); ++ FF_ALLOC_OR_GOTO(c, c->chrUPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail); ++ FF_ALLOC_OR_GOTO(c, c->chrVPixBuf, c->vChrBufSize*2*sizeof(int16_t*), fail); + if (CONFIG_SWSCALE_ALPHA && isALPHA(c->srcFormat) && isALPHA(c->dstFormat)) + FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf, c->vLumBufSize*2*sizeof(int16_t*), fail); + //Note we need at least one pixel more at the end because of the MMX code (just in case someone wanna replace the 4000/8000) + /* align at 16 bytes for AltiVec */ + for (i=0; ivLumBufSize; i++) { +- FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], VOF+1, fail); ++ FF_ALLOCZ_OR_GOTO(c, c->lumPixBuf[i+c->vLumBufSize], dst_stride+16, fail); + c->lumPixBuf[i] = c->lumPixBuf[i+c->vLumBufSize]; + } ++ // 64 / c->scalingBpp is the same as 16 / sizeof(scaling_intermediate) ++ c->uv_off = (dst_stride>>1) + 64 / (c->dstBpc &~ 7); ++ c->uv_offx2 = dst_stride + 16; + for (i=0; ivChrBufSize; i++) { +- FF_ALLOC_OR_GOTO(c, c->chrPixBuf[i+c->vChrBufSize], (VOF+1)*2, fail); +- c->chrPixBuf[i] = c->chrPixBuf[i+c->vChrBufSize]; ++ FF_ALLOC_OR_GOTO(c, c->chrUPixBuf[i+c->vChrBufSize], dst_stride*2+32, fail); ++ c->chrUPixBuf[i] = c->chrUPixBuf[i+c->vChrBufSize]; ++ c->chrVPixBuf[i] = c->chrVPixBuf[i+c->vChrBufSize] = c->chrUPixBuf[i] + (dst_stride >> 1) + 8; + } + if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) + for (i=0; ivLumBufSize; i++) { +- FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], VOF+1, fail); ++ FF_ALLOCZ_OR_GOTO(c, c->alpPixBuf[i+c->vLumBufSize], dst_stride+16, fail); + c->alpPixBuf[i] = c->alpPixBuf[i+c->vLumBufSize]; + } + + //try to avoid drawing green stuff between the right end and the stride end +- for (i=0; ivChrBufSize; i++) memset(c->chrPixBuf[i], 64, (VOF+1)*2); +- +- assert(2*VOFW == VOF); ++ for (i=0; ivChrBufSize; i++) ++ if(av_pix_fmt_descriptors[c->dstFormat].comp[0].depth_minus1 == 15){ ++ av_assert0(c->dstBpc > 10); ++ for(j=0; jchrUPixBuf[i]))[j] = 1<<18; ++ } else ++ for(j=0; jchrUPixBuf[i]))[j] = 1<<14; + + assert(c->chrDstH <= dstH); + +@@ -1048,7 +1110,7 @@ + else av_log(c, AV_LOG_INFO, "ehh flags invalid?! "); + + av_log(c, AV_LOG_INFO, "from %s to %s%s ", +- sws_format_name(srcFormat), ++ av_get_pix_fmt_name(srcFormat), + #ifdef DITHER1XBPP + dstFormat == PIX_FMT_BGR555 || dstFormat == PIX_FMT_BGR565 || + dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || +@@ -1056,70 +1118,14 @@ + #else + "", + #endif +- sws_format_name(dstFormat)); ++ av_get_pix_fmt_name(dstFormat)); + +- if (flags & SWS_CPU_CAPS_MMX2) av_log(c, AV_LOG_INFO, "using MMX2\n"); +- else if (flags & SWS_CPU_CAPS_3DNOW) av_log(c, AV_LOG_INFO, "using 3DNOW\n"); +- else if (flags & SWS_CPU_CAPS_MMX) av_log(c, AV_LOG_INFO, "using MMX\n"); +- else if (flags & SWS_CPU_CAPS_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n"); ++ if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) av_log(c, AV_LOG_INFO, "using MMX2\n"); ++ else if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW) av_log(c, AV_LOG_INFO, "using 3DNOW\n"); ++ else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) av_log(c, AV_LOG_INFO, "using MMX\n"); ++ else if (HAVE_ALTIVEC && cpu_flags & AV_CPU_FLAG_ALTIVEC) av_log(c, AV_LOG_INFO, "using AltiVec\n"); + else av_log(c, AV_LOG_INFO, "using C\n"); + +- if (flags & SWS_CPU_CAPS_MMX) { +- if (c->canMMX2BeUsed && (flags&SWS_FAST_BILINEAR)) +- av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR MMX2 scaler for horizontal scaling\n"); +- else { +- if (c->hLumFilterSize==4) +- av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal luminance scaling\n"); +- else if (c->hLumFilterSize==8) +- av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal luminance scaling\n"); +- else +- av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal luminance scaling\n"); +- +- if (c->hChrFilterSize==4) +- av_log(c, AV_LOG_VERBOSE, "using 4-tap MMX scaler for horizontal chrominance scaling\n"); +- else if (c->hChrFilterSize==8) +- av_log(c, AV_LOG_VERBOSE, "using 8-tap MMX scaler for horizontal chrominance scaling\n"); +- else +- av_log(c, AV_LOG_VERBOSE, "using n-tap MMX scaler for horizontal chrominance scaling\n"); +- } +- } else { +-#if ARCH_X86 +- av_log(c, AV_LOG_VERBOSE, "using x86 asm scaler for horizontal scaling\n"); +-#else +- if (flags & SWS_FAST_BILINEAR) +- av_log(c, AV_LOG_VERBOSE, "using FAST_BILINEAR C scaler for horizontal scaling\n"); +- else +- av_log(c, AV_LOG_VERBOSE, "using C scaler for horizontal scaling\n"); +-#endif +- } +- if (isPlanarYUV(dstFormat)) { +- if (c->vLumFilterSize==1) +- av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else +- av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (YV12 like)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- } else { +- if (c->vLumFilterSize==1 && c->vChrFilterSize==2) +- av_log(c, AV_LOG_VERBOSE, "using 1-tap %s \"scaler\" for vertical luminance scaling (BGR)\n" +- " 2-tap scaler for vertical chrominance scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else if (c->vLumFilterSize==2 && c->vChrFilterSize==2) +- av_log(c, AV_LOG_VERBOSE, "using 2-tap linear %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else +- av_log(c, AV_LOG_VERBOSE, "using n-tap %s scaler for vertical scaling (BGR)\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- } +- +- if (dstFormat==PIX_FMT_BGR24) +- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR24 converter\n", +- (flags & SWS_CPU_CAPS_MMX2) ? "MMX2" : ((flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C")); +- else if (dstFormat==PIX_FMT_RGB32) +- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR32 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else if (dstFormat==PIX_FMT_BGR565) +- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR16 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else if (dstFormat==PIX_FMT_BGR555) +- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR15 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- else if (dstFormat == PIX_FMT_RGB444BE || dstFormat == PIX_FMT_RGB444LE || +- dstFormat == PIX_FMT_BGR444BE || dstFormat == PIX_FMT_BGR444LE) +- av_log(c, AV_LOG_VERBOSE, "using %s YV12->BGR12 converter\n", (flags & SWS_CPU_CAPS_MMX) ? "MMX" : "C"); +- + av_log(c, AV_LOG_VERBOSE, "%dx%d -> %dx%d\n", srcW, srcH, dstW, dstH); + av_log(c, AV_LOG_DEBUG, "lum srcW=%d srcH=%d dstW=%d dstH=%d xInc=%d yInc=%d\n", + c->srcW, c->srcH, c->dstW, c->dstH, c->lumXInc, c->lumYInc); +@@ -1150,6 +1156,8 @@ + c->dstH= dstH; + c->srcRange = handle_jpeg(&srcFormat); + c->dstRange = handle_jpeg(&dstFormat); ++ c->src0Alpha = handle_0alpha(&srcFormat); ++ c->dst0Alpha = handle_0alpha(&dstFormat); + c->srcFormat= srcFormat; + c->dstFormat= dstFormat; + +@@ -1440,13 +1448,6 @@ + } + } + +-#if LIBSWSCALE_VERSION_MAJOR < 1 +-void sws_printVec(SwsVector *a) +-{ +- sws_printVec2(a, NULL, AV_LOG_DEBUG); +-} +-#endif +- + void sws_freeVec(SwsVector *a) + { + if (!a) return; +@@ -1477,10 +1478,11 @@ + av_freep(&c->lumPixBuf); + } + +- if (c->chrPixBuf) { ++ if (c->chrUPixBuf) { + for (i=0; ivChrBufSize; i++) +- av_freep(&c->chrPixBuf[i]); +- av_freep(&c->chrPixBuf); ++ av_freep(&c->chrUPixBuf[i]); ++ av_freep(&c->chrUPixBuf); ++ av_freep(&c->chrVPixBuf); + } + + if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { +@@ -1503,7 +1505,7 @@ + av_freep(&c->hLumFilterPos); + av_freep(&c->hChrFilterPos); + +-#if ARCH_X86 ++#if HAVE_MMX + #ifdef MAP_ANONYMOUS + if (c->lumMmx2FilterCode) munmap(c->lumMmx2FilterCode, c->lumMmx2FilterCodeSize); + if (c->chrMmx2FilterCode) munmap(c->chrMmx2FilterCode, c->chrMmx2FilterCodeSize); +@@ -1516,9 +1518,10 @@ + #endif + c->lumMmx2FilterCode=NULL; + c->chrMmx2FilterCode=NULL; +-#endif /* ARCH_X86 */ ++#endif /* HAVE_MMX */ + + av_freep(&c->yuvTable); ++ av_freep(&c->formatConvBuffer); + + av_free(c); + } +@@ -1533,8 +1536,6 @@ + if (!param) + param = default_param; + +- flags = update_flags_cpu(flags); +- + if (context && + (context->srcW != srcW || + context->srcH != srcH || +@@ -1555,10 +1556,12 @@ + context->srcW = srcW; + context->srcH = srcH; + context->srcRange = handle_jpeg(&srcFormat); ++ context->src0Alpha = handle_0alpha(&srcFormat); + context->srcFormat = srcFormat; + context->dstW = dstW; + context->dstH = dstH; + context->dstRange = handle_jpeg(&dstFormat); ++ context->dst0Alpha = handle_0alpha(&dstFormat); + context->dstFormat = dstFormat; + context->flags = flags; + context->param[0] = param[0]; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/input.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/input.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/input.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/input.asm 2012-05-14 14:08:55.457362583 +0200 +@@ -0,0 +1,244 @@ ++;****************************************************************************** ++;* x86-optimized input routines; does shuffling of packed ++;* YUV formats into individual planes, and converts RGB ++;* into YUV planes also. ++;* Copyright (c) 2012 Ronald S. Bultje ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; YUYV/UYVY/NV12/NV21 packed pixel shuffling. ++; ++; void ToY_(uint8_t *dst, const uint8_t *src, int w); ++; and ++; void toUV_(uint8_t *dstU, uint8_t *dstV, const uint8_t *src, ++; const uint8_t *unused, int w); ++;----------------------------------------------------------------------------- ++ ++; %1 = a (aligned) or u (unaligned) ++; %2 = yuyv or uyvy ++%macro LOOP_YUYV_TO_Y 2 ++.loop_%1: ++ mov%1 m0, [srcq+wq*2] ; (byte) { Y0, U0, Y1, V0, ... } ++ mov%1 m1, [srcq+wq*2+mmsize] ; (byte) { Y8, U4, Y9, V4, ... } ++%ifidn %2, yuyv ++ pand m0, m2 ; (word) { Y0, Y1, ..., Y7 } ++ pand m1, m2 ; (word) { Y8, Y9, ..., Y15 } ++%else ; uyvy ++ psrlw m0, 8 ; (word) { Y0, Y1, ..., Y7 } ++ psrlw m1, 8 ; (word) { Y8, Y9, ..., Y15 } ++%endif ; yuyv/uyvy ++ packuswb m0, m1 ; (byte) { Y0, ..., Y15 } ++ mova [dstq+wq], m0 ++ add wq, mmsize ++ jl .loop_%1 ++ REP_RET ++%endmacro ++ ++; %1 = nr. of XMM registers ++; %2 = yuyv or uyvy ++; %3 = if specified, it means that unaligned and aligned code in loop ++; will be the same (i.e. YUYV+AVX), and thus we don't need to ++; split the loop in an aligned and unaligned case ++%macro YUYV_TO_Y_FN 2-3 ++cglobal %2ToY, 5, 5, %1, dst, unused0, unused1, src, w ++%ifdef ARCH_X86_64 ++ movsxd wq, wd ++%endif ++ add dstq, wq ++%if mmsize == 16 ++ test srcq, 15 ++%endif ++ lea srcq, [srcq+wq*2] ++%ifidn %2, yuyv ++ pcmpeqb m2, m2 ; (byte) { 0xff } x 16 ++ psrlw m2, 8 ; (word) { 0x00ff } x 8 ++%endif ; yuyv ++%if mmsize == 16 ++ jnz .loop_u_start ++ neg wq ++ LOOP_YUYV_TO_Y a, %2 ++.loop_u_start: ++ neg wq ++ LOOP_YUYV_TO_Y u, %2 ++%else ; mmsize == 8 ++ neg wq ++ LOOP_YUYV_TO_Y a, %2 ++%endif ; mmsize == 8/16 ++%endmacro ++ ++; %1 = a (aligned) or u (unaligned) ++; %2 = yuyv or uyvy ++%macro LOOP_YUYV_TO_UV 2 ++.loop_%1: ++%ifidn %2, yuyv ++ mov%1 m0, [srcq+wq*4] ; (byte) { Y0, U0, Y1, V0, ... } ++ mov%1 m1, [srcq+wq*4+mmsize] ; (byte) { Y8, U4, Y9, V4, ... } ++ psrlw m0, 8 ; (word) { U0, V0, ..., U3, V3 } ++ psrlw m1, 8 ; (word) { U4, V4, ..., U7, V7 } ++%else ; uyvy ++%if cpuflag(avx) ++ vpand m0, m2, [srcq+wq*4] ; (word) { U0, V0, ..., U3, V3 } ++ vpand m1, m2, [srcq+wq*4+mmsize] ; (word) { U4, V4, ..., U7, V7 } ++%else ++ mov%1 m0, [srcq+wq*4] ; (byte) { Y0, U0, Y1, V0, ... } ++ mov%1 m1, [srcq+wq*4+mmsize] ; (byte) { Y8, U4, Y9, V4, ... } ++ pand m0, m2 ; (word) { U0, V0, ..., U3, V3 } ++ pand m1, m2 ; (word) { U4, V4, ..., U7, V7 } ++%endif ++%endif ; yuyv/uyvy ++ packuswb m0, m1 ; (byte) { U0, V0, ..., U7, V7 } ++ pand m1, m0, m2 ; (word) { U0, U1, ..., U7 } ++ psrlw m0, 8 ; (word) { V0, V1, ..., V7 } ++%if mmsize == 16 ++ packuswb m1, m0 ; (byte) { U0, ... U7, V1, ... V7 } ++ movh [dstUq+wq], m1 ++ movhps [dstVq+wq], m1 ++%else ; mmsize == 8 ++ packuswb m1, m1 ; (byte) { U0, ... U3 } ++ packuswb m0, m0 ; (byte) { V0, ... V3 } ++ movh [dstUq+wq], m1 ++ movh [dstVq+wq], m0 ++%endif ; mmsize == 8/16 ++ add wq, mmsize / 2 ++ jl .loop_%1 ++ REP_RET ++%endmacro ++ ++; %1 = nr. of XMM registers ++; %2 = yuyv or uyvy ++; %3 = if specified, it means that unaligned and aligned code in loop ++; will be the same (i.e. UYVY+AVX), and thus we don't need to ++; split the loop in an aligned and unaligned case ++%macro YUYV_TO_UV_FN 2-3 ++cglobal %2ToUV, 4, 5, %1, dstU, dstV, unused, src, w ++%ifdef ARCH_X86_64 ++ movsxd wq, dword r5m ++%else ; x86-32 ++ mov wq, r5m ++%endif ++ add dstUq, wq ++ add dstVq, wq ++%if mmsize == 16 && %0 == 2 ++ test srcq, 15 ++%endif ++ lea srcq, [srcq+wq*4] ++ pcmpeqb m2, m2 ; (byte) { 0xff } x 16 ++ psrlw m2, 8 ; (word) { 0x00ff } x 8 ++ ; NOTE: if uyvy+avx, u/a are identical ++%if mmsize == 16 && %0 == 2 ++ jnz .loop_u_start ++ neg wq ++ LOOP_YUYV_TO_UV a, %2 ++.loop_u_start: ++ neg wq ++ LOOP_YUYV_TO_UV u, %2 ++%else ; mmsize == 8 ++ neg wq ++ LOOP_YUYV_TO_UV a, %2 ++%endif ; mmsize == 8/16 ++%endmacro ++ ++; %1 = a (aligned) or u (unaligned) ++; %2 = nv12 or nv21 ++%macro LOOP_NVXX_TO_UV 2 ++.loop_%1: ++ mov%1 m0, [srcq+wq*2] ; (byte) { U0, V0, U1, V1, ... } ++ mov%1 m1, [srcq+wq*2+mmsize] ; (byte) { U8, V8, U9, V9, ... } ++ pand m2, m0, m5 ; (word) { U0, U1, ..., U7 } ++ pand m3, m1, m5 ; (word) { U8, U9, ..., U15 } ++ psrlw m0, 8 ; (word) { V0, V1, ..., V7 } ++ psrlw m1, 8 ; (word) { V8, V9, ..., V15 } ++ packuswb m2, m3 ; (byte) { U0, ..., U15 } ++ packuswb m0, m1 ; (byte) { V0, ..., V15 } ++%ifidn %2, nv12 ++ mova [dstUq+wq], m2 ++ mova [dstVq+wq], m0 ++%else ; nv21 ++ mova [dstVq+wq], m2 ++ mova [dstUq+wq], m0 ++%endif ; nv12/21 ++ add wq, mmsize ++ jl .loop_%1 ++ REP_RET ++%endmacro ++ ++; %1 = nr. of XMM registers ++; %2 = nv12 or nv21 ++%macro NVXX_TO_UV_FN 2 ++cglobal %2ToUV, 4, 5, %1, dstU, dstV, unused, src, w ++%ifdef ARCH_X86_64 ++ movsxd wq, dword r5m ++%else ; x86-32 ++ mov wq, r5m ++%endif ++ add dstUq, wq ++ add dstVq, wq ++%if mmsize == 16 ++ test srcq, 15 ++%endif ++ lea srcq, [srcq+wq*2] ++ pcmpeqb m5, m5 ; (byte) { 0xff } x 16 ++ psrlw m5, 8 ; (word) { 0x00ff } x 8 ++%if mmsize == 16 ++ jnz .loop_u_start ++ neg wq ++ LOOP_NVXX_TO_UV a, %2 ++.loop_u_start: ++ neg wq ++ LOOP_NVXX_TO_UV u, %2 ++%else ; mmsize == 8 ++ neg wq ++ LOOP_NVXX_TO_UV a, %2 ++%endif ; mmsize == 8/16 ++%endmacro ++ ++%ifdef ARCH_X86_32 ++INIT_MMX mmx ++YUYV_TO_Y_FN 0, yuyv ++YUYV_TO_Y_FN 0, uyvy ++YUYV_TO_UV_FN 0, yuyv ++YUYV_TO_UV_FN 0, uyvy ++NVXX_TO_UV_FN 0, nv12 ++NVXX_TO_UV_FN 0, nv21 ++%endif ++ ++INIT_XMM sse2 ++YUYV_TO_Y_FN 3, yuyv ++YUYV_TO_Y_FN 2, uyvy ++YUYV_TO_UV_FN 3, yuyv ++YUYV_TO_UV_FN 3, uyvy ++NVXX_TO_UV_FN 5, nv12 ++NVXX_TO_UV_FN 5, nv21 ++ ++%ifdef HAVE_AVX ++INIT_XMM avx ++; in theory, we could write a yuy2-to-y using vpand (i.e. AVX), but ++; that's not faster in practice ++YUYV_TO_UV_FN 3, yuyv ++YUYV_TO_UV_FN 3, uyvy, 1 ++NVXX_TO_UV_FN 5, nv12 ++NVXX_TO_UV_FN 5, nv21 ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/output.asm xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/output.asm +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/output.asm 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/output.asm 2012-05-14 14:08:55.458362603 +0200 +@@ -0,0 +1,412 @@ ++;****************************************************************************** ++;* x86-optimized vertical line scaling functions ++;* Copyright (c) 2011 Ronald S. Bultje ++;* Kieran Kunhya ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA ++ ++minshort: times 8 dw 0x8000 ++yuv2yuvX_16_start: times 4 dd 0x4000 - 0x40000000 ++yuv2yuvX_10_start: times 4 dd 0x10000 ++yuv2yuvX_9_start: times 4 dd 0x20000 ++yuv2yuvX_10_upper: times 8 dw 0x3ff ++yuv2yuvX_9_upper: times 8 dw 0x1ff ++pd_4: times 4 dd 4 ++pd_4min0x40000:times 4 dd 4 - (0x40000) ++pw_16: times 8 dw 16 ++pw_32: times 8 dw 32 ++pw_512: times 8 dw 512 ++pw_1024: times 8 dw 1024 ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; vertical line scaling ++; ++; void yuv2plane1__(const int16_t *src, uint8_t *dst, int dstW, ++; const uint8_t *dither, int offset) ++; and ++; void yuv2planeX__(const int16_t *filter, int filterSize, ++; const int16_t **src, uint8_t *dst, int dstW, ++; const uint8_t *dither, int offset) ++; ++; Scale one or $filterSize lines of source data to generate one line of output ++; data. The input is 15-bit in int16_t if $output_size is [8,10] and 19-bit in ++; int32_t if $output_size is 16. $filter is 12-bits. $filterSize is a multiple ++; of 2. $offset is either 0 or 3. $dither holds 8 values. ++;----------------------------------------------------------------------------- ++ ++%macro yuv2planeX_fn 3 ++ ++%ifdef ARCH_X86_32 ++%define cntr_reg r1 ++%define movsx mov ++%else ++%define cntr_reg r11 ++%define movsx movsxd ++%endif ++ ++cglobal yuv2planeX_%1, %3, 7, %2 ++%if %1 == 8 || %1 == 9 || %1 == 10 ++ pxor m6, m6 ++%endif ; %1 == 8/9/10 ++ ++%if %1 == 8 ++%ifdef ARCH_X86_32 ++%assign pad 0x2c - (stack_offset & 15) ++ SUB rsp, pad ++%define m_dith m7 ++%else ; x86-64 ++%define m_dith m9 ++%endif ; x86-32 ++ ++ ; create registers holding dither ++ movq m_dith, [r5] ; dither ++ test r6d, r6d ++ jz .no_rot ++%if mmsize == 16 ++ punpcklqdq m_dith, m_dith ++%endif ; mmsize == 16 ++ PALIGNR m_dith, m_dith, 3, m0 ++.no_rot: ++%if mmsize == 16 ++ punpcklbw m_dith, m6 ++%ifdef ARCH_X86_64 ++ punpcklwd m8, m_dith, m6 ++ pslld m8, 12 ++%else ; x86-32 ++ punpcklwd m5, m_dith, m6 ++ pslld m5, 12 ++%endif ; x86-32/64 ++ punpckhwd m_dith, m6 ++ pslld m_dith, 12 ++%ifdef ARCH_X86_32 ++ mova [rsp+ 0], m5 ++ mova [rsp+16], m_dith ++%endif ++%else ; mmsize == 8 ++ punpcklbw m5, m_dith, m6 ++ punpckhbw m_dith, m6 ++ punpcklwd m4, m5, m6 ++ punpckhwd m5, m6 ++ punpcklwd m3, m_dith, m6 ++ punpckhwd m_dith, m6 ++ pslld m4, 12 ++ pslld m5, 12 ++ pslld m3, 12 ++ pslld m_dith, 12 ++ mova [rsp+ 0], m4 ++ mova [rsp+ 8], m5 ++ mova [rsp+16], m3 ++ mova [rsp+24], m_dith ++%endif ; mmsize == 8/16 ++%endif ; %1 == 8 ++ ++ xor r5, r5 ++ ++.pixelloop: ++%assign %%i 0 ++ ; the rep here is for the 8bit output mmx case, where dither covers ++ ; 8 pixels but we can only handle 2 pixels per register, and thus 4 ++ ; pixels per iteration. In order to not have to keep track of where ++ ; we are w.r.t. dithering, we unroll the mmx/8bit loop x2. ++%if %1 == 8 ++%rep 16/mmsize ++%endif ; %1 == 8 ++ ++%if %1 == 8 ++%ifdef ARCH_X86_32 ++ mova m2, [rsp+mmsize*(0+%%i)] ++ mova m1, [rsp+mmsize*(1+%%i)] ++%else ; x86-64 ++ mova m2, m8 ++ mova m1, m_dith ++%endif ; x86-32/64 ++%else ; %1 == 9/10/16 ++ mova m1, [yuv2yuvX_%1_start] ++ mova m2, m1 ++%endif ; %1 == 8/9/10/16 ++ movsx cntr_reg, r1m ++.filterloop_ %+ %%i: ++ ; input pixels ++ mov r6, [r2+gprsize*cntr_reg-2*gprsize] ++%if %1 == 16 ++ mova m3, [r6+r5*4] ++ mova m5, [r6+r5*4+mmsize] ++%else ; %1 == 8/9/10 ++ mova m3, [r6+r5*2] ++%endif ; %1 == 8/9/10/16 ++ mov r6, [r2+gprsize*cntr_reg-gprsize] ++%if %1 == 16 ++ mova m4, [r6+r5*4] ++ mova m6, [r6+r5*4+mmsize] ++%else ; %1 == 8/9/10 ++ mova m4, [r6+r5*2] ++%endif ; %1 == 8/9/10/16 ++ ++ ; coefficients ++ movd m0, [r0+2*cntr_reg-4]; coeff[0], coeff[1] ++%if %1 == 16 ++ pshuflw m7, m0, 0 ; coeff[0] ++ pshuflw m0, m0, 0x55 ; coeff[1] ++ pmovsxwd m7, m7 ; word -> dword ++ pmovsxwd m0, m0 ; word -> dword ++ ++ pmulld m3, m7 ++ pmulld m5, m7 ++ pmulld m4, m0 ++ pmulld m6, m0 ++ ++ paddd m2, m3 ++ paddd m1, m5 ++ paddd m2, m4 ++ paddd m1, m6 ++%else ; %1 == 10/9/8 ++ punpcklwd m5, m3, m4 ++ punpckhwd m3, m4 ++ SPLATD m0, m0 ++ ++ pmaddwd m5, m0 ++ pmaddwd m3, m0 ++ ++ paddd m2, m5 ++ paddd m1, m3 ++%endif ; %1 == 8/9/10/16 ++ ++ sub cntr_reg, 2 ++ jg .filterloop_ %+ %%i ++ ++%if %1 == 16 ++ psrad m2, 31 - %1 ++ psrad m1, 31 - %1 ++%else ; %1 == 10/9/8 ++ psrad m2, 27 - %1 ++ psrad m1, 27 - %1 ++%endif ; %1 == 8/9/10/16 ++ ++%if %1 == 8 ++ packssdw m2, m1 ++ packuswb m2, m2 ++ movh [r3+r5*1], m2 ++%else ; %1 == 9/10/16 ++%if %1 == 16 ++ packssdw m2, m1 ++ paddw m2, [minshort] ++%else ; %1 == 9/10 ++%if cpuflag(sse4) ++ packusdw m2, m1 ++%else ; mmx2/sse2 ++ packssdw m2, m1 ++ pmaxsw m2, m6 ++%endif ; mmx2/sse2/sse4/avx ++ pminsw m2, [yuv2yuvX_%1_upper] ++%endif ; %1 == 9/10/16 ++ mova [r3+r5*2], m2 ++%endif ; %1 == 8/9/10/16 ++ ++ add r5, mmsize/2 ++ sub r4d, mmsize/2 ++%if %1 == 8 ++%assign %%i %%i+2 ++%endrep ++%endif ; %1 == 8 ++ jg .pixelloop ++ ++%if %1 == 8 ++%ifdef ARCH_X86_32 ++ ADD rsp, pad ++ RET ++%else ; x86-64 ++ REP_RET ++%endif ; x86-32/64 ++%else ; %1 == 9/10/16 ++ REP_RET ++%endif ; %1 == 8/9/10/16 ++%endmacro ++ ++%define PALIGNR PALIGNR_MMX ++%ifdef ARCH_X86_32 ++INIT_MMX mmx2 ++yuv2planeX_fn 8, 0, 7 ++yuv2planeX_fn 9, 0, 5 ++yuv2planeX_fn 10, 0, 5 ++%endif ++ ++INIT_XMM sse2 ++yuv2planeX_fn 8, 10, 7 ++yuv2planeX_fn 9, 7, 5 ++yuv2planeX_fn 10, 7, 5 ++ ++%define PALIGNR PALIGNR_SSSE3 ++INIT_XMM sse4 ++yuv2planeX_fn 8, 10, 7 ++yuv2planeX_fn 9, 7, 5 ++yuv2planeX_fn 10, 7, 5 ++yuv2planeX_fn 16, 8, 5 ++ ++%ifdef HAVE_AVX ++INIT_XMM avx ++yuv2planeX_fn 8, 10, 7 ++yuv2planeX_fn 9, 7, 5 ++yuv2planeX_fn 10, 7, 5 ++%endif ++ ++; %1=outout-bpc, %2=alignment (u/a) ++%macro yuv2plane1_mainloop 2 ++.loop_%2: ++%if %1 == 8 ++ paddsw m0, m2, [r0+r2*2+mmsize*0] ++ paddsw m1, m3, [r0+r2*2+mmsize*1] ++ psraw m0, 7 ++ psraw m1, 7 ++ packuswb m0, m1 ++ mov%2 [r1+r2], m0 ++%elif %1 == 16 ++ paddd m0, m4, [r0+r2*4+mmsize*0] ++ paddd m1, m4, [r0+r2*4+mmsize*1] ++ paddd m2, m4, [r0+r2*4+mmsize*2] ++ paddd m3, m4, [r0+r2*4+mmsize*3] ++ psrad m0, 3 ++ psrad m1, 3 ++ psrad m2, 3 ++ psrad m3, 3 ++%if cpuflag(sse4) ; avx/sse4 ++ packusdw m0, m1 ++ packusdw m2, m3 ++%else ; mmx/sse2 ++ packssdw m0, m1 ++ packssdw m2, m3 ++ paddw m0, m5 ++ paddw m2, m5 ++%endif ; mmx/sse2/sse4/avx ++ mov%2 [r1+r2*2], m0 ++ mov%2 [r1+r2*2+mmsize], m2 ++%else ++ paddsw m0, m2, [r0+r2*2+mmsize*0] ++ paddsw m1, m2, [r0+r2*2+mmsize*1] ++ psraw m0, 15 - %1 ++ psraw m1, 15 - %1 ++ pmaxsw m0, m4 ++ pmaxsw m1, m4 ++ pminsw m0, m3 ++ pminsw m1, m3 ++ mov%2 [r1+r2*2], m0 ++ mov%2 [r1+r2*2+mmsize], m1 ++%endif ++ add r2, mmsize ++ jl .loop_%2 ++%endmacro ++ ++%macro yuv2plane1_fn 3 ++cglobal yuv2plane1_%1, %3, %3, %2 ++ add r2, mmsize - 1 ++ and r2, ~(mmsize - 1) ++%if %1 == 8 ++ add r1, r2 ++%else ; %1 != 8 ++ lea r1, [r1+r2*2] ++%endif ; %1 == 8 ++%if %1 == 16 ++ lea r0, [r0+r2*4] ++%else ; %1 != 16 ++ lea r0, [r0+r2*2] ++%endif ; %1 == 16 ++ neg r2 ++ ++%if %1 == 8 ++ pxor m4, m4 ; zero ++ ++ ; create registers holding dither ++ movq m3, [r3] ; dither ++ test r4d, r4d ++ jz .no_rot ++%if mmsize == 16 ++ punpcklqdq m3, m3 ++%endif ; mmsize == 16 ++ PALIGNR_MMX m3, m3, 3, m2 ++.no_rot: ++%if mmsize == 8 ++ mova m2, m3 ++ punpckhbw m3, m4 ; byte->word ++ punpcklbw m2, m4 ; byte->word ++%else ++ punpcklbw m3, m4 ++ mova m2, m3 ++%endif ++%elif %1 == 9 ++ pxor m4, m4 ++ mova m3, [pw_512] ++ mova m2, [pw_32] ++%elif %1 == 10 ++ pxor m4, m4 ++ mova m3, [pw_1024] ++ mova m2, [pw_16] ++%else ; %1 == 16 ++%if cpuflag(sse4) ; sse4/avx ++ mova m4, [pd_4] ++%else ; mmx/sse2 ++ mova m4, [pd_4min0x40000] ++ mova m5, [minshort] ++%endif ; mmx/sse2/sse4/avx ++%endif ; %1 == .. ++ ++ ; actual pixel scaling ++%if mmsize == 8 ++ yuv2plane1_mainloop %1, a ++%else ; mmsize == 16 ++ test r1, 15 ++ jnz .unaligned ++ yuv2plane1_mainloop %1, a ++ REP_RET ++.unaligned: ++ yuv2plane1_mainloop %1, u ++%endif ; mmsize == 8/16 ++ REP_RET ++%endmacro ++ ++%ifdef ARCH_X86_32 ++INIT_MMX mmx ++yuv2plane1_fn 8, 0, 5 ++yuv2plane1_fn 16, 0, 3 ++ ++INIT_MMX mmx2 ++yuv2plane1_fn 9, 0, 3 ++yuv2plane1_fn 10, 0, 3 ++%endif ++ ++INIT_XMM sse2 ++yuv2plane1_fn 8, 5, 5 ++yuv2plane1_fn 9, 5, 3 ++yuv2plane1_fn 10, 5, 3 ++yuv2plane1_fn 16, 6, 3 ++ ++INIT_XMM sse4 ++yuv2plane1_fn 16, 5, 3 ++ ++%ifdef HAVE_AVX ++INIT_XMM avx ++yuv2plane1_fn 8, 5, 5 ++yuv2plane1_fn 9, 5, 3 ++yuv2plane1_fn 10, 5, 3 ++yuv2plane1_fn 16, 5, 3 ++%endif +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/rgb2rgb.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/rgb2rgb.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/rgb2rgb.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/rgb2rgb.c 2012-05-14 14:08:55.459362623 +0200 +@@ -0,0 +1,141 @@ ++/* ++ * software RGB to RGB converter ++ * pluralize by software PAL8 to RGB converter ++ * software YUV to YUV converter ++ * software YUV to RGB converter ++ * Written by Nick Kurshev. ++ * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at) ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#include "config.h" ++#include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" ++#include "libavutil/bswap.h" ++#include "libswscale/rgb2rgb.h" ++#include "libswscale/swscale.h" ++#include "libswscale/swscale_internal.h" ++ ++DECLARE_ASM_CONST(8, uint64_t, mmx_ff) = 0x00000000000000FFULL; ++DECLARE_ASM_CONST(8, uint64_t, mmx_null) = 0x0000000000000000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mmx_one) = 0xFFFFFFFFFFFFFFFFULL; ++DECLARE_ASM_CONST(8, uint64_t, mask32b) = 0x000000FF000000FFULL; ++DECLARE_ASM_CONST(8, uint64_t, mask32g) = 0x0000FF000000FF00ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask32r) = 0x00FF000000FF0000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask32a) = 0xFF000000FF000000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask32) = 0x00FFFFFF00FFFFFFULL; ++DECLARE_ASM_CONST(8, uint64_t, mask3216br) = 0x00F800F800F800F8ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask3216g) = 0x0000FC000000FC00ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask3215g) = 0x0000F8000000F800ULL; ++DECLARE_ASM_CONST(8, uint64_t, mul3216) = 0x2000000420000004ULL; ++DECLARE_ASM_CONST(8, uint64_t, mul3215) = 0x2000000820000008ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24b) = 0x00FF0000FF0000FFULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24g) = 0xFF0000FF0000FF00ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24r) = 0x0000FF0000FF0000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24l) = 0x0000000000FFFFFFULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24h) = 0x0000FFFFFF000000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24hh) = 0xffff000000000000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24hhh) = 0xffffffff00000000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask24hhhh) = 0xffffffffffff0000ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask15b) = 0x001F001F001F001FULL; /* 00000000 00011111 xxB */ ++DECLARE_ASM_CONST(8, uint64_t, mask15rg) = 0x7FE07FE07FE07FE0ULL; /* 01111111 11100000 RGx */ ++DECLARE_ASM_CONST(8, uint64_t, mask15s) = 0xFFE0FFE0FFE0FFE0ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask15g) = 0x03E003E003E003E0ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask15r) = 0x7C007C007C007C00ULL; ++#define mask16b mask15b ++DECLARE_ASM_CONST(8, uint64_t, mask16g) = 0x07E007E007E007E0ULL; ++DECLARE_ASM_CONST(8, uint64_t, mask16r) = 0xF800F800F800F800ULL; ++DECLARE_ASM_CONST(8, uint64_t, red_16mask) = 0x0000f8000000f800ULL; ++DECLARE_ASM_CONST(8, uint64_t, green_16mask) = 0x000007e0000007e0ULL; ++DECLARE_ASM_CONST(8, uint64_t, blue_16mask) = 0x0000001f0000001fULL; ++DECLARE_ASM_CONST(8, uint64_t, red_15mask) = 0x00007c0000007c00ULL; ++DECLARE_ASM_CONST(8, uint64_t, green_15mask) = 0x000003e0000003e0ULL; ++DECLARE_ASM_CONST(8, uint64_t, blue_15mask) = 0x0000001f0000001fULL; ++DECLARE_ASM_CONST(8, uint64_t, mul15_mid) = 0x4200420042004200ULL; ++DECLARE_ASM_CONST(8, uint64_t, mul15_hi) = 0x0210021002100210ULL; ++DECLARE_ASM_CONST(8, uint64_t, mul16_mid) = 0x2080208020802080ULL; ++ ++#define RGB2YUV_SHIFT 8 ++#define BY ((int)( 0.098*(1<RGB16 original by Strepto/Astral ++ ported to gcc & bugfixed : A'rpi ++ MMX2, 3DNOW optimization by Nick Kurshev ++ 32-bit C version, and and&add trick by Michael Niedermayer ++*/ ++ ++void rgb2rgb_init_x86(void) ++{ ++ int cpu_flags = av_get_cpu_flags(); ++ ++ if (cpu_flags & AV_CPU_FLAG_MMX) ++ rgb2rgb_init_MMX(); ++ if (HAVE_AMD3DNOW && cpu_flags & AV_CPU_FLAG_3DNOW) ++ rgb2rgb_init_3DNOW(); ++ if (HAVE_MMX2 && cpu_flags & AV_CPU_FLAG_MMX2) ++ rgb2rgb_init_MMX2(); ++ if (HAVE_SSE && cpu_flags & AV_CPU_FLAG_SSE2) ++ rgb2rgb_init_SSE2(); ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/rgb2rgb_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/rgb2rgb_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/rgb2rgb_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/rgb2rgb_template.c 2012-05-14 14:08:55.470362845 +0200 +@@ -0,0 +1,2595 @@ ++/* ++ * software RGB to RGB converter ++ * pluralize by software PAL8 to RGB converter ++ * software YUV to YUV converter ++ * software YUV to RGB converter ++ * Written by Nick Kurshev. ++ * palette & YUV & runtime CPU stuff by Michael (michaelni@gmx.at) ++ * lot of big-endian byte order fixes by Alex Beregszaszi ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++ ++#undef PREFETCH ++#undef MOVNTQ ++#undef EMMS ++#undef SFENCE ++#undef PAVGB ++ ++#if COMPILE_TEMPLATE_AMD3DNOW ++#define PREFETCH "prefetch" ++#define PAVGB "pavgusb" ++#elif COMPILE_TEMPLATE_MMX2 ++#define PREFETCH "prefetchnta" ++#define PAVGB "pavgb" ++#else ++#define PREFETCH " # nop" ++#endif ++ ++#if COMPILE_TEMPLATE_AMD3DNOW ++/* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ ++#define EMMS "femms" ++#else ++#define EMMS "emms" ++#endif ++ ++#if COMPILE_TEMPLATE_MMX2 ++#define MOVNTQ "movntq" ++#define SFENCE "sfence" ++#else ++#define MOVNTQ "movq" ++#define SFENCE " # nop" ++#endif ++ ++#if !COMPILE_TEMPLATE_SSE2 ++ ++#if !COMPILE_TEMPLATE_AMD3DNOW ++ ++static inline void RENAME(rgb24tobgr32)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ uint8_t *dest = dst; ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ mm_end = end - 23; ++ __asm__ volatile("movq %0, %%mm7"::"m"(mask32a):"memory"); ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "punpckldq 3%1, %%mm0 \n\t" ++ "movd 6%1, %%mm1 \n\t" ++ "punpckldq 9%1, %%mm1 \n\t" ++ "movd 12%1, %%mm2 \n\t" ++ "punpckldq 15%1, %%mm2 \n\t" ++ "movd 18%1, %%mm3 \n\t" ++ "punpckldq 21%1, %%mm3 \n\t" ++ "por %%mm7, %%mm0 \n\t" ++ "por %%mm7, %%mm1 \n\t" ++ "por %%mm7, %%mm2 \n\t" ++ "por %%mm7, %%mm3 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ MOVNTQ" %%mm1, 8%0 \n\t" ++ MOVNTQ" %%mm2, 16%0 \n\t" ++ MOVNTQ" %%mm3, 24%0" ++ :"=m"(*dest) ++ :"m"(*s) ++ :"memory"); ++ dest += 32; ++ s += 24; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ *dest++ = *s++; ++ *dest++ = *s++; ++ *dest++ = *s++; ++ *dest++ = 255; ++ } ++} ++ ++#define STORE_BGR24_MMX \ ++ "psrlq $8, %%mm2 \n\t" \ ++ "psrlq $8, %%mm3 \n\t" \ ++ "psrlq $8, %%mm6 \n\t" \ ++ "psrlq $8, %%mm7 \n\t" \ ++ "pand "MANGLE(mask24l)", %%mm0\n\t" \ ++ "pand "MANGLE(mask24l)", %%mm1\n\t" \ ++ "pand "MANGLE(mask24l)", %%mm4\n\t" \ ++ "pand "MANGLE(mask24l)", %%mm5\n\t" \ ++ "pand "MANGLE(mask24h)", %%mm2\n\t" \ ++ "pand "MANGLE(mask24h)", %%mm3\n\t" \ ++ "pand "MANGLE(mask24h)", %%mm6\n\t" \ ++ "pand "MANGLE(mask24h)", %%mm7\n\t" \ ++ "por %%mm2, %%mm0 \n\t" \ ++ "por %%mm3, %%mm1 \n\t" \ ++ "por %%mm6, %%mm4 \n\t" \ ++ "por %%mm7, %%mm5 \n\t" \ ++ \ ++ "movq %%mm1, %%mm2 \n\t" \ ++ "movq %%mm4, %%mm3 \n\t" \ ++ "psllq $48, %%mm2 \n\t" \ ++ "psllq $32, %%mm3 \n\t" \ ++ "pand "MANGLE(mask24hh)", %%mm2\n\t" \ ++ "pand "MANGLE(mask24hhh)", %%mm3\n\t" \ ++ "por %%mm2, %%mm0 \n\t" \ ++ "psrlq $16, %%mm1 \n\t" \ ++ "psrlq $32, %%mm4 \n\t" \ ++ "psllq $16, %%mm5 \n\t" \ ++ "por %%mm3, %%mm1 \n\t" \ ++ "pand "MANGLE(mask24hhhh)", %%mm5\n\t" \ ++ "por %%mm5, %%mm4 \n\t" \ ++ \ ++ MOVNTQ" %%mm0, %0 \n\t" \ ++ MOVNTQ" %%mm1, 8%0 \n\t" \ ++ MOVNTQ" %%mm4, 16%0" ++ ++ ++static inline void RENAME(rgb32tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ uint8_t *dest = dst; ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ mm_end = end - 31; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movq %1, %%mm0 \n\t" ++ "movq 8%1, %%mm1 \n\t" ++ "movq 16%1, %%mm4 \n\t" ++ "movq 24%1, %%mm5 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "movq %%mm4, %%mm6 \n\t" ++ "movq %%mm5, %%mm7 \n\t" ++ STORE_BGR24_MMX ++ :"=m"(*dest) ++ :"m"(*s) ++ :"memory"); ++ dest += 24; ++ s += 32; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ *dest++ = *s++; ++ *dest++ = *s++; ++ *dest++ = *s++; ++ s++; ++ } ++} ++ ++/* ++ original by Strepto/Astral ++ ported to gcc & bugfixed: A'rpi ++ MMX2, 3DNOW optimization by Nick Kurshev ++ 32-bit C version, and and&add trick by Michael Niedermayer ++*/ ++static inline void RENAME(rgb15to16)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ register const uint8_t* s=src; ++ register uint8_t* d=dst; ++ register const uint8_t *end; ++ const uint8_t *mm_end; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s)); ++ __asm__ volatile("movq %0, %%mm4"::"m"(mask15s)); ++ mm_end = end - 15; ++ while (s>1)&0x7FE07FE0) | (x&0x001F001F); ++ s+=4; ++ d+=4; ++ } ++ if (s < end) { ++ register uint16_t x= *((const uint16_t*)s); ++ *((uint16_t *)d) = ((x>>1)&0x7FE0) | (x&0x001F); ++ } ++} ++ ++static inline void RENAME(rgb32to16)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ mm_end = end - 15; ++#if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster) ++ __asm__ volatile( ++ "movq %3, %%mm5 \n\t" ++ "movq %4, %%mm6 \n\t" ++ "movq %5, %%mm7 \n\t" ++ "jmp 2f \n\t" ++ ".p2align 4 \n\t" ++ "1: \n\t" ++ PREFETCH" 32(%1) \n\t" ++ "movd (%1), %%mm0 \n\t" ++ "movd 4(%1), %%mm3 \n\t" ++ "punpckldq 8(%1), %%mm0 \n\t" ++ "punpckldq 12(%1), %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "pand %%mm6, %%mm0 \n\t" ++ "pand %%mm6, %%mm3 \n\t" ++ "pmaddwd %%mm7, %%mm0 \n\t" ++ "pmaddwd %%mm7, %%mm3 \n\t" ++ "pand %%mm5, %%mm1 \n\t" ++ "pand %%mm5, %%mm4 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "psrld $5, %%mm0 \n\t" ++ "pslld $11, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, (%0) \n\t" ++ "add $16, %1 \n\t" ++ "add $8, %0 \n\t" ++ "2: \n\t" ++ "cmp %2, %1 \n\t" ++ " jb 1b \n\t" ++ : "+r" (d), "+r"(s) ++ : "r" (mm_end), "m" (mask3216g), "m" (mask3216br), "m" (mul3216) ++ ); ++#else ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_16mask),"m"(green_16mask)); ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 4%1, %%mm3 \n\t" ++ "punpckldq 8%1, %%mm0 \n\t" ++ "punpckldq 12%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psrlq $3, %%mm0 \n\t" ++ "psrlq $3, %%mm3 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %2, %%mm3 \n\t" ++ "psrlq $5, %%mm1 \n\t" ++ "psrlq $5, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $8, %%mm2 \n\t" ++ "psrlq $8, %%mm5 \n\t" ++ "pand %%mm7, %%mm2 \n\t" ++ "pand %%mm7, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); ++ d += 4; ++ s += 16; ++ } ++#endif ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register int rgb = *(const uint32_t*)s; s += 4; ++ *d++ = ((rgb&0xFF)>>3) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>8); ++ } ++} ++ ++static inline void RENAME(rgb32tobgr16)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_16mask),"m"(green_16mask)); ++ mm_end = end - 15; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 4%1, %%mm3 \n\t" ++ "punpckldq 8%1, %%mm0 \n\t" ++ "punpckldq 12%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psllq $8, %%mm0 \n\t" ++ "psllq $8, %%mm3 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "psrlq $5, %%mm1 \n\t" ++ "psrlq $5, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $19, %%mm2 \n\t" ++ "psrlq $19, %%mm5 \n\t" ++ "pand %2, %%mm2 \n\t" ++ "pand %2, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); ++ d += 4; ++ s += 16; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register int rgb = *(const uint32_t*)s; s += 4; ++ *d++ = ((rgb&0xF8)<<8) + ((rgb&0xFC00)>>5) + ((rgb&0xF80000)>>19); ++ } ++} ++ ++static inline void RENAME(rgb32to15)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ mm_end = end - 15; ++#if 1 //is faster only if multiplies are reasonably fast (FIXME figure out on which CPUs this is faster, on Athlon it is slightly faster) ++ __asm__ volatile( ++ "movq %3, %%mm5 \n\t" ++ "movq %4, %%mm6 \n\t" ++ "movq %5, %%mm7 \n\t" ++ "jmp 2f \n\t" ++ ".p2align 4 \n\t" ++ "1: \n\t" ++ PREFETCH" 32(%1) \n\t" ++ "movd (%1), %%mm0 \n\t" ++ "movd 4(%1), %%mm3 \n\t" ++ "punpckldq 8(%1), %%mm0 \n\t" ++ "punpckldq 12(%1), %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "pand %%mm6, %%mm0 \n\t" ++ "pand %%mm6, %%mm3 \n\t" ++ "pmaddwd %%mm7, %%mm0 \n\t" ++ "pmaddwd %%mm7, %%mm3 \n\t" ++ "pand %%mm5, %%mm1 \n\t" ++ "pand %%mm5, %%mm4 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "psrld $6, %%mm0 \n\t" ++ "pslld $10, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, (%0) \n\t" ++ "add $16, %1 \n\t" ++ "add $8, %0 \n\t" ++ "2: \n\t" ++ "cmp %2, %1 \n\t" ++ " jb 1b \n\t" ++ : "+r" (d), "+r"(s) ++ : "r" (mm_end), "m" (mask3215g), "m" (mask3216br), "m" (mul3215) ++ ); ++#else ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_15mask),"m"(green_15mask)); ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 4%1, %%mm3 \n\t" ++ "punpckldq 8%1, %%mm0 \n\t" ++ "punpckldq 12%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psrlq $3, %%mm0 \n\t" ++ "psrlq $3, %%mm3 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %2, %%mm3 \n\t" ++ "psrlq $6, %%mm1 \n\t" ++ "psrlq $6, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $9, %%mm2 \n\t" ++ "psrlq $9, %%mm5 \n\t" ++ "pand %%mm7, %%mm2 \n\t" ++ "pand %%mm7, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); ++ d += 4; ++ s += 16; ++ } ++#endif ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register int rgb = *(const uint32_t*)s; s += 4; ++ *d++ = ((rgb&0xFF)>>3) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>9); ++ } ++} ++ ++static inline void RENAME(rgb32tobgr15)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_15mask),"m"(green_15mask)); ++ mm_end = end - 15; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 4%1, %%mm3 \n\t" ++ "punpckldq 8%1, %%mm0 \n\t" ++ "punpckldq 12%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psllq $7, %%mm0 \n\t" ++ "psllq $7, %%mm3 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "psrlq $6, %%mm1 \n\t" ++ "psrlq $6, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $19, %%mm2 \n\t" ++ "psrlq $19, %%mm5 \n\t" ++ "pand %2, %%mm2 \n\t" ++ "pand %2, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); ++ d += 4; ++ s += 16; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register int rgb = *(const uint32_t*)s; s += 4; ++ *d++ = ((rgb&0xF8)<<7) + ((rgb&0xF800)>>6) + ((rgb&0xF80000)>>19); ++ } ++} ++ ++static inline void RENAME(rgb24tobgr16)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_16mask),"m"(green_16mask)); ++ mm_end = end - 11; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 3%1, %%mm3 \n\t" ++ "punpckldq 6%1, %%mm0 \n\t" ++ "punpckldq 9%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psrlq $3, %%mm0 \n\t" ++ "psrlq $3, %%mm3 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %2, %%mm3 \n\t" ++ "psrlq $5, %%mm1 \n\t" ++ "psrlq $5, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $8, %%mm2 \n\t" ++ "psrlq $8, %%mm5 \n\t" ++ "pand %%mm7, %%mm2 \n\t" ++ "pand %%mm7, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); ++ d += 4; ++ s += 12; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ const int b = *s++; ++ const int g = *s++; ++ const int r = *s++; ++ *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); ++ } ++} ++ ++static inline void RENAME(rgb24to16)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_16mask),"m"(green_16mask)); ++ mm_end = end - 15; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 3%1, %%mm3 \n\t" ++ "punpckldq 6%1, %%mm0 \n\t" ++ "punpckldq 9%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psllq $8, %%mm0 \n\t" ++ "psllq $8, %%mm3 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "psrlq $5, %%mm1 \n\t" ++ "psrlq $5, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $19, %%mm2 \n\t" ++ "psrlq $19, %%mm5 \n\t" ++ "pand %2, %%mm2 \n\t" ++ "pand %2, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_16mask):"memory"); ++ d += 4; ++ s += 12; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ const int r = *s++; ++ const int g = *s++; ++ const int b = *s++; ++ *d++ = (b>>3) | ((g&0xFC)<<3) | ((r&0xF8)<<8); ++ } ++} ++ ++static inline void RENAME(rgb24tobgr15)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_15mask),"m"(green_15mask)); ++ mm_end = end - 11; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 3%1, %%mm3 \n\t" ++ "punpckldq 6%1, %%mm0 \n\t" ++ "punpckldq 9%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psrlq $3, %%mm0 \n\t" ++ "psrlq $3, %%mm3 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %2, %%mm3 \n\t" ++ "psrlq $6, %%mm1 \n\t" ++ "psrlq $6, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $9, %%mm2 \n\t" ++ "psrlq $9, %%mm5 \n\t" ++ "pand %%mm7, %%mm2 \n\t" ++ "pand %%mm7, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); ++ d += 4; ++ s += 12; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ const int b = *s++; ++ const int g = *s++; ++ const int r = *s++; ++ *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); ++ } ++} ++ ++static inline void RENAME(rgb24to15)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint8_t *s = src; ++ const uint8_t *end; ++ const uint8_t *mm_end; ++ uint16_t *d = (uint16_t *)dst; ++ end = s + src_size; ++ __asm__ volatile(PREFETCH" %0"::"m"(*src):"memory"); ++ __asm__ volatile( ++ "movq %0, %%mm7 \n\t" ++ "movq %1, %%mm6 \n\t" ++ ::"m"(red_15mask),"m"(green_15mask)); ++ mm_end = end - 15; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movd %1, %%mm0 \n\t" ++ "movd 3%1, %%mm3 \n\t" ++ "punpckldq 6%1, %%mm0 \n\t" ++ "punpckldq 9%1, %%mm3 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm3, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "psllq $7, %%mm0 \n\t" ++ "psllq $7, %%mm3 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "psrlq $6, %%mm1 \n\t" ++ "psrlq $6, %%mm4 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "psrlq $19, %%mm2 \n\t" ++ "psrlq $19, %%mm5 \n\t" ++ "pand %2, %%mm2 \n\t" ++ "pand %2, %%mm5 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ "psllq $16, %%mm3 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ MOVNTQ" %%mm0, %0 \n\t" ++ :"=m"(*d):"m"(*s),"m"(blue_15mask):"memory"); ++ d += 4; ++ s += 12; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ const int r = *s++; ++ const int g = *s++; ++ const int b = *s++; ++ *d++ = (b>>3) | ((g&0xF8)<<2) | ((r&0xF8)<<7); ++ } ++} ++ ++static inline void RENAME(rgb15tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint16_t *end; ++ const uint16_t *mm_end; ++ uint8_t *d = dst; ++ const uint16_t *s = (const uint16_t*)src; ++ end = s + src_size/2; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ mm_end = end - 7; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movq %1, %%mm0 \n\t" ++ "movq %1, %%mm1 \n\t" ++ "movq %1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "pmulhw %6, %%mm0 \n\t" ++ "pmulhw %6, %%mm1 \n\t" ++ "pmulhw %7, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "movq %%mm2, %%mm5 \n\t" ++ "punpcklwd %5, %%mm0 \n\t" ++ "punpcklwd %5, %%mm1 \n\t" ++ "punpcklwd %5, %%mm2 \n\t" ++ "punpckhwd %5, %%mm3 \n\t" ++ "punpckhwd %5, %%mm4 \n\t" ++ "punpckhwd %5, %%mm5 \n\t" ++ "psllq $8, %%mm1 \n\t" ++ "psllq $16, %%mm2 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "psllq $8, %%mm4 \n\t" ++ "psllq $16, %%mm5 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ ++ "movq %%mm0, %%mm6 \n\t" ++ "movq %%mm3, %%mm7 \n\t" ++ ++ "movq 8%1, %%mm0 \n\t" ++ "movq 8%1, %%mm1 \n\t" ++ "movq 8%1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "pmulhw %6, %%mm0 \n\t" ++ "pmulhw %6, %%mm1 \n\t" ++ "pmulhw %7, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "movq %%mm2, %%mm5 \n\t" ++ "punpcklwd %5, %%mm0 \n\t" ++ "punpcklwd %5, %%mm1 \n\t" ++ "punpcklwd %5, %%mm2 \n\t" ++ "punpckhwd %5, %%mm3 \n\t" ++ "punpckhwd %5, %%mm4 \n\t" ++ "punpckhwd %5, %%mm5 \n\t" ++ "psllq $8, %%mm1 \n\t" ++ "psllq $16, %%mm2 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "psllq $8, %%mm4 \n\t" ++ "psllq $16, %%mm5 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ ++ :"=m"(*d) ++ :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r),"m"(mmx_null),"m"(mul15_mid),"m"(mul15_hi) ++ :"memory"); ++ /* borrowed 32 to 24 */ ++ __asm__ volatile( ++ "movq %%mm0, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "movq %%mm6, %%mm0 \n\t" ++ "movq %%mm7, %%mm1 \n\t" ++ ++ "movq %%mm4, %%mm6 \n\t" ++ "movq %%mm5, %%mm7 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ ++ STORE_BGR24_MMX ++ ++ :"=m"(*d) ++ :"m"(*s) ++ :"memory"); ++ d += 24; ++ s += 8; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register uint16_t bgr; ++ bgr = *s++; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); ++ } ++} ++ ++static inline void RENAME(rgb16tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint16_t *end; ++ const uint16_t *mm_end; ++ uint8_t *d = (uint8_t *)dst; ++ const uint16_t *s = (const uint16_t *)src; ++ end = s + src_size/2; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ mm_end = end - 7; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movq %1, %%mm0 \n\t" ++ "movq %1, %%mm1 \n\t" ++ "movq %1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "psrlq $1, %%mm2 \n\t" ++ "pmulhw %6, %%mm0 \n\t" ++ "pmulhw %8, %%mm1 \n\t" ++ "pmulhw %7, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "movq %%mm2, %%mm5 \n\t" ++ "punpcklwd %5, %%mm0 \n\t" ++ "punpcklwd %5, %%mm1 \n\t" ++ "punpcklwd %5, %%mm2 \n\t" ++ "punpckhwd %5, %%mm3 \n\t" ++ "punpckhwd %5, %%mm4 \n\t" ++ "punpckhwd %5, %%mm5 \n\t" ++ "psllq $8, %%mm1 \n\t" ++ "psllq $16, %%mm2 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "psllq $8, %%mm4 \n\t" ++ "psllq $16, %%mm5 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ ++ "movq %%mm0, %%mm6 \n\t" ++ "movq %%mm3, %%mm7 \n\t" ++ ++ "movq 8%1, %%mm0 \n\t" ++ "movq 8%1, %%mm1 \n\t" ++ "movq 8%1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "psrlq $1, %%mm2 \n\t" ++ "pmulhw %6, %%mm0 \n\t" ++ "pmulhw %8, %%mm1 \n\t" ++ "pmulhw %7, %%mm2 \n\t" ++ "movq %%mm0, %%mm3 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "movq %%mm2, %%mm5 \n\t" ++ "punpcklwd %5, %%mm0 \n\t" ++ "punpcklwd %5, %%mm1 \n\t" ++ "punpcklwd %5, %%mm2 \n\t" ++ "punpckhwd %5, %%mm3 \n\t" ++ "punpckhwd %5, %%mm4 \n\t" ++ "punpckhwd %5, %%mm5 \n\t" ++ "psllq $8, %%mm1 \n\t" ++ "psllq $16, %%mm2 \n\t" ++ "por %%mm1, %%mm0 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "psllq $8, %%mm4 \n\t" ++ "psllq $16, %%mm5 \n\t" ++ "por %%mm4, %%mm3 \n\t" ++ "por %%mm5, %%mm3 \n\t" ++ :"=m"(*d) ++ :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mmx_null),"m"(mul15_mid),"m"(mul15_hi),"m"(mul16_mid) ++ :"memory"); ++ /* borrowed 32 to 24 */ ++ __asm__ volatile( ++ "movq %%mm0, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "movq %%mm6, %%mm0 \n\t" ++ "movq %%mm7, %%mm1 \n\t" ++ ++ "movq %%mm4, %%mm6 \n\t" ++ "movq %%mm5, %%mm7 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ ++ STORE_BGR24_MMX ++ ++ :"=m"(*d) ++ :"m"(*s) ++ :"memory"); ++ d += 24; ++ s += 8; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register uint16_t bgr; ++ bgr = *s++; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); ++ } ++} ++ ++/* ++ * mm0 = 00 B3 00 B2 00 B1 00 B0 ++ * mm1 = 00 G3 00 G2 00 G1 00 G0 ++ * mm2 = 00 R3 00 R2 00 R1 00 R0 ++ * mm6 = FF FF FF FF FF FF FF FF ++ * mm7 = 00 00 00 00 00 00 00 00 ++ */ ++#define PACK_RGB32 \ ++ "packuswb %%mm7, %%mm0 \n\t" /* 00 00 00 00 B3 B2 B1 B0 */ \ ++ "packuswb %%mm7, %%mm1 \n\t" /* 00 00 00 00 G3 G2 G1 G0 */ \ ++ "packuswb %%mm7, %%mm2 \n\t" /* 00 00 00 00 R3 R2 R1 R0 */ \ ++ "punpcklbw %%mm1, %%mm0 \n\t" /* G3 B3 G2 B2 G1 B1 G0 B0 */ \ ++ "punpcklbw %%mm6, %%mm2 \n\t" /* FF R3 FF R2 FF R1 FF R0 */ \ ++ "movq %%mm0, %%mm3 \n\t" \ ++ "punpcklwd %%mm2, %%mm0 \n\t" /* FF R1 G1 B1 FF R0 G0 B0 */ \ ++ "punpckhwd %%mm2, %%mm3 \n\t" /* FF R3 G3 B3 FF R2 G2 B2 */ \ ++ MOVNTQ" %%mm0, %0 \n\t" \ ++ MOVNTQ" %%mm3, 8%0 \n\t" \ ++ ++static inline void RENAME(rgb15to32)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint16_t *end; ++ const uint16_t *mm_end; ++ uint8_t *d = dst; ++ const uint16_t *s = (const uint16_t *)src; ++ end = s + src_size/2; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); ++ __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory"); ++ mm_end = end - 3; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movq %1, %%mm0 \n\t" ++ "movq %1, %%mm1 \n\t" ++ "movq %1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "pmulhw %5, %%mm0 \n\t" ++ "pmulhw %5, %%mm1 \n\t" ++ "pmulhw %6, %%mm2 \n\t" ++ PACK_RGB32 ++ :"=m"(*d) ++ :"m"(*s),"m"(mask15b),"m"(mask15g),"m"(mask15r),"m"(mul15_mid),"m"(mul15_hi) ++ :"memory"); ++ d += 16; ++ s += 4; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register uint16_t bgr; ++ bgr = *s++; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x3E0)>>2) | ((bgr&0x3E0)>>7); ++ *d++ = ((bgr&0x7C00)>>7) | ((bgr&0x7C00)>>12); ++ *d++ = 255; ++ } ++} ++ ++static inline void RENAME(rgb16to32)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ const uint16_t *end; ++ const uint16_t *mm_end; ++ uint8_t *d = dst; ++ const uint16_t *s = (const uint16_t*)src; ++ end = s + src_size/2; ++ __asm__ volatile(PREFETCH" %0"::"m"(*s):"memory"); ++ __asm__ volatile("pxor %%mm7,%%mm7 \n\t":::"memory"); ++ __asm__ volatile("pcmpeqd %%mm6,%%mm6 \n\t":::"memory"); ++ mm_end = end - 3; ++ while (s < mm_end) { ++ __asm__ volatile( ++ PREFETCH" 32%1 \n\t" ++ "movq %1, %%mm0 \n\t" ++ "movq %1, %%mm1 \n\t" ++ "movq %1, %%mm2 \n\t" ++ "pand %2, %%mm0 \n\t" ++ "pand %3, %%mm1 \n\t" ++ "pand %4, %%mm2 \n\t" ++ "psllq $5, %%mm0 \n\t" ++ "psrlq $1, %%mm2 \n\t" ++ "pmulhw %5, %%mm0 \n\t" ++ "pmulhw %7, %%mm1 \n\t" ++ "pmulhw %6, %%mm2 \n\t" ++ PACK_RGB32 ++ :"=m"(*d) ++ :"m"(*s),"m"(mask16b),"m"(mask16g),"m"(mask16r),"m"(mul15_mid),"m"(mul15_hi),"m"(mul16_mid) ++ :"memory"); ++ d += 16; ++ s += 4; ++ } ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ while (s < end) { ++ register uint16_t bgr; ++ bgr = *s++; ++ *d++ = ((bgr&0x1F)<<3) | ((bgr&0x1F)>>2); ++ *d++ = ((bgr&0x7E0)>>3) | ((bgr&0x7E0)>>9); ++ *d++ = ((bgr&0xF800)>>8) | ((bgr&0xF800)>>13); ++ *d++ = 255; ++ } ++} ++ ++static inline void RENAME(shuffle_bytes_2103)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ x86_reg idx = 15 - src_size; ++ const uint8_t *s = src-idx; ++ uint8_t *d = dst-idx; ++ __asm__ volatile( ++ "test %0, %0 \n\t" ++ "jns 2f \n\t" ++ PREFETCH" (%1, %0) \n\t" ++ "movq %3, %%mm7 \n\t" ++ "pxor %4, %%mm7 \n\t" ++ "movq %%mm7, %%mm6 \n\t" ++ "pxor %5, %%mm7 \n\t" ++ ".p2align 4 \n\t" ++ "1: \n\t" ++ PREFETCH" 32(%1, %0) \n\t" ++ "movq (%1, %0), %%mm0 \n\t" ++ "movq 8(%1, %0), %%mm1 \n\t" ++# if COMPILE_TEMPLATE_MMX2 ++ "pshufw $177, %%mm0, %%mm3 \n\t" ++ "pshufw $177, %%mm1, %%mm5 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm6, %%mm3 \n\t" ++ "pand %%mm7, %%mm1 \n\t" ++ "pand %%mm6, %%mm5 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ "por %%mm5, %%mm1 \n\t" ++# else ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm6, %%mm2 \n\t" ++ "pand %%mm7, %%mm1 \n\t" ++ "pand %%mm6, %%mm4 \n\t" ++ "movq %%mm2, %%mm3 \n\t" ++ "movq %%mm4, %%mm5 \n\t" ++ "pslld $16, %%mm2 \n\t" ++ "psrld $16, %%mm3 \n\t" ++ "pslld $16, %%mm4 \n\t" ++ "psrld $16, %%mm5 \n\t" ++ "por %%mm2, %%mm0 \n\t" ++ "por %%mm4, %%mm1 \n\t" ++ "por %%mm3, %%mm0 \n\t" ++ "por %%mm5, %%mm1 \n\t" ++# endif ++ MOVNTQ" %%mm0, (%2, %0) \n\t" ++ MOVNTQ" %%mm1, 8(%2, %0) \n\t" ++ "add $16, %0 \n\t" ++ "js 1b \n\t" ++ SFENCE" \n\t" ++ EMMS" \n\t" ++ "2: \n\t" ++ : "+&r"(idx) ++ : "r" (s), "r" (d), "m" (mask32b), "m" (mask32r), "m" (mmx_one) ++ : "memory"); ++ for (; idx<15; idx+=4) { ++ register int v = *(const uint32_t *)&s[idx], g = v & 0xff00ff00; ++ v &= 0xff00ff; ++ *(uint32_t *)&d[idx] = (v>>16) + g + (v<<16); ++ } ++} ++ ++static inline void RENAME(rgb24tobgr24)(const uint8_t *src, uint8_t *dst, int src_size) ++{ ++ unsigned i; ++ x86_reg mmx_size= 23 - src_size; ++ __asm__ volatile ( ++ "test %%"REG_a", %%"REG_a" \n\t" ++ "jns 2f \n\t" ++ "movq "MANGLE(mask24r)", %%mm5 \n\t" ++ "movq "MANGLE(mask24g)", %%mm6 \n\t" ++ "movq "MANGLE(mask24b)", %%mm7 \n\t" ++ ".p2align 4 \n\t" ++ "1: \n\t" ++ PREFETCH" 32(%1, %%"REG_a") \n\t" ++ "movq (%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG ++ "movq (%1, %%"REG_a"), %%mm1 \n\t" // BGR BGR BG ++ "movq 2(%1, %%"REG_a"), %%mm2 \n\t" // R BGR BGR B ++ "psllq $16, %%mm0 \n\t" // 00 BGR BGR ++ "pand %%mm5, %%mm0 \n\t" ++ "pand %%mm6, %%mm1 \n\t" ++ "pand %%mm7, %%mm2 \n\t" ++ "por %%mm0, %%mm1 \n\t" ++ "por %%mm2, %%mm1 \n\t" ++ "movq 6(%1, %%"REG_a"), %%mm0 \n\t" // BGR BGR BG ++ MOVNTQ" %%mm1, (%2, %%"REG_a") \n\t" // RGB RGB RG ++ "movq 8(%1, %%"REG_a"), %%mm1 \n\t" // R BGR BGR B ++ "movq 10(%1, %%"REG_a"), %%mm2 \n\t" // GR BGR BGR ++ "pand %%mm7, %%mm0 \n\t" ++ "pand %%mm5, %%mm1 \n\t" ++ "pand %%mm6, %%mm2 \n\t" ++ "por %%mm0, %%mm1 \n\t" ++ "por %%mm2, %%mm1 \n\t" ++ "movq 14(%1, %%"REG_a"), %%mm0 \n\t" // R BGR BGR B ++ MOVNTQ" %%mm1, 8(%2, %%"REG_a") \n\t" // B RGB RGB R ++ "movq 16(%1, %%"REG_a"), %%mm1 \n\t" // GR BGR BGR ++ "movq 18(%1, %%"REG_a"), %%mm2 \n\t" // BGR BGR BG ++ "pand %%mm6, %%mm0 \n\t" ++ "pand %%mm7, %%mm1 \n\t" ++ "pand %%mm5, %%mm2 \n\t" ++ "por %%mm0, %%mm1 \n\t" ++ "por %%mm2, %%mm1 \n\t" ++ MOVNTQ" %%mm1, 16(%2, %%"REG_a") \n\t" ++ "add $24, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ "2: \n\t" ++ : "+a" (mmx_size) ++ : "r" (src-mmx_size), "r"(dst-mmx_size) ++ ); ++ ++ __asm__ volatile(SFENCE:::"memory"); ++ __asm__ volatile(EMMS:::"memory"); ++ ++ if (mmx_size==23) return; //finished, was multiple of 8 ++ ++ src+= src_size; ++ dst+= src_size; ++ src_size= 23-mmx_size; ++ src-= src_size; ++ dst-= src_size; ++ for (i=0; i>1; ++ for (y=0; y>1; ++ for (y=0; y>1; ++ for (y=0; y>2; ++ dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; ++ } ++ dst[2*srcWidth-1]= src[srcWidth-1]; ++ ++ dst+= dstStride; ++ ++ for (y=1; y>2; ++ dst[2*x+dstStride+2]= ( src[x+0] + 3*src[x+srcStride+1])>>2; ++ dst[2*x+dstStride+1]= ( src[x+1] + 3*src[x+srcStride ])>>2; ++ dst[2*x +2]= (3*src[x+1] + src[x+srcStride ])>>2; ++ } ++ dst[srcWidth*2 -1 ]= (3*src[srcWidth-1] + src[srcWidth-1 + srcStride])>>2; ++ dst[srcWidth*2 -1 + dstStride]= ( src[srcWidth-1] + 3*src[srcWidth-1 + srcStride])>>2; ++ ++ dst+=dstStride*2; ++ src+=srcStride; ++ } ++ ++ // last line ++ dst[0]= src[0]; ++ ++ for (x=0; x>2; ++ dst[2*x+2]= ( src[x] + 3*src[x+1])>>2; ++ } ++ dst[2*srcWidth-1]= src[srcWidth-1]; ++ ++ __asm__ volatile(EMMS" \n\t" ++ SFENCE" \n\t" ++ :::"memory"); ++} ++#endif /* COMPILE_TEMPLATE_MMX2 || COMPILE_TEMPLATE_AMD3DNOW */ ++ ++#if !COMPILE_TEMPLATE_AMD3DNOW ++/** ++ * Height should be a multiple of 2 and width should be a multiple of 16. ++ * (If this is a problem for anyone then tell me, and I will fix it.) ++ * Chrominance data is only taken from every second line, others are ignored. ++ * FIXME: Write HQ version. ++ */ ++static inline void RENAME(uyvytoyv12)(const uint8_t *src, uint8_t *ydst, uint8_t *udst, uint8_t *vdst, ++ int width, int height, ++ int lumStride, int chromStride, int srcStride) ++{ ++ int y; ++ const x86_reg chromWidth= width>>1; ++ for (y=0; y>1; ++ for (y=0; y>1); ++ uint8_t* d=dst1+dstStride1*y; ++ x=0; ++ for (;x>1); ++ uint8_t* d=dst2+dstStride2*y; ++ x=0; ++ for (;x>2); ++ const uint8_t* vp=src3+srcStride3*(y>>2); ++ uint8_t* d=dst+dstStride*y; ++ x=0; ++ for (;x>1; ++ dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1; ++ count++; ++ } ++} ++ ++#if !COMPILE_TEMPLATE_AMD3DNOW ++static void RENAME(extract_odd2)(const uint8_t *src, uint8_t *dst0, uint8_t *dst1, x86_reg count) ++{ ++ dst0+= count; ++ dst1+= count; ++ src += 4*count; ++ count= - count; ++ if(count <= -8) { ++ count += 7; ++ __asm__ volatile( ++ "pcmpeqw %%mm7, %%mm7 \n\t" ++ "psrlw $8, %%mm7 \n\t" ++ "1: \n\t" ++ "movq -28(%1, %0, 4), %%mm0 \n\t" ++ "movq -20(%1, %0, 4), %%mm1 \n\t" ++ "movq -12(%1, %0, 4), %%mm2 \n\t" ++ "movq -4(%1, %0, 4), %%mm3 \n\t" ++ "psrlw $8, %%mm0 \n\t" ++ "psrlw $8, %%mm1 \n\t" ++ "psrlw $8, %%mm2 \n\t" ++ "psrlw $8, %%mm3 \n\t" ++ "packuswb %%mm1, %%mm0 \n\t" ++ "packuswb %%mm3, %%mm2 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm3 \n\t" ++ "psrlw $8, %%mm0 \n\t" ++ "psrlw $8, %%mm2 \n\t" ++ "pand %%mm7, %%mm1 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "packuswb %%mm2, %%mm0 \n\t" ++ "packuswb %%mm3, %%mm1 \n\t" ++ MOVNTQ" %%mm0,- 7(%3, %0) \n\t" ++ MOVNTQ" %%mm1,- 7(%2, %0) \n\t" ++ "add $8, %0 \n\t" ++ " js 1b \n\t" ++ : "+r"(count) ++ : "r"(src), "r"(dst0), "r"(dst1) ++ ); ++ count -= 7; ++ } ++ src++; ++ while(count<0) { ++ dst0[count]= src[4*count+0]; ++ dst1[count]= src[4*count+2]; ++ count++; ++ } ++} ++#endif /* !COMPILE_TEMPLATE_AMD3DNOW */ ++ ++static void RENAME(extract_odd2avg)(const uint8_t *src0, const uint8_t *src1, uint8_t *dst0, uint8_t *dst1, x86_reg count) ++{ ++ dst0 += count; ++ dst1 += count; ++ src0 += 4*count; ++ src1 += 4*count; ++ count= - count; ++#ifdef PAVGB ++ if(count <= -8) { ++ count += 7; ++ __asm__ volatile( ++ "pcmpeqw %%mm7, %%mm7 \n\t" ++ "psrlw $8, %%mm7 \n\t" ++ "1: \n\t" ++ "movq -28(%1, %0, 4), %%mm0 \n\t" ++ "movq -20(%1, %0, 4), %%mm1 \n\t" ++ "movq -12(%1, %0, 4), %%mm2 \n\t" ++ "movq -4(%1, %0, 4), %%mm3 \n\t" ++ PAVGB" -28(%2, %0, 4), %%mm0 \n\t" ++ PAVGB" -20(%2, %0, 4), %%mm1 \n\t" ++ PAVGB" -12(%2, %0, 4), %%mm2 \n\t" ++ PAVGB" - 4(%2, %0, 4), %%mm3 \n\t" ++ "psrlw $8, %%mm0 \n\t" ++ "psrlw $8, %%mm1 \n\t" ++ "psrlw $8, %%mm2 \n\t" ++ "psrlw $8, %%mm3 \n\t" ++ "packuswb %%mm1, %%mm0 \n\t" ++ "packuswb %%mm3, %%mm2 \n\t" ++ "movq %%mm0, %%mm1 \n\t" ++ "movq %%mm2, %%mm3 \n\t" ++ "psrlw $8, %%mm0 \n\t" ++ "psrlw $8, %%mm2 \n\t" ++ "pand %%mm7, %%mm1 \n\t" ++ "pand %%mm7, %%mm3 \n\t" ++ "packuswb %%mm2, %%mm0 \n\t" ++ "packuswb %%mm3, %%mm1 \n\t" ++ MOVNTQ" %%mm0,- 7(%4, %0) \n\t" ++ MOVNTQ" %%mm1,- 7(%3, %0) \n\t" ++ "add $8, %0 \n\t" ++ " js 1b \n\t" ++ : "+r"(count) ++ : "r"(src0), "r"(src1), "r"(dst0), "r"(dst1) ++ ); ++ count -= 7; ++ } ++#endif ++ src0++; ++ src1++; ++ while(count<0) { ++ dst0[count]= (src0[4*count+0]+src1[4*count+0])>>1; ++ dst1[count]= (src0[4*count+2]+src1[4*count+2])>>1; ++ count++; ++ } ++} ++ ++static void RENAME(yuyvtoyuv420)(uint8_t *ydst, uint8_t *udst, uint8_t *vdst, const uint8_t *src, ++ int width, int height, ++ int lumStride, int chromStride, int srcStride) ++{ ++ int y; ++ const int chromWidth= -((-width)>>1); ++ ++ for (y=0; y>1); ++ ++ for (y=0; y>1); ++ ++ for (y=0; y>1); ++ ++ for (y=0; y ++;* ++;* This file is part of Libav. ++;* ++;* Libav is free software; you can redistribute it and/or ++;* modify it under the terms of the GNU Lesser General Public ++;* License as published by the Free Software Foundation; either ++;* version 2.1 of the License, or (at your option) any later version. ++;* ++;* Libav 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 ++;* Lesser General Public License for more details. ++;* ++;* You should have received a copy of the GNU Lesser General Public ++;* License along with Libav; if not, write to the Free Software ++;* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++;****************************************************************************** ++ ++%include "x86inc.asm" ++%include "x86util.asm" ++ ++SECTION_RODATA ++ ++max_19bit_int: times 4 dd 0x7ffff ++max_19bit_flt: times 4 dd 524287.0 ++minshort: times 8 dw 0x8000 ++unicoeff: times 4 dd 0x20000000 ++ ++SECTION .text ++ ++;----------------------------------------------------------------------------- ++; horizontal line scaling ++; ++; void hscaleto__ ++; (SwsContext *c, int{16,32}_t *dst, ++; int dstW, const uint{8,16}_t *src, ++; const int16_t *filter, ++; const int32_t *filterPos, int filterSize); ++; ++; Scale one horizontal line. Input is either 8-bits width or 16-bits width ++; ($source_width can be either 8, 9, 10 or 16, difference is whether we have to ++; downscale before multiplying). Filter is 14-bits. Output is either 15bits ++; (in int16_t) or 19bits (in int32_t), as given in $intermediate_nbits. Each ++; output pixel is generated from $filterSize input pixels, the position of ++; the first pixel is given in filterPos[nOutputPixel]. ++;----------------------------------------------------------------------------- ++ ++; SCALE_FUNC source_width, intermediate_nbits, filtersize, filtersuffix, opt, n_args, n_xmm ++%macro SCALE_FUNC 7 ++cglobal hscale%1to%2_%4_%5, %6, 7, %7 ++%ifdef ARCH_X86_64 ++ movsxd r2, r2d ++%define mov32 movsxd ++%else ; x86-32 ++%define mov32 mov ++%endif ; x86-64 ++%if %2 == 19 ++%if mmsize == 8 ; mmx ++ mova m2, [max_19bit_int] ++%elifidn %5, sse4 ++ mova m2, [max_19bit_int] ++%else ; ssse3/sse2 ++ mova m2, [max_19bit_flt] ++%endif ; mmx/sse2/ssse3/sse4 ++%endif ; %2 == 19 ++%if %1 == 16 ++ mova m6, [minshort] ++ mova m7, [unicoeff] ++%elif %1 == 8 ++ pxor m3, m3 ++%endif ; %1 == 8/16 ++ ++%if %1 == 8 ++%define movlh movd ++%define movbh movh ++%define srcmul 1 ++%else ; %1 == 9-16 ++%define movlh movq ++%define movbh movu ++%define srcmul 2 ++%endif ; %1 == 8/9-16 ++ ++%ifnidn %3, X ++ ++ ; setup loop ++%if %3 == 8 ++ shl r2, 1 ; this allows *16 (i.e. now *8) in lea instructions for the 8-tap filter ++%define r2shr 1 ++%else ; %3 == 4 ++%define r2shr 0 ++%endif ; %3 == 8 ++ lea r4, [r4+r2*8] ++%if %2 == 15 ++ lea r1, [r1+r2*(2>>r2shr)] ++%else ; %2 == 19 ++ lea r1, [r1+r2*(4>>r2shr)] ++%endif ; %2 == 15/19 ++ lea r5, [r5+r2*(4>>r2shr)] ++ neg r2 ++ ++.loop: ++%if %3 == 4 ; filterSize == 4 scaling ++ ; load 2x4 or 4x4 source pixels into m0/m1 ++ mov32 r0, dword [r5+r2*4+0] ; filterPos[0] ++ mov32 r6, dword [r5+r2*4+4] ; filterPos[1] ++ movlh m0, [r3+r0*srcmul] ; src[filterPos[0] + {0,1,2,3}] ++%if mmsize == 8 ++ movlh m1, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}] ++%else ; mmsize == 16 ++%if %1 > 8 ++ movhps m0, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}] ++%else ; %1 == 8 ++ movd m4, [r3+r6*srcmul] ; src[filterPos[1] + {0,1,2,3}] ++%endif ++ mov32 r0, dword [r5+r2*4+8] ; filterPos[2] ++ mov32 r6, dword [r5+r2*4+12] ; filterPos[3] ++ movlh m1, [r3+r0*srcmul] ; src[filterPos[2] + {0,1,2,3}] ++%if %1 > 8 ++ movhps m1, [r3+r6*srcmul] ; src[filterPos[3] + {0,1,2,3}] ++%else ; %1 == 8 ++ movd m5, [r3+r6*srcmul] ; src[filterPos[3] + {0,1,2,3}] ++ punpckldq m0, m4 ++ punpckldq m1, m5 ++%endif ; %1 == 8 && %5 <= ssse ++%endif ; mmsize == 8/16 ++%if %1 == 8 ++ punpcklbw m0, m3 ; byte -> word ++ punpcklbw m1, m3 ; byte -> word ++%endif ; %1 == 8 ++ ++ ; multiply with filter coefficients ++%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll ++ ; add back 0x8000 * sum(coeffs) after the horizontal add ++ psubw m0, m6 ++ psubw m1, m6 ++%endif ; %1 == 16 ++ pmaddwd m0, [r4+r2*8+mmsize*0] ; *= filter[{0,1,..,6,7}] ++ pmaddwd m1, [r4+r2*8+mmsize*1] ; *= filter[{8,9,..,14,15}] ++ ++ ; add up horizontally (4 srcpix * 4 coefficients -> 1 dstpix) ++%if mmsize == 8 ; mmx ++ movq m4, m0 ++ punpckldq m0, m1 ++ punpckhdq m4, m1 ++ paddd m0, m4 ++%elifidn %5, sse2 ++ mova m4, m0 ++ shufps m0, m1, 10001000b ++ shufps m4, m1, 11011101b ++ paddd m0, m4 ++%else ; ssse3/sse4 ++ phaddd m0, m1 ; filter[{ 0, 1, 2, 3}]*src[filterPos[0]+{0,1,2,3}], ++ ; filter[{ 4, 5, 6, 7}]*src[filterPos[1]+{0,1,2,3}], ++ ; filter[{ 8, 9,10,11}]*src[filterPos[2]+{0,1,2,3}], ++ ; filter[{12,13,14,15}]*src[filterPos[3]+{0,1,2,3}] ++%endif ; mmx/sse2/ssse3/sse4 ++%else ; %3 == 8, i.e. filterSize == 8 scaling ++ ; load 2x8 or 4x8 source pixels into m0, m1, m4 and m5 ++ mov32 r0, dword [r5+r2*2+0] ; filterPos[0] ++ mov32 r6, dword [r5+r2*2+4] ; filterPos[1] ++ movbh m0, [r3+ r0 *srcmul] ; src[filterPos[0] + {0,1,2,3,4,5,6,7}] ++%if mmsize == 8 ++ movbh m1, [r3+(r0+4)*srcmul] ; src[filterPos[0] + {4,5,6,7}] ++ movbh m4, [r3+ r6 *srcmul] ; src[filterPos[1] + {0,1,2,3}] ++ movbh m5, [r3+(r6+4)*srcmul] ; src[filterPos[1] + {4,5,6,7}] ++%else ; mmsize == 16 ++ movbh m1, [r3+ r6 *srcmul] ; src[filterPos[1] + {0,1,2,3,4,5,6,7}] ++ mov32 r0, dword [r5+r2*2+8] ; filterPos[2] ++ mov32 r6, dword [r5+r2*2+12] ; filterPos[3] ++ movbh m4, [r3+ r0 *srcmul] ; src[filterPos[2] + {0,1,2,3,4,5,6,7}] ++ movbh m5, [r3+ r6 *srcmul] ; src[filterPos[3] + {0,1,2,3,4,5,6,7}] ++%endif ; mmsize == 8/16 ++%if %1 == 8 ++ punpcklbw m0, m3 ; byte -> word ++ punpcklbw m1, m3 ; byte -> word ++ punpcklbw m4, m3 ; byte -> word ++ punpcklbw m5, m3 ; byte -> word ++%endif ; %1 == 8 ++ ++ ; multiply ++%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll ++ ; add back 0x8000 * sum(coeffs) after the horizontal add ++ psubw m0, m6 ++ psubw m1, m6 ++ psubw m4, m6 ++ psubw m5, m6 ++%endif ; %1 == 16 ++ pmaddwd m0, [r4+r2*8+mmsize*0] ; *= filter[{0,1,..,6,7}] ++ pmaddwd m1, [r4+r2*8+mmsize*1] ; *= filter[{8,9,..,14,15}] ++ pmaddwd m4, [r4+r2*8+mmsize*2] ; *= filter[{16,17,..,22,23}] ++ pmaddwd m5, [r4+r2*8+mmsize*3] ; *= filter[{24,25,..,30,31}] ++ ++ ; add up horizontally (8 srcpix * 8 coefficients -> 1 dstpix) ++%if mmsize == 8 ++ paddd m0, m1 ++ paddd m4, m5 ++ movq m1, m0 ++ punpckldq m0, m4 ++ punpckhdq m1, m4 ++ paddd m0, m1 ++%elifidn %5, sse2 ++%if %1 == 8 ++%define mex m6 ++%else ++%define mex m3 ++%endif ++ ; emulate horizontal add as transpose + vertical add ++ mova mex, m0 ++ punpckldq m0, m1 ++ punpckhdq mex, m1 ++ paddd m0, mex ++ mova m1, m4 ++ punpckldq m4, m5 ++ punpckhdq m1, m5 ++ paddd m4, m1 ++ mova m1, m0 ++ punpcklqdq m0, m4 ++ punpckhqdq m1, m4 ++ paddd m0, m1 ++%else ; ssse3/sse4 ++ ; FIXME if we rearrange the filter in pairs of 4, we can ++ ; load pixels likewise and use 2 x paddd + phaddd instead ++ ; of 3 x phaddd here, faster on older cpus ++ phaddd m0, m1 ++ phaddd m4, m5 ++ phaddd m0, m4 ; filter[{ 0, 1,..., 6, 7}]*src[filterPos[0]+{0,1,...,6,7}], ++ ; filter[{ 8, 9,...,14,15}]*src[filterPos[1]+{0,1,...,6,7}], ++ ; filter[{16,17,...,22,23}]*src[filterPos[2]+{0,1,...,6,7}], ++ ; filter[{24,25,...,30,31}]*src[filterPos[3]+{0,1,...,6,7}] ++%endif ; mmx/sse2/ssse3/sse4 ++%endif ; %3 == 4/8 ++ ++%else ; %3 == X, i.e. any filterSize scaling ++ ++%ifidn %4, X4 ++%define r6sub 4 ++%else ; %4 == X || %4 == X8 ++%define r6sub 0 ++%endif ; %4 ==/!= X4 ++%ifdef ARCH_X86_64 ++ push r12 ++ movsxd r6, r6d ; filterSize ++ lea r12, [r3+(r6-r6sub)*srcmul] ; &src[filterSize&~4] ++%define src_reg r11 ++%define r1x r10 ++%define filter2 r12 ++%else ; x86-32 ++ lea r0, [r3+(r6-r6sub)*srcmul] ; &src[filterSize&~4] ++ mov r6m, r0 ++%define src_reg r3 ++%define r1x r1 ++%define filter2 r6m ++%endif ; x86-32/64 ++ lea r5, [r5+r2*4] ++%if %2 == 15 ++ lea r1, [r1+r2*2] ++%else ; %2 == 19 ++ lea r1, [r1+r2*4] ++%endif ; %2 == 15/19 ++ movifnidn r1mp, r1 ++ neg r2 ++ ++.loop: ++ mov32 r0, dword [r5+r2*4+0] ; filterPos[0] ++ mov32 r1x, dword [r5+r2*4+4] ; filterPos[1] ++ ; FIXME maybe do 4px/iteration on x86-64 (x86-32 wouldn't have enough regs)? ++ pxor m4, m4 ++ pxor m5, m5 ++ mov src_reg, r3mp ++ ++.innerloop: ++ ; load 2x4 (mmx) or 2x8 (sse) source pixels into m0/m1 -> m4/m5 ++ movbh m0, [src_reg+r0 *srcmul] ; src[filterPos[0] + {0,1,2,3(,4,5,6,7)}] ++ movbh m1, [src_reg+(r1x+r6sub)*srcmul] ; src[filterPos[1] + {0,1,2,3(,4,5,6,7)}] ++%if %1 == 8 ++ punpcklbw m0, m3 ++ punpcklbw m1, m3 ++%endif ; %1 == 8 ++ ++ ; multiply ++%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll ++ ; add back 0x8000 * sum(coeffs) after the horizontal add ++ psubw m0, m6 ++ psubw m1, m6 ++%endif ; %1 == 16 ++ pmaddwd m0, [r4 ] ; filter[{0,1,2,3(,4,5,6,7)}] ++ pmaddwd m1, [r4+(r6+r6sub)*2] ; filter[filtersize+{0,1,2,3(,4,5,6,7)}] ++ paddd m4, m0 ++ paddd m5, m1 ++ add r4, mmsize ++ add src_reg, srcmul*mmsize/2 ++ cmp src_reg, filter2 ; while (src += 4) < &src[filterSize] ++ jl .innerloop ++ ++%ifidn %4, X4 ++ mov32 r1x, dword [r5+r2*4+4] ; filterPos[1] ++ movlh m0, [src_reg+r0 *srcmul] ; split last 4 srcpx of dstpx[0] ++ sub r1x, r6 ; and first 4 srcpx of dstpx[1] ++%if %1 > 8 ++ movhps m0, [src_reg+(r1x+r6sub)*srcmul] ++%else ; %1 == 8 ++ movd m1, [src_reg+(r1x+r6sub)*srcmul] ++ punpckldq m0, m1 ++%endif ; %1 == 8 && %5 <= ssse ++%if %1 == 8 ++ punpcklbw m0, m3 ++%endif ; %1 == 8 ++%if %1 == 16 ; pmaddwd needs signed adds, so this moves unsigned -> signed, we'll ++ ; add back 0x8000 * sum(coeffs) after the horizontal add ++ psubw m0, m6 ++%endif ; %1 == 16 ++ pmaddwd m0, [r4] ++%endif ; %4 == X4 ++ ++ lea r4, [r4+(r6+r6sub)*2] ++ ++%if mmsize == 8 ; mmx ++ movq m0, m4 ++ punpckldq m4, m5 ++ punpckhdq m0, m5 ++ paddd m0, m4 ++%else ; mmsize == 16 ++%ifidn %5, sse2 ++ mova m1, m4 ++ punpcklqdq m4, m5 ++ punpckhqdq m1, m5 ++ paddd m4, m1 ++%else ; ssse3/sse4 ++ phaddd m4, m5 ++%endif ; sse2/ssse3/sse4 ++%ifidn %4, X4 ++ paddd m4, m0 ++%endif ; %3 == X4 ++%ifidn %5, sse2 ++ pshufd m4, m4, 11011000b ++ movhlps m0, m4 ++ paddd m0, m4 ++%else ; ssse3/sse4 ++ phaddd m4, m4 ++ SWAP 0, 4 ++%endif ; sse2/ssse3/sse4 ++%endif ; mmsize == 8/16 ++%endif ; %3 ==/!= X ++ ++%if %1 == 16 ; add 0x8000 * sum(coeffs), i.e. back from signed -> unsigned ++ paddd m0, m7 ++%endif ; %1 == 16 ++ ++ ; clip, store ++ psrad m0, 14 + %1 - %2 ++%ifidn %3, X ++ movifnidn r1, r1mp ++%endif ; %3 == X ++%if %2 == 15 ++ packssdw m0, m0 ++%ifnidn %3, X ++ movh [r1+r2*(2>>r2shr)], m0 ++%else ; %3 == X ++ movd [r1+r2*2], m0 ++%endif ; %3 ==/!= X ++%else ; %2 == 19 ++%if mmsize == 8 ++ PMINSD_MMX m0, m2, m4 ++%elifidn %5, sse4 ++ pminsd m0, m2 ++%else ; sse2/ssse3 ++ cvtdq2ps m0, m0 ++ minps m0, m2 ++ cvtps2dq m0, m0 ++%endif ; mmx/sse2/ssse3/sse4 ++%ifnidn %3, X ++ mova [r1+r2*(4>>r2shr)], m0 ++%else ; %3 == X ++ movq [r1+r2*4], m0 ++%endif ; %3 ==/!= X ++%endif ; %2 == 15/19 ++%ifnidn %3, X ++ add r2, (mmsize< ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include ++#include "config.h" ++#include "libswscale/swscale.h" ++#include "libswscale/swscale_internal.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" ++#include "libavutil/pixdesc.h" ++ ++DECLARE_ASM_CONST(8, uint64_t, bF8)= 0xF8F8F8F8F8F8F8F8LL; ++DECLARE_ASM_CONST(8, uint64_t, bFC)= 0xFCFCFCFCFCFCFCFCLL; ++DECLARE_ASM_CONST(8, uint64_t, w10)= 0x0010001000100010LL; ++DECLARE_ASM_CONST(8, uint64_t, w02)= 0x0002000200020002LL; ++DECLARE_ASM_CONST(8, uint64_t, bm00001111)=0x00000000FFFFFFFFLL; ++DECLARE_ASM_CONST(8, uint64_t, bm00000111)=0x0000000000FFFFFFLL; ++DECLARE_ASM_CONST(8, uint64_t, bm11111000)=0xFFFFFFFFFF000000LL; ++DECLARE_ASM_CONST(8, uint64_t, bm01010101)=0x00FF00FF00FF00FFLL; ++ ++const DECLARE_ALIGNED(8, uint64_t, ff_dither4)[2] = { ++ 0x0103010301030103LL, ++ 0x0200020002000200LL,}; ++ ++const DECLARE_ALIGNED(8, uint64_t, ff_dither8)[2] = { ++ 0x0602060206020602LL, ++ 0x0004000400040004LL,}; ++ ++DECLARE_ASM_CONST(8, uint64_t, b16Mask)= 0x001F001F001F001FLL; ++DECLARE_ASM_CONST(8, uint64_t, g16Mask)= 0x07E007E007E007E0LL; ++DECLARE_ASM_CONST(8, uint64_t, r16Mask)= 0xF800F800F800F800LL; ++DECLARE_ASM_CONST(8, uint64_t, b15Mask)= 0x001F001F001F001FLL; ++DECLARE_ASM_CONST(8, uint64_t, g15Mask)= 0x03E003E003E003E0LL; ++DECLARE_ASM_CONST(8, uint64_t, r15Mask)= 0x7C007C007C007C00LL; ++ ++DECLARE_ALIGNED(8, const uint64_t, ff_M24A) = 0x00FF0000FF0000FFLL; ++DECLARE_ALIGNED(8, const uint64_t, ff_M24B) = 0xFF0000FF0000FF00LL; ++DECLARE_ALIGNED(8, const uint64_t, ff_M24C) = 0x0000FF0000FF0000LL; ++ ++#ifdef FAST_BGR2YV12 ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000000210041000DULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000FFEEFFDC0038ULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00000038FFD2FFF8ULL; ++#else ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YCoeff) = 0x000020E540830C8BULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UCoeff) = 0x0000ED0FDAC23831ULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2VCoeff) = 0x00003831D0E6F6EAULL; ++#endif /* FAST_BGR2YV12 */ ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2YOffset) = 0x1010101010101010ULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_bgr2UVOffset) = 0x8080808080808080ULL; ++DECLARE_ALIGNED(8, const uint64_t, ff_w1111) = 0x0001000100010001ULL; ++ ++DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY1Coeff) = 0x0C88000040870C88ULL; ++DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toY2Coeff) = 0x20DE4087000020DEULL; ++DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY1Coeff) = 0x20DE0000408720DEULL; ++DECLARE_ASM_CONST(8, uint64_t, ff_rgb24toY2Coeff) = 0x0C88408700000C88ULL; ++DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toYOffset) = 0x0008010000080100ULL; ++ ++DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUV)[2][4] = { ++ {0x38380000DAC83838ULL, 0xECFFDAC80000ECFFULL, 0xF6E40000D0E3F6E4ULL, 0x3838D0E300003838ULL}, ++ {0xECFF0000DAC8ECFFULL, 0x3838DAC800003838ULL, 0x38380000D0E33838ULL, 0xF6E4D0E30000F6E4ULL}, ++}; ++ ++DECLARE_ASM_CONST(8, uint64_t, ff_bgr24toUVOffset)= 0x0040010000400100ULL; ++ ++//MMX versions ++#if HAVE_MMX ++#undef RENAME ++#define COMPILE_TEMPLATE_MMX2 0 ++#define RENAME(a) a ## _MMX ++#include "swscale_template.c" ++#endif ++ ++//MMX2 versions ++#if HAVE_MMX2 ++#undef RENAME ++#undef COMPILE_TEMPLATE_MMX2 ++#define COMPILE_TEMPLATE_MMX2 1 ++#define RENAME(a) a ## _MMX2 ++#include "swscale_template.c" ++#endif ++ ++void updateMMXDitherTables(SwsContext *c, int dstY, int lumBufIndex, int chrBufIndex, ++ int lastInLumBuf, int lastInChrBuf) ++{ ++ const int dstH= c->dstH; ++ const int flags= c->flags; ++ int16_t **lumPixBuf= c->lumPixBuf; ++ int16_t **chrUPixBuf= c->chrUPixBuf; ++ int16_t **alpPixBuf= c->alpPixBuf; ++ const int vLumBufSize= c->vLumBufSize; ++ const int vChrBufSize= c->vChrBufSize; ++ int32_t *vLumFilterPos= c->vLumFilterPos; ++ int32_t *vChrFilterPos= c->vChrFilterPos; ++ int16_t *vLumFilter= c->vLumFilter; ++ int16_t *vChrFilter= c->vChrFilter; ++ int32_t *lumMmxFilter= c->lumMmxFilter; ++ int32_t *chrMmxFilter= c->chrMmxFilter; ++ int32_t av_unused *alpMmxFilter= c->alpMmxFilter; ++ const int vLumFilterSize= c->vLumFilterSize; ++ const int vChrFilterSize= c->vChrFilterSize; ++ const int chrDstY= dstY>>c->chrDstVSubSample; ++ const int firstLumSrcY= vLumFilterPos[dstY]; //First line needed as input ++ const int firstChrSrcY= vChrFilterPos[chrDstY]; //First line needed as input ++ ++ c->blueDither= ff_dither8[dstY&1]; ++ if (c->dstFormat == PIX_FMT_RGB555 || c->dstFormat == PIX_FMT_BGR555) ++ c->greenDither= ff_dither8[dstY&1]; ++ else ++ c->greenDither= ff_dither4[dstY&1]; ++ c->redDither= ff_dither8[(dstY+1)&1]; ++ if (dstY < dstH - 2) { ++ const int16_t **lumSrcPtr= (const int16_t **)(void*) lumPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize; ++ const int16_t **chrUSrcPtr= (const int16_t **)(void*) chrUPixBuf + chrBufIndex + firstChrSrcY - lastInChrBuf + vChrBufSize; ++ const int16_t **alpSrcPtr= (CONFIG_SWSCALE_ALPHA && alpPixBuf) ? (const int16_t **)(void*) alpPixBuf + lumBufIndex + firstLumSrcY - lastInLumBuf + vLumBufSize : NULL; ++ int i; ++ ++ if (firstLumSrcY < 0 || firstLumSrcY + vLumFilterSize > c->srcH) { ++ const int16_t **tmpY = (const int16_t **) lumPixBuf + 2 * vLumBufSize; ++ int neg = -firstLumSrcY, i, end = FFMIN(c->srcH - firstLumSrcY, vLumFilterSize); ++ for (i = 0; i < neg; i++) ++ tmpY[i] = lumSrcPtr[neg]; ++ for ( ; i < end; i++) ++ tmpY[i] = lumSrcPtr[i]; ++ for ( ; i < vLumFilterSize; i++) ++ tmpY[i] = tmpY[i-1]; ++ lumSrcPtr = tmpY; ++ ++ if (alpSrcPtr) { ++ const int16_t **tmpA = (const int16_t **) alpPixBuf + 2 * vLumBufSize; ++ for (i = 0; i < neg; i++) ++ tmpA[i] = alpSrcPtr[neg]; ++ for ( ; i < end; i++) ++ tmpA[i] = alpSrcPtr[i]; ++ for ( ; i < vLumFilterSize; i++) ++ tmpA[i] = tmpA[i - 1]; ++ alpSrcPtr = tmpA; ++ } ++ } ++ if (firstChrSrcY < 0 || firstChrSrcY + vChrFilterSize > c->chrSrcH) { ++ const int16_t **tmpU = (const int16_t **) chrUPixBuf + 2 * vChrBufSize; ++ int neg = -firstChrSrcY, i, end = FFMIN(c->chrSrcH - firstChrSrcY, vChrFilterSize); ++ for (i = 0; i < neg; i++) { ++ tmpU[i] = chrUSrcPtr[neg]; ++ } ++ for ( ; i < end; i++) { ++ tmpU[i] = chrUSrcPtr[i]; ++ } ++ for ( ; i < vChrFilterSize; i++) { ++ tmpU[i] = tmpU[i - 1]; ++ } ++ chrUSrcPtr = tmpU; ++ } ++ ++ if (flags & SWS_ACCURATE_RND) { ++ int s= APCK_SIZE / 8; ++ for (i=0; i1)]; ++ lumMmxFilter[s*i+APCK_COEF/4 ]= ++ lumMmxFilter[s*i+APCK_COEF/4+1]= vLumFilter[dstY*vLumFilterSize + i ] ++ + (vLumFilterSize>1 ? vLumFilter[dstY*vLumFilterSize + i + 1]<<16 : 0); ++ if (CONFIG_SWSCALE_ALPHA && alpPixBuf) { ++ *(const void**)&alpMmxFilter[s*i ]= alpSrcPtr[i ]; ++ *(const void**)&alpMmxFilter[s*i+APCK_PTR2/4 ]= alpSrcPtr[i+(vLumFilterSize>1)]; ++ alpMmxFilter[s*i+APCK_COEF/4 ]= ++ alpMmxFilter[s*i+APCK_COEF/4+1]= lumMmxFilter[s*i+APCK_COEF/4 ]; ++ } ++ } ++ for (i=0; i1)]; ++ chrMmxFilter[s*i+APCK_COEF/4 ]= ++ chrMmxFilter[s*i+APCK_COEF/4+1]= vChrFilter[chrDstY*vChrFilterSize + i ] ++ + (vChrFilterSize>1 ? vChrFilter[chrDstY*vChrFilterSize + i + 1]<<16 : 0); ++ } ++ } else { ++ for (i=0; iuse_mmx_vfilter && !(c->flags & SWS_ACCURATE_RND)) ++ c->yuv2planeX = yuv2yuvX_sse3; ++ } ++#endif ++ ++#if HAVE_YASM ++#define ASSIGN_SCALE_FUNC2(hscalefn, filtersize, opt1, opt2) do { \ ++ if (c->srcBpc == 8) { \ ++ hscalefn = c->dstBpc <= 10 ? ff_hscale8to15_ ## filtersize ## _ ## opt2 : \ ++ ff_hscale8to19_ ## filtersize ## _ ## opt1; \ ++ } else if (c->srcBpc == 9) { \ ++ hscalefn = c->dstBpc <= 10 ? ff_hscale9to15_ ## filtersize ## _ ## opt2 : \ ++ ff_hscale9to19_ ## filtersize ## _ ## opt1; \ ++ } else if (c->srcBpc == 10) { \ ++ hscalefn = c->dstBpc <= 10 ? ff_hscale10to15_ ## filtersize ## _ ## opt2 : \ ++ ff_hscale10to19_ ## filtersize ## _ ## opt1; \ ++ } else if (c->srcBpc == 14 || ((c->srcFormat==PIX_FMT_PAL8||isAnyRGB(c->srcFormat)) && av_pix_fmt_descriptors[c->srcFormat].comp[0].depth_minus1<15)) { \ ++ hscalefn = c->dstBpc <= 10 ? ff_hscale14to15_ ## filtersize ## _ ## opt2 : \ ++ ff_hscale14to19_ ## filtersize ## _ ## opt1; \ ++ } else { /* c->srcBpc == 16 */ \ ++ hscalefn = c->dstBpc <= 10 ? ff_hscale16to15_ ## filtersize ## _ ## opt2 : \ ++ ff_hscale16to19_ ## filtersize ## _ ## opt1; \ ++ } \ ++} while (0) ++#define ASSIGN_MMX_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ ++ switch (filtersize) { \ ++ case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ ++ case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ ++ default: ASSIGN_SCALE_FUNC2(hscalefn, X, opt1, opt2); break; \ ++ } ++#define ASSIGN_VSCALEX_FUNC(vscalefn, opt, do_16_case) \ ++switch(c->dstBpc){ \ ++ case 16: /*do_16_case;*/ break; \ ++ case 10: if (!isBE(c->dstFormat)) /*vscalefn = ff_yuv2planeX_10_ ## opt;*/ break; \ ++ case 9: if (!isBE(c->dstFormat)) /*vscalefn = ff_yuv2planeX_9_ ## opt;*/ break; \ ++ default: /*vscalefn = ff_yuv2planeX_8_ ## opt;*/ break; \ ++ } ++#define ASSIGN_VSCALE_FUNC(vscalefn, opt1, opt2, opt2chk) \ ++ switch(c->dstBpc){ \ ++ case 16: if (!isBE(c->dstFormat)) vscalefn = ff_yuv2plane1_16_ ## opt1; break; \ ++ case 10: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_10_ ## opt2; break; \ ++ case 9: if (!isBE(c->dstFormat) && opt2chk) vscalefn = ff_yuv2plane1_9_ ## opt2; break; \ ++ default: vscalefn = ff_yuv2plane1_8_ ## opt1; break; \ ++ } ++#if ARCH_X86_32 ++ if (cpu_flags & AV_CPU_FLAG_MMX) { ++ ASSIGN_MMX_SCALE_FUNC(c->hyScale, c->hLumFilterSize, mmx, mmx); ++ ASSIGN_MMX_SCALE_FUNC(c->hcScale, c->hChrFilterSize, mmx, mmx); ++ ASSIGN_VSCALE_FUNC(c->yuv2plane1, mmx, mmx2, cpu_flags & AV_CPU_FLAG_MMX2); ++ ++ switch (c->srcFormat) { ++ case PIX_FMT_Y400A: ++ c->lumToYV12 = ff_yuyvToY_mmx; ++ if (c->alpPixBuf) ++ c->alpToYV12 = ff_uyvyToY_mmx; ++ break; ++ case PIX_FMT_YUYV422: ++ c->lumToYV12 = ff_yuyvToY_mmx; ++ c->chrToYV12 = ff_yuyvToUV_mmx; ++ break; ++ case PIX_FMT_UYVY422: ++ c->lumToYV12 = ff_uyvyToY_mmx; ++ c->chrToYV12 = ff_uyvyToUV_mmx; ++ break; ++ case PIX_FMT_NV12: ++ c->chrToYV12 = ff_nv12ToUV_mmx; ++ break; ++ case PIX_FMT_NV21: ++ c->chrToYV12 = ff_nv21ToUV_mmx; ++ break; ++ default: ++ break; ++ } ++ } ++ if (cpu_flags & AV_CPU_FLAG_MMX2) { ++ ASSIGN_VSCALEX_FUNC(c->yuv2planeX, mmx2,); ++ } ++#endif ++#define ASSIGN_SSE_SCALE_FUNC(hscalefn, filtersize, opt1, opt2) \ ++ switch (filtersize) { \ ++ case 4: ASSIGN_SCALE_FUNC2(hscalefn, 4, opt1, opt2); break; \ ++ case 8: ASSIGN_SCALE_FUNC2(hscalefn, 8, opt1, opt2); break; \ ++ default: if (filtersize & 4) ASSIGN_SCALE_FUNC2(hscalefn, X4, opt1, opt2); \ ++ else ASSIGN_SCALE_FUNC2(hscalefn, X8, opt1, opt2); \ ++ break; \ ++ } ++ if (cpu_flags & AV_CPU_FLAG_SSE2) { ++ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse2, sse2); ++ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse2, sse2); ++ ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse2,); ++ ASSIGN_VSCALE_FUNC(c->yuv2plane1, sse2, sse2, 1); ++ ++ switch (c->srcFormat) { ++ case PIX_FMT_Y400A: ++ c->lumToYV12 = ff_yuyvToY_sse2; ++ if (c->alpPixBuf) ++ c->alpToYV12 = ff_uyvyToY_sse2; ++ break; ++ case PIX_FMT_YUYV422: ++ c->lumToYV12 = ff_yuyvToY_sse2; ++ c->chrToYV12 = ff_yuyvToUV_sse2; ++ break; ++ case PIX_FMT_UYVY422: ++ c->lumToYV12 = ff_uyvyToY_sse2; ++ c->chrToYV12 = ff_uyvyToUV_sse2; ++ break; ++ case PIX_FMT_NV12: ++ c->chrToYV12 = ff_nv12ToUV_sse2; ++ break; ++ case PIX_FMT_NV21: ++ c->chrToYV12 = ff_nv21ToUV_sse2; ++ break; ++ } ++ } ++ if (cpu_flags & AV_CPU_FLAG_SSSE3) { ++ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, ssse3, ssse3); ++ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, ssse3, ssse3); ++ } ++ if (cpu_flags & AV_CPU_FLAG_SSE4) { ++ /* Xto15 don't need special sse4 functions */ ++ ASSIGN_SSE_SCALE_FUNC(c->hyScale, c->hLumFilterSize, sse4, ssse3); ++ ASSIGN_SSE_SCALE_FUNC(c->hcScale, c->hChrFilterSize, sse4, ssse3); ++ ASSIGN_VSCALEX_FUNC(c->yuv2planeX, sse4, ++ if (!isBE(c->dstFormat)) c->yuv2planeX = ff_yuv2planeX_16_sse4); ++ if (c->dstBpc == 16 && !isBE(c->dstFormat)) ++ c->yuv2plane1 = ff_yuv2plane1_16_sse4; ++ } ++ ++ if (HAVE_AVX && cpu_flags & AV_CPU_FLAG_AVX) { ++ ASSIGN_VSCALEX_FUNC(c->yuv2planeX, avx,); ++ ASSIGN_VSCALE_FUNC(c->yuv2plane1, avx, avx, 1); ++ ++ switch (c->srcFormat) { ++ case PIX_FMT_YUYV422: ++ c->chrToYV12 = ff_yuyvToUV_avx; ++ break; ++ case PIX_FMT_UYVY422: ++ c->chrToYV12 = ff_uyvyToUV_avx; ++ break; ++ case PIX_FMT_NV12: ++ c->chrToYV12 = ff_nv12ToUV_avx; ++ break; ++ case PIX_FMT_NV21: ++ c->chrToYV12 = ff_nv21ToUV_avx; ++ break; ++ default: ++ break; ++ } ++ } ++#endif ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/swscale_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/swscale_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/swscale_template.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/swscale_template.c 2012-05-14 14:08:55.482363086 +0200 +@@ -0,0 +1,1850 @@ ++/* ++ * Copyright (C) 2001-2011 Michael Niedermayer ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#undef REAL_MOVNTQ ++#undef MOVNTQ ++#undef MOVNTQ2 ++#undef PREFETCH ++ ++#if COMPILE_TEMPLATE_MMX2 ++#define PREFETCH "prefetchnta" ++#else ++#define PREFETCH " # nop" ++#endif ++ ++#if COMPILE_TEMPLATE_MMX2 ++#define REAL_MOVNTQ(a,b) "movntq " #a ", " #b " \n\t" ++#define MOVNTQ2 "movntq " ++#else ++#define REAL_MOVNTQ(a,b) "movq " #a ", " #b " \n\t" ++#define MOVNTQ2 "movq " ++#endif ++#define MOVNTQ(a,b) REAL_MOVNTQ(a,b) ++ ++#if !COMPILE_TEMPLATE_MMX2 ++static av_always_inline void ++dither_8to16(const uint8_t *srcDither, int rot) ++{ ++ if (rot) { ++ __asm__ volatile("pxor %%mm0, %%mm0\n\t" ++ "movq (%0), %%mm3\n\t" ++ "movq %%mm3, %%mm4\n\t" ++ "psrlq $24, %%mm3\n\t" ++ "psllq $40, %%mm4\n\t" ++ "por %%mm4, %%mm3\n\t" ++ "movq %%mm3, %%mm4\n\t" ++ "punpcklbw %%mm0, %%mm3\n\t" ++ "punpckhbw %%mm0, %%mm4\n\t" ++ :: "r"(srcDither) ++ ); ++ } else { ++ __asm__ volatile("pxor %%mm0, %%mm0\n\t" ++ "movq (%0), %%mm3\n\t" ++ "movq %%mm3, %%mm4\n\t" ++ "punpcklbw %%mm0, %%mm3\n\t" ++ "punpckhbw %%mm0, %%mm4\n\t" ++ :: "r"(srcDither) ++ ); ++ } ++} ++#endif ++ ++static void RENAME(yuv2yuvX)(const int16_t *filter, int filterSize, ++ const int16_t **src, uint8_t *dest, int dstW, ++ const uint8_t *dither, int offset) ++{ ++ dither_8to16(dither, offset); ++ __asm__ volatile(\ ++ "psraw $4, %%mm3\n\t" ++ "psraw $4, %%mm4\n\t" ++ "movq %%mm3, %%mm6\n\t" ++ "movq %%mm4, %%mm7\n\t" ++ "movl %3, %%ecx\n\t" ++ "mov %0, %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ ".p2align 4 \n\t" /* FIXME Unroll? */\ ++ "1: \n\t"\ ++ "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ ++ "movq (%%"REG_S", %%"REG_c", 2), %%mm2 \n\t" /* srcData */\ ++ "movq 8(%%"REG_S", %%"REG_c", 2), %%mm5 \n\t" /* srcData */\ ++ "add $16, %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "test %%"REG_S", %%"REG_S" \n\t"\ ++ "pmulhw %%mm0, %%mm2 \n\t"\ ++ "pmulhw %%mm0, %%mm5 \n\t"\ ++ "paddw %%mm2, %%mm3 \n\t"\ ++ "paddw %%mm5, %%mm4 \n\t"\ ++ " jnz 1b \n\t"\ ++ "psraw $3, %%mm3 \n\t"\ ++ "psraw $3, %%mm4 \n\t"\ ++ "packuswb %%mm4, %%mm3 \n\t" ++ MOVNTQ2 " %%mm3, (%1, %%"REG_c")\n\t" ++ "add $8, %%"REG_c" \n\t"\ ++ "cmp %2, %%"REG_c" \n\t"\ ++ "movq %%mm6, %%mm3\n\t" ++ "movq %%mm7, %%mm4\n\t" ++ "mov %0, %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "jb 1b \n\t"\ ++ :: "g" (filter), ++ "r" (dest-offset), "g" ((x86_reg)(dstW+offset)), "m" (offset) ++ : "%"REG_d, "%"REG_S, "%"REG_c ++ ); ++} ++ ++#define YSCALEYUV2PACKEDX_UV \ ++ __asm__ volatile(\ ++ "xor %%"REG_a", %%"REG_a" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "nop \n\t"\ ++ "1: \n\t"\ ++ "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "movq "VROUNDER_OFFSET"(%0), %%mm3 \n\t"\ ++ "movq %%mm3, %%mm4 \n\t"\ ++ ".p2align 4 \n\t"\ ++ "2: \n\t"\ ++ "movq 8(%%"REG_d"), %%mm0 \n\t" /* filterCoeff */\ ++ "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* UsrcData */\ ++ "add %6, %%"REG_S" \n\t" \ ++ "movq (%%"REG_S", %%"REG_a"), %%mm5 \n\t" /* VsrcData */\ ++ "add $16, %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "pmulhw %%mm0, %%mm2 \n\t"\ ++ "pmulhw %%mm0, %%mm5 \n\t"\ ++ "paddw %%mm2, %%mm3 \n\t"\ ++ "paddw %%mm5, %%mm4 \n\t"\ ++ "test %%"REG_S", %%"REG_S" \n\t"\ ++ " jnz 2b \n\t"\ ++ ++#define YSCALEYUV2PACKEDX_YA(offset,coeff,src1,src2,dst1,dst2) \ ++ "lea "offset"(%0), %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "movq "VROUNDER_OFFSET"(%0), "#dst1" \n\t"\ ++ "movq "#dst1", "#dst2" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "2: \n\t"\ ++ "movq 8(%%"REG_d"), "#coeff" \n\t" /* filterCoeff */\ ++ "movq (%%"REG_S", %%"REG_a", 2), "#src1" \n\t" /* Y1srcData */\ ++ "movq 8(%%"REG_S", %%"REG_a", 2), "#src2" \n\t" /* Y2srcData */\ ++ "add $16, %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "pmulhw "#coeff", "#src1" \n\t"\ ++ "pmulhw "#coeff", "#src2" \n\t"\ ++ "paddw "#src1", "#dst1" \n\t"\ ++ "paddw "#src2", "#dst2" \n\t"\ ++ "test %%"REG_S", %%"REG_S" \n\t"\ ++ " jnz 2b \n\t"\ ++ ++#define YSCALEYUV2PACKEDX \ ++ YSCALEYUV2PACKEDX_UV \ ++ YSCALEYUV2PACKEDX_YA(LUM_MMX_FILTER_OFFSET,%%mm0,%%mm2,%%mm5,%%mm1,%%mm7) \ ++ ++#define YSCALEYUV2PACKEDX_END \ ++ :: "r" (&c->redDither), \ ++ "m" (dummy), "m" (dummy), "m" (dummy),\ ++ "r" (dest), "m" (dstW_reg), "m"(uv_off) \ ++ : "%"REG_a, "%"REG_d, "%"REG_S \ ++ ); ++ ++#define YSCALEYUV2PACKEDX_ACCURATE_UV \ ++ __asm__ volatile(\ ++ "xor %%"REG_a", %%"REG_a" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "nop \n\t"\ ++ "1: \n\t"\ ++ "lea "CHR_MMX_FILTER_OFFSET"(%0), %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "pxor %%mm4, %%mm4 \n\t"\ ++ "pxor %%mm5, %%mm5 \n\t"\ ++ "pxor %%mm6, %%mm6 \n\t"\ ++ "pxor %%mm7, %%mm7 \n\t"\ ++ ".p2align 4 \n\t"\ ++ "2: \n\t"\ ++ "movq (%%"REG_S", %%"REG_a"), %%mm0 \n\t" /* UsrcData */\ ++ "add %6, %%"REG_S" \n\t" \ ++ "movq (%%"REG_S", %%"REG_a"), %%mm2 \n\t" /* VsrcData */\ ++ "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\ ++ "movq (%%"REG_S", %%"REG_a"), %%mm1 \n\t" /* UsrcData */\ ++ "movq %%mm0, %%mm3 \n\t"\ ++ "punpcklwd %%mm1, %%mm0 \n\t"\ ++ "punpckhwd %%mm1, %%mm3 \n\t"\ ++ "movq "STR(APCK_COEF)"(%%"REG_d"),%%mm1 \n\t" /* filterCoeff */\ ++ "pmaddwd %%mm1, %%mm0 \n\t"\ ++ "pmaddwd %%mm1, %%mm3 \n\t"\ ++ "paddd %%mm0, %%mm4 \n\t"\ ++ "paddd %%mm3, %%mm5 \n\t"\ ++ "add %6, %%"REG_S" \n\t" \ ++ "movq (%%"REG_S", %%"REG_a"), %%mm3 \n\t" /* VsrcData */\ ++ "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\ ++ "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\ ++ "test %%"REG_S", %%"REG_S" \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "punpcklwd %%mm3, %%mm2 \n\t"\ ++ "punpckhwd %%mm3, %%mm0 \n\t"\ ++ "pmaddwd %%mm1, %%mm2 \n\t"\ ++ "pmaddwd %%mm1, %%mm0 \n\t"\ ++ "paddd %%mm2, %%mm6 \n\t"\ ++ "paddd %%mm0, %%mm7 \n\t"\ ++ " jnz 2b \n\t"\ ++ "psrad $16, %%mm4 \n\t"\ ++ "psrad $16, %%mm5 \n\t"\ ++ "psrad $16, %%mm6 \n\t"\ ++ "psrad $16, %%mm7 \n\t"\ ++ "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ ++ "packssdw %%mm5, %%mm4 \n\t"\ ++ "packssdw %%mm7, %%mm6 \n\t"\ ++ "paddw %%mm0, %%mm4 \n\t"\ ++ "paddw %%mm0, %%mm6 \n\t"\ ++ "movq %%mm4, "U_TEMP"(%0) \n\t"\ ++ "movq %%mm6, "V_TEMP"(%0) \n\t"\ ++ ++#define YSCALEYUV2PACKEDX_ACCURATE_YA(offset) \ ++ "lea "offset"(%0), %%"REG_d" \n\t"\ ++ "mov (%%"REG_d"), %%"REG_S" \n\t"\ ++ "pxor %%mm1, %%mm1 \n\t"\ ++ "pxor %%mm5, %%mm5 \n\t"\ ++ "pxor %%mm7, %%mm7 \n\t"\ ++ "pxor %%mm6, %%mm6 \n\t"\ ++ ".p2align 4 \n\t"\ ++ "2: \n\t"\ ++ "movq (%%"REG_S", %%"REG_a", 2), %%mm0 \n\t" /* Y1srcData */\ ++ "movq 8(%%"REG_S", %%"REG_a", 2), %%mm2 \n\t" /* Y2srcData */\ ++ "mov "STR(APCK_PTR2)"(%%"REG_d"), %%"REG_S" \n\t"\ ++ "movq (%%"REG_S", %%"REG_a", 2), %%mm4 \n\t" /* Y1srcData */\ ++ "movq %%mm0, %%mm3 \n\t"\ ++ "punpcklwd %%mm4, %%mm0 \n\t"\ ++ "punpckhwd %%mm4, %%mm3 \n\t"\ ++ "movq "STR(APCK_COEF)"(%%"REG_d"), %%mm4 \n\t" /* filterCoeff */\ ++ "pmaddwd %%mm4, %%mm0 \n\t"\ ++ "pmaddwd %%mm4, %%mm3 \n\t"\ ++ "paddd %%mm0, %%mm1 \n\t"\ ++ "paddd %%mm3, %%mm5 \n\t"\ ++ "movq 8(%%"REG_S", %%"REG_a", 2), %%mm3 \n\t" /* Y2srcData */\ ++ "mov "STR(APCK_SIZE)"(%%"REG_d"), %%"REG_S" \n\t"\ ++ "add $"STR(APCK_SIZE)", %%"REG_d" \n\t"\ ++ "test %%"REG_S", %%"REG_S" \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "punpcklwd %%mm3, %%mm2 \n\t"\ ++ "punpckhwd %%mm3, %%mm0 \n\t"\ ++ "pmaddwd %%mm4, %%mm2 \n\t"\ ++ "pmaddwd %%mm4, %%mm0 \n\t"\ ++ "paddd %%mm2, %%mm7 \n\t"\ ++ "paddd %%mm0, %%mm6 \n\t"\ ++ " jnz 2b \n\t"\ ++ "psrad $16, %%mm1 \n\t"\ ++ "psrad $16, %%mm5 \n\t"\ ++ "psrad $16, %%mm7 \n\t"\ ++ "psrad $16, %%mm6 \n\t"\ ++ "movq "VROUNDER_OFFSET"(%0), %%mm0 \n\t"\ ++ "packssdw %%mm5, %%mm1 \n\t"\ ++ "packssdw %%mm6, %%mm7 \n\t"\ ++ "paddw %%mm0, %%mm1 \n\t"\ ++ "paddw %%mm0, %%mm7 \n\t"\ ++ "movq "U_TEMP"(%0), %%mm3 \n\t"\ ++ "movq "V_TEMP"(%0), %%mm4 \n\t"\ ++ ++#define YSCALEYUV2PACKEDX_ACCURATE \ ++ YSCALEYUV2PACKEDX_ACCURATE_UV \ ++ YSCALEYUV2PACKEDX_ACCURATE_YA(LUM_MMX_FILTER_OFFSET) ++ ++#define YSCALEYUV2RGBX \ ++ "psubw "U_OFFSET"(%0), %%mm3 \n\t" /* (U-128)8*/\ ++ "psubw "V_OFFSET"(%0), %%mm4 \n\t" /* (V-128)8*/\ ++ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ ++ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ ++ "pmulhw "UG_COEFF"(%0), %%mm3 \n\t"\ ++ "pmulhw "VG_COEFF"(%0), %%mm4 \n\t"\ ++ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ ++ "pmulhw "UB_COEFF"(%0), %%mm2 \n\t"\ ++ "pmulhw "VR_COEFF"(%0), %%mm5 \n\t"\ ++ "psubw "Y_OFFSET"(%0), %%mm1 \n\t" /* 8(Y-16)*/\ ++ "psubw "Y_OFFSET"(%0), %%mm7 \n\t" /* 8(Y-16)*/\ ++ "pmulhw "Y_COEFF"(%0), %%mm1 \n\t"\ ++ "pmulhw "Y_COEFF"(%0), %%mm7 \n\t"\ ++ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ ++ "paddw %%mm3, %%mm4 \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "movq %%mm5, %%mm6 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++ "punpcklwd %%mm2, %%mm2 \n\t"\ ++ "punpcklwd %%mm5, %%mm5 \n\t"\ ++ "punpcklwd %%mm4, %%mm4 \n\t"\ ++ "paddw %%mm1, %%mm2 \n\t"\ ++ "paddw %%mm1, %%mm5 \n\t"\ ++ "paddw %%mm1, %%mm4 \n\t"\ ++ "punpckhwd %%mm0, %%mm0 \n\t"\ ++ "punpckhwd %%mm6, %%mm6 \n\t"\ ++ "punpckhwd %%mm3, %%mm3 \n\t"\ ++ "paddw %%mm7, %%mm0 \n\t"\ ++ "paddw %%mm7, %%mm6 \n\t"\ ++ "paddw %%mm7, %%mm3 \n\t"\ ++ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ ++ "packuswb %%mm0, %%mm2 \n\t"\ ++ "packuswb %%mm6, %%mm5 \n\t"\ ++ "packuswb %%mm3, %%mm4 \n\t"\ ++ ++#define REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) \ ++ "movq "#b", "#q2" \n\t" /* B */\ ++ "movq "#r", "#t" \n\t" /* R */\ ++ "punpcklbw "#g", "#b" \n\t" /* GBGBGBGB 0 */\ ++ "punpcklbw "#a", "#r" \n\t" /* ARARARAR 0 */\ ++ "punpckhbw "#g", "#q2" \n\t" /* GBGBGBGB 2 */\ ++ "punpckhbw "#a", "#t" \n\t" /* ARARARAR 2 */\ ++ "movq "#b", "#q0" \n\t" /* GBGBGBGB 0 */\ ++ "movq "#q2", "#q3" \n\t" /* GBGBGBGB 2 */\ ++ "punpcklwd "#r", "#q0" \n\t" /* ARGBARGB 0 */\ ++ "punpckhwd "#r", "#b" \n\t" /* ARGBARGB 1 */\ ++ "punpcklwd "#t", "#q2" \n\t" /* ARGBARGB 2 */\ ++ "punpckhwd "#t", "#q3" \n\t" /* ARGBARGB 3 */\ ++\ ++ MOVNTQ( q0, (dst, index, 4))\ ++ MOVNTQ( b, 8(dst, index, 4))\ ++ MOVNTQ( q2, 16(dst, index, 4))\ ++ MOVNTQ( q3, 24(dst, index, 4))\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++#define WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) REAL_WRITEBGR32(dst, dstw, index, b, g, r, a, q0, q2, q3, t) ++ ++static void RENAME(yuv2rgb32_X_ar)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { ++ YSCALEYUV2PACKEDX_ACCURATE ++ YSCALEYUV2RGBX ++ "movq %%mm2, "U_TEMP"(%0) \n\t" ++ "movq %%mm4, "V_TEMP"(%0) \n\t" ++ "movq %%mm5, "Y_TEMP"(%0) \n\t" ++ YSCALEYUV2PACKEDX_ACCURATE_YA(ALP_MMX_FILTER_OFFSET) ++ "movq "Y_TEMP"(%0), %%mm5 \n\t" ++ "psraw $3, %%mm1 \n\t" ++ "psraw $3, %%mm7 \n\t" ++ "packuswb %%mm7, %%mm1 \n\t" ++ WRITEBGR32(%4, %5, %%REGa, %%mm3, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm2, %%mm6) ++ YSCALEYUV2PACKEDX_END ++ } else { ++ YSCALEYUV2PACKEDX_ACCURATE ++ YSCALEYUV2RGBX ++ "pcmpeqd %%mm7, %%mm7 \n\t" ++ WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ YSCALEYUV2PACKEDX_END ++ } ++} ++ ++static void RENAME(yuv2rgb32_X)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { ++ YSCALEYUV2PACKEDX ++ YSCALEYUV2RGBX ++ YSCALEYUV2PACKEDX_YA(ALP_MMX_FILTER_OFFSET, %%mm0, %%mm3, %%mm6, %%mm1, %%mm7) ++ "psraw $3, %%mm1 \n\t" ++ "psraw $3, %%mm7 \n\t" ++ "packuswb %%mm7, %%mm1 \n\t" ++ WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) ++ YSCALEYUV2PACKEDX_END ++ } else { ++ YSCALEYUV2PACKEDX ++ YSCALEYUV2RGBX ++ "pcmpeqd %%mm7, %%mm7 \n\t" ++ WRITEBGR32(%4, %5, %%REGa, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ YSCALEYUV2PACKEDX_END ++ } ++} ++ ++#define REAL_WRITERGB16(dst, dstw, index) \ ++ "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ ++ "pand "MANGLE(bFC)", %%mm4 \n\t" /* G */\ ++ "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ ++ "psrlq $3, %%mm2 \n\t"\ ++\ ++ "movq %%mm2, %%mm1 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++\ ++ "punpcklbw %%mm7, %%mm3 \n\t"\ ++ "punpcklbw %%mm5, %%mm2 \n\t"\ ++ "punpckhbw %%mm7, %%mm4 \n\t"\ ++ "punpckhbw %%mm5, %%mm1 \n\t"\ ++\ ++ "psllq $3, %%mm3 \n\t"\ ++ "psllq $3, %%mm4 \n\t"\ ++\ ++ "por %%mm3, %%mm2 \n\t"\ ++ "por %%mm4, %%mm1 \n\t"\ ++\ ++ MOVNTQ(%%mm2, (dst, index, 2))\ ++ MOVNTQ(%%mm1, 8(dst, index, 2))\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++#define WRITERGB16(dst, dstw, index) REAL_WRITERGB16(dst, dstw, index) ++ ++static void RENAME(yuv2rgb565_X_ar)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX_ACCURATE ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%0), %%mm2\n\t" ++ "paddusb "GREEN_DITHER"(%0), %%mm4\n\t" ++ "paddusb "RED_DITHER"(%0), %%mm5\n\t" ++#endif ++ WRITERGB16(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++static void RENAME(yuv2rgb565_X)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%0), %%mm5 \n\t" ++#endif ++ WRITERGB16(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++#define REAL_WRITERGB15(dst, dstw, index) \ ++ "pand "MANGLE(bF8)", %%mm2 \n\t" /* B */\ ++ "pand "MANGLE(bF8)", %%mm4 \n\t" /* G */\ ++ "pand "MANGLE(bF8)", %%mm5 \n\t" /* R */\ ++ "psrlq $3, %%mm2 \n\t"\ ++ "psrlq $1, %%mm5 \n\t"\ ++\ ++ "movq %%mm2, %%mm1 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++\ ++ "punpcklbw %%mm7, %%mm3 \n\t"\ ++ "punpcklbw %%mm5, %%mm2 \n\t"\ ++ "punpckhbw %%mm7, %%mm4 \n\t"\ ++ "punpckhbw %%mm5, %%mm1 \n\t"\ ++\ ++ "psllq $2, %%mm3 \n\t"\ ++ "psllq $2, %%mm4 \n\t"\ ++\ ++ "por %%mm3, %%mm2 \n\t"\ ++ "por %%mm4, %%mm1 \n\t"\ ++\ ++ MOVNTQ(%%mm2, (dst, index, 2))\ ++ MOVNTQ(%%mm1, 8(dst, index, 2))\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++#define WRITERGB15(dst, dstw, index) REAL_WRITERGB15(dst, dstw, index) ++ ++static void RENAME(yuv2rgb555_X_ar)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX_ACCURATE ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%0), %%mm2\n\t" ++ "paddusb "GREEN_DITHER"(%0), %%mm4\n\t" ++ "paddusb "RED_DITHER"(%0), %%mm5\n\t" ++#endif ++ WRITERGB15(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++static void RENAME(yuv2rgb555_X)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%0), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%0), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%0), %%mm5 \n\t" ++#endif ++ WRITERGB15(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++#define WRITEBGR24MMX(dst, dstw, index) \ ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ ++ "movq %%mm2, %%mm1 \n\t" /* B */\ ++ "movq %%mm5, %%mm6 \n\t" /* R */\ ++ "punpcklbw %%mm4, %%mm2 \n\t" /* GBGBGBGB 0 */\ ++ "punpcklbw %%mm7, %%mm5 \n\t" /* 0R0R0R0R 0 */\ ++ "punpckhbw %%mm4, %%mm1 \n\t" /* GBGBGBGB 2 */\ ++ "punpckhbw %%mm7, %%mm6 \n\t" /* 0R0R0R0R 2 */\ ++ "movq %%mm2, %%mm0 \n\t" /* GBGBGBGB 0 */\ ++ "movq %%mm1, %%mm3 \n\t" /* GBGBGBGB 2 */\ ++ "punpcklwd %%mm5, %%mm0 \n\t" /* 0RGB0RGB 0 */\ ++ "punpckhwd %%mm5, %%mm2 \n\t" /* 0RGB0RGB 1 */\ ++ "punpcklwd %%mm6, %%mm1 \n\t" /* 0RGB0RGB 2 */\ ++ "punpckhwd %%mm6, %%mm3 \n\t" /* 0RGB0RGB 3 */\ ++\ ++ "movq %%mm0, %%mm4 \n\t" /* 0RGB0RGB 0 */\ ++ "movq %%mm2, %%mm6 \n\t" /* 0RGB0RGB 1 */\ ++ "movq %%mm1, %%mm5 \n\t" /* 0RGB0RGB 2 */\ ++ "movq %%mm3, %%mm7 \n\t" /* 0RGB0RGB 3 */\ ++\ ++ "psllq $40, %%mm0 \n\t" /* RGB00000 0 */\ ++ "psllq $40, %%mm2 \n\t" /* RGB00000 1 */\ ++ "psllq $40, %%mm1 \n\t" /* RGB00000 2 */\ ++ "psllq $40, %%mm3 \n\t" /* RGB00000 3 */\ ++\ ++ "punpckhdq %%mm4, %%mm0 \n\t" /* 0RGBRGB0 0 */\ ++ "punpckhdq %%mm6, %%mm2 \n\t" /* 0RGBRGB0 1 */\ ++ "punpckhdq %%mm5, %%mm1 \n\t" /* 0RGBRGB0 2 */\ ++ "punpckhdq %%mm7, %%mm3 \n\t" /* 0RGBRGB0 3 */\ ++\ ++ "psrlq $8, %%mm0 \n\t" /* 00RGBRGB 0 */\ ++ "movq %%mm2, %%mm6 \n\t" /* 0RGBRGB0 1 */\ ++ "psllq $40, %%mm2 \n\t" /* GB000000 1 */\ ++ "por %%mm2, %%mm0 \n\t" /* GBRGBRGB 0 */\ ++ MOVNTQ(%%mm0, (dst))\ ++\ ++ "psrlq $24, %%mm6 \n\t" /* 0000RGBR 1 */\ ++ "movq %%mm1, %%mm5 \n\t" /* 0RGBRGB0 2 */\ ++ "psllq $24, %%mm1 \n\t" /* BRGB0000 2 */\ ++ "por %%mm1, %%mm6 \n\t" /* BRGBRGBR 1 */\ ++ MOVNTQ(%%mm6, 8(dst))\ ++\ ++ "psrlq $40, %%mm5 \n\t" /* 000000RG 2 */\ ++ "psllq $8, %%mm3 \n\t" /* RGBRGB00 3 */\ ++ "por %%mm3, %%mm5 \n\t" /* RGBRGBRG 2 */\ ++ MOVNTQ(%%mm5, 16(dst))\ ++\ ++ "add $24, "#dst" \n\t"\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++ ++#define WRITEBGR24MMX2(dst, dstw, index) \ ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */\ ++ "movq "MANGLE(ff_M24A)", %%mm0 \n\t"\ ++ "movq "MANGLE(ff_M24C)", %%mm7 \n\t"\ ++ "pshufw $0x50, %%mm2, %%mm1 \n\t" /* B3 B2 B3 B2 B1 B0 B1 B0 */\ ++ "pshufw $0x50, %%mm4, %%mm3 \n\t" /* G3 G2 G3 G2 G1 G0 G1 G0 */\ ++ "pshufw $0x00, %%mm5, %%mm6 \n\t" /* R1 R0 R1 R0 R1 R0 R1 R0 */\ ++\ ++ "pand %%mm0, %%mm1 \n\t" /* B2 B1 B0 */\ ++ "pand %%mm0, %%mm3 \n\t" /* G2 G1 G0 */\ ++ "pand %%mm7, %%mm6 \n\t" /* R1 R0 */\ ++\ ++ "psllq $8, %%mm3 \n\t" /* G2 G1 G0 */\ ++ "por %%mm1, %%mm6 \n\t"\ ++ "por %%mm3, %%mm6 \n\t"\ ++ MOVNTQ(%%mm6, (dst))\ ++\ ++ "psrlq $8, %%mm4 \n\t" /* 00 G7 G6 G5 G4 G3 G2 G1 */\ ++ "pshufw $0xA5, %%mm2, %%mm1 \n\t" /* B5 B4 B5 B4 B3 B2 B3 B2 */\ ++ "pshufw $0x55, %%mm4, %%mm3 \n\t" /* G4 G3 G4 G3 G4 G3 G4 G3 */\ ++ "pshufw $0xA5, %%mm5, %%mm6 \n\t" /* R5 R4 R5 R4 R3 R2 R3 R2 */\ ++\ ++ "pand "MANGLE(ff_M24B)", %%mm1 \n\t" /* B5 B4 B3 */\ ++ "pand %%mm7, %%mm3 \n\t" /* G4 G3 */\ ++ "pand %%mm0, %%mm6 \n\t" /* R4 R3 R2 */\ ++\ ++ "por %%mm1, %%mm3 \n\t" /* B5 G4 B4 G3 B3 */\ ++ "por %%mm3, %%mm6 \n\t"\ ++ MOVNTQ(%%mm6, 8(dst))\ ++\ ++ "pshufw $0xFF, %%mm2, %%mm1 \n\t" /* B7 B6 B7 B6 B7 B6 B6 B7 */\ ++ "pshufw $0xFA, %%mm4, %%mm3 \n\t" /* 00 G7 00 G7 G6 G5 G6 G5 */\ ++ "pshufw $0xFA, %%mm5, %%mm6 \n\t" /* R7 R6 R7 R6 R5 R4 R5 R4 */\ ++\ ++ "pand %%mm7, %%mm1 \n\t" /* B7 B6 */\ ++ "pand %%mm0, %%mm3 \n\t" /* G7 G6 G5 */\ ++ "pand "MANGLE(ff_M24B)", %%mm6 \n\t" /* R7 R6 R5 */\ ++\ ++ "por %%mm1, %%mm3 \n\t"\ ++ "por %%mm3, %%mm6 \n\t"\ ++ MOVNTQ(%%mm6, 16(dst))\ ++\ ++ "add $24, "#dst" \n\t"\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++ ++#if COMPILE_TEMPLATE_MMX2 ++#undef WRITEBGR24 ++#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX2(dst, dstw, index) ++#else ++#undef WRITEBGR24 ++#define WRITEBGR24(dst, dstw, index) WRITEBGR24MMX(dst, dstw, index) ++#endif ++ ++static void RENAME(yuv2bgr24_X_ar)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX_ACCURATE ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c"\n\t" //FIXME optimize ++ "add %4, %%"REG_c" \n\t" ++ WRITEBGR24(%%REGc, %5, %%REGa) ++ :: "r" (&c->redDither), ++ "m" (dummy), "m" (dummy), "m" (dummy), ++ "r" (dest), "m" (dstW_reg), "m"(uv_off) ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S ++ ); ++} ++ ++static void RENAME(yuv2bgr24_X)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX ++ YSCALEYUV2RGBX ++ "pxor %%mm7, %%mm7 \n\t" ++ "lea (%%"REG_a", %%"REG_a", 2), %%"REG_c" \n\t" //FIXME optimize ++ "add %4, %%"REG_c" \n\t" ++ WRITEBGR24(%%REGc, %5, %%REGa) ++ :: "r" (&c->redDither), ++ "m" (dummy), "m" (dummy), "m" (dummy), ++ "r" (dest), "m" (dstW_reg), "m"(uv_off) ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S ++ ); ++} ++ ++#define REAL_WRITEYUY2(dst, dstw, index) \ ++ "packuswb %%mm3, %%mm3 \n\t"\ ++ "packuswb %%mm4, %%mm4 \n\t"\ ++ "packuswb %%mm7, %%mm1 \n\t"\ ++ "punpcklbw %%mm4, %%mm3 \n\t"\ ++ "movq %%mm1, %%mm7 \n\t"\ ++ "punpcklbw %%mm3, %%mm1 \n\t"\ ++ "punpckhbw %%mm3, %%mm7 \n\t"\ ++\ ++ MOVNTQ(%%mm1, (dst, index, 2))\ ++ MOVNTQ(%%mm7, 8(dst, index, 2))\ ++\ ++ "add $8, "#index" \n\t"\ ++ "cmp "#dstw", "#index" \n\t"\ ++ " jb 1b \n\t" ++#define WRITEYUY2(dst, dstw, index) REAL_WRITEYUY2(dst, dstw, index) ++ ++static void RENAME(yuv2yuyv422_X_ar)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX_ACCURATE ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++ "psraw $3, %%mm3 \n\t" ++ "psraw $3, %%mm4 \n\t" ++ "psraw $3, %%mm1 \n\t" ++ "psraw $3, %%mm7 \n\t" ++ WRITEYUY2(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++static void RENAME(yuv2yuyv422_X)(SwsContext *c, const int16_t *lumFilter, ++ const int16_t **lumSrc, int lumFilterSize, ++ const int16_t *chrFilter, const int16_t **chrUSrc, ++ const int16_t **chrVSrc, ++ int chrFilterSize, const int16_t **alpSrc, ++ uint8_t *dest, int dstW, int dstY) ++{ ++ x86_reg dummy=0; ++ x86_reg dstW_reg = dstW; ++ x86_reg uv_off = c->uv_offx2; ++ ++ YSCALEYUV2PACKEDX ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++ "psraw $3, %%mm3 \n\t" ++ "psraw $3, %%mm4 \n\t" ++ "psraw $3, %%mm1 \n\t" ++ "psraw $3, %%mm7 \n\t" ++ WRITEYUY2(%4, %5, %%REGa) ++ YSCALEYUV2PACKEDX_END ++} ++ ++#define REAL_YSCALEYUV2RGB_UV(index, c) \ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ ++ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ ++ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ ++ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ ++ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ ++ "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ ++ "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ ++ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ ++ "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ ++ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ ++ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ ++ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ ++ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ ++ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ ++ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ ++ "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ ++ "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ ++ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ ++ ++#define REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) \ ++ "movq ("#b1", "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ ++ "movq ("#b2", "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ ++ "movq 8("#b1", "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ ++ "movq 8("#b2", "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ ++ "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ ++ "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ ++ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ ++ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ ++ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ ++ "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ ++ ++#define REAL_YSCALEYUV2RGB_COEFF(c) \ ++ "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ ++ "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ ++ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ ++ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ ++ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ ++ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ ++ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ ++ "paddw %%mm3, %%mm4 \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "movq %%mm5, %%mm6 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++ "punpcklwd %%mm2, %%mm2 \n\t"\ ++ "punpcklwd %%mm5, %%mm5 \n\t"\ ++ "punpcklwd %%mm4, %%mm4 \n\t"\ ++ "paddw %%mm1, %%mm2 \n\t"\ ++ "paddw %%mm1, %%mm5 \n\t"\ ++ "paddw %%mm1, %%mm4 \n\t"\ ++ "punpckhwd %%mm0, %%mm0 \n\t"\ ++ "punpckhwd %%mm6, %%mm6 \n\t"\ ++ "punpckhwd %%mm3, %%mm3 \n\t"\ ++ "paddw %%mm7, %%mm0 \n\t"\ ++ "paddw %%mm7, %%mm6 \n\t"\ ++ "paddw %%mm7, %%mm3 \n\t"\ ++ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ ++ "packuswb %%mm0, %%mm2 \n\t"\ ++ "packuswb %%mm6, %%mm5 \n\t"\ ++ "packuswb %%mm3, %%mm4 \n\t"\ ++ ++#define YSCALEYUV2RGB_YA(index, c, b1, b2) REAL_YSCALEYUV2RGB_YA(index, c, b1, b2) ++ ++#define YSCALEYUV2RGB(index, c) \ ++ REAL_YSCALEYUV2RGB_UV(index, c) \ ++ REAL_YSCALEYUV2RGB_YA(index, c, %0, %1) \ ++ REAL_YSCALEYUV2RGB_COEFF(c) ++ ++/** ++ * vertical bilinear scale YV12 to RGB ++ */ ++static void RENAME(yuv2rgb32_2)(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ ++ if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { ++ const int16_t *abuf0 = abuf[0], *abuf1 = abuf[1]; ++#if ARCH_X86_64 ++ __asm__ volatile( ++ YSCALEYUV2RGB(%%r8, %5) ++ YSCALEYUV2RGB_YA(%%r8, %5, %6, %7) ++ "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ ++ "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ ++ "packuswb %%mm7, %%mm1 \n\t" ++ WRITEBGR32(%4, 8280(%5), %%r8, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "r" (dest), ++ "a" (&c->redDither), ++ "r" (abuf0), "r" (abuf1) ++ : "%r8" ++ ); ++#else ++ c->u_temp=(intptr_t)abuf0; ++ c->v_temp=(intptr_t)abuf1; ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB(%%REGBP, %5) ++ "push %0 \n\t" ++ "push %1 \n\t" ++ "mov "U_TEMP"(%5), %0 \n\t" ++ "mov "V_TEMP"(%5), %1 \n\t" ++ YSCALEYUV2RGB_YA(%%REGBP, %5, %0, %1) ++ "psraw $3, %%mm1 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ ++ "psraw $3, %%mm7 \n\t" /* abuf0[eax] - abuf1[eax] >>7*/ ++ "packuswb %%mm7, %%mm1 \n\t" ++ "pop %1 \n\t" ++ "pop %0 \n\t" ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm1, %%mm0, %%mm7, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++#endif ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB(%%REGBP, %5) ++ "pcmpeqd %%mm7, %%mm7 \n\t" ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++} ++ ++static void RENAME(yuv2bgr24_2)(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ ++ //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ WRITEBGR24(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++} ++ ++static void RENAME(yuv2rgb555_2)(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ ++ //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB15(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++} ++ ++static void RENAME(yuv2rgb565_2)(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ ++ //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB16(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++} ++ ++#define REAL_YSCALEYUV2PACKED(index, c) \ ++ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ ++ "movq "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm1 \n\t"\ ++ "psraw $3, %%mm0 \n\t"\ ++ "psraw $3, %%mm1 \n\t"\ ++ "movq %%mm0, "CHR_MMX_FILTER_OFFSET"+8("#c") \n\t"\ ++ "movq %%mm1, "LUM_MMX_FILTER_OFFSET"+8("#c") \n\t"\ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ ++ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ ++ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "psubw %%mm3, %%mm2 \n\t" /* uvbuf0[eax] - uvbuf1[eax]*/\ ++ "psubw %%mm4, %%mm5 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048]*/\ ++ "movq "CHR_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t"\ ++ "pmulhw %%mm0, %%mm2 \n\t" /* (uvbuf0[eax] - uvbuf1[eax])uvalpha1>>16*/\ ++ "pmulhw %%mm0, %%mm5 \n\t" /* (uvbuf0[eax+2048] - uvbuf1[eax+2048])uvalpha1>>16*/\ ++ "psraw $7, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ ++ "psraw $7, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ ++ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax]uvalpha1 - uvbuf1[eax](1-uvalpha1)*/\ ++ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048]uvalpha1 - uvbuf1[eax+2048](1-uvalpha1)*/\ ++ "movq (%0, "#index", 2), %%mm0 \n\t" /*buf0[eax]*/\ ++ "movq (%1, "#index", 2), %%mm1 \n\t" /*buf1[eax]*/\ ++ "movq 8(%0, "#index", 2), %%mm6 \n\t" /*buf0[eax]*/\ ++ "movq 8(%1, "#index", 2), %%mm7 \n\t" /*buf1[eax]*/\ ++ "psubw %%mm1, %%mm0 \n\t" /* buf0[eax] - buf1[eax]*/\ ++ "psubw %%mm7, %%mm6 \n\t" /* buf0[eax] - buf1[eax]*/\ ++ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm0 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ ++ "pmulhw "LUM_MMX_FILTER_OFFSET"+8("#c"), %%mm6 \n\t" /* (buf0[eax] - buf1[eax])yalpha1>>16*/\ ++ "psraw $7, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "psraw $7, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "paddw %%mm0, %%mm1 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ ++ "paddw %%mm6, %%mm7 \n\t" /* buf0[eax]yalpha1 + buf1[eax](1-yalpha1) >>16*/\ ++ ++#define YSCALEYUV2PACKED(index, c) REAL_YSCALEYUV2PACKED(index, c) ++ ++static void RENAME(yuv2yuyv422_2)(SwsContext *c, const int16_t *buf[2], ++ const int16_t *ubuf[2], const int16_t *vbuf[2], ++ const int16_t *abuf[2], uint8_t *dest, ++ int dstW, int yalpha, int uvalpha, int y) ++{ ++ const int16_t *buf0 = buf[0], *buf1 = buf[1], ++ *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ ++ //Note 8280 == DSTW_OFFSET but the preprocessor can't handle that there :( ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2PACKED(%%REGBP, %5) ++ WRITEYUY2(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++} ++ ++#define REAL_YSCALEYUV2RGB1(index, c) \ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "psraw $4, %%mm3 \n\t" /* uvbuf0[eax] - uvbuf1[eax] >>4*/\ ++ "psraw $4, %%mm4 \n\t" /* uvbuf0[eax+2048] - uvbuf1[eax+2048] >>4*/\ ++ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ ++ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ ++ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ ++ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ ++ "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ ++ "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ ++ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ ++ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ ++ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ ++ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ ++ "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ ++ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ ++ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ ++ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ ++ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ ++ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ ++ "paddw %%mm3, %%mm4 \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "movq %%mm5, %%mm6 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++ "punpcklwd %%mm2, %%mm2 \n\t"\ ++ "punpcklwd %%mm5, %%mm5 \n\t"\ ++ "punpcklwd %%mm4, %%mm4 \n\t"\ ++ "paddw %%mm1, %%mm2 \n\t"\ ++ "paddw %%mm1, %%mm5 \n\t"\ ++ "paddw %%mm1, %%mm4 \n\t"\ ++ "punpckhwd %%mm0, %%mm0 \n\t"\ ++ "punpckhwd %%mm6, %%mm6 \n\t"\ ++ "punpckhwd %%mm3, %%mm3 \n\t"\ ++ "paddw %%mm7, %%mm0 \n\t"\ ++ "paddw %%mm7, %%mm6 \n\t"\ ++ "paddw %%mm7, %%mm3 \n\t"\ ++ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ ++ "packuswb %%mm0, %%mm2 \n\t"\ ++ "packuswb %%mm6, %%mm5 \n\t"\ ++ "packuswb %%mm3, %%mm4 \n\t"\ ++ ++#define YSCALEYUV2RGB1(index, c) REAL_YSCALEYUV2RGB1(index, c) ++ ++// do vertical chrominance interpolation ++#define REAL_YSCALEYUV2RGB1b(index, c) \ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ ++ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ ++ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ ++ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ ++ "psrlw $5, %%mm3 \n\t" /*FIXME might overflow*/\ ++ "psrlw $5, %%mm4 \n\t" /*FIXME might overflow*/\ ++ "psubw "U_OFFSET"("#c"), %%mm3 \n\t" /* (U-128)8*/\ ++ "psubw "V_OFFSET"("#c"), %%mm4 \n\t" /* (V-128)8*/\ ++ "movq %%mm3, %%mm2 \n\t" /* (U-128)8*/\ ++ "movq %%mm4, %%mm5 \n\t" /* (V-128)8*/\ ++ "pmulhw "UG_COEFF"("#c"), %%mm3 \n\t"\ ++ "pmulhw "VG_COEFF"("#c"), %%mm4 \n\t"\ ++ /* mm2=(U-128)8, mm3=ug, mm4=vg mm5=(V-128)8 */\ ++ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ ++ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ ++ "psraw $4, %%mm1 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "psraw $4, %%mm7 \n\t" /* buf0[eax] - buf1[eax] >>4*/\ ++ "pmulhw "UB_COEFF"("#c"), %%mm2 \n\t"\ ++ "pmulhw "VR_COEFF"("#c"), %%mm5 \n\t"\ ++ "psubw "Y_OFFSET"("#c"), %%mm1 \n\t" /* 8(Y-16)*/\ ++ "psubw "Y_OFFSET"("#c"), %%mm7 \n\t" /* 8(Y-16)*/\ ++ "pmulhw "Y_COEFF"("#c"), %%mm1 \n\t"\ ++ "pmulhw "Y_COEFF"("#c"), %%mm7 \n\t"\ ++ /* mm1= Y1, mm2=ub, mm3=ug, mm4=vg mm5=vr, mm7=Y2 */\ ++ "paddw %%mm3, %%mm4 \n\t"\ ++ "movq %%mm2, %%mm0 \n\t"\ ++ "movq %%mm5, %%mm6 \n\t"\ ++ "movq %%mm4, %%mm3 \n\t"\ ++ "punpcklwd %%mm2, %%mm2 \n\t"\ ++ "punpcklwd %%mm5, %%mm5 \n\t"\ ++ "punpcklwd %%mm4, %%mm4 \n\t"\ ++ "paddw %%mm1, %%mm2 \n\t"\ ++ "paddw %%mm1, %%mm5 \n\t"\ ++ "paddw %%mm1, %%mm4 \n\t"\ ++ "punpckhwd %%mm0, %%mm0 \n\t"\ ++ "punpckhwd %%mm6, %%mm6 \n\t"\ ++ "punpckhwd %%mm3, %%mm3 \n\t"\ ++ "paddw %%mm7, %%mm0 \n\t"\ ++ "paddw %%mm7, %%mm6 \n\t"\ ++ "paddw %%mm7, %%mm3 \n\t"\ ++ /* mm0=B1, mm2=B2, mm3=G2, mm4=G1, mm5=R1, mm6=R2 */\ ++ "packuswb %%mm0, %%mm2 \n\t"\ ++ "packuswb %%mm6, %%mm5 \n\t"\ ++ "packuswb %%mm3, %%mm4 \n\t"\ ++ ++#define YSCALEYUV2RGB1b(index, c) REAL_YSCALEYUV2RGB1b(index, c) ++ ++#define REAL_YSCALEYUV2RGB1_ALPHA(index) \ ++ "movq (%1, "#index", 2), %%mm7 \n\t" /* abuf0[index ] */\ ++ "movq 8(%1, "#index", 2), %%mm1 \n\t" /* abuf0[index+4] */\ ++ "psraw $7, %%mm7 \n\t" /* abuf0[index ] >>7 */\ ++ "psraw $7, %%mm1 \n\t" /* abuf0[index+4] >>7 */\ ++ "packuswb %%mm1, %%mm7 \n\t" ++#define YSCALEYUV2RGB1_ALPHA(index) REAL_YSCALEYUV2RGB1_ALPHA(index) ++ ++/** ++ * YV12 to RGB without scaling or interpolating ++ */ ++static void RENAME(yuv2rgb32_1)(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *bguf[2], ++ const int16_t *abuf0, uint8_t *dest, ++ int dstW, int uvalpha, int y) ++{ ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 ++ ++ if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster ++ if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1(%%REGBP, %5) ++ YSCALEYUV2RGB1_ALPHA(%%REGBP) ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1(%%REGBP, %5) ++ "pcmpeqd %%mm7, %%mm7 \n\t" ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++ } else { ++ if (CONFIG_SWSCALE_ALPHA && c->alpPixBuf) { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1b(%%REGBP, %5) ++ YSCALEYUV2RGB1_ALPHA(%%REGBP) ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (abuf0), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1b(%%REGBP, %5) ++ "pcmpeqd %%mm7, %%mm7 \n\t" ++ WRITEBGR32(%%REGb, 8280(%5), %%REGBP, %%mm2, %%mm4, %%mm5, %%mm7, %%mm0, %%mm1, %%mm3, %%mm6) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++ } ++} ++ ++static void RENAME(yuv2bgr24_1)(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *bguf[2], ++ const int16_t *abuf0, uint8_t *dest, ++ int dstW, int uvalpha, int y) ++{ ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 ++ ++ if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ WRITEBGR24(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1b(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ WRITEBGR24(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++} ++ ++static void RENAME(yuv2rgb555_1)(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *bguf[2], ++ const int16_t *abuf0, uint8_t *dest, ++ int dstW, int uvalpha, int y) ++{ ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 ++ ++ if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB15(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1b(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB15(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++} ++ ++static void RENAME(yuv2rgb565_1)(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *bguf[2], ++ const int16_t *abuf0, uint8_t *dest, ++ int dstW, int uvalpha, int y) ++{ ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 ++ ++ if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB16(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2RGB1b(%%REGBP, %5) ++ "pxor %%mm7, %%mm7 \n\t" ++ /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */ ++#ifdef DITHER1XBPP ++ "paddusb "BLUE_DITHER"(%5), %%mm2 \n\t" ++ "paddusb "GREEN_DITHER"(%5), %%mm4 \n\t" ++ "paddusb "RED_DITHER"(%5), %%mm5 \n\t" ++#endif ++ WRITERGB16(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++} ++ ++#define REAL_YSCALEYUV2PACKED1(index, c) \ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm3 \n\t" /* uvbuf0[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm4 \n\t" /* uvbuf0[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "psraw $7, %%mm3 \n\t" \ ++ "psraw $7, %%mm4 \n\t" \ ++ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ ++ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ ++ "psraw $7, %%mm1 \n\t" \ ++ "psraw $7, %%mm7 \n\t" \ ++ ++#define YSCALEYUV2PACKED1(index, c) REAL_YSCALEYUV2PACKED1(index, c) ++ ++#define REAL_YSCALEYUV2PACKED1b(index, c) \ ++ "xor "#index", "#index" \n\t"\ ++ ".p2align 4 \n\t"\ ++ "1: \n\t"\ ++ "movq (%2, "#index"), %%mm2 \n\t" /* uvbuf0[eax]*/\ ++ "movq (%3, "#index"), %%mm3 \n\t" /* uvbuf1[eax]*/\ ++ "add "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "movq (%2, "#index"), %%mm5 \n\t" /* uvbuf0[eax+2048]*/\ ++ "movq (%3, "#index"), %%mm4 \n\t" /* uvbuf1[eax+2048]*/\ ++ "sub "UV_OFF_BYTE"("#c"), "#index" \n\t" \ ++ "paddw %%mm2, %%mm3 \n\t" /* uvbuf0[eax] + uvbuf1[eax]*/\ ++ "paddw %%mm5, %%mm4 \n\t" /* uvbuf0[eax+2048] + uvbuf1[eax+2048]*/\ ++ "psrlw $8, %%mm3 \n\t" \ ++ "psrlw $8, %%mm4 \n\t" \ ++ "movq (%0, "#index", 2), %%mm1 \n\t" /*buf0[eax]*/\ ++ "movq 8(%0, "#index", 2), %%mm7 \n\t" /*buf0[eax]*/\ ++ "psraw $7, %%mm1 \n\t" \ ++ "psraw $7, %%mm7 \n\t" ++#define YSCALEYUV2PACKED1b(index, c) REAL_YSCALEYUV2PACKED1b(index, c) ++ ++static void RENAME(yuv2yuyv422_1)(SwsContext *c, const int16_t *buf0, ++ const int16_t *ubuf[2], const int16_t *bguf[2], ++ const int16_t *abuf0, uint8_t *dest, ++ int dstW, int uvalpha, int y) ++{ ++ const int16_t *ubuf0 = ubuf[0], *ubuf1 = ubuf[1]; ++ const int16_t *buf1= buf0; //FIXME needed for RGB1/BGR1 ++ ++ if (uvalpha < 2048) { // note this is not correct (shifts chrominance by 0.5 pixels) but it is a bit faster ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2PACKED1(%%REGBP, %5) ++ WRITEYUY2(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } else { ++ __asm__ volatile( ++ "mov %%"REG_b", "ESP_OFFSET"(%5) \n\t" ++ "mov %4, %%"REG_b" \n\t" ++ "push %%"REG_BP" \n\t" ++ YSCALEYUV2PACKED1b(%%REGBP, %5) ++ WRITEYUY2(%%REGb, 8280(%5), %%REGBP) ++ "pop %%"REG_BP" \n\t" ++ "mov "ESP_OFFSET"(%5), %%"REG_b" \n\t" ++ :: "c" (buf0), "d" (buf1), "S" (ubuf0), "D" (ubuf1), "m" (dest), ++ "a" (&c->redDither) ++ ); ++ } ++} ++ ++static av_always_inline void RENAME(bgr24ToY_mmx)(int16_t *dst, const uint8_t *src, ++ int width, enum PixelFormat srcFormat) ++{ ++ ++ if(srcFormat == PIX_FMT_BGR24) { ++ __asm__ volatile( ++ "movq "MANGLE(ff_bgr24toY1Coeff)", %%mm5 \n\t" ++ "movq "MANGLE(ff_bgr24toY2Coeff)", %%mm6 \n\t" ++ : ++ ); ++ } else { ++ __asm__ volatile( ++ "movq "MANGLE(ff_rgb24toY1Coeff)", %%mm5 \n\t" ++ "movq "MANGLE(ff_rgb24toY2Coeff)", %%mm6 \n\t" ++ : ++ ); ++ } ++ ++ __asm__ volatile( ++ "movq "MANGLE(ff_bgr24toYOffset)", %%mm4 \n\t" ++ "mov %2, %%"REG_a" \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ "1: \n\t" ++ PREFETCH" 64(%0) \n\t" ++ "movd (%0), %%mm0 \n\t" ++ "movd 2(%0), %%mm1 \n\t" ++ "movd 6(%0), %%mm2 \n\t" ++ "movd 8(%0), %%mm3 \n\t" ++ "add $12, %0 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm2 \n\t" ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ "pmaddwd %%mm5, %%mm0 \n\t" ++ "pmaddwd %%mm6, %%mm1 \n\t" ++ "pmaddwd %%mm5, %%mm2 \n\t" ++ "pmaddwd %%mm6, %%mm3 \n\t" ++ "paddd %%mm1, %%mm0 \n\t" ++ "paddd %%mm3, %%mm2 \n\t" ++ "paddd %%mm4, %%mm0 \n\t" ++ "paddd %%mm4, %%mm2 \n\t" ++ "psrad $9, %%mm0 \n\t" ++ "psrad $9, %%mm2 \n\t" ++ "packssdw %%mm2, %%mm0 \n\t" ++ "movq %%mm0, (%1, %%"REG_a") \n\t" ++ "add $8, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ : "+r" (src) ++ : "r" (dst+width), "g" ((x86_reg)-2*width) ++ : "%"REG_a ++ ); ++} ++ ++static void RENAME(bgr24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, ++ int width, uint32_t *unused) ++{ ++ RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_BGR24); ++} ++ ++static void RENAME(rgb24ToY)(int16_t *dst, const uint8_t *src, const uint8_t *unused1, const uint8_t *unused2, ++ int width, uint32_t *unused) ++{ ++ RENAME(bgr24ToY_mmx)(dst, src, width, PIX_FMT_RGB24); ++} ++ ++static av_always_inline void RENAME(bgr24ToUV_mmx)(int16_t *dstU, int16_t *dstV, ++ const uint8_t *src, int width, ++ enum PixelFormat srcFormat) ++{ ++ __asm__ volatile( ++ "movq 24(%4), %%mm6 \n\t" ++ "mov %3, %%"REG_a" \n\t" ++ "pxor %%mm7, %%mm7 \n\t" ++ "1: \n\t" ++ PREFETCH" 64(%0) \n\t" ++ "movd (%0), %%mm0 \n\t" ++ "movd 2(%0), %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "movq %%mm0, %%mm2 \n\t" ++ "movq %%mm1, %%mm3 \n\t" ++ "pmaddwd (%4), %%mm0 \n\t" ++ "pmaddwd 8(%4), %%mm1 \n\t" ++ "pmaddwd 16(%4), %%mm2 \n\t" ++ "pmaddwd %%mm6, %%mm3 \n\t" ++ "paddd %%mm1, %%mm0 \n\t" ++ "paddd %%mm3, %%mm2 \n\t" ++ ++ "movd 6(%0), %%mm1 \n\t" ++ "movd 8(%0), %%mm3 \n\t" ++ "add $12, %0 \n\t" ++ "punpcklbw %%mm7, %%mm1 \n\t" ++ "punpcklbw %%mm7, %%mm3 \n\t" ++ "movq %%mm1, %%mm4 \n\t" ++ "movq %%mm3, %%mm5 \n\t" ++ "pmaddwd (%4), %%mm1 \n\t" ++ "pmaddwd 8(%4), %%mm3 \n\t" ++ "pmaddwd 16(%4), %%mm4 \n\t" ++ "pmaddwd %%mm6, %%mm5 \n\t" ++ "paddd %%mm3, %%mm1 \n\t" ++ "paddd %%mm5, %%mm4 \n\t" ++ ++ "movq "MANGLE(ff_bgr24toUVOffset)", %%mm3 \n\t" ++ "paddd %%mm3, %%mm0 \n\t" ++ "paddd %%mm3, %%mm2 \n\t" ++ "paddd %%mm3, %%mm1 \n\t" ++ "paddd %%mm3, %%mm4 \n\t" ++ "psrad $9, %%mm0 \n\t" ++ "psrad $9, %%mm2 \n\t" ++ "psrad $9, %%mm1 \n\t" ++ "psrad $9, %%mm4 \n\t" ++ "packssdw %%mm1, %%mm0 \n\t" ++ "packssdw %%mm4, %%mm2 \n\t" ++ "movq %%mm0, (%1, %%"REG_a") \n\t" ++ "movq %%mm2, (%2, %%"REG_a") \n\t" ++ "add $8, %%"REG_a" \n\t" ++ " js 1b \n\t" ++ : "+r" (src) ++ : "r" (dstU+width), "r" (dstV+width), "g" ((x86_reg)-2*width), "r"(ff_bgr24toUV[srcFormat == PIX_FMT_RGB24]) ++ : "%"REG_a ++ ); ++} ++ ++static void RENAME(bgr24ToUV)(int16_t *dstU, int16_t *dstV, ++ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2, ++ int width, uint32_t *unused) ++{ ++ RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_BGR24); ++ assert(src1 == src2); ++} ++ ++static void RENAME(rgb24ToUV)(int16_t *dstU, int16_t *dstV, ++ const uint8_t *unused1, const uint8_t *src1, const uint8_t *src2, ++ int width, uint32_t *unused) ++{ ++ assert(src1==src2); ++ RENAME(bgr24ToUV_mmx)(dstU, dstV, src1, width, PIX_FMT_RGB24); ++} ++ ++#if COMPILE_TEMPLATE_MMX2 ++static void RENAME(hyscale_fast)(SwsContext *c, int16_t *dst, ++ int dstWidth, const uint8_t *src, ++ int srcW, int xInc) ++{ ++ int32_t *filterPos = c->hLumFilterPos; ++ int16_t *filter = c->hLumFilter; ++ void *mmx2FilterCode= c->lumMmx2FilterCode; ++ int i; ++#if defined(PIC) ++ uint64_t ebxsave; ++#endif ++#if ARCH_X86_64 ++ uint64_t retsave; ++#endif ++ ++ __asm__ volatile( ++#if defined(PIC) ++ "mov %%"REG_b", %5 \n\t" ++#if ARCH_X86_64 ++ "mov -8(%%rsp), %%"REG_a" \n\t" ++ "mov %%"REG_a", %6 \n\t" ++#endif ++#else ++#if ARCH_X86_64 ++ "mov -8(%%rsp), %%"REG_a" \n\t" ++ "mov %%"REG_a", %5 \n\t" ++#endif ++#endif ++ "pxor %%mm7, %%mm7 \n\t" ++ "mov %0, %%"REG_c" \n\t" ++ "mov %1, %%"REG_D" \n\t" ++ "mov %2, %%"REG_d" \n\t" ++ "mov %3, %%"REG_b" \n\t" ++ "xor %%"REG_a", %%"REG_a" \n\t" // i ++ PREFETCH" (%%"REG_c") \n\t" ++ PREFETCH" 32(%%"REG_c") \n\t" ++ PREFETCH" 64(%%"REG_c") \n\t" ++ ++#if ARCH_X86_64 ++#define CALL_MMX2_FILTER_CODE \ ++ "movl (%%"REG_b"), %%esi \n\t"\ ++ "call *%4 \n\t"\ ++ "movl (%%"REG_b", %%"REG_a"), %%esi \n\t"\ ++ "add %%"REG_S", %%"REG_c" \n\t"\ ++ "add %%"REG_a", %%"REG_D" \n\t"\ ++ "xor %%"REG_a", %%"REG_a" \n\t"\ ++ ++#else ++#define CALL_MMX2_FILTER_CODE \ ++ "movl (%%"REG_b"), %%esi \n\t"\ ++ "call *%4 \n\t"\ ++ "addl (%%"REG_b", %%"REG_a"), %%"REG_c" \n\t"\ ++ "add %%"REG_a", %%"REG_D" \n\t"\ ++ "xor %%"REG_a", %%"REG_a" \n\t"\ ++ ++#endif /* ARCH_X86_64 */ ++ ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ ++#if defined(PIC) ++ "mov %5, %%"REG_b" \n\t" ++#if ARCH_X86_64 ++ "mov %6, %%"REG_a" \n\t" ++ "mov %%"REG_a", -8(%%rsp) \n\t" ++#endif ++#else ++#if ARCH_X86_64 ++ "mov %5, %%"REG_a" \n\t" ++ "mov %%"REG_a", -8(%%rsp) \n\t" ++#endif ++#endif ++ :: "m" (src), "m" (dst), "m" (filter), "m" (filterPos), ++ "m" (mmx2FilterCode) ++#if defined(PIC) ++ ,"m" (ebxsave) ++#endif ++#if ARCH_X86_64 ++ ,"m"(retsave) ++#endif ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D ++#if !defined(PIC) ++ ,"%"REG_b ++#endif ++ ); ++ ++ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) ++ dst[i] = src[srcW-1]*128; ++} ++ ++static void RENAME(hcscale_fast)(SwsContext *c, int16_t *dst1, int16_t *dst2, ++ int dstWidth, const uint8_t *src1, ++ const uint8_t *src2, int srcW, int xInc) ++{ ++ int32_t *filterPos = c->hChrFilterPos; ++ int16_t *filter = c->hChrFilter; ++ void *mmx2FilterCode= c->chrMmx2FilterCode; ++ int i; ++#if defined(PIC) ++ DECLARE_ALIGNED(8, uint64_t, ebxsave); ++#endif ++#if ARCH_X86_64 ++ DECLARE_ALIGNED(8, uint64_t, retsave); ++#endif ++ ++ __asm__ volatile( ++#if defined(PIC) ++ "mov %%"REG_b", %7 \n\t" ++#if ARCH_X86_64 ++ "mov -8(%%rsp), %%"REG_a" \n\t" ++ "mov %%"REG_a", %8 \n\t" ++#endif ++#else ++#if ARCH_X86_64 ++ "mov -8(%%rsp), %%"REG_a" \n\t" ++ "mov %%"REG_a", %7 \n\t" ++#endif ++#endif ++ "pxor %%mm7, %%mm7 \n\t" ++ "mov %0, %%"REG_c" \n\t" ++ "mov %1, %%"REG_D" \n\t" ++ "mov %2, %%"REG_d" \n\t" ++ "mov %3, %%"REG_b" \n\t" ++ "xor %%"REG_a", %%"REG_a" \n\t" // i ++ PREFETCH" (%%"REG_c") \n\t" ++ PREFETCH" 32(%%"REG_c") \n\t" ++ PREFETCH" 64(%%"REG_c") \n\t" ++ ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ "xor %%"REG_a", %%"REG_a" \n\t" // i ++ "mov %5, %%"REG_c" \n\t" // src ++ "mov %6, %%"REG_D" \n\t" // buf2 ++ PREFETCH" (%%"REG_c") \n\t" ++ PREFETCH" 32(%%"REG_c") \n\t" ++ PREFETCH" 64(%%"REG_c") \n\t" ++ ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ CALL_MMX2_FILTER_CODE ++ ++#if defined(PIC) ++ "mov %7, %%"REG_b" \n\t" ++#if ARCH_X86_64 ++ "mov %8, %%"REG_a" \n\t" ++ "mov %%"REG_a", -8(%%rsp) \n\t" ++#endif ++#else ++#if ARCH_X86_64 ++ "mov %7, %%"REG_a" \n\t" ++ "mov %%"REG_a", -8(%%rsp) \n\t" ++#endif ++#endif ++ :: "m" (src1), "m" (dst1), "m" (filter), "m" (filterPos), ++ "m" (mmx2FilterCode), "m" (src2), "m"(dst2) ++#if defined(PIC) ++ ,"m" (ebxsave) ++#endif ++#if ARCH_X86_64 ++ ,"m"(retsave) ++#endif ++ : "%"REG_a, "%"REG_c, "%"REG_d, "%"REG_S, "%"REG_D ++#if !defined(PIC) ++ ,"%"REG_b ++#endif ++ ); ++ ++ for (i=dstWidth-1; (i*xInc)>>16 >=srcW-1; i--) { ++ dst1[i] = src1[srcW-1]*128; ++ dst2[i] = src2[srcW-1]*128; ++ } ++} ++#endif /* COMPILE_TEMPLATE_MMX2 */ ++ ++static av_cold void RENAME(sws_init_swScale)(SwsContext *c) ++{ ++ enum PixelFormat srcFormat = c->srcFormat, ++ dstFormat = c->dstFormat; ++ c->use_mmx_vfilter= 0; ++ if (!is16BPS(dstFormat) && !is9_OR_10BPS(dstFormat) && dstFormat != PIX_FMT_NV12 ++ && dstFormat != PIX_FMT_NV21 && !(c->flags & SWS_BITEXACT)) { ++ if (c->flags & SWS_ACCURATE_RND) { ++ if (!(c->flags & SWS_FULL_CHR_H_INT)) { ++ switch (c->dstFormat) { ++ case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X_ar); break; ++ case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X_ar); break; ++ case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X_ar); break; ++ case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X_ar); break; ++ case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X_ar); break; ++ default: break; ++ } ++ } ++ } else { ++ c->use_mmx_vfilter= 1; ++ c->yuv2planeX = RENAME(yuv2yuvX ); ++ if (!(c->flags & SWS_FULL_CHR_H_INT)) { ++ switch (c->dstFormat) { ++ case PIX_FMT_RGB32: c->yuv2packedX = RENAME(yuv2rgb32_X); break; ++ case PIX_FMT_BGR24: c->yuv2packedX = RENAME(yuv2bgr24_X); break; ++ case PIX_FMT_RGB555: c->yuv2packedX = RENAME(yuv2rgb555_X); break; ++ case PIX_FMT_RGB565: c->yuv2packedX = RENAME(yuv2rgb565_X); break; ++ case PIX_FMT_YUYV422: c->yuv2packedX = RENAME(yuv2yuyv422_X); break; ++ default: break; ++ } ++ } ++ } ++ if (!(c->flags & SWS_FULL_CHR_H_INT)) { ++ switch (c->dstFormat) { ++ case PIX_FMT_RGB32: ++ c->yuv2packed1 = RENAME(yuv2rgb32_1); ++ c->yuv2packed2 = RENAME(yuv2rgb32_2); ++ break; ++ case PIX_FMT_BGR24: ++ c->yuv2packed1 = RENAME(yuv2bgr24_1); ++ c->yuv2packed2 = RENAME(yuv2bgr24_2); ++ break; ++ case PIX_FMT_RGB555: ++ c->yuv2packed1 = RENAME(yuv2rgb555_1); ++ c->yuv2packed2 = RENAME(yuv2rgb555_2); ++ break; ++ case PIX_FMT_RGB565: ++ c->yuv2packed1 = RENAME(yuv2rgb565_1); ++ c->yuv2packed2 = RENAME(yuv2rgb565_2); ++ break; ++ case PIX_FMT_YUYV422: ++ c->yuv2packed1 = RENAME(yuv2yuyv422_1); ++ c->yuv2packed2 = RENAME(yuv2yuyv422_2); ++ break; ++ default: ++ break; ++ } ++ } ++ } ++ ++ if (c->srcBpc == 8 && c->dstBpc <= 10) { ++ // Use the new MMX scaler if the MMX2 one can't be used (it is faster than the x86 ASM one). ++#if COMPILE_TEMPLATE_MMX2 ++ if (c->flags & SWS_FAST_BILINEAR && c->canMMX2BeUsed) ++ { ++ c->hyscale_fast = RENAME(hyscale_fast); ++ c->hcscale_fast = RENAME(hcscale_fast); ++ } else { ++#endif /* COMPILE_TEMPLATE_MMX2 */ ++ c->hyscale_fast = NULL; ++ c->hcscale_fast = NULL; ++#if COMPILE_TEMPLATE_MMX2 ++ } ++#endif /* COMPILE_TEMPLATE_MMX2 */ ++ } ++ ++ if (!c->chrSrcHSubSample) { ++ switch(srcFormat) { ++ case PIX_FMT_BGR24 : c->chrToYV12 = RENAME(bgr24ToUV); break; ++ case PIX_FMT_RGB24 : c->chrToYV12 = RENAME(rgb24ToUV); break; ++ default: break; ++ } ++ } ++ ++ switch (srcFormat) { ++ case PIX_FMT_BGR24 : c->lumToYV12 = RENAME(bgr24ToY); break; ++ case PIX_FMT_RGB24 : c->lumToYV12 = RENAME(rgb24ToY); break; ++ default: break; ++ } ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/yuv2rgb_mmx.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/yuv2rgb_mmx.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/yuv2rgb_mmx.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/yuv2rgb_mmx.c 2012-05-14 14:08:55.483363106 +0200 +@@ -34,6 +34,7 @@ + #include "libswscale/swscale.h" + #include "libswscale/swscale_internal.h" + #include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" + + #define DITHER1XBPP // only for MMX + +@@ -46,57 +47,56 @@ + DECLARE_ASM_CONST(8, uint64_t, pb_07) = 0x0707070707070707ULL; + + //MMX versions ++#if HAVE_MMX + #undef RENAME +-#undef HAVE_MMX2 +-#undef HAVE_AMD3DNOW +-#define HAVE_MMX2 0 +-#define HAVE_AMD3DNOW 0 ++#undef COMPILE_TEMPLATE_MMX2 ++#define COMPILE_TEMPLATE_MMX2 0 + #define RENAME(a) a ## _MMX + #include "yuv2rgb_template.c" ++#endif /* HAVE_MMX */ + + //MMX2 versions ++#if HAVE_MMX2 + #undef RENAME +-#undef HAVE_MMX2 +-#define HAVE_MMX2 1 ++#undef COMPILE_TEMPLATE_MMX2 ++#define COMPILE_TEMPLATE_MMX2 1 + #define RENAME(a) a ## _MMX2 + #include "yuv2rgb_template.c" ++#endif /* HAVE_MMX2 */ + + SwsFunc ff_yuv2rgb_init_mmx(SwsContext *c) + { +- if (c->flags & SWS_CPU_CAPS_MMX2) { ++ int cpu_flags = av_get_cpu_flags(); ++ ++#if HAVE_MMX2 ++ if (cpu_flags & AV_CPU_FLAG_MMX2) { + switch (c->dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { +- if (HAVE_7REGS) return yuva420_rgb32_MMX2; +- break; +- } else return yuv420_rgb32_MMX2; +- case PIX_FMT_BGR32: +- if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { +- if (HAVE_7REGS) return yuva420_bgr32_MMX2; +- break; +- } else return yuv420_bgr32_MMX2; + case PIX_FMT_RGB24: return yuv420_rgb24_MMX2; + case PIX_FMT_BGR24: return yuv420_bgr24_MMX2; +- case PIX_FMT_RGB565: return yuv420_rgb16_MMX2; +- case PIX_FMT_RGB555: return yuv420_rgb15_MMX2; + } + } +- if (c->flags & SWS_CPU_CAPS_MMX) { ++#endif ++ ++ if (cpu_flags & AV_CPU_FLAG_MMX) { + switch (c->dstFormat) { +- case PIX_FMT_RGB32: +- if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { +- if (HAVE_7REGS) return yuva420_rgb32_MMX; +- break; +- } else return yuv420_rgb32_MMX; +- case PIX_FMT_BGR32: +- if (CONFIG_SWSCALE_ALPHA && c->srcFormat == PIX_FMT_YUVA420P) { +- if (HAVE_7REGS) return yuva420_bgr32_MMX; +- break; +- } else return yuv420_bgr32_MMX; +- case PIX_FMT_RGB24: return yuv420_rgb24_MMX; +- case PIX_FMT_BGR24: return yuv420_bgr24_MMX; +- case PIX_FMT_RGB565: return yuv420_rgb16_MMX; +- case PIX_FMT_RGB555: return yuv420_rgb15_MMX; ++ case PIX_FMT_RGB32: ++ if (c->srcFormat == PIX_FMT_YUVA420P) { ++#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA ++ return yuva420_rgb32_MMX; ++#endif ++ break; ++ } else return yuv420_rgb32_MMX; ++ case PIX_FMT_BGR32: ++ if (c->srcFormat == PIX_FMT_YUVA420P) { ++#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA ++ return yuva420_bgr32_MMX; ++#endif ++ break; ++ } else return yuv420_bgr32_MMX; ++ case PIX_FMT_RGB24: return yuv420_rgb24_MMX; ++ case PIX_FMT_BGR24: return yuv420_bgr24_MMX; ++ case PIX_FMT_RGB565: return yuv420_rgb16_MMX; ++ case PIX_FMT_RGB555: return yuv420_rgb15_MMX; + } + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/yuv2rgb_template.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/yuv2rgb_template.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/x86/yuv2rgb_template.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/x86/yuv2rgb_template.c 2012-05-14 14:08:55.484363127 +0200 +@@ -25,14 +25,7 @@ + #undef EMMS + #undef SFENCE + +-#if HAVE_AMD3DNOW +-/* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */ +-#define EMMS "femms" +-#else +-#define EMMS "emms" +-#endif +- +-#if HAVE_MMX2 ++#if COMPILE_TEMPLATE_MMX2 + #define MOVNTQ "movntq" + #define SFENCE "sfence" + #else +@@ -50,17 +43,14 @@ + if (h_size * depth > FFABS(dstStride[0])) \ + h_size -= 8; \ + \ +- if (c->srcFormat == PIX_FMT_YUV422P) { \ +- srcStride[1] *= 2; \ +- srcStride[2] *= 2; \ +- } \ ++ vshift = c->srcFormat != PIX_FMT_YUV422P; \ + \ + __asm__ volatile ("pxor %mm4, %mm4\n\t"); \ + for (y = 0; y < srcSliceH; y++) { \ + uint8_t *image = dst[0] + (y + srcSliceY) * dstStride[0]; \ + const uint8_t *py = src[0] + y * srcStride[0]; \ +- const uint8_t *pu = src[1] + (y >> 1) * srcStride[1]; \ +- const uint8_t *pv = src[2] + (y >> 1) * srcStride[2]; \ ++ const uint8_t *pu = src[1] + (y >> vshift) * srcStride[1]; \ ++ const uint8_t *pv = src[2] + (y >> vshift) * srcStride[2]; \ + x86_reg index = -h_size / 2; \ + + #define YUV2RGB_INITIAL_LOAD \ +@@ -148,6 +138,7 @@ + : "+r" (index), "+r" (image) \ + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ + "r" (py - 2*index) \ ++ : "memory" \ + ); \ + } \ + +@@ -155,11 +146,13 @@ + : "+r" (index), "+r" (image) \ + : "r" (pu - index), "r" (pv - index), "r"(&c->redDither), \ + "r" (py - 2*index), "r" (pa - 2*index) \ ++ : "memory" \ + ); \ + } \ + + #define YUV2RGB_ENDFUNC \ +- __asm__ volatile (SFENCE"\n\t"EMMS); \ ++ __asm__ volatile (SFENCE"\n\t" \ ++ "emms \n\t"); \ + return srcSliceH; \ + + #define IF0(x) +@@ -188,12 +181,13 @@ + "paddusb "GREEN_DITHER"(%4), %%mm2\n\t" \ + "paddusb "RED_DITHER"(%4), %%mm1\n\t" \ + ++#if !COMPILE_TEMPLATE_MMX2 + static inline int RENAME(yuv420_rgb15)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(2) + +@@ -221,7 +215,7 @@ + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(2) + +@@ -243,6 +237,7 @@ + YUV2RGB_OPERANDS + YUV2RGB_ENDFUNC + } ++#endif /* !COMPILE_TEMPLATE_MMX2 */ + + #define RGB_PACK24(blue, red)\ + "packuswb %%mm3, %%mm0 \n" /* R0 R2 R4 R6 R1 R3 R5 R7 */\ +@@ -259,7 +254,7 @@ + "punpckhwd %%mm6, %%mm5 \n" /* R4 G4 B4 R5 R6 G6 B6 R7 */\ + RGB_PACK24_B + +-#if HAVE_MMX2 ++#if COMPILE_TEMPLATE_MMX2 + DECLARE_ASM_CONST(8, int16_t, mask1101[4]) = {-1,-1, 0,-1}; + DECLARE_ASM_CONST(8, int16_t, mask0010[4]) = { 0, 0,-1, 0}; + DECLARE_ASM_CONST(8, int16_t, mask0110[4]) = { 0,-1,-1, 0}; +@@ -310,7 +305,7 @@ + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(3) + +@@ -328,7 +323,7 @@ + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(3) + +@@ -366,12 +361,13 @@ + MOVNTQ " %%mm5, 16(%1)\n\t" \ + MOVNTQ " %%mm"alpha", 24(%1)\n\t" \ + ++#if !COMPILE_TEMPLATE_MMX2 + static inline int RENAME(yuv420_rgb32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(4) + +@@ -386,13 +382,13 @@ + YUV2RGB_ENDFUNC + } + ++#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA + static inline int RENAME(yuva420_rgb32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +-#if HAVE_7REGS +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(4) + +@@ -406,15 +402,15 @@ + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS_ALPHA + YUV2RGB_ENDFUNC +-#endif + } ++#endif + + static inline int RENAME(yuv420_bgr32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(4) + +@@ -429,13 +425,13 @@ + YUV2RGB_ENDFUNC + } + ++#if HAVE_7REGS && CONFIG_SWSCALE_ALPHA + static inline int RENAME(yuva420_bgr32)(SwsContext *c, const uint8_t *src[], + int srcStride[], + int srcSliceY, int srcSliceH, + uint8_t *dst[], int dstStride[]) + { +-#if HAVE_7REGS +- int y, h_size; ++ int y, h_size, vshift; + + YUV2RGB_LOOP(4) + +@@ -449,5 +445,7 @@ + YUV2RGB_ENDLOOP(4) + YUV2RGB_OPERANDS_ALPHA + YUV2RGB_ENDFUNC +-#endif + } ++#endif ++ ++#endif /* !COMPILE_TEMPLATE_MMX2 */ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/yuv2rgb.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/yuv2rgb.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/libswscale/yuv2rgb.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/libswscale/yuv2rgb.c 2012-05-14 14:08:55.486363167 +0200 +@@ -32,8 +32,9 @@ + #include "rgb2rgb.h" + #include "swscale.h" + #include "swscale_internal.h" +-#include "libavutil/x86_cpu.h" ++#include "libavutil/cpu.h" + #include "libavutil/bswap.h" ++#include "libavutil/pixdesc.h" + + extern const uint8_t dither_4x4_16[4][8]; + extern const uint8_t dither_8x8_32[8][8]; +@@ -61,9 +62,9 @@ + #define LOADCHROMA(i) \ + U = pu[i]; \ + V = pv[i]; \ +- r = (void *)c->table_rV[V]; \ +- g = (void *)(c->table_gU[U] + c->table_gV[V]); \ +- b = (void *)c->table_bU[U]; ++ r = (void *)c->table_rV[V+YUVRGB_TABLE_HEADROOM]; \ ++ g = (void *)(c->table_gU[U+YUVRGB_TABLE_HEADROOM] + c->table_gV[V+YUVRGB_TABLE_HEADROOM]); \ ++ b = (void *)c->table_bU[U+YUVRGB_TABLE_HEADROOM]; + + #define PUTRGB(dst,src,i) \ + Y = src[2*i]; \ +@@ -99,6 +100,16 @@ + dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \ + dst[12*i+10] = dst[12*i+11] = b[Y]; + ++#define PUTBGR48(dst,src,i) \ ++ Y = src[2*i]; \ ++ dst[12*i+ 0] = dst[12*i+ 1] = b[Y]; \ ++ dst[12*i+ 2] = dst[12*i+ 3] = g[Y]; \ ++ dst[12*i+ 4] = dst[12*i+ 5] = r[Y]; \ ++ Y = src[2*i+1]; \ ++ dst[12*i+ 6] = dst[12*i+ 7] = b[Y]; \ ++ dst[12*i+ 8] = dst[12*i+ 9] = g[Y]; \ ++ dst[12*i+10] = dst[12*i+11] = r[Y]; ++ + #define YUV2RGBFUNC(func_name, dst_type, alpha) \ + static int func_name(SwsContext *c, const uint8_t* src[], int srcStride[], int srcSliceY, \ + int srcSliceH, uint8_t* dst[], int dstStride[]) \ +@@ -175,6 +186,32 @@ + PUTRGB48(dst_1,py_1,1); + ENDYUV2RGBFUNC() + ++YUV2RGBFUNC(yuv2rgb_c_bgr48, uint8_t, 0) ++ LOADCHROMA(0); ++ PUTBGR48(dst_1,py_1,0); ++ PUTBGR48(dst_2,py_2,0); ++ ++ LOADCHROMA(1); ++ PUTBGR48(dst_2,py_2,1); ++ PUTBGR48(dst_1,py_1,1); ++ ++ LOADCHROMA(2); ++ PUTBGR48(dst_1,py_1,2); ++ PUTBGR48(dst_2,py_2,2); ++ ++ LOADCHROMA(3); ++ PUTBGR48(dst_2,py_2,3); ++ PUTBGR48(dst_1,py_1,3); ++ENDYUV2RGBLINE(48) ++ LOADCHROMA(0); ++ PUTBGR48(dst_1,py_1,0); ++ PUTBGR48(dst_2,py_2,0); ++ ++ LOADCHROMA(1); ++ PUTBGR48(dst_2,py_2,1); ++ PUTBGR48(dst_1,py_1,1); ++ENDYUV2RGBFUNC() ++ + YUV2RGBFUNC(yuv2rgb_c_32, uint32_t, 0) + LOADCHROMA(0); + PUTRGB(dst_1,py_1,0); +@@ -330,28 +367,6 @@ + PUTRGB(dst_1,py_1,3); + CLOSEYUV2RGBFUNC(8) + +-#if 0 // Currently unused +-// This is exactly the same code as yuv2rgb_c_32 except for the types of +-// r, g, b, dst_1, dst_2 +-YUV2RGBFUNC(yuv2rgb_c_8, uint8_t, 0) +- LOADCHROMA(0); +- PUTRGB(dst_1,py_1,0); +- PUTRGB(dst_2,py_2,0); +- +- LOADCHROMA(1); +- PUTRGB(dst_2,py_2,1); +- PUTRGB(dst_1,py_1,1); +- +- LOADCHROMA(2); +- PUTRGB(dst_1,py_1,2); +- PUTRGB(dst_2,py_2,2); +- +- LOADCHROMA(3); +- PUTRGB(dst_2,py_2,3); +- PUTRGB(dst_1,py_1,3); +-CLOSEYUV2RGBFUNC(8) +-#endif +- + // r, g, b, dst_1, dst_2 + YUV2RGBFUNC(yuv2rgb_c_12_ordered_dither, uint16_t, 0) + const uint8_t *d16 = dither_4x4_16[y&3]; +@@ -405,36 +420,6 @@ + PUTRGB8(dst_1,py_1,3,6); + CLOSEYUV2RGBFUNC(8) + +-#if 0 // Currently unused +-// This is exactly the same code as yuv2rgb_c_32 except for the types of +-// r, g, b, dst_1, dst_2 +-YUV2RGBFUNC(yuv2rgb_c_4, uint8_t, 0) +- int acc; +-#define PUTRGB4(dst,src,i) \ +- Y = src[2*i]; \ +- acc = r[Y] + g[Y] + b[Y]; \ +- Y = src[2*i+1]; \ +- acc |= (r[Y] + g[Y] + b[Y])<<4; \ +- dst[i] = acc; +- +- LOADCHROMA(0); +- PUTRGB4(dst_1,py_1,0); +- PUTRGB4(dst_2,py_2,0); +- +- LOADCHROMA(1); +- PUTRGB4(dst_2,py_2,1); +- PUTRGB4(dst_1,py_1,1); +- +- LOADCHROMA(2); +- PUTRGB4(dst_1,py_1,2); +- PUTRGB4(dst_2,py_2,2); +- +- LOADCHROMA(3); +- PUTRGB4(dst_2,py_2,3); +- PUTRGB4(dst_1,py_1,3); +-CLOSEYUV2RGBFUNC(4) +-#endif +- + YUV2RGBFUNC(yuv2rgb_c_4_ordered_dither, uint8_t, 0) + const uint8_t *d64 = dither_8x8_73[y&7]; + const uint8_t *d128 = dither_8x8_220[y&7]; +@@ -464,28 +449,6 @@ + PUTRGB4D(dst_1,py_1,3,6); + CLOSEYUV2RGBFUNC(4) + +-#if 0 // Currently unused +-// This is exactly the same code as yuv2rgb_c_32 except for the types of +-// r, g, b, dst_1, dst_2 +-YUV2RGBFUNC(yuv2rgb_c_4b, uint8_t, 0) +- LOADCHROMA(0); +- PUTRGB(dst_1,py_1,0); +- PUTRGB(dst_2,py_2,0); +- +- LOADCHROMA(1); +- PUTRGB(dst_2,py_2,1); +- PUTRGB(dst_1,py_1,1); +- +- LOADCHROMA(2); +- PUTRGB(dst_1,py_1,2); +- PUTRGB(dst_2,py_2,2); +- +- LOADCHROMA(3); +- PUTRGB(dst_2,py_2,3); +- PUTRGB(dst_1,py_1,3); +-CLOSEYUV2RGBFUNC(8) +-#endif +- + YUV2RGBFUNC(yuv2rgb_c_4b_ordered_dither, uint8_t, 0) + const uint8_t *d64 = dither_8x8_73[y&7]; + const uint8_t *d128 = dither_8x8_220[y&7]; +@@ -516,7 +479,7 @@ + YUV2RGBFUNC(yuv2rgb_c_1_ordered_dither, uint8_t, 0) + const uint8_t *d128 = dither_8x8_220[y&7]; + char out_1 = 0, out_2 = 0; +- g= c->table_gU[128] + c->table_gV[128]; ++ g= c->table_gU[128 + YUVRGB_TABLE_HEADROOM] + c->table_gV[128 + YUVRGB_TABLE_HEADROOM]; + + #define PUTRGB1(out,src,i,o) \ + Y = src[2*i]; \ +@@ -543,31 +506,28 @@ + SwsFunc ff_yuv2rgb_get_func_ptr(SwsContext *c) + { + SwsFunc t = NULL; +-#if HAVE_MMX +- t = ff_yuv2rgb_init_mmx(c); +-#endif +-#if HAVE_VIS +- t = ff_yuv2rgb_init_vis(c); +-#endif +-#if CONFIG_MLIB +- t = ff_yuv2rgb_init_mlib(c); +-#endif +-#if HAVE_ALTIVEC +- if (c->flags & SWS_CPU_CAPS_ALTIVEC) +- t = ff_yuv2rgb_init_altivec(c); +-#endif + +-#if ARCH_BFIN +- if (c->flags & SWS_CPU_CAPS_BFIN) ++ if (HAVE_MMX) { ++ t = ff_yuv2rgb_init_mmx(c); ++ } else if (HAVE_VIS) { ++ t = ff_yuv2rgb_init_vis(c); ++ } else if (CONFIG_MLIB) { ++ t = ff_yuv2rgb_init_mlib(c); ++ } else if (HAVE_ALTIVEC) { ++ t = ff_yuv2rgb_init_altivec(c); ++ } else if (ARCH_BFIN) { + t = ff_yuv2rgb_get_func_ptr_bfin(c); +-#endif ++ } + + if (t) + return t; + +- av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", sws_format_name(c->srcFormat), sws_format_name(c->dstFormat)); ++ av_log(c, AV_LOG_WARNING, "No accelerated colorspace conversion found from %s to %s.\n", ++ av_get_pix_fmt_name(c->srcFormat), av_get_pix_fmt_name(c->dstFormat)); + + switch (c->dstFormat) { ++ case PIX_FMT_BGR48BE: ++ case PIX_FMT_BGR48LE: return yuv2rgb_c_bgr48; + case PIX_FMT_RGB48BE: + case PIX_FMT_RGB48LE: return yuv2rgb_c_48; + case PIX_FMT_ARGB: +@@ -595,29 +555,27 @@ + return NULL; + } + +-static void fill_table(uint8_t* table[256], const int elemsize, const int inc, void *y_tab) ++static void fill_table(uint8_t* table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc, void *y_tab) + { + int i; +- int64_t cb = 0; + uint8_t *y_table = y_tab; + + y_table -= elemsize * (inc >> 9); + +- for (i = 0; i < 256; i++) { ++ for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) { ++ int64_t cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc; + table[i] = y_table + elemsize * (cb >> 16); +- cb += inc; + } + } + +-static void fill_gv_table(int table[256], const int elemsize, const int inc) ++static void fill_gv_table(int table[256 + 2*YUVRGB_TABLE_HEADROOM], const int elemsize, const int inc) + { + int i; +- int64_t cb = 0; + int off = -(inc >> 9); + +- for (i = 0; i < 256; i++) { ++ for (i = 0; i < 256 + 2*YUVRGB_TABLE_HEADROOM; i++) { ++ int64_t cb = av_clip(i-YUVRGB_TABLE_HEADROOM, 0, 255)*inc; + table[i] = elemsize * (off + (cb >> 16)); +- cb += inc; + } + } + +@@ -655,7 +613,7 @@ + uint8_t *y_table; + uint16_t *y_table16; + uint32_t *y_table32; +- int i, base, rbase, gbase, bbase, abase, needAlpha; ++ int i, base, rbase, gbase, bbase, av_uninit(abase), needAlpha; + const int yoffs = fullRange ? 384 : 326; + + int64_t crv = inv_table[0]; +@@ -830,8 +788,8 @@ + y_table32 = c->yuvTable; + yb = -(384<<16) - oy; + for (i = 0; i < 1024; i++) { +- uint8_t yval = av_clip_uint8((yb + 0x8000) >> 16); +- y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255 << abase)); ++ unsigned yval = av_clip_uint8((yb + 0x8000) >> 16); ++ y_table32[i ] = (yval << rbase) + (needAlpha ? 0 : (255u << abase)); + y_table32[i+1024] = yval << gbase; + y_table32[i+2048] = yval << bbase; + yb += cy; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/LICENSE xbmc-pvr-11.0.1.patch/lib/ffmpeg/LICENSE +--- xbmc-pvr-11.0.1/lib/ffmpeg/LICENSE 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/LICENSE 2012-05-14 14:08:53.097315086 +0200 +@@ -41,6 +41,6 @@ + those licenses. So to combine the OpenCORE libraries with FFmpeg, the license + version needs to be upgraded by passing --enable-version3 to configure. + +-The nonfree external library libfaac can be hooked up in FFmpeg. You need to +-pass --enable-nonfree to configure to enable it. Employ this option with care +-as FFmpeg then becomes nonfree and unredistributable. ++The nonfree external libraries libfaac and libaacplus can be hooked up in FFmpeg. ++You need to pass --enable-nonfree to configure to enable it. Employ this option ++with care as FFmpeg then becomes nonfree and unredistributable. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/MAINTAINERS xbmc-pvr-11.0.1.patch/lib/ffmpeg/MAINTAINERS +--- xbmc-pvr-11.0.1/lib/ffmpeg/MAINTAINERS 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/MAINTAINERS 2012-05-14 14:08:53.099315126 +0200 +@@ -4,6 +4,19 @@ + Below is a list of the people maintaining different parts of the + FFmpeg code. + ++Please try to keep entries where you are the maintainer upto date! ++ ++Names in () mean that the maintainer currently has no time to maintain the code. ++A CC after the name means that the maintainer prefers to be CC-ed on patches ++and related discussions. ++ ++ ++Project Leader ++============== ++ ++Michael Niedermayer ++ final design decisions ++ + + Applications + ============ +@@ -12,7 +25,7 @@ + ffmpeg.c Michael Niedermayer + + ffplay: +- ffplay.c Michael Niedermayer ++ ffplay.c Marton Balint + + ffprobe: + ffprobe.c Stefano Sabatini +@@ -31,13 +44,13 @@ + =================== + + documentation Mike Melanson +-website Robert Swain ++website Robert Swain, Lou Logan + build system (configure,Makefiles) Diego Biurrun, Mans Rullgard +-project server Diego Biurrun, Mans Rullgard +-mailinglists Michael Niedermayer, Baptiste Coudurier ++project server Ãrpád Gereöffy, Michael Niedermayer, Reimar Döffinger ++mailinglists Michael Niedermayer, Baptiste Coudurier, Lou Logan + presets Robert Swain + metadata subsystem Aurelien Jacobs +-release management Diego Biurrun, Reinhard Tartler ++release management Michael Niedermayer + + + libavutil +@@ -74,6 +87,8 @@ + bitstream.c, bitstream.h Michael Niedermayer + CABAC: + cabac.h, cabac.c Michael Niedermayer ++ codec names: ++ codec_names.sh Nicolas George + DSP utilities: + dsputils.c, dsputils.h Michael Niedermayer + entropy coding: +@@ -118,6 +133,7 @@ + cinepak.c Roberto Togni + cljr Alex Beregszaszi + cook.c, cookdata.h Benjamin Larsson ++ crystalhd.c Philip Langdale + cscd.c Reimar Doeffinger + dca.c Kostya Shishkov, Benjamin Larsson + dnxhd* Baptiste Coudurier +@@ -126,6 +142,7 @@ + dv.c Roman Shaposhnik + eacmv*, eaidct*, eat* Peter Ross + ffv1.c Michael Niedermayer ++ ffwavesynth.c Nicolas George + flac* Justin Ruggles + flashsv* Benjamin Larsson + flicvideo.c Mike Melanson +@@ -143,11 +160,14 @@ + interplayvideo.c Mike Melanson + ivi* Kostya Shishkov + jpeg_ls.c Kostya Shishkov ++ jvdec.c Peter Ross + kmvc.c Kostya Shishkov + lcl*.c Roberto Togni, Reimar Doeffinger ++ libcelt_dec.c Nicolas George + libgsm.c Michel Bardiaux + libdirac* David Conrad + libopenjpeg.c Jaikrishnan Menon ++ libopenjpegenc.c Michael Bradshaw + libschroedinger* David Conrad + libspeexdec.c Justin Ruggles + libtheoraenc.c David Conrad +@@ -190,7 +210,7 @@ + smc.c Mike Melanson + snow.c Michael Niedermayer, Loren Merritt + sonic.c Alex Beregszaszi +- srtdec.c Aurelien Jacobs ++ srt* Aurelien Jacobs + sunrast.c Ivo van Poorten + svq3.c Michael Niedermayer + targa.c Kostya Shishkov +@@ -202,7 +222,9 @@ + tta.c Alex Beregszaszi, Jaikrishnan Menon + txd.c Ivo van Poorten + ulti* Kostya Shishkov ++ v410*.c Derek Buitenhuis + vb.c Kostya Shishkov ++ vble.c Derek Buitenhuis + vc1* Kostya Shishkov + vcr1.c Michael Niedermayer + vmnc.c Kostya Shishkov +@@ -224,8 +246,11 @@ + zmbv* Kostya Shishkov + + Hardware acceleration: ++ crystalhd.c Philip Langdale + dxva2* Laurent Aimar ++ libstagefright.cpp Mohamed Naufal + vaapi* Gwenole Beauchesne ++ vda* Sebastien Zwickert + vdpau* Carl Eugen Hoyos + + +@@ -240,6 +265,18 @@ + vfwcap.c Ramiro Polla + + ++libavfilter ++=========== ++ ++Video filters: ++ graphdump.c Nicolas George ++ af_amerge.c Nicolas George ++ af_astreamsync.c Nicolas George ++ af_pan.c Nicolas George ++ vsrc_mandelbrot.c Michael Niedermayer ++ vf_yadif.c Michael Niedermayer ++ ++ + libavformat + =========== + +@@ -276,6 +313,8 @@ + ipmovie.c Mike Melanson + img2.c Michael Niedermayer + iss.c Stefan Gehrer ++ jvdec.c Peter Ross ++ libmodplug.c Clément BÅ“sch + libnut.c Oded Shimon + lmlm4.c Ivo van Poorten + lxfdec.c Tomas Härdin +@@ -283,6 +322,7 @@ + matroskadec.c Aurelien Jacobs + matroskaenc.c David Conrad + metadata* Aurelien Jacobs ++ microdvd* Aurelien Jacobs + mm.c Peter Ross + mov.c Michael Niedermayer, Baptiste Coudurier + movenc.c Michael Niedermayer, Baptiste Coudurier +@@ -293,6 +333,7 @@ + msnwc_tcp.c Ramiro Polla + mtv.c Reynaldo H. Verdejo Pinochet + mxf* Baptiste Coudurier ++ mxfdec.c Tomas Härdin + nsvdec.c Francois Revol + nut.c Michael Niedermayer + nuv.c Reimar Doeffinger +@@ -312,6 +353,7 @@ + rtpdec_asf.* Ronald S. Bultje + rtpenc_mpv.*, rtpenc_aac.* Martin Storsjo + rtsp.c Luca Barbato ++ sbgdec.c Nicolas George + sdp.c Martin Storsjo + segafilm.c Mike Melanson + siff.c Kostya Shishkov +@@ -350,8 +392,15 @@ + x86 Michael Niedermayer + + +-GnuPG Fingerprints of maintainers and others who have svn write access +-====================================================================== ++Releases ++======== ++ ++0.9 Michael Niedermayer ++ ++ ++ ++GnuPG Fingerprints of maintainers and contributors ++================================================== + + Anssi Hannula 1A92 FF42 2DD9 8D2E 8AF7 65A9 4278 C520 513D F3CB + Anton Khirnov 6D0C 6625 56F8 65D1 E5F5 814B B50A 1241 C067 07AB +@@ -361,12 +410,15 @@ + Benoit Fouet B22A 4F4F 43EF 636B BB66 FCDC 0023 AE1E 2985 49C8 + Daniel Verkamp 78A6 07ED 782C 653E C628 B8B9 F0EB 8DD8 2F0E 21C7 + Diego Biurrun 8227 1E31 B6D9 4994 7427 E220 9CAE D6CC 4757 FCC5 ++Gwenole Beauchesne 2E63 B3A6 3E44 37E2 017D 2704 53C7 6266 B153 99C4 + Jaikrishnan Menon 61A1 F09F 01C9 2D45 78E1 C862 25DC 8831 AF70 D368 + Justin Ruggles 3136 ECC0 C10D 6C04 5F43 CA29 FCBE CD2A 3787 1EBF + Loren Merritt ABD9 08F4 C920 3F65 D8BE 35D7 1540 DAA7 060F 56DE ++Lou Logan 7D68 DC73 CBEF EABB 671A B6CF 621C 2E28 82F8 DC3A + Luca Barbato 6677 4209 213C 8843 5B67 29E7 E84C 78C2 84E9 0E34 + Michael Niedermayer 9FF2 128B 147E F673 0BAD F133 611E C787 040B 0FAB +-Panagiotis Issaris 515C E262 10A8 FDCE 5481 7B9C 3AD7 D9A5 071D B3A9 ++Nicolas George 24CE 01CE 9ACC 5CEB 74D8 8D9D B063 D997 36E5 4C93 ++Panagiotis Issaris 6571 13A3 33D9 3726 F728 AA98 F643 B12E ECF3 E029 + Peter Ross A907 E02F A6E5 0CD2 34CD 20D2 6760 79C5 AC40 DD6B + Reimar Döffinger C61D 16E5 9E2C D10C 8958 38A4 0899 A2B9 06D4 D9C7 + Reinhard Tartler 9300 5DC2 7E87 6C37 ED7B CA9A 9808 3544 9453 48A4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/Makefile 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/Makefile 2012-05-14 14:08:53.100315146 +0200 +@@ -1,8 +1,14 @@ ++MAIN_MAKEFILE=1 + include config.mak + +-SRC_DIR = $(SRC_PATH_BARE) +- +-vpath %.texi $(SRC_PATH_BARE) ++vpath %.c $(SRC_PATH) ++vpath %.cpp $(SRC_PATH) ++vpath %.h $(SRC_PATH) ++vpath %.S $(SRC_PATH) ++vpath %.asm $(SRC_PATH) ++vpath %.v $(SRC_PATH) ++vpath %.texi $(SRC_PATH) ++vpath %/fate_config.sh.template $(SRC_PATH) + + PROGS-$(CONFIG_FFMPEG) += ffmpeg + PROGS-$(CONFIG_FFPLAY) += ffplay +@@ -10,18 +16,16 @@ + PROGS-$(CONFIG_FFSERVER) += ffserver + + PROGS := $(PROGS-yes:%=%$(EXESUF)) +-PROGS_G = $(PROGS-yes:%=%_g$(EXESUF)) ++INSTPROGS = $(PROGS-yes:%=%$(PROGSSUF)$(EXESUF)) + OBJS = $(PROGS-yes:%=%.o) cmdutils.o +-MANPAGES = $(PROGS-yes:%=doc/%.1) +-PODPAGES = $(PROGS-yes:%=doc/%.pod) +-HTMLPAGES = $(PROGS-yes:%=doc/%.html) +-TOOLS = $(addprefix tools/, $(addsuffix $(EXESUF), cws2fws pktdumper probetest qt-faststart trasher)) + TESTTOOLS = audiogen videogen rotozoom tiny_psnr base64 + HOSTPROGS := $(TESTTOOLS:%=tests/%) ++TOOLS = qt-faststart trasher ++TOOLS-$(CONFIG_ZLIB) += cws2fws + + BASENAMES = ffmpeg ffplay ffprobe ffserver +-ALLPROGS = $(BASENAMES:%=%$(EXESUF)) +-ALLPROGS_G = $(BASENAMES:%=%_g$(EXESUF)) ++ALLPROGS = $(BASENAMES:%=%$(PROGSSUF)$(EXESUF)) ++ALLPROGS_G = $(BASENAMES:%=%$(PROGSSUF)_g$(EXESUF)) + ALLMANPAGES = $(BASENAMES:%=%.1) + + FFLIBS-$(CONFIG_AVDEVICE) += avdevice +@@ -29,44 +33,40 @@ + FFLIBS-$(CONFIG_AVFORMAT) += avformat + FFLIBS-$(CONFIG_AVCODEC) += avcodec + FFLIBS-$(CONFIG_POSTPROC) += postproc ++FFLIBS-$(CONFIG_SWRESAMPLE)+= swresample + FFLIBS-$(CONFIG_SWSCALE) += swscale +-FFLIBS-$(CONFIG_AVCORE) += avcore + + FFLIBS := avutil + +-DATA_FILES := $(wildcard $(SRC_DIR)/ffpresets/*.ffpreset) ++DATA_FILES := $(wildcard $(SRC_PATH)/presets/*.ffpreset) $(SRC_PATH)/doc/ffprobe.xsd + + SKIPHEADERS = cmdutils_common_opts.h + +-include common.mak ++include $(SRC_PATH)/common.mak + +-FF_LDFLAGS := $(FFLDFLAGS) + FF_EXTRALIBS := $(FFEXTRALIBS) + FF_DEP_LIBS := $(DEP_LIBS) + +-ALL_TARGETS-$(CONFIG_DOC) += documentation ++all: $(PROGS) + +-ifdef PROGS +-INSTALL_TARGETS-yes += install-progs install-data +-INSTALL_TARGETS-$(CONFIG_DOC) += install-man +-endif +-INSTALL_PROGS_TARGETS-$(CONFIG_SHARED) = install-libs ++$(PROGS): %$(EXESUF): %$(PROGSSUF)_g$(EXESUF) ++ $(CP) $< $@$(PROGSSUF) ++ $(STRIP) $@$(PROGSSUF) + +-all: $(FF_DEP_LIBS) $(PROGS) $(ALL_TARGETS-yes) ++$(TOOLS): %$(EXESUF): %.o ++ $(LD) $(LDFLAGS) -o $@ $< $(ELIBS) + +-$(PROGS): %$(EXESUF): %_g$(EXESUF) +- $(CP) $< $@ +- $(STRIP) $@ ++tools/cws2fws$(EXESUF): ELIBS = -lz + + config.h: .config +-.config: $(wildcard $(FFLIBS:%=$(SRC_DIR)/lib%/all*.c)) ++.config: $(wildcard $(FFLIBS:%=$(SRC_PATH)/lib%/all*.c)) + @-tput bold 2>/dev/null + @-printf '\nWARNING: $(?F) newer than config.h, rerun configure\n\n' + @-tput sgr0 2>/dev/null + + SUBDIR_VARS := OBJS FFLIBS CLEANFILES DIRS TESTPROGS EXAMPLES SKIPHEADERS \ + ALTIVEC-OBJS MMX-OBJS NEON-OBJS X86-OBJS YASM-OBJS-FFT YASM-OBJS \ +- HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ++ HOSTPROGS BUILT_HEADERS TESTOBJS ARCH_HEADERS ARMV6-OBJS TOOLS + + define RESET + $(1) := +@@ -76,30 +76,28 @@ + define DOSUBDIR + $(foreach V,$(SUBDIR_VARS),$(eval $(call RESET,$(V)))) + SUBDIR := $(1)/ +-include $(1)/Makefile ++include $(SRC_PATH)/$(1)/Makefile ++-include $(SRC_PATH)/$(1)/$(ARCH)/Makefile ++include $(SRC_PATH)/library.mak + endef + + $(foreach D,$(FFLIBS),$(eval $(call DOSUBDIR,lib$(D)))) + ++ffplay.o: CFLAGS += $(SDL_CFLAGS) + ffplay_g$(EXESUF): FF_EXTRALIBS += $(SDL_LIBS) +-ffserver_g$(EXESUF): FF_LDFLAGS += $(FFSERVERLDFLAGS) ++ffserver_g$(EXESUF): LDFLAGS += $(FFSERVERLDFLAGS) + +-%_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) +- $(LD) $(FF_LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) ++%$(PROGSSUF)_g$(EXESUF): %.o cmdutils.o $(FF_DEP_LIBS) ++ $(LD) $(LDFLAGS) -o $@ $< cmdutils.o $(FF_EXTRALIBS) + +-tools/%$(EXESUF): tools/%.o +- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) ++OBJDIRS += tools + +-tools/%.o: tools/%.c +- $(CC) $(CPPFLAGS) $(CFLAGS) -c $(CC_O) $< ++-include $(wildcard tools/*.d) + +-ffplay.o: CFLAGS += $(SDL_CFLAGS) +- +-VERSION_SH = $(SRC_PATH_BARE)/version.sh +-GIT_LOG = $(SRC_PATH_BARE)/.git/logs/HEAD +-SVN_ENTRIES = $(SRC_PATH_BARE)/.svn/entries ++VERSION_SH = $(SRC_PATH)/version.sh ++GIT_LOG = $(SRC_PATH)/.git/logs/HEAD + +-.version: $(wildcard $(GIT_LOG) $(SVN_ENTRIES)) $(VERSION_SH) config.mak ++.version: $(wildcard $(GIT_LOG)) $(VERSION_SH) config.mak + .version: M=@ + + version.h .version: +@@ -109,45 +107,26 @@ + # force version.sh to run whenever version might have changed + -include .version + +-alltools: $(TOOLS) +- +-DOCS = $(addprefix doc/, developer.html faq.html general.html libavfilter.html) $(HTMLPAGES) $(MANPAGES) $(PODPAGES) +- +-documentation: $(DOCS) +- +--include $(wildcard $(DOCS:%=%.d)) +- +-TEXIDEP = awk '/^@include/ { printf "$@: $(@D)/%s\n", $$2 }' <$< >$(@:%=%.d) +- +-doc/%.html: TAG = HTML +-doc/%.html: doc/%.texi $(SRC_PATH_BARE)/doc/t2h.init +- $(Q)$(TEXIDEP) +- $(M)cd doc && texi2html -monolithic --init-file $(SRC_PATH_BARE)/doc/t2h.init $(<:doc/%=%) ++ifdef PROGS ++install: install-progs install-data ++endif + +-doc/%.pod: TAG = POD +-doc/%.pod: doc/%.texi +- $(Q)$(TEXIDEP) +- $(M)doc/texi2pod.pl $< $@ ++install: install-libs install-headers + +-doc/%.1: TAG = MAN +-doc/%.1: doc/%.pod +- $(M)pod2man --section=1 --center=" " --release=" " $< > $@ ++install-libs: install-libs-yes + +-install: $(INSTALL_TARGETS-yes) ++install-progs-yes: ++install-progs-$(CONFIG_SHARED): install-libs + +-install-progs: $(PROGS) $(INSTALL_PROGS_TARGETS-yes) ++install-progs: install-progs-yes $(PROGS) + $(Q)mkdir -p "$(BINDIR)" +- $(INSTALL) -c -m 755 $(PROGS) "$(BINDIR)" ++ $(INSTALL) -c -m 755 $(INSTPROGS) "$(BINDIR)" + + install-data: $(DATA_FILES) + $(Q)mkdir -p "$(DATADIR)" + $(INSTALL) -m 644 $(DATA_FILES) "$(DATADIR)" + +-install-man: $(MANPAGES) +- $(Q)mkdir -p "$(MANDIR)/man1" +- $(INSTALL) -m 644 $(MANPAGES) "$(MANDIR)/man1" +- +-uninstall: uninstall-progs uninstall-data uninstall-man ++uninstall: uninstall-libs uninstall-headers uninstall-progs uninstall-data + + uninstall-progs: + $(RM) $(addprefix "$(BINDIR)/", $(ALLPROGS)) +@@ -155,143 +134,43 @@ + uninstall-data: + $(RM) -r "$(DATADIR)" + +-uninstall-man: +- $(RM) $(addprefix "$(MANDIR)/man1/",$(ALLMANPAGES)) +- +-testclean: +- $(RM) -r tests/vsynth1 tests/vsynth2 tests/data +- $(RM) $(addprefix tests/,$(CLEANSUFFIXES)) +- $(RM) tests/seek_test$(EXESUF) tests/seek_test.o +- $(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF)) +- +-clean:: testclean ++clean:: + $(RM) $(ALLPROGS) $(ALLPROGS_G) + $(RM) $(CLEANSUFFIXES) +- $(RM) doc/*.html doc/*.pod doc/*.1 + $(RM) $(TOOLS) ++ $(RM) $(CLEANSUFFIXES:%=tools/%) ++ $(RM) coverage.info ++ $(RM) -r coverage-html + + distclean:: + $(RM) $(DISTCLEANSUFFIXES) +- $(RM) version.h config.* libavutil/avconfig.h ++ $(RM) config.* .version version.h libavutil/avconfig.h + + config: + $(SRC_PATH)/configure $(value FFMPEG_CONFIGURATION) + +-# regression tests +- +-check: test checkheaders +- +-fulltest test: codectest lavftest lavfitest seektest +- +-FFSERVER_REFFILE = $(SRC_PATH)/tests/ffserver.regression.ref +-SEEK_REFFILE = $(SRC_PATH)/tests/seek.regression.ref +- +-codectest: fate-codec +-lavftest: fate-lavf +-lavfitest: fate-lavfi +-seektest: fate-seek +- +-AREF = tests/data/acodec.ref.wav +-VREF = tests/data/vsynth1.ref.yuv +-REFS = $(AREF) $(VREF) +- +-$(REFS): TAG = GEN +- +-$(VREF): ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm +- $(M)$(SRC_PATH)/tests/codec-regression.sh vref vsynth1 tests/vsynth1 "$(TARGET_EXEC)" "$(TARGET_PATH)" +- $(Q)$(SRC_PATH)/tests/codec-regression.sh vref vsynth2 tests/vsynth2 "$(TARGET_EXEC)" "$(TARGET_PATH)" +- +-$(AREF): ffmpeg$(EXESUF) tests/data/asynth1.sw +- $(M)$(SRC_PATH)/tests/codec-regression.sh aref acodec tests/acodec "$(TARGET_EXEC)" "$(TARGET_PATH)" +- +-ffservertest: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/data/asynth1.sw +- @echo +- @echo "Unfortunately ffserver is broken and therefore its regression" +- @echo "test fails randomly. Treat the results accordingly." +- @echo +- $(SRC_PATH)/tests/ffserver-regression.sh $(FFSERVER_REFFILE) $(SRC_PATH)/tests/ffserver.conf +- +-tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) +- @mkdir -p tests/vsynth1 +- $(M)$(BUILD_ROOT)/$< 'tests/vsynth1/' +- +-tests/vsynth2/00.pgm: tests/rotozoom$(HOSTEXESUF) +- @mkdir -p tests/vsynth2 +- $(M)$(BUILD_ROOT)/$< 'tests/vsynth2/' $(SRC_PATH)/tests/lena.pnm +- +-tests/data/asynth1.sw: tests/audiogen$(HOSTEXESUF) +- @mkdir -p tests/data +- $(M)$(BUILD_ROOT)/$< $@ +- +-tests/data/asynth1.sw tests/vsynth%/00.pgm: TAG = GEN +- +-tests/seek_test$(EXESUF): tests/seek_test.o $(FF_DEP_LIBS) +- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) +- +-tools/lavfi-showfiltfmts$(EXESUF): tools/lavfi-showfiltfmts.o $(FF_DEP_LIBS) +- $(LD) $(FF_LDFLAGS) -o $@ $< $(FF_EXTRALIBS) +- +-include $(SRC_PATH_BARE)/tests/fate.mak +-include $(SRC_PATH_BARE)/tests/fate2.mak +- +-include $(SRC_PATH_BARE)/tests/fate/aac.mak +-include $(SRC_PATH_BARE)/tests/fate/als.mak +-include $(SRC_PATH_BARE)/tests/fate/fft.mak +-include $(SRC_PATH_BARE)/tests/fate/h264.mak +-include $(SRC_PATH_BARE)/tests/fate/mp3.mak +-include $(SRC_PATH_BARE)/tests/fate/vorbis.mak +-include $(SRC_PATH_BARE)/tests/fate/vp8.mak +- +-FATE_ACODEC = $(ACODEC_TESTS:%=fate-acodec-%) +-FATE_VSYNTH1 = $(VCODEC_TESTS:%=fate-vsynth1-%) +-FATE_VSYNTH2 = $(VCODEC_TESTS:%=fate-vsynth2-%) +-FATE_VCODEC = $(FATE_VSYNTH1) $(FATE_VSYNTH2) +-FATE_LAVF = $(LAVF_TESTS:%=fate-lavf-%) +-FATE_LAVFI = $(LAVFI_TESTS:%=fate-lavfi-%) +-FATE_SEEK = $(SEEK_TESTS:seek_%=fate-seek-%) +- +-FATE = $(FATE_ACODEC) \ +- $(FATE_VCODEC) \ +- $(FATE_LAVF) \ +- $(FATE_LAVFI) \ +- $(FATE_SEEK) \ +- +-$(FATE_ACODEC): $(AREF) +-$(FATE_VCODEC): $(VREF) +-$(FATE_LAVF): $(REFS) +-$(FATE_LAVFI): $(REFS) tools/lavfi-showfiltfmts$(EXESUF) +-$(FATE_SEEK): fate-codec fate-lavf tests/seek_test$(EXESUF) +- +-$(FATE_ACODEC): CMD = codectest acodec +-$(FATE_VSYNTH1): CMD = codectest vsynth1 +-$(FATE_VSYNTH2): CMD = codectest vsynth2 +-$(FATE_LAVF): CMD = lavftest +-$(FATE_LAVFI): CMD = lavfitest +-$(FATE_SEEK): CMD = seektest +- +-fate-codec: fate-acodec fate-vcodec +-fate-acodec: $(FATE_ACODEC) +-fate-vcodec: $(FATE_VCODEC) +-fate-lavf: $(FATE_LAVF) +-fate-lavfi: $(FATE_LAVFI) +-fate-seek: $(FATE_SEEK) +- +-ifdef SAMPLES +-FATE += $(FATE_TESTS) +-else +-$(FATE_TESTS): +- @echo "SAMPLES not specified, cannot run FATE" +-endif +- +-FATE_UTILS = base64 tiny_psnr +- +-fate: $(FATE) +- +-$(FATE): ffmpeg$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF)) +- @echo "TEST $(@:fate-%=%)" +- $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' +- +-fate-list: +- @printf '%s\n' $(sort $(FATE)) ++# Without the sed genthml thinks "libavutil" and "./libavutil" are two different things ++coverage.info: $(wildcard *.gcda *.gcno */*.gcda */*.gcno */*/*.gcda */*/*.gcno) ++ $(Q)lcov -c -d . -b . | sed -e 's#/./#/#g' > $@ ++ ++coverage-html: coverage.info ++ $(Q)mkdir -p $@ ++ $(Q)genhtml -o $@ $< ++ $(Q)touch $@ ++ ++include $(SRC_PATH)/doc/Makefile ++include $(SRC_PATH)/tests/Makefile ++ ++$(sort $(OBJDIRS)): ++ $(Q)mkdir -p $@ ++ ++# Dummy rule to stop make trying to rebuild removed or renamed headers ++%.h: ++ @: ++ ++# Disable suffix rules. Most of the builtin rules are suffix rules, ++# so this saves some time on slow systems. ++.SUFFIXES: + +-.PHONY: documentation *test regtest-* alltools check config ++.PHONY: all all-yes alltools *clean config examples install* ++.PHONY: testprogs uninstall* +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/email.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/email.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/email.sh 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/email.sh 2012-05-14 14:08:55.487363187 +0200 +@@ -0,0 +1,6 @@ ++#!/bin/sh -v ++ ++# args [where to put patches] [smtp server] [destination] ++ ++git format-patch -o "$1" --inline --subject-prefix=soc --thread origin ++git send-email --no-chain-reply-to --smtp-server $2 --to $3 --dry-run "$1" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/mplayer.diff xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/mplayer.diff +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/mplayer.diff 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/mplayer.diff 2012-05-14 14:08:55.487363187 +0200 +@@ -0,0 +1,13 @@ ++diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c ++index 7c68a20..135e6b1 100644 ++--- a/libmpcodecs/vd_ffmpeg.c +++++ b/libmpcodecs/vd_ffmpeg.c ++@@ -280,7 +280,7 @@ static int init(sh_video_t *sh){ ++ return 0; ++ } ++ ++- if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug) +++ if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug && lavc_param_threads <= 1) ++ ctx->do_slices=1; ++ ++ if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264 && lavc_codec->id != CODEC_ID_INTERPLAY_VIDEO && lavc_codec->id != CODEC_ID_ROQ && lavc_codec->id != CODEC_ID_VP8 && lavc_codec->id != CODEC_ID_LAGARITH) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/raw.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/raw.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/raw.sh 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/raw.sh 2012-05-14 14:08:55.487363187 +0200 +@@ -0,0 +1,10 @@ ++#!/bin/bash ++ ++fn=`basename "$1"` ++for th in 1 4; do ++ time ./ffmpeg_g -threads $th -skip_loop_filter all -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/n-$fn-$th.yuv" ++done ++ ++#for th in 1 4; do ++# time ./ffmpeg_g -threads $th -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/$fn-$th.yuv" ++#done +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/test.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/test.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/test.sh 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/test.sh 2012-05-14 14:08:55.488363207 +0200 +@@ -0,0 +1,13 @@ ++#!/bin/bash ++ ++fn=`basename "$1"` ++for th in 1 2 3 4; do ++ time ./ffmpeg_g -threads $th -flags2 +fast -vsync 0 -y -t 30 -i "$1" -an -f framecrc "crc/$fn-$th.txt" >/dev/null 2>&1 ++done ++ ++./ffmpeg_g -threads 1 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-1-vsync.txt" >/dev/null 2>&1 ++./ffmpeg_g -threads 3 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-3-vsync.txt" >/dev/null 2>&1 ++ ++md5 "crc/$fn-"[1234].txt ++echo ++md5 "crc/$fn-"*vsync.txt +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/todo.txt xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/todo.txt +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/todo.txt 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/todo.txt 2012-05-14 14:08:55.488363207 +0200 +@@ -0,0 +1,95 @@ ++Todo ++ ++-- For other people ++- Multithread vc1. ++- Multithread an intra codec like mjpeg (trivial). ++- Fix mpeg1 (see below). ++- Try the first three items under Optimization. ++- Fix h264 (see below). ++- Try mpeg4 (see below). ++ ++-- Bug fixes ++ ++General critical: ++- Error resilience has to run before ff_report_frame_progress() ++is called. Otherwise there will be race conditions. (This might already ++work.) In general testing error paths should be done more. ++- 'make fate THREADS=2' doesn't pass. Most failures are due to ++bugs in vsync in ffmpeg.c, which are currently obscuring real failures. ++ ++h264: ++- Files that aren't parsed (e.g. mp4) and contain PAFF with two ++field pictures in the same packet are not optimal. Modify the ++nals_needed check so that the second field's first slice is ++considered as needed, then uncomment the FIXME code in decode_postinit. ++Ex: http://astrange.ithinksw.net/ffmpeg/mt-samples/PAFF-Chalet-Tire.mp4 ++ ++mpeg4: ++- Packed B-frames need to be explicitly split up ++when frame threading is on. It's not very fast ++without this. ++- The buffer age optimization is disabled due to ++the way buffers are allocated across threads. The ++branch 'fix_buffer_age' has an attempt to fix it ++which breaks ffplay. ++- Support interlaced. ++ ++mpeg1/2: ++- Seeking always prints "first frame not a keyframe" ++with threads on. Currently disabled for this reason. ++ ++-- Prove correct ++ ++- decode_update_progress() in h264.c ++race_checking branch has some work on h264, ++but not that function. It might be worth putting ++the branch under #ifdef DEBUG in mainline, but ++the code would have to be cleaner. ++- MPV_lowest_referenced_row() and co in mpegvideo.c ++- Same in vp3. ++ ++-- Optimization ++ ++- Merge h264 decode_update_progress() with loop_filter(). ++Add CODEC_CAP_DRAW_HORIZ_BAND as a side effect. ++- EMU_EDGE is always set for h264 PAFF+MT ++because draw_edges() writes into the other field's ++thread's pixels. Needs an option to skip T/B fields. ++- Check update_thread_context() functions and make ++sure they only copy what they need to. ++- Try some more optimization of the "ref < 48; ref++" ++loop in h264.c await_references(), try turning the list0/list1 check ++above into a loop without being slower. ++- Support frame+slice threading at the same time ++by assigning slice_count threads for frame threads ++to use with execute(). This is simpler but unbalanced ++if only one frame thread uses any. ++ ++-- Features ++ ++- Support streams with width/height changing. This ++requires flushing all current frames (and buffering ++the input in the meantime), closing the codec and ++reopening it. Or don't support it. ++- Support encoding. Might need more threading primitives ++for good ratecontrol; would be nice for audio and libavfilter too. ++- Async decoding part 1: instead of trying to ++start every thread at the beginning, return a picture ++if the earliest thread is already done, but don't wait ++for it. Not sure what effect this would have. ++- Part 2: have an API that doesn't wait for the decoding ++thread, only returns EAGAIN if it's not ready. What will ++it do with the next input packet if it returns that? ++- Have an API that returns finished pictures but doesn't ++require sending new ones. Maybe allow NULL avpkt when ++not at the end of the stream. ++ ++-- Samples ++ ++http://astrange.ithinksw.net/ffmpeg/mt-samples/ ++ ++See yuvcmp.c in this directory to compare decoded samples. ++ ++For debugging, try commenting out ff_thread_finish_setup calls so ++that only one thread runs at once, and then binary search+ ++scatter printfs to look for differences in codec contexts. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/valgrind-check.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/valgrind-check.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/valgrind-check.sh 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/valgrind-check.sh 2012-05-14 14:08:55.492363287 +0200 +@@ -0,0 +1,5 @@ ++#!/bin/bash ++ ++valgrind --track-origins=yes --leak-check=full ./ffmpeg_g -threads 1 -vsync 0 -y -t 30 -i "$1" -an -f null /dev/null ++ ++valgrind --track-origins=yes --leak-check=full ./ffmpeg_g -threads 3 -vsync 0 -y -t 30 -i "$1" -an -f null /dev/null +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/yuvcmp.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/yuvcmp.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/mt-work/yuvcmp.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/mt-work/yuvcmp.c 2012-05-14 14:08:55.493363308 +0200 +@@ -0,0 +1,182 @@ ++/* ++ * originally by Andreas Öman (andoma) ++ * some changes by Alexander Strange ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++ ++int ++main(int argc, char **argv) ++{ ++ int fd[2]; ++ int print_pixels = 0; ++ int dump_blocks = 0; ++ ++ int width; ++ int height; ++ int to_skip = 0; ++ ++ if (argc < 6) { ++ fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]); ++ return 1; ++ } ++ ++ width = atoi(argv[3]); ++ height = atoi(argv[4]); ++ if (argc > 6) ++ to_skip = atoi(argv[6]); ++ ++ uint8_t *Y[2], *C[2][2]; ++ int i, v, c, p; ++ int lsiz = width * height; ++ int csiz = width * height / 4; ++ int x, y; ++ int cwidth = width / 2; ++ int fr = to_skip; ++ int mb; ++ char *mberrors; ++ int mb_x, mb_y; ++ uint8_t *a; ++ uint8_t *b; ++ int die = 0; ++ ++ print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0; ++ dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0; ++ ++ for(i = 0; i < 2; i++) { ++ Y[i] = malloc(lsiz); ++ C[0][i] = malloc(csiz); ++ C[1][i] = malloc(csiz); ++ ++ fd[i] = open(argv[1 + i], O_RDONLY); ++ if(fd[i] == -1) { ++ perror("open"); ++ exit(1); ++ } ++ fcntl(fd[i], F_NOCACHE, 1); ++ ++ if (to_skip) ++ lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET); ++ } ++ ++ mb_x = width / 16; ++ mb_y = height / 16; ++ ++ mberrors = malloc(mb_x * mb_y); ++ ++ while(!die) { ++ memset(mberrors, 0, mb_x * mb_y); ++ ++ printf("Loading frame %d\n", ++fr); ++ ++ for(i = 0; i < 2; i++) { ++ v = read(fd[i], Y[i], lsiz); ++ if(v != lsiz) { ++ fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1); ++ return 1; ++ } ++ } ++ ++ ++ for(c = 0; c < lsiz; c++) { ++ if(Y[0][c] != Y[1][c]) { ++ x = c % width; ++ y = c / width; ++ ++ mb = x / 16 + (y / 16) * mb_x; ++ ++ if(print_pixels) ++ printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n", ++ Y[0][c], ++ Y[1][c], ++ x, y, ++ x / 16, ++ y / 16, ++ mb); ++ ++ mberrors[mb] |= 1; ++ } ++ } ++ ++ /* Chroma planes */ ++ ++ for(p = 0; p < 2; p++) { ++ ++ for(i = 0; i < 2; i++) { ++ v = read(fd[i], C[p][i], csiz); ++ if(v != csiz) { ++ fprintf(stderr, "Unable to read %c from file %d, exiting\n", ++ "UV"[p], i + 1); ++ return 1; ++ } ++ } ++ ++ for(c = 0; c < csiz; c++) { ++ if(C[p][0][c] != C[p][1][c]) { ++ x = c % cwidth; ++ y = c / cwidth; ++ ++ mb = x / 8 + (y / 8) * mb_x; ++ ++ mberrors[mb] |= 2 << p; ++ ++ if(print_pixels) ++ ++ printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) " ++ "mb(%3d,%-3d) #%d\n", ++ p ? 'r' : 'b', ++ C[p][0][c], ++ C[p][1][c], ++ ++ x, y, ++ x / 8, ++ y / 8, ++ x / 8 + y / 8 * cwidth / 8); ++ } ++ } ++ } ++ ++ for(i = 0; i < mb_x * mb_y; i++) { ++ x = i % mb_x; ++ y = i / mb_x; ++ ++ if(mberrors[i]) { ++ die = 1; ++ ++ printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n", ++ x, y, i, mberrors[i], ++ mberrors[i] & 1 ? 'Y' : ' ', ++ mberrors[i] & 2 ? 'U' : ' ', ++ mberrors[i] & 4 ? 'V' : ' '); ++ ++ if(dump_blocks) { ++ a = Y[0] + x * 16 + y * 16 * width; ++ b = Y[1] + x * 16 + y * 16 * width; ++ ++ for(y = 0; y < 16; y++) { ++ printf("%c ", "TB"[y&1]); ++ for(x = 0; x < 16; x++) ++ printf("%02x%c", a[x + y * width], ++ a[x + y * width] != b[x + y * width] ? '<' : ' '); ++ ++ printf("| "); ++ for(x = 0; x < 16; x++) ++ printf("%02x%c", b[x + y * width], ++ a[x + y * width] != b[x + y * width] ? '<' : ' '); ++ ++ printf("\n"); ++ } ++ } ++ } ++ } ++ } ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0001-changed-allow-reading-of-growing-avi-files-ie-curren.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0001-changed-allow-reading-of-growing-avi-files-ie-curren.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0001-changed-allow-reading-of-growing-avi-files-ie-curren.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0001-changed-allow-reading-of-growing-avi-files-ie-curren.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,52 +0,0 @@ +-From 4cb1a5a9e6a7258a5c4026c57f3e2bae9df292d0 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:28:27 -0400 +-Subject: [PATCH 01/36] changed: allow reading of growing avi files (ie currently being written) +- +---- +- libavformat/avidec.c | 8 ++++---- +- 1 files changed, 4 insertions(+), 4 deletions(-) +- +-diff --git a/libavformat/avidec.c b/libavformat/avidec.c +-index d8d4726..6b3e927 100644 +---- a/libavformat/avidec.c +-+++ b/libavformat/avidec.c +-@@ -139,7 +139,7 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ +- AVIStream *ast; +- int i; +- int64_t last_pos= -1; +-- int64_t filesize= url_fsize(s->pb); +-+ int64_t filesize= avi->fsize; +- +- #ifdef DEBUG_SEEK +- av_log(s, AV_LOG_ERROR, "longs_pre_entry:%d index_type:%d entries_in_use:%d chunk_id:%X base:%16"PRIX64"\n", +-@@ -353,7 +353,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) +- return -1; +- +- avi->fsize = url_fsize(pb); +-- if(avi->fsize<=0) +-+ if(avi->fsize<=0 || avi->fsize < avi->riff_end) +- avi->fsize= avi->riff_end == 8 ? INT64_MAX : avi->riff_end; +- +- /* first list tag */ +-@@ -379,7 +379,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) +- if (tag1 == MKTAG('m', 'o', 'v', 'i')) { +- avi->movi_list = url_ftell(pb) - 4; +- if(size) avi->movi_end = avi->movi_list + size + (size & 1); +-- else avi->movi_end = url_fsize(pb); +-+ else avi->movi_end = avi->fsize; +- av_dlog(NULL, "movi end=%"PRIx64"\n", avi->movi_end); +- goto end_of_header; +- } +-@@ -706,7 +706,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap) +- av_log(s, AV_LOG_ERROR, "Something went wrong during header parsing, " +- "I will ignore it and try to continue anyway.\n"); +- avi->movi_list = url_ftell(pb) - 4; +-- avi->movi_end = url_fsize(pb); +-+ avi->movi_end = avi->fsize; +- goto end_of_header; +- } +- /* skip tag */ +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0001-Support-raw-dvdsub-palette-as-stored-on-normal-dvd-s.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0001-Support-raw-dvdsub-palette-as-stored-on-normal-dvd-s.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0001-Support-raw-dvdsub-palette-as-stored-on-normal-dvd-s.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0001-Support-raw-dvdsub-palette-as-stored-on-normal-dvd-s.patch 2012-05-14 14:08:55.850370493 +0200 +@@ -0,0 +1,56 @@ ++From 5d361593f1149c2c0874d76a27c5cc68a219088c Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sun, 11 Sep 2011 19:04:51 +0200 ++Subject: [PATCH 01/24] Support raw dvdsub palette as stored on normal dvd's ++ ++This is how the palette is stored on dvd's. Currently ++only xbmc passes the palette information to libavcodec ++this way. ++--- ++ libavcodec/dvdsubdec.c | 23 +++++++++++++++++++++++ ++ 1 file changed, 23 insertions(+) ++ ++diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c ++index f4b5439..d0d13ee 100644 ++--- a/libavcodec/dvdsubdec.c +++++ b/libavcodec/dvdsubdec.c ++@@ -50,6 +50,24 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t * ++ } ++ } ++ +++static void ayvu_to_argb(const uint8_t *ayvu, uint32_t *argb, int num_values) +++{ +++ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +++ uint8_t r, g, b; +++ int i, y, cb, cr, a; +++ int r_add, g_add, b_add; +++ +++ for (i = num_values; i > 0; i--) { +++ a = *ayvu++; +++ y = *ayvu++; +++ cr = *ayvu++; +++ cb = *ayvu++; +++ YUV_TO_RGB1_CCIR(cb, cr); +++ YUV_TO_RGB2_CCIR(r, g, b, y); +++ *argb++ = (a << 24) | (r << 16) | (g << 8) | b; +++ } +++} +++ ++ static int decode_run_2bit(GetBitContext *gb, int *color) ++ { ++ unsigned int v, t; ++@@ -547,6 +565,11 @@ static int dvdsub_init(AVCodecContext *avctx) ++ data += strspn(data, "\n\r"); ++ } ++ +++ if (!ctx->has_palette && avctx->extradata_size == 64) { +++ ayvu_to_argb((uint8_t*)avctx->extradata, ctx->palette, 16); +++ ctx->has_palette = 1; +++ } +++ ++ if (ctx->has_palette) { ++ int i; ++ av_log(avctx, AV_LOG_DEBUG, "palette:"); ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0002-Change-fallthrough-logic-for-read_seek-to-be-based-o.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0002-Change-fallthrough-logic-for-read_seek-to-be-based-o.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0002-Change-fallthrough-logic-for-read_seek-to-be-based-o.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0002-Change-fallthrough-logic-for-read_seek-to-be-based-o.patch 2012-05-14 14:08:55.850370493 +0200 +@@ -0,0 +1,145 @@ ++From 8b480b7321130ad691cf46314164787301691161 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Mon, 12 Sep 2011 23:53:29 +0200 ++Subject: [PATCH 02/24] Change fallthrough logic for read_seek to be based on ++ return value ++ ++This changes the logic for read_seek to only use generic seek ++rutines if the return value is AVERROR(ENOSYS) to avoid retrying ++seeks if the demuxer already realized it wasn't possible. ++--- ++ libavformat/asfdec.c | 2 +- ++ libavformat/gxf.c | 4 ++-- ++ libavformat/jvdec.c | 2 +- ++ libavformat/matroskadec.c | 2 +- ++ libavformat/oggdec.c | 4 +++- ++ libavformat/pmpdec.c | 2 +- ++ libavformat/r3d.c | 2 +- ++ libavformat/utils.c | 4 +++- ++ 8 files changed, 13 insertions(+), 9 deletions(-) ++ ++diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c ++index 0deafc6..a62bab3 100644 ++--- a/libavformat/asfdec.c +++++ b/libavformat/asfdec.c ++@@ -1278,7 +1278,7 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int ++ AVStream *st = s->streams[stream_index]; ++ ++ if (s->packet_size <= 0) ++- return -1; +++ return AVERROR(ENOSYS); ++ ++ /* Try using the protocol's read_seek if available */ ++ if(s->pb) { ++diff --git a/libavformat/gxf.c b/libavformat/gxf.c ++index e773ba7..a3298a7 100644 ++--- a/libavformat/gxf.c +++++ b/libavformat/gxf.c ++@@ -542,7 +542,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int ++ idx = av_index_search_timestamp(st, timestamp - start_time, ++ AVSEEK_FLAG_ANY | AVSEEK_FLAG_BACKWARD); ++ if (idx < 0) ++- return -1; +++ return AVERROR(ENOSYS); ++ pos = st->index_entries[idx].pos; ++ if (idx < st->nb_index_entries - 2) ++ maxlen = st->index_entries[idx + 2].pos - pos; ++@@ -552,7 +552,7 @@ static int gxf_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int ++ return res; ++ found = gxf_resync_media(s, maxlen, -1, timestamp); ++ if (FFABS(found - timestamp) > 4) ++- return -1; +++ return AVERROR(ENOSYS); ++ return 0; ++ } ++ ++diff --git a/libavformat/jvdec.c b/libavformat/jvdec.c ++index 212cd8a..d52060b 100644 ++--- a/libavformat/jvdec.c +++++ b/libavformat/jvdec.c ++@@ -207,7 +207,7 @@ static int read_seek(AVFormatContext *s, int stream_index, ++ } ++ ++ if (i < 0 || i >= ast->nb_index_entries) ++- return 0; +++ return -1; ++ if (avio_seek(s->pb, ast->index_entries[i].pos, SEEK_SET) < 0) ++ return -1; ++ ++diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c ++index 2787a17..135fddd 100644 ++--- a/libavformat/matroskadec.c +++++ b/libavformat/matroskadec.c ++@@ -2048,7 +2048,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, ++ } ++ ++ if (!st->nb_index_entries) ++- return 0; +++ return -1; ++ timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); ++ ++ if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { ++diff --git a/libavformat/oggdec.c b/libavformat/oggdec.c ++index ceb4091..80669a5 100644 ++--- a/libavformat/oggdec.c +++++ b/libavformat/oggdec.c ++@@ -663,8 +663,10 @@ static int ogg_read_seek(AVFormatContext *s, int stream_index, ++ ++ ret = ff_seek_frame_binary(s, stream_index, timestamp, flags); ++ os = ogg->streams + stream_index; ++- if (ret < 0) +++ if (ret < 0) { ++ os->keyframe_seek = 0; +++ ret = AVERROR(ENOSYS); +++ } ++ return ret; ++ } ++ ++diff --git a/libavformat/pmpdec.c b/libavformat/pmpdec.c ++index a57b660..9db4e26 100644 ++--- a/libavformat/pmpdec.c +++++ b/libavformat/pmpdec.c ++@@ -157,7 +157,7 @@ static int pmp_seek(AVFormatContext *s, int stream_index, int64_t ts, int flags) ++ PMPContext *pmp = s->priv_data; ++ pmp->cur_stream = 0; ++ // fallback to default seek now ++- return -1; +++ return AVERROR(ENOSYS); ++ } ++ ++ static int pmp_close(AVFormatContext *s) ++diff --git a/libavformat/r3d.c b/libavformat/r3d.c ++index 874c361..0adad72 100644 ++--- a/libavformat/r3d.c +++++ b/libavformat/r3d.c ++@@ -358,7 +358,7 @@ static int r3d_seek(AVFormatContext *s, int stream_index, int64_t sample_time, i ++ int frame_num; ++ ++ if (!st->codec->time_base.num || !st->time_base.den) ++- return -1; +++ return AVERROR(ENOSYS); ++ ++ frame_num = sample_time*st->codec->time_base.den/ ++ ((int64_t)st->codec->time_base.num*st->time_base.den); ++diff --git a/libavformat/utils.c b/libavformat/utils.c ++index 9164cd0..242d616 100644 ++--- a/libavformat/utils.c +++++ b/libavformat/utils.c ++@@ -1910,11 +1910,13 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f ++ ff_read_frame_flush(s); ++ ret = s->iformat->read_seek(s, stream_index, timestamp, flags); ++ } else ++- ret = -1; +++ ret = AVERROR(ENOSYS); ++ ) ++ if (ret >= 0) { ++ return 0; ++ } +++ if (ret != AVERROR(ENOSYS)) +++ return ret; ++ ++ if (s->iformat->read_timestamp && !(s->iformat->flags & AVFMT_NOBINSEARCH)) { ++ ff_read_frame_flush(s); ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0002-w32thread-add-logging.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0002-w32thread-add-logging.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0002-w32thread-add-logging.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0002-w32thread-add-logging.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,46 +0,0 @@ +-From c564d6ba80e9c27c0fa95835cf09efd08fc6d570 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:30:34 -0400 +-Subject: [PATCH 02/36] w32thread: add logging +- +---- +- libavcodec/w32thread.c | 6 ++++-- +- 1 files changed, 4 insertions(+), 2 deletions(-) +- +-diff --git a/libavcodec/w32thread.c b/libavcodec/w32thread.c +-index f7a1430..5654334 100644 +---- a/libavcodec/w32thread.c +-+++ b/libavcodec/w32thread.c +-@@ -130,7 +130,7 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ +- uint32_t threadid; +- +- s->thread_count= thread_count; +-- +-+av_log(NULL, AV_LOG_INFO, "[w32thread] thread count = %d\n", thread_count); +- if (thread_count <= 1) +- return 0; +- +-@@ -147,17 +147,19 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ +- for(i=0; iexecute= avcodec_thread_execute; +- s->execute2= avcodec_thread_execute2; +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0003-asf-hacks.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0003-asf-hacks.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0003-asf-hacks.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0003-asf-hacks.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,55 +0,0 @@ +-From abf62ced1700fda797e839bc8be5dfb43bd2e67a Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:34:29 -0400 +-Subject: [PATCH 03/36] asf hacks +- +---- +- libavformat/asfdec.c | 15 ++++++++++++++- +- 1 files changed, 14 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c +-index 35e892c..2bda885 100644 +---- a/libavformat/asfdec.c +-+++ b/libavformat/asfdec.c +-@@ -1109,6 +1109,7 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) +- int64_t gsize= get_le64(s->pb); +- if (gsize < 24 || url_feof(s->pb)) { +- url_fseek(s->pb, current_pos, SEEK_SET); +-+ asf->index_read= -1; +- return; +- } +- url_fseek(s->pb, gsize-24, SEEK_CUR); +-@@ -1149,9 +1150,20 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int +- int64_t pos; +- int index; +- +-+ if (pts == 0) { +-+ // this is a hack since av_gen_search searches the entire file in this case +-+ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", s->data_offset); +-+ if (url_fseek(s->pb, s->data_offset, SEEK_SET) < 0) +-+ return -1; +-+ return 0; +-+ } +-+ +- if (s->packet_size <= 0) +- return -1; +- +-+ if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) +-+ return -1; +-+ +- /* Try using the protocol's read_seek if available */ +- if(s->pb) { +- int ret = av_url_read_fseek(s->pb, stream_index, pts, flags); +-@@ -1198,7 +1210,8 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int +- +- /* do the seek */ +- av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", pos); +-- url_fseek(s->pb, pos, SEEK_SET); +-+ if(url_fseek(s->pb, pos, SEEK_SET)<0) +-+ return -1; +- } +- asf_reset_header(s); +- return 0; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0003-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0003-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0003-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0003-matroska-Check-return-value-of-avio_seek-and-avoid-m.patch 2012-05-14 14:08:55.851370513 +0200 +@@ -0,0 +1,64 @@ ++From a8a72d52860df38f3a126ca544663f9ea379a929 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sat, 22 Oct 2011 18:33:45 +0200 ++Subject: [PATCH 03/24] [matroska] Check return value of avio_seek and avoid ++ modifying state if it fails ++ ++The code still modifies state if the timestamp is not found. Not ++sure exactly how to avoid that. ++--- ++ libavformat/matroskadec.c | 19 ++++++++++++------- ++ 1 file changed, 12 insertions(+), 7 deletions(-) ++ ++diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c ++index 135fddd..a9a0d1f 100644 ++--- a/libavformat/matroskadec.c +++++ b/libavformat/matroskadec.c ++@@ -2052,7 +2052,8 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, ++ timestamp = FFMAX(timestamp, st->index_entries[0].timestamp); ++ ++ if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { ++- avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET); +++ if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0) +++ return -1; ++ matroska->current_id = 0; ++ while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) { ++ matroska_clear_queue(matroska); ++@@ -2061,16 +2062,11 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, ++ } ++ } ++ ++- matroska_clear_queue(matroska); ++ if (index < 0) ++ return 0; ++ ++ index_min = index; ++ for (i=0; i < matroska->tracks.nb_elem; i++) { ++- tracks[i].audio.pkt_cnt = 0; ++- tracks[i].audio.sub_packet_cnt = 0; ++- tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; ++- tracks[i].end_timecode = 0; ++ if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE ++ && !tracks[i].stream->discard != AVDISCARD_ALL) { ++ index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD); ++@@ -2081,7 +2077,16 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, ++ } ++ } ++ ++- avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET); +++ if (avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET) < 0) +++ return -1; +++ +++ matroska_clear_queue(matroska); +++ for (i=0; i < matroska->tracks.nb_elem; i++) { +++ tracks[i].audio.pkt_cnt = 0; +++ tracks[i].audio.sub_packet_cnt = 0; +++ tracks[i].audio.buf_timecode = AV_NOPTS_VALUE; +++ tracks[i].end_timecode = 0; +++ } ++ matroska->current_id = 0; ++ matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); ++ matroska->skip_to_timecode = st->index_entries[index].timestamp; ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0004-asf-hacks.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0004-asf-hacks.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0004-asf-hacks.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0004-asf-hacks.patch 2012-05-14 14:08:55.852370533 +0200 +@@ -0,0 +1,37 @@ ++From 16ed0150800958b4ca544fd380bda92f21393555 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Mon, 12 Sep 2011 21:37:17 +0200 ++Subject: [PATCH 04/24] asf hacks ++ ++--- ++ libavformat/asfdec.c | 11 +++++++++++ ++ 1 file changed, 11 insertions(+) ++ ++diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c ++index a62bab3..7db3bd8 100644 ++--- a/libavformat/asfdec.c +++++ b/libavformat/asfdec.c ++@@ -1277,9 +1277,20 @@ static int asf_read_seek(AVFormatContext *s, int stream_index, int64_t pts, int ++ ASFContext *asf = s->priv_data; ++ AVStream *st = s->streams[stream_index]; ++ +++ if (pts == 0) { +++ // this is a hack since av_gen_search searches the entire file in this case +++ av_log(s, AV_LOG_DEBUG, "SEEKTO: %"PRId64"\n", s->data_offset); +++ if (avio_seek(s->pb, s->data_offset, SEEK_SET) < 0) +++ return -1; +++ return 0; +++ } +++ ++ if (s->packet_size <= 0) ++ return AVERROR(ENOSYS); ++ +++ if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO) +++ return -1; +++ ++ /* Try using the protocol's read_seek if available */ ++ if(s->pb) { ++ int ret = avio_seek_time(s->pb, stream_index, pts, flags); ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0004-support-seeking-in-nuv-files.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0004-support-seeking-in-nuv-files.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0004-support-seeking-in-nuv-files.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0004-support-seeking-in-nuv-files.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,126 +0,0 @@ +-From 2433fbdc04fd5497f71b1e3d5f9a184048616734 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:36:50 -0400 +-Subject: [PATCH 04/36] support seeking in nuv files +- +---- +- libavformat/nuv.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ +- 1 files changed, 84 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/nuv.c b/libavformat/nuv.c +-index 58a00df..04b256c 100644 +---- a/libavformat/nuv.c +-+++ b/libavformat/nuv.c +-@@ -218,12 +218,18 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { +- ret = av_new_packet(pkt, copyhdrsize + size); +- if (ret < 0) +- return ret; +-+ +- // HACK: we have no idea if it is a keyframe, +- // but if we mark none seeking will not work at all. +- pkt->flags |= AV_PKT_FLAG_KEY; +- pkt->pos = pos; +- pkt->pts = AV_RL32(&hdr[4]); +- pkt->stream_index = ctx->v_id; +-+ if(hdr[2] == 0) { +-+ AVStream *st = s->streams[pkt->stream_index]; +-+ pkt->flags |= PKT_FLAG_KEY; +-+ av_add_index_entry(st, pkt->pos, pkt->pts, size + HDRSIZE, 0, AVINDEX_KEYFRAME); +-+ } +- memcpy(pkt->data, hdr, copyhdrsize); +- ret = get_buffer(pb, pkt->data + copyhdrsize, size); +- if (ret < 0) { +-@@ -257,6 +263,83 @@ static int nuv_packet(AVFormatContext *s, AVPacket *pkt) { +- return AVERROR(EIO); +- } +- +-+/** +-+ * \brief looks for the string RTjjjjjjjjjj in the stream too resync reading +-+ * \return TRUE if the syncword is found. +-+ */ +-+static int nuv_resync(AVFormatContext *s, int64_t pos_limit) { +-+ ByteIOContext *pb = s->pb; +-+ uint32_t tag; +-+ +-+ tag = get_be32(pb); +-+ while(!url_feof(pb) && url_ftell(pb) < pos_limit) { +-+ if(tag != MKBETAG('R','T','j','j')) { +-+ tag = (tag << 8) | get_byte(pb); +-+ continue; +-+ } +-+ tag = get_be32(pb); +-+ if(tag != MKBETAG('j','j','j','j')) +-+ continue; +-+ +-+ tag = get_be32(pb); +-+ if(tag != MKBETAG('j','j','j','j')) +-+ continue; +-+ +-+ return 1; +-+ } +-+ return 0; +-+} +-+ +-+/** +-+ * \brief attempts to read a timestamp from stream at the given stream position +-+ * \return timestamp if successfull and AV_NOPTS_VALUE if failure +-+ */ +-+static int64_t nuv_read_dts(AVFormatContext *s, int stream_index, +-+ int64_t *ppos, int64_t pos_limit) +-+{ +-+ NUVContext *ctx = s->priv_data; +-+ ByteIOContext *pb = s->pb; +-+ uint8_t hdr[HDRSIZE]; +-+ nuv_frametype frametype; +-+ int size; +-+ int64_t pos, dts; +-+ +-+ if (url_fseek(pb, *ppos, SEEK_SET) < 0) +-+ return AV_NOPTS_VALUE; +-+ +-+ if (!nuv_resync(s, pos_limit)) +-+ return AV_NOPTS_VALUE; +-+ +-+ while (!url_feof(pb) && url_ftell(pb) < pos_limit) { +-+ if (get_buffer(pb, hdr, HDRSIZE) <= 0) +-+ return AV_NOPTS_VALUE; +-+ frametype = hdr[0]; +-+ size = PKTSIZE(AV_RL32(&hdr[8])); +-+ switch (frametype) { +-+ case NUV_SEEKP: +-+ break; +-+ case NUV_AUDIO: +-+ case NUV_VIDEO: +-+ pos = url_ftell(s->pb) - HDRSIZE; +-+ dts = AV_RL32(&hdr[4]); +-+ // TODO - add general support in av_gen_search, so it adds positions after reading timestamps +-+ av_add_index_entry(s->streams[frametype == NUV_VIDEO ? ctx->v_id : ctx->a_id] +-+ , pos, dts, size + HDRSIZE, 0, hdr[2] == 0 ? AVINDEX_KEYFRAME : 0); +-+ +-+ if ((frametype == NUV_VIDEO && stream_index == ctx->v_id) || +-+ (frametype == NUV_AUDIO && stream_index == ctx->a_id)) { +-+ *ppos = pos; +-+ return dts; +-+ } +-+ default: +-+ url_fskip(pb, size); +-+ break; +-+ } +-+ } +-+ return AV_NOPTS_VALUE; +-+} +-+ +-+ +- AVInputFormat ff_nuv_demuxer = { +- "nuv", +- NULL_IF_CONFIG_SMALL("NuppelVideo format"), +-@@ -266,5 +349,6 @@ AVInputFormat ff_nuv_demuxer = { +- nuv_packet, +- NULL, +- NULL, +-+ nuv_read_dts, +- .flags = AVFMT_GENERIC_INDEX, +- }; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0005-fixed-5585-Media-file-gets-played-twice.-we-assume-a.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0005-fixed-5585-Media-file-gets-played-twice.-we-assume-a.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0005-fixed-5585-Media-file-gets-played-twice.-we-assume-a.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0005-fixed-5585-Media-file-gets-played-twice.-we-assume-a.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,35 +0,0 @@ +-From 0c18eecd120fac527942cd8609545bfba7566b27 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:45:48 -0400 +-Subject: [PATCH 05/36] fixed: #5585 Media file gets played twice. we assume avi EOF when we can't find the next streams index entry for non interleaved files. +- +---- +- libavformat/avidec.c | 5 ++++- +- 1 files changed, 4 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/avidec.c b/libavformat/avidec.c +-index 6b3e927..3d223b7 100644 +---- a/libavformat/avidec.c +-+++ b/libavformat/avidec.c +-@@ -898,7 +898,8 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) +- if(i>=0){ +- int64_t pos= best_st->index_entries[i].pos; +- pos += best_ast->packet_size - best_ast->remaining; +-- url_fseek(s->pb, pos + 8, SEEK_SET); +-+ if(url_fseek(s->pb, pos + 8, SEEK_SET) < 0) +-+ return AVERROR_EOF; +- // av_log(s, AV_LOG_DEBUG, "pos=%"PRId64"\n", pos); +- +- assert(best_ast->remaining <= best_ast->packet_size); +-@@ -908,6 +909,8 @@ static int avi_read_packet(AVFormatContext *s, AVPacket *pkt) +- best_ast->packet_size= +- best_ast->remaining= best_st->index_entries[i].size; +- } +-+ else +-+ return AVERROR_EOF; +- } +- +- resync: +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0005-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0005-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0005-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0005-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch 2012-05-14 14:08:55.852370533 +0200 +@@ -0,0 +1,27 @@ ++From 55467e617c4772441e128cfcc3939beafdd8bf8a Mon Sep 17 00:00:00 2001 ++From: Cory Fields ++Date: Mon, 28 Jun 2010 01:55:31 -0400 ++Subject: [PATCH 05/24] if av_read_packet returns AVERROR_IO, we are done. ++ ffmpeg's codecs might or might not handle returning ++ any completed demuxed packets correctly ++ ++--- ++ libavformat/utils.c | 2 ++ ++ 1 file changed, 2 insertions(+) ++ ++diff --git a/libavformat/utils.c b/libavformat/utils.c ++index 242d616..ebb8493 100644 ++--- a/libavformat/utils.c +++++ b/libavformat/utils.c ++@@ -1248,6 +1248,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) ++ if (ret < 0) { ++ if (ret == AVERROR(EAGAIN)) ++ return ret; +++ if (ret == AVERROR(EIO)) +++ return ret; ++ /* return the last frames, if any */ ++ for(i = 0; i < s->nb_streams; i++) { ++ st = s->streams[i]; ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0006-added-probe-file-header-for-cdxa.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0006-added-probe-file-header-for-cdxa.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0006-added-probe-file-header-for-cdxa.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0006-added-probe-file-header-for-cdxa.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,46 +0,0 @@ +-From 88b4df4530410cd70ab0017a4415e2d040d16c1a Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:53:34 -0400 +-Subject: [PATCH 06/36] added: probe file header for cdxa +- +---- +- libavformat/mpeg.c | 16 ++++++++++++++++ +- 1 files changed, 16 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c +-index 135482b..d3b849c 100644 +---- a/libavformat/mpeg.c +-+++ b/libavformat/mpeg.c +-@@ -50,6 +50,18 @@ static int check_pes(uint8_t *p, uint8_t *end){ +- return pes1||pes2; +- } +- +-+static int cdxa_probe(AVProbeData *p) +-+{ +-+ /* check file header */ +-+ if (p->buf[0] == 'R' && p->buf[1] == 'I' && +-+ p->buf[2] == 'F' && p->buf[3] == 'F' && +-+ p->buf[8] == 'C' && p->buf[9] == 'D' && +-+ p->buf[10] == 'X' && p->buf[11] == 'A') +-+ return AVPROBE_SCORE_MAX; +-+ else +-+ return 0; +-+} +-+ +- static int mpegps_probe(AVProbeData *p) +- { +- uint32_t code= -1; +-@@ -57,6 +69,10 @@ static int mpegps_probe(AVProbeData *p) +- int i; +- int score=0; +- +-+ score = cdxa_probe(p); +-+ if (score > 0) return score; +-+ +-+ /* Search for MPEG stream */ +- for(i=0; ibuf_size; i++){ +- code = (code<<8) + p->buf[i]; +- if ((code & 0xffffff00) == 0x100) { +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0006-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0006-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0006-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0006-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch 2012-05-14 14:08:55.853370553 +0200 +@@ -0,0 +1,42 @@ ++From 406e25be924a32d5df14a977e8b9694a767f6378 Mon Sep 17 00:00:00 2001 ++From: Cory Fields ++Date: Mon, 28 Jun 2010 02:10:50 -0400 ++Subject: [PATCH 06/24] added: Ticket #7187, TV Teletext support for DVB EBU ++ Teletext streams ++ ++--- ++ libavcodec/avcodec.h | 4 ++++ ++ libavformat/mpegts.c | 2 ++ ++ 2 files changed, 6 insertions(+) ++ ++diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h ++index 81849c1..0b756d0 100644 ++--- a/libavcodec/avcodec.h +++++ b/libavcodec/avcodec.h ++@@ -425,6 +425,10 @@ enum CodecID { ++ CODEC_ID_SRT, ++ CODEC_ID_MICRODVD = MKBETAG('m','D','V','D'), ++ +++ /* data codecs */ +++ CODEC_ID_VBI_DATA= 0x17500, +++ CODEC_ID_VBI_TELETEXT, +++ ++ /* other specific kind of codecs (generally used for attachments) */ ++ CODEC_ID_FIRST_UNKNOWN = 0x18000, ///< A dummy ID pointing at the start of various fake codecs. ++ CODEC_ID_TTF = 0x18000, ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index 9998248..e7e061e 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -581,6 +581,8 @@ static const StreamType DESC_types[] = { ++ { 0x7b, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, ++ { 0x56, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_TELETEXT }, ++ { 0x59, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */ +++ { 0x45, AVMEDIA_TYPE_DATA, CODEC_ID_VBI_DATA }, /* VBI Data descriptor */ +++ { 0x46, AVMEDIA_TYPE_DATA, CODEC_ID_VBI_TELETEXT }, /* VBI Teletext descriptor */ ++ { 0 }, ++ }; ++ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0007-Don-t-accept-mpegts-PMT-that-isn-t-current.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0007-Don-t-accept-mpegts-PMT-that-isn-t-current.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0007-Don-t-accept-mpegts-PMT-that-isn-t-current.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0007-Don-t-accept-mpegts-PMT-that-isn-t-current.patch 2012-05-14 14:08:55.854370573 +0200 +@@ -0,0 +1,41 @@ ++From 3bf21b1049abf8991beac79235adfcca9d705eda Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sun, 18 Sep 2011 19:16:34 +0200 ++Subject: [PATCH 07/24] Don't accept mpegts PMT that isn't current ++ ++--- ++ libavformat/mpegts.c | 4 ++++ ++ 1 file changed, 4 insertions(+) ++ ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index e7e061e..817fbed 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -437,6 +437,7 @@ typedef struct SectionHeader { ++ uint8_t tid; ++ uint16_t id; ++ uint8_t version; +++ uint8_t current; ++ uint8_t sec_num; ++ uint8_t last_sec_num; ++ } SectionHeader; ++@@ -508,6 +509,7 @@ static int parse_section_header(SectionHeader *h, ++ val = get8(pp, p_end); ++ if (val < 0) ++ return -1; +++ h->current = val & 0x1; ++ h->version = (val >> 1) & 0x1f; ++ val = get8(pp, p_end); ++ if (val < 0) ++@@ -1556,6 +1558,8 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len ++ return; ++ if (h->tid != PAT_TID) ++ return; +++ if (!h->current) +++ return; ++ ++ ts->stream->ts_id = h->id; ++ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0007-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0007-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0007-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0007-if-av_read_packet-returns-AVERROR_IO-we-are-done.-ff.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From d684ae10f93158ff4497187cc70bcaa2257a8639 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 01:55:31 -0400 +-Subject: [PATCH 07/36] if av_read_packet returns AVERROR_IO, we are done. ffmpeg's codecs might or might not handle returning any completed demuxed packets correctly +- +---- +- libavformat/utils.c | 2 ++ +- 1 files changed, 2 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index 4f51c26..9fffaef 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -1142,6 +1142,8 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) +- if (ret < 0) { +- if (ret == AVERROR(EAGAIN)) +- return ret; +-+ if (ret == AVERROR_IO) +-+ return ret; +- /* return the last frames, if any */ +- for(i = 0; i < s->nb_streams; i++) { +- st = s->streams[i]; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0008-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0008-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0008-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0008-added-Ticket-7187-TV-Teletext-support-for-DVB-EBU-Te.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,41 +0,0 @@ +-From d6d3554d4c312a739b71ac67db594fde2e297d46 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 02:10:50 -0400 +-Subject: [PATCH 08/36] added: Ticket #7187, TV Teletext support for DVB EBU Teletext streams +- +---- +- libavcodec/avcodec.h | 4 ++++ +- libavformat/mpegts.c | 2 ++ +- 2 files changed, 6 insertions(+), 0 deletions(-) +- +-diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h +-index d0de610..4745980 100644 +---- a/libavcodec/avcodec.h +-+++ b/libavcodec/avcodec.h +-@@ -400,6 +400,10 @@ enum CodecID { +- CODEC_ID_DVB_TELETEXT, +- CODEC_ID_SRT, +- +-+ /* data codecs */ +-+ CODEC_ID_VBI_DATA= 0x17500, +-+ CODEC_ID_VBI_TELETEXT, +-+ +- /* other specific kind of codecs (generally used for attachments) */ +- CODEC_ID_TTF= 0x18000, +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index 8467e85..d550e3e 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -536,6 +536,8 @@ static const StreamType DESC_types[] = { +- { 0x7b, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +- { 0x56, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_TELETEXT }, +- { 0x59, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_DVB_SUBTITLE }, /* subtitling descriptor */ +-+ { 0x45, AVMEDIA_TYPE_DATA, CODEC_ID_VBI_DATA }, /* VBI Data descriptor */ +-+ { 0x46, AVMEDIA_TYPE_DATA, CODEC_ID_VBI_TELETEXT }, /* VBI Teletext descriptor */ +- { 0 }, +- }; +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0008-Don-t-reparse-PMT-unless-it-s-version-has-changed.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0008-Don-t-reparse-PMT-unless-it-s-version-has-changed.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0008-Don-t-reparse-PMT-unless-it-s-version-has-changed.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0008-Don-t-reparse-PMT-unless-it-s-version-has-changed.patch 2012-05-14 14:08:55.854370573 +0200 +@@ -0,0 +1,43 @@ ++From 5fecd135de1486be63e0cef53134c44f8b4becd6 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sun, 18 Sep 2011 19:17:23 +0200 ++Subject: [PATCH 08/24] Don't reparse PMT unless it's version has changed ++ ++--- ++ libavformat/mpegts.c | 6 ++++++ ++ 1 file changed, 6 insertions(+) ++ ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index 817fbed..8bdafc5 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -78,6 +78,7 @@ struct MpegTSFilter { ++ int pid; ++ int es_id; ++ int last_cc; /* last cc code (-1 if first packet) */ +++ int last_version; /* last version of data on this pid */ ++ enum MpegTSFilterType type; ++ union { ++ MpegTSPESFilter pes_filter; ++@@ -334,6 +335,7 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int ++ filter->pid = pid; ++ filter->es_id = -1; ++ filter->last_cc = -1; +++ filter->last_version = -1; ++ sec = &filter->u.section_filter; ++ sec->section_cb = section_cb; ++ sec->opaque = opaque; ++@@ -1560,6 +1562,10 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len ++ return; ++ if (!h->current) ++ return; +++ if (h->version == filter->last_version) +++ return; +++ filter->last_version = h->version; +++ av_dlog(ts->stream, "version=%d\n", filter->last_version); ++ ++ ts->stream->ts_id = h->id; ++ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0009-additional-HDMV-types-and-reg-descriptors.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0009-additional-HDMV-types-and-reg-descriptors.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0009-additional-HDMV-types-and-reg-descriptors.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0009-additional-HDMV-types-and-reg-descriptors.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-From 576a80321fbb6a6f4c4e69af75440e94990498bc Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 02:15:41 -0400 +-Subject: [PATCH 09/36] additional HDMV types and reg descriptors +- +---- +- libavformat/mpegts.c | 6 ++++++ +- 1 files changed, 6 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index d550e3e..74b0886 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -512,6 +512,8 @@ static const StreamType HDMV_types[] = { +- { 0x82, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +- { 0x83, AVMEDIA_TYPE_AUDIO, CODEC_ID_TRUEHD }, +- { 0x84, AVMEDIA_TYPE_AUDIO, CODEC_ID_EAC3 }, +-+ { 0x85, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD */ +-+ { 0x86, AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, /* DTS HD MASTER*/ +- { 0x90, AVMEDIA_TYPE_SUBTITLE, CODEC_ID_HDMV_PGS_SUBTITLE }, +- { 0 }, +- }; +-@@ -526,6 +528,10 @@ static const StreamType MISC_types[] = { +- static const StreamType REGD_types[] = { +- { MKTAG('d','r','a','c'), AVMEDIA_TYPE_VIDEO, CODEC_ID_DIRAC }, +- { MKTAG('A','C','-','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_AC3 }, +-+ { MKTAG('D','T','S','1'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +-+ { MKTAG('D','T','S','2'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +-+ { MKTAG('D','T','S','3'), AVMEDIA_TYPE_AUDIO, CODEC_ID_DTS }, +-+ { MKTAG('V','C','-','1'), AVMEDIA_TYPE_VIDEO, CODEC_ID_VC1 }, +- { 0 }, +- }; +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0009-fixed-compile-with-VDPAU-header-versions-without-MPE.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0009-fixed-compile-with-VDPAU-header-versions-without-MPE.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0009-fixed-compile-with-VDPAU-header-versions-without-MPE.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0009-fixed-compile-with-VDPAU-header-versions-without-MPE.patch 2012-05-14 14:08:55.855370593 +0200 +@@ -0,0 +1,63 @@ ++From 13fa8f2299e51192354cfb468dc05452ab9c9e4e Mon Sep 17 00:00:00 2001 ++From: Cory Fields ++Date: Mon, 28 Jun 2010 03:04:26 -0400 ++Subject: [PATCH 09/24] fixed: compile with VDPAU header versions without ++ MPEG4 support. ++ ++See http://repo.or.cz/w/FFMpeg-mirror/mplayer-patches.git/commitdiff/136c16af11076153717d3de31c9d84360644e006 ++--- ++ configure | 2 ++ ++ libavcodec/vdpau.c | 2 ++ ++ libavcodec/vdpau.h | 2 ++ ++ 3 files changed, 6 insertions(+) ++ ++diff --git a/configure b/configure ++index 07d473e..6255f57 100755 ++--- a/configure +++++ b/configure ++@@ -3058,6 +3058,8 @@ check_header sys/select.h ++ check_header termios.h ++ check_header vdpau/vdpau.h ++ check_header vdpau/vdpau_x11.h +++check_cpp_condition vdpau/vdpau.h "defined(VDP_DECODER_PROFILE_MPEG4_PART2_SP)" && enable vdpau_mpeg4_support +++ ++ check_header X11/extensions/XvMClib.h ++ check_header asm/types.h ++ ++diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c ++index ce5103a..21b4fc9 100644 ++--- a/libavcodec/vdpau.c +++++ b/libavcodec/vdpau.c ++@@ -316,6 +316,7 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, ++ render->bitstream_buffers_used = 0; ++ } ++ +++#ifdef VDP_DECODER_PROFILE_MPEG4_PART2_SP ++ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, ++ int buf_size) ++ { ++@@ -369,6 +370,7 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, ++ ff_draw_horiz_band(s, 0, s->avctx->height); ++ render->bitstream_buffers_used = 0; ++ } +++#endif ++ ++ // Only dummy functions for now ++ static int vdpau_mpeg2_start_frame(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) ++diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h ++index f3a5471..3748675 100644 ++--- a/libavcodec/vdpau.h +++++ b/libavcodec/vdpau.h ++@@ -79,7 +79,9 @@ struct vdpau_render_state { ++ VdpPictureInfoH264 h264; ++ VdpPictureInfoMPEG1Or2 mpeg; ++ VdpPictureInfoVC1 vc1; +++#ifdef VDP_DECODER_PROFILE_MPEG4_PART2_SP ++ VdpPictureInfoMPEG4Part2 mpeg4; +++#endif ++ } info; ++ }; ++ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0010-don-t-reparse-PMT-unless-it-s-version-has-changed-re.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0010-don-t-reparse-PMT-unless-it-s-version-has-changed-re.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0010-don-t-reparse-PMT-unless-it-s-version-has-changed-re.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0010-don-t-reparse-PMT-unless-it-s-version-has-changed-re.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,61 +0,0 @@ +-From 45f65bca80b6d4cfd52a141c0d666c5050419960 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 02:40:23 -0400 +-Subject: [PATCH 10/36] don't reparse PMT unless it's version has changed readded: don't accept PMT that isn't current +- +---- +- libavformat/mpegts.c | 10 ++++++++++ +- 1 files changed, 10 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index 74b0886..c355852 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -73,6 +73,7 @@ typedef struct MpegTSSectionFilter { +- struct MpegTSFilter { +- int pid; +- int last_cc; /* last cc code (-1 if first packet) */ +-+ int last_version; /* last version of data on this pid */ +- enum MpegTSFilterType type; +- union { +- MpegTSPESFilter pes_filter; +-@@ -301,6 +302,7 @@ static MpegTSFilter *mpegts_open_section_filter(MpegTSContext *ts, unsigned int +- filter->type = MPEGTS_SECTION; +- filter->pid = pid; +- filter->last_cc = -1; +-+ filter->last_version = -1; +- sec = &filter->u.section_filter; +- sec->section_cb = section_cb; +- sec->opaque = opaque; +-@@ -403,6 +405,7 @@ typedef struct SectionHeader { +- uint8_t tid; +- uint16_t id; +- uint8_t version; +-+ uint8_t current; +- uint8_t sec_num; +- uint8_t last_sec_num; +- } SectionHeader; +-@@ -474,6 +477,7 @@ static int parse_section_header(SectionHeader *h, +- val = get8(pp, p_end); +- if (val < 0) +- return -1; +-+ h->current = val & 0x1; +- h->version = (val >> 1) & 0x1f; +- val = get8(pp, p_end); +- if (val < 0) +-@@ -1124,6 +1128,12 @@ static void pat_cb(MpegTSFilter *filter, const uint8_t *section, int section_len +- return; +- if (h->tid != PAT_TID) +- return; +-+ if (!h->current) +-+ return; +-+ if (h->version == filter->last_version) +-+ return; +-+ filter->last_version = h->version; +-+ av_dlog(ts->stream, "version=%d\n", filter->last_version); +- +- clear_programs(ts); +- for(;;) { +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0010-Read-PID-timestamps-as-well-as-PCR-timestamps-to-fin.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0010-Read-PID-timestamps-as-well-as-PCR-timestamps-to-fin.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0010-Read-PID-timestamps-as-well-as-PCR-timestamps-to-fin.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0010-Read-PID-timestamps-as-well-as-PCR-timestamps-to-fin.patch 2012-05-14 14:08:55.856370613 +0200 +@@ -0,0 +1,100 @@ ++From 17c6bca0f47b1a0c3deac3ad948cdd674c135321 Mon Sep 17 00:00:00 2001 ++From: Cory Fields ++Date: Fri, 9 Jul 2010 16:43:31 -0400 ++Subject: [PATCH 10/24] Read PID timestamps as well as PCR timestamps to find ++ location in mpegts stream ++ ++--- ++ libavformat/mpegts.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++-- ++ 1 file changed, 46 insertions(+), 2 deletions(-) ++ ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index 8bdafc5..ba2f163 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -1928,6 +1928,44 @@ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, ++ return 0; ++ } ++ +++static int parse_timestamp(int64_t *ts, const uint8_t *buf) +++{ +++ int afc, flags; +++ const uint8_t *p; +++ +++ if(!(buf[1] & 0x40)) /* must be a start packet */ +++ return -1; +++ +++ afc = (buf[3] >> 4) & 3; +++ p = buf + 4; +++ if (afc == 0 || afc == 2) /* invalid or only adaption field */ +++ return -1; +++ if (afc == 3) +++ p += p[0] + 1; +++ if (p >= buf + TS_PACKET_SIZE) +++ return -1; +++ +++ if (p[0] != 0x00 || p[1] != 0x00 || p[2] != 0x01) /* packet_start_code_prefix */ +++ return -1; +++ +++ flags = p[3] | 0x100; /* stream type */ +++ if (!((flags >= 0x1c0 && flags <= 0x1df) || +++ (flags >= 0x1e0 && flags <= 0x1ef) || +++ (flags == 0x1bd) || (flags == 0x1fd))) +++ return -1; +++ +++ flags = p[7]; +++ if ((flags & 0xc0) == 0x80) { +++ *ts = ff_parse_pes_pts(p+9); +++ return 0; +++ } else if ((flags & 0xc0) == 0xc0) { +++ *ts = ff_parse_pes_pts(p+9+5); +++ return 0; +++ } +++ return -1; +++} +++ +++ ++ static int mpegts_read_header(AVFormatContext *s, ++ AVFormatParameters *ap) ++ { ++@@ -2118,6 +2156,7 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, ++ int64_t pos, timestamp; ++ uint8_t buf[TS_PACKET_SIZE]; ++ int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid; +++ int pid = ((PESContext*)s->streams[stream_index]->priv_data)->pid; ++ pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; ++ while(pos < pos_limit) { ++ if (avio_seek(s->pb, pos, SEEK_SET) < 0) ++@@ -2135,6 +2174,11 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, ++ *ppos = pos; ++ return timestamp; ++ } +++ if ((pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pid) && +++ parse_timestamp(×tamp, buf) == 0) { +++ *ppos = pos; +++ return timestamp; +++ } ++ pos += ts->raw_packet_size; ++ } ++ ++@@ -2322,7 +2366,7 @@ AVInputFormat ff_mpegts_demuxer = { ++ .read_header = mpegts_read_header, ++ .read_packet = mpegts_read_packet, ++ .read_close = mpegts_read_close, ++- .read_timestamp = mpegts_get_dts, +++ .read_timestamp = mpegts_get_pcr, ++ .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, ++ #ifdef USE_SYNCPOINT_SEARCH ++ .read_seek2 = read_seek2, ++@@ -2336,7 +2380,7 @@ AVInputFormat ff_mpegtsraw_demuxer = { ++ .read_header = mpegts_read_header, ++ .read_packet = mpegts_raw_read_packet, ++ .read_close = mpegts_read_close, ++- .read_timestamp = mpegts_get_dts, +++ .read_timestamp = mpegts_get_pcr, ++ .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, ++ #ifdef USE_SYNCPOINT_SEARCH ++ .read_seek2 = read_seek2, ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0011-Get-stream-durations-using-read_timestamp.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0011-Get-stream-durations-using-read_timestamp.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0011-Get-stream-durations-using-read_timestamp.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0011-Get-stream-durations-using-read_timestamp.patch 2012-05-14 14:08:55.857370634 +0200 +@@ -0,0 +1,69 @@ ++From 95926a84fe1369f796c916f72c50dd5b7d50b15a Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sat, 22 Oct 2011 19:01:38 +0200 ++Subject: [PATCH 11/24] Get stream durations using read_timestamp ++ ++--- ++ libavformat/utils.c | 39 +++++++++++++++++++++++++++++++++++++++ ++ 1 file changed, 39 insertions(+) ++ ++diff --git a/libavformat/utils.c b/libavformat/utils.c ++index ebb8493..25fe38e 100644 ++--- a/libavformat/utils.c +++++ b/libavformat/utils.c ++@@ -2082,6 +2082,41 @@ static void estimate_timings_from_bit_rate(AVFormatContext *ic) ++ #define DURATION_MAX_READ_SIZE 250000 ++ #define DURATION_MAX_RETRY 3 ++ +++static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset) +++{ +++ AVStream *st; +++ int i, step= 1024; +++ int64_t ts, pos; +++ +++ for(i=0;inb_streams;i++) { +++ st = ic->streams[i]; +++ +++ pos = 0; +++ ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE); +++ if (ts == AV_NOPTS_VALUE) +++ continue; +++ if (st->start_time > ts || st->start_time == AV_NOPTS_VALUE) +++ st->start_time = ts; +++ +++ pos = url_fsize(ic->pb) - 1; +++ do { +++ pos -= step; +++ ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step); +++ step += step; +++ } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE); +++ +++ if (ts == AV_NOPTS_VALUE) +++ continue; +++ +++ if (st->duration < ts - st->start_time || st->duration == AV_NOPTS_VALUE) +++ st->duration = ts - st->start_time; +++ } +++ +++ fill_all_stream_timings(ic); +++ +++ avio_seek(ic->pb, old_offset, SEEK_SET); +++} +++ ++ /* only usable for MPEG-PS streams */ ++ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) ++ { ++@@ -2184,6 +2219,10 @@ static void estimate_timings(AVFormatContext *ic, int64_t old_offset) ++ /* at least one component has timings - we use them for all ++ the components */ ++ fill_all_stream_timings(ic); +++ } else if (ic->iformat->read_timestamp && +++ file_size && ic->pb->seekable) { +++ /* get accurate estimate from the PTSes */ +++ av_estimate_timings_from_pts2(ic, old_offset); ++ } else { ++ av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\n"); ++ /* less precise: use bitrate info */ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0011-mingw-workaround.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0011-mingw-workaround.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0011-mingw-workaround.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0011-mingw-workaround.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-From c39cf2c1c78b4d1485adb0b6c7e1566beecc1e9f Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 02:49:03 -0400 +-Subject: [PATCH 11/36] mingw workaround +- +---- +- configure | 6 ++++-- +- 1 files changed, 4 insertions(+), 2 deletions(-) +- +-diff --git a/configure b/configure +-index 46f4e44..5931f35 100755 +---- a/configure +-+++ b/configure +-@@ -2921,7 +2921,8 @@ check_cflags -Wcast-qual +- check_cflags -Wwrite-strings +- check_cflags -Wtype-limits +- check_cflags -Wundef +--check_cflags -Wmissing-prototypes +-+# some gcc compilers (mingw 4.2.1-sjlj) are b0rk so for now skip this +-+# check_cflags -Wmissing-prototypes +- enabled extra_warnings && check_cflags -Winline +- +- # add some linker flags +-@@ -2986,7 +2987,8 @@ elif enabled ccc; then +- elif enabled gcc; then +- check_cflags -fno-tree-vectorize +- check_cflags -Werror=implicit-function-declaration +-- check_cflags -Werror=missing-prototypes +-+# some gcc compilers (mingw 4.2.1-sjlj) are b0rk so for now skip this +-+# check_cflags -Werror=missing-prototypes +- elif enabled llvm_gcc; then +- check_cflags -mllvm -stack-alignment=16 +- elif enabled clang; then +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0012-dvdsub-hacks.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0012-dvdsub-hacks.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0012-dvdsub-hacks.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0012-dvdsub-hacks.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,181 +0,0 @@ +-From 61baf585e90935869b4c71b406f5ba70a75211e8 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 02:50:45 -0400 +-Subject: [PATCH 12/36] dvdsub hacks +- +---- +- libavcodec/dvdsubdec.c | 99 ++++++++++++++++++++++++++++++++++++++++++----- +- 1 files changed, 88 insertions(+), 11 deletions(-) +- +-diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c +-index bea2646..e713e24 100644 +---- a/libavcodec/dvdsubdec.c +-+++ b/libavcodec/dvdsubdec.c +-@@ -25,6 +25,14 @@ +- +- //#define DEBUG +- +-+typedef struct DVDSubContext +-+{ +-+ uint8_t colormap[4]; +-+ uint8_t alpha[256]; +-+ uint32_t palette[16]; +-+ int has_palette; +-+} DVDSubContext; +-+ +- static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t *rgba, int num_values) +- { +- uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +-@@ -42,6 +50,24 @@ static void yuv_a_to_rgba(const uint8_t *ycbcr, const uint8_t *alpha, uint32_t * +- } +- } +- +-+static void ayvu_to_argb(const uint8_t *ayvu, uint32_t *argb, int num_values) +-+{ +-+ uint8_t *cm = ff_cropTbl + MAX_NEG_CROP; +-+ uint8_t r, g, b; +-+ int i, y, cb, cr, a; +-+ int r_add, g_add, b_add; +-+ +-+ for (i = num_values; i > 0; i--) { +-+ a = *ayvu++; +-+ y = *ayvu++; +-+ cr = *ayvu++; +-+ cb = *ayvu++; +-+ YUV_TO_RGB1_CCIR(cb, cr); +-+ YUV_TO_RGB2_CCIR(r, g, b, y); +-+ *argb++ = (a << 24) | (r << 16) | (g << 8) | b; +-+ } +-+} +-+ +- static int decode_run_2bit(GetBitContext *gb, int *color) +- { +- unsigned int v, t; +-@@ -115,13 +141,21 @@ static int decode_rle(uint8_t *bitmap, int linesize, int w, int h, +- return 0; +- } +- +--static void guess_palette(uint32_t *rgba_palette, +-- uint8_t *colormap, +-- uint8_t *alpha, +-- uint32_t subtitle_color) +-+static void fill_palette(DVDSubContext* ctx, +-+ uint32_t *rgba_palette, +-+ uint32_t subtitle_color) +- { +- uint8_t color_used[16]; +- int nb_opaque_colors, i, level, j, r, g, b; +-+ uint8_t *colormap = ctx->colormap; +-+ uint8_t *alpha = ctx->alpha; +-+ +-+ if(ctx->has_palette) { +-+ for(i = 0; i < 4; i++) +-+ rgba_palette[i] = (ctx->palette[ctx->colormap[i]] & 0x00ffffff) +-+ | ((alpha[i] * 17) << 24); +-+ return; +-+ } +- +- for(i = 0; i < 4; i++) +- rgba_palette[i] = 0; +-@@ -160,13 +194,14 @@ static void guess_palette(uint32_t *rgba_palette, +- +- #define READ_OFFSET(a) (big_offsets ? AV_RB32(a) : AV_RB16(a)) +- +--static int decode_dvd_subtitles(AVSubtitle *sub_header, +-+static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header, +- const uint8_t *buf, int buf_size) +- { +- int cmd_pos, pos, cmd, x1, y1, x2, y2, offset1, offset2, next_cmd_pos; +- int big_offsets, offset_size, is_8bit = 0; +- const uint8_t *yuv_palette = 0; +-- uint8_t colormap[4], alpha[256]; +-+ uint8_t *colormap = ctx->colormap; +-+ uint8_t *alpha = ctx->alpha; +- int date; +- int i; +- int is_menu = 0; +-@@ -326,8 +361,7 @@ static int decode_dvd_subtitles(AVSubtitle *sub_header, +- yuv_a_to_rgba(yuv_palette, alpha, (uint32_t*)sub_header->rects[0]->pict.data[1], 256); +- } else { +- sub_header->rects[0]->nb_colors = 4; +-- guess_palette((uint32_t*)sub_header->rects[0]->pict.data[1], +-- colormap, alpha, 0xffff00); +-+ fill_palette(ctx, sub_header->rects[0]->pict.data[1], 0xffff00); +- } +- sub_header->rects[0]->x = x1; +- sub_header->rects[0]->y = y1; +-@@ -458,12 +492,13 @@ static int dvdsub_decode(AVCodecContext *avctx, +- void *data, int *data_size, +- AVPacket *avpkt) +- { +-+ DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data; +- const uint8_t *buf = avpkt->data; +- int buf_size = avpkt->size; +- AVSubtitle *sub = data; +- int is_menu; +- +-- is_menu = decode_dvd_subtitles(sub, buf, buf_size); +-+ is_menu = decode_dvd_subtitles(ctx, sub, buf, buf_size); +- +- if (is_menu < 0) { +- no_subtitle: +-@@ -486,12 +521,54 @@ static int dvdsub_decode(AVCodecContext *avctx, +- return buf_size; +- } +- +-+static int dvdsub_init(AVCodecContext *avctx) +-+{ +-+ DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data; +-+ char *data = avctx->extradata; +-+ +-+ if (!avctx->extradata || !avctx->extradata_size) +-+ return 1; +-+ +-+ data[avctx->extradata_size] = '\0'; +-+ +-+ for(;;) { +-+ int pos = strcspn(data, "\n\r"); +-+ if (pos==0 && *data==0) +-+ break; +-+ +-+ if (strncmp("palette:", data, 8) == 0) { +-+ int i; +-+ char *p = data+8; +-+ ctx->has_palette = 1; +-+ for(i=0;i<16;i++) { +-+ ctx->palette[i] = strtoul(p, &p, 16); +-+ while(*p == ',' || isspace(*p)) +-+ p++; +-+ } +-+#if defined(DEBUG) +-+ av_log(avctx, AV_LOG_INFO, "palette:"); +-+ for(i=0;i<16;i++) +-+ av_log(avctx, AV_LOG_WARNING, " 0x%06x", ctx->palette[i]); +-+ av_log(avctx, AV_LOG_INFO, "\n"); +-+#endif +-+ } +-+ +-+ data += pos; +-+ data += strspn(data, "\n\r"); +-+ } +-+ +-+ if(!ctx->has_palette && avctx->extradata_size == 64) +-+ ayvu_to_argb((uint8_t*)avctx->extradata, ctx->palette, 16); +-+ +-+ return 1; +-+} +-+ +- AVCodec ff_dvdsub_decoder = { +- "dvdsub", +- AVMEDIA_TYPE_SUBTITLE, +- CODEC_ID_DVD_SUBTITLE, +-- 0, +-- NULL, +-+ sizeof(DVDSubContext), +-+ dvdsub_init, +- NULL, +- NULL, +- dvdsub_decode, +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0012-include-stdint.h.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0012-include-stdint.h.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0012-include-stdint.h.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0012-include-stdint.h.patch 2012-05-14 14:08:55.859370674 +0200 +@@ -0,0 +1,24 @@ ++From eaa6256c161f1f6d48b222b171f68869dace8f3f Mon Sep 17 00:00:00 2001 ++From: Cory Fields ++Date: Fri, 9 Jul 2010 16:49:01 -0400 ++Subject: [PATCH 12/24] include stdint.h ++ ++--- ++ libavutil/common.h | 1 + ++ 1 file changed, 1 insertion(+) ++ ++diff --git a/libavutil/common.h b/libavutil/common.h ++index 84290c6..5b73579 100644 ++--- a/libavutil/common.h +++++ b/libavutil/common.h ++@@ -29,6 +29,7 @@ ++ #include ++ #include ++ #include +++#include ++ #include ++ #include ++ #include ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0013-aacenc-add-recognized-profiles-array.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0013-aacenc-add-recognized-profiles-array.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0013-aacenc-add-recognized-profiles-array.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0013-aacenc-add-recognized-profiles-array.patch 2012-05-14 14:08:55.859370674 +0200 +@@ -0,0 +1,35 @@ ++From 8728e8bdef30313f1961d2687cfb0ffccf540797 Mon Sep 17 00:00:00 2001 ++From: Anssi Hannula ++Date: Fri, 21 Jan 2011 20:44:02 +0200 ++Subject: [PATCH 13/24] aacenc: add recognized profiles array ++ ++Submitted upstream. ++--- ++ libavcodec/aacenc.c | 6 ++++++ ++ 1 file changed, 6 insertions(+) ++ ++diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c ++index 2ff6f9c..4ffaa3d 100644 ++--- a/libavcodec/aacenc.c +++++ b/libavcodec/aacenc.c ++@@ -777,6 +777,11 @@ static const AVClass aacenc_class = { ++ LIBAVUTIL_VERSION_INT, ++ }; ++ +++static const AVProfile profiles[] = { +++ { FF_PROFILE_AAC_LOW, "Low" }, +++ { FF_PROFILE_UNKNOWN }, +++}; +++ ++ AVCodec ff_aac_encoder = { ++ .name = "aac", ++ .type = AVMEDIA_TYPE_AUDIO, ++@@ -789,4 +794,5 @@ AVCodec ff_aac_encoder = { ++ .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_FLT,AV_SAMPLE_FMT_NONE}, ++ .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), ++ .priv_class = &aacenc_class, +++ .profiles = profiles, ++ }; ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0013-fixed-compile-with-VDPAU-header-versions-without-MPE.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0013-fixed-compile-with-VDPAU-header-versions-without-MPE.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0013-fixed-compile-with-VDPAU-header-versions-without-MPE.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0013-fixed-compile-with-VDPAU-header-versions-without-MPE.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,69 +0,0 @@ +-From fc37326404fffb66fefd03ec5057b3864954e693 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 03:04:26 -0400 +-Subject: [PATCH 13/36] fixed: compile with VDPAU header versions without MPEG4 support. +- +-See http://repo.or.cz/w/FFMpeg-mirror/mplayer-patches.git/commitdiff/136c16af11076153717d3de31c9d84360644e006 +---- +- configure | 3 +++ +- libavcodec/vdpau.c | 2 ++ +- libavcodec/vdpau.h | 2 ++ +- 3 files changed, 7 insertions(+), 0 deletions(-) +- +-diff --git a/configure b/configure +-index 5931f35..83d9b87 100755 +---- a/configure +-+++ b/configure +-@@ -1261,6 +1261,7 @@ mpeg2_dxva2_hwaccel_deps="dxva2api_h" +- mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder" +- mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder" +- mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" +-+mpeg4_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h vdpau_mpeg4_support" +- mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder" +- mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" +- mpeg_xvmc_decoder_select="mpegvideo_decoder" +-@@ -2757,6 +2758,8 @@ check_header sys/select.h +- check_header termios.h +- check_header vdpau/vdpau.h +- check_header vdpau/vdpau_x11.h +-+check_cpp_condition vdpau/vdpau.h "defined(VDP_DECODER_PROFILE_MPEG4_PART2_SP)" && enable vdpau_mpeg4_support +-+ +- check_header X11/extensions/XvMClib.h +- +- check_struct dxva2api.h DXVA_PictureParameters wDecodedPictureIndex +-diff --git a/libavcodec/vdpau.c b/libavcodec/vdpau.c +-index bd721e8..54fdcd6 100644 +---- a/libavcodec/vdpau.c +-+++ b/libavcodec/vdpau.c +-@@ -315,6 +315,7 @@ void ff_vdpau_vc1_decode_picture(MpegEncContext *s, const uint8_t *buf, +- render->bitstream_buffers_used = 0; +- } +- +-+#ifdef VDP_DECODER_PROFILE_MPEG4_PART2_SP +- void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, +- int buf_size) +- { +-@@ -368,5 +369,6 @@ void ff_vdpau_mpeg4_decode_picture(MpegEncContext *s, const uint8_t *buf, +- ff_draw_horiz_band(s, 0, s->avctx->height); +- render->bitstream_buffers_used = 0; +- } +-+#endif +- +- /* @}*/ +-diff --git a/libavcodec/vdpau.h b/libavcodec/vdpau.h +-index ab5f682..b8cc37d 100644 +---- a/libavcodec/vdpau.h +-+++ b/libavcodec/vdpau.h +-@@ -72,7 +72,9 @@ struct vdpau_render_state { +- VdpPictureInfoH264 h264; +- VdpPictureInfoMPEG1Or2 mpeg; +- VdpPictureInfoVC1 vc1; +-+#ifdef VDP_DECODER_PROFILE_MPEG4_PART2_SP +- VdpPictureInfoMPEG4Part2 mpeg4; +-+#endif +- } info; +- +- /** Describe size/location of the compressed video data. +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0014-changed-allow-8-second-skew-between-streams-in-mov-b.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0014-changed-allow-8-second-skew-between-streams-in-mov-b.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0014-changed-allow-8-second-skew-between-streams-in-mov-b.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0014-changed-allow-8-second-skew-between-streams-in-mov-b.patch 2012-05-14 14:08:55.860370694 +0200 +@@ -0,0 +1,28 @@ ++From 5cc735503bfe1242606f19638bffeb686dd4d1b5 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Wed, 8 Dec 2010 14:03:43 +0000 ++Subject: [PATCH 14/24] changed: allow 8 second skew between streams in mov ++ before attempting to seek ++ ++--- ++ libavformat/mov.c | 4 ++-- ++ 1 file changed, 2 insertions(+), 2 deletions(-) ++ ++diff --git a/libavformat/mov.c b/libavformat/mov.c ++index 9da8eab..0f9836c 100644 ++--- a/libavformat/mov.c +++++ b/libavformat/mov.c ++@@ -2763,8 +2763,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) ++ if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) || ++ (s->pb->seekable && ++ ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && ++- ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || ++- (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { +++ ((FFABS(best_dts - dts) <= 8*AV_TIME_BASE && current_sample->pos < sample->pos) || +++ (FFABS(best_dts - dts) > 8*AV_TIME_BASE && dts < best_dts)))))) { ++ sample = current_sample; ++ best_dts = dts; ++ *st = avst; ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0014-changed-check-some-more-url_fseeks-in-asf-demuxer-to.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0014-changed-check-some-more-url_fseeks-in-asf-demuxer-to.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0014-changed-check-some-more-url_fseeks-in-asf-demuxer-to.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0014-changed-check-some-more-url_fseeks-in-asf-demuxer-to.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,39 +0,0 @@ +-From 9f19ad85257c413cf6c1facb6dc49efa8a10b6b3 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 22:27:09 -0400 +-Subject: [PATCH 14/36] changed: check some more url_fseeks in asf demuxer to avoid problems if file system is unseekable +- +---- +- libavformat/asfdec.c | 9 +++++++-- +- 1 files changed, 7 insertions(+), 2 deletions(-) +- +-diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c +-index 2bda885..4347601 100644 +---- a/libavformat/asfdec.c +-+++ b/libavformat/asfdec.c +-@@ -1058,7 +1058,8 @@ static int64_t asf_read_pts(AVFormatContext *s, int stream_index, int64_t *ppos, +- if (s->packet_size > 0) +- pos= (pos+s->packet_size-1-s->data_offset)/s->packet_size*s->packet_size+ s->data_offset; +- *ppos= pos; +-- url_fseek(s->pb, pos, SEEK_SET); +-+ if (url_fseek(s->pb, pos, SEEK_SET) < 0) +-+ return AV_NOPTS_VALUE; +- +- //printf("asf_read_pts\n"); +- asf_reset_header(s); +-@@ -1100,7 +1101,11 @@ static void asf_build_simple_index(AVFormatContext *s, int stream_index) +- int64_t current_pos= url_ftell(s->pb); +- int i; +- +-- url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET); +-+ if(url_fseek(s->pb, asf->data_object_offset + asf->data_object_size, SEEK_SET) < 0) { +-+ asf->index_read= -1; +-+ return; +-+ } +-+ +- ff_get_guid(s->pb, &g); +- +- /* the data object can be followed by other top-level objects, +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0015-Fix-7956-Adds-DTS-detection-to-MOV-files-ffmpeg-issu.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0015-Fix-7956-Adds-DTS-detection-to-MOV-files-ffmpeg-issu.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0015-Fix-7956-Adds-DTS-detection-to-MOV-files-ffmpeg-issu.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0015-Fix-7956-Adds-DTS-detection-to-MOV-files-ffmpeg-issu.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,24 +0,0 @@ +-From ead553179b4b145c4fd10af1bc9f827877bc559f Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 22:33:07 -0400 +-Subject: [PATCH 15/36] Fix #7956 - Adds DTS detection to MOV files (ffmpeg issue 1726) +- +---- +- libavformat/isom.c | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/isom.c b/libavformat/isom.c +-index 23ef82a..013cca7 100644 +---- a/libavformat/isom.c +-+++ b/libavformat/isom.c +-@@ -230,6 +230,7 @@ const AVCodecTag codec_movaudio_tags[] = { +- { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */ +- { CODEC_ID_AC3, MKTAG('a', 'c', '-', '3') }, /* ETSI TS 102 366 Annex F */ +- { CODEC_ID_AC3, MKTAG('s', 'a', 'c', '3') }, /* Nero Recode */ +-+ { CODEC_ID_DTS, MKTAG('D', 'T', 'S', ' ') }, /* DTS */ +- +- { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ +- { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0015-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0015-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0015-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0015-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch 2012-05-14 14:08:55.861370714 +0200 +@@ -0,0 +1,38 @@ ++From b83c9a2505338cdf021dd499c26686e82bcbc066 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Fri, 26 Nov 2010 20:56:48 +0000 ++Subject: [PATCH 15/24] fixed: memleak in mpegts demuxer on some malformed ++ (??) mpegts files with too large pes packets ++ ++at-visions sample file brokenStream.mpg ++--- ++ libavformat/mpegts.c | 6 ++++++ ++ 1 file changed, 6 insertions(+) ++ ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index ba2f163..c374cb9 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -664,6 +664,10 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, ++ ++ static void new_pes_packet(PESContext *pes, AVPacket *pkt) ++ { +++ if(pkt->data) { +++ av_log(pes->stream, AV_LOG_ERROR, "ignoring previously allocated packet on stream %d\n", pkt->stream_index); +++ av_free_packet(pkt); +++ } ++ av_init_packet(pkt); ++ ++ pkt->destruct = av_destruct_packet; ++@@ -2117,6 +2121,8 @@ static int mpegts_read_packet(AVFormatContext *s, ++ int ret, i; ++ ++ ts->pkt = pkt; +++ ts->pkt->data = NULL; +++ ++ ret = handle_packets(ts, 0); ++ if (ret < 0) { ++ /* flush pes data left */ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0016-changed-only-require-first-packet-to-be-known-for-al.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0016-changed-only-require-first-packet-to-be-known-for-al.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0016-changed-only-require-first-packet-to-be-known-for-al.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0016-changed-only-require-first-packet-to-be-known-for-al.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From f532df8280652147a86c12ce3701060b1d130d45 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 22:45:32 -0400 +-Subject: [PATCH 16/36] changed: only require first packet to be known for all audio and video streams +- +---- +- libavformat/utils.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index 9fffaef..ddb0ae3 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -2263,7 +2263,7 @@ int av_find_stream_info(AVFormatContext *ic) +- break; +- if(st->parser && st->parser->parser->split && !st->codec->extradata) +- break; +-- if(st->first_dts == AV_NOPTS_VALUE) +-+ if(st->first_dts == AV_NOPTS_VALUE && (st->codec->codec_type == AVMEDIA_TYPE_VIDEO || st->codec->codec_type == AVMEDIA_TYPE_AUDIO)) +- break; +- } +- if (i == ic->nb_streams) { +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0016-Speed-up-mpegts-av_find_stream_info.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0016-Speed-up-mpegts-av_find_stream_info.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0016-Speed-up-mpegts-av_find_stream_info.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0016-Speed-up-mpegts-av_find_stream_info.patch 2012-05-14 14:08:55.861370714 +0200 +@@ -0,0 +1,37 @@ ++From c240357f903f20ba51001fb90aa2de415d5be825 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Mon, 28 Jun 2010 21:26:54 +0000 ++Subject: [PATCH 16/24] Speed up mpegts av_find_stream_info ++ ++--- ++ libavformat/mpegts.c | 7 +++++-- ++ 1 file changed, 5 insertions(+), 2 deletions(-) ++ ++diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c ++index c374cb9..6da6db5 100644 ++--- a/libavformat/mpegts.c +++++ b/libavformat/mpegts.c ++@@ -825,7 +825,7 @@ static int mpegts_push_data(MpegTSFilter *filter, ++ goto skip; ++ ++ /* stream not present in PMT */ ++- if (!pes->st) { +++ if (ts->auto_guess && !pes->st) { ++ pes->st = avformat_new_stream(ts->stream, NULL); ++ if (!pes->st) ++ return AVERROR(ENOMEM); ++@@ -2013,7 +2013,10 @@ static int mpegts_read_header(AVFormatContext *s, ++ ++ av_dlog(ts->stream, "tuning done\n"); ++ ++- s->ctx_flags |= AVFMTCTX_NOHEADER; +++ /* only flag NOHEADER if we are in file mode, +++ in streaming mode scanning may take too long for users */ +++ if (!url_is_streamed(pb)) +++ s->ctx_flags |= AVFMTCTX_NOHEADER; ++ } else { ++ AVStream *st; ++ int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l; ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0017-allow-customizing-shared-library-soname-name-with-ma.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0017-allow-customizing-shared-library-soname-name-with-ma.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0017-allow-customizing-shared-library-soname-name-with-ma.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0017-allow-customizing-shared-library-soname-name-with-ma.patch 2012-05-14 14:08:55.863370754 +0200 +@@ -0,0 +1,43 @@ ++From 954d92f3fc2c5bd45fc1b4d347f2d9295d269574 Mon Sep 17 00:00:00 2001 ++From: Anssi Hannula ++Date: Wed, 23 Feb 2011 19:24:07 +0200 ++Subject: [PATCH 17/24] allow customizing shared library soname (name with ++ major) ++ ++This is a hack. ++--- ++ configure | 4 ++++ ++ 1 file changed, 4 insertions(+) ++ ++diff --git a/configure b/configure ++index 6255f57..5e11b2d 100755 ++--- a/configure +++++ b/configure ++@@ -238,6 +238,7 @@ Advanced options (experts only): ++ --arch=ARCH select architecture [$arch] ++ --cpu=CPU select the minimum required CPU (affects ++ instruction selection, may crash on older CPUs) +++ --custom-libname-with-major=NAME custom library name with major [$SLIBNAME_WITH_MAJOR] ++ --disable-asm disable all assembler optimizations ++ --disable-altivec disable AltiVec optimizations ++ --disable-amd3dnow disable 3DNow! optimizations ++@@ -1298,6 +1299,7 @@ CMDLINE_SET=" ++ cpu ++ cross_prefix ++ cxx +++ custom_libname_with_major ++ dep_cc ++ extra_version ++ host_cc ++@@ -2778,6 +2780,8 @@ EOF ++ exit 1; ++ fi ++ +++test -n "$custom_libname_with_major" && SLIBNAME_WITH_MAJOR="$custom_libname_with_major" +++ ++ die_license_disabled() { ++ enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; } ++ } ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0017-Don-t-assume-reading-more-frames-in-av_find_stream_i.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0017-Don-t-assume-reading-more-frames-in-av_find_stream_i.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0017-Don-t-assume-reading-more-frames-in-av_find_stream_i.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0017-Don-t-assume-reading-more-frames-in-av_find_stream_i.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From d3fb4761b262301398e013c703382d3f54f7a1f5 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 22:46:49 -0400 +-Subject: [PATCH 17/36] Don't assume reading more frames in av_find_stream_info will change a CODEC_ID_NONE into something better +- +---- +- libavformat/utils.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index ddb0ae3..26072c4 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -2050,7 +2050,7 @@ static int has_codec_parameters(AVCodecContext *enc) +- val = 1; +- break; +- } +-- return enc->codec_id != CODEC_ID_NONE && val != 0; +-+ return enc->codec_id != CODEC_ID_PROBE && val != 0; +- } +- +- static int has_decode_delay_been_guessed(AVStream *st) +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0018-changed-don-t-override-file-duration-with-bitrate-du.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0018-changed-don-t-override-file-duration-with-bitrate-du.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0018-changed-don-t-override-file-duration-with-bitrate-du.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0018-changed-don-t-override-file-duration-with-bitrate-du.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,43 +0,0 @@ +-From 9bbf094291649cf50d3e2c67f28185126f402b55 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Mon, 28 Jun 2010 22:49:06 -0400 +-Subject: [PATCH 18/36] changed: don't override file duration with bitrate duration for matroska files +- +---- +- libavformat/utils.c | 8 +++++--- +- 1 files changed, 5 insertions(+), 3 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index 26072c4..ad5fb83 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -1788,6 +1788,8 @@ static int av_has_duration(AVFormatContext *ic) +- { +- int i; +- AVStream *st; +-+ if(ic->duration != AV_NOPTS_VALUE) +-+ return 1; +- +- for(i = 0;i < ic->nb_streams; i++) { +- st = ic->streams[i]; +-@@ -1838,14 +1840,14 @@ static void av_update_stream_timings(AVFormatContext *ic) +- duration = end_time - start_time; +- } +- } +-- if (duration != INT64_MIN) { +-+ if (duration != INT64_MIN && ic->duration == AV_NOPTS_VALUE) { +- ic->duration = duration; +-- if (ic->file_size > 0) { +-+ } +-+ if (ic->file_size > 0 && ic->duration != AV_NOPTS_VALUE) { +- /* compute the bitrate */ +- ic->bit_rate = (double)ic->file_size * 8.0 * AV_TIME_BASE / +- (double)ic->duration; +- } +-- } +- } +- +- static void fill_all_stream_timings(AVFormatContext *ic) +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0018-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0018-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0018-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0018-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch 2012-05-14 14:08:55.863370754 +0200 +@@ -0,0 +1,75 @@ ++From 40f4c15370f7027dc5422edcb10e8a3b7e58e83d Mon Sep 17 00:00:00 2001 ++From: CrystalP ++Date: Wed, 5 Oct 2011 12:38:30 -0400 ++Subject: [PATCH 18/24] dxva-mpeg2 Allocate slices array dynamically - fixes ++ videos with > 175 slices. They used to result in ++ images with a black bottom. ++ ++sample on team ftp samples/PR471/too_many_slices.ts ++ ++Inspired by the vaapi code to reallocate the slices array for each new slice. ++Could be more efficient if the array could be preserved for all frames and ++freed only at the end of the video, but there doesn't seem to be anywhere ++appropriate to free the memory at the end. ++ ++Alternative is to allocate the proper size straight away for a new frame, ++instead of realloc'ing for each slice. ++--- ++ libavcodec/dxva2_mpeg2.c | 14 +++++++++++--- ++ 1 file changed, 11 insertions(+), 3 deletions(-) ++ ++diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c ++index 951305d..8ba83b6 100644 ++--- a/libavcodec/dxva2_mpeg2.c +++++ b/libavcodec/dxva2_mpeg2.c ++@@ -22,12 +22,12 @@ ++ ++ #include "dxva2_internal.h" ++ ++-#define MAX_SLICES (SLICE_MAX_START_CODE - SLICE_MIN_START_CODE + 1) ++ struct dxva2_picture_context { ++ DXVA_PictureParameters pp; ++ DXVA_QmatrixData qm; ++ unsigned slice_count; ++- DXVA_SliceInfo slice[MAX_SLICES]; +++ DXVA_SliceInfo *slice; +++ unsigned int slice_alloc; ++ ++ const uint8_t *bitstream; ++ unsigned bitstream_size; ++@@ -220,6 +220,8 @@ static int start_frame(AVCodecContext *avctx, ++ fill_quantization_matrices(avctx, ctx, s, &ctx_pic->qm); ++ ++ ctx_pic->slice_count = 0; +++ ctx_pic->slice = NULL; +++ ctx_pic->slice_alloc = 0; ++ ctx_pic->bitstream_size = 0; ++ ctx_pic->bitstream = NULL; ++ return 0; ++@@ -232,9 +234,14 @@ static int decode_slice(AVCodecContext *avctx, ++ struct dxva2_picture_context *ctx_pic = ++ s->current_picture_ptr->f.hwaccel_picture_private; ++ unsigned position; +++ DXVA_SliceInfo* slice; ++ ++- if (ctx_pic->slice_count >= MAX_SLICES) +++ slice = av_fast_realloc(ctx_pic->slice, +++ &ctx_pic->slice_alloc, +++ (ctx_pic->slice_count + 1) * sizeof(DXVA_SliceInfo)); +++ if (!slice) ++ return -1; +++ ctx_pic->slice = slice; ++ ++ if (!ctx_pic->bitstream) ++ ctx_pic->bitstream = buffer; ++@@ -258,6 +265,7 @@ static int end_frame(AVCodecContext *avctx) ++ &ctx_pic->pp, sizeof(ctx_pic->pp), ++ &ctx_pic->qm, sizeof(ctx_pic->qm), ++ commit_bitstream_and_slice_buffer); +++ av_freep(ctx_pic->slice); ++ } ++ ++ AVHWAccel ff_mpeg2_dxva2_hwaccel = { ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0019-changed-check-for-seek-error-when-attempting-to-read.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0019-changed-check-for-seek-error-when-attempting-to-read.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0019-changed-check-for-seek-error-when-attempting-to-read.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0019-changed-check-for-seek-error-when-attempting-to-read.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,27 +0,0 @@ +-From d4a0766af6b82ab3c99a56c726ec66cada0da6de Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 15:21:10 -0400 +-Subject: [PATCH 19/36] changed: check for seek error when attempting to read timestamp in rm demuxer +- +---- +- libavformat/rmdec.c | 4 +++- +- 1 files changed, 3 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c +-index da7e6b2..94bfc43 100644 +---- a/libavformat/rmdec.c +-+++ b/libavformat/rmdec.c +-@@ -904,7 +904,9 @@ static int64_t rm_read_dts(AVFormatContext *s, int stream_index, +- if(rm->old_format) +- return AV_NOPTS_VALUE; +- +-- url_fseek(s->pb, pos, SEEK_SET); +-+ if (url_fseek(s->pb, pos, SEEK_SET) < 0) +-+ return AV_NOPTS_VALUE; +-+ +- rm->remaining_len=0; +- for(;;){ +- int seq=1; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0019-dxva-mpeg2-speed-up-slice-allocation.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0019-dxva-mpeg2-speed-up-slice-allocation.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0019-dxva-mpeg2-speed-up-slice-allocation.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0019-dxva-mpeg2-speed-up-slice-allocation.patch 2012-05-14 14:08:55.864370774 +0200 +@@ -0,0 +1,74 @@ ++From 681f74b224e16a4df7f8c4e31a9be56975d57e10 Mon Sep 17 00:00:00 2001 ++From: CrystalP ++Date: Mon, 10 Oct 2011 19:42:50 -0400 ++Subject: [PATCH 19/24] dxva-mpeg2 speed up slice allocation ++ ++The number of slices is not very likely to change from frame to frame, so ++at the beginning of a new frame, allocate memory for the amount of slices of ++the previous frame. Saves a lot of reallocation, for some TV capture samples ++there are over 200 slices. ++ ++There wasn't anywhere really appropriate to store last_slice_count (needs to ++live from first frame to last frame), so this is likely to cause discussion to ++merge upstream. ++Adding members to dxva_context breaks ABI, which we don't care too much about ++since on Windows we don't support external ffmpeg. ++dxva mpeg2 code also has access to MpegEncContext, but adding there would ++likely break ABI as well. ++--- ++ libavcodec/dxva2.h | 1 + ++ libavcodec/dxva2_mpeg2.c | 12 ++++++++++++ ++ 2 files changed, 13 insertions(+) ++ ++diff --git a/libavcodec/dxva2.h b/libavcodec/dxva2.h ++index fc99560..16a6994 100644 ++--- a/libavcodec/dxva2.h +++++ b/libavcodec/dxva2.h ++@@ -66,6 +66,7 @@ struct dxva_context { ++ * Private to the FFmpeg AVHWAccel implementation ++ */ ++ unsigned report_id; +++ unsigned last_slice_count; ++ }; ++ ++ #endif /* AVCODEC_DXVA_H */ ++diff --git a/libavcodec/dxva2_mpeg2.c b/libavcodec/dxva2_mpeg2.c ++index 8ba83b6..90507f9 100644 ++--- a/libavcodec/dxva2_mpeg2.c +++++ b/libavcodec/dxva2_mpeg2.c ++@@ -224,6 +224,16 @@ static int start_frame(AVCodecContext *avctx, ++ ctx_pic->slice_alloc = 0; ++ ctx_pic->bitstream_size = 0; ++ ctx_pic->bitstream = NULL; +++ +++ if (ctx->last_slice_count > 0) +++ { +++ ctx_pic->slice = av_fast_realloc(NULL, +++ &ctx_pic->slice_alloc, +++ ctx->last_slice_count * sizeof(DXVA_SliceInfo)); +++ if (!ctx_pic->slice) +++ return -1; +++ } +++ ++ return 0; ++ } ++ ++@@ -258,6 +268,7 @@ static int end_frame(AVCodecContext *avctx) ++ struct MpegEncContext *s = avctx->priv_data; ++ struct dxva2_picture_context *ctx_pic = ++ s->current_picture_ptr->f.hwaccel_picture_private; +++ struct dxva_context *ctx = avctx->hwaccel_context; ++ ++ if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) ++ return -1; ++@@ -266,6 +277,7 @@ static int end_frame(AVCodecContext *avctx) ++ &ctx_pic->qm, sizeof(ctx_pic->qm), ++ commit_bitstream_and_slice_buffer); ++ av_freep(ctx_pic->slice); +++ ctx->last_slice_count = ctx_pic->slice_count; ++ } ++ ++ AVHWAccel ff_mpeg2_dxva2_hwaccel = { ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0020-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0020-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0020-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0020-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch 2012-05-14 14:08:55.865370795 +0200 +@@ -0,0 +1,49 @@ ++From 1c0fcc2cfe27197368e0490afe34dd51a831995f Mon Sep 17 00:00:00 2001 ++From: CrystalP ++Date: Wed, 5 Oct 2011 12:53:38 -0400 ++Subject: [PATCH 20/24] dxva-vc1 Take BI into account for forward and backward ++ pictures ++ ++See ticket #11643, sample on team ftp, samples/11643/vc-1 test.wmv ++--- ++ libavcodec/dxva2_vc1.c | 10 ++++++---- ++ 1 file changed, 6 insertions(+), 4 deletions(-) ++ ++diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c ++index 0ae9685..23507d3 100644 ++--- a/libavcodec/dxva2_vc1.c +++++ b/libavcodec/dxva2_vc1.c ++@@ -38,15 +38,17 @@ static void fill_picture_parameters(AVCodecContext *avctx, ++ { ++ const MpegEncContext *s = &v->s; ++ const Picture *current_picture = s->current_picture_ptr; +++ BYTE bPicIntra = s->pict_type == AV_PICTURE_TYPE_I || v->bi_type == 1; +++ BYTE bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B && v->bi_type == 0; ++ ++ memset(pp, 0, sizeof(*pp)); ++ pp->wDecodedPictureIndex = ++ pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture); ++- if (s->pict_type != AV_PICTURE_TYPE_I) +++ if (!bPicIntra) ++ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); ++ else ++ pp->wForwardRefPictureIndex = 0xffff; ++- if (s->pict_type == AV_PICTURE_TYPE_B) +++ if (bPicBackwardPrediction) ++ pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture); ++ else ++ pp->wBackwardRefPictureIndex = 0xffff; ++@@ -69,8 +71,8 @@ static void fill_picture_parameters(AVCodecContext *avctx, ++ if (s->picture_structure & PICT_BOTTOM_FIELD) ++ pp->bPicStructure |= 0x02; ++ pp->bSecondField = v->interlace && v->fcm != ILACE_FIELD && !s->first_field; ++- pp->bPicIntra = s->pict_type == AV_PICTURE_TYPE_I; ++- pp->bPicBackwardPrediction = s->pict_type == AV_PICTURE_TYPE_B; +++ pp->bPicIntra = bPicIntra; +++ pp->bPicBackwardPrediction = bPicBackwardPrediction; ++ pp->bBidirectionalAveragingMode = (1 << 7) | ++ ((ctx->cfg->ConfigIntraResidUnsigned != 0) << 6) | ++ ((ctx->cfg->ConfigResidDiffAccelerator != 0) << 5) | ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0020-fixed-wrong-fps-for-rmvb-files-patch-by-taxigps.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0020-fixed-wrong-fps-for-rmvb-files-patch-by-taxigps.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0020-fixed-wrong-fps-for-rmvb-files-patch-by-taxigps.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0020-fixed-wrong-fps-for-rmvb-files-patch-by-taxigps.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,38 +0,0 @@ +-From a10bd5edd13e8aff5e81bd1c8dddebde1698ed36 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 15:22:09 -0400 +-Subject: [PATCH 20/36] fixed: wrong fps for rmvb files (patch by taxigps) +- +---- +- libavformat/rmdec.c | 7 +++---- +- 1 files changed, 3 insertions(+), 4 deletions(-) +- +-diff --git a/libavformat/rmdec.c b/libavformat/rmdec.c +-index 94bfc43..8b59b1d 100644 +---- a/libavformat/rmdec.c +-+++ b/libavformat/rmdec.c +-@@ -294,18 +294,17 @@ ff_rm_read_mdpr_codecdata (AVFormatContext *s, ByteIOContext *pb, +- goto fail1; +- st->codec->width = get_be16(pb); +- st->codec->height = get_be16(pb); +-- st->codec->time_base.num= 1; +-+ st->codec->time_base.num= 1 << 16; +- fps= get_be16(pb); +- st->codec->codec_type = AVMEDIA_TYPE_VIDEO; +- get_be32(pb); +-- fps2= get_be16(pb); +-- get_be16(pb); +-+ fps2= get_be32(pb); +- +- if ((ret = rm_read_extradata(pb, st->codec, codec_data_size - (url_ftell(pb) - codec_pos))) < 0) +- return ret; +- +- // av_log(s, AV_LOG_DEBUG, "fps= %d fps2= %d\n", fps, fps2); +-- st->codec->time_base.den = fps * st->codec->time_base.num; +-+ st->codec->time_base.den = fps2; +- //XXX: do we really need that? +- switch(st->codec->extradata[4]>>4){ +- case 1: st->codec->codec_id = CODEC_ID_RV10; break; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0021-dxva-vc1-Pass-overlapping-transforms-hint.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0021-dxva-vc1-Pass-overlapping-transforms-hint.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0021-dxva-vc1-Pass-overlapping-transforms-hint.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0021-dxva-vc1-Pass-overlapping-transforms-hint.patch 2012-05-14 14:08:55.865370795 +0200 +@@ -0,0 +1,29 @@ ++From 6ba7fd3e2acf39e8c276e7db901c54dba0fd8307 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sat, 22 Oct 2011 21:59:22 +0200 ++Subject: [PATCH 21/24] dxva-vc1 Pass overlapping transforms hint ++ ++see ticket #11643 ++--- ++ libavcodec/dxva2_vc1.c | 5 ++++- ++ 1 file changed, 4 insertions(+), 1 deletion(-) ++ ++diff --git a/libavcodec/dxva2_vc1.c b/libavcodec/dxva2_vc1.c ++index 23507d3..9d550dd 100644 ++--- a/libavcodec/dxva2_vc1.c +++++ b/libavcodec/dxva2_vc1.c ++@@ -103,7 +103,10 @@ static void fill_picture_parameters(AVCodecContext *avctx, ++ (v->rangered << 3) | ++ (s->max_b_frames ); ++ pp->bPicExtrapolation = (!v->interlace || v->fcm == PROGRESSIVE) ? 1 : 2; ++- pp->bPicDeblocked = ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | +++ pp->bPicDeblocked = ((v->overlap == 1 && +++ pp->bPicBackwardPrediction == 0 && +++ ctx->cfg->ConfigResidDiffHost == 0) << 6) | +++ ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | ++ (s->loop_filter << 1); ++ pp->bPicDeblockConfined = (v->postprocflag << 7) | ++ (v->broadcast << 6) | ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0021-fixed-when-playing-mpegts-over-rtp-rtsp-sdp-lavf-mus.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0021-fixed-when-playing-mpegts-over-rtp-rtsp-sdp-lavf-mus.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0021-fixed-when-playing-mpegts-over-rtp-rtsp-sdp-lavf-mus.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0021-fixed-when-playing-mpegts-over-rtp-rtsp-sdp-lavf-mus.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,26 +0,0 @@ +-From f8a01f09195302ca630c28d3cabe7a6682c85f96 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 15:24:00 -0400 +-Subject: [PATCH 21/36] fixed: when playing mpegts over rtp/rtsp/sdp, lavf must still read PAT/SDT to get available streams +- +---- +- libavformat/mpegts.c | 3 +++ +- 1 files changed, 3 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index c355852..3f7098f 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -1817,6 +1817,9 @@ MpegTSContext *ff_mpegts_parse_open(AVFormatContext *s) +- ts->raw_packet_size = TS_PACKET_SIZE; +- ts->stream = s; +- ts->auto_guess = 1; +-+ mpegts_open_section_filter(ts, SDT_PID, sdt_cb, ts, 1); +-+ mpegts_open_section_filter(ts, PAT_PID, pat_cb, ts, 1); +-+ +- return ts; +- } +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0022-don-t-hardcode-subtitle-colors-to-16.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0022-don-t-hardcode-subtitle-colors-to-16.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0022-don-t-hardcode-subtitle-colors-to-16.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0022-don-t-hardcode-subtitle-colors-to-16.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From 31ec1522bb763dac0e77788a989ac3690de5a7ca Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 16:15:55 -0400 +-Subject: [PATCH 22/36] don't hardcode subtitle colors to 16 +- +---- +- libavcodec/dvbsubdec.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c +-index 0f1e004..e68a0b3 100644 +---- a/libavcodec/dvbsubdec.c +-+++ b/libavcodec/dvbsubdec.c +-@@ -1357,7 +1357,7 @@ static int dvbsub_display_end_segment(AVCodecContext *avctx, const uint8_t *buf, +- rect->y = display->y_pos + offset_y; +- rect->w = region->width; +- rect->h = region->height; +-- rect->nb_colors = 16; +-+ rect->nb_colors = (1 << region->depth); +- rect->type = SUBTITLE_BITMAP; +- rect->pict.linesize[0] = region->width; +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0022-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0022-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0022-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0022-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch 2012-05-14 14:08:55.866370816 +0200 +@@ -0,0 +1,75 @@ ++From 3b6417ff1e86c2aa72fc5360f67be2db8b83b80d Mon Sep 17 00:00:00 2001 ++From: CrystalP ++Date: Wed, 5 Oct 2011 13:13:25 -0400 ++Subject: [PATCH 22/24] dxva-h264 Fix dxva playback of streams that don't ++ start with an I-Frame. ++ ++GPUs with ATI UVDa and UVD+ have trouble when decoding doesn't start on an ++I-Frame, and they don't recover on later I-Frames. ++ ++The variable to track the first I-Frame is in H264Context so that it can be ++reset by code in h264 when initializing the context or flushing. ++ ++credits isidrogar, see ticket #11772. ++sample on team ftp, samples/11772/CSI_ New York - TV3 - 2008-09-16_1.ts ++--- ++ libavcodec/dxva2_h264.c | 8 ++++++++ ++ libavcodec/h264.c | 2 ++ ++ libavcodec/h264.h | 2 ++ ++ 3 files changed, 12 insertions(+) ++ ++diff --git a/libavcodec/dxva2_h264.c b/libavcodec/dxva2_h264.c ++index af91e02..b7e0251 100644 ++--- a/libavcodec/dxva2_h264.c +++++ b/libavcodec/dxva2_h264.c ++@@ -432,6 +432,14 @@ static int end_frame(AVCodecContext *avctx) ++ ++ if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) ++ return -1; +++ +++ // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs +++ if (!h->got_first_iframe) { +++ if (!(ctx_pic->pp.wBitFields & (1 << 15))) +++ return -1; +++ h->got_first_iframe = 1; +++ } +++ ++ return ff_dxva2_common_end_frame(avctx, s, ++ &ctx_pic->pp, sizeof(ctx_pic->pp), ++ &ctx_pic->qm, sizeof(ctx_pic->qm), ++diff --git a/libavcodec/h264.c b/libavcodec/h264.c ++index d010b55..98c7a5d 100644 ++--- a/libavcodec/h264.c +++++ b/libavcodec/h264.c ++@@ -2372,6 +2372,7 @@ static void flush_dpb(AVCodecContext *avctx){ ++ h->delayed_pic[i]->f.reference = 0; ++ h->delayed_pic[i]= NULL; ++ } +++ h->got_first_iframe = 0; ++ h->outputed_poc=h->next_outputed_poc= INT_MIN; ++ h->prev_interlaced_frame = 1; ++ idr(h); ++@@ -2819,6 +2820,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ ++ } ++ s->first_field = 0; ++ h->prev_interlaced_frame = 1; +++ h->got_first_iframe = 0; ++ ++ init_scan_tables(h); ++ if (ff_h264_alloc_tables(h) < 0) { ++diff --git a/libavcodec/h264.h b/libavcodec/h264.h ++index d0dfca3..f4df997 100644 ++--- a/libavcodec/h264.h +++++ b/libavcodec/h264.h ++@@ -584,6 +584,8 @@ typedef struct H264Context{ ++ int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag ++ int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag ++ +++ int got_first_iframe; +++ ++ // Timestamp stuff ++ int sei_buffering_period_present; ///< Buffering period SEI flag ++ int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0023-Changed-format-string-td-not-supported-by-our-MingW-.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0023-Changed-format-string-td-not-supported-by-our-MingW-.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0023-Changed-format-string-td-not-supported-by-our-MingW-.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0023-Changed-format-string-td-not-supported-by-our-MingW-.patch 2012-05-14 14:08:55.866370816 +0200 +@@ -0,0 +1,26 @@ ++From 0b24d2cd7338ddba22926a7725dc751cc801ac78 Mon Sep 17 00:00:00 2001 ++From: Joakim Plate ++Date: Sat, 22 Oct 2011 22:01:31 +0200 ++Subject: [PATCH 23/24] Changed format string - %td not supported by our MingW ++ environment. ++ ++--- ++ libavcodec/h264.c | 2 +- ++ 1 file changed, 1 insertion(+), 1 deletion(-) ++ ++diff --git a/libavcodec/h264.c b/libavcodec/h264.c ++index 98c7a5d..c4785db 100644 ++--- a/libavcodec/h264.c +++++ b/libavcodec/h264.c ++@@ -3629,7 +3629,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ ++ return 0; ++ } ++ if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { ++- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); +++ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%d)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); ++ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_MB_ERROR&part_mask); ++ return -1; ++ } ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0023-improved-mpegts-seeking.-NEEDS-REVIEW.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0023-improved-mpegts-seeking.-NEEDS-REVIEW.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0023-improved-mpegts-seeking.-NEEDS-REVIEW.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0023-improved-mpegts-seeking.-NEEDS-REVIEW.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,147 +0,0 @@ +-From 5670d7996bbe5489ee02cd87dc44280af8d30cd4 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 16:43:31 -0400 +-Subject: [PATCH 23/36] improved mpegts seeking. NEEDS REVIEW +- +---- +- libavformat/mpegts.c | 84 ++++++++++++++++++++++++++++++++++++------------- +- 1 files changed, 61 insertions(+), 23 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index 3f7098f..2fc0089 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -1451,6 +1451,44 @@ static int parse_pcr(int64_t *ppcr_high, int *ppcr_low, +- return 0; +- } +- +-+static int parse_timestamp(int64_t *ts, const uint8_t *buf) +-+{ +-+ int afc, flags; +-+ const uint8_t *p; +-+ +-+ if(!(buf[1] & 0x40)) /* must be a start packet */ +-+ return -1; +-+ +-+ afc = (buf[3] >> 4) & 3; +-+ p = buf + 4; +-+ if (afc == 0 || afc == 2) /* invalid or only adaption field */ +-+ return -1; +-+ if (afc == 3) +-+ p += p[0] + 1; +-+ if (p >= buf + TS_PACKET_SIZE) +-+ return -1; +-+ +-+ if (p[0] != 0x00 || p[1] != 0x00 || p[2] != 0x01) /* packet_start_code_prefix */ +-+ return -1; +-+ +-+ flags = p[3] | 0x100; /* stream type */ +-+ if (!((flags >= 0x1c0 && flags <= 0x1df) || +-+ (flags >= 0x1e0 && flags <= 0x1ef) || +-+ (flags == 0x1bd) || (flags == 0x1fd))) +-+ return -1; +-+ +-+ flags = p[7]; +-+ if ((flags & 0xc0) == 0x80) { +-+ *ts = ff_parse_pes_pts(p+9); +-+ return 0; +-+ } else if ((flags & 0xc0) == 0xc0) { +-+ *ts = ff_parse_pes_pts(p+9+5); +-+ return 0; +-+ } +-+ return -1; +-+} +-+ +-+ +- static int mpegts_read_header(AVFormatContext *s, +- AVFormatParameters *ap) +- { +-@@ -1660,38 +1698,39 @@ static int64_t mpegts_get_pcr(AVFormatContext *s, int stream_index, +- int64_t pos, timestamp; +- uint8_t buf[TS_PACKET_SIZE]; +- int pcr_l, pcr_pid = ((PESContext*)s->streams[stream_index]->priv_data)->pcr_pid; +-- const int find_next= 1; +-+ int pid = ((PESContext*)s->streams[stream_index]->priv_data)->pid; +- pos = ((*ppos + ts->raw_packet_size - 1 - ts->pos47) / ts->raw_packet_size) * ts->raw_packet_size + ts->pos47; +-- if (find_next) { +-- for(;;) { +-- url_fseek(s->pb, pos, SEEK_SET); +-+ while(pos < pos_limit) { +-+ if (url_fseek(s->pb, pos, SEEK_SET) < 0) +-+ return AV_NOPTS_VALUE; +- if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) +- return AV_NOPTS_VALUE; +-- if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && +-- parse_pcr(×tamp, &pcr_l, buf) == 0) { +-- break; +-- } +-- pos += ts->raw_packet_size; +-- } +-- } else { +-- for(;;) { +-- pos -= ts->raw_packet_size; +-- if (pos < 0) +-- return AV_NOPTS_VALUE; +-- url_fseek(s->pb, pos, SEEK_SET); +-- if (get_buffer(s->pb, buf, TS_PACKET_SIZE) != TS_PACKET_SIZE) +-+ if (buf[0] != 0x47) { +-+ url_fseek(s->pb, -TS_PACKET_SIZE, SEEK_CUR); +-+ if (mpegts_resync(s) < 0) +- return AV_NOPTS_VALUE; +-+ pos = url_ftell(s->pb); +-+ continue; +-+ } +- if ((pcr_pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pcr_pid) && +- parse_pcr(×tamp, &pcr_l, buf) == 0) { +-- break; +-- } +-- } +-+ *ppos = pos; +-+ return timestamp; +- } +-+ +-+ if ((pid < 0 || (AV_RB16(buf + 1) & 0x1fff) == pid) && +-+ parse_timestamp(×tamp, buf) == 0) { +- *ppos = pos; +- +- return timestamp; +- } +- +-+ pos += ts->raw_packet_size; +-+ } +-+ +-+ return AV_NOPTS_VALUE; +-+} +-+ +- #ifdef USE_SYNCPOINT_SEARCH +- +- static int read_seek2(AVFormatContext *s, +-@@ -1796,7 +1835,6 @@ static int read_seek(AVFormatContext *s, int stream_index, int64_t target_ts, in +- if(buf[1] & 0x40) break; +- pos += ts->raw_packet_size; +- } +-- url_fseek(s->pb, pos, SEEK_SET); +- +- return 0; +- } +-@@ -1867,7 +1905,7 @@ AVInputFormat ff_mpegts_demuxer = { +- mpegts_read_header, +- mpegts_read_packet, +- mpegts_read_close, +-- read_seek, +-+ NULL, +- mpegts_get_pcr, +- .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, +- #ifdef USE_SYNCPOINT_SEARCH +-@@ -1883,7 +1921,7 @@ AVInputFormat ff_mpegtsraw_demuxer = { +- mpegts_read_header, +- mpegts_raw_read_packet, +- mpegts_read_close, +-- read_seek, +-+ NULL, +- mpegts_get_pcr, +- .flags = AVFMT_SHOW_IDS|AVFMT_TS_DISCONT, +- #ifdef USE_SYNCPOINT_SEARCH +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0024-add-public-version-of-ff_read_frame_flush.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0024-add-public-version-of-ff_read_frame_flush.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0024-add-public-version-of-ff_read_frame_flush.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0024-add-public-version-of-ff_read_frame_flush.patch 2012-05-14 14:08:55.868370856 +0200 +@@ -0,0 +1,48 @@ ++From 399301fd74ed748d24d7ee2806f50e8ad57aeea8 Mon Sep 17 00:00:00 2001 ++From: elupus ++Date: Tue, 1 Nov 2011 20:18:35 +0100 ++Subject: [PATCH 24/24] add public version of ff_read_frame_flush ++ ++We need this since we sometimes seek on the ++input stream behind ffmpeg's back. After this ++all data need to be flushed completely. ++--- ++ libavformat/avformat.h | 5 +++++ ++ libavformat/utils.c | 5 +++++ ++ 2 files changed, 10 insertions(+) ++ ++diff --git a/libavformat/avformat.h b/libavformat/avformat.h ++index 1e8a629..c76ac71 100644 ++--- a/libavformat/avformat.h +++++ b/libavformat/avformat.h ++@@ -1631,6 +1631,11 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt); ++ int av_read_frame(AVFormatContext *s, AVPacket *pkt); ++ ++ /** +++ * Clear out any buffered data in context +++ */ +++void av_read_frame_flush(AVFormatContext *s); +++ +++/** ++ * Seek to the keyframe at timestamp. ++ * 'timestamp' in 'stream_index'. ++ * @param stream_index If stream_index is (-1), a default ++diff --git a/libavformat/utils.c b/libavformat/utils.c ++index 25fe38e..4729a40 100644 ++--- a/libavformat/utils.c +++++ b/libavformat/utils.c ++@@ -1463,6 +1463,11 @@ void ff_read_frame_flush(AVFormatContext *s) ++ } ++ } ++ +++void av_read_frame_flush(AVFormatContext *s) +++{ +++ ff_read_frame_flush(s); +++} +++ ++ #if FF_API_SEEK_PUBLIC ++ void av_update_cur_dts(AVFormatContext *s, AVStream *ref_st, int64_t timestamp) ++ { ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0024-get-accurate-estimate-from-the-PTSes.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0024-get-accurate-estimate-from-the-PTSes.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0024-get-accurate-estimate-from-the-PTSes.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0024-get-accurate-estimate-from-the-PTSes.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,71 +0,0 @@ +-From 3f7dbc76fbb3d13cc5816ef29771c125f701f142 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 16:47:58 -0400 +-Subject: [PATCH 24/36] get accurate estimate from the PTSes +- +---- +- libavformat/utils.c | 41 +++++++++++++++++++++++++++++++++++++++++ +- 1 files changed, 41 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index ad5fb83..fe3b453 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -1982,6 +1982,43 @@ static void av_estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset +- } +- } +- +-+static void av_estimate_timings_from_pts2(AVFormatContext *ic, int64_t old_offset) +-+{ +-+ AVStream *st; +-+ int i, step= 1024; +-+ int64_t ts, pos; +-+ +-+ for(i=0;inb_streams;i++) { +-+ st = ic->streams[i]; +-+ +-+ pos = 0; +-+ ts = ic->iformat->read_timestamp(ic, i, &pos, DURATION_MAX_READ_SIZE); +-+ if (ts == AV_NOPTS_VALUE) +-+ continue; +-+ if (st->start_time == AV_NOPTS_VALUE || +-+ st->start_time > ts) +-+ st->start_time = ts; +-+ +-+ pos = url_fsize(ic->pb) - 1; +-+ do { +-+ pos -= step; +-+ ts = ic->iformat->read_timestamp(ic, i, &pos, pos + step); +-+ step += step; +-+ } while (ts == AV_NOPTS_VALUE && pos >= step && step < DURATION_MAX_READ_SIZE); +-+ +-+ if (ts == AV_NOPTS_VALUE) +-+ continue; +-+ +-+ if (st->duration == AV_NOPTS_VALUE +-+ || st->duration < ts - st->start_time) +-+ st->duration = ts - st->start_time; +-+ } +-+ +-+ fill_all_stream_timings(ic); +-+ +-+ url_fseek(ic->pb, old_offset, SEEK_SET); +-+} +-+ +- static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset) +- { +- int64_t file_size; +-@@ -2005,6 +2042,10 @@ static void av_estimate_timings(AVFormatContext *ic, int64_t old_offset) +- /* at least one component has timings - we use them for all +- the components */ +- fill_all_stream_timings(ic); +-+ } else if (ic->iformat->read_timestamp && +-+ file_size && !url_is_streamed(ic->pb)) { +-+ /* get accurate estimate from the PTSes */ +-+ av_estimate_timings_from_pts2(ic, old_offset); +- } else { +- av_log(ic, AV_LOG_WARNING, "Estimating duration from bitrate, this may be inaccurate\n"); +- /* less precise: use bitrate info */ +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0025-dvb-subtitle-decoding-when-display-segment-is-mi.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0025-dvb-subtitle-decoding-when-display-segment-is-mi.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0025-dvb-subtitle-decoding-when-display-segment-is-mi.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0025-dvb-subtitle-decoding-when-display-segment-is-mi.patch 2012-05-14 14:08:55.869370876 +0200 +@@ -0,0 +1,65 @@ ++From 6261cbcd71e5cd192623434fa698e9f1e701f365 Mon Sep 17 00:00:00 2001 ++From: Paul Kendall ++Date: Sun, 29 Jan 2012 14:50:19 +0100 ++Subject: [PATCH 1/1] Fix dvb subtitle decoding when display segment is ++ missing. ++ ++closes ticket #8504 ++--- ++ libavcodec/dvbsubdec.c | 11 +++++++++++ ++ 1 file changed, 11 insertions(+) ++ ++diff --git a/libavcodec/dvbsubdec.c b/libavcodec/dvbsubdec.c ++index e2a804a..503223f 100644 ++--- a/libavcodec/dvbsubdec.c +++++ b/libavcodec/dvbsubdec.c ++@@ -1451,6 +1451,7 @@ static int dvbsub_decode(AVCodecContext *avctx, ++ int segment_type; ++ int page_id; ++ int segment_length; +++ int got_segment = 0; ++ int i; ++ ++ av_dlog(avctx, "DVB sub packet:\n"); ++@@ -1490,21 +1491,26 @@ static int dvbsub_decode(AVCodecContext *avctx, ++ switch (segment_type) { ++ case DVBSUB_PAGE_SEGMENT: ++ dvbsub_parse_page_segment(avctx, p, segment_length); +++ got_segment |= 1; ++ break; ++ case DVBSUB_REGION_SEGMENT: ++ dvbsub_parse_region_segment(avctx, p, segment_length); +++ got_segment |= 2; ++ break; ++ case DVBSUB_CLUT_SEGMENT: ++ dvbsub_parse_clut_segment(avctx, p, segment_length); +++ got_segment |= 4; ++ break; ++ case DVBSUB_OBJECT_SEGMENT: ++ dvbsub_parse_object_segment(avctx, p, segment_length); +++ got_segment |= 8; ++ break; ++ case DVBSUB_DISPLAYDEFINITION_SEGMENT: ++ dvbsub_parse_display_definition_segment(avctx, p, segment_length); ++ break; ++ case DVBSUB_DISPLAY_SEGMENT: ++ *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub); +++ got_segment |= 16; ++ break; ++ default: ++ av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n", ++@@ -1516,6 +1522,11 @@ static int dvbsub_decode(AVCodecContext *avctx, ++ p += segment_length; ++ } ++ +++ // Some streams do not send a display segment but if we have all the other +++ // segments then we need no further data. +++ if (got_segment == 15 && sub) +++ *data_size = dvbsub_display_end_segment(avctx, p, 0, sub); +++ ++ return p - buf; ++ } ++ ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0025-include-stdint.h.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0025-include-stdint.h.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0025-include-stdint.h.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0025-include-stdint.h.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,24 +0,0 @@ +-From d4fac342fd23faeb47a3f9c453a7af14c28de158 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 16:49:01 -0400 +-Subject: [PATCH 25/36] include stdint.h +- +---- +- libavutil/common.h | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/libavutil/common.h b/libavutil/common.h +-index 6404076..b5cd8df 100644 +---- a/libavutil/common.h +-+++ b/libavutil/common.h +-@@ -29,6 +29,7 @@ +- #include +- #include +- #include +-+#include +- #include +- #include +- #include +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0026-add-files-needed-for-xbmc-win32-build.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0026-add-files-needed-for-xbmc-win32-build.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0026-add-files-needed-for-xbmc-win32-build.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0026-add-files-needed-for-xbmc-win32-build.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,606 +0,0 @@ +-From 5931c5bb05da02fa495d99b3b7e86239a2b79374 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Fri, 4 Feb 2011 12:38:15 +0200 +-Subject: [PATCH] add files needed for xbmc win32 build +- +---- +- .gitignore | 5 + +- build_xbmc_win32.sh | 49 +++ +- include-xbmc-win32/dxva2/dxva2api.h | 502 +++++++++++++++++++++++++++++++ +- include-xbmc-win32/libavutil/avconfig.h | 6 + +- 4 files changed, 562 insertions(+), 0 deletions(-) +- create mode 100644 build_xbmc_win32.sh +- create mode 100644 include-xbmc-win32/dxva2/dxva2api.h +- create mode 100644 include-xbmc-win32/libavutil/avconfig.h +- +-diff --git a/.gitignore b/.gitignore +-index eac1758..70b94fc 100644 +---- a/.gitignore +-+++ b/.gitignore +-@@ -43,3 +43,8 @@ tools/qt-faststart +- tools/trasher +- tools/trasher*.d +- version.h +-+ +-+# ignore Windows build files +-+*.def +-+*.dll +-+*.lib +-diff --git a/build_xbmc_win32.sh b/build_xbmc_win32.sh +-new file mode 100644 +-index 0000000..5befc5a +---- /dev/null +-+++ b/build_xbmc_win32.sh +-@@ -0,0 +1,49 @@ +-+#!/bin/bash +-+ +-+if [ -d .libs ] +-+then +-+rm -r .libs +-+fi +-+ +-+if [ -f config.mak ] +-+then +-+make distclean +-+fi +-+ +-+OPTIONS=" +-+--enable-shared \ +-+--enable-memalign-hack \ +-+--enable-gpl \ +-+--enable-w32threads \ +-+--enable-postproc \ +-+--enable-zlib \ +-+--disable-static \ +-+--disable-altivec \ +-+--disable-muxers \ +-+--disable-encoders \ +-+--disable-debug \ +-+--disable-ffplay \ +-+--disable-ffserver \ +-+--disable-ffmpeg \ +-+--disable-ffprobe \ +-+--disable-devices \ +-+--enable-muxer=spdif \ +-+--enable-muxer=adts \ +-+--enable-encoder=ac3 \ +-+--enable-encoder=aac \ +-+--enable-runtime-cpudetect \ +-+--disable-debug \ +-+--disable-doc" +-+ +-+./configure --extra-cflags="-fno-common -Iinclude-xbmc-win32/dxva2" --extra-ldflags="-L/xbmc/system/players/dvdplayer" ${OPTIONS} && +-+ +-+make && +-+mkdir .libs && +-+cp lib*/*.dll .libs/ && +-+mv .libs/swscale-0.dll .libs/swscale-0.6.1.dll && +-+cp .libs/avcodec-52.dll /xbmc/system/players/dvdplayer/ && +-+cp .libs/avcore-0.dll /xbmc/system/players/dvdplayer/ && +-+cp .libs/avformat-52.dll /xbmc/system/players/dvdplayer/ && +-+cp .libs/avutil-50.dll /xbmc/system/players/dvdplayer/ && +-+cp .libs/postproc-51.dll /xbmc/system/players/dvdplayer/ && +-+cp .libs/swscale-0.6.1.dll /xbmc/system/players/dvdplayer/ +-diff --git a/include-xbmc-win32/dxva2/dxva2api.h b/include-xbmc-win32/dxva2/dxva2api.h +-new file mode 100644 +-index 0000000..28e54c8 +---- /dev/null +-+++ b/include-xbmc-win32/dxva2/dxva2api.h +-@@ -0,0 +1,502 @@ +-+/***************************************************************************** +-+ * dxva2api.h: DXVA 2 interface +-+ ***************************************************************************** +-+ * Copyright (C) 2009 Geoffroy Couprie +-+ * Copyright (C) 2009 Laurent Aimar +-+ * $Id$ +-+ * +-+ * Authors: Geoffroy Couprie +-+ * Laurent Aimar +-+ * +-+ * This program 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. +-+ * +-+ * This program 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-1301, USA. +-+ *****************************************************************************/ +-+ +-+#ifndef _DXVA2API_H +-+#define _DXVA2API_H +-+ +-+#define MINGW_DXVA2API_H_VERSION (2) +-+ +-+#if __GNUC__ >=3 +-+#pragma GCC system_header +-+#endif +-+ +-+#include +-+#include +-+ +-+/* Define it to allow using nameless struct/union (non C99 compliant) to match +-+ * the official documentation. */ +-+//#define DXVA2API_USE_BITFIELDS +-+ +-+/****************STRUCTURES******************/ +-+#pragma pack(push, 1) +-+ +-+typedef struct _DXVA2_ExtendedFormat { +-+#ifdef DXVA2API_USE_BITFIELDS +-+ union { +-+ struct { +-+ UINT SampleFormat : 8; +-+ UINT VideoChromaSubsampling : 4; +-+ UINT NominalRange : 3; +-+ UINT VideoTransferMatrix : 3; +-+ UINT VideoLighting : 4; +-+ UINT VideoPrimaries : 5; +-+ UINT VideoTransferFunction : 5; +-+ }; +-+ UINT value; +-+ }; +-+#else +-+ UINT value; +-+#endif +-+} DXVA2_ExtendedFormat; +-+ +-+typedef struct _DXVA2_Frequency { +-+ UINT Numerator; +-+ UINT Denominator; +-+} DXVA2_Frequency; +-+ +-+typedef struct _DXVA2_VideoDesc { +-+ UINT SampleWidth; +-+ UINT SampleHeight; +-+ DXVA2_ExtendedFormat SampleFormat; +-+ D3DFORMAT Format; +-+ DXVA2_Frequency InputSampleFreq; +-+ DXVA2_Frequency OutputFrameFreq; +-+ UINT UABProtectionLevel; +-+ UINT Reserved; +-+} DXVA2_VideoDesc; +-+ +-+typedef struct _DXVA2_ConfigPictureDecode { +-+ GUID guidConfigBitstreamEncryption; +-+ GUID guidConfigMBcontrolEncryption; +-+ GUID guidConfigResidDiffEncryption; +-+ UINT ConfigBitstreamRaw; +-+ UINT ConfigMBcontrolRasterOrder; +-+ UINT ConfigResidDiffHost; +-+ UINT ConfigSpatialResid8; +-+ UINT ConfigResid8Subtraction; +-+ UINT ConfigSpatialHost8or9Clipping; +-+ UINT ConfigSpatialResidInterleaved; +-+ UINT ConfigIntraResidUnsigned; +-+ UINT ConfigResidDiffAccelerator; +-+ UINT ConfigHostInverseScan; +-+ UINT ConfigSpecificIDCT; +-+ UINT Config4GroupedCoefs; +-+ USHORT ConfigMinRenderTargetBuffCount; +-+ USHORT ConfigDecoderSpecific; +-+} DXVA2_ConfigPictureDecode; +-+ +-+typedef struct _DXVA2_DecodeBufferDesc { +-+ DWORD CompressedBufferType; +-+ UINT BufferIndex; +-+ UINT DataOffset; +-+ UINT DataSize; +-+ UINT FirstMBaddress; +-+ UINT NumMBsInBuffer; +-+ UINT Width; +-+ UINT Height; +-+ UINT Stride; +-+ UINT ReservedBits; +-+ PVOID pvPVPState; +-+} DXVA2_DecodeBufferDesc; +-+ +-+typedef struct _DXVA2_DecodeExtensionData { +-+ UINT Function; +-+ PVOID pPrivateInputData; +-+ UINT PrivateInputDataSize; +-+ PVOID pPrivateOutputData; +-+ UINT PrivateOutputDataSize; +-+} DXVA2_DecodeExtensionData; +-+ +-+typedef struct _DXVA2_DecodeExecuteParams { +-+ UINT NumCompBuffers; +-+ DXVA2_DecodeBufferDesc *pCompressedBuffers; +-+ DXVA2_DecodeExtensionData *pExtensionData; +-+} DXVA2_DecodeExecuteParams; +-+ +-+enum { +-+ DXVA2_VideoDecoderRenderTarget = 0, +-+ DXVA2_VideoProcessorRenderTarget = 1, +-+ DXVA2_VideoSoftwareRenderTarget = 2 +-+}; +-+ +-+enum { +-+ DXVA2_PictureParametersBufferType = 0, +-+ DXVA2_MacroBlockControlBufferType = 1, +-+ DXVA2_ResidualDifferenceBufferType = 2, +-+ DXVA2_DeblockingControlBufferType = 3, +-+ DXVA2_InverseQuantizationMatrixBufferType = 4, +-+ DXVA2_SliceControlBufferType = 5, +-+ DXVA2_BitStreamDateBufferType = 6, +-+ DXVA2_MotionVectorBuffer = 7, +-+ DXVA2_FilmGrainBuffer = 8 +-+}; +-+ +-+/* DXVA MPEG-I/II and VC-1 */ +-+typedef struct _DXVA_PictureParameters { +-+ USHORT wDecodedPictureIndex; +-+ USHORT wDeblockedPictureIndex; +-+ USHORT wForwardRefPictureIndex; +-+ USHORT wBackwardRefPictureIndex; +-+ USHORT wPicWidthInMBminus1; +-+ USHORT wPicHeightInMBminus1; +-+ UCHAR bMacroblockWidthMinus1; +-+ UCHAR bMacroblockHeightMinus1; +-+ UCHAR bBlockWidthMinus1; +-+ UCHAR bBlockHeightMinus1; +-+ UCHAR bBPPminus1; +-+ UCHAR bPicStructure; +-+ UCHAR bSecondField; +-+ UCHAR bPicIntra; +-+ UCHAR bPicBackwardPrediction; +-+ UCHAR bBidirectionalAveragingMode; +-+ UCHAR bMVprecisionAndChromaRelation; +-+ UCHAR bChromaFormat; +-+ UCHAR bPicScanFixed; +-+ UCHAR bPicScanMethod; +-+ UCHAR bPicReadbackRequests; +-+ UCHAR bRcontrol; +-+ UCHAR bPicSpatialResid8; +-+ UCHAR bPicOverflowBlocks; +-+ UCHAR bPicExtrapolation; +-+ UCHAR bPicDeblocked; +-+ UCHAR bPicDeblockConfined; +-+ UCHAR bPic4MVallowed; +-+ UCHAR bPicOBMC; +-+ UCHAR bPicBinPB; +-+ UCHAR bMV_RPS; +-+ UCHAR bReservedBits; +-+ USHORT wBitstreamFcodes; +-+ USHORT wBitstreamPCEelements; +-+ UCHAR bBitstreamConcealmentNeed; +-+ UCHAR bBitstreamConcealmentMethod; +-+} DXVA_PictureParameters, *LPDXVA_PictureParameters; +-+ +-+typedef struct _DXVA_QmatrixData { +-+ BYTE bNewQmatrix[4]; +-+ WORD Qmatrix[4][8 * 8]; +-+} DXVA_QmatrixData, *LPDXVA_QmatrixData; +-+ +-+typedef struct _DXVA_SliceInfo { +-+ USHORT wHorizontalPosition; +-+ USHORT wVerticalPosition; +-+ UINT dwSliceBitsInBuffer; +-+ UINT dwSliceDataLocation; +-+ UCHAR bStartCodeBitOffset; +-+ UCHAR bReservedBits; +-+ USHORT wMBbitOffset; +-+ USHORT wNumberMBsInSlice; +-+ USHORT wQuantizerScaleCode; +-+ USHORT wBadSliceChopping; +-+} DXVA_SliceInfo, *LPDXVA_SliceInfo; +-+ +-+/* DXVA H264 */ +-+typedef struct { +-+#ifdef DXVA2API_USE_BITFIELDS +-+ union { +-+ struct { +-+ UCHAR Index7Bits : 7; +-+ UCHAR AssociatedFlag : 1; +-+ }; +-+ UCHAR bPicEntry; +-+ }; +-+#else +-+ UCHAR bPicEntry; +-+#endif +-+} DXVA_PicEntry_H264; +-+ +-+ +-+typedef struct { +-+ USHORT wFrameWidthInMbsMinus1; +-+ USHORT wFrameHeightInMbsMinus1; +-+ DXVA_PicEntry_H264 CurrPic; +-+ UCHAR num_ref_frames; +-+#ifdef DXVA2API_USE_BITFIELDS +-+ union { +-+ struct { +-+ USHORT field_pic_flag : 1; +-+ USHORT MbaffFrameFlag : 1; +-+ USHORT residual_colour_transform_flag : 1; +-+ USHORT sp_for_switch_flag : 1; +-+ USHORT chroma_format_idc : 2; +-+ USHORT RefPicFlag : 1; +-+ USHORT constrained_intra_pred_flag : 1; +-+ USHORT weighted_pred_flag : 1; +-+ USHORT weighted_bipred_idc : 2; +-+ USHORT MbsConsecutiveFlag : 1; +-+ USHORT frame_mbs_only_flag : 1; +-+ USHORT transform_8x8_mode_flag : 1; +-+ USHORT MinLumaBipredSize8x8Flag : 1; +-+ USHORT IntraPicFlag : 1; +-+ }; +-+ USHORT wBitFields; +-+ }; +-+#else +-+ USHORT wBitFields; +-+#endif +-+ UCHAR bit_depth_luma_minus8; +-+ UCHAR bit_depth_chroma_minus8; +-+ USHORT Reserved16Bits; +-+ UINT StatusReportFeedbackNumber; +-+ DXVA_PicEntry_H264 RefFrameList[16]; +-+ INT CurrFieldOrderCnt[2]; +-+ INT FieldOrderCntList[16][2]; +-+ CHAR pic_init_qs_minus26; +-+ CHAR chroma_qp_index_offset; +-+ CHAR second_chroma_qp_index_offset; +-+ UCHAR ContinuationFlag; +-+ CHAR pic_init_qp_minus26; +-+ UCHAR num_ref_idx_l0_active_minus1; +-+ UCHAR num_ref_idx_l1_active_minus1; +-+ UCHAR Reserved8BitsA; +-+ USHORT FrameNumList[16]; +-+ +-+ UINT UsedForReferenceFlags; +-+ USHORT NonExistingFrameFlags; +-+ USHORT frame_num; +-+ UCHAR log2_max_frame_num_minus4; +-+ UCHAR pic_order_cnt_type; +-+ UCHAR log2_max_pic_order_cnt_lsb_minus4; +-+ UCHAR delta_pic_order_always_zero_flag; +-+ UCHAR direct_8x8_inference_flag; +-+ UCHAR entropy_coding_mode_flag; +-+ UCHAR pic_order_present_flag; +-+ UCHAR num_slice_groups_minus1; +-+ UCHAR slice_group_map_type; +-+ UCHAR deblocking_filter_control_present_flag; +-+ UCHAR redundant_pic_cnt_present_flag; +-+ UCHAR Reserved8BitsB; +-+ USHORT slice_group_change_rate_minus1; +-+ UCHAR SliceGroupMap[810]; +-+} DXVA_PicParams_H264; +-+ +-+typedef struct { +-+ UCHAR bScalingLists4x4[6][16]; +-+ UCHAR bScalingLists8x8[2][64]; +-+} DXVA_Qmatrix_H264; +-+ +-+ +-+typedef struct { +-+ UINT BSNALunitDataLocation; +-+ UINT SliceBytesInBuffer; +-+ USHORT wBadSliceChopping; +-+ USHORT first_mb_in_slice; +-+ USHORT NumMbsForSlice; +-+ USHORT BitOffsetToSliceData; +-+ UCHAR slice_type; +-+ UCHAR luma_log2_weight_denom; +-+ UCHAR chroma_log2_weight_denom; +-+ +-+ UCHAR num_ref_idx_l0_active_minus1; +-+ UCHAR num_ref_idx_l1_active_minus1; +-+ CHAR slice_alpha_c0_offset_div2; +-+ CHAR slice_beta_offset_div2; +-+ UCHAR Reserved8Bits; +-+ DXVA_PicEntry_H264 RefPicList[2][32]; +-+ SHORT Weights[2][32][3][2]; +-+ CHAR slice_qs_delta; +-+ CHAR slice_qp_delta; +-+ UCHAR redundant_pic_cnt; +-+ UCHAR direct_spatial_mv_pred_flag; +-+ UCHAR cabac_init_idc; +-+ UCHAR disable_deblocking_filter_idc; +-+ USHORT slice_id; +-+} DXVA_Slice_H264_Long; +-+ +-+typedef struct { +-+ UINT BSNALunitDataLocation; +-+ UINT SliceBytesInBuffer; +-+ USHORT wBadSliceChopping; +-+} DXVA_Slice_H264_Short; +-+ +-+typedef struct { +-+ USHORT wFrameWidthInMbsMinus1; +-+ USHORT wFrameHeightInMbsMinus1; +-+ DXVA_PicEntry_H264 InPic; +-+ DXVA_PicEntry_H264 OutPic; +-+ USHORT PicOrderCnt_offset; +-+ INT CurrPicOrderCnt; +-+ UINT StatusReportFeedbackNumber; +-+ UCHAR model_id; +-+ UCHAR separate_colour_description_present_flag; +-+ UCHAR film_grain_bit_depth_luma_minus8; +-+ UCHAR film_grain_bit_depth_chroma_minus8; +-+ UCHAR film_grain_full_range_flag; +-+ UCHAR film_grain_colour_primaries; +-+ UCHAR film_grain_transfer_characteristics; +-+ UCHAR film_grain_matrix_coefficients; +-+ UCHAR blending_mode_id; +-+ UCHAR log2_scale_factor; +-+ UCHAR comp_model_present_flag[4]; +-+ UCHAR num_intensity_intervals_minus1[4]; +-+ UCHAR num_model_values_minus1[4]; +-+ UCHAR intensity_interval_lower_bound[3][16]; +-+ UCHAR intensity_interval_upper_bound[3][16]; +-+ SHORT comp_model_value[3][16][8]; +-+} DXVA_FilmGrainChar_H264; +-+ +-+#pragma pack(pop) +-+ +-+/*************INTERFACES************/ +-+#ifdef __cplusplus +-+extern "C" { +-+#endif +-+ +-+typedef _COM_interface IDirectXVideoDecoderService IDirectXVideoDecoderService; +-+typedef _COM_interface IDirectXVideoDecoder IDirectXVideoDecoder; +-+ +-+#undef INTERFACE +-+#define INTERFACE IDirectXVideoDecoder +-+DECLARE_INTERFACE_(IDirectXVideoDecoder,IUnknown) +-+{ +-+ STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; +-+ STDMETHOD_(ULONG,AddRef)(THIS) PURE; +-+ STDMETHOD_(ULONG,Release)(THIS) PURE; +-+ STDMETHOD(GetVideoDecoderService)(THIS_ IDirectXVideoDecoderService**) PURE; +-+ STDMETHOD(GetCreationParameters)(THIS_ GUID*,DXVA2_VideoDesc*,DXVA2_ConfigPictureDecode*,IDirect3DSurface9***,UINT*) PURE; +-+ STDMETHOD(GetBuffer)(THIS_ UINT,void**,UINT*) PURE; +-+ STDMETHOD(ReleaseBuffer)(THIS_ UINT) PURE; +-+ STDMETHOD(BeginFrame)(THIS_ IDirect3DSurface9 *,void*) PURE; +-+ STDMETHOD(EndFrame)(THIS_ HANDLE *) PURE; +-+ STDMETHOD(Execute)(THIS_ const DXVA2_DecodeExecuteParams*) PURE; +-+ +-+ +-+}; +-+ +-+#if !defined(__cplusplus) || defined(CINTERFACE) +-+#define IDirectXVideoDecoder_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) +-+#define IDirectXVideoDecoder_AddRef(p) (p)->lpVtbl->AddRef(p) +-+#define IDirectXVideoDecoder_Release(p) (p)->lpVtbl->Release(p) +-+#define IDirectXVideoDecoder_BeginFrame(p,a,b) (p)->lpVtbl->BeginFrame(p,a,b) +-+#define IDirectXVideoDecoder_EndFrame(p,a) (p)->lpVtbl->EndFrame(p,a) +-+#define IDirectXVideoDecoder_Execute(p,a) (p)->lpVtbl->Execute(p,a) +-+#define IDirectXVideoDecoder_GetBuffer(p,a,b,c) (p)->lpVtbl->GetBuffer(p,a,b,c) +-+#define IDirectXVideoDecoder_GetCreationParameters(p,a,b,c,d,e) (p)->lpVtbl->GetCreationParameters(p,a,b,c,d,e) +-+#define IDirectXVideoDecoder_GetVideoDecoderService(p,a) (p)->lpVtbl->GetVideoDecoderService(p,a) +-+#define IDirectXVideoDecoder_ReleaseBuffer(p,a) (p)->lpVtbl->ReleaseBuffer(p,a) +-+#else +-+#define IDirectXVideoDecoder_QueryInterface(p,a,b) (p)->QueryInterface(a,b) +-+#define IDirectXVideoDecoder_AddRef(p) (p)->AddRef() +-+#define IDirectXVideoDecoder_Release(p) (p)->Release() +-+#define IDirectXVideoDecoder_BeginFrame(p,a,b) (p)->BeginFrame(a,b) +-+#define IDirectXVideoDecoder_EndFrame(p,a) (p)->EndFrame(a) +-+#define IDirectXVideoDecoder_Execute(p,a) (p)->Execute(a) +-+#define IDirectXVideoDecoder_GetBuffer(p,a,b,c) (p)->GetBuffer(a,b,c) +-+#define IDirectXVideoDecoder_GetCreationParameters(p,a,b,c,d,e) (p)->GetCreationParameters(a,b,c,d,e) +-+#define IDirectXVideoDecoder_GetVideoDecoderService(p,a) (p)->GetVideoDecoderService(a) +-+#define IDirectXVideoDecoder_ReleaseBuffer(p,a) (p)->ReleaseBuffer(a) +-+#endif +-+ +-+#undef INTERFACE +-+#define INTERFACE IDirectXVideoAccelerationService +-+DECLARE_INTERFACE_(IDirectXVideoAccelerationService,IUnknown) +-+{ +-+ STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; +-+ STDMETHOD_(ULONG,AddRef)(THIS) PURE; +-+ STDMETHOD_(ULONG,Release)(THIS) PURE; +-+ STDMETHOD(CreateSurface)(THIS_ UINT,UINT,UINT,D3DFORMAT,D3DPOOL,DWORD,DWORD,IDirect3DSurface9**,HANDLE*) PURE; +-+ +-+}; +-+ +-+#if !defined(__cplusplus) || defined(CINTERFACE) +-+#define IDirectXVideoAccelerationService_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) +-+#define IDirectXVideoAccelerationService_AddRef(p) (p)->lpVtbl->AddRef(p) +-+#define IDirectXVideoAccelerationService_Release(p) (p)->lpVtbl->Release(p) +-+#define IDirectXVideoAccelerationService_CreateSurface(p,a,b,c,d,e,f,g,h,i) (p)->lpVtbl->CreateSurface(p,a,b,c,d,e,f,g,h,i) +-+#else +-+#define IDirectXVideoAccelerationService_QueryInterface(p,a,b) (p)->QueryInterface(a,b) +-+#define IDirectXVideoAccelerationService_AddRef(p) (p)->AddRef() +-+#define IDirectXVideoAccelerationService_Release(p) (p)->Release() +-+#define IDirectXVideoAccelerationService_CreateSurface(p,a,b,c,d,e,f,g,h,i) (p)->CreateSurface(a,b,c,d,e,f,g,h,i) +-+#endif +-+ +-+#undef INTERFACE +-+#define INTERFACE IDirectXVideoDecoderService +-+DECLARE_INTERFACE_(IDirectXVideoDecoderService,IDirectXVideoAccelerationService) +-+{ +-+ STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; +-+ STDMETHOD_(ULONG,AddRef)(THIS) PURE; +-+ STDMETHOD_(ULONG,Release)(THIS) PURE; +-+ STDMETHOD(CreateSurface)(THIS_ UINT,UINT,UINT,D3DFORMAT,D3DPOOL,DWORD,DWORD,IDirect3DSurface9**,HANDLE*) PURE; +-+ STDMETHOD(GetDecoderDeviceGuids)(THIS_ UINT*,GUID **) PURE; +-+ STDMETHOD(GetDecoderRenderTargets)(THIS_ REFGUID,UINT*,D3DFORMAT**) PURE; +-+ STDMETHOD(GetDecoderConfigurations)(THIS_ REFGUID,const DXVA2_VideoDesc*,IUnknown*,UINT*,DXVA2_ConfigPictureDecode**) PURE; +-+ STDMETHOD(CreateVideoDecoder)(THIS_ REFGUID,const DXVA2_VideoDesc*,DXVA2_ConfigPictureDecode*,IDirect3DSurface9**,UINT,IDirectXVideoDecoder**) PURE; +-+}; +-+ +-+#if !defined(__cplusplus) || defined(CINTERFACE) +-+#define IDirectXVideoDecoderService_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) +-+#define IDirectXVideoDecoderService_AddRef(p) (p)->lpVtbl->AddRef(p) +-+#define IDirectXVideoDecoderService_Release(p) (p)->lpVtbl->Release(p) +-+#define IDirectXVideoDecoderService_CreateSurface(p,a,b,c,d,e,f,g,h,i) (p)->lpVtbl->CreateSurface(p,a,b,c,d,e,f,g,h,i) +-+#define IDirectXVideoDecoderService_CreateVideoDecoder(p,a,b,c,d,e,f) (p)->lpVtbl->CreateVideoDecoder(p,a,b,c,d,e,f) +-+#define IDirectXVideoDecoderService_GetDecoderConfigurations(p,a,b,c,d,e) (p)->lpVtbl->GetDecoderConfigurations(p,a,b,c,d,e) +-+#define IDirectXVideoDecoderService_GetDecoderDeviceGuids(p,a,b) (p)->lpVtbl->GetDecoderDeviceGuids(p,a,b) +-+#define IDirectXVideoDecoderService_GetDecoderRenderTargets(p,a,b,c) (p)->lpVtbl->GetDecoderRenderTargets(p,a,b,c) +-+#else +-+#define IDirectXVideoDecoderService_QueryInterface(p,a,b) (p)->QueryInterface(a,b) +-+#define IDirectXVideoDecoderService_AddRef(p) (p)->AddRef() +-+#define IDirectXVideoDecoderService_Release(p) (p)->Release() +-+#define IDirectXVideoDecoderService_CreateSurface(p,a,b,c,d,e,f,g,h,i) (p)->CreateSurface(a,b,c,d,e,f,g,h,i) +-+#define IDirectXVideoDecoderService_CreateVideoDecoder(p,a,b,c,d,e,f) (p)->CreateVideoDecoder(a,b,c,d,e,f) +-+#define IDirectXVideoDecoderService_GetDecoderConfigurations(p,a,b,c,d,e) (p)->GetDecoderConfigurations(a,b,c,d,e) +-+#define IDirectXVideoDecoderService_GetDecoderDeviceGuids(p,a,b) (p)->GetDecoderDeviceGuids(a,b) +-+#define IDirectXVideoDecoderService_GetDecoderRenderTargets(p,a,b,c) (p)->GetDecoderRenderTargets(a,b,c) +-+#endif +-+ +-+#undef INTERFACE +-+#define INTERFACE IDirect3DDeviceManager9 +-+DECLARE_INTERFACE_(IDirect3DDeviceManager9,IUnknown) +-+{ +-+ STDMETHOD(QueryInterface)(THIS_ REFIID,PVOID*) PURE; +-+ STDMETHOD_(ULONG,AddRef)(THIS) PURE; +-+ STDMETHOD_(ULONG,Release)(THIS) PURE; +-+ STDMETHOD(ResetDevice)(THIS_ IDirect3DDevice9*,UINT) PURE; +-+ STDMETHOD(OpenDeviceHandle)(THIS_ HANDLE*) PURE; +-+ STDMETHOD(CloseDeviceHandle)( THIS_ HANDLE) PURE; +-+ STDMETHOD(TestDevice)( THIS_ HANDLE) PURE; +-+ STDMETHOD(LockDevice)( THIS_ HANDLE,IDirect3DDevice9**,BOOL) PURE; +-+ STDMETHOD(UnlockDevice)( THIS_ HANDLE,BOOL) PURE; +-+ STDMETHOD(GetVideoService)( THIS_ HANDLE,REFIID,void**) PURE; +-+}; +-+ +-+#if !defined(__cplusplus) || defined(CINTERFACE) +-+#define IDirect3DDeviceManager9_QueryInterface(p,a,b) (p)->lpVtbl->QueryInterface(p,a,b) +-+#define IDirect3DDeviceManager9_AddRef(p) (p)->lpVtbl->AddRef(p) +-+#define IDirect3DDeviceManager9_Release(p) (p)->lpVtbl->Release(p) +-+#define IDirect3DDeviceManager9_ResetDevice(p,a,b) (p)->lpVtbl->ResetDevice(p,a,b) +-+#define IDirect3DDeviceManager9_OpenDeviceHandle(p,a) (p)->lpVtbl->OpenDeviceHandle(p,a) +-+#define IDirect3DDeviceManager9_CloseDeviceHandle(p,a) (p)->lpVtbl->CloseDeviceHandle(p,a) +-+#define IDirect3DDeviceManager9_TestDevice(p,a) (p)->lpVtbl->TestDevice(p,a) +-+#define IDirect3DDeviceManager9_LockDevice(p,a,b,c) (p)->lpVtbl->LockDevice(p,a,b,c) +-+#define IDirect3DDeviceManager9_UnlockDevice(p,a,b) (p)->lpVtbl->UnlockDevice(p,a,b) +-+#define IDirect3DDeviceManager9_GetVideoService(p,a,b,c) (p)->lpVtbl->GetVideoService(p,a,b,c) +-+#else +-+#define IDirect3DDeviceManager9_QueryInterface(p,a,b) (p)->QueryInterface(a,b) +-+#define IDirect3DDeviceManager9_AddRef(p) (p)->AddRef() +-+#define IDirect3DDeviceManager9_Release(p) (p)->Release() +-+#define IDirect3DDeviceManager9_ResetDevice(p,a,b) (p)->ResetDevice(a,b) +-+#define IDirect3DDeviceManager9_OpenDeviceHandle(p,a) (p)->OpenDeviceHandle(a) +-+#define IDirect3DDeviceManager9_CloseDeviceHandle(p,a) (p)->CloseDeviceHandle(a) +-+#define IDirect3DDeviceManager9_TestDevice(p,a) (p)->TestDevice(a) +-+#define IDirect3DDeviceManager9_LockDevice(p,a,b,c) (p)->LockDevice(a,b,c) +-+#define IDirect3DDeviceManager9_UnlockDevice(p,a,b) (p)->UnlockDevice(a,b) +-+#define IDirect3DDeviceManager9_GetVideoService(p,a,b,c) (p)->GetVideoService(a,b,c) +-+#endif +-+ +-+#ifdef __cplusplus +-+}; +-+#endif +-+ +-+#endif //_DXVA2API_H +-diff --git a/include-xbmc-win32/libavutil/avconfig.h b/include-xbmc-win32/libavutil/avconfig.h +-new file mode 100644 +-index 0000000..f10aa61 +---- /dev/null +-+++ b/include-xbmc-win32/libavutil/avconfig.h +-@@ -0,0 +1,6 @@ +-+/* Generated by ffconf */ +-+#ifndef AVUTIL_AVCONFIG_H +-+#define AVUTIL_AVCONFIG_H +-+#define AV_HAVE_BIGENDIAN 0 +-+#define AV_HAVE_FAST_UNALIGNED 1 +-+#endif /* AVUTIL_AVCONFIG_H */ +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0026-Handle-return-value-of-BeginFrame-better.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0026-Handle-return-value-of-BeginFrame-better.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0026-Handle-return-value-of-BeginFrame-better.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0026-Handle-return-value-of-BeginFrame-better.patch 2012-05-14 14:08:55.870370896 +0200 +@@ -0,0 +1,51 @@ ++From d659958d58dfec08f4666a8add325c8154a662de Mon Sep 17 00:00:00 2001 ++From: CrystalP ++Date: Fri, 11 Nov 2011 19:10:54 -0500 ++Subject: [PATCH 1/1] Handle return value of BeginFrame better. ++ ++The nVidia cards sometimes return E_PENDING and need time before they can start ++decoding a new frame. ++ ++Helps nVidia cards with blocky pictures/pixellation artifacts after skip or ++when CPU is busy. ++--- ++ libavcodec/dxva2.c | 14 ++++++++++++-- ++ 1 file changed, 12 insertions(+), 2 deletions(-) ++ ++diff --git a/libavcodec/dxva2.c b/libavcodec/dxva2.c ++index b6f8aea..3a10f69 100644 ++--- a/libavcodec/dxva2.c +++++ b/libavcodec/dxva2.c ++@@ -21,6 +21,9 @@ ++ */ ++ ++ #include "dxva2_internal.h" +++#include +++ +++#define MAX_RETRY_ON_PENDING 50 ++ ++ void *ff_dxva2_get_surface(const Picture *picture) ++ { ++@@ -88,10 +91,17 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, ++ DXVA2_DecodeBufferDesc buffer[4]; ++ DXVA2_DecodeExecuteParams exec; ++ int result; +++ HRESULT hr; +++ int tries = 0; ++ ++- if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, +++ while ((hr=IDirectXVideoDecoder_BeginFrame(ctx->decoder, ++ ff_dxva2_get_surface(s->current_picture_ptr), ++- NULL))) { +++ NULL)) == E_PENDING +++ && tries < MAX_RETRY_ON_PENDING) { +++ usleep(1000); +++ tries++; +++ } +++ if (FAILED(hr)) { ++ av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); ++ return -1; ++ } ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0027-changed-check-return-value-of-seeks-to-avoid-messing.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0027-changed-check-return-value-of-seeks-to-avoid-messing.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0027-changed-check-return-value-of-seeks-to-avoid-messing.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0027-changed-check-return-value-of-seeks-to-avoid-messing.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,62 +0,0 @@ +-From 470e2804c01b609532d95539c66ebb6d13c7f805 Mon Sep 17 00:00:00 2001 +-From: Cory Fields +-Date: Fri, 9 Jul 2010 17:36:00 -0400 +-Subject: [PATCH 27/36] changed: check return value of seeks to avoid messing up current stream location +- +---- +- libavformat/avidec.c | 16 ++++++++++++---- +- 1 files changed, 12 insertions(+), 4 deletions(-) +- +-diff --git a/libavformat/avidec.c b/libavformat/avidec.c +-index 3d223b7..45ed8be 100644 +---- a/libavformat/avidec.c +-+++ b/libavformat/avidec.c +-@@ -206,13 +206,18 @@ static int read_braindead_odml_indx(AVFormatContext *s, int frame_num){ +- return -1; +- } +- +-- url_fseek(pb, offset+8, SEEK_SET); +-+ if(url_fseek(pb, offset+8, SEEK_SET) < 0) +-+ return -1; +- avi->odml_depth++; +- read_braindead_odml_indx(s, frame_num); +- avi->odml_depth--; +- frame_num += duration; +- +-- url_fseek(pb, pos, SEEK_SET); +-+ if(url_fseek(pb, pos, SEEK_SET) < 0) { +-+ av_log(s, AV_LOG_ERROR, "Failed to restore position after reading index"); +-+ return -1; +-+ } +-+ +- } +- } +- avi->index_loaded=1; +-@@ -1287,11 +1292,13 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp +- /* the av_index_search_timestamp call above. */ +- assert(stream_index == 0); +- +-+ if(url_fseek(s->pb, pos, SEEK_SET) < 0) +-+ return -1; +-+ +- /* Feed the DV video stream version of the timestamp to the */ +- /* DV demux so it can synthesize correct timestamps. */ +- dv_offset_reset(avi->dv_demux, timestamp); +- +-- url_fseek(s->pb, pos, SEEK_SET); +- avi->stream_index= -1; +- return 0; +- } +-@@ -1333,7 +1340,8 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp +- } +- +- /* do the seek */ +-- url_fseek(s->pb, pos, SEEK_SET); +-+ if(url_fseek(s->pb, pos, SEEK_SET) < 0) +-+ return -1; +- avi->stream_index= -1; +- return 0; +- } +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0027-threads-Perform-the-generic-progress-cleanup-more-ca.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0027-threads-Perform-the-generic-progress-cleanup-more-ca.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0027-threads-Perform-the-generic-progress-cleanup-more-ca.patch 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0027-threads-Perform-the-generic-progress-cleanup-more-ca.patch 2012-05-14 14:08:55.870370896 +0200 +@@ -0,0 +1,34 @@ ++From 05f8b5549c5e20cf9a417069838edd6841d7bd40 Mon Sep 17 00:00:00 2001 ++From: Michael Niedermayer ++Date: Sat, 11 Feb 2012 20:14:33 +0100 ++Subject: [PATCH 1/1] threads: Perform the generic progress cleanup more ++ carefully. ++ ++The cleanup is only done now when ++a picture is returned (assuming that it has to be done when its returned) ++a error is returned (assuming that there will be no further progress on the frame) ++the codec is not h264 (this is still needed due to some deadlocks in realvideo) ++ ++This fixes a decoding regression with 00017.MTS ++ ++Signed-off-by: Michael Niedermayer ++--- ++ libavcodec/pthread.c | 2 +- ++ 1 file changed, 1 insertion(+), 1 deletion(-) ++ ++diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c ++index 6ae763d..c58222b 100644 ++--- a/libavcodec/pthread.c +++++ b/libavcodec/pthread.c ++@@ -390,7 +390,7 @@ static attribute_align_arg void *frame_worker_thread(void *arg) ++ ++ pthread_mutex_lock(&p->progress_mutex); ++ for (i = 0; i < MAX_BUFFERS; i++) ++- if (p->progress_used[i]) { +++ if (p->progress_used[i] && (p->got_frame || p->result<0 || avctx->codec_id != CODEC_ID_H264)) { ++ p->progress[i][0] = INT_MAX; ++ p->progress[i][1] = INT_MAX; ++ } ++-- ++1.7.9.4 ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0028-fixed-if-lavc-s-mpeg2-decoder-was-asked-to-drop-a-fr.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0028-fixed-if-lavc-s-mpeg2-decoder-was-asked-to-drop-a-fr.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0028-fixed-if-lavc-s-mpeg2-decoder-was-asked-to-drop-a-fr.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0028-fixed-if-lavc-s-mpeg2-decoder-was-asked-to-drop-a-fr.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,26 +0,0 @@ +-From 937ab2b921e37b8e17edef2bb5a8b3a476d20fd8 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Wed, 29 Sep 2010 21:18:03 +0000 +-Subject: [PATCH 28/36] fixed: if lavc's mpeg2 decoder was asked to drop a frame, it would still output an old frame, and mess up timestamps +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@34307 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavcodec/mpeg12.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c +-index 3c73627..6254abb 100644 +---- a/libavcodec/mpeg12.c +-+++ b/libavcodec/mpeg12.c +-@@ -1911,7 +1911,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) +- ff_xvmc_field_end(s); +- +- /* end of slice reached */ +-- if (/*s->mb_y<mb_height &&*/ !s->first_field) { +-+ if (/*s->mb_y<mb_height &&*/ !s->first_field && !s->first_slice) { +- /* end of image */ +- +- s->current_picture_ptr->qscale_type= FF_QSCALE_TYPE_MPEG2; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0029-fixed-if-container-doesn-t-contain-timestamps-for-al.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0029-fixed-if-container-doesn-t-contain-timestamps-for-al.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0029-fixed-if-container-doesn-t-contain-timestamps-for-al.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0029-fixed-if-container-doesn-t-contain-timestamps-for-al.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,29 +0,0 @@ +-From ab91f9fecf9ac6e38dbf5d9ed65a5bd123a4c031 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Tue, 19 Oct 2010 21:07:10 +0000 +-Subject: [PATCH 29/36] fixed: if container doesn't contain timestamps for all dts packets, lavf used wrong duration of packet to fill in the blanks +- +-The issue was discussed here: http://forum.xbmc.org/showthread.php?t=82896 +- +-Ps. The DTS parser is really lacking. It doesn't fill in anything, it only slices up the frames. So if this value changes mid stream, we will start calculating this wrong again. I'm pondering if we should just stop trying to fill in the blanks. +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@34863 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavcodec/dca.c | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/libavcodec/dca.c b/libavcodec/dca.c +-index 63ea329..2e2b37f 100644 +---- a/libavcodec/dca.c +-+++ b/libavcodec/dca.c +-@@ -1642,6 +1642,7 @@ static int dca_decode_frame(AVCodecContext * avctx, +- //set AVCodec values with parsed data +- avctx->sample_rate = s->sample_rate; +- avctx->bit_rate = s->bit_rate; +-+ avctx->frame_size = s->sample_blocks * 32; +- +- s->profile = FF_PROFILE_DTS; +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0030-aacenc-add-recognized-profiles-array.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0030-aacenc-add-recognized-profiles-array.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0030-aacenc-add-recognized-profiles-array.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0030-aacenc-add-recognized-profiles-array.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,35 +0,0 @@ +-From fcdd099e3df44d7e577b2bfc0d03c2617d0dd870 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Fri, 21 Jan 2011 20:44:02 +0200 +-Subject: [PATCH 30/36] aacenc: add recognized profiles array +- +-Submitted upstream. +---- +- libavcodec/aacenc.c | 6 ++++++ +- 1 files changed, 6 insertions(+), 0 deletions(-) +- +-diff --git a/libavcodec/aacenc.c b/libavcodec/aacenc.c +-index 50dab1c..237f338 100644 +---- a/libavcodec/aacenc.c +-+++ b/libavcodec/aacenc.c +-@@ -641,6 +641,11 @@ static av_cold int aac_encode_end(AVCodecContext *avctx) +- return 0; +- } +- +-+static const AVProfile profiles[] = { +-+ { FF_PROFILE_AAC_LOW, "Low" }, +-+ { FF_PROFILE_UNKNOWN }, +-+}; +-+ +- AVCodec ff_aac_encoder = { +- "aac", +- AVMEDIA_TYPE_AUDIO, +-@@ -652,4 +657,5 @@ AVCodec ff_aac_encoder = { +- .capabilities = CODEC_CAP_SMALL_LAST_FRAME | CODEC_CAP_DELAY | CODEC_CAP_EXPERIMENTAL, +- .sample_fmts = (const enum AVSampleFormat[]){AV_SAMPLE_FMT_S16,AV_SAMPLE_FMT_NONE}, +- .long_name = NULL_IF_CONFIG_SMALL("Advanced Audio Coding"), +-+ .profiles = profiles, +- }; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0031-fixed-vp3-decoder-should-set-key_frame-field-of-AVFr.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0031-fixed-vp3-decoder-should-set-key_frame-field-of-AVFr.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0031-fixed-vp3-decoder-should-set-key_frame-field-of-AVFr.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0031-fixed-vp3-decoder-should-set-key_frame-field-of-AVFr.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From 23c286841dda2df21bb05917ff6895bec1854f61 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Tue, 14 Sep 2010 00:42:57 +0000 +-Subject: [PATCH 31/36] fixed: vp3 decoder should set key_frame field of AVFrame +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@33768 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavcodec/vp3.c | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c +-index 06f55f6..d634fca 100644 +---- a/libavcodec/vp3.c +-+++ b/libavcodec/vp3.c +-@@ -1765,6 +1765,7 @@ static int vp3_decode_frame(AVCodecContext *avctx, +- +- s->current_frame.reference = 3; +- s->current_frame.pict_type = s->keyframe ? FF_I_TYPE : FF_P_TYPE; +-+ s->current_frame.key_frame = s->keyframe; +- if (avctx->get_buffer(avctx, &s->current_frame) < 0) { +- av_log(s->avctx, AV_LOG_ERROR, "get_buffer() failed\n"); +- goto error; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0032-changed-allow-8-second-skew-between-streams-in-mov-b.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0032-changed-allow-8-second-skew-between-streams-in-mov-b.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0032-changed-allow-8-second-skew-between-streams-in-mov-b.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0032-changed-allow-8-second-skew-between-streams-in-mov-b.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,28 +0,0 @@ +-From 4dbb736cc971f8b4e305b2c2d44353f53235bb25 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Wed, 8 Dec 2010 14:03:43 +0000 +-Subject: [PATCH 32/36] changed: allow 8 second skew between streams in mov before attempting to seek +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@35598 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavformat/mov.c | 4 ++-- +- 1 files changed, 2 insertions(+), 2 deletions(-) +- +-diff --git a/libavformat/mov.c b/libavformat/mov.c +-index a48000f..18ecbb9 100644 +---- a/libavformat/mov.c +-+++ b/libavformat/mov.c +-@@ -2386,8 +2386,8 @@ static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st) +- if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || +- (!url_is_streamed(s->pb) && +- ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && +-- ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || +-- (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { +-+ ((FFABS(best_dts - dts) <= 8*AV_TIME_BASE && current_sample->pos < sample->pos) || +-+ (FFABS(best_dts - dts) > 8*AV_TIME_BASE && dts < best_dts)))))) { +- sample = current_sample; +- best_dts = dts; +- *st = avst; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0033-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0033-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0033-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0033-fixed-memleak-in-mpegts-demuxer-on-some-malformed-mp.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,39 +0,0 @@ +-From c8c185cc7890cc2bbcc285810f5ac801a8d7ef1e Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Fri, 26 Nov 2010 20:56:48 +0000 +-Subject: [PATCH 33/36] fixed: memleak in mpegts demuxer on some malformed (??) mpegts files with too large pes packets +- +-at-visions sample file brokenStream.mpg +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@35475 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavformat/mpegts.c | 6 ++++++ +- 1 files changed, 6 insertions(+), 0 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index 2fc0089..112ff50 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -616,6 +616,10 @@ static int mpegts_set_stream_info(AVStream *st, PESContext *pes, +- +- static void new_pes_packet(PESContext *pes, AVPacket *pkt) +- { +-+ if(pkt->data) { +-+ av_log(pes->stream, AV_LOG_ERROR, "ignoring previously allocated packet on stream %d\n", pkt->stream_index); +-+ av_free_packet(pkt); +-+ } +- av_init_packet(pkt); +- +- pkt->destruct = av_destruct_packet; +-@@ -1657,6 +1661,8 @@ static int mpegts_read_packet(AVFormatContext *s, +- } +- +- ts->pkt = pkt; +-+ ts->pkt->data = NULL; +-+ +- ret = handle_packets(ts, 0); +- if (ret < 0) { +- /* flush pes data left */ +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0034-fixed-dvd-still-frames-as-first-frame-caused-lavf-to.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0034-fixed-dvd-still-frames-as-first-frame-caused-lavf-to.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0034-fixed-dvd-still-frames-as-first-frame-caused-lavf-to.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0034-fixed-dvd-still-frames-as-first-frame-caused-lavf-to.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,28 +0,0 @@ +-From 91aab72bc6f677a96471de18bbf2ccc1363441be Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Thu, 15 Jul 2010 22:24:57 +0000 +-Subject: [PATCH 34/36] fixed: dvd still frames as first frame caused lavf to return CODEC_ID_PROBE, aswell as put the whole menu into an internal buffer. +- +-This fixes #9470 aswell as makes our (incomplete) hacks in DVDDemuxerFFMpeg for this case redundant. Getting this upstream would be good, but we'd need a mpeg sample file. One can be generated by chopping a .vob file at a location where there is only a singular still frame available. +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@31831 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavformat/utils.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index fe3b453..e2881ba 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -739,7 +739,7 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) +- +- if(av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ +- //FIXME we dont reduce score to 0 for the case of running out of buffer space in bytes +-- set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4 : 0); +-+ set_codec_from_probe_data(s, st, pd, st->probe_packets > 0 ? AVPROBE_SCORE_MAX/4-1 : 0); +- if(st->codec->codec_id != CODEC_ID_PROBE){ +- pd->buf_size=0; +- av_freep(&pd->buf); +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0035-Speed-up-mpegts-av_find_stream_info.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0035-Speed-up-mpegts-av_find_stream_info.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0035-Speed-up-mpegts-av_find_stream_info.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0035-Speed-up-mpegts-av_find_stream_info.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,38 +0,0 @@ +-From b3b5bde15444655b238ba68c5052c3e41b2e7cf6 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Mon, 28 Jun 2010 21:26:54 +0000 +-Subject: [PATCH 35/36] Speed up mpegts av_find_stream_info +- +-git-svn-id: https://xbmc.svn.sourceforge.net/svnroot/xbmc/trunk@31478 568bbfeb-2a22-0410-94d2-cc84cf5bfa90 +---- +- libavformat/mpegts.c | 7 +++++-- +- 1 files changed, 5 insertions(+), 2 deletions(-) +- +-diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c +-index 112ff50..9c25e37 100644 +---- a/libavformat/mpegts.c +-+++ b/libavformat/mpegts.c +-@@ -699,7 +699,7 @@ static int mpegts_push_data(MpegTSFilter *filter, +- #endif +- +- /* stream not present in PMT */ +-- if (!pes->st) { +-+ if (ts->auto_guess && !pes->st) { +- pes->st = av_new_stream(ts->stream, pes->pid); +- if (!pes->st) +- return AVERROR(ENOMEM); +-@@ -1539,7 +1539,10 @@ static int mpegts_read_header(AVFormatContext *s, +- +- av_dlog(ts->stream, "tuning done\n"); +- +-- s->ctx_flags |= AVFMTCTX_NOHEADER; +-+ /* only flag NOHEADER if we are in file mode, +-+ in streaming mode scanning may take too long for users */ +-+ if (!url_is_streamed(pb)) +-+ s->ctx_flags |= AVFMTCTX_NOHEADER; +- } else { +- AVStream *st; +- int pcr_pid, pid, nb_packets, nb_pcrs, ret, pcr_l; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0036-swscale-fix-build-with-enable-runtime-cpudetect-disa.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0036-swscale-fix-build-with-enable-runtime-cpudetect-disa.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0036-swscale-fix-build-with-enable-runtime-cpudetect-disa.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0036-swscale-fix-build-with-enable-runtime-cpudetect-disa.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,56 +0,0 @@ +-From 189505c7a47007ae25fe9d4c46787c3ef9378dc9 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Wed, 2 Feb 2011 19:36:23 +0200 +-Subject: [PATCH 36/36] swscale: fix build with --enable-runtime-cpudetect --disable-mmx/mmx2/amd3dnow +- +-Commit 0fc29f2708a "swscale: simplify selection of optimizations to +-compile." (25 Aug 2010) changed the behaviour so that with +---enable-runtime-cpudetect --disable-mmx/mmx2/amd3dnow the instruction +-sets are actually disabled. +- +-However, ff_getSwsFunc() still calls the respective initialization +-functions which no longer exist, causing a build failure. +- +-Fix that by putting those calls under #if as well. +---- +- libswscale/swscale.c | 15 +++++++++++---- +- 1 files changed, 11 insertions(+), 4 deletions(-) +- +-diff --git a/libswscale/swscale.c b/libswscale/swscale.c +-index 375171f..8d7bb73 100644 +---- a/libswscale/swscale.c +-+++ b/libswscale/swscale.c +-@@ -1262,19 +1262,26 @@ SwsFunc ff_getSwsFunc(SwsContext *c) +- +- #if ARCH_X86 +- // ordered per speed fastest first +-+#if COMPILE_MMX2 +- if (flags & SWS_CPU_CAPS_MMX2) { +- sws_init_swScale_MMX2(c); +- return swScale_MMX2; +-- } else if (flags & SWS_CPU_CAPS_3DNOW) { +-+ } +-+#endif +-+#if COMPILE_3DNOW +-+ if (flags & SWS_CPU_CAPS_3DNOW) { +- sws_init_swScale_3DNow(c); +- return swScale_3DNow; +-- } else if (flags & SWS_CPU_CAPS_MMX) { +-+ } +-+#endif +-+#if COMPILE_MMX +-+ if (flags & SWS_CPU_CAPS_MMX) { +- sws_init_swScale_MMX(c); +- return swScale_MMX; +-- } else { +-+ } +-+#endif +- sws_init_swScale_C(c); +- return swScale_C; +-- } +- +- #else +- #if COMPILE_ALTIVEC +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0037-configure-check-yasm-nasm-for-working-pextrd-opcode.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0037-configure-check-yasm-nasm-for-working-pextrd-opcode.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0037-configure-check-yasm-nasm-for-working-pextrd-opcode.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0037-configure-check-yasm-nasm-for-working-pextrd-opcode.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,41 +0,0 @@ +-From f35c0b93a336edb04149c76105480fb1076a5f6c Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Sun, 6 Feb 2011 07:42:55 +0200 +-Subject: [PATCH] configure: check yasm/nasm for working pextrd opcode +- +-NASM versions older than 2.08 fail to build ffmpeg with several +-"error: operation size not specified" errors but this is not caught in +-configure. +- +-Fix that by checking if "pextrd [eax], xmm0, 1" works in configure. +- +---- +- +-For the record, here are (some of?) the errors: +-libavcodec/x86/vc1dsp_yasm.asm:329: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:967: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:968: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:969: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:1629: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:2854: error: operation size not specified +-libavcodec/x86/vp8dsp.asm:2858: error: operation size not specified +---- +- configure | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/configure b/configure +-index 83d9b87..a62e131 100755 +---- a/configure +-+++ b/configure +-@@ -2672,7 +2672,7 @@ EOF +- elf*) enabled debug && append YASMFLAGS $yasm_debug ;; +- esac +- +-- check_yasm "pabsw xmm0, xmm0" && enable yasm || +-+ check_yasm "pextrd [eax], xmm0, 1" && enable yasm || +- die "yasm not found, use --disable-yasm for a crippled build" +- fi +- +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0038-rtsp-Don-t-store-RTSPStream-in-AVStream-priv_data.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0038-rtsp-Don-t-store-RTSPStream-in-AVStream-priv_data.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0038-rtsp-Don-t-store-RTSPStream-in-AVStream-priv_data.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0038-rtsp-Don-t-store-RTSPStream-in-AVStream-priv_data.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,108 +0,0 @@ +-From b1eb9860a582ec9459e871c00f23b5fc2500aaf4 Mon Sep 17 00:00:00 2001 +-From: =?UTF-8?q?Martin=20Storsj=C3=B6?= +-Date: Wed, 2 Feb 2011 11:08:01 +0200 +-Subject: [PATCH] rtsp: Don't store RTSPStream in AVStream->priv_data +- +-For mpegts in RTP, there isn't a direct mapping between RTSPStreams +-and AVStreams, and the RTSPStream isn't ever stored in +-AVStream->priv_data, which was earlier leaked. The fix for this +-leak, in ea7f080749d68a431226ce196014da38761a0d82, lead to +-double frees for other, normal RTP streams. +- +-This patch avoids storing RTSPStreams in AVStream->priv_data, thus +-avoiding the double free. The RTSPStreams are always available via +-RTSPState->rtsp_streams anyway. +- +-Tested with MS-RTSP, RealRTSP, DSS and mpegts/RTP. +- +-Signed-off-by: Luca Barbato +-(cherry picked from commit d9c0510e22821baa364306d867ffac45da0620c8) +---- +- libavformat/rtsp.c | 16 ++++++---------- +- libavformat/rtspenc.c | 2 -- +- 2 files changed, 6 insertions(+), 12 deletions(-) +- +-diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c +-index 09e2f1e..e1d7503 100644 +---- a/libavformat/rtsp.c +-+++ b/libavformat/rtsp.c +-@@ -273,8 +273,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- s1->default_ip = sdp_ip; +- s1->default_ttl = ttl; +- } else { +-- st = s->streams[s->nb_streams - 1]; +-- rtsp_st = st->priv_data; +-+ rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; +- rtsp_st->sdp_ip = sdp_ip; +- rtsp_st->sdp_ttl = ttl; +- } +-@@ -326,7 +325,6 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- st = av_new_stream(s, 0); +- if (!st) +- return; +-- st->priv_data = rtsp_st; +- rtsp_st->stream_index = st->index; +- st->codec->codec_type = codec_type; +- if (rtsp_st->sdp_payload_type < RTP_PT_PRIVATE) { +-@@ -355,8 +353,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- } else { +- char proto[32]; +- /* get the control url */ +-- st = s->streams[s->nb_streams - 1]; +-- rtsp_st = st->priv_data; +-+ rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; +- +- /* XXX: may need to add full url resolution */ +- av_url_split(proto, sizeof(proto), NULL, 0, NULL, 0, +-@@ -377,7 +374,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- get_word(buf1, sizeof(buf1), &p); +- payload_type = atoi(buf1); +- st = s->streams[s->nb_streams - 1]; +-- rtsp_st = st->priv_data; +-+ rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; +- sdp_parse_rtpmap(s, st, rtsp_st, payload_type, p); +- } else if (av_strstart(p, "fmtp:", &p) || +- av_strstart(p, "framesize:", &p)) { +-@@ -385,9 +382,8 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- // let dynamic protocol handlers have a stab at the line. +- get_word(buf1, sizeof(buf1), &p); +- payload_type = atoi(buf1); +-- for (i = 0; i < s->nb_streams; i++) { +-- st = s->streams[i]; +-- rtsp_st = st->priv_data; +-+ for (i = 0; i < rt->nb_rtsp_streams; i++) { +-+ rtsp_st = rt->rtsp_streams[i]; +- if (rtsp_st->sdp_payload_type == payload_type && +- rtsp_st->dynamic_handler && +- rtsp_st->dynamic_handler->parse_sdp_a_line) +-@@ -417,7 +413,7 @@ static void sdp_parse_line(AVFormatContext *s, SDPParseState *s1, +- if (rt->server_type == RTSP_SERVER_REAL) +- ff_real_parse_sdp_a_line(s, s->nb_streams - 1, p); +- +-- rtsp_st = s->streams[s->nb_streams - 1]->priv_data; +-+ rtsp_st = rt->rtsp_streams[rt->nb_rtsp_streams - 1]; +- if (rtsp_st->dynamic_handler && +- rtsp_st->dynamic_handler->parse_sdp_a_line) +- rtsp_st->dynamic_handler->parse_sdp_a_line(s, +-diff --git a/libavformat/rtspenc.c b/libavformat/rtspenc.c +-index d54be1a..34deeeb 100644 +---- a/libavformat/rtspenc.c +-+++ b/libavformat/rtspenc.c +-@@ -79,14 +79,12 @@ int ff_rtsp_setup_output_streams(AVFormatContext *s, const char *addr) +- /* Set up the RTSPStreams for each AVStream */ +- for (i = 0; i < s->nb_streams; i++) { +- RTSPStream *rtsp_st; +-- AVStream *st = s->streams[i]; +- +- rtsp_st = av_mallocz(sizeof(RTSPStream)); +- if (!rtsp_st) +- return AVERROR(ENOMEM); +- dynarray_add(&rt->rtsp_streams, &rt->nb_rtsp_streams, rtsp_st); +- +-- st->priv_data = rtsp_st; +- rtsp_st->stream_index = i; +- +- av_strlcpy(rtsp_st->control_url, rt->control_uri, sizeof(rtsp_st->control_url)); +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0039-spdifenc-fix-byte-order-on-big-endian-systems.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0039-spdifenc-fix-byte-order-on-big-endian-systems.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0039-spdifenc-fix-byte-order-on-big-endian-systems.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0039-spdifenc-fix-byte-order-on-big-endian-systems.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,121 +0,0 @@ +-From a8dd9e056114a80d11c77efbdfe4b22610f452db Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Mon, 27 Dec 2010 05:16:54 +0200 +-Subject: [PATCH] spdifenc: fix byte order on big-endian systems +- +-There is a check for HAVE_BIGENDIAN when outputting the IEC 61937 +-stream. On big-endian systems the payload data is not byteswapped, +-causing in effect the outputted payload data to be in a different byte +-order on big-endian than on little-endian systems. +- +-However, the IEC 61937 preamble (and the final odd byte if present) is +-always outputted in the same byte order. This means that on big-endian +-systems the headers have a different byte order than the payload, +-preventing useful use of the output. +- +-Fix that by outputting the data in a format suitable for sending to an +-audio device in S16LE format by default. Output as big-endian (S16BE) +-is added as an AVOption. This makes the muxer output the same on all +-archs by default. +- +---- +- +-Other ways to fix this would be to +-a) simply always output in little-endian format, or +-b) always output in native-endian format (i.e. different muxer output +-depending on arch), or +-c) have two different logical muxers. +---- +- libavformat/spdifenc.c | 35 +++++++++++++++++++++++++++++------ +- 1 files changed, 29 insertions(+), 6 deletions(-) +- +-diff --git a/libavformat/spdifenc.c b/libavformat/spdifenc.c +-index 3eea31e..9b0001c 100644 +---- a/libavformat/spdifenc.c +-+++ b/libavformat/spdifenc.c +-@@ -49,6 +49,7 @@ +- #include "libavcodec/ac3.h" +- #include "libavcodec/dca.h" +- #include "libavcodec/aacadtsdec.h" +-+#include "libavutil/opt.h" +- +- typedef struct IEC61937Context { +- enum IEC61937DataType data_type;///< burst info - reference to type of payload of the data-burst +-@@ -68,11 +69,22 @@ typedef struct IEC61937Context { +- int hd_buf_count; ///< number of frames in the hd audio buffer +- int hd_buf_filled; ///< amount of bytes in the hd audio buffer +- +-+ /* AVOptions: */ +-+#define SPDIF_FLAG_BIGENDIAN 0x01 +-+ int spdif_flags; +-+ +- /// function, which generates codec dependent header information. +- /// Sets data_type and pkt_offset, and length_code, out_bytes, out_buf if necessary +- int (*header_info) (AVFormatContext *s, AVPacket *pkt); +- } IEC61937Context; +- +-+static const AVOption options[] = { +-+{ "spdif_flags", "IEC 61937 encapsulation flags", offsetof(IEC61937Context, spdif_flags), FF_OPT_TYPE_FLAGS, 0, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, +-+{ "be", "output in big-endian format (for use as s16be)", 0, FF_OPT_TYPE_CONST, SPDIF_FLAG_BIGENDIAN, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM, "spdif_flags" }, +-+{ NULL }, +-+}; +-+ +-+static const AVClass class = { "spdif", av_default_item_name, options, LIBAVUTIL_VERSION_INT }; +- +- static int spdif_header_ac3(AVFormatContext *s, AVPacket *pkt) +- { +-@@ -330,6 +342,15 @@ static int spdif_write_trailer(AVFormatContext *s) +- return 0; +- } +- +-+static void spdif_put_16(struct AVFormatContext *s, unsigned int val) +-+{ +-+ IEC61937Context *ctx = s->priv_data; +-+ if (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN) +-+ put_be16(s->pb, val); +-+ else +-+ put_le16(s->pb, val); +-+} +-+ +- static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) +- { +- IEC61937Context *ctx = s->priv_data; +-@@ -354,13 +375,13 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) +- } +- +- if (ctx->use_preamble) { +-- put_le16(s->pb, SYNCWORD1); //Pa +-- put_le16(s->pb, SYNCWORD2); //Pb +-- put_le16(s->pb, ctx->data_type); //Pc +-- put_le16(s->pb, ctx->length_code);//Pd +-+ spdif_put_16(s, SYNCWORD1); //Pa +-+ spdif_put_16(s, SYNCWORD2); //Pb +-+ spdif_put_16(s, ctx->data_type); //Pc +-+ spdif_put_16(s, ctx->length_code);//Pd +- } +- +-- if (HAVE_BIGENDIAN ^ ctx->extra_bswap) { +-+ if (ctx->extra_bswap ^ (ctx->spdif_flags & SPDIF_FLAG_BIGENDIAN)) { +- put_buffer(s->pb, ctx->out_buf, ctx->out_bytes & ~1); +- } else { +- av_fast_malloc(&ctx->buffer, &ctx->buffer_size, ctx->out_bytes + FF_INPUT_BUFFER_PADDING_SIZE); +-@@ -370,8 +391,9 @@ static int spdif_write_packet(struct AVFormatContext *s, AVPacket *pkt) +- put_buffer(s->pb, ctx->buffer, ctx->out_bytes & ~1); +- } +- +-+ /* a final lone byte has to be MSB aligned */ +- if (ctx->out_bytes & 1) +-- put_be16(s->pb, ctx->out_buf[ctx->out_bytes - 1]); +-+ spdif_put_16(s, ctx->out_buf[ctx->out_bytes - 1] << 8); +- +- put_nbyte(s->pb, 0, padding); +- +-@@ -393,4 +415,5 @@ AVOutputFormat ff_spdif_muxer = { +- spdif_write_header, +- spdif_write_packet, +- spdif_write_trailer, +-+ .priv_class = &class, +- }; +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0040-Add-our-MAX_STREAMS-hack-back-it-was-lost-after-the-.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0040-Add-our-MAX_STREAMS-hack-back-it-was-lost-after-the-.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0040-Add-our-MAX_STREAMS-hack-back-it-was-lost-after-the-.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0040-Add-our-MAX_STREAMS-hack-back-it-was-lost-after-the-.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,28 +0,0 @@ +-From 03e5595ec1d5a87d61a67443634b0c56af7cd22c Mon Sep 17 00:00:00 2001 +-From: theuni +-Date: Mon, 7 Feb 2011 16:00:50 -0500 +-Subject: [PATCH] Add our MAX_STREAMS hack back, it was lost after the ffmpeg update. +- +-Fixes playback of some streams (one of my test mkvs). +- +-This should be removed on ffmpeg major version bump. +---- +- lib/ffmpeg/libavformat/avformat.h | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/avformat.h b/lib/ffmpeg/libavformat/avformat.h +-index f9f9be5..dec8091 100644 +---- a/lib/ffmpeg/libavformat/avformat.h +-+++ b/lib/ffmpeg/libavformat/avformat.h +-@@ -667,7 +667,7 @@ typedef struct AVChapter { +- } AVChapter; +- +- #if FF_API_MAX_STREAMS +--#define MAX_STREAMS 20 +-+#define MAX_STREAMS 100 +- #endif +- +- /** +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0041-lavf-update-ff_probe_input_buffer-documentation.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0041-lavf-update-ff_probe_input_buffer-documentation.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0041-lavf-update-ff_probe_input_buffer-documentation.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0041-lavf-update-ff_probe_input_buffer-documentation.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,29 +0,0 @@ +-From acdac292f7c1691d21e19c1e9a993e501883fd6b Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Tue, 8 Feb 2011 00:46:51 +0200 +-Subject: [PATCH 41/43] lavf: update ff_probe_input_buffer documentation +- +-It never reopens the bytestream anymore. +- +-Signed-off-by: Ronald S. Bultje +-(cherry picked from commit 4d016dd4e5b288b3c0c7396935326cb07a289ac2) +---- +- libavformat/internal.h | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/libavformat/internal.h b/libavformat/internal.h +-index b401d35..a17d9c6 100644 +---- a/libavformat/internal.h +-+++ b/libavformat/internal.h +-@@ -88,7 +88,7 @@ uint64_t ff_ntp_time(void); +- * attempt is made. When the maximum probe size is reached, the input format +- * with the highest score is returned. +- * +-- * @param pb the bytestream to probe, it may be closed and opened again +-+ * @param pb the bytestream to probe +- * @param fmt the input format is put here +- * @param filename the filename of the stream +- * @param logctx the log context +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0042-lavf-simplify-pb-parameter-of-ff_probe_input_buffer.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0042-lavf-simplify-pb-parameter-of-ff_probe_input_buffer.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0042-lavf-simplify-pb-parameter-of-ff_probe_input_buffer.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0042-lavf-simplify-pb-parameter-of-ff_probe_input_buffer.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,71 +0,0 @@ +-From c0cbd02d3bcd49f4258a9ba86004e70a56bb3a64 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Tue, 8 Feb 2011 00:46:52 +0200 +-Subject: [PATCH 42/43] lavf: simplify pb parameter of ff_probe_input_buffer +- +-There is no need to pass the ByteIOContext via a pointer to a pointer +-anymore. +- +-Signed-off-by: Ronald S. Bultje +-(cherry picked from commit aad216fd7e3209fe0a865d8751e680925f6654d3) +---- +- libavformat/internal.h | 2 +- +- libavformat/utils.c | 8 ++++---- +- 2 files changed, 5 insertions(+), 5 deletions(-) +- +-diff --git a/libavformat/internal.h b/libavformat/internal.h +-index a17d9c6..f2f3ddc 100644 +---- a/libavformat/internal.h +-+++ b/libavformat/internal.h +-@@ -97,7 +97,7 @@ uint64_t ff_ntp_time(void); +- * @return 0 in case of success, a negative value corresponding to an +- * AVERROR code otherwise +- */ +--int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, +-+int ff_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +- const char *filename, void *logctx, +- unsigned int offset, unsigned int max_probe_size); +- +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index e2881ba..f5b22a2 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -524,7 +524,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr, +- #define PROBE_BUF_MIN 2048 +- #define PROBE_BUF_MAX (1<<20) +- +--int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, +-+int ff_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +- const char *filename, void *logctx, +- unsigned int offset, unsigned int max_probe_size) +- { +-@@ -555,7 +555,7 @@ int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, +- +- /* read probe data */ +- buf = av_realloc(buf, probe_size + AVPROBE_PADDING_SIZE); +-- if ((ret = get_buffer(*pb, buf + buf_offset, probe_size - buf_offset)) < 0) { +-+ if ((ret = get_buffer(pb, buf + buf_offset, probe_size - buf_offset)) < 0) { +- /* fail if error was not end of file, otherwise, lower score */ +- if (ret != AVERROR_EOF) { +- av_free(buf); +-@@ -585,7 +585,7 @@ int ff_probe_input_buffer(ByteIOContext **pb, AVInputFormat **fmt, +- } +- +- /* rewind. reuse probe buffer to avoid seeking */ +-- if ((ret = ff_rewind_with_probe_data(*pb, buf, pd.buf_size)) < 0) +-+ if ((ret = ff_rewind_with_probe_data(pb, buf, pd.buf_size)) < 0) +- av_free(buf); +- +- return ret; +-@@ -622,7 +622,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, +- if (buf_size > 0) { +- url_setbufsize(pb, buf_size); +- } +-- if (!fmt && (err = ff_probe_input_buffer(&pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { +-+ if (!fmt && (err = ff_probe_input_buffer(pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { +- goto fail; +- } +- } +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0043-lavf-rename-ff_probe_input_buffer-to-make-it-public.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0043-lavf-rename-ff_probe_input_buffer-to-make-it-public.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0043-lavf-rename-ff_probe_input_buffer-to-make-it-public.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0043-lavf-rename-ff_probe_input_buffer-to-make-it-public.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,100 +0,0 @@ +-From 90a931ab9378be64cdffb33f8490b6891ebb9ad8 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Tue, 8 Feb 2011 00:46:53 +0200 +-Subject: [PATCH 43/43] lavf: rename ff_probe_input_buffer to make it public +- +-It is useful for applications that hand input data directly to lavf via +-a ByteIOContext. +- +-Signed-off-by: Ronald S. Bultje +---- +- libavformat/avformat.h | 19 +++++++++++++++++++ +- libavformat/internal.h | 19 ------------------- +- libavformat/utils.c | 4 ++-- +- 3 files changed, 21 insertions(+), 21 deletions(-) +- +-diff --git a/libavformat/avformat.h b/libavformat/avformat.h +-index dec8091..a08d843 100644 +---- a/libavformat/avformat.h +-+++ b/libavformat/avformat.h +-@@ -1039,6 +1039,25 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened); +- AVInputFormat *av_probe_input_format2(AVProbeData *pd, int is_opened, int *score_max); +- +- /** +-+ * Probe a bytestream to determine the input format. Each time a probe returns +-+ * with a score that is too low, the probe buffer size is increased and another +-+ * attempt is made. When the maximum probe size is reached, the input format +-+ * with the highest score is returned. +-+ * +-+ * @param pb the bytestream to probe +-+ * @param fmt the input format is put here +-+ * @param filename the filename of the stream +-+ * @param logctx the log context +-+ * @param offset the offset within the bytestream to probe from +-+ * @param max_probe_size the maximum probe buffer size (zero for default) +-+ * @return 0 in case of success, a negative value corresponding to an +-+ * AVERROR code otherwise +-+ */ +-+int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +-+ const char *filename, void *logctx, +-+ unsigned int offset, unsigned int max_probe_size); +-+ +-+/** +- * Allocate all the structures needed to read an input stream. +- * This does not open the needed codecs for decoding the stream[s]. +- */ +-diff --git a/libavformat/internal.h b/libavformat/internal.h +-index f2f3ddc..738b59d 100644 +---- a/libavformat/internal.h +-+++ b/libavformat/internal.h +-@@ -82,25 +82,6 @@ void ff_read_frame_flush(AVFormatContext *s); +- /** Get the current time since NTP epoch in microseconds. */ +- uint64_t ff_ntp_time(void); +- +--/** +-- * Probe a bytestream to determine the input format. Each time a probe returns +-- * with a score that is too low, the probe buffer size is increased and another +-- * attempt is made. When the maximum probe size is reached, the input format +-- * with the highest score is returned. +-- * +-- * @param pb the bytestream to probe +-- * @param fmt the input format is put here +-- * @param filename the filename of the stream +-- * @param logctx the log context +-- * @param offset the offset within the bytestream to probe from +-- * @param max_probe_size the maximum probe buffer size (zero for default) +-- * @return 0 in case of success, a negative value corresponding to an +-- * AVERROR code otherwise +-- */ +--int ff_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +-- const char *filename, void *logctx, +-- unsigned int offset, unsigned int max_probe_size); +-- +- #if FF_API_URL_SPLIT +- /** +- * @deprecated use av_url_split() instead +-diff --git a/libavformat/utils.c b/libavformat/utils.c +-index f5b22a2..bee0475 100644 +---- a/libavformat/utils.c +-+++ b/libavformat/utils.c +-@@ -524,7 +524,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr, +- #define PROBE_BUF_MIN 2048 +- #define PROBE_BUF_MAX (1<<20) +- +--int ff_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +-+int av_probe_input_buffer(ByteIOContext *pb, AVInputFormat **fmt, +- const char *filename, void *logctx, +- unsigned int offset, unsigned int max_probe_size) +- { +-@@ -622,7 +622,7 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, +- if (buf_size > 0) { +- url_setbufsize(pb, buf_size); +- } +-- if (!fmt && (err = ff_probe_input_buffer(pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { +-+ if (!fmt && (err = av_probe_input_buffer(pb, &fmt, filename, logctx, 0, logctx ? (*ic_ptr)->probesize : 0)) < 0) { +- goto fail; +- } +- } +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0044-MMS-also-discover-streams-in-extended-stream-propert.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0044-MMS-also-discover-streams-in-extended-stream-propert.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0044-MMS-also-discover-streams-in-extended-stream-propert.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0044-MMS-also-discover-streams-in-extended-stream-propert.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,56 +0,0 @@ +-From 91861ce25c7f19c38afdb0f115bf90118fc19428 Mon Sep 17 00:00:00 2001 +-From: Marton Balint +-Date: Sat, 19 Feb 2011 17:33:15 +0100 +-Subject: [PATCH] MMS: also discover streams in extended stream properties object +- +-Allows playback of nonprimary audio streams in multiple bitrate sources, +-such as mmsh://wmscr1.dr.dk/e02ch03m +- +-Signed-off-by: Ronald S. Bultje +-(cherry picked from commit 74d6871d6244865b5863a01c3dab16a2f06a1706) +---- +- libavformat/mms.c | 28 ++++++++++++++++++++++++++++ +- 1 files changed, 28 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/mms.c b/lib/ffmpeg/libavformat/mms.c +-index d995a43..b541208 100644 +---- a/lib/ffmpeg/libavformat/mms.c +-+++ b/lib/ffmpeg/libavformat/mms.c +-@@ -115,6 +115,34 @@ int ff_mms_asf_header_parser(MMSContext *mms) +- "Corrupt stream (too many A/V streams)\n"); +- return AVERROR_INVALIDDATA; +- } +-+ } else if (!memcmp(p, ff_asf_ext_stream_header, sizeof(ff_asf_guid))) { +-+ if (end - p >= 88) { +-+ int stream_count = AV_RL16(p + 84), ext_len_count = AV_RL16(p + 86); +-+ uint64_t skip_bytes = 88; +-+ while (stream_count--) { +-+ if (end - p < skip_bytes + 4) { +-+ av_log(NULL, AV_LOG_ERROR, +-+ "Corrupt stream (next stream name length is not in the buffer)\n"); +-+ return AVERROR_INVALIDDATA; +-+ } +-+ skip_bytes += 4 + AV_RL16(p + skip_bytes + 2); +-+ } +-+ while (ext_len_count--) { +-+ if (end - p < skip_bytes + 22) { +-+ av_log(NULL, AV_LOG_ERROR, +-+ "Corrupt stream (next extension system info length is not in the buffer)\n"); +-+ return AVERROR_INVALIDDATA; +-+ } +-+ skip_bytes += 22 + AV_RL32(p + skip_bytes + 18); +-+ } +-+ if (end - p < skip_bytes) { +-+ av_log(NULL, AV_LOG_ERROR, +-+ "Corrupt stream (the last extension system info length is invalid)\n"); +-+ return AVERROR_INVALIDDATA; +-+ } +-+ if (chunksize - skip_bytes > 24) +-+ chunksize = skip_bytes; +-+ } +- } else if (!memcmp(p, ff_asf_head1_guid, sizeof(ff_asf_guid))) { +- chunksize = 46; // see references [2] section 3.4. This should be set 46. +- } +--- +-1.7.0.4 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0045-allow-customizing-shared-library-soname-name-with-ma.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0045-allow-customizing-shared-library-soname-name-with-ma.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0045-allow-customizing-shared-library-soname-name-with-ma.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0045-allow-customizing-shared-library-soname-name-with-ma.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-From c2a0201aa2a34114f0588a95840ce3ff86554769 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Wed, 23 Feb 2011 19:24:07 +0200 +-Subject: [PATCH] allow customizing shared library soname (name with major) +- +-This is a hack. +---- +- configure | 4 ++++ +- 1 files changed, 4 insertions(+), 0 deletions(-) +- +-diff --git a/configure b/configure +-index a62e131..fec801c 100755 +---- a/configure +-+++ b/configure +-@@ -215,6 +215,7 @@ Advanced options (experts only): +- --arch=ARCH select architecture [$arch] +- --cpu=CPU select the minimum required CPU (affects +- instruction selection, may crash on older CPUs) +-+ --custom-libname-with-major=NAME custom library name with major [$SLIBNAME_WITH_MAJOR] +- --disable-asm disable all assembler optimizations +- --disable-altivec disable AltiVec optimizations +- --disable-amd3dnow disable 3DNow! optimizations +-@@ -1131,6 +1132,7 @@ CMDLINE_SET=" +- cc +- cpu +- cross_prefix +-+ custom_libname_with_major +- dep_cc +- extra_version +- host_cc +-@@ -2477,6 +2479,8 @@ fi +- +- disabled static && LIBNAME="" +- +-+test -n "$custom_libname_with_major" && SLIBNAME_WITH_MAJOR="$custom_libname_with_major" +-+ +- die_license_disabled() { +- enabled $1 || { enabled $2 && die "$2 is $1 and --enable-$1 is not specified."; } +- } +--- +-1.7.3 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0046-os_support-fix-poll-implementation.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0046-os_support-fix-poll-implementation.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0046-os_support-fix-poll-implementation.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0046-os_support-fix-poll-implementation.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,29 +0,0 @@ +-From 9ac2085dbf1821b7995fe360038c1bf0f3940032 Mon Sep 17 00:00:00 2001 +-From: Max Shakhmetov +-Date: Tue, 15 Feb 2011 17:49:27 +0100 +-Subject: [PATCH] os_support: fix poll() implementation +- +-Our poll implementation does not iterate over the pollfd array properly +-while setting the revents. +- +-Signed-off-by: Luca Barbato +---- +- libavformat/os_support.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/os_support.c b/lib/ffmpeg/libavformat/os_support.c +-index 4f73011..0b7b59e 100644 +---- a/lib/ffmpeg/libavformat/os_support.c +-+++ b/lib/ffmpeg/libavformat/os_support.c +-@@ -292,7 +292,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout) +- if (rc < 0) +- return rc; +- +-- for(i = 0; i < (nfds_t) n; i++) { +-+ for(i = 0; i < numfds; i++) { +- fds[i].revents = 0; +- +- if (FD_ISSET(fds[i].fd, &read_set)) fds[i].revents |= POLLIN; +--- +-1.7.0.4 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0047-Backporting-ffmpeg-feature-to-parse-flv-fileposition.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0047-Backporting-ffmpeg-feature-to-parse-flv-fileposition.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0047-Backporting-ffmpeg-feature-to-parse-flv-fileposition.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0047-Backporting-ffmpeg-feature-to-parse-flv-fileposition.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,105 +0,0 @@ +-From 7f608129d581ce028033e399a412cde7f37bc938 Mon Sep 17 00:00:00 2001 +-From: Dani +-Date: Fri, 3 Jun 2011 00:02:06 -0400 +-Subject: [PATCH] Backporting ffmpeg feature to parse flv filepositions so we can seek to certain points in the stream without waiting to buffer, aka pseudostreaming +- +---- +- lib/ffmpeg/libavformat/flvdec.c | 68 +++++++++++++++++++++++++++++++++++++++ +- 1 files changed, 68 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/flvdec.c b/lib/ffmpeg/libavformat/flvdec.c +-index e6081d9..f1c9eda 100644 +---- a/lib/ffmpeg/libavformat/flvdec.c +-+++ b/lib/ffmpeg/libavformat/flvdec.c +-@@ -30,6 +30,10 @@ +- #include "avformat.h" +- #include "flv.h" +- +-+#define KEYFRAMES_TAG "keyframes" +-+#define KEYFRAMES_TIMESTAMP_TAG "times" +-+#define KEYFRAMES_BYTEOFFSET_TAG "filepositions" +-+ +- typedef struct { +- int wrong_dts; ///< wrong dts due to negative cts +- } FLVContext; +-@@ -124,6 +128,66 @@ static int amf_get_string(ByteIOContext *ioc, char *buffer, int buffsize) { +- return length; +- } +- +-+static int parse_keyframes_index(AVFormatContext *s, ByteIOContext *ioc, AVStream *vstream, int64_t max_pos) { +-+ unsigned int timeslen = 0, fileposlen = 0, i; +-+ char str_val[256]; +-+ int64_t *times = NULL; +-+ int64_t *filepositions = NULL; +-+ int ret = AVERROR(ENOSYS); +-+ int64_t initial_pos = url_ftell(ioc); +-+ +-+ while (url_ftell(ioc) < max_pos - 2 && amf_get_string(ioc, str_val, sizeof(str_val)) > 0) { +-+ int64_t** current_array; +-+ unsigned int arraylen; +-+ +-+ // Expect array object in context +-+ if (get_byte(ioc) != AMF_DATA_TYPE_ARRAY) +-+ break; +-+ +-+ arraylen = get_be32(ioc); +-+ if(arraylen>>28) +-+ break; +-+ +-+ if (!strcmp(KEYFRAMES_TIMESTAMP_TAG , str_val) && !times){ +-+ current_array= × +-+ timeslen= arraylen; +-+ }else if (!strcmp(KEYFRAMES_BYTEOFFSET_TAG, str_val) && !filepositions){ +-+ current_array= &filepositions; +-+ fileposlen= arraylen; +-+ }else // unexpected metatag inside keyframes, will not use such metadata for indexing +-+ break; +-+ +-+ if (!(*current_array = av_mallocz(sizeof(**current_array) * arraylen))) { +-+ ret = AVERROR(ENOMEM); +-+ goto finish; +-+ } +-+ +-+ for (i = 0; i < arraylen && url_ftell(ioc) < max_pos - 1; i++) { +-+ if (get_byte(ioc) != AMF_DATA_TYPE_NUMBER) +-+ goto finish; +-+ current_array[0][i] = av_int2dbl(get_be64(ioc)); +-+ } +-+ if (times && filepositions) { +-+ // All done, exiting at a position allowing amf_parse_object +-+ // to finish parsing the object +-+ ret = 0; +-+ break; +-+ } +-+ } +-+ +-+ if (timeslen == fileposlen) { +-+ for(i = 0; i < timeslen; i++) +-+ av_add_index_entry(vstream, filepositions[i], times[i]*1000, 0, 0, AVINDEX_KEYFRAME); +-+ } else +-+ av_log(s, AV_LOG_WARNING, "Invalid keyframes object, skipping.\n"); +-+ +-+finish: +-+ av_freep(×); +-+ av_freep(&filepositions); +-+ url_fseek(ioc, initial_pos, SEEK_SET); +-+ return ret; +-+} +-+ +- static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vstream, const char *key, int64_t max_pos, int depth) { +- AVCodecContext *acodec, *vcodec; +- ByteIOContext *ioc; +-@@ -148,6 +212,10 @@ static int amf_parse_object(AVFormatContext *s, AVStream *astream, AVStream *vst +- case AMF_DATA_TYPE_OBJECT: { +- unsigned int keylen; +- +-+ if (!url_is_streamed(s->pb) && key && !strcmp(KEYFRAMES_TAG, key) && depth == 1) +-+ if (parse_keyframes_index(s, ioc, vstream, max_pos) < 0) +-+ av_log(s, AV_LOG_ERROR, "Keyframe index parsing failed\n"); +-+ +- while(url_ftell(ioc) < max_pos - 2 && (keylen = get_be16(ioc))) { +- url_fskip(ioc, keylen); //skip key string +- if(amf_parse_object(s, NULL, NULL, NULL, max_pos, depth + 1) < 0) +--- +-1.7.0.4 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0048-Dont-mark-genereted-dummy-frame-as-keyframe.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0048-Dont-mark-genereted-dummy-frame-as-keyframe.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0048-Dont-mark-genereted-dummy-frame-as-keyframe.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0048-Dont-mark-genereted-dummy-frame-as-keyframe.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,31 +0,0 @@ +-From fdf7deeb66155a71acf2e34766d376d50f81b43a Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Fri, 22 Apr 2011 15:42:51 +0200 +-Subject: Don't mark generated dummy frame output from mpeg1/2 decoder as keyframe. +- +-We use this flag to tell when to assume decoded data is free +-from artifacts after a seek. The mpeg1/2 decoder will generate +-a dummy frame if decoding is started on a non keyframe. This +-will sadly be output from decoder to player and displayed +-as a gray screen. +- +-diff --git a/lib/ffmpeg/libavcodec/mpegvideo.c b/lib/ffmpeg/libavcodec/mpegvideo.c +-index c8706bc..a0acda1 100644 +---- a/lib/ffmpeg/libavcodec/mpegvideo.c +-+++ b/lib/ffmpeg/libavcodec/mpegvideo.c +-@@ -996,6 +996,7 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) +- /* Allocate a dummy frame */ +- i= ff_find_unused_picture(s, 0); +- s->last_picture_ptr= &s->picture[i]; +-+ s->last_picture_ptr->key_frame = 0; +- if(ff_alloc_picture(s, s->last_picture_ptr, 0) < 0) +- return -1; +- } +-@@ -1003,6 +1004,7 @@ int MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) +- /* Allocate a dummy frame */ +- i= ff_find_unused_picture(s, 0); +- s->next_picture_ptr= &s->picture[i]; +-+ s->next_picture_ptr->key_frame = 0; +- if(ff_alloc_picture(s, s->next_picture_ptr, 0) < 0) +- return -1; +- } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0049-Added-ability-to-enable-workaround-for-dxva2-decodin.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0049-Added-ability-to-enable-workaround-for-dxva2-decodin.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0049-Added-ability-to-enable-workaround-for-dxva2-decodin.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0049-Added-ability-to-enable-workaround-for-dxva2-decodin.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,70 +0,0 @@ +-From f4a0791e9ee825ef54d370b82fce97c9cac92d26 Mon Sep 17 00:00:00 2001 +-From: Joakim Plate +-Date: Sun, 3 Jul 2011 17:18:50 +0200 +-Subject: [PATCH] Added ability to enable workaround for dxva2 decoding using older ATI cards +- +-The workaround need to be enabled per pci id which can not +-be detected inside ffmpeg. So this adds a flag that enabled +-the alternate behavior. +---- +- libavcodec/avcodec.h | 1 + +- libavcodec/dxva2_h264.c | 14 ++++++++++++-- +- 2 files changed, 13 insertions(+), 2 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/avcodec.h b/lib/ffmpeg/libavcodec/avcodec.h +-index 1eb10ab..d642203 100644 +---- a/lib/ffmpeg/libavcodec/avcodec.h +-+++ b/lib/ffmpeg/libavcodec/avcodec.h +-@@ -1441,6 +1441,7 @@ typedef struct AVCodecContext { +- #define FF_BUG_DC_CLIP 4096 +- #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +- #define FF_BUG_TRUNCATED 16384 +-+#define FF_BUG_DXVA2_SCALING_LIST_ZIGZAG 32768 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards +- //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. +- +- /** +-diff --git a/lib/ffmpeg/libavcodec/dxva2_h264.c b/lib/ffmpeg/libavcodec/dxva2_h264.c +-index bc80e98..3ad8fcf 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_h264.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_h264.c +-@@ -150,10 +150,19 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context +- //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */ +- } +- +--static void fill_scaling_lists(const H264Context *h, DXVA_Qmatrix_H264 *qm) +-+static void fill_scaling_lists(AVCodecContext *avctx, const H264Context *h, DXVA_Qmatrix_H264 *qm) +- { +- unsigned i, j; +- memset(qm, 0, sizeof(*qm)); +-+ if (avctx->workaround_bugs & FF_BUG_DXVA2_SCALING_LIST_ZIGZAG) { // For old UVD/UVD+ ATI cards +-+ for (i = 0; i < 6; i++) +-+ for (j = 0; j < 16; j++) +-+ qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j]; +-+ +-+ for (i = 0; i < 2; i++) +-+ for (j = 0; j < 64; j++) +-+ qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][j]; +-+ } else { +- for (i = 0; i < 6; i++) +- for (j = 0; j < 16; j++) +- qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][zigzag_scan[j]]; +-@@ -161,6 +170,7 @@ static void fill_scaling_lists(const H264Context *h, DXVA_Qmatrix_H264 *qm) +- for (i = 0; i < 2; i++) +- for (j = 0; j < 64; j++) +- qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][ff_zigzag_direct[j]]; +-+ } +- } +- +- static int is_slice_short(struct dxva_context *ctx) +-@@ -370,7 +380,7 @@ static int start_frame(AVCodecContext *avctx, +- fill_picture_parameters(ctx, h, &ctx_pic->pp); +- +- /* Fill up DXVA_Qmatrix_H264 */ +-- fill_scaling_lists(h, &ctx_pic->qm); +-+ fill_scaling_lists(avctx, h, &ctx_pic->qm); +- +- ctx_pic->slice_count = 0; +- ctx_pic->bitstream_size = 0; +--- +-1.7.4.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0050-Patch-for-memory-leaks-in-DVB-subtitles-decoder.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0050-Patch-for-memory-leaks-in-DVB-subtitles-decoder.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0050-Patch-for-memory-leaks-in-DVB-subtitles-decoder.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0050-Patch-for-memory-leaks-in-DVB-subtitles-decoder.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From 078e7b14d4a44073dddebc6a0a544f648e69a9cb Mon Sep 17 00:00:00 2001 +-From: =?UTF-8?q?Jernej=20Fija=C4=8Dko?= +-Date: Mon, 11 Jul 2011 10:11:04 +0200 +-Subject: [PATCH] Patch for memory leaks in DVB subtitles decoder +- +-Signed-off-by: Joakim Plate +---- +- lib/ffmpeg/libavcodec/dvbsubdec.c | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dvbsubdec.c b/lib/ffmpeg/libavcodec/dvbsubdec.c +-index e68a0b3..7c37915 100644 +---- a/lib/ffmpeg/libavcodec/dvbsubdec.c +-+++ b/lib/ffmpeg/libavcodec/dvbsubdec.c +-@@ -1457,6 +1457,7 @@ static int dvbsub_decode(AVCodecContext *avctx, +- break; +- case DVBSUB_DISPLAYDEFINITION_SEGMENT: +- dvbsub_parse_display_definition_segment(avctx, p, segment_length); +-+ break; +- case DVBSUB_DISPLAY_SEGMENT: +- *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub); +- break; +--- +-1.7.4.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0051-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0051-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0051-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0051-dxva-mpeg2-Allocate-slices-array-dynamically-fixes-v.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,74 +0,0 @@ +-From 87abcf002b55c8a26b6640ee55a56d3b79dd4740 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Wed, 5 Oct 2011 12:38:30 -0400 +-Subject: [PATCH 1/6] dxva-mpeg2 Allocate slices array dynamically - fixes videos with > 175 slices. +- They used to result in images with a black bottom. +- +-sample on team ftp samples/PR471/too_many_slices.ts +- +-Inspired by the vaapi code to reallocate the slices array for each new slice. +-Could be more efficient if the array could be preserved for all frames and +-freed only at the end of the video, but there doesn't seem to be anywhere +-appropriate to free the memory at the end. +- +-Alternative is to allocate the proper size straight away for a new frame, +-instead of realloc'ing for each slice. +---- +- lib/ffmpeg/libavcodec/dxva2_mpeg2.c | 14 +++++++++++--- +- 1 files changed, 11 insertions(+), 3 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-index 780542a..9ac2d17 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-@@ -22,12 +22,12 @@ +- +- #include "dxva2_internal.h" +- +--#define MAX_SLICES (SLICE_MAX_START_CODE - SLICE_MIN_START_CODE + 1) +- struct dxva2_picture_context { +- DXVA_PictureParameters pp; +- DXVA_QmatrixData qm; +- unsigned slice_count; +-- DXVA_SliceInfo slice[MAX_SLICES]; +-+ DXVA_SliceInfo *slice; +-+ unsigned int slice_alloc; +- +- const uint8_t *bitstream; +- unsigned bitstream_size; +-@@ -220,6 +220,8 @@ static int start_frame(AVCodecContext *avctx, +- fill_quantization_matrices(avctx, ctx, s, &ctx_pic->qm); +- +- ctx_pic->slice_count = 0; +-+ ctx_pic->slice = NULL; +-+ ctx_pic->slice_alloc = 0; +- ctx_pic->bitstream_size = 0; +- ctx_pic->bitstream = NULL; +- return 0; +-@@ -232,9 +234,14 @@ static int decode_slice(AVCodecContext *avctx, +- struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; +- unsigned position; +-+ DXVA_SliceInfo* slice; +- +-- if (ctx_pic->slice_count >= MAX_SLICES) +-+ slice = av_fast_realloc(ctx_pic->slice, +-+ &ctx_pic->slice_alloc, +-+ (ctx_pic->slice_count + 1) * sizeof(DXVA_SliceInfo)); +-+ if (!slice) +- return -1; +-+ ctx_pic->slice = slice; +- +- if (!ctx_pic->bitstream) +- ctx_pic->bitstream = buffer; +-@@ -258,6 +265,7 @@ static int end_frame(AVCodecContext *avctx) +- &ctx_pic->pp, sizeof(ctx_pic->pp), +- &ctx_pic->qm, sizeof(ctx_pic->qm), +- commit_bitstream_and_slice_buffer); +-+ av_freep(ctx_pic->slice); +- } +- +- AVHWAccel ff_mpeg2_dxva2_hwaccel = { +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0052-dxva-mpeg2-speed-up-slice-allocation.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0052-dxva-mpeg2-speed-up-slice-allocation.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0052-dxva-mpeg2-speed-up-slice-allocation.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0052-dxva-mpeg2-speed-up-slice-allocation.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,74 +0,0 @@ +-From 191bc00c62691c4e365ae8b56ed36a9002295961 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Mon, 10 Oct 2011 19:42:50 -0400 +-Subject: [PATCH 2/6] dxva-mpeg2 speed up slice allocation +- +-The number of slices is not very likely to change from frame to frame, so +-at the beginning of a new frame, allocate memory for the amount of slices of +-the previous frame. Saves a lot of reallocation, for some TV capture samples +-there are over 200 slices. +- +-There wasn't anywhere really appropriate to store last_slice_count (needs to +-live from first frame to last frame), so this is likely to cause discussion to +-merge upstream. +-Adding members to dxva_context breaks ABI, which we don't care too much about +-since on Windows we don't support external ffmpeg. +-dxva mpeg2 code also has access to MpegEncContext, but adding there would +-likely break ABI as well. +---- +- lib/ffmpeg/libavcodec/dxva2.h | 1 + +- lib/ffmpeg/libavcodec/dxva2_mpeg2.c | 12 ++++++++++++ +- 2 files changed, 13 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2.h b/lib/ffmpeg/libavcodec/dxva2.h +-index 6eb494b..12dce47 100644 +---- a/lib/ffmpeg/libavcodec/dxva2.h +-+++ b/lib/ffmpeg/libavcodec/dxva2.h +-@@ -65,6 +65,7 @@ struct dxva_context { +- * Private to the FFmpeg AVHWAccel implementation +- */ +- unsigned report_id; +-+ unsigned last_slice_count; +- }; +- +- #endif /* AVCODEC_DXVA_H */ +-diff --git a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-index 9ac2d17..2482c2f 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_mpeg2.c +-@@ -224,6 +224,16 @@ static int start_frame(AVCodecContext *avctx, +- ctx_pic->slice_alloc = 0; +- ctx_pic->bitstream_size = 0; +- ctx_pic->bitstream = NULL; +-+ +-+ if (ctx->last_slice_count > 0) +-+ { +-+ ctx_pic->slice = av_fast_realloc(NULL, +-+ &ctx_pic->slice_alloc, +-+ ctx->last_slice_count * sizeof(DXVA_SliceInfo)); +-+ if (!ctx_pic->slice) +-+ return -1; +-+ } +-+ +- return 0; +- } +- +-@@ -258,6 +268,7 @@ static int end_frame(AVCodecContext *avctx) +- struct MpegEncContext *s = avctx->priv_data; +- struct dxva2_picture_context *ctx_pic = +- s->current_picture_ptr->hwaccel_picture_private; +-+ struct dxva_context *ctx = avctx->hwaccel_context; +- +- if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) +- return -1; +-@@ -266,6 +277,7 @@ static int end_frame(AVCodecContext *avctx) +- &ctx_pic->qm, sizeof(ctx_pic->qm), +- commit_bitstream_and_slice_buffer); +- av_freep(ctx_pic->slice); +-+ ctx->last_slice_count = ctx_pic->slice_count; +- } +- +- AVHWAccel ff_mpeg2_dxva2_hwaccel = { +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0053-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0053-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0053-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0053-dxva-vc1-Take-BI-into-account-for-forward-and-backwa.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,59 +0,0 @@ +-From 9afd569e13e9c0a823e11f4dd68ba9cb5e3ad3f1 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Wed, 5 Oct 2011 12:53:38 -0400 +-Subject: [PATCH 3/6] dxva-vc1 Take BI into account for forward and backward pictures +- +-See ticket #11643, sample on team ftp, samples/11643/vc-1 test.wmv +---- +- lib/ffmpeg/libavcodec/dxva2_vc1.c | 16 +++++++++------- +- 1 files changed, 9 insertions(+), 7 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2_vc1.c b/lib/ffmpeg/libavcodec/dxva2_vc1.c +-index 2b9a690..86cdf2f 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_vc1.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_vc1.c +-@@ -38,15 +38,17 @@ static void fill_picture_parameters(AVCodecContext *avctx, +- { +- const MpegEncContext *s = &v->s; +- const Picture *current_picture = s->current_picture_ptr; +-+ BYTE bPicIntra = s->pict_type == FF_I_TYPE || v->bi_type == 1; +-+ BYTE bPicBackwardPrediction = s->pict_type == FF_B_TYPE && v->bi_type == 0; +- +- memset(pp, 0, sizeof(*pp)); +- pp->wDecodedPictureIndex = +- pp->wDeblockedPictureIndex = ff_dxva2_get_surface_index(ctx, current_picture); +-- if (s->pict_type != FF_I_TYPE) +-- pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); +-- else +-+ if (bPicIntra) +- pp->wForwardRefPictureIndex = 0xffff; +-- if (s->pict_type == FF_B_TYPE) +-+ else +-+ pp->wForwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->last_picture); +-+ if (bPicBackwardPrediction) +- pp->wBackwardRefPictureIndex = ff_dxva2_get_surface_index(ctx, &s->next_picture); +- else +- pp->wBackwardRefPictureIndex = 0xffff; +-@@ -69,8 +71,8 @@ static void fill_picture_parameters(AVCodecContext *avctx, +- if (s->picture_structure & PICT_BOTTOM_FIELD) +- pp->bPicStructure |= 0x02; +- pp->bSecondField = v->interlace && v->fcm != 0x03 && !s->first_field; +-- pp->bPicIntra = s->pict_type == FF_I_TYPE; +-- pp->bPicBackwardPrediction = s->pict_type == FF_B_TYPE; +-+ pp->bPicIntra = bPicIntra; +-+ pp->bPicBackwardPrediction = bPicBackwardPrediction; +- pp->bBidirectionalAveragingMode = (1 << 7) | +- ((ctx->cfg->ConfigIntraResidUnsigned != 0) << 6) | +- ((ctx->cfg->ConfigResidDiffAccelerator != 0) << 5) | +-@@ -108,7 +110,7 @@ static void fill_picture_parameters(AVCodecContext *avctx, +- (v->interlace << 5) | +- (v->tfcntrflag << 4) | +- (v->finterpflag << 3) | +-- ((s->pict_type != FF_B_TYPE) << 2) | +-+ ((s->pict_type != FF_B_TYPE) << 2) | //includes BI +- (v->psf << 1) | +- (v->extended_dmv ); +- if (s->pict_type != FF_I_TYPE) +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0054-dxva-vc1-Pass-overlapping-transforms-hint.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0054-dxva-vc1-Pass-overlapping-transforms-hint.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0054-dxva-vc1-Pass-overlapping-transforms-hint.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0054-dxva-vc1-Pass-overlapping-transforms-hint.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,29 +0,0 @@ +-From 537d5999337500cac1c521f45de0a921b9aab5ac Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Thu, 6 Oct 2011 20:23:31 -0400 +-Subject: [PATCH 4/6] dxva-vc1 Pass overlapping transforms hint +- +-see ticket #11643 +---- +- lib/ffmpeg/libavcodec/dxva2_vc1.c | 5 ++++- +- 1 files changed, 4 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2_vc1.c b/lib/ffmpeg/libavcodec/dxva2_vc1.c +-index 86cdf2f..eca587a 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_vc1.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_vc1.c +-@@ -103,7 +103,10 @@ static void fill_picture_parameters(AVCodecContext *avctx, +- (v->rangered << 3) | +- (s->max_b_frames ); +- pp->bPicExtrapolation = (!v->interlace || v->fcm == 0x00) ? 1 : 2; +-- pp->bPicDeblocked = ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | +-+ pp->bPicDeblocked = ((v->overlap == 1 && +-+ pp->bPicBackwardPrediction == 0 && +-+ ctx->cfg->ConfigResidDiffHost == 0) << 6) | +-+ ((v->profile != PROFILE_ADVANCED && v->rangeredfrm) << 5) | +- (s->loop_filter << 1); +- pp->bPicDeblockConfined = (v->postprocflag << 7) | +- (v->broadcast << 6) | +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0055-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0055-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0055-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0055-dxva-h264-Fix-dxva-playback-of-streams-that-don-t-st.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,74 +0,0 @@ +-From 6328fc9c25a19f1cba3fae56eeff1eaf69ec6d50 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Wed, 5 Oct 2011 13:13:25 -0400 +-Subject: [PATCH 5/6] dxva-h264 Fix dxva playback of streams that don't start with an I-Frame. +- +-GPUs with ATI UVDa and UVD+ have trouble when decoding doesn't start on an +-I-Frame, and they don't recover on later I-Frames. +- +-The variable to track the first I-Frame is in H264Context so that it can be +-reset by code in h264 when initializing the context or flushing. +- +-credits isidrogar, see ticket #11772. +-sample on team ftp, samples/11772/CSI_ New York - TV3 - 2008-09-16_1.ts +---- +- lib/ffmpeg/libavcodec/dxva2_h264.c | 8 ++++++++ +- lib/ffmpeg/libavcodec/h264.c | 2 ++ +- lib/ffmpeg/libavcodec/h264.h | 2 ++ +- 3 files changed, 12 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2_h264.c b/lib/ffmpeg/libavcodec/dxva2_h264.c +-index 4e3370c..2954b89 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_h264.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_h264.c +-@@ -430,6 +430,14 @@ static int end_frame(AVCodecContext *avctx) +- +- if (ctx_pic->slice_count <= 0 || ctx_pic->bitstream_size <= 0) +- return -1; +-+ +-+ // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs +-+ if (!h->got_first_iframe) { +-+ if (!(ctx_pic->pp.wBitFields & (1 << 15))) +-+ return -1; +-+ h->got_first_iframe = 1; +-+ } +-+ +- return ff_dxva2_common_end_frame(avctx, s, +- &ctx_pic->pp, sizeof(ctx_pic->pp), +- &ctx_pic->qm, sizeof(ctx_pic->qm), +-diff --git a/lib/ffmpeg/libavcodec/h264.c b/lib/ffmpeg/libavcodec/h264.c +-index b84430a..a4d35ae 100644 +---- a/lib/ffmpeg/libavcodec/h264.c +-+++ b/lib/ffmpeg/libavcodec/h264.c +-@@ -1479,6 +1479,7 @@ static void flush_dpb(AVCodecContext *avctx){ +- h->delayed_pic[i]->reference= 0; +- h->delayed_pic[i]= NULL; +- } +-+ h->got_first_iframe = 0; +- h->outputed_poc= INT_MIN; +- h->prev_interlaced_frame = 1; +- idr(h); +-@@ -1848,6 +1849,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ +- return -1; +- s->first_field = 0; +- h->prev_interlaced_frame = 1; +-+ h->got_first_iframe = 0; +- +- init_scan_tables(h); +- ff_h264_alloc_tables(h); +-diff --git a/lib/ffmpeg/libavcodec/h264.h b/lib/ffmpeg/libavcodec/h264.h +-index b403968..bdca237 100644 +---- a/lib/ffmpeg/libavcodec/h264.h +-+++ b/lib/ffmpeg/libavcodec/h264.h +-@@ -587,6 +587,8 @@ typedef struct H264Context{ +- int luma_weight_flag[2]; ///< 7.4.3.2 luma_weight_lX_flag +- int chroma_weight_flag[2]; ///< 7.4.3.2 chroma_weight_lX_flag +- +-+ int got_first_iframe; +-+ +- // Timestamp stuff +- int sei_buffering_period_present; ///< Buffering period SEI flag +- int initial_cpb_removal_delay[32]; ///< Initial timestamps for CPBs +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0056-Changed-format-string-td-not-supported-by-our-MingW-.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0056-Changed-format-string-td-not-supported-by-our-MingW-.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0056-Changed-format-string-td-not-supported-by-our-MingW-.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0056-Changed-format-string-td-not-supported-by-our-MingW-.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From a584fbd0039270ae30ce08603ef6e819c61c908a Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Thu, 6 Oct 2011 13:25:28 -0400 +-Subject: [PATCH 6/6] Changed format string - %td not supported by our MingW environment. +- +---- +- lib/ffmpeg/libavcodec/h264.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/h264.c b/lib/ffmpeg/libavcodec/h264.c +-index a4d35ae..31d43df 100644 +---- a/lib/ffmpeg/libavcodec/h264.c +-+++ b/lib/ffmpeg/libavcodec/h264.c +-@@ -2568,7 +2568,7 @@ static int decode_slice(struct AVCodecContext *avctx, void *arg){ +- return 0; +- } +- if( ret < 0 || h->cabac.bytestream > h->cabac.bytestream_end + 2) { +-- av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%td)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); +-+ av_log(h->s.avctx, AV_LOG_ERROR, "error while decoding MB %d %d, bytestream (%u)\n", s->mb_x, s->mb_y, h->cabac.bytestream_end - h->cabac.bytestream); +- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, (AC_ERROR|DC_ERROR|MV_ERROR)&part_mask); +- return -1; +- } +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0057-Fixes-neon-usage-under-iOS5.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0057-Fixes-neon-usage-under-iOS5.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0057-Fixes-neon-usage-under-iOS5.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0057-Fixes-neon-usage-under-iOS5.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,307 +0,0 @@ +-diff --git a/lib/ffmpeg/libavcodec/arm/fft_neon.S b/lib/ffmpeg/libavcodec/arm/fft_neon.S +-index 1db7abd..6390065 100644 +---- a/lib/ffmpeg/libavcodec/arm/fft_neon.S +-+++ b/lib/ffmpeg/libavcodec/arm/fft_neon.S +-@@ -101,8 +101,12 @@ function fft8_neon +- bx lr +- endfunc +- +-+ .align 4 +-+pmmp: .float +1.0, -1.0, -1.0, +1.0 +-+mppm: .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +-+ +- function fft16_neon +-- movrel r1, mppm +-+ adr r1, mppm +- vld1.32 {d16-d19}, [r0,:128]! @ q8{r0,i0,r1,i1} q9{r2,i2,r3,i3} +- pld [r0, #32] +- vld1.32 {d2-d3}, [r1,:128] +-@@ -144,12 +148,16 @@ function fft16_neon +- vswp d29, d30 @ q14{r12,i12,i14,r15} q15{r13,i13,i15,r14} +- vadd.f32 q0, q12, q13 @ {t1,t2,t5,t6} +- vadd.f32 q1, q14, q15 @ {t1a,t2a,t5a,t6a} +-- movrel r2, X(ff_cos_16) +-+ ldr r2, _neon_label +-+ ldr r3, L$diff1 +-+ add r2, r3 +-+local_label1: +-+ ldr r2, [pc, r2] +- vsub.f32 q13, q12, q13 @ {t3,t4,t7,t8} +- vrev64.32 d1, d1 +- vsub.f32 q15, q14, q15 @ {t3a,t4a,t7a,t8a} +- vrev64.32 d3, d3 +-- movrel r3, pmmp +-+ adr r3, pmmp +- vswp d1, d26 @ q0{t1,t2,t3,t4} q13{t6,t5,t7,t8} +- vswp d3, d30 @ q1{t1a,t2a,t3a,t4a} q15{t6a,t5a,t7a,t8a} +- vadd.f32 q12, q0, q13 @ {r8,i8,r9,i9} +-@@ -214,7 +222,7 @@ function fft_pass_neon +- add r2, r2, r0 @ &z[o2] +- add r3, r3, r0 @ &z[o3] +- vld1.32 {d20-d21},[r2,:128] @ {z[o2],z[o2+1]} +-- movrel r12, pmmp +-+ adr r12, pmmp +- vld1.32 {d22-d23},[r3,:128] @ {z[o3],z[o3+1]} +- add r5, r5, r1 @ wim +- vld1.32 {d6-d7}, [r12,:128] @ pmmp +-@@ -279,6 +287,11 @@ function fft_pass_neon +- pop {r4-r6,pc} +- endfunc +- +-+.set L$offs16, 0 +-+.macro setTabOffs n, n2 +-+.set L$offs\n, L$offs\n2 + 4 +-+.endm +-+ +- .macro def_fft n, n2, n4 +- .align 6 +- function fft\n\()_neon +-@@ -291,10 +304,15 @@ function fft\n\()_neon +- bl fft\n4\()_neon +- mov r0, r4 +- pop {r4, lr} +-- movrel r1, X(ff_cos_\n) +-+ ldr r1, _neon_label +-+ add r1, #L$diff\n +-+local_label\n: +-+ ldr r1, [pc, r1] +- mov r2, #\n4/2 +- b fft_pass_neon +- endfunc +-+setTabOffs \n, \n2 +-+.set L$diff\n, _neon_label - local_label\n + L$offs\n - 8 +- .endm +- +- def_fft 32, 16, 8 +-@@ -310,10 +328,14 @@ endfunc +- def_fft 32768, 16384, 8192 +- def_fft 65536, 32768, 16384 +- +-+.set L$diffTab, fft_tab_neon_offs - local_label_tab - 8 +- function ff_fft_calc_neon, export=1 +- ldr r2, [r0] +- sub r2, r2, #2 +-- movrel r3, fft_tab_neon +-+ ldr r3, fft_tab_neon_offs +-+ add r3, #L$diffTab +-+local_label_tab: +-+ add r3, pc +- ldr r3, [r3, r2, lsl #2] +- mov r0, r1 +- bx r3 +-@@ -349,9 +371,22 @@ function ff_fft_permute_neon, export=1 +- pop {r4,pc} +- endfunc +- +-- .section .rodata +-+ +-+.global _neon_label +-+_neon_label: +-+.word _neon_cos_tab - . +-+ +-+L$diff1: +-+.word _neon_label - local_label1 - 8 +-+ +-+fft_tab_neon_offs: +-+.word _fft_tab_neon - . +-+ +-+ +-+.section .rodata +-+ +- .align 4 +--fft_tab_neon: +-+_fft_tab_neon: +- .word fft4_neon +- .word fft8_neon +- .word fft16_neon +-@@ -367,8 +402,20 @@ fft_tab_neon: +- .word fft16384_neon +- .word fft32768_neon +- .word fft65536_neon +--ELF .size fft_tab_neon, . - fft_tab_neon +-- +-- .align 4 +--pmmp: .float +1.0, -1.0, -1.0, +1.0 +--mppm: .float -M_SQRT1_2, M_SQRT1_2, M_SQRT1_2, -M_SQRT1_2 +-+ELF .size _fft_tab_neon, . - _fft_tab_neon +-+ +-+ .align 4 +-+_neon_cos_tab: +-+ .word X(ff_cos_16) +-+ .word X(ff_cos_32) +-+ .word X(ff_cos_64) +-+ .word X(ff_cos_128) +-+ .word X(ff_cos_256) +-+ .word X(ff_cos_512) +-+ .word X(ff_cos_1024) +-+ .word X(ff_cos_2048) +-+ .word X(ff_cos_4096) +-+ .word X(ff_cos_8192) +-+ .word X(ff_cos_16384) +-+ .word X(ff_cos_32768) +-+ .word X(ff_cos_65536) +-diff --git a/lib/ffmpeg/libavcodec/arm/h264idct_neon.S b/lib/ffmpeg/libavcodec/arm/h264idct_neon.S +-index 6b6a669..8111975 100644 +---- a/lib/ffmpeg/libavcodec/arm/h264idct_neon.S +-+++ b/lib/ffmpeg/libavcodec/arm/h264idct_neon.S +-@@ -97,7 +97,7 @@ function ff_h264_idct_add16_neon, export=1 +- mov r1, r2 +- mov r2, r3 +- ldr r6, [sp, #24] +-- movrel r7, scan8 +-+ adr r7, scan8 +- mov ip, #16 +- 1: ldrb r8, [r7], #1 +- ldr r0, [r5], #4 +-@@ -117,6 +117,16 @@ function ff_h264_idct_add16_neon, export=1 +- pop {r4-r8,pc} +- endfunc +- +-+ .align +-+scan8: .byte 4+1*8, 5+1*8, 4+2*8, 5+2*8 +-+ .byte 6+1*8, 7+1*8, 6+2*8, 7+2*8 +-+ .byte 4+3*8, 5+3*8, 4+4*8, 5+4*8 +-+ .byte 6+3*8, 7+3*8, 6+4*8, 7+4*8 +-+ .byte 1+1*8, 2+1*8 +-+ .byte 1+2*8, 2+2*8 +-+ .byte 1+4*8, 2+4*8 +-+ .byte 1+5*8, 2+5*8 +-+ +- function ff_h264_idct_add16intra_neon, export=1 +- push {r4-r8,lr} +- mov r4, r0 +-@@ -124,7 +134,7 @@ function ff_h264_idct_add16intra_neon, export=1 +- mov r1, r2 +- mov r2, r3 +- ldr r6, [sp, #24] +-- movrel r7, scan8 +-+ adr r7, scan8 +- mov ip, #16 +- 1: ldrb r8, [r7], #1 +- ldr r0, [r5], #4 +-@@ -149,7 +159,7 @@ function ff_h264_idct_add8_neon, export=1 +- add r1, r2, #16*32 +- mov r2, r3 +- ldr r6, [sp, #32] +-- movrel r7, scan8+16 +-+ adr r7, scan8+16 +- mov ip, #7 +- 1: ldrb r8, [r7], #1 +- ldr r0, [r5], #4 +-@@ -353,7 +363,7 @@ function ff_h264_idct8_add4_neon, export=1 +- mov r1, r2 +- mov r2, r3 +- ldr r6, [sp, #24] +-- movrel r7, scan8 +-+ adr r7, scan8 +- mov r12, #16 +- 1: ldrb r8, [r7], #4 +- ldr r0, [r5], #16 +-@@ -372,13 +382,3 @@ function ff_h264_idct8_add4_neon, export=1 +- bne 1b +- pop {r4-r8,pc} +- endfunc +-- +-- .section .rodata +--scan8: .byte 4+1*8, 5+1*8, 4+2*8, 5+2*8 +-- .byte 6+1*8, 7+1*8, 6+2*8, 7+2*8 +-- .byte 4+3*8, 5+3*8, 4+4*8, 5+4*8 +-- .byte 6+3*8, 7+3*8, 6+4*8, 7+4*8 +-- .byte 1+1*8, 2+1*8 +-- .byte 1+2*8, 2+2*8 +-- .byte 1+4*8, 2+4*8 +-- .byte 1+5*8, 2+5*8 +-diff --git a/lib/ffmpeg/libavcodec/arm/h264pred_neon.S b/lib/ffmpeg/libavcodec/arm/h264pred_neon.S +-index 63c96ee..357c10a 100644 +---- a/lib/ffmpeg/libavcodec/arm/h264pred_neon.S +-+++ b/lib/ffmpeg/libavcodec/arm/h264pred_neon.S +-@@ -123,7 +123,7 @@ function ff_pred16x16_plane_neon, export=1 +- vaddl.u8 q8, d2, d3 +- vsubl.u8 q2, d2, d0 +- vsubl.u8 q3, d3, d1 +-- movrel r3, p16weight +-+ adr r3, p16weight +- vld1.8 {q0}, [r3,:128] +- vmul.s16 q2, q2, q0 +- vmul.s16 q3, q3, q0 +-@@ -166,7 +166,6 @@ function ff_pred16x16_plane_neon, export=1 +- bx lr +- endfunc +- +-- .section .rodata +- .align 4 +- p16weight: +- .short 1,2,3,4,5,6,7,8 +-@@ -207,7 +206,7 @@ function ff_pred8x8_plane_neon, export=1 +- vrev32.8 d0, d0 +- vtrn.32 d2, d3 +- vsubl.u8 q2, d2, d0 +-- movrel r3, p16weight +-+ adr r3, p16weight +- vld1.16 {q0}, [r3,:128] +- vmul.s16 d4, d4, d0 +- vmul.s16 d5, d5, d0 +-diff --git a/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S b/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S +-index 17cde58..e61414e 100644 +---- a/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S +-+++ b/lib/ffmpeg/libavcodec/arm/simple_idct_neon.S +-@@ -239,7 +239,6 @@ function idct_col4_st8_neon +- bx lr +- endfunc +- +-- .section .rodata +- .align 4 +- idct_coeff_neon: +- .short W1, W2, W3, W4, W5, W6, W7, W4c +-@@ -249,7 +248,7 @@ idct_coeff_neon: +- pld [\data] +- pld [\data, #64] +- vpush {d8-d15} +-- movrel r3, idct_coeff_neon +-+ adr r3, idct_coeff_neon +- vld1.64 {d0,d1}, [r3,:128] +- .endm +- +-diff --git a/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S b/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S +-index d97ed3d..74bf7ba 100644 +---- a/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S +-+++ b/lib/ffmpeg/libavcodec/arm/vp3dsp_neon.S +-@@ -20,12 +20,9 @@ +- +- #include "asm.S" +- +--.section .rodata +-+.text +- .align 4 +- +--vp3_idct_constants: +--.short 64277, 60547, 54491, 46341, 36410, 25080, 12785 +-- +- #define xC1S7 d0[0] +- #define xC2S6 d0[1] +- #define xC3S5 d0[2] +-@@ -34,8 +31,6 @@ vp3_idct_constants: +- #define xC6S2 d1[1] +- #define xC7S1 d1[2] +- +--.text +-- +- .macro vp3_loop_filter +- vsubl.u8 q3, d18, d17 +- vsubl.u8 q2, d16, d19 +-@@ -109,10 +104,14 @@ function ff_vp3_h_loop_filter_neon, export=1 +- bx lr +- endfunc +- +-+.align 4 +-+vp3_idct_constants: +-+.short 64277, 60547, 54491, 46341, 36410, 25080, 12785 +-+.align 4 +- +- function vp3_idct_start_neon +- vpush {d8-d15} +-- movrel r3, vp3_idct_constants +-+ adr r3, vp3_idct_constants +- vld1.64 {d0-d1}, [r3,:128] +- vld1.64 {d16-d19}, [r2,:128]! +- vld1.64 {d20-d23}, [r2,:128]! +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0058-fixed-seeks-in-mmsh.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0058-fixed-seeks-in-mmsh.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0058-fixed-seeks-in-mmsh.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0058-fixed-seeks-in-mmsh.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,124 +0,0 @@ +-From 4e8274d070a598e60a953c6aed2dd9f4710cd2b4 Mon Sep 17 00:00:00 2001 +-From: spiff +-Date: Tue, 1 Nov 2011 13:14:09 +0100 +-Subject: [PATCH] fixed: seeks in mmsh +- +-this backports upstream commits aedb87c57, 86a4e55e6, 8475ec190, +-60fcc19bff (partially), 237bcaa27518, 33789862, 8af4ac5272, 26b64550d6 +- +-thanks a million to michael niedermayer for giving this priority! +---- +- lib/ffmpeg/libavformat/mmsh.c | 53 ++++++++++++++++++++++++++++++++++++---- +- 1 files changed, 47 insertions(+), 6 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/mmsh.c b/lib/ffmpeg/libavformat/mmsh.c +-index 257b973..3ae886f 100644 +---- a/lib/ffmpeg/libavformat/mmsh.c +-+++ b/lib/ffmpeg/libavformat/mmsh.c +-@@ -54,6 +54,7 @@ typedef enum { +- +- typedef struct { +- MMSContext mms; +-+ uint8_t location[1024]; +- int request_seq; ///< request packet sequence +- int chunk_seq; ///< data packet sequence +- } MMSHContext; +-@@ -210,10 +211,10 @@ static int get_http_header_data(MMSHContext *mmsh) +- return 0; +- } +- +--static int mmsh_open(URLContext *h, const char *uri, int flags) +-+static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int timestamp, int64_t pos) +- { +- int i, port, err; +-- char httpname[256], path[256], host[128], location[1024]; +-+ char httpname[256], path[256], host[128]; +- char *stream_selection = NULL; +- char headers[1024]; +- MMSHContext *mmsh; +-@@ -224,10 +225,10 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) +- return AVERROR(ENOMEM); +- mmsh->request_seq = h->is_streamed = 1; +- mms = &mmsh->mms; +-- av_strlcpy(location, uri, sizeof(location)); +-+ av_strlcpy(mmsh->location, uri, sizeof(mmsh->location)); +- +- av_url_split(NULL, 0, NULL, 0, +-- host, sizeof(host), &port, path, sizeof(path), location); +-+ host, sizeof(host), &port, path, sizeof(path), mmsh->location); +- if (port<0) +- port = 80; // default mmsh protocol port +- ff_url_join(httpname, sizeof(httpname), "http", NULL, host, port, path); +-@@ -283,8 +284,9 @@ static int mmsh_open(URLContext *h, const char *uri, int flags) +- CLIENTGUID +- "Pragma: stream-switch-count=%d\r\n" +- "Pragma: stream-switch-entry=%s\r\n" +-+ "Pragma: no-cache,rate)1.000000,stream-time=%u" +- "Connection: Close\r\n\r\n", +-- host, port, mmsh->request_seq++, mms->stream_num, stream_selection); +-+ host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp); +- av_freep(&stream_selection); +- if (err < 0) { +- av_log(NULL, AV_LOG_ERROR, "Build play request failed!\n"); +-@@ -313,6 +315,11 @@ fail: +- return err; +- } +- +-+static int mmsh_open(URLContext *h, const char *uri, int flags) +-+{ +-+ return mmsh_open_internal(h, uri, flags, 0, 0); +-+} +-+ +- static int handle_chunk_type(MMSHContext *mmsh) +- { +- MMSContext *mms = &mmsh->mms; +-@@ -359,11 +366,45 @@ static int mmsh_read(URLContext *h, uint8_t *buf, int size) +- return res; +- } +- +-+static int64_t mmsh_read_seek(URLContext *h, int stream_index, +-+ int64_t timestamp, int flags) +-+{ +-+ MMSHContext *mmsh = h->priv_data; +-+ MMSContext *mms = &mmsh->mms; +-+ int ret; +-+ +-+ ret= mmsh_open_internal(h, mmsh->location, 0, FFMAX(timestamp, 0), 0); +-+ +-+ if(ret>=0){ +-+ if (mms->mms_hd) +-+ url_close(mms->mms_hd); +-+ av_freep(&mms->streams); +-+ av_freep(&mms->asf_header); +-+ av_free(mmsh); +-+ mmsh = h->priv_data; +-+ mms = &mmsh->mms; +-+ mms->asf_header_read_size= mms->asf_header_size; +-+ }else +-+ h->priv_data= mmsh; +-+ return ret; +-+} +-+ +-+static int64_t mmsh_seek(URLContext *h, int64_t pos, int whence) +-+{ +-+ MMSHContext *mmsh = h->priv_data; +-+ MMSContext *mms = &mmsh->mms; +-+ +-+ if(pos == 0 && whence == SEEK_CUR) +-+ return mms->asf_header_read_size + mms->remaining_in_len + mmsh->chunk_seq * mms->asf_packet_len; +-+ return AVERROR(ENOSYS); +-+} +-+ +- URLProtocol ff_mmsh_protocol = { +- .name = "mmsh", +- .url_open = mmsh_open, +- .url_read = mmsh_read, +- .url_write = NULL, +-- .url_seek = NULL, +-+ .url_seek = mmsh_seek, +- .url_close = mmsh_close, +-+ .url_read_seek = mmsh_read_seek, +- }; +--- +-1.7.5 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0059-fix-h264-decode-size.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0059-fix-h264-decode-size.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0059-fix-h264-decode-size.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0059-fix-h264-decode-size.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,43 +0,0 @@ +-backport of upstream commits 23acfcd9 and 29a29226 +- +-Slightly modified because of differences between upstream code and ours. +- +---- +- +-diff --git a/lib/ffmpeg/libavcodec/h264.c b/lib/ffmpeg/libavcodec/h264.c +-index 31d43df..47b0073 100644 +---- a/lib/ffmpeg/libavcodec/h264.c +-+++ b/lib/ffmpeg/libavcodec/h264.c +-@@ -1797,15 +1797,11 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ +- s->mb_height= h->sps.mb_height * (2 - h->sps.frame_mbs_only_flag); +- +- h->b_stride= s->mb_width*4; +-- +-- s->width = 16*s->mb_width - 2*FFMIN(h->sps.crop_right, 7); +-- if(h->sps.frame_mbs_only_flag) +-- s->height= 16*s->mb_height - 2*FFMIN(h->sps.crop_bottom, 7); +-- else +-- s->height= 16*s->mb_height - 4*FFMIN(h->sps.crop_bottom, 7); +-+ s->width = 16*s->mb_width; +-+ s->height= 16*s->mb_height; +- +- if (s->context_initialized +-- && ( s->width != s->avctx->width || s->height != s->avctx->height +-+ && ( s->width != s->avctx->coded_width || s->height != s->avctx->coded_height +- || av_cmp_q(h->sps.sar, s->avctx->sample_aspect_ratio))) { +- if(h != h0) +- return -1; // width / height changed during parallelized decoding +-@@ -1818,6 +1814,13 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ +- return -1; // we cant (re-)initialize context during parallel decoding +- +- avcodec_set_dimensions(s->avctx, s->width, s->height); +-+ +-+ s->avctx->width -= 2*FFMIN(h->sps.crop_right, 7); +-+ if(h->sps.frame_mbs_only_flag) +-+ s->avctx->height-=2*FFMIN(h->sps.crop_bottom, 7); +-+ else +-+ s->avctx->height-=4*FFMIN(h->sps.crop_bottom, 7); +-+ +- s->avctx->sample_aspect_ratio= h->sps.sar; +- av_assert0(s->avctx->sample_aspect_ratio.den); +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0060-DXVA-Handle-return-value-of-BeginFrame-better.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0060-DXVA-Handle-return-value-of-BeginFrame-better.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0060-DXVA-Handle-return-value-of-BeginFrame-better.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0060-DXVA-Handle-return-value-of-BeginFrame-better.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,51 +0,0 @@ +-From dd2e3a9656477f19891ae37846018da0d72c3574 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Fri, 11 Nov 2011 19:10:54 -0500 +-Subject: [PATCH] [DXVA] Handle return value of BeginFrame better. +- +-The nVidia cards sometimes return E_PENDING and need time before they can start +-decoding a new frame. +- +-Helps nVidia cards with blocky pictures/pixellation artifacts after skip or +-when CPU is busy. +---- +- lib/ffmpeg/libavcodec/dxva2.c | 14 ++++++++++++-- +- 1 files changed, 12 insertions(+), 2 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dxva2.c b/lib/ffmpeg/libavcodec/dxva2.c +-index 3f14311..0cf99c3 100644 +---- a/lib/ffmpeg/libavcodec/dxva2.c +-+++ b/lib/ffmpeg/libavcodec/dxva2.c +-@@ -21,6 +21,9 @@ +- */ +- +- #include "dxva2_internal.h" +-+#include +-+ +-+#define MAX_RETRY_ON_PENDING 50 +- +- void *ff_dxva2_get_surface(const Picture *picture) +- { +-@@ -88,10 +91,17 @@ int ff_dxva2_common_end_frame(AVCodecContext *avctx, MpegEncContext *s, +- DXVA2_DecodeBufferDesc buffer[4]; +- DXVA2_DecodeExecuteParams exec; +- int result; +-+ HRESULT hr; +-+ int tries = 0; +- +-- if (FAILED(IDirectXVideoDecoder_BeginFrame(ctx->decoder, +-+ while ((hr=IDirectXVideoDecoder_BeginFrame(ctx->decoder, +- ff_dxva2_get_surface(s->current_picture_ptr), +-- NULL))) { +-+ NULL)) == E_PENDING +-+ && tries < MAX_RETRY_ON_PENDING) { +-+ usleep(1000); +-+ tries++; +-+ } +-+ if (FAILED(hr)) { +- av_log(avctx, AV_LOG_ERROR, "Failed to begin frame\n"); +- return -1; +- } +--- +-1.7.3.1.msysgit.0 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0061-fix-vc1-vaapi-intel-sandy-bridge.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0061-fix-vc1-vaapi-intel-sandy-bridge.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0061-fix-vc1-vaapi-intel-sandy-bridge.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0061-fix-vc1-vaapi-intel-sandy-bridge.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,48 +0,0 @@ +-This patch backports 53efb758c045900f512c947074900c0dbc988685 and a18e7b4fb77d3799cf21110b5e6dda4691a295b3 +- +-Written by Gwenole Beauchesne +-and fixes vc1 decoding with vaapi on Intel Sandy Bridge GPUs. +- +- +-diff --git a/lib/ffmpeg/libavcodec/vaapi_vc1.c b/lib/ffmpeg/libavcodec/vaapi_vc1.c +-index c61a5bd..a9bcd7b 100644 +---- a/lib/ffmpeg/libavcodec/vaapi_vc1.c +-+++ b/lib/ffmpeg/libavcodec/vaapi_vc1.c +-@@ -116,6 +116,18 @@ static inline VAMvModeVC1 vc1_get_MVMODE2(VC1Context *v) +- return 0; +- } +- +-+/** Reconstruct bitstream TTFRM (7.1.1.41, Table-53) */ +-+static inline int vc1_get_TTFRM(VC1Context *v) +-+{ +-+ switch (v->ttfrm) { +-+ case TT_8X8: return 0; +-+ case TT_8X4: return 1; +-+ case TT_4X8: return 2; +-+ case TT_4X4: return 3; +-+ } +-+ return 0; +-+} +-+ +- /** Pack FFmpeg bitplanes into a VABitPlaneBuffer element */ +- static inline void vc1_pack_bitplanes(uint8_t *bitplane, int n, const uint8_t *ff_bp[3], int x, int y, int stride) +- { +-@@ -160,6 +172,9 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t +- pic_param->sequence_fields.bits.syncmarker = s->resync_marker; +- pic_param->sequence_fields.bits.rangered = v->rangered; +- pic_param->sequence_fields.bits.max_b_frames = s->avctx->max_b_frames; +-+#if VA_CHECK_VERSION(0,32,0) +-+ pic_param->sequence_fields.bits.profile = v->profile; +-+#endif +- pic_param->coded_width = s->avctx->coded_width; +- pic_param->coded_height = s->avctx->coded_height; +- pic_param->entrypoint_fields.value = 0; /* reset all bits */ +-@@ -236,7 +251,7 @@ static int vaapi_vc1_start_frame(AVCodecContext *avctx, av_unused const uint8_t +- pic_param->transform_fields.value = 0; /* reset all bits */ +- pic_param->transform_fields.bits.variable_sized_transform_flag = v->vstransform; +- pic_param->transform_fields.bits.mb_level_transform_type_flag = v->ttmbf; +-- pic_param->transform_fields.bits.frame_level_transform_type = v->ttfrm; +-+ pic_param->transform_fields.bits.frame_level_transform_type = vc1_get_TTFRM(v); +- pic_param->transform_fields.bits.transform_ac_codingset_idx1 = v->c_ac_table_index; +- pic_param->transform_fields.bits.transform_ac_codingset_idx2 = v->y_ac_table_index; +- pic_param->transform_fields.bits.intra_transform_dc_table = v->s.dc_table_index; +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0062-fixed-crash-in-ffmpeg-matroskadec-with-some-files-fi.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0062-fixed-crash-in-ffmpeg-matroskadec-with-some-files-fi.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0062-fixed-crash-in-ffmpeg-matroskadec-with-some-files-fi.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0062-fixed-crash-in-ffmpeg-matroskadec-with-some-files-fi.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,50 +0,0 @@ +-From e138f82d2b066a47262ce0f06df106665761ac43 Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Wed, 7 Mar 2012 15:08:41 +0200 +-Subject: [PATCH] fixed: crash in ffmpeg matroskadec with some files (fixes +- #12741) +- +-Backport 2851b1f6566580485dceb67cbb6b93f64ee9a9bd from upstream FFmpeg, +-it fixes a rare matroskadec crash: +- +-matroskadec: check that pointers were initialized before accessing them +- +-fix ticket #14 +- +-Signed-off-by: Aurelien Jacobs +---- +- lib/ffmpeg/libavformat/matroskadec.c | 8 +++++--- +- 1 files changed, 5 insertions(+), 3 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/matroskadec.c b/lib/ffmpeg/libavformat/matroskadec.c +-index 14b96d4..70489e8 100644 +---- a/lib/ffmpeg/libavformat/matroskadec.c +-+++ b/lib/ffmpeg/libavformat/matroskadec.c +-@@ -1066,19 +1066,21 @@ static void matroska_convert_tags(AVFormatContext *s) +- if (tags[i].target.attachuid) { +- MatroskaAttachement *attachment = matroska->attachments.elem; +- for (j=0; jattachments.nb_elem; j++) +-- if (attachment[j].uid == tags[i].target.attachuid) +-+ if (attachment[j].uid == tags[i].target.attachuid +-+ && attachment[j].stream) +- matroska_convert_tag(s, &tags[i].tag, +- &attachment[j].stream->metadata, NULL); +- } else if (tags[i].target.chapteruid) { +- MatroskaChapter *chapter = matroska->chapters.elem; +- for (j=0; jchapters.nb_elem; j++) +-- if (chapter[j].uid == tags[i].target.chapteruid) +-+ if (chapter[j].uid == tags[i].target.chapteruid +-+ && chapter[j].chapter) +- matroska_convert_tag(s, &tags[i].tag, +- &chapter[j].chapter->metadata, NULL); +- } else if (tags[i].target.trackuid) { +- MatroskaTrack *track = matroska->tracks.elem; +- for (j=0; jtracks.nb_elem; j++) +-- if (track[j].uid == tags[i].target.trackuid) +-+ if (track[j].uid == tags[i].target.trackuid && track[j].stream) +- matroska_convert_tag(s, &tags[i].tag, +- &track[j].stream->metadata, NULL); +- } else { +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0063-fixed-playing-mpegts-over-rtsp-caused-ffmpeg-to-read.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0063-fixed-playing-mpegts-over-rtsp-caused-ffmpeg-to-read.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0063-fixed-playing-mpegts-over-rtsp-caused-ffmpeg-to-read.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0063-fixed-playing-mpegts-over-rtsp-caused-ffmpeg-to-read.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,29 +0,0 @@ +-From 8ec66e240fe0a9f672d7ff1932022f22f8332ffb Mon Sep 17 00:00:00 2001 +-From: Joakim Plate +-Date: Mon, 7 Mar 2011 22:53:30 +0100 +-Subject: [PATCH] fixed: playing mpegts over rtsp caused ffmpeg to read +- uninitialized stack values +- +-This is an amendment to cdfab91b9c4b7ed2560071f5630567db174d6084 the memleak +-fix for mpegts. It's questionable if that change is needed. Since +-the main issue it was for has been fixed correctly. However it +-doesn't hurt to avoid potential memleaks this way. +---- +- lib/ffmpeg/libavformat/mpegts.c | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/mpegts.c b/lib/ffmpeg/libavformat/mpegts.c +-index 9c25e37..2dbd07e 100644 +---- a/lib/ffmpeg/libavformat/mpegts.c +-+++ b/lib/ffmpeg/libavformat/mpegts.c +-@@ -1879,6 +1879,7 @@ int ff_mpegts_parse_packet(MpegTSContext *ts, AVPacket *pkt, +- +- len1 = len; +- ts->pkt = pkt; +-+ ts->pkt->data = NULL; +- ts->stop_parse = 0; +- for(;;) { +- if (ts->stop_parse>0) +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0064-ffmpeg-add-missing-check-for-NULL-pointer.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0064-ffmpeg-add-missing-check-for-NULL-pointer.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0064-ffmpeg-add-missing-check-for-NULL-pointer.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0064-ffmpeg-add-missing-check-for-NULL-pointer.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,28 +0,0 @@ +-From 54fd0c0596e8bd47adb9ac325ddb93d99647fe83 Mon Sep 17 00:00:00 2001 +-From: Marcel Groothuis +-Date: Sat, 12 Mar 2011 23:02:06 +0100 +-Subject: [PATCH] ffmpeg: add missing check for NULL pointer Extends commit +- 8ec66e240fe0a9f672d7ff1932022f22f8332ffb (fixed: playing +- mpegts over rtsp caused ffmpeg to read uninitialized stack +- values) +- +---- +- lib/ffmpeg/libavformat/utils.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/utils.c b/lib/ffmpeg/libavformat/utils.c +-index bee0475..d3c11e2 100644 +---- a/lib/ffmpeg/libavformat/utils.c +-+++ b/lib/ffmpeg/libavformat/utils.c +-@@ -1092,7 +1092,7 @@ static int av_read_frame_internal(AVFormatContext *s, AVPacket *pkt) +- av_add_index_entry(st, pkt->pos, pkt->dts, 0, 0, AVINDEX_KEYFRAME); +- } +- break; +-- } else if (st->cur_len > 0 && st->discard < AVDISCARD_ALL) { +-+ } else if (st->cur_len > 0 && st->cur_ptr && st->discard < AVDISCARD_ALL) { +- len = av_parser_parse2(st->parser, st->codec, &pkt->data, &pkt->size, +- st->cur_ptr, st->cur_len, +- st->cur_pkt.pts, st->cur_pkt.dts, +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0065-changed-allow-yadif-deinterlacer-to-enable-and-disab.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0065-changed-allow-yadif-deinterlacer-to-enable-and-disab.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0065-changed-allow-yadif-deinterlacer-to-enable-and-disab.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0065-changed-allow-yadif-deinterlacer-to-enable-and-disab.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,106 +0,0 @@ +-From c174f74181bcfa169aa8284f9524cd9db0f4cdda Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Fri, 24 Jun 2011 01:23:48 +0200 +-Subject: [PATCH] changed: allow yadif deinterlacer to enable and disable +- based on input interlaced flag +- +---- +- lib/ffmpeg/libavfilter/vf_yadif.c | 34 ++++++++++++++++++-- +- .../DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp | 4 ++ +- 2 files changed, 35 insertions(+), 3 deletions(-) +- +-diff --git a/lib/ffmpeg/libavfilter/vf_yadif.c b/lib/ffmpeg/libavfilter/vf_yadif.c +-index bd0a9de..28b1d3e 100644 +---- a/lib/ffmpeg/libavfilter/vf_yadif.c +-+++ b/lib/ffmpeg/libavfilter/vf_yadif.c +-@@ -43,6 +43,13 @@ typedef struct { +- int parity; +- +- int frame_pending; +-+ int skip; +-+ +-+ /** +-+ * 0: deinterlace all frames +-+ * 1: only deinterlace frames marked as interlaced +-+ */ +-+ int auto_enable; +- +- AVFilterBufferRef *cur; +- AVFilterBufferRef *next; +-@@ -212,10 +219,21 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) +- yadif->prev = yadif->cur; +- yadif->cur = yadif->next; +- yadif->next = picref; +-+ yadif->skip = 0; +- +- if (!yadif->cur) +- return; +- +-+ if (yadif->auto_enable && !yadif->cur->video->interlaced) { +-+ yadif->out = yadif->cur; +-+ avfilter_unref_buffer(yadif->prev); +-+ yadif->cur = NULL; +-+ yadif->prev = NULL; +-+ yadif->skip = 1; +-+ avfilter_start_frame(ctx->outputs[0], yadif->out); +-+ return; +-+ } +-+ +- if (!yadif->prev) +- yadif->prev = avfilter_ref_buffer(yadif->cur, AV_PERM_READ); +- +-@@ -232,6 +250,12 @@ static void end_frame(AVFilterLink *link) +- AVFilterContext *ctx = link->dst; +- YADIFContext *yadif = ctx->priv; +- +-+ if (yadif->skip) { +-+ avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1); +-+ avfilter_end_frame(ctx->outputs[0]); +-+ return; +-+ } +-+ +- if (!yadif->out) +- return; +- +-@@ -253,7 +277,7 @@ static int request_frame(AVFilterLink *link) +- +- if ((ret = avfilter_request_frame(link->src->inputs[0]))) +- return ret; +-- } while (!yadif->cur); +-+ } while (!yadif->out); +- +- return 0; +- } +-@@ -275,6 +299,9 @@ static int poll_frame(AVFilterLink *link) +- } +- assert(yadif->next); +- +-+ if (yadif->skip) +-+ return val; +-+ +- return val * ((yadif->mode&1)+1); +- } +- +-@@ -307,8 +334,9 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +- +- yadif->mode = 0; +- yadif->parity = -1; +-+ yadif->auto_enable = 0; +- +-- if (args) sscanf(args, "%d:%d", &yadif->mode, &yadif->parity); +-+ if (args) sscanf(args, "%d:%d:%d", &yadif->mode, &yadif->parity, &yadif->auto_enable); +- +- yadif->filter_line = filter_line_c; +- if (HAVE_SSSE3 && cpu_flags & AV_CPU_FLAG_SSSE3) +-@@ -318,7 +346,7 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque) +- else if (HAVE_MMX && cpu_flags & AV_CPU_FLAG_MMX) +- yadif->filter_line = ff_yadif_filter_line_mmx; +- +-- av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d\n", yadif->mode, yadif->parity); +-+ av_log(ctx, AV_LOG_INFO, "mode:%d parity:%d auto_enable:%d\n", yadif->mode, yadif->parity, yadif->auto_enable); +- +- return 0; +- } +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0066-changed-updated-yadif-patch-to-same-as-will-be-appli.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0066-changed-updated-yadif-patch-to-same-as-will-be-appli.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0066-changed-updated-yadif-patch-to-same-as-will-be-appli.patch 2012-03-27 17:55:47.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0066-changed-updated-yadif-patch-to-same-as-will-be-appli.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,82 +0,0 @@ +-From 91efb0af6f80d82b104a810a1ccdc0ae6702d022 Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Sun, 3 Jul 2011 17:06:42 +0200 +-Subject: [PATCH] changed: updated yadif patch to same as will be applied +- upstream +- +---- +- lib/ffmpeg/libavfilter/vf_yadif.c | 18 +++++++----------- +- 1 files changed, 7 insertions(+), 11 deletions(-) +- +-diff --git a/lib/ffmpeg/libavfilter/vf_yadif.c b/lib/ffmpeg/libavfilter/vf_yadif.c +-index 28b1d3e..d7bed90 100644 +---- a/lib/ffmpeg/libavfilter/vf_yadif.c +-+++ b/lib/ffmpeg/libavfilter/vf_yadif.c +-@@ -43,7 +43,6 @@ typedef struct { +- int parity; +- +- int frame_pending; +-- int skip; +- +- /** +- * 0: deinterlace all frames +-@@ -219,17 +218,14 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *picref) +- yadif->prev = yadif->cur; +- yadif->cur = yadif->next; +- yadif->next = picref; +-- yadif->skip = 0; +- +- if (!yadif->cur) +- return; +- +- if (yadif->auto_enable && !yadif->cur->video->interlaced) { +-- yadif->out = yadif->cur; +-+ yadif->out = avfilter_ref_buffer(yadif->cur, AV_PERM_READ); +- avfilter_unref_buffer(yadif->prev); +-- yadif->cur = NULL; +- yadif->prev = NULL; +-- yadif->skip = 1; +- avfilter_start_frame(ctx->outputs[0], yadif->out); +- return; +- } +-@@ -250,15 +246,15 @@ static void end_frame(AVFilterLink *link) +- AVFilterContext *ctx = link->dst; +- YADIFContext *yadif = ctx->priv; +- +-- if (yadif->skip) { +-+ if (!yadif->out) +-+ return; +-+ +-+ if (yadif->auto_enable && !yadif->cur->video->interlaced) { +- avfilter_draw_slice(ctx->outputs[0], 0, link->h, 1); +- avfilter_end_frame(ctx->outputs[0]); +- return; +- } +- +-- if (!yadif->out) +-- return; +-- +- return_frame(ctx, 0); +- } +- +-@@ -277,7 +273,7 @@ static int request_frame(AVFilterLink *link) +- +- if ((ret = avfilter_request_frame(link->src->inputs[0]))) +- return ret; +-- } while (!yadif->out); +-+ } while (!yadif->cur); +- +- return 0; +- } +-@@ -299,7 +295,7 @@ static int poll_frame(AVFilterLink *link) +- } +- assert(yadif->next); +- +-- if (yadif->skip) +-+ if (yadif->auto_enable && yadif->next && !yadif->next->video->interlaced) +- return val; +- +- return val * ((yadif->mode&1)+1); +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0067-changed-updated-dxva-zigzag-workaround-for-ATI-based.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0067-changed-updated-dxva-zigzag-workaround-for-ATI-based.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0067-changed-updated-dxva-zigzag-workaround-for-ATI-based.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0067-changed-updated-dxva-zigzag-workaround-for-ATI-based.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,92 +0,0 @@ +-From 321c5e668f2c213a33cef6c7c9fe11ee2850665f Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Tue, 5 Jul 2011 00:14:52 +0200 +-Subject: [PATCH] changed: updated dxva zigzag workaround for ATI based on +- comments on xbmc.org and ffmpeg.org +- +---- +- lib/ffmpeg/libavcodec/avcodec.h | 1 - +- lib/ffmpeg/libavcodec/dxva2.h | 2 ++ +- lib/ffmpeg/libavcodec/dxva2_h264.c | 23 +++++++++++++---------- +- xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.cpp | 14 +++----------- +- 4 files changed, 18 insertions(+), 22 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/avcodec.h b/lib/ffmpeg/libavcodec/avcodec.h +-index cb96c6f..4745980 100644 +---- a/lib/ffmpeg/libavcodec/avcodec.h +-+++ b/lib/ffmpeg/libavcodec/avcodec.h +-@@ -1429,7 +1429,6 @@ typedef struct AVCodecContext { +- #define FF_BUG_DC_CLIP 4096 +- #define FF_BUG_MS 8192 ///< Work around various bugs in Microsoft's broken decoders. +- #define FF_BUG_TRUNCATED 16384 +--#define FF_BUG_DXVA2_SCALING_LIST_ZIGZAG 32768 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards +- //#define FF_BUG_FAKE_SCALABILITY 16 //Autodetection should work 100%. +- +- /** +-diff --git a/lib/ffmpeg/libavcodec/dxva2.h b/lib/ffmpeg/libavcodec/dxva2.h +-index 5c5fe21..6eb494b 100644 +---- a/lib/ffmpeg/libavcodec/dxva2.h +-+++ b/lib/ffmpeg/libavcodec/dxva2.h +-@@ -27,6 +27,8 @@ +- +- #include +- +-+#define FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG 1 ///< Work around for DXVA2 and old UVD/UVD+ ATI video cards +-+ +- /** +- * This structure is used to provides the necessary configurations and data +- * to the DXVA2 FFmpeg HWAccel implementation. +-diff --git a/lib/ffmpeg/libavcodec/dxva2_h264.c b/lib/ffmpeg/libavcodec/dxva2_h264.c +-index 7b81c8e..4e3370c 100644 +---- a/lib/ffmpeg/libavcodec/dxva2_h264.c +-+++ b/lib/ffmpeg/libavcodec/dxva2_h264.c +-@@ -113,6 +113,9 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context +- +- pp->bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; +- pp->bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; +-+ if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) +-+ pp->Reserved16Bits = 0; +-+ else +- pp->Reserved16Bits = 3; /* FIXME is there a way to detect the right mode ? */ +- pp->StatusReportFeedbackNumber = 1 + ctx->report_id++; +- pp->CurrFieldOrderCnt[0] = 0; +-@@ -150,18 +153,18 @@ static void fill_picture_parameters(struct dxva_context *ctx, const H264Context +- //pp->SliceGroupMap[810]; /* XXX not implemented by FFmpeg */ +- } +- +--static void fill_scaling_lists(AVCodecContext *avctx, const H264Context *h, DXVA_Qmatrix_H264 *qm) +-+static void fill_scaling_lists(struct dxva_context *ctx, const H264Context *h, DXVA_Qmatrix_H264 *qm) +- { +- unsigned i, j; +- memset(qm, 0, sizeof(*qm)); +-- if (avctx->workaround_bugs & FF_BUG_DXVA2_SCALING_LIST_ZIGZAG) { // For old UVD/UVD+ ATI cards +-- for (i = 0; i < 6; i++) +-- for (j = 0; j < 16; j++) +-- qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j]; +-- +-- for (i = 0; i < 2; i++) +-- for (j = 0; j < 64; j++) +-- qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][j]; +-+ if (ctx->workaround & FF_DXVA2_WORKAROUND_SCALING_LIST_ZIGZAG) { +-+ for (i = 0; i < 6; i++) +-+ for (j = 0; j < 16; j++) +-+ qm->bScalingLists4x4[i][j] = h->pps.scaling_matrix4[i][j]; +-+ +-+ for (i = 0; i < 2; i++) +-+ for (j = 0; j < 64; j++) +-+ qm->bScalingLists8x8[i][j] = h->pps.scaling_matrix8[i][j]; +- } else { +- for (i = 0; i < 6; i++) +- for (j = 0; j < 16; j++) +-@@ -380,7 +383,7 @@ static int start_frame(AVCodecContext *avctx, +- fill_picture_parameters(ctx, h, &ctx_pic->pp); +- +- /* Fill up DXVA_Qmatrix_H264 */ +-- fill_scaling_lists(avctx, h, &ctx_pic->qm); +-+ fill_scaling_lists(ctx, h, &ctx_pic->qm); +- +- ctx_pic->slice_count = 0; +- ctx_pic->bitstream_size = 0; +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0068-fixed-yadif-should-copy-frame-properties-of-second-f.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0068-fixed-yadif-should-copy-frame-properties-of-second-f.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0068-fixed-yadif-should-copy-frame-properties-of-second-f.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0068-fixed-yadif-should-copy-frame-properties-of-second-f.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,31 +0,0 @@ +-From 793f3e0bfcaadaccd0b5db2a37a60da42a6b207e Mon Sep 17 00:00:00 2001 +-From: elupus +-Date: Thu, 14 Jul 2011 22:07:22 +0200 +-Subject: [PATCH] fixed: yadif should copy frame properties of second frame as +- well +- +---- +- lib/ffmpeg/libavfilter/vf_yadif.c | 5 ++++- +- 1 files changed, 4 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavfilter/vf_yadif.c b/lib/ffmpeg/libavfilter/vf_yadif.c +-index d7bed90..da91600 100644 +---- a/lib/ffmpeg/libavfilter/vf_yadif.c +-+++ b/lib/ffmpeg/libavfilter/vf_yadif.c +-@@ -182,9 +182,12 @@ static void return_frame(AVFilterContext *ctx, int is_second) +- tff = yadif->parity^1; +- } +- +-- if (is_second) +-+ if (is_second) { +- yadif->out = avfilter_get_video_buffer(link, AV_PERM_WRITE | AV_PERM_PRESERVE | +- AV_PERM_REUSE, link->w, link->h); +-+ avfilter_copy_buffer_ref_props(yadif->out, yadif->cur); +-+ yadif->out->video->interlaced = 0; +-+ } +- +- filter(ctx, yadif->out, tff ^ !is_second, tff); +- +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0069-ffmpeg-silence-compiler-warnings.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0069-ffmpeg-silence-compiler-warnings.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0069-ffmpeg-silence-compiler-warnings.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0069-ffmpeg-silence-compiler-warnings.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,24 +0,0 @@ +-From 5542a0c7e68d123b86f168ace00f7320b294fc39 Mon Sep 17 00:00:00 2001 +-From: davilla +-Date: Wed, 7 Sep 2011 00:14:34 -0400 +-Subject: [PATCH] [ffmpeg] silence compiler warnings +- +---- +- lib/ffmpeg/libavfilter/avfilter.h | 1 + +- 1 files changed, 1 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavfilter/avfilter.h b/lib/ffmpeg/libavfilter/avfilter.h +-index ad8b1e5..daf43dc 100644 +---- a/lib/ffmpeg/libavfilter/avfilter.h +-+++ b/lib/ffmpeg/libavfilter/avfilter.h +-@@ -159,6 +159,7 @@ static inline void avfilter_copy_buffer_ref_props(AVFilterBufferRef *dst, AVFilt +- switch (src->type) { +- case AVMEDIA_TYPE_VIDEO: *dst->video = *src->video; break; +- case AVMEDIA_TYPE_AUDIO: *dst->audio = *src->audio; break; +-+ default: break; +- } +- } +- +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0070-matroskadec-use-correct-compression-parameters-for-c.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0070-matroskadec-use-correct-compression-parameters-for-c.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0070-matroskadec-use-correct-compression-parameters-for-c.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0070-matroskadec-use-correct-compression-parameters-for-c.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,33 +0,0 @@ +-From 8efe4d01dcd2f89ad012b8f1dd71192e09fa3e82 Mon Sep 17 00:00:00 2001 +-From: CrystalP +-Date: Sun, 16 Oct 2011 03:16:26 -0400 +-Subject: [PATCH] matroskadec: use correct compression parameters for current +- track CodecPrivate +- +-backport of ffmpeg dc6c36ce46d4c4d7cb63503afc2ee44f00bf3725 on 2011-08-17 +- +-fixes a bitmap sub color problem exposed by mkclean --optimize foo.mkv. +-The compressed private data could not be extracted, resulting in a bad color +-palette and wrong colors on screen. +- +-problem described in forum thread http://forum.xbmc.org/showthread.php?t=108942 +---- +- lib/ffmpeg/libavformat/matroskadec.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/matroskadec.c b/lib/ffmpeg/libavformat/matroskadec.c +-index 1a87f4a..14b96d4 100644 +---- a/lib/ffmpeg/libavformat/matroskadec.c +-+++ b/lib/ffmpeg/libavformat/matroskadec.c +-@@ -1220,7 +1220,7 @@ static int matroska_read_header(AVFormatContext *s, AVFormatParameters *ap) +- for (i=0; i < matroska->tracks.nb_elem; i++) { +- MatroskaTrack *track = &tracks[i]; +- enum CodecID codec_id = CODEC_ID_NONE; +-- EbmlList *encodings_list = &tracks->encodings; +-+ EbmlList *encodings_list = &track->encodings; +- MatroskaTrackEncoding *encodings = encodings_list->elem; +- uint8_t *extradata = NULL; +- int extradata_size = 0; +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0071-fixed-Typo.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0071-fixed-Typo.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0071-fixed-Typo.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0071-fixed-Typo.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,25 +0,0 @@ +-From dc0509f7a6341a72ca4399fee37e30c91fddc222 Mon Sep 17 00:00:00 2001 +-From: arnova +-Date: Tue, 8 Nov 2011 08:35:59 +0100 +-Subject: [PATCH] fixed: Typo +- +---- +- lib/ffmpeg/libavformat/mmsh.c | 2 +- +- 1 files changed, 1 insertions(+), 1 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/mmsh.c b/lib/ffmpeg/libavformat/mmsh.c +-index 3ae886f..cc6efa3 100644 +---- a/lib/ffmpeg/libavformat/mmsh.c +-+++ b/lib/ffmpeg/libavformat/mmsh.c +-@@ -284,7 +284,7 @@ static int mmsh_open_internal(URLContext *h, const char *uri, int flags, int tim +- CLIENTGUID +- "Pragma: stream-switch-count=%d\r\n" +- "Pragma: stream-switch-entry=%s\r\n" +-- "Pragma: no-cache,rate)1.000000,stream-time=%u" +-+ "Pragma: no-cache,rate=1.000000,stream-time=%u" +- "Connection: Close\r\n\r\n", +- host, port, mmsh->request_seq++, mms->stream_num, stream_selection, timestamp); +- av_freep(&stream_selection); +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0072-h264-Use-mismatching-frame-numbers-in-fields-to-sync.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0072-h264-Use-mismatching-frame-numbers-in-fields-to-sync.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0072-h264-Use-mismatching-frame-numbers-in-fields-to-sync.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0072-h264-Use-mismatching-frame-numbers-in-fields-to-sync.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,33 +0,0 @@ +-From 2ac62404c2f833d5aa64947819538ac354966ef0 Mon Sep 17 00:00:00 2001 +-From: Michael Niedermayer +-Date: Sat, 12 Nov 2011 21:10:15 +0100 +-Subject: [PATCH] h264: Use mismatching frame numbers in fields to synchronize +- the first/second field state independant of them being +- reference or not. Fixes Ticket354 +- +-Signed-off-by: Michael Niedermayer +---- +- lib/ffmpeg/libavcodec/h264.c | 6 ++---- +- 1 files changed, 2 insertions(+), 4 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/h264.c b/lib/ffmpeg/libavcodec/h264.c +-index 47b0073..87ec292 100644 +---- a/lib/ffmpeg/libavcodec/h264.c +-+++ b/lib/ffmpeg/libavcodec/h264.c +-@@ -1936,11 +1936,9 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ +- s0->first_field = FIELD_PICTURE; +- +- } else { +-- if (h->nal_ref_idc && +-- s0->current_picture_ptr->reference && +-- s0->current_picture_ptr->frame_num != h->frame_num) { +-+ if (s0->current_picture_ptr->frame_num != h->frame_num) { +- /* +-- * This and previous field were reference, but had +-+ * This and previous field had +- * different frame_nums. Consider this field first in +- * pair. Throw away previous field except for reference +- * purposes. +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0073-Don-t-fill-in-frame-gaps-with-copied-refs-after-flus.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0073-Don-t-fill-in-frame-gaps-with-copied-refs-after-flus.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0073-Don-t-fill-in-frame-gaps-with-copied-refs-after-flus.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0073-Don-t-fill-in-frame-gaps-with-copied-refs-after-flus.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-From 46d99a89aa16db1981441bf7103a30e7d28e5e26 Mon Sep 17 00:00:00 2001 +-From: Joakim Plate +-Date: Fri, 18 Nov 2011 20:36:13 +0100 +-Subject: [PATCH] Don't fill in frame gaps with copied refs after flush +- +-The filled in refs cause corruptions in the video frame +-for a long time after it should have recovered. +---- +- lib/ffmpeg/libavcodec/h264.c | 4 ++-- +- 1 files changed, 2 insertions(+), 2 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/h264.c b/lib/ffmpeg/libavcodec/h264.c +-index 87ec292..0e002ce 100644 +---- a/lib/ffmpeg/libavcodec/h264.c +-+++ b/lib/ffmpeg/libavcodec/h264.c +-@@ -1464,7 +1464,7 @@ static void implicit_weight_table(H264Context *h, int field){ +- */ +- static void idr(H264Context *h){ +- ff_h264_remove_all_refs(h); +-- h->prev_frame_num= 0; +-+ h->prev_frame_num= -1; +- h->prev_frame_num_offset= 0; +- h->prev_poc_msb= +- h->prev_poc_lsb= 0; +-@@ -1892,7 +1892,7 @@ static int decode_slice_header(H264Context *h, H264Context *h0){ +- h->mb_field_decoding_flag= s->picture_structure != PICT_FRAME; +- +- if(h0->current_slice == 0){ +-- while(h->frame_num != h->prev_frame_num && +-+ while(h->frame_num != h->prev_frame_num && h->prev_frame_num >= 0 && +- h->frame_num != (h->prev_frame_num+1)%(1<sps.log2_max_frame_num)){ +- Picture *prev = h->short_ref_count ? h->short_ref[0] : NULL; +- av_log(h->s.avctx, AV_LOG_DEBUG, "Frame num gap %d %d\n", h->frame_num, h->prev_frame_num); +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0074-vaapi-do-not-assert-on-value-read-from-input-bitstre.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0074-vaapi-do-not-assert-on-value-read-from-input-bitstre.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0074-vaapi-do-not-assert-on-value-read-from-input-bitstre.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0074-vaapi-do-not-assert-on-value-read-from-input-bitstre.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,41 +0,0 @@ +-From 425b9a373384813d2fe513d42b1d585ecbea6ca5 Mon Sep 17 00:00:00 2001 +-From: Diego Biurrun +-Date: Fri, 15 Jul 2011 01:06:16 +0200 +-Subject: [PATCH] vaapi: do not assert on value read from input bitstream +- +-User-provided data should never trigger an assert; return error instead. +-Also fix an instance of get_bits where get_bits_long should have been used. +- +-This eliminates the following warning: +-libavcodec/vaapi_mpeg2.c:112:14: warning: variable 'start_code' set but not used +- +-Signed-off-by: elupus +---- +- lib/ffmpeg/libavcodec/vaapi_mpeg2.c | 6 +++--- +- 1 files changed, 3 insertions(+), 3 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/vaapi_mpeg2.c b/lib/ffmpeg/libavcodec/vaapi_mpeg2.c +-index 17d82b7..8d456ba 100644 +---- a/lib/ffmpeg/libavcodec/vaapi_mpeg2.c +-+++ b/lib/ffmpeg/libavcodec/vaapi_mpeg2.c +-@@ -109,14 +109,14 @@ static int vaapi_mpeg2_decode_slice(AVCodecContext *avctx, const uint8_t *buffer +- MpegEncContext * const s = avctx->priv_data; +- VASliceParameterBufferMPEG2 *slice_param; +- GetBitContext gb; +-- uint32_t start_code, quantiser_scale_code, intra_slice_flag, macroblock_offset; +-+ uint32_t quantiser_scale_code, intra_slice_flag, macroblock_offset; +- +- av_dlog(avctx, "vaapi_mpeg2_decode_slice(): buffer %p, size %d\n", buffer, size); +- +- /* Determine macroblock_offset */ +- init_get_bits(&gb, buffer, 8 * size); +-- start_code = get_bits(&gb, 32); +-- assert((start_code & 0xffffff00) == 0x00000100); +-+ if (get_bits_long(&gb, 32) >> 8 != 1) /* start code */ +-+ return AVERROR_INVALIDDATA; +- quantiser_scale_code = get_bits(&gb, 5); +- intra_slice_flag = get_bits1(&gb); +- if (intra_slice_flag) { +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0075-fixed-playback-from-mmst-urls-would-halt-after-some-.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0075-fixed-playback-from-mmst-urls-would-halt-after-some-.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0075-fixed-playback-from-mmst-urls-would-halt-after-some-.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0075-fixed-playback-from-mmst-urls-would-halt-after-some-.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,30 +0,0 @@ +-From 919a875b4bc4ea2a8ddc0aab98ea74c6475f9525 Mon Sep 17 00:00:00 2001 +-From: spiff +-Date: Tue, 17 Jan 2012 22:47:36 +0100 +-Subject: [PATCH] fixed: playback from mmst:// urls would halt after some +- time. +- +-this backports upstream 275189a2bd71cf49d66374c44d3de2262d323460 +- +-thanks to johoja for doing the ground work +---- +- lib/ffmpeg/libavformat/mmst.c | 3 +-- +- 1 files changed, 1 insertions(+), 2 deletions(-) +- +-diff --git a/lib/ffmpeg/libavformat/mmst.c b/lib/ffmpeg/libavformat/mmst.c +-index 8464d3b..385f017 100644 +---- a/lib/ffmpeg/libavformat/mmst.c +-+++ b/lib/ffmpeg/libavformat/mmst.c +-@@ -290,8 +290,7 @@ static MMSSCPacketType get_tcp_server_response(MMSTContext *mmst) +- return read_result < 0 ? read_result : AVERROR_IO; +- } +- packet_type= AV_RL16(mms->in_buffer+36); +-- hr = AV_RL32(mms->in_buffer + 40); +-- if (hr) { +-+ if (read_result >= 44 && (hr = AV_RL32(mms->in_buffer + 40))) { +- av_log(NULL, AV_LOG_ERROR, +- "Server sent an error status code: 0x%08x\n", hr); +- return AVERROR_UNKNOWN; +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0076-Fix-dvb-subtitle-decoding-when-display-segment-is-mi.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0076-Fix-dvb-subtitle-decoding-when-display-segment-is-mi.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0076-Fix-dvb-subtitle-decoding-when-display-segment-is-mi.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0076-Fix-dvb-subtitle-decoding-when-display-segment-is-mi.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,63 +0,0 @@ +-From 6373f33e5b12eb06e37d670c9bba4e7041cded79 Mon Sep 17 00:00:00 2001 +-From: Paul Kendall +-Date: Sun, 29 Jan 2012 14:50:19 +0100 +-Subject: [PATCH] Fix dvb subtitle decoding when display segment is missing. +- +-closes ticket #8504 +---- +- lib/ffmpeg/libavcodec/dvbsubdec.c | 10 ++++++++++ +- 1 files changed, 10 insertions(+), 0 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/dvbsubdec.c b/lib/ffmpeg/libavcodec/dvbsubdec.c +-index 7c37915..e8ef8ce 100644 +---- a/lib/ffmpeg/libavcodec/dvbsubdec.c +-+++ b/lib/ffmpeg/libavcodec/dvbsubdec.c +-@@ -1409,6 +1409,7 @@ static int dvbsub_decode(AVCodecContext *avctx, +- int segment_type; +- int page_id; +- int segment_length; +-+ int got_segment = 0; +- +- #ifdef DEBUG_PACKET_CONTENTS +- int i; +-@@ -1445,21 +1446,26 @@ static int dvbsub_decode(AVCodecContext *avctx, +- switch (segment_type) { +- case DVBSUB_PAGE_SEGMENT: +- dvbsub_parse_page_segment(avctx, p, segment_length); +-+ got_segment |= 1; +- break; +- case DVBSUB_REGION_SEGMENT: +- dvbsub_parse_region_segment(avctx, p, segment_length); +-+ got_segment |= 2; +- break; +- case DVBSUB_CLUT_SEGMENT: +- dvbsub_parse_clut_segment(avctx, p, segment_length); +-+ got_segment |= 4; +- break; +- case DVBSUB_OBJECT_SEGMENT: +- dvbsub_parse_object_segment(avctx, p, segment_length); +-+ got_segment |= 8; +- break; +- case DVBSUB_DISPLAYDEFINITION_SEGMENT: +- dvbsub_parse_display_definition_segment(avctx, p, segment_length); +- break; +- case DVBSUB_DISPLAY_SEGMENT: +- *data_size = dvbsub_display_end_segment(avctx, p, segment_length, sub); +-+ got_segment |= 16; +- break; +- default: +- av_dlog(avctx, "Subtitling segment type 0x%x, page id %d, length %d\n", +-@@ -1470,6 +1476,10 @@ static int dvbsub_decode(AVCodecContext *avctx, +- +- p += segment_length; +- } +-+ // Some streams do not send a display segment but if we have all the other +-+ // segments then we need no further data. +-+ if (got_segment == 15 && sub) +-+ *data_size = dvbsub_display_end_segment(avctx, p, 0, sub); +- +- if (p != p_end) { +- av_dlog(avctx, "Junk at end of packet\n"); +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0077-Change-yadif-to-not-use-out-of-picture-lines.-Fixes-.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0077-Change-yadif-to-not-use-out-of-picture-lines.-Fixes-.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0077-Change-yadif-to-not-use-out-of-picture-lines.-Fixes-.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0077-Change-yadif-to-not-use-out-of-picture-lines.-Fixes-.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,133 +0,0 @@ +-From 42bedafe92b2921ec63024a825d4297ba39888e9 Mon Sep 17 00:00:00 2001 +-From: Michael Niedermayer +-Date: Fri, 18 Feb 2011 19:10:33 +0100 +-Subject: [PATCH] Change yadif to not use out of picture lines. Fixes +- issue2272. +- +-Signed-off-by: Michael Niedermayer +---- +- lib/ffmpeg/libavfilter/vf_yadif.c | 31 ++++++++++++++------------- +- lib/ffmpeg/libavfilter/x86/yadif_template.c | 6 ++-- +- lib/ffmpeg/libavfilter/yadif.h | 6 ++-- +- 3 files changed, 22 insertions(+), 21 deletions(-) +- +-diff --git a/lib/ffmpeg/libavfilter/vf_yadif.c b/lib/ffmpeg/libavfilter/vf_yadif.c +-index da91600..1ed8807 100644 +---- a/lib/ffmpeg/libavfilter/vf_yadif.c +-+++ b/lib/ffmpeg/libavfilter/vf_yadif.c +-@@ -56,42 +56,42 @@ typedef struct { +- AVFilterBufferRef *out; +- void (*filter_line)(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode); +-+ int w, int prefs, int mrefs, int parity, int mode); +- } YADIFContext; +- +- static void filter_line_c(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode) +-+ int w, int prefs, int mrefs, int parity, int mode) +- { +- int x; +- uint8_t *prev2 = parity ? prev : cur ; +- uint8_t *next2 = parity ? cur : next; +- for (x = 0; x < w; x++) { +-- int c = cur[-refs]; +-+ int c = cur[mrefs]; +- int d = (prev2[0] + next2[0])>>1; +-- int e = cur[+refs]; +-+ int e = cur[prefs]; +- int temporal_diff0 = FFABS(prev2[0] - next2[0]); +-- int temporal_diff1 =(FFABS(prev[-refs] - c) + FFABS(prev[+refs] - e) )>>1; +-- int temporal_diff2 =(FFABS(next[-refs] - c) + FFABS(next[+refs] - e) )>>1; +-+ int temporal_diff1 =(FFABS(prev[mrefs] - c) + FFABS(prev[prefs] - e) )>>1; +-+ int temporal_diff2 =(FFABS(next[mrefs] - c) + FFABS(next[prefs] - e) )>>1; +- int diff = FFMAX3(temporal_diff0>>1, temporal_diff1, temporal_diff2); +- int spatial_pred = (c+e)>>1; +-- int spatial_score = FFABS(cur[-refs-1] - cur[+refs-1]) + FFABS(c-e) +-- + FFABS(cur[-refs+1] - cur[+refs+1]) - 1; +-+ int spatial_score = FFABS(cur[mrefs-1] - cur[prefs-1]) + FFABS(c-e) +-+ + FFABS(cur[mrefs+1] - cur[prefs+1]) - 1; +- +- #define CHECK(j)\ +-- { int score = FFABS(cur[-refs-1+j] - cur[+refs-1-j])\ +-- + FFABS(cur[-refs +j] - cur[+refs -j])\ +-- + FFABS(cur[-refs+1+j] - cur[+refs+1-j]);\ +-+ { int score = FFABS(cur[mrefs-1+j] - cur[prefs-1-j])\ +-+ + FFABS(cur[mrefs +j] - cur[prefs -j])\ +-+ + FFABS(cur[mrefs+1+j] - cur[prefs+1-j]);\ +- if (score < spatial_score) {\ +- spatial_score= score;\ +-- spatial_pred= (cur[-refs +j] + cur[+refs -j])>>1;\ +-+ spatial_pred= (cur[mrefs +j] + cur[prefs -j])>>1;\ +- +- CHECK(-1) CHECK(-2) }} }} +- CHECK( 1) CHECK( 2) }} }} +- +- if (mode < 2) { +-- int b = (prev2[-2*refs] + next2[-2*refs])>>1; +-- int f = (prev2[+2*refs] + next2[+2*refs])>>1; +-+ int b = (prev2[2*mrefs] + next2[2*mrefs])>>1; +-+ int f = (prev2[2*prefs] + next2[2*prefs])>>1; +- #if 0 +- int a = cur[-3*refs]; +- int g = cur[+3*refs]; +-@@ -139,7 +139,8 @@ static void filter(AVFilterContext *ctx, AVFilterBufferRef *dstpic, +- uint8_t *cur = &yadif->cur ->data[i][y*refs]; +- uint8_t *next = &yadif->next->data[i][y*refs]; +- uint8_t *dst = &dstpic->data[i][y*dstpic->linesize[i]]; +-- yadif->filter_line(dst, prev, cur, next, w, refs, parity ^ tff, yadif->mode); +-+ int mode = y==1 || y+2==h ? 2 : yadif->mode; +-+ yadif->filter_line(dst, prev, cur, next, w, y+1data[i][y*dstpic->linesize[i]], +- &yadif->cur->data[i][y*refs], w); +-diff --git a/lib/ffmpeg/libavfilter/x86/yadif_template.c b/lib/ffmpeg/libavfilter/x86/yadif_template.c +-index 3e520cb..50ea843 100644 +---- a/lib/ffmpeg/libavfilter/x86/yadif_template.c +-+++ b/lib/ffmpeg/libavfilter/x86/yadif_template.c +-@@ -105,7 +105,7 @@ +- +- void RENAME(ff_yadif_filter_line)(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode) +-+ int w, int prefs, int mrefs, int parity, int mode) +- { +- DECLARE_ALIGNED(16, uint8_t, tmp0[16]); +- DECLARE_ALIGNED(16, uint8_t, tmp1[16]); +-@@ -226,8 +226,8 @@ void RENAME(ff_yadif_filter_line)(uint8_t *dst, +- :[prev] "r"(prev),\ +- [cur] "r"(cur),\ +- [next] "r"(next),\ +-- [prefs]"r"((x86_reg)refs),\ +-- [mrefs]"r"((x86_reg)-refs),\ +-+ [prefs]"r"((x86_reg)prefs),\ +-+ [mrefs]"r"((x86_reg)mrefs),\ +- [mode] "g"(mode)\ +- );\ +- __asm__ volatile(MOV" "MM"1, %0" :"=m"(*dst));\ +-diff --git a/lib/ffmpeg/libavfilter/yadif.h b/lib/ffmpeg/libavfilter/yadif.h +-index 072812c..ff574da 100644 +---- a/lib/ffmpeg/libavfilter/yadif.h +-+++ b/lib/ffmpeg/libavfilter/yadif.h +-@@ -23,14 +23,14 @@ +- +- void ff_yadif_filter_line_mmx(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode); +-+ int w, int prefs, int mrefs, int parity, int mode); +- +- void ff_yadif_filter_line_sse2(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode); +-+ int w, int prefs, int mrefs, int parity, int mode); +- +- void ff_yadif_filter_line_ssse3(uint8_t *dst, +- uint8_t *prev, uint8_t *cur, uint8_t *next, +-- int w, int refs, int parity, int mode); +-+ int w, int prefs, int mrefs, int parity, int mode); +- +- #endif /* AVFILTER_YADIF_H */ +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/patches/0078-fixed-ffmpeg-build-with-gcc-4.7-on-x86.patch xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0078-fixed-ffmpeg-build-with-gcc-4.7-on-x86.patch +--- xbmc-pvr-11.0.1/lib/ffmpeg/patches/0078-fixed-ffmpeg-build-with-gcc-4.7-on-x86.patch 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/patches/0078-fixed-ffmpeg-build-with-gcc-4.7-on-x86.patch 1970-01-01 01:00:00.000000000 +0100 +@@ -1,68 +0,0 @@ +-From 400b84bb8d3d2a9c202fa3da4fb01279230a87ce Mon Sep 17 00:00:00 2001 +-From: Anssi Hannula +-Date: Wed, 7 Mar 2012 23:08:54 +0200 +-Subject: [PATCH] fixed: ffmpeg build with gcc 4.7 on x86 +- +-Backport da4c7cce2100a4e4f9276b4f17e260be47b53f41 from FFmpeg git: +- +-> From: Mans Rullgard +-> Date: Tue, 26 Jul 2011 11:23:43 +0000 (+0100) +-> +-> x86: fix build with gcc 4.7 +-> +-> The upcoming gcc 4.7 has more advanced constant propagation +-> resulting some inline asm operands becoming constants and thus +-> emitted as literals, sometimes in contexts where this results +-> in invalid instructions. +-> +-> This patch changes the constraints of the relevant operands +-> to "rm" thus forcing a valid type. While obviously suboptimal, +-> this is what older gcc versions already did, and there is no +-> change to the code generated with these. +---- +- lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c | 8 ++++---- +- 1 files changed, 4 insertions(+), 4 deletions(-) +- +-diff --git a/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c b/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c +-index d8ceca1..f5af44e 100644 +---- a/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c +-+++ b/lib/ffmpeg/libavcodec/x86/h264_qpel_mmx.c +-@@ -398,7 +398,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, +- "2: \n\t"\ +- \ +- : "+a"(src), "+c"(dst)\ +-- : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\ +-+ : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\ +- : "memory"\ +- );\ +- src += 4-(h+5)*srcStride;\ +-@@ -446,7 +446,7 @@ static av_always_inline void OPNAME ## h264_qpel8or16_hv1_lowpass_ ## MMX(int16_ +- QPEL_H264HV(%%mm3, %%mm4, %%mm5, %%mm0, %%mm1, %%mm2, 15*48)\ +- "2: \n\t"\ +- : "+a"(src)\ +-- : "c"(tmp), "S"((x86_reg)srcStride), "g"(size)\ +-+ : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size)\ +- : "memory"\ +- );\ +- tmp += 4;\ +-@@ -823,7 +823,7 @@ static av_noinline void OPNAME ## h264_qpel8or16_v_lowpass_ ## MMX(uint8_t *dst, +- "2: \n\t"\ +- \ +- : "+a"(src), "+c"(dst)\ +-- : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "g"(h)\ +-+ : "S"((x86_reg)srcStride), "D"((x86_reg)dstStride), "rm"(h)\ +- : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", \ +- "%xmm4", "%xmm5", "%xmm6", "%xmm7",)\ +- "memory"\ +-@@ -878,7 +878,7 @@ static av_always_inline void put_h264_qpel8or16_hv1_lowpass_sse2(int16_t *tmp, u +- QPEL_H264HV_XMM(%%xmm3, %%xmm4, %%xmm5, %%xmm0, %%xmm1, %%xmm2, 15*48) +- "2: \n\t" +- : "+a"(src) +-- : "c"(tmp), "S"((x86_reg)srcStride), "g"(size) +-+ : "c"(tmp), "S"((x86_reg)srcStride), "rm"(size) +- : XMM_CLOBBERS("%xmm0", "%xmm1", "%xmm2", "%xmm3", +- "%xmm4", "%xmm5", "%xmm6", "%xmm7",) +- "memory" +--- +-1.7.7.2 +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-1080p50_60.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-1080p50_60.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-1080p50_60.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-1080p50_60.ffpreset 2012-05-14 14:08:55.494363329 +0200 +@@ -0,0 +1,17 @@ ++g=120 ++lag-in-frames=25 ++deadline=good ++cpu-used=0 ++vprofile=1 ++qmax=51 ++qmin=11 ++slices=4 ++b=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k ++auto-alt-ref=1 ++arnr-maxframes=7 ++arnr-strength=5 ++arnr-type=centered +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-1080p.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-1080p.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-1080p.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-1080p.ffpreset 2012-05-14 14:08:55.493363308 +0200 +@@ -0,0 +1,17 @@ ++g=120 ++lag-in-frames=16 ++deadline=good ++cpu-used=0 ++vprofile=1 ++qmax=51 ++qmin=11 ++slices=4 ++b=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k ++auto-alt-ref=1 ++arnr-maxframes=7 ++arnr-strength=5 ++arnr-type=centered +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-360p.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-360p.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-360p.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-360p.ffpreset 2012-05-14 14:08:55.494363329 +0200 +@@ -0,0 +1,16 @@ ++g=120 ++lag-in-frames=16 ++deadline=good ++cpu-used=0 ++vprofile=0 ++qmax=63 ++qmin=0 ++b=768k ++ ++#ignored unless using -pass 2 ++maxrate=1.5M ++minrate=40k ++auto-alt-ref=1 ++arnr-maxframes=7 ++arnr-strength=5 ++arnr-type=centered +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-720p50_60.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-720p50_60.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-720p50_60.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-720p50_60.ffpreset 2012-05-14 14:08:55.495363349 +0200 +@@ -0,0 +1,17 @@ ++g=120 ++lag-in-frames=25 ++deadline=good ++cpu-used=0 ++vprofile=0 ++qmax=51 ++qmin=11 ++slices=4 ++b=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k ++auto-alt-ref=1 ++arnr-maxframes=7 ++arnr-strength=5 ++arnr-type=centered +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-720p.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-720p.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libvpx-720p.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libvpx-720p.ffpreset 2012-05-14 14:08:55.495363349 +0200 +@@ -0,0 +1,17 @@ ++g=120 ++lag-in-frames=16 ++deadline=good ++cpu-used=0 ++vprofile=0 ++qmax=51 ++qmin=11 ++slices=4 ++b=2M ++ ++#ignored unless using -pass 2 ++maxrate=24M ++minrate=100k ++auto-alt-ref=1 ++arnr-maxframes=7 ++arnr-strength=5 ++arnr-type=centered +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libx264-ipod320.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libx264-ipod320.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libx264-ipod320.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libx264-ipod320.ffpreset 2012-05-14 14:08:55.496363369 +0200 +@@ -0,0 +1,4 @@ ++vprofile=baseline ++level=13 ++maxrate=768000 ++bufsize=3000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/presets/libx264-ipod640.ffpreset xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libx264-ipod640.ffpreset +--- xbmc-pvr-11.0.1/lib/ffmpeg/presets/libx264-ipod640.ffpreset 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/presets/libx264-ipod640.ffpreset 2012-05-14 14:08:55.496363369 +0200 +@@ -0,0 +1,4 @@ ++vprofile=baseline ++level=30 ++maxrate=10000000 ++bufsize=10000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/RELEASE xbmc-pvr-11.0.1.patch/lib/ffmpeg/RELEASE +--- xbmc-pvr-11.0.1/lib/ffmpeg/RELEASE 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/RELEASE 2012-05-14 14:08:53.101315166 +0200 +@@ -0,0 +1 @@ ++0.10.2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/subdir.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/subdir.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/subdir.mak 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/subdir.mak 1970-01-01 01:00:00.000000000 +0100 +@@ -1,101 +0,0 @@ +-SRC_DIR := $(SRC_PATH_BARE)/lib$(NAME) +- +-include $(SUBDIR)../common.mak +- +-LIBVERSION := $(lib$(NAME)_VERSION) +-LIBMAJOR := $(lib$(NAME)_VERSION_MAJOR) +-INCINSTDIR := $(INCDIR)/lib$(NAME) +-THIS_LIB := $(SUBDIR)$($(CONFIG_SHARED:yes=S)LIBNAME) +- +-all-$(CONFIG_STATIC): $(SUBDIR)$(LIBNAME) +-all-$(CONFIG_SHARED): $(SUBDIR)$(SLIBNAME) +- +-$(SUBDIR)%-test.o: $(SUBDIR)%-test.c +- $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $(CC_O) $^ +- +-$(SUBDIR)%-test.o: $(SUBDIR)%.c +- $(CC) $(CPPFLAGS) $(CFLAGS) -DTEST -c $(CC_O) $^ +- +-$(SUBDIR)x86/%.o: $(SUBDIR)x86/%.asm +- $(YASMDEP) $(YASMFLAGS) -I $( $(@:.o=.d) +- $(YASM) $(YASMFLAGS) -I $( (FRAC_ONE / 4)) { + neg = -1; +- a = (FRAC_ONE / 2) - a; ++ a = (FRAC_ONE / 2) - a; + } + p = cos_table + (a >> CSHIFT); + /* linear interpolation */ +@@ -139,63 +139,63 @@ + + /* 1 second of single freq sinus at 1000 Hz */ + a = 0; +- for(i=0;i<1 * sample_rate;i++) { ++ for (i = 0; i < 1 * sample_rate; i++) { + v = (int_cos(a) * 10000) >> FRAC_BITS; +- for(j=0;j> FRAC_BITS; +- for(j=0;j> FRAC_BITS; + put_sample(v); +- f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); ++ f = tabf1[j] + (((tabf2[j] - tabf1[j]) * i) / sample_rate); + taba[j] += (f * FRAC_ONE) / sample_rate; + } + } + + /* 2 seconds of 500 Hz with varying volume */ +- a = 0; ++ a = 0; + ampa = 0; +- for(i=0;i<2 * sample_rate;i++) { +- for(j=0;j> FRAC_BITS; + if (j & 1) + amp = 10000 - amp; + v = (int_cos(a) * amp) >> FRAC_BITS; + put_sample(v); +- a += (500 * FRAC_ONE) / sample_rate; ++ a += (500 * FRAC_ONE) / sample_rate; + ampa += (2 * FRAC_ONE) / sample_rate; + } + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/base64.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/base64.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/base64.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/base64.c 2012-05-14 14:08:55.560364656 +0200 +@@ -27,18 +27,19 @@ + static const char b64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + unsigned i_bits = 0; +- int i_shift = 0; +- int out_len = 0; ++ int i_shift = 0; ++ int out_len = 0; + int in; + +-#define putb64() do { \ ++#define putb64() \ ++ do { \ + putchar(b64[(i_bits << 6 >> i_shift) & 0x3f]); \ + out_len++; \ + i_shift -= 6; \ + } while (0) + + while ((in = getchar()) != EOF) { +- i_bits = (i_bits << 8) + in; ++ i_bits = (i_bits << 8) + in; + i_shift += 8; + while (i_shift > 6) + putb64(); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/codec-regression.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/codec-regression.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/codec-regression.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/codec-regression.sh 2012-05-14 14:08:55.562364696 +0200 +@@ -1,6 +1,6 @@ + #!/bin/sh + # +-# automatic regression test for ffmpeg ++# automatic regression test for avconv + # + # + #set -x +@@ -11,355 +11,483 @@ + + eval do_$test=y + +-rm -f "$logfile" +-rm -f "$benchfile" +- + # generate reference for quality check + if [ -n "$do_vref" ]; then +-do_ffmpeg_nocheck $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo $target_path/$raw_ref ++do_avconv $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo + fi + if [ -n "$do_aref" ]; then +-do_ffmpeg_nocheck $pcm_ref -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav $target_path/$pcm_ref ++do_avconv $pcm_ref -b 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav ++fi ++ ++if [ -n "$do_cljr" ] ; then ++do_video_encoding cljr.avi "-an -vcodec cljr" ++do_video_decoding + fi + + if [ -n "$do_mpeg" ] ; then + # mpeg1 +-do_video_encoding mpeg1.mpg "-qscale 10" "-f mpeg1video" ++do_video_encoding mpeg1.mpg "-qscale 10 -f mpeg1video" + do_video_decoding + fi + + if [ -n "$do_mpeg2" ] ; then + # mpeg2 +-do_video_encoding mpeg2.mpg "-qscale 10" "-vcodec mpeg2video -f mpeg1video" ++do_video_encoding mpeg2.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video" + do_video_decoding ++fi + ++if [ -n "$do_mpeg2_ivlc_qprd" ]; then + # mpeg2 encoding intra vlc qprd +-do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +qprd+mv0 -flags2 +ivlc -cmp 2 -subcmp 2 -mbd rd" "-vcodec mpeg2video -f mpeg2video" ++do_video_encoding mpeg2ivlc-qprd.mpg "-vb 500k -bf 2 -trellis 1 -flags +qprd+mv0 -flags2 +ivlc -cmp 2 -subcmp 2 -mbd rd -vcodec mpeg2video -f mpeg2video" + do_video_decoding ++fi + ++if [ -n "$do_mpeg2_422" ]; then + #mpeg2 4:2:2 encoding +-do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +qprd+mv0+ildct+ilme -flags2 +ivlc -mbd rd" "-vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video" ++do_video_encoding mpeg2_422.mpg "-vb 1000k -bf 2 -trellis 1 -flags +qprd+mv0+ildct+ilme -flags2 +ivlc -mbd rd -vcodec mpeg2video -pix_fmt yuv422p -f mpeg2video" + do_video_decoding ++fi + ++if [ -n "$do_mpeg2_idct_int" ]; then + # mpeg2 +-do_video_encoding mpeg2.mpg "-qscale 10" "-vcodec mpeg2video -idct int -dct int -f mpeg1video" ++do_video_encoding mpeg2_idct_int.mpg "-qscale 10 -vcodec mpeg2video -idct int -dct int -f mpeg1video" + do_video_decoding "-idct int" ++fi + ++if [ -n "$do_mpeg2_ilace" ]; then + # mpeg2 encoding interlaced +-do_video_encoding mpeg2i.mpg "-qscale 10" "-vcodec mpeg2video -f mpeg1video -flags +ildct+ilme" ++do_video_encoding mpeg2i.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -flags +ildct+ilme" + do_video_decoding + fi + + if [ -n "$do_mpeg2thread" ] ; then + # mpeg2 encoding interlaced +-do_video_encoding mpeg2thread.mpg "-qscale 10" "-vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 2" ++do_video_encoding mpeg2thread.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 2 -slices 2" + do_video_decoding ++fi + ++if [ -n "$do_mpeg2thread_ilace" ]; then + # mpeg2 encoding interlaced using intra vlc +-do_video_encoding mpeg2threadivlc.mpg "-qscale 10" "-vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2" ++do_video_encoding mpeg2threadivlc.mpg "-qscale 10 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -flags2 +ivlc -threads 2 -slices 2" + do_video_decoding + + # mpeg2 encoding interlaced + file=${outfile}mpeg2reuse.mpg +-do_ffmpeg $file -sameq -me_threshold 256 -mb_threshold 1024 -i ${target_path}/${outfile}mpeg2thread.mpg -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4 ++do_avconv $file $DEC_OPTS -me_threshold 256 -i ${target_path}/${outfile}mpeg2thread.mpg $ENC_OPTS -same_quant -me_threshold 256 -mb_threshold 1024 -vcodec mpeg2video -f mpeg1video -bf 2 -flags +ildct+ilme -threads 4 + do_video_decoding + fi + + if [ -n "$do_msmpeg4v2" ] ; then +-do_video_encoding msmpeg4v2.avi "-qscale 10" "-an -vcodec msmpeg4v2" ++do_video_encoding msmpeg4v2.avi "-qscale 10 -an -vcodec msmpeg4v2" + do_video_decoding + fi + + if [ -n "$do_msmpeg4" ] ; then +-do_video_encoding msmpeg4.avi "-qscale 10" "-an -vcodec msmpeg4" ++do_video_encoding msmpeg4.avi "-qscale 10 -an -vcodec msmpeg4" + do_video_decoding + fi + ++if [ -n "$do_msvideo1" ] ; then ++do_video_encoding msvideo1.avi "-an -vcodec msvideo1" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ + if [ -n "$do_wmv1" ] ; then +-do_video_encoding wmv1.avi "-qscale 10" "-an -vcodec wmv1" ++do_video_encoding wmv1.avi "-qscale 10 -an -vcodec wmv1" + do_video_decoding + fi + + if [ -n "$do_wmv2" ] ; then +-do_video_encoding wmv2.avi "-qscale 10" "-an -vcodec wmv2" ++do_video_encoding wmv2.avi "-qscale 10 -an -vcodec wmv2" + do_video_decoding + fi + + if [ -n "$do_h261" ] ; then +-do_video_encoding h261.avi "-qscale 11" "-s 352x288 -an -vcodec h261" ++do_video_encoding h261.avi "-qscale 11 -s 352x288 -an -vcodec h261" + do_video_decoding + fi + + if [ -n "$do_h263" ] ; then +-do_video_encoding h263.avi "-qscale 10" "-s 352x288 -an -vcodec h263" ++do_video_encoding h263.avi "-qscale 10 -s 352x288 -an -vcodec h263" + do_video_decoding + fi + + if [ -n "$do_h263p" ] ; then +-do_video_encoding h263p.avi "-qscale 2 -flags +umv+aiv+aic" "-s 352x288 -an -vcodec h263p -ps 300" ++do_video_encoding h263p.avi "-qscale 2 -flags +umv+aiv+aic -s 352x288 -an -vcodec h263p -ps 300" + do_video_decoding + fi + + if [ -n "$do_mpeg4" ] ; then +-do_video_encoding odivx.mp4 "-flags +mv4 -mbd bits -qscale 10" "-an -vcodec mpeg4" ++do_video_encoding odivx.mp4 "-flags +mv4 -mbd bits -qscale 10 -an -vcodec mpeg4" + do_video_decoding + fi + + if [ -n "$do_huffyuv" ] ; then +-do_video_encoding huffyuv.avi "" "-an -vcodec huffyuv -pix_fmt yuv422p -sws_flags neighbor+bitexact" ++do_video_encoding huffyuv.avi "-an -vcodec huffyuv -pix_fmt yuv422p -sws_flags neighbor+bitexact" + do_video_decoding "" "-strict -2 -pix_fmt yuv420p -sws_flags neighbor+bitexact" + fi + ++if [ -n "$do_amv" ] ; then ++do_video_encoding amv.avi "-an -vcodec amv" ++do_video_decoding ++fi ++ + if [ -n "$do_rc" ] ; then +-do_video_encoding mpeg4-rc.avi "-b 400k -bf 2" "-an -vcodec mpeg4" ++do_video_encoding mpeg4-rc.avi "-b 400k -bf 2 -an -vcodec mpeg4" + do_video_decoding + fi + + if [ -n "$do_mpeg4adv" ] ; then +-do_video_encoding mpeg4-adv.avi "-qscale 9 -flags +mv4+part+aic -trellis 1 -mbd bits -ps 200" "-an -vcodec mpeg4" ++do_video_encoding mpeg4-adv.avi "-qscale 9 -flags +mv4+part+aic -trellis 1 -mbd bits -ps 200 -an -vcodec mpeg4" + do_video_decoding ++fi + +-do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd" "-an -vcodec mpeg4" ++if [ -n "$do_mpeg4_qprd" ]; then ++do_video_encoding mpeg4-qprd.avi "-b 450k -bf 2 -trellis 1 -flags +mv4+qprd+mv0 -cmp 2 -subcmp 2 -mbd rd -an -vcodec mpeg4" + do_video_decoding ++fi + +-do_video_encoding mpeg4-adap.avi "-b 550k -bf 2 -flags +mv4+mv0 -trellis 1 -cmp 1 -subcmp 2 -mbd rd -scplx_mask 0.3" "-an -vcodec mpeg4" ++if [ -n "$do_mpeg4_adap" ]; then ++do_video_encoding mpeg4-adap.avi "-b 550k -bf 2 -flags +mv4+mv0 -trellis 1 -cmp 1 -subcmp 2 -mbd rd -scplx_mask 0.3 -an -vcodec mpeg4" + do_video_decoding ++fi + +-do_video_encoding mpeg4-Q.avi "-qscale 7 -flags +mv4+qpel -mbd 2 -bf 2 -cmp 1 -subcmp 2" "-an -vcodec mpeg4" ++if [ -n "$do_mpeg4_qpel" ]; then ++do_video_encoding mpeg4-Q.avi "-qscale 7 -flags +mv4+qpel -mbd 2 -bf 2 -cmp 1 -subcmp 2 -an -vcodec mpeg4" + do_video_decoding + fi + + if [ -n "$do_mpeg4thread" ] ; then +-do_video_encoding mpeg4-thread.avi "-b 500k -flags +mv4+part+aic -trellis 1 -mbd bits -ps 200 -bf 2" "-an -vcodec mpeg4 -threads 2" ++do_video_encoding mpeg4-thread.avi "-b 500k -flags +mv4+part+aic -trellis 1 -mbd bits -ps 200 -bf 2 -an -vcodec mpeg4 -threads 2 -slices 2" + do_video_decoding + fi + + if [ -n "$do_error" ] ; then +-do_video_encoding error-mpeg4-adv.avi "-qscale 7 -flags +mv4+part+aic -mbd rd -ps 250 -error 10" "-an -vcodec mpeg4" ++do_video_encoding error-mpeg4-adv.avi "-qscale 7 -flags +mv4+part+aic -mbd rd -ps 250 -error 10 -an -vcodec mpeg4" + do_video_decoding + fi + + if [ -n "$do_mpeg4nr" ] ; then +-do_video_encoding mpeg4-nr.avi "-qscale 8 -flags +mv4 -mbd rd -nr 200" "-an -vcodec mpeg4" ++do_video_encoding mpeg4-nr.avi "-qscale 8 -flags +mv4 -mbd rd -nr 200 -an -vcodec mpeg4" + do_video_decoding + fi + + if [ -n "$do_mpeg1b" ] ; then +-do_video_encoding mpeg1b.mpg "-qscale 8 -bf 3 -ps 200" "-an -vcodec mpeg1video -f mpeg1video" ++do_video_encoding mpeg1b.mpg "-qscale 8 -bf 3 -ps 200 -an -vcodec mpeg1video -f mpeg1video" + do_video_decoding + fi + + if [ -n "$do_mjpeg" ] ; then +-do_video_encoding mjpeg.avi "-qscale 9" "-an -vcodec mjpeg -pix_fmt yuvj420p" ++do_video_encoding mjpeg.avi "-qscale 9 -an -vcodec mjpeg -pix_fmt yuvj420p" + do_video_decoding "" "-pix_fmt yuv420p" + fi + ++if [ -n "$do_jpeg2000" ] ; then ++do_video_encoding jpeg2000.avi "-qscale 7 -an -vcodec j2k -strict experimental -pix_fmt rgb24" ++do_video_decoding "-vcodec j2k -strict experimental" "-pix_fmt yuv420p" ++fi ++ + if [ -n "$do_ljpeg" ] ; then +-do_video_encoding ljpeg.avi "" "-an -vcodec ljpeg -strict -1" ++do_video_encoding ljpeg.avi "-an -vcodec ljpeg -strict -1" + do_video_decoding + fi + + if [ -n "$do_jpegls" ] ; then +-do_video_encoding jpegls.avi "" "-an -vcodec jpegls -vtag MJPG -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact" ++do_video_encoding jpegls.avi "-an -vcodec jpegls -vtag MJPG -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact" + do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+bitexact" + fi + + if [ -n "$do_rv10" ] ; then +-do_video_encoding rv10.rm "-qscale 10" "-an" ++do_video_encoding rv10.rm "-qscale 10 -an" + do_video_decoding + fi + + if [ -n "$do_rv20" ] ; then +-do_video_encoding rv20.rm "-qscale 10" "-vcodec rv20 -an" ++do_video_encoding rv20.rm "-qscale 10 -vcodec rv20 -an" + do_video_decoding + fi + + if [ -n "$do_asv1" ] ; then +-do_video_encoding asv1.avi "-qscale 10" "-an -vcodec asv1" ++do_video_encoding asv1.avi "-qscale 10 -an -vcodec asv1" + do_video_decoding + fi + + if [ -n "$do_asv2" ] ; then +-do_video_encoding asv2.avi "-qscale 10" "-an -vcodec asv2" ++do_video_encoding asv2.avi "-qscale 10 -an -vcodec asv2" + do_video_decoding + fi + + if [ -n "$do_flv" ] ; then +-do_video_encoding flv.flv "-qscale 10" "-an -vcodec flv" ++do_video_encoding flv.flv "-qscale 10 -an -vcodec flv" + do_video_decoding + fi + + if [ -n "$do_ffv1" ] ; then +-do_video_encoding ffv1.avi "-strict -2" "-an -vcodec ffv1" ++do_video_encoding ffv1.avi "-strict -2 -an -vcodec ffv1" + do_video_decoding + fi + + if [ -n "$do_snow" ] ; then +-do_video_encoding snow.avi "-strict -2" "-an -vcodec snow -qscale 2 -flags +qpel -me_method iter -dia_size 2 -cmp 12 -subcmp 12 -s 128x64" ++do_video_encoding snow.avi "-strict -2 -an -vcodec snow -qscale 2 -flags +qpel -me_method iter -dia_size 2 -cmp 12 -subcmp 12 -s 128x64" + do_video_decoding "" "-s 352x288" + fi + + if [ -n "$do_snowll" ] ; then +-do_video_encoding snow53.avi "-strict -2" "-an -vcodec snow -qscale .001 -pred 1 -flags +mv4+qpel" ++do_video_encoding snow53.avi "-strict -2 -an -vcodec snow -qscale .001 -pred 1 -flags +mv4+qpel" + do_video_decoding + fi + + if [ -n "$do_dv" ] ; then +-do_video_encoding dv.dv "-dct int" "-s pal -an" ++do_video_encoding dv.dv "-dct int -s pal -an" + do_video_decoding "" "-s cif" ++fi + +-do_video_encoding dv411.dv "-dct int" "-s pal -an -pix_fmt yuv411p -sws_flags area+accurate_rnd+bitexact" ++if [ -n "$do_dv_411" ]; then ++do_video_encoding dv411.dv "-dct int -s pal -an -pix_fmt yuv411p -sws_flags area+accurate_rnd+bitexact" + do_video_decoding "" "-s cif -sws_flags area+accurate_rnd+bitexact" + fi + + if [ -n "$do_dv50" ] ; then +-do_video_encoding dv50.dv "-dct int" "-s pal -pix_fmt yuv422p -an -sws_flags neighbor+bitexact" ++do_video_encoding dv50.dv "-dct int -s pal -pix_fmt yuv422p -an -sws_flags neighbor+bitexact" + do_video_decoding "" "-s cif -pix_fmt yuv420p -sws_flags neighbor+bitexact" + fi + + if [ -n "$do_dnxhd_1080i" ] ; then + # FIXME: interlaced raw DNxHD decoding is broken +-do_video_encoding dnxhd-1080i.mov "" "-vcodec dnxhd -flags +ildct -s hd1080 -b 120M -pix_fmt yuv422p -vframes 5 -an" +-do_video_decoding "-r 25" "-s cif -pix_fmt yuv420p" ++do_video_encoding dnxhd-1080i.mov "-vcodec dnxhd -flags +ildct -s hd1080 -b 120M -pix_fmt yuv422p -vframes 5 -an" ++do_video_decoding "" "-s cif -pix_fmt yuv420p" + fi + + if [ -n "$do_dnxhd_720p" ] ; then +-do_video_encoding dnxhd-720p.dnxhd "" "-s hd720 -b 90M -pix_fmt yuv422p -vframes 5 -an" +-do_video_decoding "-r 25" "-s cif -pix_fmt yuv420p" ++do_video_encoding dnxhd-720p.dnxhd "-s hd720 -b 90M -pix_fmt yuv422p -vframes 5 -an" ++do_video_decoding "" "-s cif -pix_fmt yuv420p" + fi + + if [ -n "$do_dnxhd_720p_rd" ] ; then +-do_video_encoding dnxhd-720p-rd.dnxhd "" "-threads 4 -mbd rd -s hd720 -b 90M -pix_fmt yuv422p -vframes 5 -an" +-do_video_decoding "-r 25" "-s cif -pix_fmt yuv420p" ++do_video_encoding dnxhd-720p-rd.dnxhd "-threads 4 -mbd rd -s hd720 -b 90M -pix_fmt yuv422p -vframes 5 -an" ++do_video_decoding "" "-s cif -pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_dnxhd_720p_10bit" ] ; then ++do_video_encoding dnxhd-720p-10bit.dnxhd "-s hd720 -b 90M -pix_fmt yuv422p10 -vframes 5 -an" ++do_video_decoding "" "-s cif -pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_mpng" ] ; then ++do_video_encoding mpng.avi "-an -vcodec png" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_prores" ] ; then ++do_video_encoding prores.mov "-vcodec prores" ++do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_svq1" ] ; then +-do_video_encoding svq1.mov "" "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p" ++do_video_encoding svq1.mov "-an -vcodec svq1 -qscale 3 -pix_fmt yuv410p" + do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_flashsv" ] ; then +-do_video_encoding flashsv.flv "" "-an -vcodec flashsv -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact" ++do_video_encoding flashsv.flv "-an -vcodec flashsv -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact" ++do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact" ++fi ++ ++if [ -n "$do_flashsv2" ] ; then ++do_video_encoding flashsv2.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental" ++do_video_encoding flashsv2I.flv "-an -vcodec flashsv2 -sws_flags neighbor+full_chroma_int+accurate_rnd+bitexact -strict experimental -g 1" + do_video_decoding "" "-pix_fmt yuv420p -sws_flags area+accurate_rnd+bitexact" + fi + + if [ -n "$do_roq" ] ; then +-do_video_encoding roqav.roq "" "-vframes 5" ++do_video_encoding roqav.roq "-vframes 5" + do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_qtrle" ] ; then +-do_video_encoding qtrle.mov "" "" +-do_video_decoding "" "" ++do_video_encoding qtrle.mov "-an -vcodec qtrle" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_qtrlegray" ] ; then ++do_video_encoding qtrlegray.mov "-an -vcodec qtrle -pix_fmt gray" ++do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_rgb" ] ; then +-do_video_encoding rgb.avi "" "-an -vcodec rawvideo -pix_fmt bgr24" ++do_video_encoding rgb.avi "-an -vcodec rawvideo -pix_fmt bgr24" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_v210" ] ; then ++do_video_encoding v210.avi "-an -c:v v210" + do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_yuv" ] ; then +-do_video_encoding yuv.avi "" "-an -vcodec rawvideo -pix_fmt yuv420p" ++do_video_encoding yuv.avi "-an -vcodec rawvideo -pix_fmt yuv420p" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_zlib" ] ; then ++do_video_encoding zlib.avi "-an -vcodec zlib" ++do_video_decoding "" "-pix_fmt yuv420p" ++fi ++ ++if [ -n "$do_zmbv" ] ; then ++# default level of 9 leads to different results with ++# different zlib versions, and even with 0 md5 differs ++do_video_encoding_nomd5 zmbv.avi "-an -vcodec zmbv -compression_level 0" + do_video_decoding "" "-pix_fmt yuv420p" + fi + + if [ -n "$do_mp2" ] ; then +-do_audio_encoding mp2.mp2 "-ar 44100" ++do_audio_encoding mp2.mp2 + do_audio_decoding +-$tiny_psnr $pcm_dst $pcm_ref 2 1924 >> $logfile ++$tiny_psnr $pcm_dst $pcm_ref 2 1924 + fi + + if [ -n "$do_ac3_fixed" ] ; then +-do_audio_encoding ac3.rm "" "-vn -acodec ac3_fixed" ++do_audio_encoding ac3.rm "-vn -acodec ac3_fixed" + # binaries configured with --disable-sse decode ac3 differently + #do_audio_decoding +-#$tiny_psnr $pcm_dst $pcm_ref 2 1024 >> $logfile ++#$tiny_psnr $pcm_dst $pcm_ref 2 1024 ++fi ++ ++if [ -n "$do_g723_1" ] ; then ++do_audio_encoding g723_1.tco "-b:a 6.3k -ac 1 -ar 8000 -acodec g723_1" ++do_audio_decoding ++fi ++ ++if [ -n "$do_g722" ] ; then ++do_audio_encoding g722.wav "-b 64k -ac 1 -ar 16000 -acodec g722" ++do_audio_decoding + fi + + if [ -n "$do_g726" ] ; then +-do_audio_encoding g726.wav "-ar 44100" "-ab 32k -ac 1 -ar 8000 -acodec g726" ++do_audio_encoding g726.wav "-b:a 32k -ac 1 -ar 8000 -acodec g726" ++do_audio_decoding ++fi ++ ++if [ -n "$do_adpcm_adx" ] ; then ++do_audio_encoding adpcm_adx.adx "-acodec adpcm_adx" + do_audio_decoding + fi + + if [ -n "$do_adpcm_ima_wav" ] ; then +-do_audio_encoding adpcm_ima.wav "-ar 44100" "-acodec adpcm_ima_wav" ++do_audio_encoding adpcm_ima.wav "-acodec adpcm_ima_wav" + do_audio_decoding + fi + + if [ -n "$do_adpcm_ima_qt" ] ; then +-do_audio_encoding adpcm_qt.aiff "-ar 44100" "-acodec adpcm_ima_qt" ++do_audio_encoding adpcm_qt.aiff "-acodec adpcm_ima_qt" + do_audio_decoding + fi + + if [ -n "$do_adpcm_ms" ] ; then +-do_audio_encoding adpcm_ms.wav "-ar 44100" "-acodec adpcm_ms" ++do_audio_encoding adpcm_ms.wav "-acodec adpcm_ms" + do_audio_decoding + fi + + if [ -n "$do_adpcm_yam" ] ; then +-do_audio_encoding adpcm_yam.wav "-ar 44100" "-acodec adpcm_yamaha" ++do_audio_encoding adpcm_yam.wav "-acodec adpcm_yamaha" + do_audio_decoding + fi + + if [ -n "$do_adpcm_swf" ] ; then +-do_audio_encoding adpcm_swf.flv "-ar 44100" "-acodec adpcm_swf" ++do_audio_encoding adpcm_swf.flv "-acodec adpcm_swf" + do_audio_decoding + fi + + if [ -n "$do_alac" ] ; then +-do_audio_encoding alac.m4a "-ar 44100" "-acodec alac -compression_level 1" ++do_audio_encoding alac.m4a "-acodec alac -compression_level 1" + do_audio_decoding + fi + + if [ -n "$do_flac" ] ; then +-do_audio_encoding flac.flac "-ar 44100" "-acodec flac -compression_level 2" ++do_audio_encoding flac.flac "-acodec flac -compression_level 2" + do_audio_decoding + fi + + if [ -n "$do_wmav1" ] ; then +-do_audio_encoding wmav1.asf "-ar 44100" "-acodec wmav1" +-do_ffmpeg_nomd5 $pcm_dst -i $target_path/$file -f wav +-$tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile ++do_audio_encoding wmav1.asf "-acodec wmav1" ++do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav ++$tiny_psnr $pcm_dst $pcm_ref 2 8192 + fi + if [ -n "$do_wmav2" ] ; then +-do_audio_encoding wmav2.asf "-ar 44100" "-acodec wmav2" +-do_ffmpeg_nomd5 $pcm_dst -i $target_path/$file -f wav +-$tiny_psnr $pcm_dst $pcm_ref 2 8192 >> $logfile ++do_audio_encoding wmav2.asf "-acodec wmav2" ++do_avconv_nomd5 $pcm_dst $DEC_OPTS -i $target_path/$file -f wav ++$tiny_psnr $pcm_dst $pcm_ref 2 8192 + fi + + #if [ -n "$do_vorbis" ] ; then + # vorbis + #disabled because it is broken +-#do_audio_encoding vorbis.asf "-ar 44100" "-acodec vorbis" ++#do_audio_encoding vorbis.asf "-acodec vorbis" + #do_audio_decoding + #fi + + do_audio_enc_dec() { +- do_audio_encoding $3.$1 "" "$4 -sample_fmt $2 -acodec $3" ++ do_audio_encoding $3.$1 "$4 -sample_fmt $2 -acodec $3" + do_audio_decoding + } + +-if [ -n "$do_pcm" ] ; then ++if [ -n "$do_pcm_alaw" ] ; then + do_audio_enc_dec wav s16 pcm_alaw ++fi ++if [ -n "$do_pcm_mulaw" ] ; then + do_audio_enc_dec wav s16 pcm_mulaw ++fi ++if [ -n "$do_pcm_s8" ] ; then + do_audio_enc_dec mov u8 pcm_s8 ++fi ++if [ -n "$do_pcm_u8" ] ; then + do_audio_enc_dec wav u8 pcm_u8 ++fi ++if [ -n "$do_pcm_s16be" ] ; then + do_audio_enc_dec mov s16 pcm_s16be ++fi ++if [ -n "$do_pcm_s16le" ] ; then + do_audio_enc_dec wav s16 pcm_s16le +-do_audio_enc_dec mkv s16 pcm_s16be +-do_audio_enc_dec mkv s16 pcm_s16le ++fi ++if [ -n "$do_pcm_s24be" ] ; then + do_audio_enc_dec mov s32 pcm_s24be ++fi ++if [ -n "$do_pcm_s24le" ] ; then + do_audio_enc_dec wav s32 pcm_s24le +-#do_audio_enc_dec ??? s32 pcm_u24be #no compatible muxer or demuxer +-#do_audio_enc_dec ??? s32 pcm_u24le #no compatible muxer or demuxer ++fi ++# no compatible muxer or demuxer ++# if [ -n "$do_pcm_u24be" ] ; then ++# do_audio_enc_dec ??? u32 pcm_u24be ++# fi ++# if [ -n "$do_pcm_u24le" ] ; then ++# do_audio_enc_dec ??? u32 pcm_u24le ++# fi ++if [ -n "$do_pcm_s32be" ] ; then + do_audio_enc_dec mov s32 pcm_s32be ++fi ++if [ -n "$do_pcm_s32le" ] ; then + do_audio_enc_dec wav s32 pcm_s32le +-#do_audio_enc_dec ??? s32 pcm_u32be #no compatible muxer or demuxer +-#do_audio_enc_dec ??? s32 pcm_u32le #no compatible muxer or demuxer ++fi ++# no compatible muxer or demuxer ++# if [ -n "$do_pcm_u32be" ] ; then ++# do_audio_enc_dec ??? u32 pcm_u32be ++# fi ++# if [ -n "$do_pcm_u32le" ] ; then ++# do_audio_enc_dec ??? u32 pcm_u32le ++# fi ++if [ -n "$do_pcm_f32be" ] ; then + do_audio_enc_dec au flt pcm_f32be ++fi ++if [ -n "$do_pcm_f32le" ] ; then + do_audio_enc_dec wav flt pcm_f32le ++fi ++if [ -n "$do_pcm_f64be" ] ; then + do_audio_enc_dec au dbl pcm_f64be ++fi ++if [ -n "$do_pcm_f64le" ] ; then + do_audio_enc_dec wav dbl pcm_f64le +-do_audio_enc_dec wav s16 pcm_zork ++fi ++if [ -n "$do_pcm_s24daud" ] ; then + do_audio_enc_dec 302 s16 pcm_s24daud "-ac 6 -ar 96000" + fi +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/copy.regression.ref xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/copy.regression.ref +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/copy.regression.ref 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/copy.regression.ref 1970-01-01 01:00:00.000000000 +0100 +@@ -1,465 +0,0 @@ +----------------- +-./tests/data/a-ac3.rm +-first.nut second.nut differ: char 34, line 1 +-1dd5a62b7edb3a1bcf77626af0a85bc1 first.nut +----------------- +-./tests/data/a-adpcm_ima.wav +-first.nut second.nut differ: char 34, line 1 +-c95390143078f08db8a3bfba5789c2da first.nut +----------------- +-./tests/data/a-adpcm_ms.wav +-first.nut second.nut differ: char 34, line 1 +-05e4d8842f4001fed506423e1a8ef963 first.nut +----------------- +-./tests/data/a-adpcm_qt.aiff +-first.nut second.nut differ: char 34, line 1 +-7455d87f626f05e20030f4c93ec91e69 first.nut +----------------- +-./tests/data/a-adpcm_swf.flv +-c0402ee010a483403a655f353e184df1 first.nut +----------------- +-./tests/data/a-adpcm_yam.wav +-first.nut second.nut differ: char 34, line 1 +-f861047f6c6f75cdf3ce7bb78a4003ad first.nut +----------------- +-./tests/data/a-alac.m4a +-first.nut second.nut differ: char 34, line 1 +-ab152b0b01e540e74b04a807e3882083 first.nut +----------------- +-./tests/data/a-asv1.avi +-636fc0dfef1830cc51cf2c182bd4a7b2 first.nut +----------------- +-./tests/data/a-asv2.avi +-bbfc299390378c7bdbd7463434d8fcbe first.nut +----------------- +-./tests/data/a-dnxhd-1080i.mov +-first.nut second.nut differ: char 113, line 1 +-037e31900e6cdf7161c2a0df23d9dc9d first.nut +----------------- +-./tests/data/a-dnxhd-720p-rd.dnxhd +-first.nut second.nut differ: char 113, line 1 +-1237abac554ea9adb2a926641eec0de0 first.nut +----------------- +-./tests/data/a-dnxhd-720p.dnxhd +-first.nut second.nut differ: char 113, line 1 +-6694322cefa2f482bc3dac8be22eb5d5 first.nut +----------------- +-./tests/data/a-dv.dv +-1aa367a56d31bb45f98d820121820909 first.nut +----------------- +-./tests/data/a-dv411.dv +-7ef296512960e00d96850f2606b4b683 first.nut +----------------- +-./tests/data/a-dv50.dv +-6424dd39e22a1789a8182d7e8da224a9 first.nut +----------------- +-./tests/data/a-error-mpeg4-adv.avi +-715b262e3e7c9be2b59525ba0289f30e first.nut +----------------- +-./tests/data/a-ffv1.avi +-edada4da2170ffd3386636cff67a90f0 first.nut +----------------- +-./tests/data/a-flac.flac +-d5e0a6d87034c21627afb2a904412a21 first.nut +----------------- +-./tests/data/a-flashsv.flv +-985076a8a87df1f91b34cbb81ce96217 first.nut +----------------- +-./tests/data/a-flv.flv +-6d01a0eb07c15ec3d0a70bfad0615bec first.nut +----------------- +-./tests/data/a-g726.wav +-first.nut second.nut differ: char 34, line 1 +-59540b44c97b8e1eafc53ebdaeaf3eb8 first.nut +----------------- +-./tests/data/a-h261.avi +-18d47cc50e05e5c855a8aec1a5d8d9ec first.nut +----------------- +-./tests/data/a-h263.avi +-91b67a478420a30cf10c3d872f7e799b first.nut +----------------- +-./tests/data/a-h263p.avi +-1e9f108181dca2dd3bb621bb45fc5834 first.nut +----------------- +-./tests/data/a-huffyuv.avi +-62dccc2a428b561c08497f8378ea1567 first.nut +----------------- +-./tests/data/a-jpegls.avi +-35f1bb0f9b14bf3eb29134784f278c4f first.nut +----------------- +-./tests/data/a-ljpeg.avi +-45ec1072d8e55d6cfa784cc732830f3c first.nut +----------------- +-./tests/data/a-mjpeg.avi +-4e6d42fdda880661de8308cfa45652ee first.nut +----------------- +-./tests/data/a-mp2.mp2 +-6c8d1a33dd994d63c68e5c9953b5cb8c first.nut +----------------- +-./tests/data/a-mpeg1.mpg +-first.nut second.nut differ: char 34, line 1 +-9d444c67713ef70c06d35fd355200ed5 first.nut +----------------- +-./tests/data/a-mpeg1b.mpg +-first.nut second.nut differ: char 34, line 1 +-9d444c67713ef70c06d35fd355200ed5 first.nut +----------------- +-./tests/data/a-mpeg2.mpg +-first.nut second.nut differ: char 34, line 1 +-328f6a0069b76397c5ed0dcea8b69b50 first.nut +----------------- +-./tests/data/a-mpeg2.mpg +-first.nut second.nut differ: char 34, line 1 +-328f6a0069b76397c5ed0dcea8b69b50 first.nut +----------------- +-./tests/data/a-mpeg2_422.mpg +-first.nut second.nut differ: char 34, line 1 +-d27035bcf30801cd1bee6ac59e8f5e3e first.nut +----------------- +-./tests/data/a-mpeg2i.mpg +-first.nut second.nut differ: char 34, line 1 +-c3351b79649825a6b9f62a2a1db633c1 first.nut +----------------- +-./tests/data/a-mpeg2ivlc-qprd.mpg +-first.nut second.nut differ: char 34, line 1 +-d910da52fa10eb1deca10fa9443132d2 first.nut +----------------- +-./tests/data/a-mpeg2reuse.mpg +-first.nut second.nut differ: char 34, line 1 +-c3351b79649825a6b9f62a2a1db633c1 first.nut +----------------- +-./tests/data/a-mpeg2thread.mpg +-first.nut second.nut differ: char 34, line 1 +-c3351b79649825a6b9f62a2a1db633c1 first.nut +----------------- +-./tests/data/a-mpeg2threadivlc.mpg +-first.nut second.nut differ: char 34, line 1 +-c3351b79649825a6b9f62a2a1db633c1 first.nut +----------------- +-./tests/data/a-mpeg4-Q.avi +-first.nut second.nut differ: char 34, line 1 +-305bab90451e2c3b741e3aef51bc2a4c first.nut +----------------- +-./tests/data/a-mpeg4-adap.avi +-first.nut second.nut differ: char 34, line 1 +-5d9315ec49c4122f6f23cf84cab5fc53 first.nut +----------------- +-./tests/data/a-mpeg4-adv.avi +-5d672bf4c2e879d6a20e349cb4dc09a6 first.nut +----------------- +-./tests/data/a-mpeg4-nr.avi +-0243b2e03115fe948f99da1ee10ae588 first.nut +----------------- +-./tests/data/a-mpeg4-qprd.avi +-first.nut second.nut differ: char 34, line 1 +-5d9315ec49c4122f6f23cf84cab5fc53 first.nut +----------------- +-./tests/data/a-mpeg4-rc.avi +-first.nut second.nut differ: char 34, line 1 +-5d9315ec49c4122f6f23cf84cab5fc53 first.nut +----------------- +-./tests/data/a-mpeg4-thread.avi +-first.nut second.nut differ: char 34, line 1 +-6aa94d589e9e7626e51575d8a2aec6e7 first.nut +----------------- +-./tests/data/a-msmpeg4.avi +-836d432509ff22fd363237ef1dced5f3 first.nut +----------------- +-./tests/data/a-msmpeg4v2.avi +-37f253da3666fb057edecb86ed2dba39 first.nut +----------------- +-./tests/data/a-odivx.mp4 +-e3bd9d8a3417abc749c489e64119dbf3 first.nut +----------------- +-./tests/data/a-pcm_alaw.wav +-first.nut second.nut differ: char 34, line 1 +-22853e7806b0f0162fd5e2573e34b03c first.nut +----------------- +-./tests/data/a-pcm_f32be.au +-first.nut second.nut differ: char 34, line 1 +-94cb60c3107ec509af79191e86099a0e first.nut +----------------- +-./tests/data/a-pcm_f32le.wav +-first.nut second.nut differ: char 34, line 1 +-8d887b27a8531390af5b682557631986 first.nut +----------------- +-./tests/data/a-pcm_f64be.au +-first.nut second.nut differ: char 34, line 1 +-e0c7b64e13bb9398a57dac60806515fb first.nut +----------------- +-./tests/data/a-pcm_f64le.wav +-first.nut second.nut differ: char 34, line 1 +-9dbb9bda0c990502e910e082a008433f first.nut +----------------- +-./tests/data/a-pcm_mulaw.wav +-first.nut second.nut differ: char 34, line 1 +-78c4aae32fdddaba4f9caa5683018c94 first.nut +----------------- +-./tests/data/a-pcm_s16be.mkv +-first.nut second.nut differ: char 34, line 1 +-279810a0c30a06c4ab7de154e3de140d first.nut +----------------- +-./tests/data/a-pcm_s16be.mov +-first.nut second.nut differ: char 42, line 1 +-0a8ede3d121f17a98e9038771eb98e1a first.nut +----------------- +-./tests/data/a-pcm_s16le.mkv +-47942f5188f8d081bcbe7fb82550b135 first.nut +----------------- +-./tests/data/a-pcm_s16le.wav +-first.nut second.nut differ: char 34, line 1 +-9f868acb99ba107750f165431f95c382 first.nut +----------------- +-./tests/data/a-pcm_s24be.mov +-first.nut second.nut differ: char 34, line 1 +-9c96762f631851014dec14b506091cc1 first.nut +----------------- +-./tests/data/a-pcm_s24daud.302 +-60ecb7037b205e2013490fdadab9697b first.nut +----------------- +-./tests/data/a-pcm_s24le.wav +-first.nut second.nut differ: char 34, line 1 +-5805a2e6e2eddede4757fd488d0d6adb first.nut +----------------- +-./tests/data/a-pcm_s32be.mov +-first.nut second.nut differ: char 34, line 1 +-d6c868a1130be573bbe0cfc88913a60c first.nut +----------------- +-./tests/data/a-pcm_s32le.wav +-first.nut second.nut differ: char 34, line 1 +-3e0a81669647739c490f12521f897527 first.nut +----------------- +-./tests/data/a-pcm_s8.mov +-first.nut second.nut differ: char 34, line 1 +-a6fe0827966ee4515f27c7053d579229 first.nut +----------------- +-./tests/data/a-pcm_u8.wav +-first.nut second.nut differ: char 34, line 1 +-f0d398fd651cdedfd7b4c5433c08fd79 first.nut +----------------- +-./tests/data/a-pcm_zork.wav +-first.nut second.nut differ: char 34, line 1 +-69e40cc9266836a7101000677ee14a87 first.nut +----------------- +-./tests/data/a-roqav.roq +-first.nut second.nut differ: char 34, line 1 +-0e7a57bb28054b7e319eac2ba0a4be23 first.nut +----------------- +-./tests/data/a-rv10.rm +-first.nut second.nut differ: char 34, line 1 +-80f982c6bffea91ff45a9b320cb93c14 first.nut +----------------- +-./tests/data/a-rv20.rm +-first.nut second.nut differ: char 34, line 1 +-5b02113c0941578ca6918215eed8a728 first.nut +----------------- +-./tests/data/a-snow.avi +-e73b88690aa491491ede5970641134ad first.nut +----------------- +-./tests/data/a-snow53.avi +-18a6b061252c8c74bd22b42a7d5b2bae first.nut +----------------- +-./tests/data/a-svq1.mov +-first.nut second.nut differ: char 197, line 1 +-6bbe90d47c1763654e8388ce51ab911e first.nut +----------------- +-./tests/data/a-wmav1.asf +-first.nut second.nut differ: char 34, line 1 +-c3f7bc239ff166d738b29252b47bd437 first.nut +----------------- +-./tests/data/a-wmav2.asf +-first.nut second.nut differ: char 34, line 1 +-930f1824b9677f0b6b714f1c6ddcf825 first.nut +----------------- +-./tests/data/a-wmv1.avi +-206bd9985b575f61a8a580656af39beb first.nut +----------------- +-./tests/data/a-wmv2.avi +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-bgr24.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-gray.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-monob.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-monow.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-rgb24.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-rgb32.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-rgb555.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-rgb565.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv410p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv411p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv420p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv422p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv440p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuv444p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuvj420p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuvj422p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuvj440p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuvj444p.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf-yuyv422.yuv +-09178a3c2b99d4f7ad1f7a761a2b803a first.nut +----------------- +-./tests/data/b-lavf.aif +-first.nut second.nut differ: char 34, line 1 +-3f1d3faae1671f1cf862ddb66a5c59d1 first.nut +----------------- +-./tests/data/b-lavf.al +-e6d4b977e74a535b039a6a1dfed2dbc1 first.nut +----------------- +-./tests/data/b-lavf.asf +-first.nut second.nut differ: char 34, line 1 +-57727c41b3974697c0a79cfd08515ddd first.nut +----------------- +-./tests/data/b-lavf.au +-first.nut second.nut differ: char 34, line 1 +-1da12f41bc5ea1fd851e8a48b222c204 first.nut +----------------- +-./tests/data/b-lavf.avi +-a88edf9fb8e02e658ba3cae9313a3cdc first.nut +----------------- +-./tests/data/b-lavf.dv +-first.nut second.nut differ: char 34, line 1 +-819018a5d91c55312ffe784e8712ac4b first.nut +----------------- +-./tests/data/b-lavf.ffm +-first.nut second.nut differ: char 34, line 1 +-17f8894a05c71adb51c9a0ff1b9040bb first.nut +----------------- +-./tests/data/b-lavf.flv +-d74edb56e74e0eea748863f3aeeafa61 first.nut +----------------- +-./tests/data/b-lavf.gif +-first.nut second.nut differ: char 34, line 1 +-ef9ba6bf88f44d9d326049ef2872a4d3 first.nut +----------------- +-./tests/data/b-lavf.gxf +-first.nut second.nut differ: char 44, line 1 +-522957f46ba46051fd03a0868c905e54 first.nut +----------------- +-./tests/data/b-lavf.mkv +-8c9427bb75c96210d6580d9b881d9e4d first.nut +----------------- +-./tests/data/b-lavf.mmf +-first.nut second.nut differ: char 42, line 1 +-298136aef02389fc5b0844995fe6ac72 first.nut +----------------- +-./tests/data/b-lavf.mov +-ce895b33ff206fafbae89fd5a8f959d2 first.nut +----------------- +-./tests/data/b-lavf.mpg +-d279e3343993267241c2fac4f4563cdb first.nut +----------------- +-./tests/data/b-lavf.mxf +-first.nut second.nut differ: char 34, line 1 +-3e98a90d40986b8ea4305be06175927a first.nut +----------------- +-./tests/data/b-lavf.mxf_d10 +-1ee69644165344a096ddfaaac951a0e9 first.nut +----------------- +-./tests/data/b-lavf.nut +-1426bca4c65796516a3e94b6bebc5a58 first.nut +----------------- +-./tests/data/b-lavf.ogg +-c986ce79045f2068ae1bedc2b8702884 first.nut +----------------- +-./tests/data/b-lavf.rm +-first.nut second.nut differ: char 34, line 1 +-a3b2c9d3ec2c86b6d4c3bf0ed91391c3 first.nut +----------------- +-./tests/data/b-lavf.swf +-first.nut second.nut differ: char 34, line 1 +-d4a5c5e6343dc17bed49397d889e0799 first.nut +----------------- +-./tests/data/b-lavf.ts +-40fd2ece0c8386d3a250943eab023795 first.nut +----------------- +-./tests/data/b-lavf.ul +-1c4c747e2e9c0fd195656359341eef76 first.nut +----------------- +-./tests/data/b-lavf.voc +-first.nut second.nut differ: char 42, line 1 +-500ef42830c5bc2af849dbdcc4380f1b first.nut +----------------- +-./tests/data/b-lavf.wav +-first.nut second.nut differ: char 42, line 1 +-8d4c6a79af442610ad912625c9b85d02 first.nut +----------------- +-./tests/data/b-lavf.y4m +-f42a6ff4488de306925b057ecee75b0e first.nut +----------------- +-./tests/data/b-lavf02.bmp +-first.nut second.nut differ: char 113, line 1 +-02e3c782ef3a0c96e820201d4d4b8268 first.nut +----------------- +-./tests/data/b-lavf02.jpg +-61a19c3012a5aa056d8e9a589e29de2e first.nut +----------------- +-./tests/data/b-lavf02.pcx +-first.nut second.nut differ: char 113, line 1 +-3c4e1b9c8d5dd2bedb8eebd1edc7a2f5 first.nut +----------------- +-./tests/data/b-lavf02.pgm +-first.nut second.nut differ: char 113, line 1 +-cc36bdadd7aef501a6d5d588dec2188b first.nut +----------------- +-./tests/data/b-lavf02.ppm +-first.nut second.nut differ: char 113, line 1 +-453ec690bea6c3668e2b65e0b7ad14c8 first.nut +----------------- +-./tests/data/b-lavf02.sgi +-first.nut second.nut differ: char 113, line 1 +-6cdadd58aaa5ad196697352e96723e52 first.nut +----------------- +-./tests/data/b-lavf02.tga +-4144d2b4ee2948c1a16f7fc31b381be3 first.nut +----------------- +-./tests/data/b-lavf02.tiff +-first.nut second.nut differ: char 113, line 1 +-237fa2da2d5f4930dae9825c9cf928a6 first.nut +----------------- +-./tests/data/b-pbmpipe.pbm +-first.nut second.nut differ: char 113, line 1 +-2c65ef7188398da8a5f107b9dd5fb998 first.nut +----------------- +-./tests/data/b-pgmpipe.pgm +-first.nut second.nut differ: char 113, line 1 +-b7e98248ada1e6f7170bc7fedee3825c first.nut +----------------- +-./tests/data/b-ppmpipe.ppm +-first.nut second.nut differ: char 113, line 1 +-869fcefe430c35a9a8e46fd5f040b62e first.nut +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/aac.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/aac.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/aac.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/aac.mak 2012-05-14 14:08:55.568364818 +0200 +@@ -2,22 +2,75 @@ + fate-aac-al04_44: CMD = pcm -i $(SAMPLES)/aac/al04_44.mp4 + fate-aac-al04_44: REF = $(SAMPLES)/aac/al04_44.s16 + ++FATE_AAC += fate-aac-al05_44 ++fate-aac-al05_44: CMD = pcm -i $(SAMPLES)/aac/al05_44.mp4 ++fate-aac-al05_44: REF = $(SAMPLES)/aac/al05_44.s16 ++ ++FATE_AAC += fate-aac-al06_44 ++fate-aac-al06_44: CMD = pcm -i $(SAMPLES)/aac/al06_44.mp4 ++fate-aac-al06_44: REF = $(SAMPLES)/aac/al06_44.s16 ++ + FATE_AAC += fate-aac-al07_96 + fate-aac-al07_96: CMD = pcm -i $(SAMPLES)/aac/al07_96.mp4 + fate-aac-al07_96: REF = $(SAMPLES)/aac/al07_96.s16 + ++FATE_AAC += fate-aac-al15_44 ++fate-aac-al15_44: CMD = pcm -i $(SAMPLES)/aac/al15_44.mp4 ++fate-aac-al15_44: REF = $(SAMPLES)/aac/al15_44.s16 ++ ++FATE_AAC += fate-aac-al17_44 ++fate-aac-al17_44: CMD = pcm -i $(SAMPLES)/aac/al17_44.mp4 ++fate-aac-al17_44: REF = $(SAMPLES)/aac/al17_44.s16 ++ ++FATE_AAC += fate-aac-al18_44 ++fate-aac-al18_44: CMD = pcm -i $(SAMPLES)/aac/al18_44.mp4 ++fate-aac-al18_44: REF = $(SAMPLES)/aac/al18_44.s16 ++ + FATE_AAC += fate-aac-am00_88 + fate-aac-am00_88: CMD = pcm -i $(SAMPLES)/aac/am00_88.mp4 + fate-aac-am00_88: REF = $(SAMPLES)/aac/am00_88.s16 + ++FATE_AAC += fate-aac-am05_44 ++fate-aac-am05_44: CMD = pcm -i $(SAMPLES)/aac/am05_44.mp4 ++fate-aac-am05_44: REF = $(SAMPLES)/aac/am05_44.s16 ++ + FATE_AAC += fate-aac-al_sbr_hq_cm_48_2 + fate-aac-al_sbr_hq_cm_48_2: CMD = pcm -i $(SAMPLES)/aac/al_sbr_cm_48_2.mp4 + fate-aac-al_sbr_hq_cm_48_2: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_2.s16 + ++FATE_AAC += fate-aac-al_sbr_hq_cm_48_5.1 ++fate-aac-al_sbr_hq_cm_48_5.1: CMD = pcm -i $(SAMPLES)/aac/al_sbr_cm_48_5.1.mp4 ++fate-aac-al_sbr_hq_cm_48_5.1: REF = $(SAMPLES)/aac/al_sbr_hq_cm_48_5.1.s16 ++ + FATE_AAC += fate-aac-al_sbr_ps_06_ur + fate-aac-al_sbr_ps_06_ur: CMD = pcm -i $(SAMPLES)/aac/al_sbr_ps_06_new.mp4 + fate-aac-al_sbr_ps_06_ur: REF = $(SAMPLES)/aac/al_sbr_ps_06_ur.s16 + ++FATE_AAC += fate-aac-latm_000000001180bc60 ++fate-aac-latm_000000001180bc60: CMD = pcm -i $(SAMPLES)/aac/latm_000000001180bc60.mpg ++fate-aac-latm_000000001180bc60: REF = $(SAMPLES)/aac/latm_000000001180bc60.s16 ++ ++FATE_AAC += fate-aac-ap05_48 ++fate-aac-ap05_48: CMD = pcm -i $(SAMPLES)/aac/ap05_48.mp4 ++fate-aac-ap05_48: REF = $(SAMPLES)/aac/ap05_48.s16 ++ ++FATE_AAC += fate-aac-latm_stereo_to_51 ++fate-aac-latm_stereo_to_51: CMD = pcm -i $(SAMPLES)/aac/latm_stereo_to_51.ts -ac 6 ++fate-aac-latm_stereo_to_51: REF = $(SAMPLES)/aac/latm_stereo_to_51.s16 ++ ++fate-aac-ct%: CMD = pcm -i $(SAMPLES)/aac/CT_DecoderCheck/$(@:fate-aac-ct-%=%) ++fate-aac-ct%: REF = $(SAMPLES)/aac/CT_DecoderCheck/aacPlusv2.wav ++ ++FATE_AAC_CT = sbr_bc-ps_i.3gp \ ++ sbr_bic-ps_i.3gp \ ++ sbr_i-ps_i.aac \ ++ sbr_bc-ps_bc.mp4 \ ++ sbr_bc-ps_i.mp4 \ ++ sbr_i-ps_bic.mp4 \ ++ sbr_i-ps_i.mp4 ++ ++FATE_AAC += $(FATE_AAC_CT:%=fate-aac-ct-%) ++ + FATE_TESTS += $(FATE_AAC) + fate-aac: $(FATE_AAC) + $(FATE_AAC): CMP = oneoff +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/ac3.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/ac3.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/ac3.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/ac3.mak 2012-05-14 14:08:55.571364878 +0200 +@@ -0,0 +1,32 @@ ++FATE_AC3 += fate-ac3-2.0 ++fate-ac3-2.0: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3 ++fate-ac3-2.0: CMP = oneoff ++fate-ac3-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small.pcm ++ ++FATE_AC3 += fate-ac3-5.1 ++fate-ac3-5.1: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 ++fate-ac3-5.1: CMP = oneoff ++fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small.pcm ++ ++FATE_AC3 += fate-eac3-1 ++fate-eac3-1: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.eac3 ++fate-eac3-1: CMP = oneoff ++fate-eac3-1: REF = $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.pcm ++ ++FATE_AC3 += fate-eac3-2 ++fate-eac3-2: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.eac3 ++fate-eac3-2: CMP = oneoff ++fate-eac3-2: REF = $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.pcm ++ ++FATE_AC3 += fate-eac3-3 ++fate-eac3-3: CMD = pcm -i $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.eac3 ++fate-eac3-3: CMP = oneoff ++fate-eac3-3: REF = $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.pcm ++ ++FATE_AC3 += fate-eac3-4 ++fate-eac3-4: CMD = pcm -i $(SAMPLES)/eac3/serenity_english_5.1_1536_small.eac3 ++fate-eac3-4: CMP = oneoff ++fate-eac3-4: REF = $(SAMPLES)/eac3/serenity_english_5.1_1536_small.pcm ++ ++FATE_TESTS += $(FATE_AC3) ++fate-ac3: $(FATE_AC3) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/adpcm.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/adpcm.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/adpcm.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/adpcm.mak 2012-05-14 14:08:55.572364898 +0200 +@@ -0,0 +1,44 @@ ++FATE_ADPCM += fate-adpcm-ea-r2 ++fate-adpcm-ea-r2: CMD = crc -i $(SAMPLES)/ea-mpc/THX_logo.mpc -vn ++ ++FATE_ADPCM += fate-adpcm-ea-r3 ++fate-adpcm-ea-r3: CMD = crc -i $(SAMPLES)/ea-vp6/THX_logo.vp6 -vn ++ ++FATE_ADPCM += fate-adpcm-creative ++fate-adpcm-creative: CMD = md5 -i $(SAMPLES)/creative/intro-partial.wav -f s16le ++ ++FATE_ADPCM += fate-adpcm-creative-8-2bit ++fate-adpcm-creative-8-2bit: CMD = md5 -i $(SAMPLES)/creative/BBC_2BIT.VOC -f s16le ++ ++FATE_ADPCM += fate-adpcm-creative-8-2.6bit ++fate-adpcm-creative-8-2.6bit: CMD = md5 -i $(SAMPLES)/creative/BBC_3BIT.VOC -f s16le ++ ++FATE_ADPCM += fate-adpcm-creative-8-4bit ++fate-adpcm-creative-8-4bit: CMD = md5 -i $(SAMPLES)/creative/BBC_4BIT.VOC -f s16le ++ ++FATE_ADPCM += fate-adpcm-ea-mad-ea-r1 ++fate-adpcm-ea-mad-ea-r1: CMD = framecrc -i $(SAMPLES)/ea-mad/NFS6LogoE.mad ++ ++FATE_ADPCM += fate-adpcm-ea-tqi ++fate-adpcm-ea-tqi: CMD = framecrc -i $(SAMPLES)/ea-wve/networkBackbone-partial.wve -frames:v 26 ++ ++FATE_ADPCM += fate-adpcm-ima-dk3 ++fate-adpcm-ima-dk3: CMD = md5 -i $(SAMPLES)/duck/sop-audio-only.avi -f s16le ++ ++FATE_ADPCM += fate-adpcm-ima-dk4 ++fate-adpcm-ima-dk4: CMD = md5 -i $(SAMPLES)/duck/salsa-audio-only.avi -f s16le ++ ++FATE_ADPCM += fate-adpcm-ima_wav-stereo ++fate-adpcm-ima_wav-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms11.mov -f s16le ++ ++FATE_ADPCM += fate-adpcm-psx-str-v3 ++fate-adpcm-psx-str-v3: CMD = framecrc -i $(SAMPLES)/psx-str/abc000_cut.str -vn ++ ++FATE_ADPCM += fate-adpcm-thp ++fate-adpcm-thp: CMD = framecrc -idct simple -i $(SAMPLES)/thp/pikmin2-opening1-partial.thp ++ ++FATE_ADPCM += fate-adpcm_ms-stereo ++fate-adpcm_ms-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms02.mov -f s16le ++ ++FATE_TESTS += $(FATE_ADPCM) ++fate-adpcm: $(FATE_ADPCM) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/amrnb.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/amrnb.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/amrnb.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/amrnb.mak 2012-05-14 14:08:55.572364898 +0200 +@@ -0,0 +1,50 @@ ++FATE_AMRNB += fate-amrnb-4k75 ++fate-amrnb-4k75: CMD = pcm -i $(SAMPLES)/amrnb/4.75k.amr ++fate-amrnb-4k75: CMP = stddev ++fate-amrnb-4k75: REF = $(SAMPLES)/amrnb/4.75k.pcm ++fate-amrnb-4k75: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-5k15 ++fate-amrnb-5k15: CMD = pcm -i $(SAMPLES)/amrnb/5.15k.amr ++fate-amrnb-5k15: CMP = stddev ++fate-amrnb-5k15: REF = $(SAMPLES)/amrnb/5.15k.pcm ++fate-amrnb-5k15: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-5k9 ++fate-amrnb-5k9: CMD = pcm -i $(SAMPLES)/amrnb/5.9k.amr ++fate-amrnb-5k9: CMP = stddev ++fate-amrnb-5k9: REF = $(SAMPLES)/amrnb/5.9k.pcm ++fate-amrnb-5k9: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-6k7 ++fate-amrnb-6k7: CMD = pcm -i $(SAMPLES)/amrnb/6.7k.amr ++fate-amrnb-6k7: CMP = stddev ++fate-amrnb-6k7: REF = $(SAMPLES)/amrnb/6.7k.pcm ++fate-amrnb-6k7: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-7k4 ++fate-amrnb-7k4: CMD = pcm -i $(SAMPLES)/amrnb/7.4k.amr ++fate-amrnb-7k4: CMP = stddev ++fate-amrnb-7k4: REF = $(SAMPLES)/amrnb/7.4k.pcm ++fate-amrnb-7k4: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-7k95 ++fate-amrnb-7k95: CMD = pcm -i $(SAMPLES)/amrnb/7.95k.amr ++fate-amrnb-7k95: CMP = stddev ++fate-amrnb-7k95: REF = $(SAMPLES)/amrnb/7.95k.pcm ++fate-amrnb-7k95: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-10k2 ++fate-amrnb-10k2: CMD = pcm -i $(SAMPLES)/amrnb/10.2k.amr ++fate-amrnb-10k2: CMP = stddev ++fate-amrnb-10k2: REF = $(SAMPLES)/amrnb/10.2k.pcm ++fate-amrnb-10k2: FUZZ = 1 ++ ++FATE_AMRNB += fate-amrnb-12k2 ++fate-amrnb-12k2: CMD = pcm -i $(SAMPLES)/amrnb/12.2k.amr ++fate-amrnb-12k2: CMP = stddev ++fate-amrnb-12k2: REF = $(SAMPLES)/amrnb/12.2k.pcm ++fate-amrnb-12k2: FUZZ = 1 ++ ++FATE_TESTS += $(FATE_AMRNB) ++fate-amrnb: $(FATE_AMRNB) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/amrwb.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/amrwb.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/amrwb.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/amrwb.mak 2012-05-14 14:08:55.573364918 +0200 +@@ -0,0 +1,62 @@ ++FATE_AMRWB += fate-amrwb-6k60 ++fate-amrwb-6k60: CMD = pcm -i $(SAMPLES)/amrwb/seed-6k60.awb ++fate-amrwb-6k60: CMP = stddev ++fate-amrwb-6k60: REF = $(SAMPLES)/amrwb/seed-6k60.pcm ++fate-amrwb-6k60: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-8k85 ++fate-amrwb-8k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-8k85.awb ++fate-amrwb-8k85: CMP = stddev ++fate-amrwb-8k85: REF = $(SAMPLES)/amrwb/seed-8k85.pcm ++fate-amrwb-8k85: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-12k65 ++fate-amrwb-12k65: CMD = pcm -i $(SAMPLES)/amrwb/seed-12k65.awb ++fate-amrwb-12k65: CMP = stddev ++fate-amrwb-12k65: REF = $(SAMPLES)/amrwb/seed-12k65.pcm ++fate-amrwb-12k65: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-14k25 ++fate-amrwb-14k25: CMD = pcm -i $(SAMPLES)/amrwb/seed-14k25.awb ++fate-amrwb-14k25: CMP = stddev ++fate-amrwb-14k25: REF = $(SAMPLES)/amrwb/seed-14k25.pcm ++fate-amrwb-14k25: FUZZ = 2.6 ++ ++FATE_AMRWB += fate-amrwb-15k85 ++fate-amrwb-15k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-15k85.awb ++fate-amrwb-15k85: CMP = stddev ++fate-amrwb-15k85: REF = $(SAMPLES)/amrwb/seed-15k85.pcm ++fate-amrwb-15k85: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-18k25 ++fate-amrwb-18k25: CMD = pcm -i $(SAMPLES)/amrwb/seed-18k25.awb ++fate-amrwb-18k25: CMP = stddev ++fate-amrwb-18k25: REF = $(SAMPLES)/amrwb/seed-18k25.pcm ++fate-amrwb-18k25: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-19k85 ++fate-amrwb-19k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-19k85.awb ++fate-amrwb-19k85: CMP = stddev ++fate-amrwb-19k85: REF = $(SAMPLES)/amrwb/seed-19k85.pcm ++fate-amrwb-19k85: FUZZ = 1 ++ ++FATE_AMRWB += fate-amrwb-23k05 ++fate-amrwb-23k05: CMD = pcm -i $(SAMPLES)/amrwb/seed-23k05.awb ++fate-amrwb-23k05: CMP = stddev ++fate-amrwb-23k05: REF = $(SAMPLES)/amrwb/seed-23k05.pcm ++fate-amrwb-23k05: FUZZ = 2 ++ ++FATE_AMRWB += fate-amrwb-23k85 ++fate-amrwb-23k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-23k85.awb ++fate-amrwb-23k85: CMP = stddev ++fate-amrwb-23k85: REF = $(SAMPLES)/amrwb/seed-23k85.pcm ++fate-amrwb-23k85: FUZZ = 2 ++ ++FATE_AMRWB += fate-amrwb-23k85-2 ++fate-amrwb-23k85-2: CMD = pcm -i $(SAMPLES)/amrwb/deus-23k85.awb ++fate-amrwb-23k85-2: CMP = stddev ++fate-amrwb-23k85-2: REF = $(SAMPLES)/amrwb/deus-23k85.pcm ++fate-amrwb-23k85-2: FUZZ = 1 ++ ++FATE_TESTS += $(FATE_AMRWB) ++fate-amrwb: $(FATE_AMRWB) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/atrac.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/atrac.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/atrac.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/atrac.mak 2012-05-14 14:08:55.573364918 +0200 +@@ -0,0 +1,22 @@ ++FATE_ATRAC += fate-atrac1 ++fate-atrac1: CMD = pcm -i $(SAMPLES)/atrac1/test_tones_small.aea ++fate-atrac1: CMP = oneoff ++fate-atrac1: REF = $(SAMPLES)/atrac1/test_tones_small.pcm ++ ++FATE_ATRAC += fate-atrac3-1 ++fate-atrac3-1: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_066_small.wav ++fate-atrac3-1: CMP = oneoff ++fate-atrac3-1: REF = $(SAMPLES)/atrac3/mc_sich_at3_066_small.pcm ++ ++FATE_ATRAC += fate-atrac3-2 ++fate-atrac3-2: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_105_small.wav ++fate-atrac3-2: CMP = oneoff ++fate-atrac3-2: REF = $(SAMPLES)/atrac3/mc_sich_at3_105_small.pcm ++ ++FATE_ATRAC += fate-atrac3-3 ++fate-atrac3-3: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_132_small.wav ++fate-atrac3-3: CMP = oneoff ++fate-atrac3-3: REF = $(SAMPLES)/atrac3/mc_sich_at3_132_small.pcm ++ ++FATE_TESTS += $(FATE_ATRAC) ++fate-atrac: $(FATE_ATRAC) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/audio.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/audio.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/audio.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/audio.mak 2012-05-14 14:08:55.574364938 +0200 +@@ -0,0 +1,35 @@ ++FATE_BINKAUDIO += fate-binkaudio-dct ++fate-binkaudio-dct: CMD = pcm -i $(SAMPLES)/bink/binkaudio_dct.bik ++fate-binkaudio-dct: CMP = oneoff ++fate-binkaudio-dct: REF = $(SAMPLES)/bink/binkaudio_dct.pcm ++fate-binkaudio-dct: FUZZ = 2 ++ ++FATE_BINKAUDIO += fate-binkaudio-rdft ++fate-binkaudio-rdft: CMD = pcm -i $(SAMPLES)/bink/binkaudio_rdft.bik ++fate-binkaudio-rdft: CMP = oneoff ++fate-binkaudio-rdft: REF = $(SAMPLES)/bink/binkaudio_rdft.pcm ++fate-binkaudio-rdft: FUZZ = 2 ++ ++FATE_AUDIO += $(FATE_BINKAUDIO) ++fate-binkaudio: $(FATE_BINKAUDIO) ++ ++FATE_AUDIO += fate-dts ++fate-dts: CMD = pcm -i $(SAMPLES)/dts/dts.ts ++fate-dts: CMP = oneoff ++fate-dts: REF = $(SAMPLES)/dts/dts.pcm ++ ++FATE_AUDIO += fate-imc ++fate-imc: CMD = pcm -i $(SAMPLES)/imc/imc.avi ++fate-imc: CMP = oneoff ++fate-imc: REF = $(SAMPLES)/imc/imc.pcm ++ ++FATE_AUDIO += fate-nellymoser ++fate-nellymoser: CMD = pcm -i $(SAMPLES)/nellymoser/nellymoser.flv ++fate-nellymoser: CMP = oneoff ++fate-nellymoser: REF = $(SAMPLES)/nellymoser/nellymoser.pcm ++ ++FATE_AUDIO += fate-ws_snd ++fate-ws_snd: CMD = md5 -i $(SAMPLES)/vqa/ws_snd.vqa -f s16le ++ ++FATE_TESTS += $(FATE_AUDIO) ++fate-audio: $(FATE_AUDIO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dct.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dct.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dct.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dct.mak 2012-05-14 14:08:55.574364938 +0200 +@@ -0,0 +1,5 @@ ++FATE_TESTS += fate-idct8x8 ++fate-idct8x8: libavcodec/dct-test$(EXESUF) ++fate-idct8x8: CMD = run libavcodec/dct-test -i ++fate-idct8x8: REF = /dev/null ++fate-idct8x8: CMP = null +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/demux.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/demux.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/demux.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/demux.mak 2012-05-14 14:08:55.575364958 +0200 +@@ -0,0 +1,92 @@ ++FATE_DEMUX += fate-adts-demux ++fate-adts-demux: CMD = crc -i $(SAMPLES)/aac/ct_faac-adts.aac -acodec copy ++ ++FATE_DEMUX += fate-aea-demux ++fate-aea-demux: CMD = crc -i $(SAMPLES)/aea/chirp.aea -acodec copy ++ ++FATE_DEMUX += fate-bink-demux ++fate-bink-demux: CMD = crc -i $(SAMPLES)/bink/Snd0a7d9b58.dee -vn -acodec copy ++ ++FATE_DEMUX += fate-bmv ++fate-bmv: CMD = framecrc -i $(SAMPLES)/bmv/SURFING-partial.BMV -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-caf ++fate-caf: CMD = crc -i $(SAMPLES)/caf/caf-pcm16.caf ++ ++FATE_DEMUX += fate-cryo-apc ++fate-cryo-apc: CMD = md5 -i $(SAMPLES)/cryo-apc/cine007.APC -f s16le ++ ++FATE_DEMUX += fate-d-cinema-demux ++fate-d-cinema-demux: CMD = framecrc -i $(SAMPLES)/d-cinema/THX_Science_FLT_1920-partial.302 -acodec copy -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-funcom-iss ++fate-funcom-iss: CMD = md5 -i $(SAMPLES)/funcom-iss/0004010100.iss -f s16le ++ ++FATE_DEMUX += fate-interplay-mve-16bit ++fate-interplay-mve-16bit: CMD = framecrc -i $(SAMPLES)/interplay-mve/descent3-level5-16bit-partial.mve -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-interplay-mve-8bit ++fate-interplay-mve-8bit: CMD = framecrc -i $(SAMPLES)/interplay-mve/interplay-logo-2MB.mve -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-iv8-demux ++fate-iv8-demux: CMD = framecrc -i $(SAMPLES)/iv8/zzz-partial.mpg -vsync 0 -vcodec copy ++ ++FATE_DEMUX += fate-lmlm4-demux ++fate-lmlm4-demux: CMD = framecrc -i $(SAMPLES)/lmlm4/LMLM4_CIFat30fps.divx -t 3 -acodec copy -vcodec copy ++ ++FATE_DEMUX += fate-maxis-xa ++fate-maxis-xa: CMD = md5 -i $(SAMPLES)/maxis-xa/SC2KBUG.XA -f s16le ++ ++FATE_DEMUX += fate-mtv ++fate-mtv: CMD = framecrc -i $(SAMPLES)/mtv/comedian_auto-partial.mtv -acodec copy -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-mxf-demux ++fate-mxf-demux: CMD = framecrc -i $(SAMPLES)/mxf/C0023S01.mxf -acodec copy -vcodec copy ++ ++FATE_DEMUX += fate-nc-demux ++fate-nc-demux: CMD = framecrc -i $(SAMPLES)/nc-camera/nc-sample-partial -vcodec copy ++ ++FATE_DEMUX += fate-nsv-demux ++fate-nsv-demux: CMD = framecrc -i $(SAMPLES)/nsv/witchblade-51kbps.nsv -t 6 -vcodec copy -acodec copy ++ ++FATE_DEMUX += fate-oma-demux ++fate-oma-demux: CMD = crc -i $(SAMPLES)/oma/01-Untitled-partial.oma -acodec copy ++ ++FATE_DEMUX += fate-psx-str ++fate-psx-str: CMD = framecrc -i $(SAMPLES)/psx-str/descent-partial.str ++ ++FATE_DEMUX += fate-psx-str-v3-mdec ++fate-psx-str-v3-mdec: CMD = framecrc -i $(SAMPLES)/psx-str/abc000_cut.str -an ++ ++FATE_DEMUX += fate-pva-demux ++fate-pva-demux: CMD = framecrc -idct simple -i $(SAMPLES)/pva/PVA_test-partial.pva -t 0.6 -acodec copy ++ ++FATE_DEMUX += fate-qcp-demux ++fate-qcp-demux: CMD = crc -i $(SAMPLES)/qcp/0036580847.QCP -acodec copy ++ ++FATE_DEMUX += fate-redcode-demux ++fate-redcode-demux: CMD = framecrc -i $(SAMPLES)/r3d/4MB-sample.r3d -vcodec copy -acodec copy ++ ++FATE_DEMUX += fate-sierra-vmd ++fate-sierra-vmd: CMD = framecrc -i $(SAMPLES)/vmd/12.vmd -vsync 0 -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-siff ++fate-siff: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -t 3 -pix_fmt rgb24 ++ ++FATE_DEMUX += fate-smjpeg ++fate-smjpeg: CMD = framecrc -i $(SAMPLES)/smjpeg/scenwin.mjpg -vcodec copy ++ ++FATE_DEMUX += fate-westwood-aud ++fate-westwood-aud: CMD = md5 -i $(SAMPLES)/westwood-aud/excellent.aud -f s16le ++ ++FATE_DEMUX += fate-wtv-demux ++fate-wtv-demux: CMD = framecrc -i $(SAMPLES)/wtv/law-and-order-partial.wtv -vcodec copy -acodec copy ++ ++FATE_DEMUX += fate-xmv-demux ++fate-xmv-demux: CMD = framecrc -i $(SAMPLES)/xmv/logos1p.fmv -vcodec copy -acodec copy ++ ++FATE_DEMUX += fate-xwma-demux ++fate-xwma-demux: CMD = crc -i $(SAMPLES)/xwma/ergon.xwma -acodec copy ++ ++FATE_TESTS += $(FATE_DEMUX) ++fate-demux: $(FATE_DEMUX) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dfa.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dfa.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dfa.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dfa.mak 2012-05-14 14:08:55.575364958 +0200 +@@ -0,0 +1,35 @@ ++FATE_DFA += fate-dfa1 ++fate-dfa1: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0000.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa2 ++fate-dfa2: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0001.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa3 ++fate-dfa3: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0002.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa4 ++fate-dfa4: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0003.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa5 ++fate-dfa5: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0004.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa6 ++fate-dfa6: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0005.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa7 ++fate-dfa7: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0006.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa8 ++fate-dfa8: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0007.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa9 ++fate-dfa9: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0008.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa10 ++fate-dfa10: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0009.dfa -pix_fmt rgb24 ++ ++FATE_DFA += fate-dfa11 ++fate-dfa11: CMD = framecrc -i $(SAMPLES)/chronomaster-dfa/0010.dfa -pix_fmt rgb24 ++ ++FATE_TESTS += $(FATE_DFA) ++fate-dfa: $(FATE_DFA) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dpcm.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dpcm.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/dpcm.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/dpcm.mak 2012-05-14 14:08:55.575364958 +0200 +@@ -0,0 +1,11 @@ ++FATE_DPCM += fate-dpcm-idroq ++fate-dpcm-idroq: CMD = framecrc -i $(SAMPLES)/idroq/idlogo.roq ++ ++FATE_DPCM += fate-dpcm-sierra ++fate-dpcm-sierra: CMD = md5 -i $(SAMPLES)/sol/lsl7sample.sol -f s16le ++ ++FATE_DPCM += fate-dpcm-xan ++fate-dpcm-xan: CMD = md5 -i $(SAMPLES)/wc4-xan/wc4_2.avi -vn -f s16le ++ ++FATE_TESTS += $(FATE_DPCM) ++fate-dpcm: $(FATE_DPCM) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/ea.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/ea.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/ea.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/ea.mak 2012-05-14 14:08:55.576364978 +0200 +@@ -0,0 +1,20 @@ ++FATE_EA += fate-ea-cdata ++fate-ea-cdata: CMD = md5 -i $(SAMPLES)/ea-cdata/166b084d.46410f77.0009b440.24be960c.cdata -f s16le ++ ++FATE_EA += fate-ea-cmv ++fate-ea-cmv: CMD = framecrc -i $(SAMPLES)/ea-cmv/TITLE.CMV -vsync 0 -pix_fmt rgb24 ++ ++FATE_EA += fate-ea-dct ++fate-ea-dct: CMD = framecrc -idct simple -i $(SAMPLES)/ea-dct/NFS2Esprit-partial.dct ++ ++FATE_EA += fate-ea-tgq ++fate-ea-tgq: CMD = framecrc -i $(SAMPLES)/ea-tgq/v27.tgq -an ++ ++FATE_EA += fate-ea-tgv-ima-ea-eacs ++fate-ea-tgv-ima-ea-eacs: CMD = framecrc -i $(SAMPLES)/ea-tgv/INTRO8K-partial.TGV -pix_fmt rgb24 ++ ++FATE_EA += fate-ea-tgv-ima-ea-sead ++fate-ea-tgv-ima-ea-sead: CMD = framecrc -i $(SAMPLES)/ea-tgv/INTEL_S.TGV -pix_fmt rgb24 ++ ++FATE_TESTS += $(FATE_EA) ++fate-ea: $(FATE_EA) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/fft.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/fft.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/fft.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/fft.mak 2012-05-14 14:08:55.577364998 +0200 +@@ -1,35 +1,40 @@ +-FATE_FFT += fate-fft +-fate-fft: libavcodec/fft-test$(EXESUF) +-fate-fft: CMD = run libavcodec/fft-test +- +-FATE_FFT += fate-ifft +-fate-ifft: libavcodec/fft-test$(EXESUF) +-fate-ifft: CMD = run libavcodec/fft-test -i +- +-FATE_FFT += fate-mdct +-fate-mdct: libavcodec/fft-test$(EXESUF) +-fate-mdct: CMD = run libavcodec/fft-test -m +- +-FATE_FFT += fate-imdct +-fate-imdct: libavcodec/fft-test$(EXESUF) +-fate-imdct: CMD = run libavcodec/fft-test -m -i +- +-FATE_FFT += fate-rdft +-fate-rdft: libavcodec/fft-test$(EXESUF) +-fate-rdft: CMD = run libavcodec/fft-test -r +- +-FATE_FFT += fate-irdft +-fate-irdft: libavcodec/fft-test$(EXESUF) +-fate-irdft: CMD = run libavcodec/fft-test -r -i +- +-FATE_FFT += fate-dct1d +-fate-dct1d: libavcodec/fft-test$(EXESUF) +-fate-dct1d: CMD = run libavcodec/fft-test -d +- +-FATE_FFT += fate-idct1d +-fate-idct1d: libavcodec/fft-test$(EXESUF) +-fate-idct1d: CMD = run libavcodec/fft-test -d -i ++define DEF_FFT ++FATE_FFT += fate-fft-$(1) fate-ifft-$(1) \ ++ fate-mdct-$(1) fate-imdct-$(1) \ ++ fate-rdft-$(1) fate-irdft-$(1) \ ++ fate-dct1d-$(1) fate-idct1d-$(1) ++ ++fate-fft-$(N): CMD = run libavcodec/fft-test -n$(1) ++fate-ifft-$(N): CMD = run libavcodec/fft-test -n$(1) -i ++fate-mdct-$(N): CMD = run libavcodec/fft-test -n$(1) -m ++fate-imdct-$(N): CMD = run libavcodec/fft-test -n$(1) -m -i ++fate-rdft-$(N): CMD = run libavcodec/fft-test -n$(1) -r ++fate-irdft-$(N): CMD = run libavcodec/fft-test -n$(1) -r -i ++fate-dct1d-$(N): CMD = run libavcodec/fft-test -n$(1) -d ++fate-idct1d-$(N): CMD = run libavcodec/fft-test -n$(1) -d -i ++endef ++ ++$(foreach N, 4 5 6 7 8 9 10 11 12, $(eval $(call DEF_FFT,$(N)))) + +-FATE_TESTS += $(FATE_FFT) + fate-fft-test: $(FATE_FFT) ++$(FATE_FFT): libavcodec/fft-test$(EXESUF) + $(FATE_FFT): REF = /dev/null ++ ++define DEF_FFT_FIXED ++FATE_FFT_FIXED += fate-fft-fixed-$(1) fate-ifft-fixed-$(1) \ ++ fate-mdct-fixed-$(1) fate-imdct-fixed-$(1) ++ ++fate-fft-fixed-$(1): CMD = run libavcodec/fft-fixed-test -n$(1) ++fate-ifft-fixed-$(1): CMD = run libavcodec/fft-fixed-test -n$(1) -i ++fate-mdct-fixed-$(1): CMD = run libavcodec/fft-fixed-test -n$(1) -m ++fate-imdct-fixed-$(1): CMD = run libavcodec/fft-fixed-test -n$(1) -m -i ++endef ++ ++$(foreach N, 4 5 6 7 8 9 10 11 12, $(eval $(call DEF_FFT_FIXED,$(N)))) ++ ++fate-fft-fixed-test: $(FATE_FFT_FIXED) ++$(FATE_FFT_FIXED): libavcodec/fft-fixed-test$(EXESUF) ++$(FATE_FFT_FIXED): REF = /dev/null ++ ++FATE_TESTS += $(FATE_FFT) $(FATE_FFT_FIXED) ++fate-fft: $(FATE_FFT) $(FATE_FFT_FIXED) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/h264.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/h264.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/h264.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/h264.mak 2012-05-14 14:08:55.580365059 +0200 +@@ -113,6 +113,10 @@ + frext-hcafr3_hhi_a \ + frext-hcafr4_hhi_a \ + frext-hcamff1_hhi_b \ ++ frext-hi422fr10_sony_b \ ++ frext-hi422fr13_sony_b \ ++ frext-hi422fr1_sony_a \ ++ frext-hi422fr6_sony_a \ + frext-hpca_brcm_c \ + frext-hpcadq_brcm_b \ + frext-hpcafl_bcrm_c \ +@@ -127,6 +131,20 @@ + frext-hpcvflnl_bcrm_a \ + frext-hpcvmolq_brcm_b \ + frext-hpcvnl_brcm_a \ ++ frext-pph10i1_panasonic_a \ ++ frext-pph10i2_panasonic_a \ ++ frext-pph10i3_panasonic_a \ ++ frext-pph10i4_panasonic_a \ ++ frext-pph10i5_panasonic_a \ ++ frext-pph10i6_panasonic_a \ ++ frext-pph10i7_panasonic_a \ ++ frext-pph422i1_panasonic_a \ ++ frext-pph422i2_panasonic_a \ ++ frext-pph422i3_panasonic_a \ ++ frext-pph422i4_panasonic_a \ ++ frext-pph422i5_panasonic_a \ ++ frext-pph422i6_panasonic_a \ ++ frext-pph422i7_panasonic_a \ + hcbp2_hhi_a \ + hcmp1_hhi_a \ + ls_sva_d \ +@@ -168,176 +186,196 @@ + fate-h264-interlace-crop \ + fate-h264-lossless \ + fate-h264-extreme-plane-pred \ ++ fate-h264-bsf-mp4toannexb \ + + FATE_TESTS += $(FATE_H264) + fate-h264: $(FATE_H264) + +-fate-h264-conformance-aud_mw_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/AUD_MW_E.264 +-fate-h264-conformance-ba1_ft_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/BA1_FT_C.264 +-fate-h264-conformance-ba1_sony_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/BA1_Sony_D.jsv +-fate-h264-conformance-ba2_sony_f: CMD = framecrc -i $(SAMPLES)/h264-conformance/BA2_Sony_F.jsv +-fate-h264-conformance-ba3_sva_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/BA3_SVA_C.264 +-fate-h264-conformance-ba_mw_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/BA_MW_D.264 +-fate-h264-conformance-bamq1_jvc_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/BAMQ1_JVC_C.264 +-fate-h264-conformance-bamq2_jvc_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/BAMQ2_JVC_C.264 +-fate-h264-conformance-banm_mw_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/BANM_MW_D.264 +-fate-h264-conformance-basqp1_sony_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/BASQP1_Sony_C.jsv +-fate-h264-conformance-caba1_sony_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/CABA1_Sony_D.jsv +-fate-h264-conformance-caba1_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CABA1_SVA_B.264 +-fate-h264-conformance-caba2_sony_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CABA2_Sony_E.jsv +-fate-h264-conformance-caba2_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CABA2_SVA_B.264 +-fate-h264-conformance-caba3_sony_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABA3_Sony_C.jsv +-fate-h264-conformance-caba3_sva_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABA3_SVA_B.264 +-fate-h264-conformance-caba3_toshiba_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CABA3_TOSHIBA_E.264 +-fate-h264-conformance-cabac_mot_fld0_full: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/camp_mot_fld0_full.26l +-fate-h264-conformance-cabac_mot_frm0_full: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/camp_mot_frm0_full.26l +-fate-h264-conformance-cabac_mot_mbaff0_full: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/camp_mot_mbaff0_full.26l +-fate-h264-conformance-cabac_mot_picaff0_full: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/camp_mot_picaff0_full.26l +-fate-h264-conformance-cabaci3_sony_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABACI3_Sony_B.jsv +-fate-h264-conformance-cabast3_sony_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABAST3_Sony_E.jsv +-fate-h264-conformance-cabastbr3_sony_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABASTBR3_Sony_B.jsv +-fate-h264-conformance-cabref3_sand_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CABREF3_Sand_D.264 +-fate-h264-conformance-cacqp3_sony_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CACQP3_Sony_D.jsv +-fate-h264-conformance-cafi1_sva_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAFI1_SVA_C.264 +-fate-h264-conformance-cama1_sony_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CAMA1_Sony_C.jsv +-fate-h264-conformance-cama1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMA1_TOSHIBA_B.264 +-fate-h264-conformance-cama1_vtc_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cama1_vtc_c.avc +-fate-h264-conformance-cama2_vtc_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cama2_vtc_b.avc +-fate-h264-conformance-cama3_sand_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMA3_Sand_E.264 +-fate-h264-conformance-cama3_vtc_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cama3_vtc_b.avc +-fate-h264-conformance-camaci3_sony_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMACI3_Sony_C.jsv +-fate-h264-conformance-camanl1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMANL1_TOSHIBA_B.264 +-fate-h264-conformance-camanl2_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMANL2_TOSHIBA_B.264 +-fate-h264-conformance-camanl3_sand_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMANL3_Sand_E.264 +-fate-h264-conformance-camasl3_sony_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMASL3_Sony_B.jsv +-fate-h264-conformance-camp_mot_mbaff_l30: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMP_MOT_MBAFF_L30.26l +-fate-h264-conformance-camp_mot_mbaff_l31: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAMP_MOT_MBAFF_L31.26l +-fate-h264-conformance-canl1_sony_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL1_Sony_E.jsv +-fate-h264-conformance-canl1_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL1_SVA_B.264 +-fate-h264-conformance-canl1_toshiba_g: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL1_TOSHIBA_G.264 +-fate-h264-conformance-canl2_sony_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL2_Sony_E.jsv +-fate-h264-conformance-canl2_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL2_SVA_B.264 +-fate-h264-conformance-canl3_sony_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CANL3_Sony_C.jsv +-fate-h264-conformance-canl3_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL3_SVA_B.264 +-fate-h264-conformance-canl4_sva_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANL4_SVA_B.264 +-fate-h264-conformance-canlma2_sony_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANLMA2_Sony_C.jsv +-fate-h264-conformance-canlma3_sony_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CANLMA3_Sony_C.jsv +-fate-h264-conformance-capa1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAPA1_TOSHIBA_B.264 +-fate-h264-conformance-capama3_sand_f: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAPAMA3_Sand_F.264 +-fate-h264-conformance-capcm1_sand_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CAPCM1_Sand_E.264 +-fate-h264-conformance-capcmnl1_sand_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CAPCMNL1_Sand_E.264 +-fate-h264-conformance-capm3_sony_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAPM3_Sony_D.jsv +-fate-h264-conformance-caqp1_sony_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CAQP1_Sony_B.jsv +-fate-h264-conformance-cavlc_mot_fld0_full_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cvmp_mot_fld0_full_B.26l +-fate-h264-conformance-cavlc_mot_frm0_full_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cvmp_mot_frm0_full_B.26l +-fate-h264-conformance-cavlc_mot_mbaff0_full_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cvmp_mot_mbaff0_full_B.26l +-fate-h264-conformance-cavlc_mot_picaff0_full_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/cvmp_mot_picaff0_full_B.26l +-fate-h264-conformance-cawp1_toshiba_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CAWP1_TOSHIBA_E.264 +-fate-h264-conformance-cawp5_toshiba_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CAWP5_TOSHIBA_E.264 +-fate-h264-conformance-ci1_ft_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/CI1_FT_B.264 +-fate-h264-conformance-ci_mw_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/CI_MW_D.264 +-fate-h264-conformance-cvbs3_sony_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVBS3_Sony_C.jsv +-fate-h264-conformance-cvcanlma2_sony_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CVCANLMA2_Sony_C.jsv +-fate-h264-conformance-cvfi1_sony_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVFI1_Sony_D.jsv +-fate-h264-conformance-cvfi1_sva_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVFI1_SVA_C.264 +-fate-h264-conformance-cvfi2_sony_h: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVFI2_Sony_H.jsv +-fate-h264-conformance-cvfi2_sva_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVFI2_SVA_C.264 +-fate-h264-conformance-cvma1_sony_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/CVMA1_Sony_D.jsv +-fate-h264-conformance-cvma1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMA1_TOSHIBA_B.264 +-fate-h264-conformance-cvmanl1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMANL1_TOSHIBA_B.264 +-fate-h264-conformance-cvmanl2_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMANL2_TOSHIBA_B.264 +-fate-h264-conformance-cvmapaqp3_sony_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMAPAQP3_Sony_E.jsv +-fate-h264-conformance-cvmaqp2_sony_g: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMAQP2_Sony_G.jsv +-fate-h264-conformance-cvmaqp3_sony_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMAQP3_Sony_D.jsv +-fate-h264-conformance-cvmp_mot_fld_l30_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMP_MOT_FLD_L30_B.26l +-fate-h264-conformance-cvmp_mot_frm_l31_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVMP_MOT_FRM_L31_B.26l +-fate-h264-conformance-cvnlfi1_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVNLFI1_Sony_C.jsv +-fate-h264-conformance-cvnlfi2_sony_h: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVNLFI2_Sony_H.jsv +-fate-h264-conformance-cvpa1_toshiba_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVPA1_TOSHIBA_B.264 +-fate-h264-conformance-cvpcmnl1_sva_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CVPCMNL1_SVA_C.264 +-fate-h264-conformance-cvpcmnl2_sva_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/CVPCMNL2_SVA_C.264 +-fate-h264-conformance-cvwp1_toshiba_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/CVWP1_TOSHIBA_E.264 +-fate-h264-conformance-cvwp2_toshiba_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVWP2_TOSHIBA_E.264 +-fate-h264-conformance-cvwp3_toshiba_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVWP3_TOSHIBA_E.264 +-fate-h264-conformance-cvwp5_toshiba_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/CVWP5_TOSHIBA_E.264 +-fate-h264-conformance-fi1_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FI1_Sony_E.jsv +-fate-h264-conformance-frext-alphaconformanceg: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/test8b43.264 +-fate-h264-conformance-frext-bcrm_freh10: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh10.264 -vsync 0 +-fate-h264-conformance-frext-brcm_freh11: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh11.264 -vsync 0 +-fate-h264-conformance-frext-brcm_freh3: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh3.264 +-fate-h264-conformance-frext-brcm_freh4: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh4.264 -vsync 0 +-fate-h264-conformance-frext-brcm_freh5: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh5.264 +-fate-h264-conformance-frext-brcm_freh8: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh8.264 +-fate-h264-conformance-frext-brcm_freh9: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh9.264 +-fate-h264-conformance-frext-freh12_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/Freh12_B.264 +-fate-h264-conformance-frext-freh1_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/Freh1_B.264 +-fate-h264-conformance-frext-freh2_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/Freh2_B.264 +-fate-h264-conformance-frext-freh6: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/freh6.264 -vsync 0 +-fate-h264-conformance-frext-freh7_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/Freh7_B.264 -vsync 0 +-fate-h264-conformance-frext-frext01_jvc_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FREXT01_JVC_D.264 +-fate-h264-conformance-frext-frext02_jvc_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FREXT02_JVC_C.264 +-fate-h264-conformance-frext-frext1_panasonic_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FRExt1_Panasonic.avc +-fate-h264-conformance-frext-frext2_panasonic_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FRExt2_Panasonic.avc -vsync 0 +-fate-h264-conformance-frext-frext3_panasonic_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FRExt3_Panasonic.avc +-fate-h264-conformance-frext-frext4_panasonic_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/FRExt4_Panasonic.avc +-fate-h264-conformance-frext-frext_mmco4_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt_MMCO4_Sony_B.264 +-fate-h264-conformance-frext-hcaff1_hhi_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAFF1_HHI.264 +-fate-h264-conformance-frext-hcafr1_hhi_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAFR1_HHI.264 +-fate-h264-conformance-frext-hcafr2_hhi_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAFR2_HHI.264 +-fate-h264-conformance-frext-hcafr3_hhi_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAFR3_HHI.264 +-fate-h264-conformance-frext-hcafr4_hhi_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAFR4_HHI.264 +-fate-h264-conformance-frext-hcamff1_hhi_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HCAMFF1_HHI.264 +-fate-h264-conformance-frext-hpca_brcm_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCA_BRCM_C.264 +-fate-h264-conformance-frext-hpcadq_brcm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCADQ_BRCM_B.264 +-fate-h264-conformance-frext-hpcafl_bcrm_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCAFL_BRCM_C.264 -vsync 0 +-fate-h264-conformance-frext-hpcaflnl_bcrm_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCAFLNL_BRCM_C.264 -vsync 0 +-fate-h264-conformance-frext-hpcalq_brcm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCALQ_BRCM_B.264 +-fate-h264-conformance-frext-hpcamapalq_bcrm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCAMAPALQ_BRCM_B.264 -vsync 0 +-fate-h264-conformance-frext-hpcamolq_brcm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCAMOLQ_BRCM_B.264 +-fate-h264-conformance-frext-hpcanl_brcm_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCANL_BRCM_C.264 +-fate-h264-conformance-frext-hpcaq2lq_brcm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCAQ2LQ_BRCM_B.264 +-fate-h264-conformance-frext-hpcv_brcm_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCV_BRCM_A.264 +-fate-h264-conformance-frext-hpcvfl_bcrm_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCVFL_BRCM_A.264 -vsync 0 +-fate-h264-conformance-frext-hpcvflnl_bcrm_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCVFLNL_BRCM_A.264 -vsync 0 +-fate-h264-conformance-frext-hpcvmolq_brcm_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCVMOLQ_BRCM_B.264 +-fate-h264-conformance-frext-hpcvnl_brcm_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/FRext/HPCVNL_BRCM_A.264 +-fate-h264-conformance-hcbp2_hhi_a: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/HCBP2_HHI_A.264 +-fate-h264-conformance-hcmp1_hhi_a: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/HCMP1_HHI_A.264 +-fate-h264-conformance-ls_sva_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/LS_SVA_D.264 +-fate-h264-conformance-midr_mw_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/MIDR_MW_D.264 +-fate-h264-conformance-mps_mw_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/MPS_MW_A.264 +-fate-h264-conformance-mr1_bt_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/MR1_BT_A.h264 +-fate-h264-conformance-mr1_mw_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/MR1_MW_A.264 +-fate-h264-conformance-mr2_mw_a: CMD = framecrc -i $(SAMPLES)/h264-conformance/MR2_MW_A.264 +-fate-h264-conformance-mr2_tandberg_e: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR2_TANDBERG_E.264 +-fate-h264-conformance-mr3_tandberg_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR3_TANDBERG_B.264 +-fate-h264-conformance-mr4_tandberg_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR4_TANDBERG_C.264 +-fate-h264-conformance-mr5_tandberg_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR5_TANDBERG_C.264 +-fate-h264-conformance-mr6_bt_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR6_BT_B.h264 +-fate-h264-conformance-mr7_bt_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR7_BT_B.h264 +-fate-h264-conformance-mr8_bt_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR8_BT_B.h264 +-fate-h264-conformance-mr9_bt_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR9_BT_B.h264 +-fate-h264-conformance-mv1_brcm_d: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/src19td.IBP.264 +-fate-h264-conformance-nl1_sony_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/NL1_Sony_D.jsv +-fate-h264-conformance-nl2_sony_h: CMD = framecrc -i $(SAMPLES)/h264-conformance/NL2_Sony_H.jsv +-fate-h264-conformance-nl3_sva_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/NL3_SVA_E.264 +-fate-h264-conformance-nlmq1_jvc_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/NLMQ1_JVC_C.264 +-fate-h264-conformance-nlmq2_jvc_c: CMD = framecrc -i $(SAMPLES)/h264-conformance/NLMQ2_JVC_C.264 +-fate-h264-conformance-nrf_mw_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/NRF_MW_E.264 +-fate-h264-conformance-sharp_mp_field_1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_1_B.jvt +-fate-h264-conformance-sharp_mp_field_2_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_2_B.jvt +-fate-h264-conformance-sharp_mp_field_3_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_3_B.jvt +-fate-h264-conformance-sharp_mp_paff_1r2: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/Sharp_MP_PAFF_1r2.jvt +-fate-h264-conformance-sharp_mp_paff_2r: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/Sharp_MP_PAFF_2.jvt +-fate-h264-conformance-sl1_sva_b: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/SL1_SVA_B.264 +-fate-h264-conformance-sva_ba1_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_BA1_B.264 +-fate-h264-conformance-sva_ba2_d: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_BA2_D.264 +-fate-h264-conformance-sva_base_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_Base_B.264 +-fate-h264-conformance-sva_cl1_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_CL1_E.264 +-fate-h264-conformance-sva_fm1_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_FM1_E.264 +-fate-h264-conformance-sva_nl1_b: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_NL1_B.264 +-fate-h264-conformance-sva_nl2_e: CMD = framecrc -i $(SAMPLES)/h264-conformance/SVA_NL2_E.264 ++fate-h264-conformance-aud_mw_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/AUD_MW_E.264 ++fate-h264-conformance-ba1_ft_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BA1_FT_C.264 ++fate-h264-conformance-ba1_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BA1_Sony_D.jsv ++fate-h264-conformance-ba2_sony_f: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BA2_Sony_F.jsv ++fate-h264-conformance-ba3_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BA3_SVA_C.264 ++fate-h264-conformance-ba_mw_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BA_MW_D.264 ++fate-h264-conformance-bamq1_jvc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BAMQ1_JVC_C.264 ++fate-h264-conformance-bamq2_jvc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BAMQ2_JVC_C.264 ++fate-h264-conformance-banm_mw_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BANM_MW_D.264 ++fate-h264-conformance-basqp1_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/BASQP1_Sony_C.jsv ++fate-h264-conformance-caba1_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA1_Sony_D.jsv ++fate-h264-conformance-caba1_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA1_SVA_B.264 ++fate-h264-conformance-caba2_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA2_Sony_E.jsv ++fate-h264-conformance-caba2_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA2_SVA_B.264 ++fate-h264-conformance-caba3_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA3_Sony_C.jsv ++fate-h264-conformance-caba3_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA3_SVA_B.264 ++fate-h264-conformance-caba3_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABA3_TOSHIBA_E.264 ++fate-h264-conformance-cabac_mot_fld0_full: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/camp_mot_fld0_full.26l ++fate-h264-conformance-cabac_mot_frm0_full: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/camp_mot_frm0_full.26l ++fate-h264-conformance-cabac_mot_mbaff0_full: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/camp_mot_mbaff0_full.26l ++fate-h264-conformance-cabac_mot_picaff0_full: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/camp_mot_picaff0_full.26l ++fate-h264-conformance-cabaci3_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABACI3_Sony_B.jsv ++fate-h264-conformance-cabast3_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABAST3_Sony_E.jsv ++fate-h264-conformance-cabastbr3_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABASTBR3_Sony_B.jsv ++fate-h264-conformance-cabref3_sand_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CABREF3_Sand_D.264 ++fate-h264-conformance-cacqp3_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CACQP3_Sony_D.jsv ++fate-h264-conformance-cafi1_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAFI1_SVA_C.264 ++fate-h264-conformance-cama1_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMA1_Sony_C.jsv ++fate-h264-conformance-cama1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMA1_TOSHIBA_B.264 ++fate-h264-conformance-cama1_vtc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cama1_vtc_c.avc ++fate-h264-conformance-cama2_vtc_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cama2_vtc_b.avc ++fate-h264-conformance-cama3_sand_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMA3_Sand_E.264 ++fate-h264-conformance-cama3_vtc_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cama3_vtc_b.avc ++fate-h264-conformance-camaci3_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMACI3_Sony_C.jsv ++fate-h264-conformance-camanl1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMANL1_TOSHIBA_B.264 ++fate-h264-conformance-camanl2_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMANL2_TOSHIBA_B.264 ++fate-h264-conformance-camanl3_sand_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMANL3_Sand_E.264 ++fate-h264-conformance-camasl3_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMASL3_Sony_B.jsv ++fate-h264-conformance-camp_mot_mbaff_l30: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMP_MOT_MBAFF_L30.26l ++fate-h264-conformance-camp_mot_mbaff_l31: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAMP_MOT_MBAFF_L31.26l ++fate-h264-conformance-canl1_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL1_Sony_E.jsv ++fate-h264-conformance-canl1_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL1_SVA_B.264 ++fate-h264-conformance-canl1_toshiba_g: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL1_TOSHIBA_G.264 ++fate-h264-conformance-canl2_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL2_Sony_E.jsv ++fate-h264-conformance-canl2_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL2_SVA_B.264 ++fate-h264-conformance-canl3_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL3_Sony_C.jsv ++fate-h264-conformance-canl3_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL3_SVA_B.264 ++fate-h264-conformance-canl4_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANL4_SVA_B.264 ++fate-h264-conformance-canlma2_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANLMA2_Sony_C.jsv ++fate-h264-conformance-canlma3_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CANLMA3_Sony_C.jsv ++fate-h264-conformance-capa1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAPA1_TOSHIBA_B.264 ++fate-h264-conformance-capama3_sand_f: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAPAMA3_Sand_F.264 ++fate-h264-conformance-capcm1_sand_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAPCM1_Sand_E.264 ++fate-h264-conformance-capcmnl1_sand_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAPCMNL1_Sand_E.264 ++fate-h264-conformance-capm3_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAPM3_Sony_D.jsv ++fate-h264-conformance-caqp1_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAQP1_Sony_B.jsv ++fate-h264-conformance-cavlc_mot_fld0_full_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cvmp_mot_fld0_full_B.26l ++fate-h264-conformance-cavlc_mot_frm0_full_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cvmp_mot_frm0_full_B.26l ++fate-h264-conformance-cavlc_mot_mbaff0_full_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cvmp_mot_mbaff0_full_B.26l ++fate-h264-conformance-cavlc_mot_picaff0_full_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/cvmp_mot_picaff0_full_B.26l ++fate-h264-conformance-cawp1_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAWP1_TOSHIBA_E.264 ++fate-h264-conformance-cawp5_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CAWP5_TOSHIBA_E.264 ++fate-h264-conformance-ci1_ft_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CI1_FT_B.264 ++fate-h264-conformance-ci_mw_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CI_MW_D.264 ++fate-h264-conformance-cvbs3_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVBS3_Sony_C.jsv ++fate-h264-conformance-cvcanlma2_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVCANLMA2_Sony_C.jsv ++fate-h264-conformance-cvfi1_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVFI1_Sony_D.jsv ++fate-h264-conformance-cvfi1_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVFI1_SVA_C.264 ++fate-h264-conformance-cvfi2_sony_h: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVFI2_Sony_H.jsv ++fate-h264-conformance-cvfi2_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVFI2_SVA_C.264 ++fate-h264-conformance-cvma1_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMA1_Sony_D.jsv ++fate-h264-conformance-cvma1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMA1_TOSHIBA_B.264 ++fate-h264-conformance-cvmanl1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMANL1_TOSHIBA_B.264 ++fate-h264-conformance-cvmanl2_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMANL2_TOSHIBA_B.264 ++fate-h264-conformance-cvmapaqp3_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMAPAQP3_Sony_E.jsv ++fate-h264-conformance-cvmaqp2_sony_g: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMAQP2_Sony_G.jsv ++fate-h264-conformance-cvmaqp3_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMAQP3_Sony_D.jsv ++fate-h264-conformance-cvmp_mot_fld_l30_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMP_MOT_FLD_L30_B.26l ++fate-h264-conformance-cvmp_mot_frm_l31_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVMP_MOT_FRM_L31_B.26l ++fate-h264-conformance-cvnlfi1_sony_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVNLFI1_Sony_C.jsv ++fate-h264-conformance-cvnlfi2_sony_h: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVNLFI2_Sony_H.jsv ++fate-h264-conformance-cvpa1_toshiba_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVPA1_TOSHIBA_B.264 ++fate-h264-conformance-cvpcmnl1_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVPCMNL1_SVA_C.264 ++fate-h264-conformance-cvpcmnl2_sva_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVPCMNL2_SVA_C.264 ++fate-h264-conformance-cvwp1_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVWP1_TOSHIBA_E.264 ++fate-h264-conformance-cvwp2_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVWP2_TOSHIBA_E.264 ++fate-h264-conformance-cvwp3_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVWP3_TOSHIBA_E.264 ++fate-h264-conformance-cvwp5_toshiba_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/CVWP5_TOSHIBA_E.264 ++fate-h264-conformance-fi1_sony_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FI1_Sony_E.jsv ++fate-h264-conformance-frext-alphaconformanceg: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/test8b43.264 ++fate-h264-conformance-frext-bcrm_freh10: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh10.264 -vsync 0 ++fate-h264-conformance-frext-brcm_freh11: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh11.264 -vsync 0 ++fate-h264-conformance-frext-brcm_freh3: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh3.264 ++fate-h264-conformance-frext-brcm_freh4: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh4.264 -vsync 0 ++fate-h264-conformance-frext-brcm_freh5: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh5.264 ++fate-h264-conformance-frext-brcm_freh8: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh8.264 ++fate-h264-conformance-frext-brcm_freh9: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh9.264 ++fate-h264-conformance-frext-freh12_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Freh12_B.264 ++fate-h264-conformance-frext-freh1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Freh1_B.264 ++fate-h264-conformance-frext-freh2_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Freh2_B.264 ++fate-h264-conformance-frext-freh6: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/freh6.264 -vsync 0 ++fate-h264-conformance-frext-freh7_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Freh7_B.264 -vsync 0 ++fate-h264-conformance-frext-frext01_jvc_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FREXT01_JVC_D.264 ++fate-h264-conformance-frext-frext02_jvc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FREXT02_JVC_C.264 ++fate-h264-conformance-frext-frext1_panasonic_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt1_Panasonic.avc ++fate-h264-conformance-frext-frext2_panasonic_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt2_Panasonic.avc -vsync 0 ++fate-h264-conformance-frext-frext3_panasonic_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt3_Panasonic.avc ++fate-h264-conformance-frext-frext4_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt4_Panasonic.avc ++fate-h264-conformance-frext-frext_mmco4_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/FRExt_MMCO4_Sony_B.264 ++fate-h264-conformance-frext-hcaff1_hhi_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFF1_HHI.264 ++fate-h264-conformance-frext-hcafr1_hhi_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR1_HHI.264 ++fate-h264-conformance-frext-hcafr2_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR2_HHI.264 ++fate-h264-conformance-frext-hcafr3_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR3_HHI.264 ++fate-h264-conformance-frext-hcafr4_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAFR4_HHI.264 ++fate-h264-conformance-frext-hcamff1_hhi_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HCAMFF1_HHI.264 ++fate-h264-conformance-frext-hi422fr10_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR10_SONY_B.264 ++fate-h264-conformance-frext-hi422fr13_sony_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR13_SONY_B.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-hi422fr1_sony_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR1_SONY_A.jsv ++fate-h264-conformance-frext-hi422fr6_sony_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/Hi422FR6_SONY_A.jsv -pix_fmt yuv422p10le ++fate-h264-conformance-frext-hpca_brcm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCA_BRCM_C.264 ++fate-h264-conformance-frext-hpcadq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCADQ_BRCM_B.264 ++fate-h264-conformance-frext-hpcafl_bcrm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAFL_BRCM_C.264 -vsync 0 ++fate-h264-conformance-frext-hpcaflnl_bcrm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAFLNL_BRCM_C.264 -vsync 0 ++fate-h264-conformance-frext-hpcalq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCALQ_BRCM_B.264 ++fate-h264-conformance-frext-hpcamapalq_bcrm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAMAPALQ_BRCM_B.264 -vsync 0 ++fate-h264-conformance-frext-hpcamolq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAMOLQ_BRCM_B.264 ++fate-h264-conformance-frext-hpcanl_brcm_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCANL_BRCM_C.264 ++fate-h264-conformance-frext-hpcaq2lq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCAQ2LQ_BRCM_B.264 ++fate-h264-conformance-frext-hpcv_brcm_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCV_BRCM_A.264 ++fate-h264-conformance-frext-hpcvfl_bcrm_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCVFL_BRCM_A.264 -vsync 0 ++fate-h264-conformance-frext-hpcvflnl_bcrm_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCVFLNL_BRCM_A.264 -vsync 0 ++fate-h264-conformance-frext-hpcvmolq_brcm_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCVMOLQ_BRCM_B.264 ++fate-h264-conformance-frext-hpcvnl_brcm_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/HPCVNL_BRCM_A.264 ++fate-h264-conformance-frext-pph10i1_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I1_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i2_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I2_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i3_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I3_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i4_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I4_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i5_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I5_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i6_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I6_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph10i7_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH10I7_Panasonic_A.264 -pix_fmt yuv420p10le ++fate-h264-conformance-frext-pph422i1_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I1_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i2_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I2_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i3_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I3_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i4_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I4_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i5_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I5_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i6_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I6_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-frext-pph422i7_panasonic_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/FRext/PPH422I7_Panasonic_A.264 -pix_fmt yuv422p10le ++fate-h264-conformance-hcbp2_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/HCBP2_HHI_A.264 ++fate-h264-conformance-hcmp1_hhi_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/HCMP1_HHI_A.264 ++fate-h264-conformance-ls_sva_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/LS_SVA_D.264 ++fate-h264-conformance-midr_mw_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MIDR_MW_D.264 ++fate-h264-conformance-mps_mw_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MPS_MW_A.264 ++fate-h264-conformance-mr1_bt_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR1_BT_A.h264 ++fate-h264-conformance-mr1_mw_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR1_MW_A.264 ++fate-h264-conformance-mr2_mw_a: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR2_MW_A.264 ++fate-h264-conformance-mr2_tandberg_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR2_TANDBERG_E.264 ++fate-h264-conformance-mr3_tandberg_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR3_TANDBERG_B.264 ++fate-h264-conformance-mr4_tandberg_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR4_TANDBERG_C.264 ++fate-h264-conformance-mr5_tandberg_c: CMD = framecrc -vsync 0 -strict 1 -i $(SAMPLES)/h264-conformance/MR5_TANDBERG_C.264 ++fate-h264-conformance-mr6_bt_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR6_BT_B.h264 ++fate-h264-conformance-mr7_bt_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR7_BT_B.h264 ++fate-h264-conformance-mr8_bt_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR8_BT_B.h264 ++fate-h264-conformance-mr9_bt_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/MR9_BT_B.h264 ++fate-h264-conformance-mv1_brcm_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/src19td.IBP.264 ++fate-h264-conformance-nl1_sony_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NL1_Sony_D.jsv ++fate-h264-conformance-nl2_sony_h: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NL2_Sony_H.jsv ++fate-h264-conformance-nl3_sva_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NL3_SVA_E.264 ++fate-h264-conformance-nlmq1_jvc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NLMQ1_JVC_C.264 ++fate-h264-conformance-nlmq2_jvc_c: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NLMQ2_JVC_C.264 ++fate-h264-conformance-nrf_mw_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/NRF_MW_E.264 ++fate-h264-conformance-sharp_mp_field_1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_1_B.jvt ++fate-h264-conformance-sharp_mp_field_2_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_2_B.jvt ++fate-h264-conformance-sharp_mp_field_3_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_Field_3_B.jvt ++fate-h264-conformance-sharp_mp_paff_1r2: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_PAFF_1r2.jvt ++fate-h264-conformance-sharp_mp_paff_2r: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/Sharp_MP_PAFF_2.jvt ++fate-h264-conformance-sl1_sva_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SL1_SVA_B.264 ++fate-h264-conformance-sva_ba1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_BA1_B.264 ++fate-h264-conformance-sva_ba2_d: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_BA2_D.264 ++fate-h264-conformance-sva_base_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_Base_B.264 ++fate-h264-conformance-sva_cl1_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_CL1_E.264 ++fate-h264-conformance-sva_fm1_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_FM1_E.264 ++fate-h264-conformance-sva_nl1_b: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_NL1_B.264 ++fate-h264-conformance-sva_nl2_e: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264-conformance/SVA_NL2_E.264 + +-fate-h264-interlace-crop: CMD = framecrc -vframes 3 -i $(SAMPLES)/h264/interlaced_crop.mp4 +-fate-h264-lossless: CMD = framecrc -i $(SAMPLES)/h264/lossless.h264 +-fate-h264-extreme-plane-pred: CMD = framemd5 -strict 1 -vsync 0 -i $(SAMPLES)/h264/extreme-plane-pred.h264 ++fate-h264-interlace-crop: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vframes 3 ++fate-h264-lossless: CMD = framecrc -vsync 0 -i $(SAMPLES)/h264/lossless.h264 ++fate-h264-extreme-plane-pred: CMD = framemd5 -vsync 0 -i $(SAMPLES)/h264/extreme-plane-pred.h264 ++fate-h264-bsf-mp4toannexb: CMD = md5 -i $(SAMPLES)/h264/interlaced_crop.mp4 -vcodec copy -bsf h264_mp4toannexb -f h264 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/image.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/image.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/image.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/image.mak 2012-05-14 14:08:55.581365079 +0200 +@@ -0,0 +1,72 @@ ++FATE_IMAGE += fate-dpx ++fate-dpx: CMD = framecrc -i $(SAMPLES)/dpx/lighthouse_rgb48.dpx ++ ++FATE_IMAGE += fate-pictor ++fate-pictor: CMD = framecrc -i $(SAMPLES)/pictor/MFISH.PIC -pix_fmt rgb24 ++ ++FATE_IMAGE += fate-ptx ++fate-ptx: CMD = framecrc -i $(SAMPLES)/ptx/_113kw_pic.ptx -pix_fmt rgb24 ++ ++FATE_SUNRASTER += fate-sunraster-1bit-raw ++fate-sunraster-1bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-1bit-raw.sun ++ ++FATE_SUNRASTER += fate-sunraster-1bit-rle ++fate-sunraster-1bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-1bit-rle.sun ++ ++FATE_SUNRASTER += fate-sunraster-8bit-raw ++fate-sunraster-8bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-8bit-raw.sun -pix_fmt rgb24 ++ ++FATE_SUNRASTER += fate-sunraster-8bit-rle ++fate-sunraster-8bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-8bit-rle.sun -pix_fmt rgb24 ++ ++FATE_SUNRASTER += fate-sunraster-24bit-raw ++fate-sunraster-24bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-24bit-raw.sun ++ ++FATE_SUNRASTER += fate-sunraster-24bit-rle ++fate-sunraster-24bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-24bit-rle.sun ++ ++FATE_IMAGE += $(FATE_SUNRASTER) ++fate-sunraster: $(FATE_SUNRASTER) ++ ++FATE_TARGA = CBW8 \ ++ CCM8 \ ++ CTC16 \ ++ CTC24 \ ++ CTC32 \ ++ UBW8 \ ++ UCM8 \ ++ UTC16 \ ++ UTC24 \ ++ UTC32 ++ ++FATE_TARGA := $(FATE_TARGA:%=fate-targa-conformance-%) \ ++ fate-targa-top-to-bottom ++ ++FATE_IMAGE += $(FATE_TARGA) ++fate-targa: $(FATE_TARGA) ++ ++fate-targa-conformance-CBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CBW8.TGA ++fate-targa-conformance-CCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/CCM8.TGA -pix_fmt rgba ++fate-targa-conformance-CTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC16.TGA -pix_fmt rgb555le ++fate-targa-conformance-CTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC24.TGA ++fate-targa-conformance-CTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/CTC32.TGA -pix_fmt bgra ++fate-targa-conformance-UBW8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UBW8.TGA ++fate-targa-conformance-UCM8: CMD = framecrc -i $(SAMPLES)/targa-conformance/UCM8.TGA -pix_fmt rgba ++fate-targa-conformance-UTC16: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC16.TGA -pix_fmt rgb555le ++fate-targa-conformance-UTC24: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC24.TGA ++fate-targa-conformance-UTC32: CMD = framecrc -i $(SAMPLES)/targa-conformance/UTC32.TGA -pix_fmt bgra ++ ++fate-targa-top-to-bottom: CMD = framecrc -i $(SAMPLES)/targa/lena-top-to-bottom.tga ++ ++FATE_TIFF += fate-tiff-fax-g3 ++fate-tiff-fax-g3: CMD = framecrc -i $(SAMPLES)/CCITT_fax/G31D.TIF ++ ++FATE_TIFF += fate-tiff-fax-g3s ++fate-tiff-fax-g3s: CMD = framecrc -i $(SAMPLES)/CCITT_fax/G31DS.TIF ++ ++FATE_IMAGE += $(FATE_TIFF) ++fate-tiff: $(FATE_TIFF) ++ ++FATE_TESTS += $(FATE_IMAGE) ++fate-image: $(FATE_IMAGE) ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/indeo.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/indeo.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/indeo.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/indeo.mak 2012-05-14 14:08:55.581365079 +0200 +@@ -0,0 +1,14 @@ ++FATE_INDEO += fate-indeo2 ++fate-indeo2: CMD = framecrc -i $(SAMPLES)/rt21/VPAR0026.AVI ++ ++FATE_INDEO += fate-indeo3 ++fate-indeo3: CMD = framecrc -i $(SAMPLES)/iv32/cubes.mov ++ ++FATE_INDEO += fate-indeo4 ++fate-indeo4: CMD = framecrc -i $(SAMPLES)/iv41/indeo41-partial.avi -an ++ ++FATE_INDEO += fate-indeo5 ++fate-indeo5: CMD = framecrc -i $(SAMPLES)/iv50/Educ_Movie_DeadlyForce.avi -an ++ ++FATE_TESTS += $(FATE_INDEO) ++fate-indeo: $(FATE_INDEO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/libavcodec.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/libavcodec.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/libavcodec.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/libavcodec.mak 2012-05-14 14:08:55.582365099 +0200 +@@ -0,0 +1,3 @@ ++FATE_TESTS += fate-iirfilter ++fate-iirfilter: libavcodec/iirfilter-test$(EXESUF) ++fate-iirfilter: CMD = run libavcodec/iirfilter-test +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/libavutil.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/libavutil.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/libavutil.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/libavutil.mak 2012-05-14 14:08:55.582365099 +0200 +@@ -0,0 +1,41 @@ ++FATE_LIBAVUTIL += fate-adler32 ++fate-adler32: libavutil/adler32-test$(EXESUF) ++fate-adler32: CMD = run libavutil/adler32-test ++fate-adler32: REF = /dev/null ++ ++FATE_LIBAVUTIL += fate-aes ++fate-aes: libavutil/aes-test$(EXESUF) ++fate-aes: CMD = run libavutil/aes-test ++fate-aes: REF = /dev/null ++ ++FATE_LIBAVUTIL += fate-base64 ++fate-base64: libavutil/base64-test$(EXESUF) ++fate-base64: CMD = run libavutil/base64-test ++ ++FATE_LIBAVUTIL += fate-crc ++fate-crc: libavutil/crc-test$(EXESUF) ++fate-crc: CMD = run libavutil/crc-test ++ ++FATE_LIBAVUTIL += fate-des ++fate-des: libavutil/des-test$(EXESUF) ++fate-des: CMD = run libavutil/des-test ++fate-des: REF = /dev/null ++ ++FATE_LIBAVUTIL += fate-eval ++fate-eval: libavutil/eval-test$(EXESUF) ++fate-eval: CMD = run libavutil/eval-test ++ ++FATE_LIBAVUTIL += fate-fifo ++fate-fifo: libavutil/fifo-test$(EXESUF) ++fate-fifo: CMD = run libavutil/fifo-test ++ ++FATE_LIBAVUTIL += fate-md5 ++fate-md5: libavutil/md5-test$(EXESUF) ++fate-md5: CMD = run libavutil/md5-test ++ ++FATE_LIBAVUTIL += fate-sha ++fate-sha: libavutil/sha-test$(EXESUF) ++fate-sha: CMD = run libavutil/sha-test ++ ++FATE_TESTS += $(FATE_LIBAVUTIL) ++fate-libavutil: $(FATE_LIBAVUTIL) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/lossless-audio.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/lossless-audio.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/lossless-audio.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/lossless-audio.mak 2012-05-14 14:08:55.582365099 +0200 +@@ -0,0 +1,20 @@ ++FATE_LOSSLESS_AUDIO += fate-lossless-alac ++fate-lossless-alac: CMD = md5 -i $(SAMPLES)/lossless-audio/inside.m4a -f s16le ++ ++FATE_LOSSLESS_AUDIO += fate-lossless-meridianaudio ++fate-lossless-meridianaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.mlp -f s16le ++ ++FATE_LOSSLESS_AUDIO += fate-lossless-monkeysaudio ++fate-lossless-monkeysaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.ape -f s16le ++ ++FATE_LOSSLESS_AUDIO += fate-lossless-shorten ++fate-lossless-shorten: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.shn -f s16le ++ ++FATE_LOSSLESS_AUDIO += fate-lossless-tta ++fate-lossless-tta: CMD = crc -i $(SAMPLES)/lossless-audio/inside.tta ++ ++FATE_LOSSLESS_AUDIO += fate-lossless-wavpack ++fate-lossless-wavpack: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.wv -f s16le ++ ++FATE_TESTS += $(FATE_LOSSLESS_AUDIO) ++fate-lossless-audio: $(FATE_LOSSLESS_AUDIO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/lossless-video.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/lossless-video.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/lossless-video.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/lossless-video.mak 2012-05-14 14:08:55.583365119 +0200 +@@ -0,0 +1,23 @@ ++FATE_LOCO += fate-loco-rgb ++fate-loco-rgb: CMD = framecrc -i $(SAMPLES)/loco/pig-loco-rgb.avi ++ ++FATE_LOCO += fate-loco-yuy2 ++fate-loco-yuy2: CMD = framecrc -i $(SAMPLES)/loco/pig-loco-0.avi ++ ++FATE_LOSSLESS_VIDEO += $(FATE_LOCO) ++fate-loco: $(FATE_LOCO) ++ ++FATE_LOSSLESS_VIDEO += fate-msrle-8bit ++fate-msrle-8bit: CMD = framecrc -i $(SAMPLES)/msrle/Search-RLE.avi -pix_fmt rgb24 ++ ++FATE_LOSSLESS_VIDEO += fate-mszh ++fate-mszh: CMD = framecrc -i $(SAMPLES)/lcl/mszh-1frame.avi ++ ++FATE_LOSSLESS_VIDEO += fate-vble ++fate-vble: CMD = framecrc -i $(SAMPLES)/vble/flowers-partial-2MB.avi ++ ++FATE_LOSSLESS_VIDEO += fate-zlib ++fate-zlib: CMD = framecrc -i $(SAMPLES)/lcl/zlib-1frame.avi ++ ++FATE_TESTS += $(FATE_LOSSLESS_VIDEO) ++fate-lossless-video: $(FATE_LOSSLESS_VIDEO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mapchan.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mapchan.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mapchan.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mapchan.mak 2012-05-14 14:08:55.583365119 +0200 +@@ -0,0 +1,14 @@ ++FATE_MAPCHAN += fate-mapchan-6ch-extract-2 ++fate-mapchan-6ch-extract-2: tests/data/mapchan-6ch.sw ++fate-mapchan-6ch-extract-2: CMD = avconv -ar 22050 -ac 6 -f s16le -i $(TARGET_PATH)/tests/data/mapchan-6ch.sw -map_channel 0.0.0 -f wav md5: -map_channel 0.0.1 -f wav md5: ++ ++FATE_MAPCHAN += fate-mapchan-6ch-extract-2-downmix-mono ++fate-mapchan-6ch-extract-2-downmix-mono: tests/data/mapchan-6ch.sw ++fate-mapchan-6ch-extract-2-downmix-mono: CMD = md5 -ar 22050 -ac 6 -f s16le -i $(TARGET_PATH)/tests/data/mapchan-6ch.sw -map_channel 0.0.1 -map_channel 0.0.0 -ac 1 -f wav ++ ++FATE_MAPCHAN += fate-mapchan-silent-mono ++fate-mapchan-silent-mono: tests/data/mapchan-mono.sw ++fate-mapchan-silent-mono: CMD = md5 -ar 22050 -ac 1 -f s16le -i $(TARGET_PATH)/tests/data/mapchan-mono.sw -map_channel -1 -map_channel 0.0.0 -f wav ++ ++FATE_TESTS += $(FATE_MAPCHAN) ++fate-mapchan: $(FATE_MAPCHAN) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/microsoft.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/microsoft.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/microsoft.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/microsoft.mak 2012-05-14 14:08:55.584365139 +0200 +@@ -0,0 +1,45 @@ ++FATE_MICROSOFT += fate-msmpeg4v1 ++fate-msmpeg4v1: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/msmpeg4v1/mpg4.avi -an ++ ++FATE_MSVIDEO1 += fate-msvideo1-16bit ++fate-msvideo1-16bit: CMD = framecrc -i $(SAMPLES)/cram/clock-cram16.avi -pix_fmt rgb24 ++ ++FATE_MSVIDEO1 += fate-msvideo1-8bit ++fate-msvideo1-8bit: CMD = framecrc -i $(SAMPLES)/cram/skating.avi -t 1 -pix_fmt rgb24 ++ ++FATE_MICROSOFT += $(FATE_MSVIDEO1) ++fate-msvideo1: $(FATE_MSVIDEO1) ++ ++FATE_WMV8_DRM += fate-wmv8-drm ++# discard last packet to avoid fails due to overread of VC-1 decoder ++fate-wmv8-drm: CMD = framecrc -cryptokey 137381538c84c068111902a59c5cf6c340247c39 -i $(SAMPLES)/wmv8/wmv_drm.wmv -an -vframes 162 ++ ++FATE_WMV8_DRM += fate-wmv8-drm-nodec ++fate-wmv8-drm-nodec: CMD = framecrc -cryptokey 137381538c84c068111902a59c5cf6c340247c39 -i $(SAMPLES)/wmv8/wmv_drm.wmv -acodec copy -vcodec copy ++ ++#FATE_MICROSOFT += fate-wmv8-x8intra ++#fate-wmv8-x8intra: CMD = framecrc -flags +bitexact -idct 19 -i $(SAMPLES)/wmv8/wmv8_x8intra.wmv -an ++ ++FATE_MICROSOFT += $(FATE_WMV8_DRM) ++fate-wmv8_drm: $(FATE_WMV8_DRM) ++ ++FATE_VC1 += fate-vc1_sa00040 ++fate-vc1_sa00040: CMD = framecrc -i $(SAMPLES)/vc1/SA00040.vc1 ++ ++FATE_VC1 += fate-vc1_sa00050 ++fate-vc1_sa00050: CMD = framecrc -i $(SAMPLES)/vc1/SA00050.vc1 ++ ++FATE_VC1 += fate-vc1_sa10091 ++fate-vc1_sa10091: CMD = framecrc -i $(SAMPLES)/vc1/SA10091.vc1 ++ ++FATE_VC1 += fate-vc1_sa20021 ++fate-vc1_sa20021: CMD = framecrc -i $(SAMPLES)/vc1/SA20021.vc1 ++ ++FATE_VC1 += fate-vc1-ism ++fate-vc1-ism: CMD = framecrc -i $(SAMPLES)/isom/vc1-wmapro.ism -an ++ ++FATE_MICROSOFT += $(FATE_VC1) ++fate-vc1: $(FATE_VC1) ++ ++FATE_TESTS += $(FATE_MICROSOFT) ++fate-microsoft: $(FATE_MICROSOFT) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mp3.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mp3.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mp3.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mp3.mak 2012-05-14 14:08:55.585365159 +0200 +@@ -4,32 +4,32 @@ + fate-mp3-float-conf-compl: REF = $(SAMPLES)/mp3-conformance/compl.pcm + + FATE_MP3 += fate-mp3-float-conf-he_32khz +-fate-mp3-float-conf-he_32khz: CMD = pcm -acodec mp3float -fs 343296 -i $(SAMPLES)/mp3-conformance/he_32khz.bit ++fate-mp3-float-conf-he_32khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_32khz.bit -fs 343296 + fate-mp3-float-conf-he_32khz: CMP = stddev + fate-mp3-float-conf-he_32khz: REF = $(SAMPLES)/mp3-conformance/he_32khz.pcm + + FATE_MP3 += fate-mp3-float-conf-he_44khz +-fate-mp3-float-conf-he_44khz: CMD = pcm -acodec mp3float -fs 942336 -i $(SAMPLES)/mp3-conformance/he_44khz.bit ++fate-mp3-float-conf-he_44khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_44khz.bit -fs 942336 + fate-mp3-float-conf-he_44khz: CMP = stddev + fate-mp3-float-conf-he_44khz: REF = $(SAMPLES)/mp3-conformance/he_44khz.pcm + + FATE_MP3 += fate-mp3-float-conf-he_48khz +-fate-mp3-float-conf-he_48khz: CMD = pcm -acodec mp3float -fs 343296 -i $(SAMPLES)/mp3-conformance/he_48khz.bit ++fate-mp3-float-conf-he_48khz: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/he_48khz.bit -fs 343296 + fate-mp3-float-conf-he_48khz: CMP = stddev + fate-mp3-float-conf-he_48khz: REF = $(SAMPLES)/mp3-conformance/he_48khz.pcm + + FATE_MP3 += fate-mp3-float-conf-hecommon +-fate-mp3-float-conf-hecommon: CMD = pcm -acodec mp3float -fs 133632 -i $(SAMPLES)/mp3-conformance/hecommon.bit ++fate-mp3-float-conf-hecommon: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/hecommon.bit -fs 133632 + fate-mp3-float-conf-hecommon: CMP = stddev + fate-mp3-float-conf-hecommon: REF = $(SAMPLES)/mp3-conformance/hecommon.pcm + + FATE_MP3 += fate-mp3-float-conf-si +-fate-mp3-float-conf-si: CMD = pcm -acodec mp3float -fs 269568 -i $(SAMPLES)/mp3-conformance/si.bit ++fate-mp3-float-conf-si: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/si.bit -fs 269568 + fate-mp3-float-conf-si: CMP = stddev + fate-mp3-float-conf-si: REF = $(SAMPLES)/mp3-conformance/si.pcm + + FATE_MP3 += fate-mp3-float-conf-si_block +-fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -fs 145152 -i $(SAMPLES)/mp3-conformance/si_block.bit ++fate-mp3-float-conf-si_block: CMD = pcm -acodec mp3float -i $(SAMPLES)/mp3-conformance/si_block.bit -fs 145152 + fate-mp3-float-conf-si_block: CMP = stddev + fate-mp3-float-conf-si_block: REF = $(SAMPLES)/mp3-conformance/si_block.pcm + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mpc.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mpc.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/mpc.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/mpc.mak 2012-05-14 14:08:55.585365159 +0200 +@@ -0,0 +1,14 @@ ++FATE_MPC += fate-mpc7-demux ++fate-mpc7-demux: CMD = crc -i $(SAMPLES)/musepack/inside-mp7.mpc -acodec copy ++ ++FATE_MPC += fate-mpc8-demux ++fate-mpc8-demux: CMD = crc -i $(SAMPLES)/musepack/inside-mp8.mpc -acodec copy ++ ++FATE_MPC += fate-musepack7 ++fate-musepack7: CMD = pcm -i $(SAMPLES)/musepack/inside-mp7.mpc ++fate-musepack7: CMP = oneoff ++fate-musepack7: REF = $(SAMPLES)/musepack/inside-mp7.pcm ++fate-musepack7: FUZZ = 1 ++ ++FATE_TESTS += $(FATE_MPC) ++fate-mpc: $(FATE_MPC) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/pcm.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/pcm.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/pcm.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/pcm.mak 2012-05-14 14:08:55.585365159 +0200 +@@ -0,0 +1,29 @@ ++FATE_PCM += fate-ea-mad-pcm-planar ++fate-ea-mad-pcm-planar: CMD = framecrc -i $(SAMPLES)/ea-mad/xeasport.mad ++ ++FATE_PCM += fate-film-cvid-pcm-stereo-8bit ++fate-film-cvid-pcm-stereo-8bit: CMD = framecrc -i $(SAMPLES)/film/logo-capcom.cpk ++ ++FATE_PCM += fate-iff-pcm ++fate-iff-pcm: CMD = md5 -i $(SAMPLES)/iff/Bells -f s16le ++ ++FATE_PCM += fate-pcm_dvd ++fate-pcm_dvd: CMD = framecrc -i $(SAMPLES)/pcm-dvd/coolitnow-partial.vob -vn ++ ++FATE_PCM += fate-pcm_s16be-stereo ++fate-pcm_s16be-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-twos.mov -f s16le ++ ++FATE_PCM += fate-pcm_s16le-stereo ++fate-pcm_s16le-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-sowt.mov -f s16le ++ ++FATE_PCM += fate-pcm_u8-mono ++fate-pcm_u8-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-raw.mov -f s16le ++ ++FATE_PCM += fate-pcm_u8-stereo ++fate-pcm_u8-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-raw.mov -f s16le ++ ++FATE_PCM += fate-w64 ++fate-w64: CMD = crc -i $(SAMPLES)/w64/w64-pcm16.w64 ++ ++FATE_TESTS += $(FATE_PCM) ++fate-pcm: $(FATE_PCM) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/prores.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/prores.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/prores.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/prores.mak 2012-05-14 14:08:55.586365179 +0200 +@@ -0,0 +1,15 @@ ++FATE_PRORES = fate-prores-422 \ ++ fate-prores-422_hq \ ++ fate-prores-422_lt \ ++ fate-prores-422_proxy \ ++ fate-prores-alpha \ ++ ++FATE_TESTS += $(FATE_PRORES) ++fate-prores: $(FATE_PRORES) ++ ++fate-prores-422: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422.mov -pix_fmt yuv422p10le ++fate-prores-422_hq: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_HQ.mov -pix_fmt yuv422p10le ++fate-prores-422_lt: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_LT.mov -pix_fmt yuv422p10le ++fate-prores-422_proxy: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_422_Proxy.mov -pix_fmt yuv422p10le ++fate-prores-alpha: CMD = framecrc -flags +bitexact -vsync 0 -i $(SAMPLES)/prores/Sequence_1-Apple_ProRes_with_Alpha.mov -pix_fmt yuv444p10le ++ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/qt.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/qt.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/qt.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/qt.mak 2012-05-14 14:08:55.586365179 +0200 +@@ -0,0 +1,53 @@ ++FATE_QT += fate-8bps ++fate-8bps: CMD = framecrc -i $(SAMPLES)/8bps/full9iron-partial.mov -pix_fmt rgb24 ++ ++FATE_QT += fate-qdm2 ++fate-qdm2: CMD = pcm -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-QDM2.mov ++fate-qdm2: CMP = oneoff ++fate-qdm2: REF = $(SAMPLES)/qt-surge-suite/surge-2-16-B-QDM2.pcm ++fate-qdm2: FUZZ = 2 ++ ++FATE_QT += fate-qt-alaw-mono ++fate-qt-alaw-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-alaw.mov -f s16le ++ ++FATE_QT += fate-qt-alaw-stereo ++fate-qt-alaw-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-alaw.mov -f s16le ++ ++FATE_QT += fate-qt-ima4-mono ++fate-qt-ima4-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-ima4.mov -f s16le ++ ++FATE_QT += fate-qt-ima4-stereo ++fate-qt-ima4-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-ima4.mov -f s16le ++ ++FATE_QT += fate-qt-mac3-mono ++fate-qt-mac3-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-MAC3.mov -f s16le ++ ++FATE_QT += fate-qt-mac3-stereo ++fate-qt-mac3-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-MAC3.mov -f s16le ++ ++FATE_QT += fate-qt-mac6-mono ++fate-qt-mac6-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-MAC6.mov -f s16le ++ ++FATE_QT += fate-qt-mac6-stereo ++fate-qt-mac6-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-MAC6.mov -f s16le ++ ++FATE_QT += fate-qt-ulaw-mono ++fate-qt-ulaw-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-ulaw.mov -f s16le ++ ++FATE_QT += fate-qt-ulaw-stereo ++fate-qt-ulaw-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-ulaw.mov -f s16le ++ ++FATE_QT += fate-quickdraw ++fate-quickdraw: CMD = framecrc -i $(SAMPLES)/quickdraw/Airplane.mov -pix_fmt rgb24 ++ ++FATE_QT += fate-rpza ++fate-rpza: CMD = framecrc -i $(SAMPLES)/rpza/rpza2.mov -t 2 -pix_fmt rgb24 ++ ++FATE_QT += fate-svq1 ++fate-svq1: CMD = framecrc -i $(SAMPLES)/svq1/marymary-shackles.mov -an -t 10 ++ ++FATE_QT += fate-svq3 ++fate-svq3: CMD = framecrc -i $(SAMPLES)/svq3/Vertical400kbit.sorenson3.mov -t 6 -an ++ ++FATE_TESTS += $(FATE_QT) ++fate-qt: $(FATE_QT) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/qtrle.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/qtrle.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/qtrle.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/qtrle.mak 2012-05-14 14:08:55.587365200 +0200 +@@ -0,0 +1,23 @@ ++FATE_QTRLE += fate-qtrle-1bit ++fate-qtrle-1bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-Monochrome.mov ++ ++FATE_QTRLE += fate-qtrle-2bit ++fate-qtrle-2bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-4Greys.mov -pix_fmt rgb24 ++ ++FATE_QTRLE += fate-qtrle-4bit ++fate-qtrle-4bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-16Greys.mov -pix_fmt rgb24 -an ++ ++FATE_QTRLE += fate-qtrle-8bit ++fate-qtrle-8bit: CMD = framecrc -i $(SAMPLES)/qtrle/criticalpath-credits.mov -vsync 0 -pix_fmt rgb24 -an ++ ++FATE_QTRLE += fate-qtrle-16bit ++fate-qtrle-16bit: CMD = framecrc -i $(SAMPLES)/qtrle/mr-cork-rle.mov -pix_fmt rgb24 ++ ++FATE_QTRLE += fate-qtrle-24bit ++fate-qtrle-24bit: CMD = framecrc -i $(SAMPLES)/qtrle/aletrek-rle.mov -vsync 0 ++ ++FATE_QTRLE += fate-qtrle-32bit ++fate-qtrle-32bit: CMD = framecrc -i $(SAMPLES)/qtrle/ultra_demo_720_480_32bpp_rle.mov -pix_fmt rgb24 ++ ++FATE_TESTS += $(FATE_QTRLE) ++fate-qtrle: $(FATE_QTRLE) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/real.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/real.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/real.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/real.mak 2012-05-14 14:08:55.588365220 +0200 +@@ -0,0 +1,45 @@ ++FATE_REAL += fate-real-14_4 ++fate-real-14_4: CMD = md5 -i $(SAMPLES)/real/ra3_in_rm_file.rm -f s16le ++ ++FATE_REAL += fate-ra-288 ++fate-ra-288: CMD = pcm -i $(SAMPLES)/real/ra_288.rm ++fate-ra-288: CMP = oneoff ++fate-ra-288: REF = $(SAMPLES)/real/ra_288.pcm ++fate-ra-288: FUZZ = 2 ++ ++FATE_REAL += fate-ra-cook ++fate-ra-cook: CMD = pcm -i $(SAMPLES)/real/ra_cook.rm ++fate-ra-cook: CMP = oneoff ++fate-ra-cook: REF = $(SAMPLES)/real/ra_cook.pcm ++ ++FATE_REAL += fate-rv30 ++fate-rv30: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/real/rv30.rm -an ++ ++FATE_REAL += fate-real-rv40 ++fate-real-rv40: CMD = framecrc -i $(SAMPLES)/real/spygames-2MB.rmvb -t 10 -an -vsync 0 ++ ++FATE_SIPR += fate-sipr-5k0 ++fate-sipr-5k0: CMD = pcm -i $(SAMPLES)/sipr/sipr_5k0.rm ++fate-sipr-5k0: CMP = oneoff ++fate-sipr-5k0: REF = $(SAMPLES)/sipr/sipr_5k0.pcm ++ ++FATE_SIPR += fate-sipr-6k5 ++fate-sipr-6k5: CMD = pcm -i $(SAMPLES)/sipr/sipr_6k5.rm ++fate-sipr-6k5: CMP = oneoff ++fate-sipr-6k5: REF = $(SAMPLES)/sipr/sipr_6k5.pcm ++ ++FATE_SIPR += fate-sipr-8k5 ++fate-sipr-8k5: CMD = pcm -i $(SAMPLES)/sipr/sipr_8k5.rm ++fate-sipr-8k5: CMP = oneoff ++fate-sipr-8k5: REF = $(SAMPLES)/sipr/sipr_8k5.pcm ++ ++FATE_SIPR += fate-sipr-16k ++fate-sipr-16k: CMD = pcm -i $(SAMPLES)/sipr/sipr_16k.rm ++fate-sipr-16k: CMP = oneoff ++fate-sipr-16k: REF = $(SAMPLES)/sipr/sipr_16k.pcm ++ ++FATE_REAL += $(FATE_SIPR) ++fate-sipr: $(FATE_SIPR) ++ ++FATE_TESTS += $(FATE_REAL) ++fate-real: $(FATE_REAL) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/screen.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/screen.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/screen.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/screen.mak 2012-05-14 14:08:55.588365220 +0200 +@@ -0,0 +1,62 @@ ++FATE_SCREEN += fate-cscd ++fate-cscd: CMD = framecrc -i $(SAMPLES)/CSCD/sample_video.avi -an -vsync 0 -pix_fmt rgb24 ++ ++FATE_SCREEN += fate-dxtory ++fate-dxtory: CMD = framecrc -i $(SAMPLES)/dxtory/dxtory_mic.avi ++ ++FATE_FRAPS += fate-fraps-v0 ++fate-fraps-v0: CMD = framecrc -i $(SAMPLES)/fraps/Griffin_Ragdoll01-partial.avi ++ ++FATE_FRAPS += fate-fraps-v1 ++fate-fraps-v1: CMD = framecrc -i $(SAMPLES)/fraps/sample-v1.avi -an ++ ++FATE_FRAPS += fate-fraps-v2 ++fate-fraps-v2: CMD = framecrc -i $(SAMPLES)/fraps/test3-nosound-partial.avi ++ ++FATE_FRAPS += fate-fraps-v3 ++fate-fraps-v3: CMD = framecrc -i $(SAMPLES)/fraps/psclient-partial.avi -pix_fmt rgb24 ++ ++FATE_FRAPS += fate-fraps-v4 ++fate-fraps-v4: CMD = framecrc -i $(SAMPLES)/fraps/WoW_2006-11-03_14-58-17-19-nosound-partial.avi ++ ++FATE_FRAPS += fate-fraps-v5 ++fate-fraps-v5: CMD = framecrc -i $(SAMPLES)/fraps/fraps-v5-bouncing-balls-partial.avi ++ ++FATE_SCREEN += $(FATE_FRAPS) ++fate-fraps: $(FATE_FRAPS) ++ ++FATE_TSCC += fate-tscc-15bit ++fate-tscc-15bit: CMD = framecrc -i $(SAMPLES)/tscc/oneminute.avi -t 15 -pix_fmt rgb24 ++ ++FATE_TSCC += fate-tscc-32bit ++fate-tscc-32bit: CMD = framecrc -i $(SAMPLES)/tscc/2004-12-17-uebung9-partial.avi -pix_fmt rgb24 -an ++ ++FATE_SCREEN += $(FATE_TSCC) ++fate-tscc: $(FATE_TSCC) ++ ++FATE_VMNC += fate-vmnc-16bit ++fate-vmnc-16bit: CMD = framecrc -i $(SAMPLES)/VMnc/test.avi -pix_fmt rgb24 ++ ++FATE_VMNC += fate-vmnc-32bit ++fate-vmnc-32bit: CMD = framecrc -i $(SAMPLES)/VMnc/VS2k5DebugDemo-01-partial.avi -pix_fmt rgb24 ++ ++FATE_SCREEN += $(FATE_VMNC) ++fate-vmnc: $(FATE_VMNC) ++ ++FATE_ZMBV += fate-zmbv-8bit ++fate-zmbv-8bit: CMD = framecrc -i $(SAMPLES)/zmbv/wc2_001-partial.avi -an -pix_fmt rgb24 ++ ++FATE_ZMBV += fate-zmbv-15bit ++fate-zmbv-15bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_15bit.avi -pix_fmt rgb24 -t 25 ++ ++FATE_ZMBV += fate-zmbv-16bit ++fate-zmbv-16bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_16bit.avi -pix_fmt rgb24 -t 25 ++ ++FATE_ZMBV += fate-zmbv-32bit ++fate-zmbv-32bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_32bit.avi -pix_fmt rgb24 -t 25 ++ ++FATE_SCREEN += $(FATE_ZMBV) ++fate-zmbv: $(FATE_ZMBV) ++ ++FATE_TESTS += $(FATE_SCREEN) ++fate-screen: $(FATE_SCREEN) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/utvideo.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/utvideo.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/utvideo.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/utvideo.mak 2012-05-14 14:08:55.589365240 +0200 +@@ -0,0 +1,26 @@ ++FATE_UTVIDEO += fate-utvideo_rgba_left ++fate-utvideo_rgba_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgba_left.avi ++ ++FATE_UTVIDEO += fate-utvideo_rgba_median ++fate-utvideo_rgba_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgba_median.avi ++ ++FATE_UTVIDEO += fate-utvideo_rgb_left ++fate-utvideo_rgb_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_left.avi ++ ++FATE_UTVIDEO += fate-utvideo_rgb_median ++fate-utvideo_rgb_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_rgb_median.avi ++ ++FATE_UTVIDEO += fate-utvideo_yuv420_left ++fate-utvideo_yuv420_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_yuv420_left.avi ++ ++FATE_UTVIDEO += fate-utvideo_yuv420_median ++fate-utvideo_yuv420_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_yuv420_median.avi ++ ++FATE_UTVIDEO += fate-utvideo_yuv422_left ++fate-utvideo_yuv422_left: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_yuv422_left.avi ++ ++FATE_UTVIDEO += fate-utvideo_yuv422_median ++fate-utvideo_yuv422_median: CMD = framecrc -i $(SAMPLES)/utvideo/utvideo_yuv422_median.avi ++ ++FATE_TESTS += $(FATE_UTVIDEO) ++fate-utvideo: $(FATE_UTVIDEO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/video.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/video.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/video.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/video.mak 2012-05-14 14:08:55.590365260 +0200 +@@ -0,0 +1,219 @@ ++FATE_4XM += fate-4xm-1 ++fate-4xm-1: CMD = framecrc -i $(SAMPLES)/4xm/version1.4xm -pix_fmt rgb24 -an ++ ++FATE_4XM += fate-4xm-2 ++fate-4xm-2: CMD = framecrc -i $(SAMPLES)/4xm/version2.4xm -pix_fmt rgb24 -an ++ ++FATE_VIDEO += $(FATE_4XM) ++fate-4xm: $(FATE_4XM) ++ ++FATE_VIDEO += fate-aasc ++fate-aasc: CMD = framecrc -i $(SAMPLES)/aasc/AASC-1.5MB.AVI -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-alg-mm ++fate-alg-mm: CMD = framecrc -i $(SAMPLES)/alg-mm/ibmlogo.mm -an -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-amv ++fate-amv: CMD = framecrc -idct simple -i $(SAMPLES)/amv/MTV_high_res_320x240_sample_Penguin_Joke_MTV_from_WMV.amv -t 10 ++ ++FATE_VIDEO += fate-ansi ++fate-ansi: CMD = framecrc -chars_per_frame 44100 -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-armovie-escape124 ++fate-armovie-escape124: CMD = framecrc -i $(SAMPLES)/rpl/ESCAPE.RPL -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-auravision-v1 ++fate-auravision-v1: CMD = framecrc -i $(SAMPLES)/auravision/SOUVIDEO.AVI -an ++ ++FATE_VIDEO += fate-auravision-v2 ++fate-auravision-v2: CMD = framecrc -i $(SAMPLES)/auravision/salma-hayek-in-ugly-betty-partial-avi -an ++ ++FATE_VIDEO += fate-bethsoft-vid ++fate-bethsoft-vid: CMD = framecrc -i $(SAMPLES)/bethsoft-vid/ANIM0001.VID -vsync 0 -t 5 -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-bfi ++fate-bfi: CMD = framecrc -i $(SAMPLES)/bfi/2287.bfi -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-bink-video ++fate-bink-video: CMD = framecrc -i $(SAMPLES)/bink/hol2br.bik ++ ++FATE_VIDEO += fate-cdgraphics ++fate-cdgraphics: CMD = framecrc -i $(SAMPLES)/cdgraphics/BrotherJohn.cdg -pix_fmt rgb24 -t 1 ++ ++FATE_VIDEO += fate-cljr ++fate-cljr: CMD = framecrc -i $(SAMPLES)/cljr/testcljr-partial.avi ++ ++FATE_VIDEO += fate-corepng ++fate-corepng: CMD = framecrc -i $(SAMPLES)/png1/corepng-partial.avi ++ ++FATE_VIDEO += fate-creatureshock-avs ++fate-creatureshock-avs: CMD = framecrc -i $(SAMPLES)/creatureshock-avs/OUTATIME.AVS -pix_fmt rgb24 ++ ++FATE_CVID += fate-cvid-partial ++fate-cvid-partial: CMD = framecrc -i $(SAMPLES)/cvid/laracroft-cinepak-partial.avi -an ++ ++FATE_CVID += fate-cvid-palette ++fate-cvid-palette: CMD = framecrc -i $(SAMPLES)/cvid/catfight-cvid-pal8-partial.mov -pix_fmt rgb24 -an ++ ++FATE_CVID += fate-cvid-grayscale ++fate-cvid-grayscale: CMD = framecrc -i $(SAMPLES)/cvid/pcitva15.avi -an ++ ++FATE_VIDEO += $(FATE_CVID) ++fate-cvid: $(FATE_CVID) ++ ++FATE_VIDEO += fate-cyberia-c93 ++fate-cyberia-c93: CMD = framecrc -i $(SAMPLES)/cyberia-c93/intro1.c93 -t 3 -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-cyuv ++fate-cyuv: CMD = framecrc -i $(SAMPLES)/cyuv/cyuv.avi ++ ++FATE_VIDEO += fate-delphine-cin ++fate-delphine-cin: CMD = framecrc -i $(SAMPLES)/delphine-cin/LOGO-partial.CIN -pix_fmt rgb24 -vsync 0 ++ ++FATE_VIDEO += fate-deluxepaint-anm ++fate-deluxepaint-anm: CMD = framecrc -i $(SAMPLES)/deluxepaint-anm/INTRO1.ANM -pix_fmt rgb24 ++ ++FATE_TRUEMOTION1 += fate-truemotion1-15 ++fate-truemotion1-15: CMD = framecrc -i $(SAMPLES)/duck/phant2-940.duk -pix_fmt rgb24 ++ ++FATE_TRUEMOTION1 += fate-truemotion1-24 ++fate-truemotion1-24: CMD = framecrc -i $(SAMPLES)/duck/sonic3dblast_intro-partial.avi -pix_fmt rgb24 ++ ++FATE_VIDEO += $(FATE_TRUEMOTION1) ++fate-truemotion1: $(FATE_TRUEMOTION1) ++ ++FATE_VIDEO += fate-truemotion2 ++fate-truemotion2: CMD = framecrc -i $(SAMPLES)/duck/tm20.avi ++ ++FATE_DXA += fate-dxa-feeble ++fate-dxa-feeble: CMD = framecrc -i $(SAMPLES)/dxa/meetsquid.dxa -t 2 -pix_fmt rgb24 ++ ++FATE_DXA += fate-dxa-scummvm ++fate-dxa-scummvm: CMD = framecrc -i $(SAMPLES)/dxa/scummvm.dxa -pix_fmt rgb24 ++ ++FATE_VIDEO += $(FATE_DXA) ++fate-dxa: $(FATE_DXA) ++ ++FATE_FLIC += fate-flic-af11-palette-change ++fate-flic-af11-palette-change: CMD = framecrc -i $(SAMPLES)/fli/fli-engines.fli -t 3.3 -pix_fmt rgb24 ++ ++FATE_FLIC += fate-flic-af12 ++fate-flic-af12: CMD = framecrc -i $(SAMPLES)/fli/jj00c2.fli -pix_fmt rgb24 ++ ++FATE_FLIC += fate-flic-magiccarpet ++fate-flic-magiccarpet: CMD = framecrc -i $(SAMPLES)/fli/intel.dat -pix_fmt rgb24 ++ ++FATE_VIDEO += $(FATE_FLIC) ++fate-flic: $(FATE_FLIC) ++ ++FATE_VIDEO += fate-frwu ++fate-frwu: CMD = framecrc -i $(SAMPLES)/frwu/frwu.avi ++ ++FATE_VIDEO += fate-id-cin-video ++fate-id-cin-video: CMD = framecrc -i $(SAMPLES)/idcin/idlog-2MB.cin -pix_fmt rgb24 ++ ++FATE_VIDEO-$(CONFIG_AVFILTER) += fate-idroq-video-encode ++fate-idroq-video-encode: CMD = md5 -f image2 -vcodec pgmyuv -i $(SAMPLES)/ffmpeg-synthetic/vsynth1/%02d.pgm -sws_flags +bitexact -vf pad=512:512:80:112 -f RoQ -t 0.2 ++ ++FATE_IFF += fate-iff-byterun1 ++fate-iff-byterun1: CMD = framecrc -i $(SAMPLES)/iff/ASH.LBM -pix_fmt rgb24 ++ ++FATE_IFF += fate-iff-fibonacci ++fate-iff-fibonacci: CMD = md5 -i $(SAMPLES)/iff/dasboot-in-compressed -f s16le ++ ++FATE_IFF += fate-iff-ilbm ++fate-iff-ilbm: CMD = framecrc -i $(SAMPLES)/iff/lms-matriks.ilbm -pix_fmt rgb24 ++ ++FATE_VIDEO += $(FATE_IFF) ++fate-iff: $(FATE_IFF) ++ ++FATE_VIDEO += fate-kmvc ++fate-kmvc: CMD = framecrc -i $(SAMPLES)/KMVC/LOGO1.AVI -an -t 3 -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-mimic ++fate-mimic: CMD = framecrc -idct simple -i $(SAMPLES)/mimic/mimic2-womanloveffmpeg.cam -vsync 0 ++ ++FATE_VIDEO += fate-mjpegb ++fate-mjpegb: CMD = framecrc -idct simple -flags +bitexact -i $(SAMPLES)/mjpegb/mjpegb_part.mov -an ++ ++FATE_VIDEO += fate-motionpixels ++fate-motionpixels: CMD = framecrc -i $(SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24 -vframes 111 ++ ++FATE_VIDEO += fate-mpeg2-field-enc ++fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an ++ ++FATE_VIDEO += fate-nuv ++fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv -vsync 0 ++ ++FATE_VIDEO += fate-qpeg ++fate-qpeg: CMD = framecrc -i $(SAMPLES)/qpeg/Clock.avi -an -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-r210 ++fate-r210: CMD = framecrc -i $(SAMPLES)/r210/r210.avi -pix_fmt rgb48le ++ ++FATE_VIDEO += fate-rl2 ++fate-rl2: CMD = framecrc -i $(SAMPLES)/rl2/Z4915300.RL2 -pix_fmt rgb24 -an -vsync 0 ++ ++FATE_VIDEO += fate-smacker ++fate-smacker: CMD = framecrc -i $(SAMPLES)/smacker/wetlogo.smk -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-smc ++fate-smc: CMD = framecrc -i $(SAMPLES)/smc/cass_schi.qt -vsync 0 -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-sp5x ++fate-sp5x: CMD = framecrc -idct simple -i $(SAMPLES)/sp5x/sp5x_problem.avi ++ ++FATE_VIDEO += fate-sub-srt ++fate-sub-srt: CMD = md5 -i $(SAMPLES)/sub/SubRip_capability_tester.srt -f ass ++ ++FATE_VIDEO += fate-tiertex-seq ++fate-tiertex-seq: CMD = framecrc -i $(SAMPLES)/tiertex-seq/Gameover.seq -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-tmv ++fate-tmv: CMD = framecrc -i $(SAMPLES)/tmv/pop-partial.tmv -pix_fmt rgb24 ++ ++FATE_TXD += fate-txd-16bpp ++fate-txd-16bpp: CMD = framecrc -i $(SAMPLES)/txd/misc.txd -pix_fmt bgra -an ++ ++FATE_TXD += fate-txd-pal8 ++fate-txd-pal8: CMD = framecrc -i $(SAMPLES)/txd/outro.txd -pix_fmt rgb24 -an ++ ++FATE_VIDEO += $(FATE_TXD) ++fate-txd: $(FATE_TXD) ++ ++FATE_VIDEO += fate-ulti ++fate-ulti: CMD = framecrc -i $(SAMPLES)/ulti/hit12w.avi -an ++ ++FATE_VIDEO += fate-v210 ++fate-v210: CMD = framecrc -i $(SAMPLES)/v210/v210_720p-partial.avi -pix_fmt yuv422p16be -an ++ ++FATE_VIDEO += fate-v410dec ++fate-v410dec: CMD = framecrc -i $(SAMPLES)/v410/lenav410.mov -pix_fmt yuv444p10le ++ ++FATE_VIDEO += fate-v410enc ++fate-v410enc: tests/vsynth1/00.pgm ++fate-v410enc: CMD = md5 -f image2 -vcodec pgmyuv -i $(TARGET_PATH)/tests/vsynth1/%02d.pgm -flags +bitexact -vcodec v410 -f avi ++ ++FATE_VIDEO += fate-vcr1 ++fate-vcr1: CMD = framecrc -i $(SAMPLES)/vcr1/VCR1test.avi -an ++ ++FATE_VIDEO += fate-videoxl ++fate-videoxl: CMD = framecrc -i $(SAMPLES)/vixl/pig-vixl.avi ++ ++FATE_VIDEO += fate-vqa-cc ++fate-vqa-cc: CMD = framecrc -i $(SAMPLES)/vqa/cc-demo1-partial.vqa -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-wc3movie-xan ++fate-wc3movie-xan: CMD = framecrc -i $(SAMPLES)/wc3movie/SC_32-part.MVE -pix_fmt rgb24 ++ ++FATE_VIDEO += fate-wnv1 ++fate-wnv1: CMD = framecrc -i $(SAMPLES)/wnv1/wnv1-codec.avi -an ++ ++FATE_VIDEO += fate-yop ++fate-yop: CMD = framecrc -i $(SAMPLES)/yop/test1.yop -pix_fmt rgb24 -an ++ ++FATE_VIDEO += fate-xxan-wc4 ++fate-xxan-wc4: CMD = framecrc -i $(SAMPLES)/wc4-xan/wc4trailer-partial.avi -an ++ ++FATE_TESTS += $(FATE_VIDEO) ++fate-video: $(FATE_VIDEO) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/voice.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/voice.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/voice.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/voice.mak 2012-05-14 14:08:55.590365260 +0200 +@@ -0,0 +1,28 @@ ++FATE_VOICE += fate-g722dec-1 ++fate-g722dec-1: CMD = framecrc -i $(SAMPLES)/g722/conf-adminmenu-162.g722 ++ ++FATE_VOICE += fate-g722enc ++fate-g722enc: tests/data/asynth-16000-1.sw ++fate-g722enc: CMD = md5 -ar 16000 -ac 1 -f s16le -i $(TARGET_PATH)/tests/data/asynth-16000-1.sw -acodec g722 -ac 1 -f g722 ++ ++FATE_GSM += fate-gsm-ms ++fate-gsm-ms: CMD = framecrc -i $(SAMPLES)/gsm/ciao.wav ++ ++FATE_GSM += fate-gsm-toast ++fate-gsm-toast: CMD = framecrc -i $(SAMPLES)/gsm/sample-gsm-8000.mov -t 10 ++ ++FATE_VOICE += $(FATE_GSM) ++fate-gsm: $(FATE_GSM) ++ ++FATE_VOICE += fate-qcelp ++fate-qcelp: CMD = pcm -i $(SAMPLES)/qcp/0036580847.QCP ++fate-qcelp: CMP = oneoff ++fate-qcelp: REF = $(SAMPLES)/qcp/0036580847.pcm ++ ++FATE_VOICE += fate-truespeech ++fate-truespeech: CMD = pcm -i $(SAMPLES)/truespeech/a6.wav ++fate-truespeech: CMP = oneoff ++fate-truespeech: REF = $(SAMPLES)/truespeech/a6.pcm ++ ++FATE_TESTS += $(FATE_VOICE) ++fate-voice: $(FATE_VOICE) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vp8.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vp8.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vp8.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vp8.mak 1970-01-01 01:00:00.000000000 +0100 +@@ -1,20 +0,0 @@ +-VP8_SUITE = 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 +- +-define FATE_VP8_SUITE +-FATE_VP8 += fate-vp8-test-vector$(2)-$(1) +-fate-vp8-test-vector$(2)-$(1): CMD = framemd5 $(3) -i $(SAMPLES)/vp8-test-vectors-r1/vp80-00-comprehensive-$(1).ivf +-fate-vp8-test-vector$(2)-$(1): REF = $(SRC_PATH_BARE)/tests/ref/fate/vp8-test-vector-$(1) +-endef +- +-define FATE_VP8_FULL +-$(foreach N,$(VP8_SUITE),$(eval $(call FATE_VP8_SUITE,$(N),$(1),$(2)))) +- +-FATE_VP8 += fate-vp8-sign-bias$(1) +-fate-vp8-sign-bias$(1): CMD = framemd5 $(2) -i $(SAMPLES)/vp8/sintel-signbias.ivf +-fate-vp8-sign-bias$(1): REF = $(SRC_PATH_BARE)/tests/ref/fate/vp8-sign-bias +-endef +- +-$(eval $(call FATE_VP8_FULL)) +-$(eval $(call FATE_VP8_FULL,-emu-edge,-flags emu_edge)) +-FATE_TESTS += $(FATE_VP8) +-fate-vp8: $(FATE_VP8) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vpx.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vpx.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vpx.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vpx.mak 2012-05-14 14:08:55.591365280 +0200 +@@ -0,0 +1,44 @@ ++FATE_TESTS += fate-ea-vp60 ++fate-ea-vp60: CMD = framecrc -i $(SAMPLES)/ea-vp6/g36.vp6 ++ ++FATE_TESTS += fate-ea-vp61 ++fate-ea-vp61: CMD = framecrc -i $(SAMPLES)/ea-vp6/MovieSkirmishGondor.vp6 -t 4 ++ ++FATE_VP3 += fate-vp31 ++fate-vp31: CMD = framecrc -i $(SAMPLES)/vp3/vp31.avi ++ ++FATE_VP3 += fate-vp3-coeff-level64 ++fate-vp3-coeff-level64: CMD = framecrc -i $(SAMPLES)/vp3/coeff_level64.mkv ++ ++FATE_TESTS += $(FATE_VP3) ++fate-vp3: $(FATE_VP3) ++ ++FATE_TESTS += fate-vp5 ++fate-vp5: CMD = framecrc -i $(SAMPLES)/vp5/potter512-400-partial.avi -an ++ ++FATE_TESTS += fate-vp6a ++fate-vp6a: CMD = framecrc -i $(SAMPLES)/flash-vp6/300x180-Scr-f8-056alpha.flv ++ ++FATE_TESTS += fate-vp6f ++fate-vp6f: CMD = framecrc -i $(SAMPLES)/flash-vp6/clip1024.flv ++ ++VP8_SUITE = 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 ++ ++define FATE_VP8_SUITE ++FATE_VP8 += fate-vp8-test-vector$(2)-$(1) ++fate-vp8-test-vector$(2)-$(1): CMD = framemd5 $(3) -i $(SAMPLES)/vp8-test-vectors-r1/vp80-00-comprehensive-$(1).ivf ++fate-vp8-test-vector$(2)-$(1): REF = $(SRC_PATH)/tests/ref/fate/vp8-test-vector-$(1) ++endef ++ ++define FATE_VP8_FULL ++$(foreach N,$(VP8_SUITE),$(eval $(call FATE_VP8_SUITE,$(N),$(1),$(2)))) ++ ++FATE_VP8 += fate-vp8-sign-bias$(1) ++fate-vp8-sign-bias$(1): CMD = framemd5 $(2) -i $(SAMPLES)/vp8/sintel-signbias.ivf -vsync 0 ++fate-vp8-sign-bias$(1): REF = $(SRC_PATH)/tests/ref/fate/vp8-sign-bias ++endef ++ ++$(eval $(call FATE_VP8_FULL)) ++$(eval $(call FATE_VP8_FULL,-emu-edge,-flags emu_edge)) ++FATE_TESTS += $(FATE_VP8) ++fate-vp8: $(FATE_VP8) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vqf.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vqf.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/vqf.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/vqf.mak 2012-05-14 14:08:55.591365280 +0200 +@@ -0,0 +1,10 @@ ++FATE_VQF += fate-twinvq ++fate-twinvq: CMD = pcm -i $(SAMPLES)/vqf/achterba.vqf ++fate-twinvq: CMP = oneoff ++fate-twinvq: REF = $(SAMPLES)/vqf/achterba.pcm ++ ++FATE_VQF += fate-vqf-demux ++fate-vqf-demux: CMD = md5 -i $(SAMPLES)/vqf/achterba.vqf -acodec copy -f framecrc ++ ++FATE_TESTS += $(FATE_VQF) ++fate-vqf: $(FATE_VQF) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/wma.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/wma.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate/wma.mak 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate/wma.mak 2012-05-14 14:08:55.592365300 +0200 +@@ -0,0 +1,38 @@ ++FATE_WMAPRO += fate-wmapro-2ch ++fate-wmapro-2ch: CMD = pcm -i $(SAMPLES)/wmapro/Beethovens_9th-1_small.wma ++fate-wmapro-2ch: CMP = oneoff ++fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm ++ ++FATE_WMAPRO += fate-wmapro-5.1 ++fate-wmapro-5.1: CMD = pcm -i $(SAMPLES)/wmapro/latin_192_mulitchannel_cut.wma ++fate-wmapro-5.1: CMP = oneoff ++fate-wmapro-5.1: REF = $(SAMPLES)/wmapro/latin_192_mulitchannel_cut.pcm ++ ++FATE_WMAPRO += fate-wmapro-ism ++fate-wmapro-ism: CMD = pcm -i $(SAMPLES)/isom/vc1-wmapro.ism -vn ++fate-wmapro-ism: CMP = oneoff ++fate-wmapro-ism: REF = $(SAMPLES)/isom/vc1-wmapro.pcm ++ ++FATE_TESTS += $(FATE_WMAPRO) ++fate-wmapro: $(FATE_WMAPRO) ++ ++FATE_WMAVOICE += fate-wmavoice-7k ++fate-wmavoice-7k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-7K.wma ++fate-wmavoice-7k: CMP = stddev ++fate-wmavoice-7k: REF = $(SAMPLES)/wmavoice/streaming_CBR-7K.pcm ++fate-wmavoice-7k: FUZZ = 3 ++ ++FATE_WMAVOICE += fate-wmavoice-11k ++fate-wmavoice-11k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-11K.wma ++fate-wmavoice-11k: CMP = stddev ++fate-wmavoice-11k: REF = $(SAMPLES)/wmavoice/streaming_CBR-11K.pcm ++fate-wmavoice-11k: FUZZ = 3 ++ ++FATE_WMAVOICE += fate-wmavoice-19k ++fate-wmavoice-19k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-19K.wma ++fate-wmavoice-19k: CMP = stddev ++fate-wmavoice-19k: REF = $(SAMPLES)/wmavoice/streaming_CBR-19K.pcm ++fate-wmavoice-19k: FUZZ = 3 ++ ++FATE_TESTS += $(FATE_WMAVOICE) ++fate-wmavoice: $(FATE_WMAVOICE) +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate2.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate2.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate2.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate2.mak 1970-01-01 01:00:00.000000000 +0100 +@@ -1,332 +0,0 @@ +-FATE_TESTS += fate-twinvq +-fate-twinvq: CMD = pcm -i $(SAMPLES)/vqf/achterba.vqf +-fate-twinvq: CMP = oneoff +-fate-twinvq: REF = $(SAMPLES)/vqf/achterba.pcm +- +-FATE_TESTS += fate-sipr-16k +-fate-sipr-16k: CMD = pcm -i $(SAMPLES)/sipr/sipr_16k.rm +-fate-sipr-16k: CMP = oneoff +-fate-sipr-16k: REF = $(SAMPLES)/sipr/sipr_16k.pcm +- +-FATE_TESTS += fate-sipr-8k5 +-fate-sipr-8k5: CMD = pcm -i $(SAMPLES)/sipr/sipr_8k5.rm +-fate-sipr-8k5: CMP = oneoff +-fate-sipr-8k5: REF = $(SAMPLES)/sipr/sipr_8k5.pcm +- +-FATE_TESTS += fate-sipr-6k5 +-fate-sipr-6k5: CMD = pcm -i $(SAMPLES)/sipr/sipr_6k5.rm +-fate-sipr-6k5: CMP = oneoff +-fate-sipr-6k5: REF = $(SAMPLES)/sipr/sipr_6k5.pcm +- +-FATE_TESTS += fate-sipr-5k0 +-fate-sipr-5k0: CMD = pcm -i $(SAMPLES)/sipr/sipr_5k0.rm +-fate-sipr-5k0: CMP = oneoff +-fate-sipr-5k0: REF = $(SAMPLES)/sipr/sipr_5k0.pcm +- +-FATE_TESTS += fate-ra-288 +-fate-ra-288: CMD = pcm -i $(SAMPLES)/real/ra_288.rm +-fate-ra-288: CMP = oneoff +-fate-ra-288: REF = $(SAMPLES)/real/ra_288.pcm +-fate-ra-288: FUZZ = 2 +- +-FATE_TESTS += fate-ra-cook +-fate-ra-cook: CMD = pcm -i $(SAMPLES)/real/ra_cook.rm +-fate-ra-cook: CMP = oneoff +-fate-ra-cook: REF = $(SAMPLES)/real/ra_cook.pcm +- +-FATE_TESTS += fate-mpeg2-field-enc +-fate-mpeg2-field-enc: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/mpeg2/mpeg2_field_encoding.ts -an +- +-FATE_TESTS += fate-qcelp +-fate-qcelp: CMD = pcm -i $(SAMPLES)/qcp/0036580847.QCP +-fate-qcelp: CMP = oneoff +-fate-qcelp: REF = $(SAMPLES)/qcp/0036580847.pcm +- +-FATE_TESTS += fate-qdm2 +-fate-qdm2: CMD = pcm -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-QDM2.mov +-fate-qdm2: CMP = oneoff +-fate-qdm2: REF = $(SAMPLES)/qt-surge-suite/surge-2-16-B-QDM2.pcm +-fate-qdm2: FUZZ = 2 +- +-FATE_TESTS += fate-imc +-fate-imc: CMD = pcm -i $(SAMPLES)/imc/imc.avi +-fate-imc: CMP = oneoff +-fate-imc: REF = $(SAMPLES)/imc/imc.pcm +- +-FATE_TESTS += fate-yop +-fate-yop: CMD = framecrc -i $(SAMPLES)/yop/test1.yop -pix_fmt rgb24 -an +- +-FATE_TESTS += fate-pictor +-fate-pictor: CMD = framecrc -i $(SAMPLES)/pictor/MFISH.PIC -pix_fmt rgb24 -an +- +-FATE_TESTS += fate-dts +-fate-dts: CMD = pcm -i $(SAMPLES)/dts/dts.ts +-fate-dts: CMP = oneoff +-fate-dts: REF = $(SAMPLES)/dts/dts.pcm +- +-FATE_TESTS += fate-nellymoser +-fate-nellymoser: CMD = pcm -i $(SAMPLES)/nellymoser/nellymoser.flv +-fate-nellymoser: CMP = oneoff +-fate-nellymoser: REF = $(SAMPLES)/nellymoser/nellymoser.pcm +- +-FATE_TESTS += fate-truespeech +-fate-truespeech: CMD = pcm -i $(SAMPLES)/truespeech/a6.wav +-fate-truespeech: CMP = oneoff +-fate-truespeech: REF = $(SAMPLES)/truespeech/a6.pcm +- +-FATE_TESTS += fate-ac3-2.0 +-fate-ac3-2.0: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_2.0_192_small.ac3 +-fate-ac3-2.0: CMP = oneoff +-fate-ac3-2.0: REF = $(SAMPLES)/ac3/monsters_inc_2.0_192_small.pcm +- +-FATE_TESTS += fate-ac3-5.1 +-fate-ac3-5.1: CMD = pcm -i $(SAMPLES)/ac3/monsters_inc_5.1_448_small.ac3 +-fate-ac3-5.1: CMP = oneoff +-fate-ac3-5.1: REF = $(SAMPLES)/ac3/monsters_inc_5.1_448_small.pcm +- +-FATE_TESTS += fate-eac3-1 +-fate-eac3-1: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.eac3 +-fate-eac3-1: CMP = oneoff +-fate-eac3-1: REF = $(SAMPLES)/eac3/csi_miami_5.1_256_spx_small.pcm +- +-FATE_TESTS += fate-eac3-2 +-fate-eac3-2: CMD = pcm -i $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.eac3 +-fate-eac3-2: CMP = oneoff +-fate-eac3-2: REF = $(SAMPLES)/eac3/csi_miami_stereo_128_spx_small.pcm +- +-FATE_TESTS += fate-eac3-3 +-fate-eac3-3: CMD = pcm -i $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.eac3 +-fate-eac3-3: CMP = oneoff +-fate-eac3-3: REF = $(SAMPLES)/eac3/matrix2_commentary1_stereo_192_small.pcm +- +-FATE_TESTS += fate-eac3-4 +-fate-eac3-4: CMD = pcm -i $(SAMPLES)/eac3/serenity_english_5.1_1536_small.eac3 +-fate-eac3-4: CMP = oneoff +-fate-eac3-4: REF = $(SAMPLES)/eac3/serenity_english_5.1_1536_small.pcm +- +-FATE_TESTS += fate-atrac1 +-fate-atrac1: CMD = pcm -i $(SAMPLES)/atrac1/test_tones_small.aea +-fate-atrac1: CMP = oneoff +-fate-atrac1: REF = $(SAMPLES)/atrac1/test_tones_small.pcm +- +-FATE_TESTS += fate-atrac3-1 +-fate-atrac3-1: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_066_small.wav +-fate-atrac3-1: CMP = oneoff +-fate-atrac3-1: REF = $(SAMPLES)/atrac3/mc_sich_at3_066_small.pcm +- +-FATE_TESTS += fate-atrac3-2 +-fate-atrac3-2: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_105_small.wav +-fate-atrac3-2: CMP = oneoff +-fate-atrac3-2: REF = $(SAMPLES)/atrac3/mc_sich_at3_105_small.pcm +- +-FATE_TESTS += fate-atrac3-3 +-fate-atrac3-3: CMD = pcm -i $(SAMPLES)/atrac3/mc_sich_at3_132_small.wav +-fate-atrac3-3: CMP = oneoff +-fate-atrac3-3: REF = $(SAMPLES)/atrac3/mc_sich_at3_132_small.pcm +- +-FATE_TESTS += fate-gsm +-fate-gsm: CMD = framecrc -t 10 -i $(SAMPLES)/gsm/sample-gsm-8000.mov +- +-FATE_TESTS += fate-gsm-ms +-fate-gsm-ms: CMD = framecrc -i $(SAMPLES)/gsm/ciao.wav +- +-FATE_TESTS += fate-g722dec-1 +-fate-g722dec-1: CMD = framecrc -ar 16000 -i $(SAMPLES)/g722/conf-adminmenu-162.g722 +- +-FATE_TESTS += fate-msmpeg4v1 +-fate-msmpeg4v1: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/msmpeg4v1/mpg4.avi -an +- +-FATE_TESTS += fate-wmavoice-7k +-fate-wmavoice-7k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-7K.wma +-fate-wmavoice-7k: CMP = stddev +-fate-wmavoice-7k: REF = $(SAMPLES)/wmavoice/streaming_CBR-7K.pcm +-fate-wmavoice-7k: FUZZ = 3 +- +-FATE_TESTS += fate-wmavoice-11k +-fate-wmavoice-11k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-11K.wma +-fate-wmavoice-11k: CMP = stddev +-fate-wmavoice-11k: REF = $(SAMPLES)/wmavoice/streaming_CBR-11K.pcm +-fate-wmavoice-11k: FUZZ = 3 +- +-FATE_TESTS += fate-wmavoice-19k +-fate-wmavoice-19k: CMD = pcm -i $(SAMPLES)/wmavoice/streaming_CBR-19K.wma +-fate-wmavoice-19k: CMP = stddev +-fate-wmavoice-19k: REF = $(SAMPLES)/wmavoice/streaming_CBR-19K.pcm +-fate-wmavoice-19k: FUZZ = 3 +- +-FATE_TESTS += fate-wmapro-5.1 +-fate-wmapro-5.1: CMD = pcm -i $(SAMPLES)/wmapro/latin_192_mulitchannel_cut.wma +-fate-wmapro-5.1: CMP = oneoff +-fate-wmapro-5.1: REF = $(SAMPLES)/wmapro/latin_192_mulitchannel_cut.pcm +- +-FATE_TESTS += fate-wmapro-2ch +-fate-wmapro-2ch: CMD = pcm -i $(SAMPLES)/wmapro/Beethovens_9th-1_small.wma +-fate-wmapro-2ch: CMP = oneoff +-fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm +- +-FATE_TESTS += fate-ansi +-fate-ansi: CMD = framecrc -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24 +- +-FATE_TESTS += fate-wmv8-drm +-# discard last packet to avoid fails due to overread of VC-1 decoder +-fate-wmv8-drm: CMD = framecrc -cryptokey 137381538c84c068111902a59c5cf6c340247c39 -i $(SAMPLES)/wmv8/wmv_drm.wmv -an -vframes 162 +- +-FATE_TESTS += fate-wmv8-drm-nodec +-fate-wmv8-drm-nodec: CMD = framecrc -cryptokey 137381538c84c068111902a59c5cf6c340247c39 -i $(SAMPLES)/wmv8/wmv_drm.wmv -acodec copy -vcodec copy +- +-FATE_TESTS += fate-binkaudio-dct +-fate-binkaudio-dct: CMD = pcm -i $(SAMPLES)/bink/binkaudio_dct.bik +-fate-binkaudio-dct: CMP = oneoff +-fate-binkaudio-dct: REF = $(SAMPLES)/bink/binkaudio_dct.pcm +-fate-binkaudio-dct: FUZZ = 2 +- +-FATE_TESTS += fate-binkaudio-rdft +-fate-binkaudio-rdft: CMD = pcm -i $(SAMPLES)/bink/binkaudio_rdft.bik +-fate-binkaudio-rdft: CMP = oneoff +-fate-binkaudio-rdft: REF = $(SAMPLES)/bink/binkaudio_rdft.pcm +-fate-binkaudio-rdft: FUZZ = 2 +- +-FATE_TESTS += fate-txd-pal8 +-fate-txd-pal8: CMD = framecrc -i $(SAMPLES)/txd/outro.txd -pix_fmt rgb24 -an +- +-FATE_TESTS += fate-txd-16bpp +-fate-txd-16bpp: CMD = framecrc -i $(SAMPLES)/txd/misc.txd -pix_fmt bgra -an +- +-FATE_TESTS += fate-vp3 +-fate-vp3: CMD = framecrc -i $(SAMPLES)/vp3/vp31.avi +- +-FATE_TESTS += fate-fax-g3 +-fate-fax-g3: CMD = framecrc -i $(SAMPLES)/CCITT_fax/G31D.TIF +- +-FATE_TESTS += fate-fax-g3s +-fate-fax-g3s: CMD = framecrc -i $(SAMPLES)/CCITT_fax/G31DS.TIF +- +-FATE_TESTS += fate-ws_snd +-fate-ws_snd: CMD = md5 -i $(SAMPLES)/vqa/ws_snd.vqa -f s16le +- +-FATE_TESTS += fate-dxa-scummvm +-fate-dxa-scummvm: CMD = framecrc -i $(SAMPLES)/dxa/scummvm.dxa -pix_fmt rgb24 +- +-FATE_TESTS += fate-mjpegb +-fate-mjpegb: CMD = framecrc -idct simple -flags +bitexact -i $(SAMPLES)/mjpegb/mjpegb_part.mov -an +- +-FATE_TESTS += fate-rv30 +-fate-rv30: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i $(SAMPLES)/real/rv30.rm -an +- +-FATE_TESTS += fate-sha +-fate-sha: libavutil/sha-test$(EXESUF) +-fate-sha: CMD = run libavutil/sha-test +- +-FATE_TESTS += fate-musepack7 +-fate-musepack7: CMD = pcm -i $(SAMPLES)/musepack/inside-mp7.mpc +-fate-musepack7: CMP = oneoff +-fate-musepack7: REF = $(SAMPLES)/musepack/inside-mp7.pcm +-fate-musepack7: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-4k75 +-fate-amrnb-4k75: CMD = pcm -i $(SAMPLES)/amrnb/4.75k.amr +-fate-amrnb-4k75: CMP = stddev +-fate-amrnb-4k75: REF = $(SAMPLES)/amrnb/4.75k.pcm +-fate-amrnb-4k75: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-5k15 +-fate-amrnb-5k15: CMD = pcm -i $(SAMPLES)/amrnb/5.15k.amr +-fate-amrnb-5k15: CMP = stddev +-fate-amrnb-5k15: REF = $(SAMPLES)/amrnb/5.15k.pcm +-fate-amrnb-5k15: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-5k9 +-fate-amrnb-5k9: CMD = pcm -i $(SAMPLES)/amrnb/5.9k.amr +-fate-amrnb-5k9: CMP = stddev +-fate-amrnb-5k9: REF = $(SAMPLES)/amrnb/5.9k.pcm +-fate-amrnb-5k9: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-6k7 +-fate-amrnb-6k7: CMD = pcm -i $(SAMPLES)/amrnb/6.7k.amr +-fate-amrnb-6k7: CMP = stddev +-fate-amrnb-6k7: REF = $(SAMPLES)/amrnb/6.7k.pcm +-fate-amrnb-6k7: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-7k4 +-fate-amrnb-7k4: CMD = pcm -i $(SAMPLES)/amrnb/7.4k.amr +-fate-amrnb-7k4: CMP = stddev +-fate-amrnb-7k4: REF = $(SAMPLES)/amrnb/7.4k.pcm +-fate-amrnb-7k4: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-7k95 +-fate-amrnb-7k95: CMD = pcm -i $(SAMPLES)/amrnb/7.95k.amr +-fate-amrnb-7k95: CMP = stddev +-fate-amrnb-7k95: REF = $(SAMPLES)/amrnb/7.95k.pcm +-fate-amrnb-7k95: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-10k2 +-fate-amrnb-10k2: CMD = pcm -i $(SAMPLES)/amrnb/10.2k.amr +-fate-amrnb-10k2: CMP = stddev +-fate-amrnb-10k2: REF = $(SAMPLES)/amrnb/10.2k.pcm +-fate-amrnb-10k2: FUZZ = 1 +- +-FATE_TESTS += fate-amrnb-12k2 +-fate-amrnb-12k2: CMD = pcm -i $(SAMPLES)/amrnb/12.2k.amr +-fate-amrnb-12k2: CMP = stddev +-fate-amrnb-12k2: REF = $(SAMPLES)/amrnb/12.2k.pcm +-fate-amrnb-12k2: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-6k60 +-fate-amrwb-6k60: CMD = pcm -i $(SAMPLES)/amrwb/seed-6k60.awb +-fate-amrwb-6k60: CMP = stddev +-fate-amrwb-6k60: REF = $(SAMPLES)/amrwb/seed-6k60.pcm +-fate-amrwb-6k60: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-8k85 +-fate-amrwb-8k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-8k85.awb +-fate-amrwb-8k85: CMP = stddev +-fate-amrwb-8k85: REF = $(SAMPLES)/amrwb/seed-8k85.pcm +-fate-amrwb-8k85: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-12k65 +-fate-amrwb-12k65: CMD = pcm -i $(SAMPLES)/amrwb/seed-12k65.awb +-fate-amrwb-12k65: CMP = stddev +-fate-amrwb-12k65: REF = $(SAMPLES)/amrwb/seed-12k65.pcm +-fate-amrwb-12k65: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-14k25 +-fate-amrwb-14k25: CMD = pcm -i $(SAMPLES)/amrwb/seed-14k25.awb +-fate-amrwb-14k25: CMP = stddev +-fate-amrwb-14k25: REF = $(SAMPLES)/amrwb/seed-14k25.pcm +-fate-amrwb-14k25: FUZZ = 2.6 +- +-FATE_TESTS += fate-amrwb-15k85 +-fate-amrwb-15k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-15k85.awb +-fate-amrwb-15k85: CMP = stddev +-fate-amrwb-15k85: REF = $(SAMPLES)/amrwb/seed-15k85.pcm +-fate-amrwb-15k85: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-18k25 +-fate-amrwb-18k25: CMD = pcm -i $(SAMPLES)/amrwb/seed-18k25.awb +-fate-amrwb-18k25: CMP = stddev +-fate-amrwb-18k25: REF = $(SAMPLES)/amrwb/seed-18k25.pcm +-fate-amrwb-18k25: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-19k85 +-fate-amrwb-19k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-19k85.awb +-fate-amrwb-19k85: CMP = stddev +-fate-amrwb-19k85: REF = $(SAMPLES)/amrwb/seed-19k85.pcm +-fate-amrwb-19k85: FUZZ = 1 +- +-FATE_TESTS += fate-amrwb-23k05 +-fate-amrwb-23k05: CMD = pcm -i $(SAMPLES)/amrwb/seed-23k05.awb +-fate-amrwb-23k05: CMP = stddev +-fate-amrwb-23k05: REF = $(SAMPLES)/amrwb/seed-23k05.pcm +-fate-amrwb-23k05: FUZZ = 2 +- +-FATE_TESTS += fate-amrwb-23k85 +-fate-amrwb-23k85: CMD = pcm -i $(SAMPLES)/amrwb/seed-23k85.awb +-fate-amrwb-23k85: CMP = stddev +-fate-amrwb-23k85: REF = $(SAMPLES)/amrwb/seed-23k85.pcm +-fate-amrwb-23k85: FUZZ = 2 +- +-FATE_TESTS += fate-amrwb-23k85-2 +-fate-amrwb-23k85-2: CMD = pcm -i $(SAMPLES)/amrwb/deus-23k85.awb +-fate-amrwb-23k85-2: CMP = stddev +-fate-amrwb-23k85-2: REF = $(SAMPLES)/amrwb/deus-23k85.pcm +-fate-amrwb-23k85-2: FUZZ = 1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate_config.sh.template xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate_config.sh.template +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate_config.sh.template 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate_config.sh.template 2012-05-14 14:08:55.593365320 +0200 +@@ -0,0 +1,25 @@ ++slot= # some unique identifier ++repo=git://source.ffmpeg.org/ffmpeg.git # the source repository ++samples= # path to samples directory ++workdir= # directory in which to do all the work ++#fate_recv="ssh -T fate@fate.ffmpeg.org" # command to submit report ++comment= # optional description ++ ++# the following are optional and map to configure options ++arch= ++cpu= ++cross_prefix= ++cc= ++target_os= ++sysroot= ++target_exec= ++target_path= ++extra_cflags= ++extra_ldflags= ++extra_libs= ++extra_conf= # extra configure options not covered above ++ ++#make= # name of GNU make if not 'make' ++makeopts= # extra options passed to 'make' ++#tar= # command to create a tar archive from its arguments on stdout, ++ # defaults to 'tar c' +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate.mak xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate.mak +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate.mak 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate.mak 1970-01-01 01:00:00.000000000 +0100 +@@ -1,362 +0,0 @@ +-FATE_TESTS += fate-4xm-1 +-fate-4xm-1: CMD = framecrc -i $(SAMPLES)/4xm/version1.4xm -pix_fmt rgb24 -an +-FATE_TESTS += fate-4xm-2 +-fate-4xm-2: CMD = framecrc -i $(SAMPLES)/4xm/version2.4xm -pix_fmt rgb24 -an +-FATE_TESTS += fate-8bps +-fate-8bps: CMD = framecrc -i $(SAMPLES)/8bps/full9iron-partial.mov -pix_fmt rgb24 +-FATE_TESTS += fate-aac-demux +-fate-aac-demux: CMD = crc -i $(SAMPLES)/aac/ct_faac-adts.aac -acodec copy +-FATE_TESTS += fate-aasc +-fate-aasc: CMD = framecrc -i $(SAMPLES)/aasc/AASC-1.5MB.AVI -pix_fmt rgb24 +-FATE_TESTS += fate-adpcm-ea-r2 +-fate-adpcm-ea-r2: CMD = crc -i $(SAMPLES)/ea-mpc/THX_logo.mpc -vn +-FATE_TESTS += fate-adpcm-ea-r3 +-fate-adpcm-ea-r3: CMD = crc -i $(SAMPLES)/ea-vp6/THX_logo.vp6 -vn +-FATE_TESTS += fate-aea-demux +-fate-aea-demux: CMD = crc -i $(SAMPLES)/aea/chirp.aea -acodec copy +-FATE_TESTS += fate-alg-mm +-fate-alg-mm: CMD = framecrc -i $(SAMPLES)/alg-mm/ibmlogo.mm -an -pix_fmt rgb24 +-FATE_TESTS += fate-amv +-fate-amv: CMD = framecrc -idct simple -i $(SAMPLES)/amv/MTV_high_res_320x240_sample_Penguin_Joke_MTV_from_WMV.amv -t 10 +-FATE_TESTS += fate-armovie-escape124 +-fate-armovie-escape124: CMD = framecrc -i $(SAMPLES)/rpl/ESCAPE.RPL -pix_fmt rgb24 +-FATE_TESTS += fate-auravision +-fate-auravision: CMD = framecrc -i $(SAMPLES)/auravision/SOUVIDEO.AVI -an +-FATE_TESTS += fate-auravision-v2 +-fate-auravision-v2: CMD = framecrc -i $(SAMPLES)/auravision/salma-hayek-in-ugly-betty-partial-avi -an +-FATE_TESTS += fate-bethsoft-vid +-fate-bethsoft-vid: CMD = framecrc -i $(SAMPLES)/bethsoft-vid/ANIM0001.VID -vsync 0 -t 5 -pix_fmt rgb24 +-FATE_TESTS += fate-bfi +-fate-bfi: CMD = framecrc -i $(SAMPLES)/bfi/2287.bfi -pix_fmt rgb24 +-FATE_TESTS += fate-bink-demux +-fate-bink-demux: CMD = crc -i $(SAMPLES)/bink/Snd0a7d9b58.dee -vn -acodec copy +-FATE_TESTS += fate-bink-demux-video +-fate-bink-demux-video: CMD = framecrc -i $(SAMPLES)/bink/hol2br.bik +-FATE_TESTS += fate-caf +-fate-caf: CMD = crc -i $(SAMPLES)/caf/caf-pcm16.caf +-FATE_TESTS += fate-cdgraphics +-fate-cdgraphics: CMD = framecrc -t 1 -i $(SAMPLES)/cdgraphics/BrotherJohn.cdg -pix_fmt rgb24 +-FATE_TESTS += fate-cljr +-fate-cljr: CMD = framecrc -i $(SAMPLES)/cljr/testcljr-partial.avi +-FATE_TESTS += fate-corepng +-fate-corepng: CMD = framecrc -i $(SAMPLES)/png1/corepng-partial.avi +-FATE_TESTS += fate-creative-adpcm +-fate-creative-adpcm: CMD = md5 -i $(SAMPLES)/creative/intro-partial.wav -f s16le +-FATE_TESTS += fate-creative-adpcm-8-2.6bit +-fate-creative-adpcm-8-2.6bit: CMD = md5 -i $(SAMPLES)/creative/BBC_3BIT.VOC -f s16le +-FATE_TESTS += fate-creative-adpcm-8-2bit +-fate-creative-adpcm-8-2bit: CMD = md5 -i $(SAMPLES)/creative/BBC_2BIT.VOC -f s16le +-FATE_TESTS += fate-creative-adpcm-8-4bit +-fate-creative-adpcm-8-4bit: CMD = md5 -i $(SAMPLES)/creative/BBC_4BIT.VOC -f s16le +-FATE_TESTS += fate-creatureshock-avs +-fate-creatureshock-avs: CMD = framecrc -i $(SAMPLES)/creatureshock-avs/OUTATIME.AVS -pix_fmt rgb24 +-FATE_TESTS += fate-cryo-apc +-fate-cryo-apc: CMD = md5 -i $(SAMPLES)/cryo-apc/cine007.APC -f s16le +-FATE_TESTS += fate-cscd +-fate-cscd: CMD = framecrc -i $(SAMPLES)/CSCD/sample_video.avi -an -vsync 0 -pix_fmt rgb24 +-FATE_TESTS += fate-cvid +-fate-cvid: CMD = framecrc -i $(SAMPLES)/cvid/laracroft-cinepak-partial.avi -an +-FATE_TESTS += fate-cvid-palette +-fate-cvid-palette: CMD = framecrc -i $(SAMPLES)/cvid/catfight-cvid-pal8-partial.mov -pix_fmt rgb24 -an +-FATE_TESTS += fate-cyberia-c93 +-fate-cyberia-c93: CMD = framecrc -i $(SAMPLES)/cyberia-c93/intro1.c93 -t 3 -pix_fmt rgb24 +-FATE_TESTS += fate-cyuv +-fate-cyuv: CMD = framecrc -i $(SAMPLES)/cyuv/cyuv.avi +-FATE_TESTS += fate-d-cinema-demux +-fate-d-cinema-demux: CMD = framecrc -i $(SAMPLES)/d-cinema/THX_Science_FLT_1920-partial.302 -acodec copy -pix_fmt rgb24 +-FATE_TESTS += fate-delphine-cin +-fate-delphine-cin: CMD = framecrc -i $(SAMPLES)/delphine-cin/LOGO-partial.CIN -pix_fmt rgb24 -vsync 0 +-FATE_TESTS += fate-deluxepaint-anm +-fate-deluxepaint-anm: CMD = framecrc -i $(SAMPLES)/deluxepaint-anm/INTRO1.ANM -pix_fmt rgb24 +-FATE_TESTS += fate-dpx +-fate-dpx: CMD = framecrc -i $(SAMPLES)/dpx/lighthouse_rgb48.dpx +-FATE_TESTS += fate-duck-dk3 +-fate-duck-dk3: CMD = md5 -i $(SAMPLES)/duck/sop-audio-only.avi -f s16le +-FATE_TESTS += fate-duck-dk4 +-fate-duck-dk4: CMD = md5 -i $(SAMPLES)/duck/salsa-audio-only.avi -f s16le +-FATE_TESTS += fate-duck-tm2 +-fate-duck-tm2: CMD = framecrc -i $(SAMPLES)/duck/tm20.avi +-FATE_TESTS += fate-ea-cdata +-fate-ea-cdata: CMD = md5 -i $(SAMPLES)/ea-cdata/166b084d.46410f77.0009b440.24be960c.cdata -f s16le +-FATE_TESTS += fate-ea-cmv +-fate-ea-cmv: CMD = framecrc -i $(SAMPLES)/ea-cmv/TITLE.CMV -vsync 0 -pix_fmt rgb24 +-FATE_TESTS += fate-ea-dct +-fate-ea-dct: CMD = framecrc -idct simple -i $(SAMPLES)/ea-dct/NFS2Esprit-partial.dct +-FATE_TESTS += fate-ea-mad-adpcm-ea-r1 +-fate-ea-mad-adpcm-ea-r1: CMD = framecrc -i $(SAMPLES)/ea-mad/NFS6LogoE.mad +-FATE_TESTS += fate-ea-mad-pcm-planar +-fate-ea-mad-pcm-planar: CMD = framecrc -i $(SAMPLES)/ea-mad/xeasport.mad +-FATE_TESTS += fate-ea-tgq +-fate-ea-tgq: CMD = framecrc -i $(SAMPLES)/ea-tgq/v27.tgq -an +-FATE_TESTS += fate-ea-tgv-ima-ea-eacs +-fate-ea-tgv-ima-ea-eacs: CMD = framecrc -i $(SAMPLES)/ea-tgv/INTRO8K-partial.TGV -pix_fmt rgb24 +-FATE_TESTS += fate-ea-tgv-ima-ea-sead +-fate-ea-tgv-ima-ea-sead: CMD = framecrc -i $(SAMPLES)/ea-tgv/INTEL_S.TGV -pix_fmt rgb24 +-FATE_TESTS += fate-ea-tqi-adpcm +-fate-ea-tqi-adpcm: CMD = framecrc -i $(SAMPLES)/ea-wve/networkBackbone-partial.wve +-FATE_TESTS += fate-ea-vp60 +-fate-ea-vp60: CMD = framecrc -i $(SAMPLES)/ea-vp6/g36.vp6 +-FATE_TESTS += fate-ea-vp61 +-fate-ea-vp61: CMD = framecrc -i $(SAMPLES)/ea-vp6/MovieSkirmishGondor.vp6 -t 4 +-FATE_TESTS += fate-feeble-dxa +-fate-feeble-dxa: CMD = framecrc -i $(SAMPLES)/dxa/meetsquid.dxa -t 2 -pix_fmt rgb24 +-FATE_TESTS += fate-film-cvid-pcm-stereo-8bit +-fate-film-cvid-pcm-stereo-8bit: CMD = framecrc -i $(SAMPLES)/film/logo-capcom.cpk +-FATE_TESTS += fate-flic-af11-palette-change +-fate-flic-af11-palette-change: CMD = framecrc -i $(SAMPLES)/fli/fli-engines.fli -t 3.3 -pix_fmt rgb24 +-FATE_TESTS += fate-flic-af12 +-fate-flic-af12: CMD = framecrc -i $(SAMPLES)/fli/jj00c2.fli -pix_fmt rgb24 +-FATE_TESTS += fate-flic-magiccarpet +-fate-flic-magiccarpet: CMD = framecrc -i $(SAMPLES)/fli/intel.dat -pix_fmt rgb24 +-FATE_TESTS += fate-fraps-v0 +-fate-fraps-v0: CMD = framecrc -i $(SAMPLES)/fraps/Griffin_Ragdoll01-partial.avi +-FATE_TESTS += fate-fraps-v1 +-fate-fraps-v1: CMD = framecrc -i $(SAMPLES)/fraps/sample-v1.avi -an +-FATE_TESTS += fate-fraps-v2 +-fate-fraps-v2: CMD = framecrc -i $(SAMPLES)/fraps/test3-nosound-partial.avi +-FATE_TESTS += fate-fraps-v3 +-fate-fraps-v3: CMD = framecrc -i $(SAMPLES)/fraps/psclient-partial.avi -pix_fmt rgb24 +-FATE_TESTS += fate-fraps-v4 +-fate-fraps-v4: CMD = framecrc -i $(SAMPLES)/fraps/WoW_2006-11-03_14-58-17-19-nosound-partial.avi +-FATE_TESTS += fate-fraps-v5 +-fate-fraps-v5: CMD = framecrc -i $(SAMPLES)/fraps/fraps-v5-bouncing-balls-partial.avi +-FATE_TESTS += fate-frwu +-fate-frwu: CMD = framecrc -i $(SAMPLES)/frwu/frwu.avi +-FATE_TESTS += fate-funcom-iss +-fate-funcom-iss: CMD = md5 -i $(SAMPLES)/funcom-iss/0004010100.iss -f s16le +-FATE_TESTS += fate-id-cin-video +-fate-id-cin-video: CMD = framecrc -i $(SAMPLES)/idcin/idlog-2MB.cin -pix_fmt rgb24 +-FATE_TESTS += fate-idroq-video-dpcm +-fate-idroq-video-dpcm: CMD = framecrc -i $(SAMPLES)/idroq/idlogo.roq +-FATE_TESTS += fate-idroq-video-encode +-fate-idroq-video-encode: CMD = md5 -t 0.2 -f image2 -vcodec pgmyuv -i $(SAMPLES)/ffmpeg-synthetic/vsynth1/%02d.pgm -sws_flags +bitexact -vf pad=512:512:80:112 -f RoQ +-FATE_TESTS += fate-iff-byterun1 +-fate-iff-byterun1: CMD = framecrc -i $(SAMPLES)/iff/ASH.LBM -pix_fmt rgb24 +-FATE_TESTS += fate-iff-fibonacci +-fate-iff-fibonacci: CMD = md5 -i $(SAMPLES)/iff/dasboot-in-compressed -f s16le +-FATE_TESTS += fate-iff-ilbm +-fate-iff-ilbm: CMD = framecrc -i $(SAMPLES)/iff/lms-matriks.ilbm -pix_fmt rgb24 +-FATE_TESTS += fate-iff-pcm +-fate-iff-pcm: CMD = md5 -i $(SAMPLES)/iff/Bells -f s16le +-FATE_TESTS += fate-indeo2 +-fate-indeo2: CMD = framecrc -i $(SAMPLES)/rt21/VPAR0026.AVI +-FATE_TESTS += fate-indeo3 +-fate-indeo3: CMD = framecrc -i $(SAMPLES)/iv32/cubes.mov +-FATE_TESTS += fate-indeo5 +-fate-indeo5: CMD = framecrc -i $(SAMPLES)/iv50/Educ_Movie_DeadlyForce.avi -an +-FATE_TESTS += fate-interplay-mve-16bit +-fate-interplay-mve-16bit: CMD = framecrc -i $(SAMPLES)/interplay-mve/descent3-level5-16bit-partial.mve -pix_fmt rgb24 +-FATE_TESTS += fate-interplay-mve-8bit +-fate-interplay-mve-8bit: CMD = framecrc -i $(SAMPLES)/interplay-mve/interplay-logo-2MB.mve -pix_fmt rgb24 +-FATE_TESTS += fate-iv8-demux +-fate-iv8-demux: CMD = framecrc -i $(SAMPLES)/iv8/zzz-partial.mpg -vsync 0 -vcodec copy +-FATE_TESTS += fate-kmvc +-fate-kmvc: CMD = framecrc -i $(SAMPLES)/KMVC/LOGO1.AVI -an -t 3 -pix_fmt rgb24 +-FATE_TESTS += fate-lmlm4-demux +-fate-lmlm4-demux: CMD = framecrc -i $(SAMPLES)/lmlm4/LMLM4_CIFat30fps.divx -t 3 -acodec copy -vcodec copy +-FATE_TESTS += fate-loco-rgb +-fate-loco-rgb: CMD = framecrc -i $(SAMPLES)/loco/pig-loco-rgb.avi +-FATE_TESTS += fate-loco-yuy2 +-fate-loco-yuy2: CMD = framecrc -i $(SAMPLES)/loco/pig-loco-0.avi +-FATE_TESTS += fate-lossless-appleaudio +-fate-lossless-appleaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/inside.m4a -f s16le +-FATE_TESTS += fate-lossless-meridianaudio +-fate-lossless-meridianaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.mlp -f s16le +-FATE_TESTS += fate-lossless-monkeysaudio +-fate-lossless-monkeysaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.ape -f s16le +-FATE_TESTS += fate-lossless-shortenaudio +-fate-lossless-shortenaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.shn -f s16le +-FATE_TESTS += fate-lossless-tta +-fate-lossless-tta: CMD = crc -i $(SAMPLES)/lossless-audio/inside.tta +-FATE_TESTS += fate-lossless-wavpackaudio +-fate-lossless-wavpackaudio: CMD = md5 -i $(SAMPLES)/lossless-audio/luckynight-partial.wv -f s16le +-FATE_TESTS += fate-maxis-xa +-fate-maxis-xa: CMD = md5 -i $(SAMPLES)/maxis-xa/SC2KBUG.XA -f s16le +-FATE_TESTS += fate-mimic +-fate-mimic: CMD = framecrc -idct simple -i $(SAMPLES)/mimic/mimic2-womanloveffmpeg.cam -vsync 0 +-FATE_TESTS += fate-motionpixels +-fate-motionpixels: CMD = framecrc -i $(SAMPLES)/motion-pixels/INTRO-partial.MVI -an -pix_fmt rgb24 +-FATE_TESTS += fate-mpc7-demux +-fate-mpc7-demux: CMD = crc -i $(SAMPLES)/musepack/inside-mp7.mpc -acodec copy +-FATE_TESTS += fate-mpc8-demux +-fate-mpc8-demux: CMD = crc -i $(SAMPLES)/musepack/inside-mp8.mpc -acodec copy +-FATE_TESTS += fate-msrle-8bit +-fate-msrle-8bit: CMD = framecrc -i $(SAMPLES)/msrle/Search-RLE.avi -pix_fmt rgb24 +-FATE_TESTS += fate-msvideo1-16bit +-fate-msvideo1-16bit: CMD = framecrc -i $(SAMPLES)/cram/clock-cram16.avi -pix_fmt rgb24 +-FATE_TESTS += fate-msvideo1-8bit +-fate-msvideo1-8bit: CMD = framecrc -i $(SAMPLES)/cram/skating.avi -t 1 -pix_fmt rgb24 +-FATE_TESTS += fate-mszh +-fate-mszh: CMD = framecrc -i $(SAMPLES)/lcl/mszh-1frame.avi +-FATE_TESTS += fate-mtv +-fate-mtv: CMD = framecrc -i $(SAMPLES)/mtv/comedian_auto-partial.mtv -acodec copy -pix_fmt rgb24 +-FATE_TESTS += fate-mxf-demux +-fate-mxf-demux: CMD = framecrc -i $(SAMPLES)/mxf/C0023S01.mxf -acodec copy -vcodec copy +-FATE_TESTS += fate-nc-demux +-fate-nc-demux: CMD = framecrc -i $(SAMPLES)/nc-camera/nc-sample-partial -vcodec copy +-FATE_TESTS += fate-nsv-demux +-fate-nsv-demux: CMD = framecrc -i $(SAMPLES)/nsv/witchblade-51kbps.nsv -t 6 -vcodec copy -acodec copy +-FATE_TESTS += fate-nuv +-fate-nuv: CMD = framecrc -idct simple -i $(SAMPLES)/nuv/Today.nuv +-FATE_TESTS += fate-oma-demux +-fate-oma-demux: CMD = crc -i $(SAMPLES)/oma/01-Untitled-partial.oma -acodec copy +-FATE_TESTS += fate-pcm_dvd +-fate-pcm_dvd: CMD = framecrc -i $(SAMPLES)/pcm-dvd/coolitnow-partial.vob -vn +-FATE_TESTS += fate-psx-str +-fate-psx-str: CMD = framecrc -i $(SAMPLES)/psx-str/descent-partial.str +-FATE_TESTS += fate-psx-str-v3 +-fate-psx-str-v3: CMD = framecrc -i $(SAMPLES)/psx-str/abc000_cut.str +-FATE_TESTS += fate-ptx +-fate-ptx: CMD = framecrc -i $(SAMPLES)/ptx/_113kw_pic.ptx -pix_fmt rgb24 +-FATE_TESTS += fate-pva-demux +-fate-pva-demux: CMD = framecrc -idct simple -i $(SAMPLES)/pva/PVA_test-partial.pva -t 0.6 -acodec copy +-FATE_TESTS += fate-qcp-demux +-fate-qcp-demux: CMD = crc -i $(SAMPLES)/qcp/0036580847.QCP -acodec copy +-FATE_TESTS += fate-qpeg +-fate-qpeg: CMD = framecrc -i $(SAMPLES)/qpeg/Clock.avi -an -pix_fmt rgb24 +-FATE_TESTS += fate-qt-alaw-mono +-fate-qt-alaw-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-alaw.mov -f s16le +-FATE_TESTS += fate-qt-alaw-stereo +-fate-qt-alaw-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-alaw.mov -f s16le +-FATE_TESTS += fate-qt-ima4-mono +-fate-qt-ima4-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-ima4.mov -f s16le +-FATE_TESTS += fate-qt-ima4-stereo +-fate-qt-ima4-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-ima4.mov -f s16le +-FATE_TESTS += fate-qt-mac3-mono +-fate-qt-mac3-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-MAC3.mov -f s16le +-FATE_TESTS += fate-qt-mac3-stereo +-fate-qt-mac3-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-MAC3.mov -f s16le +-FATE_TESTS += fate-qt-mac6-mono +-fate-qt-mac6-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-MAC6.mov -f s16le +-FATE_TESTS += fate-qt-mac6-stereo +-fate-qt-mac6-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-MAC6.mov -f s16le +-FATE_TESTS += fate-qt-msadpcm-stereo +-fate-qt-msadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms02.mov -f s16le +-FATE_TESTS += fate-qt-msimaadpcm-stereo +-fate-qt-msimaadpcm-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-ms11.mov -f s16le +-FATE_TESTS += fate-qt-rawpcm-16bit-stereo-signed-be +-fate-qt-rawpcm-16bit-stereo-signed-be: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-twos.mov -f s16le +-FATE_TESTS += fate-qt-rawpcm-16bit-stereo-signed-le +-fate-qt-rawpcm-16bit-stereo-signed-le: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-L-sowt.mov -f s16le +-FATE_TESTS += fate-qt-rawpcm-8bit-mono-unsigned +-fate-qt-rawpcm-8bit-mono-unsigned: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-8-raw.mov -f s16le +-FATE_TESTS += fate-qt-rawpcm-8bit-stereo-unsigned +-fate-qt-rawpcm-8bit-stereo-unsigned: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-8-raw.mov -f s16le +-FATE_TESTS += fate-qt-ulaw-mono +-fate-qt-ulaw-mono: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-1-16-B-ulaw.mov -f s16le +-FATE_TESTS += fate-qt-ulaw-stereo +-fate-qt-ulaw-stereo: CMD = md5 -i $(SAMPLES)/qt-surge-suite/surge-2-16-B-ulaw.mov -f s16le +-FATE_TESTS += fate-qtrle-16bit +-fate-qtrle-16bit: CMD = framecrc -i $(SAMPLES)/qtrle/mr-cork-rle.mov -pix_fmt rgb24 +-FATE_TESTS += fate-qtrle-1bit +-fate-qtrle-1bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-Monochrome.mov +-FATE_TESTS += fate-qtrle-24bit +-fate-qtrle-24bit: CMD = framecrc -i $(SAMPLES)/qtrle/aletrek-rle.mov -vsync 0 +-FATE_TESTS += fate-qtrle-2bit +-fate-qtrle-2bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-4Greys.mov -pix_fmt rgb24 +-FATE_TESTS += fate-qtrle-32bit +-fate-qtrle-32bit: CMD = framecrc -i $(SAMPLES)/qtrle/ultra_demo_720_480_32bpp_rle.mov -pix_fmt rgb24 +-FATE_TESTS += fate-qtrle-4bit +-fate-qtrle-4bit: CMD = framecrc -i $(SAMPLES)/qtrle/Animation-16Greys.mov -pix_fmt rgb24 -an +-FATE_TESTS += fate-qtrle-8bit +-fate-qtrle-8bit: CMD = framecrc -i $(SAMPLES)/qtrle/criticalpath-credits.mov -vsync 0 -pix_fmt rgb24 -an +-FATE_TESTS += fate-quickdraw +-fate-quickdraw: CMD = framecrc -i $(SAMPLES)/quickdraw/Airplane.mov -pix_fmt rgb24 +-FATE_TESTS += fate-real-14_4 +-fate-real-14_4: CMD = md5 -i $(SAMPLES)/real/ra3_in_rm_file.rm -f s16le +-FATE_TESTS += fate-real-rv40 +-fate-real-rv40: CMD = framecrc -i $(SAMPLES)/real/spygames-2MB.rmvb -t 10 -an +-FATE_TESTS += fate-redcode-demux +-fate-redcode-demux: CMD = framecrc -i $(SAMPLES)/r3d/4MB-sample.r3d -vcodec copy -acodec copy +-FATE_TESTS += fate-rl2 +-fate-rl2: CMD = framecrc -i $(SAMPLES)/rl2/Z4915300.RL2 -pix_fmt rgb24 -an -vsync 0 +-FATE_TESTS += fate-rpza +-fate-rpza: CMD = framecrc -i $(SAMPLES)/rpza/rpza2.mov -t 2 -pix_fmt rgb24 +-FATE_TESTS += fate-sierra-audio +-fate-sierra-audio: CMD = md5 -i $(SAMPLES)/sol/lsl7sample.sol -f s16le +-FATE_TESTS += fate-sierra-vmd +-fate-sierra-vmd: CMD = framecrc -i $(SAMPLES)/vmd/12.vmd -vsync 0 -pix_fmt rgb24 +-FATE_TESTS += fate-siff +-fate-siff: CMD = framecrc -i $(SAMPLES)/SIFF/INTRO_B.VB -t 3 -pix_fmt rgb24 +-FATE_TESTS += fate-smacker +-fate-smacker: CMD = framecrc -i $(SAMPLES)/smacker/wetlogo.smk -pix_fmt rgb24 +-FATE_TESTS += fate-smc +-fate-smc: CMD = framecrc -i $(SAMPLES)/smc/cass_schi.qt -vsync 0 -pix_fmt rgb24 +-FATE_TESTS += fate-sp5x +-fate-sp5x: CMD = framecrc -idct simple -i $(SAMPLES)/sp5x/sp5x_problem.avi +-FATE_TESTS += fate-sub-srt +-fate-sub-srt: CMD = md5 -i $(SAMPLES)/sub/SubRip_capability_tester.srt -f ass +-FATE_TESTS += fate-sunraster-1bit-raw +-fate-sunraster-1bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-1bit-raw.sun +-FATE_TESTS += fate-sunraster-1bit-rle +-fate-sunraster-1bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-1bit-rle.sun +-FATE_TESTS += fate-sunraster-24bit-raw +-fate-sunraster-24bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-24bit-raw.sun +-FATE_TESTS += fate-sunraster-24bit-rle +-fate-sunraster-24bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-24bit-rle.sun +-FATE_TESTS += fate-sunraster-8bit-raw +-fate-sunraster-8bit-raw: CMD = framecrc -i $(SAMPLES)/sunraster/lena-8bit-raw.sun -pix_fmt rgb24 +-FATE_TESTS += fate-sunraster-8bit-rle +-fate-sunraster-8bit-rle: CMD = framecrc -i $(SAMPLES)/sunraster/lena-8bit-rle.sun -pix_fmt rgb24 +-FATE_TESTS += fate-svq1 +-fate-svq1: CMD = framecrc -i $(SAMPLES)/svq1/marymary-shackles.mov -an -t 10 +-FATE_TESTS += fate-svq3 +-fate-svq3: CMD = framecrc -i $(SAMPLES)/svq3/Vertical400kbit.sorenson3.mov -t 6 -an +-FATE_TESTS += fate-thp-mjpeg-adpcm +-fate-thp-mjpeg-adpcm: CMD = framecrc -idct simple -i $(SAMPLES)/thp/pikmin2-opening1-partial.thp +-FATE_TESTS += fate-tiertex-seq +-fate-tiertex-seq: CMD = framecrc -i $(SAMPLES)/tiertex-seq/Gameover.seq -pix_fmt rgb24 +-FATE_TESTS += fate-tmv +-fate-tmv: CMD = framecrc -i $(SAMPLES)/tmv/pop-partial.tmv -pix_fmt rgb24 +-FATE_TESTS += fate-truemotion1-15 +-fate-truemotion1-15: CMD = framecrc -i $(SAMPLES)/duck/phant2-940.duk -pix_fmt rgb24 +-FATE_TESTS += fate-truemotion1-24 +-fate-truemotion1-24: CMD = framecrc -i $(SAMPLES)/duck/sonic3dblast_intro-partial.avi -pix_fmt rgb24 +-FATE_TESTS += fate-tscc-15bit +-fate-tscc-15bit: CMD = framecrc -i $(SAMPLES)/tscc/oneminute.avi -t 15 -pix_fmt rgb24 +-FATE_TESTS += fate-tscc-32bit +-fate-tscc-32bit: CMD = framecrc -i $(SAMPLES)/tscc/2004-12-17-uebung9-partial.avi -pix_fmt rgb24 -an +-FATE_TESTS += fate-ulti +-fate-ulti: CMD = framecrc -i $(SAMPLES)/ulti/hit12w.avi -an +-FATE_TESTS += fate-v210 +-fate-v210: CMD = framecrc -i $(SAMPLES)/v210/v210_720p-partial.avi -pix_fmt yuv422p16be -an +-FATE_TESTS += fate-vc1 +-fate-vc1: CMD = framecrc -i $(SAMPLES)/vc1/SA00040.vc1 +-FATE_TESTS += fate-vcr1 +-fate-vcr1: CMD = framecrc -i $(SAMPLES)/vcr1/VCR1test.avi -an +-FATE_TESTS += fate-video-xl +-fate-video-xl: CMD = framecrc -i $(SAMPLES)/vixl/pig-vixl.avi +-FATE_TESTS += fate-vmnc-16bit +-fate-vmnc-16bit: CMD = framecrc -i $(SAMPLES)/VMnc/test.avi -pix_fmt rgb24 +-FATE_TESTS += fate-vmnc-32bit +-fate-vmnc-32bit: CMD = framecrc -i $(SAMPLES)/VMnc/VS2k5DebugDemo-01-partial.avi -pix_fmt rgb24 +-FATE_TESTS += fate-vp5 +-fate-vp5: CMD = framecrc -i $(SAMPLES)/vp5/potter512-400-partial.avi -an +-FATE_TESTS += fate-vp6a +-fate-vp6a: CMD = framecrc -i $(SAMPLES)/flash-vp6/300x180-Scr-f8-056alpha.flv +-FATE_TESTS += fate-vp6f +-fate-vp6f: CMD = framecrc -i $(SAMPLES)/flash-vp6/clip1024.flv +-FATE_TESTS += fate-vqa-cc +-fate-vqa-cc: CMD = framecrc -i $(SAMPLES)/vqa/cc-demo1-partial.vqa -pix_fmt rgb24 +-FATE_TESTS += fate-vqf-demux +-fate-vqf-demux: CMD = md5 -i $(SAMPLES)/vqf/achterba.vqf -acodec copy -f framecrc +-FATE_TESTS += fate-w64 +-fate-w64: CMD = crc -i $(SAMPLES)/w64/w64-pcm16.w64 +-FATE_TESTS += fate-wc3movie-xan +-fate-wc3movie-xan: CMD = framecrc -i $(SAMPLES)/wc3movie/SC_32-part.MVE -pix_fmt rgb24 +-FATE_TESTS += fate-westwood-aud +-fate-westwood-aud: CMD = md5 -i $(SAMPLES)/westwood-aud/excellent.aud -f s16le +-FATE_TESTS += fate-wnv1 +-fate-wnv1: CMD = framecrc -i $(SAMPLES)/wnv1/wnv1-codec.avi -an +-FATE_TESTS += fate-xan-dpcm +-fate-xan-dpcm: CMD = md5 -i $(SAMPLES)/wc4-xan/wc4_2.avi -vn -f s16le +-FATE_TESTS += fate-zlib +-fate-zlib: CMD = framecrc -i $(SAMPLES)/lcl/zlib-1frame.avi +-FATE_TESTS += fate-zmbv-15bit +-fate-zmbv-15bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_15bit.avi -pix_fmt rgb24 -t 25 +-FATE_TESTS += fate-zmbv-16bit +-fate-zmbv-16bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_16bit.avi -pix_fmt rgb24 -t 25 +-FATE_TESTS += fate-zmbv-32bit +-fate-zmbv-32bit: CMD = framecrc -i $(SAMPLES)/zmbv/zmbv_32bit.avi -pix_fmt rgb24 -t 25 +-FATE_TESTS += fate-zmbv-8bit +-fate-zmbv-8bit: CMD = framecrc -i $(SAMPLES)/zmbv/wc2_001-partial.avi -an -pix_fmt rgb24 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate-run.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate-run.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate-run.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate-run.sh 2012-05-14 14:08:55.564364737 +0200 +@@ -15,6 +15,9 @@ + cmp=${6:-diff} + ref=${7:-"${base}/ref/fate/${test}"} + fuzz=$8 ++threads=${9:-1} ++thread_type=${10:-frame+slice} ++tool=${11} + + outdir="tests/data/fate" + outfile="${outdir}/${test}" +@@ -47,37 +50,34 @@ + $target_exec $target_path/"$@" + } + +-ffmpeg(){ +- run ffmpeg -v 0 "$@" ++avconv(){ ++ run $tool -nostats -threads $threads -thread_type $thread_type "$@" + } + + framecrc(){ +- ffmpeg "$@" -f framecrc - ++ avconv "$@" -f framecrc - + } + + framemd5(){ +- ffmpeg "$@" -f framemd5 - ++ avconv "$@" -f framemd5 - + } + + crc(){ +- ffmpeg "$@" -f crc - ++ avconv "$@" -f crc - + } + + md5(){ +- ffmpeg "$@" md5: ++ avconv "$@" md5: + } + + pcm(){ +- ffmpeg "$@" -vn -f s16le - ++ avconv "$@" -vn -f s16le - + } + + regtest(){ + t="${test#$2-}" + ref=${base}/ref/$2/$t +- cleanfiles="$cleanfiles $outfile $errfile" +- outfile=tests/data/regression/$2/$t +- errfile=tests/data/$t.$2.err +- ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" ++ ${base}/${1}-regression.sh $t $2 $3 "$target_exec" "$target_path" "$threads" "$thread_type" "$tool" + } + + codectest(){ +@@ -105,7 +105,7 @@ + file=$(echo tests/data/$d/$file) + ;; + esac +- $target_exec $target_path/tests/seek_test $target_path/$file ++ run libavformat/seek-test $target_path/$file + } + + mkdir -p "$outdir" +@@ -124,6 +124,7 @@ + diff) diff -u -w "$ref" "$outfile" >$cmpfile ;; + oneoff) oneoff "$ref" "$outfile" "$fuzz" >$cmpfile ;; + stddev) stddev "$ref" "$outfile" "$fuzz" >$cmpfile ;; ++ null) cat "$outfile" >$cmpfile ;; + esac + cmperr=$? + test $err = 0 && err=$cmperr +@@ -135,5 +136,9 @@ + + echo "${test}:${sig:-$err}:$($base64 <$cmpfile):$($base64 <$errfile)" >$repfile + +-test $err = 0 && rm -f $outfile $errfile $cmpfile $cleanfiles ++if test $err = 0; then ++ rm -f $outfile $errfile $cmpfile $cleanfiles ++else ++ echo "Test $test failed. Look at $errfile for details." ++fi + exit $err +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate.sh 2012-05-14 14:08:55.567364798 +0200 +@@ -29,15 +29,13 @@ + case "$repo" in + file:*|/*) src="${repo#file:}" ;; + git:*) git clone "$repo" "$src" ;; +- svn:*) svn co "$repo" "$src" ;; + esac + } + + update()( + cd ${src} || return + case "$repo" in +- git:*) git pull ;; +- svn:*) svn up ;; ++ git:*) git pull --quiet ;; + esac + ) + +@@ -72,12 +70,12 @@ + ) + + clean(){ +- rm -r ${build} ${inst} ++ rm -rf ${build} ${inst} + } + + report(){ + date=$(date -u +%Y%m%d%H%M%S) +- echo "fate:0:${date}:${slot}:${version}:$1:$2" >report ++ echo "fate:0:${date}:${slot}:${version}:$1:$2:${comment}" >report + cat ${build}/config.fate ${build}/tests/data/fate/*.rep >>report + test -n "$fate_recv" && $tar report *.log | gzip | $fate_recv + } +@@ -93,8 +91,8 @@ + cd ${workdir} || die "cd ${workdir} failed" + + src=${workdir}/src +-build=${workdir}/build +-inst=${workdir}/install ++: ${build:=${workdir}/build} ++: ${inst:=${workdir}/install} + + test -d "$src" && update || checkout || die "Error fetching source" + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate-valgrind.supp xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate-valgrind.supp +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/fate-valgrind.supp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/fate-valgrind.supp 2012-05-14 14:08:55.564364737 +0200 +@@ -0,0 +1,31 @@ ++# seems fixed in newer versions ++# http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=577135 ++{ ++ zlib-inflate ++ Memcheck:Cond ++ fun:inflateReset2 ++ fun:inflateInit2_ ++} ++# libc overreads on purpose ++# http://sourceware.org/bugzilla/show_bug.cgi?id=12424 ++{ ++ eval-strtod ++ Memcheck:Addr8 ++ fun:__GI___strncasecmp_l ++ fun:____strtod_l_internal ++ fun:av_strtod ++} ++{ ++ eval-strtod ++ Memcheck:Value8 ++ fun:__GI___strncasecmp_l ++ fun:____strtod_l_internal ++ fun:av_strtod ++} ++{ ++ eval-strtod ++ Memcheck:Cond ++ fun:__GI___strncasecmp_l ++ fun:____strtod_l_internal ++ fun:av_strtod ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/lavfi-regression.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/lavfi-regression.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/lavfi-regression.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/lavfi-regression.sh 2012-05-14 14:08:55.595365361 +0200 +@@ -11,16 +11,13 @@ + + eval do_$test=y + +-rm -f "$logfile" +-rm -f "$benchfile" +- + do_video_filter() { + label=$1 + filters=$2 + shift 2 +- printf '%-20s' $label >>$logfile +- run_ffmpeg -f image2 -vcodec pgmyuv -i $raw_src \ +- -vf "$filters" -vcodec rawvideo $* -f nut md5: >>$logfile ++ printf '%-20s' $label ++ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src \ ++ $ENC_OPTS -vf "$filters" -vcodec rawvideo $* -f nut md5: + } + + do_lavfi() { +@@ -52,10 +49,10 @@ + out_fmts=${outfile}${1}_out_fmts + + # exclude pixel formats which are not supported as input +- $ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts +- $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ print $3 }' | sort | comm -23 - $exclude_fmts >$out_fmts ++ $avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^\..\.' | cut -d' ' -f2 | sort >$exclude_fmts ++ $showfiltfmts scale | awk -F '[ \r]' '/^OUTPUT/{ fmt=substr($3, 5); print fmt }' | sort | comm -23 - $exclude_fmts >$out_fmts + +- pix_fmts=$($showfiltfmts $filter | awk -F '[ \r]' '/^INPUT/{ print $3 }' | sort | comm -12 - $out_fmts) ++ pix_fmts=$($showfiltfmts $filter $filter_args | awk -F '[ \r]' '/^INPUT/{ fmt=substr($3, 5); print fmt }' | sort | comm -12 - $out_fmts) + for pix_fmt in $pix_fmts; do + do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,$filter=$filter_args" -pix_fmt $pix_fmt + done +@@ -72,8 +69,8 @@ + do_lavfi_pixfmts "scale" "200:100" + do_lavfi_pixfmts "vflip" "" + +-if [ -n "$do_pixdesc_be" ] || [ -n "$do_pixdesc_le" ]; then +- pix_fmts="$($ffmpeg -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)" ++if [ -n "$do_pixdesc" ]; then ++ pix_fmts="$($avconv -pix_fmts list 2>/dev/null | sed -ne '9,$p' | grep '^IO' | cut -d' ' -f2 | sort)" + for pix_fmt in $pix_fmts; do + do_video_filter $pix_fmt "slicify=random,format=$pix_fmt,pixdesctest" -pix_fmt $pix_fmt + done +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/lavf-regression.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/lavf-regression.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/lavf-regression.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/lavf-regression.sh 2012-05-14 14:08:55.595365361 +0200 +@@ -11,18 +11,20 @@ + + eval do_$test=y + ++ENC_OPTS="$ENC_OPTS -metadata title=lavftest" ++ + do_lavf() + { + file=${outfile}lavf.$1 +- do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -f s16le -i $pcm_src $2 +- do_ffmpeg_crc $file -i $target_path/$file $3 ++ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -b:a 64k -t 1 -qscale:v 10 $2 ++ do_avconv_crc $file $DEC_OPTS -i $target_path/$file $3 + } + + do_streamed_images() + { + file=${outfile}${1}pipe.$1 +- do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe +- do_ffmpeg_crc $file -f image2pipe -i $target_path/$file ++ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src -f image2pipe $ENC_OPTS -t 1 -qscale 10 ++ do_avconv_crc $file $DEC_OPTS -f image2pipe -i $target_path/$file + } + + do_image_formats() +@@ -30,49 +32,48 @@ + outfile="$datadir/images/$1/" + mkdir -p "$outfile" + file=${outfile}%02d.$1 +- $echov $ffmpeg -t 0.5 -y -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src $2 $3 -flags +bitexact -sws_flags +accurate_rnd+bitexact $target_path/$file +- $ffmpeg -t 0.5 -y -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src $2 $3 -flags +bitexact -sws_flags +accurate_rnd+bitexact $target_path/$file +- do_md5sum ${outfile}02.$1 >> $logfile +- do_ffmpeg_crc $file $3 -i $target_path/$file +- wc -c ${outfile}02.$1 >> $logfile ++ run_avconv $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $2 $ENC_OPTS $3 -t 0.5 -y -qscale 10 $target_path/$file ++ do_md5sum ${outfile}02.$1 ++ do_avconv_crc $file $DEC_OPTS $3 -i $target_path/$file ++ wc -c ${outfile}02.$1 + } + + do_audio_only() + { + file=${outfile}lavf.$1 +- do_ffmpeg $file -t 1 -qscale 10 $2 -f s16le -i $pcm_src $3 +- do_ffmpeg_crc $file -i $target_path/$file ++ do_avconv $file $DEC_OPTS $2 -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 $3 ++ do_avconv_crc $file $DEC_OPTS $4 -i $target_path/$file + } + +-rm -f "$logfile" +-rm -f "$benchfile" +- + if [ -n "$do_avi" ] ; then +-do_lavf avi ++do_lavf avi "-acodec mp2 -ab 64k" + fi + + if [ -n "$do_asf" ] ; then +-do_lavf asf "-acodec mp2" "-r 25" ++do_lavf asf "-acodec mp2 -ab 64k" "-r 25" + fi + + if [ -n "$do_rm" ] ; then + file=${outfile}lavf.rm +-do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -f s16le -i $pcm_src -acodec ac3_fixed ++do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $DEC_OPTS -ar 44100 -f s16le -i $pcm_src $ENC_OPTS -t 1 -qscale 10 -acodec ac3_fixed -ab 64k + # broken +-#do_ffmpeg_crc $file -i $target_path/$file ++#do_avconv_crc $file -i $target_path/$file + fi + + if [ -n "$do_mpg" ] ; then +-do_lavf mpg ++do_lavf mpg "-ab 64k" + fi + + if [ -n "$do_mxf" ] ; then +-do_lavf mxf "-ar 48000 -bf 2 -timecode_frame_start 264363" +-do_lavf mxf_d10 "-ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" ++do_lavf mxf "-ar 48000 -bf 2 -timecode 02:56:14:13" ++fi ++ ++if [ -n "$do_mxf_d10" ]; then ++do_lavf mxf_d10 "-ar 48000 -ac 2 -r 25 -s 720x576 -vf pad=720:608:0:32 -vcodec mpeg2video -g 0 -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -qscale 1 -ps 1 -qmin 1 -rc_max_vbv_use 1 -rc_min_vbv_use 1 -pix_fmt yuv422p -minrate 30000k -maxrate 30000k -b 30000k -bufsize 1200000 -top 1 -rc_init_occupancy 1200000 -qmax 12 -f mxf_d10" + fi + + if [ -n "$do_ts" ] ; then +-do_lavf ts ++do_lavf ts "-ab 64k -mpegts_transport_stream_id 42" + fi + + if [ -n "$do_swf" ] ; then +@@ -80,7 +81,7 @@ + fi + + if [ -n "$do_ffm" ] ; then +-do_lavf ffm ++do_lavf ffm "-ab 64k" + fi + + if [ -n "$do_flv_fmt" ] ; then +@@ -88,7 +89,7 @@ + fi + + if [ -n "$do_mov" ] ; then +-do_lavf mov "-acodec pcm_alaw" ++do_lavf mov "-acodec pcm_alaw -vcodec mpeg4" + fi + + if [ -n "$do_dv_fmt" ] ; then +@@ -100,19 +101,23 @@ + fi + + if [ -n "$do_nut" ] ; then +-do_lavf nut "-acodec mp2" ++do_lavf nut "-acodec mp2 -ab 64k" + fi + + if [ -n "$do_mkv" ] ; then +-do_lavf mkv ++do_lavf mkv "-acodec mp2 -ab 64k -vcodec mpeg4" ++fi ++ ++if [ -n "$do_wtv" ] ; then ++do_lavf wtv "-acodec mp2" + fi + + + # streamed images + # mjpeg + #file=${outfile}lavf.mjpeg +-#do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src +-#do_ffmpeg_crc $file -i $target_path/$file ++#do_avconv $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src ++#do_avconv_crc $file -i $target_path/$file + + if [ -n "$do_pbmpipe" ] ; then + do_streamed_images pbm +@@ -128,14 +133,14 @@ + + if [ -n "$do_gif" ] ; then + file=${outfile}lavf.gif +-do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src -pix_fmt rgb24 +-do_ffmpeg_crc $file -i $target_path/$file -pix_fmt rgb24 ++do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 -pix_fmt rgb24 ++do_avconv_crc $file $DEC_OPTS -i $target_path/$file -pix_fmt rgb24 + fi + + if [ -n "$do_yuv4mpeg" ] ; then + file=${outfile}lavf.y4m +-do_ffmpeg $file -t 1 -qscale 10 -f image2 -vcodec pgmyuv -i $raw_src +-#do_ffmpeg_crc $file -i $target_path/$file ++do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS -t 1 -qscale 10 ++#do_avconv_crc $file -i $target_path/$file + fi + + # image formats +@@ -150,6 +155,8 @@ + + if [ -n "$do_png" ] ; then + do_image_formats png ++do_image_formats png "-pix_fmt gray16be" ++do_image_formats png "-pix_fmt rgb48be" + fi + + if [ -n "$do_bmp" ] ; then +@@ -169,13 +176,17 @@ + fi + + if [ -n "$do_jpg" ] ; then +-do_image_formats jpg "-flags +bitexact -dct fastint -idct simple -pix_fmt yuvj420p" "-f image2" ++do_image_formats jpg "-pix_fmt yuvj420p" "-f image2" + fi + + if [ -n "$do_pcx" ] ; then + do_image_formats pcx + fi + ++if [ -n "$do_dpx" ] ; then ++do_image_formats dpx ++fi ++ + # audio only + + if [ -n "$do_wav" ] ; then +@@ -183,11 +194,11 @@ + fi + + if [ -n "$do_alaw" ] ; then +-do_audio_only al ++do_audio_only al "" "" "-ar 44100" + fi + + if [ -n "$do_mulaw" ] ; then +-do_audio_only ul ++do_audio_only ul "" "" "-ar 44100" + fi + + if [ -n "$do_au" ] ; then +@@ -218,6 +229,14 @@ + do_audio_only rso + fi + ++if [ -n "$do_sox" ] ; then ++do_audio_only sox ++fi ++ ++if [ -n "$do_caf" ] ; then ++do_audio_only caf ++fi ++ + # pix_fmt conversions + + if [ -n "$do_pixfmt" ] ; then +@@ -228,9 +247,9 @@ + monob yuv440p yuvj440p" + for pix_fmt in $conversions ; do + file=${outfile}${pix_fmt}.yuv +- do_ffmpeg_nocheck $file -r 1 -t 1 -f image2 -vcodec pgmyuv -i $raw_src \ +- -f rawvideo -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst +- do_ffmpeg $file -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \ +- -f rawvideo -s 352x288 -pix_fmt yuv444p ++ run_avconv $DEC_OPTS -r 1 -f image2 -vcodec pgmyuv -i $raw_src \ ++ $ENC_OPTS -f rawvideo -t 1 -s 352x288 -pix_fmt $pix_fmt $target_path/$raw_dst ++ do_avconv $file $DEC_OPTS -f rawvideo -s 352x288 -pix_fmt $pix_fmt -i $target_path/$raw_dst \ ++ $ENC_OPTS -f rawvideo -s 352x288 -pix_fmt yuv444p + done + fi +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/Makefile xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/Makefile +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/Makefile 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/Makefile 2012-05-14 14:08:55.497363389 +0200 +@@ -0,0 +1,155 @@ ++FFSERVER_REFFILE = $(SRC_PATH)/tests/ffserver.regression.ref ++ ++AREF = fate-acodec-aref ++VREF = fate-vsynth1-vref fate-vsynth2-vref ++REFS = $(AREF) $(VREF) ++ ++$(VREF): ffmpeg$(EXESUF) tests/vsynth1/00.pgm tests/vsynth2/00.pgm ++$(AREF): ffmpeg$(EXESUF) tests/data/asynth1.sw ++ ++ffservertest: ffserver$(EXESUF) tests/vsynth1/00.pgm tests/data/asynth1.sw ++ @echo ++ @echo "Unfortunately ffserver is broken and therefore its regression" ++ @echo "test fails randomly. Treat the results accordingly." ++ @echo ++ $(SRC_PATH)/tests/ffserver-regression.sh $(FFSERVER_REFFILE) $(SRC_PATH)/tests/ffserver.conf ++ ++tests/vsynth1/00.pgm: tests/videogen$(HOSTEXESUF) ++ @mkdir -p tests/vsynth1 ++ $(M)./$< 'tests/vsynth1/' ++ ++tests/vsynth2/00.pgm: tests/rotozoom$(HOSTEXESUF) ++ @mkdir -p tests/vsynth2 ++ $(M)./$< 'tests/vsynth2/' $(SRC_PATH)/tests/lena.pnm ++ ++tests/data/asynth1.sw: tests/audiogen$(HOSTEXESUF) ++ @mkdir -p tests/data ++ $(M)./$< $@ ++ ++tests/data/asynth-16000-1.sw: tests/audiogen$(HOSTEXESUF) ++ @mkdir -p tests/data ++ $(M)./$< $@ 16000 1 ++ ++tests/data/mapchan-6ch.sw: tests/audiogen$(HOSTEXESUF) ++ @mkdir -p tests/data ++ $(M)./$< $@ 22050 6 ++ ++tests/data/mapchan-mono.sw: tests/audiogen$(HOSTEXESUF) ++ @mkdir -p tests/data ++ $(M)./$< $@ 22050 1 ++ ++tests/data/%.sw tests/vsynth%/00.pgm: TAG = GEN ++ ++include $(SRC_PATH)/tests/fate/aac.mak ++include $(SRC_PATH)/tests/fate/ac3.mak ++include $(SRC_PATH)/tests/fate/adpcm.mak ++include $(SRC_PATH)/tests/fate/als.mak ++include $(SRC_PATH)/tests/fate/amrnb.mak ++include $(SRC_PATH)/tests/fate/amrwb.mak ++include $(SRC_PATH)/tests/fate/atrac.mak ++include $(SRC_PATH)/tests/fate/audio.mak ++include $(SRC_PATH)/tests/fate/dct.mak ++include $(SRC_PATH)/tests/fate/demux.mak ++include $(SRC_PATH)/tests/fate/dfa.mak ++include $(SRC_PATH)/tests/fate/dpcm.mak ++include $(SRC_PATH)/tests/fate/ea.mak ++include $(SRC_PATH)/tests/fate/fft.mak ++include $(SRC_PATH)/tests/fate/h264.mak ++include $(SRC_PATH)/tests/fate/image.mak ++include $(SRC_PATH)/tests/fate/indeo.mak ++include $(SRC_PATH)/tests/fate/libavcodec.mak ++include $(SRC_PATH)/tests/fate/libavutil.mak ++include $(SRC_PATH)/tests/fate/mapchan.mak ++include $(SRC_PATH)/tests/fate/lossless-audio.mak ++include $(SRC_PATH)/tests/fate/lossless-video.mak ++include $(SRC_PATH)/tests/fate/microsoft.mak ++include $(SRC_PATH)/tests/fate/mp3.mak ++include $(SRC_PATH)/tests/fate/mpc.mak ++include $(SRC_PATH)/tests/fate/pcm.mak ++include $(SRC_PATH)/tests/fate/prores.mak ++include $(SRC_PATH)/tests/fate/qt.mak ++include $(SRC_PATH)/tests/fate/qtrle.mak ++include $(SRC_PATH)/tests/fate/real.mak ++include $(SRC_PATH)/tests/fate/screen.mak ++include $(SRC_PATH)/tests/fate/utvideo.mak ++include $(SRC_PATH)/tests/fate/video.mak ++include $(SRC_PATH)/tests/fate/voice.mak ++include $(SRC_PATH)/tests/fate/vorbis.mak ++include $(SRC_PATH)/tests/fate/vpx.mak ++include $(SRC_PATH)/tests/fate/vqf.mak ++include $(SRC_PATH)/tests/fate/wma.mak ++ ++FATE_ACODEC = $(ACODEC_TESTS:%=fate-acodec-%) ++FATE_VSYNTH1 = $(VCODEC_TESTS:%=fate-vsynth1-%) ++FATE_VSYNTH2 = $(VCODEC_TESTS:%=fate-vsynth2-%) ++FATE_VCODEC = $(FATE_VSYNTH1) $(FATE_VSYNTH2) ++FATE_LAVF = $(LAVF_TESTS:%=fate-lavf-%) ++FATE_LAVFI = $(LAVFI_TESTS:%=fate-lavfi-%) ++FATE_SEEK = $(SEEK_TESTS:seek_%=fate-seek-%) ++ ++FATE = $(FATE_ACODEC) \ ++ $(FATE_VCODEC) \ ++ $(FATE_LAVF) \ ++ $(FATE_SEEK) \ ++ ++FATE-$(CONFIG_AVFILTER) += $(FATE_LAVFI) ++ ++FATE += $(FATE-yes) ++ ++$(filter-out %-aref,$(FATE_ACODEC)): $(AREF) ++$(filter-out %-vref,$(FATE_VSYNTH1)): fate-vsynth1-vref ++$(filter-out %-vref,$(FATE_VSYNTH2)): fate-vsynth2-vref ++$(FATE_LAVF): $(REFS) ++$(FATE_LAVFI): $(REFS) tools/lavfi-showfiltfmts$(EXESUF) ++$(FATE_SEEK): fate-codec fate-lavf libavformat/seek-test$(EXESUF) ++ ++$(FATE_ACODEC): CMD = codectest acodec ++$(FATE_VSYNTH1): CMD = codectest vsynth1 ++$(FATE_VSYNTH2): CMD = codectest vsynth2 ++$(FATE_LAVF): CMD = lavftest ++$(FATE_LAVFI): CMD = lavfitest ++$(FATE_SEEK): CMD = seektest ++ ++fate-codec: fate-acodec fate-vcodec ++fate-acodec: $(FATE_ACODEC) ++fate-vcodec: $(FATE_VCODEC) ++fate-lavf: $(FATE_LAVF) ++fate-lavfi: $(FATE_LAVFI) ++fate-seek: $(FATE_SEEK) ++ ++ifdef SAMPLES ++FATE += $(FATE_TESTS) $(FATE_TESTS-yes) ++fate-rsync: ++ rsync -vaLW --timeout=60 --contimeout=60 rsync://fate.ffmpeg.org/fate-suite/ $(SAMPLES) ++else ++fate:: ++ @echo "warning: only a subset of the fate tests will be run because SAMPLES is not specified" ++fate-rsync: ++ @echo "use 'make fate-rsync SAMPLES=/path/to/samples' to sync the fate suite" ++$(FATE_TESTS): ++ @echo "SAMPLES not specified, cannot run FATE" ++endif ++ ++FATE_UTILS = base64 tiny_psnr ++ ++TOOL = ffmpeg ++ ++fate:: $(FATE) ++ ++$(FATE): $(TOOL)$(EXESUF) $(FATE_UTILS:%=tests/%$(HOSTEXESUF)) ++ @echo "TEST $(@:fate-%=%)" ++ $(Q)$(SRC_PATH)/tests/fate-run.sh $@ "$(SAMPLES)" "$(TARGET_EXEC)" "$(TARGET_PATH)" '$(CMD)' '$(CMP)' '$(REF)' '$(FUZZ)' '$(THREADS)' '$(THREAD_TYPE)' '$(TOOL)' ++ ++fate-list: ++ @printf '%s\n' $(sort $(FATE)) ++ ++clean:: testclean ++ ++testclean: ++ $(RM) -r tests/vsynth1 tests/vsynth2 tests/data tools/lavfi-showfiltfmts$(EXESUF) ++ $(RM) $(CLEANSUFFIXES:%=tests/%) ++ $(RM) $(TESTTOOLS:%=tests/%$(HOSTEXESUF)) ++ ++-include $(wildcard tests/*.d) ++ ++.PHONY: fate* +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/ac3_fixed xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/ac3_fixed +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/ac3_fixed 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/ac3_fixed 2012-05-14 14:08:55.596365381 +0200 +@@ -1,2 +1,2 @@ +-37e119c644ba0472c079d0e907bf78df *./tests/data/acodec/ac3.rm ++e7fa185030a56d9db8663ad9e38c6c94 *./tests/data/acodec/ac3.rm + 98751 ./tests/data/acodec/ac3.rm +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_adx xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_adx +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_adx 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_adx 2012-05-14 14:08:55.596365381 +0200 +@@ -0,0 +1,4 @@ ++0a30509d9296b857e134b762b76dbc31 *./tests/data/acodec/adpcm_adx.adx ++297720 ./tests/data/acodec/adpcm_adx.adx ++2dbc601ed5259f4d74dc48ccd8da7eaf *./tests/data/adpcm_adx.acodec.out.wav ++stddev: 6989.46 PSNR: 19.44 MAXDIFF:65398 bytes: 1058432/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ima_qt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ima_qt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ima_qt 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ima_qt 2012-05-14 14:08:55.597365401 +0200 +@@ -1,4 +1,4 @@ +-3c06fd2f7831e3e8735b936e23ca220c *./tests/data/acodec/adpcm_qt.aiff ++057d27978b35888776512e4e9669a63b *./tests/data/acodec/adpcm_qt.aiff + 281252 ./tests/data/acodec/adpcm_qt.aiff +-9580492803ba1c1a3746367b24b751c8 *./tests/data/adpcm_ima_qt.acodec.out.wav +-stddev: 914.65 PSNR: 37.10 MAXDIFF:34026 bytes: 1058560/ 1058400 ++169c40435c68d50112c9c61fc67e446d *./tests/data/adpcm_ima_qt.acodec.out.wav ++stddev: 918.61 PSNR: 37.07 MAXDIFF:34029 bytes: 1058560/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ima_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ima_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ima_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ima_wav 2012-05-14 14:08:55.597365401 +0200 +@@ -1,4 +1,4 @@ + 56b75c3a6dacedcf2ce7b0586aa33594 *./tests/data/acodec/adpcm_ima.wav + 267324 ./tests/data/acodec/adpcm_ima.wav +-78a2af1c895792d0c221d127bdd48ece *./tests/data/adpcm_ima_wav.acodec.out.wav ++ddddfa47302da540abf19224202bef57 *./tests/data/adpcm_ima_wav.acodec.out.wav + stddev: 903.51 PSNR: 37.21 MAXDIFF:34026 bytes: 1061748/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ms xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ms +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_ms 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_ms 2012-05-14 14:08:55.598365421 +0200 +@@ -1,4 +1,4 @@ + a407b87daeef5b25dfb6c5b3f519e9c1 *./tests/data/acodec/adpcm_ms.wav + 268378 ./tests/data/acodec/adpcm_ms.wav +-7be370f937c51e8a967e6a3d08d5156a *./tests/data/adpcm_ms.acodec.out.wav ++22863fb278c4e0ebe9c34cb15db5dd6b *./tests/data/adpcm_ms.acodec.out.wav + stddev: 1050.01 PSNR: 35.91 MAXDIFF:29806 bytes: 1060576/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_swf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_swf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_swf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_swf 2012-05-14 14:08:55.599365441 +0200 +@@ -1,4 +1,4 @@ + 42d4639866ed4d692eaf126228a4fa2a *./tests/data/acodec/adpcm_swf.flv + 269166 ./tests/data/acodec/adpcm_swf.flv +-628089745a7059ae4055c2515b6d668b *./tests/data/adpcm_swf.acodec.out.wav ++f7df69d3fe708303820f2a9d00140a5b *./tests/data/adpcm_swf.acodec.out.wav + stddev: 933.58 PSNR: 36.93 MAXDIFF:51119 bytes: 1064960/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_yam xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_yam +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/adpcm_yam 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/adpcm_yam 2012-05-14 14:08:55.599365441 +0200 +@@ -1,4 +1,4 @@ +-2546d72df736b5ffa1557e8c9c9ef788 *./tests/data/acodec/adpcm_yam.wav +-266296 ./tests/data/acodec/adpcm_yam.wav +-c80c847a53a0fee17a88fa889ec34a4e *./tests/data/adpcm_yam.acodec.out.wav ++006f8dc92eb4f7bab82eded314ca1124 *./tests/data/acodec/adpcm_yam.wav ++266298 ./tests/data/acodec/adpcm_yam.wav ++c36a9d5a1e0ad57fbe9665a31373b7c1 *./tests/data/adpcm_yam.acodec.out.wav + stddev: 1247.60 PSNR: 34.41 MAXDIFF:39895 bytes: 1064960/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/alac xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/alac +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/alac 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/alac 2012-05-14 14:08:55.600365461 +0200 +@@ -1,4 +1,4 @@ +-c68f649777ab8e7c9a0f1f221451d3ad *./tests/data/acodec/alac.m4a +-389386 ./tests/data/acodec/alac.m4a +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/alac.acodec.out.wav ++cf9a4b40ab945367cbb0e6cbb4cf37a1 *./tests/data/acodec/alac.m4a ++389166 ./tests/data/acodec/alac.m4a ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/alac.acodec.out.wav + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/aref xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/aref +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/aref 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/aref 2012-05-14 14:08:55.600365461 +0200 +@@ -0,0 +1,2 @@ ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/acodec.ref.wav ++1058446 ./tests/data/acodec.ref.wav +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/flac xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/flac +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/flac 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/flac 2012-05-14 14:08:55.601365481 +0200 +@@ -1,4 +1,4 @@ + 151eef9097f944726968bec48649f00a *./tests/data/acodec/flac.flac + 361582 ./tests/data/acodec/flac.flac +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/flac.acodec.out.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/flac.acodec.out.wav + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g722 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g722 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g722 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g722 2012-05-14 14:08:55.601365481 +0200 +@@ -0,0 +1,4 @@ ++d1a10c4d35f752f60798114a156be3a8 *./tests/data/acodec/g722.wav ++48053 ./tests/data/acodec/g722.wav ++8dafe5b74ccd5f08fed2fb2a69c5475f *./tests/data/g722.acodec.out.wav ++stddev: 8939.47 PSNR: 17.30 MAXDIFF:40370 bytes: 191980/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g723_1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g723_1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g723_1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g723_1 2012-05-14 14:08:55.601365481 +0200 +@@ -0,0 +1,4 @@ ++5815887898457847a7717fbe60d9cfb6 *./tests/data/acodec/g723_1.tco ++4800 ./tests/data/acodec/g723_1.tco ++5d706e32b8e8fa991f2b1a309ea5e917 *./tests/data/g723_1.acodec.out.wav ++stddev: 8507.20 PSNR: 17.73 MAXDIFF:26473 bytes: 96000/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g726 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g726 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/g726 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/g726 2012-05-14 14:08:55.602365501 +0200 +@@ -1,4 +1,4 @@ +-fd090ddf05cc3401cc75c4a5ace1d05a *./tests/data/acodec/g726.wav +-24052 ./tests/data/acodec/g726.wav +-74abea06027375111eeac1b2f8c7d3af *./tests/data/g726.acodec.out.wav +-stddev: 8554.55 PSNR: 17.69 MAXDIFF:29353 bytes: 95984/ 1058400 ++331fcf91f4483b508059d0933af97987 *./tests/data/acodec/g726.wav ++24054 ./tests/data/acodec/g726.wav ++fac563ba7947d8fc42b4af048707c145 *./tests/data/g726.acodec.out.wav ++stddev: 8553.69 PSNR: 17.69 MAXDIFF:29353 bytes: 95984/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/mp2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/mp2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/mp2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/mp2 2012-05-14 14:08:55.602365501 +0200 +@@ -1,5 +1,5 @@ + f6eb0a205350bbd7fb1028a01c7ae8aa *./tests/data/acodec/mp2.mp2 + 96130 ./tests/data/acodec/mp2.mp2 +-74c7b6b15a001add199619fafe4059a1 *./tests/data/mp2.acodec.out.wav ++5a669ca7321adc6ab66a3eade4035909 *./tests/data/mp2.acodec.out.wav + stddev: 9315.99 PSNR: 16.94 MAXDIFF:65388 bytes: 1059840/ 1058400 + stddev: 4384.33 PSNR: 23.49 MAXDIFF:52631 bytes: 1057916/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,72 +0,0 @@ +-89f5b8dd97e0dddbe59af0d44fd229f3 *./tests/data/acodec/pcm_alaw.wav +-529256 ./tests/data/acodec/pcm_alaw.wav +-0568b0b9a72e31559e150e7e09d301cd *./tests/data/pcm.acodec.out.wav +-stddev: 101.67 PSNR: 56.19 MAXDIFF: 515 bytes: 1058400/ 1058400 +-f443a8eeb1647ec1eeb8370c939e52d4 *./tests/data/acodec/pcm_mulaw.wav +-529256 ./tests/data/acodec/pcm_mulaw.wav +-1c3eeaa8814ebd4916780dff80ed6dc5 *./tests/data/pcm.acodec.out.wav +-stddev: 103.38 PSNR: 56.04 MAXDIFF: 644 bytes: 1058400/ 1058400 +-b7936d7170e0efefb379349d81aed360 *./tests/data/acodec/pcm_s8.mov +-530837 ./tests/data/acodec/pcm_s8.mov +-652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav +-stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400 +-98cadb3502dbdc99e6e077c28b1a036c *./tests/data/acodec/pcm_u8.wav +-529244 ./tests/data/acodec/pcm_u8.wav +-652edf30f35ad89bf27bcc9d2f9c7b53 *./tests/data/pcm.acodec.out.wav +-stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400 +-c42b9c04305455250366c84e17c1023f *./tests/data/acodec/pcm_s16be.mov +-1060037 ./tests/data/acodec/pcm_s16be.mov +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/acodec/pcm_s16le.wav +-1058444 ./tests/data/acodec/pcm_s16le.wav +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-352a6bcf51d0f3ca4bf27c423a3d4d14 *./tests/data/acodec/pcm_s16be.mkv +- 1060650 ./tests/data/acodec/pcm_s16be.mkv +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-2c089d83b2699c02c9358415e00a9707 *./tests/data/acodec/pcm_s16le.mkv +- 1060650 ./tests/data/acodec/pcm_s16le.mkv +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-07ffe7ffb78f3648b6524debdde5aec1 *./tests/data/acodec/pcm_s24be.mov +-1589237 ./tests/data/acodec/pcm_s24be.mov +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-a85380fb79b0d4fff38e24ac1e34bb94 *./tests/data/acodec/pcm_s24le.wav +-1587668 ./tests/data/acodec/pcm_s24le.wav +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-d7792f0343cd66fda8b50b569e2bcc48 *./tests/data/acodec/pcm_s32be.mov +-2118437 ./tests/data/acodec/pcm_s32be.mov +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-da6ed80f4f40f0082577dea80827e014 *./tests/data/acodec/pcm_s32le.wav +-2116868 ./tests/data/acodec/pcm_s32le.wav +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-118ff3dc83c62ce9ce669eef57e55bb2 *./tests/data/acodec/pcm_f32be.au +-2116824 ./tests/data/acodec/pcm_f32be.au +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-46f44f86a18984a832206ab9e29a79f2 *./tests/data/acodec/pcm_f32le.wav +-2116880 ./tests/data/acodec/pcm_f32le.wav +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-8112296b1ed94f72f20d04b1a54850a7 *./tests/data/acodec/pcm_f64be.au +-4233624 ./tests/data/acodec/pcm_f64be.au +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-ba17c6d1a270e1333e981f239bf7eb45 *./tests/data/acodec/pcm_f64le.wav +-4233680 ./tests/data/acodec/pcm_f64le.wav +-95e54b261530a1bcf6de6fe3b21dc5f6 *./tests/data/pcm.acodec.out.wav +-stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +-8c74234928ed425b1171211a89f67ead *./tests/data/acodec/pcm_zork.wav +-529256 ./tests/data/acodec/pcm_zork.wav +-864c8c866ac25642c29a13b122c70709 *./tests/data/pcm.acodec.out.wav +-stddev: 633.11 PSNR: 40.30 MAXDIFF:32768 bytes: 1058400/ 1058400 +-8168a5c1343553ef027541830f2cb879 *./tests/data/acodec/pcm_s24daud.302 +-10368730 ./tests/data/acodec/pcm_s24daud.302 +-f552afadfdfcd6348a07095da6382de5 *./tests/data/pcm.acodec.out.wav +-stddev: 9416.28 PSNR: 16.85 MAXDIFF:42744 bytes: 6911796/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_alaw xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_alaw +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_alaw 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_alaw 2012-05-14 14:08:55.603365521 +0200 +@@ -0,0 +1,4 @@ ++ede2da07839a00c255a43129922f2c7b *./tests/data/acodec/pcm_alaw.wav ++529258 ./tests/data/acodec/pcm_alaw.wav ++f323f7551ffad91de8613f44dcb198b6 *./tests/data/pcm_alaw.acodec.out.wav ++stddev: 101.67 PSNR: 56.19 MAXDIFF: 515 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f32be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f32be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f32be 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f32be 2012-05-14 14:08:55.604365542 +0200 +@@ -0,0 +1,4 @@ ++118ff3dc83c62ce9ce669eef57e55bb2 *./tests/data/acodec/pcm_f32be.au ++2116824 ./tests/data/acodec/pcm_f32be.au ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_f32be.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f32le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f32le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f32le 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f32le 2012-05-14 14:08:55.604365542 +0200 +@@ -0,0 +1,4 @@ ++46f44f86a18984a832206ab9e29a79f2 *./tests/data/acodec/pcm_f32le.wav ++2116880 ./tests/data/acodec/pcm_f32le.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_f32le.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f64be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f64be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f64be 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f64be 2012-05-14 14:08:55.605365563 +0200 +@@ -0,0 +1,4 @@ ++8112296b1ed94f72f20d04b1a54850a7 *./tests/data/acodec/pcm_f64be.au ++4233624 ./tests/data/acodec/pcm_f64be.au ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_f64be.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f64le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f64le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_f64le 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_f64le 2012-05-14 14:08:55.605365563 +0200 +@@ -0,0 +1,4 @@ ++ba17c6d1a270e1333e981f239bf7eb45 *./tests/data/acodec/pcm_f64le.wav ++4233680 ./tests/data/acodec/pcm_f64le.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_f64le.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_mulaw xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_mulaw +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_mulaw 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_mulaw 2012-05-14 14:08:55.606365583 +0200 +@@ -0,0 +1,4 @@ ++0c2a55850fb46ad5385a69b15b271f10 *./tests/data/acodec/pcm_mulaw.wav ++529258 ./tests/data/acodec/pcm_mulaw.wav ++7ae8c3fc804bd574006fd547fe28980c *./tests/data/pcm_mulaw.acodec.out.wav ++stddev: 103.38 PSNR: 56.04 MAXDIFF: 644 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s16be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s16be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s16be 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s16be 2012-05-14 14:08:55.606365583 +0200 +@@ -0,0 +1,4 @@ ++a874f5c08b8d104a6bbf41b21454180d *./tests/data/acodec/pcm_s16be.mov ++1059045 ./tests/data/acodec/pcm_s16be.mov ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s16be.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s16le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s16le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s16le 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s16le 2012-05-14 14:08:55.607365603 +0200 +@@ -0,0 +1,4 @@ ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/acodec/pcm_s16le.wav ++1058446 ./tests/data/acodec/pcm_s16le.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s16le.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24be 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24be 2012-05-14 14:08:55.607365603 +0200 +@@ -0,0 +1,4 @@ ++833d4afd907139af7106a5642a9c23d3 *./tests/data/acodec/pcm_s24be.mov ++1588245 ./tests/data/acodec/pcm_s24be.mov ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s24be.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24daud xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24daud +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24daud 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24daud 2012-05-14 14:08:55.607365603 +0200 +@@ -0,0 +1,4 @@ ++1b75d5198ae789ab3c48f7024e08f4a9 *./tests/data/acodec/pcm_s24daud.302 ++10368730 ./tests/data/acodec/pcm_s24daud.302 ++4708f86529c594e29404603c64bb208c *./tests/data/pcm_s24daud.acodec.out.wav ++stddev: 8967.92 PSNR: 17.28 MAXDIFF:42548 bytes: 6911796/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s24le 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s24le 2012-05-14 14:08:55.608365623 +0200 +@@ -0,0 +1,4 @@ ++a85380fb79b0d4fff38e24ac1e34bb94 *./tests/data/acodec/pcm_s24le.wav ++1587668 ./tests/data/acodec/pcm_s24le.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s24le.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s32be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s32be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s32be 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s32be 2012-05-14 14:08:55.609365643 +0200 +@@ -0,0 +1,4 @@ ++c02c96e37b321f2c978968e3a102c669 *./tests/data/acodec/pcm_s32be.mov ++2117449 ./tests/data/acodec/pcm_s32be.mov ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s32be.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s32le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s32le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s32le 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s32le 2012-05-14 14:08:55.609365643 +0200 +@@ -0,0 +1,4 @@ ++da6ed80f4f40f0082577dea80827e014 *./tests/data/acodec/pcm_s32le.wav ++2116868 ./tests/data/acodec/pcm_s32le.wav ++64151e4bcc2b717aa5a8454d424d6a1f *./tests/data/pcm_s32le.acodec.out.wav ++stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_s8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_s8 2012-05-14 14:08:55.610365663 +0200 +@@ -0,0 +1,4 @@ ++111d465266385298fde83005402ac171 *./tests/data/acodec/pcm_s8.mov ++529829 ./tests/data/acodec/pcm_s8.mov ++651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm_s8.acodec.out.wav ++stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_u8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_u8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/pcm_u8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/pcm_u8 2012-05-14 14:08:55.610365663 +0200 +@@ -0,0 +1,4 @@ ++70fecbae732f81143a560c7315eda49a *./tests/data/acodec/pcm_u8.wav ++529246 ./tests/data/acodec/pcm_u8.wav ++651d4eb8d98dfcdda96ae6c43d8f156b *./tests/data/pcm_u8.acodec.out.wav ++stddev: 147.89 PSNR: 52.93 MAXDIFF: 255 bytes: 1058400/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/wmav1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/wmav1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/wmav1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/wmav1 2012-05-14 14:08:55.611365683 +0200 +@@ -1,4 +1,4 @@ +-26a7f6b0f0b7181df8df3fa589f6bf81 *./tests/data/acodec/wmav1.asf ++0260385b8a54df11ad349f9ba8240fd8 *./tests/data/acodec/wmav1.asf + 106004 ./tests/data/acodec/wmav1.asf +-stddev:12245.52 PSNR: 14.57 MAXDIFF:65521 bytes: 1064960/ 1058400 +-stddev: 2095.89 PSNR: 29.90 MAXDIFF:27658 bytes: 1056768/ 1058400 ++stddev:12241.90 PSNR: 14.57 MAXDIFF:65521 bytes: 1064960/ 1058400 ++stddev: 2074.79 PSNR: 29.99 MAXDIFF:27658 bytes: 1056768/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/wmav2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/wmav2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/acodec/wmav2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/acodec/wmav2 2012-05-14 14:08:55.611365683 +0200 +@@ -1,4 +1,4 @@ +-7c6c0cb692af01b312ae345723674b5f *./tests/data/acodec/wmav2.asf ++bdb4c312fb109f990be83a70f8ec9bdc *./tests/data/acodec/wmav2.asf + 106044 ./tests/data/acodec/wmav2.asf +-stddev:12249.93 PSNR: 14.57 MAXDIFF:65521 bytes: 1064960/ 1058400 +-stddev: 2089.21 PSNR: 29.93 MAXDIFF:27650 bytes: 1056768/ 1058400 ++stddev:12246.35 PSNR: 14.57 MAXDIFF:65521 bytes: 1064960/ 1058400 ++stddev: 2068.08 PSNR: 30.02 MAXDIFF:27650 bytes: 1056768/ 1058400 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/4xm-1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/4xm-1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/4xm-1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/4xm-1 2012-05-14 14:08:55.612365703 +0200 +@@ -1,15 +1,15 @@ +-0, 0, 921600, 0xd08f97c7 +-0, 6000, 921600, 0xc433a85b +-0, 12000, 921600, 0x7ffeee42 +-0, 18000, 921600, 0xc0ad9f52 +-0, 24000, 921600, 0xb0235112 +-0, 30000, 921600, 0xcbdd9805 +-0, 36000, 921600, 0x5468bdb9 +-0, 42000, 921600, 0x2f0c63fd +-0, 48000, 921600, 0xf1de04f0 +-0, 54000, 921600, 0x95709ce2 +-0, 60000, 921600, 0x69037c4a +-0, 66000, 921600, 0x513f8a98 +-0, 72000, 921600, 0x55b82fa1 +-0, 78000, 921600, 0x5c8ace28 +-0, 84000, 921600, 0xb019770a ++0, 0, 921600, 0xd82e4d57 ++0, 6000, 921600, 0x83f2349c ++0, 12000, 921600, 0x70d87db0 ++0, 18000, 921600, 0x66d27b93 ++0, 24000, 921600, 0xb730941c ++0, 30000, 921600, 0x15da4934 ++0, 36000, 921600, 0x1953968a ++0, 42000, 921600, 0xf0d730a0 ++0, 48000, 921600, 0x35a7d30c ++0, 54000, 921600, 0x33667f62 ++0, 60000, 921600, 0xf4707f6b ++0, 66000, 921600, 0xaac6c392 ++0, 72000, 921600, 0x68397d16 ++0, 78000, 921600, 0xb2aa0450 ++0, 84000, 921600, 0xba25c62e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/4xm-2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/4xm-2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/4xm-2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/4xm-2 2012-05-14 14:08:55.613365723 +0200 +@@ -5,153 +5,153 @@ + 0, 60000, 80640, 0x3a942680 + 0, 75000, 80640, 0x3a942680 + 0, 90000, 80640, 0x3a942680 +-0, 105000, 80640, 0x1956ebfc +-0, 120000, 80640, 0x61686290 +-0, 135000, 80640, 0x7e2c2753 +-0, 150000, 80640, 0x63e5e14f +-0, 165000, 80640, 0xa775947a +-0, 180000, 80640, 0x4b91b93d +-0, 195000, 80640, 0x83345f32 +-0, 210000, 80640, 0x5d3a3374 +-0, 225000, 80640, 0x164808c5 +-0, 240000, 80640, 0xfd0189af +-0, 255000, 80640, 0x062f9389 +-0, 270000, 80640, 0xe4dcaff8 +-0, 285000, 80640, 0xb2d9ec51 +-0, 300000, 80640, 0x3b4d5331 +-0, 315000, 80640, 0xfcbd8da1 +-0, 330000, 80640, 0xa0732142 +-0, 345000, 80640, 0x6438df5f +-0, 360000, 80640, 0x614302fa +-0, 375000, 80640, 0x53edf986 +-0, 390000, 80640, 0x6dfe13f0 +-0, 405000, 80640, 0x0b2194c3 +-0, 420000, 80640, 0xe0436945 +-0, 435000, 80640, 0x8d8ba77f +-0, 450000, 80640, 0x9c723388 +-0, 465000, 80640, 0x336bd2a2 +-0, 480000, 80640, 0x5905fd0b +-0, 495000, 80640, 0x2ca368bb +-0, 510000, 80640, 0x38c1e5ec +-0, 525000, 80640, 0xe439a194 +-0, 540000, 80640, 0xe7a19a64 +-0, 555000, 80640, 0xbe7f9094 +-0, 570000, 80640, 0x0b2cbec9 +-0, 585000, 80640, 0x8050bf7d +-0, 600000, 80640, 0x4e9d4e78 +-0, 615000, 80640, 0xaa7bb85d +-0, 630000, 80640, 0x6e42b1a6 +-0, 645000, 80640, 0x27043fe0 +-0, 660000, 80640, 0xe04bd5e6 +-0, 675000, 80640, 0xd60762d6 +-0, 690000, 80640, 0x2729df8f +-0, 705000, 80640, 0x1b62c4f7 +-0, 720000, 80640, 0xe6b5d2f7 +-0, 735000, 80640, 0xf5885096 +-0, 750000, 80640, 0xe7625cf6 +-0, 765000, 80640, 0xed804de6 +-0, 780000, 80640, 0x3f92728e +-0, 795000, 80640, 0x353e4b0d +-0, 810000, 80640, 0x70b0228c +-0, 825000, 80640, 0x851bd554 +-0, 840000, 80640, 0x594f22eb +-0, 855000, 80640, 0xa2267c0b +-0, 870000, 80640, 0xdc0fbafb +-0, 885000, 80640, 0xd596b763 +-0, 900000, 80640, 0x3b9c4b1b +-0, 915000, 80640, 0x218ac4b4 +-0, 930000, 80640, 0x4af393a4 +-0, 945000, 80640, 0x66c098c5 +-0, 960000, 80640, 0x7cc91e86 +-0, 975000, 80640, 0xba282a2e +-0, 990000, 80640, 0x50932be6 +-0, 1005000, 80640, 0x6531386e +-0, 1020000, 80640, 0x2616235f +-0, 1035000, 80640, 0x27aad18a +-0, 1050000, 80640, 0x67491df3 +-0, 1065000, 80640, 0x167028f1 +-0, 1080000, 80640, 0xa4229420 +-0, 1095000, 80640, 0x77eaed07 +-0, 1110000, 80640, 0xbdf7d8e8 +-0, 1125000, 80640, 0xc2ac8545 +-0, 1140000, 80640, 0xf3fe64ec +-0, 1155000, 80640, 0x66451d43 +-0, 1170000, 80640, 0x1af2f05e +-0, 1185000, 80640, 0x2a63c2c4 +-0, 1200000, 80640, 0xe4e07a0f +-0, 1215000, 80640, 0x598e8b11 +-0, 1230000, 80640, 0xb2ebb868 +-0, 1245000, 80640, 0xa4b6bb8a +-0, 1260000, 80640, 0x5037e910 +-0, 1275000, 80640, 0x0c55f6c0 +-0, 1290000, 80640, 0x3f4704f7 +-0, 1305000, 80640, 0xa6a8e810 +-0, 1320000, 80640, 0xedbfcfb0 +-0, 1335000, 80640, 0xe568caa0 +-0, 1350000, 80640, 0xdf21cc20 +-0, 1365000, 80640, 0xb66cd4a8 +-0, 1380000, 80640, 0xcd26c9c8 +-0, 1395000, 80640, 0x5fe8d598 +-0, 1410000, 80640, 0xed0dc9c8 +-0, 1425000, 80640, 0x8313d288 +-0, 1440000, 80640, 0x9ccdd4a0 +-0, 1455000, 80640, 0x66ffe970 +-0, 1470000, 80640, 0xf68ad1c8 +-0, 1485000, 80640, 0xd570f658 +-0, 1500000, 80640, 0x8c39d998 +-0, 1515000, 80640, 0xe18fe5e0 +-0, 1530000, 80640, 0xbbe7e340 +-0, 1545000, 80640, 0x9a90d470 +-0, 1560000, 80640, 0xd2bbced0 +-0, 1575000, 80640, 0xbbf9dce0 +-0, 1590000, 80640, 0x4ff7c888 +-0, 1605000, 80640, 0xc2e7e1f0 +-0, 1620000, 80640, 0x2104e3b0 +-0, 1635000, 80640, 0xaef5e8f0 +-0, 1650000, 80640, 0xc477e890 +-0, 1665000, 80640, 0xb12df778 +-0, 1680000, 80640, 0xd2115720 +-0, 1695000, 80640, 0x620b6538 +-0, 1710000, 80640, 0x894a8db8 +-0, 1725000, 80640, 0x8da3bcb0 +-0, 1740000, 80640, 0x96be8930 +-0, 1755000, 80640, 0xe69dc1f0 +-0, 1770000, 80640, 0x42b8d4e0 +-0, 1785000, 80640, 0x0a8da4f0 +-0, 1800000, 80640, 0x245fd3d8 +-0, 1815000, 80640, 0x3fd1e858 +-0, 1830000, 80640, 0xe2c299f0 +-0, 1845000, 80640, 0xda1cddd0 +-0, 1860000, 80640, 0xf126e498 +-0, 1875000, 80640, 0xc85ab920 +-0, 1890000, 80640, 0x52f39de8 +-0, 1905000, 80640, 0xd0daac60 +-0, 1920000, 80640, 0xef323347 +-0, 1935000, 80640, 0xcc063317 +-0, 1950000, 80640, 0xb6f53057 +-0, 1965000, 80640, 0x5fe53b07 +-0, 1980000, 80640, 0x63183d7f +-0, 1995000, 80640, 0x91a44bbf +-0, 2010000, 80640, 0xa433480f +-0, 2025000, 80640, 0xe90652ef +-0, 2040000, 80640, 0xe96e35bf +-0, 2055000, 80640, 0x84ff2ccf +-0, 2070000, 80640, 0x930f2b07 +-0, 2085000, 80640, 0x5a1228d7 +-0, 2100000, 80640, 0x29f226ef +-0, 2115000, 80640, 0xd35136df +-0, 2130000, 80640, 0x0e2d407f +-0, 2145000, 80640, 0x34a93267 +-0, 2160000, 80640, 0x7ae82af7 +-0, 2175000, 80640, 0xb20c2477 +-0, 2190000, 80640, 0xa104218f +-0, 2205000, 80640, 0xcb1121e7 +-0, 2220000, 80640, 0xaca04751 +-0, 2235000, 80640, 0x3a51c704 +-0, 2250000, 80640, 0xfa632e3d +-0, 2265000, 80640, 0x61c9407c +-0, 2280000, 80640, 0xe9a08dd9 +-0, 2295000, 80640, 0xebf3c623 ++0, 105000, 80640, 0xa731901a ++0, 120000, 80640, 0x0a1e5b3d ++0, 135000, 80640, 0x2c66418f ++0, 150000, 80640, 0xaaf8575a ++0, 165000, 80640, 0x2d1a60b1 ++0, 180000, 80640, 0x646d6e66 ++0, 195000, 80640, 0x090de107 ++0, 210000, 80640, 0x90991f6c ++0, 225000, 80640, 0xda862969 ++0, 240000, 80640, 0x5434e1ec ++0, 255000, 80640, 0x4e981ce7 ++0, 270000, 80640, 0x97eb4000 ++0, 285000, 80640, 0xbfb375b0 ++0, 300000, 80640, 0x1529d95d ++0, 315000, 80640, 0x2c0015af ++0, 330000, 80640, 0x63779ce1 ++0, 345000, 80640, 0x3f2b3949 ++0, 360000, 80640, 0xe3cf3be4 ++0, 375000, 80640, 0x54451a22 ++0, 390000, 80640, 0xc2901d91 ++0, 405000, 80640, 0x312f8b7e ++0, 420000, 80640, 0x99734f4e ++0, 435000, 80640, 0xe50b8391 ++0, 450000, 80640, 0x7c6b04e4 ++0, 465000, 80640, 0x04989996 ++0, 480000, 80640, 0x30c3c00f ++0, 495000, 80640, 0x77172ba4 ++0, 510000, 80640, 0x1257a596 ++0, 525000, 80640, 0x657e5fa8 ++0, 540000, 80640, 0xe66958ef ++0, 555000, 80640, 0xbf7f4f0a ++0, 570000, 80640, 0x588ac70e ++0, 585000, 80640, 0xb1a91c4b ++0, 600000, 80640, 0x5b73de24 ++0, 615000, 80640, 0xa3c15e73 ++0, 630000, 80640, 0x7326196b ++0, 645000, 80640, 0x1aa52b88 ++0, 660000, 80640, 0x0029f511 ++0, 675000, 80640, 0x2398433a ++0, 690000, 80640, 0xef9ab870 ++0, 705000, 80640, 0xb1ac9b79 ++0, 720000, 80640, 0x1cc2ab3b ++0, 735000, 80640, 0x41362b53 ++0, 750000, 80640, 0x81e33811 ++0, 765000, 80640, 0x621d285a ++0, 780000, 80640, 0x84e84c24 ++0, 795000, 80640, 0xbb8c2939 ++0, 810000, 80640, 0x6c6905a8 ++0, 825000, 80640, 0xc60bbaf0 ++0, 840000, 80640, 0xc80d08c8 ++0, 855000, 80640, 0xc5646343 ++0, 870000, 80640, 0x3df7a287 ++0, 885000, 80640, 0x628e9f78 ++0, 900000, 80640, 0x58f93044 ++0, 915000, 80640, 0x8ee3a59f ++0, 930000, 80640, 0xaa297416 ++0, 945000, 80640, 0x7bbd7307 ++0, 960000, 80640, 0x12dbee42 ++0, 975000, 80640, 0xaea5fb22 ++0, 990000, 80640, 0x9405fd0b ++0, 1005000, 80640, 0x59400b6f ++0, 1020000, 80640, 0x70beeba0 ++0, 1035000, 80640, 0xdc0681ae ++0, 1050000, 80640, 0xe4a3c803 ++0, 1065000, 80640, 0x3424c568 ++0, 1080000, 80640, 0xeb72838d ++0, 1095000, 80640, 0x671fbff3 ++0, 1110000, 80640, 0xa4b849bd ++0, 1125000, 80640, 0xf4c2be6f ++0, 1140000, 80640, 0xb91988fd ++0, 1155000, 80640, 0xd0e5bf3a ++0, 1170000, 80640, 0x78c2b0bc ++0, 1185000, 80640, 0xcf2deb74 ++0, 1200000, 80640, 0x84a9081b ++0, 1215000, 80640, 0x9931e9b1 ++0, 1230000, 80640, 0x1ce6b59d ++0, 1245000, 80640, 0x24a31152 ++0, 1260000, 80640, 0x206f4677 ++0, 1275000, 80640, 0x507755ab ++0, 1290000, 80640, 0xc4b5643a ++0, 1305000, 80640, 0x197445f7 ++0, 1320000, 80640, 0x53232d2a ++0, 1335000, 80640, 0x33ae27d4 ++0, 1350000, 80640, 0x77bb2925 ++0, 1365000, 80640, 0xb0d53220 ++0, 1380000, 80640, 0xacdb26fc ++0, 1395000, 80640, 0xa83d32e1 ++0, 1410000, 80640, 0xe2002717 ++0, 1425000, 80640, 0xb1722fed ++0, 1440000, 80640, 0xa7de3206 ++0, 1455000, 80640, 0x68f94780 ++0, 1470000, 80640, 0x2bcc2f28 ++0, 1485000, 80640, 0xaf9354e5 ++0, 1500000, 80640, 0x45b4375c ++0, 1515000, 80640, 0x60e043ee ++0, 1530000, 80640, 0x9ed5411e ++0, 1545000, 80640, 0xbae131ce ++0, 1560000, 80640, 0x33be2be6 ++0, 1575000, 80640, 0xdadb3a4c ++0, 1590000, 80640, 0xe9e72559 ++0, 1605000, 80640, 0x9fe93f8c ++0, 1620000, 80640, 0xc20b413a ++0, 1635000, 80640, 0x02c74699 ++0, 1650000, 80640, 0x1b284634 ++0, 1665000, 80640, 0xb7ea559e ++0, 1680000, 80640, 0x62e3b0e1 ++0, 1695000, 80640, 0x8b6bbf68 ++0, 1710000, 80640, 0x04d2e8d8 ++0, 1725000, 80640, 0xc6961955 ++0, 1740000, 80640, 0xf318e461 ++0, 1755000, 80640, 0x55231e8f ++0, 1770000, 80640, 0x772f325e ++0, 1785000, 80640, 0x31480120 ++0, 1800000, 80640, 0x5eda30fe ++0, 1815000, 80640, 0x5c534632 ++0, 1830000, 80640, 0xaca0f5c9 ++0, 1845000, 80640, 0x9ec83b5a ++0, 1860000, 80640, 0x65944233 ++0, 1875000, 80640, 0xbf7e15f0 ++0, 1890000, 80640, 0xf985f9b7 ++0, 1905000, 80640, 0x0e7a0887 ++0, 1920000, 80640, 0xee33931b ++0, 1935000, 80640, 0xea6b92f8 ++0, 1950000, 80640, 0xde559025 ++0, 1965000, 80640, 0x970c9af6 ++0, 1980000, 80640, 0x6a579d8a ++0, 1995000, 80640, 0x7053ac0c ++0, 2010000, 80640, 0x6d6ca81b ++0, 2025000, 80640, 0x6ffdb338 ++0, 2040000, 80640, 0x402f953f ++0, 2055000, 80640, 0x24358c04 ++0, 2070000, 80640, 0x26298a25 ++0, 2085000, 80640, 0xbc0487e7 ++0, 2100000, 80640, 0xf8c885fd ++0, 2115000, 80640, 0x98a79695 ++0, 2130000, 80640, 0x846aa04b ++0, 2145000, 80640, 0x22ba919b ++0, 2160000, 80640, 0xcba08a11 ++0, 2175000, 80640, 0xfba0836c ++0, 2190000, 80640, 0xb7ff8059 ++0, 2205000, 80640, 0xb15080bb ++0, 2220000, 80640, 0x42627aed ++0, 2235000, 80640, 0xd045d485 ++0, 2250000, 80640, 0xf22e7545 ++0, 2265000, 80640, 0xe24a41fc ++0, 2280000, 80640, 0x854696ac ++0, 2295000, 80640, 0x6722f8f2 + 0, 2310000, 80640, 0x00000000 + 0, 2325000, 80640, 0x0f412500 + 0, 2340000, 80640, 0x0f412500 +@@ -159,16 +159,16 @@ + 0, 2370000, 80640, 0xb6634270 + 0, 2385000, 80640, 0x9e43a4a0 + 0, 2400000, 80640, 0x136ab60b +-0, 2415000, 80640, 0x6ce3254e +-0, 2430000, 80640, 0xf4340d15 +-0, 2445000, 80640, 0x73861114 +-0, 2460000, 80640, 0x36b300d3 +-0, 2475000, 80640, 0x2ddde523 +-0, 2490000, 80640, 0xfdd79c02 +-0, 2505000, 80640, 0xe6cc4fe9 +-0, 2520000, 80640, 0x5b13e2b9 +-0, 2535000, 80640, 0x0d588e70 +-0, 2550000, 80640, 0xc6e4023f +-0, 2565000, 80640, 0xf54c496f +-0, 2580000, 80640, 0xa315a5cf +-0, 2595000, 80640, 0x2d2ac9c7 ++0, 2415000, 80640, 0xe43625dc ++0, 2430000, 80640, 0xc2eb0f8c ++0, 2445000, 80640, 0x99af167d ++0, 2460000, 80640, 0xd9cb0a37 ++0, 2475000, 80640, 0x1f2cf2ce ++0, 2490000, 80640, 0x00eeae7f ++0, 2505000, 80640, 0xcc1d666c ++0, 2520000, 80640, 0x77d6fcc9 ++0, 2535000, 80640, 0x58c8acc6 ++0, 2550000, 80640, 0xd026238d ++0, 2565000, 80640, 0xfefb6c9b ++0, 2580000, 80640, 0xa9a5cb36 ++0, 2595000, 80640, 0xc845f000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/8bps xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/8bps +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/8bps 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/8bps 2012-05-14 14:08:55.613365723 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 2048, 0x3d042426 + 0, 0, 259200, 0x7e91df07 ++1, 0, 2048, 0x3d042426 + 1, 4180, 2048, 0x5bcae456 + 0, 7200, 259200, 0x7e91df07 + 1, 8359, 2048, 0xb6043655 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/aac-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/aac-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/aac-demux 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/aac-demux 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-CRC=0xbda37454 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/aasc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/aasc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/aasc 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/aasc 2012-05-14 14:08:55.614365743 +0200 +@@ -21,3 +21,4 @@ + 0, 72000, 168000, 0x646fa087 + 0, 75600, 168000, 0x404450a2 + 0, 79200, 168000, 0x5214c456 ++0, 82800, 168000, 0xaef602d3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative 2012-05-14 14:08:55.615365763 +0200 +@@ -0,0 +1 @@ ++66004779a5e51ca659b21a4197e019e6 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2.6bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2.6bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2.6bit 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2.6bit 2012-05-14 14:08:55.615365763 +0200 +@@ -0,0 +1 @@ ++dee4417597abc2db70a175d6809870e7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2bit 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-2bit 2012-05-14 14:08:55.616365783 +0200 +@@ -0,0 +1 @@ ++832846066fbce28821b7f0717c4d3a90 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-4bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-4bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-4bit 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-creative-8-4bit 2012-05-14 14:08:55.616365783 +0200 +@@ -0,0 +1 @@ ++1813d196cef83f7030bb150399b2903e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ea-mad-ea-r1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ea-mad-ea-r1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ea-mad-ea-r1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ea-mad-ea-r1 2012-05-14 14:08:55.617365803 +0200 +@@ -0,0 +1,191 @@ ++0, 0, 535680, 0x889c32cf ++1, 0, 6496, 0x00000000 ++0, 2970, 535680, 0x0b1ef044 ++1, 3045, 6384, 0x00000000 ++0, 5940, 535680, 0xa7d0818b ++1, 6038, 6384, 0x00000000 ++0, 8910, 535680, 0xf392e4e1 ++1, 9030, 6384, 0x00000000 ++0, 11880, 535680, 0x08480c69 ++1, 12023, 6384, 0x00000000 ++0, 14850, 535680, 0x2b8af1ed ++1, 15015, 6496, 0xe2034d04 ++0, 17820, 535680, 0x0d58e062 ++1, 18060, 6384, 0x089c9157 ++0, 20790, 535680, 0xd140ced0 ++1, 21053, 6384, 0xeed5743c ++0, 23760, 535680, 0xbd0e6652 ++1, 24045, 6384, 0x71de6b34 ++0, 26730, 535680, 0xdc2f2a6b ++1, 27038, 6384, 0xc0d67710 ++0, 29700, 535680, 0x97c31a38 ++1, 30030, 6496, 0x35786490 ++0, 32670, 535680, 0x1a2bdf38 ++1, 33075, 6384, 0xdf1c99a2 ++0, 35640, 535680, 0xb3af3ac4 ++1, 36068, 6384, 0xca9591ad ++0, 38610, 535680, 0x07a52577 ++1, 39060, 6384, 0x6f0d9c3d ++0, 41580, 535680, 0x78407368 ++1, 42053, 6384, 0xfacbbaee ++0, 44550, 535680, 0xd2a9efc3 ++1, 45045, 6496, 0x927fb136 ++0, 47520, 535680, 0x36df2f29 ++1, 48090, 6384, 0x9d4f2572 ++0, 50490, 535680, 0x9821d8f7 ++1, 51083, 6384, 0x2a3c6d08 ++0, 53460, 535680, 0xf64321aa ++1, 54075, 6384, 0x4282b1e0 ++0, 56430, 535680, 0x53e4d9aa ++1, 57068, 6384, 0xc4a77b9f ++0, 59400, 535680, 0xdbd6f853 ++1, 60060, 6496, 0x2af6a14f ++0, 62370, 535680, 0x5d40cf8b ++1, 63105, 6384, 0x4d734169 ++0, 65340, 535680, 0xe624af9d ++1, 66098, 6384, 0xb91b5865 ++0, 68310, 535680, 0xd9dbb4cd ++1, 69090, 6384, 0x9dce2417 ++0, 71280, 535680, 0xf14e72ec ++1, 72083, 6384, 0xb7c4e1ce ++0, 74250, 535680, 0xb35c18f6 ++1, 75075, 6496, 0xef0dc07a ++0, 77220, 535680, 0xc96d7757 ++1, 78120, 6384, 0x4ad21d10 ++0, 80190, 535680, 0xdfb937df ++1, 81113, 6384, 0xcfe14682 ++0, 83160, 535680, 0x40cd71d7 ++1, 84105, 6384, 0x07be48eb ++0, 86130, 535680, 0x15e176d6 ++1, 87098, 6384, 0x09de3498 ++0, 89100, 535680, 0x7f891b24 ++1, 90090, 6496, 0xab2e9686 ++0, 92070, 535680, 0xb87a8c32 ++1, 93135, 6384, 0x3aba3ccc ++0, 95040, 535680, 0x0c01541f ++1, 96128, 6384, 0x0a905ec3 ++0, 98010, 535680, 0x9eee99b3 ++1, 99120, 6384, 0x76a93ce4 ++0, 100980, 535680, 0xd65eb689 ++1, 102113, 6384, 0xa99063a4 ++0, 103950, 535680, 0x6e733cfa ++1, 105105, 6496, 0xc16bb88d ++0, 106920, 535680, 0xac536670 ++1, 108150, 6384, 0x650379bf ++0, 109890, 535680, 0x002275b8 ++1, 111143, 6384, 0x4e0749fe ++0, 112860, 535680, 0x6a5385cb ++1, 114135, 6384, 0x778e8d12 ++0, 115830, 535680, 0xd129ade3 ++1, 117128, 6384, 0x9fa8c494 ++0, 118800, 535680, 0x32cab5d7 ++1, 120120, 6496, 0x61d5bead ++0, 121770, 535680, 0x08be1c8f ++1, 123165, 6384, 0x4da9bc3c ++0, 124740, 535680, 0x59e1fba0 ++1, 126158, 6384, 0xa72b6f93 ++0, 127710, 535680, 0x138aee3a ++1, 129150, 6384, 0x811f5f77 ++0, 130680, 535680, 0x4cfbcd5e ++1, 132143, 6384, 0x83ea5e3d ++0, 133650, 535680, 0xf6cf0fb4 ++1, 135135, 6496, 0x78bab460 ++0, 136620, 535680, 0xb13a06de ++1, 138180, 6384, 0xc9a07432 ++0, 139590, 535680, 0x59176f00 ++1, 141173, 6384, 0x4b4f2a34 ++0, 142560, 535680, 0xf84b4ca3 ++1, 144165, 6384, 0x4d707a53 ++0, 145530, 535680, 0x7fd09f73 ++1, 147158, 6384, 0x703efb60 ++0, 148500, 535680, 0x3be383b8 ++1, 150150, 6496, 0x319a77bb ++0, 151470, 535680, 0xa7118e51 ++1, 153195, 6384, 0xbdfd82ec ++0, 154440, 535680, 0xbd83120c ++1, 156188, 6384, 0x413c3503 ++0, 157410, 535680, 0x3bc9d256 ++1, 159180, 6384, 0xe6e666b3 ++0, 160380, 535680, 0xb6c87f87 ++1, 162173, 6384, 0xa09c7342 ++0, 163350, 535680, 0xe80d110a ++1, 165165, 6496, 0x60cba846 ++0, 166320, 535680, 0xb3a83362 ++1, 168210, 6384, 0x0ba34308 ++0, 169290, 535680, 0xfb39eb52 ++1, 171203, 6384, 0xdc3a65f0 ++0, 172260, 535680, 0xbf6e1220 ++1, 174195, 6384, 0x1ebf9dc4 ++0, 175230, 535680, 0x9ecdfbae ++1, 177188, 6384, 0xbbcb1449 ++0, 178200, 535680, 0x069a65f5 ++1, 180180, 6496, 0x926574eb ++0, 181170, 535680, 0x206e372c ++1, 183225, 6384, 0xb4da92f1 ++0, 184140, 535680, 0x58c83dd4 ++1, 186218, 6384, 0xdbbd21e0 ++0, 187110, 535680, 0xc3562b03 ++1, 189210, 6384, 0x08510eff ++0, 190080, 535680, 0xd1ed85a0 ++1, 192203, 6384, 0x9534b7ca ++0, 193050, 535680, 0xb6205f4b ++1, 195195, 6496, 0x50a5ed30 ++0, 196020, 535680, 0xaedf8bfa ++1, 198240, 6384, 0xf5ac2f7c ++0, 198990, 535680, 0xa48d5dea ++1, 201233, 6384, 0x4fe1fa55 ++0, 201960, 535680, 0xff82e7c1 ++1, 204225, 6384, 0xd61c4c05 ++0, 204930, 535680, 0xc9560222 ++1, 207218, 6384, 0x56d11b45 ++0, 207900, 535680, 0x0fafa549 ++1, 210210, 6496, 0x3906084b ++0, 210870, 535680, 0x8d556ccb ++1, 213255, 6384, 0x1ef31fed ++0, 213840, 535680, 0x802aac1f ++1, 216248, 6384, 0x58ed82f5 ++0, 216810, 535680, 0x7d0fa168 ++1, 219240, 6384, 0xb31ccd1f ++0, 219780, 535680, 0x1a9255c9 ++1, 222233, 6384, 0xfb648285 ++0, 222750, 535680, 0xb4ec7e35 ++1, 225225, 6496, 0xfae2950b ++0, 225720, 535680, 0x48fac072 ++1, 228270, 6384, 0xe28c8357 ++0, 228690, 535680, 0x1e260135 ++1, 231263, 6384, 0xda718e60 ++0, 231660, 535680, 0xce4d5079 ++1, 234255, 6384, 0x27516999 ++0, 234630, 535680, 0x13e5e4ed ++1, 237248, 6384, 0x0ba07921 ++0, 237600, 535680, 0x592305ec ++1, 240240, 6496, 0xcfbecfab ++0, 240570, 535680, 0x9e227508 ++1, 243285, 6384, 0xae4cedcd ++0, 243540, 535680, 0x1d37e5ea ++1, 246278, 6384, 0x917b4707 ++0, 246510, 535680, 0x7eae7692 ++1, 249270, 6384, 0x8671b28e ++0, 249480, 535680, 0xf452e4b9 ++1, 252263, 6384, 0x9a1238fa ++0, 252450, 535680, 0x1460e7e9 ++1, 255255, 6496, 0x23b8f8ca ++0, 255420, 535680, 0xc6d8a638 ++1, 258300, 6384, 0x3903bcd6 ++0, 258390, 535680, 0x854f5fb0 ++1, 261293, 6384, 0x0532b267 ++0, 261360, 535680, 0x854f5fb0 ++1, 264285, 6384, 0xde931220 ++0, 264330, 535680, 0x70a02d87 ++1, 267278, 6384, 0x4ed70a80 ++0, 267300, 535680, 0x9a4ad464 ++0, 270270, 535680, 0x9a4ad464 ++1, 270270, 6496, 0x4a52d5a1 ++0, 273240, 535680, 0x9a4ad464 ++1, 273315, 6384, 0xc1be5760 ++0, 276210, 535680, 0x9a4ad464 ++1, 276308, 6384, 0x790d69ba ++0, 279180, 535680, 0x9a4ad464 ++1, 279300, 6384, 0x9d73e6cf ++0, 282150, 535680, 0x9a4ad464 ++1, 282293, 6272, 0xbc0fc725 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ea-tqi xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ea-tqi +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ea-tqi 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ea-tqi 2012-05-14 14:08:55.617365803 +0200 +@@ -0,0 +1,51 @@ ++0, 0, 115200, 0x375ec573 ++1, 0, 5936, 0x00000000 ++0, 6000, 115200, 0x375ec573 ++1, 6057, 5824, 0x00000000 ++0, 12000, 115200, 0x375ec573 ++1, 12000, 5936, 0x00000000 ++0, 18000, 115200, 0x375ec573 ++1, 18057, 5824, 0x00000000 ++0, 24000, 115200, 0x375ec573 ++1, 24000, 5936, 0x00000000 ++0, 30000, 115200, 0x375ec573 ++1, 30057, 5824, 0x00000000 ++0, 36000, 115200, 0x375ec573 ++1, 36000, 5936, 0x00000000 ++0, 42000, 115200, 0x375ec573 ++1, 42057, 5824, 0x0f06f5bb ++0, 48000, 115200, 0x0b4d31bf ++1, 48000, 5936, 0xb0dbfc46 ++0, 54000, 115200, 0xdd724598 ++1, 54057, 5824, 0x9daa9f9c ++0, 60000, 115200, 0xc3077e75 ++1, 60000, 5936, 0x61400d2f ++0, 66000, 115200, 0xbf70778a ++1, 66057, 5824, 0x34a5b0e3 ++0, 72000, 115200, 0x117eb766 ++1, 72000, 5936, 0x6e546f72 ++0, 78000, 115200, 0x4617fbad ++1, 78057, 5824, 0x4f093b35 ++0, 84000, 115200, 0x5f5b02d2 ++1, 84000, 5936, 0x95b5b599 ++0, 90000, 115200, 0x2a9c5325 ++1, 90057, 5824, 0x75e15e60 ++0, 96000, 115200, 0x14a89e2a ++1, 96000, 5936, 0xd1077d39 ++0, 102000, 115200, 0xe69aa994 ++1, 102057, 5824, 0x956e21ca ++0, 108000, 115200, 0xfbacf589 ++1, 108000, 5936, 0x33bac234 ++0, 114000, 115200, 0x1d714c6e ++1, 114057, 5824, 0x5df37824 ++0, 120000, 115200, 0x6eff66cb ++1, 120000, 5936, 0xc174af24 ++0, 126000, 115200, 0xee21c1cb ++1, 126057, 5824, 0xe5dc2159 ++0, 132000, 115200, 0xce714ada ++1, 132000, 5936, 0x63ffc8b1 ++0, 138000, 115200, 0xf89d56c3 ++1, 138057, 5824, 0xefe4c365 ++0, 144000, 115200, 0x65fd5e60 ++1, 144000, 5936, 0x2174304d ++0, 150000, 115200, 0x0c256424 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk3 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk3 2012-05-14 14:08:55.618365823 +0200 +@@ -0,0 +1 @@ ++bb952ae86c72d461aef7583685ec0a4d +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk4 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima-dk4 2012-05-14 14:08:55.618365823 +0200 +@@ -0,0 +1 @@ ++5234b53dde4961dd715a2524d6a8eb75 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima_wav-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima_wav-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-ima_wav-stereo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-ima_wav-stereo 2012-05-14 14:08:55.619365843 +0200 +@@ -0,0 +1 @@ ++1ee96f1efc09251a732621049dc5b66e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm_ms-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm_ms-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm_ms-stereo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm_ms-stereo 2012-05-14 14:08:55.621365885 +0200 +@@ -0,0 +1 @@ ++3b7554e9a186c30adfd2a86bae950f4a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-psx-str-v3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-psx-str-v3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-psx-str-v3 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-psx-str-v3 2012-05-14 14:08:55.620365864 +0200 +@@ -0,0 +1,37 @@ ++0, 0, 8064, 0xa307ed8c ++0, 4800, 8064, 0xd2551927 ++0, 9600, 8064, 0x3264a799 ++0, 14400, 8064, 0x75da1393 ++0, 19200, 8064, 0x68665f59 ++0, 24000, 8064, 0xaf266a18 ++0, 28800, 8064, 0x4d4b69fd ++0, 33600, 8064, 0x129d7e17 ++0, 38400, 8064, 0x78c56725 ++0, 43200, 8064, 0x59902cf1 ++0, 48000, 8064, 0x6e699c87 ++0, 52800, 8064, 0xc30692d7 ++0, 57600, 8064, 0x29c043e5 ++0, 62400, 8064, 0x61907704 ++0, 67200, 8064, 0xf9210630 ++0, 72000, 8064, 0xc0bdda08 ++0, 76800, 8064, 0x6171b96d ++0, 81600, 8064, 0x082947cf ++0, 86400, 8064, 0xf7bbf1ce ++0, 91200, 8064, 0xe50e4436 ++0, 96000, 8064, 0x2a860844 ++0, 100800, 8064, 0xedcb502c ++0, 105600, 8064, 0x448e3c7f ++0, 110400, 8064, 0xf782f366 ++0, 115200, 8064, 0xf57f66a5 ++0, 120000, 8064, 0xdcc36939 ++0, 124800, 8064, 0x34959d99 ++0, 129600, 8064, 0xa5c20433 ++0, 134400, 8064, 0xf1364e9b ++0, 139200, 8064, 0x232fe9c7 ++0, 144000, 8064, 0xdc068d5a ++0, 148800, 8064, 0x4962e812 ++0, 153600, 8064, 0x36a6709b ++0, 158400, 8064, 0xa2837bd8 ++0, 163200, 8064, 0x68612ddb ++0, 168000, 8064, 0x8d76d1cb ++0, 172800, 8064, 0x7707cfc7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-thp xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-thp +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adpcm-thp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adpcm-thp 2012-05-14 14:08:55.620365864 +0200 +@@ -0,0 +1,143 @@ ++0, 0, 291840, 0xbd7e0b22 ++1, 0, 4312, 0x469714f6 ++0, 3003, 291840, 0xf6e12ca5 ++1, 3032, 4256, 0xe03dd882 ++0, 6006, 291840, 0x528c7049 ++1, 6024, 4312, 0x46b901f7 ++0, 9009, 291840, 0x93055de9 ++1, 9056, 4256, 0x8d4a54e4 ++0, 12012, 291840, 0xf95a51c1 ++1, 12049, 4256, 0xfd616b67 ++0, 15015, 291840, 0x6ad3a65a ++1, 15041, 4312, 0xefe62302 ++0, 18018, 291840, 0x494684a7 ++1, 18073, 4256, 0xab11684e ++0, 21021, 291840, 0x74c14eb1 ++1, 21066, 4256, 0xb4b3feb8 ++0, 24024, 291840, 0x149fcb7e ++1, 24058, 4312, 0x71db6461 ++0, 27027, 291840, 0x25649761 ++1, 27090, 4256, 0x090e5efa ++0, 30030, 291840, 0xbc3f9052 ++1, 30083, 4256, 0x36f49c28 ++0, 33033, 291840, 0x080edfff ++1, 33075, 4312, 0x0fe3d262 ++0, 36036, 291840, 0x6d7ad684 ++1, 36107, 4256, 0x199ce269 ++0, 39039, 291840, 0x6d53844d ++1, 39099, 4256, 0x98342d05 ++0, 42042, 291840, 0xf7ad5385 ++1, 42092, 4312, 0xb6fb7ebe ++0, 45045, 291840, 0x0241b56a ++1, 45124, 4256, 0x033dd562 ++0, 48048, 291840, 0x120122c8 ++1, 48116, 4256, 0xc2cc17e0 ++0, 51051, 291840, 0x31b0f32a ++1, 51109, 4312, 0x4bb3ff50 ++0, 54054, 291840, 0x14068b98 ++1, 54141, 4256, 0x6f2671ef ++0, 57057, 291840, 0xeeec658b ++1, 57133, 4256, 0x5a337bf4 ++0, 60060, 291840, 0x9376374c ++1, 60126, 4312, 0xa71f6967 ++0, 63063, 291840, 0x091e8c6e ++1, 63158, 4256, 0x48084aa9 ++0, 66066, 291840, 0x744ad07f ++1, 66150, 4256, 0x3cce4218 ++0, 69069, 291840, 0xf99c554e ++1, 69143, 4312, 0xcbb8f73d ++0, 72072, 291840, 0xc84bd677 ++1, 72174, 4256, 0x36825021 ++0, 75075, 291840, 0x3898d474 ++1, 75167, 4256, 0xeae036c6 ++0, 78078, 291840, 0x1e2910c8 ++1, 78159, 4312, 0x0d650ac6 ++0, 81081, 291840, 0xb11f58bc ++1, 81191, 4256, 0xfba4f58c ++0, 84084, 291840, 0xf89170ee ++1, 84184, 4256, 0x54311f9b ++0, 87087, 291840, 0x8f239dc3 ++1, 87176, 4312, 0x286386b3 ++0, 90090, 291840, 0x8538c76c ++1, 90208, 4256, 0x871896de ++0, 93093, 291840, 0x162ee66f ++1, 93201, 4256, 0x9ef9f970 ++0, 96096, 291840, 0x5f8708a5 ++1, 96193, 4312, 0xf9ae97f1 ++0, 99099, 291840, 0x95802dfb ++1, 99225, 4256, 0x0ad0d765 ++0, 102102, 291840, 0xc424630d ++1, 102218, 4256, 0x8e6aa9b5 ++0, 105105, 291840, 0xfb8a8667 ++1, 105210, 4312, 0x8362787b ++0, 108108, 291840, 0xbad79af5 ++1, 108242, 4256, 0x9b6a5d9c ++0, 111111, 291840, 0xc733b325 ++1, 111234, 4256, 0xfb715d8f ++0, 114114, 291840, 0x4bfbcd70 ++1, 114227, 4312, 0x02bd8075 ++0, 117117, 291840, 0x502cd950 ++1, 117259, 4256, 0x428eb932 ++0, 120120, 291840, 0x8461ca2c ++1, 120251, 4256, 0x17ea8c94 ++0, 123123, 291840, 0x00219b0d ++1, 123244, 4312, 0xb3e761d7 ++0, 126126, 291840, 0xa4de45e1 ++1, 126276, 4256, 0x0919755a ++0, 129129, 291840, 0xacd3f4df ++1, 129268, 4256, 0x5e520edd ++0, 132132, 291840, 0x2203a369 ++1, 132261, 4312, 0x69aa070e ++0, 135135, 291840, 0x0a66effa ++1, 135293, 4256, 0xf8192f7d ++0, 138138, 291840, 0x7ac1fd91 ++1, 138285, 4256, 0xaad4475c ++0, 141141, 291840, 0x84970aa7 ++1, 141278, 4312, 0x0cabcfcb ++0, 144144, 291840, 0x569d145f ++1, 144309, 4256, 0x952f0f96 ++0, 147147, 291840, 0xe51efe1b ++1, 147302, 4256, 0x1b805a0c ++0, 150150, 291840, 0x38e2cd78 ++1, 150294, 4312, 0x93043d2a ++0, 153153, 291840, 0x93428ea2 ++1, 153326, 4256, 0x38b99e44 ++0, 156156, 291840, 0x3d3f5b17 ++1, 156319, 4256, 0x60cc52ff ++0, 159159, 291840, 0x9546127d ++1, 159311, 4312, 0x6a875849 ++0, 162162, 291840, 0x4178be54 ++1, 162343, 4256, 0xd08d6d0e ++0, 165165, 291840, 0x0d0f8036 ++1, 165336, 4256, 0x36bfe48e ++0, 168168, 291840, 0xc20557b9 ++1, 168328, 4312, 0x795c6134 ++0, 171171, 291840, 0x6d4b2d64 ++1, 171360, 4256, 0x4fd79583 ++0, 174174, 291840, 0xa750125d ++1, 174353, 4256, 0x65e2ab9f ++0, 177177, 291840, 0x04623ce3 ++1, 177345, 4312, 0xedeede4a ++0, 180180, 291840, 0xc7f2bbc7 ++1, 180377, 4256, 0x097e0d09 ++0, 183183, 291840, 0x6e271336 ++1, 183369, 4256, 0x58afa133 ++0, 186186, 291840, 0xcfbd4246 ++1, 186362, 4312, 0x442525b5 ++0, 189189, 291840, 0xe1493be9 ++1, 189394, 4256, 0x6645c591 ++0, 192192, 291840, 0x6c731194 ++1, 192386, 4256, 0xb0dd948a ++0, 195195, 291840, 0x0fc30cc2 ++1, 195379, 4312, 0x12684e69 ++0, 198198, 291840, 0x967427f3 ++1, 198411, 4256, 0xb45098e3 ++0, 201201, 291840, 0x55ae3b00 ++1, 201403, 4256, 0xb6d3c61c ++0, 204204, 291840, 0xbe4f200c ++1, 204396, 4312, 0xb46b5b22 ++0, 207207, 291840, 0xc515e443 ++1, 207428, 4256, 0x9a556830 ++0, 210210, 291840, 0xd738bd69 ++1, 210420, 4256, 0x67ca2b35 ++0, 213213, 291840, 0xa8e0ab69 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adts-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adts-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/adts-demux 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/adts-demux 2012-05-14 14:08:55.621365885 +0200 +@@ -0,0 +1 @@ ++CRC=0xbda37454 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/armovie-escape124 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/armovie-escape124 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/armovie-escape124 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/armovie-escape124 2012-05-14 14:08:55.622365905 +0200 +@@ -1,104 +1,104 @@ +-0, 0, 230400, 0x5288d70f ++0, 0, 230400, 0xd133e177 + 1, 0, 176400, 0xdd61578c +-0, 3600, 230400, 0x2d3c1066 +-0, 7200, 230400, 0x89eb5b4a +-0, 10800, 230400, 0x24c2d2e7 +-0, 14400, 230400, 0x9271cb38 +-0, 18000, 230400, 0xc74a5009 +-0, 21600, 230400, 0x61d70705 +-0, 25200, 230400, 0x6bb2c252 +-0, 28800, 230400, 0x6b3ac910 +-0, 32400, 230400, 0x44071f28 +-0, 36000, 230400, 0x8abd00fe +-0, 39600, 230400, 0xcbe3395d +-0, 43200, 230400, 0x603e7b7a +-0, 46800, 230400, 0x2ca8865b +-0, 50400, 230400, 0x11b4c665 +-0, 54000, 230400, 0x3f19787c +-0, 57600, 230400, 0x651d24b6 +-0, 61200, 230400, 0x325d05af +-0, 64800, 230400, 0x4f89d8a8 +-0, 68400, 230400, 0xb07647f0 +-0, 72000, 230400, 0x71141237 +-0, 75600, 230400, 0xa848a2d2 +-0, 79200, 230400, 0x3fbe4b58 +-0, 82800, 230400, 0xa1e235a0 +-0, 86400, 230400, 0x9bcf607a +-0, 90000, 230400, 0x3302e9eb ++0, 3600, 230400, 0xe3501bb2 ++0, 7200, 230400, 0x44da84f0 ++0, 10800, 230400, 0xe0fd17ed ++0, 14400, 230400, 0xef4e08c7 ++0, 18000, 230400, 0xf52f82b5 ++0, 21600, 230400, 0x05eb186c ++0, 25200, 230400, 0x0653f05d ++0, 28800, 230400, 0xde1a0735 ++0, 32400, 230400, 0x6045576e ++0, 36000, 230400, 0xac9444c4 ++0, 39600, 230400, 0x5f7f82fb ++0, 43200, 230400, 0xaf4718ce ++0, 46800, 230400, 0x117d5787 ++0, 50400, 230400, 0x319ac1f5 ++0, 54000, 230400, 0xd05cb30a ++0, 57600, 230400, 0x96107c72 ++0, 61200, 230400, 0x73ff0a30 ++0, 64800, 230400, 0x865d0f3e ++0, 68400, 230400, 0x3384ad55 ++0, 72000, 230400, 0x6694b2ea ++0, 75600, 230400, 0x324f5cb8 ++0, 79200, 230400, 0x2de7c12f ++0, 82800, 230400, 0x57fedb1a ++0, 86400, 230400, 0xf46f2abf ++0, 90000, 230400, 0xe5fead9b + 1, 90000, 176400, 0x0b9e6d67 +-0, 93600, 230400, 0xd731ba90 +-0, 97200, 230400, 0x821eedcf +-0, 100800, 230400, 0xd068a93d +-0, 104400, 230400, 0x2811d46e +-0, 108000, 230400, 0xd9740446 +-0, 111600, 230400, 0x1bce0df6 +-0, 115200, 230400, 0x44bc60ad +-0, 118800, 230400, 0xf56f6200 +-0, 122400, 230400, 0x874a2264 +-0, 126000, 230400, 0xaa155c0e +-0, 129600, 230400, 0x595392d4 +-0, 133200, 230400, 0x58dc57de +-0, 136800, 230400, 0x1c06733e +-0, 140400, 230400, 0x6807b1db +-0, 144000, 230400, 0x3fedff87 +-0, 147600, 230400, 0x3e38cc13 +-0, 151200, 230400, 0x6685ec35 +-0, 154800, 230400, 0x6c0742fd +-0, 158400, 230400, 0x8108f83c +-0, 162000, 230400, 0xc0e217c8 +-0, 165600, 230400, 0xb22ca65d +-0, 169200, 230400, 0xd54cec93 +-0, 172800, 230400, 0xd9d61de3 +-0, 176400, 230400, 0x7e0f9675 +-0, 180000, 230400, 0x9869f5b7 ++0, 93600, 230400, 0x65764edb ++0, 97200, 230400, 0xeabdcf53 ++0, 100800, 230400, 0xaeb659fc ++0, 104400, 230400, 0x5ec97eb1 ++0, 108000, 230400, 0x2482abae ++0, 111600, 230400, 0x297fb0c8 ++0, 115200, 230400, 0x57a52a3d ++0, 118800, 230400, 0x44040e98 ++0, 122400, 230400, 0xa150e542 ++0, 126000, 230400, 0x0a1e1296 ++0, 129600, 230400, 0xf1085864 ++0, 133200, 230400, 0xe7a13b40 ++0, 136800, 230400, 0x759d384d ++0, 140400, 230400, 0x72e08991 ++0, 144000, 230400, 0x10a4bbc9 ++0, 147600, 230400, 0xb258ac16 ++0, 151200, 230400, 0xde06facb ++0, 154800, 230400, 0x94284e11 ++0, 158400, 230400, 0xedf23092 ++0, 162000, 230400, 0xc2be6319 ++0, 165600, 230400, 0x103a0b7b ++0, 169200, 230400, 0x3415888b ++0, 172800, 230400, 0x5ecaac75 ++0, 176400, 230400, 0xb9ba503e ++0, 180000, 230400, 0xb20ccf57 + 1, 180000, 176400, 0x2793fad7 +-0, 183600, 230400, 0x22f33400 +-0, 187200, 230400, 0x31b999bd +-0, 190800, 230400, 0x36c23878 +-0, 194400, 230400, 0x06093a30 +-0, 198000, 230400, 0x213f1718 +-0, 201600, 230400, 0x83683006 +-0, 205200, 230400, 0x0bfcec36 +-0, 208800, 230400, 0x01b77825 +-0, 212400, 230400, 0x650a5ea2 +-0, 216000, 230400, 0xd8b2c559 +-0, 219600, 230400, 0xb012eb10 +-0, 223200, 230400, 0x135d53a4 +-0, 226800, 230400, 0x98dd0712 +-0, 230400, 230400, 0x75240ac0 +-0, 234000, 230400, 0xa16769d5 +-0, 237600, 230400, 0x3e08cda3 +-0, 241200, 230400, 0xcd20d561 +-0, 244800, 230400, 0x3531577d +-0, 248400, 230400, 0x65ff4c82 +-0, 252000, 230400, 0x8fd4a580 +-0, 255600, 230400, 0x3cf7af4c +-0, 259200, 230400, 0xda7a9202 +-0, 262800, 230400, 0x4bebc138 +-0, 266400, 230400, 0x5517e685 +-0, 270000, 230400, 0x95f6c7a3 ++0, 183600, 230400, 0x0dba31ed ++0, 187200, 230400, 0x91c5e7d4 ++0, 190800, 230400, 0x09ac954b ++0, 194400, 230400, 0xe9c3d563 ++0, 198000, 230400, 0xf46eef67 ++0, 201600, 230400, 0x117f4b80 ++0, 205200, 230400, 0x61714860 ++0, 208800, 230400, 0x5c7112d0 ++0, 212400, 230400, 0xd42c51e7 ++0, 216000, 230400, 0x425f0c99 ++0, 219600, 230400, 0x4c398834 ++0, 223200, 230400, 0x237f89c2 ++0, 226800, 230400, 0xd2e29b05 ++0, 230400, 230400, 0x204a054b ++0, 234000, 230400, 0x25a9faf7 ++0, 237600, 230400, 0x83f6c1a8 ++0, 241200, 230400, 0xe48321b9 ++0, 244800, 230400, 0x714c1005 ++0, 248400, 230400, 0x36cc58e9 ++0, 252000, 230400, 0x5e9ffdd9 ++0, 255600, 230400, 0x582b55dc ++0, 259200, 230400, 0x139a7f39 ++0, 262800, 230400, 0xefb5f998 ++0, 266400, 230400, 0xeb736da8 ++0, 270000, 230400, 0x488f9847 + 1, 270000, 176400, 0xe2649a4a +-0, 273600, 230400, 0x9849ebf9 +-0, 277200, 230400, 0xd77e1c7d +-0, 280800, 230400, 0x4dc6c923 +-0, 284400, 230400, 0x7ce817c8 +-0, 288000, 230400, 0xafb4acde +-0, 291600, 230400, 0xd0030b2c +-0, 295200, 230400, 0xb3acb77c +-0, 298800, 230400, 0x4d32b61c +-0, 302400, 230400, 0x2436a915 +-0, 306000, 230400, 0xa6fd831f +-0, 309600, 230400, 0x6c6edfca +-0, 313200, 230400, 0x4b30d72e +-0, 316800, 230400, 0x59f46a8a +-0, 320400, 230400, 0xa2d0435f +-0, 324000, 230400, 0x463872c4 +-0, 327600, 230400, 0x1d7e870a +-0, 331200, 230400, 0x74f4e530 +-0, 334800, 230400, 0xbc61053d +-0, 338400, 230400, 0x5fb238dc +-0, 342000, 230400, 0x14a29d83 +-0, 345600, 230400, 0x3fd1d09b +-0, 349200, 230400, 0x098afc13 +-0, 352800, 230400, 0x9bd12a62 +-0, 356400, 230400, 0x7bf71419 ++0, 273600, 230400, 0x6ab20741 ++0, 277200, 230400, 0xa73686f0 ++0, 280800, 230400, 0x67878643 ++0, 284400, 230400, 0x83bb241b ++0, 288000, 230400, 0xe6b70660 ++0, 291600, 230400, 0x87f5aca3 ++0, 295200, 230400, 0x29c79bc3 ++0, 298800, 230400, 0xcadbd70b ++0, 302400, 230400, 0x8cdcfdee ++0, 306000, 230400, 0x90aa0442 ++0, 309600, 230400, 0xa68e87b7 ++0, 313200, 230400, 0xa2c49e58 ++0, 316800, 230400, 0x9a9a4c55 ++0, 320400, 230400, 0x06b53aed ++0, 324000, 230400, 0x79e1808a ++0, 327600, 230400, 0x3e53a411 ++0, 331200, 230400, 0xfebc13ca ++0, 334800, 230400, 0x1f1f443b ++0, 338400, 230400, 0xd0db806a ++0, 342000, 230400, 0x6f2aee94 ++0, 345600, 230400, 0xe8cc23ba ++0, 349200, 230400, 0x2edf510b ++0, 352800, 230400, 0x87118129 ++0, 356400, 230400, 0x1dd1709a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/auravision xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/auravision +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/auravision 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/auravision 1970-01-01 01:00:00.000000000 +0100 +@@ -1,24 +0,0 @@ +-0, 0, 28800, 0x4a4efbbc +-0, 6001, 28800, 0xc6c7e26a +-0, 12002, 28800, 0x6cd40913 +-0, 18003, 28800, 0xa7b40fe9 +-0, 24004, 28800, 0x5e77fcc6 +-0, 30005, 28800, 0x9b3ef3f0 +-0, 36006, 28800, 0xe7031845 +-0, 42007, 28800, 0x2c15458d +-0, 48008, 28800, 0xbc3d4abf +-0, 54009, 28800, 0xf8755ac7 +-0, 60010, 28800, 0x64d0405b +-0, 66011, 28800, 0x1e0c341d +-0, 72012, 28800, 0x05ca3c2b +-0, 78013, 28800, 0x28cb307f +-0, 84014, 28800, 0x3a9855af +-0, 90015, 28800, 0x92b63321 +-0, 96016, 28800, 0x85585151 +-0, 102017, 28800, 0x1ff01bf9 +-0, 108018, 28800, 0x4bab200f +-0, 114019, 28800, 0xcf732ad7 +-0, 120020, 28800, 0xced00cff +-0, 126021, 28800, 0xa69046fd +-0, 132022, 28800, 0x5aa341c3 +-0, 138023, 28800, 0x87ef6219 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/auravision-v1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/auravision-v1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/auravision-v1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/auravision-v1 2012-05-14 14:08:55.623365925 +0200 +@@ -0,0 +1,24 @@ ++0, 0, 28800, 0x4a4efbbc ++0, 6001, 28800, 0xc6c7e26a ++0, 12002, 28800, 0x6cd40913 ++0, 18003, 28800, 0xa7b40fe9 ++0, 24004, 28800, 0x5e77fcc6 ++0, 30005, 28800, 0x9b3ef3f0 ++0, 36006, 28800, 0xe7031845 ++0, 42007, 28800, 0x2c15458d ++0, 48008, 28800, 0xbc3d4abf ++0, 54009, 28800, 0xf8755ac7 ++0, 60010, 28800, 0x64d0405b ++0, 66011, 28800, 0x1e0c341d ++0, 72012, 28800, 0x05ca3c2b ++0, 78013, 28800, 0x28cb307f ++0, 84014, 28800, 0x3a9855af ++0, 90015, 28800, 0x92b63321 ++0, 96016, 28800, 0x85585151 ++0, 102017, 28800, 0x1ff01bf9 ++0, 108018, 28800, 0x4bab200f ++0, 114019, 28800, 0xcf732ad7 ++0, 120020, 28800, 0xced00cff ++0, 126021, 28800, 0xa69046fd ++0, 132022, 28800, 0x5aa341c3 ++0, 138023, 28800, 0x87ef6219 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/base64 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/base64 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/base64 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/base64 2012-05-14 14:08:55.623365925 +0200 +@@ -0,0 +1,9 @@ ++Encoding/decoding tests ++Passed! ++Passed! ++Passed! ++Passed! ++Passed! ++Passed! ++Passed! ++Passed! +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bethsoft-vid xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bethsoft-vid +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bethsoft-vid 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bethsoft-vid 2012-05-14 14:08:55.624365945 +0200 +@@ -1,90 +1,90 @@ +-1, 0, 1480, 0x00000000 + 0, 0, 192000, 0x00000000 +-0, 1500, 192000, 0x01a6cf45 +-0, 3000, 192000, 0xd07d57e9 +-0, 4500, 192000, 0x3cb1dff5 ++1, 0, 1480, 0x00000000 ++0, 1500, 192000, 0x5a5acf57 ++0, 3000, 192000, 0xbd055cf1 ++0, 4500, 192000, 0x28b1eefc + 1, 5994, 1480, 0x20a92bd4 +-0, 6000, 192000, 0xd1aaa8fb +-0, 7500, 192000, 0x75f526cd +-0, 9000, 192000, 0x0f673577 +-0, 10500, 192000, 0x897b6781 ++0, 6000, 192000, 0x0636bacd ++0, 7500, 192000, 0xbfd33cbd ++0, 9000, 192000, 0x0bd150ef ++0, 10500, 192000, 0x780d891e + 1, 11988, 1850, 0xa9e48a74 +-0, 12000, 192000, 0x81e6b7f7 +-0, 13500, 192000, 0x1f45ce61 +-0, 15000, 192000, 0x5a0772a6 +-0, 16500, 192000, 0xf78732b3 +-0, 18000, 192000, 0x8427f9e5 ++0, 12000, 192000, 0xacf5e205 ++0, 13500, 192000, 0x37c900dc ++0, 15000, 192000, 0x4ee6add7 ++0, 16500, 192000, 0x1844783a ++0, 18000, 192000, 0x7bf84848 + 1, 19481, 1480, 0x23ecd018 +-0, 19500, 192000, 0x40473f11 +-0, 21000, 192000, 0x173ceebe +-0, 22500, 192000, 0x136b9516 +-0, 24000, 192000, 0x138d11ae ++0, 19500, 192000, 0x1ec296bc ++0, 21000, 192000, 0xbaeb5292 ++0, 22500, 192000, 0xcb18038d ++0, 24000, 192000, 0xb3cc8b65 + 1, 25475, 1480, 0x206bb915 +-0, 25500, 192000, 0x063dbff3 +-0, 27000, 192000, 0x5280852f +-0, 28500, 192000, 0x99943a8f +-0, 30000, 192000, 0x0330a728 ++0, 25500, 192000, 0x6f164685 ++0, 27000, 192000, 0x304917c9 ++0, 28500, 192000, 0x8269daa1 ++0, 30000, 192000, 0x04d3500d + 1, 31469, 1850, 0xb0e10e75 +-0, 31500, 192000, 0x5d35467d +-0, 33000, 192000, 0xfd436343 +-0, 34500, 192000, 0xc323fcfe +-0, 36000, 192000, 0x2a1530a0 +-0, 37500, 192000, 0xbd43bb60 ++0, 31500, 192000, 0x9788f7a5 ++0, 33000, 192000, 0x05351c98 ++0, 34500, 192000, 0xcc8bba97 ++0, 36000, 192000, 0x76caf27b ++0, 37500, 192000, 0x28648040 + 1, 38961, 1480, 0x8d9baedd +-0, 39000, 192000, 0xa47f5eab +-0, 40500, 192000, 0xff17f5f7 +-0, 42000, 192000, 0xb4140b55 +-0, 43500, 192000, 0xb8782cc4 ++0, 39000, 192000, 0x99ea251f ++0, 40500, 192000, 0x20e7bf4d ++0, 42000, 192000, 0x046ed625 ++0, 43500, 192000, 0x1613fb12 + 1, 44955, 1480, 0xb802aae1 +-0, 45000, 192000, 0x92975b8b +-0, 46500, 192000, 0xf42a64d6 +-0, 48000, 192000, 0x2cc7077d +-0, 49500, 192000, 0x00080cc8 ++0, 45000, 192000, 0xd8b52d16 ++0, 46500, 192000, 0x31443aa9 ++0, 48000, 192000, 0xd426de3d ++0, 49500, 192000, 0xb2bce77b + 1, 50950, 1480, 0xecd7b5cc +-0, 51000, 192000, 0x584b48f3 +-0, 52500, 192000, 0xd68f57da +-0, 54000, 192000, 0x60158422 +-0, 55500, 192000, 0xd7fb89e6 ++0, 51000, 192000, 0x25a52805 ++0, 52500, 192000, 0x04f03a87 ++0, 54000, 192000, 0x41d56889 ++0, 55500, 192000, 0x3d4d6de9 + 1, 56944, 1850, 0x16861355 +-0, 57000, 192000, 0x97f1c76a +-0, 58500, 192000, 0x46c4bb9e +-0, 60000, 192000, 0xd32f9b66 +-0, 61500, 192000, 0x74f43886 +-0, 63000, 192000, 0x3c4e47df ++0, 57000, 192000, 0xa7a2abfe ++0, 58500, 192000, 0x663e9fca ++0, 60000, 192000, 0x29a67f86 ++0, 61500, 192000, 0x51531bb0 ++0, 63000, 192000, 0xd993277e + 1, 64436, 1480, 0xa51690bd +-0, 64500, 192000, 0xb5ac0a58 +-0, 66000, 192000, 0xcc572b31 +-0, 67500, 192000, 0xb1739d26 +-0, 69000, 192000, 0x73da5473 ++0, 64500, 192000, 0x4873e583 ++0, 66000, 192000, 0x06df053b ++0, 67500, 192000, 0x044f7698 ++0, 69000, 192000, 0xc2302a45 + 1, 70430, 1480, 0xdd0b90d1 +-0, 70500, 192000, 0x5f79f5bc +-0, 72000, 192000, 0x0affc0a0 +-0, 73500, 192000, 0x2b4d5c1c +-0, 75000, 192000, 0x309b41bc ++0, 70500, 192000, 0xbdfec8ee ++0, 72000, 192000, 0x3b739286 ++0, 73500, 192000, 0x3ca82cd6 ++0, 75000, 192000, 0x25af10f2 + 1, 76424, 1850, 0x3ce6e333 +-0, 76500, 192000, 0xd42b6424 +-0, 78000, 192000, 0x4795c948 +-0, 79500, 192000, 0xbc1a3a8b +-0, 81000, 192000, 0x16529c5b +-0, 82500, 192000, 0x6b1b31ba ++0, 76500, 192000, 0x09ce32bf ++0, 78000, 192000, 0xdab399c2 ++0, 79500, 192000, 0x77400d93 ++0, 81000, 192000, 0x5e8e6fe7 ++0, 82500, 192000, 0x277506c9 + 1, 83917, 1480, 0xf8ce8ea3 +-0, 84000, 192000, 0x569182ce +-0, 85500, 192000, 0xe6ea9866 +-0, 87000, 192000, 0x102c6076 +-0, 88500, 192000, 0xb29f527a ++0, 84000, 192000, 0xe91b59ac ++0, 85500, 192000, 0xc2aa6e19 ++0, 87000, 192000, 0x12c63645 ++0, 88500, 192000, 0xa39f27d6 + 1, 89911, 1480, 0xda4597af +-0, 90000, 192000, 0x040b4eee +-0, 91500, 192000, 0x92574f4a +-0, 93000, 192000, 0x1e8acdce +-0, 94500, 192000, 0x1becf516 ++0, 90000, 192000, 0x20c32512 ++0, 91500, 192000, 0x385a26a0 ++0, 93000, 192000, 0x2566a70c ++0, 94500, 192000, 0x7105cfb9 + 1, 95905, 1480, 0x918f7cb3 +-0, 96000, 192000, 0xb62e9776 +-0, 97500, 192000, 0xed37a08e +-0, 99000, 192000, 0xc0719912 +-0, 100500, 192000, 0x24cf7a7e ++0, 96000, 192000, 0x725671a2 ++0, 97500, 192000, 0x3ff2782a ++0, 99000, 192000, 0xdc0571c3 ++0, 100500, 192000, 0x4a6a5405 + 1, 101899, 1850, 0xca6edb15 +-0, 102000, 192000, 0x0307f62f +-0, 103500, 192000, 0x79b7417b ++0, 102000, 192000, 0x3ec3cce1 ++0, 103500, 192000, 0x159313a8 + 1, 109392, 1480, 0xba279597 + 1, 115386, 1480, 0xc5a38a9e + 1, 121380, 1850, 0x8147eef5 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bfi xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bfi +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bfi 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bfi 2012-05-14 14:08:55.625365965 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 17768, 0x07df135c + 0, 0, 134400, 0xc218b00c ++1, 0, 17768, 0x07df135c + 0, 10000, 134400, 0x114daf7c + 0, 20000, 134400, 0xe14db24c + 0, 30000, 134400, 0x88c71df7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bink-demux-video xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bink-demux-video +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bink-demux-video 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bink-demux-video 1970-01-01 01:00:00.000000000 +0100 +@@ -1,20 +0,0 @@ +-0, 0, 460800, 0xb06f7841 +-0, 6000, 460800, 0x7ed06412 +-0, 12000, 460800, 0xe82b5c3d +-0, 18000, 460800, 0x67284940 +-0, 24000, 460800, 0x17e2c544 +-0, 30000, 460800, 0x5dc65d36 +-0, 36000, 460800, 0x7de63f90 +-0, 42000, 460800, 0x15c8cf7d +-0, 48000, 460800, 0xbffe4047 +-0, 54000, 460800, 0xcabcc150 +-0, 60000, 460800, 0xe8a17ebe +-0, 66000, 460800, 0x27e94c03 +-0, 72000, 460800, 0x71c0f48e +-0, 78000, 460800, 0x5fc8f783 +-0, 84000, 460800, 0xd23d336a +-0, 90000, 460800, 0xa7aca9e0 +-0, 96000, 460800, 0x1dff2144 +-0, 102000, 460800, 0x82cf8b2b +-0, 108000, 460800, 0x4cbe3544 +-0, 114000, 460800, 0x7e724731 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bink-video xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bink-video +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bink-video 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bink-video 2012-05-14 14:08:55.626365985 +0200 +@@ -0,0 +1,20 @@ ++0, 0, 460800, 0xb06f7841 ++0, 6000, 460800, 0x7ed06412 ++0, 12000, 460800, 0xe82b5c3d ++0, 18000, 460800, 0x67284940 ++0, 24000, 460800, 0x17e2c544 ++0, 30000, 460800, 0x5dc65d36 ++0, 36000, 460800, 0x7de63f90 ++0, 42000, 460800, 0x15c8cf7d ++0, 48000, 460800, 0xbffe4047 ++0, 54000, 460800, 0xcabcc150 ++0, 60000, 460800, 0xe8a17ebe ++0, 66000, 460800, 0x27e94c03 ++0, 72000, 460800, 0x71c0f48e ++0, 78000, 460800, 0x5fc8f783 ++0, 84000, 460800, 0xd23d336a ++0, 90000, 460800, 0xadcfa9e0 ++0, 96000, 460800, 0x24222144 ++0, 102000, 460800, 0x88f28b2b ++0, 108000, 460800, 0x52e13544 ++0, 114000, 460800, 0x7e724731 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bmv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bmv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/bmv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/bmv 2012-05-14 14:08:55.626365985 +0200 +@@ -0,0 +1,42 @@ ++0, 0, 823680, 0xddb8a306 ++1, 0, 7424, 0x18540b36 ++0, 7500, 823680, 0xa95375c8 ++1, 7576, 7296, 0x5acd2484 ++0, 15000, 823680, 0xa95375c8 ++1, 15020, 7424, 0xa1bc5c5a ++0, 22500, 823680, 0xb6f78afe ++1, 22596, 7296, 0x71a02ad1 ++0, 30000, 823680, 0xb6f78afe ++1, 30041, 7424, 0x09cc32f2 ++0, 37500, 823680, 0x45b9c8f0 ++1, 37616, 7296, 0xa3451726 ++0, 45000, 823680, 0x45b9c8f0 ++1, 45061, 7296, 0x1eb40a18 ++0, 52500, 823680, 0x7653d8e9 ++1, 52506, 7424, 0xc55a2acf ++0, 60000, 823680, 0x7653d8e9 ++1, 60082, 7296, 0x5b9fad3f ++0, 67500, 823680, 0xf1e2fd73 ++1, 67527, 7424, 0xea651ae7 ++0, 75000, 823680, 0xf1e2fd73 ++1, 75102, 7296, 0x2bd5ddb6 ++0, 82500, 823680, 0x6d2deab3 ++1, 82547, 7424, 0xde4243b4 ++0, 90000, 823680, 0x6d2deab3 ++1, 90122, 7296, 0x358806d3 ++0, 97500, 823680, 0x37fd33ce ++1, 97567, 7296, 0x511a144e ++0, 105000, 823680, 0x37fd33ce ++1, 105012, 7424, 0x887a3e84 ++0, 112500, 823680, 0x0a8e0ab9 ++1, 112588, 7296, 0xfeae2a0c ++0, 120000, 823680, 0x0a8e0ab9 ++1, 120033, 7424, 0xa4ea5d22 ++0, 127500, 823680, 0x991bb2b0 ++1, 127608, 7296, 0xb3adf7fa ++0, 135000, 823680, 0x991bb2b0 ++1, 135053, 7424, 0xce995dcc ++0, 142500, 823680, 0xb8397c8c ++1, 142629, 7296, 0x5b4cf574 ++0, 150000, 823680, 0xb8397c8c ++1, 150073, 7296, 0x8a70eaf0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cdgraphics xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cdgraphics +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cdgraphics 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cdgraphics 2012-05-14 14:08:55.628366025 +0200 +@@ -37,263 +37,264 @@ + 0, 10800, 194400, 0x7b8cf983 + 0, 11100, 194400, 0x07a20f7c + 0, 11400, 194400, 0xa63e2962 +-0, 11700, 194400, 0xa63e2962 +-0, 12000, 194400, 0x2dd54447 +-0, 12300, 194400, 0x90735e2d +-0, 12600, 194400, 0x90735e2d +-0, 12900, 194400, 0x90d98506 +-0, 13200, 194400, 0xe5b08ffb +-0, 13500, 194400, 0xe5b08ffb +-0, 13800, 194400, 0x7a0d95f5 +-0, 14100, 194400, 0xff6bacde +-0, 14400, 194400, 0xff6bacde +-0, 14700, 194400, 0xd998c2c8 +-0, 15000, 194400, 0x3d1ddfab +-0, 15300, 194400, 0x3d1ddfab +-0, 15600, 194400, 0x817de4a6 +-0, 15900, 194400, 0xfa3ef694 +-0, 16200, 194400, 0xfa3ef694 +-0, 16500, 194400, 0x0b5bfb8f +-0, 16800, 194400, 0x00f62376 +-0, 17100, 194400, 0x00f62376 +-0, 17400, 194400, 0x2f6b2d6c +-0, 17700, 194400, 0x40cb4752 +-0, 18000, 194400, 0x40cb4752 +-0, 18300, 194400, 0xd8456435 +-0, 18600, 194400, 0x459f6a2f +-0, 18900, 194400, 0x459f6a2f +-0, 19200, 194400, 0x9b678910 +-0, 19500, 194400, 0x8791a1f7 +-0, 19800, 194400, 0x8791a1f7 +-0, 20100, 194400, 0xdb4ac5d3 +-0, 20400, 194400, 0xb223c8d0 +-0, 20700, 194400, 0xb223c8d0 +-0, 21000, 194400, 0x4a9ce7b1 +-0, 21300, 194400, 0x187eeaae +-0, 21600, 194400, 0x187eeaae +-0, 21900, 194400, 0xc712f8a0 +-0, 22200, 194400, 0x549c00a7 +-0, 22500, 194400, 0x549c00a7 +-0, 22800, 194400, 0x4d991295 +-0, 23100, 194400, 0xc41b2681 +-0, 23400, 194400, 0xc41b2681 +-0, 23700, 194400, 0xed5a3077 +-0, 24000, 194400, 0x85ad4463 +-0, 24300, 194400, 0x85ad4463 +-0, 24600, 194400, 0xb98f4760 +-0, 24900, 194400, 0x87ef5e49 +-0, 25200, 194400, 0x87ef5e49 +-0, 25500, 194400, 0x830a6146 +-0, 25800, 194400, 0xe33a792e +-0, 26100, 194400, 0xe33a792e +-0, 26400, 194400, 0x83517a2d +-0, 26700, 194400, 0xa97e9314 +-0, 27000, 194400, 0xa97e9314 +-0, 27300, 194400, 0x39059611 +-0, 27600, 194400, 0xbf4eb9ed +-0, 27900, 194400, 0xbf4eb9ed +-0, 28200, 194400, 0xe5afc4e2 +-0, 28500, 194400, 0x35d4cdd9 +-0, 28800, 194400, 0x35d4cdd9 +-0, 29100, 194400, 0xb376e1c5 +-0, 29400, 194400, 0x6128e3c3 +-0, 29700, 194400, 0x6128e3c3 +-0, 30000, 194400, 0x30b7f7af +-0, 30300, 194400, 0xf1effaac +-0, 30600, 194400, 0xf1effaac +-0, 30900, 194400, 0x483914a1 +-0, 31200, 194400, 0xbd48199c +-0, 31500, 194400, 0xbd48199c +-0, 31800, 194400, 0x382f2d88 +-0, 32100, 194400, 0x5a573085 +-0, 32400, 194400, 0x5a573085 +-0, 32700, 194400, 0x89733580 +-0, 33000, 194400, 0xd1325a5b +-0, 33300, 194400, 0xd1325a5b +-0, 33600, 194400, 0x655b6253 +-0, 33900, 194400, 0x55146352 +-0, 34200, 194400, 0x55146352 +-0, 34500, 194400, 0xda527c39 +-0, 34800, 194400, 0xb0cd7e37 +-0, 35100, 194400, 0xb0cd7e37 +-0, 35400, 194400, 0x25e7991c +-0, 35700, 194400, 0x5c22a411 +-0, 36000, 194400, 0x5c22a411 +-0, 36300, 194400, 0x1e2abdf7 +-0, 36600, 194400, 0x8308bff5 +-0, 36900, 194400, 0x8308bff5 +-0, 37200, 194400, 0xfdbfd6de +-0, 37500, 194400, 0xd4d4d9db +-0, 37800, 194400, 0xd4d4d9db +-0, 38100, 194400, 0xa449fbb9 +-0, 38400, 194400, 0x3dcafdb7 +-0, 38700, 194400, 0x3dcafdb7 +-0, 39000, 194400, 0x6f1f01c2 +-0, 39300, 194400, 0xf54a1da6 +-0, 39600, 194400, 0xf54a1da6 +-0, 39900, 194400, 0x88d11fa4 +-0, 40200, 194400, 0x59642d96 +-0, 40500, 194400, 0x59642d96 +-0, 40800, 194400, 0x8ba44182 +-0, 41100, 194400, 0x88f56360 +-0, 41400, 194400, 0x88f56360 +-0, 41700, 194400, 0xfb246d56 +-0, 42000, 194400, 0xad128043 +-0, 42300, 194400, 0xad128043 +-0, 42600, 194400, 0x3a4f8a39 +-0, 42900, 194400, 0x563d9d26 +-0, 43200, 194400, 0x563d9d26 +-0, 43500, 194400, 0x6ff8a320 +-0, 43800, 194400, 0xcdb9b70c +-0, 44100, 194400, 0xcdb9b70c +-0, 44400, 194400, 0x99c2bd06 +-0, 44700, 194400, 0x4b47cef4 +-0, 45000, 194400, 0x4b47cef4 +-0, 45300, 194400, 0x10b9dce6 +-0, 45600, 194400, 0xdd39f1d1 +-0, 45900, 194400, 0xdd39f1d1 +-0, 46200, 194400, 0xbcf104cd +-0, 46500, 194400, 0x85ec17ba +-0, 46800, 194400, 0x85ec17ba +-0, 47100, 194400, 0x069219b8 +-0, 47400, 194400, 0x84dd3899 +-0, 47700, 194400, 0x84dd3899 +-0, 48000, 194400, 0xacca4190 +-0, 48300, 194400, 0xcf5b5d74 +-0, 48600, 194400, 0xcf5b5d74 +-0, 48900, 194400, 0x4b8c626f +-0, 49200, 194400, 0xf0817958 +-0, 49500, 194400, 0xf0817958 +-0, 49800, 194400, 0xc0887e53 +-0, 50100, 194400, 0x42e6854c +-0, 50400, 194400, 0x42e6854c +-0, 50700, 194400, 0x036c9140 +-0, 51000, 194400, 0x0f21a62b +-0, 51300, 194400, 0x0f21a62b +-0, 51600, 194400, 0xcdaeaa27 +-0, 51900, 194400, 0xe425bc15 +-0, 52200, 194400, 0xe425bc15 +-0, 52500, 194400, 0x8e18c20f +-0, 52800, 194400, 0x767cd5fb +-0, 53100, 194400, 0x767cd5fb +-0, 53400, 194400, 0x554ae6ea +-0, 53700, 194400, 0xeac1f9d7 +-0, 54000, 194400, 0xeac1f9d7 +-0, 54300, 194400, 0x0b32fed2 +-0, 54600, 194400, 0xe30c19c6 +-0, 54900, 194400, 0xe30c19c6 +-0, 55200, 194400, 0x6a8a23bc +-0, 55500, 194400, 0x26bf36a9 +-0, 55800, 194400, 0x26bf36a9 +-0, 56100, 194400, 0x1e4f3fa0 +-0, 56400, 194400, 0x231f5986 +-0, 56700, 194400, 0x231f5986 +-0, 57000, 194400, 0xf557756a +-0, 57300, 194400, 0x6bce805f +-0, 57600, 194400, 0x6bce805f +-0, 57900, 194400, 0xcd80924d +-0, 58200, 194400, 0x65dc9f40 +-0, 58500, 194400, 0x65dc9f40 +-0, 58800, 194400, 0x2ab7af30 +-0, 59100, 194400, 0xd43cb728 +-0, 59400, 194400, 0xd43cb728 +-0, 59700, 194400, 0x05d9c916 +-0, 60000, 194400, 0x43cad10e +-0, 60300, 194400, 0x43cad10e +-0, 60600, 194400, 0x06b5e0fe +-0, 60900, 194400, 0xa142f0ee +-0, 61200, 194400, 0xa142f0ee +-0, 61500, 194400, 0xed7f03ea +-0, 61800, 194400, 0xf26019d4 +-0, 62100, 194400, 0xf26019d4 +-0, 62400, 194400, 0x3b7f29c4 +-0, 62700, 194400, 0x30282ebf +-0, 63000, 194400, 0x30282ebf +-0, 63300, 194400, 0xaeff4aa3 +-0, 63600, 194400, 0x1d355697 +-0, 63900, 194400, 0x1d355697 +-0, 64200, 194400, 0x2ead6f7e +-0, 64500, 194400, 0xf1b67776 +-0, 64800, 194400, 0xf1b67776 +-0, 65100, 194400, 0x93b38b62 +-0, 65400, 194400, 0x9469905d +-0, 65700, 194400, 0x9469905d +-0, 66000, 194400, 0x27bf9756 +-0, 66300, 194400, 0xd016a548 +-0, 66600, 194400, 0xd016a548 +-0, 66900, 194400, 0x6889b835 +-0, 67200, 194400, 0x6a05be2f +-0, 67500, 194400, 0x6a05be2f +-0, 67800, 194400, 0xe0a1ce1f +-0, 68100, 194400, 0x8fdbd617 +-0, 68400, 194400, 0x8fdbd617 +-0, 68700, 194400, 0xd68fe805 +-0, 69000, 194400, 0x0d1dfbf1 +-0, 69300, 194400, 0x0d1dfbf1 +-0, 69600, 194400, 0x0fe70bf0 +-0, 69900, 194400, 0x0a8f13e8 +-0, 70200, 194400, 0x0a8f13e8 +-0, 70500, 194400, 0x0ca42bd0 +-0, 70800, 194400, 0x6f3838c3 +-0, 71100, 194400, 0x6f3838c3 +-0, 71400, 194400, 0x045448b3 +-0, 71700, 194400, 0x764349b2 +-0, 72000, 194400, 0x764349b2 +-0, 72300, 194400, 0xed1651aa +-0, 72600, 194400, 0xbb376398 +-0, 72900, 194400, 0xbb376398 +-0, 73200, 194400, 0xd0d5718a +-0, 73500, 194400, 0xcd977e7d +-0, 73800, 194400, 0xcd977e7d +-0, 74100, 194400, 0x8cb39665 +-0, 74400, 194400, 0xb935b04b +-0, 74700, 194400, 0xb935b04b +-0, 75000, 194400, 0x0292be3d +-0, 75300, 194400, 0x4f21c833 +-0, 75600, 194400, 0x4f21c833 +-0, 75900, 194400, 0xa5c7d823 +-0, 76200, 194400, 0xfb8ee01b +-0, 76500, 194400, 0xfb8ee01b +-0, 76800, 194400, 0xea53ee0d +-0, 77100, 194400, 0x803efcfe +-0, 77400, 194400, 0x803efcfe +-0, 77700, 194400, 0x2c0e0aff +-0, 78000, 194400, 0x3df318f1 +-0, 78300, 194400, 0x3df318f1 +-0, 78600, 194400, 0xc4cb26e3 +-0, 78900, 194400, 0x92a033d6 +-0, 79200, 194400, 0x92a033d6 +-0, 79500, 194400, 0x1b2048c1 +-0, 79800, 194400, 0x236858b1 +-0, 80100, 194400, 0x236858b1 +-0, 80400, 194400, 0x482f6d9c +-0, 80700, 194400, 0x9ee97891 +-0, 81000, 194400, 0x9ee97891 +-0, 81300, 194400, 0xe0dc8683 +-0, 81600, 194400, 0x461b9079 +-0, 81900, 194400, 0x461b9079 +-0, 82200, 194400, 0xd346a960 +-0, 82500, 194400, 0xa384b554 +-0, 82800, 194400, 0xa384b554 +-0, 83100, 194400, 0x3246cf3a +-0, 83400, 194400, 0xa53fe722 +-0, 83700, 194400, 0xa53fe722 +-0, 84000, 194400, 0xe620fd0c +-0, 84300, 194400, 0xd6370414 +-0, 84600, 194400, 0xd6370414 +-0, 84900, 194400, 0xf57f1404 +-0, 85200, 194400, 0x8c6420f7 +-0, 85500, 194400, 0x8c6420f7 +-0, 85800, 194400, 0xd4be3add +-0, 86100, 194400, 0xa8dc4ec9 +-0, 86400, 194400, 0xa8dc4ec9 +-0, 86700, 194400, 0xda1563b4 +-0, 87000, 194400, 0xd51873a4 +-0, 87300, 194400, 0xd51873a4 +-0, 87600, 194400, 0x68588196 +-0, 87900, 194400, 0x40d18e89 +-0, 88200, 194400, 0x40d18e89 +-0, 88500, 194400, 0x1b75a275 +-0, 88800, 194400, 0xedd1a572 +-0, 89100, 194400, 0xedd1a572 +-0, 89400, 194400, 0x55daad6a ++0, 11700, 194400, 0x2dd54447 ++0, 12000, 194400, 0x90735e2d ++0, 12300, 194400, 0x90d98506 ++0, 12600, 194400, 0xe5b08ffb ++0, 12900, 194400, 0x7a0d95f5 ++0, 13200, 194400, 0xff6bacde ++0, 13500, 194400, 0xd998c2c8 ++0, 13800, 194400, 0x3d1ddfab ++0, 14100, 194400, 0x817de4a6 ++0, 14400, 194400, 0xfa3ef694 ++0, 14700, 194400, 0x0b5bfb8f ++0, 15000, 194400, 0x00f62376 ++0, 15300, 194400, 0x2f6b2d6c ++0, 15600, 194400, 0x40cb4752 ++0, 15900, 194400, 0xd8456435 ++0, 16200, 194400, 0x459f6a2f ++0, 16500, 194400, 0x9b678910 ++0, 16800, 194400, 0x8791a1f7 ++0, 17100, 194400, 0xdb4ac5d3 ++0, 17400, 194400, 0xb223c8d0 ++0, 17700, 194400, 0x4a9ce7b1 ++0, 18000, 194400, 0x187eeaae ++0, 18300, 194400, 0xc712f8a0 ++0, 18600, 194400, 0x549c00a7 ++0, 18900, 194400, 0x4d991295 ++0, 19200, 194400, 0xc41b2681 ++0, 19500, 194400, 0xed5a3077 ++0, 19800, 194400, 0x85ad4463 ++0, 20100, 194400, 0xb98f4760 ++0, 20400, 194400, 0x87ef5e49 ++0, 20700, 194400, 0x830a6146 ++0, 21000, 194400, 0xe33a792e ++0, 21300, 194400, 0x83517a2d ++0, 21600, 194400, 0xa97e9314 ++0, 21900, 194400, 0x39059611 ++0, 22200, 194400, 0xbf4eb9ed ++0, 22500, 194400, 0xe5afc4e2 ++0, 22800, 194400, 0x35d4cdd9 ++0, 23100, 194400, 0xb376e1c5 ++0, 23400, 194400, 0x6128e3c3 ++0, 23700, 194400, 0x30b7f7af ++0, 24000, 194400, 0xf1effaac ++0, 24300, 194400, 0x483914a1 ++0, 24600, 194400, 0xbd48199c ++0, 24900, 194400, 0x382f2d88 ++0, 25200, 194400, 0x5a573085 ++0, 25500, 194400, 0x89733580 ++0, 25800, 194400, 0xd1325a5b ++0, 26100, 194400, 0x655b6253 ++0, 26400, 194400, 0x55146352 ++0, 26700, 194400, 0xda527c39 ++0, 27000, 194400, 0xb0cd7e37 ++0, 27300, 194400, 0x25e7991c ++0, 27600, 194400, 0x5c22a411 ++0, 27900, 194400, 0x1e2abdf7 ++0, 28200, 194400, 0x8308bff5 ++0, 28500, 194400, 0xfdbfd6de ++0, 28800, 194400, 0xd4d4d9db ++0, 29100, 194400, 0xa449fbb9 ++0, 29400, 194400, 0x3dcafdb7 ++0, 29700, 194400, 0x6f1f01c2 ++0, 30000, 194400, 0xf54a1da6 ++0, 30300, 194400, 0x88d11fa4 ++0, 30600, 194400, 0x59642d96 ++0, 30900, 194400, 0x8ba44182 ++0, 31200, 194400, 0x88f56360 ++0, 31500, 194400, 0xfb246d56 ++0, 31800, 194400, 0xad128043 ++0, 32100, 194400, 0x3a4f8a39 ++0, 32400, 194400, 0x563d9d26 ++0, 32700, 194400, 0x6ff8a320 ++0, 33000, 194400, 0xcdb9b70c ++0, 33300, 194400, 0x99c2bd06 ++0, 33600, 194400, 0x4b47cef4 ++0, 33900, 194400, 0x10b9dce6 ++0, 34200, 194400, 0xdd39f1d1 ++0, 34500, 194400, 0xbcf104cd ++0, 34800, 194400, 0x85ec17ba ++0, 35100, 194400, 0x069219b8 ++0, 35400, 194400, 0x84dd3899 ++0, 35700, 194400, 0xacca4190 ++0, 36000, 194400, 0xcf5b5d74 ++0, 36300, 194400, 0x4b8c626f ++0, 36600, 194400, 0xf0817958 ++0, 36900, 194400, 0xc0887e53 ++0, 37200, 194400, 0x42e6854c ++0, 37500, 194400, 0x036c9140 ++0, 37800, 194400, 0x0f21a62b ++0, 38100, 194400, 0xcdaeaa27 ++0, 38400, 194400, 0xe425bc15 ++0, 38700, 194400, 0x8e18c20f ++0, 39000, 194400, 0x767cd5fb ++0, 39300, 194400, 0x554ae6ea ++0, 39600, 194400, 0xeac1f9d7 ++0, 39900, 194400, 0x0b32fed2 ++0, 40200, 194400, 0xe30c19c6 ++0, 40500, 194400, 0x6a8a23bc ++0, 40800, 194400, 0x26bf36a9 ++0, 41100, 194400, 0x1e4f3fa0 ++0, 41400, 194400, 0x231f5986 ++0, 41700, 194400, 0xf557756a ++0, 42000, 194400, 0x6bce805f ++0, 42300, 194400, 0xcd80924d ++0, 42600, 194400, 0x65dc9f40 ++0, 42900, 194400, 0x2ab7af30 ++0, 43200, 194400, 0xd43cb728 ++0, 43500, 194400, 0x05d9c916 ++0, 43800, 194400, 0x43cad10e ++0, 44100, 194400, 0x06b5e0fe ++0, 44400, 194400, 0xa142f0ee ++0, 44700, 194400, 0xed7f03ea ++0, 45000, 194400, 0xf26019d4 ++0, 45300, 194400, 0x3b7f29c4 ++0, 45600, 194400, 0x30282ebf ++0, 45900, 194400, 0xaeff4aa3 ++0, 46200, 194400, 0x1d355697 ++0, 46500, 194400, 0x2ead6f7e ++0, 46800, 194400, 0xf1b67776 ++0, 47100, 194400, 0x93b38b62 ++0, 47400, 194400, 0x9469905d ++0, 47700, 194400, 0x27bf9756 ++0, 48000, 194400, 0xd016a548 ++0, 48300, 194400, 0x6889b835 ++0, 48600, 194400, 0x6a05be2f ++0, 48900, 194400, 0xe0a1ce1f ++0, 49200, 194400, 0x8fdbd617 ++0, 49500, 194400, 0xd68fe805 ++0, 49800, 194400, 0x0d1dfbf1 ++0, 50100, 194400, 0x0fe70bf0 ++0, 50400, 194400, 0x0a8f13e8 ++0, 50700, 194400, 0x0ca42bd0 ++0, 51000, 194400, 0x6f3838c3 ++0, 51300, 194400, 0x045448b3 ++0, 51600, 194400, 0x764349b2 ++0, 51900, 194400, 0xed1651aa ++0, 52200, 194400, 0xbb376398 ++0, 52500, 194400, 0xd0d5718a ++0, 52800, 194400, 0xcd977e7d ++0, 53100, 194400, 0x8cb39665 ++0, 53400, 194400, 0xb935b04b ++0, 53700, 194400, 0x0292be3d ++0, 54000, 194400, 0x4f21c833 ++0, 54300, 194400, 0xa5c7d823 ++0, 54600, 194400, 0xfb8ee01b ++0, 54900, 194400, 0xea53ee0d ++0, 55200, 194400, 0x803efcfe ++0, 55500, 194400, 0x2c0e0aff ++0, 55800, 194400, 0x3df318f1 ++0, 56100, 194400, 0xc4cb26e3 ++0, 56400, 194400, 0x92a033d6 ++0, 56700, 194400, 0x1b2048c1 ++0, 57000, 194400, 0x236858b1 ++0, 57300, 194400, 0x482f6d9c ++0, 57600, 194400, 0x9ee97891 ++0, 57900, 194400, 0xe0dc8683 ++0, 58200, 194400, 0x461b9079 ++0, 58500, 194400, 0xd346a960 ++0, 58800, 194400, 0xa384b554 ++0, 59100, 194400, 0x3246cf3a ++0, 59400, 194400, 0xa53fe722 ++0, 59700, 194400, 0xe620fd0c ++0, 60000, 194400, 0xd6370414 ++0, 60300, 194400, 0xf57f1404 ++0, 60600, 194400, 0x8c6420f7 ++0, 60900, 194400, 0xd4be3add ++0, 61200, 194400, 0xa8dc4ec9 ++0, 61500, 194400, 0xda1563b4 ++0, 61800, 194400, 0xd51873a4 ++0, 62100, 194400, 0x68588196 ++0, 62400, 194400, 0x40d18e89 ++0, 62700, 194400, 0x1b75a275 ++0, 63000, 194400, 0xedd1a572 ++0, 63300, 194400, 0x55daad6a ++0, 63600, 194400, 0xcb93b067 ++0, 63900, 194400, 0x5888ba5d ++0, 64200, 194400, 0x2c11c84f ++0, 64500, 194400, 0x0fbae334 ++0, 64800, 194400, 0x773fed2a ++0, 65100, 194400, 0x2f87fc1b ++0, 65400, 194400, 0xe8120521 ++0, 65700, 194400, 0x64ac0f17 ++0, 66000, 194400, 0xba531c0a ++0, 66300, 194400, 0xf49433f2 ++0, 66600, 194400, 0x79e234f1 ++0, 66900, 194400, 0x043937ee ++0, 67200, 194400, 0x9e6141e4 ++0, 67500, 194400, 0x34204fd6 ++0, 67800, 194400, 0xa1dd60c5 ++0, 68100, 194400, 0x12b36eb7 ++0, 68400, 194400, 0x68987aab ++0, 68700, 194400, 0x3207889d ++0, 69000, 194400, 0x3bb59194 ++0, 69300, 194400, 0x0a119f86 ++0, 69600, 194400, 0x472bab7a ++0, 69900, 194400, 0x7364c85d ++0, 70200, 194400, 0xa812d84d ++0, 70500, 194400, 0xf384f530 ++0, 70800, 194400, 0x1546052f ++0, 71100, 194400, 0xeb611a1a ++0, 71400, 194400, 0xc39d250f ++0, 71700, 194400, 0x7bd73301 ++0, 72000, 194400, 0x10f73cf7 ++0, 72300, 194400, 0x95dc55de ++0, 72600, 194400, 0x392e61d2 ++0, 72900, 194400, 0x113c7bb8 ++0, 73200, 194400, 0x17128fa4 ++0, 73500, 194400, 0xf95e9b98 ++0, 73800, 194400, 0xdc47aa89 ++0, 74100, 194400, 0xea5dc073 ++0, 74400, 194400, 0x8dfadc57 ++0, 74700, 194400, 0xe5c3e84b ++0, 75000, 194400, 0x8952f43f ++0, 75300, 194400, 0xec9e0240 ++0, 75600, 194400, 0x8f460c36 ++0, 75900, 194400, 0xd43e182a ++0, 76200, 194400, 0xb00b2919 ++0, 76500, 194400, 0xc9f6350d ++0, 76800, 194400, 0x87ca44fd ++0, 77100, 194400, 0xa6a250f1 ++0, 77400, 194400, 0x34fa60e1 ++0, 77700, 194400, 0xe1a372cf ++0, 78000, 194400, 0xc80785bc ++0, 78300, 194400, 0x43e297aa ++0, 78600, 194400, 0x7e8ea49d ++0, 78900, 194400, 0xd009b091 ++0, 79200, 194400, 0x9126bc85 ++0, 79500, 194400, 0x175ad36e ++0, 79800, 194400, 0xf9dae160 ++0, 80100, 194400, 0x1b98f948 ++0, 80400, 194400, 0xa6c5133d ++0, 80700, 194400, 0xf5d42729 ++0, 81000, 194400, 0x8cfe311f ++0, 81300, 194400, 0x18733e12 ++0, 81600, 194400, 0x24ac50ff ++0, 81900, 194400, 0x0d1c64eb ++0, 82200, 194400, 0xde947cd3 ++0, 82500, 194400, 0x08268dc2 ++0, 82800, 194400, 0xfec69fb0 ++0, 83100, 194400, 0xba83aba4 ++0, 83400, 194400, 0xfbe2bc93 ++0, 83700, 194400, 0xe22fcc83 ++0, 84000, 194400, 0x050fcf80 ++0, 84300, 194400, 0xee1ed778 ++0, 84600, 194400, 0xb44cda75 ++0, 84900, 194400, 0xa29fe46b ++0, 85200, 194400, 0xa99bf55a ++0, 85500, 194400, 0x4f840d51 ++0, 85800, 194400, 0x58941945 ++0, 86100, 194400, 0x62cb2638 ++0, 86400, 194400, 0x22ee312d ++0, 86700, 194400, 0xea8f3925 ++0, 87000, 194400, 0xed294c12 ++0, 87300, 194400, 0xafa75e00 ++0, 87600, 194400, 0x19d45ffe ++0, 87900, 194400, 0x7fcf61fc ++0, 88200, 194400, 0x2c126df0 ++0, 88500, 194400, 0x331379e4 ++0, 88800, 194400, 0x99fe8cd1 ++0, 89100, 194400, 0xa5ec98c5 ++0, 89400, 194400, 0xac68a6b7 ++0, 89700, 194400, 0x28e6b2ab +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cljr xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cljr +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cljr 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cljr 2012-05-14 14:08:55.628366025 +0200 +@@ -1,36 +1,36 @@ +-0, 0, 64800, 0x44a1c47c +-0, 3169, 64800, 0x649cc3a4 +-0, 6338, 64800, 0xcab1b88c +-0, 9507, 64800, 0xf56cb788 +-0, 12676, 64800, 0x5336b618 +-0, 15845, 64800, 0x2704b438 +-0, 19013, 64800, 0x04c7b8e4 +-0, 22182, 64800, 0x3185b288 +-0, 25351, 64800, 0xa537c410 +-0, 28520, 64800, 0x6495c0f8 +-0, 31689, 64800, 0x06a1ca14 +-0, 34858, 64800, 0x69cdd2a0 +-0, 38027, 64800, 0x4ad2d828 +-0, 41196, 64800, 0x9604dea4 +-0, 44365, 64800, 0x1c00e430 +-0, 47534, 64800, 0x9afeefe0 +-0, 50702, 64800, 0xc13fdd78 +-0, 53871, 64800, 0x8438da7c +-0, 57040, 64800, 0xa0ead278 +-0, 60209, 64800, 0xbeced2d8 +-0, 63378, 64800, 0x85bbd7dc +-0, 66547, 64800, 0xbe59ce34 +-0, 69716, 64800, 0xd76ecccc +-0, 72885, 64800, 0xe182b474 +-0, 76054, 64800, 0x916cc394 +-0, 79223, 64800, 0x7efebd14 +-0, 82391, 64800, 0x8d28c9f0 +-0, 85560, 64800, 0x00a1c960 +-0, 88729, 64800, 0xc164c400 +-0, 91898, 64800, 0xfd4dc544 +-0, 95067, 64800, 0x01bfbe38 +-0, 98236, 64800, 0xff11b5d0 +-0, 101405, 64800, 0x4876bb20 +-0, 104574, 64800, 0x756ecb04 +-0, 107743, 64800, 0x3b8cd540 +-0, 110912, 64800, 0x063ed444 ++0, 0, 64800, 0x63132a60 ++0, 3169, 64800, 0xb3c729a3 ++0, 6338, 64800, 0xa27b1e0e ++0, 9507, 64800, 0xb9131d00 ++0, 12676, 64800, 0xaf9a1bae ++0, 15845, 64800, 0x11e319c5 ++0, 19013, 64800, 0xee6e1e6b ++0, 22182, 64800, 0x418417e9 ++0, 25351, 64800, 0x339d29f4 ++0, 28520, 64800, 0x198926c4 ++0, 31689, 64800, 0x439a3044 ++0, 34858, 64800, 0x0a4e38e1 ++0, 38027, 64800, 0x6e043e7e ++0, 41196, 64800, 0xde434533 ++0, 44365, 64800, 0xb58a4ad1 ++0, 47534, 64800, 0xaa105710 ++0, 50702, 64800, 0x1723440c ++0, 53871, 64800, 0x3b064116 ++0, 57040, 64800, 0x853f38e4 ++0, 60209, 64800, 0x52f53917 ++0, 63378, 64800, 0xea363e5a ++0, 66547, 64800, 0x4d0a344e ++0, 69716, 64800, 0xe49232fc ++0, 72885, 64800, 0x747b1a02 ++0, 76054, 64800, 0xbaa82992 ++0, 79223, 64800, 0x8e9322db ++0, 82391, 64800, 0x029a2fcf ++0, 85560, 64800, 0xb9a62f6a ++0, 88729, 64800, 0x553329fe ++0, 91898, 64800, 0x9a052b5b ++0, 95067, 64800, 0xe2ff2404 ++0, 98236, 64800, 0xaacd1b59 ++0, 101405, 64800, 0x17d820de ++0, 104574, 64800, 0x1c9e312c ++0, 107743, 64800, 0x84df3b99 ++0, 110912, 64800, 0xf7d13aa1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/corepng xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/corepng +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/corepng 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/corepng 2012-05-14 14:08:55.629366045 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 11026, 0x27ad637c + 0, 0, 230400, 0x03e25ead ++1, 0, 11026, 0x27ad637c + 0, 6000, 230400, 0x0a520ffd + 0, 12000, 230400, 0x0b11a671 + 0, 18000, 230400, 0x7d3fce32 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/crc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/crc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/crc 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/crc 2012-05-14 14:08:55.630366065 +0200 +@@ -0,0 +1,4 @@ ++crc EDB88320 =3D5CDD04 ++crc 04C11DB7 =E0BAF5C0 ++crc 00008005 =BB1F ++crc 00000007 =E3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-66004779a5e51ca659b21a4197e019e6 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2.6bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2.6bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2.6bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2.6bit 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-dee4417597abc2db70a175d6809870e7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-2bit 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-832846066fbce28821b7f0717c4d3a90 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-4bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-4bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-4bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creative-adpcm-8-4bit 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-1813d196cef83f7030bb150399b2903e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creatureshock-avs xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creatureshock-avs +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/creatureshock-avs 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/creatureshock-avs 2012-05-14 14:08:55.632366105 +0200 +@@ -1,92 +1,92 @@ ++0, 0, 188892, 0x9f47a5ec + 1, 0, 16372, 0xfaaab59d +-0, 0, 188892, 0xcb5be3dd +-0, 6000, 188892, 0x0f313ebc +-0, 12000, 188892, 0xc0da25cc +-0, 18000, 188892, 0xad6e1d44 +-0, 24000, 188892, 0xb1103b40 +-0, 30000, 188892, 0xae033450 ++0, 6000, 188892, 0xdece0269 ++0, 12000, 188892, 0xd097e86e ++0, 18000, 188892, 0x1cf2de83 ++0, 24000, 188892, 0xb664fd10 ++0, 30000, 188892, 0xc654f4c1 + 1, 33154, 4028, 0xc2daed72 +-0, 36000, 188892, 0xb31f03b4 ++0, 36000, 188892, 0x5adac3ff + 1, 41310, 5486, 0xf7fd794d +-0, 42000, 188892, 0xacb2d3f9 +-0, 48000, 188892, 0x7d77ecbd ++0, 42000, 188892, 0x5928954e ++0, 48000, 188892, 0x5e4cad6c + 1, 52420, 5790, 0xfd5a369f +-0, 54000, 188892, 0x7faa2f6c +-0, 60000, 188892, 0x28f4fdf1 ++0, 54000, 188892, 0xbbb5f11b ++0, 60000, 188892, 0xcb6bbdee + 1, 64145, 1068, 0x0b602cd0 +-0, 66000, 188892, 0x4b53f3b9 ++0, 66000, 188892, 0xa5b3b316 + 1, 66307, 4908, 0xfe870aad +-0, 72000, 188892, 0x1f09bb29 ++0, 72000, 188892, 0x9bf87b5d + 1, 76246, 6062, 0x8a4d6e0f +-0, 78000, 188892, 0x3afcc11d +-0, 84000, 188892, 0x6b918e49 ++0, 78000, 188892, 0xcc3981be ++0, 84000, 188892, 0x2eb44dfa + 1, 88522, 5402, 0x71fd352f +-0, 90000, 188892, 0x9630a04d +-0, 96000, 188892, 0x9381b4c1 ++0, 90000, 188892, 0x11c861b9 ++0, 96000, 188892, 0x7c1b767b + 1, 99461, 544, 0xeb766d34 + 1, 100563, 5906, 0x47ac7e08 +-0, 102000, 188892, 0xa7dea7e5 +-0, 108000, 188892, 0xd277c41d ++0, 102000, 188892, 0x5078694c ++0, 108000, 188892, 0xa24485c2 + 1, 112522, 5916, 0x0d26eb56 +-0, 114000, 188892, 0xafa2a6c9 +-0, 120000, 188892, 0x13a38839 ++0, 114000, 188892, 0xc8016946 ++0, 120000, 188892, 0x71e3493b + 1, 124502, 4006, 0x9941c71a +-0, 126000, 188892, 0xcd5e5a6d +-0, 132000, 188892, 0xe7da71e9 ++0, 126000, 188892, 0xa9771a0d ++0, 132000, 188892, 0x98be33fd + 1, 132615, 2100, 0xc9a2ee36 + 1, 136867, 5894, 0xd2ba4eaa +-0, 138000, 188892, 0x06928add +-0, 144000, 188892, 0x4a108eb9 ++0, 138000, 188892, 0x193e4cda ++0, 144000, 188892, 0x3b444fd1 + 1, 148803, 6090, 0xf43e73d0 +-0, 150000, 188892, 0xea2598f5 +-0, 156000, 188892, 0x17ed6839 ++0, 150000, 188892, 0x8bfe594c ++0, 156000, 188892, 0xaab8267b + 1, 161135, 2288, 0x5a8b7aa0 +-0, 162000, 188892, 0x9de6ab65 ++0, 162000, 188892, 0x03206c55 + 1, 165768, 3850, 0x7f66eb2c +-0, 168000, 188892, 0xb4ee326f ++0, 168000, 188892, 0x8ed7ea7d + 1, 173564, 5796, 0xc5cf3ee8 +-0, 174000, 188892, 0x3f85095b +-0, 180000, 188892, 0xaab7e331 ++0, 174000, 188892, 0x2a1bc3e1 ++0, 180000, 188892, 0xa6a12aa7 + 1, 185302, 6042, 0xed80136d +-0, 186000, 188892, 0xc2a079e1 +-0, 192000, 188892, 0x612080c2 ++0, 186000, 188892, 0xa96ca4fa ++0, 192000, 188892, 0x3e3a6d70 + 1, 197537, 684, 0xc42bd137 +-0, 198000, 188892, 0xa7232d47 ++0, 198000, 188892, 0x47e173dd + 1, 198922, 5436, 0xb7f8a6fd +-0, 204000, 188892, 0xc053297d ++0, 204000, 188892, 0xfcf183ba + 1, 209930, 6098, 0xee6354a2 +-0, 210000, 188892, 0x1ecc3bfe +-0, 216000, 188892, 0xcc4ac803 +-0, 222000, 188892, 0x4b90047b ++0, 210000, 188892, 0xf051be46 ++0, 216000, 188892, 0x8aa6b100 ++0, 222000, 188892, 0x36c86b01 + 1, 222278, 4838, 0x129e61d0 +-0, 228000, 188892, 0xd863b643 ++0, 228000, 188892, 0x15ae396e + 1, 232075, 1074, 0x9da90634 +-0, 234000, 188892, 0x93a25fb1 ++0, 234000, 188892, 0xc876eabf + 1, 234250, 6084, 0x8ffed952 +-0, 240000, 188892, 0xf969e131 +-0, 246000, 188892, 0x73bd2469 ++0, 240000, 188892, 0xc5c65fae ++0, 246000, 188892, 0x4feec932 + 1, 246571, 6038, 0xa07b4276 +-0, 252000, 188892, 0x265a9ce2 +-0, 258000, 188892, 0xd59ccd39 ++0, 252000, 188892, 0x21374e88 ++0, 258000, 188892, 0x52e689f1 + 1, 258798, 3176, 0xebef63c1 +-0, 264000, 188892, 0xe50fc068 ++0, 264000, 188892, 0x9e2492e8 + 1, 265229, 2794, 0xbe1000db +-0, 270000, 188892, 0x83113a86 ++0, 270000, 188892, 0xac841247 + 1, 270887, 6020, 0xd8e34961 +-0, 276000, 188892, 0xa0203504 +-0, 282000, 188892, 0x9e2d518c ++0, 276000, 188892, 0x8467aab2 ++0, 282000, 188892, 0x552b6029 + 1, 283078, 6020, 0xc07cf461 +-0, 288000, 188892, 0x5f610e66 +-0, 294000, 188892, 0x9b77f900 ++0, 288000, 188892, 0x836eb46e ++0, 294000, 188892, 0x93eb9f1b + 1, 295268, 1538, 0xc975ae02 + 1, 298383, 4230, 0x0827111b +-0, 300000, 188892, 0xaaf279c2 +-0, 306000, 188892, 0x4ac97cc2 ++0, 300000, 188892, 0xa3661fdd ++0, 306000, 188892, 0x433d22dd + 1, 306949, 6084, 0x2cf0a407 +-0, 312000, 188892, 0xddd91642 +-0, 318000, 188892, 0x4f32dcd1 ++0, 312000, 188892, 0xd64dbc4e ++0, 318000, 188892, 0x4a2aa0e3 + 1, 319269, 5828, 0x12750279 +-0, 324000, 188892, 0xdc126b42 ++0, 324000, 188892, 0xd98e4d4b + 0, 330000, 188892, 0x00000000 + 1, 331071, 230, 0xc9c03f3b + 1, 331536, 768, 0x6137a04d +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cscd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cscd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cscd 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cscd 2012-05-14 14:08:55.633366125 +0200 +@@ -1,208 +1,208 @@ + 0, 0, 270000, 0xf90015d8 +-0, 2880, 270000, 0xf90015d8 +-0, 5760, 270000, 0xf90015d8 +-0, 8640, 270000, 0xf90015d8 +-0, 11520, 270000, 0xf90015d8 ++0, 450, 270000, 0xf90015d8 ++0, 900, 270000, 0xf90015d8 ++0, 1350, 270000, 0xf90015d8 ++0, 1800, 270000, 0xf90015d8 ++0, 2250, 270000, 0xf90015d8 ++0, 2700, 270000, 0xf90015d8 ++0, 3150, 270000, 0xf90015d8 ++0, 3600, 270000, 0xf90015d8 ++0, 4050, 270000, 0xf90015d8 ++0, 4500, 270000, 0xf90015d8 ++0, 4950, 270000, 0xf90015d8 ++0, 5400, 270000, 0xf90015d8 ++0, 5850, 270000, 0xf90015d8 ++0, 6300, 270000, 0xf90015d8 ++0, 6750, 270000, 0xf90015d8 ++0, 7200, 270000, 0xf90015d8 ++0, 7650, 270000, 0xf90015d8 ++0, 8100, 270000, 0xf90015d8 ++0, 8550, 270000, 0xf90015d8 ++0, 9000, 270000, 0xf90015d8 ++0, 9450, 270000, 0xf90015d8 ++0, 9900, 270000, 0xf90015d8 ++0, 10350, 270000, 0xf90015d8 ++0, 10800, 270000, 0xf90015d8 ++0, 11250, 270000, 0xf90015d8 ++0, 11700, 270000, 0xf90015d8 ++0, 12150, 270000, 0xf90015d8 ++0, 12600, 270000, 0xf90015d8 ++0, 13050, 270000, 0xf90015d8 ++0, 13500, 270000, 0xf90015d8 ++0, 13950, 270000, 0xf90015d8 + 0, 14400, 270000, 0xf90015d8 +-0, 17280, 270000, 0xf90015d8 +-0, 20160, 270000, 0xf90015d8 +-0, 23040, 270000, 0xf90015d8 +-0, 25920, 270000, 0xf90015d8 +-0, 28800, 270000, 0xf90015d8 +-0, 31680, 270000, 0xf90015d8 +-0, 34560, 270000, 0xf90015d8 +-0, 37440, 270000, 0xf90015d8 +-0, 40320, 270000, 0xf90015d8 +-0, 43200, 270000, 0xf90015d8 +-0, 46080, 270000, 0xf90015d8 +-0, 48960, 270000, 0xf90015d8 +-0, 51840, 270000, 0xf90015d8 +-0, 54720, 270000, 0xf90015d8 +-0, 57600, 270000, 0xf90015d8 +-0, 60480, 270000, 0xf90015d8 +-0, 63360, 270000, 0xf90015d8 +-0, 66240, 270000, 0xf90015d8 +-0, 69120, 270000, 0xf90015d8 +-0, 72000, 270000, 0xf90015d8 +-0, 74880, 270000, 0xf90015d8 +-0, 77760, 270000, 0xf90015d8 +-0, 80640, 270000, 0xf90015d8 +-0, 83520, 270000, 0xf90015d8 +-0, 86400, 270000, 0xf90015d8 +-0, 89280, 270000, 0xf90015d8 +-0, 92160, 270000, 0xf90015d8 +-0, 95040, 270000, 0xf90015d8 +-0, 97920, 270000, 0xf90015d8 +-0, 100800, 270000, 0xf90015d8 +-0, 103680, 270000, 0xf90015d8 +-0, 106560, 270000, 0xf90015d8 +-0, 109440, 270000, 0xf90015d8 +-0, 112320, 270000, 0x1f9c15d8 +-0, 115200, 270000, 0x436f15d8 +-0, 118080, 270000, 0xe90115d8 +-0, 120960, 270000, 0xe90115d8 +-0, 123840, 270000, 0x8ea215d8 +-0, 126720, 270000, 0x424015d8 +-0, 129600, 270000, 0x0ce315d8 +-0, 132480, 270000, 0x14bc15d8 +-0, 135360, 270000, 0x2a9215d8 +-0, 138240, 270000, 0x233f15d8 +-0, 141120, 270000, 0x764b15d8 +-0, 144000, 270000, 0xf76115d8 +-0, 146880, 270000, 0xbbe015d8 +-0, 149760, 270000, 0x95af15d8 +-0, 152640, 270000, 0x324815d8 +-0, 155520, 270000, 0x311915d8 +-0, 158400, 270000, 0x090ef191 +-0, 161280, 270000, 0xd88974dc +-0, 164160, 270000, 0xfa7f58df +-0, 167040, 270000, 0x78f849c3 +-0, 169920, 270000, 0xae174892 +-0, 172800, 270000, 0x9d4e2332 +-0, 175680, 270000, 0x874b09b4 +-0, 178560, 270000, 0x4069fed6 +-0, 181440, 270000, 0x4069fed6 +-0, 184320, 270000, 0x4069fed6 +-0, 187200, 270000, 0x4069fed6 +-0, 190080, 270000, 0x4069fed6 +-0, 192960, 270000, 0x4069fed6 +-0, 195840, 270000, 0x4069fed6 +-0, 198720, 270000, 0x4069fed6 +-0, 201600, 270000, 0x4069fed6 +-0, 204480, 270000, 0x4069fed6 +-0, 207360, 270000, 0x4069fed6 +-0, 210240, 270000, 0x773db046 +-0, 213120, 270000, 0x773db046 +-0, 216000, 270000, 0x773db046 +-0, 218880, 270000, 0x773db046 +-0, 221760, 270000, 0x773db046 +-0, 224640, 270000, 0x773db046 +-0, 227520, 270000, 0x773db046 +-0, 230400, 270000, 0x773db046 +-0, 233280, 270000, 0x773db046 +-0, 236160, 270000, 0x773db046 +-0, 239040, 270000, 0x773db046 +-0, 241920, 270000, 0x773db046 +-0, 244800, 270000, 0x773db046 +-0, 247680, 270000, 0x773db046 +-0, 250560, 270000, 0x773db046 +-0, 253440, 270000, 0x773db046 +-0, 256320, 270000, 0x773db046 +-0, 259200, 270000, 0x17b9aec9 +-0, 262080, 270000, 0x622fad4c +-0, 264960, 270000, 0xdaea3aef +-0, 267840, 270000, 0x61bb10e3 +-0, 270720, 270000, 0xfc37ee0c +-0, 273600, 270000, 0x50dbd01e +-0, 276480, 270000, 0xcd66c27c +-0, 279360, 270000, 0xd13f1e4f +-0, 282240, 270000, 0xa4a2dbf5 +-0, 285120, 270000, 0xf302c9ab +-0, 288000, 270000, 0x4479f7fe +-0, 290880, 270000, 0x1afe92c8 +-0, 293760, 270000, 0x3007f4c3 +-0, 296640, 270000, 0x5834c096 +-0, 299520, 270000, 0x40109126 +-0, 302400, 270000, 0x0a7b8882 +-0, 305280, 270000, 0x15b8635d +-0, 308160, 270000, 0xeaa5598e +-0, 311040, 270000, 0x0b7b5489 +-0, 313920, 270000, 0x0b7b5489 +-0, 316800, 270000, 0x0b7b5489 +-0, 319680, 270000, 0x0b7b5489 +-0, 322560, 270000, 0x8f0e6eaa +-0, 325440, 270000, 0xc46fc0f2 +-0, 328320, 270000, 0xadd7e605 +-0, 331200, 270000, 0x9d23a056 +-0, 334080, 270000, 0x365afa63 +-0, 336960, 270000, 0x6ac3bda2 +-0, 339840, 270000, 0x14f5daf2 +-0, 342720, 270000, 0x4b3afb6a +-0, 345600, 270000, 0x1a3302e3 +-0, 348480, 270000, 0x1a3302e3 +-0, 351360, 270000, 0x1a3302e3 +-0, 354240, 270000, 0x1a3302e3 +-0, 357120, 270000, 0xc15526e2 +-0, 360000, 270000, 0x3dd73006 +-0, 362880, 270000, 0x60abb5bc +-0, 365760, 270000, 0xb960c27c +-0, 368640, 270000, 0x8fa4c01c +-0, 371520, 270000, 0x8fa4c01c +-0, 374400, 270000, 0x8fa4c01c +-0, 377280, 270000, 0xb20dcc38 +-0, 380160, 270000, 0x03c6ad3c +-0, 383040, 270000, 0xe550b194 +-0, 385920, 270000, 0xe550b194 +-0, 388800, 270000, 0xe550b194 +-0, 391680, 270000, 0xe550b194 +-0, 394560, 270000, 0xe550b194 +-0, 397440, 270000, 0xe550b194 +-0, 400320, 270000, 0xe550b194 +-0, 403200, 270000, 0xe550b194 +-0, 406080, 270000, 0xe550b194 +-0, 408960, 270000, 0xe550b194 +-0, 411840, 270000, 0xe550b194 +-0, 414720, 270000, 0xe550b194 +-0, 417600, 270000, 0xe550b194 +-0, 420480, 270000, 0xe550b194 +-0, 423360, 270000, 0x4550a014 +-0, 426240, 270000, 0xaf639da8 +-0, 429120, 270000, 0xe4229da8 +-0, 432000, 270000, 0x315d9da8 +-0, 434880, 270000, 0x7e899da8 +-0, 437760, 270000, 0x99b9a8a0 +-0, 440640, 270000, 0x4588ac2a +-0, 443520, 270000, 0x1e79ae6e +-0, 446400, 270000, 0xa003cb14 +-0, 449280, 270000, 0x03ef1bb8 +-0, 452160, 270000, 0x3b3f30fc +-0, 455040, 270000, 0x4dad3525 +-0, 457920, 270000, 0x5b600c12 +-0, 460800, 270000, 0x75a1fab3 +-0, 463680, 270000, 0xc9f7d9ad +-0, 466560, 270000, 0x9eaec58d +-0, 469440, 270000, 0xb91bc3e8 +-0, 472320, 270000, 0x77bdbbfb +-0, 475200, 270000, 0x77bdbbfb +-0, 478080, 270000, 0x77bdbbfb +-0, 480960, 270000, 0x77bdbbfb +-0, 483840, 270000, 0x77bdbbfb +-0, 486720, 270000, 0x77bdbbfb +-0, 489600, 270000, 0x3d54eac2 +-0, 492480, 270000, 0x3d54eac2 +-0, 495360, 270000, 0x3d54eac2 +-0, 498240, 270000, 0x3d54eac2 +-0, 501120, 270000, 0x3d54eac2 +-0, 504000, 270000, 0x3d54eac2 +-0, 506880, 270000, 0x3d54eac2 +-0, 509760, 270000, 0x3d54eac2 +-0, 512640, 270000, 0x3d54eac2 +-0, 515520, 270000, 0x3d54eac2 +-0, 518400, 270000, 0x3d54eac2 +-0, 521280, 270000, 0x3d54eac2 +-0, 524160, 270000, 0x3d54eac2 +-0, 527040, 270000, 0x3d54eac2 +-0, 529920, 270000, 0x3d54eac2 +-0, 532800, 270000, 0x3d54eac2 +-0, 535680, 270000, 0x3d54eac2 +-0, 538560, 270000, 0x3d54eac2 +-0, 541440, 270000, 0x3d54eac2 +-0, 544320, 270000, 0x5f3609ba +-0, 547200, 270000, 0x80921b0c +-0, 550080, 270000, 0x80921b0c +-0, 552960, 270000, 0x80921b0c +-0, 555840, 270000, 0x80921b0c +-0, 558720, 270000, 0x80921b0c +-0, 561600, 270000, 0x80921b0c +-0, 564480, 270000, 0x80921b0c +-0, 567360, 270000, 0x80921b0c +-0, 570240, 270000, 0x80921b0c +-0, 573120, 270000, 0x80921b0c +-0, 576000, 270000, 0x80921b0c +-0, 578880, 270000, 0x80921b0c +-0, 581760, 270000, 0x80921b0c +-0, 584640, 270000, 0x80921b0c +-0, 587520, 270000, 0x80921b0c +-0, 590400, 270000, 0x80921b0c +-0, 593280, 270000, 0xf0e626a8 +-0, 596160, 270000, 0xf0e626a8 ++0, 14850, 270000, 0xf90015d8 ++0, 15300, 270000, 0xf90015d8 ++0, 15750, 270000, 0xf90015d8 ++0, 16200, 270000, 0xf90015d8 ++0, 16650, 270000, 0xf90015d8 ++0, 17100, 270000, 0xf90015d8 ++0, 17550, 270000, 0x1f9c15d8 ++0, 18000, 270000, 0x436f15d8 ++0, 18450, 270000, 0xe90115d8 ++0, 18900, 270000, 0xe90115d8 ++0, 19350, 270000, 0x8ea215d8 ++0, 19800, 270000, 0x424015d8 ++0, 20250, 270000, 0x0ce315d8 ++0, 20700, 270000, 0x14bc15d8 ++0, 21150, 270000, 0x2a9215d8 ++0, 21600, 270000, 0x233f15d8 ++0, 22050, 270000, 0x764b15d8 ++0, 22500, 270000, 0xf76115d8 ++0, 22950, 270000, 0xbbe015d8 ++0, 23400, 270000, 0x95af15d8 ++0, 23850, 270000, 0x324815d8 ++0, 24300, 270000, 0x311915d8 ++0, 24750, 270000, 0x090ef191 ++0, 25200, 270000, 0xd88974dc ++0, 25650, 270000, 0xfa7f58df ++0, 26100, 270000, 0x78f849c3 ++0, 26550, 270000, 0xae174892 ++0, 27000, 270000, 0x9d4e2332 ++0, 27450, 270000, 0x874b09b4 ++0, 27900, 270000, 0x4069fed6 ++0, 28350, 270000, 0x4069fed6 ++0, 28800, 270000, 0x4069fed6 ++0, 29250, 270000, 0x4069fed6 ++0, 29700, 270000, 0x4069fed6 ++0, 30150, 270000, 0x4069fed6 ++0, 30600, 270000, 0x4069fed6 ++0, 31050, 270000, 0x4069fed6 ++0, 31500, 270000, 0x4069fed6 ++0, 31950, 270000, 0x4069fed6 ++0, 32400, 270000, 0x4069fed6 ++0, 32850, 270000, 0x773db046 ++0, 33300, 270000, 0x773db046 ++0, 33750, 270000, 0x773db046 ++0, 34200, 270000, 0x773db046 ++0, 34650, 270000, 0x773db046 ++0, 35100, 270000, 0x773db046 ++0, 35550, 270000, 0x773db046 ++0, 36000, 270000, 0x773db046 ++0, 36450, 270000, 0x773db046 ++0, 36900, 270000, 0x773db046 ++0, 37350, 270000, 0x773db046 ++0, 37800, 270000, 0x773db046 ++0, 38250, 270000, 0x773db046 ++0, 38700, 270000, 0x773db046 ++0, 39150, 270000, 0x773db046 ++0, 39600, 270000, 0x773db046 ++0, 40050, 270000, 0x773db046 ++0, 40500, 270000, 0x17b9aec9 ++0, 40950, 270000, 0x622fad4c ++0, 41400, 270000, 0xdaea3aef ++0, 41850, 270000, 0x61bb10e3 ++0, 42300, 270000, 0xfc37ee0c ++0, 42750, 270000, 0x50dbd01e ++0, 43200, 270000, 0xcd66c27c ++0, 43650, 270000, 0xd13f1e4f ++0, 44100, 270000, 0xa4a2dbf5 ++0, 44550, 270000, 0xf302c9ab ++0, 45000, 270000, 0x4479f7fe ++0, 45450, 270000, 0x1afe92c8 ++0, 45900, 270000, 0x3007f4c3 ++0, 46350, 270000, 0x5834c096 ++0, 46800, 270000, 0x40109126 ++0, 47250, 270000, 0x0a7b8882 ++0, 47700, 270000, 0x15b8635d ++0, 48150, 270000, 0xeaa5598e ++0, 48600, 270000, 0x0b7b5489 ++0, 49050, 270000, 0x0b7b5489 ++0, 49500, 270000, 0x0b7b5489 ++0, 49950, 270000, 0x0b7b5489 ++0, 50400, 270000, 0x8f0e6eaa ++0, 50850, 270000, 0xc46fc0f2 ++0, 51300, 270000, 0xadd7e605 ++0, 51750, 270000, 0x9d23a056 ++0, 52200, 270000, 0x365afa63 ++0, 52650, 270000, 0x6ac3bda2 ++0, 53100, 270000, 0x14f5daf2 ++0, 53550, 270000, 0x4b3afb6a ++0, 54000, 270000, 0x1a3302e3 ++0, 54450, 270000, 0x1a3302e3 ++0, 54900, 270000, 0x1a3302e3 ++0, 55350, 270000, 0x1a3302e3 ++0, 55800, 270000, 0xc15526e2 ++0, 56250, 270000, 0x3dd73006 ++0, 56700, 270000, 0x60abb5bc ++0, 57150, 270000, 0xb960c27c ++0, 57600, 270000, 0x8fa4c01c ++0, 58050, 270000, 0x8fa4c01c ++0, 58500, 270000, 0x8fa4c01c ++0, 58950, 270000, 0xb20dcc38 ++0, 59400, 270000, 0x03c6ad3c ++0, 59850, 270000, 0xe550b194 ++0, 60300, 270000, 0xe550b194 ++0, 60750, 270000, 0xe550b194 ++0, 61200, 270000, 0xe550b194 ++0, 61650, 270000, 0xe550b194 ++0, 62100, 270000, 0xe550b194 ++0, 62550, 270000, 0xe550b194 ++0, 63000, 270000, 0xe550b194 ++0, 63450, 270000, 0xe550b194 ++0, 63900, 270000, 0xe550b194 ++0, 64350, 270000, 0xe550b194 ++0, 64800, 270000, 0xe550b194 ++0, 65250, 270000, 0xe550b194 ++0, 65700, 270000, 0xe550b194 ++0, 66150, 270000, 0x4550a014 ++0, 66600, 270000, 0xaf639da8 ++0, 67050, 270000, 0xe4229da8 ++0, 67500, 270000, 0x315d9da8 ++0, 67950, 270000, 0x7e899da8 ++0, 68400, 270000, 0x99b9a8a0 ++0, 68850, 270000, 0x4588ac2a ++0, 69300, 270000, 0x1e79ae6e ++0, 69750, 270000, 0xa003cb14 ++0, 70200, 270000, 0x03ef1bb8 ++0, 70650, 270000, 0x3b3f30fc ++0, 71100, 270000, 0x4dad3525 ++0, 71550, 270000, 0x5b600c12 ++0, 72000, 270000, 0x75a1fab3 ++0, 72450, 270000, 0xc9f7d9ad ++0, 72900, 270000, 0x9eaec58d ++0, 73350, 270000, 0xb91bc3e8 ++0, 73800, 270000, 0x77bdbbfb ++0, 74250, 270000, 0x77bdbbfb ++0, 74700, 270000, 0x77bdbbfb ++0, 75150, 270000, 0x77bdbbfb ++0, 75600, 270000, 0x77bdbbfb ++0, 76050, 270000, 0x77bdbbfb ++0, 76500, 270000, 0x3d54eac2 ++0, 76950, 270000, 0x3d54eac2 ++0, 77400, 270000, 0x3d54eac2 ++0, 77850, 270000, 0x3d54eac2 ++0, 78300, 270000, 0x3d54eac2 ++0, 78750, 270000, 0x3d54eac2 ++0, 79200, 270000, 0x3d54eac2 ++0, 79650, 270000, 0x3d54eac2 ++0, 80100, 270000, 0x3d54eac2 ++0, 80550, 270000, 0x3d54eac2 ++0, 81000, 270000, 0x3d54eac2 ++0, 81450, 270000, 0x3d54eac2 ++0, 81900, 270000, 0x3d54eac2 ++0, 82350, 270000, 0x3d54eac2 ++0, 82800, 270000, 0x3d54eac2 ++0, 83250, 270000, 0x3d54eac2 ++0, 83700, 270000, 0x3d54eac2 ++0, 84150, 270000, 0x3d54eac2 ++0, 84600, 270000, 0x3d54eac2 ++0, 85050, 270000, 0x5f3609ba ++0, 85500, 270000, 0x80921b0c ++0, 85950, 270000, 0x80921b0c ++0, 86400, 270000, 0x80921b0c ++0, 86850, 270000, 0x80921b0c ++0, 87300, 270000, 0x80921b0c ++0, 87750, 270000, 0x80921b0c ++0, 88200, 270000, 0x80921b0c ++0, 88650, 270000, 0x80921b0c ++0, 89100, 270000, 0x80921b0c ++0, 89550, 270000, 0x80921b0c ++0, 90000, 270000, 0x80921b0c ++0, 90450, 270000, 0x80921b0c ++0, 90900, 270000, 0x80921b0c ++0, 91350, 270000, 0x80921b0c ++0, 91800, 270000, 0x80921b0c ++0, 92250, 270000, 0x80921b0c ++0, 92700, 270000, 0xf0e626a8 ++0, 93150, 270000, 0xf0e626a8 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid 1970-01-01 01:00:00.000000000 +0100 +@@ -1,78 +0,0 @@ +-0, 0, 112400, 0x829180d8 +-0, 7500, 112400, 0xdbebac5b +-0, 15000, 112400, 0xc5adc0f7 +-0, 22500, 112400, 0xbe1fc030 +-0, 30000, 112400, 0xe08ab460 +-0, 37500, 112400, 0xfde0dbc5 +-0, 45000, 112400, 0xed9242b0 +-0, 52500, 112400, 0x1ae3933a +-0, 60000, 112400, 0xc82d2f5b +-0, 67500, 112400, 0xbae9ddfc +-0, 75000, 112400, 0xa350a1f7 +-0, 82500, 112400, 0x3cf78029 +-0, 90000, 112400, 0xaa0b82bf +-0, 97500, 112400, 0x71aa4794 +-0, 105000, 112400, 0x2fe57373 +-0, 112500, 112400, 0x429c6f82 +-0, 120000, 112400, 0xfb2d917d +-0, 127500, 112400, 0xcc84cb9a +-0, 135000, 112400, 0xc68f0613 +-0, 142500, 112400, 0x05f30e6a +-0, 150000, 112400, 0x5c5d853d +-0, 157500, 112400, 0x01e0aff2 +-0, 165000, 112400, 0xc3b2cf4a +-0, 172500, 112400, 0xc0a3cf19 +-0, 180000, 112400, 0xc743abda +-0, 187500, 112400, 0x54bd17a2 +-0, 195000, 112400, 0x616ef28d +-0, 202500, 112400, 0x04b51f59 +-0, 210000, 112400, 0x857511a2 +-0, 217500, 112400, 0x25c62440 +-0, 225000, 112400, 0x8c78198d +-0, 232500, 112400, 0xc046c912 +-0, 240000, 112400, 0x0d828630 +-0, 247500, 112400, 0x48999b80 +-0, 255000, 112400, 0x9a869e77 +-0, 262500, 112400, 0x16d893df +-0, 270000, 112400, 0xf6b86132 +-0, 277500, 112400, 0xfa564ea4 +-0, 285000, 112400, 0xdd473f69 +-0, 292500, 112400, 0xf89625a6 +-0, 300000, 112400, 0x823a58aa +-0, 307500, 112400, 0x25e0fe43 +-0, 315000, 112400, 0x41034522 +-0, 322500, 112400, 0xb8da4f00 +-0, 330000, 112400, 0x9f684fce +-0, 337500, 112400, 0xf7188710 +-0, 345000, 112400, 0x428fbfc6 +-0, 352500, 112400, 0x535bace0 +-0, 360000, 112400, 0x23216059 +-0, 367500, 112400, 0x9b8bbfa6 +-0, 375000, 112400, 0x932be522 +-0, 382500, 112400, 0xdbd31409 +-0, 390000, 112400, 0x0a69bf18 +-0, 397500, 112400, 0xa15ef128 +-0, 405000, 112400, 0x49a1fa92 +-0, 412500, 112400, 0xadeeaf62 +-0, 420000, 112400, 0xc1ce636e +-0, 427500, 112400, 0x5ca544eb +-0, 435000, 112400, 0x07230a36 +-0, 442500, 112400, 0x12ae2b53 +-0, 450000, 112400, 0x62453ef6 +-0, 457500, 112400, 0xe0588a98 +-0, 465000, 112400, 0xacd3927a +-0, 472500, 112400, 0x5d3c6b01 +-0, 480000, 112400, 0xda671808 +-0, 487500, 112400, 0x61d0b492 +-0, 495000, 112400, 0x068b1293 +-0, 502500, 112400, 0x75b99287 +-0, 510000, 112400, 0xe657e7d6 +-0, 517500, 112400, 0x17873df6 +-0, 525000, 112400, 0xa8db5e31 +-0, 532500, 112400, 0x4f633b8e +-0, 540000, 112400, 0x22266252 +-0, 547500, 112400, 0x308a6282 +-0, 555000, 112400, 0xfdb356ce +-0, 562500, 112400, 0xe4394f1f +-0, 570000, 112400, 0x8ca8649f +-0, 577500, 112400, 0x804d44eb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid-grayscale xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid-grayscale +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid-grayscale 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid-grayscale 2012-05-14 14:08:55.634366145 +0200 +@@ -0,0 +1,152 @@ ++0, 0, 11300, 0x46c78923 ++0, 17921, 11300, 0x3f2a1175 ++0, 35842, 11300, 0x722de221 ++0, 53763, 11300, 0x01746b88 ++0, 71684, 11300, 0x549587a7 ++0, 89605, 11300, 0x843ab943 ++0, 107526, 11300, 0x62fdee48 ++0, 125447, 11300, 0x74a62867 ++0, 143368, 11300, 0x35a20e2f ++0, 161289, 11300, 0x4e9ef54d ++0, 179210, 11300, 0xec7201f5 ++0, 197131, 11300, 0x363bfe27 ++0, 215052, 11300, 0x2aaab418 ++0, 232973, 11300, 0x6a48ab3f ++0, 250894, 11300, 0x3fecea34 ++0, 268815, 11300, 0xa371f55e ++0, 286736, 11300, 0xa86b147c ++0, 304657, 11300, 0x49e9206e ++0, 322578, 11300, 0x6c9a2155 ++0, 340499, 11300, 0x2c8a4798 ++0, 358420, 11300, 0x3485676c ++0, 376341, 11300, 0xb0b293f2 ++0, 394262, 11300, 0xe4a9b068 ++0, 412183, 11300, 0xd68d0556 ++0, 430104, 11300, 0xc28e5193 ++0, 448025, 11300, 0xf6948483 ++0, 465945, 11300, 0xf21fbf57 ++0, 483866, 11300, 0x8345eb44 ++0, 501787, 11300, 0x8124f045 ++0, 519708, 11300, 0x18e31f10 ++0, 537629, 11300, 0xdb1943fc ++0, 555550, 11300, 0x8701699f ++0, 573471, 11300, 0xd7b18550 ++0, 591392, 11300, 0xa56faccc ++0, 609313, 11300, 0xf8bcc17c ++0, 627234, 11300, 0x446acab9 ++0, 645155, 11300, 0x755fd295 ++0, 663076, 11300, 0x92e3d100 ++0, 680997, 11300, 0x54895bb3 ++0, 698918, 11300, 0xd18bffda ++0, 716839, 11300, 0x480dbe4f ++0, 734760, 11300, 0x49ea9dbe ++0, 752681, 11300, 0x00d3a003 ++0, 770602, 11300, 0xda7bbfb2 ++0, 788523, 11300, 0x9700d9c2 ++0, 806444, 11300, 0xa0a9e490 ++0, 824365, 11300, 0x00eb0979 ++0, 842286, 11300, 0x32b04630 ++0, 860207, 11300, 0xdfb73e51 ++0, 878128, 11300, 0x3d8e4f96 ++0, 896049, 11300, 0x2ca83271 ++0, 913970, 11300, 0xb5b123c0 ++0, 931891, 11300, 0x8a570e58 ++0, 949812, 11300, 0xc6c805bc ++0, 967733, 11300, 0x27caf7a5 ++0, 985654, 11300, 0x5319ecb0 ++0, 1003575, 11300, 0x5471e3fd ++0, 1021496, 11300, 0x6d68a6f4 ++0, 1039417, 11300, 0x872b7194 ++0, 1057338, 11300, 0x007c36bd ++0, 1075259, 11300, 0x2714f1b5 ++0, 1093180, 11300, 0x6c8eb50f ++0, 1111101, 11300, 0xf5d57be8 ++0, 1129022, 11300, 0x981f412b ++0, 1146943, 11300, 0x1a9804a1 ++0, 1164864, 11300, 0xf0c1d24a ++0, 1182785, 11300, 0xa70a9d9b ++0, 1200706, 11300, 0x8c466876 ++0, 1218627, 11300, 0xcf2e32df ++0, 1236548, 11300, 0xcb8cfebf ++0, 1254469, 11300, 0xb961ca99 ++0, 1272390, 11300, 0x666d9619 ++0, 1290311, 11300, 0x84bf5b55 ++0, 1308232, 11300, 0xbfa22ccc ++0, 1326153, 11300, 0xcde41849 ++0, 1344074, 11300, 0x71372dcd ++0, 1361994, 11300, 0x13402cfd ++0, 1379915, 11300, 0xdebdd321 ++0, 1397836, 11300, 0xdda66de1 ++0, 1415757, 11300, 0x7f4bb682 ++0, 1433678, 11300, 0xf67fd528 ++0, 1451599, 11300, 0xe739ff8c ++0, 1469520, 11300, 0x2e131774 ++0, 1487441, 11300, 0xfa942811 ++0, 1505362, 11300, 0x0cd93ac2 ++0, 1523283, 11300, 0xd0445e0e ++0, 1541204, 11300, 0x3f3497c7 ++0, 1559125, 11300, 0x11b5bd2c ++0, 1577046, 11300, 0xccd5e62a ++0, 1594967, 11300, 0xa9d4fcb5 ++0, 1612888, 11300, 0x34aa1a03 ++0, 1630809, 11300, 0x1ce6299e ++0, 1648730, 11300, 0x661c2745 ++0, 1666651, 11300, 0x27d8a8b3 ++0, 1684572, 11300, 0x9eb07467 ++0, 1702493, 11300, 0x128374d2 ++0, 1720414, 11300, 0x05c36ff5 ++0, 1738335, 11300, 0x8a136bde ++0, 1756256, 11300, 0x15c47c99 ++0, 1774177, 11300, 0xcc4a93f4 ++0, 1792098, 11300, 0x19529b2b ++0, 1810019, 11300, 0x9943c076 ++0, 1827940, 11300, 0xf898e583 ++0, 1845861, 11300, 0x40f71f94 ++0, 1863782, 11300, 0x5b604afb ++0, 1881703, 11300, 0x8c176af4 ++0, 1899624, 11300, 0x0f1a6216 ++0, 1917545, 11300, 0x38bbd13d ++0, 1935466, 11300, 0x90c8d1fc ++0, 1953387, 11300, 0x253000d7 ++0, 1971308, 11300, 0xb94b03b1 ++0, 1989229, 11300, 0xbc872268 ++0, 2007150, 11300, 0xe77adb8c ++0, 2025071, 11300, 0xa38936b7 ++0, 2042992, 11300, 0xd6153632 ++0, 2060913, 11300, 0x1ae633cc ++0, 2078834, 11300, 0xb90c286e ++0, 2096755, 11300, 0xbc7e333d ++0, 2114676, 11300, 0x1b5421f8 ++0, 2132597, 11300, 0xdde6506d ++0, 2150518, 11300, 0xd3eb757e ++0, 2168439, 11300, 0x5ad1929c ++0, 2186360, 11300, 0x4f6aa47d ++0, 2204281, 11300, 0xab3caf55 ++0, 2222202, 11300, 0x5ff9b39a ++0, 2240123, 11300, 0x1454e12e ++0, 2258043, 11300, 0xf18216e8 ++0, 2275964, 11300, 0x62144880 ++0, 2293885, 11300, 0x54284241 ++0, 2311806, 11300, 0x8e8c7228 ++0, 2329727, 11300, 0xb498d06e ++0, 2347648, 11300, 0x7b1e6be1 ++0, 2365569, 11300, 0x5e5ea1f4 ++0, 2383490, 11300, 0x41eda28e ++0, 2401411, 11300, 0x7ba6aa92 ++0, 2419332, 11300, 0xa8a8b1c7 ++0, 2437253, 11300, 0x0d30bd08 ++0, 2455174, 11300, 0xc610bf16 ++0, 2473095, 11300, 0xed57c075 ++0, 2491016, 11300, 0xb86dbfea ++0, 2508937, 11300, 0x0970c03d ++0, 2526858, 11300, 0x743ac2ac ++0, 2544779, 11300, 0x0a44c816 ++0, 2562700, 11300, 0xe32acd6b ++0, 2580621, 11300, 0x209bcdab ++0, 2598542, 11300, 0x3cd0d105 ++0, 2616463, 11300, 0xc0bcd330 ++0, 2634384, 11300, 0x4785d6dc ++0, 2652305, 11300, 0xe85f9c90 ++0, 2670226, 11300, 0xd4a72850 ++0, 2688147, 11300, 0x04766e41 ++0, 2706068, 11300, 0x04766e41 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid-partial xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid-partial +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/cvid-partial 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/cvid-partial 2012-05-14 14:08:55.635366166 +0200 +@@ -0,0 +1,79 @@ ++0, 0, 112400, 0x829180d8 ++0, 7500, 112400, 0xdbebac5b ++0, 15000, 112400, 0xc5adc0f7 ++0, 22500, 112400, 0xbe1fc030 ++0, 30000, 112400, 0xe08ab460 ++0, 37500, 112400, 0xfde0dbc5 ++0, 45000, 112400, 0xed9242b0 ++0, 52500, 112400, 0x1ae3933a ++0, 60000, 112400, 0xc82d2f5b ++0, 67500, 112400, 0xbae9ddfc ++0, 75000, 112400, 0xa350a1f7 ++0, 82500, 112400, 0x3cf78029 ++0, 90000, 112400, 0xaa0b82bf ++0, 97500, 112400, 0x71aa4794 ++0, 105000, 112400, 0x2fe57373 ++0, 112500, 112400, 0x429c6f82 ++0, 120000, 112400, 0xfb2d917d ++0, 127500, 112400, 0xcc84cb9a ++0, 135000, 112400, 0xc68f0613 ++0, 142500, 112400, 0x05f30e6a ++0, 150000, 112400, 0x5c5d853d ++0, 157500, 112400, 0x01e0aff2 ++0, 165000, 112400, 0xc3b2cf4a ++0, 172500, 112400, 0xc0a3cf19 ++0, 180000, 112400, 0xc743abda ++0, 187500, 112400, 0x54bd17a2 ++0, 195000, 112400, 0x616ef28d ++0, 202500, 112400, 0x04b51f59 ++0, 210000, 112400, 0x857511a2 ++0, 217500, 112400, 0x25c62440 ++0, 225000, 112400, 0x8c78198d ++0, 232500, 112400, 0xc046c912 ++0, 240000, 112400, 0x0d828630 ++0, 247500, 112400, 0x48999b80 ++0, 255000, 112400, 0x9a869e77 ++0, 262500, 112400, 0x16d893df ++0, 270000, 112400, 0xf6b86132 ++0, 277500, 112400, 0xfa564ea4 ++0, 285000, 112400, 0xdd473f69 ++0, 292500, 112400, 0xf89625a6 ++0, 300000, 112400, 0x823a58aa ++0, 307500, 112400, 0x25e0fe43 ++0, 315000, 112400, 0x41034522 ++0, 322500, 112400, 0xb8da4f00 ++0, 330000, 112400, 0x9f684fce ++0, 337500, 112400, 0xf7188710 ++0, 345000, 112400, 0x428fbfc6 ++0, 352500, 112400, 0x535bace0 ++0, 360000, 112400, 0x23216059 ++0, 367500, 112400, 0x9b8bbfa6 ++0, 375000, 112400, 0x932be522 ++0, 382500, 112400, 0xdbd31409 ++0, 390000, 112400, 0x0a69bf18 ++0, 397500, 112400, 0xa15ef128 ++0, 405000, 112400, 0x49a1fa92 ++0, 412500, 112400, 0xadeeaf62 ++0, 420000, 112400, 0xc1ce636e ++0, 427500, 112400, 0x5ca544eb ++0, 435000, 112400, 0x07230a36 ++0, 442500, 112400, 0x12ae2b53 ++0, 450000, 112400, 0x62453ef6 ++0, 457500, 112400, 0xe0588a98 ++0, 465000, 112400, 0xacd3927a ++0, 472500, 112400, 0x5d3c6b01 ++0, 480000, 112400, 0xda671808 ++0, 487500, 112400, 0x61d0b492 ++0, 495000, 112400, 0x068b1293 ++0, 502500, 112400, 0x75b99287 ++0, 510000, 112400, 0xe657e7d6 ++0, 517500, 112400, 0x17873df6 ++0, 525000, 112400, 0xa8db5e31 ++0, 532500, 112400, 0x4f633b8e ++0, 540000, 112400, 0x22266252 ++0, 547500, 112400, 0x308a6282 ++0, 555000, 112400, 0xfdb356ce ++0, 562500, 112400, 0xe4394f1f ++0, 570000, 112400, 0x8ca8649f ++0, 577500, 112400, 0x804d44eb ++0, 585000, 112400, 0x3864488b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/deluxepaint-anm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/deluxepaint-anm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/deluxepaint-anm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/deluxepaint-anm 2012-05-14 14:08:55.635366166 +0200 +@@ -69,87 +69,55 @@ + 0, 204000, 192000, 0xdd7f371d + 0, 207000, 192000, 0xeed134c6 + 0, 210000, 192000, 0x362931f5 +-0, 213000, 192000, 0x362931f5 +-0, 216000, 192000, 0x362931f5 +-0, 219000, 192000, 0x362931f5 +-0, 222000, 192000, 0x362931f5 +-0, 225000, 192000, 0x362931f5 +-0, 228000, 192000, 0x362931f5 +-0, 231000, 192000, 0x362931f5 +-0, 234000, 192000, 0x362931f5 +-0, 237000, 192000, 0x362931f5 +-0, 240000, 192000, 0x362931f5 +-0, 243000, 192000, 0x362931f5 +-0, 246000, 192000, 0x362931f5 +-0, 249000, 192000, 0x362931f5 +-0, 252000, 192000, 0x362931f5 +-0, 255000, 192000, 0x362931f5 +-0, 258000, 192000, 0x362931f5 +-0, 261000, 192000, 0x362931f5 +-0, 264000, 192000, 0x362931f5 +-0, 267000, 192000, 0x362931f5 +-0, 270000, 192000, 0x362931f5 +-0, 273000, 192000, 0x362931f5 +-0, 276000, 192000, 0x362931f5 +-0, 279000, 192000, 0x362931f5 +-0, 282000, 192000, 0x362931f5 +-0, 285000, 192000, 0x362931f5 +-0, 288000, 192000, 0x362931f5 +-0, 291000, 192000, 0x362931f5 +-0, 294000, 192000, 0x362931f5 +-0, 297000, 192000, 0x362931f5 +-0, 300000, 192000, 0x362931f5 +-0, 303000, 192000, 0x362931f5 +-0, 306000, 192000, 0x362931f5 +-0, 309000, 192000, 0xfb41331d +-0, 312000, 192000, 0x087433f8 +-0, 315000, 192000, 0xf36b34a6 +-0, 318000, 192000, 0x652a33cd +-0, 321000, 192000, 0x652a33cd +-0, 324000, 192000, 0xe50c336a +-0, 327000, 192000, 0x652a33cd +-0, 330000, 192000, 0xeed134c6 +-0, 333000, 192000, 0x652a33cd +-0, 336000, 192000, 0x5d7633e5 +-0, 339000, 192000, 0x845233b5 +-0, 342000, 192000, 0x9d1c349b +-0, 345000, 192000, 0x25843317 +-0, 348000, 192000, 0xc84b375c +-0, 351000, 192000, 0xaf2b3410 +-0, 354000, 192000, 0xaf2b3410 +-0, 357000, 192000, 0x26d23594 +-0, 360000, 192000, 0xaf2b3410 +-0, 363000, 192000, 0x26d23594 +-0, 366000, 192000, 0xaf2b3410 +-0, 369000, 192000, 0x72c4dfb9 +-0, 372000, 192000, 0x3c72e390 +-0, 375000, 192000, 0xb4466634 +-0, 378000, 192000, 0x84f064f5 +-0, 381000, 192000, 0xad43f3f5 +-0, 384000, 192000, 0xa8644d57 +-0, 387000, 192000, 0xfac35238 +-0, 390000, 192000, 0xe9374d1e +-0, 393000, 192000, 0x0bd14cfa +-0, 396000, 192000, 0x7e51a437 +-0, 399000, 192000, 0x92678dfa +-0, 402000, 192000, 0x43338d41 +-0, 405000, 192000, 0x00000000 +-0, 408000, 192000, 0x00000000 +-0, 411000, 192000, 0x00000000 +-0, 414000, 192000, 0x00000000 +-0, 417000, 192000, 0x00000000 +-0, 420000, 192000, 0x00000000 +-0, 423000, 192000, 0x00000000 +-0, 426000, 192000, 0x00000000 +-0, 429000, 192000, 0x00000000 +-0, 432000, 192000, 0x00000000 +-0, 435000, 192000, 0x00000000 +-0, 438000, 192000, 0x00000000 +-0, 441000, 192000, 0x00000000 +-0, 444000, 192000, 0x00000000 +-0, 447000, 192000, 0x00000000 +-0, 450000, 192000, 0x00000000 +-0, 453000, 192000, 0x00000000 +-0, 456000, 192000, 0x00000000 +-0, 459000, 192000, 0x00000000 +-0, 462000, 192000, 0x82a79641 ++0, 213000, 192000, 0xfb41331d ++0, 216000, 192000, 0x087433f8 ++0, 219000, 192000, 0xf36b34a6 ++0, 222000, 192000, 0x652a33cd ++0, 225000, 192000, 0x652a33cd ++0, 228000, 192000, 0xe50c336a ++0, 231000, 192000, 0x652a33cd ++0, 234000, 192000, 0xeed134c6 ++0, 237000, 192000, 0x652a33cd ++0, 240000, 192000, 0x5d7633e5 ++0, 243000, 192000, 0x845233b5 ++0, 246000, 192000, 0x9d1c349b ++0, 249000, 192000, 0x25843317 ++0, 252000, 192000, 0xc84b375c ++0, 255000, 192000, 0xaf2b3410 ++0, 258000, 192000, 0xaf2b3410 ++0, 261000, 192000, 0x26d23594 ++0, 264000, 192000, 0xaf2b3410 ++0, 267000, 192000, 0x26d23594 ++0, 270000, 192000, 0xaf2b3410 ++0, 273000, 192000, 0x72c4dfb9 ++0, 276000, 192000, 0x3c72e390 ++0, 279000, 192000, 0xb4466634 ++0, 282000, 192000, 0x84f064f5 ++0, 285000, 192000, 0xad43f3f5 ++0, 288000, 192000, 0xa8644d57 ++0, 291000, 192000, 0xfac35238 ++0, 294000, 192000, 0xe9374d1e ++0, 297000, 192000, 0x0bd14cfa ++0, 300000, 192000, 0x7e51a437 ++0, 303000, 192000, 0x92678dfa ++0, 306000, 192000, 0x43338d41 ++0, 309000, 192000, 0x00000000 ++0, 312000, 192000, 0x00000000 ++0, 315000, 192000, 0x00000000 ++0, 318000, 192000, 0x00000000 ++0, 321000, 192000, 0x00000000 ++0, 324000, 192000, 0x00000000 ++0, 327000, 192000, 0x00000000 ++0, 330000, 192000, 0x00000000 ++0, 333000, 192000, 0x00000000 ++0, 336000, 192000, 0x00000000 ++0, 339000, 192000, 0x00000000 ++0, 342000, 192000, 0x00000000 ++0, 345000, 192000, 0x00000000 ++0, 348000, 192000, 0x00000000 ++0, 351000, 192000, 0x00000000 ++0, 354000, 192000, 0x00000000 ++0, 357000, 192000, 0x00000000 ++0, 360000, 192000, 0x00000000 ++0, 363000, 192000, 0x00000000 ++0, 366000, 192000, 0x82a79641 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa1 2012-05-14 14:08:55.636366186 +0200 +@@ -0,0 +1,25 @@ ++0, 0, 921600, 0xb69faa34 ++0, 11520, 921600, 0x38680829 ++0, 23040, 921600, 0xa7263c5a ++0, 34560, 921600, 0xa784626a ++0, 46080, 921600, 0xb4c47212 ++0, 57600, 921600, 0xd17285ea ++0, 69120, 921600, 0xe9b33902 ++0, 80640, 921600, 0x215ea693 ++0, 92160, 921600, 0xe2ab6c7a ++0, 103680, 921600, 0xf2867624 ++0, 115200, 921600, 0x607d78c1 ++0, 126720, 921600, 0x6e743bb7 ++0, 138240, 921600, 0x1fbf8f5a ++0, 149760, 921600, 0xac6c912e ++0, 161280, 921600, 0x556933bc ++0, 172800, 921600, 0xda4c242b ++0, 184320, 921600, 0xa6b32f83 ++0, 195840, 921600, 0x1ecc2996 ++0, 207360, 921600, 0xf1c3fc0f ++0, 218880, 921600, 0x3f1db909 ++0, 230400, 921600, 0x7582fb93 ++0, 241920, 921600, 0x102ba261 ++0, 253440, 921600, 0xfbcf9de0 ++0, 264960, 921600, 0xe9ecb4d9 ++0, 276480, 921600, 0x7ee36a42 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa10 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa10 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa10 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa10 2012-05-14 14:08:55.636366186 +0200 +@@ -0,0 +1,8 @@ ++0, 0, 192000, 0x7384f9b2 ++0, 6390, 192000, 0xd1f61c71 ++0, 12780, 192000, 0x0c6937d1 ++0, 19170, 192000, 0x56459a3a ++0, 25560, 192000, 0x6d011790 ++0, 31950, 192000, 0xb5347ce8 ++0, 38340, 192000, 0xcd422568 ++0, 44730, 192000, 0xde4fef2d +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa11 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa11 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa11 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa11 2012-05-14 14:08:55.637366206 +0200 +@@ -0,0 +1,9 @@ ++0, 0, 192000, 0x4269d703 ++0, 6390, 192000, 0xdf8667e7 ++0, 12780, 192000, 0x450026ad ++0, 19170, 192000, 0x2528ea52 ++0, 25560, 192000, 0x83bcd1ec ++0, 31950, 192000, 0x88d5ba27 ++0, 38340, 192000, 0x44424577 ++0, 44730, 192000, 0xd93f12a3 ++0, 51120, 192000, 0xcd625f3e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa2 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa2 2012-05-14 14:08:55.637366206 +0200 +@@ -0,0 +1,17 @@ ++0, 0, 921600, 0x8a5d15df ++0, 6390, 921600, 0x92c01362 ++0, 12780, 921600, 0xe1a31643 ++0, 19170, 921600, 0x37a90fe2 ++0, 25560, 921600, 0x74410783 ++0, 31950, 921600, 0xecf4ef1a ++0, 38340, 921600, 0x4d7ff3d4 ++0, 44730, 921600, 0xac820317 ++0, 51120, 921600, 0xbe5ff56e ++0, 57510, 921600, 0x8e59c329 ++0, 63900, 921600, 0x73bf23f3 ++0, 70290, 921600, 0xb90c780f ++0, 76680, 921600, 0xfbd9dc32 ++0, 83070, 921600, 0x30586821 ++0, 89460, 921600, 0x6695195b ++0, 95850, 921600, 0xc449aa85 ++0, 102240, 921600, 0xca6a391c +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa3 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa3 2012-05-14 14:08:55.638366226 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 192000, 0x236a1b54 ++0, 9000, 192000, 0xfb438b68 ++0, 18000, 192000, 0xde504563 ++0, 27000, 192000, 0xfaf88e05 ++0, 36000, 192000, 0xe15de5af ++0, 45000, 192000, 0x641fcca4 ++0, 54000, 192000, 0x74899cb6 ++0, 63000, 192000, 0x93fdb1b4 ++0, 72000, 192000, 0x58d83456 ++0, 81000, 192000, 0x7d3012ac +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa4 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa4 2012-05-14 14:08:55.638366226 +0200 +@@ -0,0 +1,13 @@ ++0, 0, 921600, 0xd9e060e3 ++0, 12780, 921600, 0x15e28dc7 ++0, 25560, 921600, 0x78e8bfbc ++0, 38340, 921600, 0xe9407075 ++0, 51120, 921600, 0xab818b8a ++0, 63900, 921600, 0xab818b8a ++0, 76680, 921600, 0xab818b8a ++0, 89460, 921600, 0xab818b8a ++0, 102240, 921600, 0xab818b8a ++0, 115020, 921600, 0xab818b8a ++0, 127800, 921600, 0xad5ad11c ++0, 140580, 921600, 0xe6e50f8c ++0, 153360, 921600, 0x9f127099 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa5 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa5 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa5 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa5 2012-05-14 14:08:55.639366246 +0200 +@@ -0,0 +1,15 @@ ++0, 0, 192000, 0x9754890f ++0, 9000, 192000, 0x01668965 ++0, 18000, 192000, 0xbd1b5e12 ++0, 27000, 192000, 0x2e97fb9f ++0, 36000, 192000, 0xf8b452e2 ++0, 45000, 192000, 0xc6859449 ++0, 54000, 192000, 0x910844f7 ++0, 63000, 192000, 0x99443581 ++0, 72000, 192000, 0xec52d1e5 ++0, 81000, 192000, 0x2fc66c35 ++0, 90000, 192000, 0xd9af7379 ++0, 99000, 192000, 0x947a26ef ++0, 108000, 192000, 0x7b77ab28 ++0, 117000, 192000, 0x2507637e ++0, 126000, 192000, 0x6ce8c0ea +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa6 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa6 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa6 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa6 2012-05-14 14:08:55.639366246 +0200 +@@ -0,0 +1,12 @@ ++0, 0, 192000, 0xb718dc63 ++0, 6390, 192000, 0x2efb7b89 ++0, 12780, 192000, 0x70827047 ++0, 19170, 192000, 0x61e1fd2f ++0, 25560, 192000, 0x06f8bccd ++0, 31950, 192000, 0xf0362404 ++0, 38340, 192000, 0xc00fc1b8 ++0, 44730, 192000, 0x94265476 ++0, 51120, 192000, 0x4b50ad23 ++0, 57510, 192000, 0x4d578b60 ++0, 63900, 192000, 0xfb14b875 ++0, 70290, 192000, 0x81682338 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa7 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa7 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa7 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa7 2012-05-14 14:08:55.640366266 +0200 +@@ -0,0 +1,12 @@ ++0, 0, 7866, 0xab73dae7 ++0, 6390, 7866, 0x100adec8 ++0, 12780, 7866, 0x1a20ddfa ++0, 19170, 7866, 0xc358cd16 ++0, 25560, 7866, 0xee0bd20e ++0, 31950, 7866, 0xef26bef9 ++0, 38340, 7866, 0xa9d0c755 ++0, 44730, 7866, 0x6c11cc7c ++0, 51120, 7866, 0x4d6ed988 ++0, 57510, 7866, 0x9965cf24 ++0, 63900, 7866, 0x9a12db24 ++0, 70290, 7866, 0x2e85cfeb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa8 2012-05-14 14:08:55.640366266 +0200 +@@ -0,0 +1,36 @@ ++0, 0, 134724, 0x53784ca9 ++0, 6390, 134724, 0x14c345b7 ++0, 12780, 134724, 0xe0d0dd51 ++0, 19170, 134724, 0xd53b5610 ++0, 25560, 134724, 0x7cbb8d47 ++0, 31950, 134724, 0x875d67c4 ++0, 38340, 134724, 0x9811c085 ++0, 44730, 134724, 0x25f6d228 ++0, 51120, 134724, 0x349495a0 ++0, 57510, 134724, 0xd0d75311 ++0, 63900, 134724, 0xb49cdfbb ++0, 70290, 134724, 0x9fa69518 ++0, 76680, 134724, 0x28a1f58c ++0, 83070, 134724, 0xb8dab657 ++0, 89460, 134724, 0x8c7e3b3b ++0, 95850, 134724, 0x37268acf ++0, 102240, 134724, 0xcce8ca02 ++0, 108630, 134724, 0xe0fd0c28 ++0, 115020, 134724, 0x5bdac906 ++0, 121410, 134724, 0xdd850bf0 ++0, 127800, 134724, 0x2002a228 ++0, 134190, 134724, 0x633617ea ++0, 140580, 134724, 0x2a3ef337 ++0, 146970, 134724, 0x507886c3 ++0, 153360, 134724, 0x51c0f07b ++0, 159750, 134724, 0x5e73dce1 ++0, 166140, 134724, 0x26acc6f0 ++0, 172530, 134724, 0x360c4349 ++0, 178920, 134724, 0xc7dbabd4 ++0, 185310, 134724, 0x671bbf66 ++0, 191700, 134724, 0x4d44df79 ++0, 198090, 134724, 0x69eade5b ++0, 204480, 134724, 0x2b1bca82 ++0, 210870, 134724, 0x8b16af47 ++0, 217260, 134724, 0xb59fa1bd ++0, 223650, 134724, 0x2ec17c24 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa9 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa9 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dfa9 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dfa9 2012-05-14 14:08:55.641366286 +0200 +@@ -0,0 +1,6 @@ ++0, 0, 228150, 0xde68df49 ++0, 6390, 228150, 0x8e12bcaf ++0, 12780, 228150, 0x851b04f7 ++0, 19170, 228150, 0x7e5e0950 ++0, 25560, 228150, 0x1d92219f ++0, 31950, 228150, 0x93caa693 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-idroq xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-idroq +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-idroq 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-idroq 2012-05-14 14:08:55.642366306 +0200 +@@ -0,0 +1,377 @@ ++0, 0, 393216, 0x56995aac ++1, 0, 29824, 0x77e265b7 ++0, 3000, 393216, 0xf9ed5d6c ++0, 6000, 393216, 0xd3285d75 ++0, 9000, 393216, 0x82d15d62 ++0, 12000, 393216, 0x893e5d6f ++0, 15000, 393216, 0x82d15d62 ++0, 18000, 393216, 0x893e5d6f ++0, 21000, 393216, 0x82d15d62 ++0, 24000, 393216, 0x893e5d6f ++0, 27000, 393216, 0x82d15d62 ++0, 30000, 393216, 0x893e5d6f ++1, 30433, 2944, 0x8dcdf50b ++0, 33000, 393216, 0x82d15d62 ++1, 33437, 2944, 0xb135cd2a ++0, 36000, 393216, 0x893e5d6f ++1, 36441, 2944, 0x54a6e73f ++0, 39000, 393216, 0x82d15d62 ++1, 39445, 2944, 0x050ccd4e ++0, 42000, 393216, 0x893e5d6f ++1, 42449, 2944, 0x6b68db44 ++0, 45000, 393216, 0x82d15d62 ++1, 45453, 2944, 0x55d1f308 ++0, 48000, 393216, 0x2ae39eca ++1, 48457, 2944, 0x7e92f50b ++0, 51000, 393216, 0x9254be70 ++1, 51461, 2944, 0xe9e91eed ++0, 54000, 393216, 0x4b2ed384 ++1, 54465, 2944, 0x80af2ce0 ++0, 57000, 393216, 0xbbd9d8f7 ++1, 57469, 2944, 0xc67ffb07 ++0, 60000, 393216, 0x1f2be0c3 ++1, 60473, 2944, 0x7aaded27 ++0, 63000, 393216, 0x2434eb25 ++1, 63478, 2944, 0x14a024fd ++0, 66000, 393216, 0xa6cced4e ++1, 66482, 2944, 0x26e8df1f ++0, 69000, 393216, 0xd116f38b ++1, 69486, 2944, 0x2688df44 ++0, 72000, 393216, 0x6b86f380 ++1, 72490, 2944, 0x4b9cdd33 ++0, 75000, 393216, 0xc1b3f8e9 ++1, 75494, 2944, 0x10c2f11c ++0, 78000, 393216, 0x2993fd5d ++1, 78498, 2944, 0xc4e3ad6d ++0, 81000, 393216, 0xf489fe18 ++1, 81502, 2944, 0xbeb1a78e ++0, 84000, 393216, 0x9ef10501 ++1, 84506, 2944, 0x283d4e7f ++0, 87000, 393216, 0x8faf0512 ++1, 87510, 2944, 0x4acf65e0 ++0, 90000, 393216, 0xa54d0736 ++1, 90514, 2944, 0x0ca29b8c ++0, 93000, 393216, 0xf4ef01e0 ++1, 93518, 2944, 0x003fae34 ++0, 96000, 393216, 0xe241ef51 ++1, 96522, 2944, 0x2acfec7e ++0, 99000, 393216, 0xcc38e51f ++1, 99527, 2944, 0xea6fc6fe ++0, 102000, 393216, 0xb1345876 ++1, 102531, 2944, 0xf5daec2f ++0, 105000, 393216, 0xf9b0968b ++1, 105535, 2944, 0x8d33ed7a ++0, 108000, 393216, 0x6bb1523f ++1, 108539, 2944, 0xc328f984 ++0, 111000, 393216, 0x83469a05 ++1, 111543, 2944, 0x6e0b58d3 ++0, 114000, 393216, 0x73e30882 ++1, 114547, 2944, 0xe282dc3f ++0, 117000, 393216, 0x8673da66 ++1, 117551, 2944, 0xbf9bf3e6 ++0, 120000, 393216, 0xb67596d3 ++1, 120555, 2944, 0xd7b7d7e3 ++0, 123000, 393216, 0xf7638710 ++1, 123559, 2944, 0x4e87b6ab ++0, 126000, 393216, 0x813a8f47 ++1, 126563, 2944, 0x7b8ce8d6 ++0, 129000, 393216, 0xb3526555 ++1, 129567, 2944, 0xd42991a5 ++0, 132000, 393216, 0x1b167be3 ++1, 132571, 2944, 0x452c98ca ++0, 135000, 393216, 0x99114562 ++1, 135576, 2944, 0x6d27832d ++0, 138000, 393216, 0xfafb0693 ++1, 138580, 2944, 0xa558720e ++0, 141000, 393216, 0x121d96c8 ++1, 141584, 2944, 0x0a31bec0 ++0, 144000, 393216, 0xb3c68c5d ++1, 144588, 2944, 0x28431384 ++0, 147000, 393216, 0x2035b97f ++1, 147592, 2944, 0xd5e9fb3d ++0, 150000, 393216, 0xfbcaeb62 ++1, 150596, 2944, 0x34f0e9f8 ++0, 153000, 393216, 0xfd5aea5d ++1, 153600, 2944, 0x979432df ++0, 156000, 393216, 0x66efbddd ++1, 156604, 2944, 0xb00acd4d ++0, 159000, 393216, 0xf1e17862 ++1, 159608, 2944, 0x726bffd6 ++0, 162000, 393216, 0x27fa584d ++1, 162612, 2944, 0xa1f39a6d ++0, 165000, 393216, 0xe644ec5f ++1, 165616, 2944, 0xf6a8e30e ++0, 168000, 393216, 0x7e3067ba ++1, 168620, 2944, 0x608e9e06 ++0, 171000, 393216, 0x1b6ba6fd ++1, 171624, 2944, 0x4ec58bc3 ++0, 174000, 393216, 0x55bdba34 ++1, 174629, 2944, 0x6d5c8458 ++0, 177000, 393216, 0xc67db2e4 ++1, 177633, 2944, 0x76a0abbd ++0, 180000, 393216, 0x359de8a2 ++1, 180637, 2944, 0xf830e8a6 ++0, 183000, 393216, 0x7b7a32ef ++1, 183641, 2944, 0x1bdd7bec ++0, 186000, 393216, 0xbe512a66 ++1, 186645, 2944, 0x3c1bd187 ++0, 189000, 393216, 0x681d82bf ++1, 189649, 2944, 0xf52cf697 ++0, 192000, 393216, 0xa2320ec5 ++1, 192653, 2944, 0x8f65b773 ++0, 195000, 393216, 0xcfbd9954 ++1, 195657, 2944, 0xf8b5b598 ++0, 198000, 393216, 0x7fee9854 ++1, 198661, 2944, 0xcd87d5ed ++0, 201000, 393216, 0x70eec155 ++1, 201665, 2944, 0x672ac02a ++0, 204000, 393216, 0x114f684e ++1, 204669, 2944, 0x1d5d13ed ++0, 207000, 393216, 0xe27f034f ++1, 207673, 2944, 0xe298e3d4 ++0, 210000, 393216, 0xfbbd89b4 ++1, 210678, 2944, 0x3d2e9c32 ++0, 213000, 393216, 0xcef4c58a ++1, 213682, 2944, 0xf3a39259 ++0, 216000, 393216, 0x9eea88e9 ++1, 216686, 2944, 0x930ae8f8 ++0, 219000, 393216, 0x911cea42 ++1, 219690, 2944, 0x8562aff7 ++0, 222000, 393216, 0xec5727ea ++1, 222694, 2944, 0x9cd6c6a7 ++0, 225000, 393216, 0xda998c33 ++1, 225698, 2944, 0x2709dc5c ++0, 228000, 393216, 0xc82140ed ++1, 228702, 2944, 0xcbe31816 ++0, 231000, 393216, 0x4caa8591 ++1, 231706, 2944, 0xd7876ec4 ++0, 234000, 393216, 0x4944206c ++1, 234710, 2944, 0xc2468b6a ++0, 237000, 393216, 0xd4676a94 ++1, 237714, 2944, 0x76043e84 ++0, 240000, 393216, 0x9e0340b3 ++1, 240718, 2944, 0xd2c35bf0 ++0, 243000, 393216, 0xbdef7f94 ++1, 243722, 2944, 0x63de6061 ++0, 246000, 393216, 0xfac05cb0 ++1, 246727, 2944, 0xd8f6ed1d ++0, 249000, 393216, 0xfef5a369 ++1, 249731, 2944, 0xe034928a ++0, 252000, 393216, 0x9fcb3711 ++1, 252735, 2944, 0xa044da74 ++0, 255000, 393216, 0x6d93f761 ++1, 255739, 2944, 0xee410dba ++0, 258000, 393216, 0xe95dc1ae ++1, 258743, 2944, 0x8e020c7c ++0, 261000, 393216, 0x3e561557 ++1, 261747, 2944, 0x73057ddb ++0, 264000, 393216, 0x0fa7a049 ++1, 264751, 2944, 0xdee5cc18 ++0, 267000, 393216, 0xf16afb95 ++1, 267755, 2944, 0xf4d31dec ++0, 270000, 393216, 0xe53a2064 ++1, 270759, 2944, 0xe8131e1c ++0, 273000, 393216, 0x57f046a4 ++1, 273763, 2944, 0x8ae69c95 ++0, 276000, 393216, 0xf6f16a0c ++1, 276767, 2944, 0x791c0bf4 ++0, 279000, 393216, 0xcba0c8b0 ++1, 279771, 2944, 0xd45a10db ++0, 282000, 393216, 0x5bdbe522 ++1, 282776, 2944, 0x3a72b010 ++0, 285000, 393216, 0x0fed0151 ++1, 285780, 2944, 0x6a4a0411 ++0, 288000, 393216, 0xbf86faf8 ++1, 288784, 2944, 0xd77ab7f5 ++0, 291000, 393216, 0x39854c5f ++1, 291788, 2944, 0xe3bf4fe5 ++0, 294000, 393216, 0xd9b7760a ++1, 294792, 2944, 0x12db1be8 ++0, 297000, 393216, 0x8edcc1d9 ++1, 297796, 2944, 0x345210b0 ++0, 300000, 393216, 0x44ae1435 ++1, 300800, 2944, 0xcfc1f892 ++0, 303000, 393216, 0xbc3d6d73 ++1, 303804, 2944, 0x5b0a80bb ++0, 306000, 393216, 0xedd82647 ++1, 306808, 2944, 0x31ab1168 ++0, 309000, 393216, 0x1c2e5ce3 ++1, 309812, 2944, 0xd4a4bb0a ++0, 312000, 393216, 0x04e29afe ++1, 312816, 2944, 0x8e211c8f ++0, 315000, 393216, 0xb191578e ++1, 315820, 2944, 0xcf464d50 ++0, 318000, 393216, 0x31d75a06 ++1, 318824, 2944, 0xe74ff3d6 ++0, 321000, 393216, 0xfdb6c56e ++1, 321829, 2944, 0x6274635f ++0, 324000, 393216, 0xf528f484 ++1, 324833, 2944, 0xc34c9f64 ++0, 327000, 393216, 0x87af758e ++1, 327837, 2944, 0xbb997537 ++0, 330000, 393216, 0xc8bdafb7 ++1, 330841, 2944, 0x3600da72 ++0, 333000, 393216, 0x573afe93 ++1, 333845, 2944, 0x343e15f4 ++0, 336000, 393216, 0xb03cb8f5 ++1, 336849, 2944, 0x17bc58a8 ++0, 339000, 393216, 0x6e03ac71 ++1, 339853, 2944, 0x3dcbd3ff ++0, 342000, 393216, 0xf919164e ++1, 342857, 2944, 0x1d422371 ++0, 345000, 393216, 0x80059f3c ++1, 345861, 2944, 0xe2b83d9d ++0, 348000, 393216, 0xf4ea0b1a ++1, 348865, 2944, 0x65388409 ++0, 351000, 393216, 0xe7720ffb ++1, 351869, 2944, 0xafbca269 ++0, 354000, 393216, 0x1ec0cd56 ++1, 354873, 2944, 0x2d00c0fb ++0, 357000, 393216, 0x2bc8cf18 ++1, 357878, 2944, 0xbac9c503 ++0, 360000, 393216, 0xe0bf17b5 ++1, 360882, 2944, 0x9990768d ++0, 363000, 393216, 0x660247e1 ++1, 363886, 2944, 0x8ba978be ++0, 366000, 393216, 0xcf66f2a9 ++1, 366890, 2944, 0x5a44a2f5 ++0, 369000, 393216, 0x5494d5ab ++1, 369894, 2944, 0xa4b6f3b8 ++0, 372000, 393216, 0x2c02f2c4 ++1, 372898, 2944, 0x631b6b9f ++0, 375000, 393216, 0x93fa3783 ++1, 375902, 2944, 0x4c840923 ++0, 378000, 393216, 0x4cc50633 ++1, 378906, 2944, 0x7c105df3 ++0, 381000, 393216, 0x3f179386 ++1, 381910, 2944, 0x01bcb213 ++0, 384000, 393216, 0x2bca9e1b ++1, 384914, 2944, 0x95cffbf7 ++0, 387000, 393216, 0x3e4af867 ++1, 387918, 2944, 0x170a9c3a ++0, 390000, 393216, 0x7e7df93c ++1, 390922, 2944, 0x59e09d61 ++0, 393000, 393216, 0x577e4fb0 ++1, 393927, 2944, 0x3ea0f205 ++0, 396000, 393216, 0x34487f0a ++1, 396931, 2944, 0xd9ea1a3a ++0, 399000, 393216, 0x0937bcfc ++1, 399935, 2944, 0xaf32d704 ++0, 402000, 393216, 0xa9e75a5e ++1, 402939, 2944, 0x2d473392 ++0, 405000, 393216, 0xf7bc0c89 ++1, 405943, 2944, 0x2a8ec544 ++0, 408000, 393216, 0x06dacca6 ++1, 408947, 2944, 0x883c8838 ++0, 411000, 393216, 0x7baaa4bd ++1, 411951, 2944, 0xfaf4d789 ++0, 414000, 393216, 0x95477f5f ++1, 414955, 2944, 0xcb315b65 ++0, 417000, 393216, 0x51117526 ++1, 417959, 2944, 0x980c93b0 ++0, 420000, 393216, 0x69656d03 ++1, 420963, 2944, 0x0819583b ++0, 423000, 393216, 0xcbd061bb ++1, 423967, 2944, 0xf126e5b5 ++0, 426000, 393216, 0x8d1d5be2 ++1, 426971, 2944, 0x88836255 ++0, 429000, 393216, 0x43e55930 ++1, 429976, 2944, 0xc8ae8ca8 ++0, 432000, 393216, 0xb56f5872 ++1, 432980, 2944, 0xf0750551 ++0, 435000, 393216, 0x09a255e9 ++1, 435984, 2944, 0x3dfe13a3 ++0, 438000, 393216, 0xcaaa5456 ++1, 438988, 2944, 0xf2aa957b ++0, 441000, 393216, 0xd267501f ++1, 441992, 2944, 0xa77b79a3 ++0, 444000, 393216, 0x7bef4eca ++1, 444996, 2944, 0xb1038284 ++0, 447000, 393216, 0x9aa94af3 ++1, 448000, 2944, 0xf96be3ba ++0, 450000, 393216, 0xd39d4a29 ++1, 451004, 2944, 0x1ae6e293 ++0, 453000, 393216, 0x7a754960 ++1, 454008, 2944, 0x2059d020 ++0, 456000, 393216, 0x3f004921 ++1, 457012, 2944, 0x7e6c9996 ++0, 459000, 393216, 0x0f784ca8 ++1, 460016, 2944, 0x3108b540 ++0, 462000, 393216, 0x2a062c70 ++1, 463020, 2944, 0x75133155 ++0, 465000, 393216, 0x114ef770 ++1, 466024, 2944, 0x59a19226 ++0, 468000, 393216, 0xfb7673bf ++1, 469029, 2944, 0x3140c138 ++0, 471000, 393216, 0xbaea88f7 ++1, 472033, 2944, 0x7570d3be ++0, 474000, 393216, 0x6fdfe2ec ++1, 475037, 2944, 0x54fd4ff6 ++0, 477000, 393216, 0xb7b2b398 ++1, 478041, 2944, 0x23bcf6dc ++0, 480000, 393216, 0x14ba127e ++1, 481045, 2944, 0x2d26489b ++0, 483000, 393216, 0x660b3041 ++1, 484049, 2944, 0x4b37bf13 ++0, 486000, 393216, 0xe3f3302a ++1, 487053, 2944, 0x12812ec9 ++0, 489000, 393216, 0x34c7f1c9 ++1, 490057, 2944, 0xc4a609dd ++0, 492000, 393216, 0xa8257bf4 ++1, 493061, 2944, 0x5a8c5b20 ++0, 495000, 393216, 0xd63fc649 ++1, 496065, 2944, 0xd05d110f ++0, 498000, 393216, 0xf8e5b79c ++1, 499069, 2944, 0xceea6f1f ++0, 501000, 393216, 0xa67b52ab ++1, 502073, 2944, 0x4033b0a5 ++0, 504000, 393216, 0xef8f9c74 ++1, 505078, 2944, 0x101895ce ++0, 507000, 393216, 0x6d3aa6b6 ++1, 508082, 2944, 0xd6c6809f ++0, 510000, 393216, 0x8c174ee6 ++1, 511086, 2944, 0x197bda7e ++0, 513000, 393216, 0x2dfbc524 ++1, 514090, 2944, 0x96fb3e4b ++0, 516000, 393216, 0x7d0808b6 ++1, 517094, 2944, 0x12a6e3de ++0, 519000, 393216, 0x6cbdf6f5 ++1, 520098, 2944, 0xfb80e466 ++0, 522000, 393216, 0xfe39bc53 ++1, 523102, 2944, 0xedb8c2fc ++0, 525000, 393216, 0xa3d869b0 ++1, 526106, 1016, 0x30e56ca5 ++0, 528000, 393216, 0x09f00057 ++0, 531000, 393216, 0x6ba56343 ++0, 534000, 393216, 0xb696ca3e ++0, 537000, 393216, 0x4eba0225 ++0, 540000, 393216, 0xdd45464b ++0, 543000, 393216, 0x2909a9ea ++0, 546000, 393216, 0x12aa3f85 ++0, 549000, 393216, 0x59421352 ++0, 552000, 393216, 0x57ea0313 ++0, 555000, 393216, 0x4e5f3a38 ++0, 558000, 393216, 0x55bc932d ++0, 561000, 393216, 0x666ee55d ++0, 564000, 393216, 0xb0f84a69 ++0, 567000, 393216, 0xad3ae63f ++0, 570000, 393216, 0x970fd47d ++0, 573000, 393216, 0x86c418e0 ++0, 576000, 393216, 0x52c9ce50 ++0, 579000, 393216, 0xd54c98c8 ++0, 582000, 393216, 0xb40e5fea ++0, 585000, 393216, 0x2aa74875 ++0, 588000, 393216, 0x305b251e ++0, 591000, 393216, 0xab8c0780 ++0, 594000, 393216, 0x0101dd0e ++0, 597000, 393216, 0x23739cab ++0, 600000, 393216, 0xf05196a0 ++0, 603000, 393216, 0x932d1e00 ++0, 606000, 393216, 0x932d1e00 ++0, 609000, 393216, 0x932d1e00 ++0, 612000, 393216, 0x932d1e00 ++0, 615000, 393216, 0x932d1e00 ++0, 618000, 393216, 0x932d1e00 ++0, 621000, 393216, 0x932d1e00 ++0, 624000, 393216, 0x932d1e00 ++0, 627000, 393216, 0x932d1e00 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-sierra xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-sierra +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-sierra 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-sierra 2012-05-14 14:08:55.642366306 +0200 +@@ -0,0 +1 @@ ++a99402e1f1a0f137608898251b3f309b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-xan xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-xan +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dpcm-xan 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dpcm-xan 2012-05-14 14:08:55.643366327 +0200 +@@ -0,0 +1 @@ ++b6da857766896ab10bb900004f915053 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-dk3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-dk3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-dk3 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-dk3 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-62fbe4db4a49cb044f57f92cce9993c5 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-dk4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-dk4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-dk4 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-dk4 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-5234b53dde4961dd715a2524d6a8eb75 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-tm2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-tm2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/duck-tm2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/duck-tm2 1970-01-01 01:00:00.000000000 +0100 +@@ -1,30 +0,0 @@ +-0, 0, 230400, 0x135cb509 +-0, 6000, 230400, 0x919a1ab7 +-0, 12000, 230400, 0x0af8722b +-0, 18000, 230400, 0xc9616809 +-0, 24000, 230400, 0xe16ecaf7 +-0, 30000, 230400, 0xa86f8d1b +-0, 36000, 230400, 0xd351b5a4 +-0, 42000, 230400, 0xd112b5b7 +-0, 48000, 230400, 0xc9c3c9b1 +-0, 54000, 230400, 0x4f91e572 +-0, 60000, 230400, 0xb1d8c4d3 +-0, 66000, 230400, 0x34de10c1 +-0, 72000, 230400, 0xbd4f3b29 +-0, 78000, 230400, 0xfeaf1477 +-0, 84000, 230400, 0x718ffa17 +-0, 90000, 230400, 0x23b46ef3 +-0, 96000, 230400, 0x6346d9b8 +-0, 102000, 230400, 0xdb66bf57 +-0, 108000, 230400, 0xeb74a2ff +-0, 114000, 230400, 0xe0750470 +-0, 120000, 230400, 0x645eb109 +-0, 126000, 230400, 0xbb96489a +-0, 132000, 230400, 0x58a70e35 +-0, 138000, 230400, 0xc7563441 +-0, 144000, 230400, 0x6098f07e +-0, 150000, 230400, 0x579ece15 +-0, 156000, 230400, 0xe1ca8d03 +-0, 162000, 230400, 0x8928cf34 +-0, 168000, 230400, 0xf621620e +-0, 174000, 230400, 0x98a344ea +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dxa-feeble xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dxa-feeble +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dxa-feeble 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dxa-feeble 2012-05-14 14:08:55.644366347 +0200 +@@ -0,0 +1,64 @@ ++0, 0, 921600, 0x0d03844f ++1, 0, 1000, 0x64cd9403 ++1, 4082, 1000, 0xa4ef8a9d ++1, 8163, 1000, 0x75c19868 ++0, 9000, 921600, 0x0d03844f ++1, 12245, 1000, 0x93db6f79 ++1, 16327, 1000, 0x6835625d ++0, 18000, 921600, 0x649cdcea ++1, 20408, 1000, 0xb3affa8f ++1, 24490, 1000, 0x159fdcc8 ++0, 27000, 921600, 0x649cdcea ++1, 28571, 1000, 0x79f9f7f1 ++1, 32653, 1000, 0xd7d1131e ++0, 36000, 921600, 0x9c7f22e8 ++1, 36735, 1000, 0x52a6f797 ++1, 40816, 1000, 0x748202ca ++1, 44898, 1000, 0x0ef92449 ++0, 45000, 921600, 0x9c7f22e8 ++1, 48980, 1000, 0x6a3760ab ++1, 53061, 1000, 0xce5c5abf ++0, 54000, 921600, 0x3451514a ++1, 57143, 1000, 0x23396792 ++1, 61224, 1000, 0xa5276238 ++0, 63000, 921600, 0x3451514a ++1, 65306, 1000, 0x288adf1b ++1, 69388, 1000, 0xe7de6fb2 ++0, 72000, 921600, 0x8f19f600 ++1, 73469, 1000, 0x2c2c707f ++1, 77551, 1000, 0xd66d6daf ++0, 81000, 921600, 0x8f19f600 ++1, 81633, 1000, 0xbcea7d64 ++1, 85714, 1000, 0x766feea5 ++1, 89796, 1000, 0xd2e1d63a ++0, 90000, 921600, 0x07e7445b ++1, 93878, 1000, 0x2f7ef4ed ++1, 97959, 1000, 0xb655cba4 ++0, 99000, 921600, 0x07e7445b ++1, 102041, 1000, 0x4507d37b ++1, 106122, 1000, 0x0c57f794 ++0, 108000, 921600, 0x873d1227 ++1, 110204, 1000, 0x0ecbe5cc ++1, 114286, 1000, 0x9bf6e345 ++0, 117000, 921600, 0x873d1227 ++1, 118367, 1000, 0xc461443c ++1, 122449, 1000, 0xad9657bf ++0, 126000, 921600, 0xbef62d86 ++1, 126531, 1000, 0x466fe91c ++1, 130612, 1000, 0x9ee377fe ++1, 134694, 1000, 0x09956428 ++0, 135000, 921600, 0xbef62d86 ++1, 138776, 1000, 0x9b285f0a ++1, 142857, 1000, 0x0a3e61a6 ++0, 144000, 921600, 0xcf84fee4 ++1, 146939, 1000, 0xacc25d6b ++1, 151020, 1000, 0x377be319 ++0, 153000, 921600, 0xcf84fee4 ++1, 155102, 1000, 0xe4890504 ++1, 159184, 1000, 0xe90a6497 ++0, 162000, 921600, 0x5639e670 ++1, 163265, 1000, 0xd00fe950 ++1, 167347, 1000, 0xf195eb44 ++0, 171000, 921600, 0x5639e670 ++1, 171429, 1000, 0xa491f3ef ++1, 175510, 1000, 0x2c036e18 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dxtory xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dxtory +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/dxtory 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/dxtory 2012-05-14 14:08:55.645366367 +0200 +@@ -0,0 +1 @@ ++0, 0, 1382400, 0x44373645 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ea-mad-adpcm-ea-r1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ea-mad-adpcm-ea-r1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ea-mad-adpcm-ea-r1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ea-mad-adpcm-ea-r1 1970-01-01 01:00:00.000000000 +0100 +@@ -1,191 +0,0 @@ +-0, 0, 535680, 0x889c32cf +-1, 0, 6496, 0x00000000 +-0, 2970, 535680, 0x0b1ef044 +-1, 3045, 6384, 0x00000000 +-0, 5940, 535680, 0xa7d0818b +-1, 6038, 6384, 0x00000000 +-0, 8910, 535680, 0xf392e4e1 +-1, 9030, 6384, 0x00000000 +-0, 11880, 535680, 0x08480c69 +-1, 12023, 6384, 0x00000000 +-0, 14850, 535680, 0x2b8af1ed +-1, 15015, 6496, 0xe2034d04 +-0, 17820, 535680, 0x0d58e062 +-1, 18060, 6384, 0x089c9157 +-0, 20790, 535680, 0xd140ced0 +-1, 21053, 6384, 0xeed5743c +-0, 23760, 535680, 0xbd0e6652 +-1, 24045, 6384, 0x71de6b34 +-0, 26730, 535680, 0xdc2f2a6b +-1, 27038, 6384, 0xc0d67710 +-0, 29700, 535680, 0x97c31a38 +-1, 30030, 6496, 0x35786490 +-0, 32670, 535680, 0x1a2bdf38 +-1, 33075, 6384, 0xdf1c99a2 +-0, 35640, 535680, 0xb3af3ac4 +-1, 36068, 6384, 0xca9591ad +-0, 38610, 535680, 0x07a52577 +-1, 39060, 6384, 0x6f0d9c3d +-0, 41580, 535680, 0x78407368 +-1, 42053, 6384, 0xfacbbaee +-0, 44550, 535680, 0xd2a9efc3 +-1, 45045, 6496, 0x927fb136 +-0, 47520, 535680, 0x36df2f29 +-1, 48090, 6384, 0x9d4f2572 +-0, 50490, 535680, 0x9821d8f7 +-1, 51083, 6384, 0x2a3c6d08 +-0, 53460, 535680, 0xf64321aa +-1, 54075, 6384, 0x4282b1e0 +-0, 56430, 535680, 0x53e4d9aa +-1, 57068, 6384, 0xc4a77b9f +-0, 59400, 535680, 0xdbd6f853 +-1, 60060, 6496, 0x2af6a14f +-0, 62370, 535680, 0x5d40cf8b +-1, 63105, 6384, 0x4d734169 +-0, 65340, 535680, 0xe624af9d +-1, 66098, 6384, 0xb91b5865 +-0, 68310, 535680, 0xd9dbb4cd +-1, 69090, 6384, 0x9dce2417 +-0, 71280, 535680, 0xf14e72ec +-1, 72083, 6384, 0xb7c4e1ce +-0, 74250, 535680, 0xb35c18f6 +-1, 75075, 6496, 0xef0dc07a +-0, 77220, 535680, 0xc96d7757 +-1, 78120, 6384, 0x4ad21d10 +-0, 80190, 535680, 0xdfb937df +-1, 81113, 6384, 0xcfe14682 +-0, 83160, 535680, 0x40cd71d7 +-1, 84105, 6384, 0x07be48eb +-0, 86130, 535680, 0x15e176d6 +-1, 87098, 6384, 0x09de3498 +-0, 89100, 535680, 0x7f891b24 +-1, 90090, 6496, 0xab2e9686 +-0, 92070, 535680, 0xb87a8c32 +-1, 93135, 6384, 0x3aba3ccc +-0, 95040, 535680, 0x0c01541f +-1, 96128, 6384, 0x0a905ec3 +-0, 98010, 535680, 0x9eee99b3 +-1, 99120, 6384, 0x76a93ce4 +-0, 100980, 535680, 0xd65eb689 +-1, 102113, 6384, 0xa99063a4 +-0, 103950, 535680, 0x6e733cfa +-1, 105105, 6496, 0xc16bb88d +-0, 106920, 535680, 0xac536670 +-1, 108150, 6384, 0x650379bf +-0, 109890, 535680, 0x002275b8 +-1, 111143, 6384, 0x4e0749fe +-0, 112860, 535680, 0x6a5385cb +-1, 114135, 6384, 0x778e8d12 +-0, 115830, 535680, 0xd129ade3 +-1, 117128, 6384, 0x9fa8c494 +-0, 118800, 535680, 0x32cab5d7 +-1, 120120, 6496, 0x61d5bead +-0, 121770, 535680, 0x08be1c8f +-1, 123165, 6384, 0x4da9bc3c +-0, 124740, 535680, 0x59e1fba0 +-1, 126158, 6384, 0xa72b6f93 +-0, 127710, 535680, 0x138aee3a +-1, 129150, 6384, 0x811f5f77 +-0, 130680, 535680, 0x4cfbcd5e +-1, 132143, 6384, 0x83ea5e3d +-0, 133650, 535680, 0xf6cf0fb4 +-1, 135135, 6496, 0x78bab460 +-0, 136620, 535680, 0xb13a06de +-1, 138180, 6384, 0xc9a07432 +-0, 139590, 535680, 0x59176f00 +-1, 141173, 6384, 0x4b4f2a34 +-0, 142560, 535680, 0xf84b4ca3 +-1, 144165, 6384, 0x4d707a53 +-0, 145530, 535680, 0x7fd09f73 +-1, 147158, 6384, 0x703efb60 +-0, 148500, 535680, 0x3be383b8 +-1, 150150, 6496, 0x319a77bb +-0, 151470, 535680, 0xa7118e51 +-1, 153195, 6384, 0xbdfd82ec +-0, 154440, 535680, 0xbd83120c +-1, 156188, 6384, 0x413c3503 +-0, 157410, 535680, 0x3bc9d256 +-1, 159180, 6384, 0xe6e666b3 +-0, 160380, 535680, 0xb6c87f87 +-1, 162173, 6384, 0xa09c7342 +-0, 163350, 535680, 0xe80d110a +-1, 165165, 6496, 0x60cba846 +-0, 166320, 535680, 0xb3a83362 +-1, 168210, 6384, 0x0ba34308 +-0, 169290, 535680, 0xfb39eb52 +-1, 171203, 6384, 0xdc3a65f0 +-0, 172260, 535680, 0xbf6e1220 +-1, 174195, 6384, 0x1ebf9dc4 +-0, 175230, 535680, 0x9ecdfbae +-1, 177188, 6384, 0xbbcb1449 +-0, 178200, 535680, 0x069a65f5 +-1, 180180, 6496, 0x926574eb +-0, 181170, 535680, 0x206e372c +-1, 183225, 6384, 0xb4da92f1 +-0, 184140, 535680, 0x58c83dd4 +-1, 186218, 6384, 0xdbbd21e0 +-0, 187110, 535680, 0xc3562b03 +-1, 189210, 6384, 0x08510eff +-0, 190080, 535680, 0xd1ed85a0 +-1, 192203, 6384, 0x9534b7ca +-0, 193050, 535680, 0xb6205f4b +-1, 195195, 6496, 0x50a5ed30 +-0, 196020, 535680, 0xaedf8bfa +-1, 198240, 6384, 0xf5ac2f7c +-0, 198990, 535680, 0xa48d5dea +-1, 201233, 6384, 0x4fe1fa55 +-0, 201960, 535680, 0xff82e7c1 +-1, 204225, 6384, 0xd61c4c05 +-0, 204930, 535680, 0xc9560222 +-1, 207218, 6384, 0x56d11b45 +-0, 207900, 535680, 0x0fafa549 +-1, 210210, 6496, 0x3906084b +-0, 210870, 535680, 0x8d556ccb +-1, 213255, 6384, 0x1ef31fed +-0, 213840, 535680, 0x802aac1f +-1, 216248, 6384, 0x58ed82f5 +-0, 216810, 535680, 0x7d0fa168 +-1, 219240, 6384, 0xb31ccd1f +-0, 219780, 535680, 0x1a9255c9 +-1, 222233, 6384, 0xfb648285 +-0, 222750, 535680, 0xb4ec7e35 +-1, 225225, 6496, 0xfae2950b +-0, 225720, 535680, 0x48fac072 +-1, 228270, 6384, 0xe28c8357 +-0, 228690, 535680, 0x1e260135 +-1, 231263, 6384, 0xda718e60 +-0, 231660, 535680, 0xce4d5079 +-1, 234255, 6384, 0x27516999 +-0, 234630, 535680, 0x13e5e4ed +-1, 237248, 6384, 0x0ba07921 +-0, 237600, 535680, 0x592305ec +-1, 240240, 6496, 0xcfbecfab +-0, 240570, 535680, 0x9e227508 +-1, 243285, 6384, 0xae4cedcd +-0, 243540, 535680, 0x1d37e5ea +-1, 246278, 6384, 0x917b4707 +-0, 246510, 535680, 0x7eae7692 +-1, 249270, 6384, 0x8671b28e +-0, 249480, 535680, 0xf452e4b9 +-1, 252263, 6384, 0x9a1238fa +-0, 252450, 535680, 0x1460e7e9 +-1, 255255, 6496, 0x23b8f8ca +-0, 255420, 535680, 0xc6d8a638 +-1, 258300, 6384, 0x3903bcd6 +-0, 258390, 535680, 0x854f5fb0 +-1, 261293, 6384, 0x0532b267 +-0, 261360, 535680, 0x854f5fb0 +-1, 264285, 6384, 0xde931220 +-0, 264330, 535680, 0x70a02d87 +-1, 267278, 6384, 0x4ed70a80 +-0, 267300, 535680, 0x9a4ad464 +-0, 270270, 535680, 0x9a4ad464 +-1, 270270, 6496, 0x4a52d5a1 +-0, 273240, 535680, 0x9a4ad464 +-1, 273315, 6384, 0xc1be5760 +-0, 276210, 535680, 0x9a4ad464 +-1, 276308, 6384, 0x790d69ba +-0, 279180, 535680, 0x9a4ad464 +-1, 279300, 6384, 0x9d73e6cf +-0, 282150, 535680, 0x9a4ad464 +-1, 282293, 6272, 0xbc0fc725 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ea-tqi-adpcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ea-tqi-adpcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ea-tqi-adpcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ea-tqi-adpcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,52 +0,0 @@ +-0, 0, 115200, 0x375ec573 +-1, 0, 5936, 0x00000000 +-0, 6000, 115200, 0x375ec573 +-1, 6057, 5824, 0x00000000 +-0, 12000, 115200, 0x375ec573 +-1, 12000, 5936, 0x00000000 +-0, 18000, 115200, 0x375ec573 +-1, 18057, 5824, 0x00000000 +-0, 24000, 115200, 0x375ec573 +-1, 24000, 5936, 0x00000000 +-0, 30000, 115200, 0x375ec573 +-1, 30057, 5824, 0x00000000 +-0, 36000, 115200, 0x375ec573 +-1, 36000, 5936, 0x00000000 +-0, 42000, 115200, 0x375ec573 +-1, 42057, 5824, 0x0f06f5bb +-0, 48000, 115200, 0x0b4d31bf +-1, 48000, 5936, 0xb0dbfc46 +-0, 54000, 115200, 0xdd724598 +-1, 54057, 5824, 0x9daa9f9c +-0, 60000, 115200, 0xc3077e75 +-1, 60000, 5936, 0x61400d2f +-0, 66000, 115200, 0xbf70778a +-1, 66057, 5824, 0x34a5b0e3 +-0, 72000, 115200, 0x117eb766 +-1, 72000, 5936, 0x6e546f72 +-0, 78000, 115200, 0x4617fbad +-1, 78057, 5824, 0x4f093b35 +-0, 84000, 115200, 0x5f5b02d2 +-1, 84000, 5936, 0x95b5b599 +-0, 90000, 115200, 0x2a9c5325 +-1, 90057, 5824, 0x75e15e60 +-0, 96000, 115200, 0x14a89e2a +-1, 96000, 5936, 0xd1077d39 +-0, 102000, 115200, 0xe69aa994 +-1, 102057, 5824, 0x956e21ca +-0, 108000, 115200, 0xfbacf589 +-1, 108000, 5936, 0x33bac234 +-0, 114000, 115200, 0x1d714c6e +-1, 114057, 5824, 0x5df37824 +-0, 120000, 115200, 0x6eff66cb +-1, 120000, 5936, 0xc174af24 +-0, 126000, 115200, 0xee21c1cb +-1, 126057, 5824, 0xe5dc2159 +-0, 132000, 115200, 0xce714ada +-1, 132000, 5936, 0x63ffc8b1 +-0, 138000, 115200, 0xf89d56c3 +-1, 138057, 5824, 0xefe4c365 +-0, 144000, 115200, 0x65fd5e60 +-1, 144000, 5936, 0x2174304d +-0, 150000, 115200, 0x0c256424 +-0, 156000, 115200, 0xa9cdd8d2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/eval xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/eval +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/eval 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/eval 2012-05-14 14:08:55.646366387 +0200 +@@ -0,0 +1,173 @@ ++Evaluating '' ++'' -> nan ++ ++Evaluating '1;2' ++'1;2' -> 2.000000 ++ ++Evaluating '-20' ++'-20' -> -20.000000 ++ ++Evaluating '-PI' ++'-PI' -> -3.141593 ++ ++Evaluating '+PI' ++'+PI' -> 3.141593 ++ ++Evaluating '1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)' ++'1+(5-2)^(3-1)+1/2+sin(PI)-max(-2.2,-3.1)' -> 12.700000 ++ ++Evaluating '80G/80Gi' ++'80G/80Gi' -> 0.931323 ++ ++Evaluating '1k' ++'1k' -> 1000.000000 ++ ++Evaluating '1Gi' ++'1Gi' -> 1073741824.000000 ++ ++Evaluating '1gi' ++'1gi' -> nan ++ ++Evaluating '1GiFoo' ++'1GiFoo' -> nan ++ ++Evaluating '1k+1k' ++'1k+1k' -> 2000.000000 ++ ++Evaluating '1Gi*3foo' ++'1Gi*3foo' -> nan ++ ++Evaluating 'foo' ++'foo' -> nan ++ ++Evaluating 'foo(' ++'foo(' -> nan ++ ++Evaluating 'foo()' ++'foo()' -> nan ++ ++Evaluating 'foo)' ++'foo)' -> nan ++ ++Evaluating 'sin' ++'sin' -> nan ++ ++Evaluating 'sin(' ++'sin(' -> nan ++ ++Evaluating 'sin()' ++'sin()' -> nan ++ ++Evaluating 'sin)' ++'sin)' -> nan ++ ++Evaluating 'sin 10' ++'sin 10' -> nan ++ ++Evaluating 'sin(1,2,3)' ++'sin(1,2,3)' -> nan ++ ++Evaluating 'sin(1 )' ++'sin(1 )' -> 0.841471 ++ ++Evaluating '1' ++'1' -> 1.000000 ++ ++Evaluating '1foo' ++'1foo' -> nan ++ ++Evaluating 'bar + PI + E + 100f*2 + foo' ++'bar + PI + E + 100f*2 + foo' -> nan ++ ++Evaluating '13k + 12f - foo(1, 2)' ++'13k + 12f - foo(1, 2)' -> nan ++ ++Evaluating '1gi' ++'1gi' -> nan ++ ++Evaluating '1Gi' ++'1Gi' -> 1073741824.000000 ++ ++Evaluating 'st(0, 123)' ++'st(0, 123)' -> 123.000000 ++ ++Evaluating 'st(1, 123); ld(1)' ++'st(1, 123); ld(1)' -> 123.000000 ++ ++Evaluating 'st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)' ++'st(0, 1); while(lte(ld(0), 100), st(1, ld(1)+ld(0));st(0, ld(0)+1)); ld(1)' -> 4950.000000 ++ ++Evaluating 'st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)' ++'st(1, 1); st(2, 2); st(0, 1); while(lte(ld(0),10), st(3, ld(1)+ld(2)); st(1, ld(2)); st(2, ld(3)); st(0, ld(0)+1)); ld(3)' -> 144.000000 ++ ++Evaluating 'while(0, 10)' ++'while(0, 10)' -> nan ++ ++Evaluating 'st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))' ++'st(0, 1); while(lte(ld(0),100), st(1, ld(1)+ld(0)); st(0, ld(0)+1))' -> 100.000000 ++ ++Evaluating 'isnan(1)' ++'isnan(1)' -> 0.000000 ++ ++Evaluating 'isnan(NAN)' ++'isnan(NAN)' -> 1.000000 ++ ++Evaluating 'floor(NAN)' ++'floor(NAN)' -> nan ++ ++Evaluating 'floor(123.123)' ++'floor(123.123)' -> 123.000000 ++ ++Evaluating 'floor(-123.123)' ++'floor(-123.123)' -> -124.000000 ++ ++Evaluating 'trunc(123.123)' ++'trunc(123.123)' -> 123.000000 ++ ++Evaluating 'trunc(-123.123)' ++'trunc(-123.123)' -> -123.000000 ++ ++Evaluating 'ceil(123.123)' ++'ceil(123.123)' -> 124.000000 ++ ++Evaluating 'ceil(-123.123)' ++'ceil(-123.123)' -> -123.000000 ++ ++Evaluating 'sqrt(1764)' ++'sqrt(1764)' -> 42.000000 ++ ++Evaluating 'isnan(sqrt(-1))' ++'isnan(sqrt(-1))' -> 1.000000 ++ ++Evaluating 'not(1)' ++'not(1)' -> 0.000000 ++ ++Evaluating 'not(NAN)' ++'not(NAN)' -> 0.000000 ++ ++Evaluating 'not(0)' ++'not(0)' -> 1.000000 ++ ++Evaluating 'pow(0,1.23)' ++'pow(0,1.23)' -> 0.000000 ++ ++Evaluating 'pow(PI,1.23)' ++'pow(PI,1.23)' -> 4.087844 ++ ++Evaluating 'PI^1.23' ++'PI^1.23' -> 4.087844 ++ ++Evaluating 'pow(-1,1.23)' ++'pow(-1,1.23)' -> nan ++ ++Evaluating 'if(1, 2)' ++'if(1, 2)' -> 2.000000 ++ ++Evaluating 'ifnot(0, 23)' ++'ifnot(0, 23)' -> 23.000000 ++ ++Evaluating 'ifnot(1, NaN) + if(0, 1)' ++'ifnot(1, NaN) + if(0, 1)' -> 0.000000 ++ ++12.700000 == 12.7 ++0.931323 == 0.931322575 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fax-g3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fax-g3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fax-g3 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fax-g3 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-0, 0, 1000384, 0xb758eb8b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fax-g3s xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fax-g3s +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fax-g3s 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fax-g3s 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-0, 0, 1000384, 0xb758eb8b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/feeble-dxa xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/feeble-dxa +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/feeble-dxa 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/feeble-dxa 1970-01-01 01:00:00.000000000 +0100 +@@ -1,65 +0,0 @@ +-1, 0, 1000, 0x64cd9403 +-0, 0, 921600, 0x0d03844f +-1, 4082, 1000, 0xa4ef8a9d +-1, 8163, 1000, 0x75c19868 +-0, 9000, 921600, 0x0d03844f +-1, 12245, 1000, 0x93db6f79 +-1, 16327, 1000, 0x6835625d +-0, 18000, 921600, 0x649cdcea +-1, 20408, 1000, 0xb3affa8f +-1, 24490, 1000, 0x159fdcc8 +-0, 27000, 921600, 0x649cdcea +-1, 28571, 1000, 0x79f9f7f1 +-1, 32653, 1000, 0xd7d1131e +-0, 36000, 921600, 0x9c7f22e8 +-1, 36735, 1000, 0x52a6f797 +-1, 40816, 1000, 0x748202ca +-1, 44898, 1000, 0x0ef92449 +-0, 45000, 921600, 0x9c7f22e8 +-1, 48980, 1000, 0x6a3760ab +-1, 53061, 1000, 0xce5c5abf +-0, 54000, 921600, 0x3451514a +-1, 57143, 1000, 0x23396792 +-1, 61224, 1000, 0xa5276238 +-0, 63000, 921600, 0x3451514a +-1, 65306, 1000, 0x288adf1b +-1, 69388, 1000, 0xe7de6fb2 +-0, 72000, 921600, 0x8f19f600 +-1, 73469, 1000, 0x2c2c707f +-1, 77551, 1000, 0xd66d6daf +-0, 81000, 921600, 0x8f19f600 +-1, 81633, 1000, 0xbcea7d64 +-1, 85714, 1000, 0x766feea5 +-1, 89796, 1000, 0xd2e1d63a +-0, 90000, 921600, 0x07e7445b +-1, 93878, 1000, 0x2f7ef4ed +-1, 97959, 1000, 0xb655cba4 +-0, 99000, 921600, 0x07e7445b +-1, 102041, 1000, 0x4507d37b +-1, 106122, 1000, 0x0c57f794 +-0, 108000, 921600, 0x873d1227 +-1, 110204, 1000, 0x0ecbe5cc +-1, 114286, 1000, 0x9bf6e345 +-0, 117000, 921600, 0x873d1227 +-1, 118367, 1000, 0xc461443c +-1, 122449, 1000, 0xad9657bf +-0, 126000, 921600, 0xbef62d86 +-1, 126531, 1000, 0x466fe91c +-1, 130612, 1000, 0x9ee377fe +-1, 134694, 1000, 0x09956428 +-0, 135000, 921600, 0xbef62d86 +-1, 138776, 1000, 0x9b285f0a +-1, 142857, 1000, 0x0a3e61a6 +-0, 144000, 921600, 0xcf84fee4 +-1, 146939, 1000, 0xacc25d6b +-1, 151020, 1000, 0x377be319 +-0, 153000, 921600, 0xcf84fee4 +-1, 155102, 1000, 0xe4890504 +-1, 159184, 1000, 0xe90a6497 +-0, 162000, 921600, 0x5639e670 +-1, 163265, 1000, 0xd00fe950 +-1, 167347, 1000, 0xf195eb44 +-0, 171000, 921600, 0x5639e670 +-1, 171429, 1000, 0xa491f3ef +-1, 175510, 1000, 0x2c036e18 +-1, 179592, 1000, 0x52d65e2a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fifo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fifo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/fifo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/fifo 2012-05-14 14:08:55.648366427 +0200 +@@ -0,0 +1,27 @@ ++-12: 1 ++-11: 2 ++-10: 3 ++-9: 4 ++-8: 5 ++-7: 6 ++-6: 7 ++-5: 8 ++-4: 9 ++-3: 10 ++-2: 11 ++-1: 12 ++0: 0 ++1: 1 ++2: 2 ++3: 3 ++4: 4 ++5: 5 ++6: 6 ++7: 7 ++8: 8 ++9: 9 ++10: 10 ++11: 11 ++12: 12 ++ ++0 1 2 3 4 5 6 7 8 9 10 11 12 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/film-cvid-pcm-stereo-8bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/film-cvid-pcm-stereo-8bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/film-cvid-pcm-stereo-8bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/film-cvid-pcm-stereo-8bit 2012-05-14 14:08:55.649366447 +0200 +@@ -1,247 +1,139 @@ +-1, 0, 88192, 0x23bb50ae + 0, 0, 107520, 0xa6c9fdd2 ++1, 0, 88192, 0x23bb50ae + 0, 3000, 107520, 0x61eb28c1 + 0, 6000, 107520, 0x45e20af7 +-0, 9000, 107520, 0x45e20af7 +-0, 12000, 107520, 0x366970fc +-0, 15000, 107520, 0x366970fc +-0, 18000, 107520, 0xa392bcb3 +-0, 21000, 107520, 0xa392bcb3 +-0, 24000, 107520, 0xcf7bac98 +-0, 27000, 107520, 0xcf7bac98 +-0, 30000, 107520, 0x222eba53 +-0, 33000, 107520, 0x222eba53 +-0, 36000, 107520, 0x74e255a1 +-0, 39000, 107520, 0x74e255a1 +-0, 42000, 107520, 0xc19eec6f ++0, 9000, 107520, 0x366970fc ++0, 12000, 107520, 0xa392bcb3 ++0, 15000, 107520, 0xcf7bac98 ++0, 18000, 107520, 0x222eba53 ++0, 21000, 107520, 0x74e255a1 ++0, 24000, 107520, 0xc19eec6f ++0, 27000, 107520, 0xa3880681 ++0, 30000, 107520, 0x957878db ++0, 33000, 107520, 0x18340692 ++0, 36000, 107520, 0x9970f24d ++0, 39000, 107520, 0xf08618aa ++0, 42000, 107520, 0xee7324f0 + 1, 44996, 44112, 0x79600f01 +-0, 45000, 107520, 0xc19eec6f +-0, 48000, 107520, 0xa3880681 +-0, 51000, 107520, 0xa3880681 +-0, 54000, 107520, 0x957878db +-0, 57000, 107520, 0x957878db +-0, 60000, 107520, 0x18340692 +-0, 63000, 107520, 0x18340692 +-0, 66000, 107520, 0x9970f24d ++0, 45000, 107520, 0xe15025b3 ++0, 48000, 107520, 0x8afa312e ++0, 51000, 107520, 0x717a7d0f ++0, 54000, 107520, 0x355c6e23 ++0, 57000, 107520, 0x7015a50f ++0, 60000, 107520, 0xcdfc1a16 ++0, 63000, 107520, 0x38d929e7 ++0, 66000, 107520, 0x52913423 + 1, 67502, 44096, 0x09dbf7aa +-0, 69000, 107520, 0x9970f24d +-0, 72000, 107520, 0xf08618aa +-0, 75000, 107520, 0xf08618aa +-0, 78000, 107520, 0xee7324f0 +-0, 81000, 107520, 0xee7324f0 +-0, 84000, 107520, 0xe15025b3 +-0, 87000, 107520, 0xe15025b3 ++0, 69000, 107520, 0xe2c91c10 ++0, 72000, 107520, 0x85516e9c ++0, 75000, 107520, 0xd1626030 ++0, 78000, 107520, 0xea7b16de ++0, 81000, 107520, 0xa33eaa0d ++0, 84000, 107520, 0x8e3be6a6 ++0, 87000, 107520, 0x14147bd6 ++0, 90000, 107520, 0x07d54bec + 1, 90000, 44112, 0x18fed048 +-0, 90000, 107520, 0x8afa312e +-0, 93000, 107520, 0x8afa312e +-0, 96000, 107520, 0x717a7d0f +-0, 99000, 107520, 0x717a7d0f +-0, 102000, 107520, 0x355c6e23 +-0, 105000, 107520, 0x355c6e23 +-0, 108000, 107520, 0x7015a50f +-0, 111000, 107520, 0x7015a50f ++0, 93000, 107520, 0xe287a0a7 ++0, 96000, 107520, 0xc023a14d ++0, 99000, 107520, 0x2437085d ++0, 102000, 107520, 0x63823918 ++0, 105000, 107520, 0xbc17e198 ++0, 108000, 107520, 0x9d99bc81 ++0, 111000, 107520, 0x7e4ec71e + 1, 112506, 44112, 0x030d35ef +-0, 114000, 107520, 0xcdfc1a16 +-0, 117000, 107520, 0xcdfc1a16 +-0, 120000, 107520, 0x38d929e7 +-0, 123000, 107520, 0x38d929e7 +-0, 126000, 107520, 0x52913423 +-0, 129000, 107520, 0x52913423 +-0, 132000, 107520, 0xe2c91c10 +-0, 135000, 107520, 0xe2c91c10 ++0, 114000, 107520, 0x55b98376 ++0, 117000, 107520, 0x356d8e9e ++0, 120000, 107520, 0xf77e8a61 ++0, 123000, 107520, 0x5ae7c8c7 ++0, 126000, 107520, 0x8acf9322 ++0, 129000, 107520, 0x40a9177e ++0, 132000, 107520, 0x3e0e4d8d ++0, 135000, 107520, 0xd268865b + 1, 135012, 44112, 0xc23154d5 +-0, 138000, 107520, 0x85516e9c +-0, 141000, 107520, 0x85516e9c +-0, 144000, 107520, 0xd1626030 +-0, 147000, 107520, 0xd1626030 +-0, 150000, 107520, 0xea7b16de +-0, 153000, 107520, 0xea7b16de +-0, 156000, 107520, 0xa33eaa0d ++0, 138000, 107520, 0x89a4efeb ++0, 141000, 107520, 0x70ca2478 ++0, 144000, 107520, 0xcc9ec981 ++0, 147000, 107520, 0xf0648459 ++0, 150000, 107520, 0x7e4a4cca ++0, 153000, 107520, 0xb315dc65 ++0, 156000, 107520, 0x2aecc7b4 + 1, 157518, 44064, 0xe4713ee7 +-0, 159000, 107520, 0xa33eaa0d +-0, 162000, 107520, 0x8e3be6a6 +-0, 165000, 107520, 0x8e3be6a6 +-0, 168000, 107520, 0x14147bd6 +-0, 171000, 107520, 0x14147bd6 +-0, 174000, 107520, 0x07d54bec +-0, 177000, 107520, 0x07d54bec ++0, 159000, 107520, 0x81742f51 ++0, 162000, 107520, 0x3a1d7571 ++0, 165000, 107520, 0x3a1d7571 ++0, 168000, 107520, 0x3a1d7571 ++0, 171000, 107520, 0x3a1d7571 ++0, 174000, 107520, 0x3a1d7571 ++0, 177000, 107520, 0x3a1d7571 ++0, 180000, 107520, 0x3a1d7571 + 1, 180000, 44112, 0xddc19d91 +-0, 180000, 107520, 0xe287a0a7 +-0, 183000, 107520, 0xe287a0a7 +-0, 186000, 107520, 0xc023a14d +-0, 189000, 107520, 0xc023a14d +-0, 192000, 107520, 0x2437085d +-0, 195000, 107520, 0x2437085d +-0, 198000, 107520, 0x63823918 +-0, 201000, 107520, 0x63823918 ++0, 183000, 107520, 0xe974733e ++0, 186000, 107520, 0x999c6fbf ++0, 189000, 107520, 0x26b56b6e ++0, 192000, 107520, 0xc9f9647b ++0, 195000, 107520, 0x6d025d00 ++0, 198000, 107520, 0xf9c056c1 ++0, 201000, 107520, 0xa5cc4d0b + 1, 202506, 44112, 0x9591522d +-0, 204000, 107520, 0xbc17e198 +-0, 207000, 107520, 0xbc17e198 +-0, 210000, 107520, 0x9d99bc81 +-0, 213000, 107520, 0x9d99bc81 +-0, 216000, 107520, 0x7e4ec71e +-0, 219000, 107520, 0x7e4ec71e +-0, 222000, 107520, 0x55b98376 +-0, 225000, 107520, 0x55b98376 ++0, 204000, 107520, 0x1a4c4236 ++0, 207000, 107520, 0xa9d538b6 ++0, 210000, 107520, 0x14682d00 ++0, 213000, 107520, 0x6236204f ++0, 216000, 107520, 0x303e14aa ++0, 219000, 107520, 0x943b0837 ++0, 222000, 107520, 0xfce5fd07 ++0, 225000, 107520, 0xd993f193 + 1, 225012, 44112, 0x90deb013 +-0, 228000, 107520, 0x356d8e9e +-0, 231000, 107520, 0x356d8e9e +-0, 234000, 107520, 0xf77e8a61 +-0, 237000, 107520, 0xf77e8a61 +-0, 240000, 107520, 0x5ae7c8c7 +-0, 243000, 107520, 0x5ae7c8c7 +-0, 246000, 107520, 0x8acf9322 ++0, 228000, 107520, 0x4d48e7b4 ++0, 231000, 107520, 0x61ccdf83 ++0, 234000, 107520, 0xfb4fd608 ++0, 237000, 107520, 0x5efdcdb3 ++0, 240000, 107520, 0xb03ec886 ++0, 243000, 107520, 0xf464c343 ++0, 246000, 107520, 0xf464c343 + 1, 247518, 44064, 0x3842d420 +-0, 249000, 107520, 0x8acf9322 +-0, 252000, 107520, 0x40a9177e +-0, 255000, 107520, 0x40a9177e +-0, 258000, 107520, 0x3e0e4d8d +-0, 261000, 107520, 0x3e0e4d8d +-0, 264000, 107520, 0xd268865b +-0, 267000, 107520, 0xd268865b ++0, 249000, 107520, 0xf464c343 ++0, 252000, 107520, 0xf464c343 ++0, 255000, 107520, 0xf464c343 ++0, 258000, 107520, 0xf464c343 ++0, 261000, 107520, 0xf464c343 ++0, 264000, 107520, 0xf464c343 ++0, 267000, 107520, 0xf464c343 ++0, 270000, 107520, 0xf464c343 + 1, 270000, 44112, 0x99c8c3d9 +-0, 270000, 107520, 0x89a4efeb +-0, 273000, 107520, 0x89a4efeb +-0, 276000, 107520, 0x70ca2478 +-0, 279000, 107520, 0x70ca2478 +-0, 282000, 107520, 0xcc9ec981 +-0, 285000, 107520, 0xcc9ec981 +-0, 288000, 107520, 0xf0648459 +-0, 291000, 107520, 0xf0648459 ++0, 273000, 107520, 0xf464c343 ++0, 276000, 107520, 0xf2b2c712 ++0, 279000, 107520, 0xf2b2c712 ++0, 282000, 107520, 0xf2b2c712 ++0, 285000, 107520, 0xf2b2c712 ++0, 288000, 107520, 0xb95e6bc8 ++0, 291000, 107520, 0x33feee37 + 1, 292506, 44112, 0xffaf3824 +-0, 294000, 107520, 0x7e4a4cca +-0, 297000, 107520, 0x7e4a4cca +-0, 300000, 107520, 0xb315dc65 +-0, 303000, 107520, 0xb315dc65 +-0, 306000, 107520, 0x2aecc7b4 +-0, 309000, 107520, 0x2aecc7b4 +-0, 312000, 107520, 0x81742f51 +-0, 315000, 107520, 0x81742f51 ++0, 294000, 107520, 0x36ee3cd5 ++0, 297000, 107520, 0x59096471 ++0, 300000, 107520, 0x53b470c6 ++0, 303000, 107520, 0xdb7c64ff ++0, 306000, 107520, 0xe5a1596a ++0, 309000, 107520, 0x8c8942eb ++0, 312000, 107520, 0x5ecc379e ++0, 315000, 107520, 0xea09432a + 1, 315012, 44112, 0x3dbe1aef +-0, 318000, 107520, 0x3a1d7571 +-0, 321000, 107520, 0x3a1d7571 +-0, 324000, 107520, 0x3a1d7571 +-0, 327000, 107520, 0x3a1d7571 +-0, 330000, 107520, 0x3a1d7571 +-0, 333000, 107520, 0x3a1d7571 +-0, 336000, 107520, 0x3a1d7571 ++0, 318000, 107520, 0xe01e6b73 ++0, 321000, 107520, 0x1d13bba8 ++0, 324000, 107520, 0x3a993a6c ++0, 327000, 107520, 0x2ede041a + 1, 337518, 44064, 0xed2c7dfb +-0, 339000, 107520, 0x3a1d7571 +-0, 342000, 107520, 0x3a1d7571 +-0, 345000, 107520, 0x3a1d7571 +-0, 348000, 107520, 0x3a1d7571 +-0, 351000, 107520, 0x3a1d7571 +-0, 354000, 107520, 0x3a1d7571 +-0, 357000, 107520, 0x3a1d7571 + 1, 360000, 44112, 0x9e475274 +-0, 360000, 107520, 0xe974733e +-0, 363000, 107520, 0xe974733e +-0, 366000, 107520, 0x999c6fbf +-0, 369000, 107520, 0x999c6fbf +-0, 372000, 107520, 0x26b56b6e +-0, 375000, 107520, 0x26b56b6e +-0, 378000, 107520, 0xc9f9647b +-0, 381000, 107520, 0xc9f9647b + 1, 382506, 44112, 0x541f05d4 +-0, 384000, 107520, 0x6d025d00 +-0, 387000, 107520, 0x6d025d00 +-0, 390000, 107520, 0xf9c056c1 +-0, 393000, 107520, 0xf9c056c1 +-0, 396000, 107520, 0xa5cc4d0b +-0, 399000, 107520, 0xa5cc4d0b +-0, 402000, 107520, 0x1a4c4236 +-0, 405000, 107520, 0x1a4c4236 + 1, 405012, 44112, 0x09e39025 +-0, 408000, 107520, 0xa9d538b6 +-0, 411000, 107520, 0xa9d538b6 +-0, 414000, 107520, 0x14682d00 +-0, 417000, 107520, 0x14682d00 +-0, 420000, 107520, 0x6236204f +-0, 423000, 107520, 0x6236204f +-0, 426000, 107520, 0x303e14aa + 1, 427518, 44064, 0xdc111087 +-0, 429000, 107520, 0x303e14aa +-0, 432000, 107520, 0x943b0837 +-0, 435000, 107520, 0x943b0837 +-0, 438000, 107520, 0xfce5fd07 +-0, 441000, 107520, 0xfce5fd07 +-0, 444000, 107520, 0xd993f193 +-0, 447000, 107520, 0xd993f193 + 1, 450000, 44112, 0xb8f86e48 +-0, 450000, 107520, 0x4d48e7b4 +-0, 453000, 107520, 0x4d48e7b4 +-0, 456000, 107520, 0x61ccdf83 +-0, 459000, 107520, 0x61ccdf83 +-0, 462000, 107520, 0xfb4fd608 +-0, 465000, 107520, 0xfb4fd608 +-0, 468000, 107520, 0x5efdcdb3 +-0, 471000, 107520, 0x5efdcdb3 + 1, 472506, 44112, 0xa1e0c75c +-0, 474000, 107520, 0xb03ec886 +-0, 477000, 107520, 0xb03ec886 +-0, 480000, 107520, 0xf464c343 +-0, 483000, 107520, 0xf464c343 +-0, 486000, 107520, 0xf464c343 +-0, 489000, 107520, 0xf464c343 +-0, 492000, 107520, 0xf464c343 +-0, 495000, 107520, 0xf464c343 + 1, 495012, 44112, 0x0654dcb0 +-0, 498000, 107520, 0xf464c343 +-0, 501000, 107520, 0xf464c343 +-0, 504000, 107520, 0xf464c343 +-0, 507000, 107520, 0xf464c343 +-0, 510000, 107520, 0xf464c343 +-0, 513000, 107520, 0xf464c343 +-0, 516000, 107520, 0xf464c343 + 1, 517518, 44064, 0xb921e11a +-0, 519000, 107520, 0xf464c343 +-0, 522000, 107520, 0xf464c343 +-0, 525000, 107520, 0xf464c343 +-0, 528000, 107520, 0xf464c343 +-0, 531000, 107520, 0xf464c343 +-0, 534000, 107520, 0xf464c343 +-0, 537000, 107520, 0xf464c343 + 1, 540000, 44112, 0xe0ac619f +-0, 540000, 107520, 0xf464c343 +-0, 543000, 107520, 0xf464c343 +-0, 546000, 107520, 0xf2b2c712 +-0, 549000, 107520, 0xf2b2c712 +-0, 552000, 107520, 0xf2b2c712 +-0, 555000, 107520, 0xf2b2c712 +-0, 558000, 107520, 0xf2b2c712 +-0, 561000, 107520, 0xf2b2c712 + 1, 562506, 44112, 0xb07aa65c +-0, 564000, 107520, 0xf2b2c712 +-0, 567000, 107520, 0xf2b2c712 +-0, 570000, 107520, 0xb95e6bc8 +-0, 573000, 107520, 0xb95e6bc8 +-0, 576000, 107520, 0x33feee37 +-0, 579000, 107520, 0x33feee37 +-0, 582000, 107520, 0x36ee3cd5 +-0, 585000, 107520, 0x36ee3cd5 + 1, 585012, 44112, 0x24610ff0 +-0, 588000, 107520, 0x59096471 +-0, 591000, 107520, 0x59096471 +-0, 594000, 107520, 0x53b470c6 +-0, 597000, 107520, 0x53b470c6 +-0, 600000, 107520, 0xdb7c64ff +-0, 603000, 107520, 0xdb7c64ff +-0, 606000, 107520, 0xe5a1596a + 1, 607518, 44064, 0x00000000 +-0, 609000, 107520, 0xe5a1596a +-0, 612000, 107520, 0x8c8942eb +-0, 615000, 107520, 0x8c8942eb +-0, 618000, 107520, 0x5ecc379e +-0, 621000, 107520, 0x5ecc379e +-0, 624000, 107520, 0xea09432a +-0, 627000, 107520, 0xea09432a + 1, 630000, 44112, 0x00000000 +-0, 630000, 107520, 0xe01e6b73 +-0, 633000, 107520, 0xe01e6b73 +-0, 636000, 107520, 0x1d13bba8 +-0, 639000, 107520, 0x1d13bba8 +-0, 642000, 107520, 0x3a993a6c +-0, 645000, 107520, 0x3a993a6c +-0, 648000, 107520, 0x2ede041a +-0, 651000, 107520, 0x2ede041a + 1, 652506, 8800, 0x00000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/flic-af11-palette-change xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/flic-af11-palette-change +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/flic-af11-palette-change 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/flic-af11-palette-change 2012-05-14 14:08:55.650366467 +0200 +@@ -1,116 +1,116 @@ +-0, 0, 192000, 0x64da83e8 +-0, 2571, 192000, 0xf59ccccc +-0, 5143, 192000, 0xaaa06c5c +-0, 7714, 192000, 0xa98f82c0 +-0, 10286, 192000, 0x164fbbdc +-0, 12857, 192000, 0x0b3abc0c +-0, 15429, 192000, 0x47661943 +-0, 18000, 192000, 0x30711074 +-0, 20571, 192000, 0x67684a84 +-0, 23143, 192000, 0x1d9afa70 +-0, 25714, 192000, 0x4fd28e78 +-0, 28286, 192000, 0x9bc5c8cc +-0, 30857, 192000, 0xcf268b6c +-0, 33429, 192000, 0xdfe65fd4 +-0, 36000, 192000, 0x47e75404 +-0, 38571, 192000, 0xb3b5b448 +-0, 41143, 192000, 0x826c94b4 +-0, 43714, 192000, 0x158e95f8 +-0, 46286, 192000, 0x576f031f +-0, 48857, 192000, 0xea3399e8 +-0, 51429, 192000, 0x76b1e224 +-0, 54000, 192000, 0x290073db +-0, 56571, 192000, 0x83741abf +-0, 59143, 192000, 0x50f9c4ec +-0, 61714, 192000, 0x6d8fdac0 +-0, 64286, 192000, 0xe26e2600 +-0, 66857, 192000, 0xbeb0e11c +-0, 69429, 192000, 0x38282fd4 +-0, 72000, 192000, 0x13d0b790 +-0, 74571, 192000, 0x0cf8fca9 +-0, 77143, 192000, 0x64da83e8 +-0, 79714, 192000, 0xf59ccccc +-0, 82286, 192000, 0xaaa06c5c +-0, 84857, 192000, 0xa98f82c0 +-0, 87429, 192000, 0x164fbbdc +-0, 90000, 192000, 0x0b3abc0c +-0, 92571, 192000, 0x47661943 +-0, 95143, 192000, 0x30711074 +-0, 97714, 192000, 0x67684a84 +-0, 100286, 192000, 0x1d9afa70 +-0, 102857, 192000, 0x4fd28e78 +-0, 105429, 192000, 0x9bc5c8cc +-0, 108000, 192000, 0xcf268b6c +-0, 110571, 192000, 0xdfe65fd4 +-0, 113143, 192000, 0x47e75404 +-0, 115714, 192000, 0xb3b5b448 +-0, 118286, 192000, 0x826c94b4 +-0, 120857, 192000, 0x158e95f8 +-0, 123429, 192000, 0x576f031f +-0, 126000, 192000, 0xea3399e8 +-0, 128571, 192000, 0x76b1e224 +-0, 131143, 192000, 0x290073db +-0, 133714, 192000, 0x83741abf +-0, 136286, 192000, 0x50f9c4ec +-0, 138857, 192000, 0x6d8fdac0 +-0, 141429, 192000, 0xe26e2600 +-0, 144000, 192000, 0xbeb0e11c +-0, 146571, 192000, 0x38282fd4 +-0, 149143, 192000, 0x13d0b790 +-0, 151714, 192000, 0x0cf8fca9 +-0, 154286, 192000, 0x64da83e8 +-0, 156857, 192000, 0xf59ccccc +-0, 159429, 192000, 0xaaa06c5c +-0, 162000, 192000, 0xa98f82c0 +-0, 164571, 192000, 0x164fbbdc +-0, 167143, 192000, 0x0b3abc0c +-0, 169714, 192000, 0x47661943 +-0, 172286, 192000, 0x30711074 +-0, 174857, 192000, 0x67684a84 +-0, 177429, 192000, 0x1d9afa70 +-0, 180000, 192000, 0x4fd28e78 +-0, 182571, 192000, 0x9bc5c8cc +-0, 185143, 192000, 0xcf268b6c +-0, 187714, 192000, 0xdfe65fd4 +-0, 190286, 192000, 0x47e75404 +-0, 192857, 192000, 0xb3b5b448 +-0, 195429, 192000, 0x826c94b4 +-0, 198000, 192000, 0x158e95f8 +-0, 200571, 192000, 0x576f031f +-0, 203143, 192000, 0xea3399e8 +-0, 205714, 192000, 0x76b1e224 +-0, 208286, 192000, 0x290073db +-0, 210857, 192000, 0x83741abf +-0, 213429, 192000, 0x50f9c4ec +-0, 216000, 192000, 0x6d8fdac0 +-0, 218571, 192000, 0xe26e2600 +-0, 221143, 192000, 0xbeb0e11c +-0, 223714, 192000, 0x38282fd4 +-0, 226286, 192000, 0x13d0b790 +-0, 228857, 192000, 0x0cf8fca9 +-0, 231429, 192000, 0xfcb10883 +-0, 234000, 192000, 0xfcb10883 +-0, 236571, 192000, 0xd0ba80c4 +-0, 239143, 192000, 0xd0ba80c4 +-0, 241714, 192000, 0x690520d9 +-0, 244286, 192000, 0x690520d9 +-0, 246857, 192000, 0x5b621c3f +-0, 249429, 192000, 0x5b621c3f +-0, 252000, 192000, 0x689e231f +-0, 254571, 192000, 0x689e231f +-0, 257143, 192000, 0x20653ff2 +-0, 259714, 192000, 0x20653ff2 +-0, 262286, 192000, 0xc18b3231 +-0, 264857, 192000, 0xc18b3231 +-0, 267429, 192000, 0x6d87ec3d +-0, 270000, 192000, 0x6d87ec3d +-0, 272571, 192000, 0x1c5b53d6 +-0, 275143, 192000, 0x1c5b53d6 +-0, 277714, 192000, 0x152fdf12 +-0, 280286, 192000, 0xde187291 +-0, 282857, 192000, 0x167617a5 +-0, 285429, 192000, 0x5067b8de +-0, 288000, 192000, 0xd02ae54e +-0, 290571, 192000, 0x0d6e9402 +-0, 293143, 192000, 0xa8e98616 +-0, 295714, 192000, 0x04762d1a ++0, 0, 192000, 0x508ff8ac ++0, 2571, 192000, 0xef0d4274 ++0, 5143, 192000, 0x0d50e0dd ++0, 7714, 192000, 0xf638f782 ++0, 10286, 192000, 0x40e4314b ++0, 12857, 192000, 0x0ce5318f ++0, 15429, 192000, 0x14848fa9 ++0, 18000, 192000, 0x676f83e1 ++0, 20571, 192000, 0x5b98bea9 ++0, 23143, 192000, 0xf5cc709d ++0, 25714, 192000, 0x719a0373 ++0, 28286, 192000, 0xba5a3e74 ++0, 30857, 192000, 0x34e10051 ++0, 33429, 192000, 0xb66dd42d ++0, 36000, 192000, 0xfb58c833 ++0, 38571, 192000, 0xa28029a4 ++0, 41143, 192000, 0x28fa09b3 ++0, 43714, 192000, 0x676f0b08 ++0, 46286, 192000, 0x7af97965 ++0, 48857, 192000, 0x436f0f03 ++0, 51429, 192000, 0xbaca5814 ++0, 54000, 192000, 0xca97eb51 ++0, 56571, 192000, 0x1fc89137 ++0, 59143, 192000, 0x8af63a74 ++0, 61714, 192000, 0xca015077 ++0, 64286, 192000, 0x761599ad ++0, 66857, 192000, 0x1ca1570c ++0, 69429, 192000, 0x1209a3ac ++0, 72000, 192000, 0xf7d92d01 ++0, 74571, 192000, 0x970d6fea ++0, 77143, 192000, 0x508ff8ac ++0, 79714, 192000, 0xef0d4274 ++0, 82286, 192000, 0x0d50e0dd ++0, 84857, 192000, 0xf638f782 ++0, 87429, 192000, 0x40e4314b ++0, 90000, 192000, 0x0ce5318f ++0, 92571, 192000, 0x14848fa9 ++0, 95143, 192000, 0x676f83e1 ++0, 97714, 192000, 0x5b98bea9 ++0, 100286, 192000, 0xf5cc709d ++0, 102857, 192000, 0x719a0373 ++0, 105429, 192000, 0xba5a3e74 ++0, 108000, 192000, 0x34e10051 ++0, 110571, 192000, 0xb66dd42d ++0, 113143, 192000, 0xfb58c833 ++0, 115714, 192000, 0xa28029a4 ++0, 118286, 192000, 0x28fa09b3 ++0, 120857, 192000, 0x676f0b08 ++0, 123429, 192000, 0x7af97965 ++0, 126000, 192000, 0x436f0f03 ++0, 128571, 192000, 0xbaca5814 ++0, 131143, 192000, 0xca97eb51 ++0, 133714, 192000, 0x1fc89137 ++0, 136286, 192000, 0x8af63a74 ++0, 138857, 192000, 0xca015077 ++0, 141429, 192000, 0x761599ad ++0, 144000, 192000, 0x1ca1570c ++0, 146571, 192000, 0x1209a3ac ++0, 149143, 192000, 0xf7d92d01 ++0, 151714, 192000, 0x970d6fea ++0, 154286, 192000, 0x508ff8ac ++0, 156857, 192000, 0xef0d4274 ++0, 159429, 192000, 0x0d50e0dd ++0, 162000, 192000, 0xf638f782 ++0, 164571, 192000, 0x40e4314b ++0, 167143, 192000, 0x0ce5318f ++0, 169714, 192000, 0x14848fa9 ++0, 172286, 192000, 0x676f83e1 ++0, 174857, 192000, 0x5b98bea9 ++0, 177429, 192000, 0xf5cc709d ++0, 180000, 192000, 0x719a0373 ++0, 182571, 192000, 0xba5a3e74 ++0, 185143, 192000, 0x34e10051 ++0, 187714, 192000, 0xb66dd42d ++0, 190286, 192000, 0xfb58c833 ++0, 192857, 192000, 0xa28029a4 ++0, 195429, 192000, 0x28fa09b3 ++0, 198000, 192000, 0x676f0b08 ++0, 200571, 192000, 0x7af97965 ++0, 203143, 192000, 0x436f0f03 ++0, 205714, 192000, 0xbaca5814 ++0, 208286, 192000, 0xca97eb51 ++0, 210857, 192000, 0x1fc89137 ++0, 213429, 192000, 0x8af63a74 ++0, 216000, 192000, 0xca015077 ++0, 218571, 192000, 0x761599ad ++0, 221143, 192000, 0x1ca1570c ++0, 223714, 192000, 0x1209a3ac ++0, 226286, 192000, 0xf7d92d01 ++0, 228857, 192000, 0x970d6fea ++0, 231429, 192000, 0x1ff28298 ++0, 234000, 192000, 0x1ff28298 ++0, 236571, 192000, 0x407d09ca ++0, 239143, 192000, 0x407d09ca ++0, 241714, 192000, 0xc743a475 ++0, 244286, 192000, 0xc743a475 ++0, 246857, 192000, 0x46bf9f7d ++0, 249429, 192000, 0x46bf9f7d ++0, 252000, 192000, 0x57ecb2c1 ++0, 254571, 192000, 0x57ecb2c1 ++0, 257143, 192000, 0x680fd3bf ++0, 259714, 192000, 0x680fd3bf ++0, 262286, 192000, 0x8772ca19 ++0, 264857, 192000, 0x8772ca19 ++0, 267429, 192000, 0x3cc29bbf ++0, 270000, 192000, 0x3cc29bbf ++0, 272571, 192000, 0xe745fb3c ++0, 275143, 192000, 0xe745fb3c ++0, 277714, 192000, 0xc5279397 ++0, 280286, 192000, 0xcc902b35 ++0, 282857, 192000, 0x50a7cf32 ++0, 285429, 192000, 0x23fd6f51 ++0, 288000, 192000, 0x14fe9c4d ++0, 290571, 192000, 0x703249f9 ++0, 293143, 192000, 0x47b73bce ++0, 295714, 192000, 0x13bce1c9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/flic-magiccarpet xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/flic-magiccarpet +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/flic-magiccarpet 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/flic-magiccarpet 2012-05-14 14:08:55.651366488 +0200 +@@ -1,42 +1,42 @@ + 0, 0, 192000, 0x00000000 +-0, 6429, 192000, 0x9c057d9c +-0, 12857, 192000, 0xab1aacaf +-0, 19286, 192000, 0x49a1dccd +-0, 25714, 192000, 0xebb7e245 +-0, 32143, 192000, 0x6287759e +-0, 38571, 192000, 0xbf007410 +-0, 45000, 192000, 0x6c72b247 +-0, 51429, 192000, 0x4c26a8c3 +-0, 57857, 192000, 0x99f06050 +-0, 64286, 192000, 0x663f2d23 +-0, 70714, 192000, 0x813c3a1f +-0, 77143, 192000, 0x6d6cfbe7 +-0, 83571, 192000, 0x7b04163a +-0, 90000, 192000, 0x6792e679 +-0, 96429, 192000, 0x939ac626 +-0, 102857, 192000, 0xc7a139c0 +-0, 109286, 192000, 0xcac7ef0c +-0, 115714, 192000, 0xf4ec59e0 +-0, 122143, 192000, 0x56060f59 +-0, 128571, 192000, 0xf45ecb3b +-0, 135000, 192000, 0xe7e634ff +-0, 141429, 192000, 0x7ac04aa4 +-0, 147857, 192000, 0x4eaba5a1 +-0, 154286, 192000, 0x89b84e25 +-0, 160714, 192000, 0xc368ec1e +-0, 167143, 192000, 0xeeafb59e +-0, 173571, 192000, 0x0b630619 +-0, 180000, 192000, 0x59cb8954 +-0, 186429, 192000, 0x16b2875f +-0, 192857, 192000, 0x524e32bd +-0, 199286, 192000, 0x96000ba2 +-0, 205714, 192000, 0x18ec28af +-0, 212143, 192000, 0x2609c56c +-0, 218571, 192000, 0xff25bb5a +-0, 225000, 192000, 0xb19a8819 +-0, 231429, 192000, 0xa5ff8727 +-0, 237857, 192000, 0xe83f6289 +-0, 244286, 192000, 0xc6cb4903 +-0, 250714, 192000, 0xa4d93eb5 +-0, 257143, 192000, 0xec84ef6c ++0, 6429, 192000, 0x03567eeb ++0, 12857, 192000, 0xe73db12c ++0, 19286, 192000, 0x7cefe740 ++0, 25714, 192000, 0xb769f827 ++0, 32143, 192000, 0x71669dea ++0, 38571, 192000, 0xc203b934 ++0, 45000, 192000, 0x30671ee2 ++0, 51429, 192000, 0xaea33a1b ++0, 57857, 192000, 0x50f220c3 ++0, 64286, 192000, 0x1ddd090f ++0, 70714, 192000, 0x17ac22a4 ++0, 77143, 192000, 0x19f9f412 ++0, 83571, 192000, 0xa2df0e55 ++0, 90000, 192000, 0x5abcd663 ++0, 96429, 192000, 0x5b09b38d ++0, 102857, 192000, 0x894d1f43 ++0, 109286, 192000, 0xbc95caaf ++0, 115714, 192000, 0xeaca27fc ++0, 122143, 192000, 0x49c5ccb4 ++0, 128571, 192000, 0x8b3e78b0 ++0, 135000, 192000, 0x1645d3ae ++0, 141429, 192000, 0x4407da0f ++0, 147857, 192000, 0x7d0826ac ++0, 154286, 192000, 0xc17ec1b8 ++0, 160714, 192000, 0x4a82520d ++0, 167143, 192000, 0xa89f0e2f ++0, 173571, 192000, 0xd58b537a ++0, 180000, 192000, 0x7123dafe ++0, 186429, 192000, 0x15d1d065 ++0, 192857, 192000, 0xa86873f6 ++0, 199286, 192000, 0x32704a91 ++0, 205714, 192000, 0xbf2b63d7 ++0, 212143, 192000, 0xb98e0126 ++0, 218571, 192000, 0x412a03ee ++0, 225000, 192000, 0x601ad161 ++0, 231429, 192000, 0x01ead407 ++0, 237857, 192000, 0x75a7bbe5 ++0, 244286, 192000, 0x155ea759 ++0, 250714, 192000, 0xe3a0a6aa ++0, 257143, 192000, 0x2b5a5770 + 0, 263571, 192000, 0x00000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g722dec-1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g722dec-1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g722dec-1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g722dec-1 2012-05-14 14:08:55.652366508 +0200 +@@ -1,167 +1,167 @@ +-0, 0, 4096, 0xde68394d +-0, 11520, 4096, 0xa5c28cb7 +-0, 23040, 4096, 0x2e3c2f23 +-0, 34560, 4096, 0xd7757825 +-0, 46080, 4096, 0xafd1fd61 +-0, 57600, 4096, 0x686afcbe +-0, 69120, 4096, 0x2290e848 +-0, 80640, 4096, 0xddd484ad +-0, 92160, 4096, 0x148811a6 +-0, 103680, 4096, 0x8b965613 +-0, 115200, 4096, 0x8b095d51 +-0, 126720, 4096, 0xf7625485 +-0, 138240, 4096, 0x982a688c +-0, 149760, 4096, 0xc290dcfc +-0, 161280, 4096, 0x8bdef225 +-0, 172800, 4096, 0xfca27fdc +-0, 184320, 4096, 0x95eff313 +-0, 195840, 4096, 0x691ed4f7 +-0, 207360, 4096, 0xd7e7b492 +-0, 218880, 4096, 0xb0416bfe +-0, 230400, 4096, 0xf94b3ebd +-0, 241920, 4096, 0x7f73ca12 +-0, 253440, 4096, 0xe91da4a3 +-0, 264960, 4096, 0x1f74dc0e +-0, 276480, 4096, 0xd95b35e8 +-0, 288000, 4096, 0x6dcdde1a +-0, 299520, 4096, 0x614fd4e4 +-0, 311040, 4096, 0xe38d0fd5 +-0, 322560, 4096, 0xfeba2999 +-0, 334080, 4096, 0x1bf541e1 +-0, 345600, 4096, 0x689f50d8 +-0, 357120, 4096, 0x0aa60f5f +-0, 368640, 4096, 0x60ac3116 +-0, 380160, 4096, 0xfa60e5e6 +-0, 391680, 4096, 0xc7207c5b +-0, 403200, 4096, 0x01196277 +-0, 414720, 4096, 0x609ca46c +-0, 426240, 4096, 0xfb799142 +-0, 437760, 4096, 0x720910df +-0, 449280, 4096, 0xe21a8662 +-0, 460800, 4096, 0x07105120 +-0, 472320, 4096, 0x593f627e +-0, 483840, 4096, 0x28ddc80c +-0, 495360, 4096, 0xc69ef356 +-0, 506880, 4096, 0x2defc5bd +-0, 518400, 4096, 0x82a4f418 +-0, 529920, 4096, 0x424cb997 +-0, 541440, 4096, 0x167a49b7 +-0, 552960, 4096, 0x32a3e0d4 +-0, 564480, 4096, 0x08a353ae +-0, 576000, 4096, 0x9543577b +-0, 587520, 4096, 0x2ed137cf +-0, 599040, 4096, 0xd80b0538 +-0, 610560, 4096, 0x2ad31bef +-0, 622080, 4096, 0x1060cff8 +-0, 633600, 4096, 0x76ab5ab8 +-0, 645120, 4096, 0x8eedb68d +-0, 656640, 4096, 0xf4e2dc46 +-0, 668160, 4096, 0xc52d3326 +-0, 679680, 4096, 0x25201a26 +-0, 691200, 4096, 0x16419378 +-0, 702720, 4096, 0x97061f3c +-0, 714240, 4096, 0xd54edecd +-0, 725760, 4096, 0xc830b07b +-0, 737280, 4096, 0x804bae00 +-0, 748800, 4096, 0xbb279150 +-0, 760320, 4096, 0x95c4d5aa +-0, 771840, 4096, 0xc51d5259 +-0, 783360, 4096, 0x856e1ab0 +-0, 794880, 4096, 0x9e6ccb12 +-0, 806400, 4096, 0xa2e5c1bb +-0, 817920, 4096, 0xe62fb62f +-0, 829440, 4096, 0xf10e3df0 +-0, 840960, 4096, 0x76def18b +-0, 852480, 4096, 0xc9c3a26d +-0, 864000, 4096, 0x8ec0e061 +-0, 875520, 4096, 0x3d4e8512 +-0, 887040, 4096, 0xec45cd46 +-0, 898560, 4096, 0xa34f3ddf +-0, 910080, 4096, 0x52b81c53 +-0, 921600, 4096, 0xd0f0397a +-0, 933120, 4096, 0x7c0de231 +-0, 944640, 4096, 0xfe86c032 +-0, 956160, 4096, 0x67cdb848 +-0, 967680, 4096, 0x90532cc0 +-0, 979200, 4096, 0x03bca9e9 +-0, 990720, 4096, 0x73169fd1 +-0, 1002240, 4096, 0x0b93967d +-0, 1013760, 4096, 0x6486d8be +-0, 1025280, 4096, 0x555cc2ac +-0, 1036800, 4096, 0x07c1912e +-0, 1048320, 4096, 0xe0423c66 +-0, 1059840, 4096, 0xc12d0fa1 +-0, 1071360, 4096, 0xdf497c2f +-0, 1082880, 4096, 0x9298d1ba +-0, 1094400, 4096, 0x691a4e15 +-0, 1105920, 4096, 0x725adc6e +-0, 1117440, 4096, 0xf68e88de +-0, 1128960, 4096, 0x37a234aa +-0, 1140480, 4096, 0x43fb0558 +-0, 1152000, 4096, 0x653e4320 +-0, 1163520, 4096, 0x651e2f13 +-0, 1175040, 4096, 0x179049f9 +-0, 1186560, 4096, 0xe02fbb9d +-0, 1198080, 4096, 0xb7e9f2a0 +-0, 1209600, 4096, 0x94ee81df +-0, 1221120, 4096, 0x398a98de +-0, 1232640, 4096, 0x1267594a +-0, 1244160, 4096, 0x715adbaf +-0, 1255680, 4096, 0x28ce1a20 +-0, 1267200, 4096, 0x4f8073d0 +-0, 1278720, 4096, 0x536846d3 +-0, 1290240, 4096, 0x7dc7defe +-0, 1301760, 4096, 0x08a28e2a +-0, 1313280, 4096, 0xd717c5cd +-0, 1324800, 4096, 0x5d6e1efd +-0, 1336320, 4096, 0x4d0eea27 +-0, 1347840, 4096, 0x70fff90c +-0, 1359360, 4096, 0xd5cc8207 +-0, 1370880, 4096, 0xf87cae0e +-0, 1382400, 4096, 0x26814ab5 +-0, 1393920, 4096, 0x9569fb8d +-0, 1405440, 4096, 0x7835122e +-0, 1416960, 4096, 0xa38840dd +-0, 1428480, 4096, 0xfc499ba3 +-0, 1440000, 4096, 0x0aa60cb0 +-0, 1451520, 4096, 0x530ef56e +-0, 1463040, 4096, 0xead968db +-0, 1474560, 4096, 0x64484214 +-0, 1486080, 4096, 0xfd0cc89e +-0, 1497600, 4096, 0x0d452a5d +-0, 1509120, 4096, 0x36ef8482 +-0, 1520640, 4096, 0x462b641b +-0, 1532160, 4096, 0x2a5c1c0c +-0, 1543680, 4096, 0x8837ff80 +-0, 1555200, 4096, 0x27a3de22 +-0, 1566720, 4096, 0xf88d28c1 +-0, 1578240, 4096, 0xed85ea97 +-0, 1589760, 4096, 0x50c3e7db +-0, 1601280, 4096, 0x82bcb480 +-0, 1612800, 4096, 0xc50ee536 +-0, 1624320, 4096, 0x086280ee +-0, 1635840, 4096, 0x6f18f2b2 +-0, 1647360, 4096, 0x1c7c0856 +-0, 1658880, 4096, 0xc576268a +-0, 1670400, 4096, 0x7a9af56d +-0, 1681920, 4096, 0x6d058fc5 +-0, 1693440, 4096, 0x8fb1107b +-0, 1704960, 4096, 0x807588d1 +-0, 1716480, 4096, 0x56178443 +-0, 1728000, 4096, 0xf2460763 +-0, 1739520, 4096, 0x284255f2 +-0, 1751040, 4096, 0xb29d17fb +-0, 1762560, 4096, 0x5e7e4633 +-0, 1774080, 4096, 0x57704db1 +-0, 1785600, 4096, 0xd87dcc1d +-0, 1797120, 4096, 0x28d4bb93 +-0, 1808640, 4096, 0x3a2e5c6c +-0, 1820160, 4096, 0xf3581656 +-0, 1831680, 4096, 0x42f1942f +-0, 1843200, 4096, 0xe75c5092 +-0, 1854720, 4096, 0x3fae7f6d +-0, 1866240, 4096, 0xf99ad73e +-0, 1877760, 4096, 0x80564e3e +-0, 1889280, 4096, 0x8ff6ebe5 +-0, 1900800, 4096, 0x436d5e69 +-0, 1912320, 1368, 0xe0ebeda3 ++0, 0, 4096, 0x4f9228b3 ++0, 11520, 4096, 0xfab58157 ++0, 23040, 4096, 0x0b641c78 ++0, 34560, 4096, 0x601c6803 ++0, 46080, 4096, 0xb3e2f166 ++0, 57600, 4096, 0x5681f206 ++0, 69120, 4096, 0x1e69e71f ++0, 80640, 4096, 0x05628be3 ++0, 92160, 4096, 0x109b1aef ++0, 103680, 4096, 0xd5435a9e ++0, 115200, 4096, 0xb38b5d28 ++0, 126720, 4096, 0x64514c93 ++0, 138240, 4096, 0x453350e7 ++0, 149760, 4096, 0x6deccce6 ++0, 161280, 4096, 0xd427ede1 ++0, 172800, 4096, 0xdecb8c42 ++0, 184320, 4096, 0x3841e4d2 ++0, 195840, 4096, 0x858ac1b1 ++0, 207360, 4096, 0x8e9dbfa0 ++0, 218880, 4096, 0xcbc0766f ++0, 230400, 4096, 0x78d52555 ++0, 241920, 4096, 0x600ac7d5 ++0, 253440, 4096, 0xafadb7ee ++0, 264960, 4096, 0x8009d5a1 ++0, 276480, 4096, 0xb07d475e ++0, 288000, 4096, 0xfcfecceb ++0, 299520, 4096, 0x38b5d85f ++0, 311040, 4096, 0xbd48072e ++0, 322560, 4096, 0xd04724d8 ++0, 334080, 4096, 0x08425144 ++0, 345600, 4096, 0x7b14483e ++0, 357120, 4096, 0x8858ef4c ++0, 368640, 4096, 0x1e3024c2 ++0, 380160, 4096, 0xcd6bfe4f ++0, 391680, 4096, 0x8cde8d18 ++0, 403200, 4096, 0xbbd856b8 ++0, 414720, 4096, 0x988c9b7a ++0, 426240, 4096, 0x2a858e03 ++0, 437760, 4096, 0x6dee1e4a ++0, 449280, 4096, 0x8cc38b41 ++0, 460800, 4096, 0x48bd5cec ++0, 472320, 4096, 0xeb7f606b ++0, 483840, 4096, 0x75f5d28c ++0, 495360, 4096, 0x5bfeec4b ++0, 506880, 4096, 0xfc35c22a ++0, 518400, 4096, 0x3a95efba ++0, 529920, 4096, 0xefdbce9c ++0, 541440, 4096, 0x00594ada ++0, 552960, 4096, 0x20ffebfa ++0, 564480, 4096, 0x1b31370a ++0, 576000, 4096, 0x50766a56 ++0, 587520, 4096, 0x0058315a ++0, 599040, 4096, 0x98090cbf ++0, 610560, 4096, 0x66ed2d40 ++0, 622080, 4096, 0xdfd7c0a7 ++0, 633600, 4096, 0x2adc57e1 ++0, 645120, 4096, 0x838bbc82 ++0, 656640, 4096, 0x2c55de1a ++0, 668160, 4096, 0xeae027f4 ++0, 679680, 4096, 0x09fe00f6 ++0, 691200, 4096, 0xa25d9970 ++0, 702720, 4096, 0xedb11a20 ++0, 714240, 4096, 0x9ce2e63e ++0, 725760, 4096, 0xeb699974 ++0, 737280, 4096, 0xcc04a296 ++0, 748800, 4096, 0xe90e9a12 ++0, 760320, 4096, 0xae85c0f7 ++0, 771840, 4096, 0x7ee877db ++0, 783360, 4096, 0x9ecf14ee ++0, 794880, 4096, 0xa821cecd ++0, 806400, 4096, 0x2714bb11 ++0, 817920, 4096, 0x28f1c1e0 ++0, 829440, 4096, 0xf81c4f60 ++0, 840960, 4096, 0x1ae0e5a1 ++0, 852480, 4096, 0xbdae9d9a ++0, 864000, 4096, 0x5202e560 ++0, 875520, 4096, 0x82408396 ++0, 887040, 4096, 0xc850ce0c ++0, 898560, 4096, 0x1d732d88 ++0, 910080, 4096, 0xc5c01e33 ++0, 921600, 4096, 0x84942d6c ++0, 933120, 4096, 0x7c27cd3a ++0, 944640, 4096, 0x22adc503 ++0, 956160, 4096, 0xfbc3af31 ++0, 967680, 4096, 0xe9652b18 ++0, 979200, 4096, 0xae75987e ++0, 990720, 4096, 0x0f7ea428 ++0, 1002240, 4096, 0x92b89582 ++0, 1013760, 4096, 0xf393d910 ++0, 1025280, 4096, 0x6349b600 ++0, 1036800, 4096, 0x16918dbd ++0, 1048320, 4096, 0x14ee15ad ++0, 1059840, 4096, 0x26b510d3 ++0, 1071360, 4096, 0x97007bf8 ++0, 1082880, 4096, 0x3718c509 ++0, 1094400, 4096, 0x24a54ccd ++0, 1105920, 4096, 0xc960df4e ++0, 1117440, 4096, 0xc7cb6e6f ++0, 1128960, 4096, 0x4c563ae5 ++0, 1140480, 4096, 0x0dd51432 ++0, 1152000, 4096, 0xdb4243c8 ++0, 1163520, 4096, 0x9bb6417f ++0, 1175040, 4096, 0xec6a40a1 ++0, 1186560, 4096, 0x82d6c3b4 ++0, 1198080, 4096, 0xd181e2ec ++0, 1209600, 4096, 0xba5d7b55 ++0, 1221120, 4096, 0x78fcb938 ++0, 1232640, 4096, 0x6691671c ++0, 1244160, 4096, 0x44fadee7 ++0, 1255680, 4096, 0xa42720d5 ++0, 1267200, 4096, 0xc1165a91 ++0, 1278720, 4096, 0x86aa3e3f ++0, 1290240, 4096, 0xab5ae57d ++0, 1301760, 4096, 0x291a91f3 ++0, 1313280, 4096, 0xfdf0dcfc ++0, 1324800, 4096, 0x1ef91f67 ++0, 1336320, 4096, 0xc899efee ++0, 1347840, 4096, 0x5ade15ac ++0, 1359360, 4096, 0x04516beb ++0, 1370880, 4096, 0xbf5ebbb9 ++0, 1382400, 4096, 0x4a235122 ++0, 1393920, 4096, 0xd7a3f4a6 ++0, 1405440, 4096, 0x5f900f20 ++0, 1416960, 4096, 0xa90b4365 ++0, 1428480, 4096, 0x63149dc4 ++0, 1440000, 4096, 0xf12c1ee8 ++0, 1451520, 4096, 0x6d0fec8c ++0, 1463040, 4096, 0x65e07850 ++0, 1474560, 4096, 0x16d951cc ++0, 1486080, 4096, 0xd296d0c4 ++0, 1497600, 4096, 0x619b2a53 ++0, 1509120, 4096, 0x316972d5 ++0, 1520640, 4096, 0xcfd64e21 ++0, 1532160, 4096, 0xcbcb10c6 ++0, 1543680, 4096, 0x20aeff7c ++0, 1555200, 4096, 0xd205dabd ++0, 1566720, 4096, 0xac9d3001 ++0, 1578240, 4096, 0x6d53dfdd ++0, 1589760, 4096, 0xbb9fe15c ++0, 1601280, 4096, 0x1852b88b ++0, 1612800, 4096, 0xb0acec01 ++0, 1624320, 4096, 0xb52a9342 ++0, 1635840, 4096, 0x7529faee ++0, 1647360, 4096, 0x150ff449 ++0, 1658880, 4096, 0xa81d31d9 ++0, 1670400, 4096, 0xbcb8084a ++0, 1681920, 4096, 0x07229514 ++0, 1693440, 4096, 0xa85cfd88 ++0, 1704960, 4096, 0x0aef9c27 ++0, 1716480, 4096, 0x8ec47b39 ++0, 1728000, 4096, 0x910b0560 ++0, 1739520, 4096, 0x99a8578e ++0, 1751040, 4096, 0xb3df1d84 ++0, 1762560, 4096, 0x48e52559 ++0, 1774080, 4096, 0xb25c4800 ++0, 1785600, 4096, 0x913bc8ce ++0, 1797120, 4096, 0xb736cc8c ++0, 1808640, 4096, 0x13c66646 ++0, 1820160, 4096, 0x70a71221 ++0, 1831680, 4096, 0x3a50a08e ++0, 1843200, 4096, 0xc0a037b0 ++0, 1854720, 4096, 0x9a789475 ++0, 1866240, 4096, 0xc890ca16 ++0, 1877760, 4096, 0xa0d34bed ++0, 1889280, 4096, 0x1689fa60 ++0, 1900800, 4096, 0x5bac4c83 ++0, 1912320, 1368, 0x904be5e5 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g722enc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g722enc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g722enc 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g722enc 2012-05-14 14:08:55.653366528 +0200 +@@ -0,0 +1 @@ ++94e2f200d6e05b47cec4aa3e94571cf3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g729-0 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g729-0 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g729-0 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g729-0 2012-05-14 14:08:55.655366568 +0200 +@@ -0,0 +1,1000 @@ ++0, 0, 160, 0xbb6d5aa0 ++0, 900, 160, 0x91563d8d ++0, 1800, 160, 0x10a7535b ++0, 2700, 160, 0xa4f35594 ++0, 3600, 160, 0x7f8e54e0 ++0, 4500, 160, 0x85275000 ++0, 5400, 160, 0x00734c7b ++0, 6300, 160, 0x8a2d544d ++0, 7200, 160, 0x97dc533c ++0, 8100, 160, 0xa7064ec4 ++0, 9000, 160, 0xb7984a3c ++0, 9900, 160, 0x28334db6 ++0, 10800, 160, 0x5838521f ++0, 11700, 160, 0x2337502c ++0, 12600, 160, 0x4a1e4599 ++0, 13500, 160, 0x0d3858a8 ++0, 14400, 160, 0xa0974b46 ++0, 15300, 160, 0xc3254b93 ++0, 16200, 160, 0x42b75231 ++0, 17100, 160, 0x93634662 ++0, 18000, 160, 0x11674fa1 ++0, 18900, 160, 0xf2da5414 ++0, 19800, 160, 0x97754dbc ++0, 20700, 160, 0x40a24d94 ++0, 21600, 160, 0x26b34ebf ++0, 22500, 160, 0x7730542f ++0, 23400, 160, 0xb45254aa ++0, 24300, 160, 0xd8d752c3 ++0, 25200, 160, 0x655c4a81 ++0, 26100, 160, 0xa5da4f35 ++0, 27000, 160, 0xd43551a1 ++0, 27900, 160, 0x72a74e7d ++0, 28800, 160, 0xdb2150b3 ++0, 29700, 160, 0x972852a1 ++0, 30600, 160, 0xbae14c07 ++0, 31500, 160, 0x23b54d57 ++0, 32400, 160, 0x2d9650a5 ++0, 33300, 160, 0xaf755107 ++0, 34200, 160, 0xdb054f0e ++0, 35100, 160, 0x9f084cc0 ++0, 36000, 160, 0x64ca5760 ++0, 36900, 160, 0x3ea24be2 ++0, 37800, 160, 0x93ea503b ++0, 38700, 160, 0xb6694afa ++0, 39600, 160, 0xf94c52e7 ++0, 40500, 160, 0x2b7156b8 ++0, 41400, 160, 0xbbdf414c ++0, 42300, 160, 0x10cd4ac8 ++0, 43200, 160, 0x39885453 ++0, 44100, 160, 0xa1505568 ++0, 45000, 160, 0x86124ec1 ++0, 45900, 160, 0xe2ab5489 ++0, 46800, 160, 0x406254bc ++0, 47700, 160, 0x09044629 ++0, 48600, 160, 0xb2ed5702 ++0, 49500, 160, 0xd9ee5188 ++0, 50400, 160, 0x59f7592a ++0, 51300, 160, 0x8f144c08 ++0, 52200, 160, 0x90394e61 ++0, 53100, 160, 0x79524df7 ++0, 54000, 160, 0x58044674 ++0, 54900, 160, 0x73b24d90 ++0, 55800, 160, 0x80e257a1 ++0, 56700, 160, 0xe8ff4caf ++0, 57600, 160, 0x1db84e3e ++0, 58500, 160, 0xd7db59d9 ++0, 59400, 160, 0x43244c15 ++0, 60300, 160, 0x1f63558f ++0, 61200, 160, 0xf0d851c6 ++0, 62100, 160, 0x76484f3a ++0, 63000, 160, 0x5746551e ++0, 63900, 160, 0x83b54cd7 ++0, 64800, 160, 0x97f550a1 ++0, 65700, 160, 0x77c45340 ++0, 66600, 160, 0xfd7b520a ++0, 67500, 160, 0x989a4e13 ++0, 68400, 160, 0x9a8551c0 ++0, 69300, 160, 0xa0cb4f93 ++0, 70200, 160, 0xc568536f ++0, 71100, 160, 0x6fa74a95 ++0, 72000, 160, 0xd550568b ++0, 72900, 160, 0xf88f4de5 ++0, 73800, 160, 0x91285517 ++0, 74700, 160, 0xdb675270 ++0, 75600, 160, 0x606c53f9 ++0, 76500, 160, 0x43f64601 ++0, 77400, 160, 0x28b94b45 ++0, 78300, 160, 0x7f2347f5 ++0, 79200, 160, 0x84ba55db ++0, 80100, 160, 0x3ca3477c ++0, 81000, 160, 0x57d158ba ++0, 81900, 160, 0x2c3c506d ++0, 82800, 160, 0x59b34e5f ++0, 83700, 160, 0x014f530a ++0, 84600, 160, 0x877f4f76 ++0, 85500, 160, 0x97a65c5f ++0, 86400, 160, 0xf643516d ++0, 87300, 160, 0x6ccc5242 ++0, 88200, 160, 0x895450bd ++0, 89100, 160, 0xe246570e ++0, 90000, 160, 0xbb9f4a0c ++0, 90900, 160, 0x60e646fe ++0, 91800, 160, 0x546f515b ++0, 92700, 160, 0xc59254f0 ++0, 93600, 160, 0xcad6551f ++0, 94500, 160, 0x14e14fac ++0, 95400, 160, 0x3cf94c52 ++0, 96300, 160, 0x99b14f45 ++0, 97200, 160, 0xfdb14dc7 ++0, 98100, 160, 0x48f359e7 ++0, 99000, 160, 0x186153e3 ++0, 99900, 160, 0x047d4a78 ++0, 100800, 160, 0x992f462b ++0, 101700, 160, 0x4a0e504d ++0, 102600, 160, 0x1f245275 ++0, 103500, 160, 0x026959a9 ++0, 104400, 160, 0x648846e7 ++0, 105300, 160, 0xcac94cb3 ++0, 106200, 160, 0x55e551a4 ++0, 107100, 160, 0x767a5315 ++0, 108000, 160, 0xbfde4d2b ++0, 108900, 160, 0x29bf4613 ++0, 109800, 160, 0x8a8d5394 ++0, 110700, 160, 0x36f94dae ++0, 111600, 160, 0x4cbf50ba ++0, 112500, 160, 0x9af44d8b ++0, 113400, 160, 0x6e8a519e ++0, 114300, 160, 0x496348b7 ++0, 115200, 160, 0x95324eb2 ++0, 116100, 160, 0x5bfe5118 ++0, 117000, 160, 0xa1ff4c88 ++0, 117900, 160, 0x86c2500a ++0, 118800, 160, 0xc53353c5 ++0, 119700, 160, 0x062f52ee ++0, 120600, 160, 0x11cf522d ++0, 121500, 160, 0x054f5855 ++0, 122400, 160, 0x8c4e44e9 ++0, 123300, 160, 0x4d514fda ++0, 124200, 160, 0x5726568e ++0, 125100, 160, 0x281859ad ++0, 126000, 160, 0x3f3344f8 ++0, 126900, 160, 0x2cbb3ee5 ++0, 127800, 160, 0xa075551c ++0, 128700, 160, 0xafb25528 ++0, 129600, 160, 0x9221478a ++0, 130500, 160, 0x6cb15634 ++0, 131400, 160, 0xb5cf4523 ++0, 132300, 160, 0x8a7a4f2c ++0, 133200, 160, 0x278e553d ++0, 134100, 160, 0x49054ad3 ++0, 135000, 160, 0x5d7449bb ++0, 135900, 160, 0x67c346a0 ++0, 136800, 160, 0x5d915bf8 ++0, 137700, 160, 0x671355b2 ++0, 138600, 160, 0xdfa84ee6 ++0, 139500, 160, 0x4c3552d0 ++0, 140400, 160, 0x63a1483c ++0, 141300, 160, 0x14c151ba ++0, 142200, 160, 0xf7434d78 ++0, 143100, 160, 0x1c3652c9 ++0, 144000, 160, 0x035b51da ++0, 144900, 160, 0x2bf6496b ++0, 145800, 160, 0x50a14f14 ++0, 146700, 160, 0x518948f8 ++0, 147600, 160, 0x7e784331 ++0, 148500, 160, 0x73384dce ++0, 149400, 160, 0x11015066 ++0, 150300, 160, 0xacc5525c ++0, 151200, 160, 0xf75a5431 ++0, 152100, 160, 0xa78e4b8a ++0, 153000, 160, 0xd07955b0 ++0, 153900, 160, 0x63164a03 ++0, 154800, 160, 0x952f519e ++0, 155700, 160, 0xe5764f77 ++0, 156600, 160, 0xa9255738 ++0, 157500, 160, 0x65d64ce5 ++0, 158400, 160, 0x8ab7507c ++0, 159300, 160, 0xf5265251 ++0, 160200, 160, 0xa6a84d74 ++0, 161100, 160, 0xc2594fee ++0, 162000, 160, 0xdfae5056 ++0, 162900, 160, 0xa5a74c11 ++0, 163800, 160, 0x5fdf4a21 ++0, 164700, 160, 0x11014f8d ++0, 165600, 160, 0x08d0553f ++0, 166500, 160, 0x3036520e ++0, 167400, 160, 0xee3a464e ++0, 168300, 160, 0xbfd94949 ++0, 169200, 160, 0x21625176 ++0, 170100, 160, 0x6c714e8d ++0, 171000, 160, 0x055a4c05 ++0, 171900, 160, 0xc7f35347 ++0, 172800, 160, 0x82344b60 ++0, 173700, 160, 0x99854ce4 ++0, 174600, 160, 0x95504ec3 ++0, 175500, 160, 0xe245502a ++0, 176400, 160, 0xb0e14a4c ++0, 177300, 160, 0x09835b86 ++0, 178200, 160, 0xe9495220 ++0, 179100, 160, 0xce9b514f ++0, 180000, 160, 0xbaf85695 ++0, 180900, 160, 0x69aa3f1d ++0, 181800, 160, 0xd6a551b8 ++0, 182700, 160, 0x4eb956e6 ++0, 183600, 160, 0xdd6d4e58 ++0, 184500, 160, 0xba1f4814 ++0, 185400, 160, 0x4a604f48 ++0, 186300, 160, 0xa8995890 ++0, 187200, 160, 0x3a80616b ++0, 188100, 160, 0xfb796013 ++0, 189000, 160, 0x8eba5c12 ++0, 189900, 160, 0xd37859b9 ++0, 190800, 160, 0x19a857c8 ++0, 191700, 160, 0xec0e5a16 ++0, 192600, 160, 0xd5335159 ++0, 193500, 160, 0x560f4de7 ++0, 194400, 160, 0x06d354c8 ++0, 195300, 160, 0xdade5860 ++0, 196200, 160, 0x093a512c ++0, 197100, 160, 0xb37b5098 ++0, 198000, 160, 0x3eea537c ++0, 198900, 160, 0xf5c94f06 ++0, 199800, 160, 0x552c4bb2 ++0, 200700, 160, 0xea9a5a79 ++0, 201600, 160, 0xd2645494 ++0, 202500, 160, 0x5ba958ea ++0, 203400, 160, 0x54b559cf ++0, 204300, 160, 0x86bf5bba ++0, 205200, 160, 0xb89b6149 ++0, 206100, 160, 0x1e825314 ++0, 207000, 160, 0xf0d250cc ++0, 207900, 160, 0xc7ad53ba ++0, 208800, 160, 0x320c552f ++0, 209700, 160, 0xc62756f7 ++0, 210600, 160, 0xa41351f7 ++0, 211500, 160, 0x27ed4e78 ++0, 212400, 160, 0x8d6047bc ++0, 213300, 160, 0xa45c48d0 ++0, 214200, 160, 0x14da5400 ++0, 215100, 160, 0x48514dd2 ++0, 216000, 160, 0xec395318 ++0, 216900, 160, 0xf3c85e4a ++0, 217800, 160, 0x657a63ed ++0, 218700, 160, 0xcc975c4d ++0, 219600, 160, 0x86125dd4 ++0, 220500, 160, 0x6a3f6019 ++0, 221400, 160, 0x84c05aeb ++0, 222300, 160, 0xe68561f7 ++0, 223200, 160, 0x7ec763ae ++0, 224100, 160, 0x91bd5792 ++0, 225000, 160, 0xb9365c8e ++0, 225900, 160, 0x42d7587a ++0, 226800, 160, 0x80a45453 ++0, 227700, 160, 0x9ecf50c2 ++0, 228600, 160, 0xc8de5173 ++0, 229500, 160, 0x776952f7 ++0, 230400, 160, 0x45f856c0 ++0, 231300, 160, 0x729c4d73 ++0, 232200, 160, 0xfd364a18 ++0, 233100, 160, 0x709e587d ++0, 234000, 160, 0x288240e5 ++0, 234900, 160, 0x16a6493f ++0, 235800, 160, 0x76db596f ++0, 236700, 160, 0x16c24a51 ++0, 237600, 160, 0xc55b5a8f ++0, 238500, 160, 0x19024a2e ++0, 239400, 160, 0x16514d1b ++0, 240300, 160, 0x48bb5b82 ++0, 241200, 160, 0x5a6e4d80 ++0, 242100, 160, 0x6d404b0f ++0, 243000, 160, 0x57bc4e4a ++0, 243900, 160, 0xc10c5381 ++0, 244800, 160, 0x34bd51d9 ++0, 245700, 160, 0x5dcf52b7 ++0, 246600, 160, 0xf61f57a7 ++0, 247500, 160, 0x4e204934 ++0, 248400, 160, 0xe18b4a3f ++0, 249300, 160, 0xb81256e3 ++0, 250200, 160, 0x294047b2 ++0, 251100, 160, 0x3ad559df ++0, 252000, 160, 0xd28d4d86 ++0, 252900, 160, 0x67b75895 ++0, 253800, 160, 0x191357b0 ++0, 254700, 160, 0x8016556f ++0, 255600, 160, 0x62475c86 ++0, 256500, 160, 0x0c975bc9 ++0, 257400, 160, 0x901c5909 ++0, 258300, 160, 0x9909567d ++0, 259200, 160, 0xce715b99 ++0, 260100, 160, 0xae5062b1 ++0, 261000, 160, 0x5bd056d6 ++0, 261900, 160, 0xe3d3555a ++0, 262800, 160, 0xc4b1555c ++0, 263700, 160, 0x39c95649 ++0, 264600, 160, 0x50145d11 ++0, 265500, 160, 0xc0ba5307 ++0, 266400, 160, 0x182455a3 ++0, 267300, 160, 0x36c24e98 ++0, 268200, 160, 0x1b5b52d0 ++0, 269100, 160, 0xd38352d1 ++0, 270000, 160, 0x6a1d5d2a ++0, 270900, 160, 0x50f05c44 ++0, 271800, 160, 0xb2365dc1 ++0, 272700, 160, 0x10825934 ++0, 273600, 160, 0xcb4c61c2 ++0, 274500, 160, 0x578252ab ++0, 275400, 160, 0xed99596c ++0, 276300, 160, 0xdfec6305 ++0, 277200, 160, 0x97e2550a ++0, 278100, 160, 0xd60a56e1 ++0, 279000, 160, 0xb6c4535e ++0, 279900, 160, 0x4d2e536c ++0, 280800, 160, 0xdef85cc7 ++0, 281700, 160, 0xee985a98 ++0, 282600, 160, 0x006a4cdb ++0, 283500, 160, 0xd06652ad ++0, 284400, 160, 0xeeee4ed6 ++0, 285300, 160, 0xcb8b586d ++0, 286200, 160, 0x2ee4556e ++0, 287100, 160, 0x6d924c01 ++0, 288000, 160, 0x7ff257cc ++0, 288900, 160, 0x67df5710 ++0, 289800, 160, 0x0f704f29 ++0, 290700, 160, 0x19dc53a7 ++0, 291600, 160, 0xfbf44bc0 ++0, 292500, 160, 0x640b5718 ++0, 293400, 160, 0x2bfd4b91 ++0, 294300, 160, 0xaae049bf ++0, 295200, 160, 0xca3154f6 ++0, 296100, 160, 0x36064f2c ++0, 297000, 160, 0x28404919 ++0, 297900, 160, 0x9c944fe3 ++0, 298800, 160, 0xb4214c82 ++0, 299700, 160, 0x442c514d ++0, 300600, 160, 0x44434ea5 ++0, 301500, 160, 0x82a05aae ++0, 302400, 160, 0x4b86510d ++0, 303300, 160, 0x46844eab ++0, 304200, 160, 0xe5455deb ++0, 305100, 160, 0x60826550 ++0, 306000, 160, 0x3c5a5448 ++0, 306900, 160, 0x2db860c9 ++0, 307800, 160, 0x4d845b78 ++0, 308700, 160, 0x81dc5e23 ++0, 309600, 160, 0x78c95932 ++0, 310500, 160, 0xb5be57cd ++0, 311400, 160, 0x6fa45c65 ++0, 312300, 160, 0x4e085e2a ++0, 313200, 160, 0x50ee530c ++0, 314100, 160, 0x2bb85587 ++0, 315000, 160, 0x6d58614e ++0, 315900, 160, 0xcf4c5d69 ++0, 316800, 160, 0x3cbf5ffb ++0, 317700, 160, 0x452157d3 ++0, 318600, 160, 0x3cb55cd8 ++0, 319500, 160, 0x2bba5735 ++0, 320400, 160, 0x36a45670 ++0, 321300, 160, 0x23b85b8a ++0, 322200, 160, 0x9a255457 ++0, 323100, 160, 0x4e6956f3 ++0, 324000, 160, 0xa0714edc ++0, 324900, 160, 0x7dee4a3d ++0, 325800, 160, 0x86404bc9 ++0, 326700, 160, 0x358c50cd ++0, 327600, 160, 0x9eda47e8 ++0, 328500, 160, 0x3cfe522e ++0, 329400, 160, 0xddb95758 ++0, 330300, 160, 0x1a434a83 ++0, 331200, 160, 0xa8a450bb ++0, 332100, 160, 0x44e7530e ++0, 333000, 160, 0x59b5555a ++0, 333900, 160, 0x65404db1 ++0, 334800, 160, 0xcac15945 ++0, 335700, 160, 0x38864f17 ++0, 336600, 160, 0x61114f30 ++0, 337500, 160, 0x195542d8 ++0, 338400, 160, 0xacbb4c69 ++0, 339300, 160, 0xd0da4ab9 ++0, 340200, 160, 0x563d4eb6 ++0, 341100, 160, 0xd0ce503c ++0, 342000, 160, 0x8b684e15 ++0, 342900, 160, 0x711541d3 ++0, 343800, 160, 0xb28b5b9b ++0, 344700, 160, 0x48b145e4 ++0, 345600, 160, 0x908f5606 ++0, 346500, 160, 0x22c74f02 ++0, 347400, 160, 0x87274716 ++0, 348300, 160, 0xaa2351e6 ++0, 349200, 160, 0x2df5505a ++0, 350100, 160, 0x7999525c ++0, 351000, 160, 0x728a4b73 ++0, 351900, 160, 0xa67447ff ++0, 352800, 160, 0x28884a20 ++0, 353700, 160, 0x3ffa5840 ++0, 354600, 160, 0xd6265047 ++0, 355500, 160, 0x2f1553a8 ++0, 356400, 160, 0xac0653ec ++0, 357300, 160, 0x35844368 ++0, 358200, 160, 0x6e1553ba ++0, 359100, 160, 0xb62a4c88 ++0, 360000, 160, 0x88a04ffc ++0, 360900, 160, 0x947e525e ++0, 361800, 160, 0x3dd24f98 ++0, 362700, 160, 0x942e542e ++0, 363600, 160, 0xdb985211 ++0, 364500, 160, 0x615a5022 ++0, 365400, 160, 0x71c04569 ++0, 366300, 160, 0xbbbe4f41 ++0, 367200, 160, 0x62074e0b ++0, 368100, 160, 0x2c5d56c7 ++0, 369000, 160, 0x34344c18 ++0, 369900, 160, 0xc57d4c22 ++0, 370800, 160, 0xb273560d ++0, 371700, 160, 0x7e985229 ++0, 372600, 160, 0x2dd3542d ++0, 373500, 160, 0x39645000 ++0, 374400, 160, 0x1b3f4d9e ++0, 375300, 160, 0x0bbf5ed2 ++0, 376200, 160, 0xc81f5608 ++0, 377100, 160, 0xe82e569e ++0, 378000, 160, 0x34df537d ++0, 378900, 160, 0x53175837 ++0, 379800, 160, 0xbb76517f ++0, 380700, 160, 0xd5a25737 ++0, 381600, 160, 0x58eb4f3d ++0, 382500, 160, 0x8f6e51d3 ++0, 383400, 160, 0x1fd85602 ++0, 384300, 160, 0xef2a4ee7 ++0, 385200, 160, 0x0e6e58f4 ++0, 386100, 160, 0x80345497 ++0, 387000, 160, 0x710150a1 ++0, 387900, 160, 0x32fb51db ++0, 388800, 160, 0x7efd564c ++0, 389700, 160, 0xf6604f26 ++0, 390600, 160, 0xc0954d7e ++0, 391500, 160, 0x27705072 ++0, 392400, 160, 0xd26f5958 ++0, 393300, 160, 0x2c2552cd ++0, 394200, 160, 0xd14056b1 ++0, 395100, 160, 0x11f356d2 ++0, 396000, 160, 0x93b35efd ++0, 396900, 160, 0xa6d65ae7 ++0, 397800, 160, 0x95015177 ++0, 398700, 160, 0x2e6157e8 ++0, 399600, 160, 0xb90c5021 ++0, 400500, 160, 0xf39155c9 ++0, 401400, 160, 0xd6ad544b ++0, 402300, 160, 0x4b8a5b98 ++0, 403200, 160, 0x90a94f2d ++0, 404100, 160, 0x46a04f3f ++0, 405000, 160, 0x542b5cd1 ++0, 405900, 160, 0xebaa5710 ++0, 406800, 160, 0x504854a0 ++0, 407700, 160, 0xbd9d53b5 ++0, 408600, 160, 0x91524fed ++0, 409500, 160, 0x9b7a582d ++0, 410400, 160, 0xa4f258cf ++0, 411300, 160, 0x46274dda ++0, 412200, 160, 0xc0335ba9 ++0, 413100, 160, 0xe59c5c74 ++0, 414000, 160, 0xc2ee5ab0 ++0, 414900, 160, 0x3e035996 ++0, 415800, 160, 0x63e25521 ++0, 416700, 160, 0xc09851af ++0, 417600, 160, 0xb8225715 ++0, 418500, 160, 0x74355bfb ++0, 419400, 160, 0xf4c75adf ++0, 420300, 160, 0x2f8b56cd ++0, 421200, 160, 0xb4705795 ++0, 422100, 160, 0xb4b25506 ++0, 423000, 160, 0xaadb54f8 ++0, 423900, 160, 0xe6d158aa ++0, 424800, 160, 0xed64614f ++0, 425700, 160, 0x80195732 ++0, 426600, 160, 0xa8995f0e ++0, 427500, 160, 0xdc4a520d ++0, 428400, 160, 0x071a5bae ++0, 429300, 160, 0xce1b5ae9 ++0, 430200, 160, 0x85e25804 ++0, 431100, 160, 0x435e555f ++0, 432000, 160, 0xe4154ef4 ++0, 432900, 160, 0xeff857b4 ++0, 433800, 160, 0xc9e25868 ++0, 434700, 160, 0x6e6961eb ++0, 435600, 160, 0x361e45e6 ++0, 436500, 160, 0xf8a94988 ++0, 437400, 160, 0x9de758b3 ++0, 438300, 160, 0x2e65533e ++0, 439200, 160, 0x3f89422d ++0, 440100, 160, 0x77fd56a5 ++0, 441000, 160, 0x91104845 ++0, 441900, 160, 0x2eeb5491 ++0, 442800, 160, 0x6a5348c4 ++0, 443700, 160, 0xe0954882 ++0, 444600, 160, 0x7e915761 ++0, 445500, 160, 0x2cb5531f ++0, 446400, 160, 0xe1dc4ecd ++0, 447300, 160, 0xbf6b4e61 ++0, 448200, 160, 0x3d6b5746 ++0, 449100, 160, 0xe8bd5077 ++0, 450000, 160, 0xd38d5921 ++0, 450900, 160, 0xfc534e38 ++0, 451800, 160, 0xd361475b ++0, 452700, 160, 0x4d5152c7 ++0, 453600, 160, 0xb6684d11 ++0, 454500, 160, 0xd2e25864 ++0, 455400, 160, 0x02ec536a ++0, 456300, 160, 0x27ac550e ++0, 457200, 160, 0xe8d44e2d ++0, 458100, 160, 0x520152c8 ++0, 459000, 160, 0xace747ea ++0, 459900, 160, 0x773a4ee3 ++0, 460800, 160, 0x7dd1559f ++0, 461700, 160, 0x124453a8 ++0, 462600, 160, 0x04154991 ++0, 463500, 160, 0x3c794d98 ++0, 464400, 160, 0x309f4e47 ++0, 465300, 160, 0x98c74a48 ++0, 466200, 160, 0xd0c34bcc ++0, 467100, 160, 0xfa304e19 ++0, 468000, 160, 0x69505201 ++0, 468900, 160, 0x2e714ac7 ++0, 469800, 160, 0x076654a3 ++0, 470700, 160, 0xc6674e27 ++0, 471600, 160, 0x1adf4dd9 ++0, 472500, 160, 0x4408507e ++0, 473400, 160, 0xd2654d94 ++0, 474300, 160, 0x97a65cc0 ++0, 475200, 160, 0xb53251f9 ++0, 476100, 160, 0xd498584b ++0, 477000, 160, 0x46a058c8 ++0, 477900, 160, 0xa2f85cbd ++0, 478800, 160, 0x43b856fb ++0, 479700, 160, 0xdeb957ba ++0, 480600, 160, 0x3064580a ++0, 481500, 160, 0xe86357a5 ++0, 482400, 160, 0x9b974d00 ++0, 483300, 160, 0x66ee4ff3 ++0, 484200, 160, 0x0b9958f7 ++0, 485100, 160, 0xc3754d0a ++0, 486000, 160, 0x42314c33 ++0, 486900, 160, 0x4550555f ++0, 487800, 160, 0x0f064e4c ++0, 488700, 160, 0xe569596d ++0, 489600, 160, 0x056c4751 ++0, 490500, 160, 0xdc1049fc ++0, 491400, 160, 0x63c54a1e ++0, 492300, 160, 0xb402518e ++0, 493200, 160, 0xaf0d4b19 ++0, 494100, 160, 0xa22b4c5b ++0, 495000, 160, 0x28084bbf ++0, 495900, 160, 0x10495224 ++0, 496800, 160, 0x4cb94993 ++0, 497700, 160, 0x17c15457 ++0, 498600, 160, 0xbd834d6d ++0, 499500, 160, 0x6ca25235 ++0, 500400, 160, 0x84b74f89 ++0, 501300, 160, 0xdeef4e76 ++0, 502200, 160, 0x6ab05188 ++0, 503100, 160, 0xa91c4646 ++0, 504000, 160, 0xad574e7d ++0, 504900, 160, 0xba264d69 ++0, 505800, 160, 0xd8734dd0 ++0, 506700, 160, 0x69f25581 ++0, 507600, 160, 0x3b8e4ae9 ++0, 508500, 160, 0xb1124607 ++0, 509400, 160, 0xd78e4e4f ++0, 510300, 160, 0x05a1504f ++0, 511200, 160, 0x3e705270 ++0, 512100, 160, 0x1e144b3b ++0, 513000, 160, 0xbb0b5416 ++0, 513900, 160, 0xc26f5b45 ++0, 514800, 160, 0x14224ab9 ++0, 515700, 160, 0x2bbd4837 ++0, 516600, 160, 0xd2bf4e60 ++0, 517500, 160, 0xbeec506c ++0, 518400, 160, 0x2cd34d3a ++0, 519300, 160, 0x85134fc6 ++0, 520200, 160, 0xdb9a4ac2 ++0, 521100, 160, 0x92715256 ++0, 522000, 160, 0xff395098 ++0, 522900, 160, 0xa5ec560c ++0, 523800, 160, 0xce95534b ++0, 524700, 160, 0xe36f46f1 ++0, 525600, 160, 0x45f74a58 ++0, 526500, 160, 0x02d05440 ++0, 527400, 160, 0xa005529f ++0, 528300, 160, 0xae0f3f22 ++0, 529200, 160, 0x3f984eb0 ++0, 530100, 160, 0xc5bd5015 ++0, 531000, 160, 0xf4504c53 ++0, 531900, 160, 0x7f4044c5 ++0, 532800, 160, 0x82dd4bab ++0, 533700, 160, 0x7a0d5122 ++0, 534600, 160, 0xd0da5271 ++0, 535500, 160, 0x67d14e3e ++0, 536400, 160, 0x54564f42 ++0, 537300, 160, 0x77df4e0a ++0, 538200, 160, 0x0c4a4f70 ++0, 539100, 160, 0xb2944f40 ++0, 540000, 160, 0xe57a52de ++0, 540900, 160, 0x7d994ed1 ++0, 541800, 160, 0x9dc35763 ++0, 542700, 160, 0x8d0a4da9 ++0, 543600, 160, 0x0c6449a4 ++0, 544500, 160, 0xc73c503a ++0, 545400, 160, 0x52904cbe ++0, 546300, 160, 0x49824c2e ++0, 547200, 160, 0xb7e14e0b ++0, 548100, 160, 0x9745548e ++0, 549000, 160, 0xdafb4c20 ++0, 549900, 160, 0x1aa84d67 ++0, 550800, 160, 0x64bc5033 ++0, 551700, 160, 0x9e2e5a05 ++0, 552600, 160, 0x69144bc5 ++0, 553500, 160, 0xce1253fa ++0, 554400, 160, 0x359f4c15 ++0, 555300, 160, 0xdba74ed0 ++0, 556200, 160, 0xea1453b8 ++0, 557100, 160, 0xccdf49d3 ++0, 558000, 160, 0xeb324750 ++0, 558900, 160, 0x62b14ad4 ++0, 559800, 160, 0x446e50c0 ++0, 560700, 160, 0x111e5151 ++0, 561600, 160, 0x6be84f3a ++0, 562500, 160, 0xf5cf4e42 ++0, 563400, 160, 0xcc995459 ++0, 564300, 160, 0x0faf5172 ++0, 565200, 160, 0x31334f66 ++0, 566100, 160, 0x20ba52c0 ++0, 567000, 160, 0xc7cc4975 ++0, 567900, 160, 0x9e7a51ba ++0, 568800, 160, 0x52884ff1 ++0, 569700, 160, 0xc7a84cfd ++0, 570600, 160, 0x5ae64c22 ++0, 571500, 160, 0x68125a92 ++0, 572400, 160, 0x39ed54f1 ++0, 573300, 160, 0xfa0a4ad1 ++0, 574200, 160, 0xe8c8590c ++0, 575100, 160, 0x5f555576 ++0, 576000, 160, 0xaf7a57a1 ++0, 576900, 160, 0x858257e9 ++0, 577800, 160, 0x1223523e ++0, 578700, 160, 0x446954a1 ++0, 579600, 160, 0xfbe952d9 ++0, 580500, 160, 0xd56259ff ++0, 581400, 160, 0xc4fa4f44 ++0, 582300, 160, 0x77cc57f6 ++0, 583200, 160, 0x53d3573d ++0, 584100, 160, 0x085e4ff9 ++0, 585000, 160, 0x7a4e5410 ++0, 585900, 160, 0xb4ad5794 ++0, 586800, 160, 0x71255738 ++0, 587700, 160, 0x36724918 ++0, 588600, 160, 0x370e5974 ++0, 589500, 160, 0xb709596c ++0, 590400, 160, 0x89b05052 ++0, 591300, 160, 0x74e550ce ++0, 592200, 160, 0x6e2c5a49 ++0, 593100, 160, 0x4dfa5b50 ++0, 594000, 160, 0x80764c70 ++0, 594900, 160, 0xc1d14fc6 ++0, 595800, 160, 0x53e746b3 ++0, 596700, 160, 0x728350c0 ++0, 597600, 160, 0x9aa6500e ++0, 598500, 160, 0x60985454 ++0, 599400, 160, 0xa0c54b6f ++0, 600300, 160, 0xe3b157ea ++0, 601200, 160, 0xce86573b ++0, 602100, 160, 0x9dad5535 ++0, 603000, 160, 0xb3094af9 ++0, 603900, 160, 0x2d1456ed ++0, 604800, 160, 0x328248b9 ++0, 605700, 160, 0x4ffb4f52 ++0, 606600, 160, 0x71fe53de ++0, 607500, 160, 0x0d114e92 ++0, 608400, 160, 0x37065510 ++0, 609300, 160, 0x426c4c07 ++0, 610200, 160, 0x58e3528b ++0, 611100, 160, 0x71674484 ++0, 612000, 160, 0x45934ee1 ++0, 612900, 160, 0x4e914b31 ++0, 613800, 160, 0x525b4ec2 ++0, 614700, 160, 0x4393563d ++0, 615600, 160, 0xb10154e9 ++0, 616500, 160, 0x23b15a4d ++0, 617400, 160, 0x6d995220 ++0, 618300, 160, 0xcd2949fd ++0, 619200, 160, 0x67234f75 ++0, 620100, 160, 0x00cc4cdb ++0, 621000, 160, 0x97c35574 ++0, 621900, 160, 0xc0855753 ++0, 622800, 160, 0xf4e650a5 ++0, 623700, 160, 0x95b14bc2 ++0, 624600, 160, 0x04d948dc ++0, 625500, 160, 0x284d4d02 ++0, 626400, 160, 0xfb0d4cd9 ++0, 627300, 160, 0x0e515126 ++0, 628200, 160, 0xb4055a86 ++0, 629100, 160, 0x0bbe4f68 ++0, 630000, 160, 0xf1b848af ++0, 630900, 160, 0x7d154853 ++0, 631800, 160, 0x78225418 ++0, 632700, 160, 0xfb2f523e ++0, 633600, 160, 0xa6d34ea6 ++0, 634500, 160, 0xe4264e30 ++0, 635400, 160, 0x113750aa ++0, 636300, 160, 0x4073529b ++0, 637200, 160, 0xd1754dda ++0, 638100, 160, 0x1b495413 ++0, 639000, 160, 0x29f94cd8 ++0, 639900, 160, 0x49004a53 ++0, 640800, 160, 0x1fec4de4 ++0, 641700, 160, 0x7d6b4670 ++0, 642600, 160, 0x626c4c9f ++0, 643500, 160, 0x79265234 ++0, 644400, 160, 0xab765b86 ++0, 645300, 160, 0xe9ae4d26 ++0, 646200, 160, 0xeee1481f ++0, 647100, 160, 0x289d5287 ++0, 648000, 160, 0xb5524e8b ++0, 648900, 160, 0x7e715764 ++0, 649800, 160, 0xb1b25091 ++0, 650700, 160, 0xf1a946f6 ++0, 651600, 160, 0x57dc51bd ++0, 652500, 160, 0x4c0b4f14 ++0, 653400, 160, 0xdc1f4930 ++0, 654300, 160, 0x79d75057 ++0, 655200, 160, 0x22bd52df ++0, 656100, 160, 0x963a5562 ++0, 657000, 160, 0x7e475303 ++0, 657900, 160, 0x2c065494 ++0, 658800, 160, 0xb0514720 ++0, 659700, 160, 0xbc734849 ++0, 660600, 160, 0xf4924e4d ++0, 661500, 160, 0xe50f44c9 ++0, 662400, 160, 0x978c4ce8 ++0, 663300, 160, 0x302e51c2 ++0, 664200, 160, 0x262b4a60 ++0, 665100, 160, 0xf95f4e99 ++0, 666000, 160, 0x7465504a ++0, 666900, 160, 0xab0e5108 ++0, 667800, 160, 0xbec15395 ++0, 668700, 160, 0x4f2c5139 ++0, 669600, 160, 0x26444deb ++0, 670500, 160, 0xee4c4b15 ++0, 671400, 160, 0x8bc350e1 ++0, 672300, 160, 0xd0744a5a ++0, 673200, 160, 0xfee64d9d ++0, 674100, 160, 0x234c50b6 ++0, 675000, 160, 0x8592482c ++0, 675900, 160, 0x5e8b5308 ++0, 676800, 160, 0x4f9848c7 ++0, 677700, 160, 0x939d4faa ++0, 678600, 160, 0x797654f1 ++0, 679500, 160, 0x15d24d9b ++0, 680400, 160, 0xa6e54bd2 ++0, 681300, 160, 0x755e4c90 ++0, 682200, 160, 0xcd334bce ++0, 683100, 160, 0xfc1746e9 ++0, 684000, 160, 0x81f04dd5 ++0, 684900, 160, 0x44b35080 ++0, 685800, 160, 0x91e65217 ++0, 686700, 160, 0x492150af ++0, 687600, 160, 0xf73e58ec ++0, 688500, 160, 0xf988538a ++0, 689400, 160, 0x0dee4c10 ++0, 690300, 160, 0x2c9f4c23 ++0, 691200, 160, 0x8c1e4e08 ++0, 692100, 160, 0x25bb5286 ++0, 693000, 160, 0xd0ed469b ++0, 693900, 160, 0x71eb50e8 ++0, 694800, 160, 0x249f4d26 ++0, 695700, 160, 0x9662498f ++0, 696600, 160, 0x49ee55e2 ++0, 697500, 160, 0x54d9491b ++0, 698400, 160, 0x4c675649 ++0, 699300, 160, 0x0e4b4b34 ++0, 700200, 160, 0x776f4995 ++0, 701100, 160, 0x722656b2 ++0, 702000, 160, 0x081d4b6f ++0, 702900, 160, 0xf70746fe ++0, 703800, 160, 0x08b151da ++0, 704700, 160, 0x6b255328 ++0, 705600, 160, 0xeb2b586a ++0, 706500, 160, 0x812b4444 ++0, 707400, 160, 0x1e16533f ++0, 708300, 160, 0xc1244760 ++0, 709200, 160, 0x67584d87 ++0, 710100, 160, 0xde8b5726 ++0, 711000, 160, 0xe96d4e3e ++0, 711900, 160, 0x41174c98 ++0, 712800, 160, 0x4cdd4cd8 ++0, 713700, 160, 0xfb724b64 ++0, 714600, 160, 0x78f154df ++0, 715500, 160, 0x97e1476d ++0, 716400, 160, 0x6f034e7f ++0, 717300, 160, 0x93b240df ++0, 718200, 160, 0xc4d040e6 ++0, 719100, 160, 0xe47744a4 ++0, 720000, 160, 0x87a950ff ++0, 720900, 160, 0x7079491b ++0, 721800, 160, 0x89f0491a ++0, 722700, 160, 0x70b8467e ++0, 723600, 160, 0x20945294 ++0, 724500, 160, 0x2d5c4919 ++0, 725400, 160, 0x1ed44c78 ++0, 726300, 160, 0x93d74a5f ++0, 727200, 160, 0x300e490e ++0, 728100, 160, 0x8249558d ++0, 729000, 160, 0x630a4f57 ++0, 729900, 160, 0xdd6e475f ++0, 730800, 160, 0xf50941e5 ++0, 731700, 160, 0x1fe44bea ++0, 732600, 160, 0x03be5469 ++0, 733500, 160, 0x7ece4f4c ++0, 734400, 160, 0x31f953dd ++0, 735300, 160, 0x22a44b7d ++0, 736200, 160, 0x1f5e5562 ++0, 737100, 160, 0x771b5688 ++0, 738000, 160, 0x7d1c4d45 ++0, 738900, 160, 0x6bc45cd0 ++0, 739800, 160, 0x8f714c36 ++0, 740700, 160, 0xfb1f4c87 ++0, 741600, 160, 0x1f8a4b36 ++0, 742500, 160, 0xee5c451a ++0, 743400, 160, 0xd56950ac ++0, 744300, 160, 0x529057f6 ++0, 745200, 160, 0x336641fd ++0, 746100, 160, 0xa0dd5a66 ++0, 747000, 160, 0x5f4b5248 ++0, 747900, 160, 0xb6ef49a3 ++0, 748800, 160, 0x07705f19 ++0, 749700, 160, 0x3fce4bbb ++0, 750600, 160, 0xda395511 ++0, 751500, 160, 0x1ecf5145 ++0, 752400, 160, 0x88a547ab ++0, 753300, 160, 0x6c6849be ++0, 754200, 160, 0x979c4e97 ++0, 755100, 160, 0x171854b3 ++0, 756000, 160, 0x9a715283 ++0, 756900, 160, 0x064e50ac ++0, 757800, 160, 0xc2fb4e94 ++0, 758700, 160, 0x708146f5 ++0, 759600, 160, 0x1ca45198 ++0, 760500, 160, 0x332d4869 ++0, 761400, 160, 0xc2ff4656 ++0, 762300, 160, 0x0747552e ++0, 763200, 160, 0x0c3d4ba8 ++0, 764100, 160, 0x72934dab ++0, 765000, 160, 0xbb1e5860 ++0, 765900, 160, 0x526d4cea ++0, 766800, 160, 0xa4c445d6 ++0, 767700, 160, 0x70cd49ba ++0, 768600, 160, 0x008c53a7 ++0, 769500, 160, 0xf7174bca ++0, 770400, 160, 0x0bab4936 ++0, 771300, 160, 0x59e5564d ++0, 772200, 160, 0x33045087 ++0, 773100, 160, 0xde7454f0 ++0, 774000, 160, 0x31184cc3 ++0, 774900, 160, 0x37984bb3 ++0, 775800, 160, 0xf5e052d4 ++0, 776700, 160, 0x23ca4b42 ++0, 777600, 160, 0xbe2a572b ++0, 778500, 160, 0x9a91538d ++0, 779400, 160, 0x8a994c40 ++0, 780300, 160, 0x5dea51ee ++0, 781200, 160, 0x1b53524c ++0, 782100, 160, 0xd9e75227 ++0, 783000, 160, 0x58384c3b ++0, 783900, 160, 0x4a1b53b2 ++0, 784800, 160, 0xc2a3458a ++0, 785700, 160, 0x7f68502d ++0, 786600, 160, 0x85475559 ++0, 787500, 160, 0xd0d25472 ++0, 788400, 160, 0x4c0d4bbf ++0, 789300, 160, 0xcad352df ++0, 790200, 160, 0x17904c97 ++0, 791100, 160, 0x4e774b8e ++0, 792000, 160, 0x21905952 ++0, 792900, 160, 0xc2d950cd ++0, 793800, 160, 0xfdea55e6 ++0, 794700, 160, 0x22ca4e37 ++0, 795600, 160, 0x1143562a ++0, 796500, 160, 0xe83c583e ++0, 797400, 160, 0xba544b27 ++0, 798300, 160, 0x1e8c50e4 ++0, 799200, 160, 0xf7ca4d2a ++0, 800100, 160, 0x67764579 ++0, 801000, 160, 0x40d74f42 ++0, 801900, 160, 0x88e35360 ++0, 802800, 160, 0xda3f4f5b ++0, 803700, 160, 0x19c1522f ++0, 804600, 160, 0x93ce4f78 ++0, 805500, 160, 0xf65447ba ++0, 806400, 160, 0xc0bc4e5a ++0, 807300, 160, 0x4915572b ++0, 808200, 160, 0x1651460b ++0, 809100, 160, 0xffe552a5 ++0, 810000, 160, 0x5bd351ab ++0, 810900, 160, 0xbbd85034 ++0, 811800, 160, 0xb9ff505f ++0, 812700, 160, 0xfc104eaf ++0, 813600, 160, 0xdaa74d6c ++0, 814500, 160, 0x34b04d78 ++0, 815400, 160, 0x1e924f70 ++0, 816300, 160, 0x0d46512d ++0, 817200, 160, 0x0d115950 ++0, 818100, 160, 0x62de55a4 ++0, 819000, 160, 0x58d652ab ++0, 819900, 160, 0x1776584e ++0, 820800, 160, 0x60175a2b ++0, 821700, 160, 0x4d714c82 ++0, 822600, 160, 0xe13c4ce0 ++0, 823500, 160, 0x7cd15464 ++0, 824400, 160, 0x6c87571a ++0, 825300, 160, 0x1abe4f07 ++0, 826200, 160, 0x039d5661 ++0, 827100, 160, 0x0eba5909 ++0, 828000, 160, 0xa46e51ec ++0, 828900, 160, 0x9be44eb7 ++0, 829800, 160, 0xe0634aad ++0, 830700, 160, 0xcd53530b ++0, 831600, 160, 0x12cd482c ++0, 832500, 160, 0x71884634 ++0, 833400, 160, 0xd5845743 ++0, 834300, 160, 0xacd1502c ++0, 835200, 160, 0x04795031 ++0, 836100, 160, 0xf0df54b9 ++0, 837000, 160, 0x43aa5155 ++0, 837900, 160, 0x316a4988 ++0, 838800, 160, 0xfbc64f8a ++0, 839700, 160, 0xda084e8e ++0, 840600, 160, 0x3cc34ce2 ++0, 841500, 160, 0xbfc055d8 ++0, 842400, 160, 0x20ef4876 ++0, 843300, 160, 0x035a5660 ++0, 844200, 160, 0xbc7255be ++0, 845100, 160, 0xba514f44 ++0, 846000, 160, 0x868c4c9c ++0, 846900, 160, 0x83494f04 ++0, 847800, 160, 0xa452521a ++0, 848700, 160, 0x2ed04f65 ++0, 849600, 160, 0x2e3e592d ++0, 850500, 160, 0x82bc4763 ++0, 851400, 160, 0x339950db ++0, 852300, 160, 0x5bb64eff ++0, 853200, 160, 0x347c4d85 ++0, 854100, 160, 0x25e949a3 ++0, 855000, 160, 0xbdf649a8 ++0, 855900, 160, 0x498650f3 ++0, 856800, 160, 0x2a6f4e60 ++0, 857700, 160, 0x661e5697 ++0, 858600, 160, 0x5d6150ca ++0, 859500, 160, 0xe7c74b8f ++0, 860400, 160, 0x1ae148da ++0, 861300, 160, 0xaeef485d ++0, 862200, 160, 0x105650c6 ++0, 863100, 160, 0xc1c45376 ++0, 864000, 160, 0x83c55011 ++0, 864900, 160, 0x77025597 ++0, 865800, 160, 0x324250b7 ++0, 866700, 160, 0x5cdc570f ++0, 867600, 160, 0x292e52a1 ++0, 868500, 160, 0x8d7a5090 ++0, 869400, 160, 0x32fc54e4 ++0, 870300, 160, 0x50984e8b ++0, 871200, 160, 0x07f442a0 ++0, 872100, 160, 0xc91c4fc3 ++0, 873000, 160, 0x06cf53d7 ++0, 873900, 160, 0xa66c5923 ++0, 874800, 160, 0xc2015120 ++0, 875700, 160, 0xedfa50c4 ++0, 876600, 160, 0xe4c85fb5 ++0, 877500, 160, 0xcd7b4c65 ++0, 878400, 160, 0xb22353c1 ++0, 879300, 160, 0x298c5996 ++0, 880200, 160, 0xefce51db ++0, 881100, 160, 0x6df74ee3 ++0, 882000, 160, 0x7c46496b ++0, 882900, 160, 0x910a48a4 ++0, 883800, 160, 0xbf504b1e ++0, 884700, 160, 0x096947e8 ++0, 885600, 160, 0x4a07629d ++0, 886500, 160, 0x577b43c1 ++0, 887400, 160, 0x939e4d6d ++0, 888300, 160, 0x486e48ac ++0, 889200, 160, 0x50064871 ++0, 890100, 160, 0x4a255534 ++0, 891000, 160, 0xc80d4618 ++0, 891900, 160, 0xf18a4780 ++0, 892800, 160, 0x1c274dd4 ++0, 893700, 160, 0x2f3e4f7c ++0, 894600, 160, 0x44b24cc2 ++0, 895500, 160, 0x89b451f4 ++0, 896400, 160, 0x06515b65 ++0, 897300, 160, 0xc5b857ce ++0, 898200, 160, 0xa47b47a7 ++0, 899100, 160, 0xfb375448 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g729-1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g729-1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/g729-1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/g729-1 2012-05-14 14:08:55.657366608 +0200 +@@ -0,0 +1,1000 @@ ++0, 0, 160, 0xf7e550f0 ++0, 900, 160, 0x42794ea8 ++0, 1800, 160, 0xfe023e42 ++0, 2700, 160, 0xc1ae40e3 ++0, 3600, 160, 0xee6d4bf1 ++0, 4500, 160, 0x107451d7 ++0, 5400, 160, 0x40cb4ba4 ++0, 6300, 160, 0x90504e5e ++0, 7200, 160, 0xf6f3531d ++0, 8100, 160, 0x48664ea0 ++0, 9000, 160, 0xa30458e1 ++0, 9900, 160, 0x00b74aa2 ++0, 10800, 160, 0x95234e49 ++0, 11700, 160, 0x9cf24a94 ++0, 12600, 160, 0x4f2952f4 ++0, 13500, 160, 0x658353db ++0, 14400, 160, 0x98ef4d79 ++0, 15300, 160, 0x765d5472 ++0, 16200, 160, 0xc6e25262 ++0, 17100, 160, 0x33334993 ++0, 18000, 160, 0xfa104dc5 ++0, 18900, 160, 0x03ee5530 ++0, 19800, 160, 0x52c54e0e ++0, 20700, 160, 0xbd744638 ++0, 21600, 160, 0x7775519f ++0, 22500, 160, 0xd22f499e ++0, 23400, 160, 0x26af4eec ++0, 24300, 160, 0x37474ed9 ++0, 25200, 160, 0x6b19548d ++0, 26100, 160, 0x4a3449b7 ++0, 27000, 160, 0x2bed5231 ++0, 27900, 160, 0x556d5349 ++0, 28800, 160, 0xbb6c5227 ++0, 29700, 160, 0xea354b4d ++0, 30600, 160, 0xf35f4b7d ++0, 31500, 160, 0x9dcb4e9d ++0, 32400, 160, 0xc81f5ac2 ++0, 33300, 160, 0xfa054cfd ++0, 34200, 160, 0x0c554e62 ++0, 35100, 160, 0x7ffa5250 ++0, 36000, 160, 0x7e5148ec ++0, 36900, 160, 0x95bc4d69 ++0, 37800, 160, 0xf34a5644 ++0, 38700, 160, 0xcaa3493d ++0, 39600, 160, 0xa44745dc ++0, 40500, 160, 0x320355c0 ++0, 41400, 160, 0xbd1e5670 ++0, 42300, 160, 0xfe3250cd ++0, 43200, 160, 0xce7a574c ++0, 44100, 160, 0x09b04f6e ++0, 45000, 160, 0x035759c8 ++0, 45900, 160, 0x713458c7 ++0, 46800, 160, 0x9a75494b ++0, 47700, 160, 0x99114fef ++0, 48600, 160, 0x129251f0 ++0, 49500, 160, 0x4eb845f2 ++0, 50400, 160, 0x5d064da5 ++0, 51300, 160, 0x5a8e4a34 ++0, 52200, 160, 0x5b784608 ++0, 53100, 160, 0x1ca7546a ++0, 54000, 160, 0x327e5cbf ++0, 54900, 160, 0xd7ae4bc3 ++0, 55800, 160, 0xba3f55b4 ++0, 56700, 160, 0x09fe4ca7 ++0, 57600, 160, 0x347248ba ++0, 58500, 160, 0xf0bf52ff ++0, 59400, 160, 0x3500507e ++0, 60300, 160, 0x30e65135 ++0, 61200, 160, 0x390a5201 ++0, 62100, 160, 0xf0dc5bca ++0, 63000, 160, 0x69b94f64 ++0, 63900, 160, 0x6ac04cf6 ++0, 64800, 160, 0xbc014cf4 ++0, 65700, 160, 0x4b564eca ++0, 66600, 160, 0x33e44e85 ++0, 67500, 160, 0xe39e5343 ++0, 68400, 160, 0xebf64c80 ++0, 69300, 160, 0x5a92562b ++0, 70200, 160, 0xe0075c88 ++0, 71100, 160, 0x59bd55e8 ++0, 72000, 160, 0xe6ca4ef2 ++0, 72900, 160, 0xea9a4df2 ++0, 73800, 160, 0xf53c4bf6 ++0, 74700, 160, 0x977a4f32 ++0, 75600, 160, 0xe5894eb2 ++0, 76500, 160, 0x956c4c28 ++0, 77400, 160, 0xdff74c3d ++0, 78300, 160, 0xace74db7 ++0, 79200, 160, 0x00e74ef5 ++0, 80100, 160, 0x6633560a ++0, 81000, 160, 0xd63647c5 ++0, 81900, 160, 0xff144eef ++0, 82800, 160, 0xc5fe4d51 ++0, 83700, 160, 0x5c244c7c ++0, 84600, 160, 0x95be50f1 ++0, 85500, 160, 0x74d84b77 ++0, 86400, 160, 0x1e965711 ++0, 87300, 160, 0x7ae45ad7 ++0, 88200, 160, 0xf9cd5920 ++0, 89100, 160, 0xf0064ea9 ++0, 90000, 160, 0xec645244 ++0, 90900, 160, 0x8330539a ++0, 91800, 160, 0x4a5d5023 ++0, 92700, 160, 0x706153d7 ++0, 93600, 160, 0xd6e0520f ++0, 94500, 160, 0x0bd9586f ++0, 95400, 160, 0xc1554dec ++0, 96300, 160, 0x89be4bde ++0, 97200, 160, 0x0c2a49c0 ++0, 98100, 160, 0xc18d498a ++0, 99000, 160, 0xc36147e1 ++0, 99900, 160, 0x99de4d4b ++0, 100800, 160, 0x2b9d542b ++0, 101700, 160, 0x062b52c9 ++0, 102600, 160, 0x9dcf542e ++0, 103500, 160, 0x641f58b9 ++0, 104400, 160, 0x114c51ff ++0, 105300, 160, 0x78e04b0e ++0, 106200, 160, 0xfec74535 ++0, 107100, 160, 0x71d54cd3 ++0, 108000, 160, 0xee9e5289 ++0, 108900, 160, 0x142354d9 ++0, 109800, 160, 0x051e4ddc ++0, 110700, 160, 0x358146b8 ++0, 111600, 160, 0x4dec58eb ++0, 112500, 160, 0xd0944f04 ++0, 113400, 160, 0xdc025a99 ++0, 114300, 160, 0x6b355402 ++0, 115200, 160, 0x1c0b5a6d ++0, 116100, 160, 0xa3b34bc8 ++0, 117000, 160, 0x92604eb7 ++0, 117900, 160, 0x6f2f5465 ++0, 118800, 160, 0xcb565361 ++0, 119700, 160, 0x8bfb50a3 ++0, 120600, 160, 0xf9114e99 ++0, 121500, 160, 0x11065580 ++0, 122400, 160, 0x903550c8 ++0, 123300, 160, 0xe7aa3da8 ++0, 124200, 160, 0x13f34e01 ++0, 125100, 160, 0x4c3b4c0a ++0, 126000, 160, 0x08e64c60 ++0, 126900, 160, 0xffcd6176 ++0, 127800, 160, 0x09684f13 ++0, 128700, 160, 0xd8a646b5 ++0, 129600, 160, 0xc07355f0 ++0, 130500, 160, 0xe836515b ++0, 131400, 160, 0x935741a5 ++0, 132300, 160, 0x68f85160 ++0, 133200, 160, 0x669a4ed0 ++0, 134100, 160, 0xce9f4883 ++0, 135000, 160, 0xd94c42de ++0, 135900, 160, 0xf1874b54 ++0, 136800, 160, 0x42da46ce ++0, 137700, 160, 0xe99a4da5 ++0, 138600, 160, 0x94934f16 ++0, 139500, 160, 0x8571437f ++0, 140400, 160, 0xe4774dc2 ++0, 141300, 160, 0x743f4f89 ++0, 142200, 160, 0x3b3e50ba ++0, 143100, 160, 0x439355e9 ++0, 144000, 160, 0x3e4d5178 ++0, 144900, 160, 0x64595524 ++0, 145800, 160, 0x42d14702 ++0, 146700, 160, 0x051e4b1d ++0, 147600, 160, 0x5db84cee ++0, 148500, 160, 0x4d875136 ++0, 149400, 160, 0x33b75996 ++0, 150300, 160, 0xd5094d76 ++0, 151200, 160, 0x6a7052b7 ++0, 152100, 160, 0x77264c8f ++0, 153000, 160, 0xcf7e4ccf ++0, 153900, 160, 0x5f7c568b ++0, 154800, 160, 0x8886578b ++0, 155700, 160, 0xd33a4e52 ++0, 156600, 160, 0xeefe5c23 ++0, 157500, 160, 0xa9c94e38 ++0, 158400, 160, 0x67845aa0 ++0, 159300, 160, 0xbe91498f ++0, 160200, 160, 0x843d46e3 ++0, 161100, 160, 0xbd215999 ++0, 162000, 160, 0x1a2e5f2c ++0, 162900, 160, 0x6a344a63 ++0, 163800, 160, 0xd80d5743 ++0, 164700, 160, 0x80964879 ++0, 165600, 160, 0xaafb5e35 ++0, 166500, 160, 0x3b855ff3 ++0, 167400, 160, 0x770b51d0 ++0, 168300, 160, 0x623a5312 ++0, 169200, 160, 0x0c235b56 ++0, 170100, 160, 0xc8c25724 ++0, 171000, 160, 0xb44650e2 ++0, 171900, 160, 0xab964d47 ++0, 172800, 160, 0x7aa35107 ++0, 173700, 160, 0xf12d4780 ++0, 174600, 160, 0x77e64f92 ++0, 175500, 160, 0x34ee4fa0 ++0, 176400, 160, 0x6701466b ++0, 177300, 160, 0xa79d4b4c ++0, 178200, 160, 0xbb7f557b ++0, 179100, 160, 0xaeb253c4 ++0, 180000, 160, 0xe7255029 ++0, 180900, 160, 0xa5f1505c ++0, 181800, 160, 0x4ae54f09 ++0, 182700, 160, 0x6a2b4bc9 ++0, 183600, 160, 0xf8724ea5 ++0, 184500, 160, 0x4ab35317 ++0, 185400, 160, 0xc8d350fb ++0, 186300, 160, 0x73a74994 ++0, 187200, 160, 0x9cd1596d ++0, 188100, 160, 0x5ba16005 ++0, 189000, 160, 0xb17e4fcc ++0, 189900, 160, 0x8ac958cd ++0, 190800, 160, 0x7919557f ++0, 191700, 160, 0x0be35121 ++0, 192600, 160, 0xf8f752f2 ++0, 193500, 160, 0xae894d40 ++0, 194400, 160, 0x03d94c10 ++0, 195300, 160, 0xf12c4917 ++0, 196200, 160, 0x3c94534e ++0, 197100, 160, 0x111d51c3 ++0, 198000, 160, 0x0a285304 ++0, 198900, 160, 0xc3ac4ab1 ++0, 199800, 160, 0x5576579d ++0, 200700, 160, 0x9cd04f10 ++0, 201600, 160, 0x38a04bf9 ++0, 202500, 160, 0xbd0d4d6d ++0, 203400, 160, 0x4db24510 ++0, 204300, 160, 0x968753de ++0, 205200, 160, 0x1fa35c67 ++0, 206100, 160, 0xc9c048bc ++0, 207000, 160, 0x221d629e ++0, 207900, 160, 0xbb864b0e ++0, 208800, 160, 0xe2964bcd ++0, 209700, 160, 0x20ff4b23 ++0, 210600, 160, 0x01dc53e7 ++0, 211500, 160, 0x522b56aa ++0, 212400, 160, 0x1e6a495a ++0, 213300, 160, 0x0dcf5731 ++0, 214200, 160, 0x241f448d ++0, 215100, 160, 0xdafa55b6 ++0, 216000, 160, 0x40584e43 ++0, 216900, 160, 0xb73850ab ++0, 217800, 160, 0x7cff593a ++0, 218700, 160, 0x2796515a ++0, 219600, 160, 0x872c5454 ++0, 220500, 160, 0xa13058e7 ++0, 221400, 160, 0xd8a65261 ++0, 222300, 160, 0x48a75601 ++0, 223200, 160, 0xb1e7584c ++0, 224100, 160, 0x29cd53fa ++0, 225000, 160, 0xba514d84 ++0, 225900, 160, 0x747f4f99 ++0, 226800, 160, 0x5819526e ++0, 227700, 160, 0x10185413 ++0, 228600, 160, 0x4d084cdc ++0, 229500, 160, 0x8313530b ++0, 230400, 160, 0xd26c5583 ++0, 231300, 160, 0x76d749f9 ++0, 232200, 160, 0x7cf847a5 ++0, 233100, 160, 0xa642590c ++0, 234000, 160, 0x7fef56f2 ++0, 234900, 160, 0xf6ea49b9 ++0, 235800, 160, 0x6c654e89 ++0, 236700, 160, 0x164f56e9 ++0, 237600, 160, 0x84cf6139 ++0, 238500, 160, 0x20c753ef ++0, 239400, 160, 0x3f3a485f ++0, 240300, 160, 0xee0c5f4b ++0, 241200, 160, 0x706b5313 ++0, 242100, 160, 0x47da5af3 ++0, 243000, 160, 0x05504b25 ++0, 243900, 160, 0x584e59d8 ++0, 244800, 160, 0xe9cc4e37 ++0, 245700, 160, 0xf33b518a ++0, 246600, 160, 0xb9ac58b7 ++0, 247500, 160, 0xed5c57f0 ++0, 248400, 160, 0x4cf1579d ++0, 249300, 160, 0x96f94792 ++0, 250200, 160, 0x7c455836 ++0, 251100, 160, 0xad6652ce ++0, 252000, 160, 0x1ba95cab ++0, 252900, 160, 0xd86755bb ++0, 253800, 160, 0x2f9e51b4 ++0, 254700, 160, 0x084e5119 ++0, 255600, 160, 0x54ad5449 ++0, 256500, 160, 0xff7c5b86 ++0, 257400, 160, 0x29a94fff ++0, 258300, 160, 0x679c55ff ++0, 259200, 160, 0x9a415b81 ++0, 260100, 160, 0x3ea5528a ++0, 261000, 160, 0x54e15d3f ++0, 261900, 160, 0x122b5c28 ++0, 262800, 160, 0xdc0f4e7f ++0, 263700, 160, 0xdc304acd ++0, 264600, 160, 0xe55e5407 ++0, 265500, 160, 0x8d07485f ++0, 266400, 160, 0xdc0b5333 ++0, 267300, 160, 0xfaed4a90 ++0, 268200, 160, 0xb0625538 ++0, 269100, 160, 0x1ef3526b ++0, 270000, 160, 0xb48c48e9 ++0, 270900, 160, 0x8c945190 ++0, 271800, 160, 0x7f9a58b3 ++0, 272700, 160, 0x55735499 ++0, 273600, 160, 0xeba34a71 ++0, 274500, 160, 0xbaa94a6d ++0, 275400, 160, 0x15ab484f ++0, 276300, 160, 0xdc675509 ++0, 277200, 160, 0xc2e94f0e ++0, 278100, 160, 0xd7f348ac ++0, 279000, 160, 0x14884e8f ++0, 279900, 160, 0x2d274a97 ++0, 280800, 160, 0x578c5834 ++0, 281700, 160, 0x12074dab ++0, 282600, 160, 0x74c55067 ++0, 283500, 160, 0x7c904e0f ++0, 284400, 160, 0x81d45735 ++0, 285300, 160, 0x766f4d71 ++0, 286200, 160, 0x9c915273 ++0, 287100, 160, 0xf37f4d04 ++0, 288000, 160, 0x1ac74d66 ++0, 288900, 160, 0xf9b253ab ++0, 289800, 160, 0x6e0c5bb2 ++0, 290700, 160, 0x603d629e ++0, 291600, 160, 0xbb674faf ++0, 292500, 160, 0x5d8d51c6 ++0, 293400, 160, 0xae7350b9 ++0, 294300, 160, 0xfde859ec ++0, 295200, 160, 0x900d50a4 ++0, 296100, 160, 0x003551b2 ++0, 297000, 160, 0xf8ae4c9d ++0, 297900, 160, 0x66ea508f ++0, 298800, 160, 0xd45b4c51 ++0, 299700, 160, 0xb64451a3 ++0, 300600, 160, 0x6d2a5621 ++0, 301500, 160, 0x71db4d36 ++0, 302400, 160, 0x06704647 ++0, 303300, 160, 0x1f124cf9 ++0, 304200, 160, 0x10d14b46 ++0, 305100, 160, 0x421b59d8 ++0, 306000, 160, 0x84ba4cae ++0, 306900, 160, 0x4fba48e1 ++0, 307800, 160, 0xec294a6b ++0, 308700, 160, 0x2f1752a7 ++0, 309600, 160, 0x8d665570 ++0, 310500, 160, 0x586e537d ++0, 311400, 160, 0x18d54a49 ++0, 312300, 160, 0xa895566d ++0, 313200, 160, 0xb9b35255 ++0, 314100, 160, 0x2e194e1f ++0, 315000, 160, 0x4810594b ++0, 315900, 160, 0xb82557ee ++0, 316800, 160, 0x35d84d67 ++0, 317700, 160, 0x5ee95128 ++0, 318600, 160, 0x24f05747 ++0, 319500, 160, 0x434d53f6 ++0, 320400, 160, 0x3c894f3e ++0, 321300, 160, 0x81c34896 ++0, 322200, 160, 0x7540543c ++0, 323100, 160, 0x35bc5504 ++0, 324000, 160, 0x546943dc ++0, 324900, 160, 0x084d46e9 ++0, 325800, 160, 0x983852ba ++0, 326700, 160, 0xefac4e15 ++0, 327600, 160, 0xc9294430 ++0, 328500, 160, 0xe9e74de1 ++0, 329400, 160, 0x4ca1516a ++0, 330300, 160, 0x44014ceb ++0, 331200, 160, 0x1dbc5ad1 ++0, 332100, 160, 0x98be4efd ++0, 333000, 160, 0x2dc75c7a ++0, 333900, 160, 0x46275852 ++0, 334800, 160, 0x61c15d30 ++0, 335700, 160, 0x1f605adc ++0, 336600, 160, 0xf08659ac ++0, 337500, 160, 0xb7656021 ++0, 338400, 160, 0x1f4a5a72 ++0, 339300, 160, 0xf8175275 ++0, 340200, 160, 0xbbf4564d ++0, 341100, 160, 0x6fdc5a7d ++0, 342000, 160, 0x082f5250 ++0, 342900, 160, 0x84cb55b5 ++0, 343800, 160, 0x0e1a51ba ++0, 344700, 160, 0xa84e52fc ++0, 345600, 160, 0xcb5a55c9 ++0, 346500, 160, 0x9ce6570d ++0, 347400, 160, 0x82b253cc ++0, 348300, 160, 0x34c4594b ++0, 349200, 160, 0xff5c5854 ++0, 350100, 160, 0xd5da4ea0 ++0, 351000, 160, 0xc86e5553 ++0, 351900, 160, 0x7ecb55c6 ++0, 352800, 160, 0xb08b5338 ++0, 353700, 160, 0xd601573c ++0, 354600, 160, 0x93305092 ++0, 355500, 160, 0x352d4912 ++0, 356400, 160, 0xddba4d29 ++0, 357300, 160, 0xc79c50b7 ++0, 358200, 160, 0xe67d4e8e ++0, 359100, 160, 0xdbfd4bbc ++0, 360000, 160, 0xb2f746fb ++0, 360900, 160, 0x835b5539 ++0, 361800, 160, 0x612049e9 ++0, 362700, 160, 0x91a6503c ++0, 363600, 160, 0x762e4f0e ++0, 364500, 160, 0x2b2153f9 ++0, 365400, 160, 0xdcfe5804 ++0, 366300, 160, 0x79144cae ++0, 367200, 160, 0xd6394d99 ++0, 368100, 160, 0x22395292 ++0, 369000, 160, 0x50b04fa0 ++0, 369900, 160, 0x846b49a5 ++0, 370800, 160, 0x1f554dff ++0, 371700, 160, 0x0aa458dd ++0, 372600, 160, 0x62154dde ++0, 373500, 160, 0xe69847ac ++0, 374400, 160, 0x75855425 ++0, 375300, 160, 0x49125665 ++0, 376200, 160, 0xa8605945 ++0, 377100, 160, 0xc02a5083 ++0, 378000, 160, 0x6198537c ++0, 378900, 160, 0x90f25711 ++0, 379800, 160, 0x32da51f1 ++0, 380700, 160, 0x96c3474d ++0, 381600, 160, 0x82ae4579 ++0, 382500, 160, 0xbabf5919 ++0, 383400, 160, 0x78095772 ++0, 384300, 160, 0x46964abb ++0, 385200, 160, 0x5fcb5ba3 ++0, 386100, 160, 0x4a775585 ++0, 387000, 160, 0xc41f53af ++0, 387900, 160, 0x457251bc ++0, 388800, 160, 0x8f864fb3 ++0, 389700, 160, 0x439d526c ++0, 390600, 160, 0x5cf6503f ++0, 391500, 160, 0x90b7534f ++0, 392400, 160, 0xecc45253 ++0, 393300, 160, 0x533b4ee3 ++0, 394200, 160, 0x4cc44f27 ++0, 395100, 160, 0x6ff35096 ++0, 396000, 160, 0x141e4a80 ++0, 396900, 160, 0x9e075461 ++0, 397800, 160, 0xc4b55791 ++0, 398700, 160, 0x40955666 ++0, 399600, 160, 0x6255462f ++0, 400500, 160, 0x2cec55d6 ++0, 401400, 160, 0xd71652e9 ++0, 402300, 160, 0xe65e530c ++0, 403200, 160, 0xeeb9556d ++0, 404100, 160, 0x558f523e ++0, 405000, 160, 0x76e14b00 ++0, 405900, 160, 0x3f9f4e9b ++0, 406800, 160, 0x0d7b492a ++0, 407700, 160, 0xdd6e51bd ++0, 408600, 160, 0x5ab353b9 ++0, 409500, 160, 0x5b934f33 ++0, 410400, 160, 0x36bb57a0 ++0, 411300, 160, 0x455d54d3 ++0, 412200, 160, 0x7e6853d7 ++0, 413100, 160, 0xdcb85ed4 ++0, 414000, 160, 0x3a8d5860 ++0, 414900, 160, 0x5c90558f ++0, 415800, 160, 0x25504d46 ++0, 416700, 160, 0x0fc55413 ++0, 417600, 160, 0x98545409 ++0, 418500, 160, 0x963b550e ++0, 419400, 160, 0x544a569c ++0, 420300, 160, 0x7ab65f77 ++0, 421200, 160, 0x14c257e2 ++0, 422100, 160, 0x6cac6262 ++0, 423000, 160, 0x2f7f5091 ++0, 423900, 160, 0xc2655462 ++0, 424800, 160, 0xbb4b4744 ++0, 425700, 160, 0x4c5f54db ++0, 426600, 160, 0x9e694ab5 ++0, 427500, 160, 0xc2c95173 ++0, 428400, 160, 0xf4ae553f ++0, 429300, 160, 0xb4c04ed1 ++0, 430200, 160, 0xf3095128 ++0, 431100, 160, 0x73b04de1 ++0, 432000, 160, 0xff4951c7 ++0, 432900, 160, 0x28c156bd ++0, 433800, 160, 0x17b652aa ++0, 434700, 160, 0xb9ce528b ++0, 435600, 160, 0x3cc558be ++0, 436500, 160, 0xdf385905 ++0, 437400, 160, 0xe2de4fe2 ++0, 438300, 160, 0xc2a6582d ++0, 439200, 160, 0xe5715bc9 ++0, 440100, 160, 0x741b6416 ++0, 441000, 160, 0xf9b1544f ++0, 441900, 160, 0x012e5f01 ++0, 442800, 160, 0x5ab65a49 ++0, 443700, 160, 0xfe1e5b1a ++0, 444600, 160, 0x370056ef ++0, 445500, 160, 0xfde45ed4 ++0, 446400, 160, 0xa34f6053 ++0, 447300, 160, 0x31755604 ++0, 448200, 160, 0xc3415bfe ++0, 449100, 160, 0xe5dd5b58 ++0, 450000, 160, 0xb6cf5295 ++0, 450900, 160, 0x3d81538b ++0, 451800, 160, 0xc00255d2 ++0, 452700, 160, 0xb0714f71 ++0, 453600, 160, 0x9c9756ac ++0, 454500, 160, 0x4de053a0 ++0, 455400, 160, 0x6706500c ++0, 456300, 160, 0x34e4511d ++0, 457200, 160, 0xe4224e3e ++0, 458100, 160, 0xdf695529 ++0, 459000, 160, 0xeb1f54e0 ++0, 459900, 160, 0x2870550e ++0, 460800, 160, 0x08465464 ++0, 461700, 160, 0xe34150e6 ++0, 462600, 160, 0xb77556e0 ++0, 463500, 160, 0xb23e46ab ++0, 464400, 160, 0x83884a7b ++0, 465300, 160, 0xa0284b16 ++0, 466200, 160, 0x87b749e1 ++0, 467100, 160, 0x4b276444 ++0, 468000, 160, 0x92f95091 ++0, 468900, 160, 0x2b1056c2 ++0, 469800, 160, 0xd5d5590a ++0, 470700, 160, 0x5a454fac ++0, 471600, 160, 0x0ab05b13 ++0, 472500, 160, 0xd98e56ca ++0, 473400, 160, 0x183d5892 ++0, 474300, 160, 0x8ba951e4 ++0, 475200, 160, 0x487054ff ++0, 476100, 160, 0xc0d05562 ++0, 477000, 160, 0x166c590f ++0, 477900, 160, 0x3e254cc0 ++0, 478800, 160, 0xd2784ab4 ++0, 479700, 160, 0x9f7b4ef6 ++0, 480600, 160, 0xdd7653b6 ++0, 481500, 160, 0x7ae453b7 ++0, 482400, 160, 0xff6c50ec ++0, 483300, 160, 0xfa0d51a9 ++0, 484200, 160, 0x29ab583b ++0, 485100, 160, 0x671d5437 ++0, 486000, 160, 0x6867569f ++0, 486900, 160, 0xdd775e05 ++0, 487800, 160, 0xbafa65ed ++0, 488700, 160, 0xd33f5aea ++0, 489600, 160, 0x851455a8 ++0, 490500, 160, 0x044c4d45 ++0, 491400, 160, 0xcd7c5d84 ++0, 492300, 160, 0xd6565e61 ++0, 493200, 160, 0x2f345a92 ++0, 494100, 160, 0x50e05530 ++0, 495000, 160, 0x787f516a ++0, 495900, 160, 0x75cd5ade ++0, 496800, 160, 0x55b558ad ++0, 497700, 160, 0x55255b01 ++0, 498600, 160, 0xfc5b5945 ++0, 499500, 160, 0x33914e05 ++0, 500400, 160, 0x1f4a5c31 ++0, 501300, 160, 0x542f4bf2 ++0, 502200, 160, 0xd8b2573f ++0, 503100, 160, 0x127758b0 ++0, 504000, 160, 0x18dd5a30 ++0, 504900, 160, 0xe8ce61c4 ++0, 505800, 160, 0x9a225b47 ++0, 506700, 160, 0xd4436314 ++0, 507600, 160, 0x2bf06310 ++0, 508500, 160, 0x0de35e82 ++0, 509400, 160, 0x76cb56f2 ++0, 510300, 160, 0x65bc569b ++0, 511200, 160, 0x00a45461 ++0, 512100, 160, 0xb5c55019 ++0, 513000, 160, 0x5eb04b4d ++0, 513900, 160, 0xf1224c39 ++0, 514800, 160, 0x4d135288 ++0, 515700, 160, 0x9bc34ba7 ++0, 516600, 160, 0xbde3510e ++0, 517500, 160, 0xefaf4fa4 ++0, 518400, 160, 0x584950e2 ++0, 519300, 160, 0x1e844e27 ++0, 520200, 160, 0x38634315 ++0, 521100, 160, 0x6b9b4a0b ++0, 522000, 160, 0xd491512a ++0, 522900, 160, 0x8624478c ++0, 523800, 160, 0x67ab45c7 ++0, 524700, 160, 0xf78e4c53 ++0, 525600, 160, 0xb1654f0d ++0, 526500, 160, 0x17bb4e96 ++0, 527400, 160, 0xf3165e7c ++0, 528300, 160, 0xf7914633 ++0, 529200, 160, 0x3421530f ++0, 530100, 160, 0x492e572c ++0, 531000, 160, 0xa3185319 ++0, 531900, 160, 0x92d054c0 ++0, 532800, 160, 0x1cc24ce1 ++0, 533700, 160, 0x2ebc519e ++0, 534600, 160, 0x946b53e7 ++0, 535500, 160, 0xf85c4fe6 ++0, 536400, 160, 0x2974534c ++0, 537300, 160, 0xef7e4a28 ++0, 538200, 160, 0x01a74c6e ++0, 539100, 160, 0x2a865674 ++0, 540000, 160, 0x70474faf ++0, 540900, 160, 0x2df75014 ++0, 541800, 160, 0xf1f3574e ++0, 542700, 160, 0x741b5308 ++0, 543600, 160, 0xcb34513e ++0, 544500, 160, 0x7b5e50c7 ++0, 545400, 160, 0x0165553b ++0, 546300, 160, 0x04b85450 ++0, 547200, 160, 0x795d5873 ++0, 548100, 160, 0x508859fb ++0, 549000, 160, 0xca09587d ++0, 549900, 160, 0x86a65ac8 ++0, 550800, 160, 0x447353fe ++0, 551700, 160, 0x48ca54a5 ++0, 552600, 160, 0x1b3e5f3e ++0, 553500, 160, 0x270a5aa2 ++0, 554400, 160, 0x48a45c29 ++0, 555300, 160, 0xfbf75a0b ++0, 556200, 160, 0xe65161e5 ++0, 557100, 160, 0xf47c6701 ++0, 558000, 160, 0xc12058bc ++0, 558900, 160, 0xdb17520c ++0, 559800, 160, 0x860455bd ++0, 560700, 160, 0xa02d56de ++0, 561600, 160, 0xf5574c7d ++0, 562500, 160, 0x500e59b3 ++0, 563400, 160, 0xf0b75894 ++0, 564300, 160, 0x9d454a04 ++0, 565200, 160, 0x0b0554a4 ++0, 566100, 160, 0x3fc34d98 ++0, 567000, 160, 0x538550b8 ++0, 567900, 160, 0xd84e495e ++0, 568800, 160, 0x736c4e17 ++0, 569700, 160, 0xa59e5607 ++0, 570600, 160, 0xe7485609 ++0, 571500, 160, 0x20185a67 ++0, 572400, 160, 0x9aa5576f ++0, 573300, 160, 0xed8c5d11 ++0, 574200, 160, 0xecef5494 ++0, 575100, 160, 0x76f75a5c ++0, 576000, 160, 0xa8fa5322 ++0, 576900, 160, 0xd1945734 ++0, 577800, 160, 0x817f5c82 ++0, 578700, 160, 0x40756063 ++0, 579600, 160, 0x524454c7 ++0, 580500, 160, 0x5a776106 ++0, 581400, 160, 0xd16e5d9d ++0, 582300, 160, 0x8522524c ++0, 583200, 160, 0x4a115bb9 ++0, 584100, 160, 0xbf5c5c27 ++0, 585000, 160, 0x48905da4 ++0, 585900, 160, 0x58735040 ++0, 586800, 160, 0x48635631 ++0, 587700, 160, 0xf1305eaf ++0, 588600, 160, 0xd34451bd ++0, 589500, 160, 0x1a244fcf ++0, 590400, 160, 0xdb995ca0 ++0, 591300, 160, 0xe38e52bb ++0, 592200, 160, 0x00715069 ++0, 593100, 160, 0x72a95190 ++0, 594000, 160, 0xea7d50b7 ++0, 594900, 160, 0xb4094a9c ++0, 595800, 160, 0xd5284d79 ++0, 596700, 160, 0x3c4349e5 ++0, 597600, 160, 0x65d34e92 ++0, 598500, 160, 0x67805756 ++0, 599400, 160, 0x1b96502f ++0, 600300, 160, 0x395250ae ++0, 601200, 160, 0x4dc74976 ++0, 602100, 160, 0x2666486e ++0, 603000, 160, 0x41924d01 ++0, 603900, 160, 0x94a845f5 ++0, 604800, 160, 0x1b264cf9 ++0, 605700, 160, 0x63ea4aab ++0, 606600, 160, 0x9c0d4a82 ++0, 607500, 160, 0x02ba4cf6 ++0, 608400, 160, 0x9cd54b87 ++0, 609300, 160, 0x24624c5b ++0, 610200, 160, 0x14cf54b1 ++0, 611100, 160, 0xce54544b ++0, 612000, 160, 0x459b4fc9 ++0, 612900, 160, 0xcc2453f1 ++0, 613800, 160, 0xa4ab53bc ++0, 614700, 160, 0x92235013 ++0, 615600, 160, 0xbfa257b3 ++0, 616500, 160, 0xd32d51f5 ++0, 617400, 160, 0x7d5d47e6 ++0, 618300, 160, 0xe23d43ed ++0, 619200, 160, 0x51d8514f ++0, 620100, 160, 0x0fa04240 ++0, 621000, 160, 0x233c4dce ++0, 621900, 160, 0xcd30466f ++0, 622800, 160, 0x4435546a ++0, 623700, 160, 0x3eb6445b ++0, 624600, 160, 0xcaed4ef9 ++0, 625500, 160, 0xf0174da8 ++0, 626400, 160, 0x60e756a0 ++0, 627300, 160, 0x72ba457d ++0, 628200, 160, 0x84ce4f0f ++0, 629100, 160, 0x660d45ae ++0, 630000, 160, 0xac8446e2 ++0, 630900, 160, 0xeeb153b4 ++0, 631800, 160, 0x6a634c23 ++0, 632700, 160, 0x890f4af8 ++0, 633600, 160, 0x1d3743a7 ++0, 634500, 160, 0xa37e4ee8 ++0, 635400, 160, 0xb9334d56 ++0, 636300, 160, 0xc1384bef ++0, 637200, 160, 0x52964f6e ++0, 638100, 160, 0xe36e57e2 ++0, 639000, 160, 0x62114a53 ++0, 639900, 160, 0xb1f855bb ++0, 640800, 160, 0xf0934da0 ++0, 641700, 160, 0xb454494a ++0, 642600, 160, 0xb6e04b15 ++0, 643500, 160, 0x933e488e ++0, 644400, 160, 0x762d5ce8 ++0, 645300, 160, 0x1c4a4f85 ++0, 646200, 160, 0xaaa25313 ++0, 647100, 160, 0xd3655979 ++0, 648000, 160, 0x8ff149e5 ++0, 648900, 160, 0x5d5e51fb ++0, 649800, 160, 0x0a354c51 ++0, 650700, 160, 0x79ea52ee ++0, 651600, 160, 0x306e5365 ++0, 652500, 160, 0x7e03546a ++0, 653400, 160, 0x71575ddf ++0, 654300, 160, 0x08da523d ++0, 655200, 160, 0x2a2152b2 ++0, 656100, 160, 0x50e55447 ++0, 657000, 160, 0xf3b55758 ++0, 657900, 160, 0xc29d5f12 ++0, 658800, 160, 0x0c0b5778 ++0, 659700, 160, 0x1b07593a ++0, 660600, 160, 0x946f562d ++0, 661500, 160, 0xcdc85636 ++0, 662400, 160, 0x2421589b ++0, 663300, 160, 0x8e3b5451 ++0, 664200, 160, 0xd565536a ++0, 665100, 160, 0x8d225557 ++0, 666000, 160, 0xa0084e44 ++0, 666900, 160, 0x85bd5413 ++0, 667800, 160, 0xa4be4c3b ++0, 668700, 160, 0x332957c8 ++0, 669600, 160, 0x60505225 ++0, 670500, 160, 0x3d154eb3 ++0, 671400, 160, 0xd85359f4 ++0, 672300, 160, 0xf95b4f6b ++0, 673200, 160, 0x8bea5846 ++0, 674100, 160, 0x43835a02 ++0, 675000, 160, 0x340b5732 ++0, 675900, 160, 0x8b6d5005 ++0, 676800, 160, 0xa4995aca ++0, 677700, 160, 0x88d34efc ++0, 678600, 160, 0x078e5003 ++0, 679500, 160, 0x09964b19 ++0, 680400, 160, 0x2eaf5120 ++0, 681300, 160, 0x52514d52 ++0, 682200, 160, 0x08f84d4c ++0, 683100, 160, 0x4a9b4cc7 ++0, 684000, 160, 0x947f4ca6 ++0, 684900, 160, 0x086a4f32 ++0, 685800, 160, 0x0e0857a6 ++0, 686700, 160, 0x38145bf7 ++0, 687600, 160, 0xc6e156bf ++0, 688500, 160, 0xb07853b2 ++0, 689400, 160, 0xaeda5172 ++0, 690300, 160, 0xc4e54d07 ++0, 691200, 160, 0x0b075a61 ++0, 692100, 160, 0x09f05c1f ++0, 693000, 160, 0xf5415796 ++0, 693900, 160, 0xe3be584e ++0, 694800, 160, 0x6e1656f9 ++0, 695700, 160, 0xd6d85599 ++0, 696600, 160, 0xd9b4502e ++0, 697500, 160, 0x1186598c ++0, 698400, 160, 0x879c543d ++0, 699300, 160, 0x5b2551a3 ++0, 700200, 160, 0xcf50528d ++0, 701100, 160, 0x95d059b2 ++0, 702000, 160, 0x34ba5515 ++0, 702900, 160, 0x7a014ba8 ++0, 703800, 160, 0x27725169 ++0, 704700, 160, 0x2fd14ca4 ++0, 705600, 160, 0xd5ad542a ++0, 706500, 160, 0xddc24d2e ++0, 707400, 160, 0x8a4b48b4 ++0, 708300, 160, 0x915e4a29 ++0, 709200, 160, 0xd56d4cae ++0, 710100, 160, 0x59594eea ++0, 711000, 160, 0x87085338 ++0, 711900, 160, 0xa5ee538f ++0, 712800, 160, 0xf34e5030 ++0, 713700, 160, 0x6bef4da7 ++0, 714600, 160, 0x05a14c52 ++0, 715500, 160, 0x67bc49ce ++0, 716400, 160, 0xb18f4cff ++0, 717300, 160, 0x5d744e6d ++0, 718200, 160, 0xcb7c5973 ++0, 719100, 160, 0x6df056f0 ++0, 720000, 160, 0xd62c4e00 ++0, 720900, 160, 0xa54d4d1e ++0, 721800, 160, 0xdaa250b0 ++0, 722700, 160, 0x350e475f ++0, 723600, 160, 0x0e454bb2 ++0, 724500, 160, 0xe37949ca ++0, 725400, 160, 0x551453bf ++0, 726300, 160, 0x35d04c27 ++0, 727200, 160, 0x6749469d ++0, 728100, 160, 0x544752e9 ++0, 729000, 160, 0xf23b4888 ++0, 729900, 160, 0x6f0a5519 ++0, 730800, 160, 0x808a58df ++0, 731700, 160, 0x8e674c88 ++0, 732600, 160, 0xd3ab51f7 ++0, 733500, 160, 0x985d500f ++0, 734400, 160, 0x734e52d8 ++0, 735300, 160, 0xb0da5227 ++0, 736200, 160, 0xcc7d4a21 ++0, 737100, 160, 0xb1354baf ++0, 738000, 160, 0xfc8d4f9a ++0, 738900, 160, 0x6f044d82 ++0, 739800, 160, 0x41e7546b ++0, 740700, 160, 0x67014682 ++0, 741600, 160, 0x5516575b ++0, 742500, 160, 0x26254693 ++0, 743400, 160, 0x81ce4af5 ++0, 744300, 160, 0x77f152a0 ++0, 745200, 160, 0x995a5096 ++0, 746100, 160, 0x6114532e ++0, 747000, 160, 0x4df457f3 ++0, 747900, 160, 0xbcd94804 ++0, 748800, 160, 0x1e544fd2 ++0, 749700, 160, 0xa70b5954 ++0, 750600, 160, 0x1c77484c ++0, 751500, 160, 0xb07f4c42 ++0, 752400, 160, 0x62074f1f ++0, 753300, 160, 0xf3b656a1 ++0, 754200, 160, 0x65734ac0 ++0, 755100, 160, 0x2a9752cd ++0, 756000, 160, 0x15ff4ef0 ++0, 756900, 160, 0xabd4532c ++0, 757800, 160, 0x8a44503a ++0, 758700, 160, 0xbf4250f3 ++0, 759600, 160, 0x17594ac5 ++0, 760500, 160, 0x7b5e4b24 ++0, 761400, 160, 0x24684cb5 ++0, 762300, 160, 0xc4d54b42 ++0, 763200, 160, 0xd48f58af ++0, 764100, 160, 0x0374593a ++0, 765000, 160, 0x398a5b0d ++0, 765900, 160, 0xf60855e6 ++0, 766800, 160, 0x6fbb5587 ++0, 767700, 160, 0x44405c2b ++0, 768600, 160, 0xa6345d70 ++0, 769500, 160, 0x464557d5 ++0, 770400, 160, 0x0c3153ca ++0, 771300, 160, 0x15ec50c4 ++0, 772200, 160, 0xd5e559da ++0, 773100, 160, 0x999757b9 ++0, 774000, 160, 0x7a5d5754 ++0, 774900, 160, 0xf85b5f18 ++0, 775800, 160, 0xa66d5c72 ++0, 776700, 160, 0xd8f55981 ++0, 777600, 160, 0xe6364f64 ++0, 778500, 160, 0x528a5785 ++0, 779400, 160, 0xdefe5332 ++0, 780300, 160, 0x4bc4532e ++0, 781200, 160, 0x505a4eb3 ++0, 782100, 160, 0xa28d589d ++0, 783000, 160, 0x092d511f ++0, 783900, 160, 0x3079591e ++0, 784800, 160, 0x2b1d5339 ++0, 785700, 160, 0xf8d849d1 ++0, 786600, 160, 0xadb056a6 ++0, 787500, 160, 0x2ee74c4f ++0, 788400, 160, 0x35c34c9f ++0, 789300, 160, 0xb6ae53d3 ++0, 790200, 160, 0x7258534e ++0, 791100, 160, 0xb76d4b1b ++0, 792000, 160, 0x99a14a0f ++0, 792900, 160, 0x88365944 ++0, 793800, 160, 0x97cf4aed ++0, 794700, 160, 0x444b56f6 ++0, 795600, 160, 0x1d1f4b01 ++0, 796500, 160, 0x3dcd417e ++0, 797400, 160, 0xa4985140 ++0, 798300, 160, 0x86f94c4d ++0, 799200, 160, 0xc3635436 ++0, 800100, 160, 0x198b432b ++0, 801000, 160, 0xae5253e4 ++0, 801900, 160, 0x248c4f1a ++0, 802800, 160, 0x787a45df ++0, 803700, 160, 0x5fd44cad ++0, 804600, 160, 0x68be581c ++0, 805500, 160, 0x5ff5531b ++0, 806400, 160, 0x2bcd4aa1 ++0, 807300, 160, 0x0d134a7c ++0, 808200, 160, 0x28af5885 ++0, 809100, 160, 0xc09f4d65 ++0, 810000, 160, 0x7468552d ++0, 810900, 160, 0x82df49ac ++0, 811800, 160, 0xe3725fdc ++0, 812700, 160, 0x0ec74d11 ++0, 813600, 160, 0xfc2a5355 ++0, 814500, 160, 0x41df4d4f ++0, 815400, 160, 0x4ebe473d ++0, 816300, 160, 0xd8734bf2 ++0, 817200, 160, 0x4acd5056 ++0, 818100, 160, 0x47805700 ++0, 819000, 160, 0xe4f25135 ++0, 819900, 160, 0x9f195649 ++0, 820800, 160, 0x8b055f64 ++0, 821700, 160, 0xc4b751c8 ++0, 822600, 160, 0x95e55ba4 ++0, 823500, 160, 0xf0955494 ++0, 824400, 160, 0xca1a47b9 ++0, 825300, 160, 0x9d025711 ++0, 826200, 160, 0xf6cb4a0a ++0, 827100, 160, 0xd8385b4d ++0, 828000, 160, 0x7b2852b6 ++0, 828900, 160, 0x90a35643 ++0, 829800, 160, 0x63105d0a ++0, 830700, 160, 0x55414083 ++0, 831600, 160, 0xc94554a9 ++0, 832500, 160, 0xa88f4a36 ++0, 833400, 160, 0xda5d52bc ++0, 834300, 160, 0x5b3943da ++0, 835200, 160, 0xd2314755 ++0, 836100, 160, 0x743c4cdc ++0, 837000, 160, 0x7c3e4dc2 ++0, 837900, 160, 0x12644715 ++0, 838800, 160, 0x1050480b ++0, 839700, 160, 0x73645906 ++0, 840600, 160, 0x28ef4a9e ++0, 841500, 160, 0xf72440bc ++0, 842400, 160, 0x41964bda ++0, 843300, 160, 0x2afb4d9b ++0, 844200, 160, 0xf74b4c5a ++0, 845100, 160, 0xcf165e2e ++0, 846000, 160, 0x3dbb4d06 ++0, 846900, 160, 0xbd9755f9 ++0, 847800, 160, 0x3248581d ++0, 848700, 160, 0xc00c559d ++0, 849600, 160, 0xff6c4b0a ++0, 850500, 160, 0x154157e3 ++0, 851400, 160, 0xb996499c ++0, 852300, 160, 0xe1a059ba ++0, 853200, 160, 0x98015946 ++0, 854100, 160, 0x168b4ceb ++0, 855000, 160, 0x567b4f83 ++0, 855900, 160, 0x903e52f8 ++0, 856800, 160, 0xc0a252dc ++0, 857700, 160, 0x08cb4b70 ++0, 858600, 160, 0x3d9a5be6 ++0, 859500, 160, 0x904b4907 ++0, 860400, 160, 0x738847b1 ++0, 861300, 160, 0x10405c19 ++0, 862200, 160, 0x8c134f27 ++0, 863100, 160, 0xdfe34d7f ++0, 864000, 160, 0x9d0948a8 ++0, 864900, 160, 0x67755611 ++0, 865800, 160, 0x46734258 ++0, 866700, 160, 0x76f449fa ++0, 867600, 160, 0xfad64d30 ++0, 868500, 160, 0x7f4357f4 ++0, 869400, 160, 0xd20e5079 ++0, 870300, 160, 0xdf7857ec ++0, 871200, 160, 0x46ff4891 ++0, 872100, 160, 0x1b724ffc ++0, 873000, 160, 0xdf20545a ++0, 873900, 160, 0xeb5254e0 ++0, 874800, 160, 0x794b4a96 ++0, 875700, 160, 0x86a15147 ++0, 876600, 160, 0x30f75504 ++0, 877500, 160, 0x39575354 ++0, 878400, 160, 0xb6a35351 ++0, 879300, 160, 0x9da34c3a ++0, 880200, 160, 0xcf2d5386 ++0, 881100, 160, 0xa7f353f6 ++0, 882000, 160, 0xa6e34e95 ++0, 882900, 160, 0x98174400 ++0, 883800, 160, 0x13685641 ++0, 884700, 160, 0x99215154 ++0, 885600, 160, 0x5be75237 ++0, 886500, 160, 0x4cb64942 ++0, 887400, 160, 0x15de4e03 ++0, 888300, 160, 0x613a4fd5 ++0, 889200, 160, 0xc97c4821 ++0, 890100, 160, 0xbf1558f2 ++0, 891000, 160, 0x651d4cf4 ++0, 891900, 160, 0xbee44a56 ++0, 892800, 160, 0x6cbd4c20 ++0, 893700, 160, 0xcf45493d ++0, 894600, 160, 0x73e74d2a ++0, 895500, 160, 0x6a3256e4 ++0, 896400, 160, 0x89ac4a68 ++0, 897300, 160, 0x0d2652aa ++0, 898200, 160, 0x56ce4b78 ++0, 899100, 160, 0xb7b24bcb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/gsm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/gsm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/gsm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/gsm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,500 +0,0 @@ +-0, 0, 320, 0x4c32ab06 +-0, 1800, 320, 0x2052a4e7 +-0, 3600, 320, 0xe9aeafca +-0, 5400, 320, 0xde83b450 +-0, 7200, 320, 0x06a6a80e +-0, 9000, 320, 0xf6aeb1e2 +-0, 10800, 320, 0x2623b40c +-0, 12600, 320, 0x8ec69f25 +-0, 14400, 320, 0xddaaac88 +-0, 16200, 320, 0x9e60b713 +-0, 18000, 320, 0xb738ab30 +-0, 19800, 320, 0xdb4bbb92 +-0, 21600, 320, 0x0370ae8b +-0, 23400, 320, 0xb611a3fb +-0, 25200, 320, 0x07ee8e3b +-0, 27000, 320, 0xdb1ec628 +-0, 28800, 320, 0xd5f1bda2 +-0, 30600, 320, 0xcabb9a9c +-0, 32400, 320, 0x16c8ad61 +-0, 34200, 320, 0xf76fc25e +-0, 36000, 320, 0x7118a10d +-0, 37800, 320, 0x29f9a0db +-0, 39600, 320, 0x41f2a4ef +-0, 41400, 320, 0x36dfb231 +-0, 43200, 320, 0xc5399eda +-0, 45000, 320, 0x17d4b9e0 +-0, 46800, 320, 0x2b5797ac +-0, 48600, 320, 0x0128c5e7 +-0, 50400, 320, 0xf4f38037 +-0, 52200, 320, 0x77d6b5f2 +-0, 54000, 320, 0xd94a93e0 +-0, 55800, 320, 0x968daae3 +-0, 57600, 320, 0xda5ba0ec +-0, 59400, 320, 0x316da1ec +-0, 61200, 320, 0x3a35b2d2 +-0, 63000, 320, 0xca0b988f +-0, 64800, 320, 0x1295b0b1 +-0, 66600, 320, 0xe121ae72 +-0, 68400, 320, 0x7da7ad43 +-0, 70200, 320, 0x96a49cfe +-0, 72000, 320, 0x70c2b1de +-0, 73800, 320, 0x668d88c0 +-0, 75600, 320, 0x5460b5a8 +-0, 77400, 320, 0x6ac78eab +-0, 79200, 320, 0x0d8dab87 +-0, 81000, 320, 0xe2be94af +-0, 82800, 320, 0x3487acdc +-0, 84600, 320, 0x5048955a +-0, 86400, 320, 0x2ef4ae0d +-0, 88200, 320, 0xc765b773 +-0, 90000, 320, 0xad96a486 +-0, 91800, 320, 0xb9fdbf1f +-0, 93600, 320, 0xf26c9ecf +-0, 95400, 320, 0xbcadb535 +-0, 97200, 320, 0xa8c897bc +-0, 99000, 320, 0xaa58b520 +-0, 100800, 320, 0xcb48a716 +-0, 102600, 320, 0x4d5da564 +-0, 104400, 320, 0x9809ae28 +-0, 106200, 320, 0x5baeb1e4 +-0, 108000, 320, 0x6a719b63 +-0, 109800, 320, 0xc27d92f0 +-0, 111600, 320, 0x0e9b9fe9 +-0, 113400, 320, 0xbf9d9bf7 +-0, 115200, 320, 0xf35aa64d +-0, 117000, 320, 0x26449ce8 +-0, 118800, 320, 0x58f4a997 +-0, 120600, 320, 0x155da289 +-0, 122400, 320, 0x63b19a5c +-0, 124200, 320, 0xe01aad38 +-0, 126000, 320, 0x4e0f9c43 +-0, 127800, 320, 0x9447a284 +-0, 129600, 320, 0xdb36a433 +-0, 131400, 320, 0x799a9b2c +-0, 133200, 320, 0x1526a162 +-0, 135000, 320, 0x0a4ea140 +-0, 136800, 320, 0xb08f9ed7 +-0, 138600, 320, 0x221bab76 +-0, 140400, 320, 0x4befacf0 +-0, 142200, 320, 0xac489509 +-0, 144000, 320, 0x57a1a5b4 +-0, 145800, 320, 0x81e8ab97 +-0, 147600, 320, 0xc6ada4d6 +-0, 149400, 320, 0x12489975 +-0, 151200, 320, 0x1da59ba9 +-0, 153000, 320, 0xf225ac62 +-0, 154800, 320, 0x8c8e9eab +-0, 156600, 320, 0x10599dec +-0, 158400, 320, 0x06c39fa5 +-0, 160200, 320, 0xb0efa3c4 +-0, 162000, 320, 0x72caadab +-0, 163800, 320, 0xe4619ff0 +-0, 165600, 320, 0x49bca017 +-0, 167400, 320, 0x413f9fbe +-0, 169200, 320, 0x6eaed0ee +-0, 171000, 320, 0x27e4b1eb +-0, 172800, 320, 0x8c42a30f +-0, 174600, 320, 0x0afaa0f4 +-0, 176400, 320, 0x0f74b76b +-0, 178200, 320, 0xa9a2b9d5 +-0, 180000, 320, 0xde2a8712 +-0, 181800, 320, 0xcfc8b3a2 +-0, 183600, 320, 0x768cadce +-0, 185400, 320, 0x3a8a97f1 +-0, 187200, 320, 0x502fa59b +-0, 189000, 320, 0x4c3e9b0f +-0, 190800, 320, 0x1cd2b111 +-0, 192600, 320, 0xa845a5a3 +-0, 194400, 320, 0xa6b8b982 +-0, 196200, 320, 0x4d5caab9 +-0, 198000, 320, 0x7993b604 +-0, 199800, 320, 0x8d19b37b +-0, 201600, 320, 0xbe48adb6 +-0, 203400, 320, 0x7d68ab8e +-0, 205200, 320, 0xbfffb0e2 +-0, 207000, 320, 0x90b5b7e3 +-0, 208800, 320, 0x9fa1b016 +-0, 210600, 320, 0x70abafc9 +-0, 212400, 320, 0x82cfad9c +-0, 214200, 320, 0x05f6aa2c +-0, 216000, 320, 0x511cbb5b +-0, 217800, 320, 0xd27caaa6 +-0, 219600, 320, 0x781ca481 +-0, 221400, 320, 0x12e9ad1a +-0, 223200, 320, 0xe46b989d +-0, 225000, 320, 0x76dbb0a7 +-0, 226800, 320, 0x10eba486 +-0, 228600, 320, 0x2269a7c8 +-0, 230400, 320, 0x084a9c7e +-0, 232200, 320, 0x84eda891 +-0, 234000, 320, 0x2ef9a639 +-0, 235800, 320, 0x8bb2a0dd +-0, 237600, 320, 0x47e5a169 +-0, 239400, 320, 0x98faae42 +-0, 241200, 320, 0x81d2aba4 +-0, 243000, 320, 0x5af8bb33 +-0, 244800, 320, 0x331e8d9f +-0, 246600, 320, 0xd9b0c09a +-0, 248400, 320, 0xbaf9bfcf +-0, 250200, 320, 0x54e89ab5 +-0, 252000, 320, 0x1d62c1d2 +-0, 253800, 320, 0xead6b436 +-0, 255600, 320, 0x465f98bc +-0, 257400, 320, 0xe707a346 +-0, 259200, 320, 0xf66cb1c2 +-0, 261000, 320, 0xcfc89ae6 +-0, 262800, 320, 0x0b10b796 +-0, 264600, 320, 0xb29caf2c +-0, 266400, 320, 0x0284a9d1 +-0, 268200, 320, 0xb966b5fc +-0, 270000, 320, 0x2defa630 +-0, 271800, 320, 0xcdcd8ef3 +-0, 273600, 320, 0xa81bba2b +-0, 275400, 320, 0x6bc0aeb1 +-0, 277200, 320, 0x38d8ac82 +-0, 279000, 320, 0xeb66a865 +-0, 280800, 320, 0x4fff9cd9 +-0, 282600, 320, 0x6819a19b +-0, 284400, 320, 0xfd7c93ce +-0, 286200, 320, 0xa7419f63 +-0, 288000, 320, 0x572caacb +-0, 289800, 320, 0x918fb1de +-0, 291600, 320, 0x0088a675 +-0, 293400, 320, 0x19229cf7 +-0, 295200, 320, 0x827ea812 +-0, 297000, 320, 0x6c258ef7 +-0, 298800, 320, 0x6a89b8fe +-0, 300600, 320, 0x166c9ce0 +-0, 302400, 320, 0x68b39db7 +-0, 304200, 320, 0x3d5aa8ec +-0, 306000, 320, 0x25e09ff3 +-0, 307800, 320, 0x759aa4ce +-0, 309600, 320, 0xe5aab0ea +-0, 311400, 320, 0xf0359e9a +-0, 313200, 320, 0x51199fff +-0, 315000, 320, 0xb04aa236 +-0, 316800, 320, 0xe09da0e3 +-0, 318600, 320, 0x144f98a9 +-0, 320400, 320, 0x0b4e9f8d +-0, 322200, 320, 0xbb69a090 +-0, 324000, 320, 0xec6e9b5b +-0, 325800, 320, 0x4f86a477 +-0, 327600, 320, 0x4a179d04 +-0, 329400, 320, 0x9682a375 +-0, 331200, 320, 0x3c6ba55e +-0, 333000, 320, 0x50c0ab50 +-0, 334800, 320, 0xe58ea907 +-0, 336600, 320, 0xc5eaa021 +-0, 338400, 320, 0x38859f01 +-0, 340200, 320, 0x73f8a540 +-0, 342000, 320, 0x395da234 +-0, 343800, 320, 0x7f50b144 +-0, 345600, 320, 0x45568ceb +-0, 347400, 320, 0xd0508dec +-0, 349200, 320, 0x60aba7e4 +-0, 351000, 320, 0x4b24b15f +-0, 352800, 320, 0xbfc9afd6 +-0, 354600, 320, 0xf0f2ad49 +-0, 356400, 320, 0xeea0a426 +-0, 358200, 320, 0xff07a7c9 +-0, 360000, 320, 0xce1fc788 +-0, 361800, 320, 0xc074ae9b +-0, 363600, 320, 0x51649696 +-0, 365400, 320, 0x24399744 +-0, 367200, 320, 0xfb0eb920 +-0, 369000, 320, 0x3bf8af5c +-0, 370800, 320, 0xeab69ee0 +-0, 372600, 320, 0x182696bb +-0, 374400, 320, 0x36e6af72 +-0, 376200, 320, 0x48cc9ecc +-0, 378000, 320, 0xfb3ca7b8 +-0, 379800, 320, 0xe01aa4b4 +-0, 381600, 320, 0x5c6dac8c +-0, 383400, 320, 0x072fbd93 +-0, 385200, 320, 0xc8899ccc +-0, 387000, 320, 0xdcc990ac +-0, 388800, 320, 0x28e0a9d0 +-0, 390600, 320, 0x0cdbaa11 +-0, 392400, 320, 0x8f4ca093 +-0, 394200, 320, 0x7ee79ea9 +-0, 396000, 320, 0xa762b695 +-0, 397800, 320, 0x9af0b5da +-0, 399600, 320, 0x1f2cb0e7 +-0, 401400, 320, 0x6029b8bb +-0, 403200, 320, 0xf2f7acec +-0, 405000, 320, 0xb3e5b5be +-0, 406800, 320, 0x266ba8a6 +-0, 408600, 320, 0x4ff59296 +-0, 410400, 320, 0x11d1b9ac +-0, 412200, 320, 0x749197f7 +-0, 414000, 320, 0x8192b517 +-0, 415800, 320, 0xde129dbe +-0, 417600, 320, 0x85e4a096 +-0, 419400, 320, 0xdebf9182 +-0, 421200, 320, 0x7a4ba0bf +-0, 423000, 320, 0x55fe9fcd +-0, 424800, 320, 0xd242adec +-0, 426600, 320, 0xeaf5b159 +-0, 428400, 320, 0xfcb1a571 +-0, 430200, 320, 0x62fabda0 +-0, 432000, 320, 0x45a9abcc +-0, 433800, 320, 0x07af974b +-0, 435600, 320, 0xc2a0b4fd +-0, 437400, 320, 0xc30abccd +-0, 439200, 320, 0xd33ca61c +-0, 441000, 320, 0x3c33d11a +-0, 442800, 320, 0x9c2ca0ac +-0, 444600, 320, 0xa5d69777 +-0, 446400, 320, 0xb7d2c6b8 +-0, 448200, 320, 0x34bbaab9 +-0, 450000, 320, 0x3e7baccb +-0, 451800, 320, 0x92c6b7e6 +-0, 453600, 320, 0xc810a18a +-0, 455400, 320, 0x06a09f56 +-0, 457200, 320, 0x8804a504 +-0, 459000, 320, 0x783ba7d5 +-0, 460800, 320, 0x24dcada6 +-0, 462600, 320, 0x4af796be +-0, 464400, 320, 0x1454b19c +-0, 466200, 320, 0x0ad0a56e +-0, 468000, 320, 0x8944a44e +-0, 469800, 320, 0x31069ebd +-0, 471600, 320, 0x19cb9812 +-0, 473400, 320, 0xac75abe2 +-0, 475200, 320, 0x0162a200 +-0, 477000, 320, 0xa2d7a4b2 +-0, 478800, 320, 0x078ca611 +-0, 480600, 320, 0x0ec39b40 +-0, 482400, 320, 0xe8f794b2 +-0, 484200, 320, 0xc2cfb258 +-0, 486000, 320, 0xe4759061 +-0, 487800, 320, 0xb1b6aea4 +-0, 489600, 320, 0x9bfb96df +-0, 491400, 320, 0xcc61b5d3 +-0, 493200, 320, 0xd14e8df9 +-0, 495000, 320, 0xd9d5bbf5 +-0, 496800, 320, 0x4d9fa9b0 +-0, 498600, 320, 0xf606abfc +-0, 500400, 320, 0x720baa19 +-0, 502200, 320, 0x7f7cac49 +-0, 504000, 320, 0xceab9b54 +-0, 505800, 320, 0x645fa70a +-0, 507600, 320, 0xa081a40f +-0, 509400, 320, 0x21d78f8c +-0, 511200, 320, 0xedf3abc6 +-0, 513000, 320, 0x17679637 +-0, 514800, 320, 0x1cb1ae04 +-0, 516600, 320, 0x17cd9f62 +-0, 518400, 320, 0xf4bca3ab +-0, 520200, 320, 0xb3bd9152 +-0, 522000, 320, 0x4e1e9825 +-0, 523800, 320, 0x037e9a56 +-0, 525600, 320, 0xd7589fcc +-0, 527400, 320, 0x5f949e90 +-0, 529200, 320, 0xe133a495 +-0, 531000, 320, 0x7cb7a52c +-0, 532800, 320, 0xb8b29d95 +-0, 534600, 320, 0x01bca472 +-0, 536400, 320, 0xbcc69895 +-0, 538200, 320, 0xabffa0ee +-0, 540000, 320, 0xe6629eca +-0, 541800, 320, 0x572da7cd +-0, 543600, 320, 0x3017972d +-0, 545400, 320, 0xac4e9c78 +-0, 547200, 320, 0x112f9c45 +-0, 549000, 320, 0x05e9a64d +-0, 550800, 320, 0x8f7394d4 +-0, 552600, 320, 0xbaeea07e +-0, 554400, 320, 0xd757c00e +-0, 556200, 320, 0x8aa09783 +-0, 558000, 320, 0x31d4ae7a +-0, 559800, 320, 0x221493e8 +-0, 561600, 320, 0x92f4a3a7 +-0, 563400, 320, 0xbd5bafd9 +-0, 565200, 320, 0x1895b760 +-0, 567000, 320, 0x7a4eacdd +-0, 568800, 320, 0xc9f7a1c3 +-0, 570600, 320, 0xd750be06 +-0, 572400, 320, 0x641d9a6f +-0, 574200, 320, 0x70d6b6ff +-0, 576000, 320, 0x1fd3a546 +-0, 577800, 320, 0x72cfaabe +-0, 579600, 320, 0x2e61b6ce +-0, 581400, 320, 0x4813a091 +-0, 583200, 320, 0xbfe7bc0f +-0, 585000, 320, 0x8c759c1f +-0, 586800, 320, 0xf4c1c952 +-0, 588600, 320, 0x00fdaa79 +-0, 590400, 320, 0x2ffda252 +-0, 592200, 320, 0x841aa523 +-0, 594000, 320, 0x8c079e5e +-0, 595800, 320, 0x96e9a83f +-0, 597600, 320, 0x5926a639 +-0, 599400, 320, 0x02e1a07b +-0, 601200, 320, 0x2972a999 +-0, 603000, 320, 0x30c89c62 +-0, 604800, 320, 0x83f5a263 +-0, 606600, 320, 0xa3909667 +-0, 608400, 320, 0xd5309fd4 +-0, 610200, 320, 0x3154a571 +-0, 612000, 320, 0x51039a5e +-0, 613800, 320, 0xf167a344 +-0, 615600, 320, 0x8e709d7d +-0, 617400, 320, 0x936fa0fd +-0, 619200, 320, 0x024b9e3c +-0, 621000, 320, 0x2ea1aa75 +-0, 622800, 320, 0x33f0a2bb +-0, 624600, 320, 0xbf079d2d +-0, 626400, 320, 0x847ba2c8 +-0, 628200, 320, 0x37e1a767 +-0, 630000, 320, 0xb607acbb +-0, 631800, 320, 0x1288ac6d +-0, 633600, 320, 0xf60e98b3 +-0, 635400, 320, 0xc6b5abdd +-0, 637200, 320, 0x7feaa710 +-0, 639000, 320, 0x77329fcd +-0, 640800, 320, 0x91a6a715 +-0, 642600, 320, 0xd0e99f24 +-0, 644400, 320, 0x07089f61 +-0, 646200, 320, 0x2bbda900 +-0, 648000, 320, 0xad3da0d5 +-0, 649800, 320, 0x997ba6d2 +-0, 651600, 320, 0xb15b9dcb +-0, 653400, 320, 0x17cea82f +-0, 655200, 320, 0xab51a73e +-0, 657000, 320, 0x77a1abd6 +-0, 658800, 320, 0x0bddacad +-0, 660600, 320, 0x43b3bdc4 +-0, 662400, 320, 0xefe0a9ba +-0, 664200, 320, 0x8eb4bc2f +-0, 666000, 320, 0x39cdc190 +-0, 667800, 320, 0x1ef3baff +-0, 669600, 320, 0x1a6ab7e2 +-0, 671400, 320, 0x444ccc69 +-0, 673200, 320, 0x05ebb598 +-0, 675000, 320, 0x4ac5b0ad +-0, 676800, 320, 0x0ee5ba52 +-0, 678600, 320, 0x501d9fa0 +-0, 680400, 320, 0x2038a9f4 +-0, 682200, 320, 0xa61cb8b3 +-0, 684000, 320, 0xdd009777 +-0, 685800, 320, 0x2a2db86d +-0, 687600, 320, 0xe9bab3bc +-0, 689400, 320, 0xf7f8a056 +-0, 691200, 320, 0x514caf14 +-0, 693000, 320, 0xa220b149 +-0, 694800, 320, 0xbf7ea183 +-0, 696600, 320, 0x1d8dc5c6 +-0, 698400, 320, 0x9182a8ea +-0, 700200, 320, 0x31eba026 +-0, 702000, 320, 0xcfbcc3df +-0, 703800, 320, 0x3d8cb7ae +-0, 705600, 320, 0xbe39aec0 +-0, 707400, 320, 0xd236bf71 +-0, 709200, 320, 0x9377b0b2 +-0, 711000, 320, 0xb5e6b2df +-0, 712800, 320, 0xa3b9bbce +-0, 714600, 320, 0xa7bda251 +-0, 716400, 320, 0xbf9ab162 +-0, 718200, 320, 0x6928b9cb +-0, 720000, 320, 0xf5cca209 +-0, 721800, 320, 0xfdf4afad +-0, 723600, 320, 0xe7e7c216 +-0, 725400, 320, 0x0c5797c6 +-0, 727200, 320, 0x66c1a9ca +-0, 729000, 320, 0x6b5ca48d +-0, 730800, 320, 0xec04968a +-0, 732600, 320, 0xaaada691 +-0, 734400, 320, 0x77c3a624 +-0, 736200, 320, 0xaed9a5d5 +-0, 738000, 320, 0x360fac41 +-0, 739800, 320, 0xa05ea727 +-0, 741600, 320, 0x9f7b9f83 +-0, 743400, 320, 0x474bc4c2 +-0, 745200, 320, 0xb6078d3b +-0, 747000, 320, 0x8e15a8f9 +-0, 748800, 320, 0x7dc7d4a8 +-0, 750600, 320, 0x55ceab6b +-0, 752400, 320, 0x982cc94f +-0, 754200, 320, 0x6153948f +-0, 756000, 320, 0x5338c621 +-0, 757800, 320, 0x2e2db6e8 +-0, 759600, 320, 0x28e3a9c3 +-0, 761400, 320, 0x74d7b435 +-0, 763200, 320, 0xcf17a10c +-0, 765000, 320, 0xf1f9ac8c +-0, 766800, 320, 0x35e0b480 +-0, 768600, 320, 0x5e60b3a4 +-0, 770400, 320, 0x20579b26 +-0, 772200, 320, 0x3e27b89b +-0, 774000, 320, 0x02e4af94 +-0, 775800, 320, 0x6d6897f1 +-0, 777600, 320, 0x1582b267 +-0, 779400, 320, 0x33ba9eb3 +-0, 781200, 320, 0xb6acad7d +-0, 783000, 320, 0x1969a6c2 +-0, 784800, 320, 0x363fa350 +-0, 786600, 320, 0xae50bf65 +-0, 788400, 320, 0x0877a50f +-0, 790200, 320, 0x66e2a42f +-0, 792000, 320, 0x0b0abcb3 +-0, 793800, 320, 0x23a9afaa +-0, 795600, 320, 0xc3729b40 +-0, 797400, 320, 0xdd3fc7e2 +-0, 799200, 320, 0x7e0494af +-0, 801000, 320, 0xcbd096fb +-0, 802800, 320, 0x5d71b303 +-0, 804600, 320, 0xeedca04a +-0, 806400, 320, 0x2836a47d +-0, 808200, 320, 0x7237c2a0 +-0, 810000, 320, 0x7c009bc0 +-0, 811800, 320, 0xc9dcb366 +-0, 813600, 320, 0x4993aac8 +-0, 815400, 320, 0x05ec9954 +-0, 817200, 320, 0xa955bd5c +-0, 819000, 320, 0x9018aea3 +-0, 820800, 320, 0x780cca52 +-0, 822600, 320, 0x9b8f95f6 +-0, 824400, 320, 0xcd7bb178 +-0, 826200, 320, 0xfec6b443 +-0, 828000, 320, 0xe214abb6 +-0, 829800, 320, 0xdcbebb38 +-0, 831600, 320, 0xe683a30d +-0, 833400, 320, 0xe4cdb197 +-0, 835200, 320, 0xa426c432 +-0, 837000, 320, 0x761ba6cc +-0, 838800, 320, 0xcc9aa6aa +-0, 840600, 320, 0x742bd03d +-0, 842400, 320, 0x61d9a511 +-0, 844200, 320, 0x3021a4dd +-0, 846000, 320, 0x6970bbc0 +-0, 847800, 320, 0x76f5a037 +-0, 849600, 320, 0x758d91f2 +-0, 851400, 320, 0xe854a2f1 +-0, 853200, 320, 0xf994a6f8 +-0, 855000, 320, 0x31ebaf40 +-0, 856800, 320, 0x24699970 +-0, 858600, 320, 0x37dda53e +-0, 860400, 320, 0xa857a752 +-0, 862200, 320, 0xc483ad1d +-0, 864000, 320, 0x5966add9 +-0, 865800, 320, 0x4dbab89c +-0, 867600, 320, 0x2f0bb0e6 +-0, 869400, 320, 0x913aaa88 +-0, 871200, 320, 0x245dc1c3 +-0, 873000, 320, 0xb085c5ad +-0, 874800, 320, 0x9cf1b0fa +-0, 876600, 320, 0x6887b543 +-0, 878400, 320, 0xcad69feb +-0, 880200, 320, 0xc12a8ddb +-0, 882000, 320, 0x01d1bc5a +-0, 883800, 320, 0x3018b7e8 +-0, 885600, 320, 0x6431b0ef +-0, 887400, 320, 0x3a53998e +-0, 889200, 320, 0x1c80a6c6 +-0, 891000, 320, 0x6639adc5 +-0, 892800, 320, 0x92489f9a +-0, 894600, 320, 0x8cafad00 +-0, 896400, 320, 0xca0392e1 +-0, 898200, 320, 0x30a9ae88 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/gsm-toast xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/gsm-toast +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/gsm-toast 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/gsm-toast 2012-05-14 14:08:55.660366670 +0200 +@@ -0,0 +1,500 @@ ++0, 0, 320, 0x4c32ab06 ++0, 1800, 320, 0x2052a4e7 ++0, 3600, 320, 0xe9aeafca ++0, 5400, 320, 0xde83b450 ++0, 7200, 320, 0x06a6a80e ++0, 9000, 320, 0xf6aeb1e2 ++0, 10800, 320, 0x2623b40c ++0, 12600, 320, 0x8ec69f25 ++0, 14400, 320, 0xddaaac88 ++0, 16200, 320, 0x9e60b713 ++0, 18000, 320, 0xb738ab30 ++0, 19800, 320, 0xdb4bbb92 ++0, 21600, 320, 0x0370ae8b ++0, 23400, 320, 0xb611a3fb ++0, 25200, 320, 0x07ee8e3b ++0, 27000, 320, 0xdb1ec628 ++0, 28800, 320, 0xd5f1bda2 ++0, 30600, 320, 0xcabb9a9c ++0, 32400, 320, 0x16c8ad61 ++0, 34200, 320, 0xf76fc25e ++0, 36000, 320, 0x7118a10d ++0, 37800, 320, 0x29f9a0db ++0, 39600, 320, 0x41f2a4ef ++0, 41400, 320, 0x36dfb231 ++0, 43200, 320, 0xc5399eda ++0, 45000, 320, 0x17d4b9e0 ++0, 46800, 320, 0x2b5797ac ++0, 48600, 320, 0x0128c5e7 ++0, 50400, 320, 0xf4f38037 ++0, 52200, 320, 0x77d6b5f2 ++0, 54000, 320, 0xd94a93e0 ++0, 55800, 320, 0x968daae3 ++0, 57600, 320, 0xda5ba0ec ++0, 59400, 320, 0x316da1ec ++0, 61200, 320, 0x3a35b2d2 ++0, 63000, 320, 0xca0b988f ++0, 64800, 320, 0x1295b0b1 ++0, 66600, 320, 0xe121ae72 ++0, 68400, 320, 0x7da7ad43 ++0, 70200, 320, 0x96a49cfe ++0, 72000, 320, 0x70c2b1de ++0, 73800, 320, 0x668d88c0 ++0, 75600, 320, 0x5460b5a8 ++0, 77400, 320, 0x6ac78eab ++0, 79200, 320, 0x0d8dab87 ++0, 81000, 320, 0xe2be94af ++0, 82800, 320, 0x3487acdc ++0, 84600, 320, 0x5048955a ++0, 86400, 320, 0x2ef4ae0d ++0, 88200, 320, 0xc765b773 ++0, 90000, 320, 0xad96a486 ++0, 91800, 320, 0xb9fdbf1f ++0, 93600, 320, 0xf26c9ecf ++0, 95400, 320, 0xbcadb535 ++0, 97200, 320, 0xa8c897bc ++0, 99000, 320, 0xaa58b520 ++0, 100800, 320, 0xcb48a716 ++0, 102600, 320, 0x4d5da564 ++0, 104400, 320, 0x9809ae28 ++0, 106200, 320, 0x5baeb1e4 ++0, 108000, 320, 0x6a719b63 ++0, 109800, 320, 0xc27d92f0 ++0, 111600, 320, 0x0e9b9fe9 ++0, 113400, 320, 0xbf9d9bf7 ++0, 115200, 320, 0xf35aa64d ++0, 117000, 320, 0x26449ce8 ++0, 118800, 320, 0x58f4a997 ++0, 120600, 320, 0x155da289 ++0, 122400, 320, 0x63b19a5c ++0, 124200, 320, 0xe01aad38 ++0, 126000, 320, 0x4e0f9c43 ++0, 127800, 320, 0x9447a284 ++0, 129600, 320, 0xdb36a433 ++0, 131400, 320, 0x799a9b2c ++0, 133200, 320, 0x1526a162 ++0, 135000, 320, 0x0a4ea140 ++0, 136800, 320, 0xb08f9ed7 ++0, 138600, 320, 0x221bab76 ++0, 140400, 320, 0x4befacf0 ++0, 142200, 320, 0xac489509 ++0, 144000, 320, 0x57a1a5b4 ++0, 145800, 320, 0x81e8ab97 ++0, 147600, 320, 0xc6ada4d6 ++0, 149400, 320, 0x12489975 ++0, 151200, 320, 0x1da59ba9 ++0, 153000, 320, 0xf225ac62 ++0, 154800, 320, 0x8c8e9eab ++0, 156600, 320, 0x10599dec ++0, 158400, 320, 0x06c39fa5 ++0, 160200, 320, 0xb0efa3c4 ++0, 162000, 320, 0x72caadab ++0, 163800, 320, 0xe4619ff0 ++0, 165600, 320, 0x49bca017 ++0, 167400, 320, 0x413f9fbe ++0, 169200, 320, 0x6eaed0ee ++0, 171000, 320, 0x27e4b1eb ++0, 172800, 320, 0x8c42a30f ++0, 174600, 320, 0x0afaa0f4 ++0, 176400, 320, 0x0f74b76b ++0, 178200, 320, 0xa9a2b9d5 ++0, 180000, 320, 0xde2a8712 ++0, 181800, 320, 0xcfc8b3a2 ++0, 183600, 320, 0x768cadce ++0, 185400, 320, 0x3a8a97f1 ++0, 187200, 320, 0x502fa59b ++0, 189000, 320, 0x4c3e9b0f ++0, 190800, 320, 0x1cd2b111 ++0, 192600, 320, 0xa845a5a3 ++0, 194400, 320, 0xa6b8b982 ++0, 196200, 320, 0x4d5caab9 ++0, 198000, 320, 0x7993b604 ++0, 199800, 320, 0x8d19b37b ++0, 201600, 320, 0xbe48adb6 ++0, 203400, 320, 0x7d68ab8e ++0, 205200, 320, 0xbfffb0e2 ++0, 207000, 320, 0x90b5b7e3 ++0, 208800, 320, 0x9fa1b016 ++0, 210600, 320, 0x70abafc9 ++0, 212400, 320, 0x82cfad9c ++0, 214200, 320, 0x05f6aa2c ++0, 216000, 320, 0x511cbb5b ++0, 217800, 320, 0xd27caaa6 ++0, 219600, 320, 0x781ca481 ++0, 221400, 320, 0x12e9ad1a ++0, 223200, 320, 0xe46b989d ++0, 225000, 320, 0x76dbb0a7 ++0, 226800, 320, 0x10eba486 ++0, 228600, 320, 0x2269a7c8 ++0, 230400, 320, 0x084a9c7e ++0, 232200, 320, 0x84eda891 ++0, 234000, 320, 0x2ef9a639 ++0, 235800, 320, 0x8bb2a0dd ++0, 237600, 320, 0x47e5a169 ++0, 239400, 320, 0x98faae42 ++0, 241200, 320, 0x81d2aba4 ++0, 243000, 320, 0x5af8bb33 ++0, 244800, 320, 0x331e8d9f ++0, 246600, 320, 0xd9b0c09a ++0, 248400, 320, 0xbaf9bfcf ++0, 250200, 320, 0x54e89ab5 ++0, 252000, 320, 0x1d62c1d2 ++0, 253800, 320, 0xead6b436 ++0, 255600, 320, 0x465f98bc ++0, 257400, 320, 0xe707a346 ++0, 259200, 320, 0xf66cb1c2 ++0, 261000, 320, 0xcfc89ae6 ++0, 262800, 320, 0x0b10b796 ++0, 264600, 320, 0xb29caf2c ++0, 266400, 320, 0x0284a9d1 ++0, 268200, 320, 0xb966b5fc ++0, 270000, 320, 0x2defa630 ++0, 271800, 320, 0xcdcd8ef3 ++0, 273600, 320, 0xa81bba2b ++0, 275400, 320, 0x6bc0aeb1 ++0, 277200, 320, 0x38d8ac82 ++0, 279000, 320, 0xeb66a865 ++0, 280800, 320, 0x4fff9cd9 ++0, 282600, 320, 0x6819a19b ++0, 284400, 320, 0xfd7c93ce ++0, 286200, 320, 0xa7419f63 ++0, 288000, 320, 0x572caacb ++0, 289800, 320, 0x918fb1de ++0, 291600, 320, 0x0088a675 ++0, 293400, 320, 0x19229cf7 ++0, 295200, 320, 0x827ea812 ++0, 297000, 320, 0x6c258ef7 ++0, 298800, 320, 0x6a89b8fe ++0, 300600, 320, 0x166c9ce0 ++0, 302400, 320, 0x68b39db7 ++0, 304200, 320, 0x3d5aa8ec ++0, 306000, 320, 0x25e09ff3 ++0, 307800, 320, 0x759aa4ce ++0, 309600, 320, 0xe5aab0ea ++0, 311400, 320, 0xf0359e9a ++0, 313200, 320, 0x51199fff ++0, 315000, 320, 0xb04aa236 ++0, 316800, 320, 0xe09da0e3 ++0, 318600, 320, 0x144f98a9 ++0, 320400, 320, 0x0b4e9f8d ++0, 322200, 320, 0xbb69a090 ++0, 324000, 320, 0xec6e9b5b ++0, 325800, 320, 0x4f86a477 ++0, 327600, 320, 0x4a179d04 ++0, 329400, 320, 0x9682a375 ++0, 331200, 320, 0x3c6ba55e ++0, 333000, 320, 0x50c0ab50 ++0, 334800, 320, 0xe58ea907 ++0, 336600, 320, 0xc5eaa021 ++0, 338400, 320, 0x38859f01 ++0, 340200, 320, 0x73f8a540 ++0, 342000, 320, 0x395da234 ++0, 343800, 320, 0x7f50b144 ++0, 345600, 320, 0x45568ceb ++0, 347400, 320, 0xd0508dec ++0, 349200, 320, 0x60aba7e4 ++0, 351000, 320, 0x4b24b15f ++0, 352800, 320, 0xbfc9afd6 ++0, 354600, 320, 0xf0f2ad49 ++0, 356400, 320, 0xeea0a426 ++0, 358200, 320, 0xff07a7c9 ++0, 360000, 320, 0xce1fc788 ++0, 361800, 320, 0xc074ae9b ++0, 363600, 320, 0x51649696 ++0, 365400, 320, 0x24399744 ++0, 367200, 320, 0xfb0eb920 ++0, 369000, 320, 0x3bf8af5c ++0, 370800, 320, 0xeab69ee0 ++0, 372600, 320, 0x182696bb ++0, 374400, 320, 0x36e6af72 ++0, 376200, 320, 0x48cc9ecc ++0, 378000, 320, 0xfb3ca7b8 ++0, 379800, 320, 0xe01aa4b4 ++0, 381600, 320, 0x5c6dac8c ++0, 383400, 320, 0x072fbd93 ++0, 385200, 320, 0xc8899ccc ++0, 387000, 320, 0xdcc990ac ++0, 388800, 320, 0x28e0a9d0 ++0, 390600, 320, 0x0cdbaa11 ++0, 392400, 320, 0x8f4ca093 ++0, 394200, 320, 0x7ee79ea9 ++0, 396000, 320, 0xa762b695 ++0, 397800, 320, 0x9af0b5da ++0, 399600, 320, 0x1f2cb0e7 ++0, 401400, 320, 0x6029b8bb ++0, 403200, 320, 0xf2f7acec ++0, 405000, 320, 0xb3e5b5be ++0, 406800, 320, 0x266ba8a6 ++0, 408600, 320, 0x4ff59296 ++0, 410400, 320, 0x11d1b9ac ++0, 412200, 320, 0x749197f7 ++0, 414000, 320, 0x8192b517 ++0, 415800, 320, 0xde129dbe ++0, 417600, 320, 0x85e4a096 ++0, 419400, 320, 0xdebf9182 ++0, 421200, 320, 0x7a4ba0bf ++0, 423000, 320, 0x55fe9fcd ++0, 424800, 320, 0xd242adec ++0, 426600, 320, 0xeaf5b159 ++0, 428400, 320, 0xfcb1a571 ++0, 430200, 320, 0x62fabda0 ++0, 432000, 320, 0x45a9abcc ++0, 433800, 320, 0x07af974b ++0, 435600, 320, 0xc2a0b4fd ++0, 437400, 320, 0xc30abccd ++0, 439200, 320, 0xd33ca61c ++0, 441000, 320, 0x3c33d11a ++0, 442800, 320, 0x9c2ca0ac ++0, 444600, 320, 0xa5d69777 ++0, 446400, 320, 0xb7d2c6b8 ++0, 448200, 320, 0x34bbaab9 ++0, 450000, 320, 0x3e7baccb ++0, 451800, 320, 0x92c6b7e6 ++0, 453600, 320, 0xc810a18a ++0, 455400, 320, 0x06a09f56 ++0, 457200, 320, 0x8804a504 ++0, 459000, 320, 0x783ba7d5 ++0, 460800, 320, 0x24dcada6 ++0, 462600, 320, 0x4af796be ++0, 464400, 320, 0x1454b19c ++0, 466200, 320, 0x0ad0a56e ++0, 468000, 320, 0x8944a44e ++0, 469800, 320, 0x31069ebd ++0, 471600, 320, 0x19cb9812 ++0, 473400, 320, 0xac75abe2 ++0, 475200, 320, 0x0162a200 ++0, 477000, 320, 0xa2d7a4b2 ++0, 478800, 320, 0x078ca611 ++0, 480600, 320, 0x0ec39b40 ++0, 482400, 320, 0xe8f794b2 ++0, 484200, 320, 0xc2cfb258 ++0, 486000, 320, 0xe4759061 ++0, 487800, 320, 0xb1b6aea4 ++0, 489600, 320, 0x9bfb96df ++0, 491400, 320, 0xcc61b5d3 ++0, 493200, 320, 0xd14e8df9 ++0, 495000, 320, 0xd9d5bbf5 ++0, 496800, 320, 0x4d9fa9b0 ++0, 498600, 320, 0xf606abfc ++0, 500400, 320, 0x720baa19 ++0, 502200, 320, 0x7f7cac49 ++0, 504000, 320, 0xceab9b54 ++0, 505800, 320, 0x645fa70a ++0, 507600, 320, 0xa081a40f ++0, 509400, 320, 0x21d78f8c ++0, 511200, 320, 0xedf3abc6 ++0, 513000, 320, 0x17679637 ++0, 514800, 320, 0x1cb1ae04 ++0, 516600, 320, 0x17cd9f62 ++0, 518400, 320, 0xf4bca3ab ++0, 520200, 320, 0xb3bd9152 ++0, 522000, 320, 0x4e1e9825 ++0, 523800, 320, 0x037e9a56 ++0, 525600, 320, 0xd7589fcc ++0, 527400, 320, 0x5f949e90 ++0, 529200, 320, 0xe133a495 ++0, 531000, 320, 0x7cb7a52c ++0, 532800, 320, 0xb8b29d95 ++0, 534600, 320, 0x01bca472 ++0, 536400, 320, 0xbcc69895 ++0, 538200, 320, 0xabffa0ee ++0, 540000, 320, 0xe6629eca ++0, 541800, 320, 0x572da7cd ++0, 543600, 320, 0x3017972d ++0, 545400, 320, 0xac4e9c78 ++0, 547200, 320, 0x112f9c45 ++0, 549000, 320, 0x05e9a64d ++0, 550800, 320, 0x8f7394d4 ++0, 552600, 320, 0xbaeea07e ++0, 554400, 320, 0xd757c00e ++0, 556200, 320, 0x8aa09783 ++0, 558000, 320, 0x31d4ae7a ++0, 559800, 320, 0x221493e8 ++0, 561600, 320, 0x92f4a3a7 ++0, 563400, 320, 0xbd5bafd9 ++0, 565200, 320, 0x1895b760 ++0, 567000, 320, 0x7a4eacdd ++0, 568800, 320, 0xc9f7a1c3 ++0, 570600, 320, 0xd750be06 ++0, 572400, 320, 0x641d9a6f ++0, 574200, 320, 0x70d6b6ff ++0, 576000, 320, 0x1fd3a546 ++0, 577800, 320, 0x72cfaabe ++0, 579600, 320, 0x2e61b6ce ++0, 581400, 320, 0x4813a091 ++0, 583200, 320, 0xbfe7bc0f ++0, 585000, 320, 0x8c759c1f ++0, 586800, 320, 0xf4c1c952 ++0, 588600, 320, 0x00fdaa79 ++0, 590400, 320, 0x2ffda252 ++0, 592200, 320, 0x841aa523 ++0, 594000, 320, 0x8c079e5e ++0, 595800, 320, 0x96e9a83f ++0, 597600, 320, 0x5926a639 ++0, 599400, 320, 0x02e1a07b ++0, 601200, 320, 0x2972a999 ++0, 603000, 320, 0x30c89c62 ++0, 604800, 320, 0x83f5a263 ++0, 606600, 320, 0xa3909667 ++0, 608400, 320, 0xd5309fd4 ++0, 610200, 320, 0x3154a571 ++0, 612000, 320, 0x51039a5e ++0, 613800, 320, 0xf167a344 ++0, 615600, 320, 0x8e709d7d ++0, 617400, 320, 0x936fa0fd ++0, 619200, 320, 0x024b9e3c ++0, 621000, 320, 0x2ea1aa75 ++0, 622800, 320, 0x33f0a2bb ++0, 624600, 320, 0xbf079d2d ++0, 626400, 320, 0x847ba2c8 ++0, 628200, 320, 0x37e1a767 ++0, 630000, 320, 0xb607acbb ++0, 631800, 320, 0x1288ac6d ++0, 633600, 320, 0xf60e98b3 ++0, 635400, 320, 0xc6b5abdd ++0, 637200, 320, 0x7feaa710 ++0, 639000, 320, 0x77329fcd ++0, 640800, 320, 0x91a6a715 ++0, 642600, 320, 0xd0e99f24 ++0, 644400, 320, 0x07089f61 ++0, 646200, 320, 0x2bbda900 ++0, 648000, 320, 0xad3da0d5 ++0, 649800, 320, 0x997ba6d2 ++0, 651600, 320, 0xb15b9dcb ++0, 653400, 320, 0x17cea82f ++0, 655200, 320, 0xab51a73e ++0, 657000, 320, 0x77a1abd6 ++0, 658800, 320, 0x0bddacad ++0, 660600, 320, 0x43b3bdc4 ++0, 662400, 320, 0xefe0a9ba ++0, 664200, 320, 0x8eb4bc2f ++0, 666000, 320, 0x39cdc190 ++0, 667800, 320, 0x1ef3baff ++0, 669600, 320, 0x1a6ab7e2 ++0, 671400, 320, 0x444ccc69 ++0, 673200, 320, 0x05ebb598 ++0, 675000, 320, 0x4ac5b0ad ++0, 676800, 320, 0x0ee5ba52 ++0, 678600, 320, 0x501d9fa0 ++0, 680400, 320, 0x2038a9f4 ++0, 682200, 320, 0xa61cb8b3 ++0, 684000, 320, 0xdd009777 ++0, 685800, 320, 0x2a2db86d ++0, 687600, 320, 0xe9bab3bc ++0, 689400, 320, 0xf7f8a056 ++0, 691200, 320, 0x514caf14 ++0, 693000, 320, 0xa220b149 ++0, 694800, 320, 0xbf7ea183 ++0, 696600, 320, 0x1d8dc5c6 ++0, 698400, 320, 0x9182a8ea ++0, 700200, 320, 0x31eba026 ++0, 702000, 320, 0xcfbcc3df ++0, 703800, 320, 0x3d8cb7ae ++0, 705600, 320, 0xbe39aec0 ++0, 707400, 320, 0xd236bf71 ++0, 709200, 320, 0x9377b0b2 ++0, 711000, 320, 0xb5e6b2df ++0, 712800, 320, 0xa3b9bbce ++0, 714600, 320, 0xa7bda251 ++0, 716400, 320, 0xbf9ab162 ++0, 718200, 320, 0x6928b9cb ++0, 720000, 320, 0xf5cca209 ++0, 721800, 320, 0xfdf4afad ++0, 723600, 320, 0xe7e7c216 ++0, 725400, 320, 0x0c5797c6 ++0, 727200, 320, 0x66c1a9ca ++0, 729000, 320, 0x6b5ca48d ++0, 730800, 320, 0xec04968a ++0, 732600, 320, 0xaaada691 ++0, 734400, 320, 0x77c3a624 ++0, 736200, 320, 0xaed9a5d5 ++0, 738000, 320, 0x360fac41 ++0, 739800, 320, 0xa05ea727 ++0, 741600, 320, 0x9f7b9f83 ++0, 743400, 320, 0x474bc4c2 ++0, 745200, 320, 0xb6078d3b ++0, 747000, 320, 0x8e15a8f9 ++0, 748800, 320, 0x7dc7d4a8 ++0, 750600, 320, 0x55ceab6b ++0, 752400, 320, 0x982cc94f ++0, 754200, 320, 0x6153948f ++0, 756000, 320, 0x5338c621 ++0, 757800, 320, 0x2e2db6e8 ++0, 759600, 320, 0x28e3a9c3 ++0, 761400, 320, 0x74d7b435 ++0, 763200, 320, 0xcf17a10c ++0, 765000, 320, 0xf1f9ac8c ++0, 766800, 320, 0x35e0b480 ++0, 768600, 320, 0x5e60b3a4 ++0, 770400, 320, 0x20579b26 ++0, 772200, 320, 0x3e27b89b ++0, 774000, 320, 0x02e4af94 ++0, 775800, 320, 0x6d6897f1 ++0, 777600, 320, 0x1582b267 ++0, 779400, 320, 0x33ba9eb3 ++0, 781200, 320, 0xb6acad7d ++0, 783000, 320, 0x1969a6c2 ++0, 784800, 320, 0x363fa350 ++0, 786600, 320, 0xae50bf65 ++0, 788400, 320, 0x0877a50f ++0, 790200, 320, 0x66e2a42f ++0, 792000, 320, 0x0b0abcb3 ++0, 793800, 320, 0x23a9afaa ++0, 795600, 320, 0xc3729b40 ++0, 797400, 320, 0xdd3fc7e2 ++0, 799200, 320, 0x7e0494af ++0, 801000, 320, 0xcbd096fb ++0, 802800, 320, 0x5d71b303 ++0, 804600, 320, 0xeedca04a ++0, 806400, 320, 0x2836a47d ++0, 808200, 320, 0x7237c2a0 ++0, 810000, 320, 0x7c009bc0 ++0, 811800, 320, 0xc9dcb366 ++0, 813600, 320, 0x4993aac8 ++0, 815400, 320, 0x05ec9954 ++0, 817200, 320, 0xa955bd5c ++0, 819000, 320, 0x9018aea3 ++0, 820800, 320, 0x780cca52 ++0, 822600, 320, 0x9b8f95f6 ++0, 824400, 320, 0xcd7bb178 ++0, 826200, 320, 0xfec6b443 ++0, 828000, 320, 0xe214abb6 ++0, 829800, 320, 0xdcbebb38 ++0, 831600, 320, 0xe683a30d ++0, 833400, 320, 0xe4cdb197 ++0, 835200, 320, 0xa426c432 ++0, 837000, 320, 0x761ba6cc ++0, 838800, 320, 0xcc9aa6aa ++0, 840600, 320, 0x742bd03d ++0, 842400, 320, 0x61d9a511 ++0, 844200, 320, 0x3021a4dd ++0, 846000, 320, 0x6970bbc0 ++0, 847800, 320, 0x76f5a037 ++0, 849600, 320, 0x758d91f2 ++0, 851400, 320, 0xe854a2f1 ++0, 853200, 320, 0xf994a6f8 ++0, 855000, 320, 0x31ebaf40 ++0, 856800, 320, 0x24699970 ++0, 858600, 320, 0x37dda53e ++0, 860400, 320, 0xa857a752 ++0, 862200, 320, 0xc483ad1d ++0, 864000, 320, 0x5966add9 ++0, 865800, 320, 0x4dbab89c ++0, 867600, 320, 0x2f0bb0e6 ++0, 869400, 320, 0x913aaa88 ++0, 871200, 320, 0x245dc1c3 ++0, 873000, 320, 0xb085c5ad ++0, 874800, 320, 0x9cf1b0fa ++0, 876600, 320, 0x6887b543 ++0, 878400, 320, 0xcad69feb ++0, 880200, 320, 0xc12a8ddb ++0, 882000, 320, 0x01d1bc5a ++0, 883800, 320, 0x3018b7e8 ++0, 885600, 320, 0x6431b0ef ++0, 887400, 320, 0x3a53998e ++0, 889200, 320, 0x1c80a6c6 ++0, 891000, 320, 0x6639adc5 ++0, 892800, 320, 0x92489f9a ++0, 894600, 320, 0x8cafad00 ++0, 896400, 320, 0xca0392e1 ++0, 898200, 320, 0x30a9ae88 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-bsf-mp4toannexb xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-bsf-mp4toannexb +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-bsf-mp4toannexb 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-bsf-mp4toannexb 2012-05-14 14:08:55.660366670 +0200 +@@ -0,0 +1 @@ ++5f04c27cc6ee8625fe2405fb0f7da9a3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr10_sony_b 2012-05-14 14:08:55.664366750 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 202752, 0xffa1c502 ++0, 3600, 202752, 0x51752f3c ++0, 7200, 202752, 0xe683991d ++0, 10800, 202752, 0xf70200a4 ++0, 14400, 202752, 0x1a4d63ef +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr13_sony_b 2012-05-14 14:08:55.664366750 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 405504, 0xe0f40e71 ++0, 3600, 405504, 0x9bdb5900 ++0, 7200, 405504, 0x527003ca ++0, 10800, 405504, 0x1fbf8ba6 ++0, 14400, 405504, 0x455e2a4e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr1_sony_a 2012-05-14 14:08:55.665366770 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 202752, 0xd5a1e49f ++0, 3600, 202752, 0x08352d61 ++0, 7200, 202752, 0x43f78f47 ++0, 10800, 202752, 0xfb5910f4 ++0, 14400, 202752, 0xd98e8739 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-hi422fr6_sony_a 2012-05-14 14:08:55.665366770 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 405504, 0x049ab58e ++0, 3600, 405504, 0x4f6226cb ++0, 7200, 405504, 0xaa5fcb44 ++0, 10800, 405504, 0xbfc09965 ++0, 14400, 405504, 0xa30acb90 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i1_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i1_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i1_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i1_panasonic_a 2012-05-14 14:08:55.666366790 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 2764800, 0xcc4df07d ++0, 3600, 2764800, 0x85f9e6d4 ++0, 7200, 2764800, 0x23ffe90d ++0, 10800, 2764800, 0xf0a6d453 ++0, 14400, 2764800, 0x913a6392 ++0, 18000, 2764800, 0xcc5f9736 ++0, 21600, 2764800, 0x43f9f9ce ++0, 25200, 2764800, 0xc874b44e ++0, 28800, 2764800, 0x83b665e6 ++0, 32400, 2764800, 0x5ea2e31e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i2_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i2_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i2_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i2_panasonic_a 2012-05-14 14:08:55.666366790 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 2764800, 0x4f710132 ++0, 3600, 2764800, 0x57e5b713 ++0, 7200, 2764800, 0xcca01477 ++0, 10800, 2764800, 0xa19a95cd ++0, 14400, 2764800, 0x700a757d ++0, 18000, 2764800, 0xd8c6f60f ++0, 21600, 2764800, 0x95a1bbc7 ++0, 25200, 2764800, 0x0582077a ++0, 28800, 2764800, 0x91595f91 ++0, 32400, 2764800, 0xf5fe034a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i3_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i3_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i3_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i3_panasonic_a 2012-05-14 14:08:55.667366810 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 2764800, 0xda69f69e ++0, 3600, 2764800, 0x29ed832f ++0, 7200, 2764800, 0xb3244cc4 ++0, 10800, 2764800, 0xe41a312c ++0, 14400, 2764800, 0xac0b344b ++0, 18000, 2764800, 0xc585aa20 ++0, 21600, 2764800, 0x0952054c ++0, 25200, 2764800, 0xd1a02f87 ++0, 28800, 2764800, 0xfcbfe87c ++0, 32400, 2764800, 0xe4e9b8a2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i4_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i4_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i4_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i4_panasonic_a 2012-05-14 14:08:55.667366810 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 6220800, 0xca2a2a5e ++0, 3600, 6220800, 0x8009a65e ++0, 7200, 6220800, 0x63e72b3b ++0, 10800, 6220800, 0x7459a1cc ++0, 14400, 6220800, 0x02191aa9 ++0, 18000, 6220800, 0x88dca590 ++0, 21600, 6220800, 0x4484d484 ++0, 25200, 6220800, 0x8afdb53f ++0, 28800, 6220800, 0xd3d6017a ++0, 32400, 6220800, 0xf5162af0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i5_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i5_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i5_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i5_panasonic_a 2012-05-14 14:08:55.668366830 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 6220800, 0x1df58ce9 ++0, 3600, 6220800, 0x8f2859ce ++0, 7200, 6220800, 0x229cc7ff ++0, 10800, 6220800, 0x73e86984 ++0, 14400, 6220800, 0xb6d4504b ++0, 18000, 6220800, 0x4e7d4883 ++0, 21600, 6220800, 0xbec3f0f7 ++0, 25200, 6220800, 0x1d9af065 ++0, 28800, 6220800, 0x44851549 ++0, 32400, 6220800, 0xfcf8728e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i6_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i6_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i6_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i6_panasonic_a 2012-05-14 14:08:55.668366830 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 6220800, 0x408daf70 ++0, 3600, 6220800, 0x59b254a3 ++0, 7200, 6220800, 0x4cf4279c ++0, 10800, 6220800, 0x5c9437ae ++0, 14400, 6220800, 0x986c3eb8 ++0, 18000, 6220800, 0x23fd883e ++0, 21600, 6220800, 0x84f222fe ++0, 25200, 6220800, 0xe7f91107 ++0, 28800, 6220800, 0xb544b31e ++0, 32400, 6220800, 0x1ebdde56 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i7_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i7_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i7_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph10i7_panasonic_a 2012-05-14 14:08:55.669366850 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 6220800, 0xf81873fe ++0, 3600, 6220800, 0x7b96fbdc ++0, 7200, 6220800, 0x75dbafc4 ++0, 10800, 6220800, 0x7524301e ++0, 14400, 6220800, 0x0f3621ab ++0, 18000, 6220800, 0xa5e25b35 ++0, 21600, 6220800, 0x063a8116 ++0, 25200, 6220800, 0x48ebc8ff ++0, 28800, 6220800, 0x1f635df8 ++0, 32400, 6220800, 0xe282c8bd +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i1_panasonic_a 2012-05-14 14:08:55.669366850 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 3686400, 0x1f9b5bee ++0, 3600, 3686400, 0x657c3609 ++0, 7200, 3686400, 0x75753934 ++0, 10800, 3686400, 0xf434d8e1 ++0, 14400, 3686400, 0x40679c77 ++0, 18000, 3686400, 0x5734d8db ++0, 21600, 3686400, 0x4a3d8269 ++0, 25200, 3686400, 0xd20b6cf6 ++0, 28800, 3686400, 0x31956bca ++0, 32400, 3686400, 0xd28d9758 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i2_panasonic_a 2012-05-14 14:08:55.670366870 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 3686400, 0x8b3ff360 ++0, 3600, 3686400, 0x422dead1 ++0, 7200, 3686400, 0xbdd0e431 ++0, 10800, 3686400, 0x1e3cc216 ++0, 14400, 3686400, 0x1a80b718 ++0, 18000, 3686400, 0xc7e3c0a2 ++0, 21600, 3686400, 0xffc99142 ++0, 25200, 3686400, 0x8b3bdf1e ++0, 28800, 3686400, 0xff1bccfb ++0, 32400, 3686400, 0x781fc45b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i3_panasonic_a 2012-05-14 14:08:55.670366870 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 3686400, 0x97c36ae3 ++0, 3600, 3686400, 0x6a0aa629 ++0, 7200, 3686400, 0xc658d722 ++0, 10800, 3686400, 0x713bc774 ++0, 14400, 3686400, 0x8d0b3afe ++0, 18000, 3686400, 0x62bf24cd ++0, 21600, 3686400, 0x77e80436 ++0, 25200, 3686400, 0x4f258e07 ++0, 28800, 3686400, 0x8426bc53 ++0, 32400, 3686400, 0xd33b58c8 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i4_panasonic_a 2012-05-14 14:08:55.671366890 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 8294400, 0xf50992f3 ++0, 3600, 8294400, 0xd34cdf98 ++0, 7200, 8294400, 0x76bced00 ++0, 10800, 8294400, 0xf9ffd9b1 ++0, 14400, 8294400, 0x303231aa ++0, 18000, 8294400, 0x0ca57c6a ++0, 21600, 8294400, 0xaa056bd5 ++0, 25200, 8294400, 0x785c9a12 ++0, 28800, 8294400, 0xe535750e ++0, 32400, 8294400, 0x78fd76bb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i5_panasonic_a 2012-05-14 14:08:55.671366890 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 8294400, 0x96d051a1 ++0, 3600, 8294400, 0xf3c2974e ++0, 7200, 8294400, 0xb18f3ed0 ++0, 10800, 8294400, 0xb5ba9998 ++0, 14400, 8294400, 0x96327a34 ++0, 18000, 8294400, 0xe24d7b61 ++0, 21600, 8294400, 0xc45d5a16 ++0, 25200, 8294400, 0x13b4a537 ++0, 28800, 8294400, 0xa81dae90 ++0, 32400, 8294400, 0x2820bbe9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i6_panasonic_a 2012-05-14 14:08:55.672366910 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 8294400, 0x1b2f1079 ++0, 3600, 8294400, 0x6646f91c ++0, 7200, 8294400, 0x17dc9f51 ++0, 10800, 8294400, 0x4aad9b3a ++0, 14400, 8294400, 0x8a422d34 ++0, 18000, 8294400, 0x8fd76d87 ++0, 21600, 8294400, 0xc7c75f18 ++0, 25200, 8294400, 0x4a1c2643 ++0, 28800, 8294400, 0xfe225709 ++0, 32400, 8294400, 0x032ad2e5 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/h264-conformance-frext-pph422i7_panasonic_a 2012-05-14 14:08:55.672366910 +0200 +@@ -0,0 +1,10 @@ ++0, 0, 8294400, 0xaa37ceea ++0, 3600, 8294400, 0xa7546d5c ++0, 7200, 8294400, 0xf2abaace ++0, 10800, 8294400, 0x36f4d47e ++0, 14400, 8294400, 0x1cdf917d ++0, 18000, 8294400, 0xa9377ba3 ++0, 21600, 8294400, 0x21c9db51 ++0, 25200, 8294400, 0x07d7936e ++0, 28800, 8294400, 0x7878ab94 ++0, 32400, 8294400, 0x77e40921 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/idroq-video-dpcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/idroq-video-dpcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/idroq-video-dpcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/idroq-video-dpcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,377 +0,0 @@ +-1, 0, 29824, 0x77e265b7 +-0, 0, 393216, 0x56995aac +-0, 3000, 393216, 0xf9ed5d6c +-0, 6000, 393216, 0xd3285d75 +-0, 9000, 393216, 0x82d15d62 +-0, 12000, 393216, 0x893e5d6f +-0, 15000, 393216, 0x82d15d62 +-0, 18000, 393216, 0x893e5d6f +-0, 21000, 393216, 0x82d15d62 +-0, 24000, 393216, 0x893e5d6f +-0, 27000, 393216, 0x82d15d62 +-0, 30000, 393216, 0x893e5d6f +-1, 30433, 2944, 0x8dcdf50b +-0, 33000, 393216, 0x82d15d62 +-1, 33437, 2944, 0xb135cd2a +-0, 36000, 393216, 0x893e5d6f +-1, 36441, 2944, 0x54a6e73f +-0, 39000, 393216, 0x82d15d62 +-1, 39445, 2944, 0x050ccd4e +-0, 42000, 393216, 0x893e5d6f +-1, 42449, 2944, 0x6b68db44 +-0, 45000, 393216, 0x82d15d62 +-1, 45453, 2944, 0x55d1f308 +-0, 48000, 393216, 0x2ae39eca +-1, 48457, 2944, 0x7e92f50b +-0, 51000, 393216, 0x9254be70 +-1, 51461, 2944, 0xe9e91eed +-0, 54000, 393216, 0x4b2ed384 +-1, 54465, 2944, 0x80af2ce0 +-0, 57000, 393216, 0xbbd9d8f7 +-1, 57469, 2944, 0xc67ffb07 +-0, 60000, 393216, 0x1f2be0c3 +-1, 60473, 2944, 0x7aaded27 +-0, 63000, 393216, 0x2434eb25 +-1, 63478, 2944, 0x14a024fd +-0, 66000, 393216, 0xa6cced4e +-1, 66482, 2944, 0x26e8df1f +-0, 69000, 393216, 0xd116f38b +-1, 69486, 2944, 0x2688df44 +-0, 72000, 393216, 0x6b86f380 +-1, 72490, 2944, 0x4b9cdd33 +-0, 75000, 393216, 0xc1b3f8e9 +-1, 75494, 2944, 0x10c2f11c +-0, 78000, 393216, 0x2993fd5d +-1, 78498, 2944, 0xc4e3ad6d +-0, 81000, 393216, 0xf489fe18 +-1, 81502, 2944, 0xbeb1a78e +-0, 84000, 393216, 0x9ef10501 +-1, 84506, 2944, 0x283d4e7f +-0, 87000, 393216, 0x8faf0512 +-1, 87510, 2944, 0x4acf65e0 +-0, 90000, 393216, 0xa54d0736 +-1, 90514, 2944, 0x0ca29b8c +-0, 93000, 393216, 0xf4ef01e0 +-1, 93518, 2944, 0x003fae34 +-0, 96000, 393216, 0xe241ef51 +-1, 96522, 2944, 0x2acfec7e +-0, 99000, 393216, 0xcc38e51f +-1, 99527, 2944, 0xea6fc6fe +-0, 102000, 393216, 0xb1345876 +-1, 102531, 2944, 0xf5daec2f +-0, 105000, 393216, 0xf9b0968b +-1, 105535, 2944, 0x8d33ed7a +-0, 108000, 393216, 0x6bb1523f +-1, 108539, 2944, 0xc328f984 +-0, 111000, 393216, 0x83469a05 +-1, 111543, 2944, 0x6e0b58d3 +-0, 114000, 393216, 0x73e30882 +-1, 114547, 2944, 0xe282dc3f +-0, 117000, 393216, 0x8673da66 +-1, 117551, 2944, 0xbf9bf3e6 +-0, 120000, 393216, 0xb67596d3 +-1, 120555, 2944, 0xd7b7d7e3 +-0, 123000, 393216, 0xf7638710 +-1, 123559, 2944, 0x4e87b6ab +-0, 126000, 393216, 0x813a8f47 +-1, 126563, 2944, 0x7b8ce8d6 +-0, 129000, 393216, 0xb3526555 +-1, 129567, 2944, 0xd42991a5 +-0, 132000, 393216, 0x1b167be3 +-1, 132571, 2944, 0x452c98ca +-0, 135000, 393216, 0x99114562 +-1, 135576, 2944, 0x6d27832d +-0, 138000, 393216, 0xfafb0693 +-1, 138580, 2944, 0xa558720e +-0, 141000, 393216, 0x121d96c8 +-1, 141584, 2944, 0x0a31bec0 +-0, 144000, 393216, 0xb3c68c5d +-1, 144588, 2944, 0x28431384 +-0, 147000, 393216, 0x2035b97f +-1, 147592, 2944, 0xd5e9fb3d +-0, 150000, 393216, 0xfbcaeb62 +-1, 150596, 2944, 0x34f0e9f8 +-0, 153000, 393216, 0xfd5aea5d +-1, 153600, 2944, 0x979432df +-0, 156000, 393216, 0x66efbddd +-1, 156604, 2944, 0xb00acd4d +-0, 159000, 393216, 0xf1e17862 +-1, 159608, 2944, 0x726bffd6 +-0, 162000, 393216, 0x27fa584d +-1, 162612, 2944, 0xa1f39a6d +-0, 165000, 393216, 0xe644ec5f +-1, 165616, 2944, 0xf6a8e30e +-0, 168000, 393216, 0x7e3067ba +-1, 168620, 2944, 0x608e9e06 +-0, 171000, 393216, 0x1b6ba6fd +-1, 171624, 2944, 0x4ec58bc3 +-0, 174000, 393216, 0x55bdba34 +-1, 174629, 2944, 0x6d5c8458 +-0, 177000, 393216, 0xc67db2e4 +-1, 177633, 2944, 0x76a0abbd +-0, 180000, 393216, 0x359de8a2 +-1, 180637, 2944, 0xf830e8a6 +-0, 183000, 393216, 0x7b7a32ef +-1, 183641, 2944, 0x1bdd7bec +-0, 186000, 393216, 0xbe512a66 +-1, 186645, 2944, 0x3c1bd187 +-0, 189000, 393216, 0x681d82bf +-1, 189649, 2944, 0xf52cf697 +-0, 192000, 393216, 0xa2320ec5 +-1, 192653, 2944, 0x8f65b773 +-0, 195000, 393216, 0xcfbd9954 +-1, 195657, 2944, 0xf8b5b598 +-0, 198000, 393216, 0x7fee9854 +-1, 198661, 2944, 0xcd87d5ed +-0, 201000, 393216, 0x70eec155 +-1, 201665, 2944, 0x672ac02a +-0, 204000, 393216, 0x114f684e +-1, 204669, 2944, 0x1d5d13ed +-0, 207000, 393216, 0xe27f034f +-1, 207673, 2944, 0xe298e3d4 +-0, 210000, 393216, 0xfbbd89b4 +-1, 210678, 2944, 0x3d2e9c32 +-0, 213000, 393216, 0xcef4c58a +-1, 213682, 2944, 0xf3a39259 +-0, 216000, 393216, 0x9eea88e9 +-1, 216686, 2944, 0x930ae8f8 +-0, 219000, 393216, 0x911cea42 +-1, 219690, 2944, 0x8562aff7 +-0, 222000, 393216, 0xec5727ea +-1, 222694, 2944, 0x9cd6c6a7 +-0, 225000, 393216, 0xda998c33 +-1, 225698, 2944, 0x2709dc5c +-0, 228000, 393216, 0xc82140ed +-1, 228702, 2944, 0xcbe31816 +-0, 231000, 393216, 0x4caa8591 +-1, 231706, 2944, 0xd7876ec4 +-0, 234000, 393216, 0x4944206c +-1, 234710, 2944, 0xc2468b6a +-0, 237000, 393216, 0xd4676a94 +-1, 237714, 2944, 0x76043e84 +-0, 240000, 393216, 0x9e0340b3 +-1, 240718, 2944, 0xd2c35bf0 +-0, 243000, 393216, 0xbdef7f94 +-1, 243722, 2944, 0x63de6061 +-0, 246000, 393216, 0xfac05cb0 +-1, 246727, 2944, 0xd8f6ed1d +-0, 249000, 393216, 0xfef5a369 +-1, 249731, 2944, 0xe034928a +-0, 252000, 393216, 0x9fcb3711 +-1, 252735, 2944, 0xa044da74 +-0, 255000, 393216, 0x6d93f761 +-1, 255739, 2944, 0xee410dba +-0, 258000, 393216, 0xe95dc1ae +-1, 258743, 2944, 0x8e020c7c +-0, 261000, 393216, 0x3e561557 +-1, 261747, 2944, 0x73057ddb +-0, 264000, 393216, 0x0fa7a049 +-1, 264751, 2944, 0xdee5cc18 +-0, 267000, 393216, 0xf16afb95 +-1, 267755, 2944, 0xf4d31dec +-0, 270000, 393216, 0xe53a2064 +-1, 270759, 2944, 0xe8131e1c +-0, 273000, 393216, 0x57f046a4 +-1, 273763, 2944, 0x8ae69c95 +-0, 276000, 393216, 0xf6f16a0c +-1, 276767, 2944, 0x791c0bf4 +-0, 279000, 393216, 0xcba0c8b0 +-1, 279771, 2944, 0xd45a10db +-0, 282000, 393216, 0x5bdbe522 +-1, 282776, 2944, 0x3a72b010 +-0, 285000, 393216, 0x0fed0151 +-1, 285780, 2944, 0x6a4a0411 +-0, 288000, 393216, 0xbf86faf8 +-1, 288784, 2944, 0xd77ab7f5 +-0, 291000, 393216, 0x39854c5f +-1, 291788, 2944, 0xe3bf4fe5 +-0, 294000, 393216, 0xd9b7760a +-1, 294792, 2944, 0x12db1be8 +-0, 297000, 393216, 0x8edcc1d9 +-1, 297796, 2944, 0x345210b0 +-0, 300000, 393216, 0x44ae1435 +-1, 300800, 2944, 0xcfc1f892 +-0, 303000, 393216, 0xbc3d6d73 +-1, 303804, 2944, 0x5b0a80bb +-0, 306000, 393216, 0xedd82647 +-1, 306808, 2944, 0x31ab1168 +-0, 309000, 393216, 0x1c2e5ce3 +-1, 309812, 2944, 0xd4a4bb0a +-0, 312000, 393216, 0x04e29afe +-1, 312816, 2944, 0x8e211c8f +-0, 315000, 393216, 0xb191578e +-1, 315820, 2944, 0xcf464d50 +-0, 318000, 393216, 0x31d75a06 +-1, 318824, 2944, 0xe74ff3d6 +-0, 321000, 393216, 0xfdb6c56e +-1, 321829, 2944, 0x6274635f +-0, 324000, 393216, 0xf528f484 +-1, 324833, 2944, 0xc34c9f64 +-0, 327000, 393216, 0x87af758e +-1, 327837, 2944, 0xbb997537 +-0, 330000, 393216, 0xc8bdafb7 +-1, 330841, 2944, 0x3600da72 +-0, 333000, 393216, 0x573afe93 +-1, 333845, 2944, 0x343e15f4 +-0, 336000, 393216, 0xb03cb8f5 +-1, 336849, 2944, 0x17bc58a8 +-0, 339000, 393216, 0x6e03ac71 +-1, 339853, 2944, 0x3dcbd3ff +-0, 342000, 393216, 0xf919164e +-1, 342857, 2944, 0x1d422371 +-0, 345000, 393216, 0x80059f3c +-1, 345861, 2944, 0xe2b83d9d +-0, 348000, 393216, 0xf4ea0b1a +-1, 348865, 2944, 0x65388409 +-0, 351000, 393216, 0xe7720ffb +-1, 351869, 2944, 0xafbca269 +-0, 354000, 393216, 0x1ec0cd56 +-1, 354873, 2944, 0x2d00c0fb +-0, 357000, 393216, 0x2bc8cf18 +-1, 357878, 2944, 0xbac9c503 +-0, 360000, 393216, 0xe0bf17b5 +-1, 360882, 2944, 0x9990768d +-0, 363000, 393216, 0x660247e1 +-1, 363886, 2944, 0x8ba978be +-0, 366000, 393216, 0xcf66f2a9 +-1, 366890, 2944, 0x5a44a2f5 +-0, 369000, 393216, 0x5494d5ab +-1, 369894, 2944, 0xa4b6f3b8 +-0, 372000, 393216, 0x2c02f2c4 +-1, 372898, 2944, 0x631b6b9f +-0, 375000, 393216, 0x93fa3783 +-1, 375902, 2944, 0x4c840923 +-0, 378000, 393216, 0x4cc50633 +-1, 378906, 2944, 0x7c105df3 +-0, 381000, 393216, 0x3f179386 +-1, 381910, 2944, 0x01bcb213 +-0, 384000, 393216, 0x2bca9e1b +-1, 384914, 2944, 0x95cffbf7 +-0, 387000, 393216, 0x3e4af867 +-1, 387918, 2944, 0x170a9c3a +-0, 390000, 393216, 0x7e7df93c +-1, 390922, 2944, 0x59e09d61 +-0, 393000, 393216, 0x577e4fb0 +-1, 393927, 2944, 0x3ea0f205 +-0, 396000, 393216, 0x34487f0a +-1, 396931, 2944, 0xd9ea1a3a +-0, 399000, 393216, 0x0937bcfc +-1, 399935, 2944, 0xaf32d704 +-0, 402000, 393216, 0xa9e75a5e +-1, 402939, 2944, 0x2d473392 +-0, 405000, 393216, 0xf7bc0c89 +-1, 405943, 2944, 0x2a8ec544 +-0, 408000, 393216, 0x06dacca6 +-1, 408947, 2944, 0x883c8838 +-0, 411000, 393216, 0x7baaa4bd +-1, 411951, 2944, 0xfaf4d789 +-0, 414000, 393216, 0x95477f5f +-1, 414955, 2944, 0xcb315b65 +-0, 417000, 393216, 0x51117526 +-1, 417959, 2944, 0x980c93b0 +-0, 420000, 393216, 0x69656d03 +-1, 420963, 2944, 0x0819583b +-0, 423000, 393216, 0xcbd061bb +-1, 423967, 2944, 0xf126e5b5 +-0, 426000, 393216, 0x8d1d5be2 +-1, 426971, 2944, 0x88836255 +-0, 429000, 393216, 0x43e55930 +-1, 429976, 2944, 0xc8ae8ca8 +-0, 432000, 393216, 0xb56f5872 +-1, 432980, 2944, 0xf0750551 +-0, 435000, 393216, 0x09a255e9 +-1, 435984, 2944, 0x3dfe13a3 +-0, 438000, 393216, 0xcaaa5456 +-1, 438988, 2944, 0xf2aa957b +-0, 441000, 393216, 0xd267501f +-1, 441992, 2944, 0xa77b79a3 +-0, 444000, 393216, 0x7bef4eca +-1, 444996, 2944, 0xb1038284 +-0, 447000, 393216, 0x9aa94af3 +-1, 448000, 2944, 0xf96be3ba +-0, 450000, 393216, 0xd39d4a29 +-1, 451004, 2944, 0x1ae6e293 +-0, 453000, 393216, 0x7a754960 +-1, 454008, 2944, 0x2059d020 +-0, 456000, 393216, 0x3f004921 +-1, 457012, 2944, 0x7e6c9996 +-0, 459000, 393216, 0x0f784ca8 +-1, 460016, 2944, 0x3108b540 +-0, 462000, 393216, 0x2a062c70 +-1, 463020, 2944, 0x75133155 +-0, 465000, 393216, 0x114ef770 +-1, 466024, 2944, 0x59a19226 +-0, 468000, 393216, 0xfb7673bf +-1, 469029, 2944, 0x3140c138 +-0, 471000, 393216, 0xbaea88f7 +-1, 472033, 2944, 0x7570d3be +-0, 474000, 393216, 0x6fdfe2ec +-1, 475037, 2944, 0x54fd4ff6 +-0, 477000, 393216, 0xb7b2b398 +-1, 478041, 2944, 0x23bcf6dc +-0, 480000, 393216, 0x14ba127e +-1, 481045, 2944, 0x2d26489b +-0, 483000, 393216, 0x660b3041 +-1, 484049, 2944, 0x4b37bf13 +-0, 486000, 393216, 0xe3f3302a +-1, 487053, 2944, 0x12812ec9 +-0, 489000, 393216, 0x34c7f1c9 +-1, 490057, 2944, 0xc4a609dd +-0, 492000, 393216, 0xa8257bf4 +-1, 493061, 2944, 0x5a8c5b20 +-0, 495000, 393216, 0xd63fc649 +-1, 496065, 2944, 0xd05d110f +-0, 498000, 393216, 0xf8e5b79c +-1, 499069, 2944, 0xceea6f1f +-0, 501000, 393216, 0xa67b52ab +-1, 502073, 2944, 0x4033b0a5 +-0, 504000, 393216, 0xef8f9c74 +-1, 505078, 2944, 0x101895ce +-0, 507000, 393216, 0x6d3aa6b6 +-1, 508082, 2944, 0xd6c6809f +-0, 510000, 393216, 0x8c174ee6 +-1, 511086, 2944, 0x197bda7e +-0, 513000, 393216, 0x2dfbc524 +-1, 514090, 2944, 0x96fb3e4b +-0, 516000, 393216, 0x7d0808b6 +-1, 517094, 2944, 0x12a6e3de +-0, 519000, 393216, 0x6cbdf6f5 +-1, 520098, 2944, 0xfb80e466 +-0, 522000, 393216, 0xfe39bc53 +-1, 523102, 2944, 0xedb8c2fc +-0, 525000, 393216, 0xa3d869b0 +-1, 526106, 1016, 0x30e56ca5 +-0, 528000, 393216, 0x09f00057 +-0, 531000, 393216, 0x6ba56343 +-0, 534000, 393216, 0xb696ca3e +-0, 537000, 393216, 0x4eba0225 +-0, 540000, 393216, 0xdd45464b +-0, 543000, 393216, 0x2909a9ea +-0, 546000, 393216, 0x12aa3f85 +-0, 549000, 393216, 0x59421352 +-0, 552000, 393216, 0x57ea0313 +-0, 555000, 393216, 0x4e5f3a38 +-0, 558000, 393216, 0x55bc932d +-0, 561000, 393216, 0x666ee55d +-0, 564000, 393216, 0xb0f84a69 +-0, 567000, 393216, 0xad3ae63f +-0, 570000, 393216, 0x970fd47d +-0, 573000, 393216, 0x86c418e0 +-0, 576000, 393216, 0x52c9ce50 +-0, 579000, 393216, 0xd54c98c8 +-0, 582000, 393216, 0xb40e5fea +-0, 585000, 393216, 0x2aa74875 +-0, 588000, 393216, 0x305b251e +-0, 591000, 393216, 0xab8c0780 +-0, 594000, 393216, 0x0101dd0e +-0, 597000, 393216, 0x23739cab +-0, 600000, 393216, 0xf05196a0 +-0, 603000, 393216, 0x932d1e00 +-0, 606000, 393216, 0x932d1e00 +-0, 609000, 393216, 0x932d1e00 +-0, 612000, 393216, 0x932d1e00 +-0, 615000, 393216, 0x932d1e00 +-0, 618000, 393216, 0x932d1e00 +-0, 621000, 393216, 0x932d1e00 +-0, 624000, 393216, 0x932d1e00 +-0, 627000, 393216, 0x932d1e00 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/iff-fibonacci xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/iff-fibonacci +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/iff-fibonacci 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/iff-fibonacci 2012-05-14 14:08:55.674366950 +0200 +@@ -1 +1 @@ +-e968a853779bb6438339e3b8d69d8d24 ++e76b025238a6a27968f8644f4ccc3207 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/iirfilter xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/iirfilter +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/iirfilter 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/iirfilter 2012-05-14 14:08:55.675366971 +0200 +@@ -0,0 +1,1024 @@ ++ 0 0 ++ 38 2 ++ 151 15 ++ 339 65 ++ 603 182 ++ 942 381 ++ 1356 664 ++ 1845 1021 ++ 2409 1450 ++ 3046 1953 ++ 3755 2530 ++ 4535 3182 ++ 5384 3907 ++ 6300 4700 ++ 7278 5563 ++ 8315 6491 ++ 9405 7481 ++ 10541 8529 ++ 11717 9629 ++ 12924 10773 ++ 14151 11956 ++ 15385 13167 ++ 16615 14396 ++ 17825 15630 ++ 18997 16857 ++ 20114 18060 ++ 21156 19222 ++ 22102 20325 ++ 22929 21349 ++ 23613 22273 ++ 24132 23073 ++ 24461 23726 ++ 24575 24208 ++ 24453 24495 ++ 24073 24564 ++ 23416 24392 ++ 22467 23959 ++ 21213 23245 ++ 19649 22236 ++ 17773 20922 ++ 15590 19296 ++ 13116 17360 ++ 10371 15119 ++ 7386 12591 ++ 4201 9797 ++ 867 6771 ++ -2559 3554 ++ -6008 199 ++ -9405 -3235 ++-12667 -6678 ++-15707 -10053 ++-18435 -13277 ++-20762 -16261 ++-22602 -18916 ++-23875 -21153 ++-24511 -22887 ++-24457 -24040 ++-23675 -24546 ++-22151 -24352 ++-19895 -23428 ++-16946 -21762 ++-13370 -19370 ++ -9265 -16296 ++ -4757 -12613 ++ 0 -8423 ++ 4831 -3858 ++ 9544 923 ++ 13934 5743 ++ 17799 10406 ++ 20942 14708 ++ 23189 18447 ++ 24395 21430 ++ 24457 23488 ++ 23323 24483 ++ 21001 24321 ++ 17563 22963 ++ 13148 20426 ++ 7959 16795 ++ 2259 12223 ++ -3643 6922 ++ -9405 1166 ++-14670 -4731 ++-19092 -10421 ++-22359 -15550 ++-24213 -19777 ++-24481 -22797 ++-23087 -24368 ++-20071 -24334 ++-15590 -22639 ++ -9924 -19343 ++ -3457 -14629 ++ 3345 -8793 ++ 9959 -2236 ++ 15851 4563 ++ 20517 11078 ++ 23528 16779 ++ 24575 21171 ++ 23506 23846 ++ 20349 24522 ++ 15327 23076 ++ 8845 19572 ++ 1469 14264 ++ -6117 7589 ++-13180 135 ++-18997 -7403 ++-22942 -14289 ++-24553 -19814 ++-23592 -23377 ++-20092 -24551 ++-14366 -23145 ++ -6989 -19239 ++ 1244 -13192 ++ 9405 -5620 ++ 16532 2656 ++ 21744 10697 ++ 24357 17548 ++ 23978 22356 ++ 20579 24483 ++ 14518 23593 ++ 6518 19723 ++ -2409 13293 ++-11083 5078 ++-18310 -3876 ++-23048 -12378 ++-24568 -19252 ++-22573 -23500 ++-17270 -24458 ++ -9370 -21908 ++ 0 -16140 ++ 9439 -7935 ++ 17484 1526 ++ 22832 10824 ++ 24568 18508 ++ 22327 23330 ++ 16392 24452 ++ 7673 21608 ++ -2409 15181 ++-12146 6168 ++-19828 -3955 ++-24050 -13466 ++-23978 -20689 ++-19535 -24292 ++-11451 -23552 ++ -1168 -18512 ++ 9405 -10015 ++ 18234 416 ++ 23560 10836 ++ 24257 19234 ++ 20092 23929 ++ 11817 23916 ++ 1055 19105 ++ -9993 10379 ++-18997 -540 ++-23986 -11413 ++-23802 -19939 ++-18385 -24246 ++ -8845 -23318 ++ 2746 -17260 ++ 13778 -7325 ++ 21691 4319 ++ 24575 15045 ++ 21656 22357 ++ 13528 24482 ++ 2071 20823 ++ -9959 12152 ++-19581 484 ++-24331 -11367 ++-22915 -20460 ++-15590 -24459 ++ -4164 -22257 ++ 8421 -14315 ++ 18828 -2603 ++ 24213 9857 ++ 23022 19756 ++ 15474 24383 ++ 3569 22388 ++ -9405 14211 ++-19761 2031 ++-24471 -10785 ++-22069 -20591 ++-13148 -24512 ++ -264 -21311 ++ 12763 -11818 ++ 21968 1241 ++ 24457 13990 ++ 19351 22545 ++ 8137 24211 ++ -5715 18362 ++-17799 6720 ++-24167 -7108 ++-22646 -18722 ++-13622 -24326 ++ 0 -21995 ++ 13685 -12382 ++ 22762 1409 ++ 24035 14788 ++ 16946 23188 ++ 3867 23644 ++-10643 15884 ++-21401 2514 ++-24457 -11806 ++-18584 -21960 ++ -5825 -24220 ++ 9160 -17649 ++ 20762 -4546 ++ 24527 10303 ++ 18901 21343 ++ 5935 24337 ++ -9405 18028 ++-21098 4727 ++-24442 -10470 ++-17979 -21608 ++ -4201 -24206 ++ 11351 -17110 ++ 22280 -3064 ++ 23970 12287 ++ 15590 22636 ++ 565 23615 ++-14760 14693 ++-23773 -479 ++-22467 -15504 ++-11284 -23907 ++ 4942 -21954 ++ 19021 -10373 ++ 24575 5837 ++ 18973 19502 ++ 4646 24445 ++-11883 18316 ++-22929 3786 ++-23226 -12541 ++-12505 -23090 ++ 4239 -22841 ++ 18997 -11784 ++ 24567 4932 ++ 18107 19331 ++ 2671 24403 ++-14151 17558 ++-23919 2036 ++-21602 -14549 ++ -8244 -23897 ++ 9405 -21206 ++ 22232 -7710 ++ 23473 9785 ++ 12342 22272 ++ -5384 23186 ++-20286 11920 ++-24287 -5693 ++-15090 -20319 ++ 2409 -24060 ++ 18633 -14771 ++ 24538 2613 ++ 16698 18608 ++ -603 24329 ++-17616 16471 ++-24575 -682 ++-17351 -17495 ++ 0 -24355 ++ 17404 -17211 ++ 24575 -65 ++ 17136 17163 ++ -603 24334 ++-18031 17094 ++-24538 -374 ++-16023 -17660 ++ 2409 -24287 ++ 19397 -16108 ++ 24287 1992 ++ 13872 18902 ++ -5384 24066 ++-21251 14131 ++-23473 -4761 ++-10473 -20664 ++ 9405 -23351 ++ 23151 -10967 ++ 21602 8573 ++ 5642 22543 ++-14151 21682 ++-24430 6431 ++-18107 -13147 ++ 641 -23920 ++ 18997 -18514 ++ 24207 -475 ++ 12505 17922 ++ -8030 23970 ++-22929 13357 ++-21511 -6625 ++ -4646 -21972 ++ 15619 -21758 ++ 24575 -6009 ++ 15561 14083 ++ -4942 24019 ++-21831 16485 ++-22467 -3138 ++ -6227 -20474 ++ 14760 -22641 ++ 24569 -7904 ++ 15590 12791 ++ -5421 23839 ++-22280 16760 ++-21797 -3160 ++ -4201 -20666 ++ 16754 -22169 ++ 24442 -6381 ++ 12602 14430 ++ -9405 23865 ++-23848 14348 ++-18901 -6644 ++ 1545 -22308 ++ 20762 -19937 ++ 22804 -1339 ++ 5825 18365 ++-16080 22954 ++-24457 8529 ++-12080 -13009 ++ 10643 -23650 ++ 24269 -14353 ++ 16946 7119 ++ -5127 22521 ++-22762 18602 ++-20413 -1370 ++ 0 -20152 ++ 20454 -21342 ++ 22646 -3797 ++ 4461 17096 ++-17799 22804 ++-23902 8148 ++ -8137 -13817 ++ 15149 -23296 ++ 24457 -11618 ++ 11016 10660 ++-12763 23135 ++-24574 14243 ++-13148 -7861 ++ 10813 -22608 ++ 24471 -16124 ++ 14609 5565 ++ -9405 21949 ++-24315 17379 ++-15474 -3849 ++ 8598 -21336 ++ 24213 -18120 ++ 15793 2745 ++ -8421 20885 ++-24220 18429 ++-15590 -2263 ++ 8880 -20663 ++ 24331 -18359 ++ 14851 2398 ++ -9959 20685 ++-24488 17917 ++-13528 -3137 ++ 11618 -20918 ++ 24575 -17075 ++ 11551 4460 ++-13778 21286 ++-24421 15770 ++ -8845 -6328 ++ 16307 -21661 ++ 23802 -13916 ++ 5348 8671 ++-18997 21868 ++-22452 11421 ++ -1055 -11371 ++ 21548 -21685 ++ 20092 -8212 ++ -3941 14242 ++-23560 20853 ++-16476 4267 ++ 9405 -17009 ++ 24547 -19106 ++ 11451 343 ++-14911 19309 ++-23978 16208 ++ -5053 -5409 ++ 19828 -20699 ++ 21364 -12016 ++ -2409 10553 ++-23347 20700 ++-16392 6559 ++ 10268 -15211 ++ 24568 -18879 ++ 9090 -118 ++-17484 18664 ++-22690 14969 ++ 0 -6714 ++ 22719 -20134 ++ 17270 -9014 ++ -9717 13022 ++-24568 18943 ++ -8527 1506 ++ 18310 -17662 ++ 21934 -14749 ++ -2409 6538 ++-23695 19463 ++-14518 7789 ++ 13433 -13633 ++ 23978 -17566 ++ 3270 935 ++-21744 18075 ++-18184 11812 ++ 9405 -9654 ++ 24544 -18394 ++ 6989 -3082 ++-19939 16117 ++-20092 13945 ++ 6881 -6613 ++ 24553 -18196 ++ 8809 -5437 ++-18997 14458 ++-20742 14731 ++ 6117 -4859 ++ 24531 -17657 ++ 8845 -6307 ++-19210 13526 ++-20349 14588 ++ 7170 -4444 ++ 24575 -17109 ++ 7098 -5874 ++-20517 13412 ++-18780 13691 ++ 9959 -5272 ++ 24347 -16558 ++ 3457 -4241 ++-22482 13949 ++-15590 11979 ++ 14181 -7142 ++ 23087 -15723 ++ -2146 -1459 ++-24213 14726 ++-10200 9228 ++ 19092 -9692 ++ 19717 -14108 ++ -9405 2343 ++-24304 15085 ++ -2259 5221 ++ 23251 -12286 ++ 13148 -11127 ++-17190 6746 ++-21001 14161 ++ 7745 2 ++ 24457 -13938 ++ 2971 -6372 ++-23189 10842 ++-12860 11094 ++ 17799 -5795 ++ 20243 -13421 ++ -9544 -30 ++-24096 13184 ++ 0 5498 ++ 24110 -10713 ++ 9265 -9718 ++-20620 6673 ++-16946 12155 ++ 14427 -1883 ++ 22151 -12653 ++ -6591 -2861 ++-24457 11378 ++ -1770 6908 ++ 23875 -8726 ++ 9648 -9817 ++-20762 5209 ++-16251 11385 ++ 15707 -1358 ++ 21059 -11610 ++ -9405 -2353 ++-23830 10656 ++ 2559 5560 ++ 24560 -8789 ++ 4201 -8028 ++-23439 6314 ++-10371 9643 ++ 20783 -3542 ++ 15590 -10404 ++-16973 742 ++-19649 10386 ++ 12407 1870 ++ 22467 -9720 ++ -7458 -4144 ++-24073 8562 ++ 2446 5991 ++ 24575 -7072 ++ 2371 -7375 ++-24132 5398 ++ -6808 8306 ++ 22929 -3667 ++ 10745 -8824 ++-21156 1980 ++-14120 8987 ++ 18997 -408 ++ 16918 -8863 ++-16615 -1001 ++-19163 8521 ++ 14151 2220 ++ 20902 -8027 ++-11717 -3241 ++-22200 7441 ++ 9405 4071 ++ 23126 -6811 ++ -7278 -4722 ++-23754 6177 ++ 5384 5213 ++ 24153 -5571 ++ -3755 -5566 ++-24386 5013 ++ 2409 5801 ++ 24506 -4521 ++ -1356 -5939 ++-24557 4104 ++ 603 5999 ++ 24573 -3765 ++ -151 -5994 ++-24575 3508 ++ 0 5937 ++ 24575 -3331 ++ -151 -5835 ++-24573 3232 ++ 603 5694 ++ 24557 -3205 ++ -1356 -5517 ++-24506 3244 ++ 2409 5303 ++ 24386 -3343 ++ -3755 -5049 ++-24153 3494 ++ 5384 4752 ++ 23754 -3685 ++ -7278 -4407 ++-23126 3906 ++ 9405 4007 ++ 22200 -4143 ++-11717 -3547 ++-20902 4380 ++ 14151 3025 ++ 19163 -4598 ++-16615 -2434 ++-16918 4778 ++ 18997 1780 ++ 14120 -4898 ++-21156 -1066 ++-10745 4934 ++ 22929 304 ++ 6808 -4862 ++-24132 489 ++ -2371 4664 ++ 24575 -1288 ++ -2446 -4320 ++-24073 2060 ++ 7458 3820 ++ 22467 -2767 ++-12407 -3162 ++-19649 3365 ++ 16973 2357 ++ 15590 -3808 ++-20783 -1429 ++-10371 4050 ++ 23439 419 ++ 4201 -4055 ++-24560 616 ++ 2559 3795 ++ 23830 -1607 ++ -9405 -3266 ++-21059 2473 ++ 15707 2486 ++ 16251 -3130 ++-20762 -1499 ++ -9648 3505 ++ 23875 386 ++ 1770 -3539 ++-24457 754 ++ 6591 3205 ++ 22151 -1798 ++-14427 -2518 ++-16946 2618 ++ 20620 1540 ++ 9265 -3101 ++-24110 -381 ++ 0 3162 ++ 24096 -809 ++ -9544 -2775 ++-20243 1859 ++ 17799 1978 ++ 12860 -2598 ++-23189 -879 ++ -2971 2893 ++ 24457 -344 ++ -7745 -2674 ++-21001 1478 ++ 17190 1966 ++ 13148 -2304 ++-23251 -890 ++ -2259 2647 ++ 24304 -341 ++ -9405 -2421 ++-19717 1467 ++ 19092 1662 ++ 10200 -2229 ++-24213 -535 ++ 2146 2434 ++ 23087 -692 ++-14181 -2022 ++-15590 1706 ++ 22482 1090 ++ 3457 -2230 ++-24347 115 ++ 9959 2111 ++ 18780 -1251 ++-20517 -1374 ++ -7098 1975 ++ 24575 238 ++ -7170 -2057 ++-20349 938 ++ 19210 1464 ++ 8845 -1763 ++-24531 -392 ++ 6117 1949 ++ 20742 -783 ++-18997 -1425 ++ -8809 1630 ++ 24553 385 ++ -6881 -1825 ++-20092 770 ++ 19939 1291 ++ 6989 -1572 ++-24544 -244 ++ 9405 1688 ++ 18184 -869 ++-21744 -1069 ++ -3270 1559 ++ 23978 -7 ++-13433 -1511 ++-14518 1041 ++ 23695 753 ++ -2409 -1536 ++-21934 344 ++ 18310 1251 ++ 8527 -1225 ++-24568 -337 ++ 9717 1436 ++ 17270 -719 ++-22719 -869 ++ 0 1342 ++ 22690 -157 ++-17484 -1188 ++ -9090 1051 ++ 24568 353 ++-10268 -1293 ++-16392 658 ++ 23347 745 ++ -2409 -1224 ++-21364 244 ++ 19828 996 ++ 5053 -1036 ++-23978 -132 ++ 14911 1114 ++ 11451 -783 ++-24547 -437 ++ 9405 1124 ++ 16476 -513 ++-23560 -661 ++ 3941 1058 ++ 20092 -257 ++-21548 -807 ++ -1055 945 ++ 22452 -37 ++-18997 -887 ++ -5348 815 ++ 23802 142 ++-16307 -917 ++ -8845 682 ++ 24421 276 ++-13778 -913 ++-11551 563 ++ 24575 371 ++-11618 -888 ++-13528 463 ++ 24488 431 ++ -9959 -854 ++-14851 386 ++ 24331 462 ++ -8880 -815 ++-15590 333 ++ 24220 471 ++ -8421 -779 ++-15793 302 ++ 24213 460 ++ -8598 -746 ++-15474 292 ++ 24315 433 ++ -9405 -717 ++-14609 300 ++ 24471 391 ++-10813 -689 ++-13148 324 ++ 24574 336 ++-12763 -660 ++-11016 359 ++ 24457 267 ++-15149 -627 ++ -8137 400 ++ 23902 184 ++-17799 -584 ++ -4461 444 ++ 22646 90 ++-20454 -527 ++ 0 483 ++ 20413 -15 ++-22762 -452 ++ 5127 511 ++ 16946 -124 ++-24269 -357 ++ 10643 517 ++ 12080 -232 ++-24457 -241 ++ 16080 495 ++ 5825 -328 ++-22804 -107 ++ 20762 440 ++ -1545 -400 ++-18901 35 ++ 23848 347 ++ -9405 -437 ++-12602 173 ++ 24442 220 ++-16754 -426 ++ -4201 290 ++ 21797 69 ++-22280 -362 ++ 5421 366 ++ 15590 -89 ++-24569 -247 ++ 14760 384 ++ 6227 -228 ++-22467 -95 ++ 21831 335 ++ -4942 -321 ++-15561 71 ++ 24575 222 ++-15619 -344 ++ -4646 214 ++ 21511 65 ++-22929 -288 ++ 8030 300 ++ 12505 -102 ++-24207 -162 ++ 18997 304 ++ -641 -232 ++-18107 4 ++ 24430 218 ++-14151 -286 ++ -5642 160 ++ 21602 68 ++-23151 -244 ++ 9405 253 ++ 10473 -97 ++-23473 -115 ++ 21251 247 ++ -5384 -216 ++-13872 49 ++ 24287 142 ++-19397 -238 ++ 2409 183 ++ 16023 -17 ++-24538 -153 ++ 18031 224 ++ -603 -158 ++-17136 0 ++ 24575 153 ++-17404 -209 ++ 0 142 ++ 17351 6 ++-24575 -144 ++ 17616 196 ++ -603 -133 ++-16698 -1 ++ 24538 131 ++-18633 -182 ++ 2409 132 ++ 15090 -11 ++-24287 -111 ++ 20286 169 ++ -5384 -134 ++-12342 30 ++ 23473 86 ++-22232 -152 ++ 9405 138 ++ 8244 -53 ++-21602 -56 ++ 23919 132 ++-14151 -138 ++ -2671 76 ++ 18107 21 ++-24567 -104 ++ 18997 134 ++ -4239 -98 ++-12505 16 ++ 23226 69 ++-22929 -119 ++ 11883 111 ++ 4646 -53 ++-18973 -28 ++ 24575 92 ++-19021 -113 ++ 4942 82 ++ 11284 -16 ++-22467 -54 ++ 23773 97 ++-14760 -97 ++ -565 56 ++ 15590 8 ++-23970 -65 ++ 22280 93 ++-11351 -82 ++ -4201 37 ++ 17979 21 ++-24442 -67 ++ 21098 85 ++ -9405 -69 ++ -5935 26 ++ 18901 24 ++-24527 -64 ++ 20762 77 ++ -9160 -61 ++ -5825 23 ++ 18584 21 ++-24457 -56 ++ 21401 69 ++-10643 -57 ++ -3867 25 ++ 16946 15 ++-24035 -47 ++ 22762 62 ++-13685 -55 ++ 0 29 ++ 13622 4 ++-22646 -35 ++ 24167 53 ++-17799 -52 ++ 5715 36 ++ 8137 -8 ++-19351 -21 ++ 24457 41 ++-21968 -49 ++ 12763 41 ++ 264 -21 ++-13148 -4 ++ 22069 27 ++-24471 -40 ++ 19761 42 ++ -9405 -31 ++ -3569 12 ++ 15474 9 ++-23022 -27 ++ 24213 36 ++-18828 -35 ++ 8421 25 ++ 4164 -9 ++-15590 -9 ++ 22915 23 ++-24331 -31 ++ 19581 31 ++ -9959 -23 ++ -2071 10 ++ 13528 5 ++-21656 -18 ++ 24575 26 ++-21691 -27 ++ 13778 22 ++ -2746 -12 ++ -8845 0 ++ 18385 11 ++-23802 -20 ++ 23986 23 ++-18997 -22 ++ 9993 15 ++ 1055 -7 ++-11817 -3 ++ 20092 11 ++-24257 -17 ++ 23560 19 ++-18234 -17 ++ 9405 12 ++ 1168 -5 ++-11451 -3 ++ 19535 10 ++-23978 -14 ++ 24050 16 ++-19828 -14 ++ 12146 11 ++ -2409 -5 ++ -7673 0 ++ 16392 6 ++-22327 -10 ++ 24568 12 ++-22832 -12 ++ 17484 11 ++ -9439 -7 ++ 0 3 ++ 9370 2 ++-17270 -5 ++ 22573 8 ++-24568 -9 ++ 23048 10 ++-18310 -8 ++ 11083 5 ++ -2409 -3 ++ -6518 -1 ++ 14518 3 ++-20579 -5 ++ 23978 7 ++-24357 -7 ++ 21744 7 ++-16532 -6 ++ 9405 3 ++ -1244 -1 ++ -6989 -1 ++ 14366 3 ++-20092 -4 ++ 23592 5 ++-24553 -5 ++ 22942 5 ++-18997 -4 ++ 13180 3 ++ -6117 -2 ++ -1469 1 ++ 8845 2 ++-15327 -2 ++ 20349 3 ++-23506 -4 ++ 24575 3 ++-23528 -4 ++ 20517 3 ++-15851 -2 ++ 9959 1 ++ -3345 0 ++ -3457 0 ++ 9924 1 ++-15590 -2 ++ 20071 2 ++-23087 -2 ++ 24481 3 ++-24213 -2 ++ 22359 2 ++-19092 -1 ++ 14670 1 ++ -9405 0 ++ 3643 0 ++ 2259 0 ++ -7959 -1 ++ 13148 1 ++-17563 -1 ++ 21001 1 ++-23323 -1 ++ 24457 1 ++-24395 -1 ++ 23189 1 ++-20942 -1 ++ 17799 1 ++-13934 0 ++ 9544 0 ++ -4831 0 ++ 0 0 ++ 4757 1 ++ -9265 0 ++ 13370 0 ++-16946 -1 ++ 19895 0 ++-22151 -1 ++ 23675 0 ++-24457 -1 ++ 24511 0 ++-23875 0 ++ 22602 0 ++-20762 0 ++ 18435 0 ++-15707 0 ++ 12667 0 ++ -9405 0 ++ 6008 0 ++ -2559 0 ++ -867 0 ++ 4201 0 ++ -7386 0 ++ 10371 0 ++-13116 0 ++ 15590 0 ++-17773 0 ++ 19649 0 ++-21213 0 ++ 22467 0 ++-23416 0 ++ 24073 0 ++-24453 0 ++ 24575 0 ++-24461 0 ++ 24132 0 ++-23613 0 ++ 22929 0 ++-22102 0 ++ 21156 0 ++-20114 0 ++ 18997 0 ++-17825 0 ++ 16615 0 ++-15385 0 ++ 14151 0 ++-12924 0 ++ 11717 0 ++-10541 0 ++ 9405 0 ++ -8315 0 ++ 7278 0 ++ -6300 0 ++ 5384 0 ++ -4535 0 ++ 3755 0 ++ -3046 0 ++ 2409 0 ++ -1845 0 ++ 1356 0 ++ -942 0 ++ 603 0 ++ -339 0 ++ 151 0 ++ -38 0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/indeo4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/indeo4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/indeo4 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/indeo4 2012-05-14 14:08:55.676366992 +0200 +@@ -0,0 +1,100 @@ ++0, 0, 86400, 0x98f5e422 ++0, 6000, 86400, 0x1864cb06 ++0, 12000, 86400, 0xb09532ef ++0, 18000, 86400, 0x3cd3dcdc ++0, 24000, 86400, 0xe738847f ++0, 30000, 86400, 0xc9b13afb ++0, 36000, 86400, 0x5005d035 ++0, 42000, 86400, 0x22f63e17 ++0, 48000, 86400, 0x93391f02 ++0, 54000, 86400, 0x264830fd ++0, 60000, 86400, 0x8fff9f5f ++0, 66000, 86400, 0x524997fe ++0, 72000, 86400, 0x54e330f9 ++0, 78000, 86400, 0x1d766a22 ++0, 84000, 86400, 0x683a70ac ++0, 90000, 86400, 0x553b7b3d ++0, 96000, 86400, 0x822c79bc ++0, 102000, 86400, 0xe1087a1c ++0, 108000, 86400, 0xff397595 ++0, 114000, 86400, 0x1b6b7717 ++0, 120000, 86400, 0x6c5275c1 ++0, 126000, 86400, 0x4e6a7189 ++0, 132000, 86400, 0x285c6eba ++0, 138000, 86400, 0xce647227 ++0, 144000, 86400, 0xa0d07b1c ++0, 150000, 86400, 0x5b567861 ++0, 156000, 86400, 0x105873ec ++0, 162000, 86400, 0x59267fa0 ++0, 168000, 86400, 0xaeac839f ++0, 174000, 86400, 0x2faf7402 ++0, 180000, 86400, 0xc8547a30 ++0, 186000, 86400, 0x3d357d49 ++0, 192000, 86400, 0x75db6d6c ++0, 198000, 86400, 0x9fbf68e9 ++0, 204000, 86400, 0x56a64d26 ++0, 210000, 86400, 0xce9e1f43 ++0, 216000, 86400, 0xa4d7fddc ++0, 222000, 86400, 0x3e20d77c ++0, 228000, 86400, 0x4680661d ++0, 234000, 86400, 0xf1b20af3 ++0, 240000, 86400, 0xb79d8045 ++0, 246000, 86400, 0x9479fc8a ++0, 252000, 86400, 0x232965c3 ++0, 258000, 86400, 0xd18bca17 ++0, 264000, 86400, 0xb9064249 ++0, 270000, 86400, 0xcc48ab34 ++0, 276000, 86400, 0xe25018cd ++0, 282000, 86400, 0x8da489ee ++0, 288000, 86400, 0x90de0fc1 ++0, 294000, 86400, 0x2428dcee ++0, 300000, 86400, 0x4316e1ae ++0, 306000, 86400, 0x2b25e54c ++0, 312000, 86400, 0x736ce020 ++0, 318000, 86400, 0x9a6be09a ++0, 324000, 86400, 0x23bddbcd ++0, 330000, 86400, 0x9368e465 ++0, 336000, 86400, 0x1ae9bb87 ++0, 342000, 86400, 0x4e591f32 ++0, 348000, 86400, 0xba1bf9dc ++0, 354000, 86400, 0x07f0aa60 ++0, 360000, 86400, 0xf5a2cfa2 ++0, 366000, 86400, 0xcba5fc18 ++0, 372000, 86400, 0x858c0cfe ++0, 378000, 86400, 0xac73ecd4 ++0, 384000, 86400, 0xf41bf03c ++0, 390000, 86400, 0x928ed146 ++0, 396000, 86400, 0x9ff5990a ++0, 402000, 86400, 0xc2fabc3d ++0, 408000, 86400, 0x94af87a3 ++0, 414000, 86400, 0x9bae514c ++0, 420000, 86400, 0xe0da267a ++0, 426000, 86400, 0x1d40f55c ++0, 432000, 86400, 0xe6173b68 ++0, 438000, 86400, 0x1445490d ++0, 444000, 86400, 0x8d8753c1 ++0, 450000, 86400, 0xe5a7779d ++0, 456000, 86400, 0x3cfc66ef ++0, 462000, 86400, 0xa5d45608 ++0, 468000, 86400, 0x62f17be1 ++0, 474000, 86400, 0xa64c84d3 ++0, 480000, 86400, 0xf98162f0 ++0, 486000, 86400, 0x0db77d9f ++0, 492000, 86400, 0x0f0cbac9 ++0, 498000, 86400, 0xb9934e97 ++0, 504000, 86400, 0x7f8fa248 ++0, 510000, 86400, 0xdfd96768 ++0, 516000, 86400, 0x81b07919 ++0, 522000, 86400, 0x66c11e9f ++0, 528000, 86400, 0xd86eb114 ++0, 534000, 86400, 0x67f20c1f ++0, 540000, 86400, 0x66915de5 ++0, 546000, 86400, 0x2b8aa76f ++0, 552000, 86400, 0x85b5a3d2 ++0, 558000, 86400, 0x80d29ed6 ++0, 564000, 86400, 0x4d508e2c ++0, 570000, 86400, 0x0d407374 ++0, 576000, 86400, 0xd4068016 ++0, 582000, 86400, 0x6ffab98f ++0, 588000, 86400, 0x2360903d ++0, 594000, 86400, 0x470e04a0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/interplay-mve-16bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/interplay-mve-16bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/interplay-mve-16bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/interplay-mve-16bit 2012-05-14 14:08:55.677367012 +0200 +@@ -1,103 +1,103 @@ +-1, 0, 5788, 0x916d2db8 + 0, 0, 614400, 0x00000000 ++1, 0, 5788, 0x916d2db8 + 1, 2953, 5888, 0xc65cb069 + 0, 3002, 614400, 0x00000000 + 1, 5957, 5888, 0xd8ec1acc +-0, 6005, 614400, 0xa17ea4ec ++0, 6005, 614400, 0x3c4ce011 + 1, 8961, 5888, 0xb22af0d6 +-0, 9007, 614400, 0x4fd207fb ++0, 9007, 614400, 0x16e83922 + 1, 11965, 5888, 0x86bb50d9 +-0, 12010, 614400, 0xd7a510fb ++0, 12010, 614400, 0x657a3d4d + 1, 14969, 5888, 0x7674d923 +-0, 15012, 614400, 0xe901e2f4 ++0, 15012, 614400, 0x933a08b0 + 1, 17973, 5888, 0xb97c5500 +-0, 18014, 614400, 0x4ac5d3c4 ++0, 18014, 614400, 0xfcd5f76e + 1, 20978, 5888, 0xecea1249 +-0, 21017, 614400, 0x32e3e99c ++0, 21017, 614400, 0xd0990cf8 + 1, 23982, 5888, 0x0f4fea81 +-0, 24019, 614400, 0x7a2ff20c ++0, 24019, 614400, 0x02131686 + 1, 26986, 5888, 0x997914d8 +-0, 27022, 614400, 0x59941193 ++0, 27022, 614400, 0x4cf53656 + 1, 29990, 5888, 0xd012f03a +-0, 30024, 614400, 0x92773a2b ++0, 30024, 614400, 0x7d1960c0 + 1, 32994, 5888, 0x03fd5248 +-0, 33026, 614400, 0x4cd14313 ++0, 33026, 614400, 0x5d9f696f + 1, 35998, 5888, 0x3041a288 +-0, 36029, 614400, 0x2a093fa3 ++0, 36029, 614400, 0x54e06663 + 1, 39002, 5888, 0xe6105de1 +-0, 39031, 614400, 0xf68b8463 ++0, 39031, 614400, 0x4c1eade1 + 1, 42006, 5888, 0xaa38c7bd +-0, 42034, 614400, 0xa9e1969b ++0, 42034, 614400, 0x4bd3bfff + 1, 45010, 5888, 0xbfff702c +-0, 45036, 614400, 0x461996bb ++0, 45036, 614400, 0xab86c041 + 1, 48014, 5888, 0xbe4319a3 +-0, 48038, 614400, 0xae58d053 ++0, 48038, 614400, 0xbb2bfbf4 + 1, 51018, 5888, 0x2e89d262 +-0, 51041, 614400, 0x7693015a ++0, 51041, 614400, 0x43822e15 + 1, 54022, 5888, 0x10992b9c +-0, 54043, 614400, 0x0b3507fa ++0, 54043, 614400, 0x835e352c + 1, 57027, 5888, 0x972904bf +-0, 57046, 614400, 0xff5c2492 ++0, 57046, 614400, 0x72cc538f + 1, 60031, 5888, 0x0093501c +-0, 60048, 614400, 0x636e3e32 ++0, 60048, 614400, 0x20bb6e30 + 1, 63035, 5888, 0x8994ad0e +-0, 63050, 614400, 0x1acd6d0a ++0, 63050, 614400, 0xfb079f52 + 1, 66039, 5888, 0x9db37d21 +-0, 66053, 614400, 0x67039232 ++0, 66053, 614400, 0x759bc4d6 + 1, 69043, 5888, 0xa8c7300f +-0, 69055, 614400, 0x8ab9c75a ++0, 69055, 614400, 0xd116fc3b + 1, 72047, 5888, 0x1b7073b5 +-0, 72058, 614400, 0xe824bbe2 ++0, 72058, 614400, 0x5c06efd2 + 1, 75051, 5888, 0x56ad7f7b +-0, 75060, 614400, 0x5133e9ea ++0, 75060, 614400, 0x61641ecd + 1, 78055, 5888, 0x9706a8fb +-0, 78062, 614400, 0xcecf1249 ++0, 78062, 614400, 0x6c8d48a0 + 1, 81059, 5888, 0x16c9420e +-0, 81065, 614400, 0xe6d928c1 ++0, 81065, 614400, 0x64725eed + 1, 84063, 5888, 0x3e11be0a +-0, 84067, 614400, 0x8da46ff1 ++0, 84067, 614400, 0x88f9a8ca + 1, 87067, 5888, 0x3e534a32 +-0, 87070, 614400, 0x1c778319 ++0, 87070, 614400, 0xcf1cbcd9 + 1, 90071, 5788, 0x0ffae5f4 +-0, 90072, 614400, 0x35a19451 ++0, 90072, 614400, 0x75a3ce24 + 1, 93024, 5888, 0xc2018f82 +-0, 93074, 614400, 0x5145d1b9 ++0, 93074, 614400, 0x3bf80ce7 + 1, 96029, 5888, 0x2a11f529 +-0, 96077, 614400, 0x146ee231 ++0, 96077, 614400, 0xd4011d7c + 1, 99033, 5888, 0xec282167 +-0, 99079, 614400, 0xd9b33380 ++0, 99079, 614400, 0xd569716b + 1, 102037, 5888, 0xd61b5a05 +-0, 102082, 614400, 0x8b112ef8 ++0, 102082, 614400, 0xfd626b6b + 1, 105041, 5888, 0x61de2741 +-0, 105084, 614400, 0xb9e79ab0 ++0, 105084, 614400, 0xc856dbaf + 1, 108045, 5888, 0x17aaff8c +-0, 108086, 614400, 0x62d3a498 ++0, 108086, 614400, 0x0e56e68e + 1, 111049, 5888, 0xd40cd7a6 +-0, 111089, 614400, 0xaeaaaa58 ++0, 111089, 614400, 0x5b29ecc9 + 1, 114053, 5888, 0x840840d4 +-0, 114091, 614400, 0x8922c440 ++0, 114091, 614400, 0xe83c0804 + 1, 117057, 5888, 0x7c97ddcf +-0, 117094, 614400, 0xd62ef758 ++0, 117094, 614400, 0xebdd3d61 + 1, 120061, 5888, 0xed9150f7 +-0, 120096, 614400, 0x2a53149f ++0, 120096, 614400, 0x7f4c5b56 + 1, 123065, 5888, 0xbccf973e +-0, 123098, 614400, 0x13da47df ++0, 123098, 614400, 0xb4019155 + 1, 126069, 5888, 0x74bda5ea +-0, 126101, 614400, 0x27c05c3f ++0, 126101, 614400, 0xffdda515 + 1, 129073, 5888, 0xd083892a +-0, 129103, 614400, 0x41ff7ca7 ++0, 129103, 614400, 0x5271c695 + 1, 132078, 5888, 0x16e444b2 +-0, 132106, 614400, 0x6b0e8a07 ++0, 132106, 614400, 0x8526d3c1 + 1, 135082, 5888, 0x68a9cedb +-0, 135108, 614400, 0xa200ad9f ++0, 135108, 614400, 0x5accf7a6 + 1, 138086, 5888, 0x80849f36 +-0, 138110, 614400, 0x9da7cc77 ++0, 138110, 614400, 0x959017aa + 1, 141090, 5888, 0x63cb7df9 +-0, 141113, 614400, 0x2f5703be ++0, 141113, 614400, 0x22f450f6 + 1, 144094, 5888, 0xf90f754d +-0, 144115, 614400, 0x91c720f6 ++0, 144115, 614400, 0x2e3d6f37 + 1, 147098, 5888, 0x9c2c867d +-0, 147118, 614400, 0x927a882e ++0, 147118, 614400, 0x0db9d89f + 1, 150102, 5888, 0x337994a4 + 1, 153106, 5888, 0xf354a28d + 1, 156110, 5888, 0x70933738 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/interplay-mve-8bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/interplay-mve-8bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/interplay-mve-8bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/interplay-mve-8bit 2012-05-14 14:08:55.678367032 +0200 +@@ -1,223 +1,223 @@ ++0, 0, 414720, 0x2580d574 + 1, 0, 5848, 0xea04292b +-0, 0, 414720, 0xa5cd50ca + 1, 5967, 5888, 0x0e59e942 +-0, 6006, 414720, 0x3facd321 ++0, 6006, 414720, 0x97f55cd3 + 1, 11976, 5888, 0x56d480f6 +-0, 12011, 414720, 0x849e6d4b ++0, 12011, 414720, 0x9408fb63 + 1, 17984, 5888, 0xcb560b22 +-0, 18017, 414720, 0xe649363f ++0, 18017, 414720, 0x7e53c155 + 1, 23992, 5888, 0xca26865b +-0, 24022, 414720, 0x5bbd7b14 ++0, 24022, 414720, 0xd8570262 + 1, 30000, 5888, 0xa434392f +-0, 30028, 414720, 0xe246ab51 ++0, 30028, 414720, 0x9dc72ed5 + 1, 36008, 5888, 0xa0615fe4 +-0, 36033, 414720, 0x5721b22e ++0, 36033, 414720, 0xf7d33211 + 1, 42016, 5888, 0x85b241cd +-0, 42039, 414720, 0xe391e107 ++0, 42039, 414720, 0x95935e3b + 1, 48024, 5888, 0x2c417a43 +-0, 48044, 414720, 0x04d851ff ++0, 48044, 414720, 0x62b1cdc5 + 1, 54033, 5888, 0x2d5ed665 +-0, 54050, 414720, 0x8d80d580 ++0, 54050, 414720, 0x971f500a + 1, 60041, 5888, 0x37267a2d +-0, 60055, 414720, 0x5a24b0bc ++0, 60055, 414720, 0x05f82b6c + 1, 66049, 5888, 0x1f803c67 +-0, 66061, 414720, 0x06cd6960 ++0, 66061, 414720, 0x7713e3cb + 1, 72057, 5888, 0xfb7940ef +-0, 72066, 414720, 0xf5ca48b4 ++0, 72066, 414720, 0x3170c2f0 + 1, 78065, 5888, 0x1a5371e8 +-0, 78072, 414720, 0x24700f94 ++0, 78072, 414720, 0x8d818956 + 1, 84073, 5888, 0x37e29b21 +-0, 84077, 414720, 0xb0bfe451 ++0, 84077, 414720, 0x16775d71 + 1, 90082, 5848, 0x70065769 +-0, 90083, 414720, 0x00e9f3d1 ++0, 90083, 414720, 0x63016ce1 + 1, 96049, 5888, 0xaf624f3d +-0, 96088, 414720, 0x0efbffd1 ++0, 96088, 414720, 0x2f94792c + 1, 102057, 5888, 0x8f5e5b57 +-0, 102094, 414720, 0x2ecdfc8d ++0, 102094, 414720, 0x37f67725 + 1, 108065, 5888, 0x93545968 +-0, 108099, 414720, 0x94b531fc ++0, 108099, 414720, 0xeb95adb1 + 1, 114073, 5888, 0x915f268f +-0, 114105, 414720, 0x2c2579f8 ++0, 114105, 414720, 0xbf32f6df + 1, 120082, 5888, 0x9cd48ac4 +-0, 120110, 414720, 0x6c7ecfb8 ++0, 120110, 414720, 0x242f4d09 + 1, 126090, 5888, 0x812c8e13 +-0, 126116, 414720, 0x08982527 ++0, 126116, 414720, 0x28a2a3b9 + 1, 132098, 5888, 0xe794a2a7 +-0, 132121, 414720, 0x5c0161b3 ++0, 132121, 414720, 0x895de0a6 + 1, 138106, 5888, 0x4a056e4b +-0, 138127, 414720, 0x453ce413 ++0, 138127, 414720, 0xd3b46447 + 1, 144114, 5888, 0xa3589992 +-0, 144132, 414720, 0x634e36b2 ++0, 144132, 414720, 0x3bbfb7d1 + 1, 150122, 5888, 0x19ea7ec5 +-0, 150138, 414720, 0x401a683a ++0, 150138, 414720, 0x0a5ee9ad + 1, 156131, 5888, 0x422d5097 +-0, 156144, 414720, 0x3c5f442e ++0, 156144, 414720, 0xaabac502 + 1, 162139, 5888, 0xc9fd963f +-0, 162149, 414720, 0x075ef787 ++0, 162149, 414720, 0x0951779d + 1, 168147, 5888, 0xc556a5ea +-0, 168155, 414720, 0x8501a04f ++0, 168155, 414720, 0x150e2073 + 1, 174155, 5888, 0x51557e0f +-0, 174160, 414720, 0x3620093b ++0, 174160, 414720, 0xb86d87ae + 1, 180163, 5848, 0x4903ad21 +-0, 180166, 414720, 0xa42d9480 ++0, 180166, 414720, 0x135411da + 1, 186131, 5888, 0xb1c85e85 +-0, 186171, 414720, 0x09b150b4 ++0, 186171, 414720, 0x9c8fcda5 + 1, 192139, 5888, 0x68963d65 +-0, 192177, 414720, 0xcad407f0 ++0, 192177, 414720, 0xb7ba838e + 1, 198147, 5888, 0x62a3124e +-0, 198182, 414720, 0x69e5eecd ++0, 198182, 414720, 0x7ef869e1 + 1, 204155, 5888, 0x4ff1878f +-0, 204188, 414720, 0xb92ad2d9 ++0, 204188, 414720, 0xf9764d47 + 1, 210163, 5888, 0x8b09ac18 +-0, 210193, 414720, 0xc78eaf29 ++0, 210193, 414720, 0xe6c72872 + 1, 216171, 5888, 0x67d85338 +-0, 216199, 414720, 0x47c3fa91 ++0, 216199, 414720, 0xb95b73b8 + 1, 222180, 5888, 0x82eca0a6 +-0, 222204, 414720, 0x8847b7b8 ++0, 222204, 414720, 0xa19e3221 + 1, 228188, 5888, 0x81a17eb8 +-0, 228210, 414720, 0x864cab2f ++0, 228210, 414720, 0xc0be27cd + 1, 234196, 5888, 0x7108478c +-0, 234215, 414720, 0x78d653e2 ++0, 234215, 414720, 0xe97cd1a9 + 1, 240204, 5888, 0xbfc18b09 +-0, 240221, 414720, 0xda15cbd2 ++0, 240221, 414720, 0xb6524a34 + 1, 246212, 5888, 0xad93711f +-0, 246226, 414720, 0xdf9ce28a ++0, 246226, 414720, 0x61a1607b + 1, 252220, 5888, 0xf8d25e39 +-0, 252232, 414720, 0xe88c49ca ++0, 252232, 414720, 0x1dd9c606 + 1, 258229, 5888, 0x41edd04e +-0, 258237, 414720, 0xd6bcbc07 ++0, 258237, 414720, 0xe2e736fa + 1, 264237, 5888, 0xa6557ee2 +-0, 264243, 414720, 0xf0b4a7bf ++0, 264243, 414720, 0x25b922d9 + 1, 270245, 5848, 0xc14d5456 +-0, 270248, 414720, 0x74f9bfbf ++0, 270248, 414720, 0xbc023b36 + 1, 276212, 5888, 0x20a7821f +-0, 276254, 414720, 0x904ce103 ++0, 276254, 414720, 0x39bb5cdf + 1, 282220, 5888, 0x9f1a8f9d +-0, 282259, 414720, 0xca877e4a ++0, 282259, 414720, 0xf83bfc4f + 1, 288229, 5888, 0x2f3c6cc8 +-0, 288265, 414720, 0x588effd6 ++0, 288265, 414720, 0x3eae7f36 + 1, 294237, 5888, 0x757c894a +-0, 294270, 414720, 0x6dff8b71 ++0, 294270, 414720, 0x8cf80c32 + 1, 300245, 5888, 0x483e98bb +-0, 300276, 414720, 0xbeaae788 ++0, 300276, 414720, 0xbc576c03 + 1, 306253, 5888, 0x84289c75 +-0, 306282, 414720, 0x1a4d1242 ++0, 306282, 414720, 0x28b79ab1 + 1, 312261, 5888, 0xf79d5a91 +-0, 312287, 414720, 0x4ae98ea0 ++0, 312287, 414720, 0x15da1138 + 1, 318269, 5888, 0x395b5228 +-0, 318293, 414720, 0x41ed6d22 ++0, 318293, 414720, 0x345ff676 + 1, 324278, 5888, 0x9c937a14 +-0, 324298, 414720, 0x486e70aa ++0, 324298, 414720, 0x0108f909 + 1, 330286, 5888, 0x40c169cf +-0, 330304, 414720, 0xfddc103e ++0, 330304, 414720, 0x57459616 + 1, 336294, 5888, 0x3e7f99b0 +-0, 336309, 414720, 0x8620f03e ++0, 336309, 414720, 0x2f497782 + 1, 342302, 5888, 0xd4de993e +-0, 342315, 414720, 0x0e4ec273 ++0, 342315, 414720, 0xb72b4f79 + 1, 348310, 5888, 0xae856b09 +-0, 348320, 414720, 0xb2298b3e ++0, 348320, 414720, 0x2bfd1967 + 1, 354318, 5888, 0xa2369c95 +-0, 354326, 414720, 0xb4f50176 ++0, 354326, 414720, 0x974a99cd + 1, 360327, 5848, 0x992d516b +-0, 360331, 414720, 0xb9c7a495 ++0, 360331, 414720, 0x5f5f4129 + 1, 366294, 5888, 0xcd785ba9 +-0, 366337, 414720, 0xed270702 ++0, 366337, 414720, 0x51ad9df4 + 1, 372302, 5888, 0x55ea3bce +-0, 372342, 414720, 0x98b72586 ++0, 372342, 414720, 0xd6e5c16c + 1, 378310, 5888, 0xf06d4bbf +-0, 378348, 414720, 0xd8977cb1 ++0, 378348, 414720, 0xd8751bda + 1, 384318, 5888, 0x2a9d4c1a +-0, 384353, 414720, 0xff3d3851 ++0, 384353, 414720, 0x216ed6f3 + 1, 390327, 5888, 0xd5e348a3 +-0, 390359, 414720, 0x7e4f0424 ++0, 390359, 414720, 0x63a0a67d + 1, 396335, 5888, 0x6431a24c +-0, 396364, 414720, 0xa9e75006 ++0, 396364, 414720, 0xe4f4eb0f + 1, 402343, 5888, 0x41f9908c +-0, 402370, 414720, 0x8f98cba9 ++0, 402370, 414720, 0xa1665ef8 + 1, 408351, 5888, 0x0ed99656 +-0, 408375, 414720, 0x25ecd620 ++0, 408375, 414720, 0xc3116dfd + 1, 414359, 5888, 0x635a6392 +-0, 414381, 414720, 0x78cf5c58 ++0, 414381, 414720, 0x3213fd70 + 1, 420367, 5888, 0x690c750c +-0, 420386, 414720, 0x3fb4b81a ++0, 420386, 414720, 0x2af76048 + 1, 426376, 5888, 0xf9d97b23 +-0, 426392, 414720, 0xd7b655fa ++0, 426392, 414720, 0x3570085d + 1, 432384, 5888, 0x75e1606b +-0, 432397, 414720, 0xd9158db3 ++0, 432397, 414720, 0x2a7c3c39 + 1, 438392, 5888, 0x1bcb43b0 +-0, 438403, 414720, 0x2e651852 ++0, 438403, 414720, 0xd8a6ba7e + 1, 444400, 5888, 0x48c295cb +-0, 444408, 414720, 0x9f9adb64 ++0, 444408, 414720, 0x48107b4d + 1, 450408, 5848, 0xe47f7b5d +-0, 450414, 414720, 0xe9d16e81 ++0, 450414, 414720, 0x653a0936 + 1, 456376, 5888, 0x20be7f3e +-0, 456420, 414720, 0xbe73daf5 ++0, 456420, 414720, 0xf68c77ab + 1, 462384, 5888, 0x8c2428c4 +-0, 462425, 414720, 0x3d164329 ++0, 462425, 414720, 0xa5ecde84 + 1, 468392, 5888, 0x851379af +-0, 468431, 414720, 0x1d5a9bc8 ++0, 468431, 414720, 0xaec33ca1 + 1, 474400, 5888, 0x5916647d +-0, 474436, 414720, 0x8e8debbe ++0, 474436, 414720, 0x26e68740 + 1, 480408, 5888, 0xef9c6281 +-0, 480442, 414720, 0x4e7a2bf0 ++0, 480442, 414720, 0xac09bfa5 + 1, 486416, 5888, 0x49660d32 +-0, 486447, 414720, 0x4a13804d ++0, 486447, 414720, 0xed5111b2 + 1, 492424, 5888, 0x62cf36a1 +-0, 492453, 414720, 0x5dd188d8 ++0, 492453, 414720, 0x38041c98 + 1, 498433, 5888, 0x56dff39c +-0, 498458, 414720, 0xbe7f4963 ++0, 498458, 414720, 0x76fbde1d + 1, 504441, 5888, 0x4e6b5b02 +-0, 504464, 414720, 0xcff3b767 ++0, 504464, 414720, 0x3ae64b7d + 1, 510449, 5888, 0xb8697067 +-0, 510469, 414720, 0xbbd3afa0 ++0, 510469, 414720, 0xb05f4da2 + 1, 516457, 5888, 0xcb4e2706 +-0, 516475, 414720, 0xaf9dec62 ++0, 516475, 414720, 0x65769088 + 1, 522465, 5888, 0x6eaa9669 +-0, 522480, 414720, 0xc74816a1 ++0, 522480, 414720, 0xbc45ba59 + 1, 528473, 5888, 0xfd9d7dba +-0, 528486, 414720, 0x51488bfc ++0, 528486, 414720, 0x8c893436 + 1, 534482, 5888, 0xfe137923 +-0, 534491, 414720, 0x68c10a2c ++0, 534491, 414720, 0x1d5ebe7f + 1, 540490, 5848, 0x1931296f +-0, 540497, 414720, 0x10179c4e ++0, 540497, 414720, 0xa9cd5a53 + 1, 546457, 5888, 0xa09a7c03 +-0, 546502, 414720, 0x18d559b7 ++0, 546502, 414720, 0xc69e1fb0 + 1, 552465, 5888, 0xded9802d +-0, 552508, 414720, 0x8257aa55 ++0, 552508, 414720, 0xb28a77ec + 1, 558473, 5888, 0x9f6723b7 +-0, 558513, 414720, 0x9ea24501 ++0, 558513, 414720, 0x834f1219 + 1, 564482, 5888, 0x3ad02476 +-0, 564519, 414720, 0x238605cc ++0, 564519, 414720, 0xba34c848 + 1, 570490, 5888, 0xa1647e32 +-0, 570524, 414720, 0xb552deaa ++0, 570524, 414720, 0x80e590c1 + 1, 576498, 5888, 0x728672da +-0, 576530, 414720, 0x07c3348d ++0, 576530, 414720, 0x7146dc31 + 1, 582506, 5888, 0x9c098090 +-0, 582535, 414720, 0x82f4f9b0 ++0, 582535, 414720, 0x05929a5f + 1, 588514, 5888, 0x32a65ea3 +-0, 588541, 414720, 0xf5d76bc5 ++0, 588541, 414720, 0x721708c5 + 1, 594522, 5888, 0xdde141d5 +-0, 594546, 414720, 0x34b3a1e6 ++0, 594546, 414720, 0x4aa83cbe + 1, 600531, 5888, 0x816c5fb4 +-0, 600552, 414720, 0xda25e11b ++0, 600552, 414720, 0x221d799f + 1, 606539, 5888, 0x75e17581 +-0, 606558, 414720, 0x2b19936b ++0, 606558, 414720, 0xe9e72bec + 1, 612547, 5888, 0x59035469 +-0, 612563, 414720, 0xe91f9f73 ++0, 612563, 414720, 0xb6a3385d + 1, 618555, 5888, 0x20d340cd +-0, 618569, 414720, 0x48d09aab ++0, 618569, 414720, 0x795a3362 + 1, 624563, 5888, 0xa89a8790 +-0, 624574, 414720, 0xac42bf83 ++0, 624574, 414720, 0x770b58d9 + 1, 630571, 5848, 0x12b74c34 +-0, 630580, 414720, 0x2d8ca14e ++0, 630580, 414720, 0xb5563ce4 + 1, 636539, 5888, 0xcd3b3bef +-0, 636585, 414720, 0xe65462fd ++0, 636585, 414720, 0x0c1a00cc + 1, 642547, 5888, 0xe5c44bf3 +-0, 642591, 414720, 0xe5bfc929 ++0, 642591, 414720, 0xcbd467fd + 1, 648555, 5888, 0xb82c4fa4 +-0, 648596, 414720, 0x66784c58 ++0, 648596, 414720, 0x3bccec29 + 1, 654563, 5888, 0x05b2443a +-0, 654602, 414720, 0x70dbeca8 ++0, 654602, 414720, 0x92d78db7 + 1, 660571, 5888, 0x78028172 + 1, 666580, 5888, 0xdfcac19a + 1, 672588, 5888, 0x0761a0b9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lmlm4-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lmlm4-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lmlm4-demux 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lmlm4-demux 2012-05-14 14:08:55.679367052 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 768, 0xaebcbebb + 0, 0, 5951, 0xe9118e0d ++1, 0, 768, 0xaebcbebb + 1, 2160, 768, 0xaebcbebb + 0, 3003, 1672, 0x4b80d4ca + 1, 4320, 768, 0xaebcbebb +@@ -213,335 +213,3 @@ + 1, 265680, 768, 0xfd6c7597 + 0, 267267, 1327, 0x7d15307c + 1, 267840, 768, 0x8d766d40 +-0, 270270, 1225, 0x1b5d0f5f +-0, 273273, 1173, 0x840efed5 +-0, 276276, 1215, 0xa8e0035e +-0, 279279, 1295, 0x142918ca +-0, 282282, 1144, 0xf50cef50 +-0, 285285, 1527, 0x7d13bd9d +-0, 288288, 5609, 0x1ae1921d +-0, 291291, 1303, 0xabdc264f +-0, 294294, 1419, 0x878169bf +-0, 297297, 972, 0x00c4a257 +-0, 300300, 1277, 0x87d520cf +-0, 303303, 1014, 0x5946b4ee +-0, 306306, 1177, 0x124e0e23 +-0, 309309, 1402, 0x8e6363cc +-0, 312312, 1171, 0x9bdaeda2 +-0, 315315, 1389, 0x2db53b22 +-0, 318318, 1056, 0xd1c3de3e +-0, 321321, 1320, 0x1ea142c7 +-0, 324324, 1250, 0x33612229 +-0, 327327, 1477, 0xb9648b48 +-0, 330330, 1522, 0x5352c318 +-0, 333333, 1391, 0x5e9157e0 +-0, 336336, 5545, 0x569e64c1 +-0, 339339, 1354, 0xdb39469e +-0, 342342, 1302, 0x79912b5d +-0, 345345, 1065, 0x4befcdd2 +-0, 348348, 1408, 0x7d2f65a2 +-0, 351351, 1727, 0x9cac0398 +-0, 354354, 1590, 0xa321b563 +-0, 357357, 1039, 0xfa35cabf +-0, 360360, 1184, 0xb332fde7 +-0, 363363, 669, 0xb10e3783 +-0, 366366, 784, 0x57275e09 +-0, 369369, 1051, 0xe072cd33 +-0, 372372, 1119, 0x635ee9ee +-0, 375375, 1147, 0x3916f981 +-0, 378378, 1086, 0x306ef895 +-0, 381381, 827, 0x213f7aef +-0, 384384, 5525, 0x19157827 +-0, 387387, 1044, 0xb661abc5 +-0, 390390, 1143, 0x032e1109 +-0, 393393, 1460, 0x5a2f9503 +-0, 396396, 1178, 0xd038141f +-0, 399399, 1004, 0x410ec3b2 +-0, 402402, 1089, 0xc89af8c9 +-0, 405405, 1367, 0x52085e0a +-0, 408408, 1115, 0x8bb2ee7f +-0, 411411, 1325, 0xc2e05647 +-0, 414414, 1295, 0x213951c9 +-0, 417417, 1054, 0xbb8bdaae +-0, 420420, 1210, 0x431122bd +-0, 423423, 1400, 0x47526fcc +-0, 426426, 1188, 0x19770b07 +-0, 429429, 1301, 0x437161c8 +-0, 432432, 5281, 0xc0c92b55 +-0, 435435, 840, 0x67da7b2f +-0, 438438, 1094, 0x3fd6d944 +-0, 441441, 832, 0x0eda74bc +-0, 444444, 1096, 0x3300da7b +-0, 447447, 1018, 0xa208c971 +-0, 450450, 1389, 0x1167724c +-0, 453453, 1411, 0xe3be666b +-0, 456456, 1294, 0xa8f35cc6 +-0, 459459, 1232, 0xfd0d20fd +-0, 462462, 1252, 0xadd83a26 +-0, 465465, 844, 0xcbaf6a55 +-0, 468468, 979, 0x78d9b241 +-0, 471471, 1057, 0x6743e16c +-0, 474474, 776, 0xfedd6615 +-0, 477477, 1158, 0xa39fee34 +-0, 480480, 5288, 0x5f26ee02 +-0, 483483, 1029, 0xa681bee8 +-0, 486486, 1106, 0xa68dea33 +-0, 489489, 844, 0x42fd83ec +-0, 492492, 779, 0xb5006759 +-0, 495495, 951, 0xec13af4f +-0, 498498, 1011, 0x90e5c86e +-0, 501501, 892, 0x4db48ca4 +-0, 504504, 804, 0x59bf73a7 +-0, 507507, 1001, 0x10c2b3ff +-0, 510510, 879, 0x65c57eaf +-0, 513513, 1320, 0x80815836 +-0, 516516, 1448, 0xaf457b3b +-0, 519519, 1168, 0x65b9f96a +-0, 522522, 1002, 0x053fafb9 +-0, 525525, 1101, 0x2d30c3d5 +-0, 528528, 5314, 0x87cee383 +-0, 531531, 1305, 0xb19035db +-0, 534534, 1240, 0xdc6a0a65 +-0, 537537, 1067, 0x9c88ba67 +-0, 540540, 823, 0x2f736a43 +-0, 543543, 1183, 0x2ef9f3c9 +-0, 546546, 899, 0x3fcc8d11 +-0, 549549, 886, 0xccec8d49 +-0, 552552, 1190, 0x2d020fa1 +-0, 555555, 1017, 0x0776b627 +-0, 558558, 1202, 0xbdd808d5 +-0, 561561, 998, 0x64c7c246 +-0, 564564, 1200, 0x9d6e2289 +-0, 567567, 895, 0xa8a68d80 +-0, 570570, 748, 0xe61a49fb +-0, 573573, 929, 0x30168b50 +-0, 576576, 5276, 0xceb2edf2 +-0, 579579, 1127, 0xab43ddc3 +-0, 582582, 1028, 0xaacfbff5 +-0, 585585, 914, 0xb63c8fb0 +-0, 588588, 1067, 0xbdacd1ed +-0, 591591, 1109, 0x6792ddec +-0, 594594, 1310, 0x71bc4da2 +-0, 597597, 1098, 0xc464de9b +-0, 600600, 1018, 0x6833b875 +-0, 603603, 1210, 0x44faf34b +-0, 606606, 1200, 0x9ee816f6 +-0, 609609, 1461, 0xc76b7d2b +-0, 612612, 829, 0x006677e6 +-0, 615615, 1145, 0xc769fb13 +-0, 618618, 1292, 0xb63225f5 +-0, 621621, 1252, 0x0e2a2626 +-0, 624624, 5257, 0x3877eca1 +-0, 627627, 952, 0x7f708d25 +-0, 630630, 1125, 0x140cd81b +-0, 633633, 1095, 0x3025dade +-0, 636636, 1388, 0xd7494d4e +-0, 639639, 1124, 0x0c48ee92 +-0, 642642, 1556, 0xa0749ee2 +-0, 645645, 1461, 0xe5fd7d7f +-0, 648648, 903, 0x07a58303 +-0, 651651, 1049, 0x4b6cd03b +-0, 654654, 1044, 0x5f47cb48 +-0, 657657, 1253, 0xba281c6a +-0, 660660, 1618, 0xed7cd040 +-0, 663663, 981, 0x2926b6f4 +-0, 666666, 1560, 0xa0e1ab73 +-0, 669669, 1479, 0x41a77e88 +-0, 672672, 5222, 0xc2dbd182 +-0, 675675, 925, 0x967580dd +-0, 678678, 1284, 0x5b7822e0 +-0, 681681, 1512, 0xe84da1e0 +-0, 684684, 1514, 0xc38bb09e +-0, 687687, 1224, 0x8752228e +-0, 690690, 1296, 0xcf053c03 +-0, 693693, 1117, 0x9a81e659 +-0, 696696, 1090, 0x003ed687 +-0, 699699, 1196, 0x3a510937 +-0, 702702, 1075, 0x05eec8d4 +-0, 705705, 1048, 0x3b19cb96 +-0, 708708, 944, 0xaad89770 +-0, 711711, 960, 0x94649e4c +-0, 714714, 1079, 0x530ddaba +-0, 717717, 1150, 0x0339e696 +-0, 720720, 5189, 0xb8dac0bf +-0, 723723, 1129, 0x3b2cd64d +-0, 726726, 962, 0xe9df9a07 +-0, 729729, 1113, 0xc6ccddb2 +-0, 732732, 1069, 0xf589d4a4 +-0, 735735, 889, 0x5f7b8762 +-0, 738738, 863, 0xe9c36be4 +-0, 741741, 1021, 0xcfb5a737 +-0, 744744, 1048, 0x203ac9ff +-0, 747747, 1223, 0x3e30fe35 +-0, 750750, 814, 0x59c076fc +-0, 753753, 1157, 0x0dcf0bd0 +-0, 756756, 1691, 0xdd030547 +-0, 759759, 1700, 0x7641fb7e +-0, 762762, 1791, 0x57ac147b +-0, 765765, 2008, 0x3d4483ca +-0, 768768, 4579, 0x874aa75b +-0, 771771, 1647, 0xeddef621 +-0, 774774, 1999, 0x61d4a23a +-0, 777777, 1572, 0x1c3ae6e1 +-0, 780780, 1803, 0xb31c3a11 +-0, 783783, 1919, 0xccbf64e3 +-0, 786786, 1720, 0xa4d010e5 +-0, 789789, 1721, 0x87ee0c7b +-0, 792792, 1626, 0x8211f3d0 +-0, 795795, 1675, 0xef8a0b3d +-0, 798798, 1609, 0x8731ce06 +-0, 801801, 1691, 0xcf24038b +-0, 804804, 1637, 0x21d8e1b2 +-0, 807807, 1546, 0xc597a700 +-0, 810810, 1518, 0xb944bc11 +-0, 813813, 1403, 0x999e59a8 +-0, 816816, 2467, 0xe69f2507 +-0, 819819, 531, 0x3c7cea7e +-0, 822822, 555, 0xdf20fb22 +-0, 825825, 500, 0xebeee00d +-0, 828828, 446, 0x664cc711 +-0, 831831, 521, 0xf223df4b +-0, 834834, 559, 0x4dc60028 +-0, 837837, 593, 0xec440ba9 +-0, 840840, 557, 0xef0100b1 +-0, 843843, 602, 0x7b1cfd88 +-0, 846846, 566, 0x77700a1d +-0, 849849, 523, 0x3df7eb64 +-0, 852852, 482, 0x5da1dba9 +-0, 855855, 541, 0x9c8ff3d7 +-0, 858858, 572, 0x3e1204b2 +-0, 861861, 549, 0x0921fe3d +-0, 864864, 2429, 0xba4fe5a8 +-0, 867867, 495, 0xc35ade54 +-0, 870870, 453, 0xcc66c9dc +-0, 873873, 421, 0x3aa7ce8f +-0, 876876, 448, 0x56c6d3d7 +-0, 879879, 478, 0x4131d467 +-0, 882882, 497, 0xac3ce3ca +-0, 885885, 470, 0x41b9d9d3 +-0, 888888, 454, 0x44c2d956 +-0, 891891, 460, 0x6629db01 +-0, 894894, 488, 0x6be2dd68 +-0, 897897, 512, 0xda4cf116 +-0, 900900, 550, 0x6e990da9 +-0, 903903, 561, 0x81180e5e +-0, 906906, 689, 0xe58a5a9a +-0, 909909, 548, 0xfa1417a9 +-0, 912912, 2832, 0x942495a5 +-0, 915915, 610, 0x6b201ab9 +-0, 918918, 1015, 0x5f36b3f9 +-0, 921921, 870, 0x14e48f0c +-0, 924924, 716, 0xf4034b52 +-0, 927927, 763, 0xcbf4694e +-0, 930930, 778, 0xb9396764 +-0, 933933, 831, 0x31999005 +-0, 936936, 877, 0xc95e977f +-0, 939939, 836, 0xb56c7d61 +-0, 942942, 853, 0x2d5980cf +-0, 945945, 861, 0x25629295 +-0, 948948, 897, 0x0ff78a5f +-0, 951951, 1016, 0x4dd8cdfd +-0, 954954, 1117, 0x763f06c4 +-0, 957957, 984, 0xcf7bc906 +-0, 960960, 2750, 0xd428962d +-0, 963963, 995, 0x5cbdd6a4 +-0, 966966, 894, 0xc42b9e25 +-0, 969969, 1028, 0xdf8ad906 +-0, 972972, 1059, 0x4c49f0cc +-0, 975975, 1122, 0x8880eed8 +-0, 978978, 1007, 0xa9b4c243 +-0, 981981, 1055, 0x6051dcd6 +-0, 984984, 1293, 0xc3b32fa5 +-0, 987987, 1101, 0xf986f9af +-0, 990990, 1272, 0x13883127 +-0, 993993, 1037, 0xb97cebff +-0, 996996, 980, 0x0931d807 +-0, 999999, 928, 0xbc3eb30b +-0, 1003002, 1068, 0x62d9e8de +-0, 1006005, 852, 0x9278a49a +-0, 1009008, 2841, 0x3091d12d +-0, 1012011, 931, 0x60f6c26e +-0, 1015014, 949, 0x31b9c856 +-0, 1018017, 835, 0xfe018775 +-0, 1021020, 779, 0x85356cd7 +-0, 1024023, 748, 0x862756bf +-0, 1027026, 768, 0x0b7d645c +-0, 1030029, 786, 0x7c196f5b +-0, 1033032, 716, 0x4e8252cc +-0, 1036035, 671, 0x0b2d3023 +-0, 1039038, 708, 0x3b2b4f25 +-0, 1042041, 786, 0x523d670e +-0, 1045044, 680, 0x329142ec +-0, 1048047, 703, 0x841b456c +-0, 1051050, 660, 0x5cf332f1 +-0, 1054053, 681, 0xcd7b3915 +-0, 1057056, 2445, 0x27660ecb +-0, 1060059, 667, 0xf3d53d2a +-0, 1063062, 652, 0xe2b037b0 +-0, 1066065, 695, 0x200248fc +-0, 1069068, 659, 0x7f6434c5 +-0, 1072071, 682, 0x8d243afb +-0, 1075074, 701, 0x16e6476f +-0, 1078077, 636, 0x319a3236 +-0, 1081080, 679, 0x81fa41f9 +-0, 1084083, 740, 0xb32850af +-0, 1087086, 694, 0xe3f832c2 +-0, 1090089, 681, 0x8174353f +-0, 1093092, 757, 0xebbe5a1f +-0, 1096095, 683, 0x9b46383c +-0, 1099098, 816, 0xd41e6bdf +-0, 1102101, 1058, 0x6170d2e6 +-0, 1105104, 2489, 0x58fb28e1 +-0, 1108107, 804, 0xb3037da8 +-0, 1111110, 1053, 0x81ffc0a8 +-0, 1114113, 868, 0xf73583cb +-0, 1117116, 875, 0xfa5d85bd +-0, 1120119, 723, 0x0714418d +-0, 1123122, 670, 0xd04333a1 +-0, 1126125, 854, 0x370e730d +-0, 1129128, 794, 0x3d8a5e3c +-0, 1132131, 836, 0xebe26aa7 +-0, 1135134, 871, 0x1da58c5e +-0, 1138137, 827, 0xda1e6ccb +-0, 1141140, 805, 0x10ad6a44 +-0, 1144143, 831, 0x826f6fc9 +-0, 1147146, 832, 0xb2517364 +-0, 1150149, 887, 0x11bf8a3f +-0, 1153152, 2718, 0x26a8a174 +-0, 1156155, 805, 0x4d0179f9 +-0, 1159158, 699, 0x176c4f45 +-0, 1162161, 758, 0xc1fc5b16 +-0, 1165164, 707, 0x161b4891 +-0, 1168167, 733, 0x99b554c0 +-0, 1171170, 671, 0xccee2f89 +-0, 1174173, 762, 0xd6416c9d +-0, 1177176, 721, 0x2ad94f0c +-0, 1180179, 727, 0x6280572e +-0, 1183182, 856, 0x0a7b797e +-0, 1186185, 843, 0xc64288aa +-0, 1189188, 877, 0x6d1c945d +-0, 1192191, 780, 0x4ba464e8 +-0, 1195194, 808, 0xb3087cca +-0, 1198197, 870, 0x75809930 +-0, 1201200, 2919, 0x5a80f685 +-0, 1204203, 1027, 0xc98add3d +-0, 1207206, 1003, 0x0d88bd54 +-0, 1210209, 1189, 0xb2f91ec7 +-0, 1213212, 1320, 0x5acc4db3 +-0, 1216215, 1381, 0xbd585feb +-0, 1219218, 1378, 0xe1a656f0 +-0, 1222221, 1398, 0x88b57a5e +-0, 1225224, 1449, 0x1c737698 +-0, 1228227, 1420, 0x6f0f80cd +-0, 1231230, 1032, 0x2d16d643 +-0, 1234233, 1275, 0x38844729 +-0, 1237236, 1112, 0x300207ea +-0, 1240239, 1105, 0xa2b700be +-0, 1243242, 1283, 0x08d04bef +-0, 1246245, 1056, 0xf795d994 +-0, 1249248, 3202, 0xebf07050 +-0, 1252251, 1034, 0x1099dbe5 +-0, 1255254, 922, 0x88be9edc +-0, 1258257, 1050, 0xd3d7eb96 +-0, 1261260, 979, 0x8de6b302 +-0, 1264263, 1053, 0x5de2eca8 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-alac xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-alac +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-alac 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-alac 2012-05-14 14:08:55.680367072 +0200 +@@ -0,0 +1 @@ ++d0beb768d860b4776358077dd9fcb1e9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-appleaudio xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-appleaudio +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-appleaudio 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-appleaudio 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-d0beb768d860b4776358077dd9fcb1e9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-shorten xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-shorten +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-shorten 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-shorten 2012-05-14 14:08:55.681367092 +0200 +@@ -0,0 +1 @@ ++da93c50961443b88fce416ae61c8ca8a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-shortenaudio xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-shortenaudio +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-shortenaudio 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-shortenaudio 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-9949141c405524f37ef1058b1ef4114b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-wavpack xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-wavpack +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-wavpack 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-wavpack 2012-05-14 14:08:55.682367112 +0200 +@@ -0,0 +1 @@ ++97223f65c91213694a660d52f87f35aa +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-wavpackaudio xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-wavpackaudio +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/lossless-wavpackaudio 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/lossless-wavpackaudio 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-97223f65c91213694a660d52f87f35aa +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2 2012-05-14 14:08:55.682367112 +0200 +@@ -0,0 +1,2 @@ ++6f091fe8c0be88c75921731dc9f74314 ++5c2d162b9024329eb367295d37b8ca0a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2-downmix-mono xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2-downmix-mono +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2-downmix-mono 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-6ch-extract-2-downmix-mono 2012-05-14 14:08:55.683367132 +0200 +@@ -0,0 +1 @@ ++959645ed73e6d08d8f1e947eac5d0b92 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-silent-mono xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-silent-mono +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mapchan-silent-mono 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mapchan-silent-mono 2012-05-14 14:08:55.683367132 +0200 +@@ -0,0 +1 @@ ++4f5148f08587a4b9794aa52aec7852ac +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/md5 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/md5 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/md5 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/md5 2012-05-14 14:08:55.684367152 +0200 +@@ -0,0 +1,5 @@ ++0bf1bcc8a1d72e2cf58d42182b637e56 ++993a3eb298e52aca83ecfbb6a766b4d0 ++07c01ca7c733475fad38c84c56f305c1 ++9fc8404827cac26385f48f4f58fd32ce ++a22bfef14302c5ca46e0ae91092bc0e0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/motionpixels xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/motionpixels +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/motionpixels 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/motionpixels 2012-05-14 14:08:55.685367172 +0200 +@@ -1,112 +1,111 @@ + 0, 0, 230400, 0xee05b509 +-0, 6000, 230400, 0x71048964 +-0, 12000, 230400, 0x2ebe4ba1 +-0, 18000, 230400, 0xeedc45a6 +-0, 24000, 230400, 0x218e8656 +-0, 30000, 230400, 0x5792b17e +-0, 36000, 230400, 0x51b0a062 +-0, 42000, 230400, 0x5dc4fd9c +-0, 48000, 230400, 0x9b0261b1 +-0, 54000, 230400, 0x35086ffc +-0, 60000, 230400, 0xcf9352ff +-0, 66000, 230400, 0x0b5139a1 +-0, 72000, 230400, 0x22e8a31e +-0, 78000, 230400, 0x82f61a81 +-0, 84000, 230400, 0xc5741ab5 +-0, 90000, 230400, 0xb5e7b2ff +-0, 96000, 230400, 0x583289ca +-0, 102001, 230400, 0xee52afbb +-0, 108001, 230400, 0xfdb4dc1a +-0, 114001, 230400, 0xf5ce99c0 +-0, 120001, 230400, 0xae222255 +-0, 126001, 230400, 0xc4f4439d +-0, 132001, 230400, 0x1758f224 +-0, 138001, 230400, 0x5f517926 +-0, 144001, 230400, 0x73a8bed8 +-0, 150001, 230400, 0x7ef8410c +-0, 156001, 230400, 0xfcb693c7 +-0, 162001, 230400, 0x5292832e +-0, 168001, 230400, 0x591261d7 +-0, 174001, 230400, 0x28cca691 +-0, 180001, 230400, 0x22cf40ef +-0, 186001, 230400, 0x517b10f9 +-0, 192001, 230400, 0x8197e939 +-0, 198001, 230400, 0x9654ffdb +-0, 204001, 230400, 0x803f10dd +-0, 210001, 230400, 0xff9f67af +-0, 216001, 230400, 0x4847244c +-0, 222001, 230400, 0xff31638f +-0, 228001, 230400, 0x9692def5 +-0, 234001, 230400, 0x67f0a5fb +-0, 240001, 230400, 0xce192074 +-0, 246001, 230400, 0x33d6c4a5 +-0, 252001, 230400, 0xaf7b5a03 +-0, 258001, 230400, 0xd956b0c0 +-0, 264001, 230400, 0x58ff1a65 +-0, 270001, 230400, 0x044758a1 +-0, 276001, 230400, 0xe8045b65 +-0, 282001, 230400, 0xf504c5fb +-0, 288001, 230400, 0x17a9a2b0 +-0, 294001, 230400, 0xf68bab8c +-0, 300002, 230400, 0xd06dd0cb +-0, 306002, 230400, 0xc47d2673 +-0, 312002, 230400, 0x2112f291 +-0, 318002, 230400, 0x4c07c83c +-0, 324002, 230400, 0x22ca0113 +-0, 330002, 230400, 0x25b0c8b1 +-0, 336002, 230400, 0xb6afc645 +-0, 342002, 230400, 0x663b1c09 +-0, 348002, 230400, 0x9006ef1f +-0, 354002, 230400, 0x54f81b11 +-0, 360002, 230400, 0x456b79f2 +-0, 366002, 230400, 0xb08f24d0 +-0, 372002, 230400, 0x652ad875 +-0, 378002, 230400, 0xc6ecd67f +-0, 384002, 230400, 0x78dad721 +-0, 390002, 230400, 0x1d2a4f71 +-0, 396002, 230400, 0xc71721d1 +-0, 402002, 230400, 0x64e3a7df +-0, 408002, 230400, 0x3bb18e71 +-0, 414002, 230400, 0xb571d58c +-0, 420002, 230400, 0xdae6ed5c +-0, 426002, 230400, 0xdd91504b +-0, 432002, 230400, 0xd5a807a5 +-0, 438002, 230400, 0x39a67b03 +-0, 444002, 230400, 0xe245c8ac +-0, 450002, 230400, 0x5b0d7858 +-0, 456002, 230400, 0x501b8097 +-0, 462002, 230400, 0xf7b10d48 +-0, 468002, 230400, 0x769db0bd +-0, 474002, 230400, 0x600f1086 +-0, 480002, 230400, 0x874f5565 +-0, 486002, 230400, 0x14322f73 +-0, 492002, 230400, 0x0eaa36a5 +-0, 498002, 230400, 0x97178d13 +-0, 504003, 230400, 0xd4c7a0d1 +-0, 510003, 230400, 0x1d424ec8 +-0, 516003, 230400, 0x695ad8d9 +-0, 522003, 230400, 0xe7cc3ecf +-0, 528003, 230400, 0xfd25fd8c +-0, 534003, 230400, 0xef4bc203 +-0, 540003, 230400, 0x2a113bec +-0, 546003, 230400, 0x6e7ad403 +-0, 552003, 230400, 0xc6714d2b +-0, 558003, 230400, 0x77df8ba6 +-0, 564003, 230400, 0xcd283106 +-0, 570003, 230400, 0xcb95676f +-0, 576003, 230400, 0xb0b70393 +-0, 582003, 230400, 0x4c40bd63 +-0, 588003, 230400, 0x557e8ccf +-0, 594003, 230400, 0x9d5934b2 +-0, 600003, 230400, 0x43c1793f +-0, 606003, 230400, 0x0232361e +-0, 612003, 230400, 0x92ed91e4 +-0, 618003, 230400, 0x99769789 +-0, 624003, 230400, 0xd49c2c5b +-0, 630003, 230400, 0x66b03495 +-0, 636003, 230400, 0xb88a4658 +-0, 642003, 230400, 0x9c21e4c2 +-0, 648003, 230400, 0xb343f372 +-0, 654003, 230400, 0xf7f1e588 +-0, 660003, 230400, 0x9682bdb2 +-0, 666003, 230400, 0x538a3db8 ++0, 6000, 230400, 0x23b28b24 ++0, 12000, 230400, 0x4a4d6007 ++0, 18000, 230400, 0xe5550693 ++0, 24000, 230400, 0xad4905a3 ++0, 30000, 230400, 0xc83b9030 ++0, 36000, 230400, 0xbc73a26a ++0, 42000, 230400, 0x7065ff8a ++0, 48000, 230400, 0x65bc7675 ++0, 54000, 230400, 0xc245737f ++0, 60000, 230400, 0x77e6c1ed ++0, 66000, 230400, 0x6761d73a ++0, 72000, 230400, 0x6207b8f8 ++0, 78000, 230400, 0xa3691862 ++0, 84000, 230400, 0x83fbfc24 ++0, 90000, 230400, 0xe1c34ef0 ++0, 96000, 230400, 0xd7b50e8e ++0, 102001, 230400, 0x5b5e2f29 ++0, 108001, 230400, 0xca7825e5 ++0, 114001, 230400, 0xb4c7b4a9 ++0, 120001, 230400, 0xc35513b5 ++0, 126001, 230400, 0x36117834 ++0, 132001, 230400, 0x8af035d7 ++0, 138001, 230400, 0x25c50a2e ++0, 144001, 230400, 0x52f54107 ++0, 150001, 230400, 0xaddca5f9 ++0, 156001, 230400, 0x3b1fe64c ++0, 162001, 230400, 0xcd52de15 ++0, 168001, 230400, 0xfaa4f7fa ++0, 174001, 230400, 0xce5b3221 ++0, 180001, 230400, 0xb2c3d9ba ++0, 186001, 230400, 0xf6ec95e9 ++0, 192001, 230400, 0xfa7ebd18 ++0, 198001, 230400, 0xb6e50465 ++0, 204001, 230400, 0xd48ceee9 ++0, 210001, 230400, 0x333605cf ++0, 216001, 230400, 0xe7ccf362 ++0, 222001, 230400, 0x39f07b83 ++0, 228001, 230400, 0xd6450b2e ++0, 234001, 230400, 0x2029ec12 ++0, 240001, 230400, 0x15d7762e ++0, 246001, 230400, 0x0d69506d ++0, 252001, 230400, 0xcf2ef066 ++0, 258001, 230400, 0x2c145df0 ++0, 264001, 230400, 0x153d7fe7 ++0, 270001, 230400, 0x98846aea ++0, 276001, 230400, 0xc0347d4e ++0, 282001, 230400, 0xda7a58a8 ++0, 288001, 230400, 0x5724c05e ++0, 294001, 230400, 0x9805237b ++0, 300002, 230400, 0x2f5f0d70 ++0, 306002, 230400, 0xb1271014 ++0, 312002, 230400, 0x6cb29d9c ++0, 318002, 230400, 0x4f91fdb4 ++0, 324002, 230400, 0x274b3f30 ++0, 330002, 230400, 0xdfc508e8 ++0, 336002, 230400, 0x16e974ef ++0, 342002, 230400, 0x98fae336 ++0, 348002, 230400, 0xbf265f84 ++0, 354002, 230400, 0x75cf323b ++0, 360002, 230400, 0xdb3481f7 ++0, 366002, 230400, 0xb8453df5 ++0, 372002, 230400, 0xd4598deb ++0, 378002, 230400, 0x4dc19cf6 ++0, 384002, 230400, 0xa8d1b340 ++0, 390002, 230400, 0x1f98aa27 ++0, 396002, 230400, 0x505c0687 ++0, 402002, 230400, 0x86179997 ++0, 408002, 230400, 0x7e28cc7d ++0, 414002, 230400, 0x0a81c0bc ++0, 420002, 230400, 0x71cc0c9a ++0, 426002, 230400, 0x8c01340f ++0, 432002, 230400, 0x4afea48a ++0, 438002, 230400, 0x7dc88c26 ++0, 444002, 230400, 0x4155fbbb ++0, 450002, 230400, 0xb1ec2d6b ++0, 456002, 230400, 0x6986ee65 ++0, 462002, 230400, 0x8ff9a311 ++0, 468002, 230400, 0x36c21c52 ++0, 474002, 230400, 0xdb0fad2e ++0, 480002, 230400, 0xc7a83c34 ++0, 486002, 230400, 0x8bd97389 ++0, 492002, 230400, 0x6dd8f0d6 ++0, 498002, 230400, 0x228e2076 ++0, 504003, 230400, 0x22544f03 ++0, 510003, 230400, 0x938084ef ++0, 516003, 230400, 0xb002cd81 ++0, 522003, 230400, 0xe58d3339 ++0, 528003, 230400, 0x02470a69 ++0, 534003, 230400, 0xa5c51328 ++0, 540003, 230400, 0x1a6e37ec ++0, 546003, 230400, 0x8f40563c ++0, 552003, 230400, 0x30f9095f ++0, 558003, 230400, 0x6227f0e8 ++0, 564003, 230400, 0xdca3596d ++0, 570003, 230400, 0x30938988 ++0, 576003, 230400, 0x28bdc666 ++0, 582003, 230400, 0x6c534265 ++0, 588003, 230400, 0x6ea56d2d ++0, 594003, 230400, 0x125f3808 ++0, 600003, 230400, 0x92a41d2f ++0, 606003, 230400, 0xf1cf2410 ++0, 612003, 230400, 0x1bea1204 ++0, 618003, 230400, 0x817e60f9 ++0, 624003, 230400, 0x9f6c720e ++0, 630003, 230400, 0xf1a43a2f ++0, 636003, 230400, 0x5e5e0b7f ++0, 642003, 230400, 0x7f526bcf ++0, 648003, 230400, 0x63a846ed ++0, 654003, 230400, 0x94400af9 ++0, 660003, 230400, 0x51f4241e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mpeg2-field-enc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mpeg2-field-enc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mpeg2-field-enc 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mpeg2-field-enc 2012-05-14 14:08:55.685367172 +0200 +@@ -1,39 +1,31 @@ + 0, 0, 622080, 0xb3b66c5c +-0, 3600, 622080, 0xb3b66c5c +-0, 7200, 622080, 0xb3b66c5c +-0, 10800, 622080, 0xb3b66c5c +-0, 14400, 622080, 0xb3b66c5c +-0, 18000, 622080, 0xb3b66c5c +-0, 21600, 622080, 0xb3b66c5c +-0, 25200, 622080, 0xb3b66c5c +-0, 28800, 622080, 0xb3b66c5c +-0, 32400, 622080, 0x088ec02b +-0, 36000, 622080, 0x7a36db21 +-0, 39600, 622080, 0x541b286f +-0, 43200, 622080, 0xb6c3e590 +-0, 46800, 622080, 0x39dbed51 +-0, 50400, 622080, 0x973dc728 +-0, 54000, 622080, 0xd7a4f804 +-0, 57600, 622080, 0xa2484762 +-0, 61200, 622080, 0x0cd268d1 +-0, 64800, 622080, 0x72eb663d +-0, 68400, 622080, 0x8fdbac59 +-0, 72000, 622080, 0xa6f4feb9 +-0, 75600, 622080, 0xadb828c6 +-0, 79200, 622080, 0xea630a63 +-0, 82800, 622080, 0xa901d925 +-0, 86400, 622080, 0xac5e7087 +-0, 90000, 622080, 0x10274a2b +-0, 93600, 622080, 0x143d541c +-0, 97200, 622080, 0xee94c93a +-0, 100800, 622080, 0xca030208 +-0, 104400, 622080, 0x26f30ead +-0, 108000, 622080, 0xfc22f32c +-0, 111600, 622080, 0x940a5ff8 +-0, 115200, 622080, 0x2164f805 +-0, 118800, 622080, 0xa76f5aba +-0, 122400, 622080, 0x8c311471 +-0, 126000, 622080, 0xa45e1d95 +-0, 129600, 622080, 0x6cc61d6c +-0, 133200, 622080, 0x6983b417 +-0, 136800, 622080, 0x982363c0 ++0, 3600, 622080, 0x088ec02b ++0, 7200, 622080, 0x7a36db21 ++0, 10800, 622080, 0x541b286f ++0, 14400, 622080, 0xb6c3e590 ++0, 18000, 622080, 0x39dbed51 ++0, 21600, 622080, 0x973dc728 ++0, 25200, 622080, 0xd7a4f804 ++0, 28800, 622080, 0xa2484762 ++0, 32400, 622080, 0x0cd268d1 ++0, 36000, 622080, 0x72eb663d ++0, 39600, 622080, 0x8fdbac59 ++0, 43200, 622080, 0xa6f4feb9 ++0, 46800, 622080, 0xadb828c6 ++0, 50400, 622080, 0xea630a63 ++0, 54000, 622080, 0xa901d925 ++0, 57600, 622080, 0xac5e7087 ++0, 61200, 622080, 0x10274a2b ++0, 64800, 622080, 0x143d541c ++0, 68400, 622080, 0xee94c93a ++0, 72000, 622080, 0xca030208 ++0, 75600, 622080, 0x26f30ead ++0, 79200, 622080, 0xfc22f32c ++0, 82800, 622080, 0x940a5ff8 ++0, 86400, 622080, 0x2164f805 ++0, 90000, 622080, 0xa76f5aba ++0, 93600, 622080, 0x8c311471 ++0, 97200, 622080, 0xa45e1d95 ++0, 100800, 622080, 0x6cc61d6c ++0, 104400, 622080, 0x6983b417 ++0, 108000, 622080, 0x982363c0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/msvideo1-16bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/msvideo1-16bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/msvideo1-16bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/msvideo1-16bit 2012-05-14 14:08:55.686367192 +0200 +@@ -1,30 +1,30 @@ +-0, 0, 65712, 0x917e0076 +-0, 6006, 65712, 0xfe76fd1f +-0, 12013, 65712, 0xd85820ee +-0, 18019, 65712, 0x1b410f6e +-0, 24026, 65712, 0x53c50436 +-0, 30032, 65712, 0xa191044d +-0, 36039, 65712, 0xcf02ff1f +-0, 42045, 65712, 0xc2abf85f +-0, 48051, 65712, 0xe273087e +-0, 54058, 65712, 0x087d0936 +-0, 60064, 65712, 0x4e4f2e96 +-0, 66071, 65712, 0x91b51896 +-0, 72077, 65712, 0x2798450e +-0, 78083, 65712, 0x9fea1d06 +-0, 84090, 65712, 0xc64a2506 +-0, 90096, 65712, 0x0551fe07 +-0, 96103, 65712, 0xc64a042e +-0, 102109, 65712, 0xf3680dc6 +-0, 108116, 65712, 0x2ea5356e +-0, 114122, 65712, 0x0315ed3f +-0, 120128, 65712, 0xc1d1f917 +-0, 126135, 65712, 0xc0f6e607 +-0, 132141, 65712, 0x5b0a092e +-0, 138148, 65712, 0x1551f16f +-0, 144154, 65712, 0x8440ee87 +-0, 150161, 65712, 0xf7581ae6 +-0, 156167, 65712, 0xee67037e +-0, 162173, 65712, 0x4a212ca6 +-0, 168180, 65712, 0x693e0aa6 +-0, 174186, 65712, 0x13e31116 ++0, 0, 65712, 0x03ff25b8 ++0, 6006, 65712, 0xfca02276 ++0, 12013, 65712, 0xd23646e4 ++0, 18019, 65712, 0x9ea43556 ++0, 24026, 65712, 0x47412948 ++0, 30032, 65712, 0x667230c9 ++0, 36039, 65712, 0x8224247a ++0, 42045, 65712, 0x9c0f1d71 ++0, 48051, 65712, 0x4fbb2e11 ++0, 54058, 65712, 0x0e4a2e34 ++0, 60064, 65712, 0xd58954c8 ++0, 66071, 65712, 0x131d3e2c ++0, 72077, 65712, 0x3b686bc7 ++0, 78083, 65712, 0xbea342a7 ++0, 84090, 65712, 0xbdff4ac7 ++0, 90096, 65712, 0x215e22ab ++0, 96103, 65712, 0xa9f0295f ++0, 102109, 65712, 0x46fb32f3 ++0, 108116, 65712, 0xd8be5bee ++0, 114122, 65712, 0x526411b6 ++0, 120128, 65712, 0x53951e21 ++0, 126135, 65712, 0x54a70ab3 ++0, 132141, 65712, 0xcc872e7a ++0, 138148, 65712, 0x06b2164c ++0, 144154, 65712, 0x1ae5135f ++0, 150161, 65712, 0x8d8a40b4 ++0, 156167, 65712, 0x3d732893 ++0, 162173, 65712, 0x239a52a8 ++0, 168180, 65712, 0xf6bd2fc9 ++0, 174186, 65712, 0x40b336c4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mtv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mtv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/mtv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/mtv 2012-05-14 14:08:55.687367212 +0200 +@@ -1,133 +1,133 @@ ++0, 0, 18432, 0x28a25967 + 1, 0, 417, 0xae1cc66a +-0, 0, 18432, 0xbd7e0ac8 + 1, 2351, 418, 0xdc3ec850 + 1, 4702, 418, 0x4e8ed05f +-0, 5625, 18432, 0xbd7e0ac8 ++0, 5625, 18432, 0x28a25967 + 1, 7053, 418, 0xeb43d574 + 1, 9404, 418, 0x9357c91d +-0, 11250, 18432, 0x902e0ab4 ++0, 11250, 18432, 0x1a1b5956 + 1, 11755, 418, 0x5306d16b + 1, 14106, 418, 0x46e0d4da + 1, 16457, 418, 0xac11ce79 +-0, 16875, 18432, 0xf1940b28 ++0, 16875, 18432, 0x684659c7 + 1, 18808, 418, 0xffdfc4ad + 1, 21159, 418, 0xf8a8c2ff +-0, 22500, 18432, 0x2c180ac8 ++0, 22500, 18432, 0x8944596a + 1, 23510, 418, 0x2d66d83f + 1, 25861, 418, 0x65c0da12 +-0, 28125, 18432, 0x2eae0b34 ++0, 28125, 18432, 0xa55159d3 + 1, 28212, 418, 0x0eafd20f + 1, 30563, 418, 0x8c6dd949 + 1, 32914, 418, 0x9094c02d +-0, 33750, 18432, 0x2eae0b34 ++0, 33750, 18432, 0xa55159d3 + 1, 35265, 418, 0xb47bd944 + 1, 37616, 418, 0x935ccce7 +-0, 39375, 18432, 0x2eae0b34 ++0, 39375, 18432, 0xa55159d3 + 1, 39967, 418, 0x6e3ed020 + 1, 42318, 418, 0x8922cd6c + 1, 44669, 418, 0xe811c8f8 +-0, 45000, 18432, 0x2eae0b34 ++0, 45000, 18432, 0xa55159d3 + 1, 47020, 418, 0xb84adc72 + 1, 49371, 418, 0xa2bbc5f4 +-0, 50625, 18432, 0x2eae0b34 ++0, 50625, 18432, 0xa55159d3 + 1, 51722, 418, 0xec0cb67d + 1, 54073, 418, 0x89d1d014 +-0, 56250, 18432, 0x2eae0b34 ++0, 56250, 18432, 0xa55159d3 + 1, 56424, 418, 0xfb5bc872 + 1, 58776, 417, 0x8bfcc7a0 + 1, 61127, 418, 0xeb4ac61b +-0, 61875, 18432, 0x2eae0b34 ++0, 61875, 18432, 0xa55159d3 + 1, 63478, 418, 0xd3cbc3c4 + 1, 65829, 418, 0xa272d092 +-0, 67500, 18432, 0x2eae0b34 ++0, 67500, 18432, 0xa55159d3 + 1, 68180, 418, 0x611ec37e + 1, 70531, 418, 0x70a3d423 + 1, 72882, 418, 0xeff9ccf4 +-0, 73125, 18432, 0x2eae0b34 ++0, 73125, 18432, 0xa55159d3 + 1, 75233, 418, 0x9788c65b + 1, 77584, 418, 0xe9a8cb8c +-0, 78750, 18432, 0x2eae0b34 ++0, 78750, 18432, 0xa55159d3 + 1, 79935, 418, 0x5834c300 + 1, 82286, 418, 0xa4b8cd3a +-0, 84375, 18432, 0x2eae0b34 ++0, 84375, 18432, 0xa55159d3 + 1, 84637, 418, 0x6de2c7f9 + 1, 86988, 418, 0x961bbbf3 + 1, 89339, 418, 0x53edc13a +-0, 90000, 18432, 0x2c180ac8 ++0, 90000, 18432, 0x8944596a + 1, 91690, 418, 0x2fedc4b0 + 1, 94041, 418, 0xb756c18b +-0, 95625, 18432, 0x2eae0b34 ++0, 95625, 18432, 0xa55159d3 + 1, 96392, 418, 0xaf0ed0e4 + 1, 98743, 418, 0x019fd3f0 + 1, 101094, 418, 0x6e29d83e +-0, 101250, 18432, 0x2c180ac8 ++0, 101250, 18432, 0x8944596a + 1, 103445, 418, 0x2ddad6bb + 1, 105796, 418, 0xafefca99 +-0, 106875, 18432, 0x2eae0b34 ++0, 106875, 18432, 0xa55159d3 + 1, 108147, 418, 0x366ed013 + 1, 110498, 418, 0x532ac7e0 +-0, 112500, 18432, 0x2c180ac8 ++0, 112500, 18432, 0x8944596a + 1, 112849, 418, 0x1d0cd1ce + 1, 115200, 417, 0x572ad1e3 + 1, 117551, 418, 0x858cd91f +-0, 118125, 18432, 0x2eae0b34 ++0, 118125, 18432, 0xa55159d3 + 1, 119902, 418, 0x82cacdfd + 1, 122253, 418, 0xf4dcc6ed +-0, 123750, 18432, 0x2c180ac8 ++0, 123750, 18432, 0x8944596a + 1, 124604, 418, 0x2cf3ca72 + 1, 126955, 418, 0x5963c859 + 1, 129306, 418, 0xa667c53d +-0, 129375, 18432, 0x2eae0b34 ++0, 129375, 18432, 0xa55159d3 + 1, 131657, 418, 0xb2f1d09c + 1, 134008, 418, 0x2ec1c8d3 +-0, 135000, 18432, 0x2eae0b34 ++0, 135000, 18432, 0xa55159d3 + 1, 136359, 418, 0x5754d2e8 + 1, 138710, 418, 0x1956bdba +-0, 140625, 18432, 0x2eae0b34 ++0, 140625, 18432, 0xa55159d3 + 1, 141061, 418, 0x3e18bd55 + 1, 143412, 418, 0xe4cfc339 + 1, 145763, 418, 0xb426c835 +-0, 146250, 18432, 0x2eae0b34 ++0, 146250, 18432, 0xa55159d3 + 1, 148114, 418, 0xd7b6cbcf + 1, 150465, 418, 0x340ec315 +-0, 151875, 18432, 0x2eae0b34 ++0, 151875, 18432, 0xa55159d3 + 1, 152816, 418, 0x23a9baec + 1, 155167, 418, 0x9f04cd01 +-0, 157500, 18432, 0x2eae0b34 ++0, 157500, 18432, 0xa55159d3 + 1, 157518, 418, 0xa80ec223 + 1, 159869, 418, 0x23d6bd5d + 1, 162220, 418, 0xcb25cf5b +-0, 163125, 18432, 0x2eae0b34 ++0, 163125, 18432, 0xa55159d3 + 1, 164571, 418, 0xccccc217 + 1, 166922, 418, 0x757abbfe +-0, 168750, 18432, 0x2eae0b34 ++0, 168750, 18432, 0xa55159d3 + 1, 169273, 418, 0xa2e6cc68 + 1, 171624, 418, 0xdf77cc05 + 1, 173976, 417, 0xe9d2c5d5 +-0, 174375, 18432, 0x2eae0b34 ++0, 174375, 18432, 0xa55159d3 + 1, 176327, 418, 0x50dec174 + 1, 178678, 418, 0xf654b27e +-0, 180000, 18432, 0x2c180ac8 ++0, 180000, 18432, 0x8944596a + 1, 181029, 418, 0x4d8bc26e + 1, 183380, 418, 0xccd2bf37 +-0, 185625, 18432, 0x2eae0b34 ++0, 185625, 18432, 0xa55159d3 + 1, 185731, 418, 0x6ce2c18a + 1, 188082, 418, 0xb3cdcf0c + 1, 190433, 418, 0x55eebe9a +-0, 191250, 18432, 0x2c180ac8 ++0, 191250, 18432, 0x8944596a + 1, 192784, 418, 0x9031c9ec + 1, 195135, 418, 0xb037c49d +-0, 196875, 18432, 0x2eae0b34 ++0, 196875, 18432, 0xa55159d3 + 1, 197486, 418, 0x377bcc78 + 1, 199837, 418, 0x3762c725 + 1, 202188, 418, 0x39afbd4d +-0, 202500, 18432, 0x2c180ac8 ++0, 202500, 18432, 0x8944596a + 1, 204539, 418, 0x655ed6cd + 1, 206890, 418, 0x09aec202 +-0, 208125, 18432, 0x2eae0b34 ++0, 208125, 18432, 0xa55159d3 + 1, 209241, 418, 0xf2d2ce55 + 1, 211592, 418, 0x254ebf04 +-0, 213750, 18432, 0x2c180ac8 ++0, 213750, 18432, 0x8944596a + 1, 213943, 418, 0xa105cdcc + 1, 216294, 418, 0x1477ba58 + 1, 218645, 418, 0x8d0dcdb2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/nuv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/nuv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/nuv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/nuv 2012-05-14 14:08:55.687367212 +0200 +@@ -1,30 +1,27 @@ +-1, 0, 4096, 0x00000000 + 0, 0, 460800, 0x54aedafe ++1, 0, 4096, 0x00000000 + 1, 2090, 4096, 0x4dfae7a6 +-0, 3003, 460800, 0x54aedafe ++0, 3003, 460800, 0xb7aa8b56 + 1, 4180, 4096, 0x3fd9f5c6 +-0, 6006, 460800, 0x54aedafe ++0, 6006, 460800, 0x283ea3b5 + 1, 6269, 4096, 0x7b86e310 + 1, 8359, 4096, 0x611cece5 +-0, 9009, 460800, 0x54aedafe ++0, 9009, 460800, 0x283ea3b5 + 1, 10449, 4096, 0xb7d8e872 +-0, 12012, 460800, 0xb7aa8b56 ++0, 12012, 460800, 0x10e577de + 1, 12539, 4096, 0x072ef72b + 1, 14629, 4096, 0xb3560144 +-0, 15015, 460800, 0x283ea3b5 ++0, 15015, 460800, 0x4e091ee2 + 1, 16718, 4096, 0x0a3d119e +-0, 18018, 460800, 0x283ea3b5 ++0, 18018, 460800, 0x2ea88828 + 1, 18808, 4096, 0xbe391aa4 + 1, 20898, 4096, 0x28f7c6e5 +-0, 21021, 460800, 0x10e577de ++0, 21021, 460800, 0x4b7f4df0 + 1, 22988, 4096, 0xca9d9df2 +-0, 24024, 460800, 0x4e091ee2 ++0, 24024, 460800, 0xa57f20d0 + 1, 25078, 4096, 0x5c6b95a9 +-0, 27027, 460800, 0x2ea88828 + 1, 27167, 4096, 0x0bdfc0bf + 1, 29257, 4096, 0xd95a9277 +-0, 30030, 460800, 0x4b7f4df0 + 1, 31347, 4096, 0xae2bef2c +-0, 33033, 460800, 0xb30eb322 + 1, 33437, 4096, 0xbf031e83 + 1, 35527, 4096, 0x4c83e2d1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_s16be-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_s16be-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_s16be-stereo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_s16be-stereo 2012-05-14 14:08:55.688367232 +0200 +@@ -0,0 +1 @@ ++f0c0fd7615cdef66fa72f5816632ca9b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_s16le-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_s16le-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_s16le-stereo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_s16le-stereo 2012-05-14 14:08:55.688367232 +0200 +@@ -0,0 +1 @@ ++0262b20b728f5bb95594e64e2173b2f2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_u8-mono xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_u8-mono +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_u8-mono 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_u8-mono 2012-05-14 14:08:55.689367252 +0200 +@@ -0,0 +1 @@ ++c2dcec9b230dad733b6b877fbed36755 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_u8-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_u8-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pcm_u8-stereo 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pcm_u8-stereo 2012-05-14 14:08:55.689367252 +0200 +@@ -0,0 +1 @@ ++973cf68365c3d58ff60ba652433b3bd2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pictor xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pictor +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/pictor 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/pictor 2012-05-14 14:08:55.690367273 +0200 +@@ -1 +1 @@ +-0, 0, 192816, 0xf97e2ba1 ++0, 0, 192816, 0x29b9c158 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422 2012-05-14 14:08:55.690367273 +0200 +@@ -0,0 +1,2 @@ ++0, 0, 8294400, 0xe8e9d448 ++0, 3003, 8294400, 0xe8e9d448 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_hq xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_hq +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_hq 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_hq 2012-05-14 14:08:55.691367293 +0200 +@@ -0,0 +1,2 @@ ++0, 0, 8294400, 0x817063b0 ++0, 3003, 8294400, 0x817063b0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_lt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_lt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_lt 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_lt 2012-05-14 14:08:55.691367293 +0200 +@@ -0,0 +1,2 @@ ++0, 0, 8294400, 0xcd4ccde1 ++0, 3003, 8294400, 0xcd4ccde1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_proxy xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_proxy +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-422_proxy 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-422_proxy 2012-05-14 14:08:55.692367313 +0200 +@@ -0,0 +1,2 @@ ++0, 0, 8294400, 0x51d29320 ++0, 3003, 8294400, 0x51d29320 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-alpha xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-alpha +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/prores-alpha 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/prores-alpha 2012-05-14 14:08:55.692367313 +0200 +@@ -0,0 +1,2 @@ ++0, 0, 12441600, 0x254d8f95 ++0, 3003, 12441600, 0x254d8f95 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str 2012-05-14 14:08:55.693367333 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 8064, 0x02260037 + 0, 0, 115200, 0x6b106a56 ++1, 0, 8064, 0x02260037 + 1, 4800, 8064, 0x4ee9f4e9 + 0, 6000, 115200, 0x53c16930 + 1, 9600, 8064, 0xf8fd82aa +@@ -7,8 +7,8 @@ + 1, 14400, 8064, 0xc100792b + 0, 18000, 115200, 0xc3c18ba0 + 1, 19200, 8064, 0xf11a5316 +-1, 24000, 8064, 0x6937f8c0 + 0, 24000, 115200, 0xe281b655 ++1, 24000, 8064, 0x6937f8c0 + 1, 28800, 8064, 0xed194e42 + 0, 30000, 115200, 0x7b1e0536 + 1, 33600, 8064, 0x619ce54b +@@ -16,8 +16,8 @@ + 1, 38400, 8064, 0x544999ec + 0, 42000, 115200, 0xfc67bf8e + 1, 43200, 8064, 0x0ea877b4 +-1, 48000, 8064, 0xb764d1c0 + 0, 48000, 115200, 0xb463151c ++1, 48000, 8064, 0xb764d1c0 + 1, 52800, 8064, 0x7a2fd211 + 0, 54000, 115200, 0x6e686846 + 1, 57600, 8064, 0xff69f6c5 +@@ -25,8 +25,8 @@ + 1, 62400, 8064, 0x26c11ec7 + 0, 66000, 115200, 0x17b91efc + 1, 67200, 8064, 0xfb4ecc0c +-1, 72000, 8064, 0x111d799b + 0, 72000, 115200, 0xc051a49a ++1, 72000, 8064, 0x111d799b + 1, 76800, 8064, 0xc704dc91 + 0, 78000, 115200, 0xc68c227b + 1, 81600, 8064, 0xa9f372fb +@@ -34,8 +34,8 @@ + 1, 86400, 8064, 0xa3f0ad0f + 0, 90000, 115200, 0x09d56ecc + 1, 91200, 8064, 0x958719b9 +-1, 96000, 8064, 0x9b011bf7 + 0, 96000, 115200, 0xc20e3485 ++1, 96000, 8064, 0x9b011bf7 + 1, 100800, 8064, 0x466d96fb + 0, 102000, 115200, 0xf07e2c48 + 1, 105600, 8064, 0x6ed4eb29 +@@ -43,8 +43,8 @@ + 1, 110400, 8064, 0x066966db + 0, 114000, 115200, 0xed65bacd + 1, 115200, 8064, 0xf60fe0bc +-1, 120000, 8064, 0x2c845167 + 0, 120000, 115200, 0x51a23a3b ++1, 120000, 8064, 0x2c845167 + 1, 124800, 8064, 0x7d63894f + 0, 126000, 115200, 0x559ddce1 + 1, 129600, 8064, 0x0682ee36 +@@ -52,8 +52,8 @@ + 1, 134400, 8064, 0xcaeb7c70 + 0, 138000, 115200, 0x11b2dece + 1, 139200, 8064, 0x93948697 +-1, 144000, 8064, 0x5805f0d6 + 0, 144000, 115200, 0x851b877c ++1, 144000, 8064, 0x5805f0d6 + 1, 148800, 8064, 0xcfb641ff + 0, 150000, 115200, 0x5f9a7c99 + 1, 153600, 8064, 0xe3499bb1 +@@ -61,8 +61,8 @@ + 1, 158400, 8064, 0x689fe483 + 0, 162000, 115200, 0x950b0de8 + 1, 163200, 8064, 0x1b8f2f2d +-1, 168000, 8064, 0x23852e71 + 0, 168000, 115200, 0x6ec4c89a ++1, 168000, 8064, 0x23852e71 + 1, 172800, 8064, 0x15e7b298 + 0, 174000, 115200, 0xa9234812 + 1, 177600, 8064, 0x5345a9a3 +@@ -70,8 +70,8 @@ + 1, 182400, 8064, 0x257b6ecf + 0, 186000, 115200, 0x2cc1a2aa + 1, 187200, 8064, 0xaf62836c +-1, 192000, 8064, 0xc3a401e3 + 0, 192000, 115200, 0x5df53b71 ++1, 192000, 8064, 0xc3a401e3 + 1, 196800, 8064, 0x2b98fdf1 + 0, 198000, 115200, 0xe1d0cb31 + 1, 201600, 8064, 0x37168697 +@@ -79,8 +79,8 @@ + 1, 206400, 8064, 0x2d876c89 + 0, 210000, 115200, 0x9342d739 + 1, 211200, 8064, 0xc40a6ada +-1, 216000, 8064, 0xcca6b829 + 0, 216000, 115200, 0x586bc658 ++1, 216000, 8064, 0xcca6b829 + 1, 220800, 8064, 0x6667550a + 0, 222000, 115200, 0x76902834 + 1, 225600, 8064, 0x99c1b5cb +@@ -88,8 +88,8 @@ + 1, 230400, 8064, 0xc05d3ed3 + 0, 234000, 115200, 0xce8c95fb + 1, 235200, 8064, 0xdd641781 +-1, 240000, 8064, 0xa65d49dc + 0, 240000, 115200, 0xdf0d3de6 ++1, 240000, 8064, 0xa65d49dc + 1, 244800, 8064, 0x2a0d5df7 + 0, 246000, 115200, 0x120db7ae + 1, 249600, 8064, 0xa6348438 +@@ -97,8 +97,8 @@ + 1, 254400, 8064, 0xf2e1412d + 0, 258000, 115200, 0x2498d3b6 + 1, 259200, 8064, 0xc41c6a7a +-1, 264000, 8064, 0x147edc3d + 0, 264000, 115200, 0x99975ff8 ++1, 264000, 8064, 0x147edc3d + 1, 268800, 8064, 0x17e3cfe7 + 0, 270000, 115200, 0xbad65f9f + 1, 273600, 8064, 0x01fe3969 +@@ -106,8 +106,8 @@ + 1, 278400, 8064, 0xc437ac11 + 0, 282000, 115200, 0x6f8a61a0 + 1, 283200, 8064, 0xbbf747c1 +-1, 288000, 8064, 0x2a4b88c0 + 0, 288000, 115200, 0x80c96143 ++1, 288000, 8064, 0x2a4b88c0 + 1, 292800, 8064, 0xcd149c80 + 0, 294000, 115200, 0x663c6198 + 1, 297600, 8064, 0xcf339dfc +@@ -115,8 +115,8 @@ + 1, 302400, 8064, 0xc81ff84b + 0, 306000, 115200, 0xfe186346 + 1, 307200, 8064, 0x4d978100 +-1, 312000, 8064, 0x6da6665b + 0, 312000, 115200, 0x844962f8 ++1, 312000, 8064, 0x6da6665b + 1, 316800, 8064, 0x12fa354f + 0, 318000, 115200, 0x917c672f + 1, 321600, 8064, 0x6baedae6 +@@ -124,8 +124,8 @@ + 1, 326400, 8064, 0xddd77327 + 0, 330000, 115200, 0xace06816 + 1, 331200, 8064, 0x0a31c118 +-1, 336000, 8064, 0x7652ee6e + 0, 336000, 115200, 0x4ef26aa2 ++1, 336000, 8064, 0x7652ee6e + 1, 340800, 8064, 0x486a24cc + 0, 342000, 115200, 0xf2046bb3 + 1, 345600, 8064, 0xf6cf01ee +@@ -133,8 +133,8 @@ + 1, 350400, 8064, 0x2a19e830 + 0, 354000, 115200, 0x8a17716d + 1, 355200, 8064, 0xde675a31 +-1, 360000, 8064, 0xeefcc9af + 0, 360000, 115200, 0x36127568 ++1, 360000, 8064, 0xeefcc9af + 1, 364800, 8064, 0xaec4c989 + 0, 366000, 115200, 0x3e877b5c + 1, 369600, 8064, 0x16b73de9 +@@ -142,8 +142,8 @@ + 1, 374400, 8064, 0x188a582a + 0, 378000, 115200, 0x41bc8a39 + 1, 379200, 8064, 0xc092e73d +-1, 384000, 8064, 0xf7ebca97 + 0, 384000, 115200, 0x6f839446 ++1, 384000, 8064, 0xf7ebca97 + 1, 388800, 8064, 0x170ce07a + 0, 390000, 115200, 0xef74a005 + 1, 393600, 8064, 0xa0705384 +@@ -151,8 +151,8 @@ + 1, 398400, 8064, 0xd0154a3c + 0, 402000, 115200, 0x4607cf99 + 1, 403200, 8064, 0x57c73c6c +-1, 408000, 8064, 0x590c9ddb + 0, 408000, 115200, 0x4c18e8db ++1, 408000, 8064, 0x590c9ddb + 1, 412800, 8064, 0x2cbe552f + 0, 414000, 115200, 0x04d71efb + 1, 417600, 8064, 0x0d286932 +@@ -160,8 +160,8 @@ + 1, 422400, 8064, 0x5931cea3 + 0, 426000, 115200, 0x4dd48d01 + 1, 427200, 8064, 0xaf0fb80d +-1, 432000, 8064, 0x7fb61e9b + 0, 432000, 115200, 0x5fa9627f ++1, 432000, 8064, 0x7fb61e9b + 1, 436800, 8064, 0xf17134bb + 0, 438000, 115200, 0x7a413f88 + 1, 441600, 8064, 0xd647859a +@@ -169,8 +169,8 @@ + 1, 446400, 8064, 0x55a60921 + 0, 450000, 115200, 0x3d720e05 + 1, 451200, 8064, 0x3811fa58 +-1, 456000, 8064, 0xaceeccea + 0, 456000, 115200, 0x49243fd8 ++1, 456000, 8064, 0xaceeccea + 1, 460800, 8064, 0x5fcedf14 + 0, 462000, 115200, 0x9834b697 + 1, 465600, 8064, 0xd8c64abf +@@ -178,8 +178,8 @@ + 1, 470400, 8064, 0x79495e8d + 0, 474000, 115200, 0x3eaf5504 + 1, 475200, 8064, 0x4b7db039 +-1, 480000, 8064, 0x7152f86d + 0, 480000, 115200, 0x057a3701 ++1, 480000, 8064, 0x7152f86d + 1, 484800, 8064, 0xd92cfc1a + 0, 486000, 115200, 0x6e88f21a + 1, 489600, 8064, 0x75c540ef +@@ -187,8 +187,8 @@ + 1, 494400, 8064, 0x9c03ef5e + 0, 498000, 115200, 0x92212d84 + 1, 499200, 8064, 0x7b2911c8 +-1, 504000, 8064, 0x69d9d553 + 0, 504000, 115200, 0xf6b0a4ff ++1, 504000, 8064, 0x69d9d553 + 1, 508800, 8064, 0xcb45d7c5 + 0, 510000, 115200, 0xb49e9b4e + 1, 513600, 8064, 0x37ec8b0a +@@ -196,5 +196,5 @@ + 1, 518400, 8064, 0xe4354221 + 0, 522000, 115200, 0x65f3339a + 1, 523200, 8064, 0xc0d91cdb +-1, 528000, 8064, 0xea0be175 + 0, 528000, 115200, 0x38e40a20 ++1, 528000, 8064, 0xea0be175 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str-v3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str-v3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str-v3 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str-v3 1970-01-01 01:00:00.000000000 +0100 +@@ -1,96 +0,0 @@ +-0, 0, 76800, 0x2677be82 +-1, 0, 8064, 0xa307ed8c +-1, 4800, 8064, 0xd2551927 +-0, 6000, 76800, 0x1f323c75 +-1, 9600, 8064, 0x3264a799 +-0, 12000, 76800, 0xc8be3be9 +-1, 14400, 8064, 0x75da1393 +-0, 18000, 76800, 0x1f323c75 +-1, 19200, 8064, 0x68665f59 +-0, 24000, 76800, 0x7e484488 +-1, 24000, 8064, 0xaf266a18 +-1, 28800, 8064, 0x4d4b69fd +-0, 30000, 76800, 0x8bd644aa +-1, 33600, 8064, 0x129d7e17 +-0, 36000, 76800, 0xaa62e7b8 +-1, 38400, 8064, 0x78c56725 +-0, 42000, 76800, 0xaa62e7b8 +-1, 43200, 8064, 0x59902cf1 +-0, 48000, 76800, 0x53fadb39 +-1, 48000, 8064, 0x6e699c87 +-1, 52800, 8064, 0xc30692d7 +-0, 54000, 76800, 0x53fadb39 +-1, 57600, 8064, 0x29c043e5 +-0, 60000, 76800, 0x1ff9d964 +-1, 62400, 8064, 0x61907704 +-0, 66000, 76800, 0x1ff9d964 +-1, 67200, 8064, 0xf9210630 +-0, 72000, 76800, 0xd8c8d947 +-1, 72000, 8064, 0xc0bdda08 +-1, 76800, 8064, 0x6171b96d +-0, 78000, 76800, 0xd8c8d947 +-1, 81600, 8064, 0x082947cf +-0, 84000, 76800, 0x6d0bd94c +-1, 86400, 8064, 0xf7bbf1ce +-0, 90000, 76800, 0x6d0bd94c +-1, 91200, 8064, 0xe50e4436 +-0, 96000, 76800, 0x7e66d948 +-1, 96000, 8064, 0x2a860844 +-1, 100800, 8064, 0xedcb502c +-0, 102000, 76800, 0x7e66d948 +-1, 105600, 8064, 0x448e3c7f +-0, 108000, 76800, 0x8eecfd72 +-1, 110400, 8064, 0xf782f366 +-0, 114000, 76800, 0xb15f29ab +-1, 115200, 8064, 0xf57f66a5 +-0, 120000, 76800, 0x08e5502e +-1, 120000, 8064, 0xdcc36939 +-1, 124800, 8064, 0x34959d99 +-0, 126000, 76800, 0xaa58796d +-1, 129600, 8064, 0xa5c20433 +-0, 132000, 76800, 0xe254a27c +-1, 134400, 8064, 0xf1364e9b +-0, 138000, 76800, 0xeec8cf68 +-1, 139200, 8064, 0x232fe9c7 +-0, 144000, 76800, 0x812bf8ee +-1, 144000, 8064, 0xdc068d5a +-1, 148800, 8064, 0x4962e812 +-0, 150000, 76800, 0x929922ef +-1, 153600, 8064, 0x36a6709b +-0, 156000, 76800, 0xe1174e06 +-1, 158400, 8064, 0xa2837bd8 +-0, 162000, 76800, 0x2da77bf1 +-1, 163200, 8064, 0x68612ddb +-0, 168000, 76800, 0xd0f6a727 +-1, 168000, 8064, 0x8d76d1cb +-1, 172800, 8064, 0x7707cfc7 +-0, 174000, 76800, 0x31bfd168 +-0, 180000, 76800, 0xb87af225 +-0, 186000, 76800, 0xd0080859 +-0, 192000, 76800, 0x99ab15ba +-0, 198000, 76800, 0x99ab15ba +-0, 204000, 76800, 0x99ab15ba +-0, 210000, 76800, 0x99ab15ba +-0, 216000, 76800, 0x99ab15ba +-0, 222000, 76800, 0x99ab15ba +-0, 228000, 76800, 0x99ab15ba +-0, 234000, 76800, 0x99ab15ba +-0, 240000, 76800, 0x99ab15ba +-0, 246000, 76800, 0x99ab15ba +-0, 252000, 76800, 0x99ab15ba +-0, 258000, 76800, 0x99ab15ba +-0, 264000, 76800, 0x99ab15ba +-0, 270000, 76800, 0x99ab15ba +-0, 276000, 76800, 0x99ab15ba +-0, 282000, 76800, 0x99ab15ba +-0, 288000, 76800, 0x0c1617d5 +-0, 294000, 76800, 0xb1c81b5d +-0, 300000, 76800, 0xb4e41e44 +-0, 306000, 76800, 0x765725e2 +-0, 312000, 76800, 0x25cd3109 +-0, 318000, 76800, 0xa42b5291 +-0, 324000, 76800, 0x15bb6ee4 +-0, 330000, 76800, 0xb33c9f50 +-0, 336000, 76800, 0x1ca1b874 +-0, 342000, 76800, 0x7506e92a +-0, 348000, 76800, 0x97c9030a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str-v3-mdec xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str-v3-mdec +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/psx-str-v3-mdec 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/psx-str-v3-mdec 2012-05-14 14:08:55.694367353 +0200 +@@ -0,0 +1,59 @@ ++0, 0, 76800, 0x2677be82 ++0, 6000, 76800, 0x1f323c75 ++0, 12000, 76800, 0xc8be3be9 ++0, 18000, 76800, 0x1f323c75 ++0, 24000, 76800, 0x7e484488 ++0, 30000, 76800, 0x8bd644aa ++0, 36000, 76800, 0xaa62e7b8 ++0, 42000, 76800, 0xaa62e7b8 ++0, 48000, 76800, 0x53fadb39 ++0, 54000, 76800, 0x53fadb39 ++0, 60000, 76800, 0x1ff9d964 ++0, 66000, 76800, 0x1ff9d964 ++0, 72000, 76800, 0xd8c8d947 ++0, 78000, 76800, 0xd8c8d947 ++0, 84000, 76800, 0x6d0bd94c ++0, 90000, 76800, 0x6d0bd94c ++0, 96000, 76800, 0x7e66d948 ++0, 102000, 76800, 0x7e66d948 ++0, 108000, 76800, 0x8eecfd72 ++0, 114000, 76800, 0xb15f29ab ++0, 120000, 76800, 0x08e5502e ++0, 126000, 76800, 0xaa58796d ++0, 132000, 76800, 0xe254a27c ++0, 138000, 76800, 0xeec8cf68 ++0, 144000, 76800, 0x812bf8ee ++0, 150000, 76800, 0x929922ef ++0, 156000, 76800, 0xe1174e06 ++0, 162000, 76800, 0x2da77bf1 ++0, 168000, 76800, 0xd0f6a727 ++0, 174000, 76800, 0x31bfd168 ++0, 180000, 76800, 0xb87af225 ++0, 186000, 76800, 0xd0080859 ++0, 192000, 76800, 0x99ab15ba ++0, 198000, 76800, 0x99ab15ba ++0, 204000, 76800, 0x99ab15ba ++0, 210000, 76800, 0x99ab15ba ++0, 216000, 76800, 0x99ab15ba ++0, 222000, 76800, 0x99ab15ba ++0, 228000, 76800, 0x99ab15ba ++0, 234000, 76800, 0x99ab15ba ++0, 240000, 76800, 0x99ab15ba ++0, 246000, 76800, 0x99ab15ba ++0, 252000, 76800, 0x99ab15ba ++0, 258000, 76800, 0x99ab15ba ++0, 264000, 76800, 0x99ab15ba ++0, 270000, 76800, 0x99ab15ba ++0, 276000, 76800, 0x99ab15ba ++0, 282000, 76800, 0x99ab15ba ++0, 288000, 76800, 0x0c1617d5 ++0, 294000, 76800, 0xb1c81b5d ++0, 300000, 76800, 0xb4e41e44 ++0, 306000, 76800, 0x765725e2 ++0, 312000, 76800, 0x25cd3109 ++0, 318000, 76800, 0xa42b5291 ++0, 324000, 76800, 0x15bb6ee4 ++0, 330000, 76800, 0xb33c9f50 ++0, 336000, 76800, 0x1ca1b874 ++0, 342000, 76800, 0x7506e92a ++0, 348000, 76800, 0x97c9030a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ptx xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ptx +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/ptx 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/ptx 2012-05-14 14:08:55.695367373 +0200 +@@ -1 +1 @@ +-0, 0, 393216, 0xda280efc ++0, 0, 393216, 0x019d9950 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-ima4-mono xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-ima4-mono +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-ima4-mono 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-ima4-mono 2012-05-14 14:08:55.695367373 +0200 +@@ -1 +1 @@ +-721b51fd66c3bb3dc49dd88d404188eb ++e178ed520edf2f46492ae740d88f5815 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-ima4-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-ima4-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-ima4-stereo 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-ima4-stereo 2012-05-14 14:08:55.696367393 +0200 +@@ -1 +1 @@ +-c9e4c21fb62eca34a533f3a9ad2e394a ++d22be0e193dcbba1068a1ca6ab04cf77 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-msadpcm-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-msadpcm-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-msadpcm-stereo 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-msadpcm-stereo 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-3b7554e9a186c30adfd2a86bae950f4a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-msimaadpcm-stereo xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-msimaadpcm-stereo +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-msimaadpcm-stereo 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-msimaadpcm-stereo 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-1ee96f1efc09251a732621049dc5b66e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-be 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-be 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-f0c0fd7615cdef66fa72f5816632ca9b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-16bit-stereo-signed-le 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-0262b20b728f5bb95594e64e2173b2f2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-mono-unsigned xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-mono-unsigned +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-mono-unsigned 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-mono-unsigned 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-c2dcec9b230dad733b6b877fbed36755 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-stereo-unsigned xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-stereo-unsigned +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-stereo-unsigned 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qt-rawpcm-8bit-stereo-unsigned 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-973cf68365c3d58ff60ba652433b3bd2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qtrle-16bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qtrle-16bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qtrle-16bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qtrle-16bit 2012-05-14 14:08:55.699367454 +0200 +@@ -1,83 +1,83 @@ +-0, 0, 57600, 0xe6b0a48c +-0, 6000, 57600, 0xe064d51c +-0, 12000, 57600, 0xbfce6b33 +-0, 18000, 57600, 0x371bab02 +-0, 24000, 57600, 0x0d2d7456 +-0, 30000, 57600, 0x9184eecb +-0, 36000, 57600, 0xb482e8db +-0, 42000, 57600, 0x0f4cd4be +-0, 48000, 57600, 0xe276cccb +-0, 54000, 57600, 0x04c21c62 +-0, 60000, 57600, 0x848960a2 +-0, 66000, 57600, 0xc4c8cf03 +-0, 72000, 57600, 0xb4094866 +-0, 78000, 57600, 0xf22da043 +-0, 84000, 57600, 0x6517b67b +-0, 90000, 57600, 0x23e39ccb +-0, 96000, 57600, 0x41525ca3 +-0, 102000, 57600, 0xc3edc5f3 +-0, 108000, 57600, 0x8ce81c7e +-0, 114000, 57600, 0x56829443 +-0, 120000, 57600, 0x511ce287 +-0, 126000, 57600, 0x8f029a5b +-0, 132000, 57600, 0x2b47cf43 +-0, 138000, 57600, 0x8e7ecf4b +-0, 144000, 57600, 0xd620317e +-0, 150000, 57600, 0x5987646e +-0, 156000, 57600, 0xcfedb7df +-0, 162000, 57600, 0x33746e7b +-0, 168000, 57600, 0x1d318573 +-0, 174000, 57600, 0xc851848b +-0, 180000, 57600, 0x939db1d7 +-0, 186000, 57600, 0x1719aed3 +-0, 192000, 57600, 0x1ba3e18c +-0, 198000, 57600, 0x04f355fb +-0, 204000, 57600, 0x6fafd5f4 +-0, 210000, 57600, 0x434f800b +-0, 216000, 57600, 0xed42179b +-0, 222000, 57600, 0x3b33118b +-0, 228000, 57600, 0xf81880cb +-0, 234000, 57600, 0xd2c58e1b +-0, 240000, 57600, 0xd96f50eb +-0, 246000, 57600, 0x64ef63fb +-0, 252000, 57600, 0x7b14b6fc +-0, 258000, 57600, 0xeb1c9054 +-0, 264000, 57600, 0x3b30c97c +-0, 270000, 57600, 0xc93e9484 +-0, 276000, 57600, 0xe012c0cc +-0, 282000, 57600, 0x48e2dda4 +-0, 288000, 57600, 0x13eb55fb +-0, 294000, 57600, 0xa5edbedc +-0, 300000, 57600, 0x0123a484 +-0, 306000, 57600, 0xc624a7ac +-0, 312000, 57600, 0xd83cf45c +-0, 318000, 57600, 0x8f9bf4b4 +-0, 324000, 57600, 0x2d494b8c +-0, 330000, 57600, 0xb246f07c +-0, 336000, 57600, 0x5750e67c +-0, 342000, 57600, 0x6643e9ac +-0, 348000, 57600, 0x8d3b86b3 +-0, 354000, 57600, 0x4bb0546b +-0, 360000, 57600, 0xfe439333 +-0, 366000, 57600, 0x0cc76233 +-0, 372000, 57600, 0xb6fe40ae +-0, 378000, 57600, 0xf79fe0d7 +-0, 384000, 57600, 0xdc90dcbb +-0, 390000, 57600, 0x371e7c2b +-0, 396000, 57600, 0x7c4590bb +-0, 402000, 57600, 0x66f5454b +-0, 408000, 57600, 0x1678ae5b +-0, 414000, 57600, 0x1ee8fdec +-0, 420000, 57600, 0x98d2a083 +-0, 426000, 57600, 0x86d29e5b +-0, 432000, 57600, 0x23d2bc83 +-0, 438000, 57600, 0x3fc729f2 +-0, 444000, 57600, 0x821d61da +-0, 450000, 57600, 0xdd549e0e +-0, 456000, 57600, 0x641234e2 +-0, 462000, 57600, 0x9a282112 +-0, 468000, 57600, 0x6587e2fb +-0, 474000, 57600, 0x043d0cb2 +-0, 480000, 57600, 0x90328707 +-0, 486000, 57600, 0x5744d313 +-0, 492000, 57600, 0x6e1b95cb ++0, 0, 57600, 0xcf2d39fc ++0, 6000, 57600, 0xfc9f6bed ++0, 12000, 57600, 0x3f5805bb ++0, 18000, 57600, 0xcb34504e ++0, 24000, 57600, 0x66b6f6e9 ++0, 30000, 57600, 0x18698e4d ++0, 36000, 57600, 0x233288d7 ++0, 42000, 57600, 0x6b195ac5 ++0, 48000, 57600, 0x3b466b45 ++0, 54000, 57600, 0x9e3dbd75 ++0, 60000, 57600, 0x90ee04b7 ++0, 66000, 57600, 0x81096dda ++0, 72000, 57600, 0xef24ca50 ++0, 78000, 57600, 0xea7a3da8 ++0, 84000, 57600, 0xc3f054c2 ++0, 90000, 57600, 0x34af39ec ++0, 96000, 57600, 0xfc31f846 ++0, 102000, 57600, 0xa4606399 ++0, 108000, 57600, 0x4b8a9c88 ++0, 114000, 57600, 0x87db3195 ++0, 120000, 57600, 0x443b618d ++0, 126000, 57600, 0x601e380e ++0, 132000, 57600, 0x405c6e6f ++0, 138000, 57600, 0xe6b66f29 ++0, 144000, 57600, 0xb8e4b2d1 ++0, 150000, 57600, 0x9fc8e7da ++0, 156000, 57600, 0x3bdb363b ++0, 162000, 57600, 0xacac0b6a ++0, 168000, 57600, 0xff3022fb ++0, 174000, 57600, 0x1e5721f3 ++0, 180000, 57600, 0x511a3071 ++0, 186000, 57600, 0xff6d4dc0 ++0, 192000, 57600, 0x5df97a35 ++0, 198000, 57600, 0x3877f1b1 ++0, 204000, 57600, 0xa9096dd2 ++0, 210000, 57600, 0xd36e1ccc ++0, 216000, 57600, 0xdc94b124 ++0, 222000, 57600, 0x873fab49 ++0, 228000, 57600, 0x7f081dca ++0, 234000, 57600, 0x7df52bc3 ++0, 240000, 57600, 0xf41feb99 ++0, 246000, 57600, 0xcf59ffeb ++0, 252000, 57600, 0x0dd94dfe ++0, 258000, 57600, 0xfbc52500 ++0, 264000, 57600, 0xc300606e ++0, 270000, 57600, 0x01e529b4 ++0, 276000, 57600, 0x359a57b0 ++0, 282000, 57600, 0xcfee7511 ++0, 288000, 57600, 0x2189f139 ++0, 294000, 57600, 0xcc535558 ++0, 300000, 57600, 0xeed13a76 ++0, 306000, 57600, 0xfb5c3ddd ++0, 312000, 57600, 0x36a98c53 ++0, 318000, 57600, 0xf4c38c4b ++0, 324000, 57600, 0x53d5df15 ++0, 330000, 57600, 0x336d890c ++0, 336000, 57600, 0x19967f1c ++0, 342000, 57600, 0xa36b8224 ++0, 348000, 57600, 0xf6ec2490 ++0, 354000, 57600, 0x6ffff0d1 ++0, 360000, 57600, 0xfcb73114 ++0, 366000, 57600, 0x5f5fff35 ++0, 372000, 57600, 0xf113c4a0 ++0, 378000, 57600, 0x64ca6175 ++0, 384000, 57600, 0x3f6f7d15 ++0, 390000, 57600, 0x18b619df ++0, 396000, 57600, 0xe6872ed7 ++0, 402000, 57600, 0x3641e174 ++0, 408000, 57600, 0x4c144d8c ++0, 414000, 57600, 0x82529776 ++0, 420000, 57600, 0xd96f3ead ++0, 426000, 57600, 0xce183c4e ++0, 432000, 57600, 0xaa475b24 ++0, 438000, 57600, 0xf7c5cbf3 ++0, 444000, 57600, 0x798e0548 ++0, 450000, 57600, 0x1233241a ++0, 456000, 57600, 0x1424d758 ++0, 462000, 57600, 0xa446c264 ++0, 468000, 57600, 0x66e082ae ++0, 474000, 57600, 0xb58cacc8 ++0, 480000, 57600, 0x3d86431c ++0, 486000, 57600, 0x601b724e ++0, 492000, 57600, 0xbe9a32c8 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qtrle-1bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qtrle-1bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/qtrle-1bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/qtrle-1bit 2012-05-14 14:08:55.700367474 +0200 +@@ -1,107 +1,107 @@ +-0, 0, 9600, 0xc1632102 ++0, 0, 9600, 0xc5921aa2 + 1, 0, 2040, 0x0a157db4 + 1, 4163, 2040, 0x00c63e08 +-0, 7500, 9600, 0x0f6c0521 ++0, 7500, 9600, 0x9032fc52 + 1, 8327, 2040, 0xacf2a25b + 1, 12490, 2040, 0xd6189e85 +-0, 15000, 9600, 0x04b90b5a ++0, 15000, 9600, 0x7db0038e + 1, 16653, 2040, 0x8276f843 + 1, 20816, 2040, 0xadebae73 +-0, 22500, 9600, 0x2ebd4500 ++0, 22500, 9600, 0x95b73c41 + 1, 24980, 2040, 0x5da76697 + 1, 29143, 2040, 0x469d0ea7 +-0, 30000, 9600, 0x726f46f4 ++0, 30000, 9600, 0x531e4189 + 1, 33306, 2040, 0x0d7412e1 + 1, 37469, 2040, 0x2f2cc63f +-0, 37500, 9600, 0x37f6968e ++0, 37500, 9600, 0xb73390ec + 1, 41633, 2040, 0x10106eb7 +-0, 45000, 9600, 0x7305872e ++0, 45000, 9600, 0x958e8221 + 1, 45796, 2040, 0x300124c7 + 1, 49959, 2040, 0xa329f8e8 +-0, 52500, 9600, 0x222eff5e ++0, 52500, 9600, 0xd393f8a6 + 1, 54122, 2040, 0xcea35ca5 + 1, 58286, 2040, 0x55105aef +-0, 60000, 9600, 0x9317e227 ++0, 60000, 9600, 0xa085da1c + 1, 62449, 2040, 0x08980ce1 + 1, 66612, 2040, 0x367faf24 +-0, 67500, 9600, 0x421eee9d ++0, 67500, 9600, 0x57ace74f + 1, 70776, 2040, 0x75bfef06 + 1, 74939, 2040, 0x34f1daf4 +-0, 75000, 9600, 0xcbcfaaff ++0, 75000, 9600, 0x5d11a308 + 1, 79102, 2040, 0x97050317 +-0, 82500, 9600, 0xe7d43be2 ++0, 82500, 9600, 0x13e133b7 + 1, 83265, 2040, 0xd297c536 + 1, 87429, 2040, 0xa8abad5a +-0, 90000, 9600, 0x0b71e28c ++0, 90000, 9600, 0x494edb86 + 1, 91592, 2040, 0x445ce8e0 + 1, 95755, 2040, 0xa3f4d940 +-0, 97500, 9600, 0xd6a050ca ++0, 97500, 9600, 0x43a448ea + 1, 99918, 2040, 0x0ebb7b26 + 1, 104082, 2040, 0x4372f6f6 +-0, 105000, 9600, 0x0ac6dbf5 ++0, 105000, 9600, 0x3562d35b + 1, 108245, 2040, 0xd4365079 + 1, 112408, 2040, 0x56f902f7 +-0, 112500, 9600, 0x5c036038 ++0, 112500, 9600, 0x0bc655d2 + 1, 116571, 2040, 0x4153938a +-0, 120000, 9600, 0x6e417ed6 ++0, 120000, 9600, 0xbece73a1 + 1, 120735, 2040, 0x14996d86 + 1, 124898, 2040, 0x3f99c318 +-0, 127500, 9600, 0x8bd0dc22 ++0, 127500, 9600, 0x82e7cfa1 + 1, 129061, 2040, 0x939978a5 + 1, 133224, 2040, 0x7086bd44 +-0, 135000, 9600, 0xdf3b0877 ++0, 135000, 9600, 0xda29fd8f + 1, 137388, 276, 0x25b89d22 + 1, 137951, 2040, 0xf3edb106 + 1, 142114, 2040, 0x0ca61430 +-0, 142500, 9600, 0xae6e7823 ++0, 142500, 9600, 0x70fb700b + 1, 146278, 2040, 0x7229c458 +-0, 150000, 9600, 0x8ff0ac32 ++0, 150000, 9600, 0xaf57a6b0 + 1, 150441, 2040, 0xc37edd31 + 1, 154604, 2040, 0xa3da98b4 +-0, 157500, 9600, 0xa2d9e2ce ++0, 157500, 9600, 0x0a5ed9b9 + 1, 158767, 2040, 0x69704803 + 1, 162931, 2040, 0xa79bf334 +-0, 165000, 9600, 0x5fd92b65 ++0, 165000, 9600, 0xf7c62c38 + 1, 167094, 2040, 0x59d8d4c4 + 1, 171257, 2040, 0xf9ff0271 +-0, 172500, 9600, 0x81c1c824 ++0, 172500, 9600, 0x0aa2ccfd + 1, 175420, 2040, 0xc4ced9d6 + 1, 179584, 2040, 0x859f1912 +-0, 180000, 9600, 0xb8a2ace4 ++0, 180000, 9600, 0xc9adabae + 1, 183747, 2040, 0xe7955aa6 +-0, 187500, 9600, 0x65b70404 ++0, 187500, 9600, 0x67ff0aba + 1, 187910, 2040, 0x374624fd + 1, 192073, 2040, 0x52121097 +-0, 195000, 9600, 0xc5349eb2 ++0, 195000, 9600, 0xea79a465 + 1, 196237, 2040, 0x660fe645 + 1, 200400, 2040, 0xf624176a +-0, 202500, 9600, 0xf60cc2b8 ++0, 202500, 9600, 0x8928c626 + 1, 204563, 2040, 0x1f2246dd + 1, 208727, 2040, 0x940e0a32 +-0, 210000, 9600, 0x31474595 ++0, 210000, 9600, 0x8dab4111 + 1, 212890, 2040, 0x9c6d338c + 1, 217053, 2040, 0xfce0d30a +-0, 217500, 9600, 0xf602635b ++0, 217500, 9600, 0x81ef63f9 + 1, 221216, 2040, 0xd0ec9aa5 +-0, 225000, 9600, 0x873cbd87 ++0, 225000, 9600, 0xf977bc5e + 1, 225380, 2040, 0x58012141 + 1, 229543, 2040, 0xde67fc43 +-0, 232500, 9600, 0xb9793ffe ++0, 232500, 9600, 0x9e6a3f4a + 1, 233706, 2040, 0x6baa0450 + 1, 237869, 2040, 0xf4f80252 +-0, 240000, 9600, 0x42eb2831 ++0, 240000, 9600, 0x77c92865 + 1, 242033, 2040, 0x0cd47ee3 + 1, 246196, 2040, 0x129cbaa7 +-0, 247500, 9600, 0x44cc1dab ++0, 247500, 9600, 0x3915170d + 1, 250359, 2040, 0x5ef5c0a1 + 1, 254522, 2040, 0xf660baa7 +-0, 255000, 9600, 0xbdcbbb87 ++0, 255000, 9600, 0xbe19b995 + 1, 258686, 2040, 0xe48bc0a1 +-0, 262500, 9600, 0x29c22df7 ++0, 262500, 9600, 0x3e8a3077 + 1, 262849, 2040, 0xdfeabaa7 + 1, 267012, 2040, 0xed04c0a1 +-0, 270000, 9600, 0xde502ef5 ++0, 270000, 9600, 0x1331342e + 1, 271176, 2040, 0xd771baa7 + 1, 275339, 300, 0x521f24e9 + 1, 275951, 1476, 0x9b9394b1 +-0, 277500, 9600, 0xaf311aeb ++0, 277500, 9600, 0x4d692175 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/r210 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/r210 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/r210 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/r210 2012-05-14 14:08:55.700367474 +0200 +@@ -0,0 +1,3 @@ ++0, 0, 1843200, 0xbd414b93 ++0, 3003, 1843200, 0x23298f1f ++0, 6006, 1843200, 0x5a56df19 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/real-rv40 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/real-rv40 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/real-rv40 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/real-rv40 2012-05-14 14:08:55.701367494 +0200 +@@ -1,121 +1,240 @@ + 0, 0, 276480, 0x5f7a0d4f +-0, 7500, 276480, 0x5f7a0d4f +-0, 15000, 276480, 0x5f7a0d4f +-0, 22500, 276480, 0x5f7a0d4f +-0, 30000, 276480, 0x5f7a0d4f +-0, 37500, 276480, 0x5f7a0d4f +-0, 45000, 276480, 0x5f7a0d4f +-0, 52500, 276480, 0x5f7a0d4f +-0, 60000, 276480, 0x5f7a0d4f +-0, 67500, 276480, 0x5f7a0d4f +-0, 75000, 276480, 0x5f7a0d4f +-0, 82500, 276480, 0x5f7a0d4f +-0, 90000, 276480, 0x5f7a0d4f +-0, 97500, 276480, 0x5f7a0d4f +-0, 105000, 276480, 0x5f7a0d4f +-0, 112500, 276480, 0x5f7a0d4f +-0, 120000, 276480, 0x5f7a0d4f +-0, 127500, 276480, 0x5f7a0d4f +-0, 135000, 276480, 0x2d722f8a +-0, 142500, 276480, 0xebbb3c8f +-0, 150000, 276480, 0x8574c868 +-0, 157500, 276480, 0x4ec1e418 +-0, 165000, 276480, 0x95f22651 +-0, 172500, 276480, 0x071d897e +-0, 180000, 276480, 0x9f7623f9 +-0, 187500, 276480, 0x86d4dedf +-0, 195000, 276480, 0xc0a0be22 +-0, 202500, 276480, 0xc5902aec +-0, 210000, 276480, 0xe000f066 +-0, 217500, 276480, 0x0b2a48d5 +-0, 225000, 276480, 0xa1565256 +-0, 232500, 276480, 0x8de3ceb3 +-0, 240000, 276480, 0x654b564a +-0, 247500, 276480, 0xc9c57884 +-0, 255000, 276480, 0x89cdcdd4 +-0, 262500, 276480, 0x3594fe61 +-0, 270000, 276480, 0x9d082a81 +-0, 277500, 276480, 0x4e6cd0c3 +-0, 285000, 276480, 0xc129765f +-0, 292500, 276480, 0x92a04c99 +-0, 300000, 276480, 0x5ca62953 +-0, 307500, 276480, 0xb7e478aa +-0, 315000, 276480, 0x932735d5 +-0, 322500, 276480, 0xaaa2d7aa +-0, 330000, 276480, 0xd1329996 +-0, 337500, 276480, 0x6de1e34b +-0, 345000, 276480, 0x8c963c9b +-0, 352500, 276480, 0xce6eff29 +-0, 360000, 276480, 0x25412f7e +-0, 367500, 276480, 0x11a5ad85 +-0, 375000, 276480, 0x26ea3248 +-0, 382500, 276480, 0x86c35fa4 +-0, 390000, 276480, 0xa98a2d38 +-0, 397500, 276480, 0xed827333 +-0, 405000, 276480, 0x5d44a824 +-0, 412500, 276480, 0x46d54d04 +-0, 420000, 276480, 0x413fd26a +-0, 427500, 276480, 0xf0b3b71b +-0, 435000, 276480, 0x459bc06d +-0, 442500, 276480, 0x4199cd45 +-0, 450000, 276480, 0xa8d35683 +-0, 457500, 276480, 0x9a3e7de0 +-0, 465000, 276480, 0x5a30f666 +-0, 472500, 276480, 0x40152668 +-0, 480000, 276480, 0x90c4d22c +-0, 487500, 276480, 0x5cbaacc9 +-0, 495000, 276480, 0x72b658f1 +-0, 502500, 276480, 0x0ba3dcc9 +-0, 510000, 276480, 0x259ed5c1 +-0, 517500, 276480, 0x7fd73a99 +-0, 525000, 276480, 0x488980c5 +-0, 532500, 276480, 0x1d4c96a5 +-0, 540000, 276480, 0x41ced7f2 +-0, 547500, 276480, 0xd62d1837 +-0, 555000, 276480, 0xf5fd9d20 +-0, 562500, 276480, 0x2af91fda +-0, 570000, 276480, 0x38ce229d +-0, 577500, 276480, 0xf3a712c0 +-0, 585000, 276480, 0x57b111d2 +-0, 592500, 276480, 0x8556b792 +-0, 600000, 276480, 0xb32d0896 +-0, 607500, 276480, 0x923b9937 +-0, 615000, 276480, 0x0da1e7e3 +-0, 622500, 276480, 0x7f172382 +-0, 630000, 276480, 0x93622b88 +-0, 637500, 276480, 0x2599d540 +-0, 645000, 276480, 0xed20c105 +-0, 652500, 276480, 0x62ce256e +-0, 660000, 276480, 0x286a04bb +-0, 667500, 276480, 0x423f7e7c +-0, 675000, 276480, 0x21fc252a +-0, 682500, 276480, 0xf8a8e8ee +-0, 690000, 276480, 0x770d4a8d +-0, 697500, 276480, 0xaa12b6fd +-0, 705000, 276480, 0xdc7221a8 +-0, 712500, 276480, 0x487eeb30 +-0, 720000, 276480, 0x1e74f2db +-0, 727500, 276480, 0x40ae2bc3 +-0, 735000, 276480, 0x9ca9b930 +-0, 742500, 276480, 0x9fb19b0f +-0, 750000, 276480, 0x7bdf836c +-0, 757500, 276480, 0x1e607ba7 +-0, 765000, 276480, 0xbd96578b +-0, 772500, 276480, 0x2124bf07 +-0, 780000, 276480, 0x4895e27a +-0, 787500, 276480, 0x694d76e3 +-0, 795000, 276480, 0xe70df513 +-0, 802500, 276480, 0xcacafe6b +-0, 810000, 276480, 0x64087748 +-0, 817500, 276480, 0x571fda23 +-0, 825000, 276480, 0x8c86cbe9 +-0, 832500, 276480, 0xc8ea4671 +-0, 840000, 276480, 0xbfb74300 +-0, 847500, 276480, 0xbe1e3770 +-0, 855000, 276480, 0x757a0232 +-0, 862500, 276480, 0xa5f50c84 +-0, 870000, 276480, 0x6d95f808 +-0, 877500, 276480, 0xf002c5ca +-0, 885000, 276480, 0x1a2abb26 +-0, 892500, 276480, 0x6cf69bf2 +-0, 900000, 276480, 0x8f316c66 ++0, 3754, 276480, 0x5f7a0d4f ++0, 7507, 276480, 0x5f7a0d4f ++0, 11261, 276480, 0x5f7a0d4f ++0, 15015, 276480, 0x5f7a0d4f ++0, 18769, 276480, 0x5f7a0d4f ++0, 22522, 276480, 0x5f7a0d4f ++0, 26276, 276480, 0x5f7a0d4f ++0, 30030, 276480, 0x5f7a0d4f ++0, 33784, 276480, 0x5f7a0d4f ++0, 37537, 276480, 0x5f7a0d4f ++0, 41291, 276480, 0x5f7a0d4f ++0, 45045, 276480, 0x5f7a0d4f ++0, 48799, 276480, 0x5f7a0d4f ++0, 52552, 276480, 0x5f7a0d4f ++0, 56306, 276480, 0x5f7a0d4f ++0, 60060, 276480, 0x5f7a0d4f ++0, 63814, 276480, 0x5f7a0d4f ++0, 67567, 276480, 0x5f7a0d4f ++0, 71321, 276480, 0x5f7a0d4f ++0, 75075, 276480, 0x5f7a0d4f ++0, 78829, 276480, 0x5f7a0d4f ++0, 82582, 276480, 0x5f7a0d4f ++0, 86336, 276480, 0x5f7a0d4f ++0, 90090, 276480, 0x5f7a0d4f ++0, 93844, 276480, 0x5f7a0d4f ++0, 97597, 276480, 0x5f7a0d4f ++0, 101351, 276480, 0x5f7a0d4f ++0, 105105, 276480, 0x5f7a0d4f ++0, 108859, 276480, 0x5f7a0d4f ++0, 112612, 276480, 0x5f7a0d4f ++0, 116366, 276480, 0x5f7a0d4f ++0, 120120, 276480, 0x5f7a0d4f ++0, 123874, 276480, 0x75641594 ++0, 127627, 276480, 0x32ee3526 ++0, 131381, 276480, 0xcb53479a ++0, 135135, 276480, 0x7ca9658e ++0, 138889, 276480, 0x5ce39368 ++0, 142642, 276480, 0x4ec1e418 ++0, 146396, 276480, 0xb3790499 ++0, 150150, 276480, 0xa9f1506f ++0, 153904, 276480, 0x85cbc3b5 ++0, 157657, 276480, 0x377c7b46 ++0, 161411, 276480, 0x1a61d8db ++0, 165165, 276480, 0xe1de7f0a ++0, 168919, 276480, 0x756a4a2e ++0, 172672, 276480, 0xcb379547 ++0, 176426, 276480, 0xbae14484 ++0, 180180, 276480, 0x8e12331c ++0, 183934, 276480, 0x99c085be ++0, 187687, 276480, 0xe479ffed ++0, 191441, 276480, 0x99c82949 ++0, 195195, 276480, 0xac7672dd ++0, 198949, 276480, 0x1e4fae19 ++0, 202702, 276480, 0x776412ef ++0, 206456, 276480, 0x7d9b579f ++0, 210210, 276480, 0x1cd1ab29 ++0, 213964, 276480, 0x58ce0f38 ++0, 217717, 276480, 0x5ab69b27 ++0, 221471, 276480, 0x0afad610 ++0, 225225, 276480, 0x9eca3f11 ++0, 228979, 276480, 0xc3db9706 ++0, 232732, 276480, 0xc9c57884 ++0, 236486, 276480, 0xd9fbb2cf ++0, 240240, 276480, 0xdc07f3c9 ++0, 243994, 276480, 0x000b5269 ++0, 247747, 276480, 0x27ff7a5d ++0, 251501, 276480, 0xd92e2017 ++0, 255255, 276480, 0x18d4b27d ++0, 259009, 276480, 0x70647530 ++0, 262762, 276480, 0x97612c4b ++0, 266516, 276480, 0xc9d4ac78 ++0, 270270, 276480, 0x4ec4d57f ++0, 274024, 276480, 0xdf4e04d7 ++0, 277777, 276480, 0xbd98f57c ++0, 281531, 276480, 0x7247ea3e ++0, 285285, 276480, 0xa5d670ec ++0, 289039, 276480, 0x5163b29b ++0, 292792, 276480, 0x99170e64 ++0, 296546, 276480, 0x37f4c0b0 ++0, 300300, 276480, 0x7a4f2561 ++0, 304053, 276480, 0x8a4e991f ++0, 307807, 276480, 0x6a45425f ++0, 311561, 276480, 0x1f0e2bb6 ++0, 315315, 276480, 0xd75482c6 ++0, 319068, 276480, 0x7bf6b1ef ++0, 322822, 276480, 0x6de1e34b ++0, 326576, 276480, 0x4526c89b ++0, 330330, 276480, 0xf964e18e ++0, 334083, 276480, 0xdcaaa99a ++0, 337837, 276480, 0xd1e98808 ++0, 341591, 276480, 0x556b2365 ++0, 345345, 276480, 0x0cf65540 ++0, 349098, 276480, 0x6e2d524e ++0, 352852, 276480, 0x22c50a3d ++0, 356606, 276480, 0x293f19af ++0, 360360, 276480, 0xf4b1c461 ++0, 364113, 276480, 0x62b76407 ++0, 367867, 276480, 0x51e9b3eb ++0, 371621, 276480, 0x7b910bc7 ++0, 375375, 276480, 0x6dd14ca6 ++0, 379128, 276480, 0x441f7afd ++0, 382882, 276480, 0xfb01efc6 ++0, 386636, 276480, 0x4f73ccea ++0, 390390, 276480, 0x5ac8e06f ++0, 394143, 276480, 0x294bb441 ++0, 397897, 276480, 0xe04ac45e ++0, 401651, 276480, 0xa7a38d41 ++0, 405405, 276480, 0xf688a3ed ++0, 409158, 276480, 0x58f275ea ++0, 412912, 276480, 0xf0b3b71b ++0, 416666, 276480, 0x3ce773bf ++0, 420420, 276480, 0x01840548 ++0, 424173, 276480, 0x674e34e4 ++0, 427927, 276480, 0x41dda2d9 ++0, 431681, 276480, 0xc5b60838 ++0, 435435, 276480, 0x9b209f41 ++0, 439188, 276480, 0xf46ba7fb ++0, 442942, 276480, 0x28b54815 ++0, 446696, 276480, 0xb605a933 ++0, 450450, 276480, 0x34484aff ++0, 454203, 276480, 0xaf2b5d89 ++0, 457957, 276480, 0x8facba58 ++0, 461711, 276480, 0xbbe3e99f ++0, 465465, 276480, 0x02162c7c ++0, 469218, 276480, 0x28a63236 ++0, 472972, 276480, 0x1ad43fd7 ++0, 476726, 276480, 0xe37883e5 ++0, 480480, 276480, 0x2b8a89c5 ++0, 484233, 276480, 0x71507bd2 ++0, 487987, 276480, 0x35626022 ++0, 491741, 276480, 0x461fc3e7 ++0, 495495, 276480, 0xce5af1ec ++0, 499248, 276480, 0x7c1139b3 ++0, 503002, 276480, 0x7fd73a99 ++0, 506756, 276480, 0x4ae4c3a6 ++0, 510510, 276480, 0xcb60725a ++0, 514263, 276480, 0xb52e1aa2 ++0, 518017, 276480, 0xd6f82cae ++0, 521771, 276480, 0x6310e665 ++0, 525525, 276480, 0xfa88a483 ++0, 529278, 276480, 0xf88f75d4 ++0, 533032, 276480, 0x04a8e3ee ++0, 536786, 276480, 0x54766a12 ++0, 540540, 276480, 0x0b41f0d7 ++0, 544293, 276480, 0xa29f5b01 ++0, 548047, 276480, 0x754ceaf5 ++0, 551801, 276480, 0x150c0423 ++0, 555555, 276480, 0xde084059 ++0, 559308, 276480, 0x5a38b4af ++0, 563062, 276480, 0xfcebc261 ++0, 566816, 276480, 0x0eb9770d ++0, 570570, 276480, 0x046394ae ++0, 574323, 276480, 0x3d3ca985 ++0, 578077, 276480, 0x94a03c75 ++0, 581831, 276480, 0x800eea2d ++0, 585585, 276480, 0x6a841f41 ++0, 589338, 276480, 0x2f98911c ++0, 593092, 276480, 0x923b9937 ++0, 596846, 276480, 0xe82f8e0f ++0, 600600, 276480, 0xee82d657 ++0, 604353, 276480, 0xefab7ffd ++0, 608107, 276480, 0x6b9fbc80 ++0, 611861, 276480, 0x4a1ada47 ++0, 615614, 276480, 0x6d4b49d7 ++0, 619368, 276480, 0xe4bdbd1e ++0, 623122, 276480, 0x225a56c0 ++0, 626876, 276480, 0xd4adadad ++0, 630629, 276480, 0xff4e1a8c ++0, 634383, 276480, 0xf58b1b7c ++0, 638137, 276480, 0xbaffcdcc ++0, 641891, 276480, 0x374f88f0 ++0, 645644, 276480, 0x3d861ae6 ++0, 649398, 276480, 0xeb6eb88f ++0, 653152, 276480, 0xdb753d35 ++0, 656906, 276480, 0x9aa543af ++0, 660659, 276480, 0xb24c8016 ++0, 664413, 276480, 0xea80a82e ++0, 668167, 276480, 0x2aae902a ++0, 671921, 276480, 0x5bba3cfb ++0, 675674, 276480, 0x5c6e97a9 ++0, 679428, 276480, 0x9b9ee961 ++0, 683182, 276480, 0xaa12b6fd ++0, 686936, 276480, 0xe9d2439f ++0, 690689, 276480, 0xbf09053c ++0, 694443, 276480, 0x50c31e73 ++0, 698197, 276480, 0xdd9fb89f ++0, 701951, 276480, 0x3e4e5aec ++0, 705704, 276480, 0x0b752d28 ++0, 709458, 276480, 0xaf82399a ++0, 713212, 276480, 0x7ce5f23c ++0, 716966, 276480, 0xad135d0f ++0, 720719, 276480, 0x55dadd30 ++0, 724473, 276480, 0x5aaa7519 ++0, 728227, 276480, 0xe45a5599 ++0, 731981, 276480, 0xc8e89913 ++0, 735734, 276480, 0x2f447fd3 ++0, 739488, 276480, 0x704411fb ++0, 743242, 276480, 0x9d7430a1 ++0, 746996, 276480, 0x24dd5fd3 ++0, 750749, 276480, 0x51cb657c ++0, 754503, 276480, 0x2c230702 ++0, 758257, 276480, 0x4a4f76cd ++0, 762011, 276480, 0xdcd71e88 ++0, 765764, 276480, 0x87160f99 ++0, 769518, 276480, 0x27f54854 ++0, 773272, 276480, 0x694d76e3 ++0, 777026, 276480, 0xcbe93c19 ++0, 780779, 276480, 0x50742e1b ++0, 784533, 276480, 0x525463e2 ++0, 788287, 276480, 0x819898f9 ++0, 792041, 276480, 0x08fac755 ++0, 795794, 276480, 0x35c46927 ++0, 799548, 276480, 0xeeed00fc ++0, 803302, 276480, 0xb6f99ee3 ++0, 807056, 276480, 0xd87f4c73 ++0, 810809, 276480, 0xde97d9fd ++0, 814563, 276480, 0xefc83107 ++0, 818317, 276480, 0xbb22e024 ++0, 822071, 276480, 0x53a7cfcb ++0, 825824, 276480, 0xbe1fbb19 ++0, 829578, 276480, 0x300f922a ++0, 833332, 276480, 0x826fc3bd ++0, 837086, 276480, 0x679aa57a ++0, 840839, 276480, 0x5497097b ++0, 844593, 276480, 0x679a53f8 ++0, 848347, 276480, 0x976c9e93 ++0, 852101, 276480, 0xe80f87f2 ++0, 855854, 276480, 0xdc2d7c6c ++0, 859608, 276480, 0xb194656e ++0, 863362, 276480, 0xf002c5ca ++0, 867116, 276480, 0x43fc1c64 ++0, 870869, 276480, 0xf62d8581 ++0, 874623, 276480, 0xb243dda5 ++0, 878377, 276480, 0x1700efbb ++0, 882131, 276480, 0x9ebe6ba2 ++0, 885884, 276480, 0x8f316c66 ++0, 889638, 276480, 0x6348ecf5 ++0, 893392, 276480, 0x34b5b78a ++0, 897146, 276480, 0xcbf66922 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/rpza xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/rpza +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/rpza 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/rpza 2012-05-14 14:08:55.702367514 +0200 +@@ -1,30 +1,30 @@ +-0, 0, 230400, 0x4aec80a3 +-0, 6000, 230400, 0xb6c41452 +-0, 12000, 230400, 0xa6c27f12 +-0, 18000, 230400, 0x309bd2d2 +-0, 24000, 230400, 0x597a7341 +-0, 30000, 230400, 0x597a7341 +-0, 36000, 230400, 0xd6d6c569 +-0, 42000, 230400, 0x31413d89 +-0, 48000, 230400, 0x464e42e9 +-0, 54000, 230400, 0x502d7c71 +-0, 60000, 230400, 0x502d7c71 +-0, 66000, 230400, 0xc96f23d1 +-0, 72000, 230400, 0xc96f23d1 +-0, 78000, 230400, 0x5bfd2bc7 +-0, 84000, 230400, 0x821640a7 +-0, 90000, 230400, 0x8f001967 +-0, 96000, 230400, 0x406ba109 +-0, 102000, 230400, 0x85d99b50 +-0, 108000, 230400, 0x2fdb4018 +-0, 114000, 230400, 0xfa127259 +-0, 120000, 230400, 0xe6427b9b +-0, 126000, 230400, 0xe6427b9b +-0, 132000, 230400, 0x3a279000 +-0, 138000, 230400, 0x710755ee +-0, 144000, 230400, 0x76549d35 +-0, 150000, 230400, 0xf4d0132c +-0, 156000, 230400, 0xf4d0132c +-0, 162000, 230400, 0x19d7ec14 +-0, 168000, 230400, 0x19d7ec14 +-0, 174000, 230400, 0x5f24b7e1 ++0, 0, 230400, 0x26a4728c ++0, 6000, 230400, 0xa5ff0a21 ++0, 12000, 230400, 0x479d767d ++0, 18000, 230400, 0xc619cd01 ++0, 24000, 230400, 0x1d377157 ++0, 30000, 230400, 0x1d377157 ++0, 36000, 230400, 0x0941c629 ++0, 42000, 230400, 0xe64b3a93 ++0, 48000, 230400, 0x28493fd7 ++0, 54000, 230400, 0x18c77af2 ++0, 60000, 230400, 0x18c77af2 ++0, 66000, 230400, 0x5a542008 ++0, 72000, 230400, 0x5a542008 ++0, 78000, 230400, 0x3b1a34fd ++0, 84000, 230400, 0x77d34944 ++0, 90000, 230400, 0x50ac218c ++0, 96000, 230400, 0xcb999f16 ++0, 102000, 230400, 0xe1ce9f19 ++0, 108000, 230400, 0xb10b4264 ++0, 114000, 230400, 0x61207031 ++0, 120000, 230400, 0x81626d5b ++0, 126000, 230400, 0x81626d5b ++0, 132000, 230400, 0x1cb59751 ++0, 138000, 230400, 0x316e6962 ++0, 144000, 230400, 0x4c01b829 ++0, 150000, 230400, 0x276e32bc ++0, 156000, 230400, 0x276e32bc ++0, 162000, 230400, 0xe251117a ++0, 168000, 230400, 0xe251117a ++0, 174000, 230400, 0x41b7f098 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/rv30 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/rv30 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/rv30 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/rv30 2012-05-14 14:08:55.703367534 +0200 +@@ -1,46 +1,109 @@ + 0, 0, 126720, 0xcefaec47 +-0, 7500, 126720, 0xa416ece5 +-0, 15000, 126720, 0xa416ece5 +-0, 22500, 126720, 0xa416ece5 +-0, 30000, 126720, 0xcc10f4b7 +-0, 37500, 126720, 0xeb6fb8d7 +-0, 45000, 126720, 0xda71b917 +-0, 52500, 126720, 0xbb1abbb7 +-0, 60000, 126720, 0x273fbc37 +-0, 67500, 126720, 0x16eebbd7 +-0, 75000, 126720, 0x105eb927 +-0, 82500, 126720, 0x7fa3ae27 +-0, 90000, 126720, 0xd115a757 +-0, 97500, 126720, 0x04e7897c +-0, 105000, 126720, 0x68cfda2b +-0, 112500, 126720, 0xe572dfc9 +-0, 120000, 126720, 0xbc3cc34f +-0, 127500, 126720, 0xcf8cb0e2 +-0, 135000, 126720, 0x6d1c630d +-0, 142500, 126720, 0x4338e469 +-0, 150000, 126720, 0x9d82ea38 +-0, 157500, 126720, 0x55e0b559 +-0, 165000, 126720, 0x5eefb5ef +-0, 172500, 126720, 0x4b10b746 +-0, 180000, 126720, 0x8b07a1db +-0, 187500, 126720, 0x8c639b34 +-0, 195000, 126720, 0x63eb0b9f +-0, 202500, 126720, 0x31c80c83 +-0, 210000, 126720, 0x78495352 +-0, 217500, 126720, 0x63d609c4 +-0, 225000, 126720, 0xcd2a62d8 +-0, 232500, 126720, 0x4aea732d +-0, 240000, 126720, 0xe3bb352c +-0, 247500, 126720, 0x4b9036ad +-0, 255000, 126720, 0x88b66e2d +-0, 262500, 126720, 0x4a8a1b16 +-0, 270000, 126720, 0x2e014eac +-0, 277500, 126720, 0x83212c67 +-0, 285000, 126720, 0x4937e897 +-0, 292500, 126720, 0x2d38babe +-0, 300000, 126720, 0xbcb43c09 +-0, 307500, 126720, 0x955ffaf4 +-0, 315000, 126720, 0x3337d4a2 +-0, 322500, 126720, 0xe8f58c33 +-0, 330000, 126720, 0x3a7f771f +-0, 337500, 126720, 0xb67c39b9 ++0, 3003, 126720, 0xa416ece5 ++0, 6006, 126720, 0xa416ece5 ++0, 9009, 126720, 0xa416ece5 ++0, 12012, 126720, 0x60d6ed27 ++0, 15015, 126720, 0x259af497 ++0, 18018, 126720, 0x5e6ff4d7 ++0, 21021, 126720, 0xcc10f4b7 ++0, 24024, 126720, 0x763ab817 ++0, 27027, 126720, 0xeb6fb8d7 ++0, 30030, 126720, 0xda71b917 ++0, 33033, 126720, 0x0967b8f7 ++0, 36036, 126720, 0x4b62b947 ++0, 39039, 126720, 0xbb1abbb7 ++0, 42042, 126720, 0x273fbc37 ++0, 45045, 126720, 0x16eebbd7 ++0, 48048, 126720, 0x105eb927 ++0, 51051, 126720, 0x7fa3ae27 ++0, 54054, 126720, 0x722e99f7 ++0, 57057, 126720, 0x5ac9a827 ++0, 60060, 126720, 0x07beba77 ++0, 63063, 126720, 0x29d6a887 ++0, 66066, 126720, 0xa5caab87 ++0, 69069, 126720, 0x9ca7aac7 ++0, 72072, 126720, 0xb7debcd7 ++0, 75075, 126720, 0xd115a757 ++0, 78078, 126720, 0x6ddaef32 ++0, 81081, 126720, 0xde1bb900 ++0, 84084, 126720, 0xac6c071b ++0, 87087, 126720, 0x04e7897c ++0, 90090, 126720, 0x5eee050f ++0, 93093, 126720, 0xe675be59 ++0, 96096, 126720, 0xdc3e0837 ++0, 99099, 126720, 0x68cfda2b ++0, 102102, 126720, 0xe572dfc9 ++0, 105105, 126720, 0x582fb176 ++0, 108108, 126720, 0xa9477df0 ++0, 111111, 126720, 0xbc3cc34f ++0, 114114, 126720, 0xcf8cb0e2 ++0, 117117, 126720, 0xcff1db35 ++0, 120120, 126720, 0xc6e10f9f ++0, 123123, 126720, 0x75ae61b6 ++0, 126126, 126720, 0x12af3119 ++0, 129129, 126720, 0x85597543 ++0, 132132, 126720, 0x68c27aca ++0, 135135, 126720, 0x554fe3e4 ++0, 138138, 126720, 0x72ecea95 ++0, 141141, 126720, 0xf4d003d1 ++0, 144144, 126720, 0x9bf6a605 ++0, 147147, 126720, 0x5d00b5fe ++0, 150150, 126720, 0x93f7b040 ++0, 153153, 126720, 0x0d6ad154 ++0, 156156, 126720, 0x4be8b4ea ++0, 159159, 126720, 0xe39bba0d ++0, 162162, 126720, 0x9c21bad8 ++0, 165165, 126720, 0xa567f25b ++0, 168168, 126720, 0x7a82663a ++0, 171171, 126720, 0x72f2a47d ++0, 174174, 126720, 0x4f639ebe ++0, 177177, 126720, 0xab0fce83 ++0, 180180, 126720, 0x6cf87d39 ++0, 183183, 126720, 0x534a10cc ++0, 186186, 126720, 0x6bbcf44c ++0, 189189, 126720, 0xfdca11d3 ++0, 192192, 126720, 0x7e58f5a6 ++0, 195195, 126720, 0x5fd753d8 ++0, 198198, 126720, 0x0c735615 ++0, 201201, 126720, 0x2a034ebf ++0, 204204, 126720, 0xeaf3dd0b ++0, 207207, 126720, 0x0eaf0c1b ++0, 210210, 126720, 0xce5e6794 ++0, 213213, 126720, 0xf27c31c3 ++0, 216216, 126720, 0xb64af168 ++0, 219219, 126720, 0x14cf7974 ++0, 222222, 126720, 0x1c2a513d ++0, 225225, 126720, 0xa3f515ab ++0, 228228, 126720, 0xcfd62765 ++0, 231231, 126720, 0xbc513f2a ++0, 234234, 126720, 0xbc303fae ++0, 237237, 126720, 0x2f8f69b9 ++0, 240240, 126720, 0x0a22cc69 ++0, 243243, 126720, 0xd9f67585 ++0, 246246, 126720, 0x20403001 ++0, 249249, 126720, 0xf92b2a25 ++0, 252252, 126720, 0x3c170aad ++0, 255255, 126720, 0x3378251f ++0, 258258, 126720, 0xb3ed5911 ++0, 261261, 126720, 0x35d24ef8 ++0, 264264, 126720, 0x8da30275 ++0, 267267, 126720, 0xc15a3577 ++0, 270270, 126720, 0xf2942f53 ++0, 273273, 126720, 0x44d8304a ++0, 276276, 126720, 0xd688a932 ++0, 279279, 126720, 0x0a24f256 ++0, 282282, 126720, 0xfab9c45d ++0, 285285, 126720, 0x10e939ce ++0, 288288, 126720, 0x97fcaa3a ++0, 291291, 126720, 0x45464610 ++0, 294294, 126720, 0xfe2e057d ++0, 297297, 126720, 0x0b6718ae ++0, 300300, 126720, 0x5284da7b ++0, 303303, 126720, 0x23efdc35 ++0, 306306, 126720, 0xc387b2b3 ++0, 309309, 126720, 0xc9e92bf1 ++0, 312312, 126720, 0xfbf20a01 ++0, 315315, 126720, 0x4d888b2e ++0, 318318, 126720, 0xdd0d74df ++0, 321321, 126720, 0x49d07aa4 ++0, 324324, 126720, 0x08382b8e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/sierra-audio xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/sierra-audio +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/sierra-audio 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/sierra-audio 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-a99402e1f1a0f137608898251b3f309b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/sierra-vmd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/sierra-vmd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/sierra-vmd 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/sierra-vmd 2012-05-14 14:08:55.705367574 +0200 +@@ -1,5 +1,5 @@ + 0, 0, 230400, 0x0224ab01 +-1, 0, 123480, 0xc1059826 ++1, 0, 123480, 0x3a794c13 + 0, 9000, 230400, 0x449e4d81 + 0, 18000, 230400, 0x3e15e07a + 0, 27000, 230400, 0xdabe4172 +@@ -27,277 +27,306 @@ + 0, 225000, 230400, 0x76aebdae + 0, 234000, 230400, 0x81357545 + 0, 243000, 230400, 0x38baeebd +-1, 252000, 4410, 0x261a09c0 + 0, 252000, 230400, 0x1c5c44d4 +-1, 261000, 4410, 0x68e9489e ++1, 252000, 4410, 0x109d04e0 + 0, 261000, 230400, 0x60e189cc +-1, 270000, 4410, 0xb830827a ++1, 261000, 4410, 0x224d244f + 0, 270000, 230400, 0xb1f4381c +-1, 279000, 4410, 0xb053b70c ++1, 270000, 4410, 0xbb72413d + 0, 279000, 230400, 0xb5048fed +-1, 288000, 4410, 0xd8845d5d ++1, 279000, 4410, 0xaa5f5b86 + 0, 288000, 230400, 0xc947c30e +-1, 297000, 4410, 0xd741f940 ++1, 288000, 4410, 0x94e7aea7 + 0, 297000, 230400, 0xe8e31c07 +-1, 306000, 4410, 0x4860193c ++1, 297000, 4410, 0xad497ca0 + 0, 306000, 230400, 0x6d49dd02 +-1, 315000, 4410, 0x2e70df5f ++1, 306000, 4410, 0x1de10c9e + 0, 315000, 230400, 0x293e15d3 +-1, 324000, 4410, 0x4b3e0e54 ++1, 315000, 4410, 0x9f55efa8 + 0, 324000, 230400, 0x354d792e +-1, 333000, 4410, 0x4afbf661 ++1, 324000, 4410, 0x220a072a + 0, 333000, 230400, 0x35468780 +-1, 342000, 4410, 0x485c3903 ++1, 333000, 4410, 0xa7dafb29 + 0, 342000, 230400, 0x365d3991 +-1, 351000, 4410, 0xc0a1a00c ++1, 342000, 4410, 0xd5e29c7a + 0, 351000, 230400, 0xc9debef2 +-1, 360000, 4410, 0x0ce2d38e ++1, 351000, 4410, 0xb8465006 + 0, 360000, 230400, 0x4c4634c2 +-1, 369000, 4410, 0x5b52dfa3 ++1, 360000, 4410, 0x518669c7 + 0, 369000, 230400, 0x347c2dca +-1, 378000, 4410, 0x0d6c02ba ++1, 369000, 4410, 0xb5b5efca + 0, 378000, 230400, 0x1efa0aaa +-1, 387000, 4410, 0x55f31fe1 ++1, 378000, 4410, 0x8600015d + 0, 387000, 230400, 0xa79a0b5a +-1, 396000, 4410, 0x7350b1b2 ++1, 387000, 4410, 0xe2f68fe9 + 0, 396000, 230400, 0xfdb2dcdb +-1, 405000, 4410, 0x2b918eea ++1, 396000, 4410, 0x8d3458d9 + 0, 405000, 230400, 0x42dbea33 +-1, 414000, 4410, 0x6df6cf92 ++1, 405000, 4410, 0xf1ff4775 + 0, 414000, 230400, 0x2a207e43 +-1, 423000, 4410, 0x2ddd1782 ++1, 414000, 4410, 0x830f67c9 + 0, 423000, 230400, 0x86573783 +-1, 432000, 4410, 0x12265e8e ++1, 423000, 4410, 0x110e0bc1 + 0, 432000, 230400, 0xc3968473 +-1, 441000, 4410, 0x00c62139 ++1, 432000, 4410, 0x71682f47 + 0, 441000, 230400, 0x8f62a7b4 +-1, 450000, 4410, 0xf2579b6c ++1, 441000, 4410, 0x38119095 + 0, 450000, 230400, 0x5a2e3073 +-1, 459000, 4410, 0x3bc24a12 ++1, 450000, 4410, 0xd2494db6 + 0, 459000, 230400, 0xd24f5e2c +-1, 468000, 4410, 0x0ce25212 ++1, 459000, 4410, 0x8b552509 + 0, 468000, 230400, 0x1df3c67d +-1, 477000, 4410, 0xad70de9a ++1, 468000, 4410, 0x71e52909 + 0, 477000, 230400, 0xe4fd884d +-1, 486000, 4410, 0x232705e4 ++1, 477000, 4410, 0x9f0a6f4d + 0, 486000, 230400, 0x9a228555 +-1, 495000, 4410, 0x5ceba444 ++1, 486000, 4410, 0x901302f2 + 0, 495000, 230400, 0x9eba8ed5 +-1, 504000, 4410, 0x17a3660b ++1, 495000, 4410, 0x855d5222 + 0, 504000, 230400, 0x3d808a3d +-1, 513000, 4410, 0x291bb07e ++1, 504000, 4410, 0x324bb2fe + 0, 513000, 230400, 0xf57e866d +-1, 522000, 4410, 0xc13ccf88 ++1, 513000, 4410, 0xe85f583f + 0, 522000, 230400, 0x85f594f5 +-1, 531000, 4410, 0xfb0cd542 ++1, 522000, 4410, 0x2cbc67c4 + 0, 531000, 230400, 0xb09f99dd +-1, 540000, 4410, 0xb6438478 ++1, 531000, 4410, 0xc82e6aa1 + 0, 540000, 230400, 0x2b368475 +-1, 549000, 4410, 0x263e9df2 ++1, 540000, 4410, 0xb9fc423c + 0, 549000, 230400, 0xa2417afd +-1, 558000, 4410, 0x81621e20 ++1, 549000, 4410, 0x6b9b4ef9 + 0, 558000, 230400, 0x590b709d +-1, 567000, 4410, 0xe9a51d77 ++1, 558000, 4410, 0x39290f10 + 0, 567000, 230400, 0x5d617705 +-1, 576000, 4410, 0x69a3c758 ++1, 567000, 4410, 0xad718eb4 + 0, 576000, 230400, 0xabf981ad +-1, 585000, 4410, 0x725af958 ++1, 576000, 4410, 0x82f463ac + 0, 585000, 230400, 0x5a8590cd +-1, 594000, 4410, 0x09db995d ++1, 585000, 4410, 0xfac87cac + 0, 594000, 230400, 0x1bff853d +-1, 603000, 4410, 0x42963941 ++1, 594000, 4410, 0x9e8bcca7 + 0, 603000, 230400, 0x71d08055 +-1, 612000, 4410, 0x33a29bc4 ++1, 603000, 4410, 0x52f79c99 + 0, 612000, 230400, 0x2ebd817d +-1, 621000, 4410, 0x02ee2bd1 ++1, 612000, 4410, 0xf2d14de2 + 0, 621000, 230400, 0x6e838255 +-1, 630000, 4410, 0xda968535 ++1, 621000, 4410, 0x367f95e1 + 0, 630000, 230400, 0x043984cd +-1, 639000, 4410, 0x5414a080 ++1, 630000, 4410, 0x8bfac293 + 0, 639000, 230400, 0x7ff18495 +-1, 648000, 4410, 0x021ac433 ++1, 639000, 4410, 0x01ea5040 + 0, 648000, 230400, 0xa43b8385 +-1, 657000, 4410, 0x50195048 ++1, 648000, 4410, 0x8ff5e212 + 0, 657000, 230400, 0x72b5825d +-1, 666000, 4410, 0xc40921c7 ++1, 657000, 4410, 0x93f32824 + 0, 666000, 230400, 0x3a178085 +-1, 675000, 4410, 0xdbb622e0 ++1, 666000, 4410, 0x998f90dc + 0, 675000, 230400, 0x67748245 +-1, 684000, 4410, 0xc8d07342 ++1, 675000, 4410, 0x65231170 + 0, 684000, 230400, 0xeddf81d5 +-1, 693000, 4410, 0x6ed9b17a ++1, 684000, 4410, 0xc79039a1 + 0, 693000, 230400, 0x8b088665 +-1, 702000, 4410, 0x39ac6a03 ++1, 693000, 4410, 0x0b0e58bd + 0, 702000, 230400, 0x6c408e15 +-1, 711000, 4410, 0x119ed51c ++1, 702000, 4410, 0xc24ab4fa + 0, 711000, 230400, 0x81f196dd +-1, 720000, 4410, 0xc9a20539 ++1, 711000, 4410, 0xd3796a8e + 0, 720000, 230400, 0xab9f953d +-1, 729000, 4410, 0x6db5fdbd ++1, 720000, 4410, 0xa37f8295 + 0, 729000, 230400, 0xa5f69795 +-1, 738000, 4410, 0x64c6b468 ++1, 729000, 4410, 0xb760fed7 + 0, 738000, 230400, 0xa772950d +-1, 747000, 4410, 0x1286686e ++1, 738000, 4410, 0x05495a34 + 0, 747000, 230400, 0x6a5596d5 +-1, 756000, 4410, 0x76632813 ++1, 747000, 4410, 0x6f203437 + 0, 756000, 230400, 0x1355958d +-1, 765000, 4410, 0x9923669b ++1, 756000, 4410, 0x71299402 + 0, 765000, 230400, 0x4134981d +-1, 774000, 4410, 0x1cf31b5c ++1, 765000, 4410, 0x72e7b346 + 0, 774000, 230400, 0x8b929515 +-1, 783000, 4410, 0xa9f14389 ++1, 774000, 4410, 0x879b0dae + 0, 783000, 230400, 0x482f95c5 +-1, 792000, 4410, 0x9438c5cc ++1, 783000, 4410, 0x041aa1bd + 0, 792000, 230400, 0x7a9795d5 +-1, 801000, 4410, 0x48dd0a72 ++1, 792000, 4410, 0x18a962e6 + 0, 801000, 230400, 0x21c29abd +-1, 810000, 4410, 0xb0fe24dd ++1, 801000, 4410, 0x21d20539 + 0, 810000, 230400, 0x9ae6a475 +-1, 819000, 4410, 0xdb9d03ac ++1, 810000, 4410, 0x8f449267 + 0, 819000, 230400, 0x3734aee5 +-1, 828000, 4410, 0x487d7ac3 ++1, 819000, 4410, 0xecdc01d6 + 0, 828000, 230400, 0xa0a1b365 +-1, 837000, 4410, 0x2b61d4d5 ++1, 828000, 4410, 0x458abd5a + 0, 837000, 230400, 0x2dcab1c5 +-1, 846000, 4410, 0xab934d9c ++1, 837000, 4410, 0xa070ea63 + 0, 846000, 230400, 0x9c8b6c44 +-1, 855000, 4410, 0xd2ee6f94 ++1, 846000, 4410, 0xc25b26ce + 0, 855000, 230400, 0x5da75feb +-1, 864000, 4410, 0x012c3002 ++1, 855000, 4410, 0x4d9237ca + 0, 864000, 230400, 0x4d02f8e3 +-1, 873000, 4410, 0xfccbd3cc ++1, 864000, 4410, 0x748e1801 + 0, 873000, 230400, 0x66824f3a +-1, 882000, 4410, 0xe53230d8 ++1, 873000, 4410, 0xc96b69e6 + 0, 882000, 230400, 0x0c9257e2 +-1, 891000, 4410, 0x2f6a6102 ++1, 882000, 4410, 0x6663186c + 0, 891000, 230400, 0xb2927092 +-1, 900000, 4410, 0x77bb876a ++1, 891000, 4410, 0x7f6d3081 + 0, 900000, 230400, 0xb5dc6e9a +-1, 909000, 4410, 0xbcb76718 ++1, 900000, 4410, 0x1a0343b5 + 0, 909000, 230400, 0x6e567bc6 +-1, 918000, 4410, 0x51c00790 ++1, 909000, 4410, 0xc48e338c + 0, 918000, 230400, 0xbf9e0f7a +-1, 927000, 4410, 0x51b8fc5a ++1, 918000, 4410, 0x26fc03c8 + 0, 927000, 230400, 0xb16f684a +-1, 936000, 4410, 0x20fe9b42 ++1, 927000, 4410, 0x69be7e2d + 0, 936000, 230400, 0xf9e55e81 +-1, 945000, 4410, 0x363c5566 ++1, 936000, 4410, 0x69a74da1 + 0, 945000, 230400, 0xd8d0bcba +-1, 954000, 4410, 0x3424a84c ++1, 945000, 4410, 0x85bd2ab3 + 0, 954000, 230400, 0x44720ac0 +-1, 963000, 4410, 0x7c3053c0 ++1, 954000, 4410, 0xeff05426 + 0, 963000, 230400, 0x7d4c2058 +-1, 972000, 4410, 0x368f2f30 ++1, 963000, 4410, 0x292829e0 + 0, 972000, 230400, 0xb0973eb9 +-1, 981000, 4410, 0x0f1e6fd2 ++1, 972000, 4410, 0x8f741798 + 0, 981000, 230400, 0x405a13ce +-1, 990000, 4410, 0x3a1fe07e ++1, 981000, 4410, 0x6b9337e9 + 0, 990000, 230400, 0x6422f00a +-1, 999000, 4410, 0x74afd86a ++1, 990000, 4410, 0xe4e1703f + 0, 999000, 230400, 0x924b6c1e +-1, 1008000, 4410, 0xfdf911dd ++1, 999000, 4410, 0x043d6c35 + 0, 1008000, 230400, 0xcf7809c0 +-1, 1017000, 4410, 0x1206a561 ++1, 1008000, 4410, 0x3a8988e7 + 0, 1017000, 230400, 0x883a3863 +-1, 1026000, 4410, 0x5f0f33d5 ++1, 1017000, 4410, 0x1fa7d2a9 + 0, 1026000, 230400, 0x6adc9e03 +-1, 1035000, 4410, 0xca3d88e0 ++1, 1026000, 4410, 0xe28799e3 + 0, 1035000, 230400, 0x4f5ab7a8 +-1, 1044000, 4410, 0xdf8f19ea ++1, 1035000, 4410, 0xc2df4470 + 0, 1044000, 230400, 0xdc0aab94 +-1, 1053000, 4410, 0xe3275b9e +-1, 1062000, 4410, 0xee1945c5 +-1, 1071000, 4410, 0x0afbd006 +-1, 1080000, 4410, 0x90ff8f14 +-1, 1089000, 4410, 0xfc0c887a +-1, 1098000, 4410, 0xae9bc232 +-1, 1107000, 4410, 0x5f688eb8 +-1, 1116000, 4410, 0x9a307469 +-1, 1125000, 4410, 0x27f1e324 +-1, 1134000, 4410, 0x0c0d4ca2 +-1, 1143000, 4410, 0xd7e8ce74 +-1, 1152000, 4410, 0x16a4bfd6 +-1, 1161000, 4410, 0xbfb02f6d +-1, 1170000, 4410, 0xf4b81a79 +-1, 1179000, 4410, 0x05d97288 +-1, 1188000, 4410, 0x3a7db4be +-1, 1197000, 4410, 0xc6bea83e +-1, 1206000, 4410, 0x436f62ed +-1, 1215000, 4410, 0x6fabea0c +-1, 1224000, 4410, 0x954878aa +-1, 1233000, 4410, 0x4d10f579 +-1, 1242000, 4410, 0xac65932a +-1, 1251000, 4410, 0x6889f957 +-1, 1260000, 4410, 0x65cf5830 +-1, 1269000, 4410, 0x87a7af71 +-1, 1278000, 4410, 0x82378c13 +-1, 1287000, 4410, 0x88ab6bd5 +-1, 1296000, 4410, 0xf90a3342 +-1, 1305000, 4410, 0xd790a1bc +-1, 1314000, 4410, 0x89919d7c +-1, 1323000, 4410, 0x7ffb22bf +-1, 1332000, 4410, 0xfefbcce3 +-1, 1341000, 4410, 0x07714e80 +-1, 1350000, 4410, 0x73078f53 +-1, 1359000, 4410, 0x35c23078 +-1, 1368000, 4410, 0x452538bb +-1, 1377000, 4410, 0x61493f33 +-1, 1386000, 4410, 0x2137c390 +-1, 1395000, 4410, 0x78c9393f +-1, 1404000, 4410, 0x7aeaf8e1 +-1, 1413000, 4410, 0x4bb8da1c +-1, 1422000, 4410, 0x5995dfc2 +-1, 1431000, 4410, 0xccce8872 +-1, 1440000, 4410, 0xca2753a4 +-1, 1449000, 4410, 0x4296ff6d +-1, 1458000, 4410, 0xe582d191 +-1, 1467000, 4410, 0xc40268da +-1, 1476000, 4410, 0xda1d475e +-1, 1485000, 4410, 0x5e91e4e0 +-1, 1494000, 4410, 0xfeb44475 +-1, 1503000, 4410, 0x17ff8e38 +-1, 1512000, 4410, 0x3bd58bcf +-1, 1521000, 4410, 0x9476e23c +-1, 1530000, 4410, 0x440651ab +-1, 1539000, 4410, 0xb08cdc74 +-1, 1548000, 4410, 0x6fc3031f +-1, 1557000, 4410, 0x197ab39a +-1, 1566000, 4410, 0xf92f0e3d +-1, 1575000, 4410, 0xd5f6b678 +-1, 1584000, 4410, 0x8af127a6 +-1, 1593000, 4410, 0xe22f585e +-1, 1602000, 4410, 0x67515610 +-1, 1611000, 4410, 0x21569d7a +-1, 1620000, 4410, 0x114597d8 +-1, 1629000, 4410, 0xba213fb6 +-1, 1638000, 4410, 0x1aca9fee +-1, 1647000, 4410, 0x48cdd264 +-1, 1656000, 4410, 0x533619ec +-1, 1665000, 4410, 0x21466244 +-1, 1674000, 4410, 0x26e00e88 +-1, 1683000, 4410, 0x8e51d07c +-1, 1692000, 4410, 0xa6c4048a +-1, 1701000, 4410, 0x98ce10e4 +-1, 1710000, 4410, 0x379bc8c2 +-1, 1719000, 4410, 0x404b09c6 +-1, 1728000, 4410, 0xfc89da8a +-1, 1737000, 4410, 0xbdbe6914 +-1, 1746000, 4410, 0x2cb09f08 +-1, 1755000, 4410, 0x835bf2d9 +-1, 1764000, 4410, 0xa4611790 +-1, 1773000, 4410, 0x67740896 +-1, 1782000, 4410, 0x489f6bd0 +-1, 1791000, 4410, 0x072bae9c +-1, 1800000, 4410, 0xadce5a89 +-1, 1809000, 4410, 0x209f2c2c +-1, 1818000, 4410, 0xf5706665 +-1, 1827000, 4410, 0x631841cb +-1, 1836000, 4410, 0xa1a2c65f +-1, 1845000, 4410, 0x8818b96b +-1, 1854000, 4410, 0x63158025 +-1, 1863000, 4410, 0xf6ae79f5 +-1, 1872000, 4410, 0xb3dcd214 +-1, 1881000, 4410, 0x7a745449 +-1, 1890000, 4410, 0x5d2b15f4 +-1, 1899000, 4410, 0x48764b7c +-1, 1908000, 4410, 0x1294e119 ++1, 1044000, 4410, 0x694d0cf5 ++1, 1053000, 4410, 0x5aac2dcf ++1, 1062000, 4410, 0x259fa2db ++1, 1071000, 4410, 0xd16d6803 ++1, 1080000, 4410, 0xa4b3478a ++1, 1089000, 4410, 0xdbe0443d ++1, 1098000, 4410, 0x26c16119 ++1, 1107000, 4410, 0x0c06475c ++1, 1116000, 4410, 0x6ffaba2d ++1, 1125000, 4410, 0x5b287192 ++1, 1134000, 4410, 0xf2cf2651 ++1, 1143000, 4410, 0x3857673a ++1, 1152000, 4410, 0x5b555feb ++1, 1161000, 4410, 0x93f997af ++1, 1170000, 4410, 0xb3ba8d35 ++1, 1179000, 4410, 0x66433944 ++1, 1188000, 4410, 0xf0005a5f ++1, 1197000, 4410, 0xb948541f ++1, 1206000, 4410, 0xc8f1b16f ++1, 1215000, 4410, 0x7d4b7506 ++1, 1224000, 4410, 0xac723c55 ++1, 1233000, 4410, 0x2926fab5 ++1, 1242000, 4410, 0x31684995 ++1, 1251000, 4410, 0x35ebfca4 ++1, 1260000, 4410, 0x9cd42c18 ++1, 1269000, 4410, 0xd7ecd7b1 ++1, 1278000, 4410, 0x5e13c602 ++1, 1287000, 4410, 0xe955b5e3 ++1, 1296000, 4410, 0xefad19a1 ++1, 1305000, 4410, 0x435950de ++1, 1314000, 4410, 0x9d624ebe ++1, 1323000, 4410, 0x774a9158 ++1, 1332000, 4410, 0x8c41e66a ++1, 1341000, 4410, 0x70112740 ++1, 1350000, 4410, 0x55abc7a2 ++1, 1359000, 4410, 0x0ec3183c ++1, 1368000, 4410, 0x54609c56 ++1, 1377000, 4410, 0x60d49f92 ++1, 1386000, 4410, 0x5fb061c8 ++1, 1395000, 4410, 0x6e119c98 ++1, 1404000, 4410, 0x3f39fc69 ++1, 1413000, 4410, 0xef466d0e ++1, 1422000, 4410, 0xf4cb6fe1 ++1, 1431000, 4410, 0xc4434439 ++1, 1440000, 4410, 0xd02329d2 ++1, 1449000, 4410, 0x216cffaf ++1, 1458000, 4410, 0x7e59e8c1 ++1, 1467000, 4410, 0xc7c3346d ++1, 1476000, 4410, 0x5b3723af ++1, 1485000, 4410, 0x76097270 ++1, 1494000, 4410, 0xae39a233 ++1, 1503000, 4410, 0x686a471c ++1, 1512000, 4410, 0x3af3c5e0 ++1, 1521000, 4410, 0x11ac711e ++1, 1530000, 4410, 0xcd8da8ce ++1, 1539000, 4410, 0x21296e3a ++1, 1548000, 4410, 0x77168188 ++1, 1557000, 4410, 0x5fcf59cd ++1, 1566000, 4410, 0x390c8717 ++1, 1575000, 4410, 0x3d5d5b3c ++1, 1584000, 4410, 0x3b8f13d3 ++1, 1593000, 4410, 0x5b002c2f ++1, 1602000, 4410, 0x9e1d2b08 ++1, 1611000, 4410, 0x69454ebd ++1, 1620000, 4410, 0x62a54bec ++1, 1629000, 4410, 0x4d231fdb ++1, 1638000, 4410, 0x65624ff7 ++1, 1647000, 4410, 0x6fc66932 ++1, 1656000, 4410, 0x23200cf6 ++1, 1665000, 4410, 0xf8033122 ++1, 1674000, 4410, 0x0fce0744 ++1, 1683000, 4410, 0x9302683e ++1, 1692000, 4410, 0xd2380245 ++1, 1701000, 4410, 0x482e0872 ++1, 1710000, 4410, 0xe98e6461 ++1, 1719000, 4410, 0x1db404e3 ++1, 1728000, 4410, 0x47a26d45 ++1, 1737000, 4410, 0x449a348a ++1, 1746000, 4410, 0xee874f84 ++1, 1755000, 4410, 0xc4ecf965 ++1, 1764000, 4410, 0xcc450bc8 ++1, 1773000, 4410, 0xb18d044b ++1, 1782000, 4410, 0x895435e8 ++1, 1791000, 4410, 0x57e7574e ++1, 1800000, 4410, 0x8041ad3d ++1, 1809000, 4410, 0x853d1616 ++1, 1818000, 4410, 0xa11bb32b ++1, 1827000, 4410, 0xe10ea0de ++1, 1836000, 4410, 0xdf2ee328 ++1, 1845000, 4410, 0xd5a6dcae ++1, 1854000, 4410, 0xd176c00b ++1, 1863000, 4410, 0x9cd6bcf3 ++1, 1872000, 4410, 0x2569690a ++1, 1881000, 4410, 0x6824aa1d ++1, 1890000, 4410, 0xa9110afa ++1, 1899000, 4410, 0x115c25be ++1, 1908000, 4410, 0x1100f085 ++1, 1917000, 4410, 0x00000000 ++1, 1926000, 4410, 0x00000000 ++1, 1935000, 4410, 0x00000000 ++1, 1944000, 4410, 0x00000000 ++1, 1953000, 4410, 0x00000000 ++1, 1962000, 4410, 0x00000000 ++1, 1971000, 4410, 0x00000000 ++1, 1980000, 4410, 0x00000000 ++1, 1989000, 4410, 0x00000000 ++1, 1998000, 4410, 0x00000000 ++1, 2007000, 4410, 0x00000000 ++1, 2016000, 4410, 0x00000000 ++1, 2025000, 4410, 0x00000000 ++1, 2034000, 4410, 0x00000000 ++1, 2043000, 4410, 0x00000000 ++1, 2052000, 4410, 0x00000000 ++1, 2061000, 4410, 0x00000000 ++1, 2070000, 4410, 0x00000000 ++1, 2079000, 4410, 0x00000000 ++1, 2088000, 4410, 0x00000000 ++1, 2097000, 4410, 0x00000000 ++1, 2106000, 4410, 0x00000000 ++1, 2115000, 4410, 0x00000000 ++1, 2124000, 4410, 0x00000000 ++1, 2133000, 4410, 0x00000000 ++1, 2142000, 4410, 0x00000000 ++1, 2151000, 4410, 0x00000000 ++1, 2160000, 4410, 0x00000000 ++1, 2169000, 4410, 0x00000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/siff xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/siff +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/siff 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/siff 2012-05-14 14:08:55.706367594 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 44100, 0xd0a49e09 + 0, 0, 230400, 0x3bd1d731 ++1, 0, 44100, 0xd0a49e09 + 0, 7500, 230400, 0x9d0774c3 + 0, 15000, 230400, 0xa0faafe2 + 0, 22500, 230400, 0x38325309 +@@ -11,8 +11,8 @@ + 0, 67500, 230400, 0x07178dd9 + 0, 75000, 230400, 0xf52b8db4 + 0, 82500, 230400, 0x2b70c1dc +-1, 90000, 44100, 0xf151af4d + 0, 90000, 230400, 0x8157a6e9 ++1, 90000, 44100, 0xf151af4d + 0, 97500, 230400, 0xd4a3c357 + 0, 105000, 230400, 0x703861bb + 0, 112500, 230400, 0xa13cf75e +@@ -24,8 +24,8 @@ + 0, 157500, 230400, 0x22050962 + 0, 165000, 230400, 0x0f5c8a0d + 0, 172500, 230400, 0x3475df44 +-1, 180000, 44100, 0xecd3cd08 + 0, 180000, 230400, 0x65354e06 ++1, 180000, 44100, 0xecd3cd08 + 0, 187500, 230400, 0xb9a01978 + 0, 195000, 230400, 0x15207ee1 + 0, 202500, 230400, 0x3b214f0b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/smacker xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/smacker +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/smacker 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/smacker 2012-05-14 14:08:55.707367615 +0200 +@@ -1,5 +1,5 @@ + 0, 0, 192000, 0x8926d7fc +-1, 0, 47240, 0xad778a78 ++1, 0, 47240, 0x9974897c + 0, 6390, 192000, 0x2506d384 + 0, 12780, 192000, 0x9a8dc93a + 0, 19170, 192000, 0x4badb7f2 +@@ -15,163 +15,163 @@ + 0, 83070, 192000, 0x1a3d7971 + 0, 89460, 192000, 0xa1a65bd5 + 0, 95850, 192000, 0x344957b9 +-1, 96408, 3128, 0x4c1564ae ++1, 96408, 3128, 0x7e4064b4 + 0, 102240, 192000, 0xe23b5f4e +-1, 102792, 3128, 0x34553309 ++1, 102792, 3128, 0x80883301 + 0, 108630, 192000, 0xb5c2710b +-1, 109176, 3136, 0xb474d246 ++1, 109176, 3136, 0x2ad2d341 + 0, 115020, 192000, 0x7a25938f +-1, 115576, 3128, 0x87b868ea ++1, 115576, 3128, 0xda8468e3 + 0, 121410, 192000, 0x0a84e4c9 +-1, 121959, 3136, 0xf1516dc3 ++1, 121959, 3136, 0x9d6f6cdf + 0, 127800, 192000, 0x94209b0d +-1, 128359, 3128, 0x867563cb ++1, 128359, 3128, 0x1aaa64b5 + 0, 134190, 192000, 0xf940e51f +-1, 134743, 3128, 0x5200728c ++1, 134743, 3128, 0x9182728b + 0, 140580, 192000, 0xb9fdec42 +-1, 141127, 3136, 0xeda118a0 ++1, 141127, 3136, 0xfa8e17b3 + 0, 146970, 192000, 0x7b04a376 +-1, 147527, 3128, 0x03e2c1d6 ++1, 147527, 3128, 0x0dc3c1cf + 0, 153360, 192000, 0x5fe0026b +-1, 153910, 3136, 0xc3e862b6 ++1, 153910, 3136, 0x0109639d + 0, 159750, 192000, 0x775aca39 +-1, 160310, 3128, 0x937a13be ++1, 160310, 3128, 0x6d8a12d9 + 0, 166140, 192000, 0xae14fb32 +-1, 166694, 3128, 0x7b1b9577 ++1, 166694, 3128, 0x4b9a9597 + 0, 172530, 192000, 0x661106e5 +-1, 173078, 3136, 0x042c7113 ++1, 173078, 3136, 0x9112710e + 0, 178920, 192000, 0xe8658dbf +-1, 179478, 3128, 0xac48f451 ++1, 179478, 3128, 0x8cccf522 + 0, 185310, 192000, 0x5359f0f9 +-1, 185861, 3128, 0x018fbbe9 ++1, 185861, 3128, 0x6594bbf3 + 0, 191700, 192000, 0xc1ec80f4 +-1, 192245, 3136, 0xc62aa7ce ++1, 192245, 3136, 0xd878a7d5 + 0, 198090, 192000, 0xca53806b +-1, 198645, 3128, 0x106e3924 ++1, 198645, 3128, 0xaa6e3905 + 0, 204480, 192000, 0xf0766b2e +-1, 205029, 3136, 0xfeb82ecc ++1, 205029, 3136, 0x2a062e04 + 0, 210870, 192000, 0x39962da8 +-1, 211429, 3128, 0x7e7c005b ++1, 211429, 3128, 0x84e4006a + 0, 217260, 192000, 0x4171c37f +-1, 217812, 3128, 0x949d3560 ++1, 217812, 3128, 0x85183633 + 0, 223650, 192000, 0x3abf3b46 +-1, 224196, 3136, 0x02bd4aff ++1, 224196, 3136, 0xb62d4b02 + 0, 230040, 192000, 0xecc68313 +-1, 230596, 3128, 0x4aaf4715 ++1, 230596, 3128, 0xe209462a + 0, 236430, 192000, 0xea339baf +-1, 236980, 3136, 0x2958825f ++1, 236980, 3136, 0x57c4824b + 0, 242820, 192000, 0x616b8f16 +-1, 243380, 3128, 0x99a5914d ++1, 243380, 3128, 0x664a9163 + 0, 249210, 192000, 0xf77a8581 +-1, 249763, 3128, 0xe67277a4 ++1, 249763, 3128, 0xb4287874 + 0, 255600, 192000, 0xb315678b +-1, 256147, 3136, 0x11296973 ++1, 256147, 3136, 0xde626885 + 0, 261990, 192000, 0x0a4a5218 +-1, 262547, 3128, 0x5cc362f7 ++1, 262547, 3128, 0x919763c2 + 0, 268380, 192000, 0x98802be4 +-1, 268931, 3128, 0x0c5e6586 ++1, 268931, 3128, 0xa4f664e1 + 0, 274770, 192000, 0xa2f0fd94 +-1, 275314, 3136, 0xe940b0f9 ++1, 275314, 3136, 0xa0bab0d4 + 0, 281160, 192000, 0x6671c84f +-1, 281714, 3128, 0x2c9292cc ++1, 281714, 3128, 0xe938939c + 0, 287550, 192000, 0x38327e31 +-1, 288098, 3136, 0xa807c096 ++1, 288098, 3136, 0x3679bfc7 + 0, 293940, 192000, 0xb85d3e08 +-1, 294498, 3128, 0x9d2254d8 ++1, 294498, 3128, 0xc96c55c3 + 0, 300330, 192000, 0xdc69eba9 +-1, 300882, 3128, 0xe68015b0 ++1, 300882, 3128, 0x119114d6 + 0, 306720, 192000, 0x8955a0b3 +-1, 307265, 3136, 0x65d58029 ++1, 307265, 3136, 0x42f3800f + 0, 313110, 192000, 0x714a548b +-1, 313665, 3128, 0xcffcc48c ++1, 313665, 3128, 0x4250c4ad + 0, 319500, 192000, 0xc0471de9 +-1, 320049, 3136, 0x8c704944 ++1, 320049, 3136, 0x5cdd4925 + 0, 325890, 192000, 0x2e16e039 +-1, 326449, 3128, 0x1459231d ++1, 326449, 3128, 0xa4c12360 + 0, 332280, 192000, 0x9fa4b033 +-1, 332833, 3128, 0x7dde4839 ++1, 332833, 3128, 0x849f48de + 0, 338670, 192000, 0x4a0f9402 +-1, 339216, 3136, 0xbb6890e2 ++1, 339216, 3136, 0x6acd8ff9 + 0, 345060, 192000, 0x1f3e6843 +-1, 345616, 3128, 0xcd9a8524 ++1, 345616, 3128, 0xb2758556 + 0, 351450, 192000, 0x31774850 +-1, 352000, 3128, 0xa244fc31 ++1, 352000, 3128, 0x10f2fcb1 + 0, 357840, 192000, 0x9d5336a2 +-1, 358384, 3136, 0x504e2bd9 ++1, 358384, 3136, 0xf0f02b23 + 0, 364230, 192000, 0xf7de27a2 +-1, 364784, 3128, 0x655858d8 ++1, 364784, 3128, 0x64f759c6 + 0, 370620, 192000, 0x98c717ce +-1, 371167, 3136, 0x46027610 ++1, 371167, 3136, 0x7ec075e3 + 0, 377010, 192000, 0x615b10b8 +-1, 377567, 3128, 0x4192d5e3 ++1, 377567, 3128, 0xf981d51e + 0, 383400, 192000, 0xd5bc0e7e +-1, 383951, 3128, 0x21d2e7fe ++1, 383951, 3128, 0xc622e8b9 + 0, 389790, 192000, 0xd5bc0e7e +-1, 390335, 3136, 0x7c93e329 ++1, 390335, 3136, 0xf632e2f8 + 0, 396180, 192000, 0xd5bc0e7e +-1, 396735, 3128, 0xa67718c0 ++1, 396735, 3128, 0xda561864 + 0, 402570, 192000, 0xd5bc0e7e +-1, 403118, 3136, 0x9bb6e8a3 ++1, 403118, 3136, 0x14d2e888 + 0, 408960, 192000, 0xd5bc0e7e +-1, 409518, 3128, 0x0933b7a6 ++1, 409518, 3128, 0x015bb869 + 0, 415350, 192000, 0xd5bc0e7e +-1, 415902, 3128, 0x07f1fb57 ++1, 415902, 3128, 0xedb1fb62 + 0, 421740, 192000, 0xd5bc0e7e +-1, 422286, 3136, 0x8a050cfd ++1, 422286, 3136, 0xe0560c41 + 0, 428130, 192000, 0xd5bc0e7e +-1, 428686, 3128, 0xdb773c0b ++1, 428686, 3128, 0x14773c9a + 0, 434520, 192000, 0xd5bc0e7e +-1, 435069, 3136, 0xd1281c53 ++1, 435069, 3136, 0x850f1c82 + 0, 440910, 192000, 0xd5bc0e7e +-1, 441469, 3128, 0x9f395324 ++1, 441469, 3128, 0xb0bd5347 + 0, 447300, 192000, 0xd5bc0e7e +-1, 447853, 3128, 0x5f13edec ++1, 447853, 3128, 0x8f82edbf + 0, 453690, 192000, 0xd5bc0e7e +-1, 454237, 3136, 0x871cbecf ++1, 454237, 3136, 0x493abee2 + 0, 460080, 192000, 0xd5bc0e7e +-1, 460637, 3128, 0x799eff3e ++1, 460637, 3128, 0xf5daff3f + 0, 466470, 192000, 0xd5bc0e7e +-1, 467020, 3128, 0x3f902762 ++1, 467020, 3128, 0x78ad2690 + 0, 472860, 192000, 0xd5bc0e7e +-1, 473404, 3136, 0x29f8bb04 ++1, 473404, 3136, 0x490ebafc + 0, 479250, 192000, 0xd5bc0e7e +-1, 479804, 3128, 0xf3523ee9 ++1, 479804, 3128, 0x70333fd2 + 0, 485640, 192000, 0xd5bc0e7e +-1, 486188, 3136, 0x4405c435 ++1, 486188, 3136, 0x8cb1c350 + 0, 492030, 192000, 0xd5bc0e7e +-1, 492588, 3128, 0x892957cb ++1, 492588, 3128, 0x8bd057cb + 0, 498420, 192000, 0xd5bc0e7e +-1, 498971, 3128, 0xdf483dbd ++1, 498971, 3128, 0x161b3dbc + 0, 504810, 192000, 0xd5bc0e7e +-1, 505355, 3136, 0x5e8ab797 ++1, 505355, 3136, 0xb47fb88a + 0, 511200, 192000, 0xd5bc0e7e +-1, 511755, 3128, 0x92e13820 ++1, 511755, 3128, 0x474b381e + 0, 517590, 192000, 0xd5bc0e7e +-1, 518139, 3136, 0xfde719b6 ++1, 518139, 3136, 0x07c519bb + 0, 523980, 192000, 0xd5bc0e7e +-1, 524539, 3128, 0x442f17ae ++1, 524539, 3128, 0x15b916c8 + 0, 530370, 192000, 0xd5bc0e7e +-1, 530922, 3128, 0x011af61f ++1, 530922, 3128, 0x0ed7f6fb + 0, 536760, 192000, 0xd5bc0e7e +-1, 537306, 3136, 0x4e3e3a6d ++1, 537306, 3136, 0x54d6397b + 0, 543150, 192000, 0xd5bc0e7e +-1, 543706, 3128, 0xc11242b9 ++1, 543706, 3128, 0x437242bb + 0, 549540, 192000, 0xd5bc0e7e +-1, 550090, 3128, 0x01415b59 ++1, 550090, 3128, 0x38f05c4d + 0, 555930, 192000, 0xd5bc0e7e +-1, 556473, 3136, 0x302e0e55 ++1, 556473, 3136, 0x5d000e59 + 0, 562320, 192000, 0xd5bc0e7e +-1, 562873, 3128, 0x20522d04 ++1, 562873, 3128, 0xdeab2d04 + 0, 568710, 192000, 0xd5bc0e7e +-1, 569257, 3136, 0x316a697d ++1, 569257, 3136, 0x77de6880 + 0, 575100, 192000, 0xd5bc0e7e +-1, 575657, 3128, 0x6d75ee27 ++1, 575657, 3128, 0xbc87ef25 + 0, 581490, 192000, 0xd5bc0e7e +-1, 582041, 3128, 0xcb008ae8 ++1, 582041, 3128, 0xc1638ade + 0, 587880, 192000, 0xd5bc0e7e +-1, 588424, 3136, 0xd2664b51 ++1, 588424, 3136, 0xcfb64a5f + 0, 594270, 192000, 0xd5bc0e7e +-1, 594824, 3128, 0xdfcab728 ++1, 594824, 3128, 0x90b1b826 + 0, 600660, 192000, 0xd5bc0e7e + 1, 601208, 3136, 0x00000000 + 0, 607050, 192000, 0xd5bc0e7e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/smjpeg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/smjpeg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/smjpeg 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/smjpeg 2012-05-14 14:08:55.708367636 +0200 +@@ -0,0 +1,423 @@ ++0, 0, 734, 0x5a042c2c ++1, 0, 1024, 0x00000000 ++1, 2090, 1024, 0x00000000 ++1, 4180, 1024, 0xd89a448e ++1, 6269, 1024, 0x695b369c ++1, 8359, 1024, 0xc8ba5707 ++0, 9990, 763, 0xb5893f2f ++1, 10449, 1024, 0xdf241fc6 ++1, 12539, 1024, 0x61cf4166 ++1, 14629, 1024, 0x97cbc386 ++1, 16718, 1024, 0x44899d04 ++1, 18808, 1024, 0xa7cbaa62 ++0, 19980, 3023, 0x0f3907d3 ++1, 20898, 1024, 0xa7aea60c ++1, 22988, 1024, 0xd7b18a89 ++1, 25078, 1024, 0x268e81f6 ++1, 27167, 1024, 0x9cf83a2f ++1, 29257, 1024, 0x5559b508 ++0, 29970, 4800, 0x22e6e18a ++1, 31347, 1024, 0xe1b9e71c ++1, 33437, 1024, 0xdcee733e ++1, 35527, 1024, 0xe5918f60 ++1, 37616, 1024, 0x29dbd209 ++1, 39706, 1024, 0x9bcbcf16 ++0, 39960, 6417, 0x427adde5 ++1, 41796, 1024, 0x86f5f458 ++1, 43886, 1024, 0xabcbda86 ++1, 45976, 1024, 0xc51f77b9 ++1, 48065, 1024, 0xf6b3a504 ++0, 49950, 6776, 0x7a74c6ad ++1, 50155, 1024, 0x1af3e40e ++1, 52245, 1024, 0x3866b03b ++1, 54335, 1024, 0xbc005403 ++1, 56424, 1024, 0xe9dfcc51 ++1, 58514, 1024, 0x83c837cb ++0, 59940, 6808, 0x1f6eb7c3 ++1, 60604, 1024, 0xfa649580 ++1, 62694, 1024, 0x519452ea ++1, 64784, 1024, 0xd4978774 ++1, 66873, 1024, 0xe2a3b1cd ++1, 68963, 1024, 0x9a9472ad ++0, 69930, 6726, 0x452087e6 ++1, 71053, 1024, 0xa12d4060 ++1, 73143, 1024, 0x31fb0646 ++1, 75233, 1024, 0xfc44343f ++1, 77322, 1024, 0x0847751a ++1, 79412, 1024, 0x227968a2 ++0, 79920, 6829, 0xee82b109 ++1, 81502, 1024, 0x7cce9f1c ++1, 83592, 1024, 0xb8356713 ++1, 85682, 1024, 0xb29f6e6f ++1, 87771, 1024, 0x9e1430ab ++1, 89861, 1024, 0x26d85423 ++0, 89910, 7055, 0xf41f1108 ++1, 91951, 1024, 0x6496547d ++1, 94041, 1024, 0x316b1a86 ++1, 96131, 1024, 0x3cd83afc ++1, 98220, 1024, 0x993ff633 ++0, 99990, 6977, 0xf8fe1ede ++1, 100310, 1024, 0x0708d1a2 ++1, 102400, 1024, 0xd7230db9 ++1, 104490, 1024, 0xbb0779ca ++1, 106580, 1024, 0xc6094e1b ++1, 108669, 1024, 0x15a8b039 ++0, 109980, 6942, 0x9ad105c6 ++1, 110759, 1024, 0xd6dbe88c ++1, 112849, 1024, 0x7e8d1140 ++1, 114939, 1024, 0xef88e525 ++1, 117029, 1024, 0x44e21149 ++1, 119118, 1024, 0x65b0f5f4 ++0, 119970, 6926, 0xe239dad6 ++1, 121208, 1024, 0xb955f687 ++1, 123298, 1024, 0xc85fba9c ++1, 125388, 1024, 0xf59655ad ++1, 127478, 1024, 0x6de80bf1 ++1, 129567, 1024, 0x2dcf6e41 ++0, 129960, 6966, 0x81dcfab1 ++1, 131657, 1024, 0xd0ddcf8a ++1, 133747, 1024, 0x00135c2d ++1, 135837, 1024, 0x697f8efd ++1, 137927, 1024, 0x7a9bada5 ++0, 139950, 6896, 0x31e6cc02 ++1, 140016, 1024, 0x0d22783c ++1, 142106, 1024, 0x7726d07d ++1, 144196, 1024, 0xa2f14f67 ++1, 146286, 1024, 0x7f51060d ++1, 148376, 1024, 0xc4ec6aea ++0, 149940, 6889, 0x1cc1006e ++1, 150465, 1024, 0x9bb37ca4 ++1, 152555, 1024, 0x9b085577 ++1, 154645, 1024, 0x8812f8af ++1, 156735, 1024, 0x788f5221 ++1, 158824, 1024, 0x3a2ce642 ++0, 159930, 6933, 0xc303f87f ++1, 160914, 1024, 0x72415692 ++1, 163004, 1024, 0xe3dcc105 ++1, 165094, 1024, 0xb26c0599 ++1, 167184, 1024, 0x5c9e55eb ++1, 169273, 1024, 0x8fe88707 ++0, 169920, 7034, 0xb4970a20 ++1, 171363, 1024, 0xc5d7beb6 ++1, 173453, 1024, 0xe1d3a3b4 ++1, 175543, 1024, 0x012da0c6 ++1, 177633, 1024, 0x8d010922 ++1, 179722, 1024, 0x3366eb0d ++0, 179910, 6961, 0xf064095d ++1, 181812, 1024, 0xc9381a27 ++1, 183902, 1024, 0x0774f685 ++1, 185992, 1024, 0xc5cae0a5 ++1, 188082, 1024, 0xa6f4737c ++0, 189990, 7089, 0x5ba350f9 ++1, 190171, 1024, 0x8fb6d0d1 ++1, 192261, 1024, 0x05f579c2 ++1, 194351, 1024, 0x56905d99 ++1, 196441, 1024, 0x002ee18d ++1, 198531, 1024, 0xeb37ef51 ++0, 199980, 7078, 0xa83f3e88 ++1, 200620, 1024, 0x38025635 ++1, 202710, 1024, 0x4fe643c8 ++1, 204800, 1024, 0x11d66ab1 ++1, 206890, 1024, 0xcc3051e9 ++1, 208980, 1024, 0xcd93e854 ++0, 209970, 7147, 0xcda66cfc ++1, 211069, 1024, 0x38f1196d ++1, 213159, 1024, 0x657a15fc ++1, 215249, 1024, 0x669ce2a9 ++1, 217339, 1024, 0x95862dda ++1, 219429, 1024, 0x1726a7b2 ++0, 219960, 7173, 0xb7455859 ++1, 221518, 1024, 0xd6ece2a1 ++1, 223608, 1024, 0x33ab9553 ++1, 225698, 1024, 0xd50c73a6 ++1, 227788, 1024, 0xfe25b63a ++1, 229878, 1024, 0x7e2959e3 ++0, 229950, 7213, 0x97b89994 ++1, 231967, 1024, 0xa4c07b34 ++1, 234057, 1024, 0xd6d8f15c ++1, 236147, 1024, 0x1eccddd7 ++1, 238237, 1024, 0x2b69f9cb ++0, 239940, 7170, 0xca8b2948 ++1, 240327, 1024, 0x667b775f ++1, 242416, 1024, 0xad3b84e9 ++1, 244506, 1024, 0x4f29fc67 ++1, 246596, 1024, 0x8d611ab7 ++1, 248686, 1024, 0x278966ea ++0, 249930, 7174, 0xc7cc6bbb ++1, 250776, 1024, 0xaf33812b ++1, 252865, 1024, 0xa55f4265 ++1, 254955, 1024, 0x023cb51c ++1, 257045, 1024, 0x1d1f1005 ++1, 259135, 1024, 0x874cccf7 ++0, 259920, 7235, 0xc2e68d2b ++1, 261224, 1024, 0xda705428 ++1, 263314, 1024, 0x48d9b440 ++1, 265404, 1024, 0xa14e0712 ++1, 267494, 1024, 0x7efbad1f ++1, 269584, 1024, 0xdb82c17f ++0, 270000, 7261, 0x8204a423 ++1, 271673, 1024, 0xcbe87613 ++1, 273763, 1024, 0x3a63df1d ++1, 275853, 1024, 0xd5636bba ++1, 277943, 1024, 0x9397af23 ++0, 279990, 7353, 0xacc7e7c0 ++1, 280033, 1024, 0x32a07c98 ++1, 282122, 1024, 0x202ca667 ++1, 284212, 1024, 0xdf969011 ++1, 286302, 1024, 0xc434d238 ++1, 288392, 1024, 0xe9ad7562 ++0, 289980, 7065, 0x45035c5c ++1, 290482, 1024, 0xb51b6b50 ++1, 292571, 1024, 0xe70aecd3 ++1, 294661, 1024, 0x03c816b2 ++1, 296751, 1024, 0x869fdf25 ++1, 298841, 1024, 0xd40a0a62 ++0, 299970, 7269, 0x72edbb76 ++1, 300931, 1024, 0x5af7dd35 ++1, 303020, 1024, 0x891ffc72 ++1, 305110, 1024, 0x1ff68a08 ++1, 307200, 1024, 0x5a7517a9 ++1, 309290, 1024, 0x0f959f74 ++0, 309960, 7220, 0xb926772f ++1, 311380, 1024, 0xe92a12a2 ++1, 313469, 1024, 0x38000e55 ++1, 315559, 1024, 0x39fbdd70 ++1, 317649, 1024, 0xca3d9184 ++1, 319739, 1024, 0x66c8995b ++0, 319950, 7326, 0x0a66c632 ++1, 321829, 1024, 0xac25acea ++1, 323918, 1024, 0x3cd1046c ++1, 326008, 1024, 0x6a1df31c ++1, 328098, 1024, 0x21ca10a1 ++0, 329940, 7225, 0xe39076ab ++1, 330188, 1024, 0x1aeccedc ++1, 332278, 1024, 0xddea1335 ++1, 334367, 1024, 0x19f5ca9f ++1, 336457, 1024, 0x88e95e43 ++1, 338547, 1024, 0x726284fe ++0, 339930, 7265, 0xe0209036 ++1, 340637, 1024, 0x6b85b40e ++1, 342727, 1024, 0x111fee2a ++1, 344816, 1024, 0x3656b588 ++1, 346906, 1024, 0xa5a2b552 ++1, 348996, 1024, 0x38fb2467 ++0, 349920, 7337, 0x7a5dc093 ++1, 351086, 1024, 0xaa919ccc ++1, 353176, 1024, 0x15993dbc ++1, 355265, 1024, 0xbe01a7b9 ++1, 357355, 1024, 0xefe93c09 ++1, 359445, 1024, 0x1bb566e5 ++0, 360000, 7246, 0x519a7a3c ++1, 361535, 1024, 0x15ce6237 ++1, 363624, 1024, 0xa8552e66 ++1, 365714, 1024, 0x9d80187e ++1, 367804, 1024, 0x5df3fc30 ++1, 369894, 1024, 0x1a312aa5 ++0, 369990, 7266, 0x352c8078 ++1, 371984, 1024, 0x6bb8e302 ++1, 374073, 1024, 0xbd9684bb ++1, 376163, 1024, 0x78b0b166 ++1, 378253, 1024, 0xd9af5eae ++0, 379980, 7323, 0xcaf69d7c ++1, 380343, 1024, 0xdb90fe82 ++1, 382433, 1024, 0x327614e9 ++1, 384522, 1024, 0x1f19b7fe ++1, 386612, 1024, 0x46c53f96 ++1, 388702, 1024, 0x921b2189 ++0, 389970, 7309, 0x98c1e6f7 ++1, 390792, 1024, 0xa8fbc85a ++1, 392882, 1024, 0xabfdaaae ++1, 394971, 1024, 0x6acc7387 ++1, 397061, 1024, 0x0d9c27b5 ++1, 399151, 1024, 0xba4dd809 ++0, 399960, 7121, 0x913d5bd6 ++1, 401241, 1024, 0x2a2ad521 ++1, 403331, 1024, 0x892de38a ++1, 405420, 1024, 0xdc97a2eb ++1, 407510, 1024, 0x4f614ca4 ++1, 409600, 1024, 0x9c8a77ea ++0, 409950, 7088, 0x56302362 ++1, 411690, 1024, 0x2d30e646 ++1, 413780, 1024, 0x74e800a7 ++1, 415869, 1024, 0x1e01fb02 ++1, 417959, 1024, 0x4ed2c1d8 ++0, 419940, 7104, 0xc0d14f78 ++1, 420049, 1024, 0xf2fdbe63 ++1, 422139, 1024, 0x8d6f63a1 ++1, 424229, 1024, 0xded468d9 ++1, 426318, 1024, 0xccad839e ++1, 428408, 1024, 0xdde7c082 ++0, 429930, 7169, 0xd03c825b ++1, 430498, 1024, 0x548613c5 ++1, 432588, 1024, 0x383909bd ++1, 434678, 1024, 0xfd37627b ++1, 436767, 1024, 0x6d95a481 ++1, 438857, 1024, 0x56aa87fa ++0, 439920, 7038, 0x1ecc201d ++1, 440947, 1024, 0x7b67258c ++1, 443037, 1024, 0x7dd99a92 ++1, 445127, 1024, 0x4a66d102 ++1, 447216, 1024, 0x7b3fce51 ++1, 449306, 1024, 0xbbd968aa ++0, 450000, 7015, 0x83c94454 ++1, 451396, 1024, 0x8283ec36 ++1, 453486, 1024, 0x3c96493d ++1, 455576, 1024, 0xfa4f8cf8 ++1, 457665, 1024, 0xe2cf872d ++1, 459755, 1024, 0x0a9e7aa6 ++0, 459990, 6983, 0x9e51f54d ++1, 461845, 1024, 0x6e7a0550 ++1, 463935, 1024, 0x3acfea2f ++1, 466024, 1024, 0x7111d0fa ++1, 468114, 1024, 0xe9a1eca9 ++0, 469980, 7088, 0x70d33de1 ++1, 470204, 1024, 0x24da6c46 ++1, 472294, 1024, 0x117cff37 ++1, 474384, 1024, 0x0f27cab6 ++1, 476473, 1024, 0x69b6b4e6 ++1, 478563, 1024, 0x1e6cc841 ++0, 479970, 7096, 0x4d0f81b5 ++1, 480653, 1024, 0xb01e2365 ++1, 482743, 1024, 0x14e200d3 ++1, 484833, 1024, 0xd1184c98 ++1, 486922, 1024, 0xef9140e9 ++1, 489012, 1024, 0x4cbb645e ++0, 489960, 7106, 0xd1a83ddc ++1, 491102, 1024, 0xe7fe2f06 ++1, 493192, 1024, 0xf8c45028 ++1, 495282, 1024, 0x561358f4 ++1, 497371, 1024, 0xd0129b77 ++1, 499461, 1024, 0xcc636e88 ++0, 499950, 7219, 0x20f47fe4 ++1, 501551, 1024, 0xe9406321 ++1, 503641, 1024, 0x9f16a041 ++1, 505731, 1024, 0x468bf409 ++1, 507820, 1024, 0x3df70f7b ++1, 509910, 1024, 0xa880b11b ++0, 509940, 7184, 0x45dc6a0e ++1, 512000, 1024, 0x3286c489 ++1, 514090, 1024, 0x39fe9ebc ++1, 516180, 1024, 0xc533d83b ++1, 518269, 1024, 0x153b195d ++0, 519930, 7222, 0x488c6499 ++1, 520359, 1024, 0xd84786a1 ++1, 522449, 1024, 0xdc295aaa ++1, 524539, 1024, 0xfb764d8c ++1, 526629, 1024, 0xeebc9db9 ++1, 528718, 1024, 0x7ba9403e ++0, 529920, 7254, 0xbd097ba7 ++1, 530808, 1024, 0x4e5571ec ++1, 532898, 1024, 0xd965fad4 ++1, 534988, 1024, 0x87e259f2 ++1, 537078, 1024, 0xae7e533b ++1, 539167, 1024, 0x313cf4d6 ++0, 540000, 7189, 0x46e06d43 ++1, 541257, 1024, 0xe1844c90 ++1, 543347, 1024, 0xbb057b44 ++1, 545437, 1024, 0xa5099687 ++1, 547527, 1024, 0xbff10707 ++1, 549616, 1024, 0x37c4ffc0 ++0, 549990, 7283, 0x19dd7319 ++1, 551706, 1024, 0xf9fb6caa ++1, 553796, 1024, 0x3b6a3a1f ++1, 555886, 1024, 0x83431edb ++1, 557976, 1024, 0x1eb713cf ++0, 559980, 7161, 0x23171d02 ++1, 560065, 1024, 0xd7b07a6d ++1, 562155, 1024, 0x81ae3391 ++1, 564245, 1024, 0xf150130a ++1, 566335, 1024, 0x09678eaa ++1, 568424, 1024, 0xb94e06f1 ++0, 569970, 6976, 0xcc610c26 ++1, 570514, 1024, 0x67b1dbc9 ++1, 572604, 1024, 0xd6edc235 ++1, 574694, 1024, 0x34e4c499 ++1, 576784, 1024, 0xeefd89c0 ++1, 578873, 1024, 0x38afdaf1 ++0, 579960, 7056, 0x6cd917b0 ++1, 580963, 1024, 0x29a60d76 ++1, 583053, 1024, 0xe28a4372 ++1, 585143, 1024, 0x7089454d ++1, 587233, 1024, 0x0c01bb7b ++1, 589322, 1024, 0xbd776a72 ++0, 589950, 6736, 0x02b78951 ++1, 591412, 1024, 0x86776fd0 ++1, 593502, 1024, 0xb37c88f7 ++1, 595592, 1024, 0x5f90aaf8 ++1, 597682, 1024, 0x203d4222 ++1, 599771, 1024, 0x382692a6 ++0, 599940, 6540, 0x767e0854 ++1, 601861, 1024, 0xf37c95fd ++1, 603951, 1024, 0x6c0b8877 ++1, 606041, 1024, 0x2e54a8b6 ++1, 608131, 1024, 0x7f266488 ++0, 609930, 6170, 0xc84962fb ++1, 610220, 1024, 0xfbf20f9a ++1, 612310, 1024, 0xf2985cc0 ++1, 614400, 1024, 0xc7075340 ++1, 616490, 1024, 0xe4585695 ++1, 618580, 1024, 0xbdffa380 ++0, 619920, 6169, 0x27e06c03 ++1, 620669, 1024, 0x2422a8a9 ++1, 622759, 1024, 0x59cbd75f ++1, 624849, 1024, 0x04ad1a8c ++1, 626939, 1024, 0x33c09191 ++1, 629029, 1024, 0x55efa6fd ++0, 630000, 5864, 0xd14db83f ++1, 631118, 1024, 0xf73d0e5d ++1, 633208, 1024, 0x6141ebae ++1, 635298, 1024, 0x7db17a68 ++1, 637388, 1024, 0xa6c690b6 ++1, 639478, 1024, 0xa6fd6725 ++0, 639990, 5375, 0x4a21055d ++1, 641567, 1024, 0x50a90b9b ++1, 643657, 1024, 0xef990dc8 ++1, 645747, 1024, 0x75adf6b5 ++1, 647837, 1024, 0x61eac43e ++1, 649927, 1024, 0x67797a19 ++0, 649980, 5206, 0x95ead3cb ++1, 652016, 1024, 0xf325277a ++1, 654106, 1024, 0x18bf254a ++1, 656196, 1024, 0x2ce6bee3 ++1, 658286, 1024, 0x8d320860 ++0, 659970, 5220, 0xcfdcc37e ++1, 660376, 1024, 0xc979b6e8 ++1, 662465, 1024, 0xdb644b41 ++1, 664555, 1024, 0xe1b368ba ++1, 666645, 1024, 0xacc53d15 ++1, 668735, 1024, 0x42ea8c18 ++0, 669960, 4946, 0x2d864a77 ++1, 670824, 1024, 0xe52c99a4 ++1, 672914, 1024, 0xd7db54a6 ++1, 675004, 1024, 0x7f27a7e3 ++1, 677094, 1024, 0xf7ffeaa9 ++1, 679184, 1024, 0x792b6088 ++0, 679950, 4390, 0x2ab9f462 ++1, 681273, 1024, 0x61d99724 ++1, 683363, 1024, 0x5213720e ++1, 685453, 1024, 0xac09dd30 ++1, 687543, 1024, 0x960bf6bb ++1, 689633, 1024, 0xc90168e1 ++0, 689940, 4051, 0x1d09592e ++1, 691722, 1024, 0x43b45768 ++1, 693812, 1024, 0x935d60a1 ++1, 695902, 1024, 0x9a342ef2 ++1, 697992, 1024, 0xc894709f ++0, 699930, 3680, 0x39bd6a12 ++1, 700082, 1024, 0x59b43b07 ++1, 702171, 1024, 0x36a1a98d ++1, 704261, 1024, 0x9e1a121c ++1, 706351, 1024, 0x02208b78 ++1, 708441, 1024, 0xd1d7b274 ++0, 709920, 2910, 0x6337ece9 ++1, 710531, 1024, 0xdacd5096 ++1, 712620, 1024, 0x51b71ead ++1, 714710, 1024, 0xd009a7ca ++1, 716800, 1024, 0xb6d5a938 ++1, 718890, 1024, 0xf3d45e47 ++0, 720000, 2153, 0xf4e3bc17 ++1, 720980, 1024, 0xea8e04fc ++1, 723069, 1024, 0x0b928bd8 ++1, 725159, 1024, 0x0f02caec ++1, 727249, 1024, 0xe2b137a8 ++1, 729339, 1024, 0xd5f94892 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CBW8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CBW8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CBW8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CBW8 2012-05-14 14:08:55.708367636 +0200 +@@ -0,0 +1 @@ ++0, 0, 16384, 0x267e21ef +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CCM8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CCM8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CCM8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CCM8 2012-05-14 14:08:55.709367656 +0200 +@@ -0,0 +1 @@ ++0, 0, 65536, 0x47e97fe9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC16 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC16 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC16 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC16 2012-05-14 14:08:55.709367656 +0200 +@@ -0,0 +1 @@ ++0, 0, 32768, 0xa6b3d20d +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC24 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC24 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC24 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC24 2012-05-14 14:08:55.710367676 +0200 +@@ -0,0 +1 @@ ++0, 0, 49152, 0xaca4bc29 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC32 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC32 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC32 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-CTC32 2012-05-14 14:08:55.710367676 +0200 +@@ -0,0 +1 @@ ++0, 0, 65536, 0xcf98bc29 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UBW8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UBW8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UBW8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UBW8 2012-05-14 14:08:55.711367696 +0200 +@@ -0,0 +1 @@ ++0, 0, 16384, 0x267e21ef +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UCM8 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UCM8 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UCM8 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UCM8 2012-05-14 14:08:55.711367696 +0200 +@@ -0,0 +1 @@ ++0, 0, 65536, 0x47e97fe9 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC16 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC16 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC16 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC16 2012-05-14 14:08:55.711367696 +0200 +@@ -0,0 +1 @@ ++0, 0, 32768, 0xa6b3d20d +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC24 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC24 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC24 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC24 2012-05-14 14:08:55.712367716 +0200 +@@ -0,0 +1 @@ ++0, 0, 49152, 0xaca4bc29 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC32 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC32 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC32 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-conformance-UTC32 2012-05-14 14:08:55.713367736 +0200 +@@ -0,0 +1 @@ ++0, 0, 65536, 0xcf98bc29 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-top-to-bottom xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-top-to-bottom +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/targa-top-to-bottom 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/targa-top-to-bottom 2012-05-14 14:08:55.713367736 +0200 +@@ -0,0 +1 @@ ++0, 0, 196608, 0xb29ec51a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/thp-mjpeg-adpcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/thp-mjpeg-adpcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/thp-mjpeg-adpcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/thp-mjpeg-adpcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1,143 +0,0 @@ +-0, 0, 291840, 0xbd7e0b22 +-1, 0, 4312, 0x469714f6 +-0, 3003, 291840, 0xf6e12ca5 +-1, 3032, 4256, 0xe03dd882 +-0, 6006, 291840, 0x528c7049 +-1, 6024, 4312, 0x46b901f7 +-0, 9009, 291840, 0x93055de9 +-1, 9056, 4256, 0x8d4a54e4 +-0, 12012, 291840, 0xf95a51c1 +-1, 12049, 4256, 0xfd616b67 +-0, 15015, 291840, 0x6ad3a65a +-1, 15041, 4312, 0xefe62302 +-0, 18018, 291840, 0x494684a7 +-1, 18073, 4256, 0xab11684e +-0, 21021, 291840, 0x74c14eb1 +-1, 21066, 4256, 0xb4b3feb8 +-0, 24024, 291840, 0x149fcb7e +-1, 24058, 4312, 0x71db6461 +-0, 27027, 291840, 0x25649761 +-1, 27090, 4256, 0x090e5efa +-0, 30030, 291840, 0xbc3f9052 +-1, 30083, 4256, 0x36f49c28 +-0, 33033, 291840, 0x080edfff +-1, 33075, 4312, 0x0fe3d262 +-0, 36036, 291840, 0x6d7ad684 +-1, 36107, 4256, 0x199ce269 +-0, 39039, 291840, 0x6d53844d +-1, 39099, 4256, 0x98342d05 +-0, 42042, 291840, 0xf7ad5385 +-1, 42092, 4312, 0xb6fb7ebe +-0, 45045, 291840, 0x0241b56a +-1, 45124, 4256, 0x033dd562 +-0, 48048, 291840, 0x120122c8 +-1, 48116, 4256, 0xc2cc17e0 +-0, 51051, 291840, 0x31b0f32a +-1, 51109, 4312, 0x4bb3ff50 +-0, 54054, 291840, 0x14068b98 +-1, 54141, 4256, 0x6f2671ef +-0, 57057, 291840, 0xeeec658b +-1, 57133, 4256, 0x5a337bf4 +-0, 60060, 291840, 0x9376374c +-1, 60126, 4312, 0xa71f6967 +-0, 63063, 291840, 0x091e8c6e +-1, 63158, 4256, 0x48084aa9 +-0, 66066, 291840, 0x744ad07f +-1, 66150, 4256, 0x3cce4218 +-0, 69069, 291840, 0xf99c554e +-1, 69143, 4312, 0xcbb8f73d +-0, 72072, 291840, 0xc84bd677 +-1, 72174, 4256, 0x36825021 +-0, 75075, 291840, 0x3898d474 +-1, 75167, 4256, 0xeae036c6 +-0, 78078, 291840, 0x1e2910c8 +-1, 78159, 4312, 0x0d650ac6 +-0, 81081, 291840, 0xb11f58bc +-1, 81191, 4256, 0xfba4f58c +-0, 84084, 291840, 0xf89170ee +-1, 84184, 4256, 0x54311f9b +-0, 87087, 291840, 0x8f239dc3 +-1, 87176, 4312, 0x286386b3 +-0, 90090, 291840, 0x8538c76c +-1, 90208, 4256, 0x871896de +-0, 93093, 291840, 0x162ee66f +-1, 93201, 4256, 0x9ef9f970 +-0, 96096, 291840, 0x5f8708a5 +-1, 96193, 4312, 0xf9ae97f1 +-0, 99099, 291840, 0x95802dfb +-1, 99225, 4256, 0x0ad0d765 +-0, 102102, 291840, 0xc424630d +-1, 102218, 4256, 0x8e6aa9b5 +-0, 105105, 291840, 0xfb8a8667 +-1, 105210, 4312, 0x8362787b +-0, 108108, 291840, 0xbad79af5 +-1, 108242, 4256, 0x9b6a5d9c +-0, 111111, 291840, 0xc733b325 +-1, 111234, 4256, 0xfb715d8f +-0, 114114, 291840, 0x4bfbcd70 +-1, 114227, 4312, 0x02bd8075 +-0, 117117, 291840, 0x502cd950 +-1, 117259, 4256, 0x428eb932 +-0, 120120, 291840, 0x8461ca2c +-1, 120251, 4256, 0x17ea8c94 +-0, 123123, 291840, 0x00219b0d +-1, 123244, 4312, 0xb3e761d7 +-0, 126126, 291840, 0xa4de45e1 +-1, 126276, 4256, 0x0919755a +-0, 129129, 291840, 0xacd3f4df +-1, 129268, 4256, 0x5e520edd +-0, 132132, 291840, 0x2203a369 +-1, 132261, 4312, 0x69aa070e +-0, 135135, 291840, 0x0a66effa +-1, 135293, 4256, 0xf8192f7d +-0, 138138, 291840, 0x7ac1fd91 +-1, 138285, 4256, 0xaad4475c +-0, 141141, 291840, 0x84970aa7 +-1, 141278, 4312, 0x0cabcfcb +-0, 144144, 291840, 0x569d145f +-1, 144309, 4256, 0x952f0f96 +-0, 147147, 291840, 0xe51efe1b +-1, 147302, 4256, 0x1b805a0c +-0, 150150, 291840, 0x38e2cd78 +-1, 150294, 4312, 0x93043d2a +-0, 153153, 291840, 0x93428ea2 +-1, 153326, 4256, 0x38b99e44 +-0, 156156, 291840, 0x3d3f5b17 +-1, 156319, 4256, 0x60cc52ff +-0, 159159, 291840, 0x9546127d +-1, 159311, 4312, 0x6a875849 +-0, 162162, 291840, 0x4178be54 +-1, 162343, 4256, 0xd08d6d0e +-0, 165165, 291840, 0x0d0f8036 +-1, 165336, 4256, 0x36bfe48e +-0, 168168, 291840, 0xc20557b9 +-1, 168328, 4312, 0x795c6134 +-0, 171171, 291840, 0x6d4b2d64 +-1, 171360, 4256, 0x4fd79583 +-0, 174174, 291840, 0xa750125d +-1, 174353, 4256, 0x65e2ab9f +-0, 177177, 291840, 0x04623ce3 +-1, 177345, 4312, 0xedeede4a +-0, 180180, 291840, 0xc7f2bbc7 +-1, 180377, 4256, 0x097e0d09 +-0, 183183, 291840, 0x6e271336 +-1, 183369, 4256, 0x58afa133 +-0, 186186, 291840, 0xcfbd4246 +-1, 186362, 4312, 0x442525b5 +-0, 189189, 291840, 0xe1493be9 +-1, 189394, 4256, 0x6645c591 +-0, 192192, 291840, 0x6c731194 +-1, 192386, 4256, 0xb0dd948a +-0, 195195, 291840, 0x0fc30cc2 +-1, 195379, 4312, 0x12684e69 +-0, 198198, 291840, 0x967427f3 +-1, 198411, 4256, 0xb45098e3 +-0, 201201, 291840, 0x55ae3b00 +-1, 201403, 4256, 0xb6d3c61c +-0, 204204, 291840, 0xbe4f200c +-1, 204396, 4312, 0xb46b5b22 +-0, 207207, 291840, 0xc515e443 +-1, 207428, 4256, 0x9a556830 +-0, 210210, 291840, 0xd738bd69 +-1, 210420, 4256, 0x67ca2b35 +-0, 213213, 291840, 0xa8e0ab69 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiertex-seq xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiertex-seq +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiertex-seq 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiertex-seq 2012-05-14 14:08:55.715367776 +0200 +@@ -1,147 +1,96 @@ +-1, 0, 1764, 0x00000000 + 0, 0, 98304, 0x2e5db4a4 +-1, 3600, 1764, 0x80a253d9 ++1, 0, 1764, 0x00000000 + 0, 3600, 98304, 0xb20c19d0 ++1, 3600, 1764, 0x80a253d9 ++0, 7200, 98304, 0x6b8538c0 + 1, 7200, 1764, 0x95a16721 +-0, 7200, 98304, 0xb20c19d0 ++0, 10800, 98304, 0x172207e3 + 1, 10800, 1764, 0x0f0d4cb6 +-0, 10800, 98304, 0xb20c19d0 ++0, 14400, 98304, 0x63fb7dc1 + 1, 14400, 1764, 0x75026779 +-0, 14400, 98304, 0x6b8538c0 ++0, 18000, 98304, 0x37cf1601 + 1, 18000, 1764, 0xb4356e37 +-0, 18000, 98304, 0x6b8538c0 ++0, 21600, 98304, 0x82941990 + 1, 21600, 1764, 0xfafa64cb +-0, 21600, 98304, 0x6b8538c0 ++0, 25200, 98304, 0xe0a5309e + 1, 25200, 1764, 0xe8fd7970 +-0, 25200, 98304, 0x172207e3 ++0, 28800, 98304, 0x164cb67d + 1, 28800, 1764, 0x666879b7 +-0, 28800, 98304, 0x172207e3 ++0, 32400, 98304, 0xed2189f8 + 1, 32400, 1764, 0xf2cd7770 +-0, 32400, 98304, 0x172207e3 ++0, 36000, 98304, 0x7215e529 + 1, 36000, 1764, 0x54317a1c +-0, 36000, 98304, 0x172207e3 ++0, 39600, 98304, 0x170c783b + 1, 39600, 1764, 0x9c396930 +-0, 39600, 98304, 0x63fb7dc1 ++0, 43200, 98304, 0xf6bd74c7 + 1, 43200, 1764, 0x87115ec4 +-0, 43200, 98304, 0x63fb7dc1 ++0, 46800, 98304, 0x1efd38c4 + 1, 46800, 1764, 0x0c9b69b6 +-0, 46800, 98304, 0x63fb7dc1 ++0, 50400, 98304, 0x29c26bba + 1, 50400, 1764, 0x8c3a758a +-0, 50400, 98304, 0x37cf1601 ++0, 54000, 98304, 0x880a6313 + 1, 54000, 1764, 0x605d776a +-0, 54000, 98304, 0x37cf1601 ++0, 57600, 98304, 0x73f5bb00 + 1, 57600, 1764, 0x0556852d +-0, 57600, 98304, 0x37cf1601 ++0, 61200, 98304, 0xc85b19ec + 1, 61200, 1764, 0x7d4363f8 +-0, 61200, 98304, 0x37cf1601 ++0, 64800, 98304, 0x00000000 + 1, 64800, 1764, 0xc5cd75d0 +-0, 64800, 98304, 0x82941990 ++0, 68400, 98304, 0x00000000 + 1, 68400, 1764, 0x3ff3646d +-0, 68400, 98304, 0x82941990 ++0, 72000, 98304, 0x00000000 + 1, 72000, 1764, 0x10136d25 +-0, 72000, 98304, 0x82941990 + 1, 75600, 1764, 0xeb1a6cd0 +-0, 75600, 98304, 0x82941990 + 1, 79200, 1764, 0xef937ed1 +-0, 79200, 98304, 0xe0a5309e + 1, 82800, 1764, 0x2d2b6f79 +-0, 82800, 98304, 0xe0a5309e + 1, 86400, 1764, 0x6f457231 +-0, 86400, 98304, 0xe0a5309e + 1, 90000, 1764, 0x56267c9d +-0, 90000, 98304, 0x164cb67d + 1, 93600, 1764, 0xd49e79c8 +-0, 93600, 98304, 0x164cb67d + 1, 97200, 1764, 0xc726703d +-0, 97200, 98304, 0x164cb67d + 1, 100800, 1764, 0x2abf8074 +-0, 100800, 98304, 0x164cb67d + 1, 104400, 1764, 0xb50c556d +-0, 104400, 98304, 0xed2189f8 + 1, 108000, 1764, 0xc1f2523c +-0, 108000, 98304, 0xed2189f8 + 1, 111600, 1764, 0x850a6f93 +-0, 111600, 98304, 0xed2189f8 + 1, 115200, 1764, 0x8da76c31 +-0, 115200, 98304, 0x7215e529 + 1, 118800, 1764, 0xfcccdf13 +-0, 118800, 98304, 0x7215e529 + 1, 122400, 1764, 0x00000000 +-0, 122400, 98304, 0x7215e529 + 1, 126000, 1764, 0x00000000 +-0, 126000, 98304, 0x7215e529 + 1, 129600, 1764, 0x00000000 +-0, 129600, 98304, 0x170c783b + 1, 133200, 1764, 0x00000000 +-0, 133200, 98304, 0x170c783b + 1, 136800, 1764, 0x00000000 +-0, 136800, 98304, 0x170c783b + 1, 140400, 1764, 0x00000000 +-0, 140400, 98304, 0xf6bd74c7 + 1, 144000, 1764, 0x00000000 +-0, 144000, 98304, 0xf6bd74c7 + 1, 147600, 1764, 0x00000000 +-0, 147600, 98304, 0xf6bd74c7 + 1, 151200, 1764, 0x00000000 +-0, 151200, 98304, 0xf6bd74c7 + 1, 154800, 1764, 0x00000000 +-0, 154800, 98304, 0x1efd38c4 + 1, 158400, 1764, 0x00000000 +-0, 158400, 98304, 0x1efd38c4 + 1, 162000, 1764, 0x00000000 +-0, 162000, 98304, 0x1efd38c4 + 1, 165600, 1764, 0x00000000 +-0, 165600, 98304, 0x1efd38c4 + 1, 169200, 1764, 0x00000000 +-0, 169200, 98304, 0x29c26bba + 1, 172800, 1764, 0x00000000 +-0, 172800, 98304, 0x29c26bba + 1, 176400, 1764, 0x00000000 +-0, 176400, 98304, 0x29c26bba + 1, 180000, 1764, 0x00000000 +-0, 180000, 98304, 0x880a6313 + 1, 183600, 1764, 0x00000000 +-0, 183600, 98304, 0x880a6313 + 1, 187200, 1764, 0x00000000 +-0, 187200, 98304, 0x880a6313 + 1, 190800, 1764, 0x00000000 +-0, 190800, 98304, 0x880a6313 + 1, 194400, 1764, 0x00000000 +-0, 194400, 98304, 0x73f5bb00 + 1, 198000, 1764, 0x00000000 +-0, 198000, 98304, 0x73f5bb00 + 1, 201600, 1764, 0x00000000 +-0, 201600, 98304, 0x73f5bb00 + 1, 205200, 1764, 0x00000000 +-0, 205200, 98304, 0xc85b19ec + 1, 208800, 1764, 0x00000000 +-0, 208800, 98304, 0xc85b19ec + 1, 212400, 1764, 0x00000000 +-0, 212400, 98304, 0xc85b19ec + 1, 216000, 1764, 0x00000000 +-0, 216000, 98304, 0xc85b19ec + 1, 219600, 1764, 0x00000000 +-0, 219600, 98304, 0x00000000 + 1, 223200, 1764, 0x00000000 +-0, 223200, 98304, 0x00000000 + 1, 226800, 1764, 0x00000000 +-0, 226800, 98304, 0x00000000 + 1, 230400, 1764, 0x00000000 +-0, 230400, 98304, 0x00000000 + 1, 234000, 1764, 0x00000000 +-0, 234000, 98304, 0x00000000 + 1, 237600, 1764, 0x00000000 +-0, 237600, 98304, 0x00000000 + 1, 241200, 1764, 0x00000000 +-0, 241200, 98304, 0x00000000 + 1, 244800, 1764, 0x00000000 +-0, 244800, 98304, 0x00000000 + 1, 248400, 1764, 0x00000000 +-0, 248400, 98304, 0x00000000 + 1, 252000, 1764, 0x00000000 +-0, 252000, 98304, 0x00000000 + 1, 255600, 1764, 0x00000000 +-0, 255600, 98304, 0x00000000 + 1, 259200, 1764, 0x00000000 + 1, 262800, 1764, 0x00000000 + 1, 266400, 1764, 0x00000000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiff-fax-g3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiff-fax-g3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiff-fax-g3 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiff-fax-g3 2012-05-14 14:08:55.715367776 +0200 +@@ -0,0 +1 @@ ++0, 0, 1000384, 0xb758eb8b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiff-fax-g3s xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiff-fax-g3s +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tiff-fax-g3s 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tiff-fax-g3s 2012-05-14 14:08:55.716367796 +0200 +@@ -0,0 +1 @@ ++0, 0, 1000384, 0xb758eb8b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion1-15 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion1-15 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion1-15 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion1-15 2012-05-14 14:08:55.717367816 +0200 +@@ -1,218 +1,218 @@ +-1, 0, 10832, 0xe1a811fa +-0, 0, 161280, 0x7041748d +-1, 5527, 10832, 0xb47841f9 +-0, 6000, 161280, 0x3cc4dfb5 +-1, 11053, 10832, 0x839eedf1 +-0, 12000, 161280, 0xca3af22d +-1, 16580, 10832, 0xb48b1f60 +-0, 18000, 161280, 0x23ad1d85 +-1, 22106, 10832, 0x743936c0 +-0, 24000, 161280, 0x9c9cf364 +-1, 27633, 10832, 0xe1f039fb +-0, 30000, 161280, 0x1551d6a8 +-1, 33159, 10832, 0xef00751a +-0, 36000, 161280, 0xc39f6b95 +-1, 38686, 10832, 0x401ed099 +-0, 42000, 161280, 0x3b036dcc +-1, 44212, 10832, 0x432a53bd +-0, 48000, 161280, 0xa6fac1db +-1, 49739, 10832, 0xc4276bfd +-0, 54000, 161280, 0x67656b62 +-1, 55265, 10832, 0x51f0fa8c +-0, 60000, 161280, 0xb41f47d1 +-1, 60792, 10832, 0xcebae622 +-0, 66000, 161280, 0xc207249e +-1, 66318, 10832, 0xe9f6dc1f +-1, 71845, 10832, 0xda087fee +-0, 72000, 161280, 0xbee8f843 +-1, 77371, 10832, 0x67a621bb +-0, 78000, 161280, 0x092acf46 +-1, 82898, 10832, 0xd7be207f +-0, 84000, 161280, 0x8d9e2680 +-1, 88424, 10832, 0x19d32507 +-0, 90000, 161280, 0x8becc20c +-1, 93951, 10832, 0xe1a3fbfa +-0, 96000, 161280, 0x655e444e +-1, 99478, 10832, 0xd10df779 +-0, 102000, 161280, 0x5c112da0 +-1, 105004, 10832, 0x4428e1a7 +-0, 108000, 161280, 0x232fa9eb +-1, 110531, 10832, 0x7ea9b33d +-0, 114000, 161280, 0x9721745d +-1, 116057, 10832, 0x6852a5a5 +-0, 120000, 161280, 0x92f1d880 +-1, 121584, 10832, 0xfeb78863 +-0, 126000, 161280, 0x16233978 +-1, 127110, 10832, 0xf157f928 +-0, 132000, 161280, 0x19a27e69 +-1, 132637, 10832, 0x86414b3e +-0, 138000, 161280, 0x7b6ad73a +-1, 138163, 10832, 0x2e28cdf6 +-1, 143690, 10832, 0x00212e44 +-0, 144000, 161280, 0xa7a674aa +-1, 149216, 10832, 0x2d7f9378 +-0, 150000, 161280, 0x4e434abb +-1, 154743, 10832, 0x84cb25d7 +-0, 156000, 161280, 0xb96eea14 +-1, 160269, 10832, 0x3aca41fa +-0, 162000, 161280, 0x1350188c +-1, 165796, 10832, 0x27ad34b9 +-0, 168000, 161280, 0x79c6f305 +-1, 171322, 10832, 0xe665144a +-0, 174000, 161280, 0xa9c7782d +-1, 176849, 10832, 0xf9546626 +-0, 180000, 161280, 0x40a4f456 +-1, 182376, 10832, 0xe71c4f22 +-0, 186000, 161280, 0xaf291ed6 +-1, 187902, 10832, 0x5e61869c +-0, 192000, 161280, 0xab29b4e1 +-1, 193429, 10832, 0x571d2c10 +-0, 198000, 161280, 0xbfcd2712 +-1, 198955, 10832, 0xf0e08cd5 +-0, 204000, 161280, 0xff22a0d7 +-1, 204482, 10832, 0x66650e49 +-0, 210000, 161280, 0xb0ae88a9 +-1, 210008, 10832, 0x4024deaf +-1, 215535, 10832, 0xda7bdb14 +-0, 216000, 161280, 0x811d1259 +-1, 221061, 10832, 0xc27a342f +-0, 222000, 161280, 0x593c39a1 +-1, 226588, 10832, 0x574fe679 +-0, 228000, 161280, 0x5a5a97f8 +-1, 232114, 10832, 0x37db464e +-0, 234000, 161280, 0xa5639ecf +-1, 237641, 10832, 0xb1fa2a83 +-0, 240000, 161280, 0x543920c6 +-1, 243167, 10832, 0x3d98d9b7 +-0, 246000, 161280, 0xb41689ee +-1, 248694, 10832, 0xb7c908e2 +-0, 252000, 161280, 0xc0ad83de +-1, 254220, 10832, 0x9f7e44d8 +-0, 258000, 161280, 0x9e9e7456 +-1, 259747, 10832, 0xae9b8774 +-0, 264000, 161280, 0x777ccbfe +-1, 265273, 10832, 0x36916e3f +-0, 270000, 161280, 0x9c2df916 +-1, 270800, 10832, 0xd785f5ef +-0, 276000, 161280, 0xe0c13b35 +-1, 276327, 10832, 0x2a3a5673 +-1, 281853, 10832, 0x7320e379 +-0, 282000, 161280, 0x39bfa5a5 +-1, 287380, 10832, 0xec787be5 +-0, 288000, 161280, 0x35dfb264 +-1, 292906, 10832, 0xd0d13aa0 +-0, 294000, 161280, 0x43018613 +-1, 298433, 10832, 0x34dfcb17 +-0, 300000, 161280, 0x43584b8a +-1, 303959, 10832, 0x1a9c29f1 +-0, 306000, 161280, 0xa5cd230a +-1, 309486, 10832, 0x3e73dcc1 +-0, 312000, 161280, 0x6fe2cfb3 +-1, 315012, 10832, 0x7855b053 +-0, 318000, 161280, 0x88a7c0db +-1, 320539, 10832, 0x5588df8f +-0, 324000, 161280, 0x476f1cd2 +-1, 326065, 10832, 0x6f621299 +-0, 330000, 161280, 0x96401d49 +-1, 331592, 10832, 0xce7f39c2 +-0, 336000, 161280, 0x7d932919 +-1, 337118, 10832, 0xd88e6552 +-0, 342000, 161280, 0x06465481 +-1, 342645, 10832, 0xddc63597 +-0, 348000, 161280, 0x39631520 +-1, 348171, 10832, 0xe3071865 +-1, 353698, 10832, 0x2a44a123 +-0, 354000, 161280, 0xc3fff780 +-1, 359224, 10832, 0x08d85d45 +-0, 360000, 161280, 0xa81faf28 +-1, 364751, 10832, 0x4dc5f83a +-0, 366000, 161280, 0x7a311f4f +-1, 370278, 10832, 0x89497812 +-0, 372000, 161280, 0x52f9b931 +-1, 375804, 10832, 0x9ee1db54 +-0, 378000, 161280, 0x938cf016 +-1, 381331, 10832, 0x5277d611 +-0, 384000, 161280, 0xf8f6e19c +-1, 386857, 10832, 0x570a619c +-0, 390000, 161280, 0xca90561b +-1, 392384, 10832, 0xa217d70f +-0, 396000, 161280, 0x8594d06b +-1, 397910, 10832, 0x6f0ecbf4 +-0, 402000, 161280, 0xea32bf3b +-1, 403437, 10832, 0x2704b114 +-0, 408000, 161280, 0x4646111a +-1, 408963, 10832, 0xf24e679f +-0, 414000, 161280, 0xee891162 +-1, 414490, 10832, 0x05572099 +-0, 420000, 161280, 0xcfc32082 +-1, 420016, 10832, 0x33942d0c +-1, 425543, 10832, 0xa77ea674 +-0, 426000, 161280, 0x863c281a +-1, 431069, 10832, 0xeba663bc +-0, 432000, 161280, 0x01b591aa +-1, 436596, 10832, 0x1338524a +-0, 438000, 161280, 0x211fbc62 +-1, 442122, 10832, 0x6182b0b3 +-0, 444000, 161280, 0xae2bafe2 +-1, 447649, 10832, 0xa410a364 +-0, 450000, 161280, 0xcfe46dca +-1, 453176, 10832, 0x2f4374b0 +-0, 456000, 161280, 0xcf8fe8a3 +-1, 458702, 10832, 0xf41f3a07 +-0, 462000, 161280, 0x3f8474eb +-1, 464229, 10832, 0x2b1c50c6 +-0, 468000, 161280, 0x06da345a +-1, 469755, 10832, 0x3692ac89 +-0, 474000, 161280, 0xbd4d3280 +-1, 475282, 10832, 0x5d6bc87e +-0, 480000, 161280, 0xb5e70fea +-1, 480808, 10832, 0x1b1cda0c +-0, 486000, 161280, 0x0c99c804 +-1, 486335, 10832, 0x11eaa15f +-1, 491861, 10832, 0x73c7d7ef +-0, 492000, 161280, 0x19841ed4 +-1, 497388, 10832, 0x65d7e3be +-0, 498000, 161280, 0xf81dea50 +-1, 502914, 10832, 0xb9c00688 +-0, 504000, 161280, 0x7777d81c +-1, 508441, 10832, 0x0b98c125 +-0, 510000, 161280, 0x0497cfd8 +-1, 513967, 10832, 0x331ed413 +-0, 516000, 161280, 0x50b6eb64 +-1, 519494, 10832, 0x9b68f485 +-0, 522000, 161280, 0x5071fc07 +-1, 525020, 10832, 0x1b865c55 +-0, 528000, 161280, 0xbb7527fb +-1, 530547, 10832, 0x68cef565 +-0, 534000, 161280, 0x13054f1f +-1, 536073, 10832, 0x3a605f15 +-0, 540000, 161280, 0x4b78fb27 +-1, 541600, 10832, 0xd72ff22e +-0, 546000, 161280, 0xf504968f +-1, 547127, 10832, 0x1c672b67 +-0, 552000, 161280, 0x555b10b7 +-1, 552653, 10832, 0xfd1a7e7e +-0, 558000, 161280, 0xcc0dde40 +-1, 558180, 10832, 0x9bf20ead +-1, 563706, 10832, 0x00000000 +-0, 564000, 161280, 0xcc0dde40 +-1, 569233, 10832, 0x00000000 +-0, 570000, 161280, 0x367f60c8 +-1, 574759, 10832, 0x00000000 +-0, 576000, 161280, 0x367f60c8 +-1, 580286, 10832, 0x00000000 +-0, 582000, 161280, 0x367f60c8 +-1, 585812, 10832, 0x00000000 +-0, 588000, 161280, 0x367f60c8 +-1, 591339, 10832, 0x00000000 +-0, 594000, 161280, 0x367f60c8 +-1, 596865, 10832, 0x00000000 +-0, 600000, 161280, 0x367f60c8 +-1, 602392, 10832, 0x00000000 +-0, 606000, 161280, 0x367f60c8 +-1, 607918, 10832, 0x00000000 +-0, 612000, 161280, 0x367f60c8 +-1, 613445, 10832, 0x00000000 +-0, 618000, 161280, 0x367f60c8 +-1, 618971, 10832, 0x00000000 +-0, 624000, 161280, 0x367f60c8 ++0, 0, 161280, 0x677c9fb3 ++1, 0, 10836, 0x2a531236 ++1, 5529, 10836, 0xc58f45af ++0, 6000, 161280, 0xaa280e0a ++1, 11057, 10836, 0x436cf135 ++0, 12000, 161280, 0x8a4d2225 ++1, 16586, 10836, 0x3a6022cc ++0, 18000, 161280, 0xf10f46a8 ++1, 22114, 10836, 0x57e83a4a ++0, 24000, 161280, 0x98d9eab6 ++1, 27643, 10836, 0xca4b3a1b ++0, 30000, 161280, 0xa543ae1e ++1, 33171, 10836, 0xc3da7536 ++0, 36000, 161280, 0x79d717ae ++1, 38700, 10836, 0x8c57d47b ++0, 42000, 161280, 0x1a87e2cb ++1, 44229, 10836, 0x9a79572b ++0, 48000, 161280, 0xe5c000ac ++1, 49757, 10836, 0x7dbd6fd3 ++0, 54000, 161280, 0xa5827077 ++1, 55286, 10836, 0x4454fdde ++0, 60000, 161280, 0xfd0615ee ++1, 60814, 10836, 0x68aae686 ++0, 66000, 161280, 0xc6fdc861 ++1, 66343, 10836, 0x61f2df35 ++1, 71871, 10836, 0xe36883c6 ++0, 72000, 161280, 0xaa007c7e ++1, 77400, 10836, 0xefa62217 ++0, 78000, 161280, 0xf15e3a96 ++1, 82929, 10836, 0x63b92479 ++0, 84000, 161280, 0xce827ae1 ++1, 88457, 10836, 0xaf452579 ++0, 90000, 161280, 0xf379fc13 ++1, 93986, 10836, 0xdbb10001 ++0, 96000, 161280, 0x89686a0c ++1, 99514, 10836, 0xafb7f7a7 ++0, 102000, 161280, 0x7e8342bd ++1, 105043, 10836, 0xd4b1e591 ++0, 108000, 161280, 0x640dab86 ++1, 110571, 10836, 0x4d44b3bb ++0, 114000, 161280, 0xc6a86456 ++1, 116100, 10836, 0xff2ea5b3 ++0, 120000, 161280, 0xe360b538 ++1, 121629, 10836, 0x214e88ad ++0, 126000, 161280, 0xbcc21064 ++1, 127157, 10836, 0xde8bfc9a ++0, 132000, 161280, 0x95bc4e63 ++1, 132686, 10836, 0xb3cc4b6a ++0, 138000, 161280, 0x390fa1bd ++1, 138214, 10836, 0x670bce40 ++1, 143743, 10836, 0xc17d31b2 ++0, 144000, 161280, 0xa35b3bb9 ++1, 149271, 10836, 0x7bcb9392 ++0, 150000, 161280, 0x730b0779 ++1, 154800, 10836, 0x230e28c9 ++0, 156000, 161280, 0xf3c3a3eb ++1, 160329, 10836, 0x42df4204 ++0, 162000, 161280, 0x676ecbaa ++1, 165857, 10836, 0xfa9134b9 ++0, 168000, 161280, 0x06c4a4e5 ++1, 171386, 10836, 0x418c1844 ++0, 174000, 161280, 0x177d26d9 ++1, 176914, 10836, 0x93ba66b6 ++0, 180000, 161280, 0xdaf69ebe ++1, 182443, 10836, 0x264a4ffa ++0, 186000, 161280, 0xabadc296 ++1, 187971, 10836, 0x82c78a8e ++0, 192000, 161280, 0xec144665 ++1, 193500, 10836, 0x10d22fdc ++0, 198000, 161280, 0x6785aa48 ++1, 199029, 10836, 0x2d25906b ++0, 204000, 161280, 0x2a0cfcaf ++1, 204557, 10836, 0xa8a111fb ++0, 210000, 161280, 0x9288d513 ++1, 210086, 10836, 0xbd95df87 ++1, 215614, 10836, 0x500ddec0 ++0, 216000, 161280, 0x1d295ad0 ++1, 221143, 10836, 0x95d9350b ++0, 222000, 161280, 0xb9fd8406 ++1, 226671, 10836, 0xfa54ea1f ++0, 228000, 161280, 0x98bced49 ++1, 232200, 10836, 0x51b2467e ++0, 234000, 161280, 0x42e6fbae ++1, 237729, 10836, 0x5d772af9 ++0, 240000, 161280, 0xfd218209 ++1, 243257, 10836, 0xae25dd8d ++0, 246000, 161280, 0x21c2ef31 ++1, 248786, 10836, 0xe4bd0cb0 ++0, 252000, 161280, 0xce4be932 ++1, 254314, 10836, 0xb33544f0 ++0, 258000, 161280, 0xd5c0d5fc ++1, 259843, 10836, 0xd5658b12 ++0, 264000, 161280, 0xf8d13076 ++1, 265371, 10836, 0xeff66e5d ++0, 270000, 161280, 0xdbf86007 ++1, 270900, 10836, 0xb1fff6c5 ++0, 276000, 161280, 0x9475a651 ++1, 276429, 10836, 0x84db56b5 ++1, 281957, 10836, 0x0230e3c9 ++0, 282000, 161280, 0x41bf1542 ++1, 287486, 10836, 0xe58a7faf ++0, 288000, 161280, 0x6945297f ++1, 293014, 10836, 0xc4003e2a ++0, 294000, 161280, 0x2282025e ++1, 298543, 10836, 0x6360cbbf ++0, 300000, 161280, 0x55aace0c ++1, 304071, 10836, 0xc29c2a05 ++0, 306000, 161280, 0xc78aa51c ++1, 309600, 10836, 0xb294dd11 ++0, 312000, 161280, 0xb4b84e6c ++1, 315129, 10836, 0x4388b43b ++0, 318000, 161280, 0x3bbb3e44 ++1, 320657, 10836, 0xdd7be367 ++0, 324000, 161280, 0x4dd89d80 ++1, 326186, 10836, 0xb9f612a9 ++0, 330000, 161280, 0xa446a5c5 ++1, 331714, 10836, 0xb64a39fe ++0, 336000, 161280, 0x8f56b1d6 ++1, 337243, 10836, 0x6eba6594 ++0, 342000, 161280, 0xa170df87 ++1, 342771, 10836, 0xb4af35c1 ++0, 348000, 161280, 0x4740a4df ++1, 348300, 10836, 0x4e581c49 ++1, 353829, 10836, 0xb062a19f ++0, 354000, 161280, 0x86608ee7 ++1, 359357, 10836, 0x87cd6135 ++0, 360000, 161280, 0x629b4543 ++1, 364886, 10836, 0x37bffbd6 ++0, 366000, 161280, 0x697fb952 ++1, 370414, 10836, 0x6c797900 ++0, 372000, 161280, 0x98e84a51 ++1, 375943, 10836, 0x1615df36 ++0, 378000, 161280, 0x97949a90 ++1, 381471, 10836, 0xb472d9e9 ++0, 384000, 161280, 0x6a8c9b96 ++1, 387000, 10836, 0xdfff626e ++0, 390000, 161280, 0xafa714ab ++1, 392529, 10836, 0xffa6d771 ++0, 396000, 161280, 0x0cf39314 ++1, 398057, 10836, 0xa7f3cf96 ++0, 402000, 161280, 0x9ccc8171 ++1, 403586, 10836, 0xf556b50a ++0, 408000, 161280, 0x8232d5a8 ++1, 409114, 10836, 0x99b86b39 ++0, 414000, 161280, 0x250dd5cb ++1, 414643, 10836, 0x886920d3 ++0, 420000, 161280, 0xf764e43a ++1, 420171, 10836, 0xefb0305a ++1, 425700, 10836, 0x4ab7aa32 ++0, 426000, 161280, 0x2f4bec00 ++1, 431229, 10836, 0x7f106530 ++0, 432000, 161280, 0x76f1598b ++1, 436757, 10836, 0x6461559a ++0, 438000, 161280, 0xa91b84da ++1, 442286, 10836, 0x25e3b12b ++0, 444000, 161280, 0x011a77fb ++1, 447814, 10836, 0x32cfa3ba ++0, 450000, 161280, 0xdbf5341c ++1, 453343, 10836, 0x0bff78a4 ++0, 456000, 161280, 0x40d5abfa ++1, 458871, 10836, 0xe4323d53 ++0, 462000, 161280, 0x9fb8360c ++1, 464400, 10836, 0x70b35196 ++0, 468000, 161280, 0xabc5fba8 ++1, 469929, 10836, 0xf2b8b07f ++0, 474000, 161280, 0x98090909 ++1, 475457, 10836, 0x826cc972 ++0, 480000, 161280, 0x9a3613bd ++1, 480986, 10836, 0x8a0fdce8 ++0, 486000, 161280, 0x9071024f ++1, 486514, 10836, 0xa072a503 ++0, 492000, 161280, 0x4df39487 ++1, 492043, 10836, 0xd698d8e7 ++1, 497571, 10836, 0xfe80e794 ++0, 498000, 161280, 0x17658524 ++1, 503100, 10836, 0xdd580a5a ++0, 504000, 161280, 0xbcd794df ++1, 508629, 10836, 0x121bc1bb ++0, 510000, 161280, 0x2a14ae05 ++1, 514157, 10836, 0x8cebd7d9 ++0, 516000, 161280, 0x664feab2 ++1, 519686, 10836, 0x6eaef4d7 ++0, 522000, 161280, 0xf6b721f4 ++1, 525214, 10836, 0x8f0b5d0b ++0, 528000, 161280, 0xfec565f3 ++1, 530743, 10836, 0x40ccf61f ++0, 534000, 161280, 0xd39aabee ++1, 536271, 10836, 0xb6db5f1d ++0, 540000, 161280, 0x1f3d5de7 ++1, 541800, 10836, 0xa089f250 ++0, 546000, 161280, 0xaf97f50c ++1, 547329, 10836, 0xd3512f2b ++0, 552000, 161280, 0xe34b6b6a ++1, 552857, 10836, 0xfa127f74 ++0, 558000, 161280, 0x4117371e ++1, 558386, 10836, 0xd6a60ead ++1, 563914, 10836, 0x00000000 ++0, 564000, 161280, 0x4117371e ++1, 569443, 10836, 0x00000000 ++0, 570000, 161280, 0xe555b55e ++1, 574971, 10836, 0x00000000 ++0, 576000, 161280, 0xe555b55e ++1, 580500, 10836, 0x00000000 ++0, 582000, 161280, 0xe555b55e ++1, 586029, 10836, 0x00000000 ++0, 588000, 161280, 0xe555b55e ++1, 591557, 10836, 0x00000000 ++0, 594000, 161280, 0xe555b55e ++1, 597086, 10836, 0x00000000 ++0, 600000, 161280, 0xe555b55e ++1, 602614, 10836, 0x00000000 ++0, 606000, 161280, 0xe555b55e ++1, 608143, 10836, 0x00000000 ++0, 612000, 161280, 0xe555b55e ++1, 613671, 10836, 0x00000000 ++0, 618000, 161280, 0xe555b55e ++1, 619200, 10836, 0x00000000 ++0, 624000, 161280, 0xe555b55e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion1-24 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion1-24 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion1-24 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion1-24 2012-05-14 14:08:55.718367836 +0200 +@@ -1,43 +1,44 @@ +-1, 0, 10832, 0x1597b4c8 + 0, 0, 69120, 0x68beb30f +-1, 5527, 10832, 0xf9479f8b ++1, 0, 10836, 0xedecb6a7 ++1, 5529, 10836, 0x8098a323 + 0, 6000, 69120, 0x3976f5cf +-1, 11053, 10832, 0x8db50e74 ++1, 11057, 10836, 0xcfa1112e + 0, 12000, 69120, 0xf815bc3c +-1, 16580, 10832, 0x2b33ecbb ++1, 16586, 10836, 0xe241ede4 + 0, 18000, 69120, 0xa7cc0ae6 +-1, 22106, 10832, 0x8d0f537b ++1, 22114, 10836, 0xddf254bb + 0, 24000, 69120, 0xd85ac282 +-1, 27633, 10832, 0x922081c7 ++1, 27643, 10836, 0xa16c8507 + 0, 30000, 69120, 0xf7fd7edb +-1, 33159, 10832, 0x40291f19 ++1, 33171, 10836, 0xbe211f93 + 0, 36000, 69120, 0x433bb6f6 +-1, 38686, 10832, 0x88f5271a ++1, 38700, 10836, 0x26c7283d + 0, 42000, 69120, 0xdbac8bee +-1, 44212, 10832, 0x55c6bbe5 ++1, 44229, 10836, 0x4d18be56 + 0, 48000, 69120, 0x88e2a799 +-1, 49739, 10832, 0x9b51ae82 ++1, 49757, 10836, 0x57b9af6f + 0, 54000, 69120, 0x49617b26 +-1, 55265, 10832, 0xcdf2409b ++1, 55286, 10836, 0xd5864280 + 0, 60000, 69120, 0xeb44ca01 +-1, 60792, 10832, 0x0933b1a4 ++1, 60814, 10836, 0xd582b451 + 0, 66000, 69120, 0x6fea37e8 +-1, 66318, 10832, 0x24b77006 +-1, 71845, 10832, 0xf612fa8a ++1, 66343, 10836, 0xec13731d ++1, 71871, 10836, 0xe3d4fbb8 + 0, 72000, 69120, 0xf55d74c7 +-1, 77371, 10832, 0x99884b06 ++1, 77400, 10836, 0xcbb54d18 + 0, 78000, 69120, 0xb5082ca7 +-1, 82898, 10832, 0x3c746fbe ++1, 82929, 10836, 0xff7e7133 + 0, 84000, 69120, 0x5876d758 +-1, 88424, 10832, 0x05f3b08a +-1, 93951, 10832, 0xa6560483 +-1, 99478, 10832, 0xd98a8e19 +-1, 105004, 10832, 0xf98a0b2e +-1, 110531, 10832, 0xb1039582 +-1, 116057, 10832, 0x85dd5c3f +-1, 121584, 10832, 0x19fc801a +-1, 127110, 10832, 0x95805089 +-1, 132637, 10832, 0x576fdec3 +-1, 138163, 10832, 0x704a0905 +-1, 143690, 10832, 0xf87ce1fa +-1, 149216, 10832, 0xfc0076b9 ++1, 88457, 10836, 0xcc28b1a7 ++0, 90000, 69120, 0x45e7dd5c ++1, 93986, 10836, 0xbf9e07a5 ++1, 99514, 10836, 0x16408f38 ++1, 105043, 10836, 0x2b000c9f ++1, 110571, 10836, 0x0ccd9811 ++1, 116100, 10836, 0xf9575d48 ++1, 121629, 10836, 0x1ee68190 ++1, 127157, 10836, 0xde435373 ++1, 132686, 10836, 0xd83be17a ++1, 138214, 10836, 0x9a7f0bbe ++1, 143743, 10836, 0x8709e4d3 ++1, 149271, 10836, 0xde1879cb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/truemotion2 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/truemotion2 2012-05-14 14:08:55.718367836 +0200 +@@ -0,0 +1,30 @@ ++0, 0, 230400, 0x135cb509 ++0, 6000, 230400, 0x919a1ab7 ++0, 12000, 230400, 0x0af8722b ++0, 18000, 230400, 0xc9616809 ++0, 24000, 230400, 0xe16ecaf7 ++0, 30000, 230400, 0xa86f8d1b ++0, 36000, 230400, 0xd351b5a4 ++0, 42000, 230400, 0xd112b5b7 ++0, 48000, 230400, 0xc9c3c9b1 ++0, 54000, 230400, 0x4f91e572 ++0, 60000, 230400, 0xb1d8c4d3 ++0, 66000, 230400, 0x34de10c1 ++0, 72000, 230400, 0xbd4f3b29 ++0, 78000, 230400, 0xfeaf1477 ++0, 84000, 230400, 0x718ffa17 ++0, 90000, 230400, 0x23b46ef3 ++0, 96000, 230400, 0x6346d9b8 ++0, 102000, 230400, 0xdb66bf57 ++0, 108000, 230400, 0xeb74a2ff ++0, 114000, 230400, 0xe0750470 ++0, 120000, 230400, 0x645eb109 ++0, 126000, 230400, 0xbb96489a ++0, 132000, 230400, 0x58a70e35 ++0, 138000, 230400, 0xc7563441 ++0, 144000, 230400, 0x6098f07e ++0, 150000, 230400, 0x579ece15 ++0, 156000, 230400, 0xe1ca8d03 ++0, 162000, 230400, 0x8928cf34 ++0, 168000, 230400, 0xf621620e ++0, 174000, 230400, 0x98a344ea +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tscc-15bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tscc-15bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tscc-15bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tscc-15bit 2012-05-14 14:08:55.720367876 +0200 +@@ -1,240 +1,240 @@ ++0, 0, 657600, 0x50b3a0c2 + 1, 0, 22050, 0x1740aaec +-0, 0, 657600, 0xaf456809 +-0, 6000, 657600, 0xaf456809 +-0, 12000, 657600, 0xaf456809 +-0, 18000, 657600, 0x2dbe6889 +-0, 24000, 657600, 0x2dbe6889 +-0, 30000, 657600, 0x2dbe6889 +-0, 36000, 657600, 0x2dbe6889 +-0, 42000, 657600, 0x2dbe6889 +-0, 48000, 657600, 0x2dbe6889 +-0, 54000, 657600, 0x2dbe6889 +-0, 60000, 657600, 0x2dbe6889 +-0, 66000, 657600, 0x2dbe6889 +-0, 72000, 657600, 0x2dbe6889 +-0, 78000, 657600, 0x2dbe6889 +-0, 84000, 657600, 0x2dbe6889 ++0, 6000, 657600, 0x50b3a0c2 ++0, 12000, 657600, 0x50b3a0c2 ++0, 18000, 657600, 0x661aa145 ++0, 24000, 657600, 0x661aa145 ++0, 30000, 657600, 0x661aa145 ++0, 36000, 657600, 0x661aa145 ++0, 42000, 657600, 0x661aa145 ++0, 48000, 657600, 0x661aa145 ++0, 54000, 657600, 0x661aa145 ++0, 60000, 657600, 0x661aa145 ++0, 66000, 657600, 0x661aa145 ++0, 72000, 657600, 0x661aa145 ++0, 78000, 657600, 0x661aa145 ++0, 84000, 657600, 0x661aa145 ++0, 90000, 657600, 0x661aa145 + 1, 90000, 22050, 0x75ed6086 +-0, 90000, 657600, 0x2dbe6889 +-0, 96000, 657600, 0x2dbe6889 +-0, 102000, 657600, 0x2dbe6889 +-0, 108000, 657600, 0x2dbe6889 +-0, 114000, 657600, 0x2dbe6889 +-0, 120000, 657600, 0x2dbe6889 +-0, 126000, 657600, 0x92796e59 +-0, 132000, 657600, 0x92796e59 +-0, 138000, 657600, 0x92796e59 +-0, 144000, 657600, 0x64cb6889 +-0, 150000, 657600, 0x64cb6889 +-0, 156000, 657600, 0x64cb6889 +-0, 162000, 657600, 0x64cb6889 +-0, 168000, 657600, 0x64cb6889 +-0, 174000, 657600, 0x64cb6889 ++0, 96000, 657600, 0x661aa145 ++0, 102000, 657600, 0x661aa145 ++0, 108000, 657600, 0x661aa145 ++0, 114000, 657600, 0x661aa145 ++0, 120000, 657600, 0x661aa145 ++0, 126000, 657600, 0x3c29a73f ++0, 132000, 657600, 0x3c29a73f ++0, 138000, 657600, 0x3c29a73f ++0, 144000, 657600, 0xee2ca145 ++0, 150000, 657600, 0xee2ca145 ++0, 156000, 657600, 0xee2ca145 ++0, 162000, 657600, 0xee2ca145 ++0, 168000, 657600, 0xee2ca145 ++0, 174000, 657600, 0xee2ca145 ++0, 180000, 657600, 0xeb6fa442 + 1, 180000, 22050, 0xca52a4e9 +-0, 180000, 657600, 0x42036b71 +-0, 186000, 657600, 0x42036b71 +-0, 192000, 657600, 0x42036b71 +-0, 198000, 657600, 0xc40a6889 +-0, 204000, 657600, 0xc40a6889 +-0, 210000, 657600, 0xc40a6889 +-0, 216000, 657600, 0xaa6f7429 +-0, 222000, 657600, 0xaa6f7429 +-0, 228000, 657600, 0xaa6f7429 +-0, 234000, 657600, 0x854172d9 +-0, 240000, 657600, 0x854172d9 +-0, 246000, 657600, 0x854172d9 +-0, 252000, 657600, 0x22d10de0 +-0, 258000, 657600, 0xa75f0d60 +-0, 264000, 657600, 0x7a440be0 ++0, 186000, 657600, 0xeb6fa442 ++0, 192000, 657600, 0xeb6fa442 ++0, 198000, 657600, 0xb235a145 ++0, 204000, 657600, 0xb235a145 ++0, 210000, 657600, 0xb235a145 ++0, 216000, 657600, 0x39f7ad39 ++0, 222000, 657600, 0x39f7ad39 ++0, 228000, 657600, 0x39f7ad39 ++0, 234000, 657600, 0xb851abda ++0, 240000, 657600, 0xb851abda ++0, 246000, 657600, 0xb851abda ++0, 252000, 657600, 0xf6574b22 ++0, 258000, 657600, 0x1a154a9f ++0, 264000, 657600, 0x3de64916 ++0, 270000, 657600, 0xca3d9cd5 + 1, 270000, 22050, 0xb306d419 +-0, 270000, 657600, 0x40095d50 +-0, 276000, 657600, 0x40095d50 +-0, 282000, 657600, 0x64766320 +-0, 288000, 657600, 0x64766320 +-0, 294000, 657600, 0x64766320 +-0, 300000, 657600, 0x64766320 +-0, 306000, 657600, 0x64766320 +-0, 312000, 657600, 0x64766320 +-0, 318000, 657600, 0x64766320 +-0, 324000, 657600, 0x64766320 +-0, 330000, 657600, 0x64766320 +-0, 336000, 657600, 0x64766320 +-0, 342000, 657600, 0xf51adc49 +-0, 348000, 657600, 0xf51adc49 +-0, 354000, 657600, 0xf51adc49 ++0, 276000, 657600, 0xca3d9cd5 ++0, 282000, 657600, 0x4779a2cf ++0, 288000, 657600, 0x4779a2cf ++0, 294000, 657600, 0x4779a2cf ++0, 300000, 657600, 0x4779a2cf ++0, 306000, 657600, 0x4779a2cf ++0, 312000, 657600, 0x4779a2cf ++0, 318000, 657600, 0x4779a2cf ++0, 324000, 657600, 0x4779a2cf ++0, 330000, 657600, 0x4779a2cf ++0, 336000, 657600, 0x4779a2cf ++0, 342000, 657600, 0x29af1818 ++0, 348000, 657600, 0x29af1818 ++0, 354000, 657600, 0x29af1818 ++0, 360000, 657600, 0x77ace9c5 + 1, 360000, 22050, 0x8cbb9625 +-0, 360000, 657600, 0xdd47af59 +-0, 366000, 657600, 0xdd47af59 +-0, 372000, 657600, 0xffa8acf1 +-0, 378000, 657600, 0x5994b059 +-0, 384000, 657600, 0x5994b059 +-0, 390000, 657600, 0x5994b059 +-0, 396000, 657600, 0x03ffae71 +-0, 402000, 657600, 0x03ffae71 +-0, 408000, 657600, 0x03ffae71 +-0, 414000, 657600, 0xe33ab89e +-0, 420000, 657600, 0xe33ab89e +-0, 426000, 657600, 0xe33ab89e +-0, 432000, 657600, 0xbe37b549 +-0, 438000, 657600, 0xbe37b549 +-0, 444000, 657600, 0x1d395bf9 ++0, 366000, 657600, 0x77ace9c5 ++0, 372000, 657600, 0x61b8e74b ++0, 378000, 657600, 0x8c6deace ++0, 384000, 657600, 0x8c6deace ++0, 390000, 657600, 0x8c6deace ++0, 396000, 657600, 0xbe1fe8d7 ++0, 402000, 657600, 0xbe1fe8d7 ++0, 408000, 657600, 0xbe1fe8d7 ++0, 414000, 657600, 0x633209db ++0, 420000, 657600, 0x633209db ++0, 426000, 657600, 0x633209db ++0, 432000, 657600, 0x3148adb5 ++0, 438000, 657600, 0x3148adb5 ++0, 444000, 657600, 0x3b5f5216 ++0, 450000, 657600, 0x3b5f5216 + 1, 450000, 22050, 0x34a11f66 +-0, 450000, 657600, 0x1d395bf9 +-0, 456000, 657600, 0x1d395bf9 +-0, 462000, 657600, 0x1d395bf9 +-0, 468000, 657600, 0x2ec36f37 +-0, 474000, 657600, 0x2ec36f37 +-0, 480000, 657600, 0xb04a6eb7 +-0, 486000, 657600, 0x66610458 +-0, 492000, 657600, 0x66610458 +-0, 498000, 657600, 0xaf8901f0 +-0, 504000, 657600, 0x3ae41c48 +-0, 510000, 657600, 0x5b870b70 +-0, 516000, 657600, 0x11490c60 +-0, 522000, 657600, 0x70064801 +-0, 528000, 657600, 0x80d54519 +-0, 534000, 657600, 0xe8c942b1 ++0, 456000, 657600, 0x3b5f5216 ++0, 462000, 657600, 0x3b5f5216 ++0, 468000, 657600, 0x5e51fb89 ++0, 474000, 657600, 0x5e51fb89 ++0, 480000, 657600, 0x48eafb06 ++0, 486000, 657600, 0x9f7a8653 ++0, 492000, 657600, 0x9f7a8653 ++0, 498000, 657600, 0x29fc83d9 ++0, 504000, 657600, 0xe7689f10 ++0, 510000, 657600, 0x9f788dba ++0, 516000, 657600, 0x0e808eb2 ++0, 522000, 657600, 0x3ec53d79 ++0, 528000, 657600, 0x67ca3a7c ++0, 534000, 657600, 0xf7583802 ++0, 540000, 657600, 0x239e2fc6 + 1, 540000, 22050, 0x1ae81230 +-0, 540000, 657600, 0x830d8c24 +-0, 546000, 657600, 0x830d8c24 +-0, 552000, 657600, 0x830d8c24 +-0, 558000, 657600, 0xf3c4707c +-0, 564000, 657600, 0x6ace707c +-0, 570000, 657600, 0x6ace707c +-0, 576000, 657600, 0x6ace707c +-0, 582000, 657600, 0x6ace707c +-0, 588000, 657600, 0x6ace707c +-0, 594000, 657600, 0x5f461aae +-0, 600000, 657600, 0x5f461aae +-0, 606000, 657600, 0x221ceecf +-0, 612000, 657600, 0x221ceecf +-0, 618000, 657600, 0x221ceecf +-0, 624000, 657600, 0x221ceecf ++0, 546000, 657600, 0x239e2fc6 ++0, 552000, 657600, 0x239e2fc6 ++0, 558000, 657600, 0x001c134c ++0, 564000, 657600, 0x5c85134c ++0, 570000, 657600, 0x5c85134c ++0, 576000, 657600, 0x5c85134c ++0, 582000, 657600, 0x5c85134c ++0, 588000, 657600, 0x5c85134c ++0, 594000, 657600, 0x5fef8bea ++0, 600000, 657600, 0x5fef8bea ++0, 606000, 657600, 0x23135efa ++0, 612000, 657600, 0x23135efa ++0, 618000, 657600, 0x23135efa ++0, 624000, 657600, 0x23135efa ++0, 630000, 657600, 0x23135efa + 1, 630000, 22050, 0x1217eeba +-0, 630000, 657600, 0x221ceecf +-0, 636000, 657600, 0x221ceecf +-0, 642000, 657600, 0x221ceecf +-0, 648000, 657600, 0x3bf6f39f +-0, 654000, 657600, 0x3bf6f39f +-0, 660000, 657600, 0x3bf6f39f +-0, 666000, 657600, 0xc2caeecf +-0, 672000, 657600, 0xc2caeecf +-0, 678000, 657600, 0xc2caeecf +-0, 684000, 657600, 0xc316d63e +-0, 690000, 657600, 0xc316d63e +-0, 696000, 657600, 0xc316d63e +-0, 702000, 657600, 0x41f6218d +-0, 708000, 657600, 0x41f6218d +-0, 714000, 657600, 0x41f6218d ++0, 636000, 657600, 0x23135efa ++0, 642000, 657600, 0x23135efa ++0, 648000, 657600, 0x50cf63ee ++0, 654000, 657600, 0x50cf63ee ++0, 660000, 657600, 0x50cf63ee ++0, 666000, 657600, 0x2f5c5efa ++0, 672000, 657600, 0x2f5c5efa ++0, 678000, 657600, 0x2f5c5efa ++0, 684000, 657600, 0x9980d3c1 ++0, 690000, 657600, 0x9980d3c1 ++0, 696000, 657600, 0x9980d3c1 ++0, 702000, 657600, 0x23f02141 ++0, 708000, 657600, 0x23f02141 ++0, 714000, 657600, 0x23f02141 ++0, 720000, 657600, 0x3d31ea57 + 1, 720000, 22050, 0x50e70baa +-0, 720000, 657600, 0xff43ec36 +-0, 726000, 657600, 0x0b10eb16 +-0, 732000, 657600, 0x0b10eb16 +-0, 738000, 657600, 0xbdf41aa5 +-0, 744000, 657600, 0xbdf41aa5 +-0, 750000, 657600, 0xbdf41aa5 +-0, 756000, 657600, 0xd502ca06 +-0, 762000, 657600, 0xd502ca06 +-0, 768000, 657600, 0xd502ca06 +-0, 774000, 657600, 0x8446f89e +-0, 780000, 657600, 0x8446f89e +-0, 786000, 657600, 0x8446f89e +-0, 792000, 657600, 0x3d4ccf06 +-0, 798000, 657600, 0x0897d1de +-0, 804000, 657600, 0x0897d1de ++0, 726000, 657600, 0x1e9be92f ++0, 732000, 657600, 0x1e9be92f ++0, 738000, 657600, 0x05091a2e ++0, 744000, 657600, 0x05091a2e ++0, 750000, 657600, 0x05091a2e ++0, 756000, 657600, 0xd214c71a ++0, 762000, 657600, 0xd214c71a ++0, 768000, 657600, 0xd214c71a ++0, 774000, 657600, 0x3b07f720 ++0, 780000, 657600, 0x3b07f720 ++0, 786000, 657600, 0x3b07f720 ++0, 792000, 657600, 0x02becc42 ++0, 798000, 657600, 0x3d8fcf2e ++0, 804000, 657600, 0x3d8fcf2e ++0, 810000, 657600, 0xec51ddd7 + 1, 810000, 22050, 0xb19e89c0 +-0, 810000, 657600, 0x3e27e01e +-0, 816000, 657600, 0x3e27e01e +-0, 822000, 657600, 0x3e27e01e +-0, 828000, 657600, 0x3e27e01e +-0, 834000, 657600, 0x3e27e01e +-0, 840000, 657600, 0x3e27e01e +-0, 846000, 657600, 0xe51078a8 +-0, 852000, 657600, 0xe51078a8 +-0, 858000, 657600, 0xe9967a40 +-0, 864000, 657600, 0xe9967a40 +-0, 870000, 657600, 0xe9967a40 +-0, 876000, 657600, 0xe9967a40 +-0, 882000, 657600, 0xe9967a40 +-0, 888000, 657600, 0xe9967a40 +-0, 894000, 657600, 0xe9967a40 ++0, 816000, 657600, 0xec51ddd7 ++0, 822000, 657600, 0xec51ddd7 ++0, 828000, 657600, 0xec51ddd7 ++0, 834000, 657600, 0xec51ddd7 ++0, 840000, 657600, 0xec51ddd7 ++0, 846000, 657600, 0x40a3b905 ++0, 852000, 657600, 0x40a3b905 ++0, 858000, 657600, 0xbfc5baa9 ++0, 864000, 657600, 0xbfc5baa9 ++0, 870000, 657600, 0xbfc5baa9 ++0, 876000, 657600, 0xbfc5baa9 ++0, 882000, 657600, 0xbfc5baa9 ++0, 888000, 657600, 0xbfc5baa9 ++0, 894000, 657600, 0xbfc5baa9 ++0, 900000, 657600, 0x54a2f8dd + 1, 900000, 22050, 0x78526696 +-0, 900000, 657600, 0x726cb6b8 +-0, 906000, 657600, 0x2960b6e8 +-0, 912000, 657600, 0x2960b6e8 +-0, 918000, 657600, 0x1637d6c8 +-0, 924000, 657600, 0x6f2fd9b0 +-0, 930000, 657600, 0x27a7d6c8 +-0, 936000, 657600, 0xe855d6c8 +-0, 942000, 657600, 0xe855d6c8 +-0, 948000, 657600, 0xe855d6c8 +-0, 954000, 657600, 0x1a8ad6c8 +-0, 960000, 657600, 0x9c11d648 +-0, 966000, 657600, 0x6136d648 +-0, 972000, 657600, 0xdfa0d6c8 +-0, 978000, 657600, 0xdfa0d6c8 +-0, 984000, 657600, 0xdfa0d6c8 ++0, 906000, 657600, 0x0b96f90d ++0, 912000, 657600, 0x0b96f90d ++0, 918000, 657600, 0xa18119e9 ++0, 924000, 657600, 0x70a11ce6 ++0, 930000, 657600, 0xb36f19e9 ++0, 936000, 657600, 0xeb2219e9 ++0, 942000, 657600, 0xeb2219e9 ++0, 948000, 657600, 0xeb2219e9 ++0, 954000, 657600, 0xb98f19e9 ++0, 960000, 657600, 0xa4281966 ++0, 966000, 657600, 0xf0e61966 ++0, 972000, 657600, 0x065c19e9 ++0, 978000, 657600, 0x065c19e9 ++0, 984000, 657600, 0x065c19e9 ++0, 990000, 657600, 0x065c19e9 + 1, 990000, 22050, 0x48e3bb21 +-0, 990000, 657600, 0xdfa0d6c8 +-0, 996000, 657600, 0xdfa0d6c8 +-0, 1002000, 657600, 0xdfa0d6c8 +-0, 1008000, 657600, 0xdfa0d6c8 +-0, 1014000, 657600, 0xdfa0d6c8 +-0, 1020000, 657600, 0xdfa0d6c8 +-0, 1026000, 657600, 0x125cd9b0 +-0, 1032000, 657600, 0x125cd9b0 +-0, 1038000, 657600, 0x8a7ed6c8 +-0, 1044000, 657600, 0x09a6d9b0 +-0, 1050000, 657600, 0x09a6d9b0 +-0, 1056000, 657600, 0x09a6d9b0 +-0, 1062000, 657600, 0x85e87a68 +-0, 1068000, 657600, 0x85e87a68 +-0, 1074000, 657600, 0x85e87a68 ++0, 996000, 657600, 0x065c19e9 ++0, 1002000, 657600, 0x065c19e9 ++0, 1008000, 657600, 0x065c19e9 ++0, 1014000, 657600, 0x065c19e9 ++0, 1020000, 657600, 0x065c19e9 ++0, 1026000, 657600, 0x2f1d1ce6 ++0, 1032000, 657600, 0x2f1d1ce6 ++0, 1038000, 657600, 0x181719e9 ++0, 1044000, 657600, 0x938d1ce6 ++0, 1050000, 657600, 0x938d1ce6 ++0, 1056000, 657600, 0x938d1ce6 ++0, 1062000, 657600, 0xf0acbabf ++0, 1068000, 657600, 0xf0acbabf ++0, 1074000, 657600, 0xf0acbabf ++0, 1080000, 657600, 0x0f47804f + 1, 1080000, 22050, 0xbc32204a +-0, 1080000, 657600, 0xb0a141a8 +-0, 1086000, 657600, 0xb0a141a8 +-0, 1092000, 657600, 0xf3333bd8 +-0, 1098000, 657600, 0xea090688 +-0, 1104000, 657600, 0xa017fe41 +-0, 1110000, 657600, 0xa017fe41 +-0, 1116000, 657600, 0x32e93bd8 +-0, 1122000, 657600, 0x7fe640c0 +-0, 1128000, 657600, 0x7fe640c0 +-0, 1134000, 657600, 0xcd8995b2 +-0, 1140000, 657600, 0x84278a92 +-0, 1146000, 657600, 0x84278a92 +-0, 1152000, 657600, 0xf1d2874a +-0, 1158000, 657600, 0xf1d2874a +-0, 1164000, 657600, 0xf1d2874a ++0, 1086000, 657600, 0x0f47804f ++0, 1092000, 657600, 0x5e0c7a55 ++0, 1098000, 657600, 0x0c8f4374 ++0, 1104000, 657600, 0x709a3b00 ++0, 1110000, 657600, 0x709a3b00 ++0, 1116000, 657600, 0xf57b7a0f ++0, 1122000, 657600, 0x99427f1b ++0, 1128000, 657600, 0x99427f1b ++0, 1134000, 657600, 0xcb3608e7 ++0, 1140000, 657600, 0x0992fd64 ++0, 1146000, 657600, 0x0992fd64 ++0, 1152000, 657600, 0x7a95fa02 ++0, 1158000, 657600, 0x7a95fa02 ++0, 1164000, 657600, 0x7a95fa02 ++0, 1170000, 657600, 0xb97dd910 + 1, 1170000, 22050, 0xdf6f1e46 +-0, 1170000, 657600, 0xa58d6742 +-0, 1176000, 657600, 0xa58d6742 +-0, 1182000, 657600, 0xa58d6742 +-0, 1188000, 657600, 0xb0cd11bb +-0, 1194000, 657600, 0xb0cd11bb +-0, 1200000, 657600, 0xc55610bb +-0, 1206000, 657600, 0x4ee1168b +-0, 1212000, 657600, 0x61c513a3 +-0, 1218000, 657600, 0xd26410bb +-0, 1224000, 657600, 0xe7c410bb +-0, 1230000, 657600, 0x444a0dd3 +-0, 1236000, 657600, 0x444a0dd3 +-0, 1242000, 657600, 0x97ac10bb +-0, 1248000, 657600, 0x97ac10bb +-0, 1254000, 657600, 0xe8b30dd3 ++0, 1176000, 657600, 0xb97dd910 ++0, 1182000, 657600, 0xb97dd910 ++0, 1188000, 657600, 0x3be07a66 ++0, 1194000, 657600, 0x3be07a66 ++0, 1200000, 657600, 0x1ae77960 ++0, 1206000, 657600, 0x62177f5a ++0, 1212000, 657600, 0xf57c7c5d ++0, 1218000, 657600, 0x600e7960 ++0, 1224000, 657600, 0xe15d7960 ++0, 1230000, 657600, 0x79427663 ++0, 1236000, 657600, 0x79427663 ++0, 1242000, 657600, 0xa7c77960 ++0, 1248000, 657600, 0xa7c77960 ++0, 1254000, 657600, 0x75f67663 ++0, 1260000, 657600, 0x3a157960 + 1, 1260000, 22050, 0x4c91da9d +-0, 1260000, 657600, 0x3d0c10bb +-0, 1266000, 657600, 0x8d2b0dd3 +-0, 1272000, 657600, 0x8d2b0dd3 +-0, 1278000, 657600, 0xa5760dd3 +-0, 1284000, 657600, 0xa5760dd3 +-0, 1290000, 657600, 0xa5760dd3 +-0, 1296000, 657600, 0x31a30dd3 +-0, 1302000, 657600, 0x31a30dd3 +-0, 1308000, 657600, 0x31a30dd3 +-0, 1314000, 657600, 0x31a30dd3 +-0, 1320000, 657600, 0x31a30dd3 +-0, 1326000, 657600, 0x31a30dd3 +-0, 1332000, 657600, 0x31a30dd3 +-0, 1338000, 657600, 0x31a30dd3 +-0, 1344000, 657600, 0x31a30dd3 ++0, 1266000, 657600, 0x72aa7663 ++0, 1272000, 657600, 0x72aa7663 ++0, 1278000, 657600, 0x1b277663 ++0, 1284000, 657600, 0x1b277663 ++0, 1290000, 657600, 0x1b277663 ++0, 1296000, 657600, 0x6f5e7663 ++0, 1302000, 657600, 0x6f5e7663 ++0, 1308000, 657600, 0x6f5e7663 ++0, 1314000, 657600, 0x6f5e7663 ++0, 1320000, 657600, 0x6f5e7663 ++0, 1326000, 657600, 0x6f5e7663 ++0, 1332000, 657600, 0x6f5e7663 ++0, 1338000, 657600, 0x6f5e7663 ++0, 1344000, 657600, 0x6f5e7663 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tscc-32bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tscc-32bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/tscc-32bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/tscc-32bit 2012-05-14 14:08:55.721367896 +0200 +@@ -9,151 +9,148 @@ + 0, 48000, 2359296, 0xe990f855 + 0, 54000, 2359296, 0x3ec2c64e + 0, 60000, 2359296, 0xda3ba3cf +-0, 66000, 2359296, 0xda3ba3cf +-0, 72000, 2359296, 0xda3ba3cf +-0, 78000, 2359296, 0x60a070fd +-0, 84000, 2359296, 0x42e5fedc +-0, 90000, 2359296, 0x42e5fedc ++0, 66000, 2359296, 0x60a070fd ++0, 72000, 2359296, 0x42e5fedc ++0, 78000, 2359296, 0x42e5fedc ++0, 84000, 2359296, 0x699cf990 ++0, 90000, 2359296, 0x699cf990 + 0, 96000, 2359296, 0x699cf990 + 0, 102000, 2359296, 0x699cf990 + 0, 108000, 2359296, 0x699cf990 + 0, 114000, 2359296, 0x699cf990 + 0, 120000, 2359296, 0x699cf990 +-0, 126000, 2359296, 0x699cf990 +-0, 132000, 2359296, 0x699cf990 ++0, 126000, 2359296, 0x1524160c ++0, 132000, 2359296, 0x1524160c + 0, 138000, 2359296, 0x1524160c + 0, 144000, 2359296, 0x1524160c + 0, 150000, 2359296, 0x1524160c + 0, 156000, 2359296, 0x1524160c + 0, 162000, 2359296, 0x1524160c +-0, 168000, 2359296, 0x1524160c +-0, 174000, 2359296, 0x1524160c ++0, 168000, 2359296, 0x33df0c8c ++0, 174000, 2359296, 0x33df0c8c + 0, 180000, 2359296, 0x33df0c8c + 0, 186000, 2359296, 0x33df0c8c + 0, 192000, 2359296, 0x33df0c8c + 0, 198000, 2359296, 0x33df0c8c + 0, 204000, 2359296, 0x33df0c8c +-0, 210000, 2359296, 0x33df0c8c +-0, 216000, 2359296, 0x33df0c8c ++0, 210000, 2359296, 0xfe3d29f8 ++0, 216000, 2359296, 0xfe3d29f8 + 0, 222000, 2359296, 0xfe3d29f8 + 0, 228000, 2359296, 0xfe3d29f8 + 0, 234000, 2359296, 0xfe3d29f8 + 0, 240000, 2359296, 0xfe3d29f8 + 0, 246000, 2359296, 0xfe3d29f8 +-0, 252000, 2359296, 0xfe3d29f8 +-0, 258000, 2359296, 0xfe3d29f8 ++0, 252000, 2359296, 0x1b9d197f ++0, 258000, 2359296, 0x1b9d197f + 0, 264000, 2359296, 0x1b9d197f + 0, 270000, 2359296, 0x1b9d197f + 0, 276000, 2359296, 0x1b9d197f + 0, 282000, 2359296, 0x1b9d197f + 0, 288000, 2359296, 0x1b9d197f +-0, 294000, 2359296, 0x1b9d197f +-0, 300000, 2359296, 0x1b9d197f ++0, 294000, 2359296, 0x48c126fb ++0, 300000, 2359296, 0x48c126fb + 0, 306000, 2359296, 0x48c126fb + 0, 312000, 2359296, 0x48c126fb + 0, 318000, 2359296, 0x48c126fb + 0, 324000, 2359296, 0x48c126fb + 0, 330000, 2359296, 0x48c126fb +-0, 336000, 2359296, 0x48c126fb +-0, 342000, 2359296, 0x48c126fb ++0, 336000, 2359296, 0xcaa31c7c ++0, 342000, 2359296, 0xcaa31c7c + 0, 348000, 2359296, 0xcaa31c7c + 0, 354000, 2359296, 0xcaa31c7c + 0, 360000, 2359296, 0xcaa31c7c + 0, 366000, 2359296, 0xcaa31c7c + 0, 372000, 2359296, 0xcaa31c7c +-0, 378000, 2359296, 0xcaa31c7c +-0, 384000, 2359296, 0xcaa31c7c ++0, 378000, 2359296, 0xc6a333ee ++0, 384000, 2359296, 0xc6a333ee + 0, 390000, 2359296, 0xc6a333ee + 0, 396000, 2359296, 0xc6a333ee + 0, 402000, 2359296, 0xc6a333ee + 0, 408000, 2359296, 0xc6a333ee + 0, 414000, 2359296, 0xc6a333ee +-0, 420000, 2359296, 0xc6a333ee +-0, 426000, 2359296, 0xc6a333ee ++0, 420000, 2359296, 0xb96d1583 ++0, 426000, 2359296, 0xb96d1583 + 0, 432000, 2359296, 0xb96d1583 + 0, 438000, 2359296, 0xb96d1583 + 0, 444000, 2359296, 0xb96d1583 + 0, 450000, 2359296, 0xb96d1583 + 0, 456000, 2359296, 0xb96d1583 +-0, 462000, 2359296, 0xb96d1583 +-0, 468000, 2359296, 0xb96d1583 ++0, 462000, 2359296, 0x878135ec ++0, 468000, 2359296, 0x878135ec + 0, 474000, 2359296, 0x878135ec + 0, 480000, 2359296, 0x878135ec + 0, 486000, 2359296, 0x878135ec + 0, 492000, 2359296, 0x878135ec + 0, 498000, 2359296, 0x878135ec +-0, 504000, 2359296, 0x878135ec +-0, 510000, 2359296, 0x878135ec +-0, 516000, 2359296, 0x878135ec ++0, 504000, 2359296, 0x76922870 ++0, 510000, 2359296, 0x76922870 ++0, 516000, 2359296, 0x76922870 + 0, 522000, 2359296, 0x76922870 + 0, 528000, 2359296, 0x76922870 + 0, 534000, 2359296, 0x76922870 + 0, 540000, 2359296, 0x76922870 +-0, 546000, 2359296, 0x76922870 +-0, 552000, 2359296, 0x76922870 +-0, 558000, 2359296, 0x76922870 ++0, 546000, 2359296, 0xb0e031f0 ++0, 552000, 2359296, 0xb0e031f0 ++0, 558000, 2359296, 0xb0e031f0 + 0, 564000, 2359296, 0xb0e031f0 + 0, 570000, 2359296, 0xb0e031f0 + 0, 576000, 2359296, 0xb0e031f0 + 0, 582000, 2359296, 0xb0e031f0 +-0, 588000, 2359296, 0xb0e031f0 +-0, 594000, 2359296, 0xb0e031f0 +-0, 600000, 2359296, 0xb0e031f0 +-0, 606000, 2359296, 0xb2ef2a6e +-0, 612000, 2359296, 0xb2ef2a6e +-0, 618000, 2359296, 0xb2ef2a6e ++0, 588000, 2359296, 0xb2ef2a6e ++0, 594000, 2359296, 0xb2ef2a6e ++0, 600000, 2359296, 0xb2ef2a6e ++0, 606000, 2359296, 0x083c2474 ++0, 612000, 2359296, 0x083c2474 ++0, 618000, 2359296, 0x083c2474 + 0, 624000, 2359296, 0x083c2474 +-0, 630000, 2359296, 0x083c2474 +-0, 636000, 2359296, 0x083c2474 +-0, 642000, 2359296, 0x083c2474 ++0, 630000, 2359296, 0xbdfe2ef3 ++0, 636000, 2359296, 0xbdfe2ef3 ++0, 642000, 2359296, 0xbdfe2ef3 + 0, 648000, 2359296, 0xbdfe2ef3 + 0, 654000, 2359296, 0xbdfe2ef3 + 0, 660000, 2359296, 0xbdfe2ef3 + 0, 666000, 2359296, 0xbdfe2ef3 +-0, 672000, 2359296, 0xbdfe2ef3 +-0, 678000, 2359296, 0xbdfe2ef3 +-0, 684000, 2359296, 0xbdfe2ef3 ++0, 672000, 2359296, 0x934b1484 ++0, 678000, 2359296, 0x934b1484 ++0, 684000, 2359296, 0x934b1484 + 0, 690000, 2359296, 0x934b1484 +-0, 696000, 2359296, 0x934b1484 +-0, 702000, 2359296, 0x934b1484 +-0, 708000, 2359296, 0x934b1484 +-0, 714000, 2359296, 0x3e0d1a7e +-0, 720000, 2359296, 0x3e0d1a7e +-0, 726000, 2359296, 0x3e0d1a7e ++0, 696000, 2359296, 0x3e0d1a7e ++0, 702000, 2359296, 0x3e0d1a7e ++0, 708000, 2359296, 0x3e0d1a7e ++0, 714000, 2359296, 0x3ce539e8 ++0, 720000, 2359296, 0x3ce539e8 ++0, 726000, 2359296, 0x3ce539e8 + 0, 732000, 2359296, 0x3ce539e8 + 0, 738000, 2359296, 0x3ce539e8 + 0, 744000, 2359296, 0x3ce539e8 + 0, 750000, 2359296, 0x3ce539e8 +-0, 756000, 2359296, 0x3ce539e8 +-0, 762000, 2359296, 0x3ce539e8 +-0, 768000, 2359296, 0x3ce539e8 ++0, 756000, 2359296, 0xd46c2f69 ++0, 762000, 2359296, 0xd46c2f69 ++0, 768000, 2359296, 0xd46c2f69 + 0, 774000, 2359296, 0xd46c2f69 + 0, 780000, 2359296, 0xd46c2f69 + 0, 786000, 2359296, 0xd46c2f69 + 0, 792000, 2359296, 0xd46c2f69 +-0, 798000, 2359296, 0xd46c2f69 +-0, 804000, 2359296, 0xd46c2f69 +-0, 810000, 2359296, 0xd46c2f69 ++0, 798000, 2359296, 0x8d2933ee ++0, 804000, 2359296, 0x8d2933ee ++0, 810000, 2359296, 0x8d2933ee + 0, 816000, 2359296, 0x8d2933ee + 0, 822000, 2359296, 0x8d2933ee + 0, 828000, 2359296, 0x8d2933ee + 0, 834000, 2359296, 0x8d2933ee +-0, 840000, 2359296, 0x8d2933ee +-0, 846000, 2359296, 0x8d2933ee +-0, 852000, 2359296, 0x8d2933ee ++0, 840000, 2359296, 0xb6092b6d ++0, 846000, 2359296, 0xb6092b6d ++0, 852000, 2359296, 0xb6092b6d + 0, 858000, 2359296, 0xb6092b6d + 0, 864000, 2359296, 0xb6092b6d + 0, 870000, 2359296, 0xb6092b6d + 0, 876000, 2359296, 0xb6092b6d +-0, 882000, 2359296, 0xb6092b6d +-0, 888000, 2359296, 0xb6092b6d +-0, 894000, 2359296, 0xb6092b6d ++0, 882000, 2359296, 0xe4ef27fa ++0, 888000, 2359296, 0xe4ef27fa ++0, 894000, 2359296, 0xe4ef27fa + 0, 900000, 2359296, 0xe4ef27fa + 0, 906000, 2359296, 0xe4ef27fa + 0, 912000, 2359296, 0xe4ef27fa + 0, 918000, 2359296, 0xe4ef27fa +-0, 924000, 2359296, 0xe4ef27fa +-0, 930000, 2359296, 0xe4ef27fa +-0, 936000, 2359296, 0xe4ef27fa +-0, 942000, 2359296, 0x5e5b2672 +-0, 948000, 2359296, 0x5e5b2672 ++0, 924000, 2359296, 0x5e5b2672 ++0, 930000, 2359296, 0x5e5b2672 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgba_left xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgba_left +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgba_left 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgba_left 2012-05-14 14:08:55.723367937 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 1228800, 0xf1bc9432 ++0, 3003, 1228800, 0x8480d1e5 ++0, 6006, 1228800, 0xb01d5fb2 ++0, 9009, 1228800, 0x53cb42c4 ++0, 12012, 1228800, 0x2b2ea176 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgba_median xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgba_median +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgba_median 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgba_median 2012-05-14 14:08:55.723367937 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 1228800, 0xf1bc9432 ++0, 3003, 1228800, 0x8480d1e5 ++0, 6006, 1228800, 0xb01d5fb2 ++0, 9009, 1228800, 0x53cb42c4 ++0, 12012, 1228800, 0x2b2ea176 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgb_left xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgb_left +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgb_left 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgb_left 2012-05-14 14:08:55.721367896 +0200 +@@ -0,0 +1,4 @@ ++0, 0, 921600, 0x27e6001e ++0, 3003, 921600, 0x7c0a92bc ++0, 6006, 921600, 0x4d2be42c ++0, 9009, 921600, 0x58ddd0be +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgb_median xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgb_median +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_rgb_median 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_rgb_median 2012-05-14 14:08:55.722367916 +0200 +@@ -0,0 +1,5 @@ ++0, 0, 921600, 0x9776611f ++0, 3003, 921600, 0xdbfa64f4 ++0, 6006, 921600, 0xed2a0580 ++0, 9009, 921600, 0x6ecc80bc ++0, 12012, 921600, 0x58ddd0be +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_left xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_left +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_left 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_left 2012-05-14 14:08:55.723367937 +0200 +@@ -0,0 +1,7 @@ ++0, 0, 460800, 0xece98fc8 ++0, 3003, 460800, 0x9baf786b ++0, 6006, 460800, 0x8e8e0510 ++0, 9009, 460800, 0x27c1f2ba ++0, 12012, 460800, 0x6a817987 ++0, 15015, 460800, 0x2f713ec2 ++0, 18018, 460800, 0x003b560e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_median xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_median +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_median 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv420_median 2012-05-14 14:08:55.724367958 +0200 +@@ -0,0 +1,4 @@ ++0, 0, 460800, 0x6a817987 ++0, 3003, 460800, 0x2f713ec2 ++0, 6006, 460800, 0x003b560e ++0, 9009, 460800, 0x9e1bbf63 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_left xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_left +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_left 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_left 2012-05-14 14:08:55.724367958 +0200 +@@ -0,0 +1,4 @@ ++0, 0, 614400, 0x9a6b8802 ++0, 3003, 614400, 0xaa8687e2 ++0, 6006, 614400, 0x2fe5bd40 ++0, 9009, 614400, 0x1c8f3737 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_median xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_median +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_median 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/utvideo_yuv422_median 2012-05-14 14:08:55.725367978 +0200 +@@ -0,0 +1,4 @@ ++0, 0, 614400, 0x9a6b8802 ++0, 3003, 614400, 0xaa8687e2 ++0, 6006, 614400, 0x2fe5bd40 ++0, 9009, 614400, 0x1c8f3737 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/v410dec xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/v410dec +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/v410dec 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/v410dec 2012-05-14 14:08:55.725367978 +0200 +@@ -0,0 +1 @@ ++0, 0, 393216, 0xfe11a6b0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/v410enc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/v410enc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/v410enc 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/v410enc 2012-05-14 14:08:55.726367998 +0200 +@@ -0,0 +1 @@ ++979c9a9a09e8eaaf6467b8c22c0ac8bb +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vble xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vble +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vble 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vble 2012-05-14 14:08:55.726367998 +0200 +@@ -0,0 +1,4 @@ ++0, 0, 1382400, 0x5e1bc307 ++0, 3003, 1382400, 0x198795f7 ++0, 6006, 1382400, 0xa9102ac2 ++0, 9009, 1382400, 0x9e347932 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1 1970-01-01 01:00:00.000000000 +0100 +@@ -1,15 +0,0 @@ +-0, 0, 38016, 0xf4715db5 +-0, 3600, 38016, 0xf4715db5 +-0, 7200, 38016, 0xf4715db5 +-0, 10800, 38016, 0xf46af0e1 +-0, 14400, 38016, 0x96992cf1 +-0, 18000, 38016, 0xbaadd874 +-0, 21600, 38016, 0x751f4328 +-0, 25200, 38016, 0x751f4328 +-0, 28800, 38016, 0xf7294772 +-0, 32400, 38016, 0xf7294772 +-0, 36000, 38016, 0xf1d12133 +-0, 39600, 38016, 0xf1d12133 +-0, 43200, 38016, 0xf1d12133 +-0, 46800, 38016, 0xf1d12133 +-0, 50400, 38016, 0xf1d12133 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1-ism xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1-ism +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1-ism 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1-ism 2012-05-14 14:08:55.727368018 +0200 +@@ -0,0 +1,120 @@ ++0, 0, 37440, 0xd1bc5235 ++0, 3750, 37440, 0x158e6167 ++0, 7500, 37440, 0x0faa4481 ++0, 11250, 37440, 0x427158c5 ++0, 15000, 37440, 0x4eb53ac6 ++0, 18750, 37440, 0x99304eea ++0, 22500, 37440, 0xcc554a6f ++0, 26250, 37440, 0xabeb6c35 ++0, 30000, 37440, 0xddfc7e18 ++0, 33750, 37440, 0xaa79b504 ++0, 37500, 37440, 0x5cb1c839 ++0, 41250, 37440, 0x7e36ecca ++0, 45000, 37440, 0xf486f425 ++0, 48750, 37440, 0xf1b4138f ++0, 52500, 37440, 0x966f1a49 ++0, 56250, 37440, 0x5eff21da ++0, 60000, 37440, 0x333f39b1 ++0, 63750, 37440, 0x62e5963e ++0, 67500, 37440, 0x26930671 ++0, 71250, 37440, 0x27b4bb6c ++0, 75000, 37440, 0xdbd07766 ++0, 78750, 37440, 0x04260104 ++0, 82500, 37440, 0x9b1e078b ++0, 86250, 37440, 0xdf4e2474 ++0, 90000, 37440, 0x57d44986 ++0, 93750, 37440, 0x8780e34c ++0, 97500, 37440, 0xf80c8bc0 ++0, 101250, 37440, 0x630a7583 ++0, 105000, 37440, 0x235ae089 ++0, 108750, 37440, 0x984b8f0e ++0, 112500, 37440, 0x865cf592 ++0, 116250, 37440, 0x70f376f2 ++0, 120000, 37440, 0x8b30c035 ++0, 123750, 37440, 0xde772d79 ++0, 127500, 37440, 0x8e076be5 ++0, 131250, 37440, 0x3dc2bd9f ++0, 135000, 37440, 0xb782eb67 ++0, 138750, 37440, 0x02025d73 ++0, 142500, 37440, 0x86bbbce8 ++0, 146250, 37440, 0xd6554f62 ++0, 150000, 37440, 0xb831b917 ++0, 153750, 37440, 0x80643560 ++0, 157500, 37440, 0x4ecf9afd ++0, 161250, 37440, 0x9ce51e0b ++0, 165000, 37440, 0x179466cd ++0, 168750, 37440, 0x145fc900 ++0, 172500, 37440, 0xb1b50402 ++0, 176250, 37440, 0x0a87552a ++0, 180000, 37440, 0x8f53821d ++0, 183750, 37440, 0x1c07c825 ++0, 187500, 37440, 0x49dde82f ++0, 191250, 37440, 0xb1a32605 ++0, 195000, 37440, 0x410f3cd5 ++0, 198750, 37440, 0xff5e6696 ++0, 202500, 37440, 0x96f678c9 ++0, 206250, 37440, 0x6c9e9e68 ++0, 210000, 37440, 0x79a2a655 ++0, 213750, 37440, 0xf237bd6c ++0, 217500, 37440, 0x4051b611 ++0, 221250, 37440, 0xc7ccc918 ++0, 225000, 37440, 0xbd02c122 ++0, 228750, 37440, 0xacb3c881 ++0, 232500, 37440, 0x2abdb940 ++0, 236250, 37440, 0x19d5be85 ++0, 240000, 37440, 0xfa5fb1ba ++0, 243750, 37440, 0xdae7a7aa ++0, 247500, 37440, 0x6b0f9f69 ++0, 251250, 37440, 0x353e8201 ++0, 255000, 37440, 0xa21443aa ++0, 258750, 37440, 0x66c8d7e0 ++0, 262500, 37440, 0xc332068e ++0, 266250, 37440, 0x71431b9b ++0, 270000, 37440, 0x392f15cb ++0, 273750, 37440, 0x95a146bb ++0, 277500, 37440, 0x7c51740a ++0, 281250, 37440, 0xa3bdd43c ++0, 285000, 37440, 0xa079f965 ++0, 288750, 37440, 0xa95423ea ++0, 292500, 37440, 0xd1bd2c67 ++0, 296250, 37440, 0x6cf82844 ++0, 300000, 37440, 0xd401e128 ++0, 303750, 37440, 0x1f7db118 ++0, 307500, 37440, 0x2e0a65a9 ++0, 311250, 37440, 0x321c1c40 ++0, 315000, 37440, 0x95b2a127 ++0, 318750, 37440, 0xa1471f4b ++0, 322500, 37440, 0x29d148c0 ++0, 326250, 37440, 0x24c07107 ++0, 330000, 37440, 0x0ead678d ++0, 333750, 37440, 0xd0ca6495 ++0, 337500, 37440, 0x08f935ef ++0, 341250, 37440, 0xb5ec3c38 ++0, 345000, 37440, 0xce371628 ++0, 348750, 37440, 0x68170812 ++0, 352500, 37440, 0xe222699e ++0, 356250, 37440, 0xd688706c ++0, 360000, 37440, 0x81a033f9 ++0, 363750, 37440, 0x28bd0fbf ++0, 367500, 37440, 0xe36db7b2 ++0, 371250, 37440, 0x30559121 ++0, 375000, 37440, 0xbf2b5fc8 ++0, 378750, 37440, 0x4b427672 ++0, 382500, 37440, 0x0544b0b4 ++0, 386250, 37440, 0x38a70b06 ++0, 390000, 37440, 0x4ed62607 ++0, 393750, 37440, 0x6efe8ea6 ++0, 397500, 37440, 0x81197e11 ++0, 401250, 37440, 0xf4060050 ++0, 405000, 37440, 0xaf205f13 ++0, 408750, 37440, 0x5fa21382 ++0, 412500, 37440, 0x8627ad05 ++0, 416250, 37440, 0xf7130133 ++0, 420000, 37440, 0x76dea7ba ++0, 423750, 37440, 0x1dbae1be ++0, 427500, 37440, 0x74a933f7 ++0, 431250, 37440, 0xbdcd41a3 ++0, 435000, 37440, 0xf0fe8c1c ++0, 438750, 37440, 0xc0036222 ++0, 442500, 37440, 0x3058385c ++0, 446250, 37440, 0x68141016 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa00040 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa00040 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa00040 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa00040 2012-05-14 14:08:55.727368018 +0200 +@@ -0,0 +1,15 @@ ++0, 0, 38016, 0xa6f15db5 ++0, 3600, 38016, 0xa6f15db5 ++0, 7200, 38016, 0xa6f15db5 ++0, 10800, 38016, 0x5c4ef0e7 ++0, 14400, 38016, 0x53a42d1d ++0, 18000, 38016, 0x68f7d89e ++0, 21600, 38016, 0xc15f4368 ++0, 25200, 38016, 0xc15f4368 ++0, 28800, 38016, 0xd1bd47a8 ++0, 32400, 38016, 0xd1bd47a8 ++0, 36000, 38016, 0xe1e821ca ++0, 39600, 38016, 0xe1e821ca ++0, 43200, 38016, 0xe1e821ca ++0, 46800, 38016, 0xe1e821ca ++0, 50400, 38016, 0xe1e821ca +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa00050 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa00050 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa00050 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa00050 2012-05-14 14:08:55.728368038 +0200 +@@ -0,0 +1,30 @@ ++0, 0, 115200, 0xb8830eef ++0, 3600, 115200, 0xb8830eef ++0, 7200, 115200, 0xb8830eef ++0, 10800, 115200, 0x952ff5e1 ++0, 14400, 115200, 0xa4362b14 ++0, 18000, 115200, 0x32bacbe7 ++0, 21600, 115200, 0x509eb814 ++0, 25200, 115200, 0x509eb814 ++0, 28800, 115200, 0x11a76c3e ++0, 32400, 115200, 0x11a76c3e ++0, 36000, 115200, 0x00cf734a ++0, 39600, 115200, 0x00cf734a ++0, 43200, 115200, 0x00cf734a ++0, 46800, 115200, 0x00cf734a ++0, 50400, 115200, 0x00cf734a ++0, 54000, 115200, 0x00cf734a ++0, 57600, 115200, 0x00cf734a ++0, 61200, 115200, 0x00cf734a ++0, 64800, 115200, 0xfddf48e6 ++0, 68400, 115200, 0xfddf48e6 ++0, 72000, 115200, 0x1eccebbf ++0, 75600, 115200, 0x3da2f77e ++0, 79200, 115200, 0x7c232572 ++0, 82800, 115200, 0xedf426e5 ++0, 86400, 115200, 0x5324ab20 ++0, 90000, 115200, 0x5324ab20 ++0, 93600, 115200, 0xa23e66bb ++0, 97200, 115200, 0x680a50ff ++0, 100800, 115200, 0x680a50ff ++0, 104400, 115200, 0x680a50ff +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa10091 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa10091 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa10091 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa10091 2012-05-14 14:08:55.728368038 +0200 +@@ -0,0 +1,30 @@ ++0, 0, 518400, 0xae20b4fa ++0, 3600, 518400, 0x2b4ccdf9 ++0, 7200, 518400, 0x2b4ccdf9 ++0, 10800, 518400, 0x2b4ccdf9 ++0, 14400, 518400, 0x2b4ccdf9 ++0, 18000, 518400, 0x2b4ccdf9 ++0, 21600, 518400, 0x70d9a891 ++0, 25200, 518400, 0x70d9a891 ++0, 28800, 518400, 0x70d9a891 ++0, 32400, 518400, 0xa461ee86 ++0, 36000, 518400, 0x722bc6e8 ++0, 39600, 518400, 0x722bc6e8 ++0, 43200, 518400, 0x722bc6e8 ++0, 46800, 518400, 0xf752fd2c ++0, 50400, 518400, 0xf752fd2c ++0, 54000, 518400, 0x91abcaca ++0, 57600, 518400, 0x572727c3 ++0, 61200, 518400, 0x572727c3 ++0, 64800, 518400, 0x24c12382 ++0, 68400, 518400, 0x24c12382 ++0, 72000, 518400, 0x9aa39fe8 ++0, 75600, 518400, 0x9aa39fe8 ++0, 79200, 518400, 0x5cb6bd19 ++0, 82800, 518400, 0x704d9300 ++0, 86400, 518400, 0x590fad49 ++0, 90000, 518400, 0x590fad49 ++0, 93600, 518400, 0x590fad49 ++0, 97200, 518400, 0x46bea10b ++0, 100800, 518400, 0x46bea10b ++0, 104400, 518400, 0x46bea10b +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa20021 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa20021 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vc1_sa20021 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vc1_sa20021 2012-05-14 14:08:55.729368058 +0200 +@@ -0,0 +1,60 @@ ++0, 0, 506880, 0x884bc093 ++0, 3600, 506880, 0x4b09548f ++0, 7200, 506880, 0x195cbee1 ++0, 10800, 506880, 0xc8141e28 ++0, 14400, 506880, 0xb170c49b ++0, 18000, 506880, 0x2782268a ++0, 21600, 506880, 0x2782268a ++0, 25200, 506880, 0x2782268a ++0, 28800, 506880, 0x2782268a ++0, 32400, 506880, 0xe6803b32 ++0, 36000, 506880, 0xe6803b32 ++0, 39600, 506880, 0xa5ef9baf ++0, 43200, 506880, 0xa5ef9baf ++0, 46800, 506880, 0x46e8cbcb ++0, 50400, 506880, 0x28a2239b ++0, 54000, 506880, 0x7667af2f ++0, 57600, 506880, 0x7667af2f ++0, 61200, 506880, 0x8011bcaf ++0, 64800, 506880, 0xd422115b ++0, 68400, 506880, 0xd422115b ++0, 72000, 506880, 0xd422115b ++0, 75600, 506880, 0xbcee0b5b ++0, 79200, 506880, 0x08fe9ec8 ++0, 82800, 506880, 0xc8fb8b37 ++0, 86400, 506880, 0xc8fb8b37 ++0, 90000, 506880, 0x2c698b52 ++0, 93600, 506880, 0x2c698b52 ++0, 97200, 506880, 0x2c698b52 ++0, 100800, 506880, 0x2b4ad9bc ++0, 104400, 506880, 0x2b4ad9bc ++0, 108000, 506880, 0x2b4ad9bc ++0, 111600, 506880, 0x2b4ad9bc ++0, 115200, 506880, 0x92e84ebb ++0, 118800, 506880, 0x92e84ebb ++0, 122400, 506880, 0xdb877da3 ++0, 126000, 506880, 0xdb877da3 ++0, 129600, 506880, 0xdb877da3 ++0, 133200, 506880, 0x44610654 ++0, 136800, 506880, 0x44610654 ++0, 140400, 506880, 0xe254ce67 ++0, 144000, 506880, 0xa6085385 ++0, 147600, 506880, 0x2d45d744 ++0, 151200, 506880, 0x2d45d744 ++0, 154800, 506880, 0x6e684f51 ++0, 158400, 506880, 0xe96186cf ++0, 162000, 506880, 0xb535d369 ++0, 165600, 506880, 0xb535d369 ++0, 169200, 506880, 0xb535d369 ++0, 172800, 506880, 0xeed0b7e0 ++0, 176400, 506880, 0xeed0b7e0 ++0, 180000, 506880, 0xeed0b7e0 ++0, 183600, 506880, 0xeed0b7e0 ++0, 187200, 506880, 0x8789b20b ++0, 190800, 506880, 0x0a0f42fb ++0, 194400, 506880, 0x09bbac2d ++0, 198000, 506880, 0x09bbac2d ++0, 201600, 506880, 0x09bbac2d ++0, 205200, 506880, 0x09bbac2d ++0, 208800, 506880, 0x09bbac2d ++0, 212400, 506880, 0xda77f0df +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/videoxl xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/videoxl +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/videoxl 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/videoxl 2012-05-14 14:08:55.730368078 +0200 +@@ -0,0 +1,40 @@ ++0, 0, 36096, 0xab1c53c1 ++0, 12780, 36096, 0x8b598ff3 ++0, 25560, 36096, 0xe9a5f3eb ++0, 38340, 36096, 0x10584b30 ++0, 51120, 36096, 0x19d8c5d2 ++0, 63900, 36096, 0x43a453b9 ++0, 76680, 36096, 0xb32db13b ++0, 89460, 36096, 0xf117e7b3 ++0, 102240, 36096, 0x9171fb33 ++0, 115020, 36096, 0xdf84081c ++0, 127800, 36096, 0xc9d9527e ++0, 140580, 36096, 0x72fa295e ++0, 153360, 36096, 0xce02060e ++0, 166140, 36096, 0x31f5fdbd ++0, 178920, 36096, 0x4179dc07 ++0, 191700, 36096, 0xf250c03f ++0, 204480, 36096, 0xc4aca7c5 ++0, 217260, 36096, 0xd9b1837f ++0, 230040, 36096, 0x0af164ef ++0, 242820, 36096, 0x90123fcd ++0, 255600, 36096, 0x60392815 ++0, 268380, 36096, 0x7a7b0ac9 ++0, 281160, 36096, 0x36c1fe9c ++0, 293940, 36096, 0x50bed8a4 ++0, 306720, 36096, 0x10f3b998 ++0, 319500, 36096, 0x18e5b516 ++0, 332280, 36096, 0x860597dc ++0, 345060, 36096, 0x05488146 ++0, 357840, 36096, 0xac577cec ++0, 370620, 36096, 0xc9f95550 ++0, 383400, 36096, 0xa0c95270 ++0, 396180, 36096, 0x977c5bf2 ++0, 408960, 36096, 0xc9f95550 ++0, 421740, 36096, 0xa0c95270 ++0, 434520, 36096, 0x977c5bf2 ++0, 447300, 36096, 0xc9f95550 ++0, 460080, 36096, 0xa0c95270 ++0, 472860, 36096, 0x977c5bf2 ++0, 485640, 36096, 0xc9f95550 ++0, 498420, 36096, 0xa0c95270 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/video-xl xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/video-xl +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/video-xl 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/video-xl 1970-01-01 01:00:00.000000000 +0100 +@@ -1,40 +0,0 @@ +-0, 0, 36096, 0xab1c53c1 +-0, 12780, 36096, 0x8b598ff3 +-0, 25560, 36096, 0xe9a5f3eb +-0, 38340, 36096, 0x10584b30 +-0, 51120, 36096, 0x19d8c5d2 +-0, 63900, 36096, 0x43a453b9 +-0, 76680, 36096, 0xb32db13b +-0, 89460, 36096, 0xf117e7b3 +-0, 102240, 36096, 0x9171fb33 +-0, 115020, 36096, 0xdf84081c +-0, 127800, 36096, 0xc9d9527e +-0, 140580, 36096, 0x72fa295e +-0, 153360, 36096, 0xce02060e +-0, 166140, 36096, 0x31f5fdbd +-0, 178920, 36096, 0x4179dc07 +-0, 191700, 36096, 0xf250c03f +-0, 204480, 36096, 0xc4aca7c5 +-0, 217260, 36096, 0xd9b1837f +-0, 230040, 36096, 0x0af164ef +-0, 242820, 36096, 0x90123fcd +-0, 255600, 36096, 0x60392815 +-0, 268380, 36096, 0x7a7b0ac9 +-0, 281160, 36096, 0x36c1fe9c +-0, 293940, 36096, 0x50bed8a4 +-0, 306720, 36096, 0x10f3b998 +-0, 319500, 36096, 0x18e5b516 +-0, 332280, 36096, 0x860597dc +-0, 345060, 36096, 0x05488146 +-0, 357840, 36096, 0xac577cec +-0, 370620, 36096, 0xc9f95550 +-0, 383400, 36096, 0xa0c95270 +-0, 396180, 36096, 0x977c5bf2 +-0, 408960, 36096, 0xc9f95550 +-0, 421740, 36096, 0xa0c95270 +-0, 434520, 36096, 0x977c5bf2 +-0, 447300, 36096, 0xc9f95550 +-0, 460080, 36096, 0xa0c95270 +-0, 472860, 36096, 0x977c5bf2 +-0, 485640, 36096, 0xc9f95550 +-0, 498420, 36096, 0xa0c95270 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vmnc-16bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vmnc-16bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vmnc-16bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vmnc-16bit 2012-05-14 14:08:55.731368098 +0200 +@@ -1,192 +1,192 @@ +-0, 0, 864000, 0x9b1cee65 +-0, 18000, 864000, 0x82950e3f +-0, 36000, 864000, 0x335f9678 +-0, 54000, 864000, 0x6b86b7e7 +-0, 72000, 864000, 0x25618cf2 +-0, 90000, 864000, 0xed2196c9 +-0, 108000, 864000, 0xbeaa31ba +-0, 126000, 864000, 0x14e6c8ab +-0, 144000, 864000, 0x17e5c196 +-0, 162000, 864000, 0x4aa15110 +-0, 180000, 864000, 0x4aa15110 +-0, 198000, 864000, 0x4aa15110 +-0, 216000, 864000, 0x3c2d3809 +-0, 234000, 864000, 0xd075f4d0 +-0, 252000, 864000, 0x0c3f2833 +-0, 270000, 864000, 0xe7471872 +-0, 288000, 864000, 0x4300b71d +-0, 306000, 864000, 0x6b5844ec +-0, 324000, 864000, 0xb3ebc395 +-0, 342000, 864000, 0x39aa8a7d +-0, 360000, 864000, 0x52a3d93d +-0, 378000, 864000, 0x73adbdac +-0, 396000, 864000, 0xa9fd6cdc +-0, 414000, 864000, 0x4a085344 +-0, 432000, 864000, 0xc21b943c +-0, 450000, 864000, 0xfaef6ed4 +-0, 468000, 864000, 0xa3e9163c +-0, 486000, 864000, 0x917e2be4 +-0, 504000, 864000, 0x2d89d534 +-0, 522000, 864000, 0x6fe5a9e4 +-0, 540000, 864000, 0x71af29ec +-0, 558000, 864000, 0x8f33f6ad +-0, 576000, 864000, 0xe7d46a24 +-0, 594000, 864000, 0xb631e044 +-0, 612000, 864000, 0x77db01cb +-0, 630000, 864000, 0x9861b6ec +-0, 648000, 864000, 0x973bd263 +-0, 666000, 864000, 0xdd4c175b +-0, 684000, 864000, 0xdc28469b +-0, 702000, 864000, 0x67393ebb +-0, 720000, 864000, 0x01a06813 +-0, 738000, 864000, 0x63e88f73 +-0, 756000, 864000, 0x3ffbdd73 +-0, 774000, 864000, 0xd25f790b +-0, 792000, 864000, 0x14e3c5d3 +-0, 810000, 864000, 0x0d3d1202 +-0, 828000, 864000, 0x69decf03 +-0, 846000, 864000, 0x1b20ab93 +-0, 864000, 864000, 0xee2f8d4a +-0, 882000, 864000, 0xaac44c52 +-0, 900000, 864000, 0x3f874a5a +-0, 918000, 864000, 0x239b2d7a +-0, 936000, 864000, 0xb85db552 +-0, 954000, 864000, 0xb12962a2 +-0, 972000, 864000, 0xb8270fd9 +-0, 990000, 864000, 0x14930601 +-0, 1008000, 864000, 0x827a15c1 +-0, 1026000, 864000, 0xe31011d1 +-0, 1044000, 864000, 0xcd2154c1 +-0, 1062000, 864000, 0xad02dbd9 +-0, 1080000, 864000, 0x40c17d58 +-0, 1098000, 864000, 0x8219e3b9 +-0, 1116000, 864000, 0x2d348340 +-0, 1134000, 864000, 0x6b61dfc9 +-0, 1152000, 864000, 0xc8d95be1 +-0, 1170000, 864000, 0x70ba0918 +-0, 1188000, 864000, 0xdc728131 +-0, 1206000, 864000, 0x9b054a10 +-0, 1224000, 864000, 0x3983f751 +-0, 1242000, 864000, 0x325fe1a9 +-0, 1260000, 864000, 0x7a41eac0 +-0, 1278000, 864000, 0x324372a8 +-0, 1296000, 864000, 0xc014ea18 +-0, 1314000, 864000, 0x1a506a1f +-0, 1332000, 864000, 0x47b59557 +-0, 1350000, 864000, 0x5f2e194f +-0, 1368000, 864000, 0x9f6abb68 +-0, 1386000, 864000, 0x831d2b97 +-0, 1404000, 864000, 0x0635af7f +-0, 1422000, 864000, 0xe54a5626 +-0, 1440000, 864000, 0x704dca4f +-0, 1458000, 864000, 0x47de6676 +-0, 1476000, 864000, 0x609705fd +-0, 1494000, 864000, 0x8d92e086 +-0, 1512000, 864000, 0xdb7dab5e +-0, 1530000, 864000, 0xe6ccb686 +-0, 1548000, 864000, 0x0d137f66 +-0, 1566000, 864000, 0xd200035d +-0, 1584000, 864000, 0x7dcb959d +-0, 1602000, 864000, 0xee849f75 +-0, 1620000, 864000, 0x89d14acd +-0, 1638000, 864000, 0x3738029d +-0, 1656000, 864000, 0x6f4c4395 +-0, 1674000, 864000, 0x06334395 +-0, 1692000, 864000, 0x238b7c94 +-0, 1710000, 864000, 0xfa5d1e14 +-0, 1728000, 864000, 0x50b10e54 +-0, 1746000, 864000, 0x9ed3b6e4 +-0, 1764000, 864000, 0x68da9374 +-0, 1782000, 864000, 0xb32a137c +-0, 1800000, 864000, 0x577d5084 +-0, 1818000, 864000, 0xd262176b +-0, 1836000, 864000, 0xf58b44b3 +-0, 1854000, 864000, 0xd0828edc +-0, 1872000, 864000, 0xc91a7544 +-0, 1890000, 864000, 0x18ae7f1c +-0, 1908000, 864000, 0x82623643 +-0, 1926000, 864000, 0x9cf82cfb +-0, 1944000, 864000, 0x93ad116b +-0, 1962000, 864000, 0xa669044b +-0, 1980000, 864000, 0x8adf88c3 +-0, 1998000, 864000, 0xb83fb413 +-0, 2016000, 864000, 0xb9e291f3 +-0, 2034000, 864000, 0x5833dcc3 +-0, 2052000, 864000, 0x4ab825aa +-0, 2070000, 864000, 0xb52c3b53 +-0, 2088000, 864000, 0x0cb0dd53 +-0, 2106000, 864000, 0x98b8dd52 +-0, 2124000, 864000, 0x989230ba +-0, 2142000, 864000, 0xaed4c073 +-0, 2160000, 864000, 0x76a7c83a +-0, 2178000, 864000, 0x02711eea +-0, 2196000, 864000, 0x8de65fe2 +-0, 2214000, 864000, 0xc1163689 +-0, 2232000, 864000, 0xc04f8b31 +-0, 2250000, 864000, 0x69218d2a +-0, 2268000, 864000, 0x7e3abe62 +-0, 2286000, 864000, 0x00ebe27a +-0, 2304000, 864000, 0x34803f11 +-0, 2322000, 864000, 0x85591cd9 +-0, 2340000, 864000, 0x8422fb51 +-0, 2358000, 864000, 0x67c759e1 +-0, 2376000, 864000, 0x4ac36af1 +-0, 2394000, 864000, 0xdf00fca2 +-0, 2412000, 864000, 0x74c633d1 +-0, 2430000, 864000, 0x00251c31 +-0, 2448000, 864000, 0x6d12a499 +-0, 2466000, 864000, 0x1b6492e1 +-0, 2484000, 864000, 0xdfc9a2a1 +-0, 2502000, 864000, 0x33dcac79 +-0, 2520000, 864000, 0x2305a499 +-0, 2538000, 864000, 0xe1f3ae71 +-0, 2556000, 864000, 0xc0cc92e1 +-0, 2574000, 864000, 0x53d3b261 +-0, 2592000, 864000, 0xf953aa81 +-0, 2610000, 864000, 0x4108da69 +-0, 2628000, 864000, 0xd6acf9e9 +-0, 2646000, 864000, 0xb97ed900 +-0, 2664000, 864000, 0x1d8b7a80 +-0, 2682000, 864000, 0xd5406cb8 +-0, 2700000, 864000, 0x5aa34948 +-0, 2718000, 864000, 0x328eee01 +-0, 2736000, 864000, 0xac92e621 +-0, 2754000, 864000, 0x4fa1f5e1 +-0, 2772000, 864000, 0xf7c4e8a8 +-0, 2790000, 864000, 0xc358bd58 +-0, 2808000, 864000, 0x29ec4b27 +-0, 2826000, 864000, 0xf7219c88 +-0, 2844000, 864000, 0xe77ff130 +-0, 2862000, 864000, 0x73683417 +-0, 2880000, 864000, 0x08b6be77 +-0, 2898000, 864000, 0x3a7eea6f +-0, 2916000, 864000, 0xb319cce7 +-0, 2934000, 864000, 0x9607b13e +-0, 2952000, 864000, 0x30543f0d +-0, 2970000, 864000, 0x56915a9e +-0, 2988000, 864000, 0x79f158a6 +-0, 3006000, 864000, 0x498b8bd6 +-0, 3024000, 864000, 0xe9ad7046 +-0, 3042000, 864000, 0xe9ad7046 +-0, 3060000, 864000, 0x10317e0e +-0, 3078000, 864000, 0x10317e0e +-0, 3096000, 864000, 0x10317e0e +-0, 3114000, 864000, 0x99ec7046 +-0, 3132000, 864000, 0x924d46ee +-0, 3150000, 864000, 0x98bf333e +-0, 3168000, 864000, 0xb2625c96 +-0, 3186000, 864000, 0xb46b3926 +-0, 3204000, 864000, 0xeb4e5c96 +-0, 3222000, 864000, 0x87154ece +-0, 3240000, 864000, 0x9e4c666e +-0, 3258000, 864000, 0x65b53d16 +-0, 3276000, 864000, 0x99e85e8e +-0, 3294000, 864000, 0x650ba17e +-0, 3312000, 864000, 0x1ecb000e +-0, 3330000, 864000, 0xb942327d +-0, 3348000, 864000, 0x1bf20925 +-0, 3366000, 864000, 0x61dba6a5 +-0, 3384000, 864000, 0x5de16d8d +-0, 3402000, 864000, 0x4eb1f75d +-0, 3420000, 864000, 0x4eb1f75d +-0, 3438000, 864000, 0xd0750144 ++0, 0, 864000, 0xd6929ea7 ++0, 18000, 864000, 0x9d5283fa ++0, 36000, 864000, 0xcec52d42 ++0, 54000, 864000, 0x34d5943e ++0, 72000, 864000, 0x5bd0b2a8 ++0, 90000, 864000, 0x41f1c468 ++0, 108000, 864000, 0x16aa54b9 ++0, 126000, 864000, 0xdb92e88a ++0, 144000, 864000, 0x0ae5d695 ++0, 162000, 864000, 0x2c338d33 ++0, 180000, 864000, 0x2c338d33 ++0, 198000, 864000, 0x2c338d33 ++0, 216000, 864000, 0xd9c1152f ++0, 234000, 864000, 0x9833bf29 ++0, 252000, 864000, 0xbedbe1bc ++0, 270000, 864000, 0xd137d921 ++0, 288000, 864000, 0xcb0f967a ++0, 306000, 864000, 0x931a2881 ++0, 324000, 864000, 0xeb8ca351 ++0, 342000, 864000, 0xe2f66886 ++0, 360000, 864000, 0xb81fb99e ++0, 378000, 864000, 0x2048a4d9 ++0, 396000, 864000, 0x145b514f ++0, 414000, 864000, 0xcb6236f4 ++0, 432000, 864000, 0x6d2d79db ++0, 450000, 864000, 0xadca5356 ++0, 468000, 864000, 0x5d51f80c ++0, 486000, 864000, 0x9e240e68 ++0, 504000, 864000, 0xcafcbcc2 ++0, 522000, 864000, 0x76f99028 ++0, 540000, 864000, 0xd7450c61 ++0, 558000, 864000, 0x1431d79c ++0, 576000, 864000, 0x081a4e30 ++0, 594000, 864000, 0x0437c7d4 ++0, 612000, 864000, 0xb4bbea4b ++0, 630000, 864000, 0x0a149d41 ++0, 648000, 864000, 0xf7dbc0d5 ++0, 666000, 864000, 0x6933003c ++0, 684000, 864000, 0x18ce30e4 ++0, 702000, 864000, 0x8c8728c8 ++0, 720000, 864000, 0x37b6535b ++0, 738000, 864000, 0xcdab7be7 ++0, 756000, 864000, 0xe1e1cbe7 ++0, 774000, 864000, 0x1d476482 ++0, 792000, 864000, 0x0ae0b393 ++0, 810000, 864000, 0x49140206 ++0, 828000, 864000, 0xe9f9bd09 ++0, 846000, 864000, 0x89a7988b ++0, 864000, 864000, 0x24f780a7 ++0, 882000, 864000, 0x88a53dc0 ++0, 900000, 864000, 0x27ed3bb9 ++0, 918000, 864000, 0xc8151dfd ++0, 936000, 864000, 0xfcb8a9e0 ++0, 954000, 864000, 0xd6d554ba ++0, 972000, 864000, 0xbc6e06c6 ++0, 990000, 864000, 0x6334fc94 ++0, 1008000, 864000, 0x7a7e0cdb ++0, 1026000, 864000, 0xf96008cd ++0, 1044000, 864000, 0xffbc4dbb ++0, 1062000, 864000, 0x1071d886 ++0, 1080000, 864000, 0x6b967ed3 ++0, 1098000, 864000, 0xd370e0a2 ++0, 1116000, 864000, 0x4cca84e8 ++0, 1134000, 864000, 0xd46bdc94 ++0, 1152000, 864000, 0x102a54bf ++0, 1170000, 864000, 0xe39406cb ++0, 1188000, 864000, 0x9bb07ad9 ++0, 1206000, 864000, 0xd3b749b2 ++0, 1224000, 864000, 0x59faf47d ++0, 1242000, 864000, 0xba38de30 ++0, 1260000, 864000, 0x7084eed8 ++0, 1278000, 864000, 0xa966732d ++0, 1296000, 864000, 0xb9f1ee2b ++0, 1314000, 864000, 0x09267201 ++0, 1332000, 864000, 0xc6b09e30 ++0, 1350000, 864000, 0x080d1e77 ++0, 1368000, 864000, 0xe28bbdc5 ++0, 1386000, 864000, 0x230a30f8 ++0, 1404000, 864000, 0x4d0bb8cd ++0, 1422000, 864000, 0x96096417 ++0, 1440000, 864000, 0x7467d417 ++0, 1458000, 864000, 0xbcc07491 ++0, 1476000, 864000, 0x794718d7 ++0, 1494000, 864000, 0xf23ff243 ++0, 1512000, 864000, 0x9961bb86 ++0, 1530000, 864000, 0x7be4c703 ++0, 1548000, 864000, 0x727f8e3f ++0, 1566000, 864000, 0xda421623 ++0, 1584000, 864000, 0xca69ac6b ++0, 1602000, 864000, 0x67aeb68e ++0, 1620000, 864000, 0x3b665f61 ++0, 1638000, 864000, 0x3716150b ++0, 1656000, 864000, 0x2dcd57f2 ++0, 1674000, 864000, 0x800257f2 ++0, 1692000, 864000, 0x10de99ef ++0, 1710000, 864000, 0x3438389f ++0, 1728000, 864000, 0x42682867 ++0, 1746000, 864000, 0x9d64d5a9 ++0, 1764000, 864000, 0x9e2eb12b ++0, 1782000, 864000, 0xb9f42d64 ++0, 1800000, 864000, 0xd6f36c3d ++0, 1818000, 864000, 0xfeaa390f ++0, 1836000, 864000, 0x3fe067b0 ++0, 1854000, 864000, 0x45ebac70 ++0, 1872000, 864000, 0xabfb9215 ++0, 1890000, 864000, 0x20f79c38 ++0, 1908000, 864000, 0x326858d2 ++0, 1926000, 864000, 0x67154ef1 ++0, 1944000, 864000, 0x2b3d328f ++0, 1962000, 864000, 0x8190250b ++0, 1980000, 864000, 0x31dead22 ++0, 1998000, 864000, 0xa9b8d9bc ++0, 2016000, 864000, 0x330db698 ++0, 2034000, 864000, 0x0ff803b1 ++0, 2052000, 864000, 0xb7614eb4 ++0, 2070000, 864000, 0x12c75d64 ++0, 2088000, 864000, 0x622c03f3 ++0, 2106000, 864000, 0x0ace0b90 ++0, 2124000, 864000, 0x2c2b59c6 ++0, 2142000, 864000, 0xadbbe628 ++0, 2160000, 864000, 0x1371f576 ++0, 2178000, 864000, 0x066a471c ++0, 2196000, 864000, 0x0e6f8a03 ++0, 2214000, 864000, 0x4325670d ++0, 2232000, 864000, 0x2e8abe3a ++0, 2250000, 864000, 0x0ea8b8a4 ++0, 2268000, 864000, 0x65e4eb53 ++0, 2286000, 864000, 0xa03d108d ++0, 2304000, 864000, 0xd3d56fd6 ++0, 2322000, 864000, 0x1b8e4c47 ++0, 2340000, 864000, 0x5bd0316d ++0, 2358000, 864000, 0x49478b20 ++0, 2376000, 864000, 0x3dae9cb2 ++0, 2394000, 864000, 0x671e2b2a ++0, 2412000, 864000, 0x521763ee ++0, 2430000, 864000, 0x73dc4b9a ++0, 2448000, 864000, 0x3c95d7bf ++0, 2466000, 864000, 0x3abdc580 ++0, 2484000, 864000, 0xae24d5b8 ++0, 2502000, 864000, 0xe630dfdb ++0, 2520000, 864000, 0x229ad7bf ++0, 2538000, 864000, 0x3372e1e2 ++0, 2556000, 864000, 0xa821c580 ++0, 2574000, 864000, 0x7c78e5f0 ++0, 2592000, 864000, 0x3324ddd4 ++0, 2610000, 864000, 0x98580f38 ++0, 2628000, 864000, 0x14072fa8 ++0, 2646000, 864000, 0xdbb21510 ++0, 2664000, 864000, 0x6a55b3b1 ++0, 2682000, 864000, 0x7b5ba580 ++0, 2700000, 864000, 0x2f5e8102 ++0, 2718000, 864000, 0x691e2313 ++0, 2736000, 864000, 0x423b1af7 ++0, 2754000, 864000, 0x02842b2f ++0, 2772000, 864000, 0x8a4e24dd ++0, 2790000, 864000, 0xbbebf834 ++0, 2808000, 864000, 0x0ba68a3b ++0, 2826000, 864000, 0x6390d66a ++0, 2844000, 864000, 0x6ee32da6 ++0, 2862000, 864000, 0xace87229 ++0, 2880000, 864000, 0xb2a10064 ++0, 2898000, 864000, 0x9cc42dab ++0, 2916000, 864000, 0x32eb0f42 ++0, 2934000, 864000, 0x6cb1fa03 ++0, 2952000, 864000, 0xddd28c0a ++0, 2970000, 864000, 0xae5ca0cf ++0, 2988000, 864000, 0x4cb99ec8 ++0, 3006000, 864000, 0xdad7d37e ++0, 3024000, 864000, 0x7090b71c ++0, 3042000, 864000, 0x7090b71c ++0, 3060000, 864000, 0x96a4c54d ++0, 3078000, 864000, 0x96a4c54d ++0, 3096000, 864000, 0x96a4c54d ++0, 3114000, 864000, 0xc47eb71c ++0, 3132000, 864000, 0xcd678c89 ++0, 3150000, 864000, 0xb89e7843 ++0, 3168000, 864000, 0x7f3aa2d6 ++0, 3186000, 864000, 0xffc57e58 ++0, 3204000, 864000, 0x091fa2d6 ++0, 3222000, 864000, 0x3bc994a5 ++0, 3240000, 864000, 0x73afacf9 ++0, 3258000, 864000, 0x628b8266 ++0, 3276000, 864000, 0xe2f2a4dd ++0, 3294000, 864000, 0x7118e9cb ++0, 3312000, 864000, 0x65b1438d ++0, 3330000, 864000, 0x51657ec8 ++0, 3348000, 864000, 0x41a75435 ++0, 3366000, 864000, 0xe387f665 ++0, 3384000, 864000, 0x2baabb9a ++0, 3402000, 864000, 0xd2d74993 ++0, 3420000, 864000, 0xd2d74993 ++0, 3438000, 864000, 0xa7bf53b6 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vmnc-32bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vmnc-32bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vmnc-32bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vmnc-32bit 2012-05-14 14:08:55.732368118 +0200 +@@ -2,170 +2,48 @@ + 0, 18000, 3655644, 0x87973530 + 0, 36000, 3655644, 0x3c3167fd + 0, 54000, 3655644, 0x87973530 +-0, 72000, 3655644, 0x87973530 +-0, 90000, 3655644, 0x3c3167fd +-0, 108000, 3655644, 0x3c3167fd +-0, 126000, 3655644, 0x87973530 ++0, 72000, 3655644, 0x3c3167fd ++0, 90000, 3655644, 0x87973530 ++0, 108000, 3655644, 0x87973530 ++0, 126000, 3655644, 0x3c3167fd + 0, 144000, 3655644, 0x87973530 +-0, 162000, 3655644, 0x87973530 +-0, 180000, 3655644, 0x87973530 +-0, 198000, 3655644, 0x3c3167fd +-0, 216000, 3655644, 0x87973530 +-0, 234000, 3655644, 0x87973530 +-0, 252000, 3655644, 0x87973530 +-0, 270000, 3655644, 0x4f0da763 +-0, 288000, 3655644, 0x4f0da763 +-0, 306000, 3655644, 0x4f0da763 +-0, 324000, 3655644, 0x66a4a763 +-0, 342000, 3655644, 0xb20a7496 +-0, 360000, 3655644, 0x66a4a763 +-0, 378000, 3655644, 0x66a4a763 +-0, 396000, 3655644, 0x66a4a763 +-0, 414000, 3655644, 0x5600644a +-0, 432000, 3655644, 0xce5880ee +-0, 450000, 3655644, 0xce5880ee +-0, 468000, 3655644, 0xa993ef3d +-0, 486000, 3655644, 0xa993ef3d +-0, 504000, 3655644, 0xa993ef3d +-0, 522000, 3655644, 0xa993ef3d +-0, 540000, 3655644, 0xa993ef3d +-0, 558000, 3655644, 0xa993ef3d +-0, 576000, 3655644, 0xa993ef3d +-0, 594000, 3655644, 0xa993ef3d +-0, 612000, 3655644, 0xa993ef3d +-0, 630000, 3655644, 0xa993ef3d +-0, 648000, 3655644, 0xa993ef3d +-0, 666000, 3655644, 0xa993ef3d +-0, 684000, 3655644, 0xa993ef3d +-0, 702000, 3655644, 0xa993ef3d +-0, 720000, 3655644, 0xa993ef3d +-0, 738000, 3655644, 0xa993ef3d +-0, 756000, 3655644, 0xa993ef3d +-0, 774000, 3655644, 0xa993ef3d +-0, 792000, 3655644, 0xa993ef3d +-0, 810000, 3655644, 0xa993ef3d +-0, 828000, 3655644, 0xa993ef3d +-0, 846000, 3655644, 0xa993ef3d +-0, 864000, 3655644, 0xa993ef3d +-0, 882000, 3655644, 0x73564014 +-0, 900000, 3655644, 0x73564014 +-0, 918000, 3655644, 0x73564014 +-0, 936000, 3655644, 0x73564014 +-0, 954000, 3655644, 0x73564014 +-0, 972000, 3655644, 0x73564014 +-0, 990000, 3655644, 0x73564014 +-0, 1008000, 3655644, 0x73564014 +-0, 1026000, 3655644, 0x73564014 +-0, 1044000, 3655644, 0x73564014 +-0, 1062000, 3655644, 0x73564014 +-0, 1080000, 3655644, 0x73564014 +-0, 1098000, 3655644, 0x2a6e1e8c +-0, 1116000, 3655644, 0x2a6e1e8c +-0, 1134000, 3655644, 0x2a6e1e8c +-0, 1152000, 3655644, 0xbae02e7c +-0, 1170000, 3655644, 0xbae02e7c +-0, 1188000, 3655644, 0xbae02e7c +-0, 1206000, 3655644, 0xbae02e7c +-0, 1224000, 3655644, 0x55af4a2d +-0, 1242000, 3655644, 0x55af4a2d +-0, 1260000, 3655644, 0x55af4a2d +-0, 1278000, 3655644, 0x55af4a2d +-0, 1296000, 3655644, 0x54b7ff2d +-0, 1314000, 3655644, 0x39af1aed +-0, 1332000, 3655644, 0x39af1aed +-0, 1350000, 3655644, 0x39af1aed +-0, 1368000, 3655644, 0x39af1aed +-0, 1386000, 3655644, 0xe48dd11c +-0, 1404000, 3655644, 0xe48dd11c +-0, 1422000, 3655644, 0xe48dd11c +-0, 1440000, 3655644, 0xe48dd11c +-0, 1458000, 3655644, 0xe48dd11c +-0, 1476000, 3655644, 0xba15c78d +-0, 1494000, 3655644, 0xba15c78d +-0, 1512000, 3655644, 0xba15c78d +-0, 1530000, 3655644, 0xba15c78d +-0, 1548000, 3655644, 0xba15c78d +-0, 1566000, 3655644, 0xba15c78d +-0, 1584000, 3655644, 0xba15c78d +-0, 1602000, 3655644, 0x39af1aed +-0, 1620000, 3655644, 0x39af1aed +-0, 1638000, 3655644, 0x39af1aed +-0, 1656000, 3655644, 0x39af1aed +-0, 1674000, 3655644, 0x39af1aed +-0, 1692000, 3655644, 0x39af1aed +-0, 1710000, 3655644, 0x39af1aed +-0, 1728000, 3655644, 0x27f96cd8 +-0, 1746000, 3655644, 0x27f96cd8 +-0, 1764000, 3655644, 0x27f96cd8 +-0, 1782000, 3655644, 0x27f96cd8 +-0, 1800000, 3655644, 0x27f96cd8 +-0, 1818000, 3655644, 0x27f96cd8 +-0, 1836000, 3655644, 0x27f96cd8 +-0, 1854000, 3655644, 0xf4f068dc +-0, 1872000, 3655644, 0xf4f068dc +-0, 1890000, 3655644, 0xf4f068dc +-0, 1908000, 3655644, 0xf4f068dc +-0, 1926000, 3655644, 0xf4f068dc +-0, 1944000, 3655644, 0xf4f068dc +-0, 1962000, 3655644, 0xf4f068dc +-0, 1980000, 3655644, 0xf1c55cf5 +-0, 1998000, 3655644, 0xd932633d +-0, 2016000, 3655644, 0xd932633d +-0, 2034000, 3655644, 0xc6e95e0a +-0, 2052000, 3655644, 0x9a63c9de +-0, 2070000, 3655644, 0xf166ad4f +-0, 2088000, 3655644, 0xe9eeba41 +-0, 2106000, 3655644, 0x7e598ad7 +-0, 2124000, 3655644, 0xf3bd257e +-0, 2142000, 3655644, 0xf3bd257e +-0, 2160000, 3655644, 0xf3bd257e +-0, 2178000, 3655644, 0xf3bd257e +-0, 2196000, 3655644, 0xf3bd257e +-0, 2214000, 3655644, 0xf35b3852 +-0, 2232000, 3655644, 0xf35b3852 +-0, 2250000, 3655644, 0xf35b3852 +-0, 2268000, 3655644, 0xf35b3852 +-0, 2286000, 3655644, 0x9d553959 +-0, 2304000, 3655644, 0x0a9de8e2 +-0, 2322000, 3655644, 0xf2325b6c +-0, 2340000, 3655644, 0xf2325b6c +-0, 2358000, 3655644, 0xf2325b6c +-0, 2376000, 3655644, 0xf2325b6c +-0, 2394000, 3655644, 0xf2325b6c +-0, 2412000, 3655644, 0xf2325b6c +-0, 2430000, 3655644, 0xcf924028 +-0, 2448000, 3655644, 0xcf924028 +-0, 2466000, 3655644, 0x8dae55bc +-0, 2484000, 3655644, 0x8dae55bc +-0, 2502000, 3655644, 0x57b08ced +-0, 2520000, 3655644, 0x57b08ced +-0, 2538000, 3655644, 0xef89a1d8 +-0, 2556000, 3655644, 0xef89a1d8 +-0, 2574000, 3655644, 0x69e5503a +-0, 2592000, 3655644, 0x69e5503a +-0, 2610000, 3655644, 0xc3de7b3f +-0, 2628000, 3655644, 0xc3de7b3f +-0, 2646000, 3655644, 0x88eea64a +-0, 2664000, 3655644, 0x88eea64a +-0, 2682000, 3655644, 0xe39cce1f +-0, 2700000, 3655644, 0xe39cce1f +-0, 2718000, 3655644, 0xe39cce1f +-0, 2736000, 3655644, 0xe39cce1f +-0, 2754000, 3655644, 0xe39cce1f +-0, 2772000, 3655644, 0xe39cce1f +-0, 2790000, 3655644, 0xe39cce1f +-0, 2808000, 3655644, 0xe39cce1f +-0, 2826000, 3655644, 0xe39cce1f +-0, 2844000, 3655644, 0xe39cce1f +-0, 2862000, 3655644, 0xe39cce1f +-0, 2880000, 3655644, 0xe39cce1f +-0, 2898000, 3655644, 0xe39cce1f +-0, 2916000, 3655644, 0xf0ed0d04 +-0, 2934000, 3655644, 0xf0ed0d04 +-0, 2952000, 3655644, 0xf0ed0d04 +-0, 2970000, 3655644, 0xf0ed0d04 +-0, 2988000, 3655644, 0x32490d3e +-0, 3006000, 3655644, 0x32490d3e +-0, 3024000, 3655644, 0x32490d3e +-0, 3042000, 3655644, 0x32490d3e +-0, 3060000, 3655644, 0x32490d3e ++0, 162000, 3655644, 0x4f0da763 ++0, 180000, 3655644, 0x66a4a763 ++0, 198000, 3655644, 0xb20a7496 ++0, 216000, 3655644, 0x66a4a763 ++0, 234000, 3655644, 0x5600644a ++0, 252000, 3655644, 0xce5880ee ++0, 270000, 3655644, 0xa993ef3d ++0, 288000, 3655644, 0x73564014 ++0, 306000, 3655644, 0x2a6e1e8c ++0, 324000, 3655644, 0xbae02e7c ++0, 342000, 3655644, 0x55af4a2d ++0, 360000, 3655644, 0x54b7ff2d ++0, 378000, 3655644, 0x39af1aed ++0, 396000, 3655644, 0xe48dd11c ++0, 414000, 3655644, 0xba15c78d ++0, 432000, 3655644, 0x39af1aed ++0, 450000, 3655644, 0x27f96cd8 ++0, 468000, 3655644, 0xf4f068dc ++0, 486000, 3655644, 0xf1c55cf5 ++0, 504000, 3655644, 0xd932633d ++0, 522000, 3655644, 0xc6e95e0a ++0, 540000, 3655644, 0x9a63c9de ++0, 558000, 3655644, 0xf166ad4f ++0, 576000, 3655644, 0xe9eeba41 ++0, 594000, 3655644, 0x7e598ad7 ++0, 612000, 3655644, 0xf3bd257e ++0, 630000, 3655644, 0xf35b3852 ++0, 648000, 3655644, 0x9d553959 ++0, 666000, 3655644, 0x0a9de8e2 ++0, 684000, 3655644, 0xf2325b6c ++0, 702000, 3655644, 0xcf924028 ++0, 720000, 3655644, 0x8dae55bc ++0, 738000, 3655644, 0x57b08ced ++0, 756000, 3655644, 0xef89a1d8 ++0, 774000, 3655644, 0x69e5503a ++0, 792000, 3655644, 0xc3de7b3f ++0, 810000, 3655644, 0x88eea64a ++0, 828000, 3655644, 0xe39cce1f ++0, 846000, 3655644, 0xf0ed0d04 ++0, 864000, 3655644, 0x32490d3e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp3 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp3 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp3 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp3 1970-01-01 01:00:00.000000000 +0100 +@@ -1,114 +0,0 @@ +-0, 0, 261120, 0xc50dec2b +-0, 3600, 261120, 0xaa8d4441 +-0, 7200, 261120, 0x932b0d44 +-0, 10800, 261120, 0x125e1af7 +-0, 14400, 261120, 0x09a763a5 +-0, 18000, 261120, 0x56939852 +-0, 21600, 261120, 0x0eda6d35 +-0, 25200, 261120, 0x2f0d3869 +-0, 28800, 261120, 0xe177c34c +-0, 32400, 261120, 0x5d4e833a +-0, 36000, 261120, 0x42e26e7a +-0, 39600, 261120, 0xf5a60b4c +-0, 43200, 261120, 0x29938341 +-0, 46800, 261120, 0x0a9ebb80 +-0, 50400, 261120, 0xd18c6a11 +-0, 54000, 261120, 0x4b8212ac +-0, 57600, 261120, 0x7902aabc +-0, 61200, 261120, 0x4babac44 +-0, 64800, 261120, 0xf33efa46 +-0, 68400, 261120, 0x110dd40a +-0, 72000, 261120, 0xae327a8a +-0, 75600, 261120, 0xab757d75 +-0, 79200, 261120, 0xfbd1402d +-0, 82800, 261120, 0x4f2c5d31 +-0, 86400, 261120, 0xc7ea2149 +-0, 90000, 261120, 0x86072cf7 +-0, 93600, 261120, 0x37c2f2ed +-0, 97200, 261120, 0x1d51ee83 +-0, 100800, 261120, 0x72291b8b +-0, 104400, 261120, 0xe9c8ffaf +-0, 108000, 261120, 0x657a1615 +-0, 111600, 261120, 0x6f832019 +-0, 115200, 261120, 0xf4445a22 +-0, 118800, 261120, 0x105306f0 +-0, 122400, 261120, 0x34c0c36b +-0, 126000, 261120, 0x7767be18 +-0, 129600, 261120, 0x88a7eaeb +-0, 133200, 261120, 0x797e69e4 +-0, 136800, 261120, 0x78901f02 +-0, 140400, 261120, 0xbc91758e +-0, 144000, 261120, 0x35d47b24 +-0, 147600, 261120, 0xaf0ebc82 +-0, 151200, 261120, 0x40e63004 +-0, 154800, 261120, 0x70d1c5c1 +-0, 158400, 261120, 0x8aea2b70 +-0, 162000, 261120, 0x51f3cd81 +-0, 165600, 261120, 0x8f8584b7 +-0, 169200, 261120, 0x921541fb +-0, 172800, 261120, 0xddd3f1ea +-0, 176400, 261120, 0x6be2e960 +-0, 180000, 261120, 0x72997a1f +-0, 183600, 261120, 0xe70fc009 +-0, 187200, 261120, 0x816a0687 +-0, 190800, 261120, 0x2aa79e82 +-0, 194400, 261120, 0x85f2fe5c +-0, 198000, 261120, 0x000dd8b6 +-0, 201600, 261120, 0x1be19dd4 +-0, 205200, 261120, 0xadea80e5 +-0, 208800, 261120, 0x0cc2204f +-0, 212400, 261120, 0xd62968a8 +-0, 216000, 261120, 0x0afc75c2 +-0, 219600, 261120, 0x82341f09 +-0, 223200, 261120, 0xbf7e66cd +-0, 226800, 261120, 0x8f3491df +-0, 230400, 261120, 0xc316d383 +-0, 234000, 261120, 0x3de7f632 +-0, 237600, 261120, 0xda55cfb0 +-0, 241200, 261120, 0xbd88bb46 +-0, 244800, 261120, 0x75444b17 +-0, 248400, 261120, 0x798cc498 +-0, 252000, 261120, 0xf9a60fa6 +-0, 255600, 261120, 0xbd8debd7 +-0, 259200, 261120, 0x7c890029 +-0, 262800, 261120, 0x7a75e44a +-0, 266400, 261120, 0x1f04611c +-0, 270000, 261120, 0x96b3ee93 +-0, 273600, 261120, 0x7fc11f39 +-0, 277200, 261120, 0xe87d6864 +-0, 280800, 261120, 0x6797d904 +-0, 284400, 261120, 0x9e3e7bde +-0, 288000, 261120, 0xc31a8039 +-0, 291600, 261120, 0xe3ef4cf7 +-0, 295200, 261120, 0x83c56fc9 +-0, 298800, 261120, 0xb304f7aa +-0, 302400, 261120, 0x039a7080 +-0, 306000, 261120, 0xffb08224 +-0, 309600, 261120, 0xa7be783a +-0, 313200, 261120, 0x572beff3 +-0, 316800, 261120, 0x1bc59ae8 +-0, 320400, 261120, 0x11c8feb4 +-0, 324000, 261120, 0xe2398651 +-0, 327600, 261120, 0x37c3efba +-0, 331200, 261120, 0xb32f0dd4 +-0, 334800, 261120, 0x66880c50 +-0, 338400, 261120, 0x4f7392c8 +-0, 342000, 261120, 0x3d5c08f6 +-0, 345600, 261120, 0xfd129211 +-0, 349200, 261120, 0x9b396ebe +-0, 352800, 261120, 0x75ab9a4a +-0, 356400, 261120, 0xf8c4e7ea +-0, 360000, 261120, 0xdd48c7c3 +-0, 363600, 261120, 0xdebf20e6 +-0, 367200, 261120, 0x35c32091 +-0, 370800, 261120, 0xce5a49c7 +-0, 374400, 261120, 0x69fc8e0d +-0, 378000, 261120, 0x43a08b41 +-0, 381600, 261120, 0x01a0513c +-0, 385200, 261120, 0x1d3f490a +-0, 388800, 261120, 0xb44df252 +-0, 392400, 261120, 0x1259753e +-0, 396000, 261120, 0x4a1538d6 +-0, 399600, 261120, 0xd5ed4bd5 +-0, 403200, 261120, 0xa21590b5 +-0, 406800, 261120, 0xfb2de1f7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp31 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp31 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp31 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp31 2012-05-14 14:08:55.734368158 +0200 +@@ -0,0 +1,114 @@ ++0, 0, 261120, 0xc50dec2b ++0, 3600, 261120, 0xaa8d4441 ++0, 7200, 261120, 0x932b0d44 ++0, 10800, 261120, 0x125e1af7 ++0, 14400, 261120, 0x09a763a5 ++0, 18000, 261120, 0x56939852 ++0, 21600, 261120, 0x0eda6d35 ++0, 25200, 261120, 0x2f0d3869 ++0, 28800, 261120, 0xe177c34c ++0, 32400, 261120, 0x5d4e833a ++0, 36000, 261120, 0x42e26e7a ++0, 39600, 261120, 0xf5a60b4c ++0, 43200, 261120, 0x29938341 ++0, 46800, 261120, 0x0a9ebb80 ++0, 50400, 261120, 0xd18c6a11 ++0, 54000, 261120, 0x4b8212ac ++0, 57600, 261120, 0x7902aabc ++0, 61200, 261120, 0x4babac44 ++0, 64800, 261120, 0xf33efa46 ++0, 68400, 261120, 0x110dd40a ++0, 72000, 261120, 0xae327a8a ++0, 75600, 261120, 0xab757d75 ++0, 79200, 261120, 0xfbd1402d ++0, 82800, 261120, 0x4f2c5d31 ++0, 86400, 261120, 0xc7ea2149 ++0, 90000, 261120, 0x86072cf7 ++0, 93600, 261120, 0x37c2f2ed ++0, 97200, 261120, 0x1d51ee83 ++0, 100800, 261120, 0x72291b8b ++0, 104400, 261120, 0xe9c8ffaf ++0, 108000, 261120, 0x657a1615 ++0, 111600, 261120, 0x6f832019 ++0, 115200, 261120, 0xf4445a22 ++0, 118800, 261120, 0x105306f0 ++0, 122400, 261120, 0x34c0c36b ++0, 126000, 261120, 0x7767be18 ++0, 129600, 261120, 0x88a7eaeb ++0, 133200, 261120, 0x797e69e4 ++0, 136800, 261120, 0x78901f02 ++0, 140400, 261120, 0xbc91758e ++0, 144000, 261120, 0x35d47b24 ++0, 147600, 261120, 0xaf0ebc82 ++0, 151200, 261120, 0x40e63004 ++0, 154800, 261120, 0x70d1c5c1 ++0, 158400, 261120, 0x8aea2b70 ++0, 162000, 261120, 0x51f3cd81 ++0, 165600, 261120, 0x8f8584b7 ++0, 169200, 261120, 0x921541fb ++0, 172800, 261120, 0xddd3f1ea ++0, 176400, 261120, 0x6be2e960 ++0, 180000, 261120, 0x72997a1f ++0, 183600, 261120, 0xe70fc009 ++0, 187200, 261120, 0x816a0687 ++0, 190800, 261120, 0x2aa79e82 ++0, 194400, 261120, 0x85f2fe5c ++0, 198000, 261120, 0x000dd8b6 ++0, 201600, 261120, 0x1be19dd4 ++0, 205200, 261120, 0xadea80e5 ++0, 208800, 261120, 0x0cc2204f ++0, 212400, 261120, 0xd62968a8 ++0, 216000, 261120, 0x0afc75c2 ++0, 219600, 261120, 0x82341f09 ++0, 223200, 261120, 0xbf7e66cd ++0, 226800, 261120, 0x8f3491df ++0, 230400, 261120, 0xc316d383 ++0, 234000, 261120, 0x3de7f632 ++0, 237600, 261120, 0xda55cfb0 ++0, 241200, 261120, 0xbd88bb46 ++0, 244800, 261120, 0x75444b17 ++0, 248400, 261120, 0x798cc498 ++0, 252000, 261120, 0xf9a60fa6 ++0, 255600, 261120, 0xbd8debd7 ++0, 259200, 261120, 0x7c890029 ++0, 262800, 261120, 0x7a75e44a ++0, 266400, 261120, 0x1f04611c ++0, 270000, 261120, 0x96b3ee93 ++0, 273600, 261120, 0x7fc11f39 ++0, 277200, 261120, 0xe87d6864 ++0, 280800, 261120, 0x6797d904 ++0, 284400, 261120, 0x9e3e7bde ++0, 288000, 261120, 0xc31a8039 ++0, 291600, 261120, 0xe3ef4cf7 ++0, 295200, 261120, 0x83c56fc9 ++0, 298800, 261120, 0xb304f7aa ++0, 302400, 261120, 0x039a7080 ++0, 306000, 261120, 0xffb08224 ++0, 309600, 261120, 0xa7be783a ++0, 313200, 261120, 0x572beff3 ++0, 316800, 261120, 0x1bc59ae8 ++0, 320400, 261120, 0x11c8feb4 ++0, 324000, 261120, 0xe2398651 ++0, 327600, 261120, 0x37c3efba ++0, 331200, 261120, 0xb32f0dd4 ++0, 334800, 261120, 0x66880c50 ++0, 338400, 261120, 0x4f7392c8 ++0, 342000, 261120, 0x3d5c08f6 ++0, 345600, 261120, 0xfd129211 ++0, 349200, 261120, 0x9b396ebe ++0, 352800, 261120, 0x75ab9a4a ++0, 356400, 261120, 0xf8c4e7ea ++0, 360000, 261120, 0xdd48c7c3 ++0, 363600, 261120, 0xdebf20e6 ++0, 367200, 261120, 0x35c32091 ++0, 370800, 261120, 0xce5a49c7 ++0, 374400, 261120, 0x69fc8e0d ++0, 378000, 261120, 0x43a08b41 ++0, 381600, 261120, 0x01a0513c ++0, 385200, 261120, 0x1d3f490a ++0, 388800, 261120, 0xb44df252 ++0, 392400, 261120, 0x1259753e ++0, 396000, 261120, 0x4a1538d6 ++0, 399600, 261120, 0xd5ed4bd5 ++0, 403200, 261120, 0xa21590b5 ++0, 406800, 261120, 0xfb2de1f7 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp3-coeff-level64 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp3-coeff-level64 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp3-coeff-level64 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp3-coeff-level64 2012-05-14 14:08:55.733368138 +0200 +@@ -0,0 +1,8 @@ ++0, 0, 4617600, 0x4ba6df50 ++0, 6000, 4617600, 0x419fdeaf ++0, 12000, 4617600, 0xeb2edced ++0, 18000, 4617600, 0xa2bb3a1a ++0, 24000, 4617600, 0x411cfb36 ++0, 30000, 4617600, 0xb2dc22ed ++0, 36000, 4617600, 0x236d23b5 ++0, 42000, 4617600, 0x7fef275e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp5 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp5 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vp5 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vp5 2012-05-14 14:08:55.735368178 +0200 +@@ -244,3 +244,4 @@ + 0, 912161, 233472, 0x6f530ac6 + 0, 915915, 233472, 0x94f7466c + 0, 919669, 233472, 0xa8c1d365 ++0, 923423, 233472, 0xedcff050 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vqa-cc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vqa-cc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/vqa-cc 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/vqa-cc 2012-05-14 14:08:55.735368178 +0200 +@@ -1,73 +1,74 @@ +-1, 0, 22048, 0x0665d7f4 + 0, 0, 192000, 0x00000000 ++1, 0, 22048, 0x0665d7f4 + 0, 6000, 192000, 0x00000000 + 0, 12000, 192000, 0x00000000 + 0, 18000, 192000, 0x00000000 +-0, 24000, 192000, 0xcd900ccc +-0, 30000, 192000, 0xfd496438 +-0, 36000, 192000, 0x965f0bf3 +-0, 42000, 192000, 0x378fca5f ++0, 24000, 192000, 0x9ee00ccf ++0, 30000, 192000, 0x67256507 ++0, 36000, 192000, 0x74c70e87 ++0, 42000, 192000, 0x8ecdce9a + 1, 44996, 2940, 0x0f3c64cb +-0, 48000, 192000, 0x5ccd8966 ++0, 48000, 192000, 0xc40f8efd + 1, 50996, 2940, 0xc90b9e78 +-0, 54000, 192000, 0x859676f9 ++0, 54000, 192000, 0xb8107dfb + 1, 56996, 2940, 0x146246a3 +-0, 60000, 192000, 0x820bfb1c ++0, 60000, 192000, 0xb4e504eb + 1, 62996, 2940, 0xd22c714e +-0, 66000, 192000, 0x7570cc05 ++0, 66000, 192000, 0x0c7fdb95 + 1, 68996, 2940, 0xd86b681e +-0, 72000, 192000, 0xf38bdb06 ++0, 72000, 192000, 0x58c9f045 + 1, 74996, 2940, 0x12ec8186 +-0, 78000, 192000, 0x9b0cbb44 ++0, 78000, 192000, 0xcba9d0e9 + 1, 80996, 2940, 0x69aa85b6 +-0, 84000, 192000, 0x0ed70665 ++0, 84000, 192000, 0x392a20f6 + 1, 86996, 2940, 0xb24d33b0 +-0, 90000, 192000, 0xd16de7fc ++0, 90000, 192000, 0xc37905cc + 1, 92996, 2940, 0x3f7b0f0d +-0, 96000, 192000, 0x97afb484 ++0, 96000, 192000, 0xe278cf95 + 1, 98996, 2940, 0x64f10f7e +-0, 102000, 192000, 0x012893f3 ++0, 102000, 192000, 0x3d03b01d + 1, 104996, 2940, 0xd6ea379a +-0, 108000, 192000, 0x742a4b43 ++0, 108000, 192000, 0x16a26f28 + 1, 110996, 2940, 0x7c38e830 +-0, 114000, 192000, 0x309dcd75 ++0, 114000, 192000, 0xdd17f51c + 1, 116996, 2940, 0xc28ff132 +-0, 120000, 192000, 0xed7814ac ++0, 120000, 192000, 0x19703b85 + 1, 122996, 2940, 0xe7b11629 +-0, 126000, 192000, 0xdb7de3d7 ++0, 126000, 192000, 0xe51f0e70 + 1, 128996, 2940, 0xeb86fdcb +-0, 132000, 192000, 0xe18679a3 ++0, 132000, 192000, 0x6f94ad2a + 1, 134996, 2940, 0x5508f586 +-0, 138000, 192000, 0xb1f213f4 ++0, 138000, 192000, 0x71e449f1 + 1, 140996, 2940, 0xf4fa1f1b +-0, 144000, 192000, 0x33c99b5c ++0, 144000, 192000, 0x1dcacc52 + 1, 146996, 2940, 0x9e5ff976 +-0, 150000, 192000, 0xf66c0c91 ++0, 150000, 192000, 0x49c23f58 + 1, 152996, 2940, 0xcfc4e08f +-0, 156000, 192000, 0x929cdc73 ++0, 156000, 192000, 0x4ce61551 + 1, 158996, 2940, 0x74bde7ed +-0, 162000, 192000, 0xa723fc3b ++0, 162000, 192000, 0xe54832d5 + 1, 164996, 2940, 0x3e4ae245 +-0, 168000, 192000, 0xe6395ccc ++0, 168000, 192000, 0xbae28a59 + 1, 170996, 2940, 0x4c6a8e56 +-0, 174000, 192000, 0x147fbf74 ++0, 174000, 192000, 0xe8a4efbe + 1, 176996, 2940, 0xa09d86ab +-0, 180000, 192000, 0x3ec62d28 ++0, 180000, 192000, 0xe9e96883 + 1, 182996, 2940, 0xc8531912 +-0, 186000, 192000, 0x22104ffb ++0, 186000, 192000, 0xa5468c49 + 1, 188996, 2940, 0xa5f266aa +-0, 192000, 192000, 0x91f25f58 ++0, 192000, 192000, 0x7ec6936a + 1, 194996, 2940, 0x587a4187 +-0, 198000, 192000, 0xc91b0e4e ++0, 198000, 192000, 0x46e53ee4 + 1, 200996, 2940, 0x14752d45 +-0, 204000, 192000, 0x4683df56 ++0, 204000, 192000, 0x937b168a + 1, 206996, 2940, 0x558cde10 +-0, 210000, 192000, 0x8ef8932a ++0, 210000, 192000, 0xed76cec4 + 1, 212996, 2940, 0x735fee38 +-0, 216000, 192000, 0xce6c0ec0 ++0, 216000, 192000, 0x4b9f454d + 1, 218996, 2940, 0xac8bb6c8 +-0, 222000, 192000, 0xcc10e2a0 ++0, 222000, 192000, 0xb58c1566 + 1, 224996, 2940, 0xa503c73b ++0, 228000, 192000, 0xb58c1566 + 1, 230996, 2940, 0x7cd588a3 + 1, 236996, 2940, 0xa6974b04 + 1, 242996, 2940, 0xbf448241 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-drm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-drm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-drm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-drm 2012-05-14 14:08:55.736368198 +0200 +@@ -1,162 +1,130 @@ + 0, 0, 84480, 0x7760a00b + 0, 3750, 84480, 0xfe39a1db +-0, 7500, 84480, 0xfe39a1db +-0, 11250, 84480, 0xfe39a1db +-0, 15000, 84480, 0xfe39a1db +-0, 18750, 84480, 0xfe39a1db +-0, 22500, 84480, 0xfe39a1db +-0, 26250, 84480, 0xfe39a1db +-0, 30000, 84480, 0xfe39a1db +-0, 33750, 84480, 0xfe39a1db +-0, 37500, 84480, 0xfe39a1db +-0, 41250, 84480, 0xfe39a1db +-0, 45000, 84480, 0xfe39a1db +-0, 48750, 84480, 0xfe39a1db +-0, 52500, 84480, 0xfe39a1db +-0, 56250, 84480, 0xfe39a1db +-0, 60000, 84480, 0xfe39a1db +-0, 63750, 84480, 0xfe39a1db +-0, 67500, 84480, 0xfe39a1db +-0, 71250, 84480, 0xfe39a1db +-0, 75000, 84480, 0xfe39a1db +-0, 78750, 84480, 0xfe39a1db +-0, 82500, 84480, 0xfe39a1db +-0, 86250, 84480, 0xfe39a1db +-0, 90000, 84480, 0xfe39a1db +-0, 93750, 84480, 0xfe39a1db +-0, 97500, 84480, 0xfe39a1db +-0, 101250, 84480, 0xfe39a1db +-0, 105000, 84480, 0xfe39a1db +-0, 108750, 84480, 0xd71961b4 +-0, 112500, 84480, 0xc80dedba +-0, 116250, 84480, 0x34d8b538 +-0, 120000, 84480, 0x1a86b8e5 +-0, 123750, 84480, 0xabf7c25d +-0, 127500, 84480, 0x912600ee +-0, 131250, 84480, 0x7ee7c70b +-0, 135000, 84480, 0xe212b0d1 +-0, 138750, 84480, 0xd4fa6c16 +-0, 142500, 84480, 0xd10fa126 +-0, 146250, 84480, 0xda91d3aa +-0, 150000, 84480, 0xd90be940 +-0, 153750, 84480, 0x908a009b +-0, 157500, 84480, 0xdd26d6e9 +-0, 161250, 84480, 0xfeda8de9 +-0, 165000, 84480, 0x96d66505 +-0, 168750, 84480, 0xf43b4b1b +-0, 172500, 84480, 0xd44122c2 +-0, 176250, 84480, 0xc65da7a9 +-0, 180000, 84480, 0xbf4178f2 +-0, 183750, 84480, 0x96be846a +-0, 187500, 84480, 0x73e6459e +-0, 191250, 84480, 0x70086917 +-0, 195000, 84480, 0x9b12571d +-0, 198750, 84480, 0xe4ce7bce +-0, 202500, 84480, 0x845672e5 +-0, 206250, 84480, 0x1c17e189 +-0, 210000, 84480, 0x12a877d0 +-0, 213750, 84480, 0xca62e8ed +-0, 217500, 84480, 0x87beb28f +-0, 221250, 84480, 0x1ba915a4 +-0, 225000, 84480, 0x159fc9c4 +-0, 228750, 84480, 0xcec3e3ef +-0, 232500, 84480, 0x96a42f48 +-0, 236250, 84480, 0xcd17decf +-0, 240000, 84480, 0x4cf95d6c +-0, 243750, 84480, 0xa258400e +-0, 247500, 84480, 0xb9c566d8 +-0, 251250, 84480, 0xc39f6dab +-0, 255000, 84480, 0xd08a0880 +-0, 258750, 84480, 0x41e3a70f +-0, 262500, 84480, 0x0ded83d9 +-0, 266250, 84480, 0x74a915ea +-0, 270000, 84480, 0x00c2c849 +-0, 273750, 84480, 0x709a9b07 +-0, 277500, 84480, 0xfb276daa +-0, 281250, 84480, 0x89ca744b +-0, 285000, 84480, 0x457ba569 +-0, 288750, 84480, 0xc37c8d57 +-0, 292500, 84480, 0x1890a97e +-0, 296250, 84480, 0xe455b8d0 +-0, 300000, 84480, 0x1f6bdbce +-0, 303750, 84480, 0x9df90ed1 +-0, 307500, 84480, 0xff80328c +-0, 311250, 84480, 0x0e115940 +-0, 315000, 84480, 0x09ddc11d +-0, 318750, 84480, 0xeef241e9 +-0, 322500, 84480, 0xbe3578b4 +-0, 326250, 84480, 0x2a83f0f3 +-0, 330000, 84480, 0xb41d01c2 +-0, 333750, 84480, 0x630efd97 +-0, 337500, 84480, 0xd592140d +-0, 341250, 84480, 0x7110f627 +-0, 345000, 84480, 0x2dbaa590 +-0, 348750, 84480, 0x13d80be5 +-0, 352500, 84480, 0xb8f3740d +-0, 356250, 84480, 0xd9a6fcef +-0, 360000, 84480, 0x56bfa4e3 +-0, 363750, 84480, 0x49364550 +-0, 367500, 84480, 0x0a2f1690 +-0, 371250, 84480, 0xb87fccbf +-0, 375000, 84480, 0xb2aa69f7 +-0, 378750, 84480, 0x176bf378 +-0, 382500, 84480, 0xe7a6de45 +-0, 386250, 84480, 0x8e3900a6 +-0, 390000, 84480, 0x24a72099 +-0, 393750, 84480, 0x5394df95 +-0, 397500, 84480, 0xd648c92e +-0, 401250, 84480, 0xab95fb62 +-0, 405000, 84480, 0xe3239cb0 +-0, 408750, 84480, 0xb4f93467 +-0, 412500, 84480, 0x94d0d01d +-0, 416250, 84480, 0x6316a25e +-0, 420000, 84480, 0x6316a25e +-0, 423750, 84480, 0x6316a25e +-0, 427500, 84480, 0x6316a25e +-0, 431250, 84480, 0x6316a25e +-0, 435000, 84480, 0x6316a25e +-0, 438750, 84480, 0x6316a25e +-0, 442500, 84480, 0xae1c8854 +-0, 446250, 84480, 0x30fe68bf +-0, 450000, 84480, 0xfd1435c8 +-0, 453750, 84480, 0xddf57fab +-0, 457500, 84480, 0xc3553a51 +-0, 461250, 84480, 0xd9ce7ae8 +-0, 465000, 84480, 0x671765cb +-0, 468750, 84480, 0x78336eab +-0, 472500, 84480, 0xb66b659c +-0, 476250, 84480, 0x0e1f68bb +-0, 480000, 84480, 0x8f4669dc +-0, 483750, 84480, 0x60c47360 +-0, 487500, 84480, 0x93037246 +-0, 491250, 84480, 0xdebe620d +-0, 495000, 84480, 0x7555161e +-0, 498750, 84480, 0xcbaf4311 +-0, 502500, 84480, 0x8e3783a0 +-0, 506250, 84480, 0x3888008f +-0, 510000, 84480, 0x8a4fa114 +-0, 513750, 84480, 0xac0bf10b +-0, 517500, 84480, 0xb485ff7f +-0, 521250, 84480, 0xeaec2133 +-0, 525000, 84480, 0x105827cd +-0, 528750, 84480, 0x55ff4b2d +-0, 532500, 84480, 0x78c64a49 +-0, 536250, 84480, 0x3897731d +-0, 540000, 84480, 0x9ca891aa +-0, 543750, 84480, 0x24a6ab0a +-0, 547500, 84480, 0x88fdc6fb +-0, 551250, 84480, 0x05afea61 +-0, 555000, 84480, 0xe703e2cf +-0, 558750, 84480, 0x9eb0e64a +-0, 562500, 84480, 0x92a7f0ab +-0, 566250, 84480, 0xec2bfbfb +-0, 570000, 84480, 0x7db600ad +-0, 573750, 84480, 0x4abd6393 +-0, 577500, 84480, 0x54ce06b5 +-0, 581250, 84480, 0x7cb6f150 +-0, 585000, 84480, 0x099d4aeb +-0, 588750, 84480, 0x0bcfdc31 +-0, 592500, 84480, 0xe4e72d1f +-0, 596250, 84480, 0xbce22331 +-0, 600000, 84480, 0x020545d7 +-0, 603750, 84480, 0x71869e48 ++0, 7500, 84480, 0xd71961b4 ++0, 11250, 84480, 0xc80dedba ++0, 15000, 84480, 0x34d8b538 ++0, 18750, 84480, 0x1a86b8e5 ++0, 22500, 84480, 0xabf7c25d ++0, 26250, 84480, 0x912600ee ++0, 30000, 84480, 0x7ee7c70b ++0, 33750, 84480, 0x09c5b0d1 ++0, 37500, 84480, 0x6dbe6c0c ++0, 41250, 84480, 0x0fe0a120 ++0, 45000, 84480, 0x2352d3a2 ++0, 48750, 84480, 0xb22ce92e ++0, 52500, 84480, 0x31db0099 ++0, 56250, 84480, 0xad2dd73a ++0, 60000, 84480, 0xb9af8e20 ++0, 63750, 84480, 0x7b956549 ++0, 67500, 84480, 0x3f774b87 ++0, 71250, 84480, 0x824a23a3 ++0, 75000, 84480, 0x4469a8d8 ++0, 78750, 84480, 0xc80c7a0a ++0, 82500, 84480, 0xcf958549 ++0, 86250, 84480, 0x449746e3 ++0, 90000, 84480, 0xbac66a82 ++0, 93750, 84480, 0x99e85855 ++0, 97500, 84480, 0xa4a17d17 ++0, 101250, 84480, 0xe29c7587 ++0, 105000, 84480, 0x551de592 ++0, 108750, 84480, 0xe0877bce ++0, 112500, 84480, 0x9660eb35 ++0, 116250, 84480, 0x0a34b644 ++0, 120000, 84480, 0x352919f0 ++0, 123750, 84480, 0xef56ce27 ++0, 127500, 84480, 0x030fe862 ++0, 131250, 84480, 0x2eba33e2 ++0, 135000, 84480, 0x242de401 ++0, 138750, 84480, 0xbadd61ca ++0, 142500, 84480, 0x2060465b ++0, 146250, 84480, 0x256e6965 ++0, 150000, 84480, 0x243b7084 ++0, 153750, 84480, 0x8b3c0b47 ++0, 157500, 84480, 0xc174a9af ++0, 161250, 84480, 0xb6d48686 ++0, 165000, 84480, 0xa3dd1871 ++0, 168750, 84480, 0x04cdcaf7 ++0, 172500, 84480, 0x55f89c94 ++0, 176250, 84480, 0xda657032 ++0, 180000, 84480, 0x38ba7698 ++0, 183750, 84480, 0x4d03a7f2 ++0, 187500, 84480, 0x115d9035 ++0, 191250, 84480, 0x24c6acc6 ++0, 195000, 84480, 0xdd2bbcae ++0, 198750, 84480, 0xb4fee0b9 ++0, 202500, 84480, 0xc51c14e0 ++0, 206250, 84480, 0xfb7737de ++0, 210000, 84480, 0x38675fb0 ++0, 213750, 84480, 0x4752c710 ++0, 217500, 84480, 0xfeb7491b ++0, 221250, 84480, 0xaa248122 ++0, 225000, 84480, 0x9a4af87c ++0, 228750, 84480, 0xedcf09df ++0, 232500, 84480, 0x563a05df ++0, 236250, 84480, 0x0dde1e03 ++0, 240000, 84480, 0xd8f0ff65 ++0, 243750, 84480, 0xbeb9ae1a ++0, 247500, 84480, 0x416d1468 ++0, 251250, 84480, 0x66c87d4c ++0, 255000, 84480, 0xa67c0774 ++0, 258750, 84480, 0xd8f8aec1 ++0, 262500, 84480, 0xadfa502b ++0, 266250, 84480, 0x50bf20e4 ++0, 270000, 84480, 0xbcb3d8cc ++0, 273750, 84480, 0xa54677d7 ++0, 277500, 84480, 0x3566042d ++0, 281250, 84480, 0x4c9eed57 ++0, 285000, 84480, 0xc3b90e58 ++0, 288750, 84480, 0x3c042bfa ++0, 292500, 84480, 0x19f8e890 ++0, 296250, 84480, 0xd3dacfb9 ++0, 300000, 84480, 0x2365fc6f ++0, 303750, 84480, 0xa2c19d00 ++0, 307500, 84480, 0xce94336f ++0, 311250, 84480, 0xfa9bcf14 ++0, 315000, 84480, 0x24d6a243 ++0, 318750, 84480, 0xae1c8854 ++0, 322500, 84480, 0xbb8968bf ++0, 326250, 84480, 0x6f923623 ++0, 330000, 84480, 0x22e98029 ++0, 333750, 84480, 0x8ac33af3 ++0, 337500, 84480, 0x05947b6e ++0, 341250, 84480, 0xfc35661a ++0, 345000, 84480, 0x0e6b6e47 ++0, 348750, 84480, 0x82c764bb ++0, 352500, 84480, 0x57a36833 ++0, 356250, 84480, 0xc8dd690a ++0, 360000, 84480, 0x02c47232 ++0, 363750, 84480, 0x6645715d ++0, 367500, 84480, 0xc64860f7 ++0, 371250, 84480, 0x4f5614b3 ++0, 375000, 84480, 0xa70842ca ++0, 378750, 84480, 0x379d8458 ++0, 382500, 84480, 0xa14701cf ++0, 386250, 84480, 0xad1aa2b2 ++0, 390000, 84480, 0xee28f320 ++0, 393750, 84480, 0x505801e9 ++0, 397500, 84480, 0x7947233b ++0, 401250, 84480, 0x3ce72a9d ++0, 405000, 84480, 0xa6834e64 ++0, 408750, 84480, 0xfebf4d70 ++0, 412500, 84480, 0x4a0775e2 ++0, 416250, 84480, 0x9d7e945b ++0, 420000, 84480, 0xaa9eadd9 ++0, 423750, 84480, 0xaa85c9b1 ++0, 427500, 84480, 0xa005edaf ++0, 431250, 84480, 0x7fc4e5cc ++0, 435000, 84480, 0xb0f6e8d1 ++0, 438750, 84480, 0x9ef9f330 ++0, 442500, 84480, 0xbe14ff1f ++0, 446250, 84480, 0xd494048c ++0, 450000, 84480, 0x046166a7 ++0, 453750, 84480, 0x052a09b2 ++0, 457500, 84480, 0x71fff4ab ++0, 461250, 84480, 0xb9684e41 ++0, 465000, 84480, 0x1ddce068 ++0, 468750, 84480, 0xb9de300e ++0, 472500, 84480, 0x13962590 ++0, 476250, 84480, 0xde79482f ++0, 480000, 84480, 0x7d1ca064 ++0, 483750, 84480, 0x0998a064 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-drm-nodec xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-drm-nodec +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-drm-nodec 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-drm-nodec 2012-05-14 14:08:55.737368218 +0200 +@@ -1,5 +1,5 @@ +-1, 0, 1088, 0x5cd379bb + 0, 0, 282, 0x000d949a ++1, 0, 1088, 0x5cd379bb + 1, 39150, 1088, 0x8dfa1368 + 1, 66600, 1088, 0xc0d211be + 1, 92070, 1088, 0x8238113a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-x8intra xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-x8intra +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wmv8-x8intra 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wmv8-x8intra 2012-05-14 14:08:55.738368239 +0200 +@@ -0,0 +1,473 @@ ++0, 0, 115200, 0x03fbd838 ++0, 6000, 115200, 0x8911d86f ++0, 12000, 115200, 0x7c5dd82e ++0, 18000, 115200, 0x7c5ed82e ++0, 24000, 115200, 0xd323d838 ++0, 30000, 115200, 0x6e7479ab ++0, 36000, 115200, 0x14674bf6 ++0, 42000, 115200, 0x074c2e3d ++0, 48000, 115200, 0x9b3025ef ++0, 54000, 115200, 0x76882dae ++0, 60000, 115200, 0xedf3421b ++0, 66000, 115200, 0xb5378486 ++0, 72000, 115200, 0xc4a53420 ++0, 78000, 115200, 0x559cb60f ++0, 84000, 115200, 0xcc034ddd ++0, 90000, 115200, 0xb77b7779 ++0, 96000, 115200, 0x0ad9c3e6 ++0, 102000, 115200, 0x4e673027 ++0, 108000, 115200, 0x54717979 ++0, 114000, 115200, 0xf9e557c9 ++0, 120000, 115200, 0xefad6344 ++0, 126000, 115200, 0x07497ba3 ++0, 132000, 115200, 0xabef71d3 ++0, 138000, 115200, 0x5b8f5802 ++0, 144000, 115200, 0x8b920b76 ++0, 150000, 115200, 0xb93f0f04 ++0, 156000, 115200, 0xa31b18c0 ++0, 162000, 115200, 0x9116235b ++0, 168000, 115200, 0xe54b1d0b ++0, 174000, 115200, 0x35e7252a ++0, 180000, 115200, 0x2cae31d5 ++0, 186000, 115200, 0x28493c57 ++0, 192000, 115200, 0xd8a445b5 ++0, 198000, 115200, 0xbf854c55 ++0, 204000, 115200, 0x3761555c ++0, 210000, 115200, 0x07a35c8a ++0, 216000, 115200, 0x848c6eb0 ++0, 222000, 115200, 0x8d7c77d1 ++0, 228000, 115200, 0x903980b7 ++0, 234000, 115200, 0xbd30898c ++0, 240000, 115200, 0x31f78d25 ++0, 246000, 115200, 0x308aa19d ++0, 252000, 115200, 0xf185948c ++0, 258000, 115200, 0x8aeea0b9 ++0, 264000, 115200, 0x06669545 ++0, 270000, 115200, 0x4d3e84d7 ++0, 276000, 115200, 0x80007e9c ++0, 282000, 115200, 0x7cad6ea5 ++0, 288000, 115200, 0xd5d747f6 ++0, 294000, 115200, 0xeddb43bf ++0, 300000, 115200, 0x2d3c30b5 ++0, 306000, 115200, 0x7b465872 ++0, 312000, 115200, 0xd144b461 ++0, 318000, 115200, 0x36b0053e ++0, 324000, 115200, 0xdf90ec64 ++0, 330000, 115200, 0xb59cecc6 ++0, 336000, 115200, 0x0469ed52 ++0, 342000, 115200, 0x2d7cf7cb ++0, 348000, 115200, 0x8376bf2c ++0, 354000, 115200, 0xd79dbd1e ++0, 360000, 115200, 0xbc79996d ++0, 366000, 115200, 0x524d0a62 ++0, 372000, 115200, 0x07798f44 ++0, 378000, 115200, 0xd8b85d49 ++0, 384000, 115200, 0x54126d07 ++0, 390000, 115200, 0x0346f350 ++0, 396000, 115200, 0x0feada4f ++0, 402000, 115200, 0x74243c65 ++0, 408000, 115200, 0xbce280c8 ++0, 414000, 115200, 0xe9bc40c7 ++0, 420000, 115200, 0x72ecea21 ++0, 426000, 115200, 0xb4c32a43 ++0, 432000, 115200, 0x428a6276 ++0, 438000, 115200, 0xf67f9364 ++0, 444000, 115200, 0xf25e8858 ++0, 450000, 115200, 0x9739b909 ++0, 456000, 115200, 0x8a1b8f38 ++0, 462000, 115200, 0xe4a2cff1 ++0, 468000, 115200, 0xa800b83f ++0, 474000, 115200, 0xa88e00d0 ++0, 480000, 115200, 0x5786082e ++0, 486000, 115200, 0xc7205eeb ++0, 492000, 115200, 0x9ad02d6b ++0, 498000, 115200, 0x5314185d ++0, 504000, 115200, 0x015b6351 ++0, 510000, 115200, 0x51a5c2e1 ++0, 516000, 115200, 0xc232ec26 ++0, 522000, 115200, 0x35b30ffc ++0, 528000, 115200, 0x2b947acd ++0, 534000, 115200, 0xcf1a7971 ++0, 540000, 115200, 0x70055748 ++0, 546000, 115200, 0x774b61e6 ++0, 552000, 115200, 0x74da78a7 ++0, 558000, 115200, 0x13b5523c ++0, 564000, 115200, 0xe27050a0 ++0, 570000, 115200, 0x073156b0 ++0, 576000, 115200, 0x9a3662d4 ++0, 582000, 115200, 0x8c90139c ++0, 588000, 115200, 0x45cdeb08 ++0, 594000, 115200, 0x046ff217 ++0, 600000, 115200, 0xa6b0a863 ++0, 606000, 115200, 0xa9c2427a ++0, 612000, 115200, 0x7d478df1 ++0, 618000, 115200, 0x9f426504 ++0, 624000, 115200, 0x89723d89 ++0, 630000, 115200, 0x851dd023 ++0, 636000, 115200, 0xe6ed007d ++0, 642000, 115200, 0xfe5cb08d ++0, 648000, 115200, 0xc96e52bd ++0, 654000, 115200, 0x15c5ffe8 ++0, 660000, 115200, 0x54540656 ++0, 666000, 115200, 0xa5e8dbec ++0, 672000, 115200, 0x35edde29 ++0, 678000, 115200, 0xbbb6cb36 ++0, 684000, 115200, 0x59c5ed50 ++0, 690000, 115200, 0x7e8a497a ++0, 696000, 115200, 0x16586d33 ++0, 702000, 115200, 0x19dfd6e6 ++0, 708000, 115200, 0x7ea8574a ++0, 714000, 115200, 0x58567b44 ++0, 720000, 115200, 0x0d2d049e ++0, 726000, 115200, 0x7c2d7b00 ++0, 732000, 115200, 0x92debda6 ++0, 738000, 115200, 0x1e4cfcc1 ++0, 744000, 115200, 0xf58b742e ++0, 750000, 115200, 0xc2089e8b ++0, 756000, 115200, 0x1b4f01e8 ++0, 762000, 115200, 0x113b1e76 ++0, 768000, 115200, 0x0f154b48 ++0, 774000, 115200, 0xf82f5795 ++0, 780000, 115200, 0xa9f68f5c ++0, 786000, 115200, 0xd37992fa ++0, 792000, 115200, 0x5e08b0ad ++0, 798000, 115200, 0xacf77f50 ++0, 804000, 115200, 0x4a37945b ++0, 810000, 115200, 0x9d2670b7 ++0, 816000, 115200, 0x7f7e5d76 ++0, 822000, 115200, 0x357d3ec3 ++0, 828000, 115200, 0xe4622287 ++0, 834000, 115200, 0x95260aa6 ++0, 840000, 115200, 0xff87049a ++0, 846000, 115200, 0x5b91c76b ++0, 852000, 115200, 0xe5fca44c ++0, 858000, 115200, 0xccc46ee1 ++0, 864000, 115200, 0x0aec53e8 ++0, 870000, 115200, 0x7509537f ++0, 876000, 115200, 0xd6516a81 ++0, 882000, 115200, 0xbc14562b ++0, 888000, 115200, 0xe3f9619e ++0, 894000, 115200, 0x2cbe35ef ++0, 900000, 115200, 0xd78a40b9 ++0, 906000, 115200, 0x2cfa08cd ++0, 912000, 115200, 0x3ece09fe ++0, 918000, 115200, 0xc445d43a ++0, 924000, 115200, 0xe1cbacdd ++0, 930000, 115200, 0x7a03b421 ++0, 936000, 115200, 0x7c80ab27 ++0, 942000, 115200, 0xececae60 ++0, 948000, 115200, 0xef00c6b3 ++0, 954000, 115200, 0xcdc9e78d ++0, 960000, 115200, 0xa5170dd1 ++0, 966000, 115200, 0xfe561e1f ++0, 972000, 115200, 0xc5d056f9 ++0, 978000, 115200, 0xf0267284 ++0, 984000, 115200, 0xcdc4a09a ++0, 990000, 115200, 0xa8c8af40 ++0, 996000, 115200, 0x0c0cc987 ++0, 1002000, 115200, 0x13a0cc64 ++0, 1008000, 115200, 0x0ff3e6fe ++0, 1014000, 115200, 0x7fbfe852 ++0, 1020000, 115200, 0x62ea0273 ++0, 1026000, 115200, 0x8d021330 ++0, 1032000, 115200, 0x7ac6321a ++0, 1038000, 115200, 0xefc92de8 ++0, 1044000, 115200, 0x4be95c24 ++0, 1050000, 115200, 0xf62c79b0 ++0, 1056000, 115200, 0x1d9f85c6 ++0, 1062000, 115200, 0x13b6ad8f ++0, 1068000, 115200, 0x3d96e451 ++0, 1074000, 115200, 0x0891f3c4 ++0, 1080000, 115200, 0xc728f8cd ++0, 1086000, 115200, 0x9481ee74 ++0, 1092000, 115200, 0xaf95fcf9 ++0, 1098000, 115200, 0x856fe48d ++0, 1104000, 115200, 0x5b9c03da ++0, 1110000, 115200, 0x98f80228 ++0, 1116000, 115200, 0xa4e52148 ++0, 1122000, 115200, 0x65bc4b91 ++0, 1128000, 115200, 0x0c166312 ++0, 1134000, 115200, 0x4657a356 ++0, 1140000, 115200, 0xf17e0003 ++0, 1146000, 115200, 0x95a81738 ++0, 1152000, 115200, 0xb02d6bd9 ++0, 1158000, 115200, 0x2594e89d ++0, 1164000, 115200, 0x5c4a1349 ++0, 1170000, 115200, 0xbc9d5875 ++0, 1176000, 115200, 0xd935b307 ++0, 1182000, 115200, 0x2114cb84 ++0, 1188000, 115200, 0xbe58130c ++0, 1194000, 115200, 0x7a3d2b2b ++0, 1200000, 115200, 0xe5753e6b ++0, 1206000, 115200, 0xc84042cc ++0, 1212000, 115200, 0x98ef4c58 ++0, 1218000, 115200, 0x2cb83bff ++0, 1224000, 115200, 0x4e58433a ++0, 1230000, 115200, 0x7ec26734 ++0, 1236000, 115200, 0x49168d07 ++0, 1242000, 115200, 0xfc9e82f2 ++0, 1248000, 115200, 0x49976c26 ++0, 1254000, 115200, 0xa12466ff ++0, 1260000, 115200, 0x98ae6499 ++0, 1266000, 115200, 0xc8575e78 ++0, 1272000, 115200, 0xc6596cd2 ++0, 1278000, 115200, 0x83d9a068 ++0, 1284000, 115200, 0xe819b560 ++0, 1290000, 115200, 0xb07ac3c3 ++0, 1296000, 115200, 0x3d79ef5b ++0, 1302000, 115200, 0xbc6800e0 ++0, 1308000, 115200, 0xc78c15f8 ++0, 1314000, 115200, 0xcb91360b ++0, 1320000, 115200, 0x6c657143 ++0, 1326000, 115200, 0x636391d1 ++0, 1332000, 115200, 0xb519e49d ++0, 1338000, 115200, 0xb65d00c5 ++0, 1344000, 115200, 0x14672ba8 ++0, 1350000, 115200, 0xb65d389f ++0, 1356000, 115200, 0xe88e991b ++0, 1362000, 115200, 0x6a7bad4e ++0, 1368000, 115200, 0xd305eca1 ++0, 1374000, 115200, 0x8cdbe729 ++0, 1380000, 115200, 0x0d1bfd9a ++0, 1386000, 115200, 0xef740a06 ++0, 1392000, 115200, 0x1cd423df ++0, 1398000, 115200, 0xf78616ba ++0, 1404000, 115200, 0xcc0b2b81 ++0, 1410000, 115200, 0x434e4ae9 ++0, 1416000, 115200, 0xf2d461ec ++0, 1422000, 115200, 0xc75f6a15 ++0, 1428000, 115200, 0x71038c87 ++0, 1434000, 115200, 0x7a55ab55 ++0, 1440000, 115200, 0xeef2e1de ++0, 1446000, 115200, 0xd2600c3d ++0, 1452000, 115200, 0xdd872452 ++0, 1458000, 115200, 0xd1361fcd ++0, 1464000, 115200, 0xda4f0d12 ++0, 1470000, 115200, 0xba061920 ++0, 1476000, 115200, 0x4b2ef9ed ++0, 1482000, 115200, 0x11dfab08 ++0, 1488000, 115200, 0x7a603fc2 ++0, 1494000, 115200, 0x61690ad9 ++0, 1500000, 115200, 0x481ac8b9 ++0, 1506000, 115200, 0xea35570d ++0, 1512000, 115200, 0xdd306f19 ++0, 1518000, 115200, 0x3f975f1b ++0, 1524000, 115200, 0x2386cd1f ++0, 1530000, 115200, 0x1b77f573 ++0, 1536000, 115200, 0x8ce213de ++0, 1542000, 115200, 0x5f7407c6 ++0, 1548000, 115200, 0x01b3ee00 ++0, 1554000, 115200, 0x92759715 ++0, 1560000, 115200, 0x4a208e1e ++0, 1566000, 115200, 0x6e1b80a5 ++0, 1572000, 115200, 0x298c7621 ++0, 1578000, 115200, 0x0e255da8 ++0, 1584000, 115200, 0xabd661ca ++0, 1590000, 115200, 0x6f045226 ++0, 1596000, 115200, 0x396a5e4c ++0, 1602000, 115200, 0x4bd53915 ++0, 1608000, 115200, 0xaf9631b3 ++0, 1614000, 115200, 0xb2602290 ++0, 1620000, 115200, 0xb1272f1b ++0, 1626000, 115200, 0xe8d23699 ++0, 1632000, 115200, 0xd6e2558d ++0, 1638000, 115200, 0xf1270106 ++0, 1644000, 115200, 0x6ab1fc4f ++0, 1650000, 115200, 0x4a9b5c6f ++0, 1656000, 115200, 0x14177b61 ++0, 1662000, 115200, 0x8f7f7971 ++0, 1668000, 115200, 0x165973cd ++0, 1674000, 115200, 0x341c4ba5 ++0, 1680000, 115200, 0x08df3902 ++0, 1686000, 115200, 0x4c1e386a ++0, 1692000, 115200, 0x1b1c387c ++0, 1698000, 115200, 0xe42fdb83 ++0, 1704000, 115200, 0x5bb2ad2e ++0, 1710000, 115200, 0x31924902 ++0, 1716000, 115200, 0x5a290e9a ++0, 1722000, 115200, 0x15d6ea45 ++0, 1728000, 115200, 0xb5adc34d ++0, 1734000, 115200, 0xb210a956 ++0, 1740000, 115200, 0x79478dac ++0, 1746000, 115200, 0x626a3fa9 ++0, 1752000, 115200, 0x6b0e370d ++0, 1758000, 115200, 0x1f1113ec ++0, 1764000, 115200, 0x362efa10 ++0, 1770000, 115200, 0xca8de637 ++0, 1776000, 115200, 0x432e1f19 ++0, 1782000, 115200, 0xa2c93031 ++0, 1788000, 115200, 0x63294fcc ++0, 1794000, 115200, 0x1c1d5928 ++0, 1800000, 115200, 0xe5fb45ea ++0, 1806000, 115200, 0x0712cc77 ++0, 1812000, 115200, 0xaef1c94b ++0, 1818000, 115200, 0x30c8a84e ++0, 1824000, 115200, 0xd6896b75 ++0, 1830000, 115200, 0x7f8839cb ++0, 1836000, 115200, 0xcd69d7d4 ++0, 1842000, 115200, 0xa6f3cdaa ++0, 1848000, 115200, 0xccbdc609 ++0, 1854000, 115200, 0x2d3f77d7 ++0, 1860000, 115200, 0x18f8582d ++0, 1866000, 115200, 0xe88717bb ++0, 1872000, 115200, 0xb42fd44b ++0, 1878000, 115200, 0x7edaa5b7 ++0, 1884000, 115200, 0xef399a7b ++0, 1890000, 115200, 0x11d75f35 ++0, 1896000, 115200, 0xc0717b78 ++0, 1902000, 115200, 0x9aebc04d ++0, 1908000, 115200, 0x44c705fc ++0, 1914000, 115200, 0xd322add3 ++0, 1920000, 115200, 0x0f5f0b79 ++0, 1926000, 115200, 0x54a15070 ++0, 1932000, 115200, 0xd11553df ++0, 1938000, 115200, 0x6f3ed910 ++0, 1944000, 115200, 0x6d3a3c17 ++0, 1950000, 115200, 0x434ebc13 ++0, 1956000, 115200, 0xcf07ecb2 ++0, 1962000, 115200, 0x1c94497e ++0, 1968000, 115200, 0x83c13cbc ++0, 1974000, 115200, 0x4a8ba4f5 ++0, 1980000, 115200, 0x922a393f ++0, 1986000, 115200, 0x44024959 ++0, 1992000, 115200, 0x23f18ebd ++0, 1998000, 115200, 0x2cdf1146 ++0, 2004000, 115200, 0x8a7d402c ++0, 2010000, 115200, 0x42d67bb3 ++0, 2016000, 115200, 0x7045ff2c ++0, 2022000, 115200, 0xb67a4f15 ++0, 2028000, 115200, 0x7481f311 ++0, 2034000, 115200, 0xe394ff8d ++0, 2040000, 115200, 0x2ca16f23 ++0, 2046000, 115200, 0xd53238e1 ++0, 2052000, 115200, 0xe28a80c9 ++0, 2058000, 115200, 0x043ccd51 ++0, 2064000, 115200, 0x2e950d80 ++0, 2070000, 115200, 0xf7394c6e ++0, 2076000, 115200, 0xae46d2c8 ++0, 2082000, 115200, 0x4b54df85 ++0, 2088000, 115200, 0x636f4ca5 ++0, 2094000, 115200, 0x2c687754 ++0, 2100000, 115200, 0x0ddea0f9 ++0, 2106000, 115200, 0x82b08dfd ++0, 2112000, 115200, 0x5db58c25 ++0, 2118000, 115200, 0x9b975eaa ++0, 2124000, 115200, 0x2cbe4bf1 ++0, 2130000, 115200, 0xc8873bd7 ++0, 2136000, 115200, 0x9aa357f2 ++0, 2142000, 115200, 0x526e5392 ++0, 2148000, 115200, 0x30aa5d18 ++0, 2154000, 115200, 0x1fe738b4 ++0, 2160000, 115200, 0x9cec04ad ++0, 2166000, 115200, 0x3ddd922d ++0, 2172000, 115200, 0xc6578bbb ++0, 2178000, 115200, 0x413c35ae ++0, 2184000, 115200, 0x90095ab3 ++0, 2190000, 115200, 0x8ae84371 ++0, 2196000, 115200, 0x1c935404 ++0, 2202000, 115200, 0x213f37e8 ++0, 2208000, 115200, 0x19ab39e6 ++0, 2214000, 115200, 0x795bf82f ++0, 2220000, 115200, 0xe238fccf ++0, 2226000, 115200, 0xe2c0d69e ++0, 2232000, 115200, 0xa1e9d34c ++0, 2238000, 115200, 0xedf3d303 ++0, 2244000, 115200, 0x40fac156 ++0, 2250000, 115200, 0x1bc59ddb ++0, 2256000, 115200, 0x4295a2ab ++0, 2262000, 115200, 0xc337809d ++0, 2268000, 115200, 0x4a329996 ++0, 2274000, 115200, 0xb4fa76b4 ++0, 2280000, 115200, 0xb49b7d18 ++0, 2286000, 115200, 0xfab67262 ++0, 2292000, 115200, 0x31919404 ++0, 2298000, 115200, 0x983d896c ++0, 2304000, 115200, 0x8594939e ++0, 2310000, 115200, 0x9fb8932a ++0, 2316000, 115200, 0xb9f3af07 ++0, 2322000, 115200, 0x5904c5b4 ++0, 2328000, 115200, 0xf6e095d6 ++0, 2334000, 115200, 0xd168bd86 ++0, 2340000, 115200, 0x39151a63 ++0, 2346000, 115200, 0x9e426f6d ++0, 2352000, 115200, 0x0c6d7d1d ++0, 2358000, 115200, 0x65f787ca ++0, 2364000, 115200, 0xf42288c6 ++0, 2370000, 115200, 0x565b8d91 ++0, 2376000, 115200, 0xd72e882f ++0, 2382000, 115200, 0x8def886c ++0, 2388000, 115200, 0x1d5e7800 ++0, 2394000, 115200, 0x628276f7 ++0, 2400000, 115200, 0x00e27d0f ++0, 2406000, 115200, 0x52df7737 ++0, 2412000, 115200, 0xf98f6303 ++0, 2418000, 115200, 0x9a2d2d65 ++0, 2424000, 115200, 0xd8cb25f5 ++0, 2430000, 115200, 0x68071ce1 ++0, 2436000, 115200, 0x4c6218c9 ++0, 2442000, 115200, 0xaf0a11a3 ++0, 2448000, 115200, 0xfa0a0fb9 ++0, 2454000, 115200, 0xc61414fb ++0, 2460000, 115200, 0x3a8b0e94 ++0, 2466000, 115200, 0x1eab0e92 ++0, 2472000, 115200, 0xc726028c ++0, 2478000, 115200, 0x2da2f5de ++0, 2484000, 115200, 0x7672e92f ++0, 2490000, 115200, 0x7edae686 ++0, 2496000, 115200, 0x9a6ce3c6 ++0, 2502000, 115200, 0x9f69e74c ++0, 2508000, 115200, 0x73fbf502 ++0, 2514000, 115200, 0xff81f5b8 ++0, 2520000, 115200, 0x2b8bf7de ++0, 2526000, 115200, 0xcd00f380 ++0, 2532000, 115200, 0x4cedfe7c ++0, 2538000, 115200, 0xcd30fbb4 ++0, 2544000, 115200, 0x4b7df228 ++0, 2550000, 115200, 0xedc7e5df ++0, 2556000, 115200, 0x687ae0f5 ++0, 2562000, 115200, 0x8127e2b9 ++0, 2568000, 115200, 0xe31ae11c ++0, 2574000, 115200, 0xece5e5c5 ++0, 2580000, 115200, 0x4f1bdfe4 ++0, 2586000, 115200, 0x65c5dfe3 ++0, 2592000, 115200, 0xfc89d51f ++0, 2598000, 115200, 0xedd1c6bc ++0, 2604000, 115200, 0x2913d073 ++0, 2610000, 115200, 0xf196fbbe ++0, 2616000, 115200, 0xc0be13e1 ++0, 2622000, 115200, 0x55b21f01 ++0, 2628000, 115200, 0xb16b2364 ++0, 2634000, 115200, 0x4a8632db ++0, 2640000, 115200, 0x44c94426 ++0, 2646000, 115200, 0xe5470b01 ++0, 2652000, 115200, 0xd895d5d0 ++0, 2658000, 115200, 0xe98715c2 ++0, 2664000, 115200, 0x2688599b ++0, 2670000, 115200, 0x8e4889aa ++0, 2676000, 115200, 0x658bcd8d ++0, 2682000, 115200, 0xf0090c06 ++0, 2688000, 115200, 0xefd9bd28 ++0, 2694000, 115200, 0x45009bb4 ++0, 2700000, 115200, 0x7ebd1655 ++0, 2706000, 115200, 0x64ff7898 ++0, 2712000, 115200, 0x4a9384f1 ++0, 2718000, 115200, 0xd80f0701 ++0, 2724000, 115200, 0x2f855116 ++0, 2730000, 115200, 0x0c1313cb ++0, 2736000, 115200, 0xf4df4d19 ++0, 2742000, 115200, 0xde6218fb ++0, 2748000, 115200, 0xce26e6b4 ++0, 2754000, 115200, 0x848af931 ++0, 2760000, 115200, 0x86770a97 ++0, 2766000, 115200, 0x8f35c3c0 ++0, 2772000, 115200, 0xb26dc220 ++0, 2778000, 115200, 0x3d5bbfce ++0, 2784000, 115200, 0xa1f9bee6 ++0, 2790000, 115200, 0xa87dcd24 ++0, 2796000, 115200, 0x9374cb71 ++0, 2802000, 115200, 0x0c7ccbd0 ++0, 2808000, 115200, 0x9a16cc49 ++0, 2814000, 115200, 0x4df0c28b ++0, 2820000, 115200, 0xb5b8b866 ++0, 2826000, 115200, 0xafcc1019 ++0, 2832000, 115200, 0x623b0ff3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wtv-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wtv-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/wtv-demux 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/wtv-demux 2012-05-14 14:08:55.739368259 +0200 +@@ -0,0 +1,139 @@ ++1, 0, 576, 0x9b6e1638 ++1, 1620, 576, 0x0ca91183 ++1, 3780, 576, 0xec6a180f ++1, 5940, 576, 0x478a2b9b ++1, 8100, 576, 0x00fa15b3 ++1, 10260, 576, 0xfb551816 ++1, 12960, 576, 0x422e12bd ++1, 15120, 576, 0xa7581b29 ++1, 17280, 576, 0xd4b31a74 ++1, 19440, 576, 0x11521b10 ++1, 21600, 576, 0x3dcc1474 ++1, 23760, 576, 0x66c31aab ++1, 25920, 576, 0x97f318a8 ++1, 28080, 576, 0xd3fb1a30 ++1, 30240, 576, 0xd2bd16af ++1, 32400, 576, 0x6c10146a ++1, 34560, 576, 0x10d81468 ++1, 36720, 576, 0x3813162d ++1, 38880, 576, 0x89e71d95 ++1, 41040, 576, 0xd1c717f9 ++1, 43200, 576, 0x1a311e5f ++1, 45360, 576, 0x0ea80e05 ++1, 47520, 576, 0x2f1718f2 ++1, 49680, 576, 0xffe01e13 ++1, 51840, 576, 0xa7b02296 ++1, 54000, 576, 0x199f1597 ++1, 56160, 576, 0xdea217ba ++1, 58320, 576, 0x8a790f01 ++1, 60480, 576, 0x23e80038 ++1, 62640, 576, 0x75dc048a ++1, 64800, 576, 0xeb4b0d93 ++1, 66960, 576, 0xde1322f5 ++1, 69120, 576, 0xc3131f35 ++1, 71280, 576, 0x708f1381 ++1, 73440, 576, 0x1f00137e ++0, 74578, 41980, 0xd4920915 ++1, 75600, 576, 0x05131eb0 ++1, 77760, 576, 0x78151c22 ++0, 78178, 7228, 0x1b141fa3 ++1, 79920, 576, 0x31771239 ++0, 81777, 7492, 0x1a47f3e4 ++1, 82080, 576, 0x3ce4097c ++1, 84240, 576, 0x180e15f4 ++0, 85378, 25068, 0xcb70a744 ++1, 86400, 576, 0x30db0604 ++1, 88560, 576, 0x9b290284 ++0, 88978, 7212, 0x0ab9f558 ++1, 90720, 576, 0xcf340753 ++0, 92578, 7612, 0xa93054f0 ++1, 92880, 576, 0xdaa41457 ++1, 95040, 576, 0x34d310a2 ++0, 96177, 22868, 0xa77db64a ++1, 97200, 576, 0x58b31010 ++1, 99360, 576, 0x19610f54 ++0, 99778, 6260, 0x6cf76411 ++1, 101520, 576, 0x17762352 ++0, 103377, 6156, 0xe168394b ++1, 103680, 576, 0x1fea1448 ++1, 105840, 576, 0x55840a01 ++0, 106977, 23364, 0x53164f1e ++1, 108000, 576, 0x6c9c24ce ++1, 110160, 576, 0x955f1e97 ++0, 110578, 6708, 0x89877269 ++1, 112320, 576, 0x2827134f ++0, 114178, 6908, 0x8d62a249 ++1, 114480, 576, 0x34a01c29 ++1, 116640, 576, 0x7d351e52 ++0, 117778, 38156, 0xec41f682 ++1, 118800, 576, 0x00c91d9e ++1, 120960, 576, 0x57ea1a97 ++0, 121377, 5764, 0xcc04534b ++1, 123120, 576, 0xef3a1c74 ++0, 124977, 5388, 0xb8a1c3c5 ++1, 125280, 576, 0x11fc217d ++1, 127440, 576, 0x59ce20e5 ++0, 128578, 16764, 0x59460d96 ++1, 129600, 576, 0xaafc1dbf ++1, 131760, 576, 0xdd941609 ++0, 132177, 5548, 0x5c91e93d ++1, 133920, 576, 0x900420b0 ++0, 135777, 5652, 0x5e321aed ++1, 136080, 576, 0x5f4f1aa1 ++1, 138240, 576, 0x7d7e18de ++0, 139377, 15564, 0xefdf5080 ++1, 140400, 576, 0x986c0d9d ++1, 142560, 576, 0xcb4c21c0 ++0, 142977, 6492, 0xd1d5c5f8 ++1, 144720, 576, 0xbcfb1e8b ++0, 146577, 5604, 0xf9472b44 ++1, 146880, 576, 0xcb541b4c ++1, 149040, 576, 0x980426e9 ++0, 150177, 17924, 0x45815b7b ++1, 151200, 576, 0x09d00aa0 ++1, 153360, 576, 0xad591374 ++0, 153778, 5020, 0x3cc5e554 ++1, 155520, 576, 0x97bf1461 ++0, 157378, 5276, 0xa0554c12 ++1, 157680, 576, 0xdc871cc4 ++1, 159840, 576, 0x56781896 ++0, 160977, 31460, 0x5765eb5f ++1, 162000, 576, 0xc77714e3 ++1, 164160, 576, 0x280e18d4 ++0, 164577, 4972, 0x91adbab7 ++1, 166320, 576, 0xbc0d2302 ++0, 168178, 5580, 0xfea707cb ++1, 168480, 576, 0x79191384 ++1, 170640, 576, 0x65481c97 ++0, 171778, 17412, 0x0afe4d27 ++1, 172800, 576, 0xc94d227d ++1, 174960, 576, 0xa68a1f14 ++0, 175378, 5236, 0x03f55309 ++1, 177120, 576, 0x6af11a5c ++0, 178977, 4924, 0x558e753c ++1, 179280, 576, 0x4d1019ef ++1, 181440, 576, 0x3b1b17b5 ++0, 182577, 15396, 0xf145d121 ++1, 183600, 576, 0xcdd8159f ++1, 185760, 576, 0x97cd1d06 ++0, 186177, 4708, 0x43066a92 ++1, 187920, 576, 0x5d1b1123 ++0, 189778, 4332, 0x9e22bcba ++1, 190080, 576, 0x888d0cb0 ++1, 192240, 576, 0x556e1dad ++0, 193377, 12876, 0x46ff9ef4 ++1, 194400, 576, 0xf7af0bce ++1, 196560, 576, 0xb5da160a ++0, 196978, 5940, 0x27cba62e ++1, 198720, 576, 0x4a8d0e98 ++0, 200578, 6124, 0x6bab0a6d ++1, 200880, 576, 0x183b1c7e ++1, 203040, 576, 0xc47120e6 ++0, 204178, 36428, 0x942f9648 ++1, 205200, 576, 0xb1f31346 ++0, 207777, 6660, 0x545a0db7 ++0, 211377, 6780, 0x2d1d4189 ++0, 214978, 16460, 0x7c3b3ca4 ++0, 218578, 6724, 0x8538cc6f ++0, 222178, 7068, 0x69574fd0 ++0, 225777, 19552, 0xf230e854 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xan-dpcm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xan-dpcm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xan-dpcm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xan-dpcm 1970-01-01 01:00:00.000000000 +0100 +@@ -1 +0,0 @@ +-b6da857766896ab10bb900004f915053 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xmv-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xmv-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xmv-demux 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xmv-demux 2012-05-14 14:08:55.740368279 +0200 +@@ -0,0 +1,181 @@ ++0, 0, 1508, 0xefceba48 ++1, 0, 5976, 0xfa2c2db9 ++1, 10841, 5976, 0x256b935c ++1, 21682, 5976, 0xa78a9563 ++1, 32522, 5976, 0x4ea056f4 ++1, 43363, 5976, 0xda772d8d ++1, 54204, 5976, 0xafacf7c9 ++0, 57600, 108, 0x06713c96 ++0, 61200, 952, 0xd306df7e ++0, 64800, 2312, 0xaf316585 ++1, 65045, 5976, 0xdeb003f4 ++0, 68400, 3872, 0xfc1c527c ++0, 72000, 20, 0xaffc0edd ++0, 75600, 6600, 0xe1b66c7f ++1, 75886, 2016, 0xa7380d36 ++0, 79200, 6868, 0xd5b3f631 ++1, 79543, 2016, 0xbc090bac ++0, 82800, 8420, 0xf70ee33b ++1, 83200, 2016, 0x6f8c164c ++0, 86400, 13144, 0x9a54ef39 ++1, 86857, 2016, 0x13b80e28 ++0, 90000, 6340, 0xe55bf555 ++1, 90514, 2016, 0xd40ff863 ++0, 93600, 3736, 0x0b23f89f ++1, 94171, 2016, 0x4d530ed7 ++0, 97200, 2624, 0x79e2e451 ++1, 97829, 2160, 0x0fbc37eb ++0, 100800, 1860, 0x63886f11 ++1, 101747, 13824, 0x82fb2602 ++0, 104400, 1244, 0x74594601 ++0, 108000, 564, 0xf4561dfb ++0, 111600, 80, 0xbf8e2e30 ++0, 115200, 20, 0xa0990c29 ++1, 126824, 13824, 0x08771caf ++1, 151902, 13824, 0xdf7d4a65 ++1, 176980, 13896, 0x24bf3f47 ++1, 202188, 3600, 0x9ad26b9f ++1, 208718, 3600, 0x8c666fd6 ++1, 215249, 3600, 0x305c6ca1 ++1, 221780, 3600, 0x48b04e1e ++0, 223200, 104, 0x12413980 ++0, 226800, 796, 0x2e698ed3 ++1, 228310, 3600, 0x8c915935 ++0, 230400, 1808, 0x8b3e6e5e ++0, 234000, 4712, 0xdbd51737 ++1, 234841, 3600, 0xa8f45e01 ++0, 237600, 5548, 0xee9c831c ++0, 241200, 6152, 0x9c18ccc1 ++1, 241371, 3816, 0xc64cc5ed ++0, 244800, 6452, 0x7860462a ++1, 248294, 1944, 0x0ac2e3f1 ++0, 248400, 6676, 0xe1b1c9e4 ++1, 251820, 1944, 0x2197dccd ++0, 252000, 10904, 0x0bded7b7 ++1, 255347, 1944, 0x0c02e77f ++0, 255600, 12844, 0xe6d16cff ++1, 258873, 1944, 0x675ee06a ++0, 259200, 10920, 0xe114c46b ++1, 262400, 2160, 0x0d803a8b ++0, 262800, 5952, 0xb7464634 ++1, 266318, 6696, 0xa7a0dfea ++0, 266400, 4732, 0x2fa2e36d ++0, 270000, 2592, 0xf54ddd57 ++0, 273600, 1516, 0x4a1cd4d5 ++0, 277200, 864, 0x49889afc ++1, 278465, 6696, 0x59aa3145 ++0, 280800, 468, 0x3932e6a4 ++0, 284400, 116, 0x2b8341e6 ++0, 288000, 16, 0x6a3109cf ++1, 290612, 6696, 0x69be4d78 ++1, 302759, 6696, 0x64064c67 ++1, 314906, 6696, 0xc8536f98 ++1, 327053, 6696, 0xc0ce5199 ++1, 339200, 6768, 0x3b275c58 ++1, 351478, 8856, 0x90e5b37c ++0, 360000, 1508, 0xefceba48 ++1, 367543, 8856, 0x86b33366 ++1, 383608, 8856, 0x19e18797 ++1, 399673, 8856, 0x0a0c7fbd ++1, 415739, 8928, 0x4a9b2d42 ++0, 417600, 100, 0x45023894 ++0, 421200, 948, 0xa65ed345 ++0, 424800, 2808, 0xd7285746 ++0, 428400, 5372, 0x05794175 ++1, 431935, 1512, 0xed8b3f4b ++0, 432000, 11596, 0x8636eca7 ++1, 434678, 1512, 0xa27d3891 ++0, 435600, 11524, 0xe1f39be3 ++1, 437420, 1512, 0xb0f13eb6 ++0, 439200, 23392, 0xab053f05 ++1, 440163, 1656, 0xe5a98324 ++0, 442800, 4560, 0x03197d07 ++1, 443167, 2232, 0x15445433 ++0, 446400, 4440, 0x1cc361a2 ++1, 447216, 2232, 0x5cb348a9 ++0, 450000, 23688, 0x16030634 ++1, 451265, 2232, 0xf10347da ++0, 453600, 16132, 0xf0eca799 ++1, 455314, 2448, 0x3e16a175 ++0, 457200, 29896, 0x0c0988ea ++1, 459755, 2520, 0x17e3ca2b ++0, 460800, 19956, 0x0093aa0b ++1, 464327, 1944, 0x35c2de84 ++0, 464400, 16392, 0x8829a9ca ++1, 467853, 1944, 0x55b4db40 ++0, 468000, 16772, 0x9a4a546d ++1, 471380, 2088, 0xdaae14b2 ++0, 471600, 8920, 0xcd8ca203 ++1, 475167, 1944, 0x92ccd37f ++0, 475200, 9632, 0x53c1d37b ++1, 478694, 1944, 0x70efede1 ++0, 478800, 8976, 0xfe4da2cc ++1, 482220, 1944, 0x7601d304 ++0, 482400, 6680, 0x35348fe0 ++1, 485747, 1944, 0x3922ebc2 ++0, 486000, 9228, 0xcbf62b0c ++1, 489273, 2160, 0xde462f2e ++0, 489600, 5108, 0xd1d88511 ++1, 493192, 1872, 0x467ac1d2 ++0, 493200, 10016, 0xaff4b2b2 ++1, 496588, 1872, 0xa1e4cd43 ++0, 496800, 7468, 0x23e81ab8 ++1, 499984, 1872, 0x1dceccc6 ++0, 500400, 4172, 0x253cd05b ++1, 503380, 1872, 0x2bbad2a5 ++0, 504000, 8188, 0x7ede743f ++1, 506776, 1872, 0xc603d44d ++0, 507600, 2884, 0x2dec55a3 ++1, 510171, 1872, 0x1b4cc261 ++0, 511200, 3900, 0xd0666a18 ++1, 513567, 1872, 0x10edd6cf ++0, 514800, 2996, 0x9cc99b8c ++1, 516963, 2376, 0xecdb9d61 ++0, 518400, 2156, 0xae612776 ++1, 521273, 2592, 0x5559eced ++0, 522000, 3988, 0x0d2c9992 ++0, 525600, 1512, 0x6281fc00 ++1, 525976, 2592, 0x8848dfc7 ++0, 529200, 6544, 0xb75c2562 ++1, 530678, 2592, 0x4ca2d7da ++0, 532800, 4108, 0xfb21efc9 ++1, 535380, 2592, 0x285fd7e6 ++0, 536400, 1096, 0x85922a37 ++0, 540000, 9740, 0xe57d7647 ++1, 540082, 2592, 0x2717e404 ++0, 543600, 416, 0x61c2ea02 ++1, 544784, 2592, 0xf106111a ++0, 547200, 336, 0x1dc5ac1c ++1, 549486, 2592, 0xd7d01119 ++0, 550800, 204, 0x16f57017 ++1, 554188, 2592, 0x550cfeda ++0, 554400, 112, 0x78374234 ++0, 558000, 40, 0x6cb21985 ++1, 558890, 2592, 0x47ad00c4 ++1, 563592, 2592, 0x39bbf306 ++1, 568294, 3240, 0x69addfce ++1, 574171, 21384, 0x254f63e0 ++1, 612963, 21456, 0x2f7a9859 ++0, 615600, 14420, 0x53324ca4 ++0, 619200, 40, 0x10971420 ++1, 651886, 37512, 0x6e962928 ++1, 719935, 2736, 0x1dc91c69 ++0, 720000, 24904, 0x15574f7e ++1, 724898, 2736, 0x023434fd ++1, 729861, 2736, 0x906f1541 ++0, 734400, 1908, 0xccb2dd3c ++1, 734824, 2736, 0x85a31102 ++0, 738000, 4676, 0xbfa42b7e ++1, 739788, 3024, 0x9296a5f3 ++0, 741600, 3600, 0x87c9dc58 ++0, 745200, 8184, 0x504a8e65 ++1, 745273, 1944, 0x7bf4dedc ++0, 748800, 9636, 0x2efb3006 ++1, 748800, 1944, 0x4196c404 ++1, 752327, 1944, 0xcda97c7a ++0, 752400, 9580, 0x0fb6f4e8 ++1, 755853, 1944, 0x5f4922b2 ++0, 756000, 7840, 0xe996f564 ++1, 759380, 2088, 0x37dfc157 ++0, 759600, 4208, 0xe9c2fba2 ++0, 763200, 556, 0x3f1e077c +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xwma-demux xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xwma-demux +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xwma-demux 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xwma-demux 2012-05-14 14:08:55.741368299 +0200 +@@ -0,0 +1 @@ ++CRC=0x2ac2159e +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xxan-wc4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xxan-wc4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/xxan-wc4 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/xxan-wc4 2012-05-14 14:08:55.741368299 +0200 +@@ -0,0 +1,21 @@ ++0, 0, 79360, 0x3b0a7d1b ++0, 6000, 79360, 0x740842c3 ++0, 12000, 79360, 0x85160167 ++0, 18000, 79360, 0xaf510e92 ++0, 24000, 79360, 0x8e290bec ++0, 30000, 79360, 0x51e981b0 ++0, 36000, 79360, 0x16e52c60 ++0, 42000, 79360, 0x66e1e60a ++0, 48000, 79360, 0x40fa58f6 ++0, 54000, 79360, 0x00388edd ++0, 60000, 79360, 0xc74f95bf ++0, 66000, 79360, 0xf446a3fd ++0, 72000, 79360, 0x27b5eb60 ++0, 78000, 79360, 0xea9266a2 ++0, 84000, 79360, 0x7b6a7907 ++0, 90000, 79360, 0x2be7d946 ++0, 96000, 79360, 0x61881ee4 ++0, 102000, 79360, 0x9214bd4f ++0, 108000, 79360, 0xeb294afe ++0, 114000, 79360, 0xc861ad55 ++0, 120000, 79360, 0x3d3b6220 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/yop xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/yop +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/yop 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/yop 2012-05-14 14:08:55.742368319 +0200 +@@ -1,7 +1,7 @@ +-0, 0, 302760, 0x78939253 +-0, 7500, 302760, 0x534f5253 +-0, 15000, 302760, 0xe991aa82 +-0, 22500, 302760, 0xc34b20bd +-0, 30000, 302760, 0x461d29a1 +-0, 37500, 302760, 0x45abca02 +-0, 45000, 302760, 0xb05448b9 ++0, 0, 302760, 0xf24dfa37 ++0, 7500, 302760, 0xcedcbb6c ++0, 15000, 302760, 0x8c2d19a2 ++0, 22500, 302760, 0xe0fc92da ++0, 30000, 302760, 0xd7699bb4 ++0, 37500, 302760, 0x26e93266 ++0, 45000, 302760, 0x4cddb216 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/zmbv-8bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/zmbv-8bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/fate/zmbv-8bit 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/fate/zmbv-8bit 2012-05-14 14:08:55.742368319 +0200 +@@ -273,3 +273,4 @@ + 0, 349284, 192000, 0xd08e49d1 + 0, 350568, 192000, 0xd08e49d1 + 0, 351852, 192000, 0xd08e49d1 ++0, 353136, 192000, 0x1f34135f +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/asf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/asf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/asf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/asf 2012-05-14 14:08:55.743368339 +0200 +@@ -1,3 +1,3 @@ +-c544bb40c2f4c09d44318db5228ee499 *./tests/data/lavf/lavf.asf +-333375 ./tests/data/lavf/lavf.asf ++3d410176ebf9ffdf99d2738922cef260 *./tests/data/lavf/lavf.asf ++333489 ./tests/data/lavf/lavf.asf + ./tests/data/lavf/lavf.asf CRC=0x9f5ab3e6 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/avi xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/avi +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/avi 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/avi 2012-05-14 14:08:55.744368359 +0200 +@@ -1,3 +1,3 @@ +-7e5e4db8c04f0acd16cff6b30e60d0e5 *./tests/data/lavf/lavf.avi +-331032 ./tests/data/lavf/lavf.avi ++a326b284ab0b34727323bf58585c9d29 *./tests/data/lavf/lavf.avi ++331050 ./tests/data/lavf/lavf.avi + ./tests/data/lavf/lavf.avi CRC=0x2a83e6b0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/caf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/caf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/caf 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/caf 2012-05-14 14:08:55.744368359 +0200 +@@ -0,0 +1,3 @@ ++df9ebf2812784a653d3337cf12c0c687 *./tests/data/lavf/lavf.caf ++90180 ./tests/data/lavf/lavf.caf ++./tests/data/lavf/lavf.caf CRC=0xf1ae5536 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/dpx xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/dpx +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/dpx 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/dpx 2012-05-14 14:08:55.744368359 +0200 +@@ -0,0 +1,3 @@ ++808ea110635774252439722a48329d61 *./tests/data/images/dpx/02.dpx ++./tests/data/images/dpx/%02d.dpx CRC=0x6da01946 ++305792 ./tests/data/images/dpx/02.dpx +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/dv_fmt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/dv_fmt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/dv_fmt 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/dv_fmt 2012-05-14 14:08:55.745368379 +0200 +@@ -1,3 +1,3 @@ +-522e5e5a46b99f8ad8aabdaf3d2f1869 *./tests/data/lavf/lavf.dv ++3a6a9163a67b729b4a6b5d972ccceb97 *./tests/data/lavf/lavf.dv + 3600000 ./tests/data/lavf/lavf.dv +-./tests/data/lavf/lavf.dv CRC=0x02c0af30 ++./tests/data/lavf/lavf.dv CRC=0x5ce4e5e4 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ffm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ffm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ffm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ffm 2012-05-14 14:08:55.745368379 +0200 +@@ -1,3 +1,3 @@ +-b6acf782a38d313153b68c4ca204fc90 *./tests/data/lavf/lavf.ffm ++58a0235967d10543268184eea50a3b65 *./tests/data/lavf/lavf.ffm + 376832 ./tests/data/lavf/lavf.ffm + ./tests/data/lavf/lavf.ffm CRC=0xf361ed74 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/flv_fmt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/flv_fmt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/flv_fmt 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/flv_fmt 2012-05-14 14:08:55.746368400 +0200 +@@ -1,3 +1,3 @@ +-62c3177547fb5853a5116661802e1ae2 *./tests/data/lavf/lavf.flv +-329541 ./tests/data/lavf/lavf.flv ++c8321cd5ae19a8853eea4a011656ff74 *./tests/data/lavf/lavf.flv ++329559 ./tests/data/lavf/lavf.flv + ./tests/data/lavf/lavf.flv CRC=0x881785d1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/gif xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/gif +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/gif 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/gif 2012-05-14 14:08:55.747368420 +0200 +@@ -1,3 +1,3 @@ +-98968ceb210ab260a6a7af36767b94d3 *./tests/data/lavf/lavf.gif +-2906382 ./tests/data/lavf/lavf.gif ++e6089fd4ef3b9df44090ab3650bdd810 *./tests/data/lavf/lavf.gif ++2906401 ./tests/data/lavf/lavf.gif + ./tests/data/lavf/lavf.gif CRC=0xe5605ff6 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/gxf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/gxf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/gxf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/gxf 2012-05-14 14:08:55.747368420 +0200 +@@ -1,3 +1,3 @@ +-346d38d330ab5cb0caa6b5537167bc0d *./tests/data/lavf/lavf.gxf ++1c1693cf2358025f1e37ac76e1da925a *./tests/data/lavf/lavf.gxf + 796392 ./tests/data/lavf/lavf.gxf +-./tests/data/lavf/lavf.gxf CRC=0xad9e86eb ++./tests/data/lavf/lavf.gxf CRC=0x102918fd +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mkv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mkv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mkv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mkv 2012-05-14 14:08:55.748368440 +0200 +@@ -1,3 +1,3 @@ +-a36c2d9378b9870880556ced1cb89ecf *./tests/data/lavf/lavf.mkv +- 320478 ./tests/data/lavf/lavf.mkv ++f99ae18e1212ee184188243107a4b824 *./tests/data/lavf/lavf.mkv ++320521 ./tests/data/lavf/lavf.mkv + ./tests/data/lavf/lavf.mkv CRC=0x2a83e6b0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mov xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mov +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mov 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mov 2012-05-14 14:08:55.748368440 +0200 +@@ -1,3 +1,3 @@ +-c145305a775eb2de43cdf94eb1ab5240 *./tests/data/lavf/lavf.mov +-357669 ./tests/data/lavf/lavf.mov ++9a0b239ff596da58debcf210dece3985 *./tests/data/lavf/lavf.mov ++357821 ./tests/data/lavf/lavf.mov + ./tests/data/lavf/lavf.mov CRC=0x2f6a9b26 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mpg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mpg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mpg 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mpg 2012-05-14 14:08:55.749368460 +0200 +@@ -1,3 +1,3 @@ + dd60652c2193670abffb8c2a123a820e *./tests/data/lavf/lavf.mpg + 372736 ./tests/data/lavf/lavf.mpg +-./tests/data/lavf/lavf.mpg CRC=0x2b39ed74 ++./tests/data/lavf/lavf.mpg CRC=0xf361ed74 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mxf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mxf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mxf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mxf 2012-05-14 14:08:55.749368460 +0200 +@@ -1,6 +1,3 @@ + 785e38ddd2466046f30aa36399b8f8fa *./tests/data/lavf/lavf.mxf + 525881 ./tests/data/lavf/lavf.mxf +-./tests/data/lavf/lavf.mxf CRC=0xb6aa0849 +-b3174e2db508564c1cce0b5e3c1bc1bd *./tests/data/lavf/lavf.mxf_d10 +-5330989 ./tests/data/lavf/lavf.mxf_d10 +-./tests/data/lavf/lavf.mxf_d10 CRC=0xc3f4f92e ++./tests/data/lavf/lavf.mxf CRC=0x4ace0849 +\ Kein Zeilenumbruch am Dateiende. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mxf_d10 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mxf_d10 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/mxf_d10 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/mxf_d10 2012-05-14 14:08:55.750368480 +0200 +@@ -0,0 +1,3 @@ ++23177c8a72f34e243e9ffc4f6c70d3c7 *./tests/data/lavf/lavf.mxf_d10 ++5330989 ./tests/data/lavf/lavf.mxf_d10 ++./tests/data/lavf/lavf.mxf_d10 CRC=0x81602ff1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/nut xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/nut +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/nut 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/nut 2012-05-14 14:08:55.750368480 +0200 +@@ -1,3 +1,3 @@ +-16b9d2cf8effb7dae316c6b9248a49b7 *./tests/data/lavf/lavf.nut +-319888 ./tests/data/lavf/lavf.nut ++bf59c686c1bb739434109dadc04eeec6 *./tests/data/lavf/lavf.nut ++319904 ./tests/data/lavf/lavf.nut + ./tests/data/lavf/lavf.nut CRC=0x2a83e6b0 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ogg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ogg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ogg 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ogg 2012-05-14 14:08:55.751368500 +0200 +@@ -1,3 +1,3 @@ +-364714f1087f3c1320b60f4209191d23 *./tests/data/lavf/lavf.ogg +-13820 ./tests/data/lavf/lavf.ogg ++010f31817f41bb99899ffcc5c3943938 *./tests/data/lavf/lavf.ogg ++13838 ./tests/data/lavf/lavf.ogg + ./tests/data/lavf/lavf.ogg CRC=0xf1ae5536 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/pixfmt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/pixfmt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/pixfmt 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/pixfmt 2012-05-14 14:08:55.751368500 +0200 +@@ -10,27 +10,27 @@ + 304128 ./tests/data/pixfmt/yuv410p.yuv + 8594ea0b8d7c2c964525b0801b5351de *./tests/data/pixfmt/yuv411p.yuv + 304128 ./tests/data/pixfmt/yuv411p.yuv +-66673539adf8cda28e3b76068d3aae61 *./tests/data/pixfmt/yuvj420p.yuv ++e176bd14185788110e055f945de7f95f *./tests/data/pixfmt/yuvj420p.yuv + 304128 ./tests/data/pixfmt/yuvj420p.yuv +-572bf387dd1e3f073cbfd082e055ca81 *./tests/data/pixfmt/yuvj422p.yuv ++472028e46a81c98d9b2477507def4723 *./tests/data/pixfmt/yuvj422p.yuv + 304128 ./tests/data/pixfmt/yuvj422p.yuv + c10442da177c9f1d12be3c53be6fa12c *./tests/data/pixfmt/yuvj444p.yuv + 304128 ./tests/data/pixfmt/yuvj444p.yuv +-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/rgb24.yuv ++6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/rgb24.yuv + 304128 ./tests/data/pixfmt/rgb24.yuv +-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/bgr24.yuv ++6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/bgr24.yuv + 304128 ./tests/data/pixfmt/bgr24.yuv +-c6e0f9b5817f484b175c1ec4ffb4e9c9 *./tests/data/pixfmt/rgb32.yuv ++6bb61113e7b70eb09dbcec356122a0e2 *./tests/data/pixfmt/rgb32.yuv + 304128 ./tests/data/pixfmt/rgb32.yuv +-66d39d464bd89ded2a124897f0a75ade *./tests/data/pixfmt/rgb565.yuv ++efa7c0337cc00c796c6df615223716f1 *./tests/data/pixfmt/rgb565.yuv + 304128 ./tests/data/pixfmt/rgb565.yuv +-c894c3bd8d2631ed1964500b90a0c350 *./tests/data/pixfmt/rgb555.yuv ++0df2a477af1415a1b8fbf2a3e552bc39 *./tests/data/pixfmt/rgb555.yuv + 304128 ./tests/data/pixfmt/rgb555.yuv + 6be306b0cce5f8e6c271ea17fef9745b *./tests/data/pixfmt/gray.yuv + 304128 ./tests/data/pixfmt/gray.yuv +-31398104d2349dd48328a6862bc6711f *./tests/data/pixfmt/monow.yuv ++6c719671e39f1bcf67b47eab98fa529b *./tests/data/pixfmt/monow.yuv + 304128 ./tests/data/pixfmt/monow.yuv +-31398104d2349dd48328a6862bc6711f *./tests/data/pixfmt/monob.yuv ++6c719671e39f1bcf67b47eab98fa529b *./tests/data/pixfmt/monob.yuv + 304128 ./tests/data/pixfmt/monob.yuv + 00b85790df5740bab95e2559d81603a7 *./tests/data/pixfmt/yuv440p.yuv + 304128 ./tests/data/pixfmt/yuv440p.yuv +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/png xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/png +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/png 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/png 2012-05-14 14:08:55.752368520 +0200 +@@ -1,3 +1,9 @@ + c162094e51dc1a3203de43e496086dfd *./tests/data/images/png/02.png + ./tests/data/images/png/%02d.png CRC=0x6da01946 + 248612 ./tests/data/images/png/02.png ++63805114b3723490833789277246276f *./tests/data/images/png/02.png ++./tests/data/images/png/%02d.png CRC=0x831a2963 ++41666 ./tests/data/images/png/02.png ++b4c1f0b706a296ba6e791d436757dc5f *./tests/data/images/png/02.png ++./tests/data/images/png/%02d.png CRC=0x5984c023 ++511879 ./tests/data/images/png/02.png +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/rm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/rm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/rm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/rm 2012-05-14 14:08:55.752368520 +0200 +@@ -1,2 +1,2 @@ +-b97899ef2812cd1c8851dea550e042e4 *./tests/data/lavf/lavf.rm +-346706 ./tests/data/lavf/lavf.rm ++2b0eebb5814825c9c4b385cbf8e5b0da *./tests/data/lavf/lavf.rm ++346714 ./tests/data/lavf/lavf.rm +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/rso xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/rso +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/rso 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/rso 2012-05-14 14:08:55.753368540 +0200 +@@ -0,0 +1,3 @@ ++f41fd78f7df981802e7caeb23648b8c0 *./tests/data/lavf/lavf.rso ++45064 ./tests/data/lavf/lavf.rso ++./tests/data/lavf/lavf.rso CRC=0x74b2b546 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/sox xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/sox +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/sox 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/sox 2012-05-14 14:08:55.753368540 +0200 +@@ -0,0 +1,3 @@ ++e6f278256f145b69ed06f35b8d3585c1 *./tests/data/lavf/lavf.sox ++180256 ./tests/data/lavf/lavf.sox ++./tests/data/lavf/lavf.sox CRC=0xf1ae5536 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ts xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ts +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/ts 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/ts 2012-05-14 14:08:55.754368561 +0200 +@@ -1,3 +1,3 @@ +-e8d609b8a5b5854a4485718434b287f7 *./tests/data/lavf/lavf.ts ++8f61dad7652abbab9e49fca274dabf30 *./tests/data/lavf/lavf.ts + 406644 ./tests/data/lavf/lavf.ts + ./tests/data/lavf/lavf.ts CRC=0x133216c1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/wav 2012-05-14 14:08:55.754368561 +0200 +@@ -1,3 +1,3 @@ +-6a3bec31d92baf52161e25179ebba315 *./tests/data/lavf/lavf.wav +-90156 ./tests/data/lavf/lavf.wav ++8854ea97f2d2172383941b001c69228b *./tests/data/lavf/lavf.wav ++90158 ./tests/data/lavf/lavf.wav + ./tests/data/lavf/lavf.wav CRC=0xf1ae5536 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/wtv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/wtv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavf/wtv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavf/wtv 2012-05-14 14:08:55.755368581 +0200 +@@ -0,0 +1,3 @@ ++7bd312f32538a14f248c2dff85394118 *./tests/data/lavf/lavf.wtv ++413696 ./tests/data/lavf/lavf.wtv ++./tests/data/lavf/lavf.wtv CRC=0xebced481 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc 2012-05-14 14:08:55.756368601 +0200 +@@ -0,0 +1,68 @@ ++0bgr 8fb023c3c8f8e64254e807543b29ad61 ++0rgb 0570cd4801a1c613a9815e98872246d4 ++abgr 037bf9df6a765520ad6d490066bf4b89 ++argb c442a8261c2265a07212ef0f72e35f5a ++bgr0 0ef8ffe42bfe53be74973a0c118b775e ++bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b ++bgr444be d9ea9307d21b162225b8b2c524cf9477 ++bgr444le 88035350e9da3a8f67387890b956f0bc ++bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8 ++bgr48le d02c235ebba7167881ca2d576497ff84 ++bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 ++bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280 ++bgr555le 378d6ac4223651a1adcbf94a3d0d807b ++bgr565be 257cf78afa35dc31e9696f139c916715 ++bgr565le 1dfdd03995c287e3c754b164bf26a355 ++bgr8 24bd566170343d06fec6fccfff5abc54 ++bgra 76a18a5151242fa137133f604cd624d2 ++gray db08f7f0751900347e6b8649e4164d21 ++gray16be b44458c2254aa7a3d7b8dbf53be91979 ++gray16le ecda5143f8a55fca1f6c7dfb238ddcba ++monob 668ebe8b8103b9046b251b2fa8a1d88f ++monow 9251497f3b0634f1165d12d5a289d943 ++nv12 e0af357888584d36eec5aa0f673793ef ++nv21 9a3297f3b34baa038b1f37cb202b512f ++rgb0 7c03f81f5e5346bf8ea42c4187f20605 ++rgb24 b41eba9651e1b5fe386289b506188105 ++rgb444be 9e89db334568c6b2e3d5d0540f4ba960 ++rgb444le 0a68cb6de8bf530aa30c5c1205c25155 ++rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2 ++rgb48le 86c5608904f75360d492dbc5c9589969 ++rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 ++rgb555be 912a62c5e53bfcbac2a0340e10973cf2 ++rgb555le a937a0fc764fb57dc1b3af87cba0273c ++rgb565be 9cadf742e05ddc23a3b5b270f89aad3c ++rgb565le d39aa298bb525e9be8860351c6f62dab ++rgb8 4a9d8e4f2f154e83a7e1735be6300700 ++rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 ++uyvy422 adcf64516a19fce44df77082bdb16291 ++yuv410p 2d9225153c83ee1132397d619d94d1b3 ++yuv411p 8b298af3e43348ca1b11eb8a3252ac6c ++yuv420p eba2f135a08829387e2f698ff72a2939 ++yuv420p10be 2f88c301feeaccd2a5fb55f54fc30be9 ++yuv420p10le 93f175084af4e78f97c7710e505f3057 ++yuv420p16be ba858ff4246368c28f03152487f57ef3 ++yuv420p16le de239729a4fe1d4cfa3743e006654e78 ++yuv420p9be 64e36fd90573f67ac2006d103972a79b ++yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80 ++yuv422p c9bba4529821d796a6ab09f6a5fd355a ++yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a ++yuv422p10le ec04efb76efa79bf0d02b21572371a56 ++yuv422p16be 5499502e1c29534a158a1fe60e889f60 ++yuv422p16le e3d61fde6978591596bc36b914386623 ++yuv422p9be 29b71579946940a8c00fa844c9dff507 ++yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a ++yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf ++yuv444p 0a98447b78fd476aa39686da6a74fa2e ++yuv444p10be 71be185a2fb7a353eb024df9bc63212d ++yuv444p10le c1c6b30a12065c7901c0a267e4861a0f ++yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 ++yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 ++yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 ++yuv444p9le f0606604a5c08becab6ba500124c4b7c ++yuva420p a29884f3f3dfe1e00b961bc17bef3d47 ++yuvj420p 32eec78ba51857b16ce9b813a49b7189 ++yuvj422p 0dfa0ed434f73be51428758c69e082cb ++yuvj440p 657501a28004e27a592757a7509f5189 ++yuvj444p 98d3d054f2ec09a75eeed5d328dc75b7 ++yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc_be xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc_be +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc_be 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc_be 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr 037bf9df6a765520ad6d490066bf4b89 +-argb c442a8261c2265a07212ef0f72e35f5a +-bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b +-bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 +-bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280 +-bgr565be 257cf78afa35dc31e9696f139c916715 +-bgr8 24bd566170343d06fec6fccfff5abc54 +-bgra 76a18a5151242fa137133f604cd624d2 +-gray db08f7f0751900347e6b8649e4164d21 +-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2 +-gray16le 10bd87059b5c189f3caef2837f4f2b5c +-monob 668ebe8b8103b9046b251b2fa8a1d88f +-monow 9251497f3b0634f1165d12d5a289d943 +-nv12 e0af357888584d36eec5aa0f673793ef +-nv21 9a3297f3b34baa038b1f37cb202b512f +-rgb24 b41eba9651e1b5fe386289b506188105 +-rgb48be 460b6de89b156290a12d3941db8bd731 +-rgb48le cd93cb34d15996987367dabda3a10128 +-rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 +-rgb555be 912a62c5e53bfcbac2a0340e10973cf2 +-rgb565be 9cadf742e05ddc23a3b5b270f89aad3c +-rgb8 4a9d8e4f2f154e83a7e1735be6300700 +-rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 +-uyvy422 adcf64516a19fce44df77082bdb16291 +-yuv410p 2d9225153c83ee1132397d619d94d1b3 +-yuv411p 8b298af3e43348ca1b11eb8a3252ac6c +-yuv420p eba2f135a08829387e2f698ff72a2939 +-yuv420p16be 16c009a235cd52b74791a895423152a3 +-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc +-yuv422p c9bba4529821d796a6ab09f6a5fd355a +-yuv422p16be 5499502e1c29534a158a1fe60e889f60 +-yuv422p16le e3d61fde6978591596bc36b914386623 +-yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf +-yuv444p 0a98447b78fd476aa39686da6a74fa2e +-yuv444p16be ea602a24b8e6969679265078bd8607b6 +-yuv444p16le 1262a0dc57ee147967fc896d04206313 +-yuva420p a29884f3f3dfe1e00b961bc17bef3d47 +-yuvj420p 32eec78ba51857b16ce9b813a49b7189 +-yuvj422p 0dfa0ed434f73be51428758c69e082cb +-yuvj440p 9c3a093ff64a83ac4cf0b1e65390e236 +-yuvj444p ede1e5882d5c5bba48ea33cf1209d231 +-yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixdesc_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixdesc_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr 037bf9df6a765520ad6d490066bf4b89 +-argb c442a8261c2265a07212ef0f72e35f5a +-bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b +-bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 +-bgr555le 378d6ac4223651a1adcbf94a3d0d807b +-bgr565le 1dfdd03995c287e3c754b164bf26a355 +-bgr8 24bd566170343d06fec6fccfff5abc54 +-bgra 76a18a5151242fa137133f604cd624d2 +-gray db08f7f0751900347e6b8649e4164d21 +-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2 +-gray16le 10bd87059b5c189f3caef2837f4f2b5c +-monob 668ebe8b8103b9046b251b2fa8a1d88f +-monow 9251497f3b0634f1165d12d5a289d943 +-nv12 e0af357888584d36eec5aa0f673793ef +-nv21 9a3297f3b34baa038b1f37cb202b512f +-rgb24 b41eba9651e1b5fe386289b506188105 +-rgb48be 460b6de89b156290a12d3941db8bd731 +-rgb48le cd93cb34d15996987367dabda3a10128 +-rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 +-rgb555le a937a0fc764fb57dc1b3af87cba0273c +-rgb565le d39aa298bb525e9be8860351c6f62dab +-rgb8 4a9d8e4f2f154e83a7e1735be6300700 +-rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 +-uyvy422 adcf64516a19fce44df77082bdb16291 +-yuv410p 2d9225153c83ee1132397d619d94d1b3 +-yuv411p 8b298af3e43348ca1b11eb8a3252ac6c +-yuv420p eba2f135a08829387e2f698ff72a2939 +-yuv420p16be 16c009a235cd52b74791a895423152a3 +-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc +-yuv422p c9bba4529821d796a6ab09f6a5fd355a +-yuv422p16be 5499502e1c29534a158a1fe60e889f60 +-yuv422p16le e3d61fde6978591596bc36b914386623 +-yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf +-yuv444p 0a98447b78fd476aa39686da6a74fa2e +-yuv444p16be ea602a24b8e6969679265078bd8607b6 +-yuv444p16le 1262a0dc57ee147967fc896d04206313 +-yuva420p a29884f3f3dfe1e00b961bc17bef3d47 +-yuvj420p 32eec78ba51857b16ce9b813a49b7189 +-yuvj422p 0dfa0ed434f73be51428758c69e082cb +-yuvj440p 9c3a093ff64a83ac4cf0b1e65390e236 +-yuvj444p ede1e5882d5c5bba48ea33cf1209d231 +-yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy 2012-05-14 14:08:55.757368621 +0200 +@@ -0,0 +1,69 @@ ++0bgr 73847fb78ab01d040bc65307aa2e772d ++0rgb 68262dbda747e9552cf04a06632a7cee ++abgr 037bf9df6a765520ad6d490066bf4b89 ++argb c442a8261c2265a07212ef0f72e35f5a ++bgr0 328a76e72c55508cdf04dc93a5b056fc ++bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b ++bgr444be d9ea9307d21b162225b8b2c524cf9477 ++bgr444le 88035350e9da3a8f67387890b956f0bc ++bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8 ++bgr48le d02c235ebba7167881ca2d576497ff84 ++bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 ++bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280 ++bgr555le 378d6ac4223651a1adcbf94a3d0d807b ++bgr565be 257cf78afa35dc31e9696f139c916715 ++bgr565le 1dfdd03995c287e3c754b164bf26a355 ++bgr8 24bd566170343d06fec6fccfff5abc54 ++bgra 76a18a5151242fa137133f604cd624d2 ++gray db08f7f0751900347e6b8649e4164d21 ++gray16be b44458c2254aa7a3d7b8dbf53be91979 ++gray16le ecda5143f8a55fca1f6c7dfb238ddcba ++monob 668ebe8b8103b9046b251b2fa8a1d88f ++monow 9251497f3b0634f1165d12d5a289d943 ++nv12 e0af357888584d36eec5aa0f673793ef ++nv21 9a3297f3b34baa038b1f37cb202b512f ++pal8 dec8ed2258ec89b8a796f21cad4df867 ++rgb0 ff1a9f355d43f9d25f07a191b5aa906c ++rgb24 b41eba9651e1b5fe386289b506188105 ++rgb444be 9e89db334568c6b2e3d5d0540f4ba960 ++rgb444le 0a68cb6de8bf530aa30c5c1205c25155 ++rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2 ++rgb48le 86c5608904f75360d492dbc5c9589969 ++rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 ++rgb555be 912a62c5e53bfcbac2a0340e10973cf2 ++rgb555le a937a0fc764fb57dc1b3af87cba0273c ++rgb565be 9cadf742e05ddc23a3b5b270f89aad3c ++rgb565le d39aa298bb525e9be8860351c6f62dab ++rgb8 4a9d8e4f2f154e83a7e1735be6300700 ++rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 ++uyvy422 adcf64516a19fce44df77082bdb16291 ++yuv410p 2d9225153c83ee1132397d619d94d1b3 ++yuv411p 8b298af3e43348ca1b11eb8a3252ac6c ++yuv420p eba2f135a08829387e2f698ff72a2939 ++yuv420p10be 2f88c301feeaccd2a5fb55f54fc30be9 ++yuv420p10le 93f175084af4e78f97c7710e505f3057 ++yuv420p16be ba858ff4246368c28f03152487f57ef3 ++yuv420p16le de239729a4fe1d4cfa3743e006654e78 ++yuv420p9be 64e36fd90573f67ac2006d103972a79b ++yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80 ++yuv422p c9bba4529821d796a6ab09f6a5fd355a ++yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a ++yuv422p10le ec04efb76efa79bf0d02b21572371a56 ++yuv422p16be 5499502e1c29534a158a1fe60e889f60 ++yuv422p16le e3d61fde6978591596bc36b914386623 ++yuv422p9be 29b71579946940a8c00fa844c9dff507 ++yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a ++yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf ++yuv444p 0a98447b78fd476aa39686da6a74fa2e ++yuv444p10be 71be185a2fb7a353eb024df9bc63212d ++yuv444p10le c1c6b30a12065c7901c0a267e4861a0f ++yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 ++yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 ++yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 ++yuv444p9le f0606604a5c08becab6ba500124c4b7c ++yuva420p a29884f3f3dfe1e00b961bc17bef3d47 ++yuvj420p 32eec78ba51857b16ce9b813a49b7189 ++yuvj422p 0dfa0ed434f73be51428758c69e082cb ++yuvj440p 657501a28004e27a592757a7509f5189 ++yuvj444p 98d3d054f2ec09a75eeed5d328dc75b7 ++yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_copy_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr 037bf9df6a765520ad6d490066bf4b89 +-argb c442a8261c2265a07212ef0f72e35f5a +-bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b +-bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 +-bgr555le 378d6ac4223651a1adcbf94a3d0d807b +-bgr565le 1dfdd03995c287e3c754b164bf26a355 +-bgr8 24bd566170343d06fec6fccfff5abc54 +-bgra 76a18a5151242fa137133f604cd624d2 +-gray db08f7f0751900347e6b8649e4164d21 +-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2 +-gray16le 10bd87059b5c189f3caef2837f4f2b5c +-monob 668ebe8b8103b9046b251b2fa8a1d88f +-monow 9251497f3b0634f1165d12d5a289d943 +-nv12 e0af357888584d36eec5aa0f673793ef +-nv21 9a3297f3b34baa038b1f37cb202b512f +-rgb24 b41eba9651e1b5fe386289b506188105 +-rgb48be 460b6de89b156290a12d3941db8bd731 +-rgb48le cd93cb34d15996987367dabda3a10128 +-rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 +-rgb555le a937a0fc764fb57dc1b3af87cba0273c +-rgb565le d39aa298bb525e9be8860351c6f62dab +-rgb8 4a9d8e4f2f154e83a7e1735be6300700 +-rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 +-uyvy422 adcf64516a19fce44df77082bdb16291 +-yuv410p 2d9225153c83ee1132397d619d94d1b3 +-yuv411p 8b298af3e43348ca1b11eb8a3252ac6c +-yuv420p eba2f135a08829387e2f698ff72a2939 +-yuv420p16be 16c009a235cd52b74791a895423152a3 +-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc +-yuv422p c9bba4529821d796a6ab09f6a5fd355a +-yuv422p16be 5499502e1c29534a158a1fe60e889f60 +-yuv422p16le e3d61fde6978591596bc36b914386623 +-yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf +-yuv444p 0a98447b78fd476aa39686da6a74fa2e +-yuv444p16be ea602a24b8e6969679265078bd8607b6 +-yuv444p16le 1262a0dc57ee147967fc896d04206313 +-yuva420p a29884f3f3dfe1e00b961bc17bef3d47 +-yuvj420p 32eec78ba51857b16ce9b813a49b7189 +-yuvj422p 0dfa0ed434f73be51428758c69e082cb +-yuvj440p 9c3a093ff64a83ac4cf0b1e65390e236 +-yuvj444p ede1e5882d5c5bba48ea33cf1209d231 +-yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop 2012-05-14 14:08:55.758368641 +0200 +@@ -0,0 +1,43 @@ ++abgr cd761690872843d1b7ab0c695393c751 ++argb 2ec6ef18769bcd651c2e8904d5a3ee67 ++bgr24 3450fd00cf1493d1ded75544d82ba3ec ++bgr48be 18ca4002732f278cc9f525215c2fca41 ++bgr48le 395a4c187c4e95217d089bd3df9f3654 ++bgr4_byte 2f6ac3cdd4676ab4e2982bdf0664945b ++bgr555be d3a7c273604723adeb7e5f5dd1c4272b ++bgr555le d22442fc13b464f9ba455b08df4e981f ++bgr565be fadceef4a64ad6873fcb43ddee0deb3c ++bgr565le 891664e5a54ae5968901347da92bc5e9 ++bgr8 4b7159e05765bd4703180072d86423c8 ++bgra 395c9f706fccda721471acaa5c96c16c ++gray 8c4850e66562a587a292dc728a65ea4a ++gray16be 257b4339925b0e672f552d8c9511f2c3 ++gray16le 67cf7b26cda55356cc25e0f4e42cc136 ++pal8 d6c1b598244f41e2f005e42407d234d2 ++rgb24 3b90ed64b687d3dc186c6ef521dc71a8 ++rgb48be e6fd353c0eb9bea889423954414bea35 ++rgb48le 68a1723da11ce08b502d42e204376503 ++rgb4_byte 6958029f73c6cdfed4f71020d816f027 ++rgb555be 41a7d1836837bc90f2cae19a9c9df3b3 ++rgb555le eeb78f8ce6186fba55c941469e60ba67 ++rgb565be b2d1cb525f3a0cfe27753c0d479b2fa9 ++rgb565le 6a49700680be9a0d434411825a769556 ++rgb8 88b0398c265d1ed7a837dc084fa0917c ++rgba fd00b24c7597268c32759a84a1de2de4 ++yuv410p a9f2eaa747bf988b7bebe4f442b9c67a ++yuv411p 3334d3aef8dba238658090ac172375d1 ++yuv420p bfea0188ddd4889787c403caae119cc7 ++yuv420p16be eb2f96b638a174377f5fc42cfc849ff5 ++yuv420p16le 3eae4c172d620b6d4ef2aeca403c4f54 ++yuv422p f2f930a91fe00d4252c4720b5ecd8961 ++yuv422p16be 167e4338811a7d272925a4c6417d60da ++yuv422p16le 3359395d5875d581fa1e975013d30114 ++yuv440p 2472417d980e395ad6843cbb8b633b29 ++yuv444p 1f151980486848c96bc5585ced99003e ++yuv444p16be 1ce8fcd4712d525af983e6179d6a4f9e ++yuv444p16le 5f1441e18345aadb3f881dac99c6c08a ++yuva420p 7536753dfbc7932560fb50c921369a0e ++yuvj420p 21f891093006d42d7683b0e1d773a657 ++yuvj422p 9a43d474c407590ad8f213880586b45e ++yuvj440p 977351350450ebdbf7a9d20020c6b5a5 ++yuvj444p 4a50ba26859dad91dcf7000de0d0efa1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_crop_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-abgr cd761690872843d1b7ab0c695393c751 +-argb 2ec6ef18769bcd651c2e8904d5a3ee67 +-bgr24 3450fd00cf1493d1ded75544d82ba3ec +-bgr4_byte 2f6ac3cdd4676ab4e2982bdf0664945b +-bgr555le d22442fc13b464f9ba455b08df4e981f +-bgr565le 891664e5a54ae5968901347da92bc5e9 +-bgr8 4b7159e05765bd4703180072d86423c8 +-bgra 395c9f706fccda721471acaa5c96c16c +-gray 8c4850e66562a587a292dc728a65ea4a +-gray16be daa5a6b98fb4a280c57c57bff1a2ab5a +-gray16le 84f5ea7259073edcb893113b42213c8e +-rgb24 3b90ed64b687d3dc186c6ef521dc71a8 +-rgb48be a808128041a1962deaa8620c7448feba +-rgb48le ce92d02cc322608d5be377cb1940677b +-rgb4_byte 6958029f73c6cdfed4f71020d816f027 +-rgb555le eeb78f8ce6186fba55c941469e60ba67 +-rgb565le 6a49700680be9a0d434411825a769556 +-rgb8 88b0398c265d1ed7a837dc084fa0917c +-rgba fd00b24c7597268c32759a84a1de2de4 +-yuv410p a9f2eaa747bf988b7bebe4f442b9c67a +-yuv411p 3334d3aef8dba238658090ac172375d1 +-yuv420p bfea0188ddd4889787c403caae119cc7 +-yuv420p16be 8365eff38b8c329aeb95fc605fa229bb +-yuv420p16le 5e8dd38d973d5854abe1ad4efad20cc1 +-yuv422p f2f930a91fe00d4252c4720b5ecd8961 +-yuv422p16be 167e4338811a7d272925a4c6417d60da +-yuv422p16le 3359395d5875d581fa1e975013d30114 +-yuv440p 2472417d980e395ad6843cbb8b633b29 +-yuv444p 1f151980486848c96bc5585ced99003e +-yuv444p16be d69280c2856865d2ea94bd5292aac1c6 +-yuv444p16le 33f43e030bedf9723be4f63c3e9fc80e +-yuva420p 7536753dfbc7932560fb50c921369a0e +-yuvj420p 21f891093006d42d7683b0e1d773a657 +-yuvj422p 9a43d474c407590ad8f213880586b45e +-yuvj440p 977351350450ebdbf7a9d20020c6b5a5 +-yuvj444p 4a50ba26859dad91dcf7000de0d0efa1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip 2012-05-14 14:08:55.759368661 +0200 +@@ -0,0 +1,43 @@ ++abgr 49468c6c9ceee5d52b08b1270a909323 ++argb 50ba9f16c6475530602f2983278b82d0 ++bgr24 cc53d2011d097972db0d22756c3699e3 ++bgr48be 815192d3757c66de97b0d51818acbe0f ++bgr48le 8e4184ac6eae251b4bace51dba7d790c ++bgr4_byte aac987e7d1a6a96477cfc0b48a4285de ++bgr555be bc07265898440116772200390d70c092 ++bgr555le ccee08679bac84a1f960c6c9070c5538 ++bgr565be e088789ce46224b87c6e46610ef19add ++bgr565le 3703466e19e1b52e03a34fd244a8e8e4 ++bgr8 50b505a889f0428242305acb642da107 ++bgra 01ca21e7e6a8d1281b4553bde8e8a404 ++gray 03efcb4ab52a24c0af0e03cfd26c9377 ++gray16be 632535b46edec78a6534ef18d37f2b71 ++gray16le 5c24e6f847bf9a41a40760c0d15df161 ++pal8 6c1545bb295e9289add1760851a3d9c9 ++rgb24 754f1722fc738590cc407ac65749bfe8 ++rgb48be d690412ca5fada031b5da47b87096248 ++rgb48le c901feb564232f5d0bc0eabd66dae3e7 ++rgb4_byte c8a3f995fcf3e0919239ea2c413ddc29 ++rgb555be 045ce8607d3910586f4d97481dda8632 ++rgb555le 8778ee0cf58ce9ad1d99a1eca9f95e87 ++rgb565be c8022a1b2470e72f124e4389fad4c372 ++rgb565le 2cb690eb3fcb72da3771ad6a48931158 ++rgb8 9e462b811b9b6173397b9cfc1f6b2f17 ++rgba d3d0dc1ecef3ed72f26a2986d0efc204 ++yuv410p acb543ebbbf63eefe533e6faffc006da ++yuv411p c626cf6d191139b4ca7efc0155f957f1 ++yuv420p 2d5c80f9ba2ddd85b2aeda3564cc7d64 ++yuv420p16be 1c4fa93d0744de3cdc6d34ab55db3fb4 ++yuv420p16le 92c74f5759068c381e4a066fe7faf2e0 ++yuv422p 6e728f4eb9eae287c224f396d84be6ea ++yuv422p16be a05d43cd62b790087bd37083174557de ++yuv422p16le 6954abebcbc62d81068d58d0c62bdd5b ++yuv440p a99e2b57ed601f39852715c9d675d0d3 ++yuv444p 947e47f7bb5fdccc659d19b7df2b6fc3 ++yuv444p16be 58c012e5ab73b066ef3c2b6411a395f1 ++yuv444p16le 32c12794e184042a59738ab2de608c8d ++yuva420p d83ec0c01498189f179ec574918185f1 ++yuvj420p df3aaaec3bb157c3bde5f0365af30f4f ++yuvj422p d113871528d510a192797af59df9c05c ++yuvj440p 07f5ff12ced85aba1b5cf51692fff4bb ++yuvj444p 8d95f6b4d4c9b4b0389d36df686bfa46 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_hflip_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,36 +0,0 @@ +-abgr 49468c6c9ceee5d52b08b1270a909323 +-argb 50ba9f16c6475530602f2983278b82d0 +-bgr24 cc53d2011d097972db0d22756c3699e3 +-bgr4_byte aac987e7d1a6a96477cfc0b48a4285de +-bgr555le ccee08679bac84a1f960c6c9070c5538 +-bgr565le 3703466e19e1b52e03a34fd244a8e8e4 +-bgr8 50b505a889f0428242305acb642da107 +-bgra 01ca21e7e6a8d1281b4553bde8e8a404 +-gray 03efcb4ab52a24c0af0e03cfd26c9377 +-gray16be 9bcbca979601ddc4869f846f08f3d1dd +-gray16le c1b8965adcc7f847ee343149ff507073 +-rgb24 754f1722fc738590cc407ac65749bfe8 +-rgb48be 10743e1577dc3198dbbc7c0b3b8f429e +-rgb48le dd945a44f39119221407bf7a04f1bc49 +-rgb4_byte c8a3f995fcf3e0919239ea2c413ddc29 +-rgb555le 8778ee0cf58ce9ad1d99a1eca9f95e87 +-rgb565le 2cb690eb3fcb72da3771ad6a48931158 +-rgb8 9e462b811b9b6173397b9cfc1f6b2f17 +-rgba d3d0dc1ecef3ed72f26a2986d0efc204 +-yuv410p acb543ebbbf63eefe533e6faffc006da +-yuv411p c626cf6d191139b4ca7efc0155f957f1 +-yuv420p 2d5c80f9ba2ddd85b2aeda3564cc7d64 +-yuv420p16be 758b0c1e2113b15e7afde48da4e4d024 +-yuv420p16le 480ccd951dcb806bc875d307e02e50a0 +-yuv422p 6e728f4eb9eae287c224f396d84be6ea +-yuv422p16be a05d43cd62b790087bd37083174557de +-yuv422p16le 6954abebcbc62d81068d58d0c62bdd5b +-yuv440p a99e2b57ed601f39852715c9d675d0d3 +-yuv444p 947e47f7bb5fdccc659d19b7df2b6fc3 +-yuv444p16be e5ef45bc3d2f5b0b2542d5151340c382 +-yuv444p16le 70793e3d66d0c23a0cdedabe9c24c2a7 +-yuva420p d83ec0c01498189f179ec574918185f1 +-yuvj420p df3aaaec3bb157c3bde5f0365af30f4f +-yuvj422p d113871528d510a192797af59df9c05c +-yuvj440p e8f7ed76e57c892a1e9e27a3f29452db +-yuvj444p 2c3ae369607608c6dcb0d830f00f971a +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_null xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_null +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_null 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_null 2012-05-14 14:08:55.760368681 +0200 +@@ -0,0 +1,69 @@ ++0bgr 73847fb78ab01d040bc65307aa2e772d ++0rgb 68262dbda747e9552cf04a06632a7cee ++abgr 037bf9df6a765520ad6d490066bf4b89 ++argb c442a8261c2265a07212ef0f72e35f5a ++bgr0 328a76e72c55508cdf04dc93a5b056fc ++bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b ++bgr444be d9ea9307d21b162225b8b2c524cf9477 ++bgr444le 88035350e9da3a8f67387890b956f0bc ++bgr48be 00624e6c7ec7ab19897ba2f0a3257fe8 ++bgr48le d02c235ebba7167881ca2d576497ff84 ++bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 ++bgr555be 49f01b1f1f0c84fd9e776dd34cc3c280 ++bgr555le 378d6ac4223651a1adcbf94a3d0d807b ++bgr565be 257cf78afa35dc31e9696f139c916715 ++bgr565le 1dfdd03995c287e3c754b164bf26a355 ++bgr8 24bd566170343d06fec6fccfff5abc54 ++bgra 76a18a5151242fa137133f604cd624d2 ++gray db08f7f0751900347e6b8649e4164d21 ++gray16be b44458c2254aa7a3d7b8dbf53be91979 ++gray16le ecda5143f8a55fca1f6c7dfb238ddcba ++monob 668ebe8b8103b9046b251b2fa8a1d88f ++monow 9251497f3b0634f1165d12d5a289d943 ++nv12 e0af357888584d36eec5aa0f673793ef ++nv21 9a3297f3b34baa038b1f37cb202b512f ++pal8 dec8ed2258ec89b8a796f21cad4df867 ++rgb0 ff1a9f355d43f9d25f07a191b5aa906c ++rgb24 b41eba9651e1b5fe386289b506188105 ++rgb444be 9e89db334568c6b2e3d5d0540f4ba960 ++rgb444le 0a68cb6de8bf530aa30c5c1205c25155 ++rgb48be cc139ec1dd9451f0e049c0cb3a0c8aa2 ++rgb48le 86c5608904f75360d492dbc5c9589969 ++rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 ++rgb555be 912a62c5e53bfcbac2a0340e10973cf2 ++rgb555le a937a0fc764fb57dc1b3af87cba0273c ++rgb565be 9cadf742e05ddc23a3b5b270f89aad3c ++rgb565le d39aa298bb525e9be8860351c6f62dab ++rgb8 4a9d8e4f2f154e83a7e1735be6300700 ++rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 ++uyvy422 adcf64516a19fce44df77082bdb16291 ++yuv410p 2d9225153c83ee1132397d619d94d1b3 ++yuv411p 8b298af3e43348ca1b11eb8a3252ac6c ++yuv420p eba2f135a08829387e2f698ff72a2939 ++yuv420p10be 2f88c301feeaccd2a5fb55f54fc30be9 ++yuv420p10le 93f175084af4e78f97c7710e505f3057 ++yuv420p16be ba858ff4246368c28f03152487f57ef3 ++yuv420p16le de239729a4fe1d4cfa3743e006654e78 ++yuv420p9be 64e36fd90573f67ac2006d103972a79b ++yuv420p9le 9ed4b1dfabc53fd9e586ff6c4c43af80 ++yuv422p c9bba4529821d796a6ab09f6a5fd355a ++yuv422p10be 11af7dfafe8bc025c7e3bd82b830fe8a ++yuv422p10le ec04efb76efa79bf0d02b21572371a56 ++yuv422p16be 5499502e1c29534a158a1fe60e889f60 ++yuv422p16le e3d61fde6978591596bc36b914386623 ++yuv422p9be 29b71579946940a8c00fa844c9dff507 ++yuv422p9le 062b7f9cbb972bf36b5bdb1a7623701a ++yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf ++yuv444p 0a98447b78fd476aa39686da6a74fa2e ++yuv444p10be 71be185a2fb7a353eb024df9bc63212d ++yuv444p10le c1c6b30a12065c7901c0a267e4861a0f ++yuv444p16be 1c6ea2c2f5e539006112ceec3d4e7d90 ++yuv444p16le 20f86bc2f68d2b3f1f2b48b97b2189f4 ++yuv444p9be 6ab31f4c12b533ce318ecdff83cdd054 ++yuv444p9le f0606604a5c08becab6ba500124c4b7c ++yuva420p a29884f3f3dfe1e00b961bc17bef3d47 ++yuvj420p 32eec78ba51857b16ce9b813a49b7189 ++yuvj422p 0dfa0ed434f73be51428758c69e082cb ++yuvj440p 657501a28004e27a592757a7509f5189 ++yuvj444p 98d3d054f2ec09a75eeed5d328dc75b7 ++yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_null_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_null_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_null_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_null_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr 037bf9df6a765520ad6d490066bf4b89 +-argb c442a8261c2265a07212ef0f72e35f5a +-bgr24 0d0cb38ab3fa0b2ec0865c14f78b217b +-bgr4_byte 50d23cc82d9dcef2fd12adb81fb9b806 +-bgr555le 378d6ac4223651a1adcbf94a3d0d807b +-bgr565le 1dfdd03995c287e3c754b164bf26a355 +-bgr8 24bd566170343d06fec6fccfff5abc54 +-bgra 76a18a5151242fa137133f604cd624d2 +-gray db08f7f0751900347e6b8649e4164d21 +-gray16be 7becf34ae825a3df3969bf4c6bfeb5e2 +-gray16le 10bd87059b5c189f3caef2837f4f2b5c +-monob 668ebe8b8103b9046b251b2fa8a1d88f +-monow 9251497f3b0634f1165d12d5a289d943 +-nv12 e0af357888584d36eec5aa0f673793ef +-nv21 9a3297f3b34baa038b1f37cb202b512f +-rgb24 b41eba9651e1b5fe386289b506188105 +-rgb48be 460b6de89b156290a12d3941db8bd731 +-rgb48le cd93cb34d15996987367dabda3a10128 +-rgb4_byte c93ba89b74c504e7f5ae9d9ab1546c73 +-rgb555le a937a0fc764fb57dc1b3af87cba0273c +-rgb565le d39aa298bb525e9be8860351c6f62dab +-rgb8 4a9d8e4f2f154e83a7e1735be6300700 +-rgba 93a5b3712e6eb8c5b9a09ffc7b9fbc12 +-uyvy422 adcf64516a19fce44df77082bdb16291 +-yuv410p 2d9225153c83ee1132397d619d94d1b3 +-yuv411p 8b298af3e43348ca1b11eb8a3252ac6c +-yuv420p eba2f135a08829387e2f698ff72a2939 +-yuv420p16be 16c009a235cd52b74791a895423152a3 +-yuv420p16le 2d59c4f1d0314a5a957a7cfc4b6fabcc +-yuv422p c9bba4529821d796a6ab09f6a5fd355a +-yuv422p16be 5499502e1c29534a158a1fe60e889f60 +-yuv422p16le e3d61fde6978591596bc36b914386623 +-yuv440p 5a064afe2b453bb52cdb3f176b1aa1cf +-yuv444p 0a98447b78fd476aa39686da6a74fa2e +-yuv444p16be ea602a24b8e6969679265078bd8607b6 +-yuv444p16le 1262a0dc57ee147967fc896d04206313 +-yuva420p a29884f3f3dfe1e00b961bc17bef3d47 +-yuvj420p 32eec78ba51857b16ce9b813a49b7189 +-yuvj422p 0dfa0ed434f73be51428758c69e082cb +-yuvj440p 9c3a093ff64a83ac4cf0b1e65390e236 +-yuvj444p ede1e5882d5c5bba48ea33cf1209d231 +-yuyv422 f2569f2b5069a0ee0cecae33de0455e3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad 2012-05-14 14:08:55.761368701 +0200 +@@ -0,0 +1,17 @@ ++abgr e8e5e350c856c051d502cd435a2aa0bd ++argb a98e0a1213824ee4566d4891468bb614 ++bgr24 ac7417cea8d6e799a31a3c9a39b8f202 ++bgra 6113a09a023cb2b08e9cad78eb1eb37a ++rgb24 65eed443acc66c4f02bab6df4ebed515 ++rgba 74d4158ad0c626e9a7c6923b9ca73294 ++yuv410p a5210eb6a9b10c3269899b935df9a2d6 ++yuv411p a23380c9698e2d80c9fa8a8b6d4f6854 ++yuv420p f8733600369adaea28aa445dbdf2ed4c ++yuv422p 3e0d822c11c716e7636387b1bf27c5ff ++yuv440p 225dd7fbc8cceb24c26b765187d43a9e ++yuv444p 45484f0411d336ce94636da0395f4692 ++yuva420p 919722724765dc3a716c38fa53b20580 ++yuvj420p 4f20e2799966c21a9d9e0788b0956925 ++yuvj422p e4d84b0683f77a76f1c17d976eff127c ++yuvj440p 33511c43339aa32533ab832861c150c3 ++yuvj444p 82f0badd9d0c062bbfa0d9d73d7240a3 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_pad_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,17 +0,0 @@ +-abgr e8e5e350c856c051d502cd435a2aa0bd +-argb a98e0a1213824ee4566d4891468bb614 +-bgr24 ac7417cea8d6e799a31a3c9a39b8f202 +-bgra 6113a09a023cb2b08e9cad78eb1eb37a +-rgb24 65eed443acc66c4f02bab6df4ebed515 +-rgba 74d4158ad0c626e9a7c6923b9ca73294 +-yuv410p a5210eb6a9b10c3269899b935df9a2d6 +-yuv411p a23380c9698e2d80c9fa8a8b6d4f6854 +-yuv420p f8733600369adaea28aa445dbdf2ed4c +-yuv422p 3e0d822c11c716e7636387b1bf27c5ff +-yuv440p 225dd7fbc8cceb24c26b765187d43a9e +-yuv444p 45484f0411d336ce94636da0395f4692 +-yuva420p 919722724765dc3a716c38fa53b20580 +-yuvj420p 4f20e2799966c21a9d9e0788b0956925 +-yuvj422p e4d84b0683f77a76f1c17d976eff127c +-yuvj440p 9ccc1f03d8d9a00dc4a5888bd77093ad +-yuvj444p 7d202babcedf836e9ae9776163ee9425 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale 2012-05-14 14:08:55.762368722 +0200 +@@ -0,0 +1,69 @@ ++0bgr 1c9ce2c650cc9afc669e3a9a15842c9d ++0rgb 87749d52eb3056848cccea5875622a86 ++abgr cff82561a074874027ac1cc896fd2730 ++argb 756dd1eaa5baca2238ce23dbdc452684 ++bgr0 ff6e1dfa26d4c2ada3a59e8b0b600d1f ++bgr24 e44192347a45586c6c157e3059610cd1 ++bgr444be c23768338d76693f0da76e8a9b6fd8df ++bgr444le 846c431a47bfb745437941bde768469c ++bgr48be 390d3058a12a99c2b153ed7922508bea ++bgr48le 39fe06feb4ec1d9730dccc04a0cfac4c ++bgr4_byte ee1d35a7baf8e9016891929a2f565c0b ++bgr555be 6a2d335856db12e3ea72173d71610e21 ++bgr555le 41e3e0961478dc634bf68a7bbd670cc9 ++bgr565be 21077a3744c889b97032414b11232933 ++bgr565le 614897eaeb422bd9a972f8ee51909be5 ++bgr8 7f007fa6c153a16e808a9c51605a4016 ++bgra 01cfdda1f72fcabb6c46424e27f8c519 ++gray d7786a7d9d99ac74230cc045cab5632c ++gray16be a8fc0d7fea36407b5c319e3e736c7127 ++gray16le 495c89186178308ef171d385bbd8bd70 ++monob cb62f31b701c6e987b574974d1b31e32 ++monow fd5d417ab7728acddffc06870661df61 ++nv12 4676d59db43d657dc12841f6bc3ab452 ++nv21 69c699510ff1fb777b118ebee1002f14 ++pal8 6324fa058e1bc157ed7132bfe4022317 ++rgb0 1bd6f54ad067503ac9783a70062c8f87 ++rgb24 13ff53ebeab74dc05492836f1cfbd2c1 ++rgb444be 46e466b2709f62b2fffc63708063eaaf ++rgb444le f0c57a48be671428e2e53c9b54a6c4e2 ++rgb48be 8fac63787a711886030f8e056872b488 ++rgb48le ab92f2763a2eb264c3870cc758f97149 ++rgb4_byte d81ffd3add95842a618eec81024f0b5c ++rgb555be 491dc49ff83258ffe415289bdcfb50b2 ++rgb555le bd698d86c03170c4a16607c0fd1f750f ++rgb565be 35682c17c85f307147041f23ac8092aa ++rgb565le bfa0c639d80c3c03fd0c9e5f34296a5e ++rgb8 091d0170b354ef0e97312b95feb5483f ++rgba 16873e3ac914e76116629a5ff8940ac4 ++uyvy422 314bd486277111a95d9369b944fa0400 ++yuv410p 7df8f6d69b56a8dcb6c7ee908e5018b5 ++yuv411p 1143e7c5cc28fe0922b051b17733bc4c ++yuv420p fdad2d8df8985e3d17e73c71f713cb14 ++yuv420p10be 418039dbd82cf612db88417276aa0d1a ++yuv420p10le ff7e5321208ab995b4f95634ebdf192b ++yuv420p16be 31988e9a5d6acacaa710f67bc1172f3a ++yuv420p16le f5390ce399f88e0e4e2621ed7833b250 ++yuv420p9be ec4983b7a949c0472110a7a2c58e278a ++yuv420p9le c136dce5913a722eee44ab72cff664b2 ++yuv422p 918e37701ee7377d16a8a6c119c56a40 ++yuv422p10be 315654908d50718e175aae018c484732 ++yuv422p10le 91bbc78a9a56f659b55abc17722dcc09 ++yuv422p16be e7e34fe9264784763ab6cb406524c0f3 ++yuv422p16le c435b76b08204dda6908640fb5fd4621 ++yuv422p9be 82494823944912f73cebc58ad2979bbd ++yuv422p9le fc69c8a21f473916a4b4225636b97e06 ++yuv440p 461503fdb9b90451020aa3b25ddf041c ++yuv444p 81b2eba962d12e8d64f003ac56f6faf2 ++yuv444p10be fb304d77c6d2e18df5938662a22176f0 ++yuv444p10le b17136913eb066dca6be6af645b9f7e8 ++yuv444p16be 0da9bed80f5542682ab286f3261cf24c ++yuv444p16le a0c5d3c7bf3f181db503cf8e450d1335 ++yuv444p9be 9ac2643ce7f7e5c4e17c8c9fd8494d4a ++yuv444p9le 896a1cc9cccca1ba410dd53942d33cc4 ++yuva420p 8673a9131fb47de69788863f93a50eb7 ++yuvj420p 30427bd6caf5bda93a173dbebe759e09 ++yuvj422p fc8288f64fd149573f73cf8da05d8e6d ++yuvj440p 508ac7a9ddeb6d1794a1100ba7a1664c ++yuvj444p 73aebe144085b22d1189caf6ca07e18c ++yuyv422 169e19ac91b257bd84ace0fdf56559ad +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_scale_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr d894cb97f6c80eb21bdbe8a4eea62d86 +-argb 54346f2b2eef10919e0f247241df3b24 +-bgr24 570f8d6b51a838aed022ef67535f6bdc +-bgr4_byte ee1d35a7baf8e9016891929a2f565c0b +-bgr555le 36b745067197f9ca8c1731cac51329c9 +-bgr565le 3a514a298c6161a071ddf9963c06509d +-bgr8 7f007fa6c153a16e808a9c51605a4016 +-bgra a5e7040f9a80cccd65e5acf2ca09ace5 +-gray d7786a7d9d99ac74230cc045cab5632c +-gray16be af39ce3a497f6734b157c8b94544f537 +-gray16le 7ac1b788bcc472010df7a97e762485e0 +-monob 88c4c050758e64d120f50c7eff694381 +-monow d31772ebaa877fc2a78565937f7f9673 +-nv12 4676d59db43d657dc12841f6bc3ab452 +-nv21 69c699510ff1fb777b118ebee1002f14 +-rgb24 514692e28e8ff6860e415ce4fcf6eb8c +-rgb48be 1894cd30dabcd3180518e4d5f09f25e7 +-rgb48le 1354e6e27ce3c1d4d4989ee56030c94b +-rgb4_byte d81ffd3add95842a618eec81024f0b5c +-rgb555le a350ef1dc2c9688ed49e7ba018843795 +-rgb565le 6f4bb711238baa762d73305213f8d035 +-rgb8 091d0170b354ef0e97312b95feb5483f +-rgba a3d362f222098a00e63867f612018659 +-uyvy422 314bd486277111a95d9369b944fa0400 +-yuv410p 7df8f6d69b56a8dcb6c7ee908e5018b5 +-yuv411p 1143e7c5cc28fe0922b051b17733bc4c +-yuv420p fdad2d8df8985e3d17e73c71f713cb14 +-yuv420p16be 29a0265764530070f5cd3251cc01f66a +-yuv420p16le 6f3a265b084a78baec229238d9f7945f +-yuv422p 918e37701ee7377d16a8a6c119c56a40 +-yuv422p16be ef3e865fc1d0c68977c735323c50af6e +-yuv422p16le 428a9b96214c09cb5a983ce36d6961ff +-yuv440p 461503fdb9b90451020aa3b25ddf041c +-yuv444p 81b2eba962d12e8d64f003ac56f6faf2 +-yuv444p16be 99a3738c70c8fbdc5a0e4ad4bf50648d +-yuv444p16le 385d0cc5240d62da0871915be5d86f0a +-yuva420p 8673a9131fb47de69788863f93a50eb7 +-yuvj420p 30427bd6caf5bda93a173dbebe759e09 +-yuvj422p fc8288f64fd149573f73cf8da05d8e6d +-yuvj440p 26d0b4713a87ab9637a4062c22e6e70d +-yuvj444p 894e6184d987a5ec4dc6f77bb75ef38c +-yuyv422 169e19ac91b257bd84ace0fdf56559ad +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip 2012-05-14 14:08:55.763368743 +0200 +@@ -0,0 +1,69 @@ ++0bgr 39270c968598bac0ef53faaa5f9ab7cd ++0rgb 099dc071d7385b2958e36604c2fbf4ef ++abgr 25e72e9dbd01ab00727c976d577f7be5 ++argb 19869bf1a5ac0b6af4d8bbe2c104533c ++bgr0 e03d3ee0b977f6d86e5116b20494bef5 ++bgr24 89108a4ba00201f79b75b9305c42352d ++bgr444be 9ef12c42fb791948ca4423c452dc6b9a ++bgr444le 3650ecfc163abd1596c0cd29d130c4b0 ++bgr48be 2f23931844f57641f3737348182d118c ++bgr48le 4242a026012b6c135a6aa138a6d67031 ++bgr4_byte 407fcf564ed764c38e1d748f700ab921 ++bgr555be f739d2519f7e9d494359bf67a3821537 ++bgr555le bd7b3ec4d684dfad075d89a606cb8b74 ++bgr565be f19e9a4786395e1ddcd51399c98c9f6c ++bgr565le fdb617533e1e7ff512ea5b6b6233e738 ++bgr8 c60f93fd152c6903391d1fe9decd3547 ++bgra 7f9b799fb48544e49ce93e91d7f9fca8 ++gray 30d9014a9d43b5f37e7aa64be3a3ecfc ++gray16be 9e8319fa0d4945e587b8c095277be8de ++gray16le 790031119f8e874d75ee6f01b4654185 ++monob d0cf8732677a5360b6160133043590d8 ++monow ff9869d067ecb94eb9d90c9750c31fea ++nv12 046f00f598ce14d9854a3534a5c99114 ++nv21 01ea369dd2d0d3ed7451dc5c8d61497f ++pal8 47ed19a7e128b0e33c25d2a463b0611a ++rgb0 330bd6168e46c0d5eb4acbdbb50afa2e ++rgb24 eaefabc168d0b14576bab45bc1e56e1e ++rgb444be 06722e03f8404e7d2226665ed2444a32 ++rgb444le 185c9a5d9c2877484310d4196ef4cd6f ++rgb48be 62dd185862ed142283bd300eb6dbd216 ++rgb48le dcb76353268bc5862194d131762220da ++rgb4_byte 8c6ff02df0b06dd2d574836c3741b2a2 ++rgb555be 40dc33cfb5cf56aac1c5a290ac486c36 ++rgb555le 4f8eaad29a17e0f8e9d8ab743e76b999 ++rgb565be b57623ad9df74648339311a0edcebc7b ++rgb565le 73f247a3315dceaea3022ac7c197c5ef ++rgb8 13a8d89ef78d8127297d899005456ff0 ++rgba 1fc6e920a42ec812aaa3b2aa02f37987 ++uyvy422 ffbd36720c77398d9a0d03ce2625928f ++yuv410p 7bfb39d7afb49d6a6173e6b23ae321eb ++yuv411p 4a90048cc3a65fac150e53289700efe1 ++yuv420p 2e6d6062e8cad37fb3ab2c433b55f382 ++yuv420p10be 7ce787a888381dd46b0212c099ecaad9 ++yuv420p10le bf22a1c543a7b3dbc556a0eb9592e179 ++yuv420p16be b6d25ba55bc1831d352f379311b42b6d ++yuv420p16le 1d7ef427b6f79a02b93948738dab5442 ++yuv420p9be 9865bf5c4392b56b1c4eb4f5a3fd32f9 ++yuv420p9le 0f1e371a1374d3cba2205b70cc7cac90 ++yuv422p d7f5cb44d9b0210d66d6a8762640ab34 ++yuv422p10be 0be8378c3773e1c0b394315ef4994351 ++yuv422p10le 6518094fe8de6bee95af21af1e5dc1e1 ++yuv422p16be 9bd8f8c961822b586fa4cf992be54acc ++yuv422p16le 9c4a1239605c7952b736ac3130163f14 ++yuv422p9be 7c6f1e140b3999ee7d923854e507752a ++yuv422p9le 51f10d79c07989060dd06e767e6d7d60 ++yuv440p 876385e96165acf51271b20e5d85a416 ++yuv444p 9c3c667d1613b72d15bc6d851c5eb8f7 ++yuv444p10be ee069cc6db48975eb029d72f889a7fe6 ++yuv444p10le 645b3335248113cafe3c29edb1d7f3be ++yuv444p16be de2dedfc6f12073ffead113f86e07ecf ++yuv444p16le 8e83323cf102d6c823a03ae8a7b7e033 ++yuv444p9be 6ac92b7dc9ab2fc59bee99204886899a ++yuv444p9le 85aef13a654953d3455d89770b0d74bd ++yuva420p c705d1cf061d8c6580ac690b55f92276 ++yuvj420p 41fd02b204da0ab62452cd14b595e2e4 ++yuvj422p 7f6ca9bc1812cde02036d7d29a7cce43 ++yuvj440p 25711c3c0fd15ec19c59a10784fcfb96 ++yuvj444p e45dee2ac02276dfab92e8ebfbe52e00 ++yuyv422 e944ff7316cd03c42c091717ce74f602 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip_le xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip_le +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip_le 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/lavfi/pixfmts_vflip_le 1970-01-01 01:00:00.000000000 +0100 +@@ -1,42 +0,0 @@ +-abgr 25e72e9dbd01ab00727c976d577f7be5 +-argb 19869bf1a5ac0b6af4d8bbe2c104533c +-bgr24 89108a4ba00201f79b75b9305c42352d +-bgr4_byte 407fcf564ed764c38e1d748f700ab921 +-bgr555le bd7b3ec4d684dfad075d89a606cb8b74 +-bgr565le fdb617533e1e7ff512ea5b6b6233e738 +-bgr8 c60f93fd152c6903391d1fe9decd3547 +-bgra 7f9b799fb48544e49ce93e91d7f9fca8 +-gray 30d9014a9d43b5f37e7aa64be3a3ecfc +-gray16be 6b84b85d3326182fa1217e138249edc5 +-gray16le 66bb8faa09dc149734aca3c768a6d4e1 +-monob d0cf8732677a5360b6160133043590d8 +-monow ff9869d067ecb94eb9d90c9750c31fea +-nv12 046f00f598ce14d9854a3534a5c99114 +-nv21 01ea369dd2d0d3ed7451dc5c8d61497f +-rgb24 eaefabc168d0b14576bab45bc1e56e1e +-rgb48be 4e0c384163ebab06a08e74637beb02bc +-rgb48le a77bfeefcd96750cf0e1917a2e2bf1e7 +-rgb4_byte 8c6ff02df0b06dd2d574836c3741b2a2 +-rgb555le 4f8eaad29a17e0f8e9d8ab743e76b999 +-rgb565le 73f247a3315dceaea3022ac7c197c5ef +-rgb8 13a8d89ef78d8127297d899005456ff0 +-rgba 1fc6e920a42ec812aaa3b2aa02f37987 +-uyvy422 ffbd36720c77398d9a0d03ce2625928f +-yuv410p 7bfb39d7afb49d6a6173e6b23ae321eb +-yuv411p 4a90048cc3a65fac150e53289700efe1 +-yuv420p 2e6d6062e8cad37fb3ab2c433b55f382 +-yuv420p16be 539076782902664a8acf381bf4f713e8 +-yuv420p16le 0f609e588e5a258644ef85170d70e030 +-yuv422p d7f5cb44d9b0210d66d6a8762640ab34 +-yuv422p16be 9bd8f8c961822b586fa4cf992be54acc +-yuv422p16le 9c4a1239605c7952b736ac3130163f14 +-yuv440p 876385e96165acf51271b20e5d85a416 +-yuv444p 9c3c667d1613b72d15bc6d851c5eb8f7 +-yuv444p16be 0f4afa4a4aacf4bb6b87641abde71ea9 +-yuv444p16le 8f31557bc52adfe00ae8b40a9b8c23f8 +-yuva420p c705d1cf061d8c6580ac690b55f92276 +-yuvj420p 41fd02b204da0ab62452cd14b595e2e4 +-yuvj422p 7f6ca9bc1812cde02036d7d29a7cce43 +-yuvj440p 40591908cca457f51dee30a86c3e8ffd +-yuvj444p 77e5e095881c52a04fd9f5abd1d7b5ac +-yuyv422 e944ff7316cd03c42c091717ce74f602 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/ac3_rm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/ac3_rm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/ac3_rm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/ac3_rm 2012-05-14 14:08:55.764368763 +0200 +@@ -5,22 +5,27 @@ + ret:-1 st: 0 flags:0 ts: 0.788000 + ret: 0 st: 0 flags:1 ts:-0.317000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +-ret:-1 st:-1 flags:0 ts: 2.576668 ++ret: 0 st:-1 flags:0 ts: 2.576668 ++ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558 + ret:-1 st:-1 flags:1 ts: 1.470835 + ret:-1 st: 0 flags:0 ts: 0.365000 + ret: 0 st: 0 flags:1 ts:-0.741000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +-ret:-1 st:-1 flags:0 ts: 2.153336 ++ret: 0 st:-1 flags:0 ts: 2.153336 ++ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558 + ret:-1 st:-1 flags:1 ts: 1.047503 + ret: 0 st: 0 flags:0 ts:-0.058000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +-ret:-1 st: 0 flags:1 ts: 2.836000 ++ret: 0 st: 0 flags:1 ts: 2.836000 ++ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558 + ret:-1 st:-1 flags:0 ts: 1.730004 + ret:-1 st:-1 flags:1 ts: 0.624171 + ret: 0 st: 0 flags:0 ts:-0.482000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +-ret:-1 st: 0 flags:1 ts: 2.413000 +-ret:-1 st:-1 flags:0 ts: 1.306672 ++ret: 0 st: 0 flags:1 ts: 2.413000 ++ret: 0 st: 0 flags:1 dts: 2.124000 pts: 2.124000 pos: 34997 size: 558 ++ret: 0 st:-1 flags:0 ts: 1.306672 ++ret: 0 st: 0 flags:1 dts:65.537000 pts:65.537000 pos: 87488 size: 6132 + ret:-1 st:-1 flags:1 ts: 0.200839 + ret: 0 st: 0 flags:0 ts:-0.905000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +@@ -30,6 +35,7 @@ + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 + ret:-1 st: 0 flags:0 ts: 2.672000 + ret:-1 st: 0 flags:1 ts: 1.566000 +-ret:-1 st:-1 flags:0 ts: 0.460008 ++ret: 0 st:-1 flags:0 ts: 0.460008 ++ret: 0 st: 0 flags:1 dts: 1.567000 pts: 1.567000 pos: 25889 size: 556 + ret: 0 st:-1 flags:1 ts:-0.645825 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 271 size: 556 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/adpcm_yam_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/adpcm_yam_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/adpcm_yam_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/adpcm_yam_wav 2012-05-14 14:08:55.765368783 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos: 29752 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.856009 pts: 1.856009 pos: 29754 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos: 13368 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.831995 pts: 0.831995 pos: 13370 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos: 42040 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.623991 pts: 2.623991 pos: 42042 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos: 22584 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.408005 pts: 1.408005 pos: 22586 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos: 6200 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.383991 pts: 0.383991 pos: 6202 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos: 34872 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.176009 pts: 2.176009 pos: 34874 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos: 16440 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.023991 pts: 1.023991 pos: 16442 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos: 45112 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.816009 pts: 2.816009 pos: 45114 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos: 28728 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.791995 pts: 1.791995 pos: 28730 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos: 9272 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.576009 pts: 0.576009 pos: 9274 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos: 37944 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.368005 pts: 2.368005 pos: 37946 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos: 21560 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.343991 pts: 1.343991 pos: 21562 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos: 3128 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.191995 pts: 0.191995 pos: 3130 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos: 31800 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.983991 pts: 1.983991 pos: 31802 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos: 14392 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.896009 pts: 0.896009 pos: 14394 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos: 43064 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.688005 pts: 2.688005 pos: 43066 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos: 24632 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.536009 pts: 1.536009 pos: 24634 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos: 8248 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.511995 pts: 0.511995 pos: 8250 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv411_dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv411_dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv411_dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv411_dv 2012-05-14 14:08:55.766368803 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:6768000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:5328000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.360000 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.760000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:3744000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.040000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.840000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:6192000 size:144000 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:4752000 size:144000 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 720000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.920000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.000000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:0 ts: 2.680000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st: 0 flags:1 ts: 1.560000 +-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:5616000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv50_dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv50_dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv50_dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv50_dv 2012-05-14 14:08:55.767368823 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:13536000 size:288000 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:5760000 size:288000 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:10656000 size:288000 + ret: 0 st: 0 flags:0 ts: 0.360000 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:2592000 size:288000 + ret: 0 st: 0 flags:1 ts:-0.760000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:7488000 size:288000 + ret: 0 st: 0 flags:0 ts:-0.040000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st: 0 flags:1 ts: 2.840000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:12384000 size:288000 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:4608000 size:288000 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:9504000 size:288000 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:1440000 size:288000 + ret: 0 st: 0 flags:0 ts:-0.920000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st: 0 flags:1 ts: 2.000000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:6336000 size:288000 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 + ret: 0 st: 0 flags:0 ts: 2.680000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:14112000 size:288000 + ret: 0 st: 0 flags:1 ts: 1.560000 +-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:11232000 size:288000 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:3456000 size:288000 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:288000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:288000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv_dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv_dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/dv_dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/dv_dv 2012-05-14 14:08:55.767368823 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.880000 pts: 1.880000 pos:6768000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.480000 pts: 1.480000 pos:5328000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.360000 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.760000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.040000 pts: 1.040000 pos:3744000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.040000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.840000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.720000 pts: 1.720000 pos:6192000 size:144000 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.320000 pts: 1.320000 pos:4752000 size:144000 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 720000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.920000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.000000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:0 ts: 2.680000 +-ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.960000 pts: 1.960000 pos:7056000 size:144000 + ret: 0 st: 0 flags:1 ts: 1.560000 +-ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 1.560000 pts: 1.560000 pos:5616000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/g726_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/g726_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/g726_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/g726_wav 2012-05-14 14:08:55.768368843 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894000 pts: 1.894000 pos: 7632 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.894000 pts: 1.894000 pos: 7634 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788375 +-ret: 0 st: 0 flags:1 dts: 0.788500 pts: 0.788500 pos: 3210 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788500 pts: 0.788500 pos: 3212 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317500 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576750 pts: 2.576750 pos: 10363 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.576750 pts: 2.576750 pos: 10365 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470750 pts: 1.470750 pos: 5939 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.470750 pts: 1.470750 pos: 5941 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 0.365000 pts: 0.365000 pos: 1516 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365000 pts: 0.365000 pos: 1518 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740875 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153500 pts: 2.153500 pos: 8670 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.153500 pts: 2.153500 pos: 8672 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047500 pts: 1.047500 pos: 4246 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.047500 pts: 1.047500 pos: 4248 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058375 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835875 +-ret: 0 st: 0 flags:1 dts: 2.835750 pts: 2.835750 pos: 11399 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.835750 pts: 2.835750 pos: 11401 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 6976 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 6978 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624000 pts: 0.624000 pos: 2552 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624000 pts: 0.624000 pos: 2554 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481625 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412500 +-ret: 0 st: 0 flags:1 dts: 2.412500 pts: 2.412500 pos: 9706 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.412500 pts: 2.412500 pos: 9708 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306750 pts: 1.306750 pos: 5283 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.306750 pts: 1.306750 pos: 5285 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200750 pts: 0.200750 pos: 859 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200750 pts: 0.200750 pos: 861 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989125 +-ret: 0 st: 0 flags:1 dts: 1.989000 pts: 1.989000 pos: 8012 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.989000 pts: 1.989000 pos: 8014 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883500 pts: 0.883500 pos: 3590 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883500 pts: 0.883500 pos: 3592 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671625 +-ret: 0 st: 0 flags:1 dts: 2.671750 pts: 2.671750 pos: 10743 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.671750 pts: 2.671750 pos: 10745 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565875 +-ret: 0 st: 0 flags:1 dts: 1.565750 pts: 1.565750 pos: 6319 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.565750 pts: 1.565750 pos: 6321 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 1896 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 1898 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_asf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_asf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_asf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_asf 2012-05-14 14:08:55.769368863 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 1 flags:1 dts: 3.544000 pts: 3.544000 pos: 147775 size: 209 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st: 1 flags:0 ts: 2.577000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st: 1 flags:1 ts: 1.471000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147889 size: 209 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st: 0 flags:0 ts: 2.153000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 0 flags:1 ts: 1.048000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 1 flags:0 ts:-0.058000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 29489 size: 208 + ret: 0 st: 1 flags:1 ts: 2.836000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147889 size: 209 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 1 flags:0 ts: 1.307000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st: 1 flags:1 ts: 0.201000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: 71089 size: 209 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 0 flags:0 ts: 0.883000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.940000 pts: 0.940000 pos: 301489 size: 209 + ret: 0 st: 0 flags:1 ts:-0.222000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 + ret: 0 st: 1 flags:0 ts: 2.672000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st: 1 flags:1 ts: 1.566000 +-ret: 0 st: 1 flags:1 dts: 3.100000 pts: 3.100000 pos: 29375 size: 208 ++ret: 0 st: 1 flags:1 dts: 0.967000 pts: 0.967000 pos: 330289 size: 209 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 1 flags:1 dts: 0.444000 pts: 0.444000 pos: 147889 size: 209 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 575 size: 28487 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 689 size: 28487 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_avi xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_avi +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_avi 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_avi 2012-05-14 14:08:55.770368883 +0200 +@@ -1,44 +1,44 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret:-1 st: 0 flags:1 ts:-0.320000 + ret:-1 st: 1 flags:0 ts: 2.586122 + ret: 0 st: 1 flags:1 ts: 1.462857 +-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955 ++ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155966 size: 209 + ret:-1 st:-1 flags:1 ts:-0.740831 + ret:-1 st: 0 flags:0 ts: 2.160000 + ret: 0 st: 0 flags:1 ts: 1.040000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret: 0 st: 1 flags:0 ts:-0.052245 +-ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 37784 size: 208 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st: 1 flags:1 ts: 2.847347 +-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret:-1 st:-1 flags:0 ts: 1.730004 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955 ++ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155966 size: 209 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret:-1 st: 1 flags:0 ts: 1.306122 + ret: 0 st: 1 flags:1 ts: 0.208980 +-ret: 0 st: 1 flags:1 dts: 0.208980 pts: 0.208980 pos: 92800 size: 209 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9908 size: 27867 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 9926 size: 27867 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret: 0 st: 0 flags:0 ts: 0.880000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301466 size: 27864 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret:-1 st: 0 flags:1 ts:-0.240000 + ret:-1 st: 1 flags:0 ts: 2.664490 + ret: 0 st: 1 flags:1 ts: 1.567347 +-ret: 0 st: 1 flags:1 dts: 1.018776 pts: 1.018776 pos: 329774 size: 209 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 301484 size: 27864 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 156166 size: 27955 ++ret: 0 st: 1 flags:1 dts: 0.470204 pts: 0.470204 pos: 155966 size: 209 + ret:-1 st:-1 flags:1 ts:-0.645825 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_dv 2012-05-14 14:08:55.771368903 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:2880000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 1 flags:0 ts: 2.576667 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 1 flags:1 ts: 1.470833 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1296000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:0 ts: 2.160000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 0 flags:1 ts: 1.040000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 1 flags:0 ts:-0.058333 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 1 flags:1 ts: 2.835833 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:2304000 size:144000 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 1 flags:0 ts: 1.306667 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 1 flags:1 ts: 0.200833 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 0 flags:0 ts: 0.880000 +-ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:3168000 size:144000 + ret: 0 st: 0 flags:1 ts:-0.240000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 + ret: 0 st: 1 flags:0 ts: 2.671667 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st: 1 flags:1 ts: 1.565833 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:3456000 size:144000 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:1728000 size:144000 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:144000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 0 size:144000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ffm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ffm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ffm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ffm 2012-05-14 14:08:55.772368923 +0200 +@@ -4,7 +4,7 @@ + ret: 0 st:-1 flags:1 ts: 1.894167 + ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209 + ret: 0 st: 0 flags:0 ts: 0.788334 +-ret: 0 st: 1 flags:1 dts: 0.783673 pts: 0.783673 pos: 315392 size: 209 ++ret: 0 st: 1 flags:1 dts: 0.809796 pts: 0.809796 pos: 327680 size: 209 + ret: 0 st: 0 flags:1 ts:-0.317499 + ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664 + ret: 0 st: 1 flags:0 ts: 2.576668 +@@ -12,7 +12,7 @@ + ret: 0 st: 1 flags:1 ts: 1.470835 + ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 1 flags:1 dts: 0.339592 pts: 0.339592 pos: 155648 size: 209 ++ret: 0 st: 1 flags:1 dts: 0.365714 pts: 0.365714 pos: 163840 size: 209 + ret: 0 st:-1 flags:1 ts:-0.740831 + ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664 + ret: 0 st: 0 flags:0 ts: 2.153336 +@@ -40,7 +40,7 @@ + ret: 0 st:-1 flags:1 ts: 1.989173 + ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209 + ret: 0 st: 0 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:0 dts: 0.880000 pts: 0.920000 pos: 339968 size: 12307 ++ret: 0 st: 1 flags:1 dts: 0.888163 pts: 0.888163 pos: 352256 size: 209 + ret: 0 st: 0 flags:1 ts:-0.222493 + ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664 + ret: 0 st: 1 flags:0 ts: 2.671674 +@@ -48,6 +48,6 @@ + ret: 0 st: 1 flags:1 ts: 1.565841 + ret: 0 st: 1 flags:1 dts: 0.940408 pts: 0.940408 pos: 376832 size: 209 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 1 flags:1 dts: 0.444082 pts: 0.444082 pos: 204800 size: 209 ++ret: 0 st: 1 flags:1 dts: 0.496327 pts: 0.496327 pos: 221184 size: 209 + ret: 0 st:-1 flags:1 ts:-0.645825 + ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 8192 size: 24664 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_flv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_flv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_flv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_flv 2012-05-14 14:08:55.772368923 +0200 +@@ -1,44 +1,44 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret:-1 st: 0 flags:1 ts:-0.317000 + ret:-1 st:-1 flags:0 ts: 2.576668 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149441 size: 31125 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149459 size: 31125 + ret:-1 st: 0 flags:1 ts:-0.741000 + ret:-1 st:-1 flags:0 ts: 2.153336 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret: 0 st: 0 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st: 0 flags:1 ts: 2.836000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret:-1 st:-1 flags:0 ts: 1.730004 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149441 size: 31125 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149459 size: 31125 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret:-1 st:-1 flags:0 ts: 1.306672 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 199 size: 31074 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 217 size: 31074 + ret: 0 st: 0 flags:1 ts: 1.989000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret:-1 st:-1 flags:1 ts:-0.222493 + ret:-1 st: 0 flags:0 ts: 2.672000 + ret: 0 st: 0 flags:1 ts: 1.566000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298403 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 298421 size: 31134 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149441 size: 31125 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 149459 size: 31125 + ret:-1 st:-1 flags:1 ts:-0.645825 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_gif xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_gif +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_gif 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_gif 2012-05-14 14:08:55.773368943 +0200 +@@ -1,4 +1,4 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:2906382 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: -1 size:2906401 + ret:-EINVAL st:-1 flags:0 ts:-1.000000 + ret:-EINVAL st:-1 flags:1 ts: 1.894167 + ret:-EINVAL st: 0 flags:0 ts: 0.800000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mkv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mkv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mkv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mkv 2012-05-14 14:08:55.774368963 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st: 1 flags:0 ts: 2.577000 + ret:-EOF + ret: 0 st: 1 flags:1 ts: 1.471000 +-ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320207 size: 209 ++ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320250 size: 209 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146703 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st: 0 flags:0 ts: 2.153000 + ret:-EOF + ret: 0 st: 0 flags:1 ts: 1.048000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 1 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st: 1 flags:1 ts: 2.836000 +-ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320207 size: 209 ++ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320250 size: 209 + ret: 0 st:-1 flags:0 ts: 1.730004 + ret:-EOF + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146703 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 1 flags:0 ts: 1.307000 + ret:-EOF + ret: 0 st: 1 flags:1 ts: 0.201000 +-ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: 72083 size: 209 ++ret: 0 st: 1 flags:1 dts: 0.183000 pts: 0.183000 pos: 72126 size: 209 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 0 flags:0 ts: 0.883000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291934 size: 27834 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 291977 size: 27834 + ret: 0 st: 0 flags:1 ts:-0.222000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 + ret: 0 st: 1 flags:0 ts: 2.672000 + ret:-EOF + ret: 0 st: 1 flags:1 ts: 1.566000 +-ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320207 size: 209 ++ret: 0 st: 1 flags:1 dts: 1.019000 pts: 1.019000 pos: 320250 size: 209 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146703 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146746 size: 27925 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 513 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 556 size: 27837 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mxf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mxf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mxf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mxf 2012-05-14 14:08:55.775368983 +0200 +@@ -1,53 +1,48 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 +-ret: 0 st: 1 flags:0 ts: 2.560000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 ++ret:-1 st: 1 flags:0 ts: 2.560000 + ret: 0 st: 1 flags:1 ts: 1.480000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.480000 pos: 211968 size: 24787 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 +-ret: 0 st: 0 flags:0 ts: 2.160000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 ++ret:-1 st: 0 flags:0 ts: 2.160000 + ret: 0 st: 0 flags:1 ts: 1.040000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st: 1 flags:0 ts:-0.040000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st: 1 flags:1 ts: 2.840000 +-ret:-1 +-ret: 0 st:-1 flags:0 ts: 1.730004 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 ++ret:-1 st:-1 flags:0 ts: 1.730004 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.480000 pos: 211968 size: 24787 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret:-1 +-ret: 0 st: 1 flags:0 ts: 1.320000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 ++ret:-1 st: 1 flags:0 ts: 1.320000 + ret: 0 st: 1 flags:1 ts: 0.200000 +-ret: 0 st: 0 flags:1 dts: 0.200000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st: 0 flags:0 ts: 0.880000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st: 0 flags:1 ts:-0.240000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 +-ret: 0 st: 1 flags:0 ts: 2.680000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 ++ret:-1 st: 1 flags:0 ts: 2.680000 + ret: 0 st: 1 flags:1 ts: 1.560000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts: 0.840000 pts: 0.960000 pos: 460800 size: 24712 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 6144 size: 24801 ++ret: 0 st: 0 flags:1 dts:-0.040000 pts: 0.000000 pos: 6144 size: 24801 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mxf_d10 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mxf_d10 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_mxf_d10 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_mxf_d10 2012-05-14 14:08:55.775368983 +0200 +@@ -2,52 +2,52 @@ + ret: 0 st:-1 flags:0 ts:-1.000000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.800000 pts: 0.800000 pos:4265984 size:150000 + ret: 0 st: 0 flags:1 ts:-0.320000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st: 1 flags:0 ts: 2.560000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 1 flags:1 ts: 1.480000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos: 6144 size:150000 ++ret: 0 st: 0 flags:1 dts: 0.360000 pts: 0.360000 pos:1923072 size:150000 + ret: 0 st:-1 flags:1 ts:-0.740831 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st: 0 flags:0 ts: 2.160000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 0 flags:1 ts: 1.040000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 1 flags:0 ts:-0.040000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st: 1 flags:1 ts: 2.840000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.640000 pts: 0.640000 pos:3414016 size:150000 + ret: 0 st: 0 flags:0 ts:-0.480000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 1 flags:0 ts: 1.320000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 1 flags:1 ts: 0.200000 +-ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos: 6144 size:150000 ++ret: 0 st: 0 flags:1 dts: 0.200000 pts: 0.200000 pos:1071104 size:150000 + ret: 0 st:-1 flags:0 ts:-0.904994 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 0 flags:0 ts: 0.880000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.880000 pts: 0.880000 pos:4691968 size:150000 + ret: 0 st: 0 flags:1 ts:-0.240000 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 + ret: 0 st: 1 flags:0 ts: 2.680000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st: 1 flags:1 ts: 1.560000 +-ret:-1 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos:5117952 size:150000 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 6144 size:150000 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos:2562048 size:150000 + ret: 0 st:-1 flags:1 ts:-0.645825 + ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 6144 size:150000 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_nut xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_nut +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_nut 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_nut 2012-05-14 14:08:55.776369003 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:0 ts: 0.800000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:1 ts:-0.320000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st: 1 flags:0 ts: 2.586122 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 1 flags:1 ts: 1.462857 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st: 0 flags:0 ts: 2.160000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:1 ts: 1.040000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 1 flags:0 ts:-0.052245 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st: 1 flags:1 ts: 2.847347 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:0 ts:-0.480000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st: 0 flags:1 ts: 2.400000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 1 flags:0 ts: 1.306122 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 1 flags:1 ts: 0.208980 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:0 ts: 0.880000 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 0 flags:1 ts:-0.240000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 + ret: 0 st: 1 flags:0 ts: 2.664490 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st: 1 flags:1 ts: 1.567347 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146329 size: 27925 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 146345 size: 27925 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 279 size: 27837 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 295 size: 27837 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ogg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ogg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ogg 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ogg 2012-05-14 14:08:55.777369023 +0200 +@@ -1,4 +1,4 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 125 size: 1364 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 143 size: 1364 + ret:-1 st:-1 flags:0 ts:-1.000000 + ret:-1 st:-1 flags:1 ts: 1.894167 + ret:-1 st: 0 flags:0 ts: 0.788345 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_rm xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_rm +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_rm 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_rm 2012-05-14 14:08:55.778369044 +0200 +@@ -1,47 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 +-ret:-1 st: 1 flags:0 ts: 2.577000 +-ret:-1 st: 1 flags:1 ts: 1.471000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 ++ret: 0 st: 1 flags:0 ts: 2.577000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 ++ret: 0 st: 1 flags:1 ts: 1.471000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158523 size: 31134 + ret: 0 st:-1 flags:1 ts:-0.740831 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 + ret: 0 st: 0 flags:0 ts: 2.153000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 0 flags:1 ts: 1.048000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 1 flags:0 ts:-0.058000 +-ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 31483 size: 278 +-ret:-1 st: 1 flags:1 ts: 2.836000 ++ret: 0 st: 1 flags:1 dts: 0.000000 pts: 0.000000 pos: 31491 size: 278 ++ret: 0 st: 1 flags:1 ts: 2.836000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158523 size: 31134 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 +-ret:-1 st: 1 flags:0 ts: 1.307000 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 ++ret: 0 st: 1 flags:0 ts: 1.307000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 + ret: 0 st: 1 flags:1 ts: 0.201000 +-ret: 0 st: 1 flags:1 dts: 0.174000 pts: 0.174000 pos: 78969 size: 278 ++ret: 0 st: 1 flags:1 dts: 0.174000 pts: 0.174000 pos: 78977 size: 278 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 0 flags:0 ts: 0.883000 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314982 size: 31143 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: 0.960000 pos: 314990 size: 31143 + ret: 0 st: 0 flags:1 ts:-0.222000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 +-ret:-1 st: 1 flags:0 ts: 2.672000 +-ret:-1 st: 1 flags:1 ts: 1.566000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 ++ret: 0 st: 1 flags:0 ts: 2.672000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 ++ret: 0 st: 1 flags:1 ts: 1.566000 ++ret: 0 st: 1 flags:1 dts: 0.975000 pts: 0.975000 pos: 346136 size: 278 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158515 size: 31134 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: 0.480000 pos: 158523 size: 31134 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 398 size: 31082 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 406 size: 31082 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ts xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ts +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_ts 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_ts 2012-05-14 14:08:55.778369044 +0200 +@@ -1,53 +1,53 @@ + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 ++ret: 0 st: 0 flags:0 dts: 1.880000 pts: 1.920000 pos: 216012 size: 17441 + ret: 0 st: 0 flags:0 ts: 0.788333 +-ret: 0 st: 0 flags:0 dts: 1.520000 pts: 1.560000 pos: 74260 size: 13388 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 0 flags:1 ts:-0.317500 + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 1 flags:0 ts: 2.576667 + ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 + ret: 0 st: 1 flags:1 ts: 1.470833 +-ret: 0 st: 0 flags:0 dts: 2.160000 pts: 2.200000 pos: 325240 size: 12679 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st:-1 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st:-1 flags:1 ts:-0.740831 + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 0 flags:0 ts: 2.153333 +-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 ++ret: 0 st: 0 flags:0 dts: 2.160000 pts: 2.200000 pos: 325240 size: 12679 + ret: 0 st: 0 flags:1 ts: 1.047500 +-ret: 0 st: 0 flags:0 dts: 1.680000 pts: 1.720000 pos: 130096 size: 14133 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 1 flags:0 ts:-0.058333 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st: 1 flags:1 ts: 2.835833 + ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st:-1 flags:1 ts: 0.624171 + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 0 flags:0 ts:-0.481667 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 0 flags:1 ts: 2.412500 + ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 + ret: 0 st: 1 flags:0 ts: 1.306667 +-ret: 0 st: 0 flags:0 dts: 2.080000 pts: 2.120000 pos: 294032 size: 13839 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st: 1 flags:1 ts: 0.200844 +-ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st:-1 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st:-1 flags:1 ts: 1.989173 +-ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 ++ret: 0 st: 0 flags:0 dts: 1.960000 pts: 2.000000 pos: 250980 size: 13438 + ret: 0 st: 0 flags:0 ts: 0.883344 +-ret: 0 st: 0 flags:0 dts: 1.600000 pts: 1.640000 pos: 102836 size: 12781 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 0 flags:1 ts:-0.222489 + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st: 1 flags:0 ts: 2.671678 + ret: 0 st: 1 flags:1 dts: 2.131433 pts: 2.131433 pos: 403636 size: 209 + ret: 0 st: 1 flags:1 ts: 1.565844 +-ret: 0 st: 0 flags:0 dts: 2.240000 pts: 2.280000 pos: 350996 size: 11307 ++ret: 0 st: 1 flags:1 dts: 1.400000 pts: 1.400000 pos: 172584 size: 208 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:0 dts: 1.440000 pts: 1.480000 pos: 44932 size: 14502 ++ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 + ret: 0 st:-1 flags:1 ts:-0.645825 + ret: 0 st: 0 flags:1 dts: 1.360000 pts: 1.400000 pos: 564 size: 24801 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_wav 2012-05-14 14:08:55.779369065 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 + ret:-EOF + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69576 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69578 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 + ret:-EOF + ret: 0 st:-1 flags:1 ts: 1.470835 + ret:-EOF + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32238 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32240 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 + ret:-EOF + ret: 0 st:-1 flags:1 ts: 1.047503 + ret:-EOF + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 + ret:-EOF + ret: 0 st:-1 flags:0 ts: 1.730004 + ret:-EOF + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55096 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55098 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 + ret:-EOF + ret: 0 st:-1 flags:0 ts: 1.306672 + ret:-EOF + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17758 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17760 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 + ret:-EOF + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77954 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77956 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 + ret:-EOF + ret: 0 st: 0 flags:1 ts: 1.565850 + ret:-EOF + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40616 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40618 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_wtv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_wtv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/lavf_wtv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/lavf_wtv 2012-05-14 14:08:55.780369085 +0200 +@@ -0,0 +1,41 @@ ++ret: 0 st: 0 flags:1 dts:-0.040000 pts:-0.040000 pos: 2144 size: 24801 ++ret: 0 st:-1 flags:0 ts:-1.000000 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st:-1 flags:1 ts: 1.894167 ++ret: 0 st: 0 flags:0 ts: 0.788334 ++ret: 0 st: 1 flags:1 dts: 0.783674 pts: 0.783674 pos: 321176 size: 209 ++ret: 0 st: 0 flags:1 ts:-0.317499 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st: 1 flags:0 ts: 2.576668 ++ret:-1 st: 1 flags:1 ts: 1.470835 ++ret: 0 st:-1 flags:0 ts: 0.365002 ++ret: 0 st: 1 flags:1 dts: 0.365714 pts: 0.365714 pos: 167160 size: 209 ++ret: 0 st:-1 flags:1 ts:-0.740831 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st: 0 flags:0 ts: 2.153336 ++ret:-1 st: 0 flags:1 ts: 1.047503 ++ret: 0 st: 1 flags:0 ts:-0.058330 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st: 1 flags:1 ts: 2.835837 ++ret:-1 st:-1 flags:0 ts: 1.730004 ++ret: 0 st:-1 flags:1 ts: 0.624171 ++ret: 0 st: 1 flags:1 dts: 0.600816 pts: 0.600816 pos: 266240 size: 209 ++ret: 0 st: 0 flags:0 ts:-0.481662 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st: 0 flags:1 ts: 2.412505 ++ret:-1 st: 1 flags:0 ts: 1.306672 ++ret: 0 st: 1 flags:1 ts: 0.200839 ++ret: 0 st: 1 flags:1 dts: 0.208980 pts: 0.208980 pos: 113304 size: 209 ++ret: 0 st:-1 flags:0 ts:-0.904994 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st:-1 flags:1 ts: 1.989173 ++ret: 0 st: 0 flags:0 ts: 0.883340 ++ret: 0 st: 1 flags:1 dts: 0.888163 pts: 0.888163 pos: 357608 size: 209 ++ret: 0 st: 0 flags:1 ts:-0.222493 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 ++ret:-1 st: 1 flags:0 ts: 2.671674 ++ret:-1 st: 1 flags:1 ts: 1.565841 ++ret: 0 st:-1 flags:0 ts: 0.460008 ++ret: 0 st: 1 flags:1 dts: 0.444082 pts: 0.444082 pos: 205440 size: 209 ++ret: 0 st:-1 flags:1 ts:-0.645825 ++ret: 0 st: 0 flags:1 dts: NOPTS pts: 0.000000 pos: 2144 size: 24801 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/mpeg2_idct_int_mpg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/mpeg2_idct_int_mpg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/mpeg2_idct_int_mpg 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/mpeg2_idct_int_mpg 2012-05-14 14:08:55.780369085 +0200 +@@ -0,0 +1,46 @@ ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st:-1 flags:0 ts:-1.000000 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st:-1 flags:1 ts: 1.894167 ++ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 ++ret: 0 st: 0 flags:0 ts: 0.788334 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 ++ret:-1 st: 0 flags:1 ts:-0.317499 ++ret:-1 st:-1 flags:0 ts: 2.576668 ++ret: 0 st:-1 flags:1 ts: 1.470835 ++ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 ++ret: 0 st: 0 flags:0 ts: 0.365002 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 ++ret:-1 st: 0 flags:1 ts:-0.740831 ++ret:-1 st:-1 flags:0 ts: 2.153336 ++ret: 0 st:-1 flags:1 ts: 1.047503 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 ++ret: 0 st: 0 flags:0 ts:-0.058330 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st: 0 flags:1 ts: 2.835837 ++ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 ++ret: 0 st:-1 flags:0 ts: 1.730004 ++ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 ++ret: 0 st:-1 flags:1 ts: 0.624171 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 ++ret: 0 st: 0 flags:0 ts:-0.481662 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st: 0 flags:1 ts: 2.412505 ++ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 ++ret: 0 st:-1 flags:0 ts: 1.306672 ++ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 ++ret: 0 st:-1 flags:1 ts: 0.200839 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st: 0 flags:0 ts:-0.904994 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 ++ret: 0 st: 0 flags:1 ts: 1.989173 ++ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 ++ret: 0 st:-1 flags:0 ts: 0.883340 ++ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 ++ret:-1 st:-1 flags:1 ts:-0.222493 ++ret:-1 st: 0 flags:0 ts: 2.671674 ++ret: 0 st: 0 flags:1 ts: 1.565841 ++ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 ++ret: 0 st:-1 flags:0 ts: 0.460008 ++ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 ++ret:-1 st:-1 flags:1 ts:-0.645825 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/mpeg2_mpg xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/mpeg2_mpg +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/mpeg2_mpg 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/mpeg2_mpg 1970-01-01 01:00:00.000000000 +0100 +@@ -1,46 +0,0 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 +-ret: 0 st: 0 flags:0 ts: 0.788334 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 +-ret:-1 st: 0 flags:1 ts:-0.317499 +-ret:-1 st:-1 flags:0 ts: 2.576668 +-ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 +-ret: 0 st: 0 flags:0 ts: 0.365002 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 +-ret:-1 st: 0 flags:1 ts:-0.740831 +-ret:-1 st:-1 flags:0 ts: 2.153336 +-ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 +-ret: 0 st: 0 flags:0 ts:-0.058330 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st: 0 flags:1 ts: 2.835837 +-ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 +-ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 +-ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 +-ret: 0 st: 0 flags:0 ts:-0.481662 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st: 0 flags:1 ts: 2.412505 +-ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 +-ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 +-ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st: 0 flags:0 ts:-0.904994 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: NOPTS pos: 0 size: 9911 +-ret: 0 st: 0 flags:1 ts: 1.989173 +-ret: 0 st: 0 flags:1 dts: 1.920000 pts: NOPTS pos: 182138 size: 12183 +-ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.960000 pts: NOPTS pos: 79103 size: 10909 +-ret:-1 st:-1 flags:1 ts:-0.222493 +-ret:-1 st: 0 flags:0 ts: 2.671674 +-ret: 0 st: 0 flags:1 ts: 1.565841 +-ret: 0 st: 0 flags:1 dts: 1.440000 pts: NOPTS pos: 127925 size: 11918 +-ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.480000 pts: NOPTS pos: 38992 size: 9985 +-ret:-1 st:-1 flags:1 ts:-0.645825 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_alaw_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_alaw_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_alaw_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_alaw_wav 2012-05-14 14:08:55.782369125 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30364 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12672 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41286 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23590 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5900 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34512 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16818 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45430 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27738 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10044 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38656 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20966 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3270 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31884 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14192 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42806 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25110 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7418 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_mulaw_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_mulaw_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_mulaw_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_mulaw_wav 2012-05-14 14:08:55.782369125 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30364 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12672 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41286 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23590 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5900 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34512 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16818 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45430 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27738 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10044 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38656 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20966 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3270 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31884 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14192 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42806 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25110 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7418 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 58 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16be_mkv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16be_mkv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16be_mkv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16be_mkv 1970-01-01 01:00:00.000000000 +0100 +@@ -1,53 +0,0 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.881000 pts: 1.881000 pos: 332755 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 0.789000 pts: 0.789000 pos: 139914 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.577000 pts: 2.577000 pos: 455845 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.463000 pts: 1.463000 pos: 258901 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 0.372000 pts: 0.372000 pos: 66060 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.741000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.159000 pts: 2.159000 pos: 381991 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.045000 pts: 1.045000 pos: 185047 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.836000 +-ret: 0 st: 0 flags:1 dts: 2.833000 pts: 2.833000 pos: 500978 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.741000 pts: 1.741000 pos: 308137 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.604000 pts: 0.604000 pos: 107090 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 2.392000 pts: 2.392000 pos: 423021 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.324000 pts: 1.324000 pos: 234283 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 33236 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.989000 +-ret: 0 st: 0 flags:1 dts: 1.974000 pts: 1.974000 pos: 349167 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.906000 pts: 0.906000 pos: 160429 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:0 ts: 2.672000 +-ret: 0 st: 0 flags:1 dts: 2.694000 pts: 2.694000 pos: 476360 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.566000 +-ret: 0 st: 0 flags:1 dts: 1.556000 pts: 1.556000 pos: 275313 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.464000 pts: 0.464000 pos: 82472 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16le_mkv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16le_mkv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16le_mkv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16le_mkv 1970-01-01 01:00:00.000000000 +0100 +@@ -1,53 +0,0 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.881000 pts: 1.881000 pos: 332755 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 0.789000 pts: 0.789000 pos: 139914 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.577000 pts: 2.577000 pos: 455845 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.463000 pts: 1.463000 pos: 258901 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 0.372000 pts: 0.372000 pos: 66060 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.741000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.159000 pts: 2.159000 pos: 381991 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.045000 pts: 1.045000 pos: 185047 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.836000 +-ret: 0 st: 0 flags:1 dts: 2.833000 pts: 2.833000 pos: 500978 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.741000 pts: 1.741000 pos: 308137 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.604000 pts: 0.604000 pos: 107090 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 2.392000 pts: 2.392000 pos: 423021 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.324000 pts: 1.324000 pos: 234283 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 33236 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.989000 +-ret: 0 st: 0 flags:1 dts: 1.974000 pts: 1.974000 pos: 349167 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.906000 pts: 0.906000 pos: 160429 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +-ret: 0 st: 0 flags:0 ts: 2.672000 +-ret: 0 st: 0 flags:1 dts: 2.694000 pts: 2.694000 pos: 476360 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.566000 +-ret: 0 st: 0 flags:1 dts: 1.556000 pts: 1.556000 pos: 275313 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.464000 pts: 0.464000 pos: 82472 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 412 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16le_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16le_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_s16le_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_s16le_wav 2012-05-14 14:08:55.784369165 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 334176 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 334178 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 139108 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 139110 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 454568 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 454570 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 259500 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 259502 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 64432 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 64434 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 379892 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 379894 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 184824 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 184826 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 500284 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 500286 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 305216 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 305218 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 110148 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 110150 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 425608 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 425610 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 230540 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 230542 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 35472 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 35474 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 350936 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 350938 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 155864 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 155866 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 471328 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 471330 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 276260 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 276262 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 81188 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 81190 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_u8_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_u8_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_u8_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_u8_wav 2012-05-14 14:08:55.785369185 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 167110 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.894172 pts: 1.894172 pos: 167112 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69576 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.788345 pts: 0.788345 pos: 69578 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 227306 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.576667 pts: 2.576667 pos: 227308 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 129772 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.470839 pts: 1.470839 pos: 129774 size: 4096 + ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32238 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.365011 pts: 0.365011 pos: 32240 size: 4096 + ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 189968 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.153333 pts: 2.153333 pos: 189970 size: 4096 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 92434 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 92436 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 250164 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.835828 pts: 2.835828 pos: 250166 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 152630 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 152632 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55096 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.624172 pts: 0.624172 pos: 55098 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 212826 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.412494 pts: 2.412494 pos: 212828 size: 4096 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 115292 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.306667 pts: 1.306667 pos: 115294 size: 4096 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17758 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.200839 pts: 0.200839 pos: 17760 size: 4096 + ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 175490 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.989184 pts: 1.989184 pos: 175492 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77954 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.883333 pts: 0.883333 pos: 77956 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 + ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 235686 size: 4096 ++ret: 0 st: 0 flags:1 dts: 2.671678 pts: 2.671678 pos: 235688 size: 4096 + ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 138152 size: 4096 ++ret: 0 st: 0 flags:1 dts: 1.565850 pts: 1.565850 pos: 138154 size: 4096 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40616 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 40618 size: 4096 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 44 size: 4096 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 46 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_zork_wav xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_zork_wav +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/pcm_zork_wav 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/pcm_zork_wav 1970-01-01 01:00:00.000000000 +0100 +@@ -1,53 +0,0 @@ +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 1.894127 pts: 1.894127 pos: 30362 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.788345 +-ret: 0 st: 0 flags:1 dts: 0.788367 pts: 0.788367 pos: 12670 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.317506 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 2.576757 pts: 2.576757 pos: 41284 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 1.470748 pts: 1.470748 pos: 23588 size: 4096 +-ret: 0 st: 0 flags:0 ts: 0.365011 +-ret: 0 st: 0 flags:1 dts: 0.365125 pts: 0.365125 pos: 5898 size: 4096 +-ret: 0 st: 0 flags:1 ts:-0.740839 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 2.153379 pts: 2.153379 pos: 34510 size: 4096 +-ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 1.047506 pts: 1.047506 pos: 16816 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.058322 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.835828 +-ret: 0 st: 0 flags:1 dts: 2.835760 pts: 2.835760 pos: 45428 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 1.730000 pts: 1.730000 pos: 27736 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 0.624127 pts: 0.624127 pos: 10042 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.481655 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st: 0 flags:1 ts: 2.412494 +-ret: 0 st: 0 flags:1 dts: 2.412381 pts: 2.412381 pos: 38654 size: 4096 +-ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 1.306757 pts: 1.306757 pos: 20964 size: 4096 +-ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 0.200748 pts: 0.200748 pos: 3268 size: 4096 +-ret: 0 st: 0 flags:0 ts:-0.904989 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.989184 +-ret: 0 st: 0 flags:1 dts: 1.989116 pts: 1.989116 pos: 31882 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 0.883379 pts: 0.883379 pos: 14190 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +-ret: 0 st: 0 flags:0 ts: 2.671678 +-ret: 0 st: 0 flags:1 dts: 2.671746 pts: 2.671746 pos: 42804 size: 4096 +-ret: 0 st: 0 flags:1 ts: 1.565850 +-ret: 0 st: 0 flags:1 dts: 1.565760 pts: 1.565760 pos: 25108 size: 4096 +-ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 0.460000 pts: 0.460000 pos: 7416 size: 4096 +-ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 56 size: 4096 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/wmav1_asf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/wmav1_asf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/wmav1_asf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/wmav1_asf 2012-05-14 14:08:55.787369225 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 3.286000 pts: 3.286000 pos: 3604 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32404 size: 743 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16404 size: 743 + ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.601000 pts: 2.601000 pos: 45204 size: 743 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.300000 pts: 1.300000 pos: 22804 size: 743 + ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.372000 pts: 0.372000 pos: 6804 size: 743 + ret: 0 st: 0 flags:1 ts:-0.741000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.229000 pts: 2.229000 pos: 38804 size: 743 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16404 size: 743 + ret: 0 st: 0 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st: 0 flags:1 ts: 2.836000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.786000 pts: 2.786000 pos: 48404 size: 743 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32404 size: 743 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.557000 pts: 0.557000 pos: 10004 size: 743 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.229000 pts: 2.229000 pos: 38804 size: 743 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.486000 pts: 1.486000 pos: 26004 size: 743 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 3604 size: 743 + ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st: 0 flags:1 ts: 1.989000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32404 size: 743 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16404 size: 743 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 + ret: 0 st: 0 flags:0 ts: 2.672000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.786000 pts: 2.786000 pos: 48404 size: 743 + ret: 0 st: 0 flags:1 ts: 1.566000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.486000 pts: 1.486000 pos: 26004 size: 743 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.557000 pts: 0.557000 pos: 10004 size: 743 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 404 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 404 size: 743 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/wmav2_asf xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/wmav2_asf +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/seek/wmav2_asf 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/seek/wmav2_asf 2012-05-14 14:08:55.787369225 +0200 +@@ -1,53 +1,53 @@ +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st:-1 flags:0 ts:-1.000000 +-ret: 0 st: 0 flags:1 dts: 3.286000 pts: 3.286000 pos: 3644 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st:-1 flags:1 ts: 1.894167 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32444 size: 743 + ret: 0 st: 0 flags:0 ts: 0.788000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16444 size: 743 + ret: 0 st: 0 flags:1 ts:-0.317000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st:-1 flags:0 ts: 2.576668 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.601000 pts: 2.601000 pos: 45244 size: 743 + ret: 0 st:-1 flags:1 ts: 1.470835 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.300000 pts: 1.300000 pos: 22844 size: 743 + ret: 0 st: 0 flags:0 ts: 0.365000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.372000 pts: 0.372000 pos: 6844 size: 743 + ret: 0 st: 0 flags:1 ts:-0.741000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st:-1 flags:0 ts: 2.153336 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.229000 pts: 2.229000 pos: 38844 size: 743 + ret: 0 st:-1 flags:1 ts: 1.047503 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16444 size: 743 + ret: 0 st: 0 flags:0 ts:-0.058000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st: 0 flags:1 ts: 2.836000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.786000 pts: 2.786000 pos: 48444 size: 743 + ret: 0 st:-1 flags:0 ts: 1.730004 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32444 size: 743 + ret: 0 st:-1 flags:1 ts: 0.624171 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.557000 pts: 0.557000 pos: 10044 size: 743 + ret: 0 st: 0 flags:0 ts:-0.482000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st: 0 flags:1 ts: 2.413000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.229000 pts: 2.229000 pos: 38844 size: 743 + ret: 0 st:-1 flags:0 ts: 1.306672 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.486000 pts: 1.486000 pos: 26044 size: 743 + ret: 0 st:-1 flags:1 ts: 0.200839 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.186000 pts: 0.186000 pos: 3644 size: 743 + ret: 0 st: 0 flags:0 ts:-0.905000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st: 0 flags:1 ts: 1.989000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.858000 pts: 1.858000 pos: 32444 size: 743 + ret: 0 st:-1 flags:0 ts: 0.883340 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.929000 pts: 0.929000 pos: 16444 size: 743 + ret: 0 st:-1 flags:1 ts:-0.222493 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 + ret: 0 st: 0 flags:0 ts: 2.672000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 2.786000 pts: 2.786000 pos: 48444 size: 743 + ret: 0 st: 0 flags:1 ts: 1.566000 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 1.486000 pts: 1.486000 pos: 26044 size: 743 + ret: 0 st:-1 flags:0 ts: 0.460008 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.557000 pts: 0.557000 pos: 10044 size: 743 + ret: 0 st:-1 flags:1 ts:-0.645825 +-ret: 0 st: 0 flags:1 dts: 3.100000 pts: 3.100000 pos: 444 size: 743 ++ret: 0 st: 0 flags:1 dts: 0.000000 pts: 0.000000 pos: 444 size: 743 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/amv/vsynth1-amv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/amv/vsynth1-amv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/amv/vsynth1-amv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/amv/vsynth1-amv 2012-05-14 14:08:55.788369245 +0200 +@@ -0,0 +1,4 @@ ++539c26ba470de4d72279855fcf61f5a2 *./tests/data/vsynth1/amv.avi ++1365534 ./tests/data/vsynth1/amv.avi ++27bbe70dd002ec67af0bb219fbae626a *./tests/data/amv.vsynth1.out.yuv ++stddev: 12.46 PSNR: 26.21 MAXDIFF: 97 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/cljr xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/cljr +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/cljr 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/cljr 2012-05-14 14:08:55.788369245 +0200 +@@ -0,0 +1,4 @@ ++041982e4fa83428c621a127647d47b3f *./tests/data/vsynth1/cljr.avi ++ 5075660 ./tests/data/vsynth1/cljr.avi ++e1c4c96c74de3435d0f9f6118c5ed9b5 *./tests/data/cljr.vsynth1.out.yuv ++stddev: 30.53 PSNR: 18.43 MAXDIFF: 225 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dnxhd_1080i xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dnxhd_1080i +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dnxhd_1080i 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dnxhd_1080i 2012-05-14 14:08:55.789369265 +0200 +@@ -1,4 +1,4 @@ +-8a814d4056ca2810a8ed0bad3b70f358 *./tests/data/vsynth1/dnxhd-1080i.mov +-3031875 ./tests/data/vsynth1/dnxhd-1080i.mov ++027c985483caab9397592bf27477dce1 *./tests/data/vsynth1/dnxhd-1080i.mov ++3031911 ./tests/data/vsynth1/dnxhd-1080i.mov + 0c651e840f860592f0d5b66030d9fa32 *./tests/data/dnxhd_1080i.vsynth1.out.yuv + stddev: 6.29 PSNR: 32.15 MAXDIFF: 64 bytes: 760320/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dnxhd_720p_10bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dnxhd_720p_10bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dnxhd_720p_10bit 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dnxhd_720p_10bit 2012-05-14 14:08:55.789369265 +0200 +@@ -0,0 +1,4 @@ ++b5e24a055af02edec8674333260214fd *./tests/data/vsynth1/dnxhd-720p-10bit.dnxhd ++ 2293760 ./tests/data/vsynth1/dnxhd-720p-10bit.dnxhd ++4466ff3d73d01bbe75ea25001d379b63 *./tests/data/dnxhd_720p_10bit.vsynth1.out.yuv ++stddev: 6.27 PSNR: 32.18 MAXDIFF: 64 bytes: 760320/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv 2012-05-14 14:08:55.790369285 +0200 +@@ -1,8 +1,4 @@ +-27ade3031b17214cf81c19cbf70f37d7 *./tests/data/vsynth1/dv.dv ++4d572f758b55a1756adf9f54132f3b9e *./tests/data/vsynth1/dv.dv + 7200000 ./tests/data/vsynth1/dv.dv + 02ac7cdeab91d4d5621e7ce96dddc498 *./tests/data/dv.vsynth1.out.yuv +-stddev: 6.90 PSNR: 31.34 MAXDIFF: 76 bytes: 7603200/ 7603200 +-bd67f2431db160d4bb6dcd791cea6efd *./tests/data/vsynth1/dv411.dv +-7200000 ./tests/data/vsynth1/dv411.dv +-b6640a3a572353f51284acb746eb00c4 *./tests/data/dv.vsynth1.out.yuv +-stddev: 30.76 PSNR: 18.37 MAXDIFF: 205 bytes: 7603200/ 7603200 ++stddev: 6.90 PSNR: 31.34 MAXDIFF: 76 bytes: 7603200/ 7603200 +\ Kein Zeilenumbruch am Dateiende. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv_411 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv_411 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv_411 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv_411 2012-05-14 14:08:55.791369305 +0200 +@@ -0,0 +1,4 @@ ++f179899efba432c6f01149c36c709092 *./tests/data/vsynth1/dv411.dv ++7200000 ./tests/data/vsynth1/dv411.dv ++b6640a3a572353f51284acb746eb00c4 *./tests/data/dv_411.vsynth1.out.yuv ++stddev: 30.76 PSNR: 18.37 MAXDIFF: 205 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv50 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv50 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/dv50 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/dv50 2012-05-14 14:08:55.791369305 +0200 +@@ -1,4 +1,4 @@ +-26dba84f0ea895b914ef5b333d8394ac *./tests/data/vsynth1/dv50.dv ++a193c5f92bf6e74c604e759d5f4f0f94 *./tests/data/vsynth1/dv50.dv + 14400000 ./tests/data/vsynth1/dv50.dv + a2ff093e93ffed10f730fa21df02fc50 *./tests/data/dv50.vsynth1.out.yuv + stddev: 1.72 PSNR: 43.38 MAXDIFF: 29 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/error xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/error +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/error 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/error 2012-05-14 14:08:55.791369305 +0200 +@@ -1,4 +1,4 @@ + 7416dfd319f04044d4575dc9d1b406e1 *./tests/data/vsynth1/error-mpeg4-adv.avi + 756836 ./tests/data/vsynth1/error-mpeg4-adv.avi +-ef8bfcd6e0883daba95d0f32486ebe2d *./tests/data/error.vsynth1.out.yuv +-stddev: 18.05 PSNR: 23.00 MAXDIFF: 245 bytes: 7603200/ 7603200 ++79e94ba32b37759397362cbcb479d4d3 *./tests/data/error.vsynth1.out.yuv ++stddev: 18.36 PSNR: 22.85 MAXDIFF: 243 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/flashsv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/flashsv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/flashsv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/flashsv 2012-05-14 14:08:55.792369325 +0200 +@@ -1,4 +1,4 @@ + 97894502b4cb57aca1105b6333f72dae *./tests/data/vsynth1/flashsv.flv + 14681925 ./tests/data/vsynth1/flashsv.flv +-947cb24ec45a453348ae6fe3fa278071 *./tests/data/flashsv.vsynth1.out.yuv +-stddev: 2.85 PSNR: 39.03 MAXDIFF: 49 bytes: 7603200/ 7603200 ++791e1fb999deb2e4156e2286d48c4ed1 *./tests/data/flashsv.vsynth1.out.yuv ++stddev: 2.84 PSNR: 39.04 MAXDIFF: 49 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/flashsv2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/flashsv2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/flashsv2 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/flashsv2 2012-05-14 14:08:55.793369346 +0200 +@@ -0,0 +1,6 @@ ++ec13d68cbce263f589fe79bcd2e98364 *./tests/data/vsynth1/flashsv2.flv ++8406137 ./tests/data/vsynth1/flashsv2.flv ++ed28c0021768629b2675e72bf1632426 *./tests/data/vsynth1/flashsv2I.flv ++8755723 ./tests/data/vsynth1/flashsv2I.flv ++efa88d09115a2e947eff00ee435ba3f3 *./tests/data/flashsv2.vsynth1.out.yuv ++stddev: 3.47 PSNR: 37.31 MAXDIFF: 49 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/huffyuv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/huffyuv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/huffyuv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/huffyuv 2012-05-14 14:08:55.793369346 +0200 +@@ -1,4 +1,4 @@ +-ace2536fa169d835d0fb332abde28d51 *./tests/data/vsynth1/huffyuv.avi ++f5f2e109af0612694ff3cd6464063e82 *./tests/data/vsynth1/huffyuv.avi + 7933800 ./tests/data/vsynth1/huffyuv.avi + c5ccac874dbf808e9088bc3107860042 *./tests/data/huffyuv.vsynth1.out.yuv + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/jpeg2000 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/jpeg2000 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/jpeg2000 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/jpeg2000 2012-05-14 14:08:55.794369366 +0200 +@@ -0,0 +1,4 @@ ++8da8ef50cccb9996f4bebbc585c4edb4 *./tests/data/vsynth1/jpeg2000.avi ++2306914 ./tests/data/vsynth1/jpeg2000.avi ++ee9b245b3b07eed90bc6f2147bbd916c *./tests/data/jpeg2000.vsynth1.out.yuv ++stddev: 5.47 PSNR: 33.37 MAXDIFF: 64 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/jpegls xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/jpegls +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/jpegls 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/jpegls 2012-05-14 14:08:55.794369366 +0200 +@@ -1,4 +1,4 @@ + 519e26bb1ac0f3db8f90b36537f2f760 *./tests/data/vsynth1/jpegls.avi + 9089812 ./tests/data/vsynth1/jpegls.avi +-947cb24ec45a453348ae6fe3fa278071 *./tests/data/jpegls.vsynth1.out.yuv +-stddev: 2.85 PSNR: 39.03 MAXDIFF: 49 bytes: 7603200/ 7603200 ++791e1fb999deb2e4156e2286d48c4ed1 *./tests/data/jpegls.vsynth1.out.yuv ++stddev: 2.84 PSNR: 39.04 MAXDIFF: 49 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2 2012-05-14 14:08:55.795369386 +0200 +@@ -2,19 +2,3 @@ + 728044 ./tests/data/vsynth1/mpeg2.mpg + b41ca49c1a02e66ce64d262e2cdaec15 *./tests/data/mpeg2.vsynth1.out.yuv + stddev: 7.65 PSNR: 30.45 MAXDIFF: 84 bytes: 7603200/ 7603200 +-8f6b20714918e6443e0c03716ed06f0d *./tests/data/vsynth1/mpeg2ivlc-qprd.mpg +-783552 ./tests/data/vsynth1/mpeg2ivlc-qprd.mpg +-98eb9da15f880978e7f2ee1e7ce476ef *./tests/data/mpeg2.vsynth1.out.yuv +-stddev: 10.07 PSNR: 28.06 MAXDIFF: 165 bytes: 7603200/ 7603200 +-af0cb75451aaa807beb5102707a98823 *./tests/data/vsynth1/mpeg2_422.mpg +-728200 ./tests/data/vsynth1/mpeg2_422.mpg +-29b518282493203e83b27a939795dc3a *./tests/data/mpeg2.vsynth1.out.yuv +-stddev: 63.33 PSNR: 12.10 MAXDIFF: 242 bytes: 10137600/ 7603200 +-4c067397b504d65532d7779cd36f3f88 *./tests/data/vsynth1/mpeg2.mpg +-725668 ./tests/data/vsynth1/mpeg2.mpg +-9f7b065f98d57cdecf90e6f7a2524eb5 *./tests/data/mpeg2.vsynth1.out.yuv +-stddev: 7.65 PSNR: 30.45 MAXDIFF: 81 bytes: 7603200/ 7603200 +-ec3f6713c88a2b41f6c369fd64341077 *./tests/data/vsynth1/mpeg2i.mpg +-737473 ./tests/data/vsynth1/mpeg2i.mpg +-97615390fdd69abfcbc7e02df863a7d2 *./tests/data/mpeg2.vsynth1.out.yuv +-stddev: 7.67 PSNR: 30.43 MAXDIFF: 84 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_422 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_422 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_422 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_422 2012-05-14 14:08:55.795369386 +0200 +@@ -0,0 +1,4 @@ ++af0cb75451aaa807beb5102707a98823 *./tests/data/vsynth1/mpeg2_422.mpg ++728200 ./tests/data/vsynth1/mpeg2_422.mpg ++29b518282493203e83b27a939795dc3a *./tests/data/mpeg2_422.vsynth1.out.yuv ++stddev: 63.33 PSNR: 12.10 MAXDIFF: 242 bytes: 10137600/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_idct_int xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_idct_int +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_idct_int 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_idct_int 2012-05-14 14:08:55.796369406 +0200 +@@ -0,0 +1,4 @@ ++4c067397b504d65532d7779cd36f3f88 *./tests/data/vsynth1/mpeg2_idct_int.mpg ++725668 ./tests/data/vsynth1/mpeg2_idct_int.mpg ++9f7b065f98d57cdecf90e6f7a2524eb5 *./tests/data/mpeg2_idct_int.vsynth1.out.yuv ++stddev: 7.65 PSNR: 30.45 MAXDIFF: 81 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ilace xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ilace +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ilace 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ilace 2012-05-14 14:08:55.796369406 +0200 +@@ -0,0 +1,4 @@ ++ec3f6713c88a2b41f6c369fd64341077 *./tests/data/vsynth1/mpeg2i.mpg ++737473 ./tests/data/vsynth1/mpeg2i.mpg ++97615390fdd69abfcbc7e02df863a7d2 *./tests/data/mpeg2_ilace.vsynth1.out.yuv ++stddev: 7.67 PSNR: 30.43 MAXDIFF: 84 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ivlc_qprd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ivlc_qprd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ivlc_qprd 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2_ivlc_qprd 2012-05-14 14:08:55.797369426 +0200 +@@ -0,0 +1,4 @@ ++8f6b20714918e6443e0c03716ed06f0d *./tests/data/vsynth1/mpeg2ivlc-qprd.mpg ++783552 ./tests/data/vsynth1/mpeg2ivlc-qprd.mpg ++98eb9da15f880978e7f2ee1e7ce476ef *./tests/data/mpeg2_ivlc_qprd.vsynth1.out.yuv ++stddev: 10.07 PSNR: 28.06 MAXDIFF: 165 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread 2012-05-14 14:08:55.797369426 +0200 +@@ -1,12 +1,4 @@ + ecd183706688bd977c9994c3d1b23d61 *./tests/data/vsynth1/mpeg2thread.mpg + 801313 ./tests/data/vsynth1/mpeg2thread.mpg + d1658911ca83f5616c1d32abc40750de *./tests/data/mpeg2thread.vsynth1.out.yuv +-stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200 +-23d600b026222253c2340e23300a4c02 *./tests/data/vsynth1/mpeg2threadivlc.mpg +-791773 ./tests/data/vsynth1/mpeg2threadivlc.mpg +-d1658911ca83f5616c1d32abc40750de *./tests/data/mpeg2thread.vsynth1.out.yuv +-stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200 +-d119fe917dd81d1ff758b4ce684a8d9d *./tests/data/vsynth1/mpeg2reuse.mpg +-2074636 ./tests/data/vsynth1/mpeg2reuse.mpg +-92ced6afe8c02304943c400cce51a5f4 *./tests/data/mpeg2thread.vsynth1.out.yuv +-stddev: 7.66 PSNR: 30.44 MAXDIFF: 111 bytes: 7603200/ 7603200 ++stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200 +\ Kein Zeilenumbruch am Dateiende. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread_ilace xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread_ilace +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread_ilace 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg2thread_ilace 2012-05-14 14:08:55.798369446 +0200 +@@ -0,0 +1,8 @@ ++23d600b026222253c2340e23300a4c02 *./tests/data/vsynth1/mpeg2threadivlc.mpg ++791773 ./tests/data/vsynth1/mpeg2threadivlc.mpg ++d1658911ca83f5616c1d32abc40750de *./tests/data/mpeg2thread_ilace.vsynth1.out.yuv ++stddev: 7.63 PSNR: 30.48 MAXDIFF: 110 bytes: 7603200/ 7603200 ++d119fe917dd81d1ff758b4ce684a8d9d *./tests/data/vsynth1/mpeg2reuse.mpg ++2074636 ./tests/data/vsynth1/mpeg2reuse.mpg ++92ced6afe8c02304943c400cce51a5f4 *./tests/data/mpeg2thread_ilace.vsynth1.out.yuv ++stddev: 7.66 PSNR: 30.44 MAXDIFF: 111 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4 2012-05-14 14:08:55.798369446 +0200 +@@ -1,4 +1,4 @@ +-fd83f2ef5887a62b4d755d7cb5f0ac59 *./tests/data/vsynth1/odivx.mp4 +-540144 ./tests/data/vsynth1/odivx.mp4 ++6ea715a2de70af8d37128ce643e4cca0 *./tests/data/vsynth1/odivx.mp4 ++539996 ./tests/data/vsynth1/odivx.mp4 + 8828a375448dc5c2215163ba70656f89 *./tests/data/mpeg4.vsynth1.out.yuv + stddev: 7.97 PSNR: 30.10 MAXDIFF: 105 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_adap xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_adap +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_adap 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_adap 2012-05-14 14:08:55.799369466 +0200 +@@ -0,0 +1,4 @@ ++2d870c0da9ab2231ab5fc06981e70399 *./tests/data/vsynth1/mpeg4-adap.avi ++403456 ./tests/data/vsynth1/mpeg4-adap.avi ++fa2049396479b5f170aa764fed5b2a31 *./tests/data/mpeg4_adap.vsynth1.out.yuv ++stddev: 14.05 PSNR: 25.17 MAXDIFF: 184 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4adv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4adv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4adv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4adv 2012-05-14 14:08:55.800369486 +0200 +@@ -2,15 +2,3 @@ + 589716 ./tests/data/vsynth1/mpeg4-adv.avi + f8b226876b1b2c0b98fd6928fd9adbd8 *./tests/data/mpeg4adv.vsynth1.out.yuv + stddev: 6.98 PSNR: 31.25 MAXDIFF: 84 bytes: 7603200/ 7603200 +-d6b7e724a6ad66ab5e4c5a499218b40d *./tests/data/vsynth1/mpeg4-qprd.avi +-710944 ./tests/data/vsynth1/mpeg4-qprd.avi +-e65f4c7f343fe2bad1cac44b7da5f7c4 *./tests/data/mpeg4adv.vsynth1.out.yuv +-stddev: 9.79 PSNR: 28.31 MAXDIFF: 176 bytes: 7603200/ 7603200 +-2d870c0da9ab2231ab5fc06981e70399 *./tests/data/vsynth1/mpeg4-adap.avi +-403456 ./tests/data/vsynth1/mpeg4-adap.avi +-fa2049396479b5f170aa764fed5b2a31 *./tests/data/mpeg4adv.vsynth1.out.yuv +-stddev: 14.05 PSNR: 25.17 MAXDIFF: 184 bytes: 7603200/ 7603200 +-3bf17c3d04f52988386ce106a2a58976 *./tests/data/vsynth1/mpeg4-Q.avi +-860678 ./tests/data/vsynth1/mpeg4-Q.avi +-756928496245ecc701f79eebeec8e5e6 *./tests/data/mpeg4adv.vsynth1.out.yuv +-stddev: 5.63 PSNR: 33.12 MAXDIFF: 70 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qpel xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qpel +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qpel 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qpel 2012-05-14 14:08:55.799369466 +0200 +@@ -0,0 +1,4 @@ ++3bf17c3d04f52988386ce106a2a58976 *./tests/data/vsynth1/mpeg4-Q.avi ++860678 ./tests/data/vsynth1/mpeg4-Q.avi ++756928496245ecc701f79eebeec8e5e6 *./tests/data/mpeg4_qpel.vsynth1.out.yuv ++stddev: 5.63 PSNR: 33.12 MAXDIFF: 70 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qprd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qprd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qprd 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpeg4_qprd 2012-05-14 14:08:55.800369486 +0200 +@@ -0,0 +1,4 @@ ++d6b7e724a6ad66ab5e4c5a499218b40d *./tests/data/vsynth1/mpeg4-qprd.avi ++710944 ./tests/data/vsynth1/mpeg4-qprd.avi ++e65f4c7f343fe2bad1cac44b7da5f7c4 *./tests/data/mpeg4_qprd.vsynth1.out.yuv ++stddev: 9.79 PSNR: 28.31 MAXDIFF: 176 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpng xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpng +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/mpng 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/mpng 2012-05-14 14:08:55.801369507 +0200 +@@ -0,0 +1,4 @@ ++a8e7393fa534289eee9319ded7807f99 *./tests/data/vsynth1/mpng.avi ++12157242 ./tests/data/vsynth1/mpng.avi ++93695a27c24a61105076ca7b1f010bbd *./tests/data/mpng.vsynth1.out.yuv ++stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/msvideo1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/msvideo1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/msvideo1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/msvideo1 2012-05-14 14:08:55.801369507 +0200 +@@ -0,0 +1,4 @@ ++267a152a73cbc5ac4694a6e3b254be34 *./tests/data/vsynth1/msvideo1.avi ++2162264 ./tests/data/vsynth1/msvideo1.avi ++c0665fac1bd896b6fe7fe0eead805bd5 *./tests/data/msvideo1.vsynth1.out.yuv ++stddev: 11.80 PSNR: 26.69 MAXDIFF: 151 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/prores xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/prores +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/prores 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/prores 2012-05-14 14:08:55.801369507 +0200 +@@ -0,0 +1,4 @@ ++31159cc9d1693bc66ad7a3083c48bcc4 *./tests/data/vsynth1/prores.mov ++5022811 ./tests/data/vsynth1/prores.mov ++a2e2d1d45341a94ff994d1d92629f778 *./tests/data/prores.vsynth1.out.yuv ++stddev: 2.47 PSNR: 40.27 MAXDIFF: 31 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/qtrle xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/qtrle +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/qtrle 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/qtrle 2012-05-14 14:08:55.802369527 +0200 +@@ -1,4 +1,4 @@ +-3f070779d7deb54626515ac7f7002e63 *./tests/data/vsynth1/qtrle.mov +-387772 ./tests/data/vsynth1/qtrle.mov +-a3c2610e2c069c3ad22ec03da83f774f *./tests/data/qtrle.vsynth1.out.yuv +-stddev: 15.14 PSNR: 24.53 MAXDIFF: 174 bytes: 7603200/ 7603200 ++9c6ee876369fceac1ff2478a0225bc9b *./tests/data/vsynth1/qtrle.mov ++15263148 ./tests/data/vsynth1/qtrle.mov ++93695a27c24a61105076ca7b1f010bbd *./tests/data/qtrle.vsynth1.out.yuv ++stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/qtrlegray xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/qtrlegray +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/qtrlegray 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/qtrlegray 2012-05-14 14:08:55.802369527 +0200 +@@ -0,0 +1,4 @@ ++dfb185e38b3557eca0ead72d57ca48f8 *./tests/data/vsynth1/qtrlegray.mov ++5113284 ./tests/data/vsynth1/qtrlegray.mov ++29def4aed035ed65d3a89f7d382fccbe *./tests/data/qtrlegray.vsynth1.out.yuv ++stddev: 25.95 PSNR: 19.85 MAXDIFF: 122 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/rgb xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/rgb +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/rgb 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/rgb 2012-05-14 14:08:55.803369547 +0200 +@@ -1,4 +1,4 @@ + 05f0719cb52486d9a4beb9cfae3f2571 *./tests/data/vsynth1/rgb.avi + 15213260 ./tests/data/vsynth1/rgb.avi +-243325fb2cae1a9245efd49aff936327 *./tests/data/rgb.vsynth1.out.yuv +-stddev: 3.42 PSNR: 37.43 MAXDIFF: 48 bytes: 7603200/ 7603200 ++93695a27c24a61105076ca7b1f010bbd *./tests/data/rgb.vsynth1.out.yuv ++stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/svq1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/svq1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/svq1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/svq1 2012-05-14 14:08:55.803369547 +0200 +@@ -1,4 +1,4 @@ +-595fc4e38734521356b60e67b813f0fa *./tests/data/vsynth1/svq1.mov +-1334367 ./tests/data/vsynth1/svq1.mov ++4654e7af0d4aa58c3db1eb145e278038 *./tests/data/vsynth1/svq1.mov ++1334223 ./tests/data/vsynth1/svq1.mov + 9cc35c54b2c77d36bd7e308b393c1f81 *./tests/data/svq1.vsynth1.out.yuv + stddev: 9.58 PSNR: 28.50 MAXDIFF: 210 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/v210 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/v210 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/v210 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/v210 2012-05-14 14:08:55.804369567 +0200 +@@ -0,0 +1,4 @@ ++dd6c870a2a52c9e75ce61c3670e710e7 *./tests/data/vsynth1/v210.avi ++14752460 ./tests/data/vsynth1/v210.avi ++50973792d3f1abe04a51ee0121f077f2 *./tests/data/v210.vsynth1.out.yuv ++stddev: 1.85 PSNR: 42.78 MAXDIFF: 29 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/vref xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/vref +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/vref 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/vref 2012-05-14 14:08:55.804369567 +0200 +@@ -0,0 +1,2 @@ ++c5ccac874dbf808e9088bc3107860042 *./tests/data/vsynth1.ref.yuv ++7603200 ./tests/data/vsynth1.ref.yuv +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/yuv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/yuv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/yuv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/yuv 2012-05-14 14:08:55.805369587 +0200 +@@ -1,4 +1,4 @@ +-aa6b9e862aebcf8902a6d770e7729d59 *./tests/data/vsynth1/yuv.avi ++eaa66c3b27a2602e882befe154a8b119 *./tests/data/vsynth1/yuv.avi + 7610060 ./tests/data/vsynth1/yuv.avi + c5ccac874dbf808e9088bc3107860042 *./tests/data/yuv.vsynth1.out.yuv + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/zlib xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/zlib +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/zlib 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/zlib 2012-05-14 14:08:55.806369607 +0200 +@@ -0,0 +1,4 @@ ++fe4983e551b48dc555e1aeaf628f649f *./tests/data/vsynth1/zlib.avi ++12108644 ./tests/data/vsynth1/zlib.avi ++93695a27c24a61105076ca7b1f010bbd *./tests/data/zlib.vsynth1.out.yuv ++stddev: 3.42 PSNR: 37.44 MAXDIFF: 48 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/zmbv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/zmbv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth1/zmbv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth1/zmbv 2012-05-14 14:08:55.806369607 +0200 +@@ -0,0 +1,3 @@ ++5112508 ./tests/data/vsynth1/zmbv.avi ++cfbec364e41d70c9b177435b5655d8af *./tests/data/zmbv.vsynth1.out.yuv ++stddev: 46.47 PSNR: 14.79 MAXDIFF: 129 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/amv/vsynth2-amv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/amv/vsynth2-amv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/amv/vsynth2-amv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/amv/vsynth2-amv 2012-05-14 14:08:55.807369627 +0200 +@@ -0,0 +1,4 @@ ++816a4226fe7640a835139f8a44286a12 *./tests/data/vsynth2/amv.avi ++761976 ./tests/data/vsynth2/amv.avi ++f1a9e46e77934d4cc5ca9f927662c4be *./tests/data/amv.vsynth2.out.yuv ++stddev: 8.14 PSNR: 29.91 MAXDIFF: 66 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/cljr xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/cljr +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/cljr 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/cljr 2012-05-14 14:08:55.807369627 +0200 +@@ -0,0 +1,4 @@ ++fdc1926e0a599de94513f0a3472b598f *./tests/data/vsynth2/cljr.avi ++ 5075660 ./tests/data/vsynth2/cljr.avi ++7df03229ee6361ea11a0d83d4926cb10 *./tests/data/cljr.vsynth2.out.yuv ++stddev: 10.30 PSNR: 27.87 MAXDIFF: 65 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dnxhd_1080i xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dnxhd_1080i +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dnxhd_1080i 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dnxhd_1080i 2012-05-14 14:08:55.808369647 +0200 +@@ -1,4 +1,4 @@ +-c81c7cfb375f61b7ab9b60fa340fe52a *./tests/data/vsynth2/dnxhd-1080i.mov +-3031875 ./tests/data/vsynth2/dnxhd-1080i.mov ++204e80f2e406ada90fca596ab2810b3e *./tests/data/vsynth2/dnxhd-1080i.mov ++3031911 ./tests/data/vsynth2/dnxhd-1080i.mov + 3c559af629ae0a8fb1a9a0e4b4da7733 *./tests/data/dnxhd_1080i.vsynth2.out.yuv + stddev: 1.31 PSNR: 45.77 MAXDIFF: 23 bytes: 760320/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dnxhd_720p_10bit xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dnxhd_720p_10bit +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dnxhd_720p_10bit 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dnxhd_720p_10bit 2012-05-14 14:08:55.808369647 +0200 +@@ -0,0 +1,4 @@ ++4b57da2c0c1280469ff3579f7151c227 *./tests/data/vsynth2/dnxhd-720p-10bit.dnxhd ++ 2293760 ./tests/data/vsynth2/dnxhd-720p-10bit.dnxhd ++31a6aa8b8702e85fa3b48e73f035c4e4 *./tests/data/dnxhd_720p_10bit.vsynth2.out.yuv ++stddev: 1.35 PSNR: 45.46 MAXDIFF: 23 bytes: 760320/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv 2012-05-14 14:08:55.809369668 +0200 +@@ -1,8 +1,4 @@ +-bfa766f89bfeabc0ae1044f3954bed52 *./tests/data/vsynth2/dv.dv ++85b8d55b0b68bb3fc2e90babb580f9b7 *./tests/data/vsynth2/dv.dv + 7200000 ./tests/data/vsynth2/dv.dv + 7ec62bd3350a6848364669e6e1e4b9cc *./tests/data/dv.vsynth2.out.yuv +-stddev: 1.71 PSNR: 43.47 MAXDIFF: 33 bytes: 7603200/ 7603200 +-00a9d8683ac6826af41bcf7223fb0389 *./tests/data/vsynth2/dv411.dv +-7200000 ./tests/data/vsynth2/dv411.dv +-7f9fa421028aabb11eaf4c6513a5a843 *./tests/data/dv.vsynth2.out.yuv +-stddev: 10.09 PSNR: 28.05 MAXDIFF: 60 bytes: 7603200/ 7603200 ++stddev: 1.71 PSNR: 43.47 MAXDIFF: 33 bytes: 7603200/ 7603200 +\ Kein Zeilenumbruch am Dateiende. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv_411 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv_411 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv_411 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv_411 2012-05-14 14:08:55.810369688 +0200 +@@ -0,0 +1,4 @@ ++e428508f400327aeb96969c08fb9e1b5 *./tests/data/vsynth2/dv411.dv ++7200000 ./tests/data/vsynth2/dv411.dv ++7f9fa421028aabb11eaf4c6513a5a843 *./tests/data/dv_411.vsynth2.out.yuv ++stddev: 10.09 PSNR: 28.05 MAXDIFF: 60 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv50 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv50 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/dv50 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/dv50 2012-05-14 14:08:55.809369668 +0200 +@@ -1,4 +1,4 @@ +-61e31c79e8949b25c849753a0785b0d7 *./tests/data/vsynth2/dv50.dv ++0032a07167199e6f49e07fa7ed4d5f62 *./tests/data/vsynth2/dv50.dv + 14400000 ./tests/data/vsynth2/dv50.dv + af3f2dd5ab62c1a1d98b07d4aeb6852f *./tests/data/dv50.vsynth2.out.yuv + stddev: 0.82 PSNR: 49.82 MAXDIFF: 12 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/error xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/error +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/error 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/error 2012-05-14 14:08:55.810369688 +0200 +@@ -1,4 +1,4 @@ + 90e65096aa9ebafa3fe3f44a5a47cdc4 *./tests/data/vsynth2/error-mpeg4-adv.avi + 176588 ./tests/data/vsynth2/error-mpeg4-adv.avi +-9fe1082179f80179439953c7397a46ef *./tests/data/error.vsynth2.out.yuv +-stddev: 9.00 PSNR: 29.04 MAXDIFF: 168 bytes: 7603200/ 7603200 ++96baa9e4c24c837a3ba5abd8dd2cdd30 *./tests/data/error.vsynth2.out.yuv ++stddev: 8.98 PSNR: 29.06 MAXDIFF: 184 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/flashsv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/flashsv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/flashsv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/flashsv 2012-05-14 14:08:55.811369708 +0200 +@@ -1,4 +1,4 @@ + 0667077971e0cb63b5f49c580006e90e *./tests/data/vsynth2/flashsv.flv + 12368953 ./tests/data/vsynth2/flashsv.flv +-592b3321994e26a990deb3a0a1415de9 *./tests/data/flashsv.vsynth2.out.yuv +-stddev: 0.65 PSNR: 51.84 MAXDIFF: 14 bytes: 7603200/ 7603200 ++3a984506f1ebfc9fb73b6814cab201cc *./tests/data/flashsv.vsynth2.out.yuv ++stddev: 0.66 PSNR: 51.73 MAXDIFF: 14 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/flashsv2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/flashsv2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/flashsv2 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/flashsv2 2012-05-14 14:08:55.811369708 +0200 +@@ -0,0 +1,6 @@ ++6fbb1cf84d473a93035047c3a3e344ff *./tests/data/vsynth2/flashsv2.flv ++4814443 ./tests/data/vsynth2/flashsv2.flv ++d5a22183d9fe670174340a8a1847e52a *./tests/data/vsynth2/flashsv2I.flv ++5037122 ./tests/data/vsynth2/flashsv2I.flv ++8f63e24049ba1789a7f8353c695a3d99 *./tests/data/flashsv2.vsynth2.out.yuv ++stddev: 2.39 PSNR: 40.55 MAXDIFF: 21 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/huffyuv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/huffyuv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/huffyuv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/huffyuv 2012-05-14 14:08:55.812369728 +0200 +@@ -1,4 +1,4 @@ +-56cd44907a48990e06bd065e189ff461 *./tests/data/vsynth2/huffyuv.avi ++ed66182be0d515e8b6cb970ad63162da *./tests/data/vsynth2/huffyuv.avi + 6455232 ./tests/data/vsynth2/huffyuv.avi + dde5895817ad9d219f79a52d0bdfb001 *./tests/data/huffyuv.vsynth2.out.yuv + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/jpeg2000 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/jpeg2000 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/jpeg2000 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/jpeg2000 2012-05-14 14:08:55.812369728 +0200 +@@ -0,0 +1,4 @@ ++b30dc1851c0fb37726d977ec1d5ad527 *./tests/data/vsynth2/jpeg2000.avi ++1151156 ./tests/data/vsynth2/jpeg2000.avi ++ec5218eec33a021945c28c72093382a5 *./tests/data/jpeg2000.vsynth2.out.yuv ++stddev: 4.54 PSNR: 34.99 MAXDIFF: 61 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/jpegls xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/jpegls +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/jpegls 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/jpegls 2012-05-14 14:08:55.813369748 +0200 +@@ -1,4 +1,4 @@ + 4fc53937f048c900ae6d50fda9dba206 *./tests/data/vsynth2/jpegls.avi + 8334630 ./tests/data/vsynth2/jpegls.avi +-592b3321994e26a990deb3a0a1415de9 *./tests/data/jpegls.vsynth2.out.yuv +-stddev: 0.65 PSNR: 51.84 MAXDIFF: 14 bytes: 7603200/ 7603200 ++3a984506f1ebfc9fb73b6814cab201cc *./tests/data/jpegls.vsynth2.out.yuv ++stddev: 0.66 PSNR: 51.73 MAXDIFF: 14 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2 2012-05-14 14:08:55.813369748 +0200 +@@ -2,19 +2,3 @@ + 198667 ./tests/data/vsynth2/mpeg2.mpg + b7cae8a1f751b821cddcbe4d5dbc518c *./tests/data/mpeg2.vsynth2.out.yuv + stddev: 4.96 PSNR: 34.20 MAXDIFF: 59 bytes: 7603200/ 7603200 +-1ba5efeb53fab7b4b71edc96d86f6c91 *./tests/data/vsynth2/mpeg2ivlc-qprd.mpg +-244694 ./tests/data/vsynth2/mpeg2ivlc-qprd.mpg +-b26e21599dee48a174bdbc40b2817e55 *./tests/data/mpeg2.vsynth2.out.yuv +-stddev: 4.15 PSNR: 35.76 MAXDIFF: 74 bytes: 7603200/ 7603200 +-2c8e33c2d2efab86fc16a195f6877682 *./tests/data/vsynth2/mpeg2_422.mpg +-356124 ./tests/data/vsynth2/mpeg2_422.mpg +-de44597c6c470f3e7019b31245a3ff69 *./tests/data/mpeg2.vsynth2.out.yuv +-stddev: 54.55 PSNR: 13.39 MAXDIFF: 201 bytes: 10137600/ 7603200 +-f979bcca866e6e4cad5dc6cb06e56cfb *./tests/data/vsynth2/mpeg2.mpg +-198041 ./tests/data/vsynth2/mpeg2.mpg +-f6d9bf24ff8676a7f6076c05cd2c81a3 *./tests/data/mpeg2.vsynth2.out.yuv +-stddev: 4.97 PSNR: 34.19 MAXDIFF: 58 bytes: 7603200/ 7603200 +-f90197a8b6e62ae25f82625337f27240 *./tests/data/vsynth2/mpeg2i.mpg +-204579 ./tests/data/vsynth2/mpeg2i.mpg +-ea5057b60146c06d40449cdfc686bf13 *./tests/data/mpeg2.vsynth2.out.yuv +-stddev: 4.98 PSNR: 34.18 MAXDIFF: 65 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_422 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_422 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_422 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_422 2012-05-14 14:08:55.814369768 +0200 +@@ -0,0 +1,4 @@ ++2c8e33c2d2efab86fc16a195f6877682 *./tests/data/vsynth2/mpeg2_422.mpg ++356124 ./tests/data/vsynth2/mpeg2_422.mpg ++de44597c6c470f3e7019b31245a3ff69 *./tests/data/mpeg2_422.vsynth2.out.yuv ++stddev: 54.55 PSNR: 13.39 MAXDIFF: 201 bytes: 10137600/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_idct_int xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_idct_int +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_idct_int 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_idct_int 2012-05-14 14:08:55.814369768 +0200 +@@ -0,0 +1,4 @@ ++f979bcca866e6e4cad5dc6cb06e56cfb *./tests/data/vsynth2/mpeg2_idct_int.mpg ++198041 ./tests/data/vsynth2/mpeg2_idct_int.mpg ++f6d9bf24ff8676a7f6076c05cd2c81a3 *./tests/data/mpeg2_idct_int.vsynth2.out.yuv ++stddev: 4.97 PSNR: 34.19 MAXDIFF: 58 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ilace xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ilace +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ilace 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ilace 2012-05-14 14:08:55.814369768 +0200 +@@ -0,0 +1,4 @@ ++f90197a8b6e62ae25f82625337f27240 *./tests/data/vsynth2/mpeg2i.mpg ++204579 ./tests/data/vsynth2/mpeg2i.mpg ++ea5057b60146c06d40449cdfc686bf13 *./tests/data/mpeg2_ilace.vsynth2.out.yuv ++stddev: 4.98 PSNR: 34.18 MAXDIFF: 65 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ivlc_qprd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ivlc_qprd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ivlc_qprd 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2_ivlc_qprd 2012-05-14 14:08:55.815369788 +0200 +@@ -0,0 +1,4 @@ ++1ba5efeb53fab7b4b71edc96d86f6c91 *./tests/data/vsynth2/mpeg2ivlc-qprd.mpg ++244694 ./tests/data/vsynth2/mpeg2ivlc-qprd.mpg ++b26e21599dee48a174bdbc40b2817e55 *./tests/data/mpeg2_ivlc_qprd.vsynth2.out.yuv ++stddev: 4.15 PSNR: 35.76 MAXDIFF: 74 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread 2012-05-14 14:08:55.816369808 +0200 +@@ -1,12 +1,4 @@ + 889c754a42d7689b228853e1ece6d345 *./tests/data/vsynth2/mpeg2thread.mpg + 179650 ./tests/data/vsynth2/mpeg2thread.mpg + 8c6a7ed2eb73bd18fd2bb9829464100d *./tests/data/mpeg2thread.vsynth2.out.yuv +-stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200 +-10b900e32809758857c596d56746e00e *./tests/data/vsynth2/mpeg2threadivlc.mpg +-178801 ./tests/data/vsynth2/mpeg2threadivlc.mpg +-8c6a7ed2eb73bd18fd2bb9829464100d *./tests/data/mpeg2thread.vsynth2.out.yuv +-stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200 +-864d6bf2982a61e510003a518be65a2d *./tests/data/vsynth2/mpeg2reuse.mpg +-383419 ./tests/data/vsynth2/mpeg2reuse.mpg +-bb20fa080cfd2b0a687ea7376ff4f902 *./tests/data/mpeg2thread.vsynth2.out.yuv +-stddev: 4.73 PSNR: 34.63 MAXDIFF: 72 bytes: 7603200/ 7603200 ++stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200 +\ Kein Zeilenumbruch am Dateiende. +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread_ilace xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread_ilace +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread_ilace 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg2thread_ilace 2012-05-14 14:08:55.816369808 +0200 +@@ -0,0 +1,8 @@ ++10b900e32809758857c596d56746e00e *./tests/data/vsynth2/mpeg2threadivlc.mpg ++178801 ./tests/data/vsynth2/mpeg2threadivlc.mpg ++8c6a7ed2eb73bd18fd2bb9829464100d *./tests/data/mpeg2thread_ilace.vsynth2.out.yuv ++stddev: 4.72 PSNR: 34.65 MAXDIFF: 72 bytes: 7603200/ 7603200 ++864d6bf2982a61e510003a518be65a2d *./tests/data/vsynth2/mpeg2reuse.mpg ++383419 ./tests/data/vsynth2/mpeg2reuse.mpg ++bb20fa080cfd2b0a687ea7376ff4f902 *./tests/data/mpeg2thread_ilace.vsynth2.out.yuv ++stddev: 4.73 PSNR: 34.63 MAXDIFF: 72 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4 2012-05-14 14:08:55.817369828 +0200 +@@ -1,4 +1,4 @@ +-47de227982e77830a2db278214a08773 *./tests/data/vsynth2/odivx.mp4 +-119797 ./tests/data/vsynth2/odivx.mp4 ++051ff85797971b9047723044eaec07be *./tests/data/vsynth2/odivx.mp4 ++119649 ./tests/data/vsynth2/odivx.mp4 + 90a3577850239083a9042bef33c50e85 *./tests/data/mpeg4.vsynth2.out.yuv + stddev: 5.34 PSNR: 33.57 MAXDIFF: 83 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_adap xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_adap +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_adap 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_adap 2012-05-14 14:08:55.817369828 +0200 +@@ -0,0 +1,4 @@ ++547e1849dcf910935ff6383ca49e5706 *./tests/data/vsynth2/mpeg4-adap.avi ++198510 ./tests/data/vsynth2/mpeg4-adap.avi ++4affb83f6adc94f31024b4f9e0168945 *./tests/data/mpeg4_adap.vsynth2.out.yuv ++stddev: 3.75 PSNR: 36.65 MAXDIFF: 71 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4adv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4adv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4adv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4adv 2012-05-14 14:08:55.819369870 +0200 +@@ -2,15 +2,3 @@ + 141546 ./tests/data/vsynth2/mpeg4-adv.avi + 3f3a21e9db85a9c0f7022f557a5374c1 *./tests/data/mpeg4adv.vsynth2.out.yuv + stddev: 4.94 PSNR: 34.25 MAXDIFF: 69 bytes: 7603200/ 7603200 +-fd5ab0f55dbc959316e32923e86290df *./tests/data/vsynth2/mpeg4-qprd.avi +-231458 ./tests/data/vsynth2/mpeg4-qprd.avi +-de8a883865e2dff7a51f66da6c48df48 *./tests/data/mpeg4adv.vsynth2.out.yuv +-stddev: 3.71 PSNR: 36.72 MAXDIFF: 61 bytes: 7603200/ 7603200 +-547e1849dcf910935ff6383ca49e5706 *./tests/data/vsynth2/mpeg4-adap.avi +-198510 ./tests/data/vsynth2/mpeg4-adap.avi +-4affb83f6adc94f31024b4f9e0168945 *./tests/data/mpeg4adv.vsynth2.out.yuv +-stddev: 3.75 PSNR: 36.65 MAXDIFF: 71 bytes: 7603200/ 7603200 +-7680d2e7d34399dfdfb8a49cf1e10239 *./tests/data/vsynth2/mpeg4-Q.avi +-163688 ./tests/data/vsynth2/mpeg4-Q.avi +-26dc7c78955fa678fbf150e236eb5627 *./tests/data/mpeg4adv.vsynth2.out.yuv +-stddev: 3.97 PSNR: 36.14 MAXDIFF: 54 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qpel xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qpel +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qpel 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qpel 2012-05-14 14:08:55.818369849 +0200 +@@ -0,0 +1,4 @@ ++7680d2e7d34399dfdfb8a49cf1e10239 *./tests/data/vsynth2/mpeg4-Q.avi ++163688 ./tests/data/vsynth2/mpeg4-Q.avi ++26dc7c78955fa678fbf150e236eb5627 *./tests/data/mpeg4_qpel.vsynth2.out.yuv ++stddev: 3.97 PSNR: 36.14 MAXDIFF: 54 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qprd xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qprd +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qprd 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpeg4_qprd 2012-05-14 14:08:55.818369849 +0200 +@@ -0,0 +1,4 @@ ++fd5ab0f55dbc959316e32923e86290df *./tests/data/vsynth2/mpeg4-qprd.avi ++231458 ./tests/data/vsynth2/mpeg4-qprd.avi ++de8a883865e2dff7a51f66da6c48df48 *./tests/data/mpeg4_qprd.vsynth2.out.yuv ++stddev: 3.71 PSNR: 36.72 MAXDIFF: 61 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpng xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpng +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/mpng 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/mpng 2012-05-14 14:08:55.819369870 +0200 +@@ -0,0 +1,4 @@ ++198a3d67c56e1b5b12bdd3ffa67d8128 *./tests/data/vsynth2/mpng.avi ++12557288 ./tests/data/vsynth2/mpng.avi ++98d0e2854731472c5bf13d8638502d0a *./tests/data/mpng.vsynth2.out.yuv ++stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/msvideo1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/msvideo1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/msvideo1 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/msvideo1 2012-05-14 14:08:55.820369890 +0200 +@@ -0,0 +1,4 @@ ++5dddbbd6616d9be4bc0fd0c9650bd9e3 *./tests/data/vsynth2/msvideo1.avi ++1259308 ./tests/data/vsynth2/msvideo1.avi ++cd83ffcbc73573044e3aead3094229e5 *./tests/data/msvideo1.vsynth2.out.yuv ++stddev: 7.42 PSNR: 30.72 MAXDIFF: 123 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/prores xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/prores +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/prores 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/prores 2012-05-14 14:08:55.820369890 +0200 +@@ -0,0 +1,4 @@ ++0faf42c187120c61d64a5e0cea4fc92a *./tests/data/vsynth2/prores.mov ++2844066 ./tests/data/vsynth2/prores.mov ++b5844025c0f4c7c37db702c3213db232 *./tests/data/prores.vsynth2.out.yuv ++stddev: 1.31 PSNR: 45.77 MAXDIFF: 11 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/qtrle xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/qtrle +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/qtrle 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/qtrle 2012-05-14 14:08:55.821369910 +0200 +@@ -1,4 +1,4 @@ +-5346bba8e03e7de72b482efbcf712a2e *./tests/data/vsynth2/qtrle.mov +-141533 ./tests/data/vsynth2/qtrle.mov +-f967b290c7e6d015c0e78175db828249 *./tests/data/qtrle.vsynth2.out.yuv +-stddev: 5.75 PSNR: 32.93 MAXDIFF: 92 bytes: 7603200/ 7603200 ++6ac61c011e1811ebd045535b141351de *./tests/data/vsynth2/qtrle.mov ++14798335 ./tests/data/vsynth2/qtrle.mov ++98d0e2854731472c5bf13d8638502d0a *./tests/data/qtrle.vsynth2.out.yuv ++stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/qtrlegray xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/qtrlegray +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/qtrlegray 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/qtrlegray 2012-05-14 14:08:55.821369910 +0200 +@@ -0,0 +1,4 @@ ++5a66c6d2b2db71eddbc50819483aa647 *./tests/data/vsynth2/qtrlegray.mov ++5111273 ./tests/data/vsynth2/qtrlegray.mov ++f63b5ebdfdba750e547c25131b0a3fd1 *./tests/data/qtrlegray.vsynth2.out.yuv ++stddev: 19.42 PSNR: 22.36 MAXDIFF: 72 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/rgb xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/rgb +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/rgb 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/rgb 2012-05-14 14:08:55.822369930 +0200 +@@ -1,4 +1,4 @@ + f2e9c419023c743bf99aa5b2e55ad233 *./tests/data/vsynth2/rgb.avi + 15213260 ./tests/data/vsynth2/rgb.avi +-b2418e0e3a9a8619b31219cbcf24dc82 *./tests/data/rgb.vsynth2.out.yuv +-stddev: 1.26 PSNR: 46.06 MAXDIFF: 13 bytes: 7603200/ 7603200 ++98d0e2854731472c5bf13d8638502d0a *./tests/data/rgb.vsynth2.out.yuv ++stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/svq1 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/svq1 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/svq1 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/svq1 2012-05-14 14:08:55.822369930 +0200 +@@ -1,4 +1,4 @@ +-7f9fbe4890bc1df67867bf03803dca48 *./tests/data/vsynth2/svq1.mov +-766851 ./tests/data/vsynth2/svq1.mov ++320a7fbbaecc0989df054bf9678bfdf6 *./tests/data/vsynth2/svq1.mov ++766691 ./tests/data/vsynth2/svq1.mov + aa03471dac3f49455a33a2b19fda1098 *./tests/data/svq1.vsynth2.out.yuv + stddev: 3.23 PSNR: 37.93 MAXDIFF: 61 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/v210 xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/v210 +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/v210 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/v210 2012-05-14 14:08:55.823369950 +0200 +@@ -0,0 +1,4 @@ ++db0579bd46e1ba133ff86c0f7cdd761f *./tests/data/vsynth2/v210.avi ++14752460 ./tests/data/vsynth2/v210.avi ++a627fb50c8276200fd71383977d87ca3 *./tests/data/v210.vsynth2.out.yuv ++stddev: 0.34 PSNR: 57.43 MAXDIFF: 6 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/vref xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/vref +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/vref 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/vref 2012-05-14 14:08:55.823369950 +0200 +@@ -0,0 +1,2 @@ ++dde5895817ad9d219f79a52d0bdfb001 *./tests/data/vsynth2.ref.yuv ++7603200 ./tests/data/vsynth2.ref.yuv +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/yuv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/yuv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/yuv 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/yuv 2012-05-14 14:08:55.824369970 +0200 +@@ -1,4 +1,4 @@ +-30a400773ab26f2c83e469198b156f1d *./tests/data/vsynth2/yuv.avi ++3d5ee6d2023bc15bba898819e4977e46 *./tests/data/vsynth2/yuv.avi + 7610060 ./tests/data/vsynth2/yuv.avi + dde5895817ad9d219f79a52d0bdfb001 *./tests/data/yuv.vsynth2.out.yuv + stddev: 0.00 PSNR:999.99 MAXDIFF: 0 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/zlib xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/zlib +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/zlib 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/zlib 2012-05-14 14:08:55.824369970 +0200 +@@ -0,0 +1,4 @@ ++f4bfa774c853abe8f06a29596c1f16cb *./tests/data/vsynth2/zlib.avi ++12517188 ./tests/data/vsynth2/zlib.avi ++98d0e2854731472c5bf13d8638502d0a *./tests/data/zlib.vsynth2.out.yuv ++stddev: 1.26 PSNR: 46.10 MAXDIFF: 13 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/zmbv xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/zmbv +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/ref/vsynth2/zmbv 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/ref/vsynth2/zmbv 2012-05-14 14:08:55.824369970 +0200 +@@ -0,0 +1,3 @@ ++5116352 ./tests/data/vsynth2/zmbv.avi ++cfbec364e41d70c9b177435b5655d8af *./tests/data/zmbv.vsynth2.out.yuv ++stddev: 42.07 PSNR: 15.65 MAXDIFF: 112 bytes: 7603200/ 7603200 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/regression-funcs.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/regression-funcs.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/regression-funcs.sh 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/regression-funcs.sh 2012-05-14 14:08:55.825369990 +0200 +@@ -1,6 +1,6 @@ + #!/bin/sh + # +-# common regression functions for ffmpeg ++# common regression functions for avconv + # + # + +@@ -9,22 +9,18 @@ + raw_src_dir=$3 + target_exec=$4 + target_path=$5 ++threads=${6:-1} ++tool=$8 + + datadir="./tests/data" + target_datadir="${target_path}/${datadir}" + + this="$test.$test_ref" +-logdir="$datadir/regression/$test_ref" +-logfile="$logdir/$test" + outfile="$datadir/$test_ref/" +-errfile="$datadir/$this.err" + + # various files +-ffmpeg="$target_exec ${target_path}/ffmpeg" ++avconv="$target_exec ${target_path}/${tool}" + tiny_psnr="tests/tiny_psnr" +-benchfile="$datadir/$this.bench" +-bench="$datadir/$this.bench.tmp" +-bench2="$datadir/$this.bench2.tmp" + raw_src="${target_path}/$raw_src_dir/%02d.pgm" + raw_dst="$datadir/$this.out.yuv" + raw_ref="$datadir/$test_ref.ref.yuv" +@@ -34,17 +30,13 @@ + crcfile="$datadir/$this.crc" + target_crcfile="$target_datadir/$this.crc" + +-cleanfiles="$raw_dst $pcm_dst $crcfile $bench $bench2" ++cleanfiles="$raw_dst $pcm_dst $crcfile" + trap 'rm -f -- $cleanfiles' EXIT + + mkdir -p "$datadir" + mkdir -p "$outfile" +-mkdir -p "$logdir" +- +-(exec >&3) 2>/dev/null || exec 3>&2 + + [ "${V-0}" -gt 0 ] && echov=echov || echov=: +-[ "${V-0}" -gt 1 ] || exec 2>$errfile + + echov(){ + echo "$@" >&3 +@@ -52,88 +44,80 @@ + + . $(dirname $0)/md5.sh + +-FFMPEG_OPTS="-v 0 -y -flags +bitexact -dct fastint -idct simple -sws_flags +accurate_rnd+bitexact" ++AVCONV_OPTS="-nostats -y" ++COMMON_OPTS="-flags +bitexact -idct simple -sws_flags +accurate_rnd+bitexact" ++DEC_OPTS="$COMMON_OPTS -threads $threads" ++ENC_OPTS="$COMMON_OPTS -threads 1 -dct fastint" + +-run_ffmpeg() ++run_avconv() + { +- $echov $ffmpeg $FFMPEG_OPTS $* +- $ffmpeg $FFMPEG_OPTS $* ++ $echov $avconv $AVCONV_OPTS $* ++ $avconv $AVCONV_OPTS $* + } + +-do_ffmpeg() ++do_avconv() + { + f="$1" + shift + set -- $* ${target_path}/$f +- $echov $ffmpeg $FFMPEG_OPTS $* +- $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench +- do_md5sum $f >> $logfile ++ run_avconv $* ++ do_md5sum $f + if [ $f = $raw_dst ] ; then +- $tiny_psnr $f $raw_ref >> $logfile ++ $tiny_psnr $f $raw_ref + elif [ $f = $pcm_dst ] ; then +- $tiny_psnr $f $pcm_ref 2 >> $logfile ++ $tiny_psnr $f $pcm_ref 2 + else +- wc -c $f >> $logfile ++ wc -c $f + fi +- expr "$(cat $bench)" : '.*utime=\(.*s\)' > $bench2 +- echo $(cat $bench2) $f >> $benchfile + } + +-do_ffmpeg_nomd5() ++do_avconv_nomd5() + { + f="$1" + shift + set -- $* ${target_path}/$f +- $echov $ffmpeg $FFMPEG_OPTS $* +- $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench ++ run_avconv $* + if [ $f = $raw_dst ] ; then +- $tiny_psnr $f $raw_ref >> $logfile ++ $tiny_psnr $f $raw_ref + elif [ $f = $pcm_dst ] ; then +- $tiny_psnr $f $pcm_ref 2 >> $logfile ++ $tiny_psnr $f $pcm_ref 2 + else +- wc -c $f >> $logfile ++ wc -c $f + fi +- expr "$(cat $bench)" : '.*utime=\(.*s\)' > $bench2 +- echo $(cat $bench2) $f >> $benchfile + } + +-do_ffmpeg_crc() ++do_avconv_crc() + { + f="$1" + shift +- $echov $ffmpeg $FFMPEG_OPTS $* -f crc "$target_crcfile" +- $ffmpeg $FFMPEG_OPTS $* -f crc "$target_crcfile" +- echo "$f $(cat $crcfile)" >> $logfile ++ run_avconv $* -f crc "$target_crcfile" ++ echo "$f $(cat $crcfile)" + } + +-do_ffmpeg_nocheck() ++do_video_decoding() + { +- f="$1" +- shift +- $echov $ffmpeg $FFMPEG_OPTS $* +- $ffmpeg $FFMPEG_OPTS -benchmark $* > $bench +- expr "$(cat $bench)" : '.*utime=\(.*s\)' > $bench2 +- echo $(cat $bench2) $f >> $benchfile ++ do_avconv $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2 + } + +-do_video_decoding() ++do_video_encoding() + { +- do_ffmpeg $raw_dst $1 -i $target_path/$file -f rawvideo $2 ++ file=${outfile}$1 ++ do_avconv $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2 + } + +-do_video_encoding() ++do_video_encoding_nomd5() + { + file=${outfile}$1 +- do_ffmpeg $file $2 -f image2 -vcodec pgmyuv -i $raw_src $3 ++ do_avconv_nomd5 $file $DEC_OPTS -f image2 -vcodec pgmyuv -i $raw_src $ENC_OPTS $2 + } + + do_audio_encoding() + { + file=${outfile}$1 +- do_ffmpeg $file -ab 128k -ac 2 -f s16le -i $pcm_src $3 ++ do_avconv $file $DEC_OPTS -ac 2 -ar 44100 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2 + } + + do_audio_decoding() + { +- do_ffmpeg $pcm_dst -i $target_path/$file -sample_fmt s16 -f wav ++ do_avconv $pcm_dst $DEC_OPTS -i $target_path/$file -sample_fmt s16 -f wav + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/rotozoom.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/rotozoom.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/rotozoom.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/rotozoom.c 2012-05-14 14:08:55.827370030 +0200 +@@ -1,5 +1,5 @@ + /* +- * Generates a synthetic YUV video sequence suitable for codec testing. ++ * Generate a synthetic YUV video sequence suitable for codec testing. + * + * copyright (c) Sebastien Bechet + * +@@ -24,94 +24,99 @@ + #include + #include + +-#define FIXP (1<<16) +-#define MY_PI 205887 //(M_PI*FIX) ++#define FIXP (1 << 16) ++#define MY_PI 205887 // (M_PI * FIX) + +-static int64_t int_pow(int64_t a, int p){ +- int64_t v= FIXP; ++static int64_t int_pow(int64_t a, int p) ++{ ++ int64_t v = FIXP; + +- for(; p; p--){ +- v*= a; +- v/= FIXP; ++ for (; p; p--) { ++ v *= a; ++ v /= FIXP; + } + + return v; + } + +-static int64_t int_sin(int64_t a){ +- if(a<0) a= MY_PI-a; // 0..inf +- a %= 2*MY_PI; // 0..2PI +- +- if(a>=MY_PI*3/2) a -= 2*MY_PI; // -PI/2 .. 3PI/2 +- if(a>=MY_PI/2 ) a = MY_PI - a; // -PI/2 .. PI/2 ++static int64_t int_sin(int64_t a) ++{ ++ if (a < 0) ++ a = MY_PI - a; // 0..inf ++ a %= 2 * MY_PI; // 0..2PI ++ ++ if (a >= MY_PI * 3 / 2) ++ a -= 2 * MY_PI; // -PI / 2 .. 3PI / 2 ++ if (a >= MY_PI / 2) ++ a = MY_PI - a; // -PI / 2 .. PI / 2 + +- return a - int_pow(a, 3)/6 + int_pow(a, 5)/120 - int_pow(a, 7)/5040; ++ return a - int_pow(a, 3) / 6 + int_pow(a, 5) / 120 - int_pow(a, 7) / 5040; + } + + #define SCALEBITS 8 + #define ONE_HALF (1 << (SCALEBITS - 1)) +-#define FIX(x) ((int) ((x) * (1L<> SCALEBITS; +- r = p[3]; +- g = p[4]; +- b = p[5]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- p += wrap3; +- lum += wrap; +- +- r = p[0]; +- g = p[1]; +- b = p[2]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- r = p[3]; +- g = p[4]; +- b = p[5]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- +- cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + +- FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; +- cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - +- FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; ++ p = src; ++ for (y = 0; y < height; y += 2) { ++ for (x = 0; x < width; x += 2) { ++ r = p[0]; ++ g = p[1]; ++ b = p[2]; ++ r1 = r; ++ g1 = g; ++ b1 = b; ++ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ r = p[3]; ++ g = p[4]; ++ b = p[5]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ p += wrap3; ++ lum += wrap; ++ ++ r = p[0]; ++ g = p[1]; ++ b = p[2]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ r = p[3]; ++ g = p[4]; ++ b = p[5]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ ++ cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + ++ FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; ++ cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - ++ FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; + + cb++; + cr++; +- p += -wrap3 + 2 * 3; +- lum += -wrap + 2; ++ p += -wrap3 + 2 * 3; ++ lum += -wrap + 2; + } +- p += wrap3; ++ p += wrap3; + lum += wrap; + } + } +@@ -119,7 +124,7 @@ + /* cif format */ + #define DEFAULT_WIDTH 352 + #define DEFAULT_HEIGHT 288 +-#define DEFAULT_NB_PICT 50 ++#define DEFAULT_NB_PICT 50 + + static void pgmyuv_save(const char *filename, int w, int h, + unsigned char *rgb_tab) +@@ -130,19 +135,19 @@ + unsigned char *lum_tab, *cb_tab, *cr_tab; + + lum_tab = malloc(w * h); +- cb_tab = malloc((w * h) / 4); +- cr_tab = malloc((w * h) / 4); ++ cb_tab = malloc(w * h / 4); ++ cr_tab = malloc(w * h / 4); + + rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); + +- f = fopen(filename,"wb"); +- fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255); ++ f = fopen(filename, "wb"); ++ fprintf(f, "P5\n%d %d\n%d\n", w, h * 3 / 2, 255); + fwrite(lum_tab, 1, w * h, f); + h2 = h / 2; + w2 = w / 2; + cb = cb_tab; + cr = cr_tab; +- for(i=0;i= height) + return; + +- p = rgb_tab + y * wrap + x * 3; ++ p = rgb_tab + y * wrap + x * 3; + p[0] = r; + p[1] = g; + p[2] = b; + } + +-unsigned char tab_r[256*256]; +-unsigned char tab_g[256*256]; +-unsigned char tab_b[256*256]; +- +-int h_cos [360]; +-int h_sin [360]; +- +-static int ipol(uint8_t *src, int x, int y){ +- int int_x= x>>16; +- int int_y= y>>16; +- int frac_x= x&0xFFFF; +- int frac_y= y&0xFFFF; +- int s00= src[ ( int_x &255) + 256*( int_y &255) ]; +- int s01= src[ ((int_x+1)&255) + 256*( int_y &255) ]; +- int s10= src[ ( int_x &255) + 256*((int_y+1)&255) ]; +- int s11= src[ ((int_x+1)&255) + 256*((int_y+1)&255) ]; +- int s0= (((1<<16) - frac_x)*s00 + frac_x*s01)>>8; +- int s1= (((1<<16) - frac_x)*s10 + frac_x*s11)>>8; ++unsigned char tab_r[256 * 256]; ++unsigned char tab_g[256 * 256]; ++unsigned char tab_b[256 * 256]; ++ ++int h_cos[360]; ++int h_sin[360]; ++ ++static int ipol(uint8_t *src, int x, int y) ++{ ++ int int_x = x >> 16; ++ int int_y = y >> 16; ++ int frac_x = x & 0xFFFF; ++ int frac_y = y & 0xFFFF; ++ int s00 = src[( int_x & 255) + 256 * ( int_y & 255)]; ++ int s01 = src[((int_x + 1) & 255) + 256 * ( int_y & 255)]; ++ int s10 = src[( int_x & 255) + 256 * ((int_y + 1) & 255)]; ++ int s11 = src[((int_x + 1) & 255) + 256 * ((int_y + 1) & 255)]; ++ int s0 = (((1 << 16) - frac_x) * s00 + frac_x * s01) >> 8; ++ int s1 = (((1 << 16) - frac_x) * s10 + frac_x * s11) >> 8; + +- return (((1<<16) - frac_y)*s0 + frac_y*s1)>>24; ++ return (((1 << 16) - frac_y) * s0 + frac_y * s1) >> 24; + } + + static void gen_image(int num, int w, int h) + { +- const int c = h_cos [num % 360]; +- const int s = h_sin [num % 360]; ++ const int c = h_cos[num % 360]; ++ const int s = h_sin[num % 360]; + +- const int xi = -(w/2) * c; +- const int yi = (w/2) * s; ++ const int xi = -(w / 2) * c; ++ const int yi = (w / 2) * s; + +- const int xj = -(h/2) * s; +- const int yj = -(h/2) * c; +- int i,j; +- +- int x,y; +- int xprime = xj; +- int yprime = yj; +- +- +- for (j=0;j>16)&255) + (((y>>16)&255)<<8); +- put_pixel(i, j, tab_r[dep], tab_g[dep], tab_b[dep]); +- } +-#endif ++ const int xj = -(h / 2) * s; ++ const int yj = -(h / 2) * c; ++ int i, j; ++ ++ int x, y; ++ int xprime = xj; ++ int yprime = yj; ++ ++ for (j = 0; j < h; j++) { ++ x = xprime + xi + FIXP * w / 2; ++ xprime += s; ++ ++ y = yprime + yi + FIXP * h / 2; ++ yprime += c; ++ ++ for (i = 0; i < w; i++) { ++ x += c; ++ y -= s; ++ put_pixel(i, j, ++ ipol(tab_r, x, y), ++ ipol(tab_g, x, y), ++ ipol(tab_b, x, y)); ++ } + } +- } + } + + #define W 256 + #define H 256 + +-static void init_demo(const char *filename) { +- int i,j; +- int h; +- int radian; +- char line[3 * W]; +- +- FILE *fichier; +- +- fichier = fopen(filename,"rb"); +- if (!fichier) { +- perror(filename); +- exit(1); +- } +- +- fread(line, 1, 15, fichier); +- for (i=0;i +-#include +-#include +-#include +- +-#include "libavutil/common.h" +-#include "libavformat/avformat.h" +- +-#undef exit +-#undef printf +-#undef fprintf +- +-static char buffer[20]; +- +-static const char *ret_str(int v) +-{ +- switch (v) { +- case AVERROR_EOF: return "-EOF"; +- case AVERROR(EIO): return "-EIO"; +- case AVERROR(ENOMEM): return "-ENOMEM"; +- case AVERROR(EINVAL): return "-EINVAL"; +- default: +- snprintf(buffer, sizeof(buffer), "%2d", v); +- return buffer; +- } +-} +- +-static void ts_str(char buffer[60], int64_t ts, AVRational base) +-{ +- double tsval; +- if (ts == AV_NOPTS_VALUE) { +- strcpy(buffer, " NOPTS "); +- return; +- } +- tsval = ts * av_q2d(base); +- snprintf(buffer, 60, "%9f", tsval); +-} +- +-int main(int argc, char **argv) +-{ +- const char *filename; +- AVFormatContext *ic = NULL; +- int i, ret, stream_id; +- int64_t timestamp; +- AVFormatParameters params, *ap= ¶ms; +- memset(ap, 0, sizeof(params)); +- ap->channels=1; +- ap->sample_rate= 22050; +- +- /* initialize libavcodec, and register all codecs and formats */ +- av_register_all(); +- +- if (argc != 2) { +- printf("usage: %s input_file\n" +- "\n", argv[0]); +- exit(1); +- } +- +- filename = argv[1]; +- +- ret = av_open_input_file(&ic, filename, NULL, 0, ap); +- if (ret < 0) { +- fprintf(stderr, "cannot open %s\n", filename); +- exit(1); +- } +- +- ret = av_find_stream_info(ic); +- if (ret < 0) { +- fprintf(stderr, "%s: could not find codec parameters\n", filename); +- exit(1); +- } +- +- for(i=0; ; i++){ +- AVPacket pkt; +- AVStream *av_uninit(st); +- char ts_buf[60]; +- +- memset(&pkt, 0, sizeof(pkt)); +- if(ret>=0){ +- ret= av_read_frame(ic, &pkt); +- if(ret>=0){ +- char dts_buf[60]; +- st= ic->streams[pkt.stream_index]; +- ts_str(dts_buf, pkt.dts, st->time_base); +- ts_str(ts_buf, pkt.pts, st->time_base); +- printf("ret:%-10s st:%2d flags:%d dts:%s pts:%s pos:%7" PRId64 " size:%6d", ret_str(ret), pkt.stream_index, pkt.flags, dts_buf, ts_buf, pkt.pos, pkt.size); +- av_free_packet(&pkt); +- } else +- printf("ret:%s", ret_str(ret)); // necessary to avoid trailing whitespace +- printf("\n"); +- } +- +- if(i>25) break; +- +- stream_id= (i>>1)%(ic->nb_streams+1) - 1; +- timestamp= (i*19362894167LL) % (4*AV_TIME_BASE) - AV_TIME_BASE; +- if(stream_id>=0){ +- st= ic->streams[stream_id]; +- timestamp= av_rescale_q(timestamp, AV_TIME_BASE_Q, st->time_base); +- } +- //FIXME fully test the new seek API +- if(i&1) ret = avformat_seek_file(ic, stream_id, INT64_MIN, timestamp, timestamp, 0); +- else ret = avformat_seek_file(ic, stream_id, timestamp, timestamp, INT64_MAX, 0); +- ts_str(ts_buf, timestamp, stream_id < 0 ? AV_TIME_BASE_Q : st->time_base); +- printf("ret:%-10s st:%2d flags:%d ts:%s\n", ret_str(ret), stream_id, i&1, ts_buf); +- } +- +- av_close_input_file(ic); +- +- return 0; +-} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/tiny_psnr.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/tiny_psnr.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/tiny_psnr.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/tiny_psnr.c 2012-05-14 14:08:55.829370070 +0200 +@@ -24,32 +24,32 @@ + #include + #include + +-#define FFMIN(a,b) ((a) > (b) ? (b) : (a)) ++#define FFMIN(a, b) ((a) > (b) ? (b) : (a)) + #define F 100 + #define SIZE 2048 + +-uint64_t exp16_table[21]={ +- 65537, +- 65538, +- 65540, +- 65544, +- 65552, +- 65568, +- 65600, +- 65664, +- 65793, +- 66050, +- 66568, +- 67616, +- 69763, +- 74262, +- 84150, +- 108051, +- 178145, +- 484249, +- 3578144, +- 195360063, +- 582360139072LL, ++uint64_t exp16_table[21] = { ++ 65537, ++ 65538, ++ 65540, ++ 65544, ++ 65552, ++ 65568, ++ 65600, ++ 65664, ++ 65793, ++ 66050, ++ 66568, ++ 67616, ++ 69763, ++ 74262, ++ 84150, ++ 108051, ++ 178145, ++ 484249, ++ 3578144, ++ 195360063, ++ 582360139072LL, + }; + + #if 0 +@@ -68,63 +68,66 @@ + #endif + + // 16.16 fixpoint log() +-static int64_t log16(uint64_t a){ ++static int64_t log16(uint64_t a) ++{ + int i; +- int out=0; ++ int out = 0; + +- if(a < 1<<16) +- return -log16((1LL<<32) / a); +- a<<=16; +- +- for(i=20;i>=0;i--){ +- int64_t b= exp16_table[i]; +- if(a<(b<<16)) continue; +- out |= 1<= 0; i--) { ++ int64_t b = exp16_table[i]; ++ if (a < (b << 16)) ++ continue; ++ out |= 1 << i; ++ a = ((a / b) << 16) + (((a % b) << 16) + b / 2) / b; + } + return out; + } + + static uint64_t int_sqrt(uint64_t a) + { +- uint64_t ret=0; ++ uint64_t ret = 0; ++ uint64_t ret_sq = 0; + int s; +- uint64_t ret_sq=0; + +- for(s=31; s>=0; s--){ +- uint64_t b= ret_sq + (1ULL<<(s*2)) + (ret<= 0; s--) { ++ uint64_t b = ret_sq + (1ULL << (s * 2)) + (ret << s) * 2; ++ if (b <= a) { ++ ret_sq = b; ++ ret += 1ULL << s; + } + } + return ret; + } + +-int main(int argc,char* argv[]){ ++int main(int argc, char *argv[]) ++{ + int i, j; +- uint64_t sse=0; ++ uint64_t sse = 0; + uint64_t dev; + FILE *f[2]; + uint8_t buf[2][SIZE]; + uint64_t psnr; +- int len= argc<4 ? 1 : atoi(argv[3]); +- int64_t max= (1<<(8*len))-1; +- int shift= argc<5 ? 0 : atoi(argv[4]); +- int skip_bytes = argc<6 ? 0 : atoi(argv[5]); +- int size0=0; +- int size1=0; +- int maxdist = 0; ++ int len = argc < 4 ? 1 : atoi(argv[3]); ++ int64_t max = (1 << (8 * len)) - 1; ++ int shift = argc < 5 ? 0 : atoi(argv[4]); ++ int skip_bytes = argc < 6 ? 0 : atoi(argv[5]); ++ int size0 = 0; ++ int size1 = 0; ++ int maxdist = 0; + +- if(argc<3){ ++ if (argc < 3) { + printf("tiny_psnr [ [ []]]\n"); + printf("WAV headers are skipped automatically.\n"); + return 1; + } + +- f[0]= fopen(argv[1], "rb"); +- f[1]= fopen(argv[2], "rb"); +- if(!f[0] || !f[1]){ ++ f[0] = fopen(argv[1], "rb"); ++ f[1] = fopen(argv[2], "rb"); ++ if (!f[0] || !f[1]) { + fprintf(stderr, "Could not open input files.\n"); + return 1; + } +@@ -133,12 +136,12 @@ + uint8_t *p = buf[i]; + if (fread(p, 1, 12, f[i]) != 12) + return 1; +- if (!memcmp(p, "RIFF", 4) && +- !memcmp(p+8, "WAVE", 4)) { ++ if (!memcmp(p, "RIFF", 4) && ++ !memcmp(p + 8, "WAVE", 4)) { + if (fread(p, 1, 8, f[i]) != 8) + return 1; + while (memcmp(p, "data", 4)) { +- int s = p[4] | p[5]<<8 | p[6]<<16 | p[7]<<24; ++ int s = p[4] | p[5] << 8 | p[6] << 16 | p[7] << 24; + fseek(f[i], s, SEEK_CUR); + if (fread(p, 1, 8, f[i]) != 8) + return 1; +@@ -148,47 +151,47 @@ + } + } + +- fseek(f[shift<0], abs(shift), SEEK_CUR); ++ fseek(f[shift < 0], abs(shift), SEEK_CUR); + +- fseek(f[0],skip_bytes,SEEK_CUR); +- fseek(f[1],skip_bytes,SEEK_CUR); ++ fseek(f[0], skip_bytes, SEEK_CUR); ++ fseek(f[1], skip_bytes, SEEK_CUR); + +- for(;;){ +- int s0= fread(buf[0], 1, SIZE, f[0]); +- int s1= fread(buf[1], 1, SIZE, f[1]); +- +- for(j=0; j maxdist) maxdist = dist; ++ sse += (a - b) * (a - b); ++ dist = abs(a - b); ++ if (dist > maxdist) ++ maxdist = dist; + } + size0 += s0; + size1 += s1; +- if(s0+s1<=0) ++ if (s0 + s1 <= 0) + break; + } + +- i= FFMIN(size0,size1)/len; +- if(!i) i=1; +- dev= int_sqrt( ((sse/i)*F*F) + (((sse%i)*F*F) + i/2)/i ); +- if(sse) +- psnr= ((2*log16(max<<16) + log16(i) - log16(sse))*284619LL*F + (1LL<<31)) / (1LL<<32); ++ i = FFMIN(size0, size1) / len; ++ if (!i) ++ i = 1; ++ dev = int_sqrt(((sse / i) * F * F) + (((sse % i) * F * F) + i / 2) / i); ++ if (sse) ++ psnr = ((2 * log16(max << 16) + log16(i) - log16(sse)) * ++ 284619LL * F + (1LL << 31)) / (1LL << 32); + else +- psnr= 1000*F-1; //floating point free infinity :) ++ psnr = 1000 * F - 1; // floating point free infinity :) + + printf("stddev:%5d.%02d PSNR:%3d.%02d MAXDIFF:%5d bytes:%9d/%9d\n", +- (int)(dev/F), (int)(dev%F), +- (int)(psnr/F), (int)(psnr%F), +- maxdist, +- size0, size1); ++ (int)(dev / F), (int)(dev % F), ++ (int)(psnr / F), (int)(psnr % F), ++ maxdist, size0, size1); + return 0; + } +- +- +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tests/videogen.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/videogen.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tests/videogen.c 2012-03-27 17:55:48.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tests/videogen.c 2012-05-14 14:08:55.830370090 +0200 +@@ -1,6 +1,6 @@ + /* +- * Generates a synthetic YUV video sequence suitable for codec testing. +- * NOTE: No floats are used to guarantee a bit exact output. ++ * Generate a synthetic YUV video sequence suitable for codec testing. ++ * NOTE: No floats are used to guarantee bitexact output. + * + * Copyright (c) 2002 Fabrice Bellard + * +@@ -27,67 +27,73 @@ + + #define SCALEBITS 8 + #define ONE_HALF (1 << (SCALEBITS - 1)) +-#define FIX(x) ((int) ((x) * (1L<> SCALEBITS; +- r = p[3]; +- g = p[4]; +- b = p[5]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- p += wrap3; +- lum += wrap; +- +- r = p[0]; +- g = p[1]; +- b = p[2]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- r = p[3]; +- g = p[4]; +- b = p[5]; +- r1 += r; +- g1 += g; +- b1 += b; +- lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + +- FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; +- +- cb[0] = ((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + +- FIX(0.50000) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; +- cr[0] = ((FIX(0.50000) * r1 - FIX(0.41869) * g1 - +- FIX(0.08131) * b1 + 4 * ONE_HALF - 1) >> (SCALEBITS + 2)) + 128; ++ p = src; ++ for (y = 0; y < height; y += 2) { ++ for (x = 0; x < width; x += 2) { ++ r = p[0]; ++ g = p[1]; ++ b = p[2]; ++ r1 = r; ++ g1 = g; ++ b1 = b; ++ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ r = p[3]; ++ g = p[4]; ++ b = p[5]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ p += wrap3; ++ lum += wrap; ++ ++ r = p[0]; ++ g = p[1]; ++ b = p[2]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[0] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ r = p[3]; ++ g = p[4]; ++ b = p[5]; ++ r1 += r; ++ g1 += g; ++ b1 += b; ++ lum[1] = (FIX(0.29900) * r + FIX(0.58700) * g + ++ FIX(0.11400) * b + ONE_HALF) >> SCALEBITS; ++ ++ cb[0] = 128 + ((- FIX(0.16874) * r1 - ++ FIX(0.33126) * g1 + ++ FIX(0.50000) * b1 + ++ 4 * ONE_HALF - 1) ++ >> (SCALEBITS + 2)); ++ cr[0] = 128 + ((FIX(0.50000) * r1 - ++ FIX(0.41869) * g1 - ++ FIX(0.08131) * b1 + ++ 4 * ONE_HALF - 1) ++ >> (SCALEBITS + 2)); + + cb++; + cr++; +- p += -wrap3 + 2 * 3; ++ p += -wrap3 + 2 * 3; + lum += -wrap + 2; + } +- p += wrap3; ++ p += wrap3; + lum += wrap; + } + } +@@ -106,19 +112,19 @@ + unsigned char *lum_tab, *cb_tab, *cr_tab; + + lum_tab = malloc(w * h); +- cb_tab = malloc((w * h) / 4); +- cr_tab = malloc((w * h) / 4); ++ cb_tab = malloc((w * h) / 4); ++ cr_tab = malloc((w * h) / 4); + + rgb24_to_yuv420p(lum_tab, cb_tab, cr_tab, rgb_tab, w, h); + +- f = fopen(filename,"wb"); ++ f = fopen(filename, "wb"); + fprintf(f, "P5\n%d %d\n%d\n", w, (h * 3) / 2, 255); + fwrite(lum_tab, 1, w * h, f); + h2 = h / 2; + w2 = w / 2; + cb = cb_tab; + cr = cr_tab; +- for(i=0;i= height) + return; + +- p = rgb_tab + y * wrap + x * 3; ++ p = rgb_tab + y * wrap + x * 3; + p[0] = r; + p[1] = g; + p[2] = b; +@@ -180,7 +186,7 @@ + neg = 0; + if (a > (FRAC_ONE / 4)) { + neg = -1; +- a = (FRAC_ONE / 2) - a; ++ a = (FRAC_ONE / 2) - a; + } + v = FRAC_ONE - ((a * a) >> 4); + v = (v ^ neg) - neg; +@@ -204,7 +210,7 @@ + unsigned int seed1; + + if (num == 0) { +- for(i=0;i> FRAC_BITS) & 0xff; +- g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff; +- b = ((x1 * 5) >> FRAC_BITS) & 0xff; ++ r = ((y1 * 7) >> FRAC_BITS) & 0xff; ++ g = (((x1 + y1) * 9) >> FRAC_BITS) & 0xff; ++ b = ((x1 * 5) >> FRAC_BITS) & 0xff; + put_pixel(x, y, r, g, b); + } + } + + /* then some noise with very high intensity to test saturation */ + seed1 = num; +- for(y=0;yh;y++) { +- for(x=0;xw;x++) { ++ for (y = 0; y < p->h; y++) { ++ for (x = 0; x < p->w; x++) { + r = p->r; + g = p->g; + b = p->b; +@@ -277,11 +283,11 @@ + h = DEFAULT_HEIGHT; + + rgb_tab = malloc(w * h * 3); +- wrap = w * 3; +- width = w; +- height = h; ++ wrap = w * 3; ++ width = w; ++ height = h; + +- for(i=0;i ++#include ++#include ++ ++#include "libavformat/avformat.h" ++ ++static int usage(const char *argv0, int ret) ++{ ++ fprintf(stderr, "%s [-b bytespersec] input_url output_url\n", argv0); ++ return ret; ++} ++ ++int main(int argc, char **argv) ++{ ++ int bps = 0, ret, i; ++ const char *input_url = NULL, *output_url = NULL; ++ int64_t stream_pos = 0; ++ int64_t start_time; ++ char errbuf[50]; ++ AVIOContext *input, *output; ++ ++ av_register_all(); ++ avformat_network_init(); ++ ++ for (i = 1; i < argc; i++) { ++ if (!strcmp(argv[i], "-b")) { ++ bps = atoi(argv[i + 1]); ++ i++; ++ } else if (!input_url) { ++ input_url = argv[i]; ++ } else if (!output_url) { ++ output_url = argv[i]; ++ } else { ++ return usage(argv[0], 1); ++ } ++ } ++ if (!output_url) ++ return usage(argv[0], 1); ++ ++ ret = avio_open2(&input, input_url, AVIO_FLAG_READ, NULL, NULL); ++ if (ret) { ++ av_strerror(ret, errbuf, sizeof(errbuf)); ++ fprintf(stderr, "Unable to open %s: %s\n", input_url, errbuf); ++ return 1; ++ } ++ ret = avio_open2(&output, output_url, AVIO_FLAG_WRITE, NULL, NULL); ++ if (ret) { ++ av_strerror(ret, errbuf, sizeof(errbuf)); ++ fprintf(stderr, "Unable to open %s: %s\n", output_url, errbuf); ++ goto fail; ++ } ++ ++ start_time = av_gettime(); ++ while (1) { ++ uint8_t buf[1024]; ++ int n; ++ n = avio_read(input, buf, sizeof(buf)); ++ if (n <= 0) ++ break; ++ avio_write(output, buf, n); ++ stream_pos += n; ++ if (bps) { ++ avio_flush(output); ++ while ((av_gettime() - start_time) * bps / AV_TIME_BASE < stream_pos) ++ usleep(50 * 1000); ++ } ++ } ++ ++ avio_flush(output); ++ avio_close(output); ++ ++fail: ++ avio_close(input); ++ avformat_network_deinit(); ++ return ret ? 1 : 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/build_avopt xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/build_avopt +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/build_avopt 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/build_avopt 1970-01-01 01:00:00.000000000 +0100 +@@ -1,9 +0,0 @@ +-#!/bin/sh +-sed 's/unsigned//g' |\ +- sed 's/enum//g' |\ +- egrep '^ *(int|float|double|AVRational|char *\*) *[a-zA-Z_0-9]* *;' |\ +- sed 's/^ *\([^ ]*\)[ *]*\([^;]*\);.*$/{"\2", NULL, OFFSET(\2), FF_OPT_TYPE_\U\1, DEFAULT, \1_MIN, \1_MAX},/' |\ +- sed 's/AVRATIONAL_M/INT_M/g'|\ +- sed 's/TYPE_AVRATIONAL/TYPE_RATIONAL/g'|\ +- sed 's/FLOAT_M/FLT_M/g'|\ +- sed 's/FF_OPT_TYPE_CHAR/FF_OPT_TYPE_STRING/g' +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/build_libstagefright xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/build_libstagefright +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/build_libstagefright 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/build_libstagefright 2012-05-14 14:08:55.832370130 +0200 +@@ -0,0 +1,58 @@ ++#!/bin/bash ++ ++if [ "$NDK" = "" ]; then ++ echo NDK variable not set, assuming ${HOME}/android-ndk ++ export NDK=${HOME}/android-ndk ++fi ++ ++echo "Fetching Android system headers" ++git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_frameworks_base.git ../android-source/frameworks/base ++git clone --depth=1 --branch gingerbread-release git://github.com/CyanogenMod/android_system_core.git ../android-source/system/core ++ ++echo "Fetching Android libraries for linking" ++# Libraries from any froyo/gingerbread device/emulator should work ++# fine, since the symbols used should be available on most of them. ++if [ ! -d "../android-libs" ]; then ++ if [ ! -f "../update-cm-7.0.3-N1-signed.zip" ]; then ++ wget http://download.cyanogenmod.com/get/update-cm-7.0.3-N1-signed.zip -P../ ++ fi ++ unzip ../update-cm-7.0.3-N1-signed.zip system/lib/* -d../ ++ mv ../system/lib ../android-libs ++ rmdir ../system ++fi ++ ++ ++SYSROOT=$NDK/platforms/android-9/arch-arm ++# Expand the prebuilt/* path into the correct one ++TOOLCHAIN=`echo $NDK/toolchains/arm-linux-androideabi-4.4.3/prebuilt/*-x86` ++export PATH=$TOOLCHAIN/bin:$PATH ++ANDROID_SOURCE=../android-source ++ANDROID_LIBS=../android-libs ++ ++rm -rf ../build/stagefright ++mkdir -p ../build/stagefright ++ ++DEST=../build/stagefright ++FLAGS="--target-os=linux --cross-prefix=arm-linux-androideabi- --arch=arm --cpu=armv7-a" ++FLAGS="$FLAGS --sysroot=$SYSROOT" ++FLAGS="$FLAGS --disable-avdevice --disable-decoder=h264 --disable-decoder=h264_vdpau --enable-libstagefright-h264" ++ ++EXTRA_CFLAGS="-I$ANDROID_SOURCE/frameworks/base/include -I$ANDROID_SOURCE/system/core/include" ++EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/media/libstagefright" ++EXTRA_CFLAGS="$EXTRA_CFLAGS -I$ANDROID_SOURCE/frameworks/base/include/media/stagefright/openmax" ++EXTRA_CFLAGS="$EXTRA_CFLAGS -I$NDK/sources/cxx-stl/system/include" ++ ++EXTRA_CFLAGS="$EXTRA_CFLAGS -march=armv7-a -mfloat-abi=softfp -mfpu=neon" ++EXTRA_LDFLAGS="-Wl,--fix-cortex-a8 -L$ANDROID_LIBS -Wl,-rpath-link,$ANDROID_LIBS" ++EXTRA_CXXFLAGS="-Wno-multichar -fno-exceptions -fno-rtti" ++ABI="armeabi-v7a" ++DEST="$DEST/$ABI" ++FLAGS="$FLAGS --prefix=$DEST" ++ ++mkdir -p $DEST ++ ++echo $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" > $DEST/info.txt ++./configure $FLAGS --extra-cflags="$EXTRA_CFLAGS" --extra-ldflags="$EXTRA_LDFLAGS" --extra-cxxflags="$EXTRA_CXXFLAGS" | tee $DEST/configuration.txt ++[ $PIPESTATUS == 0 ] || exit 1 ++make clean ++make -j4 || exit 1 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/clean-diff xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/clean-diff +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/clean-diff 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/clean-diff 2012-05-14 14:08:55.832370130 +0200 +@@ -1,6 +1,6 @@ + #!/bin/sh + sed '/^+[^+]/!s/ /TaBBaT/g' |\ +- expand -t `seq -s , 9 8 200` |\ ++ expand -t $(seq -s , 9 8 200) |\ + sed 's/TaBBaT/ /g' |\ + sed '/^+[^+]/s/ * $//' |\ + tr -d '\015' |\ +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/cws2fws.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/cws2fws.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/cws2fws.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/cws2fws.c 2012-05-14 14:08:55.833370150 +0200 +@@ -26,82 +26,83 @@ + z_stream zstream; + struct stat statbuf; + +- if (argc < 3) +- { ++ if (argc < 3) { + printf("Usage: %s \n", argv[0]); +- exit(1); ++ return 1; + } + + fd_in = open(argv[1], O_RDONLY); +- if (fd_in < 0) +- { +- perror("Error while opening: "); +- exit(1); ++ if (fd_in < 0) { ++ perror("Error opening input file"); ++ return 1; + } + +- fd_out = open(argv[2], O_WRONLY|O_CREAT, 00644); +- if (fd_out < 0) +- { +- perror("Error while opening: "); ++ fd_out = open(argv[2], O_WRONLY | O_CREAT, 00644); ++ if (fd_out < 0) { ++ perror("Error opening output file"); + close(fd_in); +- exit(1); ++ return 1; + } + +- if (read(fd_in, &buf_in, 8) != 8) +- { ++ if (read(fd_in, &buf_in, 8) != 8) { + printf("Header error\n"); + close(fd_in); + close(fd_out); +- exit(1); ++ return 1; + } + +- if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') +- { ++ if (buf_in[0] != 'C' || buf_in[1] != 'W' || buf_in[2] != 'S') { + printf("Not a compressed flash file\n"); +- exit(1); ++ return 1; + } + + fstat(fd_in, &statbuf); +- comp_len = statbuf.st_size; ++ comp_len = statbuf.st_size; + uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24); + +- printf("Compressed size: %d Uncompressed size: %d\n", comp_len-4, uncomp_len-4); ++ printf("Compressed size: %d Uncompressed size: %d\n", ++ comp_len - 4, uncomp_len - 4); + + // write out modified header + buf_in[0] = 'F'; +- write(fd_out, &buf_in, 8); ++ if (write(fd_out, &buf_in, 8) < 8) { ++ perror("Error writing output file"); ++ return 1; ++ } + + zstream.zalloc = NULL; +- zstream.zfree = NULL; ++ zstream.zfree = NULL; + zstream.opaque = NULL; + inflateInit(&zstream); + +- for (i = 0; i < comp_len-8;) +- { ++ for (i = 0; i < comp_len - 8;) { + int ret, len = read(fd_in, &buf_in, 1024); + + dbgprintf("read %d bytes\n", len); + + last_out = zstream.total_out; + +- zstream.next_in = &buf_in[0]; +- zstream.avail_in = len; +- zstream.next_out = &buf_out[0]; ++ zstream.next_in = &buf_in[0]; ++ zstream.avail_in = len; ++ zstream.next_out = &buf_out[0]; + zstream.avail_out = 65536; + + ret = inflate(&zstream, Z_SYNC_FLUSH); +- if (ret != Z_STREAM_END && ret != Z_OK) +- { ++ if (ret != Z_STREAM_END && ret != Z_OK) { + printf("Error while decompressing: %d\n", ret); + inflateEnd(&zstream); +- exit(1); ++ return 1; + } + + dbgprintf("a_in: %d t_in: %lu a_out: %d t_out: %lu -- %lu out\n", +- zstream.avail_in, zstream.total_in, zstream.avail_out, zstream.total_out, +- zstream.total_out-last_out); ++ zstream.avail_in, zstream.total_in, zstream.avail_out, ++ zstream.total_out, zstream.total_out - last_out); + +- write(fd_out, &buf_out, zstream.total_out-last_out); ++ if (write(fd_out, &buf_out, zstream.total_out - last_out) < ++ zstream.total_out - last_out) { ++ perror("Error writing output file"); ++ return 1; ++ } + + i += len; + +@@ -109,18 +110,20 @@ + break; + } + +- if (zstream.total_out != uncomp_len-8) +- { ++ if (zstream.total_out != uncomp_len - 8) { + printf("Size mismatch (%lu != %d), updating header...\n", +- zstream.total_out, uncomp_len-8); ++ zstream.total_out, uncomp_len - 8); + +- buf_in[0] = (zstream.total_out+8) & 0xff; +- buf_in[1] = ((zstream.total_out+8) >> 8) & 0xff; +- buf_in[2] = ((zstream.total_out+8) >> 16) & 0xff; +- buf_in[3] = ((zstream.total_out+8) >> 24) & 0xff; ++ buf_in[0] = (zstream.total_out + 8) & 0xff; ++ buf_in[1] = ((zstream.total_out + 8) >> 8) & 0xff; ++ buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff; ++ buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff; + + lseek(fd_out, 4, SEEK_SET); +- write(fd_out, &buf_in, 4); ++ if (write(fd_out, &buf_in, 4) < 4) { ++ perror("Error writing output file"); ++ return 1; ++ } + } + + inflateEnd(&zstream); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/enum_options.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/enum_options.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/enum_options.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/enum_options.c 2012-05-14 14:08:55.834370171 +0200 +@@ -0,0 +1,143 @@ ++/* ++ * Copyright (c) 2011 Anton Khirnov ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/* ++ * enumerate avoptions and format them in texinfo format ++ */ ++ ++#include ++ ++#include "libavformat/avformat.h" ++#include "libavcodec/avcodec.h" ++#include "libavutil/log.h" ++#include "libavutil/opt.h" ++ ++static void print_usage(void) ++{ ++ fprintf(stderr, "Usage: enum_options type\n" ++ "type: format codec\n"); ++ exit(1); ++} ++ ++static void print_option(const AVClass *class, const AVOption *o) ++{ ++ printf("@item -%s @var{", o->name); ++ switch (o->type) { ++ case FF_OPT_TYPE_BINARY: printf("hexadecimal string"); break; ++ case FF_OPT_TYPE_STRING: printf("string"); break; ++ case FF_OPT_TYPE_INT: ++ case FF_OPT_TYPE_INT64: printf("integer"); break; ++ case FF_OPT_TYPE_FLOAT: ++ case FF_OPT_TYPE_DOUBLE: printf("float"); break; ++ case FF_OPT_TYPE_RATIONAL: printf("rational number"); break; ++ case FF_OPT_TYPE_FLAGS: printf("flags"); break; ++ default: printf("value"); break; ++ } ++ printf("} (@emph{"); ++ ++ if (o->flags & AV_OPT_FLAG_ENCODING_PARAM) { ++ printf("input"); ++ if (o->flags & AV_OPT_FLAG_ENCODING_PARAM) ++ printf("/"); ++ } ++ if (o->flags & AV_OPT_FLAG_ENCODING_PARAM) ++ printf("output"); ++ ++ printf("})\n"); ++ if (o->help) ++ printf("%s\n", o->help); ++ ++ if (o->unit) { ++ const AVOption *u = NULL; ++ printf("\nPossible values:\n@table @samp\n"); ++ ++ while ((u = av_next_option(&class, u))) ++ if (u->type == FF_OPT_TYPE_CONST && u->unit && !strcmp(u->unit, o->unit)) ++ printf("@item %s\n%s\n", u->name, u->help ? u->help : ""); ++ printf("@end table\n"); ++ } ++} ++ ++static void show_opts(const AVClass *class) ++{ ++ const AVOption *o = NULL; ++ ++ printf("@table @option\n"); ++ while ((o = av_next_option(&class, o))) ++ if (o->type != FF_OPT_TYPE_CONST) ++ print_option(class, o); ++ printf("@end table\n"); ++} ++ ++static void show_format_opts(void) ++{ ++ AVInputFormat *iformat = NULL; ++ AVOutputFormat *oformat = NULL; ++ ++ printf("@section Generic format AVOptions\n"); ++ show_opts(avformat_get_class()); ++ ++ printf("@section Format-specific AVOptions\n"); ++ while ((iformat = av_iformat_next(iformat))) { ++ if (!iformat->priv_class) ++ continue; ++ printf("@subsection %s AVOptions\n", iformat->priv_class->class_name); ++ show_opts(iformat->priv_class); ++ } ++ while ((oformat = av_oformat_next(oformat))) { ++ if (!oformat->priv_class) ++ continue; ++ printf("@subsection %s AVOptions\n", oformat->priv_class->class_name); ++ show_opts(oformat->priv_class); ++ } ++} ++ ++static void show_codec_opts(void) ++{ ++ AVCodec *c = NULL; ++ ++ printf("@section Generic codec AVOptions\n"); ++ show_opts(avcodec_get_class()); ++ ++ printf("@section Codec-specific AVOptions\n"); ++ while ((c = av_codec_next(c))) { ++ if (!c->priv_class) ++ continue; ++ printf("@subsection %s AVOptions\n", c->priv_class->class_name); ++ show_opts(c->priv_class); ++ } ++} ++ ++int main(int argc, char **argv) ++{ ++ if (argc < 2) ++ print_usage(); ++ ++ av_register_all(); ++ ++ if (!strcmp(argv[1], "format")) ++ show_format_opts(); ++ else if (!strcmp(argv[1], "codec")) ++ show_codec_opts(); ++ else ++ print_usage(); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/ffeval.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/ffeval.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/ffeval.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/ffeval.c 2012-05-14 14:08:55.835370192 +0200 +@@ -0,0 +1,128 @@ ++/* ++ * Copyright (c) 2012 Stefano Sabatini ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include /* getopt */ ++#include "libavutil/eval.h" ++ ++/** ++ * @file ++ * simple arithmetic expression evaluator ++ */ ++ ++static void usage(void) ++{ ++ printf("Simple expression evalutor, please *don't* turn me to a feature-complete language interpreter\n"); ++ printf("usage: ffeval [OPTIONS]\n"); ++ printf("\n" ++ "Options:\n" ++ "-e echo each input line on output\n" ++ "-h print this help\n" ++ "-i INFILE set INFILE as input file, stdin if omitted\n" ++ "-o OUTFILE set OUTFILE as output file, stdout if omitted\n" ++ "-p PROMPT set output prompt\n"); ++} ++ ++#define MAX_BLOCK_SIZE SIZE_MAX ++ ++int main(int argc, char **argv) ++{ ++ size_t buf_size = 256; ++ char *buf = av_malloc(buf_size); ++ const char *outfilename = NULL, *infilename = NULL; ++ FILE *outfile = NULL, *infile = NULL; ++ const char *prompt = "=> "; ++ int count = 0, echo = 0; ++ char c; ++ ++ av_max_alloc(MAX_BLOCK_SIZE); ++ ++ while ((c = getopt(argc, argv, "ehi:o:p:")) != -1) { ++ switch (c) { ++ case 'e': ++ echo = 1; ++ break; ++ case 'h': ++ usage(); ++ return 0; ++ case 'i': ++ infilename = optarg; ++ break; ++ case 'o': ++ outfilename = optarg; ++ break; ++ case 'p': ++ prompt = optarg; ++ break; ++ case '?': ++ return 1; ++ } ++ } ++ ++ if (!infilename || !strcmp(infilename, "-")) ++ infilename = "/dev/stdin"; ++ infile = fopen(infilename, "r"); ++ if (!infile) { ++ fprintf(stderr, "Impossible to open input file '%s': %s\n", infilename, strerror(errno)); ++ return 1; ++ } ++ ++ if (!outfilename || !strcmp(outfilename, "-")) ++ outfilename = "/dev/stdout"; ++ outfile = fopen(outfilename, "w"); ++ if (!outfile) { ++ fprintf(stderr, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno)); ++ return 1; ++ } ++ ++ while ((c = fgetc(infile)) != EOF) { ++ if (c == '\n') { ++ double d; ++ ++ buf[count] = 0; ++ if (buf[0] != '#') { ++ av_expr_parse_and_eval(&d, buf, ++ NULL, NULL, ++ NULL, NULL, NULL, NULL, NULL, 0, NULL); ++ if (echo) ++ fprintf(outfile, "%s ", buf); ++ fprintf(outfile, "%s%f\n", prompt, d); ++ } ++ count = 0; ++ } else { ++ if (count >= buf_size-1) { ++ if (buf_size == MAX_BLOCK_SIZE) { ++ av_log(NULL, AV_LOG_ERROR, "Memory allocation problem, " ++ "max block size '%zd' reached\n", MAX_BLOCK_SIZE); ++ return 1; ++ } ++ buf_size = FFMIN(buf_size, MAX_BLOCK_SIZE / 2) * 2; ++ buf = av_realloc_f((void *)buf, buf_size, 1); ++ if (!buf) { ++ av_log(NULL, AV_LOG_ERROR, "Memory allocation problem occurred\n"); ++ return 1; ++ } ++ } ++ buf[count++] = c; ++ } ++ } ++ ++ av_free(buf); ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/graph2dot.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/graph2dot.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/graph2dot.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/graph2dot.c 2012-05-14 14:08:55.836370212 +0200 +@@ -20,8 +20,8 @@ + + #include /* getopt */ + +-#undef HAVE_AV_CONFIG_H + #include "libavutil/pixdesc.h" ++#include "libavutil/audioconvert.h" + #include "libavfilter/avfiltergraph.h" + + static void usage(void) +@@ -62,15 +62,30 @@ + char dst_filter_ctx_label[128]; + const AVFilterContext *dst_filter_ctx = link->dst; + +- snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label), "%s (%s)", ++ snprintf(dst_filter_ctx_label, sizeof(dst_filter_ctx_label), ++ "%s (%s)", + dst_filter_ctx->name, + dst_filter_ctx->filter->name); + +- fprintf(outfile, "\"%s\" -> \"%s\"", filter_ctx_label, dst_filter_ctx_label); +- fprintf(outfile, " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ];\n", +- link->type == AVMEDIA_TYPE_VIDEO ? av_pix_fmt_descriptors[link->format].name : +- link->type == AVMEDIA_TYPE_AUDIO ? av_get_sample_fmt_name(link->format) : "unknown", +- link->w, link->h, link->time_base.num, link->time_base.den); ++ fprintf(outfile, "\"%s\" -> \"%s\"", ++ filter_ctx_label, dst_filter_ctx_label); ++ if (link->type == AVMEDIA_TYPE_VIDEO) { ++ fprintf(outfile, ++ " [ label= \"fmt:%s w:%d h:%d tb:%d/%d\" ]", ++ av_pix_fmt_descriptors[link->format].name, ++ link->w, link->h, link->time_base.num, ++ link->time_base.den); ++ } else if (link->type == AVMEDIA_TYPE_AUDIO) { ++ char buf[255]; ++ av_get_channel_layout_string(buf, sizeof(buf), -1, ++ link->channel_layout); ++ fprintf(outfile, ++ " [ label= \"fmt:%s sr:%"PRId64" cl:%s tb:%d/%d\" ]", ++ av_get_sample_fmt_name(link->format), ++ link->sample_rate, buf, ++ link->time_base.num, link->time_base.den); ++ } ++ fprintf(outfile, ";\n"); + } + } + } +@@ -80,17 +95,17 @@ + int main(int argc, char **argv) + { + const char *outfilename = NULL; +- const char *infilename = NULL; +- FILE *outfile = NULL; +- FILE *infile = NULL; +- char *graph_string = NULL; ++ const char *infilename = NULL; ++ FILE *outfile = NULL; ++ FILE *infile = NULL; ++ char *graph_string = NULL; + AVFilterGraph *graph = av_mallocz(sizeof(AVFilterGraph)); + char c; + + av_log_set_level(AV_LOG_DEBUG); + + while ((c = getopt(argc, argv, "hi:o:")) != -1) { +- switch(c) { ++ switch (c) { + case 'h': + usage(); + return 0; +@@ -109,7 +124,8 @@ + infilename = "/dev/stdin"; + infile = fopen(infilename, "r"); + if (!infile) { +- fprintf(stderr, "Impossible to open input file '%s': %s\n", infilename, strerror(errno)); ++ fprintf(stderr, "Impossible to open input file '%s': %s\n", ++ infilename, strerror(errno)); + return 1; + } + +@@ -117,7 +133,8 @@ + outfilename = "/dev/stdout"; + outfile = fopen(outfilename, "w"); + if (!outfile) { +- fprintf(stderr, "Impossible to open output file '%s': %s\n", outfilename, strerror(errno)); ++ fprintf(stderr, "Impossible to open output file '%s': %s\n", ++ outfilename, strerror(errno)); + return 1; + } + +@@ -132,7 +149,7 @@ + struct line *new_line = av_malloc(sizeof(struct line)); + count += strlen(last_line->data); + last_line->next = new_line; +- last_line = new_line; ++ last_line = new_line; + } + last_line->next = NULL; + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/ismindex.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/ismindex.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/ismindex.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/ismindex.c 2012-05-14 14:08:55.837370232 +0200 +@@ -0,0 +1,525 @@ ++/* ++ * Copyright (c) 2012 Martin Storsjo ++ * ++ * This file is part of Libav. ++ * ++ * Libav is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * Libav 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with Libav; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++/* ++ * To create a simple file for smooth streaming: ++ * avconv -movflags frag_keyframe foo.ismv ++ * ismindex -n foo foo.ismv ++ * This step creates foo.ism and foo.ismc that is required by IIS for ++ * serving it. ++ * ++ * To pre-split files for serving as static files by a web server without ++ * any extra server support, create the ismv file as above, and split it: ++ * ismindex -split foo.ismv ++ * This step creates a file Manifest and directories QualityLevel(...), ++ * that can be read directly by a smooth streaming player. ++ */ ++ ++#include ++#include ++#include ++#ifdef _WIN32 ++#include ++#define mkdir(a, b) mkdir(a) ++#endif ++ ++#include "libavformat/avformat.h" ++#include "libavutil/intreadwrite.h" ++#include "libavutil/mathematics.h" ++ ++static int usage(const char *argv0, int ret) ++{ ++ fprintf(stderr, "%s [-split] [-n basename] file1 [file2] ...\n", argv0); ++ return ret; ++} ++ ++struct MoofOffset { ++ int64_t time; ++ int64_t offset; ++ int duration; ++}; ++ ++struct VideoFile { ++ const char *name; ++ int64_t duration; ++ int bitrate; ++ int track_id; ++ int is_audio, is_video; ++ int width, height; ++ int chunks; ++ int sample_rate, channels; ++ uint8_t *codec_private; ++ int codec_private_size; ++ struct MoofOffset *offsets; ++ int timescale; ++ const char *fourcc; ++ int blocksize; ++ int tag; ++}; ++ ++struct VideoFiles { ++ int nb_files; ++ int64_t duration; ++ struct VideoFile **files; ++ int video_file, audio_file; ++ int nb_video_files, nb_audio_files; ++}; ++ ++static int copy_tag(AVIOContext *in, AVIOContext *out, int32_t tag_name) ++{ ++ int32_t size, tag; ++ ++ size = avio_rb32(in); ++ tag = avio_rb32(in); ++ avio_wb32(out, size); ++ avio_wb32(out, tag); ++ if (tag != tag_name) ++ return -1; ++ size -= 8; ++ while (size > 0) { ++ char buf[1024]; ++ int len = FFMIN(sizeof(buf), size); ++ if (avio_read(in, buf, len) != len) ++ break; ++ avio_write(out, buf, len); ++ size -= len; ++ } ++ return 0; ++} ++ ++static int write_fragment(const char *filename, AVIOContext *in) ++{ ++ AVIOContext *out = NULL; ++ int ret; ++ ++ if ((ret = avio_open2(&out, filename, AVIO_FLAG_WRITE, NULL, NULL)) < 0) ++ return ret; ++ copy_tag(in, out, MKBETAG('m', 'o', 'o', 'f')); ++ copy_tag(in, out, MKBETAG('m', 'd', 'a', 't')); ++ ++ avio_flush(out); ++ avio_close(out); ++ ++ return ret; ++} ++ ++static int write_fragments(struct VideoFiles *files, int start_index, ++ AVIOContext *in) ++{ ++ char dirname[100], filename[500]; ++ int i, j; ++ ++ for (i = start_index; i < files->nb_files; i++) { ++ struct VideoFile *vf = files->files[i]; ++ const char *type = vf->is_video ? "video" : "audio"; ++ snprintf(dirname, sizeof(dirname), "QualityLevels(%d)", vf->bitrate); ++ mkdir(dirname, 0777); ++ for (j = 0; j < vf->chunks; j++) { ++ snprintf(filename, sizeof(filename), "%s/Fragments(%s=%"PRId64")", ++ dirname, type, vf->offsets[j].time); ++ avio_seek(in, vf->offsets[j].offset, SEEK_SET); ++ write_fragment(filename, in); ++ } ++ } ++ return 0; ++} ++ ++static int read_tfra(struct VideoFiles *files, int start_index, AVIOContext *f) ++{ ++ int ret = AVERROR_EOF, track_id; ++ int version, fieldlength, i, j; ++ int64_t pos = avio_tell(f); ++ uint32_t size = avio_rb32(f); ++ struct VideoFile *vf = NULL; ++ ++ if (avio_rb32(f) != MKBETAG('t', 'f', 'r', 'a')) ++ goto fail; ++ version = avio_r8(f); ++ avio_rb24(f); ++ track_id = avio_rb32(f); /* track id */ ++ for (i = start_index; i < files->nb_files && !vf; i++) ++ if (files->files[i]->track_id == track_id) ++ vf = files->files[i]; ++ if (!vf) { ++ /* Ok, continue parsing the next atom */ ++ ret = 0; ++ goto fail; ++ } ++ fieldlength = avio_rb32(f); ++ vf->chunks = avio_rb32(f); ++ vf->offsets = av_mallocz(sizeof(*vf->offsets) * vf->chunks); ++ if (!vf->offsets) { ++ ret = AVERROR(ENOMEM); ++ goto fail; ++ } ++ for (i = 0; i < vf->chunks; i++) { ++ if (version == 1) { ++ vf->offsets[i].time = avio_rb64(f); ++ vf->offsets[i].offset = avio_rb64(f); ++ } else { ++ vf->offsets[i].time = avio_rb32(f); ++ vf->offsets[i].offset = avio_rb32(f); ++ } ++ for (j = 0; j < ((fieldlength >> 4) & 3) + 1; j++) ++ avio_r8(f); ++ for (j = 0; j < ((fieldlength >> 2) & 3) + 1; j++) ++ avio_r8(f); ++ for (j = 0; j < ((fieldlength >> 0) & 3) + 1; j++) ++ avio_r8(f); ++ if (i > 0) ++ vf->offsets[i - 1].duration = vf->offsets[i].time - ++ vf->offsets[i - 1].time; ++ } ++ if (vf->chunks > 0) ++ vf->offsets[vf->chunks - 1].duration = vf->duration - ++ vf->offsets[vf->chunks - 1].time; ++ ret = 0; ++ ++fail: ++ avio_seek(f, pos + size, SEEK_SET); ++ return ret; ++} ++ ++static int read_mfra(struct VideoFiles *files, int start_index, ++ const char *file, int split) ++{ ++ int err = 0; ++ AVIOContext *f = NULL; ++ int32_t mfra_size; ++ ++ if ((err = avio_open2(&f, file, AVIO_FLAG_READ, NULL, NULL)) < 0) ++ goto fail; ++ avio_seek(f, avio_size(f) - 4, SEEK_SET); ++ mfra_size = avio_rb32(f); ++ avio_seek(f, -mfra_size, SEEK_CUR); ++ if (avio_rb32(f) != mfra_size) ++ goto fail; ++ if (avio_rb32(f) != MKBETAG('m', 'f', 'r', 'a')) ++ goto fail; ++ while (!read_tfra(files, start_index, f)) { ++ /* Empty */ ++ } ++ ++ if (split) ++ write_fragments(files, start_index, f); ++ ++fail: ++ if (f) ++ avio_close(f); ++ return err; ++} ++ ++static int get_private_data(struct VideoFile *vf, AVCodecContext *codec) ++{ ++ vf->codec_private_size = codec->extradata_size; ++ vf->codec_private = av_mallocz(codec->extradata_size); ++ if (!vf->codec_private) ++ return AVERROR(ENOMEM); ++ memcpy(vf->codec_private, codec->extradata, codec->extradata_size); ++ return 0; ++} ++ ++static int get_video_private_data(struct VideoFile *vf, AVCodecContext *codec) ++{ ++ AVIOContext *io = NULL; ++ uint16_t sps_size, pps_size; ++ int err = AVERROR(EINVAL); ++ ++ if (codec->codec_id == CODEC_ID_VC1) ++ return get_private_data(vf, codec); ++ ++ avio_open_dyn_buf(&io); ++ if (codec->extradata_size < 11 || codec->extradata[0] != 1) ++ goto fail; ++ sps_size = AV_RB16(&codec->extradata[6]); ++ if (11 + sps_size > codec->extradata_size) ++ goto fail; ++ avio_wb32(io, 0x00000001); ++ avio_write(io, &codec->extradata[8], sps_size); ++ pps_size = AV_RB16(&codec->extradata[9 + sps_size]); ++ if (11 + sps_size + pps_size > codec->extradata_size) ++ goto fail; ++ avio_wb32(io, 0x00000001); ++ avio_write(io, &codec->extradata[11 + sps_size], pps_size); ++ err = 0; ++ ++fail: ++ vf->codec_private_size = avio_close_dyn_buf(io, &vf->codec_private); ++ return err; ++} ++ ++static int handle_file(struct VideoFiles *files, const char *file, int split) ++{ ++ AVFormatContext *ctx = NULL; ++ int err = 0, i, orig_files = files->nb_files; ++ char errbuf[50], *ptr; ++ struct VideoFile *vf; ++ ++ err = avformat_open_input(&ctx, file, NULL, NULL); ++ if (err < 0) { ++ av_strerror(err, errbuf, sizeof(errbuf)); ++ fprintf(stderr, "Unable to open %s: %s\n", file, errbuf); ++ return 1; ++ } ++ ++ err = avformat_find_stream_info(ctx, NULL); ++ if (err < 0) { ++ av_strerror(err, errbuf, sizeof(errbuf)); ++ fprintf(stderr, "Unable to identify %s: %s\n", file, errbuf); ++ goto fail; ++ } ++ ++ if (ctx->nb_streams < 1) { ++ fprintf(stderr, "No streams found in %s\n", file); ++ goto fail; ++ } ++ if (!files->duration) ++ files->duration = ctx->duration; ++ ++ for (i = 0; i < ctx->nb_streams; i++) { ++ AVStream *st = ctx->streams[i]; ++ vf = av_mallocz(sizeof(*vf)); ++ files->files = av_realloc(files->files, ++ sizeof(*files->files) * (files->nb_files + 1)); ++ files->files[files->nb_files] = vf; ++ ++ vf->name = file; ++ if ((ptr = strrchr(file, '/')) != NULL) ++ vf->name = ptr + 1; ++ ++ vf->bitrate = st->codec->bit_rate; ++ vf->track_id = st->id; ++ vf->timescale = st->time_base.den; ++ vf->duration = av_rescale_rnd(ctx->duration, vf->timescale, ++ AV_TIME_BASE, AV_ROUND_UP); ++ vf->is_audio = st->codec->codec_type == AVMEDIA_TYPE_AUDIO; ++ vf->is_video = st->codec->codec_type == AVMEDIA_TYPE_VIDEO; ++ ++ if (!vf->is_audio && !vf->is_video) { ++ fprintf(stderr, ++ "Track %d in %s is neither video nor audio, skipping\n", ++ vf->track_id, file); ++ av_freep(&files->files[files->nb_files]); ++ continue; ++ } ++ ++ if (vf->is_audio) { ++ if (files->audio_file < 0) ++ files->audio_file = files->nb_files; ++ files->nb_audio_files++; ++ vf->channels = st->codec->channels; ++ vf->sample_rate = st->codec->sample_rate; ++ if (st->codec->codec_id == CODEC_ID_AAC) { ++ vf->fourcc = "AACL"; ++ vf->tag = 255; ++ vf->blocksize = 4; ++ } else if (st->codec->codec_id == CODEC_ID_WMAPRO) { ++ vf->fourcc = "WMAP"; ++ vf->tag = st->codec->codec_tag; ++ vf->blocksize = st->codec->block_align; ++ } ++ get_private_data(vf, st->codec); ++ } ++ if (vf->is_video) { ++ if (files->video_file < 0) ++ files->video_file = files->nb_files; ++ files->nb_video_files++; ++ vf->width = st->codec->width; ++ vf->height = st->codec->height; ++ if (st->codec->codec_id == CODEC_ID_H264) ++ vf->fourcc = "H264"; ++ else if (st->codec->codec_id == CODEC_ID_VC1) ++ vf->fourcc = "WVC1"; ++ get_video_private_data(vf, st->codec); ++ } ++ ++ files->nb_files++; ++ } ++ ++ avformat_close_input(&ctx); ++ ++ read_mfra(files, orig_files, file, split); ++ ++fail: ++ if (ctx) ++ avformat_close_input(&ctx); ++ return err; ++} ++ ++static void output_server_manifest(struct VideoFiles *files, ++ const char *basename) ++{ ++ char filename[1000]; ++ FILE *out; ++ int i; ++ ++ snprintf(filename, sizeof(filename), "%s.ism", basename); ++ out = fopen(filename, "w"); ++ if (!out) { ++ perror(filename); ++ return; ++ } ++ fprintf(out, "\n"); ++ fprintf(out, "\n"); ++ fprintf(out, "\t\n"); ++ fprintf(out, "\t\t\n", basename); ++ fprintf(out, "\t\n"); ++ fprintf(out, "\t\n"); ++ fprintf(out, "\t\t\n"); ++ for (i = 0; i < files->nb_files; i++) { ++ struct VideoFile *vf = files->files[i]; ++ const char *type = vf->is_video ? "video" : "audio"; ++ fprintf(out, "\t\t\t<%s src=\"%s\" systemBitrate=\"%d\">\n", ++ type, vf->name, vf->bitrate); ++ fprintf(out, "\t\t\t\t\n", vf->track_id); ++ fprintf(out, "\t\t\t\n", type); ++ } ++ fprintf(out, "\t\t\n"); ++ fprintf(out, "\t\n"); ++ fprintf(out, "\n"); ++ fclose(out); ++} ++ ++static void output_client_manifest(struct VideoFiles *files, ++ const char *basename, int split) ++{ ++ char filename[1000]; ++ FILE *out; ++ int i, j; ++ ++ if (split) ++ snprintf(filename, sizeof(filename), "Manifest"); ++ else ++ snprintf(filename, sizeof(filename), "%s.ismc", basename); ++ out = fopen(filename, "w"); ++ if (!out) { ++ perror(filename); ++ return; ++ } ++ fprintf(out, "\n"); ++ fprintf(out, "\n", files->duration * 10); ++ if (files->video_file >= 0) { ++ struct VideoFile *vf = files->files[files->video_file]; ++ int index = 0; ++ fprintf(out, ++ "\t\n", ++ files->nb_video_files, vf->chunks); ++ for (i = 0; i < files->nb_files; i++) { ++ vf = files->files[i]; ++ if (!vf->is_video) ++ continue; ++ fprintf(out, ++ "\t\tbitrate, vf->fourcc, vf->width, vf->height); ++ for (j = 0; j < vf->codec_private_size; j++) ++ fprintf(out, "%02X", vf->codec_private[j]); ++ fprintf(out, "\" />\n"); ++ index++; ++ } ++ vf = files->files[files->video_file]; ++ for (i = 0; i < vf->chunks; i++) ++ fprintf(out, "\t\t\n", i, ++ vf->offsets[i].duration); ++ fprintf(out, "\t\n"); ++ } ++ if (files->audio_file >= 0) { ++ struct VideoFile *vf = files->files[files->audio_file]; ++ int index = 0; ++ fprintf(out, ++ "\t\n", ++ files->nb_audio_files, vf->chunks); ++ for (i = 0; i < files->nb_files; i++) { ++ vf = files->files[i]; ++ if (!vf->is_audio) ++ continue; ++ fprintf(out, ++ "\t\tbitrate, vf->fourcc, vf->sample_rate, ++ vf->channels, vf->blocksize, vf->tag); ++ for (j = 0; j < vf->codec_private_size; j++) ++ fprintf(out, "%02X", vf->codec_private[j]); ++ fprintf(out, "\" />\n"); ++ index++; ++ } ++ vf = files->files[files->audio_file]; ++ for (i = 0; i < vf->chunks; i++) ++ fprintf(out, "\t\t\n", ++ i, vf->offsets[i].duration); ++ fprintf(out, "\t\n"); ++ } ++ fprintf(out, "\n"); ++ fclose(out); ++} ++ ++static void clean_files(struct VideoFiles *files) ++{ ++ int i; ++ for (i = 0; i < files->nb_files; i++) { ++ av_freep(&files->files[i]->codec_private); ++ av_freep(&files->files[i]->offsets); ++ av_freep(&files->files[i]); ++ } ++ av_freep(&files->files); ++ files->nb_files = 0; ++} ++ ++int main(int argc, char **argv) ++{ ++ const char *basename = NULL; ++ int split = 0, i; ++ struct VideoFiles vf = { 0, .video_file = -1, .audio_file = -1 }; ++ ++ av_register_all(); ++ ++ for (i = 1; i < argc; i++) { ++ if (!strcmp(argv[i], "-n")) { ++ basename = argv[i + 1]; ++ i++; ++ } else if (!strcmp(argv[i], "-split")) { ++ split = 1; ++ } else if (argv[i][0] == '-') { ++ return usage(argv[0], 1); ++ } else { ++ handle_file(&vf, argv[i], split); ++ } ++ } ++ if (!vf.nb_files || (!basename && !split)) ++ return usage(argv[0], 1); ++ ++ if (!split) ++ output_server_manifest(&vf, basename); ++ output_client_manifest(&vf, basename, split); ++ ++ clean_files(&vf); ++ ++ return 0; ++} +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/jauche_sortierer.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/jauche_sortierer.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/jauche_sortierer.sh 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/jauche_sortierer.sh 1970-01-01 01:00:00.000000000 +0100 +@@ -1,21 +0,0 @@ +-#!/bin/sh +-#GPL +-#TODO +-#add pixelformat/sampleformat into the path of the codecs +- +-FFP=../ffprobe +-TMP=$(mktemp) || exit 1 +-TARGET=$1 +-shift +- +-for v do +- BASE=$(basename $v) +- echo $v | egrep -i '(public|private)' >/dev/null && echo Warning $v may be private +- $FFP $v 2> $TMP +- FORM=$((grep 'Input #0, ' -m1 $TMP || echo 'Input #0, unknown') | sed 's/Input #0, \([a-zA-Z0-9_]*\).*/\1/' ) +- mkdir -p $TARGET/container/$FORM +- ln -s $v $TARGET/container/$FORM/$BASE +- eval $(grep 'Stream #0\.[^:]*: [a-zA-Z0-9][^:]*: [a-zA-Z0-9]' $TMP | sed 's#[^:]*: \([a-zA-Z0-9]*\)[^:]*: \([a-zA-Z0-9]*\).*#mkdir -p '$TARGET'/\1/\2 ; ln -s '$v' '$TARGET'/\1/\2/'$BASE' ; #') +-done +- +-rm $TMP +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/lavfi-showfiltfmts.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/lavfi-showfiltfmts.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/lavfi-showfiltfmts.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/lavfi-showfiltfmts.c 2012-05-14 14:08:55.839370272 +0200 +@@ -20,15 +20,62 @@ + + #include "libavformat/avformat.h" + #include "libavutil/pixdesc.h" ++#include "libavutil/samplefmt.h" + #include "libavfilter/avfilter.h" + ++static void print_formats(AVFilterContext *filter_ctx) ++{ ++ int i, j; ++ ++#define PRINT_FMTS(inout, outin, INOUT) \ ++ for (i = 0; i < filter_ctx->inout##put_count; i++) { \ ++ if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) { \ ++ AVFilterFormats *fmts = \ ++ filter_ctx->inout##puts[i]->outin##_formats; \ ++ for (j = 0; j < fmts->format_count; j++) \ ++ if(av_get_pix_fmt_name(fmts->formats[j])) \ ++ printf(#INOUT "PUT[%d] %s: fmt:%s\n", \ ++ i, filter_ctx->filter->inout##puts[i].name, \ ++ av_get_pix_fmt_name(fmts->formats[j])); \ ++ } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \ ++ AVFilterFormats *fmts; \ ++ \ ++ fmts = filter_ctx->inout##puts[i]->outin##_formats; \ ++ for (j = 0; j < fmts->format_count; j++) \ ++ printf(#INOUT "PUT[%d] %s: fmt:%s\n", \ ++ i, filter_ctx->filter->inout##puts[i].name, \ ++ av_get_sample_fmt_name(fmts->formats[j])); \ ++ \ ++ fmts = filter_ctx->inout##puts[i]->outin##_chlayouts; \ ++ for (j = 0; j < fmts->format_count; j++) { \ ++ char buf[256]; \ ++ av_get_channel_layout_string(buf, sizeof(buf), -1, \ ++ fmts->formats[j]); \ ++ printf(#INOUT "PUT[%d] %s: chlayout:%s\n", \ ++ i, filter_ctx->filter->inout##puts[i].name, buf); \ ++ } \ ++ \ ++ fmts = filter_ctx->inout##puts[i]->outin##_packing; \ ++ for (j = 0; j < fmts->format_count; j++) { \ ++ printf(#INOUT "PUT[%d] %s: packing:%s\n", \ ++ i, filter_ctx->filter->inout##puts[i].name, \ ++ fmts->formats[j] == AVFILTER_PACKED ? \ ++ "packed" : "planar"); \ ++ } \ ++ } \ ++ } \ ++ ++ PRINT_FMTS(in, out, IN); ++ PRINT_FMTS(out, in, OUT); ++} ++ + int main(int argc, char **argv) + { + AVFilter *filter; + AVFilterContext *filter_ctx; + const char *filter_name; + const char *filter_args = NULL; +- int i, j; ++ int i; + + av_log_set_level(AV_LOG_DEBUG); + +@@ -50,11 +97,13 @@ + } + + if (avfilter_open(&filter_ctx, filter, NULL) < 0) { +- fprintf(stderr, "Inpossible to open filter with name '%s'\n", filter_name); ++ fprintf(stderr, "Inpossible to open filter with name '%s'\n", ++ filter_name); + return 1; + } + if (avfilter_init_filter(filter_ctx, filter_args, NULL) < 0) { +- fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", filter_name, filter_args); ++ fprintf(stderr, "Impossible to init filter '%s' with arguments '%s'\n", ++ filter_name, filter_args); + return 1; + } + +@@ -75,23 +124,7 @@ + else + avfilter_default_query_formats(filter_ctx); + +- /* print the supported formats in input */ +- for (i = 0; i < filter_ctx->input_count; i++) { +- AVFilterFormats *fmts = filter_ctx->inputs[i]->out_formats; +- for (j = 0; j < fmts->format_count; j++) +- printf("INPUT[%d] %s: %s\n", +- i, filter_ctx->filter->inputs[i].name, +- av_pix_fmt_descriptors[fmts->formats[j]].name); +- } +- +- /* print the supported formats in output */ +- for (i = 0; i < filter_ctx->output_count; i++) { +- AVFilterFormats *fmts = filter_ctx->outputs[i]->in_formats; +- for (j = 0; j < fmts->format_count; j++) +- printf("OUTPUT[%d] %s: %s\n", +- i, filter_ctx->filter->outputs[i].name, +- av_pix_fmt_descriptors[fmts->formats[j]].name); +- } ++ print_formats(filter_ctx); + + avfilter_free(filter_ctx); + fflush(stdout); +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/patcheck xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/patcheck +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/patcheck 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/patcheck 2012-05-14 14:08:55.840370292 +0200 +@@ -8,16 +8,18 @@ + exit + fi + ++GREP=grep ++EGREP=egrep + TMP=patcheck.tmp + OPT="-nH" +-#FILES=`grep '^+++' $* | sed 's/+++ //g'` ++#FILES=$($GREP '^+++' $* | sed 's/+++ //g') + + echo patCHeck 1e10.0 +-echo This tool is intended to help a human check/review patches it is very far from +-echo being free of false positives and negatives, its output are just hints of what ++echo This tool is intended to help a human check/review patches. It is very far from ++echo being free of false positives and negatives, and its output are just hints of what + echo may or may not be bad. When you use it and it misses something or detects +-echo something wrong, fix it and send a patch to the ffmpeg-dev ML +-echo License:GPL Autor: Michael Niedermayer ++echo something wrong, fix it and send a patch to the ffmpeg-devel mailing list. ++echo License: GPL, Author: Michael Niedermayer + + ERE_PRITYP='(unsigned *|)(char|short|long|int|long *int|short *int|void|float|double|(u|)int(8|16|32|64)_t)' + ERE_TYPES='(const|static|av_cold|inline| *)*('$ERE_PRITYP'|[a-zA-Z][a-zA-Z0-9_]*)[* ]{1,}[a-zA-Z][a-zA-Z0-9_]*' +@@ -27,7 +29,7 @@ + arg="$1" + msg="$2" + shift 2 +- grep $OPT '^+' $* | grep -v ':+++'| egrep --color=always -- "$arg"> $TMP && printf "\n$msg\n" ++ $GREP $OPT '^+' $* | $GREP -v ':+++'| $EGREP --color=always -- "$arg"> $TMP && printf "\n$msg\n" + cat $TMP + } + +@@ -36,12 +38,12 @@ + varg="$2" + msg="$3" + shift 3 +- grep $OPT '^+' $* | grep -v ':+++' | egrep -v -- "$varg" | egrep --color=always -- "$arg" > $TMP && printf "\n$msg\n" ++ $GREP $OPT '^+' $* | $GREP -v ':+++' | $EGREP -v -- "$varg" | $EGREP --color=always -- "$arg" > $TMP && printf "\n$msg\n" + cat $TMP + } + + hiegrep '[[:space:]]$' 'trailing whitespace' $* +-hiegrep "`echo x | tr 'x' '\t'`" 'tabs' $* ++hiegrep "$(echo x | tr 'x' '\t')" 'tabs' $* + #hiegrep ':\+$' 'Empty lines' $* + hiegrep ';;' 'double ;' $* + hiegrep2 '\b_[a-zA-Z0-9_]{1,}' '__(asm|attribute)([^a-zA-Z0-9]|$)' 'reserved identifer' $* +@@ -53,6 +55,7 @@ + hiegrep '=[-+\*\&] ' 'looks like compound assignment' $* + hiegrep2 '/\*\* *[a-zA-Z0-9].*' '\*/' 'Inconsistently formatted doxygen comment' $* + hiegrep '; */\*\*[^<]' 'Misformatted doxygen comment' $* ++hiegrep '//!|/\*!' 'inconsistent doxygen syntax' $* + + hiegrep2 '(int|unsigned|static|void)[a-zA-Z0-9 _]*(init|end)[a-zA-Z0-9 _]*\(.*[^;]$' '(av_cold|:\+[^a-zA-Z_])' 'These functions may need av_cold, please review the whole patch for similar functions needing av_cold' $* + +@@ -60,11 +63,11 @@ + hiegrep '-= *1 *;' 'can be simplified to --' $* + hiegrep '((!|=)= *(0|NULL)[^0-9a-z]|[^0-9a-z](0|NULL) *(!|=)=)' 'x==0 / x!=0 can be simplified to !x / x' $* + +-egrep $OPT '^\+ *(const *|)static' $*| egrep --color=always '[^=]= *(0|NULL)[^0-9a-zA-Z]'> $TMP && printf '\nuseless 0 init\n' ++$EGREP $OPT '^\+ *(const *|)static' $*| $EGREP --color=always '[^=]= *(0|NULL)[^0-9a-zA-Z]'> $TMP && printf '\nuseless 0 init\n' + cat $TMP + hiegrep '# *ifdef * (HAVE|CONFIG)_' 'ifdefs that should be #if' $* + +-hiegrep '\b(awnser|cant|dont|quantised|quantisation|teh|wont)\b' 'common typos' $* ++hiegrep '\b(awnser|cant|dont|wont|usefull|successfull|occured|teh|alot|wether|skiped|heigth|informations|colums|loosy|loosing|seperate|preceed|upto|paket|posible)\b' 'common typos' $* + + hiegrep 'av_log\( *NULL' 'Missing context in av_log' $* + hiegrep '[^sn]printf' 'Please use av_log' $* +@@ -82,6 +85,7 @@ + hiegrep '(:\+|,|;)( *|static|\*)*'"$ERE_PRITYP"' *(src|source|input|in)([0-9A-Z_][0-9A-Za-z_]*){1,} *\[' 'missing const (test2)?' $* + hiegrep ' *static *'"$ERE_FUNCS"'[^)]*\);' 'static prototype, maybe you should reorder your functions' $* + hiegrep '@file: *[a-zA-Z0-9_]' 'doxy filetag with filename can in the future cause problems when forgotten during a rename' $* ++hiegrep '\bassert' 'Please use av_assert0, av_assert1 or av_assert2' $* + + hiegrep2 '\.long_name *=' 'NULL_IF_CONFIG_SMAL' 'missing NULL_IF_CONFIG_SMAL' $* + hiegrep2 '\.pix_fmts *= *\(' 'const' 'missing const for pix_fmts array' $* +@@ -89,7 +93,7 @@ + hiegrep2 '\.supported_framerates *= *\(' 'const' 'missing const for supported_framerates array' $* + hiegrep2 '\.channel_layouts *= *\(' 'const' 'missing const for channel_layouts array' $* + +-#egrep $OPT '^\+.*const ' $*| grep -v 'static'> $TMP && printf '\nnon static const\n' ++#$EGREP $OPT '^\+.*const ' $*| $GREP -v 'static'> $TMP && printf '\nnon static const\n' + #cat $TMP + + hiegrep2 "$ERE_TYPES" '(static|av_|ff_|typedef|:\+[^a-zA-Z_])' 'Non static with no ff_/av_ prefix' $* +@@ -104,58 +108,58 @@ + + + rm $TMP +-for i in `grep -H '^+.*@param' $*| sed 's/^\([^:]*\):.*@param\(\[.*\]\|\) *\([a-zA-Z0-9_]*\) .*$/\1:\3/'` ; do +- doxpar=`echo $i | sed 's/^.*:\(.*\)$/\1/'` +- file=`echo $i | sed 's/^\([^:]*\):.*$/\1/'` +- grep " *$doxpar *[),]" $file | grep -v '@param' >/dev/null || grep --color=always "@param *$doxpar" $file >>$TMP ++for i in $($GREP -H '^+.*@param' $*| sed 's/^\([^:]*\):.*@param\(\[.*\]\|\) *\([a-zA-Z0-9_]*\) .*$/\1:\3/') ; do ++ doxpar=$(echo $i | sed 's/^.*:\(.*\)$/\1/') ++ file=$(echo $i | sed 's/^\([^:]*\):.*$/\1/') ++ $GREP " *$doxpar *[),]" $file | $GREP -v '@param' >/dev/null || $GREP --color=always "@param *$doxpar" $file >>$TMP + done + if test -e $TMP ; then + printf '\nmismatching doxy params\n' + cat $TMP + fi + +-egrep -B2 $OPT '^(\+|) *('"$ERE_TYPES"'|# *define)' $* | egrep -A2 --color=always '(:|-)\+[^/]*/(\*([^*]|$)|/([^/]|$))' > $TMP && printf "\n Non doxy comments\n" ++$EGREP -B2 $OPT '^(\+|) *('"$ERE_TYPES"'|# *define)' $* | $EGREP -A2 --color=always '(:|-)\+[^/]*/(\*([^*]|$)|/([^/]|$))' > $TMP && printf "\n Non doxy comments\n" + cat $TMP + + rm $TMP + for i in \ +- `egrep -H '^\+ *'"$ERE_TYPES" $* |\ +- grep -v '(' | egrep -v '\Wgoto\W' |\ ++ $($EGREP -H '^\+ *'"$ERE_TYPES" $* |\ ++ $GREP -v '(' | $EGREP -v '\Wgoto\W' |\ + xargs -d '\n' -n 1 |\ +- grep -o '[* ][* ]*[a-zA-Z][0-9a-zA-Z_]* *[,;=]' |\ +- sed 's/.[* ]*\([a-zA-Z][0-9a-zA-Z_]*\) *[,;=]/\1/'` \ ++ $GREP -o '[* ][* ]*[a-zA-Z][0-9a-zA-Z_]* *[,;=]' |\ ++ sed 's/.[* ]*\([a-zA-Z][0-9a-zA-Z_]*\) *[,;=]/\1/') \ + ; do +- echo $i | grep '^NULL$' && continue +- egrep $i' *(\+|-|\*|/|\||&|%|)=[^=]' $* >/dev/null || echo "possibly never written:"$i >> $TMP +- egrep '(=|\(|return).*'$i'(==|[^=])*$' $* >/dev/null || echo "possibly never read :"$i >> $TMP +- egrep -o $i' *((\+|-|\*|/|\||&|%|)=[^=]|\+\+|--) *(0x|)[0-9]*(;|)' $* |\ +- egrep -v $i' *= *(0x|)[0-9]{1,};'>/dev/null || echo "possibly constant :"$i >> $TMP ++ echo $i | $GREP '^NULL$' && continue ++ $EGREP $i' *(\+|-|\*|/|\||&|%|)=[^=]' $* >/dev/null || echo "possibly never written:"$i >> $TMP ++ $EGREP '(=|\(|return).*'$i'(==|[^=])*$' $* >/dev/null || echo "possibly never read :"$i >> $TMP ++ $EGREP -o $i' *((\+|-|\*|/|\||&|%|)=[^=]|\+\+|--) *(0x|)[0-9]*(;|)' $* |\ ++ $EGREP -v $i' *= *(0x|)[0-9]{1,};'>/dev/null || echo "possibly constant :"$i >> $TMP + done + if test -e $TMP ; then + printf '\npossibly unused variables\n' + cat $TMP + fi + +-grep '^+++ .*Changelog' $* >/dev/null || printf "\nMissing changelog entry (ignore if minor change)\n" ++$GREP '^+++ .*Changelog' $* >/dev/null || printf "\nMissing changelog entry (ignore if minor change)\n" + +-cat $* | tr '\n' '@' | egrep --color=always -o '(fprintf|av_log|printf)\([^)]*\)[+ ;@]*\1' >$TMP && printf "\nMergeable calls\n" ++cat $* | tr '\n' '@' | $EGREP --color=always -o '(fprintf|av_log|printf)\([^)]*\)[+ ;@]*\1' >$TMP && printf "\nMergeable calls\n" + cat $TMP | tr '@' '\n' + +-cat $* | tr '\n' '@' | egrep --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *[0-9]* *\) * \1 *= *[0-9]* *;[ @\\+]*else *if *\( *\1 *[<>]=? *[0-9]* *\) *\1 *= *[0-9]* *;' >$TMP && printf "\nav_clip / av_clip_uint8 / av_clip_int16 / ...\n" ++cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *[0-9]* *\) * \1 *= *[0-9]* *;[ @\\+]*else *if *\( *\1 *[<>]=? *[0-9]* *\) *\1 *= *[0-9]* *;' >$TMP && printf "\nav_clip / av_clip_uint8 / av_clip_int16 / ...\n" + cat $TMP | tr '@' '\n' + +-cat $* | tr '\n' '@' | egrep --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *([A-Za-z0-9_]*) *\)[ @\\+]*(\1|\2) *= *(\1|\2) *;' >$TMP && printf "\nFFMIN/FFMAX\n" ++cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *[<>]=? *([A-Za-z0-9_]*) *\)[ @\\+]*(\1|\2) *= *(\1|\2) *;' >$TMP && printf "\nFFMIN/FFMAX\n" + cat $TMP | tr '@' '\n' + +-cat $* | tr '\n' '@' | egrep --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *\)[ @\\+]*av_free(p|) *\( *(&|) *\1[^-.]' >$TMP && printf "\nav_free(NULL) is safe\n" ++cat $* | tr '\n' '@' | $EGREP --color=always -o '\+ *if *\( *([A-Za-z0-9_]*) *\)[ @\\+]*av_free(p|) *\( *(&|) *\1[^-.]' >$TMP && printf "\nav_free(NULL) is safe\n" + cat $TMP | tr '@' '\n' + +-cat $* | tr '\n' '@' | egrep --color=always -o '[^a-zA-Z0-9_]([a-zA-Z0-9_]*) *= *av_malloc *\([^)]*\)[ @;\\+]*memset *\( *\1' >$TMP && printf "\nav_mallocz()\n" ++cat $* | tr '\n' '@' | $EGREP --color=always -o '[^a-zA-Z0-9_]([a-zA-Z0-9_]*) *= *av_malloc *\([^)]*\)[ @;\\+]*memset *\( *\1' >$TMP && printf "\nav_mallocz()\n" + cat $TMP | tr '@' '\n' + + + # doesnt work +-#cat $* | tr '\n' '@' | egrep -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1' | egrep -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1 *=[^=]' >$TMP && printf "\nPossibly written 2x before read\n" ++#cat $* | tr '\n' '@' | $EGREP -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1' | $EGREP -o '[^a-zA-Z_0-9]([a-zA-Z][a-zA-Z_0-9]*) *=[^=].*\1 *=[^=]' >$TMP && printf "\nPossibly written 2x before read\n" + #cat $TMP | tr '@' '\n' + + exit +@@ -163,7 +167,7 @@ + TODO/idea list: + + for all demuxers & muxers +- grep for "avctx->priv_data" ++ $EGREP for "avctx->priv_data" + + vertical align = + /* and * align +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/pktdumper.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/pktdumper.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/pktdumper.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/pktdumper.c 2012-05-14 14:08:55.841370312 +0200 +@@ -24,11 +24,10 @@ + #include + #include + #include +-#include "libavformat/avformat.h" + +-#define PKTFILESUFF "_%08"PRId64"_%02d_%010"PRId64"_%06d_%c.bin" ++#include "libavformat/avformat.h" + +-#undef strcat ++#define PKTFILESUFF "_%08" PRId64 "_%02d_%010" PRId64 "_%06d_%c.bin" + + static int usage(int ret) + { +@@ -44,12 +43,12 @@ + { + char fntemplate[PATH_MAX]; + char pktfilename[PATH_MAX]; +- AVFormatContext *fctx; ++ AVFormatContext *fctx = NULL; + AVPacket pkt; +- int64_t pktnum = 0; ++ int64_t pktnum = 0; + int64_t maxpkts = 0; +- int donotquit = 0; +- int nowrite = 0; ++ int donotquit = 0; ++ int nowrite = 0; + int err; + + if ((argc > 1) && !strncmp(argv[1], "-", 1)) { +@@ -64,16 +63,16 @@ + return usage(1); + if (argc > 2) + maxpkts = atoi(argv[2]); +- strncpy(fntemplate, argv[1], PATH_MAX-1); ++ strncpy(fntemplate, argv[1], PATH_MAX - 1); + if (strrchr(argv[1], '/')) +- strncpy(fntemplate, strrchr(argv[1], '/')+1, PATH_MAX-1); ++ strncpy(fntemplate, strrchr(argv[1], '/') + 1, PATH_MAX - 1); + if (strrchr(fntemplate, '.')) + *strrchr(fntemplate, '.') = '\0'; + if (strchr(fntemplate, '%')) { + fprintf(stderr, "can't use filenames containing '%%'\n"); + return usage(1); + } +- if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX-1) { ++ if (strlen(fntemplate) + sizeof(PKTFILESUFF) >= PATH_MAX - 1) { + fprintf(stderr, "filename too long\n"); + return usage(1); + } +@@ -83,15 +82,15 @@ + // register all file formats + av_register_all(); + +- err = av_open_input_file(&fctx, argv[1], NULL, 0, NULL); ++ err = avformat_open_input(&fctx, argv[1], NULL, NULL); + if (err < 0) { +- fprintf(stderr, "av_open_input_file: error %d\n", err); ++ fprintf(stderr, "cannot open input: error %d\n", err); + return 1; + } + +- err = av_find_stream_info(fctx); ++ err = avformat_find_stream_info(fctx, NULL); + if (err < 0) { +- fprintf(stderr, "av_find_stream_info: error %d\n", err); ++ fprintf(stderr, "avformat_find_stream_info: error %d\n", err); + return 1; + } + +@@ -99,12 +98,19 @@ + + while ((err = av_read_frame(fctx, &pkt)) >= 0) { + int fd; +- snprintf(pktfilename, PATH_MAX-1, fntemplate, pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & AV_PKT_FLAG_KEY)?'K':'_'); +- printf(PKTFILESUFF"\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, (pkt.flags & AV_PKT_FLAG_KEY)?'K':'_'); ++ snprintf(pktfilename, PATH_MAX - 1, fntemplate, pktnum, ++ pkt.stream_index, pkt.pts, pkt.size, ++ (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); ++ printf(PKTFILESUFF "\n", pktnum, pkt.stream_index, pkt.pts, pkt.size, ++ (pkt.flags & AV_PKT_FLAG_KEY) ? 'K' : '_'); + //printf("open(\"%s\")\n", pktfilename); + if (!nowrite) { +- fd = open(pktfilename, O_WRONLY|O_CREAT, 0644); +- write(fd, pkt.data, pkt.size); ++ fd = open(pktfilename, O_WRONLY | O_CREAT, 0644); ++ err = write(fd, pkt.data, pkt.size); ++ if (err < 0) { ++ fprintf(stderr, "write: error %d\n", err); ++ return 1; ++ } + close(fd); + } + av_free_packet(&pkt); +@@ -113,10 +119,10 @@ + break; + } + +- av_close_input_file(fctx); ++ avformat_close_input(&fctx); + + while (donotquit) +- sleep(60); ++ usleep(60 * 1000000); + + return 0; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/probetest.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/probetest.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/probetest.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/probetest.c 2012-05-14 14:08:55.841370312 +0200 +@@ -39,7 +39,8 @@ + int score = fmt->read_probe(pd); + if (score > score_array[i] && score > AVPROBE_SCORE_MAX / 4) { + score_array[i] = score; +- fprintf(stderr, "Failure of %s probing code with score=%d type=%d p=%X size=%d\n", ++ fprintf(stderr, ++ "Failure of %s probing code with score=%d type=%d p=%X size=%d\n", + fmt->name, score, type, p, size); + failures++; + } +@@ -75,9 +76,8 @@ + init_put_bits(&pb, pd.buf, size); + switch (type) { + case 0: +- for (i = 0; i < size * 8; i++) { ++ for (i = 0; i < size * 8; i++) + put_bits(&pb, 1, (av_lfg_get(&state) & 0xFFFFFFFF) > p << 20); +- } + break; + case 1: + for (i = 0; i < size * 8; i++) { +@@ -89,10 +89,10 @@ + break; + case 2: + for (i = 0; i < size * 8; i++) { +- unsigned int p2 = (p >> (hist*3)) & 7; ++ unsigned int p2 = (p >> (hist * 3)) & 7; + unsigned int v = (av_lfg_get(&state) & 0xFFFFFFFF) > p2 << 29; + put_bits(&pb, 1, v); +- hist = (2*hist + v) & 3; ++ hist = (2 * hist + v) & 3; + } + break; + case 3: +@@ -100,12 +100,18 @@ + int c = 0; + while (p & 63) { + c = (av_lfg_get(&state) & 0xFFFFFFFF) >> 24; +- if (c >= 'a' && c <= 'z' && (p & 1)) break; +- else if(c >= 'A' && c <= 'Z' && (p & 2)) break; +- else if(c >= '0' && c <= '9' && (p & 4)) break; +- else if(c == ' ' && (p & 8)) break; +- else if(c == 0 && (p & 16)) break; +- else if(c == 1 && (p & 32)) break; ++ if (c >= 'a' && c <= 'z' && (p & 1)) ++ break; ++ else if (c >= 'A' && c <= 'Z' && (p & 2)) ++ break; ++ else if (c >= '0' && c <= '9' && (p & 4)) ++ break; ++ else if (c == ' ' && (p & 8)) ++ break; ++ else if (c == 0 && (p & 16)) ++ break; ++ else if (c == 1 && (p & 32)) ++ break; + } + pd.buf[i] = c; + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/qt-faststart.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/qt-faststart.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/qt-faststart.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/qt-faststart.c 2012-05-14 14:08:55.843370352 +0200 +@@ -30,29 +30,31 @@ + #include + + #ifdef __MINGW32__ +-#define fseeko(x,y,z) fseeko64(x,y,z) +-#define ftello(x) ftello64(x) ++#define fseeko(x, y, z) fseeko64(x, y, z) ++#define ftello(x) ftello64(x) + #endif + +-#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) +-#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ +- (((uint8_t*)(x))[1] << 16) | \ +- (((uint8_t*)(x))[2] << 8) | \ ++#define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) ++ ++#define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ ++ (((uint8_t*)(x))[1] << 16) | \ ++ (((uint8_t*)(x))[2] << 8) | \ + ((uint8_t*)(x))[3]) +-#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ +- ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ +- ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ +- ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ +- ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ +- ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ +- ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ +- ((uint64_t)((uint8_t*)(x))[7])) +- +-#define BE_FOURCC( ch0, ch1, ch2, ch3 ) \ +- ( (uint32_t)(unsigned char)(ch3) | \ +- ( (uint32_t)(unsigned char)(ch2) << 8 ) | \ +- ( (uint32_t)(unsigned char)(ch1) << 16 ) | \ +- ( (uint32_t)(unsigned char)(ch0) << 24 ) ) ++ ++#define BE_64(x) (((uint64_t)(((uint8_t*)(x))[0]) << 56) | \ ++ ((uint64_t)(((uint8_t*)(x))[1]) << 48) | \ ++ ((uint64_t)(((uint8_t*)(x))[2]) << 40) | \ ++ ((uint64_t)(((uint8_t*)(x))[3]) << 32) | \ ++ ((uint64_t)(((uint8_t*)(x))[4]) << 24) | \ ++ ((uint64_t)(((uint8_t*)(x))[5]) << 16) | \ ++ ((uint64_t)(((uint8_t*)(x))[6]) << 8) | \ ++ ((uint64_t)( (uint8_t*)(x))[7])) ++ ++#define BE_FOURCC(ch0, ch1, ch2, ch3) \ ++ ( (uint32_t)(unsigned char)(ch3) | \ ++ ((uint32_t)(unsigned char)(ch2) << 8) | \ ++ ((uint32_t)(unsigned char)(ch1) << 16) | \ ++ ((uint32_t)(unsigned char)(ch0) << 24) ) + + #define QT_ATOM BE_FOURCC + /* top level atoms */ +@@ -71,16 +73,16 @@ + #define STCO_ATOM QT_ATOM('s', 't', 'c', 'o') + #define CO64_ATOM QT_ATOM('c', 'o', '6', '4') + +-#define ATOM_PREAMBLE_SIZE 8 +-#define COPY_BUFFER_SIZE 1024 ++#define ATOM_PREAMBLE_SIZE 8 ++#define COPY_BUFFER_SIZE 1024 + + int main(int argc, char *argv[]) + { + FILE *infile = NULL; + FILE *outfile = NULL; + unsigned char atom_bytes[ATOM_PREAMBLE_SIZE]; +- uint32_t atom_type = 0; +- uint64_t atom_size = 0; ++ uint32_t atom_type = 0; ++ uint64_t atom_size = 0; + uint64_t atom_offset = 0; + uint64_t last_offset; + unsigned char *moov_atom = NULL; +@@ -95,7 +97,7 @@ + int bytes_to_copy; + + if (argc != 3) { +- printf ("Usage: qt-faststart \n"); ++ printf("Usage: qt-faststart \n"); + return 0; + } + +@@ -116,7 +118,7 @@ + if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { + break; + } +- atom_size = (uint32_t)BE_32(&atom_bytes[0]); ++ atom_size = (uint32_t) BE_32(&atom_bytes[0]); + atom_type = BE_32(&atom_bytes[4]); + + /* keep ftyp atom */ +@@ -125,8 +127,8 @@ + free(ftyp_atom); + ftyp_atom = malloc(ftyp_atom_size); + if (!ftyp_atom) { +- printf ("could not allocate %"PRIu64" byte for ftyp atom\n", +- atom_size); ++ printf("could not allocate %"PRIu64" bytes for ftyp atom\n", ++ atom_size); + goto error_out; + } + fseeko(infile, -ATOM_PREAMBLE_SIZE, SEEK_CUR); +@@ -136,18 +138,17 @@ + } + start_offset = ftello(infile); + } else { +- +- /* 64-bit special case */ +- if (atom_size == 1) { +- if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { +- break; ++ /* 64-bit special case */ ++ if (atom_size == 1) { ++ if (fread(atom_bytes, ATOM_PREAMBLE_SIZE, 1, infile) != 1) { ++ break; ++ } ++ atom_size = BE_64(&atom_bytes[0]); ++ fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); ++ } else { ++ fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); + } +- atom_size = BE_64(&atom_bytes[0]); +- fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE * 2, SEEK_CUR); +- } else { +- fseeko(infile, atom_size - ATOM_PREAMBLE_SIZE, SEEK_CUR); + } +- } + printf("%c%c%c%c %10"PRIu64" %"PRIu64"\n", + (atom_type >> 24) & 255, + (atom_type >> 16) & 255, +@@ -165,7 +166,7 @@ + (atom_type != PICT_ATOM) && + (atom_type != UUID_ATOM) && + (atom_type != FTYP_ATOM)) { +- printf ("encountered non-QT top-level atom (is this a Quicktime file?)\n"); ++ printf("encountered non-QT top-level atom (is this a QuickTime file?)\n"); + break; + } + atom_offset += atom_size; +@@ -178,7 +179,7 @@ + } + + if (atom_type != MOOV_ATOM) { +- printf ("last atom in file was not a moov atom\n"); ++ printf("last atom in file was not a moov atom\n"); + free(ftyp_atom); + fclose(infile); + return 0; +@@ -187,12 +188,11 @@ + /* moov atom was, in fact, the last atom in the chunk; load the whole + * moov atom */ + fseeko(infile, -atom_size, SEEK_END); +- last_offset = ftello(infile); ++ last_offset = ftello(infile); + moov_atom_size = atom_size; +- moov_atom = malloc(moov_atom_size); ++ moov_atom = malloc(moov_atom_size); + if (!moov_atom) { +- printf ("could not allocate %"PRIu64" byte for moov atom\n", +- atom_size); ++ printf("could not allocate %"PRIu64" bytes for moov atom\n", atom_size); + goto error_out; + } + if (fread(moov_atom, atom_size, 1, infile) != 1) { +@@ -203,7 +203,7 @@ + /* this utility does not support compressed atoms yet, so disqualify + * files with compressed QT atoms */ + if (BE_32(&moov_atom[12]) == CMOV_ATOM) { +- printf ("this utility does not support compressed moov atoms yet\n"); ++ printf("this utility does not support compressed moov atoms yet\n"); + goto error_out; + } + +@@ -215,15 +215,15 @@ + for (i = 4; i < moov_atom_size - 4; i++) { + atom_type = BE_32(&moov_atom[i]); + if (atom_type == STCO_ATOM) { +- printf (" patching stco atom...\n"); ++ printf(" patching stco atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { +- printf (" bad atom size\n"); ++ printf(" bad atom size\n"); + goto error_out; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { +- current_offset = BE_32(&moov_atom[i + 12 + j * 4]); ++ current_offset = BE_32(&moov_atom[i + 12 + j * 4]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 4 + 0] = (current_offset >> 24) & 0xFF; + moov_atom[i + 12 + j * 4 + 1] = (current_offset >> 16) & 0xFF; +@@ -232,15 +232,15 @@ + } + i += atom_size - 4; + } else if (atom_type == CO64_ATOM) { +- printf (" patching co64 atom...\n"); ++ printf(" patching co64 atom...\n"); + atom_size = BE_32(&moov_atom[i - 4]); + if (i + atom_size - 4 > moov_atom_size) { +- printf (" bad atom size\n"); ++ printf(" bad atom size\n"); + goto error_out; + } + offset_count = BE_32(&moov_atom[i + 8]); + for (j = 0; j < offset_count; j++) { +- current_offset = BE_64(&moov_atom[i + 12 + j * 8]); ++ current_offset = BE_64(&moov_atom[i + 12 + j * 8]); + current_offset += moov_atom_size; + moov_atom[i + 12 + j * 8 + 0] = (current_offset >> 56) & 0xFF; + moov_atom[i + 12 + j * 8 + 1] = (current_offset >> 48) & 0xFF; +@@ -275,7 +275,7 @@ + + /* dump the same ftyp atom */ + if (ftyp_atom_size > 0) { +- printf (" writing ftyp atom...\n"); ++ printf(" writing ftyp atom...\n"); + if (fwrite(ftyp_atom, ftyp_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; +@@ -283,14 +283,14 @@ + } + + /* dump the new moov atom */ +- printf (" writing moov atom...\n"); ++ printf(" writing moov atom...\n"); + if (fwrite(moov_atom, moov_atom_size, 1, outfile) != 1) { + perror(argv[2]); + goto error_out; + } + + /* copy the remainder of the infile, from offset 0 -> last_offset - 1 */ +- printf (" copying rest of file...\n"); ++ printf(" copying rest of file...\n"); + while (last_offset) { + if (last_offset > COPY_BUFFER_SIZE) + bytes_to_copy = COPY_BUFFER_SIZE; +@@ -305,7 +305,6 @@ + perror(argv[2]); + goto error_out; + } +- + last_offset -= bytes_to_copy; + } + +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/tools/trasher.c xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/trasher.c +--- xbmc-pvr-11.0.1/lib/ffmpeg/tools/trasher.c 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/tools/trasher.c 2012-05-14 14:08:55.843370352 +0200 +@@ -23,47 +23,50 @@ + #include + + static uint32_t state; +-static uint32_t ran(void){ +- return state= state*1664525+1013904223; ++static uint32_t ran(void) ++{ ++ return state = state * 1664525 + 1013904223; + } + +-int main(int argc, char** argv) ++int main(int argc, char **argv) + { + FILE *f; + int count, maxburst, length; + +- if (argc < 5){ ++ if (argc < 5) { + printf("USAGE: trasher \n"); + return 1; + } + +- f= fopen(argv[1], "rb+"); +- if (!f){ ++ f = fopen(argv[1], "rb+"); ++ if (!f) { + perror(argv[1]); + return 2; + } +- count= atoi(argv[2]); +- maxburst= atoi(argv[3]); +- state= atoi(argv[4]); ++ count = atoi(argv[2]); ++ maxburst = atoi(argv[3]); ++ state = atoi(argv[4]); + + fseek(f, 0, SEEK_END); +- length= ftell(f); ++ length = ftell(f); + fseek(f, 0, SEEK_SET); + +- while(count--){ +- int burst= 1 + ran() * (uint64_t) (abs(maxburst)-1) / UINT32_MAX; +- int pos= ran() * (uint64_t) length / UINT32_MAX; ++ while (count--) { ++ int burst = 1 + ran() * (uint64_t) (abs(maxburst) - 1) / UINT32_MAX; ++ int pos = ran() * (uint64_t) length / UINT32_MAX; + fseek(f, pos, SEEK_SET); + +- if(maxburst<0) burst= -maxburst; ++ if (maxburst < 0) ++ burst = -maxburst; + +- if(pos + burst > length) ++ if (pos + burst > length) + continue; + +- while(burst--){ +- int val= ran() * 256ULL / UINT32_MAX; ++ while (burst--) { ++ int val = ran() * 256ULL / UINT32_MAX; + +- if(maxburst<0) val=0; ++ if (maxburst < 0) ++ val = 0; + + fwrite(&val, 1, 1, f); + } +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/VERSION xbmc-pvr-11.0.1.patch/lib/ffmpeg/VERSION +--- xbmc-pvr-11.0.1/lib/ffmpeg/VERSION 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/VERSION 2012-05-14 14:08:53.101315166 +0200 +@@ -0,0 +1 @@ ++0.10.2 +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/version.h xbmc-pvr-11.0.1.patch/lib/ffmpeg/version.h +--- xbmc-pvr-11.0.1/lib/ffmpeg/version.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/version.h 2012-05-14 14:08:55.844370372 +0200 +@@ -0,0 +1 @@ ++#define FFMPEG_VERSION "0.10.2" +diff -Naur xbmc-pvr-11.0.1/lib/ffmpeg/version.sh xbmc-pvr-11.0.1.patch/lib/ffmpeg/version.sh +--- xbmc-pvr-11.0.1/lib/ffmpeg/version.sh 2012-03-27 17:55:45.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/ffmpeg/version.sh 2012-05-14 14:08:55.844370372 +0200 +@@ -1,29 +1,32 @@ + #!/bin/sh + +-# check for SVN revision number +-revision=$(cd "$1" && cat snapshot_version 2> /dev/null) +-test "$revision" || revision=$(cd "$1" && LC_ALL=C svn info 2> /dev/null | grep "Last Changed Rev" | cut -d' ' -f4) +-test "$revision" || revision=$(cd "$1" && grep committed-rev .svn/entries 2>/dev/null | head -n 1 | cut -d '"' -f2) +-test "$revision" || revision=$(cd "$1" && sed -n -e '/^dir$/{n +-p +-q +-}' .svn/entries 2>/dev/null) +-test "$revision" && revision=SVN-r$revision +- +-# check for git svn revision number ++# check for git short hash + if ! test "$revision"; then +- revision=$(cd "$1" && git svn find-rev HEAD 2> /dev/null) +- test "$revision" && revision=git-svn-r$revision ++ revision=$(cd "$1" && git describe --tags --match N 2> /dev/null) + fi + +-# check for git short hash +-if ! test "$revision"; then +- revision=$(cd "$1" && git describe --always 2> /dev/null) +- test "$revision" && revision=git-$revision ++# Shallow Git clones (--depth) do not have the N tag: ++# use 'git-YYYY-MM-DD-hhhhhhh'. ++test "$revision" || revision=$(cd "$1" && ++ git log -1 --pretty=format:"git-%cd-%h" --date=short 2> /dev/null) ++ ++# Snapshots from gitweb are in a directory called ffmpeg-hhhhhhh or ++# ffmpeg-HEAD-hhhhhhh. ++if [ -z "$revision" ]; then ++ srcdir=$(cd "$1" && pwd) ++ case "$srcdir" in ++ */ffmpeg-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ++ git_hash="${srcdir##*-}";; ++ */ffmpeg-HEAD-[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]) ++ git_hash="${srcdir##*-}";; ++ esac + fi + + # no revision number found +-test "$revision" || revision=UNKNOWN ++test "$revision" || revision=$(cd "$1" && cat RELEASE 2> /dev/null) ++ ++# Append the Git hash if we have one ++test "$revision" && test "$git_hash" && revision="$revision-$git_hash" + + # releases extract the version number from the VERSION file + version=$(cd "$1" && cat VERSION 2> /dev/null) +diff -Naur xbmc-pvr-11.0.1/lib/Makefile.in xbmc-pvr-11.0.1.patch/lib/Makefile.in +--- xbmc-pvr-11.0.1/lib/Makefile.in 2012-03-27 17:55:43.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/Makefile.in 2012-05-14 14:08:56.013373773 +0200 +@@ -1,21 +1,18 @@ + ARCH=@ARCH@ + ++AR=@AR@ + LD=@LD@ + CC=@CC@ + CXX=@CXX@ +-SHELL=@SHELL@ +-ifeq ($(findstring osx,$(ARCH)),osx) +-ifeq ($(findstring arm,$(ARCH)),arm) +-LDFLAGS=-arch armv7 -iphoneos_version_min 4.1 -bundle -undefined dynamic_lookup -read_only_relocs suppress +-else +-LDFLAGS=-bundle -undefined dynamic_lookup -read_only_relocs suppress +-endif +-else +-LDFLAGS=-shared -fPIC -rdynamic +-endif + SYSDIR=@abs_top_srcdir@/system/players/dvdplayer +-WRAPPER=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper.o +-WRAPPER_MACH_ALIAS=@abs_top_srcdir@/xbmc/cores/DllLoader/exports/wrapper_mach_alias ++ ++AVFORMAT_SO=avformat-53-$(ARCH).so ++AVCODEC_SO=avcodec-53-$(ARCH).so ++AVUTIL_SO=avutil-51-$(ARCH).so ++AVFILTER_SO=avfilter-2-$(ARCH).so ++SWSCALE_SO=swscale-2-$(ARCH).so ++POSTPROC_SO=postproc-52-$(ARCH).so ++SWRESAMPLE_SO=swresample-0-$(ARCH).so + + DIRS= + ifneq (@USE_EXTERNAL_FFMPEG@,1) +@@ -24,123 +21,55 @@ + + LIBS= + ifneq (@USE_EXTERNAL_FFMPEG@,1) +- LIBS+=avutil-50-$(ARCH).so \ +- avcodec-52-$(ARCH).so \ +- avcore-0-$(ARCH).so \ +- avformat-52-$(ARCH).so \ +- postproc-51-$(ARCH).so \ +- avfilter-1-$(ARCH).so \ +- swscale-0-$(ARCH).so +-endif +- +-ifneq (,$(findstring powerpc,$(ARCH))) +- ARCH_DIR=ppc +-else +-ifeq ($(findstring arm,$(ARCH)),arm) +- ARCH_DIR=arm +-else +- ARCH_DIR=x86 +-endif ++ LIBS+=$(AVUTIL_SO) \ ++ $(AVCODEC_SO) \ ++ $(AVFORMAT_SO) \ ++ $(POSTPROC_SO) \ ++ $(AVFILTER_SO) \ ++ $(SWSCALE_SO) \ ++ $(SWRESAMPLE_SO) + endif + + .PHONY: $(DIRS) codecs + +-codecs: $(addprefix $(SYSDIR)/, $(LIBS)); +- +- +-ifeq ($(findstring osx,$(ARCH)), osx) +-# Add -lbundle1.o for powerpc-osx +-ifeq ($(ARCH), powerpc-osx) +-BUNDLE1_O = -lbundle1.o +-endif +- +-$(SYSDIR)/avutil-50-$(ARCH).so: $(WRAPPER) ffmpeg/libavutil/libavutil.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavutil/*.o \ +- ffmpeg/libavutil/$(ARCH_DIR)/*.o $(BUNDLE1_O) +- +-$(SYSDIR)/avcodec-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavcodec/libavcodec.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavcodec/*.o \ +- ffmpeg/libavcodec/$(ARCH_DIR)/*.o $(BUNDLE1_O) +- +-$(SYSDIR)/avcore-0-$(ARCH).so: $(WRAPPER) ffmpeg/libavcore/libavcore.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavcore/*.o $(BUNDLE1_O) +- +-$(SYSDIR)/avformat-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavformat/libavformat.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavformat/*.o $(BUNDLE1_O) +- +-ifeq ($(findstring x86,$(ARCH_DIR)), x86) +-$(SYSDIR)/avfilter-1-$(ARCH).so: $(WRAPPER) ffmpeg/libavfilter/libavfilter.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavfilter/$(ARCH_DIR)/*.o \ +- ffmpeg/libavfilter/*.o $(BUNDLE1_O) +-else # No libavfilter/ppc or libavfilter/arm +-$(SYSDIR)/avfilter-1-$(ARCH).so: $(WRAPPER) ffmpeg/libavfilter/libavfilter.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libavfilter/*.o $(BUNDLE1_O) +-endif ++ifneq ($(findstring osx,$(ARCH)), osx) + +-ifneq ($(findstring arm,$(ARCH)), arm) +-$(SYSDIR)/swscale-0-$(ARCH).so: $(WRAPPER) ffmpeg/libswscale/libswscale.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libswscale/*.o \ +- ffmpeg/libswscale/$(ARCH_DIR)/*.o $(BUNDLE1_O) +-else # No ARM version of swscale available yet. +-$(SYSDIR)/swscale-0-$(ARCH).so: $(WRAPPER) ffmpeg/libswscale/libswscale.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libswscale/*.o +-endif +- +-$(SYSDIR)/postproc-51-$(ARCH).so: $(WRAPPER) ffmpeg/libpostproc/libpostproc.dylib +- $(LD) $(LDFLAGS) -alias_list $(WRAPPER_MACH_ALIAS) -o $@ \ +- $(WRAPPER) ffmpeg/libpostproc/*.o $(BUNDLE1_O) +- +-ffmpeg/libavutil/libavutil.dylib : ffmpeg; +-ffmpeg/libavcodec/libavcodec.dylib : ffmpeg; +-ffmpeg/libavcore/libavcore.dylib : ffmpeg; +-ffmpeg/libavformat/libavformat.dylib : ffmpeg; +-ffmpeg/libavformat/libavfilter.dylib : ffmpeg; +-ffmpeg/libswscale/libswscale.dylib : ffmpeg; +-ffmpeg/libpostproc/libpostproc.dylib : ffmpeg; +-ffmpeg: +- $(MAKE) -C $@ +- +-else ++codecs: $(addprefix $(SYSDIR)/, $(LIBS)); + +-$(SYSDIR)/avutil-50-$(ARCH).so: ffmpeg/libavutil/libavutil.so ++$(SYSDIR)/$(AVUTIL_SO): ffmpeg/libavutil/libavutil.so + cp ffmpeg/libavutil/libavutil.so $@ + +-$(SYSDIR)/avcodec-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavcodec/libavcodec.so ++$(SYSDIR)/$(AVCODEC_SO): ffmpeg/libavcodec/libavcodec.so + cp ffmpeg/libavcodec/libavcodec.so $@ + +-$(SYSDIR)/avcore-0-$(ARCH).so: $(WRAPPER) ffmpeg/libavcore/libavcore.so +- cp ffmpeg/libavcore/libavcore.so $@ +- +-$(SYSDIR)/avformat-52-$(ARCH).so: $(WRAPPER) ffmpeg/libavformat/libavformat.so ++$(SYSDIR)/$(AVFORMAT_SO): ffmpeg/libavformat/libavformat.so + cp ffmpeg/libavformat/libavformat.so $@ + +-$(SYSDIR)/avfilter-1-$(ARCH).so: $(WRAPPER) ffmpeg/libavfilter/libavfilter.so ++$(SYSDIR)/$(AVFILTER_SO): ffmpeg/libavfilter/libavfilter.so + cp ffmpeg/libavfilter/libavfilter.so $@ + +-$(SYSDIR)/swscale-0-$(ARCH).so: $(WRAPPER) ffmpeg/libswscale/libswscale.so ++$(SYSDIR)/$(SWSCALE_SO): ffmpeg/libswscale/libswscale.so + cp ffmpeg/libswscale/libswscale.so $@ + +-$(SYSDIR)/postproc-51-$(ARCH).so: $(WRAPPER) ffmpeg/libpostproc/libpostproc.so ++$(SYSDIR)/$(POSTPROC_SO): ffmpeg/libpostproc/libpostproc.so + cp ffmpeg/libpostproc/libpostproc.so $@ + ++$(SYSDIR)/$(SWRESAMPLE_SO): ffmpeg/libswresample/libswresample.so ++ cp ffmpeg/libswresample/libswresample.so $@ ++ + ffmpeg/libavutil/libavutil.so : ffmpeg; + ffmpeg/libavcodec/libavcodec.so : ffmpeg; +-ffmpeg/libavcore/libavcore.so : ffmpeg; + ffmpeg/libavformat/libavformat.so : ffmpeg; + ffmpeg/libavfilter/libavfilter.so : ffmpeg; + ffmpeg/libswscale/libswscale.so : ffmpeg; + ffmpeg/libpostproc/libpostproc.so : ffmpeg; ++ffmpeg/libswresample/libswresample.so : ffmpeg; ++endif ++ + ffmpeg: + $(MAKE) -C $@ +- ++ifeq ($(findstring osx,$(ARCH)), osx) ++ $(AR) d ffmpeg/libavcodec/libavcodec.a inverse.o + endif + + clean: +diff -Naur xbmc-pvr-11.0.1/xbmc/cdrip/EncoderFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cdrip/EncoderFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cdrip/EncoderFFmpeg.cpp 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cdrip/EncoderFFmpeg.cpp 2012-05-14 14:08:55.986373230 +0200 +@@ -59,11 +59,7 @@ + + CStdString filename = URIUtils::GetFileName(strFile); + AVOutputFormat *fmt = NULL; +-#if LIBAVFORMAT_VERSION_MAJOR < 52 +- fmt = m_dllAvFormat.guess_format(NULL, filename.c_str(), NULL); +-#else + fmt = m_dllAvFormat.av_guess_format(NULL, filename.c_str(), NULL); +-#endif + if (!fmt) + { + CLog::Log(LOGERROR, "CEncoderFFmpeg::Init - Unable to guess the output format for the file %s", filename.c_str()); +@@ -82,7 +78,7 @@ + } + + m_Format = m_dllAvFormat.avformat_alloc_context(); +- m_Format->pb = m_dllAvFormat.av_alloc_put_byte(m_BCBuffer, sizeof(m_BCBuffer), URL_RDONLY, this, NULL, MuxerReadPacket, NULL); ++ m_Format->pb = m_dllAvFormat.avio_alloc_context(m_BCBuffer, sizeof(m_BCBuffer), AVIO_FLAG_READ, this, NULL, MuxerReadPacket, NULL); + if (!m_Format->pb) + { + m_dllAvUtil.av_freep(&m_Format); +@@ -93,17 +89,8 @@ + m_Format->oformat = fmt; + m_Format->bit_rate = g_guiSettings.GetInt("audiocds.bitrate") * 1000; + +- /* setup the muxer */ +- if (m_dllAvFormat.av_set_parameters(m_Format, NULL) != 0) +- { +- m_dllAvUtil.av_freep(&m_Format->pb); +- m_dllAvUtil.av_freep(&m_Format); +- CLog::Log(LOGERROR, "CEncoderFFmpeg::Init - Failed to set the muxer parameters"); +- return false; +- } +- + /* add a stream to it */ +- m_Stream = m_dllAvFormat.av_new_stream(m_Format, 1); ++ m_Stream = m_dllAvFormat.avformat_new_stream(m_Format, codec); + if (!m_Stream) + { + m_dllAvUtil.av_freep(&m_Format->pb); +@@ -144,7 +131,7 @@ + return false; + } + +- if (m_dllAvCodec.avcodec_open(m_CodecCtx, codec)) ++ if (m_dllAvCodec.avcodec_open2(m_CodecCtx, codec, NULL)) + { + CLog::Log(LOGERROR, "CEncoderFFmpeg::Init - Failed to open the codec"); + m_dllAvUtil.av_freep(&m_Stream); +@@ -179,7 +166,7 @@ + SetTag("encoder" , "XBMC FFmpeg Encoder"); + + /* write the header */ +- if (m_dllAvFormat.av_write_header(m_Format) != 0) ++ if (m_dllAvFormat.avformat_write_header(m_Format, NULL) != 0) + { + CLog::Log(LOGERROR, "CEncoderFFmpeg::Init - Failed to write the header"); + delete[] m_Buffer; +@@ -194,7 +181,7 @@ + + void CEncoderFFmpeg::SetTag(const CStdString tag, const CStdString value) + { +- m_dllAvFormat.av_metadata_set2(&m_Format->metadata, tag.c_str(), value.c_str(), 0); ++ m_dllAvUtil.av_dict_set(&m_Format->metadata, tag.c_str(), value.c_str(), 0); + } + + int CEncoderFFmpeg::MuxerReadPacket(void *opaque, uint8_t *buf, int buf_size) +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.cpp 2012-05-14 14:08:56.016373834 +0200 +@@ -29,10 +29,6 @@ + + CDVDAudioCodecFFmpeg::CDVDAudioCodecFFmpeg() : CDVDAudioCodec() + { +- m_iBufferSize1 = 0; +- m_pBuffer1 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16); +- memset(m_pBuffer1, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); +- + m_iBufferSize2 = 0; + m_pBuffer2 = (BYTE*)_aligned_malloc(AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE, 16); + memset(m_pBuffer2, 0, AVCODEC_MAX_AUDIO_FRAME_SIZE + FF_INPUT_BUFFER_PADDING_SIZE); +@@ -45,11 +41,11 @@ + m_channelMap[0] = PCM_INVALID; + m_channels = 0; + m_layout = 0; ++ m_pFrame1 = NULL; + } + + CDVDAudioCodecFFmpeg::~CDVDAudioCodecFFmpeg() + { +- _aligned_free(m_pBuffer1); + _aligned_free(m_pBuffer2); + Dispose(); + } +@@ -59,12 +55,10 @@ + AVCodec* pCodec; + m_bOpenedCodec = false; + +- if (!m_dllAvCore.Load() || !m_dllAvUtil.Load() || !m_dllAvCodec.Load()) ++ if (!m_dllAvUtil.Load() || !m_dllAvCodec.Load()) + return false; + + m_dllAvCodec.avcodec_register_all(); +- m_pCodecContext = m_dllAvCodec.avcodec_alloc_context(); +- m_dllAvCodec.avcodec_get_context_defaults(m_pCodecContext); + + pCodec = m_dllAvCodec.avcodec_find_decoder(hints.codec); + if (!pCodec) +@@ -73,6 +67,7 @@ + return false; + } + ++ m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec); + m_pCodecContext->debug_mv = 0; + m_pCodecContext->debug = 0; + m_pCodecContext->workaround_bugs = 1; +@@ -97,13 +92,14 @@ + memcpy(m_pCodecContext->extradata, hints.extradata, hints.extrasize); + } + +- if (m_dllAvCodec.avcodec_open(m_pCodecContext, pCodec) < 0) ++ if (m_dllAvCodec.avcodec_open2(m_pCodecContext, pCodec, NULL) < 0) + { + CLog::Log(LOGDEBUG,"CDVDAudioCodecFFmpeg::Open() Unable to open codec"); + Dispose(); + return false; + } + ++ m_pFrame1 = m_dllAvCodec.avcodec_alloc_frame(); + m_bOpenedCodec = true; + m_iSampleFormat = AV_SAMPLE_FMT_NONE; + return true; +@@ -111,6 +107,9 @@ + + void CDVDAudioCodecFFmpeg::Dispose() + { ++ if (m_pFrame1) m_dllAvUtil.av_free(m_pFrame1); ++ m_pFrame1 = NULL; ++ + if (m_pConvert) + { + m_dllAvCodec.av_audio_convert_free(m_pConvert); +@@ -135,7 +134,7 @@ + + int CDVDAudioCodecFFmpeg::Decode(BYTE* pData, int iSize) + { +- int iBytesUsed; ++ int iBytesUsed, got_frame; + if (!m_pCodecContext) return -1; + + m_iBufferSize1 = AVCODEC_MAX_AUDIO_FRAME_SIZE ; +@@ -145,10 +144,17 @@ + m_dllAvCodec.av_init_packet(&avpkt); + avpkt.data = pData; + avpkt.size = iSize; +- iBytesUsed = m_dllAvCodec.avcodec_decode_audio3( m_pCodecContext +- , (int16_t*)m_pBuffer1 +- , &m_iBufferSize1 ++ iBytesUsed = m_dllAvCodec.avcodec_decode_audio4( m_pCodecContext ++ , m_pFrame1 ++ , &got_frame + , &avpkt); ++ if (iBytesUsed < 0 || !got_frame) ++ { ++ m_iBufferSize1 = 0; ++ m_iBufferSize2 = 0; ++ return iBytesUsed; ++ } ++ m_iBufferSize1 = m_dllAvUtil.av_samples_get_buffer_size(NULL, m_pCodecContext->channels, m_pFrame1->nb_samples, m_pCodecContext->sample_fmt, 1); + + /* some codecs will attempt to consume more data than what we gave */ + if (iBytesUsed > iSize) +@@ -184,9 +190,9 @@ + return iBytesUsed; + } + +- const void *ibuf[6] = { m_pBuffer1 }; ++ const void *ibuf[6] = { m_pFrame1->data[0] }; + void *obuf[6] = { m_pBuffer2 }; +- int istr[6] = { m_dllAvCore.av_get_bits_per_sample_fmt(m_pCodecContext->sample_fmt)/8 }; ++ int istr[6] = { m_dllAvUtil.av_get_bytes_per_sample(m_pCodecContext->sample_fmt) }; + int ostr[6] = { 2 }; + int len = m_iBufferSize1 / istr[0]; + if(m_dllAvCodec.av_audio_convert(m_pConvert, obuf, ostr, ibuf, istr, len) < 0) +@@ -208,7 +214,7 @@ + { + if(m_iBufferSize1) + { +- *dst = m_pBuffer1; ++ *dst = m_pFrame1->data[0]; + return m_iBufferSize1; + } + if(m_iBufferSize2) +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecFFmpeg.h 2012-05-14 14:08:56.005373612 +0200 +@@ -23,7 +23,6 @@ + + #include "DVDAudioCodec.h" + #include "DllAvCodec.h" +-#include "DllAvCore.h" + #include "DllAvFormat.h" + #include "DllAvUtil.h" + +@@ -51,7 +50,7 @@ + enum AVSampleFormat m_iSampleFormat; + enum PCMChannels m_channelMap[PCM_MAX_CH + 1]; + +- BYTE *m_pBuffer1; ++ AVFrame* m_pFrame1; + int m_iBufferSize1; + + BYTE *m_pBuffer2; +@@ -64,7 +63,6 @@ + int64_t m_layout; + + DllAvCodec m_dllAvCodec; +- DllAvCore m_dllAvCore; + DllAvUtil m_dllAvUtil; + + void BuildChannelMap(); +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecPassthroughFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecPassthroughFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecPassthroughFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/DVDAudioCodecPassthroughFFmpeg.cpp 2012-05-14 14:08:55.995373412 +0200 +@@ -79,11 +79,7 @@ + /* get the muxer */ + AVOutputFormat *fOut = NULL; + +-#if LIBAVFORMAT_VERSION_MAJOR < 52 +- fOut = m_dllAvFormat.guess_format(muxerName.c_str(), NULL, NULL); +-#else + fOut = m_dllAvFormat.av_guess_format(muxerName.c_str(), NULL, NULL); +-#endif + if (!fOut) + { + CLog::Log(LOGERROR, "CDVDAudioCodecPassthroughFFmpeg::SetupMuxer - Failed to get the FFmpeg %s muxer", muxerName.c_str()); +@@ -103,7 +99,7 @@ + muxer.m_pFormat->oformat = fOut; + + /* allocate a put_byte struct so we can grab the output */ +- muxer.m_pFormat->pb = m_dllAvFormat.av_alloc_put_byte(muxer.m_BCBuffer, sizeof(muxer.m_BCBuffer), URL_RDONLY, &muxer, NULL, MuxerReadPacket, NULL); ++ muxer.m_pFormat->pb = m_dllAvFormat.avio_alloc_context(muxer.m_BCBuffer, sizeof(muxer.m_BCBuffer), AVIO_FLAG_READ, &muxer, NULL, MuxerReadPacket, NULL); + if (!muxer.m_pFormat->pb) + { + CLog::Log(LOGERROR, "CDVDAudioCodecPassthroughFFmpeg::SetupMuxer - Failed to allocate ByteIOContext"); +@@ -112,21 +108,10 @@ + } + + /* this is streamed, no file, and ignore the index */ +- muxer.m_pFormat->pb->is_streamed = 1; ++ muxer.m_pFormat->pb->seekable = 0; + muxer.m_pFormat->flags |= AVFMT_NOFILE | AVFMT_FLAG_IGNIDX; + muxer.m_pFormat->bit_rate = hints.bitrate; + +- /* setup the muxer */ +- if (m_dllAvFormat.av_set_parameters(muxer.m_pFormat, NULL) != 0) +- { +- CLog::Log(LOGERROR, "CDVDAudioCodecPassthroughFFmpeg::SetupMuxer - Failed to set the %s muxer parameters", muxerName.c_str()); +- Dispose(); +- return false; +- } +- +-#if LIBAVFORMAT_VERSION_INT >= AV_VERSION_INT(52,92,0) +- // API added on: 2011-01-02 +- + /* While this is strictly only needed on big-endian systems, we do it on + * both to avoid as much dead code as possible. + * CoreAudio (at least on the cases we've seen) wants IEC 61937 in +@@ -138,8 +123,7 @@ + #endif + + /* request output of wanted endianness */ +- if (!fOut->priv_class || m_dllAvUtil.av_set_string3(muxer.m_pFormat->priv_data, "spdif_flags", spdifFlags, 0, NULL) != 0) +-#endif ++ if (!fOut->priv_class || m_dllAvUtil.av_opt_set(muxer.m_pFormat->priv_data, "spdif_flags", spdifFlags, 0) != 0) + { + #if defined(WORDS_BIGENDIAN) && !defined(__APPLE__) + CLog::Log(LOGERROR, "CDVDAudioCodecPassthroughFFmpeg::SetupMuxer - Unable to set big-endian stream mode (FFmpeg too old?), disabling passthrough"); +@@ -149,7 +133,7 @@ + } + + /* add a stream to it */ +- muxer.m_pStream = m_dllAvFormat.av_new_stream(muxer.m_pFormat, 1); ++ muxer.m_pStream = m_dllAvFormat.avformat_new_stream(muxer.m_pFormat, NULL); + if (!muxer.m_pStream) + { + CLog::Log(LOGERROR, "CDVDAudioCodecPassthroughFFmpeg::SetupMuxer - Failed to allocate AVStream context"); +@@ -159,8 +143,6 @@ + + + /* set the stream's parameters */ +- muxer.m_pStream->stream_copy = 1; +- + m_SampleRate = hints.samplerate; + if(!m_SampleRate && hints.codec == CODEC_ID_AC3) + m_SampleRate = 48000; +@@ -176,7 +158,7 @@ + codec->extradata_size = hints.extrasize; + memcpy(codec->extradata, hints.extradata, hints.extrasize); + +- muxer.m_WroteHeader = m_dllAvFormat.av_write_header(muxer.m_pFormat) == 0; ++ muxer.m_WroteHeader = m_dllAvFormat.avformat_write_header(muxer.m_pFormat, NULL) == 0; + if (!muxer.m_WroteHeader) + { + CLog::Log(LOGERROR, "CDVDAudioCodecPassthrough::SetupMuxer - Failed to write the frame header"); +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.cpp 2012-05-14 14:08:56.002373552 +0200 +@@ -55,7 +55,7 @@ + bool CDVDAudioEncoderFFmpeg::Initialize(unsigned int channels, enum PCMChannels *channelMap, unsigned int bitsPerSample, unsigned int sampleRate) + { + Reset(); +- if (!channelMap || !m_dllAvUtil.Load() || !m_dllAvCore.Load() || !m_dllAvCodec.Load()) ++ if (!channelMap || !m_dllAvUtil.Load() || !m_dllAvCodec.Load()) + return false; + + m_dllAvCodec.avcodec_register_all(); +@@ -65,7 +65,7 @@ + return false; + + /* always assume 6 channels, 5.1... m_remap will give us what we want */ +- m_CodecCtx = m_dllAvCodec.avcodec_alloc_context(); ++ m_CodecCtx = m_dllAvCodec.avcodec_alloc_context3(codec); + m_CodecCtx->bit_rate = AC3_ENCODE_BITRATE; + m_CodecCtx->sample_rate = sampleRate; + m_CodecCtx->channels = 6; +@@ -104,7 +104,7 @@ + } + } + +- if (m_dllAvCodec.avcodec_open(m_CodecCtx, codec)) ++ if (m_dllAvCodec.avcodec_open2(m_CodecCtx, codec, NULL)) + { + m_dllAvUtil.av_freep(&m_CodecCtx); + return false; +@@ -149,7 +149,7 @@ + + if (m_AudioConvert) + m_TmpBuffer2 = new uint8_t[m_NeededFrames * m_CodecCtx->channels * +- m_dllAvCore.av_get_bits_per_sample_fmt(m_CodecCtx->sample_fmt) / 8]; ++ m_dllAvUtil.av_get_bytes_per_sample(m_CodecCtx->sample_fmt)]; + + return true; + } +@@ -186,7 +186,7 @@ + void *convInBuf[] = { m_TmpBuffer }; + int convInStr[] = { m_BitsPerSample / 8 }; + void *convOutBuf[] = { m_TmpBuffer2 }; +- int convOutStr[] = { m_dllAvCore.av_get_bits_per_sample_fmt(m_CodecCtx->sample_fmt) / 8 }; ++ int convOutStr[] = { m_dllAvUtil.av_get_bytes_per_sample(m_CodecCtx->sample_fmt) }; + if (m_dllAvCodec.av_audio_convert(m_AudioConvert, convOutBuf, convOutStr, + convInBuf, convInStr, m_NeededFrames * m_CodecCtx->channels) < 0) { + CLog::Log(LOGERROR, "CDVDAudioEncoderFFmpeg: Audio conversion failed"); +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Audio/Encoders/DVDAudioEncoderFFmpeg.h 2012-05-14 14:08:55.849370473 +0200 +@@ -43,7 +43,6 @@ + virtual int GetData(uint8_t **data); + private: + DllAvCodec m_dllAvCodec; +- DllAvCore m_dllAvCore; + DllAvUtil m_dllAvUtil; + + AVCodecContext *m_CodecCtx; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Overlay/DVDOverlayCodecFFmpeg.cpp 2012-05-14 14:08:55.936372223 +0200 +@@ -49,7 +49,14 @@ + + m_dllAvCodec.avcodec_register_all(); + +- m_pCodecContext = m_dllAvCodec.avcodec_alloc_context(); ++ AVCodec* pCodec = m_dllAvCodec.avcodec_find_decoder(hints.codec); ++ if (!pCodec) ++ { ++ CLog::Log(LOGDEBUG,"%s - Unable to find codec %d", __FUNCTION__, hints.codec); ++ return false; ++ } ++ ++ m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec); + m_pCodecContext->debug_mv = 0; + m_pCodecContext->debug = 0; + m_pCodecContext->workaround_bugs = FF_BUG_AUTODETECT; +@@ -100,14 +107,7 @@ + delete[] parse_extra; + } + +- AVCodec* pCodec = m_dllAvCodec.avcodec_find_decoder(hints.codec); +- if (!pCodec) +- { +- CLog::Log(LOGDEBUG,"%s - Unable to find codec %d", __FUNCTION__, hints.codec); +- return false; +- } +- +- if (m_dllAvCodec.avcodec_open(m_pCodecContext, pCodec) < 0) ++ if (m_dllAvCodec.avcodec_open2(m_pCodecContext, pCodec, NULL) < 0) + { + CLog::Log(LOGDEBUG,"CDVDVideoCodecFFmpeg::Open() Unable to open codec"); + return false; +@@ -134,19 +134,12 @@ + { + for(unsigned i=0;i= (52<<10) + if(sub.rects[i]) + { + m_dllAvUtil.av_free(sub.rects[i]->pict.data[0]); + m_dllAvUtil.av_free(sub.rects[i]->pict.data[1]); + m_dllAvUtil.av_freep(&sub.rects[i]); + } +-#else +- if(sub.rects[i].bitmap) +- m_dllAvUtil.av_freep(&sub.rects[i].bitmap); +- if(m_Subtitle.rects[i].rgba_palette) +- m_dllAvUtil.av_freep(&sub.rects[i].rgba_palette); +-#endif + } + if(sub.rects) + m_dllAvUtil.av_freep(&sub.rects); +@@ -294,7 +287,6 @@ + overlay->source_width = m_width; + overlay->source_height = m_height; + +-#if LIBAVCODEC_VERSION_INT >= (52<<10) + BYTE* s = rect.pict.data[0]; + BYTE* t = overlay->data; + for(int i=0;idata; +- for(int i=0;ilinesize; +- } +- +- memcpy(overlay->palette, rect.rgba_palette, rect.nb_colors*4); +- +- m_dllAvUtil.av_freep(&rect.bitmap); +- m_dllAvUtil.av_freep(&rect.rgba_palette); +-#endif + m_SubtitleIndex++; + + return overlay; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-05-14 14:08:56.019373894 +0200 +@@ -123,12 +123,11 @@ + CDVDVideoCodecFFmpeg::CDVDVideoCodecFFmpeg() : CDVDVideoCodec() + { + m_pCodecContext = NULL; +- m_pConvertFrame = NULL; + m_pFrame = NULL; + m_pFilterGraph = NULL; + m_pFilterIn = NULL; + m_pFilterOut = NULL; +- m_pFilterLink = NULL; ++ m_pBufferRef = NULL; + + m_iPictureWidth = 0; + m_iPictureHeight = 0; +@@ -163,9 +162,13 @@ + m_dllAvFilter.avfilter_register_all(); + + m_bSoftware = hints.software; +- m_pCodecContext = m_dllAvCodec.avcodec_alloc_context(); ++ ++ m_formats.push_back(PIX_FMT_YUV420P); ++ m_formats.push_back(PIX_FMT_YUVJ420P); ++ m_formats.push_back(PIX_FMT_NONE); /* always add none to get a terminated list in ffmpeg world */ + + pCodec = NULL; ++ m_pCodecContext = NULL; + + if (hints.codec == CODEC_ID_H264) + { +@@ -196,6 +199,7 @@ + + CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Creating VDPAU(%ix%i, %d)",hints.width, hints.height, hints.codec); + CVDPAU* vdp = new CVDPAU(); ++ m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec); + m_pCodecContext->codec_id = hints.codec; + m_pCodecContext->width = hints.width; + m_pCodecContext->height = hints.height; +@@ -207,7 +211,7 @@ + m_pCodecContext->codec_id = CODEC_ID_NONE; // ffmpeg will complain if this has been set + break; + } +- m_pCodecContext->codec_id = CODEC_ID_NONE; // ffmpeg will complain if this has been set ++ m_dllAvUtil.av_freep(&m_pCodecContext); + CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Failed to get VDPAU device"); + vdp->Release(); + } +@@ -226,21 +230,26 @@ + + CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Using codec: %s",pCodec->long_name ? pCodec->long_name : pCodec->name); + ++ if(m_pCodecContext == NULL) ++ m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec); ++ + m_pCodecContext->opaque = (void*)this; + m_pCodecContext->debug_mv = 0; + m_pCodecContext->debug = 0; + m_pCodecContext->workaround_bugs = FF_BUG_AUTODETECT; + m_pCodecContext->get_format = GetFormat; + m_pCodecContext->codec_tag = hints.codec_tag; ++ /* Only allow slice threading, since frame threading is more ++ * sensitive to changes in frame sizes, and it causes crashes ++ * during HW accell */ ++ m_pCodecContext->thread_type = FF_THREAD_SLICE; + + #if defined(__APPLE__) && defined(__arm__) + // ffmpeg with enabled neon will crash and burn if this is enabled + m_pCodecContext->flags &= CODEC_FLAG_EMU_EDGE; + #else + if (pCodec->id != CODEC_ID_H264 && pCodec->capabilities & CODEC_CAP_DR1 +-#if LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(52,69,0) + && pCodec->id != CODEC_ID_VP8 +-#endif + ) + m_pCodecContext->flags |= CODEC_FLAG_EMU_EDGE; + #endif +@@ -272,16 +281,16 @@ + if (it->m_name == "surfaces") + m_uSurfacesCount = std::atoi(it->m_value.c_str()); + else +- m_dllAvUtil.av_set_string3(m_pCodecContext, it->m_name.c_str(), it->m_value.c_str(), 0, NULL); ++ m_dllAvUtil.av_opt_set(m_pCodecContext, it->m_name.c_str(), it->m_value.c_str(), 0); + } + + int num_threads = std::min(8 /*MAX_THREADS*/, g_cpuInfo.getCPUCount()); + if( num_threads > 1 && !hints.software && m_pHardware == NULL // thumbnail extraction fails when run threaded + && ( pCodec->id == CODEC_ID_H264 + || pCodec->id == CODEC_ID_MPEG4 )) +- m_dllAvCodec.avcodec_thread_init(m_pCodecContext, num_threads); ++ m_pCodecContext->thread_count = num_threads; + +- if (m_dllAvCodec.avcodec_open(m_pCodecContext, pCodec) < 0) ++ if (m_dllAvCodec.avcodec_open2(m_pCodecContext, pCodec, NULL) < 0) + { + CLog::Log(LOGDEBUG,"CDVDVideoCodecFFmpeg::Open() Unable to open codec"); + return false; +@@ -290,14 +299,7 @@ + m_pFrame = m_dllAvCodec.avcodec_alloc_frame(); + if (!m_pFrame) return false; + +- if(pCodec->name) +- m_name = CStdString("ff-") + pCodec->name; +- else +- m_name = "ffmpeg"; +- +- if(m_pHardware) +- m_name += "-" + m_pHardware->Name(); +- ++ UpdateName(); + return true; + } + +@@ -306,13 +308,6 @@ + if (m_pFrame) m_dllAvUtil.av_free(m_pFrame); + m_pFrame = NULL; + +- if (m_pConvertFrame) +- { +- m_dllAvCodec.avpicture_free(m_pConvertFrame); +- m_dllAvUtil.av_free(m_pConvertFrame); +- } +- m_pConvertFrame = NULL; +- + if (m_pCodecContext) + { + if (m_pCodecContext->codec) m_dllAvCodec.avcodec_close(m_pCodecContext); +@@ -458,9 +453,6 @@ + return VC_ERROR; + } + +- if (len != iSize && m_pCodecContext->skip_frame != AVDISCARD_NONREF) +- CLog::Log(LOGWARNING, "%s - avcodec_decode_video didn't consume the full packet. size: %d, consumed: %d", __FUNCTION__, iSize, len); +- + if (!iGotPicture) + return VC_BUFFER; + +@@ -478,67 +470,32 @@ + if(m_pCodecContext->codec_id == CODEC_ID_H264) + m_started = true; + +- if(m_pCodecContext->pix_fmt != PIX_FMT_YUV420P +- && m_pCodecContext->pix_fmt != PIX_FMT_YUVJ420P +- && m_pHardware == NULL) +- { +- if (!m_dllSwScale.IsLoaded() && !m_dllSwScale.Load()) +- return VC_ERROR; +- +- if (!m_pConvertFrame) +- { +- // Allocate an AVFrame structure +- m_pConvertFrame = (AVPicture*)m_dllAvUtil.av_mallocz(sizeof(AVPicture)); +- // Due to a bug in swsscale we need to allocate one extra line of data +- if(m_dllAvCodec.avpicture_alloc( m_pConvertFrame +- , PIX_FMT_YUV420P +- , m_pCodecContext->width +- , m_pCodecContext->height+1) < 0) +- { +- m_dllAvUtil.av_free(m_pConvertFrame); +- m_pConvertFrame = NULL; +- return VC_ERROR; +- } +- } ++ if(m_pHardware == NULL) ++ { ++ bool need_scale = std::find( m_formats.begin() ++ , m_formats.end() ++ , m_pCodecContext->pix_fmt) == m_formats.end(); + +- // convert the picture +- struct SwsContext *context = m_dllSwScale.sws_getContext(m_pCodecContext->width, m_pCodecContext->height, +- m_pCodecContext->pix_fmt, m_pCodecContext->width, m_pCodecContext->height, +- PIX_FMT_YUV420P, SWS_FAST_BILINEAR | SwScaleCPUFlags(), NULL, NULL, NULL); ++ bool need_reopen = false; ++ if(!m_filters.Equals(m_filters_next)) ++ need_reopen = true; + +- if(context == NULL) ++ if(m_pFilterIn) + { +- CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::Decode - unable to obtain sws context for w:%i, h:%i, pixfmt: %i", m_pCodecContext->width, m_pCodecContext->height, m_pCodecContext->pix_fmt); +- return VC_ERROR; ++ if(m_pFilterIn->outputs[0]->format != m_pCodecContext->pix_fmt ++ || m_pFilterIn->outputs[0]->w != m_pCodecContext->width ++ || m_pFilterIn->outputs[0]->h != m_pCodecContext->height) ++ need_reopen = true; + } + +- m_dllSwScale.sws_scale(context +- , m_pFrame->data +- , m_pFrame->linesize +- , 0 +- , m_pCodecContext->height +- , m_pConvertFrame->data +- , m_pConvertFrame->linesize); +- +- m_dllSwScale.sws_freeContext(context); +- } +- else +- { +- // no need to convert, just free any existing convert buffers +- if (m_pConvertFrame) ++ // try to setup new filters ++ if (need_reopen || (need_scale && m_pFilterGraph == NULL)) + { +- m_dllAvCodec.avpicture_free(m_pConvertFrame); +- m_dllAvUtil.av_free(m_pConvertFrame); +- m_pConvertFrame = NULL; +- } +- } ++ m_filters = m_filters_next; + +- // try to setup new filters +- if (!m_filters.Equals(m_filters_next)) +- { +- m_filters = m_filters_next; +- if(FilterOpen(m_filters) < 0) +- FilterClose(); ++ if(FilterOpen(m_filters, need_scale) < 0) ++ FilterClose(); ++ } + } + + int result; +@@ -564,12 +521,6 @@ + if (m_pHardware) + m_pHardware->Reset(); + +- if (m_pConvertFrame) +- { +- m_dllAvCodec.avpicture_free(m_pConvertFrame); +- m_dllAvUtil.av_free(m_pConvertFrame); +- m_pConvertFrame = NULL; +- } + m_filters = ""; + FilterClose(); + } +@@ -579,10 +530,10 @@ + pDvdVideoPicture->iWidth = m_pCodecContext->width; + pDvdVideoPicture->iHeight = m_pCodecContext->height; + +- if(m_pFilterLink) ++ if(m_pBufferRef) + { +- pDvdVideoPicture->iWidth = m_pFilterLink->cur_buf->video->w; +- pDvdVideoPicture->iHeight = m_pFilterLink->cur_buf->video->h; ++ pDvdVideoPicture->iWidth = m_pBufferRef->video->w; ++ pDvdVideoPicture->iHeight = m_pBufferRef->video->h; + } + + /* crop of 10 pixels if demuxer asked it */ +@@ -598,12 +549,8 @@ + + /* use variable in the frame */ + AVRational pixel_aspect = m_pCodecContext->sample_aspect_ratio; +- if (m_pFilterLink) +-#ifdef HAVE_AVFILTERBUFFERREFVIDEOPROPS_SAMPLE_ASPECT_RATIO +- pixel_aspect = m_pFilterLink->cur_buf->video->sample_aspect_ratio; +-#else +- pixel_aspect = m_pFilterLink->cur_buf->video->pixel_aspect; +-#endif ++ if (m_pBufferRef) ++ pixel_aspect = m_pBufferRef->video->sample_aspect_ratio; + + if (pixel_aspect.num == 0) + aspect_ratio = 0; +@@ -632,8 +579,6 @@ + pDvdVideoPicture->iFlags = DVP_FLAG_ALLOCATED; + pDvdVideoPicture->iFlags |= m_pFrame->interlaced_frame ? DVP_FLAG_INTERLACED : 0; + pDvdVideoPicture->iFlags |= m_pFrame->top_field_first ? DVP_FLAG_TOP_FIELD_FIRST: 0; +- if(m_pCodecContext->pix_fmt == PIX_FMT_YUVJ420P) +- pDvdVideoPicture->color_range = 1; + + pDvdVideoPicture->chroma_position = m_pCodecContext->chroma_sample_location; + pDvdVideoPicture->color_primaries = m_pCodecContext->color_primaries; +@@ -677,14 +622,6 @@ + if(!GetPictureCommon(pDvdVideoPicture)) + return false; + +- if(m_pConvertFrame) +- { +- for (int i = 0; i < 4; i++) +- pDvdVideoPicture->data[i] = m_pConvertFrame->data[i]; +- for (int i = 0; i < 4; i++) +- pDvdVideoPicture->iLineSize[i] = m_pConvertFrame->linesize[i]; +- } +- else + { + for (int i = 0; i < 4; i++) + pDvdVideoPicture->data[i] = m_pFrame->data[i]; +@@ -693,20 +630,38 @@ + } + + pDvdVideoPicture->iFlags |= pDvdVideoPicture->data[0] ? 0 : DVP_FLAG_DROPPED; +- pDvdVideoPicture->format = DVDVideoPicture::FMT_YUV420P; + pDvdVideoPicture->extended_format = 0; ++ pDvdVideoPicture->color_range = 0; ++ ++ PixelFormat pix_fmt; ++ if(m_pBufferRef) ++ pix_fmt = (PixelFormat)m_pBufferRef->format; ++ else ++ pix_fmt = m_pCodecContext->pix_fmt; ++ ++ switch(pix_fmt) ++ { ++ case PIX_FMT_YUVJ420P: ++ pDvdVideoPicture->format = DVDVideoPicture::FMT_YUV420P; ++ pDvdVideoPicture->color_range = 1; ++ break; ++ default: ++ pDvdVideoPicture->format = DVDVideoPicture::FMT_YUV420P; ++ break; ++ } + + return true; + } + +-int CDVDVideoCodecFFmpeg::FilterOpen(const CStdString& filters) ++int CDVDVideoCodecFFmpeg::FilterOpen(const CStdString& filters, bool scale) + { + int result; ++ AVBufferSinkParams *buffersink_params; + + if (m_pFilterGraph) + FilterClose(); + +- if (filters.IsEmpty()) ++ if (filters.IsEmpty() && !scale) + return 0; + + if (!(m_pFilterGraph = m_dllAvFilter.avfilter_graph_alloc())) +@@ -715,17 +670,8 @@ + return -1; + } + +- // CrHasher HACK (if an alternative becomes available use it!): In order to display the output +- // produced by a combination of filters we insert "nullsink" as the last filter and we use +- // its input pin as our output pin. +- // +- // input --> .. --> last_filter --> [in] nullsink [null] [in] --> output +- // | | +- // | | +- // +------------------------+ +- // + AVFilter* srcFilter = m_dllAvFilter.avfilter_get_by_name("buffer"); +- AVFilter* outFilter = m_dllAvFilter.avfilter_get_by_name("nullsink"); // should be last filter in the graph for now ++ AVFilter* outFilter = m_dllAvFilter.avfilter_get_by_name("buffersink"); // should be last filter in the graph for now + + CStdString args; + +@@ -744,11 +690,19 @@ + return result; + } + +- if ((result = m_dllAvFilter.avfilter_graph_create_filter(&m_pFilterOut, outFilter, "out", NULL, NULL/*nullsink=>NULL*/, m_pFilterGraph)) < 0) ++ buffersink_params = m_dllAvFilter.av_buffersink_params_alloc(); ++ buffersink_params->pixel_fmts = &m_formats[0]; ++#ifdef FF_API_OLD_VSINK_API ++ if ((result = m_dllAvFilter.avfilter_graph_create_filter(&m_pFilterOut, outFilter, "out", NULL, (void*)buffersink_params->pixel_fmts, m_pFilterGraph)) < 0) ++#else ++ if ((result = m_dllAvFilter.avfilter_graph_create_filter(&m_pFilterOut, outFilter, "out", NULL, buffersink_params, m_pFilterGraph)) < 0) ++#endif + { ++ m_dllAvUtil.av_freep(&buffersink_params); + CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterOpen - avfilter_graph_create_filter: out"); + return result; + } ++ m_dllAvUtil.av_freep(&buffersink_params); + + if (!filters.empty()) + { +@@ -794,6 +748,12 @@ + + void CDVDVideoCodecFFmpeg::FilterClose() + { ++ if(m_pBufferRef) ++ { ++ m_dllAvFilter.avfilter_unref_buffer(m_pBufferRef); ++ m_pBufferRef = NULL; ++ } ++ + if (m_pFilterGraph) + { + m_dllAvFilter.avfilter_graph_free(&m_pFilterGraph); +@@ -801,7 +761,6 @@ + // Disposed by above code + m_pFilterIn = NULL; + m_pFilterOut = NULL; +- m_pFilterLink = NULL; + } + } + +@@ -809,20 +768,9 @@ + { + int result, frames; + +- m_pFilterLink = m_pFilterOut->inputs[0]; +- + if (frame) + { +-#if LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,13,0) + result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame, 0); +-#elif LIBAVFILTER_VERSION_INT >= AV_VERSION_INT(2,7,0) +- result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame); +-#elif LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(53,3,0) +- result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame, frame->pts); +-#else +- result = m_dllAvFilter.av_vsrc_buffer_add_frame(m_pFilterIn, frame, frame->pts, m_pCodecContext->sample_aspect_ratio); +-#endif +- + if (result < 0) + { + CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - av_vsrc_buffer_add_frame"); +@@ -830,7 +778,13 @@ + } + } + +- if ((frames = m_dllAvFilter.avfilter_poll_frame(m_pFilterLink)) < 0) ++ if(m_pBufferRef) ++ { ++ m_dllAvFilter.avfilter_unref_buffer(m_pBufferRef); ++ m_pBufferRef = NULL; ++ } ++ ++ if ((frames = m_dllAvFilter.av_buffersink_poll_frame(m_pFilterOut)) < 0) + { + CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - avfilter_poll_frame"); + return VC_ERROR; +@@ -838,19 +792,9 @@ + + if (frames > 0) + { +- if (m_pFilterLink->cur_buf) +- { +- m_dllAvFilter.avfilter_unref_buffer(m_pFilterLink->cur_buf); +- m_pFilterLink->cur_buf = NULL; +- } +- +- if ((result = m_dllAvFilter.avfilter_request_frame(m_pFilterLink)) < 0) +- { +- CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - avfilter_request_frame"); +- return VC_ERROR; +- } + +- if (!m_pFilterLink->cur_buf) ++ result = m_dllAvFilter.av_buffersink_get_buffer_ref(m_pFilterOut, &m_pBufferRef, 0); ++ if(!m_pBufferRef) + { + CLog::Log(LOGERROR, "CDVDVideoCodecFFmpeg::FilterProcess - cur_buf"); + return VC_ERROR; +@@ -861,11 +805,11 @@ + else + m_pFrame->repeat_pict = -(frames - 1); + +- m_pFrame->interlaced_frame = m_pFilterLink->cur_buf->video->interlaced; +- m_pFrame->top_field_first = m_pFilterLink->cur_buf->video->top_field_first; ++ m_pFrame->interlaced_frame = m_pBufferRef->video->interlaced; ++ m_pFrame->top_field_first = m_pBufferRef->video->top_field_first; + +- memcpy(m_pFrame->linesize, m_pFilterLink->cur_buf->linesize, 4*sizeof(int)); +- memcpy(m_pFrame->data , m_pFilterLink->cur_buf->data , 4*sizeof(uint8_t*)); ++ memcpy(m_pFrame->linesize, m_pBufferRef->linesize, 4*sizeof(int)); ++ memcpy(m_pFrame->data , m_pBufferRef->data , 4*sizeof(uint8_t*)); + + if(frames > 1) + return VC_PICTURE; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-05-14 14:08:56.022373954 +0200 +@@ -68,27 +68,36 @@ + { + SAFE_RELEASE(m_pHardware); + m_pHardware = hardware; +- m_name += "-"; +- m_name += m_pHardware->Name(); ++ UpdateName(); + } + + protected: + static enum PixelFormat GetFormat(struct AVCodecContext * avctx, const PixelFormat * fmt); + +- int FilterOpen(const CStdString& filters); ++ int FilterOpen(const CStdString& filters, bool scale); + void FilterClose(); + int FilterProcess(AVFrame* frame); + ++ void UpdateName() ++ { ++ if(m_pCodecContext->codec->name) ++ m_name = CStdString("ff-") + m_pCodecContext->codec->name; ++ else ++ m_name = "ffmpeg"; ++ ++ if(m_pHardware) ++ m_name += "-" + m_pHardware->Name(); ++ } ++ + AVFrame* m_pFrame; + AVCodecContext* m_pCodecContext; + +- AVPicture* m_pConvertFrame; + CStdString m_filters; + CStdString m_filters_next; + AVFilterGraph* m_pFilterGraph; + AVFilterContext* m_pFilterIn; + AVFilterContext* m_pFilterOut; +- AVFilterLink* m_pFilterLink; ++ AVFilterBufferRef* m_pBufferRef; + + int m_iPictureWidth; + int m_iPictureHeight; +@@ -109,4 +118,5 @@ + int m_iLastKeyframe; + double m_dts; + bool m_started; ++ std::vector m_formats; + }; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVDA.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVDA.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVDA.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVDA.cpp 2012-05-14 14:08:55.977373050 +0200 +@@ -525,8 +525,8 @@ + { + while (!*(nal_start++)); + nal_end = avc_find_startcode(nal_start, end); +- av_format_ctx->put_be32(pb, nal_end - nal_start); +- av_format_ctx->put_buffer(pb, nal_start, nal_end - nal_start); ++ av_format_ctx->avio_wb32(pb, nal_end - nal_start); ++ av_format_ctx->avio_write(pb, nal_start, nal_end - nal_start); + size += 4 + nal_end - nal_start; + nal_start = nal_end; + } +@@ -537,14 +537,14 @@ + const uint8_t *buf_in, uint8_t **buf, int *size) + { + ByteIOContext *pb; +- int ret = av_format_ctx->url_open_dyn_buf(&pb); ++ int ret = av_format_ctx->avio_open_dyn_buf(&pb); + if (ret < 0) + return ret; + + avc_parse_nal_units(av_format_ctx, pb, buf_in, *size); + + av_util_ctx->av_freep(buf); +- *size = av_format_ctx->url_close_dyn_buf(pb, buf); ++ *size = av_format_ctx->avio_close_dyn_buf(pb, buf); + return 0; + } + +@@ -590,26 +590,26 @@ + } + assert(sps); + +- av_format_ctx->put_byte(pb, 1); /* version */ +- av_format_ctx->put_byte(pb, sps[1]); /* profile */ +- av_format_ctx->put_byte(pb, sps[2]); /* profile compat */ +- av_format_ctx->put_byte(pb, sps[3]); /* level */ +- av_format_ctx->put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ +- av_format_ctx->put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ ++ av_format_ctx->avio_w8(pb, 1); /* version */ ++ av_format_ctx->avio_w8(pb, sps[1]); /* profile */ ++ av_format_ctx->avio_w8(pb, sps[2]); /* profile compat */ ++ av_format_ctx->avio_w8(pb, sps[3]); /* level */ ++ av_format_ctx->avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ ++ av_format_ctx->avio_w8(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ + +- av_format_ctx->put_be16(pb, sps_size); +- av_format_ctx->put_buffer(pb, sps, sps_size); ++ av_format_ctx->avio_wb16(pb, sps_size); ++ av_format_ctx->avio_write(pb, sps, sps_size); + if (pps) + { +- av_format_ctx->put_byte(pb, 1); /* number of pps */ +- av_format_ctx->put_be16(pb, pps_size); +- av_format_ctx->put_buffer(pb, pps, pps_size); ++ av_format_ctx->avio_w8(pb, 1); /* number of pps */ ++ av_format_ctx->avio_wb16(pb, pps_size); ++ av_format_ctx->avio_write(pb, pps, pps_size); + } + av_util_ctx->av_free(start); + } + else + { +- av_format_ctx->put_buffer(pb, data, len); ++ av_format_ctx->avio_write(pb, data, len); + } + } + return 0; +@@ -706,7 +706,7 @@ + } + + ByteIOContext *pb; +- if (m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if (m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + { + return false; + } +@@ -717,7 +717,7 @@ + // unhook from ffmpeg's extradata + extradata = NULL; + // extract the avcC atom data into extradata then write it into avcCData for VDADecoder +- extrasize = m_dllAvFormat->url_close_dyn_buf(pb, &extradata); ++ extrasize = m_dllAvFormat->avio_close_dyn_buf(pb, &extradata); + // CFDataCreate makes a copy of extradata contents + avcCData = CFDataCreate(kCFAllocatorDefault, (const uint8_t*)extradata, extrasize); + // done with the converted extradata, we MUST free using av_free +@@ -948,12 +948,12 @@ + int demuxer_bytes; + uint8_t *demuxer_content; + +- if(m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if(m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + { + return VC_ERROR; + } + demuxer_bytes = avc_parse_nal_units(m_dllAvFormat, pb, pData, iSize); +- demuxer_bytes = m_dllAvFormat->url_close_dyn_buf(pb, &demuxer_content); ++ demuxer_bytes = m_dllAvFormat->avio_close_dyn_buf(pb, &demuxer_content); + avc_demux = CFDataCreate(kCFAllocatorDefault, demuxer_content, demuxer_bytes); + m_dllAvUtil->av_free(demuxer_content); + } +@@ -961,7 +961,7 @@ + { + // convert demuxer packet from 3 byte NAL sizes to 4 byte + ByteIOContext *pb; +- if (m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if (m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + return VC_ERROR; + + uint32_t nal_size; +@@ -970,14 +970,14 @@ + while (nal_start < end) + { + nal_size = VDA_RB24(nal_start); +- m_dllAvFormat->put_be32(pb, nal_size); ++ m_dllAvFormat->avio_wb32(pb, nal_size); + nal_start += 3; +- m_dllAvFormat->put_buffer(pb, nal_start, nal_size); ++ m_dllAvFormat->avio_write(pb, nal_start, nal_size); + nal_start += nal_size; + } + + uint8_t *demuxer_content; +- int demuxer_bytes = m_dllAvFormat->url_close_dyn_buf(pb, &demuxer_content); ++ int demuxer_bytes = m_dllAvFormat->avio_close_dyn_buf(pb, &demuxer_content); + avc_demux = CFDataCreate(kCFAllocatorDefault, demuxer_content, demuxer_bytes); + m_dllAvUtil->av_free(demuxer_content); + } +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecVideoToolBox.cpp 2012-05-14 14:08:55.980373110 +0200 +@@ -474,7 +474,7 @@ + { + b |= 0x80; + } +- av_format_ctx->put_byte(pb, b); ++ av_format_ctx->avio_w8(pb, b); + } + + return numBytes; +@@ -482,37 +482,37 @@ + + void quicktime_write_esds(DllAvFormat *av_format_ctx, ByteIOContext *pb, quicktime_esds_t *esds) + { +- av_format_ctx->put_byte(pb, 0); // Version +- av_format_ctx->put_be24(pb, 0); // Flags ++ av_format_ctx->avio_w8(pb, 0); // Version ++ av_format_ctx->avio_wb24(pb, 0); // Flags + + // elementary stream descriptor tag +- av_format_ctx->put_byte(pb, 0x03); ++ av_format_ctx->avio_w8(pb, 0x03); + quicktime_write_mp4_descr_length(av_format_ctx, pb, + 3 + 5 + (13 + 5 + esds->decoderConfigLen) + 3, false); + // 3 bytes + 5 bytes for tag +- av_format_ctx->put_be16(pb, esds->esid); +- av_format_ctx->put_byte(pb, esds->stream_priority); ++ av_format_ctx->avio_wb16(pb, esds->esid); ++ av_format_ctx->avio_w8(pb, esds->stream_priority); + + // decoder configuration description tag +- av_format_ctx->put_byte(pb, 0x04); ++ av_format_ctx->avio_w8(pb, 0x04); + quicktime_write_mp4_descr_length(av_format_ctx, pb, + 13 + 5 + esds->decoderConfigLen, false); + // 13 bytes + 5 bytes for tag +- av_format_ctx->put_byte(pb, esds->objectTypeId); // objectTypeIndication +- av_format_ctx->put_byte(pb, esds->streamType); // streamType +- av_format_ctx->put_be24(pb, esds->bufferSizeDB); // buffer size +- av_format_ctx->put_be32(pb, esds->maxBitrate); // max bitrate +- av_format_ctx->put_be32(pb, esds->avgBitrate); // average bitrate ++ av_format_ctx->avio_w8(pb, esds->objectTypeId); // objectTypeIndication ++ av_format_ctx->avio_w8(pb, esds->streamType); // streamType ++ av_format_ctx->avio_wb24(pb, esds->bufferSizeDB); // buffer size ++ av_format_ctx->avio_wb32(pb, esds->maxBitrate); // max bitrate ++ av_format_ctx->avio_wb32(pb, esds->avgBitrate); // average bitrate + + // decoder specific description tag +- av_format_ctx->put_byte(pb, 0x05); ++ av_format_ctx->avio_w8(pb, 0x05); + quicktime_write_mp4_descr_length(av_format_ctx, pb, esds->decoderConfigLen, false); +- av_format_ctx->put_buffer(pb, esds->decoderConfig, esds->decoderConfigLen); ++ av_format_ctx->avio_write(pb, esds->decoderConfig, esds->decoderConfigLen); + + // sync layer configuration descriptor tag +- av_format_ctx->put_byte(pb, 0x06); // tag +- av_format_ctx->put_byte(pb, 0x01); // length +- av_format_ctx->put_byte(pb, 0x7F); // no SL ++ av_format_ctx->avio_w8(pb, 0x06); // tag ++ av_format_ctx->avio_w8(pb, 0x01); // length ++ av_format_ctx->avio_w8(pb, 0x7F); // no SL + + /* no IPI_DescrPointer */ + /* no IP_IdentificationDataSet */ +@@ -666,8 +666,8 @@ + { + while (!*(nal_start++)); + nal_end = avc_find_startcode(nal_start, end); +- av_format_ctx->put_be32(pb, nal_end - nal_start); +- av_format_ctx->put_buffer(pb, nal_start, nal_end - nal_start); ++ av_format_ctx->avio_wb32(pb, nal_end - nal_start); ++ av_format_ctx->avio_write(pb, nal_start, nal_end - nal_start); + size += 4 + nal_end - nal_start; + nal_start = nal_end; + } +@@ -678,14 +678,14 @@ + const uint8_t *buf_in, uint8_t **buf, int *size) + { + ByteIOContext *pb; +- int ret = av_format_ctx->url_open_dyn_buf(&pb); ++ int ret = av_format_ctx->avio_open_dyn_buf(&pb); + if (ret < 0) + return ret; + + avc_parse_nal_units(av_format_ctx, pb, buf_in, *size); + + av_util_ctx->av_freep(buf); +- *size = av_format_ctx->url_close_dyn_buf(pb, buf); ++ *size = av_format_ctx->avio_close_dyn_buf(pb, buf); + return 0; + } + +@@ -770,26 +770,26 @@ + } + assert(sps); + +- av_format_ctx->put_byte(pb, 1); /* version */ +- av_format_ctx->put_byte(pb, sps[1]); /* profile */ +- av_format_ctx->put_byte(pb, sps[2]); /* profile compat */ +- av_format_ctx->put_byte(pb, sps[3]); /* level */ +- av_format_ctx->put_byte(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ +- av_format_ctx->put_byte(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ ++ av_format_ctx->avio_w8(pb, 1); /* version */ ++ av_format_ctx->avio_w8(pb, sps[1]); /* profile */ ++ av_format_ctx->avio_w8(pb, sps[2]); /* profile compat */ ++ av_format_ctx->avio_w8(pb, sps[3]); /* level */ ++ av_format_ctx->avio_w8(pb, 0xff); /* 6 bits reserved (111111) + 2 bits nal size length - 1 (11) */ ++ av_format_ctx->avio_w8(pb, 0xe1); /* 3 bits reserved (111) + 5 bits number of sps (00001) */ + +- av_format_ctx->put_be16(pb, sps_size); +- av_format_ctx->put_buffer(pb, sps, sps_size); ++ av_format_ctx->avio_wb16(pb, sps_size); ++ av_format_ctx->avio_write(pb, sps, sps_size); + if (pps) + { +- av_format_ctx->put_byte(pb, 1); /* number of pps */ +- av_format_ctx->put_be16(pb, pps_size); +- av_format_ctx->put_buffer(pb, pps, pps_size); ++ av_format_ctx->avio_w8(pb, 1); /* number of pps */ ++ av_format_ctx->avio_wb16(pb, pps_size); ++ av_format_ctx->avio_write(pb, pps, pps_size); + } + av_util_ctx->av_free(start); + } + else + { +- av_format_ctx->put_buffer(pb, data, len); ++ av_format_ctx->avio_write(pb, data, len); + } + } + return 0; +@@ -1086,7 +1086,7 @@ + ByteIOContext *pb; + quicktime_esds_t *esds; + +- if (m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if (m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + return false; + + esds = quicktime_set_esds(m_dllAvFormat, extradata, extrasize); +@@ -1095,7 +1095,7 @@ + // unhook from ffmpeg's extradata + extradata = NULL; + // extract the esds atom decoderConfig from extradata +- extrasize = m_dllAvFormat->url_close_dyn_buf(pb, &extradata); ++ extrasize = m_dllAvFormat->avio_close_dyn_buf(pb, &extradata); + free(esds->decoderConfig); + free(esds); + +@@ -1152,7 +1152,7 @@ + // NAL reformating to bitstream format required + + ByteIOContext *pb; +- if (m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if (m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + return false; + + m_convert_bytestream = true; +@@ -1161,7 +1161,7 @@ + // unhook from ffmpeg's extradata + extradata = NULL; + // extract the avcC atom data into extradata getting size into extrasize +- extrasize = m_dllAvFormat->url_close_dyn_buf(pb, &extradata); ++ extrasize = m_dllAvFormat->avio_close_dyn_buf(pb, &extradata); + + // check for interlaced and get number of ref frames + if (!validate_avcC_spc(extradata, extrasize, &m_max_ref_frames)) +@@ -1301,17 +1301,17 @@ + if (m_convert_bytestream) + { + // convert demuxer packet from bytestream (AnnexB) to bitstream +- if(m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if(m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + return VC_ERROR; + + demux_size = avc_parse_nal_units(m_dllAvFormat, pb, pData, iSize); +- demux_size = m_dllAvFormat->url_close_dyn_buf(pb, &demux_buff); ++ demux_size = m_dllAvFormat->avio_close_dyn_buf(pb, &demux_buff); + sampleBuff = CreateSampleBufferFrom(m_fmt_desc, demux_buff, demux_size); + } + else if (m_convert_3byteTo4byteNALSize) + { + // convert demuxer packet from 3 byte NAL sizes to 4 byte +- if (m_dllAvFormat->url_open_dyn_buf(&pb) < 0) ++ if (m_dllAvFormat->avio_open_dyn_buf(&pb) < 0) + return VC_ERROR; + + uint32_t nal_size; +@@ -1320,13 +1320,13 @@ + while (nal_start < end) + { + nal_size = VDA_RB24(nal_start); +- m_dllAvFormat->put_be32(pb, nal_size); ++ m_dllAvFormat->avio_wb32(pb, nal_size); + nal_start += 3; +- m_dllAvFormat->put_buffer(pb, nal_start, nal_size); ++ m_dllAvFormat->avio_write(pb, nal_start, nal_size); + nal_start += nal_size; + } + +- demux_size = m_dllAvFormat->url_close_dyn_buf(pb, &demux_buff); ++ demux_size = m_dllAvFormat->avio_close_dyn_buf(pb, &demux_buff); + sampleBuff = CreateSampleBufferFrom(m_fmt_desc, demux_buff, demux_size); + } + else +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VAAPI.cpp 2012-05-14 14:08:55.991373330 +0200 +@@ -223,7 +223,6 @@ + } + + pic->type = FF_BUFFER_TYPE_USER; +- pic->age = 1; + pic->data[0] = (uint8_t*)wrapper; + pic->data[1] = NULL; + pic->data[2] = NULL; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 14:08:55.992373351 +0200 +@@ -1211,14 +1211,12 @@ + + if(pic->reference) + { +- pic->age = pA->ip_age[0]; + pA->ip_age[0]= pA->ip_age[1]+1; + pA->ip_age[1]= 1; + pA->b_age++; + } + else + { +- pic->age = pA->b_age; + pA->ip_age[0]++; + pA->ip_age[1]++; + pA->b_age = 1; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-05-14 14:08:56.023373975 +0200 +@@ -161,7 +161,7 @@ + #define g_demuxer (*((CDVDDemuxFFmpeg**)g_tls.Get())) + #endif + +-static int interrupt_cb(void) ++static int interrupt_cb(void* unused) + { + if(g_demuxer && g_demuxer->Aborted()) + return 1; +@@ -179,7 +179,7 @@ + + static int dvd_file_read(void *h, uint8_t* buf, int size) + { +- if(interrupt_cb()) ++ if(interrupt_cb(NULL)) + return -1; + + CDVDInputStream* pInputStream = (CDVDInputStream*)h; +@@ -193,7 +193,7 @@ + */ + static offset_t dvd_file_seek(void *h, offset_t pos, int whence) + { +- if(interrupt_cb()) ++ if(interrupt_cb(NULL)) + return -1; + + CDVDInputStream* pInputStream = (CDVDInputStream*)h; +@@ -237,6 +237,7 @@ + m_speed = DVD_PLAYSPEED_NORMAL; + g_demuxer = this; + m_program = UINT_MAX; ++ const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; + + if (!pInput) return false; + +@@ -247,10 +248,6 @@ + + // register codecs + m_dllAvFormat.av_register_all(); +- m_dllAvFormat.url_set_interrupt_cb(interrupt_cb); +- +- // could be used for interupting ffmpeg while opening a file (eg internet streams) +- // url_set_interrupt_cb(NULL); + + m_pInput = pInput; + strFile = m_pInput->GetFileName(); +@@ -285,14 +282,14 @@ + // try mmsh, then mmst + CStdString strFile2; + strFile2.Format("mmsh://%s",strFile.substr(6,strFile.size()-6).c_str()); +- result = m_dllAvFormat.av_open_input_file(&m_pFormatContext, strFile2.c_str(), iformat, FFMPEG_FILE_BUFFER_SIZE, NULL); ++ result = m_dllAvFormat.avformat_open_input(&m_pFormatContext, strFile2.c_str(), iformat, NULL); + if (result < 0) + { + strFile = "mmst://"; + strFile += strFile2.Mid(7).c_str(); + } + } +- if (result < 0 && m_dllAvFormat.av_open_input_file(&m_pFormatContext, strFile.c_str(), iformat, FFMPEG_FILE_BUFFER_SIZE, NULL) < 0 ) ++ if (result < 0 && m_dllAvFormat.avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, NULL) < 0 ) + { + CLog::Log(LOGDEBUG, "Error, could not open file %s", strFile.c_str()); + Dispose(); +@@ -302,24 +299,16 @@ + else + { + unsigned char* buffer = (unsigned char*)m_dllAvUtil.av_malloc(FFMPEG_FILE_BUFFER_SIZE); +- m_ioContext = m_dllAvFormat.av_alloc_put_byte(buffer, FFMPEG_FILE_BUFFER_SIZE, 0, m_pInput, dvd_file_read, NULL, dvd_file_seek); ++ m_ioContext = m_dllAvFormat.avio_alloc_context(buffer, FFMPEG_FILE_BUFFER_SIZE, 0, m_pInput, dvd_file_read, NULL, dvd_file_seek); + m_ioContext->max_packet_size = m_pInput->GetBlockSize(); + if(m_ioContext->max_packet_size) + m_ioContext->max_packet_size *= FFMPEG_FILE_BUFFER_SIZE / m_ioContext->max_packet_size; + + if(m_pInput->Seek(0, SEEK_POSSIBLE) == 0) +- m_ioContext->is_streamed = 1; ++ m_ioContext->seekable = 0; + + if( iformat == NULL ) + { +-#if defined(USE_EXTERNAL_FFMPEG) && LIBAVFORMAT_VERSION_INT < AV_VERSION_INT(52,98,0) +- // API added on: 2011-02-09 +- // Old versions of ffmpeg do not have av_probe_input_format, so we need +- // to always probe using the lower-level functions as well. +- const bool legacyProbing = true; +-#else +- const bool legacyProbing = false; +-#endif + // let ffmpeg decide which demuxer we have to open + + bool trySPDIFonly = (m_pInput->GetContent() == "audio/x-spdif-compressed"); +@@ -332,7 +321,7 @@ + // want to probe for spdif (DTS or IEC 61937) compressed audio + // specifically, or in case the file is a wav which may contain DTS or + // IEC 61937 (e.g. ac3-in-wav) and we want to check for those formats. +- if (legacyProbing || trySPDIFonly || (iformat && strcmp(iformat->name, "wav") == 0)) ++ if (trySPDIFonly || (iformat && strcmp(iformat->name, "wav") == 0)) + { + AVProbeData pd; + BYTE probe_buffer[FFMPEG_FILE_BUFFER_SIZE + AVPROBE_PADDING_SIZE]; +@@ -342,7 +331,7 @@ + pd.filename = strFile.c_str(); + + // read data using avformat's buffers +- pd.buf_size = m_dllAvFormat.get_buffer(m_ioContext, pd.buf, m_ioContext->max_packet_size ? m_ioContext->max_packet_size : m_ioContext->buffer_size); ++ pd.buf_size = m_dllAvFormat.avio_read(m_ioContext, pd.buf, m_ioContext->max_packet_size ? m_ioContext->max_packet_size : m_ioContext->buffer_size); + if (pd.buf_size <= 0) + { + CLog::Log(LOGERROR, "%s - error reading from input stream, %s", __FUNCTION__, strFile.c_str()); +@@ -351,10 +340,7 @@ + memset(pd.buf+pd.buf_size, 0, AVPROBE_PADDING_SIZE); + + // restore position again +- m_dllAvFormat.url_fseek(m_ioContext , 0, SEEK_SET); +- +- if (legacyProbing && !trySPDIFonly) +- iformat = m_dllAvFormat.av_probe_input_format(&pd, 1); ++ m_dllAvFormat.avio_seek(m_ioContext , 0, SEEK_SET); + + // the advancedsetting is for allowing the user to force outputting the + // 44.1 kHz DTS wav file as PCM, so that an A/V receiver can decode +@@ -425,7 +411,10 @@ + + + // open the demuxer +- if (m_dllAvFormat.av_open_input_stream(&m_pFormatContext, m_ioContext, strFile.c_str(), iformat, NULL) < 0) ++ m_pFormatContext = m_dllAvFormat.avformat_alloc_context(); ++ m_pFormatContext->pb = m_ioContext; ++ ++ if (m_dllAvFormat.avformat_open_input(&m_pFormatContext, strFile.c_str(), iformat, NULL) < 0) + { + CLog::Log(LOGERROR, "%s - Error, could not open file %s", __FUNCTION__, strFile.c_str()); + Dispose(); +@@ -433,8 +422,11 @@ + } + } + ++ // set the interrupt callback, appeared in libavformat 53.15.0 ++ m_pFormatContext->interrupt_callback = int_cb; ++ + // analyse very short to speed up mjpeg playback start +- if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && m_ioContext->is_streamed) ++ if (iformat && (strcmp(iformat->name, "mjpeg") == 0) && m_ioContext->seekable == 0) + m_pFormatContext->max_analyze_duration = 500000; + + // we need to know if this is matroska or avi later +@@ -448,8 +440,8 @@ + m_pFormatContext->max_analyze_duration = 500000; + + +- CLog::Log(LOGDEBUG, "%s - av_find_stream_info starting", __FUNCTION__); +- int iErr = m_dllAvFormat.av_find_stream_info(m_pFormatContext); ++ CLog::Log(LOGDEBUG, "%s - avformat_find_stream_info starting", __FUNCTION__); ++ int iErr = m_dllAvFormat.avformat_find_stream_info(m_pFormatContext, NULL); + if (iErr < 0) + { + CLog::Log(LOGWARNING,"could not find codec parameters for %s", strFile.c_str()); +@@ -472,7 +464,7 @@ + m_pFormatContext->flags |= AVFMT_FLAG_NONBLOCK; + + // print some extra information +- m_dllAvFormat.dump_format(m_pFormatContext, 0, strFile.c_str(), 0); ++ m_dllAvFormat.av_dump_format(m_pFormatContext, 0, strFile.c_str(), 0); + + UpdateCurrentPTS(); + +@@ -511,20 +503,12 @@ + + if (m_pFormatContext) + { +- if (m_ioContext) ++ if (m_ioContext && m_pFormatContext->pb && m_pFormatContext->pb != m_ioContext) + { +- if(m_pFormatContext->pb && m_pFormatContext->pb != m_ioContext) +- { +- CLog::Log(LOGWARNING, "CDVDDemuxFFmpeg::Dispose - demuxer changed our byte context behind our back, possible memleak"); +- m_ioContext = m_pFormatContext->pb; +- } +- m_dllAvFormat.av_close_input_stream(m_pFormatContext); +- if (m_ioContext->buffer) +- m_dllAvUtil.av_free(m_ioContext->buffer); +- m_dllAvUtil.av_free(m_ioContext); ++ CLog::Log(LOGWARNING, "CDVDDemuxFFmpeg::Dispose - demuxer changed our byte context behind our back, possible memleak"); ++ m_ioContext = m_pFormatContext->pb; + } +- else +- m_dllAvFormat.av_close_input_file(m_pFormatContext); ++ m_dllAvFormat.avformat_close_input(&m_pFormatContext); + } + m_ioContext = NULL; + m_pFormatContext = NULL; +@@ -774,19 +758,12 @@ + { + stream->duration = duration; + duration = m_dllAvUtil.av_rescale_rnd(stream->duration, (int64_t)stream->time_base.num * AV_TIME_BASE, stream->time_base.den, AV_ROUND_NEAR_INF); +- if ((m_pFormatContext->duration == (int64_t)AV_NOPTS_VALUE && m_pFormatContext->file_size > 0) ++ if ((m_pFormatContext->duration == (int64_t)AV_NOPTS_VALUE) + || (m_pFormatContext->duration != (int64_t)AV_NOPTS_VALUE && duration > m_pFormatContext->duration)) + m_pFormatContext->duration = duration; + } + } + +- // check if stream seem to have grown since start +- if(m_pFormatContext->file_size > 0 && m_pFormatContext->pb) +- { +- if(m_pFormatContext->pb->pos > m_pFormatContext->file_size) +- m_pFormatContext->file_size = m_pFormatContext->pb->pos; +- } +- + pPacket->iStreamId = pkt.stream_index; // XXX just for now + } + m_dllAvCodec.av_free_packet(&pkt); +@@ -924,19 +901,6 @@ + if (!m_pFormatContext) + return 0; + +- /* apperently ffmpeg messes up sometimes, so check for negative value too */ +- if (m_pFormatContext->duration == (int64_t)AV_NOPTS_VALUE || m_pFormatContext->duration < 0LL) +- { +- // no duration is available for us +- // try to calculate it +- int iLength = 0; +- if (m_iCurrentPts != DVD_NOPTS_VALUE && m_pFormatContext->file_size > 0 && m_pFormatContext->pb && m_pFormatContext->pb->pos > 0) +- { +- iLength = (int)(((m_iCurrentPts * m_pFormatContext->file_size) / m_pFormatContext->pb->pos) / 1000) & 0xFFFFFFFF; +- } +- return iLength; +- } +- + return (int)(m_pFormatContext->duration / (AV_TIME_BASE / 1000)); + } + +@@ -971,6 +935,12 @@ + + void CDVDDemuxFFmpeg::AddStream(int iId) + { ++ if(iId >= MAX_STREAMS) ++ { ++ CLog::Log(LOGWARNING, "%s - streams id %d exeeds maximum supported", __FUNCTION__, iId); ++ return; ++ } ++ + AVStream* pStream = m_pFormatContext->streams[iId]; + if (pStream) + { +@@ -988,8 +958,8 @@ + st->iBitRate = pStream->codec->bit_rate; + st->iBitsPerSample = pStream->codec->bits_per_coded_sample; + +- if(m_dllAvFormat.av_metadata_get(pStream->metadata, "title", NULL, 0)) +- st->m_description = m_dllAvFormat.av_metadata_get(pStream->metadata, "title", NULL, 0)->value; ++ if(m_dllAvUtil.av_dict_get(pStream->metadata, "title", NULL, 0)) ++ st->m_description = m_dllAvUtil.av_dict_get(pStream->metadata, "title", NULL, 0)->value; + + break; + } +@@ -1078,8 +1048,8 @@ + if(pStream->codec) + st->identifier = pStream->codec->sub_id; + +- if(m_dllAvFormat.av_metadata_get(pStream->metadata, "title", NULL, 0)) +- st->m_description = m_dllAvFormat.av_metadata_get(pStream->metadata, "title", NULL, 0)->value; ++ if(m_dllAvUtil.av_dict_get(pStream->metadata, "title", NULL, 0)) ++ st->m_description = m_dllAvUtil.av_dict_get(pStream->metadata, "title", NULL, 0)->value; + + break; + } +@@ -1090,7 +1060,7 @@ + { + std::string fileName = "special://temp/fonts/"; + XFILE::CDirectory::Create(fileName); +- AVMetadataTag *nameTag = m_dllAvFormat.av_metadata_get(pStream->metadata, "filename", NULL, 0); ++ AVDictionaryEntry *nameTag = m_dllAvUtil.av_dict_get(pStream->metadata, "filename", NULL, 0); + if (!nameTag) { + CLog::Log(LOGERROR, "%s: TTF attachment has no name", __FUNCTION__); + break; +@@ -1139,7 +1109,7 @@ + // API added on: 2010-10-15 + // (Note that while the function was available earlier, the generic + // metadata tags were not populated by default) +- AVMetadataTag *langTag = m_dllAvFormat.av_metadata_get(pStream->metadata, "language", NULL, 0); ++ AVDictionaryEntry *langTag = m_dllAvUtil.av_dict_get(pStream->metadata, "language", NULL, 0); + if (langTag) + strncpy(m_streams[iId]->language, langTag->value, 3); + #else +@@ -1249,7 +1219,7 @@ + // API added on: 2010-10-15 + // (Note that while the function was available earlier, the generic + // metadata tags were not populated by default) +- AVMetadataTag *titleTag = m_dllAvFormat.av_metadata_get(m_pFormatContext->chapters[chapterIdx-1]->metadata, ++ AVDictionaryEntry *titleTag = m_dllAvUtil.av_dict_get(m_pFormatContext->chapters[chapterIdx-1]->metadata, + "title", NULL, 0); + if (titleTag) + strChapterName = titleTag->value; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.h 2012-05-14 14:08:55.906371620 +0200 +@@ -128,7 +128,7 @@ + #define MAX_STREAMS 100 + CDemuxStream* m_streams[MAX_STREAMS]; // maximum number of streams that ffmpeg can handle + +- ByteIOContext* m_ioContext; ++ AVIOContext* m_ioContext; + + DllAvFormat m_dllAvFormat; + DllAvCodec m_dllAvCodec; +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-05-14 14:08:56.018373874 +0200 +@@ -413,6 +413,7 @@ + { + if(m_pVideoCodec) + m_pVideoCodec->Reset(); ++ picture.iFlags &= ~DVP_FLAG_ALLOCATED; + m_packets.clear(); + m_started = false; + } +@@ -420,6 +421,7 @@ + { + if(m_pVideoCodec) + m_pVideoCodec->Reset(); ++ picture.iFlags &= ~DVP_FLAG_ALLOCATED; + m_packets.clear(); + + m_pullupCorrection.Flush(); +diff -Naur xbmc-pvr-11.0.1/xbmc/DllPaths_generated.h.in xbmc-pvr-11.0.1.patch/xbmc/DllPaths_generated.h.in +--- xbmc-pvr-11.0.1/xbmc/DllPaths_generated.h.in 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/DllPaths_generated.h.in 2012-05-14 14:08:55.845370392 +0200 +@@ -74,13 +74,13 @@ + #define DLL_PATH_LIBMAD "@MAD_SONAME@" + + /* ffmpeg */ +-#define DLL_PATH_LIBAVCODEC "special://xbmcbin/system/players/dvdplayer/avcodec-52-@ARCH@.so" +-#define DLL_PATH_LIBAVCORE "special://xbmcbin/system/players/dvdplayer/avcore-0-@ARCH@.so" +-#define DLL_PATH_LIBAVFORMAT "special://xbmcbin/system/players/dvdplayer/avformat-52-@ARCH@.so" +-#define DLL_PATH_LIBAVUTIL "special://xbmcbin/system/players/dvdplayer/avutil-50-@ARCH@.so" +-#define DLL_PATH_LIBPOSTPROC "special://xbmcbin/system/players/dvdplayer/postproc-51-@ARCH@.so" +-#define DLL_PATH_LIBSWSCALE "special://xbmcbin/system/players/dvdplayer/swscale-0-@ARCH@.so" +-#define DLL_PATH_LIBAVFILTER "special://xbmcbin/system/players/dvdplayer/avfilter-1-@ARCH@.so" ++#define DLL_PATH_LIBAVCODEC "special://xbmcbin/system/players/dvdplayer/avcodec-53-@ARCH@.so" ++#define DLL_PATH_LIBAVFORMAT "special://xbmcbin/system/players/dvdplayer/avformat-53-@ARCH@.so" ++#define DLL_PATH_LIBAVUTIL "special://xbmcbin/system/players/dvdplayer/avutil-51-@ARCH@.so" ++#define DLL_PATH_LIBPOSTPROC "special://xbmcbin/system/players/dvdplayer/postproc-52-@ARCH@.so" ++#define DLL_PATH_LIBSWSCALE "special://xbmcbin/system/players/dvdplayer/swscale-2-@ARCH@.so" ++#define DLL_PATH_LIBAVFILTER "special://xbmcbin/system/players/dvdplayer/avfilter-2-@ARCH@.so" ++#define DLL_PATH_LIBSWRESAMPLE "special://xbmcbin/system/players/dvdplayer/swresample-0-@ARCH@.so" + + /* cdrip */ + #if defined(_LINUX) && !defined(__APPLE__) +diff -Naur xbmc-pvr-11.0.1/xbmc/DllPaths_win32.h xbmc-pvr-11.0.1.patch/xbmc/DllPaths_win32.h +--- xbmc-pvr-11.0.1/xbmc/DllPaths_win32.h 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/DllPaths_win32.h 2012-05-14 14:08:55.846370412 +0200 +@@ -58,13 +58,13 @@ + #define DLL_PATH_LIBRTMP "special://xbmcbin/system/players/dvdplayer/librtmp.dll" + + /* ffmpeg */ +-#define DLL_PATH_LIBAVCODEC "special://xbmcbin/system/players/dvdplayer/avcodec-52.dll" +-#define DLL_PATH_LIBAVCORE "special://xbmcbin/system/players/dvdplayer/avcore-0.dll" +-#define DLL_PATH_LIBAVFORMAT "special://xbmcbin/system/players/dvdplayer/avformat-52.dll" +-#define DLL_PATH_LIBAVUTIL "special://xbmcbin/system/players/dvdplayer/avutil-50.dll" +-#define DLL_PATH_LIBAVFILTER "special://xbmcbin/system/players/dvdplayer/avfilter-1.dll" +-#define DLL_PATH_LIBPOSTPROC "special://xbmcbin/system/players/dvdplayer/postproc-51.dll" +-#define DLL_PATH_LIBSWSCALE "special://xbmcbin/system/players/dvdplayer/swscale-0.dll" ++#define DLL_PATH_LIBAVCODEC "special://xbmcbin/system/players/dvdplayer/avcodec-53.dll" ++#define DLL_PATH_LIBAVFORMAT "special://xbmcbin/system/players/dvdplayer/avformat-53.dll" ++#define DLL_PATH_LIBAVUTIL "special://xbmcbin/system/players/dvdplayer/avutil-51.dll" ++#define DLL_PATH_LIBAVFILTER "special://xbmcbin/system/players/dvdplayer/avfilter-2.dll" ++#define DLL_PATH_LIBPOSTPROC "special://xbmcbin/system/players/dvdplayer/postproc-52.dll" ++#define DLL_PATH_LIBSWSCALE "special://xbmcbin/system/players/dvdplayer/swscale-2.dll" ++#define DLL_PATH_LIBSWRESAMPLE "special://xbmcbin/system/players/dvdplayer/swresample-0.dll" + + /* cdrip */ + #define DLL_PATH_LAME_ENC "special://xbmcbin/system/cdrip/lame_enc.dll" diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.02-ffmpeg_dvd_still_frames_ended_up_in_internal_lavf_buffer.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.02-ffmpeg_dvd_still_frames_ended_up_in_internal_lavf_buffer.patch new file mode 100644 index 0000000000..5ffac97686 --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.02-ffmpeg_dvd_still_frames_ended_up_in_internal_lavf_buffer.patch @@ -0,0 +1,35 @@ +From 45e41b9096869062a2113590f3158321d06dea8b Mon Sep 17 00:00:00 2001 +From: elupus +Date: Tue, 17 Apr 2012 01:13:15 +0200 +Subject: [PATCH] fixed: dvd still frames ended up in internal lavf buffer + +This is very hackish, but it's the old solution we had for dvd +still frames. The problem is that the demuxer asks for probing +of the codec in the mpeg stream. This causes lavf to read the +whole menu structure into internal buffers. After which, it +won't read from input stream anymore and no events triggers. + +The only proper fix to avoid this is to allow this situation +in our navigator. This needs further work so that we can +process HOP/ACTIVATION events in libdvdnav without advancing +stream. +--- + lib/ffmpeg/libavformat/utils.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/lib/ffmpeg/libavformat/utils.c b/lib/ffmpeg/libavformat/utils.c +index 4729a40..63f89dd 100644 +--- a/lib/ffmpeg/libavformat/utils.c ++++ b/lib/ffmpeg/libavformat/utils.c +@@ -833,7 +833,7 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) + + if(end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)){ + int score= set_codec_from_probe_data(s, st, pd); +- if( (st->codec->codec_id != CODEC_ID_NONE && score > AVPROBE_SCORE_MAX/4) ++ if( (st->codec->codec_id != CODEC_ID_NONE && score > AVPROBE_SCORE_MAX/4-1) + || end){ + pd->buf_size=0; + av_freep(&pd->buf); +-- +1.7.10 + diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.31-ffmpeg_add_xvba_support.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.31-ffmpeg_add_xvba_support.patch new file mode 100644 index 0000000000..95eb43a1eb --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.31-ffmpeg_add_xvba_support.patch @@ -0,0 +1,813 @@ +diff -Naur xbmc-11.0.1/lib/ffmpeg/configure xbmc-11.0.1.patch/lib/ffmpeg/configure +--- xbmc-11.0.1/lib/ffmpeg/configure 2012-05-12 21:45:47.005596234 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/configure 2012-05-12 21:46:03.902936436 +0200 +@@ -113,6 +113,7 @@ + --enable-vdpau enable VDPAU code [autodetect] + --disable-dxva2 disable DXVA2 code + --disable-vda disable VDA code ++ --disable-xvba disable XVBA code + --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary) + --enable-hardcoded-tables use hardcoded tables instead of runtime generation + --disable-safe-bitstream-reader +@@ -1084,6 +1085,7 @@ + vaapi + vda + vdpau ++ xvba + version3 + x11grab + zlib +@@ -1423,6 +1425,7 @@ + h264_vaapi_hwaccel_select="vaapi h264_decoder" + h264_vda_hwaccel_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" + h264_vda_hwaccel_select="vda h264_decoder" ++h264_xvba_hwaccel_select="xvba" + h264_vdpau_decoder_select="vdpau h264_decoder" + imc_decoder_select="fft mdct sinewin" + jpegls_decoder_select="golomb" +@@ -1459,6 +1462,7 @@ + mpeg4_decoder_select="h263_decoder mpeg4video_parser" + mpeg4_encoder_select="h263_encoder" + mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" ++mpeg2_xvba_hwaccel_select="xvba mpeg2video_decoder" + mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder" + msmpeg4_crystalhd_decoder_select="crystalhd" + msmpeg4v1_decoder_select="h263_decoder" +@@ -1501,6 +1505,7 @@ + vc1_dxva2_hwaccel_deps="dxva2api_h" + vc1_dxva2_hwaccel_select="dxva2 vc1_decoder" + vc1_vaapi_hwaccel_select="vaapi vc1_decoder" ++vc1_xvba_hwaccel_select="xvba vc1_decoder" + vc1_vdpau_decoder_select="vdpau vc1_decoder" + vc1image_decoder_select="vc1_decoder" + vorbis_decoder_select="mdct" +@@ -1525,6 +1530,7 @@ + wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel" + wmv3_vdpau_decoder_select="vc1_vdpau_decoder" + wmv3image_decoder_select="wmv3_decoder" ++wmv3_xvba_hwaccel_select="vc1_xvba_hwaccel" + zlib_decoder_select="zlib" + zlib_encoder_select="zlib" + zmbv_decoder_select="zlib" +@@ -1533,6 +1539,7 @@ + crystalhd_deps="libcrystalhd_libcrystalhd_if_h" + vaapi_deps="va_va_h" + vda_deps="VideoDecodeAcceleration_VDADecoder_h pthreads" ++xvba_deps="amd_amdxvba_h" + vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" + + # parsers +@@ -3062,6 +3069,7 @@ + check_header termios.h + check_header vdpau/vdpau.h + check_header vdpau/vdpau_x11.h ++check_header amd/amdxvba.h + check_cpp_condition vdpau/vdpau.h "defined(VDP_DECODER_PROFILE_MPEG4_PART2_SP)" && enable vdpau_mpeg4_support + + check_header X11/extensions/XvMClib.h +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c 2012-05-12 21:45:47.257601308 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c 2012-05-12 21:46:03.905936496 +0200 +@@ -59,14 +59,18 @@ + REGISTER_HWACCEL (H264_VAAPI, h264_vaapi); + REGISTER_HWACCEL (H264_VDA, h264_vda); + REGISTER_HWACCEL (MPEG1_VDPAU, mpeg1_vdpau); ++ REGISTER_HWACCEL (H264_XVBA, h264_xvba); + REGISTER_HWACCEL (MPEG2_DXVA2, mpeg2_dxva2); + REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi); + REGISTER_HWACCEL (MPEG2_VDPAU, mpeg2_vdpau); + REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi); ++ REGISTER_HWACCEL (MPEG2_XVBA, mpeg2_xvba); + REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2); + REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi); ++ REGISTER_HWACCEL (VC1_XVBA, vc1_xvba); + REGISTER_HWACCEL (WMV3_DXVA2, wmv3_dxva2); + REGISTER_HWACCEL (WMV3_VAAPI, wmv3_vaapi); ++ REGISTER_HWACCEL (WMV3_XVBA, wmv3_xvba); + + /* video codecs */ + REGISTER_ENCODER (A64MULTI, a64multi); +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/h264.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/h264.c 2012-05-12 21:45:47.757611376 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c 2012-05-12 21:46:03.908936558 +0200 +@@ -60,6 +60,7 @@ + PIX_FMT_DXVA2_VLD, + PIX_FMT_VAAPI_VLD, + PIX_FMT_VDA_VLD, ++ PIX_FMT_XVBA_VLD, + PIX_FMT_YUVJ420P, + PIX_FMT_NONE + }; +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/Makefile xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/Makefile 2012-05-12 21:45:47.927614798 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile 2012-05-12 21:46:03.904936476 +0200 +@@ -3,7 +3,7 @@ + NAME = avcodec + FFLIBS = avutil + +-HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vda.h vdpau.h version.h xvmc.h ++HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vda.h vdpau.h version.h xvmc.h xvba.h + + OBJS = allcodecs.o \ + audioconvert.o \ +@@ -51,6 +51,7 @@ + OBJS-$(CONFIG_VAAPI) += vaapi.o + OBJS-$(CONFIG_VDA) += vda.o + OBJS-$(CONFIG_VDPAU) += vdpau.o ++OBJS-$(CONFIG_XVBA) += xvba.o + + # decoders/encoders/hardware accelerators + OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o +@@ -201,6 +202,7 @@ + OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o + OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o + OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o ++OBJS-$(CONFIG_H264_XVBA_HWACCEL) += xvba_h264.o + OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o + OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o + OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o +@@ -284,6 +286,7 @@ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o + OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o ++OBJS-$(CONFIG_MPEG2_XVBA_HWACCEL) += xvba_mpeg2.o + OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \ + mpegvideo.o error_resilience.o + OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ +@@ -431,6 +434,7 @@ + intrax8.o intrax8dsp.o + OBJS-$(CONFIG_VC1_DXVA2_HWACCEL) += dxva2_vc1.o + OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o ++OBJS-$(CONFIG_VC1_XVBA_HWACCEL) += xvba_vc1.o + OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o + OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o + OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o +@@ -732,6 +736,7 @@ + SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h + SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h + SKIPHEADERS-$(CONFIG_VDA) += vda_internal.h ++SKIPHEADERS-$(CONFIG_XVBA) += xvba_internal.h + SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h + SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h + SKIPHEADERS-$(HAVE_W32THREADS) += w32pthreads.h +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c 2012-05-12 21:45:48.027616812 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c 2012-05-12 21:46:03.910936598 +0200 +@@ -136,6 +136,7 @@ + PIX_FMT_DXVA2_VLD, + PIX_FMT_VAAPI_VLD, + PIX_FMT_VDA_VLD, ++ PIX_FMT_XVBA_VLD, + PIX_FMT_YUV420P, + PIX_FMT_NONE + }; +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.c 2012-05-12 21:46:03.918936758 +0200 +@@ -0,0 +1,66 @@ ++/* ++ * HW decode acceleration for MPEG-2, H.264 and VC-1 ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++ ++/** ++ * \addtogroup XVBA_Decoding ++ * ++ * @{ ++ */ ++ ++#include ++#include "xvba.h" ++#include "xvba_internal.h" ++#include "avcodec.h" ++ ++int ff_xvba_translate_profile(int profile) { ++ ++ if (profile == 66) ++ return 1; ++ else if (profile == 77) ++ return 2; ++ else if (profile == 100) ++ return 3; ++ else if (profile == 0) ++ return 4; ++ else if (profile == 1) ++ return 5; ++ else if (profile == 3) ++ return 6; ++ else ++ return -1; ++} ++ ++void ff_xvba_add_slice_data(struct xvba_render_state *render, const uint8_t *buffer, uint32_t size) { ++ ++ render->buffers = av_fast_realloc( ++ render->buffers, ++ &render->buffers_alllocated, ++ sizeof(struct xvba_bitstream_buffers)*(render->num_slices + 1) ++ ); ++ ++ render->buffers[render->num_slices].buffer = buffer; ++ render->buffers[render->num_slices].size = size; ++ ++ render->num_slices++; ++} ++ +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.h +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.h 2012-05-12 21:46:03.918936758 +0200 +@@ -0,0 +1,71 @@ ++/* ++ * HW decode acceleration for MPEG-2, H.264 and VC-1 ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#ifndef AVCODEC_XVBA_H ++#define AVCODEC_XVBA_H ++ ++#include ++#include ++#include ++ ++ ++/** ++ * \defgroup XVBA_Decoding VA API Decoding ++ * \ingroup Decoder ++ * @{ ++ */ ++ ++/** \brief The videoSurface is used for rendering. */ ++#define FF_XVBA_STATE_USED_FOR_RENDER 1 ++ ++/** ++ * \brief The videoSurface is needed for reference/prediction. ++ * The codec manipulates this. ++ */ ++#define FF_XVBA_STATE_USED_FOR_REFERENCE 2 ++ ++/** ++ * \brief The videoSurface holds a decoded frame. ++ * The codec manipulates this. ++ */ ++#define FF_XVBA_STATE_DECODED 4 ++ ++/* @} */ ++ ++struct xvba_bitstream_buffers ++{ ++ const void *buffer; ++ unsigned int size; ++}; ++ ++struct xvba_render_state { ++ ++ int state; ///< Holds FF_XVBA_STATE_* values. ++ void *surface; ++ XVBAPictureDescriptor *picture_descriptor; ++ XVBAQuantMatrixAvc *iq_matrix; ++ int num_slices; ++ struct xvba_bitstream_buffers *buffers; ++ uint32_t buffers_alllocated; ++}; ++ ++#endif /* AVCODEC_XVBA_H */ +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_h264.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_h264.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_h264.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_h264.c 2012-05-12 21:46:03.919936778 +0200 +@@ -0,0 +1,180 @@ ++/* ++ * H.264 HW decode acceleration through XVBA ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "xvba.h" ++#include "xvba_internal.h" ++#include "h264.h" ++#include ++ ++/** @file ++ * This file implements the glue code between FFmpeg's and XvBA API's ++ * structures for H.264 decoding. ++ */ ++ ++ ++/** Initialize and start decoding a frame with XVBA. */ ++static int start_frame(AVCodecContext *avctx, ++ av_unused const uint8_t *buffer, ++ av_unused uint32_t size) ++{ ++ H264Context * const h = avctx->priv_data; ++ MpegEncContext * const s = &h->s; ++ struct xvba_render_state *render; ++ XVBAPictureDescriptor *pic_descriptor; ++ int i; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ if (render->picture_descriptor == 0) ++ return -1; ++ ++ pic_descriptor = render->picture_descriptor; ++ ++ for (i = 0; i < 2; ++i) { ++ int foc = s->current_picture_ptr->field_poc[i]; ++ if (foc == INT_MAX) ++ foc = 0; ++ pic_descriptor->avc_curr_field_order_cnt_list[i] = foc; ++ } ++ ++ pic_descriptor->avc_frame_num = h->frame_num; ++ ++ render->num_slices = 0; ++ ++ return 0; ++} ++ ++/** End a hardware decoding based frame. */ ++static int end_frame(AVCodecContext *avctx) ++{ ++ H264Context * const h = avctx->priv_data; ++ MpegEncContext * const s = &h->s; ++ struct xvba_render_state *render; ++ XVBAPictureDescriptor *pic_descriptor; ++ XVBAQuantMatrixAvc *iq_matrix; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ if (render->picture_descriptor == 0 || render->iq_matrix == 0) ++ return -1; ++ ++ pic_descriptor = render->picture_descriptor; ++ iq_matrix = render->iq_matrix; ++ ++ av_dlog(avctx, "end_frame()\n"); ++ ++ /* Fill in Picture Parameters*/ ++ pic_descriptor->profile = ff_xvba_translate_profile(avctx->profile); ++ pic_descriptor->level = avctx->level; ++ pic_descriptor->width_in_mb = s->mb_width; ++ pic_descriptor->height_in_mb = s->mb_height; ++ pic_descriptor->picture_structure = s->picture_structure; ++ pic_descriptor->chroma_format = s->chroma_format ? s->chroma_format : 1; ++ pic_descriptor->avc_intra_flag = (h->slice_type == FF_I_TYPE) ? 1 : 0; ++ pic_descriptor->avc_reference = (s->current_picture_ptr->f.reference & 3) ? 1 : 0; ++ ++ pic_descriptor->avc_bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; ++ pic_descriptor->avc_bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; ++ pic_descriptor->avc_log2_max_frame_num_minus4 = h->sps.log2_max_frame_num -4; ++ pic_descriptor->avc_pic_order_cnt_type = h->sps.poc_type; ++ pic_descriptor->avc_log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4; ++ pic_descriptor->avc_num_ref_frames = h->sps.ref_frame_count; ++ pic_descriptor->avc_reserved_8bit = 0; ++ ++ pic_descriptor->avc_num_slice_groups_minus1 = h->pps.slice_group_count - 1; ++ pic_descriptor->avc_num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1; ++ pic_descriptor->avc_num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1; ++ ++ pic_descriptor->avc_pic_init_qp_minus26 = h->pps.init_qp - 26; ++ pic_descriptor->avc_pic_init_qs_minus26 = h->pps.init_qs - 26; ++ pic_descriptor->avc_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0]; ++ pic_descriptor->avc_second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1]; ++ pic_descriptor->avc_slice_group_change_rate_minus1 = 0; // not implemented in ffmpeg ++ pic_descriptor->avc_reserved_16bit = 0; // must be 0 ++ memset(pic_descriptor->avc_field_order_cnt_list,0,sizeof(pic_descriptor->avc_field_order_cnt_list)); // must be 0 ++ memset(pic_descriptor->avc_slice_group_map,0,sizeof(pic_descriptor->avc_slice_group_map)); // must be 0 ++ ++ // sps ++ pic_descriptor->sps_info.avc.delta_pic_always_zero_flag = h->sps.delta_pic_order_always_zero_flag; ++ pic_descriptor->sps_info.avc.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag; ++ pic_descriptor->sps_info.avc.frame_mbs_only_flag = h->sps.frame_mbs_only_flag; ++ pic_descriptor->sps_info.avc.gaps_in_frame_num_value_allowed_flag = h->sps.gaps_in_frame_num_allowed_flag; ++ pic_descriptor->sps_info.avc.mb_adaptive_frame_field_flag = h->sps.mb_aff; ++ pic_descriptor->sps_info.avc.residual_colour_transform_flag = h->sps.residual_color_transform_flag; ++ pic_descriptor->sps_info.avc.xvba_avc_sps_reserved = 0; ++ ++ // pps ++ pic_descriptor->pps_info.avc.entropy_coding_mode_flag = h->pps.cabac; ++ pic_descriptor->pps_info.avc.pic_order_present_flag = h->pps.pic_order_present; ++ pic_descriptor->pps_info.avc.weighted_pred_flag = h->pps.weighted_pred; ++ pic_descriptor->pps_info.avc.weighted_bipred_idc = h->pps.weighted_bipred_idc; ++ pic_descriptor->pps_info.avc.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; ++ pic_descriptor->pps_info.avc.constrained_intra_pred_flag = h->pps.constrained_intra_pred; ++ pic_descriptor->pps_info.avc.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present; ++ pic_descriptor->pps_info.avc.transform_8x8_mode_flag = h->pps.transform_8x8_mode; ++ pic_descriptor->pps_info.avc.xvba_avc_pps_reserved = 0; // must be 0 ++ ++ memcpy(iq_matrix->bScalingLists4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->bScalingLists4x4)); ++ memcpy(iq_matrix->bScalingLists8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->bScalingLists8x8)); ++ ++ // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs ++ if (!h->got_first_iframe) { ++ if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) ++ return -1; ++ h->got_first_iframe = 1; ++ } ++ ++ ff_draw_horiz_band(s, 0, s->avctx->height); ++ ++ return 0; ++} ++ ++/** Decode the given H.264 slice with XVBA. */ ++static int decode_slice(AVCodecContext *avctx, ++ const uint8_t *buffer, ++ uint32_t size) ++{ ++ H264Context * const h = avctx->priv_data; ++ MpegEncContext * const s = &h->s; ++ struct xvba_render_state *render; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ ff_xvba_add_slice_data(render, buffer, size); ++ ++ return 0; ++} ++ ++AVHWAccel ff_h264_xvba_hwaccel = { ++ .name = "h264_xvba", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_H264, ++ .pix_fmt = PIX_FMT_XVBA_VLD, ++ .capabilities = 0, ++ .start_frame = start_frame, ++ .end_frame = end_frame, ++ .decode_slice = decode_slice, ++ .priv_data_size = 0, ++}; +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_internal.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_internal.h +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_internal.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_internal.h 2012-05-12 21:46:03.920936798 +0200 +@@ -0,0 +1,24 @@ ++/* ++ * HW decode acceleration for MPEG-2, H.264 and VC-1 ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++int ff_xvba_translate_profile(int profile); ++void ff_xvba_add_slice_data(struct xvba_render_state *render, const uint8_t *buffer, uint32_t size); +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_mpeg2.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_mpeg2.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_mpeg2.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_mpeg2.c 2012-05-12 21:46:03.920936798 +0200 +@@ -0,0 +1,52 @@ ++/* ++ * MPEG-2 HW decode acceleration through XVBA ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "dsputil.h" ++ ++static int start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size) ++{ ++ struct MpegEncContext * const s = avctx->priv_data; ++ return 0; ++} ++ ++static int end_frame(AVCodecContext *avctx) ++{ ++ return 0; ++} ++ ++static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) ++{ ++ struct MpegEncContext * const s = avctx->priv_data; ++ return 0; ++} ++ ++AVHWAccel ff_mpeg2_xvba_hwaccel = { ++ .name = "mpeg2_xvba", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_MPEG2VIDEO, ++ .pix_fmt = PIX_FMT_XVBA_VLD, ++ .capabilities = 0, ++ .start_frame = start_frame, ++ .end_frame = end_frame, ++ .decode_slice = decode_slice, ++ .priv_data_size = 0, ++}; +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_vc1.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_vc1.c +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_vc1.c 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_vc1.c 2012-05-12 21:46:03.921936819 +0200 +@@ -0,0 +1,194 @@ ++/* ++ * VC-1 HW decode acceleration through XVBA ++ * ++ * Copyright (C) 2005-2011 Team XBMC ++ * ++ * This file is part of FFmpeg. ++ * ++ * FFmpeg is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU Lesser General Public ++ * License as published by the Free Software Foundation; either ++ * version 2.1 of the License, or (at your option) any later version. ++ * ++ * FFmpeg 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 ++ * Lesser General Public License for more details. ++ * ++ * You should have received a copy of the GNU Lesser General Public ++ * License along with FFmpeg; if not, write to the Free Software ++ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ++ */ ++ ++#include "xvba.h" ++#include "xvba_internal.h" ++#include "vc1.h" ++#include "vc1data.h" ++#include ++ ++ ++/** @file ++ * Implement structures of ffmpeg <-> XvBA ++ */ ++ ++/* Initialize and start decoding a frame with XvBA */ ++static int start_frame(AVCodecContext *avctx, ++ av_unused const uint8_t *buffer, ++ av_unused uint32_t size) ++{ ++ VC1Context * const v = avctx->priv_data; ++ MpegEncContext * const s = &v->s; ++ struct xvba_render_state *render; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ render->num_slices = 0; ++ return 0; ++} ++ ++/* End a hardware decoding based frame */ ++static int end_frame(AVCodecContext *avctx) ++{ ++ VC1Context* const v = avctx->priv_data; ++ MpegEncContext* const s = &v->s; ++ struct xvba_render_state *render, *last, *next; ++ XVBAPictureDescriptor *pic_descriptor; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ if (render->picture_descriptor == 0) ++ return -1; ++ ++ pic_descriptor = render->picture_descriptor; ++ ++ av_dlog(avctx, "xvba_vc1_end_frame()\n"); ++ ++ memset(pic_descriptor, 0, sizeof(*pic_descriptor)); ++ ++ /* Fill in Parameters - for reference see AMD sdk documentation */ ++ pic_descriptor->profile = ff_xvba_translate_profile(v->profile); ++ pic_descriptor->level = v->level; ++ //done like in va-driver and vaapi ++ if (v->profile == PROFILE_ADVANCED) { ++ pic_descriptor->width_in_mb = s->avctx->coded_width; ++ pic_descriptor->height_in_mb = s->avctx->coded_height; ++ } else { ++ pic_descriptor->width_in_mb = s->mb_width; ++ pic_descriptor->height_in_mb = s->mb_height; ++ } ++ pic_descriptor->picture_structure = s->picture_structure; ++ // xvba-video set this to 1 only 4:2:0 supported ++ // doc says: if not set, choose 1 - we try this ++ pic_descriptor->chroma_format = 1; ++ pic_descriptor->avc_intra_flag = s->pict_type == FF_I_TYPE || v->bi_type == 1; ++ pic_descriptor->avc_reference = (s->current_picture_ptr->f.reference & 3) ? 1 : 0; ++ ++ // VC-1 explicit parameters see page 30 of sdk ++ // sps_info ++ pic_descriptor->sps_info.vc1.postprocflag = v->postprocflag; ++ ++ // done as in vaapi ++ pic_descriptor->sps_info.vc1.pulldown = v->broadcast; ++ pic_descriptor->sps_info.vc1.interlace = v->interlace; ++ pic_descriptor->sps_info.vc1.tfcntrflag = v->tfcntrflag; ++ pic_descriptor->sps_info.vc1.finterpflag = v->finterpflag; ++ pic_descriptor->sps_info.vc1.reserved = 1; ++ // eventually check if this makes sense together with interlace ++ pic_descriptor->sps_info.vc1.psf = v->psf; ++ // what about if it is a frame (page 31) ++ // looked at xvba-driver ++ pic_descriptor->sps_info.vc1.second_field = !s->first_field; ++ pic_descriptor->sps_info.vc1.xvba_vc1_sps_reserved = 0; ++ ++ // VC-1 explicit parameters see page 30 of sdk ++ // pps_info ++ pic_descriptor->pps_info.vc1.panscan_flag = v->panscanflag; ++ pic_descriptor->pps_info.vc1.refdist_flag = v->refdist_flag; ++ pic_descriptor->pps_info.vc1.loopfilter = s->loop_filter; ++ pic_descriptor->pps_info.vc1.fastuvmc = v->fastuvmc; ++ pic_descriptor->pps_info.vc1.extended_mv = v->extended_mv; ++ pic_descriptor->pps_info.vc1.dquant = v->dquant; ++ pic_descriptor->pps_info.vc1.vstransform = v->vstransform; ++ pic_descriptor->pps_info.vc1.overlap = v->overlap; ++ pic_descriptor->pps_info.vc1.quantizer = v->quantizer_mode; ++ pic_descriptor->pps_info.vc1.extended_dmv = v->extended_dmv; ++ pic_descriptor->pps_info.vc1.maxbframes = s->avctx->max_b_frames; ++ pic_descriptor->pps_info.vc1.rangered = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : v->rangered; ++ pic_descriptor->pps_info.vc1.syncmarker = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : s->resync_marker; ++ pic_descriptor->pps_info.vc1.multires = v->multires; ++ pic_descriptor->pps_info.vc1.reserved = 1; ++ pic_descriptor->pps_info.vc1.range_mapy_flag = v->range_mapy_flag; ++ pic_descriptor->pps_info.vc1.range_mapy = v->range_mapy; ++ pic_descriptor->pps_info.vc1.range_mapuv_flag = v->range_mapuv_flag; ++ pic_descriptor->pps_info.vc1.range_mapuv = v->range_mapuv; ++ pic_descriptor->pps_info.vc1.xvba_vc1_pps_reserved = 0; ++ ++ pic_descriptor->past_surface = 0; ++ pic_descriptor->future_surface = 0; ++ switch (s->pict_type) { ++ case FF_B_TYPE: ++ next = (struct xvba_render_state *)s->next_picture.f.data[0]; ++ assert(next); ++ if (next) ++ pic_descriptor->past_surface = next->surface; ++ // fall-through ++ case FF_P_TYPE: ++ last = (struct xvba_render_state *)s->last_picture.f.data[0]; ++ assert(last); ++ if (last) ++ pic_descriptor->future_surface = last->surface; ++ break; ++ } ++ ++ ff_draw_horiz_band(s, 0, s->avctx->height); ++ ++ return 0; ++} ++ ++static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) ++{ ++ VC1Context* const v = avctx->priv_data; ++ MpegEncContext* const s = &v->s; ++ struct xvba_render_state *render; ++ ++ render = (struct xvba_render_state *)s->current_picture_ptr->f.data[0]; ++ assert(render); ++ ++ if (avctx->codec_id == CODEC_ID_VC1 && ++ size >= 4 && IS_MARKER(AV_RB32(buffer))) { ++ buffer += 4; ++ size -= 4; ++ } ++ ++ ff_xvba_add_slice_data(render, buffer, size); ++ ++ return 0; ++} ++ ++#if CONFIG_WMV3_XVBA_HWACCEL ++AVHWAccel ff_wmv3_xvba_hwaccel = { ++ .name = "wmv3_xvba", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_WMV3, ++ .pix_fmt = PIX_FMT_XVBA_VLD, ++ .capabilities = 0, ++ .start_frame = start_frame, ++ .end_frame = end_frame, ++ .decode_slice = decode_slice, ++ .priv_data_size = 0, ++}; ++#endif ++ ++AVHWAccel ff_vc1_xvba_hwaccel = { ++ .name = "vc1_xvba", ++ .type = AVMEDIA_TYPE_VIDEO, ++ .id = CODEC_ID_VC1, ++ .pix_fmt = PIX_FMT_XVBA_VLD, ++ .capabilities = 0, ++ .start_frame = start_frame, ++ .end_frame = end_frame, ++ .decode_slice = decode_slice, ++ .priv_data_size = 0, ++}; +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h +--- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-05-12 21:45:48.572627784 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-05-12 21:46:03.922936840 +0200 +@@ -1,5 +1,7 @@ + /* +- * XVideo Motion Compensation internal functions ++ * HW decode acceleration for MPEG-2, H.264 and VC-1 ++ * ++ * Copyright (C) 2005-2011 Team XBMC + * + * This file is part of FFmpeg. + * +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavutil/pixdesc.c xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.c +--- xbmc-11.0.1/lib/ffmpeg/libavutil/pixdesc.c 2012-05-12 21:45:49.442645301 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.c 2012-05-12 21:46:03.923936860 +0200 +@@ -874,6 +874,12 @@ + .log2_chroma_h = 1, + .flags = PIX_FMT_HWACCEL, + }, ++ [PIX_FMT_XVBA_VLD] = { ++ .name = "xvba_vld", ++ .log2_chroma_w = 1, ++ .log2_chroma_h = 1, ++ .flags = PIX_FMT_HWACCEL, ++ }, + [PIX_FMT_YUV420P9LE] = { + .name = "yuv420p9le", + .nb_components = 3, +diff -Naur xbmc-11.0.1/lib/ffmpeg/libavutil/pixfmt.h xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h +--- xbmc-11.0.1/lib/ffmpeg/libavutil/pixfmt.h 2012-05-12 21:45:49.445645361 +0200 ++++ xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h 2012-05-12 21:46:03.924936880 +0200 +@@ -129,6 +129,7 @@ + PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian + PIX_FMT_VDPAU_MPEG4, ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers + PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer ++ PIX_FMT_XVBA_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers + + PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 + PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.32-ffmpeg_xvba_adapt_to_new_ffmpeg_fix_artifacts_for_h.264.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.32-ffmpeg_xvba_adapt_to_new_ffmpeg_fix_artifacts_for_h.264.patch new file mode 100644 index 0000000000..b5aa15dced --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.32-ffmpeg_xvba_adapt_to_new_ffmpeg_fix_artifacts_for_h.264.patch @@ -0,0 +1,50 @@ +From 1f4d4832065673eaa989bd8d45f55703d8a135ab Mon Sep 17 00:00:00 2001 +From: xbmc +Date: Mon, 30 Apr 2012 13:58:29 +0200 +Subject: [PATCH] ffmpeg: xvba, adapt to new ffmpeg, fix artifacts for h.264 + +--- + lib/ffmpeg/libavcodec/xvba_h264.c | 9 ++++----- + 1 file changed, 4 insertions(+), 5 deletions(-) + +diff --git a/lib/ffmpeg/libavcodec/xvba_h264.c b/lib/ffmpeg/libavcodec/xvba_h264.c +index 1f737b0..9be6ffb 100644 +--- a/lib/ffmpeg/libavcodec/xvba_h264.c ++++ b/lib/ffmpeg/libavcodec/xvba_h264.c +@@ -91,7 +91,7 @@ static int end_frame(AVCodecContext *avctx) + pic_descriptor->height_in_mb = s->mb_height; + pic_descriptor->picture_structure = s->picture_structure; + pic_descriptor->chroma_format = s->chroma_format ? s->chroma_format : 1; +- pic_descriptor->avc_intra_flag = (h->slice_type == FF_I_TYPE) ? 1 : 0; ++ pic_descriptor->avc_intra_flag = (h->slice_type == AV_PICTURE_TYPE_I) ? 1 : 0; + pic_descriptor->avc_reference = (s->current_picture_ptr->f.reference & 3) ? 1 : 0; + + pic_descriptor->avc_bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; +@@ -136,11 +136,12 @@ static int end_frame(AVCodecContext *avctx) + pic_descriptor->pps_info.avc.xvba_avc_pps_reserved = 0; // must be 0 + + memcpy(iq_matrix->bScalingLists4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->bScalingLists4x4)); +- memcpy(iq_matrix->bScalingLists8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->bScalingLists8x8)); ++ memcpy(iq_matrix->bScalingLists8x8[0], h->pps.scaling_matrix8[0], sizeof(iq_matrix->bScalingLists8x8[0])); ++ memcpy(iq_matrix->bScalingLists8x8[1], h->pps.scaling_matrix8[3], sizeof(iq_matrix->bScalingLists8x8[0])); + + // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs + if (!h->got_first_iframe) { +- if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) ++ if (h->slice_type != AV_PICTURE_TYPE_I && h->slice_type != AV_PICTURE_TYPE_SI) + return -1; + h->got_first_iframe = 1; + } +@@ -172,9 +173,7 @@ static int decode_slice(AVCodecContext *avctx, + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_H264, + .pix_fmt = PIX_FMT_XVBA_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .end_frame = end_frame, + .decode_slice = decode_slice, +- .priv_data_size = 0, + }; +-- +1.7.10 + diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.33-ffmpeg_xvba_xvba_vc-1_new_ffmpeg.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.33-ffmpeg_xvba_xvba_vc-1_new_ffmpeg.patch new file mode 100644 index 0000000000..ae2ac514ab --- /dev/null +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-901.33-ffmpeg_xvba_xvba_vc-1_new_ffmpeg.patch @@ -0,0 +1,64 @@ +From 81d1514a1daf379d58c61080244bb01c7ee7e662 Mon Sep 17 00:00:00 2001 +From: fritsch +Date: Mon, 30 Apr 2012 21:33:18 +0200 +Subject: [PATCH] xvba: (VC-1) rename FF_P_TYPE, FF_B_TYPE and FF_I_TYPE to + new ffmpeg conventions + +--- + lib/ffmpeg/libavcodec/xvba_vc1.c | 10 +++------- + 1 file changed, 3 insertions(+), 7 deletions(-) + +diff --git a/lib/ffmpeg/libavcodec/xvba_vc1.c b/lib/ffmpeg/libavcodec/xvba_vc1.c +index c202b9c..7315b62 100644 +--- a/lib/ffmpeg/libavcodec/xvba_vc1.c ++++ b/lib/ffmpeg/libavcodec/xvba_vc1.c +@@ -82,7 +82,7 @@ static int end_frame(AVCodecContext *avctx) + // xvba-video set this to 1 only 4:2:0 supported + // doc says: if not set, choose 1 - we try this + pic_descriptor->chroma_format = 1; +- pic_descriptor->avc_intra_flag = s->pict_type == FF_I_TYPE || v->bi_type == 1; ++ pic_descriptor->avc_intra_flag = s->pict_type == AV_PICTURE_TYPE_I || v->bi_type == 1; + pic_descriptor->avc_reference = (s->current_picture_ptr->f.reference & 3) ? 1 : 0; + + // VC-1 explicit parameters see page 30 of sdk +@@ -128,13 +128,13 @@ static int end_frame(AVCodecContext *avctx) + pic_descriptor->past_surface = 0; + pic_descriptor->future_surface = 0; + switch (s->pict_type) { +- case FF_B_TYPE: ++ case AV_PICTURE_TYPE_B: + next = (struct xvba_render_state *)s->next_picture.f.data[0]; + assert(next); + if (next) + pic_descriptor->past_surface = next->surface; + // fall-through +- case FF_P_TYPE: ++ case AV_PICTURE_TYPE_P: + last = (struct xvba_render_state *)s->last_picture.f.data[0]; + assert(last); + if (last) +@@ -173,11 +173,9 @@ static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t s + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_WMV3, + .pix_fmt = PIX_FMT_XVBA_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .end_frame = end_frame, + .decode_slice = decode_slice, +- .priv_data_size = 0, + }; + #endif + +@@ -186,9 +184,7 @@ static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t s + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_VC1, + .pix_fmt = PIX_FMT_XVBA_VLD, +- .capabilities = 0, + .start_frame = start_frame, + .end_frame = end_frame, + .decode_slice = decode_slice, +- .priv_data_size = 0, + }; +-- +1.7.10 + diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.00-xdpau_reset_pvr_changes.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.00-xdpau_reset_pvr_changes.patch index e1ff0da442..2fdf1dbed4 100644 --- a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.00-xdpau_reset_pvr_changes.patch +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.00-xdpau_reset_pvr_changes.patch @@ -1,6 +1,6 @@ diff -Naur xbmc-pvr-11.0.1/language/Dutch/strings.xml xbmc-pvr-11.0.1.patch/language/Dutch/strings.xml --- xbmc-pvr-11.0.1/language/Dutch/strings.xml 2012-03-27 17:55:51.000000000 +0200 -+++ xbmc-pvr-11.0.1.patch/language/Dutch/strings.xml 2012-05-14 09:40:49.363267601 +0200 ++++ xbmc-pvr-11.0.1.patch/language/Dutch/strings.xml 2012-05-14 14:13:28.656860932 +0200 @@ -1542,7 +1542,6 @@ Spline36 Spline36 geoptimaliseerd @@ -11,7 +11,7 @@ diff -Naur xbmc-pvr-11.0.1/language/Dutch/strings.xml xbmc-pvr-11.0.1.patch/lang diff -Naur xbmc-pvr-11.0.1/language/English/strings.xml xbmc-pvr-11.0.1.patch/language/English/strings.xml --- xbmc-pvr-11.0.1/language/English/strings.xml 2012-03-27 17:55:51.000000000 +0200 -+++ xbmc-pvr-11.0.1.patch/language/English/strings.xml 2012-05-14 09:40:49.366267654 +0200 ++++ xbmc-pvr-11.0.1.patch/language/English/strings.xml 2012-05-14 14:13:28.661861033 +0200 @@ -1539,9 +1539,7 @@ DXVA Best Spline36 @@ -23,8 +23,8 @@ diff -Naur xbmc-pvr-11.0.1/language/English/strings.xml xbmc-pvr-11.0.1.patch/la Post-processing diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp ---- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-03-27 17:55:38.000000000 +0200 -+++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 09:40:49.371267744 +0200 +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 14:11:52.791931577 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 14:13:28.663861073 +0200 @@ -531,8 +531,7 @@ bool CVDPAU::Supports(EINTERLACEMETHOD method) { @@ -59,7 +59,7 @@ diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-p { VdpBool enabled[]={1,0,0}; vdp_st = vdp_video_mixer_set_feature_enables(videoMixer, ARSIZE(feature), feature, enabled); -@@ -1401,16 +1387,14 @@ +@@ -1399,16 +1385,14 @@ if (mode == VS_DEINTERLACEMODE_FORCE || (mode == VS_DEINTERLACEMODE_AUTO && m_DVDVideoPics.front().iFlags & DVP_FLAG_INTERLACED)) { @@ -80,7 +80,7 @@ diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-p m_mixerstep = 0; diff -Naur xbmc-pvr-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp xbmc-pvr-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp --- xbmc-pvr-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-03-27 17:55:34.000000000 +0200 -+++ xbmc-pvr-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-05-14 09:40:52.908330712 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-05-14 14:13:28.664861093 +0200 @@ -113,7 +113,6 @@ entries.push_back(make_pair(VS_INTERLACEMETHOD_VDPAU_INVERSE_TELECINE , 16314)); entries.push_back(make_pair(VS_INTERLACEMETHOD_DXVA_BOB , 16320)); diff --git a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.01-xvba_support_vdpau_rework-c633159.patch b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.01-xvba_support_vdpau_rework-c633159.patch index 807ade8595..98a4fa1a77 100644 --- a/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.01-xvba_support_vdpau_rework-c633159.patch +++ b/packages/mediacenter/xbmc-pvr/patches/xbmc-pvr-11.0.1-902.01-xvba_support_vdpau_rework-c633159.patch @@ -1,6 +1,6 @@ -diff -Naur xbmc-11.0.1/configure.in xbmc-11.0.1.patch/configure.in ---- xbmc-11.0.1/configure.in 2012-03-21 23:57:58.000000000 +0100 -+++ xbmc-11.0.1.patch/configure.in 2012-05-13 22:08:46.942192804 +0200 +diff -Naur xbmc-pvr-11.0.1/configure.in xbmc-pvr-11.0.1.patch/configure.in +--- xbmc-pvr-11.0.1/configure.in 2012-05-14 14:11:49.081856910 +0200 ++++ xbmc-pvr-11.0.1.patch/configure.in 2012-05-14 14:15:12.045218673 +0200 @@ -98,6 +98,8 @@ vaapi_disabled="== VAAPI support manually disabled. ==" crystalhd_not_found="== Could not find libcrystalhd. CrystalHD support disabled. ==" @@ -75,7 +75,7 @@ diff -Naur xbmc-11.0.1/configure.in xbmc-11.0.1.patch/configure.in if test "x$use_vdadecoder" != "xno"; then final_message="$final_message\n VDADecoder:\tYes" else -@@ -1943,6 +1989,7 @@ +@@ -1952,6 +1998,7 @@ AC_SUBST(USE_VDPAU) AC_SUBST(USE_VAAPI) AC_SUBST(USE_CRYSTALHD) @@ -83,7 +83,7 @@ diff -Naur xbmc-11.0.1/configure.in xbmc-11.0.1.patch/configure.in AC_SUBST(USE_LIBSMBCLIENT) AC_SUBST(USE_LIBNFS) AC_SUBST(USE_LIBAFPCLIENT) -@@ -2085,6 +2132,7 @@ +@@ -2094,6 +2141,7 @@ --enable-gpl \ `if test "x$use_vdpau" != "xno"; then echo --enable-vdpau; else echo --disable-vdpau; fi` \ `if test "x$use_vaapi" != "xno"; then echo --enable-vaapi; else echo --disable-vaapi; fi` \ @@ -91,10 +91,10 @@ diff -Naur xbmc-11.0.1/configure.in xbmc-11.0.1.patch/configure.in --enable-protocol=http \ --enable-pthreads \ --enable-runtime-cpudetect \ -diff -Naur xbmc-11.0.1/language/Dutch/strings.xml xbmc-11.0.1.patch/language/Dutch/strings.xml ---- xbmc-11.0.1/language/Dutch/strings.xml 2012-03-21 23:57:54.000000000 +0100 -+++ xbmc-11.0.1.patch/language/Dutch/strings.xml 2012-05-13 22:16:42.908637517 +0200 -@@ -1233,7 +1233,8 @@ +diff -Naur xbmc-pvr-11.0.1/language/Dutch/strings.xml xbmc-pvr-11.0.1.patch/language/Dutch/strings.xml +--- xbmc-pvr-11.0.1/language/Dutch/strings.xml 2012-05-14 14:14:51.670808009 +0200 ++++ xbmc-pvr-11.0.1.patch/language/Dutch/strings.xml 2012-05-14 14:15:12.051218793 +0200 +@@ -1236,7 +1236,8 @@ Hardwareversnelling inschakelen (OpenMax) Pixelshaders Hardware acceleratie toestaan (VideoToolbox) @@ -104,7 +104,7 @@ diff -Naur xbmc-11.0.1/language/Dutch/strings.xml xbmc-11.0.1.patch/language/Dut A/V-synchronisatiemethode Audiosignaal Videosignaal (Drop/Dupe audio) -@@ -1539,6 +1540,7 @@ +@@ -1542,6 +1543,7 @@ Spline36 Spline36 geoptimaliseerd Software menging @@ -112,10 +112,10 @@ diff -Naur xbmc-11.0.1/language/Dutch/strings.xml xbmc-11.0.1.patch/language/Dut Kwaliteitsverbetering video -diff -Naur xbmc-11.0.1/language/English/strings.xml xbmc-11.0.1.patch/language/English/strings.xml ---- xbmc-11.0.1/language/English/strings.xml 2012-03-21 23:57:54.000000000 +0100 -+++ xbmc-11.0.1.patch/language/English/strings.xml 2012-05-13 22:16:30.975400722 +0200 -@@ -1232,6 +1232,9 @@ +diff -Naur xbmc-pvr-11.0.1/language/English/strings.xml xbmc-pvr-11.0.1.patch/language/English/strings.xml +--- xbmc-pvr-11.0.1/language/English/strings.xml 2012-05-14 14:14:51.673808069 +0200 ++++ xbmc-pvr-11.0.1.patch/language/English/strings.xml 2012-05-14 14:15:12.053218833 +0200 +@@ -1234,6 +1234,9 @@ Allow hardware acceleration (OpenMax) Pixel Shaders Allow hardware acceleration (VideoToolbox) @@ -125,7 +125,7 @@ diff -Naur xbmc-11.0.1/language/English/strings.xml xbmc-11.0.1.patch/language/E A/V sync method Audio clock -@@ -1538,6 +1541,8 @@ +@@ -1540,6 +1543,8 @@ Spline36 Spline36 optimized Software Blend @@ -134,10 +134,10 @@ diff -Naur xbmc-11.0.1/language/English/strings.xml xbmc-11.0.1.patch/language/E Post-processing -diff -Naur xbmc-11.0.1/language/German/strings.xml xbmc-11.0.1.patch/language/German/strings.xml ---- xbmc-11.0.1/language/German/strings.xml 2012-03-21 23:57:54.000000000 +0100 -+++ xbmc-11.0.1.patch/language/German/strings.xml 2012-05-13 22:08:46.676187527 +0200 -@@ -1266,6 +1266,8 @@ +diff -Naur xbmc-pvr-11.0.1/language/German/strings.xml xbmc-pvr-11.0.1.patch/language/German/strings.xml +--- xbmc-pvr-11.0.1/language/German/strings.xml 2012-03-27 17:55:51.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/language/German/strings.xml 2012-05-14 14:15:12.059218956 +0200 +@@ -1268,6 +1268,8 @@ Hardwarebeschleunigung erlauben (OpenMax) Pixel Shaders Hardwarebeschleunigung erlauben (VideoToolbox) @@ -146,7 +146,7 @@ diff -Naur xbmc-11.0.1/language/German/strings.xml xbmc-11.0.1.patch/language/Ge A/V Sync Methode Audio Takt -@@ -1565,6 +1567,7 @@ +@@ -1567,6 +1569,7 @@ Zeitlich (Hälfte) Zeitlich/Räumlich (Hälfte) DXVA @@ -154,9 +154,9 @@ diff -Naur xbmc-11.0.1/language/German/strings.xml xbmc-11.0.1.patch/language/Ge Video Nachbearbeitung Deaktiviert -diff -Naur xbmc-11.0.1/language/Swedish/strings.xml xbmc-11.0.1.patch/language/Swedish/strings.xml ---- xbmc-11.0.1/language/Swedish/strings.xml 2012-03-21 23:57:54.000000000 +0100 -+++ xbmc-11.0.1.patch/language/Swedish/strings.xml 2012-05-13 22:08:46.663187269 +0200 +diff -Naur xbmc-pvr-11.0.1/language/Swedish/strings.xml xbmc-pvr-11.0.1.patch/language/Swedish/strings.xml +--- xbmc-pvr-11.0.1/language/Swedish/strings.xml 2012-03-27 17:55:51.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/language/Swedish/strings.xml 2012-05-14 14:15:12.062219016 +0200 @@ -1412,6 +1412,7 @@ Spline36 Spline36-optimerad @@ -165,819 +165,9 @@ diff -Naur xbmc-11.0.1/language/Swedish/strings.xml xbmc-11.0.1.patch/language/S Efterbearbetning Visa insommningstimeout Byt till kanal -diff -Naur xbmc-11.0.1/lib/ffmpeg/configure xbmc-11.0.1.patch/lib/ffmpeg/configure ---- xbmc-11.0.1/lib/ffmpeg/configure 2012-03-21 23:57:44.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/configure 2012-05-13 22:08:46.926192488 +0200 -@@ -111,6 +111,7 @@ - --disable-vaapi disable VAAPI code - --disable-vdpau disable VDPAU code - --disable-dxva2 disable DXVA2 code -+ --disable-xvba disable XVBA code - --enable-runtime-cpudetect detect cpu capabilities at runtime (bigger binary) - --enable-hardcoded-tables use hardcoded tables instead of runtime generation - --enable-memalign-hack emulate memalign, interferes with memory debuggers -@@ -932,6 +933,7 @@ - swscale_alpha - vaapi - vdpau -+ xvba - version3 - x11grab - zlib -@@ -1240,6 +1242,7 @@ - h264_dxva2_hwaccel_deps="dxva2api_h" - h264_dxva2_hwaccel_select="dxva2 h264_decoder" - h264_vaapi_hwaccel_select="vaapi" -+h264_xvba_hwaccel_select="xvba" - h264_vdpau_decoder_select="vdpau h264_decoder" - imc_decoder_select="fft mdct" - jpegls_decoder_select="golomb" -@@ -1263,6 +1266,7 @@ - mpeg2_dxva2_hwaccel_select="dxva2 mpeg2video_decoder" - mpeg2_vaapi_hwaccel_select="vaapi mpeg2video_decoder" - mpeg4_vaapi_hwaccel_select="vaapi mpeg4_decoder" -+mpeg2_xvba_hwaccel_select="xvba mpeg2video_decoder" - mpeg4_vdpau_decoder_deps="vdpau_vdpau_h vdpau_vdpau_x11_h vdpau_mpeg4_support" - mpeg4_vdpau_decoder_select="vdpau mpeg4_decoder" - mpeg_xvmc_decoder_deps="X11_extensions_XvMClib_h" -@@ -1306,6 +1310,7 @@ - vc1_dxva2_hwaccel_deps="dxva2api_h DXVA_PictureParameters_wDecodedPictureIndex" - vc1_dxva2_hwaccel_select="dxva2 vc1_decoder" - vc1_vaapi_hwaccel_select="vaapi vc1_decoder" -+vc1_xvba_hwaccel_select="xvba vc1_decoder" - vc1_vdpau_decoder_select="vdpau vc1_decoder" - vorbis_decoder_select="mdct" - vorbis_encoder_select="mdct" -@@ -1327,12 +1332,14 @@ - wmv3_dxva2_hwaccel_select="vc1_dxva2_hwaccel" - wmv3_vaapi_hwaccel_select="vc1_vaapi_hwaccel" - wmv3_vdpau_decoder_select="vc1_vdpau_decoder" -+wmv3_xvba_hwaccel_select="vc1_xvba_hwaccel" - zlib_decoder_select="zlib" - zlib_encoder_select="zlib" - zmbv_decoder_select="zlib" - zmbv_encoder_select="zlib" - - vaapi_deps="va_va_h" -+xvba_deps="amd_amdxvba_h" - vdpau_deps="vdpau_vdpau_h vdpau_vdpau_x11_h" - - # parsers -@@ -2762,6 +2769,7 @@ - check_header termios.h - check_header vdpau/vdpau.h - check_header vdpau/vdpau_x11.h -+check_header amd/amdxvba.h - check_cpp_condition vdpau/vdpau.h "defined(VDP_DECODER_PROFILE_MPEG4_PART2_SP)" && enable vdpau_mpeg4_support - - check_header X11/extensions/XvMClib.h -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/allcodecs.c 2012-03-21 23:57:47.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/allcodecs.c 2012-05-13 22:08:46.928192528 +0200 -@@ -57,13 +57,17 @@ - REGISTER_HWACCEL (H263_VAAPI, h263_vaapi); - REGISTER_HWACCEL (H264_DXVA2, h264_dxva2); - REGISTER_HWACCEL (H264_VAAPI, h264_vaapi); -+ REGISTER_HWACCEL (H264_XVBA, h264_xvba); - REGISTER_HWACCEL (MPEG2_DXVA2, mpeg2_dxva2); - REGISTER_HWACCEL (MPEG2_VAAPI, mpeg2_vaapi); - REGISTER_HWACCEL (MPEG4_VAAPI, mpeg4_vaapi); -+ REGISTER_HWACCEL (MPEG2_XVBA, mpeg2_xvba); - REGISTER_HWACCEL (VC1_DXVA2, vc1_dxva2); - REGISTER_HWACCEL (VC1_VAAPI, vc1_vaapi); -+ REGISTER_HWACCEL (VC1_XVBA, vc1_xvba); - REGISTER_HWACCEL (WMV3_DXVA2, wmv3_dxva2); - REGISTER_HWACCEL (WMV3_VAAPI, wmv3_vaapi); -+ REGISTER_HWACCEL (WMV3_XVBA, wmv3_xvba); - - /* video codecs */ - REGISTER_ENCODER (A64MULTI, a64multi); -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/h264.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/h264.c 2012-03-21 23:57:45.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/h264.c 2012-05-13 22:08:46.930192568 +0200 -@@ -55,6 +55,7 @@ - static const enum PixelFormat hwaccel_pixfmt_list_h264_jpeg_420[] = { - PIX_FMT_DXVA2_VLD, - PIX_FMT_VAAPI_VLD, -+ PIX_FMT_XVBA_VLD, - PIX_FMT_YUVJ420P, - PIX_FMT_NONE - }; -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/Makefile xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/Makefile 2012-03-21 23:57:45.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/Makefile 2012-05-13 22:08:46.927192508 +0200 -@@ -3,7 +3,7 @@ - NAME = avcodec - FFLIBS = avcore avutil - --HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vdpau.h xvmc.h -+HEADERS = avcodec.h avfft.h dxva2.h opt.h vaapi.h vdpau.h xvmc.h xvba.h - - OBJS = allcodecs.o \ - audioconvert.o \ -@@ -43,6 +43,7 @@ - OBJS-$(CONFIG_RDFT) += rdft.o $(RDFT-OBJS-yes) - OBJS-$(CONFIG_VAAPI) += vaapi.o - OBJS-$(CONFIG_VDPAU) += vdpau.o -+OBJS-$(CONFIG_XVBA) += xvba.o - - # decoders/encoders/hardware accelerators - OBJS-$(CONFIG_A64MULTI_ENCODER) += a64multienc.o elbg.o -@@ -169,6 +170,7 @@ - mpegvideo.o error_resilience.o - OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o - OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o -+OBJS-$(CONFIG_H264_XVBA_HWACCEL) += xvba_h264.o - OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o - OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o - OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o -@@ -246,6 +248,7 @@ - mpegvideo.o error_resilience.o - OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o - OBJS-$(CONFIG_MPEG2_VAAPI_HWACCEL) += vaapi_mpeg2.o -+OBJS-$(CONFIG_MPEG2_XVBA_HWACCEL) += xvba_mpeg2.o - OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12.o mpeg12data.o \ - mpegvideo.o error_resilience.o - OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpegvideo_enc.o \ -@@ -379,6 +382,7 @@ - intrax8.o intrax8dsp.o - OBJS-$(CONFIG_VC1_DXVA2_HWACCEL) += dxva2_vc1.o - OBJS-$(CONFIG_VC1_VAAPI_HWACCEL) += vaapi_vc1.o -+OBJS-$(CONFIG_VC1_XVBA_HWACCEL) += xvba_vc1.o - OBJS-$(CONFIG_VCR1_DECODER) += vcr1.o - OBJS-$(CONFIG_VCR1_ENCODER) += vcr1.o - OBJS-$(CONFIG_VMDAUDIO_DECODER) += vmdav.o -@@ -647,6 +651,7 @@ - SKIPHEADERS-$(CONFIG_LIBDIRAC) += libdirac.h - SKIPHEADERS-$(CONFIG_LIBSCHROEDINGER) += libschroedinger.h - SKIPHEADERS-$(CONFIG_VAAPI) += vaapi_internal.h -+SKIPHEADERS-$(CONFIG_XVBA) += xvba_internal.h - SKIPHEADERS-$(CONFIG_VDPAU) += vdpau.h - SKIPHEADERS-$(CONFIG_XVMC) += xvmc.h - SKIPHEADERS += mpegaudio3.h -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/mpegvideo.c 2012-03-21 23:57:45.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/mpegvideo.c 2012-05-13 22:08:46.933192627 +0200 -@@ -117,6 +117,7 @@ - const enum PixelFormat ff_hwaccel_pixfmt_list_420[] = { - PIX_FMT_DXVA2_VLD, - PIX_FMT_VAAPI_VLD, -+ PIX_FMT_XVBA_VLD, - PIX_FMT_YUV420P, - PIX_FMT_NONE - }; -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.c 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.c 2012-05-13 22:08:46.934192647 +0200 -@@ -0,0 +1,65 @@ -+/* -+ * HW decode acceleration for MPEG-2, H.264 and VC-1 -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+ -+/** -+ * \addtogroup XVBA_Decoding -+ * -+ * @{ -+ */ -+ -+#include -+#include "xvba.h" -+#include "avcodec.h" -+ -+int ff_xvba_translate_profile(int profile) { -+ -+ if (profile == 66) -+ return 1; -+ else if (profile == 77) -+ return 2; -+ else if (profile == 100) -+ return 3; -+ else if (profile == 0) -+ return 4; -+ else if (profile == 1) -+ return 5; -+ else if (profile == 3) -+ return 6; -+ else -+ return -1; -+} -+ -+void ff_xvba_add_slice_data(struct xvba_render_state *render, const void *buffer, uint32_t size) { -+ -+ render->buffers = av_fast_realloc( -+ render->buffers, -+ &render->buffers_alllocated, -+ sizeof(struct xvba_bitstream_buffers)*(render->num_slices + 1) -+ ); -+ -+ render->buffers[render->num_slices].buffer = buffer; -+ render->buffers[render->num_slices].size = size; -+ -+ render->num_slices++; -+} -+ -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.h ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba.h 2012-05-13 22:08:46.935192667 +0200 -@@ -0,0 +1,71 @@ -+/* -+ * HW decode acceleration for MPEG-2, H.264 and VC-1 -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+#ifndef AVCODEC_XVBA_H -+#define AVCODEC_XVBA_H -+ -+#include -+#include -+#include -+ -+ -+/** -+ * \defgroup XVBA_Decoding VA API Decoding -+ * \ingroup Decoder -+ * @{ -+ */ -+ -+/** \brief The videoSurface is used for rendering. */ -+#define FF_XVBA_STATE_USED_FOR_RENDER 1 -+ -+/** -+ * \brief The videoSurface is needed for reference/prediction. -+ * The codec manipulates this. -+ */ -+#define FF_XVBA_STATE_USED_FOR_REFERENCE 2 -+ -+/** -+ * \brief The videoSurface holds a decoded frame. -+ * The codec manipulates this. -+ */ -+#define FF_XVBA_STATE_DECODED 4 -+ -+/* @} */ -+ -+struct xvba_bitstream_buffers -+{ -+ const void *buffer; -+ unsigned int size; -+}; -+ -+struct xvba_render_state { -+ -+ int state; ///< Holds FF_XVBA_STATE_* values. -+ void *surface; -+ XVBAPictureDescriptor *picture_descriptor; -+ XVBAQuantMatrixAvc *iq_matrix; -+ int num_slices; -+ struct xvba_bitstream_buffers *buffers; -+ uint32_t buffers_alllocated; -+}; -+ -+#endif /* AVCODEC_XVBA_H */ -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_h264.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_h264.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_h264.c 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_h264.c 2012-05-13 22:08:46.936192687 +0200 -@@ -0,0 +1,180 @@ -+/* -+ * H.264 HW decode acceleration through XVBA -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+#include "xvba.h" -+#include "xvba_internal.h" -+#include "h264.h" -+#include -+ -+/** @file -+ * This file implements the glue code between FFmpeg's and XvBA API's -+ * structures for H.264 decoding. -+ */ -+ -+ -+/** Initialize and start decoding a frame with XVBA. */ -+static int start_frame(AVCodecContext *avctx, -+ av_unused const uint8_t *buffer, -+ av_unused uint32_t size) -+{ -+ H264Context * const h = avctx->priv_data; -+ MpegEncContext * const s = &h->s; -+ struct xvba_render_state *render; -+ XVBAPictureDescriptor *pic_descriptor; -+ int i; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ if (render->picture_descriptor == 0) -+ return -1; -+ -+ pic_descriptor = render->picture_descriptor; -+ -+ for (i = 0; i < 2; ++i) { -+ int foc = s->current_picture_ptr->field_poc[i]; -+ if (foc == INT_MAX) -+ foc = 0; -+ pic_descriptor->avc_curr_field_order_cnt_list[i] = foc; -+ } -+ -+ pic_descriptor->avc_frame_num = h->frame_num; -+ -+ render->num_slices = 0; -+ -+ return 0; -+} -+ -+/** End a hardware decoding based frame. */ -+static int end_frame(AVCodecContext *avctx) -+{ -+ H264Context * const h = avctx->priv_data; -+ MpegEncContext * const s = &h->s; -+ struct xvba_render_state *render; -+ XVBAPictureDescriptor *pic_descriptor; -+ XVBAQuantMatrixAvc *iq_matrix; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ if (render->picture_descriptor == 0 || render->iq_matrix == 0) -+ return -1; -+ -+ pic_descriptor = render->picture_descriptor; -+ iq_matrix = render->iq_matrix; -+ -+ av_dlog(avctx, "end_frame()\n"); -+ -+ /* Fill in Picture Parameters*/ -+ pic_descriptor->profile = ff_xvba_translate_profile(avctx->profile); -+ pic_descriptor->level = avctx->level; -+ pic_descriptor->width_in_mb = s->mb_width; -+ pic_descriptor->height_in_mb = s->mb_height; -+ pic_descriptor->picture_structure = s->picture_structure; -+ pic_descriptor->chroma_format = s->chroma_format ? s->chroma_format : 1; -+ pic_descriptor->avc_intra_flag = (h->slice_type == FF_I_TYPE) ? 1 : 0; -+ pic_descriptor->avc_reference = (s->current_picture_ptr->reference & 3) ? 1 : 0; -+ -+ pic_descriptor->avc_bit_depth_luma_minus8 = h->sps.bit_depth_luma - 8; -+ pic_descriptor->avc_bit_depth_chroma_minus8 = h->sps.bit_depth_chroma - 8; -+ pic_descriptor->avc_log2_max_frame_num_minus4 = h->sps.log2_max_frame_num -4; -+ pic_descriptor->avc_pic_order_cnt_type = h->sps.poc_type; -+ pic_descriptor->avc_log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4; -+ pic_descriptor->avc_num_ref_frames = h->sps.ref_frame_count; -+ pic_descriptor->avc_reserved_8bit = 0; -+ -+ pic_descriptor->avc_num_slice_groups_minus1 = h->pps.slice_group_count - 1; -+ pic_descriptor->avc_num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1; -+ pic_descriptor->avc_num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1; -+ -+ pic_descriptor->avc_pic_init_qp_minus26 = h->pps.init_qp - 26; -+ pic_descriptor->avc_pic_init_qs_minus26 = h->pps.init_qs - 26; -+ pic_descriptor->avc_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0]; -+ pic_descriptor->avc_second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1]; -+ pic_descriptor->avc_slice_group_change_rate_minus1 = 0; // not implemented in ffmpeg -+ pic_descriptor->avc_reserved_16bit = 0; // must be 0 -+ memset(pic_descriptor->avc_field_order_cnt_list,0,sizeof(pic_descriptor->avc_field_order_cnt_list)); // must be 0 -+ memset(pic_descriptor->avc_slice_group_map,0,sizeof(pic_descriptor->avc_slice_group_map)); // must be 0 -+ -+ // sps -+ pic_descriptor->sps_info.avc.delta_pic_always_zero_flag = h->sps.delta_pic_order_always_zero_flag; -+ pic_descriptor->sps_info.avc.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag; -+ pic_descriptor->sps_info.avc.frame_mbs_only_flag = h->sps.frame_mbs_only_flag; -+ pic_descriptor->sps_info.avc.gaps_in_frame_num_value_allowed_flag = h->sps.gaps_in_frame_num_allowed_flag; -+ pic_descriptor->sps_info.avc.mb_adaptive_frame_field_flag = h->sps.mb_aff; -+ pic_descriptor->sps_info.avc.residual_colour_transform_flag = h->sps.residual_color_transform_flag; -+ pic_descriptor->sps_info.avc.xvba_avc_sps_reserved = 0; -+ -+ // pps -+ pic_descriptor->pps_info.avc.entropy_coding_mode_flag = h->pps.cabac; -+ pic_descriptor->pps_info.avc.pic_order_present_flag = h->pps.pic_order_present; -+ pic_descriptor->pps_info.avc.weighted_pred_flag = h->pps.weighted_pred; -+ pic_descriptor->pps_info.avc.weighted_bipred_idc = h->pps.weighted_bipred_idc; -+ pic_descriptor->pps_info.avc.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; -+ pic_descriptor->pps_info.avc.constrained_intra_pred_flag = h->pps.constrained_intra_pred; -+ pic_descriptor->pps_info.avc.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present; -+ pic_descriptor->pps_info.avc.transform_8x8_mode_flag = h->pps.transform_8x8_mode; -+ pic_descriptor->pps_info.avc.xvba_avc_pps_reserved = 0; // must be 0 -+ -+ memcpy(iq_matrix->bScalingLists4x4, h->pps.scaling_matrix4, sizeof(iq_matrix->bScalingLists4x4)); -+ memcpy(iq_matrix->bScalingLists8x8, h->pps.scaling_matrix8, sizeof(iq_matrix->bScalingLists8x8)); -+ -+ // Wait for an I-frame before start decoding. Workaround for ATI UVD and UVD+ GPUs -+ if (!h->got_first_iframe) { -+ if (h->slice_type != FF_I_TYPE && h->slice_type != FF_SI_TYPE) -+ return -1; -+ h->got_first_iframe = 1; -+ } -+ -+ ff_draw_horiz_band(s, 0, s->avctx->height); -+ -+ return 0; -+} -+ -+/** Decode the given H.264 slice with VA API. */ -+static int decode_slice(AVCodecContext *avctx, -+ const uint8_t *buffer, -+ uint32_t size) -+{ -+ H264Context * const h = avctx->priv_data; -+ MpegEncContext * const s = &h->s; -+ struct xvba_render_state *render; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ ff_xvba_add_slice_data(render, buffer, size); -+ -+ return 0; -+} -+ -+AVHWAccel ff_h264_xvba_hwaccel = { -+ .name = "h264_xvba", -+ .type = AVMEDIA_TYPE_VIDEO, -+ .id = CODEC_ID_H264, -+ .pix_fmt = PIX_FMT_XVBA_VLD, -+ .capabilities = 0, -+ .start_frame = start_frame, -+ .end_frame = end_frame, -+ .decode_slice = decode_slice, -+ .priv_data_size = 0, -+}; -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_internal.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_internal.h ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_internal.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_internal.h 2012-05-13 22:08:46.936192687 +0200 -@@ -0,0 +1,24 @@ -+/* -+ * HW decode acceleration for MPEG-2, H.264 and VC-1 -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+int ff_xvba_translate_profile(int profile); -+void ff_xvba_add_slice_data(struct xvba_render_state *render, const uint8_t *buffer, uint32_t size); -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_mpeg2.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_mpeg2.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_mpeg2.c 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_mpeg2.c 2012-05-13 22:08:46.937192706 +0200 -@@ -0,0 +1,52 @@ -+/* -+ * MPEG-2 HW decode acceleration through XVBA -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+#include "dsputil.h" -+ -+static int start_frame(AVCodecContext *avctx, av_unused const uint8_t *buffer, av_unused uint32_t size) -+{ -+ struct MpegEncContext * const s = avctx->priv_data; -+ return 0; -+} -+ -+static int end_frame(AVCodecContext *avctx) -+{ -+ return 0; -+} -+ -+static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) -+{ -+ struct MpegEncContext * const s = avctx->priv_data; -+ return 0; -+} -+ -+AVHWAccel ff_mpeg2_xvba_hwaccel = { -+ .name = "mpeg2_xvba", -+ .type = AVMEDIA_TYPE_VIDEO, -+ .id = CODEC_ID_MPEG2VIDEO, -+ .pix_fmt = PIX_FMT_XVBA_VLD, -+ .capabilities = 0, -+ .start_frame = start_frame, -+ .end_frame = end_frame, -+ .decode_slice = decode_slice, -+ .priv_data_size = 0, -+}; -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_vc1.c xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_vc1.c ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvba_vc1.c 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvba_vc1.c 2012-05-13 22:08:46.937192706 +0200 -@@ -0,0 +1,194 @@ -+/* -+ * VC-1 HW decode acceleration through XVBA -+ * -+ * Copyright (C) 2005-2011 Team XBMC -+ * -+ * This file is part of FFmpeg. -+ * -+ * FFmpeg is free software; you can redistribute it and/or -+ * modify it under the terms of the GNU Lesser General Public -+ * License as published by the Free Software Foundation; either -+ * version 2.1 of the License, or (at your option) any later version. -+ * -+ * FFmpeg 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 -+ * Lesser General Public License for more details. -+ * -+ * You should have received a copy of the GNU Lesser General Public -+ * License along with FFmpeg; if not, write to the Free Software -+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -+ */ -+ -+#include "xvba.h" -+#include "xvba_internal.h" -+#include "vc1.h" -+#include "vc1data.h" -+#include -+ -+ -+/** @file -+ * Implement structures of ffmpeg <-> XvBA -+ */ -+ -+/* Initialize and start decoding a frame with XvBA */ -+static int start_frame(AVCodecContext *avctx, -+ av_unused const uint8_t *buffer, -+ av_unused uint32_t size) -+{ -+ VC1Context * const v = avctx->priv_data; -+ MpegEncContext * const s = &v->s; -+ struct xvba_render_state *render; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ render->num_slices = 0; -+ return 0; -+} -+ -+/* End a hardware decoding based frame */ -+static int end_frame(AVCodecContext *avctx) -+{ -+ VC1Context* const v = avctx->priv_data; -+ MpegEncContext* const s = &v->s; -+ struct xvba_render_state *render, *last, *next; -+ XVBAPictureDescriptor *pic_descriptor; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ if (render->picture_descriptor == 0) -+ return -1; -+ -+ pic_descriptor = render->picture_descriptor; -+ -+ av_dlog(avctx, "xvba_vc1_end_frame()\n"); -+ -+ memset(pic_descriptor, 0, sizeof(*pic_descriptor)); -+ -+ /* Fill in Parameters - for reference see AMD sdk documentation */ -+ pic_descriptor->profile = ff_xvba_translate_profile(v->profile); -+ pic_descriptor->level = v->level; -+ //done like in va-driver and vaapi -+ if (v->profile == PROFILE_ADVANCED) { -+ pic_descriptor->width_in_mb = s->avctx->coded_width; -+ pic_descriptor->height_in_mb = s->avctx->coded_height; -+ } else { -+ pic_descriptor->width_in_mb = s->mb_width; -+ pic_descriptor->height_in_mb = s->mb_height; -+ } -+ pic_descriptor->picture_structure = s->picture_structure; -+ // xvba-video set this to 1 only 4:2:0 supported -+ // doc says: if not set, choose 1 - we try this -+ pic_descriptor->chroma_format = 1; -+ pic_descriptor->avc_intra_flag = s->pict_type == FF_I_TYPE || v->bi_type == 1; -+ pic_descriptor->avc_reference = (s->current_picture_ptr->reference & 3) ? 1 : 0; -+ -+ // VC-1 explicit parameters see page 30 of sdk -+ // sps_info -+ pic_descriptor->sps_info.vc1.postprocflag = v->postprocflag; -+ -+ // done as in vaapi -+ pic_descriptor->sps_info.vc1.pulldown = v->broadcast; -+ pic_descriptor->sps_info.vc1.interlace = v->interlace; -+ pic_descriptor->sps_info.vc1.tfcntrflag = v->tfcntrflag; -+ pic_descriptor->sps_info.vc1.finterpflag = v->finterpflag; -+ pic_descriptor->sps_info.vc1.reserved = 1; -+ // eventually check if this makes sense together with interlace -+ pic_descriptor->sps_info.vc1.psf = v->psf; -+ // what about if it is a frame (page 31) -+ // looked at xvba-driver -+ pic_descriptor->sps_info.vc1.second_field = !s->first_field; -+ pic_descriptor->sps_info.vc1.xvba_vc1_sps_reserved = 0; -+ -+ // VC-1 explicit parameters see page 30 of sdk -+ // pps_info -+ pic_descriptor->pps_info.vc1.panscan_flag = v->panscanflag; -+ pic_descriptor->pps_info.vc1.refdist_flag = v->refdist_flag; -+ pic_descriptor->pps_info.vc1.loopfilter = s->loop_filter; -+ pic_descriptor->pps_info.vc1.fastuvmc = v->fastuvmc; -+ pic_descriptor->pps_info.vc1.extended_mv = v->extended_mv; -+ pic_descriptor->pps_info.vc1.dquant = v->dquant; -+ pic_descriptor->pps_info.vc1.vstransform = v->vstransform; -+ pic_descriptor->pps_info.vc1.overlap = v->overlap; -+ pic_descriptor->pps_info.vc1.quantizer = v->quantizer_mode; -+ pic_descriptor->pps_info.vc1.extended_dmv = v->extended_dmv; -+ pic_descriptor->pps_info.vc1.maxbframes = s->avctx->max_b_frames; -+ pic_descriptor->pps_info.vc1.rangered = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : v->rangered; -+ pic_descriptor->pps_info.vc1.syncmarker = (pic_descriptor->profile == PROFILE_SIMPLE) ? 0 : s->resync_marker; -+ pic_descriptor->pps_info.vc1.multires = v->multires; -+ pic_descriptor->pps_info.vc1.reserved = 1; -+ pic_descriptor->pps_info.vc1.range_mapy_flag = v->range_mapy_flag; -+ pic_descriptor->pps_info.vc1.range_mapy = v->range_mapy; -+ pic_descriptor->pps_info.vc1.range_mapuv_flag = v->range_mapuv_flag; -+ pic_descriptor->pps_info.vc1.range_mapuv = v->range_mapuv; -+ pic_descriptor->pps_info.vc1.xvba_vc1_pps_reserved = 0; -+ -+ pic_descriptor->past_surface = 0; -+ pic_descriptor->future_surface = 0; -+ switch (s->pict_type) { -+ case FF_B_TYPE: -+ next = (struct xvba_render_state *)s->next_picture.data[0]; -+ assert(next); -+ if (next) -+ pic_descriptor->past_surface = next->surface; -+ // fall-through -+ case FF_P_TYPE: -+ last = (struct xvba_render_state *)s->last_picture.data[0]; -+ assert(last); -+ if (last) -+ pic_descriptor->future_surface = last->surface; -+ break; -+ } -+ -+ ff_draw_horiz_band(s, 0, s->avctx->height); -+ -+ return 0; -+} -+ -+static int decode_slice(AVCodecContext *avctx, const uint8_t *buffer, uint32_t size) -+{ -+ VC1Context* const v = avctx->priv_data; -+ MpegEncContext* const s = &v->s; -+ struct xvba_render_state *render; -+ -+ render = (struct xvba_render_state *)s->current_picture_ptr->data[0]; -+ assert(render); -+ -+ if (avctx->codec_id == CODEC_ID_VC1 && -+ size >= 4 && IS_MARKER(AV_RB32(buffer))) { -+ buffer += 4; -+ size -= 4; -+ } -+ -+ ff_xvba_add_slice_data(render, buffer, size); -+ -+ return 0; -+} -+ -+#if CONFIG_WMV3_XVBA_HWACCEL -+AVHWAccel ff_wmv3_xvba_hwaccel = { -+ .name = "wmv3_xvba", -+ .type = AVMEDIA_TYPE_VIDEO, -+ .id = CODEC_ID_WMV3, -+ .pix_fmt = PIX_FMT_XVBA_VLD, -+ .capabilities = 0, -+ .start_frame = start_frame, -+ .end_frame = end_frame, -+ .decode_slice = decode_slice, -+ .priv_data_size = 0, -+}; -+#endif -+ -+AVHWAccel ff_vc1_xvba_hwaccel = { -+ .name = "vc1_xvba", -+ .type = AVMEDIA_TYPE_VIDEO, -+ .id = CODEC_ID_VC1, -+ .pix_fmt = PIX_FMT_XVBA_VLD, -+ .capabilities = 0, -+ .start_frame = start_frame, -+ .end_frame = end_frame, -+ .decode_slice = decode_slice, -+ .priv_data_size = 0, -+}; -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h ---- xbmc-11.0.1/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-03-21 23:57:47.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavcodec/xvmc_internal.h 2012-05-13 22:08:46.938192726 +0200 -@@ -1,5 +1,7 @@ - /* -- * XVideo Motion Compensation internal functions -+ * HW decode acceleration for MPEG-2, H.264 and VC-1 -+ * -+ * Copyright (C) 2005-2011 Team XBMC - * - * This file is part of FFmpeg. - * -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavutil/pixdesc.c xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.c ---- xbmc-11.0.1/lib/ffmpeg/libavutil/pixdesc.c 2012-03-21 23:57:44.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixdesc.c 2012-05-13 22:08:46.939192746 +0200 -@@ -717,6 +717,12 @@ - .log2_chroma_h = 1, - .flags = PIX_FMT_HWACCEL, - }, -+ [PIX_FMT_XVBA_VLD] = { -+ .name = "xvba_vld", -+ .log2_chroma_w = 1, -+ .log2_chroma_h = 1, -+ .flags = PIX_FMT_HWACCEL, -+ }, - [PIX_FMT_YUV420P16LE] = { - .name = "yuv420p16le", - .nb_components= 3, -diff -Naur xbmc-11.0.1/lib/ffmpeg/libavutil/pixfmt.h xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h ---- xbmc-11.0.1/lib/ffmpeg/libavutil/pixfmt.h 2012-03-21 23:57:44.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/ffmpeg/libavutil/pixfmt.h 2012-05-13 22:08:46.939192746 +0200 -@@ -127,6 +127,7 @@ - PIX_FMT_YUV444P16BE, ///< planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian - PIX_FMT_VDPAU_MPEG4, ///< MPEG4 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers - PIX_FMT_DXVA2_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer -+ PIX_FMT_XVBA_VLD, ///< HW decoding through DXVA2, Picture.data[3] contains a vaapi_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers - - PIX_FMT_RGB444BE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), big-endian, most significant bits to 0 - PIX_FMT_RGB444LE, ///< packed RGB 4:4:4, 16bpp, (msb)4A 4R 4G 4B(lsb), little-endian, most significant bits to 0 -diff -Naur xbmc-11.0.1/lib/UnrarXLib/extract.cpp xbmc-11.0.1.patch/lib/UnrarXLib/extract.cpp ---- xbmc-11.0.1/lib/UnrarXLib/extract.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/UnrarXLib/extract.cpp 2012-05-13 22:08:46.773189450 +0200 +diff -Naur xbmc-pvr-11.0.1/lib/UnrarXLib/extract.cpp xbmc-pvr-11.0.1.patch/lib/UnrarXLib/extract.cpp +--- xbmc-pvr-11.0.1/lib/UnrarXLib/extract.cpp 2012-03-27 17:55:39.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/UnrarXLib/extract.cpp 2012-05-14 14:15:12.095219681 +0200 @@ -1,9 +1,5 @@ #include "rar.hpp" #include "Util.h" @@ -988,9 +178,9 @@ diff -Naur xbmc-11.0.1/lib/UnrarXLib/extract.cpp xbmc-11.0.1.patch/lib/UnrarXLib // a cautious wrapper around strncpy char *strncpy_null_terminated(char *dest, const char *src, size_t n) -diff -Naur xbmc-11.0.1/lib/UnrarXLib/unpack15.cpp xbmc-11.0.1.patch/lib/UnrarXLib/unpack15.cpp ---- xbmc-11.0.1/lib/UnrarXLib/unpack15.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/UnrarXLib/unpack15.cpp 2012-05-13 22:08:46.774189470 +0200 +diff -Naur xbmc-pvr-11.0.1/lib/UnrarXLib/unpack15.cpp xbmc-pvr-11.0.1.patch/lib/UnrarXLib/unpack15.cpp +--- xbmc-pvr-11.0.1/lib/UnrarXLib/unpack15.cpp 2012-03-27 17:55:39.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/UnrarXLib/unpack15.cpp 2012-05-14 14:15:12.095219681 +0200 @@ -1,7 +1,3 @@ -#ifdef _LINUX -#include "XSyncUtils.h" @@ -999,9 +189,9 @@ diff -Naur xbmc-11.0.1/lib/UnrarXLib/unpack15.cpp xbmc-11.0.1.patch/lib/UnrarXLi #define STARTL1 2 static unsigned int DecL1[]={0x8000,0xa000,0xc000,0xd000,0xe000,0xea00, 0xee00,0xf000,0xf200,0xf200,0xffff}; -diff -Naur xbmc-11.0.1/lib/UnrarXLib/unpack.cpp xbmc-11.0.1.patch/lib/UnrarXLib/unpack.cpp ---- xbmc-11.0.1/lib/UnrarXLib/unpack.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/lib/UnrarXLib/unpack.cpp 2012-05-13 22:08:46.774189470 +0200 +diff -Naur xbmc-pvr-11.0.1/lib/UnrarXLib/unpack.cpp xbmc-pvr-11.0.1.patch/lib/UnrarXLib/unpack.cpp +--- xbmc-pvr-11.0.1/lib/UnrarXLib/unpack.cpp 2012-03-27 17:55:39.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/lib/UnrarXLib/unpack.cpp 2012-05-14 14:15:12.096219701 +0200 @@ -8,11 +8,6 @@ #include "unpack20.cpp" #endif @@ -1014,9 +204,9 @@ diff -Naur xbmc-11.0.1/lib/UnrarXLib/unpack.cpp xbmc-11.0.1.patch/lib/UnrarXLib/ Unpack::Unpack(ComprDataIO *DataIO) { UnpIO=DataIO; -diff -Naur xbmc-11.0.1/system/shaders/yuv2rgb_basic.glsl xbmc-11.0.1.patch/system/shaders/yuv2rgb_basic.glsl ---- xbmc-11.0.1/system/shaders/yuv2rgb_basic.glsl 2012-03-21 23:57:58.000000000 +0100 -+++ xbmc-11.0.1.patch/system/shaders/yuv2rgb_basic.glsl 2012-05-13 22:01:28.506492824 +0200 +diff -Naur xbmc-pvr-11.0.1/system/shaders/yuv2rgb_basic.glsl xbmc-pvr-11.0.1.patch/system/shaders/yuv2rgb_basic.glsl +--- xbmc-pvr-11.0.1/system/shaders/yuv2rgb_basic.glsl 2012-03-27 17:55:54.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/system/shaders/yuv2rgb_basic.glsl 2012-05-14 14:15:12.097219721 +0200 @@ -70,6 +70,18 @@ rgb.a = gl_Color.a; gl_FragColor = rgb; @@ -1036,10 +226,10 @@ diff -Naur xbmc-11.0.1/system/shaders/yuv2rgb_basic.glsl xbmc-11.0.1.patch/syste #elif defined(XBMC_YUY2) || defined(XBMC_UYVY) #if(XBMC_texture_rectangle) -diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.cpp ---- xbmc-11.0.1/xbmc/Application.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/Application.cpp 2012-05-13 22:08:46.751189015 +0200 -@@ -369,8 +369,6 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/Application.cpp xbmc-pvr-11.0.1.patch/xbmc/Application.cpp +--- xbmc-pvr-11.0.1/xbmc/Application.cpp 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/Application.cpp 2012-05-14 14:15:12.101219801 +0200 +@@ -391,8 +391,6 @@ #endif m_currentStack = new CFileItemList; @@ -1048,7 +238,7 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c m_bPresentFrame = false; m_bPlatformDirectories = true; -@@ -1965,28 +1963,18 @@ +@@ -2026,28 +2024,18 @@ bool CApplication::WaitFrame(unsigned int timeout) { @@ -1082,7 +272,7 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c } void CApplication::Render() -@@ -2020,12 +2008,13 @@ +@@ -2081,12 +2069,13 @@ m_bPresentFrame = false; if (!extPlayerActive && g_graphicsContext.IsFullScreenVideo() && !IsPaused()) { @@ -1101,7 +291,7 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c decrement = m_bPresentFrame; hasRendered = true; } -@@ -2108,18 +2097,14 @@ +@@ -2169,18 +2158,14 @@ m_lastFrameTime = XbmcThreads::SystemClockMillis(); if (flip) @@ -1123,7 +313,7 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c } void CApplication::SetStandAlone(bool value) -@@ -5303,12 +5288,6 @@ +@@ -5399,12 +5384,6 @@ // See if we're playing a video, and are in GUI mode if ( IsPlayingVideo() && g_windowManager.GetActiveWindow() != WINDOW_FULLSCREEN_VIDEO) { @@ -1136,7 +326,7 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c // then switch to fullscreen mode g_windowManager.ActivateWindow(WINDOW_FULLSCREEN_VIDEO); return true; -@@ -5479,7 +5458,6 @@ +@@ -5580,7 +5559,6 @@ bool CApplication::IsPresentFrame() { @@ -1144,10 +334,10 @@ diff -Naur xbmc-11.0.1/xbmc/Application.cpp xbmc-11.0.1.patch/xbmc/Application.c bool ret = m_bPresentFrame; return ret; -diff -Naur xbmc-11.0.1/xbmc/Application.h xbmc-11.0.1.patch/xbmc/Application.h ---- xbmc-11.0.1/xbmc/Application.h 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/Application.h 2012-05-13 22:08:46.752189035 +0200 -@@ -343,9 +343,7 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/Application.h xbmc-pvr-11.0.1.patch/xbmc/Application.h +--- xbmc-pvr-11.0.1/xbmc/Application.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/Application.h 2012-05-14 14:15:12.102219821 +0200 +@@ -351,9 +351,7 @@ bool m_bTestMode; bool m_bSystemScreenSaverEnable; @@ -1158,10 +348,10 @@ diff -Naur xbmc-11.0.1/xbmc/Application.h xbmc-11.0.1.patch/xbmc/Application.h void Mute(); void UnMute(); -diff -Naur xbmc-11.0.1/xbmc/ApplicationMessenger.cpp xbmc-11.0.1.patch/xbmc/ApplicationMessenger.cpp ---- xbmc-11.0.1/xbmc/ApplicationMessenger.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/ApplicationMessenger.cpp 2012-05-13 22:08:46.776189511 +0200 -@@ -73,7 +73,7 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/ApplicationMessenger.cpp xbmc-pvr-11.0.1.patch/xbmc/ApplicationMessenger.cpp +--- xbmc-pvr-11.0.1/xbmc/ApplicationMessenger.cpp 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/ApplicationMessenger.cpp 2012-05-14 14:15:12.106219903 +0200 +@@ -75,7 +75,7 @@ using namespace std; @@ -1170,9 +360,9 @@ diff -Naur xbmc-11.0.1/xbmc/ApplicationMessenger.cpp xbmc-11.0.1.patch/xbmc/Appl { m_msg.dwMessage = msg.dwMessage; m_msg.dwParam1 = msg.dwParam1; -diff -Naur xbmc-11.0.1/xbmc/cdrip/CDDAReader.cpp xbmc-11.0.1.patch/xbmc/cdrip/CDDAReader.cpp ---- xbmc-11.0.1/xbmc/cdrip/CDDAReader.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cdrip/CDDAReader.cpp 2012-05-13 22:08:46.776189511 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cdrip/CDDAReader.cpp xbmc-pvr-11.0.1.patch/xbmc/cdrip/CDDAReader.cpp +--- xbmc-pvr-11.0.1/xbmc/cdrip/CDDAReader.cpp 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cdrip/CDDAReader.cpp 2012-05-14 14:15:12.106219903 +0200 @@ -29,7 +29,7 @@ #define SECTOR_COUNT 52 @@ -1182,9 +372,9 @@ diff -Naur xbmc-11.0.1/xbmc/cdrip/CDDAReader.cpp xbmc-11.0.1.patch/xbmc/cdrip/CD { m_sRipBuffer[0].pbtStream = NULL; m_sRipBuffer[1].pbtStream = NULL; -diff -Naur xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.cpp xbmc-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.cpp ---- xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.cpp 2012-05-13 22:08:46.777189531 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.cpp 2012-05-14 14:15:12.107219923 +0200 @@ -240,15 +240,6 @@ #endif } @@ -1201,9 +391,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.cpp xbmc-11.0.1 extern "C" int WINAPI dllDuplicateHandle(HANDLE hSourceProcessHandle, // handle to source process HANDLE hSourceHandle, // handle to duplicate HANDLE hTargetProcessHandle, // handle to target process -diff -Naur xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.h xbmc-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.h ---- xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.h 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.h 2012-05-13 22:08:46.778189551 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.h xbmc-pvr-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.h +--- xbmc-pvr-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/DllLoader/exports/emu_kernel32.h 2012-05-14 14:15:12.108219943 +0200 @@ -686,7 +686,6 @@ extern "C" HGLOBAL WINAPI dllLoadResource(HMODULE module, HRSRC res); @@ -1212,9 +402,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/DllLoader/exports/emu_kernel32.h xbmc-11.0.1.p extern "C" int WINAPI dllGetLocaleInfoA(LCID Locale, LCTYPE LCType, LPTSTR lpLCData, int cchData); extern "C" UINT WINAPI dllGetConsoleCP(); extern "C" UINT WINAPI dllGetConsoleOutputCP(); -diff -Naur xbmc-11.0.1/xbmc/cores/DummyVideoPlayer.cpp xbmc-11.0.1.patch/xbmc/cores/DummyVideoPlayer.cpp ---- xbmc-11.0.1/xbmc/cores/DummyVideoPlayer.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/DummyVideoPlayer.cpp 2012-05-13 22:08:46.778189551 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/DummyVideoPlayer.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/DummyVideoPlayer.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/DummyVideoPlayer.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/DummyVideoPlayer.cpp 2012-05-14 14:15:12.109219963 +0200 @@ -33,7 +33,7 @@ CDummyVideoPlayer::CDummyVideoPlayer(IPlayerCallback& callback) @@ -1224,9 +414,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/DummyVideoPlayer.cpp xbmc-11.0.1.patch/xbmc/co { m_paused = false; m_clock = 0; -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp 2012-05-13 22:08:46.780189591 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp 2012-05-14 14:15:12.111220003 +0200 @@ -325,7 +325,7 @@ #pragma mark - #endif @@ -1236,9 +426,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/CrystalHD.cpp xbmc-1 m_dll(dll), m_device(device), m_has_bcm70015(has_bcm70015), -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-05-13 22:08:46.978193519 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-05-14 14:11:52.781931376 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.cpp 2012-05-14 14:32:47.792343580 +0200 @@ -56,6 +56,9 @@ #ifdef HAVE_LIBVA #include "VAAPI.h" @@ -1287,7 +477,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. #ifdef HAVE_LIBVA // mpeg4 vaapi decoding is disabled if(*cur == PIX_FMT_VAAPI_VLD && g_guiSettings.GetBool("videoplayer.usevaapi") -@@ -142,6 +158,7 @@ +@@ -141,6 +157,7 @@ m_iLastKeyframe = 0; m_dts = DVD_NOPTS_VALUE; m_started = false; @@ -1295,12 +485,13 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. } CDVDVideoCodecFFmpeg::~CDVDVideoCodecFFmpeg() -@@ -195,13 +212,25 @@ +@@ -198,14 +215,26 @@ continue; CLog::Log(LOGNOTICE,"CDVDVideoCodecFFmpeg::Open() Creating VDPAU(%ix%i, %d)",hints.width, hints.height, hints.codec); - CVDPAU* vdp = new CVDPAU(); + VDPAU::CDecoder* vdp = new VDPAU::CDecoder(); + m_pCodecContext = m_dllAvCodec.avcodec_alloc_context3(pCodec); m_pCodecContext->codec_id = hints.codec; m_pCodecContext->width = hints.width; m_pCodecContext->height = hints.height; @@ -1323,7 +514,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. { m_pHardware = vdp; m_pCodecContext->codec_id = CODEC_ID_NONE; // ffmpeg will complain if this has been set -@@ -338,6 +367,14 @@ +@@ -333,6 +362,14 @@ { if( m_pCodecContext ) { @@ -1338,7 +529,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. // i don't know exactly how high this should be set // couldn't find any good docs on it. think it varies // from codec to codec on what it does -@@ -558,6 +595,7 @@ +@@ -515,6 +552,7 @@ void CDVDVideoCodecFFmpeg::Reset() { m_started = false; @@ -1346,7 +537,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. m_iLastKeyframe = m_pCodecContext->has_b_frames; m_dllAvCodec.avcodec_flush_buffers(m_pCodecContext); -@@ -663,6 +701,22 @@ +@@ -608,6 +646,22 @@ else pDvdVideoPicture->pts = DVD_NOPTS_VALUE; @@ -1369,7 +560,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. if(!m_started) pDvdVideoPicture->iFlags |= DVP_FLAG_DROPPED; -@@ -883,3 +937,14 @@ +@@ -827,3 +881,14 @@ else return 0; } @@ -1384,9 +575,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. +{ + m_codecControlState = state; +} -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-05-13 22:08:46.989193738 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-05-14 14:11:52.782931396 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg.h 2012-05-14 14:30:28.105682654 +0200 @@ -29,7 +29,6 @@ #include "DllSwScale.h" #include "DllAvFilter.h" @@ -1414,7 +605,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. bool IsHardwareAllowed() { return !m_bSoftware; } IHardwareDecoder * GetHardware() { return m_pHardware; }; -@@ -109,4 +113,8 @@ +@@ -118,5 +122,9 @@ int m_iLastKeyframe; double m_dts; bool m_started; @@ -1422,10 +613,11 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodecFFmpeg. + int m_skippedDeint; + bool m_requestSkipDeint; + int m_codecControlState; + std::vector m_formats; }; -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h 2012-05-13 22:08:46.989193738 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h 2012-05-14 14:15:12.117220123 +0200 @@ -34,7 +34,8 @@ namespace DXVA { class CSurfaceContext; } @@ -1515,9 +707,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/DVDVideoCodec.h xbmc + + virtual void SetCodecControl(int state) {} }; -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in 2012-05-13 22:08:46.950192964 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in 2012-05-14 14:15:12.118220144 +0200 @@ -17,6 +17,10 @@ DVDVideoCodecCrystalHD.cpp \ @@ -1529,9 +721,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/Makefile.in xbmc-11. ifeq (@USE_VDA@,1) SRCS+= DVDVideoCodecVDA.cpp \ -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-13 22:08:47.058195107 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 14:14:51.682808251 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp 2012-05-14 14:15:12.128220346 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2009 Team XBMC @@ -2831,7 +2023,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. avctx->coded_width, avctx->coded_height, &render->surface); -@@ -1216,15 +798,16 @@ +@@ -1214,15 +796,16 @@ return 0; } @@ -2851,7 +2043,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. render=(vdpau_render_state*)pic->data[0]; if(!render) -@@ -1233,6 +816,8 @@ +@@ -1231,6 +814,8 @@ return; } @@ -2860,7 +2052,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. for(i=0; i<4; i++) pic->data[i]= NULL; -@@ -1247,21 +832,18 @@ +@@ -1245,21 +830,18 @@ } @@ -2887,7 +2079,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. if(src->linesize[0] || src->linesize[1] || src->linesize[2] || offset[0] || offset[1] || offset[2]) -@@ -1291,59 +873,41 @@ +@@ -1289,59 +871,41 @@ if(s->pix_fmt == PIX_FMT_VDPAU_H264) max_refs = render->info.h264.num_ref_frames; @@ -2962,7 +2154,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. if(pFrame) { // we have a new frame from decoder -@@ -1351,7 +915,10 @@ +@@ -1349,7 +913,10 @@ if(!render) // old style ffmpeg gave data on plane 0 render = (vdpau_render_state*)pFrame->data[0]; if(!render) @@ -2973,7 +2165,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. // ffmpeg vc-1 decoder does not flush, make sure the data buffer is still valid if (!IsSurfaceValid(render)) -@@ -1360,256 +927,175 @@ +@@ -1358,256 +925,175 @@ return VC_BUFFER; } @@ -3352,7 +2544,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. if(m_DisplayState == VDPAU_OPEN) { -@@ -1627,4 +1113,2432 @@ +@@ -1625,4 +1111,2432 @@ return false; } @@ -5785,9 +4977,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.cpp xbmc-11.0. + + #endif -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h 2012-05-13 22:08:47.038194709 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h 2012-05-14 14:15:12.131220406 +0200 @@ -1,4 +1,3 @@ - #pragma once @@ -6519,9 +5711,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/VDPAU.h xbmc-11.0.1. + +} + -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp 2012-05-13 22:08:47.063195207 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp 2012-05-14 14:15:12.135220486 +0200 @@ -0,0 +1,2382 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -8905,9 +8097,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.cpp xbmc-11.0.1 +} + +#endif -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h 2012-05-13 22:08:47.053195007 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h 2012-05-14 14:15:12.137220527 +0200 @@ -0,0 +1,386 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -9295,9 +8487,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDCodecs/Video/XVBA.h xbmc-11.0.1.p +}; + +} -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-05-13 22:08:46.782189631 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-05-14 14:11:52.793931617 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp 2012-05-14 14:35:25.789526441 +0200 @@ -19,7 +19,6 @@ * */ @@ -9306,7 +8498,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- #include "system.h" #ifndef __STDC_CONSTANT_MACROS #define __STDC_CONSTANT_MACROS -@@ -43,6 +42,7 @@ +@@ -44,6 +43,7 @@ #include "filesystem/Directory.h" #include "utils/log.h" #include "threads/Thread.h" @@ -9314,7 +8506,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- #include "utils/TimeUtils.h" void CDemuxStreamAudioFFmpeg::GetStreamInfo(std::string& strInfo) -@@ -153,16 +153,12 @@ +@@ -154,16 +154,12 @@ ++it; } @@ -9326,7 +8518,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- -#endif +static XbmcThreads::ThreadLocal g_demuxer; - static int interrupt_cb(void) + static int interrupt_cb(void* unused) { - if(g_demuxer && g_demuxer->Aborted()) + CDVDDemuxFFmpeg* demuxer = g_demuxer.get(); @@ -9334,16 +8526,16 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- return 1; return 0; } -@@ -234,7 +230,7 @@ +@@ -235,7 +231,7 @@ std::string strFile; m_iCurrentPts = DVD_NOPTS_VALUE; m_speed = DVD_PLAYSPEED_NORMAL; - g_demuxer = this; + g_demuxer.set(this); m_program = UINT_MAX; + const AVIOInterruptCB int_cb = { interrupt_cb, NULL }; - if (!pInput) return false; -@@ -506,7 +502,7 @@ +@@ -499,7 +495,7 @@ void CDVDDemuxFFmpeg::Dispose() { @@ -9352,7 +8544,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- if (m_pFormatContext) { -@@ -555,7 +551,7 @@ +@@ -540,7 +536,7 @@ void CDVDDemuxFFmpeg::Flush() { @@ -9361,7 +8553,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- // naughty usage of an internal ffmpeg function if (m_pFormatContext) -@@ -571,7 +567,7 @@ +@@ -556,7 +552,7 @@ void CDVDDemuxFFmpeg::SetSpeed(int iSpeed) { @@ -9370,7 +8562,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- if(!m_pFormatContext) return; -@@ -633,7 +629,7 @@ +@@ -618,7 +614,7 @@ DemuxPacket* CDVDDemuxFFmpeg::Read() { @@ -9379,7 +8571,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- AVPacket pkt; DemuxPacket* pPacket = NULL; -@@ -832,7 +828,7 @@ +@@ -810,7 +806,7 @@ bool CDVDDemuxFFmpeg::SeekTime(int time, bool backwords, double *startpts) { @@ -9388,7 +8580,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- if(time < 0) time = 0; -@@ -892,7 +888,7 @@ +@@ -870,7 +866,7 @@ bool CDVDDemuxFFmpeg::SeekByte(__int64 pos) { @@ -9397,9 +8589,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDDemuxers/DVDDemuxFFmpeg.cpp xbmc- CSingleLock lock(m_critSection); int ret = m_dllAvFormat.av_seek_frame(m_pFormatContext, -1, pos, AVSEEK_FLAG_BYTE); -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp 2012-05-13 22:08:46.782189631 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp 2012-05-14 14:15:12.140220588 +0200 @@ -21,6 +21,7 @@ #include "DVDPerformanceCounter.h" @@ -9434,9 +8626,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.cpp xbmc-11.0. __int64 threadTime = (p->timer_thread.QuadPart - old_time_thread.QuadPart); __int64 systemTime = (p->timer_system.QuadPart - old_time_system.QuadPart); -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.h 2012-05-13 22:08:46.783189651 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPerformanceCounter.h 2012-05-14 14:15:12.141220608 +0200 @@ -24,7 +24,7 @@ #define FILETIME_TO_ULARGE_INTEGER(ularge, filetime) { ularge.u.HighPart = filetime.dwHighDateTime; ularge.u.LowPart = filetime.dwLowDateTime; } @@ -9486,9 +8678,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPerformanceCounter.h xbmc-11.0.1. CDVDMessageQueue* m_pAudioQueue; CDVDMessageQueue* m_pVideoQueue; -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp 2012-05-13 22:08:46.786189710 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp 2012-05-14 14:15:12.142220628 +0200 @@ -518,7 +518,7 @@ m_decode.msg = NULL; m_decode.Release(); @@ -9498,10 +8690,10 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerAudio.cpp xbmc-11.0.1.patch #ifdef _WIN32 CoInitializeEx(NULL, COINIT_MULTITHREADED); -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayer.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayer.cpp 2012-05-13 22:08:46.897191913 +0200 -@@ -341,7 +341,7 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayer.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayer.cpp 2012-05-14 14:15:12.145220688 +0200 +@@ -348,7 +348,7 @@ // if playing a file close it first // this has to be changed so we won't have to close it. @@ -9510,7 +8702,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc CloseFile(); m_bAbortRequest = false; -@@ -358,7 +358,7 @@ +@@ -366,7 +366,7 @@ m_ready.Reset(); #if defined(HAS_VIDEO_PLAYBACK) @@ -9519,7 +8711,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc #endif Create(); -@@ -432,9 +432,8 @@ +@@ -440,9 +440,8 @@ m_messenger.Init(); @@ -9530,7 +8722,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc } bool CDVDPlayer::OpenInputStream() -@@ -1457,7 +1456,7 @@ +@@ -1585,7 +1584,7 @@ } else if (m_CurrentVideo.id >= 0 @@ -9539,7 +8731,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc && m_SpeedState.lastpts != m_dvdPlayerVideo.GetCurrentPts() && m_SpeedState.lasttime != GetTime()) { -@@ -2127,6 +2126,11 @@ +@@ -2262,6 +2261,11 @@ if (speed != DVD_PLAYSPEED_PAUSE && m_playSpeed != DVD_PLAYSPEED_PAUSE && speed != m_playSpeed) m_callback.OnPlayBackSpeedChanged(speed / DVD_PLAYSPEED_NORMAL); @@ -9551,15 +8743,15 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc // if playspeed is different then DVD_PLAYSPEED_NORMAL or DVD_PLAYSPEED_PAUSE // audioplayer, stops outputing audio to audiorendere, but still tries to // sleep an correct amount for each packet -@@ -2143,6 +2147,7 @@ +@@ -2278,6 +2282,7 @@ // until our buffers are somewhat filled if(m_pDemuxer) m_pDemuxer->SetSpeed(speed); + } - else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_NEXT) || - pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_PREV) || -@@ -2716,7 +2721,7 @@ + else if (pMsg->IsType(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) && m_messenger.GetPacketCount(CDVDMsg::PLAYER_CHANNEL_SELECT_NUMBER) == 0) + { +@@ -2897,7 +2902,7 @@ m_dvdPlayerAudio.SendMessage(new CDVDMsg(CDVDMsg::PLAYER_STARTED), 1); /* audio normally won't consume full cpu, so let it have prio */ @@ -9568,7 +8760,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc return true; } -@@ -2781,11 +2786,11 @@ +@@ -2962,11 +2967,11 @@ // the CoreAudio audio device handler thread. We do the same for // the DVDPlayerVideo thread so it can run to sleep without getting // swapped out by a busy OS. @@ -9582,9 +8774,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayer.cpp xbmc-11.0.1.patch/xbmc #endif return true; -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-05-13 22:08:47.040194749 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-05-14 14:11:52.795931658 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp 2012-05-14 14:38:53.481710398 +0200 @@ -189,7 +189,7 @@ return false; } @@ -9622,23 +8814,16 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch while (!m_bStop) { -@@ -414,18 +417,24 @@ - if(m_pVideoCodec) - m_pVideoCodec->Reset(); +@@ -416,6 +419,8 @@ + picture.iFlags &= ~DVP_FLAG_ALLOCATED; m_packets.clear(); -+ picture.iFlags &= ~DVP_FLAG_ALLOCATED; m_started = false; + m_droppingStats.Reset(); + g_renderManager.EnableBuffering(false); } else if (pMsg->IsType(CDVDMsg::GENERAL_FLUSH)) // private message sent by (CDVDPlayerVideo::Flush()) { - if(m_pVideoCodec) - m_pVideoCodec->Reset(); - m_packets.clear(); -+ picture.iFlags &= ~DVP_FLAG_ALLOCATED; - - m_pullupCorrection.Flush(); +@@ -428,6 +433,8 @@ //we need to recalculate the framerate //TODO: this needs to be set on a streamchange instead ResetFrameRateCalc(); @@ -9647,7 +8832,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch m_stalled = true; m_started = false; -@@ -443,6 +452,10 @@ +@@ -445,6 +452,10 @@ m_speed = static_cast(pMsg)->m_value; if(m_speed == DVD_PLAYSPEED_PAUSE) m_iNrOfPicturesNotToSkip = 0; @@ -9658,7 +8843,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch } else if (pMsg->IsType(CDVDMsg::PLAYER_STARTED)) { -@@ -477,6 +490,29 @@ +@@ -479,6 +490,29 @@ m_iNrOfPicturesNotToSkip = 1; } @@ -9688,7 +8873,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch #ifdef PROFILE bRequestDrop = false; #else -@@ -486,6 +522,7 @@ +@@ -488,6 +522,7 @@ bRequestDrop = false; m_iDroppedRequest = 0; m_iLateFrames = 0; @@ -9696,7 +8881,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch } #endif -@@ -524,7 +561,7 @@ +@@ -526,7 +561,7 @@ if(m_pVideoCodec->GetConvergeCount() > 0) { m_packets.push_back(DVDMessageListItem(pMsg, 0)); @@ -9705,7 +8890,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch || m_packets.size() * frametime > DVD_SEC_TO_TIME(10)) m_packets.pop_front(); } -@@ -534,11 +571,13 @@ +@@ -536,11 +571,13 @@ // picture from a demux packet, this should be reasonable // for libavformat as a demuxer as it normally packetizes // pictures when they come from demuxer @@ -9724,7 +8909,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch // loop while no error while (!m_bStop) -@@ -561,6 +600,8 @@ +@@ -563,6 +600,8 @@ m_pVideoCodec->Reset(); m_packets.clear(); @@ -9733,7 +8918,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch break; } -@@ -670,11 +711,15 @@ +@@ -672,11 +711,15 @@ CDVDCodecUtils::FreePicture(pTempYUVPackedPicture); #endif @@ -9749,7 +8934,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch } // guess next frame pts. iDuration is always valid -@@ -1037,6 +1082,10 @@ +@@ -1039,6 +1082,10 @@ flags |= CONF_FLAGS_FORMAT_VDPAU; formatstr = "VDPAU"; break; @@ -9760,7 +8945,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch case DVDVideoPicture::FMT_DXVA: flags |= CONF_FLAGS_FORMAT_DXVA; formatstr = "DXVA"; -@@ -1052,6 +1101,10 @@ +@@ -1054,6 +1101,10 @@ flags |= CONF_FLAGS_FORMAT_CVBREF; formatstr = "BGRA"; break; @@ -9771,7 +8956,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch } if(m_bAllowFullscreen) -@@ -1160,50 +1213,63 @@ +@@ -1162,50 +1213,63 @@ m_FlipTimeStamp += max(0.0, iSleepTime); m_FlipTimeStamp += iFrameDuration; @@ -9871,7 +9056,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch { // calculate frame dropping pattern to render at this speed // we do that by deciding if this or next frame is closest -@@ -1239,6 +1305,16 @@ +@@ -1241,6 +1305,16 @@ mDisplayField = FS_BOT; } @@ -9888,7 +9073,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch ProcessOverlays(pPicture, pts); AutoCrop(pPicture); -@@ -1255,7 +1331,7 @@ +@@ -1257,7 +1331,7 @@ if (index < 0) return EOS_DROPPED; @@ -9897,7 +9082,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch return result; #else -@@ -1269,7 +1345,8 @@ +@@ -1271,7 +1345,8 @@ if ((pPicture->format == DVDVideoPicture::FMT_YUV420P) || (pPicture->format == DVDVideoPicture::FMT_NV12) || (pPicture->format == DVDVideoPicture::FMT_YUY2) || @@ -9907,7 +9092,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch { RECT crop; -@@ -1498,7 +1575,7 @@ +@@ -1500,7 +1575,7 @@ double frameduration = m_pullupCorrection.GetFrameDuration(); if (frameduration == DVD_NOPTS_VALUE || @@ -9916,7 +9101,7 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch { //reset the stored framerates if no good framerate was detected m_fStableFrameRate = 0.0; -@@ -1554,3 +1631,142 @@ +@@ -1556,3 +1631,142 @@ m_iFrameRateCount = 0; } } @@ -10059,9 +9244,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.cpp xbmc-11.0.1.patch + m_gain.push_back(gain); + m_totalGain += frametime; +} -diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.h xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.h ---- xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.h 2012-05-13 22:08:47.047194890 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.h xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.h +--- xbmc-pvr-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/dvdplayer/DVDPlayerVideo.h 2012-05-14 14:15:12.150220789 +0200 @@ -38,6 +38,26 @@ #define VIDEO_PICTURE_QUEUE_SIZE 1 @@ -10117,9 +9302,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/dvdplayer/DVDPlayerVideo.h xbmc-11.0.1.patch/x + CDroppingStats m_droppingStats; }; -diff -Naur xbmc-11.0.1/xbmc/cores/paplayer/PAPlayer.cpp xbmc-11.0.1.patch/xbmc/cores/paplayer/PAPlayer.cpp ---- xbmc-11.0.1/xbmc/cores/paplayer/PAPlayer.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/paplayer/PAPlayer.cpp 2012-05-13 22:08:46.787189730 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/paplayer/PAPlayer.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/paplayer/PAPlayer.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/paplayer/PAPlayer.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/paplayer/PAPlayer.cpp 2012-05-14 14:15:12.151220809 +0200 @@ -52,7 +52,7 @@ // Supporting all open audio codec standards. // First one being nullsoft's nsv audio decoder format @@ -10138,9 +9323,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/paplayer/PAPlayer.cpp xbmc-11.0.1.patch/xbmc/c Create(); m_startEvent.Set(); -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp 2012-05-13 22:08:47.060195147 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp 2012-05-14 14:15:12.155220890 +0200 @@ -61,6 +61,9 @@ VA_MICRO_VERSION == 0 && VA_SDS_VERSION < 5))) @@ -10798,9 +9983,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.cpp xbmc-11.0.1 +#endif + #endif -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.h xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.h ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.h 2012-05-13 22:08:46.947192904 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.h xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.h +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/LinuxRendererGL.h 2012-05-14 14:15:12.156220910 +0200 @@ -35,13 +35,14 @@ class CRenderCapture; @@ -10897,9 +10082,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/LinuxRendererGL.h xbmc-11.0.1.p }; typedef YUVBUFFER YUVBUFFERS[NUM_BUFFERS]; -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.cpp xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.cpp ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.cpp 2012-03-21 23:57:35.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.cpp 2012-05-13 22:08:46.744188878 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.cpp 2012-05-14 14:15:12.157220930 +0200 @@ -89,7 +89,7 @@ CRenderer::CRenderer() { @@ -10948,9 +10133,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.cpp xbmc-11.0.1 } void CRenderer::Render() -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.h xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.h ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.h 2012-05-13 22:08:46.745188897 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.h xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.h +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/OverlayRenderer.h 2012-05-14 14:15:12.157220930 +0200 @@ -99,6 +99,9 @@ void Flip(); void Render(); @@ -10971,9 +10156,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/OverlayRenderer.h xbmc-11.0.1.p int m_decode; int m_render; -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderFlags.h xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderFlags.h ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderFlags.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderFlags.h 2012-05-13 22:08:46.948192924 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderFlags.h xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderFlags.h +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderFlags.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderFlags.h 2012-05-14 14:15:12.158220950 +0200 @@ -76,8 +76,10 @@ #define CONF_FLAGS_FORMAT_YUY2 0x008000 #define CONF_FLAGS_FORMAT_DXVA 0x010000 @@ -10985,9 +10170,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderFlags.h xbmc-11.0.1.patch #define CONF_FLAGS_FORMAT_BYPASS 0x100000 +#define CONF_FLAGS_FORMAT_XVBA 0x200000 #endif -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.cpp xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.cpp ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.cpp 2012-05-13 22:08:47.061195167 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderManager.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderManager.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.cpp 2012-05-14 14:15:12.160220990 +0200 @@ -26,6 +26,7 @@ #include "utils/MathUtils.h" #include "threads/SingleLock.h" @@ -11480,9 +10665,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.cpp xbmc-11.0.1.p + else + return true; +} -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.h xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.h ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.h 2012-05-13 22:08:47.016194272 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderManager.h xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.h +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/RenderManager.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/RenderManager.h 2012-05-14 14:15:12.161221010 +0200 @@ -39,10 +39,11 @@ #include "OverlayRenderer.h" @@ -11591,9 +10776,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/RenderManager.h xbmc-11.0.1.pat OVERLAY::CRenderer m_overlays; -diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp ---- xbmc-11.0.1/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp 2012-05-13 22:01:28.569494075 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp +--- xbmc-pvr-11.0.1/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp 2012-05-14 14:15:12.162221031 +0200 @@ -186,6 +186,8 @@ m_defines += "#define XBMC_YUY2\n"; else if (CONF_FLAGS_FORMAT_MASK(flags) == CONF_FLAGS_FORMAT_UYVY) @@ -11603,9 +10788,9 @@ diff -Naur xbmc-11.0.1/xbmc/cores/VideoRenderers/VideoShaders/YUV2RGBShader.cpp VertexShader()->LoadSource("yuv2rgb_vertex.glsl", m_defines); #elif HAS_GLES == 2 -diff -Naur xbmc-11.0.1/xbmc/dialogs/GUIDialogCache.cpp xbmc-11.0.1.patch/xbmc/dialogs/GUIDialogCache.cpp ---- xbmc-11.0.1/xbmc/dialogs/GUIDialogCache.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/dialogs/GUIDialogCache.cpp 2012-05-13 22:08:46.789189770 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/dialogs/GUIDialogCache.cpp xbmc-pvr-11.0.1.patch/xbmc/dialogs/GUIDialogCache.cpp +--- xbmc-pvr-11.0.1/xbmc/dialogs/GUIDialogCache.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/dialogs/GUIDialogCache.cpp 2012-05-14 14:15:12.163221052 +0200 @@ -29,7 +29,7 @@ #include "threads/SingleLock.h" #include "utils/TimeUtils.h" @@ -11615,9 +10800,9 @@ diff -Naur xbmc-11.0.1/xbmc/dialogs/GUIDialogCache.cpp xbmc-11.0.1.patch/xbmc/di { m_pDlg = (CGUIDialogProgress*)g_windowManager.GetWindow(WINDOW_DIALOG_PROGRESS); -diff -Naur xbmc-11.0.1/xbmc/filesystem/FileCache.cpp xbmc-11.0.1.patch/xbmc/filesystem/FileCache.cpp ---- xbmc-11.0.1/xbmc/filesystem/FileCache.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/FileCache.cpp 2012-05-13 22:08:46.789189770 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/FileCache.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/FileCache.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/FileCache.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/FileCache.cpp 2012-05-14 14:15:12.163221052 +0200 @@ -79,7 +79,7 @@ }; @@ -11636,9 +10821,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/FileCache.cpp xbmc-11.0.1.patch/xbmc/file { m_pCache = pCache; m_bDeleteCache = bDeleteCache; -diff -Naur xbmc-11.0.1/xbmc/filesystem/FilePipe.cpp xbmc-11.0.1.patch/xbmc/filesystem/FilePipe.cpp ---- xbmc-11.0.1/xbmc/filesystem/FilePipe.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/FilePipe.cpp 2012-05-13 22:08:46.790189789 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/FilePipe.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/FilePipe.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/FilePipe.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/FilePipe.cpp 2012-05-14 14:15:12.164221072 +0200 @@ -24,6 +24,8 @@ #include "PipesManager.h" #include "utils/StringUtils.h" @@ -11648,9 +10833,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/FilePipe.cpp xbmc-11.0.1.patch/xbmc/files using namespace XFILE; CFilePipe::CFilePipe() : m_pos(0), m_length(-1), m_pipe(NULL) -diff -Naur xbmc-11.0.1/xbmc/filesystem/FileRar.cpp xbmc-11.0.1.patch/xbmc/filesystem/FileRar.cpp ---- xbmc-11.0.1/xbmc/filesystem/FileRar.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/FileRar.cpp 2012-05-13 22:08:46.790189789 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/FileRar.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/FileRar.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/FileRar.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/FileRar.cpp 2012-05-14 14:15:12.165221092 +0200 @@ -43,7 +43,7 @@ #define SEEKTIMOUT 30000 @@ -11660,9 +10845,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/FileRar.cpp xbmc-11.0.1.patch/xbmc/filesy { m_pArc = NULL; m_pCmd = NULL; -diff -Naur xbmc-11.0.1/xbmc/filesystem/HTSPDirectory.cpp xbmc-11.0.1.patch/xbmc/filesystem/HTSPDirectory.cpp ---- xbmc-11.0.1/xbmc/filesystem/HTSPDirectory.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/HTSPDirectory.cpp 2012-05-13 22:08:46.791189809 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/HTSPDirectory.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/HTSPDirectory.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/HTSPDirectory.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/HTSPDirectory.cpp 2012-05-14 14:15:12.166221112 +0200 @@ -76,7 +76,7 @@ static CCriticalSection g_section; @@ -11672,9 +10857,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/HTSPDirectory.cpp xbmc-11.0.1.patch/xbmc/ { } -diff -Naur xbmc-11.0.1/xbmc/filesystem/LastFMDirectory.cpp xbmc-11.0.1.patch/xbmc/filesystem/LastFMDirectory.cpp ---- xbmc-11.0.1/xbmc/filesystem/LastFMDirectory.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/LastFMDirectory.cpp 2012-05-13 22:08:46.792189829 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/LastFMDirectory.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/LastFMDirectory.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/LastFMDirectory.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/LastFMDirectory.cpp 2012-05-14 14:15:12.167221132 +0200 @@ -69,7 +69,7 @@ m_dlgProgress->Progress(); } @@ -11684,9 +10869,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/LastFMDirectory.cpp xbmc-11.0.1.patch/xbm m_strSource = url; m_strDestination = "special://temp/lastfm.xml"; thread.Create(); -diff -Naur xbmc-11.0.1/xbmc/filesystem/MythSession.cpp xbmc-11.0.1.patch/xbmc/filesystem/MythSession.cpp ---- xbmc-11.0.1/xbmc/filesystem/MythSession.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/MythSession.cpp 2012-05-13 22:08:46.792189829 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/MythSession.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/MythSession.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/MythSession.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/MythSession.cpp 2012-05-14 14:15:12.168221152 +0200 @@ -359,7 +359,7 @@ return; } @@ -11696,9 +10881,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/MythSession.cpp xbmc-11.0.1.patch/xbmc/fi { m_control = NULL; m_event = NULL; -diff -Naur xbmc-11.0.1/xbmc/filesystem/PipesManager.cpp xbmc-11.0.1.patch/xbmc/filesystem/PipesManager.cpp ---- xbmc-11.0.1/xbmc/filesystem/PipesManager.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/PipesManager.cpp 2012-05-13 22:08:46.793189848 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/PipesManager.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/PipesManager.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/PipesManager.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/PipesManager.cpp 2012-05-14 14:15:12.169221172 +0200 @@ -23,6 +23,8 @@ #include "threads/SingleLock.h" #include "Application.h" @@ -11708,9 +10893,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/PipesManager.cpp xbmc-11.0.1.patch/xbmc/f #ifndef min #define min(a,b) ((a) < (b) ? (a) : (b)) #endif -diff -Naur xbmc-11.0.1/xbmc/filesystem/RarManager.h xbmc-11.0.1.patch/xbmc/filesystem/RarManager.h ---- xbmc-11.0.1/xbmc/filesystem/RarManager.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/RarManager.h 2012-05-13 22:08:46.793189848 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/RarManager.h xbmc-pvr-11.0.1.patch/xbmc/filesystem/RarManager.h +--- xbmc-pvr-11.0.1/xbmc/filesystem/RarManager.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/RarManager.h 2012-05-14 14:15:12.169221172 +0200 @@ -71,7 +71,7 @@ CRarManager(); ~CRarManager(); @@ -11720,9 +10905,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/RarManager.h xbmc-11.0.1.patch/xbmc/files const CStdString& strDir =RAR_DEFAULT_CACHE, const int64_t iSize=-1); bool GetPathInCache(CStdString& strPathInCache, const CStdString& strRarPath, const CStdString& strPathInRar = ""); -diff -Naur xbmc-11.0.1/xbmc/filesystem/SAPDirectory.cpp xbmc-11.0.1.patch/xbmc/filesystem/SAPDirectory.cpp ---- xbmc-11.0.1/xbmc/filesystem/SAPDirectory.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/filesystem/SAPDirectory.cpp 2012-05-13 22:08:46.794189867 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/filesystem/SAPDirectory.cpp xbmc-pvr-11.0.1.patch/xbmc/filesystem/SAPDirectory.cpp +--- xbmc-pvr-11.0.1/xbmc/filesystem/SAPDirectory.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/filesystem/SAPDirectory.cpp 2012-05-14 14:15:12.170221192 +0200 @@ -272,7 +272,7 @@ using namespace SDP; @@ -11741,9 +10926,9 @@ diff -Naur xbmc-11.0.1/xbmc/filesystem/SAPDirectory.cpp xbmc-11.0.1.patch/xbmc/f g_sapsessions.Create(); // check if we can find this session in our cache -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp ---- xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp 2012-05-13 22:08:46.796189907 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp 2012-05-14 14:15:12.171221212 +0200 @@ -181,9 +181,9 @@ m_threadState = state; } @@ -11756,9 +10941,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.cpp xbm m_actionEvent.Reset(); } -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h ---- xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h 2012-05-13 22:08:46.796189907 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h 2012-05-14 14:15:12.171221212 +0200 @@ -51,7 +51,7 @@ virtual bool OnAction(const CAction &action); virtual bool OnBack(int actionID); @@ -11768,9 +10953,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindow.h xbmc- void PulseActionEvent(); void SetDestroyAfterDeinit(bool destroy = true); protected: -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp ---- xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp 2012-05-13 22:08:46.797189927 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp 2012-05-14 14:15:12.172221232 +0200 @@ -279,9 +279,9 @@ UpdateButtons(); } @@ -11783,9 +10968,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.cpp m_actionEvent.Reset(); } -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h ---- xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h 2012-05-13 22:08:46.798189947 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h 2012-05-14 14:15:12.173221252 +0200 @@ -40,7 +40,7 @@ virtual void AllocResources(bool forceLoad = false); virtual void FreeResources(bool forceUnLoad = false); @@ -11795,9 +10980,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/GUIPythonWindowXML.h xb void PulseActionEvent(); void AddItem(CFileItemPtr fileItem,int itemPosition); void RemoveItem(int itemPosition); -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/window.cpp xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/window.cpp ---- xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/window.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/window.cpp 2012-05-13 22:08:46.798189947 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/window.cpp xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/window.cpp +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/xbmcmodule/window.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/xbmcmodule/window.cpp 2012-05-14 14:15:12.174221272 +0200 @@ -540,11 +540,11 @@ CPyThreadState pyState; @@ -11813,9 +10998,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/xbmcmodule/window.cpp xbmc-11.0.1. } } Py_INCREF(Py_None); -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/XBPython.cpp xbmc-11.0.1.patch/xbmc/interfaces/python/XBPython.cpp ---- xbmc-11.0.1/xbmc/interfaces/python/XBPython.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/XBPython.cpp 2012-05-13 22:08:46.795189887 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/XBPython.cpp xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/XBPython.cpp +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/XBPython.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/XBPython.cpp 2012-05-14 14:15:12.175221293 +0200 @@ -676,11 +676,11 @@ m_globalEvent.Set(); } @@ -11830,9 +11015,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/XBPython.cpp xbmc-11.0.1.patch/xbm m_globalEvent.Reset(); } -diff -Naur xbmc-11.0.1/xbmc/interfaces/python/XBPython.h xbmc-11.0.1.patch/xbmc/interfaces/python/XBPython.h ---- xbmc-11.0.1/xbmc/interfaces/python/XBPython.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/interfaces/python/XBPython.h 2012-05-13 22:08:46.795189887 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/interfaces/python/XBPython.h xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/XBPython.h +--- xbmc-pvr-11.0.1/xbmc/interfaces/python/XBPython.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/interfaces/python/XBPython.h 2012-05-14 14:15:12.176221314 +0200 @@ -61,7 +61,7 @@ void Process(); @@ -11842,9 +11027,9 @@ diff -Naur xbmc-11.0.1/xbmc/interfaces/python/XBPython.h xbmc-11.0.1.patch/xbmc/ int ScriptsSize(); int GetPythonScriptId(int scriptPosition); -diff -Naur xbmc-11.0.1/xbmc/linux/Makefile.in xbmc-11.0.1.patch/xbmc/linux/Makefile.in ---- xbmc-11.0.1/xbmc/linux/Makefile.in 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/Makefile.in 2012-05-13 22:08:46.799189967 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/Makefile.in xbmc-pvr-11.0.1.patch/xbmc/linux/Makefile.in +--- xbmc-pvr-11.0.1/xbmc/linux/Makefile.in 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/Makefile.in 2012-05-14 14:15:12.176221314 +0200 @@ -10,14 +10,11 @@ LinuxResourceCounter.cpp \ LinuxTimezone.cpp \ @@ -11860,9 +11045,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/Makefile.in xbmc-11.0.1.patch/xbmc/linux/Makef LIB=linux.a -diff -Naur xbmc-11.0.1/xbmc/linux/PlatformDefs.h xbmc-11.0.1.patch/xbmc/linux/PlatformDefs.h ---- xbmc-11.0.1/xbmc/linux/PlatformDefs.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/PlatformDefs.h 2012-05-13 22:08:46.800189987 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/PlatformDefs.h xbmc-pvr-11.0.1.patch/xbmc/linux/PlatformDefs.h +--- xbmc-pvr-11.0.1/xbmc/linux/PlatformDefs.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/PlatformDefs.h 2012-05-14 14:15:12.177221334 +0200 @@ -182,8 +182,6 @@ #define EXCEPTION_EXECUTE_HANDLER ... //NOTE: dont try to define __except because it breaks g++ (already uses it). @@ -11872,9 +11057,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/PlatformDefs.h xbmc-11.0.1.patch/xbmc/linux/Pl struct CXHandle; // forward declaration typedef CXHandle* HANDLE; -diff -Naur xbmc-11.0.1/xbmc/linux/PlatformInclude.h xbmc-11.0.1.patch/xbmc/linux/PlatformInclude.h ---- xbmc-11.0.1/xbmc/linux/PlatformInclude.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/PlatformInclude.h 2012-05-13 22:08:46.800189987 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/PlatformInclude.h xbmc-pvr-11.0.1.patch/xbmc/linux/PlatformInclude.h +--- xbmc-pvr-11.0.1/xbmc/linux/PlatformInclude.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/PlatformInclude.h 2012-05-14 14:15:12.178221354 +0200 @@ -25,10 +25,7 @@ #include "PlatformDefs.h" #include "XHandlePublic.h" @@ -11886,9 +11071,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/PlatformInclude.h xbmc-11.0.1.patch/xbmc/linux #include "XMemUtils.h" #include "ConvUtils.h" -diff -Naur xbmc-11.0.1/xbmc/linux/XEventUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XEventUtils.cpp ---- xbmc-11.0.1/xbmc/linux/XEventUtils.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XEventUtils.cpp 1970-01-01 01:00:00.000000000 +0100 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XEventUtils.cpp xbmc-pvr-11.0.1.patch/xbmc/linux/XEventUtils.cpp +--- xbmc-pvr-11.0.1/xbmc/linux/XEventUtils.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XEventUtils.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,144 +0,0 @@ -/* - * Copyright (C) 2005-2008 Team XBMC @@ -12034,9 +11219,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XEventUtils.cpp xbmc-11.0.1.patch/xbmc/linux/X - return true; -} - -diff -Naur xbmc-11.0.1/xbmc/linux/XEventUtils.h xbmc-11.0.1.patch/xbmc/linux/XEventUtils.h ---- xbmc-11.0.1/xbmc/linux/XEventUtils.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XEventUtils.h 1970-01-01 01:00:00.000000000 +0100 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XEventUtils.h xbmc-pvr-11.0.1.patch/xbmc/linux/XEventUtils.h +--- xbmc-pvr-11.0.1/xbmc/linux/XEventUtils.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XEventUtils.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,38 +0,0 @@ -#ifndef __X_EVENT_UTIL_H__ -#define __X_EVENT_UTIL_H__ @@ -12076,9 +11261,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XEventUtils.h xbmc-11.0.1.patch/xbmc/linux/XEv - -#endif - -diff -Naur xbmc-11.0.1/xbmc/linux/XHandle.cpp xbmc-11.0.1.patch/xbmc/linux/XHandle.cpp ---- xbmc-11.0.1/xbmc/linux/XHandle.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XHandle.cpp 2012-05-13 22:08:46.805190085 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XHandle.cpp xbmc-pvr-11.0.1.patch/xbmc/linux/XHandle.cpp +--- xbmc-pvr-11.0.1/xbmc/linux/XHandle.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XHandle.cpp 2012-05-14 14:15:12.185221494 +0200 @@ -20,12 +20,15 @@ */ @@ -12140,9 +11325,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XHandle.cpp xbmc-11.0.1.patch/xbmc/linux/XHand m_bManualEvent=FALSE; m_bEventSet=FALSE; m_nFindFileIterator=0 ; -diff -Naur xbmc-11.0.1/xbmc/linux/XHandle.h xbmc-11.0.1.patch/xbmc/linux/XHandle.h ---- xbmc-11.0.1/xbmc/linux/XHandle.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XHandle.h 2012-05-13 22:08:46.805190085 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XHandle.h xbmc-pvr-11.0.1.patch/xbmc/linux/XHandle.h +--- xbmc-pvr-11.0.1/xbmc/linux/XHandle.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XHandle.h 2012-05-14 14:15:12.186221514 +0200 @@ -25,7 +25,6 @@ #ifndef _WIN32 @@ -12177,9 +11362,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XHandle.h xbmc-11.0.1.patch/xbmc/linux/XHandle int fd; bool m_bManualEvent; time_t m_tmCreation; -diff -Naur xbmc-11.0.1/xbmc/linux/XMemUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XMemUtils.cpp ---- xbmc-11.0.1/xbmc/linux/XMemUtils.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XMemUtils.cpp 2012-05-13 22:08:46.806190105 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XMemUtils.cpp xbmc-pvr-11.0.1.patch/xbmc/linux/XMemUtils.cpp +--- xbmc-pvr-11.0.1/xbmc/linux/XMemUtils.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XMemUtils.cpp 2012-05-14 14:15:12.187221534 +0200 @@ -25,6 +25,10 @@ #include "XMemUtils.h" @@ -12322,9 +11507,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XMemUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XMe + +#endif -diff -Naur xbmc-11.0.1/xbmc/linux/XMemUtils.h xbmc-11.0.1.patch/xbmc/linux/XMemUtils.h ---- xbmc-11.0.1/xbmc/linux/XMemUtils.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XMemUtils.h 2012-05-13 22:08:46.806190105 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XMemUtils.h xbmc-pvr-11.0.1.patch/xbmc/linux/XMemUtils.h +--- xbmc-pvr-11.0.1/xbmc/linux/XMemUtils.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XMemUtils.h 2012-05-14 14:15:12.187221534 +0200 @@ -22,10 +22,14 @@ * */ @@ -12340,9 +11525,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XMemUtils.h xbmc-11.0.1.patch/xbmc/linux/XMemU + #endif -diff -Naur xbmc-11.0.1/xbmc/linux/XSyncUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XSyncUtils.cpp ---- xbmc-11.0.1/xbmc/linux/XSyncUtils.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XSyncUtils.cpp 1970-01-01 01:00:00.000000000 +0100 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XSyncUtils.cpp xbmc-pvr-11.0.1.patch/xbmc/linux/XSyncUtils.cpp +--- xbmc-pvr-11.0.1/xbmc/linux/XSyncUtils.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XSyncUtils.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2005-2008 Team XBMC @@ -12513,9 +11698,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XSyncUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XS -} - -#endif -diff -Naur xbmc-11.0.1/xbmc/linux/XSyncUtils.h xbmc-11.0.1.patch/xbmc/linux/XSyncUtils.h ---- xbmc-11.0.1/xbmc/linux/XSyncUtils.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XSyncUtils.h 1970-01-01 01:00:00.000000000 +0100 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XSyncUtils.h xbmc-pvr-11.0.1.patch/xbmc/linux/XSyncUtils.h +--- xbmc-pvr-11.0.1/xbmc/linux/XSyncUtils.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XSyncUtils.h 1970-01-01 01:00:00.000000000 +0100 @@ -1,44 +0,0 @@ -#ifndef __X_SYNC_UTILS_ -#define __X_SYNC_UTILS_ @@ -12561,9 +11746,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XSyncUtils.h xbmc-11.0.1.patch/xbmc/linux/XSyn - -#endif - -diff -Naur xbmc-11.0.1/xbmc/linux/XThreadUtils.cpp xbmc-11.0.1.patch/xbmc/linux/XThreadUtils.cpp ---- xbmc-11.0.1/xbmc/linux/XThreadUtils.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/linux/XThreadUtils.cpp 1970-01-01 01:00:00.000000000 +0100 +diff -Naur xbmc-pvr-11.0.1/xbmc/linux/XThreadUtils.cpp xbmc-pvr-11.0.1.patch/xbmc/linux/XThreadUtils.cpp +--- xbmc-pvr-11.0.1/xbmc/linux/XThreadUtils.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/linux/XThreadUtils.cpp 1970-01-01 01:00:00.000000000 +0100 @@ -1,210 +0,0 @@ -/* - * Copyright (C) 2005-2009 Team XBMC @@ -12775,9 +11960,9 @@ diff -Naur xbmc-11.0.1/xbmc/linux/XThreadUtils.cpp xbmc-11.0.1.patch/xbmc/linux/ - -#endif - -diff -Naur xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScanner.cpp xbmc-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScanner.cpp ---- xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScanner.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScanner.cpp 2012-05-13 22:08:46.811190206 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/music/infoscanner/MusicInfoScanner.cpp xbmc-pvr-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScanner.cpp +--- xbmc-pvr-11.0.1/xbmc/music/infoscanner/MusicInfoScanner.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScanner.cpp 2012-05-14 14:15:12.192221636 +0200 @@ -57,7 +57,7 @@ using namespace XFILE; using namespace MUSIC_GRABBER; @@ -12796,9 +11981,9 @@ diff -Naur xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScanner.cpp xbmc-11.0.1.p if (m_pObserver) fileCountReader.Create(); -diff -Naur xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScraper.cpp xbmc-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScraper.cpp ---- xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScraper.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScraper.cpp 2012-05-13 22:08:46.812190226 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/music/infoscanner/MusicInfoScraper.cpp xbmc-pvr-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScraper.cpp +--- xbmc-pvr-11.0.1/xbmc/music/infoscanner/MusicInfoScraper.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/music/infoscanner/MusicInfoScraper.cpp 2012-05-14 14:15:12.192221636 +0200 @@ -28,7 +28,7 @@ using namespace ADDON; using namespace std; @@ -12808,9 +11993,9 @@ diff -Naur xbmc-11.0.1/xbmc/music/infoscanner/MusicInfoScraper.cpp xbmc-11.0.1.p { m_bSucceeded=false; m_bCanceled=false; -diff -Naur xbmc-11.0.1/xbmc/music/LastFmManager.cpp xbmc-11.0.1.patch/xbmc/music/LastFmManager.cpp ---- xbmc-11.0.1/xbmc/music/LastFmManager.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/music/LastFmManager.cpp 2012-05-13 22:08:46.810190186 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/music/LastFmManager.cpp xbmc-pvr-11.0.1.patch/xbmc/music/LastFmManager.cpp +--- xbmc-pvr-11.0.1/xbmc/music/LastFmManager.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/music/LastFmManager.cpp 2012-05-14 14:15:12.193221656 +0200 @@ -70,7 +70,7 @@ CLastFmManager* CLastFmManager::m_pInstance=NULL; @@ -12838,9 +12023,9 @@ diff -Naur xbmc-11.0.1/xbmc/music/LastFmManager.cpp xbmc-11.0.1.patch/xbmc/music { m_bStop = true; m_hWorkerEvent.Set(); -diff -Naur xbmc-11.0.1/xbmc/network/AirPlayServer.cpp xbmc-11.0.1.patch/xbmc/network/AirPlayServer.cpp ---- xbmc-11.0.1/xbmc/network/AirPlayServer.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/AirPlayServer.cpp 2012-05-13 22:08:46.813190246 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/AirPlayServer.cpp xbmc-pvr-11.0.1.patch/xbmc/network/AirPlayServer.cpp +--- xbmc-pvr-11.0.1/xbmc/network/AirPlayServer.cpp 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/AirPlayServer.cpp 2012-05-14 14:15:12.194221676 +0200 @@ -184,7 +184,7 @@ } } @@ -12850,9 +12035,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/AirPlayServer.cpp xbmc-11.0.1.patch/xbmc/net { m_port = port; m_nonlocal = nonlocal; -diff -Naur xbmc-11.0.1/xbmc/network/AirTunesServer.cpp xbmc-11.0.1.patch/xbmc/network/AirTunesServer.cpp ---- xbmc-11.0.1/xbmc/network/AirTunesServer.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/AirTunesServer.cpp 2012-05-13 22:08:46.871191395 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/AirTunesServer.cpp xbmc-pvr-11.0.1.patch/xbmc/network/AirTunesServer.cpp +--- xbmc-pvr-11.0.1/xbmc/network/AirTunesServer.cpp 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/AirTunesServer.cpp 2012-05-14 14:15:12.195221696 +0200 @@ -292,7 +292,7 @@ } } @@ -12862,9 +12047,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/AirTunesServer.cpp xbmc-11.0.1.patch/xbmc/ne { m_port = port; m_pLibShairport = new DllLibShairport(); -diff -Naur xbmc-11.0.1/xbmc/network/libscrobbler/scrobbler.cpp xbmc-11.0.1.patch/xbmc/network/libscrobbler/scrobbler.cpp ---- xbmc-11.0.1/xbmc/network/libscrobbler/scrobbler.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/libscrobbler/scrobbler.cpp 2012-05-13 22:08:46.816190305 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/libscrobbler/scrobbler.cpp xbmc-pvr-11.0.1.patch/xbmc/network/libscrobbler/scrobbler.cpp +--- xbmc-pvr-11.0.1/xbmc/network/libscrobbler/scrobbler.cpp 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/libscrobbler/scrobbler.cpp 2012-05-14 14:15:12.196221716 +0200 @@ -46,7 +46,7 @@ #define SCROBBLER_ACTION_NOWPLAYING 2 @@ -12883,9 +12068,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/libscrobbler/scrobbler.cpp xbmc-11.0.1.patch Create(); } -diff -Naur xbmc-11.0.1/xbmc/network/Network.h xbmc-11.0.1.patch/xbmc/network/Network.h ---- xbmc-11.0.1/xbmc/network/Network.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/Network.h 2012-05-13 22:08:46.813190246 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/Network.h xbmc-pvr-11.0.1.patch/xbmc/network/Network.h +--- xbmc-pvr-11.0.1/xbmc/network/Network.h 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/Network.h 2012-05-14 14:15:12.197221736 +0200 @@ -24,6 +24,7 @@ #include @@ -12894,9 +12079,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/Network.h xbmc-11.0.1.patch/xbmc/network/Net enum EncMode { ENC_NONE = 0, ENC_WEP = 1, ENC_WPA = 2, ENC_WPA2 = 3 }; enum NetworkAssignment { NETWORK_DASH = 0, NETWORK_DHCP = 1, NETWORK_STATIC = 2, NETWORK_DISABLED = 3 }; -diff -Naur xbmc-11.0.1/xbmc/network/TCPServer.cpp xbmc-11.0.1.patch/xbmc/network/TCPServer.cpp ---- xbmc-11.0.1/xbmc/network/TCPServer.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/TCPServer.cpp 2012-05-13 22:08:46.814190266 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/TCPServer.cpp xbmc-pvr-11.0.1.patch/xbmc/network/TCPServer.cpp +--- xbmc-pvr-11.0.1/xbmc/network/TCPServer.cpp 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/TCPServer.cpp 2012-05-14 14:15:12.197221736 +0200 @@ -85,7 +85,7 @@ } } @@ -12906,9 +12091,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/TCPServer.cpp xbmc-11.0.1.patch/xbmc/network { m_port = port; m_nonlocal = nonlocal; -diff -Naur xbmc-11.0.1/xbmc/network/UdpClient.cpp xbmc-11.0.1.patch/xbmc/network/UdpClient.cpp ---- xbmc-11.0.1/xbmc/network/UdpClient.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/UdpClient.cpp 2012-05-13 22:08:46.814190266 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/UdpClient.cpp xbmc-pvr-11.0.1.patch/xbmc/network/UdpClient.cpp +--- xbmc-pvr-11.0.1/xbmc/network/UdpClient.cpp 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/UdpClient.cpp 2012-05-14 14:15:12.198221756 +0200 @@ -35,7 +35,7 @@ #define UDPCLIENT_DEBUG_LEVEL LOGDEBUG @@ -12918,9 +12103,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/UdpClient.cpp xbmc-11.0.1.patch/xbmc/network {} CUdpClient::~CUdpClient(void) -diff -Naur xbmc-11.0.1/xbmc/network/UdpClient.h xbmc-11.0.1.patch/xbmc/network/UdpClient.h ---- xbmc-11.0.1/xbmc/network/UdpClient.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/network/UdpClient.h 2012-05-13 22:08:46.815190286 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/network/UdpClient.h xbmc-pvr-11.0.1.patch/xbmc/network/UdpClient.h +--- xbmc-pvr-11.0.1/xbmc/network/UdpClient.h 2012-03-27 17:55:33.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/network/UdpClient.h 2012-05-14 14:15:12.199221776 +0200 @@ -25,6 +25,7 @@ #include "threads/CriticalSection.h" #include @@ -12929,9 +12114,9 @@ diff -Naur xbmc-11.0.1/xbmc/network/UdpClient.h xbmc-11.0.1.patch/xbmc/network/U class CUdpClient : CThread { -diff -Naur xbmc-11.0.1/xbmc/peripherals/Peripherals.cpp xbmc-11.0.1.patch/xbmc/peripherals/Peripherals.cpp ---- xbmc-11.0.1/xbmc/peripherals/Peripherals.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/peripherals/Peripherals.cpp 2012-05-13 22:08:46.940192765 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/peripherals/Peripherals.cpp xbmc-pvr-11.0.1.patch/xbmc/peripherals/Peripherals.cpp +--- xbmc-pvr-11.0.1/xbmc/peripherals/Peripherals.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/peripherals/Peripherals.cpp 2012-05-14 14:15:12.199221776 +0200 @@ -19,6 +19,7 @@ * */ @@ -12940,9 +12125,9 @@ diff -Naur xbmc-11.0.1/xbmc/peripherals/Peripherals.cpp xbmc-11.0.1.patch/xbmc/p #include "Peripherals.h" #include "bus/PeripheralBus.h" #include "devices/PeripheralBluetooth.h" -diff -Naur xbmc-11.0.1/xbmc/pictures/GUIWindowSlideShow.cpp xbmc-11.0.1.patch/xbmc/pictures/GUIWindowSlideShow.cpp ---- xbmc-11.0.1/xbmc/pictures/GUIWindowSlideShow.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/pictures/GUIWindowSlideShow.cpp 2012-05-13 22:08:46.816190305 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/pictures/GUIWindowSlideShow.cpp xbmc-pvr-11.0.1.patch/xbmc/pictures/GUIWindowSlideShow.cpp +--- xbmc-pvr-11.0.1/xbmc/pictures/GUIWindowSlideShow.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/pictures/GUIWindowSlideShow.cpp 2012-05-14 14:15:12.201221817 +0200 @@ -67,7 +67,7 @@ static float zoomamount[10] = { 1.0f, 1.2f, 1.5f, 2.0f, 2.8f, 4.0f, 6.0f, 9.0f, 13.5f, 20.0f }; @@ -12952,9 +12137,9 @@ diff -Naur xbmc-11.0.1/xbmc/pictures/GUIWindowSlideShow.cpp xbmc-11.0.1.patch/xb { m_pCallback = NULL; m_isLoading = false; -diff -Naur xbmc-11.0.1/xbmc/rendering/dx/RenderSystemDX.cpp xbmc-11.0.1.patch/xbmc/rendering/dx/RenderSystemDX.cpp ---- xbmc-11.0.1/xbmc/rendering/dx/RenderSystemDX.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/rendering/dx/RenderSystemDX.cpp 2012-05-13 22:08:46.817190325 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/rendering/dx/RenderSystemDX.cpp xbmc-pvr-11.0.1.patch/xbmc/rendering/dx/RenderSystemDX.cpp +--- xbmc-pvr-11.0.1/xbmc/rendering/dx/RenderSystemDX.cpp 2012-03-27 17:55:35.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/rendering/dx/RenderSystemDX.cpp 2012-05-14 14:15:12.202221838 +0200 @@ -569,7 +569,7 @@ //CVideoReferenceClock polls GetRasterStatus too, @@ -12964,9 +12149,9 @@ diff -Naur xbmc-11.0.1/xbmc/rendering/dx/RenderSystemDX.cpp xbmc-11.0.1.patch/xb { //save current thread priority and set thread priority to THREAD_PRIORITY_TIME_CRITICAL int priority = GetThreadPriority(GetCurrentThread()); -diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.cpp xbmc-11.0.1.patch/xbmc/settings/AdvancedSettings.cpp ---- xbmc-11.0.1/xbmc/settings/AdvancedSettings.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/settings/AdvancedSettings.cpp 2012-05-13 22:08:47.021194373 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/settings/AdvancedSettings.cpp xbmc-pvr-11.0.1.patch/xbmc/settings/AdvancedSettings.cpp +--- xbmc-pvr-11.0.1/xbmc/settings/AdvancedSettings.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/settings/AdvancedSettings.cpp 2012-05-14 14:15:12.203221858 +0200 @@ -96,12 +96,18 @@ m_videoAllowMpeg4VAAPI = false; m_videoDisableBackgroundDeinterlace = false; @@ -12986,7 +12171,7 @@ diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.cpp xbmc-11.0.1.patch/xbmc m_musicUseTimeSeeking = true; m_musicTimeSeekForward = 10; -@@ -455,6 +461,11 @@ +@@ -470,6 +476,11 @@ XMLUtils::GetBoolean(pElement,"allowmpeg4vaapi",m_videoAllowMpeg4VAAPI); XMLUtils::GetBoolean(pElement, "disablebackgrounddeinterlace", m_videoDisableBackgroundDeinterlace); XMLUtils::GetInt(pElement, "useocclusionquery", m_videoCaptureUseOcclusionQuery, -1, 1); @@ -12998,7 +12183,7 @@ diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.cpp xbmc-11.0.1.patch/xbmc TiXmlElement* pAdjustRefreshrate = pElement->FirstChildElement("adjustrefreshrate"); if (pAdjustRefreshrate) -@@ -544,6 +555,8 @@ +@@ -559,6 +570,8 @@ //0 = disable fps detect, 1 = only detect on timestamps with uniform spacing, 2 detect on all timestamps XMLUtils::GetInt(pElement, "fpsdetect", m_videoFpsDetect, 0, 2); @@ -13007,9 +12192,9 @@ diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.cpp xbmc-11.0.1.patch/xbmc // Store global display latency settings TiXmlElement* pVideoLatency = pElement->FirstChildElement("latency"); if (pVideoLatency) -diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.h xbmc-11.0.1.patch/xbmc/settings/AdvancedSettings.h ---- xbmc-11.0.1/xbmc/settings/AdvancedSettings.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/settings/AdvancedSettings.h 2012-05-13 22:08:47.022194393 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/settings/AdvancedSettings.h xbmc-pvr-11.0.1.patch/xbmc/settings/AdvancedSettings.h +--- xbmc-pvr-11.0.1/xbmc/settings/AdvancedSettings.h 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/settings/AdvancedSettings.h 2012-05-14 14:15:12.204221878 +0200 @@ -111,6 +111,11 @@ int m_videoPercentSeekBackwardBig; CStdString m_videoPPFFmpegDeint; @@ -13030,10 +12215,10 @@ diff -Naur xbmc-11.0.1/xbmc/settings/AdvancedSettings.h xbmc-11.0.1.patch/xbmc/s CStdString m_videoDefaultPlayer; CStdString m_videoDefaultDVDPlayer; -diff -Naur xbmc-11.0.1/xbmc/settings/GUISettings.cpp xbmc-11.0.1.patch/xbmc/settings/GUISettings.cpp ---- xbmc-11.0.1/xbmc/settings/GUISettings.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/settings/GUISettings.cpp 2012-05-13 22:08:46.957193103 +0200 -@@ -583,10 +583,15 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/settings/GUISettings.cpp xbmc-pvr-11.0.1.patch/xbmc/settings/GUISettings.cpp +--- xbmc-pvr-11.0.1/xbmc/settings/GUISettings.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/settings/GUISettings.cpp 2012-05-14 14:15:12.205221898 +0200 +@@ -588,10 +588,15 @@ #ifdef HAVE_LIBVDPAU AddBool(vp, "videoplayer.usevdpau", 13425, true); @@ -13049,10 +12234,10 @@ diff -Naur xbmc-11.0.1/xbmc/settings/GUISettings.cpp xbmc-11.0.1.patch/xbmc/sett #ifdef HAS_DX AddBool(g_sysinfo.IsVistaOrHigher() ? vp: NULL, "videoplayer.usedxva2", 13427, g_sysinfo.IsVistaOrHigher() ? true : false); #endif -diff -Naur xbmc-11.0.1/xbmc/settings/GUIWindowSettingsCategory.cpp xbmc-11.0.1.patch/xbmc/settings/GUIWindowSettingsCategory.cpp ---- xbmc-11.0.1/xbmc/settings/GUIWindowSettingsCategory.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/settings/GUIWindowSettingsCategory.cpp 2012-05-13 22:08:46.682187646 +0200 -@@ -549,6 +549,40 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/settings/GUIWindowSettingsCategory.cpp xbmc-pvr-11.0.1.patch/xbmc/settings/GUIWindowSettingsCategory.cpp +--- xbmc-pvr-11.0.1/xbmc/settings/GUIWindowSettingsCategory.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/settings/GUIWindowSettingsCategory.cpp 2012-05-14 14:15:12.207221938 +0200 +@@ -557,6 +557,40 @@ pControl->SetEnabled(true); } } @@ -13093,21 +12278,21 @@ diff -Naur xbmc-11.0.1/xbmc/settings/GUIWindowSettingsCategory.cpp xbmc-11.0.1.p else #endif if (strSetting.Equals("videoscreen.resolution")) -diff -Naur xbmc-11.0.1/xbmc/settings/VideoSettings.h xbmc-11.0.1.patch/xbmc/settings/VideoSettings.h ---- xbmc-11.0.1/xbmc/settings/VideoSettings.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/settings/VideoSettings.h 2012-05-13 22:08:46.958193123 +0200 -@@ -67,6 +67,8 @@ - +diff -Naur xbmc-pvr-11.0.1/xbmc/settings/VideoSettings.h xbmc-pvr-11.0.1.patch/xbmc/settings/VideoSettings.h +--- xbmc-pvr-11.0.1/xbmc/settings/VideoSettings.h 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/settings/VideoSettings.h 2012-05-14 14:15:12.208221958 +0200 +@@ -66,6 +66,8 @@ VS_INTERLACEMETHOD_SW_BLEND = 20, + VS_INTERLACEMETHOD_AUTO_ION = 21, + VS_INTERLACEMETHOD_XVBA = 22, + VS_INTERLACEMETHOD_MAX // do not use and keep as last enum value. }; -diff -Naur xbmc-11.0.1/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp xbmc-11.0.1.patch/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp ---- xbmc-11.0.1/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp 2012-05-13 22:08:46.821190405 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp 2012-05-14 14:15:12.208221958 +0200 @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13156,9 +12341,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/darwin/ThreadSchedImpl.cpp xbmc-11. + policy = SCHED_RR; + result = pthread_setschedparam(ThreadId(), policy, ¶m ); +} -diff -Naur xbmc-11.0.1/xbmc/threads/platform/linux/ThreadSchedImpl.cpp xbmc-11.0.1.patch/xbmc/threads/platform/linux/ThreadSchedImpl.cpp ---- xbmc-11.0.1/xbmc/threads/platform/linux/ThreadSchedImpl.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/linux/ThreadSchedImpl.cpp 2012-05-13 22:08:46.821190405 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/linux/ThreadSchedImpl.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/platform/linux/ThreadSchedImpl.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/platform/linux/ThreadSchedImpl.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/linux/ThreadSchedImpl.cpp 2012-05-14 14:15:12.209221978 +0200 @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13190,9 +12375,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/linux/ThreadSchedImpl.cpp xbmc-11.0 +{ + return false; +} -diff -Naur xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.cpp xbmc-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.cpp ---- xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.cpp 2012-05-13 22:08:46.822190424 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.cpp 2012-05-14 14:15:12.210221998 +0200 @@ -0,0 +1,220 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13414,9 +12599,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.cpp xbmc-11.0.1 + return time; +} + -diff -Naur xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.h xbmc-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.h ---- xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.h 2012-05-13 22:08:46.822190424 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.h xbmc-pvr-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.h +--- xbmc-pvr-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/pthreads/ThreadImpl.h 2012-05-14 14:15:12.210221998 +0200 @@ -0,0 +1,39 @@ +/* +* Copyright (C) 2005-2011 Team XBMC @@ -13457,9 +12642,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/pthreads/ThreadImpl.h xbmc-11.0.1.p + inline static void ThreadSleep(unsigned int millis) { usleep(millis*1000); } +} + -diff -Naur xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.cpp xbmc-11.0.1.patch/xbmc/threads/platform/ThreadImpl.cpp ---- xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/ThreadImpl.cpp 2012-05-13 22:08:46.820190385 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/ThreadImpl.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/platform/ThreadImpl.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/platform/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/ThreadImpl.cpp 2012-05-14 14:15:12.211222019 +0200 @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13495,9 +12680,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.cpp xbmc-11.0.1.patch/xb +#include "threads/platform/win/ThreadImpl.cpp" +#endif + -diff -Naur xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.h xbmc-11.0.1.patch/xbmc/threads/platform/ThreadImpl.h ---- xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/ThreadImpl.h 2012-05-13 22:08:46.820190385 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/ThreadImpl.h xbmc-pvr-11.0.1.patch/xbmc/threads/platform/ThreadImpl.h +--- xbmc-pvr-11.0.1/xbmc/threads/platform/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/ThreadImpl.h 2012-05-14 14:15:12.211222019 +0200 @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13527,9 +12712,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/ThreadImpl.h xbmc-11.0.1.patch/xbmc +#elif (defined TARGET_WINDOWS) +#include "threads/platform/win/ThreadImpl.h" +#endif -diff -Naur xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.cpp xbmc-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.cpp ---- xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.cpp 2012-05-13 22:08:46.823190444 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/win/ThreadImpl.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/platform/win/ThreadImpl.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.cpp 2012-05-14 14:15:12.212222039 +0200 @@ -0,0 +1,207 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -13738,9 +12923,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.cpp xbmc-11.0.1.patc + return time; +} + -diff -Naur xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.h xbmc-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.h ---- xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.h 2012-05-13 22:08:46.823190444 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/platform/win/ThreadImpl.h xbmc-pvr-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.h +--- xbmc-pvr-11.0.1/xbmc/threads/platform/win/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/platform/win/ThreadImpl.h 2012-05-14 14:15:12.212222039 +0200 @@ -0,0 +1,40 @@ +/* +* Copyright (C) 2005-2011 Team XBMC @@ -13782,9 +12967,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/platform/win/ThreadImpl.h xbmc-11.0.1.patch/ + inline static void ThreadSleep(unsigned int millis) { Sleep(millis); } +} + -diff -Naur xbmc-11.0.1/xbmc/threads/Thread.cpp xbmc-11.0.1.patch/xbmc/threads/Thread.cpp ---- xbmc-11.0.1/xbmc/threads/Thread.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/Thread.cpp 2012-05-13 22:08:46.872191415 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/Thread.cpp xbmc-pvr-11.0.1.patch/xbmc/threads/Thread.cpp +--- xbmc-pvr-11.0.1/xbmc/threads/Thread.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/Thread.cpp 2012-05-14 14:15:12.214222079 +0200 @@ -20,41 +20,27 @@ #include "threads/SystemClock.h" @@ -14332,9 +13517,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/Thread.cpp xbmc-11.0.1.patch/xbmc/threads/Th } -diff -Naur xbmc-11.0.1/xbmc/threads/Thread.h xbmc-11.0.1.patch/xbmc/threads/Thread.h ---- xbmc-11.0.1/xbmc/threads/Thread.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/Thread.h 2012-05-13 22:08:46.819190365 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/Thread.h xbmc-pvr-11.0.1.patch/xbmc/threads/Thread.h +--- xbmc-pvr-11.0.1/xbmc/threads/Thread.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/Thread.h 2012-05-14 14:15:12.215222099 +0200 @@ -23,19 +23,13 @@ // ////////////////////////////////////////////////////////////////////// @@ -14461,9 +13646,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/Thread.h xbmc-11.0.1.patch/xbmc/threads/Thre }; - -#endif // !defined(AFX_THREAD_H__ACFB7357_B961_4AC1_9FB2_779526219817__INCLUDED_) -diff -Naur xbmc-11.0.1/xbmc/threads/ThreadImpl.h xbmc-11.0.1.patch/xbmc/threads/ThreadImpl.h ---- xbmc-11.0.1/xbmc/threads/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/threads/ThreadImpl.h 2012-05-13 22:08:46.819190365 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/threads/ThreadImpl.h xbmc-pvr-11.0.1.patch/xbmc/threads/ThreadImpl.h +--- xbmc-pvr-11.0.1/xbmc/threads/ThreadImpl.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/threads/ThreadImpl.h 2012-05-14 14:15:12.215222099 +0200 @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -14490,9 +13675,9 @@ diff -Naur xbmc-11.0.1/xbmc/threads/ThreadImpl.h xbmc-11.0.1.patch/xbmc/threads/ + +#include "threads/platform/ThreadImpl.h" + -diff -Naur xbmc-11.0.1/xbmc/utils/ActorProtocol.cpp xbmc-11.0.1.patch/xbmc/utils/ActorProtocol.cpp ---- xbmc-11.0.1/xbmc/utils/ActorProtocol.cpp 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/ActorProtocol.cpp 2012-05-13 22:08:46.700188003 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/ActorProtocol.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/ActorProtocol.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/ActorProtocol.cpp 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/ActorProtocol.cpp 2012-05-14 14:15:12.216222119 +0200 @@ -0,0 +1,254 @@ +/* + * Copyright (C) 2005-2011 Team XBMC @@ -14748,9 +13933,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/ActorProtocol.cpp xbmc-11.0.1.patch/xbmc/utils + while (ReceiveOutMessage(&msg)) + msg->Release(); +} -diff -Naur xbmc-11.0.1/xbmc/utils/ActorProtocol.h xbmc-11.0.1.patch/xbmc/utils/ActorProtocol.h ---- xbmc-11.0.1/xbmc/utils/ActorProtocol.h 1970-01-01 01:00:00.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/ActorProtocol.h 2012-05-13 22:08:46.700188003 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/ActorProtocol.h xbmc-pvr-11.0.1.patch/xbmc/utils/ActorProtocol.h +--- xbmc-pvr-11.0.1/xbmc/utils/ActorProtocol.h 1970-01-01 01:00:00.000000000 +0100 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/ActorProtocol.h 2012-05-14 14:15:12.217222140 +0200 @@ -0,0 +1,89 @@ + +#pragma once @@ -14841,9 +14026,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/ActorProtocol.h xbmc-11.0.1.patch/xbmc/utils/A +}; + +} -diff -Naur xbmc-11.0.1/xbmc/utils/AlarmClock.cpp xbmc-11.0.1.patch/xbmc/utils/AlarmClock.cpp ---- xbmc-11.0.1/xbmc/utils/AlarmClock.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/AlarmClock.cpp 2012-05-13 22:08:46.823190444 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/AlarmClock.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/AlarmClock.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/AlarmClock.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/AlarmClock.cpp 2012-05-14 14:15:12.217222140 +0200 @@ -28,7 +28,7 @@ using namespace std; @@ -14853,9 +14038,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/AlarmClock.cpp xbmc-11.0.1.patch/xbmc/utils/Al { } -diff -Naur xbmc-11.0.1/xbmc/utils/AsyncFileCopy.cpp xbmc-11.0.1.patch/xbmc/utils/AsyncFileCopy.cpp ---- xbmc-11.0.1/xbmc/utils/AsyncFileCopy.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/AsyncFileCopy.cpp 2012-05-13 22:08:46.824190464 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/AsyncFileCopy.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/AsyncFileCopy.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/AsyncFileCopy.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/AsyncFileCopy.cpp 2012-05-14 14:15:12.218222160 +0200 @@ -26,7 +26,7 @@ #include "log.h" #include "utils/TimeUtils.h" @@ -14865,9 +14050,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/AsyncFileCopy.cpp xbmc-11.0.1.patch/xbmc/utils { m_cancelled = false; m_succeeded = false; -diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueue.cpp xbmc-11.0.1.patch/xbmc/utils/DownloadQueue.cpp ---- xbmc-11.0.1/xbmc/utils/DownloadQueue.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/DownloadQueue.cpp 2012-05-13 22:08:46.824190464 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/DownloadQueue.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueue.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/DownloadQueue.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueue.cpp 2012-05-14 14:15:12.218222160 +0200 @@ -32,7 +32,7 @@ WORD CDownloadQueue::m_wNextQueueId = 0; @@ -14877,9 +14062,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueue.cpp xbmc-11.0.1.patch/xbmc/utils { m_bStop = false; m_wQueueId = m_wNextQueueId++; -diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueue.h xbmc-11.0.1.patch/xbmc/utils/DownloadQueue.h ---- xbmc-11.0.1/xbmc/utils/DownloadQueue.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/DownloadQueue.h 2012-05-13 22:08:46.825190483 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/DownloadQueue.h xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueue.h +--- xbmc-pvr-11.0.1/xbmc/utils/DownloadQueue.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueue.h 2012-05-14 14:15:12.219222180 +0200 @@ -26,6 +26,8 @@ #include "threads/CriticalSection.h" #include "StdString.h" @@ -14889,9 +14074,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueue.h xbmc-11.0.1.patch/xbmc/utils/D struct TICKET { TICKET(WORD aQueueId, DWORD aItemId) -diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueueManager.h xbmc-11.0.1.patch/xbmc/utils/DownloadQueueManager.h ---- xbmc-11.0.1/xbmc/utils/DownloadQueueManager.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/DownloadQueueManager.h 2012-05-13 22:08:46.825190483 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/DownloadQueueManager.h xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueueManager.h +--- xbmc-pvr-11.0.1/xbmc/utils/DownloadQueueManager.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/DownloadQueueManager.h 2012-05-14 14:15:12.220222200 +0200 @@ -22,6 +22,7 @@ */ @@ -14900,9 +14085,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/DownloadQueueManager.h xbmc-11.0.1.patch/xbmc/ #define MAX_DOWNLOAD_QUEUES 3 -diff -Naur xbmc-11.0.1/xbmc/utils/JobManager.cpp xbmc-11.0.1.patch/xbmc/utils/JobManager.cpp ---- xbmc-11.0.1/xbmc/utils/JobManager.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/JobManager.cpp 2012-05-13 22:08:46.826190502 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/JobManager.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/JobManager.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/JobManager.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/JobManager.cpp 2012-05-14 14:15:12.220222200 +0200 @@ -24,6 +24,9 @@ #include "threads/SingleLock.h" #include "utils/log.h" @@ -14913,9 +14098,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/JobManager.cpp xbmc-11.0.1.patch/xbmc/utils/Jo using namespace std; bool CJob::ShouldCancel(unsigned int progress, unsigned int total) const -diff -Naur xbmc-11.0.1/xbmc/utils/LCD.h xbmc-11.0.1.patch/xbmc/utils/LCD.h ---- xbmc-11.0.1/xbmc/utils/LCD.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/LCD.h 2012-05-13 22:08:46.826190502 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/LCD.h xbmc-pvr-11.0.1.patch/xbmc/utils/LCD.h +--- xbmc-pvr-11.0.1/xbmc/utils/LCD.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/LCD.h 2012-05-14 14:15:12.221222220 +0200 @@ -68,8 +68,9 @@ void LoadSkin(const CStdString &xmlFile); void Reset(); @@ -14928,10 +14113,10 @@ diff -Naur xbmc-11.0.1/xbmc/utils/LCD.h xbmc-11.0.1.patch/xbmc/utils/LCD.h protected: virtual void Process() = 0; void StringToLCDCharSet(CStdString& strText); -diff -Naur xbmc-11.0.1/xbmc/utils/Makefile xbmc-11.0.1.patch/xbmc/utils/Makefile ---- xbmc-11.0.1/xbmc/utils/Makefile 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/Makefile 2012-05-13 22:08:46.701188023 +0200 -@@ -57,6 +57,7 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/Makefile xbmc-pvr-11.0.1.patch/xbmc/utils/Makefile +--- xbmc-pvr-11.0.1/xbmc/utils/Makefile 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/Makefile 2012-05-14 14:15:12.222222240 +0200 +@@ -59,6 +59,7 @@ Weather.cpp \ Win32Exception.cpp \ XMLUtils.cpp \ @@ -14939,9 +14124,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/Makefile xbmc-11.0.1.patch/xbmc/utils/Makefile LIB=utils.a -diff -Naur xbmc-11.0.1/xbmc/utils/RssReader.cpp xbmc-11.0.1.patch/xbmc/utils/RssReader.cpp ---- xbmc-11.0.1/xbmc/utils/RssReader.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/RssReader.cpp 2012-05-13 22:08:46.827190522 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/RssReader.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/RssReader.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/RssReader.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/RssReader.cpp 2012-05-14 14:15:12.223222260 +0200 @@ -44,7 +44,7 @@ // Construction/Destruction ////////////////////////////////////////////////////////////////////// @@ -14951,9 +14136,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/RssReader.cpp xbmc-11.0.1.patch/xbmc/utils/Rss { m_pObserver = NULL; m_spacesBetweenFeeds = 0; -diff -Naur xbmc-11.0.1/xbmc/utils/RssReader.h xbmc-11.0.1.patch/xbmc/utils/RssReader.h ---- xbmc-11.0.1/xbmc/utils/RssReader.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/RssReader.h 2012-05-13 22:08:46.827190522 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/RssReader.h xbmc-pvr-11.0.1.patch/xbmc/utils/RssReader.h +--- xbmc-pvr-11.0.1/xbmc/utils/RssReader.h 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/RssReader.h 2012-05-14 14:15:12.223222260 +0200 @@ -39,6 +39,9 @@ #include "tinyXML/tinyxml.h" @@ -14964,9 +14149,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/RssReader.h xbmc-11.0.1.patch/xbmc/utils/RssRe #define RSS_COLOR_BODY 0 #define RSS_COLOR_HEADLINE 1 #define RSS_COLOR_CHANNEL 2 -diff -Naur xbmc-11.0.1/xbmc/utils/Splash.cpp xbmc-11.0.1.patch/xbmc/utils/Splash.cpp ---- xbmc-11.0.1/xbmc/utils/Splash.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/Splash.cpp 2012-05-13 22:08:46.828190542 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/Splash.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/Splash.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/Splash.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/Splash.cpp 2012-05-14 14:15:12.224222280 +0200 @@ -31,7 +31,7 @@ using namespace XFILE; @@ -14983,9 +14168,9 @@ diff -Naur xbmc-11.0.1/xbmc/utils/Splash.cpp xbmc-11.0.1.patch/xbmc/utils/Splash - return (m_ThreadHandle != NULL); + return (IsRunning()); } -diff -Naur xbmc-11.0.1/xbmc/utils/TuxBoxUtil.cpp xbmc-11.0.1.patch/xbmc/utils/TuxBoxUtil.cpp ---- xbmc-11.0.1/xbmc/utils/TuxBoxUtil.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/utils/TuxBoxUtil.cpp 2012-05-13 22:08:46.829190562 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/utils/TuxBoxUtil.cpp xbmc-pvr-11.0.1.patch/xbmc/utils/TuxBoxUtil.cpp +--- xbmc-pvr-11.0.1/xbmc/utils/TuxBoxUtil.cpp 2012-03-27 17:55:37.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/utils/TuxBoxUtil.cpp 2012-05-14 14:15:12.225222300 +0200 @@ -48,7 +48,7 @@ CTuxBoxUtil g_tuxbox; CTuxBoxService g_tuxboxService; @@ -14995,10 +14180,10 @@ diff -Naur xbmc-11.0.1/xbmc/utils/TuxBoxUtil.cpp xbmc-11.0.1.patch/xbmc/utils/Tu { } CTuxBoxService::~CTuxBoxService() -diff -Naur xbmc-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp xbmc-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp ---- xbmc-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-05-13 22:18:16.222981047 +0200 -@@ -105,12 +105,12 @@ +diff -Naur xbmc-pvr-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp xbmc-pvr-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp +--- xbmc-pvr-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-05-14 14:14:51.709808795 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/dialogs/GUIDialogVideoSettings.cpp 2012-05-14 14:15:12.226222321 +0200 +@@ -107,12 +107,12 @@ entries.push_back(make_pair(VS_INTERLACEMETHOD_INVERSE_TELECINE , 16314)); entries.push_back(make_pair(VS_INTERLACEMETHOD_VDPAU_TEMPORAL_SPATIAL , 16311)); entries.push_back(make_pair(VS_INTERLACEMETHOD_VDPAU_TEMPORAL , 16310)); @@ -15013,9 +14198,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/dialogs/GUIDialogVideoSettings.cpp xbmc-11.0.1 /* remove unsupported methods */ for(vector >::iterator it = entries.begin(); it != entries.end();) -diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoDownloader.cpp xbmc-11.0.1.patch/xbmc/video/VideoInfoDownloader.cpp ---- xbmc-11.0.1/xbmc/video/VideoInfoDownloader.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/VideoInfoDownloader.cpp 2012-05-13 22:08:46.829190562 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/video/VideoInfoDownloader.cpp xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoDownloader.cpp +--- xbmc-pvr-11.0.1/xbmc/video/VideoInfoDownloader.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoDownloader.cpp 2012-05-14 14:15:12.227222342 +0200 @@ -116,7 +116,7 @@ m_state = FIND_MOVIE; m_strMovie = strMovie; @@ -15052,9 +14237,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoDownloader.cpp xbmc-11.0.1.patch/xbmc StopThread(); Create(); while (!m_found) -diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoDownloader.h xbmc-11.0.1.patch/xbmc/video/VideoInfoDownloader.h ---- xbmc-11.0.1/xbmc/video/VideoInfoDownloader.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/VideoInfoDownloader.h 2012-05-13 22:08:46.830190582 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/video/VideoInfoDownloader.h xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoDownloader.h +--- xbmc-pvr-11.0.1/xbmc/video/VideoInfoDownloader.h 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoDownloader.h 2012-05-14 14:15:12.228222362 +0200 @@ -42,7 +42,7 @@ class CVideoInfoDownloader : public CThread { @@ -15064,9 +14249,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoDownloader.h xbmc-11.0.1.patch/xbmc/v virtual ~CVideoInfoDownloader() {} // threaded lookup functions -diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoScanner.cpp xbmc-11.0.1.patch/xbmc/video/VideoInfoScanner.cpp ---- xbmc-11.0.1/xbmc/video/VideoInfoScanner.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/VideoInfoScanner.cpp 2012-05-13 22:08:46.831190602 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/video/VideoInfoScanner.cpp xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoScanner.cpp +--- xbmc-pvr-11.0.1/xbmc/video/VideoInfoScanner.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/VideoInfoScanner.cpp 2012-05-14 14:15:12.229222382 +0200 @@ -54,7 +54,7 @@ namespace VIDEO { @@ -15076,9 +14261,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/VideoInfoScanner.cpp xbmc-11.0.1.patch/xbmc/vi { m_bRunning = false; m_pObserver = NULL; -diff -Naur xbmc-11.0.1/xbmc/video/VideoReferenceClock.cpp xbmc-11.0.1.patch/xbmc/video/VideoReferenceClock.cpp ---- xbmc-11.0.1/xbmc/video/VideoReferenceClock.cpp 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/VideoReferenceClock.cpp 2012-05-13 22:08:47.011194174 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/video/VideoReferenceClock.cpp xbmc-pvr-11.0.1.patch/xbmc/video/VideoReferenceClock.cpp +--- xbmc-pvr-11.0.1/xbmc/video/VideoReferenceClock.cpp 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/VideoReferenceClock.cpp 2012-05-14 14:15:12.231222422 +0200 @@ -31,6 +31,7 @@ #include #include @@ -15201,9 +14386,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/VideoReferenceClock.cpp xbmc-11.0.1.patch/xbmc while (m_CurrTime < Target) { //calculate how long to sleep before we should have gotten a signal that a vblank happened -diff -Naur xbmc-11.0.1/xbmc/video/VideoReferenceClock.h xbmc-11.0.1.patch/xbmc/video/VideoReferenceClock.h ---- xbmc-11.0.1/xbmc/video/VideoReferenceClock.h 2012-03-21 23:57:32.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/video/VideoReferenceClock.h 2012-05-13 22:08:46.917192309 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/video/VideoReferenceClock.h xbmc-pvr-11.0.1.patch/xbmc/video/VideoReferenceClock.h +--- xbmc-pvr-11.0.1/xbmc/video/VideoReferenceClock.h 2012-03-27 17:55:34.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/video/VideoReferenceClock.h 2012-05-14 14:15:12.232222442 +0200 @@ -125,6 +125,7 @@ bool m_UseNvSettings; @@ -15212,9 +14397,9 @@ diff -Naur xbmc-11.0.1/xbmc/video/VideoReferenceClock.h xbmc-11.0.1.patch/xbmc/v #elif defined(_WIN32) && defined(HAS_DX) bool SetupD3D(); -diff -Naur xbmc-11.0.1/xbmc/win32/PlatformDefs.h xbmc-11.0.1.patch/xbmc/win32/PlatformDefs.h ---- xbmc-11.0.1/xbmc/win32/PlatformDefs.h 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/win32/PlatformDefs.h 2012-05-13 22:08:46.870191375 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/win32/PlatformDefs.h xbmc-pvr-11.0.1.patch/xbmc/win32/PlatformDefs.h +--- xbmc-pvr-11.0.1/xbmc/win32/PlatformDefs.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/win32/PlatformDefs.h 2012-05-14 14:15:12.232222442 +0200 @@ -33,7 +33,6 @@ typedef __int64 fpos64_t; typedef __int64 __off64_t; @@ -15223,9 +14408,9 @@ diff -Naur xbmc-11.0.1/xbmc/win32/PlatformDefs.h xbmc-11.0.1.patch/xbmc/win32/Pl #define ssize_t int -diff -Naur xbmc-11.0.1/xbmc/win32/WindowHelper.cpp xbmc-11.0.1.patch/xbmc/win32/WindowHelper.cpp ---- xbmc-11.0.1/xbmc/win32/WindowHelper.cpp 2012-03-21 23:57:34.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/win32/WindowHelper.cpp 2012-05-13 22:08:46.871191395 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/win32/WindowHelper.cpp xbmc-pvr-11.0.1.patch/xbmc/win32/WindowHelper.cpp +--- xbmc-pvr-11.0.1/xbmc/win32/WindowHelper.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/win32/WindowHelper.cpp 2012-05-14 14:15:12.233222462 +0200 @@ -28,7 +28,7 @@ CWHelper g_windowHelper; @@ -15235,9 +14420,9 @@ diff -Naur xbmc-11.0.1/xbmc/win32/WindowHelper.cpp xbmc-11.0.1.patch/xbmc/win32/ { m_hwnd = NULL; m_hProcess = NULL; -diff -Naur xbmc-11.0.1/xbmc/windowing/X11/WinSystemX11.cpp xbmc-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.cpp ---- xbmc-11.0.1/xbmc/windowing/X11/WinSystemX11.cpp 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.cpp 2012-05-13 22:08:47.023194413 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/windowing/X11/WinSystemX11.cpp xbmc-pvr-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.cpp +--- xbmc-pvr-11.0.1/xbmc/windowing/X11/WinSystemX11.cpp 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.cpp 2012-05-14 14:15:12.234222482 +0200 @@ -35,6 +35,8 @@ #include #include "cores/VideoRenderers/RenderManager.h" @@ -15345,9 +14530,9 @@ diff -Naur xbmc-11.0.1/xbmc/windowing/X11/WinSystemX11.cpp xbmc-11.0.1.patch/xbm CSingleLock lock(m_resourceSection); -diff -Naur xbmc-11.0.1/xbmc/windowing/X11/WinSystemX11.h xbmc-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.h ---- xbmc-11.0.1/xbmc/windowing/X11/WinSystemX11.h 2012-03-21 23:57:33.000000000 +0100 -+++ xbmc-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.h 2012-05-13 22:08:47.024194433 +0200 +diff -Naur xbmc-pvr-11.0.1/xbmc/windowing/X11/WinSystemX11.h xbmc-pvr-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.h +--- xbmc-pvr-11.0.1/xbmc/windowing/X11/WinSystemX11.h 2012-03-27 17:55:38.000000000 +0200 ++++ xbmc-pvr-11.0.1.patch/xbmc/windowing/X11/WinSystemX11.h 2012-05-14 14:15:12.234222482 +0200 @@ -27,6 +27,7 @@ #include "utils/Stopwatch.h" #include